1 <?php
  2 
  3 /**
  4  * Klasse regelt den Zugriff auf Artikelinhalte.
  5  * DB Anfragen werden vermieden, caching läuft über generated Dateien.
  6  *
  7  * @package redaxo\structure\content
  8  */
  9 class rex_article_content extends rex_article_content_base
 10 {
 11     // bc schalter
 12     private $viasql;
 13 
 14     public function __construct($article_id = null, $clang = null)
 15     {
 16         $this->viasql = false;
 17         parent::__construct($article_id, $clang);
 18     }
 19 
 20     // bc
 21     public function getContentAsQuery($viasql = true)
 22     {
 23         if ($viasql !== true) {
 24             $viasql = false;
 25         }
 26         $this->viasql = $viasql;
 27     }
 28 
 29     public function setArticleId($article_id)
 30     {
 31         // bc
 32         if ($this->viasql) {
 33             return parent::setArticleId($article_id);
 34         }
 35 
 36         $article_id = (int) $article_id;
 37         $this->article_id = $article_id;
 38 
 39         $rex_article = rex_article::get($article_id, $this->clang);
 40         if ($rex_article instanceof rex_article) {
 41             $this->category_id = $rex_article->getCategoryId();
 42             $this->template_id = $rex_article->getTemplateId();
 43             return true;
 44         }
 45 
 46         $this->article_id = 0;
 47         $this->template_id = 0;
 48         $this->category_id = 0;
 49         return false;
 50     }
 51 
 52     protected function _getValue($value)
 53     {
 54         // bc
 55         if ($this->viasql) {
 56             return parent::_getValue($value);
 57         }
 58 
 59         $value = $this->correctValue($value);
 60 
 61         return rex_article::get($this->article_id, $this->clang)->getValue($value);
 62     }
 63 
 64     public function hasValue($value)
 65     {
 66         // bc
 67         if ($this->viasql) {
 68             return parent::hasValue($value);
 69         }
 70 
 71         $value = $this->correctValue($value);
 72 
 73         return rex_article::get($this->article_id, $this->clang)->hasValue($value);
 74     }
 75 
 76     public function getArticle($curctype = -1)
 77     {
 78         // bc
 79         if ($this->viasql) {
 80             return parent::getArticle($curctype);
 81         }
 82 
 83         $this->ctype = $curctype;
 84 
 85         if (!$this->getSlice && $this->article_id != 0) {
 86             // ----- start: article caching
 87             ob_start();
 88             ob_implicit_flush(0);
 89 
 90             $article_content_file = rex_path::addonCache('structure', $this->article_id . '.' . $this->clang . '.content');
 91 
 92             $generated = true;
 93             if (!file_exists($article_content_file)) {
 94                 $generated = rex_content_service::generateArticleContent($this->article_id, $this->clang);
 95                 if ($generated !== true) {
 96                     // fehlermeldung ausgeben
 97                     echo $generated;
 98                 }
 99             }
100 
101             if ($generated === true) {
102                 require $article_content_file;
103             }
104 
105             // ----- end: article caching
106             $CONTENT = ob_get_clean();
107         } else {
108             // Inhalt ueber sql generierens
109             $CONTENT = parent::getArticle($curctype);
110         }
111 
112         $CONTENT = rex_extension::registerPoint(new rex_extension_point('ART_CONTENT', $CONTENT, [
113             'ctype' => $curctype,
114             'article' => $this,
115         ]));
116 
117         return $CONTENT;
118     }
119 }
120