Simple stats, login, new roles for users
This commit is contained in:
parent
682a80a084
commit
02464b637b
|
@ -3,7 +3,6 @@ bl-content/*
|
||||||
bl-plugins/timemachine
|
bl-plugins/timemachine
|
||||||
bl-plugins/timemachine-x
|
bl-plugins/timemachine-x
|
||||||
bl-plugins/remote-content
|
bl-plugins/remote-content
|
||||||
bl-plugins/simple-stats
|
|
||||||
bl-plugins/discovery
|
bl-plugins/discovery
|
||||||
bl-kernel/bludit.pro.php
|
bl-kernel/bludit.pro.php
|
||||||
bl-themes/docs
|
bl-themes/docs
|
||||||
|
|
|
@ -34,7 +34,7 @@ if (!method_exists($plugin, 'form')) {
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||||
// Add to syslog
|
// Add to syslog
|
||||||
$Syslog->add(array(
|
$syslog->add(array(
|
||||||
'dictionaryKey'=>'plugin-configured',
|
'dictionaryKey'=>'plugin-configured',
|
||||||
'notes'=>$plugin->name()
|
'notes'=>$plugin->name()
|
||||||
));
|
));
|
||||||
|
|
|
@ -8,7 +8,7 @@ if (!checkRole(array('admin','moderator'), false)) {
|
||||||
$pageKey = isset($_POST['key']) ? $_POST['key'] : $layout['parameters'];
|
$pageKey = isset($_POST['key']) ? $_POST['key'] : $layout['parameters'];
|
||||||
$page = buildPage($pageKey);
|
$page = buildPage($pageKey);
|
||||||
if (!$page || $page->username()!==$Login->username()) {
|
if (!$page || $page->username()!==$Login->username()) {
|
||||||
$Syslog->add(array(
|
$syslog->add(array(
|
||||||
'dictionaryKey'=>'access-deny',
|
'dictionaryKey'=>'access-deny',
|
||||||
'notes'=>$Login->username()
|
'notes'=>$Login->username()
|
||||||
));
|
));
|
||||||
|
|
|
@ -28,7 +28,7 @@ if( Sanitize::pathFile(PATH_THEMES.$themeDirname) ) {
|
||||||
$Site->set(array('theme'=>$themeDirname));
|
$Site->set(array('theme'=>$themeDirname));
|
||||||
|
|
||||||
// Add to syslog
|
// Add to syslog
|
||||||
$Syslog->add(array(
|
$syslog->add(array(
|
||||||
'dictionaryKey'=>'new-theme-configured',
|
'dictionaryKey'=>'new-theme-configured',
|
||||||
'notes'=>$themeDirname
|
'notes'=>$themeDirname
|
||||||
));
|
));
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'new-content' ?>"><span class="oi oi-plus"></span><?php $L->p('New content') ?></a>
|
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'new-content' ?>"><span class="oi oi-plus"></span><?php $L->p('New content') ?></a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<?php if (checkRole(array('admin'),false)): ?>
|
||||||
|
|
||||||
<li class="nav-item mt-3">
|
<li class="nav-item mt-3">
|
||||||
<h4>Manage</h4>
|
<h4>Manage</h4>
|
||||||
</li>
|
</li>
|
||||||
|
@ -45,6 +47,8 @@
|
||||||
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'about' ?>"><?php $L->p('About') ?></a>
|
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'about' ?>"><?php $L->p('About') ?></a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<li class="nav-item mt-5">
|
<li class="nav-item mt-5">
|
||||||
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'logout' ?>"><span class="oi oi-account-logout"></span><?php $L->p('Logout') ?></a>
|
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'logout' ?>"><span class="oi oi-account-logout"></span><?php $L->p('Logout') ?></a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
<ul class="uk-list uk-list-line">
|
<ul class="uk-list uk-list-line">
|
||||||
<?php
|
<?php
|
||||||
// Print Notifications
|
// Print Notifications
|
||||||
$logs = array_slice($Syslog->db, 0, NOTIFICATIONS_AMOUNT);
|
$logs = array_slice($syslog->db, 0, NOTIFICATIONS_AMOUNT);
|
||||||
foreach($logs as $log) {
|
foreach($logs as $log) {
|
||||||
$dict = $L->g($log['dictionaryKey']);
|
$dict = $L->g($log['dictionaryKey']);
|
||||||
echo '<li>';
|
echo '<li>';
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
<ul class="list-group list-group-striped b-0">
|
<ul class="list-group list-group-striped b-0">
|
||||||
<li class="list-group-item pt-0"><h4>Notifications</h4></li>
|
<li class="list-group-item pt-0"><h4>Notifications</h4></li>
|
||||||
<?php
|
<?php
|
||||||
$logs = array_slice($Syslog->db, 0, NOTIFICATIONS_AMOUNT);
|
$logs = array_slice($syslog->db, 0, NOTIFICATIONS_AMOUNT);
|
||||||
foreach ($logs as $log) {
|
foreach ($logs as $log) {
|
||||||
$phrase = $L->g($log['dictionaryKey']);
|
$phrase = $L->g($log['dictionaryKey']);
|
||||||
echo '<li class="list-group-item">';
|
echo '<li class="list-group-item">';
|
||||||
|
|
|
@ -41,7 +41,7 @@ echo Bootstrap::formOpen(array());
|
||||||
echo Bootstrap::formSelect(array(
|
echo Bootstrap::formSelect(array(
|
||||||
'name'=>'role',
|
'name'=>'role',
|
||||||
'label'=>$L->g('Role'),
|
'label'=>$L->g('Role'),
|
||||||
'options'=>array('editor'=>$L->g('Editor'), 'admin'=>$L->g('Administrator')),
|
'options'=>array('editor'=>$L->g('Editor'), 'moderator'=>$L->g('Moderator'), 'admin'=>$L->g('Administrator')),
|
||||||
'selected'=>'editor',
|
'selected'=>'editor',
|
||||||
'class'=>'',
|
'class'=>'',
|
||||||
'tip'=>''
|
'tip'=>''
|
||||||
|
|
|
@ -134,7 +134,7 @@ $site = $Site = new dbSite();
|
||||||
$url = $Url = new Url();
|
$url = $Url = new Url();
|
||||||
$parsedown = $Parsedown = new Parsedown();
|
$parsedown = $Parsedown = new Parsedown();
|
||||||
$security = $Security = new Security();
|
$security = $Security = new Security();
|
||||||
$syslog = $Syslog = new dbSyslog();
|
$syslog = $syslog = new dbSyslog();
|
||||||
|
|
||||||
// --- Relative paths ---
|
// --- Relative paths ---
|
||||||
// This paths are relative for the user / web browsing.
|
// This paths are relative for the user / web browsing.
|
||||||
|
|
|
@ -93,7 +93,7 @@ if ($dbPages->scheduler()) {
|
||||||
reindexCategories();
|
reindexCategories();
|
||||||
|
|
||||||
// Add to syslog
|
// Add to syslog
|
||||||
$Syslog->add(array(
|
$syslog->add(array(
|
||||||
'dictionaryKey'=>'content-published-from-scheduler',
|
'dictionaryKey'=>'content-published-from-scheduler',
|
||||||
'notes'=>''
|
'notes'=>''
|
||||||
));
|
));
|
||||||
|
|
|
@ -731,7 +731,7 @@ function editSettings($args) {
|
||||||
function changeUserPassword($args) {
|
function changeUserPassword($args) {
|
||||||
global $dbUsers;
|
global $dbUsers;
|
||||||
global $Language;
|
global $Language;
|
||||||
global $Syslog;
|
global $syslog;
|
||||||
|
|
||||||
// Arguments
|
// Arguments
|
||||||
$username = $args['username'];
|
$username = $args['username'];
|
||||||
|
@ -750,7 +750,7 @@ function changeUserPassword($args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dbUsers->setPassword(array('username'=>$username, 'password'=>$newPassword))) {
|
if ($dbUsers->setPassword(array('username'=>$username, 'password'=>$newPassword))) {
|
||||||
$Syslog->add(array(
|
$syslog->add(array(
|
||||||
'dictionaryKey'=>'user-password-changed',
|
'dictionaryKey'=>'user-password-changed',
|
||||||
'notes'=>$username
|
'notes'=>$username
|
||||||
));
|
));
|
||||||
|
@ -773,7 +773,7 @@ function checkRole($allowRoles, $redirect=true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($redirect) {
|
if ($redirect) {
|
||||||
$Syslog->add(array(
|
$syslog->add(array(
|
||||||
'dictionaryKey'=>'access-deny',
|
'dictionaryKey'=>'access-deny',
|
||||||
'notes'=>$Login->username()
|
'notes'=>$Login->username()
|
||||||
));
|
));
|
||||||
|
|
|
@ -74,7 +74,6 @@
|
||||||
if (isset($_SESSION[$key])) {
|
if (isset($_SESSION[$key])) {
|
||||||
return $_SESSION[$key];
|
return $_SESSION[$key];
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,36 @@
|
||||||
|
.simple-stats-plugin .ct-perfect-fourth {
|
||||||
|
height: 250px;
|
||||||
|
}
|
||||||
|
.simple-stats-plugin .ct-series-a .ct-line {
|
||||||
|
stroke: #4586d4;
|
||||||
|
stroke-width: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-stats-plugin .ct-series-a .ct-point {
|
||||||
|
stroke: #4586d4;
|
||||||
|
stroke-width: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-stats-plugin .ct-series-b .ct-line {
|
||||||
|
stroke: #777777;
|
||||||
|
stroke-width: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-stats-plugin .ct-series-b .ct-point {
|
||||||
|
stroke: #777777;
|
||||||
|
stroke-width: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-stats-plugin p.legends {
|
||||||
|
font-size: 0.8em;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-stats-plugin p.visits-today {
|
||||||
|
color: #4586d4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.simple-stats-plugin p.unique-today {
|
||||||
|
color: #777777;
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"plugin-data":
|
||||||
|
{
|
||||||
|
"name": "Simple Stats",
|
||||||
|
"description": "Show the number of visitors per day on your dashboard."
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"plugin-data":
|
||||||
|
{
|
||||||
|
"name": "Simple Stats",
|
||||||
|
"description": "Muestra el número de visitantes por día en tu panel."
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"author": "Bludit",
|
||||||
|
"email": "",
|
||||||
|
"website": "https://plugins.bludit.com",
|
||||||
|
"version": "2.3",
|
||||||
|
"releaseDate": "2018-01-23",
|
||||||
|
"license": "MIT",
|
||||||
|
"compatible": "2.3",
|
||||||
|
"notes": ""
|
||||||
|
}
|
|
@ -0,0 +1,189 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
This plugin use the javascript library https://github.com/gionkunz/chartist-js
|
||||||
|
*/
|
||||||
|
class pluginSimpleStats extends Plugin {
|
||||||
|
|
||||||
|
private $loadOnController = array(
|
||||||
|
'dashboard'
|
||||||
|
);
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
// Fields and default values for the database of this plugin
|
||||||
|
$this->dbFields = array(
|
||||||
|
'label'=>'Visits',
|
||||||
|
'numberOfDays'=>7,
|
||||||
|
'excludeAdmins'=>false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function form()
|
||||||
|
{
|
||||||
|
global $Language;
|
||||||
|
|
||||||
|
$html = '<div>';
|
||||||
|
$html .= '<label>'.$Language->get('Label').'</label>';
|
||||||
|
$html .= '<input id="jslabel" name="label" type="text" value="'.$this->getValue('label').'">';
|
||||||
|
$html .= '<span class="tip">'.$Language->get('This title is almost always used in the sidebar of the site').'</span>';
|
||||||
|
$html .= '</div>';
|
||||||
|
|
||||||
|
if (defined('BLUDIT_PRO')) {
|
||||||
|
$html .= '<div>';
|
||||||
|
$html .= '<label>'.$Language->get('Exclude administrators users').'</label>';
|
||||||
|
$html .= '<select name="excludeAdmins">';
|
||||||
|
$html .= '<option value="true" '.($this->getValue('excludeAdmins')===true?'selected':'').'>'.$Language->get('Enabled').'</option>';
|
||||||
|
$html .= '<option value="false" '.($this->getValue('excludeAdmins')===false?'selected':'').'>'.$Language->get('Disabled').'</option>';
|
||||||
|
$html .= '</select>';
|
||||||
|
$html .= '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function adminHead()
|
||||||
|
{
|
||||||
|
if (in_array($GLOBALS['ADMIN_CONTROLLER'], $this->loadOnController)) {
|
||||||
|
$css = '<link rel="stylesheet" type="text/css" href="'.$this->htmlPath().'css/chartist.min.css">';
|
||||||
|
$css .= '<link rel="stylesheet" type="text/css" href="'.$this->htmlPath().'css/style.css">';
|
||||||
|
$script = '<script src="'.$this->htmlPath().'js/chartist.min.js"></script>';
|
||||||
|
return $css.PHP_EOL.$script.PHP_EOL;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dashboard()
|
||||||
|
{
|
||||||
|
$label = $this->getValue('label');
|
||||||
|
$currentDate = Date::current('Y-m-d');
|
||||||
|
$visitsToday = $this->visits($currentDate);
|
||||||
|
$uniqueVisitors = $this->uniqueVisitors($currentDate);
|
||||||
|
|
||||||
|
$html = <<<EOF
|
||||||
|
<div class="simple-stats-plugin">
|
||||||
|
<div class="container mt-5 pt-5 border-top">
|
||||||
|
<h4 class="pb-3">$label</h4>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<div class="ct-chart ct-perfect-fourth"></div>
|
||||||
|
<p class="legends visits-today">Visits today: $visitsToday</p>
|
||||||
|
<p class="legends unique-today">Unique visitors today: $uniqueVisitors</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
EOF;
|
||||||
|
$numberOfDays = $this->getValue('numberOfDays');
|
||||||
|
$numberOfDays = $numberOfDays - 1;
|
||||||
|
for ($i=$numberOfDays; $i >= 0 ; $i--) {
|
||||||
|
$dateWithOffset = Date::currentOffset('Y-m-d', '-'.$i.' day');
|
||||||
|
$visits[$i] = $this->visits($dateWithOffset);
|
||||||
|
$unique[$i] = $this->uniqueVisitors($dateWithOffset);
|
||||||
|
$days[$i] = Date::format($dateWithOffset, 'Y-m-d', 'D');
|
||||||
|
}
|
||||||
|
|
||||||
|
$labels = "'" . implode("','", $days) . "'";
|
||||||
|
$seriesVisits = implode(',', $visits);
|
||||||
|
$seriesUnique = implode(',', $unique);
|
||||||
|
|
||||||
|
$script = <<<EOF
|
||||||
|
<script>
|
||||||
|
var data = {
|
||||||
|
labels: [$labels],
|
||||||
|
series: [
|
||||||
|
[$seriesVisits],
|
||||||
|
[$seriesUnique]
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
height: 250,
|
||||||
|
onlyInteger: true
|
||||||
|
};
|
||||||
|
|
||||||
|
new Chartist.Line('.ct-chart', data, options);
|
||||||
|
</script>
|
||||||
|
EOF;
|
||||||
|
|
||||||
|
$this->deleteOldLogs();
|
||||||
|
|
||||||
|
return $html.PHP_EOL.$script.PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function siteBodyEnd()
|
||||||
|
{
|
||||||
|
$this->addVisitor();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep only 7 days of logs, remove the old ones
|
||||||
|
public function deleteOldLogs()
|
||||||
|
{
|
||||||
|
$logs = Filesystem::listFiles($this->workspace(), '*', 'log', true);
|
||||||
|
$remove = array_slice($logs, 7);
|
||||||
|
|
||||||
|
foreach ($remove as $log) {
|
||||||
|
Filesystem::rmfile($log);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the amount of visits by date
|
||||||
|
public function visits($date)
|
||||||
|
{
|
||||||
|
$file = $this->workspace().$date.'.log';
|
||||||
|
$handle = @fopen($file, 'rb');
|
||||||
|
if ($handle===false) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The amount of visits are the number of lines on the file
|
||||||
|
$lines = 0;
|
||||||
|
while (!feof($handle)) {
|
||||||
|
$lines += substr_count(fread($handle, 8192), PHP_EOL);
|
||||||
|
}
|
||||||
|
@fclose($handle);
|
||||||
|
return $lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the amount of unique visitors by date
|
||||||
|
public function uniqueVisitors($date)
|
||||||
|
{
|
||||||
|
$file = $this->workspace().$date.'.log';
|
||||||
|
$lines = @file($file);
|
||||||
|
if (empty($lines)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
$tmp = array();
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
$key = json_decode($line);
|
||||||
|
$tmp[$key[0]] = true;
|
||||||
|
}
|
||||||
|
return count($tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a line to the current log
|
||||||
|
// The line is a json array with the hash IP of the visitor and the time
|
||||||
|
public function addVisitor()
|
||||||
|
{
|
||||||
|
// Exclude administrators visits
|
||||||
|
global $Login;
|
||||||
|
if ($this->getValue('excludeAdmins') && defined('BLUDIT_PRO')) {
|
||||||
|
if ($Login->role()=='admin') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$currentTime = Date::current('Y-m-d H:i:s');
|
||||||
|
$ip = TCP::getIP();
|
||||||
|
if (empty($ip)) {
|
||||||
|
$ip = session_id();
|
||||||
|
}
|
||||||
|
$hashIP = md5($ip);
|
||||||
|
|
||||||
|
$line = json_encode(array($hashIP, $currentTime));
|
||||||
|
$currentDate = Date::current('Y-m-d');
|
||||||
|
$file = $this->workspace().$currentDate.'.log';
|
||||||
|
|
||||||
|
return file_put_contents($file, $line.PHP_EOL, FILE_APPEND | LOCK_EX)!==false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue