From b21e286961248ab04955608d619265e73d8a18ab Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Tue, 7 Sep 2021 15:21:38 +0200 Subject: [PATCH] cleanup code --- README.md | 2 +- _admin.php | 91 +- _install.php | 135 ++- _public.php | 1033 +++++++++++----------- _uninstall.php | 108 ++- _widgets.php | 595 +++++++------ dcstore.xml | 12 + default-templates/cinecturlink2-atom.xml | 4 +- default-templates/cinecturlink2-rss2.xml | 6 +- inc/class.cinecturlink2.php | 795 +++++++++-------- inc/lib.cinecturlink2.context.php | 171 ++-- inc/lib.cinecturlink2.list.php | 173 ++-- inc/lib.sitemaps.cinecturlink2.php | 73 +- index.php | 955 ++++++++++---------- js/cinecturlink2.js | 6 +- locales/fr/main.lang.php | 4 +- 16 files changed, 2077 insertions(+), 2086 deletions(-) create mode 100644 dcstore.xml diff --git a/README.md b/README.md index ff1ecd7..5f0acef 100644 --- a/README.md +++ b/README.md @@ -40,4 +40,4 @@ to your theme tpl path and adapt them. * License : GNU GPL v2 * Source & contribution : [GitHub Page](https://github.com/JcDenis/cinecturlink2) * Packages & details: [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/cinecturlink2) - * Discuss and help : [Dotclear Forum](https://forum.dotclear.org/viewtopic.php?id=40893) + * Discuss and help : [Dotclear Forum](https://forum.dotclear.org/viewtopic.php?id=40893) \ No newline at end of file diff --git a/_admin.php b/_admin.php index 295082e..54e1270 100644 --- a/_admin.php +++ b/_admin.php @@ -1,65 +1,56 @@ addItem( - __('My cinecturlink'), - 'plugin.php?p=cinecturlink2', - 'index.php?pf=cinecturlink2/icon.png', - preg_match( - '/plugin.php\?p=cinecturlink2(&.*)?$/', - $_SERVER['REQUEST_URI']) - , - $core->auth->check('contentadmin', $core->blog->id) + __('My cinecturlink'), + $core->adminurl->get('admin.plugin.cinecturlink2'), + dcPage::getPF('cinecturlink2/icon.png'), + preg_match( + '/' . preg_quote($core->adminurl->get('admin.plugin.dcAdvancedCleaner')) . '(&.*)?$/', + $_SERVER['REQUEST_URI'] + ), + $core->auth->check('contentadmin', $core->blog->id) ); $core->addBehavior( - 'adminDashboardFavorites', - array('cinecturlink2AdminBehaviors', 'adminDashboardFavorites') + 'adminDashboardFavorites', + ['cinecturlink2AdminBehaviors', 'adminDashboardFavorites'] ); class cinecturlink2AdminBehaviors { - public static function adminDashboardFavorites($core, $favs) - { - $favs->register('cinecturlink2', array( - 'title' => __('My cinecturlink'), - 'url' => 'plugin.php?p=cinecturlink2#links', - 'small-icon' => 'index.php?pf=cinecturlink2/icon.png', - 'large-icon' => 'index.php?pf=cinecturlink2/icon-big.png', - 'permissions' => $core->auth->check( - 'contentadmin', - $core->blog->id - ), - 'active_cb' => array( - 'cinecturlink2AdminBehaviors', - 'adminDashboardFavoritesActive' - ) - )); - } + public static function adminDashboardFavorites($core, $favs) + { + $favs->register('cinecturlink2', [ + 'title' => __('My cinecturlink'), + 'url' => $core->adminurl->get('admin.plugin.cinecturlink2').'#links', + 'small-icon' => dcPage::getPF('cinecturlink2/icon.png'), + 'large-icon' => dcPage::getPF('cinecturlink2/icon-big.png'), + 'permissions' => $core->auth->check('contentadmin', $core->blog->id), + 'active_cb' => ['cinecturlink2AdminBehaviors', 'adminDashboardFavoritesActive'] + ]); + } - public static function adminDashboardFavoritesActive($request, $params) - { - return $request == 'plugin.php' - && isset($params['p']) - && $params['p'] == 'cinecturlink2'; - } -} + public static function adminDashboardFavoritesActive($request, $params) + { + return $request == 'plugin.php' + && isset($params['p']) + && $params['p'] == 'cinecturlink2'; + } +} \ No newline at end of file diff --git a/_install.php b/_install.php index 3832363..4a7a717 100644 --- a/_install.php +++ b/_install.php @@ -1,19 +1,18 @@ plugins->moduleInfo('cinecturlink2', 'version'); @@ -24,69 +23,69 @@ if (version_compare($old_version, $new_version, '>=')) { } try { - $s = new dbStruct($core->con, $core->prefix); - $s->cinecturlink2 - ->link_id ('bigint', 0, false) - ->blog_id ('varchar', 32, false) - ->cat_id ('bigint', 0, true) - ->user_id ('varchar', 32, true) - ->link_type ('varchar', 32, false, "'cinecturlink'") - ->link_title ('varchar', 255, false) - ->link_desc ('varchar', 255, false) - ->link_author ('varchar', 255, false) - ->link_lang ('varchar', 5, false, "'en'") - ->link_url ('varchar', 255, false) - ->link_img ('varchar', 255, false) - ->link_creadt ('timestamp', 0, false, 'now()') - ->link_upddt ('timestamp', 0, false, 'now()') - ->link_pos ('smallint', 0, false, "'0'") - ->link_note('smallint', 0, false, "'10'") - ->link_count('bigint', 0, false, "'0'") + $s = new dbStruct($core->con, $core->prefix); + $s->cinecturlink2 + ->link_id ('bigint', 0, false) + ->blog_id ('varchar', 32, false) + ->cat_id ('bigint', 0, true) + ->user_id ('varchar', 32, true) + ->link_type ('varchar', 32, false, "'cinecturlink'") + ->link_title ('varchar', 255, false) + ->link_desc ('varchar', 255, false) + ->link_author ('varchar', 255, false) + ->link_lang ('varchar', 5, false, "'en'") + ->link_url ('varchar', 255, false) + ->link_img ('varchar', 255, false) + ->link_creadt ('timestamp', 0, false, 'now()') + ->link_upddt ('timestamp', 0, false, 'now()') + ->link_pos ('smallint', 0, false, "'0'") + ->link_note('smallint', 0, false, "'10'") + ->link_count('bigint', 0, false, "'0'") - ->primary('pk_cinecturlink2', 'link_id') - ->index('idx_cinecturlink2_title', 'btree', 'link_title') - ->index('idx_cinecturlink2_author', 'btree', 'link_author') - ->index('idx_cinecturlink2_blog_id', 'btree', 'blog_id') - ->index('idx_cinecturlink2_cat_id', 'btree', 'cat_id') - ->index('idx_cinecturlink2_user_id', 'btree', 'user_id') - ->index('idx_cinecturlink2_type', 'btree', 'link_type'); + ->primary('pk_cinecturlink2', 'link_id') + ->index('idx_cinecturlink2_title', 'btree', 'link_title') + ->index('idx_cinecturlink2_author', 'btree', 'link_author') + ->index('idx_cinecturlink2_blog_id', 'btree', 'blog_id') + ->index('idx_cinecturlink2_cat_id', 'btree', 'cat_id') + ->index('idx_cinecturlink2_user_id', 'btree', 'user_id') + ->index('idx_cinecturlink2_type', 'btree', 'link_type'); - $s->cinecturlink2_cat - ->cat_id ('bigint', 0, false) - ->blog_id ('varchar', 32, false) - ->cat_title ('varchar', 255, false) - ->cat_desc ('varchar', 255, false) - ->cat_creadt ('timestamp', 0, false, 'now()') - ->cat_upddt ('timestamp', 0, false, 'now()') - ->cat_pos ('smallint', 0, false, "'0'") + $s->cinecturlink2_cat + ->cat_id ('bigint', 0, false) + ->blog_id ('varchar', 32, false) + ->cat_title ('varchar', 255, false) + ->cat_desc ('varchar', 255, false) + ->cat_creadt ('timestamp', 0, false, 'now()') + ->cat_upddt ('timestamp', 0, false, 'now()') + ->cat_pos ('smallint', 0, false, "'0'") - ->primary('pk_cinecturlink2_cat', 'cat_id') - ->index('idx_cinecturlink2_cat_blog_id', 'btree', 'blog_id') - ->unique('uk_cinecturlink2_cat_title', 'cat_title', 'blog_id'); + ->primary('pk_cinecturlink2_cat', 'cat_id') + ->index('idx_cinecturlink2_cat_blog_id', 'btree', 'blog_id') + ->unique('uk_cinecturlink2_cat_title', 'cat_title', 'blog_id'); - $si = new dbStruct($core->con,$core->prefix); - $changes = $si->synchronize($s); + $si = new dbStruct($core->con,$core->prefix); + $changes = $si->synchronize($s); - $core->blog->settings->addNamespace('cinecturlink2'); - $s = $core->blog->settings->cinecturlink2; - $s->put('cinecturlink2_active', true, 'boolean', 'Enable cinecturlink2', false, true); - $s->put('cinecturlink2_widthmax', 100, 'integer', 'Maximum width of picture', false, true); - $s->put('cinecturlink2_folder', 'cinecturlink', 'string', 'Public folder of pictures', false, true); - $s->put('cinecturlink2_triggeronrandom', false, 'boolean', 'Open link in new window', false, true); - $s->put('cinecturlink2_public_active', false, 'boolean', 'Enable cinecturlink2', false, true); - $s->put('cinecturlink2_public_title', '', 'string', 'Title of public page', false, true); - $s->put('cinecturlink2_public_description', '', 'string','Description of public page', false, true); - $s->put('cinecturlink2_public_nbrpp', 20, 'integer', 'Number of entries per page on public page', false, true); - $s->put('cinecturlink2_public_caturl', 'c2cat', 'string', 'Part of URL for a category list', false, true); + $core->blog->settings->addNamespace('cinecturlink2'); + $s = $core->blog->settings->cinecturlink2; + $s->put('cinecturlink2_active', true, 'boolean', 'Enable cinecturlink2', false, true); + $s->put('cinecturlink2_widthmax', 100, 'integer', 'Maximum width of picture', false, true); + $s->put('cinecturlink2_folder', 'cinecturlink', 'string', 'Public folder of pictures', false, true); + $s->put('cinecturlink2_triggeronrandom', false, 'boolean', 'Open link in new window', false, true); + $s->put('cinecturlink2_public_active', false, 'boolean', 'Enable cinecturlink2', false, true); + $s->put('cinecturlink2_public_title', '', 'string', 'Title of public page', false, true); + $s->put('cinecturlink2_public_description', '', 'string','Description of public page', false, true); + $s->put('cinecturlink2_public_nbrpp', 20, 'integer', 'Number of entries per page on public page', false, true); + $s->put('cinecturlink2_public_caturl', 'c2cat', 'string', 'Part of URL for a category list', false, true); - $core->setVersion( - 'cinecturlink2', - $core->plugins->moduleInfo('cinecturlink2', 'version') - ); + $core->setVersion( + 'cinecturlink2', + $core->plugins->moduleInfo('cinecturlink2', 'version') + ); - return true; + return true; } catch (Exception $e) { - $core->error->add($e->getMessage()); + $core->error->add($e->getMessage()); } return false; \ No newline at end of file diff --git a/_public.php b/_public.php index 898122c..7ddb514 100644 --- a/_public.php +++ b/_public.php @@ -1,20 +1,19 @@ blog->settings->addNamespace('cinecturlink2'); $c2_tpl_values = array( - 'c2PageFeedID', - 'c2PageFeedURL', - 'c2PageURL', - 'c2PageTitle', - 'c2PageDescription', + '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', + 'c2EntryIfOdd', + 'c2EntryIfFirst', + 'c2EntryFeedID', + 'c2EntryID', + 'c2EntryTitle', + 'c2EntryDescription', + 'c2EntryFromAuthor', + 'c2EntryAuthorCommonName', + 'c2EntryAuthorDisplayName', + 'c2EntryAuthorEmail', + 'c2EntryAuthorID', + 'c2EntryAuthorLink', + 'c2EntryAuthorURL', + 'c2EntryLang', + 'c2EntryURL', + 'c2EntryCategory', + 'c2EntryCategoryID', + 'c2EntryCategoryURL', + 'c2EntryImg', + 'c2EntryDate', + 'c2EntryTime', - 'c2PaginationCounter', - 'c2PaginationCurrent', - 'c2PaginationURL', + 'c2PaginationCounter', + 'c2PaginationCurrent', + 'c2PaginationURL', - 'c2CategoryFeedID', - 'c2CategoryFeedURL', - 'c2CategoryID', - 'c2CategoryTitle', - 'c2CategoryDescription', - 'c2CategoryURL' + 'c2CategoryFeedID', + 'c2CategoryFeedURL', + 'c2CategoryID', + 'c2CategoryTitle', + 'c2CategoryDescription', + 'c2CategoryURL' ); $c2_tpl_blocks = array( - 'c2If', + 'c2If', - 'c2Entries', - 'c2EntriesHeader', - 'c2EntriesFooter', - 'c2EntryIf', + 'c2Entries', + 'c2EntriesHeader', + 'c2EntriesFooter', + 'c2EntryIf', - 'c2Pagination', - 'c2PaginationIf', + 'c2Pagination', + 'c2PaginationIf', - 'c2Categories', - 'c2CategoriesHeader', - 'c2CategoriesFooter', - 'c2CategoryIf' + 'c2Categories', + 'c2CategoriesHeader', + 'c2CategoriesFooter', + 'c2CategoryIf' ); if ($core->blog->settings->cinecturlink2->cinecturlink2_active) { - foreach($c2_tpl_blocks as $v) { - $core->tpl->addBlock($v, array('tplCinecturlink2', $v)); - } - foreach($c2_tpl_values as $v) { - $core->tpl->addValue($v, array('tplCinecturlink2', $v)); - } + foreach($c2_tpl_blocks as $v) { + $core->tpl->addBlock($v, array('tplCinecturlink2', $v)); + } + foreach($c2_tpl_values as $v) { + $core->tpl->addValue($v, array('tplCinecturlink2', $v)); + } } else { - foreach(array_merge($c2_tpl_blocks, $c2_tpl_values) as $v) { - $core->tpl->addBlock($v, array('tplCinecturlink2', 'disable')); - } + foreach(array_merge($c2_tpl_blocks, $c2_tpl_values) as $v) { + $core->tpl->addBlock($v, array('tplCinecturlink2', 'disable')); + } } class urlCinecturlink2 extends dcUrlHandlers { - public static function c2Page($args) - { - global $core, $_ctx; - $core->blog->settings->addNamespace('cinecturlink2'); + 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(); + if (!$core->blog->settings->cinecturlink2->cinecturlink2_active + || !$core->blog->settings->cinecturlink2->cinecturlink2_public_active) + { + self::p404(); - return null; - } + return null; + } - $core->tpl->setPath( - $core->tpl->getPath(), - dirname(__FILE__).'/default-templates/' - ); + $core->tpl->setPath( + $core->tpl->getPath(), + dirname(__FILE__).'/default-templates/' + ); - $params = array(); + $params = array(); - $n = self::getPageArgs($args, 'c2page'); - if ($n) { - $GLOBALS['c2_page_number'] = $n; - } + $n = self::getPageArgs($args, 'c2page'); + if ($n) { + $GLOBALS['c2_page_number'] = $n; + } - $caturl = $core->blog->settings->cinecturlink2->cinecturlink2_public_caturl; - if (!$caturl) $caturl = 'c2cat'; + $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'] = (integer) $c; - } - else { - $params['cat_title'] = urldecode($c); - } - } + $c = self::getPageArgs($args, $caturl); + if ($c) { + if (is_numeric($c)) { + $params['cat_id'] = (integer) $c; + } + else { + $params['cat_title'] = urldecode($c); + } + } - $f = self::getPageArgs($args, 'feed'); - if ($f && in_array($f, array('atom', 'rss2'))) { - $mime = $f == 'atom' ? 'application/atom+xml' : 'application/xml'; + $f = self::getPageArgs($args, 'feed'); + if ($f && in_array($f, array('atom', 'rss2'))) { + $mime = $f == 'atom' ? 'application/atom+xml' : 'application/xml'; - //$_ctx->short_feed_items = $core->blog->settings->system->short_feed_items; + //$_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; + $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'] = (integer) $d; - } - else { - $params['link_title'] = urldecode($d); - } - } + 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'] = (integer) $d; + } + else { + $params['link_title'] = urldecode($d); + } + } - $params['limit'] = $core->blog->settings->cinecturlink2->cinecturlink2_public_nbrpp; - $_ctx->c2_page_params = $params; + $params['limit'] = $core->blog->settings->cinecturlink2->cinecturlink2_public_nbrpp; + $_ctx->c2_page_params = $params; - self::serveDocument('cinecturlink2.html', 'text/html'); - } + self::serveDocument('cinecturlink2.html', 'text/html'); + } - return null; - } + return null; + } - protected static function getPageArgs(&$args, $part) - { - if (preg_match('#(^|/)'.$part.'/([^/]+)#', $args, $m)) { - $args = preg_replace('#(^|/)'.$part.'/([^/]+)#', '', $args); + protected static function getPageArgs(&$args, $part) + { + if (preg_match('#(^|/)'.$part.'/([^/]+)#', $args, $m)) { + $args = preg_replace('#(^|/)'.$part.'/([^/]+)#', '', $args); - return $m[2]; - } + return $m[2]; + } - return false; - } + 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 = array(); - - $operator = isset($a['operator']) ? self::getOperator($a['operator']) : '&&'; - - if (isset($a['request_link'])) { - $sign = (boolean) $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 = (boolean) $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((integer) $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'] = ".(integer) $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'],array('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 = array(); - - $operator = isset($a['operator']) ? self::getOperator($a['operator']) : '&&'; - - if (isset($a['has_category'])) { - $sign = (boolean) $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('\"%s\"',". - "\$_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']) ? (integer) $a['offset'] : 0).')', $a); - } - - public static function c2PaginationIf($a, $c) - { - $if = array(); - - if (isset($a['start'])) { - $sign = (boolean) $a['start'] ? '' : '!'; - $if[] = $sign.'cinecturlink2Context::PaginationStart()'; - } - if (isset($a['end'])) { - $sign = (boolean) $a['end'] ? '' : '!'; - $if[] = $sign.'cinecturlink2Context::PaginationEnd()'; - } - - return empty($if) ? $c : ''.$c.''; - } - - public static function c2PaginationURL($a) - { - return self::getGenericValue('cinecturlink2Context::PaginationURL('.(isset($a['offset']) ? (integer) $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 = array(); - - if (isset($a['current'])) { - $sign = (boolean) $a['current'] ? '' : '!'; - $if[] = $sign.'cinecturlink2Context::CategoryCurrent()'; - } - if (isset($a['first'])) { - $sign = (boolean) $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 '&&'; - } - } -} + 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 = array(); + + $operator = isset($a['operator']) ? self::getOperator($a['operator']) : '&&'; + + if (isset($a['request_link'])) { + $sign = (boolean) $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 = (boolean) $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((integer) $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'] = ".(integer) $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'],array('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 = array(); + + $operator = isset($a['operator']) ? self::getOperator($a['operator']) : '&&'; + + if (isset($a['has_category'])) { + $sign = (boolean) $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('\"%s\"',". + "\$_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']) ? (integer) $a['offset'] : 0).')', $a); + } + + public static function c2PaginationIf($a, $c) + { + $if = array(); + + if (isset($a['start'])) { + $sign = (boolean) $a['start'] ? '' : '!'; + $if[] = $sign.'cinecturlink2Context::PaginationStart()'; + } + if (isset($a['end'])) { + $sign = (boolean) $a['end'] ? '' : '!'; + $if[] = $sign.'cinecturlink2Context::PaginationEnd()'; + } + + return empty($if) ? $c : ''.$c.''; + } + + public static function c2PaginationURL($a) + { + return self::getGenericValue('cinecturlink2Context::PaginationURL('.(isset($a['offset']) ? (integer) $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 = array(); + + if (isset($a['current'])) { + $sign = (boolean) $a['current'] ? '' : '!'; + $if[] = $sign.'cinecturlink2Context::CategoryCurrent()'; + } + if (isset($a['first'])) { + $sign = (boolean) $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 '&&'; + } + } +} \ No newline at end of file diff --git a/_uninstall.php b/_uninstall.php index ce91a81..dfb24d5 100644 --- a/_uninstall.php +++ b/_uninstall.php @@ -1,88 +1,86 @@ addUserAction( - /* type */ 'settings', - /* action */ 'delete_all', - /* ns */ 'cinecturlink2', - /* desc */ __('delete all settings') + /* type */ 'settings', + /* action */ 'delete_all', + /* ns */ 'cinecturlink2', + /* desc */ __('delete all settings') ); $this->addUserAction( - /* type */ 'tables', - /* action */ 'delete', - /* ns */ 'cinecturlink2', - /* desc */ sprintf(__('delete %s table'), 'cinecturlink2') + /* type */ 'tables', + /* action */ 'delete', + /* ns */ 'cinecturlink2', + /* desc */ sprintf(__('delete %s table'), 'cinecturlink2') ); $this->addUserAction( - /* type */ 'tables', - /* action */ 'delete', - /* ns */ 'cinecturlink2_cat', - /* desc */ sprintf(__('delete %s table'), 'cinecturlink2_cat') + /* type */ 'tables', + /* action */ 'delete', + /* ns */ 'cinecturlink2_cat', + /* desc */ sprintf(__('delete %s table'), 'cinecturlink2_cat') ); $this->addUserAction( - /* type */ 'versions', - /* action */ 'delete', - /* ns */ 'cinecturlink2', - /* desc */ __('delete the version number') + /* type */ 'versions', + /* action */ 'delete', + /* ns */ 'cinecturlink2', + /* desc */ __('delete the version number') ); $this->addUserAction( - /* type */ 'plugins', - /* action */ 'delete', - /* ns */ 'cinecturlink2', - /* desc */ __('delete plugin files') + /* type */ 'plugins', + /* action */ 'delete', + /* ns */ 'cinecturlink2', + /* desc */ __('delete plugin files') ); $this->addDirectAction( - /* type */ 'settings', - /* action */ 'delete_all', - /* ns */ 'cinecturlink2', - /* desc */ sprintf(__('delete all %s settings'), 'cinecturlink2') + /* type */ 'settings', + /* action */ 'delete_all', + /* ns */ 'cinecturlink2', + /* desc */ sprintf(__('delete all %s settings'), 'cinecturlink2') ); $this->addDirectAction( - /* type */ 'tables', - /* action */ 'delete', - /* ns */ 'cinecturlink2', - /* desc */ sprintf(__('delete %s table'), 'cinecturlink2') + /* type */ 'tables', + /* action */ 'delete', + /* ns */ 'cinecturlink2', + /* desc */ sprintf(__('delete %s table'), 'cinecturlink2') ); $this->addDirectAction( - /* type */ 'tables', - /* action */ 'delete', - /* ns */ 'cinecturlink2_cat', - /* desc */ sprintf(__('delete %s table'), 'cinecturlink2_cat') + /* type */ 'tables', + /* action */ 'delete', + /* ns */ 'cinecturlink2_cat', + /* desc */ sprintf(__('delete %s table'), 'cinecturlink2_cat') ); $this->addDirectAction( - /* type */ 'versions', - /* action */ 'delete', - /* ns */ 'cinecturlink2', - /* desc */ sprintf(__('delete %s version number'), 'cinecturlink2') + /* type */ 'versions', + /* action */ 'delete', + /* ns */ 'cinecturlink2', + /* desc */ sprintf(__('delete %s version number'), 'cinecturlink2') ); $this->addDirectAction( - /* type */ 'plugins', - /* action */ 'delete', - /* ns */ 'cinecturlink2', - /* description */ sprintf(__('delete %s plugin files'), 'cinecturlink2') -); + /* type */ 'plugins', + /* action */ 'delete', + /* ns */ 'cinecturlink2', + /* description */ sprintf(__('delete %s plugin files'), 'cinecturlink2') +); \ No newline at end of file diff --git a/_widgets.php b/_widgets.php index 36b8f58..9cb411d 100644 --- a/_widgets.php +++ b/_widgets.php @@ -1,347 +1,346 @@ addBehavior( - 'initWidgets', - array('cinecturlink2Widget', 'adminLinks') + 'initWidgets', + array('cinecturlink2Widget', 'adminLinks') ); $core->addBehavior( - 'initWidgets', - array('cinecturlink2Widget', 'adminCats') + 'initWidgets', + array('cinecturlink2Widget', 'adminCats') ); class cinecturlink2Widget { - public static function adminLinks($w) - { - global $core; + public static function adminLinks($w) + { + global $core; - $C2 = new cinecturlink2($core); + $C2 = new cinecturlink2($core); - $categories_combo = array('' => '', __('Uncategorized') => 'null'); - $categories = $C2->getCategories(); - while($categories->fetch()) { - $cat_title = html::escapeHTML($categories->cat_title); - $categories_combo[$cat_title] = $categories->cat_id; - } + $categories_combo = array('' => '', __('Uncategorized') => 'null'); + $categories = $C2->getCategories(); + while($categories->fetch()) { + $cat_title = html::escapeHTML($categories->cat_title); + $categories_combo[$cat_title] = $categories->cat_id; + } - $sortby_combo = array( - __('Update date') => 'link_upddt', - __('My rating') => 'link_note', - __('Title') => 'link_title', - __('Random') => 'RANDOM', - __('Number of views') => 'COUNTER' - ); - $order_combo = array( - __('Ascending') => 'asc', - __('Descending') => 'desc' - ); + $sortby_combo = array( + __('Update date') => 'link_upddt', + __('My rating') => 'link_note', + __('Title') => 'link_title', + __('Random') => 'RANDOM', + __('Number of views') => 'COUNTER' + ); + $order_combo = array( + __('Ascending') => 'asc', + __('Descending') => 'desc' + ); - $w->create( - 'cinecturlink2links', - __('My cinecturlink'), - array('cinecturlink2Widget', 'publicLinks'), - 'null', - __('Show selection of cinecturlinks') - ); - $w->cinecturlink2links->setting( - 'title', - __('Title:'), - __('My cinecturlink'), - 'text' - ); - $w->cinecturlink2links->setting( - 'category', - __('Category:'), - '', - 'combo', - $categories_combo - ); - $w->cinecturlink2links->setting( - 'sortby', - __('Order by:'), - 'link_upddt', - 'combo', - $sortby_combo - ); - $w->cinecturlink2links->setting( - 'sort', - __('Sort: (only for date, note and title)'), - 'desc', - 'combo', - $order_combo - ); - $w->cinecturlink2links->setting( - 'limit', - __('Limit:'), - 10, - 'text' - ); - $w->cinecturlink2links->setting( - 'withlink', - __('Enable link'), - 1, - 'check' - ); - $w->cinecturlink2links->setting( - 'showauthor', - __('Show author'), - 1, - 'check' - ); - $w->cinecturlink2links->setting( - 'shownote', - __('Show my rating'), - 0, - 'check' - ); - $w->cinecturlink2links->setting( - 'showdesc', - __('Show description'), - 0, - 'check' - ); - $w->cinecturlink2links->setting( - 'showpagelink', - __('Show a link to cinecturlink page'), - 0, - 'check' - ); - $w->cinecturlink2links->setting( - 'homeonly', - __('Display on:'), - 1, - 'combo', - array( - __('All pages') => 0, - __('Home page only') => 1, - __('Except on home page') => 2 - ) - ); - } + $w->create( + 'cinecturlink2links', + __('My cinecturlink'), + array('cinecturlink2Widget', 'publicLinks'), + 'null', + __('Show selection of cinecturlinks') + ); + $w->cinecturlink2links->setting( + 'title', + __('Title:'), + __('My cinecturlink'), + 'text' + ); + $w->cinecturlink2links->setting( + 'category', + __('Category:'), + '', + 'combo', + $categories_combo + ); + $w->cinecturlink2links->setting( + 'sortby', + __('Order by:'), + 'link_upddt', + 'combo', + $sortby_combo + ); + $w->cinecturlink2links->setting( + 'sort', + __('Sort: (only for date, note and title)'), + 'desc', + 'combo', + $order_combo + ); + $w->cinecturlink2links->setting( + 'limit', + __('Limit:'), + 10, + 'text' + ); + $w->cinecturlink2links->setting( + 'withlink', + __('Enable link'), + 1, + 'check' + ); + $w->cinecturlink2links->setting( + 'showauthor', + __('Show author'), + 1, + 'check' + ); + $w->cinecturlink2links->setting( + 'shownote', + __('Show my rating'), + 0, + 'check' + ); + $w->cinecturlink2links->setting( + 'showdesc', + __('Show description'), + 0, + 'check' + ); + $w->cinecturlink2links->setting( + 'showpagelink', + __('Show a link to cinecturlink page'), + 0, + 'check' + ); + $w->cinecturlink2links->setting( + 'homeonly', + __('Display on:'), + 1, + 'combo', + array( + __('All pages') => 0, + __('Home page only') => 1, + __('Except on home page') => 2 + ) + ); + } - public static function adminCats($w) - { - $w->create( - 'cinecturlink2cats', - __('List of categories of cinecturlink'), - array('cinecturlink2Widget', 'publicCats'), - null, - __('List of categories of cinecturlink') - ); - $w->cinecturlink2cats->setting( - 'title', - __('Title:'), - __('My cinecturlink by categories'), - 'text' - ); - $w->cinecturlink2cats->setting( - 'shownumlink', - __('Show number of links'), - 0, - 'check' - ); - $w->cinecturlink2cats->setting( - 'homeonly', - __('Display on:'), - 1, - 'combo', - array( - __('All pages') => 0, - __('Home page only') => 1, - __('Except on home page') => 2 - ) - ); - } + public static function adminCats($w) + { + $w->create( + 'cinecturlink2cats', + __('List of categories of cinecturlink'), + array('cinecturlink2Widget', 'publicCats'), + null, + __('List of categories of cinecturlink') + ); + $w->cinecturlink2cats->setting( + 'title', + __('Title:'), + __('My cinecturlink by categories'), + 'text' + ); + $w->cinecturlink2cats->setting( + 'shownumlink', + __('Show number of links'), + 0, + 'check' + ); + $w->cinecturlink2cats->setting( + 'homeonly', + __('Display on:'), + 1, + 'combo', + array( + __('All pages') => 0, + __('Home page only') => 1, + __('Except on home page') => 2 + ) + ); + } - public static function publicLinks($w) - { - global $core; + public static function publicLinks($w) + { + global $core; - $core->blog->settings->addNamespace('cinecturlink2'); + $core->blog->settings->addNamespace('cinecturlink2'); - if (!$core->blog->settings->cinecturlink2->cinecturlink2_active - || $w->homeonly == 1 && $core->url->type != 'default' - || $w->homeonly == 2 && $core->url->type == 'default' - ) { - return null; - } + if (!$core->blog->settings->cinecturlink2->cinecturlink2_active + || $w->homeonly == 1 && $core->url->type != 'default' + || $w->homeonly == 2 && $core->url->type == 'default' + ) { + return null; + } - $C2 = new cinecturlink2($core); + $C2 = new cinecturlink2($core); - if ($w->category) { - if ($w->category == 'null') { - $params['sql'] = ' AND L.cat_id IS NULL '; - } - elseif (is_numeric($w->category)) { - $params['cat_id'] = (integer) $w->category; - } - } + if ($w->category) { + if ($w->category == 'null') { + $params['sql'] = ' AND L.cat_id IS NULL '; + } + elseif (is_numeric($w->category)) { + $params['cat_id'] = (integer) $w->category; + } + } - $limit = abs((integer) $w->limit); + $limit = abs((integer) $w->limit); - # Tirage aléatoire - # Consomme beaucoup de ressources! - if ($w->sortby == 'RANDOM') { - $big_rs = $C2->getLinks($params); + # Tirage aléatoire + # Consomme beaucoup de ressources! + if ($w->sortby == 'RANDOM') { + $big_rs = $C2->getLinks($params); - if ($big_rs->isEmpty()) { + if ($big_rs->isEmpty()) { - return null; - } + return null; + } - $ids= array(); - while($big_rs->fetch()) { - $ids[] = $big_rs->link_id; - } - shuffle($ids); - $ids = array_slice($ids, 0, $limit); + $ids= array(); + while($big_rs->fetch()) { + $ids[] = $big_rs->link_id; + } + shuffle($ids); + $ids = array_slice($ids, 0, $limit); - $params['link_id'] = array(); - foreach($ids as $id) { - $params['link_id'][] = $id; - } - } - elseif ($w->sortby == 'COUNTER') { - $params['order'] = 'link_count asc'; - $params['limit'] = $limit; - } - else { - $params['order'] = $w->sortby; - $params['order'] .= $w->sort == 'asc' ? ' asc' : ' desc'; - $params['limit'] = $limit; - } + $params['link_id'] = array(); + foreach($ids as $id) { + $params['link_id'][] = $id; + } + } + elseif ($w->sortby == 'COUNTER') { + $params['order'] = 'link_count asc'; + $params['limit'] = $limit; + } + else { + $params['order'] = $w->sortby; + $params['order'] .= $w->sort == 'asc' ? ' asc' : ' desc'; + $params['limit'] = $limit; + } - $rs = $C2->getLinks($params); + $rs = $C2->getLinks($params); - if ($rs->isEmpty()) { + if ($rs->isEmpty()) { - return null; - } + return null; + } - $widthmax = (integer) $core->blog->settings->cinecturlink2->cinecturlink2_widthmax; - $style = $widthmax ? ' style="width:'.$widthmax.'px;"' : ''; + $widthmax = (integer) $core->blog->settings->cinecturlink2->cinecturlink2_widthmax; + $style = $widthmax ? ' style="width:'.$widthmax.'px;"' : ''; - $entries = array(); - while($rs->fetch()) { - $url = $rs->link_url; - $img = $rs->link_img; - $title = html::escapeHTML($rs->link_title); - $author = html::escapeHTML($rs->link_author); - $cat = html::escapeHTML($rs->cat_title); - $note = $w->shownote ? ' ('.$rs->link_note.'/20)' : ''; - $desc = $w->showdesc ? '
'.html::escapeHTML($rs->link_desc).'' : ''; - $lang = $rs->link_lang ? ' hreflang="'.$rs->link_lang.'"' : ''; - $count = abs((integer) $rs->link_count); + $entries = array(); + while($rs->fetch()) { + $url = $rs->link_url; + $img = $rs->link_img; + $title = html::escapeHTML($rs->link_title); + $author = html::escapeHTML($rs->link_author); + $cat = html::escapeHTML($rs->cat_title); + $note = $w->shownote ? ' ('.$rs->link_note.'/20)' : ''; + $desc = $w->showdesc ? '
'.html::escapeHTML($rs->link_desc).'' : ''; + $lang = $rs->link_lang ? ' hreflang="'.$rs->link_lang.'"' : ''; + $count = abs((integer) $rs->link_count); - # --BEHAVIOR-- cinecturlink2WidgetLinks - $bhv = $core->callBehavior('cinecturlink2WidgetLinks', $rs->link_id); + # --BEHAVIOR-- cinecturlink2WidgetLinks + $bhv = $core->callBehavior('cinecturlink2WidgetLinks', $rs->link_id); - $entries[] = - '

'. - ($w->withlink && !empty($url) ? '' : ''). - ''.$title.''.$note.'
'. - ($w->showauthor ? $author.'
' : '').'
'. - ''.$title.' - '.$author.''. - $desc. - ($w->withlink && !empty($url) ? '
' : ''). - '

'.$bhv; + $entries[] = + '

'. + ($w->withlink && !empty($url) ? '' : ''). + ''.$title.''.$note.'
'. + ($w->showauthor ? $author.'
' : '').'
'. + ''.$title.' - '.$author.''. + $desc. + ($w->withlink && !empty($url) ? '
' : ''). + '

'.$bhv; - try { - $cur = $core->con->openCursor($C2->table); - $cur->link_count = ($count + 1); - $C2->updLink($rs->link_id, $cur, false); - } - catch (Exception $e) { + try { + $cur = $core->con->openCursor($C2->table); + $cur->link_count = ($count + 1); + $C2->updLink($rs->link_id, $cur, false); + } + catch (Exception $e) { - } - } - # Tirage aléatoire - if ($w->sortby == 'RANDOM' - || $w->sortby == 'COUNTER' - ) { - shuffle($entries); - if ($core->blog->settings->cinecturlink2->cinecturlink2_triggeronrandom) { - $core->blog->triggerBlog(); - } - } + } + } + # Tirage aléatoire + if ($w->sortby == 'RANDOM' + || $w->sortby == 'COUNTER' + ) { + shuffle($entries); + if ($core->blog->settings->cinecturlink2->cinecturlink2_triggeronrandom) { + $core->blog->triggerBlog(); + } + } - return - '
'. - ($w->title ? '

'.html::escapeHTML($w->title).'

' : ''). - implode(' ',$entries). - ($w->showpagelink && $core->blog->settings->cinecturlink2->cinecturlink2_public_active ? - '

'.__('More links').'

' : '' - ). - '
'; - } + return + '
'. + ($w->title ? '

'.html::escapeHTML($w->title).'

' : ''). + implode(' ',$entries). + ($w->showpagelink && $core->blog->settings->cinecturlink2->cinecturlink2_public_active ? + '

'.__('More links').'

' : '' + ). + '
'; + } - public static function publicCats($w) - { - global $core; + public static function publicCats($w) + { + global $core; - $core->blog->settings->addNamespace('cinecturlink2'); + $core->blog->settings->addNamespace('cinecturlink2'); - if (!$core->blog->settings->cinecturlink2->cinecturlink2_active - || !$core->blog->settings->cinecturlink2->cinecturlink2_public_active - || $w->homeonly == 1 && $core->url->type != 'default' - || $w->homeonly == 2 && $core->url->type == 'default' - ) { - return null; - } + if (!$core->blog->settings->cinecturlink2->cinecturlink2_active + || !$core->blog->settings->cinecturlink2->cinecturlink2_public_active + || $w->homeonly == 1 && $core->url->type != 'default' + || $w->homeonly == 2 && $core->url->type == 'default' + ) { + return null; + } - $C2 = new cinecturlink2($core); + $C2 = new cinecturlink2($core); - $rs = $C2->getCategories(array()); + $rs = $C2->getCategories(array()); - if ($rs->isEmpty()) { + if ($rs->isEmpty()) { - return null; - } + return null; + } - $res = - '
  • '.__('all links'). - ''; - if ($w->shownumlink) { - $res .= ' ('.($C2->getLinks(array(), true)->f(0)).')'; - } - $res .= '
  • '; + $res = + '
  • '.__('all links'). + ''; + if ($w->shownumlink) { + $res .= ' ('.($C2->getLinks(array(), true)->f(0)).')'; + } + $res .= '
  • '; - while($rs->fetch()) { - $res .= - '
  • '. - html::escapeHTML($rs->cat_title). - ''; - if ($w->shownumlink) { - $res .= ' ('.($C2->getLinks(array('cat_id'=>$rs->cat_id), true)->f(0)).')'; - } - $res .= '
  • '; - } + while($rs->fetch()) { + $res .= + '
  • '. + html::escapeHTML($rs->cat_title). + ''; + if ($w->shownumlink) { + $res .= ' ('.($C2->getLinks(array('cat_id'=>$rs->cat_id), true)->f(0)).')'; + } + $res .= '
  • '; + } - return - '
    '. - ($w->title ? '

    '.html::escapeHTML($w->title).'

    ' : ''). - ''. - '
    '; - } -} + return + '
    '. + ($w->title ? '

    '.html::escapeHTML($w->title).'

    ' : ''). + ''. + '
    '; + } +} \ No newline at end of file diff --git a/dcstore.xml b/dcstore.xml new file mode 100644 index 0000000..efb4956 --- /dev/null +++ b/dcstore.xml @@ -0,0 +1,12 @@ + + +Cinecturlink 2 +0.7.1 +Jean-Christian Denis and Contributors +Widgets and pages about books, musics, films, blogs you are interested in +https://github.com/JcDenis/cinecturlink2/releases/download/v0.7.1/plugin-cinecturlink2.zip +2.19 +https://plugins.dotaddict.org/dc2/details/cinecturlink2 +https://github.com/JcDenis/cinecturlink2 + + \ No newline at end of file diff --git a/default-templates/cinecturlink2-atom.xml b/default-templates/cinecturlink2-atom.xml index 86b663b..3ff60a7 100644 --- a/default-templates/cinecturlink2-atom.xml +++ b/default-templates/cinecturlink2-atom.xml @@ -3,7 +3,7 @@ xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xml:lang="{{tpl:BlogLanguage}}"> - + {{tpl:BlogName encode_xml="1"}} - {{tpl:c2PageTitle encode_xml="1"}} {{tpl:c2PageDescription encode_xml="1"}} @@ -14,7 +14,7 @@ {{tpl:c2PageFeedID}} Dotclear - + diff --git a/default-templates/cinecturlink2-rss2.xml b/default-templates/cinecturlink2-rss2.xml index f12fd3e..53e9ebd 100644 --- a/default-templates/cinecturlink2-rss2.xml +++ b/default-templates/cinecturlink2-rss2.xml @@ -15,9 +15,9 @@ {{tpl:BlogCopyrightNotice encode_xml="1"}} http://blogs.law.harvard.edu/tech/rss Dotclear - + - + {{tpl:c2EntryTitle encode_xml="1"}} {{tpl:c2EntryURL encode_xml="1"}} @@ -31,6 +31,6 @@ - + \ No newline at end of file diff --git a/inc/class.cinecturlink2.php b/inc/class.cinecturlink2.php index 4315de9..44a4ec7 100644 --- a/inc/class.cinecturlink2.php +++ b/inc/class.cinecturlink2.php @@ -1,20 +1,19 @@ blog->settings->addNamespace('cinecturlink2'); + /** + * Contructor + * + * @param dcCore $core dcCore instance + */ + public function __construct(dcCore $core) + { + $core->blog->settings->addNamespace('cinecturlink2'); - $this->core = $core; - $this->con = $core->con; - $this->table = $core->prefix.'cinecturlink2'; - $this->blog = $core->con->escape($core->blog->id); - } + $this->core = $core; + $this->con = $core->con; + $this->table = $core->prefix.'cinecturlink2'; + $this->blog = $core->con->escape($core->blog->id); + } - /** - * Get links - * - * @param array $params Query params - * @param boolean $count_only Count only result - * @return record record instance - */ - public function getLinks($params=array(), $count_only=false) - { - if ($count_only) { - $strReq = 'SELECT count(L.link_id) '; - } - else { - $content_req = ''; - if (!empty($params['columns']) && is_array($params['columns'])) { - $content_req .= implode(', ', $params['columns']).', '; - } + /** + * Get links + * + * @param array $params Query params + * @param boolean $count_only Count only result + * @return record record instance + */ + public function getLinks($params=array(), $count_only=false) + { + if ($count_only) { + $strReq = 'SELECT count(L.link_id) '; + } + else { + $content_req = ''; + if (!empty($params['columns']) && is_array($params['columns'])) { + $content_req .= implode(', ', $params['columns']).', '; + } - $strReq = - 'SELECT L.link_id, L.blog_id, L.cat_id, L.user_id, L.link_type, '. - $content_req. - 'L.link_creadt, L.link_upddt, L.link_note, L.link_count, '. - 'L.link_title, L.link_desc, L.link_author, '. - 'L.link_lang, L.link_url, L.link_img, '. - 'U.user_name, U.user_firstname, U.user_displayname, U.user_email, '. - 'U.user_url, '. - 'C.cat_title, C.cat_desc '; - } + $strReq = + 'SELECT L.link_id, L.blog_id, L.cat_id, L.user_id, L.link_type, '. + $content_req. + 'L.link_creadt, L.link_upddt, L.link_note, L.link_count, '. + 'L.link_title, L.link_desc, L.link_author, '. + 'L.link_lang, L.link_url, L.link_img, '. + 'U.user_name, U.user_firstname, U.user_displayname, U.user_email, '. + 'U.user_url, '. + 'C.cat_title, C.cat_desc '; + } - $strReq .= - 'FROM '.$this->table.' L '. - 'INNER JOIN '.$this->core->prefix.'user U ON U.user_id = L.user_id '. - 'LEFT OUTER JOIN '.$this->table.'_cat C ON L.cat_id = C.cat_id '; + $strReq .= + 'FROM '.$this->table.' L '. + 'INNER JOIN '.$this->core->prefix.'user U ON U.user_id = L.user_id '. + 'LEFT OUTER JOIN '.$this->table.'_cat C ON L.cat_id = C.cat_id '; - if (!empty($params['from'])) { - $strReq .= $params['from'].' '; - } + if (!empty($params['from'])) { + $strReq .= $params['from'].' '; + } - $strReq .= "WHERE L.blog_id = '".$this->blog."' "; + $strReq .= "WHERE L.blog_id = '".$this->blog."' "; - if (isset($params['link_type'])) { - if (is_array($params['link_type']) && !empty($params['link_type'])) { - $strReq .= 'AND L.link_type '.$this->con->in($params['link_type']); - } - elseif ($params['link_type'] != '') { - $strReq .= "AND L.link_type = '".$this->con->escape($params['link_type'])."' "; - } - } - else { - $strReq .= "AND L.link_type = 'cinecturlink' "; - } + if (isset($params['link_type'])) { + if (is_array($params['link_type']) && !empty($params['link_type'])) { + $strReq .= 'AND L.link_type '.$this->con->in($params['link_type']); + } + elseif ($params['link_type'] != '') { + $strReq .= "AND L.link_type = '".$this->con->escape($params['link_type'])."' "; + } + } + else { + $strReq .= "AND L.link_type = 'cinecturlink' "; + } - if (!empty($params['link_id'])) { - if (is_array($params['link_id'])) { - array_walk($params['link_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}')); - } - else { - $params['link_id'] = array((integer) $params['link_id']); - } - $strReq .= 'AND L.link_id '.$this->con->in($params['link_id']); - } - - if (!empty($params['cat_id'])) { - if (is_array($params['cat_id'])) { - array_walk($params['cat_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}')); - } - else { - $params['cat_id'] = array((integer) $params['cat_id']); - } - $strReq .= 'AND L.cat_id '.$this->con->in($params['cat_id']); - } - if (!empty($params['cat_title'])) { - $strReq .= "AND C.cat_title = '".$this->con->escape($params['cat_title'])."' "; - } + if (!empty($params['link_id'])) { + if (is_array($params['link_id'])) { + array_walk($params['link_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}')); + } + else { + $params['link_id'] = array((integer) $params['link_id']); + } + $strReq .= 'AND L.link_id '.$this->con->in($params['link_id']); + } - if (!empty($params['link_title'])) { - $strReq .= "AND L.link_title = '".$this->con->escape($params['link_title'])."' "; - } + if (!empty($params['cat_id'])) { + if (is_array($params['cat_id'])) { + array_walk($params['cat_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}')); + } + else { + $params['cat_id'] = array((integer) $params['cat_id']); + } + $strReq .= 'AND L.cat_id '.$this->con->in($params['cat_id']); + } + if (!empty($params['cat_title'])) { + $strReq .= "AND C.cat_title = '".$this->con->escape($params['cat_title'])."' "; + } - if (!empty($params['link_lang'])) { - $strReq .= "AND L.link_lang = '".$this->con->escape($params['link_lang'])."' "; - } + if (!empty($params['link_title'])) { + $strReq .= "AND L.link_title = '".$this->con->escape($params['link_title'])."' "; + } - if (!empty($params['sql'])) { - $strReq .= $params['sql'].' '; - } + if (!empty($params['link_lang'])) { + $strReq .= "AND L.link_lang = '".$this->con->escape($params['link_lang'])."' "; + } - if (!$count_only) { - if (!empty($params['order'])) { - $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; - } - else { - $strReq .= 'ORDER BY L.link_upddt DESC '; - } - } + if (!empty($params['sql'])) { + $strReq .= $params['sql'].' '; + } - if (!$count_only && !empty($params['limit'])) { - $strReq .= $this->con->limit($params['limit']); - } + if (!$count_only) { + if (!empty($params['order'])) { + $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; + } + else { + $strReq .= 'ORDER BY L.link_upddt DESC '; + } + } - return $this->con->select($strReq); - } + if (!$count_only && !empty($params['limit'])) { + $strReq .= $this->con->limit($params['limit']); + } - /** - * Add link - * - * @param cursor $cur cursor instance - */ - public function addLink(cursor $cur) - { - $this->con->writeLock($this->table); - - try { - if ($cur->link_title == '') { - throw new Exception(__('No link title')); - } - if ($cur->link_desc == '') { - throw new Exception(__('No link description')); - } - if ('' == $cur->link_note) { - $cur->link_note = 10; - } - if (0 > $cur->link_note || $cur->link_note > 20) { - $cur->link_note = 10; - } + return $this->con->select($strReq); + } - $cur->link_id = $this->getNextLinkId(); - $cur->blog_id = $this->blog; - $cur->user_id = $this->core->auth->userID(); - $cur->link_creadt = date('Y-m-d H:i:s'); - $cur->link_upddt = date('Y-m-d H:i:s'); - $cur->link_pos = 0; - $cur->link_count = 0; - $cur->insert(); - $this->con->unlock(); - } - catch (Exception $e) { - $this->con->unlock(); - throw $e; - } - $this->trigger(); + /** + * Add link + * + * @param cursor $cur cursor instance + */ + public function addLink(cursor $cur) + { + $this->con->writeLock($this->table); - # --BEHAVIOR-- cinecturlink2AfterAddLink - $this->core->callBehavior('cinecturlink2AfterAddLink', $cur); + try { + if ($cur->link_title == '') { + throw new Exception(__('No link title')); + } + if ($cur->link_desc == '') { + throw new Exception(__('No link description')); + } + if ('' == $cur->link_note) { + $cur->link_note = 10; + } + if (0 > $cur->link_note || $cur->link_note > 20) { + $cur->link_note = 10; + } - return $cur->link_id; - } + $cur->link_id = $this->getNextLinkId(); + $cur->blog_id = $this->blog; + $cur->user_id = $this->core->auth->userID(); + $cur->link_creadt = date('Y-m-d H:i:s'); + $cur->link_upddt = date('Y-m-d H:i:s'); + $cur->link_pos = 0; + $cur->link_count = 0; + $cur->insert(); + $this->con->unlock(); + } + catch (Exception $e) { + $this->con->unlock(); + throw $e; + } + $this->trigger(); - /** - * Update link - * - * @param integer $id Link ID - * @param cursor $cur cursor instance - * @param boolean $behavior Call related behaviors - */ - public function updLink($id, cursor $cur, $behavior=true) - { - $id = (integer) $id; - - if (empty($id)) { - throw new Exception(__('No such link ID')); - } + # --BEHAVIOR-- cinecturlink2AfterAddLink + $this->core->callBehavior('cinecturlink2AfterAddLink', $cur); - $cur->link_upddt = date('Y-m-d H:i:s'); + return $cur->link_id; + } - $cur->update("WHERE link_id = ".$id." AND blog_id = '".$this->blog."' "); - $this->trigger(); + /** + * Update link + * + * @param integer $id Link ID + * @param cursor $cur cursor instance + * @param boolean $behavior Call related behaviors + */ + public function updLink($id, cursor $cur, $behavior=true) + { + $id = (integer) $id; - if ($behavior) { - # --BEHAVIOR-- cinecturlink2AfterUpdLink - $this->core->callBehavior('cinecturlink2AfterUpdLink', $cur, $id); - } - } + if (empty($id)) { + throw new Exception(__('No such link ID')); + } - /** - * Delete link - * - * @param integer $id Link ID - */ - public function delLink($id) - { - $id = (integer) $id; - - if (empty($id)) { - throw new Exception(__('No such link ID')); - } + $cur->link_upddt = date('Y-m-d H:i:s'); - # --BEHAVIOR-- cinecturlink2BeforeDelLink - $this->core->callBehavior('cinecturlink2BeforeDelLink', $id); + $cur->update("WHERE link_id = ".$id." AND blog_id = '".$this->blog."' "); + $this->trigger(); - $this->con->execute( - 'DELETE FROM '.$this->table.' '. - 'WHERE link_id = '.$id.' '. - "AND blog_id = '".$this->blog."' " - ); + if ($behavior) { + # --BEHAVIOR-- cinecturlink2AfterUpdLink + $this->core->callBehavior('cinecturlink2AfterUpdLink', $cur, $id); + } + } - $this->trigger(); - } + /** + * Delete link + * + * @param integer $id Link ID + */ + public function delLink($id) + { + $id = (integer) $id; - /** - * Get next link ID - * - * @return integer Next link ID - */ - private function getNextLinkId() - { - return $this->con->select( - 'SELECT MAX(link_id) FROM '.$this->table.' ' - )->f(0) + 1; - } + if (empty($id)) { + throw new Exception(__('No such link ID')); + } - /** - * Get categories - * - * @param array $params Query params - * @param boolean $count_only Count only result - * @return record record instance - */ - public function getCategories($params=array(), $count_only=false) - { - if ($count_only) { - $strReq = 'SELECT count(C.cat_id) '; - } - else { - $content_req = ''; - if (!empty($params['columns']) && is_array($params['columns'])) { - $content_req .= implode(', ', $params['columns']).', '; - } + # --BEHAVIOR-- cinecturlink2BeforeDelLink + $this->core->callBehavior('cinecturlink2BeforeDelLink', $id); - $strReq = - 'SELECT C.cat_id, C.blog_id, C.cat_title, C.cat_desc, '. - $content_req. - 'C.cat_pos, C.cat_creadt, C.cat_upddt '; - } + $this->con->execute( + 'DELETE FROM '.$this->table.' '. + 'WHERE link_id = '.$id.' '. + "AND blog_id = '".$this->blog."' " + ); - $strReq .= 'FROM '.$this->table.'_cat C '; + $this->trigger(); + } - if (!empty($params['from'])) { - $strReq .= $params['from'].' '; - } + /** + * Get next link ID + * + * @return integer Next link ID + */ + private function getNextLinkId() + { + return $this->con->select( + 'SELECT MAX(link_id) FROM '.$this->table.' ' + )->f(0) + 1; + } - $strReq .= "WHERE C.blog_id = '".$this->blog."' "; + /** + * Get categories + * + * @param array $params Query params + * @param boolean $count_only Count only result + * @return record record instance + */ + public function getCategories($params=array(), $count_only=false) + { + if ($count_only) { + $strReq = 'SELECT count(C.cat_id) '; + } + else { + $content_req = ''; + if (!empty($params['columns']) && is_array($params['columns'])) { + $content_req .= implode(', ', $params['columns']).', '; + } - if (!empty($params['cat_id'])) { - if (is_array($params['cat_id'])) { - array_walk($params['cat_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}')); - } - else { - $params['cat_id'] = array((integer) $params['cat_id']); - } - $strReq .= 'AND C.cat_id '.$this->con->in($params['cat_id']); - } + $strReq = + 'SELECT C.cat_id, C.blog_id, C.cat_title, C.cat_desc, '. + $content_req. + 'C.cat_pos, C.cat_creadt, C.cat_upddt '; + } - if (!empty($params['cat_title'])) { - $strReq .= "AND C.cat_title = '".$this->con->escape($params['cat_title'])."' "; - } + $strReq .= 'FROM '.$this->table.'_cat C '; - if (!empty($params['sql'])) { - $strReq .= $params['sql'].' '; - } + if (!empty($params['from'])) { + $strReq .= $params['from'].' '; + } - if (!$count_only) { - if (!empty($params['order'])) { - $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; - } - else { - $strReq .= 'ORDER BY cat_pos ASC '; - } - } + $strReq .= "WHERE C.blog_id = '".$this->blog."' "; - if (!$count_only && !empty($params['limit'])) { - $strReq .= $this->con->limit($params['limit']); - } + if (!empty($params['cat_id'])) { + if (is_array($params['cat_id'])) { + array_walk($params['cat_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}')); + } + else { + $params['cat_id'] = array((integer) $params['cat_id']); + } + $strReq .= 'AND C.cat_id '.$this->con->in($params['cat_id']); + } - return $this->con->select($strReq); - } + if (!empty($params['cat_title'])) { + $strReq .= "AND C.cat_title = '".$this->con->escape($params['cat_title'])."' "; + } - /** - * Add category - * - * @param cursor $cur cursor instance - * @return integer New category ID - */ - public function addCategory(cursor $cur) - { - $this->con->writeLock($this->table.'_cat'); - - try { - if ($cur->cat_title == '') { - throw new Exception(__('No category title')); - } - if ($cur->cat_desc == '') { - throw new Exception(__('No category description')); - } + if (!empty($params['sql'])) { + $strReq .= $params['sql'].' '; + } - $cur->cat_id = $this->getNextCatId(); - $cur->cat_pos = $this->getNextCatPos(); - $cur->blog_id = $this->blog; - $cur->cat_creadt = date('Y-m-d H:i:s'); - $cur->cat_upddt = date('Y-m-d H:i:s'); - $cur->insert(); - $this->con->unlock(); - } - catch (Exception $e) { - $this->con->unlock(); - throw $e; - } - $this->trigger(); + if (!$count_only) { + if (!empty($params['order'])) { + $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; + } + else { + $strReq .= 'ORDER BY cat_pos ASC '; + } + } - return $cur->cat_id; - } + if (!$count_only && !empty($params['limit'])) { + $strReq .= $this->con->limit($params['limit']); + } - /** - * Update category - * - * @param integer $id Category ID - * @param cursor $cur cursor instance - */ - public function updCategory($id, cursor $cur) - { - $id = (integer) $id; - - if (empty($id)) { - throw new Exception(__('No such category ID')); - } + return $this->con->select($strReq); + } - $cur->cat_upddt = date('Y-m-d H:i:s'); + /** + * Add category + * + * @param cursor $cur cursor instance + * @return integer New category ID + */ + public function addCategory(cursor $cur) + { + $this->con->writeLock($this->table.'_cat'); - $cur->update("WHERE cat_id = ".$id." AND blog_id = '".$this->blog."' "); - $this->trigger(); - } + try { + if ($cur->cat_title == '') { + throw new Exception(__('No category title')); + } + if ($cur->cat_desc == '') { + throw new Exception(__('No category description')); + } - /** - * Delete category - * - * @param integer $id Category ID - */ - public function delCategory($id) - { - $id = (integer) $id; - - if (empty($id)) { - throw new Exception(__('No such category ID')); - } + $cur->cat_id = $this->getNextCatId(); + $cur->cat_pos = $this->getNextCatPos(); + $cur->blog_id = $this->blog; + $cur->cat_creadt = date('Y-m-d H:i:s'); + $cur->cat_upddt = date('Y-m-d H:i:s'); + $cur->insert(); + $this->con->unlock(); + } + catch (Exception $e) { + $this->con->unlock(); + throw $e; + } + $this->trigger(); - $this->con->execute( - 'DELETE FROM '.$this->table.'_cat '. - 'WHERE cat_id = '.$id.' '. - "AND blog_id = '".$this->blog."' " - ); + return $cur->cat_id; + } - # Update link cat to NULL - $cur = $this->con->openCursor($this->table); - $cur->cat_id = NULL; - $cur->link_upddt = date('Y-m-d H:i:s'); - $cur->update("WHERE cat_id = ".$id." AND blog_id = '".$this->blog."' "); + /** + * Update category + * + * @param integer $id Category ID + * @param cursor $cur cursor instance + */ + public function updCategory($id, cursor $cur) + { + $id = (integer) $id; - $this->trigger(); - } + if (empty($id)) { + throw new Exception(__('No such category ID')); + } - /** - * Get next category ID - * - * @return integer Next category ID - */ - private function getNextCatId() - { - return $this->con->select( - 'SELECT MAX(cat_id) FROM '.$this->table.'_cat ' - )->f(0) + 1; - } + $cur->cat_upddt = date('Y-m-d H:i:s'); - /** - * Get next category position - * - * @return integer Next category position - */ - private function getNextCatPos() - { - return $this->con->select( - 'SELECT MAX(cat_pos) FROM '.$this->table.'_cat '. - "WHERE blog_id = '".$this->blog."' " - )->f(0) + 1; - } + $cur->update("WHERE cat_id = ".$id." AND blog_id = '".$this->blog."' "); + $this->trigger(); + } - /** - * Trigger event - */ - private function trigger() - { - $this->core->blog->triggerBlog(); - } + /** + * Delete category + * + * @param integer $id Category ID + */ + public function delCategory($id) + { + $id = (integer) $id; - /** - * Check if a directory exists and is writable - * - * @param string $root Root - * @param string $folder Folder to create into root folder - * @param boolean $throw Throw exception or not - * @return boolean True if exists and writable - */ - public static function test_folder($root, $folder, $throw=false) - { - if (!is_dir($root.'/'.$folder)) { - if (!is_dir($root) || !is_writable($root) || !mkdir($root.'/'.$folder)) { - if ($throw) { - throw new Exception(__('Failed to create public folder for images.')); - } + if (empty($id)) { + throw new Exception(__('No such category ID')); + } - return false; - } - } + $this->con->execute( + 'DELETE FROM '.$this->table.'_cat '. + 'WHERE cat_id = '.$id.' '. + "AND blog_id = '".$this->blog."' " + ); - return true; - } -} + # Update link cat to NULL + $cur = $this->con->openCursor($this->table); + $cur->cat_id = NULL; + $cur->link_upddt = date('Y-m-d H:i:s'); + $cur->update("WHERE cat_id = ".$id." AND blog_id = '".$this->blog."' "); + + $this->trigger(); + } + + /** + * Get next category ID + * + * @return integer Next category ID + */ + private function getNextCatId() + { + return $this->con->select( + 'SELECT MAX(cat_id) FROM '.$this->table.'_cat ' + )->f(0) + 1; + } + + /** + * Get next category position + * + * @return integer Next category position + */ + private function getNextCatPos() + { + return $this->con->select( + 'SELECT MAX(cat_pos) FROM '.$this->table.'_cat '. + "WHERE blog_id = '".$this->blog."' " + )->f(0) + 1; + } + + /** + * Trigger event + */ + private function trigger() + { + $this->core->blog->triggerBlog(); + } + + /** + * Check if a directory exists and is writable + * + * @param string $root Root + * @param string $folder Folder to create into root folder + * @param boolean $throw Throw exception or not + * @return boolean True if exists and writable + */ + public static function test_folder($root, $folder, $throw=false) + { + if (!is_dir($root.'/'.$folder)) { + if (!is_dir($root) || !is_writable($root) || !mkdir($root.'/'.$folder)) { + if ($throw) { + throw new Exception(__('Failed to create public folder for images.')); + } + + return false; + } + } + + return true; + } +} \ No newline at end of file diff --git a/inc/lib.cinecturlink2.context.php b/inc/lib.cinecturlink2.context.php index cbd9d65..84962b5 100644 --- a/inc/lib.cinecturlink2.context.php +++ b/inc/lib.cinecturlink2.context.php @@ -1,117 +1,116 @@ c2_pagination === null) { + if ($_ctx->c2_pagination === null) { - return false; - } + return false; + } - $nb_posts = $_ctx->c2_pagination->f(0); - $nb_per_page = $_ctx->c2_params['limit'][1]; + $nb_posts = $_ctx->c2_pagination->f(0); + $nb_per_page = $_ctx->c2_params['limit'][1]; - $nb_pages = ceil($nb_posts/$nb_per_page); + $nb_pages = ceil($nb_posts/$nb_per_page); - return $nb_pages; - } + return $nb_pages; + } - public static function PaginationPosition($offset=0) - { - if (isset($GLOBALS['c2_page_number'])) { - $p = $GLOBALS['c2_page_number']; - } - else { - $p = 1; - } + public static function PaginationPosition($offset=0) + { + if (isset($GLOBALS['c2_page_number'])) { + $p = $GLOBALS['c2_page_number']; + } + else { + $p = 1; + } - $p = $p+$offset; + $p = $p+$offset; - $n = self::PaginationNbPages(); - if (!$n) { + $n = self::PaginationNbPages(); + if (!$n) { - return $p; - } + return $p; + } - return $p > $n || $p <= 0 ? 1 : $p; - } + return $p > $n || $p <= 0 ? 1 : $p; + } - public static function PaginationStart() - { - if (isset($GLOBALS['c2_page_number'])) { + public static function PaginationStart() + { + if (isset($GLOBALS['c2_page_number'])) { - return self::PaginationPosition() == 1; - } + return self::PaginationPosition() == 1; + } - return true; - } - - public static function PaginationEnd() - { - if (isset($GLOBALS['c2_page_number'])) { + return true; + } - return self::PaginationPosition() == self::PaginationNbPages(); - } + public static function PaginationEnd() + { + if (isset($GLOBALS['c2_page_number'])) { - return false; - } - - public static function PaginationURL($offset=0) - { - $args = $_SERVER['URL_REQUEST_PART']; + return self::PaginationPosition() == self::PaginationNbPages(); + } - $n = self::PaginationPosition($offset); + return false; + } - $args = preg_replace('#(^|/)c2page/([0-9]+)$#', '', $args); + public static function PaginationURL($offset=0) + { + $args = $_SERVER['URL_REQUEST_PART']; - $url = $GLOBALS['core']->blog->url.$args; + $n = self::PaginationPosition($offset); - if ($n > 1) { - $url = preg_replace('#/$#','',$url); - $url .= '/c2page/'.$n; - } + $args = preg_replace('#(^|/)c2page/([0-9]+)$#', '', $args); - # If search param - if (!empty($_GET['q'])) { - $s = strpos($url,'?') !== false ? '&' : '?'; - $url .= $s.'q='.rawurlencode($_GET['q']); - } + $url = $GLOBALS['core']->blog->url.$args; - return $url; - } + if ($n > 1) { + $url = preg_replace('#/$#','',$url); + $url .= '/c2page/'.$n; + } - public static function categoryCurrent() - { - global $_ctx; + # If search param + if (!empty($_GET['q'])) { + $s = strpos($url,'?') !== false ? '&' : '?'; + $url .= $s.'q='.rawurlencode($_GET['q']); + } - if (!isset($_ctx->c2_page_params['cat_id']) && !isset($_ctx->c2_page_params['cat_title'])) { + return $url; + } - return false; - } - if (isset($_ctx->c2_page_params['cat_id']) && $_ctx->c2_page_params['cat_id'] == $_ctx->c2_categories->cat_id) { + public static function categoryCurrent() + { + global $_ctx; - return true; - } - if (isset($_ctx->c2_page_params['cat_title']) && $_ctx->c2_page_params['cat_title'] == $_ctx->c2_categories->cat_title) { + if (!isset($_ctx->c2_page_params['cat_id']) && !isset($_ctx->c2_page_params['cat_title'])) { - return true; - } + return false; + } + if (isset($_ctx->c2_page_params['cat_id']) && $_ctx->c2_page_params['cat_id'] == $_ctx->c2_categories->cat_id) { - return false; - } -} + return true; + } + if (isset($_ctx->c2_page_params['cat_title']) && $_ctx->c2_page_params['cat_title'] == $_ctx->c2_categories->cat_title) { + + return true; + } + + return false; + } +} \ No newline at end of file diff --git a/inc/lib.cinecturlink2.list.php b/inc/lib.cinecturlink2.list.php index bd3a818..193ecd3 100644 --- a/inc/lib.cinecturlink2.list.php +++ b/inc/lib.cinecturlink2.list.php @@ -1,102 +1,101 @@ rs->isEmpty()) { - echo '

    '.__('There is no link').'

    '; - } - else { - $pager = new pager($page, $this->rs_count, $nb_per_page,10); + public function display($page, $nb_per_page, $url) + { + if ($this->rs->isEmpty()) { + echo '

    '.__('There is no link').'

    '; + } + else { + $pager = new pager($page, $this->rs_count, $nb_per_page,10); - $pager->base_url = $url; + $pager->base_url = $url; - $html_block = - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - '%s'. - '
    '.__('Title').''.__('Author').''.__('Description').''.__('Links').''.__('Category').''.__('My rating').''.__('Date').'
    '; + $html_block = + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + '%s'. + '
    '.__('Title').''.__('Author').''.__('Description').''.__('Links').''.__('Category').''.__('My rating').''.__('Date').'
    '; - echo '

    '.__('Page(s)').' : '.$pager->getLinks().'

    '; - $blocks = explode('%s',$html_block); - echo $blocks[0]; + echo '

    '.__('Page(s)').' : '.$pager->getLinks().'

    '; + $blocks = explode('%s',$html_block); + echo $blocks[0]; - $this->rs->index(((integer)$page - 1) * $nb_per_page); - $iter = 0; - while ($iter < $nb_per_page) { - echo $this->linkLine($url,$iter); + $this->rs->index(((integer)$page - 1) * $nb_per_page); + $iter = 0; + while ($iter < $nb_per_page) { + echo $this->linkLine($url,$iter); - if ($this->rs->isEnd()) - break; - else - $this->rs->moveNext(); + if ($this->rs->isEnd()) + break; + else + $this->rs->moveNext(); - $iter++; - } - echo $blocks[1]; - echo '

    '.__('Page(s)').' : '.$pager->getLinks().'

    '; - } - } + $iter++; + } + echo $blocks[1]; + echo '

    '.__('Page(s)').' : '.$pager->getLinks().'

    '; + } + } - private function linkLine($url, $loop) - { - return - ''."\n". - ''. - form::checkbox(array('links[]'), $this->rs->link_id, 0). - ''. - ''. - ''. - html::escapeHTML($this->rs->link_title). - ''. - "\n". - ''. - html::escapeHTML($this->rs->link_author). - "\n". - ''. - html::escapeHTML($this->rs->link_desc). - "\n". - ''. - ''.__('URL').' '. - ''.__('image').' '. - "\n". - ''. - html::escapeHTML($this->rs->cat_title). - "\n". - ''. - html::escapeHTML($this->rs->link_note).'/20'. - "\n". - ''. - dt::dt2str($GLOBALS['core']->blog->settings->system->date_format.', '.$GLOBALS['core']->blog->settings->system->time_format,$this->rs->link_upddt,$GLOBALS['core']->auth->getInfo('user_tz')). - "\n". - ''."\n"; - } -} + private function linkLine($url, $loop) + { + return + ''."\n". + ''. + form::checkbox(array('links[]'), $this->rs->link_id, 0). + ''. + ''. + ''. + html::escapeHTML($this->rs->link_title). + ''. + "\n". + ''. + html::escapeHTML($this->rs->link_author). + "\n". + ''. + html::escapeHTML($this->rs->link_desc). + "\n". + ''. + ''.__('URL').' '. + ''.__('image').' '. + "\n". + ''. + html::escapeHTML($this->rs->cat_title). + "\n". + ''. + html::escapeHTML($this->rs->link_note).'/20'. + "\n". + ''. + dt::dt2str($GLOBALS['core']->blog->settings->system->date_format.', '.$GLOBALS['core']->blog->settings->system->time_format,$this->rs->link_upddt,$GLOBALS['core']->auth->getInfo('user_tz')). + "\n". + ''."\n"; + } +} \ No newline at end of file diff --git a/inc/lib.sitemaps.cinecturlink2.php b/inc/lib.sitemaps.cinecturlink2.php index 1262ccc..d6d9b23 100644 --- a/inc/lib.sitemaps.cinecturlink2.php +++ b/inc/lib.sitemaps.cinecturlink2.php @@ -1,44 +1,43 @@ offsetSet(__('Cinecturlink'), 'cinecturlink2'); - } + public static function sitemapsDefineParts($map_parts) + { + $map_parts->offsetSet(__('Cinecturlink'), 'cinecturlink2'); + } - public static function sitemapsURLsCollect($sitemaps) - { - global $core; - $core->blog->settings->addNamespace('sitemaps'); - - if ($core->plugins->moduleExists('cinecturlink2') - && $core->blog->settings->sitemaps->sitemaps_cinecturlink2_url) { + public static function sitemapsURLsCollect($sitemaps) + { + global $core; + $core->blog->settings->addNamespace('sitemaps'); - $freq = $sitemaps->getFrequency($core->blog->settings->sitemaps->sitemaps_cinecturlink2_fq); - $prio = $sitemaps->getPriority($core->blog->settings->sitemaps->sitemaps_cinecturlink2_pr); - $base = $core->blog->url.$core->url->getBase('cinecturlink2'); + if ($core->plugins->moduleExists('cinecturlink2') + && $core->blog->settings->sitemaps->sitemaps_cinecturlink2_url) { - $sitemaps->addEntry($base, $prio, $freq); - - $core->blog->settings->addNamespace('cinecturlink2'); - $C2 = new cinecturlink2($core); - $cats = $C2->getCategories(); - while ($cats->fetch()) { - $sitemaps->addEntry($base."/".$core->blog->settings->cinecturlink2->cinecturlink2_public_caturl.'/'.urlencode($cats->cat_title), $prio, $freq); - } - } - } -} + $freq = $sitemaps->getFrequency($core->blog->settings->sitemaps->sitemaps_cinecturlink2_fq); + $prio = $sitemaps->getPriority($core->blog->settings->sitemaps->sitemaps_cinecturlink2_pr); + $base = $core->blog->url.$core->url->getBase('cinecturlink2'); + + $sitemaps->addEntry($base, $prio, $freq); + + $core->blog->settings->addNamespace('cinecturlink2'); + $C2 = new cinecturlink2($core); + $cats = $C2->getCategories(); + while ($cats->fetch()) { + $sitemaps->addEntry($base."/".$core->blog->settings->cinecturlink2->cinecturlink2_public_caturl.'/'.urlencode($cats->cat_title), $prio, $freq); + } + } + } +} \ No newline at end of file diff --git a/index.php b/index.php index e823425..22b6e5f 100644 --- a/index.php +++ b/index.php @@ -1,20 +1,19 @@ auth->getInfo('user_lang'); -$new_image = isset($_POST['new_image']) ? $_POST['new_image'] : ''; -$new_note = isset($_POST['new_note']) ? $_POST['new_note'] : 10; -$new_cattitle = isset($_POST['new_cattitle']) ? $_POST['new_cattitle'] : ''; -$new_catdesc = isset($_POST['new_catdesc']) ? $_POST['new_catdesc'] : ''; -$action = isset($_POST['action']) ? $_POST['action'] : ''; +$upd_link_id = isset($_REQUEST['link_id']) ? $_REQUEST['link_id'] : null; +$new_title = isset($_POST['new_title']) ? $_POST['new_title'] : ''; +$new_desc = isset($_POST['new_desc']) ? $_POST['new_desc'] : ''; +$new_author = isset($_POST['new_author']) ? $_POST['new_author'] : ''; +$new_url = isset($_POST['new_url']) ? $_POST['new_url'] : ''; +$new_category = isset($_POST['new_category']) ? $_POST['new_category'] : ''; +$new_lang = isset($_POST['new_lang']) ? $_POST['new_lang'] : $core->auth->getInfo('user_lang'); +$new_image = isset($_POST['new_image']) ? $_POST['new_image'] : ''; +$new_note = isset($_POST['new_note']) ? $_POST['new_note'] : 10; +$new_cattitle = isset($_POST['new_cattitle']) ? $_POST['new_cattitle'] : ''; +$new_catdesc = isset($_POST['new_catdesc']) ? $_POST['new_catdesc'] : ''; +$action = isset($_POST['action']) ? $_POST['action'] : ''; # Actions try { - # Update categories - if ($action == 'update_categories') { + # Update categories + if ($action == 'update_categories') { - # Reorder categories - if (empty($_POST['cats_order']) - && !empty($_POST['catpos']) - ) { - $order = $_POST['catpos']; - asort($order); - $order = array_keys($order); - } - elseif (!empty($_POST['cats_order'])) { - $order = explode(',', $_POST['cats_order']); - } + # Reorder categories + if (empty($_POST['cats_order']) + && !empty($_POST['catpos']) + ) { + $order = $_POST['catpos']; + asort($order); + $order = array_keys($order); + } + elseif (!empty($_POST['cats_order'])) { + $order = explode(',', $_POST['cats_order']); + } - if (!empty($order)) { + if (!empty($order)) { - foreach ($order as $pos => $id) { + foreach ($order as $pos => $id) { - $pos = ((integer) $pos)+1; - if (empty($pos) || empty($id)) { - continue; - } + $pos = ((integer) $pos)+1; + if (empty($pos) || empty($id)) { + continue; + } - $cur = $core->con->openCursor($C2->table.'_cat'); - $cur->cat_pos = $pos; - $C2->updCategory($id, $cur); - } + $cur = $core->con->openCursor($C2->table.'_cat'); + $cur->cat_pos = $pos; + $C2->updCategory($id, $cur); + } - dcPage::addSuccessNotice( - __('Categories successfully reordered.') - ); - } + dcPage::addSuccessNotice( + __('Categories successfully reordered.') + ); + } - # Delete categories - if (!empty($_POST['delcat'])) { + # Delete categories + if (!empty($_POST['delcat'])) { - foreach($_POST['delcat'] as $cat_id) { - $C2->delCategory($cat_id); - } + foreach($_POST['delcat'] as $cat_id) { + $C2->delCategory($cat_id); + } - dcPage::addSuccessNotice( - __('Categories successfully deleted.') - ); - } + dcPage::addSuccessNotice( + __('Categories successfully deleted.') + ); + } - http::redirect(empty($_POST['redir']) ? - $p_url.'#cats' : $_POST['redir'] - ); - } + http::redirect(empty($_POST['redir']) ? + $p_url.'#cats' : $_POST['redir'] + ); + } - # Create new category - if ($action == 'create_category') { + # Create new category + if ($action == 'create_category') { - if (empty($new_cattitle)) { - throw new Exception(__('You must provide a title.')); - } + if (empty($new_cattitle)) { + throw new Exception(__('You must provide a title.')); + } - $exists = $C2->getCategories(array('cat_title' => $new_cattitle), true)->f(0); - if ($exists) { - throw new Exception(__('Category with same name already exists.')); - } + $exists = $C2->getCategories(array('cat_title' => $new_cattitle), true)->f(0); + if ($exists) { + throw new Exception(__('Category with same name already exists.')); + } - $cur = $core->con->openCursor($C2->table.'_cat'); - $cur->cat_title = $new_cattitle; - $cur->cat_desc = $new_catdesc; - - $C2->addCategory($cur); + $cur = $core->con->openCursor($C2->table.'_cat'); + $cur->cat_title = $new_cattitle; + $cur->cat_desc = $new_catdesc; - dcPage::addSuccessNotice( - __('Category successfully created.') - ); - http::redirect(empty($_POST['redir']) ? - $p_url.'#cats' : $_POST['redir'] - ); - } + $C2->addCategory($cur); - # Delete links - if (!empty($_POST['links']) && $action == 'delete_links') { + dcPage::addSuccessNotice( + __('Category successfully created.') + ); + http::redirect(empty($_POST['redir']) ? + $p_url.'#cats' : $_POST['redir'] + ); + } - foreach($_POST['links'] as $link_id) { - $C2->delLink($link_id); - } + # Delete links + if (!empty($_POST['links']) && $action == 'delete_links') { - dcPage::addSuccessNotice( - __('Links successfully deleted.') - ); - http::redirect(empty($_POST['redir']) ? - $p_url.'#links' : $_POST['redir'] - ); - } + foreach($_POST['links'] as $link_id) { + $C2->delLink($link_id); + } - # Move to right tab - if (!empty($_POST['links']) && $action == 'moveto_change_links_category') { - // Nothing to do: show links action page - } + dcPage::addSuccessNotice( + __('Links successfully deleted.') + ); + http::redirect(empty($_POST['redir']) ? + $p_url.'#links' : $_POST['redir'] + ); + } - # Update category for a group of links - if (!empty($_POST['links']) && $action == 'change_links_category') { + # Move to right tab + if (!empty($_POST['links']) && $action == 'moveto_change_links_category') { + // Nothing to do: show links action page + } - foreach($_POST['links'] as $link_id) { - $cur = $core->con->openCursor($C2->table); - $cur->cat_id = abs((integer) $_POST['upd_category']); - $C2->updLink($link_id,$cur); - } + # Update category for a group of links + if (!empty($_POST['links']) && $action == 'change_links_category') { - dcPage::addSuccessNotice( - __('Links successfully updated.') - ); - http::redirect(empty($_POST['redir']) ? - $p_url.'#links' : $_POST['redir'] - ); - } + foreach($_POST['links'] as $link_id) { + $cur = $core->con->openCursor($C2->table); + $cur->cat_id = abs((integer) $_POST['upd_category']); + $C2->updLink($link_id,$cur); + } - # Move to right tab - if (!empty($_POST['links']) && $_POST['action'] == 'moveto_change_links_note') { - // Nothing to do: show links action page - } + dcPage::addSuccessNotice( + __('Links successfully updated.') + ); + http::redirect(empty($_POST['redir']) ? + $p_url.'#links' : $_POST['redir'] + ); + } - # Update note for a group of links - if (!empty($_POST['links']) && $action == 'change_links_note') { + # Move to right tab + if (!empty($_POST['links']) && $_POST['action'] == 'moveto_change_links_note') { + // Nothing to do: show links action page + } - foreach($_POST['links'] as $link_id) { - $cur = $core->con->openCursor($C2->table); - $cur->link_note = abs((integer) $_POST['upd_note']); - $C2->updLink($link_id,$cur); - } + # Update note for a group of links + if (!empty($_POST['links']) && $action == 'change_links_note') { - dcPage::addSuccessNotice( - __('Links successfully updated.') - ); - http::redirect(empty($_POST['redir']) ? - $p_url.'#links' : $_POST['redir'] - ); - } + foreach($_POST['links'] as $link_id) { + $cur = $core->con->openCursor($C2->table); + $cur->link_note = abs((integer) $_POST['upd_note']); + $C2->updLink($link_id,$cur); + } - # Create or update link - if (!empty($_POST['newlink'])) { + dcPage::addSuccessNotice( + __('Links successfully updated.') + ); + http::redirect(empty($_POST['redir']) ? + $p_url.'#links' : $_POST['redir'] + ); + } - cinecturlink2::test_folder( - DC_ROOT.'/'.$core->blog->settings->system->public_path, - $core->blog->settings->cinecturlink2->cinecturlink2_folder - ); + # Create or update link + if (!empty($_POST['newlink'])) { - if (empty($new_title)) { - throw new Exception(__('You must provide a title.')); - } - if (empty($new_author)) { - throw new Exception(__('You must provide an author.')); - } - if (!preg_match('/http:\/\/.+/',$new_image)) { - throw new Exception(__('You must provide a link to an image.')); - } + cinecturlink2::test_folder( + DC_ROOT.'/'.$core->blog->settings->system->public_path, + $core->blog->settings->cinecturlink2->cinecturlink2_folder + ); - $cur = $core->con->openCursor($C2->table); - $cur->link_title = $new_title; - $cur->link_desc = $new_desc; - $cur->link_author = $new_author; - $cur->link_url = $new_url; - $cur->cat_id = $new_category == '' ? null : $new_category; - $cur->link_lang = $new_lang; - $cur->link_img = $new_image; - $cur->link_note = $new_note; + if (empty($new_title)) { + throw new Exception(__('You must provide a title.')); + } + if (empty($new_author)) { + throw new Exception(__('You must provide an author.')); + } + if (!preg_match('/http:\/\/.+/',$new_image)) { + throw new Exception(__('You must provide a link to an image.')); + } - # Create link - if (empty($upd_link_id)) { + $cur = $core->con->openCursor($C2->table); + $cur->link_title = $new_title; + $cur->link_desc = $new_desc; + $cur->link_author = $new_author; + $cur->link_url = $new_url; + $cur->cat_id = $new_category == '' ? null : $new_category; + $cur->link_lang = $new_lang; + $cur->link_img = $new_image; + $cur->link_note = $new_note; - $exists = $C2->getLinks(array('link_title'=>$new_title),true)->f(0); - if ($exists) { - throw new Exception(__('Link with same name already exists.')); - } + # Create link + if (empty($upd_link_id)) { - $C2->addLink($cur); + $exists = $C2->getLinks(array('link_title'=>$new_title),true)->f(0); + if ($exists) { + throw new Exception(__('Link with same name already exists.')); + } - dcPage::addSuccessNotice( - __('Link successfully created.') - ); - } + $C2->addLink($cur); - # Update link - else { + dcPage::addSuccessNotice( + __('Link successfully created.') + ); + } - $exists = $C2->getLinks(array('link_id'=>$upd_link_id),true)->f(0); - if (!$exists) { - throw new Exception(__('Unknown link.')); - } + # Update link + else { - $C2->updLink($upd_link_id,$cur); + $exists = $C2->getLinks(array('link_id'=>$upd_link_id),true)->f(0); + if (!$exists) { + throw new Exception(__('Unknown link.')); + } - dcPage::addSuccessNotice( - __('Link successfully updated.') - ); - } + $C2->updLink($upd_link_id,$cur); - http::redirect(empty($_POST['redir']) ? - $p_url.'#links' : $_POST['redir'] - ); - } + dcPage::addSuccessNotice( + __('Link successfully updated.') + ); + } + + http::redirect(empty($_POST['redir']) ? + $p_url.'#links' : $_POST['redir'] + ); + } } catch(Exception $e) { - $core->error->add($e->getMessage()); + $core->error->add($e->getMessage()); } # Construct lists @@ -250,86 +249,86 @@ $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; $nb_per_page = 30; if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { - if ($nb_per_page != $_GET['nb']) $show_filters = true; - $nb_per_page = (integer) $_GET['nb']; + if ($nb_per_page != $_GET['nb']) $show_filters = true; + $nb_per_page = (integer) $_GET['nb']; } $sortby_combo = array( - __('Date') => 'link_upddt', - __('Title') => 'link_title', - __('Category') => 'cat_title', - __('My rating') => 'link_note', + __('Date') => 'link_upddt', + __('Title') => 'link_title', + __('Category') => 'cat_title', + __('My rating') => 'link_note', ); $order_combo = array( - __('Descending') => 'desc', - __('Ascending') => 'asc' + __('Descending') => 'desc', + __('Ascending') => 'asc' ); $params = array(); $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); if ($sortby != '' && in_array($sortby,$sortby_combo)) { - if ($order != '' && in_array($order,$order_combo)) { - $params['order'] = $sortby.' '.$order; - } - if ($sortby != 'link_upddt' || $order != 'desc') { - $show_filters = true; - } + if ($order != '' && in_array($order,$order_combo)) { + $params['order'] = $sortby.' '.$order; + } + if ($sortby != 'link_upddt' || $order != 'desc') { + $show_filters = true; + } } $categories = $C2->getCategories(); $categories_combo = array('-'=> ''); while($categories->fetch()) { - $cat_title = html::escapeHTML($categories->cat_title); - $categories_combo[$cat_title] = $categories->cat_id; + $cat_title = html::escapeHTML($categories->cat_title); + $categories_combo[$cat_title] = $categories->cat_id; } $medias_combo = $tmp_medias_combo = $dir = null; try { - $allowed_medias = array('png','jpg','gif','bmp','jpeg'); - $core->media = new dcMedia($core); - $core->media->chdir($core->blog->settings->cinecturlink2->cinecturlink2_folder); - $core->media->getDir(); - $dir =& $core->media->dir; - - foreach($dir['files'] as $file) { - if (!in_array(files::getExtension($file->relname),$allowed_medias)) continue; - $tmp_medias_combo[$file->media_title] = $file->file_url; - } - if (!empty($tmp_medias_combo)) { - $medias_combo = array_merge(array('-'=>''),$tmp_medias_combo); - } + $allowed_medias = array('png','jpg','gif','bmp','jpeg'); + $core->media = new dcMedia($core); + $core->media->chdir($core->blog->settings->cinecturlink2->cinecturlink2_folder); + $core->media->getDir(); + $dir =& $core->media->dir; + + foreach($dir['files'] as $file) { + if (!in_array(files::getExtension($file->relname),$allowed_medias)) continue; + $tmp_medias_combo[$file->media_title] = $file->file_url; + } + if (!empty($tmp_medias_combo)) { + $medias_combo = array_merge(array('-'=>''),$tmp_medias_combo); + } } catch (Exception $e) { - //$core->error->add($e->getMessage()); + //$core->error->add($e->getMessage()); } $langs_combo = l10n::getISOcodes(true); $links_action_combo = array( - __('delete') => 'delete_links', - __('change category') => 'moveto_change_links_category', - __('change my rating') => 'moveto_change_links_note' + __('delete') => 'delete_links', + __('change category') => 'moveto_change_links_category', + __('change my rating') => 'moveto_change_links_note' ); $notes_combo = array(); for ($i=0;$i<21;$i++) { - $notes_combo[$i.'/20'] = $i; + $notes_combo[$i.'/20'] = $i; } $pager_base_url = $p_url. - '&sortby='.$sortby. - '&order='.$order. - '&nb='.$nb_per_page. - '&page=%s'; + '&sortby='.$sortby. + '&order='.$order. + '&nb='.$nb_per_page. + '&page=%s'; try { - $links = $C2->getLinks($params); - $links_counter = $C2->getLinks($params,true)->f(0); - $links_list = new adminListCinecturlink2($core,$links,$links_counter,$pager_base_url); + $links = $C2->getLinks($params); + $links_counter = $C2->getLinks($params,true)->f(0); + $links_list = new adminListCinecturlink2($core,$links,$links_counter,$pager_base_url); } catch (Exception $e) { - $core->error->add($e->getMessage()); + $core->error->add($e->getMessage()); } # Page headers @@ -360,309 +359,309 @@ dcPage::jsVar('dotclear.msg.cancel_the_filter', __('Cancel filters and display o # Change category for links if (!empty($_POST['links']) && $action == 'moveto_change_links_category') { - echo - dcPage::breadcrumb( - array( - html::escapeHTML($core->blog->name) => '', - __('Cinecturlink 2') => $p_url.'&move=1#links', - __('Change category of links') => '' - ) - ). - dcPage::notices(); - - echo ' - + echo + dcPage::breadcrumb( + array( + html::escapeHTML($core->blog->name) => '', + __('Cinecturlink 2') => $p_url.'&move=1#links', + __('Change category of links') => '' + ) + ). + dcPage::notices(); - '; } # Change note for links elseif (!empty($_POST['links']) && $action == 'moveto_change_links_note') { - echo dcPage::breadcrumb( - array( - html::escapeHTML($core->blog->name) => '', - __('Cinecturlink 2') => $p_url.'&move=1#links', - __('Change note of links') => '' - ) - ). - dcPage::notices(); + echo dcPage::breadcrumb( + array( + html::escapeHTML($core->blog->name) => '', + __('Cinecturlink 2') => $p_url.'&move=1#links', + __('Change note of links') => '' + ) + ). + dcPage::notices(); - echo ' - + echo ' + - '; } # All other tabs else { - echo dcPage::breadcrumb( - array( - html::escapeHTML($core->blog->name) => '', - __('Cinecturlink 2') => '' - ) - ). - dcPage::notices(); + echo dcPage::breadcrumb( + array( + html::escapeHTML($core->blog->name) => '', + __('Cinecturlink 2') => '' + ) + ). + dcPage::notices(); - # List links - echo ' - '; - if (null !== $upd_link_id) { + # Create/edit link + $title = __('New link'); - $upd_rs = $C2->getLinks(array('link_id' => $upd_link_id)); - $upd_link_id = null; - if (!$upd_rs->isEmpty()) { - $new_title = $upd_rs->link_title; - $new_desc = $upd_rs->link_desc; - $new_author = $upd_rs->link_author; - $new_url = $upd_rs->link_url; - $new_category = $upd_rs->cat_id; - $new_lang = $upd_rs->link_lang; - $new_image = $upd_rs->link_img; - $new_note = $upd_rs->link_note; - $upd_link_id = $upd_rs->link_id; - $title = __('Edit link'); - } - } + if (null !== $upd_link_id) { - echo ' - '; + echo ' + + +

    '.__('Check to delete').'

    +

    '. + form::hidden('cats_order', ''). + form::hidden(array('action'), 'update_categories'). + $core->formNonce().' + +

    + '; + } - # Create category - echo ' -
    -
    + echo ' +
    '; -

    + # Create category + echo ' +
    + -

    +

    -

    '. - form::hidden(array('action'), 'create_category'). - $core->formNonce().' - -

    - -
    '; +

    + +

    '. + form::hidden(array('action'), 'create_category'). + $core->formNonce().' + +

    + + '; } dcPage::helpBlock('cinecturlink2'); @@ -676,4 +675,4 @@ urlencode('plugin.php?p=cinecturlink2').'">'.__('Configuration').' - cinecturlink2 - '.$core->plugins->moduleInfo('cinecturlink2', 'version').'  '.__('cinecturlink2').'

    -'; +'; \ No newline at end of file diff --git a/js/cinecturlink2.js b/js/cinecturlink2.js index 4944bfd..adba4de 100644 --- a/js/cinecturlink2.js +++ b/js/cinecturlink2.js @@ -71,10 +71,10 @@ dotclear.sortable = { } }; $(function() { - + $filtersform = $('#filters-form'); $filtersform.before('

    '+dotclear.msg.filter_posts_list+'

    ') - + if( dotclear.msg.show_filters == 'false' ) { $filtersform.hide(); } else { @@ -82,7 +82,7 @@ $(function() { .addClass('open') .text(dotclear.msg.cancel_the_filter); } - + $('#filter-control').click(function() { if( $(this).hasClass('open') ) { if( dotclear.msg.show_filters == 'true' ) { diff --git a/locales/fr/main.lang.php b/locales/fr/main.lang.php index ae2753d..fe4e727 100644 --- a/locales/fr/main.lang.php +++ b/locales/fr/main.lang.php @@ -322,6 +322,4 @@ $GLOBALS['__l10n']['description'] = 'description'; $GLOBALS['__l10n']['Check to delete'] = 'Cocher pour supprimer'; #index.php:638 -$GLOBALS['__l10n']['update categories'] = 'mettre à jour les catégories'; - -?> \ No newline at end of file +$GLOBALS['__l10n']['update categories'] = 'mettre à jour les catégories'; \ No newline at end of file