YaWK  24.1
Yet another WebKit
YAWK\page Class Reference

The default pages class. Provide all functions to handle static pages. More...

Public Member Functions

 copy ($db)
 make a copy of a page More...
 
 create ($db, $alias, $menuID, $locked, $blogid, $plugin)
 create a new page More...
 
 delete ($db)
 delete a page More...
 
 deleteContent ($dirprefix)
 delete a static content page More...
 
 getContent ($db, $lang)
 get and include static page content More...
 
 getCurrentLanguageByID ($db, $id)
 
 getProperty ($db, $id, $property)
 get any requested page property More...
 
 loadProperties ($db, $alias)
 load page properties and store as object properties More...
 
 loadPropertiesByID ($db, $id)
 load page properties and store as object properties More...
 
 readContent ($dirPrefix)
 read content from static page More...
 
 save ($db)
 save a static page including all settings More...
 
 toggleLock ($db, $id, $locked)
 toggle page lock to avoid unintended changes More...
 
 toggleOffline ($db, $id, $published, $title)
 toggle page status online or offline (plus corresponding menu entries) More...
 
 writeContent ($content)
 write content to static page More...
 

Static Public Member Functions

static countPages ($db)
 count and return the pages in database More...
 
static getLatest ($db, $limit)
 get latest pages More...
 
static getMetaTags ($db, $id, $type)
 get and return meta tags for requested page More...
 
static getMetaTagsArray ($db, $id)
 get and return meta tags of requested page as array More...
 

Public Attributes

 $alias = ''
 
 $alias_new = ''
 
 $bgimage
 
 $blogid
 
 $date_created
 
 $date_publish
 
 $date_unpublish
 
 $gid
 
 $id = -1
 
 $language
 
 $locked
 
 $menu = -1
 
 $meta_keywords = "Meta Tag Keywords"
 
 $meta_local = "Meta Tag Description"
 
 $metadescription
 
 $metakeywords
 
 $newLanguage
 
 $ownerid = -1
 
 $path = "../content/pages/"
 
 $plugin
 
 $published = 0
 
 $searchstring
 
 $title = ''
 
 $title_new = ''
 

Detailed Description

The default pages class. Provide all functions to handle static pages.

The default pages class. Provide all functions to handle static html pages.

All functions that are required to handle a page. Methods are: create, save, edit, delete and many more.

Class covers both, backend & frontend functionality. See Methods Summary for Details!

Author
Daniel Retzl danie.nosp@m.lret.nosp@m.zl@gm.nosp@m.ail..nosp@m.com
Version
1.0.0

Definition at line 19 of file page.php.

Member Function Documentation

◆ copy()

YAWK\page::copy (   $db)

make a copy of a page

Parameters
object$dbdatabase
Returns
bool
Parameters
$dbdb

Definition at line 265 of file page.php.

266  {
267  /** @param $db db */
268  // creation date
269  $currentDateTime = date("Y-m-d G:i:s");
270 
271 
272  // init helper vars for copy processing
273  $page = '';
274  $newPage = '';
275 
276  // if page name is not given
277  if (!$this->alias) {
278  return false;
279  }
280  // ## select max id from pages
281  if ($res = $db->query("SELECT MAX(id) FROM {pages}"))
282  {
283  $row = mysqli_fetch_row($res);
284  $this->id = $row[0] + 1;
285  }
286  else
287  {
288  sys::setSyslog($db, 7, 1, "could not fetch MAX(id) of pages database", 0, 0, 0, 0);
289  die ("Sorry, database error: could not fetch MAX(id).");
290  }
291 
292  $this->id++;
293 
294  // ## add new page to db pages
295  if ($result = $db->query("INSERT INTO {pages} (id,gid,date_created,date_publish,alias,title,blogid,locked,lang,meta_local,meta_keywords,plugin)
296  VALUES ('" . $this->id . "',
297  '" . $this->gid . "',
298  '" . $currentDateTime . "',
299  '" . $currentDateTime . "',
300  '" . $this->alias.'-copy'."',
301  '" . $this->title .'-copy'."',
302  '" . $this->blogid . "',
303  '" . $this->locked . "',
304  '" . $this->language . "',
305  '" . $this->meta_local . "',
306  '" . $this->meta_keywords . "',
307  '" . $this->plugin . "')"))
308  {
309  /* TODO: COPY META TAGS when COPY PAGE
310  // generate local meta tags
311  $desc = "description";
312  $keyw = "keywords";
313  $words = "";
314  // add local meta tags
315  if (!$db->query("INSERT INTO {meta_local} (name,page,content)
316  VALUES ('" . $desc . "', '" . $id . "', '" . $title . "')"))
317  {
318  \YAWK\sys::setSyslog($db, 8, 1, "failed to store local meta tags", 0, 0, 0, 0);
319  echo \YAWK\alert::draw("warning","Warning", "Could not store local meta tags", "", "");
320  }
321 
322  // add local meta tags to db meta_local
323  if (!$db->query("INSERT INTO {meta_local} (name,page,content)
324  VALUES ('" . $keyw . "','" . $id . "','" . $words . "')"))
325  {
326  \YAWK\sys::setSyslog($db, 8, 1, "failed to store local meta tags", 0, 0, 0, 0);
327  echo \YAWK\alert::draw("warning","Warning", "Could not store local meta tags", "", "");
328  }
329  */
330 
331  // copy page as new language requested
332  if ($this->newLanguage === true)
333  { // check, if requested language dir exists
334  if (!is_dir($this->path.$this->language))
335  { // if not, try to create it
336  mkdir($this->path.$this->language);
337 
338  // prepare files to get copied into new language sub folder
339  $page = $this->path.$this->alias.".php";
340  $newPage = $this->path.$this->language."/".$this->alias."-copy.php";
341  }
342  }
343  else
344  { // prepare files to get copied into content/pages/ root folder
345  $page = $this->path.$this->alias.".php";
346  $newPage = $this->path.$this->alias."-copy.php";
347  }
348 
349  // copy file
350  if (!copy($page, $newPage) && !chmod($newPage, 0777))
351  {
352  sys::setSyslog($db, 8, 1, "copy failed: $page to $newPage", 0, 0, 0, 0);
353  print alert::draw("danger", "Error!", "File could not be copied. Check folder permissions of /content/pages !", "", "");
354  }
355  else {
356  // file copies successfully...
357  return true;
358  }
359  /*
360 
361  // ## selectmenuID from menu db
362  if ($row = $db->query("SELECT menuID FROM {menu} WHERE title LIKE '" . $this->title . "'"))
363  {
364  $res = mysqli_fetch_row($row);
365  if (isset($res[0])){
366  $menuID = $res[0];
367  }
368  else {
369  $menuID = 0;
370  }
371  }
372  else
373  { // select failed, throw error
374  sys::setSyslog($db, 23, 1, "failed to select menu entry for $this->title", 0, 0, 0, 0);
375  echo alert::draw("warning","Warning", "Could not select menu entry for: $this->title", "", "");
376  $menuID = '0';
377  }
378 
379  // ## select max ID from menu
380  if ($row = $db->query("SELECT MAX(id) FROM {menu}"))
381  {
382  $res = mysqli_fetch_row($row);
383  if (!isset($res[0]))
384  { // if not, give it a ID of 1
385  $newMenuID = 1;
386  }
387  else
388  { // if entry exists, add +1 to ID #
389  $newMenuID = $res[0]++;
390  }
391  }
392  else
393  {
394  $newMenuID = 0;
395  // select MAX(id) from menu failed, throw error
396  sys::setSyslog($db, 23, 1, "failed to fetch MAX(id) from menu", 0, 0, 0, 0);
397  echo alert::draw("warning","Warning", "Could not fetch MAX(id) from menu", "", "");
398  }
399 
400 
401  // to increment sort var correctly, check if there is an entry in the menu
402  if ($res = $db->query("SELECT MAX(sort) FROM {menu} WHERE menuID = '" . $menuID . "'"))
403  {
404  $row = mysqli_fetch_row($res);
405  if (!isset($row[0]))
406  { // if not, give it a sort ID of 1
407  $sort = 1;
408  }
409  else
410  { // if entry exists, add +1 to sort #
411  $sort = $row[0]++;
412  }
413 
414  $link = "$this->alias" . ".html";
415  if ($db->query("INSERT INTO {menu} (id,sort,menuID,text,href)
416  VALUES('" . $newMenuID . "','" . $sort . "', '" . $menuID . "', '" . $this->title_new . "', '" . $link . "')"))
417  {
418  sys::setSyslog($db, 21, 0, "menu entry $this->title_new added", 0, 0, 0, 0);
419  return true;
420  }
421  else
422  {
423  // insert failed, throw error
424  sys::setSyslog($db, 23, 1, "failed to insert menu entry for: $this->title_new", 0, 0, 0, 0);
425  echo alert::draw("warning","Warning", "Could not insert menu entry for: $this->title_new", "", "");
426  }
427  }
428  else
429  {
430  // select failed, throw error
431  sys::setSyslog($db, 23, 1, "failed to select menu entry for: $menuID", 0, 0, 0, 0);
432  echo alert::draw("warning","Warning", "Could not select menu entry for: $menuID", "", "");
433  }
434  */
435  }
436  else
437  {
438  sys::setSyslog($db, 7, 1, "could not insert data into pages table", 0, 0, 0, 0);
439  }
440  sys::setSyslog($db, 8, 1, "copy $this->path.$this->alias failed.", 0, 0, 0, 0);
441  return false;
442  }
die
Definition: block-user.php:27
static draw($type, $title, $text, $redirect, $delay)
Definition: alert.php:30
copy($db)
make a copy of a page
Definition: page.php:265
$result
Definition: email-send.php:137
$page alias
Definition: page-edit.php:68
$page
Definition: pages.php:355
print $tourdates date

References $db, $page, $res, $result, alias, date, die, and YAWK\alert\draw().

◆ countPages()

static YAWK\page::countPages (   $db)
static

count and return the pages in database

Parameters
object$dbdatabase
Returns
int|bool
Parameters
$dbdb

Definition at line 75 of file page.php.

76  { /** @param $db db */
77  if ($result = $db->query('SELECT count(id) FROM {pages}'))
78  {
79  $i = mysqli_fetch_row($result);
80  return $i[0];
81  }
82  else
83  {
84  return false;
85  }
86  }
$i

References $db, $i, and $result.

◆ create()

YAWK\page::create (   $db,
  $alias,
  $menuID,
  $locked,
  $blogid,
  $plugin 
)

create a new page

Parameters
object$dbdatabase
string$aliaspage filename
int$menuIDmenu ID
int$locked0|1 page lock status
int$blogidblog ID, if any
int$pluginplugin ID, if any
Returns
bool
Parameters
$dbdb

Definition at line 511 of file page.php.

512  {
513  // TODO: refactor this method to oop code
514  $this->alias = $alias;
515  $this->menu = $menuID;
516  $this->locked = $locked;
517  $this->blogid = $blogid;
518  $this->plugin = $plugin;
519 
520  /** @param $db db */
521  // init variables
522  // if page name is not given
523  if (!$alias) {
524  return false;
525  }
526  $alias = html_entity_decode($alias);
527  // creation date
528  $date_created = date("Y-m-d G:i:s");
529 // $date_unpublish = date('Y-m-d', strtotime('+25 year', strtotime($date_created)) );
530 // $date_unpublish = NULL;
531  $title = $alias;
532  /* alias string manipulation */
533  $alias = mb_strtolower($alias); // lowercase
534  $alias = str_replace(" ", "-", $alias); // replace all ' ' with -
535  // special chars
536  $ersetze = array("/ä/", "/ü/", "/ö/", "/Ä/", "/Ü/", "/Ö/", "/ß/"); // array of special chars
537  $umlaute = array("ae", "ue", "oe", "Ae", "Ue", "Oe", "ss"); // array of replacement chars
538  $alias = preg_replace($ersetze, $umlaute, $alias); // replace with preg
539 
540  // convert special chars
542  // final check: just numbers and chars are allowed
543  $alias = preg_replace("/[^a-z0-9\-\/]/i", "", $alias);
544  // final filename
545  $link = "$alias" . ".html";
546 
547  // if menu select field is not empty
548  if ($menuID !== "empty") {
549  // ## select max ID from menu + add menu entry
550  if ($res = $db->query("SELECT MAX(id) FROM {menu}"))
551  {
552  $row = mysqli_fetch_row($res);
553  if (!isset($row[0])) { // if not, give it a ID of 1
554  $id = 1;
555  } else {
556  $id = $row[0] + 1; // if entry exists, add +1 to ID #
557  }
558  }
559  else
560  { // throw error
561  $id = 1;
562  sys::setSyslog($db, 7, 1, "failed to fetch MAX(id) FROM {menu}", 0, 0, 0, 0);
563  alert::draw("danger","Error:", "Could not fetch MAX(id) FROM {menu}", "page=page-new", "4300");
564  }
565  // to increment sort var correctly, check if there is an entry in the menu
566  if ($res = $db->query("SELECT MAX(sort) FROM {menu} WHERE menuID = '" . $menuID . "'"))
567  {
568  $row = mysqli_fetch_row($res);
569  if (!isset($row[0]))
570  { // if not, give it a ID of 1
571  $sort = 1;
572  }
573  else
574  { // if entry exists, add +1 to sort #
575  $sort = $row[0] + 1;
576  }
577  }
578  else
579  { // throw error
580  $sort = 1;
581  sys::setSyslog($db, 7, 1, "failed to fetch MAX(id) FROM {menu} WHERE menuID = $menuID", 0, 0, 0, 0);
582  alert::draw("danger","Error:", "Could not fetch MAX(id) FROM {menu} WHERE menuID = $menuID", "page=page-new", "4300");
583  }
584 
585  if ($plugin) {
586  if (strlen($plugin) >= 1) {
587  $menu_published = 1;
588  }
589  else {
590  $menu_published = 0;
591  }
592  }
593  else {
594  $menu_published = 0;
595  }
596  $title = htmlentities($title);
597  $tmpID = 0;
598  $titleText = '';
599  // insert menu data
600  if (!$res = $db->query("INSERT INTO {menu} (id,sort,menuID,published,title,text,href,blogid, menuLanguage)
601  VALUES('" . $id . "',
602  '" . $sort . "',
603  '" . $menuID . "',
604  '" . $menu_published . "',
605  '" . $titleText . "',
606  '" . $title . "',
607  '" . $link . "',
608  '" . $blogid . "',
609  '" . $this->language . "')"))
610  { // throw error
611  sys::setSyslog($db, 23, 1, "failed to insert data into {menu}", 0, 0, 0, 0);
612  alert::draw("danger", "Error:", "could not insert menu data", "page=page-new", "4300");
613  }
614  else
615  { // success syslog entry
616  sys::setSyslog($db, 21, 0, "added new menu: $title (id: $id)", 0, 0, 0, 0);
617  }
618  } // ./ if menu != empty
619 
620  // if the method is called from the blog, set settings
621  if ($locked === '0' && $blogid === '0') {
622  $locked = 0;
623  $published = 0;
624  $content = "leer";
625  } else {
626  $published = 0;
627  $content = "<?php \$blog_id = $blogid; include 'system/plugins/blog/blog.php'; ?>";
628  }
629 
630  // if the method is called from the plugin, set settings
631  if ($plugin) {
632  if (is_array($plugin)){
633  $plugin = array("tos", $_POST['signup_tospage'], $_POST['signup_terms-long']);
634  if ($plugin[0] === 'tos'){
635  $published = 1;
636  $locked = 1;
637  $alias = "$plugin[1]";
638  $content = "$plugin[2]";
639  $plugin = "signup";
640  }
641  }
642  else if (strlen($plugin) >= 1) {
643  $published = 1;
644  $locked = 1;
645  $content = "<?php include 'system/plugins/$plugin/$plugin.php'; ?>";
646  }
647  }
648  else {
649  $plugin = 0;
650  }
651 
652  // ## select max id from pages
653  if ($res = $db->query("SELECT MAX(id) FROM {pages}"))
654  {
655  $row = mysqli_fetch_row($res);
656  $id = $row[0] + 1;
657  }
658  else
659  {
660  $id = 1;
661  sys::setSyslog($db, 7, 1, "failed to select MAX(id) from pages db", 0, 0, 0, 0);
662  }
663 
664  $alias = htmlentities($alias);
665  // ## add new page to db pages
666  if (!$db->query("INSERT INTO {pages} (id,published,date_created,date_changed,date_publish,date_unpublish,alias,title,locked,blogid,plugin,lang)
667  VALUES ('" . $id . "',
668  '" . $published . "',
669  '" . $date_created . "',
670  '" . $date_created . "',
671  '" . $date_created . "',
672  NULL,
673  '" . $alias . "',
674  '" . $title . "',
675  '" . $locked . "',
676  '" . $blogid . "',
677  '".$plugin."',
678  '".$this->language."')"))
679  { // error inserting page into database - throw error
680  sys::setSyslog($db, 7, 2, "unable to add page $alias into database.", 0, 0, 0, 0);
681  alert::draw("danger", "Error!", "unable to add new page ($alias) id: $id into pages database.", "", 4300);
682  }
683 
684  // check if language is set
685  if (isset($this->language) && (!empty($this->language)))
686  { // set path for new language page
687  $filename = $this->path.$this->language."/".$alias.".php";
688  if (!is_dir($this->path.$this->language)){
689  if (!mkdir($this->path.$this->language)){
690  sys::setSyslog($db, 7, 2, "failed to create language folder: $this->path.$this->language");
691  return false;
692  }
693  }
694  }
695  else
696  { // set path for root dir
697  $filename = $this->path.$alias.".php";
698  }
699 
700  // create file
701  if (!file_exists($filename)) {
702  $handle = fopen($filename, "wr");
703  fwrite($handle, $content);
704  fclose($handle);
705  chmod($filename, 0777);
706  }
707 
708  // page created successfully
709  sys::setSyslog($db, 5, 0, "created $filename", 0, 0, 0, 0);
710  return true;
711  }
$filename
Definition: actions.php:10
print $blog blogid
Definition: blog-edit.php:376
$blogid
Definition: page.php:48
$date_created
Definition: page.php:40
$locked
Definition: page.php:50
$title
Definition: page.php:28
$alias
Definition: page.php:24
$plugin
Definition: page.php:46
$published
Definition: page.php:32
static encodeChars($string)
convert german special chars and vowels into legal html
Definition: sys.php:1089

References YAWK\page\$alias, YAWK\page\$blogid, $content, YAWK\page\$date_created, $db, $filename, YAWK\page\$id, YAWK\page\$locked, YAWK\page\$plugin, YAWK\page\$published, $res, YAWK\page\$title, alias, blogid, date, YAWK\alert\draw(), and YAWK\sys\encodeChars().

◆ delete()

YAWK\page::delete (   $db)

delete a page

Parameters
object$dbdatabase
Returns
bool
Parameters
$dbdb

Definition at line 449 of file page.php.

450  {
451  /** @param $db db */
452  // delete item from pages db
453  if (!$db->query("DELETE FROM {pages} WHERE id = '" . $this->id . "'")) {
454  sys::setSyslog($db, 7, 1, "failed to delete page $this->alias from database", 0, 0, 0, 0);
455  alert::draw("danger", "Error:", "could not delete page from database", "pages", "4300");
456  }
457  else
458  { // page deleted
459  sys::setSyslog($db, 5, 0, "deleted page $this->alias from database", 0, 0, 0, 0);
460  }
461  // delete item from menu db
462  if (!$db->query("DELETE FROM {menu} WHERE href = '" . $this->alias . ".html'")) {
463  sys::setSyslog($db, 23, 1, "failed to delete menu entry of page $this->alias from database", 0, 0, 0, 0);
464  alert::draw("danger", "Error:", "could not delete menu entry from database", "pages", "4300");
465  }
466  else
467  { // deleted menu syslog entry
468  sys::setSyslog($db, 21, 0, "deleted menu of ../content/pages/$this->alias.php", 0, 0, 0, 0);
469  }
470 
471  // check, if language is set and build path + filename
472  if (isset($this->language) && (!empty($this->language)))
473  { // file should be in corresponding language folder
474  $filename = $this->path.$this->language."/".$this->alias.".php";
475  }
476  else
477  { // file should be in pages root folder
478  $filename = $this->path.$this->alias.".php";
479  }
480 
481  // check if file exists
482  if (file_exists($filename))
483  { // delete file
484  if (!unlink($filename))
485  { // delete failed
486  sys::setSyslog($db, 8, 2, "unable to delete $filename", 0, 0, 0, 0);
487  alert::draw("danger", "Error:", "could not delete file from /content/ folder", "pages", "4300");
488  return false;
489  }
490  else
491  { // delete successful
492  sys::setSyslog($db, 5, 0, "deleted $filename", 0, 0, 0, 0);
493  return true;
494  }
495  }
496  // file does not exist.
497  sys::setSyslog($db, 7, 1, "file $filename does not exist. page->delete() failed", 0, 0, 0, 0);
498  return false;
499  }

References $db, $filename, alias, and YAWK\alert\draw().

◆ deleteContent()

YAWK\page::deleteContent (   $dirprefix)

delete a static content page

Parameters
string$dirprefixdirectory prefix

Definition at line 819 of file page.php.

820  {
821  global $dirprefix;
822  if (isset($this->language) && (!empty($this->language)))
823  {
824  $filename = $dirprefix.$this->path.$this->language."/".$this->alias.".php";
825  }
826  else
827  {
828  $filename = $dirprefix.$this->path.$this->alias."php";
829  }
830 
831  if (file_exists($filename))
832  {
833  if (unlink($filename))
834  {
835  return true;
836  }
837  else
838  {
839  return false;
840  }
841  }
842  else
843  {
844  return true;
845  }
846  }
if(!isset($page)) if(!isset($db)) if(!isset($lang)) if(isset($_GET['id'])) if(isset($_POST['save'])) $dirprefix
Definition: page-edit.php:63

References $dirprefix, $filename, and alias.

◆ getContent()

YAWK\page::getContent (   $db,
  $lang 
)

get and include static page content

Parameters
object$dbdatabase
object$langlanguage obj
Returns
mixed

@noinspection PhpIncludeInspection

@noinspection PhpIncludeInspection

@noinspection PhpIncludeInspection

@noinspection PhpIncludeInspection

Definition at line 1116 of file page.php.

References $_GET, $db, $lang, YAWK\page\$language, $now, YAWK\page\$path, date, die, exit, YAWK\controller\filterfilename(), and YAWK\settings\getSetting().

◆ getCurrentLanguageByID()

YAWK\page::getCurrentLanguageByID (   $db,
  $id 
)
Parameters
$dbdb $res

Definition at line 929 of file page.php.

929  {
930  /** @param $db db $res */
931  if (isset($id) && (!empty($id)))
932  { // query db for given page ID
933  $res = $db->query("SELECT lang FROM {pages} WHERE id ='".$id."'");
934  $currentLanguage = mysqli_fetch_row($res);
935  }
936  // check, if page got a language set
937  if (isset($currentLanguage[0]) && (!empty($currentLanguage[0])))
938  { // return page language
939  return $currentLanguage[0];
940  }
941  else
942  { // no language set, return empty string
943  return "";
944  }
945  }

References $db, YAWK\page\$id, and $res.

◆ getLatest()

static YAWK\page::getLatest (   $db,
  $limit 
)
static

get latest pages

Parameters
object$dbdatabase
int$limitlimit to n entries
Returns
array|string
Parameters
$dbdb

Definition at line 1058 of file page.php.

1059  { /** @param $db db */
1060  // check and set default value
1061  if (!isset($limit) && (empty($limit))) { $limit = 4; }
1062  // select latest n page titles
1063  if ($res = $db->query("SELECT id, alias, title, published, date_publish
1064  FROM {pages}
1065  WHERE blogid = 0
1066  AND plugin = 0
1067  ORDER BY date_created
1068  DESC LIMIT $limit"))
1069  {
1070  $latestPages = array();
1071  while ($row = mysqli_fetch_assoc($res))
1072  {
1073  $latestPages[] = $row;
1074  }
1075  return $latestPages;
1076  }
1077  else
1078  {
1079  return "no pages found.";
1080  }
1081  }

References $db, and $res.

Referenced by YAWK\BACKEND\dashboard\drawLatestPagesBox().

◆ getMetaTags()

static YAWK\page::getMetaTags (   $db,
  $id,
  $type 
)
static

get and return meta tags for requested page

Parameters
object$dbdatabase
int$idaffected page ID
string$typemeta description
Returns
string|bool meta tags as string
Parameters
$dbdb $res

Definition at line 95 of file page.php.

96  { /** @param $db db $res */
97  if ($row = $db->query("SELECT meta_local, meta_keywords
98  FROM {pages}
99  WHERE id = '".$id."'"))
100  { // output meta content description
101  $res = $row->fetch_assoc();
102  if (!empty($type))
103  {
104  if ($type == "meta_local"){
105  if (!empty($res['meta_local'])){
106  return $res['meta_local'];
107  }
108  else {
109  return null;
110  }
111  }
112  else if ($type == "meta_keywords"){
113  if (!empty($res['meta_keywords'])){
114  return $res['meta_keywords'];
115  }
116  else {
117  return null;
118  }
119  }
120  else {
121  return null;
122  }
123  }
124  }
125  else {
126  // throw alert
127  sys::setSyslog($db, 7, 1, "failed to fetch meta $type for page ID $id", 0, 0, 0, 0);
128  return alert::draw("warning", "Warning", "Could not fetch meta $type for page ID $id", "",4200);
129  }
130  // q failed
131  return false;
132  }
$type

References $db, $res, $type, and YAWK\alert\draw().

◆ getMetaTagsArray()

static YAWK\page::getMetaTagsArray (   $db,
  $id 
)
static

get and return meta tags of requested page as array

Parameters
object$dbdatabase
int$idaffected page ID
string$typemeta description
Returns
array|bool meta tags as array
Parameters
$dbdb $res

Definition at line 141 of file page.php.

142  { /** @param $db db $res */
143  if ($row = $db->query("SELECT meta_local, meta_keywords
144  FROM {pages}
145  WHERE id = '".$id."'"))
146  { // output meta content description
147  $res = $row->fetch_assoc();
148  if (is_array($res)
149  && (!empty($res['meta_local'])
150  && (!empty($res['meta_keywords'])))){
151  return $res;
152  }
153  else {
154  // meta tags not set, get global meta tags
155  $res['meta_local'] = \YAWK\settings::getSetting($db, "globalmetatext");
156  $res['meta_keywords'] = \YAWK\settings::getSetting($db, "globalmetakeywords");
157  if (!empty($res['meta_local']) && (!empty($res['meta_keywords']))){
158  return $res;
159  }
160  else {
161  $res['meta_local'] = "Unable to get Meta Description for this page. Neither local or global meta description found.";
162  $res['meta_keywords'] = "Unable to get Meta Keywords for this page. Neither local or global meta keywords found.";
163  return $res;
164  }
165  }
166  }
167  else {
168  // throw alert
169  sys::setSyslog($db, 7, 1, "failed to fetch meta tags for page ID $id", 0, 0, 0, 0);
170  $res['meta_local'] = "Unable to get Meta Description for this page. Neither local or global meta description found.";
171  $res['meta_keywords'] = "Unable to get Meta Keywords for this page. Neither local or global meta keywords found.";
172  return $res;
173  }
174  }
static getSetting($db, $property)
Get and return value for property from settings database.
Definition: settings.php:470

References $db, $res, and YAWK\settings\getSetting().

◆ getProperty()

YAWK\page::getProperty (   $db,
  $id,
  $property 
)

get any requested page property

Parameters
object$dbdatabase
int$idaffected page ID
string$propertydatabase field to get
Returns
string|bool the selected property or false
Parameters
$dbdb $res

Definition at line 1090 of file page.php.

1091  { /** @param $db db $res */
1092  // select property from pages db
1093  if ($res = $db->query("SELECT $property FROM {pages}
1094  WHERE id = '" . $id . "'"))
1095  { // fetch data
1096  if ($row = mysqli_fetch_row($res)){
1097  return $row[0];
1098  }
1099  }
1100  else
1101  { // throw error
1102  sys::setSyslog($db, 7, 1, "unable to get property: $property from pages database.", 0, 0, 0, 0);
1103  alert::draw("warning", "Warning", "unable to get property: $property from Paged Database.", "", "4200");
1104  return false;
1105  }
1106  // q failed
1107  return null;
1108  }

References $db, YAWK\page\$id, $res, and YAWK\alert\draw().

◆ loadProperties()

YAWK\page::loadProperties (   $db,
  $alias 
)

load page properties and store as object properties

Parameters
object$dbdatabase
string$aliaspage filename
Parameters
$dbdb $res

Definition at line 952 of file page.php.

953  {
954  /** @param $db db $res */
955  if (isset($alias) && (!empty($alias)))
956  {
957  $res = $db->query("SELECT * FROM {pages} WHERE alias = '".$alias."'");
958  if ($row = mysqli_fetch_assoc($res))
959  {
960  $this->id = $row['id'];
961  $this->date_created = $row['date_created'];
962  $this->date_publish = $row['date_publish'];
963  $this->date_unpublish = $row['date_unpublish'];
964  $this->published = $row['published'];
965  $this->gid = $row['gid'];
966  $this->title = $row['title'];
967  $this->ownerid = $row['owner'];
968  $this->menu = $row['menu'];
969  $this->bgimage = $row['bgimage'];
970  $this->locked = $row['locked'];
971  $this->blogid = $row['blogid'];
972  $this->plugin = $row['plugin'];
973  $this->language = $row['lang'];
974  $this->meta_local = $row['meta_local'];
975  $this->meta_keywords = $row['meta_keywords'];
976  $this->alias = $alias;
977  }
978  else
979  { // 404 error handling
980  if ($this->alias == "content/errors/404")
981  { // check if user is logged in (session uid is set in that case)
982  if (isset($_SESSION['uid']) && (!empty($_SESSION['uid'])))
983  { // logged in user created a 404 error
984  sys::setSyslog($db, 7, 2, "404: file not found - displayed $alias instead", $_SESSION['uid'], 0, 0, 0);
985  }
986  else
987  { // user is not logged in - unknown user created a 404 error
988  sys::setSyslog($db, 7, 2, "404: file not found - displayed $alias instead", 0, 0, 0, 0);
989  }
990  }
991  }
992  }
993  else
994  { // page not set - unable to load page properties
995  sys::setSyslog($db, 7, 2, "failed to load properties because page alias was not set", 0, 0, 0, 0);
996  }
997  }
$blog gid
Definition: blog-setup.php:139
if(!isset($blog)) if(!isset($language)||(!isset($lang))) if(!isset($db)) $blog published
Definition: blog-toggle.php:17
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
print $page bgimage
Definition: page-edit.php:522
print $page title
Definition: page-edit.php:377
print $page date_unpublish
Definition: page-edit.php:448

References YAWK\page\$alias, $db, $res, alias, bgimage, blogid, date_publish, date_unpublish, gid, meta_keywords, meta_local, published, and title.

◆ loadPropertiesByID()

YAWK\page::loadPropertiesByID (   $db,
  $id 
)

load page properties and store as object properties

Parameters
object$dbdatabase
string$idpage id
Parameters
$dbdb $res

Definition at line 1004 of file page.php.

1005  {
1006  /** @param $db db $res */
1007  if (isset($id) && (!empty($id)))
1008  {
1009  $res = $db->query("SELECT * FROM {pages} WHERE id = '".$id."'");
1010  if ($row = mysqli_fetch_assoc($res))
1011  {
1012  $this->id = $row['id'];
1013  $this->date_created = $row['date_created'];
1014  $this->date_publish = $row['date_publish'];
1015  $this->date_unpublish = $row['date_unpublish'];
1016  $this->published = $row['published'];
1017  $this->gid = $row['gid'];
1018  $this->alias = $row['alias'];
1019  $this->title = $row['title'];
1020  $this->ownerid = $row['owner'];
1021  $this->menu = $row['menu'];
1022  $this->bgimage = $row['bgimage'];
1023  $this->locked = $row['locked'];
1024  $this->blogid = $row['blogid'];
1025  $this->plugin = $row['plugin'];
1026  $this->language = $row['lang'];
1027  $this->meta_local = $row['meta_local'];
1028  $this->meta_keywords = $row['meta_keywords'];
1029  }
1030  else
1031  { // 404 error handling
1032  if ($this->alias == "content/errors/404")
1033  { // check if user is logged in (session uid is set in that case)
1034  if (isset($_SESSION['uid']) && (!empty($_SESSION['uid'])))
1035  { // logged in user created a 404 error
1036  sys::setSyslog($db, 7, 2, "404: file not found - displayed $this->alias instead", $_SESSION['uid'], 0, 0, 0);
1037  }
1038  else
1039  { // user is not logged in - unknown user created a 404 error
1040  sys::setSyslog($db, 7, 2, "404: file not found - displayed $this->alias instead", 0, 0, 0, 0);
1041  }
1042  }
1043  }
1044  }
1045  else
1046  { // page ID not set - unable to load page properties
1047  sys::setSyslog($db, 7, 2, "failed to load properties because page ID was not set", 0, 0, 0, 0);
1048  }
1049  }

References $db, YAWK\page\$id, $res, alias, bgimage, blogid, date_publish, date_unpublish, gid, meta_keywords, meta_local, published, and title.

◆ readContent()

YAWK\page::readContent (   $dirPrefix)

read content from static page

Parameters
string$dirPrefixdirectory prefix
Returns
string html content

Definition at line 901 of file page.php.

901  : string
902  {
903  // check, if language is set
904  if (isset($this->language) && (!empty($this->language)))
905  { // if so, build path including language folder
906  $filename = $this->path.$this->language."/".$this->alias.".php";
907  }
908  else
909  { // no language set, build path for content/pages root folder
910  $filename = $this->path.$this->alias.".php";
911  }
912  if(file_exists($filename)){
913  // open page file
914  $handle = @fopen($filename, "rw");
915  // read content into var
916  $content = @fread($handle, filesize($filename));
917  // close resource
918  fclose($handle);
919  // and return page content
920  return $content;
921  }
922  else
923  {
924  return 'ERROR: Unable to read content of file: '.$filename.'
925 Maybe the file has been physically deleted, moved or renamed.';
926  }
927  }

References $content, $filename, and alias.

◆ save()

YAWK\page::save (   $db)

save a static page including all settings

Parameters
object$dbdatabase
Returns
bool
Parameters
$dbdb

Definition at line 718 of file page.php.

719  {
720  /** @param $db db */
721  $date_changed = date("Y-m-d G:i:s");
722 
723  /* alias string manipulation */
724  $this->alias = mb_strtolower($this->alias); // lowercase
725  $this->alias = str_replace(" ", "-", $this->alias); // replace all ' ' with -
726  // special chars
727  $umlaute = array("/ä/", "/ü/", "/ö/", "/Ä/", "/Ü/", "/Ö/", "/ß/"); // array of special chars
728  $ersetze = array("ae", "ue", "oe", "ae", "ue", "oe", "ss"); // array of replacement chars
729  $this->alias = preg_replace($umlaute, $ersetze, $this->alias); // replace with preg
730  $this->alias = preg_replace("/[^a-z0-9\-\/]/i", "", $this->alias); // final check: just numbers and chars are allowed
731 
732 
733  // old alias string
734  $oldAlias = substr($this->searchstring, 0, -5); // remove last 5 chars (.html) to get the plain filename
735 
736  // update menu entry
737  /*
738  if (!$db->query("UPDATE {menu}
739  SET text = '" . $this->title ."',
740  href = '" . $this->alias . ".html',
741  gid = '" . $this->gid . "',
742  published = '" . $this->published . "'
743  WHERE href = '" . $this->searchstring . "'"))
744  {
745  // throw error
746  \YAWK\sys::setSyslog($db, 23, 1, "failed to update menu entry $this->title.", 0, 0, 0, 0);
747  \YAWK\alert::draw("warning", "Warning", "menu entry could not be stored in database.", "", 6200);
748  }
749  */
750 
751  // update page db
752  // check unpublish date
753  if ($this->date_unpublish == "0000-00-00 00:00:00" || (empty($this->date_unpublish) || $this->date_unpublish == NULL))
754  {
755  // sql code with NULL unpublish date
756  if (!$db->query("UPDATE {pages}
757  SET published = '" . $this->published . "',
758  gid = '" . $this->gid . "',
759  date_changed = '" . $date_changed . "',
760  date_publish = '" . $this->date_publish . "',
761  date_unpublish = NULL,
762  title = '" . $this->title . "',
763  alias = '" . $this->alias . "',
764  bgimage = '" . $this->bgimage . "',
765  lang = '" . $this->language . "',
766  meta_local = '" . $this->meta_local . "',
767  meta_keywords = '" . $this->meta_keywords . "'
768  WHERE id = '" . $this->id . "'"))
769  {
770  // throw error
771  sys::setSyslog($db, 23, 1, "failed to update database of page $this->title", 0, 0, 0, 0);
772  // \YAWK\alert::draw("warning", "Warning", "page data could not be stored in database.", "", 6200);
773  // \YAWK\alert::draw("danger", 'MySQL Error: ('.mysqli_errno().')', 'Database error: '.mysqli_error($db).'', "", 0);
774  return false;
775  }
776  else
777  {
778  // update pages db worked, all fin
779  sys::setSyslog($db, 5, 0, "updated $this->alias", 0, 0, 0, 0);
780  return true;
781  }
782  }
783  else
784  {
785  // sql code with correct, user-selected unpublish date
786  if (!$db->query("UPDATE {pages}
787  SET published = '" . $this->published . "',
788  gid = '" . $this->gid . "',
789  date_changed = '" . $date_changed . "',
790  date_publish = '" . $this->date_publish . "',
791  date_unpublish = '" . $this->date_unpublish . "',
792  title = '" . $this->title . "',
793  alias = '" . $this->alias . "',
794  bgimage = '" . $this->bgimage . "',
795  lang = '" . $this->language . "',
796  meta_local = '" . $this->meta_local . "',
797  meta_keywords = '" . $this->meta_keywords . "'
798  WHERE id = '" . $this->id . "'"))
799  {
800  // throw error
801  sys::setSyslog($db, 23, 1, "failed to update page $this->title", 0, 0, 0, 0);
802  alert::draw("warning", "Warning", "failed to store data of $this->alias in database.", "", 6200);
803  return false;
804  }
805  else
806  {
807  // update pages db worked, all fin
808  sys::setSyslog($db, 5, 0, "updated $this->alias", 0, 0, 0, 0);
809  return true;
810  }
811  }
812  } // ./ save function

References $db, alias, date, date_unpublish, and YAWK\alert\draw().

◆ toggleLock()

YAWK\page::toggleLock (   $db,
  $id,
  $locked 
)

toggle page lock to avoid unintended changes

Parameters
object$dbdatabase
int$idaffected page id
int$locked0|1 lock status
Returns
bool page toggle lock status

Definition at line 241 of file page.php.

242  {
243  /* @param $db db */
244  $id = $db->quote($id);
245  $locked = $db->quote($locked);
246  if ($db->query("UPDATE {pages} SET locked = '".$locked."' WHERE id = '".$id."'")) {
247  /* free result set */
248  // $res->close();
249  return true;
250  }
251  else
252  { //
253  print alert::draw("danger", "Error", "Site Lock could not be toggled.","page=pages",4200);
254  if ($locked === "0") { $status = "unlocked"; } else { $status = "locked"; }
255  sys::setSyslog($db, 5,0, "set status $status page id #$id", 0, 0, 0, 0);
256  return false;
257  }
258  }

References $db, YAWK\page\$id, YAWK\page\$locked, and YAWK\alert\draw().

◆ toggleOffline()

YAWK\page::toggleOffline (   $db,
  $id,
  $published,
  $title 
)

toggle page status online or offline (plus corresponding menu entries)

Parameters
object$dbdatabase
int$idaffected page ID
int$published0|1 page publish status
string$titlepage title
Returns
bool page toggle on/offline status

Definition at line 184 of file page.php.

185  { /* @param $db db */
186  // check data types
187  if (is_numeric($id) && (is_numeric($published) && is_string($title)))
188  {
189  if ($published === '1')
190  { $published = 0; }
191  else if ($published === '0')
192  { $published = 1; }
193 
194  // escape vars
195  $id = $db->quote($id);
196  $published = $db->quote($published);
197  $title = $db->quote($title);
198 
199  if ($published === "0") { $status = "offline"; } else { $status = "online"; }
200 
201  // TOGGLE PAGES
202  if (!$db->query("UPDATE {pages}
203  SET published = '" . $published . "'
204  WHERE id = '" . $id . "'"))
205  { // could not update pages db table
206  $status = sys::iStatusToString($published, "online", "offline");
207  sys::setSyslog($db, 7, 1, "failed to toggle $title status to $status", 0, 0, 0, 0);
208  print alert::draw("danger", "Error", "Site Status could not be toggled.", "", 4200);
209  }
210  else
211  { // ok, set syslog entry
212  sys::setSyslog($db, 5, 0, "toggled page $id to $status", 0, 0, 0, 0);
213  }
214 
215  // TOGGLE MENU STATUS
216  if (!$db->query("UPDATE {menu}
217  SET published = '" . $published . "'
218  WHERE title = '" . $title . "'")) {
219  // could not update pages db table
220  print alert::draw("danger", "Error", "Menu Status could not be toggled.", "", 4200);
221  }
222  else
223  { // ok, set syslog entry
224  sys::setSyslog($db, 21, 0, "toggled menu $id to $status", 0, 0, 0, 0);
225  }
226  }
227  else
228  { // data type is incorrect, throw yoda's hint
229  print alert::draw("danger", "Error", "YaWK said: variable manipulate you shall not do!", "", 4200);
230  }
231  return true;
232  }
static iStatusToString($i, $on, $off)
convert a integer status to string variable (0|1) to online / offline
Definition: sys.php:729

References $db, YAWK\page\$id, YAWK\page\$published, YAWK\page\$title, YAWK\alert\draw(), and YAWK\sys\iStatusToString().

◆ writeContent()

YAWK\page::writeContent (   $content)

write content to static page

Parameters
string$contentthe content to write
Returns
bool true|false
Parameters
$dbdb $alias

Definition at line 853 of file page.php.

854  {
855  /** @param $db db $alias */
856  /* alias string manipulation */
857  $this->alias = mb_strtolower($this->alias); // lowercase
858  $this->alias = str_replace(" ", "-", $this->alias); // replace all ' ' with -
859  // special chars
860  $specialChars = array("/ä/", "/ü/", "/ö/", "/Ä/", "/Ü/", "/Ö/", "/ß/"); // array of special chars
861  $replacementChars = array("ae", "ue", "oe", "ae", "ue", "oe", "ss"); // array of replacement chars
862  $this->alias = preg_replace($specialChars, $replacementChars, $this->alias); // replace with preg
863  $this->alias = preg_replace("/[^a-z0-9\-\/]/i", "", $this->alias); // final check: just numbers and chars are allowed
864  if (!empty($this->language))
865  {
866  $this->language = mb_substr($this->language, 0, 2);
867  // check if requested language directory exists
868  if (!is_dir($this->path.$this->language))
869  { // if not, create it
870  mkdir ($this->path.$this->language);
871  }
872  // store file to corresponding language folder
873  $filename = $this->path.$this->language."/".$this->alias.".php";
874  }
875  else
876  { // store file to content/pages root folder
877  $filename = $this->path.$this->alias.".php";
878  }
879 
880  // open file
881  $handle = fopen($filename, "w+");
882  if (fwrite($handle, $content))
883  { // write content + close
884  fclose($handle);
885  // set file perms
886  chmod($filename, 0777);
887  return true;
888  }
889  else
890  { // writeContent failed
891  sys::setSyslog($db, 7, 2, "unable to write content to file $filename", 0, 0, 0, 0);
892  return false;
893  }
894  }
$specialChars
Definition: page-edit.php:71

References $content, $db, $filename, $specialChars, and alias.

Member Data Documentation

◆ $alias

YAWK\page::$alias = ''
  • Parameters
    stringpage filename

Definition at line 24 of file page.php.

Referenced by YAWK\page\create(), and YAWK\page\loadProperties().

◆ $alias_new

YAWK\page::$alias_new = ''
  • Parameters
    stringnew page filename (used by copy function)

Definition at line 26 of file page.php.

◆ $bgimage

YAWK\page::$bgimage
  • Parameters
    stringbg image

Definition at line 58 of file page.php.

◆ $blogid

YAWK\page::$blogid
  • Parameters
    intblog ID of that page

Definition at line 48 of file page.php.

Referenced by YAWK\page\create().

◆ $date_created

YAWK\page::$date_created
  • Parameters
    stringdate when the site is created

Definition at line 40 of file page.php.

Referenced by YAWK\page\create().

◆ $date_publish

YAWK\page::$date_publish
  • Parameters
    stringdate when the site is published

Definition at line 42 of file page.php.

◆ $date_unpublish

YAWK\page::$date_unpublish
  • Parameters
    stringdate when the site should be unpublished

Definition at line 44 of file page.php.

◆ $gid

YAWK\page::$gid
  • Parameters
    intgroup id for this page

Definition at line 38 of file page.php.

◆ $id

YAWK\page::$id = -1

◆ $language

YAWK\page::$language
  • Parameters
    stringpage language

Definition at line 60 of file page.php.

Referenced by YAWK\page\getContent().

◆ $locked

YAWK\page::$locked
  • Parameters
    int0|1 to check if the page is locked

Definition at line 50 of file page.php.

Referenced by YAWK\page\create(), and YAWK\page\toggleLock().

◆ $menu

YAWK\page::$menu = -1
  • Parameters
    intmenu id according to this page

Definition at line 36 of file page.php.

◆ $meta_keywords

YAWK\page::$meta_keywords = "Meta Tag Keywords"
  • Parameters
    stringthe meta tags keywords of this page

Definition at line 68 of file page.php.

◆ $meta_local

YAWK\page::$meta_local = "Meta Tag Description"
  • Parameters
    stringthe meta tags description of this page

Definition at line 66 of file page.php.

◆ $metadescription

YAWK\page::$metadescription
  • Parameters
    stringmeta description for this page

Definition at line 52 of file page.php.

◆ $metakeywords

YAWK\page::$metakeywords
  • Parameters
    stringmeta keywords for this page

Definition at line 54 of file page.php.

◆ $newLanguage

YAWK\page::$newLanguage
  • Parameters
    boolcopy page into new language indicator

Definition at line 62 of file page.php.

◆ $ownerid

YAWK\page::$ownerid = -1
  • Parameters
    intuid (user id) of the page owner

Definition at line 34 of file page.php.

◆ $path

YAWK\page::$path = "../content/pages/"
  • Parameters
    stringthe root path where pages are physically stored

Definition at line 64 of file page.php.

Referenced by YAWK\page\getContent().

◆ $plugin

YAWK\page::$plugin
  • Parameters
    intplugin ID of that page

Definition at line 46 of file page.php.

Referenced by YAWK\page\create().

◆ $published

YAWK\page::$published = 0
  • Parameters
    int0|1 published status

Definition at line 32 of file page.php.

Referenced by YAWK\page\create(), and YAWK\page\toggleOffline().

◆ $searchstring

YAWK\page::$searchstring
  • Parameters
    stringsearch string for this page

Definition at line 56 of file page.php.

◆ $title

YAWK\page::$title = ''
  • Parameters
    stringpage title

Definition at line 28 of file page.php.

Referenced by YAWK\page\create(), and YAWK\page\toggleOffline().

◆ $title_new

YAWK\page::$title_new = ''
  • Parameters
    stringnew page title (used by copy function)

Definition at line 30 of file page.php.


The documentation for this class was generated from the following file: