YaWK  24.1
Yet another WebKit
cssFramework.php
Go to the documentation of this file.
1 <?php
2 namespace YAWK\FRAMEWORK {
3 use YAWK\language;
4 
5  /**
6  * @details <b>Bootstrap CSS check version + return corresponding css</b>
7  * <p>This is a helper function, used by admin/includes/template-save.php.
8  * It generates the custom css code for the current loaded bootstrap version,
9  * depending on the selection of the fields within the backend.</p>
10  *
11  * @author Daniel Retzl <[email protected]>
12  * @copyright 2018 Daniel Retzl yawk.io
13  * @license https://opensource.org/licenses/MIT
14  * @version 1.0.0
15  * @brief Helper function to output custom (overriden) bootstrap css (settings.css)
16  */
18  {
19  /** @param int current loaded bootstrap version */
20  public $version = '';
21  /** @param array template settings array */
22  public $tplSettings = '';
23  /** @param string all the css as string */
24  public $cssCode = '';
25 
26  // call constructor on object creation
27 
28  /**
29  * cssFramework constructor.
30  * @param $version string the current bootstrap version to work with
31  * @param $tplSettings array the template settings array
32  */
33  public function __construct($version, $tplSettings)
34  {
35  /** @var $lang language */
36  // check if bootstrap version is set
37  if (isset($version) && (is_string($version) && (!empty($version))))
38  {
39  // set this bootstrap version
40  $this->version = $version;
41  }
42  else
43  { // bootstrap version not set, try to query current active version
44  if (!isset($db))
45  { // create new db object
46  $db = new \YAWK\db;
47  }
48  // check if template obj is set
49  if (!isset($template))
50  { // if not, create new template object
51  $template = new \YAWK\template();
52  }
53  // get current template ID
54  $currentTemplateID = \YAWK\template::getCurrentTemplateId($db);
55  // check and set current bootstrap version
56  $this->version = $template->checkBootstrapVersion($db, $currentTemplateID, $lang);
57  }
58 
59  // check and set this template settings array
60  if (isset($tplSettings) && (is_array($tplSettings)) && (!empty($tplSettings)))
61  { // set this template settings array
62  $this->tplSettings = $tplSettings;
63  }
64  else
65  { // tpl settings param not set, empty or wrong type - try to query array instead
66  if (!isset($db))
67  { // create new db object
68  $db = new \YAWK\db;
69  }
70  // get current template ID
71  $currentTemplateID = \YAWK\template::getCurrentTemplateId($db);
72  // get template settings array
73  $this->tplSettings = \YAWK\template::getTemplateSettingsArray($db, $currentTemplateID);
74  }
75  }
76 
77 
78  /**
79  * @details Initialize and start check function
80  * @return string|null the generated css code as (big) string
81  * @brief Init calls setBootstrapComponents and return all css code as string on success or null on error
82  */
83  public function init()
84  {
85  // load required methods, depending on this bootstrap version
86  if ($this->setBootstrapComponents() === true)
87  {
88  // ok, return css code
89  return $this->cssCode;
90  }
91  else
92  { // unknown error
93  return null;
94  }
95  }
96 
97  /**
98  * @details Check and return generated CSS Code as string
99  * @return string|null the generated css code as (big) string
100  * @brief Check CSS code and return it on success as string, otherwise return null
101  */
102  public function outputCssCode()
103  { // check if css code string is set and not empty
104  if (isset($this->cssCode) && (is_string($this->cssCode) && (!empty($this->cssCode))))
105  { // ok, return css code
106  return $this->cssCode;
107  }
108  else
109  { // do nothing
110  return null;
111  }
112  }
113 
114  /**
115  * @brief Check if Bootstrap is version 3 or 4 and load the required component methods
116  * @return true|null the generated css code as (big) string
117  * @details Return true after executing component methods or false if Bootstrap version is unknown
118  */
119  public function setBootstrapComponents()
120  {
121  // if Bootstrap 3 is loaded
122  if ($this->version == 3)
123  { // include bootstrap 3 class
124  require_once 'bootstrap3.php';
125  // generate new object
126  $bootstrap3 = new \YAWK\FRAMEWORK\BOOTSTRAP3\bootstrap3($this->version, $this->tplSettings);
127  // init bootstrap 3 class
128  $this->cssCode = $bootstrap3->init();
129  // check if bootstrap 3 css code is set
130  if (isset($this->cssCode) && (is_string($this->cssCode) && (!empty($this->cssCode))))
131  { // bootstrap 3 css code is set
132  return true;
133  }
134  else
135  { // css code not set properly
136  return null;
137  }
138  }
139  // if Bootstrap 4 is loaded
140  if ($this->version == 4)
141  { // include bootstrap 4 class
142  require_once 'bootstrap4.php';
143  // generate new object
144  $bootstrap4 = new \YAWK\FRAMEWORK\BOOTSTRAP4\bootstrap4($this->version, $this->tplSettings);
145  // init bootstrap 4 class
146  $this->cssCode = $bootstrap4->init();
147  // check if bootstrap 4 css code is set
148  if (isset($this->cssCode) && (is_string($this->cssCode) && (!empty($this->cssCode))))
149  { // bootstrap 4 css code is set
150  return true;
151  }
152  else
153  { // css code not set properly
154  return null;
155  }
156  }
157  else
158  {
159  // bootstrap version not supported
160  return null;
161  }
162  }
163  }
164 }
print $lang['FILEMAN_UPLOAD']
Helper function to output custom (overriden) bootstrap css (settings.css)
init()
Init calls setBootstrapComponents and return all css code as string on success or null on error.
setBootstrapComponents()
Check if Bootstrap is version 3 or 4 and load the required component methods.
outputCssCode()
Check CSS code and return it on success as string, otherwise return null.
The language class - support multilingual backend.
Definition: language.php:17
static getTemplateSettingsArray($db, $templateID)
get all template settings into an array and return it
Definition: template.php:2794
static getCurrentTemplateId(object $db)
return ID of current (active) template
Definition: template.php:73