Ticket #1120: piwik.patch

File piwik.patch, 30.3 KB (added by jr-ewing, 2 years ago)
  • plugins/Live/API.php

     
    1818 */ 
    1919require_once PIWIK_INCLUDE_PATH . '/plugins/Live/Visitor.php'; 
    2020 
    21 class Piwik_Live_API  
     21class Piwik_Live_API 
    2222{ 
    2323        static private $instance = null; 
    24          
     24 
    2525        /* 
    2626         * @return Piwik_Live_API 
    2727         */ 
    2828        static public function getInstance() 
    2929        { 
    3030                if (self::$instance == null) 
    31                 {             
     31                { 
    3232                        $c = __CLASS__; 
    3333                        self::$instance = new $c(); 
    3434                } 
     
    4242        { 
    4343                return $this->getLastVisitsForVisitor($visitorId, $idSite, 1); 
    4444        } 
    45          
     45 
    4646        /* 
    4747         * @return Piwik_DataTable 
    4848         */ 
     
    5656                { 
    5757                        Piwik::checkUserHasViewAccess($idSite); 
    5858                } 
     59 
    5960                $visitorDetails = self::loadLastVisitorDetailsFromDatabase($visitorId, $idSite, $limit); 
    6061                $table = self::getCleanedVisitorsFromDetails($visitorDetails); 
     62 
    6163                return $table; 
    6264        } 
    6365 
     
    7880                } 
    7981                $visitorDetails = self::loadLastVisitorDetailsFromDatabase(null, $idSite, $limit, $minIdVisit); 
    8082                $table = self::getCleanedVisitorsFromDetails($visitorDetails); 
    81 //              var_dump($table); 
     83 
    8284                return $table; 
    8385        } 
    8486 
     
    8890        public function getLastVisitsDetails( $idSite = false, $limit = 1000, $minIdVisit = false ) 
    8991        { 
    9092                // for checking given vars 
    91                 // echo $idSite.'|'.$limit.'|'.$minIdVisit.'<br>'; 
    9293                if(is_null($idSite)) 
    9394                { 
    9495                        Piwik::checkUserIsSuperUser(); 
     
    99100                } 
    100101                $visitorDetails = self::loadLastVisitorDetailsFromDatabase(null, $idSite, $limit, $minIdVisit); 
    101102                $dataTable = self::getCleanedVisitorsFromDetails($visitorDetails); 
    102 //echo "hallo"; 
    103 // 
    104103//              $dataTable->queueFilter('ColumnCallbackAddMetadata', array('operatingSystem', 'icon', 'Piwik_Live_Visitor::getVisitLength()')); 
    105                  
    106 // echo "<pre>"; 
    107 // var_dump($dataTable[0]); 
    108 // echo "</pre>";                
    109                  
     104 
    110105                return $dataTable; 
    111106        } 
    112107 
    113          
     108 
    114109        /* 
    115110         * @return Piwik_DataTable 
    116111         */ 
    117112        static private function getCleanedVisitorsFromDetails($visitorDetails) 
    118113        { 
    119114                $table = new Piwik_DataTable(); 
     115 
    120116                foreach($visitorDetails as $visitorDetail) 
    121117                { 
    122118                        self::cleanVisitorDetails($visitorDetail); 
    123119                        $visitor = new Piwik_Live_Visitor($visitorDetail); 
     120 
     121                        // $visitorDetail must contain the match_atribute 
    124122                        $visitorDetailsArray = $visitor->getAllVisitorDetails(); 
     123 
     124//                      $visitorDetailsArray['goalIcon'] = "themes/default/images/goal.png"; 
     125 
    125126                        $dateTimeVisit = Piwik_Date::factory($visitorDetailsArray['firstActionTimestamp']); 
    126127                        //TODO TO FIX 
    127128                        $visitorDetailsArray['serverDatePretty'] = $dateTimeVisit->getLocalized('%shortDay% %day% %shortMonth%'); 
    128129                        $visitorDetailsArray['serverTimePretty'] = $dateTimeVisit->getLocalized('%time%'); 
    129                          
    130                         // get Detail 
     130 
     131                        // get Detail - 100 single SQL Statements - Performance Issue 
    131132                        $idvisit = $visitorDetailsArray['idVisit']; 
    132                         $sql = "SELECT DISTINCT`" .Piwik::prefixTable('log_action')."`.`name` AS pageUrl 
    133                                 FROM `" .Piwik::prefixTable('log_visit')."` 
    134                                         INNER JOIN `" .Piwik::prefixTable('log_link_visit_action')."` ON `" .Piwik::prefixTable('log_visit')."`.`idvisit` =  `" .Piwik::prefixTable('log_link_visit_action')."`.`idvisit` 
     133 
     134                        $sql = "SELECT DISTINCT `" .Piwik::prefixTable('log_action')."`.`name` AS pageUrl 
     135                                FROM `" .Piwik::prefixTable('log_link_visit_action')."` 
    135136                                        INNER JOIN `" .Piwik::prefixTable('log_action')."` ON  `" .Piwik::prefixTable('log_link_visit_action')."`.`idaction_url` = `" .Piwik::prefixTable('log_action')."`.`idaction` 
    136                                 WHERE `" .Piwik::prefixTable('log_visit')."`.`idvisit` = $idvisit; 
     137                                WHERE `" .Piwik::prefixTable('log_link_visit_action')."`.`idvisit` = $idvisit; 
    137138                                 "; 
    138                          
     139 
    139140                        $visitorDetailsArray['actionDetails'] = Piwik_FetchAll($sql); 
    140                          
     141 
     142                        $sql = "SELECT DISTINCT `" .Piwik::prefixTable('log_action')."`.`name` AS pageUrl 
     143                                FROM `" .Piwik::prefixTable('log_link_visit_action')."` 
     144                                        INNER JOIN `" .Piwik::prefixTable('log_action')."` ON  `" .Piwik::prefixTable('log_link_visit_action')."`.`idaction_name` = `" .Piwik::prefixTable('log_action')."`.`idaction` 
     145                                WHERE `" .Piwik::prefixTable('log_link_visit_action')."`.`idvisit` = $idvisit; 
     146                                 "; 
     147 
     148                        $visitorDetailsArray['actionDetailsTitle'] = Piwik_FetchAll($sql); 
     149 
    141150                        $table->addRowFromArray( array(Piwik_DataTable_Row::COLUMNS => $visitorDetailsArray)); 
    142151                } 
     152 
    143153                return $table; 
    144154        } 
    145          
     155 
    146156        /* 
    147157         * @return array 
    148158         */ 
    149159        private function loadLastVisitorDetailsFromDatabase($visitorId = null, $idSite = null, $limit = null, $minIdVisit = false ) 
    150160        { 
    151161                // for checking given vars 
    152                 // echo $visitorId.'|'.$idSite.'|'.$limit.'|'.$minIdVisit.'<br>';                
     162                // echo $visitorId.'|'.$idSite.'|'.$limit.'|'.$minIdVisit.'<br>'; 
    153163                $where = $whereBind = array(); 
    154                  
     164 
    155165                if(!is_null($idSite)) 
    156166                { 
    157                         $where[] = " idsite = ? "; 
     167                        $where[] = Piwik::prefixTable('log_visit') . ".idsite = ? "; 
    158168                        $whereBind[] = $idSite; 
    159169                } 
    160                  
     170 
    161171                if(!is_null($visitorId)) 
    162172                { 
    163                         $where[] = " visitor_idcookie = ? "; 
     173                        $where[] = Piwik::prefixTable('log_visit') . ".visitor_idcookie = ? "; 
    164174                        $whereBind[] = $visitorId; 
    165175                } 
    166                  
     176 
    167177                if(!is_null($minIdVisit)) 
    168178                { 
    169                         $where[] = " idvisit > ? "; 
     179                        $where[] = Piwik::prefixTable('log_visit') . ".idvisit > ? "; 
    170180                        $whereBind[] = $minIdVisit; 
    171181                } 
    172                  
     182 
    173183                $sqlWhere = ""; 
    174184                if(count($where) > 0) 
    175185                { 
    176186                        $sqlWhere = " WHERE " . join(' AND ', $where); 
    177187                } 
    178                  
    179                 $sql = "SELECT * 
     188 
     189                $sql = "SELECT  " . Piwik::prefixTable('log_visit') . ".* , " . Piwik::prefixTable ( 'goal' ) . ".`match_attribute` 
    180190                                FROM " . Piwik::prefixTable('log_visit') . " 
    181                                 $sqlWhere  
     191                                LEFT JOIN ".Piwik::prefixTable('log_conversion')." ON " . Piwik::prefixTable('log_visit') . ".`idvisit` = " . Piwik::prefixTable('log_conversion') . ".`idvisit` 
     192                                LEFT JOIN ".Piwik::prefixTable('goal')." ON " . Piwik::prefixTable('goal') . ".`idgoal` = " . Piwik::prefixTable('log_conversion') . ".`idgoal` AND " . Piwik::prefixTable('goal') . ".`deleted` = 0 
     193                                $sqlWhere 
    182194                                ORDER BY idvisit DESC 
    183195                                LIMIT $limit"; 
    184                                  
     196 
     197 
    185198                return Piwik_FetchAll($sql, $whereBind); 
    186199        } 
    187200 
     
    190203         */ 
    191204        static private function cleanVisitorDetails( &$visitorDetails ) 
    192205        { 
    193                 $toUnset = array('config_md5config');            
     206                $toUnset = array('config_md5config'); 
    194207                if(!Piwik::isUserIsSuperUser()) 
    195208                { 
    196209                        $toUnset[] = 'visitor_idcookie'; 
     
    204217                        } 
    205218                } 
    206219        } 
    207          
    208          
    209          
     220 
     221 
     222 
    210223        /* 
    211224         * @return Piwik_DataTable 
    212225         */ 
     
    220233                { 
    221234                        Piwik::checkUserHasViewAccess($idSite); 
    222235                } 
    223                 $visitorDetails = self::loadLastVisitorDetailsInLastXMinFromDatabase(null, $idSite, $limit, $minIdVisit, $minutes); 
    224                  
     236//              $visitorDetails = self::loadLastVisitorDetailsInLastXMinFromDatabase(null, $idSite, $limit, $minIdVisit, $minutes); 
     237                $visitorDetails = self::loadLastVisitorInLastXTimeFromDatabase(null, $idSite, $limit, $minIdVisit, $minutes, 0, 1); 
    225238                $table = self::getCleanedVisitorsFromDetails($visitorDetails); 
     239 
    226240                return $table; 
    227241        } 
    228242 
     
    231245         */ 
    232246        public function getUsersInLastXDays( $idSite = false, $limit = 10, $minIdVisit = false, $days = 10 ) 
    233247        { 
    234          
     248 
    235249                if(is_null($idSite)) 
    236250                { 
    237251                        Piwik::checkUserIsSuperUser(); 
     
    240254                { 
    241255                        Piwik::checkUserHasViewAccess($idSite); 
    242256                } 
    243                 $visitorDetails = self::loadLastVisitorDetailsInLastXDaysFromDatabase(null, $idSite, $limit, $minIdVisit, $days); 
    244                  
     257//              $visitorDetails = self::loadLastVisitorDetailsInLastXDaysFromDatabase(null, $idSite, $limit, $minIdVisit, $days); 
     258                $visitorDetails = self::loadLastVisitorInLastXTimeFromDatabase(null, $idSite, $limit, $minIdVisit, 0, $days, 1); 
     259 
    245260                $table = self::getCleanedVisitorsFromDetails($visitorDetails); 
    246261 
    247262                return $table; 
    248263        } 
    249          
     264 
    250265        /* 
    251266         * @return array 
    252          */      
     267         */ 
    253268        public function getPageImpressionsInLastXDays($idSite = false, $limit = 10, $minIdVisit = false, $days = 10){ 
    254269                // for checking given vars 
    255270                #echo $idSite.'|'.$limit.'|'.$minIdVisit.'|'.$days.'<br>'; 
    256                          
     271 
    257272                if(is_null($idSite)) 
    258273                { 
    259274                        Piwik::checkUserIsSuperUser(); 
     
    262277                { 
    263278                        Piwik::checkUserHasViewAccess($idSite); 
    264279                } 
    265                 $pageDetails = self::loadLastVisitedPagesInLastXDaysFromDatabase(null, $idSite, $limit, $minIdVisit, $days); 
    266                  
     280//              $pageDetails = self::loadLastVisitedPagesInLastXDaysFromDatabase(null, $idSite, $limit, $minIdVisit, $days); 
     281                $pageDetails = self::loadLastVisitorInLastXTimeFromDatabase(null, $idSite, $limit, $minIdVisit, 0, $days, 2); 
     282 
    267283                $i = -1; 
    268284                foreach ($pageDetails as $detail) { 
    269285                        $i++; 
     
    272288                        } 
    273289                } 
    274290 
    275                 return $pageDetails;             
     291                return $pageDetails; 
    276292        } 
    277293 
    278294        /* 
    279295         * @return array 
    280          */      
     296         */ 
    281297        public function getPageImpressionsInLastXMin($idSite = false, $limit = 10, $minIdVisit = false, $minutes = 30){ 
    282298 
    283299                if(is_null($idSite)) 
     
    288304                { 
    289305                        Piwik::checkUserHasViewAccess($idSite); 
    290306                } 
    291                 $pageDetails = self::loadLastVisitedPagesInLastXMinFromDatabase(null, $idSite, $limit, $minIdVisit, $minutes); 
    292                  
     307//              $pageDetails = self::loadLastVisitedPagesInLastXMinFromDatabase(null, $idSite, $limit, $minIdVisit, $minutes); 
     308                $pageDetails = self::loadLastVisitorInLastXTimeFromDatabase(null, $idSite, $limit, $minIdVisit, $minutes, 0, 2); 
     309 
    293310                $i = -1; 
    294311                foreach ($pageDetails as $detail) { 
    295312                        $i++; 
     
    297314                                $pageDetails[$i]['name']  = substr($pageDetails[$i]['name'] , 0, 30 - 3).'...'; 
    298315                        } 
    299316                } 
    300                 return $pageDetails;             
     317                return $pageDetails; 
    301318        } 
    302                  
    303319 
    304          
    305320 
    306         /* 
    307          * TODO should be refactored with function below 
    308          * @return array 
     321        /** 
     322         * Load last Visitors PAGES or DETAILS in MINUTES or DAYS from database 
     323         * 
     324         * @param boolen $visitorId 
     325         * @param boolen $idSite 
     326         * @param int $limit int 
     327         * @param int $minIdVisit 
     328         * @param int $minutes 
     329         * @param int $days 
     330         * @param int $type 1 = DETAILS; 2 = PAGES 
     331         * 
     332         * @return mixed 
    309333         */ 
    310         private function loadLastVisitorDetailsInLastXMinFromDatabase($visitorId = null, $idSite = null, $limit = 1000, $minIdVisit = false, $minutes = 0 ) 
     334        private function loadLastVisitorInLastXTimeFromDatabase($visitorId = null, $idSite = null, $limit = 1000, $minIdVisit = false, $minutes = 0, $days = 0, $type = 0 ) 
    311335        { 
    312336                $where = $whereBind = array(); 
    313                  
     337 
    314338                if(!is_null($idSite)) 
    315339                { 
    316                         $where[] = " idsite = ? "; 
     340                        $where[] = " " . Piwik::prefixTable('log_visit') . ".`idsite` = ? "; 
    317341                        $whereBind[] = $idSite; 
    318342                } 
    319                  
     343 
    320344                if(!is_null($visitorId)) 
    321345                { 
    322                         $where[] = " visitor_idcookie = ? "; 
     346                        $where[] = " `visitor_idcookie` = ? "; 
    323347                        $whereBind[] = $visitorId; 
    324348                } 
    325                  
     349 
    326350                if(!is_null($minIdVisit)) 
    327351                { 
    328                         $where[] = " idvisit > ? "; 
     352                        $where[] = " " . Piwik::prefixTable('log_visit') . ".`idvisit` > ? "; 
    329353                        $whereBind[] = $minIdVisit; 
    330354                } 
    331                  
     355 
    332356                if($minutes != 0) 
    333357                { 
    334358                        $timeLimit = mktime(date("H"), date("i") - $minutes, 0, date("m"),   date("d"),   date("Y")); 
    335  
    336                         $where[] = " visit_last_action_time > '".date('Y-m-d H:i:s',$timeLimit)."'"; 
    337                 } 
    338                  
    339                 $sqlWhere = ""; 
    340                 if(count($where) > 0) 
    341                 { 
    342                         $sqlWhere = " WHERE " . join(' AND ', $where); 
    343                 } 
    344                  
    345                 $sql = "SELECT  * 
    346                                 FROM " . Piwik::prefixTable('log_visit') . " 
    347                                 $sqlWhere  
    348                                 ORDER BY idvisit DESC 
    349                                 LIMIT " . (int)$limit; 
    350                 return Piwik_FetchAll($sql, $whereBind); 
    351         } 
    352          
    353         /* 
    354          * TODO should be refactored with function above 
    355          * @return array 
    356          */ 
    357         private function loadLastVisitorDetailsInLastXDaysFromDatabase($visitorId = null, $idSite = null, $limit = 1000, $minIdVisit = false, $days = 0 ) 
    358         { 
    359                 $where = $whereBind = array(); 
    360                  
    361                 if(!is_null($idSite)) 
    362                 { 
    363                         $where[] = " idsite = ? "; 
    364                         $whereBind[] = $idSite; 
     359                        $where[] = " `visit_last_action_time` > '".date('Y-m-d H:i:s',$timeLimit)."'"; 
    365360                } 
    366                  
    367                 if(!is_null($visitorId)) 
    368                 { 
    369                         $where[] = " visitor_idcookie = ? "; 
    370                         $whereBind[] = $visitorId; 
    371                 } 
    372                  
    373                 if(!is_null($minIdVisit)) 
    374                 { 
    375                         $where[] = " idvisit > ? "; 
    376                         $whereBind[] = $minIdVisit; 
    377                 } 
    378                  
     361 
    379362                if($days != 0) 
    380363                { 
    381364                        $timeLimit = mktime(0, 0, 0, date("m"),   date("d") - $days + 1,   date("Y")); 
    382  
    383                         $where[] = " visit_last_action_time > '".date('Y-m-d H:i:s',$timeLimit)."'"; 
     365                        $where[] = " `visit_last_action_time` > '".date('Y-m-d H:i:s',$timeLimit)."'"; 
    384366                } 
    385                  
     367 
    386368                $sqlWhere = ""; 
    387369                if(count($where) > 0) 
    388370                { 
    389371                        $sqlWhere = " WHERE " . join(' AND ', $where); 
    390372                } 
    391                  
    392                 $sql = "SELECT  * 
     373 
     374                // Details 
     375                if($type == 1) 
     376                { 
     377                        $sql = "SELECT  " . Piwik::prefixTable('log_visit') . ".* 
    393378                                FROM " . Piwik::prefixTable('log_visit') . " 
    394                                 $sqlWhere  
     379                                $sqlWhere 
    395380                                ORDER BY idvisit DESC 
    396381                                LIMIT " . (int)$limit; 
    397                 return Piwik_FetchAll($sql, $whereBind); 
    398         } 
    399          
    400         /* 
    401          * TODO should be refactored with function above 
    402          * @return array 
    403          */ 
    404         private function loadLastVisitedPagesInLastXMinFromDatabase($visitorId = null, $idSite = null, $limit = null, $minIdVisit = false, $minutes = 0 ) 
    405         { 
    406                 $where = $whereBind = array(); 
    407                  
    408                 if(!is_null($idSite)) 
    409                 { 
    410                         $where[] = " idsite = ? "; 
    411                         $whereBind[] = $idSite; 
    412                 } 
    413                  
    414                 if(!is_null($visitorId)) 
    415                 { 
    416                         $where[] = " visitor_idcookie = ? "; 
    417                         $whereBind[] = $visitorId; 
    418                 } 
    419                  
    420                 if(!is_null($minIdVisit)) 
    421                 { 
    422                         $where[] = Piwik::prefixTable('log_visit') .".idvisit > ? "; 
    423                         $whereBind[] = $minIdVisit; 
    424                 } 
    425  
    426                 if($minutes != 0) 
    427                 { 
    428                         $timeLimit = mktime(date("H"), date("i") - $minutes, 0, date("m"),   date("d"),   date("Y")); 
     382                 } 
     383                 // Pages 
     384                 elseif($type == 2) 
     385                 { 
     386                        // different SELECT between $minutes & $days 
     387                        if($minutes != 0) 
     388                        { 
     389                                $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') . ".*"; 
     390                        } 
     391                        elseif($days != 0) 
     392                        { 
     393                            $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') . ".*"; 
     394                        } 
     395                        else 
     396                        { 
     397                                // neither $minutes nor $days --> ERROR 
     398                                return false; 
     399                        } 
    429400 
    430                         $where[] = " visit_last_action_time > '".date('Y-m-d H:i:s',$timeLimit)."'"; 
    431                 } 
    432                  
    433                 $sqlWhere = ""; 
    434                 if(count($where) > 0) 
    435                 { 
    436                         $sqlWhere = " WHERE " . join(' AND ', $where); 
    437                 } 
    438                  
    439                 $sql = "SELECT " . Piwik::prefixTable('log_link_visit_action') . ".`idaction_url`," . Piwik::prefixTable('log_action') . ".`idaction`, " . Piwik::prefixTable('log_action') . ".`name` , " . Piwik::prefixTable('log_visit') . ".* 
     401                        $sql = $sql_select." 
    440402                                FROM " . Piwik::prefixTable('log_link_visit_action') . " 
    441                                 INNER JOIN " . Piwik::prefixTable('log_action') . " ON " . Piwik::prefixTable('log_link_visit_action') . ".`idaction_url`= " . Piwik::prefixTable('log_action') . ".`idaction`  
     403                                INNER JOIN " . Piwik::prefixTable('log_action') . " ON " . Piwik::prefixTable('log_link_visit_action') . ".`idaction_url`= " . Piwik::prefixTable('log_action') . ".`idaction` 
    442404                                INNER JOIN " . Piwik::prefixTable('log_visit') . " ON " . Piwik::prefixTable('log_visit') . ".`idvisit` = " . Piwik::prefixTable('log_link_visit_action') . ".`idvisit` 
    443405                                $sqlWhere"; 
    444                 return Piwik_FetchAll($sql, $whereBind); 
    445         }        
    446                  
    447         /* 
    448          * TODO should be refactored with function above 
    449          * @return array 
    450          */ 
    451         private function loadLastVisitedPagesInLastXDaysFromDatabase($visitorId = null, $idSite = null, $limit = null, $minIdVisit = false, $days = 0 ) 
    452         { 
    453                 $where = $whereBind = array(); 
    454                  
    455                 if(!is_null($idSite)) 
    456                 { 
    457                         $where[] = " idsite = ? "; 
    458                         $whereBind[] = $idSite; 
    459                 } 
    460                  
    461                 if(!is_null($visitorId)) 
    462                 { 
    463                         $where[] = " visitor_idcookie = ? "; 
    464                         $whereBind[] = $visitorId; 
    465                 } 
    466                  
    467                 if($days != 0) 
    468                 { 
    469                         $timeLimit = mktime(0, 0, 0, date("m"),   date("d") - $days + 1,   date("Y")); 
     406                 } 
     407                 else 
     408                 { 
     409                        // no $type is set --> ERROR 
     410                        return false; 
     411                 } 
    470412 
    471                         $where[] = " visit_last_action_time > '".date('Y-m-d H:i:s',$timeLimit)."'"; 
    472                 } 
    473                  
    474                 $sqlWhere = ""; 
    475                 if(count($where) > 0) 
    476                 { 
    477                         $sqlWhere = " WHERE " . join(' AND ', $where); 
    478                 } 
    479                  
    480                 $sql = "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') . ".* 
    481                                 FROM " . Piwik::prefixTable('log_link_visit_action') . " 
    482                                 INNER JOIN " . Piwik::prefixTable('log_action') . " ON " . Piwik::prefixTable('log_link_visit_action') . ".`idaction_url`= " . Piwik::prefixTable('log_action') . ".`idaction`  
    483                                 INNER JOIN " . Piwik::prefixTable('log_visit') . " ON " . Piwik::prefixTable('log_visit') . ".idvisit=" . Piwik::prefixTable('log_link_visit_action') . ".idvisit 
    484                                 $sqlWhere"; 
    485  
     413                // return $sql by fetching 
    486414                return Piwik_FetchAll($sql, $whereBind); 
    487415        } 
    488          
     416 
    489417} 
  • plugins/Live/Visitor.php

     
    7575                        'screenIcon' => $this->getScreenTypeIcon(), 
    7676                        'plugins' => $this->getPlugins(), 
    7777                        'lastActionDateTime' => $this->getDateTimeLastAction(), 
     78                        'isVisitorGoalConverted' => $this->isVisitorGoalConverted(), 
     79                        'goalIcon' => $this->getGoalIcon(), 
     80                        'goalType' => $this->getGoalType(),              
    7881                ); 
    7982        } 
    8083         
     
    121124        { 
    122125                return $this->details['visitor_returning']; 
    123126        } 
    124          
     127 
    125128        function getTimestampFirstAction() 
    126129        { 
    127130                return strtotime($this->details['visit_first_action_time']); 
     
    291294        { 
    292295                return date('Y-m-d H:i:s', strtotime($this->details['visit_last_action_time'])); 
    293296        } 
    294 } 
     297 
     298        function isVisitorGoalConverted() 
     299        { 
     300                return $this->details['visit_goal_converted']; 
     301        } 
     302         
     303        function getGoalType() 
     304        { 
     305                if(isset($this->details['match_attribute'])){ 
     306                        return $this->details['match_attribute']; 
     307                } 
     308                else { 
     309                        return false; 
     310                }        
     311        } 
     312         
     313        function getGoalIcon() 
     314        {        
     315                $goalicon = ""; 
     316                if(isset($this->details['match_attribute'])){ 
     317                        switch ($this->details['match_attribute']) { 
     318                        case "url": 
     319                                $goalicon = "plugins/Live/templates/images/goal.png"; 
     320                                break; 
     321                            case "file": 
     322                                $goalicon = "plugins/Live/templates/images/download.png"; 
     323                                break; 
     324                            case "external_website": 
     325                                $goalicon = "plugins/Live/templates/images/outboundlink.png"; 
     326                                break;   
     327                        } 
     328                        return $goalicon; 
     329                } 
     330                else { 
     331                        return false; 
     332                }                                
     333        } 
     334                 
     335} 
     336 No newline at end of file 
  • plugins/Live/templates/lastVisits.tpl

     
    22        <div class="visit{if $visitor.idVisit % 2} alt{/if}"> 
    33                <!--<div class="idvisit">{$visitor.idVisit}</div>--> 
    44                <div style="display:none" class="idvisit">{$visitor.idVisit}</div> 
    5          
     5 
    66                        <div class="datetime"> 
    77                                {$visitor.serverDatePretty} - {$visitor.serverTimePretty} 
    88                                &nbsp;<img src="{$visitor.countryFlag}" title="{$visitor.country}, Provider {$visitor.provider}"> 
    99                                &nbsp;<img src="{$visitor.browserIcon}" title="{$visitor.browser} with plugins {$visitor.plugins} enabled"> 
    10                                 &nbsp;<img src="{$visitor.operatingSystemIcon}" title="{$visitor.operatingSystem}, {$visitor.resolution}">               
     10                                &nbsp;<img src="{$visitor.operatingSystemIcon}" title="{$visitor.operatingSystem}, {$visitor.resolution}"> 
     11                                &nbsp;{if $visitor.isVisitorGoalConverted}<img src="{$visitor.goalIcon}" title="{$visitor.goalType}">{/if} 
     12                                {if $visitor.isVisitorReturning}&nbsp;<img src="plugins/Live/templates/images/returningVisitor.gif" title="Returning Visitor">{/if} 
     13                                &nbsp;<label id="" title="IP: {$visitor.ip} - Duration: {$visitor.visitLengthPretty}">more...</label> 
    1114                        </div> 
    12                         <div class="settings"> 
    13                                 {$visitor.ip}  
    14                                 {if $visitor.isVisitorReturning}<img src="plugins/Live/templates/images/returningVisitor.gif" title="Returning Visitor">{/if} 
    15                         </div> 
     15                        <!--<div class="settings"></div>--> 
    1616                        <div class="referer"> 
    17                                 {if $visitor.refererType != 'directEntry'}from <a href="{$visitor.refererUrl}"><img src="{$visitor.searchEngineIcon}"> {$visitor.refererName}</a>  
     17                                {if $visitor.refererType != 'directEntry'}from <a href="{$visitor.refererUrl}"><img src="{$visitor.searchEngineIcon}"> {$visitor.refererName}</a> 
    1818                                        {if !empty($visitor.keywords)}"{$visitor.keywords}"{/if} 
    1919                                {/if} 
    2020                                {if $visitor.refererType == 'directEntry'}Direct entry{/if} 
    2121                        </div> 
    22                 <div id="{$visitor.idVisit}_actions" class="actions"> 
     22                <div id="{$visitor.idVisit}_actions" class="settings"> 
    2323                        <span class="pagesTitle">Pages:</span>&nbsp; 
    2424                        {php} $col = 0; {/php} 
    2525                        {foreach from=$visitor.actionDetails item=action} 
    26                           {php}  
    27                                 $col++;  
     26                          {php} 
     27                                $col++; 
    2828                                if ($col>=9) 
    2929                                { 
    3030                                  $col=0; 
    3131                                } 
    32                                 {/php}   
     32                                {/php} 
    3333                                <a href="{$action.pageUrl}" target="_blank"><img align="middle" src="plugins/Live/templates/images/file{php} echo $col; {/php}.png" title="{$action.pageUrl}"></a> 
    3434                        {/foreach} 
    3535                </div> 
  • plugins/Live/templates/index.tpl

     
    33 
    44<script type="text/javascript" charset="utf-8"> 
    55 
    6   
    7         $(document).ready(function() {  
     6 
     7        $(document).ready(function() { 
    88                if($('#_spyTmp').size() == 0) { 
    99                        $('#visitsLive > div:gt(2)').fadeEachDown(); // initial fade 
    10                         $('#visitsLive').spy({  
    11                                 limit: 10,  
    12                                 ajax: 'index.php?module=Live&idSite={/literal}{$idSite}{literal}&action=getLastVisitsStart',  
    13                                 fadeLast: 2,  
     10                        $('#visitsLive').spy({ 
     11                                limit: 10, 
     12                                ajax: 'index.php?module=Live&idSite={/literal}{$idSite}{literal}&action=getLastVisitsStart', 
     13                                fadeLast: 2, 
    1414                                isDupes : check_for_dupe, 
    1515                                timeout: 20000, 
    16                                 customParameterName: 'minIdVisit',  
     16                                customParameterName: 'minIdVisit', 
    1717                                customParameterValueCallback: lastIdVisit, 
    1818                                fadeInSpeed: 1400 
    19                         }); 
     19                        });      
    2020                } 
    2121        }); 
    22                  
     22 
    2323        // first I'm ensuring that 'last' has been initialised (with last.constructor == Object), 
    2424        // then prev.html() == last.html() will return true if the HTML is the same, or false, 
    2525        // if I have a different entry. 
    2626        function check_for_dupe(prev, last) 
    2727        { 
    28                  
     28 
    2929                if (last.constructor == Object) { 
    3030                        return (prev.html() == last.html()); 
    31                 }        
     31                } 
    3232                else { 
    3333                        return 0; 
    34                          
    35                 }        
     34 
     35                } 
    3636        } 
    3737 
    3838        function lastIdVisit() 
     
    4646        var pauseDisabledImage = "plugins/Live/templates/images/pause_disabled.gif"; 
    4747        var playImage = "plugins/Live/templates/images/play.gif"; 
    4848        var playDisabledImage = "plugins/Live/templates/images/play_disabled.gif"; 
    49          
     49 
    5050        function onClickPause() 
    5151        { 
    5252                $('#pauseImage').attr('src', pauseImage); 
     
    5959                $('#pauseImage').attr('src', pauseDisabledImage); 
    6060                return playSpy(); 
    6161        } 
    62          
     62 
    6363        // updates the numbers of total visits in startbox 
    6464        function updateTotalVisits() 
    6565        { 
    6666                $("#visitsTotal").load("index.php?module=Live&idSite={/literal}{$idSite}{literal}&action=ajaxTotalVisitors"); 
    6767        } 
    68          
     68 
    6969        // updates the visit table, to refresh the already presented visotors pages 
    7070        function updateVisitBox() 
    7171        { 
    7272                $("#visitsLive").load("index.php?module=Live&idSite={/literal}{$idSite}{literal}&action=getLastVisitsStart"); 
    7373        } 
    7474 
     75        /* TOOLTIP */ 
     76                $('#visitsLive label').tooltip({ 
     77                    track: true, 
     78                    delay: 0, 
     79                    showURL: false, 
     80                    showBody: " - ", 
     81                    fade: 250 
     82                }); 
     83 
    7584</script> 
    7685 
    7786<style> 
     
    8291#visitsLive .datetime, #visitsLive .country, #visitsLive .referer, #visitsLive .settings, #visitsLive .returning , #visitsLive .countActions{ 
    8392        border-bottom:1px solid #C1DAD7; 
    8493        border-right:1px solid #C1DAD7; 
    85         padding:5px 5px 5px 12px;        
     94        padding:5px 5px 5px 12px; 
    8695} 
    8796 
    8897#visitsLive .datetime { 
     
    169178</div> 
    170179 
    171180<div> 
    172         <a href="javascript:void(0);" onclick="onClickPause();"><img id="pauseImage" border="0" src="plugins/Live/templates/images/pause_disabled.gif"></a>  
     181        <a href="javascript:void(0);" onclick="onClickPause();"><img id="pauseImage" border="0" src="plugins/Live/templates/images/pause_disabled.gif"></a> 
    173182        <a href="javascript:void(0);" onclick="onClickPlay();"><img id="playImage" border="0" src="plugins/Live/templates/images/play.gif"></a> 
    174183</div> 
  • plugins/Live/Controller.php

     
    11<?php 
    22/** 
    33 * Piwik - Open source web analytics 
    4  *  
     4 * 
    55 * @link http://piwik.org 
    66 * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later 
    77 * @version $Id$ 
    8  *  
     8 * 
    99 * @category Piwik_Plugins 
    1010 * @package Piwik_Live 
    1111 */ 
     
    1616 */ 
    1717class Piwik_Live_Controller extends Piwik_Controller 
    1818{ 
    19          
     19 
    2020        function __construct() 
    2121        { 
    2222                parent::__construct(); 
    2323                $this->idSite = Piwik_Common::getRequestVar('idSite'); 
    2424                $this->minIdVisit = Piwik_Common::getRequestVar('minIdVisit', 0, 'int'); 
    2525        } 
    26                  
     26 
    2727        function index() 
    2828        { 
    2929                $this->widget(true); 
    30         }        
    31          
     30        } 
     31 
    3232        public function widget($fetch = false) 
    3333        { 
    34                 $view = Piwik_View::factory('index');            
     34                $view = Piwik_View::factory('index'); 
    3535                $this->setGeneralVariablesView($view); 
    3636                $view->visitorsCountHalfHour = $this->getUsersInLastXMin(30); 
    3737                $view->visitorsCountToday = $this->getUsersInLastXDays(1); 
     
    3939                $view->pisToday = $this->getPageImpressionsInLastXDays(1); 
    4040                $view->visitors = $this->getLastVisitsStart($fetch = true); 
    4141 
    42                 echo $view->render();            
     42                echo $view->render(); 
    4343        } 
    44          
     44 
    4545        public function getLastVisitsDetails($fetch = false) 
    4646        { 
    4747                $view = Piwik_ViewDataTable::factory(''); 
    4848                $view->init( $this->pluginName, 
    49                                                         __FUNCTION__,  
     49                                                        __FUNCTION__, 
    5050                                                'Live.getLastVisitsDetails', 
    51                                                 'getPagesFromVisitId');                                                                                  
     51                                                'getPagesFromVisitId'); 
    5252// All colomns in DB which could be shown 
    53 //'ip', 'idVisit', 'countActions', 'isVisitorReturning', 'country', 'countryFlag', 'continent', 'provider', 'providerUrl', 'idSite',  
    54 //'serverDate', 'visitLength', 'visitLengthPretty', 'firstActionTimestamp', 'lastActionTimestamp', 'refererType', 'refererName',         
     53//'ip', 'idVisit', 'countActions', 'isVisitorReturning', 'country', 'countryFlag', 'continent', 'provider', 'providerUrl', 'idSite', 
     54//'serverDate', 'visitLength', 'visitLengthPretty', 'firstActionTimestamp', 'lastActionTimestamp', 'refererType', 'refererName', 
    5555//'keywords', 'refererUrl', 'searchEngineUrl', 'searchEngineIcon', 'operatingSystem', 'operatingSystemShortName', 'operatingSystemIcon', 
    5656//'browserFamily', 'browserFamilyDescription', 'browser', 'browserIcon', 'screen', 'resolution', 'screenIcon', 'plugins', 'lastActionDateTime', 
    5757//'serverDatePretty', 'serverTimePretty', 'actionDetails' 
    58                  
     58 
    5959                $view->setColumnsToDisplay(array( 
    6060//                      'label', 
    6161                        'idVisit', 
     
    7878                        'idVisit' => Piwik_Translate(''), 
    7979                        'serverDatePretty' => Piwik_Translate('Live_Date'), 
    8080                        'serverTimePretty' => Piwik_Translate('Live_Time'), 
    81                         'ip' => 'IP',  
     81                        'ip' => 'IP', 
    8282                        'countActions' => Piwik_Translate('VisitorInterest_ColumnPagesPerVisit'), 
    8383                        'visitLengthPretty' => Piwik_Translate('VisitorInterest_ColumnVisitDuration'), 
    8484                        'keywords' => Piwik_Translate('Referers_ColumnKeyword'), 
     
    9292 
    9393                $view->disableSort(); 
    9494                $view->setLimit(10); 
    95                 $view->disableExcludeLowPopulation();            
     95                $view->disableExcludeLowPopulation(); 
    9696                $view->setSortedColumn('idVisit', 'ASC'); 
    97                  
     97                $view->disableSearchBox(); 
     98                // "Include low population" link won't be displayed under this table 
     99                $view->disableExcludeLowPopulation(); 
     100                // disable the tag cloud,  pie charts, bar chart icons 
     101                $view->disableShowAllViewsIcons(); 
     102                // disable the button "show more datas" 
     103                $view->disableShowAllColumns(); 
     104 
    98105                return $this->renderView($view, $fetch); 
    99106        } 
    100107 
     
    102109        { 
    103110                $view = Piwik_ViewDataTable::factory(''); 
    104111                $view->init( $this->pluginName, 
    105                                                         __FUNCTION__,  
     112                                                        __FUNCTION__, 
    106113                                                'Live.getLastVisitsForVisitor', 
    107                                                 'getPagesFromVisitId');  
     114                                                'getPagesFromVisitId'); 
    108115 
    109116                #$view->disableSearchBox(); 
    110117                #$view->disableExcludeLowPopulation(); 
     
    112119                #$view->setColumnTranslation('label', Piwik_Translate('Referers_ColumnKeyword')); 
    113120 
    114121                return $this->renderView($view, $fetch); 
    115         }        
     122        } 
    116123 
    117         public function getLastVisitsStart($fetch = false)  
     124        public function getLastVisitsStart($fetch = false) 
    118125        { 
    119126                $view = Piwik_View::factory('lastVisits'); 
    120127                $view->visitors = $this->getLastVisits(10); 
    121                  
     128 
    122129                $rendered = $view->render($fetch); 
    123                  
     130 
    124131                if($fetch) 
    125132                { 
    126133                        return $rendered; 
    127134                } 
    128                 echo $rendered;          
     135                echo $rendered; 
    129136        } 
    130                  
     137 
    131138        public function getLastVisits($limit = 10) 
    132139        { 
    133140                $api = new Piwik_API_Request("method=Live.getLastVisits&idSite=$this->idSite&limit=$limit&minIdVisit=$this->minIdVisit&format=php&serialize=0&disable_generic_filters=1"); 
     
    135142 
    136143                return $visitors; 
    137144        } 
    138          
     145 
    139146        public function getUsersInLastXMin($minutes = 30) { 
    140147                $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"); 
    141148                $visitors_halfhour = $api->process(); 
    142                  
     149 
    143150                return count($visitors_halfhour); 
    144151        } 
    145          
     152 
    146153        public function getUsersInLastXDays($days = 1) { 
    147154                $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"); 
    148155                $visitors_today = $api->process(); 
    149                  
     156 
    150157                return count($visitors_today); 
    151158        } 
    152          
     159 
    153160        public function getPageImpressionsInLastXMin($minutes = 30) { 
    154161                $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"); 
    155162                $pis_halfhour = $api->process(); 
    156                  
     163 
    157164                return count($pis_halfhour); 
    158165        } 
    159          
     166 
    160167        public function getPageImpressionsInLastXDays($days = 1) { 
    161168                $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"); 
    162169                $pis_today = $api->process(); 
    163                  
     170 
    164171                return count($pis_today); 
    165172        } 
    166          
     173 
    167174        public function ajaxTotalVisitors($fetch = false) 
    168175        { 
    169                 $view = Piwik_View::factory('totalVisits');              
     176                $view = Piwik_View::factory('totalVisits'); 
    170177                $this->setGeneralVariablesView($view); 
    171178                $view->visitorsCountHalfHour = $this->getUsersInLastXMin(30); 
    172179                $view->visitorsCountToday = $this->getUsersInLastXDays(1); 
    173180                $view->pisHalfhour = $this->getPageImpressionsInLastXMin(30); 
    174181                $view->pisToday = $this->getPageImpressionsInLastXDays(1); 
    175                  
    176                 echo $view->render();            
    177         }        
     182 
     183                echo $view->render(); 
     184        } 
    178185}