00001 <?php
00002
00003 lt_include( PLOG_CLASS_PATH."class/action/action.class.php" );
00004 lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
00005 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00006 lt_include( PLOG_CLASS_PATH."class/data/validator/usernamevalidator.class.php" );
00007 lt_include( PLOG_CLASS_PATH."class/data/validator/blognamevalidator.class.php" );
00008 lt_include( PLOG_CLASS_PATH."class/data/validator/domainvalidator.class.php" );
00009
00021 class BlogAction extends Action
00022 {
00023
00024 var $_session;
00025 var $_config;
00026 var $_blogInfo;
00027 var $_locale;
00028 var $_pm;
00029 var $_articles;
00030 var $_userInfo;
00031
00038 function BlogAction( $actionInfo, $request )
00039 {
00040 lt_include( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
00041 lt_include( PLOG_CLASS_PATH."class/security/pipeline.class.php" );
00042 lt_include( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
00043
00044 $this->Action( $actionInfo, $request );
00045
00046
00047
00048 $session = HttpVars::getSession();
00049 $this->_session = $session['SessionInfo'];
00050
00051 $this->_config =& Config::getConfig();
00052 if( !$this->_getBlogInfo() ) {
00053 lt_include( PLOG_CLASS_PATH."class/view/view.class.php" );
00054 lt_include( PLOG_CLASS_PATH."class/view/redirectview.class.php" );
00055
00056 $this->_session->setValue( 'blogId', null );
00057 $blogDoesNotExistUrl = $this->_config->getValue( "blog_does_not_exist_url" );
00058 if ( empty($blogDoesNotExistUrl) )
00059 $blogDoesNotExistUrl = trim( $this->_config->getValue( "base_url" ) );
00060
00061 $this->_view = new RedirectView( $blogDoesNotExistUrl );
00062 $this->_view->render();
00063 die();
00064 }
00065
00066
00067 $this->_session->setValue( 'blogId', $this->_blogInfo->getId());
00068
00069
00070 $this->_userInfo = SessionManager::getUserInfoFromSession();
00071
00072 $this->checkDateParameter();
00073
00074
00075 $this->_pm =& PluginManager::getPluginManager();
00076 $this->_pm->setBlogInfo( $this->_blogInfo );
00077 $this->_pm->setUserInfo( $this->_userInfo );
00078
00079
00080 $this->_locale = $this->_blogInfo->getBlogLocale();
00081
00082
00083
00084
00085 $pipeline = new Pipeline( $request, $this->_blogInfo );
00086 $result = $pipeline->process();
00087
00088
00089
00090 if( !$result->isValid()) {
00091 if( !$result->hasView()) {
00092
00093 lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00094 $message = $this->_locale->tr('error_you_have_been_blocked').'<br/><br/>';
00095 $message .= $result->getErrorMessage();
00096 $this->_view = new ErrorView( $this->_blogInfo, $message );
00097 }
00098 else {
00099
00100
00101 $this->_view = $result->getView();
00102 }
00103 $this->setCommonData();
00104 $this->_view->render();
00105
00106 die();
00107 }
00108
00109
00110 $this->_updateReferrer();
00111
00112
00113 $this->_page = $this->_getPage();
00114 }
00115
00121 function notifyEvent( $eventType, $params = Array())
00122 {
00123 $params[ 'from' ] = $this->_actionInfo->getActionParamValue();
00124 $params[ 'request' ] = $this->_request;
00125
00126 return $this->_pm->notifyEvent( $eventType, $params );
00127 }
00128
00132 function saveSession()
00133 {
00134
00135 $session = HttpVars::getSession();
00136 $session['SessionInfo'] = $this->_session;
00137 HttpVars::setSession( $session );
00138 }
00139
00149 function setCommonData( $copyFormValues = false )
00150 {
00151 $this->_view->setValue( "Year", $this->_session->getValue( 'Year'));
00152 $this->_view->setValue( "Month", $this->_session->getValue( 'Month' ));
00153 $this->_view->setValue( "authuser", $this->_userInfo );
00154 $this->_view->setValue( "blog", $this->_blogInfo );
00155 $this->_view->setValue( "blogsettings", $this->_blogInfo->getSettings());
00156
00157 parent::setCommonData( $copyFormValues );
00158 }
00159
00164 function _getBlogInfo()
00165 {
00166
00167 $config =& Config::getConfig();
00168 if( $config->getValue( "subdomains_enabled" )) {
00169 lt_include( PLOG_CLASS_PATH."class/net/http/subdomains.class.php" );
00170
00171 $subdomainInfo = Subdomains::getSubdomainInfoFromRequest();
00172
00173 if( !empty($subdomainInfo["blogdomain"]) && $this->_request->getValue( 'blogDomain' ) == "" ) {
00174 $this->_request->setValue( 'blogDomain', $subdomainInfo["blogdomain"] );
00175 }
00176 if( !empty($subdomainInfo["username"]) && $this->_request->getValue( 'blogUserName' ) == "" ) {
00177 $this->_request->setValue( 'blogUserName', $subdomainInfo["username"] );
00178 }
00179 if( !empty($subdomainInfo["blogname"]) && $this->_request->getValue( 'blogName' ) == "" ) {
00180 $this->_request->setValue( 'blogName', $subdomainInfo["blogname"] );
00181 }
00182 }
00183
00184 $val = new IntegerValidator();
00185 $blogId = $this->_request->getValue( 'blogId' );
00186 if( !$val->validate( $blogId ))
00187 $blogId = "";
00188
00189 $val = new IntegerValidator();
00190 $userId = $this->_request->getValue( 'userId' );
00191 if( !$val->validate( $userId ))
00192 $userId = "";
00193
00194 $val = new BlogNameValidator();
00195 $blogName = $this->_request->getValue( 'blogName' );
00196 if( !$val->validate( $blogName ))
00197 $blogName = "";
00198
00199 $val = new UsernameValidator();
00200 $userName = $this->_request->getValue( 'blogUserName' );
00201 if( !$val->validate( $userName ))
00202 $userName = "";
00203
00204 $val = new DomainValidator();
00205 $blogDomain = $this->_request->getValue( 'blogDomain' );
00206 if( !$val->validate( $blogDomain ))
00207 $blogDomain = "";
00208
00209
00210
00211
00212 if( !$blogId && !$blogName && !$blogDomain) {
00213
00214 if( !empty($userName) ) {
00215 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
00216
00217 $users = new Users();
00218 $userInfo = $users->getUserInfoFromUsername( $userName );
00219
00220 if( $userInfo ) {
00221 $userBlogs = $users->getUsersBlogs( $userInfo->getId(), BLOG_STATUS_ACTIVE );
00222
00223
00224 if( !empty($userBlogs)) {
00225 $i = 0;
00226 $found = false;
00227 while( $i < count($userBlogs) && !$found ) {
00228 $blog = $userBlogs[$i];
00229 if( $blog->getOwnerId() == $userInfo->getId()) $found = true;
00230 $i++;
00231 }
00232 $blogId = $blog->getId();
00233 }
00234 else {
00235 $blogId = $this->_config->getValue('default_blog_id');
00236 }
00237 }
00238 else {
00239 $blogId = $this->_config->getValue('default_blog_id');
00240 }
00241 }
00242 else {
00243
00244 if( $this->_session->getValue('blogId') != '' ) {
00245 $blogId = $this->_session->getValue('blogId');
00246 }
00247 else {
00248
00249 $blogId = $this->_config->getValue('default_blog_id');
00250 }
00251 }
00252 }
00253
00254
00255 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00256 $blogs = new Blogs();
00257 if( $blogId ) {
00258 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00259 $blogs = new Blogs();
00260 $this->_blogInfo = $blogs->getBlogInfo( $blogId );
00261 }
00262 else if($blogName) {
00263 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00264 $blogs = new Blogs();
00265 $this->_blogInfo = $blogs->getBlogInfoByName( $blogName );
00266 }
00267 else if($blogDomain) {
00268 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00269 $blogs = new Blogs();
00270 $this->_blogInfo = $blogs->getBlogInfoByDomain( $blogDomain );
00271 }
00272 else {
00273 $this->_blogInfo = false;
00274 }
00275
00276 $blogExists = true;
00277
00278
00279 if( $this->_blogInfo == false ) {
00280 $blogExists = false;
00281 } else {
00282
00283 if( $this->_blogInfo->getStatus() != BLOG_STATUS_ACTIVE )
00284 $blogExists = false;
00285 }
00286 return $blogExists;
00287 }
00288
00292 function checkDateParameter()
00293 {
00294 $date = $this->_request->getValue( 'Date' );
00295 $val = new IntegerValidator();
00296 if( $date && $val->validate( $date ) ) {
00297 $year = substr( $date, 0, 4);
00298 $month = substr( $date, 4,2 );
00299 $day = substr( $date, 6, 2);
00300 }
00301 else {
00302
00303
00304
00305
00306 $year = date('Y');
00307
00308 $month = date('m');
00309
00310 $day = date('d');
00311 }
00312
00313 $this->_session->setValue( 'Year', $year );
00314 $this->_session->setValue( 'Month', $month );
00315 $this->_session->setValue( 'Day', $day );
00316 }
00317
00324 function _updateReferrer()
00325 {
00326 if( $this->_request->getValue( "articleId" ) != "" ||
00327 $this->_request->getValue( "articleName" ) != "" )
00328 return true;
00329
00330
00331 lt_include( PLOG_CLASS_PATH."class/dao/referers.class.php" );
00332
00333 if( $this->_config->getValue( "referer_tracker_enabled", true )) {
00334 $referers = new Referers();
00335 if (array_key_exists( 'HTTP_REFERER', $_SERVER ))
00336 $referers->addReferer( $_SERVER['HTTP_REFERER'], 0, $this->_blogInfo->getId());
00337 }
00338
00339 return true;
00340 }
00341
00348 function _getCorrectedDatePeriod( $inDate )
00349 {
00350 $blogSettings = $this->_blogInfo->getSettings();
00351 $serverTimeOffset = $blogSettings->getValue( "time_offset" );
00352
00353 if( strlen($inDate) == 4 )
00354 {
00355 $year = $inDate;
00356 $outDate = Timestamp::getDateWithOffset( $year."0101000000", -$serverTimeOffset );
00357 $maxDate = Timestamp::getDateWithOffset( $year."1231235959", -$serverTimeOffset );
00358 }
00359 elseif ( strlen($inDate) == 6 )
00360 {
00361 $year = substr( $inDate, 0, 4 );
00362 $month = substr( $inDate, 4, 2 );
00363 $dayOfMonth = Date_Calc::daysInMonth( $month, $year );
00364 $outDate = Timestamp::getDateWithOffset( $year.$month."01000000", -$serverTimeOffset );
00365 $maxDate = Timestamp::getDateWithOffset( $year.$month.$dayOfMonth."235959", -$serverTimeOffset );
00366 }
00367 elseif ( strlen($inDate) == 8 )
00368 {
00369 $year = substr( $inDate, 0, 4 );
00370 $month = substr( $inDate, 4, 2 );
00371 $day = substr( $inDate, 6, 2 );
00372 $outDate = Timestamp::getDateWithOffset( $year.$month.$day."000000", -$serverTimeOffset );
00373
00374
00375
00376
00377
00378 $maxDate = Timestamp::getDateWithOffset( $year.$month.$day."235959", 0 );
00379 }
00380 else
00381 {
00382 $maxDate = -1;
00383 $outDate = $inDate;
00384 }
00385
00386 $result["inDate"] = $inDate;
00387 $result["maxDate"] = $maxDate;
00388 $result["adjustedDate"] = $outDate;
00389
00390 return( $result );
00391 }
00392
00396 function _getPage()
00397 {
00398
00399 $page = HttpVars::getRequestValue( "page" );
00400
00401 $val = new IntegerValidator();
00402 if( !$val->validate( $page ))
00403 $page = 1;
00404
00405 return $page;
00406 }
00407 }
00408 ?>