1 <?php
 2 
 3 /**
 4  * REX_ARTICLE[1]
 5  * REX_ARTICLE[id=1].
 6  *
 7  * REX_ARTICLE[id=1 ctype=2 clang=1]
 8  *
 9  * REX_ARTICLE[field='id']
10  * REX_ARTICLE[field='description' id=3]
11  * REX_ARTICLE[field='description' id=3 clang=2]
12  *
13  * Attribute:
14  *   - clang     => ClangId des Artikels festlegen
15  *   - ctype     => Spalte des Artikels festlegen
16  *   - field     => Nur dieses Feld des Artikels ausgeben
17  *
18  * @package redaxo\structure
19  */
20 class rex_var_article extends rex_var
21 {
22     /**
23      * Werte für die Ausgabe.
24      */
25     protected function getOutput()
26     {
27         $id = $this->getParsedArg('id', 0, true);
28         $clang = $this->getParsedArg('clang', 'null');
29         $ctype = $this->getParsedArg('ctype', -1);
30         $field = $this->getParsedArg('field');
31 
32         $noId = $id == 0;
33         if ($noId) {
34             $id = '$this->getValue(\'id\')';
35         }
36 
37         if ($field) {
38             return self::class . '::getArticleValue(' . $id . ', ' . $field . ', ' . $clang . ')';
39         }
40         if (!$noId || !in_array($this->getContext(), ['module', 'action'])) {
41             // aktueller Artikel darf nur in Templates, nicht in Modulen eingebunden werden
42             // => endlossschleife
43             if ($noId && $clang == 'null') {
44                 return '$this->getArticle(' . $ctype . ')';
45             }
46             return self::class . '::getArticle(' . $id . ', ' . $ctype . ', ' . $clang . ')';
47         }
48 
49         return false;
50     }
51 
52     public static function getArticleValue($id, $field, $clang = null)
53     {
54         if ($clang === null) {
55             $clang = rex_clang::getCurrentId();
56         }
57         $article = rex_article::get($id, $clang);
58         return rex_escape($article->getValue($field));
59     }
60 
61     public static function getArticle($id, $ctype = -1, $clang = null)
62     {
63         if ($clang === null) {
64             $clang = rex_clang::getCurrentId();
65         }
66         $article = new rex_article_content($id, $clang);
67         return $article->getArticle($ctype);
68     }
69 }
70