| [ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/view/admin/adminsitelocaleslistview.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/file/fileupload.class.php" ); 7 lt_include( PLOG_CLASS_PATH."class/file/fileuploads.class.php" ); 8 lt_include( PLOG_CLASS_PATH."class/locale/localefinder.class.php" ); 9 10 /** 11 * \ingroup Action 12 * @private 13 * 14 * Takes care of adding new locales to the system 15 */ 16 class AdminAddLocaleAction extends AdminAction 17 { 18 19 function AdminAddLocaleAction( $actionInfo, $request ) 20 { 21 $this->AdminAction( $actionInfo, $request ); 22 23 // decide what to do based on which submit button was clicked 24 if( $this->_request->getValue( "addLocale" ) != "" ) 25 $this->_op = "uploadLocale"; 26 else 27 $this->_op = "scanLocales"; 28 29 $this->requireAdminPermission( "add_locale" ); 30 } 31 32 function validate() 33 { 34 // first of all, we have to see if the name of the file is valid 35 if( $this->_op == "uploadLocale" ) { 36 $files = HttpVars::getFiles(); 37 38 $upload = new FileUpload( $files["localeFile"] ); 39 40 if( !Locales::isValidLocaleFileName( $upload->getFileName())) { 41 $this->_view = new AdminTemplatedView( $this->_blogInfo, "newlocale" ); 42 $this->_view->setErrorMessage( $this->_locale->tr("error_invalid_locale_file")); 43 $this->setCommonData(); 44 return false; 45 } 46 } 47 48 return true; 49 } 50 51 /** 52 * scans the locale folder looking for new locales 53 * 54 * @return always true 55 * @private 56 */ 57 function _performScanLocales() 58 { 59 $locales = new Locales(); 60 61 // find all the new locales that we have not yet stored 62 $f = new LocaleFinder(); 63 $newLocaleCodes = $f->find(); 64 65 // success message 66 $successMessage = ""; 67 68 // set up the view 69 $this->_view = new AdminSiteLocalesListView( $this->_blogInfo ); 70 71 // if there are no new locales, there's no point in doing anything! 72 if( count( $newLocaleCodes ) == 0 ) { 73 $this->_view->setErrorMessage( $this->_locale->tr("error_no_new_locales_found" )); 74 return false; 75 } 76 77 foreach( $newLocaleCodes as $newLocaleCode ) { 78 // add the locale to the config settings 79 $res = $locales->addLocale( $newLocaleCode ); 80 81 // and create a success message 82 $successMessage .= $this->_locale->pr("locale_added_ok", $newLocaleCode)."<br/>"; 83 } 84 85 if( $successMessage != "" ) $this->_view->setSuccessMessage( $successMessage ); 86 87 return true; 88 } 89 90 function _performUploadLocale() 91 { 92 // since we are here, the file name was validated to be ok, so we can 93 // continue with the operation 94 $files = HttpVars::getFiles(); 95 $uploads = new FileUploads( $files ); 96 97 $this->_view = new AdminSiteLocalesListView( $this->_blogInfo ); 98 99 // we can first of all move the file to the destionation folder 100 $result = $uploads->process( $this->_config->getValue( "locale_folder" )); 101 102 // the only thing that can happen is that the file was not correctly saved 103 if( $result[0]->getError() != 0 ) { 104 $this->_view->setErrorMessage( $this->_locale->tr("error_saving_locale")); 105 return false; 106 } 107 108 // and once it's there, we can do as if we were adding a locale code 109 $upload = new FileUpload( $files["localeFile"] ); 110 $res = preg_match( REGEXP_VALID_LOCALE, $upload->getFileName(), $matches ); 111 $localeCode = $matches[1]; 112 113 // add the file to the list of locales 114 $locales = new Locales(); 115 $locales->addLocale( $localeCode ); 116 117 $this->_view->setSuccessMessage( $this->_locale->pr( "locale_added_ok", $localeCode )); 118 119 return true; 120 } 121 122 function perform() 123 { 124 if( $this->_op == "scanLocales" ) 125 $result = $this->_performScanLocales(); 126 else 127 $result = $this->_performUploadLocale(); 128 129 $this->setCommonData(); 130 131 return $result; 132 } 133 } 134 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
|