[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/template/templatesets/ -> templatesets.class.php (source)

   1  <?php
   2  
   3      
   4      lt_include( PLOG_CLASS_PATH."class/template/templatesets/templateset.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/template/templatesets/templatesetstorage.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/template/templateservice.class.php" );
   7  
   8      /**
   9       * \ingroup Template
  10       * 
  11       * Takes care of retrieving information about template sets. By using this class
  12       * we can know which template sets are globally available, or which blog-specific templates
  13       * a blog has.
  14       *
  15       * The relation between this class, TemplateService and TemplateSetStorage is that TemplateService
  16       * takes care of generating the right object (CachedTemplate, PluginTemplate, Template) when
  17       * needed for rendering template pages. TemplateSets deals with the logical information (does it have an
  18       * screenshot? Is it a local template?) and TemplateStorage deals with adding
  19       * templates, removing them from disk, etc.
  20       */
  21      class TemplateSets 
  22      {
  23  
  24  		function TemplateSets()
  25          {
  26              
  27          }
  28  
  29          /**
  30           * Returns all the template sets that are available for a given blog, including global
  31           * templates by default. 
  32           *
  33           * @param blogId The id of the blog
  34           * @param includeGlobal Whether global templates should be included, or else only
  35           * blog-specific templates will be returned.
  36           * @return An array of TemplateSet objects
  37           */
  38  		function getBlogTemplateSets( $blogId, $includeGlobal = true )
  39          {
  40              $blogTemplates = $this->getBlogTemplates( $blogId );
  41  
  42              if( $includeGlobal )
  43                  $templateSets = $this->getGlobalTemplateSets();
  44              else
  45                  $templateSets = Array();
  46  
  47              // now loop through the list and create the TemplateSet objects
  48              foreach( $blogTemplates as $template ) {
  49                  $templateSet = new TemplateSet( $template, TEMPLATE_SET_BLOG_SPECIFIC, $blogId );
  50                  array_push( $templateSets, $templateSet );
  51              }
  52  
  53              return $templateSets;
  54          }
  55  
  56          /**
  57           * Returns all the global template sets that are available to all blogs
  58           *
  59           * @return returns an array of TemplateSet objects with all the global templates
  60           */
  61  		function getGlobalTemplateSets()
  62          {
  63              // get the list of global templates
  64              $globalTemplates = $this->getGlobalTemplates();
  65  
  66              // now loop through the list and create the TemplateSet objects
  67              $templateSets = Array();
  68              foreach( $globalTemplates as $template ) {
  69                  $templateSet = new TemplateSet( $template, TEMPLATE_SET_GLOBAL );
  70                  array_push( $templateSets, $templateSet );
  71              }
  72  
  73              return $templateSets;
  74          }
  75  
  76  
  77          /**
  78           * Returns an array that contains the name of all the 'global' templates
  79           * available.
  80           *
  81           * @return Returns an array of strings with the name of the template sets
  82           */
  83          function getGlobalTemplates()
  84          {
  85              $config =& Config::getConfig();
  86  
  87              $templates = $config->getValue( "templates" );
  88  
  89              if( !is_array($templates))
  90                  $templates = Array();
  91  
  92              return $templates;
  93          }
  94  
  95          /**
  96           * Returns a list with all the custom templates available *only*
  97           * to this blog.
  98           *
  99           * @return An array of string containing the identifiers of the template
 100           * sets available for the given blog
 101           */
 102          function getBlogTemplates( $blogId )
 103          {
 104              lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );        
 105              $blogs = new Blogs();
 106              $blogInfo = $blogs->getBlogInfo( $blogId );
 107              $blogSettings = $blogInfo->getSettings();
 108  
 109              $templates = $blogSettings->getValue( "blog_templates" );
 110  
 111              if( $templates == "" || !$templates )
 112                  $templates = Array();
 113  
 114              return $templates;
 115          }
 116  
 117          /**
 118           * Returns an array with all the global templates and the custom ones
 119           * from the given blog.
 120           *
 121           * @return Array
 122           * @see Config::getGlobalTemplates
 123           * @see Config::getBlogTemplates
 124           */
 125          function getAllTemplates( $blogId )
 126          {
 127              $globalTemplates = $this->getGlobalTemplates();
 128              $blogTemplates   = $this->getBlogTemplates( $blogId );
 129  
 130              $allTemplates = Array();
 131              foreach( $globalTemplates as $template )
 132                  array_push( $allTemplates, $template );
 133              foreach( $blogTemplates as $template )
 134                  array_push( $allTemplates, $template );
 135  
 136              return $allTemplates;
 137          }
 138  
 139          /**
 140           * Returns a TemplateSet object with information about the template. If there are a local
 141           * template and a global template with the same template id, the global template will <b>ALWAYS</b>
 142           * have more priority!
 143           *
 144           * @param templateName the name of the template
 145           * @param blogId 0 if the template is global or the blog id otherwise
 146           * @return a TemplateSet object, or 'null' if the template does not exist at all
 147           */
 148  		function getTemplateSet( $templateName, $blogId = 0 )
 149          {
 150              if( $this->isTemplate( $templateName ))
 151                  $templateSet = new TemplateSet( $templateName, TEMPLATE_SET_GLOBAL, 0 );
 152              elseif( $this->isBlogTemplate( $templateName, $blogId ))
 153                  $templateSet = new TemplateSet( $templateName, TEMPLATE_SET_BLOG_SPECIFIC, $blogId );
 154              else {
 155                  $templateSet = null;
 156              }
 157  
 158              return $templateSet;
 159          }
 160  
 161  
 162          /**
 163           * Returns true if the template is a valid global template set, or false otherwise.
 164           *
 165           * @param templateName The name of the template.
 166           */
 167          function isTemplate( $templateName )
 168          {
 169              $config =& Config::getConfig();
 170              $templates = $config->getValue( "templates" );
 171  
 172              if( !is_array($templates))
 173                  return false;
 174  
 175              return in_array( $templateName, $templates );
 176          }
 177  
 178          /**
 179           * Returns true if the template is a valid blog template set, or false otherwise.
 180           *
 181           * @param templateName The name of the template.
 182           * @param blogId The identifier of the blog we'd like to check
 183           */
 184          function isBlogTemplate( $templateName, $blogId )
 185          {
 186              lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );        
 187              $blogs = new Blogs();
 188              $blog = $blogs->getBlogInfo( $blogId );
 189              $blogSettings = $blog->getSettings( $blogId );
 190  
 191              // get the array with the template names stored in the settings
 192              $blogTemplates = $blogSettings->getValue( "blog_templates" );
 193              if( empty($blogTemplates) || $blogTemplates == false )
 194                  return false;
 195  
 196              return in_array( $templateName, $blogTemplates );
 197          }
 198  
 199          /**
 200           * returns the default template set that has been configured in this site
 201           *
 202           * @return A TemplateSet object
 203           */
 204          function getDefaultTemplateSet()
 205          {
 206               $config =& Config::getConfig();
 207               return( $this->getTemplateSet( $config->getValue( "default_template" )));
 208          }
 209      }
 210  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics