[ 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/action/admin/ -> adminaddblogtemplateaction.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/action/admin/adminaddtemplateaction.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/file/unpacker/unpacker.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/view/admin/adminblogtemplatesetslistview.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/template/templatesets/templatesetstorage.class.php" );
   9      lt_include( PLOG_CLASS_PATH."class/template/templatesandbox.class.php" );
  10      lt_include( PLOG_CLASS_PATH."class/file/fileuploads.class.php" );
  11  
  12      /**
  13       * \ingroup Action
  14       * @private
  15       *
  16       * Shows a form to add a new locale file
  17       */
  18      class AdminAddBlogTemplateAction extends AdminAction
  19      {
  20  
  21          var $_op;
  22  
  23          function AdminAddBlogTemplateAction( $actionInfo, $request )
  24          {
  25              $this->AdminAction( $actionInfo, $request );
  26  
  27              // decide what to do based on which submit button was pressed
  28              if( $this->_request->getValue( "addBlogTemplate" ) != "" )
  29                  $this->_op = "addBlogTemplate";
  30              else
  31                  $this->_op = "scanBlogTemplates";
  32                  
  33              $this->requirePermission( "add_blog_template" );                
  34          }
  35  
  36          function validate()
  37          {
  38              //
  39              // first of all, let's make sure that users are allowed to
  40              // add new templates
  41              //
  42              $config =& Config::getConfig();
  43              if( !$config->getValue( "users_can_add_templates" )) {
  44                  $this->_view = new AdminBlogTemplateSetsListView( $this->_blogInfo );
  45                  $this->_view->setErrorMessage( $this->_locale->tr("error_add_template_disabled"));
  46                  $this->setCommonData();
  47  
  48                  return false;
  49              }
  50  
  51              return parent::validate();
  52          }
  53  
  54          function _performUploadTemplate()
  55          {
  56              // get the temporary folder
  57              $config =& Config::getConfig();
  58              $tmpFolder = $config->getValue( "temp_folder" );
  59  
  60              // move it to the temporary folder
  61              $files    = HttpVars::getFiles();
  62  
  63              if( count($files) == 0 || $files["templateFile"]["name"] == "") {
  64                  $this->_view = new AdminTemplatedView( $this->_blogInfo, "newblogtemplate" );
  65                  $this->_view->setValue( "templateFolder", TemplateSetStorage::getBlogBaseTemplateFolder( $this->_blogInfo->getId()));
  66                  $this->_view->setErrorMessage( $this->_locale->tr("error_must_upload_file"));
  67                  $this->setCommonData();
  68                  return false;
  69              }
  70  
  71              $uploads  = new FileUploads( $files );
  72              
  73              if( $this->userHasPermission( "view_blog_templates" ))
  74                  $this->_view = new AdminBlogTemplateSetsListView( $this->_blogInfo );
  75              else
  76                  $this->_view = new AdminTemplatedView( $this->_blogInfo, "newblogtemplate" );
  77  
  78              $result = $uploads->process( $tmpFolder );
  79              if( $result < 0 ) {
  80                  $this->_view->setErrorMessage( $this->_locale->tr("error_uploads_disabled"));
  81                  $this->setCommonData();
  82  
  83                  return false;
  84              }
  85  
  86              $upload   = new FileUpload( $files["templateFile"] );
  87              $templateName = TemplateSandbox::toTemplateSetName( $upload->getFileName() );            
  88  
  89              // Check the template set exist or not
  90              if( TemplateSets::isTemplate( $templateName ) || TemplateSets::isBlogTemplate( $templateName, $this->_blogInfo->getId() ) ) {
  91                  $this->_view->setErrorMessage( $this->_locale->pr("error_template_exist", $templateName));
  92                  $this->setCommonData();
  93  
  94                  return false;
  95              }
  96  
  97              // and make it go through the template sandbox to check if
  98              // we're dealing with a 'healthy' file
  99              $templateSandbox = new TemplateSandbox();
 100              $valid = $templateSandbox->checkTemplateSet( $upload->getFileName(), $tmpFolder."/");
 101  
 102              if( $valid < 0 ) {
 103                  $this->_view->setErrorMessage( AdminAddTemplateAction::_checkTemplateSandboxResult( $valid ));
 104                  $this->setCommonData();
 105  
 106                  return false;
 107              }
 108  
 109              //
 110              // :KLUDGE:
 111              //
 112              // maybe we should simply move the files rather than unpacking the whole
 113              // thing again, but this indeed makes things easier! ;)
 114              //
 115  
 116              // since it is a local template, the path has to be $template_folder/blog_x/$templateName
 117              $ts = new TemplateSetStorage();
 118              $blogTemplateFolder = $ts->createBlogTemplateFolder( $this->_blogInfo->getId());
 119  
 120              // it should be there now... we can continue
 121              $destFolder = $blogTemplateFolder."/";
 122  
 123              $unpacker = new Unpacker();
 124              if( !$unpacker->unpack( $tmpFolder."/".$upload->getFileName(), $destFolder )) {
 125                  $this->_view->setErrorMessage( $this->_locale->tr("error_installing_template"));
 126                  $this->setCommonData();
 127  
 128                  // remove the file before returning!
 129                  File::delete( $tmpFolder."/".$upload->getFileName());
 130  
 131                  return false;
 132              }
 133  
 134              // if the template set was installed ok in the template folder, we can record
 135              // it as a valid set
 136              $ts->addTemplate( $templateName, $this->_blogInfo->getId());
 137  
 138              // remove the file
 139              File::delete( $tmpFolder."/".$upload->getFileName());
 140  
 141              $this->_view->setSuccessMessage( $this->_locale->pr("template_installed_ok", $templateName));
 142              $this->setCommonData();
 143  
 144              return true;
 145          }
 146  
 147  
 148          /**
 149           * @private
 150           */
 151  		function _addTemplateCode( $templateName )
 152          {
 153              $config =& Config::getConfig();
 154              $templateFolder = $config->getValue( "template_folder" );
 155  
 156              $ts = new TemplateSetStorage();
 157  
 158              $this->_view = new AdminBlogTemplateSetsListView( $this->_blogInfo );
 159  
 160              // make sure that the template is valid
 161              $templateSandbox = new TemplateSandbox();
 162              $valid = $templateSandbox->checkTemplateFolder( $templateName, $ts->getBlogBaseTemplateFolder( $this->_blogInfo->getId()));
 163              if( $valid < 0 ) {
 164                  $this->_errorMessage .= $this->_locale->pr( 'error_installing_template', $templateName ).': '.AdminAddTemplateAction::_checkTemplateSandboxResult( $valid ).'<br/>';
 165                  $result = false;
 166              }
 167              else {
 168                  // otherwise, we can add it without problems
 169                  $ts->addTemplate( $templateName, $this->_blogInfo->getId());
 170                  $this->_successMessage .=  $this->_locale->pr( "template_installed_ok", $templateName )."<br/>";
 171                  $result = true;
 172              }
 173  
 174              $this->setCommonData();
 175              return $result;
 176          }
 177          
 178          /**
 179           * scans the templates folder looking for new files
 180           *
 181           * @private
 182           */
 183  		function _performScanTemplateFolder()
 184          {
 185              $this->_errorMessage = "";
 186              $this->_successMessage = "";        
 187          
 188              // set up the view
 189              if( $this->userHasPermission( "view_blog_templates" ))
 190                  $this->_view = new AdminBlogTemplateSetsListView( $this->_blogInfo );        
 191              else
 192                  $this->_view = new AdminTemplatedView( $this->_blogInfo, "newblogtemplate" );
 193          
 194              // and tell the template finder to find any new template file...
 195              $tf = new TemplateFinder( TemplateSetStorage::getBlogBaseTemplateFolder( $this->_blogInfo->getId()));
 196              $newTemplates = $tf->find( TemplateSets::getBlogTemplates( $this->_blogInfo->getId()));
 197              
 198              $this->_errorMessage = "";
 199              $this->_successMessage = "";
 200              
 201              if( count($newTemplates) == 0 ) {
 202                  // no new templates found
 203                  $this->_errorMessage = $this->_locale->tr( 'error_no_new_templates_found' );
 204              }
 205              else {
 206                  // now add each one of the new ones
 207                  foreach( $newTemplates as $newTemplate ) {
 208                      $this->_addTemplateCode( $newTemplate );
 209                  }
 210              }
 211              
 212              // set the success and error messages, if any
 213              if( $this->_errorMessage != '' ) $this->_view->setErrorMessage( $this->_errorMessage );
 214              if( $this->_successMessage != '' ) $this->_view->setSuccessMessage( $this->_successMessage );
 215              
 216              $this->setCommonData();
 217              
 218              return true;
 219          }        
 220  
 221          function perform()
 222          {
 223              if( $this->_op == "addBlogTemplate" ) {
 224                  $result = $this->_performUploadTemplate();
 225              }
 226              elseif( $this->_op == "scanBlogTemplates" ) {
 227                  $result = $this->_performScanTemplateFolder();
 228              }
 229              else {
 230                  throw( new Exception( "You shouldn't be seeing this!!! :)" ));
 231                  die();
 232              }
 233  
 234              // We should update the session too, or we will get data dirty
 235              lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
 236              $blogs = new Blogs();
 237              $blogInfo = $blogs->getBlogInfo( $this->_blogInfo->getId() );
 238              $this->_session->setValue( "blogInfo", $blogInfo );
 239              $this->saveSession();
 240              
 241              return $result;
 242          }
 243      }
 244  ?>


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