/**
  * @private
  * updates the article referrers given an id
  */
 function _updateArticleReferrersById($articleId)
 {
     if (array_key_exists('HTTP_REFERER', $_SERVER)) {
         $referrers = new Referers();
         $referrers->addReferer($_SERVER['HTTP_REFERER'], $articleId, $this->_blogInfo->getId());
     }
 }
 /**
  * Returns the referers object of specific article
  */
 function getArticleReferers($articleId, $maxReferers = 0, $sortByField = 1)
 {
     $referers = new Referers();
     $blogId = $this->blogInfo->getId();
     $query = "SELECT * FROM " . $this->prefix . "referers WHERE article_id = " . $articleId;
     if ($this->sortByField != "" && $this->sortByField != $sortByField) {
         $sortByField = $this->sortByField;
     }
     if ($sortByField == 1) {
         $query .= " ORDER BY hits DESC";
     } elseif ($sortByField == 2) {
         $query .= " ORDER BY last_date DESC";
     } else {
         return false;
     }
     if ($maxReferers > 0 && $this->maxReferers > 0) {
         $query .= " LIMIT " . $maxReferers . ";";
     } else {
         $query .= " LIMIT " . $this->maxReferers . ";";
     }
     $result = $referers->_db->Execute($query);
     if (!$result) {
         return false;
     }
     $articlereferers = array();
     while ($row = $result->FetchRow()) {
         array_push($articlereferers, $referers->_fillRefererInformation($row));
     }
     return $articlereferers;
 }
 function render()
 {
     $referers = new Referers();
     $totalReferers = $referers->getBlogTotalReferers($this->_blogInfo->getId(), $this->_article->getId());
     $postReferers = $referers->getArticleReferers($this->_article->getId(), $this->_blogInfo->getId(), $this->_page, DEFAULT_ITEMS_PER_PAGE);
     if (!$blogReferers) {
         $blogReferers = array();
     }
     // calculate the links to the different pages
     $pager = new Pager("?op=postStats&postId=" . $this->_article->getId() . "&page=", $this->_page, $totalReferers, DEFAULT_ITEMS_PER_PAGE);
     $this->setValue("referrers", $postReferers);
     $this->setValue("pager", $pager);
     $this->setValue("post", $this->_article);
     parent::render();
 }
 function render()
 {
     $referers = new Referers();
     $totalReferers = $referers->getBlogTotalReferers($this->_blogInfo->getId());
     // get the current page
     $this->_page = $this->getCurrentPageFromRequest();
     $blogReferers = $referers->getBlogReferers($this->_blogInfo->getId(), $this->_page, DEFAULT_ITEMS_PER_PAGE);
     if (!$blogReferers) {
         $blogReferers = array();
     }
     // calculate the links to the different pages
     $pager = new Pager("?op=Stats&page=", $this->_page, $totalReferers, DEFAULT_ITEMS_PER_PAGE);
     $this->setValue("referrers", $blogReferers);
     $this->setValue("pager", $pager);
     parent::render();
 }
 /**
  * Carries out the specified action
  */
 function _deleteReferrers()
 {
     $referrers = new Referers();
     $errorMessage = "";
     $successMessage = "";
     $totalOk = 0;
     foreach ($this->_referrerIds as $referrerId) {
         // fetch the referrer
         $referrer = $referrers->getBlogReferer($referrerId, $this->_blogInfo->getId());
         // fire the pre-event
         $this->notifyEvent(EVEN_PRE_REFERRER_DELETE, array("referrer" => &$referrer));
         if (!$referrer) {
             $errorMessage .= $this->_locale->pr("error_deleting_referrer2", $referrerId) . "<br/>";
         } else {
             if (!$referrers->deleteBlogReferer($referrerId, $this->_blogInfo->getId())) {
                 $errorMessage .= $this->_locale->pr("error_deleting_referrer", $referrer->getUrl()) . "<br/>";
             } else {
                 $totalOk++;
                 if ($totalOk < 2) {
                     $successMessage = $this->_locale->pr("referrer_deleted_ok", $referrer->getUrl());
                 } else {
                     $successMessage = $this->_locale->pr("referrers_deleted_ok", $totalOk);
                 }
                 // fire the post-event
                 $this->notifyEvent(EVENT_POST_REFERRER_DELETE, array("referrer" => &$referrer));
                 $clearCache = true;
             }
         }
     }
     if ($clearCache) {
         // clear the cache if needed
         CacheControl::resetBlogCache($this->_blogInfo->getId(), false);
     }
     $this->_view = new AdminReferrersView($this->_blogInfo);
     if ($errorMessage != "") {
         $this->_view->setErrorMessage($errorMessage);
     }
     if ($successMessage != "") {
         $this->_view->setSuccessMessage($successMessage);
     }
     $this->setCommonData();
     // better to return true if everything fine
     return true;
 }
 /**
  * updates the referrers but only if there is no $articleId parameter in the request. If that's the case,
  * it will be left up to the correct action to take care of updating the referrers
  *
  * @private
  */
 function _updateReferrer()
 {
     if ($this->_request->getValue("articleId") != "" || $this->_request->getValue("articleName") != "") {
         return true;
     }
     // update the referer statistics
     $referers = new Referers();
     if (array_key_exists('HTTP_REFERER', $_SERVER)) {
         $referers->addReferer($_SERVER['HTTP_REFERER'], 0, $this->_blogInfo->getId());
     }
     return true;
 }