psf
 All Classes Functions Variables
functions.php
1 <?php
2 
3 //Part of simple php framework (spf)
4 
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 
15 // Copyright (c) Petr Bena <petr@bena.rocks> 2015 - 2017
16 
17 if (!defined("PSF_ENTRY_POINT"))
18  die("Not a valid psf entry point");
19 
20 require_once(dirname(__FILE__) . "/default_config.php");
21 require_once(dirname(__FILE__) . "/definitions.php");
22 require_once(dirname(__FILE__) . "/variables.php");
23 
24 // String tools
25 
27 function psf_string_startsWith($string, $text)
28 {
29  return (strpos($string, $text) === 0);
30 }
31 
33 function psf_string_endsWith($string, $text)
34 {
35  $length = strlen($text);
36  if ($length == 0)
37  return true;
38 
39  return (substr($string, -$length) === $text);
40 }
41 
43 function psf_string_contains($string, $text)
44 {
45  return strpos($string, $text) !== false;
46 }
47 
48 function psf_version()
49 {
50  return PSF_VERSION;
51 }
52 
53 function psf_path($file = '')
54 {
55  global $psf_home;
56  return $psf_home . $file;
57 }
58 
61 function psf_generate_friendly_name($text)
62 {
63  $text = str_replace(";", "", $text);
64  $text = str_replace("&", "", $text);
65  $text = str_replace("\"", "", $text);
66  $text = str_replace(">", "", $text);
67  $text = str_replace("<", "", $text);
68  $text = str_replace(" ", "_", $text);
69  $text = str_replace("(", "", $text);
70  $text = str_replace(")", "", $text);
71  $text = str_replace("/", "", $text);
72  $text = strtolower($text);
73  return $text;
74 }
75 
76 function psf_indent_text($text, $in)
77 {
78  global $psf_indent_system_enabled;
79  if (!$psf_indent_system_enabled)
80  return $text;
81  $prefix = '';
82  while ($in-- > 0)
83  $prefix .= " ";
84  $result = '';
85  $lines = explode("\n", $text);
86  foreach ($lines as $line)
87  $result .= $prefix . $line . "\n";
88  return $result;
89 }
90 
91 function _l($key)
92 {
93  return Localization::Get($key);
94 }
95 
96 function psf_string2bool($str)
97 {
98  $str = strtolower($str);
99  if ($str == "true")
100  return true;
101  if ($str == "t")
102  return true;
103  return false;
104 }
105 
106 function psf_curl($link, $timeout=5)
107 {
108  $ch = curl_init();
109  curl_setopt($ch, CURLOPT_URL, $link);
110  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
111  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
112  $data = curl_exec($ch);
113  curl_close($ch);
114  return $data;
115 }
116 
117 function psf_debug_log($text)
118 {
119  global $psf_global_debug_ring;
120  $psf_global_debug_ring[] = $text;
121 }
122 
123 function psf_print_debug_as_html()
124 {
125  global $psf_global_debug_ring;
126  $html = "";
127  foreach ($psf_global_debug_ring as $log)
128  $html .= "<!-- PSF Debug: " . htmlspecialchars($log) . " -->\n";
129  echo($html);
130 }
131 
133 function psf_get_execution_time()
134 {
135  global $psf_global_startup_time;
136  return (microtime(true) - $psf_global_startup_time);
137 }
138 
139