diff --git a/CHANGELOG.md b/CHANGELOG.md index 3403861..bcfd686 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ dev - ... +- fix error on empty record on widget +- update to PS12 -2021.11.01 +2021.10.30 - clean up code - update license - update translations diff --git a/_admin.php b/_admin.php index 124816c..d40adb8 100644 --- a/_admin.php +++ b/_admin.php @@ -1,21 +1,20 @@ blog->settings->postwidgettext->postwidgettext_active) { @@ -55,4 +54,4 @@ if ($core->blog->settings->postwidgettext->postwidgettext_importexport_active) { $core->addBehavior('importInit', ['adminPostWidgetText', 'importInit']); $core->addBehavior('importSingle', ['adminPostWidgetText', 'importSingle']); $core->addBehavior('importFull', ['adminPostWidgetText', 'importFull']); -} \ No newline at end of file +} diff --git a/_define.php b/_define.php index ab39461..24a4ccd 100644 --- a/_define.php +++ b/_define.php @@ -1,16 +1,15 @@ registerModule( 'support' => 'https://github.com/JcDenis/postWidgetText', 'details' => 'https://plugins.dotaddict.org/dc2/details/postWidgetText', 'repository' => 'https://raw.githubusercontent.com/JcDenis/postWidgetText/master/dcstore.xml', - 'settings' => [ + 'settings' => [ 'blog' => '#params.pwt_params' ] ] -); \ No newline at end of file +); diff --git a/_install.php b/_install.php index 0aab9b1..55d7794 100644 --- a/_install.php +++ b/_install.php @@ -1,16 +1,15 @@ con, $core->prefix); $s->post_option - ->option_id ('bigint', 0, false) - ->post_id ('bigint', 0, false) - ->option_creadt ('timestamp', 0, false, 'now()') - ->option_upddt ('timestamp', 0, false, 'now()') - ->option_type ('varchar', 32, false, "''") - ->option_format ('varchar', 32, false, "'xhtml'") - ->option_lang ('varchar', 5, true, null) - ->option_title ('varchar', 255, true, null) - ->option_content ('text', 0, true, null) - ->option_content_xhtml ('text', 0, false) + ->option_id('bigint', 0, false) + ->post_id('bigint', 0, false) + ->option_creadt('timestamp', 0, false, 'now()') + ->option_upddt('timestamp', 0, false, 'now()') + ->option_type('varchar', 32, false, "''") + ->option_format('varchar', 32, false, "'xhtml'") + ->option_lang('varchar', 5, true, null) + ->option_title('varchar', 255, true, null) + ->option_content('text', 0, true, null) + ->option_content_xhtml('text', 0, false) ->index('idx_post_option_option', 'btree', 'option_id') ->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($core->con, $core->prefix); $changes = $si->synchronize($s); # Settings $core->blog->settings->addNamespace('postwidgettext'); - $core->blog->settings->postwidgettext->put('postwidgettext_active', - 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); + $core->blog->settings->postwidgettext->put( + 'postwidgettext_active', + 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 - if ($core->getVersion('postWidgetText') !== null + if ($core->getVersion('postWidgetText') !== null && 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 @@ -67,4 +78,4 @@ try { $core->error->add($e->getMessage()); } -return false; \ No newline at end of file +return false; diff --git a/_prepend.php b/_prepend.php index e4d8572..1b0ec91 100644 --- a/_prepend.php +++ b/_prepend.php @@ -1,16 +1,15 @@ offline) { return null; } if (!$core->blog->settings->postwidgettext->postwidgettext_active - || !$_ctx->exists('posts') + || !$_ctx->exists('posts') || !$_ctx->posts->post_id ) { return null; } - $title = $w->title ?: null; + $title = $w->title ?: null; $content = ''; $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()) { return null; @@ -96,4 +95,4 @@ class postWidgetTextWidget ($title ? $w->renderTitle(html::escapeHTML($title)) : '') . $content ); } -} \ No newline at end of file +} diff --git a/inc/class.postwidgettext.php b/inc/class.postwidgettext.php index e728824..72da245 100644 --- a/inc/class.postwidgettext.php +++ b/inc/class.postwidgettext.php @@ -1,16 +1,15 @@ core =& $core; - $this->con =& $this->core->con; + $this->core = & $core; + $this->con = & $this->core->con; $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() @@ -62,7 +61,9 @@ class postWidgetText 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_creadt'; $params['columns'][] = 'option_upddt'; @@ -83,8 +84,7 @@ class postWidgetText } if (isset($params['option_type'])) { $params['sql'] .= "AND W.option_type = '" . $this->con->escape($params['option_type']) . "' "; - } - else { + } else { $params['sql'] .= "AND W.option_type = 'postwidgettext' "; } unset($params['option_type']); @@ -107,23 +107,24 @@ class postWidgetText } $this->lockTable(); + try { $rs = $this->con->select( - 'SELECT MAX(option_id) '. - 'FROM ' . $this->table + 'SELECT MAX(option_id) ' . + '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_upddt = date('Y-m-d H:i:s'); + $cur->option_upddt = date('Y-m-d H:i:s'); $this->getWidgetContent($cur, $cur->option_id); $cur->insert(); $this->unlockTable(); - } - catch (Exception $e) { + } catch (Exception $e) { $this->unlockTable(); + throw $e; } @@ -138,7 +139,7 @@ class postWidgetText throw new Exception(__('You are not allowed to update entries text widget')); } - $id = (integer) $id; + $id = (int) $id; if (empty($id)) { throw new Exception(__('No such ID')); @@ -149,10 +150,10 @@ class postWidgetText $cur->option_upddt = date('Y-m-d H:i:s'); if (!$this->core->auth->check('contentadmin', $this->blog)) { - $params['option_id'] = $id; - $params['user_id'] = $this->con->escape($this->core->auth->userID()); + $params['option_id'] = $id; + $params['user_id'] = $this->con->escape($this->core->auth->userID()); $params['no_content'] = true; - $params['limit'] = 1; + $params['limit'] = 1; $rs = $this->getWidgets($params); @@ -171,17 +172,17 @@ class postWidgetText throw new Exception(__('You are not allowed to delete entries text widget')); } - $id = (integer) $id; + $id = (int) $id; if (empty($id)) { throw new Exception(__('No such ID')); } if (!$this->core->auth->check('contentadmin', $this->blog)) { - $params['option_id'] = $id; - $params['user_id'] = $this->con->escape($this->core->auth->userID()); + $params['option_id'] = $id; + $params['user_id'] = $this->con->escape($this->core->auth->userID()); $params['no_content'] = true; - $params['limit'] = 1; + $params['limit'] = 1; $rs = $this->getWidgets($params); @@ -201,15 +202,18 @@ class postWidgetText private function getWidgetContent(&$cur, $option_id) { - $option_content = $cur->option_content; + $option_content = $cur->option_content; $option_content_xhtml = $cur->option_content_xhtml; $this->setWidgetContent( - $option_id,$cur->option_format,$cur->option_lang, - $option_content,$option_content_xhtml + $option_id, + $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; } @@ -217,7 +221,7 @@ class postWidgetText { if ($format == 'wiki') { $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) { $this->core->wiki2xhtml->setOpt('active_fr_syntax', 1); } @@ -226,8 +230,7 @@ class postWidgetText if ($content) { $content_xhtml = $this->core->callFormater($format, $content); $content_xhtml = $this->core->HTMLfilter($content_xhtml); - } - else { + } else { $content_xhtml = ''; } @@ -235,10 +238,10 @@ class postWidgetText # --BEHAVIOR-- coreAfterPostContentFormat $this->core->callBehavior('coreAfterPostContentFormat', [ - 'excerpt' => &$excerpt, - 'content' => &$content, + 'excerpt' => &$excerpt, + 'content' => &$content, 'excerpt_xhtml' => &$excerpt_xhtml, 'content_xhtml' => &$content_xhtml ]); } -} \ No newline at end of file +} diff --git a/inc/lib.pwt.admin.php b/inc/lib.pwt.admin.php index 238afae..b9e2d71 100644 --- a/inc/lib.pwt.admin.php +++ b/inc/lib.pwt.admin.php @@ -1,16 +1,15 @@

@@ -86,8 +85,8 @@ class adminPostWidgetText */ public static function adminDashboardFavoritesActive($request, $params) { - return $request == 'plugin.php' - && isset($params['p']) + return $request == 'plugin.php' + && isset($params['p']) && $params['p'] == 'postWidgetText'; } @@ -96,33 +95,32 @@ class adminPostWidgetText global $core; $editor = $core->auth->getOption('editor'); - return - $core->callBehavior('adminPostEditor', $editor['xhtml'], 'pwt', ['#post_wtext'], 'xhtml') . + return + $core->callBehavior('adminPostEditor', $editor['xhtml'], 'pwt', ['#post_wtext'], 'xhtml') . dcPage::jsLoad(dcPage::getPF('postWidgetText/js/post.js')); } public static function adminPostFormItems($main, $sidebar, $post) { # _POST fields - $title = $_POST['post_wtitle'] ?? ''; - $content = $_POST['post_wtext'] ?? ''; + $title = $_POST['post_wtitle'] ?? ''; + $content = $_POST['post_wtext'] ?? ''; # Existing post if ($post) { - $post_id = (integer) $post->post_id; + $post_id = (int) $post->post_id; $pwt = new postWidgetText($GLOBALS['core']); - $w = $pwt->getWidgets(['post_id' => $post_id]); + $w = $pwt->getWidgets(['post_id' => $post_id]); # Existing widget if (!$w->isEmpty()) { - $title = $w->option_title; + $title = $w->option_title; $content = $w->option_content; } } - $main['post_widget'] = - '
' . + $main['post_widget'] = '
' . '

' . __('Additional widget') . '

' . '

' . @@ -131,7 +129,7 @@ class adminPostWidgetText '

' . '

' . - '' . + '' . form::textarea('post_wtext', 50, 5, html::escapeHTML($content)) . '

' . @@ -140,11 +138,11 @@ class adminPostWidgetText public static function adminAfterPostSave($cur, $post_id) { - $post_id = (integer) $post_id; + $post_id = (int) $post_id; # _POST fields - $title = $_POST['post_wtitle'] ?? ''; - $content = $_POST['post_wtext'] ?? ''; + $title = $_POST['post_wtitle'] ?? ''; + $content = $_POST['post_wtext'] ?? ''; # Object $pwt = new postWidgetText($GLOBALS['core']); @@ -159,7 +157,7 @@ class adminPostWidgetText # If new content is not empty if (!empty($title) || !empty($content)) { - $wcur = $pwt->openCursor(); + $wcur = $pwt->openCursor(); $wcur->post_id = $post_id; $wcur->option_type = 'postwidgettext'; $wcur->option_lang = $cur->post_lang; @@ -180,7 +178,7 @@ class adminPostWidgetText public static function adminBeforePostDelete($post_id) { - $post_id = (integer) $post_id; + $post_id = (int) $post_id; # Object $pwt = new postWidgetText($GLOBALS['core']); @@ -196,7 +194,8 @@ class adminPostWidgetText public static function exportSingle(dcCore $core, $exp, $blog_id) { - $exp->export('postwidgettext', + $exp->export( + 'postwidgettext', 'SELECT option_type, option_content, ' . 'option_content_xhtml, W.post_id ' . 'FROM ' . $core->prefix . 'post_option W ' . @@ -209,9 +208,10 @@ class adminPostWidgetText public static function exportFull(dcCore $core, $exp) { - $exp->export('postwidgettext', + $exp->export( + 'postwidgettext', 'SELECT option_type, option_content, ' . - 'option_content_xhtml, W.post_id '. + 'option_content_xhtml, W.post_id ' . 'FROM ' . $core->prefix . 'post_option W ' . 'LEFT JOIN ' . $core->prefix . 'post P ' . 'ON P.post_id = W.post_id ' . @@ -229,10 +229,10 @@ class adminPostWidgetText public static function importSingle($line, $bk, dcCore $core) { - if ($line->__name == 'postwidgettext' - && isset($bk->old_ids['post'][(integer) $line->post_id]) + if ($line->__name == 'postwidgettext' + && 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([ 'post_id' => $line->post_id @@ -241,18 +241,12 @@ class adminPostWidgetText if ($exists->isEmpty()) { $bk->cur_postwidgettext->clean(); - $bk->cur_postwidgettext->post_id = - (integer) $line->post_id; - $bk->cur_postwidgettext->option_type = - (string) $line->option_type; - $bk->cur_postwidgettext->option_lang = - (string) $line->option_lang; - $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->cur_postwidgettext->post_id = (int) $line->post_id; + $bk->cur_postwidgettext->option_type = (string) $line->option_type; + $bk->cur_postwidgettext->option_lang = (string) $line->option_lang; + $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->cur_postwidgettext @@ -271,18 +265,12 @@ class adminPostWidgetText if ($exists->isEmpty()) { $bk->cur_postwidgettext->clean(); - $bk->cur_postwidgettext->post_id = - (integer) $line->post_id; - $bk->cur_postwidgettext->option_type = - (string) $line->option_type; - $bk->cur_postwidgettext->option_format = - (string) $line->option_format; - $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->cur_postwidgettext->post_id = (int) $line->post_id; + $bk->cur_postwidgettext->option_type = (string) $line->option_type; + $bk->cur_postwidgettext->option_format = (string) $line->option_format; + $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->cur_postwidgettext @@ -290,4 +278,4 @@ class adminPostWidgetText } } } -} \ No newline at end of file +} diff --git a/inc/lib.pwt.list.php b/inc/lib.pwt.list.php index e212089..a378bdf 100644 --- a/inc/lib.pwt.list.php +++ b/inc/lib.pwt.list.php @@ -1,18 +1,16 @@ rs->isEmpty()) { - - return '

'.__('No widget').'

'; + return '

' . __('No widget') . '

'; } - $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_next = $this->html_next; - $pager->var_page = 'page'; + $pager->var_page = 'page'; - $content = - '
' . + $content = '
' . '' . '' . '' . @@ -49,23 +45,29 @@ class listPostWidgetText extends adminGenericList ''; while ($this->rs->fetch()) { - $w_title = html::escapeHTML($this->rs->option_title); if ($w_title == '') { $w_title = '' . context::global_filter( - $this->rs->option_content, 1, 1, 80, 0, 0 + $this->rs->option_content, + 1, + 1, + 80, + 0, + 0 ) . ''; } - $content .= - 'rs->post_status != 1 ? ' offline' : '' ) . '" id="p' . $this->rs->post_id . '">' . '' . '
' . form::checkbox( - array('widgets[]'), + ['widgets[]'], $this->rs->option_id, - '', '', '', + '', + '', + '', !$this->rs->isEditable() ) . 'adminurl->get('admin.plugin.postWidgetText') . '" method="post" id="form-entries">' . '%s' . '
' . '

' . '

' . '

' . - $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() . '
' . '' @@ -88,4 +87,4 @@ $posts_list->display($filter->page, $filter->nb, # Footer dcPage::helpBlock('postWidgetText'); -echo ''; \ No newline at end of file +echo '';