2014-08-17 23:02:56 +02:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* 3words configuration file
|
|
|
|
*/
|
|
|
|
|
|
|
|
$MYSQL_SERVER = "localhost";
|
|
|
|
$MYSQL_DATABASE = "";
|
|
|
|
$MYSQL_USERNAME = "";
|
|
|
|
$MYSQL_PASSWORD = "";
|
|
|
|
|
|
|
|
// Please comment or delete the next line.
|
|
|
|
die('Please edit config.php!');
|
|
|
|
|
|
|
|
// Don't touch anything below here.
|
|
|
|
|
|
|
|
$sql = new mysqli($MYSQL_SERVER,
|
|
|
|
$MYSQL_USERNAME,
|
|
|
|
$MYSQL_PASSWORD,
|
|
|
|
$MYSQL_DATABASE);
|
|
|
|
|
|
|
|
if ($sql->connect_errno) {
|
|
|
|
echo '<!-- Failed to connect to MySQL server: ' . $sql->connect_error . ' ('
|
|
|
|
. $sql->connect_errno . ') --><style>*{background:red !important;}'
|
|
|
|
. '</style>';
|
|
|
|
}
|
|
|
|
|
|
|
|
// some useful functions
|
|
|
|
function gen_salt($length, $charset='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') {
|
|
|
|
$str = '';
|
|
|
|
$count = strlen($charset);
|
|
|
|
while ($length--) {
|
|
|
|
$str .= $charset[mt_rand(0, $count-1)];
|
|
|
|
}
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
function crypt_password ($pass, $salt) {
|
|
|
|
return crypt($pass, "$2y$08$" . $salt);
|
|
|
|
}
|
|
|
|
|
|
|
|
// the
|
|
|
|
session_start();
|
|
|
|
|
2014-08-18 14:51:00 +02:00
|
|
|
if (!isset($_SESSION['logged_in'])) {
|
|
|
|
$_SESSION['logged_in'] = false;
|
|
|
|
}
|
|
|
|
|
2014-08-17 23:02:56 +02:00
|
|
|
if (!isset($notemplate)) {
|
|
|
|
require_once 'ext/rain.tpl.class.php';
|
|
|
|
|
|
|
|
raintpl::configure("path_replace", false);
|
|
|
|
raintpl::configure("tpl_dir", "views/");
|
|
|
|
|
|
|
|
$tpl = new RainTPL;
|
2014-08-18 14:51:00 +02:00
|
|
|
|
|
|
|
// new words counter
|
|
|
|
$new_words_count = -1;
|
|
|
|
if ($_SESSION['logged_in'] === true) {
|
|
|
|
$res = $sql->query("SELECT `id` FROM `words` WHERE `new` = 1;");
|
|
|
|
$new_words_count = $res->num_rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
// total words count
|
|
|
|
$res = $sql->query("SELECT `id` FROM `words`;");
|
|
|
|
$words_total_count = $res->num_rows * 3;
|
|
|
|
|
|
|
|
// site name
|
|
|
|
$res = $sql->query("SELECT `value` FROM `config` WHERE `key` = \"sitename\";")->fetch_assoc();
|
|
|
|
$site_name = htmlspecialchars($res['value']);
|
|
|
|
|
2014-08-18 15:30:09 +02:00
|
|
|
// user name
|
|
|
|
$res = $sql->query("SELECT `value` FROM `config` WHERE `key` = \"username\";")->fetch_assoc();
|
|
|
|
$user_name = htmlspecialchars($res['value']);
|
|
|
|
|
2014-08-18 16:43:48 +02:00
|
|
|
// show recent?
|
|
|
|
$res = $sql->query("SELECT `value` FROM `config` WHERE `key` = \"recent_public\";")->fetch_assoc();
|
|
|
|
$recent_public = $res['value'] === "true" ? true : false;
|
2014-08-18 17:49:20 +02:00
|
|
|
$res = $sql->query("SELECT `value` FROM `config` WHERE `key` = \"recent_count\";")->fetch_assoc();
|
|
|
|
$recent_count = (int) $res['value'];
|
2014-08-18 16:43:48 +02:00
|
|
|
|
2014-08-18 15:07:41 +02:00
|
|
|
// the flash
|
|
|
|
$message = null;
|
|
|
|
if (isset($_SESSION['flash'])) {
|
|
|
|
$message = $_SESSION['flash'];
|
|
|
|
unset($_SESSION['flash']);
|
|
|
|
}
|
|
|
|
|
2014-08-18 14:51:00 +02:00
|
|
|
$tpl->assign("logged_in", $_SESSION['logged_in']);
|
|
|
|
$tpl->assign("site_name", $site_name);
|
2014-08-18 15:30:09 +02:00
|
|
|
$tpl->assign("user_name", $user_name);
|
2014-08-18 14:51:00 +02:00
|
|
|
$tpl->assign("words_total", $words_total_count);
|
|
|
|
$tpl->assign("inbox_count", $new_words_count);
|
2014-08-18 16:43:48 +02:00
|
|
|
$tpl->assign("recent_public", $recent_public);
|
|
|
|
$tpl->assign("recent_count", $recent_count);
|
2014-08-18 15:07:41 +02:00
|
|
|
$tpl->assign("message", $message);
|
2014-08-17 23:02:56 +02:00
|
|
|
}
|