[ 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/view/admin/adminresourceslistview.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/view/admin/adminnewresourceview.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" ); 7 lt_include( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" ); 8 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" ); 9 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" ); 10 lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" ); 11 lt_include( PLOG_CLASS_PATH."class/view/admin/chooser/adminsimpleresourceslistview.class.php" ); 12 lt_include( PLOG_CLASS_PATH."class/view/admin/chooser/adminuserpictureselectview.class.php" ); 13 lt_include( PLOG_CLASS_PATH."class/view/admin/adminresourceslistview.class.php" ); 14 lt_include( PLOG_CLASS_PATH."class/file/fileupload.class.php" ); 15 16 /** 17 * \ingroup Action 18 * @private 19 * 20 * Adds a new resource to an album 21 */ 22 class AdminAddResourceAction extends AdminAction 23 { 24 25 var $_description; 26 var $_albumId; 27 var $_resource; 28 var $_destView; 29 30 /** 31 * Constructor. If nothing else, it also has to call the constructor of the parent 32 * class, BlogAction with the same parameters 33 */ 34 function AdminAddResourceAction( $actionInfo, $request ) 35 { 36 $this->AdminAction( $actionInfo, $request ); 37 38 $this->registerFieldValidator( "resourceFile_1", new ArrayValidator(), true); 39 $this->registerFieldValidator( "albumId", new IntegerValidator()); 40 $this->_destView = $this->_request->getValue( "destView" ); 41 $this->_form->registerField( "resourceDescription" ); 42 $this->_form->registerField( "destination" ); 43 44 if( $this->_destView == "resourceList" ) 45 $view = new AdminSimpleResourcesListView( $this->_blogInfo, Array( "albumId" => 0 )); 46 elseif ($this->_destView == "userPictureSelect" ) 47 $view = new AdminUserPictureSelectView( $this->_blogInfo, Array( "albumId" => 0 )); 48 else 49 $view = new AdminNewResourceView( $this->_blogInfo ); 50 51 $view->setErrorMessage( $this->_locale->tr( "error_no_resource_uploaded" )); 52 $this->setValidationErrorView( $view ); 53 54 $this->requirePermission( "add_resource" ); 55 56 } 57 58 /** 59 * Carries out the specified action 60 */ 61 function perform() 62 { 63 // are resources enabled? 64 $config =& Config::getConfig(); 65 if( !$config->getValue( "resources_enabled", true )) { 66 $this->_view = new AdminResourcesListView( $this->_blogInfo ); 67 $this->_view->setErrorMessage( $this->_locale->tr("error_resources_disabled")); 68 $this->setCommonData(); 69 return false; 70 } 71 72 73 // fetch the information coming from the resource 74 $this->_description = Textfilter::filterAllHTML($this->_request->getValue( "resourceDescription" )); 75 $this->_albumId = $this->_request->getValue( "albumId" ); 76 $this->_resource = $this->_request->getValue( "resourceFile" ); 77 $this->_destination = $this->_request->getValue( "destination" ); 78 79 // check if there is any file uploaded 80 $files = HttpVars::getFiles(); 81 // we probably need to rearrange the $files array a bit better... 82 $this->_files = Array(); 83 foreach( $files as $file ) { 84 if( $file["error"] == 0 && $file["size"] > 0 && $file["name"] != "" ) { 85 $this->_files[] = $file; 86 } 87 } 88 89 // let the gallery library do its work... 90 $resources = new GalleryResources(); 91 92 if( $this->_destView == "resourceList" ) { 93 $this->_view = new AdminSimpleResourcesListView( $this->_blogInfo, Array( "albumId" => $this->_albumId )); 94 $this->_view->setValue( "destination", $this->_destination ); 95 } 96 elseif ($this->_destView == "userPictureSelect" ) { 97 $this->_view = new AdminUserPictureSelectView( $this->_blogInfo, Array( "albumId" => 0 )); 98 $this->_view->setValue( "destination", $this->_destination ); 99 } 100 else 101 $this->_view = new AdminResourcesListView( $this->_blogInfo, Array( "albumId" => $this->_albumId )); 102 103 $successMessage = ""; 104 $errorMessage = ""; 105 106 foreach( $this->_files as $file ) { 107 108 // create a new FileUpload object based on the file 109 $upload = new FileUpload( $file ); 110 111 // add the resource to the db 112 $this->notifyEvent( EVENT_PRE_RESOURCE_ADD, Array( "upload" => &$upload )); 113 $res = $resources->addResource( $this->_blogInfo->getId(), $this->_albumId, 114 $this->_description, $upload ); 115 116 // check if everything went fine and if not, show an error message 117 if( $res > 0 ) { 118 $successMessage .= $this->_locale->pr("resource_added_ok", $file["name"])."<br/>"; 119 // try to fetch the resource so that we can send it in the event 120 $resource = $resources->getResource( $res, $this->_blogInfo->getId()); 121 $this->notifyEvent( EVENT_POST_RESOURCE_ADD, Array( "resource" => &$resource )); 122 } 123 else { 124 if( $res == GALLERY_ERROR_RESOURCE_FORBIDDEN_EXTENSION ) 125 $errorMessage .= $this->_locale->pr("error_resource_forbidden_extension", $file["name"])."<br/>"; 126 elseif( $res == GALLERY_ERROR_RESOURCE_NOT_WHITELISTED_EXTENSION ) 127 $errorMessage .= $this->_locale->pr("error_resource_not_whitelisted_extension", $file["name"])."<br/>"; 128 elseif( $res == GALLERY_ERROR_RESOURCE_TOO_BIG ) 129 $errorMessage .= $this->_locale->pr("error_resource_too_big", $file["name"])."<br/>"; 130 elseif( $res == GALLERY_ERROR_UPLOADS_NOT_ENABLED ) 131 $errorMessage .= $this->_locale->tr("error_uploads_disabled" )."<br/>"; 132 elseif( $res == GALLERY_ERROR_QUOTA_EXCEEDED ) 133 $errorMessage .= $this->_locale->tr( "error_quota_exceeded" )."<br/>"; 134 else 135 $errorMessage .= $this->_locale->pr("error_adding_resource", $file["name"])."<br/>"; 136 } 137 } 138 139 // clear the cache no matter what happened... we should only clear it if there was at least one 140 // file uploaded but this way is not that bad after all... 141 CacheControl::resetBlogCache( $this->_blogInfo->getId(), false ); 142 143 if( $successMessage != "" ) $this->_view->setSuccessMessage( $successMessage ); 144 if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage ); 145 $this->setCommonData(); 146 147 return true; 148 } 149 } 150 ?>
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 |
![]() |