00001 <?php
00002
00003 lt_include( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
00004 lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00005 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
00006 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00007 lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00008
00009 define( "VIEW_RESOURCE_TEMPLATE", "resource" );
00010
00017 class ViewResourceAction extends BlogAction
00018 {
00019
00020 var $_resourceId;
00021 var $_albumId;
00022 var $_albumName;
00023 var $_resourceName;
00024
00025 function ViewResourceAction( $actionInfo, $request )
00026 {
00027 $this->BlogAction( $actionInfo, $request );
00028 $this->registerFieldValidator( "resId", new IntegerValidator(), true );
00029 $this->registerFieldValidator( "resource", new StringValidator(), true );
00030 $this->registerFieldValidator( "albumId", new IntegerValidator(), true );
00031 $this->registerFieldValidator( "albumName", new StringValidator(), true );
00032
00033 if( $this->_request->getValue( "resource" ) == "" )
00034 $this->registerFieldValidator( "resId", new IntegerValidator() );
00035
00036 $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_fetching_resource" ));
00037 }
00038
00039 function perform()
00040 {
00041 lt_include( PLOG_CLASS_PATH."class/data/filter/htmlfilter.class.php" );
00042 $this->_resourceId = $this->_request->getValue( "resId" );
00043 $this->_resourceName = $this->_request->getFilteredValue( "resource", new HtmlFilter() );
00044 $this->_albumId = $this->_request->getValue( "albumId" );
00045 $this->_albumName = $this->_request->getFilteredValue( "albumName", new HtmlFilter() );
00046
00047
00048 if( $this->_albumId == "" && $this->_albumName == "")
00049 $this->_albumId = -1;
00050
00051 $galleryResources = new GalleryResources();
00052
00053
00054 $this->_view = new BlogView( $this->_blogInfo,
00055 VIEW_RESOURCE_TEMPLATE,
00056 SMARTY_VIEW_CACHE_CHECK,
00057 Array( "resourceId" => $this->_resourceId,
00058 "resourceName" => $this->_resourceName,
00059 "albumName" => $this->_albumName,
00060 "albumId" => $this->_albumId ));
00061
00062 if( $this->_view->isCached()) {
00063 $this->setCommonData();
00064 return true;
00065 }
00066
00067
00068
00069
00070 if( $this->_albumName ) {
00071 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
00072 $galleryAlbums = new GalleryAlbums();
00073 $album = $galleryAlbums->getAlbumByName( $this->_albumName, $this->_blogInfo->getId(), false, false );
00074 if( !$album ) {
00075 $this->_view = new ErrorView( $this->_blogInfo );
00076 $this->_view->setValue( "message", "error_fetching_resource" );
00077 $this->setCommonData();
00078 return false;
00079 }
00080 $this->_albumId = $album->getId();
00081 }
00082
00083
00084 if( $this->_resourceName != "" ) {
00085 $resource = $galleryResources->getResourceFile( $this->_blogInfo->getId(), $this->_resourceName, $this->_albumId );
00086 }
00087 else {
00088 $resource = $galleryResources->getResource( $this->_resourceId, $this->_blogInfo->getId(), $this->_albumId );
00089 }
00090
00091
00092 if( !$resource ) {
00093 $this->_view = new ErrorView( $this->_blogInfo );
00094 $this->_view->setValue( "message", "error_fetching_resource" );
00095 $this->setCommonData();
00096
00097 return false;
00098 }
00099
00100
00101
00102 $nextResource = $galleryResources->getNextResource( $resource );
00103 $prevResource = $galleryResources->getPreviousResource( $resource );
00104
00105
00106 $this->notifyEvent( EVENT_RESOURCE_LOADED, Array( "resource" => &$resource ));
00107 if( $nextResource ) $this->notifyEvent( EVENT_RESOURCE_LOADED, Array( "resource" => &$nextResource ));
00108 if( $prevResource ) $this->notifyEvent( EVENT_RESOURCE_LOADED, Array( "resource" => &$prevResource ));
00109 $this->_view->setValue( "resource", $resource );
00110 $this->_view->setValue( "prevresource", $prevResource );
00111 $this->_view->setValue( "nextresource", $nextResource );
00112
00113
00114 $this->_view->setPageTitle( $this->_blogInfo->getBlog()." | ".$resource->getFileName());
00115
00116 $this->setCommonData();
00117
00118
00119 return true;
00120 }
00121 }
00122 ?>