get() public method

Get a value from the GET array or return the entire GET array.
public get ( string | null $key = null, mixed $default = null ) : mixed
$key string | null The key of the get item or null to return the entire get array.
$default mixed The value to return if the item isn't set.
return mixed
Exemplo n.º 1
0
 /**
  * Check whether all condition are met for this plugin to do its magic.
  *
  * @param Gdn_Request $request
  * @param int|bool $categoryID Category ID of the welcome category if it exists and this function return true
  * @return bool
  */
 protected function isWelcomePostActive($request, &$categoryID)
 {
     static $cachedCategoryID = null;
     if ($cachedCategoryID === null) {
         $isWelcomePost = true;
         if ($request->get('welcomepost', false) !== "true") {
             $cachedCategoryID = false;
             return false;
         }
         if (!Gdn::session()->isValid()) {
             $cachedCategoryID = false;
             return false;
         }
         $category = (array) CategoryModel::instance()->getByCode('welcome');
         $cachedCategoryID = val('CategoryID', $category, false);
         if (!$cachedCategoryID) {
             return false;
         }
         $categoryID = $cachedCategoryID;
     } else {
         $isWelcomePost = (bool) $cachedCategoryID;
         $categoryID = $cachedCategoryID;
     }
     return $isWelcomePost;
 }
Exemplo n.º 2
0
 /**
  * Rewrite the request based on rewrite rules (currently called routes in Vanilla).
  *
  * This method modifies the passed {@link $request} object. It can also cause a redirect if a rule matches that
  * specifies a redirect.
  *
  * @param Gdn_Request $request The request to rewrite.
  */
 private function rewriteRequest($request)
 {
     $pathAndQuery = $request->PathAndQuery();
     $matchRoute = Gdn::router()->matchRoute($pathAndQuery);
     // We have a route. Take action.
     if (!empty($matchRoute)) {
         $dest = $matchRoute['FinalDestination'];
         if (strpos($dest, '?') === false) {
             // The rewrite rule doesn't include a query string so keep the current one intact.
             $request->path($dest);
         } else {
             // The rewrite rule has a query string so rewrite that too.
             $request->pathAndQuery($dest);
         }
         switch ($matchRoute['Type']) {
             case 'Internal':
                 // Do nothing. The request has been rewritten.
                 break;
             case 'Temporary':
                 safeHeader("HTTP/1.1 302 Moved Temporarily");
                 safeHeader("Location: " . url($matchRoute['FinalDestination']));
                 exit;
                 break;
             case 'Permanent':
                 safeHeader("HTTP/1.1 301 Moved Permanently");
                 safeHeader("Location: " . url($matchRoute['FinalDestination']));
                 exit;
                 break;
             case 'NotAuthorized':
                 safeHeader("HTTP/1.1 401 Not Authorized");
                 break;
             case 'NotFound':
                 safeHeader("HTTP/1.1 404 Not Found");
                 break;
             case 'Drop':
                 die;
             case 'Test':
                 decho($matchRoute, 'Route');
                 decho(array('Path' => $request->path(), 'Get' => $request->get()), 'Request');
                 die;
         }
     } elseif (in_array($request->path(), ['', '/'])) {
         $this->isHomepage = true;
         $defaultController = Gdn::router()->getRoute('DefaultController');
         $request->pathAndQuery($defaultController['Destination']);
     }
     return $request;
 }