. // Copyright © 2007-2014 Erwan Briand // // This program is free software: you can redistribute it and/or modify it // under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, version 3 only. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public // License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . /** * @file * This file contains the Texts class * * Update or get texts from database (like Terms of Use). */ /** * Texts class */ class Texts { private $ct_db; function __construct ($db) { $this->ct_db = $db; } /** * Update * * Create the text if not exists, else update it * @param $page * The name of the page. * @param $title * The title of the page. * @param $text * The content of the page. * @param $allow_nl2br * The nl2br rule. * @param $nickname * The nickname of the page author. * @param $date * The date (in datetime format). */ function update ($page, $title, $text, $allow_nl2br, $nickname, $date) { $idn = count($this->ct_db->select('texts', array('page' => $page), 'page')); if ($idn === 0) $this->ct_db->insert('texts', array('page' => $page, 'title' => $title, 'text' => $text, 'allow_nl2br' => $allow_nl2br, 'date' => $date, 'author' => $nickname, )); else $this->ct_db->update('texts', array('title' => $title, 'text' => $text, 'allow_nl2br' => $allow_nl2br, 'date' => $date, 'author' => $nickname, ), array('page' => $page)); } /** * Get * * Get the text from the database * @param $page * The name of the page. * @return * An array with the title, the text, the nl2br rule, the date and * the author. * Return FALSE if text not foud. */ function get ($page) { $req = $this->ct_db->select('texts', array('page' => $page), 'page, title, text, allow_nl2br, date, author'); if (count($req) == 1) return array('title' => $req[0]['title'], 'text' => $req[0]['text'], 'allow_nl2br' => $req[0]['allow_nl2br'], 'date' => $req[0]['date'], 'author' => $req[0]['author']); return FALSE; } } ?>