Ticket #1120: piwik.patch
| File piwik.patch, 30.3 KB (added by jr-ewing, 2 years ago) |
|---|
-
plugins/Live/API.php
18 18 */ 19 19 require_once PIWIK_INCLUDE_PATH . '/plugins/Live/Visitor.php'; 20 20 21 class Piwik_Live_API 21 class Piwik_Live_API 22 22 { 23 23 static private $instance = null; 24 24 25 25 /* 26 26 * @return Piwik_Live_API 27 27 */ 28 28 static public function getInstance() 29 29 { 30 30 if (self::$instance == null) 31 { 31 { 32 32 $c = __CLASS__; 33 33 self::$instance = new $c(); 34 34 } … … 42 42 { 43 43 return $this->getLastVisitsForVisitor($visitorId, $idSite, 1); 44 44 } 45 45 46 46 /* 47 47 * @return Piwik_DataTable 48 48 */ … … 56 56 { 57 57 Piwik::checkUserHasViewAccess($idSite); 58 58 } 59 59 60 $visitorDetails = self::loadLastVisitorDetailsFromDatabase($visitorId, $idSite, $limit); 60 61 $table = self::getCleanedVisitorsFromDetails($visitorDetails); 62 61 63 return $table; 62 64 } 63 65 … … 78 80 } 79 81 $visitorDetails = self::loadLastVisitorDetailsFromDatabase(null, $idSite, $limit, $minIdVisit); 80 82 $table = self::getCleanedVisitorsFromDetails($visitorDetails); 81 // var_dump($table); 83 82 84 return $table; 83 85 } 84 86 … … 88 90 public function getLastVisitsDetails( $idSite = false, $limit = 1000, $minIdVisit = false ) 89 91 { 90 92 // for checking given vars 91 // echo $idSite.'|'.$limit.'|'.$minIdVisit.'<br>';92 93 if(is_null($idSite)) 93 94 { 94 95 Piwik::checkUserIsSuperUser(); … … 99 100 } 100 101 $visitorDetails = self::loadLastVisitorDetailsFromDatabase(null, $idSite, $limit, $minIdVisit); 101 102 $dataTable = self::getCleanedVisitorsFromDetails($visitorDetails); 102 //echo "hallo";103 //104 103 // $dataTable->queueFilter('ColumnCallbackAddMetadata', array('operatingSystem', 'icon', 'Piwik_Live_Visitor::getVisitLength()')); 105 106 // echo "<pre>"; 107 // var_dump($dataTable[0]); 108 // echo "</pre>"; 109 104 110 105 return $dataTable; 111 106 } 112 107 113 108 114 109 /* 115 110 * @return Piwik_DataTable 116 111 */ 117 112 static private function getCleanedVisitorsFromDetails($visitorDetails) 118 113 { 119 114 $table = new Piwik_DataTable(); 115 120 116 foreach($visitorDetails as $visitorDetail) 121 117 { 122 118 self::cleanVisitorDetails($visitorDetail); 123 119 $visitor = new Piwik_Live_Visitor($visitorDetail); 120 121 // $visitorDetail must contain the match_atribute 124 122 $visitorDetailsArray = $visitor->getAllVisitorDetails(); 123 124 // $visitorDetailsArray['goalIcon'] = "themes/default/images/goal.png"; 125 125 126 $dateTimeVisit = Piwik_Date::factory($visitorDetailsArray['firstActionTimestamp']); 126 127 //TODO TO FIX 127 128 $visitorDetailsArray['serverDatePretty'] = $dateTimeVisit->getLocalized('%shortDay% %day% %shortMonth%'); 128 129 $visitorDetailsArray['serverTimePretty'] = $dateTimeVisit->getLocalized('%time%'); 129 130 // get Detail 130 131 // get Detail - 100 single SQL Statements - Performance Issue 131 132 $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')."` 135 136 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; 137 138 "; 138 139 139 140 $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 141 150 $table->addRowFromArray( array(Piwik_DataTable_Row::COLUMNS => $visitorDetailsArray)); 142 151 } 152 143 153 return $table; 144 154 } 145 155 146 156 /* 147 157 * @return array 148 158 */ 149 159 private function loadLastVisitorDetailsFromDatabase($visitorId = null, $idSite = null, $limit = null, $minIdVisit = false ) 150 160 { 151 161 // for checking given vars 152 // echo $visitorId.'|'.$idSite.'|'.$limit.'|'.$minIdVisit.'<br>'; 162 // echo $visitorId.'|'.$idSite.'|'.$limit.'|'.$minIdVisit.'<br>'; 153 163 $where = $whereBind = array(); 154 164 155 165 if(!is_null($idSite)) 156 166 { 157 $where[] = "idsite = ? ";167 $where[] = Piwik::prefixTable('log_visit') . ".idsite = ? "; 158 168 $whereBind[] = $idSite; 159 169 } 160 170 161 171 if(!is_null($visitorId)) 162 172 { 163 $where[] = "visitor_idcookie = ? ";173 $where[] = Piwik::prefixTable('log_visit') . ".visitor_idcookie = ? "; 164 174 $whereBind[] = $visitorId; 165 175 } 166 176 167 177 if(!is_null($minIdVisit)) 168 178 { 169 $where[] = "idvisit > ? ";179 $where[] = Piwik::prefixTable('log_visit') . ".idvisit > ? "; 170 180 $whereBind[] = $minIdVisit; 171 181 } 172 182 173 183 $sqlWhere = ""; 174 184 if(count($where) > 0) 175 185 { 176 186 $sqlWhere = " WHERE " . join(' AND ', $where); 177 187 } 178 179 $sql = "SELECT *188 189 $sql = "SELECT " . Piwik::prefixTable('log_visit') . ".* , " . Piwik::prefixTable ( 'goal' ) . ".`match_attribute` 180 190 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 182 194 ORDER BY idvisit DESC 183 195 LIMIT $limit"; 184 196 197 185 198 return Piwik_FetchAll($sql, $whereBind); 186 199 } 187 200 … … 190 203 */ 191 204 static private function cleanVisitorDetails( &$visitorDetails ) 192 205 { 193 $toUnset = array('config_md5config'); 206 $toUnset = array('config_md5config'); 194 207 if(!Piwik::isUserIsSuperUser()) 195 208 { 196 209 $toUnset[] = 'visitor_idcookie'; … … 204 217 } 205 218 } 206 219 } 207 208 209 220 221 222 210 223 /* 211 224 * @return Piwik_DataTable 212 225 */ … … 220 233 { 221 234 Piwik::checkUserHasViewAccess($idSite); 222 235 } 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); 225 238 $table = self::getCleanedVisitorsFromDetails($visitorDetails); 239 226 240 return $table; 227 241 } 228 242 … … 231 245 */ 232 246 public function getUsersInLastXDays( $idSite = false, $limit = 10, $minIdVisit = false, $days = 10 ) 233 247 { 234 248 235 249 if(is_null($idSite)) 236 250 { 237 251 Piwik::checkUserIsSuperUser(); … … 240 254 { 241 255 Piwik::checkUserHasViewAccess($idSite); 242 256 } 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 245 260 $table = self::getCleanedVisitorsFromDetails($visitorDetails); 246 261 247 262 return $table; 248 263 } 249 264 250 265 /* 251 266 * @return array 252 */ 267 */ 253 268 public function getPageImpressionsInLastXDays($idSite = false, $limit = 10, $minIdVisit = false, $days = 10){ 254 269 // for checking given vars 255 270 #echo $idSite.'|'.$limit.'|'.$minIdVisit.'|'.$days.'<br>'; 256 271 257 272 if(is_null($idSite)) 258 273 { 259 274 Piwik::checkUserIsSuperUser(); … … 262 277 { 263 278 Piwik::checkUserHasViewAccess($idSite); 264 279 } 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 267 283 $i = -1; 268 284 foreach ($pageDetails as $detail) { 269 285 $i++; … … 272 288 } 273 289 } 274 290 275 return $pageDetails; 291 return $pageDetails; 276 292 } 277 293 278 294 /* 279 295 * @return array 280 */ 296 */ 281 297 public function getPageImpressionsInLastXMin($idSite = false, $limit = 10, $minIdVisit = false, $minutes = 30){ 282 298 283 299 if(is_null($idSite)) … … 288 304 { 289 305 Piwik::checkUserHasViewAccess($idSite); 290 306 } 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 293 310 $i = -1; 294 311 foreach ($pageDetails as $detail) { 295 312 $i++; … … 297 314 $pageDetails[$i]['name'] = substr($pageDetails[$i]['name'] , 0, 30 - 3).'...'; 298 315 } 299 316 } 300 return $pageDetails; 317 return $pageDetails; 301 318 } 302 303 319 304 305 320 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 309 333 */ 310 private function loadLastVisitor DetailsInLastXMinFromDatabase($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 ) 311 335 { 312 336 $where = $whereBind = array(); 313 337 314 338 if(!is_null($idSite)) 315 339 { 316 $where[] = " idsite= ? ";340 $where[] = " " . Piwik::prefixTable('log_visit') . ".`idsite` = ? "; 317 341 $whereBind[] = $idSite; 318 342 } 319 343 320 344 if(!is_null($visitorId)) 321 345 { 322 $where[] = " visitor_idcookie= ? ";346 $where[] = " `visitor_idcookie` = ? "; 323 347 $whereBind[] = $visitorId; 324 348 } 325 349 326 350 if(!is_null($minIdVisit)) 327 351 { 328 $where[] = " idvisit> ? ";352 $where[] = " " . Piwik::prefixTable('log_visit') . ".`idvisit` > ? "; 329 353 $whereBind[] = $minIdVisit; 330 354 } 331 355 332 356 if($minutes != 0) 333 357 { 334 358 $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)."'"; 365 360 } 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 379 362 if($days != 0) 380 363 { 381 364 $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)."'"; 384 366 } 385 367 386 368 $sqlWhere = ""; 387 369 if(count($where) > 0) 388 370 { 389 371 $sqlWhere = " WHERE " . join(' AND ', $where); 390 372 } 391 392 $sql = "SELECT * 373 374 // Details 375 if($type == 1) 376 { 377 $sql = "SELECT " . Piwik::prefixTable('log_visit') . ".* 393 378 FROM " . Piwik::prefixTable('log_visit') . " 394 $sqlWhere 379 $sqlWhere 395 380 ORDER BY idvisit DESC 396 381 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 } 429 400 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." 440 402 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` 442 404 INNER JOIN " . Piwik::prefixTable('log_visit') . " ON " . Piwik::prefixTable('log_visit') . ".`idvisit` = " . Piwik::prefixTable('log_link_visit_action') . ".`idvisit` 443 405 $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 } 470 412 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 486 414 return Piwik_FetchAll($sql, $whereBind); 487 415 } 488 416 489 417 } -
plugins/Live/Visitor.php
75 75 'screenIcon' => $this->getScreenTypeIcon(), 76 76 'plugins' => $this->getPlugins(), 77 77 'lastActionDateTime' => $this->getDateTimeLastAction(), 78 'isVisitorGoalConverted' => $this->isVisitorGoalConverted(), 79 'goalIcon' => $this->getGoalIcon(), 80 'goalType' => $this->getGoalType(), 78 81 ); 79 82 } 80 83 … … 121 124 { 122 125 return $this->details['visitor_returning']; 123 126 } 124 127 125 128 function getTimestampFirstAction() 126 129 { 127 130 return strtotime($this->details['visit_first_action_time']); … … 291 294 { 292 295 return date('Y-m-d H:i:s', strtotime($this->details['visit_last_action_time'])); 293 296 } 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
2 2 <div class="visit{if $visitor.idVisit % 2} alt{/if}"> 3 3 <!--<div class="idvisit">{$visitor.idVisit}</div>--> 4 4 <div style="display:none" class="idvisit">{$visitor.idVisit}</div> 5 5 6 6 <div class="datetime"> 7 7 {$visitor.serverDatePretty} - {$visitor.serverTimePretty} 8 8 <img src="{$visitor.countryFlag}" title="{$visitor.country}, Provider {$visitor.provider}"> 9 9 <img src="{$visitor.browserIcon}" title="{$visitor.browser} with plugins {$visitor.plugins} enabled"> 10 <img src="{$visitor.operatingSystemIcon}" title="{$visitor.operatingSystem}, {$visitor.resolution}"> 10 <img src="{$visitor.operatingSystemIcon}" title="{$visitor.operatingSystem}, {$visitor.resolution}"> 11 {if $visitor.isVisitorGoalConverted}<img src="{$visitor.goalIcon}" title="{$visitor.goalType}">{/if} 12 {if $visitor.isVisitorReturning} <img src="plugins/Live/templates/images/returningVisitor.gif" title="Returning Visitor">{/if} 13 <label id="" title="IP: {$visitor.ip} - Duration: {$visitor.visitLengthPretty}">more...</label> 11 14 </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>--> 16 16 <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> 18 18 {if !empty($visitor.keywords)}"{$visitor.keywords}"{/if} 19 19 {/if} 20 20 {if $visitor.refererType == 'directEntry'}Direct entry{/if} 21 21 </div> 22 <div id="{$visitor.idVisit}_actions" class=" actions">22 <div id="{$visitor.idVisit}_actions" class="settings"> 23 23 <span class="pagesTitle">Pages:</span> 24 24 {php} $col = 0; {/php} 25 25 {foreach from=$visitor.actionDetails item=action} 26 {php} 27 $col++; 26 {php} 27 $col++; 28 28 if ($col>=9) 29 29 { 30 30 $col=0; 31 31 } 32 {/php} 32 {/php} 33 33 <a href="{$action.pageUrl}" target="_blank"><img align="middle" src="plugins/Live/templates/images/file{php} echo $col; {/php}.png" title="{$action.pageUrl}"></a> 34 34 {/foreach} 35 35 </div> -
plugins/Live/templates/index.tpl
3 3 4 4 <script type="text/javascript" charset="utf-8"> 5 5 6 7 $(document).ready(function() { 6 7 $(document).ready(function() { 8 8 if($('#_spyTmp').size() == 0) { 9 9 $('#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, 14 14 isDupes : check_for_dupe, 15 15 timeout: 20000, 16 customParameterName: 'minIdVisit', 16 customParameterName: 'minIdVisit', 17 17 customParameterValueCallback: lastIdVisit, 18 18 fadeInSpeed: 1400 19 }); 19 }); 20 20 } 21 21 }); 22 22 23 23 // first I'm ensuring that 'last' has been initialised (with last.constructor == Object), 24 24 // then prev.html() == last.html() will return true if the HTML is the same, or false, 25 25 // if I have a different entry. 26 26 function check_for_dupe(prev, last) 27 27 { 28 28 29 29 if (last.constructor == Object) { 30 30 return (prev.html() == last.html()); 31 } 31 } 32 32 else { 33 33 return 0; 34 35 } 34 35 } 36 36 } 37 37 38 38 function lastIdVisit() … … 46 46 var pauseDisabledImage = "plugins/Live/templates/images/pause_disabled.gif"; 47 47 var playImage = "plugins/Live/templates/images/play.gif"; 48 48 var playDisabledImage = "plugins/Live/templates/images/play_disabled.gif"; 49 49 50 50 function onClickPause() 51 51 { 52 52 $('#pauseImage').attr('src', pauseImage); … … 59 59 $('#pauseImage').attr('src', pauseDisabledImage); 60 60 return playSpy(); 61 61 } 62 62 63 63 // updates the numbers of total visits in startbox 64 64 function updateTotalVisits() 65 65 { 66 66 $("#visitsTotal").load("index.php?module=Live&idSite={/literal}{$idSite}{literal}&action=ajaxTotalVisitors"); 67 67 } 68 68 69 69 // updates the visit table, to refresh the already presented visotors pages 70 70 function updateVisitBox() 71 71 { 72 72 $("#visitsLive").load("index.php?module=Live&idSite={/literal}{$idSite}{literal}&action=getLastVisitsStart"); 73 73 } 74 74 75 /* TOOLTIP */ 76 $('#visitsLive label').tooltip({ 77 track: true, 78 delay: 0, 79 showURL: false, 80 showBody: " - ", 81 fade: 250 82 }); 83 75 84 </script> 76 85 77 86 <style> … … 82 91 #visitsLive .datetime, #visitsLive .country, #visitsLive .referer, #visitsLive .settings, #visitsLive .returning , #visitsLive .countActions{ 83 92 border-bottom:1px solid #C1DAD7; 84 93 border-right:1px solid #C1DAD7; 85 padding:5px 5px 5px 12px; 94 padding:5px 5px 5px 12px; 86 95 } 87 96 88 97 #visitsLive .datetime { … … 169 178 </div> 170 179 171 180 <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> 173 182 <a href="javascript:void(0);" onclick="onClickPlay();"><img id="playImage" border="0" src="plugins/Live/templates/images/play.gif"></a> 174 183 </div> -
plugins/Live/Controller.php
1 1 <?php 2 2 /** 3 3 * Piwik - Open source web analytics 4 * 4 * 5 5 * @link http://piwik.org 6 6 * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later 7 7 * @version $Id$ 8 * 8 * 9 9 * @category Piwik_Plugins 10 10 * @package Piwik_Live 11 11 */ … … 16 16 */ 17 17 class Piwik_Live_Controller extends Piwik_Controller 18 18 { 19 19 20 20 function __construct() 21 21 { 22 22 parent::__construct(); 23 23 $this->idSite = Piwik_Common::getRequestVar('idSite'); 24 24 $this->minIdVisit = Piwik_Common::getRequestVar('minIdVisit', 0, 'int'); 25 25 } 26 26 27 27 function index() 28 28 { 29 29 $this->widget(true); 30 } 31 30 } 31 32 32 public function widget($fetch = false) 33 33 { 34 $view = Piwik_View::factory('index'); 34 $view = Piwik_View::factory('index'); 35 35 $this->setGeneralVariablesView($view); 36 36 $view->visitorsCountHalfHour = $this->getUsersInLastXMin(30); 37 37 $view->visitorsCountToday = $this->getUsersInLastXDays(1); … … 39 39 $view->pisToday = $this->getPageImpressionsInLastXDays(1); 40 40 $view->visitors = $this->getLastVisitsStart($fetch = true); 41 41 42 echo $view->render(); 42 echo $view->render(); 43 43 } 44 44 45 45 public function getLastVisitsDetails($fetch = false) 46 46 { 47 47 $view = Piwik_ViewDataTable::factory(''); 48 48 $view->init( $this->pluginName, 49 __FUNCTION__, 49 __FUNCTION__, 50 50 'Live.getLastVisitsDetails', 51 'getPagesFromVisitId'); 51 'getPagesFromVisitId'); 52 52 // 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', 55 55 //'keywords', 'refererUrl', 'searchEngineUrl', 'searchEngineIcon', 'operatingSystem', 'operatingSystemShortName', 'operatingSystemIcon', 56 56 //'browserFamily', 'browserFamilyDescription', 'browser', 'browserIcon', 'screen', 'resolution', 'screenIcon', 'plugins', 'lastActionDateTime', 57 57 //'serverDatePretty', 'serverTimePretty', 'actionDetails' 58 58 59 59 $view->setColumnsToDisplay(array( 60 60 // 'label', 61 61 'idVisit', … … 78 78 'idVisit' => Piwik_Translate(''), 79 79 'serverDatePretty' => Piwik_Translate('Live_Date'), 80 80 'serverTimePretty' => Piwik_Translate('Live_Time'), 81 'ip' => 'IP', 81 'ip' => 'IP', 82 82 'countActions' => Piwik_Translate('VisitorInterest_ColumnPagesPerVisit'), 83 83 'visitLengthPretty' => Piwik_Translate('VisitorInterest_ColumnVisitDuration'), 84 84 'keywords' => Piwik_Translate('Referers_ColumnKeyword'), … … 92 92 93 93 $view->disableSort(); 94 94 $view->setLimit(10); 95 $view->disableExcludeLowPopulation(); 95 $view->disableExcludeLowPopulation(); 96 96 $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 98 105 return $this->renderView($view, $fetch); 99 106 } 100 107 … … 102 109 { 103 110 $view = Piwik_ViewDataTable::factory(''); 104 111 $view->init( $this->pluginName, 105 __FUNCTION__, 112 __FUNCTION__, 106 113 'Live.getLastVisitsForVisitor', 107 'getPagesFromVisitId'); 114 'getPagesFromVisitId'); 108 115 109 116 #$view->disableSearchBox(); 110 117 #$view->disableExcludeLowPopulation(); … … 112 119 #$view->setColumnTranslation('label', Piwik_Translate('Referers_ColumnKeyword')); 113 120 114 121 return $this->renderView($view, $fetch); 115 } 122 } 116 123 117 public function getLastVisitsStart($fetch = false) 124 public function getLastVisitsStart($fetch = false) 118 125 { 119 126 $view = Piwik_View::factory('lastVisits'); 120 127 $view->visitors = $this->getLastVisits(10); 121 128 122 129 $rendered = $view->render($fetch); 123 130 124 131 if($fetch) 125 132 { 126 133 return $rendered; 127 134 } 128 echo $rendered; 135 echo $rendered; 129 136 } 130 137 131 138 public function getLastVisits($limit = 10) 132 139 { 133 140 $api = new Piwik_API_Request("method=Live.getLastVisits&idSite=$this->idSite&limit=$limit&minIdVisit=$this->minIdVisit&format=php&serialize=0&disable_generic_filters=1"); … … 135 142 136 143 return $visitors; 137 144 } 138 145 139 146 public function getUsersInLastXMin($minutes = 30) { 140 147 $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"); 141 148 $visitors_halfhour = $api->process(); 142 149 143 150 return count($visitors_halfhour); 144 151 } 145 152 146 153 public function getUsersInLastXDays($days = 1) { 147 154 $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"); 148 155 $visitors_today = $api->process(); 149 156 150 157 return count($visitors_today); 151 158 } 152 159 153 160 public function getPageImpressionsInLastXMin($minutes = 30) { 154 161 $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"); 155 162 $pis_halfhour = $api->process(); 156 163 157 164 return count($pis_halfhour); 158 165 } 159 166 160 167 public function getPageImpressionsInLastXDays($days = 1) { 161 168 $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"); 162 169 $pis_today = $api->process(); 163 170 164 171 return count($pis_today); 165 172 } 166 173 167 174 public function ajaxTotalVisitors($fetch = false) 168 175 { 169 $view = Piwik_View::factory('totalVisits'); 176 $view = Piwik_View::factory('totalVisits'); 170 177 $this->setGeneralVariablesView($view); 171 178 $view->visitorsCountHalfHour = $this->getUsersInLastXMin(30); 172 179 $view->visitorsCountToday = $this->getUsersInLastXDays(1); 173 180 $view->pisHalfhour = $this->getPageImpressionsInLastXMin(30); 174 181 $view->pisToday = $this->getPageImpressionsInLastXDays(1); 175 176 echo $view->render(); 177 } 182 183 echo $view->render(); 184 } 178 185 }
