cinecturlink2/_public.php

555 lines
20 KiB
PHP
Raw Normal View History

2021-09-07 12:33:18 +00:00
<?php
2021-09-07 13:21:38 +00:00
/**
* @brief cinecturlink2, a plugin for Dotclear 2
2021-11-02 22:55:41 +00:00
*
2021-09-07 13:21:38 +00:00
* @package Dotclear
* @subpackage Plugin
2021-11-02 22:55:41 +00:00
*
2021-09-07 13:21:38 +00:00
* @author Jean-Christian Denis and Contributors
2021-11-02 22:55:41 +00:00
*
2021-09-07 13:21:38 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2021-09-07 12:33:18 +00:00
if (!defined('DC_RC_PATH')) {
2021-09-07 13:21:38 +00:00
return null;
2021-09-07 12:33:18 +00:00
}
2022-11-17 21:01:00 +00:00
require_once __DIR__ . '/_widgets.php';
2021-09-07 12:33:18 +00:00
2022-11-17 21:01:00 +00:00
dcCore::app()->blog->settings->addNamespace('cinecturlink2');
2021-09-07 12:33:18 +00:00
2021-11-02 22:55:41 +00:00
$c2_tpl_values = [
2021-09-07 13:21:38 +00:00
'c2PageFeedID',
'c2PageFeedURL',
'c2PageURL',
'c2PageTitle',
'c2PageDescription',
'c2EntryIfOdd',
'c2EntryIfFirst',
'c2EntryFeedID',
'c2EntryID',
'c2EntryTitle',
'c2EntryDescription',
'c2EntryFromAuthor',
'c2EntryAuthorCommonName',
'c2EntryAuthorDisplayName',
'c2EntryAuthorEmail',
'c2EntryAuthorID',
'c2EntryAuthorLink',
'c2EntryAuthorURL',
'c2EntryLang',
'c2EntryURL',
'c2EntryCategory',
'c2EntryCategoryID',
'c2EntryCategoryURL',
'c2EntryImg',
'c2EntryDate',
'c2EntryTime',
'c2PaginationCounter',
'c2PaginationCurrent',
'c2PaginationURL',
'c2CategoryFeedID',
'c2CategoryFeedURL',
'c2CategoryID',
'c2CategoryTitle',
'c2CategoryDescription',
2022-11-17 21:01:00 +00:00
'c2CategoryURL',
2021-11-02 22:55:41 +00:00
];
2021-09-07 12:33:18 +00:00
2021-11-02 22:55:41 +00:00
$c2_tpl_blocks = [
2021-09-07 13:21:38 +00:00
'c2If',
2021-09-07 12:33:18 +00:00
2021-09-07 13:21:38 +00:00
'c2Entries',
'c2EntriesHeader',
'c2EntriesFooter',
'c2EntryIf',
2021-09-07 12:33:18 +00:00
2021-09-07 13:21:38 +00:00
'c2Pagination',
'c2PaginationIf',
2021-09-07 12:33:18 +00:00
2021-09-07 13:21:38 +00:00
'c2Categories',
'c2CategoriesHeader',
'c2CategoriesFooter',
2022-11-17 21:01:00 +00:00
'c2CategoryIf',
2021-11-02 22:55:41 +00:00
];
2021-09-07 12:33:18 +00:00
2022-11-17 21:01:00 +00:00
if (dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_active) {
2021-11-02 22:55:41 +00:00
foreach ($c2_tpl_blocks as $v) {
2022-11-17 21:01:00 +00:00
dcCore::app()->tpl->addBlock($v, ['tplCinecturlink2', $v]);
2021-09-07 13:21:38 +00:00
}
2021-11-02 22:55:41 +00:00
foreach ($c2_tpl_values as $v) {
2022-11-17 21:01:00 +00:00
dcCore::app()->tpl->addValue($v, ['tplCinecturlink2', $v]);
2021-09-07 13:21:38 +00:00
}
2021-11-02 22:55:41 +00:00
} else {
foreach (array_merge($c2_tpl_blocks, $c2_tpl_values) as $v) {
2022-11-17 21:01:00 +00:00
dcCore::app()->tpl->addBlock($v, ['tplCinecturlink2', 'disable']);
2021-09-07 13:21:38 +00:00
}
2021-09-07 12:33:18 +00:00
}
class urlCinecturlink2 extends dcUrlHandlers
{
2021-09-07 13:21:38 +00:00
public static function c2Page($args)
{
2022-11-17 21:01:00 +00:00
dcCore::app()->blog->settings->addNamespace('cinecturlink2');
$args = (string) $args;
2021-09-07 13:21:38 +00:00
2022-11-17 21:01:00 +00:00
if (!dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_active
|| !dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_active) {
2021-09-07 13:21:38 +00:00
self::p404();
return null;
}
2022-11-17 21:01:00 +00:00
dcCore::app()->tpl->setPath(
dcCore::app()->tpl->getPath(),
__DIR__ . '/default-templates/'
2021-09-07 13:21:38 +00:00
);
2021-11-02 22:55:41 +00:00
$params = [];
2021-09-07 13:21:38 +00:00
$n = self::getPageArgs($args, 'c2page');
if ($n) {
$GLOBALS['c2_page_number'] = $n;
}
2022-11-17 21:01:00 +00:00
$caturl = dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_caturl;
2021-11-02 22:55:41 +00:00
if (!$caturl) {
$caturl = 'c2cat';
}
2021-09-07 13:21:38 +00:00
$c = self::getPageArgs($args, $caturl);
if ($c) {
if (is_numeric($c)) {
2021-11-02 22:55:41 +00:00
$params['cat_id'] = (int) $c;
} else {
2021-09-07 13:21:38 +00:00
$params['cat_title'] = urldecode($c);
}
}
$f = self::getPageArgs($args, 'feed');
2021-11-02 22:55:41 +00:00
if ($f && in_array($f, ['atom', 'rss2'])) {
2021-09-07 13:21:38 +00:00
$mime = $f == 'atom' ? 'application/atom+xml' : 'application/xml';
2022-11-17 21:01:00 +00:00
//dcCore::app()->ctx->short_feed_items = dcCore::app()->blog->settings->system->short_feed_items;
2021-09-07 13:21:38 +00:00
2022-11-17 21:01:00 +00:00
$params['limit'] = dcCore::app()->blog->settings->system->nb_post_per_feed;
dcCore::app()->ctx->c2_page_params = $params;
2021-09-07 13:21:38 +00:00
2022-11-17 21:01:00 +00:00
header('X-Robots-Tag: ' . context::robotsPolicy(dcCore::app()->blog->settings->system->robots_policy, ''));
2021-11-02 22:55:41 +00:00
self::serveDocument('cinecturlink2-' . $f . '.xml', $mime);
} else {
2021-09-07 13:21:38 +00:00
$d = self::getPageArgs($args, 'c2detail');
if ($d) {
if (is_numeric($d)) {
2021-11-02 22:55:41 +00:00
$params['link_id'] = (int) $d;
} else {
2021-09-07 13:21:38 +00:00
$params['link_title'] = urldecode($d);
}
}
2022-11-17 21:01:00 +00:00
$params['limit'] = dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_nbrpp;
dcCore::app()->ctx->c2_page_params = $params;
2021-09-07 13:21:38 +00:00
self::serveDocument('cinecturlink2.html', 'text/html');
}
return null;
}
protected static function getPageArgs(&$args, $part)
{
2021-11-02 22:55:41 +00:00
if (preg_match('#(^|/)' . $part . '/([^/]+)#', $args, $m)) {
$args = preg_replace('#(^|/)' . $part . '/([^/]+)#', '', $args);
2021-09-07 13:21:38 +00:00
return $m[2];
}
return false;
}
2021-09-07 12:33:18 +00:00
}
class tplCinecturlink2
{
2021-11-02 22:55:41 +00:00
public static function disable($a, $c = null)
2021-09-07 13:21:38 +00:00
{
return '';
}
public static function c2PageURL($a)
{
2022-11-17 21:01:00 +00:00
return '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->blog->url.dcCore::app()->url->getBase(\'cinecturlink2\')') . '; ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2PageTitle($a)
{
2022-11-17 21:01:00 +00:00
return "<?php \$title = (string) dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_title; if (empty(\$title)) { \$title = __('My cinecturlink'); } echo " . sprintf(dcCore::app()->tpl->getFilters($a), '$title') . '; ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2PageFeedURL($a)
{
2022-11-17 21:01:00 +00:00
return '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("cinecturlink2")."/feed/' . (!empty($a['type']) && preg_match('#^(rss2|atom)$#', $a['type']) ? $a['type'] : 'atom') . '"') . '; ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2PageFeedID($a)
{
2022-11-17 21:01:00 +00:00
return 'urn:md5:<?php echo md5(dcCore::app()->blog->id."cinecturlink2"); ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2PageDescription($a)
{
2022-11-17 21:01:00 +00:00
return '<?php $description = (string) dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_description; echo ' . sprintf(dcCore::app()->tpl->getFilters($a), '$description') . '; ?>';
2021-09-07 13:21:38 +00:00
}
2021-11-02 22:55:41 +00:00
public static function c2If($a, $c)
2021-09-07 13:21:38 +00:00
{
2021-11-02 22:55:41 +00:00
$if = [];
2021-09-07 13:21:38 +00:00
$operator = isset($a['operator']) ? self::getOperator($a['operator']) : '&&';
if (isset($a['request_link'])) {
2021-11-02 22:55:41 +00:00
$sign = (bool) $a['request_link'] ? '' : '!';
2022-11-17 21:01:00 +00:00
$if[] = $sign . '(isset(dcCore::app()->ctx->c2_page_params["link_id"]) || isset(dcCore::app()->ctx->c2_page_params["link_title"]))';
2021-09-07 13:21:38 +00:00
}
if (isset($a['request_cat'])) {
2021-11-02 22:55:41 +00:00
$sign = (bool) $a['request_cat'] ? '' : '!';
2022-11-17 21:01:00 +00:00
$if[] = $sign . '(isset(dcCore::app()->ctx->c2_page_params["cat_id"]) || isset(dcCore::app()->ctx->c2_page_params["cat_title"]))';
2021-09-07 13:21:38 +00:00
}
2021-11-02 22:55:41 +00:00
return empty($if) ? $c : '<?php if(' . implode(' ' . $operator . ' ', $if) . ") : ?>\n" . $c . "<?php endif; ?>\n";
2021-09-07 13:21:38 +00:00
}
public static function c2Entries($a, $c)
{
2021-11-02 22:55:41 +00:00
$lastn = isset($a['lastn']) ? abs((int) $a['lastn']) + 0 : -1;
2021-09-07 13:21:38 +00:00
2021-11-02 22:55:41 +00:00
$res = 'if (!isset($c2_page_number)) { $c2_page_number = 1; }' . "\n";
2021-09-07 13:21:38 +00:00
if ($lastn != 0) {
if ($lastn > 0) {
2021-11-02 22:55:41 +00:00
$res .= "\$params['limit'] = " . $lastn . ";\n";
} else {
2021-09-07 13:21:38 +00:00
$res .= "if (!isset(\$params['limit']) || \$params['limit'] < 1) { \$params['limit'] = 10; }\n";
}
2021-11-02 22:55:41 +00:00
if (!isset($a['ignore_pagination']) || $a['ignore_pagination'] == '0') {
2021-09-07 13:21:38 +00:00
$res .= "\$params['limit'] = array(((\$c2_page_number-1)*\$params['limit']),\$params['limit']);\n";
2021-11-02 22:55:41 +00:00
} else {
2021-09-07 13:21:38 +00:00
$res .= "\$params['limit'] = array(0, \$params['limit']);\n";
}
}
if (isset($a['category'])) {
if ($a['category'] == 'null') {
$res .= "\$params['sql'] = ' AND L.cat_id IS NULL ';\n";
2021-11-02 22:55:41 +00:00
} elseif (is_numeric($a['category'])) {
$res .= "\$params['cat_id'] = " . (int) $a['category'] . ";\n";
} else {
$res .= "\$params['cat_title'] = '" . $a['category'] . "';\n";
2021-09-07 13:21:38 +00:00
}
}
2021-11-02 22:55:41 +00:00
$sort = isset($a['sort']) && $a['sort'] == 'asc' ? ' asc' : ' desc';
$sortby = isset($a['order']) && in_array($a['order'], ['link_count','link_upddt','link_creadt','link_note','link_title']) ? $a['order'] : 'link_upddt';
$res .= "\$params['order'] = '" . $sortby . $sort . "';\n";
return
"<?php \n" .
2022-11-17 21:01:00 +00:00
"\$params = is_array(dcCore::app()->ctx->c2_page_params) ? dcCore::app()->ctx->c2_page_params : array(); \n" .
2021-11-02 22:55:41 +00:00
$res .
2022-11-17 21:01:00 +00:00
"dcCore::app()->ctx->c2_params = \$params; unset(\$params);\n" .
"if (!dcCore::app()->ctx->exists('cinecturlink')) { dcCore::app()->ctx->cinecturlink = new cinecturlink2(); } \n" .
"dcCore::app()->ctx->c2_entries = dcCore::app()->ctx->cinecturlink->getLinks(dcCore::app()->ctx->c2_params); \n" .
'while (dcCore::app()->ctx->c2_entries->fetch()) : ?>' . $c . '<?php endwhile; ' . "\n" .
"dcCore::app()->ctx->pop('c2_entries'); dcCore::app()->ctx->pop('c2_params'); \n" .
2021-09-07 13:21:38 +00:00
"?>\n";
}
public static function c2EntriesHeader($a, $c)
{
2022-11-17 21:01:00 +00:00
return '<?php if (dcCore::app()->ctx->c2_entries->isStart()) : ?>' . $c . '<?php endif; ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2EntriesFooter($a, $c)
{
2022-11-17 21:01:00 +00:00
return '<?php if (dcCore::app()->ctx->c2_entries->isEnd()) : ?>' . $c . '<?php endif; ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2EntryIf($a, $c)
{
2021-11-02 22:55:41 +00:00
$if = [];
2021-09-07 13:21:38 +00:00
$operator = isset($a['operator']) ? self::getOperator($a['operator']) : '&&';
if (isset($a['has_category'])) {
2021-11-02 22:55:41 +00:00
$sign = (bool) $a['has_category'] ? '!' : '=';
2022-11-17 21:01:00 +00:00
$if[] = '(dcCore::app()->ctx->exists("c2_entries") && "" ' . $sign . '= dcCore::app()->ctx->c2_entries->cat_title)';
2021-09-07 13:21:38 +00:00
}
2021-11-02 22:55:41 +00:00
return empty($if) ? $c : '<?php if(' . implode(' ' . $operator . ' ', $if) . ") : ?>\n" . $c . "<?php endif; ?>\n";
2021-09-07 13:21:38 +00:00
}
public static function c2EntryIfFirst($a)
{
2022-11-17 21:01:00 +00:00
return '<?php if (dcCore::app()->ctx->c2_entries->index() == 0) { echo "' . (isset($a['return']) ? addslashes(html::escapeHTML($a['return'])) : 'first') . '"; } ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2EntryIfOdd($a)
{
2022-11-17 21:01:00 +00:00
return '<?php if ((dcCore::app()->ctx->c2_entries->index()+1)%2 == 1) { echo "' . (isset($a['return']) ? addslashes(html::escapeHTML($a['return'])) : 'odd') . '"; } ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2EntryFeedID($a)
{
2022-11-17 21:01:00 +00:00
return 'urn:md5:<?php echo md5(dcCore::app()->ctx->c2_entries->blog_id.dcCore::app()->ctx->c2_entries->link_id.dcCore::app()->ctx->c2_entries->link_creadt); ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2EntryID($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_id', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryTitle($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_title', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryDescription($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_desc', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryAuthorCommonName($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('dcUtils::getUserCN(dcCore::app()->ctx->c2_entries->user_id,dcCore::app()->ctx->c2_entries->user_name,dcCore::app()->ctx->c2_entries->user_firstname,dcCore::app()->ctx->c2_entries->user_displayname)', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryAuthorDisplayName($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('dcCore::app()->ctx->c2_entries->user_displayname', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryAuthorID($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('dcCore::app()->ctx->c2_entries->user_id', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryAuthorEmail($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue((isset($a['spam_protected']) && !$a['spam_protected'] ? 'dcCore::app()->ctx->c2_entries->user_email' : "strtr(dcCore::app()->ctx->c2_entries->user_email,array('@'=>'%40','.'=>'%2e'))"), $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryAuthorLink($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('sprintf((dcCore::app()->ctx->c2_entries->user_url ? \'<a href="%2$s">%1$s</a>\' : \'%1$s\'),html::escapeHTML(dcUtils::getUserCN(dcCore::app()->ctx->c2_entries->user_id,dcCore::app()->ctx->c2_entries->user_name,dcCore::app()->ctx->c2_entries->user_firstname,dcCore::app()->ctx->c2_entries->user_displayname)),html::escapeHTML(dcCore::app()->ctx->c2_entries->user_url))', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryAuthorURL($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('dcCore::app()->ctx->c2_entries->user_url', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryFromAuthor($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_author', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryLang($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_lang', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryURL($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_url', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryCategory($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('dcCore::app()->ctx->c2_entries->cat_title', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryCategoryID($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('dcCore::app()->ctx->c2_entries->cat_id', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryCategoryURL($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('dcCore::app()->blog->url.dcCore::app()->url->getBase("cinecturlink2")."/".dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_caturl."/".urlencode(dcCore::app()->ctx->c2_entries->cat_title)', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2EntryImg($a)
{
2022-11-17 21:01:00 +00:00
$f = dcCore::app()->tpl->getFilters($a);
2021-09-07 13:21:38 +00:00
$style = isset($a['style']) ? html::escapeHTML($a['style']) : '';
2021-11-02 22:55:41 +00:00
return
2022-11-17 21:01:00 +00:00
"<?php if (dcCore::app()->ctx->exists('c2_entries')) { " .
'$widthmax = (integer) dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_widthmax; ' .
2021-11-02 22:55:41 +00:00
"\$img = sprintf('<img src=\"%s\" alt=\"%s\" %s/>'," .
2022-11-17 21:01:00 +00:00
'dcCore::app()->ctx->c2_entries->link_img, ' .
"html::escapeHTML(dcCore::app()->ctx->c2_entries->link_title.' - '.dcCore::app()->ctx->c2_entries->link_author), " .
2021-11-02 22:55:41 +00:00
"(\$widthmax ? ' style=\"width:'.\$widthmax.'px;$style\"' : '') " .
'); ' .
'echo ' . sprintf($f, '$img') . "; unset(\$img); } ?> \n";
2021-09-07 13:21:38 +00:00
}
public static function c2EntryDate($a)
{
$format = !empty($a['format']) ? addslashes($a['format']) : '';
2021-11-02 22:55:41 +00:00
if (!empty($a['rfc822'])) {
2022-11-17 21:01:00 +00:00
$p = 'dt::rfc822(strtotime(dcCore::app()->ctx->c2_entries->link_creadt), dcCore::app()->blog->settings->system->blog_timezone)';
2021-11-02 22:55:41 +00:00
} elseif (!empty($a['iso8601'])) {
2022-11-17 21:01:00 +00:00
$p = 'dt::iso8601(strtotime(dcCore::app()->ctx->c2_entries->link_creadt), dcCore::app()->blog->settings->system->blog_timezone)';
2021-11-02 22:55:41 +00:00
} elseif ($format) {
2022-11-17 21:01:00 +00:00
$p = "dt::dt2str('" . $format . "', dcCore::app()->ctx->c2_entries->link_creadt)";
2021-11-02 22:55:41 +00:00
} else {
2022-11-17 21:01:00 +00:00
$p = 'dt::dt2str(dcCore::app()->blog->settings->system->date_format, dcCore::app()->ctx->c2_entries->link_creadt)';
2021-11-02 22:55:41 +00:00
}
2021-09-07 13:21:38 +00:00
return self::getGenericValue($p, $a);
}
public static function c2EntryTime($a)
{
2022-11-17 21:01:00 +00:00
return self::getGenericValue('dt::dt2str(' . (!empty($a['format']) ? "'" . addslashes($a['format']) . "'" : 'dcCore::app()->blog->settings->system->time_format') . ', dcCore::app()->ctx->c2_entries->link_creadt)', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2Pagination($a, $c)
{
2021-11-02 22:55:41 +00:00
$p = "<?php\n" .
2022-11-17 21:01:00 +00:00
"\$params = dcCore::app()->ctx->c2_params;\n" .
"dcCore::app()->ctx->c2_pagination = dcCore::app()->ctx->cinecturlink->getLinks(\$params,true); unset(\$params);\n" .
2021-09-07 13:21:38 +00:00
"?>\n";
2022-11-17 21:01:00 +00:00
return isset($a['no_context']) ? $p . $c : $p . '<?php if (dcCore::app()->ctx->c2_pagination->f(0) > dcCore::app()->ctx->c2_entries->count()) : ?>' . $c . '<?php endif; ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2PaginationCounter($a)
{
return self::getGenericValue('cinecturlink2Context::PaginationNbPages()', $a);
}
public static function c2PaginationCurrent($a)
{
2021-11-02 22:55:41 +00:00
return self::getGenericValue('cinecturlink2Context::PaginationPosition(' . (isset($a['offset']) ? (int) $a['offset'] : 0) . ')', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2PaginationIf($a, $c)
{
2021-11-02 22:55:41 +00:00
$if = [];
2021-09-07 13:21:38 +00:00
if (isset($a['start'])) {
2021-11-02 22:55:41 +00:00
$sign = (bool) $a['start'] ? '' : '!';
$if[] = $sign . 'cinecturlink2Context::PaginationStart()';
2021-09-07 13:21:38 +00:00
}
if (isset($a['end'])) {
2021-11-02 22:55:41 +00:00
$sign = (bool) $a['end'] ? '' : '!';
$if[] = $sign . 'cinecturlink2Context::PaginationEnd()';
2021-09-07 13:21:38 +00:00
}
2021-11-02 22:55:41 +00:00
return empty($if) ? $c : '<?php if(' . implode(' && ', $if) . ') : ?>' . $c . '<?php endif; ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2PaginationURL($a)
{
2021-11-02 22:55:41 +00:00
return self::getGenericValue('cinecturlink2Context::PaginationURL(' . (isset($a['offset']) ? (int) $a['offset'] : 0) . ')', $a);
2021-09-07 13:21:38 +00:00
}
public static function c2Categories($a, $c)
{
2021-11-02 22:55:41 +00:00
return
"<?php \n" .
2022-11-17 21:01:00 +00:00
"if (!dcCore::app()->ctx->exists('cinecturlink')) { dcCore::app()->ctx->cinecturlink = new cinecturlink2(); } \n" .
"dcCore::app()->ctx->c2_categories = dcCore::app()->ctx->cinecturlink->getCategories(); \n" .
'while (dcCore::app()->ctx->c2_categories->fetch()) : ?>' . $c . '<?php endwhile; ' . "\n" .
"dcCore::app()->ctx->c2_categories = null; \n" .
2021-09-07 13:21:38 +00:00
"?>\n";
}
public static function c2CategoriesHeader($a, $c)
{
2022-11-17 21:01:00 +00:00
return '<?php if (dcCore::app()->ctx->c2_categories->isStart()) : ?>' . $c . '<?php endif; ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2CategoriesFooter($a, $c)
{
2022-11-17 21:01:00 +00:00
return '<?php if (dcCore::app()->ctx->c2_categories->isEnd()) : ?>' . $c . '<?php endif; ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2CategoryIf($a, $c)
{
2021-11-02 22:55:41 +00:00
$if = [];
2021-09-07 13:21:38 +00:00
if (isset($a['current'])) {
2021-11-02 22:55:41 +00:00
$sign = (bool) $a['current'] ? '' : '!';
$if[] = $sign . 'cinecturlink2Context::CategoryCurrent()';
2021-09-07 13:21:38 +00:00
}
if (isset($a['first'])) {
2021-11-02 22:55:41 +00:00
$sign = (bool) $a['first'] ? '' : '!';
2022-11-17 21:01:00 +00:00
$if[] = $sign . 'dcCore::app()->ctx->c2_categories->isStart()';
2021-09-07 13:21:38 +00:00
}
2021-11-02 22:55:41 +00:00
return empty($if) ? $c : '<?php if(' . implode(' && ', $if) . ') : ?>' . $c . '<?php endif; ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2CategoryFeedURL($a)
{
$p = !empty($a['type']) ? $a['type'] : 'atom';
if (!preg_match('#^(rss2|atom)$#', $p)) {
$p = 'atom';
}
2022-11-17 21:01:00 +00:00
return '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("cinecturlink2")."/".dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_caturl."/".urlencode(dcCore::app()->ctx->c2_categories->cat_title)."/feed/' . $p . '"') . '; ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2CategoryFeedID($a)
{
2022-11-17 21:01:00 +00:00
return 'urn:md5:<?php echo md5(dcCore::app()->blog->id."cinecturlink2".dcCore::app()->ctx->c2_categories->cat_id); ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2CategoryID($a)
{
2022-11-17 21:01:00 +00:00
return "<?php if (dcCore::app()->ctx->exists('c2_categories')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->ctx->c2_categories->cat_id') . '; } ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2CategoryTitle($a)
{
2022-11-17 21:01:00 +00:00
return "<?php if (dcCore::app()->ctx->exists('c2_categories')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->ctx->c2_categories->cat_title') . '; } ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2CategoryDescription($a)
{
2022-11-17 21:01:00 +00:00
return "<?php if (dcCore::app()->ctx->exists('c2_categories')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->ctx->c2_categories->cat_desc') . '; } ?>';
2021-09-07 13:21:38 +00:00
}
public static function c2CategoryURL($a)
{
2022-11-17 21:01:00 +00:00
return "<?php if (dcCore::app()->ctx->exists('c2_categories')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("cinecturlink2")."/".dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_caturl."/".urlencode(dcCore::app()->ctx->c2_categories->cat_title)') . '; } ?>';
2021-09-07 13:21:38 +00:00
}
2021-11-02 22:55:41 +00:00
protected static function getGenericValue($p, $a)
2021-09-07 13:21:38 +00:00
{
2022-11-17 21:01:00 +00:00
return "<?php if (dcCore::app()->ctx->exists('c2_entries')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), "$p") . '; } ?>';
2021-09-07 13:21:38 +00:00
}
protected static function getOperator($op)
{
2021-11-02 22:55:41 +00:00
switch (strtolower($op)) {
2021-09-07 13:21:38 +00:00
case 'or':
case '||':
return '||';
case 'and':
case '&&':
default:
return '&&';
}
}
2021-11-02 22:55:41 +00:00
}