lifetype-1.1.6/class/action/blogaction.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/data/validator/integervalidator.class.php" );
00006
00018 class BlogAction extends Action
00019 {
00020
00021 var $_session;
00022 var $_config;
00023 var $_blogInfo;
00024 var $_locale;
00025 var $_pm;
00026 var $_articles;
00027
00034 function BlogAction( $actionInfo, $request )
00035 {
00036 include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
00037 include_once( PLOG_CLASS_PATH."class/security/pipeline.class.php" );
00038 include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
00039
00040 $this->Action( $actionInfo, $request );
00041
00042
00043
00044 $session = HttpVars::getSession();
00045 $this->_session = $session['SessionInfo'];
00046
00047 $this->_config =& Config::getConfig();
00048 if( !$this->_getBlogInfo() ) {
00049 include_once( PLOG_CLASS_PATH."class/view/view.class.php" );
00050 include_once( PLOG_CLASS_PATH."class/view/redirectview.class.php" );
00051
00052 $this->_session->setValue( 'blogId', null );
00053 $blogDoesNotExistUrl = $this->_config->getValue( "blog_does_not_exist_url" );
00054 if ( empty($blogDoesNotExistUrl) )
00055 $blogDoesNotExistUrl = trim( $this->_config->getValue( "base_url" ) );
00056
00057 $this->_view = new RedirectView( $blogDoesNotExistUrl );
00058 $this->_view->render();
00059 die();
00060 }
00061
00062
00063 $this->_session->setValue( 'blogId', $this->_blogInfo->getId());
00064
00065 $this->checkDateParameter();
00066
00067
00068 $this->_pm =& PluginManager::getPluginManager();
00069 $this->_pm->setBlogInfo( $this->_blogInfo );
00070 $this->_pm->setUserInfo( $this->_userInfo );
00071
00072
00073 $this->_locale = $this->_blogInfo->getLocale();
00074
00075
00076
00077
00078 $pipeline = new Pipeline( $request, $this->_blogInfo );
00079 $result = $pipeline->process();
00080
00081
00082
00083 if( !$result->isValid()) {
00084 if( !$result->hasView()) {
00085
00086 include_once( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00087 $message = $this->_locale->tr('error_you_have_been_blocked').'<br/><br/>';
00088 $message .= $result->getErrorMessage();
00089 $this->_view = new ErrorView( $this->_blogInfo, $message );
00090 }
00091 else {
00092
00093
00094 $this->_view = $result->getView();
00095 }
00096 $this->setCommonData();
00097 $this->_view->render();
00098
00099 die();
00100 }
00101
00102
00103 $this->_updateReferrer();
00104
00105
00106 $this->_page = $this->_getPage();
00107 }
00108
00114 function notifyEvent( $eventType, $params = Array())
00115 {
00116 $params[ 'from' ] = $this->_actionInfo->getActionParamValue();
00117 $params[ 'request' ] = $this->_request;
00118
00119 return $this->_pm->notifyEvent( $eventType, $params );
00120 }
00121
00125 function saveSession()
00126 {
00127
00128 $session = HttpVars::getSession();
00129 $session['SessionInfo'] = $this->_session;
00130 HttpVars::setSession( $session );
00131 }
00132
00142 function setCommonData( $copyFormValues = false )
00143 {
00144 $this->_view->setValue( "Year", $this->_session->getValue( 'Year'));
00145 $this->_view->setValue( "Month", $this->_session->getValue( 'Month' ));
00146
00147 parent::setCommonData( $copyFormValues );
00148 }
00149
00154 function _getBlogInfo()
00155 {
00156
00157 $config =& Config::getConfig();
00158 if( $config->getValue( "subdomains_enabled" )) {
00159 include_once( PLOG_CLASS_PATH."class/net/http/subdomains.class.php" );
00160
00161 $subdomainInfo = Subdomains::getSubdomainInfoFromRequest();
00162
00163 if( !empty($subdomainInfo["blogdomain"]) && $this->_request->getValue( 'blogDomain' ) == "" ) {
00164 $this->_request->setValue( 'blogDomain', $subdomainInfo["blogdomain"] );
00165 }
00166 if( !empty($subdomainInfo["username"]) && $this->_request->getValue( 'blogUserName' ) == "" ) {
00167 $this->_request->setValue( 'blogUserName', $subdomainInfo["username"] );
00168 }
00169 if( !empty($subdomainInfo["blogname"]) && $this->_request->getValue( 'blogName' ) == "" ) {
00170 $this->_request->setValue( 'blogName', $subdomainInfo["blogname"] );
00171 }
00172 }
00173
00174 $blogId = $this->_request->getValue( 'blogId' );
00175 $blogName = $this->_request->getValue( 'blogName' );
00176 $userId = $this->_request->getValue( 'userId' );
00177 $userName = $this->_request->getValue( 'blogUserName' );
00178 $blogDomain = $this->_request->getValue( 'blogDomain' );
00179
00180
00181
00182 if( !$blogId && !$blogName && !$blogDomain) {
00183
00184 if( !empty($userName) ) {
00185 include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
00186
00187 $users = new Users();
00188 $userInfo = $users->getUserInfoFromUsername( $userName );
00189
00190 if( $userInfo ) {
00191 $userBlogs = $users->getUsersBlogs( $userInfo->getId(), BLOG_STATUS_ACTIVE );
00192
00193
00194 if( !empty($userBlogs)) {
00195 $i = 0;
00196 $found = false;
00197 while( $i < count($userBlogs) && !$found ) {
00198 $blog = $userBlogs[$i];
00199 if( $blog->getOwnerId() == $userInfo->getId()) $found = true;
00200 $i++;
00201 }
00202 $blogId = $blog->getId();
00203 }
00204 else {
00205 $blogId = $this->_config->getValue('default_blog_id');
00206 }
00207 }
00208 else {
00209 $blogId = $this->_config->getValue('default_blog_id');
00210 }
00211 }
00212 else {
00213
00214 if( $this->_session->getValue('blogId') != '' ) {
00215 $blogId = $this->_session->getValue('blogId');
00216 }
00217 else {
00218
00219 $blogId = $this->_config->getValue('default_blog_id');
00220 }
00221 }
00222 }
00223
00224
00225 include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00226 $blogs = new Blogs();
00227 if( $blogId ) {
00228 $this->_blogInfo = $blogs->getBlogInfo( $blogId );
00229 }
00230 else if($blogName){
00231 $this->_blogInfo = $blogs->getBlogInfoByName( $blogName );
00232 }
00233 else if($blogDomain){
00234 $this->_blogInfo = $blogs->getBlogInfoByDomain( $blogDomain );
00235 }
00236 else{
00237 $this->_blogInfo = false;
00238 }
00239
00240 $blogExists = true;
00241
00242
00243 if( $this->_blogInfo == false ) {
00244 $blogExists = false;
00245 } else {
00246
00247 if( $this->_blogInfo->getStatus() != BLOG_STATUS_ACTIVE )
00248 $blogExists = false;
00249 }
00250 return $blogExists;
00251 }
00252
00256 function checkDateParameter()
00257 {
00258 $date = $this->_request->getValue( 'Date' );
00259 $val = new IntegerValidator();
00260 if( $date && $val->validate( $date ) ) {
00261 $year = substr( $date, 0, 4);
00262 $month = substr( $date, 4,2 );
00263 $day = substr( $date, 6, 2);
00264 }
00265 else {
00266
00267
00268
00269
00270 $year = date('Y');
00271
00272 $month = date('m');
00273
00274 $day = date('d');
00275 }
00276
00277 $this->_session->setValue( 'Year', $year );
00278 $this->_session->setValue( 'Month', $month );
00279 $this->_session->setValue( 'Day', $day );
00280 }
00281
00288 function _updateReferrer()
00289 {
00290 if( $this->_request->getValue( "articleId" ) != "" ||
00291 $this->_request->getValue( "articleName" ) != "" )
00292 return true;
00293
00294
00295 include_once( PLOG_CLASS_PATH."class/dao/referers.class.php" );
00296
00297 $referers = new Referers();
00298 if (array_key_exists( 'HTTP_REFERER', $_SERVER ))
00299 $referers->addReferer( $_SERVER['HTTP_REFERER'], 0, $this->_blogInfo->getId());
00300
00301 return true;
00302 }
00303
00310 function _getCorrectedDatePeriod( $inDate )
00311 {
00312 $blogSettings = $this->_blogInfo->getSettings();
00313 $serverTimeOffset = $blogSettings->getValue( "time_offset" );
00314
00315 if( strlen($inDate) == 4 )
00316 {
00317 $year = $inDate;
00318 $outDate = Timestamp::getDateWithOffset( $year."0101000000", -$serverTimeOffset );
00319 $maxDate = Timestamp::getDateWithOffset( $year."1231235959", -$serverTimeOffset );
00320 }
00321 elseif ( strlen($inDate) == 6 )
00322 {
00323 $year = substr( $inDate, 0, 4 );
00324 $month = substr( $inDate, 4, 2 );
00325 $dayOfMonth = Date_Calc::daysInMonth( $month, $year );
00326 $outDate = Timestamp::getDateWithOffset( $year.$month."01000000", -$serverTimeOffset );
00327 $maxDate = Timestamp::getDateWithOffset( $year.$month.$dayOfMonth."235959", -$serverTimeOffset );
00328 }
00329 elseif ( strlen($inDate) == 8 )
00330 {
00331 $year = substr( $inDate, 0, 4 );
00332 $month = substr( $inDate, 4, 2 );
00333 $day = substr( $inDate, 6, 2 );
00334 $outDate = Timestamp::getDateWithOffset( $year.$month.$day."000000", -$serverTimeOffset );
00335
00336
00337
00338
00339
00340 $maxDate = Timestamp::getDateWithOffset( $year.$month.$day."235959", 0 );
00341 }
00342 else
00343 {
00344 $maxDate = -1;
00345 $outDate = $inDate;
00346 }
00347
00348 $result["inDate"] = $inDate;
00349 $result["maxDate"] = $maxDate;
00350 $result["adjustedDate"] = $outDate;
00351
00352 return( $result );
00353 }
00354
00355
00359 function _getPage()
00360 {
00361 include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php");
00362
00363 $page = HttpVars::getRequestValue( "page" );
00364
00365 $val = new IntegerValidator();
00366 if( !$val->validate( $page ))
00367 $page = 1;
00368
00369 return $page;
00370 }
00371 }
00372 ?>