cleanup code

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

View file

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

File diff suppressed because it is too large Load diff

View file

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

View file

@ -1,347 +1,346 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of cinecturlink2, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
# contact@jcdenis.fr http://jcd.lv
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
/**
* @brief cinecturlink2, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
return null;
}
$core->addBehavior(
'initWidgets',
array('cinecturlink2Widget', 'adminLinks')
'initWidgets',
array('cinecturlink2Widget', 'adminLinks')
);
$core->addBehavior(
'initWidgets',
array('cinecturlink2Widget', 'adminCats')
'initWidgets',
array('cinecturlink2Widget', 'adminCats')
);
class cinecturlink2Widget
{
public static function adminLinks($w)
{
global $core;
public static function adminLinks($w)
{
global $core;
$C2 = new cinecturlink2($core);
$C2 = new cinecturlink2($core);
$categories_combo = array('' => '', __('Uncategorized') => 'null');
$categories = $C2->getCategories();
while($categories->fetch()) {
$cat_title = html::escapeHTML($categories->cat_title);
$categories_combo[$cat_title] = $categories->cat_id;
}
$categories_combo = array('' => '', __('Uncategorized') => 'null');
$categories = $C2->getCategories();
while($categories->fetch()) {
$cat_title = html::escapeHTML($categories->cat_title);
$categories_combo[$cat_title] = $categories->cat_id;
}
$sortby_combo = array(
__('Update date') => 'link_upddt',
__('My rating') => 'link_note',
__('Title') => 'link_title',
__('Random') => 'RANDOM',
__('Number of views') => 'COUNTER'
);
$order_combo = array(
__('Ascending') => 'asc',
__('Descending') => 'desc'
);
$sortby_combo = array(
__('Update date') => 'link_upddt',
__('My rating') => 'link_note',
__('Title') => 'link_title',
__('Random') => 'RANDOM',
__('Number of views') => 'COUNTER'
);
$order_combo = array(
__('Ascending') => 'asc',
__('Descending') => 'desc'
);
$w->create(
'cinecturlink2links',
__('My cinecturlink'),
array('cinecturlink2Widget', 'publicLinks'),
'null',
__('Show selection of cinecturlinks')
);
$w->cinecturlink2links->setting(
'title',
__('Title:'),
__('My cinecturlink'),
'text'
);
$w->cinecturlink2links->setting(
'category',
__('Category:'),
'',
'combo',
$categories_combo
);
$w->cinecturlink2links->setting(
'sortby',
__('Order by:'),
'link_upddt',
'combo',
$sortby_combo
);
$w->cinecturlink2links->setting(
'sort',
__('Sort: (only for date, note and title)'),
'desc',
'combo',
$order_combo
);
$w->cinecturlink2links->setting(
'limit',
__('Limit:'),
10,
'text'
);
$w->cinecturlink2links->setting(
'withlink',
__('Enable link'),
1,
'check'
);
$w->cinecturlink2links->setting(
'showauthor',
__('Show author'),
1,
'check'
);
$w->cinecturlink2links->setting(
'shownote',
__('Show my rating'),
0,
'check'
);
$w->cinecturlink2links->setting(
'showdesc',
__('Show description'),
0,
'check'
);
$w->cinecturlink2links->setting(
'showpagelink',
__('Show a link to cinecturlink page'),
0,
'check'
);
$w->cinecturlink2links->setting(
'homeonly',
__('Display on:'),
1,
'combo',
array(
__('All pages') => 0,
__('Home page only') => 1,
__('Except on home page') => 2
)
);
}
$w->create(
'cinecturlink2links',
__('My cinecturlink'),
array('cinecturlink2Widget', 'publicLinks'),
'null',
__('Show selection of cinecturlinks')
);
$w->cinecturlink2links->setting(
'title',
__('Title:'),
__('My cinecturlink'),
'text'
);
$w->cinecturlink2links->setting(
'category',
__('Category:'),
'',
'combo',
$categories_combo
);
$w->cinecturlink2links->setting(
'sortby',
__('Order by:'),
'link_upddt',
'combo',
$sortby_combo
);
$w->cinecturlink2links->setting(
'sort',
__('Sort: (only for date, note and title)'),
'desc',
'combo',
$order_combo
);
$w->cinecturlink2links->setting(
'limit',
__('Limit:'),
10,
'text'
);
$w->cinecturlink2links->setting(
'withlink',
__('Enable link'),
1,
'check'
);
$w->cinecturlink2links->setting(
'showauthor',
__('Show author'),
1,
'check'
);
$w->cinecturlink2links->setting(
'shownote',
__('Show my rating'),
0,
'check'
);
$w->cinecturlink2links->setting(
'showdesc',
__('Show description'),
0,
'check'
);
$w->cinecturlink2links->setting(
'showpagelink',
__('Show a link to cinecturlink page'),
0,
'check'
);
$w->cinecturlink2links->setting(
'homeonly',
__('Display on:'),
1,
'combo',
array(
__('All pages') => 0,
__('Home page only') => 1,
__('Except on home page') => 2
)
);
}
public static function adminCats($w)
{
$w->create(
'cinecturlink2cats',
__('List of categories of cinecturlink'),
array('cinecturlink2Widget', 'publicCats'),
null,
__('List of categories of cinecturlink')
);
$w->cinecturlink2cats->setting(
'title',
__('Title:'),
__('My cinecturlink by categories'),
'text'
);
$w->cinecturlink2cats->setting(
'shownumlink',
__('Show number of links'),
0,
'check'
);
$w->cinecturlink2cats->setting(
'homeonly',
__('Display on:'),
1,
'combo',
array(
__('All pages') => 0,
__('Home page only') => 1,
__('Except on home page') => 2
)
);
}
public static function adminCats($w)
{
$w->create(
'cinecturlink2cats',
__('List of categories of cinecturlink'),
array('cinecturlink2Widget', 'publicCats'),
null,
__('List of categories of cinecturlink')
);
$w->cinecturlink2cats->setting(
'title',
__('Title:'),
__('My cinecturlink by categories'),
'text'
);
$w->cinecturlink2cats->setting(
'shownumlink',
__('Show number of links'),
0,
'check'
);
$w->cinecturlink2cats->setting(
'homeonly',
__('Display on:'),
1,
'combo',
array(
__('All pages') => 0,
__('Home page only') => 1,
__('Except on home page') => 2
)
);
}
public static function publicLinks($w)
{
global $core;
public static function publicLinks($w)
{
global $core;
$core->blog->settings->addNamespace('cinecturlink2');
$core->blog->settings->addNamespace('cinecturlink2');
if (!$core->blog->settings->cinecturlink2->cinecturlink2_active
|| $w->homeonly == 1 && $core->url->type != 'default'
|| $w->homeonly == 2 && $core->url->type == 'default'
) {
return null;
}
if (!$core->blog->settings->cinecturlink2->cinecturlink2_active
|| $w->homeonly == 1 && $core->url->type != 'default'
|| $w->homeonly == 2 && $core->url->type == 'default'
) {
return null;
}
$C2 = new cinecturlink2($core);
$C2 = new cinecturlink2($core);
if ($w->category) {
if ($w->category == 'null') {
$params['sql'] = ' AND L.cat_id IS NULL ';
}
elseif (is_numeric($w->category)) {
$params['cat_id'] = (integer) $w->category;
}
}
if ($w->category) {
if ($w->category == 'null') {
$params['sql'] = ' AND L.cat_id IS NULL ';
}
elseif (is_numeric($w->category)) {
$params['cat_id'] = (integer) $w->category;
}
}
$limit = abs((integer) $w->limit);
$limit = abs((integer) $w->limit);
# Tirage aléatoire
# Consomme beaucoup de ressources!
if ($w->sortby == 'RANDOM') {
$big_rs = $C2->getLinks($params);
# Tirage aléatoire
# Consomme beaucoup de ressources!
if ($w->sortby == 'RANDOM') {
$big_rs = $C2->getLinks($params);
if ($big_rs->isEmpty()) {
if ($big_rs->isEmpty()) {
return null;
}
return null;
}
$ids= array();
while($big_rs->fetch()) {
$ids[] = $big_rs->link_id;
}
shuffle($ids);
$ids = array_slice($ids, 0, $limit);
$ids= array();
while($big_rs->fetch()) {
$ids[] = $big_rs->link_id;
}
shuffle($ids);
$ids = array_slice($ids, 0, $limit);
$params['link_id'] = array();
foreach($ids as $id) {
$params['link_id'][] = $id;
}
}
elseif ($w->sortby == 'COUNTER') {
$params['order'] = 'link_count asc';
$params['limit'] = $limit;
}
else {
$params['order'] = $w->sortby;
$params['order'] .= $w->sort == 'asc' ? ' asc' : ' desc';
$params['limit'] = $limit;
}
$params['link_id'] = array();
foreach($ids as $id) {
$params['link_id'][] = $id;
}
}
elseif ($w->sortby == 'COUNTER') {
$params['order'] = 'link_count asc';
$params['limit'] = $limit;
}
else {
$params['order'] = $w->sortby;
$params['order'] .= $w->sort == 'asc' ? ' asc' : ' desc';
$params['limit'] = $limit;
}
$rs = $C2->getLinks($params);
$rs = $C2->getLinks($params);
if ($rs->isEmpty()) {
if ($rs->isEmpty()) {
return null;
}
return null;
}
$widthmax = (integer) $core->blog->settings->cinecturlink2->cinecturlink2_widthmax;
$style = $widthmax ? ' style="width:'.$widthmax.'px;"' : '';
$widthmax = (integer) $core->blog->settings->cinecturlink2->cinecturlink2_widthmax;
$style = $widthmax ? ' style="width:'.$widthmax.'px;"' : '';
$entries = array();
while($rs->fetch()) {
$url = $rs->link_url;
$img = $rs->link_img;
$title = html::escapeHTML($rs->link_title);
$author = html::escapeHTML($rs->link_author);
$cat = html::escapeHTML($rs->cat_title);
$note = $w->shownote ? ' <em>('.$rs->link_note.'/20)</em>' : '';
$desc = $w->showdesc ? '<br /><em>'.html::escapeHTML($rs->link_desc).'</em>' : '';
$lang = $rs->link_lang ? ' hreflang="'.$rs->link_lang.'"' : '';
$count = abs((integer) $rs->link_count);
$entries = array();
while($rs->fetch()) {
$url = $rs->link_url;
$img = $rs->link_img;
$title = html::escapeHTML($rs->link_title);
$author = html::escapeHTML($rs->link_author);
$cat = html::escapeHTML($rs->cat_title);
$note = $w->shownote ? ' <em>('.$rs->link_note.'/20)</em>' : '';
$desc = $w->showdesc ? '<br /><em>'.html::escapeHTML($rs->link_desc).'</em>' : '';
$lang = $rs->link_lang ? ' hreflang="'.$rs->link_lang.'"' : '';
$count = abs((integer) $rs->link_count);
# --BEHAVIOR-- cinecturlink2WidgetLinks
$bhv = $core->callBehavior('cinecturlink2WidgetLinks', $rs->link_id);
# --BEHAVIOR-- cinecturlink2WidgetLinks
$bhv = $core->callBehavior('cinecturlink2WidgetLinks', $rs->link_id);
$entries[] =
'<p style="text-align:center;">'.
($w->withlink && !empty($url) ? '<a href="'.$url.'"'.$lang.' title="'.$cat.'">' : '').
'<strong>'.$title.'</strong>'.$note.'<br />'.
($w->showauthor ? $author.'<br />' : '').'<br />'.
'<img src="'.$img.'" alt="'.$title.' - '.$author.'"'.$style.' />'.
$desc.
($w->withlink && !empty($url) ? '</a>' : '').
'</p>'.$bhv;
$entries[] =
'<p style="text-align:center;">'.
($w->withlink && !empty($url) ? '<a href="'.$url.'"'.$lang.' title="'.$cat.'">' : '').
'<strong>'.$title.'</strong>'.$note.'<br />'.
($w->showauthor ? $author.'<br />' : '').'<br />'.
'<img src="'.$img.'" alt="'.$title.' - '.$author.'"'.$style.' />'.
$desc.
($w->withlink && !empty($url) ? '</a>' : '').
'</p>'.$bhv;
try {
$cur = $core->con->openCursor($C2->table);
$cur->link_count = ($count + 1);
$C2->updLink($rs->link_id, $cur, false);
}
catch (Exception $e) {
try {
$cur = $core->con->openCursor($C2->table);
$cur->link_count = ($count + 1);
$C2->updLink($rs->link_id, $cur, false);
}
catch (Exception $e) {
}
}
# Tirage aléatoire
if ($w->sortby == 'RANDOM'
|| $w->sortby == 'COUNTER'
) {
shuffle($entries);
if ($core->blog->settings->cinecturlink2->cinecturlink2_triggeronrandom) {
$core->blog->triggerBlog();
}
}
}
}
# Tirage aléatoire
if ($w->sortby == 'RANDOM'
|| $w->sortby == 'COUNTER'
) {
shuffle($entries);
if ($core->blog->settings->cinecturlink2->cinecturlink2_triggeronrandom) {
$core->blog->triggerBlog();
}
}
return
'<div class="cinecturlink2list">'.
($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
implode(' ',$entries).
($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>' : ''
).
'</div>';
}
return
'<div class="cinecturlink2list">'.
($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
implode(' ',$entries).
($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>' : ''
).
'</div>';
}
public static function publicCats($w)
{
global $core;
public static function publicCats($w)
{
global $core;
$core->blog->settings->addNamespace('cinecturlink2');
$core->blog->settings->addNamespace('cinecturlink2');
if (!$core->blog->settings->cinecturlink2->cinecturlink2_active
|| !$core->blog->settings->cinecturlink2->cinecturlink2_public_active
|| $w->homeonly == 1 && $core->url->type != 'default'
|| $w->homeonly == 2 && $core->url->type == 'default'
) {
return null;
}
if (!$core->blog->settings->cinecturlink2->cinecturlink2_active
|| !$core->blog->settings->cinecturlink2->cinecturlink2_public_active
|| $w->homeonly == 1 && $core->url->type != 'default'
|| $w->homeonly == 2 && $core->url->type == 'default'
) {
return null;
}
$C2 = new cinecturlink2($core);
$C2 = new cinecturlink2($core);
$rs = $C2->getCategories(array());
$rs = $C2->getCategories(array());
if ($rs->isEmpty()) {
if ($rs->isEmpty()) {
return null;
}
return null;
}
$res =
'<li><a href="'.
$core->blog->url.$core->url->getBase('cinecturlink2').
'" title="'.__('view all links').'">'.__('all links').
'</a>';
if ($w->shownumlink) {
$res .= ' ('.($C2->getLinks(array(), true)->f(0)).')';
}
$res .= '</li>';
$res =
'<li><a href="'.
$core->blog->url.$core->url->getBase('cinecturlink2').
'" title="'.__('view all links').'">'.__('all links').
'</a>';
if ($w->shownumlink) {
$res .= ' ('.($C2->getLinks(array(), true)->f(0)).')';
}
$res .= '</li>';
while($rs->fetch()) {
$res .=
'<li><a href="'.
$core->blog->url.$core->url->getBase('cinecturlink2').'/'.$core->blog->settings->cinecturlink2->cinecturlink2_public_caturl.'/'.urlencode($rs->cat_title).
'" title="'.__('view links of this category').'">'.
html::escapeHTML($rs->cat_title).
'</a>';
if ($w->shownumlink) {
$res .= ' ('.($C2->getLinks(array('cat_id'=>$rs->cat_id), true)->f(0)).')';
}
$res .= '</li>';
}
while($rs->fetch()) {
$res .=
'<li><a href="'.
$core->blog->url.$core->url->getBase('cinecturlink2').'/'.$core->blog->settings->cinecturlink2->cinecturlink2_public_caturl.'/'.urlencode($rs->cat_title).
'" title="'.__('view links of this category').'">'.
html::escapeHTML($rs->cat_title).
'</a>';
if ($w->shownumlink) {
$res .= ' ('.($C2->getLinks(array('cat_id'=>$rs->cat_id), true)->f(0)).')';
}
$res .= '</li>';
}
return
'<div class="cinecturlink2cat">'.
($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
'<ul>'.$res.'</ul>'.
'</div>';
}
return
'<div class="cinecturlink2cat">'.
($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
'<ul>'.$res.'</ul>'.
'</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
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of cinecturlink2, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
# contact@jcdenis.fr http://jcd.lv
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
/**
* @brief cinecturlink2, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
return null;
}
/**
@ -24,443 +23,443 @@ if (!defined('DC_RC_PATH')) {
*/
class cinecturlink2
{
/** @var dcCore dcCore instance */
public $core;
/** @var dbLayer dbLayer instance */
public $con;
/** @var string Cinecturlink table name */
public $table;
/** @var string Blog ID */
public $blog;
/** @var dcCore dcCore instance */
public $core;
/** @var dbLayer dbLayer instance */
public $con;
/** @var string Cinecturlink table name */
public $table;
/** @var string Blog ID */
public $blog;
/**
* Contructor
*
* @param dcCore $core dcCore instance
*/
public function __construct(dcCore $core)
{
$core->blog->settings->addNamespace('cinecturlink2');
/**
* Contructor
*
* @param dcCore $core dcCore instance
*/
public function __construct(dcCore $core)
{
$core->blog->settings->addNamespace('cinecturlink2');
$this->core = $core;
$this->con = $core->con;
$this->table = $core->prefix.'cinecturlink2';
$this->blog = $core->con->escape($core->blog->id);
}
$this->core = $core;
$this->con = $core->con;
$this->table = $core->prefix.'cinecturlink2';
$this->blog = $core->con->escape($core->blog->id);
}
/**
* Get links
*
* @param array $params Query params
* @param boolean $count_only Count only result
* @return record record instance
*/
public function getLinks($params=array(), $count_only=false)
{
if ($count_only) {
$strReq = 'SELECT count(L.link_id) ';
}
else {
$content_req = '';
if (!empty($params['columns']) && is_array($params['columns'])) {
$content_req .= implode(', ', $params['columns']).', ';
}
/**
* Get links
*
* @param array $params Query params
* @param boolean $count_only Count only result
* @return record record instance
*/
public function getLinks($params=array(), $count_only=false)
{
if ($count_only) {
$strReq = 'SELECT count(L.link_id) ';
}
else {
$content_req = '';
if (!empty($params['columns']) && is_array($params['columns'])) {
$content_req .= implode(', ', $params['columns']).', ';
}
$strReq =
'SELECT L.link_id, L.blog_id, L.cat_id, L.user_id, L.link_type, '.
$content_req.
'L.link_creadt, L.link_upddt, L.link_note, L.link_count, '.
'L.link_title, L.link_desc, L.link_author, '.
'L.link_lang, L.link_url, L.link_img, '.
'U.user_name, U.user_firstname, U.user_displayname, U.user_email, '.
'U.user_url, '.
'C.cat_title, C.cat_desc ';
}
$strReq =
'SELECT L.link_id, L.blog_id, L.cat_id, L.user_id, L.link_type, '.
$content_req.
'L.link_creadt, L.link_upddt, L.link_note, L.link_count, '.
'L.link_title, L.link_desc, L.link_author, '.
'L.link_lang, L.link_url, L.link_img, '.
'U.user_name, U.user_firstname, U.user_displayname, U.user_email, '.
'U.user_url, '.
'C.cat_title, C.cat_desc ';
}
$strReq .=
'FROM '.$this->table.' L '.
'INNER JOIN '.$this->core->prefix.'user U ON U.user_id = L.user_id '.
'LEFT OUTER JOIN '.$this->table.'_cat C ON L.cat_id = C.cat_id ';
$strReq .=
'FROM '.$this->table.' L '.
'INNER JOIN '.$this->core->prefix.'user U ON U.user_id = L.user_id '.
'LEFT OUTER JOIN '.$this->table.'_cat C ON L.cat_id = C.cat_id ';
if (!empty($params['from'])) {
$strReq .= $params['from'].' ';
}
if (!empty($params['from'])) {
$strReq .= $params['from'].' ';
}
$strReq .= "WHERE L.blog_id = '".$this->blog."' ";
$strReq .= "WHERE L.blog_id = '".$this->blog."' ";
if (isset($params['link_type'])) {
if (is_array($params['link_type']) && !empty($params['link_type'])) {
$strReq .= 'AND L.link_type '.$this->con->in($params['link_type']);
}
elseif ($params['link_type'] != '') {
$strReq .= "AND L.link_type = '".$this->con->escape($params['link_type'])."' ";
}
}
else {
$strReq .= "AND L.link_type = 'cinecturlink' ";
}
if (isset($params['link_type'])) {
if (is_array($params['link_type']) && !empty($params['link_type'])) {
$strReq .= 'AND L.link_type '.$this->con->in($params['link_type']);
}
elseif ($params['link_type'] != '') {
$strReq .= "AND L.link_type = '".$this->con->escape($params['link_type'])."' ";
}
}
else {
$strReq .= "AND L.link_type = 'cinecturlink' ";
}
if (!empty($params['link_id'])) {
if (is_array($params['link_id'])) {
array_walk($params['link_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}'));
}
else {
$params['link_id'] = array((integer) $params['link_id']);
}
$strReq .= 'AND L.link_id '.$this->con->in($params['link_id']);
}
if (!empty($params['link_id'])) {
if (is_array($params['link_id'])) {
array_walk($params['link_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}'));
}
else {
$params['link_id'] = array((integer) $params['link_id']);
}
$strReq .= 'AND L.link_id '.$this->con->in($params['link_id']);
}
if (!empty($params['cat_id'])) {
if (is_array($params['cat_id'])) {
array_walk($params['cat_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}'));
}
else {
$params['cat_id'] = array((integer) $params['cat_id']);
}
$strReq .= 'AND L.cat_id '.$this->con->in($params['cat_id']);
}
if (!empty($params['cat_title'])) {
$strReq .= "AND C.cat_title = '".$this->con->escape($params['cat_title'])."' ";
}
if (!empty($params['cat_id'])) {
if (is_array($params['cat_id'])) {
array_walk($params['cat_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}'));
}
else {
$params['cat_id'] = array((integer) $params['cat_id']);
}
$strReq .= 'AND L.cat_id '.$this->con->in($params['cat_id']);
}
if (!empty($params['cat_title'])) {
$strReq .= "AND C.cat_title = '".$this->con->escape($params['cat_title'])."' ";
}
if (!empty($params['link_title'])) {
$strReq .= "AND L.link_title = '".$this->con->escape($params['link_title'])."' ";
}
if (!empty($params['link_title'])) {
$strReq .= "AND L.link_title = '".$this->con->escape($params['link_title'])."' ";
}
if (!empty($params['link_lang'])) {
$strReq .= "AND L.link_lang = '".$this->con->escape($params['link_lang'])."' ";
}
if (!empty($params['link_lang'])) {
$strReq .= "AND L.link_lang = '".$this->con->escape($params['link_lang'])."' ";
}
if (!empty($params['sql'])) {
$strReq .= $params['sql'].' ';
}
if (!empty($params['sql'])) {
$strReq .= $params['sql'].' ';
}
if (!$count_only) {
if (!empty($params['order'])) {
$strReq .= 'ORDER BY '.$this->con->escape($params['order']).' ';
}
else {
$strReq .= 'ORDER BY L.link_upddt DESC ';
}
}
if (!$count_only) {
if (!empty($params['order'])) {
$strReq .= 'ORDER BY '.$this->con->escape($params['order']).' ';
}
else {
$strReq .= 'ORDER BY L.link_upddt DESC ';
}
}
if (!$count_only && !empty($params['limit'])) {
$strReq .= $this->con->limit($params['limit']);
}
if (!$count_only && !empty($params['limit'])) {
$strReq .= $this->con->limit($params['limit']);
}
return $this->con->select($strReq);
}
return $this->con->select($strReq);
}
/**
* Add link
*
* @param cursor $cur cursor instance
*/
public function addLink(cursor $cur)
{
$this->con->writeLock($this->table);
/**
* Add link
*
* @param cursor $cur cursor instance
*/
public function addLink(cursor $cur)
{
$this->con->writeLock($this->table);
try {
if ($cur->link_title == '') {
throw new Exception(__('No link title'));
}
if ($cur->link_desc == '') {
throw new Exception(__('No link description'));
}
if ('' == $cur->link_note) {
$cur->link_note = 10;
}
if (0 > $cur->link_note || $cur->link_note > 20) {
$cur->link_note = 10;
}
try {
if ($cur->link_title == '') {
throw new Exception(__('No link title'));
}
if ($cur->link_desc == '') {
throw new Exception(__('No link description'));
}
if ('' == $cur->link_note) {
$cur->link_note = 10;
}
if (0 > $cur->link_note || $cur->link_note > 20) {
$cur->link_note = 10;
}
$cur->link_id = $this->getNextLinkId();
$cur->blog_id = $this->blog;
$cur->user_id = $this->core->auth->userID();
$cur->link_creadt = date('Y-m-d H:i:s');
$cur->link_upddt = date('Y-m-d H:i:s');
$cur->link_pos = 0;
$cur->link_count = 0;
$cur->insert();
$this->con->unlock();
}
catch (Exception $e) {
$this->con->unlock();
throw $e;
}
$this->trigger();
$cur->link_id = $this->getNextLinkId();
$cur->blog_id = $this->blog;
$cur->user_id = $this->core->auth->userID();
$cur->link_creadt = date('Y-m-d H:i:s');
$cur->link_upddt = date('Y-m-d H:i:s');
$cur->link_pos = 0;
$cur->link_count = 0;
$cur->insert();
$this->con->unlock();
}
catch (Exception $e) {
$this->con->unlock();
throw $e;
}
$this->trigger();
# --BEHAVIOR-- cinecturlink2AfterAddLink
$this->core->callBehavior('cinecturlink2AfterAddLink', $cur);
# --BEHAVIOR-- cinecturlink2AfterAddLink
$this->core->callBehavior('cinecturlink2AfterAddLink', $cur);
return $cur->link_id;
}
return $cur->link_id;
}
/**
* Update link
*
* @param integer $id Link ID
* @param cursor $cur cursor instance
* @param boolean $behavior Call related behaviors
*/
public function updLink($id, cursor $cur, $behavior=true)
{
$id = (integer) $id;
/**
* Update link
*
* @param integer $id Link ID
* @param cursor $cur cursor instance
* @param boolean $behavior Call related behaviors
*/
public function updLink($id, cursor $cur, $behavior=true)
{
$id = (integer) $id;
if (empty($id)) {
throw new Exception(__('No such link ID'));
}
if (empty($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."' ");
$this->trigger();
$cur->update("WHERE link_id = ".$id." AND blog_id = '".$this->blog."' ");
$this->trigger();
if ($behavior) {
# --BEHAVIOR-- cinecturlink2AfterUpdLink
$this->core->callBehavior('cinecturlink2AfterUpdLink', $cur, $id);
}
}
if ($behavior) {
# --BEHAVIOR-- cinecturlink2AfterUpdLink
$this->core->callBehavior('cinecturlink2AfterUpdLink', $cur, $id);
}
}
/**
* Delete link
*
* @param integer $id Link ID
*/
public function delLink($id)
{
$id = (integer) $id;
/**
* Delete link
*
* @param integer $id Link ID
*/
public function delLink($id)
{
$id = (integer) $id;
if (empty($id)) {
throw new Exception(__('No such link ID'));
}
if (empty($id)) {
throw new Exception(__('No such link ID'));
}
# --BEHAVIOR-- cinecturlink2BeforeDelLink
$this->core->callBehavior('cinecturlink2BeforeDelLink', $id);
# --BEHAVIOR-- cinecturlink2BeforeDelLink
$this->core->callBehavior('cinecturlink2BeforeDelLink', $id);
$this->con->execute(
'DELETE FROM '.$this->table.' '.
'WHERE link_id = '.$id.' '.
"AND blog_id = '".$this->blog."' "
);
$this->con->execute(
'DELETE FROM '.$this->table.' '.
'WHERE link_id = '.$id.' '.
"AND blog_id = '".$this->blog."' "
);
$this->trigger();
}
$this->trigger();
}
/**
* Get next link ID
*
* @return integer Next link ID
*/
private function getNextLinkId()
{
return $this->con->select(
'SELECT MAX(link_id) FROM '.$this->table.' '
)->f(0) + 1;
}
/**
* Get next link ID
*
* @return integer Next link ID
*/
private function getNextLinkId()
{
return $this->con->select(
'SELECT MAX(link_id) FROM '.$this->table.' '
)->f(0) + 1;
}
/**
* Get categories
*
* @param array $params Query params
* @param boolean $count_only Count only result
* @return record record instance
*/
public function getCategories($params=array(), $count_only=false)
{
if ($count_only) {
$strReq = 'SELECT count(C.cat_id) ';
}
else {
$content_req = '';
if (!empty($params['columns']) && is_array($params['columns'])) {
$content_req .= implode(', ', $params['columns']).', ';
}
/**
* Get categories
*
* @param array $params Query params
* @param boolean $count_only Count only result
* @return record record instance
*/
public function getCategories($params=array(), $count_only=false)
{
if ($count_only) {
$strReq = 'SELECT count(C.cat_id) ';
}
else {
$content_req = '';
if (!empty($params['columns']) && is_array($params['columns'])) {
$content_req .= implode(', ', $params['columns']).', ';
}
$strReq =
'SELECT C.cat_id, C.blog_id, C.cat_title, C.cat_desc, '.
$content_req.
'C.cat_pos, C.cat_creadt, C.cat_upddt ';
}
$strReq =
'SELECT C.cat_id, C.blog_id, C.cat_title, C.cat_desc, '.
$content_req.
'C.cat_pos, C.cat_creadt, C.cat_upddt ';
}
$strReq .= 'FROM '.$this->table.'_cat C ';
$strReq .= 'FROM '.$this->table.'_cat C ';
if (!empty($params['from'])) {
$strReq .= $params['from'].' ';
}
if (!empty($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 (is_array($params['cat_id'])) {
array_walk($params['cat_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}'));
}
else {
$params['cat_id'] = array((integer) $params['cat_id']);
}
$strReq .= 'AND C.cat_id '.$this->con->in($params['cat_id']);
}
if (!empty($params['cat_id'])) {
if (is_array($params['cat_id'])) {
array_walk($params['cat_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}'));
}
else {
$params['cat_id'] = array((integer) $params['cat_id']);
}
$strReq .= 'AND C.cat_id '.$this->con->in($params['cat_id']);
}
if (!empty($params['cat_title'])) {
$strReq .= "AND C.cat_title = '".$this->con->escape($params['cat_title'])."' ";
}
if (!empty($params['cat_title'])) {
$strReq .= "AND C.cat_title = '".$this->con->escape($params['cat_title'])."' ";
}
if (!empty($params['sql'])) {
$strReq .= $params['sql'].' ';
}
if (!empty($params['sql'])) {
$strReq .= $params['sql'].' ';
}
if (!$count_only) {
if (!empty($params['order'])) {
$strReq .= 'ORDER BY '.$this->con->escape($params['order']).' ';
}
else {
$strReq .= 'ORDER BY cat_pos ASC ';
}
}
if (!$count_only) {
if (!empty($params['order'])) {
$strReq .= 'ORDER BY '.$this->con->escape($params['order']).' ';
}
else {
$strReq .= 'ORDER BY cat_pos ASC ';
}
}
if (!$count_only && !empty($params['limit'])) {
$strReq .= $this->con->limit($params['limit']);
}
if (!$count_only && !empty($params['limit'])) {
$strReq .= $this->con->limit($params['limit']);
}
return $this->con->select($strReq);
}
return $this->con->select($strReq);
}
/**
* Add category
*
* @param cursor $cur cursor instance
* @return integer New category ID
*/
public function addCategory(cursor $cur)
{
$this->con->writeLock($this->table.'_cat');
/**
* Add category
*
* @param cursor $cur cursor instance
* @return integer New category ID
*/
public function addCategory(cursor $cur)
{
$this->con->writeLock($this->table.'_cat');
try {
if ($cur->cat_title == '') {
throw new Exception(__('No category title'));
}
if ($cur->cat_desc == '') {
throw new Exception(__('No category description'));
}
try {
if ($cur->cat_title == '') {
throw new Exception(__('No category title'));
}
if ($cur->cat_desc == '') {
throw new Exception(__('No category description'));
}
$cur->cat_id = $this->getNextCatId();
$cur->cat_pos = $this->getNextCatPos();
$cur->blog_id = $this->blog;
$cur->cat_creadt = date('Y-m-d H:i:s');
$cur->cat_upddt = date('Y-m-d H:i:s');
$cur->insert();
$this->con->unlock();
}
catch (Exception $e) {
$this->con->unlock();
throw $e;
}
$this->trigger();
$cur->cat_id = $this->getNextCatId();
$cur->cat_pos = $this->getNextCatPos();
$cur->blog_id = $this->blog;
$cur->cat_creadt = date('Y-m-d H:i:s');
$cur->cat_upddt = date('Y-m-d H:i:s');
$cur->insert();
$this->con->unlock();
}
catch (Exception $e) {
$this->con->unlock();
throw $e;
}
$this->trigger();
return $cur->cat_id;
}
return $cur->cat_id;
}
/**
* Update category
*
* @param integer $id Category ID
* @param cursor $cur cursor instance
*/
public function updCategory($id, cursor $cur)
{
$id = (integer) $id;
/**
* Update category
*
* @param integer $id Category ID
* @param cursor $cur cursor instance
*/
public function updCategory($id, cursor $cur)
{
$id = (integer) $id;
if (empty($id)) {
throw new Exception(__('No such category ID'));
}
if (empty($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."' ");
$this->trigger();
}
$cur->update("WHERE cat_id = ".$id." AND blog_id = '".$this->blog."' ");
$this->trigger();
}
/**
* Delete category
*
* @param integer $id Category ID
*/
public function delCategory($id)
{
$id = (integer) $id;
/**
* Delete category
*
* @param integer $id Category ID
*/
public function delCategory($id)
{
$id = (integer) $id;
if (empty($id)) {
throw new Exception(__('No such category ID'));
}
if (empty($id)) {
throw new Exception(__('No such category ID'));
}
$this->con->execute(
'DELETE FROM '.$this->table.'_cat '.
'WHERE cat_id = '.$id.' '.
"AND blog_id = '".$this->blog."' "
);
$this->con->execute(
'DELETE FROM '.$this->table.'_cat '.
'WHERE cat_id = '.$id.' '.
"AND blog_id = '".$this->blog."' "
);
# Update link cat to NULL
$cur = $this->con->openCursor($this->table);
$cur->cat_id = NULL;
$cur->link_upddt = date('Y-m-d H:i:s');
$cur->update("WHERE cat_id = ".$id." AND blog_id = '".$this->blog."' ");
# Update link cat to NULL
$cur = $this->con->openCursor($this->table);
$cur->cat_id = NULL;
$cur->link_upddt = date('Y-m-d H:i:s');
$cur->update("WHERE cat_id = ".$id." AND blog_id = '".$this->blog."' ");
$this->trigger();
}
$this->trigger();
}
/**
* Get next category ID
*
* @return integer Next category ID
*/
private function getNextCatId()
{
return $this->con->select(
'SELECT MAX(cat_id) FROM '.$this->table.'_cat '
)->f(0) + 1;
}
/**
* Get next category ID
*
* @return integer Next category ID
*/
private function getNextCatId()
{
return $this->con->select(
'SELECT MAX(cat_id) FROM '.$this->table.'_cat '
)->f(0) + 1;
}
/**
* Get next category position
*
* @return integer Next category position
*/
private function getNextCatPos()
{
return $this->con->select(
'SELECT MAX(cat_pos) FROM '.$this->table.'_cat '.
"WHERE blog_id = '".$this->blog."' "
)->f(0) + 1;
}
/**
* Get next category position
*
* @return integer Next category position
*/
private function getNextCatPos()
{
return $this->con->select(
'SELECT MAX(cat_pos) FROM '.$this->table.'_cat '.
"WHERE blog_id = '".$this->blog."' "
)->f(0) + 1;
}
/**
* Trigger event
*/
private function trigger()
{
$this->core->blog->triggerBlog();
}
/**
* Trigger event
*/
private function trigger()
{
$this->core->blog->triggerBlog();
}
/**
* Check if a directory exists and is writable
*
* @param string $root Root
* @param string $folder Folder to create into root folder
* @param boolean $throw Throw exception or not
* @return boolean True if exists and writable
*/
public static function test_folder($root, $folder, $throw=false)
{
if (!is_dir($root.'/'.$folder)) {
if (!is_dir($root) || !is_writable($root) || !mkdir($root.'/'.$folder)) {
if ($throw) {
throw new Exception(__('Failed to create public folder for images.'));
}
/**
* Check if a directory exists and is writable
*
* @param string $root Root
* @param string $folder Folder to create into root folder
* @param boolean $throw Throw exception or not
* @return boolean True if exists and writable
*/
public static function test_folder($root, $folder, $throw=false)
{
if (!is_dir($root.'/'.$folder)) {
if (!is_dir($root) || !is_writable($root) || !mkdir($root.'/'.$folder)) {
if ($throw) {
throw new Exception(__('Failed to create public folder for images.'));
}
return false;
}
}
return false;
}
}
return true;
}
return true;
}
}

View file

@ -1,117 +1,116 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of cinecturlink2, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
# contact@jcdenis.fr http://jcd.lv
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
/**
* @brief cinecturlink2, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class cinecturlink2Context
{
public static function PaginationNbPages()
{
global $_ctx;
public static function PaginationNbPages()
{
global $_ctx;
if ($_ctx->c2_pagination === null) {
if ($_ctx->c2_pagination === null) {
return false;
}
return false;
}
$nb_posts = $_ctx->c2_pagination->f(0);
$nb_per_page = $_ctx->c2_params['limit'][1];
$nb_posts = $_ctx->c2_pagination->f(0);
$nb_per_page = $_ctx->c2_params['limit'][1];
$nb_pages = ceil($nb_posts/$nb_per_page);
$nb_pages = ceil($nb_posts/$nb_per_page);
return $nb_pages;
}
return $nb_pages;
}
public static function PaginationPosition($offset=0)
{
if (isset($GLOBALS['c2_page_number'])) {
$p = $GLOBALS['c2_page_number'];
}
else {
$p = 1;
}
public static function PaginationPosition($offset=0)
{
if (isset($GLOBALS['c2_page_number'])) {
$p = $GLOBALS['c2_page_number'];
}
else {
$p = 1;
}
$p = $p+$offset;
$p = $p+$offset;
$n = self::PaginationNbPages();
if (!$n) {
$n = self::PaginationNbPages();
if (!$n) {
return $p;
}
return $p;
}
return $p > $n || $p <= 0 ? 1 : $p;
}
return $p > $n || $p <= 0 ? 1 : $p;
}
public static function PaginationStart()
{
if (isset($GLOBALS['c2_page_number'])) {
public static function PaginationStart()
{
if (isset($GLOBALS['c2_page_number'])) {
return self::PaginationPosition() == 1;
}
return self::PaginationPosition() == 1;
}
return true;
}
return true;
}
public static function PaginationEnd()
{
if (isset($GLOBALS['c2_page_number'])) {
public static function PaginationEnd()
{
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)
{
$args = $_SERVER['URL_REQUEST_PART'];
public static function PaginationURL($offset=0)
{
$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) {
$url = preg_replace('#/$#','',$url);
$url .= '/c2page/'.$n;
}
if ($n > 1) {
$url = preg_replace('#/$#','',$url);
$url .= '/c2page/'.$n;
}
# If search param
if (!empty($_GET['q'])) {
$s = strpos($url,'?') !== false ? '&amp;' : '?';
$url .= $s.'q='.rawurlencode($_GET['q']);
}
# If search param
if (!empty($_GET['q'])) {
$s = strpos($url,'?') !== false ? '&amp;' : '?';
$url .= $s.'q='.rawurlencode($_GET['q']);
}
return $url;
}
return $url;
}
public static function categoryCurrent()
{
global $_ctx;
public static function categoryCurrent()
{
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;
}
if (isset($_ctx->c2_page_params['cat_id']) && $_ctx->c2_page_params['cat_id'] == $_ctx->c2_categories->cat_id) {
return false;
}
if (isset($_ctx->c2_page_params['cat_id']) && $_ctx->c2_page_params['cat_id'] == $_ctx->c2_categories->cat_id) {
return true;
}
if (isset($_ctx->c2_page_params['cat_title']) && $_ctx->c2_page_params['cat_title'] == $_ctx->c2_categories->cat_title) {
return true;
}
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
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of cinecturlink2, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
# contact@jcdenis.fr http://jcd.lv
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
/**
* @brief cinecturlink2, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
return null;
}
class adminlistCinecturlink2 extends adminGenericList
{
public function display($page, $nb_per_page, $url)
{
if ($this->rs->isEmpty()) {
echo '<p><strong>'.__('There is no link').'</strong></p>';
}
else {
$pager = new pager($page, $this->rs_count, $nb_per_page,10);
public function display($page, $nb_per_page, $url)
{
if ($this->rs->isEmpty()) {
echo '<p><strong>'.__('There is no link').'</strong></p>';
}
else {
$pager = new pager($page, $this->rs_count, $nb_per_page,10);
$pager->base_url = $url;
$pager->base_url = $url;
$html_block =
'<table class="clear">'.
'<thead>'.
'<tr>'.
'<th class="nowrap" colspan="2">'.__('Title').'</th>'.
'<th class="nowrap">'.__('Author').'</th>'.
'<th class="maximal">'.__('Description').'</th>'.
'<th class="maximal">'.__('Links').'</th>'.
'<th class="nowrap">'.__('Category').'</th>'.
'<th class="nowrap">'.__('My rating').'</th>'.
'<th class="nowrap">'.__('Date').'</th>'.
'</tr>'.
'</thead>'.
'<tbody>%s</tbody>'.
'</table>';
$html_block =
'<table class="clear">'.
'<thead>'.
'<tr>'.
'<th class="nowrap" colspan="2">'.__('Title').'</th>'.
'<th class="nowrap">'.__('Author').'</th>'.
'<th class="maximal">'.__('Description').'</th>'.
'<th class="maximal">'.__('Links').'</th>'.
'<th class="nowrap">'.__('Category').'</th>'.
'<th class="nowrap">'.__('My rating').'</th>'.
'<th class="nowrap">'.__('Date').'</th>'.
'</tr>'.
'</thead>'.
'<tbody>%s</tbody>'.
'</table>';
echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>';
$blocks = explode('%s',$html_block);
echo $blocks[0];
echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>';
$blocks = explode('%s',$html_block);
echo $blocks[0];
$this->rs->index(((integer)$page - 1) * $nb_per_page);
$iter = 0;
while ($iter < $nb_per_page) {
echo $this->linkLine($url,$iter);
$this->rs->index(((integer)$page - 1) * $nb_per_page);
$iter = 0;
while ($iter < $nb_per_page) {
echo $this->linkLine($url,$iter);
if ($this->rs->isEnd())
break;
else
$this->rs->moveNext();
if ($this->rs->isEnd())
break;
else
$this->rs->moveNext();
$iter++;
}
echo $blocks[1];
echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>';
}
}
$iter++;
}
echo $blocks[1];
echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>';
}
}
private function linkLine($url, $loop)
{
return
'<tr class="line">'."\n".
'<td class="nowrap">'.
form::checkbox(array('links[]'), $this->rs->link_id, 0).
'</td>'.
'<td class="nowrap">'.
'<a href="plugin.php?p=cinecturlink2&amp;link_id='.$this->rs->link_id.'#newlink" title="'.__('Edit').'">'.
html::escapeHTML($this->rs->link_title).
'</a>'.
"</td>\n".
'<td class="nowrap">'.
html::escapeHTML($this->rs->link_author).
"</td>\n".
'<td class="maximal">'.
html::escapeHTML($this->rs->link_desc).
"</td>\n".
'<td class="nowrap">'.
'<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> '.
"</td>\n".
'<td class="nowrap">'.
html::escapeHTML($this->rs->cat_title).
"</td>\n".
'<td class="nowrap">'.
html::escapeHTML($this->rs->link_note).'/20'.
"</td>\n".
'<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')).
"</td>\n".
'</tr>'."\n";
}
private function linkLine($url, $loop)
{
return
'<tr class="line">'."\n".
'<td class="nowrap">'.
form::checkbox(array('links[]'), $this->rs->link_id, 0).
'</td>'.
'<td class="nowrap">'.
'<a href="plugin.php?p=cinecturlink2&amp;link_id='.$this->rs->link_id.'#newlink" title="'.__('Edit').'">'.
html::escapeHTML($this->rs->link_title).
'</a>'.
"</td>\n".
'<td class="nowrap">'.
html::escapeHTML($this->rs->link_author).
"</td>\n".
'<td class="maximal">'.
html::escapeHTML($this->rs->link_desc).
"</td>\n".
'<td class="nowrap">'.
'<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> '.
"</td>\n".
'<td class="nowrap">'.
html::escapeHTML($this->rs->cat_title).
"</td>\n".
'<td class="nowrap">'.
html::escapeHTML($this->rs->link_note).'/20'.
"</td>\n".
'<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')).
"</td>\n".
'</tr>'."\n";
}
}

View file

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

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
$GLOBALS['__l10n']['update categories'] = 'mettre à jour les catégories';
?>