Second pass to clean up code

This commit is contained in:
Jean-Christian Paul Denis 2021-09-03 00:51:23 +02:00
parent 55136bb6d7
commit 60289b71c4
8 changed files with 157 additions and 179 deletions

View File

@ -15,6 +15,9 @@ themes and plugins from Dotclear administration pages.
* Permissions superadmin or admin * Permissions superadmin or admin
* Dotclear 2.19 * Dotclear 2.19
* plugin add a table to database
* plugin send email
## USAGE ## USAGE
First install _activityReport_, manualy from a zip package or from First install _activityReport_, manualy from a zip package or from

View File

@ -11,48 +11,42 @@
* @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')){return;} if (!defined('DC_CONTEXT_ADMIN')) {
return null;
if (!defined('ACTIVITY_REPORT')){return;} }
if (!defined('ACTIVITY_REPORT')) {
return null;
}
# Plugin menu # Plugin menu
$_menu['Plugins']->addItem( $_menu['Plugins']->addItem(
__('Activity report'), __('Activity report'),
'plugin.php?p=activityReport','index.php?pf=activityReport/icon.png', $core->adminurl->get('admin.plugin.activityReport'),
preg_match('/plugin.php\?p=activityReport(&.*)?$/', dcPage::getPF('activityReport/icon.png'),
$_SERVER['REQUEST_URI']), preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.activityReport')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
$core->auth->check('admin',$core->blog->id) $core->auth->check('admin',$core->blog->id)
); );
# Dashboarditems # Dashboarditems
if ($core->activityReport->getSetting('dashboardItem')) if ($core->activityReport->getSetting('dashboardItem')) {
{ $core->addBehavior('adminDashboardHeaders', ['activityReportAdmin', 'dashboardHeaders']);
$core->addBehavior( $core->addBehavior('adminDashboardItems', ['activityReportAdmin', 'dashboardItems']);
'adminDashboardHeaders',
array('activityReportAdmin','dashboardHeaders')
);
$core->addBehavior(
'adminDashboardItems',
array('activityReportAdmin','dashboardItems')
);
} }
class activityReportAdmin class activityReportAdmin
{ {
# Add CSS to dashboardHeaders for items /**
* Add CSS to dashboardHeaders for items
*/
public static function dashboardHeaders() public static function dashboardHeaders()
{ {
return return dcPage::jsLoad('index.php?pf=activityReport/style.css');
"\n<!-- CSS for activityReport --> \n".
"<style type=\"text/css\"> \n".
"#dashboard-items #report dt { font-weight: bold; margin: 0 0 0.4em 0; } \n".
"#dashboard-items #report dd { font-size: 0.9em; margin: 0 0 1em 0; } \n".
"#dashboard-items #report dd p { margin: 0.2em 0 0 0; } \n".
"</style> \n";
} }
# Add report to dashboardItems /**
public static function dashboardItems($core, $__dashboard_items) * Add report to dashboardItems
*/
public static function dashboardItems(dcCore $core, $__dashboard_items)
{ {
$r = $core->activityReport->getSetting('requests'); $r = $core->activityReport->getSetting('requests');
$g = $core->activityReport->getGroups(); $g = $core->activityReport->getGroups();
@ -64,30 +58,29 @@ class activityReportAdmin
$res = ''; $res = '';
$rs = $core->activityReport->getLogs($p); $rs = $core->activityReport->getLogs($p);
if (!$rs->isEmpty()) if (!$rs->isEmpty()) {
{ while($rs->fetch()) {
while($rs->fetch())
{
$group = $rs->activity_group; $group = $rs->activity_group;
if (!isset($g[$group])) continue; if (!isset($g[$group])) {
continue;
}
$res .= $res .=
'<dd><p title="'.__($g[$group]['title']).'"><strong>'. '<dd><p title="' . __($g[$group]['title']) . '"><strong>' .
__($g[$group]['actions'][$rs->activity_action]['title']). __($g[$group]['actions'][$rs->activity_action]['title']) .
'</p></strong><em>'. '</p></strong><em>' .
vsprintf( vsprintf(
__($g[$group]['actions'][$rs->activity_action]['msg']), __($g[$group]['actions'][$rs->activity_action]['msg']),
$core->activityReport->decode($rs->activity_logs) $core->activityReport->decode($rs->activity_logs)
). ) .
'</em></dd>'; '</em></dd>';
} }
} }
if (!empty($res)) if (!empty($res)) {
{
$__dashboard_items[1][] = $__dashboard_items[1][] =
'<h3>'.__('Activity report').'</h3>'. '<h3>' . __('Activity report') . '</h3>' .
'<dl id="report">'.$res.'</dl>'; '<dl id="report">' . $res . '</dl>';
} }
} }
} }

View File

@ -11,61 +11,54 @@
* @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')){return;} if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
$new_version = $core->plugins->moduleInfo('activityReport','version'); $new_version = $core->plugins->moduleInfo('activityReport', 'version');
$old_version = $core->getVersion('activityReport'); $old_version = $core->getVersion('activityReport');
if (version_compare($old_version,$new_version,'>=')) {return;} if (version_compare($old_version, $new_version, '>=')) {
return null;
}
try try {
{ $s = new dbStruct($core->con, $core->prefix);
# Check DC version
if (version_compare(DC_VERSION,'2.2-beta','<'))
{
throw new Exception('translater requires Dotclear 2.2');
}
# Table
$s = new dbStruct($core->con,$core->prefix);
$s->activity $s->activity
->activity_id ('bigint',0,false) ->activity_id ('bigint', 0, false)
->activity_type ('varchar',32,false,"'activityReport'") ->activity_type ('varchar', 32, false, "'activityReport'")
->blog_id ('varchar',32,true) ->blog_id ('varchar', 32, true)
->activity_group('varchar',32,false) ->activity_group('varchar', 32, false)
->activity_action ('varchar',32,false) ->activity_action ('varchar', 32, false)
->activity_logs ('text',0,false) ->activity_logs ('text', 0, false)
->activity_dt ('timestamp',0,false,'now()') ->activity_dt ('timestamp', 0 ,false, 'now()')
->activity_blog_status ('smallint',0,false,0) ->activity_blog_status ('smallint', 0, false,0)
->activity_super_status ('smallint',0,false,0) ->activity_super_status ('smallint',0, false,0)
->primary('pk_activity','activity_id') ->primary('pk_activity', 'activity_id')
->index('idx_activity_type','btree','activity_type') ->index('idx_activity_type', 'btree', 'activity_type')
->index('idx_activity_blog_id','btree','blog_id') ->index('idx_activity_blog_id', 'btree', 'blog_id')
->index('idx_activity_action','btree','activity_group','activity_action') ->index('idx_activity_action', 'btree', 'activity_group', 'activity_action')
->index('idx_activity_blog_status','btree','activity_blog_status') ->index('idx_activity_blog_status', 'btree', 'activity_blog_status')
->index('idx_activity_super_status','btree','activity_super_status'); ->index('idx_activity_super_status', 'btree', 'activity_super_status');
$s->activity_setting $s->activity_setting
->setting_id('varchar',64,false) ->setting_id('varchar', 64, false)
->blog_id ('varchar',32,true) ->blog_id ('varchar', 32, true)
->setting_type('varchar',32,false) ->setting_type('varchar', 32, false)
->setting_value('text',0,false) ->setting_value('text', 0, false)
->unique('uk_activity_setting','setting_id','blog_id','setting_type') ->unique('uk_activity_setting', 'setting_id', 'blog_id', 'setting_type')
->index('idx_activity_setting_blog_id','btree','blog_id') ->index('idx_activity_setting_blog_id', 'btree', 'blog_id')
->index('idx_activity_setting_type','btree','setting_type'); ->index('idx_activity_setting_type', 'btree', 'setting_type');
$si = new dbStruct($core->con,$core->prefix); $si = new dbStruct($core->con, $core->prefix);
$changes = $si->synchronize($s); $changes = $si->synchronize($s);
# Version $core->setVersion('activityReport', $new_version);
$core->setVersion('activityReport',$new_version);
return true; return true;
} } catch (Exception $e) {
catch (Exception $e)
{
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
return false; return false;

View File

@ -11,28 +11,25 @@
* @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')){return;} if (!defined('DC_RC_PATH')) {
return null;
}
global $__autoload, $core; $__autoload['activityReport'] = dirname(__FILE__) . '/inc/class.activity.report.php';
$__autoload['activityReport'] = try {
dirname(__FILE__).'/inc/class.activity.report.php';
try
{
$core->activityReport = new activityReport($core); $core->activityReport = new activityReport($core);
$core->url->register( $core->url->register(
'activityReport', 'activityReport',
'reports', 'reports',
'^reports/((atom|rss2)/(.+))$', '^reports/((atom|rss2)/(.+))$',
array('activityReportPublicUrl','feed') ['activityReportPublicUrl', 'feed']
); );
define('ACTIVITY_REPORT',true); define('ACTIVITY_REPORT', true);
require_once dirname(__FILE__).'/inc/class.activity.report.behaviors.php'; require_once dirname(__FILE__) . '/inc/class.activity.report.behaviors.php';
} } catch (Exception $e) {
catch (Exception $e) {
//throw new Exception('Failed to launch activityReport'); //throw new Exception('Failed to launch activityReport');
} }

View File

@ -11,16 +11,19 @@
* @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')){return;} if (!defined('DC_RC_PATH')) {
return null;
}
if (!defined('ACTIVITY_REPORT')) {
return null;
}
if (!defined('ACTIVITY_REPORT')){return;} $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates/tpl');
$core->tpl->addBlock('activityReports', ['activityReportPublicTpl','activityReports']);
$core->tpl->setPath($core->tpl->getPath(),dirname(__FILE__).'/default-templates/tpl'); $core->tpl->addValue('activityReportFeedID', ['activityReportPublicTpl','activityReportFeedID']);
$core->tpl->addBlock('activityReports',array('activityReportPublicTpl','activityReports')); $core->tpl->addValue('activityReportTitle', ['activityReportPublicTpl','activityReportTitle']);
$core->tpl->addValue('activityReportFeedID',array('activityReportPublicTpl','activityReportFeedID')); $core->tpl->addValue('activityReportDate', ['activityReportPublicTpl','activityReportDate']);
$core->tpl->addValue('activityReportTitle',array('activityReportPublicTpl','activityReportTitle')); $core->tpl->addValue('activityReportContent', ['activityReportPublicTpl','activityReportContent']);
$core->tpl->addValue('activityReportDate',array('activityReportPublicTpl','activityReportDate'));
$core->tpl->addValue('activityReportContent',array('activityReportPublicTpl','activityReportContent'));
class activityReportPublicUrl extends dcUrlHandlers class activityReportPublicUrl extends dcUrlHandlers
{ {
@ -28,17 +31,15 @@ class activityReportPublicUrl extends dcUrlHandlers
{ {
global $core, $_ctx; global $core, $_ctx;
if (!preg_match('/^(atom|rss2)\/(.+)$/',$args,$m)) if (!preg_match('/^(atom|rss2)\/(.+)$/', $args, $m)) {
{
self::p404(); self::p404();
return; return;
} }
if (!defined('ACTIVITY_REPORT')){ if (!defined('ACTIVITY_REPORT')) {
self::p404(); self::p404();
return; return;
} }
if (!$core->activityReport->getSetting('active')) if (!$core->activityReport->getSetting('active')) {
{
self::p404(); self::p404();
return; return;
} }
@ -52,25 +53,25 @@ class activityReportPublicUrl extends dcUrlHandlers
$_ctx->nb_entry_per_page = $core->blog->settings->system->nb_post_per_feed; $_ctx->nb_entry_per_page = $core->blog->settings->system->nb_post_per_feed;
$_ctx->short_feed_items = $core->blog->settings->system->short_feed_items; $_ctx->short_feed_items = $core->blog->settings->system->short_feed_items;
header('X-Robots-Tag: '.context::robotsPolicy($core->blog->settings->system->robots_policy,'')); header('X-Robots-Tag: '. context::robotsPolicy($core->blog->settings->system->robots_policy, ''));
self::serveDocument('activityreport-'.$m[1].'.xml',$mime); self::serveDocument('activityreport-' . $m[1] . '.xml', $mime);
return; return;
} }
} }
class activityReportPublicTpl class activityReportPublicTpl
{ {
public static function activityReports($attr,$content) public static function activityReports($attr, $content)
{ {
$lastn = 0; $lastn = 0;
if (isset($attr['lastn'])) { if (isset($attr['lastn'])) {
$lastn = abs((integer) $attr['lastn'])+0; $lastn = abs((integer) $attr['lastn']) + 0;
} }
$p = 'if (!isset($_page_number)) { $_page_number = 1; }'."\n\$params = array();\n"; $p = 'if (!isset($_page_number)) { $_page_number = 1; }' . "\n\$params = array();\n";
if ($lastn > 0) { if ($lastn > 0) {
$p .= "\$params['limit'] = ".$lastn.";\n"; $p .= "\$params['limit'] = " . $lastn . ";\n";
} else { } else {
$p .= "\$params['limit'] = \$_ctx->nb_entry_per_page;\n"; $p .= "\$params['limit'] = \$_ctx->nb_entry_per_page;\n";
} }
@ -81,36 +82,34 @@ class activityReportPublicTpl
$p .= "\$params['limit'] = array(0, \$params['limit']);\n"; $p .= "\$params['limit'] = array(0, \$params['limit']);\n";
} }
$res = return
"<?php \n". "<?php \n" .
$p. $p .
'$_ctx->activityreport_params = $params; '."\n". '$_ctx->activityreport_params = $params; ' . "\n" .
'$_ctx->activityreports = $core->activityReport->getLogs($params); unset($params); '."\n". '$_ctx->activityreports = $core->activityReport->getLogs($params); unset($params); ' . "\n" .
'while ($_ctx->activityreports->fetch()) : ?>'.$content.'<?php endwhile; '. 'while ($_ctx->activityreports->fetch()) : ?>'.$content.'<?php endwhile; ' .
'$_ctx->activityreports = null; $_ctx->activityreport_params = null; '."\n". '$_ctx->activityreports = null; $_ctx->activityreport_params = null; ' . "\n" .
"?>"; "?>";
return $res;
} }
public static function activityReportFeedID($attr) public static function activityReportFeedID($attr)
{ {
return return
'urn:md5:<?php echo md5($_ctx->activityreports->blog_id.'. 'urn:md5:<?php echo md5($_ctx->activityreports->blog_id.' .
'$_ctx->activityreports->activity_id.$_ctx->activityreports->activity_dt); '. '$_ctx->activityreports->activity_id.$_ctx->activityreports->activity_dt); ' .
'?>'; '?>';
} }
public static function activityReportTitle($attr) public static function activityReportTitle($attr)
{ {
$f = $GLOBALS['core']->tpl->getFilters($attr); $f = $GLOBALS['core']->tpl->getFilters($attr);
return '<?php echo '.sprintf($f,'activityReportContext::parseTitle()').'; ?>'; return '<?php echo ' . sprintf($f,'activityReportContext::parseTitle()') . '; ?>';
} }
public static function activityReportContent($attr) public static function activityReportContent($attr)
{ {
$f = $GLOBALS['core']->tpl->getFilters($attr); $f = $GLOBALS['core']->tpl->getFilters($attr);
return '<?php echo '.sprintf($f,'activityReportContext::parseContent()').'; ?>'; return '<?php echo ' . sprintf($f,'activityReportContext::parseContent()') . '; ?>';
} }
public static function activityReportDate($attr) public static function activityReportDate($attr)
@ -126,13 +125,13 @@ class activityReportPublicTpl
$f = $GLOBALS['core']->tpl->getFilters($attr); $f = $GLOBALS['core']->tpl->getFilters($attr);
if ($rfc822) { if ($rfc822) {
return '<?php echo '.sprintf($f,"dt::rfc822(strtotime(\$_ctx->activityreports->activity_dt),\$core->blog->settings->system->blog_timezone)").'; ?>'; return '<?php echo ' . sprintf($f,"dt::rfc822(strtotime(\$_ctx->activityreports->activity_dt),\$core->blog->settings->system->blog_timezone)") . '; ?>';
} elseif ($iso8601) { } elseif ($iso8601) {
return '<?php echo '.sprintf($f,"dt::iso8601(strtotime(\$_ctx->activityreports->activity_dt),\$core->blog->settings->system->blog_timezone)").'; ?>'; return '<?php echo ' . sprintf($f,"dt::iso8601(strtotime(\$_ctx->activityreports->activity_dt),\$core->blog->settings->system->blog_timezone)") . '; ?>';
} elseif (!empty($format)) { } elseif (!empty($format)) {
return '<?php echo '.sprintf($f,"dt::dt2str('".$format."',\$_ctx->activityreports->activity_dt)").'; ?>'; return '<?php echo ' . sprintf($f,"dt::dt2str('" . $format . "',\$_ctx->activityreports->activity_dt)") . '; ?>';
} else { } else {
return '<?php echo '.sprintf($f,"dt::dt2str(\$core->blog->settings->system->date_format,\$_ctx->activityreports->activity_dt)").'; ?>'; return '<?php echo ' . sprintf($f,"dt::dt2str(\$core->blog->settings->system->date_format,\$_ctx->activityreports->activity_dt)") . '; ?>';
} }
} }
} }

View File

@ -11,20 +11,22 @@
* @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')){return;} if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
$this->addUserAction( $this->addUserAction(
/* type */ 'tables', /* type */ 'tables',
/* action */ 'delete', /* action */ 'delete',
/* ns */ 'activity', /* ns */ 'activity',
/* description */ sprintf(__('delete %s table'),'"activity"') /* description */ sprintf(__('delete %s table'), '"activity"')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'tables', /* type */ 'tables',
/* action */ 'delete', /* action */ 'delete',
/* ns */ 'activity_setting', /* ns */ 'activity_setting',
/* description */ sprintf(__('delete %s table'),'"activity_setting"') /* description */ sprintf(__('delete %s table'), '"activity_setting"')
); );
$this->addUserAction( $this->addUserAction(
@ -45,12 +47,12 @@ $this->addDirectAction(
/* type */ 'versions', /* type */ 'versions',
/* action */ 'delete', /* action */ 'delete',
/* ns */ 'activityReport', /* ns */ 'activityReport',
/* description */ sprintf(__('delete %s version number'),'activityReport') /* description */ sprintf(__('delete %s version number'), 'activityReport')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'plugins', /* type */ 'plugins',
/* action */ 'delete', /* action */ 'delete',
/* ns */ 'activityReport', /* ns */ 'activityReport',
/* description */ sprintf(__('delete %s plugin files'),'activityReport') /* description */ sprintf(__('delete %s plugin files'), 'activityReport')
); );

View File

@ -11,61 +11,42 @@
* @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')){return;} if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
if (!defined('ACTIVITY_REPORT')){return;} if (!defined('ACTIVITY_REPORT')) {
return null;
}
dcPage::check('admin'); dcPage::check('admin');
require_once dirname(__FILE__).'/inc/lib.activity.report.index.php'; require_once dirname(__FILE__) . '/inc/lib.activity.report.index.php';
$tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : 'blog_settings'; $tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : 'blog_settings';
?> echo '
<html> <html><head><title><?php echo __('Activity report'); ?></title>' .
<head> dcPage::jsLoad('js/_posts_list.js') .
<title><?php echo __('Activity report'); ?></title> dcPage::jsToolBar() .
<?php dcPage::jsPageTabs($tab) .
echo dcPage::jsLoad('index.php?pf=activityReport/js/main.js') .
dcPage::jsLoad('js/_posts_list.js'). '<script type="text/javascript">'."\n//<![CDATA[\n" .
dcPage::jsToolBar(). dcPage::jsVar('jcToolsBox.prototype.text_wait',__('Please wait')) .
dcPage::jsPageTabs($tab). dcPage::jsVar('jcToolsBox.prototype.section',$section) .
dcPage::jsLoad('index.php?pf=activityReport/js/main.js'). "\n//]]>\n</script>\n" . '
'<script type="text/javascript">'."\n//<![CDATA[\n". </head><body>
dcPage::jsVar('jcToolsBox.prototype.text_wait',__('Please wait')). <h2>' . html::escapeHTML($core->blog->name) . ' &rsaquo; ' . __('Activity report') . '</h2>';
dcPage::jsVar('jcToolsBox.prototype.section',$section).
"\n//]]>\n</script>\n";
?>
</head>
<body>
<h2><?php
echo html::escapeHTML($core->blog->name).
' &rsaquo; '.__('Activity report');
?></h2>
<?php if (!activityReport::hasMailer()) {
if (!activityReport::hasMailer())
{ echo '<p class="error">' . __('This server has no mail function, activityReport not send email report.') . '</p>';
?>
<p class="error"><?php echo __('This server has no mail function, activityReport not send email report.'); ?></p>
<?php
} }
activityReportLib::settingTab($core,__('Settings')); activityReportLib::settingTab($core,__('Settings'));
activityReportLib::logTab($core,__('Logs')); activityReportLib::logTab($core,__('Logs'));
if ($core->auth->isSuperAdmin()) if ($core->auth->isSuperAdmin()) {
{ activityReportLib::settingTab($core, __('Super settings'), true);
activityReportLib::settingTab($core,__('Super settings'),true); activityReportLib::logTab($core, __('Super logs'), true);
activityReportLib::logTab($core,__('Super logs'),true);
} }
echo '</html>';
?>
<hr class="clear"/>
<p class="right">
activityReport -
<?php echo $core->plugins->moduleInfo('activityReport','version'); ?>&nbsp;
<img alt="activityReport" src="index.php?pf=activityReport/icon.png" />
</p>
</body>
</html>

10
style.css Normal file
View File

@ -0,0 +1,10 @@
#dashboard-items #report dt {
font-weight: bold;
margin: 0 0 0.4em 0;
}
#dashboard-items #report dd {
font-size: 0.9em;
margin: 0 0 1em 0; }
#dashboard-items #report dd p {
margin: 0.2em 0 0 0;
}