YaWK  24.1
Yet another WebKit
blog.php
Go to the documentation of this file.
1 <?php
2 namespace YAWK\PLUGINS\BLOG {
3  /**
4  * @brief <b>Start blogging today! Very powerful app to create and manage any kind of blog.</b>
5  * <p>The Blog Plugin is very useful if you want to build anything that is or acts actually like
6  * blog. A bunch of pre-defined layouts are there to help you building a clean view to make
7  * your pages good looking. A Blog got a title, subtitle, teaser text, longer text, an image
8  * according left or right to the teaser text. It comes with a nice built in ajax-powered comment
9  * feature. You can create many different blogs and much more entries. It is perfect to build up
10  * a dynamic website. Blogs, pages, user comments and blog settings can be comfortably managed in
11  * a beautiful Backend. It is part of YaWK and integrates seamless.</p><br>
12  * <b>There are four major layouts:</b>
13  * <ul>
14  * <li>1 col, default text blog</li>
15  * <li>2 col, with preview image on the left</li>
16  * <li>2 col, with preview image on the right</li>
17  * <li>3 col, basic newspaper style</li></ul><br>
18  * <p>Create as many blogs as you want to, gain user rights to blogs and / or to any single item.
19  * Let users write down comments on every item. Comments can be turned on and off. There are many
20  * settings available to sort content, show up a title and subline (or not) and much more. It is a
21  * perfect choice to present content and -if needed- interact with users. You can manage everything
22  * in a beautiful Backend with the typically YaWK-styled performant table design. Be sure to check
23  * out the Blog's Docs on our website or watch our blog screenscast for further information!</p>
24  *
25  * <p><i>This class covers both, backend + frontend functionality.
26  * See Methods Summary for Details!</i></p>
27  *
28  * @author Daniel Retzl <[email protected]>
29  * @version 1.0.0
30  * @brief Handles the Blog System.
31  */
32  class blog
33  {
34  /** * @param int $id ID */
35  public $id;
36  /** * @param string $html html */
37  public $html;
38  /** * @param string $html_ext html ext */
39  public $html_ext;
40  /** * @param int $blogid blog ID */
41  public $blogid;
42  /** * @param int $itemid item ID */
43  public $itemid;
44  /** * @param int $itemgid item group ID */
45  public $itemgid;
46  /** * @param int $teaser 0|1 teaser yes/no */
47  public $teaser;
48  /** * @param string $title blog title */
49  public $title;
50  /** * @param string $filename blog filename */
51  public $filename;
52  /** * @param string $blogtitle blog title */
53  public $blogtitle;
54  /** * @param string $name blog name */
55  public $name;
56  /** * @param int $published 0|1 published, 1 = published, 0 = not published */
57  public $published;
58  /** * @param string $content blog content */
59  public $content;
60  /** * @param string $date_publish datetime when blog was published */
61  public $date_publish;
62  /** * @param string $date_changed datetime when blog was changed */
63  public $date_changed;
64  /** * @param string $date_unpublish datetime when blog is about to un-publish */
65  public $date_unpublish;
66  /** * @param string $description blog description */
67  public $description;
68  /** * @param string $subtitle blog subtitle */
69  public $subtitle;
70  /** * @param string $date_created datetime when blog was created */
71  public $date_created;
72  /** * @param string $year_created year */
73  public $year_created;
74  /** * @param string $teasertext teaser text */
75  public $teasertext;
76  /** * @param string $blogtext blog text */
77  public $blogtext;
78  /** * @param string $author blog author */
79  public $author;
80  /** * @param string $author_vis ? blog vis */
81  public $author_vis;
82  /** * @param string $comment_date comment date */
83  public $comment_date;
84  /** * @param string $comment_author comment author */
85  public $comment_author;
86  /** * @param string $comment_email comment email */
87  public $comment_email;
88  /** * @param string $comment_text comment text */
89  public $comment_text;
90  /** * @param int $showTitle 0|1 show title, yes or no */
91  public $showTitle;
92  /** * @param int $showDesc 0|1 show description, yes or no */
93  public $showDesc;
94  /** * @param int $showDate 0|1 show date, yes or no */
95  public $showDate;
96  /** * @param int $showAuthor 0|1 show author, yes or no */
97  public $showAuthor;
98  /** * @param int|string $sequence ? */
99  public $sequence;
100  /** * @param int $sortation order sortation var */
101  public $sortation;
102  /** * @param string $icon blog icon (eg. fa fa-anyicon */
103  public $icon;
104  /** * @param string $permaLink permalink url */
105  public $permaLink;
106  /** * @param int|string $layout blog layout */
107  public $layout;
108  /** * @param int $comments 0|1 show comments, yes or no */
109  public $comments;
110  /** * @param string $thumbnail any thumbnail beneath the blog item */
111  public $thumbnail;
112  /** * @param string $alias blog alias (filename) */
113  public $alias;
114  /** * @param int $sort order sortation number */
115  public $sort;
116  /** * @param int $gid group ID */
117  public $gid;
118  /** * @param int $pageid page ID */
119  public $pageid;
120  /** * @param int|string $preview ?blog preview */
121  public $preview;
122  /** * @param int|string $voting 0|1 show voting, yes or no */
123  public $voting;
124  /** * @param string $youtubeUrl youtube video link */
125  public $youtubeUrl;
126  /** * @param string $weblink any external weblink */
127  public $weblink;
128  /** * @param string $metakeywords meta keywords */
129  public $meta_local;
130  /** * @param string $metadescription meta description */
131  public $meta_keywords;
132  /** * @param int|string $itemlayout blog item layout */
133  public $itemlayout;
134  /** * @param int|string $itemcomments show blog item comments, yes or no */
135  public $itemcomments;
136  /** * @param int $spacer 0|1 show a <hr> line between every item (article), yes or no */
137  public $spacer;
138  /** * @param int $frontendIcon 0|1 display blog icon in frontend */
139  public $frontendIcon;
140  /** * @param int $limitEntries 0|1 how many entries should be displayed */
141  public $limitEntries;
142  /** * @param int $showTotalVotes 0|1 if total votes should be displayed */
143  public $showTotalVotes;
144 
145  /**
146  * @brief @brief Inject Language Tags
147  * @author Daniel Retzl <[email protected]>
148  * @param array $lang language data array
149  * @param object $language the language object
150  * @return null
151  */
152  public function injectLanguageTags($lang, $language)
153  {
154  /** @var $db \YAWK\db */
155  // #####################################################################################
156  // prepare language tag injection
157  // check if lang array is set
158  if (!isset($lang) || (empty($lang) || (!is_array($lang) || (!isset($language) || (empty($language))))))
159  { // if no lang array is set
160  // check if language object is set
161  if (!isset($language))
162  { // if not, include language class
163  require_once '../system/classes/language.php';
164  // and create new language object
165  $language = new \YAWK\language();
166  }
167  // ok...
168  $language->init($db, "backend");
169  // convert lang object param to array
170  $lang = (array) $language->lang;
171  }
172  // all should be set ok - finally: inject additional language tags
173  return $lang = $language->inject($lang, "../system/plugins/blog/language/");
174  }
175 
176 
177  /**
178  * @brief @brief Print blog title
179  * @param string $title Blog Title
180  * @param string $subtext Blog SubTitle
181  * @param string $icon Font Awesome Icon e.g. fa fa-globe
182  * @return null
183  */
184  static function getBlogTitle($title, $subtext, $icon)
185  { // draw title
186  if ($title && $subtext && $icon)
187  { // draw title with icon
188  print "<h1><i class=\"fa " . $icon . "\"></i> " . $title . "&nbsp;<small>" . $subtext . "</small></h1>";
189  }
190  else if (empty($icon))
191  { // draw title without icon
192  print "<h1>" . $title . "&nbsp;<small>" . $subtext . "</small></h1>";
193  }
194  return null;
195  }
196 
197 
198  /**
199  * @brief @brief Print the latest blog subtitle from
200  * @param object $db Database Object
201  * @param int $blogid The blog id of the subtitle to get
202  * @return mixed mixed|bool
203  */
204  static function getLatestEntrySubtitle($db, $blogid)
205  { /** @var $db \YAWK\db */
206  if ($res = $db->query("SELECT subtitle FROM {blog_items} WHERE blogid = " . $blogid . " ORDER BY id DESC LIMIT 1")) { // fetch data
207  if ($result = mysqli_fetch_row($res)) { // success
208  return $res[0];
209  } else { // fetch failed
210  return false;
211  }
212  } else { // q failed
213  return false;
214  }
215  }
216 
217  /**
218  * @brief @brief Get the blog title
219  * @param object $db Database Object
220  * @param int $blogid The blog id of the title to get
221  * @return null
222  */
223  static function getTitle($db, $blogid)
224  { /** @var $db \YAWK\db */
225  // get blog title settings from database
226  $showTitle = self::getBlogProperty($db, $blogid, "showtitle");
227  $showDesc = self::getBlogProperty($db, $blogid, "showdesc");
228  $description = self::getBlogProperty($db, $blogid, "description");
229  $name = self::getBlogProperty($db, $blogid, "name");
230  $icon = self::getBlogProperty($db, $blogid, "icon");
231  $frontendIcon = self::getBlogProperty($db, $blogid, "frontendIcon");
232 
233 
234  // if frontend icon is enabled
235  if ($frontendIcon == 1)
236  { // check if icon is set and display it
237  if (!empty($icon))
238  { // set font awesome icon
239  $icon = "<i class=\"fa $icon\"></i>&nbsp;";
240  }
241  else
242  { // no icon is set, leave empty
243  $icon = '';
244  }
245  }
246  else
247  { // icon disabled
248  $icon = '';
249  }
250 
251  if ($showTitle && $showDesc == 1) { // show title AND description
252  print "<div class=\"container-fluid\">";
253  print "<h1>$icon"."$name <small>$description</small></h1><br>";
254  }
255  else if ($showTitle == 1 && $showDesc == 0) { // just title
256  print "<div class=\"container-fluid\">";
257  print "<h1>$icon"."$name</h1><br>";
258  }
259  else if ($showTitle == 0 && $showDesc == 1) { // just show description
260  print "<div class=\"container-fluid\">";
261  print "<h1>$icon"."$description</h1><br>";
262  }
263  else
264  { // just open a new container for following content (body, footer...)
265  print "<div class=\"container-fluid\">";
266  }
267  return null;
268  }
269 
270  /**
271  * @brief @brief Toggle a whole blog on/offline
272  * @param object $db Database Object
273  * @param int $id The blog id of the blog to toggle
274  * @param int $published The publish status 0|1
275  * @return bool
276  */
277  function toggleOffline($db, $id, $published)
278  {
279  /** @var $db \YAWK\db */
280  // TOGGLE BLOG STATUS
281  if ($res = $db->query("UPDATE {blog}
282  SET published = '" . $published . "'
283  WHERE id = '" . $id . "'")
284  ) { // success
285  return true;
286  } else { // q failed
287  return true;
288  }
289  }
290 
291  /**
292  * @brief @brief Toggle a single blog item (entry) on/offline
293  * @param object $db Database Object
294  * @param int $id The id of the blog item to toggle
295  * @param int $published The publish status 0|1
296  * @return bool
297  */
298  function toggleItemOffline($db, $id, $published)
299  {
300  /** @var $db \YAWK\db */
301  // TOGGLE ITEM STATUS
302  if ($db->query("UPDATE {blog_items}
303  SET published = '" . $published . "'
304  WHERE id = '" . $id . "'"))
305  {
306  // success
307  return true;
308  }
309  else
310  {
311  // toggle blog item failed
312  return false;
313  }
314  }
315 
316  /**
317  * @brief @brief Toggle a blog comment on/offline
318  * @param object $db Database Object
319  * @param int $id The id of the comment to toggle
320  * @param int $published The publish status 0|1
321  * @return bool
322  */
323  function toggleCommentOffline($db, $id, $published)
324  {
325  /** @var $db \YAWK\db */
326  // TOGGLE ITEM STATUS
327  if ($res = $db->query("UPDATE {blog_comments}
328  SET published = '" . $published . "'
329  WHERE id = '" . $id . "'")
330  ) { // success
331  return true;
332  } else { // q failed
333  return false;
334  }
335  }
336 
337  /**
338  * @brief @brief Toggle a the group id (role) of blog item
339  * @param object $db Database Object
340  * @param int $itemgid The new group id for the blog item
341  * @param int $id The id of the blog item to set
342  * @return bool
343  */
344  function toggleRole($db, $itemgid, $id)
345  {
346  /** @var $db \YAWK\db*/
347  // TOGGLE ITEM STATUS
348  if ($db->query("UPDATE {blog_items}
349  SET itemgid = '" . $itemgid . "'
350  WHERE id = '" . $id . "'"))
351  {
352  // success
353  return true;
354  }
355  else
356  { // update item group id failed
357  return false;
358  }
359  }
360 
361  /**
362  * @brief @brief This get all blog entries from database, prepare layout and draw them onscreen (frontend).
363  * @param object $db Database Object
364  * @param int $blogid The id of the blog to get entries from
365  * @param int $itemid The item id to get, if a single entry is wanted
366  * @param int $full_view Should the blog be loaded without a preview, in full mode as default? 0|1
367  * @param int $limit Number of entries to get from database.
368  * @return null
369  */
370  function getFrontendEntries($db, $blogid, $itemid, $full_view, $limit)
371  {
372  global $lang;
373  /** @var $db \YAWK\db */
374  // if no itemid is set, set the sql code for all items, vice versa.
375  if ($itemid != 0) $sql = "AND id = '$itemid'"; else $sql = '';
376  // get settings (frontend view)
377 
378  // get blog Group ID
379  $blog_gid = self::getBlogProperty($db, $blogid, "gid");
380 
381 
382  // ORDER BY
383  if ($this->sequence === '0')
384  {
385  $orderBy = "date_publish";
386  }
387  else if ($this->sequence === '1')
388  {
389  $orderBy = "title";
390  }
391 
392  // SORT
393  if ($this->sortation === '0')
394  {
395  $this->sortation = "ASC";
396  }
397  else if ($this->sortation === '1')
398  {
399  $this->sortation = "DESC";
400  }
401 
402  if ($limit != 0)
403  {
404  $limitSql = "LIMIT $limit";
405  }
406  else
407  {
408  $limitSql = '';
409  }
410 
411  // select settings for given blog id
412  $res = $db->query("SELECT * FROM {blog_items}
413  WHERE blogid = '$blogid' " . $sql . "
414  AND published = '1'
415  ORDER BY " . $orderBy . " " . $this->sortation . "
416  $limitSql");
417  // fetch data in loop
418  while ($row = mysqli_fetch_array($res))
419  { // set blog item properties
420  $this->itemid = $row['id'];
421  $this->uid = $row['uid'];
422  $this->gid = $row['uid'];
423  $this->pageid = $row['pageid'];
424  $this->title = $row['title'];
425  $this->subtitle = $row['subtitle'];
426  $this->teasertext = $row['teasertext'];
427  $this->blogtext = $row['blogtext'];
428  $this->gid = $row['itemgid'];
429  $this->date_publish = $row['date_publish'];
430  $this->date_unpublish = $row['date_unpublish'];
431  $this->date_created = $row['date_created'];
432  $this->date_changed = $row['date_changed'];
433  $this->author = $row['author'];
434  $this->blogid = $row['blogid'];
435  $this->thumbnail = $row['thumbnail'];
436  $this->youtubeUrl = $row['youtubeUrl'];
437  $this->weblink = $row['weblink'];
438  $this->voteUp = $row['voteUp'];
439  $this->voteDown = $row['voteDown'];
440  $this->itemlayout = $row['itemlayout'];
441  $this->itemcomments = $row['itemcomments'];
442  // settings for blog_item are set,
443 
444  // override blog layout, if item layout differ from global blog settings
445  if ($this->itemlayout !== "-1")
446  { // global layout differs from itemlayout,
447  // obviously we need to override the layout w item settings:
448  $this->layout = $this->itemlayout;
449  }
450 
451 
452  if ($this->showDate === '1')
453  { // show date of this entry
454  /* date string to array function */
455  $splitDate = \YAWK\sys::splitDate($this->date_publish);
456  /* set seperated vars */
457  $year = $splitDate['year'];
458  $day = $splitDate['day'];
459  $month = $splitDate['month'];
460  $time = $splitDate['time'];
461 
462  // get weekday from datetime
463  $weekday = \YAWK\sys::getWeekday($this->date_publish, $lang);
464 
465  // build a prettydate
466  $prettydate = "$weekday, $day. $month $year, $time";
467  $prettydate = trim($prettydate);
468  }
469  else
470  { // display no date
471  $prettydate = '';
472  }
473 
474  if ($this->permaLink === '1')
475  { // show permalink of this entry
477  $page = new \YAWK\page();
478  $alias = $page->getProperty($db, $this->pageid, "alias");
479  $this->permaLink = "share this URL: <a href=\"$host/$alias.html\">$host/$alias.html</a>";
480  }
481  else
482  { // no permalink
483  $page = new \YAWK\page();
484  $alias = $page->getProperty($db, $this->pageid, "alias");
485  $this->permaLink = '';
486  }
487 
488  if ($this->showAuthor === '1')
489  { // show author of this entry
490  $author = "by <strong>$this->author</strong>";
491  }
492  else
493  { // do not display author
494  $author = '';
495  }
496 
497  if ($this->voting === '1')
498  { // show voting box
499  $voting = self::drawVotingBox($db, $this->voteUp, $this->voteDown);
500  }
501  else
502  { // no voting
503  $voting = '';
504  }
505 
506  // current date + time
507  $atm = date("Y-m-d G:i:s");
508 
509  // check publish date and show entry
510  if ($atm < $this->date_publish)
511  {
512  $this->html .= "";
513  }
514  if (isset($_SESSION['gid']))
515  {
516  $session_gid = $_SESSION['gid'];
517  }
518  else
519  {
520  $session_gid = 1;
521  }
522  // check if content is outdated
523  if ($this->date_unpublish < $atm XOR $this->date_unpublish === NULL)
524  {
525  $this->html .= ""; // do nothing
526  } // check publish date and show entry
527  else if ($atm > $this->date_publish && $session_gid >= $this->gid && $session_gid >= $blog_gid)
528  {
529  // publish datetime is behind us, so display the blog
530  // 1.) check & get settings, 2. check layouts, 3. draw
531 
532  // check & build vars for single entry FULL view
533  if (isset($full_view) && ($full_view === 1))
534  {
535  $blogtextHtml = $this->blogtext;
536  $showAllButton = '';
537  }
538  else
539  {
540  if ($this->preview === 0)
541  {
542  $showAllButton = "<a class=\"btn btn-default\" role=\"button\" href=\"$alias.html\"><i class=\"fa fa-bars\"></i> &nbsp;alles anzeigen</a>";
543  }
544  else
545  {
546  $showAllButton = '';
547  }
548  $blogtextHtml = '';
549  }
550 
551  // check & set the different layouts
552  // LAYOUT 0 = 1 col, TEXT BLOG
553  // LAYOUT 1 = 2 col, IMG PREVIEW LEFT
554  // LAYOUT 2 = 2 col, IMG PREVIEW RIGHT
555  // LAYOUT 3 = 1 col, NEWSPAPER STYLE
556  // LAYOUT 4 = 1 col, YOUTUBE RESPONSIVE BLOG
557 
558  if ($this->layout === '0')
559  { // LAYOUT 0 = 1 col, default text blog
560  $this->html .= "<small class=\"pull-right\"><i>$this->permaLink$prettydate " . $author . "</i></small>";
561  $this->html .= "<h2>$this->title&nbsp;<small>$this->subtitle</small></h2>$this->teasertext" . $blogtextHtml . "";
562  // are comments enabled?
563  if ($this->comments !== '0')
564  {
565  if (isset($full_view) && ($full_view === 1))
566  { // full view, display comments
567  $this->html .= self::draw_commentbox($db, $lang);
568  }
569  else
570  { // display btn with link to the full view
571  $this->html .= "<br><a class='btn btn-default' role='button' href=\"$alias.html\"><i class='fa fa-bars'></i> &nbsp;anzeigen</a>";
572  }
573  }
574  else
575  { // no comments, show all button
576  $this->html .= $showAllButton;
577  }
578  if ($this->spacer === '1')
579  {
580  $this->html .= "<hr><br><br>";
581  }
582  else
583  {
584  $this->html .= "<br><br>";
585  }
586  }
587 
588  if ($this->layout === '1')
589  { // LAYOUT 1 = 2 cols, left thumbnail
590  if (!empty($this->thumbnail)) $imgHtml = "<br><img src=\"" . $this->thumbnail . "\" class=\"img-thumbnail img-lefty-less protected\">"; else $imgHtml = '';
591  $this->html .= "
592  <div class=\"row\">
593  <div class=\"col-md-4 text-center\">
594  <br>$imgHtml
595  </div>
596  <div class=\"col-md-8\">
597  <small class=\"pull-right\"><i>$this->permaLink$prettydate $author</i></small>
598  <h2>$this->title&nbsp;<small>$this->subtitle</small></h2>$this->teasertext" . $blogtextHtml . "";
599  // are comments enabled?
600  if ($this->comments !== '0')
601  {
602  if (isset($full_view) && ($full_view === 1))
603  { // full view, display comments
604  $this->html .= self::draw_commentbox($db);
605  }
606  else
607  { // display btn with link to the full view
608  $this->html .= "<br><a class='btn btn-default' href=\"$alias.html\"><i class='fa fa-bars'></i> &nbsp;anzeigen</a>";
609  }
610  }
611  else
612  { // no comments, show all button
613  $this->html .= $showAllButton;
614  }
615 
616  if ($this->spacer === '1')
617  {
618  $this->html .= "<hr>";
619  }
620  $this->html .= "</div>
621  </div><br><br>";
622  }
623 
624  if ($this->layout === '2')
625  { // LAYOUT 2 = 2 cols, right thumbnail
626  // check if there is a thumbnail
627  if (!empty($this->thumbnail))
628  { // build thumbnail markup
629  $imgHtml = "<br><a href=\"$alias.html\"><img src=\"" . $this->thumbnail . "\" class=\"img-thumbnail img-righty-less hvr-grow\"></a><br><br>";
630  }
631  else
632  { // no thumbnail, empty markup
633  $imgHtml = '';
634  }
635 
636  // fill HTML code
637  $this->html .= "
638  <div class=\"row\">
639  <div class=\"col-md-12 col-sm-12 col-lg-8 text-right\">
640  <small class=\"pull-right\"><i>$this->permaLink$prettydate $author</i></small><br>
641  <h2>$this->title&nbsp;<small>$this->subtitle</small></h2>$this->teasertext ".$blogtextHtml . "";
642 
643  // are comments enabled?
644  if ($this->comments !== '0')
645  {
646  if (isset($full_view) && ($full_view === 1))
647  {
648  $this->html .= self::draw_commentbox($db);
649  // $this->html .= $voting;
650  }
651  else
652  {
653  $this->html .= "<br><a class=\"btn btn-dark hvr-grow\" href=\"$alias.html\"><i class='fa fa-bars'></i> &nbsp;Show more</a><br><br>";
654  }
655  }
656  else
657  {
658  $this->html .= $showAllButton;
659  }
660 
661  if ($this->spacer === '1')
662  {
663  $this->html .= "<hr>";
664  }
665  $this->html .= "</div>
666  <div class=\"col-md-12 col-sm-12 col-lg-4\">
667  <br>$imgHtml </div>
668 
669  </div><br><br>";
670  }
671  if ($this->layout === '3')
672  { // LAYOUT 3 = 3 cols, newspaper layout
673  if (!empty($this->thumbnail)) $imgHtml = "<img src=\"" . $this->thumbnail . "\" class=\"thumbnail img-responsive\">"; else $imgHtml = '';
674  $this->html .= "<div class=\"row\">
675  <div class=\"col-xs-6 col-md-4\"><br>advertising space</div>
676  <div class=\"col-xs-6 col-md-4\">
677  <small class=\"pull-right\"><i>$this->permaLink$prettydate $author</i></small>
678  <h2>$this->title&nbsp;<small>$this->subtitle</small></h2>$imgHtml $this->teasertext" . $blogtextHtml . "
679  ";
680  // are comments enabled?
681  if ($this->comments !== '0')
682  {
683  if (isset($full_view) && ($full_view === 1))
684  {
685  $this->html .= self::draw_commentbox($db);
686  }
687  else
688  {
689  $this->html .= "<a href=\"$alias.html\"><i class='btn btn-info'>comments anzeigen</i></a>";
690  }
691  }
692  else
693  {
694  $this->html .= $showAllButton;
695  }
696 
697  if ($this->spacer === '1')
698  {
699  $this->html .= "<hr>";
700  }
701  $this->html .= "</div>
702  <div class=\"col-xs-6 col-md-4\"><br>advertising space
703  </div>
704  </div><br><br>";
705  }
706  if ($this->layout === '4') { // LAYOUT 4 = 1 col, youtube responsive blog
707  // cut of time from prettydate
708  $prettydate = substr($prettydate, 0, -7);
709  if (!empty($this->youtubeUrl)) {
710  $this->html .= "<small class=\"pull-right\"><i>$this->permaLink$prettydate $author</i></small>";
711  $this->html .= "<h2>$this->title&nbsp;<small>$this->subtitle</small></h2>
712  <div class=\"embed-container\">
713  <iframe src=\"$this->youtubeUrl\" frameborder=\"0\" allowfullscreen></iframe>
714  </div>";
715  $this->html .= "$this->teasertext";
716  $this->html .= "<br>$voting";
717  $this->html .= "$blogtextHtml";
718 
719  // are comments enabled?
720  if ($this->comments !== '0') {
721  if (isset($full_view) && ($full_view === 1)) {
722  $this->html .= self::draw_commentbox($db);
723  } else {
724  $this->html .= "<a class='btn btn-default' role='button' href=\"$alias.html\"><i class='fa fa-bars'></i> &nbsp;anzeigen</a><br><br><br>";
725  }
726  } else {
727  $this->html .= $showAllButton;
728  }
729 
730  if ($this->spacer === '1')
731  {
732  $this->html .= "<hr><br><br>";
733  }
734  else
735  {
736  $this->html .= "<br><br>";
737  }
738  }
739  }
740  }
741  }
742  return null;
743  }
744 
745  /**
746  * @details +++ still in development +++ not for production use! - Draw a voting box (thumbs up/down)
747  * @author Daniel Retzl <[email protected]>
748  * @version 0.0.0
749  * @link http://yawk.io
750  * @param object $db Database Object
751  * @param int $voteUp Vote up integer
752  * @param int $voteDown Vote down integer
753  * @return mixed Html voting box
754  */
755  function drawVotingBox($db, $voteUp, $voteDown)
756  { /** @var $db \YAWK\db */
757  if ($this->voting === '1')
758  {
759  $totalVotes = $voteUp + $voteDown;
760  // check, if there are any votes yet
761  if ($totalVotes === 0)
762  { // if not, set this text:
763  $totalText = "<b>Be the first to vote!</b>";
764  }
765  // check if total votes should be shown or not
766  if ($this->showTotalVotes === '1')
767  {
768  // show total votes
769  $totalText = "<b>Total Votes:</b> <span id=\"totalVotesText\">$totalVotes</span>";
770  }
771  else
772  { // no total votes, empty markup
773  $totalText = "";
774  }
775 
776  $votingBox = "<div class=\"mx-auto d-block\"><h3>Vote this</h3><br><h5><small>$totalText
777  <span id=\"voteUp\" class=\"hvr-grow\" style=\"cursor:pointer;\"><i class=\"fa fa-thumbs-o-up fa-3x\" id=\"voteUpIcon\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"LIKE this\"></i>&nbsp;(<span id=\"voteUpText\"><small>$voteUp</small></span>)</span>
778  &nbsp;
779  <span id=\"voteDown\" class=\"hvr-grow\" style=\"cursor:pointer;\"><i class=\"fa fa-thumbs-o-down fa-3x\" id=\"voteDownIcon\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"Dislike this\"></i>&nbsp;(<span id=\"voteDownText\"><small>$voteDown</small></span>)</span><br></small></h5></div>";
780  return $votingBox;
781  }
782  else
783  { // no voting allowed
784  return null;
785  }
786  }
787 
788  /**
789  * @brief @brief Get any blog property you want from given blogid.
790  * @details Selection goes like this: "SELECT $property FROM {blog} WHERE id = $blogid
791  * @author Daniel Retzl <[email protected]>
792  * @version 1.0.0
793  * @param object $db Database Object
794  * @param int $blogid The blog id of which we want to get the settings
795  * @param string $property The property to get
796  * @return mixed|bool
797  */
798  static function getBlogProperty($db, $blogid, $property)
799  {
800  /** @var $db \YAWK\db */
801  if ($res = $db->query("SELECT $property FROM {blog} WHERE id = '" . $blogid . "'"))
802  { // fetch data
803  if ($row = mysqli_fetch_row($res))
804  {
805  // success
806  return $row['0'];
807  }
808  else
809  { // fetch failed
810  return false;
811  }
812  }
813  else
814  { // q failed
815  return false;
816  }
817  }
818 
819  /**
820  * @brief @brief Load properties for given blog id and store $this -> $blog properties
821  * @author Daniel Retzl <[email protected]>
822  * @version 1.0.0
823  * @param object $db Database Object
824  * @param int $blogid The blog id of which we want to load properties
825  * @param string $property The property to get
826  * @return bool
827  */
828  function loadBlogProperties($db, $blogid)
829  {
830  /** @var $db \YAWK\db */
831  if ($res = $db->query("SELECT * FROM {blog} WHERE id = '" . $blogid . "'"))
832  { // fetch data
833  if ($row = mysqli_fetch_array($res))
834  { // set properties
835  $this->id = $row['id'];
836  $this->sort = $row['sort'];
837  $this->published = $row['published'];
838  $this->name = $row['name'];
839  $this->description = $row['description'];
840  $this->icon = $row['icon'];
841  $this->showTitle = $row['showtitle'];
842  $this->showDesc = $row['showdesc'];
843  $this->showDate = $row['showdate'];
844  $this->showAuthor = $row['showauthor'];
845  $this->sequence = $row['sequence'];
846  $this->sortation = $row['sortation'];
847  $this->footer = $row['footer'];
848  $this->comments = $row['comments'];
849  $this->gid = $row['gid'];
850  $this->permaLink = $row['permalink'];
851  $this->layout = $row['layout'];
852  $this->preview = $row['preview'];
853  $this->voting = $row['voting'];
854  $this->spacer = $row['spacer'];
855  $this->frontendIcon = $row['frontendIcon'];
856  $this->showTotalVotes = $row['showTotalVotes'];
857  return true;
858  }
859  else
860  { // fetch failed
861  return false;
862  }
863  }
864  else
865  { // q failed
866  return false;
867  }
868  }
869 
870  /**
871  * @brief @brief Load properties for given blog item (entry) and store $this -> $blog properties
872  * @author Daniel Retzl <[email protected]>
873  * @version 1.0.0
874  * @param object $db Database Object
875  * @param int $blogid The blog id of which we want to load properties
876  * @param int $itemid The item id of which we want to load properties
877  * @return bool
878  */
879  function loadItemProperties($db, $blogid, $itemid)
880  { /** @var $db \YAWK\db */
881  if ($res = $db->query("SELECT * FROM {blog_items}
882  WHERE blogid = '" . $blogid . "'
883  AND id = '" . $itemid . "'"))
884  { // fetch data
885  if ($row = mysqli_fetch_array($res)) { // set blog ITEM properties
886  $this->blogid = $row['blogid'];
887  $this->itemid = $row['id'];
888  $this->uid = $row['uid'];
889  $this->pageid = $row['pageid'];
890  $this->sort = $row['sort'];
891  $this->published = $row['published'];
892  $this->itemgid = $row['itemgid'];
893  $this->teaser = $row['teaser'];
894  $this->blogtitle = $row['title'];
895  $this->filename = $row['filename'];
896  $this->subtitle = $row['subtitle'];
897  $this->date_created = $row['date_created'];
898  $this->date_changed = $row['date_changed'];
899  $this->date_publish = $row['date_publish'];
900  $this->date_unpublish = $row['date_unpublish'];
901  $this->teasertext = $row['teasertext'];
902  $this->blogtext = $row['blogtext'];
903  $this->author = $row['author'];
904  $this->thumbnail = $row['thumbnail'];
905  $this->youtubeUrl = $row['youtubeUrl'];
906  $this->weblink = $row['weblink'];
907  $this->itemlayout = $row['itemlayout'];
908  $this->itemcomments = $row['itemcomments'];
909 
910  // todo: improve query to select join instead! (this spares two db requests)
911  $this->meta_local = \YAWK\page::getMetaTags($db, $this->pageid, "meta_local");
912  $this->meta_keywords = \YAWK\page::getMetaTags($db, $this->pageid, "meta_keywords");
913  }
914  else
915  { // fetch failed
916  return false;
917  }
918  }
919  else
920  { // q failed
921  return false;
922  }
923  return true;
924  }
925 
926  /**
927  * @brief Save blog blog entry data. (See blog properties)
928  * @author Daniel Retzl <[email protected]>
929  * @version 1.0.0
930  * @param object $db Database Object
931  * @return bool
932  */
933  function save($db)
934  {
935  if (empty($this->sort)){ $this->sort = 1; }
936  /** @var $db \YAWK\db */
937  $date_changed = date("Y-m-d G:i:s");
938  // $this->teasertext = stripslashes(str_replace('\r\n', '', $this->teasertext));
939  /* alias string manipulation to generate a valid filename */
940  $this->filename = mb_strtolower($this->filename); // lowercase
941  $this->filename = str_replace(" ", "-", $this->filename); // replace all ' ' with -
942  // special chars
943  $umlaute = array("/ä/", "/ü/", "/ö/", "/Ä/", "/Ãœ/", "/Ö/", "/ß/"); // array of special chars
944  $ersetze = array("ae", "ue", "oe", "ae", "ue", "oe", "ss"); // array of replacement chars
945  $this->filename = preg_replace($umlaute, $ersetze, $this->filename); // replace with preg
946  $this->filename = preg_replace("/[^a-z0-9\-\/]/i", "", $this->filename); // final check: just numbers and chars are allowed
947 
948  // get filename from pages db
949  $res = $db->query("SELECT alias FROM {pages} WHERE id = '" . $this->pageid . "'");
950  $row = mysqli_fetch_row($res);
951  $alias_old = $row[0];
952  $filename_old = "../content/pages/" . $alias_old . ".php";
953  $filename = "../content/pages/" . $this->filename . ".php";
954  // set content of the plugin file
955  $content = "<?php \$blog_id = $this->blogid; \$item_id = $this->itemid; \$full_view = 1; include 'system/plugins/blog/blog.php'; ?>";
956  if (file_exists($filename_old))
957  {
958  $handle = fopen($filename, "wr");
959  $res = fwrite($handle, $content);
960  fclose($handle);
961  chmod($filename, 0777);
962  if (!$res)
963  { // cannot write file, throw error
964  \YAWK\alert::draw("danger", "Error", "could not write file: $filename", "", "4200");
965  }
966  }
967  else
968  {
969  $handle = fopen($filename, "wr");
970  $res = fwrite($handle, $content);
971  fclose($handle);
972  chmod($filename, 0777);
973  if (!$res)
974  {
975  \YAWK\alert::draw("danger", "Error", "could not create file: $filename", "", "4200");
976  }
977  }
978  // convert html special chars
979 
980  if (!empty($this->title)) {
981  $this->title = htmlentities($this->title);
982  }
983  if (!empty($this->subtitle)){
984  $this->subtitle = htmlentities($this->subtitle);
985  }
986 
987  // $this->blogtext = nl2br(htmlentities($this->blogtext, ENT_QUOTES, 'UTF-8'));
988 
989  // UPDATE PAGES TABLE
990  if ($res = $db->query("UPDATE {pages} SET
991  alias = '" . $this->filename . "',
992  title = '" . $this->blogtitle . "',
993  meta_local = '" . $this->meta_local . "',
994  meta_keywords = '" . $this->meta_keywords . "'
995  WHERE id = '" . $this->pageid . "'"))
996  {
997 
998  // UPDATE BLOG ENTRY ITSELF
999  if ($this->date_unpublish === "0000-00-00 00:00:00" || (empty($this->date_unpublish)))
1000  {
1001  // sql code with date_unblish = NULL
1002  if ($res = $db->query("UPDATE {blog_items} SET
1003  published = '" . $this->published . "',
1004  itemgid = '" . $this->itemgid . "',
1005  sort = '" . $this->sort . "',
1006  teaser = '" . $this->teaser . "',
1007  title = '" . $this->blogtitle . "',
1008  filename = '" . $this->filename . "',
1009  subtitle = '" . $this->subtitle . "',
1010  date_changed = '" . $date_changed . "',
1011  date_publish = '" . $this->date_publish . "',
1012  date_unpublish = NULL,
1013  teasertext = '" . $this->teasertext . "',
1014  blogtext = '" . $this->blogtext . "',
1015  thumbnail = '" . $this->thumbnail . "',
1016  youtubeUrl = '" . $this->youtubeUrl . "',
1017  weblink = '" . $this->weblink . "',
1018  itemlayout = '" . $this->itemlayout . "',
1019  itemcomments = '" . $this->itemcomments . "'
1020  WHERE id = '" . $this->itemid . "'
1021  AND blogid = '" . $this->blogid . "'"))
1022  { // success
1023  return true;
1024  }
1025  else
1026  { // update blog items failed,
1027  return false;
1028  }
1029  }
1030  else
1031  {
1032  // sql insert with a valid user selected unpublish date
1033  if ($res = $db->query("UPDATE {blog_items} SET
1034  published = '" . $this->published . "',
1035  itemgid = '" . $this->itemgid . "',
1036  sort = '" . $this->sort . "',
1037  teaser = '" . $this->teaser . "',
1038  title = '" . $this->blogtitle . "',
1039  filename = '" . $this->filename . "',
1040  subtitle = '" . $this->subtitle . "',
1041  date_changed = '" . $date_changed . "',
1042  date_publish = '" . $this->date_publish . "',
1043  date_unpublish = '" . $this->date_unpublish . "',
1044  teasertext = '" . $this->teasertext . "',
1045  blogtext = '" . $this->blogtext . "',
1046  thumbnail = '" . $this->thumbnail . "',
1047  youtubeUrl = '" . $this->youtubeUrl . "',
1048  weblink = '" . $this->weblink . "',
1049  itemlayout = '" . $this->itemlayout . "',
1050  itemcomments = '" . $this->itemcomments . "'
1051  WHERE id = '" . $this->itemid . "'
1052  AND blogid = '" . $this->blogid . "'"))
1053  { // success
1054  return true;
1055  }
1056  else
1057  { // update blog items failed,
1058  return false;
1059  }
1060  }
1061  }
1062  else
1063  { // update pages failed, abort +
1064  return false;
1065  }
1066  }
1067 
1068  /**
1069  * @brief Save blog settings data. (layout, general settings, comment settings etc...)
1070  * @author Daniel Retzl <[email protected]>
1071  * @version 1.0.0
1072  * @param object $db Database Object
1073  * @param object $blog The blog Object
1074  * @param string $property The property to get
1075  * @return bool
1076  */
1077  public function setup($db, $blog)
1078  {
1079  /** @var $db \YAWK\db */
1080  // convert html special chars
1081  // $this->name = htmlentities($blog->name);
1082  // $this->description = htmlentities($blog->description);
1083  if ($db->query("UPDATE {blog} SET
1084  name = '" . $this->name . "',
1085  description = '" . $this->description . "',
1086  icon = '" . $this->icon . "',
1087  showtitle = '" . $this->showTitle . "',
1088  showdesc = '" . $this->showDesc . "',
1089  showdate = '" . $this->showDate . "',
1090  showauthor = '" . $this->showAuthor . "',
1091  sequence = '" . $this->sequence . "',
1092  sortation = '" . $this->sortation . "',
1093  comments = '" . $this->comments . "',
1094  permalink = '" . $this->permaLink . "',
1095  preview = '" . $this->preview . "',
1096  voting = '" . $this->voting . "',
1097  layout = '" . $this->layout . "',
1098  gid = '" . $this->gid . "',
1099  spacer = '" . $this->spacer . "',
1100  limitEntries = '" . $this->limitEntries. "',
1101  showTotalVotes = '" . $this->showTotalVotes. "'
1102  WHERE id = '" . $this->blogid . "'"))
1103  {
1104  return true;
1105  }
1106  else
1107  {
1108  return false;
1109  }
1110  }
1111 
1112  /**
1113  * @brief Return a copyright footer
1114  * @author Daniel Retzl <[email protected]>
1115  * @version 1.0.0
1116  * @param object $db Database Object
1117  * @return mixed Html Code
1118  */
1119  function getFooter($db)
1120  {
1121  /** @var $db \YAWK\db */
1122  $this->year_created = date("Y"); // current year
1123  $hostURL = \YAWK\settings::getSetting($db, "host");
1124  return $this->html .= "<small><i class='pull-right'>Copyright (C) $this->year_created $hostURL</i></small>";
1125  }
1126 
1127 
1128  /**
1129  * @brief Return the HTML code. To render the view, call this function with echo or print
1130  * @author Daniel Retzl <[email protected]>
1131  * @version 1.0.0
1132  * @return mixed Html
1133  */
1134  function draw()
1135  { // mixed HTML, built, filled and modified previously by several blog class methods
1136  return $this->html;
1137  }
1138 
1139  /**
1140  * @brief Get all comments for given blog + item id and stores it in $this->html
1141  * @author Daniel Retzl <[email protected]>
1142  * @version 1.0.0
1143  * @param object $db Database Object
1144  * @param int $blogid The blog ID to get comments from
1145  * @param int $itemid The item ID to get comments from
1146  * @param array $row The current dataset
1147  * @return null
1148  */
1149  function getAllComments($db, $blogid, $itemid, $row, $lang)
1150  {
1151  /** @var $db \YAWK\db */
1152  $replies = 0;
1153  $replyForm = "";
1154  $replyCount = 1;
1155  // prepare vars + design
1156  // get the date and make it pretty
1157  $date = \YAWK\sys::splitDate($row['date_created']);
1158  $prettydate = "$date[day]. $date[month] $date[year] um $date[time]";
1159 
1160  // if emailadress is set
1161  if (isset($row['email']) && (!empty($row['email']))) {
1162  // draw mailto: link
1163  $emailUrl = "<a href=\"mailto:" . $row['email'] . "\" class=\"text-black\">" . $row['name'] . "</a>";
1164  } else { // draw the comment's author grey colored
1165  $emailUrl = "<span class=\"text-grey\">" . $row['name'] . "</span>";
1166  }
1167 
1168  // if user was NOT logged in, it was a public comment
1169  if ($row['uid'] === '0' || $row['gid'] === '0') {
1170  $VipStyle = 'h5'; // smaller size for not logged in users
1171  } else { // bigger tag if user was a VIP
1172  $VipStyle = "h4 style=\"color: #912F40;\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"VIP User\"";
1173  }
1174 
1175  // build reply link based on $i replies
1176  // count comment replies from parent items
1177  if ($sql_replies = $db->query("SELECT id FROM {blog_comments} WHERE parentID = '" . $row['id'] . "' AND published = '1'")) { // fetch data in loop
1178  while ($res = mysqli_fetch_assoc($sql_replies)) { // add 1 for each loop cycle
1179  $replies++;
1180  }
1181  }
1182  // if there are replies
1183  if ($replies > 0) { // draw "comments" link ($i replies)
1184  $replyLink = "<small class=\"pull-right\"><a href='#replyBox$row[id]' data-toggle=\"collapse\" aria-expanded=\"false\" aria-controls=\"replyBox\" id='" . $row['id'] . "'>Kommentare ($replies)</a></small>";
1185  } else { // draw "reply" link
1186  $replyLink = "<small class=\"pull-right\"><a href='#form' data-toggle=\"collapse\" aria-expanded=\"false\" aria-controls=\"form\" id='" . $row['id'] . "'>antworten</a></small>";
1187  }
1188  // if comment ain't got a parent id
1189  if ($row['parentID'] == 0) {
1190  $replyForm = "";
1191  } else { // display reply form
1192  if ($replyCount <= 2) {
1193  $replyForm = "<form role='form' method='post'>
1194  <input type='text' name='name' class='form-control'>
1195  <textarea class='form-control' name='comment'></textarea>
1196  </form>";
1197  } else { // no reply form
1198  $replyForm = "";
1199  }
1200  }
1201 
1202  $this->html .= "$replyForm";
1203  $this->html .= "<i><$VipStyle>" . $emailUrl . " <small>am $prettydate</small></i></h5>";
1204  $this->html .= "<p>" . $row['comment'] . "</p>$replyLink";
1205  // $this->html .="<small class=\"pull-right\"><a href='#replyBox$row[id]' data-toggle=\"collapse\" aria-expanded=\"false\" aria-controls=\"replyBox\" id='".$row['id']."'>$btnText</a></small>";
1206  /* The following sql checks whether there's any reply for the comment */
1207  if ($res = $db->query("SELECT * FROM {blog_comments}
1208  WHERE blogid='" . $blogid . "' AND itemid='" . $itemid . "' AND parentID = '" . $row['id'] . "'")
1209  ) {
1210  if (mysqli_num_rows($res) > 0) // there is at least reply
1211  { // draw entry
1212  $this->html .= "<div class=\"collapse\" id=\"replyBox$row[id]\"><blockquote>";
1213  while ($row = mysqli_fetch_assoc($res)) {
1214  // self::draw_commentbox();
1215  self::getAllComments($db, $blogid, $itemid, $row, $lang);
1216  }
1217  $this->html .= "</blockquote></div>";
1218  }
1219  }
1220  $this->html .= "<br>";
1221  return null;
1222  }
1223 
1224  /**
1225  * @brief Get all comments for given blog + item id and stores it in $this->html
1226  * @author Daniel Retzl <[email protected]>
1227  * @version 1.0.0
1228  * @param object $db Database Object
1229  * @param int $blogid The blog ID to get comments from
1230  * @param int $itemid The item ID to get comments from
1231  * @return null
1232  */
1233  function drawComments($db, $blogid, $itemid, $lang)
1234  {
1235  /** @var $db \YAWK\db */
1236  // build html
1237  $this->html .= "<div id=\comment_thread\">";
1238 
1239  // get parent items
1240  $res = $db->query("SELECT * FROM {blog_comments} WHERE blogid = '" . $blogid . "' AND itemid = '" . $itemid . "' ORDER BY date_created DESC");
1241  while ($row = mysqli_fetch_assoc($res)) {
1242  self::getComments($db, $blogid, $itemid);
1243  // self::getAllComments($blogid, $itemid, $row);
1244  }
1245  $this->html .= "</div>";
1246  return null;
1247  }
1248 
1249 
1250  /**
1251  * @brief Get all comments for given blog + item id and stores it in $this->html
1252  * @author Daniel Retzl <[email protected]>
1253  * @version 1.0.0
1254  * @param object $db Database Object
1255  * @param int $blogid The blog ID to get comments from
1256  * @param int $itemid The item ID to get comments from
1257  * @return null
1258  */
1259  function getComments($db, $blogid, $itemid)
1260  {
1261  /** @var $db \YAWK\db */
1262  /* ADMIN ONLY */
1263  // ADMIN? - SHOW ALL COMMENTS:
1264  if ($_SESSION['gid'] >=5)
1265  {
1266  // GET COMMENTS
1267  $sql = $db->query("SELECT * FROM {blog_comments} WHERE blogid = '".$blogid."'");
1268  while($row = mysqli_fetch_row($sql))
1269  {
1270  $sql2 = $db->query("SELECT username FROM {users} WHERE id = '".$row[0]."'");
1271  while($row2 = mysqli_fetch_row($sql2))
1272  {
1273  // DRAW COMMENTS
1274  $this->comments .= "<i>von: <strong>$row2[0]</i></strong><br> &nbsp;$row[1]<br><br>";
1275  }
1276  }
1277  } // end admin check */
1278  // GET COMMENTS
1279 
1280  // set var defaults
1281  $comment_replies = 0;
1282  $indent = "";
1283  $padding = "padding-left: 0.3em;";
1284  // build html...
1285  $this->html .= "<div id=\"comment_thread\">";
1286  if ($res = $db->query("SELECT * FROM {blog_comments}
1287  WHERE blogid = '" . $blogid . "'
1288  AND itemid = '" . $itemid . "'
1289  AND published = '1'
1290  ORDER BY date_created DESC"))
1291  {
1292  while ($row = mysqli_fetch_assoc($res))
1293  {
1294  $comment_id = $row['id'];
1295  $comment = $row['comment'];
1296  $uid = $row['uid'];
1297  $gid = $row['gid'];
1298  $name = $row['name'];
1299  $email = $row['email'];
1300  $date_created = $row['date_created'];
1301  $isParent = $row['isParent'];
1302  $isChild = $row['isChild'];
1303  $parentID = $row['parentID'];
1304 
1305  $date = \YAWK\sys::splitDate($date_created);
1306  $prettydate = "$date[day]. $date[month] $date[year] um $date[time]";
1307 
1308  // if zero, set text link "answer..."
1309  if ($isParent === '0')
1310  {
1311  //
1312  if ($isChild !== '1')
1313  {
1314  $indent = "";
1315  $padding = "padding-left: 0.3em;";
1316  $collapse = "";
1317  $collapseFooter = "";
1318  // no child items available, because this is not a parent item
1319  $reply_link = "<small><a href=\"#replyBox\" class=\"pull-right small\"><i>antworten... </i><i class=\"fa fa-chevron-down\"></i></a></small>";
1320  }
1321  else
1322  {
1323  $reply_link = "";
1324  $indent = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
1325  $padding = "padding-left: 2.5em;";
1326  $collapse = "<div class=\"collapse\" id=\"replyBox\"><blockquote>";
1327  $collapseFooter = "</blockquote></div>";
1328  }
1329  }
1330  else
1331  {
1332  // get parent items from db
1333  $sql_replies = $db->query("SELECT * FROM {blog_comments} WHERE parentID = '" . $comment_id . "' AND published = '1'");
1334  while ($row = mysqli_fetch_assoc($sql_replies))
1335  {
1336  $comment_replies++;
1337  }
1338  $collapse = "<div class=\"collapse\" id=\"replyBox\"><blockquote>";
1339  $collapseFooter = "</blockquote></div>";
1340  // draw reply link with i comments
1341  $reply_link = "<small><a href=\"#replyBox\" data-toggle=\"collapse\" aria-expanded=\"true\" aria-controls=\"replyBox\" class=\"pull-right small\"><i>Kommentare ($comment_replies) </i><i class=\"fa fa-chevron-down\"></i></a></small>";
1342  }
1343 
1344  // if there is no user id (uid) or group id (gid)...
1345  if ($uid === '0' || $gid === '0')
1346  {
1347  // this is a GUEST COMMENT
1348  // check if comment got an email adress and set link color
1349  if (!empty($email))
1350  {
1351  $emailLink = "<a href=\"mailto:$email\" class=\"text-black\">$name</a>";
1352  }
1353  else
1354  {
1355  $emailLink = "<span class=\"text-grey\">$name</span>";
1356  }
1357 
1358  // draw guest comments
1359  // $this->html .= $collapse;
1360  $this->html .= "<p><i><h5><strong>" . $emailLink . "</strong> <small>am " . $prettydate . "</small></h5></i>" . $comment . "
1361  </p><hr>";
1362  // $reply_link </p><hr></div>";
1363  // $this->html .= "<p><i><h5>".$indent."<strong>".$emailLink."</strong> <small>am " . $prettydate . "</small></h5></i><div style=\"$padding\">".$comment."</div>
1364  // $this->html .= "$reply_link</p><hr>";
1365  }
1366  else // uid or gid value is not zero...
1367  {
1368  // which means this is a REGISTERED USER COMMENT
1369  // check if comment got an email and set link color
1370  if (!empty($email)) {
1371  $emailLink = "<a href=\"mailto:$email\">$name</a>";
1372  } else {
1373  $emailLink = "<span>$name</span>";
1374  }
1375  // get username for given uid
1376  $sql2 = $db->query("SELECT username FROM {users} WHERE id = '" . $uid . "'");
1377  while ($row2 = mysqli_fetch_row($sql2)) {
1378  // draw user comments
1379  // $this->html .= $collapse;
1380  $this->html .= "<p<i><h5><strong>" . $emailLink . "</strong> &nbsp;<small>am " . $prettydate . "</small></h5></i>" . $comment . "
1381  </p><hr>";
1382  // $reply_link</p><hr>";
1383  }
1384  }
1385  } // end while fetch comments
1386  }
1387  else // unable to query blog comments
1388  { // q failed
1389  $this->html = 'Failed to query comments database.';
1390  }
1391  $this->html .= "</div>";
1392  return null;
1393  }
1394 
1395 
1396  /**
1397  * @brief Count and returns all active comments. If no result is found, false will be returned.
1398  * @author Daniel Retzl <[email protected]>
1399  * @version 1.0.0
1400  * @param object $db Database Object
1401  * @param int $blogid The blog ID to count comments from
1402  * @param int $itemid The item ID to count comments from
1403  * @return mixed bool
1404  */
1405  static function countActiveComments($db, $blogid, $itemid)
1406  {
1407  /** @var $db \YAWK\db */
1408  if ($res = $db->query("SELECT COUNT(id) FROM {blog_comments}
1409  WHERE blogid = " . $blogid . "
1410  AND itemid=" . $itemid . " AND published = '1' ")
1411  ) { // fetch data
1412  $result = mysqli_fetch_row($res);
1413  return $result[0];
1414  } else {
1415  return false;
1416  }
1417  }
1418 
1419 
1420  /**
1421  * @brief Draw comments box
1422  * @author Daniel Retzl <[email protected]>
1423  * @version 1.0.0
1424  * @param object $db Database Object
1425  * @return null
1426  */
1427  function draw_commentbox($db)
1428  { /** @var $db \YAWK\db */
1429  // check if user is logged in
1430  if (isset($_SESSION['logged_in']) && ($_SESSION['logged_in'] == true)) {
1431  // check if uid and gid is set
1432  if (isset($_SESSION['uid']) && (isset($_SESSION['gid']))) {
1433  if (isset($_SESSION['username'])) {
1434  $username = $_SESSION['username'];
1435  }
1436  else
1437  {
1438  $username = "";
1439  }
1440  $hidden_uid = $_SESSION['uid'];
1441  $hidden_gid = $_SESSION['gid'];
1442  $i = self::countActiveComments($db, $this->blogid, $this->itemid);
1443  $this->html .= "
1444  <div class=\"row\">
1445  <div id=\"comments\" class=\"col-md-8\">
1446  <h4>Comments, please! <!-- <small>Give your mustard (:</small> --></h4>
1447  <div class=\"form-group\">
1448  <input class=\"form-control\" type=\"text\" id=\"nameplaceholder\" disabled title=\"Du bist als $username eingeloggt.\" placeholder=\"$username &nbsp;[Du bist eingeloggt]\">
1449  <textarea class=\"form-control\" id=\"comment\" placeholder=\"Deine Nachricht \" rows=\"3\"></textarea>
1450  <input type=\"button\" class=\"btn btn-success\" id=\"submit_post\" name=\"save_comment\" value=\"absenden\" style=\"\">
1451  <input type=\"hidden\" id=\"uid\" name=\"uid\" value=\"" . $hidden_uid . "\">
1452  <input type=\"hidden\" id=\"gid\" name=\"gid\" value=\"" . $hidden_gid . "\">
1453  <input type=\"hidden\" id=\"itemid\" name=\"itemid\" value=\"" . $this->itemid . "\">
1454  <input type=\"hidden\" id=\"blogid\" name=\"blogid\" value=\"" . $this->blogid . "\">
1455  <input type=\"hidden\" id=\"name\" name=\"name\" value=\"$username\">
1456  </div>";
1457 
1458  $this->html .= self::getComments($db, $this->blogid, $this->itemid);
1459  $this->html .= "</div>
1460  <div class=\"col-md-4 mx-auto d-block\">";
1461  $this->html .= self::drawVotingBox($db, $this->voteUp, $this->voteDown);
1462  $this->html .= "</div>
1463  </div>";
1464 
1465 
1466  } // session uid or gid is empty, user is not logged in correctly
1467  else
1468  {
1469  echo \YAWK\alert::draw("danger", "Error!", "Cannot detect User Status. Obviously you are not correctly logged-in. Please try to re-login.", "", "4200");
1470  exit;
1471  }
1472  }
1473  else
1474  {
1475  // user is not logged in
1476  $hidden_uid = 0;
1477  $hidden_gid = 0;
1478  $i = self::countActiveComments($db, $this->blogid, $this->itemid);
1479  $this->html .= "
1480  <div class=\"row\">
1481  <div id=\"comments\" class=\"col-md-8\">
1482  <h4>Comments, please! <!-- <small>Give your mustard (:</small> --></h4>
1483  <div class=\"form-group\">
1484  <input type=\"text\" name=\"name\" id=\"name\" class=\"form-control\" placeholder=\"Dein Name\">
1485  <input type=\"text\" name=\"email\" id=\"email\" class=\"form-control\" placeholder=\"Emailadresse &nbsp;[optional]\">
1486  <textarea class=\"form-control\" id=\"comment\" placeholder=\"Deine Nachricht \" rows=\"3\"></textarea>
1487  <input type=\"button\" class=\"btn btn-success\" id=\"submit_post\" name=\"save_comment\" value=\"absenden\" style=\"\">
1488  <input type=\"hidden\" id=\"uid\" name=\"uid\" value=\"" . $hidden_uid . "\">
1489  <input type=\"hidden\" id=\"gid\" name=\"gid\" value=\"" . $hidden_gid . "\">
1490  <input type=\"hidden\" id=\"itemid\" name=\"itemid\" value=\"" . $this->itemid . "\">
1491  <input type=\"hidden\" id=\"blogid\" name=\"blogid\" value=\"" . $this->blogid . "\">
1492  </div>";
1493  $this->html .= self::getComments($db, $this->blogid, $this->itemid);
1494  $this->html .= "</div>
1495  <div class=\"col-md-4 mx-auto d-block\">";
1496  $this->html .= self::drawVotingBox($db, $this->voteUp, $this->voteDown);
1497  $this->html .= "</div>
1498  </div>";
1499 
1500  }
1501  return null;
1502  }
1503 
1504  /**
1505  * @brief @brief Get Property of any blog item
1506  * @param object $db Database Object
1507  * @param int $blogid The blog ID to get data from
1508  * @param int $itemid The item ID to get data from
1509  * @param string $property The property you like to get
1510  * @return mixed bool
1511  */
1512  function getItemProperty($db, $blogid, $itemid, $property)
1513  {
1514  /** @var $db \YAWK\db $sql */
1515  if ($res = $db->query("SELECT " . $property . " WHERE id = '" . $itemid . " AND blogid = '" . $blogid . "'")) { // fetch data
1516  while ($row = mysqli_fetch_row($res)) { // success
1517  return $row[0];
1518  }
1519  } else { // q failed
1520  return false;
1521  }
1522  return null;
1523  }
1524 
1525 
1526  /**
1527  * @brief @brief Delete a whole blog, including its contents, all entries, comments and pages.
1528  * @param object $db Database Object
1529  * @param int $blogid The blog ID to delete
1530  * @return bool
1531  */
1532  function delete($db, $blogid)
1533  {
1534  /** @var $db \YAWK\db */
1535  if ($res = $db->query("SELECT alias FROM {pages} WHERE blogid = '" . $blogid . "'")) { // get file alias from page table
1536 
1537  while ($row = mysqli_fetch_row($res)) {
1538  // unlink file
1539  $alias = $row[0];
1540  $filename = "../content/pages/" . $alias . ".php";
1541  if (file_exists($filename)) { // delete file
1542  if (unlink($filename)) {
1543  \YAWK\alert::draw("success", "Success!", "Blog file $filename deleted.", "", 2800);
1544  }
1545  else
1546  {
1547  \YAWK\alert::draw("danger", "Could not delete file!", "Blog file $filename not deleted.", "", 6800);
1548  }
1549  }
1550  else
1551  {
1552  \YAWK\alert::draw("warning", "Could not find file", "$filename", "", 12800);
1553  }
1554  }
1555  if (!isset($filename)){ $filename = ''; }
1556  if ($db->query("DELETE FROM {pages} WHERE blogid = '" . $blogid . "'")) {
1557  \YAWK\alert::draw("success", "Deleted Blog", "Blog $filename deleted successfully.", "", 2800);
1558  }
1559  }
1560  else
1561  {
1562  \YAWK\alert::draw("danger", "Could not get alias from pages!", "File could not be deleted.", "", 5800);
1563  }
1564  if ($res = $db->query("DELETE FROM {menu} WHERE blogid = '" . $blogid . "'")) { // delete menu entry
1565  \YAWK\alert::draw("success", "Success!", "Menu Entry deleted.", "", "2000");
1566  }
1567  if ($res = $db->query("DELETE FROM {blog} WHERE id = '" . $blogid . "'")) { // delete blog itself
1568  \YAWK\alert::draw("success", "Success!", "Blog deleted.", "", "2200");
1569  }
1570  if ($res = $db->query("DELETE FROM {blog_items} WHERE blogid = '" . $blogid . "'")) { // delete blog items (entries)
1571  \YAWK\alert::draw("success", "Success!", "Blog Item deleted.", "", "2400");
1572  }
1573  if ($res = $db->query("DELETE FROM {blog_comments} WHERE blogid = '" . $blogid . "'")) { // delete blog comments
1574  \YAWK\alert::draw("success", "Success!", "Blog Comments deleted.", "", "2600");
1575  }
1576  return true;
1577  }
1578 
1579  /**
1580  * @brief @brief Delete any blog item
1581  * @param object $db Database Object
1582  * @param int $blogid The blog ID to delete
1583  * @param int $itemid The item ID to delete
1584  * @param int $pageid The page ID to delete
1585  * @return bool
1586  */
1587  function deleteItem($db, $blogid, $itemid, $pageid)
1588  {
1589  /** @var $db \YAWK\db */
1590  if ($res = $db->query("SELECT alias FROM {pages} WHERE id = '" . $pageid . "'")) { // GET ALIAS FROM PAGE ID TO GET THE FILENAME FOR UNLINK (see below)
1591  if ($row = mysqli_fetch_array($res)) { // get page alias
1592  $alias = $row['alias'];
1593  // remove page data from db
1594  if ($res = $db->query("DELETE FROM {pages} WHERE id = '" . $pageid . "'")) { // build filename to delete
1595  $filename = "../content/pages/" . $alias . ".php";
1596  if (file_exists($filename)) { // delete file
1597  unlink($filename);
1598  if ($res = $db->query("DELETE FROM {blog_items} WHERE blogid = '" . $blogid . "' AND id = '" . $itemid . "'")) { // blog item deleted from database
1599  \YAWK\alert::draw("success", "Blog item deleted ", "Blog item deleted from database!", "", "2200");
1600  }
1601  if ($res = $db->query("DELETE FROM {blog_comments} WHERE blogid = '" . $blogid . "' AND itemid = '" . $itemid . "'")) { // blog comments removed from db
1602  \YAWK\alert::draw("success", "Blog comments deleted", "Blog comments deleted from database!", "", "2200");
1603  }
1604  } else { // could not delete file, throw error
1605  // \YAWK\alert::draw("danger", "Error: ", "Could not delete $filename", "", "3800");
1606  return false;
1607  }
1608  } else { // delete failed, throw error
1609  // \YAWK\alert::draw("warning", "Error: ", "Could not delete item from database", "", "3800");
1610  return false;
1611  }
1612  } else { // fetch failed, throw error
1613  // \YAWK\alert::draw("danger", "Error: ", "Could not fetch alias from pages database.", "", "3800");
1614  return false;
1615  }
1616  } else { // q failed
1617  // \YAWK\alert::draw("danger", "Error: ", "Could not query alias from pages database.", "", "3800");
1618  return false;
1619  }
1620  return true;
1621  }
1622 
1623  /**
1624  * @brief @brief Delete any blog comment
1625  * @param object $db Database Object
1626  * @param int $blogid The blog ID to delete
1627  * @param int $itemid The item ID to delete
1628  * @param int $commentidid The page ID to delete
1629  * @return bool
1630  */
1631  function deleteComment($db, $blogid, $itemid, $commentid)
1632  {
1633  /** @var $db \YAWK\db */
1634  if ($res = $db->query("DELETE FROM {blog_comments} WHERE blogid = '" . $blogid . "' AND itemid = '" . $itemid . "' AND id = '" . $commentid . "'")) { // single comment removed from database
1635  \YAWK\alert::draw("success", "Success!", "Comment deleted from database!", "", "2000");
1636  return true;
1637  } else { // delete failed
1638  return false;
1639  }
1640  }
1641 
1642  /**
1643  * @brief @brief Create a new blog
1644  * @param object $db Database Object
1645  * @param string $name The name of the new blog
1646  * @param string $description What is this blog all about?
1647  * @param int $menuID Menu ID to which an entry will be added
1648  * @param string $icon Any font awesome icon to identify the blog e.g fa fa-globe
1649  * @return bool
1650  */
1651  function create($db, $name, $description, $menuID, $icon)
1652  {
1653  /** @var $db \YAWK\db */
1654  /* generate ID manually to prevent id holes */
1655 
1656  $published = 1;
1657  $name = htmlentities($name);
1658  $description = htmlentities($description);
1659  $name = $db->quote($name);
1660  $description = $db->quote($description);
1661  $locked = 1;
1662 
1663  // add new blog into database
1664  if ($db->query("INSERT INTO {blog} (sort, published, name, description, icon)
1665  VALUES(1,
1666  '" . $published . "',
1667  '" . $name . "',
1668  '" . $description . "',
1669  '" . $icon . "')"))
1670  {
1671  // get ID of this blog; we need the blogID to assign it correctly to the static page afterwards
1672  if (!$res_blog = $db->query("SELECT MAX(id), MAX(sort) FROM {blog}"))
1673  { // this is the first blog
1674  $blogId = 1;
1675  }
1676  else
1677  { // fetch data and set blogID
1678  $row = mysqli_fetch_row($res_blog);
1679  if (!isset($row[0])) {
1680  $blogId = 1;
1681  } else {
1682  $blogId = $row[0]++;
1683  }
1684  }
1685 
1686  if ($row = $db->query("SELECT blogid FROM {pages} WHERE blogid = '" . $blogId . "' LIMIT 1"))
1687  {
1688  $res = mysqli_fetch_row($row);
1689  } else { $res = null; }
1690  if ($res != $blogId)
1691  {
1692  // create blog page
1693  if (!isset($page))
1694  { // create new page object
1695  $page = new \YAWK\page();
1696  }
1697  if ($page->create($db, $name, $menuID, $locked, $blogId, 0) === true)
1698  { // success
1699  return true;
1700  }
1701  else
1702  { // create page failed, throw error...
1703  \YAWK\alert::draw("danger", "Error: ", "Could not create blog page! Please enter all fields.", "", "2200");
1704  return false;
1705  }
1706  }
1707 
1708  }
1709  else
1710  { // q failed
1711  \YAWK\alert::draw("danger", "Error: ", "Could not create blog page database entry - please try it again.", "", "3800");
1712  return false;
1713  }
1714  }
1715 
1716 
1717  /**
1718  * @brief @brief Create a new blog item
1719  * @param object $db Database Object
1720  * @param int $blogid Blog id to which the entry should be added
1721  * @param string $title Title of the new blog
1722  * @param string $subtitle SubTitle of the new blog
1723  * @param string $teasertext Teaser text as intro with (read more) link afterwards
1724  * @param string $blogtext The blog main story text
1725  * @param string $date_publish Publishing date in mysql datetime format yyyy-mm-dd 00:00:00
1726  * @param string $date_unpublish UnPublishing date in mysql datetime format yyyy-mm-dd 00:00:00
1727  * @param string $thumbnail Any preview image. Will be displayed beneath the teasertext.
1728  * @param string $youtubeUrl Any YouTube URL to display video if video layout is selected
1729  * @param string $weblink Any URL (external Link, related information)
1730  * @return bool
1731  */
1732  function createItem($db, $blogid, $title, $subtitle, $published, $teasertext, $blogtext, $date_publish, $date_unpublish, $thumbnail, $youtubeUrl, $weblink, $meta_local, $meta_keywords)
1733  {
1734  /** @var $db \YAWK\db */
1735 
1736  $date_created = date("Y-m-d G:i:s");
1737  $alias = $title;
1738  /* alias string manipulation to generate a valid filename */
1739  $alias = mb_strtolower($alias); // lowercase
1740  $alias = str_replace(" ", "-", $alias); // replace all ' ' with -
1741  // special chars
1742  $umlaute = array("/ä/", "/ü/", "/ö/", "/Ä/", "/Ãœ/", "/Ö/", "/ß/"); // array of special chars
1743  $ersetze = array("ae", "ue", "oe", "ae", "ue", "oe", "ss"); // array of replacement chars
1744  $alias = preg_replace($umlaute, $ersetze, $alias); // replace with preg
1745  $alias = preg_replace("/[^a-z0-9\-\/]/i", "", $alias); // final check: just numbers and chars are allowed
1746 
1747  // ## select max id from pages
1748  if ($res = $db->query("SELECT MAX(id) FROM {pages}"))
1749  {
1750  $row = mysqli_fetch_row($res);
1751  $page_id = $row[0] + 1;
1752  $locked = 1;
1753  // ## add new page to db pages
1754  // convert html special chars
1755  $title = htmlentities($title);
1756  if (!$res = $db->query("INSERT INTO {pages} (id,published,date_created,date_publish,alias,title,locked,blogid,meta_local,meta_keywords)
1757  VALUES ('" . $page_id . "',
1758  '" . $published . "',
1759  '" . $date_created . "',
1760  '" . $date_created . "',
1761  '" . $alias . "',
1762  '" . $title . "',
1763  '" . $locked . "',
1764  '" . $this->blogid . "',
1765  '" . $this->meta_local . "',
1766  '" . $this->meta_keywords . "')")
1767  ) { // q insert page into database failed
1768  // \YAWK\alert::draw("danger", "Error: ", "Could not insert blog page into database.", "", "3800");
1769  \YAWK\sys::setSyslog($db, 7, 1, "failed to insert blog page $alias into database", 0, 0, 0, 0);
1770  return false;
1771  }
1772  else
1773  {
1774  /* generate ID manually to prevent id holes */
1775  if ($res_blog = $db->query("SELECT MAX(id), MAX(sort) FROM {blog_items}"))
1776  { // add ID
1777  $row = mysqli_fetch_row($res_blog);
1778  if (empty($row[0]))
1779  {
1780  $row[0] = 1;
1781  $id = $row[0] + 1;
1782  }
1783  if (empty($row[1]))
1784  {
1785  $row[1] = 1;
1786  $sort = $row[1] + 1;
1787  }
1788  $id = $row[0] + 1;
1789  $sort = $row[1] + 1;
1790  }
1791 
1792  // convert html special chars
1793  $subtitle = htmlentities($subtitle);
1794 
1795  // convert html special chars
1796  $this->teasertext = \YAWK\sys::encodeChars($this->teasertext);
1797  $this->blogtext = \YAWK\sys::encodeChars($this->blogtext);
1798 
1799  if ($date_unpublish == "0000-00-00 00:00:00" || (empty($date_unpublish)))
1800  {
1801  // sql code for zero date - insert NULL instead
1802  $res = $db->query("INSERT INTO {blog_items}
1803  (blogid,id,uid,pageid,sort,published,title,filename,subtitle,date_created,date_publish,date_unpublish,teasertext,blogtext,thumbnail,youtubeUrl,author,weblink)
1804  VALUES('" . $this->blogid . "',
1805  '" . $id . "',
1806  '" . $_SESSION['uid'] . "',
1807  '" . $page_id . "',
1808  '" . $sort . "',
1809  '" . $published . "',
1810  '" . $title . "',
1811  '" . $alias . "',
1812  '" . $subtitle . "',
1813  '" . $date_created . "',
1814  '" . $date_publish . "',
1815  NULL,
1816  '" . $teasertext . "',
1817  '" . $blogtext . "',
1818  '" . $thumbnail . "',
1819  '" . $youtubeUrl . "',
1820  '" . $_SESSION['username'] . "',
1821  '" . $weblink . "')");
1822  }
1823  else
1824  {
1825  // sql code for zero date - insert NULL instead
1826  $res = $db->query("INSERT INTO {blog_items}
1827  (blogid,id,uid,pageid,sort,published,title,filename,subtitle,date_created,date_publish,date_unpublish,teasertext,blogtext,thumbnail,youtubeUrl,author,weblink)
1828  VALUES('" . $this->blogid . "',
1829  '" . $id . "',
1830  '" . $_SESSION['uid'] . "',
1831  '" . $page_id . "',
1832  '" . $sort . "',
1833  '" . $published . "',
1834  '" . $title . "',
1835  '" . $alias . "',
1836  '" . $subtitle . "',
1837  '" . $date_created . "',
1838  '" . $date_publish . "',
1839  '" . $date_unpublish . "',
1840  '" . $teasertext . "',
1841  '" . $blogtext . "',
1842  '" . $thumbnail . "',
1843  '" . $youtubeUrl . "',
1844  '" . $_SESSION['username'] . "',
1845  '" . $weblink . "')");
1846  }
1847 
1848  if ($res === true)
1849  {
1850  // define content of file
1851  $content = "<?php \$blog_id = $blogid; \$item_id = $id; \$full_view = 1; include 'system/plugins/blog/blog.php'; ?>";
1852  // prepare file
1853  $filename = "../content/pages/" . $alias . ".php";
1854  if (!file_exists($filename)) { // create file if not exist
1855  $handle = fopen($filename, "wr");
1856  $res = fwrite($handle, $content);
1857  fclose($handle);
1858  chmod($filename, 0777);
1859  }
1860  } // ./ end insert blog item
1861  else { // insert blog item failed
1862  // \YAWK\alert::draw("danger", "Error: ", "Could not insert blog item into database!", "", "3800");
1863  \YAWK\sys::setSyslog($db, 7, 1, "failed to insert blog item to db, affected: ID: $id \"$alias\" into blog ID: $blogid", 0, 0, 0, 0);
1864  }
1865  } // ./ end insert blog page
1866  } // ./ end select MAXid
1867  else { // q failed (getMAX id)
1868  // \YAWK\alert::draw("danger", "Error: ", "Could not get MAX id from pages database.", "", "3800");
1869  \YAWK\sys::setSyslog($db, 7, 1, "failed to get MAX ID from pages database", 0, 0, 0, 0);
1870  return false;
1871  }
1872  return true;
1873  }
1874 
1875  /**
1876  * @brief @brief Copy a single blog entry
1877  * @param object $db Database Object
1878  * @return bool
1879  */
1880  function copyItem($db)
1881  {
1882  /** @var $db \YAWK\db */
1883  $gid = "$this->itemgid";
1884  $alias = "$this->filename-kopie";
1885  $title_new = "$this->filename-kopie";
1886  $this->blogtitle = $this->blogtitle."-KOPIE";
1887  $date_created = date("Y-m-d G:i:s");
1888 
1889  if (!$this->alias)
1890  { // if no page name is given
1891  \YAWK\alert::draw("warning", "Warning: ", "Alias not set. Please reload the page and try again.", "","5600");
1892  }
1893  // select max id from pages
1894  if (!$res = $db->query("SELECT MAX(id) FROM {pages}"))
1895  { // q failed
1896  \YAWK\alert::draw("warning", "Warning: ", "Cannot get MAX id from pages database.", "","3600");
1897  }
1898  else
1899  { // fetch data & prepare vars
1900  $row = mysqli_fetch_row($res);
1901  $pageid = $row[0] + 1;
1902  $locked = 1;
1903  $published = 1;
1904  }
1905 
1906  // ## add new page to db pages
1907  if ($res = $db->query("INSERT INTO {pages} (id,gid,published,date_created,date_publish,alias,title,locked,blogid,meta_local,meta_keywords)
1908  VALUES ('" . $pageid . "',
1909  '" . $gid . "',
1910  '" . $published . "',
1911  '" . $date_created . "',
1912  '" . $date_created . "',
1913  '" . $alias . "',
1914  '" . $this->blogtitle . "',
1915  '" . $locked . "',
1916  '" . $this->blogid . "',
1917  '" . $this->meta_local . "',
1918  '" . $this->meta_keywords . "')"))
1919  { // select max id from blog_items
1920  if ($res = $db->query("SELECT MAX(id) FROM {blog_items}"))
1921  { // fetch data and prepare ID
1922  $row = mysqli_fetch_row($res);
1923  $id = $row[0] + 1;
1924  }
1925 
1926  if ($this->date_unpublish == "0000-00-00 00:00:00" || (empty($this->date_unpublish)))
1927  {
1928  // add new entry to blog_items with date_unpublish ZERO value
1929  if ($res = $db->query("INSERT INTO {blog_items} (blogid,id,uid,pageid,sort,published,itemgid,title,filename,subtitle,date_created,date_changed,date_publish,date_unpublish,teasertext,blogtext,author,youtubeUrl,weblink, thumbnail)
1930  VALUES ('" . $this->blogid . "',
1931  '" . $id . "',
1932  '" . $this->uid . "',
1933  '" . $pageid . "',
1934  '" . $this->sort . "',
1935  '" . $this->published . "',
1936  '" . $this->itemgid . "',
1937  '" . $this->blogtitle . "',
1938  '" . $alias . "',
1939  '" . $this->subtitle . "',
1940  '" . $this->date_created . "',
1941  '" . $this->date_changed . "',
1942  '" . $this->date_publish . "',
1943  NULL,
1944  '" . $this->teasertext . "',
1945  '" . $this->blogtext . "',
1946  '" . $this->author . "',
1947  '" . $this->youtubeUrl . "',
1948  '" . $this->weblink . "',
1949  '" . $this->thumbnail . "')"))
1950  { // blog items inserted into database
1951  // generate local meta tags
1952  $desc = "description";
1953  $keyw = "keywords";
1954  $words = "";
1955  // insert local meta description to db meta_local
1956  if (!$res = $db->query("INSERT INTO {meta_local} (name,page,content)
1957  VALUES ('" . $desc . "', '" . $id . "', '" . $this->blogtitle . "')"))
1958  { // inset local meta description failed
1959  // \YAWK\alert::draw("warning", "Warning: ", "Could not store meta description.", "", "3800");
1960  }
1961  if (!$res = $db->query("INSERT INTO {meta_local} (name,page,content)
1962  VALUES ('" . $keyw . "','" . $id . "','" . $words . "')"))
1963  { // insert local meta keywords
1964  // \YAWK\alert::draw("warning", "Warning: ", "Could not store meta description.", "", "3800");
1965  }
1966  // prepare loading page content
1967  $content = "<?php \$blog_id = $this->blogid; \$item_id = $id; \$full_view = 1; include 'system/plugins/blog/blog.php'; ?>";
1968  // prepare file
1969  $filename = "../content/pages/" . $alias . ".php";
1970  $handle = fopen($filename, "wr");
1971  if (fwrite($handle, $content))
1972  { // create file
1973  fclose($handle);
1974  chmod($filename, 0777);
1975  }
1976  else
1977  { // could not create file, throw error
1978  \YAWK\alert::draw("error", "Error: ", "Could not create loading file $filename", "", "3800");
1979  }
1980  }
1981  else
1982  { // insert blog item failed,
1983  \YAWK\alert::draw("danger", "Error: ", "Insert Blog item failed.", "","3600");
1984  return false;
1985  }
1986  }
1987  else
1988  { // add new entry to db blog_items WITH correct unpublish date
1989  if ($res = $db->query("INSERT INTO {blog_items} (blogid,id,uid,pageid,sort,published,itemgid,title,filename,subtitle,date_created,date_changed,date_publish,date_unpublish,teasertext,blogtext,author,youtubeUrl,weblink,thumbnail)
1990  VALUES ('" . $this->blogid . "',
1991  '" . $id . "',
1992  '" . $this->uid . "',
1993  '" . $pageid . "',
1994  '" . $this->sort . "',
1995  '" . $this->published . "',
1996  '" . $this->itemgid . "',
1997  '" . $this->blogtitle . "',
1998  '" . $alias . "',
1999  '" . $this->subtitle . "',
2000  '" . $this->date_created . "',
2001  '" . $this->date_changed . "',
2002  '" . $this->date_publish . "',
2003  '" . $this->date_unpublish . "',
2004  '" . $this->teasertext . "',
2005  '" . $this->blogtext . "',
2006  '" . $this->author . "',
2007  '" . $this->youtubeUrl . "',
2008  '" . $this->weblink . "',
2009  '" . $this->thumbnail . "')"))
2010  { // blog items inserted into database
2011 
2012  // prepare loading page content
2013  $content = "<?php \$blog_id = $this->blogid; \$item_id = $id; \$full_view = 1; include 'system/plugins/blog/blog.php'; ?>";
2014  // prepare file
2015  $filename = "../content/pages/" . $alias . ".php";
2016  $handle = fopen($filename, "wr");
2017  if (fwrite($handle, $content))
2018  { // create file
2019  fclose($handle);
2020  chmod($filename, 0777);
2021  }
2022  else
2023  { // could not create file, throw error
2024  \YAWK\alert::draw("error", "Error: ", "Could not create loading file $filename", "", "3800");
2025  }
2026  }
2027  else
2028  { // insert blog item failed,
2029  \YAWK\alert::draw("danger", "Error: ", "Insert Blog item failed.", "","3600");
2030  return false;
2031  }
2032  }
2033 
2034  }
2035  else
2036  { // insert item into pages db failed,
2037  \YAWK\alert::draw("danger", "Error: ", "Insert pages database failed.", "","3600");
2038  return false;
2039  }
2040  // all good,
2041  return true;
2042  } // ./ end function copy item
2043 
2044  } // ./ end class blog
2045 } // ./ end namespace
if(!isset($db)) $uid
$filename
Definition: actions.php:10
$comment
Definition: add-comment.php:10
$name
Definition: add-comment.php:11
$blogid
Definition: add-comment.php:5
$itemid
Definition: add-comment.php:6
$blog
Definition: blog.php:122
print $lang['BLOG_ADD']
Definition: blog.php:91
$blog icon
print $blog teasertext
Definition: blog-edit.php:712
print $blog pageid
Definition: blog-edit.php:711
print $blog youtubeUrl
Definition: blog-edit.php:594
print $blog blogid
Definition: blog-edit.php:376
print $blog itemid
Definition: blog-edit.php:376
$blog layout
Definition: blog-edit.php:370
print $blog blogtext
Definition: blog-edit.php:410
print $blog blogtitle
Definition: blog-edit.php:386
print $blog thumbnail
Definition: blog-edit.php:583
$blog comments
$blog description
Definition: blog-setup.php:49
$blog showTitle
Definition: blog-setup.php:156
$blog showAuthor
Definition: blog-setup.php:133
$blog spacer
Definition: blog-setup.php:142
$blog frontendIcon
Definition: blog-setup.php:143
$blog showTotalVotes
Definition: blog-setup.php:145
$blog sequence
Definition: blog-setup.php:134
$blog voting
Definition: blog-setup.php:141
$blog showDesc
Definition: blog-setup.php:131
$blog preview
Definition: blog-setup.php:140
$blog gid
Definition: blog-setup.php:139
$blog showDate
Definition: blog-setup.php:132
$blog permaLink
Definition: blog-setup.php:137
$blog sortation
Definition: blog-setup.php:135
if(!isset($blog)) if(!isset($language)||(!isset($lang))) if(!isset($db)) $blog published
Definition: blog-toggle.php:17
static draw($type, $title, $text, $redirect, $delay)
Definition: alert.php:30
static getMetaTags($db, $id, $type)
get and return meta tags for requested page
Definition: page.php:95
static getSetting($db, $property)
Get and return value for property from settings database.
Definition: settings.php:470
static splitDate($date)
split a date to month, day, year and time
Definition: sys.php:1502
static getWeekday($date, $lang)
return weekday from given date
Definition: sys.php:1735
static encodeChars($string)
convert german special chars and vowels into legal html
Definition: sys.php:1089
if(!isset($db)) $id
$result
Definition: email-send.php:137
$subtext
Definition: jplayer.php:19
exit
$sql
Definition: message-new.php:32
print $page date_publish
Definition: page-edit.php:442
print $page meta_local
Definition: page-edit.php:489
print $page meta_keywords
Definition: page-edit.php:512
$page alias
Definition: page-edit.php:68
$host
Definition: page-edit.php:65
print $page title
Definition: page-edit.php:377
print $page date_unpublish
Definition: page-edit.php:448
$page
Definition: pages.php:355
if(isset($_POST['sent'])) $layout
Definition: signup.php:98
$template name
print $tourdates date
$date
Definition: user-edit.php:285
$gid
Definition: user-new.php:104
$email
Definition: user-new.php:94
$voteDown
Definition: vote-down.php:6
$voteUp
Definition: vote-up.php:6
$i