示例#1
0
 /**
  * Analyzes the supplied query string and decides how to dispatch the request.
  */
 public function Dispatch($ImportRequest = NULL, $Permanent = TRUE)
 {
     if ($ImportRequest && is_string($ImportRequest)) {
         $ImportRequest = Gdn_Request::Create()->FromEnvironment()->WithURI($ImportRequest);
     }
     if (is_a($ImportRequest, 'Gdn_Request') && $Permanent) {
         Gdn::Request($ImportRequest);
     }
     $Request = is_a($ImportRequest, 'Gdn_Request') ? $ImportRequest : Gdn::Request();
     if (Gdn::Session()->NewVisit()) {
         Gdn::UserModel()->FireEvent('Visit');
     }
     // Move this up to allow pre-routing
     $this->FireEvent('BeforeDispatch');
     // By default, all requests can be blocked by UpdateMode/PrivateCommunity
     $CanBlock = self::BLOCK_ANY;
     try {
         $BlockExceptions = array('/^utility(\\/.*)?$/' => self::BLOCK_NEVER, '/^plugin(\\/.*)?$/' => self::BLOCK_NEVER, '/^sso(\\/.*)?$/' => self::BLOCK_NEVER, '/^discussions\\/getcommentcounts/' => self::BLOCK_NEVER, '/^entry(\\/.*)?$/' => self::BLOCK_PERMISSION, '/^user\\/usernameavailable(\\/.*)?$/' => self::BLOCK_PERMISSION, '/^user\\/emailavailable(\\/.*)?$/' => self::BLOCK_PERMISSION, '/^home\\/termsofservice(\\/.*)?$/' => self::BLOCK_PERMISSION);
         $this->EventArguments['BlockExceptions'] =& $BlockExceptions;
         $this->FireEvent('BeforeBlockDetect');
         $PathRequest = Gdn::Request()->Path();
         foreach ($BlockExceptions as $BlockException => $BlockLevel) {
             if (preg_match($BlockException, $PathRequest)) {
                 throw new Exception("Block detected - {$BlockException}", $BlockLevel);
             }
         }
         // Never block an admin
         if (Gdn::Session()->CheckPermission('Garden.Settings.Manage')) {
             throw new Exception("Block detected", self::BLOCK_NEVER);
         }
         if (Gdn::Session()->IsValid()) {
             throw new Exception("Block detected", self::BLOCK_PERMISSION);
         }
     } catch (Exception $e) {
         // BlockLevel
         //  TRUE = Block any time
         //  FALSE = Absolutely no blocking
         //  NULL = Block for permissions (e.g. PrivateCommunity)
         $CanBlock = $e->getCode();
     }
     // If we're in updatemode and arent explicitly prevented from blocking, block
     if (Gdn::Config('Garden.UpdateMode', FALSE) && $CanBlock > self::BLOCK_NEVER) {
         $Request->WithURI(Gdn::Router()->GetDestination('UpdateMode'));
     }
     // Analze the request AFTER checking for update mode.
     $this->AnalyzeRequest($Request);
     $this->FireEvent('AfterAnalyzeRequest');
     // If we're in updatemode and can block, redirect to signin
     if (C('Garden.PrivateCommunity') && $CanBlock > self::BLOCK_PERMISSION) {
         Redirect('/entry/signin?Target=' . urlencode($this->Request));
         exit;
     }
     $ControllerName = $this->ControllerName();
     if ($ControllerName != '' && class_exists($ControllerName)) {
         // Create it and call the appropriate method/action
         $Controller = new $ControllerName();
         Gdn::Controller($Controller);
         $this->EventArguments['Controller'] =& $Controller;
         $this->FireEvent('AfterControllerCreate');
         // Pass along any assets
         if (is_array($this->_AssetCollection)) {
             foreach ($this->_AssetCollection as $AssetName => $Assets) {
                 foreach ($Assets as $Asset) {
                     $Controller->AddAsset($AssetName, $Asset);
                 }
             }
         }
         // Instantiate Imported & Uses classes
         $Controller->GetImports();
         // Pass in the syndication method
         $Controller->SyndicationMethod = $this->_SyndicationMethod;
         // Pass along the request
         $Controller->SelfUrl = $this->Request;
         // Pass along any objects
         foreach ($this->_PropertyCollection as $Name => $Mixed) {
             $Controller->{$Name} = $Mixed;
         }
         // Pass along any data.
         if (is_array($this->_Data)) {
             $Controller->Data = $this->_Data;
         }
         // Set up a default controller method in case one isn't defined.
         $ControllerMethod = str_replace('_', '', $this->ControllerMethod);
         $Controller->OriginalRequestMethod = $ControllerMethod;
         // Take enabled plugins into account, as well
         $PluginReplacement = Gdn::PluginManager()->HasNewMethod($this->ControllerName(), $this->ControllerMethod);
         if (!$PluginReplacement && ($this->ControllerMethod == '' || !method_exists($Controller, $ControllerMethod))) {
             // Check to see if there is an 'x' version of the method.
             if (method_exists($Controller, 'x' . $ControllerMethod)) {
                 // $PluginManagerHasReplacementMethod = TRUE;
                 $ControllerMethod = 'x' . $ControllerMethod;
             } else {
                 if ($this->ControllerMethod != '') {
                     array_unshift($this->_ControllerMethodArgs, $this->ControllerMethod);
                 }
                 $this->ControllerMethod = 'Index';
                 $ControllerMethod = 'Index';
                 $PluginReplacement = Gdn::PluginManager()->HasNewMethod($this->ControllerName(), $this->ControllerMethod);
             }
         }
         // Pass in the querystring values
         $Controller->ApplicationFolder = $this->_ApplicationFolder;
         $Controller->Application = $this->EnabledApplication();
         $Controller->ControllerFolder = $this->ControllerFolder;
         $Controller->RequestMethod = $this->ControllerMethod;
         $Controller->RequestArgs = $this->_ControllerMethodArgs;
         $Controller->Request = $Request;
         $Controller->DeliveryType($Request->GetValue('DeliveryType', $this->_DeliveryType));
         $Controller->DeliveryMethod($Request->GetValue('DeliveryMethod', $this->_DeliveryMethod));
         // Set special controller method options for REST APIs.
         $Controller->Initialize();
         $this->EventArguments['Controller'] =& $Controller;
         $this->FireEvent('AfterControllerInit');
         // Call the requested method on the controller - error out if not defined.
         if ($PluginReplacement) {
             // Set the application folder to the plugin's key.
             //            $PluginInfo = Gdn::PluginManager()->GetPluginInfo($PluginReplacement, Gdn_PluginManager::ACCESS_CLASSNAME);
             //            if ($PluginInfo) {
             //               $Controller->ApplicationFolder = 'plugins/'.GetValue('Index', $PluginInfo);
             //            }
             // Reflect the args for the method.
             $Callback = Gdn::PluginManager()->GetCallback($Controller->ControllerName, $ControllerMethod);
             // Augment the arguments to the plugin with the sender and these arguments.
             $InputArgs = array_merge(array($Controller), $this->_ControllerMethodArgs, array('Sender' => $Controller, 'Args' => $this->_ControllerMethodArgs));
             //            decho(array_keys($InputArgs), 'InputArgs');
             $Args = ReflectArgs($Callback, $InputArgs, $Request->Get());
             $Controller->ReflectArgs = $Args;
             try {
                 $this->FireEvent('BeforeControllerMethod');
                 Gdn::PluginManager()->CallEventHandlers($Controller, $Controller->ControllerName, $ControllerMethod, 'Before');
                 call_user_func_array($Callback, $Args);
             } catch (Exception $Ex) {
                 $Controller->RenderException($Ex);
             }
         } elseif (method_exists($Controller, $ControllerMethod)) {
             $Args = ReflectArgs(array($Controller, $ControllerMethod), $this->_ControllerMethodArgs, $Request->Get());
             $this->_ControllerMethodArgs = $Args;
             $Controller->ReflectArgs = $Args;
             try {
                 $this->FireEvent('BeforeControllerMethod');
                 Gdn::PluginManager()->CallEventHandlers($Controller, $Controller->ControllerName, $ControllerMethod, 'Before');
                 call_user_func_array(array($Controller, $ControllerMethod), $Args);
             } catch (Exception $Ex) {
                 $Controller->RenderException($Ex);
                 exit;
             }
         } else {
             $this->EventArguments['Handled'] = FALSE;
             $Handled =& $this->EventArguments['Handled'];
             $this->FireEvent('NotFound');
             if (!$Handled) {
                 Gdn::Request()->WithRoute('Default404');
                 return $this->Dispatch();
             } else {
                 return $Handled;
             }
         }
     }
 }
   /**
    * Analyzes the supplied query string and decides how to dispatch the request.
    */
   public function Dispatch($ImportRequest = NULL, $Permanent = TRUE) {
      if ($ImportRequest && is_string($ImportRequest))
         $ImportRequest = Gdn_Request::Create()->FromEnvironment()->WithURI($ImportRequest);
      
      if (is_a($ImportRequest, 'Gdn_Request') && $Permanent) {
         Gdn::Request($ImportRequest);
      }
      
      $Request = is_a($ImportRequest, 'Gdn_Request') ? $ImportRequest : Gdn::Request();
   
      if (Gdn::Config('Garden.UpdateMode', FALSE)) {
         if (!Gdn::Session()->CheckPermission('Garden.Settings.GlobalPrivs')) {
            // Updatemode, and this user is not root admin
            $Request->WithURI(Gdn::Router()->GetDestination('UpdateMode'));
         }
      }
      
      $this->FireEvent('BeforeDispatch');
      $this->AnalyzeRequest($Request);
            
      // Send user to login page if this is a private community (with some minor exceptions)
      if (
         C('Garden.PrivateCommunity')
         && $this->ControllerName() != 'EntryController'
         && !Gdn::Session()->IsValid()
         && !InArrayI($this->ControllerMethod(), array('UsernameAvailable', 'EmailAvailable', 'TermsOfService'))
      ) {
         Redirect('/entry/signin?Target='.urlencode($this->Request));
         exit();
      }

      $ControllerName = $this->ControllerName();
      
      if ($ControllerName != '' && class_exists($ControllerName)) {
         // Create it and call the appropriate method/action
         $Controller = new $ControllerName();
         
         $this->EventArguments['Controller'] =& $Controller;

         // Pass along any assets
         if (is_array($this->_AssetCollection)) {
            foreach ($this->_AssetCollection as $AssetName => $Assets) {
               foreach ($Assets as $Asset) {
                  $Controller->AddAsset($AssetName, $Asset);
               }
            }
         }

         // Instantiate Imported & Uses classes
         $Controller->GetImports();

         // Pass in the syndication method
         $Controller->SyndicationMethod = $this->_SyndicationMethod;

         // Pass along the request
         $Controller->SelfUrl = $this->Request;

         // Pass along any objects
         foreach($this->_PropertyCollection as $Name => $Mixed) {
            $Controller->$Name = $Mixed;
         }

         // Set up a default controller method in case one isn't defined.
         $ControllerMethod = str_replace('_', '', $this->_ControllerMethod);
         $Controller->OriginalRequestMethod = $ControllerMethod;
         
         $this->FireEvent('AfterAnalyzeRequest');
         
         // Take enabled plugins into account, as well
         $PluginManagerHasReplacementMethod = Gdn::PluginManager()->HasNewMethod($this->ControllerName(), $this->_ControllerMethod);
         if (!$PluginManagerHasReplacementMethod && ($this->_ControllerMethod == '' || !method_exists($Controller, $ControllerMethod))) {
            // Check to see if there is an 'x' version of the method.
            if (method_exists($Controller, 'x'.$ControllerMethod)) {
               // $PluginManagerHasReplacementMethod = TRUE;
               $ControllerMethod = 'x'.$ControllerMethod;
            } else {
               if ($this->_ControllerMethod != '')
                  array_unshift($this->_ControllerMethodArgs, $this->_ControllerMethod);
               
               $this->_ControllerMethod = 'Index';
               $ControllerMethod = 'Index';
               
               $PluginManagerHasReplacementMethod = Gdn::PluginManager()->HasNewMethod($this->ControllerName(), $this->_ControllerMethod);
            }
         }
         
         // Pass in the querystring values
         $Controller->ApplicationFolder = $this->_ApplicationFolder;
         $Controller->Application = $this->EnabledApplication();
         $Controller->ControllerFolder = $this->_ControllerFolder;
         $Controller->RequestMethod = $this->_ControllerMethod;
         $Controller->RequestArgs = $this->_ControllerMethodArgs;
         $Controller->Request = $Request;
         $Controller->DeliveryType($Request->GetValue('DeliveryType', $this->_DeliveryType));
         $Controller->DeliveryMethod($Request->GetValue('DeliveryMethod', $this->_DeliveryMethod));
         
         $this->FireEvent('BeforeControllerMethod');

         // Set special controller method options for REST APIs.
         $this->_ReflectControllerArgs($Controller);
         
         Gdn::Controller($Controller);
         $Controller->Initialize();

         // Call the requested method on the controller - error out if not defined.
         if ($PluginManagerHasReplacementMethod || method_exists($Controller, $ControllerMethod)) {
            // call_user_func_array is too slow!!
            //call_user_func_array(array($Controller, $ControllerMethod), $this->_ControllerMethodArgs);
            
            if ($PluginManagerHasReplacementMethod) {
              try {
                 Gdn::PluginManager()->CallNewMethod($Controller, $Controller->ControllerName, $ControllerMethod);
              } catch (Exception $Ex) {
                 $Controller->RenderException($Ex);
              }
            } else { 
              $Args = $this->_ControllerMethodArgs;
              $Count = count($Args);

              try {
                 call_user_func_array(array($Controller, $ControllerMethod), $Args);
              } catch (Exception $Ex) {
                 $Controller->RenderException($Ex);
                 exit();
              }
            }
         } else {
            Gdn::Request()->WithRoute('Default404');
            return $this->Dispatch();
         }
      }
   }
示例#3
0
 /**
  * Analyzes the supplied query string and decides how to dispatch the request.
  */
 public function Dispatch($ImportRequest = NULL, $Permanent = TRUE)
 {
     if ($ImportRequest && is_string($ImportRequest)) {
         $ImportRequest = Gdn_Request::Create()->FromEnvironment()->WithURI($ImportRequest);
     }
     if (is_a($ImportRequest, 'Gdn_Request') && $Permanent) {
         Gdn::Request($ImportRequest);
     }
     $Request = is_a($ImportRequest, 'Gdn_Request') ? $ImportRequest : Gdn::Request();
     if (Gdn::Config('Garden.UpdateMode', FALSE)) {
         if (!Gdn::Session()->CheckPermission('Garden.Settings.GlobalPrivs')) {
             // Updatemode, and this user is not root admin
             $Request->WithURI(Gdn::Router()->GetDestination('UpdateMode'));
         }
     }
     $this->FireEvent('BeforeDispatch');
     $this->_AnalyzeRequest($Request);
     // Send user to login page if this is a private community
     if (C('Garden.PrivateCommunity') && $this->ControllerName() != 'EntryController' && !Gdn::Session()->IsValid()) {
         Redirect(Gdn::Authenticator()->SignInUrl($this->Request));
         exit;
     }
     /*
     echo "<br />Gdn::Request thinks: ".Gdn::Request()->Path();
     echo "<br />Gdn::Request also suggests: output=".Gdn::Request()->OutputFormat().", filename=".Gdn::Request()->Filename();
     echo '<br />Request: '.$this->Request;      
     echo '<br />App folder: '.$this->_ApplicationFolder;
     echo '<br />Controller folder: '.$this->_ControllerFolder;
     echo '<br />ControllerName: '.$this->_ControllerName;
     echo '<br />ControllerMethod: '.$this->_ControllerMethod;
     */
     $ControllerName = $this->ControllerName();
     if ($ControllerName != '' && class_exists($ControllerName)) {
         // Create it and call the appropriate method/action
         $Controller = new $ControllerName();
         // Pass along any assets
         if (is_array($this->_AssetCollection)) {
             foreach ($this->_AssetCollection as $AssetName => $Assets) {
                 foreach ($Assets as $Asset) {
                     $Controller->AddAsset($AssetName, $Asset);
                 }
             }
         }
         // Instantiate Imported & Uses classes
         $Controller->GetImports();
         // Pass in the syndication method
         $Controller->SyndicationMethod = $this->_SyndicationMethod;
         // Pass along the request
         $Controller->SelfUrl = $this->Request;
         // Pass along any objects
         foreach ($this->_PropertyCollection as $Name => $Mixed) {
             $Controller->{$Name} = $Mixed;
         }
         // Set up a default controller method in case one isn't defined.
         $ControllerMethod = str_replace('_', '', $this->_ControllerMethod);
         $Controller->OriginalRequestMethod = $ControllerMethod;
         // Take enabled plugins into account, as well
         $PluginManagerHasReplacementMethod = Gdn::PluginManager()->HasNewMethod($this->ControllerName(), $this->_ControllerMethod);
         if (!$PluginManagerHasReplacementMethod && ($this->_ControllerMethod == '' || !method_exists($Controller, $ControllerMethod))) {
             // Check to see if there is an 'x' version of the method.
             if (method_exists($Controller, 'x' . $ControllerMethod)) {
                 // $PluginManagerHasReplacementMethod = TRUE;
                 $ControllerMethod = 'x' . $ControllerMethod;
             } else {
                 if ($this->_ControllerMethod != '') {
                     array_unshift($this->_ControllerMethodArgs, $this->_ControllerMethod);
                 }
                 $this->_ControllerMethod = 'Index';
                 $ControllerMethod = 'Index';
                 $PluginManagerHasReplacementMethod = Gdn::PluginManager()->HasNewMethod($this->ControllerName(), $this->_ControllerMethod);
             }
         }
         // Pass in the querystring values
         $Controller->ApplicationFolder = $this->_ApplicationFolder;
         $Controller->Application = $this->EnabledApplication();
         $Controller->ControllerFolder = $this->_ControllerFolder;
         $Controller->RequestMethod = $this->_ControllerMethod;
         $Controller->RequestArgs = $this->_ControllerMethodArgs;
         $Controller->Request = $Request;
         $Controller->DeliveryType($Request->GetValue('DeliveryType', ''));
         $Controller->DeliveryMethod($Request->GetValue('DeliveryMethod', ''));
         $Controller->Initialize();
         // Call the requested method on the controller - error out if not defined.
         if ($PluginManagerHasReplacementMethod || method_exists($Controller, $ControllerMethod)) {
             // call_user_func_array is too slow!!
             //call_user_func_array(array($Controller, $ControllerMethod), $this->_ControllerMethodArgs);
             if ($PluginManagerHasReplacementMethod) {
                 Gdn::PluginManager()->CallNewMethod($Controller, $Controller->ControllerName, $ControllerMethod);
             } else {
                 $Args = $this->_ControllerMethodArgs;
                 $Count = count($Args);
                 if ($Count == 0) {
                     $Controller->{$ControllerMethod}();
                 } else {
                     if ($Count == 1) {
                         $Controller->{$ControllerMethod}($Args[0]);
                     } else {
                         if ($Count == 2) {
                             $Controller->{$ControllerMethod}($Args[0], $Args[1]);
                         } else {
                             if ($Count == 3) {
                                 $Controller->{$ControllerMethod}($Args[0], $Args[1], $Args[2]);
                             } else {
                                 if ($Count == 4) {
                                     $Controller->{$ControllerMethod}($Args[0], $Args[1], $Args[2], $Args[3]);
                                 } else {
                                     if ($Count == 5) {
                                         $Controller->{$ControllerMethod}($Args[0], $Args[1], $Args[2], $Args[3], $Args[4]);
                                     } else {
                                         if ($Count == 6) {
                                             $Controller->{$ControllerMethod}($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5]);
                                         } else {
                                             if ($Count == 7) {
                                                 $Controller->{$ControllerMethod}($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6]);
                                             } else {
                                                 if ($Count == 8) {
                                                     $Controller->{$ControllerMethod}($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], $Args[7]);
                                                 } else {
                                                     if ($Count == 9) {
                                                         $Controller->{$ControllerMethod}($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], $Args[7], $Args[8]);
                                                     } else {
                                                         $Controller->{$ControllerMethod}($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], $Args[7], $Args[8], $Args[9]);
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             Gdn::Request()->WithRoute('Default404');
             return $this->Dispatch();
         }
     }
 }
 public function EntryController_Land_Create($Sender)
 {
     if (!Gdn::Authenticator()->IsPrimary('proxy')) {
         return;
     }
     $LandingRequest = Gdn_Request::Create()->FromImport(Gdn::Request())->WithURI("/dashboard/entry/signin")->WithCustomArgs(array('Landing' => TRUE));
     return Gdn::Dispatcher()->Dispatch($LandingRequest);
 }