lifetype/branches/lifetype-1.0.6/class/action/resourceserveraction.class.php
Go to the documentation of this file.00001 <?php
00002
00003 include_once( PLOG_CLASS_PATH."class/action/action.class.php" );
00004 include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
00005 include_once( PLOG_CLASS_PATH."class/view/resourceserverview.class.php" );
00006 include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00007 include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
00008 include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
00009 include_once( PLOG_CLASS_PATH."class/net/url.class.php" );
00010 include_once( PLOG_CLASS_PATH."class/security/pipeline.class.php" );
00011 include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
00012 include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00013 include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00014
00019 class ResourceServerAction extends Action
00020 {
00021 var $_mode;
00022 var $_resource;
00023 var $_resId;
00024 var $_album;
00025 var $_config;
00026 var $_blogInfo;
00027
00028 function ResourceServerAction( $actionInfo, $request )
00029 {
00030 $this->Action( $actionInfo, $request );
00031
00032
00033 $session = HttpVars::getSession();
00034 $this->_session = $session['SessionInfo'];
00035
00036 $this->_config =& Config::getConfig();
00037
00038 $this->registerFieldValidator( "resource", new StringValidator(), true );
00039 $this->registerFieldValidator( "resId", new IntegerValidator(), true );
00040 $this->registerFieldValidator( "albumId", new IntegerValidator(), true );
00041 $this->registerFieldValidator( "albumName", new StringValidator(), true );
00042 $this->registerFieldValidator( "blogId", new IntegerValidator(), true );
00043 $this->registerFieldValidator( "blogName", new StringValidator(), true );
00044 $this->registerFieldValidator( "userId", new IntegerValidator(), true );
00045 $this->registerFieldValidator( "blogUserName", new StringValidator(), true );
00046
00047
00048
00049 $view = new ResourceServerView();
00050 $view->addHeaderResponse( "HTTP/1.1 404 Not Found" );
00051 $view->addHeaderResponse( "Status: 404 Not Found" );
00052 $view->addHeaderResponse( "X-LifeType-Error: Invalid parameters" );
00053 $this->setValidationErrorView( $view );
00054 }
00055
00060 function _getBlogInfo()
00061 {
00062
00063 $config =& Config::getConfig();
00064 if( $config->getValue( "subdomains_enabled" )) {
00065 $subdomainInfo = Subdomains::getSubdomainInfoFromRequest();
00066
00067 if( $subdomainInfo["username"] != "" && $this->_request->getValue( 'blogUserName' ) == "" )
00068 $this->_request->setValue( 'blogUserName', $subdomainInfo["username"] );
00069 if( $subdomainInfo["blogname"] != "" && $this->_request->getValue( 'blogName' ) == "" )
00070 $this->_request->setValue( 'blogName', $subdomainInfo["blogname"] );
00071 }
00072
00073 $blogId = $this->_request->getValue( 'blogId' );
00074 $blogName = $this->_request->getValue( 'blogName' );
00075 $userId = $this->_request->getValue( 'userId' );
00076 $userName = $this->_request->getValue( 'blogUserName' );
00077
00078
00079
00080 if( !$blogId && !$blogName ) {
00081
00082 if( !empty($userName) ) {
00083
00084 $users = new Users();
00085 $userInfo = $users->getUserInfoFromUsername( $userName );
00086
00087 if( $userInfo ) {
00088 $userBlogs = $users->getUsersBlogs( $userInfo->getId(), BLOG_STATUS_ACTIVE );
00089
00090
00091 if( !empty($userBlogs)) {
00092 $blogId = $userBlogs[0]->getId();
00093 } else{
00094 $blogId = $this->_config->getValue('default_blog_id');
00095 }
00096 } else{
00097 $blogId = $this->_config->getValue('default_blog_id');
00098 }
00099 }
00100 else {
00101
00102 if( $this->_session->getValue('blogId') != '' ) {
00103 $blogId = $this->_session->getValue('blogId');
00104 }
00105 else {
00106
00107 $blogId = $this->_config->getValue('default_blog_id');
00108 }
00109 }
00110 }
00111
00112
00113 $blogs = new Blogs();
00114 if( $blogId )
00115 $this->_blogInfo = $blogs->getBlogInfo( $blogId );
00116 else
00117 $this->_blogInfo = $blogs->getBlogInfoByName( $blogName );
00118 }
00119
00120 function validate()
00121 {
00122 if( !parent::validate())
00123 return false;
00124
00125
00126 $this->_getBlogInfo();
00127 if( $this->_blogInfo == false ) {
00128
00129 $this->_view = new ResourceServerView();
00130 $this->_view->addHeaderResponse( "HTTP/1.1 404 Not Found" );
00131 $this->_view->addHeaderResponse( "Status: 404 Not Found" );
00132 $this->_view->addHeaderResponse( "X-LifeType-Error: Blog $resId is not correct" );
00133
00134 return false;
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 $pipeline = new Pipeline( $this->_request, $this->_blogInfo );
00146 $result = $pipeline->process();
00147
00148
00149
00150 if( !$result->isValid()) {
00151 $this->_view = new ResourceServerView();
00152 $this->_view->addHeaderResponse( "HTTP/1.1 403 Forbidden" );
00153 $this->_view->addHeaderResponse( "Status: 403 Forbidden" );
00154 $this->_view->addHeaderResponse( "X-LifeType-Error: Access is blocked" );
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 $albums = new GalleryAlbums();
00171 $album = $albums->getAlbumByName( $this->_albumName );
00172 if( !$album ) {
00173 $this->_view = new ResourceServerView();
00174 $this->_view->addHeaderResponse( "HTTP/1.1 404 Not Found" );
00175 $this->_view->addHeaderResponse( "Status: 404 Not Found" );
00176 $this->_view->addHeaderResponse( "X-LifeType-Error: Album $albumId not found" );
00177 return false;
00178 }
00179 $this->_albumId = $album->getId();
00180 }
00181 }
00182
00183 return true;
00184 }
00185
00191 function notifyEvent( $eventType, $params = Array())
00192 {
00193 $params[ 'from' ] = $this->_actionInfo->getActionParamValue();
00194 $params[ 'request' ] = $this->_request;
00195
00196 return $this->_pm->notifyEvent( $eventType, $params );
00197 }
00198
00199 function perform()
00200 {
00201
00202
00203
00204 $this->_pm =& PluginManager::getPluginManager();
00205 $this->_pm->setBlogInfo( $this->_blogInfo );
00206 $this->_userInfo = $this->_blogInfo->getOwnerInfo();
00207 $this->_pm->setUserInfo( $this->_userInfo );
00208
00209
00210 $resources = new GalleryResources();
00211 if( $this->_resName ) {
00212 $resource = $resources->getResourceFile( $this->_blogInfo->getId(), $this->_resName );
00213 }
00214 else {
00215 $resource = $resources->getResource( $this->_resId, $this->_blogInfo->getId());
00216 }
00217
00218 if( !$resource ) {
00219
00220 $this->_view = new ResourceServerView();
00221 $this->_view->addHeaderResponse( "HTTP/1.1 404 Not Found" );
00222 $this->_view->addHeaderResponse( "Status: 404 Not Found" );
00223 $this->_view->addHeaderResponse( "X-LifeType-Error: Resource $this->_resId not found" );
00224
00225 return false;
00226 }
00227
00228
00229 $this->notifyEvent( EVENT_RESOURCE_LOADED, Array( "resource" => &$resource ));
00230
00231
00232 $this->_view = new ResourceServerView( $resource, $this->_mode );
00233
00234 return true;
00235 }
00236 }
00237 ?>