CMS  Version 3.9
mobile_content_manager.inc
Go to the documentation of this file.
1 <?php
7 Fakoli::using("settings", "section", "menu");
8 
15 {
17  {
18 
19  }
20 
21  static function setDefaults()
22  {
23  Settings::setDefaultValue("mobile_settings", "mobile_content_mode", "Deliver Full Content", String, "Sets the content delivery mode for mobile content", "", "Deliver Full Content\nUse Mobile Template\nDedicated Mobile Section");
24  Settings::setDefaultValue("mobile_settings", "mobile_content_section", "", String, "The identifier of the section providing dedicated mobile content");
25  Settings::setDefaultValue("mobile_settings", "send_mobile_content_to_tablets", false, Boolean);
26  Settings::setDefaultValue("mobile_settings", "use_native_form_controls", false, Boolean, "Use native HTML 5 controls for date and time fields (when available on mobile device)");
27  }
28 
29  static function onInitialize()
30  {
31  global $isResource;
32  global $isAction;
33  global $auto_form_defaults;
34 
35  $identifier = checkIdentifier($_GET["identifier"]);
36 
37  $mode = Settings::getValue("mobile_settings", "mobile_content_mode");
38  $useNative = Settings::getValue("mobile_settings", "use_native_form_controls");
39 
40  $useMobile = MobileSettingsManager::useMobile();
41  $isTablet = MobileSettingsManager::isTablet();
42 
43  MenuManager::setDisplayFlag("mobile", $useMobile);
44  MenuManager::setDisplayFlag("tablet", $isTablet);
45 
46  if ($useMobile && !$isTablet)
47  {
48  $auto_form_defaults["default_layout"] = "mobile";
49  }
50 
51  if ($useMobile && $useNative)
52  {
53  $detect = new MobileDetect();
54  if ($detect->isiPhone() || $detect->isiPad())
55  {
56  Fakoli::usingFeature("auto_form");
57  AutoForm::registerFieldRendererClass(DateTime, NativeDateTimeFieldRenderer);
58  AutoForm::registerFieldRendererClass(Date, NativeDateFieldRenderer);
59  }
60  }
61 
62  if ($isResource || $isAction || $mode == "Deliver Full Content") return;
63 
64  if ($mode != "Dedicated Mobile Section" || !$useMobile) return;
65 
66  trace ("Using Dedicated Mobile Section", 4);
67 
68  $section = checkIdentifier($_GET["section"]);
69 
70  $mobileSection = Settings::getValue("mobile_settings", "mobile_content_section");
71 
72  if ($mobileSection == "") return;
73 
74  trace("Mobile: $mobileSection vs $section", 4);
75 
76  if ($mobileSection != $section)
77  {
78  if ($useMobile)
79  {
80  $mobileSectionObject = Section::findSection($mobileSection);
81  if ($mobileSectionObject->getContent($identifier))
82  {
83  $pattern = ($section == "") ? "#^/#" : "#/^{$section}/#";
84  $uri = preg_replace($pattern, "/{$mobileSection}/", $_SERVER["REQUEST_URI"]);
85  }
86  else
87  {
88 
89  $uri = ($mobileSection == "/") ? "/" : "/{$mobileSection}/";
90  }
91 
92  trace("Redirecting to mobile section at $uri", 3);
93  redirect($uri);
94  }
95  }
96  else
97  {
99  {
100  $auto_form_defaults["default_layout"] = "mobile";
101  }
102  }
103  }
104 
105  static function overrideTemplate($template, &$continue)
106  {
107  global $site;
108 
109  if (!MobileSettingsManager::useMobile()) return $template;
110 
111  $mode = Settings::getValue("mobile_settings", "mobile_content_mode");
112  $mode = ($mode == "Use Mobile Template");
113  $continue = !$mode;
114  $out = $mode ? $site->mobile_template : $template;
115 
116  trace("OverrideTemplate: $template -> $out", 4);
117  return $out;
118  }
119 
120  static function useMobile()
121  {
122  if (isset($_SESSION["useMobile"])) return $_SESSION["useMobile"];
123 
124  $mobileTablets = Settings::getValue("mobile_settings", "send_mobile_content_to_tablets");
125 
126  $detect = new MobileDetect();
127 
128  $mobile = false;
129 
130  if ($detect->isTablet())
131  {
132  $mobile = $mobileTablets;
133  }
134  else $mobile = $detect->isMobile();
135 
136  trace("useMobile: ".($mobile?'true':'false'), 4);
137 
138  return $mobile;
139  }
140 
141  static function isTablet()
142  {
143  $detect = new MobileDetect();
144  return $detect->isTablet();
145  }
146 }
147 ?>
$section
Definition: event_form.inc:44
$out
Definition: page.inc:66
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static setDisplayFlag($name, $value=true)
Mobile Detect.
Provides a central management class for event handlers and common functionality for the mobile compon...
static overrideTemplate($template, &$continue)
static findSection($section_name)
Definition: section.inc:145
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
static setDefaultValue($component, $name, $value, $field_type="String", $annotation="", $category="", $options="", $weight=0)
Sets the default value of the given component setting.
Definition: settings.inc:174
$isResource
Definition: core.inc:1585
if($config["default_content_type"]) $isAction
Definition: core.inc:1584
$mode
$mobile
Definition: override.inc:4
$_SESSION["useMobile"]
Definition: override.inc:7
$identifier
Definition: rss.inc:37
$uri
Definition: tearoff.inc:4