public function testConstructor() { @unlink(__DIR__ . '/test.sqlite'); $this->assertFalse(file_exists(__DIR__ . '/test.sqlite'), "File still exists."); $sql = new SQLite(__DIR__ . '/test.sqlite'); $sql->open(); $sql->close(); $this->assertTrue(file_exists(__DIR__ . '/test.sqlite'), "File not created."); }
/** * Update data. * @param $vo data. */ public function update(UserVO $vo) { $query = "UPDATE user SET "; $query .= "usr_name = " . SQLite::format($vo->getName()) . ", "; $query .= "usr_nick = " . SQLite::format($vo->getNick()) . ", "; $query .= "chn_id = " . SQLite::format($vo->getChannel()->getId()); $query .= " WHERE usr_id = " . SQLite::format($vo->getId()); }
public static function connect($cur_dir = "") { global $file_db; $db_exist = file_exists($cur_dir . WW_BDD . DB_FILE); $file_db = new PDO('sqlite:' . $cur_dir . WW_BDD . DB_FILE); $file_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if (!$db_exist) { SQLite::initData(); } }
$error = "Passwords do not match!"; $smarty->assign('register_username', $_POST['username']); } } } } } } } } if ($error) { $smarty->assign('registration_error', $error); $smarty->display('index.tpl.html'); exit; } $db = new SQLite($SQLITE_DB_PATH); $user_count_query = "SELECT COUNT(*) FROM users WHERE username = '******'username']}'"; $user_count = $db->fetchRowQuerySingle($user_count_query); if ($db->isError()) { $error = "Registration failed! There was a database error: " . $db->getError(); $smarty->assign('registration_error', $error); $smarty->assign('register_username', $_POST['username']); $smarty->display('index.tpl.html'); exit; } if ($user_count) { $error = "Username '{$_POST['username']}' already exists!\n" . "Please choose a different one!"; $smarty->assign('registration_error', $error); $smarty->assign('register_username', $_POST['username']); $smarty->display('index.tpl.html'); exit;
/** * Renders single row * * If you use for formatting then interact with template->set() directly * prior to calling parent * * @param SQLite $template template to use for row rendering * * @return string HTML of rendered template */ function rowRender($template) { foreach ($this->current_row as $key => $val) { if (isset($this->current_row_html[$key])) { continue; } $template->trySet($key, $val); } $template->setHTML($this->current_row_html); $template->trySet('id', $this->current_id); $o = $template->render(); foreach (array_keys($this->current_row) + array_keys($this->current_row_html) as $k) { $template->tryDel($k); } return $o; }
$profile = isset($profile) && $profile === false ? false : true; if (isset($mssql)) { if ($export = ci_load_database('mssql', $mssql, $query_builder, $profile)) { $export = new Database($export); } } elseif (isset($mysql)) { if ($export = ci_load_database('mysqli', $mysql, $query_builder, $profile)) { $export = new Database($export); } } elseif (isset($oracle)) { if ($export = ci_load_database('oci8', $oracle, $query_builder, $profile)) { $export = new Database($export); } } elseif (isset($postgre)) { if ($export = ci_load_database('postgre', $postgre, $query_builder, $profile)) { $export = new Database($export); } } elseif (isset($sqlite)) { $export = new SQLite($sqlite, $query_builder, $profile); } elseif (isset($fts)) { $export = array(); list($search, $values) = each($fts); $db = new SQLite(); $db->fts->create('results', 'search', 'porter'); $db->fts->upsert('results', 'search', $values); $db->query('SELECT docid, search FROM results WHERE search MATCH ?', array($search)); while (list($docid, $value) = $db->fetch('row')) { $export[$docid] = $value; } unset($db); }
header("Location: {$SITE_URL}"); exit; } require_once 'mysmarty.php'; require_once 'system/db.sqlite.php'; define('PAGE_NAME', 'page-site'); define('CACHE_TIME', 60); $site_name = $HandlerMatches[1]; $current_page = isset($HandlerMatches[2]) ? $HandlerMatches[2] : 1; $unique_page_name = PAGE_NAME . "{$site_name}-{$current_page}"; $smarty = new MySmarty(); if ($smarty->is_cached('index.tpl.html', $unique_page_name)) { $smarty->display('index.tpl.html', $unique_page_name); exit; } $db = new SQLite($SQLITE_DB_PATH); # Check if the requested site exists. # # $HandlerMatches is a global array defined index.php where the # request url was matched. # $escaped_site = $db->escape($HandlerMatches[1]); # find the sites to display # TODO: cache this (because it changes very rarely) # $site = $db->fetchRowQueryAssoc("SELECT id, name, sane_name, url FROM sites WHERE sane_name = '{$escaped_site}' AND visible = 1"); if ($db->isError()) { $smarty->assign('tpl_content', 'content-error.tpl.html'); $smarty->assign('error', 'Database error has occured: ' . $db->getError()); $smarty->display('index.tpl.html'); exit;
/** * Apply TD parameters to appropriate template * * You can pass row template to use too. That's useful to set up totals rows, for example. * * @param string $field Fieldname * @param SQLite $row_template Optional row template * * @return void */ function applyTDParams($field, &$row_template = null) { // data row template by default if (!$row_template) { $row_template =& $this->row_t; } // setting cell parameters (tdparam) $tdparam = @$this->tdparam[$this->getCurrentIndex()][$field]; $tdparam_str = ''; if (is_array($tdparam)) { if (is_array($tdparam['style'])) { $tdparam_str .= 'style="'; foreach ($tdparam['style'] as $key => $value) { $tdparam_str .= $key . ':' . $value . ';'; } $tdparam_str .= '" '; unset($tdparam['style']); } //walking and combining string foreach ($tdparam as $id => $value) { $tdparam_str .= $id . '="' . $value . '" '; } // set TD param to appropriate row template $row_template->set("tdparam_{$field}", trim($tdparam_str)); } }
error_reporting(E_ALL); if (!$included_from_index) { header("Location: {$SITE_URL}"); exit; } require_once 'mysmarty.php'; require_once 'system/db.sqlite.php'; define('PAGE_NAME', 'page-index'); define('CACHE_TIME', 60); $unique_page_name = PAGE_NAME; $smarty = new MySmarty(); if ($smarty->is_cached('index.tpl.html', $unique_page_name)) { $smarty->display('index.tpl.html', $unique_page_name); exit; } $db = new SQLite($SQLITE_DB_PATH); # find the sites to display # $sites = $db->fetchAllQueryAssoc('SELECT id, name, sane_name, url FROM sites WHERE visible = 1 ORDER BY priority ASC'); if ($db->isError()) { $smarty->assign('tpl_content', 'content-error.tpl.html'); $smarty->assign('error', 'Database error has occured: ' . $db->getError()); # TODO: figure out how not to cache a page $smarty->display('index.tpl.html'); exit; } # Fetch ITEMS_PER_INDEX_PAGE for each site # foreach ($sites as $site_idx => $site) { $item_query = "SELECT " . join(',', $ITEM_FIELDS) . " FROM items " . "WHERE site_id = {$site['id']} AND visible = 1 " . "ORDER BY date_added DESC, id DESC LIMIT {$ITEMS_PER_INDEX_PAGE}"; $items = $db->fetchAllQueryAssoc($item_query, 'id');
define("WW_CLASS", "class/"); require_once '../' . WW_CLASS . 'Constantes.class.php'; Constantes::repertoires(); /* * ********************************************************************** */ /* Classes nécéssaires au fonctionnement général de l'admin */ /* * ********************************************************************** */ require_once '../' . WW_CLASS . 'SQLite.class.php'; require_once '../' . WW_CLASS . 'BouletteManager.class.php'; require_once '../' . WW_CLASS . 'Collaborateur.class.php'; require_once '../' . WW_CLASS . 'Phrase.class.php'; require_once '../' . WW_CLASS . 'Boulette.class.php'; require_once '../' . WW_CLASS . 'RandomColor.class.php'; require_once '../' . WW_PLUGINS . 'autoload.php'; //Connection a la base de donnée Constantes::bdd(); SQLite::connect("../"); Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem('views'); $twig = new Twig_Environment($loader, array()); Constantes::config(); if (!isset($_GET['page'])) { $_GET['page'] = "dashboard"; } switch ($_GET['page']) { case "boulette": require_once __DIR__ . '/controllers/boulette/index.php'; break; case "collaborateur": require_once __DIR__ . '/controllers/collaborateur/index.php'; break; case "categorie":
*/ error_reporting(E_ALL); # TODO: decouple profile from password changing (move to separate files) if (!$included_from_index) { header("Location: {$SITE_URL}"); exit; } else { if (!isset($_SESSION['user_id'])) { header("Location: {$SITE_URL}"); exit; } } require_once 'mysmarty.php'; require_once 'system/db.sqlite.php'; $smarty = new MySmarty(); $db = new SQLite($SQLITE_DB_PATH); $smarty->assign('tpl_content', 'content-my-profile.tpl.html'); $smarty->assign('page_style', 'style-my-profile.css'); # Get the current information # $data_query = "SELECT data FROM users WHERE id = {$_SESSION['user_id']}"; $data_ser = $db->fetchRowQuerySingle($data_query); if ($db->isError()) { $smarty->assign('tpl_content', 'content-error.tpl.html'); $smarty->assign('error', 'There was a database error while getting your profile information: ' . $db->getError()); $smarty->display('index.tpl.html'); exit; } $data = array(); if ($data_ser) { $data = unserialize($data_ser);
$human_diff = "{$days} day" . ($days != 1 ? 's' : ''); } else { if ($time_diff >= 3600 * 24 * 30 && $time_diff < 3600 * 24 * 30 * 12) { $months = ceil($time_diff / 3600 / 24 / 30); $human_diff = "{$month} month" . ($months != 1 ? 's' : ''); } else { $years = ceil($time_diff / 3600 / 24 / 30 / 12); $human_diff = "{$years} year" . ($years != 1 ? 's' : ''); } } } } return 'aprox. ' . $human_diff; } $smarty = new MySmarty(); $db = new SQLite($SQLITE_DB_PATH); $smarty->assign('tpl_content', 'content-my-comments.tpl.html'); $smarty->assign('page_style', 'style-my-comments.css'); # Prepare data for navigation through pages [<prev] [1], [2], [3], etc, [next>] # $total_comments_query = "SELECT COUNT(*) FROM comments WHERE user_id = {$_SESSION['user_id']}"; $total_comments = $db->fetchRowQuerySingle($total_comments_query); if ($db->isError()) { $smarty->assign('tpl_content', 'content-error.tpl.html'); $smarty->assign('error', 'Database error has occured: ' . $db->getError()); $smarty->display('index.tpl.html'); exit; } $total_pages = ceil($total_comments / $COMMENTS_PER_MY_COMMENTS); $current_page = isset($HandlerMatches[1]) ? $HandlerMatches[1] : 1; if ($current_page > $total_pages) {
/** * Renders single row * * @param SQLite $template template to use for row rendering * * @return string HTML of rendered template */ function rowRender($template) { $template->trySet('width', $this->model->default_thumb_width); return parent::rowRender($template); }
function insert_defaults($dsn) { // {{{ $db = NewADOConnection($dsn); if (!$db) { die("Couldn't connect to \"{$dsn}\""); } else { if (substr($dsn, 0, 5) == "mysql") { $engine = new MySQL(); } else { if (substr($dsn, 0, 5) == "pgsql") { $engine = new PostgreSQL(); } else { if (substr($dsn, 0, 6) == "sqlite") { $engine = new SQLite(); } else { die("Unknown database engine; Shimmie currently officially supports MySQL\n\t\t\t(mysql://), with hacks for Postgres (pgsql://) and SQLite (sqlite://)"); } } } $engine->init($db); $config_insert = $db->Prepare("INSERT INTO config(name, value) VALUES(?, ?)"); $user_insert = $db->Prepare("INSERT INTO users(name, pass, joindate, admin) VALUES(?, ?, now(), ?)"); $db->Execute($user_insert, array('Anonymous', null, 'N')); $db->Execute($config_insert, array('anon_id', $db->Insert_ID())); if (check_im_version() > 0) { $db->Execute($config_insert, array('thumb_engine', 'convert')); } $db->Close(); } }
if (get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } $_POST = array_map('stripslashes_deep', $_POST); $_GET = array_map('stripslashes_deep', $_GET); $_COOKIE = array_map('stripslashes_deep', $_COOKIE); } # Let's see if the user had logged in previously but not in this session # if (isset($_COOKIE['user_id']) && isset($_COOKIE['md5_pass']) && !isset($_SESSION['user_id'])) { if (preg_match("#^\\d+\$#", $_COOKIE['user_id'])) { require_once 'system/db.sqlite.php'; $db = new SQLite($SQLITE_DB_PATH); $query = "SELECT username, password, can_login FROM users WHERE id = {$_COOKIE['user_id']}"; $user_info = $db->fetchRowQueryAssoc($query); if ($user_info && $user_info['can_login']) { if ($user_info['password'] == $_COOKIE['md5_pass']) { $_SESSION['user_id'] = $_COOKIE['user_id']; $_SESSION['username'] = $user_info['username']; $time = time(); $last_access_query = "UPDATE users set date_access = {$time} WHERE id= {$_COOKIE['user_id']}"; $db->query($last_access_query); } } } } $pages = array('#^/(?:index\\.(?:html|php))?$#' => 'page-index.php', '#^/site/(\\w+)(?:-(\\d+))?.html#' => 'page-site.php', '#^/item/([a-z0-9-]+).html#' => 'page-item.php', '#^/login.html#' => 'page-login.php', '#^/register.html#' => 'page-register.php', '#^/logout.html#' => 'page-logout.php', '#^/my-comments(?:-(\\d+))?.html#' => 'page-my-comments.php', '#^/my-profile.html#' => 'page-my-profile.php'); $parts = parse_url($_SERVER['REQUEST_URI']);
header("Content-type: image/gif"); print base64_decode($trans_gif_64); } function isPost() { return $_SERVER['REQUEST_METHOD'] == 'POST'; } if (!file_exists("enable_sqlite")) { sendWebBug(); exit; } if (!class_exists('SQLite')) { sendWebBug(); exit; } $sqlite = new SQLite('unittest2.dbf'); if (!$sqlite) { header("HTTP/1.0 500 Internal Server Error"); exit; } function getNextRequestId($sqlite, $token) { $requests = $sqlite->query_array("SELECT uri FROM requests WHERE token = \"{$token}\""); if (empty($requests)) { return 1; } return count($requests) + 1; } if (filesize(dirname(__FILE__) . '/unittest2.dbf') == 0) { try { $query = @$sqlite->exec('CREATE TABLE requests (requestid TEXT, token TEXT, ip TEXT, ts TEXT, uri TEXT, referer TEXT, ua TEXT)');
/** * Renders single row * * If you use for formatting then interact with template->set() directly * prior to calling parent * * @param SQLite $template template to use for row rendering * * @return string HTML of rendered template */ function rowRender($template) { foreach ($this->current_row as $key => $val) { if (isset($this->current_row_html[$key])) { continue; } $template->trySet($key, $val); } $template->setHTML($this->current_row_html); $template->trySet('id', $this->current_id); return $template->render(); }
$smarty->assign('login_username', $_POST['username']); } else { if (empty($_POST['password'])) { $error = "Password was left blank!"; $smarty->assign('login_username', $_POST['username']); } } } } } if ($error) { $smarty->assign('login_error', $error); $smarty->display('index.tpl.html'); exit; } $db = new SQLite($SQLITE_DB_PATH); $query = "SELECT id, password, can_login FROM users WHERE username = '******'username']}'"; $user_info = $db->fetchRowQueryAssoc($query); if ($db->isError()) { $error = "Login failed! There was a database error: " . $db->getError(); $smarty->assign('login_error', $error); $smarty->display('index.tpl.html'); exit; } if (!$user_info) { $error = "Username '{$_POST['username']}' does not exist!"; $smarty->assign('login_error', $error); $smarty->assign('login_username', $_POST['username']); $smarty->display('index.tpl.html'); exit; }
if (!$included_from_index) { header("Location: {$SITE_URL}"); exit; } require_once 'mysmarty.php'; require_once 'system/db.sqlite.php'; define('PAGE_NAME', 'page-item'); define('CACHE_TIME', 3600); $sane_item_title = $HandlerMatches[1]; $unique_page_name = PAGE_NAME . "{$sane_item_title}"; $smarty = new MySmarty(); if ($smarty->is_cached('index.tpl.html', $unique_page_name)) { $smarty->display('index.tpl.html', $unique_page_name); exit; } $db = new SQLite($SQLITE_DB_PATH); $comment_error = false; $add_comment = 0; if (isset($_POST['sane_title'])) { if (!preg_match("#^[a-z0-9-]+\$#", $_POST['sane_title']) || $_POST['sane_title'] != $sane_item_title) { # Title must be well formatted and must match the requested URL $comment_error = "The item title was invalid. Is there some hackery going on?!"; $smarty->assign('comment_error', $comment_error); $smarty->assign('existing_comment', isset($_POST['comment']) ? $_POST['comment'] : ''); } else { if (!isset($_POST['comment']) || empty($_POST['comment'])) { $comment_error = "No comment was typed. Please type what you wished and submit it again!"; $smarty->assign('comment_error', $comment_error); } else { if (!isset($_POST['botspam']) || $_POST['botspam'] != 2) { $comment_error = "No spam prevention code was entered!";
require_once dirname(__FILE__) . '/SQLite.php'; function sendWebBug() { $trans_gif_64 = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="; header("Content-type: image/gif"); print base64_decode($trans_gif_64); } if (!file_exists("enable_sqlite")) { sendWebBug(); exit; } if (!class_exists('SQLite')) { sendWebBug(); exit; } $sqlite = new SQLite('unittest.dbf'); if (!$sqlite) { header("HTTP/1.0 500 Internal Server Error"); exit; } if (filesize(dirname(__FILE__) . '/unittest.dbf') == 0) { try { $query = @$sqlite->exec('CREATE TABLE requests (token TEXT, ip TEXT, ts TEXT, uri TEXT, referer TEXT, ua TEXT)'); } catch (Exception $e) { header("HTTP/1.0 500 Internal Server Error"); exit; } } if (isset($_GET['requests'])) { $token = get_magic_quotes_gpc() ? stripslashes($_GET['requests']) : $_GET['requests']; $ua = $_SERVER['HTTP_USER_AGENT'];
// Même chose que error_reporting(E_ALL); ini_set('error_reporting', E_ALL); // Constantes nécéssaires au fonctionnement du script define("WW_CLASS", "class/"); require_once WW_CLASS . 'Constantes.class.php'; Constantes::repertoires(); /* * ********************************************************************** */ /* Classes nécéssaires au fonctionnement général du site */ /* * ********************************************************************** */ require_once WW_CLASS . 'SQLite.class.php'; require_once WW_CLASS . 'BouletteManager.class.php'; require_once WW_CLASS . 'Collaborateur.class.php'; require_once WW_CLASS . 'Phrase.class.php'; require_once WW_CLASS . 'Boulette.class.php'; require_once WW_CLASS . 'Categorie.class.php'; require_once WW_CLASS . 'RandomColor.class.php'; require_once WW_PLUGINS . 'autoload.php'; Constantes::config(); //Connection a la base de donnée Constantes::bdd(); SQLite::connect(); Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem('views'); $twig = new Twig_Environment($loader, array()); if (isset($_GET['page']) && intval($_GET['page']) > 1) { $page = intval($_GET['page']); } else { $page = 1; } $boulettes = BouletteManager::getBoulettes($page); echo $twig->render('index.html', array('name' => 'Boulettes Chouquettes', 'boulettes' => $boulettes, 'page' => $page));