diff options
author | vipsoft <vipsoft@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-03-30 02:50:49 +0400 |
---|---|---|
committer | vipsoft <vipsoft@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-03-30 02:50:49 +0400 |
commit | 0b08873d5c8a442facb82cdcbad5ce3b8130867d (patch) | |
tree | db865bb58bb17993ac99673e514829470dc3bb0c /plugins/Live | |
parent | c9f4913bf59d6972d139fa948607b66c6cdce4cc (diff) |
refs #1120 - commiting update from Live-0.5.5.zip
Diffstat (limited to 'plugins/Live')
-rw-r--r-- | plugins/Live/API.php | 96 | ||||
-rw-r--r-- | plugins/Live/Controller.php | 28 | ||||
-rw-r--r-- | plugins/Live/Visitor.php | 2 |
3 files changed, 41 insertions, 85 deletions
diff --git a/plugins/Live/API.php b/plugins/Live/API.php index c68fffa2a1..6f52e50d1d 100644 --- a/plugins/Live/API.php +++ b/plugins/Live/API.php @@ -221,7 +221,7 @@ class Piwik_Live_API /* * @return Piwik_DataTable */ - public function getUsersInLastXMin( $idSite = false, $limit = 10, $minIdVisit = false, $minutes = 30 ) + public function getUsersInLastXMin( $idSite = false, $minutes = 30 ) { if(is_null($idSite)) { @@ -231,18 +231,15 @@ class Piwik_Live_API { Piwik::checkUserHasViewAccess($idSite); } -// $visitorDetails = $this->loadLastVisitorDetailsInLastXMinFromDatabase(null, $idSite, $limit, $minIdVisit, $minutes); - $visitorDetails = $this->loadLastVisitorInLastXTimeFromDatabase(null, $idSite, $limit, $minIdVisit, $minutes, 0, 1); + $visitorData = $this->loadLastVisitorInLastXTimeFromDatabase($idSite, $minutes, 0, 1); - $table = $this->getCleanedVisitorsFromDetails($visitorDetails); - - return $table; + return $visitorData; } /* * @return Piwik_DataTable */ - public function getUsersInLastXDays( $idSite = false, $limit = 10, $minIdVisit = false, $days = 10 ) + public function getUsersInLastXDays( $idSite = false, $days = 10 ) { if(is_null($idSite)) @@ -253,20 +250,16 @@ class Piwik_Live_API { Piwik::checkUserHasViewAccess($idSite); } -// $visitorDetails = $this->loadLastVisitorDetailsInLastXDaysFromDatabase(null, $idSite, $limit, $minIdVisit, $days); - $visitorDetails = $this->loadLastVisitorInLastXTimeFromDatabase(null, $idSite, $limit, $minIdVisit, 0, $days, 1); - - $table = $this->getCleanedVisitorsFromDetails($visitorDetails); + $visitorData = $this->loadLastVisitorInLastXTimeFromDatabase($idSite, 0, $days, 1); - return $table; + return $visitorData; } /* * @return array */ - public function getPageImpressionsInLastXDays($idSite = false, $limit = 10, $minIdVisit = false, $days = 10){ - // for checking given vars - #echo $idSite.'|'.$limit.'|'.$minIdVisit.'|'.$days.'<br />'; + public function getPageImpressionsInLastXDays($idSite = false, $days = 10) + { if(is_null($idSite)) { @@ -276,24 +269,16 @@ class Piwik_Live_API { Piwik::checkUserHasViewAccess($idSite); } -// $pageDetails = $this->loadLastVisitedPagesInLastXDaysFromDatabase(null, $idSite, $limit, $minIdVisit, $days); - $pageDetails = $this->loadLastVisitorInLastXTimeFromDatabase(null, $idSite, $limit, $minIdVisit, 0, $days, 2); - - $i = -1; - foreach ($pageDetails as $detail) { - $i++; - if(strlen($pageDetails[$i]['name']) > 30) { - $pageDetails[$i]['name'] = substr($pageDetails[$i]['name'] , 0, 30 - 3).'...'; - } - } + $visitorData = $this->loadLastVisitorInLastXTimeFromDatabase($idSite, 0, $days, 2); - return $pageDetails; + return $visitorData; } /* * @return array */ - public function getPageImpressionsInLastXMin($idSite = false, $limit = 10, $minIdVisit = false, $minutes = 30){ + public function getPageImpressionsInLastXMin($idSite = false, $minutes = 30) + { if(is_null($idSite)) { @@ -303,34 +288,23 @@ class Piwik_Live_API { Piwik::checkUserHasViewAccess($idSite); } -// $pageDetails = $this->loadLastVisitedPagesInLastXMinFromDatabase(null, $idSite, $limit, $minIdVisit, $minutes); - $pageDetails = $this->loadLastVisitorInLastXTimeFromDatabase(null, $idSite, $limit, $minIdVisit, $minutes, 0, 2); - - $i = -1; - foreach ($pageDetails as $detail) { - $i++; - if(strlen($pageDetails[$i]['name']) > 30) { - $pageDetails[$i]['name'] = substr($pageDetails[$i]['name'] , 0, 30 - 3).'...'; - } - } - return $pageDetails; + $visitorData = $this->loadLastVisitorInLastXTimeFromDatabase($idSite, $minutes, 0, 2); + + return $visitorData; } /** * Load last Visitors PAGES or DETAILS in MINUTES or DAYS from database * - * @param boolen $visitorId - * @param boolen $idSite - * @param int $limit int - * @param int $minIdVisit + * @param int $idSite * @param int $minutes * @param int $days - * @param int $type 1 = DETAILS; 2 = PAGES + * @param int $type 1 = VISITS; 2 = PAGEVIEWS * * @return mixed */ - private function loadLastVisitorInLastXTimeFromDatabase($visitorId = null, $idSite = null, $limit = 1000, $minIdVisit = false, $minutes = 0, $days = 0, $type = 0 ) + private function loadLastVisitorInLastXTimeFromDatabase($idSite = null, $minutes = 0, $days = 0, $type = 0 ) { $where = $whereBind = array(); @@ -340,18 +314,6 @@ class Piwik_Live_API $whereBind[] = $idSite; } - if(!is_null($visitorId)) - { - $where[] = " `visitor_idcookie` = ? "; - $whereBind[] = $visitorId; - } - - if(!is_null($minIdVisit)) - { - $where[] = " " . Piwik::prefixTable('log_visit') . ".`idvisit` > ? "; - $whereBind[] = $minIdVisit; - } - if($minutes != 0) { $timeLimit = mktime(date("H"), date("i") - $minutes, 0, date("m"), date("d"), date("Y")); @@ -373,33 +335,17 @@ class Piwik_Live_API // Details if($type == 1) { - $sql = "SELECT " . Piwik::prefixTable('log_visit') . ".* + $sql = "SELECT " . Piwik::prefixTable('log_visit') . ".idvisit FROM " . Piwik::prefixTable('log_visit') . " $sqlWhere - ORDER BY idvisit DESC - LIMIT " . (int)$limit; + ORDER BY idvisit DESC"; } // Pages elseif($type == 2) { - // different SELECT between $minutes & $days - if($minutes != 0) - { - $sql_select = "SELECT " . Piwik::prefixTable('log_link_visit_action') . ".`idaction_url`, " . Piwik::prefixTable('log_action') . ".`idaction`, " . Piwik::prefixTable('log_action') . ".`name` , " . Piwik::prefixTable('log_visit') . ".*"; - } - elseif($days != 0) - { - $sql_select = "SELECT " . Piwik::prefixTable('log_link_visit_action') . ".`idaction_url`, " . Piwik::prefixTable('log_action') . ".`idaction`, " . Piwik::prefixTable('log_action') . ".`name` , " . Piwik::prefixTable('log_link_visit_action') . ".*"; - } - else - { - // neither $minutes nor $days --> ERROR - return false; - } - + $sql_select = "SELECT " . Piwik::prefixTable('log_link_visit_action') . ".`idaction_url`"; $sql = $sql_select." FROM " . Piwik::prefixTable('log_link_visit_action') . " - INNER JOIN " . Piwik::prefixTable('log_action') . " ON " . Piwik::prefixTable('log_link_visit_action') . ".`idaction_url`= " . Piwik::prefixTable('log_action') . ".`idaction` INNER JOIN " . Piwik::prefixTable('log_visit') . " ON " . Piwik::prefixTable('log_visit') . ".`idvisit` = " . Piwik::prefixTable('log_link_visit_action') . ".`idvisit` $sqlWhere"; } diff --git a/plugins/Live/Controller.php b/plugins/Live/Controller.php index 5fe8508a60..2aae5ac7ae 100644 --- a/plugins/Live/Controller.php +++ b/plugins/Live/Controller.php @@ -32,7 +32,8 @@ class Piwik_Live_Controller extends Piwik_Controller public function widget($fetch = false) { $view = Piwik_View::factory('index'); - $this->setGeneralVariablesView($view); +// $this->setGeneralVariablesView($view); + $view->idSite = Piwik_Common::getRequestVar('idSite'); $view->visitorsCountHalfHour = $this->getUsersInLastXMin(30); $view->visitorsCountToday = $this->getUsersInLastXDays(1); $view->pisHalfhour = $this->getPageImpressionsInLastXMin(30); @@ -124,7 +125,9 @@ class Piwik_Live_Controller extends Piwik_Controller public function getLastVisitsStart($fetch = false) { $view = Piwik_View::factory('lastVisits'); - $this->setGeneralVariablesView($view); +// $this->setGeneralVariablesView($view); + $view->idSite = Piwik_Common::getRequestVar('idSite'); + $view->visitors = $this->getLastVisits(10); $rendered = $view->render($fetch); @@ -138,35 +141,35 @@ class Piwik_Live_Controller extends Piwik_Controller public function getLastVisits($limit = 10) { - $api = new Piwik_API_Request("method=Live.getLastVisits&idSite=$this->idSite&limit=$limit&minIdVisit=$this->minIdVisit&format=php&serialize=0&disable_generic_filters=1"); + $api = new Piwik_API_Request("method=Live.getLastVisits&idSite=$this->idSite&limit=$limit&format=php&serialize=0&disable_generic_filters=1"); $visitors = $api->process(); return $visitors; } public function getUsersInLastXMin($minutes = 30) { - $api = new Piwik_API_Request("method=Live.getUsersInLastXMin&idSite=".$this->idSite."&limit=10000&minIdVisit=".$this->minIdVisit."&minutes=".$minutes."&format=php&serialize=0&disable_generic_filters=1"); + $api = new Piwik_API_Request("method=Live.getUsersInLastXMin&idSite=".$this->idSite."&minutes=".$minutes."&format=php&serialize=0&disable_generic_filters=1"); $visitors_halfhour = $api->process(); return count($visitors_halfhour); } public function getUsersInLastXDays($days = 1) { - $api = new Piwik_API_Request("method=Live.getUsersInLastXDays&idSite=$this->idSite&limit=50000&minIdVisit=$this->minIdVisit&days=$days&format=php&serialize=0&disable_generic_filters=1"); + $api = new Piwik_API_Request("method=Live.getUsersInLastXDays&idSite=$this->idSite&days=$days&format=php&serialize=0&disable_generic_filters=1"); $visitors_today = $api->process(); return count($visitors_today); } public function getPageImpressionsInLastXMin($minutes = 30) { - $api = new Piwik_API_Request("method=Live.getPageImpressionsInLastXMin&idSite=$this->idSite&limit=10000&minIdVisit=$this->minIdVisit&minutes=$minutes&format=php&serialize=0&disable_generic_filters=1"); + $api = new Piwik_API_Request("method=Live.getPageImpressionsInLastXMin&idSite=$this->idSite&minutes=$minutes&format=php&serialize=0&disable_generic_filters=1"); $pis_halfhour = $api->process(); return count($pis_halfhour); } public function getPageImpressionsInLastXDays($days = 1) { - $api = new Piwik_API_Request("method=Live.getPageImpressionsInLastXDays&idSite=$this->idSite&limit=50000&minIdVisit=$this->minIdVisit&days=$days&format=php&serialize=0&disable_generic_filters=1"); + $api = new Piwik_API_Request("method=Live.getPageImpressionsInLastXDays&idSite=$this->idSite&days=$days&format=php&serialize=0&disable_generic_filters=1"); $pis_today = $api->process(); return count($pis_today); @@ -175,12 +178,19 @@ class Piwik_Live_Controller extends Piwik_Controller public function ajaxTotalVisitors($fetch = false) { $view = Piwik_View::factory('totalVisits'); - $this->setGeneralVariablesView($view); +// $this->setGeneralVariablesView($view); + $view->idSite = Piwik_Common::getRequestVar('idSite'); $view->visitorsCountHalfHour = $this->getUsersInLastXMin(30); $view->visitorsCountToday = $this->getUsersInLastXDays(1); $view->pisHalfhour = $this->getPageImpressionsInLastXMin(30); $view->pisToday = $this->getPageImpressionsInLastXDays(1); - echo $view->render(); + $rendered = $view->render($fetch); + + if($fetch) + { + return $rendered; + } + echo $rendered; } } diff --git a/plugins/Live/Visitor.php b/plugins/Live/Visitor.php index a78f9ca9c4..388913e420 100644 --- a/plugins/Live/Visitor.php +++ b/plugins/Live/Visitor.php @@ -83,7 +83,7 @@ class Piwik_Live_Visitor function getServerDate() { - return date('Y-m-d', strtotime($this->details['visit_last_action_time'])); + return $this->details['visit_server_date']; } function getIp() |