YaWK  24.1
Yet another WebKit
YAWK\sys Class Reference

The sys class - handles yawk's system core functions. More...

Public Member Functions

 logMessage ($message)
 log message to debug_log.txt More...
 

Static Public Member Functions

static addPreTags ($customCSS)
 THIS SEEMS OUTDATED - obviously not needed anymore.... More...
 
static addTrailingSlash ($url)
 sometimes it is necessary to add a slash to a url. More...
 
static array2lines ($array, $property)
 Display a multidimensional array line per line. Expects an array and property. More...
 
static checkIfAssetsAreLoaded ($db, $assets, $switch)
 Check if assets are loaded, load if switch is true. More...
 
static checkZlib ()
 Check if zlib is available. More...
 
static countCodeLines ($path, $fileType)
 Count code lines and output a small overview. More...
 
static drawPhpInfo ($lang)
 Display a complete PHPinfo() More...
 
static encodeChars ($string)
 convert german special chars and vowels into legal html More...
 
static full_copy ($source, $target)
 copy an entire folder including subdirectories More...
 
static generateRandomPassword ($length)
 Generate a random password with given length. More...
 
static getBaseDir ()
 Return current base directory. More...
 
static getBrowser ($useragent)
 extract browser from useragent More...
 
static getCurrentUserName ()
 returns the current user name, if set More...
 
static getDirPrefix ($db)
 if yawk is installed into a subdirectory, use this to get this prefix directory More...
 
static getGroupFromId ($db, $id, $table)
 get requested group ID for given page ID More...
 
static getGroupId ($db, $id, $table)
 get requested group ID for given page ID (used in page-edit) More...
 
static getGroups ($db, $table)
 get all user groups from database More...
 
static getHost ($db)
 get hostname (url where yawk is installed) from database More...
 
static getLoadingTime ($debugTime)
 measure script loading time More...
 
static getMenuItem ($db, $id)
 get menu item for given page ID More...
 
static getMenuLanguage ($db, $id)
 returns menu language for given menu ID More...
 
static getMenuName ($db, $id)
 returns menu name for given menu ID More...
 
static getOS ($useragent)
 get operating system from useragent string More...
 
static getProperty ($db, $property, $table, $id)
 get any property from any table where id is given ID More...
 
static getRobotsText ($db, $path)
 Return the content of /robots.txt. More...
 
static getSubMenu ($db, $id)
 get submenu ID for given page ID More...
 
static getWeekday ($date, $lang)
 return weekday from given date More...
 
static isBrowscapSet ($useragent)
 check if browscap file is set More...
 
static iStatusToString ($i, $on, $off)
 convert a integer status to string variable (0|1) to online / offline More...
 
static minify ($content)
 Minify any string: removes spaces, tabs and linebreaks. More...
 
static minifyCSS ($input)
 Minify any string: removes spaces, tabs and linebreaks. More...
 
static minifyHTML ($input)
 HTML Minifier - minify any string: removes spaces, tabstops and linebreaks. More...
 
static minifyJs ($input)
 Minify any string: removes spaces, tabs and linebreaks. More...
 
static multiarray2lines ($array, $property)
 Display a multidimensional array line per line. Expects an array and property. More...
 
static now ()
 returns the current datetime More...
 
static outputObjects ($template, $lang, $controller, $page, $user, $stats)
 check if objects exists and display their data More...
 
static parse_phpinfo ()
 Read phpinfo() into multidimensional array and return it. More...
 
static read_recursive ($path)
 Read a directory recursively. More...
 
static recurseRmdir ($dir)
 remove a directory recurse More...
 
static replaceCarriageReturns ($replace, $string)
 replace all carriage returns with linebreaks More...
 
static replacePreTags ($replace, $customCSS)
 removes all unnecessary HTML tags from custom.css More...
 
static safeFileReWrite ($fileName, $dataToSave)
 Safe way to open a file and update data. More...
 
static setRobotsText ($path, $content)
 Set the content of /robots.txt (overwrite) More...
 
static setTimeout ($location, $wait)
 set a timeout and force page reload via JS More...
 
static splitDate ($date)
 split a date to month, day, year and time More...
 
static splitDateShort ($date)
 split a date to month, day, year and time this is the same as splitDate() but keep the months short More...
 
static time_ago ($userdate, $lang)
 how many time is been gone since given date More...
 
static writeIniFile ($array, $file)
 write ini file More...
 
static xcopy ($source, $dest, $permissions=0755)
 Copy a file, or recursively copy a folder and its contents. More...
 

Detailed Description

The sys class - handles yawk's system core functions.

handles many of yawk's system core functions.

Most of them are static functions, like get and set paths, get ids, roles and so on.

Class covers both, backend & frontend functionality. See Methods Summary for Details!

Author
Daniel Retzl danie.nosp@m.lret.nosp@m.zl@gm.nosp@m.ail..nosp@m.com
Version
1.0.0

Definition at line 16 of file sys.php.

Member Function Documentation

◆ addPreTags()

static YAWK\sys::addPreTags (   $customCSS)
static

THIS SEEMS OUTDATED - obviously not needed anymore....

Parameters
string$customCSS
Returns
string

Definition at line 780 of file sys.php.

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  }

References $customCSS.

◆ addTrailingSlash()

static YAWK\sys::addTrailingSlash (   $url)
static

sometimes it is necessary to add a slash to a url.

Parameters
string$urlthe url were the slash needs to be added
Returns
string return url containing the slash

Definition at line 1147 of file sys.php.

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  }
$url
Definition: user-new.php:101

References $url.

Referenced by YAWK\sys\getHost().

◆ array2lines()

static YAWK\sys::array2lines (   $array,
  $property 
)
static

Display a multidimensional array line per line. Expects an array and property.

Author
Daniel Retzl danie.nosp@m.lret.nosp@m.zl@gm.nosp@m.ail..nosp@m.com
Version
1.0.0

Definition at line 135 of file sys.php.

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  }
if(!isset($language)||(!isset($lang))) $item

References $item.

Referenced by YAWK\sys\drawPhpInfo().

◆ checkIfAssetsAreLoaded()

static YAWK\sys::checkIfAssetsAreLoaded (   $db,
  $assets,
  $switch 
)
static

Check if assets are loaded, load if switch is true.

Parameters
$dbobject Database object
$assetsarray Required assets as array
$switchbool true|false If true, required assset gets loaded if not
Returns
mixed

This methods checks if given assets are loaded and load them on demand

Definition at line 26 of file sys.php.

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  }
$templateID
Definition: blog.php:9
static getCurrentTemplateId(object $db)
return ID of current (active) template
Definition: template.php:73
$type

References $db, $res, $templateID, $type, and YAWK\template\getCurrentTemplateId().

◆ checkZlib()

static YAWK\sys::checkZlib ( )
static

Check if zlib is available.

Returns
bool

Definition at line 451 of file sys.php.

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  }

◆ countCodeLines()

static YAWK\sys::countCodeLines (   $path,
  $fileType 
)
static

Count code lines and output a small overview.

Parameters
object$dbdatabase object
string$paththe full path (including base path)
string$fileTypefile type with leading dot, for example: '.php'
Returns
mixed array

Definition at line 425 of file sys.php.

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  }
$data
Definition: stats.php:78
static read_recursive($path)
Read a directory recursively.
Definition: sys.php:381
$value

References $data, $value, and YAWK\sys\read_recursive().

◆ drawPhpInfo()

static YAWK\sys::drawPhpInfo (   $lang)
static

Display a complete PHPinfo()

Parameters
$lang

Definition at line 164 of file sys.php.

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  }
static array2lines($array, $property)
Display a multidimensional array line per line. Expects an array and property.
Definition: sys.php:135
static parse_phpinfo()
Read phpinfo() into multidimensional array and return it.
Definition: sys.php:274

References $data, YAWK\sys\array2lines(), and YAWK\sys\parse_phpinfo().

◆ encodeChars()

static YAWK\sys::encodeChars (   $string)
static

convert german special chars and vowels into legal html

Parameters
string$stringto encode
Returns
string return encoded string

Definition at line 1089 of file sys.php.

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  }

Referenced by YAWK\page\create(), and YAWK\menu\createMenu().

◆ full_copy()

static YAWK\sys::full_copy (   $source,
  $target 
)
static

copy an entire folder including subdirectories

Parameters
string$sourcesource directory
string$targettarget directory

copy an entire folder into another location

Definition at line 694 of file sys.php.

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  }
static full_copy($source, $target)
copy an entire folder including subdirectories
Definition: sys.php:694

◆ generateRandomPassword()

static YAWK\sys::generateRandomPassword (   $length)
static

Generate a random password with given length.

Parameters
int$lengthlength of the password you wish to return
Returns
string

Definition at line 314 of file sys.php.

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  }

References $password.

◆ getBaseDir()

static YAWK\sys::getBaseDir ( )
static

Return current base directory.

Returns
string

Definition at line 304 of file sys.php.

305  {
306  return substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'],basename($_SERVER['SCRIPT_NAME'])));
307  }

Referenced by YAWK\installer\step3(), and YAWK\installer\step4().

◆ getBrowser()

static YAWK\sys::getBrowser (   $useragent)
static

extract browser from useragent

Parameters
string$useragentthe full useragent
Returns
array array with useragent, browser, version and platform

Definition at line 911 of file sys.php.

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  }
$i
$useragent
Definition: yawk-stats.php:70

References $i, and $useragent.

Referenced by YAWK\stats\prepareData().

◆ getCurrentUserName()

static YAWK\sys::getCurrentUserName ( )
static

returns the current user name, if set

Returns
string

Definition at line 1284 of file sys.php.

1285  {
1286  if (isset($_SESSION['username'])) {
1287  return $_SESSION['username'];
1288  }
1289  else {
1290  return "Gast";
1291  }
1292  }

Referenced by YAWK\menu\drawLogoutMenu().

◆ getDirPrefix()

static YAWK\sys::getDirPrefix (   $db)
static

if yawk is installed into a subdirectory, use this to get this prefix directory

Parameters
object$dbdatabase
Returns
string return the directory prefix

Definition at line 1104 of file sys.php.

1105  { // returns directory prefix from settings
1106  $dirprefix = settings::getSetting($db, "dirprefix");
1107  return $dirprefix;
1108  }
static getSetting($db, $property)
Get and return value for property from settings database.
Definition: settings.php:470
if(!isset($page)) if(!isset($db)) if(!isset($lang)) if(isset($_GET['id'])) if(isset($_POST['save'])) $dirprefix
Definition: page-edit.php:63

References $db, $dirprefix, and YAWK\settings\getSetting().

Referenced by YAWK\widget\getCurrentWidgetPath().

◆ getGroupFromId()

static YAWK\sys::getGroupFromId (   $db,
  $id,
  $table 
)
static

get requested group ID for given page ID

Parameters
object$dbdatabase
string$idpage ID
string$tablethe table to select from
Returns
string|bool return the group ID or false
Parameters
$db\YAWK\db $res

Definition at line 1217 of file sys.php.

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  }
static draw($type, $title, $text, $redirect, $delay)
Definition: alert.php:30

References $db, $res, and YAWK\alert\draw().

◆ getGroupId()

static YAWK\sys::getGroupId (   $db,
  $id,
  $table 
)
static

get requested group ID for given page ID (used in page-edit)

Parameters
object$dbdatabase
string$idpage ID
string$tablethe table to select from
Returns
string|bool return the group ID or false
Parameters
$db\YAWK\db $res

Definition at line 1192 of file sys.php.

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  }

References $db, $res, and YAWK\alert\draw().

◆ getGroups()

static YAWK\sys::getGroups (   $db,
  $table 
)
static

get all user groups from database

Parameters
object$dbdatabase
string$tablethe table to select from
Returns
array|bool|string
Parameters
$db\YAWK\db $res

Definition at line 1244 of file sys.php.

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  }

References $db, and $res.

◆ getHost()

static YAWK\sys::getHost (   $db)
static

get hostname (url where yawk is installed) from database

Parameters
object$dbdatabase
Returns
bool|string

Definition at line 1115 of file sys.php.

1116  { // get host from settings db
1117  $hostname = settings::getSetting($db, "host");
1118  $hostname = self::addTrailingSlash($hostname);
1119  return $hostname;
1120  }
static addTrailingSlash($url)
sometimes it is necessary to add a slash to a url.
Definition: sys.php:1147

References $db, YAWK\sys\addTrailingSlash(), and YAWK\settings\getSetting().

Referenced by YAWK\PLUGINS\MESSAGES\messages\__construct(), and YAWK\user\sendResetEmail().

◆ getLoadingTime()

static YAWK\sys::getLoadingTime (   $debugTime)
static

measure script loading time

Parameters
string$debugTimestarting time
Returns
string return formated time in milliseconds

Definition at line 1076 of file sys.php.

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  }

◆ getMenuItem()

static YAWK\sys::getMenuItem (   $db,
  $id 
)
static

get menu item for given page ID

Parameters
object$dbdatabase
int$idpage ID
Returns
bool
Parameters
$db\YAWK\db $res

Definition at line 1329 of file sys.php.

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  }

References $db, and $res.

◆ getMenuLanguage()

static YAWK\sys::getMenuLanguage (   $db,
  $id 
)
static

returns menu language for given menu ID

Parameters
object$dbdatabase
int$idmenu ID
Returns
bool
Parameters
$db\YAWK\db $res

Definition at line 1405 of file sys.php.

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  }

References $db, and $res.

◆ getMenuName()

static YAWK\sys::getMenuName (   $db,
  $id 
)
static

returns menu name for given menu ID

Parameters
object$dbdatabase
int$idmenu ID
Returns
bool
Parameters
$db\YAWK\db $res

Definition at line 1384 of file sys.php.

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  }

References $db, and $res.

◆ getOS()

static YAWK\sys::getOS (   $useragent)
static

get operating system from useragent string

Parameters
string$useragentfull useragent string
Returns
mixed|string return string containing the OS (platform)

Definition at line 1027 of file sys.php.

1027  {
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  }

References $useragent, and $value.

Referenced by YAWK\stats\prepareData().

◆ getProperty()

static YAWK\sys::getProperty (   $db,
  $property,
  $table,
  $id 
)
static

get any property from any table where id is given ID

Parameters
object$dbdatabase
string$propertywhat to select (field)
string$tablefrom wich (table)
string$idwhere id = (id)
Returns
bool
Parameters
$db\YAWK\db $res

Definition at line 1165 of file sys.php.

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  }
if(!isset($db)) $id

References $db, $id, and $res.

◆ getRobotsText()

static YAWK\sys::getRobotsText (   $db,
  $path 
)
static

Return the content of /robots.txt.

Parameters
string$pathabsolute path to the robots.txt file
Returns
string|bool

Definition at line 334 of file sys.php.

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  }
static getLongSetting($db, $property)
Get and return longValue for property from settings database.
Definition: settings.php:527
This class serves methods to create backup from files.
Definition: AdminLTE.php:2

References $db, and YAWK\settings\getLongSetting().

◆ getSubMenu()

static YAWK\sys::getSubMenu (   $db,
  $id 
)
static

get submenu ID for given page ID

Parameters
object$dbdatabase
string$idpage ID
Returns
mixed string|int
Parameters
$db\YAWK\db $res

Definition at line 1300 of file sys.php.

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  }

References $db, and $res.

◆ getWeekday()

static YAWK\sys::getWeekday (   $date,
  $lang 
)
static

return weekday from given date

Parameters
string$datethe date to calculate
Returns
bool|false|string

Definition at line 1735 of file sys.php.

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  }
print $lang['FILEMAN_UPLOAD']
print $tourdates date
$date
Definition: user-edit.php:285

References $date, $lang, and date.

Referenced by YAWK\stats\countWeekdays().

◆ isBrowscapSet()

static YAWK\sys::isBrowscapSet (   $useragent)
static

check if browscap file is set

Parameters
string$useragentfull useragent
Returns
bool|null

Definition at line 880 of file sys.php.

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  }

References $useragent, and YAWK\alert\draw().

◆ iStatusToString()

static YAWK\sys::iStatusToString (   $i,
  $on,
  $off 
)
static

convert a integer status to string variable (0|1) to online / offline

Parameters
int$ithe status var
string$onstring for status 1 (online, published...)
string$offstring for status 0 (offline, not published...)
Returns
bool|string return the converted string or false

Definition at line 729 of file sys.php.

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  }

References $i.

Referenced by YAWK\menu\toggleItemOffline(), YAWK\menu\toggleOffline(), and YAWK\page\toggleOffline().

◆ logMessage()

YAWK\sys::logMessage (   $message)

log message to debug_log.txt

this function is used to log any given messages to debug_log.txt

Parameters
$message
Returns
void

Definition at line 1834 of file sys.php.

1834  {
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  }

References date.

◆ minify()

static YAWK\sys::minify (   $content)
static

Minify any string: removes spaces, tabs and linebreaks.

Parameters
string$content
Returns
mixed

minify data

Definition at line 528 of file sys.php.

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  }

References $content.

◆ minifyCSS()

static YAWK\sys::minifyCSS (   $input)
static

Minify any string: removes spaces, tabs and linebreaks.

Author
Rodrigo54
Version
1.0.0 string $input the CSS string to minify mixed CSS Minifier => http://ideone.com/Q5USEF + improvement(s)

Definition at line 614 of file sys.php.

614  {
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  }

Referenced by YAWK\sys\minifyHTML().

◆ minifyHTML()

static YAWK\sys::minifyHTML (   $input)
static

HTML Minifier - minify any string: removes spaces, tabstops and linebreaks.

Author
Rodrigo54
Version
1.0.0 string $input the CSS string to minify mixed Based on https://github.com/mecha-cms/mecha-cms/blob/master/system/kernel/converter.php

Definition at line 548 of file sys.php.

548  {
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  }
static minifyCSS($input)
Minify any string: removes spaces, tabs and linebreaks.
Definition: sys.php:614
static minifyJs($input)
Minify any string: removes spaces, tabs and linebreaks.
Definition: sys.php:664

References YAWK\sys\minifyCSS(), and YAWK\sys\minifyJs().

◆ minifyJs()

static YAWK\sys::minifyJs (   $input)
static

Minify any string: removes spaces, tabs and linebreaks.

Author
Rodrigo54
Version
1.0.0 string $input the JS string to minify mixed

Definition at line 664 of file sys.php.

664  {
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  }

Referenced by YAWK\sys\minifyHTML().

◆ multiarray2lines()

static YAWK\sys::multiarray2lines (   $array,
  $property 
)
static

Display a multidimensional array line per line. Expects an array and property.

Author
Daniel Retzl danie.nosp@m.lret.nosp@m.zl@gm.nosp@m.ail..nosp@m.com
Version
1.0.0 bool

Definition at line 257 of file sys.php.

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  }

References $item.

◆ now()

static YAWK\sys::now ( )
static

returns the current datetime

Returns
string datetime Y-m-d H:i:s

Definition at line 1492 of file sys.php.

1493  { // return current datetime in mysql format
1494  return date("Y-m-d H:i:s");
1495  }

References date.

Referenced by YAWK\template\downloadTemplate(), YAWK\stats\prepareData(), YAWK\template\saveAs(), and YAWK\BACKUP\FILES\fileBackup\setBackupSettings().

◆ outputObjects()

static YAWK\sys::outputObjects (   $template,
  $lang,
  $controller,
  $page,
  $user,
  $stats 
)
static

check if objects exists and display their data

Definition at line 2068 of file sys.php.

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  }
exit

References exit.

◆ parse_phpinfo()

static YAWK\sys::parse_phpinfo ( )
static

Read phpinfo() into multidimensional array and return it.

Author
Ray Chang
Version
1.0.0 array phpinfo() data as multidimensional array

Definition at line 274 of file sys.php.

274  {
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  }
$name
Definition: add-comment.php:11

References $i, and $name.

Referenced by YAWK\sys\drawPhpInfo().

◆ read_recursive()

static YAWK\sys::read_recursive (   $path)
static

Read a directory recursively.

Parameters
string$pathfull path e.g. /xampp/htdocs/yawk-LTE/
Returns
array

Definition at line 381 of file sys.php.

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  }
$result
Definition: email-send.php:137

References $name, $result, and $value.

Referenced by YAWK\sys\countCodeLines().

◆ recurseRmdir()

static YAWK\sys::recurseRmdir (   $dir)
static

remove a directory recurse

Parameters
string$dirthe directory to delete
Returns
bool

Definition at line 1127 of file sys.php.

1127  {
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  }

Referenced by YAWK\BACKUP\FILES\fileBackup\doFolderBackup(), and YAWK\BACKUP\backup\doRestore().

◆ replaceCarriageReturns()

static YAWK\sys::replaceCarriageReturns (   $replace,
  $string 
)
static

replace all carriage returns with linebreaks

Parameters
string$replacesearchstring
string$stringreplacestring
Returns
string

Definition at line 770 of file sys.php.

771  {
772  return str_replace(array("\n\r", "\n", "\r"), $replace, $string);
773  }

◆ replacePreTags()

static YAWK\sys::replacePreTags (   $replace,
  $customCSS 
)
static

removes all unnecessary HTML tags from custom.css

Parameters
string$replace
string$customCSS
Returns
string

Definition at line 799 of file sys.php.

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  }

References $customCSS.

◆ safeFileReWrite()

static YAWK\sys::safeFileReWrite (   $fileName,
  $dataToSave 
)
static

Safe way to open a file and update data.

Parameters
$fileName
$dataToSave
Returns
bool

Definition at line 2113 of file sys.php.

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  }

◆ setRobotsText()

static YAWK\sys::setRobotsText (   $path,
  $content 
)
static

Set the content of /robots.txt (overwrite)

Parameters
string$pathabsolute path to the robots.txt file
string$contentfile content to write in robots.txt
Returns
bool

Definition at line 361 of file sys.php.

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  }
$filename
Definition: actions.php:10

References $filename.

◆ setTimeout()

static YAWK\sys::setTimeout (   $location,
  $wait 
)
static

set a timeout and force page reload via JS

Parameters
string$locationthe url to redirect
int$waitthe time in ms to wait before redirect
Returns
bool

Definition at line 864 of file sys.php.

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  }

Referenced by YAWK\installer\step5().

◆ splitDate()

static YAWK\sys::splitDate (   $date)
static

split a date to month, day, year and time

Parameters
string$datethe date to split
Returns
array return an array w single items

Definition at line 1502 of file sys.php.

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  }

References $date.

Referenced by YAWK\BACKEND\AdminLTE\drawHtmlNavbarUserAccountMenu().

◆ splitDateShort()

static YAWK\sys::splitDateShort (   $date)
static

split a date to month, day, year and time this is the same as splitDate() but keep the months short

Parameters
string$datethe date to split
Returns
array return an array w single items

Definition at line 1572 of file sys.php.

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  }

References $date.

Referenced by YAWK\PLUGINS\MESSAGES\messages\MessageView().

◆ time_ago()

static YAWK\sys::time_ago (   $userdate,
  $lang 
)
static

how many time is been gone since given date

Parameters
string$userdatedate to calculate
array$langlanguage array
Returns
string return how many time has gone since $userdate

Definition at line 1630 of file sys.php.

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  }
static getCurrentLanguageStatic()
returns the currently set backend language, but is static callable
Definition: language.php:146

References $date, $lang, and YAWK\language\getCurrentLanguageStatic().

Referenced by YAWK\BACKEND\AdminLTE\drawHtmlNavbarMessagesMenu(), YAWK\BACKEND\AdminLTE\drawHtmlNavbarNotificationsMenu(), YAWK\BACKEND\AdminLTE\drawHtmlNavbarWebmailMenu(), YAWK\BACKEND\dashboard\drawLatestPagesBox(), YAWK\BACKEND\dashboard\drawLatestUsers(), and YAWK\PLUGINS\MESSAGES\messages\MessageView().

◆ writeIniFile()

static YAWK\sys::writeIniFile (   $array,
  $file 
)
static

write ini file

Parameters
$array
$file
Returns
bool

Definition at line 2085 of file sys.php.

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  }

References $res.

Referenced by YAWK\BACKUP\FILES\fileBackup\doFolderBackup(), YAWK\template\downloadTemplate(), and YAWK\BACKUP\backup\setIniFile().

◆ xcopy()

static YAWK\sys::xcopy (   $source,
  $dest,
  $permissions = 0755 
)
static

Copy a file, or recursively copy a folder and its contents.

Author
Aidan Lister aidan.nosp@m.@php.nosp@m..net
Version
1.0.1 string $source Source path string $dest Destination path int $permissions New folder creation permissions bool Returns true on success, false on failure

Definition at line 473 of file sys.php.

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  }

Referenced by YAWK\BACKUP\FILES\fileBackup\copyFolder(), YAWK\BACKUP\backup\doRestore(), YAWK\template\downloadTemplate(), YAWK\template\saveAs(), and YAWK\template\uploadTemplate().


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