cleanup code

This commit is contained in:
Jean-Christian Paul Denis 2021-09-07 15:21:38 +02:00
parent e510c444d7
commit b21e286961
16 changed files with 2077 additions and 2086 deletions

View File

@ -1,65 +1,56 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief cinecturlink2, a plugin for Dotclear 2
# This file is part of cinecturlink2, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null;
return null;
} }
require_once dirname(__FILE__).'/_widgets.php'; require_once dirname(__FILE__) . '/_widgets.php';
# Admin menu
$_menu['Plugins']->addItem( $_menu['Plugins']->addItem(
__('My cinecturlink'), __('My cinecturlink'),
'plugin.php?p=cinecturlink2', $core->adminurl->get('admin.plugin.cinecturlink2'),
'index.php?pf=cinecturlink2/icon.png', dcPage::getPF('cinecturlink2/icon.png'),
preg_match( preg_match(
'/plugin.php\?p=cinecturlink2(&.*)?$/', '/' . preg_quote($core->adminurl->get('admin.plugin.dcAdvancedCleaner')) . '(&.*)?$/',
$_SERVER['REQUEST_URI']) $_SERVER['REQUEST_URI']
, ),
$core->auth->check('contentadmin', $core->blog->id) $core->auth->check('contentadmin', $core->blog->id)
); );
$core->addBehavior( $core->addBehavior(
'adminDashboardFavorites', 'adminDashboardFavorites',
array('cinecturlink2AdminBehaviors', 'adminDashboardFavorites') ['cinecturlink2AdminBehaviors', 'adminDashboardFavorites']
); );
class cinecturlink2AdminBehaviors class cinecturlink2AdminBehaviors
{ {
public static function adminDashboardFavorites($core, $favs) public static function adminDashboardFavorites($core, $favs)
{ {
$favs->register('cinecturlink2', array( $favs->register('cinecturlink2', [
'title' => __('My cinecturlink'), 'title' => __('My cinecturlink'),
'url' => 'plugin.php?p=cinecturlink2#links', 'url' => $core->adminurl->get('admin.plugin.cinecturlink2').'#links',
'small-icon' => 'index.php?pf=cinecturlink2/icon.png', 'small-icon' => dcPage::getPF('cinecturlink2/icon.png'),
'large-icon' => 'index.php?pf=cinecturlink2/icon-big.png', 'large-icon' => dcPage::getPF('cinecturlink2/icon-big.png'),
'permissions' => $core->auth->check( 'permissions' => $core->auth->check('contentadmin', $core->blog->id),
'contentadmin', 'active_cb' => ['cinecturlink2AdminBehaviors', 'adminDashboardFavoritesActive']
$core->blog->id ]);
), }
'active_cb' => array(
'cinecturlink2AdminBehaviors',
'adminDashboardFavoritesActive'
)
));
}
public static function adminDashboardFavoritesActive($request, $params) public static function adminDashboardFavoritesActive($request, $params)
{ {
return $request == 'plugin.php' return $request == 'plugin.php'
&& isset($params['p']) && isset($params['p'])
&& $params['p'] == 'cinecturlink2'; && $params['p'] == 'cinecturlink2';
} }
} }

View File

@ -1,19 +1,18 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief cinecturlink2, a plugin for Dotclear 2
# This file is part of cinecturlink2, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$new_version = $core->plugins->moduleInfo('cinecturlink2', 'version'); $new_version = $core->plugins->moduleInfo('cinecturlink2', 'version');
@ -24,69 +23,69 @@ if (version_compare($old_version, $new_version, '>=')) {
} }
try { try {
$s = new dbStruct($core->con, $core->prefix); $s = new dbStruct($core->con, $core->prefix);
$s->cinecturlink2 $s->cinecturlink2
->link_id ('bigint', 0, false) ->link_id ('bigint', 0, false)
->blog_id ('varchar', 32, false) ->blog_id ('varchar', 32, false)
->cat_id ('bigint', 0, true) ->cat_id ('bigint', 0, true)
->user_id ('varchar', 32, true) ->user_id ('varchar', 32, true)
->link_type ('varchar', 32, false, "'cinecturlink'") ->link_type ('varchar', 32, false, "'cinecturlink'")
->link_title ('varchar', 255, false) ->link_title ('varchar', 255, false)
->link_desc ('varchar', 255, false) ->link_desc ('varchar', 255, false)
->link_author ('varchar', 255, false) ->link_author ('varchar', 255, false)
->link_lang ('varchar', 5, false, "'en'") ->link_lang ('varchar', 5, false, "'en'")
->link_url ('varchar', 255, false) ->link_url ('varchar', 255, false)
->link_img ('varchar', 255, false) ->link_img ('varchar', 255, false)
->link_creadt ('timestamp', 0, false, 'now()') ->link_creadt ('timestamp', 0, false, 'now()')
->link_upddt ('timestamp', 0, false, 'now()') ->link_upddt ('timestamp', 0, false, 'now()')
->link_pos ('smallint', 0, false, "'0'") ->link_pos ('smallint', 0, false, "'0'")
->link_note('smallint', 0, false, "'10'") ->link_note('smallint', 0, false, "'10'")
->link_count('bigint', 0, false, "'0'") ->link_count('bigint', 0, false, "'0'")
->primary('pk_cinecturlink2', 'link_id') ->primary('pk_cinecturlink2', 'link_id')
->index('idx_cinecturlink2_title', 'btree', 'link_title') ->index('idx_cinecturlink2_title', 'btree', 'link_title')
->index('idx_cinecturlink2_author', 'btree', 'link_author') ->index('idx_cinecturlink2_author', 'btree', 'link_author')
->index('idx_cinecturlink2_blog_id', 'btree', 'blog_id') ->index('idx_cinecturlink2_blog_id', 'btree', 'blog_id')
->index('idx_cinecturlink2_cat_id', 'btree', 'cat_id') ->index('idx_cinecturlink2_cat_id', 'btree', 'cat_id')
->index('idx_cinecturlink2_user_id', 'btree', 'user_id') ->index('idx_cinecturlink2_user_id', 'btree', 'user_id')
->index('idx_cinecturlink2_type', 'btree', 'link_type'); ->index('idx_cinecturlink2_type', 'btree', 'link_type');
$s->cinecturlink2_cat $s->cinecturlink2_cat
->cat_id ('bigint', 0, false) ->cat_id ('bigint', 0, false)
->blog_id ('varchar', 32, false) ->blog_id ('varchar', 32, false)
->cat_title ('varchar', 255, false) ->cat_title ('varchar', 255, false)
->cat_desc ('varchar', 255, false) ->cat_desc ('varchar', 255, false)
->cat_creadt ('timestamp', 0, false, 'now()') ->cat_creadt ('timestamp', 0, false, 'now()')
->cat_upddt ('timestamp', 0, false, 'now()') ->cat_upddt ('timestamp', 0, false, 'now()')
->cat_pos ('smallint', 0, false, "'0'") ->cat_pos ('smallint', 0, false, "'0'")
->primary('pk_cinecturlink2_cat', 'cat_id') ->primary('pk_cinecturlink2_cat', 'cat_id')
->index('idx_cinecturlink2_cat_blog_id', 'btree', 'blog_id') ->index('idx_cinecturlink2_cat_blog_id', 'btree', 'blog_id')
->unique('uk_cinecturlink2_cat_title', 'cat_title', 'blog_id'); ->unique('uk_cinecturlink2_cat_title', 'cat_title', 'blog_id');
$si = new dbStruct($core->con,$core->prefix); $si = new dbStruct($core->con,$core->prefix);
$changes = $si->synchronize($s); $changes = $si->synchronize($s);
$core->blog->settings->addNamespace('cinecturlink2'); $core->blog->settings->addNamespace('cinecturlink2');
$s = $core->blog->settings->cinecturlink2; $s = $core->blog->settings->cinecturlink2;
$s->put('cinecturlink2_active', true, 'boolean', 'Enable cinecturlink2', false, true); $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_widthmax', 100, 'integer', 'Maximum width of picture', false, true);
$s->put('cinecturlink2_folder', 'cinecturlink', 'string', 'Public folder of pictures', 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_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_active', false, 'boolean', 'Enable cinecturlink2', false, true);
$s->put('cinecturlink2_public_title', '', 'string', 'Title of public page', 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_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_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); $s->put('cinecturlink2_public_caturl', 'c2cat', 'string', 'Part of URL for a category list', false, true);
$core->setVersion( $core->setVersion(
'cinecturlink2', 'cinecturlink2',
$core->plugins->moduleInfo('cinecturlink2', 'version') $core->plugins->moduleInfo('cinecturlink2', 'version')
); );
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
return false; return false;

File diff suppressed because it is too large Load Diff

View File

@ -1,88 +1,86 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief cinecturlink2, a plugin for Dotclear 2
# This file is part of cinecturlink2, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null;
return null;
} }
$this->addUserAction( $this->addUserAction(
/* type */ 'settings', /* type */ 'settings',
/* action */ 'delete_all', /* action */ 'delete_all',
/* ns */ 'cinecturlink2', /* ns */ 'cinecturlink2',
/* desc */ __('delete all settings') /* desc */ __('delete all settings')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'tables', /* type */ 'tables',
/* action */ 'delete', /* action */ 'delete',
/* ns */ 'cinecturlink2', /* ns */ 'cinecturlink2',
/* desc */ sprintf(__('delete %s table'), 'cinecturlink2') /* desc */ sprintf(__('delete %s table'), 'cinecturlink2')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'tables', /* type */ 'tables',
/* action */ 'delete', /* action */ 'delete',
/* ns */ 'cinecturlink2_cat', /* ns */ 'cinecturlink2_cat',
/* desc */ sprintf(__('delete %s table'), 'cinecturlink2_cat') /* desc */ sprintf(__('delete %s table'), 'cinecturlink2_cat')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'versions', /* type */ 'versions',
/* action */ 'delete', /* action */ 'delete',
/* ns */ 'cinecturlink2', /* ns */ 'cinecturlink2',
/* desc */ __('delete the version number') /* desc */ __('delete the version number')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'plugins', /* type */ 'plugins',
/* action */ 'delete', /* action */ 'delete',
/* ns */ 'cinecturlink2', /* ns */ 'cinecturlink2',
/* desc */ __('delete plugin files') /* desc */ __('delete plugin files')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'settings', /* type */ 'settings',
/* action */ 'delete_all', /* action */ 'delete_all',
/* ns */ 'cinecturlink2', /* ns */ 'cinecturlink2',
/* desc */ sprintf(__('delete all %s settings'), 'cinecturlink2') /* desc */ sprintf(__('delete all %s settings'), 'cinecturlink2')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'tables', /* type */ 'tables',
/* action */ 'delete', /* action */ 'delete',
/* ns */ 'cinecturlink2', /* ns */ 'cinecturlink2',
/* desc */ sprintf(__('delete %s table'), 'cinecturlink2') /* desc */ sprintf(__('delete %s table'), 'cinecturlink2')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'tables', /* type */ 'tables',
/* action */ 'delete', /* action */ 'delete',
/* ns */ 'cinecturlink2_cat', /* ns */ 'cinecturlink2_cat',
/* desc */ sprintf(__('delete %s table'), 'cinecturlink2_cat') /* desc */ sprintf(__('delete %s table'), 'cinecturlink2_cat')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'versions', /* type */ 'versions',
/* action */ 'delete', /* action */ 'delete',
/* ns */ 'cinecturlink2', /* ns */ 'cinecturlink2',
/* desc */ sprintf(__('delete %s version number'), 'cinecturlink2') /* desc */ sprintf(__('delete %s version number'), 'cinecturlink2')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'plugins', /* type */ 'plugins',
/* action */ 'delete', /* action */ 'delete',
/* ns */ 'cinecturlink2', /* ns */ 'cinecturlink2',
/* description */ sprintf(__('delete %s plugin files'), 'cinecturlink2') /* description */ sprintf(__('delete %s plugin files'), 'cinecturlink2')
); );

View File

@ -1,347 +1,346 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief cinecturlink2, a plugin for Dotclear 2
# This file is part of cinecturlink2, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$core->addBehavior( $core->addBehavior(
'initWidgets', 'initWidgets',
array('cinecturlink2Widget', 'adminLinks') array('cinecturlink2Widget', 'adminLinks')
); );
$core->addBehavior( $core->addBehavior(
'initWidgets', 'initWidgets',
array('cinecturlink2Widget', 'adminCats') array('cinecturlink2Widget', 'adminCats')
); );
class cinecturlink2Widget class cinecturlink2Widget
{ {
public static function adminLinks($w) public static function adminLinks($w)
{ {
global $core; global $core;
$C2 = new cinecturlink2($core); $C2 = new cinecturlink2($core);
$categories_combo = array('' => '', __('Uncategorized') => 'null'); $categories_combo = array('' => '', __('Uncategorized') => 'null');
$categories = $C2->getCategories(); $categories = $C2->getCategories();
while($categories->fetch()) { while($categories->fetch()) {
$cat_title = html::escapeHTML($categories->cat_title); $cat_title = html::escapeHTML($categories->cat_title);
$categories_combo[$cat_title] = $categories->cat_id; $categories_combo[$cat_title] = $categories->cat_id;
} }
$sortby_combo = array( $sortby_combo = array(
__('Update date') => 'link_upddt', __('Update date') => 'link_upddt',
__('My rating') => 'link_note', __('My rating') => 'link_note',
__('Title') => 'link_title', __('Title') => 'link_title',
__('Random') => 'RANDOM', __('Random') => 'RANDOM',
__('Number of views') => 'COUNTER' __('Number of views') => 'COUNTER'
); );
$order_combo = array( $order_combo = array(
__('Ascending') => 'asc', __('Ascending') => 'asc',
__('Descending') => 'desc' __('Descending') => 'desc'
); );
$w->create( $w->create(
'cinecturlink2links', 'cinecturlink2links',
__('My cinecturlink'), __('My cinecturlink'),
array('cinecturlink2Widget', 'publicLinks'), array('cinecturlink2Widget', 'publicLinks'),
'null', 'null',
__('Show selection of cinecturlinks') __('Show selection of cinecturlinks')
); );
$w->cinecturlink2links->setting( $w->cinecturlink2links->setting(
'title', 'title',
__('Title:'), __('Title:'),
__('My cinecturlink'), __('My cinecturlink'),
'text' 'text'
); );
$w->cinecturlink2links->setting( $w->cinecturlink2links->setting(
'category', 'category',
__('Category:'), __('Category:'),
'', '',
'combo', 'combo',
$categories_combo $categories_combo
); );
$w->cinecturlink2links->setting( $w->cinecturlink2links->setting(
'sortby', 'sortby',
__('Order by:'), __('Order by:'),
'link_upddt', 'link_upddt',
'combo', 'combo',
$sortby_combo $sortby_combo
); );
$w->cinecturlink2links->setting( $w->cinecturlink2links->setting(
'sort', 'sort',
__('Sort: (only for date, note and title)'), __('Sort: (only for date, note and title)'),
'desc', 'desc',
'combo', 'combo',
$order_combo $order_combo
); );
$w->cinecturlink2links->setting( $w->cinecturlink2links->setting(
'limit', 'limit',
__('Limit:'), __('Limit:'),
10, 10,
'text' 'text'
); );
$w->cinecturlink2links->setting( $w->cinecturlink2links->setting(
'withlink', 'withlink',
__('Enable link'), __('Enable link'),
1, 1,
'check' 'check'
); );
$w->cinecturlink2links->setting( $w->cinecturlink2links->setting(
'showauthor', 'showauthor',
__('Show author'), __('Show author'),
1, 1,
'check' 'check'
); );
$w->cinecturlink2links->setting( $w->cinecturlink2links->setting(
'shownote', 'shownote',
__('Show my rating'), __('Show my rating'),
0, 0,
'check' 'check'
); );
$w->cinecturlink2links->setting( $w->cinecturlink2links->setting(
'showdesc', 'showdesc',
__('Show description'), __('Show description'),
0, 0,
'check' 'check'
); );
$w->cinecturlink2links->setting( $w->cinecturlink2links->setting(
'showpagelink', 'showpagelink',
__('Show a link to cinecturlink page'), __('Show a link to cinecturlink page'),
0, 0,
'check' 'check'
); );
$w->cinecturlink2links->setting( $w->cinecturlink2links->setting(
'homeonly', 'homeonly',
__('Display on:'), __('Display on:'),
1, 1,
'combo', 'combo',
array( array(
__('All pages') => 0, __('All pages') => 0,
__('Home page only') => 1, __('Home page only') => 1,
__('Except on home page') => 2 __('Except on home page') => 2
) )
); );
} }
public static function adminCats($w) public static function adminCats($w)
{ {
$w->create( $w->create(
'cinecturlink2cats', 'cinecturlink2cats',
__('List of categories of cinecturlink'), __('List of categories of cinecturlink'),
array('cinecturlink2Widget', 'publicCats'), array('cinecturlink2Widget', 'publicCats'),
null, null,
__('List of categories of cinecturlink') __('List of categories of cinecturlink')
); );
$w->cinecturlink2cats->setting( $w->cinecturlink2cats->setting(
'title', 'title',
__('Title:'), __('Title:'),
__('My cinecturlink by categories'), __('My cinecturlink by categories'),
'text' 'text'
); );
$w->cinecturlink2cats->setting( $w->cinecturlink2cats->setting(
'shownumlink', 'shownumlink',
__('Show number of links'), __('Show number of links'),
0, 0,
'check' 'check'
); );
$w->cinecturlink2cats->setting( $w->cinecturlink2cats->setting(
'homeonly', 'homeonly',
__('Display on:'), __('Display on:'),
1, 1,
'combo', 'combo',
array( array(
__('All pages') => 0, __('All pages') => 0,
__('Home page only') => 1, __('Home page only') => 1,
__('Except on home page') => 2 __('Except on home page') => 2
) )
); );
} }
public static function publicLinks($w) public static function publicLinks($w)
{ {
global $core; global $core;
$core->blog->settings->addNamespace('cinecturlink2'); $core->blog->settings->addNamespace('cinecturlink2');
if (!$core->blog->settings->cinecturlink2->cinecturlink2_active if (!$core->blog->settings->cinecturlink2->cinecturlink2_active
|| $w->homeonly == 1 && $core->url->type != 'default' || $w->homeonly == 1 && $core->url->type != 'default'
|| $w->homeonly == 2 && $core->url->type == 'default' || $w->homeonly == 2 && $core->url->type == 'default'
) { ) {
return null; return null;
} }
$C2 = new cinecturlink2($core); $C2 = new cinecturlink2($core);
if ($w->category) { if ($w->category) {
if ($w->category == 'null') { if ($w->category == 'null') {
$params['sql'] = ' AND L.cat_id IS NULL '; $params['sql'] = ' AND L.cat_id IS NULL ';
} }
elseif (is_numeric($w->category)) { elseif (is_numeric($w->category)) {
$params['cat_id'] = (integer) $w->category; $params['cat_id'] = (integer) $w->category;
} }
} }
$limit = abs((integer) $w->limit); $limit = abs((integer) $w->limit);
# Tirage aléatoire # Tirage aléatoire
# Consomme beaucoup de ressources! # Consomme beaucoup de ressources!
if ($w->sortby == 'RANDOM') { if ($w->sortby == 'RANDOM') {
$big_rs = $C2->getLinks($params); $big_rs = $C2->getLinks($params);
if ($big_rs->isEmpty()) { if ($big_rs->isEmpty()) {
return null; return null;
} }
$ids= array(); $ids= array();
while($big_rs->fetch()) { while($big_rs->fetch()) {
$ids[] = $big_rs->link_id; $ids[] = $big_rs->link_id;
} }
shuffle($ids); shuffle($ids);
$ids = array_slice($ids, 0, $limit); $ids = array_slice($ids, 0, $limit);
$params['link_id'] = array(); $params['link_id'] = array();
foreach($ids as $id) { foreach($ids as $id) {
$params['link_id'][] = $id; $params['link_id'][] = $id;
} }
} }
elseif ($w->sortby == 'COUNTER') { elseif ($w->sortby == 'COUNTER') {
$params['order'] = 'link_count asc'; $params['order'] = 'link_count asc';
$params['limit'] = $limit; $params['limit'] = $limit;
} }
else { else {
$params['order'] = $w->sortby; $params['order'] = $w->sortby;
$params['order'] .= $w->sort == 'asc' ? ' asc' : ' desc'; $params['order'] .= $w->sort == 'asc' ? ' asc' : ' desc';
$params['limit'] = $limit; $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; $widthmax = (integer) $core->blog->settings->cinecturlink2->cinecturlink2_widthmax;
$style = $widthmax ? ' style="width:'.$widthmax.'px;"' : ''; $style = $widthmax ? ' style="width:'.$widthmax.'px;"' : '';
$entries = array(); $entries = array();
while($rs->fetch()) { while($rs->fetch()) {
$url = $rs->link_url; $url = $rs->link_url;
$img = $rs->link_img; $img = $rs->link_img;
$title = html::escapeHTML($rs->link_title); $title = html::escapeHTML($rs->link_title);
$author = html::escapeHTML($rs->link_author); $author = html::escapeHTML($rs->link_author);
$cat = html::escapeHTML($rs->cat_title); $cat = html::escapeHTML($rs->cat_title);
$note = $w->shownote ? ' <em>('.$rs->link_note.'/20)</em>' : ''; $note = $w->shownote ? ' <em>('.$rs->link_note.'/20)</em>' : '';
$desc = $w->showdesc ? '<br /><em>'.html::escapeHTML($rs->link_desc).'</em>' : ''; $desc = $w->showdesc ? '<br /><em>'.html::escapeHTML($rs->link_desc).'</em>' : '';
$lang = $rs->link_lang ? ' hreflang="'.$rs->link_lang.'"' : ''; $lang = $rs->link_lang ? ' hreflang="'.$rs->link_lang.'"' : '';
$count = abs((integer) $rs->link_count); $count = abs((integer) $rs->link_count);
# --BEHAVIOR-- cinecturlink2WidgetLinks # --BEHAVIOR-- cinecturlink2WidgetLinks
$bhv = $core->callBehavior('cinecturlink2WidgetLinks', $rs->link_id); $bhv = $core->callBehavior('cinecturlink2WidgetLinks', $rs->link_id);
$entries[] = $entries[] =
'<p style="text-align:center;">'. '<p style="text-align:center;">'.
($w->withlink && !empty($url) ? '<a href="'.$url.'"'.$lang.' title="'.$cat.'">' : ''). ($w->withlink && !empty($url) ? '<a href="'.$url.'"'.$lang.' title="'.$cat.'">' : '').
'<strong>'.$title.'</strong>'.$note.'<br />'. '<strong>'.$title.'</strong>'.$note.'<br />'.
($w->showauthor ? $author.'<br />' : '').'<br />'. ($w->showauthor ? $author.'<br />' : '').'<br />'.
'<img src="'.$img.'" alt="'.$title.' - '.$author.'"'.$style.' />'. '<img src="'.$img.'" alt="'.$title.' - '.$author.'"'.$style.' />'.
$desc. $desc.
($w->withlink && !empty($url) ? '</a>' : ''). ($w->withlink && !empty($url) ? '</a>' : '').
'</p>'.$bhv; '</p>'.$bhv;
try { try {
$cur = $core->con->openCursor($C2->table); $cur = $core->con->openCursor($C2->table);
$cur->link_count = ($count + 1); $cur->link_count = ($count + 1);
$C2->updLink($rs->link_id, $cur, false); $C2->updLink($rs->link_id, $cur, false);
} }
catch (Exception $e) { catch (Exception $e) {
} }
} }
# Tirage aléatoire # Tirage aléatoire
if ($w->sortby == 'RANDOM' if ($w->sortby == 'RANDOM'
|| $w->sortby == 'COUNTER' || $w->sortby == 'COUNTER'
) { ) {
shuffle($entries); shuffle($entries);
if ($core->blog->settings->cinecturlink2->cinecturlink2_triggeronrandom) { if ($core->blog->settings->cinecturlink2->cinecturlink2_triggeronrandom) {
$core->blog->triggerBlog(); $core->blog->triggerBlog();
} }
} }
return return
'<div class="cinecturlink2list">'. '<div class="cinecturlink2list">'.
($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
implode(' ',$entries). implode(' ',$entries).
($w->showpagelink && $core->blog->settings->cinecturlink2->cinecturlink2_public_active ? ($w->showpagelink && $core->blog->settings->cinecturlink2->cinecturlink2_public_active ?
'<p><a href="'.$core->blog->url.$core->url->getBase('cinecturlink2').'" title="'.__('view all links').'">'.__('More links').'</a></p>' : '' '<p><a href="'.$core->blog->url.$core->url->getBase('cinecturlink2').'" title="'.__('view all links').'">'.__('More links').'</a></p>' : ''
). ).
'</div>'; '</div>';
} }
public static function publicCats($w) public static function publicCats($w)
{ {
global $core; global $core;
$core->blog->settings->addNamespace('cinecturlink2'); $core->blog->settings->addNamespace('cinecturlink2');
if (!$core->blog->settings->cinecturlink2->cinecturlink2_active if (!$core->blog->settings->cinecturlink2->cinecturlink2_active
|| !$core->blog->settings->cinecturlink2->cinecturlink2_public_active || !$core->blog->settings->cinecturlink2->cinecturlink2_public_active
|| $w->homeonly == 1 && $core->url->type != 'default' || $w->homeonly == 1 && $core->url->type != 'default'
|| $w->homeonly == 2 && $core->url->type == 'default' || $w->homeonly == 2 && $core->url->type == 'default'
) { ) {
return null; 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 = $res =
'<li><a href="'. '<li><a href="'.
$core->blog->url.$core->url->getBase('cinecturlink2'). $core->blog->url.$core->url->getBase('cinecturlink2').
'" title="'.__('view all links').'">'.__('all links'). '" title="'.__('view all links').'">'.__('all links').
'</a>'; '</a>';
if ($w->shownumlink) { if ($w->shownumlink) {
$res .= ' ('.($C2->getLinks(array(), true)->f(0)).')'; $res .= ' ('.($C2->getLinks(array(), true)->f(0)).')';
} }
$res .= '</li>'; $res .= '</li>';
while($rs->fetch()) { while($rs->fetch()) {
$res .= $res .=
'<li><a href="'. '<li><a href="'.
$core->blog->url.$core->url->getBase('cinecturlink2').'/'.$core->blog->settings->cinecturlink2->cinecturlink2_public_caturl.'/'.urlencode($rs->cat_title). $core->blog->url.$core->url->getBase('cinecturlink2').'/'.$core->blog->settings->cinecturlink2->cinecturlink2_public_caturl.'/'.urlencode($rs->cat_title).
'" title="'.__('view links of this category').'">'. '" title="'.__('view links of this category').'">'.
html::escapeHTML($rs->cat_title). html::escapeHTML($rs->cat_title).
'</a>'; '</a>';
if ($w->shownumlink) { if ($w->shownumlink) {
$res .= ' ('.($C2->getLinks(array('cat_id'=>$rs->cat_id), true)->f(0)).')'; $res .= ' ('.($C2->getLinks(array('cat_id'=>$rs->cat_id), true)->f(0)).')';
} }
$res .= '</li>'; $res .= '</li>';
} }
return return
'<div class="cinecturlink2cat">'. '<div class="cinecturlink2cat">'.
($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
'<ul>'.$res.'</ul>'. '<ul>'.$res.'</ul>'.
'</div>'; '</div>';
} }
} }

12
dcstore.xml Normal file
View File

@ -0,0 +1,12 @@
<modules xmlns:da="http://dotaddict.org/da/">
<module id="cinecturlink2">
<name>Cinecturlink 2</name>
<version>0.7.1</version>
<author>Jean-Christian Denis and Contributors</author>
<desc>Widgets and pages about books, musics, films, blogs you are interested in</desc>
<file>https://github.com/JcDenis/cinecturlink2/releases/download/v0.7.1/plugin-cinecturlink2.zip</file>
<da:dcmin>2.19</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/cinecturlink2</da:details>
<da:support>https://github.com/JcDenis/cinecturlink2</da:support>
</module>
</modules>

View File

@ -1,20 +1,19 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief cinecturlink2, a plugin for Dotclear 2
# This file is part of cinecturlink2, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
/** /**
@ -24,443 +23,443 @@ if (!defined('DC_RC_PATH')) {
*/ */
class cinecturlink2 class cinecturlink2
{ {
/** @var dcCore dcCore instance */ /** @var dcCore dcCore instance */
public $core; public $core;
/** @var dbLayer dbLayer instance */ /** @var dbLayer dbLayer instance */
public $con; public $con;
/** @var string Cinecturlink table name */ /** @var string Cinecturlink table name */
public $table; public $table;
/** @var string Blog ID */ /** @var string Blog ID */
public $blog; public $blog;
/** /**
* Contructor * Contructor
* *
* @param dcCore $core dcCore instance * @param dcCore $core dcCore instance
*/ */
public function __construct(dcCore $core) public function __construct(dcCore $core)
{ {
$core->blog->settings->addNamespace('cinecturlink2'); $core->blog->settings->addNamespace('cinecturlink2');
$this->core = $core; $this->core = $core;
$this->con = $core->con; $this->con = $core->con;
$this->table = $core->prefix.'cinecturlink2'; $this->table = $core->prefix.'cinecturlink2';
$this->blog = $core->con->escape($core->blog->id); $this->blog = $core->con->escape($core->blog->id);
} }
/** /**
* Get links * Get links
* *
* @param array $params Query params * @param array $params Query params
* @param boolean $count_only Count only result * @param boolean $count_only Count only result
* @return record record instance * @return record record instance
*/ */
public function getLinks($params=array(), $count_only=false) public function getLinks($params=array(), $count_only=false)
{ {
if ($count_only) { if ($count_only) {
$strReq = 'SELECT count(L.link_id) '; $strReq = 'SELECT count(L.link_id) ';
} }
else { else {
$content_req = ''; $content_req = '';
if (!empty($params['columns']) && is_array($params['columns'])) { if (!empty($params['columns']) && is_array($params['columns'])) {
$content_req .= implode(', ', $params['columns']).', '; $content_req .= implode(', ', $params['columns']).', ';
} }
$strReq = $strReq =
'SELECT L.link_id, L.blog_id, L.cat_id, L.user_id, L.link_type, '. 'SELECT L.link_id, L.blog_id, L.cat_id, L.user_id, L.link_type, '.
$content_req. $content_req.
'L.link_creadt, L.link_upddt, L.link_note, L.link_count, '. 'L.link_creadt, L.link_upddt, L.link_note, L.link_count, '.
'L.link_title, L.link_desc, L.link_author, '. 'L.link_title, L.link_desc, L.link_author, '.
'L.link_lang, L.link_url, L.link_img, '. 'L.link_lang, L.link_url, L.link_img, '.
'U.user_name, U.user_firstname, U.user_displayname, U.user_email, '. 'U.user_name, U.user_firstname, U.user_displayname, U.user_email, '.
'U.user_url, '. 'U.user_url, '.
'C.cat_title, C.cat_desc '; 'C.cat_title, C.cat_desc ';
} }
$strReq .= $strReq .=
'FROM '.$this->table.' L '. 'FROM '.$this->table.' L '.
'INNER JOIN '.$this->core->prefix.'user U ON U.user_id = L.user_id '. '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 '; 'LEFT OUTER JOIN '.$this->table.'_cat C ON L.cat_id = C.cat_id ';
if (!empty($params['from'])) { if (!empty($params['from'])) {
$strReq .= $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 (isset($params['link_type'])) {
if (is_array($params['link_type']) && !empty($params['link_type'])) { if (is_array($params['link_type']) && !empty($params['link_type'])) {
$strReq .= 'AND L.link_type '.$this->con->in($params['link_type']); $strReq .= 'AND L.link_type '.$this->con->in($params['link_type']);
} }
elseif ($params['link_type'] != '') { elseif ($params['link_type'] != '') {
$strReq .= "AND L.link_type = '".$this->con->escape($params['link_type'])."' "; $strReq .= "AND L.link_type = '".$this->con->escape($params['link_type'])."' ";
} }
} }
else { else {
$strReq .= "AND L.link_type = 'cinecturlink' "; $strReq .= "AND L.link_type = 'cinecturlink' ";
} }
if (!empty($params['link_id'])) { if (!empty($params['link_id'])) {
if (is_array($params['link_id'])) { if (is_array($params['link_id'])) {
array_walk($params['link_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}')); array_walk($params['link_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}'));
} }
else { else {
$params['link_id'] = array((integer) $params['link_id']); $params['link_id'] = array((integer) $params['link_id']);
} }
$strReq .= 'AND L.link_id '.$this->con->in($params['link_id']); $strReq .= 'AND L.link_id '.$this->con->in($params['link_id']);
} }
if (!empty($params['cat_id'])) { if (!empty($params['cat_id'])) {
if (is_array($params['cat_id'])) { if (is_array($params['cat_id'])) {
array_walk($params['cat_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}')); array_walk($params['cat_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}'));
} }
else { else {
$params['cat_id'] = array((integer) $params['cat_id']); $params['cat_id'] = array((integer) $params['cat_id']);
} }
$strReq .= 'AND L.cat_id '.$this->con->in($params['cat_id']); $strReq .= 'AND L.cat_id '.$this->con->in($params['cat_id']);
} }
if (!empty($params['cat_title'])) { if (!empty($params['cat_title'])) {
$strReq .= "AND C.cat_title = '".$this->con->escape($params['cat_title'])."' "; $strReq .= "AND C.cat_title = '".$this->con->escape($params['cat_title'])."' ";
} }
if (!empty($params['link_title'])) { if (!empty($params['link_title'])) {
$strReq .= "AND L.link_title = '".$this->con->escape($params['link_title'])."' "; $strReq .= "AND L.link_title = '".$this->con->escape($params['link_title'])."' ";
} }
if (!empty($params['link_lang'])) { if (!empty($params['link_lang'])) {
$strReq .= "AND L.link_lang = '".$this->con->escape($params['link_lang'])."' "; $strReq .= "AND L.link_lang = '".$this->con->escape($params['link_lang'])."' ";
} }
if (!empty($params['sql'])) { if (!empty($params['sql'])) {
$strReq .= $params['sql'].' '; $strReq .= $params['sql'].' ';
} }
if (!$count_only) { if (!$count_only) {
if (!empty($params['order'])) { if (!empty($params['order'])) {
$strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' ';
} }
else { else {
$strReq .= 'ORDER BY L.link_upddt DESC '; $strReq .= 'ORDER BY L.link_upddt DESC ';
} }
} }
if (!$count_only && !empty($params['limit'])) { if (!$count_only && !empty($params['limit'])) {
$strReq .= $this->con->limit($params['limit']); $strReq .= $this->con->limit($params['limit']);
} }
return $this->con->select($strReq); return $this->con->select($strReq);
} }
/** /**
* Add link * Add link
* *
* @param cursor $cur cursor instance * @param cursor $cur cursor instance
*/ */
public function addLink(cursor $cur) public function addLink(cursor $cur)
{ {
$this->con->writeLock($this->table); $this->con->writeLock($this->table);
try { try {
if ($cur->link_title == '') { if ($cur->link_title == '') {
throw new Exception(__('No link title')); throw new Exception(__('No link title'));
} }
if ($cur->link_desc == '') { if ($cur->link_desc == '') {
throw new Exception(__('No link description')); throw new Exception(__('No link description'));
} }
if ('' == $cur->link_note) { if ('' == $cur->link_note) {
$cur->link_note = 10; $cur->link_note = 10;
} }
if (0 > $cur->link_note || $cur->link_note > 20) { if (0 > $cur->link_note || $cur->link_note > 20) {
$cur->link_note = 10; $cur->link_note = 10;
} }
$cur->link_id = $this->getNextLinkId(); $cur->link_id = $this->getNextLinkId();
$cur->blog_id = $this->blog; $cur->blog_id = $this->blog;
$cur->user_id = $this->core->auth->userID(); $cur->user_id = $this->core->auth->userID();
$cur->link_creadt = date('Y-m-d H:i:s'); $cur->link_creadt = date('Y-m-d H:i:s');
$cur->link_upddt = date('Y-m-d H:i:s'); $cur->link_upddt = date('Y-m-d H:i:s');
$cur->link_pos = 0; $cur->link_pos = 0;
$cur->link_count = 0; $cur->link_count = 0;
$cur->insert(); $cur->insert();
$this->con->unlock(); $this->con->unlock();
} }
catch (Exception $e) { catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
$this->trigger(); $this->trigger();
# --BEHAVIOR-- cinecturlink2AfterAddLink # --BEHAVIOR-- cinecturlink2AfterAddLink
$this->core->callBehavior('cinecturlink2AfterAddLink', $cur); $this->core->callBehavior('cinecturlink2AfterAddLink', $cur);
return $cur->link_id; return $cur->link_id;
} }
/** /**
* Update link * Update link
* *
* @param integer $id Link ID * @param integer $id Link ID
* @param cursor $cur cursor instance * @param cursor $cur cursor instance
* @param boolean $behavior Call related behaviors * @param boolean $behavior Call related behaviors
*/ */
public function updLink($id, cursor $cur, $behavior=true) public function updLink($id, cursor $cur, $behavior=true)
{ {
$id = (integer) $id; $id = (integer) $id;
if (empty($id)) { if (empty($id)) {
throw new Exception(__('No such link ID')); throw new Exception(__('No such link ID'));
} }
$cur->link_upddt = date('Y-m-d H:i:s'); $cur->link_upddt = date('Y-m-d H:i:s');
$cur->update("WHERE link_id = ".$id." AND blog_id = '".$this->blog."' "); $cur->update("WHERE link_id = ".$id." AND blog_id = '".$this->blog."' ");
$this->trigger(); $this->trigger();
if ($behavior) { if ($behavior) {
# --BEHAVIOR-- cinecturlink2AfterUpdLink # --BEHAVIOR-- cinecturlink2AfterUpdLink
$this->core->callBehavior('cinecturlink2AfterUpdLink', $cur, $id); $this->core->callBehavior('cinecturlink2AfterUpdLink', $cur, $id);
} }
} }
/** /**
* Delete link * Delete link
* *
* @param integer $id Link ID * @param integer $id Link ID
*/ */
public function delLink($id) public function delLink($id)
{ {
$id = (integer) $id; $id = (integer) $id;
if (empty($id)) { if (empty($id)) {
throw new Exception(__('No such link ID')); throw new Exception(__('No such link ID'));
} }
# --BEHAVIOR-- cinecturlink2BeforeDelLink # --BEHAVIOR-- cinecturlink2BeforeDelLink
$this->core->callBehavior('cinecturlink2BeforeDelLink', $id); $this->core->callBehavior('cinecturlink2BeforeDelLink', $id);
$this->con->execute( $this->con->execute(
'DELETE FROM '.$this->table.' '. 'DELETE FROM '.$this->table.' '.
'WHERE link_id = '.$id.' '. 'WHERE link_id = '.$id.' '.
"AND blog_id = '".$this->blog."' " "AND blog_id = '".$this->blog."' "
); );
$this->trigger(); $this->trigger();
} }
/** /**
* Get next link ID * Get next link ID
* *
* @return integer Next link ID * @return integer Next link ID
*/ */
private function getNextLinkId() private function getNextLinkId()
{ {
return $this->con->select( return $this->con->select(
'SELECT MAX(link_id) FROM '.$this->table.' ' 'SELECT MAX(link_id) FROM '.$this->table.' '
)->f(0) + 1; )->f(0) + 1;
} }
/** /**
* Get categories * Get categories
* *
* @param array $params Query params * @param array $params Query params
* @param boolean $count_only Count only result * @param boolean $count_only Count only result
* @return record record instance * @return record record instance
*/ */
public function getCategories($params=array(), $count_only=false) public function getCategories($params=array(), $count_only=false)
{ {
if ($count_only) { if ($count_only) {
$strReq = 'SELECT count(C.cat_id) '; $strReq = 'SELECT count(C.cat_id) ';
} }
else { else {
$content_req = ''; $content_req = '';
if (!empty($params['columns']) && is_array($params['columns'])) { if (!empty($params['columns']) && is_array($params['columns'])) {
$content_req .= implode(', ', $params['columns']).', '; $content_req .= implode(', ', $params['columns']).', ';
} }
$strReq = $strReq =
'SELECT C.cat_id, C.blog_id, C.cat_title, C.cat_desc, '. 'SELECT C.cat_id, C.blog_id, C.cat_title, C.cat_desc, '.
$content_req. $content_req.
'C.cat_pos, C.cat_creadt, C.cat_upddt '; 'C.cat_pos, C.cat_creadt, C.cat_upddt ';
} }
$strReq .= 'FROM '.$this->table.'_cat C '; $strReq .= 'FROM '.$this->table.'_cat C ';
if (!empty($params['from'])) { if (!empty($params['from'])) {
$strReq .= $params['from'].' '; $strReq .= $params['from'].' ';
} }
$strReq .= "WHERE C.blog_id = '".$this->blog."' "; $strReq .= "WHERE C.blog_id = '".$this->blog."' ";
if (!empty($params['cat_id'])) { if (!empty($params['cat_id'])) {
if (is_array($params['cat_id'])) { if (is_array($params['cat_id'])) {
array_walk($params['cat_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}')); array_walk($params['cat_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}'));
} }
else { else {
$params['cat_id'] = array((integer) $params['cat_id']); $params['cat_id'] = array((integer) $params['cat_id']);
} }
$strReq .= 'AND C.cat_id '.$this->con->in($params['cat_id']); $strReq .= 'AND C.cat_id '.$this->con->in($params['cat_id']);
} }
if (!empty($params['cat_title'])) { if (!empty($params['cat_title'])) {
$strReq .= "AND C.cat_title = '".$this->con->escape($params['cat_title'])."' "; $strReq .= "AND C.cat_title = '".$this->con->escape($params['cat_title'])."' ";
} }
if (!empty($params['sql'])) { if (!empty($params['sql'])) {
$strReq .= $params['sql'].' '; $strReq .= $params['sql'].' ';
} }
if (!$count_only) { if (!$count_only) {
if (!empty($params['order'])) { if (!empty($params['order'])) {
$strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' ';
} }
else { else {
$strReq .= 'ORDER BY cat_pos ASC '; $strReq .= 'ORDER BY cat_pos ASC ';
} }
} }
if (!$count_only && !empty($params['limit'])) { if (!$count_only && !empty($params['limit'])) {
$strReq .= $this->con->limit($params['limit']); $strReq .= $this->con->limit($params['limit']);
} }
return $this->con->select($strReq); return $this->con->select($strReq);
} }
/** /**
* Add category * Add category
* *
* @param cursor $cur cursor instance * @param cursor $cur cursor instance
* @return integer New category ID * @return integer New category ID
*/ */
public function addCategory(cursor $cur) public function addCategory(cursor $cur)
{ {
$this->con->writeLock($this->table.'_cat'); $this->con->writeLock($this->table.'_cat');
try { try {
if ($cur->cat_title == '') { if ($cur->cat_title == '') {
throw new Exception(__('No category title')); throw new Exception(__('No category title'));
} }
if ($cur->cat_desc == '') { if ($cur->cat_desc == '') {
throw new Exception(__('No category description')); throw new Exception(__('No category description'));
} }
$cur->cat_id = $this->getNextCatId(); $cur->cat_id = $this->getNextCatId();
$cur->cat_pos = $this->getNextCatPos(); $cur->cat_pos = $this->getNextCatPos();
$cur->blog_id = $this->blog; $cur->blog_id = $this->blog;
$cur->cat_creadt = date('Y-m-d H:i:s'); $cur->cat_creadt = date('Y-m-d H:i:s');
$cur->cat_upddt = date('Y-m-d H:i:s'); $cur->cat_upddt = date('Y-m-d H:i:s');
$cur->insert(); $cur->insert();
$this->con->unlock(); $this->con->unlock();
} }
catch (Exception $e) { catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
$this->trigger(); $this->trigger();
return $cur->cat_id; return $cur->cat_id;
} }
/** /**
* Update category * Update category
* *
* @param integer $id Category ID * @param integer $id Category ID
* @param cursor $cur cursor instance * @param cursor $cur cursor instance
*/ */
public function updCategory($id, cursor $cur) public function updCategory($id, cursor $cur)
{ {
$id = (integer) $id; $id = (integer) $id;
if (empty($id)) { if (empty($id)) {
throw new Exception(__('No such category ID')); throw new Exception(__('No such category ID'));
} }
$cur->cat_upddt = date('Y-m-d H:i:s'); $cur->cat_upddt = date('Y-m-d H:i:s');
$cur->update("WHERE cat_id = ".$id." AND blog_id = '".$this->blog."' "); $cur->update("WHERE cat_id = ".$id." AND blog_id = '".$this->blog."' ");
$this->trigger(); $this->trigger();
} }
/** /**
* Delete category * Delete category
* *
* @param integer $id Category ID * @param integer $id Category ID
*/ */
public function delCategory($id) public function delCategory($id)
{ {
$id = (integer) $id; $id = (integer) $id;
if (empty($id)) { if (empty($id)) {
throw new Exception(__('No such category ID')); throw new Exception(__('No such category ID'));
} }
$this->con->execute( $this->con->execute(
'DELETE FROM '.$this->table.'_cat '. 'DELETE FROM '.$this->table.'_cat '.
'WHERE cat_id = '.$id.' '. 'WHERE cat_id = '.$id.' '.
"AND blog_id = '".$this->blog."' " "AND blog_id = '".$this->blog."' "
); );
# Update link cat to NULL # Update link cat to NULL
$cur = $this->con->openCursor($this->table); $cur = $this->con->openCursor($this->table);
$cur->cat_id = NULL; $cur->cat_id = NULL;
$cur->link_upddt = date('Y-m-d H:i:s'); $cur->link_upddt = date('Y-m-d H:i:s');
$cur->update("WHERE cat_id = ".$id." AND blog_id = '".$this->blog."' "); $cur->update("WHERE cat_id = ".$id." AND blog_id = '".$this->blog."' ");
$this->trigger(); $this->trigger();
} }
/** /**
* Get next category ID * Get next category ID
* *
* @return integer Next category ID * @return integer Next category ID
*/ */
private function getNextCatId() private function getNextCatId()
{ {
return $this->con->select( return $this->con->select(
'SELECT MAX(cat_id) FROM '.$this->table.'_cat ' 'SELECT MAX(cat_id) FROM '.$this->table.'_cat '
)->f(0) + 1; )->f(0) + 1;
} }
/** /**
* Get next category position * Get next category position
* *
* @return integer Next category position * @return integer Next category position
*/ */
private function getNextCatPos() private function getNextCatPos()
{ {
return $this->con->select( return $this->con->select(
'SELECT MAX(cat_pos) FROM '.$this->table.'_cat '. 'SELECT MAX(cat_pos) FROM '.$this->table.'_cat '.
"WHERE blog_id = '".$this->blog."' " "WHERE blog_id = '".$this->blog."' "
)->f(0) + 1; )->f(0) + 1;
} }
/** /**
* Trigger event * Trigger event
*/ */
private function trigger() private function trigger()
{ {
$this->core->blog->triggerBlog(); $this->core->blog->triggerBlog();
} }
/** /**
* Check if a directory exists and is writable * Check if a directory exists and is writable
* *
* @param string $root Root * @param string $root Root
* @param string $folder Folder to create into root folder * @param string $folder Folder to create into root folder
* @param boolean $throw Throw exception or not * @param boolean $throw Throw exception or not
* @return boolean True if exists and writable * @return boolean True if exists and writable
*/ */
public static function test_folder($root, $folder, $throw=false) public static function test_folder($root, $folder, $throw=false)
{ {
if (!is_dir($root.'/'.$folder)) { if (!is_dir($root.'/'.$folder)) {
if (!is_dir($root) || !is_writable($root) || !mkdir($root.'/'.$folder)) { if (!is_dir($root) || !is_writable($root) || !mkdir($root.'/'.$folder)) {
if ($throw) { if ($throw) {
throw new Exception(__('Failed to create public folder for images.')); throw new Exception(__('Failed to create public folder for images.'));
} }
return false; return false;
} }
} }
return true; return true;
} }
} }

View File

@ -1,117 +1,116 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief cinecturlink2, a plugin for Dotclear 2
# This file is part of cinecturlink2, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
class cinecturlink2Context class cinecturlink2Context
{ {
public static function PaginationNbPages() public static function PaginationNbPages()
{ {
global $_ctx; global $_ctx;
if ($_ctx->c2_pagination === null) { if ($_ctx->c2_pagination === null) {
return false; return false;
} }
$nb_posts = $_ctx->c2_pagination->f(0); $nb_posts = $_ctx->c2_pagination->f(0);
$nb_per_page = $_ctx->c2_params['limit'][1]; $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) public static function PaginationPosition($offset=0)
{ {
if (isset($GLOBALS['c2_page_number'])) { if (isset($GLOBALS['c2_page_number'])) {
$p = $GLOBALS['c2_page_number']; $p = $GLOBALS['c2_page_number'];
} }
else { else {
$p = 1; $p = 1;
} }
$p = $p+$offset; $p = $p+$offset;
$n = self::PaginationNbPages(); $n = self::PaginationNbPages();
if (!$n) { if (!$n) {
return $p; return $p;
} }
return $p > $n || $p <= 0 ? 1 : $p; return $p > $n || $p <= 0 ? 1 : $p;
} }
public static function PaginationStart() public static function PaginationStart()
{ {
if (isset($GLOBALS['c2_page_number'])) { if (isset($GLOBALS['c2_page_number'])) {
return self::PaginationPosition() == 1; return self::PaginationPosition() == 1;
} }
return true; return true;
} }
public static function PaginationEnd() public static function PaginationEnd()
{ {
if (isset($GLOBALS['c2_page_number'])) { if (isset($GLOBALS['c2_page_number'])) {
return self::PaginationPosition() == self::PaginationNbPages(); return self::PaginationPosition() == self::PaginationNbPages();
} }
return false; return false;
} }
public static function PaginationURL($offset=0) public static function PaginationURL($offset=0)
{ {
$args = $_SERVER['URL_REQUEST_PART']; $args = $_SERVER['URL_REQUEST_PART'];
$n = self::PaginationPosition($offset); $n = self::PaginationPosition($offset);
$args = preg_replace('#(^|/)c2page/([0-9]+)$#', '', $args); $args = preg_replace('#(^|/)c2page/([0-9]+)$#', '', $args);
$url = $GLOBALS['core']->blog->url.$args; $url = $GLOBALS['core']->blog->url.$args;
if ($n > 1) { if ($n > 1) {
$url = preg_replace('#/$#','',$url); $url = preg_replace('#/$#','',$url);
$url .= '/c2page/'.$n; $url .= '/c2page/'.$n;
} }
# If search param # If search param
if (!empty($_GET['q'])) { if (!empty($_GET['q'])) {
$s = strpos($url,'?') !== false ? '&amp;' : '?'; $s = strpos($url,'?') !== false ? '&amp;' : '?';
$url .= $s.'q='.rawurlencode($_GET['q']); $url .= $s.'q='.rawurlencode($_GET['q']);
} }
return $url; return $url;
} }
public static function categoryCurrent() public static function categoryCurrent()
{ {
global $_ctx; global $_ctx;
if (!isset($_ctx->c2_page_params['cat_id']) && !isset($_ctx->c2_page_params['cat_title'])) { if (!isset($_ctx->c2_page_params['cat_id']) && !isset($_ctx->c2_page_params['cat_title'])) {
return false; return false;
} }
if (isset($_ctx->c2_page_params['cat_id']) && $_ctx->c2_page_params['cat_id'] == $_ctx->c2_categories->cat_id) { if (isset($_ctx->c2_page_params['cat_id']) && $_ctx->c2_page_params['cat_id'] == $_ctx->c2_categories->cat_id) {
return true; 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_title']) && $_ctx->c2_page_params['cat_title'] == $_ctx->c2_categories->cat_title) {
return true; return true;
} }
return false; return false;
} }
} }

View File

@ -1,102 +1,101 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief cinecturlink2, a plugin for Dotclear 2
# This file is part of cinecturlink2, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
class adminlistCinecturlink2 extends adminGenericList class adminlistCinecturlink2 extends adminGenericList
{ {
public function display($page, $nb_per_page, $url) public function display($page, $nb_per_page, $url)
{ {
if ($this->rs->isEmpty()) { if ($this->rs->isEmpty()) {
echo '<p><strong>'.__('There is no link').'</strong></p>'; echo '<p><strong>'.__('There is no link').'</strong></p>';
} }
else { else {
$pager = new pager($page, $this->rs_count, $nb_per_page,10); $pager = new pager($page, $this->rs_count, $nb_per_page,10);
$pager->base_url = $url; $pager->base_url = $url;
$html_block = $html_block =
'<table class="clear">'. '<table class="clear">'.
'<thead>'. '<thead>'.
'<tr>'. '<tr>'.
'<th class="nowrap" colspan="2">'.__('Title').'</th>'. '<th class="nowrap" colspan="2">'.__('Title').'</th>'.
'<th class="nowrap">'.__('Author').'</th>'. '<th class="nowrap">'.__('Author').'</th>'.
'<th class="maximal">'.__('Description').'</th>'. '<th class="maximal">'.__('Description').'</th>'.
'<th class="maximal">'.__('Links').'</th>'. '<th class="maximal">'.__('Links').'</th>'.
'<th class="nowrap">'.__('Category').'</th>'. '<th class="nowrap">'.__('Category').'</th>'.
'<th class="nowrap">'.__('My rating').'</th>'. '<th class="nowrap">'.__('My rating').'</th>'.
'<th class="nowrap">'.__('Date').'</th>'. '<th class="nowrap">'.__('Date').'</th>'.
'</tr>'. '</tr>'.
'</thead>'. '</thead>'.
'<tbody>%s</tbody>'. '<tbody>%s</tbody>'.
'</table>'; '</table>';
echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>';
$blocks = explode('%s',$html_block); $blocks = explode('%s',$html_block);
echo $blocks[0]; echo $blocks[0];
$this->rs->index(((integer)$page - 1) * $nb_per_page); $this->rs->index(((integer)$page - 1) * $nb_per_page);
$iter = 0; $iter = 0;
while ($iter < $nb_per_page) { while ($iter < $nb_per_page) {
echo $this->linkLine($url,$iter); echo $this->linkLine($url,$iter);
if ($this->rs->isEnd()) if ($this->rs->isEnd())
break; break;
else else
$this->rs->moveNext(); $this->rs->moveNext();
$iter++; $iter++;
} }
echo $blocks[1]; echo $blocks[1];
echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>';
} }
} }
private function linkLine($url, $loop) private function linkLine($url, $loop)
{ {
return return
'<tr class="line">'."\n". '<tr class="line">'."\n".
'<td class="nowrap">'. '<td class="nowrap">'.
form::checkbox(array('links[]'), $this->rs->link_id, 0). form::checkbox(array('links[]'), $this->rs->link_id, 0).
'</td>'. '</td>'.
'<td class="nowrap">'. '<td class="nowrap">'.
'<a href="plugin.php?p=cinecturlink2&amp;link_id='.$this->rs->link_id.'#newlink" title="'.__('Edit').'">'. '<a href="plugin.php?p=cinecturlink2&amp;link_id='.$this->rs->link_id.'#newlink" title="'.__('Edit').'">'.
html::escapeHTML($this->rs->link_title). html::escapeHTML($this->rs->link_title).
'</a>'. '</a>'.
"</td>\n". "</td>\n".
'<td class="nowrap">'. '<td class="nowrap">'.
html::escapeHTML($this->rs->link_author). html::escapeHTML($this->rs->link_author).
"</td>\n". "</td>\n".
'<td class="maximal">'. '<td class="maximal">'.
html::escapeHTML($this->rs->link_desc). html::escapeHTML($this->rs->link_desc).
"</td>\n". "</td>\n".
'<td class="nowrap">'. '<td class="nowrap">'.
'<a href="'.$this->rs->link_url.'" title="'.html::escapeHTML($this->rs->link_url).'">'.__('URL').'</a> '. '<a href="'.$this->rs->link_url.'" title="'.html::escapeHTML($this->rs->link_url).'">'.__('URL').'</a> '.
'<a href="'.$this->rs->link_img.'" title="'.html::escapeHTML($this->rs->link_img).'">'.__('image').'</a> '. '<a href="'.$this->rs->link_img.'" title="'.html::escapeHTML($this->rs->link_img).'">'.__('image').'</a> '.
"</td>\n". "</td>\n".
'<td class="nowrap">'. '<td class="nowrap">'.
html::escapeHTML($this->rs->cat_title). html::escapeHTML($this->rs->cat_title).
"</td>\n". "</td>\n".
'<td class="nowrap">'. '<td class="nowrap">'.
html::escapeHTML($this->rs->link_note).'/20'. html::escapeHTML($this->rs->link_note).'/20'.
"</td>\n". "</td>\n".
'<td class="nowrap">'. '<td class="nowrap">'.
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')). 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')).
"</td>\n". "</td>\n".
'</tr>'."\n"; '</tr>'."\n";
} }
} }

View File

@ -1,44 +1,43 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief cinecturlink2, a plugin for Dotclear 2
# This file is part of cinecturlink2, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
class sitemapsCinecturlink2 class sitemapsCinecturlink2
{ {
public static function sitemapsDefineParts($map_parts) public static function sitemapsDefineParts($map_parts)
{ {
$map_parts->offsetSet(__('Cinecturlink'), 'cinecturlink2'); $map_parts->offsetSet(__('Cinecturlink'), 'cinecturlink2');
} }
public static function sitemapsURLsCollect($sitemaps) public static function sitemapsURLsCollect($sitemaps)
{ {
global $core; global $core;
$core->blog->settings->addNamespace('sitemaps'); $core->blog->settings->addNamespace('sitemaps');
if ($core->plugins->moduleExists('cinecturlink2') if ($core->plugins->moduleExists('cinecturlink2')
&& $core->blog->settings->sitemaps->sitemaps_cinecturlink2_url) { && $core->blog->settings->sitemaps->sitemaps_cinecturlink2_url) {
$freq = $sitemaps->getFrequency($core->blog->settings->sitemaps->sitemaps_cinecturlink2_fq); $freq = $sitemaps->getFrequency($core->blog->settings->sitemaps->sitemaps_cinecturlink2_fq);
$prio = $sitemaps->getPriority($core->blog->settings->sitemaps->sitemaps_cinecturlink2_pr); $prio = $sitemaps->getPriority($core->blog->settings->sitemaps->sitemaps_cinecturlink2_pr);
$base = $core->blog->url.$core->url->getBase('cinecturlink2'); $base = $core->blog->url.$core->url->getBase('cinecturlink2');
$sitemaps->addEntry($base, $prio, $freq); $sitemaps->addEntry($base, $prio, $freq);
$core->blog->settings->addNamespace('cinecturlink2'); $core->blog->settings->addNamespace('cinecturlink2');
$C2 = new cinecturlink2($core); $C2 = new cinecturlink2($core);
$cats = $C2->getCategories(); $cats = $C2->getCategories();
while ($cats->fetch()) { while ($cats->fetch()) {
$sitemaps->addEntry($base."/".$core->blog->settings->cinecturlink2->cinecturlink2_public_caturl.'/'.urlencode($cats->cat_title), $prio, $freq); $sitemaps->addEntry($base."/".$core->blog->settings->cinecturlink2->cinecturlink2_public_caturl.'/'.urlencode($cats->cat_title), $prio, $freq);
} }
} }
} }
} }

945
index.php

File diff suppressed because it is too large Load Diff

View File

@ -323,5 +323,3 @@ $GLOBALS['__l10n']['Check to delete'] = 'Cocher pour supprimer';
#index.php:638 #index.php:638
$GLOBALS['__l10n']['update categories'] = 'mettre à jour les catégories'; $GLOBALS['__l10n']['update categories'] = 'mettre à jour les catégories';
?>