YaWK  24.1
Yet another WebKit
gallery.php
Go to the documentation of this file.
1 <?php
3  /**
4  * @details <b>Gallery Plugin</b>
5  * <p>Whenever you build a website, sooner or later you will get to the point where you need to put
6  * a few photos within a lightbox on your page.
7  * YaWK's gallery plugin help you out! It can build image galleries automatically. It does a perfect batch
8  * job adding a watermark to every image or resize images and much more. To add a new gallery, just place
9  * all your images in any folder and put that folder fia ftp to /media/images/{yourfolder}. If you don't like to use ftp,
10  * you could also use yawk's built-in file manager to upload your files. Once the upload is complete, go
11  * back to the gallery plugin and select your uploaded folder. (Or any other folder that is stored under /media/images)
12  * Set some settings and you're ready to go. When the gallery is created, load the gallery widget into
13  * any layout position you like, select which gallery to show up and you are done.</p>
14  * <p><b>Basic Features:</b></p>
15  * <ul>
16  * <li>put a text watermark onto all your images</li>
17  * <li>change color and style of your watermark text</li>
18  * <li>use any custom .ttf font (must be in /system/fonts)</li>
19  * <li>or watermark images overlaying any transparent image (eg. your logo as .png)</li>
20  * <li>watermark placement at bottom, middle or top, left or right with any margin</li>
21  * <li>change the size of your images</li>
22  * <li>flip horizontal or vertical</li>
23  * <li>rotate around 90 degrees</li>
24  * <li>fit to width</li>
25  * <li>fit to height</li>
26  * <li>fit to thumbnail</li>
27  * <li>auto create thumbnails with the size of your need</li></ul><br>
28  * <p><b>Image Manipulation: </b>irrespective from all of that, you can easy overview all images on a page and adjust</p>
29  * <ul><li>brightness</li>
30  * <li>contrast</li>
31  * <li>sharpen</li>
32  * <li>blur</li>
33  * <li>magic flatten</li>
34  * <li>sepia and much more <b>with just a few clicks!</b></li><br>
35  * </ul>
36  * <p>Try it out - this is a really biiiig time-saver! In most cases you don't need to open all images in
37  * photoshop. <i>(or something else)</i> Think about it: you <i>don't</i> need to open, edit and save every single
38  * image for each - Yet another WebKit's Gallery Plugin is here to do that automatically for you - you just need
39  * to set a few parameters, do a single click... - and everything will get set-up as you wish.</p>
40  * <p><i>Class covers backend functionality only.
41  * See Methods Summary for Details!</i></p>
42  *
43  * @author Daniel Retzl <[email protected]>
44  * @copyright 2009-2016 Daniel Retzl
45  * @version 1.0.0/
46  * @since File available since Release 1.0.0
47  * @brief The Gallery Plugin Class. Help you building powerful image galleries nearly automatically.
48  */
49  class gallery
50  {
51  /** * @param int gallery ID */
52  public $id;
53  /** * @param int item ID */
54  public $itemID;
55  /** * @param int order sortation number */
56  public $sort;
57  /** * @param string image manipulation action (eg. flip-horizontal) */
58  public $action;
59  /** * @param string images folder */
60  public $folder;
61  /** * @param string gallery title */
62  public $title;
63  /** * @param string item title */
64  public $itemTitle;
65  /** * @param string gallery description */
66  public $description;
67  /** * @param string images author (originator, photographer) */
68  public $author;
69  /** * @param string images author's url (originator, photographer) */
70  public $authorUrl;
71  /** * @param string single image author (originator, photographer) */
72  public $itemAuthor;
73  /** * @param string single image author's url (originator, photographer) */
75  /** * @param string image filename */
76  public $filename;
77  /** * @param int 0|1 switch: 1 if thumbnails should be created, zero if not. */
79  /** * @param int image width in px */
80  public $imageWidth;
81  /** * @param int image height in px */
82  public $imageHeight;
83  /** * @param int 0|1 switch: 1 if images should be resized, zero if not */
84  public $resizeImages;
85  /** * @param string type of resizing (eg. thumbnail or fit to width...) */
86  public $resizeType;
87  /** * @param int thumbnail width in px */
89  /** * @param string watermark text */
90  public $watermark;
91  /** * @param int 0|1 switch: 1 if watermark is enabled, zero if not */
93  /** * @param string the image which should be overlayed for watermarking */
95  /** * @param string watermark position */
97  /** * @param int offset Y in px */
98  public $offsetY;
99  /** * @param int offset X in px */
100  public $offsetX;
101  /** * @param string path and filename of the .ttf font to use for text watermarking */
103  /** * @param int watermark text size in pt */
105  /** * @param int watermark opacity */
107  /** * @param string watermark text color */
109  /** * @param string watermark text border color */
111  /** * @param string watermark border thickness in px */
113  /** * @param string headline */
114  public $headline;
115 
116  /**
117  * @brief define JS function doImageAction
118  * gallery constructor.
119  */
120  public function __construct()
121  {
122  echo "<script type=\"text/javascript\">
123  function doImageAction(action, id, folder, filename, itemID, createThumbnails, thumbnailWidth, watermark, watermarkImage, watermarkOpacity, watermarkPosition, offsetX, offsetY, watermarkFont, watermarkTextSize, watermarkColor, watermarkBorderColor, watermarkBorder)
124  {
125  $.ajax({
126  url:'../system/plugins/gallery/js/actions.php',
127  type:'post',
128  data:'action='+action+'&id='+id+'&folder='+folder+'&filename='+filename+'&itemID='+itemID+'&createThumbnails='+createThumbnails+'&thumbnailWidth='+thumbnailWidth+'&watermark='+watermark+'&watermarkImage='+watermarkImage+'&watermarkOpacity='+watermarkOpacity+'&watermarkPosition='+watermarkPosition+'&offsetX='+offsetX+'&offsetY='+offsetY+'&watermarkFont='+watermarkFont+'&watermarkTextSize='+watermarkTextSize+'&watermarkColor='+watermarkColor+'&watermarkBorderColor='+watermarkBorderColor+'&watermarkBorder='+watermarkBorder,
129  dataType: 'json',
130  // dataType: 'json',
131  success: function(data)
132  {
133  // alert(data.status);
134  var status = data.status;
135  var action = data.action;
136  if(status == 'delete')
137  { // delete successful, reload page afterwards to update gallery view
138  // console.log( data );
139  $('#imgCol-'+itemID).hide();
140  $('#toolset-'+itemID).hide();
141  return true;
142  // location.reload();
143  }
144  if(status == 'true')
145  { // after any other action, reload that image to see changes
146  $('#img-'+itemID).hide().removeAttr('src').attr('src', '../'+folder+'/'+filename+'?'+Math.random()).show();
147  return true;
148  }
149  if(status == 'false')
150  { // could not manipulate image
151  alert('Sorry, the action '+action+'could not be done.');
152  return false;
153  }
154  else
155  { // any other error
156  alert('Sorry, undefined error executing '+action+'. Maybe there is a problem with your image folders, files or permissions.');
157  return false;
158  }
159  }
160  });
161  }
162  </script>";
163  }
164 
165  /**
166  * @brief draw (output) html folder select field, containing the sub folders of /media/images as value
167  * @param array $lang language array
168  * @param string $path usually media/images/
169  */
170  public function drawFolderSelect($lang, $path)
171  {
172  echo "<select name=\"folder\" class=\"form-control\" id=\"folder\">
173  <option value=\"\">$lang[SELECT_FOLDER]</option>
174  " . self::scanImageDirectory($path) . "
175  </select>";
176  }
177 
178  /**
179  * @brief draw (output) html folder select field, containing the current folder of /media/images as value
180  * @param string $path usually media/images/
181  * @param string $folder the folder of this gallery
182  */
183  public function drawFolderSelectFromGallery($path, $folder)
184  {
185  echo "<select name=\"folder\" class=\"form-control\" id=\"folder\">
186  <option value=\"$folder\">$folder</option>
187  " . self::scanImageDirectory($path) . "
188  </select>";
189  }
190 
191  /**
192  * @brief check if folder exists and create it on demand
193  * @param string $folder affected folder
194  * @return bool
195  */
196  public function checkDir($folder)
197  { // check if directory exists
198  if (!is_dir("$folder/")) { // folder does not exist, create it
199  if (mkdir("$folder/")) { // folder created,
200  return true;
201  } else { // could not create folder
202  return false;
203  }
204  } else { // directory exists
205  return true;
206  }
207  }
208 
209 
210  /**
211  * @brief scan system font directory for fonts and return fonts as select field option value
212  * @param string $path the path to search for fonts. If its empty, the default folder will be ../system/fonts/
213  * @return string oprion value containing all fonts from font directory
214  */
215  public function scanFonts($path)
216  {
217  $html = '';
218  if (!isset($path)) {
219  $path = "../system/fonts/"; // '.' for current
220  }
221  foreach (new \DirectoryIterator("$path") as $file) {
222  if ($file->isDot()) continue;
223  if ($file->isDir()) continue;
224  if ($file->getExtension() === "ttf") {
225  // print $file->getFilename() . '<br>';
226  $html .= "<option value=\"$path" . $file->getFilename() . "\">system/fonts/" . $file->getFilename() . "</option>";
227  }
228 
229  }
230  return $html;
231  }
232 
233  /**
234  * @brief scan image directory and return images as select field option value
235  * @param string $path usually media/images/
236  * @return string option value containing all fonts from font directory
237  */
238  public function scanImageDirectory($path)
239  {
240  $html = '';
241  if (!isset($path)) {
242  $path = "media/images/"; // '.' for current
243  }
244  foreach (new \DirectoryIterator("../$path") as $file) {
245  if ($file->isDot()) continue;
246  if ($file->isDir()) {
247  // print $file->getFilename() . '<br>';
248  $html .= "<option value=\"$path" . $file->getFilename() . "\">images/" . $file->getFilename() . "</option>";
249  }
250  }
251  return $html;
252  }
253 
254  /**
255  * @brief delete a gallery
256  * @param object $db database
257  * @return bool
258  */
259  public function delete($db)
260  {
261  /** @var $db \YAWK\db * */
262  // check if a gallery ID is set and in correct format
263  if (isset($_GET['id']) && (!empty($_GET['id']) && (is_numeric($_GET['id'])))) {
264  // gallery folder
265  $folder = $this->getGalleryFolderByID($db, $_GET['id']);
266  // DELETE FILES
267  // check if thumbnail directory is here
268  if (is_dir("../$folder/thumbnails/")) { // try to delete it recursively
269  if (!\YAWK\sys::recurseRmdir("../$folder/thumbnails/")) { // did not work, throw notification
270  \YAWK\alert::draw("warning", "Could not delete thumbnails!", "$folder/thumbnails could not be deleted.", "", 5800);
271  } else { // thumbnails deleted success msg
272  \YAWK\alert::draw("success", "Thumbnails deleted!", "$folder/thumbnails is removed.", "", 1200);
273  }
274  }
275  // check if edit directory is here
276  if (is_dir("../$folder/edit/")) { // try to delete it recursively
277  if (!\YAWK\sys::recurseRmdir("../$folder/edit/")) { // did not work, throw notification
278  \YAWK\alert::draw("warning", "Could not delete edit folder!", "$folder/edit could not be deleted.", "", 5800);
279  } else { // delete edit (tmp) folder did not work, throw notify...
280  // \YAWK\alert::draw("success", "TMP folder deleted!", "$folder/edit is removed.", "", 1200);
281  }
282  }
283 
284  // check if there are backup files to restore
285  if (is_dir("../$folder/original/")) {
286  // delete images in root folder of this gallery
287  foreach (new \DirectoryIterator("../$folder/") as $fileInfo) {
288  if ($fileInfo->isDir()) continue;
289  if ($fileInfo->isDot()) continue;
290  $filename = $fileInfo->getFilename();
291  unlink("../$folder/$filename");
292  }
293  // copy images back from backup folder
294  foreach (new \DirectoryIterator("../$folder/original") as $fileInfo) {
295  if ($fileInfo->isDir()) continue;
296  if ($fileInfo->isDot()) continue;
297  $filename = $fileInfo->getFilename();
298  // copy files from backup folder back to root directory
299  if (!copy("../$folder/original/$filename", "../$folder/$filename")) { // could not copy file, throw notification
300  \YAWK\alert::draw("warning", "Could not restore file $filename", "This should not happen. We're sorry!", "", 800);
301  }
302  }
303 
304  // delete backup folder
305  if (!\YAWK\sys::recurseRmdir("../$folder/original/")) { // did not work, throw notification
306  \YAWK\alert::draw("warning", "Could not delete backup folder!", "$folder/original could not be deleted.", "", 5800);
307  }
308  }
309 
310  // delete gallery from database
311  if ($res = $db->query("DELETE FROM {plugin_gallery} WHERE id = '$_GET[id]'")) { // gallery deleted...
312  // now go ahead with the items
313  if (!$deleteItems = $db->query("DELETE FROM {plugin_gallery_items}
314  WHERE galleryID = '$_GET[id]'")) { // could not delete items
315  \YAWK\alert::draw("warning", "Could not delete gallery items from database", "Please try again!", "", 5800);
316  }
317 
318  // RESET AUTO INCREMENT
319  // ALTER table and set auto_increment value to prevent errors when deleting + adding new tpl
320  if ($alterTable = $db->query("SELECT MAX(id) FROM {plugin_gallery}")) { // get MAX ID
321  $row = mysqli_fetch_row($alterTable);
322  if ($row[0] >= 1) {
323  if (!$alterTable = $db->query("ALTER TABLE {plugin_gallery} AUTO_INCREMENT=$row[0]")) { // could not delete plugin_gallery
324  return false;
325  }
326  } else {
327  // could not get maxID, maybe there is not entry - reset auto increment value to zero
328  if (!$alterTable = $db->query("ALTER TABLE {plugin_gallery} AUTO_INCREMENT=1")) { // could not select auto encrement
329  return false;
330  }
331 
332  }
333  }
334  // RESET AUTO INCREMENT
335  // ALTER table and set auto_increment value to prevent errors when deleting + adding new tpl
336  if ($alterItemsTable = $db->query("SELECT MAX(id) FROM {plugin_gallery_items}")) { // get MAX ID
337  $row = mysqli_fetch_row($alterItemsTable);
338  if ($row[0] >= 1) {
339  if (!$alterItemsTable = $db->query("ALTER TABLE {plugin_gallery_items} AUTO_INCREMENT=$row[0]")) { // could not delete plugin_gallery
340  return false;
341  }
342  } else {
343  // could not get maxID, maybe there is not entry - reset auto increment value to zero
344  if (!$alterItemsTable = $db->query("ALTER TABLE {plugin_gallery_items} AUTO_INCREMENT=1")) { // could not select auto encrement
345  return false;
346  }
347 
348  }
349  }
350  } else { // delete failed, throw error
351  \YAWK\alert::draw("danger", "Could not delete this gallery", "Please try again!", "", 5800);
352  }
353  }
354  return true;
355  }
356 
357  /**
358  * @brief return gallery folder by given gallery ID
359  * @param object $db database
360  * @param int $galleryID the gallery ID to get the folder from
361  * @return string|bool gallery folder or false
362  */
363  public function getGalleryFolderByID($db, $galleryID)
364  {
365  /** @var $db \YAWK\db * */
366  if ($res = $db->query("SELECT folder from {plugin_gallery} WHERE id='$galleryID'")) { // fetch data
367  $row = mysqli_fetch_row($res);
368  return $row[0]; // return folder
369  } else { // error fetch data
370  return false;
371  }
372  }
373 
374  /**
375  * @brief re-scan a folder to check if there a new images added TODO: STILL BUGGY - needs to be fixed + finished
376  * @param object $db database
377  * @param int $galleryID the gallery ID
378  * @return bool
379  */
380  public function reScanFolder($db, $galleryID)
381  {
382  /** @var $db \YAWK\db * */
383  if (isset($galleryID) && (!empty($galleryID) && (is_numeric($galleryID)))) { // check if folder obj property is set
384  if (!isset($this->folder) && (empty($this->folder))) { // if not, get folder from ID
385  $this->folder = $this->getGalleryFolderByID($db, $galleryID);
386  }
387  if ($res = $db->query("SELECT filename from {plugin_gallery_items} WHERE galleryID = $galleryID")) { // get items from database
388  $dbItems = mysqli_fetch_assoc($res);
389  } else {
390  $dbItems = '';
391  }
392 
393  // TODO: only files that are NOT in the folder should be processed - still buggy yet!
394 
395  // walk through images folder
396  foreach (new \DirectoryIterator("../$this->folder/") as $image) { // exclude dots'n'dirs
397  if ($image->isDot()) continue; // exclude dots
398  if ($image->isDir()) continue; // exclude subdirectories
399  $filename = $image->getFilename();
400 
401  foreach ($dbItems as $item) {
402  if ($item === $filename) {
403 
404  } else {
405  \YAWK\alert::draw("info", "$item", "$item", "", 5800);
406  if (!@copy("../$this->folder/$filename", "../$this->folder/original/$filename")) { // could not copy file, throw notification
407  \YAWK\alert::draw("warning", "Could not copy file $filename to original folder", "Could not copy image to backup folder!", "", 800);
408  }
409  if (!@copy("../$this->folder/$filename", "../$this->folder/edit/$filename")) { // could not copy file, throw notification
410  \YAWK\alert::draw("warning", "Could not copy file $filename to edit folder", "Could not copy image to backup folder!", "", 800);
411  }
412  if (!$res = $db->query("INSERT INTO {plugin_gallery_items} (galleryID, filename) VALUES ('" . $galleryID . "', '" . $filename . "')")) { // could not add image data to db
413  \YAWK\alert::draw("warning", "Could not add image data to database.", "Error inserting <b>$filename</b>.", "", 2800);
414  }
415  }
416  }
417  }
418  return true;
419  } else { // no id is set
420  return false;
421  }
422  }
423 
424  /**
425  * @brief add a new gallery
426  * @param object $db database
427  * @return bool
428  * @throws \Exception
429  */
430  public function add($db)
431  {
432  /** @var $db \YAWK\db * */
433  // add a new gallery
434  // 1.) check vars
435  // 2.) manipulate images corresponding to selected settings
436  // 3.) insert into database
437 
438  // loading info...
439  \YAWK\alert::draw("success", "Gallery will be created. . .", "<div class=\"text-center\"><i class=\"fa fa-spinner fa-spin\" style=\"font-size:24px\"></i><br>Please be patient, this should only take a few seconds.</div>", "", 3800);
440 
441  // include SimpleImage Class
442  require_once 'SimpleImage.php';
443  // create object
444  $img = new \YAWK\SimpleImage();
445 
446  if (isset($_POST['folder']) && (!empty($_POST['folder']))) { // gallery folder
447  $this->folder = $db->quote($_POST['folder']);
448  }
449  if (isset($_POST['customFolder']) && (!empty($_POST['customFolder']))) { // if a custom folder is set, overwrite gallery folder
450  $this->folder = $_POST['customFolder'];
451  }
452  if (isset($_POST['title']) && (!empty($_POST['title']))) { // gallery title
453  $this->title = $db->quote($_POST['title']);
454  }
455  if (isset($_POST['description']) && (!empty($_POST['description']))) { // gallery description
456  $this->description = $db->quote($_POST['description']);
457  }
458  if (isset($_POST['createThumbnails']) && (!empty($_POST['createThumbnails']))) { // thumbnails? 0|1
459  $this->createThumbnails = $db->quote($_POST['createThumbnails']);
460  }
461  if (isset($_POST['thumbnailWidth']) && (!empty($_POST['thumbnailWidth']))) { // thumbnail width in px
462  $this->thumbnailWidth = $db->quote($_POST['thumbnailWidth']);
463  }
464  if (isset($_POST['watermark']) && (!empty($_POST['watermark']))) { // any string can do the watermark job
465  $this->watermark = $db->quote($_POST['watermark']);
466  }
467  if (isset($_POST['watermarkPosition']) && (!empty($_POST['watermarkPosition']))) { // position of the watermark (bottom left, bottom right, top left, top right, bottom, center, top)
468  $this->watermarkPosition = $db->quote($_POST['watermarkPosition']);
469  }
470  if (isset($_POST['author']) && (!empty($_POST['author']))) { // name of the author, studio, photographer, originator
471  $this->author = $db->quote($_POST['author']);
472  }
473  if (isset($_POST['authorUrl']) && (!empty($_POST['authorUrl']))) { // url of the photographer (author, originator)
474  $this->authorUrl = $db->quote($_POST['authorUrl']);
475  }
476  if (isset($_POST['watermarkImage']) && (!empty($_POST['watermarkImage']))) { // any image used as watermark (preferably transparent png-24)
477  $this->watermarkImage = $db->quote($_POST['watermarkImage']);
478  }
479  if (isset($_POST['offsetY']) && (!empty($_POST['offsetY']))) { // offset bottom (from bottom)
480  $this->offsetY = $db->quote($_POST['offsetY']);
481  }
482  if (isset($_POST['offsetX']) && (!empty($_POST['offsetX']))) { // offset right (from right)
483  $this->offsetX = $db->quote($_POST['offsetX']);
484  }
485  if (isset($_POST['watermarkFont']) && (!empty($_POST['watermarkFont']))) { // true type font to use for watermarking (located in system/fonts/)
486  // $this->watermarkFont = $db->quote($_POST['watermarkFont']);
487  $this->watermarkFont = ($_POST['watermarkFont']);
488  }
489  if (isset($_POST['watermarkTextSize']) && (!empty($_POST['watermarkTextSize']))) { // text size of your watermark
490  $this->watermarkTextSize = $db->quote($_POST['watermarkTextSize']);
491  }
492  if (isset($_POST['watermarkOpacity']) && (!empty($_POST['watermarkOpacity']))) { // opacity (this works only, when watermark is set to an image!)
493  $this->watermarkOpacity = $db->quote($_POST['watermarkOpacity']);
494  }
495  if (isset($_POST['watermarkColor']) && (!empty($_POST['watermarkColor']))) { // text color of your text-watermark
496  $this->watermarkColor = $db->quote($_POST['watermarkColor']);
497  }
498  if (isset($_POST['watermarkBorderColor']) && (!empty($_POST['watermarkBorderColor']))) { // border color of your text-watermark
499  $this->watermarkBorderColor = $db->quote($_POST['watermarkBorderColor']);
500  }
501  if (isset($_POST['watermarkBorder']) && (!empty($_POST['watermarkBorder']))) { // text-border in px
502  $this->watermarkBorder = $db->quote($_POST['watermarkBorder']);
503  }
504 
505  if ($this->watermarkPosition === "---") {
506  $this->watermarkPosition = "bottom right";
507  }
508  if (empty($this->thumbnailWidth) || ($this->thumbnailWidth === "0")) {
509  $this->thumbnailWidth = 200;
510  }
511 
512  // add new gallery to database
513  if ($res = $db->query("INSERT INTO {plugin_gallery} (folder,
514  title,
515  description,
516  createThumbnails,
517  thumbnailWidth,
518  watermark,
519  watermarkEnabled,
520  watermarkPosition,
521  watermarkImage,
522  offsetY,
523  offsetX,
524  watermarkFont,
525  watermarkTextSize,
526  watermarkOpacity,
527  watermarkColor,
528  watermarkBorderColor,
529  watermarkBorder)
530  VALUES ('" . $this->folder . "',
531  '" . $this->title . "',
532  '" . $this->description . "',
533  '" . $this->createThumbnails . "',
534  '" . $this->thumbnailWidth . "',
535  '" . $this->watermark . "',
536  '" . $this->watermarkEnabled . "',
537  '" . $this->watermarkPosition . "',
538  '" . $this->watermarkImage . "',
539  '" . $this->offsetY . "',
540  '" . $this->offsetX . "',
541  '" . $this->watermarkFont . "',
542  '" . $this->watermarkTextSize . "',
543  '" . $this->watermarkOpacity . "',
544  '" . $this->watermarkColor . "',
545  '" . $this->watermarkBorderColor . "',
546  '" . $this->watermarkBorder . "')")) { // all good
547  // \YAWK\alert::draw("success", "Gallery created.", "Database entry success.", "", 800);
548  } else { // gallery could not be added - notify user
549  \YAWK\alert::draw("danger", "Could not add the new gallery.", "Please check your data and try again.", "", 5800);
550  }
551 
552  // get ID from current added gallery
553  if ($res = $db->query("SELECT id from {plugin_gallery} WHERE folder = '$this->folder'")) { // get last ID from db
554  $row = mysqli_fetch_row($res);
555  $galleryID = $row[0];
556  } else { // if ID cannot be found, use the gallery title as identifier
558  }
559 
560  // ITERATE THROUGH FOLDER
561  // check settings, set them...
562  // and save each file in a db row.
563  $i = 0;
564  foreach (new \DirectoryIterator("../$this->folder") as $fileInfo) {
565  if ($fileInfo->isDot()) continue; // exclude dots
566  if ($fileInfo->isDir()) continue; // exclude subdirectories
567  $i++;
568  // store filename in var for better handling
569  $filename = $fileInfo->getFilename();
570  // MANIPULATE IMAGES IN A ROW
571 
572  // check if a watermark should be set
573  if (!empty($this->watermark) || (!empty($this->watermarkImage))) { // check watermark position
574  if ($this->watermarkPosition === "---") { // default position, if no pos is set
575  $this->watermarkPosition = "bottom right";
576  }
577  // CREATE EDIT FOLDER
578  // images here are stored to keep settings while user is in edit preview
579  if (!is_dir("../$this->folder/edit")) { // if no edit folder is set
580  mkdir("../$this->folder/edit");
581  // copy original files to backup folder
582  // iterate through folder and write backup files
583  foreach (new \DirectoryIterator("../$this->folder") as $backupFile) { // exclude dots'n'dirs
584  if ($fileInfo->isDot()) continue; // exclude dots
585  if ($fileInfo->isDir()) continue; // exclude subdirectories
586  $copyFile = $backupFile->getFilename();
587  if (!@copy("../$this->folder/$copyFile", "../$this->folder/edit/$copyFile")) { // could not copy file, throw notification
588  \YAWK\alert::draw("warning", "Could not copy file $filename to edit folder", "This should not happen. We're sorry!", "", 800);
589  }
590  } // end backup copy original files
591  }
592 
593  // BACKUP
594  // keep non-watermarked files in folder original
595  // check if backup folder exists
596  if (!is_dir("../$this->folder/original")) { // if not, create folder
597  mkdir("../$this->folder/original");
598  // copy original files to backup folder
599  // iterate through folder and write backup files
600  foreach (new \DirectoryIterator("../$this->folder") as $backupFile) { // exclude dots'n'dirs
601  if ($fileInfo->isDot()) continue; // exclude dots
602  if ($fileInfo->isDir()) continue; // exclude subdirectories
603  $copyFile = $backupFile->getFilename();
604  if (!@copy("../$this->folder/$copyFile", "../$this->folder/original/$copyFile")) { // could not copy file, throw notification
605  \YAWK\alert::draw("warning", "Could not backup file $filename", "This should not happen. We're sorry!", "", 800);
606  }
607  } // end backup copy original files
608  }
609  // add watermark with stroke to every image
610  if (!empty($this->watermarkImage)) { // Overlay image watermark
611  $img->fromFile("../$this->folder/$filename")
612  ->overlay("../$this->watermarkImage",
613  "$this->watermarkPosition",
614  $this->watermarkOpacity)
615  ->toFile("../$this->folder/$filename");
616  }
617  if (!empty($this->watermark)) { // text watermark
618  $img->fromFile("../$this->folder/$filename")
619  ->text("$this->watermark",
620  "$this->watermarkFont",
621  $this->watermarkTextSize,
622  "#$this->watermarkColor",
623  "$this->watermarkPosition",
624  "$this->offsetX",
625  "$this->offsetY",
626  "#$this->watermarkBorderColor",
627  $this->watermarkBorder)
628  ->toFile("../$this->folder/$filename");
629  }
630 
631  // check if thumbnails should be created
632  if ($this->createThumbnails === "1") { // check if tn width is set
633  if (empty($this->thumbnailWidth)) { // if no default width is set, take this as default value
634  $this->thumbnailWidth = 200;
635  } else { // remove all but numbers from thumbnail width
636  $this->thumbnailWidth = preg_replace("/[^0-9]/", "", $this->thumbnailWidth);
637  }
638  // check if thumbnail folder exists
639  $this->checkDir("../$this->folder/thumbnails");
640  // add watermark with stroke to every thumbnail image
641  $img->fromFile("../$this->folder/$filename")
642  ->text("$this->watermark",
643  "$this->watermarkFont",
644  $this->watermarkTextSize,
645  "#$this->watermarkColor",
646  "$this->watermarkPosition",
647  "$this->offsetX",
648  "$this->offsetY",
649  "#$this->watermarkBorderColor",
650  $this->watermarkBorder)
651  ->bestFit($this->thumbnailWidth, 600)
652  ->toFile("../$this->folder/thumbnails/$filename");
653  }
654  } else { // no watermark required...
655 
656  // BACKUP
657  // but to keep the usability of the edit function (pixlate, sharpen etc)
658  // we do a backup of original images here too. (in case no watermark is needed)
659  // keep non-watermarked files in folder original
660  // check if backup folder exists
661  if (!is_dir("../$this->folder/original")) { // if not, create folder
662  mkdir("../$this->folder/original");
663  // copy original files to backup folder
664  // iterate through folder and write backup files
665  foreach (new \DirectoryIterator("../$this->folder") as $backupFile) { // exclude dots'n'dirs
666  if ($fileInfo->isDot()) continue; // exclude dots
667  if ($fileInfo->isDir()) continue; // exclude subdirectories
668  $copyFile = $backupFile->getFilename();
669  if (!@copy("../$this->folder/$copyFile", "../$this->folder/original/$copyFile")) { // could not copy file, throw notification
670  \YAWK\alert::draw("warning", "Could not backup file $filename", "This should not happen. We're sorry!", "", 800);
671  }
672  } // end backup copy original files
673  }
674 
675  // CREATE EDIT FOLDER
676  // images here are stored to keep settings while user is in edit preview
677  if (!is_dir("../$this->folder/edit")) { // if no edit folder is set
678  mkdir("../$this->folder/edit");
679  // copy original files to backup folder
680  // iterate through folder and write backup files
681  foreach (new \DirectoryIterator("../$this->folder") as $backupFile) { // exclude dots'n'dirs
682  if ($fileInfo->isDot()) continue; // exclude dots
683  if ($fileInfo->isDir()) continue; // exclude subdirectories
684  $copyFile = $backupFile->getFilename();
685  if (!@copy("../$this->folder/$copyFile", "../$this->folder/edit/$copyFile")) { // could not copy file, throw notification
686  \YAWK\alert::draw("warning", "Could not copy file $filename to edit folder", "This should not happen. We're sorry!", "", 800);
687  }
688  } // end backup copy original files
689  }
690 
691  // check if thumbnails should be created
692  if ($this->createThumbnails === "1") { // check if tn width is set
693  if (empty($this->thumbnailWidth)) { // if no default width is set, take this as default value
694  $this->thumbnailWidth = 200;
695  }
696  // check if thumbnail folder exits
697  $this->checkDir("../$this->folder/thumbnails");
698  // fit to width
699  $img->fromFile("../$this->folder/$filename")
700  ->bestFit($this->thumbnailWidth, 600)
701  ->toFile("../$this->folder/thumbnails/$filename");
702  }
703  }
704 
705  // TODO: this needs to be improved:
706  // TODO: 1 db insert per file is NOT! ok - but how to implement implode() correctly to avoid that memory lack?
707  if ($res = $db->query("INSERT INTO {plugin_gallery_items} (galleryID, sort, filename, title, author, authorUrl)
708  VALUES ('" . $galleryID . "', '" . $i . "', '" . $filename . "', '" . $this->title . "', '" . $this->author . "', '" . $this->authorUrl . "')")) { // all good
709  // \YAWK\alert::draw("success", "Gallery created.", "Database entry success.", "", 800);
710  } else { // error inserting data, throw notification
711  \YAWK\alert::draw("warning", "Could not insert $filename", "Database error. Please check folder and try again.", "", 1200);
712  }
713  }
714  return true;
715  }
716 
717  /**
718  * @brief load gallery settings into object properties
719  * @param object $db database
720  * @param int $galleryID
721  */
722  public function loadProperties($db, $galleryID)
723  {
724  /** @var $db \YAWK\db * */
725  // load all gallery properties
726  if ($res = $db->query("SELECT * from {plugin_gallery} where id = $galleryID")) {
727  while ($row = mysqli_fetch_assoc($res)) {
728  $this->id = $galleryID;
729  $this->folder = $row['folder'];
730  $this->title = $row['title'];
731  $this->description = $row['description'];
732  $this->author = $row['author'];
733  $this->authorUrl = $row['authorUrl'];
734  $this->createThumbnails = $row['createThumbnails'];
735  $this->imageWidth = $row['imageWidth'];
736  $this->imageHeight = $row['imageHeight'];
737  $this->resizeImages = $row['resizeImages'];
738  $this->resizeType = $row['resizeType'];
739  $this->thumbnailWidth = $row['thumbnailWidth'];
740  $this->watermark = $row['watermark'];
741  $this->watermarkEnabled = $row['watermarkEnabled'];
742  $this->watermarkPosition = $row['watermarkPosition'];
743  $this->watermarkImage = $row['watermarkImage'];
744  $this->offsetY = $row['offsetY'];
745  $this->offsetX = $row['offsetX'];
746  $this->watermarkFont = $row['watermarkFont'];
747  $this->watermarkTextSize = $row['watermarkTextSize'];
748  $this->watermarkOpacity = $row['watermarkOpacity'];
749  $this->watermarkColor = $row['watermarkColor'];
750  $this->watermarkBorderColor = $row['watermarkBorderColor'];
751  $this->watermarkBorder = $row['watermarkBorder'];
752  }
753  }
754  }
755 
756  /**
757  * @brief edit (update) a gallery
758  * @param object $db database
759  * @param int $galleryID gallery ID to edit
760  * @return bool
761  * @throws \Exception
762  */
763  public function edit($db, $galleryID)
764  {
765  /** @var $db \YAWK\db * */
766 
767  // quote all POST vars
768  $this->id = $galleryID;
769  $this->folder = $db->quote($_POST['folder']);
770  $this->title = $db->quote($_POST['title']);
771  $this->description = $db->quote($_POST['description']);
772  $this->author = $db->quote($_POST['author']);
773  $this->authorUrl = $db->quote($_POST['authorUrl']);
774  $this->createThumbnails = $db->quote($_POST['createThumbnails']);
775  $this->imageWidth = $db->quote($_POST['imageWidth']);
776  $this->imageHeight = $db->quote($_POST['imageHeight']);
777  $this->imageHeight = $db->quote($_POST['imageHeight']);
778  $this->resizeImages = $db->quote($_POST['resizeImages']);
779  $this->resizeType = $db->quote($_POST['resizeType']);
780  $this->thumbnailWidth = $db->quote($_POST['thumbnailWidth']);
781  $this->watermark = $db->quote($_POST['watermark']);
782  $this->watermarkEnabled = $db->quote($_POST['watermarkEnabled']);
783  $this->watermarkPosition = $db->quote($_POST['watermarkPosition']);
784  $this->watermarkImage = $db->quote($_POST['watermarkImage']);
785  $this->offsetY = $db->quote($_POST['offsetY']);
786  $this->offsetX = $db->quote($_POST['offsetX']);
787  $this->watermarkFont = $db->quote($_POST['watermarkFont']);
788  $this->watermarkTextSize = $db->quote($_POST['watermarkTextSize']);
789  $this->watermarkOpacity = $db->quote($_POST['watermarkOpacity']);
790  $this->watermarkColor = $db->quote($_POST['watermarkColor']);
791  $this->watermarkBorderColor = $db->quote($_POST['watermarkBorderColor']);
792  $this->watermarkBorder = $db->quote($_POST['watermarkBorder']);
793 
794  // check if count is set to calculate estimating time for the fancy user notification
795  if (isset($_GET['imageCount']) && (is_numeric($_GET['imageCount']))) { // prepare and calculate
796  $i = $_GET['imageCount']; // the number of images
797  $processingDurationPerImage = 200; // estimated processing time per item in ms
798  $notifyDuration = $i * $processingDurationPerImage; // time that the notify box will be shown
799  $notifyDurationShort = $notifyDuration / 2;
800  } else { // count images to calculate notify box
801  $i = $this->countEntries($db, $this->id);
802  $processingDurationPerImage = 200; // estimated processing time per item in ms
803  $notifyDuration = $i * $processingDurationPerImage; // time that the notify box will be shown
804  $notifyDurationShort = $notifyDuration / 2;
805  }
806 
807  $oldThumbnailWidth = $_POST['thumbnailWidth-old'];
808  if ($oldThumbnailWidth !== $this->thumbnailWidth) { // "saving thumbnails" message
809  \YAWK\alert::draw("success", "Saving new thumbnails. . .", "<div class=\"text-center\"><i class=\"fa fa-spinner fa-spin\" style=\"font-size:24px\"></i><br>Please be patient, this should only take a few seconds.</div>", "", $notifyDuration);
810  }
811  if ($this->resizeImages === "1") {
812  { // "changing image size" message
813  \YAWK\alert::draw("success", "Resizing your images. . .", "<div class=\"text-center\"><i class=\"fa fa-spinner fa-spin\" style=\"font-size:24px\"></i><br>Please be patient, this should only take a few seconds.</div>", "", $notifyDuration);
814  }
815  } else {
816  \YAWK\alert::draw("success", "Settings saved.", "Gallery updated.", "", $notifyDurationShort);
817  }
818 
819  // check, if any itemIDs need to be updated, get get them and loop through items...
820  if ($res = $db->query("SELECT id from {plugin_gallery_items}
821  WHERE galleryID = $this->id")) { // foreach itemID
822  while ($row = mysqli_fetch_assoc($res)) { // set itemID
823  $this->itemID = $row['id'];
824  // set vars to compare if they have changed...
825  // filename
826  $oldFile = $_POST['filename-' . $this->itemID . '-old'];
827  $newFile = $_POST['filename-' . $this->itemID . ''];
828  // title
829  $oldTitle = $_POST['title-' . $this->itemID . '-old'];
830  $newTitle = $_POST['title-' . $this->itemID . ''];
831  // author
832  $oldAuthor = $_POST['author-' . $this->itemID . '-old'];
833  $newAuthor = $_POST['author-' . $this->itemID . ''];
834  // authorUrl
835  $oldAuthorUrl = $_POST['authorUrl-' . $this->itemID . '-old'];
836  $newAuthorUrl = $_POST['authorUrl-' . $this->itemID . ''];
837 
838  // item sortation
839  $oldSort = $_POST['sort-' . $this->itemID . '-old'];
840  $newSort = $_POST['sort-' . $this->itemID . ''];
841  if ($oldSort !== $newSort) {
842  if (!$db->query("UPDATE {plugin_gallery_items}
843  SET sort = '$newSort'
844  WHERE id = $this->itemID")) { // could not rename file in database, notify user
845  \YAWK\alert::draw("warning", "Could not save new filename $newFile in database!", "But... the file is already renamed. Expect errors.", "", 5800);
846  }
847  }
848 
849  // ## CHECK IF IMAGE FILENAME HAS CHANGED...
850  if ($oldFile === $newFile) { // files MATCH, no rename required: save ressources + do nothing :)
851  // \YAWK\alert::draw("warning", "files match!", "no rename required.", "", 800);
852  } else { // files DO NOT match - RENAME file
853  if (rename("../$this->folder/$oldFile", "../$this->folder/$newFile")) { // filename did change - notify user about that
854  \YAWK\alert::draw("success", "$oldFile renamed to $newFile", "$this->itemID", "", 800);
855  // update database: save new file name
856  if (!$saveItem = $db->query("UPDATE {plugin_gallery_items}
857  SET filename = '$newFile'
858  WHERE id = $this->itemID")) { // could not rename file in database, notify user
859  \YAWK\alert::draw("warning", "Could not save new filename $newFile in database!", "But... the file is already renamed. Expect errors.", "", 5800);
860  }
861 
862  // check if there are any originals to rename...
863  if (is_dir("../$this->folder/original/")) { // thumbnail directory exist
864  if (!rename("../$this->folder/original/$oldFile", "../$this->folder/original/$newFile")) { // rename thumbnail failed, throw error
865  \YAWK\alert::draw("warning", "Could not rename original/$oldFile to $newFile", "Please check folder permissions!", "", 5800);
866  }
867  }
868 
869  // check if there are any originals to rename...
870  if (is_dir("../$this->folder/edit/")) { // thumbnail directory exist
871  if (!rename("../$this->folder/edit/$oldFile", "../$this->folder/edit/$newFile")) { // rename thumbnail failed, throw error
872  \YAWK\alert::draw("warning", "Could not rename edit/$oldFile to $newFile", "Please check folder permissions!", "", 5800);
873  }
874  }
875 
876  // check if there are thumbnails to rename...
877  if (is_dir("../$this->folder/thumbnails/")) { // thumbnail directory exist
878  if (!rename("../$this->folder/thumbnails/$oldFile", "../$this->folder/thumbnails/$newFile")) { // rename thumbnail failed, throw error
879  \YAWK\alert::draw("warning", "Could not rename thumbnails/$oldFile to $newFile", "Please check folder permissions!", "", 5800);
880  }
881  }
882  } else { // rename failed
883  \YAWK\alert::draw("danger", "Could not rename $oldFile to $newFile", "Please check folder permissions!", "", 5800);
884  }
885  }
886  // ## CHECK IF IMAGE TITLE HAS CHANGED...
887  if ($oldTitle === $newTitle) {
888  // files MATCH, no action required: save ressources + do nothing :)
889  } else { // change title for this image in database
890  if (!$saveItem = $db->query("UPDATE {plugin_gallery_items}
891  SET title = '$newTitle'
892  WHERE id = $this->itemID")) { // could not change title in db => notify user
893  \YAWK\alert::draw("warning", "Could not change title $newTitle", "Please check your data and try again!", "", 5800);
894  } else { // change title success
895  \YAWK\alert::draw("success", "Changed $oldTitle to $newTitle", "affected image ID: $this->itemID", "", 800);
896  }
897  }
898  // ## CHECK IF IMAGE AUTHOR HAS CHANGED...
899  if ($oldAuthor === $newAuthor) {
900  // authors MATCH, no action required: save ressources + do nothing :)
901  } else { // change author for this image in database
902  if (!$saveItem = $db->query("UPDATE {plugin_gallery_items}
903  SET author = '$newAuthor'
904  WHERE id = $this->itemID")) { // could not change author => notify user
905  \YAWK\alert::draw("warning", "Could not change author $newAuthor", "Please check your data and try again!", "", 5800);
906  } else { // change title success
907  \YAWK\alert::draw("success", "Changed $oldAuthor to $newAuthor", "affected image ID: $this->itemID", "", 800);
908  }
909  }
910  // ## CHECK IF IMAGE AUTHOR URL HAS CHANGED...
911  if ($oldAuthorUrl === $newAuthorUrl) {
912  // authors MATCH, no action required: save ressources + do nothing :)
913  } else { // change authorUrl for this image in database
914  if (!$saveItem = $db->query("UPDATE {plugin_gallery_items}
915  SET authorUrl = '$newAuthorUrl'
916  WHERE id = $this->itemID")) { // could not change author => notify user
917  \YAWK\alert::draw("warning", "Could not change author URL to $newAuthorUrl", "Please check your data and try again!", "", 5800);
918  } else { // change title success
919  \YAWK\alert::draw("success", "Changed Author URL to $newAuthorUrl", "affected image ID: $this->itemID", "", 800);
920  }
921  }
922  }
923 
924  // load SimpleImage Class
925  require_once 'SimpleImage.php';
926  // create object
927  $img = new \YAWK\SimpleImage();
928 
929  if (empty($this->watermark) || ($this->watermarkEnabled === "0")) {
930  // watermark not changed, no action required: save ressources + do nothing :)
931  // check if thumbnails should be created
932  if ($this->createThumbnails === "1") { // check if tn width is set
933  if (empty($this->thumbnailWidth)) { // if no default width is set, take this as default value
934  $this->thumbnailWidth = 200;
935  }
936  // walk through images folder
937  foreach (new \DirectoryIterator("../$this->folder/edit/") as $image) { // exclude dots'n'dirs
938  if ($image->isDot()) continue; // exclude dots
939  if ($image->isDir()) continue; // exclude subdirectories
940  // store filename in var for better handling
941  $filename = $image->getFilename();
942  $img->fromFile("../$this->folder/edit/$filename")
943  ->toFile("../$this->folder/$filename")
944  ->bestFit($this->thumbnailWidth, 600)
945  ->toFile("../$this->folder/thumbnails/$filename");
946  }
947  } else { // no thumbnails required, just change watermark to root folder images
948  // walk through images folder
949  foreach (new \DirectoryIterator("../$this->folder/edit/") as $image) { // exclude dots'n'dirs
950  if ($image->isDot()) continue; // exclude dots
951  if ($image->isDir()) continue; // exclude subdirectories
952  // store filename in var for better handling
953  $filename = $image->getFilename();
954  $img->fromFile("../$this->folder/edit/$filename")
955  ->toFile("../$this->folder/$filename");
956  }
957  }
958 
959  } else { // save new watermark onto files
960  // check if thumbnails should be created
961  if ($this->createThumbnails === "1") { // check if tn width is set
962  if (empty($this->thumbnailWidth)) { // if no default width is set, take this as default value
963  $this->thumbnailWidth = 200;
964  }
965  // walk through images folder
966  foreach (new \DirectoryIterator("../$this->folder/edit/") as $image) { // exclude dots'n'dirs
967  if ($image->isDot()) continue; // exclude dots
968  if ($image->isDir()) continue; // exclude subdirectories
969  // store filename in var for better handling
970  $filename = $image->getFilename();
971  $img->fromFile("../$this->folder/edit/$filename")
972  ->text("$this->watermark",
973  "$this->watermarkFont",
974  $this->watermarkTextSize,
975  "#$this->watermarkColor",
976  "$this->watermarkPosition",
977  "$this->offsetX",
978  "$this->offsetY",
979  "#$this->watermarkBorderColor",
980  $this->watermarkBorder)
981  ->toFile("../$this->folder/$filename")
982  ->bestFit($this->thumbnailWidth, 600)
983  ->toFile("../$this->folder/thumbnails/$filename");
984  }
985  } else { // no thumbnails required, just change watermark to root folder images
986  // walk through images folder
987  foreach (new \DirectoryIterator("../$this->folder/edit/") as $image) { // exclude dots'n'dirs
988  if ($image->isDot()) continue; // exclude dots
989  if ($image->isDir()) continue; // exclude subdirectories
990  // store filename in var for better handling
991  $filename = $image->getFilename();
992  $img->fromFile("../$this->folder/edit/$filename")
993  ->text("$this->watermark",
994  "$this->watermarkFont",
995  $this->watermarkTextSize,
996  "#$this->watermarkColor",
997  "$this->watermarkPosition",
998  "$this->offsetX",
999  "$this->offsetY",
1000  "#$this->watermarkBorderColor",
1001  $this->watermarkBorder)
1002  ->toFile("../$this->folder/$filename");
1003  }
1004  }
1005  }
1006  // ## CHECK IF WATERMARK HAS CHANGED...
1007  if (empty($this->watermarkImage)) {
1008  // watermark not changed, no action required: save ressources + do nothing :)
1009 
1010  } else { // walk through images folder
1011  foreach (new \DirectoryIterator("../$this->folder/edit/") as $image) { // exclude dots'n'dirs
1012  if ($image->isDot()) continue; // exclude dots
1013  if ($image->isDir()) continue; // exclude subdirectories
1014  // store filename in var for better handling
1015  $filename = $image->getFilename();
1016 
1017  // check if thumbnails should be created
1018  if ($this->createThumbnails === "1") { // check if tn width is set
1019  if (empty($this->thumbnailWidth)) { // if no default width is set, take this as default value
1020  $this->thumbnailWidth = 200;
1021  }
1022  // add watermark with stroke to every image + save as thumbnail
1023  $img->fromFile("../$this->folder/edit/$filename")
1024  ->overlay("../$this->watermarkImage",
1025  "$this->watermarkPosition",
1026  $this->watermarkOpacity)
1027  ->toFile("../$this->folder/$filename")
1028  ->bestFit($this->thumbnailWidth, 600)
1029  ->toFile("../$this->folder/thumbnails/$filename");
1030  } else {
1031  // add watermark with stroke to every image
1032  $img->fromFile("../$this->folder/edit/$filename")
1033  ->overlay("../$this->watermarkImage",
1034  "$this->watermarkPosition",
1035  $this->watermarkOpacity)
1036  ->toFile("../$this->folder/$filename");
1037  }
1038  }
1039  }
1040 
1041  // ## CHECK IF THUMBNAILS SHOULD BE CHANGED...
1042  if ($oldThumbnailWidth === $this->thumbnailWidth) {
1043  // thumbnail size not changed, no action required: save ressources + do nothing :)
1044  } else { // save thumbnails new...
1045  // check if thumbnails should be created
1046  if ($this->createThumbnails === "1") { // check if tn width is set
1047  if (empty($this->thumbnailWidth)) { // if no default width is set, take this as default value
1048  $this->thumbnailWidth = 200;
1049  }
1050  // include SimpleImage Class
1051  require_once 'SimpleImage.php';
1052  // create object
1053  $img = new \YAWK\SimpleImage();
1054 
1055  // walk through images folder
1056  foreach (new \DirectoryIterator("../$this->folder") as $image) { // exclude dots'n'dirs
1057  if ($image->isDot()) continue; // exclude dots
1058  if ($image->isDir()) continue; // exclude subdirectories
1059  // store filename in var for better handling
1060  $filename = $image->getFilename();
1061  $img->fromFile("../$this->folder/$filename")
1062  ->bestFit($this->thumbnailWidth, 600)
1063  ->toFile("../$this->folder/thumbnails/$filename");
1064  }
1065  }
1066  }
1067 
1068  // SHOULD IMAGES BE RESIZED?
1069  // ## CHECK IF IMAGES SHOULD BE RESIZED...
1070  if ($this->resizeImages === "1") {
1071  $this->imageWidth = preg_replace('![^0-9]!', '', $this->imageWidth);
1072  $this->imageHeight = preg_replace('![^0-9]!', '', $this->imageHeight);
1073 
1074  // if width is empty, try to take height
1075  if (!isset($this->imageWidth) || (empty($this->imageWidth))) {
1076  $this->imageWidth = $this->imageHeight;
1077  }
1078  // if height is empty, try to take width
1079  if (!isset($this->imageHeight) || (empty($this->imageHeight))) {
1080  $this->imageHeight = $this->imageWidth;
1081  }
1082  // if both values are empty...
1083  if (empty($this->imageWidth) && (empty($this->imageHeight))) { // set default value
1084  $this->imageWidth = 300;
1085  $this->imageHeight = 300;
1086  }
1087 
1088  if ($this->resizeType === "fit_to_width") {
1089  // walk through images folder
1090  foreach (new \DirectoryIterator("../$this->folder") as $image) { // exclude dots'n'dirs
1091  if ($image->isDot()) continue; // exclude dots
1092  if ($image->isDir()) continue; // exclude subdirectories
1093  // store filename in var for better handling
1094  $filename = $image->getFilename();
1095  $img->fromFile("../$this->folder/$filename")
1096  ->bestFit($this->imageWidth, 600)
1097  ->toFile("../$this->folder/$filename");
1098  }
1099  }
1100  if ($this->resizeType === "fit_to_height") {
1101  // walk through images folder
1102  foreach (new \DirectoryIterator("../$this->folder") as $image) { // exclude dots'n'dirs
1103  if ($image->isDot()) continue; // exclude dots
1104  if ($image->isDir()) continue; // exclude subdirectories
1105  // store filename in var for better handling
1106  $filename = $image->getFilename();
1107  $img->fromFile("../$this->folder/$filename")
1108  ->bestFit($this->imageWidth, 600)
1109  ->toFile("../$this->folder/$filename");
1110  }
1111  }
1112  if ($this->resizeType === "best_fit") {
1113  // walk through images folder
1114  foreach (new \DirectoryIterator("../$this->folder") as $image) { // exclude dots'n'dirs
1115  if ($image->isDot()) continue; // exclude dots
1116  if ($image->isDir()) continue; // exclude subdirectories
1117  // store filename in var for better handling
1118  $filename = $image->getFilename();
1119  $img->fromFile("../$this->folder/$filename")
1120  ->bestFit($this->imageWidth, $this->imageHeight)
1121  ->toFile("../$this->folder/$filename");
1122  }
1123  }
1124  if ($this->resizeType === "resize") {
1125  // walk through images folder
1126  foreach (new \DirectoryIterator("../$this->folder") as $image) { // exclude dots'n'dirs
1127  if ($image->isDot()) continue; // exclude dots
1128  if ($image->isDir()) continue; // exclude subdirectories
1129  // store filename in var for better handling
1130  $filename = $image->getFilename();
1131  $img->fromFile("../$this->folder/$filename")
1132  ->resize($this->imageWidth, $this->imageHeight)
1133  ->toFile("../$this->folder/$filename");
1134  }
1135  }
1136  if ($this->resizeType === "thumbnail") {
1137  // walk through images folder
1138  foreach (new \DirectoryIterator("../$this->folder") as $image) { // exclude dots'n'dirs
1139  if ($image->isDot()) continue; // exclude dots
1140  if ($image->isDir()) continue; // exclude subdirectories
1141  // store filename in var for better handling
1142  $filename = $image->getFilename();
1143  $img->fromFile("../$this->folder/$filename")
1144  ->thumbnail($this->imageWidth, $this->imageHeight, 'top')
1145  ->toFile("../$this->folder/$filename");
1146  }
1147  }
1148  }
1149  }
1150 
1151  // update database: gallery settings
1152  if (!$res = $db->query("UPDATE {plugin_gallery}
1153  SET folder='$this->folder',
1154  title='$this->title',
1155  description='$this->description',
1156  author='$this->author',
1157  authorUrl='$this->authorUrl',
1158  createThumbnails='$this->createThumbnails',
1159  thumbnailWidth='$this->thumbnailWidth',
1160  imageWidth='$this->imageWidth',
1161  imageHeight='$this->imageHeight',
1162  resizeImages='$this->resizeImages',
1163  resizeType='$this->resizeType',
1164  watermark='$this->watermark',
1165  watermarkPosition='$this->watermarkPosition',
1166  watermarkImage='$this->watermarkImage',
1167  offsetY='$this->offsetY',
1168  offsetX='$this->offsetX',
1169  watermarkFont='$this->watermarkFont',
1170  watermarkTextSize='$this->watermarkTextSize',
1171  watermarkOpacity='$this->watermarkOpacity',
1172  watermarkColor='$this->watermarkColor',
1173  watermarkBorderColor='$this->watermarkBorderColor',
1174  watermarkBorder='$this->watermarkBorder' WHERE id = '$this->id'")) { // update gallery not worked, notify user
1175  \YAWK\alert::draw("warning", "Could not save gallery settings.", "Please check your input data and try again.", "", 5800);
1176  } else { // all good,
1177  return true;
1178  }
1179  // something above did not worked,
1180  return false;
1181  }
1182 
1183  /**
1184  * @brief count and return the number of gallery entries
1185  * @param object $db database
1186  * @param int $galleryID gallery ID to count
1187  * @return int|bool number of entries or false
1188  */
1189  public function countEntries($db, $galleryID)
1190  {
1191  /** @var $db \YAWK\db * */
1192  // count gallery item entries
1193  $i = 0; // init entries counter
1194  if ($res = $db->query("SELECT id from {plugin_gallery_items} WHERE galleryID = '$galleryID'")) { // loop
1195  while ($row = mysqli_fetch_assoc($res)) { // add counter
1196  $i++;
1197  }
1198  } else { // could not get data from db
1199  return false;
1200  }
1201  return $i;
1202  }
1203 
1204  /**
1205  * @brief get and draw (output) html gallery preview
1206  * @param object $db database
1207  * @param array $lang language array
1208  * @return null echo html output
1209  */
1210  public function getPreview($db, $lang)
1211  {
1212  /** @var $db \YAWK\db * */
1213  // get gallery titles...
1214 
1215  if ($res = $db->query("SELECT * from {plugin_gallery}")) {
1216  while ($row = mysqli_fetch_assoc($res)) {
1217  if (!$getPreviewImages = $db->query("SELECT galleryID, filename from {plugin_gallery_items} WHERE galleryID = '$row[id]' ORDER by sort, filename DESC LIMIT 5")) { // store info msg, if files could not be retrieved
1218  $previewError = "Sorry, no preview available.";
1219  }
1220  $imageCount = $this->countEntries($db, $row['id']);
1221  // preview without images
1222  echo "<div class=\"row\"><div class=\"col-md-4\"><a class=\"fa fa-trash-o\" role=\"dialog\" data-confirm=\"Soll die Galerie &laquo;" . $row['id'] . " / " . $row['title'] . "&raquo; wirklich gel&ouml;scht werden?\"
1223  title=\"" . $lang['DEL'] . "\" href=\"index.php?plugin=gallery&delete=1&id=" . $row['id'] . "\"></a>
1224  <!-- &nbsp;<a href=\"index.php?plugin=gallery&refresh=1&id=$row[id]&folder=$row[folder]\" title=\"refresh\"><i class=\"fa fa-refresh\"></i></a> -->
1225  &nbsp;<a href=\"index.php?plugin=gallery&pluginpage=edit&id=$row[id]&folder=$row[folder]&imageCount=$imageCount\" title=\"edit\"><i class=\"fa fa-edit\"></i>
1226  &nbsp;<b>" . $row['title'] . "</b></a><br><small><strong>$imageCount Images</strong><br> " . $row['description'] . "</small></div>
1227  <div class=\"col-md-8\">";
1228  if (isset($previewError)) { // if files could not be loaded from db
1229  echo $previewError;
1230  } else { // previewImage array is set, walk through it...
1231  foreach ($getPreviewImages as $property => $image) { // display preview images
1232  $rnd = uniqid();
1233  echo "<a href=\"index.php?plugin=gallery&pluginpage=edit&id=$row[id]&folder=$row[folder]&imageCount=$imageCount\" title=\"edit gallery\">
1234  <img src=\"../$row[folder]/$image[filename]?$rnd\" class=\"img-thumbnail\" width=\"100\"></a>";
1235  }
1236  }
1237  echo "</div></div>
1238  <hr>";
1239  }
1240  }
1241  return null;
1242  }
1243 
1244  /**
1245  * @brief @param object $db database
1246  * @param array $lang language array
1247  * @param int $galleryID gallery ID to load
1248  */
1249  public function drawImageGallery($db, $galleryID)
1250  {
1251  /** @var $db \YAWK\db * */
1252  if ($res = $db->query("SELECT * from {plugin_gallery} WHERE id = $galleryID")) {
1253  while ($row = mysqli_fetch_assoc($res)) {
1254  if (!$getPreviewImages = $db->query("SELECT id, galleryID, sort, filename, title, author, authorUrl
1255  from {plugin_gallery_items}
1256  WHERE galleryID = $galleryID ORDER BY sort, filename DESC")) { // store info msg, if files could not be retrieved
1257  $previewError = "Sorry, could not get preview images";
1258  }
1259  if (isset($previewError)) { // if files could not be loaded from db
1260  echo $previewError;
1261  } else { // previewImage array is set, walk through it...
1262  $count = 3;
1263  echo '
1264  <div class="row">
1265  ';
1266  foreach ($getPreviewImages as $property => $image) { // display preview images
1267  for ($i = 0; $i < count($property); $i++) {
1268  $this->itemID = $image['id'];
1269  $this->sort = $image['sort'];
1270  $this->filename = $image['filename'];
1271  $this->itemTitle = $image['title'];
1272  $this->itemAuthor = $image['author'];
1273  $this->itemAuthorUrl = $image['authorUrl'];
1274  // $rnd = uniqid();
1275 
1276  if ($count % 3 == 0) { // time to break line
1277  echo '
1278  </div>';
1279  echo '
1280  <div class="row">
1281  <div class="col-md-4 animate text-center" id="imgCol-' . $this->itemID . '">
1282  <a href="' . $row['folder'] . "/" . $this->filename . '" data-lightbox="' . $galleryID . '" data-title="' . $this->itemTitle . '"><img class="img-responsive img-rounded hvr-grow" id="img-' . $this->itemID . '" width="400" alt="' . $this->itemTitle . '" title="' . $this->itemTitle . '" src="' . $row['folder'] . "/" . $this->filename . '"></a><br><br>
1283  </div>';
1284  } else {
1285  echo '
1286  <div class="col-md-4 animate text-center" id="imgCol-' . $this->itemID . '">
1287  <a href="' . $row['folder'] . "/" . $this->filename . '" data-lightbox="' . $galleryID . '" data-title="' . $this->itemTitle . '"><img class="img-responsive img-rounded hvr-grow"' . $this->itemTitle . '" id="img-' . $this->itemID . '" width="400" title="' . $this->itemTitle . '" src="' . $row['folder'] . "/" . $this->filename . '"></a><br><br>
1288  </div>';
1289  }
1290  $count++;
1291  }
1292  }
1293  }
1294  echo "</div>";
1295  }
1296  }
1297  }
1298 
1299 
1300  /**
1301  * @brief get and draw all editable images + edit controls
1302  * @param object $db database
1303  * @param array $lang language array
1304  * @param int $galleryID affected gallery ID
1305  * @return null echo html output
1306  */
1307  public function getEditableImages($db, $lang, $galleryID)
1308  {
1309  /** @var $db \YAWK\db * */
1310  // get gallery titles...
1311 
1312  if ($res = $db->query("SELECT * from {plugin_gallery} WHERE id = $galleryID")) {
1313  while ($row = mysqli_fetch_assoc($res)) {
1314  if (!$getPreviewImages = $db->query("SELECT id, galleryID, sort, filename, title, author, authorUrl
1315  from {plugin_gallery_items}
1316  WHERE galleryID = $galleryID ORDER BY sort, filename DESC")) { // store info msg, if files could not be retrieved
1317  $previewError = "Sorry, could not get preview images";
1318  }
1319  if (!isset($_GET['imageCount']) && (!empty($_GET['imageCount']))) {
1320  $imageCount = $_GET['imageCount'];
1321  } else {
1322  $imageCount = '';
1323  }
1324  // preview without images
1325  echo "<a class=\"fa fa-trash-o\" role=\"dialog\" data-confirm=\"Soll die Galerie &laquo;" . $row['id'] . " / " . $row['title'] . "&raquo; wirklich gel&ouml;scht werden?\"
1326  title=\"" . $lang['DEL'] . "\" href=\"index.php?plugin=gallery&delete=1&id=" . $row['id'] . "\"></a>
1327  &nbsp;<a href=\"index.php?plugin=gallery&pluginpage=edit&refresh=1&id=$row[id]&folder=$row[folder]&imageCount=" . $imageCount . "\" title=\"refresh\"><i class=\"fa fa-refresh\"></i></a>
1328  &nbsp;<b>" . $row['title'] . "</b><br><small>" . $row['description'] . "</small><br>
1329  <div class=\"text-center\">";
1330  if (isset($previewError)) { // if files could not be loaded from db
1331  echo $previewError;
1332  } else { // previewImage array is set, walk through it...
1333  $count = 3;
1334  echo '
1335  <div class="row">
1336  ';
1337  foreach ($getPreviewImages as $property => $image) {
1338  { // display preview images
1339  for ($i = 0; $i < mb_strlen($property); $i++) {
1340  $this->itemID = $image['id'];
1341  $this->sort = $image['sort'];
1342  $this->filename = $image['filename'];
1343  $this->itemTitle = $image['title'];
1344  $this->itemAuthor = $image['author'];
1345  $this->itemAuthorUrl = $image['authorUrl'];
1346  $rnd = uniqid();
1347 
1348  if ($count % 3 == 0) { // time to break line
1349  echo '
1350  </div>';
1351  echo '
1352  <div class="row"><div class="col-md-4" id="imgCol-' . $this->itemID . '">
1353  <a href="../' . $row['folder'] . "/" . $this->filename . '?' . $rnd . '" data-lightbox="' . $this->id . '"><img class="img-thumbnail" id="img-' . $this->itemID . '" width="400" title="' . $this->itemTitle . '" src="../' . $row['folder'] . "/" . $this->filename . '?' . $rnd . '"></a>
1354  <br>
1355  <div style="margin-top: 10px; margin-bottom:10px; cursor:pointer;" id="toolset-' . $this->itemID . '">
1356  <i class="fa fa-arrows-h"
1357  id="flipHorizontal"
1358  onclick="doImageAction(\'flip-horizontal\',
1359  \'' . $this->id . '\',
1360  \'' . $this->folder . '\',
1361  \'' . $this->filename . '\',
1362  \'' . $this->itemID . '\',
1363  \'' . $this->createThumbnails . '\',
1364  \'' . $this->thumbnailWidth . '\',
1365  \'' . $this->watermark . '\',
1366  \'' . $this->watermarkImage . '\',
1367  \'' . $this->watermarkOpacity . '\',
1368  \'' . $this->watermarkPosition . '\',
1369  \'' . $this->offsetX . '\',
1370  \'' . $this->offsetY . '\',
1371  \'' . $this->watermarkFont . '\',
1372  \'' . $this->watermarkTextSize . '\',
1373  \'' . $this->watermarkColor . '\',
1374  \'' . $this->watermarkBorderColor . '\',
1375  \'' . $this->watermarkBorder . '\'
1376  )"></i>&nbsp;
1377  <i class="fa fa-arrows-v"
1378  id="flipVertical"
1379  onclick="doImageAction(\'flip-vertical\',
1380  \'' . $this->id . '\',
1381  \'' . $this->folder . '\',
1382  \'' . $this->filename . '\',
1383  \'' . $this->itemID . '\',
1384  \'' . $this->createThumbnails . '\',
1385  \'' . $this->thumbnailWidth . '\',
1386  \'' . $this->watermark . '\',
1387  \'' . $this->watermarkImage . '\',
1388  \'' . $this->watermarkOpacity . '\',
1389  \'' . $this->watermarkPosition . '\',
1390  \'' . $this->offsetX . '\',
1391  \'' . $this->offsetY . '\',
1392  \'' . $this->watermarkFont . '\',
1393  \'' . $this->watermarkTextSize . '\',
1394  \'' . $this->watermarkColor . '\',
1395  \'' . $this->watermarkBorderColor . '\',
1396  \'' . $this->watermarkBorder . '\'
1397  )"></i>&nbsp;
1398  <i class="fa fa-undo"
1399  id="rotate-90"
1400  onclick="doImageAction(\'rotate-90\',
1401  \'' . $this->id . '\',
1402  \'' . $this->folder . '\',
1403  \'' . $this->filename . '\',
1404  \'' . $this->itemID . '\',
1405  \'' . $this->createThumbnails . '\',
1406  \'' . $this->thumbnailWidth . '\',
1407  \'' . $this->watermark . '\',
1408  \'' . $this->watermarkImage . '\',
1409  \'' . $this->watermarkOpacity . '\',
1410  \'' . $this->watermarkPosition . '\',
1411  \'' . $this->offsetX . '\',
1412  \'' . $this->offsetY . '\',
1413  \'' . $this->watermarkFont . '\',
1414  \'' . $this->watermarkTextSize . '\',
1415  \'' . $this->watermarkColor . '\',
1416  \'' . $this->watermarkBorderColor . '\',
1417  \'' . $this->watermarkBorder . '\'
1418  )"></i>&nbsp;
1419  <i class="fa fa-adjust"
1420  id="contrast-plus"
1421  onclick="doImageAction(\'contrast-plus\',
1422  \'' . $this->id . '\',
1423  \'' . $this->folder . '\',
1424  \'' . $this->filename . '\',
1425  \'' . $this->itemID . '\',
1426  \'' . $this->createThumbnails . '\',
1427  \'' . $this->thumbnailWidth . '\',
1428  \'' . $this->watermark . '\',
1429  \'' . $this->watermarkImage . '\',
1430  \'' . $this->watermarkOpacity . '\',
1431  \'' . $this->watermarkPosition . '\',
1432  \'' . $this->offsetX . '\',
1433  \'' . $this->offsetY . '\',
1434  \'' . $this->watermarkFont . '\',
1435  \'' . $this->watermarkTextSize . '\',
1436  \'' . $this->watermarkColor . '\',
1437  \'' . $this->watermarkBorderColor . '\',
1438  \'' . $this->watermarkBorder . '\'
1439  )"></i>&nbsp;
1440  <i class="fa fa-adjust text-muted" style="color:#ccc;"
1441  id="contrast-minus"
1442  onclick="doImageAction(\'contrast-minus\',
1443  \'' . $this->id . '\',
1444  \'' . $this->folder . '\',
1445  \'' . $this->filename . '\',
1446  \'' . $this->itemID . '\',
1447  \'' . $this->createThumbnails . '\',
1448  \'' . $this->thumbnailWidth . '\',
1449  \'' . $this->watermark . '\',
1450  \'' . $this->watermarkImage . '\',
1451  \'' . $this->watermarkOpacity . '\',
1452  \'' . $this->watermarkPosition . '\',
1453  \'' . $this->offsetX . '\',
1454  \'' . $this->offsetY . '\',
1455  \'' . $this->watermarkFont . '\',
1456  \'' . $this->watermarkTextSize . '\',
1457  \'' . $this->watermarkColor . '\',
1458  \'' . $this->watermarkBorderColor . '\',
1459  \'' . $this->watermarkBorder . '\'
1460  )"></i>&nbsp;
1461  <i class="fa fa-sun-o"
1462  id="brightness-plus"
1463  onclick="doImageAction(\'brightness-plus\',
1464  \'' . $this->id . '\',
1465  \'' . $this->folder . '\',
1466  \'' . $this->filename . '\',
1467  \'' . $this->itemID . '\',
1468  \'' . $this->createThumbnails . '\',
1469  \'' . $this->thumbnailWidth . '\',
1470  \'' . $this->watermark . '\',
1471  \'' . $this->watermarkImage . '\',
1472  \'' . $this->watermarkOpacity . '\',
1473  \'' . $this->watermarkPosition . '\',
1474  \'' . $this->offsetX . '\',
1475  \'' . $this->offsetY . '\',
1476  \'' . $this->watermarkFont . '\',
1477  \'' . $this->watermarkTextSize . '\',
1478  \'' . $this->watermarkColor . '\',
1479  \'' . $this->watermarkBorderColor . '\',
1480  \'' . $this->watermarkBorder . '\'
1481  )"></i>&nbsp;
1482  <i class="fa fa-sun-o text-muted" style="color:#ccc;"
1483  id="brightness-minus"
1484  onclick="doImageAction(\'brightness-minus\',
1485  \'' . $this->id . '\',
1486  \'' . $this->folder . '\',
1487  \'' . $this->filename . '\',
1488  \'' . $this->itemID . '\',
1489  \'' . $this->createThumbnails . '\',
1490  \'' . $this->thumbnailWidth . '\',
1491  \'' . $this->watermark . '\',
1492  \'' . $this->watermarkImage . '\',
1493  \'' . $this->watermarkOpacity . '\',
1494  \'' . $this->watermarkPosition . '\',
1495  \'' . $this->offsetX . '\',
1496  \'' . $this->offsetY . '\',
1497  \'' . $this->watermarkFont . '\',
1498  \'' . $this->watermarkTextSize . '\',
1499  \'' . $this->watermarkColor . '\',
1500  \'' . $this->watermarkBorderColor . '\',
1501  \'' . $this->watermarkBorder . '\'
1502  )"></i>&nbsp;
1503  <i class="fa fa-diamond"
1504  id="sharpen"
1505  onclick="doImageAction(\'sharpen\',
1506  \'' . $this->id . '\',
1507  \'' . $this->folder . '\',
1508  \'' . $this->filename . '\',
1509  \'' . $this->itemID . '\',
1510  \'' . $this->createThumbnails . '\',
1511  \'' . $this->thumbnailWidth . '\',
1512  \'' . $this->watermark . '\',
1513  \'' . $this->watermarkImage . '\',
1514  \'' . $this->watermarkOpacity . '\',
1515  \'' . $this->watermarkPosition . '\',
1516  \'' . $this->offsetX . '\',
1517  \'' . $this->offsetY . '\',
1518  \'' . $this->watermarkFont . '\',
1519  \'' . $this->watermarkTextSize . '\',
1520  \'' . $this->watermarkColor . '\',
1521  \'' . $this->watermarkBorderColor . '\',
1522  \'' . $this->watermarkBorder . '\'
1523  )"></i>&nbsp;
1524  <i class="fa fa-magic"
1525  id="selective-blur"
1526  onclick="doImageAction(\'selective-blur\',
1527  \'' . $this->id . '\',
1528  \'' . $this->folder . '\',
1529  \'' . $this->filename . '\',
1530  \'' . $this->itemID . '\',
1531  \'' . $this->createThumbnails . '\',
1532  \'' . $this->thumbnailWidth . '\',
1533  \'' . $this->watermark . '\',
1534  \'' . $this->watermarkImage . '\',
1535  \'' . $this->watermarkOpacity . '\',
1536  \'' . $this->watermarkPosition . '\',
1537  \'' . $this->offsetX . '\',
1538  \'' . $this->offsetY . '\',
1539  \'' . $this->watermarkFont . '\',
1540  \'' . $this->watermarkTextSize . '\',
1541  \'' . $this->watermarkColor . '\',
1542  \'' . $this->watermarkBorderColor . '\',
1543  \'' . $this->watermarkBorder . '\'
1544  )"></i>&nbsp;
1545  <i class="fa fa-tint text-muted"
1546  id="greyscale"
1547  onclick="doImageAction(\'greyscale\',
1548  \'' . $this->id . '\',
1549  \'' . $this->folder . '\',
1550  \'' . $this->filename . '\',
1551  \'' . $this->itemID . '\',
1552  \'' . $this->createThumbnails . '\',
1553  \'' . $this->thumbnailWidth . '\',
1554  \'' . $this->watermark . '\',
1555  \'' . $this->watermarkImage . '\',
1556  \'' . $this->watermarkOpacity . '\',
1557  \'' . $this->watermarkPosition . '\',
1558  \'' . $this->offsetX . '\',
1559  \'' . $this->offsetY . '\',
1560  \'' . $this->watermarkFont . '\',
1561  \'' . $this->watermarkTextSize . '\',
1562  \'' . $this->watermarkColor . '\',
1563  \'' . $this->watermarkBorderColor . '\',
1564  \'' . $this->watermarkBorder . '\'
1565  )"></i>&nbsp;
1566  <i class="fa fa-tint"
1567  style="color:#9b5c1c;"
1568  id="sepia"
1569  onclick="doImageAction(\'sepia\',
1570  \'' . $this->id . '\',
1571  \'' . $this->folder . '\',
1572  \'' . $this->filename . '\',
1573  \'' . $this->itemID . '\',
1574  \'' . $this->createThumbnails . '\',
1575  \'' . $this->thumbnailWidth . '\',
1576  \'' . $this->watermark . '\',
1577  \'' . $this->watermarkImage . '\',
1578  \'' . $this->watermarkOpacity . '\',
1579  \'' . $this->watermarkPosition . '\',
1580  \'' . $this->offsetX . '\',
1581  \'' . $this->offsetY . '\',
1582  \'' . $this->watermarkFont . '\',
1583  \'' . $this->watermarkTextSize . '\',
1584  \'' . $this->watermarkColor . '\',
1585  \'' . $this->watermarkBorderColor . '\',
1586  \'' . $this->watermarkBorder . '\'
1587  )"></i>&nbsp;
1588  <i class="fa fa-th text-muted"
1589  id="pixelate"
1590  onclick="doImageAction(\'pixelate\',
1591  \'' . $this->id . '\',
1592  \'' . $this->folder . '\',
1593  \'' . $this->filename . '\',
1594  \'' . $this->itemID . '\',
1595  \'' . $this->createThumbnails . '\',
1596  \'' . $this->thumbnailWidth . '\',
1597  \'' . $this->watermark . '\',
1598  \'' . $this->watermarkImage . '\',
1599  \'' . $this->watermarkOpacity . '\',
1600  \'' . $this->watermarkPosition . '\',
1601  \'' . $this->offsetX . '\',
1602  \'' . $this->offsetY . '\',
1603  \'' . $this->watermarkFont . '\',
1604  \'' . $this->watermarkTextSize . '\',
1605  \'' . $this->watermarkColor . '\',
1606  \'' . $this->watermarkBorderColor . '\',
1607  \'' . $this->watermarkBorder . '\'
1608  )"></i>&nbsp;
1609  <i class="fa fa-refresh"
1610  id="reset-file"
1611  onclick="doImageAction(\'reset-file\',
1612  \'' . $this->id . '\',
1613  \'' . $this->folder . '\',
1614  \'' . $this->filename . '\',
1615  \'' . $this->itemID . '\',
1616  \'' . $this->createThumbnails . '\',
1617  \'' . $this->thumbnailWidth . '\',
1618  \'' . $this->watermark . '\',
1619  \'' . $this->watermarkImage . '\',
1620  \'' . $this->watermarkOpacity . '\',
1621  \'' . $this->watermarkPosition . '\',
1622  \'' . $this->offsetX . '\',
1623  \'' . $this->offsetY . '\',
1624  \'' . $this->watermarkFont . '\',
1625  \'' . $this->watermarkTextSize . '\',
1626  \'' . $this->watermarkColor . '\',
1627  \'' . $this->watermarkBorderColor . '\',
1628  \'' . $this->watermarkBorder . '\'
1629  )"></i>&nbsp;
1630  <i class="fa fa-trash-o"
1631  id="delete-file"
1632  onclick="doImageAction(\'delete-file\',
1633  \'' . $this->id . '\',
1634  \'' . $this->folder . '\',
1635  \'' . $this->filename . '\',
1636  \'' . $this->itemID . '\',
1637  \'' . $this->createThumbnails . '\',
1638  \'' . $this->thumbnailWidth . '\',
1639  \'' . $this->watermark . '\',
1640  \'' . $this->watermarkImage . '\',
1641  \'' . $this->watermarkOpacity . '\',
1642  \'' . $this->watermarkPosition . '\',
1643  \'' . $this->offsetX . '\',
1644  \'' . $this->offsetY . '\',
1645  \'' . $this->watermarkFont . '\',
1646  \'' . $this->watermarkTextSize . '\',
1647  \'' . $this->watermarkColor . '\',
1648  \'' . $this->watermarkBorderColor . '\',
1649  \'' . $this->watermarkBorder . '\'
1650  )"></i>&nbsp;<br>
1651  </div>
1652  <input type="hidden" name="filename-' . $this->itemID . '-old" value="' . $this->filename . '">
1653  <input type="hidden" name="title-' . $this->itemID . '-old" value="' . $this->itemTitle . '">
1654  <input type="hidden" name="author-' . $this->itemID . '-old" value="' . $this->itemAuthor . '">
1655  <input type="hidden" name="authorUrl-' . $this->itemID . '-old" value="' . $this->itemAuthorUrl . '">
1656  <input type="hidden" name="sort-' . $this->itemID . '-old" value="' . $this->sort . '">
1657  <input type="text" class="form-control" style="margin-bottom:2px;" maxlength="11" name="sort-' . $this->itemID . '" id="sort-' . $this->itemID . '" placeholder="0" value="' . $this->sort . '">
1658  <input type="text" class="form-control" style="margin-bottom:2px;" name="filename-' . $this->itemID . '" id="filename-' . $this->itemID . '" placeholder="filename.jpg" value="' . $this->filename . '">
1659  <input type="text" class="form-control" style="margin-bottom:2px;" name="title-' . $this->itemID . '" id="title-' . $this->itemID . '" placeholder="File Title" value="' . $this->itemTitle . '">
1660  <input type="text" class="form-control" style="margin-bottom:2px;" name="author-' . $this->itemID . '" id="author-' . $this->itemID . '" placeholder="Copyright owner of this picture" value="' . $this->itemAuthor . '">
1661  <input type="text" class="form-control" style="margin-bottom:2px;" name="authorUrl-' . $this->itemID . '" id="authorUrl-' . $this->itemID . '" placeholder="URL" value="' . $this->itemAuthorUrl . '"><br>
1662  <br></div>';
1663  } else {
1664  echo '
1665  <div class="col-md-4" id="imgCol-' . $this->itemID . '">
1666  <a href="../' . $row['folder'] . "/" . $this->filename . '?' . $rnd . '" data-lightbox="' . $this->id . '"><img class="img-thumbnail" id="img-' . $this->itemID . '" width="400" title="' . $this->itemTitle . '" src="../' . $row['folder'] . "/" . $this->filename . '?' . $rnd . '"></a>
1667 
1668  <div style="margin-top: 10px; margin-bottom:10px; cursor:pointer;" id="toolset-' . $this->itemID . '">
1669  <i class="fa fa-arrows-h"
1670  id="flipHorizontal"
1671  onclick="doImageAction(\'flip-horizontal\',
1672  \'' . $this->id . '\',
1673  \'' . $this->folder . '\',
1674  \'' . $this->filename . '\',
1675  \'' . $this->itemID . '\',
1676  \'' . $this->createThumbnails . '\',
1677  \'' . $this->thumbnailWidth . '\',
1678  \'' . $this->watermark . '\',
1679  \'' . $this->watermarkImage . '\',
1680  \'' . $this->watermarkOpacity . '\',
1681  \'' . $this->watermarkPosition . '\',
1682  \'' . $this->offsetX . '\',
1683  \'' . $this->offsetY . '\',
1684  \'' . $this->watermarkFont . '\',
1685  \'' . $this->watermarkTextSize . '\',
1686  \'' . $this->watermarkColor . '\',
1687  \'' . $this->watermarkBorderColor . '\',
1688  \'' . $this->watermarkBorder . '\'
1689  )"></i>&nbsp;
1690  <i class="fa fa-arrows-v"
1691  id="flipVertical"
1692  onclick="doImageAction(\'flip-vertical\',
1693  \'' . $this->id . '\',
1694  \'' . $this->folder . '\',
1695  \'' . $this->filename . '\',
1696  \'' . $this->itemID . '\',
1697  \'' . $this->createThumbnails . '\',
1698  \'' . $this->thumbnailWidth . '\',
1699  \'' . $this->watermark . '\',
1700  \'' . $this->watermarkImage . '\',
1701  \'' . $this->watermarkOpacity . '\',
1702  \'' . $this->watermarkPosition . '\',
1703  \'' . $this->offsetX . '\',
1704  \'' . $this->offsetY . '\',
1705  \'' . $this->watermarkFont . '\',
1706  \'' . $this->watermarkTextSize . '\',
1707  \'' . $this->watermarkColor . '\',
1708  \'' . $this->watermarkBorderColor . '\',
1709  \'' . $this->watermarkBorder . '\'
1710  )"></i>&nbsp;
1711  <i class="fa fa-undo"
1712  id="rotate-90"
1713  onclick="doImageAction(\'rotate-90\',
1714  \'' . $this->id . '\',
1715  \'' . $this->folder . '\',
1716  \'' . $this->filename . '\',
1717  \'' . $this->itemID . '\',
1718  \'' . $this->createThumbnails . '\',
1719  \'' . $this->thumbnailWidth . '\',
1720  \'' . $this->watermark . '\',
1721  \'' . $this->watermarkImage . '\',
1722  \'' . $this->watermarkOpacity . '\',
1723  \'' . $this->watermarkPosition . '\',
1724  \'' . $this->offsetX . '\',
1725  \'' . $this->offsetY . '\',
1726  \'' . $this->watermarkFont . '\',
1727  \'' . $this->watermarkTextSize . '\',
1728  \'' . $this->watermarkColor . '\',
1729  \'' . $this->watermarkBorderColor . '\',
1730  \'' . $this->watermarkBorder . '\'
1731  )"></i>&nbsp;
1732  <i class="fa fa-adjust"
1733  id="contrast-plus"
1734  onclick="doImageAction(\'contrast-plus\',
1735  \'' . $this->id . '\',
1736  \'' . $this->folder . '\',
1737  \'' . $this->filename . '\',
1738  \'' . $this->itemID . '\',
1739  \'' . $this->createThumbnails . '\',
1740  \'' . $this->thumbnailWidth . '\',
1741  \'' . $this->watermark . '\',
1742  \'' . $this->watermarkImage . '\',
1743  \'' . $this->watermarkOpacity . '\',
1744  \'' . $this->watermarkPosition . '\',
1745  \'' . $this->offsetX . '\',
1746  \'' . $this->offsetY . '\',
1747  \'' . $this->watermarkFont . '\',
1748  \'' . $this->watermarkTextSize . '\',
1749  \'' . $this->watermarkColor . '\',
1750  \'' . $this->watermarkBorderColor . '\',
1751  \'' . $this->watermarkBorder . '\'
1752  )"></i>&nbsp;
1753  <i class="fa fa-adjust text-muted" style="color:#ccc;"
1754  id="contrast-minus"
1755  onclick="doImageAction(\'contrast-minus\',
1756  \'' . $this->id . '\',
1757  \'' . $this->folder . '\',
1758  \'' . $this->filename . '\',
1759  \'' . $this->itemID . '\',
1760  \'' . $this->createThumbnails . '\',
1761  \'' . $this->thumbnailWidth . '\',
1762  \'' . $this->watermark . '\',
1763  \'' . $this->watermarkImage . '\',
1764  \'' . $this->watermarkOpacity . '\',
1765  \'' . $this->watermarkPosition . '\',
1766  \'' . $this->offsetX . '\',
1767  \'' . $this->offsetY . '\',
1768  \'' . $this->watermarkFont . '\',
1769  \'' . $this->watermarkTextSize . '\',
1770  \'' . $this->watermarkColor . '\',
1771  \'' . $this->watermarkBorderColor . '\',
1772  \'' . $this->watermarkBorder . '\'
1773  )"></i>&nbsp;
1774  <i class="fa fa-sun-o"
1775  id="brightness-plus"
1776  onclick="doImageAction(\'brightness-plus\',
1777  \'' . $this->id . '\',
1778  \'' . $this->folder . '\',
1779  \'' . $this->filename . '\',
1780  \'' . $this->itemID . '\',
1781  \'' . $this->createThumbnails . '\',
1782  \'' . $this->thumbnailWidth . '\',
1783  \'' . $this->watermark . '\',
1784  \'' . $this->watermarkImage . '\',
1785  \'' . $this->watermarkOpacity . '\',
1786  \'' . $this->watermarkPosition . '\',
1787  \'' . $this->offsetX . '\',
1788  \'' . $this->offsetY . '\',
1789  \'' . $this->watermarkFont . '\',
1790  \'' . $this->watermarkTextSize . '\',
1791  \'' . $this->watermarkColor . '\',
1792  \'' . $this->watermarkBorderColor . '\',
1793  \'' . $this->watermarkBorder . '\'
1794  )"></i>&nbsp;
1795  <i class="fa fa-sun-o text-muted" style="color:#ccc;"
1796  id="brightness-minus"
1797  onclick="doImageAction(\'brightness-minus\',
1798  \'' . $this->id . '\',
1799  \'' . $this->folder . '\',
1800  \'' . $this->filename . '\',
1801  \'' . $this->itemID . '\',
1802  \'' . $this->createThumbnails . '\',
1803  \'' . $this->thumbnailWidth . '\',
1804  \'' . $this->watermark . '\',
1805  \'' . $this->watermarkImage . '\',
1806  \'' . $this->watermarkOpacity . '\',
1807  \'' . $this->watermarkPosition . '\',
1808  \'' . $this->offsetX . '\',
1809  \'' . $this->offsetY . '\',
1810  \'' . $this->watermarkFont . '\',
1811  \'' . $this->watermarkTextSize . '\',
1812  \'' . $this->watermarkColor . '\',
1813  \'' . $this->watermarkBorderColor . '\',
1814  \'' . $this->watermarkBorder . '\'
1815  )"></i>&nbsp;
1816  <i class="fa fa-diamond"
1817  id="sharpen"
1818  onclick="doImageAction(\'sharpen\',
1819  \'' . $this->id . '\',
1820  \'' . $this->folder . '\',
1821  \'' . $this->filename . '\',
1822  \'' . $this->itemID . '\',
1823  \'' . $this->createThumbnails . '\',
1824  \'' . $this->thumbnailWidth . '\',
1825  \'' . $this->watermark . '\',
1826  \'' . $this->watermarkImage . '\',
1827  \'' . $this->watermarkOpacity . '\',
1828  \'' . $this->watermarkPosition . '\',
1829  \'' . $this->offsetX . '\',
1830  \'' . $this->offsetY . '\',
1831  \'' . $this->watermarkFont . '\',
1832  \'' . $this->watermarkTextSize . '\',
1833  \'' . $this->watermarkColor . '\',
1834  \'' . $this->watermarkBorderColor . '\',
1835  \'' . $this->watermarkBorder . '\'
1836  )"></i>&nbsp;
1837  <i class="fa fa-magic"
1838  id="selective-blur"
1839  onclick="doImageAction(\'selective-blur\',
1840  \'' . $this->id . '\',
1841  \'' . $this->folder . '\',
1842  \'' . $this->filename . '\',
1843  \'' . $this->itemID . '\',
1844  \'' . $this->createThumbnails . '\',
1845  \'' . $this->thumbnailWidth . '\',
1846  \'' . $this->watermark . '\',
1847  \'' . $this->watermarkImage . '\',
1848  \'' . $this->watermarkOpacity . '\',
1849  \'' . $this->watermarkPosition . '\',
1850  \'' . $this->offsetX . '\',
1851  \'' . $this->offsetY . '\',
1852  \'' . $this->watermarkFont . '\',
1853  \'' . $this->watermarkTextSize . '\',
1854  \'' . $this->watermarkColor . '\',
1855  \'' . $this->watermarkBorderColor . '\',
1856  \'' . $this->watermarkBorder . '\'
1857  )"></i>&nbsp;
1858  <i class="fa fa-tint text-muted"
1859  id="greyscale"
1860  onclick="doImageAction(\'greyscale\',
1861  \'' . $this->id . '\',
1862  \'' . $this->folder . '\',
1863  \'' . $this->filename . '\',
1864  \'' . $this->itemID . '\',
1865  \'' . $this->createThumbnails . '\',
1866  \'' . $this->thumbnailWidth . '\',
1867  \'' . $this->watermark . '\',
1868  \'' . $this->watermarkImage . '\',
1869  \'' . $this->watermarkOpacity . '\',
1870  \'' . $this->watermarkPosition . '\',
1871  \'' . $this->offsetX . '\',
1872  \'' . $this->offsetY . '\',
1873  \'' . $this->watermarkFont . '\',
1874  \'' . $this->watermarkTextSize . '\',
1875  \'' . $this->watermarkColor . '\',
1876  \'' . $this->watermarkBorderColor . '\',
1877  \'' . $this->watermarkBorder . '\'
1878  )"></i>&nbsp;
1879  <i class="fa fa-tint"
1880  style="color:#9b5c1c;"
1881  id="sepia"
1882  onclick="doImageAction(\'sepia\',
1883  \'' . $this->id . '\',
1884  \'' . $this->folder . '\',
1885  \'' . $this->filename . '\',
1886  \'' . $this->itemID . '\',
1887  \'' . $this->createThumbnails . '\',
1888  \'' . $this->thumbnailWidth . '\',
1889  \'' . $this->watermark . '\',
1890  \'' . $this->watermarkImage . '\',
1891  \'' . $this->watermarkOpacity . '\',
1892  \'' . $this->watermarkPosition . '\',
1893  \'' . $this->offsetX . '\',
1894  \'' . $this->offsetY . '\',
1895  \'' . $this->watermarkFont . '\',
1896  \'' . $this->watermarkTextSize . '\',
1897  \'' . $this->watermarkColor . '\',
1898  \'' . $this->watermarkBorderColor . '\',
1899  \'' . $this->watermarkBorder . '\'
1900  )"></i>&nbsp;
1901  <i class="fa fa-th text-muted"
1902  id="pixelate"
1903  onclick="doImageAction(\'pixelate\',
1904  \'' . $this->id . '\',
1905  \'' . $this->folder . '\',
1906  \'' . $this->filename . '\',
1907  \'' . $this->itemID . '\',
1908  \'' . $this->createThumbnails . '\',
1909  \'' . $this->thumbnailWidth . '\',
1910  \'' . $this->watermark . '\',
1911  \'' . $this->watermarkImage . '\',
1912  \'' . $this->watermarkOpacity . '\',
1913  \'' . $this->watermarkPosition . '\',
1914  \'' . $this->offsetX . '\',
1915  \'' . $this->offsetY . '\',
1916  \'' . $this->watermarkFont . '\',
1917  \'' . $this->watermarkTextSize . '\',
1918  \'' . $this->watermarkColor . '\',
1919  \'' . $this->watermarkBorderColor . '\',
1920  \'' . $this->watermarkBorder . '\'
1921  )"></i>&nbsp;
1922  <i class="fa fa-refresh"
1923  id="reset-file"
1924  onclick="doImageAction(\'reset-file\',
1925  \'' . $this->id . '\',
1926  \'' . $this->folder . '\',
1927  \'' . $this->filename . '\',
1928  \'' . $this->itemID . '\',
1929  \'' . $this->createThumbnails . '\',
1930  \'' . $this->thumbnailWidth . '\',
1931  \'' . $this->watermark . '\',
1932  \'' . $this->watermarkImage . '\',
1933  \'' . $this->watermarkOpacity . '\',
1934  \'' . $this->watermarkPosition . '\',
1935  \'' . $this->offsetX . '\',
1936  \'' . $this->offsetY . '\',
1937  \'' . $this->watermarkFont . '\',
1938  \'' . $this->watermarkTextSize . '\',
1939  \'' . $this->watermarkColor . '\',
1940  \'' . $this->watermarkBorderColor . '\',
1941  \'' . $this->watermarkBorder . '\'
1942  )"></i>&nbsp;
1943  <i class="fa fa-trash-o"
1944  id="delete-file"
1945  onclick="doImageAction(\'delete-file\',
1946  \'' . $this->id . '\',
1947  \'' . $this->folder . '\',
1948  \'' . $this->filename . '\',
1949  \'' . $this->itemID . '\',
1950  \'' . $this->createThumbnails . '\',
1951  \'' . $this->thumbnailWidth . '\',
1952  \'' . $this->watermark . '\',
1953  \'' . $this->watermarkImage . '\',
1954  \'' . $this->watermarkOpacity . '\',
1955  \'' . $this->watermarkPosition . '\',
1956  \'' . $this->offsetX . '\',
1957  \'' . $this->offsetY . '\',
1958  \'' . $this->watermarkFont . '\',
1959  \'' . $this->watermarkTextSize . '\',
1960  \'' . $this->watermarkColor . '\',
1961  \'' . $this->watermarkBorderColor . '\',
1962  \'' . $this->watermarkBorder . '\'
1963  )"></i>&nbsp;<br>
1964  </div>
1965  <input type="hidden" name="filename-' . $this->itemID . '-old" value="' . $this->filename . '">
1966  <input type="hidden" name="title-' . $this->itemID . '-old" value="' . $this->itemTitle . '">
1967  <input type="hidden" name="author-' . $this->itemID . '-old" value="' . $this->itemAuthor . '">
1968  <input type="hidden" name="authorUrl-' . $this->itemID . '-old" value="' . $this->itemAuthorUrl . '">
1969  <input type="hidden" name="sort-' . $this->itemID . '-old" value="' . $this->sort . '">
1970  <input type="text" class="form-control" style="margin-bottom:2px;" maxlength="11" style="margin-bottom:2px;" name="sort-' . $this->itemID . '" id="sort-' . $this->itemID . '" placeholder="0" value="' . $this->sort . '">
1971  <input type="text" class="form-control" style="margin-bottom:2px;" name="filename-' . $this->itemID . '" id="filename-' . $this->itemID . '" placeholder="filename.jpg" value="' . $this->filename . '">
1972  <input type="text" class="form-control" style="margin-bottom:2px;" name="title-' . $this->itemID . '" id="title-' . $this->itemID . '" placeholder="File Title" value="' . $this->itemTitle . '">
1973  <input type="text" class="form-control" style="margin-bottom:2px;" name="author-' . $this->itemID . '" id="author-' . $this->itemID . '" placeholder="Copyright owner of this picture" value="' . $this->itemAuthor . '">
1974  <input type="text" class="form-control" style="margin-bottom:2px;" name="authorUrl-' . $this->itemID . '" id="authorUrl-' . $this->itemID . '" placeholder="URL" value="' . $this->itemAuthorUrl . '"><br>
1975  <br></div>';
1976  }
1977  $count++;
1978  }
1979  }
1980  }
1981  echo "</div></div>
1982  <hr>";
1983  }
1984  }
1985  return null;
1986  }
1987 
1988  }
1989  }
1990 }
$img
Definition: actions.php:3
$galleryID
Definition: actions.php:8
print $blog thumbnail
Definition: blog-edit.php:583
$blog description
Definition: blog-setup.php:49
if(!isset($language)||(!isset($lang))) $item
The Gallery Plugin Class. Help you building powerful image galleries nearly automatically.
Definition: gallery.php:50
drawFolderSelect($lang, $path)
draw (output) html folder select field, containing the sub folders of /media/images as value
Definition: gallery.php:170
scanImageDirectory($path)
scan image directory and return images as select field option value
Definition: gallery.php:238
checkDir($folder)
check if folder exists and create it on demand
Definition: gallery.php:196
__construct()
define JS function doImageAction gallery constructor.
Definition: gallery.php:120
drawFolderSelectFromGallery($path, $folder)
draw (output) html folder select field, containing the current folder of /media/images as value
Definition: gallery.php:183
scanFonts($path)
scan system font directory for fonts and return fonts as select field option value
Definition: gallery.php:215
static draw($type, $title, $text, $redirect, $delay)
Definition: alert.php:30
static recurseRmdir($dir)
remove a directory recurse
Definition: sys.php:1127
function h
This class serves methods to create backup from files.
Definition: AdminLTE.php:2
print $page title
Definition: page-edit.php:377
print $_GET['id']
Definition: page-edit.php:357
$i
Definition: gallery.php:161
print $lang['GALLERY_ADD']
Definition: gallery.php:91
function v(e, t, n, r, a)
Definition: plyr.js:1
function o(e, t, n)
Definition: plyr.js:1