Пример #1
0
 /**
  * Internal function to return a Referral object from a row.
  * @param $row array
  * @return Referral
  */
 function &_returnReferralFromRow(&$row)
 {
     $referral = new Referral();
     $referral->setId($row['referral_id']);
     $referral->setArticleId($row['article_id']);
     $referral->setStatus($row['status']);
     $referral->setUrl($row['url']);
     $referral->setDateAdded($this->datetimeFromDB($row['date_added']));
     $referral->setLinkCount($row['link_count']);
     $this->getDataObjectSettings('referral_settings', 'referral_id', $row['referral_id'], $referral);
     return $referral;
 }
Пример #2
0
 function logArticleRequest(&$templateMgr)
 {
     $article = $templateMgr->get_template_vars('article');
     if (!$article) {
         return false;
     }
     $articleId = $article->getId();
     $referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
     // Check if referrer is empty or is the local journal
     if (empty($referrer) || strpos($referrer, Request::getIndexUrl()) !== false) {
         return false;
     }
     $referralDao =& DAORegistry::getDAO('ReferralDAO');
     if ($referralDao->referralExistsByUrl($articleId, $referrer)) {
         // It exists -- increment the count
         $referralDao->incrementReferralCount($article->getId(), $referrer);
     } else {
         // It's a new referral -- log it.
         $referral = new Referral();
         $referral->setArticleId($article->getId());
         $referral->setLinkCount(1);
         $referral->setUrl($referrer);
         $referral->setStatus(REFERRAL_STATUS_NEW);
         $referral->setDateAdded(Core::getCurrentDate());
         $referralDao->insertReferral($referral);
     }
 }
Пример #3
0
 /**
  * Intercept requests for article display to collect and record
  * incoming referrals.
  */
 function logArticleRequest(&$templateMgr)
 {
     $article = $templateMgr->get_template_vars('article');
     if (!$article) {
         return false;
     }
     $articleId = $article->getId();
     $referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
     // Check if referrer is empty or is the local journal
     if (empty($referrer) || strpos($referrer, Request::getIndexUrl()) !== false) {
         return false;
     }
     $referralDao =& DAORegistry::getDAO('ReferralDAO');
     if ($referralDao->referralExistsByUrl($articleId, $referrer)) {
         // It exists -- increment the count
         $referralDao->incrementReferralCount($article->getId(), $referrer);
     } else {
         // It's a new referral. Log it unless it's excluded.
         $journal = $templateMgr->get_template_vars('currentJournal');
         $exclusions = $this->getSetting($journal->getId(), 'exclusions');
         foreach (array_map('trim', explode("\n", "{$exclusions}")) as $exclusion) {
             if (empty($exclusion)) {
                 continue;
             }
             if (preg_match($exclusion, $referrer)) {
                 return false;
             }
         }
         $referral = new Referral();
         $referral->setArticleId($article->getId());
         $referral->setLinkCount(1);
         $referral->setUrl($referrer);
         $referral->setStatus(REFERRAL_STATUS_NEW);
         $referral->setDateAdded(Core::getCurrentDate());
         $referralDao->insertReferral($referral);
     }
     return false;
 }
Пример #4
0
 /**
  * Save referral. 
  */
 function execute()
 {
     $referralDao =& DAORegistry::getDAO('ReferralDAO');
     if (isset($this->referralId)) {
         $referral =& $referralDao->getReferral($this->referralId);
     }
     if (!isset($referral)) {
         $referral = new Referral();
         $referral->setDateAdded(Core::getCurrentDate());
         $referral->setLinkCount(0);
     }
     $referral->setArticleId($this->article->getId());
     $referral->setName($this->getData('name'), null);
     // Localized
     $referral->setUrl($this->getData('url'));
     $referral->setStatus($this->getData('status'));
     // Update or insert referral
     if ($referral->getId() != null) {
         $referralDao->updateReferral($referral);
     } else {
         $referralDao->insertReferral($referral);
     }
 }