Example #1
0
 /**
  * Returns the {@link $path} property normalized using the
  * {@link \ICanBoogie\normalize_url_path()} function.
  *
  * @return string
  */
 protected function get_normalized_path()
 {
     return \ICanBoogie\normalize_url_path($this->path);
 }
Example #2
0
 /**
  * Redirects the request to the first available website to the user if the request matches
  * none.
  *
  * Only online websites are used if the user is a guest or a member.
  *
  * @param Dispatcher\BeforeDispatchEvent $event
  * @param Dispatcher $target
  */
 public static function before_http_dispatcher_dispatch(Dispatcher\BeforeDispatchEvent $event, Dispatcher $target)
 {
     global $core;
     if ($core->site_id) {
         return;
     }
     $request = $event->request;
     if (!in_array($request->method, array(Request::METHOD_ANY, Request::METHOD_GET, Request::METHOD_HEAD))) {
         return;
     }
     $path = \ICanBoogie\normalize_url_path(\ICanBoogie\Routing\decontextualize($request->path));
     if (strpos($path, '/api/') === 0) {
         return;
     }
     try {
         $query = $core->models['sites']->order('weight');
         $user = $core->user;
         if ($user->is_guest || $user instanceof \Icybee\Modules\Members\Member) {
             $query->filter_by_status(Site::STATUS_OK);
         }
         $site = $query->one;
         if ($site) {
             $request_url = \ICanBoogie\normalize_url_path($core->site->url . $request->path);
             $location = \ICanBoogie\normalize_url_path($site->url . $path);
             #
             # we don't redirect if the redirect location is the same as the request URL.
             #
             if ($request_url != $location) {
                 $query_string = $request->query_string;
                 if ($query_string) {
                     $location .= '?' . $query_string;
                 }
                 $event->response = new RedirectResponse($location, 302, array('Icybee-Redirected-By' => __CLASS__ . '::' . __FUNCTION__));
                 return;
             }
         }
     } catch (\Exception $e) {
     }
     \ICanBoogie\log_error('You are on a dummy website. You should check which websites are available or create one if none are.');
 }