. */ // Advanced SQLite example // this is a mini-CMS : you can publish articles and read them // Here we renamed skeleton tags to match the english language require_once '../class.miniskel.php'; class sqlSkel extends miniSkel { private $file = './sqlite.base'; private $db = false; public function __construct() { $this->db = new SQLiteDatabase($this->file, 0600); if (!@$this->db->query('SELECT id FROM articles WHERE 1 LIMIT 1;')) { $this->initDB(); } $this->loopKeywords['orderDesc'] = 'reversed'; $this->loopKeywords['orderBy'] = 'by'; $this->loopKeywords['begin'] = 'begin'; $this->loopTagName = 'LOOP'; $this->loopShortTagName = 'L'; } public function addArticle($title, $text, $name) { $this->db->query('INSERT INTO articles (id, title, text, name, date) VALUES (NULL, "'.sqlite_escape_string($title).'", "'.sqlite_escape_string($text).'", "'.sqlite_escape_string($name).'", "'.time().'");'); } public function initDB() { $this->db->query('CREATE TABLE articles ( id INTEGER PRIMARY KEY, title VARCHAR(255), text TEXT, name VARCHAR(128), date INT);'); $this->db->query('CREATE INDEX date ON articles (date);'); } protected function processLoopType_article($criterias, $content) { $out = ''; $query = 'SELECT * FROM articles '; $where = 'WHERE 1'; $order = ''; $limit = ''; foreach ($criterias as $criteria) { switch ($criteria['action']) { case miniSkel::ACTION_ORDER_BY: if (!$order) $order = 'ORDER BY '.$criteria['field'].''; else $order .= ', '.$criteria['field'].''; break; case miniSkel::ACTION_ORDER_DESC: if ($order) $order .= ' DESC'; break; case miniSkel::ACTION_LIMIT: $limit = 'LIMIT '.$criteria['begin'].','.$criteria['number']; break; case miniSkel::ACTION_MATCH_FIELD_BY_VALUE: $where .= ' AND '.$criteria['field'].' '.$criteria['comparison'].' "'. sqlite_escape_string($criteria['value']); break; default: break; } } $query .= $where . ' ' . $order . ' ' .$limit; $articles = $this->db->arrayQuery($query); foreach ($articles as $art) { $out .= $this->parseVariables($content, $art); } return $out; } protected function variableModifier_dateFormat($value) { return date('d/m/Y H:i', $value); } } $skel = new sqlSkel; if (!empty($_POST['add'])) { $skel->addArticle($_POST['title'], $_POST['text'], $_POST['name']); header('Location: ./sqlite.php'); exit; } $skel->assign('site_title', 'My web2.0 articles'); $skel->display('sqlite_example.tpl'); ?>