Compare commits
No commits in common. "52a60eb47a48b9e3cf022bdb81593c16be2299d3" and "2230589ea03f6ce170ba8dcd7c85779e6f9b63c4" have entirely different histories.
52a60eb47a
...
2230589ea0
|
@ -1,11 +1,3 @@
|
|||
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.3-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/cinecturlink2/releases)
|
||||
![Date](https://img.shields.io/badge/date-2023.10.23-c44d58.svg)]
|
||||
[![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)]
|
||||
[![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.3',
|
||||
'2.2',
|
||||
[
|
||||
'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.3</version>
|
||||
<version>2.2</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.3/plugin-cinecturlink2.zip</file>
|
||||
<file>https://git.dotclear.watch/JcDenis/cinecturlink2/releases/download/v2.2/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,33 +65,35 @@ class ActivityReportAction extends Process
|
|||
return true;
|
||||
}
|
||||
|
||||
public static function addLink(Cursor $cur): void
|
||||
public static function addLink(Cursor $cur)
|
||||
{
|
||||
$logs = [
|
||||
(string) $cur->getField('link_title'),
|
||||
(string) App::auth()->getInfo('user_cn'),
|
||||
$cur->link_title,
|
||||
App::auth()->getInfo('user_cn'),
|
||||
];
|
||||
ActivityReport::instance()->addLog('cinecturlink2', 'create', $logs);
|
||||
}
|
||||
|
||||
public static function updLink(Cursor $cur, int $id): void
|
||||
public static function updLink(Cursor $cur, int $id)
|
||||
{
|
||||
$rs = (new Utils())->getLinks(['link_id' => $id]);
|
||||
$C2 = new Utils();
|
||||
$rs = $C2->getLinks(['link_id' => $id]);
|
||||
|
||||
$logs = [
|
||||
(string) $rs->field('link_title'),
|
||||
(string) App::auth()->getInfo('user_cn'),
|
||||
$rs->link_title,
|
||||
App::auth()->getInfo('user_cn'),
|
||||
];
|
||||
ActivityReport::instance()->addLog('cinecturlink2', 'update', $logs);
|
||||
}
|
||||
|
||||
public static function delLink(int $id): void
|
||||
public static function delLink(int $id)
|
||||
{
|
||||
$rs = (new Utils())->getLinks(['link_id' => $id]);
|
||||
$C2 = new Utils();
|
||||
$rs = $C2->getLinks(['link_id' => $id]);
|
||||
|
||||
$logs = [
|
||||
(string) $rs->field('link_title'),
|
||||
(string) App::auth()->getInfo('user_cn'),
|
||||
$rs->link_title,
|
||||
App::auth()->getInfo('user_cn'),
|
||||
];
|
||||
ActivityReport::instance()->addLog('cinecturlink2', 'delete', $logs);
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ class Backend extends Process
|
|||
->for(My::id() . 'newdir'),
|
||||
(new Input(My::id() . 'newdir'))
|
||||
->size(65)
|
||||
->maxlength(255)
|
||||
->maxlenght(255)
|
||||
->value(''),
|
||||
]),
|
||||
(new Para())
|
||||
|
@ -171,7 +171,7 @@ class Backend extends Process
|
|||
->for(My::id() . 'public_title'),
|
||||
(new Input(My::id() . 'public_title'))
|
||||
->size(65)
|
||||
->maxlength(255)
|
||||
->maxlenght(255)
|
||||
->value((string) $s->get('public_title')),
|
||||
]),
|
||||
(new Para())
|
||||
|
@ -180,7 +180,7 @@ class Backend extends Process
|
|||
->for(My::id() . 'public_description'),
|
||||
(new Input(My::id() . 'public_description'))
|
||||
->size(65)
|
||||
->maxlength(255)
|
||||
->maxlenght(255)
|
||||
->value((string) $s->get('public_description')),
|
||||
]),
|
||||
(new Para())
|
||||
|
|
|
@ -27,12 +27,6 @@ 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();
|
||||
|
@ -98,7 +92,7 @@ class BackendActionsLinks extends Actions
|
|||
|
||||
$rs = $this->utils->getLinks($params);
|
||||
while ($rs->fetch()) {
|
||||
$this->entries[(string) $rs->f('link_id')] = $rs->f('link_title');
|
||||
$this->entries[$rs->f('link_id')] = $rs->f('link_title');
|
||||
}
|
||||
$this->rs = $rs;
|
||||
} else {
|
||||
|
|
|
@ -46,9 +46,6 @@ class BackendActionsLinksDefault
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, int|string> $post
|
||||
*/
|
||||
public static function doDeleteLinks(BackendActionsLinks $ap, ArrayObject $post): void
|
||||
{
|
||||
$ids = $ap->getIDs();
|
||||
|
@ -60,7 +57,7 @@ class BackendActionsLinksDefault
|
|||
}
|
||||
|
||||
foreach ($ids as $id) {
|
||||
$ap->utils->delLink((int) $id);
|
||||
$ap->utils->delLink($id);
|
||||
}
|
||||
|
||||
Notices::addSuccessNotice(sprintf(
|
||||
|
@ -74,9 +71,6 @@ 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'])) {
|
||||
|
@ -94,7 +88,7 @@ class BackendActionsLinksDefault
|
|||
foreach ($ids as $id) {
|
||||
$cur->clean();
|
||||
$cur->setField('cat_id', $cat_id == 0 ? null : $cat_id);
|
||||
$ap->utils->updLink((int) $id, $cur);
|
||||
$ap->utils->updLink($id, $cur);
|
||||
}
|
||||
|
||||
Notices::addSuccessNotice(sprintf(
|
||||
|
@ -139,9 +133,6 @@ class BackendActionsLinksDefault
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, int|string> $post
|
||||
*/
|
||||
public static function doChangeNote(BackendActionsLinks $ap, ArrayObject $post): void
|
||||
{
|
||||
if (isset($post['upd_link_note'])) {
|
||||
|
@ -162,7 +153,7 @@ class BackendActionsLinksDefault
|
|||
foreach ($ids as $id) {
|
||||
$cur->clean();
|
||||
$cur->setField('link_note', $link_note);
|
||||
$ap->utils->updLink((int) $id, $cur);
|
||||
$ap->utils->updLink($id, $cur);
|
||||
}
|
||||
|
||||
Notices::addSuccessNotice(sprintf(
|
||||
|
|
|
@ -84,7 +84,7 @@ class BackendListingLinks extends Listing
|
|||
|
||||
$lines = [];
|
||||
while ($this->rs->fetch()) {
|
||||
$lines[] = $this->linkLine(new RecordLinksRow($this->rs), isset($links[$this->rs->f('link_id')]));
|
||||
$lines[] = $this->linkLine(isset($links[$this->rs->link_id]));
|
||||
}
|
||||
|
||||
echo
|
||||
|
@ -112,61 +112,60 @@ class BackendListingLinks extends Listing
|
|||
$pager->getLinks();
|
||||
}
|
||||
|
||||
private function linkLine(RecordLinksRow $row, bool $checked): Para
|
||||
private function linkLine(bool $checked): Para
|
||||
{
|
||||
$cols = new ArrayObject([
|
||||
'check' => (new Td())
|
||||
->class('nowrap minimal')
|
||||
->items([
|
||||
(new Checkbox(['entries[]'], $checked))
|
||||
->value((string) $row->link_id),
|
||||
->value($this->rs->link_id),
|
||||
]),
|
||||
'title' => (new Td())
|
||||
->class('maximal')
|
||||
->items([
|
||||
(new Link())
|
||||
->href(My::manageUrl(['part' => 'link', 'link_id' => $row->link_id, 'redir' => $this->redir]))
|
||||
->href(My::manageUrl(['part' => 'link', 'linkid' => $this->rs->link_id, 'redir' => $this->redir]))
|
||||
->title(__('Edit'))
|
||||
->text(Html::escapeHTML($row->link_title)),
|
||||
->text(Html::escapeHTML($this->rs->link_title)),
|
||||
]),
|
||||
'author' => (new Td())
|
||||
->text(Html::escapeHTML($row->link_author))
|
||||
->text(Html::escapeHTML($this->rs->link_author))
|
||||
->class('nowrap'),
|
||||
'desc' => (new Td())
|
||||
->text(Html::escapeHTML($row->link_desc))
|
||||
->text(Html::escapeHTML($this->rs->link_desc))
|
||||
->class('nowrap'),
|
||||
'link' => (new Td())
|
||||
'link' => (new Text('td'))
|
||||
->separator(' ')
|
||||
->items([
|
||||
(new Link())
|
||||
->href($row->link_url)
|
||||
->href($this->rs->link_url)
|
||||
->title(__('URL'))
|
||||
->text(Html::escapeHTML($row->link_title)),
|
||||
->text(Html::escapeHTML($this->rs->link_title)),
|
||||
(new Link())
|
||||
->href($row->link_img)
|
||||
->href($this->rs->link_img)
|
||||
->title(__('image'))
|
||||
->text(Html::escapeHTML($row->link_title)),
|
||||
])
|
||||
->class('nowrap'),
|
||||
->text(Html::escapeHTML($this->rs->link_title)),
|
||||
]),
|
||||
'cat' => (new Td())
|
||||
->items([
|
||||
(new Link())
|
||||
->href(My::manageUrl(['part' => 'cat', 'cat_id' => (string) $row->cat_id, 'redir' => $this->redir]))
|
||||
->href(My::manageUrl(['part' => 'cat', 'catid' => $this->rs->cat_id, 'redir' => $this->redir]))
|
||||
->title(__('Edit'))
|
||||
->text(Html::escapeHTML($row->cat_title)),
|
||||
->text(Html::escapeHTML($this->rs->cat_title)),
|
||||
]),
|
||||
'note' => (new Td())
|
||||
->text(Html::escapeHTML($row->link_note))
|
||||
->text(Html::escapeHTML($this->rs->link_note))
|
||||
->class('number'),
|
||||
'date' => (new Td())
|
||||
->text(Html::escapeHTML(Date::dt2str(__('%Y-%m-%d %H:%M'), $row->link_upddt, (string) App::auth()->getInfo('user_tz'))))
|
||||
->text(Html::escapeHTML(Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->link_upddt, (string) App::auth()->getInfo('user_tz'))))
|
||||
->class('nowrap'),
|
||||
]);
|
||||
|
||||
$this->userColumns(My::id(), $cols);
|
||||
|
||||
return
|
||||
(new Para('p' . $row->link_id, 'tr'))
|
||||
(new Para('p' . $this->rs->kut_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[(string) $file->media_title] = (string) $file->file_url;
|
||||
$tmp[$file->media_title] = $file->file_url;
|
||||
}
|
||||
if (!empty($tmp)) {
|
||||
$stack = array_merge(['-' => ''], $tmp);
|
||||
|
|
|
@ -96,6 +96,7 @@ 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(): int
|
||||
public static function PaginationNbPages()
|
||||
{
|
||||
if (App::frontend()->context()->c2_pagination === null) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
$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 (int) $nb_pages;
|
||||
return $nb_pages;
|
||||
}
|
||||
|
||||
public static function PaginationPosition(string|int $offset = 0): int
|
||||
public static function PaginationPosition($offset = 0)
|
||||
{
|
||||
if (isset($GLOBALS['c2_page_number'])) {
|
||||
$p = $GLOBALS['c2_page_number'];
|
||||
} else {
|
||||
$p = 1;
|
||||
}
|
||||
$p = (int) $p + (int) $offset;
|
||||
$p = $p + $offset;
|
||||
$n = self::PaginationNbPages();
|
||||
if (!$n) {
|
||||
return $p;
|
||||
|
@ -43,17 +43,25 @@ class FrontendContext
|
|||
return $p > $n || $p <= 0 ? 1 : $p;
|
||||
}
|
||||
|
||||
public static function PaginationStart(): bool
|
||||
public static function PaginationStart()
|
||||
{
|
||||
return isset($GLOBALS['c2_page_number']) ? self::PaginationPosition() == 1 : true;
|
||||
if (isset($GLOBALS['c2_page_number'])) {
|
||||
return self::PaginationPosition() == 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function PaginationEnd(): bool
|
||||
public static function PaginationEnd()
|
||||
{
|
||||
return isset($GLOBALS['c2_page_number']) ? self::PaginationPosition() == self::PaginationNbPages() : false;
|
||||
if (isset($GLOBALS['c2_page_number'])) {
|
||||
return self::PaginationPosition() == self::PaginationNbPages();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function PaginationURL(int|string $offset = 0): string
|
||||
public static function PaginationURL($offset = 0)
|
||||
{
|
||||
$args = $_SERVER['URL_REQUEST_PART'];
|
||||
|
||||
|
@ -76,7 +84,7 @@ class FrontendContext
|
|||
return $url;
|
||||
}
|
||||
|
||||
public static function categoryCurrent(): bool
|
||||
public static function categoryCurrent()
|
||||
{
|
||||
if (!isset(App::frontend()->context()->c2_page_params['cat_id'])
|
||||
&& !isset(App::frontend()->context()->c2_page_params['cat_title'])
|
||||
|
|
|
@ -18,57 +18,36 @@ 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 = [];
|
||||
|
@ -88,9 +67,6 @@ 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;
|
||||
|
@ -137,25 +113,16 @@ 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 = [];
|
||||
|
@ -170,153 +137,96 @@ 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);
|
||||
|
@ -333,9 +243,6 @@ 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']) : '';
|
||||
|
@ -353,17 +260,11 @@ 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" .
|
||||
|
@ -374,25 +275,16 @@ 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 = [];
|
||||
|
@ -409,17 +301,11 @@ class FrontendTemplate
|
|||
return empty($if) ? $c : '<?php if(' . implode(' && ', $if) . ') : ?>' . $c . '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $a The attributes
|
||||
*/
|
||||
public static function c2PaginationURL(ArrayObject $a): string
|
||||
public static function c2PaginationURL($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
|
||||
|
@ -431,25 +317,16 @@ 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 = [];
|
||||
|
@ -466,9 +343,6 @@ 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';
|
||||
|
@ -480,49 +354,31 @@ 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): null
|
||||
public static function c2Page(?string $args)
|
||||
{
|
||||
$args = (string) $args;
|
||||
|
||||
|
|
|
@ -32,7 +32,9 @@ use Exception;
|
|||
class ManageCat extends Process
|
||||
{
|
||||
private static string $module_redir = '';
|
||||
private static RecordCatsRow $row;
|
||||
private static int $catid = 0;
|
||||
private static string $cattitle = '';
|
||||
private static string $catdesc = '';
|
||||
|
||||
public static function init(): bool
|
||||
{
|
||||
|
@ -45,18 +47,25 @@ class ManageCat extends Process
|
|||
return false;
|
||||
}
|
||||
|
||||
$utils = new Utils();
|
||||
|
||||
self::$module_redir = $_REQUEST['redir'] ?? '';
|
||||
self::$row = new RecordCatsRow();
|
||||
$utils = new Utils();
|
||||
self::$catid = (int) ($_REQUEST['catid'] ?? 0);
|
||||
self::$cattitle = $_POST['cattitle'] ?? '';
|
||||
self::$catdesc = $_POST['catdesc'] ?? '';
|
||||
|
||||
try {
|
||||
// create category
|
||||
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 (!empty($_POST['save']) && empty(self::$catid) && !empty(self::$cattitle) && !empty(self::$catdesc)) {
|
||||
$exists = $utils->getCategories(['cat_title' => self::$cattitle], true)->f(0);
|
||||
if ($exists) {
|
||||
throw new Exception(__('Category with same name already exists.'));
|
||||
}
|
||||
$cat_id = $utils->addCategory(self::$row->getCursor());
|
||||
$cur = App::con()->openCursor($utils->cat_table);
|
||||
$cur->setField('cat_title', self::$cattitle);
|
||||
$cur->setField('cat_desc', self::$catdesc);
|
||||
|
||||
$catid = $utils->addCategory($cur);
|
||||
|
||||
Notices::addSuccessNotice(
|
||||
__('Category successfully created.')
|
||||
|
@ -64,12 +73,16 @@ class ManageCat extends Process
|
|||
My::redirect(['part' => 'cats']);
|
||||
}
|
||||
// update category
|
||||
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 (!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 ($exists) {
|
||||
throw new Exception(__('Category with same name already exists.'));
|
||||
}
|
||||
$cat_id = $utils->updCategory(self::$row->cat_id, self::$row->getCursor());
|
||||
$cur = App::con()->openCursor($C2->cat_table);
|
||||
$cur->setField('cat_title', self::$cattitle);
|
||||
$cur->setField('cat_desc', self::$catdesc);
|
||||
|
||||
$utils->updCategory(self::$catid, $cur);
|
||||
|
||||
Notices::addSuccessNotice(
|
||||
__('Category successfully updated.')
|
||||
|
@ -77,20 +90,14 @@ class ManageCat extends Process
|
|||
My::redirect(['part' => 'cats']);
|
||||
}
|
||||
// delete category
|
||||
if (!empty($_POST['delete']) && !empty(self::$row->cat_id)) {
|
||||
$utils->delCategory(self::$row->cat_id);
|
||||
if (!empty($_POST['delete']) && !empty(self::$catid)) {
|
||||
$utils->delCategory(self::$catid);
|
||||
|
||||
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());
|
||||
}
|
||||
|
@ -106,13 +113,21 @@ 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::$row->cat_id) ? __('New category') : __('Edit category')) => '',
|
||||
__('Plugins') => '',
|
||||
My::name() => My::manageUrl(),
|
||||
(empty(self::$catid) ? __('New category') : __('Edit category')) => '',
|
||||
]) .
|
||||
Notices::getNotices();
|
||||
|
||||
|
@ -127,8 +142,8 @@ class ManageCat extends Process
|
|||
->render();
|
||||
}
|
||||
|
||||
if (self::$row->cat_id) {
|
||||
$links = (int) $utils->getLinks(['cat_id' => self::$row->cat_id], true)->f(0);
|
||||
if (self::$catid) {
|
||||
$links = (int) $utils->getLinks(['cat_id' => self::$catid], true)->f(0);
|
||||
echo (new Note())
|
||||
->class('info')
|
||||
->text(
|
||||
|
@ -146,20 +161,20 @@ class ManageCat extends Process
|
|||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Title:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('cat_title'),
|
||||
(new Input('cat_title'))
|
||||
->for('cattitle'),
|
||||
(new Input('cattitle'))
|
||||
->size(65)
|
||||
->maxlength(64)
|
||||
->value(Html::escapeHTML(self::$row->cat_title)),
|
||||
->maxlenght(64)
|
||||
->value(Html::escapeHTML(self::$cattitle)),
|
||||
]),
|
||||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Description:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('cat_desc'),
|
||||
(new Input('cat_desc'))
|
||||
->for('catdesc'),
|
||||
(new Input('catdesc'))
|
||||
->size(65)
|
||||
->maxlength(64)
|
||||
->value(Html::escapeHTML(self::$row->cat_desc)),
|
||||
->maxlenght(64)
|
||||
->value(Html::escapeHTML(self::$catdesc)),
|
||||
]),
|
||||
(new Para())
|
||||
->class('border-top')
|
||||
|
@ -179,9 +194,9 @@ class ManageCat extends Process
|
|||
->value(__('Delete') . ' (d)')
|
||||
->accesskey('d'),
|
||||
... My::hiddenFields([
|
||||
'cat_id' => self::$row->cat_id,
|
||||
'part' => 'cat',
|
||||
'redir' => self::$module_redir,
|
||||
'catid' => self::$catid,
|
||||
'part' => 'cat',
|
||||
'redir' => self::$module_redir,
|
||||
]),
|
||||
]),
|
||||
])
|
||||
|
|
|
@ -107,8 +107,7 @@ class ManageCats extends Process
|
|||
$items = [];
|
||||
$i = 0;
|
||||
while ($categories->fetch()) {
|
||||
$row = new RecordCatsRow($categories);
|
||||
$id = (string) $row->cat_id;
|
||||
$id = $categories->f('cat_id');
|
||||
|
||||
$items[] = (new Tr('l_' . $i))
|
||||
->class('line')
|
||||
|
@ -121,7 +120,7 @@ class ManageCats extends Process
|
|||
->max($categories->count())
|
||||
->value($i + 1)
|
||||
->class('position')
|
||||
->title(Html::escapeHTML(sprintf(__('position of %s'), $row->cat_title))),
|
||||
->title(Html::escapeHTML(sprintf(__('position of %s'), (string) $categories->f('cat_title')))),
|
||||
(new Hidden(['dynorder[]', 'dynorder-' . $i], $id)),
|
||||
]),
|
||||
(new Td())
|
||||
|
@ -135,19 +134,19 @@ class ManageCats extends Process
|
|||
->items([
|
||||
(new Link())
|
||||
->href(My::manageUrl([
|
||||
'part' => 'cat',
|
||||
'cat_id' => $id,
|
||||
'redir' => My::manageUrl([
|
||||
'part' => 'cat',
|
||||
'catid' => $id,
|
||||
'redir' => My::manageUrl([
|
||||
'part' => 'cats',
|
||||
'redir' => self::$module_redir,
|
||||
]),
|
||||
]))
|
||||
->title(__('Edit'))
|
||||
->text(Html::escapeHTML($row->cat_title)),
|
||||
->text(Html::escapeHTML((string) $categories->f('cat_title'))),
|
||||
]),
|
||||
(new Td())
|
||||
->class('maximal')
|
||||
->text(Html::escapeHTML($row->cat_desc)),
|
||||
->text(Html::escapeHTML((string) $categories->f('cat_desc'))),
|
||||
]);
|
||||
|
||||
$i++;
|
||||
|
@ -188,7 +187,7 @@ class ManageCats extends Process
|
|||
(new Link())
|
||||
->class('button add')
|
||||
->href(My::manageUrl(['part' => 'cat', 'redir' => My::manageUrl(['part' => 'cats'])]))
|
||||
->text(__('New Category')),
|
||||
->text(__('New Link')),
|
||||
])
|
||||
->render();
|
||||
|
||||
|
|
|
@ -36,7 +36,15 @@ use Exception;
|
|||
class ManageLink extends Process
|
||||
{
|
||||
private static string $module_redir = '';
|
||||
private static RecordLinksRow $row;
|
||||
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 = '';
|
||||
|
||||
public static function init(): bool
|
||||
{
|
||||
|
@ -49,9 +57,18 @@ class ManageLink extends Process
|
|||
return false;
|
||||
}
|
||||
|
||||
$utils = new Utils();
|
||||
|
||||
self::$module_redir = $_REQUEST['redir'] ?? '';
|
||||
self::$row = new RecordLinksRow();
|
||||
$utils = new Utils();
|
||||
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'] ?? '';
|
||||
|
||||
if (!empty($_POST['save'])) {
|
||||
try {
|
||||
|
@ -59,34 +76,44 @@ class ManageLink extends Process
|
|||
App::config()->dotclearRoot() . '/' . App::blog()->settings()->system->get('public_path'),
|
||||
My::settings()->folder
|
||||
);
|
||||
if (empty(self::$row->link_title)) {
|
||||
if (empty(self::$linktitle)) {
|
||||
throw new Exception(__('You must provide a title.'));
|
||||
}
|
||||
if (empty(self::$row->link_author)) {
|
||||
if (empty(self::$linkauthor)) {
|
||||
throw new Exception(__('You must provide an author.'));
|
||||
}
|
||||
if (!preg_match('/https?:\/\/.+/', self::$row->link_img)) {
|
||||
if (!preg_match('/https?:\/\/.+/', self::$linkimage)) {
|
||||
//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 (!self::$row->link_id) {
|
||||
$exists = $utils->getLinks(['link_title' => self::$row->link_title], true)->f(0);
|
||||
if (empty(self::$linkid)) {
|
||||
$exists = $utils->getLinks(['link_title' => self::$linktitle], true)->f(0);
|
||||
if ($exists) {
|
||||
throw new Exception(__('Link with same name already exists.'));
|
||||
}
|
||||
$link_id = $utils->addLink(self::$row->getCursor());
|
||||
self::$linkid = $utils->addLink($cur);
|
||||
|
||||
Notices::addSuccessNotice(
|
||||
__('Link successfully created.')
|
||||
);
|
||||
// update a link
|
||||
} else {
|
||||
$exists = $utils->getLinks(['link_id' => self::$row->link_id], true)->f(0);
|
||||
$exists = $utils->getLinks(['link_id' => self::$linkid], true)->f(0);
|
||||
if (!$exists) {
|
||||
throw new Exception(__('Unknown link.'));
|
||||
}
|
||||
$link_id = $utils->updLink(self::$row->link_id, self::$row->getCursor());
|
||||
$utils->updLink(self::$linkid, $cur);
|
||||
|
||||
Notices::addSuccessNotice(
|
||||
__('Link successfully updated.')
|
||||
|
@ -94,9 +121,9 @@ class ManageLink extends Process
|
|||
}
|
||||
My::redirect(
|
||||
[
|
||||
'part' => 'link',
|
||||
'link_id' => $link_id,
|
||||
'redir' => self::$module_redir,
|
||||
'part' => 'link',
|
||||
'linkid' => self::$linkid,
|
||||
'redir' => self::$module_redir,
|
||||
]
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
|
@ -104,9 +131,9 @@ class ManageLink extends Process
|
|||
}
|
||||
}
|
||||
|
||||
if (!empty($_POST['delete']) && self::$row->link_id) {
|
||||
if (!empty($_POST['delete']) && !empty(self::$linkid)) {
|
||||
try {
|
||||
$utils->delLink(self::$row->link_id);
|
||||
$utils->delLink(self::$linkid);
|
||||
|
||||
Notices::addSuccessNotice(
|
||||
__('Link successfully deleted.')
|
||||
|
@ -121,10 +148,18 @@ class ManageLink extends Process
|
|||
}
|
||||
}
|
||||
|
||||
if (self::$row->link_id) {
|
||||
self::$row = new RecordLinksRow(
|
||||
$utils->getLinks(['link_id' => self::$row->link_id])
|
||||
);
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -146,9 +181,9 @@ class ManageLink extends Process
|
|||
|
||||
echo
|
||||
Page::breadcrumb([
|
||||
__('Plugins') => '',
|
||||
My::name() => My::manageUrl(),
|
||||
(empty(self::$row->link_id) ? __('New link') : __('Edit link')) => '',
|
||||
__('Plugins') => '',
|
||||
My::name() => My::manageUrl(),
|
||||
(empty(self::$linkid) ? __('New link') : __('Edit link')) => '',
|
||||
]) .
|
||||
Notices::getNotices();
|
||||
|
||||
|
@ -178,38 +213,38 @@ class ManageLink extends Process
|
|||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Title:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('link_title'),
|
||||
(new Input('link_title'))
|
||||
->for('linktitle'),
|
||||
(new Input('linktitle'))
|
||||
->size(65)
|
||||
->maxlength(255)
|
||||
->value(Html::escapeHTML(self::$row->link_title)),
|
||||
->maxlenght(255)
|
||||
->value(Html::escapeHTML(self::$linktitle)),
|
||||
]),
|
||||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Description:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('link_desc'),
|
||||
(new Input('link_desc'))
|
||||
->for('linkdesc'),
|
||||
(new Input('linkdesc'))
|
||||
->size(65)
|
||||
->maxlength(255)
|
||||
->value(Html::escapeHTML(self::$row->link_desc)),
|
||||
->maxlenght(255)
|
||||
->value(Html::escapeHTML(self::$linkdesc)),
|
||||
]),
|
||||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Author:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('link_author'),
|
||||
(new Input('link_author'))
|
||||
->for('linkauthor'),
|
||||
(new Input('linkauthor'))
|
||||
->size(65)
|
||||
->maxlength(255)
|
||||
->value(Html::escapeHTML(self::$row->link_author)),
|
||||
->maxlenght(255)
|
||||
->value(Html::escapeHTML(self::$linkauthor)),
|
||||
]),
|
||||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Details URL:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('link_url'),
|
||||
(new Input('link_url'))
|
||||
->for('linkurl'),
|
||||
(new Input('linkurl'))
|
||||
->size(65)
|
||||
->maxlength(255)
|
||||
->value(Html::escapeHTML(self::$row->link_url)),
|
||||
->maxlenght(255)
|
||||
->value(Html::escapeHTML(self::$linkurl)),
|
||||
(new Link('newlinksearch'))
|
||||
->class('modal hidden-if-no-js')
|
||||
->href('http://google.com')
|
||||
|
@ -219,11 +254,11 @@ class ManageLink extends Process
|
|||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Image URL:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('link_img'),
|
||||
(new Input('link_img'))
|
||||
->for('linkimage'),
|
||||
(new Input('linkimage'))
|
||||
->size(65)
|
||||
->maxlength(255)
|
||||
->value(Html::escapeHTML(self::$row->link_img)),
|
||||
->maxlenght(255)
|
||||
->value(Html::escapeHTML(self::$linkimage)),
|
||||
(new Link('newimagesearch'))
|
||||
->class('modal hidden-if-no-js')
|
||||
->href('http://amazon.com')
|
||||
|
@ -261,27 +296,27 @@ class ManageLink extends Process
|
|||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Category:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('cat_id'),
|
||||
(new Select('cat_id'))
|
||||
->for('linkcat'),
|
||||
(new Select('linkcat'))
|
||||
->items(Combo::categoriesCombo())
|
||||
->default((string) self::$row->cat_id),
|
||||
->default(self::$linkcat),
|
||||
]),
|
||||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Lang:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('link_lang'),
|
||||
(new Select('link_lang'))
|
||||
->for('linklang'),
|
||||
(new Select('linklang'))
|
||||
->items(Combo::langsCombo())
|
||||
->default(self::$row->link_lang),
|
||||
->default(self::$linklang),
|
||||
]),
|
||||
(new Para())
|
||||
->items([
|
||||
(new Label(__('Rating:'), Label::OUTSIDE_LABEL_BEFORE))
|
||||
->for('link_note'),
|
||||
(new Number('link_note'))
|
||||
->for('linknote'),
|
||||
(new Number('linknote'))
|
||||
->min(0)
|
||||
->max(20)
|
||||
->value(self::$row->link_note),
|
||||
->value(self::$linknote),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
|
@ -303,9 +338,9 @@ class ManageLink extends Process
|
|||
->value(__('Delete') . ' (d)')
|
||||
->accesskey('d'),
|
||||
... My::hiddenFields([
|
||||
'link_id' => self::$row->link_id,
|
||||
'part' => 'link',
|
||||
'redir' => self::$module_redir,
|
||||
'linkid' => self::$linkid,
|
||||
'part' => 'link',
|
||||
'redir' => self::$module_redir,
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
|
|
|
@ -10,6 +10,7 @@ use Dotclear\Core\Backend\Filter\{
|
|||
Filters,
|
||||
FiltersLibrary
|
||||
};
|
||||
use Dotclear\Core\Backend\Listing\Listing;
|
||||
use Dotclear\Core\Backend\{
|
||||
Notices,
|
||||
Page
|
||||
|
@ -39,7 +40,7 @@ class ManageLinks extends Process
|
|||
{
|
||||
private static Actions $module_action;
|
||||
private static Filters $module_filter;
|
||||
private static BackendListingLinks $module_listing;
|
||||
private static Listing $module_listing;
|
||||
private static int $module_counter = 0;
|
||||
private static ?bool $module_rendered = null;
|
||||
|
||||
|
@ -66,7 +67,7 @@ class ManageLinks extends Process
|
|||
self::$module_filter->add(FiltersLibrary::getPageFilter());
|
||||
self::$module_filter->add(FiltersLibrary::getSearchFilter());
|
||||
self::$module_filter->add(FiltersLibrary::getSelectFilter(
|
||||
'cat_id',
|
||||
'catid',
|
||||
__('Category:'),
|
||||
Combo::categoriesCombo(),
|
||||
'cat_id'
|
||||
|
@ -170,7 +171,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
|
||||
{
|
||||
/**
|
||||
* Links table name.
|
||||
* Link table name.
|
||||
*
|
||||
* @var string CINECTURLINK_TABLE_NAME
|
||||
*/
|
||||
public const CINECTURLINK_TABLE_NAME = 'cinecturlink2';
|
||||
|
||||
/**
|
||||
* Categories table name.
|
||||
* Category table name.
|
||||
*
|
||||
* @var string CATEGORY_TABLE_NAME
|
||||
*/
|
||||
|
@ -40,8 +40,8 @@ class My extends MyPlugin
|
|||
public static function checkCustomContext(int $context): ?bool
|
||||
{
|
||||
return match ($context) {
|
||||
// Add content admin perm to backend
|
||||
self::MENU, self::MANAGE => App::task()->checkContext('BACKEND')
|
||||
self::MENU, self::MANAGE, self::BACKEND => App::task()->checkContext('BACKEND')
|
||||
&& App::blog()->isDefined()
|
||||
&& App::auth()->check(App::auth()->makePermissions([
|
||||
App::auth()::PERMISSION_CONTENT_ADMIN,
|
||||
]), App::blog()->id()),
|
||||
|
|
|
@ -4,30 +4,23 @@ 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
|
||||
{
|
||||
/**
|
||||
* @param ArrayObject<string, string> $map_parts
|
||||
*/
|
||||
public static function sitemapsDefineParts(ArrayObject $map_parts): void
|
||||
public static function sitemapsDefineParts($map_parts)
|
||||
{
|
||||
$map_parts->offsetSet(My::name(), My::id());
|
||||
}
|
||||
|
||||
public static function sitemapsURLsCollect(Sitemap $sitemaps): void
|
||||
public static function sitemapsURLsCollect($sitemaps)
|
||||
{
|
||||
if (App::plugins()->moduleExists('cinecturlink2')
|
||||
&& App::blog()->settings()->get('sitemaps')->get('sitemaps_cinecturlink2_url')
|
||||
|
@ -41,7 +34,7 @@ class PluginSitemaps
|
|||
$C2 = new Utils();
|
||||
$cats = $C2->getCategories();
|
||||
while ($cats->fetch()) {
|
||||
$sitemaps->addEntry($base . '/' . My::settings()->get('public_caturl') . '/' . urlencode((string) $cats->field('cat_title')), $prio, $freq);
|
||||
$sitemaps->addEntry($base . '/' . My::settings()->get('public_caturl') . '/' . urlencode($cats->cat_title), $prio, $freq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
<?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,9 +72,8 @@ class Utils
|
|||
/**
|
||||
* Get links.
|
||||
*
|
||||
* @param array<string, mixed> $params Query params
|
||||
* @param bool $count_only Count only result
|
||||
*
|
||||
* @param array $params Query params
|
||||
* @param bool $count_only Count only result
|
||||
* @return MetaRecord MetaRecord instance
|
||||
*/
|
||||
public function getLinks(array $params = [], bool $count_only = false): MetaRecord
|
||||
|
@ -265,10 +264,8 @@ 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): int
|
||||
public function updLink(int $id, Cursor $cur, bool $behavior = true): void
|
||||
{
|
||||
if (empty($id)) {
|
||||
throw new Exception(__('No such link ID'));
|
||||
|
@ -286,8 +283,6 @@ class Utils
|
|||
# --BEHAVIOR-- cinecturlink2AfterUpdLink
|
||||
App::behavior()->callBehavior('cinecturlink2AfterUpdLink', $cur, $id);
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -323,20 +318,18 @@ class Utils
|
|||
{
|
||||
$sql = new SelectStatement();
|
||||
|
||||
$rs = $sql
|
||||
return $sql
|
||||
->column($sql->max('link_id'))
|
||||
->from($this->table)
|
||||
->select();
|
||||
|
||||
return is_null($rs) ? 1 : (int) $rs->f(0) + 1;
|
||||
->select()
|
||||
->f(0) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get categories.
|
||||
*
|
||||
* @param array<string, mixed> $params Query params
|
||||
* @param bool $count_only Count only result
|
||||
*
|
||||
* @param array $params Query params
|
||||
* @param bool $count_only Count only result
|
||||
* @return MetaRecord Record instance
|
||||
*/
|
||||
public function getCategories(array $params = [], bool $count_only = false): MetaRecord
|
||||
|
@ -458,10 +451,8 @@ class Utils
|
|||
*
|
||||
* @param int $id Category ID
|
||||
* @param Cursor $cur Cursor instance
|
||||
*
|
||||
* @return int The category ID
|
||||
*/
|
||||
public function updCategory(int $id, Cursor $cur): int
|
||||
public function updCategory(int $id, Cursor $cur): void
|
||||
{
|
||||
if (empty($id)) {
|
||||
throw new Exception(__('No such category ID'));
|
||||
|
@ -476,8 +467,6 @@ class Utils
|
|||
->update($cur);
|
||||
|
||||
$this->trigger();
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -521,12 +510,11 @@ class Utils
|
|||
{
|
||||
$sql = new SelectStatement();
|
||||
|
||||
$rs = $sql
|
||||
return $sql
|
||||
->column($sql->max('cat_id'))
|
||||
->from($this->cat_table)
|
||||
->select();
|
||||
|
||||
return is_null($rs) ? 1 : (int) $rs->f(0) + 1;
|
||||
->select()
|
||||
->f(0) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -538,13 +526,12 @@ class Utils
|
|||
{
|
||||
$sql = new SelectStatement();
|
||||
|
||||
$rs = $sql
|
||||
return $sql
|
||||
->column($sql->max('cat_pos'))
|
||||
->from($this->cat_table)
|
||||
->where('blog_id = ' . $sql->quote($this->blog))
|
||||
->select();
|
||||
|
||||
return is_null($rs) ? 1 : (int) $rs->f(0) + 1;
|
||||
->select()
|
||||
->f(0) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -582,15 +569,12 @@ 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;
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
<?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'));
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
<?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,7 +8,6 @@ use Dotclear\App;
|
|||
use Dotclear\Helper\Html\Html;
|
||||
use Dotclear\Plugin\widgets\WidgetsStack;
|
||||
use Dotclear\Plugin\widgets\WidgetsElement;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @brief cinecturlink2 widgets class.
|
||||
|
@ -19,20 +18,6 @@ use Exception;
|
|||
*/
|
||||
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(
|
||||
|
@ -54,7 +39,7 @@ class Widgets
|
|||
|
||||
$w
|
||||
->create(
|
||||
self::WIDGET_ID_LINKS,
|
||||
'cinecturlink2links',
|
||||
__('My cinecturlink'),
|
||||
self::parseLinks(...),
|
||||
null,
|
||||
|
@ -127,7 +112,7 @@ class Widgets
|
|||
|
||||
$w
|
||||
->create(
|
||||
self::WIDGET_ID_CATS,
|
||||
'cinecturlink2cats',
|
||||
__('List of categories of cinecturlink'),
|
||||
self::parseCats(...),
|
||||
null,
|
||||
|
@ -154,29 +139,30 @@ class Widgets
|
|||
->addOffline();
|
||||
}
|
||||
|
||||
public static function parseLinks(WidgetsElement $widget): string
|
||||
public static function parseLinks(WidgetsElement $w): string
|
||||
{
|
||||
if (!My::settings()->get('active')
|
||||
|| !$widget->checkHomeOnly(App::url()->type)
|
||||
if (!My::settings()->avtive
|
||||
|| !$w->checkHomeOnly(App::url()->type)
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$wdesc = new WidgetLinksDescriptor($widget);
|
||||
$utils = new Utils();
|
||||
$C2 = new Utils();
|
||||
$params = [];
|
||||
|
||||
if ($wdesc->category) {
|
||||
if ($wdesc->category == 'null') {
|
||||
if ($w->category) {
|
||||
if ($w->category == 'null') {
|
||||
$params['sql'] = ' AND L.cat_id IS NULL ';
|
||||
} elseif (is_numeric($wdesc->category)) {
|
||||
$params['cat_id'] = (int) $wdesc->category;
|
||||
} elseif (is_numeric($w->category)) {
|
||||
$params['cat_id'] = (int) $w->category;
|
||||
}
|
||||
}
|
||||
|
||||
$limit = abs((int) $w->limit);
|
||||
|
||||
// Tirage aléatoire: Consomme beaucoup de ressources!
|
||||
if ($wdesc->sortby == 'RANDOM') {
|
||||
$big_rs = $utils->getLinks($params);
|
||||
if ($w->sortby == 'RANDOM') {
|
||||
$big_rs = $C2->getLinks($params);
|
||||
|
||||
if ($big_rs->isEmpty()) {
|
||||
return '';
|
||||
|
@ -187,93 +173,94 @@ class Widgets
|
|||
$ids[] = $big_rs->link_id;
|
||||
}
|
||||
shuffle($ids);
|
||||
$ids = array_slice($ids, 0, $wdesc->limit);
|
||||
$ids = array_slice($ids, 0, $limit);
|
||||
|
||||
$params['link_id'] = [];
|
||||
foreach ($ids as $id) {
|
||||
$params['link_id'][] = $id;
|
||||
}
|
||||
} elseif ($wdesc->sortby == 'COUNTER') {
|
||||
} elseif ($w->sortby == 'COUNTER') {
|
||||
$params['order'] = 'link_count asc';
|
||||
$params['limit'] = $wdesc->limit;
|
||||
$params['limit'] = $limit;
|
||||
} else {
|
||||
$params['order'] = $wdesc->sortby . ' ' . $wdesc->sort;
|
||||
$params['limit'] = $wdesc->limit;
|
||||
$params['order'] = $w->sortby;
|
||||
$params['order'] .= $w->sort == 'asc' ? ' asc' : ' desc';
|
||||
$params['limit'] = $limit;
|
||||
}
|
||||
|
||||
$rs = $utils->getLinks($params);
|
||||
$rs = $C2->getLinks($params);
|
||||
|
||||
if ($rs->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$widthmax = (int) My::settings()->get('widthmax');
|
||||
$widthmax = (int) My::settings()->widthmax;
|
||||
$style = $widthmax ? ' style="width:' . $widthmax . 'px;"' : '';
|
||||
|
||||
$entries = [];
|
||||
while ($rs->fetch()) {
|
||||
$row = new RecordLinksRow($rs);
|
||||
$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);
|
||||
|
||||
# --BEHAVIOR-- cinecturlink2WidgetLinks
|
||||
$bhv = App::behavior()->callBehavior('cinecturlink2WidgetLinks', $row->link_id);
|
||||
$bhv = App::behavior()->callBehavior('cinecturlink2WidgetLinks', $rs->link_id);
|
||||
|
||||
$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;
|
||||
$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;
|
||||
|
||||
try {
|
||||
$cur = App::con()->openCursor($utils->table);
|
||||
$cur->setField('link_count', ($row->link_count + 1));
|
||||
$utils->updLink($row->link_id, $cur, false);
|
||||
} catch (Exception) {
|
||||
$cur = App::con()->openCursor($C2->table);
|
||||
$cur->link_count = ($count + 1);
|
||||
$C2->updLink((int) $rs->link_id, $cur, false);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
# Tirage aléatoire
|
||||
if (in_array($wdesc->sortby, ['RANDOM', 'COUNTER'])) {
|
||||
if ($w->sortby == 'RANDOM'
|
||||
|| $w->sortby == 'COUNTER'
|
||||
) {
|
||||
shuffle($entries);
|
||||
if (My::settings()->get('triggeronrandom')) {
|
||||
if (My::settings()->triggeronrandom) {
|
||||
App::blog()->triggerBlog();
|
||||
}
|
||||
}
|
||||
|
||||
return $widget->renderDiv(
|
||||
$wdesc->content_only,
|
||||
$widget->id() . ' ' . $wdesc->class,
|
||||
return $w->renderDiv(
|
||||
(bool) $w->content_only,
|
||||
'cinecturlink2list ' . $w->class,
|
||||
'',
|
||||
($wdesc->title ? $widget->renderTitle(Html::escapeHTML($wdesc->title)) : '') . implode(' ', $entries) .
|
||||
($w->title ? $w->renderTitle(Html::escapeHTML($w->title)) : '') . implode(' ', $entries) .
|
||||
(
|
||||
$wdesc->showpagelink && My::settings()->get('public_active') ?
|
||||
$w->showpagelink && My::settings()->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 $widget): string
|
||||
public static function parseCats(WidgetsElement $w): string
|
||||
{
|
||||
if (!My::settings()->get('active')
|
||||
|| !My::settings()->get('public_active')
|
||||
|| !$widget->checkHomeOnly(App::url()->type)
|
||||
if (!My::settings()->avtive
|
||||
|| !My::settings()->public_active
|
||||
|| !$w->checkHomeOnly(App::url()->type)
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$wdesc = new WidgetCatsDescriptor($widget);
|
||||
$utils = new Utils();
|
||||
$rs = $utils->getCategories([]);
|
||||
$C2 = new Utils();
|
||||
$rs = $C2->getCategories([]);
|
||||
if ($rs->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
|
@ -282,28 +269,26 @@ class Widgets
|
|||
$res[] = '<li><a href="' .
|
||||
App::blog()->url() . App::url()->getBase(My::id()) .
|
||||
'" title="' . __('view all links') . '">' . __('all links') .
|
||||
'</a>' . ($wdesc->shownumlink ? ' (' . ($utils->getLinks([], true)->f(0)) . ')' : '') .
|
||||
'</a>' . ($w->shownumlink ? ' (' . ($C2->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()->get('public_caturl') . '/' .
|
||||
urlencode($row->cat_title) .
|
||||
My::settings()->public_caturl . '/' .
|
||||
urlencode($rs->cat_title) .
|
||||
'" title="' . __('view links of this category') . '">' .
|
||||
Html::escapeHTML($row->cat_title) .
|
||||
'</a>' . ($wdesc->shownumlink ? ' (' .
|
||||
($utils->getLinks(['cat_id' => $row->cat_id], true)->f(0)) . ')' : '') .
|
||||
Html::escapeHTML($rs->cat_title) .
|
||||
'</a>' . ($w->shownumlink ? ' (' .
|
||||
($C2->getLinks(['cat_id' => $rs->cat_id], true)->f(0)) . ')' : '') .
|
||||
'</li>';
|
||||
}
|
||||
|
||||
return $widget->renderDiv(
|
||||
$wdesc->content_only,
|
||||
$widget->id() . ' ' . $wdesc->class,
|
||||
return $w->renderDiv(
|
||||
(bool) $w->content_only,
|
||||
'cinecturlink2cat ' . $w->class,
|
||||
'',
|
||||
($wdesc->title ? $widget->renderTitle(Html::escapeHTML($wdesc->title)) : '') .
|
||||
($w->title ? $w->renderTitle(Html::escapeHTML($w->title)) : '') .
|
||||
'<ul>' . implode(' ', $res) . '</ul>'
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue