prepare to DC 2.24

This commit is contained in:
Jean-Christian Denis 2022-11-15 22:05:23 +01:00
parent 91805f7688
commit 222000a5fe
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
9 changed files with 123 additions and 113 deletions

View file

@ -14,44 +14,44 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
require dirname(__FILE__) . '/_widgets.php'; require __DIR__ . '/_widgets.php';
# Admin menu # Admin menu
if ($core->blog->settings->postwidgettext->postwidgettext_active) { if (dcCore::app()->blog->settings->postwidgettext->postwidgettext_active) {
$_menu['Plugins']->addItem( dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
__('Post widget text'), __('Post widget text'),
$core->adminurl->get('admin.plugin.postWidgetText'), dcCore::app()->adminurl->get('admin.plugin.postWidgetText'),
dcPage::getPF('postWidgetText/icon.png'), dcPage::getPF('postWidgetText/icon.png'),
preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.postWidgetText')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.postWidgetText')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
$core->auth->check('contentadmin', $core->blog->id) dcCore::app()->auth->check(dcAuth::PERMISSION_CONTENT_ADMIN, dcCore::app()->blog->id)
); );
$core->addBehavior('adminDashboardFavorites', ['adminPostWidgetText', 'adminDashboardFavorites']); dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['adminPostWidgetText', 'adminDashboardFavorites']);
} }
# Pref # Pref
$core->addBehavior('adminFiltersLists', ['adminPostWidgetText', 'adminFiltersLists']); dcCore::app()->addBehavior('adminFiltersListsV2', ['adminPostWidgetText', 'adminFiltersLists']);
$core->addBehavior('adminBlogPreferencesForm', ['adminPostWidgetText', 'adminBlogPreferencesForm']); dcCore::app()->addBehavior('adminBlogPreferencesFormV2', ['adminPostWidgetText', 'adminBlogPreferencesForm']);
$core->addBehavior('adminBeforeBlogSettingsUpdate', ['adminPostWidgetText', 'adminBeforeBlogSettingsUpdate']); dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', ['adminPostWidgetText', 'adminBeforeBlogSettingsUpdate']);
# Post # Post
$core->addBehavior('adminPostHeaders', ['adminPostWidgetText', 'adminPostHeaders']); dcCore::app()->addBehavior('adminPostHeaders', ['adminPostWidgetText', 'adminPostHeaders']);
$core->addBehavior('adminPostFormItems', ['adminPostWidgetText', 'adminPostFormItems']); dcCore::app()->addBehavior('adminPostFormItems', ['adminPostWidgetText', 'adminPostFormItems']);
$core->addBehavior('adminAfterPostUpdate', ['adminPostWidgetText', 'adminAfterPostSave']); dcCore::app()->addBehavior('adminAfterPostUpdate', ['adminPostWidgetText', 'adminAfterPostSave']);
$core->addBehavior('adminAfterPostCreate', ['adminPostWidgetText', 'adminAfterPostSave']); dcCore::app()->addBehavior('adminAfterPostCreate', ['adminPostWidgetText', 'adminAfterPostSave']);
$core->addBehavior('adminBeforePostDelete', ['adminPostWidgetText', 'adminBeforePostDelete']); dcCore::app()->addBehavior('adminBeforePostDelete', ['adminPostWidgetText', 'adminBeforePostDelete']);
# Plugin "pages" # Plugin "pages"
$core->addBehavior('adminPageHeaders', ['adminPostWidgetText', 'adminPostHeaders']); dcCore::app()->addBehavior('adminPageHeaders', ['adminPostWidgetText', 'adminPostHeaders']);
$core->addBehavior('adminPageFormItems', ['adminPostWidgetText', 'adminPostFormItems']); dcCore::app()->addBehavior('adminPageFormItems', ['adminPostWidgetText', 'adminPostFormItems']);
$core->addBehavior('adminAfterPageUpdate', ['adminPostWidgetText', 'adminAfterPostSave']); dcCore::app()->addBehavior('adminAfterPageUpdate', ['adminPostWidgetText', 'adminAfterPostSave']);
$core->addBehavior('adminAfterPageCreate', ['adminPostWidgetText', 'adminAfterPostSave']); dcCore::app()->addBehavior('adminAfterPageCreate', ['adminPostWidgetText', 'adminAfterPostSave']);
$core->addBehavior('adminBeforePageDelete', ['adminPostWidgetText', 'adminBeforePostDelete']); dcCore::app()->addBehavior('adminBeforePageDelete', ['adminPostWidgetText', 'adminBeforePostDelete']);
# Plugin "importExport" # Plugin "importExport"
if ($core->blog->settings->postwidgettext->postwidgettext_importexport_active) { if (dcCore::app()->blog->settings->postwidgettext->postwidgettext_importexport_active) {
$core->addBehavior('exportFull', ['adminPostWidgetText', 'exportFull']); dcCore::app()->addBehavior('exportFull', ['adminPostWidgetText', 'exportFull']);
$core->addBehavior('exportSingle', ['adminPostWidgetText', 'exportSingle']); dcCore::app()->addBehavior('exportSingle', ['adminPostWidgetText', 'exportSingle']);
$core->addBehavior('importInit', ['adminPostWidgetText', 'importInit']); dcCore::app()->addBehavior('importInit', ['adminPostWidgetText', 'importInit']);
$core->addBehavior('importSingle', ['adminPostWidgetText', 'importSingle']); dcCore::app()->addBehavior('importSingle', ['adminPostWidgetText', 'importSingle']);
$core->addBehavior('importFull', ['adminPostWidgetText', 'importFull']); dcCore::app()->addBehavior('importFull', ['adminPostWidgetText', 'importFull']);
} }

View file

@ -18,10 +18,13 @@ $this->registerModule(
'Post widget text', 'Post widget text',
'Add a widget with a text related to an entry', 'Add a widget with a text related to an entry',
'Jean-Christian Denis and Contributors', 'Jean-Christian Denis and Contributors',
'2021.11.06', '2022.11.12',
[ [
'requires' => [['core', '2.20']], 'requires' => [['core', '2.24']],
'permissions' => 'usage,contentadmin', 'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_USAGE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]),
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://github.com/JcDenis/postWidgetText', 'support' => 'https://github.com/JcDenis/postWidgetText',
'details' => 'https://plugins.dotaddict.org/dc2/details/postWidgetText', 'details' => 'https://plugins.dotaddict.org/dc2/details/postWidgetText',

View file

@ -14,8 +14,8 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$new_version = $core->plugins->moduleInfo('postWidgetText', 'version'); $new_version = dcCore::app()->plugins->moduleInfo('postWidgetText', 'version');
$old_version = $core->getVersion('postWidgetText'); $old_version = dcCore::app()->getVersion('postWidgetText');
if (version_compare($old_version, $new_version, '>=')) { if (version_compare($old_version, $new_version, '>=')) {
return; return;
@ -24,7 +24,7 @@ if (version_compare($old_version, $new_version, '>=')) {
try { try {
# Table is the same for plugins # Table is the same for plugins
# pollsFactory, postTask, postWidgetText # pollsFactory, postTask, postWidgetText
$s = new dbStruct($core->con, $core->prefix); $s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
$s->post_option $s->post_option
->option_id('bigint', 0, false) ->option_id('bigint', 0, false)
->post_id('bigint', 0, false) ->post_id('bigint', 0, false)
@ -41,12 +41,12 @@ try {
->index('idx_post_option_post', 'btree', 'post_id') ->index('idx_post_option_post', 'btree', 'post_id')
->index('idx_post_option_type', 'btree', 'option_type'); ->index('idx_post_option_type', 'btree', 'option_type');
$si = new dbStruct($core->con, $core->prefix); $si = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
$changes = $si->synchronize($s); $changes = $si->synchronize($s);
# Settings # Settings
$core->blog->settings->addNamespace('postwidgettext'); dcCore::app()->blog->settings->addNamespace('postwidgettext');
$core->blog->settings->postwidgettext->put( dcCore::app()->blog->settings->postwidgettext->put(
'postwidgettext_active', 'postwidgettext_active',
true, true,
'boolean', 'boolean',
@ -54,7 +54,7 @@ try {
false, false,
true true
); );
$core->blog->settings->postwidgettext->put( dcCore::app()->blog->settings->postwidgettext->put(
'postwidgettext_importexport_active', 'postwidgettext_importexport_active',
true, true,
'boolean', 'boolean',
@ -64,18 +64,18 @@ try {
); );
# Transfert records from old table to the new one # Transfert records from old table to the new one
if ($core->getVersion('postWidgetText') !== null if (dcCore::app()->getVersion('postWidgetText') !== null
&& version_compare($core->getVersion('postWidgetText'), '0.5', '<') && version_compare(dcCore::app()->getVersion('postWidgetText'), '0.5', '<')
) { ) {
require_once dirname(__FILE__) . '/inc/patch.0.5.php'; require_once __DIR__ . '/inc/patch.0.5.php';
} }
# Set module version # Set module version
$core->setVersion('postWidgetText', $new_version); dcCore::app()->setVersion('postWidgetText', $new_version);
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
return false; return false;

View file

@ -14,9 +14,9 @@ if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$core->blog->settings->addNamespace('postwidgettext'); dcCore::app()->blog->settings->addNamespace('postwidgettext');
$core->addBehavior('initWidgets', ['postWidgetTextWidget', 'init']); dcCore::app()->addBehavior('initWidgets', ['postWidgetTextWidget', 'init']);
/** /**
* @ingroup DC_PLUGIN_POSTWIDGETTEXT * @ingroup DC_PLUGIN_POSTWIDGETTEXT
@ -55,15 +55,13 @@ class postWidgetTextWidget
public static function display($w) public static function display($w)
{ {
global $core, $_ctx;
if ($w->offline) { if ($w->offline) {
return null; return null;
} }
if (!$core->blog->settings->postwidgettext->postwidgettext_active if (!dcCore::app()->blog->settings->postwidgettext->postwidgettext_active
|| !$_ctx->exists('posts') || !dcCore::app()->ctx->exists('posts')
|| !$_ctx->posts->post_id || !dcCore::app()->ctx->posts->post_id
) { ) {
return null; return null;
} }
@ -71,8 +69,8 @@ class postWidgetTextWidget
$title = $w->title ?: null; $title = $w->title ?: null;
$content = ''; $content = '';
$pwt = new postWidgetText($core); $pwt = new postWidgetText();
$rs = $pwt->getWidgets(['post_id' => $_ctx->posts->post_id]); $rs = $pwt->getWidgets(['post_id' => dcCore::app()->ctx->posts->post_id]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return null; return null;
@ -85,7 +83,7 @@ class postWidgetTextWidget
$content = $rs->option_content_xhtml; $content = $rs->option_content_xhtml;
} }
if ('' == $content && $w->excerpt) { if ('' == $content && $w->excerpt) {
$content = $_ctx->posts->post_excerpt_xhtml; $content = dcCore::app()->ctx->posts->post_excerpt_xhtml;
} }
return $w->renderDiv( return $w->renderDiv(

View file

@ -21,17 +21,15 @@ if (!defined('DC_RC_PATH')) {
*/ */
class postWidgetText class postWidgetText
{ {
public $core;
public $con; public $con;
private $table; private $table;
private $blog; private $blog;
public function __construct($core) public function __construct()
{ {
$this->core = & $core; $this->con = dcCore::app()->con;
$this->con = & $this->core->con; $this->table = dcCore::app()->prefix . 'post_option';
$this->table = $this->core->prefix . 'post_option'; $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id);
$this->blog = $core->con->escape($core->blog->id);
} }
public function tableName() public function tableName()
@ -56,7 +54,7 @@ class postWidgetText
public function triggerBlog() public function triggerBlog()
{ {
$this->core->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
} }
public function getWidgets($params, $count_only = false) public function getWidgets($params, $count_only = false)
@ -77,7 +75,7 @@ class postWidgetText
if (!isset($params['from'])) { if (!isset($params['from'])) {
$params['from'] = ''; $params['from'] = '';
} }
$params['from'] .= 'LEFT JOIN ' . $this->table . ' W ON P.post_id=W.post_id '; $params['join'] = 'LEFT JOIN ' . $this->table . ' W ON P.post_id=W.post_id ';
if (!isset($params['sql'])) { if (!isset($params['sql'])) {
$params['sql'] = ''; $params['sql'] = '';
@ -92,12 +90,15 @@ class postWidgetText
$params['post_type'] = ''; $params['post_type'] = '';
} }
return $this->core->blog->getPosts($params, $count_only); return dcCore::app()->blog->getPosts($params, $count_only);
} }
public function addWidget($cur) public function addWidget($cur)
{ {
if (!$this->core->auth->check('usage,contentadmin', $this->blog)) { if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_USAGE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]), $this->blog)) {
throw new Exception(__('You are not allowed to create an entry text widget')); throw new Exception(__('You are not allowed to create an entry text widget'));
} }
if ($cur->post_id == '') { if ($cur->post_id == '') {
@ -135,7 +136,10 @@ class postWidgetText
public function updWidget($id, &$cur) public function updWidget($id, &$cur)
{ {
if (!$this->core->auth->check('usage,contentadmin', $this->blog)) { if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_USAGE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]), $this->blog)) {
throw new Exception(__('You are not allowed to update entries text widget')); throw new Exception(__('You are not allowed to update entries text widget'));
} }
@ -149,9 +153,9 @@ class postWidgetText
$cur->option_upddt = date('Y-m-d H:i:s'); $cur->option_upddt = date('Y-m-d H:i:s');
if (!$this->core->auth->check('contentadmin', $this->blog)) { if (!dcCore::app()->auth->check(dcAuth::PERMISSION_CONTENT_ADMIN, $this->blog)) {
$params['option_id'] = $id; $params['option_id'] = $id;
$params['user_id'] = $this->con->escape($this->core->auth->userID()); $params['user_id'] = $this->con->escape(dcCore::app()->auth->userID());
$params['no_content'] = true; $params['no_content'] = true;
$params['limit'] = 1; $params['limit'] = 1;
@ -168,7 +172,10 @@ class postWidgetText
public function delWidget($id, $type = 'postwidgettext') public function delWidget($id, $type = 'postwidgettext')
{ {
if (!$this->core->auth->check('delete,contentadmin', $this->blog)) { if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_DELETE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]), $this->blog)) {
throw new Exception(__('You are not allowed to delete entries text widget')); throw new Exception(__('You are not allowed to delete entries text widget'));
} }
@ -178,9 +185,9 @@ class postWidgetText
throw new Exception(__('No such ID')); throw new Exception(__('No such ID'));
} }
if (!$this->core->auth->check('contentadmin', $this->blog)) { if (!dcCore::app()->auth->check(dcAuth::PERMISSION_CONTENT_ADMIN, $this->blog)) {
$params['option_id'] = $id; $params['option_id'] = $id;
$params['user_id'] = $this->con->escape($this->core->auth->userID()); $params['user_id'] = $this->con->escape(dcCore::app()->auth->userID());
$params['no_content'] = true; $params['no_content'] = true;
$params['limit'] = 1; $params['limit'] = 1;
@ -220,16 +227,16 @@ class postWidgetText
public function setWidgetContent($option_id, $format, $lang, &$content, &$content_xhtml) public function setWidgetContent($option_id, $format, $lang, &$content, &$content_xhtml)
{ {
if ($format == 'wiki') { if ($format == 'wiki') {
$this->core->initWikiPost(); dcCore::app()->initWikiPost();
$this->core->wiki2xhtml->setOpt('note_prefix', 'wnote-' . $option_id); dcCore::app()->wiki2xhtml->setOpt('note_prefix', 'wnote-' . $option_id);
if (strpos($lang, 'fr') === 0) { if (strpos($lang, 'fr') === 0) {
$this->core->wiki2xhtml->setOpt('active_fr_syntax', 1); dcCore::app()->wiki2xhtml->setOpt('active_fr_syntax', 1);
} }
} }
if ($content) { if ($content) {
$content_xhtml = $this->core->callFormater($format, $content); $content_xhtml = dcCore::app()->callFormater($format, $content);
$content_xhtml = $this->core->HTMLfilter($content_xhtml); $content_xhtml = dcCore::app()->HTMLfilter($content_xhtml);
} else { } else {
$content_xhtml = ''; $content_xhtml = '';
} }
@ -237,7 +244,7 @@ class postWidgetText
$excerpt = $excerpt_xhtml = ''; $excerpt = $excerpt_xhtml = '';
# --BEHAVIOR-- coreAfterPostContentFormat # --BEHAVIOR-- coreAfterPostContentFormat
$this->core->callBehavior('coreAfterPostContentFormat', [ dcCore::app()->callBehavior('coreAfterPostContentFormat', [
'excerpt' => &$excerpt, 'excerpt' => &$excerpt,
'content' => &$content, 'content' => &$content,
'excerpt_xhtml' => &$excerpt_xhtml, 'excerpt_xhtml' => &$excerpt_xhtml,

View file

@ -27,7 +27,7 @@ class adminPostWidgetText
]; ];
} }
public static function adminFiltersLists(dcCore $core, $sorts) public static function adminFiltersLists($sorts)
{ {
$sorts['pwt'] = [ $sorts['pwt'] = [
__('Post widget text'), __('Post widget text'),
@ -38,7 +38,7 @@ class adminPostWidgetText
]; ];
} }
public static function adminBlogPreferencesForm(dcCore $core, dcSettings $blog_settings) public static function adminBlogPreferencesForm(dcSettings $blog_settings)
{ {
echo ' echo '
<div class="fieldset"> <div class="fieldset">
@ -65,14 +65,14 @@ class adminPostWidgetText
$blog_settings->postwidgettext->put('postwidgettext_importexport_active', !empty($_POST['importexport_active'])); $blog_settings->postwidgettext->put('postwidgettext_importexport_active', !empty($_POST['importexport_active']));
} }
public static function adminDashboardFavorites(dcCore $core, $favs) public static function adminDashboardFavorites(dcFavorites $favs)
{ {
$favs->register('postWidgetText', [ $favs->register('postWidgetText', [
'title' => __('Post widget text'), 'title' => __('Post widget text'),
'url' => $core->adminurl->get('admin.plugin.postWidgetText'), 'url' => dcCore::app()->adminurl->get('admin.plugin.postWidgetText'),
'small-icon' => dcPage::getPF('postWidgetText/icon.png'), 'small-icon' => dcPage::getPF('postWidgetText/icon.png'),
'large-icon' => dcPage::getPF('postWidgetText/icon-big.png'), 'large-icon' => dcPage::getPF('postWidgetText/icon-big.png'),
'permissions' => $core->auth->check('usage,contentadmin', $core->blog->id), 'permissions' => dcCore::app()->auth->check('usage,contentadmin', dcCore::app()->blog->id),
'active_cb' => ['adminPostWidgetText', 'adminDashboardFavoritesActive'] 'active_cb' => ['adminPostWidgetText', 'adminDashboardFavoritesActive']
]); ]);
} }
@ -92,11 +92,10 @@ class adminPostWidgetText
public static function adminPostHeaders() public static function adminPostHeaders()
{ {
global $core; $editor = dcCore::app()->auth->getOption('editor');
$editor = $core->auth->getOption('editor');
return return
$core->callBehavior('adminPostEditor', $editor['xhtml'], 'pwt', ['#post_wtext'], 'xhtml') . dcCore::app()->callBehavior('adminPostEditor', $editor['xhtml'], 'pwt', ['#post_wtext'], 'xhtml') .
dcPage::jsLoad(dcPage::getPF('postWidgetText/js/post.js')); dcPage::jsLoad(dcPage::getPF('postWidgetText/js/post.js'));
} }
@ -110,7 +109,7 @@ class adminPostWidgetText
if ($post) { if ($post) {
$post_id = (int) $post->post_id; $post_id = (int) $post->post_id;
$pwt = new postWidgetText($GLOBALS['core']); $pwt = new postWidgetText();
$w = $pwt->getWidgets(['post_id' => $post_id]); $w = $pwt->getWidgets(['post_id' => $post_id]);
# Existing widget # Existing widget
@ -145,7 +144,7 @@ class adminPostWidgetText
$content = $_POST['post_wtext'] ?? ''; $content = $_POST['post_wtext'] ?? '';
# Object # Object
$pwt = new postWidgetText($GLOBALS['core']); $pwt = new postWidgetText();
# Get existing widget # Get existing widget
$w = $pwt->getWidgets(['post_id' => $post_id]); $w = $pwt->getWidgets(['post_id' => $post_id]);
@ -181,7 +180,7 @@ class adminPostWidgetText
$post_id = (int) $post_id; $post_id = (int) $post_id;
# Object # Object
$pwt = new postWidgetText($GLOBALS['core']); $pwt = new postWidgetText();
# Get existing widget # Get existing widget
$w = $pwt->getWidgets(['post_id' => $post_id]); $w = $pwt->getWidgets(['post_id' => $post_id]);
@ -198,8 +197,8 @@ class adminPostWidgetText
'postwidgettext', 'postwidgettext',
'SELECT option_type, option_content, ' . 'SELECT option_type, option_content, ' .
'option_content_xhtml, W.post_id ' . 'option_content_xhtml, W.post_id ' .
'FROM ' . $core->prefix . 'post_option W ' . 'FROM ' . dcCore::app()->prefix . 'post_option W ' .
'LEFT JOIN ' . $core->prefix . 'post P ' . 'LEFT JOIN ' . dcCore::app()->prefix . 'post P ' .
'ON P.post_id = W.post_id ' . 'ON P.post_id = W.post_id ' .
"WHERE P.blog_id = '" . $blog_id . "' " . "WHERE P.blog_id = '" . $blog_id . "' " .
"AND W.option_type = 'postwidgettext' " "AND W.option_type = 'postwidgettext' "
@ -212,8 +211,8 @@ class adminPostWidgetText
'postwidgettext', 'postwidgettext',
'SELECT option_type, option_content, ' . 'SELECT option_type, option_content, ' .
'option_content_xhtml, W.post_id ' . 'option_content_xhtml, W.post_id ' .
'FROM ' . $core->prefix . 'post_option W ' . 'FROM ' . dcCore::app()->prefix . 'post_option W ' .
'LEFT JOIN ' . $core->prefix . 'post P ' . 'LEFT JOIN ' . dcCore::app()->prefix . 'post P ' .
'ON P.post_id = W.post_id ' . 'ON P.post_id = W.post_id ' .
"WHERE W.option_type = 'postwidgettext' " "WHERE W.option_type = 'postwidgettext' "
); );
@ -221,10 +220,10 @@ class adminPostWidgetText
public static function importInit($bk, dcCore $core) public static function importInit($bk, dcCore $core)
{ {
$bk->cur_postwidgettext = $core->con->openCursor( $bk->cur_postwidgettext = dcCore::app()->con->openCursor(
$core->prefix . 'post_option' dcCore::app()->prefix . 'post_option'
); );
$bk->postwidgettext = new postWidgetText($core); $bk->postwidgettext = new postWidgetText();
} }
public static function importSingle($line, $bk, dcCore $core) public static function importSingle($line, $bk, dcCore $core)

View file

@ -71,7 +71,7 @@ class listPostWidgetText extends adminGenericList
!$this->rs->isEditable() !$this->rs->isEditable()
) . '</td>' . ) . '</td>' .
'<td class="maximal"><a href="' . '<td class="maximal"><a href="' .
$this->core->getPostAdminURL( dcCore::app()->getPostAdminURL(
$this->rs->post_type, $this->rs->post_type,
$this->rs->post_id $this->rs->post_id
) . '#post-wtext-form">' . ) . '#post-wtext-form">' .

View file

@ -10,18 +10,18 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
$records = $core->con->select( $records = dcCore::app()->con->select(
'SELECT W.*, P.post_lang, P.post_format FROM ' . $core->prefix . 'post_wtext W ' . 'SELECT W.*, P.post_lang, P.post_format FROM ' . dcCore::app()->prefix . 'post_wtext W ' .
'LEFT JOIN ' . $core->prefix . 'post P ON P.post_id=W.post_id ' 'LEFT JOIN ' . dcCore::app()->prefix . 'post P ON P.post_id=W.post_id '
); );
if (!$records->isEmpty()) { if (!$records->isEmpty()) {
$cur = $core->con->openCursor($core->prefix . 'post_option'); $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'post_option');
while ($records->fetch()) { while ($records->fetch()) {
$core->con->writeLock($core->prefix . 'post_option'); dcCore::app()->con->writeLock(dcCore::app()->prefix . 'post_option');
try { try {
$id = $core->con->select( $id = dcCore::app()->con->select(
'SELECT MAX(option_id) FROM ' . $core->prefix . 'post_option' 'SELECT MAX(option_id) FROM ' . dcCore::app()->prefix . 'post_option'
)->f(0) + 1; )->f(0) + 1;
$cur->clean(); $cur->clean();
@ -38,9 +38,9 @@ if (!$records->isEmpty()) {
$cur->option_content_xhtml = $records->wtext_content_xhtml; $cur->option_content_xhtml = $records->wtext_content_xhtml;
$cur->insert(); $cur->insert();
$core->con->unlock(); dcCore::app()->con->unlock();
} catch (Exception $e) { } catch (Exception $e) {
$core->con->unlock(); dcCore::app()->con->unlock();
throw $e; throw $e;
} }

View file

@ -14,9 +14,12 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
dcPage::check('usage,contentadmin'); dcPage::check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_USAGE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]));
$pwt = new postWidgetText($core); $pwt = new postWidgetText();
# Delete widgets # Delete widgets
if (!empty($_POST['save']) && !empty($_POST['widgets'])) { if (!empty($_POST['save']) && !empty($_POST['widgets'])) {
@ -26,21 +29,21 @@ if (!empty($_POST['save']) && !empty($_POST['widgets'])) {
$pwt->delWidget($id); $pwt->delWidget($id);
} }
dcPage::addSuccessNotice( dcAdminNotices::addSuccessNotice(
__('Posts widgets successfully delete.') __('Posts widgets successfully delete.')
); );
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
$core->adminurl->redirect('admin.plugin.postWidgetText'); dcCore::app()->adminurl->redirect('admin.plugin.postWidgetText');
} }
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
# filters # filters
$filter = new adminGenericFilter($core, 'pwt'); $filter = new adminGenericFilter(dcCore::app(), 'pwt');
$filter->add(dcAdminFilters::getPageFilter()); $filter->add(dcAdminFilters::getPageFilter());
$params = $filter->params(); $params = $filter->params();
@ -48,16 +51,16 @@ $params = $filter->params();
try { try {
$posts = $pwt->getWidgets($params); $posts = $pwt->getWidgets($params);
$counter = $pwt->getWidgets($params, true); $counter = $pwt->getWidgets($params, true);
$posts_list = new listPostWidgetText($core, $posts, $counter->f(0)); $posts_list = new listPostWidgetText(dcCore::app(), $posts, $counter->f(0));
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
# Display # Display
echo ' echo '
<html><head><title>' . __('Post widget text') . '</title>' . <html><head><title>' . __('Post widget text') . '</title>' .
dcPage::jsLoad(dcPage::getPF('postWidgetText/js/index.js')) . dcPage::jsLoad(dcPage::getPF('postWidgetText/js/index.js')) .
$filter->js($core->adminurl->get('admin.plugin.postWidgetText')) . ' $filter->js(dcCore::app()->adminurl->get('admin.plugin.postWidgetText')) . '
</head> </head>
<body>' . <body>' .
@ -72,14 +75,14 @@ $filter->display('admin.plugin.postWidgetText', form::hidden('p', 'postWidgetTex
$posts_list->display( $posts_list->display(
$filter->page, $filter->page,
$filter->nb, $filter->nb,
'<form action="' . $core->adminurl->get('admin.plugin.postWidgetText') . '" method="post" id="form-entries">' . '<form action="' . dcCore::app()->adminurl->get('admin.plugin.postWidgetText') . '" method="post" id="form-entries">' .
'%s' . '%s' .
'<div class="two-cols">' . '<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>' . '<p class="col checkboxes-helpers"></p>' .
'<p class="col right">' . '<p class="col right">' .
'<input id="do-action" type="submit" name="save" value="' . __('Delete selected widgets') . '" /></p>' . '<input id="do-action" type="submit" name="save" value="' . __('Delete selected widgets') . '" /></p>' .
$core->adminurl->getHiddenFormFields('admin.plugin.postWidgetText', array_merge(['p' => 'postWidgetText'], $filter->values(true))) . dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.postWidgetText', array_merge(['p' => 'postWidgetText'], $filter->values(true))) .
$core->formNonce() . dcCore::app()->formNonce() .
'</div>' . '</div>' .
'</form>' '</form>'
); );