YaWK  24.1
Yet another WebKit
sys.php
Go to the documentation of this file.
1 <?php
2 namespace YAWK {
3  /**
4  * @details handles many of yawk's system core functions.
5  *
6  * Most of them are static functions, like get and set paths, get ids, roles and so on.
7  * <p><i>Class covers both, backend & frontend functionality.
8  * See Methods Summary for Details!</i></p>
9  *
10  * @author Daniel Retzl <[email protected]>
11  * @copyright 2009-2016 Daniel Retzl
12  * @license https://opensource.org/licenses/MIT
13  * @version 1.0.0
14  * @brief The sys class - handles yawk's system core functions.
15  */
16  class sys
17  {
18  /**
19  * @brief Check if assets are loaded, load if switch is true
20  * @param $db object Database object
21  * @param $assets array Required assets as array
22  * @param $switch bool true|false If true, required assset gets loaded if not
23  * @return mixed
24  * @details This methods checks if given assets are loaded and load them on demand
25  */
26  static function checkIfAssetsAreLoaded($db, $assets, $switch)
27  {
28  // check if any assets are sent
29  if (isset($assets) && (!empty($assets) && (is_array($assets))))
30  {
31  // get current template ID
33 
34  // get the number of assets
35  $assetItems = count($assets);
36 
37  // loop counter
38  $successful = 0;
39 
40  // check if templateID is valid
41  if (!isset($templateID) || (empty($templateID) || (!is_numeric($templateID))))
42  { // unable to get current template ID
43  return false;
44  }
45  else // valid template ID, go ahead and...
46  { // walk through required assets array
47  foreach ($assets as $asset => $type)
48  {
49  // check if asset is loaded
50  if ($res = $db->query(("SELECT asset FROM {assets}
51  WHERE asset = '" . $asset . "'
52  AND templateID = '".$templateID."'")))
53  {
54  if ($row = (mysqli_fetch_row($res)))
55  {
56  if (count($row) > 0)
57  {
58  // asset found, set loop counter +1
59  $successful++;
60  }
61  }
62  else // asset not found
63  { // check if switch is true and asset should be loaded...
64  if (isset($switch) && ($switch == 'true'))
65  { // select data from asset types db
66  if ($res = $db->query("SELECT * FROM {assets_types} WHERE asset = '".$asset."'"))
67  { // foreach result
68  while ($row = (mysqli_fetch_assoc($res)))
69  {
70  // check link (internal or external)
71  if (isset($row['internal']) && (!empty($row['internal'])))
72  { // internal link
73  $row['link'] = $row['internal'];
74  }
75  elseif (isset($row['url1']) && (!empty($row['url1'])))
76  { // external link
77  $row['link'] = $row['url1'];
78  }
79 
80  // load required asset into database
81  if ($db->query("INSERT INTO {assets} (templateID, type, sortation, asset, link) VALUES ('" . $templateID . "', '" . $type . "', '" . $row['sortation']. "','" . $row['asset'] . "', '" . $row['link'] . "')"))
82  { // asset successfully loaded
83  $successful++;
84  }
85  else
86  { // no success - do nothing
87  return \YAWK\alert::draw("danger", "ERROR", "Unable to insert Asset into Assets database. Please add this asset $asset manually.", "", 12000);
88  }
89  }
90  }
91  else
92  {
93  // required asset not found in database - add manually!
94  // die ('required asset is not in database - add manually!');
95  return \YAWK\alert::draw("danger", "ERROR", "Required Asset is not in the database! Please check, if this asset is registered!", "", 12000);
96  }
97  // select data of this asset
98  }
99  else
100  { // switch is false, means enable asset is not requested
101  return \YAWK\alert::draw("warning", "Warning - please check this!", "Unable to load asset! $asset Please check required template assets manually!", "", 12000);
102  }
103  }
104  }
105  else
106  { // error selecting asset from database
107  return \YAWK\alert::draw("warning", "Warning - this widget requires an additional asset!", "Asset $asset not loaded! Please load this asset within system/asset settings.", "", 12000);
108  }
109  }
110 
111  // check if count and assetItems match to see if everything worked like expected
112  if ($assetItems === $successful)
113  { // all assets loaded
114  // die ('Required assset was not loaded');
115  return \YAWK\alert::draw("success", "Asset System Information", "I have found out that the required asset was not loaded. I've successfully fixed this for you.", "", 6200);
116  }
117  else
118  { // not all asset items could get loaded...
119  // die ('Unable to load all assets');
120  return \YAWK\alert::draw("warning", "Warning - please check this!", "Unable to load asset! $asset Please check required template assets manually!", "", 12000);
121  }
122  }
123  }
124  else
125  { // no assets are set
126  return false;
127  }
128  }
129 
130  /**
131  * @brief Display a multidimensional array line per line. Expects an array and property
132  * @author Daniel Retzl <[email protected]>
133  * @version 1.0.0
134  */
135  static function array2lines($array, $property)
136  {
137  if (!isset($array) || (!isset($property)))
138  {
139  echo 'array or property not set';
140  }
141 
142  if (isset($array) && (isset($array[$property]) && (isset($property))))
143  {
144  echo "<h2 class=\"myClass\">$property</h2>";
145  foreach ($array[$property] as $item => $key)
146  {
147  $linkProperty = str_replace(" ", "+", $item);
148  if (is_array($key))
149  {
150  echo "<li class=\"list-group-item\"><a href=\"https://www.google.at/search?q=php.net+$linkProperty\" title=\"google this: $item setting\" target=\"_blank\"><b>$item</b> = $key[0]</a></li>";
151  }
152  else
153  {
154  echo "<li class=\"list-group-item\"><a href=\"https://www.google.at/search?q=php.net+$linkProperty\" title=\"google this: $item setting\" target=\"_blank\"><b>$item</b> = $key</a></li>";
155  }
156  }
157  }
158  }
159 
160  /**
161  * @brief Display a complete PHPinfo()
162  * @param $lang
163  */
164  static function drawPhpInfo($lang)
165  {
166  // get data from php info into array
168 
169  // JS filter script
170  echo "
171  <script>
172  function myFunction() {
173  // Declare variables
174  var input, filter, ul, li, a, i;
175  input = document.getElementById('myInput');
176  filter = input.value.toUpperCase();
177  ul = document.getElementById(\"phpinfoList\");
178  li = ul.getElementsByTagName('li');
179 
180  // Loop through all list items, hide those who don't match the search query
181  for (i = 0; i < li.length; i++) {
182  a = li[i].getElementsByTagName(\"a\")[0];
183  if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
184  li[i].style.display = \"\";
185  $('.myClass').show();
186  } else {
187  li[i].style.display = \"none\";
188  $('.myClass').hide();
189 
190  }
191  }
192  }
193  </script>";
194 
195  echo "<input type=\"text\" id=\"myInput\" class=\"form-control\" onkeyup=\"myFunction()\" placeholder=\"$lang[SEARCH_DOTDOTDOT]\">";
196  echo "<ul id=\"phpinfoList\" class=\"list-group\">";
197  \YAWK\sys::array2lines($data, "apache2handler");
198  \YAWK\sys::array2lines($data, "Apache Environment");
199  \YAWK\sys::array2lines($data, "HTTP Headers Information");
200  \YAWK\sys::array2lines($data, "bcmath");
202  \YAWK\sys::array2lines($data, "calendar");
203  \YAWK\sys::array2lines($data, "Core");
204  \YAWK\sys::array2lines($data, "ctype");
205  \YAWK\sys::array2lines($data, "curl");
206  \YAWK\sys::array2lines($data, "date");
208  \YAWK\sys::array2lines($data, "ereg");
209  \YAWK\sys::array2lines($data, "exif");
210  \YAWK\sys::array2lines($data, "fileinfo");
211  \YAWK\sys::array2lines($data, "filter");
214  \YAWK\sys::array2lines($data, "gettext");
215  \YAWK\sys::array2lines($data, "hash");
216  \YAWK\sys::array2lines($data, "iconv");
217  \YAWK\sys::array2lines($data, "imagick");
218  \YAWK\sys::array2lines($data, "json");
219  \YAWK\sys::array2lines($data, "libxml");
220  \YAWK\sys::array2lines($data, "mbstring");
221  \YAWK\sys::array2lines($data, "mcrypt");
222  \YAWK\sys::array2lines($data, "mhash");
223  \YAWK\sys::array2lines($data, "mysqli");
224  \YAWK\sys::array2lines($data, "mysqlnd");
225  \YAWK\sys::array2lines($data, "odbc");
226  \YAWK\sys::array2lines($data, "openssl");
227  \YAWK\sys::array2lines($data, "pcre");
229  \YAWK\sys::array2lines($data, "pdo_mysql");
230  \YAWK\sys::array2lines($data, "pdo_sqlite");
231  \YAWK\sys::array2lines($data, "Phar");
232  \YAWK\sys::array2lines($data, "Reflection");
233  \YAWK\sys::array2lines($data, "session");
234  \YAWK\sys::array2lines($data, "SimpleXML");
236  \YAWK\sys::array2lines($data, "standard");
237  \YAWK\sys::array2lines($data, "tokenizer");
238  \YAWK\sys::array2lines($data, "wddx");
240  \YAWK\sys::array2lines($data, "xmlreader");
241  \YAWK\sys::array2lines($data, "xmlwriter");
243  \YAWK\sys::array2lines($data, "zlib");
244  echo "</ul>";
245  /*
246  echo "</tbody></table>";
247  */
248  }
249 
250  /**
251  * @brief Display a multidimensional array line per line. Expects an array and property
252  * @author Daniel Retzl <[email protected]>
253  * @version 1.0.0
254  * @link https://gist.github.com/sbmzhcn/6255314
255  * @return bool
256  */
257  static function multiarray2lines($array, $property)
258  {
259  echo "<h2><small>".strtoupper($property)."</small></h2>";
260  foreach ($array[$property] as $item => $key)
261  {
262  echo "<b>$item</b> = $key[0]<br>";
263  }
264  return true;
265  }
266 
267  /**
268  * @brief Read phpinfo() into multidimensional array and return it
269  * @author Ray Chang
270  * @version 1.0.0
271  * @link https://gist.github.com/sbmzhcn/6255314
272  * @return array phpinfo() data as multidimensional array
273  */
274  public static function parse_phpinfo() {
275  ob_start(); phpinfo(INFO_MODULES); $s = ob_get_contents(); ob_end_clean();
276  $s = strip_tags($s, '<h2><th><td>');
277  $s = preg_replace('/<th[^>]*>([^<]+)<\/th>/', '<info>\1</info>', $s);
278  $s = preg_replace('/<td[^>]*>([^<]+)<\/td>/', '<info>\1</info>', $s);
279  $t = preg_split('/(<h2[^>]*>[^<]+<\/h2>)/', $s, -1, PREG_SPLIT_DELIM_CAPTURE);
280  $r = array(); $count = count($t);
281  $p1 = '<info>([^<]+)<\/info>';
282  $p2 = '/'.$p1.'\s*'.$p1.'\s*'.$p1.'/';
283  $p3 = '/'.$p1.'\s*'.$p1.'/';
284  for ($i = 1; $i < $count; $i++) {
285  if (preg_match('/<h2[^>]*>([^<]+)<\/h2>/', $t[$i], $matchs)) {
286  $name = trim($matchs[1]);
287  $vals = explode("\n", $t[$i + 1]);
288  foreach ($vals AS $val) {
289  if (preg_match($p2, $val, $matchs)) { // 3cols
290  $r[$name][trim($matchs[1])] = array(trim($matchs[2]), trim($matchs[3]));
291  } elseif (preg_match($p3, $val, $matchs)) { // 2cols
292  $r[$name][trim($matchs[1])] = trim($matchs[2]);
293  }
294  }
295  }
296  }
297  return $r;
298  }
299 
300  /**
301  * @brief Return current base directory
302  * @return string
303  */
304  public static function getBaseDir()
305  {
306  return substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'],basename($_SERVER['SCRIPT_NAME'])));
307  }
308 
309  /**
310  * @brief Generate a random password with given length
311  * @param int $length length of the password you wish to return
312  * @return string
313  */
314  public static function generateRandomPassword($length)
315  {
316  // if length is not set or wrong type
317  if (!isset($length) || (empty($length) || (!is_int($length))))
318  { // generate password with default length (8 chars)
319  $length = 8;
320  }
321  // string with allowed chars - these can appear in the generated password
322  $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?";
323  // generate password
324  $password = substr(str_shuffle($chars), 0, $length);
325  return $password;
326  }
327 
328 
329  /**
330  * @brief Return the content of /robots.txt
331  * @param string $path absolute path to the robots.txt file
332  * @return string|bool
333  */
334  public static function getRobotsText($db, $path)
335  {
336  $robotsText = "$path/robots.txt";
337  $file = file_get_contents($robotsText);
338  if (!empty($file))
339  {
340  return $file;
341  }
342  else
343  { // try to get robots.txt from database
344  if ($file = \YAWK\settings::getLongSetting($db, "robotsText-long"))
345  {
346  return $file;
347  }
348  else
349  { // db setting robotsText-long is empty
350  return false;
351  }
352  }
353  }
354 
355  /**
356  * @brief Set the content of /robots.txt (overwrite)
357  * @param string $path absolute path to the robots.txt file
358  * @param string $content file content to write in robots.txt
359  * @return bool
360  */
361  public static function setRobotsText($path, $content)
362  {
363  // check if file content is set...
364  // set robots.txt path + filename
365  $filename = "$path"."robots.txt";
366  if (file_put_contents("$filename", "$content"))
367  {
368  return true;
369  }
370  else
371  {
372  return false;
373  }
374  }
375 
376  /**
377  * @brief Read a directory recursively
378  * @param string $path full path e.g. /xampp/htdocs/yawk-LTE/
379  * @return array
380  */
381  public static function read_recursive($path)
382  {
383  global $files_count;
384  $result = array();
385  $handle = opendir($path);
386  if ($handle)
387  {
388  while (false !== ($file = readdir($handle)))
389  {
390  if ($file != "." && $file != "..")
391  {
392  if (is_file($file))
393  {
394  $files_count = $files_count + 1;
395  }
396  $name = $path . "/" . $file;
397 
398  if (is_dir($name))
399  {
401  foreach ($ar as $value)
402  {
403  $result[] = $value;
404  }
405  }
406  else
407  {
408  $result[] = $name;
409  $files_count = $files_count + 1;
410  }
411  }
412  }
413  }
414  closedir($handle);
415  return $result;
416  }
417 
418  /**
419  * @brief Count code lines and output a small overview
420  * @param object $db database object
421  * @param string $path the full path (including base path)
422  * @param string $fileType file type with leading dot, for example: '.php'
423  * @return mixed array
424  */
425  public static function countCodeLines($path, $fileType)
426  {
428  $linesCount = 0;
429  $filesCount = 0;
430  foreach($data as $value) {
431  // count lines of files with given type
432  if (substr($value, -4) === "$fileType") {
433  $lines = file($value);
434  $i_lines = count($lines);
435  $linesCount += $i_lines;
436  unset($lines, $i_lines);
437  $filesCount++;
438  }
439  }
440  return $array = [
441  "type" => $fileType,
442  "files" => $filesCount,
443  "lines" => $linesCount,
444  ];
445  }
446 
447  /**
448  * @brief Check if zlib is available
449  * @return bool
450  */
451  public static function checkZlib()
452  { // check if zlib is installed
453  if(extension_loaded('zlib'))
454  { // installed
455  return true;
456  }
457  else
458  { // not installed
459  return false;
460  }
461  }
462 
463  /**
464  * @brief Copy a file, or recursively copy a folder and its contents
465  * @author Aidan Lister <[email protected]>
466  * @version 1.0.1
467  * @link http://aidanlister.com/2004/04/recursively-copying-directories-in-php/
468  * @param string $source Source path
469  * @param string $dest Destination path
470  * @param int $permissions New folder creation permissions
471  * @return bool Returns true on success, false on failure
472  */
473  static function xcopy($source, $dest, $permissions = 0755)
474  { // Check for symlinks
475  if (is_link($source))
476  {
477  return symlink(readlink($source), $dest);
478  }
479  // Simple copy for a file
480  if (is_file($source))
481  {
482  if (copy($source, $dest) === false)
483  {
484  return false;
485  }
486  }
487  // Make destination directory
488  if (!is_dir($dest))
489  {
490  if (!@mkdir($dest, $permissions)) {
491  // $error = error_get_last();
492  return false;
493  }
494 
495  }
496  // Loop through the folder
497  if(!is_dir($source))
498  {
499  return false;
500  }
501  else
502  {
503  $dir = dir($source);
504  while (false !== $entry = $dir->read())
505  {
506  // Skip pointers
507  if ($entry == '.' || $entry == '..')
508  {
509  continue;
510  }
511  // Deep copy directories
512  if (self::xcopy("$source/$entry", "$dest/$entry", $permissions))
513  {
514  // return false;
515  }
516  }
517  // Clean up
518  $dir->close();
519  return true;
520  }
521  }
522 
523  /**
524  * @brief Minify any string: removes spaces, tabs and linebreaks.
525  * @param string $content
526  * @return mixed
527  */
528  static function minify($content)
529  { /** minify data */
530  // remove comments
531  $content = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $content);
532  // remove space after colons
533  $content = str_replace(': ', ':', $content);
534  // remove whitespaces
535  $content = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $content);
536  return $content;
537  }
538 
539  /**
540  * @brief HTML Minifier - minify any string: removes spaces, tabstops and linebreaks.
541  * @author Rodrigo54
542  * @version 1.0.0
543  * @link https://gist.github.com/Rodrigo54/93169db48194d470188f
544  * @param string $input the CSS string to minify
545  * @return mixed
546  * @details Based on `https://github.com/mecha-cms/mecha-cms/blob/master/system/kernel/converter.php`
547  */
548  static function minifyHTML($input) {
549  if(trim($input) === "") return $input;
550  // Remove extra white-space(s) between HTML attribute(s)
551  $input = preg_replace_callback('#<([^\/\s<>!]+)(?:\s+([^<>]*?)\s*|\s*)(\/?)>#s', function($matches) {
552  return '<' . $matches[1] . preg_replace('#([^\s=]+)(\=([\'"]?)(.*?)\3)?(\s+|$)#s', ' $1$2', $matches[2]) . $matches[3] . '>';
553  }, str_replace("\r", "", $input));
554  // Minify inline CSS declaration(s)
555  if(strpos($input, ' style=') !== false) {
556  $input = preg_replace_callback('#<([^<]+?)\s+style=([\'"])(.*?)\2(?=[\/\s>])#s', function($matches) {
557  return '<' . $matches[1] . ' style=' . $matches[2] . self::minifyCSS($matches[3]) . $matches[2];
558  }, $input);
559  }
560  if(strpos($input, '</style>') !== false) {
561  $input = preg_replace_callback('#<style(.*?)>(.*?)</style>#is', function($matches) {
562  return '<style' . $matches[1] .'>'. self::minifyCSS($matches[2]) . '</style>';
563  }, $input);
564  }
565  if(strpos($input, '</script>') !== false) {
566  $input = preg_replace_callback('#<script(.*?)>(.*?)</script>#is', function($matches) {
567  return '<script' . $matches[1] .'>'. self::minifyJs($matches[2]) . '</script>';
568  }, $input);
569  }
570  return preg_replace(
571  array(
572  // t = text
573  // o = tag open
574  // c = tag close
575  // Keep important white-space(s) after self-closing HTML tag(s)
576  '#<(img|input)(>| .*?>)#s',
577  // Remove a line break and two or more white-space(s) between tag(s)
578  '#(<!--.*?-->)|(>)(?:\n*|\s{2,})(<)|^\s*|\s*$#s',
579  '#(<!--.*?-->)|(?<!>)\s+(<\/.*?>)|(<[^\/]*?>)\s+(?!<)#s', // t+c || o+t
580  '#(<!--.*?-->)|(<[^\/]*?>)\s+(<[^\/]*?>)|(<\/.*?>)\s+(<\/.*?>)#s', // o+o || c+c
581  '#(<!--.*?-->)|(<\/.*?>)\s+(\s)(?!<)|(?<!>)\s+(\s)(<[^\/]*?\/?>)|(<[^\/]*?\/?>)\s+(\s)(?!<)#s', // c+t || t+o || o+t -- separated by long white-space(s)
582  '#(<!--.*?-->)|(<[^\/]*?>)\s+(<\/.*?>)#s', // empty tag
583  '#<(img|input)(>| .*?>)<\/\1>#s', // reset previous fix
584  '#(&nbsp;)&nbsp;(?![<\s])#', // clean up ...
585  '#(?<=>)(&nbsp;)(?=<)#', // --ibid
586  // Remove HTML comment(s) except IE comment(s)
587  '#\s*<!--(?!\[if\s).*?-->\s*|(?<!>)\n+(?=<[^!])#s'
588  ),
589  array(
590  '<$1$2</$1>',
591  '$1$2$3',
592  '$1$2$3',
593  '$1$2$3$4$5',
594  '$1$2$3$4$5$6$7',
595  '$1$2$3',
596  '<$1$2',
597  '$1 ',
598  '$1',
599  ""
600  ),
601  $input);
602  }
603 
604  /**
605  * @brief Minify any string: removes spaces, tabs and linebreaks.
606  * @author Rodrigo54
607  * @version 1.0.0
608  * @link https://gist.github.com/Rodrigo54/93169db48194d470188f
609  * @param string $input the CSS string to minify
610  * @return mixed
611  * @details CSS Minifier => http://ideone.com/Q5USEF + improvement(s)
612  */
613  static
614  function minifyCSS($input) {
615  if(trim($input) === "") return $input;
616  return preg_replace(
617  array(
618  // Remove comment(s)
619  '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s',
620  // Remove unused white-space(s)
621  '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~+]|\s*+-(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si',
622  // Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0`
623  '#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si',
624  // Replace `:0 0 0 0` with `:0`
625  '#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i',
626  // Replace `background-position:0` with `background-position:0 0`
627  '#(background-position):0(?=[;\}])#si',
628  // Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space
629  '#(?<=[\s:,\-])0+\.(\d+)#s',
630  // Minify string value
631  '#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si',
632  '#(\/\*(?>.*?\*\/))|(\burl\‍()([\'"])([^\s]+?)\3(\‍))#si',
633  // Minify HEX color code
634  '#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i',
635  // Replace `(border|outline):none` with `(border|outline):0`
636  '#(?<=[\{;])(border|outline):none(?=[;\}\!])#',
637  // Remove empty selector(s)
638  '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s'
639  ),
640  array(
641  '$1',
642  '$1$2$3$4$5$6$7',
643  '$1',
644  ':0',
645  '$1:0 0',
646  '.$1',
647  '$1$3',
648  '$1$2$4$5',
649  '$1$2$3',
650  '$1:0',
651  '$1$2'
652  ),
653  $input);
654  }
655 
656  /**
657  * @brief Minify any string: removes spaces, tabs and linebreaks.
658  * @author Rodrigo54
659  * @version 1.0.0
660  * @link https://gist.github.com/Rodrigo54/93169db48194d470188f
661  * @param string $input the JS string to minify
662  * @return mixed
663  */
664  static function minifyJs($input) {
665  if(trim($input) === "") return $input;
666  return preg_replace(
667  array(
668  // Remove comment(s)
669  '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#',
670  // Remove white-space(s) outside the string and regex
671  '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\‍(\‍)\-=+\[\]\{\}|;:,.<>?\/])\s*#s',
672  // Remove the last semicolon
673  '#;+\}#',
674  // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}`
675  '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i',
676  // --ibid. From `foo['bar']` to `foo.bar`
677  '#([a-z0-9_\‍)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i'
678  ),
679  array(
680  '$1',
681  '$1$2',
682  '}',
683  '$1$3',
684  '$1.$3'
685  ),
686  $input);
687  }
688 
689  /**
690  * @brief copy an entire folder including subdirectories
691  * @param string $source source directory
692  * @param string $target target directory
693  */
694  static function full_copy($source, $target )
695  { /** copy an entire folder into another location */
696  if (is_dir($source))
697  {
698  @mkdir($target);
699  $d = dir($source);
700  while (FALSE !== ($entry = $d->read()))
701  {
702  if ($entry == '.' || $entry == '..')
703  {
704  continue;
705  }
706  $Entry = $source.'/'.$entry;
707  if (is_dir($Entry))
708  {
709  self::full_copy($Entry, $target.'/'.$entry);
710  continue;
711  }
712  copy($Entry, $target.'/'.$entry);
713  }
714  $d->close();
715  }
716  else
717  {
718  copy( $source, $target );
719  }
720  }
721 
722  /**
723  * @brief convert a integer status to string variable (0|1) to online / offline
724  * @param int $i the status var
725  * @param string $on string for status 1 (online, published...)
726  * @param string $off string for status 0 (offline, not published...)
727  * @return bool|string return the converted string or false
728  */
729  static function iStatusToString($i, $on, $off)
730  { // check if $i is set and from correct type
731  $status = '';
732  if (isset($i))
733  {
734  // check online string
735  if (!isset($on) || (empty($on)))
736  {
737  $on = "online";
738  }
739  // check offline string
740  if (!isset($off) || (empty($off)))
741  {
742  $off = "offline";
743  }
744  if ($i == "1")
745  { // return word online
746  $status = $on;
747  }
748  elseif ($i == "0")
749  { // return word online
750  $status = $off;
751  }
752  else
753  {
754  $status = "error: \$i status undefined";
755  }
756  }
757  else
758  { // ID not set or not a number
759  return false;
760  }
761  return $status;
762  }
763 
764  /**
765  * @brief replace all carriage returns with linebreaks
766  * @param string $replace searchstring
767  * @param string $string replacestring
768  * @return string
769  */
770  static function replaceCarriageReturns($replace, $string)
771  {
772  return str_replace(array("\n\r", "\n", "\r"), $replace, $string);
773  }
774 
775  /**
776  * @brief THIS SEEMS OUTDATED - obviously not needed anymore....
777  * @param string $customCSS
778  * @return string
779  */
780  static function addPreTags($customCSS)
781  {
782  // this function wraps a <pre> tag around the CSS file
783  // so that the editor (tinyMCE) can get along with the CSS
784  // after submitting the form, <pre> tags will be replaced,
785  // so that any browser can interpret the custom.css file proper.
786  $preOpen = "<pre style=\"word-wrap: break-word; white-space: pre-wrap;\">";
787  $preClose = "</pre>";
788  $customCSS = $preOpen .$customCSS;
789  $customCSS = $customCSS .$preClose;
790  return $customCSS;
791  }
792 
793  /**
794  * @brief removes all unnecessary HTML tags from custom.css
795  * @param string $replace
796  * @param string $customCSS
797  * @return string
798  */
799  static function replacePreTags($replace, $customCSS)
800  { // this function removes all unnecessary HTML tags from custom.css
801  return str_replace(array("<p>", "</p>", "<br />", "</pre>", "<pre style=\"word-wrap: break-word; white-space: pre-wrap;\">"), "", $customCSS);
802  }
803 
804  /**
805  * @brief check global page status: returns 0|1 if page is offline / online
806  * @param object $db database
807  * @return bool
808  */
809  static function isOffline($db)
810  { /** @var $db \YAWK\db */
811  /* check global site status online / offline */
812  if (\YAWK\settings::getSetting($db, "offline") == 1)
813  { // website is in maintaince mode: set offline
814  if (\YAWK\user::isAdmin($db) == false)
815  { // site is offline
816  return true;
817  }
818  else
819  { // website is offline, but display the page to admin
820  return false;
821  }
822  }
823  else
824  { // website is online, display the page for everybody
825  return false;
826  }
827  }
828 
829  /**
830  * @brief output html div with offline message
831  * @param object $db database
832  */
833  static function drawOfflineMessage($db)
834  { /** @var $db \YAWK\db */
835  /* get offline message + image */
836  $offlinemsg = \YAWK\settings::getSetting($db, "offlinemsg");
837  $offlineimg = \YAWK\settings::getSetting($db, "offlineimage");
838 
839  // include bootstrap js
840  echo "<script src=\"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js\"></script>";
841  // include bootstrap css
842  echo "<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css\">";
843  // include jquery
844  echo "<script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>";
845  // include animate.css
846  echo "<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.0/animate.min.css\" />";
847 
848  // draw offline message
849  echo "<div class=\"row\">";
850  echo "<div class=\"col-md-12 text-center\">
851  <img src=\"".$offlineimg."\" class=\"img-responsive img-fluid mx-auto mt-5 mb-5 animated flipInX\" title=\"This website is under construction. Come back again later.\">
852  <div class=\"animated fadeIn\">".$offlinemsg."</div>
853  </div>";
854  echo "</div>";
855  exit;
856  }
857 
858  /**
859  * @brief set a timeout and force page reload via JS
860  * @param string $location the url to redirect
861  * @param int $wait the time in ms to wait before redirect
862  * @return bool
863  */
864  static function setTimeout($location, $wait)
865  {
866  print"<script type=\"text/javascript\">
867  setTimeout(\"self.location.href='" . $location . "'\"," . $wait . ");
868  </script>
869  <noscript>
870  <h1>Im Browser muss javascript aktiviert sein, um die Seite richtig nutzen zu k&ouml;nnen.</h1>
871  </noscript>";
872  return true;
873  }
874 
875  /**
876  * @brief check if browscap file is set
877  * @param string $useragent full useragent
878  * @return bool|null
879  */
880  static function isBrowscapSet($useragent)
881  {
882  // check if a browscap file is set...
883  if (ini_get('browscap'))
884  { // got it, output file path
885  $browscapFile = ini_get('browscap');
886  // print browser info:
887  echo "<pre>"; print_r(get_browser($useragent)); echo "</pre>";
888  }
889  else
890  { // browscap file not set
891  \YAWK\alert::draw("info", "Warning!", "Browscap file not set in your php.ini", "", 7500);
892  // try to enable via ini_set
893  if (ini_set('browscap', 'browscap.ini'))
894  { // worked, show browser info...
895  echo "<pre>"; print_r(get_browser($useragent)); echo "</pre>";
896  }
897  else
898  { // enable failed, exit with error
899  return false;
900  // \YAWK\alert::draw("danger", "Error: ", "Browscap file not set in php.ini Tried to enable via ini_set. Did not work... aborting!", "", 15000);
901  }
902  }
903  return null;
904  }
905 
906  /**
907  * @brief extract browser from useragent
908  * @param string $useragent the full useragent
909  * @return array array with useragent, browser, version and platform
910  */
911  static function getBrowser($useragent)
912  {
913  if (isset($useragent) && (!empty($useragent)))
914  {
915  $u_agent = $useragent;
916  }
917  else
918  {
919  $u_agent = $_SERVER['HTTP_USER_AGENT'];
920  }
921  $bname = 'Unknown';
922  $platform = 'Unknown';
923  $ub = '';
924  $version= "";
925 
926  //First get the platform?
927  if (preg_match('/linux/i', $u_agent)) {
928  $platform = 'linux';
929  }
930  elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
931  $platform = 'mac';
932  }
933  elseif (preg_match('/windows|win32/i', $u_agent)) {
934  $platform = 'windows';
935  }
936  elseif(preg_match('/linux|android/i',$u_agent))
937  {
938  $bname = 'Android';
939  $ub = "Android";
940  $platform = "Android";
941  }
942 
943  // Next get the name of the useragent yes seperately and for good reason
944  if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
945  {
946  $bname = 'Internet Explorer';
947  $ub = "MSIE";
948  }
949  if(preg_match('/Edge/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
950  {
951  $bname = 'Edge';
952  $ub = "Edge";
953  }
954  elseif(preg_match('/Trident/i',$u_agent))
955  { // this condition is for IE11
956  $bname = 'Internet Explorer';
957  $ub = "rv";
958  }
959  elseif(preg_match('/Firefox/i',$u_agent))
960  {
961  $bname = 'Mozilla Firefox';
962  $ub = "Firefox";
963  }
964  elseif(preg_match('/Chrome/i',$u_agent))
965  {
966  $bname = 'Google Chrome';
967  $ub = "Chrome";
968  }
969  elseif(preg_match('/Safari/i',$u_agent))
970  {
971  $bname = 'Apple Safari';
972  $ub = "Safari";
973  }
974  elseif(preg_match('/Opera/i',$u_agent))
975  {
976  $bname = 'Opera';
977  $ub = "Opera";
978  }
979  elseif(preg_match('/Netscape/i',$u_agent))
980  {
981  $bname = 'Netscape';
982  $ub = "Netscape";
983  }
984 
985  // finally get the correct version number
986  // Added "|:"
987  $known = array('Version', $ub, 'other');
988  $pattern = '#(?<browser>' . join('|', $known) .
989  ')[/|: ]+(?<version>[0-9.|a-zA-Z.]*)#';
990  if (!preg_match_all($pattern, $u_agent, $matches)) {
991  // we have no matching number just continue
992  }
993 
994  // see how many we have
995  $i = count($matches['browser']);
996  if ($i != 1) {
997  //we will have two since we are not using 'other' argument yet
998  //see if version is before or after the name
999  if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
1000  $version= $matches['version'][0];
1001  }
1002  else {
1003  $version= $matches['version'][1];
1004  }
1005  }
1006  else {
1007  $version= $matches['version'][0];
1008  }
1009 
1010  // check if we have a number
1011  if ($version==null || $version=="") {$version="?";}
1012 
1013  return array(
1014  'userAgent' => $u_agent,
1015  'name' => $bname,
1016  'version' => $version,
1017  'platform' => $platform,
1018  'pattern' => $pattern
1019  );
1020  }
1021 
1022  /**
1023  * @brief get operating system from useragent string
1024  * @param string $useragent full useragent string
1025  * @return mixed|string return string containing the OS (platform)
1026  */
1027  static function getOS($useragent) {
1028  if (isset($useragent) && (!empty($useragent)))
1029  {
1030  $u_agent = $useragent;
1031  }
1032  else
1033  {
1034  $u_agent = $_SERVER['HTTP_USER_AGENT'];
1035  }
1036  // $os_platform = "Unknown OS Platform";
1037  $os_array = array(
1038  '/Sec-CH-UA-Platform/i' => 'Windows 11',
1039  '/Windows NT 10.0/i' => 'Windows 10',
1040  '/windows nt 6.2/i' => 'Windows 8',
1041  '/windows nt 6.1/i' => 'Windows 7',
1042  '/windows nt 6.0/i' => 'Windows Vista',
1043  '/windows nt 5.2/i' => 'Windows Server 2003/XP x64',
1044  '/windows nt 5.1/i' => 'Windows XP',
1045  '/windows xp/i' => 'Windows XP',
1046  '/windows nt 5.0/i' => 'Windows 2000',
1047  '/windows me/i' => 'Windows ME',
1048  '/win98/i' => 'Windows 98',
1049  '/win95/i' => 'Windows 95',
1050  '/win16/i' => 'Windows 3.11',
1051  '/macintosh|mac os x/i' => 'Mac OS X',
1052  '/mac_powerpc/i' => 'Mac OS 9',
1053  '/linux/i' => 'Linux',
1054  '/ubuntu/i' => 'Ubuntu',
1055  '/iphone/i' => 'iPhone',
1056  '/ipod/i' => 'iPod',
1057  '/ipad/i' => 'iPad',
1058  '/android/i' => 'Android',
1059  '/blackberry/i' => 'BlackBerry',
1060  '/webos/i' => 'Mobile'
1061  );
1062 
1063  foreach ($os_array as $regex => $value) {
1064  if (preg_match($regex, $u_agent)) {
1065  $os_platform = $value;
1066  }
1067  }
1068  return $os_platform;
1069  }
1070 
1071  /**
1072  * @brief measure script loading time
1073  * @param string $debugTime starting time
1074  * @return string return formated time in milliseconds
1075  */
1076  static function getLoadingTime($debugTime)
1077  {
1078  // debugTime to measure script time
1079  $debugTime = microtime(true) - $debugTime;
1080  $debugTime = number_format($debugTime, 3);
1081  return "<small>&nbsp; script execution time: $debugTime Sek.</small>";
1082  }
1083 
1084  /**
1085  * @brief convert german special chars and vowels into legal html
1086  * @param string $string to encode
1087  * @return string return encoded string
1088  */
1089  static function encodeChars($string)
1090  { // requires string. encodes german vowels
1091  // $string = utf8_decode($string);
1092  $chars = array("ö" => "&ouml;", "ä" => "&auml;", "ü" => "&uuml;",
1093  "Ö" => "&Ouml;", "Ä" => "&Auml;", "Ãœ" => "&Uuml;",
1094  "ß" => "&szlig;",
1095  "€" => "&euro;");
1096  return strtr($string, $chars);
1097  }
1098 
1099  /**
1100  * @brief if yawk is installed into a subdirectory, use this to get this prefix directory
1101  * @param object $db database
1102  * @return string return the directory prefix
1103  */
1104  static function getDirPrefix($db)
1105  { // returns directory prefix from settings
1106  $dirprefix = settings::getSetting($db, "dirprefix");
1107  return $dirprefix;
1108  }
1109 
1110  /**
1111  * @brief get hostname (url where yawk is installed) from database
1112  * @param object $db database
1113  * @return bool|string
1114  */
1115  static function getHost($db)
1116  { // get host from settings db
1117  $hostname = settings::getSetting($db, "host");
1118  $hostname = self::addTrailingSlash($hostname);
1119  return $hostname;
1120  }
1121 
1122  /**
1123  * @brief remove a directory recurse
1124  * @param string $dir the directory to delete
1125  * @return bool
1126  */
1127  static function recurseRmdir($dir) {
1128  if (is_dir(dirname($dir)))
1129  {
1130  $files = array_diff(scandir($dir), array('.','..'));
1131  foreach ($files as $file) {
1132  (is_dir("$dir/$file")) ? self::recurseRmdir("$dir/$file") : unlink("$dir/$file");
1133  }
1134  return rmdir($dir);
1135  }
1136  else
1137  {
1138  return false;
1139  }
1140  }
1141 
1142  /**
1143  * @brief sometimes it is necessary to add a slash to a url.
1144  * @param string $url the url were the slash needs to be added
1145  * @return string return url containing the slash
1146  */
1147  static function addTrailingSlash($url)
1148  { // check if url contains a trailing slash at the end
1149  if (substr($url, -1, 1) !== "/")
1150  { // if not, it will be added
1151  $url = $url."/";
1152  }
1153  // return url with trailing slash
1154  return $url;
1155  }
1156 
1157  /**
1158  * @brief get any property from any table where id is given ID
1159  * @param object $db database
1160  * @param string $property what to select (field)
1161  * @param string $table from wich (table)
1162  * @param string $id where id = (id)
1163  * @return bool
1164  */
1165  static function getProperty($db, $property, $table, $id)
1166  { /** @param $db \YAWK\db $res */
1167  if ($res = $db->query("SELECT " . $property . " FROM {$table}
1168  WHERE id = '" . $id . "'"))
1169  { // fetch data
1170  if ($row = mysqli_fetch_row($res))
1171  { // return property
1172  return $row[0];
1173  }
1174  else
1175  { // fetch failed
1176  return false;
1177  }
1178  }
1179  else
1180  { // q failed
1181  return false;
1182  }
1183  }
1184 
1185  /**
1186  * @brief get requested group ID for given page ID (used in page-edit)
1187  * @param object $db database
1188  * @param string $id page ID
1189  * @param string $table the table to select from
1190  * @return string|bool return the group ID or false
1191  */
1192  static function getGroupId($db, $id, $table)
1193  { /** @param $db \YAWK\db $res */
1194  if ($res = $db->query("SELECT cg.id
1195  FROM {".$table."} as cp
1196  JOIN {user_groups} as cg on cg.id = cp.gid
1197  WHERE cp.id = $id"))
1198  { // get GroupId (gid) from given table
1199  $row = mysqli_fetch_row($res);
1200  return $row[0];
1201  }
1202  else
1203  {
1204  \YAWK\alert::draw("warning", "Warning", "Could not fetch Group ID from $table", "","2000");
1205  }
1206  return false;
1207  }
1208 
1209 
1210  /**
1211  * @brief get requested group ID for given page ID
1212  * @param object $db database
1213  * @param string $id page ID
1214  * @param string $table the table to select from
1215  * @return string|bool return the group ID or false
1216  */
1217  static function getGroupFromId($db, $id, $table)
1218  {
1219  /** @param $db \YAWK\db $res */
1220  if ($res = $db->query("SELECT cp.gid, cg.value
1221  FROM {".$table."} as cp
1222  JOIN {user_groups} as cg on cg.id = cp.gid
1223  WHERE cp.id = $id"))
1224  {
1225  while ($row = mysqli_fetch_row($res))
1226  {
1227  echo $row[1];
1228  }
1229  return $row[0];
1230  }
1231  else {
1232  \YAWK\alert::draw("warning", "Warning", "Could not fetch Group from page ID $id", "","2000");
1233  // q failed
1234  return false;
1235  }
1236  }
1237 
1238  /**
1239  * @brief get all user groups from database
1240  * @param object $db database
1241  * @param string $table the table to select from
1242  * @return array|bool|string
1243  */
1244  static function getGroups($db, $table)
1245  {
1246  /** @param $db \YAWK\db $res */
1247  $groupsArray = array();
1248  if ($res = $db->query("SELECT id, value, (
1249  SELECT COUNT( * )
1250  FROM {".$table."}
1251  WHERE gid = {user_groups.id}
1252  )count
1253  FROM {user_groups} ORDER by id ASC"))
1254  {
1255  while ($row = $res->fetch_assoc())
1256  {
1257  $groupsArray[] = $row;
1258  }
1259  return $groupsArray;
1260  }
1261  // q failed
1262  return false;
1263  }
1264 
1265  /**
1266  * @brief include page header and metadata
1267  * @param object $db database
1268  * @param string $host host URL
1269  */
1270  static function includeHeader($db, $host)
1271  { /** @var $db \YAWK\db */
1272  global $currentpage;
1273  $i = 1;
1274  echo "<title>" . $currentpage->title . "</title>
1275 <base href=\"".$host."\">
1276 <meta http-equiv=\"Content-Type\" content=\"text/html\">
1277 <link rel=\"shortcut icon\" href=\"favicon.ico\" type=\"image/x-icon\">";
1278  }
1279 
1280  /**
1281  * @brief returns the current user name, if set
1282  * @return string
1283  */
1284  static function getCurrentUserName()
1285  {
1286  if (isset($_SESSION['username'])) {
1287  return $_SESSION['username'];
1288  }
1289  else {
1290  return "Gast";
1291  }
1292  }
1293 
1294  /**
1295  * @brief get submenu ID for given page ID
1296  * @param object $db database
1297  * @param string $id page ID
1298  * @return mixed string|int
1299  */
1300  static function getSubMenu($db, $id)
1301  {
1302  /** @param $db \YAWK\db $res */
1303  if ($res = $db->query("SELECT m.id
1304  FROM {pages} as p
1305  JOIN {menu_names} as m on m.id = p.menu
1306  WHERE p.id = $id")){
1307  $row = mysqli_fetch_row($res);
1308  if (!isset($row[0]) ||(empty($row[0])))
1309  {
1310  return "0";
1311  }
1312  else
1313  {
1314  return $row[0];
1315  }
1316  }
1317  else
1318  {
1319  return "0";
1320  }
1321  }
1322 
1323  /**
1324  * @brief get menu item for given page ID
1325  * @param object $db database
1326  * @param int $id page ID
1327  * @return bool
1328  */
1329  static function getMenuItem($db, $id)
1330  {
1331  /** @param $db \YAWK\db $res */
1332  if ($row = $db->query("SELECT p.menu, m.name
1333  FROM {pages} as p
1334  JOIN {menu_names} as m on m.id = p.menu
1335  WHERE p.id = $id"))
1336  {
1337  $res = mysqli_fetch_row($row);
1338  if (isset($res[1])){
1339  return $res[1];
1340  }
1341  else {
1342  return null;
1343  }
1344  }
1345  else
1346  {
1347  return null;
1348  }
1349  }
1350 
1351  /**
1352  * @brief get menu names from database
1353  * @param object $db database
1354  * @return array|bool
1355  */
1356  static function getMenus($db)
1357  {
1358  /** @var $db \YAWK\db */
1359  $menusArray = array();
1360  if ($res = $db->query("SELECT id, name, published, (
1361  SELECT COUNT( * )
1362  FROM {menu}
1363  WHERE menuID = {menu_names.id}
1364  ) count FROM {menu_names}"))
1365  {
1366  while ($row = $res->fetch_assoc())
1367  {
1368  $menusArray[] = $row;
1369  }
1370  return $menusArray;
1371  }
1372  else
1373  { // q failed
1374  return false;
1375  }
1376  }
1377 
1378  /**
1379  * @brief returns menu name for given menu ID
1380  * @param object $db database
1381  * @param int $id menu ID
1382  * @return bool
1383  */
1384  static function getMenuName($db, $id)
1385  { /** @param $db \YAWK\db $res */
1386  if ($res = $db->query("SELECT name
1387  FROM {menu_names}
1388  WHERE id = $id"))
1389  { // return menu name
1390  $row = mysqli_fetch_row($res);
1391  return $row[0];
1392  }
1393  else
1394  { // q failed
1395  return false;
1396  }
1397  }
1398 
1399  /**
1400  * @brief returns menu language for given menu ID
1401  * @param object $db database
1402  * @param int $id menu ID
1403  * @return bool
1404  */
1405  static function getMenuLanguage($db, $id)
1406  { /** @param $db \YAWK\db $res */
1407  if ($res = $db->query("SELECT menuLanguage
1408  FROM {menu_names}
1409  WHERE id = $id"))
1410  { // return menu name
1411  $row = mysqli_fetch_row($res);
1412  return $row[0];
1413  }
1414  else
1415  { // q failed
1416  return false;
1417  }
1418  }
1419 
1420  /**
1421  * @brief get pages from database
1422  * @param object $db database
1423  * @return bool|mixed
1424  */
1425  static function getPages($db)
1426  { /** @var $db \YAWK\db */
1427  if ($row = $db->query("SELECT id, title
1428  FROM {pages} ORDER BY title"))
1429  {
1430  $PagesArray = array();
1431  while ($res = $row->fetch_assoc())
1432  {
1433  $pagesArray[] = $res;
1434  }
1435  return $pagesArray;
1436  }
1437  else
1438  {
1439  return false;
1440  }
1441  }
1442 
1443 
1444  /**
1445  * @brief get user groups (roles) for given page
1446  * @param object $db database
1447  * @param int $id page ID
1448  * @param string $table from table
1449  * @return mixed
1450  */
1451  static function getRole($db, $id, $table)
1452  { /** @var $db \YAWK\db */
1453  $mysqlRes = $db->query("SELECT cp.gid, cg.value
1454  FROM {".$table."} as cp
1455  JOIN {user_groups} as cg on cg.id = cp.gid
1456  WHERE cp.id = '".$id."'");
1457  // fetch data
1458  while ($row = mysqli_fetch_row($mysqlRes)) {
1459  echo $row[1];
1460  }
1461  return $row[0];
1462  }
1463 
1464  /**
1465  * @brief get group ID (role) for given page ID
1466  * @param object $db database
1467  * @param int $id affected page ID
1468  * @param string $table from table
1469  * @return string|bool
1470  */
1471  static function getRoleId($db, $id, $table)
1472  { /** @var $db \YAWK\db */
1473  $mysqlRes = $db->query("SELECT cg.id
1474  FROM {".$table."} as cp
1475  JOIN {user_groups} as cg on cg.id = cp.gid
1476  WHERE cp.id = $id");
1477 
1478  if ($row = mysqli_fetch_row($mysqlRes))
1479  {
1480  return $row[0];
1481  }
1482  else
1483  {
1484  return false;
1485  }
1486  }
1487 
1488  /**
1489  * @brief returns the current datetime
1490  * @return string datetime Y-m-d H:i:s
1491  */
1492  static function now()
1493  { // return current datetime in mysql format
1494  return date("Y-m-d H:i:s");
1495  }
1496 
1497  /**
1498  * @brief split a date to month, day, year and time
1499  * @param string $date the date to split
1500  * @return array return an array w single items
1501  */
1502  static function splitDate($date)
1503  {
1504  $year = substr($date, 0, 4);
1505  $day = substr($date, 8, 2);
1506  $month = substr($date, 5, 2);
1507  $time = substr($date, 11, 5);
1508 
1509  /* remove leading null */
1510  $day = 1 * $day; // to do that, change type from string to integer
1511 
1512  /* calculate months */
1513  switch ($month) {
1514  case "01":
1515  $month = "January";
1516  // $month = $lang['FEBRUARY'];
1517  break;
1518  case "02":
1519  $month = "February";
1520  // $month = $lang['FEBRUARY'];
1521  break;
1522  case "03":
1523  $month = "March";
1524  // $month = $lang['MARCH'];
1525  break;
1526  case "04":
1527  $month = "April";
1528  // $month = $lang['APRIL'];
1529  break;
1530  case "05":
1531  $month = "May";
1532  // $month = $lang['MAY'];
1533  break;
1534  case "06":
1535  $month = "June";
1536  // $month = $lang['JUNE'];
1537  break;
1538  case "07":
1539  $month = "July";
1540  // $month = $lang['JULY'];
1541  break;
1542  case "08":
1543  $month = "August";
1544  // $month = $lang['AUGUST'];
1545  break;
1546  case "09":
1547  $month = "September";
1548  // $month = $lang['SEPTEMBER'];
1549  break;
1550  case "10":
1551  $month = "October";
1552  // $month = $lang['OCTOBER'];
1553  break;
1554  case "11":
1555  $month = "November";
1556  // $month = $lang['NOVEMBER'];
1557  break;
1558  case "12":
1559  $month = "December";
1560  // $month = $lang['DECEMBER'];
1561  break;
1562  }
1563  return $splitDate = array("year" => "$year", "day" => "$day", "month" => "$month", "time" => "$time");
1564  }
1565 
1566 
1567  /**
1568  * @brief split a date to month, day, year and time this is the same as splitDate() but keep the months short
1569  * @param string $date the date to split
1570  * @return array return an array w single items
1571  */
1572  static function splitDateShort($date)
1573  {
1574  $year = substr($date, 0, 4);
1575  $day = substr($date, 8, 2);
1576  $month = substr($date, 5, 2);
1577  $time = substr($date, 11, 5);
1578 
1579  /* remove leading null */
1580  $day = 1 * $day; // to do that, we change type from string to integer
1581 
1582  /* monate umrechnen */
1583  switch ($month) {
1584  case "01":
1585  $month = "Jan";
1586  break;
1587  case "02":
1588  $month = "Feb";
1589  break;
1590  case "03":
1591  $month = "Mar";
1592  break;
1593  case "04":
1594  $month = "Apr";
1595  break;
1596  case "05":
1597  $month = "May";
1598  break;
1599  case "06":
1600  $month = "Jun";
1601  break;
1602  case "07":
1603  $month = "Jul";
1604  break;
1605  case "08":
1606  $month = "Aug";
1607  break;
1608  case "09":
1609  $month = "Sep";
1610  break;
1611  case "10":
1612  $month = "Okt";
1613  break;
1614  case "11":
1615  $month = "Nov";
1616  break;
1617  case "12":
1618  $month = "Dez";
1619  break;
1620  }
1621  return $splitDate = array("year" => "$year", "day" => "$day", "month" => "$month", "time" => "$time");
1622  }
1623 
1624  /**
1625  * @brief how many time is been gone since given date
1626  * @param string $userdate date to calculate
1627  * @param array $lang language array
1628  * @return string return how many time has gone since $userdate
1629  */
1630  static function time_ago($userdate, $lang)
1631  {
1632  $time_ago = '';
1633 
1634  $date = new \DateTime($userdate);
1635  $diff = $date->diff(new \DateTime('now'));
1636 
1637  if ($t = $diff->format("%y"))
1638  {
1639  if ($t > 1)
1640  {
1641  $time_ago = (int)$t . ' '.$lang['YEARS'].'';
1642  }
1643  else if ($t < 2)
1644  {
1645  $time_ago = (int)$t . ' '.$lang['YEAR'].'';
1646  }
1647  }
1648 
1649  elseif ($t = $diff->format("%m"))
1650  {
1651  if ($t > 1)
1652  {
1653  $time_ago = (int)$t . ' '.$lang['MONTHS'].'';
1654  }
1655  else if ($t < 2)
1656  {
1657  $time_ago = (int)$t . ' '.$lang['MONTH'].'';
1658  }
1659  }
1660  elseif ($t = $diff->format("%d"))
1661  {
1662 
1663  if ($t >= 7 && $t < 13)
1664  {
1665  $time_ago = $lang['A_WEEK_AGO'];
1666  }
1667  elseif ($t >= 14 && $t < 20)
1668  {
1669  $time_ago = $lang['TWO_WEEKS_AGO'];
1670  }
1671  elseif ($t >= 21 && $t < 27)
1672  {
1673  $time_ago = $lang['THREE_WEEKS_AGO'];
1674  }
1675  elseif ($t >= 28 && $t < 31)
1676  {
1677  $time_ago = $lang['FOUR_WEEKS_AGO'];
1678  }
1679  else if ($t > 1)
1680  {
1681  $time_ago = (int)$t . ' '.$lang['DAYS_P'].'';
1682  }
1683  else if ($t < 2)
1684  {
1685  $time_ago = (int)$t . ' '.$lang['DAY'].'';
1686  }
1687  }
1688 
1689  elseif ($t = $diff->format("%h"))
1690  {
1691  if ($t > 1)
1692  {
1693  $time_ago = (int)$t . ' '.$lang['HOURS'].'';
1694  }
1695  else if ($t < 2)
1696  {
1697  $time_ago = (int)$t . ' '.$lang['HOUR'].'';
1698  }
1699  }
1700 
1701  elseif ($t = $diff->format("%i"))
1702  {
1703  if ($t > 1)
1704  {
1705  $time_ago = (int)$t . ' '.$lang['MINUTES'].'';
1706  }
1707  else if ($t < 2)
1708  {
1709  $time_ago = (int)$t . ' '.$lang['MINUTE'].'';
1710  }
1711  }
1712 
1713  elseif ($t = $diff->format("%s"))
1714  {
1715  if ($t < 60)
1716  {
1717  $time_ago = $lang['LESS_THAN_A_MINUTE'];
1718  }
1719  }
1720 
1721  // if language is german, turn around the 'ago' term
1722  if (\YAWK\language::getCurrentLanguageStatic() === "de-DE")
1723  { // return reverse for germans
1724  return $lang['AGO'] . ' '.$time_ago.'';
1725  }
1726  // default return string
1727  return $time_ago . ' '.$lang['AGO'].'';
1728  }
1729 
1730  /**
1731  * @brief return weekday from given date
1732  * @param string $date the date to calculate
1733  * @return bool|false|string
1734  */
1735  static function getWeekday($date, $lang)
1736  {
1737  global $lang;
1738  if (isset($date)){
1739  // get weekday
1740  $weekday = date("l",strtotime($date));
1741  if (isset($lang) && (!empty($lang) && (is_array($lang))))
1742  {
1743  // translate, if language is set
1744  switch($weekday){
1745  case "$lang[MONDAY]":
1746  $weekday = "$lang[MONDAY]";
1747  break;
1748  case "$lang[TUESDAY]":
1749  $weekday = "$lang[TUESDAY]";
1750  break;
1751  case "$lang[WEDNESDAY]":
1752  $weekday = "$lang[WEDNESDAY]";
1753  break;
1754  case "$lang[THURSDAY]":
1755  $weekday = "$lang[THURSDAY]";
1756  break;
1757  case "$lang[FRIDAY]":
1758  $weekday = "$lang[FRIDAY]";
1759  break;
1760  case "$lang[SATURDAY]":
1761  $weekday = "$lang[SATURDAY]";
1762  break;
1763  case "$lang[SUNDAY]":
1764  $weekday = "$lang[SUNDAY]";
1765  break;
1766  }
1767  }
1768  return $weekday;
1769  }
1770  else {
1771  return false;
1772  }
1773  }
1774 
1775  /**
1776  * @brief Returns, if given syslog category ID is active or not
1777  * @param object $db database object
1778  * @param string $syslogCategoryID ID of the requested syslog category
1779  * @return array
1780  */
1781  static function isSysLogCategoryActive($db, $syslogCategoryID)
1782  { /** @var $db \YAWK\db */
1783  $syslogSettings = arraY();
1784  if(isset($syslogCategoryID) && (!empty($syslogCategoryID)))
1785  { // query db
1786  if ($sql = ($db->query("SELECT active, notify from {syslog_categories} WHERE id = '".$syslogCategoryID."'")))
1787  {
1788  // fetch db
1789  while ($row = mysqli_fetch_assoc($sql))
1790  {
1791  $syslogSettings[] = $row;
1792  }
1793  // check if category should be logged (is active)
1794  if (isset($syslogSettings['active']) && (!empty($active['active']) && ($active['active'] === "1")))
1795  { // category active
1796  $syslogSettings['active'] = 1;
1797  }
1798  else
1799  { // category not active
1800  $syslogSettings['active'] = 0;
1801  }
1802  // check if category should be notyfied (is enabled)
1803  if (isset($syslogSettings['notify']) && (!empty($active['notify']) && ($active['notify'] === "1")))
1804  { // notify active
1805  $syslogSettings['notify'] = 1;
1806  }
1807  else
1808  { // notify not active
1809  $syslogSettings['notify'] = 0;
1810  }
1811  }
1812  else
1813  { // unable to query database, set notification ON default
1814  $syslogSettings['active'] = 1;
1815  $syslogSettings['notify'] = 1;
1816  return $syslogSettings;
1817  }
1818  return $syslogSettings;
1819  }
1820  else
1821  { // no category ID was sent, set notification ON default
1822  $syslogSettings['active'] = 1;
1823  $syslogSettings['notify'] = 1;
1824  return $syslogSettings;
1825  }
1826  }
1827 
1828  /**
1829  * @brief log message to debug_log.txt
1830  * @details this function is used to log any given messages to debug_log.txt
1831  * @param $message
1832  * @return void
1833  */
1834  public function logMessage($message) {
1835  $logfile = 'debug_log.txt';
1836  $timestamp = date('Y-m-d H:i:s');
1837  file_put_contents($logfile, "[$timestamp] $message\n", FILE_APPEND);
1838  }
1839 
1840  /**
1841  * @brief set a syslog entry to database
1842  * @param object $db database
1843  * @param int $log_category log category
1844  * @param int $log_type log type (info = 0 , warning = 1, error = 2)
1845  * @param string $message logging message
1846  * @param int $fromUID affected from UID
1847  * @param int $toUID affected to UID
1848  * @param int $toGID affected GID
1849  * @param int $seen 0|1 status if this entry has been overviewed
1850  * @return bool|null
1851  */
1852  static function setSyslog($db, $log_category, $log_type, $message, $fromUID, $toUID, $toGID, $seen)
1853  { /** @var $db \YAWK\db */
1854  // THIS DB STORES ALL THE SYSLOG FOR ADMINISTRATOR REASONS
1855  // insert admin-friendly message of all data into syslog db
1856 
1857  // get current log date
1858  $log_date = sys::now();
1859 
1860  // check if syslog is enabled
1861  if (\YAWK\settings::getSetting($db, "syslogEnable") == "1")
1862  {
1863  // check if log_category is empty
1864  if (!isset($log_category) || (empty($log_category) || ($log_category === "0")))
1865  { // default value: system settings (type 1)
1866  $log_category = 1;
1867  }
1868  // check if message is empty
1869  if (!isset($message) || (empty($message) || ($message === "0")))
1870  { // default value
1871  if (isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 'no page set.'; }
1872  $message = "something happened, but no text was set for logging. $page";
1873  }
1874 
1875  // check if log type is set
1876  if (!isset($log_type) ||(empty($log_type)))
1877  {
1878  $log_type = 0;
1879  }
1880 
1881  // check, if fromUID (user that affected the event) is set
1882  if (!isset($fromUID) || (empty($fromUID) || ($fromUID == "0")))
1883  { // check if session uid is set
1884  if (isset($_SESSION['uid']))
1885  { // ok, set var
1886  $fromUID = $_SESSION['uid'];
1887  }
1888  else
1889  { // set zero
1890  $fromUID = 0;
1891  }
1892  }
1893 
1894 
1895  // get syslog settings (which category is active and should be notified)
1896  $syslogSettings = self::isSysLogCategoryActive($db, $log_category);
1897  // check if notification should be enabled for this category
1898  if (isset($syslogSettings[0]['notify']) && ($syslogSettings[0]['notify'] == 1))
1899  { // set syslog entry to state !seen (not seen)
1900  $seen = 0; // means notification WILL be drawn
1901  }
1902  else
1903  { // set syslog entry to state 'seen'
1904  $seen = 1; // means notification will NOT be drawn
1905  }
1906 
1907  // only add syslog entry if category is enabled for logging (active)
1908  if (isset($syslogSettings[0]['active']) && ($syslogSettings[0]['active'] == 1))
1909  {
1910  // insert syslog entry into db
1911  if ($db->query("INSERT INTO {syslog} (log_date, log_category, log_type, message, fromUID, toUID, toGID, seen)
1912  VALUES ('".$log_date."',
1913  '".$log_category."',
1914  '".$log_type."',
1915  '".$message."',
1916  '".$fromUID."',
1917  '".$toUID."',
1918  '".$toGID."',
1919  '".$seen."')"))
1920  { // syslog entry set
1921  return true;
1922  }
1923  else
1924  { // insert q failed
1925  return false;
1926  }
1927  }
1928  else
1929  { // syslog disabled for this category
1930  return null;
1931  }
1932  }
1933  else
1934  { // syslog is disabled
1935  return null;
1936  }
1937  }
1938 
1939  /**
1940  * @brief get all syslog entries
1941  * @param object $db database
1942  * @return array|bool $syslogResults
1943  */
1944  static function getSyslog($db)
1945  { /** @var $db \YAWK\db */
1946  // get syslog data from db
1947  $syslogResults = array();
1948  if ($res = $db->query("SELECT * FROM {syslog} AS log
1949  LEFT JOIN {syslog_categories} AS category ON log.log_category=category.id
1950  LEFT JOIN {users} AS u ON log.fromUID=u.id
1951  GROUP BY log.log_id
1952  ORDER BY log.log_date DESC"))
1953  { // syslog entry set
1954  while ($row = mysqli_fetch_assoc($res))
1955  // check if array is set and not empty
1956  { // build syslog results array
1957  $syslogResults[] = $row;
1958  }
1959  // check if syslog array is set and not empty
1960  if (is_array($syslogResults) && (!empty($syslogResults)))
1961  { // all good...
1962  return $syslogResults;
1963  }
1964  else
1965  { // array is not set or empty
1966  return false;
1967  }
1968  }
1969  else
1970  { // failed to query syslog data from db
1971  return false;
1972  }
1973  }
1974 
1975  /**
1976  * @brief get all syslog categories
1977  * @param object $db database
1978  * @return array|bool $syslogResults
1979  */
1980  static function getSyslogCategories($db)
1981  { /** @var $db \YAWK\db */
1982  // get syslog data from db
1983  $syslogCategories = array();
1984  if ($res = $db->query("SELECT * FROM {syslog_categories} ORDER BY property"))
1985  { // syslog entry set
1986  while ($row = mysqli_fetch_assoc($res))
1987  // check if array is set and not empty
1988  { // build syslog results array
1989  $syslogCategories[] = $row;
1990  }
1991  // check if syslog array is set and not empty
1992  if (is_array($syslogCategories) && (!empty($syslogCategories)))
1993  { // all good...
1994  return $syslogCategories;
1995  }
1996  else
1997  { // array is not set or empty
1998  return false;
1999  }
2000  }
2001  else
2002  { // failed to query syslog data from db
2003  return false;
2004  }
2005  }
2006 
2007  /**
2008  * @brief set a system notification for any user or admin
2009  * @param object $db database
2010  * @param int $log_category log category
2011  * @param int $log_type log type
2012  * @param int $msg_id message id
2013  * @param int $fromUID affected from user ID
2014  * @param int $toUID affected to user ID
2015  * @param int $toGID affected to group ID
2016  * @param int $seen 0|1 status if notification has been seen
2017  * @return bool
2018  */
2019  static function setNotification($db, $log_category, $log_type, $msg_id, $fromUID, $toUID, $toGID, $seen)
2020  { /** @var $db \YAWK\db */
2021  // THIS ARE THE MESSAGES FOR END-USERS
2022  // (a copy of syslog) DUE PERFORMANCE REASONS
2023  // (only user-messages, no system messages...)
2024  // insert user-friendly message into notifications db
2025  if ($db->query("INSERT INTO {notifications} (log_type,msg_id,fromUID,toUID,toGID,seen)
2026  VALUES ('".$log_category."',
2027  '".$log_type."',
2028  '".$msg_id."',
2029  '".$fromUID."',
2030  '".$toUID."',
2031  '".$toGID."',
2032  '".$seen."')"))
2033  { // set a notification into user notifications db
2034  return true;
2035  }
2036  else
2037  { // q failed
2038  return false;
2039  }
2040  }
2041 
2042  /**
2043  * @brief mark a notification as seen / unseen
2044  * @param object $db database
2045  * @param int $id the affected notification log_id
2046  * @param int $seen 0|1 status if notification has been seen
2047  * @return bool
2048  */
2049  static function markNotification($db, $id, $seen)
2050  { /** @var $db \YAWK\db */
2051  if (!isset($seen))
2052  { // default value
2053  $seen = 0;
2054  }
2055  if ($db->query("UPDATE {notifications} SET seen = '".$seen."' WHERE log_id = '".$id."'"))
2056  { // set a notification into syslog
2057  return true;
2058  }
2059  else
2060  { // q failed
2061  return false;
2062  }
2063  }
2064 
2065  /**
2066  * @brief check if objects exists and display their data
2067  */
2068  static function outputObjects($template, $lang, $controller, $page, $user, $stats)
2069  {
2070  $objects = get_defined_vars();
2071  if (isset($objects) && (is_array($objects)))
2072  {
2073  echo "ALL DECLARED OBJECTS IN THIS SCOPE:<hr>";
2074  echo "<pre>";print_r($objects);echo"</pre><hr>";
2075  }
2076  exit;
2077  }
2078 
2079  /**
2080  * @brief write ini file
2081  * @param $array
2082  * @param $file
2083  * @return bool
2084  */
2085  static function writeIniFile($array, $file)
2086  {
2087  $res = array();
2088  foreach($array as $key => $val)
2089  {
2090  if(is_array($val))
2091  {
2092  $res[] = "[$key]";
2093  foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"');
2094  }
2095  else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"');
2096  }
2097  if (self::safeFileReWrite($file, implode("\r\n", $res)))
2098  { // ini file written
2099  return true;
2100  }
2101  else
2102  { // failed to return ini file
2103  return false;
2104  }
2105  }
2106 
2107  /**
2108  * @brief Safe way to open a file and update data
2109  * @param $fileName
2110  * @param $dataToSave
2111  * @return bool
2112  */
2113  static function safeFileReWrite($fileName, $dataToSave)
2114  {
2115  if ($fp = fopen($fileName, 'w'))
2116  {
2117  $startTime = microtime(TRUE);
2118  do
2119  {
2120  $canWrite = flock($fp, LOCK_EX);
2121  // If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
2122  if(!$canWrite) usleep(round(rand(0, 100)*1000));
2123  }
2124  while ((!$canWrite)and((microtime(TRUE)-$startTime) < 5));
2125 
2126  //file was locked so now we can store information
2127  if ($canWrite)
2128  {
2129  fwrite($fp, $dataToSave);
2130  flock($fp, LOCK_UN);
2131  }
2132  fclose($fp);
2133  }
2134  if (is_file($fileName))
2135  {
2136  return true;
2137  }
2138  else
2139  {
2140  return false;
2141  }
2142  }
2143 
2144  } // ./class widget
2145 } // ./ namespace
$filename
Definition: actions.php:10
$name
Definition: add-comment.php:11
print $lang['FILEMAN_UPLOAD']
$data
Definition: stats.php:78
if(!isset($language)||(!isset($lang))) $item
$templateID
Definition: blog.php:9
static draw($type, $title, $text, $redirect, $delay)
Definition: alert.php:30
static getCurrentLanguageStatic()
returns the currently set backend language, but is static callable
Definition: language.php:146
static getSetting($db, $property)
Get and return value for property from settings database.
Definition: settings.php:470
static getLongSetting($db, $property)
Get and return longValue for property from settings database.
Definition: settings.php:527
The sys class - handles yawk's system core functions.
Definition: sys.php:17
static splitDate($date)
split a date to month, day, year and time
Definition: sys.php:1502
static minify($content)
Minify any string: removes spaces, tabs and linebreaks.
Definition: sys.php:528
static xcopy($source, $dest, $permissions=0755)
Copy a file, or recursively copy a folder and its contents.
Definition: sys.php:473
static getGroupId($db, $id, $table)
get requested group ID for given page ID (used in page-edit)
Definition: sys.php:1192
static minifyCSS($input)
Minify any string: removes spaces, tabs and linebreaks.
Definition: sys.php:614
static replacePreTags($replace, $customCSS)
removes all unnecessary HTML tags from custom.css
Definition: sys.php:799
static getWeekday($date, $lang)
return weekday from given date
Definition: sys.php:1735
static time_ago($userdate, $lang)
how many time is been gone since given date
Definition: sys.php:1630
static minifyHTML($input)
HTML Minifier - minify any string: removes spaces, tabstops and linebreaks.
Definition: sys.php:548
static recurseRmdir($dir)
remove a directory recurse
Definition: sys.php:1127
static generateRandomPassword($length)
Generate a random password with given length.
Definition: sys.php:314
static safeFileReWrite($fileName, $dataToSave)
Safe way to open a file and update data.
Definition: sys.php:2113
static read_recursive($path)
Read a directory recursively.
Definition: sys.php:381
static getSubMenu($db, $id)
get submenu ID for given page ID
Definition: sys.php:1300
static drawPhpInfo($lang)
Display a complete PHPinfo()
Definition: sys.php:164
static getDirPrefix($db)
if yawk is installed into a subdirectory, use this to get this prefix directory
Definition: sys.php:1104
static setTimeout($location, $wait)
set a timeout and force page reload via JS
Definition: sys.php:864
static outputObjects($template, $lang, $controller, $page, $user, $stats)
check if objects exists and display their data
Definition: sys.php:2068
static getLoadingTime($debugTime)
measure script loading time
Definition: sys.php:1076
static getMenuName($db, $id)
returns menu name for given menu ID
Definition: sys.php:1384
static full_copy($source, $target)
copy an entire folder including subdirectories
Definition: sys.php:694
static multiarray2lines($array, $property)
Display a multidimensional array line per line. Expects an array and property.
Definition: sys.php:257
static splitDateShort($date)
split a date to month, day, year and time this is the same as splitDate() but keep the months short
Definition: sys.php:1572
static minifyJs($input)
Minify any string: removes spaces, tabs and linebreaks.
Definition: sys.php:664
static getHost($db)
get hostname (url where yawk is installed) from database
Definition: sys.php:1115
static getRobotsText($db, $path)
Return the content of /robots.txt.
Definition: sys.php:334
static array2lines($array, $property)
Display a multidimensional array line per line. Expects an array and property.
Definition: sys.php:135
static iStatusToString($i, $on, $off)
convert a integer status to string variable (0|1) to online / offline
Definition: sys.php:729
static checkIfAssetsAreLoaded($db, $assets, $switch)
Check if assets are loaded, load if switch is true.
Definition: sys.php:26
static countCodeLines($path, $fileType)
Count code lines and output a small overview.
Definition: sys.php:425
static writeIniFile($array, $file)
write ini file
Definition: sys.php:2085
static addPreTags($customCSS)
THIS SEEMS OUTDATED - obviously not needed anymore....
Definition: sys.php:780
static addTrailingSlash($url)
sometimes it is necessary to add a slash to a url.
Definition: sys.php:1147
static getCurrentUserName()
returns the current user name, if set
Definition: sys.php:1284
static getMenuLanguage($db, $id)
returns menu language for given menu ID
Definition: sys.php:1405
static getBrowser($useragent)
extract browser from useragent
Definition: sys.php:911
static checkZlib()
Check if zlib is available.
Definition: sys.php:451
static getGroups($db, $table)
get all user groups from database
Definition: sys.php:1244
static getGroupFromId($db, $id, $table)
get requested group ID for given page ID
Definition: sys.php:1217
static replaceCarriageReturns($replace, $string)
replace all carriage returns with linebreaks
Definition: sys.php:770
static isBrowscapSet($useragent)
check if browscap file is set
Definition: sys.php:880
static getProperty($db, $property, $table, $id)
get any property from any table where id is given ID
Definition: sys.php:1165
static getMenuItem($db, $id)
get menu item for given page ID
Definition: sys.php:1329
static getBaseDir()
Return current base directory.
Definition: sys.php:304
static encodeChars($string)
convert german special chars and vowels into legal html
Definition: sys.php:1089
static parse_phpinfo()
Read phpinfo() into multidimensional array and return it.
Definition: sys.php:274
static getOS($useragent)
get operating system from useragent string
Definition: sys.php:1027
static now()
returns the current datetime
Definition: sys.php:1492
logMessage($message)
log message to debug_log.txt
Definition: sys.php:1834
static setRobotsText($path, $content)
Set the content of /robots.txt (overwrite)
Definition: sys.php:361
static getCurrentTemplateId(object $db)
return ID of current (active) template
Definition: template.php:73
if(!isset($db)) $id
$result
Definition: email-send.php:137
if(!isset($db)) $msg_id
exit
$type
$sql
Definition: message-new.php:32
$toUID
Definition: message-new.php:23
$fromUID
Definition: message-new.php:21
This class serves methods to create backup from files.
Definition: AdminLTE.php:2
$host
Definition: page-edit.php:65
print $_GET['id']
Definition: page-edit.php:357
if(!isset($page)) if(!isset($db)) if(!isset($lang)) if(isset($_GET['id'])) if(isset($_POST['save'])) $dirprefix
Definition: page-edit.php:63
$page
Definition: pages.php:355
$syslogCategories
print $tourdates date
$date
Definition: user-edit.php:285
$url
Definition: user-new.php:101
$value
$i
$useragent
Definition: yawk-stats.php:70