diff --git a/_admin.php b/_admin.php index f551f60..751db23 100644 --- a/_admin.php +++ b/_admin.php @@ -14,30 +14,30 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } -require_once dirname(__FILE__) . '/_widgets.php'; +require_once __DIR__ . '/_widgets.php'; -$_menu['Plugins']->addItem( +dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('My cinecturlink'), - $core->adminurl->get('admin.plugin.cinecturlink2'), + dcCore::app()->adminurl->get('admin.plugin.cinecturlink2'), dcPage::getPF('cinecturlink2/icon.png'), preg_match( - '/' . preg_quote($core->adminurl->get('admin.plugin.cinecturlink2')) . '(&.*)?$/', + '/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.cinecturlink2')) . '(&.*)?$/', $_SERVER['REQUEST_URI'] ), - $core->auth->check('contentadmin', $core->blog->id) + dcCore::app()->auth->check(dcAuth::PERMISSION_CONTENT_ADMIN, dcCore::app()->blog->id) ); -$core->addBehavior( - 'adminColumnsLists', +dcCore::app()->addBehavior( + 'adminColumnsListsV2', ['cinecturlink2AdminBehaviors', 'adminColumnsLists'] ); -$core->addBehavior( - 'adminFiltersLists', +dcCore::app()->addBehavior( + 'adminFiltersListsV2', ['cinecturlink2AdminBehaviors', 'adminFiltersLists'] ); -$core->addBehavior( - 'adminDashboardFavorites', +dcCore::app()->addBehavior( + 'adminDashboardFavoritesV2', ['cinecturlink2AdminBehaviors', 'adminDashboardFavorites'] ); @@ -52,11 +52,11 @@ class cinecturlink2AdminBehaviors __('Author') => 'link_author', __('Description') => 'link_desc', __('Link') => 'link_url', - __('Rating') => 'link_note' + __('Rating') => 'link_note', ]; } - public static function adminColumnsLists($core, $cols) + public static function adminColumnsLists($cols) { $cols['c2link'] = [ __('Cinecturlink'), @@ -67,30 +67,30 @@ class cinecturlink2AdminBehaviors 'desc' => [false, __('Description')], 'link' => [true, __('Liens')], 'note' => [true, __('Rating')], - ] + ], ]; } - public static function adminFiltersLists($core, $sorts) + public static function adminFiltersLists($sorts) { $sorts['c2link'] = [ __('Cinecturlink'), self::adminSortbyCombo(), 'link_upddt', 'desc', - [__('Links per page'), 30] + [__('Links per page'), 30], ]; } - public static function adminDashboardFavorites($core, $favs) + public static function adminDashboardFavorites($favs) { $favs->register('cinecturlink2', [ 'title' => __('My cinecturlink'), - 'url' => $core->adminurl->get('admin.plugin.cinecturlink2') . '#links', + 'url' => dcCore::app()->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'] + 'permissions' => dcCore::app()->auth->check('contentadmin', dcCore::app()->blog->id), + 'active_cb' => ['cinecturlink2AdminBehaviors', 'adminDashboardFavoritesActive'], ]); } diff --git a/_config.php b/_config.php index 1cd274c..e309ef6 100644 --- a/_config.php +++ b/_config.php @@ -15,13 +15,13 @@ if (!defined('DC_CONTEXT_MODULE')) { } # Check user perms -dcPage::check('admin'); +dcPage::check(dcAuth::PERMISSION_ADMIN); $redir = empty($_REQUEST['redir']) ? - $list->getURL() . '#plugins' : $_REQUEST['redir']; + dcCore::app()->admin->list->getURL() . '#plugins' : $_REQUEST['redir']; -$core->blog->settings->addNamespace('cinecturlink2'); -$s = $core->blog->settings->cinecturlink2; +dcCore::app()->blog->settings->addNamespace('cinecturlink2'); +$s = dcCore::app()->blog->settings->cinecturlink2; $cinecturlink2_active = (bool) $s->cinecturlink2_active; $cinecturlink2_widthmax = abs((int) $s->cinecturlink2_widthmax); $cinecturlink2_folder = (string) $s->cinecturlink2_folder; @@ -34,7 +34,7 @@ if ($cinecturlink2_public_nbrpp < 1) { $cinecturlink2_public_nbrpp = 10; } -$combo_dirs = cinecturlink2::getPublicDirs($core); +$combo_dirs = cinecturlink2::getPublicDirs(); if (!empty($_POST['save'])) { try { @@ -56,7 +56,7 @@ if (!empty($_POST['save'])) { throw new Exception(__('You must provide a specific folder for images.')); } cinecturlink2::makePublicDir( - DC_ROOT . '/' . $core->blog->settings->system->public_path, + DC_ROOT . '/' . dcCore::app()->blog->settings->system->public_path, $cinecturlink2_folder, true ); @@ -69,15 +69,15 @@ if (!empty($_POST['save'])) { $s->put('cinecturlink2_folder', $cinecturlink2_folder); $s->put('cinecturlink2_triggeronrandom', $cinecturlink2_triggeronrandom); - dcPage::addSuccessNotice( + dcAdminNotices::addSuccessNotice( __('Configuration successfully updated.') ); - $core->adminurl->redirect( + dcCore::app()->adminurl->redirect( 'admin.plugins', - ['module' => 'cinecturlink2', 'conf' => 1, 'redir' => $list->getRedir()] + ['module' => 'cinecturlink2', 'conf' => 1, 'redir' => dcCore::app()->admin->list->getRedir()] ); } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } } @@ -116,7 +116,7 @@ __('Update cache when use "Random" or "Number of view" order on widget (Need rel
-' . sprintf(__('Public page has url: %s'), '' . $core->blog->url . $core->url->getBase('cinecturlink2') . '') . '
+' . sprintf(__('Public page has url: %s'), '' . dcCore::app()->blog->url . dcCore::app()->url->getBase('cinecturlink2') . '') . '
' . form::field('cinecturlink2_public_title', 60, 255, $cinecturlink2_public_title, 'maximal') . '
diff --git a/_define.php b/_define.php index e7c3ae8..8d61558 100644 --- a/_define.php +++ b/_define.php @@ -24,13 +24,13 @@ $this->registerModule( 'Cinecturlink 2', 'Widgets and pages about books, musics, films, blogs you are interested in', 'Jean-Christian Denis and Contributors', - '1.0.0', + '1.1.0', [ - 'requires' => [['core', '2.20']], - 'permissions' => 'contentadmin', + 'requires' => [['core', '2.24']], + 'permissions' => dcAuth::PERMISSION_CONTENT_ADMIN, 'type' => 'plugin', 'support' => 'https://github.com/JcDenis/cinecturlink2', 'details' => 'https://plugins.dotaddict.org/dc2/details/cinecturlink2', - 'repository' => 'https://raw.githubusercontent.com/JcDenis/cinecturlink2/master/dcstore.xml' + 'repository' => 'https://raw.githubusercontent.com/JcDenis/cinecturlink2/master/dcstore.xml', ] ); diff --git a/_install.php b/_install.php index 307f244..00f4482 100644 --- a/_install.php +++ b/_install.php @@ -14,15 +14,15 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } -$new_version = $core->plugins->moduleInfo('cinecturlink2', 'version'); -$old_version = $core->getVersion('cinecturlink2'); +$new_version = dcCore::app()->plugins->moduleInfo('cinecturlink2', 'version'); +$old_version = dcCore::app()->getVersion('cinecturlink2'); if (version_compare($old_version, $new_version, '>=')) { return; } try { - $s = new dbStruct($core->con, $core->prefix); + $s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); $s->cinecturlink2 ->link_id('bigint', 0, false) ->blog_id('varchar', 32, false) @@ -62,11 +62,11 @@ try { ->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); + $si = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); $changes = $si->synchronize($s); - $core->blog->settings->addNamespace('cinecturlink2'); - $s = $core->blog->settings->cinecturlink2; + dcCore::app()->blog->settings->addNamespace('cinecturlink2'); + $s = dcCore::app()->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); @@ -77,14 +77,14 @@ try { $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( + dcCore::app()->setVersion( 'cinecturlink2', - $core->plugins->moduleInfo('cinecturlink2', 'version') + dcCore::app()->plugins->moduleInfo('cinecturlink2', 'version') ); return true; } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } return false; diff --git a/_prepend.php b/_prepend.php index fbeb6d8..ed6065b 100644 --- a/_prepend.php +++ b/_prepend.php @@ -14,30 +14,28 @@ if (!defined('DC_RC_PATH')) { return null; } -$d = dirname(__FILE__) . '/inc/'; +Clearbricks::lib()->autoload(['cinecturlink2' => __DIR__ . '/inc/class.cinecturlink2.php']); +Clearbricks::lib()->autoload(['cinecturlink2Context' => __DIR__ . '/inc/lib.cinecturlink2.context.php']); +Clearbricks::lib()->autoload(['adminlistCinecturlink2' => __DIR__ . '/inc/lib.cinecturlink2.list.php']); +Clearbricks::lib()->autoload(['sitemapsCinecturlink2' => __DIR__ . '/inc/lib.sitemaps.cinecturlink2.php']); +Clearbricks::lib()->autoload(['cinecturlink2ActivityReportBehaviors' => __DIR__ . '/inc/lib.cinecturlink2.activityreport.php']); -$__autoload['cinecturlink2'] = $d . 'class.cinecturlink2.php'; -$__autoload['cinecturlink2Context'] = $d . 'lib.cinecturlink2.context.php'; -$__autoload['adminlistCinecturlink2'] = $d . 'lib.cinecturlink2.list.php'; -$__autoload['sitemapsCinecturlink2'] = $d . 'lib.sitemaps.cinecturlink2.php'; -$__autoload['cinecturlink2ActivityReportBehaviors'] = $d . 'lib.cinecturlink2.activityreport.php'; - -$core->url->register( +dcCore::app()->url->register( 'cinecturlink2', 'cinecturlink', '^cinecturlink(?:/(.+))?$', ['urlCinecturlink2', 'c2Page'] ); -$core->addBehavior( +dcCore::app()->addBehavior( 'sitemapsDefineParts', ['sitemapsCinecturlink2', 'sitemapsDefineParts'] ); -$core->addBehavior( +dcCore::app()->addBehavior( 'sitemapsURLsCollect', ['sitemapsCinecturlink2', 'sitemapsURLsCollect'] ); if (defined('ACTIVITY_REPORT')) { - cinecturlink2ActivityReportBehaviors::add($core); + cinecturlink2ActivityReportBehaviors::add(); } diff --git a/_public.php b/_public.php index be7d401..a7bd2db 100644 --- a/_public.php +++ b/_public.php @@ -14,9 +14,9 @@ if (!defined('DC_RC_PATH')) { return null; } -require_once dirname(__FILE__) . '/_widgets.php'; +require_once __DIR__ . '/_widgets.php'; -$core->blog->settings->addNamespace('cinecturlink2'); +dcCore::app()->blog->settings->addNamespace('cinecturlink2'); $c2_tpl_values = [ 'c2PageFeedID', @@ -56,7 +56,7 @@ $c2_tpl_values = [ 'c2CategoryID', 'c2CategoryTitle', 'c2CategoryDescription', - 'c2CategoryURL' + 'c2CategoryURL', ]; $c2_tpl_blocks = [ @@ -73,19 +73,19 @@ $c2_tpl_blocks = [ 'c2Categories', 'c2CategoriesHeader', 'c2CategoriesFooter', - 'c2CategoryIf' + 'c2CategoryIf', ]; -if ($core->blog->settings->cinecturlink2->cinecturlink2_active) { +if (dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_active) { foreach ($c2_tpl_blocks as $v) { - $core->tpl->addBlock($v, ['tplCinecturlink2', $v]); + dcCore::app()->tpl->addBlock($v, ['tplCinecturlink2', $v]); } foreach ($c2_tpl_values as $v) { - $core->tpl->addValue($v, ['tplCinecturlink2', $v]); + dcCore::app()->tpl->addValue($v, ['tplCinecturlink2', $v]); } } else { foreach (array_merge($c2_tpl_blocks, $c2_tpl_values) as $v) { - $core->tpl->addBlock($v, ['tplCinecturlink2', 'disable']); + dcCore::app()->tpl->addBlock($v, ['tplCinecturlink2', 'disable']); } } @@ -93,19 +93,19 @@ class urlCinecturlink2 extends dcUrlHandlers { public static function c2Page($args) { - global $core, $_ctx; - $core->blog->settings->addNamespace('cinecturlink2'); + dcCore::app()->blog->settings->addNamespace('cinecturlink2'); + $args = (string) $args; - if (!$core->blog->settings->cinecturlink2->cinecturlink2_active - || !$core->blog->settings->cinecturlink2->cinecturlink2_public_active) { + if (!dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_active + || !dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_active) { self::p404(); return null; } - $core->tpl->setPath( - $core->tpl->getPath(), - dirname(__FILE__) . '/default-templates/' + dcCore::app()->tpl->setPath( + dcCore::app()->tpl->getPath(), + __DIR__ . '/default-templates/' ); $params = []; @@ -115,7 +115,7 @@ class urlCinecturlink2 extends dcUrlHandlers $GLOBALS['c2_page_number'] = $n; } - $caturl = $core->blog->settings->cinecturlink2->cinecturlink2_public_caturl; + $caturl = dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_caturl; if (!$caturl) { $caturl = 'c2cat'; } @@ -133,12 +133,12 @@ class urlCinecturlink2 extends dcUrlHandlers if ($f && in_array($f, ['atom', 'rss2'])) { $mime = $f == 'atom' ? 'application/atom+xml' : 'application/xml'; - //$_ctx->short_feed_items = $core->blog->settings->system->short_feed_items; + //dcCore::app()->ctx->short_feed_items = dcCore::app()->blog->settings->system->short_feed_items; - $params['limit'] = $core->blog->settings->system->nb_post_per_feed; - $_ctx->c2_page_params = $params; + $params['limit'] = dcCore::app()->blog->settings->system->nb_post_per_feed; + dcCore::app()->ctx->c2_page_params = $params; - header('X-Robots-Tag: ' . context::robotsPolicy($core->blog->settings->system->robots_policy, '')); + header('X-Robots-Tag: ' . context::robotsPolicy(dcCore::app()->blog->settings->system->robots_policy, '')); self::serveDocument('cinecturlink2-' . $f . '.xml', $mime); } else { $d = self::getPageArgs($args, 'c2detail'); @@ -150,8 +150,8 @@ class urlCinecturlink2 extends dcUrlHandlers } } - $params['limit'] = $core->blog->settings->cinecturlink2->cinecturlink2_public_nbrpp; - $_ctx->c2_page_params = $params; + $params['limit'] = dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_nbrpp; + dcCore::app()->ctx->c2_page_params = $params; self::serveDocument('cinecturlink2.html', 'text/html'); } @@ -180,27 +180,27 @@ class tplCinecturlink2 public static function c2PageURL($a) { - return 'tpl->getFilters($a), '$core->blog->url.$core->url->getBase(\'cinecturlink2\')') . '; ?>'; + return 'tpl->getFilters($a), 'dcCore::app()->blog->url.dcCore::app()->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') . '; ?>'; + return "blog->settings->cinecturlink2->cinecturlink2_public_title; if (empty(\$title)) { \$title = __('My cinecturlink'); } echo " . sprintf(dcCore::app()->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') . '"') . '; ?>'; + return 'tpl->getFilters($a), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("cinecturlink2")."/feed/' . (!empty($a['type']) && preg_match('#^(rss2|atom)$#', $a['type']) ? $a['type'] : 'atom') . '"') . '; ?>'; } public static function c2PageFeedID($a) { - return 'urn:md5:blog->id."cinecturlink2"); ?>'; + return 'urn:md5:blog->id."cinecturlink2"); ?>'; } public static function c2PageDescription($a) { - return 'blog->settings->cinecturlink2->cinecturlink2_public_description; echo ' . sprintf($GLOBALS['core']->tpl->getFilters($a), '$description') . '; ?>'; + return 'blog->settings->cinecturlink2->cinecturlink2_public_description; echo ' . sprintf(dcCore::app()->tpl->getFilters($a), '$description') . '; ?>'; } public static function c2If($a, $c) @@ -211,12 +211,12 @@ class tplCinecturlink2 if (isset($a['request_link'])) { $sign = (bool) $a['request_link'] ? '' : '!'; - $if[] = $sign . '(isset($_ctx->c2_page_params["link_id"]) || isset($_ctx->c2_page_params["link_title"]))'; + $if[] = $sign . '(isset(dcCore::app()->ctx->c2_page_params["link_id"]) || isset(dcCore::app()->ctx->c2_page_params["link_title"]))'; } if (isset($a['request_cat'])) { $sign = (bool) $a['request_cat'] ? '' : '!'; - $if[] = $sign . '(isset($_ctx->c2_page_params["cat_id"]) || isset($_ctx->c2_page_params["cat_title"]))'; + $if[] = $sign . '(isset(dcCore::app()->ctx->c2_page_params["cat_id"]) || isset(dcCore::app()->ctx->c2_page_params["cat_title"]))'; } return empty($if) ? $c : '\n" . $c . "\n"; @@ -258,24 +258,24 @@ class tplCinecturlink2 return "c2_page_params) ? \$_ctx->c2_page_params : array(); \n" . + "\$params = is_array(dcCore::app()->ctx->c2_page_params) ? dcCore::app()->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" . + "dcCore::app()->ctx->c2_params = \$params; unset(\$params);\n" . + "if (!dcCore::app()->ctx->exists('cinecturlink')) { dcCore::app()->ctx->cinecturlink = new cinecturlink2(); } \n" . + "dcCore::app()->ctx->c2_entries = dcCore::app()->ctx->cinecturlink->getLinks(dcCore::app()->ctx->c2_params); \n" . + 'while (dcCore::app()->ctx->c2_entries->fetch()) : ?>' . $c . 'ctx->pop('c2_entries'); dcCore::app()->ctx->pop('c2_params'); \n" . "?>\n"; } public static function c2EntriesHeader($a, $c) { - return 'c2_entries->isStart()) : ?>' . $c . ''; + return 'ctx->c2_entries->isStart()) : ?>' . $c . ''; } public static function c2EntriesFooter($a, $c) { - return 'c2_entries->isEnd()) : ?>' . $c . ''; + return 'ctx->c2_entries->isEnd()) : ?>' . $c . ''; } public static function c2EntryIf($a, $c) @@ -286,7 +286,7 @@ class tplCinecturlink2 if (isset($a['has_category'])) { $sign = (bool) $a['has_category'] ? '!' : '='; - $if[] = '($_ctx->exists("c2_entries") && "" ' . $sign . '= $_ctx->c2_entries->cat_title)'; + $if[] = '(dcCore::app()->ctx->exists("c2_entries") && "" ' . $sign . '= dcCore::app()->ctx->c2_entries->cat_title)'; } return empty($if) ? $c : '\n" . $c . "\n"; @@ -294,106 +294,105 @@ class tplCinecturlink2 public static function c2EntryIfFirst($a) { - return 'c2_entries->index() == 0) { echo "' . (isset($a['return']) ? addslashes(html::escapeHTML($a['return'])) : 'first') . '"; } ?>'; + return 'ctx->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') . '"; } ?>'; + return 'ctx->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_creadt); ?>'; + return 'urn:md5:ctx->c2_entries->blog_id.dcCore::app()->ctx->c2_entries->link_id.dcCore::app()->ctx->c2_entries->link_creadt); ?>'; } public static function c2EntryID($a) { - return self::getGenericValue('$_ctx->c2_entries->link_id', $a); + return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_id', $a); } public static function c2EntryTitle($a) { - return self::getGenericValue('$_ctx->c2_entries->link_title', $a); + return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_title', $a); } public static function c2EntryDescription($a) { - return self::getGenericValue('$_ctx->c2_entries->link_desc', $a); + return self::getGenericValue('dcCore::app()->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); + return self::getGenericValue('dcUtils::getUserCN(dcCore::app()->ctx->c2_entries->user_id,dcCore::app()->ctx->c2_entries->user_name,dcCore::app()->ctx->c2_entries->user_firstname,dcCore::app()->ctx->c2_entries->user_displayname)', $a); } public static function c2EntryAuthorDisplayName($a) { - return self::getGenericValue('$_ctx->c2_entries->user_displayname', $a); + return self::getGenericValue('dcCore::app()->ctx->c2_entries->user_displayname', $a); } public static function c2EntryAuthorID($a) { - return self::getGenericValue('$_ctx->c2_entries->user_id', $a); + return self::getGenericValue('dcCore::app()->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); + return self::getGenericValue((isset($a['spam_protected']) && !$a['spam_protected'] ? 'dcCore::app()->ctx->c2_entries->user_email' : "strtr(dcCore::app()->ctx->c2_entries->user_email,array('@'=>'%40','.'=>'%2e'))"), $a); } 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); + return self::getGenericValue('sprintf((dcCore::app()->ctx->c2_entries->user_url ? \'%1$s\' : \'%1$s\'),html::escapeHTML(dcUtils::getUserCN(dcCore::app()->ctx->c2_entries->user_id,dcCore::app()->ctx->c2_entries->user_name,dcCore::app()->ctx->c2_entries->user_firstname,dcCore::app()->ctx->c2_entries->user_displayname)),html::escapeHTML(dcCore::app()->ctx->c2_entries->user_url))', $a); } public static function c2EntryAuthorURL($a) { - return self::getGenericValue('$_ctx->c2_entries->user_url', $a); + return self::getGenericValue('dcCore::app()->ctx->c2_entries->user_url', $a); } public static function c2EntryFromAuthor($a) { - return self::getGenericValue('$_ctx->c2_entries->link_author', $a); + return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_author', $a); } public static function c2EntryLang($a) { - return self::getGenericValue('$_ctx->c2_entries->link_lang', $a); + return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_lang', $a); } public static function c2EntryURL($a) { - return self::getGenericValue('$_ctx->c2_entries->link_url', $a); + return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_url', $a); } public static function c2EntryCategory($a) { - return self::getGenericValue('$_ctx->c2_entries->cat_title', $a); + return self::getGenericValue('dcCore::app()->ctx->c2_entries->cat_title', $a); } public static function c2EntryCategoryID($a) { - return self::getGenericValue('$_ctx->c2_entries->cat_id', $a); + return self::getGenericValue('dcCore::app()->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); + return self::getGenericValue('dcCore::app()->blog->url.dcCore::app()->url->getBase("cinecturlink2")."/".dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_caturl."/".urlencode(dcCore::app()->ctx->c2_entries->cat_title)', $a); } public static function c2EntryImg($a) { - global $core; - $f = $core->tpl->getFilters($a); + $f = dcCore::app()->tpl->getFilters($a); $style = isset($a['style']) ? html::escapeHTML($a['style']) : ''; return - "exists('c2_entries')) { " . - '$widthmax = (integer) $core->blog->settings->cinecturlink2->cinecturlink2_widthmax; ' . + "ctx->exists('c2_entries')) { " . + '$widthmax = (integer) dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_widthmax; ' . "\$img = sprintf(''," . - '$_ctx->c2_entries->link_img, ' . - "html::escapeHTML(\$_ctx->c2_entries->link_title.' - '.\$_ctx->c2_entries->link_author), " . + 'dcCore::app()->ctx->c2_entries->link_img, ' . + "html::escapeHTML(dcCore::app()->ctx->c2_entries->link_title.' - '.dcCore::app()->ctx->c2_entries->link_author), " . "(\$widthmax ? ' style=\"width:'.\$widthmax.'px;$style\"' : '') " . '); ' . 'echo ' . sprintf($f, '$img') . "; unset(\$img); } ?> \n"; @@ -404,13 +403,13 @@ class tplCinecturlink2 $format = !empty($a['format']) ? addslashes($a['format']) : ''; if (!empty($a['rfc822'])) { - $p = 'dt::rfc822(strtotime($_ctx->c2_entries->link_creadt), $core->blog->settings->system->blog_timezone)'; + $p = 'dt::rfc822(strtotime(dcCore::app()->ctx->c2_entries->link_creadt), dcCore::app()->blog->settings->system->blog_timezone)'; } elseif (!empty($a['iso8601'])) { - $p = 'dt::iso8601(strtotime($_ctx->c2_entries->link_creadt), $core->blog->settings->system->blog_timezone)'; + $p = 'dt::iso8601(strtotime(dcCore::app()->ctx->c2_entries->link_creadt), dcCore::app()->blog->settings->system->blog_timezone)'; } elseif ($format) { - $p = "dt::dt2str('" . $format . "', \$_ctx->c2_entries->link_creadt)"; + $p = "dt::dt2str('" . $format . "', dcCore::app()->ctx->c2_entries->link_creadt)"; } else { - $p = 'dt::dt2str($core->blog->settings->system->date_format, $_ctx->c2_entries->link_creadt)'; + $p = 'dt::dt2str(dcCore::app()->blog->settings->system->date_format, dcCore::app()->ctx->c2_entries->link_creadt)'; } return self::getGenericValue($p, $a); @@ -418,17 +417,17 @@ class tplCinecturlink2 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); + return self::getGenericValue('dt::dt2str(' . (!empty($a['format']) ? "'" . addslashes($a['format']) . "'" : 'dcCore::app()->blog->settings->system->time_format') . ', dcCore::app()->ctx->c2_entries->link_creadt)', $a); } public static function c2Pagination($a, $c) { $p = "c2_params;\n" . - "\$_ctx->c2_pagination = \$_ctx->cinecturlink->getLinks(\$params,true); unset(\$params);\n" . + "\$params = dcCore::app()->ctx->c2_params;\n" . + "dcCore::app()->ctx->c2_pagination = dcCore::app()->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 . ''; + return isset($a['no_context']) ? $p . $c : $p . 'ctx->c2_pagination->f(0) > dcCore::app()->ctx->c2_entries->count()) : ?>' . $c . ''; } public static function c2PaginationCounter($a) @@ -466,21 +465,21 @@ class tplCinecturlink2 { 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" . + "if (!dcCore::app()->ctx->exists('cinecturlink')) { dcCore::app()->ctx->cinecturlink = new cinecturlink2(); } \n" . + "dcCore::app()->ctx->c2_categories = dcCore::app()->ctx->cinecturlink->getCategories(); \n" . + 'while (dcCore::app()->ctx->c2_categories->fetch()) : ?>' . $c . 'ctx->c2_categories = null; \n" . "?>\n"; } public static function c2CategoriesHeader($a, $c) { - return 'c2_categories->isStart()) : ?>' . $c . ''; + return 'ctx->c2_categories->isStart()) : ?>' . $c . ''; } public static function c2CategoriesFooter($a, $c) { - return 'c2_categories->isEnd()) : ?>' . $c . ''; + return 'ctx->c2_categories->isEnd()) : ?>' . $c . ''; } public static function c2CategoryIf($a, $c) @@ -493,7 +492,7 @@ class tplCinecturlink2 } if (isset($a['first'])) { $sign = (bool) $a['first'] ? '' : '!'; - $if[] = $sign . '$_ctx->c2_categories->isStart()'; + $if[] = $sign . 'dcCore::app()->ctx->c2_categories->isStart()'; } return empty($if) ? $c : '' . $c . ''; @@ -507,37 +506,37 @@ class tplCinecturlink2 $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 . '"') . '; ?>'; + return 'tpl->getFilters($a), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("cinecturlink2")."/".dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_caturl."/".urlencode(dcCore::app()->ctx->c2_categories->cat_title)."/feed/' . $p . '"') . '; ?>'; } public static function c2CategoryFeedID($a) { - return 'urn:md5:blog->id."cinecturlink2".$_ctx->c2_categories->cat_id); ?>'; + return 'urn:md5:blog->id."cinecturlink2".dcCore::app()->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') . '; } ?>'; + return "ctx->exists('c2_categories')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->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') . '; } ?>'; + return "ctx->exists('c2_categories')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->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') . '; } ?>'; + return "ctx->exists('c2_categories')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->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)') . '; } ?>'; + return "ctx->exists('c2_categories')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("cinecturlink2")."/".dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_caturl."/".urlencode(dcCore::app()->ctx->c2_categories->cat_title)') . '; } ?>'; } protected static function getGenericValue($p, $a) { - return "exists('c2_entries')) { echo " . sprintf($GLOBALS['core']->tpl->getFilters($a), "$p") . '; } ?>'; + return "ctx->exists('c2_entries')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), "$p") . '; } ?>'; } protected static function getOperator($op) diff --git a/_widgets.php b/_widgets.php index 21843f8..4c1e4ec 100644 --- a/_widgets.php +++ b/_widgets.php @@ -14,11 +14,11 @@ if (!defined('DC_RC_PATH')) { return null; } -$core->addBehavior( +dcCore::app()->addBehavior( 'initWidgets', ['cinecturlink2Widget', 'adminLinks'] ); -$core->addBehavior( +dcCore::app()->addBehavior( 'initWidgets', ['cinecturlink2Widget', 'adminCats'] ); @@ -27,9 +27,7 @@ class cinecturlink2Widget { public static function adminLinks($w) { - global $core; - - $C2 = new cinecturlink2($core); + $C2 = new cinecturlink2(); $categories_combo = ['' => '', __('Uncategorized') => 'null']; $categories = $C2->getCategories(); @@ -43,11 +41,11 @@ class cinecturlink2Widget __('My rating') => 'link_note', __('Title') => 'link_title', __('Random') => 'RANDOM', - __('Number of views') => 'COUNTER' + __('Number of views') => 'COUNTER', ]; $order_combo = [ __('Ascending') => 'asc', - __('Descending') => 'desc' + __('Descending') => 'desc', ]; $w @@ -157,18 +155,16 @@ class cinecturlink2Widget public static function publicLinks($w) { - global $core; + dcCore::app()->blog->settings->addNamespace('cinecturlink2'); - $core->blog->settings->addNamespace('cinecturlink2'); - - if (!$core->blog->settings->cinecturlink2->cinecturlink2_active - || $w->homeonly == 1 && !$core->url->isHome($core->url->type) - || $w->homeonly == 2 && $core->url->isHome($core->url->type) + if (!dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_active + || $w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type) + || $w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type) ) { return null; } - $C2 = new cinecturlink2($core); + $C2 = new cinecturlink2(); if ($w->category) { if ($w->category == 'null') { @@ -214,7 +210,7 @@ class cinecturlink2Widget return null; } - $widthmax = (int) $core->blog->settings->cinecturlink2->cinecturlink2_widthmax; + $widthmax = (int) dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_widthmax; $style = $widthmax ? ' style="width:' . $widthmax . 'px;"' : ''; $entries = []; @@ -230,7 +226,7 @@ class cinecturlink2Widget $count = abs((int) $rs->link_count); # --BEHAVIOR-- cinecturlink2WidgetLinks - $bhv = $core->callBehavior('cinecturlink2WidgetLinks', $rs->link_id); + $bhv = dcCore::app()->callBehavior('cinecturlink2WidgetLinks', $rs->link_id); $entries[] = '' . ($w->withlink && !empty($url) ? '' : '') . @@ -242,19 +238,19 @@ class cinecturlink2Widget '
' . $bhv; try { - $cur = $core->con->openCursor($C2->table); + $cur = dcCore::app()->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' + if ($w->sortby == 'RANDOM' || $w->sortby == 'COUNTER' ) { shuffle($entries); - if ($core->blog->settings->cinecturlink2->cinecturlink2_triggeronrandom) { - $core->blog->triggerBlog(); + if (dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_triggeronrandom) { + dcCore::app()->blog->triggerBlog(); } } @@ -264,27 +260,25 @@ class cinecturlink2Widget '', ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . implode(' ', $entries) . ( - $w->showpagelink && $core->blog->settings->cinecturlink2->cinecturlink2_public_active ? - '' : '' + $w->showpagelink && dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_active ? + '' : '' ) ); } public static function publicCats($w) { - global $core; + dcCore::app()->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->isHome($core->url->type) - || $w->homeonly == 2 && $core->url->isHome($core->url->type) + if (!dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_active + || !dcCore::app()->blog->settings->cinecturlink2->cinecturlink2_public_active + || $w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type) + || $w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type) ) { return null; } - $C2 = new cinecturlink2($core); + $C2 = new cinecturlink2(); $rs = $C2->getCategories([]); if ($rs->isEmpty()) { return null; @@ -292,15 +286,15 @@ class cinecturlink2Widget $res = []; $res[] = '' . __('New Link') . ' ' . __('Edit categories') . '
'; if ($links->isEmpty() && !$c2link_filter->show()) { @@ -498,7 +498,7 @@ if ($part == 'links') { $links_list->display( $c2link_filter->page, $c2link_filter->nb, - '', $c2link_filter->show(), @@ -521,7 +521,7 @@ if ($part == 'links') { if ($part == 'link') { echo ' - '; } @@ -593,17 +593,17 @@ if ($part == 'link') { if ($part == 'cats') { echo ''; @@ -612,7 +612,7 @@ if ($part == 'cats') { echo '' . __('There is no category') . '
'; } else { echo ' -