/** * Get information about the language. * * @param boolean $bOnlyActive Only active lang. Default: TRUE * @return object Language data. */ public function getInfos($bOnlyActive = true) { $oCache = (new Cache())->start(self::CACHE_GROUP, 'list' . $bOnlyActive, 172800); if (!($oData = $oCache->get())) { $sSqlWhere = $bOnlyActive ? 'WHERE active=\'1\'' : ''; $rStmt = Db::getInstance()->prepare('SELECT * FROM ' . DB::prefix('LanguagesInfo') . $sSqlWhere . ' ORDER BY name ASC'); $rStmt->execute(); $oData = $rStmt->fetchAll(\PDO::FETCH_OBJ); Db::free($rStmt); $oCache->put($oData); } unset($oCache); return $oData; }
/** * Get all modules status (enabled & disabled). * * @param string $sFolderName Name of the module folder. Default: NULL * @return object */ public function get($sFolderName = null) { $this->cache->start(static::CACHE_GROUP, 'list' . $sFolderName, static::CACHE_TIME); if (!($oData = $this->cache->get())) { $bIsFolderName = !empty($sFolderName); $sSelect = $bIsFolderName ? 'enabled' : '*'; $sSqlWhere = $bIsFolderName ? 'WHERE folderName = :modName LIMIT 1' : ''; $rStmt = Db::getInstance()->prepare('SELECT ' . $sSelect . ' FROM ' . DB::prefix('SysModsEnabled') . $sSqlWhere); if ($bIsFolderName) { $rStmt->bindValue(':modName', $sFolderName, \PDO::PARAM_STR); } $rStmt->execute(); $sFetchMethod = $bIsFolderName ? 'fetch' : 'fetchAll'; $oData = $rStmt->{$sFetchMethod}(\PDO::FETCH_OBJ); Db::free($rStmt); $this->cache->put($oData); } return $oData; }
static function setUpBeforeClass() { DB::open(array('master' => true, 'driver' => 'sqlite', 'file' => ':memory:')); DB::$prefix = 'elefant_'; $sql = sql_split(' create table #prefix#webpage ( id char(72) not null primary key, title char(72) not null, menu_title char(72) not null, window_title char(72) not null, access char(12) not null, layout char(48) not null, description text, keywords text, body text ); insert into #prefix#webpage (id, title, menu_title, window_title, access, layout, description, keywords, body) values ("index", "Welcome to Elefant", "Home", "", "public", "default", "", "", \'<table><tbody><tr><td><h3>Congratulations!</h3>You have successfully installed Elefant, the refreshingly simple new PHP web framework and CMS.</td><td><h3>Getting Started</h3>To log in as an administrator and edit pages, write a blog post, or upload files, go to <a href="/admin">/admin</a>.</td><td><h3>Developers</h3>Documentation, source code and issue tracking can be found at <a href="http://github.com/jbroadway/elefant">github.com/jbroadway/elefant</a></td></tr></tbody></table>\'); '); foreach ($sql as $query) { if (!DB::execute($query)) { die(DB::error()); } } }
$c->updateconfig('host', str); $c->updateconfig('dbuser', str); $c->updateconfig('dbpw', str); $c->updateconfig('database', str); $c->updateconfig('pconnect', int); $c->updateconfig('dbprefix', str); $c->updateconfig('dbsystem', str); $c->savedata(); ?> <div class="bfoot center">Database Settings saved!</div> <?php } require '../data/config.inc.php'; require_once '../classes/database/' . $config['dbsystem'] . '.inc.php'; $db = new DB($config['host'], $config['dbuser'], $config['dbpw'], $config['database'], $config['pconnect'], false, $config['dbprefix']); $db->pre = $db->prefix(); $db->connect(false); if (!is_resource($db->conn)) { ?> <div class="bbody">Could not connect to database! Pleasy try again later or check the database settings!</div> <div class="bfoot center"><a class="submit" href="index.php?step=<?php echo $step - 1; ?> ">Go back</a> <a class="submit" href="index.php?step=<?php echo $step; ?> ">Refresh</a></div> <?php } else { if (!$db->select_db()) { ?>
$file .= "\r\n.tooltip_body {\r\n\tpadding: 3px;\r\n}\r\n"; $filesystem->file_put_contents($path . 'standard.css', $file); } if ($path . 'ie.css') { $file = file_get_contents($path . 'ie.css'); $file .= "\r\n* html .tooltip {\r\n\twidth: 300px;\r\n}\r\n"; $filesystem->file_put_contents($path . 'ie.css', $file); } } } $dir->close(); echo "- Stylesheets updated.<br />"; // MySQL $file = 'package/' . $package . '/db/db_changes.sql'; $sql = file_get_contents($file); $sql = str_ireplace('{:=DBPREFIX=:}', $db->prefix(), $sql); $db->multi_query($sql); echo "- Database tables updated.<br />"; // Languages $ini = array('settings' => array('language' => array('compatible_version' => VISCACHA_VERSION), 'language_de' => array('compatible_version' => VISCACHA_VERSION)), 'global' => array('language' => array('upload_error_default' => null, 'upload_error_fileexists' => null, 'upload_error_maxfilesize' => null, 'upload_error_maximagesize' => null, 'upload_error_noaccess' => null, 'upload_error_noupload' => null, 'upload_error_wrongfiletype' => null, 'ats_select9' => null, 'ats_choose' => 'No Status', 'ats_choose_standard_a' => 'Use default setting (Article)', 'ats_choose_standard_n' => 'Use default setting (News)', 'profile_never' => 'Never'), 'language_de' => array('upload_error_default' => null, 'upload_error_fileexists' => null, 'upload_error_maxfilesize' => null, 'upload_error_maximagesize' => null, 'upload_error_noaccess' => null, 'upload_error_noupload' => null, 'upload_error_wrongfiletype' => null, 'ats_select9' => null, 'ats_choose' => 'Kein Status', 'ats_choose_standard_a' => 'Standardeinstellung nutzen (Artikel)', 'ats_choose_standard_n' => 'Standardeinstellung nutzen (News)', 'editprofile_about_longdesc' => 'Hier können Sie sich eine persönliche "Forenseite" erstellen.<br /><br />Sie können BB-Codes und maximal <em>{$chars}</em> Zeichen für die Seite nutzen.', 'profile_about' => 'Persönliche Seite', 'profile_never' => 'Nie'))); $c = new manageconfig(); $codes = array(); $keys = array('language', 'language_de'); $codes = getLangCodesByKeys($keys); $langcodes = getLangCodes(); foreach ($langcodes as $code => $lid) { $ldat = explode('_', $code); if (isset($codes[$ldat[0]])) { $count = count($codes[$ldat[0]]); if (in_array('', $codes[$ldat[0]])) { $count--;
public static function field($tree, $item) { $sql = ' INSERT INTO {{data}} SET tree=' . $tree . ', path=\'' . $item['path'] . '\', type=\'' . $item['type'] . '\', ' . $item['field'] . '=\'' . $item['value'] . '\', cdate=NOW(), num=' . $item['num'] . ', visible=1 '; if (Prepare::$show == 1) { print DB::prefix($sql); } else { DB::exec($sql); } }
// got the settings, save them $config = file_get_contents ('../conf/config.php'); $config = preg_replace ('/site_name = .*(?:\r\n|\r|\n)/', 'site_name = "' . $_POST['site_name'] . '"'. PHP_EOL, $config, 1); $config = preg_replace ('/email_from = .*(?:\r\n|\r|\n)/', 'email_from = "' . $_POST['email_from'] . '"'. PHP_EOL, $config, 1); $config = preg_replace ('/site_key = .*(?:\r\n|\r|\n)/', 'site_key = "' . md5 (uniqid (rand (), true)) . '"'. PHP_EOL, $config, 1); if (! file_put_contents ('../conf/config.php', $config)) { $data['error'] = __ ('Failed to write to conf/config.php'); } else { // create the admin user now $conf = parse_ini_file ('../conf/config.php', true); $conf['Database']['master']['master'] = true; if (isset ($conf['Database']['master']['file'])) { $conf['Database']['master']['file'] = '../' . $conf['Database']['master']['file']; } DB::$prefix = $conf['Database']['prefix']; if (! DB::open ($conf['Database']['master'])) { $data['error'] = DB::error (); } else { $date = gmdate ('Y-m-d H:i:s'); if (! DB::execute ( "update `#prefix#user` set `email` = ?, `password` = ?, `name` = ? where `id` = 1", $_POST['email_from'], encrypt_pass ($_POST['pass']), $_POST['your_name'] )) { $data['error'] = DB::error (); } else { $data['ready'] = true; }
/** * Connect to the databases. Will die if the master connect * fails, or if all connections fail, but will continue * as long as the master connection succeeds since that is * require to issue write commands. */ public static function load_connections() { $list = conf('Database'); self::$prefix = isset($list['prefix']) ? $list['prefix'] : ''; unset($list['prefix']); foreach ($list as $key => $conf) { if ($key == 'master') { $conf['master'] = true; } if (!self::open($conf)) { if ($conf['master'] === true) { // Die immediately if connection to master fails, // since we can't issue any write commands. die(self::$error); } } } // Die if no connections succeeded. if (self::count() === 0) { die(self::$error); } }
public function exec($sql) { try { $sql = DB::prefix($sql, 1); DB::$pdo->exec($sql); return DB::$pdo->lastInsertId(); } catch (PDOException $e) { print $e->getMessage(); die(DB::error($sql, debug_backtrace())); } }
public function exec($sql) { $sql = DB::prefix($sql, 1); mysql_query($sql) or die(DB::error($sql, debug_backtrace())); return mysql_insert_id(); }
} require_once 'apps/cli/lib/Functions.php'; // set the necessary folder permissions system('chmod -R 777 cache conf css files lang layouts'); system('chmod 777 apps'); // update config file $config_plain = file_get_contents('conf/config.php'); $config_plain = preg_replace('/site_key = .*/', 'site_key = "' . md5(uniqid(rand(), true)) . '"', $config_plain, 1); if (!file_put_contents('conf/config.php', $config_plain)) { // currently it is not error, just warning Cli::out('** Warning: Failed to write to conf/config.php.'); } $conf = parse_ini_file('conf/config.php', true); // connect to the database $connected = false; DB::$prefix = isset($conf['Database']['prefix']) ? $conf['Database']['prefix'] : ''; unset($conf['Database']['prefix']); foreach (array_keys($conf['Database']) as $key) { if ($key == 'master') { $conf['Database'][$key]['master'] = true; if (!DB::open($conf['Database'][$key])) { Cli::out('** Error: Could not connect to the database. Please check the', 'error'); Cli::out(' settings in conf/config.php and try again.', 'error'); echo "\n"; Cli::out(' ' . DB::error(), 'error'); return; } $connected = true; break; } }
public static function connect($host, $name, $user, $pass, $prefix) { if (self::$connected) { return; } // establishing connection $link = @mysql_connect($host, $user, $pass); // on errors if (!$link) { throw new WMException('Nie mogę połączyć się z bazą danych (mysql_connect zwrócił błąd: ' . mysql_error() . ')', 'DB:connectError'); } if (!@mysql_select_db($name)) { throw new WMException('Nie mogę połączyć się z bazą danych (mysql_select_db zwrócił błąd: ' . mysql_error() . ')', 'DB:selectError'); } // settings self::query("SET NAMES 'utf8'"); self::$connected = true; self::$prefix = $prefix; }
/** * Method to set a prefix * * @param string $prefix Contains a tableprefix */ public function setPrefix($prefix = '') { self::$prefix = $prefix; return $this; }
public static function execSql($sql) { if (strpos(strtolower($sql), 'delete') !== false || strpos(strtolower($sql), 'insert') !== false || strpos(strtolower($sql), 'update') !== false) { $q = mysql_query(DB::prefix($sql)); if ($q) { return array(0 => array('Ответ' => 'Запрос выполнен успешно')); } else { return array(0 => array('Ошибка' => mysql_error())); } } else { $data = array(); $q = mysql_query(DB::prefix($sql)); if ($q) { while ($row = mysql_fetch_assoc($q)) { if ($one == '') { $data[] = $row; } else { $data[] = $row[$one]; } } return $data; } else { return array(0 => array('Ошибка' => mysql_error())); } } }