update to PSR12

master
Jean-Christian Paul Denis 2021-11-06 16:11:19 +01:00
parent f024b01c85
commit 05a623e4fb
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
12 changed files with 203 additions and 208 deletions

View File

@ -1,7 +1,9 @@
dev dev
- ... - ...
- fix error on empty record on widget
- update to PS12
2021.11.01 2021.10.30
- clean up code - clean up code
- update license - update license
- update translations - update translations

View File

@ -10,12 +10,11 @@
* @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
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
require dirname(__FILE__).'/_widgets.php'; require dirname(__FILE__) . '/_widgets.php';
# Admin menu # Admin menu
if ($core->blog->settings->postwidgettext->postwidgettext_active) { if ($core->blog->settings->postwidgettext->postwidgettext_active) {

View File

@ -10,7 +10,6 @@
* @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
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -27,7 +26,7 @@ $this->registerModule(
'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',
'repository' => 'https://raw.githubusercontent.com/JcDenis/postWidgetText/master/dcstore.xml', 'repository' => 'https://raw.githubusercontent.com/JcDenis/postWidgetText/master/dcstore.xml',
'settings' => [ 'settings' => [
'blog' => '#params.pwt_params' 'blog' => '#params.pwt_params'
] ]
] ]

View File

@ -10,7 +10,6 @@
* @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
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -27,36 +26,48 @@ try {
# pollsFactory, postTask, postWidgetText # pollsFactory, postTask, postWidgetText
$s = new dbStruct($core->con, $core->prefix); $s = new dbStruct($core->con, $core->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)
->option_creadt ('timestamp', 0, false, 'now()') ->option_creadt('timestamp', 0, false, 'now()')
->option_upddt ('timestamp', 0, false, 'now()') ->option_upddt('timestamp', 0, false, 'now()')
->option_type ('varchar', 32, false, "''") ->option_type('varchar', 32, false, "''")
->option_format ('varchar', 32, false, "'xhtml'") ->option_format('varchar', 32, false, "'xhtml'")
->option_lang ('varchar', 5, true, null) ->option_lang('varchar', 5, true, null)
->option_title ('varchar', 255, true, null) ->option_title('varchar', 255, true, null)
->option_content ('text', 0, true, null) ->option_content('text', 0, true, null)
->option_content_xhtml ('text', 0, false) ->option_content_xhtml('text', 0, false)
->index('idx_post_option_option', 'btree', 'option_id') ->index('idx_post_option_option', 'btree', 'option_id')
->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($core->con, $core->prefix);
$changes = $si->synchronize($s); $changes = $si->synchronize($s);
# Settings # Settings
$core->blog->settings->addNamespace('postwidgettext'); $core->blog->settings->addNamespace('postwidgettext');
$core->blog->settings->postwidgettext->put('postwidgettext_active', $core->blog->settings->postwidgettext->put(
true, 'boolean', 'post widget text plugin enabled', false, true); 'postwidgettext_active',
$core->blog->settings->postwidgettext->put('postwidgettext_importexport_active', true,
true, 'boolean', 'activate import/export behaviors', false, true); 'boolean',
'post widget text plugin enabled',
false,
true
);
$core->blog->settings->postwidgettext->put(
'postwidgettext_importexport_active',
true,
'boolean',
'activate import/export behaviors',
false,
true
);
# Transfert records from old table to the new one # Transfert records from old table to the new one
if ($core->getVersion('postWidgetText') !== null if ($core->getVersion('postWidgetText') !== null
&& version_compare($core->getVersion('postWidgetText'), '0.5', '<') && version_compare($core->getVersion('postWidgetText'), '0.5', '<')
) { ) {
require_once dirname(__FILE__).'/inc/patch.0.5.php'; require_once dirname(__FILE__) . '/inc/patch.0.5.php';
} }
# Set module version # Set module version

View File

@ -10,7 +10,6 @@
* @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
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }

View File

@ -10,9 +10,8 @@
* @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
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
require dirname(__FILE__).'/_widgets.php'; require dirname(__FILE__) . '/_widgets.php';

View File

@ -10,7 +10,6 @@
* @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
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -69,11 +68,11 @@ class postWidgetTextWidget
return null; return null;
} }
$title = $w->title ?: null; $title = $w->title ?: null;
$content = ''; $content = '';
$pwt = new postWidgetText($core); $pwt = new postWidgetText($core);
$rs = $pwt->getWidgets(['post_id' => $_ctx->posts->post_id]); $rs = $pwt->getWidgets(['post_id' => $_ctx->posts->post_id]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return null; return null;

View File

@ -10,7 +10,6 @@
* @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
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -29,10 +28,10 @@ class postWidgetText
public function __construct($core) public function __construct($core)
{ {
$this->core =& $core; $this->core = & $core;
$this->con =& $this->core->con; $this->con = & $this->core->con;
$this->table = $this->core->prefix . 'post_option'; $this->table = $this->core->prefix . 'post_option';
$this->blog = $core->con->escape($core->blog->id); $this->blog = $core->con->escape($core->blog->id);
} }
public function tableName() public function tableName()
@ -62,7 +61,9 @@ class postWidgetText
public function getWidgets($params, $count_only = false) public function getWidgets($params, $count_only = false)
{ {
if (!isset($params['columns'])) $params['columns'] = []; if (!isset($params['columns'])) {
$params['columns'] = [];
}
$params['columns'][] = 'option_id'; $params['columns'][] = 'option_id';
$params['columns'][] = 'option_creadt'; $params['columns'][] = 'option_creadt';
$params['columns'][] = 'option_upddt'; $params['columns'][] = 'option_upddt';
@ -83,8 +84,7 @@ class postWidgetText
} }
if (isset($params['option_type'])) { if (isset($params['option_type'])) {
$params['sql'] .= "AND W.option_type = '" . $this->con->escape($params['option_type']) . "' "; $params['sql'] .= "AND W.option_type = '" . $this->con->escape($params['option_type']) . "' ";
} } else {
else {
$params['sql'] .= "AND W.option_type = 'postwidgettext' "; $params['sql'] .= "AND W.option_type = 'postwidgettext' ";
} }
unset($params['option_type']); unset($params['option_type']);
@ -107,23 +107,24 @@ class postWidgetText
} }
$this->lockTable(); $this->lockTable();
try { try {
$rs = $this->con->select( $rs = $this->con->select(
'SELECT MAX(option_id) '. 'SELECT MAX(option_id) ' .
'FROM ' . $this->table 'FROM ' . $this->table
); );
$cur->option_id = (integer) $rs->f(0) + 1; $cur->option_id = (int) $rs->f(0) + 1;
$cur->option_creadt = date('Y-m-d H:i:s'); $cur->option_creadt = date('Y-m-d H:i:s');
$cur->option_upddt = date('Y-m-d H:i:s'); $cur->option_upddt = date('Y-m-d H:i:s');
$this->getWidgetContent($cur, $cur->option_id); $this->getWidgetContent($cur, $cur->option_id);
$cur->insert(); $cur->insert();
$this->unlockTable(); $this->unlockTable();
} } catch (Exception $e) {
catch (Exception $e) {
$this->unlockTable(); $this->unlockTable();
throw $e; throw $e;
} }
@ -138,7 +139,7 @@ class postWidgetText
throw new Exception(__('You are not allowed to update entries text widget')); throw new Exception(__('You are not allowed to update entries text widget'));
} }
$id = (integer) $id; $id = (int) $id;
if (empty($id)) { if (empty($id)) {
throw new Exception(__('No such ID')); throw new Exception(__('No such ID'));
@ -149,10 +150,10 @@ 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 (!$this->core->auth->check('contentadmin', $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($this->core->auth->userID());
$params['no_content'] = true; $params['no_content'] = true;
$params['limit'] = 1; $params['limit'] = 1;
$rs = $this->getWidgets($params); $rs = $this->getWidgets($params);
@ -171,17 +172,17 @@ class postWidgetText
throw new Exception(__('You are not allowed to delete entries text widget')); throw new Exception(__('You are not allowed to delete entries text widget'));
} }
$id = (integer) $id; $id = (int) $id;
if (empty($id)) { if (empty($id)) {
throw new Exception(__('No such ID')); throw new Exception(__('No such ID'));
} }
if (!$this->core->auth->check('contentadmin', $this->blog)) { if (!$this->core->auth->check('contentadmin', $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($this->core->auth->userID());
$params['no_content'] = true; $params['no_content'] = true;
$params['limit'] = 1; $params['limit'] = 1;
$rs = $this->getWidgets($params); $rs = $this->getWidgets($params);
@ -201,15 +202,18 @@ class postWidgetText
private function getWidgetContent(&$cur, $option_id) private function getWidgetContent(&$cur, $option_id)
{ {
$option_content = $cur->option_content; $option_content = $cur->option_content;
$option_content_xhtml = $cur->option_content_xhtml; $option_content_xhtml = $cur->option_content_xhtml;
$this->setWidgetContent( $this->setWidgetContent(
$option_id,$cur->option_format,$cur->option_lang, $option_id,
$option_content,$option_content_xhtml $cur->option_format,
$cur->option_lang,
$option_content,
$option_content_xhtml
); );
$cur->option_content = $option_content; $cur->option_content = $option_content;
$cur->option_content_xhtml = $option_content_xhtml; $cur->option_content_xhtml = $option_content_xhtml;
} }
@ -217,7 +221,7 @@ class postWidgetText
{ {
if ($format == 'wiki') { if ($format == 'wiki') {
$this->core->initWikiPost(); $this->core->initWikiPost();
$this->core->wiki2xhtml->setOpt('note_prefix','wnote-' . $option_id); $this->core->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); $this->core->wiki2xhtml->setOpt('active_fr_syntax', 1);
} }
@ -226,8 +230,7 @@ class postWidgetText
if ($content) { if ($content) {
$content_xhtml = $this->core->callFormater($format, $content); $content_xhtml = $this->core->callFormater($format, $content);
$content_xhtml = $this->core->HTMLfilter($content_xhtml); $content_xhtml = $this->core->HTMLfilter($content_xhtml);
} } else {
else {
$content_xhtml = ''; $content_xhtml = '';
} }
@ -235,8 +238,8 @@ class postWidgetText
# --BEHAVIOR-- coreAfterPostContentFormat # --BEHAVIOR-- coreAfterPostContentFormat
$this->core->callBehavior('coreAfterPostContentFormat', [ $this->core->callBehavior('coreAfterPostContentFormat', [
'excerpt' => &$excerpt, 'excerpt' => &$excerpt,
'content' => &$content, 'content' => &$content,
'excerpt_xhtml' => &$excerpt_xhtml, 'excerpt_xhtml' => &$excerpt_xhtml,
'content_xhtml' => &$content_xhtml 'content_xhtml' => &$content_xhtml
]); ]);

View File

@ -10,7 +10,6 @@
* @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
*/ */
/** /**
* @ingroup DC_PLUGIN_POSTWIDGETTEXT * @ingroup DC_PLUGIN_POSTWIDGETTEXT
* @brief postWidgetText - admin methods. * @brief postWidgetText - admin methods.
@ -47,12 +46,12 @@ class adminPostWidgetText
<div class="two-cols"> <div class="two-cols">
<div class="col"> <div class="col">
<p><label for="active">' . <p><label for="active">' .
form::checkbox('active', 1, (boolean) $blog_settings->postwidgettext->postwidgettext_active). form::checkbox('active', 1, (bool) $blog_settings->postwidgettext->postwidgettext_active) .
__('Enable post widget text on this blog') . '</label></p> __('Enable post widget text on this blog') . '</label></p>
</div> </div>
<div class="col"> <div class="col">
<p><label for="importexport_active">' . <p><label for="importexport_active">' .
form::checkbox('importexport_active', 1, (boolean) $blog_settings->postwidgettext->postwidgettext_importexport_active). form::checkbox('importexport_active', 1, (bool) $blog_settings->postwidgettext->postwidgettext_importexport_active) .
__('Enable import/export behaviors') . '</label></p> __('Enable import/export behaviors') . '</label></p>
</div> </div>
</div> </div>
@ -104,25 +103,24 @@ class adminPostWidgetText
public static function adminPostFormItems($main, $sidebar, $post) public static function adminPostFormItems($main, $sidebar, $post)
{ {
# _POST fields # _POST fields
$title = $_POST['post_wtitle'] ?? ''; $title = $_POST['post_wtitle'] ?? '';
$content = $_POST['post_wtext'] ?? ''; $content = $_POST['post_wtext'] ?? '';
# Existing post # Existing post
if ($post) { if ($post) {
$post_id = (integer) $post->post_id; $post_id = (int) $post->post_id;
$pwt = new postWidgetText($GLOBALS['core']); $pwt = new postWidgetText($GLOBALS['core']);
$w = $pwt->getWidgets(['post_id' => $post_id]); $w = $pwt->getWidgets(['post_id' => $post_id]);
# Existing widget # Existing widget
if (!$w->isEmpty()) { if (!$w->isEmpty()) {
$title = $w->option_title; $title = $w->option_title;
$content = $w->option_content; $content = $w->option_content;
} }
} }
$main['post_widget'] = $main['post_widget'] = '<div id="post-wtext-form">' .
'<div id="post-wtext-form">' .
'<h4>' . __('Additional widget') . '</h4>' . '<h4>' . __('Additional widget') . '</h4>' .
'<p class="col">' . '<p class="col">' .
@ -131,7 +129,7 @@ class adminPostWidgetText
'</p>' . '</p>' .
'<p class="area" id="post-wtext">' . '<p class="area" id="post-wtext">' .
'<label class="bold" for="post_wtext">' .__('Wigdet text:') . '</label>' . '<label class="bold" for="post_wtext">' . __('Wigdet text:') . '</label>' .
form::textarea('post_wtext', 50, 5, html::escapeHTML($content)) . form::textarea('post_wtext', 50, 5, html::escapeHTML($content)) .
'</p>' . '</p>' .
@ -140,11 +138,11 @@ class adminPostWidgetText
public static function adminAfterPostSave($cur, $post_id) public static function adminAfterPostSave($cur, $post_id)
{ {
$post_id = (integer) $post_id; $post_id = (int) $post_id;
# _POST fields # _POST fields
$title = $_POST['post_wtitle'] ?? ''; $title = $_POST['post_wtitle'] ?? '';
$content = $_POST['post_wtext'] ?? ''; $content = $_POST['post_wtext'] ?? '';
# Object # Object
$pwt = new postWidgetText($GLOBALS['core']); $pwt = new postWidgetText($GLOBALS['core']);
@ -159,7 +157,7 @@ class adminPostWidgetText
# If new content is not empty # If new content is not empty
if (!empty($title) || !empty($content)) { if (!empty($title) || !empty($content)) {
$wcur = $pwt->openCursor(); $wcur = $pwt->openCursor();
$wcur->post_id = $post_id; $wcur->post_id = $post_id;
$wcur->option_type = 'postwidgettext'; $wcur->option_type = 'postwidgettext';
$wcur->option_lang = $cur->post_lang; $wcur->option_lang = $cur->post_lang;
@ -180,7 +178,7 @@ class adminPostWidgetText
public static function adminBeforePostDelete($post_id) public static function adminBeforePostDelete($post_id)
{ {
$post_id = (integer) $post_id; $post_id = (int) $post_id;
# Object # Object
$pwt = new postWidgetText($GLOBALS['core']); $pwt = new postWidgetText($GLOBALS['core']);
@ -196,7 +194,8 @@ class adminPostWidgetText
public static function exportSingle(dcCore $core, $exp, $blog_id) public static function exportSingle(dcCore $core, $exp, $blog_id)
{ {
$exp->export('postwidgettext', $exp->export(
'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 ' . $core->prefix . 'post_option W ' .
@ -209,9 +208,10 @@ class adminPostWidgetText
public static function exportFull(dcCore $core, $exp) public static function exportFull(dcCore $core, $exp)
{ {
$exp->export('postwidgettext', $exp->export(
'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 ' . $core->prefix . 'post_option W ' .
'LEFT JOIN ' . $core->prefix . 'post P ' . 'LEFT JOIN ' . $core->prefix . 'post P ' .
'ON P.post_id = W.post_id ' . 'ON P.post_id = W.post_id ' .
@ -230,9 +230,9 @@ class adminPostWidgetText
public static function importSingle($line, $bk, dcCore $core) public static function importSingle($line, $bk, dcCore $core)
{ {
if ($line->__name == 'postwidgettext' if ($line->__name == 'postwidgettext'
&& isset($bk->old_ids['post'][(integer) $line->post_id]) && isset($bk->old_ids['post'][(int) $line->post_id])
) { ) {
$line->post_id = $bk->old_ids['post'][(integer) $line->post_id]; $line->post_id = $bk->old_ids['post'][(int) $line->post_id];
$exists = $bk->postwidgettext->getWidgets([ $exists = $bk->postwidgettext->getWidgets([
'post_id' => $line->post_id 'post_id' => $line->post_id
@ -241,18 +241,12 @@ class adminPostWidgetText
if ($exists->isEmpty()) { if ($exists->isEmpty()) {
$bk->cur_postwidgettext->clean(); $bk->cur_postwidgettext->clean();
$bk->cur_postwidgettext->post_id = $bk->cur_postwidgettext->post_id = (int) $line->post_id;
(integer) $line->post_id; $bk->cur_postwidgettext->option_type = (string) $line->option_type;
$bk->cur_postwidgettext->option_type = $bk->cur_postwidgettext->option_lang = (string) $line->option_lang;
(string) $line->option_type; $bk->cur_postwidgettext->option_format = (string) $line->option_format;
$bk->cur_postwidgettext->option_lang = $bk->cur_postwidgettext->option_content = (string) $line->option_content;
(string) $line->option_lang; $bk->cur_postwidgettext->option_content_xhtml = (string) $line->option_content_xhtml;
$bk->cur_postwidgettext->option_format =
(string) $line->option_format;
$bk->cur_postwidgettext->option_content =
(string) $line->option_content;
$bk->cur_postwidgettext->option_content_xhtml =
(string) $line->option_content_xhtml;
$bk->postwidgettext->addWidget( $bk->postwidgettext->addWidget(
$bk->cur_postwidgettext $bk->cur_postwidgettext
@ -271,18 +265,12 @@ class adminPostWidgetText
if ($exists->isEmpty()) { if ($exists->isEmpty()) {
$bk->cur_postwidgettext->clean(); $bk->cur_postwidgettext->clean();
$bk->cur_postwidgettext->post_id = $bk->cur_postwidgettext->post_id = (int) $line->post_id;
(integer) $line->post_id; $bk->cur_postwidgettext->option_type = (string) $line->option_type;
$bk->cur_postwidgettext->option_type = $bk->cur_postwidgettext->option_format = (string) $line->option_format;
(string) $line->option_type; $bk->cur_postwidgettext->option_content = (string) $line->option_content;
$bk->cur_postwidgettext->option_format = $bk->cur_postwidgettext->option_content = (string) $line->option_content;
(string) $line->option_format; $bk->cur_postwidgettext->option_content_xhtml = (string) $line->option_content_xhtml;
$bk->cur_postwidgettext->option_content =
(string) $line->option_content;
$bk->cur_postwidgettext->option_content =
(string) $line->option_content;
$bk->cur_postwidgettext->option_content_xhtml =
(string) $line->option_content_xhtml;
$bk->postwidgettext->addWidget( $bk->postwidgettext->addWidget(
$bk->cur_postwidgettext $bk->cur_postwidgettext

View File

@ -10,9 +10,7 @@
* @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
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -26,17 +24,15 @@ class listPostWidgetText extends adminGenericList
public function display($page, $nb_per_page, $enclose = '') public function display($page, $nb_per_page, $enclose = '')
{ {
if ($this->rs->isEmpty()) { if ($this->rs->isEmpty()) {
return '<p><strong>' . __('No widget') . '</strong></p>';
return '<p><strong>'.__('No widget').'</strong></p>';
} }
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$pager->html_prev = $this->html_prev; $pager->html_prev = $this->html_prev;
$pager->html_next = $this->html_next; $pager->html_next = $this->html_next;
$pager->var_page = 'page'; $pager->var_page = 'page';
$content = $content = '<div class="table-outer">' .
'<div class="table-outer">' .
'<table class="clear">' . '<table class="clear">' .
'<thead>' . '<thead>' .
'<tr>' . '<tr>' .
@ -49,23 +45,29 @@ class listPostWidgetText extends adminGenericList
'</tr></thead><tbody>'; '</tr></thead><tbody>';
while ($this->rs->fetch()) { while ($this->rs->fetch()) {
$w_title = html::escapeHTML($this->rs->option_title); $w_title = html::escapeHTML($this->rs->option_title);
if ($w_title == '') { if ($w_title == '') {
$w_title = '<em>' . context::global_filter( $w_title = '<em>' . context::global_filter(
$this->rs->option_content, 1, 1, 80, 0, 0 $this->rs->option_content,
1,
1,
80,
0,
0
) . '</em>'; ) . '</em>';
} }
$content .= $content .= '<tr class="line' . (
'<tr class="line' . ($this->rs->post_status != 1 ? $this->rs->post_status != 1 ?
' offline' : '' ' offline' : ''
) . '" id="p' . $this->rs->post_id . '">' . ) . '" id="p' . $this->rs->post_id . '">' .
'<td class="nowrap">' . '<td class="nowrap">' .
form::checkbox( form::checkbox(
array('widgets[]'), ['widgets[]'],
$this->rs->option_id, $this->rs->option_id,
'', '', '', '',
'',
'',
!$this->rs->isEditable() !$this->rs->isEditable()
) . '</td>' . ) . '</td>' .
'<td class="maximal"><a href="' . '<td class="maximal"><a href="' .
@ -89,8 +91,7 @@ class listPostWidgetText extends adminGenericList
'</tr>'; '</tr>';
} }
$content .= $content .= '</tbody></table></div>';
'</tbody></table></div>';
echo echo
$pager->getLinks() . $pager->getLinks() .

View File

@ -10,42 +10,38 @@
* @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 = $core->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 ' . $core->prefix . 'post_wtext W ' .
'LEFT JOIN '.$core->prefix.'post P ON P.post_id=W.post_id ' 'LEFT JOIN ' . $core->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 = $core->con->openCursor($core->prefix.'post_option'); while ($records->fetch()) {
while ($records->fetch()) $core->con->writeLock($core->prefix . 'post_option');
{
$core->con->writeLock($core->prefix.'post_option');
try {
try {
$id = $core->con->select( $id = $core->con->select(
'SELECT MAX(option_id) FROM '.$core->prefix.'post_option' 'SELECT MAX(option_id) FROM ' . $core->prefix . 'post_option'
)->f(0) + 1; )->f(0) + 1;
$cur->clean(); $cur->clean();
$cur->option_creadt = date('Y-m-d H:i:s'); $cur->option_creadt = date('Y-m-d H:i:s');
$cur->option_upddt = date('Y-m-d H:i:s'); $cur->option_upddt = date('Y-m-d H:i:s');
$cur->option_id = $id; $cur->option_id = $id;
$cur->post_id = $records->post_id; $cur->post_id = $records->post_id;
$cur->option_type = $records->wtext_type; $cur->option_type = $records->wtext_type;
$cur->option_lang = $records->post_lang; $cur->option_lang = $records->post_lang;
$cur->option_format = $records->post_format; $cur->option_format = $records->post_format;
$cur->option_title = $records->wtext_title; $cur->option_title = $records->wtext_title;
$cur->option_content = $records->wtext_content; $cur->option_content = $records->wtext_content;
$cur->option_content_xhtml = $records->wtext_content_xhtml; $cur->option_content_xhtml = $records->wtext_content_xhtml;
$cur->insert(); $cur->insert();
$core->con->unlock(); $core->con->unlock();
} } catch (Exception $e) {
catch (Exception $e)
{
$core->con->unlock(); $core->con->unlock();
throw $e; throw $e;
} }
} }

View File

@ -10,7 +10,6 @@
* @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
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -22,8 +21,8 @@ $pwt = new postWidgetText($core);
# Delete widgets # Delete widgets
if (!empty($_POST['save']) && !empty($_POST['widgets'])) { if (!empty($_POST['save']) && !empty($_POST['widgets'])) {
try { try {
foreach($_POST['widgets'] as $k => $id) { foreach ($_POST['widgets'] as $k => $id) {
$id = (integer) $id; $id = (int) $id;
$pwt->delWidget($id); $pwt->delWidget($id);
} }
@ -35,8 +34,7 @@ if (!empty($_POST['save']) && !empty($_POST['widgets'])) {
} else { } else {
$core->adminurl->redirect('admin.plugin.postWidgetText'); $core->adminurl->redirect('admin.plugin.postWidgetText');
} }
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
@ -48,11 +46,10 @@ $params = $filter->params();
# Get posts with text widget # Get posts with text widget
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($core, $posts, $counter->f(0));
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
@ -65,21 +62,23 @@ $filter->js($core->adminurl->get('admin.plugin.postWidgetText')) . '
<body>' . <body>' .
dcPage::breadcrumb([ dcPage::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
__('Posts widgets') => '' __('Posts widgets') => ''
]). ]) .
dcPage::notices(); dcPage::notices();
$filter->display('admin.plugin.postWidgetText', form::hidden('p', 'postWidgetText')); $filter->display('admin.plugin.postWidgetText', form::hidden('p', 'postWidgetText'));
$posts_list->display($filter->page, $filter->nb, $posts_list->display(
$filter->page,
$filter->nb,
'<form action="' . $core->adminurl->get('admin.plugin.postWidgetText') . '" method="post" id="form-entries">' . '<form action="' . $core->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))) . $core->adminurl->getHiddenFormFields('admin.plugin.postWidgetText', array_merge(['p' => 'postWidgetText'], $filter->values(true))) .
$core->formNonce() . $core->formNonce() .
'</div>' . '</div>' .
'</form>' '</form>'