From ebfc5f07101c9467e98872d35a4e3e46fc7a1548 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 30 Oct 2021 01:12:43 +0200 Subject: [PATCH] cosmetics --- _define.php | 10 +++---- _prepend.php | 18 +++++------ _public.php | 1 - inc/class.postwidgettext.php | 37 +++++++++++------------ inc/lib.pwt.admin.php | 49 ++++++++++++++---------------- inc/lib.pwt.backup.php | 37 +++++++++++------------ inc/lib.pwt.dashboard.php | 22 +++++--------- inc/lib.pwt.list.php | 58 ++++++++++++++++++------------------ 8 files changed, 108 insertions(+), 124 deletions(-) diff --git a/_define.php b/_define.php index f38af86..8d0e559 100644 --- a/_define.php +++ b/_define.php @@ -21,11 +21,11 @@ $this->registerModule( 'Jean-Christian Denis and Contributors', '2021.00.00.1', [ - 'requires' => [['core', '2.19']], + 'requires' => [['core', '2.19']], 'permissions' => 'usage,contentadmin', - 'type'=> 'plugin', - 'support'=> 'https://github.com/JcDenis/postWidgetText', - 'details'=> 'https://plugins.dotaddict.org/dc2/details/postWidgetText', - 'repository' => 'https://raw.githubusercontent.com/JcDenis/postWidgetText/master/dcstore.xml' + 'type' => 'plugin', + 'support' => 'https://github.com/JcDenis/postWidgetText', + 'details' => 'https://plugins.dotaddict.org/dc2/details/postWidgetText', + 'repository' => 'https://raw.githubusercontent.com/JcDenis/postWidgetText/master/dcstore.xml' ] ); \ No newline at end of file diff --git a/_prepend.php b/_prepend.php index 783e73c..169e4c9 100644 --- a/_prepend.php +++ b/_prepend.php @@ -12,17 +12,13 @@ */ if (!defined('DC_RC_PATH')) { - return null; } -$__autoload['postWidgetText'] = - dirname(__FILE__).'/inc/class.postwidgettext.php'; -$__autoload['postWidgetTextDashboard'] = - dirname(__FILE__).'/inc/lib.pwt.dashboard.php'; -$__autoload['postWidgetTextAdmin'] = - dirname(__FILE__).'/inc/lib.pwt.admin.php'; -$__autoload['postWidgetTextBackup'] = - dirname(__FILE__).'/inc/lib.pwt.backup.php'; -$__autoload['postWidgetTextList'] = - dirname(__FILE__).'/inc/lib.pwt.list.php'; \ No newline at end of file +$d = dirname(__FILE__) . '/inc/'; + +$__autoload['postWidgetText'] = $d . 'class.postwidgettext.php'; +$__autoload['postWidgetTextDashboard'] = $d . 'lib.pwt.dashboard.php'; +$__autoload['postWidgetTextAdmin'] = $d . 'lib.pwt.admin.php'; +$__autoload['postWidgetTextBackup'] = $d . 'lib.pwt.backup.php'; +$__autoload['postWidgetTextList'] = $d . 'lib.pwt.list.php'; \ No newline at end of file diff --git a/_public.php b/_public.php index 8e01a8a..360c9dc 100644 --- a/_public.php +++ b/_public.php @@ -12,7 +12,6 @@ */ if (!defined('DC_RC_PATH')) { - return null; } diff --git a/inc/class.postwidgettext.php b/inc/class.postwidgettext.php index b97d923..e29fc79 100644 --- a/inc/class.postwidgettext.php +++ b/inc/class.postwidgettext.php @@ -12,7 +12,6 @@ */ if (!defined('DC_RC_PATH')) { - return null; } @@ -27,7 +26,7 @@ class postWidgetText { $this->core =& $core; $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); } @@ -56,9 +55,9 @@ class postWidgetText $this->core->blog->triggerBlog(); } - public function getWidgets($params,$count_only=false) + public function getWidgets($params, $count_only = false) { - if (!isset($params['columns'])) $params['columns'] = array(); + if (!isset($params['columns'])) $params['columns'] = []; $params['columns'][] = 'option_id'; $params['columns'][] = 'option_creadt'; $params['columns'][] = 'option_upddt'; @@ -72,13 +71,13 @@ class postWidgetText if (!isset($params['from'])) { $params['from'] = ''; } - $params['from'] .= 'LEFT JOIN '.$this->table.' W ON P.post_id=W.post_id '; + $params['from'] .= 'LEFT JOIN ' . $this->table . ' W ON P.post_id=W.post_id '; if (!isset($params['sql'])) { $params['sql'] = ''; } 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 { $params['sql'] .= "AND W.option_type = 'postwidgettext' "; @@ -106,7 +105,7 @@ class postWidgetText try { $rs = $this->con->select( 'SELECT MAX(option_id) '. - 'FROM '.$this->table + 'FROM ' . $this->table ); $cur->option_id = (integer) $rs->f(0) + 1; @@ -128,7 +127,7 @@ class postWidgetText return $cur->option_id; } - public function updWidget($id,&$cur) + public function updWidget($id, &$cur) { if (!$this->core->auth->check('usage,contentadmin', $this->blog)) { throw new Exception(__('You are not allowed to update entries text widget')); @@ -140,7 +139,7 @@ class postWidgetText throw new Exception(__('No such ID')); } - $this->getWidgetContent($cur,$id); + $this->getWidgetContent($cur, $id); $cur->option_upddt = date('Y-m-d H:i:s'); @@ -157,11 +156,11 @@ class postWidgetText } } - $cur->update('WHERE option_id = '.$id.' '); + $cur->update('WHERE option_id = ' . $id . ' '); $this->triggerBlog(); } - public function delWidget($id,$type='postwidgettext') + public function delWidget($id, $type = 'postwidgettext') { if (!$this->core->auth->check('delete,contentadmin', $this->blog)) { throw new Exception(__('You are not allowed to delete entries text widget')); @@ -187,9 +186,9 @@ class postWidgetText } $this->con->execute( - 'DELETE FROM '.$this->table.' '. - 'WHERE option_id = '.$id.' '. - "AND option_type = '".$this->con->escape($type)."' " + 'DELETE FROM ' . $this->table . ' ' . + 'WHERE option_id = ' . $id . ' ' . + "AND option_type = '" . $this->con->escape($type) . "' " ); $this->triggerBlog(); @@ -213,14 +212,14 @@ class postWidgetText { if ($format == 'wiki') { $this->core->initWikiPost(); - $this->core->wiki2xhtml->setOpt('note_prefix','wnote-'.$option_id); - if (strpos($lang,'fr') === 0) { + $this->core->wiki2xhtml->setOpt('note_prefix','wnote-' . $option_id); + if (strpos($lang, 'fr') === 0) { $this->core->wiki2xhtml->setOpt('active_fr_syntax', 1); } } if ($content) { - $content_xhtml = $this->core->callFormater($format,$content); + $content_xhtml = $this->core->callFormater($format, $content); $content_xhtml = $this->core->HTMLfilter($content_xhtml); } else { @@ -230,11 +229,11 @@ class postWidgetText $excerpt = $excerpt_xhtml = ''; # --BEHAVIOR-- coreAfterPostContentFormat - $this->core->callBehavior('coreAfterPostContentFormat',array( + $this->core->callBehavior('coreAfterPostContentFormat', [ '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 9697740..0d92fe6 100644 --- a/inc/lib.pwt.admin.php +++ b/inc/lib.pwt.admin.php @@ -12,7 +12,6 @@ */ if (!defined('DC_CONTEXT_ADMIN')) { - return null; } @@ -52,15 +51,15 @@ class postWidgetTextAdmin public static function form($main, $sidebar, $post) { # _POST fields - $title = empty($_POST['post_wtitle']) ? '' : $_POST['post_wtitle']; - $content = empty($_POST['post_wtext']) ? '' : $_POST['post_wtext']; + $title = $_POST['post_wtitle'] ?? ''; + $content = $_POST['post_wtext'] ?? ''; # Existing post if ($post) { $post_id = (integer) $post->post_id; $pwt = new postWidgetText($GLOBALS['core']); - $w = $pwt->getWidgets(array('post_id' => $post_id)); + $w = $pwt->getWidgets(['post_id' => $post_id]); # Existing widget if (!$w->isEmpty()) { @@ -70,18 +69,18 @@ class postWidgetTextAdmin } $main['post_widget'] = - '
'. - '

'.__('Additional widget').'

'. + '
' . + '

' . __('Additional widget') . '

' . - '

'. - ''. - form::field('post_wtitle',20,255,html::escapeHTML($title),'maximal'). - '

'. + '

' + '' . + form::field('post_wtitle', 20, 255, html::escapeHTML($title), 'maximal') . + '

' . - '

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

'. + '

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

' . '
'; } @@ -91,16 +90,14 @@ class postWidgetTextAdmin $post_id = (integer) $post_id; # _POST fields - $title = isset($_POST['post_wtitle']) && !empty($_POST['post_wtitle']) ? - $_POST['post_wtitle'] : ''; - $content = isset($_POST['post_wtext']) && !empty($_POST['post_wtext']) ? - $_POST['post_wtext'] : ''; + $title = $_POST['post_wtitle'] ?? ''; + $content = $_POST['post_wtext'] ?? ''; # Object $pwt = new postWidgetText($GLOBALS['core']); # Get existing widget - $w = $pwt->getWidgets(array('post_id'=>$post_id)); + $w = $pwt->getWidgets(['post_id' => $post_id]); # If new content is empty, delete old existing widget if (empty($title) && empty($content) && !$w->isEmpty()) { @@ -111,11 +108,11 @@ class postWidgetTextAdmin if (!empty($title) || !empty($content)) { $wcur = $pwt->openCursor(); $wcur->post_id = $post_id; - $wcur->option_type = 'postwidgettext'; - $wcur->option_lang = $cur->post_lang; - $wcur->option_format = $cur->post_format; - $wcur->option_title = $title; - $wcur->option_content = $content; + $wcur->option_type = 'postwidgettext'; + $wcur->option_lang = $cur->post_lang; + $wcur->option_format = $cur->post_format; + $wcur->option_title = $title; + $wcur->option_content = $content; # Create widget if ($w->isEmpty()) { @@ -123,7 +120,7 @@ class postWidgetTextAdmin } # Upddate widget else { - $pwt->updWidget($w->option_id,$wcur); + $pwt->updWidget($w->option_id, $wcur); } } } @@ -136,7 +133,7 @@ class postWidgetTextAdmin $pwt = new postWidgetText($GLOBALS['core']); # Get existing widget - $w = $pwt->getWidgets(array('post_id'=>$post_id)); + $w = $pwt->getWidgets(['post_id' => $post_id]); # If new content is empty, delete old existing widget if (!$w->isEmpty()) { diff --git a/inc/lib.pwt.backup.php b/inc/lib.pwt.backup.php index 32faf26..c46e2da 100644 --- a/inc/lib.pwt.backup.php +++ b/inc/lib.pwt.backup.php @@ -12,7 +12,6 @@ */ if (!defined('DC_CONTEXT_ADMIN')) { - return null; } @@ -26,12 +25,12 @@ class postWidgetTextBackup public static function exportSingle(dcCore $core, $exp, $blog_id) { $exp->export('postwidgettext', - 'SELECT option_type, option_content, '. - '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 '. - "WHERE P.blog_id = '".$blog_id."' ". + 'SELECT option_type, option_content, ' . + '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 ' . + "WHERE P.blog_id = '" . $blog_id . "' " . "AND W.option_type = 'postwidgettext' " ); } @@ -39,11 +38,11 @@ class postWidgetTextBackup public static function exportFull(dcCore $core, $exp) { $exp->export('postwidgettext', - 'SELECT option_type, option_content, '. + 'SELECT option_type, option_content, ' . '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 '. + 'FROM ' . $core->prefix . 'post_option W ' . + 'LEFT JOIN ' . $core->prefix . 'post P ' . + 'ON P.post_id = W.post_id ' . "WHERE W.option_type = 'postwidgettext' " ); } @@ -51,7 +50,7 @@ class postWidgetTextBackup public static function importInit($bk, dcCore $core) { $bk->cur_postwidgettext = $core->con->openCursor( - $core->prefix.'post_option' + $core->prefix . 'post_option' ); $bk->postwidgettext = new postWidgetText($core); } @@ -63,9 +62,9 @@ class postWidgetTextBackup ) { $line->post_id = $bk->old_ids['post'][(integer) $line->post_id]; - $exists = $bk->postwidgettext->getWidgets(array( - 'post_id' => $line->post_id) - ); + $exists = $bk->postwidgettext->getWidgets([ + 'post_id' => $line->post_id + ]); if ($exists->isEmpty()) { $bk->cur_postwidgettext->clean(); @@ -90,12 +89,12 @@ class postWidgetTextBackup } } - public static function importFull($line ,$bk, dcCore $core) + public static function importFull($line, $bk, dcCore $core) { if ($line->__name == 'postwidgettext') { - $exists = $bk->postwidgettext->getWidgets(array( - 'post_id' => $line->post_id) - ); + $exists = $bk->postwidgettext->getWidgets([ + 'post_id' => $line->post_id + ]); if ($exists->isEmpty()) { $bk->cur_postwidgettext->clean(); diff --git a/inc/lib.pwt.dashboard.php b/inc/lib.pwt.dashboard.php index b7152a3..4a7aa3f 100644 --- a/inc/lib.pwt.dashboard.php +++ b/inc/lib.pwt.dashboard.php @@ -31,20 +31,14 @@ class postWidgetTextDashboard */ public static function favorites(dcCore $core, $favs) { - $favs->register('postWidgetText', array( - 'title' => __('Post widget text'), - 'url' => 'plugin.php?p=postWidgetText', - 'small-icon' => 'index.php?pf=postWidgetText/icon.png', - 'large-icon' => 'index.php?pf=postWidgetText/icon-big.png', - 'permissions' => $core->auth->check( - 'usage,contentadmin', - $core->blog->id - ), - 'active_cb' => array( - 'postWidgetTextDashboard', - 'active' - ) - )); + $favs->register('postWidgetText', [ + 'title' => __('Post widget text'), + 'url' => $core->adminurl->get('admin.plugin.postWidgetText'), + 'small-icon' => dcPage::getPF('postWidgetText/icon.png'), + 'large-icon' => dcPage::getPF('postWidgetText/icon-big.png'), + 'permissions' => $core->auth->check('usage,contentadmin', $core->blog->id), + 'active_cb' => ['postWidgetTextDashboard', 'active'] + ]); } /** diff --git a/inc/lib.pwt.list.php b/inc/lib.pwt.list.php index 20d5493..0a99fb8 100644 --- a/inc/lib.pwt.list.php +++ b/inc/lib.pwt.list.php @@ -36,56 +36,56 @@ class postWidgetTextList extends adminGenericList $pager->var_page = 'page'; $content = - '
'. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. + '
' . + '
'.__('Post title').''.__('Post date').''.__('Widget title').''.__('Widget date').''.__('Author').''.__('Type').'
' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . ''; while ($this->rs->fetch()) { $w_title = html::escapeHTML($this->rs->option_title); if ($w_title == '') { - $w_title = ''.context::global_filter( + $w_title = '' . context::global_filter( $this->rs->option_content, 1, 1, 80, 0, 0 - ).''; + ) . ''; } $content .= - 'rs->post_status != 1 ? ' offline' : '' - ).'" id="p'.$this->rs->post_id.'">'. - ''. - ''. - '' . + ''. - ''. - '' . + '' . + ''. - ''. - ''. + ) . '' . + '' . + '' . ''; } @@ -93,8 +93,8 @@ class postWidgetTextList extends adminGenericList '
' . __('Post title') . '' . __('Post date') . '' . __('Widget title') . '' . __('Widget date') . '' . __('Author') . '' . __('Type') . '
'. + ) . '" id="p' . $this->rs->post_id . '">' . + '' . form::checkbox( array('widgets[]'), $this->rs->option_id, '', '', '', !$this->rs->isEditable() - ).''. - html::escapeHTML($this->rs->post_title). - ''.dt::dt2str( + ) . '#post-wtext-form">' . + html::escapeHTML($this->rs->post_title) . + '' . dt::dt2str( __('%Y-%m-%d %H:%M'), $this->rs->post_dt - ).''.$w_title.''.dt::dt2str( + ) . '' . $w_title . '' . dt::dt2str( __('%Y-%m-%d %H:%M'), $this->rs->option_upddt - ).''.$this->rs->user_id.''.$this->rs->post_type.'' . $this->rs->user_id . '' . $this->rs->post_type . '
'; echo - $pager->getLinks(). - sprintf($enclose, $content). + $pager->getLinks() . + sprintf($enclose, $content) . $pager->getLinks(); } } \ No newline at end of file