diff --git a/_admin.php b/_admin.php index d40adb8..7c99124 100644 --- a/_admin.php +++ b/_admin.php @@ -14,44 +14,44 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } -require dirname(__FILE__) . '/_widgets.php'; +require __DIR__ . '/_widgets.php'; # Admin menu -if ($core->blog->settings->postwidgettext->postwidgettext_active) { - $_menu['Plugins']->addItem( +if (dcCore::app()->blog->settings->postwidgettext->postwidgettext_active) { + dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('Post widget text'), - $core->adminurl->get('admin.plugin.postWidgetText'), + dcCore::app()->adminurl->get('admin.plugin.postWidgetText'), dcPage::getPF('postWidgetText/icon.png'), - preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.postWidgetText')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), - $core->auth->check('contentadmin', $core->blog->id) + preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.postWidgetText')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), + dcCore::app()->auth->check(dcAuth::PERMISSION_CONTENT_ADMIN, dcCore::app()->blog->id) ); - $core->addBehavior('adminDashboardFavorites', ['adminPostWidgetText', 'adminDashboardFavorites']); + dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['adminPostWidgetText', 'adminDashboardFavorites']); } # Pref -$core->addBehavior('adminFiltersLists', ['adminPostWidgetText', 'adminFiltersLists']); -$core->addBehavior('adminBlogPreferencesForm', ['adminPostWidgetText', 'adminBlogPreferencesForm']); -$core->addBehavior('adminBeforeBlogSettingsUpdate', ['adminPostWidgetText', 'adminBeforeBlogSettingsUpdate']); +dcCore::app()->addBehavior('adminFiltersListsV2', ['adminPostWidgetText', 'adminFiltersLists']); +dcCore::app()->addBehavior('adminBlogPreferencesFormV2', ['adminPostWidgetText', 'adminBlogPreferencesForm']); +dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', ['adminPostWidgetText', 'adminBeforeBlogSettingsUpdate']); # Post -$core->addBehavior('adminPostHeaders', ['adminPostWidgetText', 'adminPostHeaders']); -$core->addBehavior('adminPostFormItems', ['adminPostWidgetText', 'adminPostFormItems']); -$core->addBehavior('adminAfterPostUpdate', ['adminPostWidgetText', 'adminAfterPostSave']); -$core->addBehavior('adminAfterPostCreate', ['adminPostWidgetText', 'adminAfterPostSave']); -$core->addBehavior('adminBeforePostDelete', ['adminPostWidgetText', 'adminBeforePostDelete']); +dcCore::app()->addBehavior('adminPostHeaders', ['adminPostWidgetText', 'adminPostHeaders']); +dcCore::app()->addBehavior('adminPostFormItems', ['adminPostWidgetText', 'adminPostFormItems']); +dcCore::app()->addBehavior('adminAfterPostUpdate', ['adminPostWidgetText', 'adminAfterPostSave']); +dcCore::app()->addBehavior('adminAfterPostCreate', ['adminPostWidgetText', 'adminAfterPostSave']); +dcCore::app()->addBehavior('adminBeforePostDelete', ['adminPostWidgetText', 'adminBeforePostDelete']); # Plugin "pages" -$core->addBehavior('adminPageHeaders', ['adminPostWidgetText', 'adminPostHeaders']); -$core->addBehavior('adminPageFormItems', ['adminPostWidgetText', 'adminPostFormItems']); -$core->addBehavior('adminAfterPageUpdate', ['adminPostWidgetText', 'adminAfterPostSave']); -$core->addBehavior('adminAfterPageCreate', ['adminPostWidgetText', 'adminAfterPostSave']); -$core->addBehavior('adminBeforePageDelete', ['adminPostWidgetText', 'adminBeforePostDelete']); +dcCore::app()->addBehavior('adminPageHeaders', ['adminPostWidgetText', 'adminPostHeaders']); +dcCore::app()->addBehavior('adminPageFormItems', ['adminPostWidgetText', 'adminPostFormItems']); +dcCore::app()->addBehavior('adminAfterPageUpdate', ['adminPostWidgetText', 'adminAfterPostSave']); +dcCore::app()->addBehavior('adminAfterPageCreate', ['adminPostWidgetText', 'adminAfterPostSave']); +dcCore::app()->addBehavior('adminBeforePageDelete', ['adminPostWidgetText', 'adminBeforePostDelete']); # Plugin "importExport" -if ($core->blog->settings->postwidgettext->postwidgettext_importexport_active) { - $core->addBehavior('exportFull', ['adminPostWidgetText', 'exportFull']); - $core->addBehavior('exportSingle', ['adminPostWidgetText', 'exportSingle']); - $core->addBehavior('importInit', ['adminPostWidgetText', 'importInit']); - $core->addBehavior('importSingle', ['adminPostWidgetText', 'importSingle']); - $core->addBehavior('importFull', ['adminPostWidgetText', 'importFull']); +if (dcCore::app()->blog->settings->postwidgettext->postwidgettext_importexport_active) { + dcCore::app()->addBehavior('exportFull', ['adminPostWidgetText', 'exportFull']); + dcCore::app()->addBehavior('exportSingle', ['adminPostWidgetText', 'exportSingle']); + dcCore::app()->addBehavior('importInit', ['adminPostWidgetText', 'importInit']); + dcCore::app()->addBehavior('importSingle', ['adminPostWidgetText', 'importSingle']); + dcCore::app()->addBehavior('importFull', ['adminPostWidgetText', 'importFull']); } diff --git a/_define.php b/_define.php index 5cf8913..1e8dc01 100644 --- a/_define.php +++ b/_define.php @@ -18,10 +18,13 @@ $this->registerModule( 'Post widget text', 'Add a widget with a text related to an entry', 'Jean-Christian Denis and Contributors', - '2021.11.06', + '2022.11.12', [ - 'requires' => [['core', '2.20']], - 'permissions' => 'usage,contentadmin', + 'requires' => [['core', '2.24']], + 'permissions' => dcCore::app()->auth->makePermissions([ + dcAuth::PERMISSION_USAGE, + dcAuth::PERMISSION_CONTENT_ADMIN, + ]), 'type' => 'plugin', 'support' => 'https://github.com/JcDenis/postWidgetText', 'details' => 'https://plugins.dotaddict.org/dc2/details/postWidgetText', diff --git a/_install.php b/_install.php index 55d7794..f647767 100644 --- a/_install.php +++ b/_install.php @@ -14,8 +14,8 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } -$new_version = $core->plugins->moduleInfo('postWidgetText', 'version'); -$old_version = $core->getVersion('postWidgetText'); +$new_version = dcCore::app()->plugins->moduleInfo('postWidgetText', 'version'); +$old_version = dcCore::app()->getVersion('postWidgetText'); if (version_compare($old_version, $new_version, '>=')) { return; @@ -24,7 +24,7 @@ if (version_compare($old_version, $new_version, '>=')) { try { # Table is the same for plugins # pollsFactory, postTask, postWidgetText - $s = new dbStruct($core->con, $core->prefix); + $s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); $s->post_option ->option_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_type', 'btree', 'option_type'); - $si = new dbStruct($core->con, $core->prefix); + $si = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); $changes = $si->synchronize($s); # Settings - $core->blog->settings->addNamespace('postwidgettext'); - $core->blog->settings->postwidgettext->put( + dcCore::app()->blog->settings->addNamespace('postwidgettext'); + dcCore::app()->blog->settings->postwidgettext->put( 'postwidgettext_active', true, 'boolean', @@ -54,7 +54,7 @@ try { false, true ); - $core->blog->settings->postwidgettext->put( + dcCore::app()->blog->settings->postwidgettext->put( 'postwidgettext_importexport_active', true, 'boolean', @@ -64,18 +64,18 @@ try { ); # Transfert records from old table to the new one - if ($core->getVersion('postWidgetText') !== null - && version_compare($core->getVersion('postWidgetText'), '0.5', '<') + if (dcCore::app()->getVersion('postWidgetText') !== null + && 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 - $core->setVersion('postWidgetText', $new_version); + dcCore::app()->setVersion('postWidgetText', $new_version); return true; } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } return false; diff --git a/_widgets.php b/_widgets.php index 907b1a2..8c1babc 100644 --- a/_widgets.php +++ b/_widgets.php @@ -14,9 +14,9 @@ if (!defined('DC_RC_PATH')) { 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 @@ -55,15 +55,13 @@ class postWidgetTextWidget public static function display($w) { - global $core, $_ctx; - if ($w->offline) { return null; } - if (!$core->blog->settings->postwidgettext->postwidgettext_active - || !$_ctx->exists('posts') - || !$_ctx->posts->post_id + if (!dcCore::app()->blog->settings->postwidgettext->postwidgettext_active + || !dcCore::app()->ctx->exists('posts') + || !dcCore::app()->ctx->posts->post_id ) { return null; } @@ -71,8 +69,8 @@ class postWidgetTextWidget $title = $w->title ?: null; $content = ''; - $pwt = new postWidgetText($core); - $rs = $pwt->getWidgets(['post_id' => $_ctx->posts->post_id]); + $pwt = new postWidgetText(); + $rs = $pwt->getWidgets(['post_id' => dcCore::app()->ctx->posts->post_id]); if ($rs->isEmpty()) { return null; @@ -85,7 +83,7 @@ class postWidgetTextWidget $content = $rs->option_content_xhtml; } if ('' == $content && $w->excerpt) { - $content = $_ctx->posts->post_excerpt_xhtml; + $content = dcCore::app()->ctx->posts->post_excerpt_xhtml; } return $w->renderDiv( diff --git a/inc/class.postwidgettext.php b/inc/class.postwidgettext.php index 72da245..7be8b31 100644 --- a/inc/class.postwidgettext.php +++ b/inc/class.postwidgettext.php @@ -21,17 +21,15 @@ if (!defined('DC_RC_PATH')) { */ class postWidgetText { - public $core; public $con; private $table; private $blog; - public function __construct($core) + public function __construct() { - $this->core = & $core; - $this->con = & $this->core->con; - $this->table = $this->core->prefix . 'post_option'; - $this->blog = $core->con->escape($core->blog->id); + $this->con = dcCore::app()->con; + $this->table = dcCore::app()->prefix . 'post_option'; + $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id); } public function tableName() @@ -56,7 +54,7 @@ class postWidgetText public function triggerBlog() { - $this->core->blog->triggerBlog(); + dcCore::app()->blog->triggerBlog(); } public function getWidgets($params, $count_only = false) @@ -77,7 +75,7 @@ class postWidgetText if (!isset($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'])) { $params['sql'] = ''; @@ -92,12 +90,15 @@ class postWidgetText $params['post_type'] = ''; } - return $this->core->blog->getPosts($params, $count_only); + return dcCore::app()->blog->getPosts($params, $count_only); } 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')); } if ($cur->post_id == '') { @@ -135,7 +136,10 @@ class postWidgetText 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')); } @@ -149,9 +153,9 @@ class postWidgetText $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['user_id'] = $this->con->escape($this->core->auth->userID()); + $params['user_id'] = $this->con->escape(dcCore::app()->auth->userID()); $params['no_content'] = true; $params['limit'] = 1; @@ -168,7 +172,10 @@ class 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')); } @@ -178,9 +185,9 @@ class postWidgetText 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['user_id'] = $this->con->escape($this->core->auth->userID()); + $params['user_id'] = $this->con->escape(dcCore::app()->auth->userID()); $params['no_content'] = true; $params['limit'] = 1; @@ -220,16 +227,16 @@ class postWidgetText public function setWidgetContent($option_id, $format, $lang, &$content, &$content_xhtml) { if ($format == 'wiki') { - $this->core->initWikiPost(); - $this->core->wiki2xhtml->setOpt('note_prefix', 'wnote-' . $option_id); + dcCore::app()->initWikiPost(); + dcCore::app()->wiki2xhtml->setOpt('note_prefix', 'wnote-' . $option_id); if (strpos($lang, 'fr') === 0) { - $this->core->wiki2xhtml->setOpt('active_fr_syntax', 1); + dcCore::app()->wiki2xhtml->setOpt('active_fr_syntax', 1); } } if ($content) { - $content_xhtml = $this->core->callFormater($format, $content); - $content_xhtml = $this->core->HTMLfilter($content_xhtml); + $content_xhtml = dcCore::app()->callFormater($format, $content); + $content_xhtml = dcCore::app()->HTMLfilter($content_xhtml); } else { $content_xhtml = ''; } @@ -237,7 +244,7 @@ class postWidgetText $excerpt = $excerpt_xhtml = ''; # --BEHAVIOR-- coreAfterPostContentFormat - $this->core->callBehavior('coreAfterPostContentFormat', [ + dcCore::app()->callBehavior('coreAfterPostContentFormat', [ 'excerpt' => &$excerpt, 'content' => &$content, 'excerpt_xhtml' => &$excerpt_xhtml, diff --git a/inc/lib.pwt.admin.php b/inc/lib.pwt.admin.php index b9e2d71..f1101f6 100644 --- a/inc/lib.pwt.admin.php +++ b/inc/lib.pwt.admin.php @@ -27,7 +27,7 @@ class adminPostWidgetText ]; } - public static function adminFiltersLists(dcCore $core, $sorts) + public static function adminFiltersLists($sorts) { $sorts['pwt'] = [ __('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 '