BMLT Basic Standalone Satellite
bmlt_basic.class.php
Go to the documentation of this file.
1 <?php
2 
3 /****************************************************************************************/
4 
5 /**
6 * \file bmlt_basic.class.php *
7 * *
8 * \brief This is a standalone implementation of a BMLT satellite client. *
9 * \version 3.11.0 *
10 * *
11 * In order to use this class, you need to take this entire directory and its contents, *
12 * and place it at the same level of the file that you wish to use as your implementation. *
13 * The "index.php" file in the repository is an example of this. It is important that the *
14 * implementation file be one level above this file (or at the same level as the *
15 * "bmlt-basic" directory). *
16 * *
17 * This file is part of the Basic Meeting List Toolbox (BMLT). *
18 * *
19 * Find out more at: http://bmlt.app *
20 * *
21 * BMLT is free software: you can redistribute it and/or modify *
22 * it under the terms of the GNU General Public License as published by *
23 * the Free Software Foundation, either version 3 of the License, or *
24 * (at your option) any later version. *
25 * *
26 * BMLT is distributed in the hope that it will be useful, *
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
29 * GNU General Public License for more details. *
30 * *
31 * You should have received a copy of the GNU General Public License *
32 * along with this code. If not, see <http://www.gnu.org/licenses/>. *
33 ********************************************************************************************/
34 
35 ob_start();
36 
37 // define ( '_DEBUG_MODE_', 1 ); //Uncomment for easier JavaScript debugging.
38 
39 // Include our configuration.
40 require_once(dirname(__FILE__) . '/../config-bmlt-basic.inc.php');
41 // Include the satellite driver class.
42 define('ROOTPATH', __DIR__);
43 require_once(ROOTPATH . '/vendor/bmlt/bmlt-satellite-base-class/bmlt-cms-satellite-plugin.php');
44 
45 /****************************************************************************************//**
46 * \class bmlt_basic *
47 * *
48 * \brief
49 ********************************************************************************************/
50 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
51 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
52 class bmlt_basic extends BMLTPlugin
53 {
54  // phpcs:enable Squiz.Classes.ValidClassName.NotCamelCaps
55  // phpcs:enable PSR1.Classes.ClassDeclaration.MissingNamespace
56  public $my_shortcode = null; ///< This will hold the given shortcode.
57 
58  /************************************************************************************//**
59  * CLIENT FUNCTIONS *
60  ****************************************************************************************/
61 
62  /************************************************************************************//**
63  * \brief Outputs the head HTML, CSS and JavaScript. *
64  ****************************************************************************************/
65  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
66  public function output_head($in_shortcode = '[[bmlt]]')
67  {
68  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
69  ///< You need to provide a shortcode, if you want something other than the default.
70  $this->my_shortcode = $in_shortcode; // Save this.
71  echo $this->standard_head($this->my_shortcode);
72  }
73 
74  /************************************************************************************//**
75  * \brief Outputs the body HTML and JavaScript. *
76  ****************************************************************************************/
77  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
78  public function output_body()
79  {
80  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
81  echo $this->content_filter($this->my_shortcode);
82  }
83 
84  /************************************************************************************//**
85  * INTERNAL FUNCTIONS (NOT CALLED BY CLIENT) *
86  ****************************************************************************************/
87 
88  /************************************************************************************//**
89  * \brief Return an HTTP path to the AJAX callback target. *
90  * *
91  * \returns a string, containing the path. *
92  ****************************************************************************************/
93  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
94  protected function get_ajax_base_uri()
95  {
96  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
97  // We try to account for SSL and unusual TCP ports.
98  $port = null;
99  $https = false;
100  $from_proxy = array_key_exists("HTTP_X_FORWARDED_PROTO", $_SERVER);
101  if ($from_proxy) {
102  // If the port is specified in the header, use it. If not, default to 80
103  // for http and 443 for https. We can't trust what's in $_SERVER['SERVER_PORT']
104  // because something in front of the server is fielding the request.
105  $https = $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https';
106  if (array_key_exists("HTTP_X_FORWARDED_PORT", $_SERVER)) {
107  $port = intval($_SERVER['HTTP_X_FORWARDED_PORT']);
108  } elseif ($https) {
109  $port = 443;
110  } else {
111  $port = 80;
112  }
113  } else {
114  $port = $_SERVER['SERVER_PORT'];
115  // IIS puts "off" in the HTTPS field, so we need to test for that.
116  $https = (!empty($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] !== 'off') || ($port == 443)));
117  }
118  $server_path = $_SERVER['SERVER_NAME'];
119  $my_path = $_SERVER['PHP_SELF'];
120  $server_path .= trim((($https && ($port != 443)) || (!$https && ($port != 80))) ? ':' . $port : '', '/');
121  $server_path = 'http' . ($https ? 's' : '') . '://' . $server_path . $my_path;
122  return $server_path;
123  }
124 
125  /************************************************************************************//**
126  * \brief Return an HTTP path to the plugin directory. *
127  * *
128  * \returns a string, containing the path. *
129  ****************************************************************************************/
130  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
131  protected function get_plugin_path()
132  {
133  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
134  $ret = isset($this->my_http_vars['base_url']) ? $this->my_http_vars['base_url'] : dirname($this->get_ajax_base_uri()) . '/bmlt-basic/vendor/bmlt/bmlt-satellite-base-class/';
135 
136  return $ret;
137  }
138 
139  /************************************************************************************//**
140  * \brief This uses the CMS text processor (t) to process the given string. *
141  * *
142  * This allows easier translation of displayed strings. All strings displayed by the *
143  * plugin should go through this function. *
144  * *
145  * \returns a string, processed by WP. *
146  ****************************************************************************************/
147  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
148  public function process_text($in_string)
149  {
150  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
151  $in_string = htmlspecialchars($in_string);
152 
153  return $in_string;
154  }
155 
156  /************************************************************************************//**
157  * \brief This gets the default admin options from the object (not the DB). *
158  * *
159  * \returns an associative array, with the default option settings. *
160  ****************************************************************************************/
161  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
162  protected function geDefaultBMLTOptions()
163  {
164  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
166  // These are the defaults. If the saved option has a different value, it replaces the ones in here.
167  return $bmlt_basic_configuration[0];
168  }
169 
170  /************************************************************************************//**
171  * \brief This gets the admin options from the config file. *
172  * *
173  * \returns an associative array, with the option settings. *
174  ****************************************************************************************/
175  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
176  protected function cms_get_option($in_option_key)
177  {
178  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
180  global $bmlt_basic_configuration_index;
181 
182  $ret = null;
183 
184  if ($in_option_key != self::$admin2OptionsName) {
185  $index = intval(max($bmlt_basic_configuration_index - 1, intval(str_replace(self::$adminOptionsName . '_', '', $in_option_key))));
186 
187  $ret = $bmlt_basic_configuration[$index];
188  } else {
189  $ret = array ( 'num_servers' => $bmlt_basic_configuration_index );
190  }
191 
192  return $ret;
193  }
194 
195  /************************************************************************************//**
196  * \brief This function fetches the settings ID for a page (if there is one). *
197  * *
198  * If $in_check_mobile is set to true, then ONLY a check for mobile support will be *
199  * made, and no other shortcodes will be checked. *
200  * *
201  * \returns a mixed type, with the settings ID. *
202  ****************************************************************************************/
203  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
204  protected function cms_get_page_settings_id(
205  $in_text, ///< Required (for the base version) content to check.
206  $in_check_mobile = false ///< True if this includes a check for mobile. Default is false.
207  ) {
208  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
209  $my_option_id = 0;
210 
211  if (!$in_check_mobile && isset($this->my_http_vars['bmlt_settings_id']) && is_array($this->getBMLTOptions($this->my_http_vars['bmlt_settings_id']))) {
212  $my_option_id = $this->my_http_vars['bmlt_settings_id'];
213  } else {
214  $support_mobile = self::get_shortcode($in_text, 'bmlt_mobile');
215 
216  if ($support_mobile === true) {
217  $options = $this->getBMLTOptions(1);
218  $support_mobile = strval($options['id']);
219  }
220 
221  if ($in_check_mobile && $support_mobile && !isset($this->my_http_vars['BMLTPlugin_mobile']) && (self::mobile_sniff_ua($this->my_http_vars) != 'xhtml')) {
222  $my_option_id = $support_mobile;
223  } elseif (!$in_check_mobile) {
224  if (isset($this->my_http_vars['bmlt_settings_id']) && intval($this->my_http_vars['bmlt_settings_id'])) {
225  $my_option_id = intval($this->my_http_vars['bmlt_settings_id']);
226  } elseif ($in_text) {
227  $my_option_id_content = parent::cms_get_page_settings_id($in_text, $in_check_mobile);
228 
229  $my_option_id = $my_option_id_content ? $my_option_id_content : $my_option_id;
230  }
231 
232  if (!$my_option_id) { // If nothing else gives, we go for the default (first) settings.
233  $options = $this->getBMLTOptions(1);
234  $my_option_id = $options['id'];
235  }
236  }
237  }
238 
239  return $my_option_id;
240  }
241 
242  /************************************************************************************//**
243  * \brief returns any necessary head content. *
244  ****************************************************************************************/
245  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
246  public function standard_head($in_text = null)
247  {
248  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
249  ///< This is the page content text.
250  $this->ajax_router();
251  $load_head = false; // This is a throwback. It prevents the GM JS from being loaded if there is no directly specified settings ID.
252  $head_content = "<!-- Added by the BMLT plugin 3.X. -->\n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=EmulateIE7\" /><meta http-equiv=\"Content-Style-Type\" content=\"text/css\" /><meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\" />";
253 
254  $support_mobile = $this->cms_get_page_settings_id($in_text, true);
255 
256  if ($support_mobile) {
257  $mobile_options = $this->getBMLTOptions_by_id($support_mobile);
258  } else {
259  $support_mobile = null;
260  }
261 
262  $options = $this->getBMLTOptions_by_id($this->cms_get_page_settings_id($in_text));
263 
264  if ($support_mobile && is_array($mobile_options) && count($mobile_options)) {
265  $mobile_url = $_SERVER['PHP_SELF'] . '?BMLTPlugin_mobile&bmlt_settings_id=' . $support_mobile;
266 
267  if (isset($this->my_http_vars['WML'])) {
268  $mobile_url .= '&WML=' . intval($this->my_http_vars['WML']);
269  }
270  if (isset($this->my_http_vars['simulate_smartphone'])) {
271  $mobile_url .= '&simulate_smartphone';
272  }
273 
274  if (ob_get_contents()) {
275  ob_end_clean();
276  }
277 
278  header("location: $mobile_url");
279  die();
280  }
281 
282  $load_server_header = $this->get_shortcode($in_text, 'bmlt');
283 
284  $this->my_http_vars['start_view'] = $options['bmlt_initial_view'];
285 
286  $this->load_params();
287 
288  $root_server_root = $options['root_server'];
289 
290  $head_content .= '<meta name="BMLT-Root-URI" content="' . htmlspecialchars($root_server_root) . '" />';
291 
292  $head_content .= "\n" . '<style type="text/css">' . "\n";
293  $temp = self::stripFile("styles.css", $options['theme']);
294  if ($temp) {
295  $image_dir_path = $this->get_plugin_path() . '/themes/' . $options['theme'] . '/images/';
296  $temp = str_replace('##-IMAGEDIR-##', $image_dir_path, $temp);
297  $head_content .= "\t$temp\n";
298  }
299  $temp = self::stripFile("nouveau_map_styles.css", $options['theme']);
300  if ($temp) {
301  $image_dir_path = $this->get_plugin_path() . '/themes/' . $options['theme'] . '/images/';
302  $temp = str_replace('##-IMAGEDIR-##', $image_dir_path, $temp);
303  $head_content .= "\t$temp\n";
304  }
305 
306  $head_content .= self::stripFile('table_styles.css') . "\n";
307  $head_content .= self::stripFile('quicksearch.css') . "\n";
308 
309  $dirname = ROOTPATH . '/vendor/bmlt/bmlt-satellite-base-class/themes';
310  $dir = new DirectoryIterator($dirname);
311 
312  foreach ($dir as $fileinfo) {
313  if (!$fileinfo->isDot()) {
314  $fName = $fileinfo->getFilename();
315  $temp = self::stripFile("table_styles.css", $fName);
316  if ($temp) {
317  $image_dir_path = $this->get_plugin_path() . '/themes/' . $fName . '/images/';
318  $temp = str_replace('##-IMAGEDIR-##', $image_dir_path, $temp);
319  $head_content .= "\t$temp\n";
320  }
321  $temp = self::stripFile("quicksearch.css", $fName);
322  if ($temp) {
323  $head_content .= "\t$temp\n";
324  }
325  }
326  }
327  $head_content .= self::stripFile('responsiveness.css') . "\n";
328  $head_content .= "\n</style>\n";
329  $head_content .= '<script type="text/javascript">';
330 
331  $head_content .= self::stripFile('javascript.js');
332 
333  if ($this->get_shortcode($in_text, 'bmlt_quicksearch')) {
334  $head_content .= self::stripFile('quicksearch.js') . (defined('_DEBUG_MODE_') ? "\n" : '');
335  }
336 
337  if ($this->get_shortcode($in_text, 'bmlt_map')) {
338  $head_content .= self::stripFile('map_search.js');
339  }
340 
341  if ($this->get_shortcode($in_text, 'bmlt_mobile')) {
342  $head_content .= self::stripFile('fast_mobile_lookup.js');
343  }
344 
345  $head_content .= '</script>';
346 
347  return $head_content;
348  }
349 
350  /************************************************************************************//**
351  * THESE ARE ALL DISABLED IN THE BASIC SATELLITE *
352  ****************************************************************************************/
353  /************************************************************************************//**
354  * \brief We don't do admin in this variant, so this makes that clear. *
355  * *
356  * \returns null *
357  ****************************************************************************************/
358  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
359  protected function get_admin_ajax_base_uri()
360  {
361  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
362  return null;
363  }
364 
365  /************************************************************************************//**
366  * \brief We don't do admin in this variant, so this makes that clear. *
367  * *
368  * \returns null *
369  ****************************************************************************************/
370  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
371  protected function get_admin_form_uri()
372  {
373  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
374  return null;
375  }
376 
377  /************************************************************************************//**
378  * \brief You cannot set options in this implementation. *
379  * *
380  * \returns false *
381  ****************************************************************************************/
382  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
383  protected function cms_set_option(
384  $in_option_key, ///< The name of the option
385  $in_option_value ///< the values to be set (associative array)
386  ) {
387  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
388  return false;
389  }
390 
391  /************************************************************************************//**
392  * \brief You cannot delete options in this implementation. *
393  * *
394  * \returns false *
395  ****************************************************************************************/
396  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
397  protected function cms_delete_option($in_option_key)
398  {
399  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
400  return false;
401  }
402 
403  /************************************************************************************//**
404  * \brief This is declared to make it clear that we don't do post meta. *
405  * *
406  * \returns null *
407  ****************************************************************************************/
408  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
409  protected function cms_get_post_meta(
410  $in_page_id, ///< The ID of the page/post
411  $in_settings_id ///< The ID of the meta tag to fetch
412  ) {
413  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
414  return null;
415  }
416 
417  /************************************************************************************//**
418  * \brief No admin in this implementation. *
419  * *
420  * \returns null *
421  ****************************************************************************************/
422  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
423  public function admin_head()
424  {
425  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
426  return null;
427  }
428 
429  /************************************************************************************//**
430  * \brief Prevents the admin page from being shown. *
431  ****************************************************************************************/
432  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
433  public function admin_page()
434  {
435  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
436  }
437 }
438 
439 /****************************************************************************************//**
440 * MAIN EXECUTION *
441 ********************************************************************************************/
442 
443 static $basic_bmlt_object;
444 
445 if (!isset($basic_bmlt_object) && class_exists("bmlt_basic")) {
446  $basic_bmlt_object = new bmlt_basic();
447 }
448 
449 if ($basic_bmlt_object) {
450  $basic_bmlt_object->ajax_router();
451 } else {
452  echo 'UNABLE TO INITIALIZE THE BMLT SUBSYSTEM';
453 }
454 
455 ob_end_flush();
get_ajax_base_uri()
Return an HTTP path to the AJAX callback target. * *.
$my_shortcode
This will hold the given shortcode.
output_head($in_shortcode='[[bmlt]]')
Outputs the head HTML, CSS and JavaScript. *.
get_plugin_path()
Return an HTTP path to the plugin directory. * *.
cms_get_post_meta( $in_page_id, $in_settings_id)
This is declared to make it clear that we don't do post meta. * *.
cms_set_option( $in_option_key, $in_option_value)
You cannot set options in this implementation. * *.
cms_get_option($in_option_key)
This gets the admin options from the config file. * *.
admin_head()
No admin in this implementation. * *.
cms_delete_option($in_option_key)
You cannot delete options in this implementation. * *.
process_text($in_string)
This uses the CMS text processor (t) to process the given string. *This allows easier translation of ...
admin_page()
Prevents the admin page from being shown. *.
get_admin_form_uri()
We don't do admin in this variant, so this makes that clear. * *.
get_admin_ajax_base_uri()
We don't do admin in this variant, so this makes that clear. * *.
output_body()
Outputs the body HTML and JavaScript. *.
geDefaultBMLTOptions()
This gets the default admin options from the object (not the DB). * *.
cms_get_page_settings_id( $in_text, $in_check_mobile=false)
This function fetches the settings ID for a page (if there is one). *If $in_check_mobile is set to tr...
standard_head($in_text=null)
returns any necessary head content. *
global $bmlt_basic_configuration
These are used by the bmlt_basic class. Don't mess with them.