NewsFeaturesDownloadsDevelopmentSupportAbout Us

lifetype-1.1.6/class/action/admin/adminaction.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/locale/locales.class.php" );
00005     include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
00006     include_once( PLOG_CLASS_PATH."class/template/templateservice.class.php" );
00007     include_once( PLOG_CLASS_PATH."class/misc/version.class.php" );
00008         include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
00009         include_once( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
00010         include_once( PLOG_CLASS_PATH."class/view/admin/admindefaultview.class.php" );
00011         include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
00012         include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
00013 
00029     class AdminAction extends Action 
00030         {
00031 
00032         var $_blogInfo;
00033         var $_userInfo;
00034         var $_session;
00035         var $_config;
00036         var $_locale;
00037                 var $_pm;
00038                 var $_userBlogs;
00039 
00046         function AdminAction( $actionInfo, $request )
00047         {
00048                 $this->Action( $actionInfo, $request );
00049         
00050             // get information about the session
00051             $session = HttpVars::getSession();
00052             $this->_session = $session["SessionInfo"];
00053 
00054             $this->_config  =& Config::getConfig();
00055 
00056             // get the information about the user and quit if we don't have it...
00057             $this->_getUserInfo();
00058             if( empty( $this->_userInfo ) ) {
00059                 header( "HTTP/1.0 403 Forbidden" );
00060                 print($this->mustAuthenticatePage());
00061                 die();
00062             }
00063 
00064             // do the same with the information about the blog
00065             $this->_getBlogInfo();
00066             if( empty( $this->_blogInfo )) {
00067                 if( $this->_actionInfo->getActionParamValue() != "blogSelect" &&
00068                     $this->_actionInfo->getActionParamValue() != "registerBlog" &&
00069                     $this->_actionInfo->getActionParamValue() != "finishRegisterBlog" ) {
00070                         header( "HTTP/1.0 403 Forbidden" );
00071                         print($this->mustAuthenticatePage());
00072                     die();
00073                 }
00074             }
00075                         
00076                         // prepare the plugin manager in case we'd like to throw events
00077                         $this->_pm =& PluginManager::getPluginManager();                        
00078                         
00079                         // fetch the site locale
00080             $this->_locale =& $this->getLocale();
00081 
00082                         $users =& new Users();
00083             $this->_userBlogs = $users->getUsersBlogs( $this->_userInfo->getId(), BLOG_STATUS_ACTIVE );            
00084                         // in case we're in "admin mode" (where administrators can log into anybody's blog), we should also
00085                         // display the current blog in the drop-down list on the top left corner, if only to make it clear to
00086                         // the user that this is another completely different blog
00087             if( !empty( $this->_blogInfo ) && $this->_blogInfo->getOwnerId() != $this->_userInfo->getId() &&  $this->_userInfo->isSiteAdmin() ) {
00088                                 $find = false;
00089                 foreach( $this->_userBlogs as $userBlog ) {
00090                                         if( $userBlog->getId() == $this->_blogInfo->getId() ) {
00091                                                 $find = true;
00092                                                 break;
00093                                 }
00094                     }
00095                     
00096                             if( !$find ) {
00097                                 $this->_userBlogs[] = $this->_blogInfo;
00098                             }
00099             }
00100         }
00101 
00106         function _getBlogInfo()
00107         {
00108             $session = HttpVars::getSession();
00109             $sessionInfo = $session["SessionInfo"];
00110 
00111             $this->_blogInfo = $sessionInfo->getValue( "blogInfo" );
00112         }
00113 
00118         function _getUserInfo()
00119         {
00120             $session = HttpVars::getSession();
00121             $sessionInfo = $session["SessionInfo"];
00122             $this->_userInfo = $sessionInfo->getValue("userInfo");
00123         }
00124 
00129         function &getLocale()
00130         {
00131                 // don't like this so much...
00132                 if( !empty( $this->_blogInfo ) ) {
00133                         $this->_blogSettings = $this->_blogInfo->getSettings();
00134                 //$locale =& Locales::getLocale( $this->_blogSettings->getValue("locale"));
00135                                 $locale =& $this->_blogInfo->getLocale();
00136             }
00137             else {
00138                 $locale =& Locales::getLocale( $this->_config->getValue("default_locale"));
00139             }
00140                         
00141                         return $locale;
00142         }
00143 
00151         function setCommonData( $copyFormValues = false )
00152         {       
00153                         parent::setCommonData( $copyFormValues );
00154 
00155                         // initialiaze plugins
00156                         $this->_pm->setBlogInfo( $this->_blogInfo );
00157                         $this->_pm->setUserInfo( $this->_userInfo );
00158                         $this->_pm->getPlugins();                       
00159                         
00160                 $this->_view->setValue( "user", $this->_userInfo );
00161                 $this->_view->setValue( "userBlogs", $this->_userBlogs);
00162                         $this->_view->setUserInfo( $this->_userInfo );
00163             $this->_view->setValue( "blog", $this->_blogInfo );
00164             if( $this->_blogInfo )
00165                 $this->_view->setValue( "blogsettings", $this->_blogInfo->getSettings());
00166             $this->_view->setValue( "op", $this->_actionInfo->_actionParamValue );
00167                         $this->_view->setValue( "locale", $this->_locale );
00168                         $this->_view->setValue( "config", $this->_config );
00169         }
00170 
00175         function saveSession()
00176         {
00177                 if( !empty( $this->_blogInfo ) )
00178                         $this->_session->setValue( "blogId", $this->_blogInfo->getId() );
00179                 if( !empty( $this->_userInfo ) )
00180                 $this->_session->setValue( "userInfo", $this->_userInfo );
00181                 //$_SESSION["SessionInfo"] = $this->_session;
00182             $session = HttpVars::getSession();
00183             $session["SessionInfo"] = $this->_session;
00184             HttpVars::setSession( $session );
00185         }
00186 
00192         function mustAuthenticatePage()
00193         {
00194                         $locale = $this->getLocale();           
00195                         $config =& Config::getConfig();                 
00196                         $destinationUrl = $config->getValue( "logout_destination_url", "" );
00197             if( $destinationUrl == "" ) {
00198                                 $view = new AdminDefaultView();
00199                         }
00200                         else {
00201                                 // nothing else to do, just redirect the browser once we've cleaned up the session
00202                                 include_once( PLOG_CLASS_PATH."class/view/redirectview.class.php" );                            
00203                                 $view = new RedirectView( $destinationUrl );                                                    
00204                         }
00205                         $view->setErrorMessage( $locale->tr("error_access_forbidden" ));                        
00206                         
00207                         return $view->render();
00208         }
00209                 
00219                 function notifyEvent( $eventType, $params = Array())
00220                 {
00221                         $params[ "from" ] = $this->_actionInfo->getActionParamValue();
00222                         $params[ "request" ] = $this->_request;
00223                         
00224                         return $this->_pm->notifyEvent( $eventType, $params );
00225                 }
00226     }
00227 ?>