blog->settings->addNamespace('cinecturlink2');
$c2_tpl_values = [
'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',
'c2CategoryURL'
];
$c2_tpl_blocks = [
'c2If',
'c2Entries',
'c2EntriesHeader',
'c2EntriesFooter',
'c2EntryIf',
'c2Pagination',
'c2PaginationIf',
'c2Categories',
'c2CategoriesHeader',
'c2CategoriesFooter',
'c2CategoryIf'
];
if ($core->blog->settings->cinecturlink2->cinecturlink2_active) {
foreach ($c2_tpl_blocks as $v) {
$core->tpl->addBlock($v, ['tplCinecturlink2', $v]);
}
foreach ($c2_tpl_values as $v) {
$core->tpl->addValue($v, ['tplCinecturlink2', $v]);
}
} else {
foreach (array_merge($c2_tpl_blocks, $c2_tpl_values) as $v) {
$core->tpl->addBlock($v, ['tplCinecturlink2', 'disable']);
}
}
class urlCinecturlink2 extends dcUrlHandlers
{
public static function c2Page($args)
{
global $core, $_ctx;
$core->blog->settings->addNamespace('cinecturlink2');
if (!$core->blog->settings->cinecturlink2->cinecturlink2_active
|| !$core->blog->settings->cinecturlink2->cinecturlink2_public_active) {
self::p404();
return null;
}
$core->tpl->setPath(
$core->tpl->getPath(),
dirname(__FILE__) . '/default-templates/'
);
$params = [];
$n = self::getPageArgs($args, 'c2page');
if ($n) {
$GLOBALS['c2_page_number'] = $n;
}
$caturl = $core->blog->settings->cinecturlink2->cinecturlink2_public_caturl;
if (!$caturl) {
$caturl = 'c2cat';
}
$c = self::getPageArgs($args, $caturl);
if ($c) {
if (is_numeric($c)) {
$params['cat_id'] = (int) $c;
} else {
$params['cat_title'] = urldecode($c);
}
}
$f = self::getPageArgs($args, 'feed');
if ($f && in_array($f, ['atom', 'rss2'])) {
$mime = $f == 'atom' ? 'application/atom+xml' : 'application/xml';
//$_ctx->short_feed_items = $core->blog->settings->system->short_feed_items;
$params['limit'] = $core->blog->settings->system->nb_post_per_feed;
$_ctx->c2_page_params = $params;
header('X-Robots-Tag: ' . context::robotsPolicy($core->blog->settings->system->robots_policy, ''));
self::serveDocument('cinecturlink2-' . $f . '.xml', $mime);
} else {
$d = self::getPageArgs($args, 'c2detail');
if ($d) {
if (is_numeric($d)) {
$params['link_id'] = (int) $d;
} else {
$params['link_title'] = urldecode($d);
}
}
$params['limit'] = $core->blog->settings->cinecturlink2->cinecturlink2_public_nbrpp;
$_ctx->c2_page_params = $params;
self::serveDocument('cinecturlink2.html', 'text/html');
}
return null;
}
protected static function getPageArgs(&$args, $part)
{
if (preg_match('#(^|/)' . $part . '/([^/]+)#', $args, $m)) {
$args = preg_replace('#(^|/)' . $part . '/([^/]+)#', '', $args);
return $m[2];
}
return false;
}
}
class tplCinecturlink2
{
public static function disable($a, $c = null)
{
return '';
}
public static function c2PageURL($a)
{
return 'tpl->getFilters($a), '$core->blog->url.$core->url->getBase(\'cinecturlink2\')') . '; ?>';
}
public static function c2PageTitle($a)
{
return "blog->settings->cinecturlink2->cinecturlink2_public_title; if (empty(\$title)) { \$title = __('My cinecturlink'); } echo " . sprintf($GLOBALS['core']->tpl->getFilters($a), '$title') . '; ?>';
}
public static function c2PageFeedURL($a)
{
return 'tpl->getFilters($a), '$core->blog->url.$core->url->getBase("cinecturlink2")."/feed/' . (!empty($a['type']) && preg_match('#^(rss2|atom)$#', $a['type']) ? $a['type'] : 'atom') . '"') . '; ?>';
}
public static function c2PageFeedID($a)
{
return 'urn:md5:blog->blog_id."cinecturlink2"); ?>';
}
public static function c2PageDescription($a)
{
return 'blog->settings->cinecturlink2->cinecturlink2_public_description; echo ' . sprintf($GLOBALS['core']->tpl->getFilters($a), '$description') . '; ?>';
}
public static function c2If($a, $c)
{
$if = [];
$operator = isset($a['operator']) ? self::getOperator($a['operator']) : '&&';
if (isset($a['request_link'])) {
$sign = (bool) $a['request_link'] ? '' : '!';
$if[] = $sign . '(isset($_ctx->c2_page_params["link_id"]) || isset($_ctx->c2_page_params["link_title"]))';
}
if (isset($a['request_cat'])) {
$sign = (bool) $a['request_cat'] ? '' : '!';
$if[] = $sign . '(isset($_ctx->c2_page_params["cat_id"]) || isset($_ctx->c2_page_params["cat_title"]))';
}
return empty($if) ? $c : '\n" . $c . "\n";
}
public static function c2Entries($a, $c)
{
$lastn = isset($a['lastn']) ? abs((int) $a['lastn']) + 0 : -1;
$res = 'if (!isset($c2_page_number)) { $c2_page_number = 1; }' . "\n";
if ($lastn != 0) {
if ($lastn > 0) {
$res .= "\$params['limit'] = " . $lastn . ";\n";
} else {
$res .= "if (!isset(\$params['limit']) || \$params['limit'] < 1) { \$params['limit'] = 10; }\n";
}
if (!isset($a['ignore_pagination']) || $a['ignore_pagination'] == '0') {
$res .= "\$params['limit'] = array(((\$c2_page_number-1)*\$params['limit']),\$params['limit']);\n";
} else {
$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";
} elseif (is_numeric($a['category'])) {
$res .= "\$params['cat_id'] = " . (int) $a['category'] . ";\n";
} else {
$res .= "\$params['cat_title'] = '" . $a['category'] . "';\n";
}
}
$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
"c2_page_params) ? \$_ctx->c2_page_params : array(); \n" .
$res .
"\$_ctx->c2_params = \$params; unset(\$params);\n" .
"if (!\$_ctx->exists('cinecturlink')) { \$_ctx->cinecturlink = new cinecturlink2(\$core); } \n" .
"\$_ctx->c2_entries = \$_ctx->cinecturlink->getLinks(\$_ctx->c2_params); \n" .
'while ($_ctx->c2_entries->fetch()) : ?>' . $c . 'c2_entries = null; \$_ctx->c2_params = null; \n" .
"?>\n";
}
public static function c2EntriesHeader($a, $c)
{
return 'c2_entries->isStart()) : ?>' . $c . '';
}
public static function c2EntriesFooter($a, $c)
{
return 'c2_entries->isEnd()) : ?>' . $c . '';
}
public static function c2EntryIf($a, $c)
{
$if = [];
$operator = isset($a['operator']) ? self::getOperator($a['operator']) : '&&';
if (isset($a['has_category'])) {
$sign = (bool) $a['has_category'] ? '!' : '=';
$if[] = '($_ctx->exists("c2_entries") && "" ' . $sign . '= $_ctx->c2_entries->cat_title)';
}
return empty($if) ? $c : '\n" . $c . "\n";
}
public static function c2EntryIfFirst($a)
{
return 'c2_entries->index() == 0) { echo "' . (isset($a['return']) ? addslashes(html::escapeHTML($a['return'])) : 'first') . '"; } ?>';
}
public static function c2EntryIfOdd($a)
{
return 'c2_entries->index()+1)%2 == 1) { echo "' . (isset($a['return']) ? addslashes(html::escapeHTML($a['return'])) : 'odd') . '"; } ?>';
}
public static function c2EntryFeedID($a)
{
return 'urn:md5:c2_entries->blog_id.$_ctx->c2_entries->link_id.$_ctx->c2_entries->link_dt); ?>';
}
public static function c2EntryID($a)
{
return self::getGenericValue('$_ctx->c2_entries->link_id', $a);
}
public static function c2EntryTitle($a)
{
return self::getGenericValue('$_ctx->c2_entries->link_title', $a);
}
public static function c2EntryDescription($a)
{
return self::getGenericValue('$_ctx->c2_entries->link_desc', $a);
}
public static function c2EntryAuthorCommonName($a)
{
return self::getGenericValue('dcUtils::getUserCN($_ctx->c2_entries->user_id,$_ctx->c2_entries->user_name,$_ctx->c2_entries->user_firstname,$_ctx->c2_entries->user_displayname)', $a);
}
public static function c2EntryAuthorDisplayName($a)
{
return self::getGenericValue('$_ctx->c2_entries->user_displayname', $a);
}
public static function c2EntryAuthorID($a)
{
return self::getGenericValue('$_ctx->c2_entries->user_id', $a);
}
public static function c2EntryAuthorEmail($a)
{
return self::getGenericValue((isset($a['spam_protected']) && !$a['spam_protected'] ? '$_ctx->c2_entries->user_email' : "strtr(\$_ctx->c2_entries->user_email,array('@'=>'%40','.'=>'%2e'))"), $a);
}
public static function c2EntryAuthorLink($a)
{
return self::getGenericValue('sprintf(($_ctx->c2_entries->user_url ? \'%1$s\' : \'%1$s\'),html::escapeHTML(dcUtils::getUserCN($_ctx->c2_entries->user_id,$_ctx->c2_entries->user_name,$_ctx->c2_entries->user_firstname,$_ctx->c2_entries->user_displayname)),html::escapeHTML($_ctx->c2_entries->user_url))', $a);
}
public static function c2EntryAuthorURL($a)
{
return self::getGenericValue('$_ctx->c2_entries->user_url', $a);
}
public static function c2EntryFromAuthor($a)
{
return self::getGenericValue('$_ctx->c2_entries->link_author', $a);
}
public static function c2EntryLang($a)
{
return self::getGenericValue('$_ctx->c2_entries->link_lang', $a);
}
public static function c2EntryURL($a)
{
return self::getGenericValue('$_ctx->c2_entries->link_url', $a);
}
public static function c2EntryCategory($a)
{
return self::getGenericValue('$_ctx->c2_entries->cat_title', $a);
}
public static function c2EntryCategoryID($a)
{
return self::getGenericValue('$_ctx->c2_entries->cat_id', $a);
}
public static function c2EntryCategoryURL($a)
{
return self::getGenericValue('$core->blog->url.$core->url->getBase("cinecturlink2")."/".$core->blog->settings->cinecturlink2->cinecturlink2_public_caturl."/".urlencode($_ctx->c2_entries->cat_title)', $a);
}
public static function c2EntryImg($a)
{
global $core;
$f = $core->tpl->getFilters($a);
$style = isset($a['style']) ? html::escapeHTML($a['style']) : '';
return
"exists('c2_entries')) { " .
'$widthmax = (integer) $core->blog->settings->cinecturlink2->cinecturlink2_widthmax; ' .
"\$img = sprintf(''," .
'$_ctx->c2_entries->link_img, ' .
"html::escapeHTML(\$_ctx->c2_entries->link_title.' - '.\$_ctx->c2_entries->link_author), " .
"(\$widthmax ? ' style=\"width:'.\$widthmax.'px;$style\"' : '') " .
'); ' .
'echo ' . sprintf($f, '$img') . "; unset(\$img); } ?> \n";
}
public static function c2EntryDate($a)
{
$format = !empty($a['format']) ? addslashes($a['format']) : '';
if (!empty($a['rfc822'])) {
$p = 'dt::rfc822(strtotime($_ctx->c2_entries->link_creadt), $_ctx->posts->post_tz)';
} elseif (!empty($a['iso8601'])) {
$p = 'dt::iso8601(strtotime($_ctx->c2_entries->link_creadt), $_ctx->posts->post_tz)';
} elseif ($format) {
$p = "dt::dt2str('" . $format . "', \$_ctx->c2_entries->link_creadt)";
} else {
$p = 'dt::dt2str($core->blog->settings->system->date_format, $_ctx->c2_entries->link_creadt)';
}
return self::getGenericValue($p, $a);
}
public static function c2EntryTime($a)
{
return self::getGenericValue('dt::dt2str(' . (!empty($a['format']) ? "'" . addslashes($a['format']) . "'" : '$core->blog->settings->system->time_format') . ', $_ctx->c2_entries->link_creadt)', $a);
}
public static function c2Pagination($a, $c)
{
$p = "c2_params;\n" .
"\$_ctx->c2_pagination = \$_ctx->cinecturlink->getLinks(\$params,true); unset(\$params);\n" .
"?>\n";
return isset($a['no_context']) ? $p . $c : $p . 'c2_pagination->f(0) > $_ctx->c2_entries->count()) : ?>' . $c . '';
}
public static function c2PaginationCounter($a)
{
return self::getGenericValue('cinecturlink2Context::PaginationNbPages()', $a);
}
public static function c2PaginationCurrent($a)
{
return self::getGenericValue('cinecturlink2Context::PaginationPosition(' . (isset($a['offset']) ? (int) $a['offset'] : 0) . ')', $a);
}
public static function c2PaginationIf($a, $c)
{
$if = [];
if (isset($a['start'])) {
$sign = (bool) $a['start'] ? '' : '!';
$if[] = $sign . 'cinecturlink2Context::PaginationStart()';
}
if (isset($a['end'])) {
$sign = (bool) $a['end'] ? '' : '!';
$if[] = $sign . 'cinecturlink2Context::PaginationEnd()';
}
return empty($if) ? $c : '' . $c . '';
}
public static function c2PaginationURL($a)
{
return self::getGenericValue('cinecturlink2Context::PaginationURL(' . (isset($a['offset']) ? (int) $a['offset'] : 0) . ')', $a);
}
public static function c2Categories($a, $c)
{
return
"exists('cinecturlink')) { \$_ctx->cinecturlink = new cinecturlink2(\$core); } \n" .
"\$_ctx->c2_categories = \$_ctx->cinecturlink->getCategories(); \n" .
'while ($_ctx->c2_categories->fetch()) : ?>' . $c . 'c2_categories = null; \n" .
"?>\n";
}
public static function c2CategoriesHeader($a, $c)
{
return 'c2_categories->isStart()) : ?>' . $c . '';
}
public static function c2CategoriesFooter($a, $c)
{
return 'c2_categories->isEnd()) : ?>' . $c . '';
}
public static function c2CategoryIf($a, $c)
{
$if = [];
if (isset($a['current'])) {
$sign = (bool) $a['current'] ? '' : '!';
$if[] = $sign . 'cinecturlink2Context::CategoryCurrent()';
}
if (isset($a['first'])) {
$sign = (bool) $a['first'] ? '' : '!';
$if[] = $sign . '$_ctx->c2_categories->isStart()';
}
return empty($if) ? $c : '' . $c . '';
}
public static function c2CategoryFeedURL($a)
{
$p = !empty($a['type']) ? $a['type'] : 'atom';
if (!preg_match('#^(rss2|atom)$#', $p)) {
$p = 'atom';
}
return 'tpl->getFilters($a), '$core->blog->url.$core->url->getBase("cinecturlink2")."/".$core->blog->settings->cinecturlink2->cinecturlink2_public_caturl."/".urlencode($_ctx->c2_categories->cat_title)."/feed/' . $p . '"') . '; ?>';
}
public static function c2CategoryFeedID($a)
{
return 'urn:md5:blog->blog_id."cinecturlink2".$_ctx->c2_categories->cat_id); ?>';
}
public static function c2CategoryID($a)
{
return "exists('c2_categories')) { echo " . sprintf($GLOBALS['core']->tpl->getFilters($a), '$_ctx->c2_categories->cat_id') . '; } ?>';
}
public static function c2CategoryTitle($a)
{
return "exists('c2_categories')) { echo " . sprintf($GLOBALS['core']->tpl->getFilters($a), '$_ctx->c2_categories->cat_title') . '; } ?>';
}
public static function c2CategoryDescription($a)
{
return "exists('c2_categories')) { echo " . sprintf($GLOBALS['core']->tpl->getFilters($a), '$_ctx->c2_categories->cat_desc') . '; } ?>';
}
public static function c2CategoryURL($a)
{
return "exists('c2_categories')) { echo " . sprintf($GLOBALS['core']->tpl->getFilters($a), '$core->blog->url.$core->url->getBase("cinecturlink2")."/".$core->blog->settings->cinecturlink2->cinecturlink2_public_caturl."/".urlencode($_ctx->c2_categories->cat_title)') . '; } ?>';
}
protected static function getGenericValue($p, $a)
{
return "exists('c2_entries')) { echo " . sprintf($GLOBALS['core']->tpl->getFilters($a), "$p") . '; } ?>';
}
protected static function getOperator($op)
{
switch (strtolower($op)) {
case 'or':
case '||':
return '||';
case 'and':
case '&&':
default:
return '&&';
}
}
}