RD_Sitemap
[ class tree: RD_Sitemap ] [ index: RD_Sitemap ] [ all elements ]

Source for file sitemap.php

Documentation is available at sitemap.php

  1. <?php
  2. /**
  3.  * Run Digital Sitemap
  4.  * @author Robert Deutz (email contact@rdbs.net / site www.rdbs.de)
  5.  * @version $Id$
  6.  *
  7.  * @copyright Copyright (C) 2005-2007 run-digital
  8.  * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  9.  *
  10.  *  This is free software
  11.  ***/
  12. defined'RDCOMPONENT' or die'Restricted access' );
  13. /**
  14.  * class RdSitemapModelSitemap
  15.  *
  16.  *  @package RD_Sitemap
  17.  *
  18.  */
  19. {
  20.     /** values to replace in the sql **/
  21.     var $basicValues = array();
  22.  
  23.     /** component parameter object **/
  24.     var $cparams = null;
  25.  
  26.     /** the data **/
  27.     var $data = array();
  28.  
  29.     /** menu item parameter object **/
  30.     var $mparams = null;
  31.  
  32.     /** parameter object for the actuall view **/
  33.     var $viewParameter = null;
  34.  
  35.     /** the views to process **/
  36.     var $views = array();
  37.  
  38.     /** id viewset **/
  39.     var $viewset = 0;
  40.  
  41.     /**
  42.      * Constructor
  43.      */
  44.     function __construct()
  45.     {
  46.         $this->getComponentParamsObj();
  47.  
  48.         // set up basis Values
  49.         $this->setUpBasisValues();
  50.  
  51.         parent::__construct();
  52.     }
  53.  
  54.     /**
  55.      * Get the component params
  56.      *
  57.      * @return parameter object Component Parameters
  58.      */
  59.     function getComponentParamsObj()
  60.     {
  61.         if ($this->cparams === null )
  62.         {
  63.             $db =RdFactory::getDBO();
  64.             $query "SELECT params " .
  65.                     "\n FROM #__components" .
  66.                     "\n WHERE parent = 0 AND `option` = '".RDCOMPONENT."' ";
  67.             $db->setQuery($query);
  68.             $this->cparams = new RdParameter($db->loadResult());
  69.         }
  70.         return $this->cparams;
  71.     }
  72.  
  73.     /**
  74.      * Get the Data
  75.      *
  76.      * @return mixed the data
  77.      */
  78.     function getData()
  79.     {
  80.         // get the view
  81.         $this->views = $this->getViews();
  82.         $data array();
  83.         // get data for a view
  84.         foreach ($this->views as $view)
  85.         {
  86.             $data[]=$this->getViewData($view);
  87.         }
  88.         $this->data = $data;
  89.  
  90.         return $data;
  91.     }
  92.  
  93.  
  94.     /**
  95.      * Get a menu parameter for this menu item
  96.      * fetch the information out of the model
  97.      *
  98.      * @param string the parameter key to get
  99.      * @param string default value
  100.      *
  101.      */
  102.     function getMenuParams($parameter$default='')
  103.     {
  104.         if ($this->mparams == null)
  105.         {
  106.             $this->mparams=$this->_state->get('parameters.menu');
  107.         }
  108.         return $this->mparams->get($parameter,$default);
  109.     }
  110.  
  111.     /**
  112.      * Get the menu params for this menu item
  113.      * fetch the information out of the model
  114.      *
  115.      *  @return parameter object Menu Parameters
  116.      */
  117.     function getMenuParamsObj()
  118.     {
  119.         if ($this->mparams == null)
  120.         {
  121.             $this->mparams=$this->_state->get('parameters.menu');
  122.         }
  123.         return $this->mparams;
  124.     }
  125.  
  126.     /**
  127.      * Get the Data for a view
  128.      *
  129.      * @param object the view sql source
  130.      * @return object the view plus additional data
  131.      */
  132.     function getViewData($view)
  133.     {
  134.         $db                         =RdFactory::getDBO();
  135.         $result                 new stdClass();
  136.         $result->title             $view->title;
  137.         $result->type            $view->type;
  138.         $result->params         new RdParameter($view->params);
  139.         $this->viewParameter     = $result->params;
  140.         $querybase                 $view->content;
  141.         $query preg_replace_callback ("/\{.+\}/",array($this,"replaceValues"),$querybase);
  142.         $db->setQuery($query);
  143.         //    echo $db->getQuery().'<br>';
  144.         $r=$db->loadObjectList();
  145.         if ($db->getErrorNum()) {
  146.             RdError::raiseWarning500$db->getErrorMsg(.'<br /><br />'.RdText::_('This was your SQL:'.'<br /><br />'.$db->getQuery(.'<br /><br />'.RdText::_('End of SQL') );
  147.         }
  148.  
  149.         if ($view->type == 'menu')
  150.         {
  151.             $r $this->sortMenu($r);
  152.         }
  153.         $result->data$r;
  154.         return $result;
  155.     }
  156.  
  157.     /**
  158.      * Get the views for a viewset
  159.      *
  160.      * @return array sql result (array of objects)
  161.      */
  162.     function getViews()
  163.     {
  164.         $db =RdFactory::getDBO();
  165.  
  166.         $viewsetId $this->getViewset();
  167.  
  168.         if $viewsetId != )
  169.         {
  170.             $query "SELECT v.* " .
  171.                     "\n FROM " .
  172.                     "\n  #__rd_sitemap_rel_viewset_has_view as r, " .
  173.                     "\n  #__rd_sitemap_view as v," .
  174.                     "\n  #__rd_sitemap_viewset as vs " .
  175.                     "\n WHERE " .
  176.                     "\n  v.id = r.view " .
  177.                     "\n  AND r.viewset = vs.id " .
  178.                     "\n  AND r.viewset = $viewsetId .
  179.                     "\n  AND v.published = '1' " .
  180.                     "\n  AND vs.published = '1' " .
  181.                     "\n ORDER BY r.ordering";
  182.             $db->setQuery($query);
  183.  
  184.             $this->views = $db->loadObjectList();
  185.             return $this->views;
  186.         }
  187.         else
  188.         {
  189.             RdError::raiseWarning500RdText::_('Can not get the Viewset'));
  190.         }
  191.         return null;
  192.     }
  193.  
  194.     /**
  195.      * Get the viewset for this request
  196.      *
  197.      * @return int the viewset id
  198.      */
  199.     function getViewset()
  200.     {
  201.         $this->viewset = (int) RdRequest::getVar('id',0);
  202.         return $this->viewset ;
  203.     }
  204.  
  205.     /**
  206.      * Replace values, callbacl function for getViewData
  207.      *
  208.      * @param array the search result
  209.      * @return string the relaced value or an empty string if the replacment fails
  210.      */
  211.     function replaceValues($m)
  212.     {
  213.         /**
  214.          * {NOW} -> Replace NOW
  215.          *
  216.          * or {Something {VAR}} -> REPLACE VAR, if not exists return an empty string
  217.          */
  218.         $str trim($m[0],'{}');
  219.         if (strpos($str,'{'=== false)
  220.         {
  221.             //{NOW}
  222.             $r=trim($str);
  223.             if(array_key_exists($r,$this->basicValues))
  224.             {
  225.                 $result $this->basicValues["$r"];
  226.                 return $result;
  227.             }
  228.         }
  229.         else
  230.         {
  231.             // {Something {VAR}}
  232.             $r=trim($str,'{}');
  233.             $s=strpos($r'{');
  234.             $e=strpos($r'}');
  235.             if ($s!==false AND $e!==false)
  236.             {
  237.                 $t1=substr($r,0,$s);
  238.                 $t2=trim(substr($r,$s,$e-$s+1));
  239.                 $t3=substr($r,$e+1);
  240.                 $t2=trim(trim($t2,'{}'));
  241.                 $param $this->viewParameter->get($t2);
  242.                 if ($param != '')
  243.                 {
  244.                     $result $t1.$param.$t3;
  245.                     return $result;
  246.                 }
  247.             }
  248.         }
  249.         return '';
  250.     }
  251.  
  252.     /**
  253.      * set up some values
  254.      */
  255.     function setUpBasisValues()
  256.     {
  257.         // NOW
  258.         $this->basicValues['NOW']=gmdate("Y-m-d H:i:s");
  259.  
  260.         // USER
  261.         $user RdFactory::getUser();
  262.         $this->basicValues['USER_ID']    =$user->id;
  263.         $this->basicValues['USER_GID']    =$user->gid;
  264.  
  265.         // ....
  266.     }
  267.  
  268.     /**
  269.      * sort a menu view
  270.      *
  271.      * @param array the menu
  272.      * @return array the sorted menu
  273.      */
  274.     function sortMenu($m)
  275.     {
  276.         $rootlevel array();
  277.         $sublevels array();
  278.         $r 0;
  279.         $s 0;
  280.         foreach ($m as $item)
  281.         {
  282.             if ($item->parent == 0)
  283.             {
  284.                 //rootlevel
  285.                 $item->ebene 0;
  286.                 $rootlevel[$r$item;
  287.                 $r++;
  288.             }
  289.             else
  290.             {
  291.                 //sublevel
  292.                 $item->ebene 1;
  293.                 $sublevels[$s$item;
  294.                 $s++;
  295.             }
  296.         }
  297.         $maxlevels=$this->viewParameter->get('maxlevels','5');
  298.         $z 0;
  299.         if ($s != AND $maxlevels != 0{
  300.             foreach ($rootlevel as $elm{
  301.                 $newmenuitems[$z$elm;
  302.                 $z++;
  303.                 $this->sortMenuRecursive($z,$elm->id,$sublevels,1,$maxlevels,$newmenuitems);
  304.             }
  305.         else {
  306.             $newmenuitems $rootlevel;
  307.         }
  308.         return $newmenuitems;
  309.     }
  310.  
  311.     /**
  312.      * sort a menu view Recursive through the tree
  313.      *
  314.      * @param int element number to work with
  315.      * @param int the parent id
  316.      * @param array the sublevels
  317.      * @param int the level
  318.      * @param int the maximun depth for the search
  319.      * @param array new menu
  320.      */
  321.     function sortMenuRecursive(&$z,$id,$sl,$ebene,$maxlevels&$nm)
  322.     {
  323.         if ($ebene $maxlevels{return true;}
  324.         foreach ($sl as $selm{
  325.             if ($selm->parent == $id{
  326.                 $selm->ebene $ebene;
  327.                 $nm[$z$selm;
  328.                 $z++;
  329.                 $nebene $ebene 1;
  330.                 $this->sortMenuRecursive($z,$selm->id,$sl,$nebene,$maxlevels,$nm);
  331.             }
  332.         }
  333.         return true;
  334.     }
  335. }
  336. ?>

Documentation generated on Thu, 23 Aug 2007 16:30:26 +0200 by phpDocumentor 1.3.2