code review
This commit is contained in:
parent
71e3de1834
commit
52a60eb47a
25 changed files with 625 additions and 296 deletions
|
@ -1,3 +1,11 @@
|
|||
cinecturlink2 2.3 - 2023.10.23
|
||||
===========================================================
|
||||
* Require Dotclear 2.28
|
||||
* Require PHP 8.1
|
||||
* Use specific class for records
|
||||
* Use specific class for widgets
|
||||
* Code review (phpstan)
|
||||
|
||||
cinecturlink2 2.2 - 2023.10.18
|
||||
===========================================================
|
||||
* Require Dotclear 2.28
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# README
|
||||
|
||||
[![Release](https://img.shields.io/badge/release-2.2-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/cinecturlink2/releases)
|
||||
![Date](https://img.shields.io/badge/date-2023.10.18-c44d58.svg)]
|
||||
[![Release](https://img.shields.io/badge/release-2.3-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/cinecturlink2/releases)
|
||||
![Date](https://img.shields.io/badge/date-2023.10.23-c44d58.svg)]
|
||||
[![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download)
|
||||
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/cinecturlink2)
|
||||
[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/cinecturlink2/src/branch/master/LICENSE)
|
||||
|
|
|
@ -21,7 +21,7 @@ $this->registerModule(
|
|||
'Cinecturlink 2',
|
||||
'Widgets and pages about books, musics, films, blogs you are interested in',
|
||||
'Jean-Christian Denis and Contributors',
|
||||
'2.2',
|
||||
'2.3',
|
||||
[
|
||||
'requires' => [['core', '2.28']],
|
||||
'settings' => ['blog' => '#params.' . basename(__DIR__) . '_params'],
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="cinecturlink2">
|
||||
<name>Cinecturlink 2</name>
|
||||
<version>2.2</version>
|
||||
<version>2.3</version>
|
||||
<author>Jean-Christian Denis and Contributors</author>
|
||||
<desc>Widgets and pages about books, musics, films, blogs you are interested in</desc>
|
||||
<file>https://git.dotclear.watch/JcDenis/cinecturlink2/releases/download/v2.2/plugin-cinecturlink2.zip</file>
|
||||
<file>https://git.dotclear.watch/JcDenis/cinecturlink2/releases/download/v2.3/plugin-cinecturlink2.zip</file>
|
||||
<da:dcmin>2.28</da:dcmin>
|
||||
<da:details>https://git.dotclear.watch/JcDenis/cinecturlink2/src/branch/master/README.md</da:details>
|
||||
<da:support>https://git.dotclear.watch/JcDenis/cinecturlink2/issues</da:support>
|
||||
|
|
|
@ -65,35 +65,33 @@ class ActivityReportAction extends Process
|
|||
return true;
|
||||
}
|
||||
|
||||
public static function addLink(Cursor $cur)
|
||||
public static function addLink(Cursor $cur): void
|
||||
{
|
||||
$logs = [
|
||||
$cur->link_title,
|
||||
App::auth()->getInfo('user_cn'),
|
||||
(string) $cur->getField('link_title'),
|
||||
(string) App::auth()->getInfo('user_cn'),
|
||||
];
|
||||
ActivityReport::instance()->addLog('cinecturlink2', 'create', $logs);
|
||||
}
|
||||
|
||||
public static function updLink(Cursor $cur, int $id)
|
||||
public static function updLink(Cursor $cur, int $id): void
|
||||
{
|
||||
$C2 = new Utils();
|
||||
$rs = $C2->getLinks(['link_id' => $id]);
|
||||
$rs = (new Utils())->getLinks(['link_id' => $id]);
|
||||
|
||||
$logs = [
|
||||
$rs->link_title,
|
||||
App::auth()->getInfo('user_cn'),
|
||||
(string) $rs->field('link_title'),
|
||||
(string) App::auth()->getInfo('user_cn'),
|
||||
];
|
||||
ActivityReport::instance()->addLog('cinecturlink2', 'update', $logs);
|
||||
}
|
||||
|
||||
public static function delLink(int $id)
|
||||
public static function delLink(int $id): void
|
||||
{
|
||||
$C2 = new Utils();
|
||||
$rs = $C2->getLinks(['link_id' => $id]);
|
||||
$rs = (new Utils())->getLinks(['link_id' => $id]);
|
||||
|
||||
$logs = [
|
||||
$rs->link_title,
|
||||
App::auth()->getInfo('user_cn'),
|
||||
(string) $rs->field('link_title'),
|
||||
(string) App::auth()->getInfo('user_cn'),
|
||||
];
|
||||
ActivityReport::instance()->addLog('cinecturlink2', 'delete', $logs);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,12 @@ class BackendActionsLinks extends Actions
|
|||
protected bool $use_render = true;
|
||||
public Utils $utils;
|
||||
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @param string $uri The form uri
|
||||
* @param array<string, string> $redirect_args The redirection $_GET arguments,
|
||||
*/
|
||||
public function __construct(string $uri, array $redirect_args = [])
|
||||
{
|
||||
$this->utils = new Utils();
|
||||
|
@ -92,7 +98,7 @@ class BackendActionsLinks extends Actions
|
|||
|
||||
$rs = $this->utils->getLinks($params);
|
||||
while ($rs->fetch()) {
|
||||
$this->entries[$rs->f('link_id')] = $rs->f('link_title');
|
||||
$this->entries[(string) $rs->f('link_id')] = $rs->f('link_title');
|
||||
}
|
||||
$this->rs = $rs;
|
||||
} else {
|
||||
|
|
|
@ -46,6 +46,9 @@ class BackendActionsLinksDefault
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, int|string> $post
|
||||
*/
|
||||
public static function doDeleteLinks(BackendActionsLinks $ap, ArrayObject $post): void
|
||||
{
|
||||
$ids = $ap->getIDs();
|
||||
|
@ -57,7 +60,7 @@ class BackendActionsLinksDefault
|
|||
}
|
||||
|
||||
foreach ($ids as $id) {
|
||||
$ap->utils->delLink($id);
|
||||
$ap->utils->delLink((int) $id);
|
||||
}
|
||||
|
||||
Notices::addSuccessNotice(sprintf(
|
||||
|
@ -71,6 +74,9 @@ class BackendActionsLinksDefault
|
|||
$ap->redirect(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, int|string> $post
|
||||
*/
|
||||
public static function doChangeCategory(BackendActionsLinks $ap, ArrayObject $post): void
|
||||
{
|
||||
if (isset($post['upd_cat_id'])) {
|
||||
|
@ -88,7 +94,7 @@ class BackendActionsLinksDefault
|
|||
foreach ($ids as $id) {
|
||||
$cur->clean();
|
||||
$cur->setField('cat_id', $cat_id == 0 ? null : $cat_id);
|
||||
$ap->utils->updLink($id, $cur);
|
||||
$ap->utils->updLink((int) $id, $cur);
|
||||
}
|
||||
|
||||
Notices::addSuccessNotice(sprintf(
|
||||
|
@ -133,6 +139,9 @@ class BackendActionsLinksDefault
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, int|string> $post
|
||||
*/
|
||||
public static function doChangeNote(BackendActionsLinks $ap, ArrayObject $post): void
|
||||
{
|
||||
if (isset($post['upd_link_note'])) {
|
||||
|
@ -153,7 +162,7 @@ class BackendActionsLinksDefault
|
|||
foreach ($ids as $id) {
|
||||
$cur->clean();
|
||||
$cur->setField('link_note', $link_note);
|
||||
$ap->utils->updLink($id, $cur);
|
||||
$ap->utils->updLink((int) $id, $cur);
|
||||
}
|
||||
|
||||
Notices::addSuccessNotice(sprintf(
|
||||
|
|
|
@ -84,7 +84,7 @@ class BackendListingLinks extends Listing
|
|||
|
||||
$lines = [];
|
||||
while ($this->rs->fetch()) {
|
||||
$lines[] = $this->linkLine(isset($links[$this->rs->link_id]));
|
||||
$lines[] = $this->linkLine(new RecordLinksRow($this->rs), isset($links[$this->rs->f('link_id')]));
|
||||
}
|
||||
|
||||
echo
|
||||
|
@ -112,60 +112,61 @@ class BackendListingLinks extends Listing
|
|||
$pager->getLinks();
|
||||
}
|
||||
|
||||
private function linkLine(bool $checked): Para
|
||||
private function linkLine(RecordLinksRow $row, bool $checked): Para
|
||||
{
|
||||
$cols = new ArrayObject([
|
||||
'check' => (new Td())
|
||||
->class('nowrap minimal')
|
||||
->items([
|
||||
(new Checkbox(['entries[]'], $checked))
|
||||
->value($this->rs->link_id),
|
||||
->value((string) $row->link_id),
|
||||
]),
|
||||
'title' => (new Td())
|
||||
->class('maximal')
|
||||
->items([
|
||||
(new Link())
|
||||
->href(My::manageUrl(['part' => 'link', 'linkid' => $this->rs->link_id, 'redir' => $this->redir]))
|
||||
->href(My::manageUrl(['part' => 'link', 'link_id' => $row->link_id, 'redir' => $this->redir]))
|
||||
->title(__('Edit'))
|
||||
->text(Html::escapeHTML($this->rs->link_title)),
|
||||
->text(Html::escapeHTML($row->link_title)),
|
||||
]),
|
||||
'author' => (new Td())
|
||||
->text(Html::escapeHTML($this->rs->link_author))
|
||||
->text(Html::escapeHTML($row->link_author))
|
||||
->class('nowrap'),
|
||||
'desc' => (new Td())
|
||||
->text(Html::escapeHTML($this->rs->link_desc))
|
||||
->text(Html::escapeHTML($row->link_desc))
|
||||
->class('nowrap'),
|
||||
'link' => (new Text('td'))
|
||||
'link' => (new Td())
|
||||
->separator(' ')
|
||||
->items([
|
||||
(new Link())
|
||||
->href($this->rs->link_url)
|
||||
->href($row->link_url)
|
||||
->title(__('URL'))
|
||||
->text(Html::escapeHTML($this->rs->link_title)),
|
||||
->text(Html::escapeHTML($row->link_title)),
|
||||
(new Link())
|
||||
->href($this->rs->link_img)
|
||||
->href($row->link_img)
|
||||
->title(__('image'))
|
||||
->text(Html::escapeHTML($this->rs->link_title)),
|
||||
]),
|
||||
->text(Html::escapeHTML($row->link_title)),
|
||||
])
|
||||
->class('nowrap'),
|
||||
'cat' => (new Td())
|
||||
->items([
|
||||
(new Link())
|
||||
->href(My::manageUrl(['part' => 'cat', 'catid' => $this->rs->cat_id, 'redir' => $this->redir]))
|
||||
->href(My::manageUrl(['part' => 'cat', 'cat_id' => (string) $row->cat_id, 'redir' => $this->redir]))
|
||||
->title(__('Edit'))
|
||||
->text(Html::escapeHTML($this->rs->cat_title)),
|
||||
->text(Html::escapeHTML($row->cat_title)),
|
||||
]),
|
||||
'note' => (new Td())
|
||||
->text(Html::escapeHTML($this->rs->link_note))
|
||||
->text(Html::escapeHTML($row->link_note))
|
||||
->class('number'),
|
||||
'date' => (new Td())
|
||||
->text(Html::escapeHTML(Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->link_upddt, (string) App::auth()->getInfo('user_tz'))))
|
||||
->text(Html::escapeHTML(Date::dt2str(__('%Y-%m-%d %H:%M'), $row->link_upddt, (string) App::auth()->getInfo('user_tz'))))
|
||||
->class('nowrap'),
|
||||
]);
|
||||
|
||||
$this->userColumns(My::id(), $cols);
|
||||
|
||||
return
|
||||
(new Para('p' . $this->rs->kut_id, 'tr'))
|
||||
(new Para('p' . $row->link_id, 'tr'))
|
||||
->class('line')
|
||||
->items(iterator_to_array($cols));
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ class Combo
|
|||
if (!in_array($file->extension, My::ALLOWED_MEDIA_EXTENSION)) {
|
||||
continue;
|
||||
}
|
||||
$tmp[$file->media_title] = $file->file_url;
|
||||
$tmp[(string) $file->media_title] = (string) $file->file_url;
|
||||
}
|
||||
if (!empty($tmp)) {
|
||||
$stack = array_merge(['-' => ''], $tmp);
|
||||
|
|
|
@ -96,7 +96,6 @@ class Frontend extends Process
|
|||
}
|
||||
} else {
|
||||
foreach (array_merge($blocks, $values) as $v) {
|
||||
pdump($v);
|
||||
App::frontend()->template()->addBlock($v, FrontendTemplate::disable(...));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,26 +15,26 @@ use Dotclear\App;
|
|||
*/
|
||||
class FrontendContext
|
||||
{
|
||||
public static function PaginationNbPages()
|
||||
public static function PaginationNbPages(): int
|
||||
{
|
||||
if (App::frontend()->context()->c2_pagination === null) {
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
$nb_posts = App::frontend()->context()->c2_pagination->f(0);
|
||||
$nb_per_page = App::frontend()->context()->c2_params['limit'][1];
|
||||
$nb_pages = ceil($nb_posts / $nb_per_page);
|
||||
|
||||
return $nb_pages;
|
||||
return (int) $nb_pages;
|
||||
}
|
||||
|
||||
public static function PaginationPosition($offset = 0)
|
||||
public static function PaginationPosition(string|int $offset = 0): int
|
||||
{
|
||||
if (isset($GLOBALS['c2_page_number'])) {
|
||||
$p = $GLOBALS['c2_page_number'];
|
||||
} else {
|
||||
$p = 1;
|
||||
}
|
||||
$p = $p + $offset;
|
||||
$p = (int) $p + (int) $offset;
|
||||
$n = self::PaginationNbPages();
|
||||
if (!$n) {
|
||||
return $p;
|
||||
|
@ -43,25 +43,17 @@ class FrontendContext
|
|||
return $p > $n || $p <= 0 ? 1 : $p;
|
||||
}
|
||||
|
||||
public static function PaginationStart()
|
||||
public static function PaginationStart(): bool
|
||||
{
|
||||
if (isset($GLOBALS['c2_page_number'])) {
|
||||
return self::PaginationPosition() == 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
return isset($GLOBALS['c2_page_number']) ? self::PaginationPosition() == 1 : true;
|
||||
}
|
||||
|
||||
public static function PaginationEnd()
|
||||
public static function PaginationEnd(): bool
|
||||
{
|
||||
if (isset($GLOBALS['c2_page_number'])) {
|
||||
return self::PaginationPosition() == self::PaginationNbPages();
|
||||
}
|
||||
|
||||
return false;
|
||||
return isset($GLOBALS['c2_page_number']) ? self::PaginationPosition() == self::PaginationNbPages() : false;
|
||||
}
|
||||
|
||||
public static function PaginationURL($offset = 0)
|
||||
public static function PaginationURL(int|string $offset = 0): string
|
||||
{
|
||||
$args = $_SERVER['URL_REQUEST_PART'];
|
||||
|
||||
|
@ -84,7 +76,7 @@ class FrontendContext
|
|||
return $url;
|
||||
}
|
||||
|
||||
public static function categoryCurrent()
|
||||
public static function categoryCurrent(): bool
|
||||
{
|
||||
if (!isset(App::frontend()->context()->c2_page_params['cat_id'])
|
||||
&& !isset(App::frontend()->context()->c2_page_params['cat_title'])
|
||||
|
|
|
@ -18,36 +18,57 @@ use Dotclear\Helper\Html\Html;
|
|||
*/
|
||||
class FrontendTemplate
|
||||
{
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function disable(ArrayObject $a, ?string $c = null): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2PageURL(ArrayObject $a): string
|
||||
{
|
||||
return '<?php echo ' . sprintf(App::frontend()->template()->getFilters($a), 'App::blog()->url().App::url()->getBase(\'cinecturlink2\')') . '; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2PageTitle(ArrayObject $a): string
|
||||
{
|
||||
return "<?php \$title = (string) App::blog()->settings()->cinecturlink2->public_title; if (empty(\$title)) { \$title = __('My cinecturlink'); } echo " . sprintf(App::frontend()->template()->getFilters($a), '$title') . '; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2PageFeedURL(ArrayObject $a): string
|
||||
{
|
||||
return '<?php echo ' . sprintf(App::frontend()->template()->getFilters($a), 'App::blog()->url().App::url()->getBase("' . My::id() . '")."/feed/' . (!empty($a['type']) && preg_match('#^(rss2|atom)$#', $a['type']) ? $a['type'] : 'atom') . '"') . '; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2PageFeedID(ArrayObject $a): string
|
||||
{
|
||||
return 'urn:md5:<?php echo md5(App::blog()->id()."' . My::id() . '"); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2PageDescription(ArrayObject $a): string
|
||||
{
|
||||
return '<?php $description = (string) App::blog()->settings()->cinecturlink2->public_description; echo ' . sprintf(App::frontend()->template()->getFilters($a), '$description') . '; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2If(ArrayObject $a, string $c): string
|
||||
{
|
||||
$if = [];
|
||||
|
@ -67,6 +88,9 @@ class FrontendTemplate
|
|||
return empty($if) ? $c : '<?php if(' . implode(' ' . $operator . ' ', $if) . ") : ?>\n" . $c . "<?php endif; ?>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2Entries(ArrayObject $a, string $c): string
|
||||
{
|
||||
$lastn = isset($a['lastn']) ? abs((int) $a['lastn']) + 0 : -1;
|
||||
|
@ -113,16 +137,25 @@ class FrontendTemplate
|
|||
"?>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntriesHeader(ArrayObject $a, string $c): string
|
||||
{
|
||||
return '<?php if (App::frontend()->context()->c2_entries->isStart()) : ?>' . $c . '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntriesFooter(ArrayObject $a, string $c): string
|
||||
{
|
||||
return '<?php if (App::frontend()->context()->c2_entries->isEnd()) : ?>' . $c . '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryIf(ArrayObject $a, string $c): string
|
||||
{
|
||||
$if = [];
|
||||
|
@ -137,96 +170,153 @@ class FrontendTemplate
|
|||
return empty($if) ? $c : '<?php if(' . implode(' ' . $operator . ' ', $if) . ") : ?>\n" . $c . "<?php endif; ?>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryIfFirst(ArrayObject $a): string
|
||||
{
|
||||
return '<?php if (App::frontend()->context()->c2_entries->index() == 0) { echo "' . (isset($a['return']) ? addslashes(Html::escapeHTML($a['return'])) : 'first') . '"; } ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryIfOdd(ArrayObject $a): string
|
||||
{
|
||||
return '<?php if ((App::frontend()->context()->c2_entries->index()+1)%2 == 1) { echo "' . (isset($a['return']) ? addslashes(Html::escapeHTML($a['return'])) : 'odd') . '"; } ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryFeedID(ArrayObject $a): string
|
||||
{
|
||||
return 'urn:md5:<?php echo md5(App::frontend()->context()->c2_entries->blog_id.App::frontend()->context()->c2_entries->link_id.App::frontend()->context()->c2_entries->link_creadt); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryID(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('App::frontend()->context()->c2_entries->link_id', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryTitle(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('App::frontend()->context()->c2_entries->link_title', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryDescription(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('App::frontend()->context()->c2_entries->link_desc', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryAuthorCommonName(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('App::users()->getUserCN(App::frontend()->context()->c2_entries->user_id,App::frontend()->context()->c2_entries->user_name,App::frontend()->context()->c2_entries->user_firstname,App::frontend()->context()->c2_entries->user_displayname)', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryAuthorDisplayName(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('App::frontend()->context()->c2_entries->user_displayname', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryAuthorID(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('App::frontend()->context()->c2_entries->user_id', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryAuthorEmail(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue((isset($a['spam_protected']) && !$a['spam_protected'] ? 'App::frontend()->context()->c2_entries->user_email' : "strtr(App::frontend()->context()->c2_entries->user_email,array('@'=>'%40','.'=>'%2e'))"), $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryAuthorLink(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('sprintf((App::frontend()->context()->c2_entries->user_url ? \'<a href="%2$s">%1$s</a>\' : \'%1$s\'),html::escapeHTML(App::users()->getUserCN(App::frontend()->context()->c2_entries->user_id,App::frontend()->context()->c2_entries->user_name,App::frontend()->context()->c2_entries->user_firstname,App::frontend()->context()->c2_entries->user_displayname)),html::escapeHTML(App::frontend()->context()->c2_entries->user_url))', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryAuthorURL(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('App::frontend()->context()->c2_entries->user_url', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryFromAuthor(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('App::frontend()->context()->c2_entries->link_author', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryLang(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('App::frontend()->context()->c2_entries->link_lang', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryURL(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('App::frontend()->context()->c2_entries->link_url', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryCategory(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('App::frontend()->context()->c2_entries->cat_title', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryCategoryID(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('App::frontend()->context()->c2_entries->cat_id', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryCategoryURL(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('App::blog()->url().App::url()->getBase("' . My::id() . '")."/".App::blog()->settings()->cinecturlink2->public_caturl."/".urlencode(App::frontend()->context()->c2_entries->cat_title)', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryImg(ArrayObject $a): string
|
||||
{
|
||||
$f = App::frontend()->template()->getFilters($a);
|
||||
|
@ -243,6 +333,9 @@ class FrontendTemplate
|
|||
'echo ' . sprintf($f, '$img') . "; unset(\$img); } ?> \n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryDate(ArrayObject $a): string
|
||||
{
|
||||
$format = !empty($a['format']) ? addslashes($a['format']) : '';
|
||||
|
@ -260,11 +353,17 @@ class FrontendTemplate
|
|||
return self::getGenericValue($p, $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2EntryTime(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue('dt::dt2str(' . (!empty($a['format']) ? "'" . addslashes($a['format']) . "'" : 'App::blog()->settings()->system->time_format') . ', App::frontend()->context()->c2_entries->link_creadt)', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2Pagination(ArrayObject $a, string $c): string
|
||||
{
|
||||
$p = "<?php\n" .
|
||||
|
@ -275,16 +374,25 @@ class FrontendTemplate
|
|||
return isset($a['no_context']) ? $p . $c : $p . '<?php if (App::frontend()->context()->c2_pagination->f(0) > App::frontend()->context()->c2_entries->count()) : ?>' . $c . '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2PaginationCounter(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue(FrontendContext::class . '::PaginationNbPages()', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2PaginationCurrent(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue(FrontendContext::class . '::PaginationPosition(' . (isset($a['offset']) ? (int) $a['offset'] : 0) . ')', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2PaginationIf(ArrayObject $a, string $c): string
|
||||
{
|
||||
$if = [];
|
||||
|
@ -301,11 +409,17 @@ class FrontendTemplate
|
|||
return empty($if) ? $c : '<?php if(' . implode(' && ', $if) . ') : ?>' . $c . '<?php endif; ?>';
|
||||
}
|
||||
|
||||
public static function c2PaginationURL($a): string
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2PaginationURL(ArrayObject $a): string
|
||||
{
|
||||
return self::getGenericValue(FrontendContext::class . '::PaginationURL(' . (isset($a['offset']) ? (int) $a['offset'] : 0) . ')', $a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2Categories(ArrayObject $a, string $c): string
|
||||
{
|
||||
return
|
||||
|
@ -317,16 +431,25 @@ class FrontendTemplate
|
|||
"?>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2CategoriesHeader(ArrayObject $a, string $c): string
|
||||
{
|
||||
return '<?php if (App::frontend()->context()->c2_categories->isStart()) : ?>' . $c . '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2CategoriesFooter(ArrayObject $a, string $c): string
|
||||
{
|
||||
return '<?php if (App::frontend()->context()->c2_categories->isEnd()) : ?>' . $c . '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2CategoryIf(ArrayObject $a, string $c): string
|
||||
{
|
||||
$if = [];
|
||||
|
@ -343,6 +466,9 @@ class FrontendTemplate
|
|||
return empty($if) ? $c : '<?php if(' . implode(' && ', $if) . ') : ?>' . $c . '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2CategoryFeedURL(ArrayObject $a): string
|
||||
{
|
||||
$p = !empty($a['type']) ? $a['type'] : 'atom';
|
||||
|
@ -354,31 +480,49 @@ class FrontendTemplate
|
|||
return '<?php echo ' . sprintf(App::frontend()->template()->getFilters($a), 'App::blog()->url().App::url()->getBase("' . My::id() . '")."/".App::blog()->settings()->cinecturlink2->public_caturl."/".urlencode(App::frontend()->context()->c2_categories->cat_title)."/feed/' . $p . '"') . '; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2CategoryFeedID(ArrayObject $a): string
|
||||
{
|
||||
return 'urn:md5:<?php echo md5(App::blog()->id()."' . My::id() . '".App::frontend()->context()->c2_categories->cat_id); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2CategoryID(ArrayObject $a): string
|
||||
{
|
||||
return "<?php if (App::frontend()->context()->exists('c2_categories')) { echo " . sprintf(App::frontend()->template()->getFilters($a), 'App::frontend()->context()->c2_categories->cat_id') . '; } ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2CategoryTitle(ArrayObject $a): string
|
||||
{
|
||||
return "<?php if (App::frontend()->context()->exists('c2_categories')) { echo " . sprintf(App::frontend()->template()->getFilters($a), 'App::frontend()->context()->c2_categories->cat_title') . '; } ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2CategoryDescription(ArrayObject $a): string
|
||||
{
|
||||
return "<?php if (App::frontend()->context()->exists('c2_categories')) { echo " . sprintf(App::frontend()->template()->getFilters($a), 'App::frontend()->context()->c2_categories->cat_desc') . '; } ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2CategoryURL(ArrayObject $a): string
|
||||
{
|
||||
return "<?php if (App::frontend()->context()->exists('c2_categories')) { echo " . sprintf(App::frontend()->template()->getFilters($a), 'App::blog()->url().App::url()->getBase("' . My::id() . '")."/".App::blog()->settings()->cinecturlink2->public_caturl."/".urlencode(App::frontend()->context()->c2_categories->cat_title)') . '; } ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
protected static function getGenericValue(string $p, ArrayObject $a): string
|
||||
{
|
||||
return "<?php if (App::frontend()->context()->exists('c2_entries')) { echo " . sprintf(App::frontend()->template()->getFilters($a), "$p") . '; } ?>';
|
||||
|
|
|
@ -17,7 +17,7 @@ use Dotclear\Helper\File\Path;
|
|||
*/
|
||||
class FrontendUrl extends Url
|
||||
{
|
||||
public static function c2Page(?string $args)
|
||||
public static function c2Page(?string $args): null
|
||||
{
|
||||
$args = (string) $args;
|
||||
|
||||
|
|
|
@ -32,9 +32,7 @@ use Exception;
|
|||
class ManageCat extends Process
|
||||
{
|
||||
private static string $module_redir = '';
|
||||
private static int $catid = 0;
|
||||
private static string $cattitle = '';
|
||||
private static string $catdesc = '';
|
||||
private static RecordCatsRow $row;
|
||||
|
||||
public static function init(): bool
|
||||
{
|
||||
|
@ -47,25 +45,18 @@ class ManageCat extends Process
|
|||
return false;
|
||||
}
|
||||
|
||||
$utils = new Utils();
|
||||
|
||||
self::$module_redir = $_REQUEST['redir'] ?? '';
|
||||
self::$catid = (int) ($_REQUEST['catid'] ?? 0);
|
||||
self::$cattitle = $_POST['cattitle'] ?? '';
|
||||
self::$catdesc = $_POST['catdesc'] ?? '';
|
||||
self::$row = new RecordCatsRow();
|
||||
$utils = new Utils();
|
||||
|
||||
try {
|
||||
// create category
|
||||
if (!empty($_POST['save']) && empty(self::$catid) && !empty(self::$cattitle) && !empty(self::$catdesc)) {
|
||||
$exists = $utils->getCategories(['cat_title' => self::$cattitle], true)->f(0);
|
||||
if (!empty($_POST['save']) && empty(self::$row->cat_id) && !empty(self::$row->cat_title) && !empty(self::$row->cat_desc)) {
|
||||
$exists = $utils->getCategories(['cat_title' => self::$row->cat_title], true)->f(0);
|
||||
if ($exists) {
|
||||
throw new Exception(__('Category with same name already exists.'));
|
||||
}
|
||||
$cur = App::con()->openCursor($utils->cat_table);
|
||||
$cur->setField('cat_title', self::$cattitle);
|
||||
$cur->setField('cat_desc', self::$catdesc);
|
||||
|
||||
$catid = $utils->addCategory($cur);
|
||||
$cat_id = $utils->addCategory(self::$row->getCursor());
|
||||
|
||||
Notices::addSuccessNotice(
|
||||
__('Category successfully created.')
|
||||
|
@ -73,16 +64,12 @@ class ManageCat extends Process
|
|||
My::redirect(['part' => 'cats']);
|
||||
}
|
||||
// update category
|
||||
if (!empty($_POST['save']) && !empty(self::$catid) && !empty(self::$cattitle) && !empty(self::$catdesc)) {
|
||||
$exists = $utils->getCategories(['cat_title' => self::$cattitle, 'exclude_cat_id' => self::$catid], true)->f(0);
|
||||
if (!empty($_POST['save']) && !empty(self::$row->cat_id) && !empty(self::$row->cat_title) && !empty(self::$row->cat_desc)) {
|
||||
$exists = $utils->getCategories(['cat_title' => self::$row->cat_title, 'exclude_cat_id' => self::$row->cat_id], true)->f(0);
|
||||
if ($exists) {
|
||||
throw new Exception(__('Category with same name already exists.'));
|
||||
}
|
||||
$cur = App::con()->openCursor($C2->cat_table);
|
||||
$cur->setField('cat_title', self::$cattitle);
|
||||
$cur->setField('cat_desc', self::$catdesc);
|
||||
|
||||
$utils->updCategory(self::$catid, $cur);
|
||||
$cat_id = $utils->updCategory(self::$row->cat_id, self::$row->getCursor());
|
||||
|
||||
Notices::addSuccessNotice(
|
||||
__('Category successfully updated.')
|
||||
|
@ -90,14 +77,20 @@ class ManageCat extends Process
|
|||
My::redirect(['part' => 'cats']);
|
||||
}
|
||||
// delete category
|
||||
if (!empty($_POST['delete']) && !empty(self::$catid)) {
|
||||
$utils->delCategory(self::$catid);
|
||||
if (!empty($_POST['delete']) && !empty(self::$row->cat_id)) {
|
||||
$utils->delCategory(self::$row->cat_id);
|
||||
|
||||
Notices::addSuccessNotice(
|
||||
__('Category successfully deleted.')
|
||||
);
|
||||
My::redirect(['part' => 'cats']);
|
||||
}
|
||||
|
||||
if (self::$row->cat_id) {
|
||||
self::$row = new RecordCatsRow(
|
||||
$utils->getCategories(['cat_id' => self::$row->cat_id])
|
||||
);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
App::error()->add($e->getMessage());
|
||||
}
|
||||
|
@ -113,21 +106,13 @@ class ManageCat extends Process
|
|||
|
||||
$utils = new Utils();
|
||||
|
||||
if (!empty(self::$catid)) {
|
||||
$category = $utils->getCategories(['cat_id' => self::$catid]);
|
||||
if (!$category->isEmpty()) {
|
||||
self::$cattitle = (string) $category->f('cat_title');
|
||||
self::$catdesc = (string) $category->f('cat_desc');
|
||||
}
|
||||
}
|
||||
|
||||
Page::openModule(My::name());
|
||||
|
||||
echo
|
||||
Page::breadcrumb([
|
||||
__('Plugins') => '',
|
||||
My::name() => My::manageUrl(),
|
||||
(empty(self::$catid) ? __('New category') : __('Edit category')) => '',
|
||||
__('Plugins') => '',
|
||||
My::name() => My::manageUrl(),
|
||||
(empty(self::$row->cat_id) ? __('New category') : __('Edit category')) => '',
|
||||
]) .
|
||||
Notices::getNotices();
|
||||
|
||||
|
@ -142,8 +127,8 @@ class ManageCat extends Process
|
|||
->render();
|
||||
}
|
||||
|
||||
if (self::$catid) {
|
||||
$links = (int) $utils->getLinks(['cat_id' => self::$catid], true)->f(0);
|
||||
if (self::$row->cat_id) {
|
||||
$links = (int) $utils->getLinks(['cat_id' => self::$row->cat_id], true)->f(0);
|
||||
echo (new Note())
|
||||
->class('info')
|
||||
->text(
|
||||
|
@ -161,20 +146,20 @@ class ManageCat extends Process
|
|||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Title:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('cattitle'),
|
||||
(new Input('cattitle'))
|
||||
->for('cat_title'),
|
||||
(new Input('cat_title'))
|
||||
->size(65)
|
||||
->maxlength(64)
|
||||
->value(Html::escapeHTML(self::$cattitle)),
|
||||
->value(Html::escapeHTML(self::$row->cat_title)),
|
||||
]),
|
||||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Description:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('catdesc'),
|
||||
(new Input('catdesc'))
|
||||
->for('cat_desc'),
|
||||
(new Input('cat_desc'))
|
||||
->size(65)
|
||||
->maxlength(64)
|
||||
->value(Html::escapeHTML(self::$catdesc)),
|
||||
->value(Html::escapeHTML(self::$row->cat_desc)),
|
||||
]),
|
||||
(new Para())
|
||||
->class('border-top')
|
||||
|
@ -194,9 +179,9 @@ class ManageCat extends Process
|
|||
->value(__('Delete') . ' (d)')
|
||||
->accesskey('d'),
|
||||
... My::hiddenFields([
|
||||
'catid' => self::$catid,
|
||||
'part' => 'cat',
|
||||
'redir' => self::$module_redir,
|
||||
'cat_id' => self::$row->cat_id,
|
||||
'part' => 'cat',
|
||||
'redir' => self::$module_redir,
|
||||
]),
|
||||
]),
|
||||
])
|
||||
|
|
|
@ -107,7 +107,8 @@ class ManageCats extends Process
|
|||
$items = [];
|
||||
$i = 0;
|
||||
while ($categories->fetch()) {
|
||||
$id = $categories->f('cat_id');
|
||||
$row = new RecordCatsRow($categories);
|
||||
$id = (string) $row->cat_id;
|
||||
|
||||
$items[] = (new Tr('l_' . $i))
|
||||
->class('line')
|
||||
|
@ -120,7 +121,7 @@ class ManageCats extends Process
|
|||
->max($categories->count())
|
||||
->value($i + 1)
|
||||
->class('position')
|
||||
->title(Html::escapeHTML(sprintf(__('position of %s'), (string) $categories->f('cat_title')))),
|
||||
->title(Html::escapeHTML(sprintf(__('position of %s'), $row->cat_title))),
|
||||
(new Hidden(['dynorder[]', 'dynorder-' . $i], $id)),
|
||||
]),
|
||||
(new Td())
|
||||
|
@ -134,19 +135,19 @@ class ManageCats extends Process
|
|||
->items([
|
||||
(new Link())
|
||||
->href(My::manageUrl([
|
||||
'part' => 'cat',
|
||||
'catid' => $id,
|
||||
'redir' => My::manageUrl([
|
||||
'part' => 'cat',
|
||||
'cat_id' => $id,
|
||||
'redir' => My::manageUrl([
|
||||
'part' => 'cats',
|
||||
'redir' => self::$module_redir,
|
||||
]),
|
||||
]))
|
||||
->title(__('Edit'))
|
||||
->text(Html::escapeHTML((string) $categories->f('cat_title'))),
|
||||
->text(Html::escapeHTML($row->cat_title)),
|
||||
]),
|
||||
(new Td())
|
||||
->class('maximal')
|
||||
->text(Html::escapeHTML((string) $categories->f('cat_desc'))),
|
||||
->text(Html::escapeHTML($row->cat_desc)),
|
||||
]);
|
||||
|
||||
$i++;
|
||||
|
@ -187,7 +188,7 @@ class ManageCats extends Process
|
|||
(new Link())
|
||||
->class('button add')
|
||||
->href(My::manageUrl(['part' => 'cat', 'redir' => My::manageUrl(['part' => 'cats'])]))
|
||||
->text(__('New Link')),
|
||||
->text(__('New Category')),
|
||||
])
|
||||
->render();
|
||||
|
||||
|
|
|
@ -36,15 +36,7 @@ use Exception;
|
|||
class ManageLink extends Process
|
||||
{
|
||||
private static string $module_redir = '';
|
||||
private static int $linkid = 0;
|
||||
private static string $linktitle = '';
|
||||
private static string $linkdesc = '';
|
||||
private static string $linkauthor = '';
|
||||
private static string $linkurl = '';
|
||||
private static ?string $linkcat = '';
|
||||
private static string $linklang = '';
|
||||
private static string $linkimage = '';
|
||||
private static string $linknote = '';
|
||||
private static RecordLinksRow $row;
|
||||
|
||||
public static function init(): bool
|
||||
{
|
||||
|
@ -57,18 +49,9 @@ class ManageLink extends Process
|
|||
return false;
|
||||
}
|
||||
|
||||
$utils = new Utils();
|
||||
|
||||
self::$module_redir = $_REQUEST['redir'] ?? '';
|
||||
self::$linkid = (int) ($_REQUEST['linkid'] ?? 0);
|
||||
self::$linktitle = $_POST['linktitle'] ?? '';
|
||||
self::$linkdesc = $_POST['linkdesc'] ?? '';
|
||||
self::$linkauthor = $_POST['linkauthor'] ?? '';
|
||||
self::$linkurl = $_POST['linkurl'] ?? '';
|
||||
self::$linkcat = $_POST['linkcat'] ?? null;
|
||||
self::$linklang = $_POST['linklang'] ?? App::auth()->getInfo('user_lang');
|
||||
self::$linkimage = $_POST['linkimage'] ?? '';
|
||||
self::$linknote = $_POST['linknote'] ?? '';
|
||||
self::$row = new RecordLinksRow();
|
||||
$utils = new Utils();
|
||||
|
||||
if (!empty($_POST['save'])) {
|
||||
try {
|
||||
|
@ -76,44 +59,34 @@ class ManageLink extends Process
|
|||
App::config()->dotclearRoot() . '/' . App::blog()->settings()->system->get('public_path'),
|
||||
My::settings()->folder
|
||||
);
|
||||
if (empty(self::$linktitle)) {
|
||||
if (empty(self::$row->link_title)) {
|
||||
throw new Exception(__('You must provide a title.'));
|
||||
}
|
||||
if (empty(self::$linkauthor)) {
|
||||
if (empty(self::$row->link_author)) {
|
||||
throw new Exception(__('You must provide an author.'));
|
||||
}
|
||||
if (!preg_match('/https?:\/\/.+/', self::$linkimage)) {
|
||||
if (!preg_match('/https?:\/\/.+/', self::$row->link_img)) {
|
||||
//throw new Exception(__('You must provide a link to an image.'));
|
||||
}
|
||||
|
||||
$cur = App::con()->openCursor($utils->table);
|
||||
$cur->setField('link_title', self::$linktitle);
|
||||
$cur->setField('link_desc', self::$linkdesc);
|
||||
$cur->setField('link_author', self::$linkauthor);
|
||||
$cur->setField('link_url', self::$linkurl);
|
||||
$cur->setField('cat_id', self::$linkcat == '' ? null : self::$linkcat);
|
||||
$cur->setField('link_lang', self::$linklang);
|
||||
$cur->setField('link_img', self::$linkimage);
|
||||
$cur->setField('link_note', self::$linknote);
|
||||
|
||||
// create a link
|
||||
if (empty(self::$linkid)) {
|
||||
$exists = $utils->getLinks(['link_title' => self::$linktitle], true)->f(0);
|
||||
if (!self::$row->link_id) {
|
||||
$exists = $utils->getLinks(['link_title' => self::$row->link_title], true)->f(0);
|
||||
if ($exists) {
|
||||
throw new Exception(__('Link with same name already exists.'));
|
||||
}
|
||||
self::$linkid = $utils->addLink($cur);
|
||||
$link_id = $utils->addLink(self::$row->getCursor());
|
||||
|
||||
Notices::addSuccessNotice(
|
||||
__('Link successfully created.')
|
||||
);
|
||||
// update a link
|
||||
} else {
|
||||
$exists = $utils->getLinks(['link_id' => self::$linkid], true)->f(0);
|
||||
$exists = $utils->getLinks(['link_id' => self::$row->link_id], true)->f(0);
|
||||
if (!$exists) {
|
||||
throw new Exception(__('Unknown link.'));
|
||||
}
|
||||
$utils->updLink(self::$linkid, $cur);
|
||||
$link_id = $utils->updLink(self::$row->link_id, self::$row->getCursor());
|
||||
|
||||
Notices::addSuccessNotice(
|
||||
__('Link successfully updated.')
|
||||
|
@ -121,9 +94,9 @@ class ManageLink extends Process
|
|||
}
|
||||
My::redirect(
|
||||
[
|
||||
'part' => 'link',
|
||||
'linkid' => self::$linkid,
|
||||
'redir' => self::$module_redir,
|
||||
'part' => 'link',
|
||||
'link_id' => $link_id,
|
||||
'redir' => self::$module_redir,
|
||||
]
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
|
@ -131,9 +104,9 @@ class ManageLink extends Process
|
|||
}
|
||||
}
|
||||
|
||||
if (!empty($_POST['delete']) && !empty(self::$linkid)) {
|
||||
if (!empty($_POST['delete']) && self::$row->link_id) {
|
||||
try {
|
||||
$utils->delLink(self::$linkid);
|
||||
$utils->delLink(self::$row->link_id);
|
||||
|
||||
Notices::addSuccessNotice(
|
||||
__('Link successfully deleted.')
|
||||
|
@ -148,18 +121,10 @@ class ManageLink extends Process
|
|||
}
|
||||
}
|
||||
|
||||
if (!empty(self::$linkid)) {
|
||||
$link = $utils->getLinks(['link_id' => self::$linkid]);
|
||||
if (!$link->isEmpty()) {
|
||||
self::$linktitle = (string) $link->f('link_title');
|
||||
self::$linkdesc = (string) $link->f('link_desc');
|
||||
self::$linkauthor = (string) $link->f('link_author');
|
||||
self::$linkurl = (string) $link->f('link_url');
|
||||
self::$linkcat = (string) $link->f('cat_id');
|
||||
self::$linklang = (string) $link->f('link_lang');
|
||||
self::$linkimage = (string) $link->f('link_img');
|
||||
self::$linknote = (string) $link->f('link_note');
|
||||
}
|
||||
if (self::$row->link_id) {
|
||||
self::$row = new RecordLinksRow(
|
||||
$utils->getLinks(['link_id' => self::$row->link_id])
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -181,9 +146,9 @@ class ManageLink extends Process
|
|||
|
||||
echo
|
||||
Page::breadcrumb([
|
||||
__('Plugins') => '',
|
||||
My::name() => My::manageUrl(),
|
||||
(empty(self::$linkid) ? __('New link') : __('Edit link')) => '',
|
||||
__('Plugins') => '',
|
||||
My::name() => My::manageUrl(),
|
||||
(empty(self::$row->link_id) ? __('New link') : __('Edit link')) => '',
|
||||
]) .
|
||||
Notices::getNotices();
|
||||
|
||||
|
@ -213,38 +178,38 @@ class ManageLink extends Process
|
|||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Title:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('linktitle'),
|
||||
(new Input('linktitle'))
|
||||
->for('link_title'),
|
||||
(new Input('link_title'))
|
||||
->size(65)
|
||||
->maxlength(255)
|
||||
->value(Html::escapeHTML(self::$linktitle)),
|
||||
->value(Html::escapeHTML(self::$row->link_title)),
|
||||
]),
|
||||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Description:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('linkdesc'),
|
||||
(new Input('linkdesc'))
|
||||
->for('link_desc'),
|
||||
(new Input('link_desc'))
|
||||
->size(65)
|
||||
->maxlength(255)
|
||||
->value(Html::escapeHTML(self::$linkdesc)),
|
||||
->value(Html::escapeHTML(self::$row->link_desc)),
|
||||
]),
|
||||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Author:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('linkauthor'),
|
||||
(new Input('linkauthor'))
|
||||
->for('link_author'),
|
||||
(new Input('link_author'))
|
||||
->size(65)
|
||||
->maxlength(255)
|
||||
->value(Html::escapeHTML(self::$linkauthor)),
|
||||
->value(Html::escapeHTML(self::$row->link_author)),
|
||||
]),
|
||||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Details URL:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('linkurl'),
|
||||
(new Input('linkurl'))
|
||||
->for('link_url'),
|
||||
(new Input('link_url'))
|
||||
->size(65)
|
||||
->maxlength(255)
|
||||
->value(Html::escapeHTML(self::$linkurl)),
|
||||
->value(Html::escapeHTML(self::$row->link_url)),
|
||||
(new Link('newlinksearch'))
|
||||
->class('modal hidden-if-no-js')
|
||||
->href('http://google.com')
|
||||
|
@ -254,11 +219,11 @@ class ManageLink extends Process
|
|||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Image URL:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('linkimage'),
|
||||
(new Input('linkimage'))
|
||||
->for('link_img'),
|
||||
(new Input('link_img'))
|
||||
->size(65)
|
||||
->maxlength(255)
|
||||
->value(Html::escapeHTML(self::$linkimage)),
|
||||
->value(Html::escapeHTML(self::$row->link_img)),
|
||||
(new Link('newimagesearch'))
|
||||
->class('modal hidden-if-no-js')
|
||||
->href('http://amazon.com')
|
||||
|
@ -296,27 +261,27 @@ class ManageLink extends Process
|
|||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Category:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('linkcat'),
|
||||
(new Select('linkcat'))
|
||||
->for('cat_id'),
|
||||
(new Select('cat_id'))
|
||||
->items(Combo::categoriesCombo())
|
||||
->default(self::$linkcat),
|
||||
->default((string) self::$row->cat_id),
|
||||
]),
|
||||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Lang:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('linklang'),
|
||||
(new Select('linklang'))
|
||||
->for('link_lang'),
|
||||
(new Select('link_lang'))
|
||||
->items(Combo::langsCombo())
|
||||
->default(self::$linklang),
|
||||
->default(self::$row->link_lang),
|
||||
]),
|
||||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Rating:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('linknote'),
|
||||
(new Number('linknote'))
|
||||
->for('link_note'),
|
||||
(new Number('link_note'))
|
||||
->min(0)
|
||||
->max(20)
|
||||
->value(self::$linknote),
|
||||
->value(self::$row->link_note),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
|
@ -338,9 +303,9 @@ class ManageLink extends Process
|
|||
->value(__('Delete') . ' (d)')
|
||||
->accesskey('d'),
|
||||
... My::hiddenFields([
|
||||
'linkid' => self::$linkid,
|
||||
'part' => 'link',
|
||||
'redir' => self::$module_redir,
|
||||
'link_id' => self::$row->link_id,
|
||||
'part' => 'link',
|
||||
'redir' => self::$module_redir,
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
|
|
|
@ -10,7 +10,6 @@ use Dotclear\Core\Backend\Filter\{
|
|||
Filters,
|
||||
FiltersLibrary
|
||||
};
|
||||
use Dotclear\Core\Backend\Listing\Listing;
|
||||
use Dotclear\Core\Backend\{
|
||||
Notices,
|
||||
Page
|
||||
|
@ -40,7 +39,7 @@ class ManageLinks extends Process
|
|||
{
|
||||
private static Actions $module_action;
|
||||
private static Filters $module_filter;
|
||||
private static Listing $module_listing;
|
||||
private static BackendListingLinks $module_listing;
|
||||
private static int $module_counter = 0;
|
||||
private static ?bool $module_rendered = null;
|
||||
|
||||
|
@ -67,7 +66,7 @@ class ManageLinks extends Process
|
|||
self::$module_filter->add(FiltersLibrary::getPageFilter());
|
||||
self::$module_filter->add(FiltersLibrary::getSearchFilter());
|
||||
self::$module_filter->add(FiltersLibrary::getSelectFilter(
|
||||
'catid',
|
||||
'cat_id',
|
||||
__('Category:'),
|
||||
Combo::categoriesCombo(),
|
||||
'cat_id'
|
||||
|
@ -171,7 +170,7 @@ class ManageLinks extends Process
|
|||
(new Label(__('Selected links action:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('action'),
|
||||
(new Select('action'))
|
||||
->items(self::$module_action->getCombo()),
|
||||
->items(self::$module_action->getCombo() ?? []),
|
||||
(new Submit('do-action'))
|
||||
->value(__('ok')),
|
||||
... My::hiddenFields(self::$module_filter->values(true)),
|
||||
|
|
|
@ -17,14 +17,14 @@ use Dotclear\Module\MyPlugin;
|
|||
class My extends MyPlugin
|
||||
{
|
||||
/**
|
||||
* Link table name.
|
||||
* Links table name.
|
||||
*
|
||||
* @var string CINECTURLINK_TABLE_NAME
|
||||
*/
|
||||
public const CINECTURLINK_TABLE_NAME = 'cinecturlink2';
|
||||
|
||||
/**
|
||||
* Category table name.
|
||||
* Categories table name.
|
||||
*
|
||||
* @var string CATEGORY_TABLE_NAME
|
||||
*/
|
||||
|
|
|
@ -4,23 +4,30 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\cinecturlink2;
|
||||
|
||||
use ArrayObject;
|
||||
use Dotclear\App;
|
||||
use Dotclear\Plugin\sitemaps\Sitemap;
|
||||
|
||||
/**
|
||||
* @brief cinecturlink2 sitemaps class.
|
||||
* @ingroup cinecturlink2
|
||||
*
|
||||
* Add Cinecturlink public main page and categories pages to plugin sitemap.
|
||||
*
|
||||
* @author Jean-Christian Denis (author)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class PluginSitemaps
|
||||
{
|
||||
public static function sitemapsDefineParts($map_parts)
|
||||
/**
|
||||
* @param ArrayObject<string, string> $map_parts
|
||||
*/
|
||||
public static function sitemapsDefineParts(ArrayObject $map_parts): void
|
||||
{
|
||||
$map_parts->offsetSet(My::name(), My::id());
|
||||
}
|
||||
|
||||
public static function sitemapsURLsCollect($sitemaps)
|
||||
public static function sitemapsURLsCollect(Sitemap $sitemaps): void
|
||||
{
|
||||
if (App::plugins()->moduleExists('cinecturlink2')
|
||||
&& App::blog()->settings()->get('sitemaps')->get('sitemaps_cinecturlink2_url')
|
||||
|
@ -34,7 +41,7 @@ class PluginSitemaps
|
|||
$C2 = new Utils();
|
||||
$cats = $C2->getCategories();
|
||||
while ($cats->fetch()) {
|
||||
$sitemaps->addEntry($base . '/' . My::settings()->get('public_caturl') . '/' . urlencode($cats->cat_title), $prio, $freq);
|
||||
$sitemaps->addEntry($base . '/' . My::settings()->get('public_caturl') . '/' . urlencode((string) $cats->field('cat_title')), $prio, $freq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
41
src/RecordCatsRow.php
Normal file
41
src/RecordCatsRow.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\cinecturlink2;
|
||||
|
||||
use Dotclear\App;
|
||||
use Dotclear\Database\Cursor;
|
||||
use Dotclear\Database\MetaRecord;
|
||||
|
||||
/**
|
||||
* @brief cinecturlink2 record categories row class.
|
||||
* @ingroup cinecturlink2
|
||||
*
|
||||
* @author Jean-Christian Denis (author)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class RecordCatsRow
|
||||
{
|
||||
public readonly int $cat_id;
|
||||
public readonly string $cat_title;
|
||||
public readonly string $cat_desc;
|
||||
public readonly int $cat_pos;
|
||||
|
||||
public function __construct(?MetaRecord $rs = null)
|
||||
{
|
||||
$this->cat_id = (int) ($rs?->field('cat_id') ?? $_REQUEST['cat_id'] ?? 0);
|
||||
$this->cat_title = (string) ($rs?->field('cat_title') ?? $_POST['cat_title'] ?? '');
|
||||
$this->cat_desc = (string) ($rs?->field('cat_desc') ?? $_POST['cat_desc'] ?? '');
|
||||
$this->cat_pos = (int) ($rs?->field('cat_pos') ?? 0);
|
||||
}
|
||||
|
||||
public function getCursor(): Cursor
|
||||
{
|
||||
$cur = App::con()->openCursor(App::con()->prefix() . My::CATEGORY_TABLE_NAME);
|
||||
$cur->setField('cat_title', $this->cat_title);
|
||||
$cur->setField('cat_desc', $this->cat_desc);
|
||||
|
||||
return $cur;
|
||||
}
|
||||
}
|
63
src/RecordLinksRow.php
Normal file
63
src/RecordLinksRow.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\cinecturlink2;
|
||||
|
||||
use Dotclear\App;
|
||||
use Dotclear\Database\Cursor;
|
||||
use Dotclear\Database\MetaRecord;
|
||||
|
||||
/**
|
||||
* @brief cinecturlink2 record links row class.
|
||||
* @ingroup cinecturlink2
|
||||
*
|
||||
* @author Jean-Christian Denis (author)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class RecordLinksRow
|
||||
{
|
||||
public readonly int $link_id;
|
||||
public readonly string $link_title;
|
||||
public readonly string $link_desc;
|
||||
public readonly string $link_author;
|
||||
public readonly string $link_url;
|
||||
public readonly ?int $cat_id;
|
||||
public readonly string $cat_title;
|
||||
public readonly string $link_lang;
|
||||
public readonly string $link_img;
|
||||
public readonly string $link_note;
|
||||
public readonly string $link_upddt;
|
||||
public readonly int $link_count;
|
||||
|
||||
public function __construct(?MetaRecord $rs = null)
|
||||
{
|
||||
$this->link_id = (int) ($rs?->field('link_id') ?? $_REQUEST['link_id'] ?? 0);
|
||||
$this->link_title = (string) ($rs?->field('link_title') ?? $_POST['link_title'] ?? '');
|
||||
$this->link_desc = (string) ($rs?->field('link_desc') ?? $_POST['link_desc'] ?? '');
|
||||
$this->link_author = (string) ($rs?->field('link_author') ?? $_POST['link_author'] ?? '');
|
||||
$this->link_url = (string) ($rs?->field('link_url') ?? $_POST['link_url'] ?? '');
|
||||
$this->cat_id = $rs?->field('cat_id') ? (int) $rs->field('cat_id') : (isset($_POST['cat_id']) ? (int) $_POST['cat_id'] : null);
|
||||
$this->cat_title = (string) ($rs?->field('cat_title') ?? $_POST['cat_title'] ?? '');
|
||||
$this->link_lang = (string) ($rs?->field('link_lang') ?? $_POST['link_lang'] ?? App::auth()->getInfo('user_lang'));
|
||||
$this->link_img = (string) ($rs?->field('link_img') ?? $_POST['link_img'] ?? '');
|
||||
$this->link_note = (string) ($rs?->field('link_note') ?? $_POST['link_note'] ?? '');
|
||||
$this->link_upddt = (string) ($rs?->field('link_upddt') ?? '');
|
||||
$this->link_count = abs((int) $rs?->field('link_count'));
|
||||
}
|
||||
|
||||
public function getCursor(): Cursor
|
||||
{
|
||||
$cur = App::con()->openCursor(App::con()->prefix() . My::CINECTURLINK_TABLE_NAME);
|
||||
$cur->setField('link_title', $this->link_title);
|
||||
$cur->setField('link_desc', $this->link_desc);
|
||||
$cur->setField('link_author', $this->link_author);
|
||||
$cur->setField('link_url', $this->link_url);
|
||||
$cur->setField('cat_id', $this->cat_id);
|
||||
$cur->setField('link_lang', $this->link_lang);
|
||||
$cur->setField('link_img', $this->link_img);
|
||||
$cur->setField('link_note', $this->link_note);
|
||||
|
||||
return $cur;
|
||||
}
|
||||
}
|
|
@ -72,8 +72,9 @@ class Utils
|
|||
/**
|
||||
* Get links.
|
||||
*
|
||||
* @param array $params Query params
|
||||
* @param bool $count_only Count only result
|
||||
* @param array<string, mixed> $params Query params
|
||||
* @param bool $count_only Count only result
|
||||
*
|
||||
* @return MetaRecord MetaRecord instance
|
||||
*/
|
||||
public function getLinks(array $params = [], bool $count_only = false): MetaRecord
|
||||
|
@ -264,8 +265,10 @@ class Utils
|
|||
* @param int $id Link ID
|
||||
* @param Cursor $cur Cursor instance
|
||||
* @param bool $behavior Call related behaviors
|
||||
*
|
||||
* @return int The link ID
|
||||
*/
|
||||
public function updLink(int $id, Cursor $cur, bool $behavior = true): void
|
||||
public function updLink(int $id, Cursor $cur, bool $behavior = true): int
|
||||
{
|
||||
if (empty($id)) {
|
||||
throw new Exception(__('No such link ID'));
|
||||
|
@ -283,6 +286,8 @@ class Utils
|
|||
# --BEHAVIOR-- cinecturlink2AfterUpdLink
|
||||
App::behavior()->callBehavior('cinecturlink2AfterUpdLink', $cur, $id);
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -318,18 +323,20 @@ class Utils
|
|||
{
|
||||
$sql = new SelectStatement();
|
||||
|
||||
return $sql
|
||||
$rs = $sql
|
||||
->column($sql->max('link_id'))
|
||||
->from($this->table)
|
||||
->select()
|
||||
->f(0) + 1;
|
||||
->select();
|
||||
|
||||
return is_null($rs) ? 1 : (int) $rs->f(0) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get categories.
|
||||
*
|
||||
* @param array $params Query params
|
||||
* @param bool $count_only Count only result
|
||||
* @param array<string, mixed> $params Query params
|
||||
* @param bool $count_only Count only result
|
||||
*
|
||||
* @return MetaRecord Record instance
|
||||
*/
|
||||
public function getCategories(array $params = [], bool $count_only = false): MetaRecord
|
||||
|
@ -451,8 +458,10 @@ class Utils
|
|||
*
|
||||
* @param int $id Category ID
|
||||
* @param Cursor $cur Cursor instance
|
||||
*
|
||||
* @return int The category ID
|
||||
*/
|
||||
public function updCategory(int $id, Cursor $cur): void
|
||||
public function updCategory(int $id, Cursor $cur): int
|
||||
{
|
||||
if (empty($id)) {
|
||||
throw new Exception(__('No such category ID'));
|
||||
|
@ -467,6 +476,8 @@ class Utils
|
|||
->update($cur);
|
||||
|
||||
$this->trigger();
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -510,11 +521,12 @@ class Utils
|
|||
{
|
||||
$sql = new SelectStatement();
|
||||
|
||||
return $sql
|
||||
$rs = $sql
|
||||
->column($sql->max('cat_id'))
|
||||
->from($this->cat_table)
|
||||
->select()
|
||||
->f(0) + 1;
|
||||
->select();
|
||||
|
||||
return is_null($rs) ? 1 : (int) $rs->f(0) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -526,12 +538,13 @@ class Utils
|
|||
{
|
||||
$sql = new SelectStatement();
|
||||
|
||||
return $sql
|
||||
$rs = $sql
|
||||
->column($sql->max('cat_pos'))
|
||||
->from($this->cat_table)
|
||||
->where('blog_id = ' . $sql->quote($this->blog))
|
||||
->select()
|
||||
->f(0) + 1;
|
||||
->select();
|
||||
|
||||
return is_null($rs) ? 1 : (int) $rs->f(0) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -569,12 +582,15 @@ class Utils
|
|||
/**
|
||||
* Get list of public directories.
|
||||
*
|
||||
* @return array<string,string> Directories
|
||||
* @return array<string, string> Directories
|
||||
*/
|
||||
public static function getPublicDirs(): array
|
||||
{
|
||||
$dirs = [];
|
||||
$all = Files::getDirList(App::blog()->publicPath());
|
||||
if (empty($all['dirs'])) {
|
||||
return $dirs;
|
||||
}
|
||||
foreach ($all['dirs'] as $dir) {
|
||||
$dir = substr($dir, strlen(App::blog()->publicPath()) + 1);
|
||||
$dirs[$dir] = $dir;
|
||||
|
|
32
src/WidgetCatsDescriptor.php
Normal file
32
src/WidgetCatsDescriptor.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\cinecturlink2;
|
||||
|
||||
use Dotclear\Plugin\widgets\WidgetsElement;
|
||||
|
||||
/**
|
||||
* @brief cinecturlink2 widget categories descriptor class.
|
||||
* @ingroup cinecturlink2
|
||||
*
|
||||
* @author Jean-Christian Denis (author)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class WidgetCatsDescriptor
|
||||
{
|
||||
public readonly string $title;
|
||||
public readonly string $class;
|
||||
public readonly bool $content_only;
|
||||
|
||||
public readonly bool $shownumlink;
|
||||
|
||||
public function __construct(WidgetsElement $w)
|
||||
{
|
||||
$this->title = (string) $w->get('title');
|
||||
$this->class = (string) $w->get('class');
|
||||
$this->content_only = !empty($w->get('content_only'));
|
||||
|
||||
$this->shownumlink = !empty($w->get('shownumlink'));
|
||||
}
|
||||
}
|
48
src/WidgetLinksDescriptor.php
Normal file
48
src/WidgetLinksDescriptor.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\cinecturlink2;
|
||||
|
||||
use Dotclear\Plugin\widgets\WidgetsElement;
|
||||
|
||||
/**
|
||||
* @brief cinecturlink2 widget links descriptor class.
|
||||
* @ingroup cinecturlink2
|
||||
*
|
||||
* @author Jean-Christian Denis (author)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class WidgetLinksDescriptor
|
||||
{
|
||||
public readonly string $title;
|
||||
public readonly string $class;
|
||||
public readonly bool $content_only;
|
||||
|
||||
public readonly string $category;
|
||||
public readonly string $sortby;
|
||||
public readonly string $sort;
|
||||
public readonly int $limit;
|
||||
public readonly bool $shownote;
|
||||
public readonly bool $showdesc;
|
||||
public readonly bool $withlink;
|
||||
public readonly bool $showauthor;
|
||||
public readonly bool $showpagelink;
|
||||
|
||||
public function __construct(WidgetsElement $w)
|
||||
{
|
||||
$this->title = (string) $w->get('title');
|
||||
$this->class = (string) $w->get('class');
|
||||
$this->content_only = !empty($w->get('content_only'));
|
||||
|
||||
$this->category = (string) $w->get('category');
|
||||
$this->sortby = (string) $w->get('sortby');
|
||||
$this->sort = $w->get('sort') == 'desc' ? 'desc' : 'asc';
|
||||
$this->limit = abs((int) $w->get('limit'));
|
||||
$this->shownote = !empty($w->get('shownote'));
|
||||
$this->showdesc = !empty($w->get('showdesc'));
|
||||
$this->withlink = !empty($w->get('withlink'));
|
||||
$this->showauthor = !empty($w->get('showauthor'));
|
||||
$this->showpagelink = !empty($w->get('showpagelink'));
|
||||
}
|
||||
}
|
153
src/Widgets.php
153
src/Widgets.php
|
@ -8,6 +8,7 @@ use Dotclear\App;
|
|||
use Dotclear\Helper\Html\Html;
|
||||
use Dotclear\Plugin\widgets\WidgetsStack;
|
||||
use Dotclear\Plugin\widgets\WidgetsElement;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @brief cinecturlink2 widgets class.
|
||||
|
@ -18,6 +19,20 @@ use Dotclear\Plugin\widgets\WidgetsElement;
|
|||
*/
|
||||
class Widgets
|
||||
{
|
||||
/**
|
||||
* Widget cinecturlink links ID.
|
||||
*
|
||||
* @var string WIDGET_ID_LINKS
|
||||
*/
|
||||
private const WIDGET_ID_LINKS = 'cinecturlink2links';
|
||||
|
||||
/**
|
||||
* Widget cinecturlink categories ID.
|
||||
*
|
||||
* @var string WIDGET_ID_CATS
|
||||
*/
|
||||
private const WIDGET_ID_CATS = 'cinecturlink2cats';
|
||||
|
||||
public static function init(WidgetsStack $w): void
|
||||
{
|
||||
$categories_combo = array_merge(
|
||||
|
@ -39,7 +54,7 @@ class Widgets
|
|||
|
||||
$w
|
||||
->create(
|
||||
'cinecturlink2links',
|
||||
self::WIDGET_ID_LINKS,
|
||||
__('My cinecturlink'),
|
||||
self::parseLinks(...),
|
||||
null,
|
||||
|
@ -112,7 +127,7 @@ class Widgets
|
|||
|
||||
$w
|
||||
->create(
|
||||
'cinecturlink2cats',
|
||||
self::WIDGET_ID_CATS,
|
||||
__('List of categories of cinecturlink'),
|
||||
self::parseCats(...),
|
||||
null,
|
||||
|
@ -139,30 +154,29 @@ class Widgets
|
|||
->addOffline();
|
||||
}
|
||||
|
||||
public static function parseLinks(WidgetsElement $w): string
|
||||
public static function parseLinks(WidgetsElement $widget): string
|
||||
{
|
||||
if (!My::settings()->avtive
|
||||
|| !$w->checkHomeOnly(App::url()->type)
|
||||
if (!My::settings()->get('active')
|
||||
|| !$widget->checkHomeOnly(App::url()->type)
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$C2 = new Utils();
|
||||
$wdesc = new WidgetLinksDescriptor($widget);
|
||||
$utils = new Utils();
|
||||
$params = [];
|
||||
|
||||
if ($w->category) {
|
||||
if ($w->category == 'null') {
|
||||
if ($wdesc->category) {
|
||||
if ($wdesc->category == 'null') {
|
||||
$params['sql'] = ' AND L.cat_id IS NULL ';
|
||||
} elseif (is_numeric($w->category)) {
|
||||
$params['cat_id'] = (int) $w->category;
|
||||
} elseif (is_numeric($wdesc->category)) {
|
||||
$params['cat_id'] = (int) $wdesc->category;
|
||||
}
|
||||
}
|
||||
|
||||
$limit = abs((int) $w->limit);
|
||||
|
||||
// Tirage aléatoire: Consomme beaucoup de ressources!
|
||||
if ($w->sortby == 'RANDOM') {
|
||||
$big_rs = $C2->getLinks($params);
|
||||
if ($wdesc->sortby == 'RANDOM') {
|
||||
$big_rs = $utils->getLinks($params);
|
||||
|
||||
if ($big_rs->isEmpty()) {
|
||||
return '';
|
||||
|
@ -173,94 +187,93 @@ class Widgets
|
|||
$ids[] = $big_rs->link_id;
|
||||
}
|
||||
shuffle($ids);
|
||||
$ids = array_slice($ids, 0, $limit);
|
||||
$ids = array_slice($ids, 0, $wdesc->limit);
|
||||
|
||||
$params['link_id'] = [];
|
||||
foreach ($ids as $id) {
|
||||
$params['link_id'][] = $id;
|
||||
}
|
||||
} elseif ($w->sortby == 'COUNTER') {
|
||||
} elseif ($wdesc->sortby == 'COUNTER') {
|
||||
$params['order'] = 'link_count asc';
|
||||
$params['limit'] = $limit;
|
||||
$params['limit'] = $wdesc->limit;
|
||||
} else {
|
||||
$params['order'] = $w->sortby;
|
||||
$params['order'] .= $w->sort == 'asc' ? ' asc' : ' desc';
|
||||
$params['limit'] = $limit;
|
||||
$params['order'] = $wdesc->sortby . ' ' . $wdesc->sort;
|
||||
$params['limit'] = $wdesc->limit;
|
||||
}
|
||||
|
||||
$rs = $C2->getLinks($params);
|
||||
$rs = $utils->getLinks($params);
|
||||
|
||||
if ($rs->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$widthmax = (int) My::settings()->widthmax;
|
||||
$widthmax = (int) My::settings()->get('widthmax');
|
||||
$style = $widthmax ? ' style="width:' . $widthmax . 'px;"' : '';
|
||||
|
||||
$entries = [];
|
||||
while ($rs->fetch()) {
|
||||
$url = $rs->link_url;
|
||||
$img = $rs->link_img;
|
||||
$title = Html::escapeHTML($rs->link_title);
|
||||
$author = Html::escapeHTML($rs->link_author);
|
||||
$cat = Html::escapeHTML($rs->cat_title);
|
||||
$note = $w->shownote ? ' <em>(' . $rs->link_note . '/20)</em>' : '';
|
||||
$desc = $w->showdesc ? '<br /><em>' . Html::escapeHTML($rs->link_desc) . '</em>' : '';
|
||||
$lang = $rs->link_lang ? ' hreflang="' . $rs->link_lang . '"' : '';
|
||||
$count = abs((int) $rs->link_count);
|
||||
$row = new RecordLinksRow($rs);
|
||||
|
||||
# --BEHAVIOR-- cinecturlink2WidgetLinks
|
||||
$bhv = App::behavior()->callBehavior('cinecturlink2WidgetLinks', $rs->link_id);
|
||||
$bhv = App::behavior()->callBehavior('cinecturlink2WidgetLinks', $row->link_id);
|
||||
|
||||
$entries[] = '<p style="text-align:center;">' .
|
||||
($w->withlink && !empty($url) ? '<a href="' . $url . '"' . $lang . ' title="' . $cat . '">' : '') .
|
||||
'<strong>' . $title . '</strong>' . $note . '<br />' .
|
||||
($w->showauthor ? $author . '<br />' : '') . '<br />' .
|
||||
'<img src="' . $img . '" alt="' . $title . ' - ' . $author . '"' . $style . ' />' .
|
||||
$desc .
|
||||
($w->withlink && !empty($url) ? '</a>' : '') .
|
||||
'</p>' . $bhv;
|
||||
$tmp = '';
|
||||
if ($wdesc->withlink && !empty($row->link_url)) {
|
||||
$tmp .= '<a href="' . $row->link_url . '"' . ($row->link_lang ? ' hreflang="' . $row->link_lang . '"' : '') . ' title="' . Html::escapeHTML($row->cat_title) . '">';
|
||||
}
|
||||
$tmp .= '<strong>' . Html::escapeHTML($row->link_title) . '</strong>' . ($wdesc->shownote ? ' <em>(' . $row->link_note . '/20)</em>' : '') . '<br />';
|
||||
if ($wdesc->showauthor) {
|
||||
$tmp .= Html::escapeHTML($row->link_author) . '<br />';
|
||||
}
|
||||
$tmp .= '<br /><img src="' . $row->link_img . '" alt="' . Html::escapeHTML($row->link_title) . ' - ' . Html::escapeHTML($row->link_author) . '"' . $style . ' />';
|
||||
if ($wdesc->showdesc) {
|
||||
$tmp .= '<br /><em>' . Html::escapeHTML($row->link_desc) . '</em>';
|
||||
}
|
||||
if ($wdesc->withlink && !empty($row->link_url)) {
|
||||
$tmp .= '</a>';
|
||||
}
|
||||
|
||||
$entries[] = '<p style="text-align:center;">' . $tmp . '</p>' . $bhv;
|
||||
|
||||
try {
|
||||
$cur = App::con()->openCursor($C2->table);
|
||||
$cur->link_count = ($count + 1);
|
||||
$C2->updLink((int) $rs->link_id, $cur, false);
|
||||
} catch (Exception $e) {
|
||||
$cur = App::con()->openCursor($utils->table);
|
||||
$cur->setField('link_count', ($row->link_count + 1));
|
||||
$utils->updLink($row->link_id, $cur, false);
|
||||
} catch (Exception) {
|
||||
}
|
||||
}
|
||||
# Tirage aléatoire
|
||||
if ($w->sortby == 'RANDOM'
|
||||
|| $w->sortby == 'COUNTER'
|
||||
) {
|
||||
if (in_array($wdesc->sortby, ['RANDOM', 'COUNTER'])) {
|
||||
shuffle($entries);
|
||||
if (My::settings()->triggeronrandom) {
|
||||
if (My::settings()->get('triggeronrandom')) {
|
||||
App::blog()->triggerBlog();
|
||||
}
|
||||
}
|
||||
|
||||
return $w->renderDiv(
|
||||
(bool) $w->content_only,
|
||||
'cinecturlink2list ' . $w->class,
|
||||
return $widget->renderDiv(
|
||||
$wdesc->content_only,
|
||||
$widget->id() . ' ' . $wdesc->class,
|
||||
'',
|
||||
($w->title ? $w->renderTitle(Html::escapeHTML($w->title)) : '') . implode(' ', $entries) .
|
||||
($wdesc->title ? $widget->renderTitle(Html::escapeHTML($wdesc->title)) : '') . implode(' ', $entries) .
|
||||
(
|
||||
$w->showpagelink && My::settings()->public_active ?
|
||||
$wdesc->showpagelink && My::settings()->get('public_active') ?
|
||||
'<p><a href="' . App::blog()->url() . App::url()->getBase(My::id()) . '" title="' . __('view all links') . '">' . __('More links') . '</a></p>' : ''
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function parseCats(WidgetsElement $w): string
|
||||
public static function parseCats(WidgetsElement $widget): string
|
||||
{
|
||||
if (!My::settings()->avtive
|
||||
|| !My::settings()->public_active
|
||||
|| !$w->checkHomeOnly(App::url()->type)
|
||||
if (!My::settings()->get('active')
|
||||
|| !My::settings()->get('public_active')
|
||||
|| !$widget->checkHomeOnly(App::url()->type)
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$C2 = new Utils();
|
||||
$rs = $C2->getCategories([]);
|
||||
$wdesc = new WidgetCatsDescriptor($widget);
|
||||
$utils = new Utils();
|
||||
$rs = $utils->getCategories([]);
|
||||
if ($rs->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
|
@ -269,26 +282,28 @@ class Widgets
|
|||
$res[] = '<li><a href="' .
|
||||
App::blog()->url() . App::url()->getBase(My::id()) .
|
||||
'" title="' . __('view all links') . '">' . __('all links') .
|
||||
'</a>' . ($w->shownumlink ? ' (' . ($C2->getLinks([], true)->f(0)) . ')' : '') .
|
||||
'</a>' . ($wdesc->shownumlink ? ' (' . ($utils->getLinks([], true)->f(0)) . ')' : '') .
|
||||
'</li>';
|
||||
|
||||
while ($rs->fetch()) {
|
||||
$row = new RecordCatsRow($rs);
|
||||
|
||||
$res[] = '<li><a href="' .
|
||||
App::blog()->url() . App::url()->getBase('cinecturlink2') . '/' .
|
||||
My::settings()->public_caturl . '/' .
|
||||
urlencode($rs->cat_title) .
|
||||
My::settings()->get('public_caturl') . '/' .
|
||||
urlencode($row->cat_title) .
|
||||
'" title="' . __('view links of this category') . '">' .
|
||||
Html::escapeHTML($rs->cat_title) .
|
||||
'</a>' . ($w->shownumlink ? ' (' .
|
||||
($C2->getLinks(['cat_id' => $rs->cat_id], true)->f(0)) . ')' : '') .
|
||||
Html::escapeHTML($row->cat_title) .
|
||||
'</a>' . ($wdesc->shownumlink ? ' (' .
|
||||
($utils->getLinks(['cat_id' => $row->cat_id], true)->f(0)) . ')' : '') .
|
||||
'</li>';
|
||||
}
|
||||
|
||||
return $w->renderDiv(
|
||||
(bool) $w->content_only,
|
||||
'cinecturlink2cat ' . $w->class,
|
||||
return $widget->renderDiv(
|
||||
$wdesc->content_only,
|
||||
$widget->id() . ' ' . $wdesc->class,
|
||||
'',
|
||||
($w->title ? $w->renderTitle(Html::escapeHTML($w->title)) : '') .
|
||||
($wdesc->title ? $widget->renderTitle(Html::escapeHTML($wdesc->title)) : '') .
|
||||
'<ul>' . implode(' ', $res) . '</ul>'
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue