YaWK  24.1
Yet another WebKit
template.php
Go to the documentation of this file.
1 <?php
2 namespace YAWK {
3  /**
4  * @details Template controller - get and set template settings.
5  *
6  * Templates itself are located in /system/templates/ - if you want to modify them, start there.
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-2022 Daniel Retzl
12  * @license https://opensource.org/licenses/MIT
13  * @brief The template controller - get and set template settings.
14  */
15  class template
16  {
17  /** * @param int template ID */
18  public $id;
19  /** * @param int new TPL ID (latest template) */
20  public $newId;
21  /** * @param int 0|1 is this template active? */
22  public $active;
23  /** * @param string template name */
24  public $name;
25  /** * @param string new template name */
26  public $newTplName;
27  /** * @param array db config array */
28  public $config;
29  /** * @param string template folder (root path of all templates) */
30  public $folder = '../system/templates/';
31  /** * @param string template tmp folder (where uploads will be unpacked) */
32  public $tmpFolder = '../system/templates/tmp/';
33  /** * @param string upload file (including complete path) */
34  public $uploadFile = '';
35  /** * @param string template sub folder (template name, eg. ../system/templates/SUBFOLDER */
36  public $subFolder;
37  /** * @param string positions as string */
38  public $positions;
39  /** * @param string template description */
40  public $description;
41  /** * @param string datetime when this template was released */
42  public $releaseDate;
43  /** * @param string author of this template */
44  public $author;
45  /** * @param string author's url */
46  public $authorUrl;
47  /** * @param string weblink to this template */
48  public $weblink;
49  /** * @param string sub-author who has modified the template */
50  public $subAuthor = '';
51  /** * @param string sub-author's url */
52  public $subAuthorUrl = '';
53  /** * @param string datetime when this template was modified */
54  public $modifyDate;
55  /** * @param string template's version number */
56  public $version;
57  /** * @param string the current loaded Bootstrap version */
59  /** * @param string required framework for this template */
60  public $framework = 'bootstrap4';
61  /** * @param string template's license */
62  public $license;
63  /** * @param int which template is currently set to active? */
64  public int $selectedTemplate;
65  /** * @param string path to custom fonts (ttf|otf|woff) */
66  public string $ttfPath = '../system/fonts/';
67 
68  /**
69  * @brief return ID of current (active) template
70  * @param object $db database object
71  * @return int the ID of the currently selected template
72  */
73  static function getCurrentTemplateId(object $db): int
74  { // return value of property selectedTemplate from settings db
75  // outdated: return \YAWK\settings::getSetting($db, "selectedTemplate");
76 
77  if (!isset($user)){
78  $user = new user($db);
79  }
80  if (!isset($template)){
81  $template = new template();
82  }
83 
84  // since user can override his template, there are more specific checks needed,
85  // which template is currently active and which ID we will return. To do that:
86  return template::getValidTemplateID($db, $user, $template);
87  }
88 
89  /**
90  * @brief Check if a template with given name already exists, return true or false
91  * @param object $db
92  * @param string $name
93  * @return bool true|false
94  */
95  public function checkIfTemplateAlreadyExists(object $db, string $name): bool
96  {
97  // check if name is set, not empty and valid type
98  if (isset($name) && (!empty($name) && (is_string($name))))
99  {
100  // strip unwanted code
101  $name = strip_tags($name);
102 
103  // check if template is already in database
104  $result = $db->query("SELECT name FROM {templates} WHERE name = '".$name."'");
105  // if there are no rows
106  if($result->num_rows == 0)
107  { // template not found in database...
108  sys::setSyslog($db, 45, 0, "template $name not found in database", 0, 0, 0, 0);
109  return false;
110  }
111  else
112  { // template exists in database
113  sys::setSyslog($db, 45, 0, "template $name updated", 0, 0, 0, 0);
114  return true;
115  }
116  }
117  else
118  { // template param not set, empty or wrong type
119  sys::setSyslog($db, 45, 0, "template param $name not set or wrong type", 0, 0, 0, 0);
120  return false;
121  }
122  }
123 
124  /**
125  * @brief switch all positions indicators on or off
126  * @param int $templateID ID of the affected template
127  * @param int $status value to set (0|1)
128  * @param object $db
129  * @return bool true|false
130  */
131  public function switchPositionIndicators(object $db, int $templateID, int $status): bool
132  {
133  // if template param is not set
134  if (!isset($templateID) || (!is_numeric($templateID))) { // get current active template ID
136  }
137 
138  // if status parameter is not set
139  if (!isset($status) || (!is_numeric($status))) { // turn off is default behaviour
140  $status = 0;
141  }
142 
143  // update position indicator status
144  if ($db->query("UPDATE {template_settings}
145  SET value = '" . $status . "'
146  WHERE property
147  LIKE '%indicator%'
148  AND templateID = '" . $templateID . "'")
149  ) { // all good,
150  return true;
151  } else { // update position indicators failed
152  return false;
153  }
154  }
155 
156  /**
157  * @brief fetch positions of current (active) template, explode string and return positions array
158  * @param object $db
159  * @return array|bool
160  */
161  static function getTemplatePositions(object $db)
162  {
163  /** @var $db \YAWK\db */
164  $res = '';
165  // fetch template id
166  $tpl_id = settings::getSetting($db, "selectedTemplate");
167  // fetch template positions
168  if ($res = $db->query("SELECT positions
169  FROM {templates}
170  WHERE id = '" . $tpl_id . "'")
171  ) { // fetch data
172  $posArray = array();
173  while ($row = $res->fetch_assoc()) {
174  $posArray[] = $row;
175  }
176  $pos = $posArray[0]['positions'];
177  // explode string into array + return
178  $positions = explode(':', $pos);
179  // return tpl positions
180  return $positions;
181  } else {
182  // q failed
183  sys::setSyslog($db, 47, 1, "failed to get template positions of template id: <b>$tpl_id</b> ", 0, 0, 0, 0);
184  return false;
185  }
186  }
187 
188  /**
189  * @brief save a template as new. It copies the tpl folder and all settings into a new one.
190  * @param object $db
191  * @param object $template
192  * @param string $new_template
193  * @param string $description
194  * @param string $author
195  * @param string $authorUrl
196  * @param string $weblink
197  * @param string $version
198  * @param string $license
199  * @return bool
200  */
201  public function saveAs(object $db): bool
202  {
203  /** @param \YAWK\db $db */
204  // prepare vars
205  $replace = array("/ä/", "/ü/", "/ö/", "/Ä/", "/Ü/", "/Ö/", "/ß/"); // array of special chars
206  $chars = array("ae", "ue", "oe", "Ae", "Ue", "Oe", "ss"); // array of replacement chars
207  $this->newTplName = preg_replace($replace, $chars, $this->newTplName); // replace with preg
208  // final check: just numbers and chars are allowed
209  $this->newTplName = preg_replace("/[^a-z0-9\-\/]/i", "", $this->newTplName);
210  // same goes on for $template->name
211  $this->name = preg_replace($replace, $chars, $this->name); // replace with preg
212  // final check: just numbers and chars are allowed
213  $this->name = preg_replace("/[^a-z0-9\-\/]/i", "", $this->name);
214  // get current timestamp
215  $now = sys::now();
216 
217  // copy new template into database
218  if ($res = $db->query("INSERT INTO {templates} (name, positions, description, releaseDate, author, authorUrl, weblink, subAuthor, subAuthorUrl, modifyDate, version, framework, license)
219  VALUES('" . $this->newTplName . "',
220  '" . $this->positions . "',
221  '" . $this->description . "',
222  '" . $now . "',
223  '" . $this->author . "',
224  '" . $this->authorUrl . "',
225  '" . $this->weblink . "',
226  '" . $this->subAuthor ."',
227  '" . $this->subAuthorUrl ."',
228  '" . $now . "',
229  '" . $this->version . "',
230  '" . $this->framework . "',
231  '" . $this->license . "')"))
232  {
233 
234  }
235  else
236  { // q failed, throw error
237  sys::setSyslog($db, 47, 1, "failed to save <b>$this->newTplName</b> as new template", 0, 0, 0, 0);
238  // \YAWK\alert::draw("warning", "Warning!", "Could not insert your template $new_template into database.", "", 6200);
239  return false;
240  }
241  // tpl added to database successful
242  // check if template folder exists
243  if (is_dir(dirname("../system/templates/$this->name")))
244  {
245  // ok, start to copy template from source to new destination
246  sys::xcopy("../system/templates/$this->name", "../system/templates/$this->newTplName");
247  sys::setSyslog($db, 47, 1, "copy template folder from ../system/templates/$this->name to ../system/templates/$this->newTplName", 0, 0, 0, 0);
248  return true;
249  }
250  else
251  { // template folder does not exist
252  // what should we copy if nothing exists?
253  sys::setSyslog($db, 47, 1, "failed to copy template - template name $this->name does not exist", 0, 0, 0, 0);
254  return false;
255  }
256  }
257 
258  /**
259  * @brief load properties into template object
260  * @param object $db database object
261  * @param int $id template id to load
262  * @return bool true or false
263  */
264  public function loadProperties($db, $id)
265  {
266  /** @param $db \YAWK\db $res */
267  $res = $db->query("SELECT * FROM {templates} WHERE id = '" . $id . "'");
268  if ($row = mysqli_fetch_assoc($res)) {
269  $this->id = $row['id'];
270  $this->active = $row['active'];
271  $this->name = $row['name'];
272  $this->positions = $row['positions'];
273  $this->description = $row['description'];
274  $this->releaseDate = $row['releaseDate'];
275  $this->author = $row['author'];
276  $this->authorUrl = $row['authorUrl'];
277  $this->weblink = $row['weblink'];
278  $this->subAuthor = $row['subAuthor'];
279  $this->subAuthorUrl = $row['subAuthorUrl'];
280  $this->modifyDate = $row['modifyDate'];
281  $this->version = $row['version'];
282  $this->framework = $row['framework'];
283  $this->license = $row['license'];
284  $this->selectedTemplate = settings::getSetting($db, "selectedTemplate");
285  return true;
286  } else { // could not fetch tpl properties, throw error...
287  sys::setSyslog($db, 47, 1, "failed to load properties of template <b>$this->name</b> (id: <b>$id</b>)", 0, 0, 0, 0);
288  // \YAWK\alert::draw("danger", "Warning!", "Could not fetch template properties. Expect a buggy view.", "", 3000);
289  return false;
290  }
291  }
292 
293 
294  /**
295  * @brief load template properties and return as array
296  * @param object $db database object
297  * @param int $id template id to load
298  * @return bool|array true or false
299  */
300  public function loadPropertiesIntoArray(object $db, int $id)
301  {
302  /** @param $db \YAWK\db $res */
303  $res = $db->query("SELECT * FROM {templates} WHERE id = '" . $id . "'");
304  if ($row = mysqli_fetch_assoc($res))
305  {
306  if (!is_array($row) || (empty($row)))
307  { // not an array or empty...
308  return false;
309  }
310  else
311  { // return array
312  return $row;
313  }
314  }
315  else
316  { // could not fetch tpl properties, throw error...
317  sys::setSyslog($db, 47, 1, "failed to load properties of template id <b>$id</b> into array", 0, 0, 0, 0);
318  return false;
319  }
320  }
321 
322  /**
323  * @brief load template settings of ID and return as array
324  * @param object $db database object
325  * @param int $id template id to load
326  * @return array|false
327  */
328  public function loadAllSettingsIntoArray(object $db, int $id)
329  {
330  /** @param $db \YAWK\db $res */
331  $res = $db->query("SELECT * FROM {template_settings} WHERE templateID = '" . $id . "'");
332  while ($row = mysqli_fetch_assoc($res))
333  {
334  $templateSettings[] = $row;
335  }
336 
337  if (isset($templateSettings) && (is_array($templateSettings) && (!empty($templateSettings))))
338  { // not an array or empty...
339  return $templateSettings;
340  }
341  else
342  { // could not fetch tpl properties, throw error...
343  sys::setSyslog($db, 47, 1, "failed to load template_settings of template id <b>$id</b> into array", 0, 0, 0, 0);
344  return false;
345  }
346  }
347 
348  /**
349  * @brief save new template properties into database
350  * @param object $db database object
351  * @param int $id template id to save
352  * @param array $data post data from form (new settings)
353  * @param array $oldTplSettings template settings array (old settings)
354  * @return bool true or false
355  */
356  public function saveProperties(object $db, int $id, array $data, array $oldTplSettings): bool
357  {
358  // check if data is set set
359  if (!isset($data) || (!isset($id))) { // if not, abort
360  return false;
361  }
362  if (empty($oldTplSettings))
363  {
364  $oldTplSettings = array();
365  }
366 
367  // walk through all post data settings
368  foreach ($data as $property => $value)
369  {
370  // check, if settings is a long value
371  if (fnmatch('*-longValue', $property))
372  { // it is, set long value indicator to true
373  $longValue = 1;
374  }
375  else
376  { // not a long value
377  $longValue = 0;
378  }
379 
380  // save this property only if its NOT save or customcss
381  if ($property != "save" && ($property != "customCSS") && ($property != "testText")) {
382  if (isset($oldTplSettings[$property]) && ($oldTplSettings[$property]) === $value)
383  { // if old settings and new settings are the same
384  // do nothing
385  }
386  else
387  { // update template setting
388  $this->setTemplateSetting($db, $id, $property, $value, $longValue);
389  }
390  }
391  }
392  return true;
393  }
394 
395 
396  /**
397  * @brief load template_settings_types and return as array
398  * @param object $db database object
399  * @return array|false
400  */
401  public function loadSettingsTypesIntoArray(object $db)
402  {
403  /** @param $db \YAWK\db $res */
404  $res = $db->query("SELECT * FROM {template_settings_types}");
405  while ($row = mysqli_fetch_assoc($res))
406  {
407  $settingsTypes[] = $row;
408  }
409  if (isset($settingsTypes) && (is_array($settingsTypes) && (!empty($settingsTypes))))
410  { // all good,
411  return $settingsTypes;
412  }
413  else
414  { // could not fetch tpl properties, throw error...
415  sys::setSyslog($db, 47, 1, "failed to load template_settings_types into array", 0, 0, 0, 0);
416  return false;
417  }
418  }
419 
420 
421  /**
422  * @brief return array with all template id's + names.
423  * @param object $db database
424  * @return array|bool
425  */
426  static function getTemplateIds(object $db)
427  {
428  /** @param \YAWK\db $db */
429  // returns an array with all template IDs
430  $mysqlRes = $db->query("SELECT id, name
431  FROM {templates}
432  ORDER by name ASC");
433  while ($row = mysqli_fetch_assoc($mysqlRes)) {
434  $res[] = $row;
435  }
436  if (!empty($res)) { // yey, return array
437  return $res;
438  } else { // could not fetch array
439  sys::setSyslog($db, 47, 1, "failed get template id and name ", 0, 0, 0, 0);
440  return false;
441  }
442  }
443 
444  /**
445  * @brief count and return how many settings got this: template ID
446  * @param object $db database
447  * @param int $templateID affected template ID
448  * @return int the number of settings for this template
449  */
450  static function countTemplateSettings(object $db, int $templateID): int
451  {
452  /** @var $db \YAWK\db */
453  // count + return settings from given tpl ID
454  $res = $db->query("SELECT id FROM {template_settings}
455  WHERE templateID = '" . $templateID . "'");
456  return mysqli_num_rows($res);
457  }
458 
459  /**
460  * @brief return template name for given ID
461  * @param object $db database
462  * @param int $templateID affected template ID
463  * @return string|null
464  */
465  public static function getTemplateNameById(object $db, int $templateID): ?string
466  {
467  /** @var $db \YAWK\db */
468  if (!isset($templateID) || (empty($templateID))) { // template id is not set, try to get current template
469  $templateID = settings::getSetting($db, "selectedTemplate");
470  }
471  // query template name
472  if ($res = $db->query("SELECT name from {templates} WHERE id = $templateID")) { // fetch data
473  if ($row = mysqli_fetch_row($res)) { // return current name
474  return $row[0];
475  }
476  } else { // exit and throw error
477  sys::setSyslog($db, 47, 1, "failed to get template name by id <b>$templateID</b> ", 0, 0, 0, 0);
478  // die ("Please check database connection.");
479  }
480  return null;
481  }
482 
483 
484  /**
485  * @brief return template ID for given name
486  * @param object $db database
487  * @param string $name affected template name
488  * @return int|null
489  */
490  public static function getTemplateIdByName(object $db, string $name): ?int
491  {
492  /** @var $db \YAWK\db */
493  if (!isset($name) || (empty($name)))
494  { // template name is not set
495  return null;
496  }
497  // query template name
498  if ($res = $db->query("SELECT id from {templates} WHERE name = '$name'"))
499  { // fetch data
500  if ($row = mysqli_fetch_row($res))
501  { // return ID
502  return $row[0];
503  }
504  }
505  else
506  {
507  // exit and throw error
508  sys::setSyslog($db, 47, 1, "failed to get template ID by name <b>$name</b> ", 0, 0, 0, 0);
509  return null;
510  }
511  // any other case is an error
512  return null;
513  }
514 
515  /**
516  * @brief return current active template name
517  * @param object $db database
518  * @param string $location frontend or backend
519  * @param int $templateID affected template ID
520  * @return bool|string
521  */
522  public static function getCurrentTemplateName(object $db, string $location, int $templateID)
523  {
524  /** @var $db \YAWK\db */
525  if (!isset($location) || (empty($location))) { // if location is empty, set frontend as default
526  $location = "frontend";
527  $prefix = "";
528  } else { // check location to set path correctly
529  if ($location == "frontend") { // call from frontend
530  $prefix = "";
531  } else { // call from backend
532  $prefix = "../";
533  }
534  }
535  // NO TEMPLATE ID IS SET...
536  if (empty($templateID) || ($templateID == 0)) {
537  // check if user has its own template
538  // $userTemplateID = \YAWK\user::getUserTemplateID($db, )
539  // no templateID sent via param, set current selected template ID
540  $templateID = settings::getSetting($db, "selectedTemplate");
541  }
542  // get current template name from database
543  $tpldir = $prefix . "system/templates/";
544  if ($res = $db->query("SELECT name FROM {templates}
545  WHERE id = $templateID")
546  ) { // fetch data
547  if ($row = mysqli_fetch_row($res)) { // check if selected tpl exists
548  if (!$dir = @opendir("$tpldir" . $row[0])) { // if directory could not be opened: throw error
549  sys::setSyslog($db, 47, 1, "failed to load template directory of template id: <b>$templateID</b>", 0, 0, 0, 0);
550  return "<b>Oh-oh! There was a big error. . .</b> <u>you shall not see this!</u><br><br>Unable to load template " . $row[0] . ".&nbsp; I am deeply sorry.<br> I am sure my administrator is hurry to fix that problem.<br> yours,<br>YaWK <i><small>(Yet another Web Kit)</i></small>";
551  } else { // return template name
552  return $row[0];
553  }
554  } else { // could not fetch template -
555  // - in that case set default template
556  // print alert::draw("warning", "Warning: ", "Template kann nicht gelesen werden, default template gesetzt. (YaWK-bootstrap3)","page=settings-system","4800");
557  return "template ID $templateID not in database...?";
558  }
559  }
560  // something else has happened
561  return false;
562  }
563 
564  /**
565  * @brief get, set and minify template css file
566  * @param object $db database
567  * @param int $tplId affected template ID
568  * @param string $content contains the css file content
569  * @param int $minify 0|1 if 1, file gets minified before saving.
570  * @return bool
571  */
572  public function writeTemplateCssFile(object $db, int $tplId, string $content, int $minify): bool
573  {
574  /** @var $db \YAWK\db */
575  // check whether templateID is not set or empty
576  if (!isset($tplId) || (empty($tplId))) { // set default value: template 1
577  $tplId = 1;
578  }
579  // prepare vars
580  $filename = self::getSettingsCSSFilename($db, "backend", $tplId);
581  // check if file need to be minified
582  if (isset($minify) && (!empty($minify))) { // minify is set
583  if ($minify === 1) { // create a minified version: template/css/custom.min.css (for production include)
584  $filename = substr($filename, 0, -4);
585  $filename = "$filename.min.css";
587  } else { // failed to minify, insert syslog
588  sys::setSyslog($db, 47, 1, "failed to minify template css <b>$filename</b>", 0, 0, 0, 0);
589  }
590  }
591  // do all the file stuff, open, write, close and chmod to set permissions.
592  $handle = fopen($filename, "wb");
593 
594  if (!fwrite($handle, $content)) { // write failed, throw error
595  sys::setSyslog($db, 48, 2, "failed to write <b>$filename</b> Please check file / folder owner or group permissions", 0, 0, 0, 0);
596  alert::draw("danger", "Error!", "Could not template CSS file $filename<br>Please check your file / owner or group permissions.", "", 4200);
597  }
598  if (!fclose($handle)) { // close failed, throw error
599  sys::setSyslog($db, 47, 1, "failed to close <b>$filename</b>", 0, 0, 0, 0);
600  alert::draw("warning", "Warning!", "Failed to template CSS file close $filename<br>Please try again and / or expect some errors.", "", 4200);
601  }
602  if (!chmod($filename, 0775)) { // chmod failed, throw error
603  sys::setSyslog($db, 47, 1, "failed to chmod 775 to template CSS file <b>$filename</b>", 0, 0, 0, 0);
604  alert::draw("warning", "Warning!", "Failed to chmod(775) $filename<br>Please check file / folder / owner / group permissions!", "", 4200);
605  }
606  // after all....
607  return true;
608  }
609 
610  /**
611  * @brief get, set and minify custom.css file
612  * @param object $db database
613  * @param string $content contains the css file content
614  * @param int $minify 0|1 if 1, the file gets minified before saving.
615  * @param int $templateID affected template ID
616  * @return bool
617  */
618  public function setCustomCssFile(object $db, string $content, int $minify, int $templateID): bool
619  {
620  /** @var $db \YAWK\db */
621  // create template/css/custom.css (for development purpose in backend)
622  // prepare vars
623  $filename = self::getCustomCSSFilename($db, "backend", $templateID);
624  // check if file need to be minified
625  if (isset($minify) && (!empty($minify))) { // minify is set
626  if ($minify === 1) { // create a minified version: template/css/custom.min.css (for production include)
627  $filename = substr($filename, 0, -4);
628  $filename = "$filename.min.css";
630  } else {
631  sys::setSyslog($db, 47, 1, "failed to minify file <b>$filename</b>", 0, 0, 0, 0);
632  }
633  }
634  // do all the file stuff, open, write, close and chmod to set permissions.
635  $handle = fopen($filename, "wb");
636  //$content = \YAWK\sys::replaceCarriageReturns("\n\r", $content);
638  if (!fwrite($handle, $content)) { // write failed, throw error
639  alert::draw("danger", "Error!", "Could not write custom css $filename<br>Please check your file / owner or group permissions.", "", 4200);
640  }
641  if (!fclose($handle)) { // close failed, throw error
642  alert::draw("warning", "Warning!", "Failed to close custom css $filename<br>Please try again and / or expect some errors.", "", 4200);
643  }
644  if (!chmod($filename, 0775)) { // chmod failed, throw error
645  alert::draw("warning", "Warning!", "Failed to chmod(775) custom css $filename<br>Please check file / folder / owner / group permissions!", "", 4200);
646  }
647  // after all....
648  return true;
649  }
650 
651  /**
652  * @brief get, set and minify custom.js file
653  * @param object $db database
654  * @param string $content contains the js file content
655  * @param int $minify 0|1 if 1, the file gets minified before saving.
656  * @param int $templateID affected template ID
657  * @return bool
658  */
659  public function setCustomJsFile(object $db, string $content, int $minify, int $templateID): bool
660  {
661  /** @var $db \YAWK\db */
662  // create template/css/custom.css (for development purpose in backend)
663  // prepare vars
664  $filename = self::getCustomJSFilename($db, "backend", $templateID);
665  // check if file need to be minified
666  if (isset($minify) && (!empty($minify))) { // minify is set
667  if ($minify === 1) { // create a minified version: template/js/custom.min.js (for production include)
668  $filename = substr($filename, 0, -3);
669  $filename = "$filename.min.js";
671  } else {
672  sys::setSyslog($db, 47, 1, "failed to minify file <b>$filename</b>", 0, 0, 0, 0);
673  }
674  }
675  // do all the file stuff, open, write, close and chmod to set permissions.
676  $handle = fopen($filename, "wb");
677  //$content = \YAWK\sys::replaceCarriageReturns("\n\r", $content);
679  if (!fwrite($handle, $content)) { // write failed, throw error
680  alert::draw("danger", "Error!", "failed to write file $filename<br>Please check your file / owner or group permissions.", "", 4200);
681  }
682  if (!fclose($handle)) { // close failed, throw error
683  alert::draw("warning", "Warning!", "Failed to close custom js $filename<br>Please try again and / or expect some errors.", "", 4200);
684  }
685  if (!chmod($filename, 0775)) { // chmod failed, throw error
686  alert::draw("warning", "Warning!", "Failed to chmod(775) custom js $filename<br>Please check file / folder / owner / group permissions!", "", 4200);
687  }
688  // after all....
689  return true;
690  }
691 
692  /**
693  * @brief return the content of custom.css
694  * @param object $db database
695  * @param int $templateID affected template ID
696  * @return string the content of custom.css
697  */
698  public function getCustomCSSFile(object $db, int $templateID): string
699  { // get the content from custom.css
700  $filename = self::getCustomCSSFilename($db, "backend", $templateID);
701  return file_get_contents($filename);
702  }
703 
704  /**
705  * @brief return the content of custom.js
706  * @param object $db database
707  * @param int $templateID affected template ID
708  * @return string the content of custom.css
709  */
710  public function getCustomJSFile(object $db, int $templateID): string
711  { // get the content from custom.css
712  $filename = self::getCustomJSFilename($db, "backend", $templateID);
713  return file_get_contents($filename);
714  }
715 
716  /**
717  * @brief return filename of template css file
718  * @param object $db database
719  * @param string $location frontend or backend
720  * @param int $templateID affected template ID
721  * @return string the template's css filename, including path
722  */
723  public function getSettingsCSSFilename(object $db, string $location, int $templateID): string
724  {
725  /** @var $db \YAWK\db */
726  // prepare vars... path + filename
727  if (!isset($templateID) || (empty($templateID))) {
729  }
730  if (!isset($location) || (empty($location))) {
731  $location = "Backend";
732  }
733  $tplName = self::getCurrentTemplateName($db, $location, $templateID); // tpl name
734  $alias = "settings"; // set CSS file name
735  $filename = "../system/templates/$tplName/css/" . $alias . ".css";
736  return $filename;
737  }
738 
739  /**
740  * @brief return filename of custom css file
741  * @param object $db database
742  * @param string $location frontend or backend
743  * @param int $templateID affected template ID
744  * @return string the template's custom css filename, including path
745  */
746  public function getCustomCSSFilename(object $db, string $location, int $templateID): string
747  {
748  /** @var $db \YAWK\db */
749  // prepare vars... path + filename
750  $tplName = self::getCurrentTemplateName($db, $location, $templateID); // tpl name
751  $alias = "custom"; // set CSS file name
752  $filename = "../system/templates/$tplName/css/" . $alias . ".css";
753  return $filename;
754  }
755 
756  /**
757  * @brief return filename of custom js file
758  * @param object $db database
759  * @param string $location frontend or backend
760  * @param int $templateID affected template ID
761  * @return string the template's custom css filename, including path
762  */
763  public function getCustomJSFilename($db, $location, $templateID)
764  {
765  /** @var $db \YAWK\db */
766  // prepare vars... path + filename
767  $tplName = self::getCurrentTemplateName($db, $location, $templateID); // tpl name
768  $alias = "custom"; // set JS file name
769  $filename = "../system/templates/$tplName/js/" . $alias . ".js";
770  return $filename;
771  }
772 
773 
774  /**
775  * @brief return biggest ID from template database
776  * @param object $db database
777  * @return int|bool
778  */
779  public static function getMaxId($db)
780  {
781  /* @param $db \YAWK\db */
782  if ($res = $db->query("SELECT MAX(id) from {templates}")) { // fetch id
783  if ($row = mysqli_fetch_row($res)) {
784  return $row[0];
785  } else {
786  sys::setSyslog($db, 47, 1, "failed to get MAX(id) from template db", 0, 0, 0, 0);
787  return false;
788  }
789  } else {
790  return false;
791  }
792  }
793 
794  /** delete template settings css file
795  * @param object $db database
796  * @param string $filename the filename (including path) you wish to delete
797  * @return bool
798  */
800  { // if no filename is given
801  if (!isset($filename) || (empty($filename))) { // set default filename
802  $filename = self::getSettingsCSSFilename($db, '', '');
803  }
804  // we want the settings.css file to be overridden, so check if file exists and delete it if needed.
805  if (file_exists($filename)) { // if there is a file, delete it.
806  if (!unlink($filename)) { // delete failed, throw error
807  sys::setSyslog($db, 47, 1, "failed to delete file <b>$filename</b>", 0, 0, 0, 0);
808  alert::draw("danger", "Error!", "Failed to unlink $filename<br>Please delete this file and check file / folder / owner or group permissions!", "", 6200);
809  return false;
810  } else { // delete worked
811  return true;
812  }
813  } else { // file does not exist
814  sys::setSyslog($db, 47, 1, "failed to delete settings css file because it does not exist.", 0, 0, 0, 0);
815  return true;
816  }
817  }
818 
819  /**
820  * @brief update (save) template settings
821  * @param object $db database
822  * @param int $id affected template ID
823  * @param string $property template settings property
824  * @param string $value template settings value
825  * @return bool
826  */
827  function setTemplateSetting($db, $id, $property, $value, $longValue)
828  {
829  /** @var $db \YAWK\db */
830  $property = $db->quote($property);
831  $value = $db->quote($value);
832  $longValue = $db->quote($longValue);
833  $value = strip_tags($value);
834  $longValue = strip_tags($longValue);
835  if ($longValue === "1") {
836  $sql = "SET longValue = '" . $value . "'";
837  } else {
838  $sql = "SET value = '" . $value . "'";
839  }
840 
841  if ($res = $db->query("UPDATE {template_settings}
842  $sql
843  WHERE property = '" . $property . "'
844  AND templateID = '" . $id . "'")
845  ) { // success
846  return true;
847  } else { // q failed
848  sys::setSyslog($db, 47, 1, "failed to set template #$id setting <b>$value</b> of <b>$property</b> ", 0, 0, 0, 0);
849  return false;
850  }
851  }
852 
853 
854  /**
855  * @brief set template active
856  * @param object $db database
857  * @param int $templateID affected template ID
858  * @return bool
859  */
860  public static function setTemplateActive($db, $templateID)
861  {
862  /** @var $db \YAWK\db */
863  if (!isset($templateID) && (empty($templateID))) { // if template id is not set, get it from database
864  $templateID = settings::getSetting($db, "selectedTemplate");
865  }
866  // null active template in table
867  if (!$res = $db->query("UPDATE {templates} SET active = 0 WHERE active != 0")) { // error: abort.
868  return false;
869  }
870  if ($res = $db->query("UPDATE {templates}
871  SET active = 1
872  WHERE id = $templateID")
873  ) { // success
874  return true;
875  } else { // q failed
876  sys::setSyslog($db, 47, 1, "failed to set template #$templateID active ", 0, 0, 0, 0);
877  return false;
878  }
879 
880  }
881 
882  /**
883  * @brief copy template settings into a new template
884  * @param object $db database
885  * @param int $templateID template ID
886  * @param int $newID template ID
887  */
888  public static function copyTemplateSettings($db, $templateID, $newID)
889  {
890  /** @var $db \YAWK\db */
891 
892  $res = $db->query("INSERT INTO {template_settings}
893  (templateID, property, value, valueDefault, longValue, type, activated, sort, label, fieldClass, fieldType,
894  options, placeholder, description, icon, heading, subtext)
895  SELECT '" . $newID . "', property, value, valueDefault, longValue, type, activated, sort, label, fieldClass, fieldType,
896  options, placeholder, description, icon, heading, subtext
897  FROM {template_settings}
898  WHERE templateID = '" . $templateID . "'");
899 
900  if (!$res) {
901  sys::setSyslog($db, 47, 1, "failed to copy template settings of template #$templateID ", 0, 0, 0, 0);
902  alert::draw("danger", "Could not copy settings", "please try again.", "", 5000);
903  } else {
904  alert::draw("success", "Settings copied", "successful", "", 5000);
905 
906  $update = $db->query("UPDATE {template_settings} SET templateID='" . $newID . "' WHERE templateID=0");
907  if ($update) {
908  alert::draw("success", "Settings are set-up", "successful", "", 5000);
909  } else {
910  sys::setSyslog($db, 47, 1, "failed to set new template settings of template #$templateID ", 0, 0, 0, 0);
911  alert::draw("warning", "Could not set new template settings", "unable to alter IDs.", "", 5000);
912  }
913  }
914  }
915 
916  /**
917  * @brief Add a new template setting to the database.
918  * @param object $db database
919  * @param string $property template property
920  * @param string $value template value
921  * @param string $valueDefault default value
922  * @param string $label setting label
923  * @param string $fieldclass class for the input field (eg. color or form-control)
924  * @param string $placeholder placeholder for the input field
925  * @return bool
926  */
927  // alter IDs
928  /**
929  * @param object $db
930  * @param string $property
931  * @param string $value
932  * @param string $valueDefault
933  * @param string $label
934  * @param string $fieldclass
935  * @param string $placeholder
936  * @return bool
937  */
938  function addTemplateSetting($db, $property, $value, $valueDefault, $label, $fieldclass, $placeholder)
939  {
940  /** @var $db \YAWK\db */
941  $active = 1;
942  $sort = 0;
943  $templateID = settings::getSetting($db, "selectedTemplate"); // self::getCurrentTemplateId($db);
944 
945  $property = $db->quote($property);
946  $value = $db->quote($value);
947  $valueDefault = $db->quote($valueDefault);
948  $label = $db->quote($label);
949  $fieldclass = $db->quote($fieldclass);
950  $placeholder = $db->quote($placeholder);
951  if ($res = $db->query("INSERT INTO {template_settings} (templateID, property, value, valueDefault, label, activated, sort, fieldClass, placeholder)
952  VALUES('" . $templateID . "','" . $property . "', '" . $value . "', '" . $valueDefault . "', '" . $label . "', '" . $active . "', '" . $sort . "', '" . $fieldclass . "', '" . $placeholder . "')")
953  ) { // success
954  return true;
955  } else { // q failed
956  sys::setSyslog($db, 47, 1, "failed to add template setting $property:$value ", 0, 0, 0, 0);
957  return false;
958  }
959  }
960 
961  /**
962  * @brief set template details
963  * @param object $db object database
964  * @param string $description template description
965  * @param string $author author name
966  * @param string $authorUrl author URL
967  * @param int $id affected template ID
968  * @return bool
969  */
970  public function setTemplateDetails($db, $description, $author, $authorUrl, $id)
971  {
972  /** @var $db \YAWK\db */
973  if ($res = $db->query("UPDATE {templates} SET description = '" . $description . "', subAuthor = '" . $author . "', subAuthorUrl = '" . $authorUrl . "' WHERE id = '" . $id . "'")) { // template details updated...
974  return true;
975  } else { // could not save template details
976  sys::setSyslog($db, 47, 1, "failed to set template details", 0, 0, 0, 0);
977  return false;
978  }
979  }
980 
981  /**
982  * @brief delete template
983  * @param object $db database
984  * @param int $templateID template ID of the template you wish to delete
985  * @return bool
986  */
987  static function deleteTemplate($db, $templateID)
988  {
989  /** @var $db \YAWK\db */
990  if (!isset($templateID) && (empty($templateID)))
991  { // no templateID is set...
992  sys::setSyslog($db, 47, 1, "failed to delete template because templateID was missing.", 0, 0, 0, 0);
993  return false;
994  }
995 
996  // quote var, just to be sure its clean
997  $templateID = $db->quote($templateID);
998 
999  // to delete the files, we need to get the template folder's name
1000  // this function checks if template exits in database + if folder physically exists on disk
1001  $templateFolder = template::getCurrentTemplateName($db, "backend", $templateID);
1002 
1003  // check if template folder exists...
1004  if (is_dir(dirname(__dir__."../system/templates/".$templateFolder."")))
1005  {
1006  // delete template folder from disk
1007  if (!sys::recurseRmdir(__dir__."../system/templates/$templateFolder"))
1008  { // booh, deleting recurse did not work
1009  sys::setSyslog($db, 47, 1, "failed to delete recursive ../system/templates/$templateFolder", 0, 0, 0, 0);
1010  return false;
1011  }
1012  }
1013 
1014 
1015  // delete template settings of requested templateID
1016  if (!$res = $db->query("DELETE FROM {template_settings} WHERE templateID = $templateID"))
1017  { // delete settings failed...
1018  sys::setSyslog($db, 47, 1, "failed to delete template settings of ID: $templateID", 0, 0, 0, 0);
1019  return false;
1020  }
1021 
1022  // delete assets of requested templateID
1023  if (!$res = $db->query("DELETE FROM {assets} WHERE templateID = $templateID"))
1024  { // delete settings failed...
1025  sys::setSyslog($db, 47, 1, "failed to delete template assets of ID: $templateID", 0, 0, 0, 0);
1026  return false;
1027  }
1028 
1029  // delete template from database {templates}
1030  if (!$res = $db->query("DELETE FROM {templates} WHERE id = $templateID"))
1031  { // failed to delete from database
1032  sys::setSyslog($db, 47, 1, "failed to delete template ID: $templateID from database", 0, 0, 0, 0);
1033  return false;
1034  }
1035  else
1036  {
1037  // ALTER table and set auto_increment value to prevent errors when deleting + adding new tpl
1038  if ($res = $db->query("SELECT MAX(id) FROM {templates}"))
1039  { // get MAX ID
1040  $row = mysqli_fetch_row($res);
1041  if (!$res = $db->query("ALTER TABLE {templates} AUTO_INCREMENT $row[0]"))
1042  { // could not select auto increment
1043  sys::setSyslog($db, 47, 1, "failed alter auto increment templates table ", 0, 0, 0, 0);
1044  return false;
1045  }
1046  }
1047  }
1048 
1049 
1050  // all good - no false = template should be deleted
1051  return true;
1052  }
1053 
1054 
1055  /**
1056  * @brief Returns an array with all template settings.
1057  * @param object $db Database Object
1058  * @param object $user User Object
1059  * @return array|bool
1060  */
1061  public static function getAllSettingsIntoArray($db, $user) // get all settings from db like property
1062  {
1063  if (!isset($user) || empty($user))
1064  {
1065  $user = new user($db);
1066  }
1067  // get template settings
1068  if (isset($user))
1069  { // get template settings for this user
1070  if ($user->overrideTemplate == 1) {
1071  $sql = "SELECT ts.property, ts.value, ts.longValue, ts.valueDefault, ts.type, ts.label, ts.sort, ts.fieldClass, ts.fieldType, ts.placeholder, ts.description, ts.options, ts.activated, ts.icon, ts.heading, ts.subtext
1072  FROM {template_settings} ts
1073  JOIN {users} u on u.templateID = ts.templateID
1074  WHERE ts.activated = 1 && u.id = $user->id
1075  ORDER BY ts.sort";
1076  } else {
1077  $sql = "SELECT ts.property, ts.value, ts.longValue, ts.valueDefault, ts.type, ts.label, ts.sort, ts.fieldClass, ts.fieldType, ts.placeholder, ts.description, ts.options, ts.activated, ts.icon, ts.heading, ts.subtext
1078  FROM {template_settings} ts
1079  JOIN {settings} s on s.value = ts.templateID
1080  WHERE ts.activated = 1 && s.property = 'selectedTemplate'
1081  ORDER BY ts.sort";
1082  }
1083  } else {
1084  sys::setSyslog($db, 47, 1, "failed to get template settings array - user is not set or empty", 0, 0, 0, 0);
1085  return false;
1086  }
1087 
1088  /* @param $db \YAWK\db */
1089  // if ($res= $db->query("SELECT * FROM {template_settings} ORDER by property"))
1090  if ($res = $db->query($sql)) {
1091  $settingsArray = array();
1092  while ($row = $res->fetch_assoc()) { // fill array
1093  $settingsArray[$row['property']] = $row;
1094  }
1095  } else { // q failed, throw error
1096  sys::setSyslog($db, 5, 1, "failed to query template settings", 0, 0, 0, 0);
1097  // \YAWK\alert::draw("warning", "Warning!", "Fetch database error: getSettingsArray failed.","","4800");
1098  return false;
1099  }
1100 
1101  // check if array has been generated
1102  if (is_array($settingsArray) && (!empty($settingsArray))) { // all good -
1103  return $settingsArray;
1104  } else { // error generating settings array -
1105  return false;
1106  }
1107  }
1108 
1109  /**
1110  * @brief return div box with postition settings
1111  * @param object $db Database object
1112  * @param string $position The position to load
1113  * @param array $positions Positions [enabled] status array
1114  * @param array $indicators Positions [indicator] status array
1115  * @param object $user the current user object
1116  * @param object $template Template object
1117  */
1118  public static function getPositionDivBox($db, $lang, $position, $row, $bootstrapGrid, $positions, $indicators, $user, $template)
1119  {
1120  global $currentpage;
1121  if (isset($row) && (!empty($row))) {
1122  if ($row === "1") {
1123  $startRow = "<div class=\"row\">";
1124  $endRow = "</div>";
1125  } else {
1126  $startRow = '';
1127  $endRow = '';
1128  }
1129  } else {
1130  $startRow = '';
1131  $endRow = '';
1132  }
1133 
1134  // check if position indicator is enabled
1135  if ($positions["pos-$position-enabled"] === "1")
1136  { // check if position indicator is enabled
1137  if ($indicators["pos-$position-indicator"] === "1")
1138  { // display position indicator
1139  $indicatorStyle = "style=\"border: 1px solid red;\"";
1140  $indicatorText = "<i><b>$position</b></i>";
1141  }
1142  else
1143  { // no position indicator set
1144  $indicatorStyle = '';
1145  $indicatorText = '';
1146  }
1147 
1148  // output position div box
1149  echo "$startRow";
1150  echo "<div class=\"$bootstrapGrid pos-$position\" id=\"$position\" $indicatorStyle>$indicatorText";
1151  template::setPosition($db, $lang, "$position-pos", $currentpage, $user, $template);
1152  echo "
1153  </div>";
1154  echo "$endRow";
1155  }
1156  }
1157 
1158 
1159  /**
1160  * @brief return html form field, depending on fieldClass
1161  * @param object $db Database Object
1162  */
1163  public function getFormElements($db, $settings, $type, $lang, $user)
1164  { // loop trough array
1165  // removed not needed checkup
1166  if (!isset($type) && (empty($type)))
1167  { // if param 'type' is missing, set type 1 as default
1168  $type = 1;
1169  }
1170  if (!isset($settings) || (is_array($settings) === false))
1171  {
1172  echo 'Template settings are missing. Please re-install template.';
1173  }
1174  else
1175  {
1176  // loop trough settings array
1177  foreach ($settings as $setting)
1178  {
1179  // field type not set or empty
1180  if (!isset($setting['fieldType']) && (empty($fieldType)))
1181  { // set input field as common default
1182  $setting['fieldType'] = "input";
1183  }
1184  else
1185  { // settings type must be equal to param $type
1186  // equals settings category
1187  if ($setting['type'] === "$type" && ($setting['activated'] === "1"))
1188  {
1189  // check if ICON is set
1190  // if an icon is set, it will be drawn before the heading, to the left.
1191  if (isset($setting['icon']) && (!empty($setting['icon'])))
1192  { // fill it w icon
1193  $setting['icon'] = "<i class=\"$setting[icon]\"></i>";
1194  }
1195  else
1196  { // leave empty - no icon available
1197  $setting['icon'] = '';
1198  }
1199 
1200  // check if LABEL is set
1201  // The label sits directly above, relative to the setting form element
1202  if (isset($setting['label']) && (!empty($setting['label'])))
1203  { // if its set, put it into $lang array for L11n
1204  $setting['label'] = $lang[$setting['label']];
1205  }
1206  else
1207  { // otherwise throw error
1208  $setting['label'] = 'sorry, there is not label set. meh!';
1209  }
1210 
1211  // check if HEADING is set
1212  // if set, a <H3>Heading</H3> will be shown above the setting
1213  if (isset($setting['heading']) && (!empty($setting['heading'])))
1214  { // L11n
1215  $setting['heading'] = $lang[$setting['heading']];
1216  }
1217  else
1218  { // leave empty - no heading for that setting
1219  $setting['heading'] = '';
1220  }
1221 
1222  // check if SUBTEXT is set
1223  // this is shown in <small>tags</small> beneath the heading
1224  if (isset($setting['subtext']) && (!empty($setting['subtext'])))
1225  { // L11n
1226  $setting['subtext'] = $lang[$setting['subtext']];
1227  }
1228  else
1229  { // leave empty - no subtext beneath the heading
1230  $setting['subtext'] = '';
1231  }
1232 
1233  // check if description is set
1234  // the description will be shown right beside the label
1235  if (isset($setting['description']) && (!empty($setting['description'])))
1236  { // L11n
1237  $setting['description'] = $lang[$setting['description']];
1238  $setting['description'] = "&nbsp;<small><i class=\"fa fa-question-circle-o text-info\" data-placement=\"auto right\" data-toggle=\"tooltip\" title=\"$setting[description]\"></i></small>";
1239  }
1240 
1241  /* SELECT FIELD */
1242  if ($setting['fieldType'] === "select")
1243  { // display icon, heading and subtext, if its set
1244  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1245  {
1246  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1247  }
1248  // begin draw select
1249  echo "<label for=\"$setting[property]\">$setting[label]&nbsp;$setting[description]&nbsp;
1250  <small><i class=\"small\" style=\"font-weight:normal\">$lang[DEFAULT]: $setting[valueDefault]</i></small></label>
1251  <select style=\"margin-bottom:10px;\" class=\"form-control\" id=\"$setting[property]\" name=\"$setting[property]\">";
1252  echo "<option value=\"$setting[value]\">$lang[SETTING_CURRENT] $setting[value]</option>";
1253  // explode option string into array
1254  $optionValues = explode(":", $setting['options']);
1255  foreach ($optionValues as $value)
1256  {
1257  // extract value from option setting string
1258  // $optionValue = preg_replace("/,[a-zA-Z0-9]*/", "", $value);
1259  // extract description from option setting
1260  $optionDesc = preg_replace('/.*,(.*)/', '$1', $value);
1261  $optionValue = preg_split("/,[a-zA-Z0-9]*/", $value);
1262 
1263  echo "<option value=\"$optionValue[0]\">$optionDesc</option>";
1264  }
1265  echo "</select>";
1266  }
1267 
1268  /* RADIO BUTTTONS */
1269  else if ($setting['fieldType'] === "radio")
1270  {
1271  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1272  {
1273  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1274  }
1275  echo "<label for=\"$setting[property]\">$setting[label]&nbsp;$setting[description]&nbsp;</label>
1276  <input style=\"margin-bottom:10px;\" type=\"radio\" id=\"$setting[property]\" name=\"$setting[property]\">";
1277  echo "<input type=\"radio\" value=\"$setting[value]\">$lang[SETTING_CURRENT] $setting[value]</option>";
1278 
1279  // explode option string into array
1280  $optionValues = explode(":", $setting['options']);
1281  foreach ($optionValues as $value)
1282  {
1283  // extract value from option setting string
1284  $optionValue = preg_replace("/,[a-zA-Z0-9]*/", "", $value);
1285  // extract description from option setting
1286  $optionDesc = preg_replace('/.*,(.*)/', '$1', $value);
1287 
1288  echo "<option value=\"$optionValue\">$optionDesc</option>";
1289  }
1290  echo "</select>";
1291  }
1292 
1293  // CHECKBOX
1294  else if ($setting['fieldType'] === "checkbox")
1295  { // build a checkbox
1296  if ($setting['value'] === "1")
1297  { // set checkbox to checked
1298  $checked = "checked";
1299  }
1300  else
1301  { // checkbox not checked
1302  $checked = "";
1303  }
1304  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1305  {
1306  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1307  }
1308  echo "<input type=\"hidden\" name=\"$setting[property]\" value=\"0\">
1309  <input type=\"checkbox\" id=\"$setting[property]\" name=\"$setting[property]\" value=\"1\" $checked>
1310  <label style=\"margin-bottom:10px;\" for=\"$setting[property]\">&nbsp; $setting[label]&nbsp;$setting[description]&nbsp;</label>";
1311  }
1312 
1313  // CHECKBOX as toggle switch
1314  else if ($setting['fieldType'] === "checkbox toggle")
1315  {
1316  // build a checkbox
1317  if ($setting['value'] === "1")
1318  { // set checkbox to checked
1319  $checked = "checked";
1320  }
1321  else
1322  { // checkbox not checked
1323  $checked = "";
1324  }
1325 
1326  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1327  {
1328  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1329  }
1330  echo "<input type=\"hidden\" name=\"$setting[property]\" value=\"0\">
1331  <input type=\"checkbox\" data-on=\"$lang[ON_]\" data-off=\"$lang[OFF_]\" data-toggle=\"toggle\" data-onstyle=\"success\" data-offstyle=\"danger\" id=\"$setting[property]\" name=\"$setting[property]\" value=\"1\" $checked>
1332  <label for=\"$setting[property]\">&nbsp; $setting[label]&nbsp;$setting[description]&nbsp;</label><hr>";
1333  }
1334 
1335  /* TEXTAREA */
1336  else if ($setting['fieldType'] === "textarea")
1337  { // if a long value is set
1338  $placeholder = $setting['placeholder'];
1339  // store placeholder from array in var to use it at language array
1340  if (isset($setting['longValue']) && (!empty($setting['longValue'])))
1341  { // build a longValue tagged textarea and fill with longValue
1342  $setting['longValue'] = nl2br($setting['longValue']);
1343  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1344  {
1345  echo "<h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1346  }
1347  echo "<label for=\"$setting[property]\">$setting[label]&nbsp;$setting[description]&nbsp;</label>
1348  <textarea style=\"margin-bottom:10px;\" cols=\"64\" rows=\"4\" class=\"$setting[fieldClass]\" placeholder=\"$lang[$placeholder]\" id=\"$setting[property]\" name=\"$setting[property]\">$setting[longValue]</textarea>";
1349  }
1350  else
1351  { // draw default textarea
1352  $setting['value'] = nl2br($setting['value']);
1353  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1354  {
1355  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1356  }
1357  echo "<label for=\"$setting[property]-long\">$setting[label]&nbsp;$setting[description]&nbsp;</label>
1358  <textarea style=\"margin-bottom:10px;\" cols=\"64\" rows=\"4\" class=\"$setting[fieldClass]\" placeholder=\"$lang[$placeholder]\" id=\"$setting[property]\" name=\"$setting[property]\">$setting[value]</textarea>";
1359  }
1360  }
1361 
1362  /* INPUT PASSWORD FIELD */
1363  else if ($setting['fieldType'] === "password")
1364  { // draw an input field
1365  $placeholder = $setting['placeholder'];
1366  // store placeholder from array in var to use it at language array
1367  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1368  {
1369  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1370  }
1371  echo "<label for=\"$setting[property]\">$setting[label]</label>&nbsp;$setting[description]&nbsp;
1372  <input style=\"margin-bottom:10px;\" type=\"password\" class=\"$setting[fieldClass]\" id=\"$setting[property]\" name=\"$setting[property]\"
1373  value=\"$setting[value]\" placeholder=\"$lang[$placeholder]\">";
1374  }
1375  /* INPUT TEXT FIELD */
1376  else if ($setting['fieldType'] === "input")
1377  { // draw an input field
1378  $placeholder = $setting['placeholder'];
1379  // store placeholder from array in var to use it at language array
1380  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1381  {
1382  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1383  }
1384  echo "<label for=\"$setting[property]\">$setting[label]&nbsp;$setting[description]&nbsp;
1385  <small><i class=\"small\" style=\"font-weight:normal\">$lang[DEFAULT]: $setting[valueDefault]</i></small></label>
1386  <input style=\"margin-bottom:10px;\" type=\"text\" class=\"$setting[fieldClass]\" id=\"$setting[property]\" name=\"$setting[property]\"
1387  value=\"$setting[value]\" placeholder=\"$lang[$placeholder]\">";
1388  }
1389 
1390  /* COLOR TEXT FIELD */
1391  else if ($setting['fieldType'] === "color")
1392  { // draw a color input field
1393  $placeholder = $setting['placeholder']; // store placeholder from array in var to use it at language array
1394  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1395  {
1396  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1397  }
1398  echo "<label for=\"$setting[property]\">$setting[label]&nbsp;$setting[description]&nbsp;
1399  <small><i class=\"small\" style=\"font-weight:normal\">$lang[DEFAULT]: $setting[valueDefault]</i></small></label>
1400  <input style=\"margin-bottom:10px;\" type=\"text\" class=\"$setting[fieldClass]\" id=\"$setting[property]\" name=\"$setting[property]\"
1401  value=\"$setting[value]\" placeholder=\"$lang[$placeholder]\">";
1402  }
1403 
1404  /* TEMPLATE SELECT FIELD */
1405  else if ($setting['fieldType'] === "select template")
1406  { // display icon, heading and subtext, if its set
1407 
1408  $templateArray = \YAWK\template::getTemplateIds($db);
1409  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1410  {
1411  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1412  }
1413  // begin draw select
1414  echo "<label for=\"$setting[property]\">$setting[label]&nbsp;$setting[description]&nbsp;
1415  <small><i class=\"small\" style=\"font-weight:normal\">$lang[DEFAULT]: $setting[valueDefault]</i></small></label>
1416  <select style=\"margin-bottom:10px;\" class=\"form-control\" id=\"$setting[property]\" name=\"$setting[property]\">";
1417  $activeTemplateName = \YAWK\template::getTemplateNameById($db, (int)$setting['value']);
1418  echo "<option value=\"$setting[value]\">$lang[SETTING_CURRENT] $activeTemplateName</option>";
1419  // explode option string into array
1420  $optionValues = explode(":", $setting['options']);
1421  foreach ($templateArray as $template)
1422  {
1423  if ($setting['value'] != $template['id']) {
1424  echo "<option value=\"".$template['id']."\"".$markup.">".$template['name']."</option>";
1425  }
1426  }
1427  echo "</select>";
1428  }
1429  else
1430  {
1431  // draw an input field
1432  $placeholder = $setting['placeholder'];
1433  // store placeholder from array in var to use it at language array
1434  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1435  {
1436  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1437  }
1438  if (!isset($lang[$placeholder]) ||(empty($lang[$placeholder]))){ $phMarkup = ""; } else { $phMarkup = " placeholder=\"$lang[$placeholder]\""; }
1439  echo "<label for=\"$setting[property]\">$setting[label]&nbsp;$setting[description]&nbsp;
1440  <small><i class=\"small\" style=\"font-weight:normal\">$lang[DEFAULT]: $setting[valueDefault]</i></small></label>
1441  <input style=\"margin-bottom:10px;\" type=\"text\" class=\"$setting[fieldClass]\" id=\"$setting[property]\" name=\"$setting[property]\"
1442  value=\"$setting[value]\"$phMarkup\">";
1443  }
1444  }
1445  }
1446  }
1447  }
1448  }
1449 
1450 
1451  /**
1452  * @brief return font edit row including preview
1453  * @param object $db database
1454  * @param array $lang language array
1455  * @param string $fontRow the prefix of the font group to edit (eg. h1, h2, h3, globaltext...)
1456  * @param string $previewClass css class you want to use on the preview
1457  * @param array $templateSettings all template settings as an array
1458  *
1459  */
1460  public function getFontRow($db, $lang, $fontRow, $previewClass, $templateSettings)
1461  {
1462  // prepare vars
1463  $fontRowSize = "$fontRow-size";
1464  $fontRowColor = "$fontRow-fontcolor";
1465  $fontRowFontfamily = "$fontRow-fontfamily";
1466  $fontRowFontShadowSize = "$fontRow-fontshadowsize";
1467  $fontRowFontShadowColor = "$fontRow-fontshadowcolor";
1468  $fontRowFontWeight = "$fontRow-fontweight";
1469  $fontRowFontStyle = "$fontRow-fontstyle";
1470  $fontRowTextdecoration = "$fontRow-textdecoration";
1471  $fontRowALinkColor = "$fontRow-alink";
1472  $fontRowAHoverColor = "$fontRow-ahover";
1473  $fontRowAVisitedColor = "$fontRow-avisited";
1474  $fontRowLinkFontWeight = "$fontRow-linkfontweight";
1475  $fontRowLinkFontStyle = "$fontRow-linkfontstyle";
1476  $fontRowLinkTextDecoration = "$fontRow-linktextdecoration";
1477  $fontRowHoverTextDecoration = "$fontRow-hovertextdecoration";
1478  $fontRowSmallColor = "$fontRow-smallcolor";
1479  $fontRowSmallShadowSize = "$fontRow-smallshadowsize";
1480  $fontRowSmallShadowColor = "$fontRow-smallshadowcolor";
1481 
1482  if ($fontRow === "globaltext" xor ($fontRow === "menufont")) {
1483  $col = 4;
1484  } else {
1485  $col = 2;
1486  }
1487 
1488  $FONT_ROW = strtoupper($fontRow);
1489  $labelFontSize = "TPL_" . $FONT_ROW . "_SIZE";
1490  $labelFontColor = "TPL_" . $FONT_ROW . "_COLOR";
1491  $labelSmallColor = "TPL_" . $FONT_ROW . "_SMALLCOLOR";
1492 
1493 
1494  // check if description is set
1495  // the description will be shown right beside the label as small info icon
1496  if (isset($templateSettings[$fontRowFontfamily]['description']) && (!empty($templateSettings[$fontRowFontfamily]['description']))) { // L11n
1497  $fontRowFamilyDesc = $lang[$templateSettings[$fontRowFontfamily]['description']];
1498  $fontRowFamilyInfoBtn = "&nbsp;<small><i class=\"fa fa-question-circle-o text-info\" data-placement=\"auto right\" data-toggle=\"tooltip\" title=\"$fontRowFamilyDesc\"></i></small>";
1499  } else {
1500  $fontRowFamilyInfoBtn = '';
1501  }
1502  // check if font family default value is set
1503  if (isset($templateSettings[$fontRowFontfamily]['valueDefault']) && (!empty($templateSettings[$fontRowFontfamily]['valueDefault']))) { // default values:
1504  $fontRowFamilyDefault = "<i class=\"h6 small\">default: " . $templateSettings[$fontRowFontfamily]['valueDefault'] . "</i>";
1505  } else {
1506  $fontRowFamilyDefault = '';
1507  }
1508 
1509  // check if font size is set
1510  if (isset($templateSettings[$fontRowSize]['valueDefault']) && (!empty($templateSettings[$fontRowSize]['valueDefault']))) { // default values:
1511  $fontRowSizeDefault = "<i class=\"h6 small\">(" . $templateSettings[$fontRowSize]['valueDefault'] . ")</i>";
1512  } else {
1513  $fontRowSizeDefault = '';
1514  }
1515 
1516  $html = "
1517  <div class=\"col-md-$col\">
1518  <div class=\"$previewClass\" id=\"$fontRow-preview\" style=\"height: auto; overflow:hidden; font-size: " . $templateSettings[$fontRowSize]['value'] . "; color: #" . $templateSettings[$fontRowColor]['value'] . ";\">$fontRow Heading</div>
1519 
1520  <label for=\"$fontRowFontfamily\">$FONT_ROW $lang[TPL_FONTFAMILY] $fontRowFamilyInfoBtn</label>";
1521  $html .= $this->drawFontFamilySelectField($db, $lang, "$fontRowFontfamily", $templateSettings[$fontRowFontfamily]['value']);
1522  $html .= "
1523 
1524  <label for=\"$fontRowSize\">$lang[$labelFontSize] $fontRowSizeDefault</label>
1525  <input style=\"margin-bottom:10px;\" id=\"$fontRowSize\" name=\"$fontRowSize\" value=\"" . $templateSettings[$fontRowSize]['value'] . "\" class=\"form-control\">
1526 
1527  <label for=\"$fontRowColor\">$lang[$labelFontColor]</label>
1528  <input style=\"margin-bottom:10px;\" id=\"$fontRowColor\" name=\"$fontRowColor\" class=\"form-control color\" value=\"" . $templateSettings[$fontRowColor]['value'] . "\">
1529 
1530  <label for=\"$fontRowFontShadowSize\">$lang[TPL_FONTSHADOWSIZE]</label>
1531  <input style=\"margin-bottom:10px;\" id=\"$fontRowFontShadowSize\" name=\"$fontRowFontShadowSize\" class=\"form-control\" value=\"" . $templateSettings[$fontRowFontShadowSize]['value'] . "\" placeholder=\"2px 2px\">
1532 
1533  <label for=\"$fontRowFontShadowColor\">$lang[TPL_FONTSHADOWCOLOR]</label>
1534  <input style=\"margin-bottom:10px;\" id=\"$fontRowFontShadowColor\" name=\"$fontRowFontShadowColor\" value=\"" . $templateSettings[$fontRowFontShadowColor]['value'] . "\" class=\"form-control color\">
1535 
1536  <label for=\"$fontRowFontWeight\">$lang[TPL_FONTWEIGHT]</label>
1537  <select style=\"margin-bottom:10px;\" id=\"$fontRowFontWeight\" name=\"$fontRowFontWeight\" class=\"form-control\">";
1538 
1539  $fontweightStyles = array("normal", "bold", "bolder", "lighter", "100", "200", "300", "400 [normal]", "500", "600", "700 [bold]", "800", "900", "initial", "inherit");
1540  foreach ($fontweightStyles as $weight) {
1541  $currentFontWeight = "$fontRow-fontweight";
1542  if ($weight === $templateSettings[$currentFontWeight]['value']) {
1543  $selected = "selected aria-selected=\"true\"";
1544  } else {
1545  $selected = '';
1546  }
1547  $html .= "<option value=\"$weight\" $selected>$weight</option>";
1548  }
1549  $html .= "</select>
1550 
1551  <label for=\"$fontRowFontStyle\">$lang[TPL_FONTSTYLE]</label>
1552  <select style=\"margin-bottom:10px;\" id=\"$fontRowFontStyle\" name=\"$fontRowFontStyle\" class=\"form-control\">";
1553 
1554  $fontStyles = array("normal", "italic", "oblique", "initial", "inherit");
1555  foreach ($fontStyles as $style) {
1556  $currentFontStyle = "$fontRow-fontstyle";
1557  if ($style === $templateSettings[$currentFontStyle]['value']) {
1558  $selected = "selected aria-selected=\"true\"";
1559  } else {
1560  $selected = '';
1561  }
1562  $html .= "<option value=\"$style\" $selected>$style</option>";
1563  }
1564 
1565  $html .= "</select>
1566 
1567  <label for=\"$fontRowTextdecoration\">$lang[TPL_TEXTDECORATION]</label>
1568  <select style=\"margin-bottom:10px;\" id=\"$fontRowTextdecoration\" name=\"$fontRowTextdecoration\" class=\"form-control\">";
1569 
1570  $textdecorationTypes = array("none", "underline", "overline", "line-through", "intial", "inherit");
1571  foreach ($textdecorationTypes as $decoration) {
1572  $currentFontDecoration = "$fontRow-textdecoration";
1573  if ($decoration === $templateSettings[$currentFontDecoration]['value']) {
1574  $selected = "selected aria-selected=\"true\"";
1575  } else {
1576  $selected = '';
1577  }
1578  $html .= "<option value=\"$decoration\" $selected>$decoration</option>";
1579  }
1580  $html .= "</select>";
1581 
1582  // LINK SETTINGS START HERE
1583  $html .= "
1584 
1585  <label for=\"$fontRowLinkTextDecoration\">$lang[TPL_LINK_TEXTDECORATION]</label>
1586  <select style=\"margin-bottom:10px;\" id=\"$fontRowLinkTextDecoration\" name=\"$fontRowLinkTextDecoration\" class=\"form-control\">";
1587 
1588  foreach ($textdecorationTypes as $decoration) {
1589  $currentLinkTextDecoration = "$fontRow-linktextdecoration";
1590  if ($decoration === $templateSettings[$currentLinkTextDecoration]['value']) {
1591  $selected = "selected aria-selected=\"true\"";
1592  } else {
1593  $selected = '';
1594  }
1595  $html .= "<option value=\"$decoration\" $selected>$decoration</option>";
1596  }
1597  $html .= "</select>
1598  <label for=\"$fontRow-alink\">$lang[TPL_LINK_COLOR]</label>
1599  <input style=\"margin-bottom:10px;\" id=\"$fontRow-alink\" name=\"$fontRow-alink\" value=\"" . $templateSettings[$fontRowALinkColor]['value'] . "\" class=\"form-control color\">
1600 
1601  <label for=\"$fontRow-avisited\">$lang[TPL_LINK_VISITED_COLOR]</label>
1602  <input style=\"margin-bottom:10px;\" id=\"$fontRow-avisited\" name=\"$fontRow-avisited\" value=\"" . $templateSettings[$fontRowAVisitedColor]['value'] . "\" class=\"form-control color\">
1603 
1604  <label for=\"$fontRow-ahover\">$lang[TPL_LINK_HOVER_COLOR]</label>
1605  <input style=\"margin-bottom:10px;\" id=\"$fontRow-ahover\" name=\"$fontRow-ahover\" value=\"" . $templateSettings[$fontRowAHoverColor]['value'] . "\" class=\"form-control color\">
1606 
1607  <label for=\"$fontRowLinkFontWeight\">$lang[TPL_LINK_TEXTDECORATION]</label>
1608  <select style=\"margin-bottom:10px;\" id=\"$fontRowLinkFontWeight\" name=\"$fontRowLinkFontWeight\" class=\"form-control\">";
1609 
1610  foreach ($fontweightStyles as $weight) {
1611  $currentLinkFontWeight = "$fontRow-linkfontweight";
1612  if ($weight === $templateSettings[$currentLinkFontWeight]['value']) {
1613  $selected = "selected aria-selected=\"true\"";
1614  } else {
1615  $selected = '';
1616  }
1617  $html .= "<option value=\"$weight\" $selected>$weight</option>";
1618  }
1619  $html .= "</select>
1620 
1621  <label for=\"$fontRowLinkFontStyle\">$lang[TPL_LINK_FONTSTYLE]</label>
1622  <select style=\"margin-bottom:10px;\" id=\"$fontRowLinkFontStyle\" name=\"$fontRowLinkFontStyle\" class=\"form-control\">";
1623 
1624  foreach ($fontStyles as $style) {
1625  $currentLinkFontStyle = "$fontRow-linkfontstyle";
1626  if ($style === $templateSettings[$currentLinkFontStyle]['value']) {
1627  $selected = "selected aria-selected=\"true\"";
1628  } else {
1629  $selected = '';
1630  }
1631  $html .= "<option value=\"$style\" $selected>$style</option>";
1632  }
1633 
1634  $html .= "</select>
1635  <label for=\"$fontRowHoverTextDecoration\">$lang[TPL_HOVER_TEXTDECORATION]</label>
1636  <select style=\"margin-bottom:10px;\" id=\"$fontRowHoverTextDecoration\" name=\"$fontRowHoverTextDecoration\" class=\"form-control\">";
1637 
1638  foreach ($textdecorationTypes as $decoration) {
1639  $currentFontDecoration = "$fontRow-hovertextdecoration";
1640  if ($decoration === $templateSettings[$currentFontDecoration]['value']) {
1641  $selected = "selected aria-selected=\"true\"";
1642  } else {
1643  $selected = '';
1644  }
1645  $html .= "<option value=\"$decoration\" $selected>$decoration</option>";
1646  }
1647  $html .= "</select>";
1648 
1649 
1650  // SMALL TAG COLOR
1651  $html .= "<label for=\"$fontRowSmallColor\">$lang[TPL_SMALLCOLOR]</label>
1652  <input style=\"margin-bottom:10px;\" id=\"$fontRowSmallColor\" name=\"$fontRowSmallColor\" class=\"form-control color\" value=\"" . $templateSettings[$fontRowSmallColor]['value'] . "\">";
1653 
1654  // SMALL TAG SHADOW SIZE
1655  $html .= "<label for=\"$fontRowSmallShadowSize\">$lang[TPL_SMALLSHADOWSIZE]</label>
1656  <input style=\"margin-bottom:10px;\" id=\"$fontRowSmallShadowSize\" name=\"$fontRowSmallShadowSize\" class=\"form-control\" value=\"" . $templateSettings[$fontRowSmallShadowSize]['value'] . "\" placeholder=\"2px 2px\">";
1657  // SMALL TAG SHADOW COLOR
1658  $html .= "<label for=\"$fontRowSmallShadowColor\">$lang[TPL_SMALLSHADOWCOLOR]</label>
1659  <input style=\"margin-bottom:10px;\" id=\"$fontRowSmallShadowColor\" name=\"$fontRowSmallShadowColor\" value=\"" . $templateSettings[$fontRowSmallShadowColor]['value'] . "\" class=\"form-control color\">";
1660 
1661  // end font div box
1662  $html .= "
1663  </div>";
1664 
1665  echo $html;
1666 
1667  }
1668 
1669  /**
1670  * @brief get fonts from folder and return as array
1671  * @param string $folder folder that helds all fonts (usually ../system/fonts/)
1672  * @return string | array
1673  */
1674  static public function getFontsFromFolder($folder)
1675  {
1676  // if no folder is given
1677  if (!isset($folder) || (empty($folder))) { // set default folder
1678  $folder = '../system/fonts/';
1679  } else {
1680  // make sure that there is a slash at the end
1681  $folder = rtrim($folder, '/') . '/';
1682  // check if folder is a directory
1683  if (!is_dir($folder)) { // if not, abort
1684  return "Folder <b>$folder</b> is not a valid folder";
1685  }
1686  }
1687 
1688  // create new font array
1689  $fontArray = array();
1690  // create new directory iterator
1691  $iterator = new \DirectoryIterator($folder);
1692  // walk through folder
1693  foreach ($iterator as $file) {
1694  // exclude dots
1695  if (!$file->isDot()) { // check filetype
1696  if ($file->getExtension() === "ttf") { // add ttf fonts to array
1697  $fontArray['ttf'][] = $file->getFilename();
1698  }
1699  // check filetype
1700  if ($file->getExtension() === "otf") { // add otf fonts to array
1701  $fontArray['otf'][] = $file->getFilename();
1702  }
1703  // check filetype
1704  if ($file->getExtension() === "woff") { // add woff fonts to array
1705  $fontArray['woff'][] = $file->getFilename();
1706  }
1707  // check filetype
1708  if ($file->getExtension() === "WOFF") { // add woff fonts to array
1709  $fontArray['woff'][] = $file->getFilename();
1710  }
1711  }
1712  }
1713  // check if font array is set and not empty
1714  if (is_array($fontArray) && (!empty($fontArray))) { // all good
1715  return $fontArray;
1716  } else { // array not set or empty, throw message
1717  return "No fonts found in $folder";
1718  }
1719  }
1720 
1721  /**
1722  * @brief get setting from database and draw input field
1723  * @param object $db database
1724  * @param string $filter filter the search result (eg. all field w %-color)
1725  * @param string $special could be a slider *OUTDATED
1726  * @param string $readonly "readonly" if the field should be this way
1727  * @param object $user the current user object
1728  * @return bool
1729  */
1730  function getSetting($db, $filter, $special, $readonly, $user)
1731  {
1732  /** @var $db \YAWK\db */
1733  // build sql query string
1734  // to build the template-settings page correct within one function
1735  // the query string will be manipulated like
1736  if ($filter != '%-color') { // don't fetch -color settings
1737  $sql = "&& ts.property NOT RLIKE '.*-color'";
1738  }
1739  if ($filter != '%-bgcolor') { // don't fetch -bgcolor settings
1740  $sql = "&& ts.property NOT RLIKE '.*-bgcolor'";
1741  } else {
1742  $sql = '';
1743  }
1744 
1745  if (isset($readonly)) { // if any field should be readonly
1746  switch ($readonly) { // set html code
1747  case "readonly":
1748  $readonly = "readonly=\"readonly\"";
1749  break;
1750  default:
1751  $readonly = '';
1752  break;
1753  }
1754  }
1755  // OVERRIDE SETTINGS
1756  if (isset($user)) {
1757  if ($user->overrideTemplate == 1) {
1758  $sql = "SELECT ts.property, ts.value, ts.longValue, ts.valueDefault, ts.label, ts.fieldClass, ts.placeholder
1759  FROM {template_settings} ts
1760  JOIN {users} u on u.templateID = ts.templateID
1761  WHERE ts.activated = 1 && u.id = $user->id && ts.property
1762  LIKE '$filter' && ts.property NOT RLIKE '.*-pos' $sql ORDER BY ts.sort";
1763  } else {
1764  $sql = "SELECT ts.property, ts.value, ts.longValue, ts.valueDefault, ts.label, ts.fieldClass, ts.placeholder
1765  FROM {template_settings} ts
1766  JOIN {settings} s on s.value = ts.templateID
1767  WHERE ts.activated = 1 && s.property = 'selectedTemplate' && ts.property
1768  LIKE '$filter' && ts.property NOT RLIKE '.*-pos' $sql ORDER BY ts.sort";
1769  }
1770  } else {
1771  sys::setSyslog($db, 47, 1, "failed to get template setting - user is not set or empty.", 0, 0, 0, 0);
1772  return false;
1773  }
1774 
1775  if ($res = $db->query($sql)) {
1776  $x = 1; // <h> tags count var
1777  // draw input fields / template-settings.php
1778  while ($row = mysqli_fetch_assoc($res)) { // fetch template settings in loop
1779  $property = $row['property'];
1780  $value = $row['value'];
1781  // $property = substr("$property", 0, -4);
1782  // echo "<label for=\"".$row['property']."\">" . $row['description'] . "</label><br>";
1783 
1784  if ($filter == "h%-fontsize") { // case <h> fontsize
1785  // draw a textfield
1786  echo "<div style=\"display:inline-block;\"><label for=\"" . htmlentities($row['property']) . "\">";
1787  echo "<legend>";
1788  echo "<input type=\"text\" id=\"h" . $x . "-fontsize\" class=\"form-control\" name=\"" . htmlentities($row['property']) . "\" value=\"" . htmlentities($row['value']) . "\" />";
1789  echo "<div id=\"slider$x\"></legend></div>";
1790  $x++;
1791  }
1792  if (fnmatch('*-longValue', $filter)) {
1793  // draw a textfield
1794  echo "<label for=\"" . $row['property'] . "\"><small>" . $row['label'] . " <i class=\"h6 small\">default: " . $row['valueDefault'] . "</i></small></label><br>";
1795  echo "<div style=\"display:inline-block; width:90%;\"><label for=\"" . htmlentities($row['property']) . "\">";
1796  echo "<input type=\"hidden\" name=\"$row[property]-long\" id=\"longValue\" value=\"1\">";
1797  echo "<textarea cols=\"85\" rows=\"12\" id=\"" . $row['property'] . "\" $readonly class=\"form-control\" style=\"font-weight:normal;\" name=\"" . htmlentities($row['property']) . "\">" . $row['longValue'] . "</textarea>";
1798  } else { // draw a textfield
1799  echo "<label for=\"" . $row['property'] . "\"><small>" . $row['label'] . " <i class=\"h6 small\">default: " . $row['valueDefault'] . "</i></small></label><br>";
1800  echo "<div style=\"display:inline-block; \">";
1801  echo "<input id=\"";
1802  echo $row['property'];
1803  echo "\" placeholder=\"";
1804  echo $row['placeholder'];
1805  echo "\" class=\"form-control ";
1806  echo $row['fieldClass'];
1807  echo "\" type=\"text\" size=\"88\" maxlength=\"255\"";
1808  echo $readonly;
1809  echo "name=\"" . htmlentities($row['property']) . "\" value=\"" . htmlentities($row['value']) . "\" /><br>";
1810  }
1811 
1812  if ($special == "slider") { // set slider html
1813  // if method is called with slider parameter, draw one with given property name
1814  echo "<div id=\"slider-";
1815  echo $row['property'];
1816  echo "\"></div>";
1817  }
1818  echo "</div></label>";
1819  }
1820  } else { // q failed
1821  sys::setSyslog($db, 47, 1, "failed to query template setting ", 0, 0, 0, 0);
1822  return false;
1823  }
1824  // all good, fin
1825  return true;
1826  }
1827 
1828  /* END FUNCTION YAWK\settings::getSetting */
1829 
1830  /**
1831  * @brief return a select option list with all fonts:
1832  * @details <ul>
1833  * <li>system default fonts</li>
1834  * <li>own true type fonts from system/fonts</li>
1835  * <li>google fonts from database: gfonts</li>
1836  * </ul>
1837  * @param object $db database
1838  * @param string $selectName selectName
1839  * @param array $lang language array
1840  */
1841  public function drawFontFamilySelectField($db, $lang, $selectName, $defaultValue)
1842  {
1843  if (isset($defaultValue) && (!empty($defaultValue))) {
1844  $defaultValueOption = "<option value=\"$defaultValue\" selected aria-selected=\"true\">$defaultValue</option>";
1845  } else {
1846  $defaultValueOption = '';
1847  }
1848  $selectField = ''; // init var to hold select field html code
1849  $selectField =
1850  "
1851  <select style=\"margin-bottom:10px;\" id=\"$selectName\" name=\"$selectName\" class=\"form-control\">
1852  $defaultValueOption;
1853  <optgroup label=\"System Sans-Serif Fonts\"></optgroup>
1854  <option value=\"Arial, Helvetica, sans-serif\">&nbsp;&nbsp;Arial, Helvetica, sans-serif</option>
1855  <option value=\"Arial Black\">&nbsp;&nbsp;Arial Black</option>
1856  <option value=\"Comic Sans MS, cursive, sans-serif\">&nbsp;&nbsp;Comic Sans</option>
1857  <option value=\"Impact, Charcoal, sans-serif\">&nbsp;&nbsp;Impact, Charcoal, sans-serif</option>
1858  <option value=\"Lucida Sans Unicode, Lucida Grande, sans-serif\">&nbsp;&nbsp;Lucida Sans Unicode, Lucida Grande, sans-serif</option>
1859  <option value=\"Tahoma, Geneva, sans-serif\">&nbsp;&nbsp;Tahoma, Geneva, sans-serif</option>
1860  <option value=\"Trebuchet MS, Helvetica, sans-serif\">&nbsp;&nbsp;Trebuchet MS, Helvetica, sans-serif</option>
1861  <option value=\"Verdana, Geneava, sans-serif\">&nbsp;&nbsp;Verdana, Geneava, sans-serif</option>
1862  <optgroup label=\"System Serif Fonts\"></optgroup>
1863  <option value=\"Georgia, serif\">&nbsp;&nbsp;Georgia, serif</option>
1864  <option value=\"Palatino Linotype, Book Antiqua, Palatino, serif\">&nbsp;&nbsp;Palatino Linotype, Book Antiqua, Palatino, serif</option>
1865  <option value=\"Times New Roman, Times, serif\">&nbsp;&nbsp;Times New Roman, Times, serif</option>
1866  <optgroup label=\"System Monospace Fonts\"></optgroup>
1867  <option value=\"Courier New, Courier, monospace\">&nbsp;&nbsp;Courier New, Courier, monospace</option>
1868  <option value=\"Lucida Console, Monaco, monospace\">&nbsp;&nbsp;Lucida Console, Monaco, monospace</option>";
1869 
1870  // directory iterator walks trough system/fonts
1871  // and build up 3 arrays: ttf fonts, otf fonts and woff fonts
1872  // afterwards they get processed and drawn
1873  if (is_dir($this->ttfPath)) // only if directory exists, otherwise skip
1874  {
1875  $dir = new \DirectoryIterator($this->ttfPath);
1876  $ttfFonts = array(); // all .ttf files
1877  $otfFonts = array(); // all .otf files
1878  $woffFonts = array(); // all .woff files
1879 
1880  foreach ($dir as $item) {
1881  if (!$item->isDot()
1882  && (!$item->isDir())
1883  ) {
1884  // workaround: todo what about filenames with spaces?
1885  // check if it is a true type file
1886  if (strtolower(substr($item, -3)) === "ttf") {
1887  // workaround: if dots are in there, the form does not work.
1888  // so lets change the dots to '-' and let option pass trough
1889  $item = str_replace(".", "-", $item);
1890  // add ttf font to array
1891  $ttfFonts[] = "<option value=\"$item\">&nbsp;&nbsp;$item</option>";
1892  }
1893  // check if it is a otf file
1894  if (strtolower(substr($item, -3)) === "otf") {
1895  $item = str_replace(".", "-", $item);
1896  // add option to select field
1897  $otfFonts[] = "<option value=\"$item\">&nbsp;&nbsp;$item</option>";
1898  }
1899  // check if it is a woff file
1900  if (strtolower(substr($item, -4)) === "woff") {
1901  // workaround: change dots to '-' to let option pass trough
1902  $item = str_replace(".", "-", $item);
1903  // add option to select field
1904  $woffFonts[] = "<option value=\"$item\">&nbsp;&nbsp;$item</option>";
1905  }
1906  }
1907  } // end if is_dir
1908 
1909  // add .ttf fonts to select option
1910  $selectField .= "<optgroup label=\"True Type Fonts (system/fonts/*.ttf)\"></optgroup>";
1911  foreach ($ttfFonts as $ttfFont) { // add ttf option to select field
1912  $selectField .= $ttfFont;
1913  }
1914  // add .otf fonts to select option
1915  $selectField .= "<optgroup label=\"Open Type Fonts (system/fonts/*.otf)\"></optgroup>";
1916  foreach ($otfFonts as $otfFont) { // add ttf option to select field
1917  $selectField .= $otfFont;
1918  }
1919  // add .woff fonts to select option
1920  $selectField .= "<optgroup label=\"Web Open Font Format (system/fonts/*.woff)\"></optgroup>";
1921  foreach ($woffFonts as $woffFont) { // add ttf option to select field
1922  $selectField .= $woffFont;
1923  }
1924  }
1925 
1926 
1927  // fill google fonts array
1928  $googleFonts = $this->getGoogleFontsArray($db);
1929  // add google fonts to select option
1930  $selectField .= "<optgroup label=\"Google Fonts\"></optgroup>";
1931  foreach ($googleFonts as $gFont) {
1932  // add google font option to select field
1933  // add option to select field
1934  $selectField .= "<option value=\"$gFont-gfont\">&nbsp;&nbsp;$gFont (Google Font)</option>";
1935  }
1936  // close select option
1937  $selectField .= "</select>";
1938 
1939  // finally: output the html code of this select field
1940  return $selectField;
1941  }
1942 
1943  /**
1944  * @brief get all google fonts into an array and return array
1945  * @param object $db database
1946  * @return array | null
1947  *
1948  */
1949  public static function getGoogleFontsArray($db)
1950  {
1951  // array that holds the data
1952  $googleFonts = array();
1953  // select google fonts from database
1954  if ($sql = $db->query("SELECT font FROM {gfonts} ORDER BY font")) { // for every single row...
1955  while ($row = mysqli_fetch_array($sql)) { // add font to array
1956  $googleFonts[] = $row['0'];
1957  }
1958  }
1959  // check if googleFont is set and an array and not empty
1960  if (isset($googleFonts) && (is_array($googleFonts) && (!empty($googleFonts)))) { // return array containing all google fonts
1961  return $googleFonts;
1962  } else { // no google font in database...
1963  return null;
1964  }
1965  }
1966 
1967  /**
1968  * @brief return a radio list of all registered google fonts
1969  * @param object $db database
1970  * @param string $item the font
1971  * @param array $lang language array
1972  * @return bool
1973  */
1974  function getgFonts($db, $item, $lang)
1975  {
1976  /** @var $db \YAWK\db */
1977  $nc = '';
1978  $gfontID = '';
1979  // query fonts
1980  if ($res = $db->query("SELECT ts.property, ts.value, ts.description
1981  FROM {template_settings} ts
1982  JOIN {settings} s on s.value = ts.templateID
1983  WHERE ts.activated = 1 && s.property = 'selectedTemplate' && ts.property = '$item'
1984  ORDER BY sort")
1985  ) {
1986  // draw radio buttons in loop...
1987  while ($row = mysqli_fetch_assoc($res)) {
1988  $gfontID = $row['value'];
1989  if ($gfontID === '0') { // checked
1990  $nc = "checked=\"checked\"";
1991  } else { // not checked
1992  $nc = "";
1993  }
1994  }
1995  echo "<div id=\"nogooglefont\">
1996  <label for=\"fontType\">$lang[FONT_TYPE_SELECTOR]</label>
1997  <select id=\"fontType\" name=\"fontType\" class=\"form-control\">
1998  <optgroup label=\"System Fonts\">
1999  <option value=\"helvetica\">Helvetica</option>
2000  <option value=\"arial\">Arial</option>
2001  <option value=\"verdana\">Verdana</option>
2002  <optgroup label=\"Own TrueType Font (system/fonts)\">
2003 
2004  </select>
2005  </div><br>";
2006 
2007  // <input type=\"radio\" name=\"global-gfont\" value=\"0\" $nc> | Use system default fonts
2008 
2009  echo "<div id=\"googlefontcontainer\">";
2010 
2011  if ($res = $db->query("SELECT id, font, description, activated
2012  FROM {gfonts}
2013  WHERE activated = 1
2014  AND id != 0
2015  ORDER BY font")
2016  ) {
2017  while ($row = mysqli_fetch_array($res)) {
2018  // test output:
2019  $id = $row[0];
2020  $value = $row[1];
2021  $description = $row[2];
2022  if ($gfontID === "$id") {
2023  $checked = "checked=\"checked\"";
2024  } else {
2025  $checked = "";
2026  }
2027 
2028  echo "<link href=\"http://fonts.googleapis.com/css?family=$row[1]\" rel=\"stylesheet\" type=\"text/css\">";
2029  echo "<div id=\"googlefont\">
2030 <a class=\"pull-right\" data-confirm=\"Google Font &laquo;$value&raquo; wirklich l&ouml;schen?\" href='index.php?page=template-edit&deletegfont=1&gfontid=$id'><i style=\"margin-bottom:5px;\" class=\"fa fa-trash-o\"></i></a>
2031 <input type=\"radio\" $checked name=\"" . $item . "\" value=\"$id\">
2032 | <span style=\"font-family:$row[1]; font-size:18px;\">$description</span>
2033 <hr></div>";
2034  } // ./ end while
2035  } else { // fetch loop failed
2036  return false;
2037  }
2038  echo "</div>";
2039  } else { // q failed;
2040  sys::setSyslog($db, 47, 1, "failed to get google fonts from database ", 0, 0, 0, 0);
2041  return false;
2042  }
2043  // fin
2044  return true;
2045  } // ./ function getgFonts
2046 
2047 
2048  /**
2049  * @brief delete google font with requested ID
2050  * @param object $db database
2051  * @param int $gfontid google font ID you wish to delete
2052  * @param string $gfont google font (name) you wish to delete
2053  * @return bool
2054  */
2055  public static function deleteGfont($db, $gfontid, $gfont)
2056  {
2057  /** @var $db \YAWK\db */
2058 
2059  // no google font ID was sent
2060  if (!isset($gfontid) || (empty($gfontid))) { // check if google font name was sent
2061  if (isset($gfont) && (!empty($gfont))) {
2062  // try to delete google font by name
2063  if ($res = $db->query("DELETE from {gfonts}
2064  WHERE font LIKE '%" . $gfont . "%'")
2065  ) { // success
2066  return true;
2067  } else { // q failed
2068  sys::setSyslog($db, 47, 1, "failed to delete google font ID: $gfontid ", 0, 0, 0, 0);
2069  return false;
2070  }
2071  }
2072  } else { // delete google font by ID
2073  if ($res = $db->query("DELETE from {gfonts}
2074  WHERE id = '" . $gfontid . "'")
2075  ) { // success
2076  return true;
2077  } else { // q failed
2078  sys::setSyslog($db, 47, 1, "failed to delete google font ID: $gfontid ", 0, 0, 0, 0);
2079  return false;
2080  }
2081  }
2082  return false;
2083  }
2084 
2085  /**
2086  * @brief add google font to database
2087  * @param object $db database
2088  * @param string $gfont name of the google font you wish to add
2089  * @param string $description any description for the font (eg. YourFont, cursive)
2090  * @return bool
2091  */
2092  public static function addgfont($db, $gfont, $description)
2093  {
2094  /** @var $db \YAWK\db */
2095  if (empty($gfont)) { // no font was sent
2096  return false;
2097  }
2098  if (empty($description)) { // no description was sent
2099  return false;
2100  }
2101  $gfont = $db->quote($gfont);
2102  $description = $db->quote($description);
2103  // ## select max ID from gfonts
2104  if ($res = $db->query("SELECT MAX(id) FROM {gfonts}")) { // fetch data
2105  $row = mysqli_fetch_row($res);
2106  $id = $row[0] + 1;
2107  if ($res = $db->query("INSERT INTO {gfonts} (id, font, description)
2108  VALUES('" . $id . "', '" . $gfont . "', '" . $description . "')")
2109  ) { // success
2110  return true;
2111  } else { // fetch failed
2112  sys::setSyslog($db, 47, 1, "failed to insert new google font to database", 0, 0, 0, 0);
2113  return false;
2114  }
2115  } else { // q failed
2116  sys::setSyslog($db, 47, 1, "failed to get MAX(id) from google fonts database", 0, 0, 0, 0);
2117  return false;
2118  }
2119  }
2120 
2121  /**
2122  * @brief set css code for custom fonts (ttf / otf / woff)
2123  * @param $cssTagName
2124  * @param $tplSettings
2125  * @return string
2126  */
2127  static function setCssBodyFontFace($cssTagName, $tplSettings)
2128  {
2129  $bodyFontFaceCSS = '';
2130  $fontFamily = $tplSettings["$cssTagName-fontfamily"];
2131  // get font type by cutting off file extension
2132  $fontType = substr($fontFamily, -4);
2133  // check file types
2134  if ($fontType === "-ttf") {
2135  $filename = str_replace("-ttf", ".ttf", $fontFamily);
2136  $bodyFontFaceCSS = "@font-face {
2137  font-family: $fontFamily;
2138  src: url('../../../fonts/$filename');
2139  }";
2140  } elseif ($fontType === "-otf") {
2141  $filename = str_replace("-otf", ".otf", $fontFamily);
2142  $bodyFontFaceCSS = "@font-face {
2143  font-family: $fontFamily;
2144  src: url('../../../fonts/$filename');
2145  }";
2146  } elseif ($fontType === "woff") {
2147  $filename = str_replace("-woff", ".woff", $fontFamily);
2148  $bodyFontFaceCSS = "@font-face {
2149  font-family: $fontFamily;
2150  src: url('../../../fonts/$filename') !important;
2151  }";
2152  }
2153  return $bodyFontFaceCSS;
2154  }
2155 
2156  /**
2157  * @brief set css code for body link styling
2158  * @param $cssTagName
2159  * @param $tplSettings
2160  * @return string
2161  */
2162  static function setCssBodyLinkTags($cssTagName, $tplSettings)
2163  {
2164  $aLink = $tplSettings["$cssTagName-alink"];
2165  $aVisited = $tplSettings["$cssTagName-avisited"];
2166  $aHover = $tplSettings["$cssTagName-ahover"];
2167  $aWeight = $tplSettings["$cssTagName-linkfontweight"];
2168  $aStyle = $tplSettings["$cssTagName-linkfontstyle"];
2169  $aDecoration = $tplSettings["$cssTagName-linktextdecoration"];
2170  $hoverDecoration = $tplSettings["$cssTagName-hovertextdecoration"];
2171  $bodyLinkTags = "
2172  /* TODO: must be out of body */
2173  a:link {
2174  color: #$aLink;
2175  font-weight: $aWeight;
2176  font-style: $aStyle;
2177  text-decoration: $aDecoration;
2178  }
2179  a:visited {
2180  color: #$aVisited;
2181  }
2182  a:hover {
2183  color: #$aHover;
2184  text-decoration: $hoverDecoration;
2185  }
2186  ";
2187  return $bodyLinkTags;
2188  }
2189 
2190  /**
2191  * @brief set small font settings css code
2192  * @param $cssTagName
2193  * @param $tplSettings
2194  * @return string
2195  */
2196  static function setCssBodySmallFontSettings($cssTagName, $tplSettings)
2197  {
2198  $smallColor = $tplSettings["$cssTagName-smallcolor"];
2199  $smallShadowSize = $tplSettings["$cssTagName-smallshadowsize"];
2200  $smallShadowColor = $tplSettings["$cssTagName-smallshadowcolor"];
2201 
2202  $bodySmallTags = "small,
2203  .small
2204  {
2205  font-weight: normal;
2206  line-height: 1;
2207  color: #$smallColor;
2208  text-shadow: $smallShadowSize #$smallShadowColor;
2209  }
2210  ";
2211  return $bodySmallTags;
2212  }
2213 
2214  /**
2215  * @brief set body font settings css code
2216  * @param $cssTagName
2217  * @param $tplSettings
2218  * @return string
2219  */
2220  static function setCssBodyFontSettings($cssTagName, $tplSettings)
2221  {
2222  $fontFamily = $tplSettings["$cssTagName-fontfamily"];
2223  $fontSize = $tplSettings["$cssTagName-size"];
2224  $fontColor = $tplSettings["$cssTagName-fontcolor"];
2225  $fontShadowSize = $tplSettings["$cssTagName-fontshadowsize"];
2226  $fontShadowColor = $tplSettings["$cssTagName-fontshadowcolor"];
2227  $fontWeight = $tplSettings["$cssTagName-fontweight"];
2228  $fontStyle = $tplSettings["$cssTagName-fontstyle"];
2229  $fontTextDecoration = $tplSettings["$cssTagName-textdecoration"];
2230  // check, if it's a google font
2231  if (substr($fontFamily, -6) === "-gfont") {
2232  $googleFont = substr($fontFamily, 0, -6);
2233  $bodyFontCSS = "
2234  font-family: $googleFont !important;
2235  font-size: $fontSize;
2236  color: #$fontColor;
2237  text-shadow: $fontShadowSize #$fontShadowColor;
2238  font-weight: $fontWeight;
2239  font-style: $fontStyle;
2240  text-decoration: $fontTextDecoration;
2241  ";
2242  } else {
2243  $bodyFontCSS = "
2244  font-family: $fontFamily;
2245  font-size: $fontSize;
2246  color: #$fontColor;
2247  text-shadow: $fontShadowSize #$fontShadowColor;
2248  font-weight: $fontWeight;
2249  font-style: $fontStyle;
2250  text-decoration: $fontTextDecoration;
2251  ";
2252  }
2253  return $bodyFontCSS;
2254  }
2255 
2256  /**
2257  * @brief set font settings css code
2258  * @param $cssTagName
2259  * @param $tplSettings
2260  * @return string
2261  */
2262  static function setCssFontSettings($cssTagName, $tplSettings)
2263  {
2264  $fontFamily = $tplSettings["$cssTagName-fontfamily"];
2265  $fontSize = $tplSettings["$cssTagName-size"];
2266  $fontColor = $tplSettings["$cssTagName-fontcolor"];
2267  $fontShadowSize = $tplSettings["$cssTagName-fontshadowsize"];
2268  $fontShadowColor = $tplSettings["$cssTagName-fontshadowcolor"];
2269  $fontWeight = $tplSettings["$cssTagName-fontweight"];
2270  $fontStyle = $tplSettings["$cssTagName-fontstyle"];
2271  $fontTextDecoration = $tplSettings["$cssTagName-textdecoration"];
2272  $aLink = $tplSettings["$cssTagName-alink"];
2273  $aVisited = $tplSettings["$cssTagName-avisited"];
2274  $aHover = $tplSettings["$cssTagName-ahover"];
2275  $aWeight = $tplSettings["$cssTagName-linkfontweight"];
2276  $aStyle = $tplSettings["$cssTagName-linkfontstyle"];
2277  $aDecoration = $tplSettings["$cssTagName-linktextdecoration"];
2278  $hoverDecoration = $tplSettings["$cssTagName-hovertextdecoration"];
2279  $smallColor = $tplSettings["$cssTagName-smallcolor"];
2280  $smallShadowSize = $tplSettings["$cssTagName-smallshadowsize"];
2281  $smallShadowColor = $tplSettings["$cssTagName-smallshadowcolor"];
2282 
2283  // get font type by cutting off file extension
2284  $fontType = substr($fontFamily, -4);
2285  // check file types
2286  if ($fontType === "-ttf") {
2287  $filename = str_replace("-ttf", ".ttf", $fontFamily);
2288  $fontCSS = "@font-face {
2289  font-family: $fontFamily;
2290  src: url('../../../fonts/$filename');
2291  }
2292  $cssTagName
2293  {
2294  font-family: $fontFamily !important;
2295  font-size: $fontSize;
2296  color: #$fontColor;
2297  text-shadow: $fontShadowSize #$fontShadowColor;
2298  font-weight: $fontWeight;
2299  font-style: $fontStyle;
2300  text-decoration: $fontTextDecoration;
2301  }
2302  $cssTagName a:link { /* LINK SETTINGS */
2303  color: #$aLink;
2304  font-weight: $aWeight;
2305  font-style: $aStyle;
2306  text-decoration: $aDecoration;
2307  }
2308  $cssTagName a:visited {
2309  color: #$aVisited;
2310  }
2311  $cssTagName a:hover {
2312  color: #$aHover;
2313  text-decoration: $hoverDecoration;
2314  }
2315  $cssTagName small,
2316  .$cssTagName small
2317  {
2318  font-weight: normal;
2319  line-height: 1;
2320  color: #$smallColor;
2321  text-shadow: $smallShadowSize #$smallShadowColor;
2322  }
2323  ";
2324  } elseif ($fontType === "-otf") {
2325  $filename = str_replace("-otf", ".otf", $fontFamily);
2326  $fontCSS = "@font-face {
2327  font-family: $fontFamily;
2328  src: url('../../../fonts/$filename');
2329  }
2330  $cssTagName
2331  {
2332  font-family: $fontFamily !important;
2333  font-size: $fontSize;
2334  color: #$fontColor;
2335  text-shadow: $fontShadowSize #$fontShadowColor;
2336  font-weight: $fontWeight;
2337  font-style: $fontStyle;
2338  text-decoration: $fontTextDecoration;
2339  }
2340  $cssTagName a:link { /* LINK SETTINGS */
2341  color: #$aLink;
2342  font-weight: $aWeight;
2343  font-style: $aStyle;
2344  text-decoration: $aDecoration;
2345  }
2346  $cssTagName a:visited {
2347  color: #$aVisited;
2348  }
2349  $cssTagName a:hover {
2350  color: #$aHover;
2351  text-decoration: $hoverDecoration;
2352  }
2353  $cssTagName small,
2354  .$cssTagName small
2355  {
2356  font-weight: normal;
2357  line-height: 1;
2358  color: #$smallColor;
2359  text-shadow: $smallShadowSize #$smallShadowColor;
2360  }
2361  ";
2362  } elseif ($fontType === "woff") {
2363  $filename = str_replace("-woff", ".woff", $fontFamily);
2364  $fontCSS = "@font-face {
2365  font-family: $fontFamily;
2366  src: url('../../../fonts/$filename') !important;
2367  }
2368  $cssTagName
2369  {
2370  font-family: $fontFamily !important;
2371  font-size: $fontSize;
2372  color: #$fontColor;
2373  text-shadow: $fontShadowSize #$fontShadowColor;
2374  font-weight: $fontWeight;
2375  font-style: $fontStyle;
2376  text-decoration: $fontTextDecoration;
2377  }
2378  $cssTagName a:link { /* LINK SETTINGS */
2379  color: #$aLink;
2380  font-weight: $aWeight;
2381  font-style: $aStyle;
2382  text-decoration: $aDecoration;
2383  }
2384  $cssTagName a:visited {
2385  color: #$aVisited;
2386  }
2387  $cssTagName a:hover {
2388  color: #$aHover;
2389  text-decoration: $hoverDecoration;
2390  }
2391  $cssTagName small,
2392  .$cssTagName small
2393  {
2394  font-weight: normal;
2395  line-height: 1;
2396  color: #$smallColor;
2397  text-shadow: $smallShadowSize #$smallShadowColor;
2398  }
2399  ";
2400  } // check, if it's a google font
2401  elseif (substr($fontFamily, -6) === "-gfont") {
2402  $googleFont = substr($fontFamily, 0, -6);
2403  $fontCSS = "
2404  $cssTagName
2405  {
2406  font-family: $googleFont !important;
2407  font-size: $fontSize;
2408  color: #$fontColor;
2409  text-shadow: $fontShadowSize #$fontShadowColor;
2410  font-weight: $fontWeight;
2411  font-style: $fontStyle;
2412  text-decoration: $fontTextDecoration;
2413  }
2414 
2415  $cssTagName a:link { /* LINK SETTINGS */
2416  color: #$aLink;
2417  font-weight: $aWeight;
2418  font-style: $aStyle;
2419  text-decoration: $aDecoration;
2420  }
2421  $cssTagName a:visited {
2422  color: #$aVisited;
2423  }
2424  $cssTagName a:hover {
2425  color: #$aHover;
2426  text-decoration: $hoverDecoration;
2427  }
2428  $cssTagName small,
2429  .$cssTagName small
2430  {
2431  font-weight: normal;
2432  line-height: 1;
2433  color: #$smallColor;
2434  text-shadow: $smallShadowSize #$smallShadowColor;
2435  }
2436  ";
2437  } else {
2438  $fontCSS = "
2439  $cssTagName
2440  {
2441  font-family: $fontFamily;
2442  font-size: $fontSize;
2443  color: #$fontColor;
2444  text-shadow: $fontShadowSize #$fontShadowColor;
2445  font-weight: $fontWeight;
2446  font-style: $fontStyle;
2447  text-decoration: $fontTextDecoration;
2448  }
2449 
2450  $cssTagName a:link { /* LINK SETTINGS */
2451  color: #$aLink;
2452  font-weight: $aWeight;
2453  font-style: $aStyle;
2454  text-decoration: $aDecoration;
2455  }
2456  $cssTagName a:visited {
2457  color: #$aVisited;
2458  }
2459  $cssTagName a:hover {
2460  color: #$aHover;
2461  text-decoration: $hoverDecoration;
2462  }
2463  $cssTagName small,
2464  .$cssTagName small
2465  {
2466  font-weight: normal;
2467  line-height: 1;
2468  color: #$smallColor;
2469  text-shadow: $smallShadowSize #$smallShadowColor;
2470  }
2471  ";
2472  }
2473  return $fontCSS;
2474  }
2475 
2476  /**
2477  * @brief Get and return current active google font
2478  * @param $db
2479  * @return string
2480  */
2481  static function getActiveBodyFont($db, $user, $template)
2482  {
2483  /* @var \YAWK\db $db */
2484  $bodyFont = template::getTemplateSetting($db, "value", "globaltext-fontfamily", $user, $template);
2485  $bodyFontFamily = "font-family: $bodyFont";
2486  return $bodyFontFamily;
2487  }
2488 
2489  /**
2490  * @brief return currently active google font
2491  * @param object $db database
2492  * @param string $status the url or font name
2493  * @param string $property affected settings property
2494  * @return null|string
2495  */
2496  static function getActivegfont($db, $status, $property)
2497  {
2498  /* @var \YAWK\db $db */
2499  if ($res = $db->query("SELECT id, font, setting
2500  FROM {gfonts}
2501  WHERE activated = 1
2502  AND id = (SELECT ts.value
2503  FROM {template_settings} ts
2504  JOIN {settings} s on s.value = ts.templateID
2505  WHERE ts.activated = 1 && s.property = 'selectedTemplate' && ts.property = '$property')")
2506  ) {
2507  while ($row = mysqli_fetch_array($res)) {
2508  // if no google font is selected
2509  if ($row[1] === "0") {
2510  return "font-family: Arial";
2511  }
2512  // css include output for index.php
2513  if ($status == "url") {//
2514  if (isset($row[2]) || (!empty($row[2]))) {
2515  return "
2516 <link rel=\"stylesheet\" href=\"http://fonts.googleapis.com/css?family=$row[1]:$row[2]\" type=\"text/css\" media=\"all\">";
2517  } else {
2518  return "
2519 <link rel=\"stylesheet\" href=\"http://fonts.googleapis.com/css?family=$row[1]\" type=\"text/css\" media=\"all\">";
2520  }
2521  } else {
2522  return "font-family: $row[1];";
2523  }
2524  }
2525  } else { // could not get active google font
2526  return "could not get active google font";
2527  }
2528  return null;
2529  }
2530 
2531  /**
2532  * @brief get settings for heading, menu and text font and output html to load font
2533  * @param object $db database
2534  */
2535  // TODO: OUTDATED AFTER REFACTORING...
2536  static function loadGoogleFonts($db)
2537  {
2538  $fonts = array(); // hold all fonts
2539  $googleFontFamilyString = ''; // the string the contains all google font families to minimize requests
2540  if ($sql = $db->query("SELECT value FROM {template_settings} WHERE property LIKE '%-fontfamily'")) {
2541  while ($row = mysqli_fetch_row($sql)) {
2542  $fonts[] = $row[0];
2543  }
2544  }
2545  foreach ($fonts as $googleFont) {
2546  if (substr($googleFont, -6) === "-gfont") {
2547  // remove font indicator
2548  $googleFont = rtrim($googleFont, "gfont");
2549  $googleFont = rtrim($googleFont, "-");
2550  // build google font loading string
2551  $googleFontFamilyString .= $googleFont;
2552  // add | to allow loading more than one font
2553  $googleFontFamilyString .= "|";
2554  }
2555  }
2556  if (!empty($googleFontFamilyString)) {
2557  // remove last | because its not needed
2558  $googleFontFamilyString = rtrim($googleFontFamilyString, "|");
2559  echo "<link rel=\"dns-prefetch\" href=\"//fonts.googleapis.com\">";
2560  echo "<link href=\"https://fonts.googleapis.com/css?family=$googleFontFamilyString\" rel=\"stylesheet\">";
2561  }
2562 
2563  }
2564 
2565  /**
2566  * @brief get any template setting from database
2567  * @param object $db database
2568  * @param string $field the setting (field) to get
2569  * @param string $property the property to get
2570  * @return bool
2571  */
2572  static function getTemplateSetting($db, $field, $property, $user, $template)
2573  { /** @var $db \YAWK\db */
2574 
2575  // to ensure, we get the setting of the correct template get a valid template ID
2576  $validTemplateID = template::getValidTemplateID($db, $user, $template);
2577 
2578  // query the template setting
2579  if ($row = $db->query("SELECT $field
2580  FROM {template_settings}
2581  WHERE property = '" . $property . "'
2582  AND templateID = '" . $validTemplateID . "'"))
2583  { // fetch data
2584  $res = mysqli_fetch_row($row);
2585  if (!empty($res))
2586  { // return valid template ID
2587  return $res[0];
2588  }
2589  else
2590  {
2591  return false;
2592  }
2593  }
2594  }
2595 
2596  /**
2597  * @brief check the current template ID, considering if user is logged in, allowed to override template and so on
2598  * @param object $db database
2599  * @param object $user the current user object
2600  * @param object $template the current page object
2601  * @return int
2602  */
2603  static function getValidTemplateID($db, $user, $template)
2604  {
2605  // it is important to do some checks to determine the correct template id
2606  // to do that, we need data from 2 objects;
2607 
2608  // check if template and user obj are there and not empty
2609  if (isset($user) && (isset($template)))
2610  { // check, if user is allowed to override template
2611 
2612  if ($user->overrideTemplate == 1)
2613  { // ok, get user templateID
2614  if (!empty($user->templateID))
2615  { // set templateID for following query
2616  $validTemplateID = $user->templateID;
2617  }
2618  else
2619  { // user->TemplateID not set, instead use default template
2620  if (!empty($template->selectedTemplate))
2621  { // set global defined (current active), default template ID
2622  $validTemplateID = $template->selectedTemplate;
2623  }
2624  }
2625  }
2626  else
2627  { // user is not allowed to override template, use default template
2628  if (!empty($template->selectedTemplate))
2629  { // set global defined (current active), default template ID
2630  $validTemplateID = $template->selectedTemplate;
2631  }
2632  }
2633  }
2634  else
2635  { // unable to determine template from objects, load active (global) template instead
2636  $validTemplateID = settings::getSetting($db, "selectedTemplate");
2637  }
2638  // for any reasons, that valid template ID could not be set
2639  if (!isset($validTemplateID) || (empty($validTemplateID)))
2640  { // set current (active / selected) template as templateID
2641  $validTemplateID = settings::getSetting($db, "selectedTemplate");
2642  }
2643  // must be set
2644  return $validTemplateID;
2645  }
2646 
2647  /**
2648  * @brief include header for html page *outdated? *moved to sys?
2649  * @param object $db database
2650  */
2651  static function includeHeader($db)
2652  {
2653  /** @param \YAWK\db $db */
2654  global $currentpage;
2655  $i = 1;
2656  $host = settings::getSetting($db, "host");
2657  echo "<title>" . $currentpage->title . "</title>
2658  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=\"utf-8\">
2659  <link rel=\"shortcut icon\" href=\"favicon.ico\" type=\"image/x-icon\">
2660  <base href=\"" . $host . "/\">";
2661  $get_localtags = $db->query("SELECT name, content
2662  FROM {meta_local}
2663  WHERE page = '" . $currentpage->id . "'");
2664  while ($row = mysqli_fetch_row($get_localtags)) {
2665  if (isset($row['1']) && !empty($row['1'])) {
2666  echo "<meta name=\"" . $row[0] . "\" content=\"" . $row[1] . "\" />";
2667  } else {
2668  $get_globaltags = $db->query("SELECT content
2669  FROM {meta_global}
2670  WHERE name = 'description'");
2671  $row = mysqli_fetch_row($get_globaltags);
2672  while ($i > 0) {
2673  echo "<meta name=\"description\" content=\"" . $row[0] . "\" />";
2674  $i--;
2675  }
2676  }
2677  }
2678  }
2679 
2680  /**
2681  * @brief get the position states of all templates. This is used on index.php to render only templates that are enabled (1)
2682  * @param object $db database
2683  * @param int $templateID ID of the current selected template
2684  * @return array|bool $array template positions 0|1
2685  */
2687  {
2688  $array = array();
2689  $sql = $db->query("SELECT property, value
2690  FROM {template_settings}
2691  WHERE property LIKE 'pos-%-enabled' AND
2692  templateID = '" . $templateID . "'");
2693  while ($row = mysqli_fetch_assoc($sql)) {
2694  $prop = $row['property'];
2695  $array[$prop] = $row['value'];
2696  }
2697  if (is_array($array) && (!empty($array))) {
2698  return $array;
2699  } else {
2700  die("Positions array not set");
2701  }
2702  }
2703 
2704  /**
2705  * @brief get the position indicators. This is used on index.php to mark indicated positions
2706  * @param object $db database
2707  * @param int $templateID ID of the current template
2708  * @return array|bool $array position indicator 0|1
2709  */
2711  {
2712  $markedPositions = array();
2713  $sql = $db->query("SELECT property, value
2714  FROM {template_settings}
2715  WHERE property
2716  LIKE 'pos-%-indicator'
2717  AND templateID = '" . $templateID . "'");
2718  while ($row = mysqli_fetch_assoc($sql)) {
2719  $prop = $row['property'];
2720  $markedPositions[$prop] = $row['value'];
2721  }
2722  if (!empty($markedPositions)) {
2723  return $markedPositions;
2724  } else {
2725  return false;
2726  }
2727  }
2728 
2729  /**
2730  * @brief set template position and output the correct data depending on position
2731  * @param object $db database
2732  * @param object $user the current user object
2733  * @param string $position the template position
2734  * @param object $template template object
2735  */
2736  static function setPosition($db, $lang, $position, $currentpage, $user, $template)
2737  {
2738  $main_set = 0;
2739  $globalmenu_set = 0;
2740  // get template setting for given pos
2741  // $setting = self::getTemplateSetting($db, $position, "");
2742  if (empty($setting)) {
2743  // no property
2744  // substr, because css definitions are without -pos (changefix?!)
2745  $position = substr("$position", 0, -4);
2746  // if main, we need to include the content page
2747  if ($position == "main") {
2748  // if user is given to index.php, load userpage
2749  if (isset($_GET['user'])) {
2750  // if var is set, but empty, show all users
2751  if (empty($_GET['user'])) {
2752  echo "<h2>Show all users</h2>";
2754  } else {
2755  // show userpage
2756  echo "<h2>Show Profile of user $_GET[user]</h2>";
2757  }
2758  } // if a blog is requested, load blog by given id
2759  elseif (isset($_GET['blogid'])) {
2760  $blog = new \YAWK\PLUGINS\BLOG\blog();
2761  $blog->limitEntries = $blog->getBlogProperty($db, $_GET['blogid'], "limitEntries");
2762  $blog->getFrontendEntries($db, $_GET['blogid'], '', '', $blog->limitEntries);
2763  $blog->getFooter($db);
2764  $blog->draw();
2765  // in any other case, get content for requested static page
2766  } else {
2767  echo "<div id=\"$position\">";
2768  $currentpage->getContent($db, $lang);
2769  echo "</div>";
2770  $main_set = 1;
2771  }
2772  }
2773 
2774  // if position is globalmenu
2775  if ($position == "globalmenu") {
2776  \YAWK\menu::displayGlobalMenu($db, $user, $template);
2777  $globalmenu_set = 1;
2778  }
2779  // in any other case, simply load a div box onto given position
2780  if (!$globalmenu_set == 1) {
2781  echo "<div id=\"$position\">";
2782  echo \YAWK\widget::loadWidgets($db, $position);
2783  echo "</div>";
2784  }
2785  }
2786  }
2787 
2788  /**
2789  * @brief get all template settings into an array and return it
2790  * @param object $db database
2791  * @param int $templateID affected template ID
2792  * @return array
2793  */
2795  {
2796  /* @var \YAWK\db $db */
2797  if (!isset($templateID) || (empty($templateID))) { // if no templateID is set, take current template ID from settings db
2798  $templateID = settings::getSetting($db, "selectedTemplate");
2799  }
2800  $array = array();
2801  $res = $db->query("SELECT property, value, longValue
2802  FROM {template_settings}
2803  WHERE templateID = $templateID");
2804 
2805  while ($row = mysqli_fetch_assoc($res)) {
2806  $prop = $row['property'];
2807  $array[$prop] = $row['value'];
2808  $array[$prop] .= $row['longValue'];
2809  }
2810  return $array;
2811  }
2812 
2813  /**
2814  * @brief check if an admin LTE wrapper should be loaded around the backend content.
2815  * This function must be called at the top of every backend page (admin/includes/xyz.php)
2816  * @param array $lang language array
2817  * @return null
2818  */
2819  static function checkWrapper($lang, $title, $subtitle)
2820  {
2821  /* @var \YAWK\db $db */
2822  if (!isset($_GET['hideWrapper'])) {
2823  // draw the admin lte wrapper around content to include breadcrumbs and start content section
2824  // TEMPLATE WRAPPER - HEADER & breadcrumbs
2825  echo "
2826  <!-- Content Wrapper. Contains page content -->
2827  <div class=\"content-wrapper\" id=\"content-FX\">
2828  <!-- Content Header (Page header) -->
2829  <section class=\"content-header\">";
2830  /* draw Title on top */
2831  echo \YAWK\backend::getTitle($lang[$title], $lang[$subtitle]);
2832  echo "<ol class=\"breadcrumb\">
2833  <li><a href=\"index.php\" title=\"$lang[DASHBOARD]\"><i class=\"fa fa-dashboard\"></i> $lang[DASHBOARD]</a></li>
2834  <li><a href=\"index.php?page=users\" class=\"active\" title=\"$lang[USERS]\"> $lang[USERS]</a></li>
2835  </ol>
2836  </section>
2837  <!-- Main content -->
2838  <section class=\"content\">";
2839  /* page content start here */
2840  return null;
2841  } else // if wrapper is set
2842  { // check if hide status is 1
2843  if ($_GET['hideWrapper'] === 1) {
2844  // no wrapper needed - do nothing
2845  }
2846  }
2847  return null;
2848  }
2849 
2850  /**
2851  * @brief Return a multidimensional array with all assets by requested type.
2852  * @details If no type is set, or type == 0, all assets will be returned.
2853  * @param object $db database object
2854  * @param int $type 0 = all, 1 = required, 2 = optional, 3 = additional
2855  * @return array
2856  */
2857  public static function getAssetsByType($db, $type)
2858  {
2859  /* @var \YAWK\db $db */
2860  // check if type is set
2861  if (!isset($type) || (empty($type))) { // if its not set, get all assets from db, no matter which type they are
2862  $typeSQLCode = ''; // terminate db query
2863  } else { // check if type is a number
2864  if (is_numeric($type) || (is_int($type))) { // and build additional sql string
2865  $typeSQLCode = "AND type = '$type'";
2866 
2867  // if type is zero, fetch all data
2868  if ($type === 0) { // terminate db query
2869  $typeSQLCode = '';
2870  }
2871  } else { // type is not a number, get all data
2872  $typeSQLCode = ''; // terminate db query
2873  }
2874  }
2875 
2876  // init a new empty array
2877  $assets = array();
2878  // get assets from database
2879  $res = $db->query("SELECT *
2880  FROM {assets_types}
2881  WHERE published = '1'
2882  $typeSQLCode ORDER by sortation, asset");
2883  // fetch data in loop
2884  while ($row = mysqli_fetch_assoc($res)) { // build assets array
2885  $prop = $row['asset'];
2886  $assets[$prop]["asset"] = $prop;
2887  $assets[$prop]["property"] = $row['property'];
2888  $assets[$prop]["internal"] = $row['internal'];
2889  $assets[$prop]["url1"] = $row['url1'];
2890  $assets[$prop]["url2"] = $row['url2'];
2891  $assets[$prop]["url3"] = $row['url3'];
2892  $assets[$prop]["sortation"] = $row['sortation'];
2893  }
2894  // check if assets is an array
2895  if (is_array($assets)) { // all good
2896  return $assets;
2897  } else { // error: exit with msg
2898  die ('unable to return assets array - maybe database is corrupt or missing.');
2899  }
2900  }
2901 
2902  /**
2903  * @brief Draw a list with all assets that are used in this template
2904  * @param object $db database object
2905  * @param int $templateID ID of the affectd template
2906  * @param array $lang language array
2907  * @return null
2908  */
2909  public static function drawAssetsTitles($db, $templateID, $lang)
2910  {
2911  /* @var \YAWK\db $db */
2912  // if no template ID is set
2913  if (!isset($templateID) || (empty($templateID))) { // get current ID from database
2914  $templateID = settings::getSetting($db, "selectedTemplate");
2915  }
2916  if ($res = $db->query("SELECT asset, link FROM {assets}
2917  WHERE templateID = '" . $templateID . "'
2918  ORDER BY asset")
2919  ) {
2920  while ($row = mysqli_fetch_assoc($res)) {
2921  // check, if link is external
2922  if (strpos($row['link'], 'http://') !== false || (strpos($row['link'], 'https://') !== false)) {
2923  $icon = "fa fa-cloud";
2924  $title = "$lang[EXTERNAL]";
2925  } else {
2926  $icon = "fa fa-server";
2927  $title = "$lang[INTERNAL]";
2928  }
2929  $qString = rawurlencode($row['asset']);
2930 
2931  echo "<small><a href=\"index.php?page=template-assets\" data-toggle=\"tooltip\" title=\"$title\"><i class=\"$icon text-info\"></i></a></small> &nbsp;$row[asset] &nbsp;<small><a href=\"https://www.google.at/search?q=$qString\" target=\"_blank\" data-toggle=\"tooltip\" title=\"$row[asset] $lang[GOOGLE_THIS]\"><i class=\"fa fa-question-circle-o\"></i></a></small><br>";
2932  }
2933  }
2934  return null;
2935  }
2936 
2937 
2938  /**
2939  * @brief Draw asset select fields
2940  * @details This method is used in the backend to generate asset select fields in template-assets view
2941  * @param object $db database object
2942  * @param int $type 0 = all, 1 = required, 2 = optional, 3 = additional
2943  * @param int $templateID id of the affected template
2944  * @param array $lang language array
2945  * @return null
2946  */
2947  public static function drawAssetsSelectFields($db, $type, $templateID, $lang)
2948  {
2949  /* @var \YAWK\db $db */
2950 
2951  // check type and load assets data
2952  // if type is not set
2953  if (!isset($type) || (empty($type))) { // set to zero -this will get all assets in array
2954  $type = 0;
2955  }
2956 
2957  // check if templateID is set
2958  if (!isset($templateID) || (empty($templateID))) {
2959  // get current template ID
2960  $templateID = settings::getSetting($db, "selectedTemplate");
2961  }
2962 
2963  // get assets, depending on type from database
2964  $assets = template::getAssetsByType($db, $type);
2965 
2966  foreach ($assets as $asset => $property) {
2967  $resInternal = $db->query("SELECT link from {assets}
2968  WHERE templateID = '" . $templateID . "'
2969  AND link = '" . $property['internal'] . "'");
2970 
2971  $resUrl1 = $db->query("SELECT link from {assets}
2972  WHERE templateID = '" . $templateID . "'
2973  AND link = '" . $property['url1'] . "'");
2974 
2975  $resUrl2 = $db->query("SELECT link from {assets}
2976  WHERE templateID = '" . $templateID . "'
2977  AND link = '" . $property['url2'] . "'");
2978 
2979  $resUrl3 = $db->query("SELECT link from {assets}
2980  WHERE templateID = '" . $templateID . "'
2981  AND link = '" . $property['url3'] . "'");
2982 
2983  $row = mysqli_fetch_assoc($resInternal);
2984  if (isset($property['internal']) && isset($row['link']) && $row['link'] === $property['internal']) {
2985  $selectedInternal = " selected";
2986  } else {
2987  $selectedInternal = '';
2988  }
2989 
2990  $row = mysqli_fetch_assoc($resUrl1);
2991  if (isset($property['url1']) && isset($row['link']) && $row['link'] === $property['url1']) {
2992  $selectedUrl1 = " selected";
2993  } else {
2994  $selectedUrl1 = '';
2995  }
2996 
2997  $row = mysqli_fetch_assoc($resUrl2);
2998  // echo "<br>VAR : "; // print_r($property);
2999  if (isset($property['url2']) && isset($row['link']) && $row['link'] === $property['url2']) {
3000  $selectedUrl2 = " selected";
3001  } else {
3002  $selectedUrl2 = '';
3003  }
3004 
3005  $row = mysqli_fetch_assoc($resUrl3);
3006  if (isset($property['url3']) && isset($row['link']) && $row['link'] === $property['url3']) {
3007  $selectedUrl3 = " selected";
3008  } else {
3009  $selectedUrl3 = '';
3010  }
3011 
3012  echo "<label for=\"include-$property[property]\">$property[asset]</label>
3013  <input name=\"title-$property[property]\" value=\"$property[asset]\" type=\"hidden\">
3014  <input name=\"sortation-$property[property]\" value=\"$property[sortation]\" type=\"hidden\">
3015 
3016  <select id=\"include-$property[property]\" name=\"include-$property[property]\" class=\"form-control\">
3017  <option name=\"null\" value=\"\">inactive</option>
3018  <optgroup label=\"internal\">internal</optgroup>
3019  <option name=\"value\"$selectedInternal>$property[internal]</option>
3020  <optgroup label=\"external\">external</optgroup>
3021  <option name=\"value\"$selectedUrl1>$property[url1]</option>";
3022  if (!empty($property['url2'])) { // display 2nd external asset link
3023  echo "
3024  <option name=\"value\"$selectedUrl2>$property[url2]</option>";
3025  }
3026  if (!empty($property['url3'])) {
3027  echo "
3028  <option name=\"value\"$selectedUrl3>$property[url3]</option>";
3029  }
3030  echo "
3031  </select>";
3032  }
3033  return null;
3034  }
3035 
3036  /**
3037  * @brief Load Active Assets
3038  * @details Load HTML markup for each active asset of current template
3039  * @param $db object db connection
3040  * @param $templateID int the current template ID
3041  * @param $host string host URL will be used by internal assets to avoid relative paths
3042  * @param $type string css|js to detect which assets to load
3043  * @return null
3044  */
3046  {
3047  /* @var \YAWK\db $db */
3048 
3049  // check if templateID is set
3050  if (isset($templateID) && (!empty($templateID)))
3051  {
3052  echo "
3053 <!-- ASSETS -->";
3054  // get assets from database for this template
3055  if ($res = $db->query("SELECT type, asset, link FROM {assets} WHERE templateID = '" . $templateID . "' ORDER BY sortation ASC"))
3056  {
3057  // loop through assets
3058  while ($row = mysqli_fetch_assoc($res))
3059  {
3060  // make sure, host will only be added for relative url assets
3061  if (stristr($row['link'], 'http://') || (stristr($row['link'], 'https://')) === FALSE) {
3062  // echo "".$row['link']." internal:";
3063  $url = $host . $row['link'];
3064  // do nothing
3065  } else { // external URL, do not prepend host string to link
3066  // echo "".$row['link']." ext:";
3067  $url = $row['link'];
3068  }
3069 
3070  if ($row['type'] === "js")
3071  { // load js asset
3072  echo "
3073 <!--load JS: $row[asset] -->
3074 <script src = \"" . $url . "\"></script>";
3075  }
3076  else if ($row['type'] === "css")
3077  { // load css asset
3078  echo "
3079 <!-- load CSS: $row[asset] -->
3080 <link rel=\"stylesheet\" href=\"" . $url . "\" type=\"text/css\" media=\"all\">";
3081  }
3082  }
3083  }
3084  }
3085  return null;
3086  }
3087 
3089  {
3090  /* @var \YAWK\db $db */
3091 
3092  if (isset($templateID) && (!empty($templateID)))
3093  {
3094  if ($sql = $db->query("SELECT * FROM {assets} WHERE templateID = '" . $templateID . "'"))
3095  { // fetch data
3096  while ($row = mysqli_fetch_assoc($sql)) { // store data as array
3097  $assets[] = $row;
3098  }
3099  }
3100  if (isset($assets) && (is_array($assets) && (!empty($assets))))
3101  {
3102  return $assets;
3103  }
3104  else
3105  {
3106  return false;
3107  }
3108  }
3109  else
3110  { // template ID is not set
3111  return false;
3112  }
3113  }
3114 
3115 
3116  /**
3117  * @brief copy template settings into a new template
3118  * @param object $db database
3119  * @param int $templateID template ID
3120  * @param int $newID template ID
3121  */
3122  public static function copyAssets($db, $templateID, $newID)
3123  {
3124  /** @var $db \YAWK\db */
3125 
3126  $res = $db->query("INSERT INTO {assets} (templateID, type, sortation, asset, link)
3127  SELECT '" . $newID . "', type, sortation, asset, link
3128  FROM {assets}
3129  WHERE templateID = '" . $templateID . "'");
3130 
3131  if (!$res)
3132  {
3133  sys::setSyslog($db, 48, 2, "failed to copy assets of template #$templateID", 0, 0, 0, 0);
3134  alert::draw("danger", "Could not copy assets", "please try again.", "", 5000);
3135  }
3136  else
3137  {
3138  alert::draw("success", "Assets copied", "successful", "", 5000);
3139 
3140 
3141  $update = $db->query("UPDATE {assets} SET templateID='" . $newID . "' WHERE templateID=0");
3142 
3143  if ($update) {
3144  alert::draw("success", "Assets are set-up", "successful", "", 5000);
3145  } else {
3146  sys::setSyslog($db, 48, 2, "failed to copy assets of template #$templateID", 0, 0, 0, 0);
3147  alert::draw("warning", "Could not copy template assets", "unable to alter IDs.", "", 5000);
3148  }
3149 
3150  }
3151  }
3152 
3153  /**
3154  * @brief Return which Bootstrap version is currently loaded in given template
3155  * @param object $db database
3156  * @return string Which Bootstrap v is setup in given template ID
3157  */
3159  {
3160  // query database
3161  if ($sql = $db->query("SELECT asset FROM {assets} WHERE templateID = '" . $templateID . "' AND asset LIKE '%Bootstrap%CSS'")) { // fetch data
3162  while ($row = mysqli_fetch_row($sql)) { // store data as array
3163  $asset[] = $row;
3164  }
3165  }
3166 
3167  // check if asset array is set and not empty
3168  if (isset($asset) && (is_array($asset) && (!empty($asset[0][0]))))
3169  {
3170  if ($asset[0][0] === "Bootstrap 4 CSS")
3171  { // v4
3172  return "4";
3173  }
3174 
3175  else if ($asset[0][0] === "Bootstrap 3 CSS")
3176  { // v3
3177  return "3";
3178  }
3179  else
3180  { // unable to detect bootstrap version, maybe this template ID does not load bootstrap
3181  return "0";
3182  }
3183  }
3184  return null;
3185  }
3186 
3187  /**
3188  * @brief Check which Bootstrap version is currently loaded in active template
3189  * @param object $db database
3190  * @return string 0|3|4|X
3191  * @details return values: 0 = not loaded, 3 = bootstrap 3, 4 = bootstrap 4, X = multiple (false!)
3192  */
3193  public function checkBootstrapVersion($db, $templateID, $lang)
3194  {
3195  /** @var $db \YAWK\db */
3196 
3197  // query database
3198  if ($sql = $db->query("SELECT asset FROM {assets} WHERE templateID = '" . $templateID . "' AND asset LIKE '%Bootstrap%CSS'")) { // fetch data
3199  while ($row = mysqli_fetch_row($sql)) { // store data as array
3200  $asset[] = $row;
3201  }
3202  }
3203 
3204  // check if there is more than 1 entry
3205  /*
3206  if (isset($asset[1]) && (!empty($asset[1]))) { // bootstrap seem to be loaded twice
3207  \YAWK\sys::setSyslog($db, 48, 2, "bootstrap loaded multiple times - template <b>$this->name</b> requires only <b>$this->framework</b>", $_SESSION['uid'], 0, 0, 0);
3208  return "X";
3209  }
3210  */
3211 
3212  // check if asset array is set and not empty
3213  if (isset($asset) && (is_array($asset) && (!empty($asset[0][0]))))
3214  {
3215  // check if framework requirement match current loaded bootstrap version
3216  // if boostrap 3 is required
3217  if ($this->framework == "bootstrap3") {
3218  // check if str contains 3 (must be when 'Bootstrap 3 CSS' is loaded, see sql query)
3219  if (strstr($asset[0][0], "3")) { // Bootstrap 3 (is required and loaded)
3220  return "3";
3221  } else { // wrong framework loaded - set syslog entry
3222  sys::setSyslog($db, 48, 2, "wrong Bootstrap version loaded - template <b>$this->name</b> requires <b>$this->framework</b>", $_SESSION['uid'], 0, 0, 0);
3223  return null;
3224  }
3225  } // if boostrap 4 is required
3226  elseif ($this->framework == "bootstrap4") {
3227  // check if str contains 4 (must be when 'Bootstrap 4 CSS' is loaded, see sql query)
3228  if (strstr($asset[0][0], "4")) { // Bootstrap 4 (is required and loaded)
3229  return "4";
3230  } else { // wrong framework loaded - set syslog entry
3231  sys::setSyslog($db, 48, 2, "wrong Bootstrap version loaded - template <b>$this->name</b> requires <b>$this->framework</b>", $_SESSION['uid'], 0, 0, 0);
3232  return null;
3233  }
3234  } else { // unknown framework
3235  sys::setSyslog($db, 48, 2, "template <b>$this->name</b> requires framework: [<b>$this->framework</b>] - UNABLE TO DETECT CURRENT FRAMEWORK.", $_SESSION['uid'], 0, 0, 0);
3236  return "0";
3237  }
3238  } // asset not set, no array or empty
3239  else { // it seems that no Bootstrap css is loaded
3240  sys::setSyslog($db, 48, 2, "template <b>$this->name</b> requires <b>$this->framework</b>, but no corresponding asset is loaded.", $_SESSION['uid'], 0, 0, 0);
3241  return "0";
3242  }
3243  }
3244 
3245  public function emptyTmpFolder()
3246  {
3247  foreach(glob($this->tmpFolder."*") as $file)
3248  {
3249  if(!is_dir($file))
3250  {
3251  unlink($file);
3252  }
3253  else
3254  {
3256  }
3257  }
3258  }
3259 
3260  /**
3261  * @brief Upload a template (install / update)
3262  * @param object $db database object
3263  * @param array $postData data that has been sent by upload form
3264  * @param array $postFiles uploaded file that has been sent by upload form
3265  * @return bool true|false
3266  * @details upload .zip file, unpack to tmp folder,
3267  */
3268  public function uploadTemplate($db, $postData, $postFiles, $lang)
3269  {
3270  // check if params are set and valid...
3271  if (!isset($postData)
3272  || (empty($postData)
3273  || (!is_array($postData))))
3274  { // post data wrong
3275  return false;
3276  }
3277  if (!isset($postFiles['templateFile'])
3278  || (empty($postFiles['templateFile'])
3279  || (!is_array($postFiles['templateFile']))))
3280  { // post file data wrong
3281  return false;
3282  }
3283 
3284  // prepare (empty) temp directory
3285  $this->emptyTmpFolder();
3286 
3287  // check if tmp folder exists...
3288  if (!is_dir(dirname($this->tmpFolder)))
3289  {
3290  // try to create tmp folder
3291  if (!mkdir($this->tmpFolder))
3292  {
3293  // add syslog: failed to create $this->tmpFolder
3294  return false;
3295  }
3296  }
3297 
3298  // check if template folder is writeable
3299  if (is_writeable(dirname($this->folder)))
3300  {
3301  // check if tmp folder exits
3302  if (is_dir(dirname($this->tmpFolder)))
3303  {
3304  $this->uploadFile = $this->tmpFolder.$postFiles['templateFile']['name'];
3305 
3306  // check for errors
3307  if ($postFiles['templateFile']['error'] !== 0)
3308  { // unknown error - upload failed
3309  sys::setSyslog($db, 48, 2, "failed to upload file - unknown error (".$postFiles['templateFile']['error'].") processing file ".$postFiles['templateFile']['name']."", 0, 0, 0, 0);
3310  // echo \YAWK\alert::draw("warning", $lang['ERROR'], $lang['FILE_UPLOAD_FAILED'], "", 4800);
3311  }
3312  else
3313  { // try to move uploaded file
3314  if (!move_uploaded_file($postFiles['templateFile']['tmp_name'], $this->uploadFile))
3315  { // throw error msg
3316  sys::setSyslog($db, 48, 2, "failed to move upload file $this->uploadFile to folder ".$postFiles['templateFile']['tmp_name']."", 0, 0, 0, 0);
3317  // echo \YAWK\alert::draw("danger", "$lang[ERROR]", "$this->uploadFile - $lang[FILE_UPLOAD_ERROR]","","4800");
3318  }
3319  else
3320  { // file upload seem to be successful...
3321  // check if uploaded file is there
3322  if (is_file($this->uploadFile))
3323  {
3324  // here we could check more things - eg latest file timestamp
3325  // create zip object + extract to tmp folder
3326  $zip = new \ZipArchive;
3327  // open zip archive
3328  $res = $zip->open($this->uploadFile);
3329  // if zip open was successful
3330  if ($res === TRUE)
3331  { // extract zip file
3332  $zip->extractTo($this->tmpFolder);
3333  // close zip file
3334  $zip->close();
3335  }
3336 
3337  // check and read template.ini file - stores all information about the template
3338  if (is_file($this->tmpFolder.'template.ini'))
3339  {
3340  // try to parse ini file into array
3341  if (!$iniFile = parse_ini_file($this->tmpFolder."template.ini"))
3342  { // error: unable to parse ini file
3343  sys::setSyslog($db, 48, 2, "failed to parse ini file ".$this->tmpFolder."template.ini ", 0, 0, 0, 0);
3344  return false;
3345  }
3346  }
3347  else
3348  { // error: ini file not there
3349  sys::setSyslog($db, 48, 2, "failed to parse ini file ".$this->tmpFolder."template.ini - file not found", 0, 0, 0, 0);
3350  return false;
3351  }
3352 
3353  // set target path
3354  $this->targetPath = $iniFile['TARGET_PATH'];
3355  // set subfolder
3356  $this->subFolder = $iniFile['SUBFOLDER']."/";
3357 
3358  // read assets.json into array
3359  if (is_file($this->tmpFolder.$this->subFolder.'assets.json'))
3360  { // read and decode json file into array
3361  $assets = json_decode(file_get_contents($this->tmpFolder.$this->subFolder.'assets.json'), true);
3362  }
3363  else
3364  { // assets.json not found
3365  $assets = '';
3366  sys::setSyslog($db, 48, 1, "failed to get ".$this->tmpFolder.$this->subFolder."assets.json - file not found", 0, 0, 0, 0);
3367  }
3368 
3369  // read template settings into array
3370  if (is_file($this->tmpFolder.$this->subFolder.'template_settings.json'))
3371  { // read and decode json file into array
3372  $templateSettings = json_decode(file_get_contents($this->tmpFolder.$this->subFolder.'template_settings.json'), true);
3373  }
3374  else
3375  { // template_settings.json not found
3376  $templateSettings = '';
3377  sys::setSyslog($db, 48, 1, "failed to get ".$this->tmpFolder.$this->subFolder."template_settings.json - file not found", 0, 0, 0, 0);
3378  }
3379 
3380  // read template_settings_types into array
3381  if (is_file($this->tmpFolder.$this->subFolder.'template_settings_types.json'))
3382  { // read and decode json into array
3383  $templateSettingsTypes = json_decode(file_get_contents($this->tmpFolder.$this->subFolder.'template_settings_types.json'), true);
3384  }
3385  else
3386  { // template_settings_types json file not found
3387  $templateSettingsTypes = '';
3388  sys::setSyslog($db, 48, 1, "failed to get ".$this->tmpFolder.$this->subFolder."template_settings_types.json - file not found", 0, 0, 0, 0);
3389  }
3390 
3391  // read templates.json into array
3392  if (is_file($this->tmpFolder.$this->subFolder.'templates.json'))
3393  { // read and decode json into array
3394  $templates = json_decode(file_get_contents($this->tmpFolder.$this->subFolder.'templates.json'), true);
3395  }
3396  else
3397  { // templates.json file not found
3398  $templates = '';
3399  sys::setSyslog($db, 48, 1, "failed to get ".$this->tmpFolder.$this->subFolder."templates.json - file not found", 0, 0, 0, 0);
3400  }
3401 
3402  // check if template with same name exists
3403  if ($this->checkIfTemplateAlreadyExists($db, $iniFile['NAME']) === true)
3404  {
3405  // die('template already exists');
3406 
3407  // TEMPLATE ALREADY EXISTS - OVERWRITE IT!
3408  // .) check, which ID got this template?
3409  // .) manipulate assets + template_settings arrays
3410  // (means: change template ID to the one of the existing template that was found)
3411  // .) UPDATE data of these arrays into related db tables
3412  // .) delete json files from tmp folder (unwanted in target)
3413  // .) xcopy files and overwrite template folder
3414  // .) empty tmp directory
3415  // -fin- template updated - if all went good
3416 
3417  // get ID of installed template
3418  $this->id = self::getTemplateIdByName($db, $iniFile['NAME']);
3419 
3420  // update ID in templates array
3421  $templates['id'] = $this->id;
3422 
3423  // update ID in assets array
3424  foreach ($assets as &$asset)
3425  {
3426  $asset['templateID'] = $this->id;
3427  }
3428 
3429  // update ID in template_settings array
3430  foreach ($templateSettings as &$templateSetting)
3431  {
3432  $templateSetting['templateID'] = $this->id;
3433  }
3434 
3435  if ($db->query("UPDATE {templates}
3436  SET id = '".$this->id."',
3437  active = 1,
3438  name = '".$iniFile['NAME']."',
3439  positions ='outerTop:outerLeft:outerRight:intro:globalmenu:top:leftMenu:mainTop:mainTopLeft:mainTopCenter:mainTopRight:main:mainBottom:mainBottomLeft:mainBottomCenter:mainBottomRight:mainFooter:mainFooterLeft:mainFooterCenter:mainFooterRight:rightMenu:bottom:footer:hiddentoolbar:debug:outerBottom',
3440  description = '".$iniFile['DESCRIPTION']."',
3441  modifyDate = '".$iniFile['DATE']."',
3442  author = '".$iniFile['AUTHOR']."',
3443  authorUrl = '".$iniFile['AUTHOR_URL']."',
3444  weblink = '".$iniFile['WEBLINK']."',
3445  subAuthor = '".$iniFile['SUB_AUTHOR']."',
3446  subAuthorUrl = '".$iniFile['SUB_AUTHOR_URL']."',
3447  version = '".$iniFile['VERSION']."',
3448  framework = '".$iniFile['FRAMEWORK']."',
3449  license = '".$iniFile['LICENSE']."'
3450  WHERE name = '".$iniFile['NAME']."'"))
3451  {
3452  // success: updated templates database
3453  // \YAWK\sys::setSyslog($db, 45, 0, "template $iniFile[NAME] - templates db updated", 0, 0, 0, 0);
3454  }
3455  else
3456  { // error: failed to update templates db
3457  sys::setSyslog($db, 47, 0, "failed to update template $iniFile[NAME] - templates db NOT updated", 0, 0, 0, 0);
3458  }
3459 
3460  // update assets database
3461  foreach ($assets as $asset)
3462  {
3463  if ($db->query("UPDATE {assets}
3464  SET templateID = '".$this->id."',
3465  type = '".$asset['type']."',
3466  sortation = '".$asset['sortation']."',
3467  asset = '".$asset['asset']."',
3468  link = '".$asset['link']."'
3469  WHERE link = '".$asset['link']."' AND templateID = '".$iniFile['ID']."'"))
3470  {
3471  // success: updated templates database
3472  // \YAWK\sys::setSyslog($db, 45, 0, "template $iniFile[NAME] - assets db updated", 0, 0, 0, 0);
3473  }
3474  else
3475  { // error: failed to update templates db
3476  sys::setSyslog($db, 47, 0, "failed to update template $iniFile[NAME] - assets db NOT updated", 0, 0, 0, 0);
3477  }
3478  // process asset data
3479  }
3480 
3481  // update template_settings database
3482 
3483  foreach ($templateSettings as $templateSetting)
3484  {
3485  if ($db->query("UPDATE {template_settings}
3486  SET templateID = '".$this->id."',
3487  property = '".$templateSetting['property']."',
3488  value = '".$templateSetting['value']."',
3489  valueDefault = '".$templateSetting['valueDefault']."',
3490  longValue = '".$templateSetting['longValue']."',
3491  type = '".$templateSetting['type']."',
3492  activated = '".$templateSetting['activated']."',
3493  sort = '".$templateSetting['sort']."',
3494  label = '".$templateSetting['label']."',
3495  fieldClass = '".$templateSetting['fieldClass']."',
3496  fieldType = '".$templateSetting['fieldType']."',
3497  options = '".$templateSetting['options']."',
3498  placeholder = '".$templateSetting['placeholder']."',
3499  description = '".$templateSetting['description']."',
3500  icon = '".$templateSetting['icon']."',
3501  heading = '".$templateSetting['heading']."',
3502  subtext = '".$templateSetting['subtext']."'
3503  WHERE property = '".$templateSetting['property']."' AND templateID = '".$iniFile['ID']."'"))
3504  {
3505  // success: updated templates database
3506  // \YAWK\sys::setSyslog($db, 45, 0, "template $iniFile[NAME] - template_settings db updated", 0, 0, 0, 0);
3507  }
3508  else
3509  { // error: failed to update templates db
3510  sys::setSyslog($db, 47, 0, "failed to update property $templateSetting[property] of template $iniFile[NAME] - template_settings db NOT updated", 0, 0, 0, 0);
3511  }
3512  }
3513 
3514  // update template settings types
3515  foreach ($templateSettingsTypes as $templateSettingsType)
3516  {
3517  if ($db->query("UPDATE {template_settings_types}
3518  SET type = '".$templateSettingsType['type']."'
3519  WHERE type = '".$templateSettingsType['type']."'"))
3520  {
3521  // success: updated templates database
3522  // \YAWK\sys::setSyslog($db, 45, 0, "template $iniFile[NAME] - template_settings db updated", 0, 0, 0, 0);
3523  }
3524  else
3525  { // error: failed to update templates db
3526  sys::setSyslog($db, 47, 0, "failed to update type $templateSettingsType[type] - template_settings_types db NOT updated", 0, 0, 0, 0);
3527  }
3528  }
3529 
3530  // delete unwanted json files - they are not needed anymore
3531  if (!unlink ($this->tmpFolder.$this->subFolder."assets.json"))
3532  {
3533  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."assets.json", 0, 0, 0, 0);
3534  }
3535  if (!unlink ($this->tmpFolder.$this->subFolder."template_settings.json"))
3536  {
3537  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."template_settings.json", 0, 0, 0, 0);
3538  }
3539  if (!unlink ($this->tmpFolder.$this->subFolder."template_settings_types.json"))
3540  {
3541  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."template_settings_types.json", 0, 0, 0, 0);
3542  }
3543  if (!unlink ($this->tmpFolder.$this->subFolder."templates.json"))
3544  {
3545  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."templates.json", 0, 0, 0, 0);
3546  }
3547 
3548  // copy template folder
3549  sys::xcopy($this->tmpFolder.$this->subFolder, $this->folder.$this->subFolder);
3550 
3551  // remove tmp folder
3552  if (!\YAWK\filemanager::recursiveRemoveDirectory($this->tmpFolder))
3553  { // failed to remove tmp folder
3554  sys::setSyslog($db, 47, 0, "failed to remove tmp folder $this->tmpFolder", 0, 0, 0, 0);
3555  }
3556 
3557  // create a fresh, empty tmp folder
3558  mkdir($this->tmpFolder);
3559  return true;
3560  }
3561  else
3562  {
3563  // TEMPLATE DOES NOT EXIST YET - INSTALL IT!
3564  // 1.) add template to templates database
3565  // 2.) retrieve ID of this new added template
3566  // 3.) manipulate assets + template_settings arrays
3567  // (means: change template ID to the new created one)
3568  //
3569  // 4.) INSERT data of these arrays into related db tables
3570  // 5.) delete json files from tmp folder (unwanted in target)
3571  // 6.) delete ini file (unwanted in target)
3572  // 7.) next step - xcopy files
3573  // -fin- template installed - if all went good
3574  // die('template does not exist');
3575 
3576  // step 1.) add template to templates database
3577  if ($res = $db->query("INSERT INTO {templates} (active, name, positions, description, releaseDate, modifyDate, author, authorUrl, weblink, subAuthor, subAuthorUrl, version, framework, license)
3578  VALUES ('1',
3579  '".$iniFile['NAME']."',
3580  'outerTop:outerLeft:outerRight:intro:globalmenu:top:leftMenu:mainTop:mainTopLeft:mainTopCenter:mainTopRight:main:mainBottom:mainBottomLeft:mainBottomCenter:mainBottomRight:mainFooter:mainFooterLeft:mainFooterCenter:mainFooterRight:rightMenu:bottom:footer:hiddentoolbar:debug:outerBottom',
3581  '".$iniFile['DESCRIPTION']."',
3582  '".$iniFile['DATE']."',
3583  '".$iniFile['DATE']."',
3584  '".$iniFile['AUTHOR']."',
3585  '".$iniFile['AUTHOR_URL']."',
3586  '".$iniFile['WEBLINK']."',
3587  '".$iniFile['SUB_AUTHOR']."',
3588  '".$iniFile['SUB_AUTHOR_URL']."',
3589  '".$iniFile['VERSION']."',
3590  '".$iniFile['FRAMEWORK']."',
3591  '".$iniFile['LICENSE']."')"))
3592  {
3593 
3594  // 2.) retrieve ID of this new added template
3595  $this->id = self::getTemplateIdByName($db, $iniFile['NAME']);
3596 
3597  // add assets to database
3598  foreach ($assets as $asset)
3599  {
3600  $db->query("INSERT INTO {assets} (templateID, type, sortation, asset, link)
3601  VALUES (
3602  '".$this->id."',
3603  '".$asset['type']."',
3604  '".$asset['sortation']."',
3605  '".$asset['asset']."',
3606  '".$asset['link']."'
3607  )");
3608  }
3609 
3610  // add template settings to database
3611  foreach ($templateSettings as $templateSetting)
3612  {
3613  $db->query("INSERT INTO {template_settings}
3614  (templateID, property, value, valueDefault, longValue, type, activated, sort, label, fieldClass, fieldType, options, placeholder, description, icon, heading, subtext)
3615  VALUES ('".$this->id."',
3616  '".$templateSetting['property']."',
3617  '".$templateSetting['value']."',
3618  '".$templateSetting['valueDefault']."',
3619  '".$templateSetting['longValue']."',
3620  '".$templateSetting['type']."',
3621  '".$templateSetting['activated']."',
3622  '".$templateSetting['sort']."',
3623  '".$templateSetting['label']."',
3624  '".$templateSetting['fieldClass']."',
3625  '".$templateSetting['fieldType']."',
3626  '".$templateSetting['options']."',
3627  '".$templateSetting['placeholder']."',
3628  '".$templateSetting['description']."',
3629  '".$templateSetting['icon']."',
3630  '".$templateSetting['heading']."',
3631  '".$templateSetting['subtext']."')");
3632  }
3633 
3634  // delete unwanted json files - they are not needed anymore
3635  if (!unlink ($this->tmpFolder.$this->subFolder."assets.json"))
3636  {
3637  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."assets.json", 0, 0, 0, 0);
3638  }
3639  if (!unlink ($this->tmpFolder.$this->subFolder."template_settings.json"))
3640  {
3641  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."template_settings.json", 0, 0, 0, 0);
3642  }
3643  if (!unlink ($this->tmpFolder.$this->subFolder."template_settings_types.json"))
3644  {
3645  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."template_settings_types.json", 0, 0, 0, 0);
3646  }
3647  if (!unlink ($this->tmpFolder.$this->subFolder."templates.json"))
3648  {
3649  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."templates.json", 0, 0, 0, 0);
3650  }
3651 
3652  // copy template folder
3653  sys::xcopy($this->tmpFolder.$this->subFolder, $this->folder.$this->subFolder);
3654 
3655  // remove tmp folder
3656  if (!\YAWK\filemanager::recursiveRemoveDirectory($this->tmpFolder))
3657  { // failed to remove tmp folder
3658  sys::setSyslog($db, 47, 0, "failed to remove tmp folder $this->tmpFolder", 0, 0, 0, 0);
3659  }
3660 
3661  // create a fresh, empty tmp folder
3662  mkdir($this->tmpFolder);
3663 
3664  // success: updated templates database
3665  sys::setSyslog($db, 45, 0, "added template <b>$iniFile[NAME] ID: ".$this->id."</b> to templates db", 0, 0, 0, 0);
3666  return true;
3667 
3668  }
3669  else
3670  { // error: failed to insert new template into db
3671  sys::setSyslog($db, 47, 0, "failed to insert new template: $iniFile[NAME] - templates db NOT updated", 0, 0, 0, 0);
3672  }
3673 
3674  }
3675 
3676  // xcopy files
3677  // recursive delete tmp folder
3678 
3679  // throw success message
3680  sys::setSyslog($db, 46, 3, "uploaded template package $this->uploadFile successfully", 0, 0, 0, 0);
3681  }
3682  else
3683  { // failed to check uploaded file - file not found
3684  sys::setSyslog($db, 48, 1, "failed to check uploaded file upload file: $this->uploadFile not found", 0, 0, 0, 0);
3685  }
3686  }
3687  }
3688  }
3689  else
3690  { // tmp folder does not exist
3691  sys::setSyslog($db, 48, 1, "failed to uploaded tempalte: ../system/templates/tmp/ does not exist or is not accessable", 0, 0, 0, 0);
3692  return false;
3693  }
3694  }
3695  else
3696  { // tmp folder is not writeable
3697  sys::setSyslog($db, 48, 1, "failed to uploaded template: $this->folder is not writeable", 0, 0, 0, 0);
3698  return false;
3699  }
3700 
3701  // if something else went wrong
3702  return false;
3703  }
3704 
3705  /**
3706  * @brief Create a zip file from template and force direct download
3707  * @param object $db database
3708  * @param string $templateFolder the template folder to zip + download
3709  * @param int $templateID ID of the template to process
3710  * @param object $user user object
3711  * @return bool true|false
3712  * @details dump database settings into .json files, write template.ini and license file, zip the whole template folder and serve .zip for direct download
3713  */
3714  public function downloadTemplate($db, $templateFolder, $templateID, $user)
3715  {
3716  // check if template folder is set and valid
3717  if (!isset($templateFolder) || (empty($templateFolder) || (!is_string($templateFolder))))
3718  { // required param not set
3719  return false;
3720  }
3721  else
3722  { // set template folder property
3723  $this->subFolder = $templateFolder;
3724  $this->name = $templateFolder;
3725  }
3726  // check if template ID is set and valid
3727  if (!isset($templateID) || (empty($templateID) || (!is_numeric($templateID))))
3728  { // required param not set
3729  return false;
3730  }
3731  else
3732  { // set template ID property
3733  $this->id = $templateID;
3734  }
3735 
3736  if (!is_dir(dirname($this->tmpFolder)))
3737  {
3738  // check if tmp directory exists...
3739  if (!mkdir(dirname($this->tmpFolder)))
3740  { // failed to create tmp folder
3741  // todo: add syslog entry
3742  return false;
3743  }
3744  }
3745 
3746  // params are set, next step:
3747  // check if tmp directory exists and is empty
3748  if (is_writeable(dirname($this->tmpFolder)))
3749  {
3750  // check if subfolder exists...
3751  if (!is_dir(dirname($this->tmpFolder.$this->subFolder)))
3752  {
3753  // check if tmp directory exists...
3754  if (!mkdir(dirname($this->tmpFolder.$this->subFolder)))
3755  { // failed to create tmp sub folder
3756  sys::setSyslog($db, 47, 0, "failed to create ".$this->tmpFolder.$this->subFolder."", 0, 0, 0, 0);
3757  return false;
3758  }
3759  }
3760 
3761  // next step is to copy the whole template folder into tmp folder
3762  if (sys::xcopy($this->folder.$this->subFolder."/", $this->tmpFolder.$this->subFolder) === false)
3763  { // failed to copy template into tmp folder
3764  sys::setSyslog($db, 47, 0, "failed to copy template into tmp folder: ".$this->tmpFolder.$this->subFolder."", 0, 0, 0, 0);
3765  return false;
3766  }
3767 
3768  // check if template folder is writeable
3769  if (is_writeable($this->tmpFolder.$this->subFolder))
3770  {
3771  // GET TEMPLATE DEPENDING DATABASE DATA
3772  // get current template data
3773  $templateData = self::loadPropertiesIntoArray($db, $this->id);
3774  $templateAssets = self::loadActiveAssetsIntoArray($db, $this->id);
3776  $templateSettingsTypes = self::loadSettingsTypesIntoArray($db);
3777 
3778  // encode arrays to JSON format
3779  $templateData = json_encode($templateData);
3780  $templateAssets = json_encode($templateAssets);
3781  $templateSettings = json_encode($templateSettings);
3782  $templateSettingsTypes = json_encode($templateSettingsTypes);
3783 
3784  // write json arrays into files
3785  // write templates.json
3786  if (!file_put_contents($this->tmpFolder.$this->subFolder."/"."templates.json", $templateData))
3787  { // error writing templates.json
3788  sys::setSyslog($db, 48, 0, "failed to write ".$this->tmpFolder.$this->subFolder."templates.json", 0, 0, 0, 0);
3789  }
3790  // write assets.json
3791  if (!file_put_contents($this->tmpFolder.$this->name."/"."assets.json", $templateAssets))
3792  { // error writing assets.json
3793  sys::setSyslog($db, 48, 0, "failed to write ".$this->tmpFolder.$this->subFolder."assets.json", 0, 0, 0, 0);
3794  }
3795  // write template_settings.json
3796  if (!file_put_contents($this->tmpFolder.$this->name."/"."template_settings.json", $templateSettings))
3797  { // error writing template_settings.json
3798  sys::setSyslog($db, 48, 0, "failed to write ".$this->tmpFolder.$this->subFolder."template_settings.json", 0, 0, 0, 0);
3799  }
3800  // write template_settings_types.json
3801  if (!file_put_contents($this->tmpFolder.$this->name."/"."template_settings_types.json", $templateSettingsTypes))
3802  { // error writing template_settings_types.json
3803  sys::setSyslog($db, 48, 0, "failed to write ".$this->tmpFolder.$this->subFolder."template_settings_types.json", 0, 0, 0, 0);
3804  }
3805 
3806  // get template properties
3807  $this->loadProperties($db, $this->id);
3808  // get year only from release date
3809  $year = (substr($this->releaseDate, 0, 4));
3810  // include class
3811  require_once('../system/classes/licenses.php');
3812  // create license object
3813  $license = new \YAWK\licenses($this->license, $this->description, $year, $this->author, $this->tmpFolder.$this->name."/");
3814  // write license file
3815  if ($license->writeLicenseFile() === false)
3816  { // failed to write license file
3817  sys::setSyslog($db, 47, 0, "failed to write license file ($this->license license) to ".$this->tmpFolder.$this->subFolder."", 0, 0, 0, 0);
3818  }
3819  }
3820 
3821  // check if .json files have been written...
3822  if (is_file($this->tmpFolder.$this->subFolder.'/assets.json')
3823  && (is_file($this->tmpFolder.$this->subFolder.'/templates.json')
3824  && (is_file($this->tmpFolder.$this->subFolder.'/template_settings.json')
3825  && (is_file($this->tmpFolder.$this->subFolder.'/template_settings_types.json')))))
3826  {
3827  // ok, all files seem to be processed successfully
3828 
3829  // set source (path to the affected template)
3830  $source = $this->tmpFolder;
3831  // set target (path to the zip file that will be generated)
3832  $destination = $this->tmpFolder.$this->name.'.zip';
3833 
3834  // set data for ini file
3835  $iniData['DATE'] = sys::now();
3836  $iniData['NAME'] = $this->name;
3837  $iniData['FOLDER'] = $this->folder;
3838  $iniData['SUBFOLDER'] = $this->subFolder;
3839  $iniData['TARGET_PATH'] = $this->folder.$this->subFolder."/";
3840  $iniData['ID'] = $this->id;
3841  $iniData['FRAMEWORK'] = $this->framework;
3842  $iniData['DESCRIPTION'] = $this->description;
3843  $iniData['AUTHOR'] = $this->author;
3844  $iniData['AUTHOR_URL'] = $this->authorUrl;
3845  $iniData['SUB_AUTHOR'] = $this->subAuthor;
3846  $iniData['SUB_AUTHOR_URL'] = $this->subAuthorUrl;
3847  $iniData['WEBLINK'] = $this->weblink;
3848  $iniData['VERSION'] = $this->version;
3849  $iniData['LICENSE'] = $this->license;
3850 
3851  // write ini file
3852  if (sys::writeIniFile($iniData, $this->tmpFolder."template.ini") === false)
3853  {
3854  // failed to write ini file:
3855  sys::setSyslog($db, 47, 0, "failed to write ".$this->tmpFolder."template.ini ", 0, 0, 0, 0);
3856  return false;
3857  }
3858 
3859  // next step is to zip the whole template folder, containing all files
3860 
3861  // check if zip extension is loaded
3862  if (extension_loaded('zip'))
3863  {
3864  // make sure $source (template folder) exists
3865  if (!is_dir(dirname($source)))
3866  { // if folder does not exist
3867  return false;
3868  }
3869 
3870  // create new zip object
3871  $zip = new \ZipArchive();
3872 
3873  // make sure to create and open new zip archive
3874  if (!$zip->open($destination, \ZIPARCHIVE::CREATE))
3875  { // if not
3876  return false;
3877  }
3878 
3879  // set path slashes correctly
3880  $source = str_replace('\\', '/', realpath($source));
3881 
3882  // check if $source is a directoy
3883  if (is_dir($source) === true)
3884  {
3885  // run recursive iterators to store files in array
3886  $elements = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST);
3887 
3888  // walk through folder
3889  foreach ($elements as $file)
3890  {
3891  // set path slashes correctly
3892  $file = str_replace('\\', '/', $file);
3893 
3894  // ignore dot folders (. and ..)
3895  if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
3896  continue;
3897 
3898  // set file including path
3899  $file = realpath($file);
3900 
3901  // check if current element is a directory
3902  if (is_dir($file) === true)
3903  { // add folder to zip file
3904  $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
3905  }
3906  // check if current element is a file
3907  else if (is_file($file) === true)
3908  { // add file to zip archive
3909  $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
3910  }
3911  }
3912  }
3913  // if $source is a file
3914  else if (is_file($source) === true)
3915  { // add file to zip archive
3916  $zip->addFromString(basename($source), file_get_contents($source));
3917  }
3918 
3919  // all done, close (and write) zip archive
3920  $zip->close();
3921 
3922  if (is_file($destination))
3923  { // destination zip file is there.
3924 
3925  // delete all files from tmp folder - except the created zipfile
3926  if (\YAWK\filemanager::recursiveRemoveDirectory($this->tmpFolder.$this->subFolder) === false)
3927  { // warning: failed to delete tmp files
3928  sys::setSyslog($db, 47, 0, "failed to delete tmp folder ".$this->tmpFolder.$this->subFolder."", 0, 0, 0, 0);
3929  // return false;
3930  }
3931 
3932  // check if template ID is set
3933  if (isset($_GET['id']) && (!empty($_GET['id'])))
3934  { // set var for JS: downloadArchiveLink (selector)
3935  $downloadTemplateLink = "#downloadTemplateLink-".$_GET['id'];
3936  // set var for JS: link to the file to download
3937  $downloadFile = $destination;
3938  // dirty lil piece of JS code to emulate the user's click
3939  // (this avoids that he have to click twice - 1st click to generate + 2nd click to download)
3940  echo "
3941  <script type='text/javascript'>
3942  $(document).ready(function()
3943  { // change href attribute for this archive to direct donwload file
3944  var oldLink = $('$downloadTemplateLink').attr('href');
3945  $('$downloadTemplateLink').attr('href', '$downloadFile')
3946  // emulate a users click to force direct download
3947  $('$downloadTemplateLink')[0].click();
3948  // if this is not working, the user have to click on that link.
3949  });
3950  </script>";
3951  }
3952  // download file generated, direct download forced...
3953  return true;
3954  }
3955  else
3956  { // zip not generated
3957  sys::setSyslog($db, 52, 2, "failed to create template $this->name.zip package - zip file not there", 0, 0, 0, 0);
3958  return false;
3959  }
3960  }
3961  else
3962  { // zip extension is not loaded
3963  sys::setSyslog($db, 52, 2, "failed to create template .zip package: PHP zip extension not loaded.", 0, 0, 0, 0);
3964  return false;
3965  }
3966  }
3967  else
3968  { // .sql files not written
3969  sys::setSyslog($db, 52, 2, ".json files missing: $this->folder$this->subFolder/*.json not found", 0, 0, 0, 0);
3970  return false;
3971  }
3972  }
3973  else
3974  { // unable to include class
3975  sys::setSyslog($db, 52, 2, "create template .zip package failed: folder $this->folder is not writeable. Please check folder group permissions", 0, 0, 0, 0);
3976  return false;
3977  }
3978  }
3979  } // ./class template
3980 } // ./namespace
$now
$filename
Definition: actions.php:10
$prefix
Definition: actions.php:6
$blog
Definition: blog.php:122
print $lang['FILEMAN_UPLOAD']
$data
Definition: stats.php:78
die
Definition: block-user.php:27
$blog description
Definition: blog-setup.php:49
if(!isset($language)||(!isset($lang))) $item
$templateID
Definition: blog.php:9
static draw($type, $title, $text, $redirect, $delay)
Definition: alert.php:30
static recursiveRemoveDirectory($directory)
Delete a directory recursive.
static displayGlobalMenu($db, $user, $template)
display the global menu
Definition: menu.php:69
static getSetting($db, $property)
Get and return value for property from settings database.
Definition: settings.php:470
static xcopy($source, $dest, $permissions=0755)
Copy a file, or recursively copy a folder and its contents.
Definition: sys.php:473
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 recurseRmdir($dir)
remove a directory recurse
Definition: sys.php:1127
static minifyJs($input)
Minify any string: removes spaces, tabs and linebreaks.
Definition: sys.php:664
static writeIniFile($array, $file)
write ini file
Definition: sys.php:2085
static now()
returns the current datetime
Definition: sys.php:1492
The template controller - get and set template settings.
Definition: template.php:16
static checkWrapper($lang, $title, $subtitle)
check if an admin LTE wrapper should be loaded around the backend content. This function must be call...
Definition: template.php:2819
static setCssBodyFontSettings($cssTagName, $tplSettings)
set body font settings css code
Definition: template.php:2220
static getAllSettingsIntoArray($db, $user)
Returns an array with all template settings.
Definition: template.php:1061
string $ttfPath
Definition: template.php:66
static setPosition($db, $lang, $position, $currentpage, $user, $template)
set template position and output the correct data depending on position
Definition: template.php:2736
static getAssetsByType($db, $type)
Return a multidimensional array with all assets by requested type.
Definition: template.php:2857
static setCssFontSettings($cssTagName, $tplSettings)
set font settings css code
Definition: template.php:2262
loadAllSettingsIntoArray(object $db, int $id)
load template settings of ID and return as array
Definition: template.php:328
static getTemplateSettingsArray($db, $templateID)
get all template settings into an array and return it
Definition: template.php:2794
static getPositionIndicatorStatusArray($db, $templateID)
get the position indicators. This is used on index.php to mark indicated positions
Definition: template.php:2710
int $selectedTemplate
Definition: template.php:64
downloadTemplate($db, $templateFolder, $templateID, $user)
Create a zip file from template and force direct download.
Definition: template.php:3714
switchPositionIndicators(object $db, int $templateID, int $status)
switch all positions indicators on or off
Definition: template.php:131
loadSettingsTypesIntoArray(object $db)
load template_settings_types and return as array
Definition: template.php:401
checkIfTemplateAlreadyExists(object $db, string $name)
Check if a template with given name already exists, return true or false.
Definition: template.php:95
static getCurrentTemplateId(object $db)
return ID of current (active) template
Definition: template.php:73
loadActiveAssets($db, $templateID, $host)
Load Active Assets.
Definition: template.php:3045
static getPositionStatesArray($db, $templateID)
get the position states of all templates. This is used on index.php to render only templates that are...
Definition: template.php:2686
static setCssBodyLinkTags($cssTagName, $tplSettings)
set css code for body link styling
Definition: template.php:2162
drawFontFamilySelectField($db, $lang, $selectName, $defaultValue)
return a select option list with all fonts:
Definition: template.php:1841
static getValidTemplateID($db, $user, $template)
check the current template ID, considering if user is logged in, allowed to override template and so ...
Definition: template.php:2603
uploadTemplate($db, $postData, $postFiles, $lang)
Upload a template (install / update)
Definition: template.php:3268
static getTemplateIds(object $db)
return array with all template id's + names.
Definition: template.php:426
static returnCurrentBootstrapVersion($db, $templateID)
Return which Bootstrap version is currently loaded in given template.
Definition: template.php:3158
static loadGoogleFonts($db)
get settings for heading, menu and text font and output html to load font
Definition: template.php:2536
saveAs(object $db)
save a template as new. It copies the tpl folder and all settings into a new one.
Definition: template.php:201
saveProperties(object $db, int $id, array $data, array $oldTplSettings)
save new template properties into database
Definition: template.php:356
static setCssBodyFontFace($cssTagName, $tplSettings)
set css code for custom fonts (ttf / otf / woff)
Definition: template.php:2127
getCustomJSFile(object $db, int $templateID)
return the content of custom.js
Definition: template.php:710
getCustomCSSFile(object $db, int $templateID)
return the content of custom.css
Definition: template.php:698
static getActivegfont($db, $status, $property)
return currently active google font
Definition: template.php:2496
getFormElements($db, $settings, $type, $lang, $user)
return html form field, depending on fieldClass
Definition: template.php:1163
getFontRow($db, $lang, $fontRow, $previewClass, $templateSettings)
return font edit row including preview
Definition: template.php:1460
static getMaxId($db)
return biggest ID from template database
Definition: template.php:779
loadProperties($db, $id)
load properties into template object
Definition: template.php:264
static getPositionDivBox($db, $lang, $position, $row, $bootstrapGrid, $positions, $indicators, $user, $template)
return div box with postition settings
Definition: template.php:1118
static getGoogleFontsArray($db)
get all google fonts into an array and return array
Definition: template.php:1949
loadPropertiesIntoArray(object $db, int $id)
load template properties and return as array
Definition: template.php:300
static drawAssetsTitles($db, $templateID, $lang)
Draw a list with all assets that are used in this template.
Definition: template.php:2909
static getFontsFromFolder($folder)
get fonts from folder and return as array
Definition: template.php:1674
loadActiveAssetsIntoArray($db, $templateID)
Definition: template.php:3088
static getActiveBodyFont($db, $user, $template)
Get and return current active google font.
Definition: template.php:2481
static setCssBodySmallFontSettings($cssTagName, $tplSettings)
set small font settings css code
Definition: template.php:2196
static drawAssetsSelectFields($db, $type, $templateID, $lang)
Draw asset select fields.
Definition: template.php:2947
static includeHeader($db)
include header for html page *outdated? *moved to sys?
Definition: template.php:2651
deleteSettingsCSSFile($db, $filename)
Definition: template.php:799
The default user class. Provide all functions to handle the user object.
Definition: user.php:17
static getUserList($db)
output a list of all users (who have not activated privacy switch)
Definition: user.php:2129
$result
Definition: email-send.php:137
$template selectedTemplate
Definition: index.php:170
$type
$sql
Definition: message-new.php:32
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
$field
Definition: booking.php:9
if(isset($_POST['save'])) $settings
if(isset($_GET) &&(!empty($_GET))) $googleFonts
$fontArray
$indicators
Definition: index.php:57
$col
Definition: index.php:79
$template name
if(isset($_GET['positionIndicatorStatus'])) $templateSettings
$oldTplSettings
if(!isset($db)) if(!isset($lang)) $update
$url
Definition: user-new.php:101
$value
$position[$i]
$i