cosmetics

This commit is contained in:
Jean-Christian Denis 2021-10-30 01:12:43 +02:00
parent d2a2b18308
commit ebfc5f0710
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
8 changed files with 108 additions and 124 deletions

View file

@ -21,11 +21,11 @@ $this->registerModule(
'Jean-Christian Denis and Contributors', 'Jean-Christian Denis and Contributors',
'2021.00.00.1', '2021.00.00.1',
[ [
'requires' => [['core', '2.19']], 'requires' => [['core', '2.19']],
'permissions' => 'usage,contentadmin', 'permissions' => 'usage,contentadmin',
'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',
'repository' => 'https://raw.githubusercontent.com/JcDenis/postWidgetText/master/dcstore.xml' 'repository' => 'https://raw.githubusercontent.com/JcDenis/postWidgetText/master/dcstore.xml'
] ]
); );

View file

@ -12,17 +12,13 @@
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$__autoload['postWidgetText'] = $d = dirname(__FILE__) . '/inc/';
dirname(__FILE__).'/inc/class.postwidgettext.php';
$__autoload['postWidgetTextDashboard'] = $__autoload['postWidgetText'] = $d . 'class.postwidgettext.php';
dirname(__FILE__).'/inc/lib.pwt.dashboard.php'; $__autoload['postWidgetTextDashboard'] = $d . 'lib.pwt.dashboard.php';
$__autoload['postWidgetTextAdmin'] = $__autoload['postWidgetTextAdmin'] = $d . 'lib.pwt.admin.php';
dirname(__FILE__).'/inc/lib.pwt.admin.php'; $__autoload['postWidgetTextBackup'] = $d . 'lib.pwt.backup.php';
$__autoload['postWidgetTextBackup'] = $__autoload['postWidgetTextList'] = $d . 'lib.pwt.list.php';
dirname(__FILE__).'/inc/lib.pwt.backup.php';
$__autoload['postWidgetTextList'] =
dirname(__FILE__).'/inc/lib.pwt.list.php';

View file

@ -12,7 +12,6 @@
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }

View file

@ -12,7 +12,6 @@
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -27,7 +26,7 @@ class postWidgetText
{ {
$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);
} }
@ -56,9 +55,9 @@ class postWidgetText
$this->core->blog->triggerBlog(); $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_id';
$params['columns'][] = 'option_creadt'; $params['columns'][] = 'option_creadt';
$params['columns'][] = 'option_upddt'; $params['columns'][] = 'option_upddt';
@ -72,13 +71,13 @@ 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['from'] .= 'LEFT JOIN ' . $this->table . ' W ON P.post_id=W.post_id ';
if (!isset($params['sql'])) { if (!isset($params['sql'])) {
$params['sql'] = ''; $params['sql'] = '';
} }
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' ";
@ -106,7 +105,7 @@ class postWidgetText
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 = (integer) $rs->f(0) + 1;
@ -128,7 +127,7 @@ class postWidgetText
return $cur->option_id; return $cur->option_id;
} }
public function updWidget($id,&$cur) public function updWidget($id, &$cur)
{ {
if (!$this->core->auth->check('usage,contentadmin', $this->blog)) { if (!$this->core->auth->check('usage,contentadmin', $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'));
@ -140,7 +139,7 @@ class postWidgetText
throw new Exception(__('No such ID')); throw new Exception(__('No such ID'));
} }
$this->getWidgetContent($cur,$id); $this->getWidgetContent($cur, $id);
$cur->option_upddt = date('Y-m-d H:i:s'); $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(); $this->triggerBlog();
} }
public function delWidget($id,$type='postwidgettext') public function delWidget($id, $type = 'postwidgettext')
{ {
if (!$this->core->auth->check('delete,contentadmin', $this->blog)) { if (!$this->core->auth->check('delete,contentadmin', $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'));
@ -187,9 +186,9 @@ class postWidgetText
} }
$this->con->execute( $this->con->execute(
'DELETE FROM '.$this->table.' '. 'DELETE FROM ' . $this->table . ' ' .
'WHERE option_id = '.$id.' '. 'WHERE option_id = ' . $id . ' ' .
"AND option_type = '".$this->con->escape($type)."' " "AND option_type = '" . $this->con->escape($type) . "' "
); );
$this->triggerBlog(); $this->triggerBlog();
@ -213,14 +212,14 @@ 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);
} }
} }
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 {
@ -230,11 +229,11 @@ class postWidgetText
$excerpt = $excerpt_xhtml = ''; $excerpt = $excerpt_xhtml = '';
# --BEHAVIOR-- coreAfterPostContentFormat # --BEHAVIOR-- coreAfterPostContentFormat
$this->core->callBehavior('coreAfterPostContentFormat',array( $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

@ -12,7 +12,6 @@
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -52,15 +51,15 @@ class postWidgetTextAdmin
public static function form($main, $sidebar, $post) public static function form($main, $sidebar, $post)
{ {
# _POST fields # _POST fields
$title = empty($_POST['post_wtitle']) ? '' : $_POST['post_wtitle']; $title = $_POST['post_wtitle'] ?? '';
$content = empty($_POST['post_wtext']) ? '' : $_POST['post_wtext']; $content = $_POST['post_wtext'] ?? '';
# Existing post # Existing post
if ($post) { if ($post) {
$post_id = (integer) $post->post_id; $post_id = (integer) $post->post_id;
$pwt = new postWidgetText($GLOBALS['core']); $pwt = new postWidgetText($GLOBALS['core']);
$w = $pwt->getWidgets(array('post_id' => $post_id)); $w = $pwt->getWidgets(['post_id' => $post_id]);
# Existing widget # Existing widget
if (!$w->isEmpty()) { if (!$w->isEmpty()) {
@ -70,18 +69,18 @@ class postWidgetTextAdmin
} }
$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">'
'<label class="bold" for="post_wtitle">'.__('Widget title:').'</label>'. '<label class="bold" for="post_wtitle">' . __('Widget title:') . '</label>' .
form::field('post_wtitle',20,255,html::escapeHTML($title),'maximal'). form::field('post_wtitle', 20, 255, html::escapeHTML($title), 'maximal') .
'</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>' .
'</div>'; '</div>';
} }
@ -91,16 +90,14 @@ class postWidgetTextAdmin
$post_id = (integer) $post_id; $post_id = (integer) $post_id;
# _POST fields # _POST fields
$title = isset($_POST['post_wtitle']) && !empty($_POST['post_wtitle']) ? $title = $_POST['post_wtitle'] ?? '';
$_POST['post_wtitle'] : ''; $content = $_POST['post_wtext'] ?? '';
$content = isset($_POST['post_wtext']) && !empty($_POST['post_wtext']) ?
$_POST['post_wtext'] : '';
# Object # Object
$pwt = new postWidgetText($GLOBALS['core']); $pwt = new postWidgetText($GLOBALS['core']);
# Get existing widget # 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 new content is empty, delete old existing widget
if (empty($title) && empty($content) && !$w->isEmpty()) { if (empty($title) && empty($content) && !$w->isEmpty()) {
@ -111,11 +108,11 @@ class postWidgetTextAdmin
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;
$wcur->option_format = $cur->post_format; $wcur->option_format = $cur->post_format;
$wcur->option_title = $title; $wcur->option_title = $title;
$wcur->option_content = $content; $wcur->option_content = $content;
# Create widget # Create widget
if ($w->isEmpty()) { if ($w->isEmpty()) {
@ -123,7 +120,7 @@ class postWidgetTextAdmin
} }
# Upddate widget # Upddate widget
else { else {
$pwt->updWidget($w->option_id,$wcur); $pwt->updWidget($w->option_id, $wcur);
} }
} }
} }
@ -136,7 +133,7 @@ class postWidgetTextAdmin
$pwt = new postWidgetText($GLOBALS['core']); $pwt = new postWidgetText($GLOBALS['core']);
# Get existing widget # 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 new content is empty, delete old existing widget
if (!$w->isEmpty()) { if (!$w->isEmpty()) {

View file

@ -12,7 +12,6 @@
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -26,12 +25,12 @@ class postWidgetTextBackup
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 ' .
'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 ' .
"WHERE P.blog_id = '".$blog_id."' ". "WHERE P.blog_id = '" . $blog_id . "' " .
"AND W.option_type = 'postwidgettext' " "AND W.option_type = 'postwidgettext' "
); );
} }
@ -39,11 +38,11 @@ class postWidgetTextBackup
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 ' .
"WHERE W.option_type = 'postwidgettext' " "WHERE W.option_type = 'postwidgettext' "
); );
} }
@ -51,7 +50,7 @@ class postWidgetTextBackup
public static function importInit($bk, dcCore $core) public static function importInit($bk, dcCore $core)
{ {
$bk->cur_postwidgettext = $core->con->openCursor( $bk->cur_postwidgettext = $core->con->openCursor(
$core->prefix.'post_option' $core->prefix . 'post_option'
); );
$bk->postwidgettext = new postWidgetText($core); $bk->postwidgettext = new postWidgetText($core);
} }
@ -63,9 +62,9 @@ class postWidgetTextBackup
) { ) {
$line->post_id = $bk->old_ids['post'][(integer) $line->post_id]; $line->post_id = $bk->old_ids['post'][(integer) $line->post_id];
$exists = $bk->postwidgettext->getWidgets(array( $exists = $bk->postwidgettext->getWidgets([
'post_id' => $line->post_id) 'post_id' => $line->post_id
); ]);
if ($exists->isEmpty()) { if ($exists->isEmpty()) {
$bk->cur_postwidgettext->clean(); $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') { if ($line->__name == 'postwidgettext') {
$exists = $bk->postwidgettext->getWidgets(array( $exists = $bk->postwidgettext->getWidgets([
'post_id' => $line->post_id) 'post_id' => $line->post_id
); ]);
if ($exists->isEmpty()) { if ($exists->isEmpty()) {
$bk->cur_postwidgettext->clean(); $bk->cur_postwidgettext->clean();

View file

@ -31,20 +31,14 @@ class postWidgetTextDashboard
*/ */
public static function favorites(dcCore $core, $favs) public static function favorites(dcCore $core, $favs)
{ {
$favs->register('postWidgetText', array( $favs->register('postWidgetText', [
'title' => __('Post widget text'), 'title' => __('Post widget text'),
'url' => 'plugin.php?p=postWidgetText', 'url' => $core->adminurl->get('admin.plugin.postWidgetText'),
'small-icon' => 'index.php?pf=postWidgetText/icon.png', 'small-icon' => dcPage::getPF('postWidgetText/icon.png'),
'large-icon' => 'index.php?pf=postWidgetText/icon-big.png', 'large-icon' => dcPage::getPF('postWidgetText/icon-big.png'),
'permissions' => $core->auth->check( 'permissions' => $core->auth->check('usage,contentadmin', $core->blog->id),
'usage,contentadmin', 'active_cb' => ['postWidgetTextDashboard', 'active']
$core->blog->id ]);
),
'active_cb' => array(
'postWidgetTextDashboard',
'active'
)
));
} }
/** /**

View file

@ -36,56 +36,56 @@ class postWidgetTextList extends adminGenericList
$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>' .
'<th colspan="2" class="nowrap">'.__('Post title').'</th>'. '<th colspan="2" class="nowrap">' . __('Post title') . '</th>' .
'<th class="nowrap">'.__('Post date').'</th>'. '<th class="nowrap">' . __('Post date') . '</th>' .
'<th class="nowrap">'.__('Widget title').'</th>'. '<th class="nowrap">' . __('Widget title') . '</th>' .
'<th class="nowrap">'.__('Widget date').'</th>'. '<th class="nowrap">' . __('Widget date') . '</th>' .
'<th class="nowrap">'.__('Author').'</th>'. '<th class="nowrap">' . __('Author') . '</th>' .
'<th class="nowrap">'.__('Type').'</th>'. '<th class="nowrap">' . __('Type') . '</th>' .
'</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'.($this->rs->post_status != 1 ? '<tr class="line' . ($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[]'), array('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="' .
$this->core->getPostAdminURL( $this->core->getPostAdminURL(
$this->rs->post_type, $this->rs->post_type,
$this->rs->post_id $this->rs->post_id
).'#post-wtext-form">'. ) . '#post-wtext-form">' .
html::escapeHTML($this->rs->post_title). html::escapeHTML($this->rs->post_title) .
'</a></td>'. '</a></td>' .
'<td class="nowrap">'.dt::dt2str( '<td class="nowrap">' . dt::dt2str(
__('%Y-%m-%d %H:%M'), __('%Y-%m-%d %H:%M'),
$this->rs->post_dt $this->rs->post_dt
).'</td>'. ) . '</td>' .
'<td class="nowrap">'.$w_title.'</td>'. '<td class="nowrap">' . $w_title . '</td>' .
'<td class="nowrap">'.dt::dt2str( '<td class="nowrap">' . dt::dt2str(
__('%Y-%m-%d %H:%M'), __('%Y-%m-%d %H:%M'),
$this->rs->option_upddt $this->rs->option_upddt
).'</td>'. ) . '</td>' .
'<td class="nowrap">'.$this->rs->user_id.'</td>'. '<td class="nowrap">' . $this->rs->user_id . '</td>' .
'<td class="nowrap">'.$this->rs->post_type.'</td>'. '<td class="nowrap">' . $this->rs->post_type . '</td>' .
'</tr>'; '</tr>';
} }
@ -93,8 +93,8 @@ class postWidgetTextList extends adminGenericList
'</tbody></table></div>'; '</tbody></table></div>';
echo echo
$pager->getLinks(). $pager->getLinks() .
sprintf($enclose, $content). sprintf($enclose, $content) .
$pager->getLinks(); $pager->getLinks();
} }
} }