--- /dev/null
+<?php\r
+class wsStats {\r
+ public static $datestocorrect = array(array(22, 11, 2009), array(23, 11, 2009), array(8, 12, 2009), array(9, 12, 2009));\r
+ /*\r
+ if (in_array($dd, $datestocorrect)) {\r
+ $d->book = round($d->visitor * 1.2);\r
+ }*/\r
+ public static function display($bid, $annee = null, $mois = null)\r
+ {\r
+ wsDroits::viewBook($bid);\r
+ cubePHP::set_memory('512M');\r
+ if (is_null($annee) && is_null($mois)) {\r
+ return self::vue_globale($bid);\r
+ }\r
+ if (is_null($mois)) {\r
+ return self::vue_annuelle($bid, $annee);\r
+ }\r
+ return self::vue_mensuelle($bid, $annee, $mois);\r
+ }\r
+\r
+ public static function getExtra($extra)\r
+ {\r
+ $xml = simplexml_load_string('<extra>' . $extra . '</extra>');\r
+ if ((string)$xml->extraName != '') {\r
+ return (string)$xml->extraName;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ public static function load_stats($bid, $annee = null, $mois = null)\r
+ {\r
+ $root = WS_STATS . 'xml/' . $bid;\r
+ if (is_null($annee)) {\r
+ $xml = $root;\r
+ $sort = 'globalSort';\r
+ } else if (is_null($mois)) {\r
+ $xml = $root . '/' . $annee;\r
+ $sort = 'yearSort';\r
+ } else {\r
+ $xml = $root . '/' . $annee . '/' . $mois;\r
+ $sort = 'monthSort';\r
+ }\r
+ $xml = rtrim($xml, '/');\r
+ $xml .= '.xml';\r
+ if ($x = @simplexml_load_file($xml)) {\r
+ if (!is_null($mois)) {\r
+ }\r
+ $x = call_user_func(array('wsStats', $sort), $x);\r
+ self::correctValues($x, $annee, $mois);\r
+ return $x;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ public static function correctValues($x, $y, $m)\r
+ {\r
+ foreach(self::$datestocorrect as $date) {\r
+ if ($date[2] != $y || $date[1] != $m) {\r
+ continue;\r
+ }\r
+ fb($y, $m);\r
+ $days = $x->xpath("//day[@day=" . $date[0] . "]");\r
+ foreach($days as $day) {\r
+ break;\r
+ }\r
+ $visitors = (string)$day['places'] * 1.2;\r
+ $visits = $visitors * 1.1;\r
+ cubeXML::removeAttribute($day, 'visitors');\r
+ cubeXML::removeAttribute($day, 'visits');\r
+ $day->addAttribute('visitors', $visitors);\r
+ $day->addAttribute('visits', $visits);\r
+ }\r
+ }\r
+\r
+ public static function correctPlaces($x)\r
+ {\r
+ }\r
+\r
+ public static function globalSort($xml, $root = 'stats')\r
+ {\r
+ $res = simplexml_load_string('<' . $root . ' />');\r
+ foreach($xml->attributes() as $k => $v) {\r
+ $res->addAttribute($k, $v);\r
+ }\r
+ $years = array();\r
+ foreach($xml->year as $year) {\r
+ $years[(string)$year['year']] = self::yearSort($year, 'year');\r
+ }\r
+ ksort($years);\r
+ foreach($years as $y) {\r
+ cubeXML::append($res, $y);\r
+ }\r
+ return $res;\r
+ }\r
+\r
+ public static function yearSort($xml, $root = 'stats')\r
+ {\r
+ $res = simplexml_load_string('<' . $root . ' />');\r
+ foreach($xml->attributes() as $k => $v) {\r
+ $res->addAttribute($k, $v);\r
+ }\r
+ $months = array();\r
+ foreach($xml->month as $month) {\r
+ $months[(string)$month['month']] = $month;\r
+ }\r
+\r
+ ksort($months);\r
+ foreach($months as $month) {\r
+ cubeXML::append($res, $month);\r
+ }\r
+\r
+ return $res;\r
+ }\r
+\r
+ public static function monthSort($xml, $root = 'stats')\r
+ {\r
+ $res = simplexml_load_string('<' . $root . ' />');\r
+ foreach($xml->attributes() as $k => $v) {\r
+ $res->addAttribute($k, $v);\r
+ }\r
+ self::daysSort($xml, $res);\r
+ self::pagesSort($xml, $res);\r
+ self::linksSort($xml, $res);\r
+ self::searchesSort($xml, $res);\r
+ self::countriesSort($xml, $res);\r
+\r
+ return $res;\r
+ }\r
+\r
+ public static function daysSort($xml, $res)\r
+ {\r
+ $x = $res->addChild('days');\r
+ $days = array();\r
+ foreach($xml->days->day as $day) {\r
+ $days[(string)$day['day']] = $day;\r
+ }\r
+ ksort($days);\r
+ foreach($days as $day) {\r
+ $places = (string)$day['places'];\r
+ if ($places == 1) {\r
+ $visitors = (string)$day['visitors'];\r
+ if ($visitors > 10) {\r
+ cubeXML::removeAttribute($day, 'places');\r
+ $day->addAttribute('places', round($visitors * 0.99));\r
+ }\r
+ }\r
+ cubeXML::append($x, $day);\r
+ }\r
+ }\r
+\r
+ public static function pagesSort($xml, $res)\r
+ {\r
+ $xpages = $res->addChild('pages');\r
+ $pages = array();\r
+ $trans = array();\r
+ foreach($xml->pages->page as $page) {\r
+ $pages[(string)$page['page']] = (string)$page['score'];\r
+ $trans[(string)$page['page']] = $page;\r
+ }\r
+ arsort($pages);\r
+ foreach($pages as $num => $score) {\r
+ cubeXML::append($xpages, $trans[$num]);\r
+ }\r
+ }\r
+\r
+ public static function linksSort($xml, $res)\r
+ {\r
+ $x = $res->addChild('links');\r
+ $links = array();\r
+ $trans = array();\r
+ foreach($xml->links->link as $link) {\r
+ $links[(string)$link['url']] = (string)$link['click'];\r
+ $trans[(string)$link['url']] = $link;\r
+ }\r
+ arsort($links);\r
+ $links = array_slice($links, 0, 100, true);\r
+ foreach($links as $url => $click) {\r
+ cubeXML::append($x, $trans[$url]);\r
+ }\r
+ }\r
+\r
+ public static function searchesSort($xml, $res)\r
+ {\r
+ $x = $res->addChild('searches');\r
+ $searches = array();\r
+ $trans = array();\r
+ foreach($xml->searches->search as $search) {\r
+ $searches[(string)$search['query']] = (string)$search['count'];\r
+ $trans[(string)$search['query']] = $search;\r
+ }\r
+ arsort($searches);\r
+ $searches = array_slice($searches, 0, 100, true);\r
+ foreach($searches as $q => $count) {\r
+ cubeXML::append($x, $trans[$q]);\r
+ }\r
+ }\r
+\r
+ public static function countriesSort($xml, $res)\r
+ {\r
+ $x = $res->addChild('countries');\r
+ $countries = array();\r
+ $trans = array();\r
+ foreach($xml->countries->country as $country) {\r
+ $countries[(string)$country['code']] = (string)$country['visitors'];\r
+ $trans[(string)$country['code']] = $country;\r
+ }\r
+ arsort($countries);\r
+ foreach($countries as $code => $visitors) {\r
+ cubeXML::append($x, $trans[$code]);\r
+ }\r
+ }\r
+\r
+ public static function getActives($stats, $rr, &$aextra, &$adown, &$adownp, &$aprint, &$afriend)\r
+ {\r
+ $extra = self::getExtra($rr->extras);\r
+ $aextra = ($extra != null && $stats['extras'] > 0);\r
+ $adown = ($rr->pdf == 1 && $stats['downloads'] > 0);\r
+ $adownp = ($rr->pdf == 1 && $rr->pdfComplex == 1 && $stats['partDownloads'] > 0);\r
+ $aprint = ($rr->print == 1);\r
+ $afriend = ($rr->friend == 1);\r
+ }\r
+\r
+ public static function globalDatas($date_creation, $rr, $stats, $afriend, $aprint, $adown, $adownp, $aextra)\r
+ {\r
+ $res = '<table class="liste max">';\r
+ $res .= '<tr><td>' . $date_creation . '</td><td class="stats_col">' . date(__('d-m-Y'), $rr->date) . '</td></tr>';\r
+\r
+ $res .= '<tr><td>' . __('Nombre de lieux de visite') . '</td><td class="stats_col">' . $stats['places'] . '</td></tr>';\r
+ $res .= '<tr><td>' . __('Nombre de visiteurs uniques') . '</td><td class="stats_col">' . $stats['visitors'] . '</td></tr>';\r
+ $res .= '<tr><td>' . __('Nombre de visites') . '</td><td class="stats_col">' . $stats['visits'] . '</td></tr>';\r
+\r
+ $res .= '<tr><td>' . __('Nombre de pages vues') . '</td><td class="stats_col">' . $stats['pages'] . '</td></tr>';\r
+ if ($afriend) {\r
+ $res .= '<tr><td>' . __('Nombre de liens envoyés') . '</td><td class="stats_col">' . $stats['friends'] . '</td></tr>';\r
+ }\r
+ $res .= '<tr><td>' . __('Nombre de liens cliqués') . '</td><td class="stats_col">' . $stats['links'] . '</td></tr>';\r
+ if ($aprint) {\r
+ $res .= '<tr><td>' . __("Nombre d'impressions") . '</td><td class="stats_col">' . $stats['prints'] . '</td></tr>';\r
+ }\r
+ if ($adown) {\r
+ $res .= '<tr><td>' . __('Nombre de téléchargements') . '</td><td class="stats_col">' . $stats['downloads'] . '</td></tr>';\r
+ }\r
+ if ($adownp) {\r
+ $res .= '<tr><td>' . __('Nombre de téléchargements partiels') . '</td><td class="stats_col">' . $stats['partDownloads'] . '</td></tr>';\r
+ }\r
+ if ($aextra) {\r
+ $res .= '<tr><td>' . __('Accès à la rubrique') . ' ' . $extra . '</td><td class="stats_col">' . $stats['extras'] . '</td></tr>';\r
+ }\r
+ $res .= '</table>';\r
+ return $res;\r
+ }\r
+\r
+ public static function indisponible()\r
+ {\r
+ $res = wsPage::bh('stats_global');\r
+ $res .= '<p class="center">' . __('Les statistiques concernant cette période ne sont actuellement pas disponibles') . '</p>';\r
+ $res .= wsPage::bf();\r
+ return $res;\r
+ }\r
+\r
+ public static function vue_globale($bid, $annee = null)\r
+ {\r
+ global $core;\r
+ $rr = $core->con->select('SELECT * FROM book WHERE bid=' . $bid);\r
+\r
+ $extra = self::getExtra($rr->extras);\r
+\r
+ if (is_null($annee)) {\r
+ $stats = self::load_stats($bid);\r
+ } else {\r
+ $stats = self::load_stats($bid, $annee);\r
+ }\r
+\r
+ if (is_null($stats)) {\r
+ return self::indisponible();\r
+ }\r
+\r
+ self::getActives($stats, $rr, $aextra, $adown, $adownp, $aprint, $afriend);\r
+\r
+ $res = wsPage::bh('stats_global');\r
+ $titre = ($_SESSION['white'])?__('Statistiques de la publication « %s »'):__('Statistiques du fluidbook « %s »');\r
+ $date_creation = ($_SESSION['white'])? __('Date de création de la publication'): __('Date de création du fluidbook');\r
+ $res .= cubeTypographp::typographp(array('texte' => mb_strtoupper(sprintf($titre, $rr->titre))), 'hache2');\r
+ $res .= self::globalDatas($date_creation, $rr, $stats, $afriend, $aprint, $adown, $adownp, $aextra);\r
+ $res .= wsPage::bf();\r
+\r
+ $res .= wsPage::bh('stats_detail_mois');\r
+ $res .= cubeTypographp::typographp(array('texte' => mb_strtoupper(sprintf(__('Détail par mois'), $rr->titre))), 'hache2');\r
+ $res .= '<div class="center" style="width:944px;margin:0 auto;position:relative;">' ;\r
+ if (is_null($annee)) {\r
+ $res .= self::graph_global($bid, $stats);\r
+ } else {\r
+ $res .= self::graph_annuel($bid, $annee, $stats);\r
+ }\r
+ $res .= '</div>';\r
+ $res .= '<table class="liste max">';\r
+ $res .= '<tr><th>' . __('Période') . '</th>';\r
+ $res .= '<th class="stats_col">' . __('Lieux de visite') . '</th>';\r
+ $res .= '<th class="stats_col">' . __('Visiteurs uniques') . '</th>';\r
+ $res .= '<th class="stats_col">' . __('Visites') . '</th>';\r
+ $res .= '<th class="stats_col">' . __('Pages vues') . '</th>';\r
+ if ($afriend) {\r
+ $res .= '<th class="stats_col">' . __('Liens envoyés') . '</th>';\r
+ }\r
+ $res .= '<th class="stats_col">' . __('Liens cliqués') . '</th>';\r
+ if ($aprint) {\r
+ $res .= '<th class="stats_col">' . __('Impressions') . '</th>';\r
+ }\r
+ if ($adown) {\r
+ $res .= '<th class="stats_col">' . __('Téléchargements') . '</th>';\r
+ }\r
+ if ($adownp) {\r
+ $res .= '<th class="stats_col">' . __('Téléchargements partiels') . '</th>';\r
+ }\r
+ if ($aextra) {\r
+ $res .= '<th class="stats_col">' . $extra . '</th>';\r
+ }\r
+\r
+ $res .= '</tr>';\r
+\r
+ if (is_null($annee)) {\r
+ $years = $stats->year;\r
+ } else {\r
+ $years = array($stats);\r
+ }\r
+\r
+ foreach($years as $year) {\r
+ if (is_null($annee)) {\r
+ $res .= '<tr><td><strong><a href="' . SITE_PATH . 'stats/' . $bid . '/' . $year['year'] . '">' . $year['year'] . '</a></strong></td>';\r
+ $res .= '<td class="stats_col">' . $year['places'] . '</td>';\r
+ $res .= '<td class="stats_col"><strong>' . $year['visitors'] . '</strong></td>';\r
+ $res .= '<td class="stats_col"><strong>' . $year['visits'] . '</strong></td>';\r
+ $res .= '<td class="stats_col"><strong>' . $year['pages'] . '</strong></td>';\r
+ if ($afriend) {\r
+ $res .= '<td class="stats_col"><strong>' . $year['friends'] . '</strong></td>';\r
+ }\r
+ $res .= '<td class="stats_col"><strong>' . $year['links'] . '<strong></td>';\r
+ if ($aprint) {\r
+ $res .= '<td class="stats_col"><strong>' . $year['prints'] . '</strong></td>';\r
+ }\r
+ if ($adown) {\r
+ $res .= '<td class="stats_col"><strong>' . $year['downloads'] . '</strong></td>';\r
+ }\r
+ if ($adownp) {\r
+ $res .= '<td class="stats_col"><strong>' . $year['partDownloads'] . '</strong></td>';\r
+ }\r
+ if ($aextra) {\r
+ $res .= '<td class="stats_col"><strong>' . $year['extras'] . '</strong></td>';\r
+ }\r
+ $res .= '</tr>';\r
+ }\r
+ foreach($year->month as $month) {\r
+ $res .= '<tr><td><a href="' . SITE_PATH . 'stats/' . $bid . '/' . $month['year'] . '/' . $month['month'] . '">' . strftime('%B %Y', mktime(0, 0, 0, (string)$month['month'], 15, (string)$month['year'])) . '</a></td>';\r
+\r
+ $res .= '<td class="stats_col">' . $month['places'] . '</td>';\r
+ $res .= '<td class="stats_col">' . $month['visitors'] . '</td>';\r
+ $res .= '<td class="stats_col">' . $month['visits'] . '</td>';\r
+ $res .= '<td class="stats_col">' . $month['pages'] . '</td>';\r
+ if ($afriend) {\r
+ $res .= '<td class="stats_col">' . $month['friends'] . '</td>';\r
+ }\r
+ $res .= '<td class="stats_col">' . $month['links'] . '</td>';\r
+ if ($aprint) {\r
+ $res .= '<td class="stats_col">' . $month['prints'] . '</td>';\r
+ }\r
+ if ($adown) {\r
+ $res .= '<td class="stats_col">' . $month['downloads'] . '</td>';\r
+ }\r
+ if ($adownp) {\r
+ $res .= '<td class="stats_col">' . $month['partDownloads'] . '</td>';\r
+ }\r
+ if ($aextra) {\r
+ $res .= '<td class="stats_col">' . $month['extras'] . '</td>';\r
+ }\r
+ $res .= '</tr>';\r
+ }\r
+ }\r
+ $res .= '</table>';\r
+ $res .= wsPage::bf();\r
+ return $res;\r
+ }\r
+\r
+ public static function graph_global($bid, $stats)\r
+ {\r
+ wsDroits::viewBook($bid);\r
+ global $core;\r
+ $img = ROOT . '/images/stats/global-' . $bid . '.png';\r
+ $imgw = WEBROOT . '/images/stats/global-' . $bid . '.png';\r
+\r
+ $s = array();\r
+ foreach ($stats->year as $year) {\r
+ foreach($year->month as $month) {\r
+ $time = mktime(0, 0, 0, intval((string)$month['month']), 15, (string)$month['year']);\r
+ $s[$time]['book'] = $month['visits'];\r
+ $s[$time]['page'] = $month['pages'];\r
+ $s[$time]['time'] = $time;\r
+ $s[$time]['visit'] = $month['visitors'];\r
+ }\r
+ }\r
+ fb($s);\r
+ krsort($s);\r
+ $s = array_slice($s, 0, 12, true);\r
+ // $s = array_reverse($s);\r
+ fb($s);\r
+ $maxv = 0;\r
+ $maxp = 0;\r
+ $maxb = 0;\r
+ foreach($s as $time => $d) {\r
+ $maxb = max($maxb, (string) $d['book']);\r
+ $maxp = max($maxp, (string)$d['page']);\r
+ $maxv = max($maxv, (string) $d['visit']);\r
+ }\r
+\r
+ $max = max($maxb, $maxv);\r
+ self::getQ($bid, $max, $maxp, $maxpages, $s);\r
+ $max = max($maxv, $maxb, $maxp, 1);\r
+ if (file_exists($img)) {\r
+ unlink($img);\r
+ }\r
+ if (!file_exists($img) || filemtime($img) < cubeDate::round(null, 'H')) {\r
+ $im = imagecreatetruecolor(944, 306);\r
+ imagelayereffect($im, IMG_EFFECT_REPLACE);\r
+ $trans = imagecolorallocatealpha($im, 244, 244, 241, 0);\r
+ imagefill($im, 0, 0, $trans);\r
+ imagelayereffect($im, IMG_EFFECT_ALPHABLEND);\r
+ $i = 1;\r
+ $x0 = 900;\r
+ $y0 = 305;\r
+ $h = 300;\r
+ $c0 = imagecolorallocate($im, 0, 0 , 0);\r
+ $c1 = imagecolorallocatealpha($im, 81, 78, 73, 64);\r
+ $hp = $h * ($maxp / $max)-2;\r
+ $mhp = $y0 - $hp-6;\r
+ imagesetstyle($im, array($c1, $c1, $c1, $c1, $c1, $trans, $trans, $trans, $trans));\r
+ imageline($im, 0, $y0 - $hp, 944, $y0 - $hp, IMG_COLOR_STYLED);\r
+ $c1 = imagecolorallocate($im, 81, 78, 73);\r
+ $c2 = imagecolorallocatealpha($im, 245, 77, 0, 64);\r
+ $hb = $h * ($maxb / $max)-1;\r
+ $mhb = $y0 - $hb-6;\r
+ imagesetstyle($im, array($c2, $c2, $c2, $c2, $c2, $trans, $trans, $trans, $trans));\r
+ imageline($im, 0, $y0 - $hb, 944, $y0 - $hb, IMG_COLOR_STYLED);\r
+ $c2 = imagecolorallocate($im, 245, 77, 0);\r
+ $c3 = imagecolorallocatealpha($im, 194, 211, 19, 32);\r
+ $hv = $h * ($maxv / $max);\r
+ $mhv = $y0 - $hv-6;\r
+ imagesetstyle($im, array($c3, $c3, $c3, $c3, $c3, $trans, $trans, $trans, $trans));\r
+ imageline($im, 0, $y0 - $hv, 944, $y0 - $hv, IMG_COLOR_STYLED);\r
+ $c3 = imagecolorallocate($im, 194, 211, 19);\r
+ foreach($s as $t) {\r
+ $x0 -= 15;\r
+ $hp = $h * ($t['page'] / $max)-2;\r
+ $hb = $h * ($t['book'] / $max)-1;\r
+ $hv = $h * ($t['visit'] / $max);\r
+ imagefilledrectangle($im, $x0-40, $y0 - $hp, $x0, $y0, $c1);\r
+ imagerectangle($im, $x0-40, $y0 - $hp, $x0, $y0, $c0);\r
+ $x0 -= 5;\r
+ imagefilledrectangle($im, $x0-40, $y0 - $hb, $x0, $y0, $c2);\r
+ imagerectangle($im, $x0-40, $y0 - $hb, $x0, $y0, $c0);\r
+ $x0 -= 5;\r
+ imagefilledrectangle($im, $x0-40, $y0 - $hv, $x0, $y0, $c3);\r
+ imagerectangle($im, $x0-40, $y0 - $hv, $x0, $y0, $c0);\r
+ $i++;\r
+ $x0 -= 50;\r
+ }\r
+\r
+ imageline($im, 0 , $y0, 944 , $y0 , $c0);\r
+ imagepng($im, $img);\r
+ }\r
+ $res = '<div style="position:absolute;top:' . $mhp . 'px;left:900px;color:#514e49;background:#f4f4f1;padding-left:2px;padding-right:2px;">' . $maxpages . '</div>';\r
+ $res .= '<div style="position:absolute;top:' . $mhb . 'px;left:900px;color:#f54d00;background:#f4f4f1;padding-left:2px;padding-right:2px;">' . $maxb . '</div>';\r
+ $res .= '<div style="position:absolute;top:' . $mhv . 'px;left:900px;color:#c2d313;background:#f4f4f1;padding-left:2px;padding-right:2px;">' . $maxv . '</div>';\r
+ $res .= '<img src="' . $imgw . '" alt="' . __('Statistiques globales') . '" />';\r
+ $s = array_reverse(array_pad($s, 12, false), true);\r
+ $res .= '<table style="width:944px;max-width:944px;"><tr>';\r
+ foreach($s as $time => $val) {\r
+ if (!$val) {\r
+ $res .= '<td style="width:75px;max-width:75px;">' . cubeMedia::spacer(75, 20) . '</td>';\r
+ } else {\r
+ $res .= '<td style="width:75px;max-width:75px;">' . strftime('%b %y', $val['time']) . '</td>';\r
+ }\r
+ }\r
+ $res .= '<td style="width:44px;">' . cubeMedia::spacer(44, 20) . '</td>';\r
+ $res .= '</tr></table>';\r
+ $res .= '<table style="margin-top:10px;margin-bottom:10px;"><tr>';\r
+ $res .= '<td style="width:12px;background:#514e49;height:12px;"></td><td style="width:10px;"></td><td>' . __('Pages vues') . '</td><td style="width:10px;"></td>';\r
+ $res .= '<td style="width:12px;background:#f54d00;height:12px;"></td><td style="width:10px;"></td><td>' . __('Visites') . '</td><td style="width:10px;"></td>';\r
+ $res .= '<td style="width:12px;background:#c2d313;height:12px;"></td><td style="width:10px;"></td><td>' . __('Visiteurs uniques') . '</td><td style="width:10px;"></td>';\r
+ $res .= '</tr></table>';\r
+ return $res;\r
+ }\r
+\r
+ /**\r
+ * wsStats::vue_annuelle()\r
+ *\r
+ * @param mixed $bid\r
+ * @param mixed $annee\r
+ * @return\r
+ */\r
+ public static function vue_annuelle($bid, $annee)\r
+ {\r
+ return self::vue_globale($bid, $annee);\r
+ }\r
+\r
+ public static function getQ($bid, $max, &$maxp, &$maxpages, &$s)\r
+ {\r
+ global $core;\r
+ $rrr = $core->con->select('SELECT pages FROM book WHERE bid=' . $bid);\r
+ $maxpages = $maxp;\r
+ $q = max($rrr->pages / 5, 1);\r
+ $maxp /= $q;\r
+ $maxp = max($max * 4, $maxp);\r
+ $q = $maxpages / $maxp;\r
+ foreach($s as $time => $t) {\r
+ $s[$time]['page'] = intval($s[$time]['page'] / $q);\r
+ }\r
+ }\r
+\r
+ public static function graph_annuel($bid, $a, $stats)\r
+ {\r
+ wsDroits::viewBook($bid);\r
+ global $core;\r
+ $img = ROOT . '/images/stats/annuel-' . $a . '-' . $bid . '.png';\r
+ $imgw = WEBROOT . '/images/stats/annuel-' . $a . '-' . $bid . '.png';\r
+ $maxv = 0;\r
+ $maxp = 0;\r
+ $maxb = 0;\r
+ $s = array();\r
+ foreach ($stats->month as $month) {\r
+ $maxb = max($maxb, (string)$month['visits']);\r
+ $maxp = max($maxp, (string) $month['pages']);\r
+ $maxv = max($maxv, (string)$month['visitors']);\r
+ $time = cubeDate::round(mktime(0, 0, 0, (string)$month['month'], 15, (string)$month['year']), 'm');\r
+ $s[$time] = array();\r
+ $s[$time]['book'] = (string)$month['visits'];\r
+ $s[$time]['page'] = (string)$month['pages'];\r
+ $s[$time]['visit'] = (string) $month['visitors'];\r
+ }\r
+ // .\r
+ $max = max($maxb, $maxv);\r
+ self::getQ($bid, $max, $maxp, $maxpages, $s);\r
+ krsort($s);\r
+ $max = max($maxb, $maxv, $maxp);\r
+ $months = cubeDate::getMonths($a);\r
+ @unlink($img);\r
+ if (!file_exists($img) || filemtime($img) < cubeDate::round(null, 'H')) {\r
+ $im = imagecreatetruecolor(944, 306);\r
+ imagelayereffect($im, IMG_EFFECT_REPLACE);\r
+ $trans = imagecolorallocatealpha($im, 244, 244, 241, 0);\r
+ imagefill($im, 0, 0, $trans);\r
+ imagelayereffect($im, IMG_EFFECT_ALPHABLEND);\r
+ $i = 1;\r
+ $x0 = 0;\r
+ $y0 = 305;\r
+ $h = 300;\r
+ $c0 = imagecolorallocate($im, 0, 0 , 0);\r
+ $c1 = imagecolorallocatealpha($im, 81, 78, 73, 64);\r
+ $hp = $h * ($maxp / $max)-2;\r
+ $mhp = $y0 - $hp-6;\r
+ imagesetstyle($im, array($c1, $c1, $c1, $c1, $c1, $trans, $trans, $trans, $trans));\r
+ imageline($im, 0, $y0 - $hp, 944, $y0 - $hp, IMG_COLOR_STYLED);\r
+ $c1 = imagecolorallocate($im, 81, 78, 73);\r
+ $c2 = imagecolorallocatealpha($im, 245, 77, 0, 64);\r
+ $hb = $h * ($maxb / $max)-1;\r
+ $mhb = $y0 - $hb-6;\r
+ imagesetstyle($im, array($c2, $c2, $c2, $c2, $c2, $trans, $trans, $trans, $trans));\r
+ imageline($im, 0, $y0 - $hb, 944, $y0 - $hb, IMG_COLOR_STYLED);\r
+ $c2 = imagecolorallocate($im, 245, 77, 0);\r
+ $c3 = imagecolorallocatealpha($im, 194, 211, 19, 32);\r
+ $hv = $h * ($maxv / $max);\r
+ $mhv = $y0 - $hv-6;\r
+ imagesetstyle($im, array($c3, $c3, $c3, $c3, $c3, $trans, $trans, $trans, $trans));\r
+ imageline($im, 0, $y0 - $hv, 944, $y0 - $hv, IMG_COLOR_STYLED);\r
+ $c3 = imagecolorallocate($im, 194, 211, 19);\r
+ foreach($months as $m => $t) {\r
+ if (isset($s[$t])) {\r
+ $x0 += 15;\r
+ $hp = $h * ($s[$t]['page'] / $max)-2;\r
+ $hb = $h * ($s[$t]['book'] / $max)-1;\r
+ $hv = $h * ($s[$t]['visit'] / $max);\r
+ imagefilledrectangle($im, $x0 + 40, $y0 - $hp, $x0, $y0, $c1);\r
+ imagerectangle($im, $x0 + 40, $y0 - $hp, $x0, $y0, $c0);\r
+ $x0 += 5;\r
+ imagefilledrectangle($im, $x0 + 40, $y0 - $hb, $x0, $y0, $c2);\r
+ imagerectangle($im, $x0 + 40, $y0 - $hb, $x0, $y0, $c0);\r
+ $x0 += 5;\r
+ imagefilledrectangle($im, $x0 + 40, $y0 - $hv, $x0, $y0, $c3);\r
+ imagerectangle($im, $x0 + 40, $y0 - $hv, $x0, $y0, $c0);\r
+ $i++;\r
+ $x0 += 50;\r
+ } else {\r
+ $x0 += 75;\r
+ }\r
+ }\r
+\r
+ imageline($im, 0 , $y0, 944 , $y0 , $c0);\r
+ imagepng($im, $img);\r
+ }\r
+ $res = '<div style="position:absolute;top:' . $mhp . 'px;left:900px;color:#514e49;background:#f4f4f1;padding-left:2px;padding-right:2px;">' . $maxpages . '</div>';\r
+ $res .= '<div style="position:absolute;top:' . $mhb . 'px;left:900px;color:#f54d00;background:#f4f4f1;padding-left:2px;padding-right:2px;">' . $maxb . '</div>';\r
+ $res .= '<div style="position:absolute;top:' . $mhv . 'px;left:900px;color:#c2d313;background:#f4f4f1;padding-left:2px;padding-right:2px;">' . $maxv . '</div>';\r
+ $res .= '<img src="' . $imgw . '" alt="' . __('Statistiques annuelles') . '" />';\r
+ $res .= '<table style="width:944px;max-width:944px;table-layout:fixed;"><tr>';\r
+ foreach($months as $m => $t) {\r
+ $res .= '<td style="width:75px;max-width:75px;">' . strftime('%b %y', $t) . '</td>';\r
+ }\r
+ $res .= '<td style="width:44px;">' . cubeMedia::spacer(44, 20) . '</td>';\r
+ $res .= '</tr></table>';\r
+ $res .= '<table style="margin-top:10px;margin-bottom:10px;"><tr>';\r
+ $res .= '<td style="width:12px;background:#514e49;height:12px;"></td><td style="width:10px;"></td><td>' . __('Pages vues') . '</td><td style="width:10px;"></td>';\r
+ $res .= '<td style="width:12px;background:#f54d00;height:12px;"></td><td style="width:10px;"></td><td>' . __('Visites') . '</td><td style="width:10px;"></td>';\r
+ $res .= '<td style="width:12px;background:#c2d313;height:12px;"></td><td style="width:10px;"></td><td>' . __('Visiteurs uniques') . '</td><td style="width:10px;"></td>';\r
+ $res .= '</tr></table>';\r
+ return $res;\r
+ }\r
+\r
+ public static function vue_mensuelle($bid, $annee, $mois)\r
+ {\r
+ wsDroits::viewBook($bid);\r
+ $datestocorrect = array(mktime(0, 0, 0, 11, 23, 2009), mktime(0, 0, 0, 12, 8, 2009), mktime(0, 0, 0, 12, 9, 2009));\r
+ global $core;\r
+ $rr = $core->con->select('SELECT *,book.date AS date FROM book,user WHERE user.uid=book.uid AND bid=' . $bid);\r
+ $extra = self::getExtra($rr->extras);\r
+ $stats = self::load_stats($bid, $annee, $mois);\r
+\r
+ if (is_null($stats)) {\r
+ return self::indisponible();\r
+ }\r
+\r
+ self::getActives($stats, $rr, $aextra, $adown, $adownp, $aprint, $afriend);\r
+\r
+ $time_page = mktime(0, 0, 0, $mois, 15, $annee);\r
+ $res = wsPage::bh('stats_global');\r
+ $titre = ($_SESSION['white'])?__('Statistiques de la publication « %s »'):__('Statistiques du fluidbook « %s »');\r
+ $date_creation = ($_SESSION['white'])? __('Date de création de la publication'): __('Date de création du fluidbook');\r
+ $res .= cubeTypographp::typographp(array('texte' => mb_strtoupper(sprintf($titre, $rr->titre) . ' - ' . strftime('%B %Y', $time_page))), 'hache2');\r
+ $res .= self::globalDatas($date_creation, $rr, $stats, $afriend, $aprint, $adown, $adownp, $aextra);\r
+ $res .= wsPage::bf();\r
+ $res .= wsPage::bh('stats_detail_mois');\r
+ $res .= cubeTypographp::typographp(array('texte' => mb_strtoupper(__('Détail par jour') . ' - ' . strftime('%B %Y', $time_page))), 'hache2');\r
+ $res .= '<div class="center" style="width:944px;margin-top:10px;position:relative;">' . self::graph_mensuel($bid, $annee, $mois, $stats) . '</div>';\r
+ $res .= '<table class="liste max">';\r
+ $res .= '<tr><th>' . __('Jour') . '</th>';\r
+\r
+ $res .= '<th class="stats_col">' . __('Lieux de visite') . '</th>';\r
+\r
+ $res .= '<th class="stats_col">' . __('Visiteurs uniques') . '</th>';\r
+ $res .= '<th class="stats_col">' . __('Visites') . '</th>';\r
+ $res .= '<th class="stats_col">' . __('Pages vues') . '</th>';\r
+ $res .= '<th class="stats_col">' . __('Liens cliqués') . '</th>';\r
+ $res .= '</tr>';\r
+\r
+ foreach ($stats->days->day as $day) {\r
+ $res .= '<tr><td>' . strftime('%A %d', mktime(0, 0, 0, $mois, (string)$day['day'], $annee)) . '</td>';\r
+\r
+ $res .= '<td class="stats_col">' . $day['places'] . '</td>';\r
+ $res .= '<td class="stats_col">' . $day['visitors'] . '</td>';\r
+ $res .= '<td class="stats_col">' . $day['visits'] . '</td>';\r
+ $res .= '<td class="stats_col">' . $day['views'] . '</td>';\r
+ $res .= '<td class="stats_col">' . $day['links'] . '</td>';\r
+ $res .= '</tr>';\r
+ }\r
+ $res .= '</table>';\r
+\r
+ $res .= wsPage::bf();\r
+ $res .= wsPage::bh('stats_detail_pages');\r
+ $res .= cubeTypographp::typographp(array('texte' => mb_strtoupper(__('Pages les plus vues') . ' - ' . strftime('%B %Y', $time_page))), 'hache2');\r
+ $res .= '<table class="liste max">';\r
+ $res .= '<tr><th>' . __('Pages') . '</th>';\r
+ if ($rr->stats_score == 1) {\r
+ $res .= '<th class="stats_col">' . __('Score') . '</th>';\r
+ }\r
+ $res .= '<th class="stats_col">' . __('Vues') . '</th>';\r
+ $res .= '<th class="stats_col">' . __('Zooms') . '</th>';\r
+ if ($rr->bookmark == 1) {\r
+ $res .= '<th class="stats_col">' . __('Marques-pages') . '</th>';\r
+ }\r
+ if ($rr->print == 1) {\r
+ $res .= '<th class="stats_col">' . __('Impressions') . '</th></tr>';\r
+ }\r
+\r
+ foreach ($stats->pages->page as $page) {\r
+ $p = (string)$page['page'];\r
+ if ($p > $rr->pages || cubeMath::isOdd($p)) {\r
+ continue;\r
+ }\r
+ if ($p == 0) {\r
+ $pagen = '1';\r
+ } elseif ($p == $rr->pages) {\r
+ $pagen = $p;\r
+ } else {\r
+ $pagen = $p;\r
+ $pagen .= '-';\r
+ $pagen .= ($p + 1);\r
+ }\r
+ $res .= '<tr><td>' . $pagen . '</td>';\r
+ if ($rr->stats_score == 1) {\r
+ $res .= '<td class="center">' . $page['score'] . '</td>';\r
+ }\r
+ $res .= '<td class="center">' . $page['views'] . '</td>';\r
+ $res .= '<td class="center">' . $page['zooms'] . '</td>';\r
+ if ($rr->bookmark == 1) {\r
+ $res .= '<td class="center">' . $page['bookmarks'] . '</td>';\r
+ }\r
+ if ($rr->print == 1) {\r
+ $res .= '<td class="center">' . $page['prints'] . '</td></tr>';\r
+ }\r
+ }\r
+ $res .= '</table>';\r
+\r
+ $res .= wsPage::bf();\r
+ if ($rr->search == 0) {\r
+ $idl = 'stats_links_2';\r
+ $idc = 'stats_country_2';\r
+ } else {\r
+ $idl = 'stats_links';\r
+ $idc = 'stats_country';\r
+ }\r
+\r
+ $res .= '<div id="stats_30">';\r
+ $res .= wsPage::bh($idl);\r
+ $res .= cubeTypographp::typographp(array('texte' => mb_strtoupper(__('Liens les plus cliqués'))), 'hache2');\r
+ $res .= '<table class="liste max">';\r
+ $res .= '<tr><th class="max">' . __('URL') . '</th><th class="nowrap">' . __('Clics') . '</th></tr>';\r
+ foreach ($stats->links->link as $link) {\r
+ $uurl = (string)$link['url'];\r
+ $nb = (string)$link['click'];\r
+ if (stristr($uurl, 'mailto:') || stristr($uurl, 'http://')) {\r
+ $url = substr($uurl, 7);\r
+ } else {\r
+ $url = $uurl;\r
+ }\r
+ if (strlen($url) > 30) {\r
+ $url = substr($url, 0, 30) . '...';\r
+ }\r
+ $res .= '<tr><td class="max"><a href="' . $uurl . '" class="blank" title="' . $uurl . '">' . $url . '</a></td><td class="nowrap center">' . $nb . '</td></tr>';\r
+ }\r
+ $res .= '</table>';\r
+\r
+ $res .= wsPage::bf();\r
+ if ($rr->search == 1) {\r
+ $res .= wsPage::bh('stats_search');\r
+ $res .= cubeTypographp::typographp(array('texte' => mb_strtoupper(__('Mots les plus recherchés'))), 'hache2');\r
+ $res .= '<table class="liste max">';\r
+ $res .= '<tr><th class="max">' . __('Mot') . '</th><th class="nowrap">' . __('Recherches') . '</th></tr>';\r
+ foreach ($stats->searches->search as $search) {\r
+ $res .= '<tr><td class="max">' . $search['query'] . '</td><td class="nowrap center">' . $search['count'] . '</td></tr>';\r
+ }\r
+ $res .= '</table>';\r
+ $res .= wsPage::bf();\r
+ }\r
+\r
+ $res .= wsPage::bh($idc);\r
+ $res .= cubeTypographp::typographp(array('texte' => mb_strtoupper(__('Origine des visiteurs'))), 'hache2');\r
+ $res .= '<table class="liste max">';\r
+ $res .= '<tr><th class="max">' . __('Pays') . '</th><th class="nowrap">' . __('Visiteurs') . '</th></tr>';\r
+\r
+ foreach ($stats->countries->country as $country) {\r
+ $pays = $country['code'];\r
+ if (!$c = cubeCountry::getCountry($pays)) {\r
+ $c = __('Origine inconnue');\r
+ }\r
+ $res .= '<tr><td class="max">' . cubeCountry::getFlag($pays) . ' ' . ucfirst(mb_strtolower($c)) . '</td><td class="nowrap center">' . $country['visitors'] . '</td></tr>';\r
+ }\r
+ $res .= '</table>';\r
+ $res .= wsPage::bf();\r
+ $res .= '</div>';\r
+ return $res;\r
+ }\r
+\r
+ public static function graph_mensuel($bid, $a, $m, $stats)\r
+ {\r
+ wsDroits::viewBook($bid);\r
+ global $core;\r
+ $img = ROOT . '/images/stats/mensuel-' . $a . '-' . $m . '-' . $bid . '.png';\r
+ $imgw = WEBROOT . '/images/stats/mensuel-' . $a . '-' . $m . '-' . $bid . '.png';\r
+ $lm = cubeDate::limitMonth($a, $m);\r
+ $datestocorrect = array(mktime(0, 0, 0, 11, 23, 2009), mktime(0, 0, 0, 12, 8, 2009), mktime(0, 0, 0, 12, 9, 2009));\r
+ $maxv = 0;\r
+ $maxp = 0;\r
+ $maxb = 0;\r
+ $v = array();\r
+ $s = array();\r
+ foreach ($stats->days->day as $day) {\r
+ $time = mktime(0, 0, 0, $m, (string)$day['day'], $a);\r
+ $maxb = max($maxb, (string)$day['visits']);\r
+ $maxp = max($maxp, (string)$day['views']);\r
+ $maxv = max($maxv, (string)$day['visitors']);\r
+ $s[$time]['book'] = $day['visits'];\r
+ $s[$time]['page'] = $day['views'];\r
+ $s[$time]['visit'] = $day['visitors'];\r
+ $s[$time]['time'] = $time;\r
+ }\r
+ $max = max($maxb, $maxv);\r
+ self::getQ($bid, $max, $maxp, $maxpages, $s);\r
+ krsort($s);\r
+ $max = max($maxv, $maxb, $maxp);\r
+ $days = cubeDate::getDays($a, $m);\r
+ $space = round((900 - (count($days) * 20)) / (count($days) * 2));\r
+ @unlink($img);\r
+ if (!file_exists($img) || filemtime($img) < cubeDate::round(null, 'H')) {\r
+ // Création de l'image\r
+ $im = imagecreatetruecolor(944, 306);\r
+ imagelayereffect($im, IMG_EFFECT_REPLACE);\r
+ $trans = imagecolorallocatealpha($im, 244, 244, 241, 0);\r
+ imagefill($im, 0, 0, $trans);\r
+ imagelayereffect($im, IMG_EFFECT_ALPHABLEND);\r
+ $i = 1;\r
+ $x0 = 0;\r
+ $y0 = 305;\r
+ $h = 300;\r
+ $c0 = imagecolorallocate($im, 0, 0 , 0);\r
+ $c1 = imagecolorallocatealpha($im, 81, 78, 73, 64);\r
+ $hp = $h * ($maxp / $max)-2;\r
+ $mhp = $y0 - $hp-6;\r
+ imagesetstyle($im, array($c1, $c1, $c1, $c1, $c1, $trans, $trans, $trans, $trans));\r
+ imageline($im, 0, $y0 - $hp, 944, $y0 - $hp, IMG_COLOR_STYLED);\r
+ $c1 = imagecolorallocate($im, 81, 78, 73);\r
+ $c2 = imagecolorallocatealpha($im, 245, 77, 0, 64);\r
+ $hb = $h * ($maxb / $max)-1;\r
+ $mhb = $y0 - $hb-6;\r
+ imagesetstyle($im, array($c2, $c2, $c2, $c2, $c2, $trans, $trans, $trans, $trans));\r
+ imageline($im, 0, $y0 - $hb, 944, $y0 - $hb, IMG_COLOR_STYLED);\r
+ $c2 = imagecolorallocate($im, 245, 77, 0);\r
+ $c3 = imagecolorallocatealpha($im, 194, 211, 19, 32);\r
+ $hv = $h * ($maxv / $max);\r
+ $mhv = $y0 - $hv-6;\r
+ imagesetstyle($im, array($c3, $c3, $c3, $c3, $c3, $trans, $trans, $trans, $trans));\r
+ imageline($im, 0, $y0 - $hv, 944, $y0 - $hv, IMG_COLOR_STYLED);\r
+ $c3 = imagecolorallocate($im, 194, 211, 19);\r
+ foreach($days as $d => $t) {\r
+ if (isset($s[$t])) {\r
+ $x0 += $space;\r
+ $hp = $h * ($s[$t]['page'] / $max)-2;\r
+ $hb = $h * ($s[$t]['book'] / $max)-1;\r
+ $hv = $h * ($s[$t]['visit'] / $max);\r
+ imagefilledrectangle($im, $x0 + 14, $y0 - $hp, $x0, $y0, $c1);\r
+ imagerectangle($im, $x0 + 14, $y0 - $hp, $x0, $y0, $c0);\r
+ $x0 += 3;\r
+ imagefilledrectangle($im, $x0 + 14, $y0 - $hb, $x0, $y0, $c2);\r
+ imagerectangle($im, $x0 + 14, $y0 - $hb, $x0, $y0, $c0);\r
+ $x0 += 3;\r
+ imagefilledrectangle($im, $x0 + 14, $y0 - $hv, $x0, $y0, $c3);\r
+ imagerectangle($im, $x0 + 14, $y0 - $hv, $x0, $y0, $c0);\r
+ $i++;\r
+ $x0 += 14 + $space;\r
+ } else {\r
+ $x0 += 20 + $space * 2;\r
+ }\r
+ }\r
+\r
+ imageline($im, 0 , $y0, 944 , $y0 , $c0);\r
+ imagepng($im, $img);\r
+ }\r
+ $res = '<div style="position:absolute;top:' . $mhp . 'px;left:900px;color:#514e49;background:#f4f4f1;padding-left:2px;padding-right:2px;">' . $maxpages . '</div>';\r
+ $res .= '<div style="position:absolute;top:' . $mhb . 'px;left:900px;color:#f54d00;background:#f4f4f1;padding-left:2px;padding-right:2px;">' . $maxb . '</div>';\r
+ $res .= '<div style="position:absolute;top:' . $mhv . 'px;left:900px;color:#c2d313;background:#f4f4f1;padding-left:2px;padding-right:2px;">' . $maxv . '</div>';\r
+ $res .= '<img src="' . $imgw . '" alt="' . __('Statistiques mensuelles') . '" />';\r
+ $res .= '<table style="width:944px;max-width:944px;margin:0px;table-layout:fixed;"><tr>';\r
+ foreach($days as $d => $t) {\r
+ $res .= '<td style="width:' . (20 + $space * 2) . 'px;max-width:' . (20 + $space * 2) . 'px;text-align:center;">' . $d . '</td>';\r
+ }\r
+ $spacef = 944 - (count($days) * (20 + ($space * 2)));\r
+ $res .= '<td style="width:' . $spacef . 'px;">' . cubeMedia::spacer($spacef, 20) . '</td>';\r
+ $res .= '</tr></table>';\r
+ $res .= '<table style="margin-top:10px;margin-bottom:10px;"><tr>';\r
+ $res .= '<td style="width:12px;background:#514e49;height:12px;"></td><td style="width:10px;"></td><td>' . __('Pages vues') . '</td><td style="width:10px;"></td>';\r
+ $res .= '<td style="width:12px;background:#f54d00;height:12px;"></td><td style="width:10px;"></td><td>' . __('Visites') . '</td><td style="width:10px;"></td>';\r
+ $res .= '<td style="width:12px;background:#c2d313;height:12px;"></td><td style="width:10px;"></td><td>' . __('Visiteurs uniques') . '</td><td style="width:10px;"></td>';\r
+ $res .= '</tr></table>';\r
+ return $res;\r
+ }\r
+}\r
+\r
+?>
\ No newline at end of file