Advertisement
Guest User

include/classes/class.ooarticle.inc.php

a guest
Feb 24th, 2016
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.60 KB | None | 0 0
  1. <?php
  2. // include/classes/class.ooarticle.inc.php
  3.  
  4. /**
  5.  * WARNING: This code is not the original code for Redaxo, use for testing purposes only
  6.  */
  7.  
  8. class OOArticle extends OORedaxo
  9. {
  10.     /*protected*/ function OOArticle($params = false, $clang = false)
  11. {
  12.     parent :: OORedaxo($params, $clang);
  13. }
  14.  
  15.     ############################################################################
  16.    # Testing purposes only
  17.  
  18.     static private function __log($errorInfo, $toFile = true)
  19.     {
  20.         if ($toFile) {
  21.             self::__logToFile($errorInfo);
  22.         } else {
  23.             self::__logToConsole($errorInfo);
  24.         }
  25.     }
  26.  
  27.     static private function __logToFile($errorInfo)
  28.     {
  29.         $logFile = fopen('/tmp/errorlog_redaxo.log', 'a+');
  30.         fwrite($logFile, self::__get_var_dump($errorInfo));
  31.     }
  32.  
  33.     static private function __logToConsole($errorInfo)
  34.     {
  35.         echo sprintf('<script>console.log(%s);</script>',
  36.             json_encode(self::__get_var_dump($errorInfo))
  37.         );
  38.     }
  39.  
  40.     static private function __get_var_dump($var)
  41.     {
  42.         ob_start();
  43.         var_dump($var);
  44.         return ob_get_clean();
  45.     }
  46.  
  47.     ############################################################################
  48.  
  49.     /**
  50.      * CLASS Function:
  51.      * Return an OORedaxo object based on an id
  52.      */
  53.     static /*public*/ function getArticleById($article_id, $clang = false, $OOCategory = false)
  54.     {
  55.         global $REX;
  56.  
  57.         $article_id = (int) $article_id;
  58.  
  59.         if (!is_int($article_id)) {
  60.             return null;
  61.         }
  62.  
  63.         if ($clang === false) {
  64.             $clang = $REX['CUR_CLANG'];
  65.         }
  66.  
  67.         $article_path = $REX['GENERATED_PATH'] . '/articles/' . $article_id . '.' . $clang . '.article';
  68.         if (!file_exists($article_path)) {
  69.             require_once $REX['INCLUDE_PATH'] . '/functions/function_rex_generate.inc.php';
  70.             rex_generateArticleMeta($article_id, $clang);
  71.         }
  72.  
  73.         if (file_exists($article_path)) {
  74.             require_once $article_path;
  75.  
  76.             if (isset($REX['ART'][$article_id]))
  77.             {
  78.                 $errorInfo = array(
  79.                     'missing article_id' => $article_id,
  80.                     'REX[ART]' => $REX['ART']
  81.                 );
  82.                 self::__log($errorInfo);
  83.  
  84.             } else {
  85.  
  86.                 if ($OOCategory) {
  87.  
  88.                     return new OOCategory(OORedaxo :: convertGeneratedArray($REX['ART'][$article_id], $clang));
  89.                 } else {
  90.                     return new self(OORedaxo :: convertGeneratedArray($REX['ART'][$article_id], $clang));
  91.                 }
  92.             }
  93.         }
  94.  
  95.         return null;
  96.     }
  97.  
  98.     /**
  99.      * CLASS Function:
  100.      * Return the site wide start article
  101.      */
  102.     static /*public*/ function getSiteStartArticle($clang = false)
  103.     {
  104.         global $REX;
  105.  
  106.         if ($clang === false) {
  107.             $clang = $REX['CUR_CLANG'];
  108.         }
  109.  
  110.         return self :: getArticleById($REX['START_ARTICLE_ID'], $clang);
  111.     }
  112.  
  113.     /**
  114.      * CLASS Function:
  115.      * Return start article for a certain category
  116.      */
  117.     static /*public*/ function getCategoryStartArticle($a_category_id, $clang = false)
  118.     {
  119.         global $REX;
  120.  
  121.         if ($clang === false) {
  122.             $clang = $REX['CUR_CLANG'];
  123.         }
  124.  
  125.         return self :: getArticleById($a_category_id, $clang);
  126.     }
  127.  
  128.     /**
  129.      * CLASS Function:
  130.      * Return a list of articles for a certain category
  131.      */
  132.     static /*public*/ function getArticlesOfCategory($a_category_id, $ignore_offlines = false, $clang = false)
  133.     {
  134.         global $REX;
  135.  
  136.         if ($clang === false) {
  137.             $clang = $REX['CUR_CLANG'];
  138.         }
  139.  
  140.         $articlelist = $REX['GENERATED_PATH'] . '/articles/' . $a_category_id . '.' . $clang . '.alist';
  141.         if (!file_exists($articlelist)) {
  142.             include_once $REX['INCLUDE_PATH'] . '/functions/function_rex_generate.inc.php';
  143.             rex_generateLists($a_category_id, $clang);
  144.         }
  145.  
  146.         $artlist = array ();
  147.         if (file_exists($articlelist)) {
  148.             include_once $articlelist;
  149.  
  150.             if (isset($REX['RE_ID'][$a_category_id])) {
  151.                 foreach ($REX['RE_ID'][$a_category_id] as $var) {
  152.                     $article = self :: getArticleById($var, $clang);
  153.                     if ($ignore_offlines) {
  154.                         if ($article->isOnline()) {
  155.                             $artlist[] = $article;
  156.                         }
  157.                     } else {
  158.                         $artlist[] = $article;
  159.                     }
  160.                 }
  161.             }
  162.         }
  163.  
  164.         return $artlist;
  165.     }
  166.  
  167.     /**
  168.      * CLASS Function:
  169.      * Return a list of top-level articles
  170.      */
  171.     static /*public*/ function getRootArticles($ignore_offlines = false, $clang = false)
  172.     {
  173.         return self :: getArticlesOfCategory(0, $ignore_offlines, $clang);
  174.     }
  175.  
  176.     /**
  177.      * Accessor Method:
  178.      * returns the category id
  179.      */
  180.     /*public*/ function getCategoryId()
  181. {
  182.     return $this->isStartPage() ? $this->getId() : $this->getParentId();
  183. }
  184.  
  185.     /*
  186.      * Object Function:
  187.      * Returns the parent category
  188.      */
  189.     /*public*/ function getCategory()
  190. {
  191.     return OOCategory :: getCategoryById($this->getCategoryId(), $this->getClang());
  192. }
  193.  
  194.     /**
  195.      * Accessor Method:
  196.      * returns the path of the category/article
  197.      */
  198.     /*public*/ function getPath()
  199. {
  200.     if ($this->isStartArticle()) {
  201.         return $this->_path . $this->_id . '|';
  202.     }
  203.  
  204.     return $this->_path;
  205. }
  206.  
  207.     /**
  208.      * Accessor Method:
  209.      * returns the path ids of the category/article as an array
  210.      */
  211.     /*public*/ function getPathAsArray()
  212. {
  213.     $path = explode('|', $this->getPath());
  214.     return array_values(array_map('intval', array_filter($path)));
  215. }
  216.  
  217.     /*
  218.      * Static Method: Returns True when the given article is a valid OOArticle
  219.      */
  220.     static /*public*/ function isValid($article)
  221.     {
  222.         return is_object($article) && is_a($article, 'ooarticle');
  223.     }
  224.  
  225.     /*public*/ function getValue($value)
  226. {
  227.     // alias für re_id -> category_id
  228.     if (in_array($value, array('re_id', '_re_id', 'category_id', '_category_id'))) {
  229.         // für die CatId hier den Getter verwenden,
  230.         // da dort je nach ArtikelTyp unterscheidungen getroffen werden müssen
  231.         return $this->getCategoryId();
  232.     }
  233.     return parent::getValue($value);
  234. }
  235.  
  236.     static /*public*/ function hasValue($value)
  237.     {
  238.         return parent::hasValueWithPrefixes($value, array('art_'));
  239.     }
  240.  
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement