NewsFeaturesDownloadsDevelopmentSupportAbout Us

lifetype-1.1.6/class/action/admin/adminaddlocaleaction.class.php

Go to the documentation of this file.
00001 <?php
00002 
00003         include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
00004     include_once( PLOG_CLASS_PATH."class/locale/locales.class.php" );
00005         include_once( PLOG_CLASS_PATH."class/view/admin/adminsitelocaleslistview.class.php" );
00006     include_once( PLOG_CLASS_PATH."class/file/fileupload.class.php" );
00007     include_once( PLOG_CLASS_PATH."class/file/fileuploads.class.php" );
00008         include_once( PLOG_CLASS_PATH."class/locale/localefinder.class.php" );
00009 
00016     class AdminAddLocaleAction extends SiteAdminAction 
00017         {
00018 
00019         function AdminAddLocaleAction( $actionInfo, $request )
00020         {
00021                 $this->SiteAdminAction( $actionInfo, $request );
00022 
00023                 // decide what to do based on which submit button was clicked
00024                 if( $this->_request->getValue( "addLocale" ) != "" )
00025                         $this->_op = "uploadLocale";
00026                 else
00027                         $this->_op = "scanLocales";
00028         }
00029 
00030         function validate()
00031         {
00032                 // first of all, we have to see if the name of the file is valid
00033                 if( $this->_op == "uploadLocale" ) {
00034                     $files = HttpVars::getFiles();
00035 
00036                     $upload = new FileUpload( $files["localeFile"] );
00037 
00038                     if( !Locales::isValidLocaleFileName( $upload->getFileName())) {
00039                         $this->_view = new AdminTemplatedView( $this->_blogInfo, "newlocale" );
00040                         $this->_view->setErrorMessage( $this->_locale->tr("error_invalid_locale_file"));
00041                         $this->setCommonData();
00042                         return false;
00043                 }
00044                 }
00045 
00046                 return true;
00047         }
00048 
00055         function _performScanLocales()
00056         {
00057                 $locales = new Locales();
00058 
00059                 // find all the new locales that we have not yet stored
00060                 $f = new LocaleFinder();
00061                 $newLocaleCodes = $f->find();
00062 
00063                 // success message
00064                 $successMessage = "";
00065 
00066                 // set up the view
00067                 $this->_view = new AdminSiteLocalesListView( $this->_blogInfo );
00068 
00069                 // if there are no new locales, there's no point in doing anything!
00070                 if( count( $newLocaleCodes ) == 0 ) {
00071                         $this->_view->setErrorMessage( $this->_locale->tr("error_no_new_locales_found" ));
00072                         return false;
00073                 }
00074 
00075                 foreach( $newLocaleCodes as $newLocaleCode ) {
00076                         // add the locale to the config settings
00077                         $res = $locales->addLocale( $newLocaleCode );
00078 
00079                         // and create a success message
00080                         $successMessage .= $this->_locale->pr("locale_added_ok", $newLocaleCode)."<br/>";
00081                 }
00082 
00083                 if( $successMessage != "" ) $this->_view->setSuccessMessage( $successMessage );
00084 
00085                 return true;
00086         }
00087 
00088         function _performUploadLocale()
00089         {
00090                 // since we are here, the file name was validated to be ok, so we can
00091             // continue with the operation
00092             $files = HttpVars::getFiles();
00093             $uploads = new FileUploads( $files );
00094 
00095                         $this->_view = new AdminSiteLocalesListView( $this->_blogInfo );
00096 
00097             // we can first of all move the file to the destionation folder
00098             $result = $uploads->process( $this->_config->getValue( "locale_folder" ));
00099 
00100             // the only thing that can happen is that the file was not correctly saved
00101             if( $result[0]->getError() != 0 ) {
00102                 $this->_view->setErrorMessage( $this->_locale->tr("error_saving_locale"));
00103                 return false;
00104             }
00105 
00106             // and once it's there, we can do as if we were adding a locale code
00107             $upload = new FileUpload( $files["localeFile"] );
00108             $res = preg_match( REGEXP_VALID_LOCALE, $upload->getFileName(), $matches );
00109                 $localeCode = $matches[1];
00110 
00111                 // add the file to the list of locales
00112             $locales = new Locales();
00113             $locales->addLocale( $localeCode );
00114 
00115                 $this->_view->setSuccessMessage( $this->_locale->pr( "locale_added_ok", $localeCode ));
00116 
00117                 return true;
00118         }
00119 
00120         function perform()
00121         {
00122             if( $this->_op == "scanLocales" )
00123                 $result = $this->_performScanLocales();
00124             else
00125                 $result = $this->_performUploadLocale();
00126 
00127                 $this->setCommonData();
00128 
00129             return $result;
00130         }
00131     }
00132 ?>