CMS  Version 3.9
PhonegapManager Class Reference

Provides support for managing Phonegap apps. More...

Public Member Functions

 PhonegapManager ()
 

Static Public Member Functions

static setDefaults ()
 
static detectPhonegap ()
 Detects whether a phonegap / cordova app is being used to access the current page. More...
 
static hasPhonegap ()
 
static showVersion ()
 
static getOS ()
 Retrieve the current client device's OS (assuming it is running in Phonegap / Cordova) More...
 
static addScript ($script)
 
static registerPhonegapFile ($platform, $version, $file)
 
static getPhonegapFile ($platform, $version)
 
static registerPhonegapAppScript ($platform, $version, $file)
 
static getPhonegapAppScript ($platform, $version)
 
static registerPhonegapSupportScript ($s)
 
static defaultSupportScripts ()
 

Static Public Attributes

static $phonegapFiles = array()
 
static $appScripts = array()
 
static $supportScripts = array()
 

Detailed Description

Provides support for managing Phonegap apps.

Author
andy

Definition at line 19 of file phonegap_manager.inc.

Member Function Documentation

◆ addScript()

static PhonegapManager::addScript (   $script)
static

Definition at line 119 of file phonegap_manager.inc.

120  {
121  global $phonegap;
122  global $phonegap_csp;
123 
125  {
126  ComponentManager::fireEvent("RegisterPhonegapFiles");
127  ComponentManager::fireEvent("RegisterPhonegapAppScripts");
128  ComponentManager::fireEvent("RegisterPhonegapSupportScripts");
129 
130  $os = PhonegapManager::getOS();
131 
132  //AJG: Do not add phonegap script references if we do not definitively know the OS
133  if (!$os) return $script;
134 
135  trace(print_r(PhonegapManager::$appScripts, true), 3);
136 
137  $file = PhonegapManager::getPhonegapFile($os, $_SESSION["phonegap_version"]);
138  $app = PhonegapManager::getPhonegapAppScript($os, $_SESSION["phonegap_version"]);
139 
140  if ($app)
141  {
142  $phonegap = "<script type='text/javascript' src='{$app}'></script>\n".$phonegap;
143  }
144 
145  if (Settings::getValue("phonegap", "use_local_phonegap_files"))
146  {
147  $phonegap_csp = "gap: cdvfile:";
148  $phonegap = "<script type='text/javascript' src='cdvfile://localhost/bundle/www/cordova.js'></script>".$phonegap;
149  }
150  else
151  {
152  $phonegap_csp = "gap:";
153  $phonegap = "<script type='text/javascript' src='{$file}'></script>\n".$phonegap;
154  }
155  foreach(PhonegapManager::$supportScripts as $supportScript => $dummy)
156  {
157  $phonegap .= "<script type='text/javascript' src='{$supportScript}'></script>\n";
158  }
159  }
160  else
161  {
162  $phonegap = "";
163  }
164 
165  return $script;
166  }
$dummy
Definition: data_import.inc:7
$file
Definition: delete.inc:47
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
static getOS()
Retrieve the current client device's OS (assuming it is running in Phonegap / Cordova)
static getPhonegapFile($platform, $version)
static getPhonegapAppScript($platform, $version)
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
global $phonegap
Provides a central management class for event handlers and common functionality for the phonegap comp...
$_SESSION["useMobile"]
Definition: override.inc:7

◆ defaultSupportScripts()

static PhonegapManager::defaultSupportScripts ( )
static

Definition at line 221 of file phonegap_manager.inc.

222  {
223  PhonegapManager::registerPhonegapSupportScript("/components/phonegap/js/photo_uploader.js");
224  PhonegapManager::registerPhonegapSupportScript("/components/phonegap/js/photo_attachment_uploader.js");
225  }
static registerPhonegapSupportScript($s)

◆ detectPhonegap()

static PhonegapManager::detectPhonegap ( )
static

Detects whether a phonegap / cordova app is being used to access the current page.

Definition at line 42 of file phonegap_manager.inc.

43  {
44  global $script;
45 
46  trace("Detecting PhoneGap", 4);
47 
48  if ($_SESSION["phonegap"])
49  {
50  if ($_SESSION["phonegap_os"] != "" && $_SESSION["phonegap_version"] != "")
51  {
52  return;
53  }
54  else
55  {
56  trace("Phonegap flag without OS or version detected in session for {$_SERVER["REMOTE_ADDR"]} - resetting", 2);
57  $_SESSION["phonegap"] = false;
58  }
59  }
60 
61  $matches = array();
62  if (preg_match("/PhoneGap\\/Cordova (\\w+) (\\d+\\.\\d+\\.\\d+)/i", $_SERVER['HTTP_USER_AGENT'], $matches))
63  {
64  $_SESSION["phonegap"] = true;
65  $_SESSION["phonegap_os"] = $matches[1];
66  $_SESSION["phonegap_version"] = $matches[2];
67 
68  trace("PhoneGap {$_SESSION["phonegap_version"]} for {$_SESSION["phonegap_os"]} enabled for {$_SERVER["REMOTE_ADDR"]} via User Agent", 2);
69  }
70  else if ($_POST["phonegap"] && $_POST["phonegap_version"] != "" && $_POST["phonegap_os"] != "")
71  {
72  $_SESSION["phonegap"] = true;
73  $_SESSION["phonegap_version"] = $_POST["phonegap_version"];
74  $_SESSION["phonegap_os"] = $_POST["phonegap_os"];
75 
76  trace("PhoneGap {$_SESSION["phonegap_version"]} for {$_SESSION["phonegap_os"]} enabled for {$_SERVER["REMOTE_ADDR"]} via POST", 2);
77  }
78  else if (Settings::getValue("phonegap", "enable_phonegap_debugging") && $_GET["phonegap"])
79  {
80  $_SESSION["phonegap"] = true;
81  $_SESSION["phonegap_version"] = Settings::getValue("phonegap", "phonegap_debug_version");
82  $_SESSION["phonegap_os"] = Settings::getValue("phonegap", "phonegap_debug_os");
83 
84  trace("PhoneGap {$_SESSION["phonegap_version"]} for {$_SESSION["phonegap_os"]} enabled for {$_SERVER["REMOTE_ADDR"]} in debugging mode", 2);
85  }
86 
87  if ($_SESSION["phonegap_os"] == "droid") $_SESSION["phonegap_os"] = "android";
88  }
$_POST["owner_id"]
Definition: blog_form.inc:54

◆ getOS()

static PhonegapManager::getOS ( )
static

Retrieve the current client device's OS (assuming it is running in Phonegap / Cordova)

Returns
string the device OS

Definition at line 112 of file phonegap_manager.inc.

113  {
114  $os = $_SESSION["phonegap_os"];
115  if ($os == "droid") $os = "android";
116  return $os;
117  }

◆ getPhonegapAppScript()

static PhonegapManager::getPhonegapAppScript (   $platform,
  $version 
)
static

Definition at line 194 of file phonegap_manager.inc.

195  {
196  $key = "{$platform}-{$version}";
197  if (array_key_exists($key, PhonegapManager::$appScripts))
198  {
199  return PhonegapManager::$appScripts[$key];
200  }
201 
202  $key = "*-{$version}";
203  if (array_key_exists($key, PhonegapManager::$appScripts))
204  {
205  return PhonegapManager::$appScripts[$key];
206  }
207 
208  if (array_key_exists("*-*", PhonegapManager::$appScripts))
209  {
210  return PhonegapManager::$appScripts["*-*"];
211  }
212 
213  return "";
214  }

◆ getPhonegapFile()

static PhonegapManager::getPhonegapFile (   $platform,
  $version 
)
static

Definition at line 175 of file phonegap_manager.inc.

176  {
177  $key = "{$platform}-{$version}";
178  if (array_key_exists($key, PhonegapManager::$phonegapFiles))
179  {
180  // Send the registered configured file for the platform and version
181  return PhonegapManager::$phonegapFiles[$key];
182  }
183 
184  // Send default file with no plugins
185  return "/components/phonegap/js/{$platform}/cordova-{$version}.js";
186  }

◆ hasPhonegap()

static PhonegapManager::hasPhonegap ( )
static

Definition at line 90 of file phonegap_manager.inc.

91  {
92  if (!Settings::getValue("phonegap", "enable_phonegap")) return false;
93  return (isset($_SESSION["phonegap"]) && $_SESSION["phonegap"] == true) || stripos($_SERVER['HTTP_USER_AGENT'], "PhoneGap/Cordova") !== false;
94  }

◆ PhonegapManager()

PhonegapManager::PhonegapManager ( )

Definition at line 25 of file phonegap_manager.inc.

26  {
27 
28  }

◆ registerPhonegapAppScript()

static PhonegapManager::registerPhonegapAppScript (   $platform,
  $version,
  $file 
)
static

Definition at line 188 of file phonegap_manager.inc.

189  {
190  trace("Registering Phonegap App Script for $platform $version: $file", 3);
191  PhonegapManager::$appScripts["{$platform}-{$version}"] = $file;
192  }

◆ registerPhonegapFile()

static PhonegapManager::registerPhonegapFile (   $platform,
  $version,
  $file 
)
static

Definition at line 168 of file phonegap_manager.inc.

169  {
170  trace("Registering Phonegap file for $platform $version: $file", 3);
171 
172  PhonegapManager::$phonegapFiles["{$platform}-{$version}"] = $file;
173  }

◆ registerPhonegapSupportScript()

static PhonegapManager::registerPhonegapSupportScript (   $s)
static

Definition at line 216 of file phonegap_manager.inc.

217  {
219  }

◆ setDefaults()

static PhonegapManager::setDefaults ( )
static

Definition at line 30 of file phonegap_manager.inc.

31  {
32  Settings::setDefaultValue("phonegap", "enable_phonegap", true, Boolean, "Enables support for Phonegap/Cordova applications");
33  Settings::setDefaultValue("phonegap", "enable_phonegap_debugging", false, Boolean, "Enables PhoneGap debugging mode - append phonegap=1 to any URL in your desktop browser to turn on PhoneGap mode");
34  Settings::setDefaultValue("phonegap", "phonegap_debug_version", "2.4.0", String, "The version of Phonegap that is assumed in debugging mode");
35  Settings::setDefaultValue("phonegap", "phonegap_debug_os", "android", String, "The OS of Phonegap that is assumed in debugging mode");
36  Settings::setDefaultValue("phonegap", "use_local_phonegap_files", false, Boolean, "Check this box to pull the local cordova files in the packaged app, instead of pulling them from the server (EXPERIMENTAL)");
37  }
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

◆ showVersion()

static PhonegapManager::showVersion ( )
static

Definition at line 96 of file phonegap_manager.inc.

97  {
98  if ($_SESSION["phonegap"])
99  {
100  echo "<p>Using Phonegap version ".$_SESSION["phonegap_version"]." on ".$_SESSION["phonegap_os"]."</p>";
101  }
102  else
103  {
104  echo "<p>Not using Phonegap</p>";
105  }
106  }

Member Data Documentation

◆ $appScripts

PhonegapManager::$appScripts = array()
static

Definition at line 22 of file phonegap_manager.inc.

◆ $phonegapFiles

PhonegapManager::$phonegapFiles = array()
static

Definition at line 21 of file phonegap_manager.inc.

◆ $supportScripts

PhonegapManager::$supportScripts = array()
static

Definition at line 23 of file phonegap_manager.inc.


The documentation for this class was generated from the following file: