BMLT Root Server
index.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************************/
3 /** \file client_interface/simple/index.php
4 
5  \brief This file is a very simple interface that is designed to return
6  a basic XHTML string, in response to a search.
7  In order to use this, you need to call: <ROOT SERVER BASE URI>/client_interface/simple/
8  with the same parameters that you would send to an advanced search. The results
9  will be returned as XHTML data.
10 
11  This file can be called from other servers.
12 
13  This file is part of the Basic Meeting List Toolbox (BMLT).
14 
15  Find out more at: https://bmlt.app
16 
17  BMLT is free software: you can redistribute it and/or modify
18  it under the terms of the MIT License.
19 
20  BMLT is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  MIT License for more details.
24 
25  You should have received a copy of the MIT License along with this code.
26  If not, see <https://opensource.org/licenses/MIT>.
27 */
28 defined('BMLT_EXEC') or define('BMLT_EXEC', true); // This is a security verifier. Keeps files from being executed outside of the context
29 require_once(dirname(__FILE__).'/../../server/shared/classes/comdef_utilityclasses.inc.php');
30 require_once(dirname(__FILE__).'/../csv/csv.php');
31 
32 $server = c_comdef_server::MakeServer();
33 $ret = null;
34 
35 if ($server instanceof c_comdef_server) {
36  /*******************************************************************/
37  /**
38  \brief Queries the local server, and returns processes XHTML.
39 
40  This requires that the "switcher=" parameter be set in the GET or
41  POST parameters:
42  - 'GetSearchResults'
43  This returns the search results.
44 
45  \returns CSV data, with the first row a key header.
46  */
47  function parse_redirect_simple(
48  &$server ///< A reference to an instance of c_comdef_server
49  ) {
50  $result = null;
51  $http_vars = array_merge_recursive($_GET, $_POST);
52 
53  if (!isset($http_vars['lang_enum']) || !$http_vars['lang_enum']) {
54  $http_vars['lang_enum'] = $server->GetLocalLang();
55  }
56 
57  // Just to be safe, we override any root passed in. We know where our root is, and we don't need to be told.
58  $http_vars['bmlt_root'] = 'http://'.$_SERVER['SERVER_NAME'].(($_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').dirname($_SERVER['SCRIPT_NAME'])."/../../";
59 
60  switch ($http_vars['switcher']) {
61  case 'GetSearchResults':
62  $container = (isset($http_vars['container_id']) && $http_vars['container_id']) ? $http_vars['container_id'] : null;
63  $result = GetSimpleSearchResults($http_vars, isset($http_vars['block_mode']), $container);
64  break;
65 
66  case 'GetFormats':
67  $lang = null;
68 
69  if (isset($http_vars['lang_enum'])) {
70  $lang = $http_vars['lang_enum'];
71  }
72 
73  unset($http_vars['lang_enum']);
74  unset($http_vars['switcher']);
75  $container = (isset($http_vars['container_id']) && $http_vars['container_id']) ? $http_vars['container_id'] : null;
76  $result = GetSimpleFormats($server, isset($http_vars['block_mode']), $container, $lang, $http_vars);
77  break;
78 
79  default:
80  $result = HandleSimpleDefault($http_vars);
81  break;
82  }
83 
84  return $result;
85  }
86 
87  /*******************************************************************/
88  /**
89  \brief This returns the search results, in whatever form was requested.
90 
91  \returns XHTML data. It will either be a table, or block elements.
92  */
93  function GetSimpleSearchResults(
94  $in_http_vars, ///< The HTTP GET and POST parameters.
95  $in_block = false, ///< If this is true, the results will be sent back as block elements (div tags), as opposed to a table. Default is false.
96  $in_container_id = null ///< This is an optional ID for the "wrapper."
97  ) {
98  $localized_strings = c_comdef_server::GetLocalStrings();
99  $original_weekday = -1;
100  $current_weekday = -1;
101 
102  if (!( isset($in_http_vars['geo_width']) && $in_http_vars['geo_width'] ) && isset($in_http_vars['bmlt_search_type']) && ($in_http_vars['bmlt_search_type'] == 'advanced') && isset($in_http_vars['advanced_radius']) && isset($in_http_vars['advanced_mapmode']) && $in_http_vars['advanced_mapmode'] && ( floatval($in_http_vars['advanced_radius'] != 0.0) ) && isset($in_http_vars['lat_val']) && isset($in_http_vars['long_val']) && ( (floatval($in_http_vars['lat_val']) != 0.0) || (floatval($in_http_vars['long_val']) != 0.0) )) {
103  $in_http_vars['geo_width'] = $in_http_vars['advanced_radius'];
104  } elseif (!( isset($in_http_vars['geo_width']) && $in_http_vars['geo_width'] ) && isset($in_http_vars['bmlt_search_type']) && ($in_http_vars['bmlt_search_type'] == 'advanced')) {
105  $in_http_vars['lat_val'] = null;
106  $in_http_vars['long_val'] = null;
107  } elseif (!isset($in_http_vars['geo_loc']) || $in_http_vars['geo_loc'] != 'yes') {
108  if (!isset($in_http_vars['geo_width'])) {
109  $in_http_vars['geo_width'] = 0;
110  }
111  }
112 
113  if (!(isset($in_http_vars['sort_key']) && $in_http_vars['sort_key']) && !(isset($in_http_vars['sort_keys']) && $in_http_vars['sort_keys'])) {
114  $in_http_vars['sort_key'] = 'time';
115  }
116 
117  require_once(dirname(__FILE__).'/../csv/search_results_csv.php');
118  $results = DisplaySearchResultsCSV($in_http_vars);
119 
120  $ret = '';
121 
122  // What we do, is to parse the CSV return. We'll pick out certain fields, and format these into a table or block element return.
123  if ($results) {
124  if (isset($in_http_vars['single_uri']) && $in_http_vars['single_uri']) {
125  $single_uri = $in_http_vars['single_uri'];
126  }
127 
128  // Start by turning the CSV into an array of meeting lines.
129  $results = explode("\n", $results);
130 
131  if (is_array($results) && count($results)) {
132  $ret = $in_block ? '<div class="bmlt_simple_meetings_div"'.($in_container_id ? ' id="'.c_comdef_htmlspecialchars($in_container_id).'"' : '').'>' : '<table class="bmlt_simple_meetings_table"'.($in_container_id ? ' id="'.c_comdef_htmlspecialchars($in_container_id).'"' : '').' cellpadding="0" cellspacing="0" summary="Meetings">';
133  $keys = preg_replace('|^"|', '', preg_replace('|"$|', '', explode('","', $results[0])));
134  $weekday_div = false;
135 
136  $alt = 1; // This is used to provide an alternating class.
137  // We skip the first line, because that is the field header.
138  for ($count = 1; $count < count($results); $count++) {
139  $meeting = $results[$count];
140 
141  if ($meeting) {
142  if ($alt == 1) {
143  $alt = 0;
144  } else {
145  $alt = 1;
146  }
147 
148  $meeting = preg_replace('|^"|', '', preg_replace('|"$|', '', explode('","', $meeting)));
149  if (is_array($meeting) && count($meeting)) {
150  if (count($meeting) > count($keys)) {
151  $keys[] = 'unused';
152  }
153 
154  // This is for convenience. We turn the meeting array into an associative one by adding the keys.
155  $meeting = array_combine($keys, $meeting);
156  $location_borough = c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_city_subsection'])));
157  $location_neighborhood = c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_neighborhood'])));
158  $location_province = c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_province'])));
159  $location_nation = c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_nation'])));
160  $location_postal_code_1 = c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_postal_code_1'])));
161  $location_municipality = c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_municipality'])));
162  $town = '';
163 
164  if ($location_municipality) {
165  if ($location_borough) {
166  // We do it this verbose way, so we will scrag the comma if we want to hide the town.
167  $town = "<span class=\"c_comdef_search_results_borough\">$location_borough</span><span class=\"bmlt_separator bmlt_separator_comma c_comdef_search_results_municipality_separator\">, </span><span class=\"c_comdef_search_results_municipality\">$location_municipality</span>";
168  } else {
169  $town = "<span class=\"c_comdef_search_results_municipality\">$location_municipality</span>";
170  }
171  } elseif ($location_borough) {
172  $town = "<span class=\"c_comdef_search_results_municipality_borough\">$location_borough</span>";
173  }
174 
175  if ($location_province) {
176  if ($town) {
177  $town .= '<span class="bmlt_separator bmlt_separator_comma c_comdef_search_results_province_separator">, </span>';
178  }
179 
180  $town .= "<span class=\"c_comdef_search_results_province\">$location_province</span>";
181  }
182 
183  if ($location_postal_code_1) {
184  if ($town) {
185  $town .= '<span class="bmlt_separator bmlt_separator_comma c_comdef_search_results_zip_separator">, </span>';
186  }
187 
188  $town .= "<span class=\"c_comdef_search_results_zip\">$location_postal_code_1</span>";
189  }
190 
191  if ($location_nation) {
192  if ($town) {
193  $town .= '<span class="bmlt_separator bmlt_separator_comma c_comdef_search_results_nation_separator">, </span>';
194  }
195 
196  $town .= "<span class=\"c_comdef_search_results_nation\">$location_nation</span>";
197  }
198 
199  if ($location_neighborhood) {
200  $town_temp = '';
201 
202  if ($town) {
203  $town_temp = '<span class="bmlt_separator bmlt_separator_paren bmlt_separator_open_paren bmlt_separator_neighborhood_open_paren"> (</span>';
204  }
205 
206  $town_temp .= "<span class=\"c_comdef_search_results_neighborhood\">$location_neighborhood</span>";
207 
208  if ($town) {
209  $town_temp .= '<span class="bmlt_separator bmlt_separator_paren bmlt_separator_close_paren bmlt_separator_neighborhood_close_paren">)</span>';
210  }
211 
212  $town .= $town_temp;
213  }
214 
215  $weekday = c_comdef_htmlspecialchars($localized_strings['weekdays'][intval($meeting['weekday_tinyint'])]);
216  $time = BuildMeetingTime($meeting['start_time']);
217 
218  $address = '';
219  $location_text = c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_text'])));
220  $street = c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_street'])));
221  $info = c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_info'])));
222 
223  if ($location_text) {
224  $address = "<span class=\"bmlt_simple_list_location_text\">$location_text</span>";
225  }
226 
227  if ($street) {
228  if ($address) {
229  $address .= '<span class="bmlt_separator bmlt_separator_comma bmlt_simple_list_location_street_separator">, </span>';
230  }
231 
232  $address .= "<span class=\"bmlt_simple_list_location_street\">$street</span>";
233  }
234 
235  if ($info) {
236  if ($address) {
237  $address .= '<span class="bmlt_separator bmlt_separator_space bmlt_simple_list_location_info_separator"> </span>';
238  }
239 
240  $address .= "<span class=\"bmlt_simple_list_location_info\">($info)</span>";
241  }
242 
243  $name = c_comdef_htmlspecialchars(trim(stripslashes($meeting['meeting_name'])));
244  $format = c_comdef_htmlspecialchars(trim(stripslashes($meeting['formats'])));
245 
246  $name_uri = urlencode(htmlspecialchars_decode($name));
247 
248  $map_uri = str_replace("##LONG##", c_comdef_htmlspecialchars($meeting['longitude']), str_replace("##LAT##", c_comdef_htmlspecialchars($meeting['latitude']), str_replace("##NAME##", $name_uri, $localized_strings['comdef_server_admin_strings']['MapsURL'])));
249 
250  if ($time && $weekday && $address) {
251  $meeting_weekday = $meeting['weekday_tinyint'];
252 
253  if (7 < $meeting_weekday) {
254  $meeting_weekday = 1;
255  }
256 
257  if (($current_weekday != $meeting_weekday) && $in_block) {
258  if ($current_weekday != -1) {
259  $weekday_div = false;
260  $ret .= '</div>';
261  }
262 
263  $current_weekday = $meeting_weekday;
264 
265  $ret .= '<div class="bmlt_simple_meeting_weekday_div_'.$current_weekday.'">';
266  $weekday_div = true;
267  if (isset($in_http_vars['weekday_header']) && $in_http_vars['weekday_header']) {
268  $ret .= '<div id="weekday-start-'.$current_weekday.'" class="weekday-header weekday-index-'.$current_weekday.'">'.htmlspecialchars($weekday).'</div>';
269  }
270  }
271 
272  $ret .= $in_block ? '<div class="bmlt_simple_meeting_one_meeting_div bmlt_alt_'.intval($alt).'">' : '<tr class="bmlt_simple_meeting_one_meeting_tr bmlt_alt_'.intval($alt).'">';
273  $ret .= $in_block ? '<div class="bmlt_simple_meeting_one_meeting_town_div">' : '<td class="bmlt_simple_meeting_one_meeting_town_td">';
274  $ret .= $town;
275  $ret .= $in_block ? '</div>' : '</td>';
276  $ret .= $in_block ? '<div class="bmlt_simple_meeting_one_meeting_name_div">' : '<td class="bmlt_simple_meeting_one_meeting_name_td">';
277 
278  if (isset($single_uri) && $single_uri) {
279  $ret .= '<a href="'.htmlspecialchars($single_uri).intval($meeting['id_bigint']).'">';
280  }
281 
282  if ($name) {
283  $ret .= $name;
284  } else {
285  $ret .= $localized_strings['comdef_server_admin_strings']['Value_Prompts']['generic'];
286  }
287 
288  if (isset($single_uri) && $single_uri) {
289  $ret .= '</a>';
290  }
291 
292  $ret .= $in_block ? '</div>' : '</td>';
293 
294  $ret .= $in_block ? '<div class="bmlt_simple_meeting_one_meeting_time_div">' : '<td class="bmlt_simple_meeting_one_meeting_time_td">';
295  $ret .= $time;
296  $ret .= $in_block ? '</div>' : '</td>';
297 
298  $ret .= $in_block ? '<div class="bmlt_simple_meeting_one_meeting_weekday_div">' : '<td class="bmlt_simple_meeting_one_meeting_weekday_td">';
299  $ret .= $weekday;
300  $ret .= $in_block ? '</div>' : '</td>';
301 
302  $ret .= $in_block ? '<div class="bmlt_simple_meeting_one_meeting_address_div">' : '<td class="bmlt_simple_meeting_one_meeting_address_td">';
303  $ret .= '<a href="'.$map_uri.'">'.$address.'</a>';
304  $ret .= $in_block ? '</div>' : '</td>';
305 
306  $ret .= $in_block ? '<div class="bmlt_simple_meeting_one_meeting_format_div">' : '<td class="bmlt_simple_meeting_one_meeting_format_td">';
307  $ret .= $format;
308  $ret .= $in_block ? '</div>' : '</td>';
309 
310  $ret .= $in_block ? '<div class="bmlt_clear_div"></div></div>' : '</tr>';
311  }
312  }
313  }
314  }
315 
316  if ($weekday_div && $in_block) {
317  $ret .= '</div>';
318  }
319 
320  $ret .= $in_block ? '</div>' : '</table>';
321  }
322  }
323 
324  return $ret;
325  }
326 
327  /*******************************************************************/
328  /** \brief This creates a time string to be displayed for the meeting.
329  The display is done in non-military time, and "midnight" and
330  "noon" are substituted for 12:59:00, 00:00:00 and 12:00:00
331 
332  \returns a string, containing the HTML rendered by the function.
333  */
334  function BuildMeetingTime( $in_time ///< A string. The value of the time field.
335  )
336  {
337  $localized_strings = c_comdef_server::GetLocalStrings();
338 
339  $time = null;
340 
341  if (($in_time == "00:00:00") || ($in_time >= "23:55:00")) {
342  $time = c_comdef_htmlspecialchars($localized_strings['comdef_server_admin_strings']['meeting_editor_screen_meeting_midnight_label']);
343  } elseif ($in_time == "12:00:00") {
344  $time = c_comdef_htmlspecialchars($localized_strings['comdef_server_admin_strings']['meeting_editor_screen_meeting_noon_label']);
345  } else {
346  include(dirname(__FILE__).'/../../server/config/get-config.php');
347 
348  $time = c_comdef_htmlspecialchars(date($time_format, strtotime($in_time)));
349  }
350 
351  return $time;
352  }
353 
354  /*******************************************************************/
355  /**
356  \brief This returns the complete formats table.
357 
358  \returns XHTML data, with the first row a key header.
359  */
360  function GetSimpleFormats(
361  &$server, ///< A reference to an instance of c_comdef_server
362  $in_block = false, ///< If this is true, the results will be sent back as block elements (div tags), as opposed to a table. Default is false.
363  $in_container_id = null, ///< This is an optional ID for the "wrapper."
364  $in_lang = null, ///< The language of the formats to be returned. Default is null (server language). Can be an array.
365  $in_search_params = null ///< If this is supplied, then it is a search parameter list. The idea is that only the formats used in the returned meetings will be displayed.
366  ) {
367  $my_keys = array ( 'key_string',
368  'name_string',
369  'description_string'
370  );
371 
372  $ret = $in_block ? '<div class="bmlt_simple_format_div"'.($in_container_id ? ' id="'.c_comdef_htmlspecialchars($in_container_id).'"' : '').'>' : '<table class="bmlt_simple_format_table"'.($in_container_id ? ' id="'.c_comdef_htmlspecialchars($in_container_id).'"' : '').' cellpadding="0" cellspacing="0" summary="Format Codes">';
373  $formats_ar = array();
374 
375  if (isset($in_search_params) && is_array($in_search_params) && count($in_search_params)) {
376  require_once(dirname(__FILE__).'/../csv/search_results_csv.php');
377  $results = GetSearchResults($in_search_params, $formats_ar);
378  }
379 
380  $formats_obj = $server->GetFormatsObj();
381  if ($formats_obj instanceof c_comdef_formats) {
382  $langs = $server->GetServerLangs();
383 
384  if (is_array($in_lang) && count($in_lang)) {
385  $langs2 = array();
386  foreach ($in_lang as $key) {
387  if (array_key_exists($key, $langs)) {
388  $langs2[$key] = $langs[$key];
389  }
390  }
391 
392  $langs = $langs2;
393  } elseif (array_key_exists($in_lang, $langs)) {
394  $langs = array ( $in_lang => $langs[$in_lang] );
395  }
396 
397  foreach ($langs as $key => $value) {
398  $format_array = $formats_obj->GetFormatsByLanguage($key);
399 
400  if (is_array($format_array) && count($format_array)) {
401  usort($format_array, function ($a, $b) {
402  return strnatcasecmp($a->GetKey(), $b->GetKey());
403  });
404 
405  $alt = 1; // This is used to provide an alternating style.
406  foreach ($format_array as $format) {
407  $has = false;
408  if ($format instanceof c_comdef_format) {
409  if (($formats_ar != null)) {
410  foreach ($formats_ar as $format_obj) {
411  if ($format->GetSharedID() && ($format_obj->GetSharedID() == $format->GetSharedID())) {
412  $has = true;
413  break;
414  }
415  }
416  }
417 
418  if ($has) {
419  if ($alt == 1) {
420  $alt = 0;
421  } else {
422  $alt = 1;
423  }
424 
425  $ret .= $in_block ? '<div class="bmlt_simple_format_one_format_div bmlt_alt_'.intval($alt).'">' : '<tr class="bmlt_simple_format_one_format_tr bmlt_alt_'.intval($alt).'">';
426  foreach ($my_keys as $ky) {
427  $ret .= ($in_block ? '<div' : '<td').' class="';
428 
429  $val = '';
430 
431  switch ($ky) {
432  case 'key_string':
433  $ret .= 'bmlt_simple_format_one_format_key';
434  $val = $format->GetKey();
435  break;
436 
437  case 'name_string':
438  $ret .= 'bmlt_simple_format_one_format_name';
439  $val = $format->GetLocalName();
440  break;
441 
442  case 'description_string':
443  $ret .= 'bmlt_simple_format_one_format_description';
444  $val = $format->GetLocalDescription();
445  break;
446 
447  default:
448  $ret .= 'bmlt_simple_format_one_format_unknown';
449  break;
450  }
451 
452  $ret .= $in_block ? '_div">' : '_td">';
453  $ret .= c_comdef_htmlspecialchars(trim($val));
454  $ret .= $in_block ? '</div>' : '</td>';
455  }
456  $ret .= $in_block ? '<div class="bmlt_clear_div"></div></div>' : '</tr>';
457  }
458  }
459  }
460  }
461  }
462  }
463 
464  $ret .= $in_block ? '</div>' : '</table>';
465 
466  return $ret;
467  }
468 
469  /*******************************************************************/
470  /**
471  \brief Handles no command supplied (error)
472 
473  \returns English error string (not XML).
474  */
475  function HandleSimpleDefault(
476  $in_http_vars ///< The HTTP GET and POST parameters.
477  ) {
478  return "You must supply either 'switcher=GetSearchResults' or 'switcher=GetFormats'";
479  }
480 
481  $ret = parse_redirect_simple($server);
482 } else {
483  $ret = HandleNoServer();
484 }
485 
486 $handler = 'ob_gzhandler';
487 
488 // Server-side includes (and some other implementations) can't handle compressed data in the response. If "nocompress" is specified, then the GZIP handler isn't used.
489 if (isset($_GET['nocompress']) || isset($_POST['nocompress'])) {
490  $handler = null;
491 }
492 
493 ob_start($handler);
494  $ret = preg_replace('/<!--(.|\s)*?-->/', '', $ret);
495  $ret = preg_replace('/\/\*(.|\s)*?\*\//', '', $ret);
496  $ret = preg_replace("|\s+\/\/.*|", " ", $ret);
497  $ret = preg_replace("/\s+/", " ", $ret);
498  echo $ret;
499 ob_end_flush();
static GetLocalStrings($in_lang_enum=null)
This gets the appropriate language files, and puts all the the strings into an associative array...
if($handler instanceof c_comdef_admin_ajax_handler)
$handler
Definition: index.php:486
const BMLT_EXEC
Definition: index.php:21
function htmlspecialchars_decode(string, quote_style)
$ret
Definition: index.php:33
A Class for Format Codes.
Include the format class.
global $http_vars
Definition: index.php:21
GetSearchResults($in_http_vars, &$formats_ar=null, &$meanLocationData=null)
This returns the search results, in whatever form was requested.
Definition: csv.php:752
c_comdef_htmlspecialchars($in_string)
This function creates a displayable string.
DisplaySearchResultsCSV($in_http_vars, &$return_array=null, &$return_geocode=null, &$return_results=null, $in_supress_hidden_concat=false, $in_editor_only=false)
This function does a search, then builds a CSV result, with each row being a meeting. The first row is a row of keys.
This class is the main server class. It instantiates a PDO database object, and is the starting point...
defined('BMLT_EXEC') or define('BMLT_EXEC'
Definition: index.php:3
defined('BMLT_EXEC') or define('BMLT_EXEC' true
Definition: index.php:29
$server
Definition: index.php:32
HandleNoServer()
Handles no server available (error).
Definition: csv.php:1483
$_GET['switcher']