insanelyBlog/includes/page.class.php

92 lines
2.0 KiB
PHP
Raw Normal View History

<?php
class page
{
private $query;
public $exists;
public $data;
public $slug;
public function __construct($slug = false)
{
global $_sql;
if ($slug)
{
$slug = sqlprot($slug);
$this->slug = $slug;
$this->query = $_sql->query("SELECT * FROM pages WHERE pageSlug = '$slug'");
$this->exists = ($this->query->num_rows ? true : false);
if ($this->exists)
$this->data = $this->query->fetch_assoc();
} else
{
$this->query = $_sql->query("SELECT * FROM pages".($trash ? ' WHERE pageDeleted = 1' : ''));
$this->exists = ($this->query->num_rows ? true : false);
}
}
public function status()
{
if ($this->exists)
return true;
return false;
}
public function readable()
{
if ($this->exists && !$this->data['pageDeleted'])
return true;
return false;
}
public function get_list()
{
$pages = array();
while ($data = $this->query->fetch_assoc())
array_push($pages, $data);
}
public function update($title, $content)
{
global $_sql;
$title = sqlprot($title);
$content = sqlprot($content);
if (Check::title($title) && $this->data)
if ($_sql->query("UPDATE pages SET pageTitle = '$title', pageContent = '$content', pageModified = ".time()." WHERE pageSlug = '".$this->data['pageSlug']."' AND pageDeleted IS NULL"))
return true;
return false;
}
public function create($title, $content)
{
global $_sql;
$slug = sqlprot($this->slug);
$title = sqlprot($title);
$content = sqlprot($content);
if (Check::title($title) && Check::slug($slug) && !$this->data)
if ($_sql->query("INSERT INTO pages (pageSlug, pageTitle, pageContent, pageCreated) VALUES ('$slug', '$title', '$content', ".time().")"))
return true;
return false;
}
public function delete()
{
global $_sql;
if ($this->data)
if ($_sql->query("UPDATE pages SET pageDeleted = ".time()." WHERE pageSlug = '".$this->data['pageSlug']."'"))
return true;
return false;
}
2016-06-18 10:07:35 +02:00
}