00001 <?php
00002
00003
00004 define( 'RESOURCE_VIEW_MODE_DEFAULT', '' );
00005 define( 'RESOURCE_VIEW_MODE_PREVIEW', 'preview' );
00006 define( 'RESOURCE_VIEW_MODE_MEDIUM', 'medium' );
00007
00008 lt_include( PLOG_CLASS_PATH."class/action/action.class.php" );
00009 lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
00010 lt_include( PLOG_CLASS_PATH."class/view/redirectview.class.php" );
00011 lt_include( PLOG_CLASS_PATH."class/net/http/subdomains.class.php" );
00012 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00013 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
00014 lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00015 lt_include( PLOG_CLASS_PATH."class/data/validator/usernamevalidator.class.php" );
00016 lt_include( PLOG_CLASS_PATH."class/data/validator/domainvalidator.class.php" );
00017 lt_include( PLOG_CLASS_PATH."class/data/validator/blognamevalidator.class.php" );
00018 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00019
00024 class ResourceServerAction extends Action
00025 {
00026 var $_mode;
00027 var $_resource;
00028 var $_resId;
00029 var $_album;
00030 var $_config;
00031 var $_blogInfo;
00032
00033 function ResourceServerAction( $actionInfo, $request )
00034 {
00035 $this->Action( $actionInfo, $request );
00036
00037
00038 $session = HttpVars::getSession();
00039 $this->_session = $session['SessionInfo'];
00040
00041 $this->_config =& Config::getConfig();
00042
00043 $this->registerFieldValidator( "resource", new StringValidator(), true );
00044 $this->registerFieldValidator( "resId", new IntegerValidator(), true );
00045 $this->registerFieldValidator( "albumId", new IntegerValidator(), true );
00046 $this->registerFieldValidator( "albumName", new StringValidator(), true );
00047 $this->registerFieldValidator( "blogId", new IntegerValidator(), true );
00048 $this->registerFieldValidator( "blogDomain", new DomainValidator(), true );
00049 $this->registerFieldValidator( "blogName", new BlogNameValidator(), true );
00050 $this->registerFieldValidator( "userId", new IntegerValidator(), true );
00051 $this->registerFieldValidator( "blogUserName", new UsernameValidator(), true );
00052
00053
00054
00055 $view = new View();
00056 $view->addHeaderResponse( "HTTP/1.1 404 Not Found" );
00057 $view->addHeaderResponse( "Status: 404 Not Found" );
00058 $view->addHeaderResponse( "X-LifeType-Error: Invalid parameters" );
00059 $this->setValidationErrorView( $view );
00060 }
00061
00066 function _getBlogInfo()
00067 {
00068
00069 $config =& Config::getConfig();
00070 if( $config->getValue( "subdomains_enabled" )) {
00071 $subdomainInfo = Subdomains::getSubdomainInfoFromRequest();
00072
00073 if( !empty($subdomainInfo["blogdomain"]) && $this->_request->getValue( 'blogDomain' ) == "" ) {
00074 $this->_request->setValue( 'blogDomain', $subdomainInfo["blogdomain"] );
00075 }
00076 if( !empty($subdomainInfo["username"]) && $this->_request->getValue( 'blogUserName' ) == "" ) {
00077 $this->_request->setValue( 'blogUserName', $subdomainInfo["username"] );
00078 }
00079 if( !empty($subdomainInfo["blogname"]) && $this->_request->getValue( 'blogName' ) == "" ) {
00080 $this->_request->setValue( 'blogName', $subdomainInfo["blogname"] );
00081 }
00082 }
00083
00084 $blogId = $this->_request->getValue( 'blogId' );
00085 $blogName = $this->_request->getValue( 'blogName' );
00086 $userId = $this->_request->getValue( 'userId' );
00087 $userName = $this->_request->getValue( 'blogUserName' );
00088 $blogDomain = $this->_request->getValue( 'blogDomain' );
00089
00090
00091
00092 if( !$blogId && !$blogName && !$blogDomain) {
00093
00094 if( !empty($userName) ) {
00095
00096 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
00097 $users = new Users();
00098 $userInfo = $users->getUserInfoFromUsername( $userName );
00099
00100 if( $userInfo ) {
00101 $userBlogs = $users->getUsersBlogs( $userInfo->getId(), BLOG_STATUS_ACTIVE );
00102
00103
00104 if( !empty($userBlogs)) {
00105 $blogId = $userBlogs[0]->getId();
00106 } else{
00107 $blogId = $this->_config->getValue('default_blog_id');
00108 }
00109 } else{
00110 $blogId = $this->_config->getValue('default_blog_id');
00111 }
00112 }
00113 else {
00114
00115 if( $this->_session->getValue('blogId') != '' ) {
00116 $blogId = $this->_session->getValue('blogId');
00117 }
00118 else {
00119
00120 $blogId = $this->_config->getValue('default_blog_id');
00121 }
00122 }
00123 }
00124
00125
00126 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00127 $blogs = new Blogs();
00128 if( $blogId ) {
00129 $this->_blogInfo = $blogs->getBlogInfo( $blogId );
00130 }
00131 else if($blogName){
00132 $this->_blogInfo = $blogs->getBlogInfoByName( $blogName );
00133 }
00134 else if($blogDomain){
00135 $this->_blogInfo = $blogs->getBlogInfoByDomain( $blogDomain );
00136 }
00137 else{
00138 $this->_blogInfo = false;
00139 }
00140 }
00141
00142 function validate()
00143 {
00144 if( !parent::validate())
00145 return false;
00146
00147
00148 $this->_getBlogInfo();
00149 if( $this->_blogInfo == false ) {
00150
00151 $this->_view = new View();
00152 $this->_view->addHeaderResponse( "HTTP/1.1 404 Not Found" );
00153 $this->_view->addHeaderResponse( "Status: 404 Not Found" );
00154 $this->_view->addHeaderResponse( "X-LifeType-Error: Blog $resId is not correct" );
00155
00156 return false;
00157 }
00158
00159
00160 $this->_resName = $this->_request->getValue( "resource" );
00161 $this->_resId = $this->_request->getValue( "resId" );
00162 $this->_albumId = $this->_request->getValue( "albumId" );
00163 $this->_albumName = $this->_request->getValue( "albumName" );
00164 $this->_mode = $this->_request->getValue( "mode" );
00165
00166
00167
00168 if( !empty($this->_albumId) || !empty($this->_albumName)) {
00169 if( $this->_albumName ) {
00170 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
00171 $albums = new GalleryAlbums();
00172 $album = $albums->getAlbumByName( $this->_albumName );
00173 if( !$album ) {
00174 $this->_view = new View();
00175 $this->_view->addHeaderResponse( "HTTP/1.1 404 Not Found" );
00176 $this->_view->addHeaderResponse( "Status: 404 Not Found" );
00177 $this->_view->addHeaderResponse( "X-LifeType-Error: Album $albumId not found" );
00178 return false;
00179 }
00180 $this->_albumId = $album->getId();
00181 }
00182 }
00183
00184 return true;
00185 }
00186
00187 function perform()
00188 {
00189
00190 $resources = new GalleryResources();
00191 if( $this->_resName ) {
00192 $resource = $resources->getResourceFile( $this->_blogInfo->getId(), $this->_resName );
00193 }
00194 else {
00195 $resource = $resources->getResource( $this->_resId, $this->_blogInfo->getId());
00196 }
00197
00198 if( !$resource ) {
00199
00200 $this->_view = new View();
00201 $this->_view->addHeaderResponse( "HTTP/1.1 404 Not Found" );
00202 $this->_view->addHeaderResponse( "Status: 404 Not Found" );
00203 $this->_view->addHeaderResponse( "X-LifeType-Error: Resource $this->_resId not found" );
00204
00205 return false;
00206 }
00207
00208 $url = $this->_blogInfo->getBlogRequestGenerator();
00209 switch( $this->_mode ) {
00210 case RESOURCE_VIEW_MODE_PREVIEW:
00211 $redirectUrl = $url->resourcePreviewLink( $resource );
00212 break;
00213 case RESOURCE_VIEW_MODE_MEDIUM:
00214 $redirectUrl = $url->resourceMediumSizePreviewLink( $resource );
00215 break;
00216 default:
00217 $redirectUrl = $url->resourceDownloadLink( $resource );
00218 break;
00219 }
00220
00221
00222 $this->_view = new RedirectView( $redirectUrl );
00223
00224 return true;
00225 }
00226 }
00227 ?>