29 public $piwikServerURL;
58 if (empty($this->count))
59 $this->count = Yii::app()->getModule(
'piwik')->count;
60 if (empty($this->token))
61 $this->token = Yii::app()->getModule(
'piwik')->token;
62 if (empty($this->piwikServerURL))
63 $this->piwikServerURL = Yii::app()->getModule(
'piwik')->piwikServerURL;
64 if (empty($this->sites))
65 $this->sites = Yii::app()->getModule(
'piwik')->sites;
66 if (empty($this->cacheTime))
67 $this->cacheTime = Yii::app()->getModule(
'piwik')->cacheTime;
69 $mostvisited = array();
71 $check = Yii::app()->cache->get(md5($this->sites .
"_popular"));
74 $mostvisited = $check;
77 $url = $this->piwikServerURL;
78 $url .=
"/?module=API&method=Actions.getPageUrls";
79 $url .=
"&idSite=".$this->sites.
"&period=month&date=yesterday";
80 $url .=
"&format=PHP&filter_limit=".$this->count;
81 $url .=
"&filter_sort_column=nb_hits&filter_sort_order=desc";
82 $url .=
"&token_auth=".$this->token;
84 $fetched = file_get_contents($url);
85 $content = unserialize($fetched);
87 if ($this->sites ==
"all" || strstr($this->sites,
',')){
88 foreach($content as $mysiteid => $mysite){
89 foreach($mysite as $myline){
90 $mostvisited[] = $this->calcresult($myline);
92 $key = md5($mysiteid .
"_popular");
93 Yii::app()->cache->set($key, $mostvisited, $this->cacheTime);
95 $key = md5($this->sites .
"_popular");
96 Yii::app()->cache->set($key, $mostvisited, $this->cacheTime);
99 foreach($content as $myline){
100 $mostvisited[] = $this->calcresult($myline);
102 $key = md5($this->sites .
"_popular");
103 Yii::app()->cache->set($key, $mostvisited, $this->cacheTime);
107 $this->render($mostvisited);
110 private function calcresult($line){
111 return array(
"url" => $line[
'url'],
"name" => $line[
'label']);
114 public function render($mostvisited){
115 foreach($mostvisited as $h){
116 $name = (!empty($h[
'name']) ? $h[
'name'] : $h[
'url']);
117 $cmsObject = Yii::app()->getComponent(
"repositoryApi")->getCmsObject($h[
'name'], array(
"name"));
118 if (!empty($cmsObject)){
119 $name = $cmsObject[
"attributes"][
"name"];
121 echo
"<li>".CHtml::link($name, $h[
'url']).
"</li>";