1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-18 03:31:54 +02:00

InfoPanel "Website Stats" moved to e107_plugins/user/e_dashboard.php .

FlexPanel drag-n-drop now working with plugin e_dashboard addons.
This commit is contained in:
Cameron 2017-04-21 16:40:47 -07:00
parent fe46bc7a50
commit 572d1a0da0
3 changed files with 456 additions and 342 deletions

View File

@ -212,11 +212,11 @@ class adminstyle_flexpanel extends adminstyle_infopanel
// --------------------- Website Status ---------------------------
$ns->setStyle('flexpanel');
/* $ns->setStyle('flexpanel');
$ns->setUniqueId('core-infopanel_website_status');
$coreInfoPanelWebsiteStatus = $ns->tablerender(LAN_WEBSITE_STATUS, $this->renderWebsiteStatus(), "core-infopanel_website_status", true);
$coreInfoPanelWebsiteStatus = '';// 'hi';/// "<div id='core-infopanel_website_status'>".$this->renderAddonDashboards()."</div>"; $ns->tablerender(LAN_WEBSITE_STATUS, $this->renderAddonDashboards(), "core-infopanel_website_status", true);
$info = $this->getMenuPosition('core-infopanel_website_status');
$panels[$info['area']][$info['weight']] .= $coreInfoPanelWebsiteStatus;
$panels[$info['area']][$info['weight']] .= $coreInfoPanelWebsiteStatus;*/
// --------------------- Latest Comments --------------------------
@ -254,6 +254,26 @@ class adminstyle_flexpanel extends adminstyle_infopanel
}
}
// --------------------- Plugin Addon Dashboards ---------------------- eg. e107_plugin/user/e_dashboard.php
$dashboards = $this->getAddonDashboards();
if(!empty($dashboards))
{
$ns->setStyle('flexpanel');
foreach($dashboards as $val)
{
$id = $val['mode'];
$ns->setUniqueId($id);
$inc = $ns->tablerender($val['caption'], $val['text'], $val['mode'], true);
$info = $this->getMenuPosition($id);
$panels[$info['area']][$info['weight']] .= $inc;
}
}
// Sorting panels.
foreach($panels as $key => $value)
{
@ -292,7 +312,7 @@ class adminstyle_flexpanel extends adminstyle_infopanel
{
$user_pref = $this->getUserPref();
if(varset($user_pref['core-flexpanel-order'][$id]))
if(!empty($user_pref['core-flexpanel-order'][$id]))
{
return $user_pref['core-flexpanel-order'][$id];
}
@ -311,6 +331,14 @@ class adminstyle_flexpanel extends adminstyle_infopanel
return $positions[$layout][$id];
}
if(strpos($id,'plug-infopanel-') === 0) // addon dashboards default to area 2.
{
$default = array(
'area' => 'menu-area-02',
'weight' => 1000,
);
}
return $default;
}

View File

@ -264,7 +264,7 @@ class adminstyle_infopanel
$text3 .= $ns->tablerender(LAN_WEBSITE_STATUS, $this->renderWebsiteStatus(),"",true);
// $text3 .= $ns->tablerender(LAN_WEBSITE_STATUS, $this->renderWebsiteStatus(),"",true);
@ -364,7 +364,7 @@ class adminstyle_infopanel
}
}
/*
private function renderChart()
{
@ -374,51 +374,62 @@ class adminstyle_infopanel
{
return $this->renderStats('log');
}
/* elseif(e107::isInstalled('awstats'))
{
return $this->renderStats('awstats');
}*/
else
{
return $this->renderStats('demo');
}
}
}*/
function renderWebsiteStatus()
{
$tp = e107::getParser();
return;
/* $tp = e107::getParser();
$tab = array();
$tab['e-stats'] = array('caption'=>$tp->toGlyph('fa-signal').' '.LAN_STATS, 'text'=>$this->renderChart());
$tab['e-online'] = array('caption'=>$tp->toGlyph('fa-user').' '.LAN_ONLINE.' ('.$this->renderOnlineUsers('count').')', 'text'=>$this->renderOnlineUsers());
return e107::getForm()->tabs($tab);
return e107::getForm()->tabs($tab);*/
}
function renderAddonDashboards()
function getAddonDashboards()
{
$panel = array();
$ns = e107::getRender();
$arr = array();
$text = '';
if($plugs = e107::getAddonConfig('e_dashboard',null, 'chart'))
{
foreach($plugs as $plug => $val)
{
$adg = e107::getAddon($plug,'e_dashboard');
if(!empty($adg->chartCaption))
{
$cap = $adg->chartCaption;
}
else
{
$cap = defset('LAN_PLUGIN_'.strtoupper($plug).'_NAME', ucfirst($plug));
}
foreach($val as $k=>$item)
{
if(!empty($item))
{
// $var[] = $item;
$renderMode = 'plug-infopanel-'.$plug;
$renderMode = 'plug-infopanel-'.$plug."-".intval($k);
if(isset($item[$k]['text']))
if(!isset($item['text']))
{
foreach ($item as $key => $v) // make sure the ids are unique.
{
$newkey = eHelper::dasherize($plug.'-'.$k.'-'.$key);
@ -427,12 +438,16 @@ class adminstyle_infopanel
}
$t = e107::getForm()->tabs($item);
$cap = defset('LAN_PLUGIN_'.strtoupper($plug).'_NAME', ucfirst($plug));
$text .= $ns->tablerender($cap, $t, $renderMode, true);
// $text .= $ns->tablerender($cap, $t, $renderMode, true);
$arr[] = array('caption'=>$cap, 'text'=>$t, 'mode'=>$renderMode);
}
else
{
$text .= $ns->tablerender($item['caption'], $item['text'], $renderMode, true);
// $text .= $ns->tablerender($item['caption'], $item['text'], $renderMode, true);
$arr[] = array('caption'=>$item['caption'], 'text'=>$item['text'], 'mode'=>$renderMode);
}
}
}
@ -440,129 +455,29 @@ class adminstyle_infopanel
}
}
return $arr;
}
function renderAddonDashboards()
{
$ns = e107::getRender();
$arr = $this->getAddonDashboards();
$text = '';
foreach($arr as $val)
{
$text .= $ns->tablerender($val['caption'], $val['text'], $val['mode'], true);
}
return $text;
}
function renderOnlineUsers($data=false)
{
$ol = e107::getOnline();
$tp = e107::getParser();
$multilan = e107::getPref('multilanguage');
$panelOnline = "
<table class='table table-condensed table-striped' >
<colgroup>
<col style='width: 10%' />
<col style='width: 25%' />
<col style='width: 10%' />
<col style='width: 40%' />
<col style='width: auto' />";
$panelOnline .= (!empty($multilan)) ? "<col style='width: auto' />" : "";
$panelOnline .= "
</colgroup>
<thead>
<tr class='first'>
<th>".LAN_TIMESTAMP."</th>
<th>".LAN_USER."</th>
<th>".LAN_IP."</th>
<th>".LAN_PAGE."</th>
<th class='center'>".LAN_AGENT."</th>";
$panelOnline .= (!empty($multilan)) ? "<th class='center'>".LAN_LANG."</th>" : "";
$panelOnline .= "
</tr>
</thead>
<tbody>";
$online = $ol->userList() + $ol->guestList();
if($data == 'count')
{
return count($online);
}
// echo "Users: ".print_a($online);
$lng = e107::getLanguage();
foreach ($online as $val)
{
$panelOnline .= "
<tr>
<td class='nowrap'>".e107::getDateConvert()->convert_date($val['user_currentvisit'],'%H:%M:%S')."</td>
<td>".$this->renderOnlineName($val['online_user_id'])."</td>
<td>".e107::getIPHandler()->ipDecode($val['user_ip'])."</td>
<td><a class='e-tip' href='".$val['user_location']."' title='".$val['user_location']."'>".$tp->html_truncate(basename($val['user_location']),50,"...")."</a></td>
<td class='center'><a class='e-tip' href='#' title='".$val['user_agent']."'>".$this->browserIcon($val)."</a></td>";
$panelOnline .= (!empty($multilan)) ? "<td class='center'><a class='e-tip' href='#' title=\"".$lng->convert($val['user_language'])."\">".$val['user_language']."</a></td>" : "";
$panelOnline .= "
</tr>
";
}
$panelOnline .= "</tbody></table>";
return $panelOnline;
}
function browserIcon($row)
{
$types = array(
"ie" => "MSIE",
'chrome' => 'Chrome',
'firefox' => 'Firefox',
'seamonkey' => 'Seamonkey',
// 'Chromium/xyz
'safari' => "Safari",
'opera' => "Opera"
);
if($row['user_bot'] === true)
{
return "<i class='browser e-bot-16'></i>";
}
foreach($types as $icon=>$b)
{
if(strpos($row['user_agent'], $b)!==false)
{
return "<i class='browsers e-".$icon."-16' ></i>";
}
}
return "<i class='browsers e-firefox-16'></i>"; // FIXME find a default icon.
}
function renderOnlineName($val)
{
if($val==0)
{
return LAN_GUEST;
}
return $val;
}
function renderLatestComments()
{
$sql = e107::getDb();
@ -768,202 +683,11 @@ class adminstyle_infopanel
return $text;
}
private function getStats($type)
{
/*
if(file_exists(e_PLUGIN."awstats/awstats.graph.php"))
{
require_once(e_PLUGIN."awstats/awstats.graph.php");
$stat = new awstats;
if($data = $stat->getData())
{
return $data;
}
// return;
}
*/ if($type == 'demo')
{
$data = array();
$months = e107::getDate()->terms('month');
$data['labels'] = array($months[0], //"January",
$months[1], //"February",
$months[2], //"March",
$months[3], //"April",
$months[4], //"May",
$months[5], //"June",
$months[6] //"July"
);
$data['datasets'][] = array(
'fillColor' => "rgba(220,220,220,0.5)",
'strokeColor' => "rgba(220,220,220,1)",
'pointColor ' => "rgba(220,220,220,1)",
'pointStrokeColor' => "#fff",
'data' => array(65,59,90,81,56,55,40),
'title' => ADLAN_168// "Visits"
);
$data['datasets'][] = array(
'fillColor' => "rgba(151,187,205,0.5)",
'strokeColor' => "rgba(151,187,205,1)",
'pointColor ' => "rgba(151,187,205,1)",
'pointStrokeColor' => "#fff",
'data' => array(28,48,40,19,96,27,100),
'title' => ADLAN_169 //"Unique Visits"
);
return $data;
}
$sql = e107::getDB();
$td = date("Y-m-j", time());
$dayarray[$td] = array();
$pagearray = array();
$qry = "
SELECT * from #logstats WHERE log_id REGEXP('[[:digit:]]+\-[[:digit:]]+\-[[:digit:]]+')
ORDER BY CONCAT(LEFT(log_id,4), SUBSTRING(log_id, 6, 2), LPAD(SUBSTRING(log_id, 9), 2, '0'))
DESC LIMIT 0,9
";
if($amount = $sql->gen($qry))
{
$array = $sql->db_getList();
$ttotal = 0;
$utotal = 0;
foreach($array as $key => $value)
{
extract($value);
$log_id = substr($log_id, 0, 4).'-'.substr($log_id, 5, 2).'-'.str_pad(substr($log_id, 8), 2, '0', STR_PAD_LEFT);
if(is_array($log_data)) {
$entries[0] = $log_data['host'];
$entries[1] = $log_data['date'];
$entries[2] = $log_data['os'];
$entries[3] = $log_data['browser'];
$entries[4] = $log_data['screen'];
$entries[5] = $log_data['referer'];
}
else
{
$entries = explode(chr(1), $log_data);
}
$dayarray[$log_id]['daytotal'] = $entries[0];
$dayarray[$log_id]['dayunique'] = $entries[1];
unset($entries[0]);
unset($entries[1]);
foreach($entries as $entry)
{
if($entry)
{
list($url, $total, $unique) = explode("|", $entry);
if(strstr($url, "/"))
{
$urlname = preg_replace("/\.php|\?.*/", "", substr($url, (strrpos($url, "/")+1)));
}
else
{
$urlname = preg_replace("/\.php|\?.*/", "", $url);
}
$dayarray[$log_id][$urlname] = array('url' => $url, 'total' => $total, 'unique' => $unique);
if (!isset($pagearray[$urlname]['total'])) $pagearray[$urlname]['total'] = 0;
if (!isset($pagearray[$urlname]['unique'])) $pagearray[$urlname]['unique'] = 0;
$pagearray[$urlname]['total'] += $total;
$pagearray[$urlname]['unique'] += $unique;
$ttotal += $total;
$utotal += $unique;
}
}
}
}
$logfile = e_LOG.'logp_'.date('z.Y', time()).'.php'; // was logi_ ??
if(is_readable($logfile))
{
require($logfile);
}
if(vartrue($pageInfo))
{
foreach($pageInfo as $fkey => $fvalue)
{
$dayarray[$td][$fkey]['total'] += $fvalue['ttl'];
$dayarray[$td][$fkey]['unique'] += $fvalue['unq'];
$dayarray[$td]['daytotal'] += $fvalue['ttl'];
$dayarray[$td]['dayunique'] += $fvalue['unq'];
$pagearray[$fkey]['total'] += $fvalue['ttl'];
$pagearray[$fkey]['unique'] += $fvalue['unq'];
$ttotal += $fvalue['ttl'];
$utotal += $fvalue['unq'];
}
}
$visitors = array();
$unique = array();
ksort($dayarray);
foreach($dayarray as $k=>$v)
{
$unix = strtotime($k);
$visitors[] = intval(vartrue($v['daytotal']));
$unique[] = intval(vartrue($v['dayunique']));
$label[] = "'".date("D",$unix)."'";
}
$data = array();
$data['labels'] = $label;
//visitors
$data['datasets'][] = array(
'fillColor' => "rgba(220,220,220,0.5)",
'strokeColor' => "rgba(220,220,220,1)",
'pointColor ' => "rgba(220,220,220,1)",
'pointStrokeColor' => "#fff",
'data' => $visitors
);
//Unique Visitors
$data['datasets'][] = array(
'fillColor' => "rgba(151,187,205,0.5)",
'strokeColor' => "rgba(151,187,205,1)",
'pointColor ' => "rgba(151,187,205,1)",
'pointStrokeColor' => "#fff",
'data' => $unique
);
return $data;
}
private function renderStats($type)
/* private function renderStats($type)
{
$data = $this->getStats($type);
@ -994,7 +718,7 @@ class adminstyle_infopanel
return $text;
}
}*/
}
?>

View File

@ -14,22 +14,263 @@ if (!defined('e107_INIT')) { exit; }
class user_dashboard // plugin-folder + '_url'
{
private $title;
private $title;
public $chartCaption = LAN_WEBSITE_STATUS;
function chart()
{
$config = array();
$tp = e107::getParser();
$config[] = array(
'text' => $this->registered('thismonth'),
'caption' => $this->title,
0 => array( 'text' => $this->renderChart(), 'caption' => $tp->toGlyph('fa-signal').' '.LAN_STATS),
1 => array('caption' =>$tp->toGlyph('fa-user').' '.LAN_ONLINE.' ('.$this->renderOnlineUsers('count').')', 'text'=>$this->renderOnlineUsers()),
2 => array( 'text' => $this->registered('user_new_thismonth'), 'caption' => $this->title),
);
return $config;
}
private function renderChart()
{
if (e107::isInstalled('log'))
{
return $this->renderStats('log');
}
else
{
return $this->renderStats('demo');
}
}
private function getStats($type)
{
if($type == 'demo')
{
$data = array();
$months = e107::getDate()->terms('month');
$data['labels'] = array($months[0], //"January",
$months[1], //"February",
$months[2], //"March",
$months[3], //"April",
$months[4], //"May",
$months[5], //"June",
$months[6] //"July"
);
$data['datasets'][] = array(
'fillColor' => "rgba(220,220,220,0.5)",
'strokeColor' => "rgba(220,220,220,1)",
'pointColor ' => "rgba(220,220,220,1)",
'pointStrokeColor' => "#fff",
'data' => array(65,59,90,81,56,55,40),
'title' => ADLAN_168// "Visits"
);
$data['datasets'][] = array(
'fillColor' => "rgba(151,187,205,0.5)",
'strokeColor' => "rgba(151,187,205,1)",
'pointColor ' => "rgba(151,187,205,1)",
'pointStrokeColor' => "#fff",
'data' => array(28,48,40,19,96,27,100),
'title' => ADLAN_169 //"Unique Visits"
);
return $data;
}
$sql = e107::getDB();
$td = date("Y-m-j", time());
$dayarray[$td] = array();
$pagearray = array();
$qry = "
SELECT * from #logstats WHERE log_id REGEXP('[[:digit:]]+\-[[:digit:]]+\-[[:digit:]]+')
ORDER BY CONCAT(LEFT(log_id,4), SUBSTRING(log_id, 6, 2), LPAD(SUBSTRING(log_id, 9), 2, '0'))
DESC LIMIT 0,9
";
if($amount = $sql->gen($qry))
{
$array = $sql->db_getList();
$ttotal = 0;
$utotal = 0;
foreach($array as $key => $value)
{
extract($value);
$log_id = substr($log_id, 0, 4).'-'.substr($log_id, 5, 2).'-'.str_pad(substr($log_id, 8), 2, '0', STR_PAD_LEFT);
if(is_array($log_data)) {
$entries[0] = $log_data['host'];
$entries[1] = $log_data['date'];
$entries[2] = $log_data['os'];
$entries[3] = $log_data['browser'];
$entries[4] = $log_data['screen'];
$entries[5] = $log_data['referer'];
}
else
{
$entries = explode(chr(1), $log_data);
}
$dayarray[$log_id]['daytotal'] = $entries[0];
$dayarray[$log_id]['dayunique'] = $entries[1];
unset($entries[0]);
unset($entries[1]);
foreach($entries as $entry)
{
if($entry)
{
list($url, $total, $unique) = explode("|", $entry);
if(strstr($url, "/"))
{
$urlname = preg_replace("/\.php|\?.*/", "", substr($url, (strrpos($url, "/")+1)));
}
else
{
$urlname = preg_replace("/\.php|\?.*/", "", $url);
}
$dayarray[$log_id][$urlname] = array('url' => $url, 'total' => $total, 'unique' => $unique);
if (!isset($pagearray[$urlname]['total'])) $pagearray[$urlname]['total'] = 0;
if (!isset($pagearray[$urlname]['unique'])) $pagearray[$urlname]['unique'] = 0;
$pagearray[$urlname]['total'] += $total;
$pagearray[$urlname]['unique'] += $unique;
$ttotal += $total;
$utotal += $unique;
}
}
}
}
$logfile = e_LOG.'logp_'.date('z.Y', time()).'.php'; // was logi_ ??
if(is_readable($logfile))
{
require($logfile);
}
if(vartrue($pageInfo))
{
foreach($pageInfo as $fkey => $fvalue)
{
$dayarray[$td][$fkey]['total'] += $fvalue['ttl'];
$dayarray[$td][$fkey]['unique'] += $fvalue['unq'];
$dayarray[$td]['daytotal'] += $fvalue['ttl'];
$dayarray[$td]['dayunique'] += $fvalue['unq'];
$pagearray[$fkey]['total'] += $fvalue['ttl'];
$pagearray[$fkey]['unique'] += $fvalue['unq'];
$ttotal += $fvalue['ttl'];
$utotal += $fvalue['unq'];
}
}
$visitors = array();
$unique = array();
ksort($dayarray);
foreach($dayarray as $k=>$v)
{
$unix = strtotime($k);
$visitors[] = intval(vartrue($v['daytotal']));
$unique[] = intval(vartrue($v['dayunique']));
$label[] = "'".date("D",$unix)."'";
}
$data = array();
$data['labels'] = $label;
//visitors
$data['datasets'][] = array(
'fillColor' => "rgba(220,220,220,0.5)",
'strokeColor' => "rgba(220,220,220,1)",
'pointColor ' => "rgba(220,220,220,1)",
'pointStrokeColor' => "#fff",
'data' => $visitors
);
//Unique Visitors
$data['datasets'][] = array(
'fillColor' => "rgba(151,187,205,0.5)",
'strokeColor' => "rgba(151,187,205,1)",
'pointColor ' => "rgba(151,187,205,1)",
'pointStrokeColor' => "#fff",
'data' => $unique
);
return $data;
}
private function renderStats($type)
{
$data = $this->getStats($type);
$cht = e107::getChart();
$cht->setType('line');
$cht->setOptions(array(
'annotateDisplay' => true,
'annotateFontSize' => 8
));
$cht->setData($data,'canvas');
$text = $cht->render('canvas');
if($type == 'demo')
{
$text .= "<div class='center'><small>".ADLAN_170."<a class='btn btn-xs btn-mini' href='".e_ADMIN."plugin.php?avail'>".ADLAN_171."</a></small></div>";
}
else
{
$text .= "<div class='center'><small>
<span style='color:rgba(220,220,220,0.5)'>&diams;</span>".ADLAN_168."&nbsp;&nbsp;
<span style='color:rgba(151,187,205,1)'>&diams;</span>".ADLAN_169."
</small></div>";
}
return $text;
}
/**
* TODO Switch to line-filled graph and add unactivated users also.
* @param string $when
@ -120,7 +361,7 @@ class user_dashboard // plugin-folder + '_url'
$cht->setData($data);
// redraw to fix sizing issue.
e107::js('footer-inline', "
/* e107::js('footer-inline', "
$('a[data-toggle=\"tab\"]').on('shown.bs.tab', function (e) {
@ -129,14 +370,135 @@ class user_dashboard // plugin-folder + '_url'
})
");
");*/
return "<div class='height:50%'>".$cht->render($id, $width, $height)."</div>";
// return "<div class='height:50%'>".$cht->render('projection', 320, 380)."</div>";
}
}
function renderOnlineUsers($data=false)
{
$ol = e107::getOnline();
$tp = e107::getParser();
$multilan = e107::getPref('multilanguage');
$panelOnline = "
<table class='table table-condensed table-striped' >
<colgroup>
<col style='width: 10%' />
<col style='width: 25%' />
<col style='width: 10%' />
<col style='width: 40%' />
<col style='width: auto' />";
$panelOnline .= (!empty($multilan)) ? "<col style='width: auto' />" : "";
$panelOnline .= "
</colgroup>
<thead>
<tr class='first'>
<th>".LAN_TIMESTAMP."</th>
<th>".LAN_USER."</th>
<th>".LAN_IP."</th>
<th>".LAN_PAGE."</th>
<th class='center'>".LAN_AGENT."</th>";
$panelOnline .= (!empty($multilan)) ? "<th class='center'>".LAN_LANG."</th>" : "";
$panelOnline .= "
</tr>
</thead>
<tbody>";
$online = $ol->userList() + $ol->guestList();
if($data == 'count')
{
return count($online);
}
// echo "Users: ".print_a($online);
$lng = e107::getLanguage();
foreach ($online as $val)
{
$panelOnline .= "
<tr>
<td class='nowrap'>".e107::getDateConvert()->convert_date($val['user_currentvisit'],'%H:%M:%S')."</td>
<td>".$this->renderOnlineName($val['online_user_id'])."</td>
<td>".e107::getIPHandler()->ipDecode($val['user_ip'])."</td>
<td><a class='e-tip' href='".$val['user_location']."' title='".$val['user_location']."'>".$tp->html_truncate(basename($val['user_location']),50,"...")."</a></td>
<td class='center'><a class='e-tip' href='#' title='".$val['user_agent']."'>".$this->browserIcon($val)."</a></td>";
$panelOnline .= (!empty($multilan)) ? "<td class='center'><a class='e-tip' href='#' title=\"".$lng->convert($val['user_language'])."\">".$val['user_language']."</a></td>" : "";
$panelOnline .= "
</tr>
";
}
$panelOnline .= "</tbody></table>";
return $panelOnline;
}
function browserIcon($row)
{
$types = array(
"ie" => "MSIE",
'chrome' => 'Chrome',
'firefox' => 'Firefox',
'seamonkey' => 'Seamonkey',
// 'Chromium/xyz
'safari' => "Safari",
'opera' => "Opera"
);
if($row['user_bot'] === true)
{
return "<i class='browser e-bot-16'></i>";
}
foreach($types as $icon=>$b)
{
if(strpos($row['user_agent'], $b)!==false)
{
return "<i class='browsers e-".$icon."-16' ></i>";
}
}
return "<i class='browsers e-firefox-16'></i>"; // FIXME find a default icon.
}
private function renderOnlineName($val)
{
if($val==0)
{
return LAN_GUEST;
}
return $val;
}
}