/**
  * Send request to refresh article cache on Facebook
  *
  * @param int $number
  * @param int $languageId
  *
  * @return mixed response from Facebook about url, or array with error message
  */
 private function clearpageCache($number, $languageId)
 {
     $article = new \Article($languageId, $number);
     if (!$article->isPublished()) {
         return array('message' => $this->get('translator')->trans('fb.label.errornot'));
     }
     $url = \ShortURL::GetURL($article->getPublicationId(), $article->getLanguageId(), $article->getIssueNumber(), $article->getSectionNumber(), $article->getArticleNumber());
     try {
         $curlClient = new \Buzz\Client\Curl();
         $curlClient->setTimeout(10000);
         $browser = new \Buzz\Browser($curlClient);
         $result = $browser->post('https://graph.facebook.com/?id=' . $url . '&scrape=true');
         $urlInfo = json_decode($result->getContent(), true);
     } catch (\Buzz\Exception\ClientException $e) {
         return array('message' => $this->get('translator')->trans('fb.label.error'));
     }
     return $urlInfo;
 }
Example #2
0
 /**
  * Returns true if the article was translated in to the language
  * identified by the given language code
  *
  * @param string $p_language - language code
  * @return bool
  */
 public function translated_to($p_language) {
     if (is_string($p_language)) {
         $languages = Language::GetLanguages(null, $p_language);
         if (sizeof($languages) == 0) {
             return (int)false;
         }
         $language = $languages[0];
     } else {
         $language = $p_language;
     }
     $article = new Article($language->getLanguageId(),
     $this->m_dbObject->getArticleNumber());
     return (int)$article->exists()
     && ($article->isPublished() || CampTemplate::singleton()->context()->preview);
 }
 /**
  * Get article
  *
  * @param  int          $articleNo
  * @param  MetaLanguage $language
  * @return MetaArticle
  */
 private function _getArticle($articleNo, MetaLanguage $language)
 {
     if (empty($articleNo)) {
         return null;
     }
     $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
     $cacheKey = $cacheService->getCacheKey(array('getArticle', $articleNo, $language->number), 'article');
     if ($cacheService->contains($cacheKey)) {
         $metaArticle = $cacheService->fetch($cacheKey);
     } else {
         $articleObj = new Article($language->number, $articleNo);
         if (!$articleObj->exists() || !$this->m_preview && !$articleObj->isPublished()) {
             throw new InvalidArgumentException("Invalid article identifier in URL.", self::INVALID_ARTICLE);
         }
         $metaArticle = new MetaArticle($language->number, $articleObj->getArticleNumber());
         $cacheService->save($cacheKey, $metaArticle);
     }
     return $metaArticle;
 }
Example #4
0
 /**
  *
  */
 public static function GetTemplate($p_lngId, $p_pubId, $p_issNr, $p_sctNr, $p_artNr, $p_isPublished = true)
 {
     $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
     global $g_ado_db;
     if ($p_lngId <= 0) {
         $cacheKey = $cacheService->getCacheKey('legacy_publication' . $p_pubId, 'publication');
         if ($cacheService->contains($cacheKey)) {
             $publication = $cacheService->fetch($cacheKey);
         } else {
             $publication = new Publication($p_pubId);
             $cacheService->save($cacheKey, $publication);
         }
         if (!$publication->exists()) {
             return null;
         }
         $p_lngId = $publication->getLanguageId();
     }
     if ($p_artNr > 0) {
         if ($p_issNr <= 0 || $p_sctNr <= 0) {
             $article = new Article($p_lngId, $p_artNr);
             if (!$article->exists() || $p_isPublished && !$article->isPublished()) {
                 return self::GetInvalidURLTemplate($p_pubId, $p_issNr, $p_lngId, $p_isPublished);
             }
             $p_issNr = $article->getIssueNumber();
             $p_sctNr = $article->getSectionNumber();
         }
         return self::GetArticleTemplate($p_lngId, $p_pubId, $p_issNr, $p_sctNr);
     }
     if ($p_sctNr > 0) {
         if ($p_issNr <= 0) {
             $sql = 'SELECT MAX(i.Number) AS Number ' . 'FROM Sections as s, Issues as i ' . 'WHERE s.IdPublication = i.IdPublication' . ' AND s.IdLanguage = i.IdLanguage' . ' AND s.IdPublication = ' . (int) $p_pubId . ' AND s.IdLanguage = ' . (int) $p_lngId;
             if ($p_isPublished == true) {
                 $sql .= " AND i.Published = 'Y'";
             }
             $data = $g_ado_db->GetOne($sql);
             if (empty($data)) {
                 return null;
             }
             $p_issNr = $data;
         }
         return self::GetSectionTemplate($p_lngId, $p_pubId, $p_issNr, $p_sctNr);
     }
     if ($p_issNr <= 0) {
         $sql = 'SELECT MAX(Number) AS Number FROM Issues ' . 'WHERE IdPublication = ' . $p_pubId . ' AND IdLanguage = ' . $p_lngId;
         if ($p_isPublished == true) {
             $sql .= " AND Published = 'Y'";
         }
         $data = $g_ado_db->GetOne($sql);
         if (empty($data)) {
             return null;
         }
         $p_issNr = $data;
     }
     return self::GetIssueTemplate($p_lngId, $p_pubId, $p_issNr);
 }
    /**
     * Sets the URL values.
     *
     * Algorithm:
	 * - identify object (e.g.: publication, language, issue, section, article)
	 *     - object defined
	 *         - valid object?
	 *             - yes: set
	 *             - no: return error
	 *     - object undefined
	 *         - has default value?
	 *             - yes: set
	 *             - no:
	 *                 - object mandatory?
	 *                     - yes: return error
	 *                     - no: continue
     *
     * @return PEAR_Error
     *
     */
    private function setURL()
    {
        $this->setQueryVar('acid', null);

        $this->m_publication = null;
        $this->m_language = null;
        $this->m_issue = null;
        $this->m_section = null;
        $this->m_article = null;

        // gets the publication object based on site name (URI host)
        $alias = preg_replace('/^'.$this->getScheme().':\/\//', '', $this->getBase());
        $aliasObj = new Alias($alias);
        if ($aliasObj->exists()) {
            $this->m_publication = new MetaPublication($aliasObj->getPublicationId());
        }
        if (is_null($this->m_publication) || !$this->m_publication->defined()) {
            return new PEAR_Error("Invalid site name '$alias' in URL.", self::INVALID_SITE_NAME);
        }

        // reads parameters values if any
        $params = str_replace($this->m_config->getSetting('SUBDIR'), '', $this->getPath());
        $cParams = explode('/', trim($params, '/'));
        $cParamsSize = sizeof($cParams);
        if ($cParamsSize >= 1) {
            $cLangCode = $cParams[0];
        }
        if ($cParamsSize >= 2) {
            $cIssueSName = $cParams[1];
        }
        if ($cParamsSize >= 3) {
            $cSectionSName = $cParams[2];
        }
        if ($cParamsSize >= 4) {
            $cArticleSName = $cParams[3];
        }

        // gets the language identifier and sets the language code
        if (!empty($cLangCode)) {
            $langArray = Language::GetLanguages(null, $cLangCode);
            if (is_array($langArray) && sizeof($langArray) == 1) {
                $this->m_language = new MetaLanguage($langArray[0]->getLanguageId());
            }
        } else {
            $this->m_language = new MetaLanguage($this->m_publication->default_language->number);
        }
        if (is_null($this->m_language) || !$this->m_language->defined()) {
            return new PEAR_Error("Invalid language identifier in URL.", self::INVALID_LANGUAGE);
        }

        // gets the issue number and sets the issue short name
        if (!empty($cIssueSName)) {
        	$publishedOnly = !$this->m_preview;
            $issueArray = Issue::GetIssues($this->m_publication->identifier,
            $this->m_language->number, null, $cIssueSName, null, $publishedOnly);
            if (is_array($issueArray) && sizeof($issueArray) == 1) {
                $this->m_issue = new MetaIssue($this->m_publication->identifier,
                $this->m_language->number,
                $issueArray[0]->getIssueNumber());
            } else {
                return new PEAR_Error("Invalid issue identifier in URL.", self::INVALID_ISSUE);
	        }
        } else {
            $issueObj = Issue::GetCurrentIssue($this->m_publication->identifier,
            $this->m_language->number);
            $this->m_issue = new MetaIssue($this->m_publication->identifier,
            $this->m_language->number, $issueObj->getIssueNumber());
            if (!$this->m_issue->defined()) {
                return new PEAR_Error("No published issue was found.", self::INVALID_ISSUE);
            }
        }

        // gets the section number and sets the section short name
        if (!empty($cSectionSName)) {
            $sectionArray = Section::GetSections($this->m_publication->identifier,
            $this->m_issue->number,
            $this->m_language->number,
            $cSectionSName);
            if (is_array($sectionArray) && sizeof($sectionArray) == 1) {
                $this->m_section = new MetaSection($this->m_publication->identifier,
                $this->m_issue->number,
                $this->m_language->number,
                $sectionArray[0]->getSectionNumber());
            } else {
                return new PEAR_Error("Invalid section identifier in URL.", self::INVALID_SECTION);
            }
        }

        // gets the article number and sets the article short name
        if (!empty($cArticleSName)) {
            // we pass article short name as article identifier as they are
            // the same for Campsite, we will have to change this in the future
            $articleObj = new Article($this->m_language->number, $cArticleSName);
            if (!$articleObj->exists() || (!$this->m_preview && !$articleObj->isPublished())) {
                return new PEAR_Error("Invalid article identifier in URL.", self::INVALID_ARTICLE);
            }
            $this->m_article = new MetaArticle($this->m_language->number,
            $articleObj->getArticleNumber());
        }

        $templateId = CampRequest::GetVar(CampRequest::TEMPLATE_ID);
        $this->m_template = new MetaTemplate($this->getTemplate($templateId));
        if (!$this->m_template->defined()) {
            return new PEAR_Error("Invalid template in URL or no default template specified.",
            self::INVALID_TEMPLATE);
        }

        $this->m_validURI = true;
        $this->validateCache(false);
    } // fn setURL
Example #6
0
 /**
  *
  */
 public static function GetTemplate($p_lngId, $p_pubId, $p_issNr, $p_sctNr, $p_artNr, $p_isPublished = true)
 {
     global $g_ado_db;
     if ($p_lngId <= 0) {
         $publication = new Publication($p_pubId);
         if (!$publication->exists()) {
             return null;
         }
         $p_lngId = $publication->getLanguageId();
     }
     if ($p_artNr > 0) {
         if ($p_issNr <= 0 || $p_sctNr <= 0) {
             $article = new Article($p_lngId, $p_artNr);
             if (!$article->exists() || $p_isPublished && !$article->isPublished()) {
                 return self::GetInvalidURLTemplate($p_pubId, $p_issNr, $p_lngId, $p_isPublished);
             }
             $p_issNr = $article->getIssueNumber();
             $p_sctNr = $article->getSectionNumber();
         }
         return self::GetArticleTemplate($p_lngId, $p_pubId, $p_issNr, $p_sctNr);
     }
     if ($p_sctNr > 0) {
         if ($p_issNr <= 0) {
             $sql = 'SELECT MAX(i.Number) AS Number ' . 'FROM Sections as s, Issues as i ' . 'WHERE s.IdPublication = i.IdPublication' . ' AND s.IdLanguage = i.IdLanguage' . ' AND s.IdPublication = ' . (int) $p_pubId . ' AND s.IdLanguage = ' . (int) $p_lngId;
             if ($p_isPublished == true) {
                 $sql .= " AND i.Published = 'Y'";
             }
             $data = $g_ado_db->GetOne($sql);
             if (empty($data)) {
                 return null;
             }
             $p_issNr = $data;
         }
         return self::GetSectionTemplate($p_lngId, $p_pubId, $p_issNr, $p_sctNr);
     }
     if ($p_issNr <= 0) {
         $sql = 'SELECT MAX(Number) AS Number FROM Issues ' . 'WHERE IdPublication = ' . $p_pubId . ' AND IdLanguage = ' . $p_lngId;
         if ($p_isPublished == true) {
             $sql .= " AND Published = 'Y'";
         }
         $data = $g_ado_db->GetOne($sql);
         if (empty($data)) {
             return null;
         }
         $p_issNr = $data;
     }
     return self::GetIssueTemplate($p_lngId, $p_pubId, $p_issNr);
 }
Example #7
0
 /**
  * Get article
  *
  * @param int $articleNo
  * @param MetaLanguage $language
  * @return MetaArticle
  */
 private function _getArticle($articleNo, MetaLanguage $language)
 {
     if (empty($articleNo)) {
         return null;
     }
     $articleObj = new Article($language->number, $articleNo);
     if (!$articleObj->exists() || !$this->m_preview && !$articleObj->isPublished()) {
         throw new InvalidArgumentException("Invalid article identifier in URL.", self::INVALID_ARTICLE);
     }
     return new MetaArticle($language->number, $articleObj->getArticleNumber());
 }