CMS  Version 3.9
redirect_manager.inc
Go to the documentation of this file.
1 <?php
14 {
15  function RedirectManager()
16  {
17 
18  }
19 
20  static function setDefaults()
21  {
22  //TODO: Set default configuration parameters here
23  }
24 
25 
26 
27  static function upgradeComponent($version)
28  {
30  $mgr->upgrade($version);
31  }
32 
33  static function handleRedirects($identifier)
34  {
35  global $section;
36  $path = "";
37  if ($section->section != "/") $path .= "/" . $section->section;
38  $path .= "/" . $identifier;
39 
40  trace("Redirect: $path", 3);
41 
42  try
43  {
44  $redirect = Query::create(Redirect, "WHERE redirect_from=:p")
45  ->bind(":p", $path)
46  ->executeSingle();
47 
48  if ($redirect->preserve_query_string)
49  {
50  $redirect = (strpos($redirect->redirect_to, "?") === false) ?
51  $redirect->redirect_to."?".getCleanQueryString() :
52  $redirect->redirect_to."&".getCleanQueryString();
53  redirect($redirect);
54  }
55  else
56  {
57  redirect($redirect->redirect_to);
58  }
59  }
60  catch(DataNotFoundException $e)
61  {
62 
63  }
64 
65  return $identifier;
66  }
67 
68  static function handleSectionRedirects()
69  {
70  $redirects = Query::create(Redirect, "WHERE active=1 AND redirect_from=:p")
71  ->bind(":p", Fakoli::$requestURI)
72  ->execute();
73  if (count($redirects) > 0)
74  {
75  redirect($redirects[0]->redirect_to);
76  }
77  }
78 
79  static function handleOverrides($identifier)
80  {
81  global $section;
82  $path = "";
83  if ($section->section != "/") $path .= "/" . $section->section;
84  $path .= "/" . $identifier;
85 
86  trace("Redirect: $path", 3);
87 
88  $overrides = Cache::get("resource_overrides");
89 
90  if (!$overrides)
91  {
92  $overrides = IndexedQuery::create(Redirect, "WHERE override=1 and active=1", "redirect_from")->execute();
93  Cache::put("resource_overrides", $overrides);
94  }
95 
96  if (array_key_exists($path, $overrides))
97  {
98  $redirect = $overrides[$path];
99 
100  if ($redirect->exempt_roles && checkRole($redirect->exempt_roles)) return;
101  if ($redirect->exemption_flag && $_SESSION[$redirect->exemption_flag]) return;
102 
103  if ($redirect->preserve_query_string)
104  {
105  $redirect = (strpos($redirect->redirect_to, "?") === false) ?
106  $redirect->redirect_to."?".getCleanQueryString() :
107  $redirect->redirect_to."&".getCleanQueryString();
108  redirect($redirect);
109  }
110  else
111  {
112  redirect($redirect->redirect_to);
113  }
114  }
115  }
116 
117 
119  {
121  return true;
122  }
123 }
124 ?>
$redirect
$section
Definition: event_form.inc:44
if(! $page) $path
Definition: page.inc:57
static $requestURI
The initial request URI.
Definition: core.inc:88
Provides a central management class for event handlers and common functionality for the redirect comp...
static handleRedirects($identifier)
static handleOverrides($identifier)
static handleSectionRedirects()
static upgradeComponent($version)
static registerSerializationHandler()
registerHandler($component, $title, $handler)
Registers a serialization handler for a component.
Provides a simple implementation of a SerializationHandler that can serialize a single DataItem class...
$_SESSION["useMobile"]
Definition: override.inc:7
$redirects
Definition: redirects.inc:6
$identifier
Definition: rss.inc:37