From: vincent@cubedesigners.com Date: Tue, 7 Apr 2020 15:23:54 +0000 (+0000) Subject: fix #3572 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=f168714a069134117f5e2cc1c2e9f7f7310ef491;p=cubeextranet.git fix #3572 @0.5 --- diff --git a/inc/ws/Controlleur/class.ws.stats.php b/inc/ws/Controlleur/class.ws.stats.php index cdab98dfd..2f4c1d013 100644 --- a/inc/ws/Controlleur/class.ws.stats.php +++ b/inc/ws/Controlleur/class.ws.stats.php @@ -3,1141 +3,1144 @@ class wsStats { - public static $datestocorrect = array(array(22, 11, 2009), array(23, 11, 2009), array(8, 12, 2009), array(9, 12, 2009)); - - /** - * @var PHPExcel - */ - public static $xls; - - public static function exportXLS($bid, $annee = null, $mois = null) - { - $xname = self::_getXLSFile($bid, $annee, $mois); - $fname = 'stats_' . $bid; - if (!is_null($annee)) { - $fname .= '_' . $annee; - if (!is_null($mois)) { - $fname .= '_' . $mois; - } - } - $fname .= '.xlsx'; - - files::$mimeType['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; - - cubeHTTP::downloadFile($xname, $fname); - } - - protected static function _getXLSFile($bid, $annee = null, $mois = null) - { - self::forceComputation($bid); - $e = explode('_', $bid); - $bid = $e[0]; - $xname = '/home/stats/www/xls/' . $bid; - if (!is_null($annee)) { - $xname .= '/' . $annee; - if (!is_null($mois)) { - $xname .= '/' . $mois; - } - } - - $xname .= '.xlsx'; - - $dir = dirname($xname); - if (!file_exists($dir)) { - mkdir($dir, 0777, true); - } - - return $xname; - } - - public static function display($bid, $annee = null, $mois = null) - { - global $core; - - self::forceComputation($bid); - - cubePHP::set_memory('12G'); - - self::$xls = new PHPExcel(); - self::$xls->removeSheetByIndex(0); - - - $global = self::load_stats($bid); - - - $exporturl = SITE_PATH . 'statsxls/' . $bid; - if (!is_null($annee)) { - $exporturl .= '/' . $annee; - if (!is_null($mois)) { - $exporturl .= '/' . $mois; - } - } - - $actions = array(); - $actions[] = '' . $core->typo->Ajouter('Exporter au format Excel') . ''; - - $years = $global->year; - $annees = array('' . __('Toutes') . '' => SITE_PATH . 'stats/' . $bid); - - $listeShortcuts = array(); - - - $listeMois = null; - foreach ($years as $y) { - $selectedYear = __('Toutes'); - if (!is_null($annee) && $annee == (string)$y['year']) { - $months = $y->month; - $moiss = array('' . __('Tous') . '' => SITE_PATH . 'stats/' . $bid . '/' . (string)$y['year']); - $selectedMonth = __('Tous'); - foreach ($months as $m) { - if ((string)$m['month'] == $mois) { - $selectedMonth = cubeDate::getMonth((string)$m['month']); - } - $moiss[cubeDate::getMonth((string)$m['month'])] = SITE_PATH . 'stats/' . $bid . '/' . (string)$y['year'] . '/' . (string)$m['month']; - } - $listeMois = new commonShortcuts(__('Mois'), $moiss, $selectedMonth); - } - if ((string)$y['year'] == $annee) { - $selectedYear = $annee; - } - $annees[(string)$y['year']] = SITE_PATH . 'stats/' . $bid . '/' . (string)$y['year']; - } - - $listeAnnees = new commonShortcuts(__('Année'), $annees, $selectedYear); - $listeShortcuts[] = $listeAnnees; - if (!is_null($listeMois)) { - $listeShortcuts[] = $listeMois; - } - - $res = commonPage::barre($listeShortcuts, 'filtreStats', 'stats', $actions); - $res .= commonPage::tMain(); - if (is_null($annee) && is_null($mois)) { - $res .= self::vue_globale($bid); - } elseif (is_null($mois)) { - $res .= self::vue_annuelle($bid, $annee); - } else { - $res .= self::vue_mensuelle($bid, $annee, $mois); - } - $res .= commonPage::bMain(); - - - try { - self::$xls->setActiveSheetIndex(0); - $writer = new PHPExcel_Writer_Excel2007(); - $writer->setPHPExcel(self::$xls); - $xlsfile = self::_getXLSFile($bid, $annee, $mois); - cubePHP::set_memory('12G'); - $writer->save($xlsfile); - } catch (Exception $e) { - die($e->getMessage()); - } - - return $res; - } - - public static function getExtra($extra) - { - $xml = simplexml_load_string('' . $extra . ''); - if ((string)$xml->extraName != '') { - return (string)$xml->extraName; - } - return null; - } - - public static function load_stats($bid, $annee = null, $mois = null) - { - - $e = explode('_', $bid, 2); - $bid = $e[0]; - - $root = WS_STATS . 'xml/' . $bid; - if (is_null($annee)) { - $xml = $root; - $sort = 'globalSort'; - } else if (is_null($mois)) { - $xml = $root . '/' . $annee; - $sort = 'yearSort'; - } else { - $xml = $root . '/' . $annee . '/' . $mois; - $sort = 'monthSort'; - } - $xml = rtrim($xml, '/'); - $xml .= '.xml'; - if ($x = @simplexml_load_file($xml)) { - if (!is_null($mois)) { - - } - $x = call_user_func(array('wsStats', $sort), $x); - self::correctValues($x, $annee, $mois); - return $x; - } - return null; - } - - public static function correctValues($x, $y, $m) - { - return; - foreach (self::$datestocorrect as $date) { - if ($date[2] != $y || $date[1] != $m) { - continue; - } - $days = $x->xpath("//day[@day=" . $date[0] . "]"); - foreach ($days as $day) { - break; - } - $visitors = (string)$day['places'] * 1.2; - $visits = $visitors * 1.1; - cubeXML::removeAttribute($day, 'visitors'); - cubeXML::removeAttribute($day, 'visits'); - $day->addAttribute('visitors', $visitors); - $day->addAttribute('visits', $visits); - } - } - - public static function correctPlaces($x) - { - - } - - public static function globalSort($xml, $root = 'stats') - { - $res = simplexml_load_string('<' . $root . ' />'); - foreach ($xml->attributes() as $k => $v) { - $res->addAttribute($k, $v); - } - $years = array(); - foreach ($xml->year as $year) { - $years[(string)$year['year']] = self::yearSort($year, 'year'); - } - ksort($years); - foreach ($years as $y) { - cubeXML::append($res, $y); - } - return $res; - } - - public static function yearSort($xml, $root = 'stats') - { - $res = simplexml_load_string('<' . $root . ' />'); - foreach ($xml->attributes() as $k => $v) { - $res->addAttribute($k, $v); - } - $months = array(); - foreach ($xml->month as $month) { - $months[(string)$month['month']] = $month; - } - - ksort($months); - foreach ($months as $month) { - cubeXML::append($res, $month); - } - - return $res; - } - - public static function monthSort($xml, $root = 'stats') - { - $res = simplexml_load_string('<' . $root . ' />'); - foreach ($xml->attributes() as $k => $v) { - $res->addAttribute($k, $v); - } - self::daysSort($xml, $res); - self::pagesSort($xml, $res); - self::linksSort($xml, $res); - self::searchesSort($xml, $res); - self::countriesSort($xml, $res); - return $res; - } - - public static function daysSort($xml, $res) - { - $x = $res->addChild('days'); - $days = array(); - foreach ($xml->days->day as $day) { - $days[(string)$day['day']] = $day; - } - ksort($days); - foreach ($days as $day) { - $places = (string)$day['places']; - if ($places == 1) { - $visitors = (string)$day['visitors']; - if ($visitors > 10) { - cubeXML::removeAttribute($day, 'places'); - $day->addAttribute('places', round($visitors * 0.99)); - } - } - cubeXML::append($x, $day); - } - } - - public static function pagesSort($xml, $res) - { - $xpages = $res->addChild('pages'); - $pages = array(); - $trans = array(); - foreach ($xml->pages->page as $page) { - $pages[(string)$page['page']] = (string)$page['score']; - $trans[(string)$page['page']] = $page; - } - arsort($pages); - foreach ($pages as $num => $score) { - cubeXML::append($xpages, $trans[$num]); - } - } - - public static function linksSort($xml, $res) - { - $x = $res->addChild('links'); - $links = array(); - $trans = array(); - foreach ($xml->links->link as $link) { - $links[(string)$link['url']] = (string)$link['click']; - $trans[(string)$link['url']] = $link; - } - arsort($links); - $links = array_slice($links, 0, 100, true); - foreach ($links as $url => $click) { - cubeXML::append($x, $trans[$url]); - } - } - - public static function searchesSort($xml, $res) - { - $x = $res->addChild('searches'); - $searches = array(); - $trans = array(); - foreach ($xml->searches->search as $search) { - $searches[(string)$search['query']] = (string)$search['count']; - $trans[(string)$search['query']] = $search; - } - arsort($searches); - $searches = array_slice($searches, 0, 100, true); - foreach ($searches as $q => $count) { - cubeXML::append($x, $trans[$q]); - } - } - - public static function countriesSort($xml, $res) - { - $x = $res->addChild('countries'); - $countries = array(); - $trans = array(); - foreach ($xml->countries->country as $country) { - $countries[(string)$country['code']] = (string)$country['visitors']; - $trans[(string)$country['code']] = $country; - } - arsort($countries); - foreach ($countries as $code => $visitors) { - cubeXML::append($x, $trans[$code]); - } - } - - public static function getActives($stats, $book, &$aextra, &$adown, &$adownp, &$aprint, &$afriend) - { - $extra = self::getExtra($book->extras); - $aextra = ($extra != null && $stats['extras'] > 0); - $adown = ($book->parametres->pdf == 1 && $stats['downloads'] > 0); - $adownp = ($book->parametres->pdf == 1 && $book->parametres->pdfComplex == 1 && $stats['partDownloads'] > 0); - $aprint = ($book->parametres->print == 1); - $afriend = ($book->parametres->friend == 1); - } - - public static function table($title, $colsTitles, $lines, $class, $firstColMax = true, $firstLineBold = false, $noOdd = false) - { - global $core; - if (is_string($class)) { - $class = array($class); - } - $res = ''; - // Titre - $res .= ''; - // Head - if (implode('', $colsTitles) != '') { - $res .= ''; - foreach ($colsTitles as $i => $title) { - $max = ($firstColMax && $i == 0) ? '' : ' class="stats_col"'; - $res .= '' . $title . ''; - } - $res . ''; - } - // Body - foreach ($lines as $i => $line) { - $odd = cubeMath::isOdd($i) ? ' class="odd"' : ''; - if ($firstLineBold && $i == 0) { - $odd = ' class="odd"'; - } elseif ($firstLineBold) { - $odd = ''; - } - if ($noOdd) { - $odd = ''; - } - $res .= ''; - foreach ($line as $j => $cell) { - $max = ($firstColMax && $j == 0) ? '' : ' class="stats_col"'; - if ($firstLineBold && $i == 0) { - $cell = '' . $cell . ''; - } - $res .= '' . $cell . ''; - } - $res .= ''; - } - - $res .= '

' . $title . '

'; - - return $res; - } - - /** - * - * @param string $name - * @return PHPExcel_Worksheet - */ - protected static function _createSheet($name) - { - $s = self::$xls->createSheet(); - $s->setTitle($name); - return $s; - } - - public static function globalDatas($titre, $date_creation, $book, $stats, $afriend, $aprint, $adown, $adownp, $aextra) - { - global $xls; - - $colsTitles = array('', ''); - $lines = array(); - $class = array('liste', 'max'); - - $lines[] = array($date_creation, date(__('d-m-Y'), $book->date)); - //$lines[] = array(__('Nombre de lieux de visite'), $stats['places']); - $lines[] = array(__('Nombre de visiteurs uniques'), $stats['visitors']); - $lines[] = array(__('Nombre de visites'), $stats['visits']); - $lines[] = array(__('Nombre de pages vues'), $stats['pages']); - if ($afriend) { - $lines[] = array(__('Nombre de liens envoyés'), $stats['friends']); - } - $lines[] = array(__('Nombre de liens cliqués'), $stats['links']); - if ($aprint) { - $lines[] = array(__("Nombre d'impressions"), $stats['prints']); - } - if ($adown) { - $lines[] = array(__('Nombre de téléchargements'), $stats['downloads']); - } - if ($adownp) { - $lines[] = array(__('Nombre de téléchargements partiels'), $stats['partDownloads']); - } - if ($aextra) { - $lines[] = array(__('Accès à la rubrique') . ' ' . $extra, $stats['extras']); - } - - self::setSheetFromDatas(__('Résumé'), null, $lines); - - return self::table($titre, $colsTitles, $lines, $class); - } - - public static function indisponible() - { - $res = commonPage::bh('stats_global'); - $res .= '

' . __('Les statistiques concernant cette période ne sont actuellement pas disponibles') . '

'; - $res .= commonPage::bf(); - return $res; - } - - public static function getBook($bid) - { - global $core; - $daoBook = new wsDAOBook($core->con); - return $daoBook->selectById($bid); - } - - public static function vue_globale($bid, $annee = null) - { - global $core; - $book = self::getBook($bid); - $extra = self::getExtra($book->extras); - if (is_null($annee)) { - $stats = self::load_stats($bid); - } else { - $stats = self::load_stats($bid, $annee); - } - - if (is_null($stats)) { - return self::indisponible(); - } - - self::getActives($stats, $book, $aextra, $adown, $adownp, $aprint, $afriend); - $res = commonPage::bh('stats_global'); - $titre = __('Statistiques de la publication « %s »'); - $date_creation = __('Date de création de la publication'); - $res .= self::globalDatas(sprintf($titre, $book->nom), $date_creation, $book, $stats, $afriend, $aprint, $adown, $adownp, $aextra); - $res .= commonPage::bf(); - $res .= commonPage::bh(); - $res .= ''; - $res .= ''; - $res .= ''; - $res .= '

' . __('Détail par mois') . '

'; - $res .= '
'; - if (is_null($annee)) { - $res .= self::graph_global($bid, $stats); - } else { - $res .= self::graph_annuel($bid, $annee, $stats); - } - $res .= '
'; - $res .= '
'; - $res .= self::detailPeriode($book, $stats, $bid, $annee); - $res .= commonPage::bf(); - return $res; - } - - /** - * wsStats::vue_annuelle() - * - * @param mixed $bid - * @param mixed $annee - * @return - */ - public static function vue_annuelle($bid, $annee) - { - return self::vue_globale($bid, $annee); - } - - public static function vue_mensuelle($bid, $annee, $mois) - { - $datestocorrect = array(mktime(0, 0, 0, 11, 23, 2009), mktime(0, 0, 0, 12, 8, 2009), mktime(0, 0, 0, 12, 9, 2009)); - global $core; - $book = self::getBook($bid); - $extra = self::getExtra($book->extras); - $stats = self::load_stats($bid, $annee, $mois); - if (is_null($stats)) { - return self::indisponible(); - } - - self::getActives($stats, $book, $aextra, $adown, $adownp, $aprint, $afriend); - $time_page = mktime(0, 0, 0, $mois, 15, $annee); - $res = commonPage::bh('stats_global'); - $titre = __('Statistiques de la publication « %s »'); - $date_creation = __('Date de création de la publication'); - $res .= self::globalDatas(sprintf($titre, $book->nom), $date_creation, $book, $stats, $afriend, $aprint, $adown, $adownp, $aextra); - $res .= commonPage::bf(); - // . - $res .= commonPage::bh('stats_detail_mois'); - $res .= '
'; - $res .= self::graph_mensuel($bid, $annee, $mois, $stats); - $res .= '
'; - $res .= self::detailJour($book, $annee, $mois, $stats); - $res .= commonPage::bf(); - - - // . - $res .= commonPage::bh('stats_detail_pages'); - $res .= self::detailPages($book, $annee, $mois, $stats); - $res .= commonPage::bf(); - // . - if ($book->parametres->search == 0) { - $idl = 'stats_links_2'; - $idc = 'stats_country_2'; - } else { - $idl = 'stats_links'; - $idc = 'stats_country'; - } - - $res .= '
'; - $res .= commonPage::bh($idl); - $res .= self::detailLiens($book, $stats); - $res .= commonPage::bf(); - if ($book->parametres->search == 1) { - $res .= commonPage::bh('stats_search'); - $res .= self::detailSearch($book, $stats); - $res .= commonPage::bf(); - } - // Origine - $res .= commonPage::bh($idc); - $res .= self::detailOrigine($book, $stats); - $res .= commonPage::bf(); - $res .= '
'; - return $res; - } - - public static function detailPeriode($book, $stats, $bid, $annee) - { - self::getActives($stats, $book, $aextra, $adown, $adownp, $aprint, $afriend); - $title = ''; - - $colsTitles = array(__('Période'), /*__('Lieux de visite'),*/ - __('Visiteurs uniques'), __('Visites'), __('Pages vues')); - if ($afriend) { - $colsTitles[] = __('Liens envoyés'); - } - $colsTitles[] = __('Liens cliqués'); - if ($aprint) { - $colsTitles[] = __('Impressions'); - } - if ($adown) { - $colsTitles[] = __('Téléchargements'); - } - if ($adownp) { - $colsTitles[] = __('Téléchargements partiels'); - } - if ($aextra) { - $colsTitles[] = $extra; - } - - if (is_null($annee)) { - $years = $stats->year; - } else { - $years = array($stats); - } - - $lines = array(); - $noOdd = false; - foreach ($years as $year) { - if ($year['annee'] != null) { - $lines[] = self::linePeriod($year, $bid, $afriend, $aprint, $adown, $adownp, $aextra); - } else { - $noOdd = true; - } - - foreach ($year->month as $month) { - $lines[] = self::linePeriod($month, $bid, $afriend, $aprint, $adown, $adownp, $aextra); - } - } - - self::setSheetFromDatas(__('Détail'), $colsTitles, $lines); - - return self::table($title, $colsTitles, $lines, array('max', 'liste'), true, false, $noOdd); - } - - protected static function setSheetFromDatas($title, $columns, $lines) - { - $s = self::_createSheet($title); - $offset = 1; - if (!is_null($columns)) { - $offset = 2; - foreach ($columns as $k => $c) { - - $s->setCellValueByColumnAndRow($k, 1, $c); - $s->getStyleByColumnAndRow($k, 1)->getFont()->setBold(true); - - if ($k == 0) { - $s->getStyleByColumnAndRow($k, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); - } else { - $s->getStyleByColumnAndRow($k, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); - } - } - } - foreach ($lines as $k => $l) { - foreach ($l as $c => $v) { - $s->getColumnDimensionByColumn($c)->setAutoSize(true); - $s->setCellValueByColumnAndRow($c, $k + $offset, strip_tags($v)); - - if ($c == 0) { - $s->getStyleByColumnAndRow($c, $k + $offset)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); - } else { - $s->getStyleByColumnAndRow($c, $k + $offset)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); - } - } - } - } - - public static function linePeriod($stats, $bid, $afriend, $aprint, $adown, $adownp, $aextra) - { - $line = array(); - $url = SITE_PATH . 'stats/' . $bid; - if (isset($stats['year'])) { - $url .= '/' . $stats['year']; - if (isset($stats['month'])) { - $url .= '/' . $stats['month']; - $date = strftime('%B %Y', mktime(0, 0, 0, (string)$stats['month'], 15, (string)$stats['year'])); - } else { - $date = (string)$stats['year']; - } - } - - $line[] = '' . $date . ''; - //$line[] = $stats['places']; - $line[] = $stats['visitors']; - $line[] = $stats['visits']; - $line[] = $stats['pages']; - if ($afriend) { - $line[] = $stats['friends']; - } - $line[] = $stats['links']; - if ($aprint) { - $line[] = $stats['prints']; - } - if ($adown) { - $line[] = $stats['downloads']; - } - if ($adownp) { - $line[] = $stats['partDownloads']; - } - if ($aextra) { - $line[] = $stats['extras']; - } - - return $line; - } - - public static function detailJour($book, $annee, $mois, $stats) - { - $colsTitles = array(__('Jour'), /*__('Lieux de visite'),*/ - __('Visiteurs uniques'), __('Visites'), __('Pages vues'), __('Liens cliqués')); - $lines = array(); - $xlines = array(); - - foreach ($stats->days->day as $day) { - $lines[] = array(strftime('%A %d', mktime(0, 0, 0, $mois, (string)$day['day'], $annee)), - // $day['places'], - $day['visitors'], - $day['visits'], - $day['views'], - $day['links']); - $xlines[] = array(strftime('%d', mktime(0, 0, 0, $mois, (string)$day['day'], $annee)), - //$day['places'], - $day['visitors'], - $day['visits'], - $day['views'], - $day['links']); - } - $time_page = mktime(0, 0, 0, $mois, 15, $annee); - - self::setSheetFromDatas(__('Jours'), $colsTitles, $xlines); - - return self::table(__('Détail par jour') . ' - ' . strftime('%B %Y', $time_page), $colsTitles, $lines, array('liste', 'max'), true); - } - - public static function detailPages($book, $annee, $mois, $stats) - { - $colsTitles = array(__('Pages')); - if ($book->parametres->stats_score) { - $colsTitles[] = __('Score'); - } - $colsTitles[] = __('Vues'); - $colsTitles[] = __('Zooms'); - if ($book->parametres->bookmark) { - $colsTitles[] = __('Marques-pages'); - } - if ($book->parametres->print) { - $colsTitles[] = __('Impressions'); - } - - $lines = array(); - foreach ($stats->pages->page as $page) { - $p = (string)$page['page']; - if ($p > $book->pages || cubeMath::isOdd($p)) { - continue; - } - if ($p == 0) { - $pagen = '1'; - } elseif ($p == $book->parametres->pages) { - $pagen = $p; - } else { - $pagen = $p; - $pagen .= '-'; - $pagen .= ($p + 1); - } - - $line = array($pagen); - - if ($book->parametres->stats_score == 1) { - $line[] = $page['score']; - } - $line[] = $page['views']; - $line[] = $page['zooms']; - - if ($book->parametres->bookmark == 1) { - $line[] = $page['bookmarks']; - } - if ($book->parametres->print == 1) { - $line[] = $page['prints']; - } - $lines[] = $line; - } - $time_page = mktime(0, 0, 0, $mois, 15, $annee); - - self::setSheetFromDatas(__('Pages'), $colsTitles, $lines); - - return self::table(__('Détail par page') . ' - ' . strftime('%B %Y', $time_page), $colsTitles, $lines, array('liste', 'max')); - } - - public static function detailLiens($book, $stats) - { - $colsTitles = array(__('URL'), __('Clics')); - $lines = array(); - $xlines = array(); - - foreach ($stats->links->link as $link) { - $uurl = (string)$link['url']; - $nb = (string)$link['click']; - if (stristr($uurl, 'mailto:') || stristr($uurl, 'http://') || stristr($uurl, 'https://')) { - $url = substr($uurl, 7); - } else { - $url = $uurl; - } - if (strlen($url) > 30) { - $url = substr($url, 0, 30) . '...'; - } - - $lines[] = array('' . $url . '', $nb); - $xlines[] = array($uurl, $nb); - } - - self::setSheetFromDatas(__('Liens'), $colsTitles, $xlines); - return self::table(__('Liens les plus cliqués'), $colsTitles, $lines, array('liste', 'max')); - } - - public static function detailSearch($book, $stats) - { - $colsTitles = array(__('Mot'), __('Recherches')); - $lines = array(); - - foreach ($stats->searches->search as $search) { - $q = $search['query']; - if (strlen($q) > 25) { - $q = '' . substr($q, 0, 25) . ' ...'; - } - $lines[] = array($q, $search['count']); - } - self::setSheetFromDatas(__('Recherches'), $colsTitles, $lines); - return self::table(__('Mots les plus recherchés'), $colsTitles, $lines, array('liste', 'max')); - } - - public static function detailOrigine($book, $stats) - { - $colsTitles = array(__('Pays'), __('Visiteurs')); - $lines = array(); - $xlines = array(); - $i = 0; - - foreach ($stats->countries->country as $country) { - $pays = $country['code']; - $odd = cubeMath::isOdd($i) ? ' class="odd"' : ''; - if (!$c = cubeCountry::getCountry($pays)) { - $c = __('Origine inconnue'); - } - $lines[] = array(cubeCountry::getFlag($pays) . ' ' . ucfirst(mb_strtolower($c)), $country['visitors']); - $xlines[] = array(ucfirst(mb_strtolower($c)), $country['visitors']); - $i++; - } - self::setSheetFromDatas(__('Origines'), $colsTitles, $xlines); - return self::table(__('Origine des visiteurs'), $colsTitles, $lines, array('liste', 'max')); - } - - public static function getQ($max, &$maxp, &$maxpages, &$s) - { - $maxpages = $maxp; - $q = 1; - $maxp /= $q; - $maxp = max($max * 4, $maxp); - $q = $maxpages / $maxp; - foreach ($s as $time => $t) { - $s[$time]['page'] = intval($s[$time]['page'] / $q); - } - } - - public static function graph_annuel($bid, $a, $stats) - { - $img = SYSIMG . '/stats/annuel-' . $a . '-' . $bid . '.png'; - $imgw = IMG . '/stats/annuel-' . $a . '-' . $bid . '.png'; - $maxv = 0; - $maxp = 0; - $maxb = 0; - $s = array(); - foreach ($stats->month as $month) { - $maxb = max($maxb, (string)$month['visits']); - $maxp = max($maxp, (string)$month['pages']); - $maxv = max($maxv, (string)$month['visitors']); - $time = cubeDate::round(mktime(0, 0, 0, (string)$month['month'], 15, (string)$month['year']), 'm'); - $s[$time] = array(); - $s[$time]['book'] = (string)$month['visits']; - $s[$time]['page'] = (string)$month['pages']; - $s[$time]['visit'] = (string)$month['visitors']; - } - // . - $max = max($maxb, $maxv); - self::getQ($max, $maxp, $maxpages, $s); - krsort($s); - $max = max($maxb, $maxv, $maxp); - $months = cubeDate::getMonths($a); - @unlink($img); - if (!file_exists($img) || filemtime($img) < cubeDate::round(null, 'H')) { - $im = imagecreatetruecolor(944, 306); - //imagelayereffect($im, IMG_EFFECT_REPLACE); - $trans = imagecolorallocatealpha($im, 255, 255, 255, 0); - imagefill($im, 0, 0, $trans); - //imagelayereffect($im, IMG_EFFECT_ALPHABLEND); - $i = 1; - $x0 = 0; - $y0 = 305; - $h = 300; - $c0 = imagecolorallocate($im, 0, 0, 0); - $c1 = imagecolorallocatealpha($im, 81, 78, 73, 64); - $hp = $h * ($maxp / $max) - 2; - $mhp = $y0 - $hp - 6; - imagesetstyle($im, array($c1, $c1, $c1, $c1, $c1, $trans, $trans, $trans, $trans)); - imageline($im, 0, $y0 - $hp, 944, $y0 - $hp, IMG_COLOR_STYLED); - $c1 = imagecolorallocate($im, 81, 78, 73); - $c2 = imagecolorallocatealpha($im, 245, 77, 0, 64); - $hb = $h * ($maxb / $max) - 1; - $mhb = $y0 - $hb - 6; - imagesetstyle($im, array($c2, $c2, $c2, $c2, $c2, $trans, $trans, $trans, $trans)); - imageline($im, 0, $y0 - $hb, 944, $y0 - $hb, IMG_COLOR_STYLED); - $c2 = imagecolorallocate($im, 245, 77, 0); - $c3 = imagecolorallocatealpha($im, 194, 211, 19, 32); - $hv = $h * ($maxv / $max); - $mhv = $y0 - $hv - 6; - imagesetstyle($im, array($c3, $c3, $c3, $c3, $c3, $trans, $trans, $trans, $trans)); - imageline($im, 0, $y0 - $hv, 944, $y0 - $hv, IMG_COLOR_STYLED); - $c3 = imagecolorallocate($im, 194, 211, 19); - foreach ($months as $m => $t) { - if (isset($s[$t])) { - $x0 += 15; - $hp = $h * ($s[$t]['page'] / $max) - 2; - $hb = $h * ($s[$t]['book'] / $max) - 1; - $hv = $h * ($s[$t]['visit'] / $max); - imagefilledrectangle($im, $x0 + 40, $y0 - $hp, $x0, $y0, $c1); - imagerectangle($im, $x0 + 40, $y0 - $hp, $x0, $y0, $c0); - $x0 += 5; - imagefilledrectangle($im, $x0 + 40, $y0 - $hb, $x0, $y0, $c2); - imagerectangle($im, $x0 + 40, $y0 - $hb, $x0, $y0, $c0); - $x0 += 5; - imagefilledrectangle($im, $x0 + 40, $y0 - $hv, $x0, $y0, $c3); - imagerectangle($im, $x0 + 40, $y0 - $hv, $x0, $y0, $c0); - $i++; - $x0 += 50; - } else { - $x0 += 75; - } - } - - imageline($im, 0, $y0, 944, $y0, $c0); - imagepng($im, $img); - } - $res = '
' . $maxpages . '
'; - $res .= '
' . $maxb . '
'; - $res .= '
' . $maxv . '
'; - $res .= '
'; - $res .= ''; - foreach ($months as $m => $t) { - $res .= ''; - } - $res .= ''; - $res .= '
' . strftime('%b %y', $t) . '' . cubeMedia::spacer(44, 20) . '
'; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= '
' . __('Pages vues') . '' . __('Visites') . '' . __('Visiteurs uniques') . '
'; - return $res; - } - - public static function graph_global($bid, $stats) - { - global $core; - $img = SYSIMG . '/stats/global-' . $bid . '.png'; - $imgw = IMG . '/stats/global-' . $bid . '.png'; - $s = array(); - foreach ($stats->year as $year) { - foreach ($year->month as $month) { - $time = mktime(0, 0, 0, intval((string)$month['month']), 15, (string)$month['year']); - $s[$time]['book'] = $month['visits']; - $s[$time]['page'] = $month['pages']; - $s[$time]['time'] = $time; - $s[$time]['visit'] = $month['visitors']; - } - } - - krsort($s); - $s = array_slice($s, 0, 12, true); - $maxv = 0; - $maxp = 0; - $maxb = 0; - foreach ($s as $time => $d) { - $maxb = max($maxb, (string)$d['book']); - $maxp = max($maxp, (string)$d['page']); - $maxv = max($maxv, (string)$d['visit']); - } - - $max = max($maxb, $maxv); - self::getQ($max, $maxp, $maxpages, $s); - $max = max($maxv, $maxb, $maxp, 1); - if (file_exists($img)) { - unlink($img); - } - if (!file_exists($img) || filemtime($img) < cubeDate::round(null, 'H')) { - $im = imagecreatetruecolor(944, 306); - //imagelayereffect($im, IMG_EFFECT_REPLACE); - $trans = imagecolorallocatealpha($im, 255, 255, 255, 0); - imagefill($im, 0, 0, $trans); - //imagelayereffect($im, IMG_EFFECT_ALPHABLEND); - $i = 1; - $x0 = 900; - $y0 = 305; - $h = 300; - $c0 = imagecolorallocate($im, 0, 0, 0); - $c1 = imagecolorallocatealpha($im, 81, 78, 73, 64); - $hp = $h * ($maxp / $max) - 2; - $mhp = $y0 - $hp - 6; - imagesetstyle($im, array($c1, $c1, $c1, $c1, $c1, $trans, $trans, $trans, $trans)); - imageline($im, 0, $y0 - $hp, 944, $y0 - $hp, IMG_COLOR_STYLED); - $c1 = imagecolorallocate($im, 81, 78, 73); - $c2 = imagecolorallocatealpha($im, 245, 77, 0, 64); - $hb = $h * ($maxb / $max) - 1; - $mhb = $y0 - $hb - 6; - imagesetstyle($im, array($c2, $c2, $c2, $c2, $c2, $trans, $trans, $trans, $trans)); - imageline($im, 0, $y0 - $hb, 944, $y0 - $hb, IMG_COLOR_STYLED); - $c2 = imagecolorallocate($im, 245, 77, 0); - $c3 = imagecolorallocatealpha($im, 194, 211, 19, 32); - $hv = $h * ($maxv / $max); - $mhv = $y0 - $hv - 6; - imagesetstyle($im, array($c3, $c3, $c3, $c3, $c3, $trans, $trans, $trans, $trans)); - imageline($im, 0, $y0 - $hv, 944, $y0 - $hv, IMG_COLOR_STYLED); - $c3 = imagecolorallocate($im, 194, 211, 19); - foreach ($s as $t) { - $x0 -= 15; - $hp = $h * ($t['page'] / $max) - 2; - $hb = $h * ($t['book'] / $max) - 1; - $hv = $h * ($t['visit'] / $max); - imagefilledrectangle($im, $x0 - 40, $y0 - $hp, $x0, $y0, $c1); - imagerectangle($im, $x0 - 40, $y0 - $hp, $x0, $y0, $c0); - $x0 -= 5; - imagefilledrectangle($im, $x0 - 40, $y0 - $hb, $x0, $y0, $c2); - imagerectangle($im, $x0 - 40, $y0 - $hb, $x0, $y0, $c0); - $x0 -= 5; - imagefilledrectangle($im, $x0 - 40, $y0 - $hv, $x0, $y0, $c3); - imagerectangle($im, $x0 - 40, $y0 - $hv, $x0, $y0, $c0); - $i++; - $x0 -= 50; - } - - imageline($im, 0, $y0, 944, $y0, $c0); - imagepng($im, $img); - } - $res = '
' . $maxpages . '
'; - $res .= '
' . $maxb . '
'; - $res .= '
' . $maxv . '
'; - $res .= '
'; - $s = array_reverse(array_pad($s, 12, false), true); - $res .= ''; - foreach ($s as $time => $val) { - if (!$val) { - $res .= ''; - } else { - $res .= ''; - } - } - $res .= ''; - $res .= '
' . cubeMedia::spacer(75, 20) . '' . strftime('%b %y', $val['time']) . '' . cubeMedia::spacer(44, 20) . '
'; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= '
' . __('Pages vues') . '' . __('Visites') . '' . __('Visiteurs uniques') . '
'; - return $res; - } - - public static function graph_mensuel($bid, $a, $m, $stats) - { - $img = SYSIMG . '/stats/mensuel-' . $a . '-' . $m . '-' . $bid . '.png'; - $imgw = IMG . '/stats/mensuel-' . $a . '-' . $m . '-' . $bid . '.png'; - $lm = cubeDate::limitMonth($a, $m); - $datestocorrect = array(mktime(0, 0, 0, 11, 23, 2009), mktime(0, 0, 0, 12, 8, 2009), mktime(0, 0, 0, 12, 9, 2009)); - $maxv = 0; - $maxp = 0; - $maxb = 0; - $v = array(); - $s = array(); - foreach ($stats->days->day as $day) { - $time = mktime(0, 0, 0, $m, (string)$day['day'], $a); - $maxb = max($maxb, (string)$day['visits']); - $maxp = max($maxp, (string)$day['views']); - $maxv = max($maxv, (string)$day['visitors']); - $s[$time]['book'] = $day['visits']; - $s[$time]['page'] = $day['views']; - $s[$time]['visit'] = $day['visitors']; - $s[$time]['time'] = $time; - } - $max = max($maxb, $maxv); - self::getQ($max, $maxp, $maxpages, $s); - krsort($s); - $max = max($maxv, $maxb, $maxp); - $days = cubeDate::getDays($a, $m); - $space = round((900 - (count($days) * 20)) / (count($days) * 2)); - @unlink($img); - if (!file_exists($img) || filemtime($img) < cubeDate::round(null, 'H')) { - // Création de l'image - $im = imagecreatetruecolor(944, 306); - //imagelayereffect($im, IMG_EFFECT_REPLACE); - $trans = imagecolorallocatealpha($im, 255, 255, 255, 0); - imagefill($im, 0, 0, $trans); - //imagelayereffect($im, IMG_EFFECT_ALPHABLEND); - $i = 1; - $x0 = 0; - $y0 = 305; - $h = 300; - $c0 = imagecolorallocate($im, 0, 0, 0); - $c1 = imagecolorallocatealpha($im, 81, 78, 73, 64); - $hp = $h * ($maxp / $max) - 2; - $mhp = $y0 - $hp - 6; - imagesetstyle($im, array($c1, $c1, $c1, $c1, $c1, $trans, $trans, $trans, $trans)); - imageline($im, 0, $y0 - $hp, 944, $y0 - $hp, IMG_COLOR_STYLED); - $c1 = imagecolorallocate($im, 81, 78, 73); - $c2 = imagecolorallocatealpha($im, 245, 77, 0, 64); - $hb = $h * ($maxb / $max) - 1; - $mhb = $y0 - $hb - 6; - imagesetstyle($im, array($c2, $c2, $c2, $c2, $c2, $trans, $trans, $trans, $trans)); - imageline($im, 0, $y0 - $hb, 944, $y0 - $hb, IMG_COLOR_STYLED); - $c2 = imagecolorallocate($im, 245, 77, 0); - $c3 = imagecolorallocatealpha($im, 194, 211, 19, 32); - $hv = $h * ($maxv / $max); - $mhv = $y0 - $hv - 6; - imagesetstyle($im, array($c3, $c3, $c3, $c3, $c3, $trans, $trans, $trans, $trans)); - imageline($im, 0, $y0 - $hv, 944, $y0 - $hv, IMG_COLOR_STYLED); - $c3 = imagecolorallocate($im, 194, 211, 19); - foreach ($days as $d => $t) { - if (isset($s[$t])) { - $x0 += $space; - $hp = $h * ($s[$t]['page'] / $max) - 2; - $hb = $h * ($s[$t]['book'] / $max) - 1; - $hv = $h * ($s[$t]['visit'] / $max); - imagefilledrectangle($im, $x0 + 14, $y0 - $hp, $x0, $y0, $c1); - imagerectangle($im, $x0 + 14, $y0 - $hp, $x0, $y0, $c0); - $x0 += 3; - imagefilledrectangle($im, $x0 + 14, $y0 - $hb, $x0, $y0, $c2); - imagerectangle($im, $x0 + 14, $y0 - $hb, $x0, $y0, $c0); - $x0 += 3; - imagefilledrectangle($im, $x0 + 14, $y0 - $hv, $x0, $y0, $c3); - imagerectangle($im, $x0 + 14, $y0 - $hv, $x0, $y0, $c0); - $i++; - $x0 += 14 + $space; - } else { - $x0 += 20 + $space * 2; - } - } - - imageline($im, 0, $y0, 944, $y0, $c0); - imagepng($im, $img); - } - $res = '
' . $maxpages . '
'; - $res .= '
' . $maxb . '
'; - $res .= '
' . $maxv . '
'; - $res .= '
'; - $res .= ''; - foreach ($days as $d => $t) { - $res .= ''; - } - $spacef = 944 - (count($days) * (20 + ($space * 2))); - $res .= ''; - $res .= '
' . $d . '' . cubeMedia::spacer($spacef, 20) . '
'; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= '
' . __('Pages vues') . '' . __('Visites') . '' . __('Visiteurs uniques') . '
'; - return $res; - } - - public static function forceComputation($id) - { - `/home/stats/www/FWStats.sh /home/stats/www onlybook=$id`; - } + public static $datestocorrect = array(array(22, 11, 2009), array(23, 11, 2009), array(8, 12, 2009), array(9, 12, 2009)); + + /** + * @var PHPExcel + */ + public static $xls; + + public static function exportXLS($bid, $annee = null, $mois = null) + { + $xname = self::_getXLSFile($bid, $annee, $mois); + $fname = 'stats_' . $bid; + if (!is_null($annee)) { + $fname .= '_' . $annee; + if (!is_null($mois)) { + $fname .= '_' . $mois; + } + } + $fname .= '.xlsx'; + + files::$mimeType['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + + cubeHTTP::downloadFile($xname, $fname); + } + + protected static function _getXLSFile($bid, $annee = null, $mois = null) + { + self::forceComputation($bid); + $e = explode('_', $bid); + $bid = $e[0]; + $xname = '/home/stats/www/xls/' . $bid; + if (!is_null($annee)) { + $xname .= '/' . $annee; + if (!is_null($mois)) { + $xname .= '/' . $mois; + } + } + + $xname .= '.xlsx'; + + $dir = dirname($xname); + if (!file_exists($dir)) { + mkdir($dir, 0777, true); + } + + return $xname; + } + + public static function display($bid, $annee = null, $mois = null) + { + global $core; + + self::forceComputation($bid); + + cubePHP::set_memory('12G'); + + self::$xls = new PHPExcel(); + if (self::$xls->getSheetCount() < 2) { + wsMaintenance::fixStats([$bid]); + }else { + self::$xls->removeSheetByIndex(0); + } + + $global = self::load_stats($bid); + + + $exporturl = SITE_PATH . 'statsxls/' . $bid; + if (!is_null($annee)) { + $exporturl .= '/' . $annee; + if (!is_null($mois)) { + $exporturl .= '/' . $mois; + } + } + + $actions = array(); + $actions[] = '' . $core->typo->Ajouter('Exporter au format Excel') . ''; + + $years = $global->year; + $annees = array('' . __('Toutes') . '' => SITE_PATH . 'stats/' . $bid); + + $listeShortcuts = array(); + + + $listeMois = null; + foreach ($years as $y) { + $selectedYear = __('Toutes'); + if (!is_null($annee) && $annee == (string)$y['year']) { + $months = $y->month; + $moiss = array('' . __('Tous') . '' => SITE_PATH . 'stats/' . $bid . '/' . (string)$y['year']); + $selectedMonth = __('Tous'); + foreach ($months as $m) { + if ((string)$m['month'] == $mois) { + $selectedMonth = cubeDate::getMonth((string)$m['month']); + } + $moiss[cubeDate::getMonth((string)$m['month'])] = SITE_PATH . 'stats/' . $bid . '/' . (string)$y['year'] . '/' . (string)$m['month']; + } + $listeMois = new commonShortcuts(__('Mois'), $moiss, $selectedMonth); + } + if ((string)$y['year'] == $annee) { + $selectedYear = $annee; + } + $annees[(string)$y['year']] = SITE_PATH . 'stats/' . $bid . '/' . (string)$y['year']; + } + + $listeAnnees = new commonShortcuts(__('Année'), $annees, $selectedYear); + $listeShortcuts[] = $listeAnnees; + if (!is_null($listeMois)) { + $listeShortcuts[] = $listeMois; + } + + $res = commonPage::barre($listeShortcuts, 'filtreStats', 'stats', $actions); + $res .= commonPage::tMain(); + if (is_null($annee) && is_null($mois)) { + $res .= self::vue_globale($bid); + } elseif (is_null($mois)) { + $res .= self::vue_annuelle($bid, $annee); + } else { + $res .= self::vue_mensuelle($bid, $annee, $mois); + } + $res .= commonPage::bMain(); + + + try { + self::$xls->setActiveSheetIndex(0); + $writer = new PHPExcel_Writer_Excel2007(); + $writer->setPHPExcel(self::$xls); + $xlsfile = self::_getXLSFile($bid, $annee, $mois); + cubePHP::set_memory('12G'); + $writer->save($xlsfile); + } catch (Exception $e) { + die($e->getMessage()); + } + + return $res; + } + + public static function getExtra($extra) + { + $xml = simplexml_load_string('' . $extra . ''); + if ((string)$xml->extraName != '') { + return (string)$xml->extraName; + } + return null; + } + + public static function load_stats($bid, $annee = null, $mois = null) + { + + $e = explode('_', $bid, 2); + $bid = $e[0]; + + $root = WS_STATS . 'xml/' . $bid; + if (is_null($annee)) { + $xml = $root; + $sort = 'globalSort'; + } else if (is_null($mois)) { + $xml = $root . '/' . $annee; + $sort = 'yearSort'; + } else { + $xml = $root . '/' . $annee . '/' . $mois; + $sort = 'monthSort'; + } + $xml = rtrim($xml, '/'); + $xml .= '.xml'; + if ($x = @simplexml_load_file($xml)) { + if (!is_null($mois)) { + + } + $x = call_user_func(array('wsStats', $sort), $x); + self::correctValues($x, $annee, $mois); + return $x; + } + return null; + } + + public static function correctValues($x, $y, $m) + { + return; + foreach (self::$datestocorrect as $date) { + if ($date[2] != $y || $date[1] != $m) { + continue; + } + $days = $x->xpath("//day[@day=" . $date[0] . "]"); + foreach ($days as $day) { + break; + } + $visitors = (string)$day['places'] * 1.2; + $visits = $visitors * 1.1; + cubeXML::removeAttribute($day, 'visitors'); + cubeXML::removeAttribute($day, 'visits'); + $day->addAttribute('visitors', $visitors); + $day->addAttribute('visits', $visits); + } + } + + public static function correctPlaces($x) + { + + } + + public static function globalSort($xml, $root = 'stats') + { + $res = simplexml_load_string('<' . $root . ' />'); + foreach ($xml->attributes() as $k => $v) { + $res->addAttribute($k, $v); + } + $years = array(); + foreach ($xml->year as $year) { + $years[(string)$year['year']] = self::yearSort($year, 'year'); + } + ksort($years); + foreach ($years as $y) { + cubeXML::append($res, $y); + } + return $res; + } + + public static function yearSort($xml, $root = 'stats') + { + $res = simplexml_load_string('<' . $root . ' />'); + foreach ($xml->attributes() as $k => $v) { + $res->addAttribute($k, $v); + } + $months = array(); + foreach ($xml->month as $month) { + $months[(string)$month['month']] = $month; + } + + ksort($months); + foreach ($months as $month) { + cubeXML::append($res, $month); + } + + return $res; + } + + public static function monthSort($xml, $root = 'stats') + { + $res = simplexml_load_string('<' . $root . ' />'); + foreach ($xml->attributes() as $k => $v) { + $res->addAttribute($k, $v); + } + self::daysSort($xml, $res); + self::pagesSort($xml, $res); + self::linksSort($xml, $res); + self::searchesSort($xml, $res); + self::countriesSort($xml, $res); + return $res; + } + + public static function daysSort($xml, $res) + { + $x = $res->addChild('days'); + $days = array(); + foreach ($xml->days->day as $day) { + $days[(string)$day['day']] = $day; + } + ksort($days); + foreach ($days as $day) { + $places = (string)$day['places']; + if ($places == 1) { + $visitors = (string)$day['visitors']; + if ($visitors > 10) { + cubeXML::removeAttribute($day, 'places'); + $day->addAttribute('places', round($visitors * 0.99)); + } + } + cubeXML::append($x, $day); + } + } + + public static function pagesSort($xml, $res) + { + $xpages = $res->addChild('pages'); + $pages = array(); + $trans = array(); + foreach ($xml->pages->page as $page) { + $pages[(string)$page['page']] = (string)$page['score']; + $trans[(string)$page['page']] = $page; + } + arsort($pages); + foreach ($pages as $num => $score) { + cubeXML::append($xpages, $trans[$num]); + } + } + + public static function linksSort($xml, $res) + { + $x = $res->addChild('links'); + $links = array(); + $trans = array(); + foreach ($xml->links->link as $link) { + $links[(string)$link['url']] = (string)$link['click']; + $trans[(string)$link['url']] = $link; + } + arsort($links); + $links = array_slice($links, 0, 100, true); + foreach ($links as $url => $click) { + cubeXML::append($x, $trans[$url]); + } + } + + public static function searchesSort($xml, $res) + { + $x = $res->addChild('searches'); + $searches = array(); + $trans = array(); + foreach ($xml->searches->search as $search) { + $searches[(string)$search['query']] = (string)$search['count']; + $trans[(string)$search['query']] = $search; + } + arsort($searches); + $searches = array_slice($searches, 0, 100, true); + foreach ($searches as $q => $count) { + cubeXML::append($x, $trans[$q]); + } + } + + public static function countriesSort($xml, $res) + { + $x = $res->addChild('countries'); + $countries = array(); + $trans = array(); + foreach ($xml->countries->country as $country) { + $countries[(string)$country['code']] = (string)$country['visitors']; + $trans[(string)$country['code']] = $country; + } + arsort($countries); + foreach ($countries as $code => $visitors) { + cubeXML::append($x, $trans[$code]); + } + } + + public static function getActives($stats, $book, &$aextra, &$adown, &$adownp, &$aprint, &$afriend) + { + $extra = self::getExtra($book->extras); + $aextra = ($extra != null && $stats['extras'] > 0); + $adown = ($book->parametres->pdf == 1 && $stats['downloads'] > 0); + $adownp = ($book->parametres->pdf == 1 && $book->parametres->pdfComplex == 1 && $stats['partDownloads'] > 0); + $aprint = ($book->parametres->print == 1); + $afriend = ($book->parametres->friend == 1); + } + + public static function table($title, $colsTitles, $lines, $class, $firstColMax = true, $firstLineBold = false, $noOdd = false) + { + global $core; + if (is_string($class)) { + $class = array($class); + } + $res = ''; + // Titre + $res .= ''; + // Head + if (implode('', $colsTitles) != '') { + $res .= ''; + foreach ($colsTitles as $i => $title) { + $max = ($firstColMax && $i == 0) ? '' : ' class="stats_col"'; + $res .= '' . $title . ''; + } + $res . ''; + } + // Body + foreach ($lines as $i => $line) { + $odd = cubeMath::isOdd($i) ? ' class="odd"' : ''; + if ($firstLineBold && $i == 0) { + $odd = ' class="odd"'; + } elseif ($firstLineBold) { + $odd = ''; + } + if ($noOdd) { + $odd = ''; + } + $res .= ''; + foreach ($line as $j => $cell) { + $max = ($firstColMax && $j == 0) ? '' : ' class="stats_col"'; + if ($firstLineBold && $i == 0) { + $cell = '' . $cell . ''; + } + $res .= '' . $cell . ''; + } + $res .= ''; + } + + $res .= '

' . $title . '

'; + + return $res; + } + + /** + * + * @param string $name + * @return PHPExcel_Worksheet + */ + protected static function _createSheet($name) + { + $s = self::$xls->createSheet(); + $s->setTitle($name); + return $s; + } + + public static function globalDatas($titre, $date_creation, $book, $stats, $afriend, $aprint, $adown, $adownp, $aextra) + { + global $xls; + + $colsTitles = array('', ''); + $lines = array(); + $class = array('liste', 'max'); + + $lines[] = array($date_creation, date(__('d-m-Y'), $book->date)); + //$lines[] = array(__('Nombre de lieux de visite'), $stats['places']); + $lines[] = array(__('Nombre de visiteurs uniques'), $stats['visitors']); + $lines[] = array(__('Nombre de visites'), $stats['visits']); + $lines[] = array(__('Nombre de pages vues'), $stats['pages']); + if ($afriend) { + $lines[] = array(__('Nombre de liens envoyés'), $stats['friends']); + } + $lines[] = array(__('Nombre de liens cliqués'), $stats['links']); + if ($aprint) { + $lines[] = array(__("Nombre d'impressions"), $stats['prints']); + } + if ($adown) { + $lines[] = array(__('Nombre de téléchargements'), $stats['downloads']); + } + if ($adownp) { + $lines[] = array(__('Nombre de téléchargements partiels'), $stats['partDownloads']); + } + if ($aextra) { + $lines[] = array(__('Accès à la rubrique') . ' ' . $extra, $stats['extras']); + } + + self::setSheetFromDatas(__('Résumé'), null, $lines); + + return self::table($titre, $colsTitles, $lines, $class); + } + + public static function indisponible() + { + $res = commonPage::bh('stats_global'); + $res .= '

' . __('Les statistiques concernant cette période ne sont actuellement pas disponibles') . '

'; + $res .= commonPage::bf(); + return $res; + } + + public static function getBook($bid) + { + global $core; + $daoBook = new wsDAOBook($core->con); + return $daoBook->selectById($bid); + } + + public static function vue_globale($bid, $annee = null) + { + global $core; + $book = self::getBook($bid); + $extra = self::getExtra($book->extras); + if (is_null($annee)) { + $stats = self::load_stats($bid); + } else { + $stats = self::load_stats($bid, $annee); + } + + if (is_null($stats)) { + return self::indisponible(); + } + + self::getActives($stats, $book, $aextra, $adown, $adownp, $aprint, $afriend); + $res = commonPage::bh('stats_global'); + $titre = __('Statistiques de la publication « %s »'); + $date_creation = __('Date de création de la publication'); + $res .= self::globalDatas(sprintf($titre, $book->nom), $date_creation, $book, $stats, $afriend, $aprint, $adown, $adownp, $aextra); + $res .= commonPage::bf(); + $res .= commonPage::bh(); + $res .= ''; + $res .= ''; + $res .= ''; + $res .= '

' . __('Détail par mois') . '

'; + $res .= '
'; + if (is_null($annee)) { + $res .= self::graph_global($bid, $stats); + } else { + $res .= self::graph_annuel($bid, $annee, $stats); + } + $res .= '
'; + $res .= '
'; + $res .= self::detailPeriode($book, $stats, $bid, $annee); + $res .= commonPage::bf(); + return $res; + } + + /** + * wsStats::vue_annuelle() + * + * @param mixed $bid + * @param mixed $annee + * @return + */ + public static function vue_annuelle($bid, $annee) + { + return self::vue_globale($bid, $annee); + } + + public static function vue_mensuelle($bid, $annee, $mois) + { + $datestocorrect = array(mktime(0, 0, 0, 11, 23, 2009), mktime(0, 0, 0, 12, 8, 2009), mktime(0, 0, 0, 12, 9, 2009)); + global $core; + $book = self::getBook($bid); + $extra = self::getExtra($book->extras); + $stats = self::load_stats($bid, $annee, $mois); + if (is_null($stats)) { + return self::indisponible(); + } + + self::getActives($stats, $book, $aextra, $adown, $adownp, $aprint, $afriend); + $time_page = mktime(0, 0, 0, $mois, 15, $annee); + $res = commonPage::bh('stats_global'); + $titre = __('Statistiques de la publication « %s »'); + $date_creation = __('Date de création de la publication'); + $res .= self::globalDatas(sprintf($titre, $book->nom), $date_creation, $book, $stats, $afriend, $aprint, $adown, $adownp, $aextra); + $res .= commonPage::bf(); + // . + $res .= commonPage::bh('stats_detail_mois'); + $res .= '
'; + $res .= self::graph_mensuel($bid, $annee, $mois, $stats); + $res .= '
'; + $res .= self::detailJour($book, $annee, $mois, $stats); + $res .= commonPage::bf(); + + + // . + $res .= commonPage::bh('stats_detail_pages'); + $res .= self::detailPages($book, $annee, $mois, $stats); + $res .= commonPage::bf(); + // . + if ($book->parametres->search == 0) { + $idl = 'stats_links_2'; + $idc = 'stats_country_2'; + } else { + $idl = 'stats_links'; + $idc = 'stats_country'; + } + + $res .= '
'; + $res .= commonPage::bh($idl); + $res .= self::detailLiens($book, $stats); + $res .= commonPage::bf(); + if ($book->parametres->search == 1) { + $res .= commonPage::bh('stats_search'); + $res .= self::detailSearch($book, $stats); + $res .= commonPage::bf(); + } + // Origine + $res .= commonPage::bh($idc); + $res .= self::detailOrigine($book, $stats); + $res .= commonPage::bf(); + $res .= '
'; + return $res; + } + + public static function detailPeriode($book, $stats, $bid, $annee) + { + self::getActives($stats, $book, $aextra, $adown, $adownp, $aprint, $afriend); + $title = ''; + + $colsTitles = array(__('Période'), /*__('Lieux de visite'),*/ + __('Visiteurs uniques'), __('Visites'), __('Pages vues')); + if ($afriend) { + $colsTitles[] = __('Liens envoyés'); + } + $colsTitles[] = __('Liens cliqués'); + if ($aprint) { + $colsTitles[] = __('Impressions'); + } + if ($adown) { + $colsTitles[] = __('Téléchargements'); + } + if ($adownp) { + $colsTitles[] = __('Téléchargements partiels'); + } + if ($aextra) { + $colsTitles[] = $extra; + } + + if (is_null($annee)) { + $years = $stats->year; + } else { + $years = array($stats); + } + + $lines = array(); + $noOdd = false; + foreach ($years as $year) { + if ($year['annee'] != null) { + $lines[] = self::linePeriod($year, $bid, $afriend, $aprint, $adown, $adownp, $aextra); + } else { + $noOdd = true; + } + + foreach ($year->month as $month) { + $lines[] = self::linePeriod($month, $bid, $afriend, $aprint, $adown, $adownp, $aextra); + } + } + + self::setSheetFromDatas(__('Détail'), $colsTitles, $lines); + + return self::table($title, $colsTitles, $lines, array('max', 'liste'), true, false, $noOdd); + } + + protected static function setSheetFromDatas($title, $columns, $lines) + { + $s = self::_createSheet($title); + $offset = 1; + if (!is_null($columns)) { + $offset = 2; + foreach ($columns as $k => $c) { + + $s->setCellValueByColumnAndRow($k, 1, $c); + $s->getStyleByColumnAndRow($k, 1)->getFont()->setBold(true); + + if ($k == 0) { + $s->getStyleByColumnAndRow($k, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); + } else { + $s->getStyleByColumnAndRow($k, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); + } + } + } + foreach ($lines as $k => $l) { + foreach ($l as $c => $v) { + $s->getColumnDimensionByColumn($c)->setAutoSize(true); + $s->setCellValueByColumnAndRow($c, $k + $offset, strip_tags($v)); + + if ($c == 0) { + $s->getStyleByColumnAndRow($c, $k + $offset)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); + } else { + $s->getStyleByColumnAndRow($c, $k + $offset)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); + } + } + } + } + + public static function linePeriod($stats, $bid, $afriend, $aprint, $adown, $adownp, $aextra) + { + $line = array(); + $url = SITE_PATH . 'stats/' . $bid; + if (isset($stats['year'])) { + $url .= '/' . $stats['year']; + if (isset($stats['month'])) { + $url .= '/' . $stats['month']; + $date = strftime('%B %Y', mktime(0, 0, 0, (string)$stats['month'], 15, (string)$stats['year'])); + } else { + $date = (string)$stats['year']; + } + } + + $line[] = '' . $date . ''; + //$line[] = $stats['places']; + $line[] = $stats['visitors']; + $line[] = $stats['visits']; + $line[] = $stats['pages']; + if ($afriend) { + $line[] = $stats['friends']; + } + $line[] = $stats['links']; + if ($aprint) { + $line[] = $stats['prints']; + } + if ($adown) { + $line[] = $stats['downloads']; + } + if ($adownp) { + $line[] = $stats['partDownloads']; + } + if ($aextra) { + $line[] = $stats['extras']; + } + + return $line; + } + + public static function detailJour($book, $annee, $mois, $stats) + { + $colsTitles = array(__('Jour'), /*__('Lieux de visite'),*/ + __('Visiteurs uniques'), __('Visites'), __('Pages vues'), __('Liens cliqués')); + $lines = array(); + $xlines = array(); + + foreach ($stats->days->day as $day) { + $lines[] = array(strftime('%A %d', mktime(0, 0, 0, $mois, (string)$day['day'], $annee)), + // $day['places'], + $day['visitors'], + $day['visits'], + $day['views'], + $day['links']); + $xlines[] = array(strftime('%d', mktime(0, 0, 0, $mois, (string)$day['day'], $annee)), + //$day['places'], + $day['visitors'], + $day['visits'], + $day['views'], + $day['links']); + } + $time_page = mktime(0, 0, 0, $mois, 15, $annee); + + self::setSheetFromDatas(__('Jours'), $colsTitles, $xlines); + + return self::table(__('Détail par jour') . ' - ' . strftime('%B %Y', $time_page), $colsTitles, $lines, array('liste', 'max'), true); + } + + public static function detailPages($book, $annee, $mois, $stats) + { + $colsTitles = array(__('Pages')); + if ($book->parametres->stats_score) { + $colsTitles[] = __('Score'); + } + $colsTitles[] = __('Vues'); + $colsTitles[] = __('Zooms'); + if ($book->parametres->bookmark) { + $colsTitles[] = __('Marques-pages'); + } + if ($book->parametres->print) { + $colsTitles[] = __('Impressions'); + } + + $lines = array(); + foreach ($stats->pages->page as $page) { + $p = (string)$page['page']; + if ($p > $book->pages || cubeMath::isOdd($p)) { + continue; + } + if ($p == 0) { + $pagen = '1'; + } elseif ($p == $book->parametres->pages) { + $pagen = $p; + } else { + $pagen = $p; + $pagen .= '-'; + $pagen .= ($p + 1); + } + + $line = array($pagen); + + if ($book->parametres->stats_score == 1) { + $line[] = $page['score']; + } + $line[] = $page['views']; + $line[] = $page['zooms']; + + if ($book->parametres->bookmark == 1) { + $line[] = $page['bookmarks']; + } + if ($book->parametres->print == 1) { + $line[] = $page['prints']; + } + $lines[] = $line; + } + $time_page = mktime(0, 0, 0, $mois, 15, $annee); + + self::setSheetFromDatas(__('Pages'), $colsTitles, $lines); + + return self::table(__('Détail par page') . ' - ' . strftime('%B %Y', $time_page), $colsTitles, $lines, array('liste', 'max')); + } + + public static function detailLiens($book, $stats) + { + $colsTitles = array(__('URL'), __('Clics')); + $lines = array(); + $xlines = array(); + + foreach ($stats->links->link as $link) { + $uurl = (string)$link['url']; + $nb = (string)$link['click']; + if (stristr($uurl, 'mailto:') || stristr($uurl, 'http://') || stristr($uurl, 'https://')) { + $url = substr($uurl, 7); + } else { + $url = $uurl; + } + if (strlen($url) > 30) { + $url = substr($url, 0, 30) . '...'; + } + + $lines[] = array('' . $url . '', $nb); + $xlines[] = array($uurl, $nb); + } + + self::setSheetFromDatas(__('Liens'), $colsTitles, $xlines); + return self::table(__('Liens les plus cliqués'), $colsTitles, $lines, array('liste', 'max')); + } + + public static function detailSearch($book, $stats) + { + $colsTitles = array(__('Mot'), __('Recherches')); + $lines = array(); + + foreach ($stats->searches->search as $search) { + $q = $search['query']; + if (strlen($q) > 25) { + $q = '' . substr($q, 0, 25) . ' ...'; + } + $lines[] = array($q, $search['count']); + } + self::setSheetFromDatas(__('Recherches'), $colsTitles, $lines); + return self::table(__('Mots les plus recherchés'), $colsTitles, $lines, array('liste', 'max')); + } + + public static function detailOrigine($book, $stats) + { + $colsTitles = array(__('Pays'), __('Visiteurs')); + $lines = array(); + $xlines = array(); + $i = 0; + + foreach ($stats->countries->country as $country) { + $pays = $country['code']; + $odd = cubeMath::isOdd($i) ? ' class="odd"' : ''; + if (!$c = cubeCountry::getCountry($pays)) { + $c = __('Origine inconnue'); + } + $lines[] = array(cubeCountry::getFlag($pays) . ' ' . ucfirst(mb_strtolower($c)), $country['visitors']); + $xlines[] = array(ucfirst(mb_strtolower($c)), $country['visitors']); + $i++; + } + self::setSheetFromDatas(__('Origines'), $colsTitles, $xlines); + return self::table(__('Origine des visiteurs'), $colsTitles, $lines, array('liste', 'max')); + } + + public static function getQ($max, &$maxp, &$maxpages, &$s) + { + $maxpages = $maxp; + $q = 1; + $maxp /= $q; + $maxp = max($max * 4, $maxp); + $q = $maxpages / $maxp; + foreach ($s as $time => $t) { + $s[$time]['page'] = intval($s[$time]['page'] / $q); + } + } + + public static function graph_annuel($bid, $a, $stats) + { + $img = SYSIMG . '/stats/annuel-' . $a . '-' . $bid . '.png'; + $imgw = IMG . '/stats/annuel-' . $a . '-' . $bid . '.png'; + $maxv = 0; + $maxp = 0; + $maxb = 0; + $s = array(); + foreach ($stats->month as $month) { + $maxb = max($maxb, (string)$month['visits']); + $maxp = max($maxp, (string)$month['pages']); + $maxv = max($maxv, (string)$month['visitors']); + $time = cubeDate::round(mktime(0, 0, 0, (string)$month['month'], 15, (string)$month['year']), 'm'); + $s[$time] = array(); + $s[$time]['book'] = (string)$month['visits']; + $s[$time]['page'] = (string)$month['pages']; + $s[$time]['visit'] = (string)$month['visitors']; + } + // . + $max = max($maxb, $maxv); + self::getQ($max, $maxp, $maxpages, $s); + krsort($s); + $max = max($maxb, $maxv, $maxp); + $months = cubeDate::getMonths($a); + @unlink($img); + if (!file_exists($img) || filemtime($img) < cubeDate::round(null, 'H')) { + $im = imagecreatetruecolor(944, 306); + //imagelayereffect($im, IMG_EFFECT_REPLACE); + $trans = imagecolorallocatealpha($im, 255, 255, 255, 0); + imagefill($im, 0, 0, $trans); + //imagelayereffect($im, IMG_EFFECT_ALPHABLEND); + $i = 1; + $x0 = 0; + $y0 = 305; + $h = 300; + $c0 = imagecolorallocate($im, 0, 0, 0); + $c1 = imagecolorallocatealpha($im, 81, 78, 73, 64); + $hp = $h * ($maxp / $max) - 2; + $mhp = $y0 - $hp - 6; + imagesetstyle($im, array($c1, $c1, $c1, $c1, $c1, $trans, $trans, $trans, $trans)); + imageline($im, 0, $y0 - $hp, 944, $y0 - $hp, IMG_COLOR_STYLED); + $c1 = imagecolorallocate($im, 81, 78, 73); + $c2 = imagecolorallocatealpha($im, 245, 77, 0, 64); + $hb = $h * ($maxb / $max) - 1; + $mhb = $y0 - $hb - 6; + imagesetstyle($im, array($c2, $c2, $c2, $c2, $c2, $trans, $trans, $trans, $trans)); + imageline($im, 0, $y0 - $hb, 944, $y0 - $hb, IMG_COLOR_STYLED); + $c2 = imagecolorallocate($im, 245, 77, 0); + $c3 = imagecolorallocatealpha($im, 194, 211, 19, 32); + $hv = $h * ($maxv / $max); + $mhv = $y0 - $hv - 6; + imagesetstyle($im, array($c3, $c3, $c3, $c3, $c3, $trans, $trans, $trans, $trans)); + imageline($im, 0, $y0 - $hv, 944, $y0 - $hv, IMG_COLOR_STYLED); + $c3 = imagecolorallocate($im, 194, 211, 19); + foreach ($months as $m => $t) { + if (isset($s[$t])) { + $x0 += 15; + $hp = $h * ($s[$t]['page'] / $max) - 2; + $hb = $h * ($s[$t]['book'] / $max) - 1; + $hv = $h * ($s[$t]['visit'] / $max); + imagefilledrectangle($im, $x0 + 40, $y0 - $hp, $x0, $y0, $c1); + imagerectangle($im, $x0 + 40, $y0 - $hp, $x0, $y0, $c0); + $x0 += 5; + imagefilledrectangle($im, $x0 + 40, $y0 - $hb, $x0, $y0, $c2); + imagerectangle($im, $x0 + 40, $y0 - $hb, $x0, $y0, $c0); + $x0 += 5; + imagefilledrectangle($im, $x0 + 40, $y0 - $hv, $x0, $y0, $c3); + imagerectangle($im, $x0 + 40, $y0 - $hv, $x0, $y0, $c0); + $i++; + $x0 += 50; + } else { + $x0 += 75; + } + } + + imageline($im, 0, $y0, 944, $y0, $c0); + imagepng($im, $img); + } + $res = '
' . $maxpages . '
'; + $res .= '
' . $maxb . '
'; + $res .= '
' . $maxv . '
'; + $res .= '
'; + $res .= ''; + foreach ($months as $m => $t) { + $res .= ''; + } + $res .= ''; + $res .= '
' . strftime('%b %y', $t) . '' . cubeMedia::spacer(44, 20) . '
'; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= '
' . __('Pages vues') . '' . __('Visites') . '' . __('Visiteurs uniques') . '
'; + return $res; + } + + public static function graph_global($bid, $stats) + { + global $core; + $img = SYSIMG . '/stats/global-' . $bid . '.png'; + $imgw = IMG . '/stats/global-' . $bid . '.png'; + $s = array(); + foreach ($stats->year as $year) { + foreach ($year->month as $month) { + $time = mktime(0, 0, 0, intval((string)$month['month']), 15, (string)$month['year']); + $s[$time]['book'] = $month['visits']; + $s[$time]['page'] = $month['pages']; + $s[$time]['time'] = $time; + $s[$time]['visit'] = $month['visitors']; + } + } + + krsort($s); + $s = array_slice($s, 0, 12, true); + $maxv = 0; + $maxp = 0; + $maxb = 0; + foreach ($s as $time => $d) { + $maxb = max($maxb, (string)$d['book']); + $maxp = max($maxp, (string)$d['page']); + $maxv = max($maxv, (string)$d['visit']); + } + + $max = max($maxb, $maxv); + self::getQ($max, $maxp, $maxpages, $s); + $max = max($maxv, $maxb, $maxp, 1); + if (file_exists($img)) { + unlink($img); + } + if (!file_exists($img) || filemtime($img) < cubeDate::round(null, 'H')) { + $im = imagecreatetruecolor(944, 306); + //imagelayereffect($im, IMG_EFFECT_REPLACE); + $trans = imagecolorallocatealpha($im, 255, 255, 255, 0); + imagefill($im, 0, 0, $trans); + //imagelayereffect($im, IMG_EFFECT_ALPHABLEND); + $i = 1; + $x0 = 900; + $y0 = 305; + $h = 300; + $c0 = imagecolorallocate($im, 0, 0, 0); + $c1 = imagecolorallocatealpha($im, 81, 78, 73, 64); + $hp = $h * ($maxp / $max) - 2; + $mhp = $y0 - $hp - 6; + imagesetstyle($im, array($c1, $c1, $c1, $c1, $c1, $trans, $trans, $trans, $trans)); + imageline($im, 0, $y0 - $hp, 944, $y0 - $hp, IMG_COLOR_STYLED); + $c1 = imagecolorallocate($im, 81, 78, 73); + $c2 = imagecolorallocatealpha($im, 245, 77, 0, 64); + $hb = $h * ($maxb / $max) - 1; + $mhb = $y0 - $hb - 6; + imagesetstyle($im, array($c2, $c2, $c2, $c2, $c2, $trans, $trans, $trans, $trans)); + imageline($im, 0, $y0 - $hb, 944, $y0 - $hb, IMG_COLOR_STYLED); + $c2 = imagecolorallocate($im, 245, 77, 0); + $c3 = imagecolorallocatealpha($im, 194, 211, 19, 32); + $hv = $h * ($maxv / $max); + $mhv = $y0 - $hv - 6; + imagesetstyle($im, array($c3, $c3, $c3, $c3, $c3, $trans, $trans, $trans, $trans)); + imageline($im, 0, $y0 - $hv, 944, $y0 - $hv, IMG_COLOR_STYLED); + $c3 = imagecolorallocate($im, 194, 211, 19); + foreach ($s as $t) { + $x0 -= 15; + $hp = $h * ($t['page'] / $max) - 2; + $hb = $h * ($t['book'] / $max) - 1; + $hv = $h * ($t['visit'] / $max); + imagefilledrectangle($im, $x0 - 40, $y0 - $hp, $x0, $y0, $c1); + imagerectangle($im, $x0 - 40, $y0 - $hp, $x0, $y0, $c0); + $x0 -= 5; + imagefilledrectangle($im, $x0 - 40, $y0 - $hb, $x0, $y0, $c2); + imagerectangle($im, $x0 - 40, $y0 - $hb, $x0, $y0, $c0); + $x0 -= 5; + imagefilledrectangle($im, $x0 - 40, $y0 - $hv, $x0, $y0, $c3); + imagerectangle($im, $x0 - 40, $y0 - $hv, $x0, $y0, $c0); + $i++; + $x0 -= 50; + } + + imageline($im, 0, $y0, 944, $y0, $c0); + imagepng($im, $img); + } + $res = '
' . $maxpages . '
'; + $res .= '
' . $maxb . '
'; + $res .= '
' . $maxv . '
'; + $res .= '
'; + $s = array_reverse(array_pad($s, 12, false), true); + $res .= ''; + foreach ($s as $time => $val) { + if (!$val) { + $res .= ''; + } else { + $res .= ''; + } + } + $res .= ''; + $res .= '
' . cubeMedia::spacer(75, 20) . '' . strftime('%b %y', $val['time']) . '' . cubeMedia::spacer(44, 20) . '
'; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= '
' . __('Pages vues') . '' . __('Visites') . '' . __('Visiteurs uniques') . '
'; + return $res; + } + + public static function graph_mensuel($bid, $a, $m, $stats) + { + $img = SYSIMG . '/stats/mensuel-' . $a . '-' . $m . '-' . $bid . '.png'; + $imgw = IMG . '/stats/mensuel-' . $a . '-' . $m . '-' . $bid . '.png'; + $lm = cubeDate::limitMonth($a, $m); + $datestocorrect = array(mktime(0, 0, 0, 11, 23, 2009), mktime(0, 0, 0, 12, 8, 2009), mktime(0, 0, 0, 12, 9, 2009)); + $maxv = 0; + $maxp = 0; + $maxb = 0; + $v = array(); + $s = array(); + foreach ($stats->days->day as $day) { + $time = mktime(0, 0, 0, $m, (string)$day['day'], $a); + $maxb = max($maxb, (string)$day['visits']); + $maxp = max($maxp, (string)$day['views']); + $maxv = max($maxv, (string)$day['visitors']); + $s[$time]['book'] = $day['visits']; + $s[$time]['page'] = $day['views']; + $s[$time]['visit'] = $day['visitors']; + $s[$time]['time'] = $time; + } + $max = max($maxb, $maxv); + self::getQ($max, $maxp, $maxpages, $s); + krsort($s); + $max = max($maxv, $maxb, $maxp); + $days = cubeDate::getDays($a, $m); + $space = round((900 - (count($days) * 20)) / (count($days) * 2)); + @unlink($img); + if (!file_exists($img) || filemtime($img) < cubeDate::round(null, 'H')) { + // Création de l'image + $im = imagecreatetruecolor(944, 306); + //imagelayereffect($im, IMG_EFFECT_REPLACE); + $trans = imagecolorallocatealpha($im, 255, 255, 255, 0); + imagefill($im, 0, 0, $trans); + //imagelayereffect($im, IMG_EFFECT_ALPHABLEND); + $i = 1; + $x0 = 0; + $y0 = 305; + $h = 300; + $c0 = imagecolorallocate($im, 0, 0, 0); + $c1 = imagecolorallocatealpha($im, 81, 78, 73, 64); + $hp = $h * ($maxp / $max) - 2; + $mhp = $y0 - $hp - 6; + imagesetstyle($im, array($c1, $c1, $c1, $c1, $c1, $trans, $trans, $trans, $trans)); + imageline($im, 0, $y0 - $hp, 944, $y0 - $hp, IMG_COLOR_STYLED); + $c1 = imagecolorallocate($im, 81, 78, 73); + $c2 = imagecolorallocatealpha($im, 245, 77, 0, 64); + $hb = $h * ($maxb / $max) - 1; + $mhb = $y0 - $hb - 6; + imagesetstyle($im, array($c2, $c2, $c2, $c2, $c2, $trans, $trans, $trans, $trans)); + imageline($im, 0, $y0 - $hb, 944, $y0 - $hb, IMG_COLOR_STYLED); + $c2 = imagecolorallocate($im, 245, 77, 0); + $c3 = imagecolorallocatealpha($im, 194, 211, 19, 32); + $hv = $h * ($maxv / $max); + $mhv = $y0 - $hv - 6; + imagesetstyle($im, array($c3, $c3, $c3, $c3, $c3, $trans, $trans, $trans, $trans)); + imageline($im, 0, $y0 - $hv, 944, $y0 - $hv, IMG_COLOR_STYLED); + $c3 = imagecolorallocate($im, 194, 211, 19); + foreach ($days as $d => $t) { + if (isset($s[$t])) { + $x0 += $space; + $hp = $h * ($s[$t]['page'] / $max) - 2; + $hb = $h * ($s[$t]['book'] / $max) - 1; + $hv = $h * ($s[$t]['visit'] / $max); + imagefilledrectangle($im, $x0 + 14, $y0 - $hp, $x0, $y0, $c1); + imagerectangle($im, $x0 + 14, $y0 - $hp, $x0, $y0, $c0); + $x0 += 3; + imagefilledrectangle($im, $x0 + 14, $y0 - $hb, $x0, $y0, $c2); + imagerectangle($im, $x0 + 14, $y0 - $hb, $x0, $y0, $c0); + $x0 += 3; + imagefilledrectangle($im, $x0 + 14, $y0 - $hv, $x0, $y0, $c3); + imagerectangle($im, $x0 + 14, $y0 - $hv, $x0, $y0, $c0); + $i++; + $x0 += 14 + $space; + } else { + $x0 += 20 + $space * 2; + } + } + + imageline($im, 0, $y0, 944, $y0, $c0); + imagepng($im, $img); + } + $res = '
' . $maxpages . '
'; + $res .= '
' . $maxb . '
'; + $res .= '
' . $maxv . '
'; + $res .= '
'; + $res .= ''; + foreach ($days as $d => $t) { + $res .= ''; + } + $spacef = 944 - (count($days) * (20 + ($space * 2))); + $res .= ''; + $res .= '
' . $d . '' . cubeMedia::spacer($spacef, 20) . '
'; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= '
' . __('Pages vues') . '' . __('Visites') . '' . __('Visiteurs uniques') . '
'; + return $res; + } + + public static function forceComputation($id) + { + `/home/stats/www/FWStats.sh /home/stats/www onlybook=$id`; + } } \ No newline at end of file