[ 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/data/validator/ -> templatesetvalidator.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH.'class/data/validator/validator.class.php' );
   4      lt_include( PLOG_CLASS_PATH.'class/file/file.class.php' );
   5  
   6      define( 'ERROR_TEMPLATE_NOT_INSIDE_FOLDER', -1 );
   7      define( 'ERROR_MISSING_BASE_FILES', -2 );
   8  
   9      /**
  10       * \ingroup Validator
  11       *
  12       * This is a more complex Validator (and a very specific one) that will validate whether
  13       * the contents of a given folder are the same of a valid template set. In order to be valid
  14       * a template folder must contain the following template files:
  15       *
  16       * - main.template
  17       * - postandcomments.template
  18       * - commentarticle.template
  19       * - posttrackbacks.template
  20       * - error.template
  21       * - album.template
  22       * - albums.template
  23       * - resource.template
  24       *
  25       * The template files should be inside a folder with the same name as template set.
  26       *
  27       * If the template set is not valid, this class will set one of the following errors:
  28       * 
  29       * - ERROR_TEMPLATE_NOT_INSIDE_FOLDER
  30       * - ERROR_MISSING_BASE_FILES
  31       *
  32       * This Validator class is also a good example of the more complex things that can be achieved
  33       * with Validator classes, not just simple data validation.
  34       */
  35      class TemplateSetValidator extends Validator 
  36      {
  37  
  38          var $_templateName;
  39          var $_folder;
  40          var $_fullName;
  41  
  42          // these are the basic files that should be present in every
  43          // template set. This array is now empty since Lifetype 1.2 supports "partial" templates
  44          // that only provide the needed files while everything else loaded from templates/default/
  45          var $_basicFiles = Array();
  46  
  47  
  48      	function TemplateSetValidator( $templateName, $folder )
  49          {
  50              $this->Validator();
  51  
  52              $this->_templateName = $templateName;
  53              $this->_folder    = $folder;
  54  
  55              $this->_fullName = $this->_folder;
  56              if( $this->_fullName[strlen($this->_fullName)-1] != '/' )
  57                  $this->_fullName[strlen($this->_fullName)] = '/';
  58              $this->_fullName .= $templateName.'/';
  59          }
  60  
  61          /**
  62           * Returns true if the template is a valid template set
  63           */
  64          function validate()
  65          {
  66              // first of all, check that the folder exists
  67              if( !File::isDir( $this->_fullName ))
  68                  return ERROR_TEMPLATE_NOT_INSIDE_FOLDER;
  69  
  70              // now check that all the basic files are available
  71              foreach( $this->_basicFiles as $basicFile ) {
  72                  if( !File::isReadable( $this->_fullName.$basicFile )) {
  73                      return ERROR_MISSING_BASE_FILES;
  74                  }
  75              }
  76  
  77              return true;
  78          }
  79      }
  80  ?>


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