YaWK  24.1
Yet another WebKit
settings-fonts.php
Go to the documentation of this file.
1 <?php
2 use YAWK\alert;
3 use YAWK\backend;
4 use YAWK\db;
5 use YAWK\language;
6 use YAWK\template;
7 /** @var $db db */
8 /** @var $lang language */
9 
10 // FONT ACTIONS.....
11 // upload folder
12 $fontFolder = "../system/fonts/";
13 if (isset($_GET) && (!empty($_GET)))
14 { // user wants upload a custom font (ttf, otf or woff)
15  if (isset($_GET['add']) && ($_GET['add'] === "true"))
16  { // check if data is here
17  if (isset($_POST) && (!empty($_POST)))
18  { // check if new font file was sent
19  if (isset($_FILES['fontFile']['tmp_name']) && (!empty($_FILES['fontFile']['tmp_name'])))
20  { // allowed file extensions
21  $exts = array('ttf', 'otf', 'woff');
22  // file type seems to be ok
23  $fontFileName = $_FILES['fontFile']['name'];
24  // check if file is there, error supressor used for php 7 reasons (better solution?)
25  if(@in_array(end(explode('.', $fontFileName)), $exts))
26  {
27  // folder and file to upload
28  $uploadFile = $fontFolder . basename($_FILES['fontFile']['name']);
29 
30  // check if directory is existent and writeable
31  if (is_dir($fontFolder) && is_writable($fontFolder))
32  {
33  // copy file to font folder
34  if (move_uploaded_file($_FILES['fontFile']['tmp_name'], $uploadFile))
35  { // upload ok, throw success msg
36  alert::draw("success", $lang['SUCCESS'], "$lang[UPLOAD_SUCCESSFUL]: $uploadFile", "", 1800);
37  }
38  else
39  { // file upload failed - throw msg with error code
40  alert::draw("danger", $lang['ERROR'], "$lang[UPLOAD_FAILED]: $uploadFile $lang[ERROR]: ".$_FILES['fontFile']['error']."", "", 2600);
41  }
42  }
43  else
44  { // folder does not exist or is not writeable
45  alert::draw("danger", $lang['ERROR'], "$lang[FILE_UPLOAD_ERROR] $lang[FOLDER]: $uploadFile", "", 4800);
46  }
47  }
48  else
49  { // wrong file type
50  alert::draw("danger", $lang['ERROR'], "$lang[FONT_WRONG_TYPE]", "", 4600);
51  }
52  }
53 
54  // add new google font to database
55  if (isset($_POST['gfont']) && (!empty($_POST['gfont']) && (isset($_POST['gfontDescription']) && (!empty($_POST['gfontDescription'])))))
56  {
57  $description = $_POST['gfontDescription'];
58  $gfont = $_POST['gfont'];
59  // add google font
60  if (template::addgfont($db, $gfont,$description) === true)
61  { // successful, throw info
62  alert::draw("success", "$lang[TPL_ADD_GFONT]", "$lang[ADD_SUCCESSFUL]: $_POST[gfont]", '', 1800);
63  }
64  else
65  { // add gfont failed - throw error
66  alert::draw("danger", "$lang[TPL_ADD_GFONT]", "$lang[ADD_FAILED]: $_POST[gfont]", '', 4600);
67  }
68  }
69  }
70  }
71 
72  // DELETE FONT ACTION REQUESTED
73  if (isset($_GET['delete']) && ($_GET['delete'] === "true"))
74  { // check which type of font it is
75  if (isset($_GET['type']) && (!empty($_GET['type'])))
76  { // custom font (.ttf, .otf or .woff)
77  if ($_GET['type'] === "custom")
78  { // check if font is sent
79  if (isset($_GET['font']) && (!empty($_GET['font'])))
80  { // check if file is existent
81  if (is_file($fontFolder.$_GET['font']))
82  { // try to delete file
83  if (unlink($fontFolder.$_GET['font']))
84  { // all good, throw success msg
85  alert::draw("success", "$lang[SUCCESS]", "$lang[FONT_DEL_OK]: $_GET[font]", "", 1200);
86  }
87  else
88  { // failed to delete file
89  alert::draw("danger", "$lang[ERROR]", "$lang[FONT_DEL_FAILED]", "", 2600);
90  }
91  }
92  else
93  { // file does not exist
94  alert::draw("success", "$lang[ERROR]", "$lang[FILEMAN_FILE_DOES_NOT_EXIST] $fontFolder$_GET[font]", "", 4600);
95  }
96  }
97  else
98  { // no font was sent - manipulated get vars?!
99  alert::draw("success", "$lang[ERROR]", "$lang[VARS_MANIPULATED]", "", 4600);
100  }
101  }
102  else
103  { // it must be a google font...
104  if (template::deleteGfont($db, '', $_GET['font']) === true)
105  {
106  alert::draw("success", "$lang[SUCCESS]", "$lang[FONT_DEL_OK]: $_GET[font]", "", 1200);
107  }
108  else
109  { // failed to delete file
110  alert::draw("danger", "$lang[ERROR]", "$lang[FONT_DEL_FAILED]", "", 2600);
111  }
112  }
113  }
114  else
115  { // no type was sent - manipulated get vars?!
116  alert::draw("success", "$lang[ERROR]", "$lang[VARS_MANIPULATED]", "", 4600);
117  }
118  }
119 }
120 
121 // load google fonts from database into array
122 $googleFonts = template::getGoogleFontsArray($db);
123 // load font files from folder to array
124 $fontArray = template::getFontsFromFolder($fontFolder);
125 
126 $cssTTF = '';
127 $cssOTF = '';
128 $cssWOFF = '';
130 
131 // check if there are any true type fonts
132 if (isset($fontArray['ttf']) && (!empty($fontArray['ttf'])))
133 {
134  // walk through ttf array
135  foreach ($fontArray['ttf'] as $font)
136  { // set ttf font family css
137  $cssTTF .= "
138  @font-face { font-family: '$font';
139  src: url('$fontFolder$font') format('truetype'); }
140  ";
141  }
142 }
143 // check if there are any otf type fonts
144 if (isset($fontArray['otf']) && (!empty($fontArray['otf'])))
145 {
146  // walk through otf array
147  foreach ($fontArray['otf'] as $font)
148  { // set otf font family css
149  $cssOTF .= "
150  @font-face { font-family: '$font';
151  src: url('$fontFolder$font') format('opentype'); }
152  ";
153  }
154 }
155 
156 // check if there are any woff type fonts
157 if (isset($fontArray['woff']) && (!empty($fontArray['woff'])))
158 {
159  // walk through woff array
160  foreach ($fontArray['woff'] as $font)
161  { // set woff font family css
162  $cssWOFF .= "
163  @font-face { font-family: '$font';
164  src: url('$fontFolder$font') format('woff'); }
165  ";
166  }
167 }
168 
169 // check if there are any google fonts
170 if (isset($googleFonts) && (!empty($googleFonts)))
171 {
172  // walk through google fonts array
173  foreach ($googleFonts as $gFont)
174  { // set google font family css
175  $cssGoogleFont .= "
176  <link href=\"https://fonts.googleapis.com/css?family=$gFont\" rel=\"stylesheet\">
177  ";
178  }
179 }
180 
181 // output Google <link href="...">
182 echo $cssGoogleFont;
183 // output custom font css styles
184 echo "<style>
185  ".$cssTTF."
186  ".$cssOTF."
187  ".$cssWOFF."
188  </style>";
189 ?>
190 
191 
192 <?php
193 // TEMPLATE WRAPPER - HEADER & breadcrumbs
194 echo "
195  <!-- Content Wrapper. Contains page content -->
196  <div class=\"content-wrapper\" id=\"content-FX\">
197  <!-- Content Header (Page header) -->
198  <section class=\"content-header\">";
199 // draw Title on top
200 echo backend::getTitle($lang['SETTINGS'], $lang['FONTS']);
201 echo backend::getSettingsBreadcrumbs($lang);
202 echo"</section><!-- Main content -->
203  <section class=\"content\">";
204 /* page content start here */
205 ?>
206  <div class="box">
207  <div class="box-body">
208  <div class="col-md-10">
209  <?php echo "<h4><i class=\"fa fa-font\"></i> &nbsp;$lang[FONTS]&nbsp;<small>$lang[CONFIGURE]</small></h4>"; ?>
210  </div>
211  <div class="col-md-2">
212  <a href="#" id="addFontBtn" class="btn btn-success pull-right" data-toggle="modal" data-target="#myModal" style="margin-top:2px;"><i class="fa fa-plus"></i>&nbsp; <?php echo "$lang[FONT_ADD]"; ?></a>
213  </div>
214  </div>
215  </div>
216 
217  <!-- FONT MANAGEMENT -->
218  <div class="row">
219  <!-- GOOGLE FONTS OVERVIEW -->
220  <div class="col-md-3">
221  <div class="box">
222  <div class="box-header with-border">
223  <h3 class="box-title"><?php echo $lang['FONTS_GOOGLE']; ?> <small> <?php echo $lang['FONTS_GFONT']; ?></small></h3>
224  </div>
225  <div class="box-body">
226  <?php
227  // check if google fonts are set
228  if (isset($googleFonts) && (!empty($googleFonts)))
229  { // draw google fonts list
230  backend::drawFontList($googleFonts, $fontFolder, 'Google', $lang);
231  }
232  ?>
233  </div>
234  </div>
235  </div>
236  <!-- TTF FONT OVERVIEW -->
237  <div class="col-md-3">
238  <div class="box">
239  <div class="box-header with-border">
240  <h3 class="box-title"><?php echo $lang['FONTS_TTF']; ?> <small> <?php echo $lang['FONTS_TRUETYPE']; ?></small></h3>
241  </div>
242  <div class="box-body">
243  <?php
244  // check if true type fonts are set
245  if (isset($fontArray['ttf']) && (!empty($fontArray['ttf'])))
246  { // draw TTF font list
247  backend::drawFontList($fontArray['ttf'], $fontFolder, '.ttf', $lang);
248  }
249  ?>
250  </div>
251  </div>
252  </div>
253  <!-- OTF FONTS OVERVIEW -->
254  <div class="col-md-3">
255  <div class="box">
256  <div class="box-header with-border">
257  <h3 class="box-title"><?php echo $lang['FONTS_OTF']; ?> <small> <?php echo $lang['FONTS_OPENTYPE']; ?></small></h3>
258  </div>
259  <div class="box-body">
260  <?php
261  // check if otf fonts are set
262  if (isset($fontArray['otf']) && (!empty($fontArray['otf'])))
263  { // draw OTF font list
264  backend::drawFontList($fontArray['otf'], $fontFolder, '.otf', $lang);
265  }
266  ?>
267  </div>
268  </div>
269  </div>
270  <!-- WOFF FONT OVERVIEW -->
271  <div class="col-md-3">
272  <div class="box">
273  <div class="box-header with-border">
274  <h3 class="box-title"><?php echo $lang['FONTS_WOFF']; ?> <small> <?php echo $lang['FONTS_WEBOPEN']; ?></small></h3>
275  </div>
276  <div class="box-body">
277  <?php
278  // check if woff fonts are set
279  if (isset($fontArray['woff']) && (!empty($fontArray['woff'])))
280  { // draw WOFF fonts list
281  backend::drawFontList($fontArray['woff'], $fontFolder, '.woff', $lang);
282  }
283  ?>
284  </div>
285  </div>
286  </div>
287  </div>
288 
289 <!-- Modal --ADD FONT-- -->
290 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModal2Label" aria-hidden="true">
291  <div class="modal-dialog">
292  <div class="modal-content">
293  <form enctype="multipart/form-data" action="index.php?page=settings-fonts&add=true" method="POST">
294  <div class="modal-header">
295  <!-- modal header with close controls -->
296  <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i> </button>
297  <br>
298  <div class="col-md-1"><h3 class="modal-title"><i class="fa fa-font"></i></h3></div>
299  <div class="col-md-11"><h3 class="modal-title"><?php echo $lang['FONT_ADD']; ?></h3></div>
300  </div>
301 
302  <!-- modal body -->
303  <div class="modal-body">
304  <!-- ADD CUSTOM FONT -->
305  <h4><b><?php echo $lang['FONT_ADD_CUSTOM']; ?></b></h4>
306  <b><?php echo $lang['FONTS_SUPPORTED']; ?></b>
307  <ul>
308  <li><b>.ttf</b> <small><i>(TrueType)</i></small></li>
309  <li><b>.otf</b> <small><i>(Open Type Font)</i></small></li>
310  <li><b>.woff</b> <small><i>(Web Open Font Format)</i></small></li>
311  </ul>
312 
313  <label for="fontFile"><?php echo $lang['SELECT_FILE']; ?></label>
314  <input type="hidden" name="MAX_FILE_SIZE" value="4194304"> <!-- 4 MB -->
315  <input type="file" class="form-control" id="fontFile" name="fontFile">
316  <small><?php echo $lang['FONTS_PATH']; ?></small>
317  <hr>
318  <h4><b><?php echo $lang['FONT_ADD_GFONT']; ?></b></h4>
319  <label for="gfont"><?php echo $lang['FONT_GOOGLE_NAME']; ?></label>
320  <input type="text" class="form-control" id="gfont" name="gfont" placeholder="<?php echo $lang['FONT_GOOGLE_NAME_PH']; ?>">
321  <label for="gfontDescription"><?php echo $lang['FONT_GOOGLE_DESC']; ?></label>
322  <input type="text" class="form-control" name="gfontDescription" id="gfontDescription" placeholder="<?php echo $lang['FONT_GOOGLE_DESC_PH']; ?>">
323 
324  </div>
325 
326  <!-- modal footer /w submit btn -->
327  <div class="modal-footer">
328  <input class="btn btn-large btn-default" data-dismiss="modal" aria-hidden="true" type="submit" value="<?php echo $lang['CANCEL']; ?>">
329  <button class="btn btn-large btn-success" type="submit"><i class="fa fa-check"></i>&nbsp; <?php echo $lang['FONT_ADD']; ?></button>
330  <br><br>
331  </div>
332  </form>
333  </div> <!-- modal content -->
334  </div> <!-- modal dialog -->
335 </div>
print $lang['FILEMAN_UPLOAD']
Throws a fancy Bootstrap Alert (success, info, warning or danger)
Definition: alert.php:19
Backend class serves a few useful functions for the admin backend.
Definition: backend.php:27
Mysqli database class; returns db connection object.
Definition: db.php:16
The language class - support multilingual backend.
Definition: language.php:17
The template controller - get and set template settings.
Definition: template.php:16
function b(a)
Definition: browser.js:14
function a
Definition: browser.js:14
type
Definition: menu-new.php:35
print $_GET['id']
Definition: page-edit.php:357
function i(e, t)
Definition: plyr.js:1
function w(e, t)
Definition: plyr.js:1
if(isset($_GET) &&(!empty($_GET))) $googleFonts
$cssGoogleFont
$fontFolder
$fontArray
$cssWOFF
<!-- backend language -->< h3 >< i class="fa fa-language"></i > & nbsp
$template name