stat module

This commit is contained in:
Dro1d.Ru 2018-06-12 22:40:51 +05:00
parent e448bd01a2
commit e6a5ccea31
26 changed files with 1212 additions and 2 deletions

View file

@ -236,6 +236,11 @@ textarea {
#zira-auth-dialog a {
color: #073954;
}
.zira_bottom_counter {
text-align: right;
font-style: italic;
font-size: 90%;
}
@keyframes loader {
0% {

38
assets/js/stat/dash.js Normal file
View file

@ -0,0 +1,38 @@
var dash_stat_access_row = function() {
var selected = this.getSelectedContentItems();
if (selected && selected.length==1) {
desk_window_request(this, url('stat/dash/access'),{'item':selected[0].data}, this.bind(this, function(result){
desk_message(t('Request')+':<div style="color:black;padding:10px 16px">'+result.join('<br />')+'</div>');
}));
}
};
var dash_stat_requests = function() {
if (this.options.data.access_log_enabled=='0') {
desk_error(t('Requests logging is disabled'));
return;
}
var data = {
'data': {
'items': []
},
'reload': this.className,
'onClose':function(){
desk_window_reload_all(this.options.reload);
}
};
desk_call(dash_stat_requests_wnd, null, data);
};
var dash_stat_settings = function() {
var data = {
'data': {
'items': []
},
'reload': this.className,
'onClose':function(){
desk_window_reload_all(this.options.reload);
}
};
desk_call(dash_stat_settings_wnd, null, data);
};

35
languages/ru/stat.php Normal file
View file

@ -0,0 +1,35 @@
<?php
return array(
'Statistics' => 'Статистика',
'Collect statistics about your website visitors' => 'Собирайте статистику о посетителях вашего сайта',
'Record views count' => 'Количество просмотров записи',
'Views: %s' => 'Просмотров: %s',
'Statistics cleaned up' => 'Статистика почищена',
'Request' => 'Запрос',
'Requests' => 'Запросы',
'View statistics' => 'Просмотр статистики',
'View requests' => 'Просмотр запросов',
'User-Agent' => 'Клиент',
'Referer' => 'Реферер',
'Language' => 'Язык',
'Time' => 'Время',
'Category' => 'Категория',
'Record' => 'Запись',
'Statistics settings' => 'Настройки статистики',
'Collect browser information' => 'Собирать информацию о браузерах',
'Log requests' => 'Записывать запросы',
'Requests logging is disabled' => 'Запись запросов отключена',
'Today new page views: %s' => 'Новые просмотры страниц за сегодня: %s',
'Yesterday new page views: %s' => 'Новые просмотры страниц за вчера: %s',
'Today most viewed pages' => 'Наиболее просматриваемые страницы за сегодня',
'Yesterday most viewed pages' => 'Наиболее просматриваемые страницы за вчера',
'30-days most viewed pages' => 'Наиболее просматриваемые страницы за 30 дней',
'Browsers' => 'Браузеры',
'Desktop devices: %s' => 'Десктопные устройства: %s',
'Mobile devices: %s' => 'Мобильные устройства: %s',
'30-days most used browsers' => 'Наиболее часто используемые браузеры за 30 дней',
'Today: %s' => 'Сегодня: %s',
'Yesterday: %s' => 'Вчера: %s',
'30-days referers' => 'Рефереры за 30 дней'
);

31
stat/controllers/dash.php Normal file
View file

@ -0,0 +1,31 @@
<?php
/**
* Zira project.
* dash.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Controllers;
use Zira;
use Stat;
class Dash extends \Dash\Controller {
public function _before() {
parent::_before();
Zira\View::setAjax(true);
}
protected function getRequestsWindowModel() {
$window = new Stat\Windows\Requests();
return new Stat\Models\Requests($window);
}
public function access() {
if (Zira\Request::isPost()) {
$vote = Zira\Request::post('item');
$response = $this->getRequestsWindowModel()->request($vote);
Zira\Page::render($response);
}
}
}

19
stat/cron/cleaner.php Normal file
View file

@ -0,0 +1,19 @@
<?php
/**
* Zira project.
* cleaner.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Cron;
use Zira;
class Cleaner implements Zira\Cron {
public function run() {
\Stat\Models\Access::cleanUp();
\Stat\Models\Visitor::cleanUp();
\Stat\Models\Agent::cleanUp();
return Zira\Locale::tm('Statistics cleaned up','stat');
}
}

49
stat/forms/settings.php Normal file
View file

@ -0,0 +1,49 @@
<?php
/**
* Zira project.
* settings.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Forms;
use Zira;
use Zira\Form;
use Zira\Locale;
class Settings extends Form
{
protected $_id = 'dash-forum-settings-form';
protected $_label_class = 'col-sm-4 control-label';
protected $_input_wrap_class = 'col-sm-8';
protected $_input_offset_wrap_class = 'col-sm-offset-4 col-sm-8';
protected $_checkbox_inline_label = true;
public function __construct()
{
parent::__construct($this->_id);
}
protected function _init()
{
$this->setRenderPanel(false);
$this->setFormClass('form-horizontal dash-window-form');
}
protected function _render()
{
$html = $this->open();
$html .= $this->checkbox(Locale::tm('Collect browser information', 'stat'), 'stat_log_ua', null, false);
$html .= $this->checkbox(Locale::tm('Log requests', 'stat'), 'stat_log_access', null, false);
$html .= $this->close();
return $html;
}
protected function _validate()
{
//$validator = $this->getValidator();
}
}

53
stat/install/access.php Normal file
View file

@ -0,0 +1,53 @@
<?php
/**
* Zira project.
* access.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Install;
use Zira\Db\Table;
use Zira\Db\Field;
class Access extends Table {
protected $_table = 'stat_access';
public function __construct() {
parent::__construct($this->_table);
}
public function getFields() {
return array(
'id' => Field::primary(),
'anonymous_id' => Field::string(true),
'url' => Field::string(true),
'record_id' => Field::int(true, true),
'category_id' => Field::int(true, true),
'language' => Field::string(true),
'ip' => Field::string(true),
'ua' => Field::string(true),
'referer' => Field::string(true),
'access_day' => Field::date(true),
'access_time' => Field::datetime(true)
);
}
public function getKeys() {
return array(
'stat' => array('access_day')
);
}
public function getUnique() {
return array(
);
}
public function getDefaults() {
return array(
);
}
}

48
stat/install/agent.php Normal file
View file

@ -0,0 +1,48 @@
<?php
/**
* Zira project.
* agent.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Install;
use Zira\Db\Table;
use Zira\Db\Field;
class Agent extends Table {
protected $_table = 'stat_agents';
public function __construct() {
parent::__construct($this->_table);
}
public function getFields() {
return array(
'id' => Field::primary(),
'ua' => Field::string(true),
'mobile' => Field::tinyint(true, true, 0),
'anonymous_id' => Field::string(true),
'access_day' => Field::date(true)
);
}
public function getKeys() {
return array(
'ua' => array('ua', 'anonymous_id'),
'day' => array('access_day')
);
}
public function getUnique() {
return array(
);
}
public function getDefaults() {
return array(
);
}
}

46
stat/install/record.php Normal file
View file

@ -0,0 +1,46 @@
<?php
/**
* Zira project.
* record.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Install;
use Zira\Db\Table;
use Zira\Db\Field;
class Record extends Table {
protected $_table = 'stat_records';
public function __construct() {
parent::__construct($this->_table);
}
public function getFields() {
return array(
'id' => Field::primary(),
'record_id' => Field::int(true, true),
'category_id' => Field::int(true, true),
'views_count' => Field::int(true, true)
);
}
public function getKeys() {
return array(
);
}
public function getUnique() {
return array(
'record_id' => array('record_id')
);
}
public function getDefaults() {
return array(
);
}
}

48
stat/install/visitor.php Normal file
View file

@ -0,0 +1,48 @@
<?php
/**
* Zira project.
* visitor.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Install;
use Zira\Db\Table;
use Zira\Db\Field;
class Visitor extends Table {
protected $_table = 'stat_visitors';
public function __construct() {
parent::__construct($this->_table);
}
public function getFields() {
return array(
'id' => Field::primary(),
'record_id' => Field::int(true, true),
'category_id' => Field::int(true, true),
'anonymous_id' => Field::string(true),
'access_day' => Field::date(true)
);
}
public function getKeys() {
return array(
'record' => array('record_id', 'anonymous_id'),
'day' => array('access_day')
);
}
public function getUnique() {
return array(
);
}
public function getDefaults() {
return array(
);
}
}

119
stat/models/access.php Normal file
View file

@ -0,0 +1,119 @@
<?php
/**
* Zira project.
* access.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Models;
use Zira;
use Zira\Orm;
class Access extends Orm {
public static $table = 'stat_access';
public static $pk = 'id';
public static $alias = 'st_a';
public static function getTable() {
return self::$table;
}
public static function getPk() {
return self::$pk;
}
public static function getAlias() {
return self::$alias;
}
public static function getReferences() {
return array(
Zira\Models\Record::getClass() => 'record_id',
Zira\Models\Category::getClass() => 'category_id'
);
}
public static function log() {
try {
$record_id = (int)Zira\Page::getRecordId();
$category_id = Zira\Category::current() ? Zira\Category::current()->id : 0;
$anonymous_id = Zira\User::getAnonymousUserId();
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$referer = isset($_SERVER['HTTP_REFERER']) ? trim(urldecode($_SERVER['HTTP_REFERER'])) : '';
if ($record_id) {
$exists = \Stat\Models\Visitor::getCollection()
->where('record_id','=',$record_id)
->and_where('anonymous_id','=',$anonymous_id)
->limit(1)
->get(0);
if (!$exists) {
$visitor_object = new \Stat\Models\Visitor();
$visitor_object->record_id = $record_id;
$visitor_object->category_id= $category_id;
$visitor_object->anonymous_id = $anonymous_id;
$visitor_object->access_day = date('Y-m-d');
$visitor_object->save();
$stat_record = \Stat\Models\Record::getCollection()
->where('record_id','=',$record_id)
->get(0, true);
$stat_record_object = new \Stat\Models\Record();
if (!$stat_record) {
$stat_record_object->record_id = $record_id;
$stat_record_object->category_id= $category_id;
$stat_record_object->views_count = 1;
} else {
$stat_record_object->loadFromArray($stat_record);
$stat_record_object->views_count++;
}
$stat_record_object->save();
}
}
if (Zira\Config::get('stat_log_ua')) {
$ua_exists = \Stat\Models\Agent::getCollection()
->where('ua','=',$ua)
->and_where('anonymous_id','=',$anonymous_id)
->limit(1)
->get(0);
if (!$ua_exists) {
$ua_object = new \Stat\Models\Agent();
$ua_object->ua = $ua;
$ua_object->mobile= Zira\Request::isMobile() ? 1 : 0;
$ua_object->anonymous_id = $anonymous_id;
$ua_object->access_day = date('Y-m-d');
$ua_object->save();
}
}
if (Zira\Config::get('stat_log_access')) {
$stat = new self;
$stat->anonymous_id = $anonymous_id;
$stat->url = trim(urldecode(Zira\Request::uri()));
$stat->record_id = $record_id;
$stat->category_id = $category_id;
$stat->language = Zira\Locale::getLanguage();
$stat->ip = trim(Zira\Request::ip());
$stat->ua = $ua;
$stat->referer = $referer;
$stat->access_day = date('Y-m-d');
$stat->access_time = date('Y-m-d H:i:s');
$stat->save();
}
} catch(\Exception $e) {
// ignore
}
}
public static function cleanUp() {
self::getCollection()
->delete()
->where('access_day','<',date('Y-m-d', time()-2592000))
->execute();
}
}

42
stat/models/agent.php Normal file
View file

@ -0,0 +1,42 @@
<?php
/**
* Zira project.
* agent.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Models;
use Zira;
use Zira\Orm;
class Agent extends Orm {
public static $table = 'stat_agents';
public static $pk = 'id';
public static $alias = 'st_a';
public static function getTable() {
return self::$table;
}
public static function getPk() {
return self::$pk;
}
public static function getAlias() {
return self::$alias;
}
public static function getReferences() {
return array(
);
}
public static function cleanUp() {
self::getCollection()
->delete()
->where('access_day','<',date('Y-m-d', time()-31536000))
->execute();
}
}

36
stat/models/record.php Normal file
View file

@ -0,0 +1,36 @@
<?php
/**
* Zira project.
* record.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Models;
use Zira;
use Zira\Orm;
class Record extends Orm {
public static $table = 'stat_records';
public static $pk = 'id';
public static $alias = 'st_r';
public static function getTable() {
return self::$table;
}
public static function getPk() {
return self::$pk;
}
public static function getAlias() {
return self::$alias;
}
public static function getReferences() {
return array(
Zira\Models\Record::getClass() => 'record_id',
Zira\Models\Category::getClass() => 'category_id'
);
}
}

67
stat/models/requests.php Normal file
View file

@ -0,0 +1,67 @@
<?php
/**
* Zira project.
* requests.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Models;
use Zira;
use Dash;
use Stat;
use Zira\Permission;
class Requests extends Dash\Models\Model {
public function delete($data) {
if (empty($data) || !is_array($data)) return array('error' => Zira\Locale::t('An error occurred'));
if (!Permission::check(Permission::TO_EXECUTE_TASKS)) {
return array('error'=>Zira\Locale::t('Permission denied'));
}
foreach($data as $access_id) {
$access = new Stat\Models\Access($access_id);
if (!$access->loaded()) {
return array('error' => Zira\Locale::t('An error occurred'));
}
$access->delete();
}
return array('reload' => $this->getJSClassName());
}
public function request($access_id) {
$return = array();
$access = new Stat\Models\Access($access_id);
if ($access->loaded()) {
if ($access->category_id>0) {
$category = new Zira\Models\Category($access->category_id);
if ($category->loaded()) {
$return []= Zira\Locale::t('Category').': '.Zira\Helper::html($category->title);
}
}
if ($access->record_id>0) {
$record = new Zira\Models\Record($access->record_id);
if ($record->loaded()) {
$return []= Zira\Locale::t('Record').': '.Zira\Helper::html($record->title);
}
}
$return []= Zira\Locale::t('URL').': '.Zira\Helper::html($access->url);
$return []= Zira\Locale::t('IP').': '.Zira\Helper::html($access->ip);
$return []= Zira\Locale::t('User-Agent').': '.Zira\Helper::html($access->ua);
if ($access->referer) {
$return []= Zira\Locale::t('Referer').': '.Zira\Helper::html($access->referer);
}
if (count(Zira\Config::get('languages'))>1) {
$return []= Zira\Locale::t('Language').': '.Zira\Helper::html($access->language);
}
$mtime = strtotime($access->access_time);
$date = date(Zira\Config::get('date_format'), $mtime);
$time = date('H:i:s', $mtime);
$return []= Zira\Locale::t('Time').': '.Zira\Helper::html($date.' - '.$time);
}
return $return;
}
}

57
stat/models/settings.php Normal file
View file

@ -0,0 +1,57 @@
<?php
/**
* Zira project.
* settings.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Models;
use Zira;
use Dash;
use Stat;
use Zira\Permission;
class Settings extends Dash\Models\Model {
public function save($data) {
if (!Permission::check(Permission::TO_CHANGE_OPTIONS)) {
return array('error' => Zira\Locale::t('Permission denied'));
}
$form = new Stat\Forms\Settings();
if ($form->isValid()) {
$options = array(
'stat_log_ua' => 'int',
'stat_log_access' => 'int'
);
$config_ids = array();
$user_configs = Zira\Models\Option::getCollection()->get();
foreach($user_configs as $user_config) {
$config_ids[$user_config->name] = $user_config->id;
}
foreach($options as $option=>$type) {
if (!array_key_exists($option, $config_ids)) {
$optionObj = new Zira\Models\Option();
} else {
$optionObj = new Zira\Models\Option($config_ids[$option]);
}
$optionObj->name = $option;
$value = $form->getValue($option);
if ($type=='int') $value=intval($value);
$optionObj->value = $value;
$optionObj->module = 'forum';
$optionObj->save();
}
Zira\Models\Option::raiseVersion();
return array('message'=>Zira\Locale::t('Successfully saved'));
} else {
return array('error'=>$form->getError());
}
}
}

17
stat/models/stats.php Normal file
View file

@ -0,0 +1,17 @@
<?php
/**
* Zira project.
* stats.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Models;
use Zira;
use Dash;
use Stat;
use Zira\Permission;
class Stats extends Dash\Models\Model {
}

43
stat/models/visitor.php Normal file
View file

@ -0,0 +1,43 @@
<?php
/**
* Zira project.
* visitor.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Models;
use Zira;
use Zira\Orm;
class Visitor extends Orm {
public static $table = 'stat_visitors';
public static $pk = 'id';
public static $alias = 'st_v';
public static function getTable() {
return self::$table;
}
public static function getPk() {
return self::$pk;
}
public static function getAlias() {
return self::$alias;
}
public static function getReferences() {
return array(
Zira\Models\Record::getClass() => 'record_id',
Zira\Models\Category::getClass() => 'category_id'
);
}
public static function cleanUp() {
self::getCollection()
->delete()
->where('access_day','<',date('Y-m-d', time()-31536000))
->execute();
}
}

5
stat/module.meta Normal file
View file

@ -0,0 +1,5 @@
[meta]
name = Statistics
description = Collect statistics about your website visitors
author = Zira
version = 1.0

41
stat/stat.php Normal file
View file

@ -0,0 +1,41 @@
<?php
/**
* Zira project.
* stat.php
* (c)2018 http://dro1d.ru
*/
namespace Stat;
use Zira;
use Dash;
class Stat {
private static $_instance;
public static function getInstance() {
if (self::$_instance === null) {
self::$_instance = new self();
}
return self::$_instance;
}
public function bootstrap() {
if (ENABLE_CONFIG_DATABASE && Dash\Dash::getInstance()->isPanelEnabled() && Zira\Permission::check(Zira\Permission::TO_ACCESS_DASHBOARD) && Zira\Permission::check(Zira\Permission::TO_EXECUTE_TASKS)) {
Dash\Dash::loadDashLanguage();
Dash\Dash::getInstance()->addPanelModulesGroupItem('glyphicon glyphicon-signal', Zira\Locale::tm('Statistics', 'stat', null, Dash\Dash::getDashLanguage()), null, 'statsWindow()');
Dash\Dash::getInstance()->registerModuleWindowClass('statsWindow', 'Stat\Windows\Stats', 'Stat\Models\Stats');
Dash\Dash::getInstance()->registerModuleWindowClass('statRequestsWindow', 'Stat\Windows\Requests', 'Stat\Models\Requests');
Dash\Dash::getInstance()->registerModuleWindowClass('statSettingsWindow', 'Stat\Windows\Settings', 'Stat\Models\Settings');
Dash\Dash::unloadDashLanguage();
}
Zira\View::registerRenderHook(get_class(), 'log');
}
public static function log() {
if (Zira\View::isAjax()) return;
\Stat\Models\Access::log();
}
}

41
stat/widgets/record.php Normal file
View file

@ -0,0 +1,41 @@
<?php
/**
* Zira project.
* record.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Widgets;
use Zira;
class Record extends Zira\Widget {
protected $_title = 'Record views count';
protected function _init() {
$this->setDynamic(false);
$this->setCaching(false);
$this->setOrder(0);
$this->setPlaceholder(Zira\View::VAR_CONTENT);
}
protected function _render() {
if (Zira\Router::getModule()==DEFAULT_MODULE && Zira\Router::getController()==DEFAULT_CONTROLLER && Zira\Router::getAction()==DEFAULT_ACTION) return;
$record_id = (int)Zira\Page::getRecordId();
if (!$record_id) return;
$views = 0;
$row = \Stat\Models\Record::getCollection()
->where('record_id','=',$record_id)
->get(0);
if ($row) {
$views = $row->views_count;
}
Zira\View::renderView(array(
'views' => $views,
), 'stat/record');
}
}

78
stat/windows/requests.php Normal file
View file

@ -0,0 +1,78 @@
<?php
/**
* Zira project.
* requests.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Windows;
use Dash;
use Zira;
use Stat;
use Zira\Permission;
class Requests extends Dash\Windows\Window {
protected static $_icon_class = 'glyphicon glyphicon-signal';
protected static $_title = 'Requests';
public $page = 0;
public $pages = 0;
public $order = 'desc';
protected $limit = 50;
protected $total = 0;
//protected $_help_url = 'zira/help/stat-requests';
public function init() {
$this->setIconClass(self::$_icon_class);
$this->setTitle(Zira\Locale::t(self::$_title));
$this->setViewSwitcherEnabled(false);
$this->setSelectionLinksEnabled(true);
$this->setBodyViewListVertical(true);
$this->setSidebarEnabled(false);
$this->setDeleteActionEnabled(true);
}
public function create() {
}
public function load() {
if (!Permission::check(Permission::TO_EXECUTE_TASKS)) {
$this->setBodyItems(array());
return array('error'=>Zira\Locale::t('Permission denied'));
}
$limit= (int)Zira\Request::post('limit');
if ($limit > 0) {
$this->limit = $limit < \Dash\Dash::MAX_LIMIT ? $limit : \Dash\Dash::MAX_LIMIT;
}
$this->total = Stat\Models\Access::getCollection()->count()->get('co');
$this->pages = ceil($this->total/$this->limit);
if ($this->page>$this->pages) $this->page = $this->pages;
if ($this->page<1) $this->page=1;
$rows = Stat\Models\Access::getCollection()
->order_by('id',$this->order)
->limit($this->limit, ($this->page - 1) * $this->limit)
->get();
$items = array();
foreach($rows as $row) {
$mtime = date(Zira\Config::get('date_format'), strtotime($row->access_time));
$items[]=$this->createBodyFileItem(Zira\Helper::html($row->url), Zira\Helper::html($row->ip."\n".$row->ua), $row->id, 'desk_call(dash_stat_access_row,this);', false, array('type'=>'txt'), $mtime);
}
$this->setBodyItems($items);
$this->setData(array(
'page'=>$this->page,
'pages'=>$this->pages,
'limit'=>$this->limit,
'order'=>$this->order
));
}
}

51
stat/windows/settings.php Normal file
View file

@ -0,0 +1,51 @@
<?php
/**
* Zira project.
* settings.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Windows;
use Zira;
use Dash;
use Zira\Permission;
class Settings extends Dash\Windows\Window {
protected static $_icon_class = 'glyphicon glyphicon-cog';
protected static $_title = 'Statistics settings';
//protected $_help_url = 'zira/help/stat-settings';
public $item;
public function init() {
$this->setIconClass(self::$_icon_class);
$this->setTitle(Zira\Locale::t(self::$_title));
$this->setSidebarEnabled(false);
$this->setSaveActionEnabled(true);
}
public function create() {
$this->setOnLoadJSCallback(
$this->createJSCallback(
'desk_window_form_init(this);'
)
);
}
public function load() {
if (!empty($this->item)) $this->item=intval($this->item);
if (!Permission::check(Permission::TO_CHANGE_OPTIONS)) {
return array('error' => Zira\Locale::t('Permission denied'));
}
$configs = Zira\Config::getArray();
$form = new \Stat\Forms\Settings();
$form->setValues($configs);
$this->setBodyContent($form);
}
}

240
stat/windows/stats.php Normal file
View file

@ -0,0 +1,240 @@
<?php
/**
* Zira project.
* stats.php
* (c)2018 http://dro1d.ru
*/
namespace Stat\Windows;
use Dash;
use Zira;
use Stat;
use Zira\Permission;
class Stats extends Dash\Windows\Window {
protected static $_icon_class = 'glyphicon glyphicon-signal';
protected static $_title = 'Statistics';
//protected $_help_url = 'zira/help/stats';
public function init() {
$this->setIconClass(self::$_icon_class);
$this->setTitle(Zira\Locale::t(self::$_title));
$this->setViewSwitcherEnabled(false);
$this->setSelectionLinksEnabled(false);
$this->setBodyViewListVertical(true);
$this->setSidebarEnabled(false);
$this->setDeleteActionEnabled(false);
}
public function create() {
$this->addDefaultToolbarItem(
$this->createToolbarButton(Zira\Locale::tm('View requests', 'stat'), Zira\Locale::tm('View requests', 'stat'), 'glyphicon glyphicon-eye-open', 'desk_call(dash_stat_requests, this);')
);
$this->addDefaultToolbarItem(
$this->createToolbarButton(null, Zira\Locale::tm('Statistics settings', 'stat'), 'glyphicon glyphicon-cog', 'desk_call(dash_stat_settings, this);', 'settings', false, true)
);
$this->addVariables(array(
'dash_stat_requests_wnd' => Dash\Dash::getInstance()->getWindowJSName(Requests::getClass()),
'dash_stat_settings_wnd' => Dash\Dash::getInstance()->getWindowJSName(Settings::getClass())
));
$this->addStrings(array(
'Request',
'Requests logging is disabled'
));
$this->includeJS('stat/dash');
}
public function load() {
if (!Permission::check(Permission::TO_EXECUTE_TASKS)) {
$this->setBodyItems(array());
return array('error'=>Zira\Locale::t('Permission denied'));
}
$now = time();
$today_new_page_views_co = Stat\Models\Visitor::getCollection()
->count()
->where('access_day','=',date('Y-m-d', $now))
->get('co');
$yesterday_new_page_views_co = Stat\Models\Visitor::getCollection()
->count()
->where('access_day','=',date('Y-m-d', $now-86400))
->get('co');
$today_most_viewed_pages = Stat\Models\Visitor::getCollection()
->count()
->join(Zira\Models\Record::getClass(), array('title'))
->where('access_day','=',date('Y-m-d', $now))
->group_by('record_id')
->order_by('co', 'desc')
->limit(10)
->get();
$yesterday_most_viewed_pages = Stat\Models\Visitor::getCollection()
->count()
->join(Zira\Models\Record::getClass(), array('title'))
->where('access_day','=',date('Y-m-d', $now-86400))
->group_by('record_id')
->order_by('co', 'desc')
->limit(10)
->get();
$month_most_viewed_pages = Stat\Models\Visitor::getCollection()
->count()
->join(Zira\Models\Record::getClass(), array('title'))
->where('access_day','>',date('Y-m-d', $now-2592000))
->group_by('record_id')
->order_by('co', 'desc')
->limit(20)
->get();
if (Zira\Config::get('stat_log_ua')) {
$month_desktop_agents_co = Stat\Models\Agent::getCollection()
->count()
->where('access_day','>',date('Y-m-d', $now-2592000))
->and_where('mobile','=',0)
->get('co');
$month_mobile_agents_co = Stat\Models\Agent::getCollection()
->count()
->where('access_day','>',date('Y-m-d', $now-2592000))
->and_where('mobile','=',1)
->get('co');
$month_most_accessed_agents = Stat\Models\Agent::getCollection()
->select('ua')
->count()
->where('access_day','>',date('Y-m-d', $now-2592000))
->group_by('ua')
->order_by('co', 'desc')
->limit(20)
->get();
} else {
$month_desktop_agents_co = null;
$month_mobile_agents_co = null;
$month_most_accessed_agents = null;
}
if (Zira\Config::get('stat_log_access')) {
$today_requests_co = Stat\Models\Access::getCollection()
->count()
->where('access_day','=',date('Y-m-d', $now))
->get('co');
$yesterday_requests_co = Stat\Models\Access::getCollection()
->count()
->where('access_day','=',date('Y-m-d', $now-86400))
->get('co');
$month_referers = Stat\Models\Access::getCollection()
->where('access_day','>',date('Y-m-d', $now-2592000))
->and_where('referer','<>','')
->and_where('referer','not like','http://'.$_SERVER['HTTP_HOST'].'%')
->and_where('referer','not like','https://'.$_SERVER['HTTP_HOST'].'%')
->order_by('id', 'desc')
->limit(20)
->get();
} else {
$today_requests_co = null;
$yesterday_requests_co = null;
$month_referers = null;
}
$content = Zira\Helper::tag_open('div', array('style'=>'background:#e0e3ea'));
$content .= Zira\Helper::tag_open('div', array('style'=>'padding:14px;'));
$content .= Zira\Helper::tag('div', Zira\Locale::t('Today new page views: %s', $today_new_page_views_co));
$content .= Zira\Helper::tag('div', Zira\Locale::t('Yesterday new page views: %s', $yesterday_new_page_views_co));
$content .= Zira\Helper::tag_close('div');
if ($today_most_viewed_pages) {
$content .= Zira\Helper::tag_open('div', array('style'=>'padding:14px;background:#efefef'));
$content .= Zira\Locale::t('Today most viewed pages').':';
$co = 0;
foreach($today_most_viewed_pages as $today_most_viewed_page) {
$co++;
$content .= Zira\Helper::tag('div', $co.'. '.$today_most_viewed_page->title.' - '.$today_most_viewed_page->co, array('style'=>'padding-left:20px'));
}
$content .= Zira\Helper::tag_close('div');
}
if ($yesterday_most_viewed_pages) {
$content .= Zira\Helper::tag_open('div', array('style'=>'padding:14px;'));
$content .= Zira\Locale::t('Yesterday most viewed pages').':';
$co = 0;
foreach($yesterday_most_viewed_pages as $yesterday_most_viewed_page) {
$co++;
$content .= Zira\Helper::tag('div', $co.'. '.$yesterday_most_viewed_page->title.' - '.$yesterday_most_viewed_page->co, array('style'=>'padding-left:20px'));
}
$content .= Zira\Helper::tag_close('div');
}
if ($month_most_viewed_pages) {
$content .= Zira\Helper::tag_open('div', array('style'=>'padding:14px;background:#efefef'));
$content .= Zira\Locale::t('30-days most viewed pages').':';
$co = 0;
foreach($month_most_viewed_pages as $month_most_viewed_page) {
$co++;
$content .= Zira\Helper::tag('div', $co.'. '.$month_most_viewed_page->title.' - '.$month_most_viewed_page->co, array('style'=>'padding-left:20px'));
}
$content .= Zira\Helper::tag_close('div');
}
if ($month_desktop_agents_co !== null && $month_mobile_agents_co !== null) {
$month_all_agents_co = $month_desktop_agents_co + $month_mobile_agents_co;
$month_desktop_agents_percent = round($month_desktop_agents_co / $month_all_agents_co * 100);
$month_mobile_agents_percent = round($month_mobile_agents_co / $month_all_agents_co * 100);
$content .= Zira\Helper::tag_open('div', array('style'=>'padding:14px;'));
$content .= Zira\Locale::t('Browsers').':';
$content .= Zira\Helper::tag('div', Zira\Locale::t('Desktop devices: %s', $month_desktop_agents_percent.'%'), array('style'=>'padding-left:20px'));
$content .= Zira\Helper::tag('div', Zira\Locale::t('Mobile devices: %s', $month_mobile_agents_percent.'%'), array('style'=>'padding-left:20px'));
$content .= Zira\Helper::tag_close('div');
}
if ($month_most_accessed_agents) {
$content .= Zira\Helper::tag_open('div', array('style'=>'padding:14px;background:#efefef'));
$content .= Zira\Locale::t('30-days most used browsers').':';
$co = 0;
foreach($month_most_accessed_agents as $month_most_accessed_agent) {
$co++;
$content .= Zira\Helper::tag('div', $co.'. '.$month_most_accessed_agent->ua.' - '.$month_most_accessed_agent->co, array('style'=>'padding-left:20px'));
}
$content .= Zira\Helper::tag_close('div');
}
if ($today_requests_co !== null && $yesterday_requests_co !== null) {
$content .= Zira\Helper::tag_open('div', array('style'=>'padding:14px;'));
$content .= Zira\Locale::t('Requests').':';
$content .= Zira\Helper::tag('div', Zira\Locale::t('Today: %s', $today_requests_co), array('style'=>'padding-left:20px'));
$content .= Zira\Helper::tag('div', Zira\Locale::t('Yesterday: %s', $yesterday_requests_co), array('style'=>'padding-left:20px'));
$content .= Zira\Helper::tag_close('div');
}
if ($month_referers) {
$content .= Zira\Helper::tag_open('div', array('style'=>'padding:14px;background:#efefef'));
$content .= Zira\Locale::t('30-days referers').':';
$co = 0;
foreach($month_referers as $month_referer) {
$co++;
$content .= Zira\Helper::tag('div', $co.'. '.$month_referer->referer, array('style'=>'padding-left:20px'));
}
$content .= Zira\Helper::tag_close('div');
}
$content .= Zira\Helper::tag_close('div');
$this->setBodyContent($content);
$this->setData(array(
'access_log_enabled' => (int)Zira\Config::get('stat_log_access')
));
}
}

View file

@ -0,0 +1 @@
<div class="views_count_wrapper zira_bottom_counter" title="<?php echo t('Views: %s', (int)$views) ?>"><span class="glyphicon glyphicon-eye-open"></span> <?php echo (int)$views ?></div>

View file

@ -1,7 +1,7 @@
<?php
/**
* Zira project.
* index.php
* dash.php
* (c)2016 http://dro1d.ru
*/

View file

@ -36,7 +36,7 @@ class Cron extends Zira\Controller {
$response = Zira\Locale::t('An error occurred') . ': ' . $e->getMessage();
Zira\Log::exception($e);
}
$output .= "\t" . $co . '. ' . $response . "\r\n";
$output .= "\t" . $response . "\r\n";
}
}
Zira\Models\Option::write('cron_run', time());