diff --git a/ajax.php b/ajax.php
old mode 100644
new mode 100755
index dcca3dc..0b6b176
--- a/ajax.php
+++ b/ajax.php
@@ -5,24 +5,24 @@ $ajax = new Ajax();
try {
$ajax->token();
-
+
// Prepare inputs
$request = array_merge(@$_POST, @$_GET);
if(empty($request["action"])){
throw new Exception("No action specified.");
}
-
+
$method = ['Post', $request["action"]];
-
+
// If method exists
if(!is_callable($method)){
throw new Exception("Method was not found.");
}
-
+
// CAll method
$response = call_user_func($method, $request);
$ajax->set_response($response);
-
+
// Log
Log::put("ajax_access", $request["action"]);
} catch (Exception $e) {
diff --git a/app/ajax.class.php b/app/ajax.class.php
old mode 100644
new mode 100755
index 9a349ab..ad8310f
--- a/app/ajax.class.php
+++ b/app/ajax.class.php
@@ -3,22 +3,22 @@
class Ajax
{
private $_response = null;
-
+
public function set_error($msg = null){
$this->_response = [
"error" => true,
"msg" => $msg
];
-
+
// Log
Log::put("ajax_errors", $msg);
}
-
+
public function token(){
if(empty($_SESSION['token'])){
throw new Exception("Direct access violation.");
}
-
+
$headers = apache_request_headers();
if(!isset($headers['Csrf-Token']) && !isset($headers['csrf-token'])){
throw new Exception("No CSRF token.");
@@ -28,11 +28,11 @@ class Ajax
throw new Exception("Wrong CSRF token.");
}
}
-
+
public function set_response($response = null){
$this->_response = $response;
}
-
+
public function json_response(){
ob_clean();
header('Content-Type: application/json');
diff --git a/app/config.class.php b/app/config.class.php
old mode 100644
new mode 100755
index 8d6ce02..615c332
--- a/app/config.class.php
+++ b/app/config.class.php
@@ -3,17 +3,17 @@
class Config
{
private static $_settings = null;
-
+
private static function init(){
$config_file = PROJECT_PATH.'config.ini';
-
+
if(!is_readable($config_file)){
throw new ConfigException('Cannot read config file');
}
-
+
self::$_settings = parse_ini_file($config_file);
$custom_config = PROJECT_PATH.'custom.ini';
-
+
if(is_readable($custom_config)){
$custom = parse_ini_file($custom_config);
if($custom !== false){
@@ -21,26 +21,26 @@ class Config
}
}
}
-
+
public static function get($key){
if(self::$_settings === null){
self::init();
}
-
+
if(!array_key_exists($key, self::$_settings)){
throw new ConfigException(sprintf('Key "%s" not found in settings.', $key));
}
-
+
return self::$_settings[$key];
}
-
+
public static function get_safe($key, $default = ''){
try {
$value = self::get($key);
} catch (ConfigException $e) {
$value = $default;
}
-
+
return $value;
}
}
diff --git a/app/db.class.php b/app/db.class.php
index 7daa819..85f8dc3 100755
--- a/app/db.class.php
+++ b/app/db.class.php
@@ -4,30 +4,30 @@
class DB
{
private static $_instance = null;
-
+
private $_PDO;
private $_query;
-
+
private $_query_counter;
-
+
// Handle instances
public final static function get_instance(){
if(self::$_instance === null){
self::$_instance = new static();
}
-
+
return self::$_instance;
}
-
+
// Initialise PDO object
private final function __construct(){
$host = Config::get_safe('mysql_host', false);
$socket = Config::get_safe('mysql_socket', false);
-
+
if($socket === false && $host === false){
throw new DBException("Mysql host or socket must be defined");
}
-
+
// Try to connect
try {
$this->_PDO = new \PDO(
@@ -46,29 +46,29 @@ class DB
} catch (PDOException $e) {
throw new DBException($e->getMessage());
}
-
+
// When is this not set, chat does dot work, odd behavior
$this->_PDO->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
-
+
// Throwing exceptions
$this->_PDO->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
//$this->_PDO->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
}
-
+
// Just flattern array to be binded : [key1, key2, [key3, [key4]]] => [key1, key2, key3, key4]
private final function bind_value($key, $value){
if(is_array($value)){
foreach($value as $one_value){
$key = $this->bind_value($key, $one_value);
}
-
+
return $key;
}
-
+
$this->_query->bindValue($key, $value);
return ++$key;
}
-
+
// Process Query
// query ($sql)
// query ($sql, $bind_param_01, $bind_param_02, ...)
@@ -76,49 +76,49 @@ class DB
public final function query(){
// Second parm is binded values
$params = func_get_args();
-
+
// First parameter is sql
$sql = $params[0];
unset($params[0]);
-
+
// Debug mode
if(Config::get_safe('debug', false)){
echo "\n";
}
-
+
// Try to prepare MySQL statement
try {
// Prepare PDO statement
$this->_query = $this->_PDO->prepare($sql);
-
+
// Bind values
$this->bind_value(1, $params);
-
+
// Execute
$this->_query->execute();
} catch (PDOException $e) {
throw new DBException($e->getMessage());
}
-
+
$this->_query_counter++;
return $this;
}
-
+
// Insert into table
public final function insert($table_name, $fields = null){
// If empty line
if(empty($fields)){
return $this->query("INSERT INTO `{$table_name}` () VALUES ()");
}
-
+
// If multiple
if(isset($fields[0])){
// Turn array into PDO prepered statement format
$keys = array_keys($fields[0]);
-
+
// Build query
$query = "INSERT INTO `{$table_name}` (`".implode('`, `', $keys)."`) VALUES ";
-
+
// Insert values
$first = true;
$prepared_data = array();
@@ -128,10 +128,10 @@ class DB
} else {
$query .= ',';
}
-
+
end($field);
$last_key = key($field);
-
+
$query .= '(';
foreach($field as $key => $value){
if($value === "NOW()"){
@@ -140,22 +140,22 @@ class DB
$query .= '?';
$prepared_data[] = $value;
}
-
+
if($last_key != $key){
$query .= ',';
}
}
$query .= ')';
}
-
+
// Execute query
return $this->query($query, $prepared_data);
}
-
+
// If only single
return $this->insert($table_name, array($fields));
}
-
+
// Update table
// update ($table_name, $fields)
// update ($table_name, $fields, $sql)
@@ -164,27 +164,27 @@ class DB
public final function update(){
// Fourt param is binded values
$params = func_get_args();
-
+
// First is table_name
$table_name = $params[0];
unset($params[0]);
-
+
// Second is fields
$fields = $params[1];
unset($params[1]);
-
+
// Third is sql
$sql = $params[2];
unset($params[2]);
-
+
// If fields are not array, do nothing
if(!is_array($fields)){
return $this;
}
-
+
end($fields);
$last_key = key($fields);
-
+
// Support for NOW()
$prepared_data = array();
$set_data = null;
@@ -195,61 +195,61 @@ class DB
$set_data .= "`{$key}` = ?";
$prepared_data[] = $value;
}
-
+
if($last_key != $key){
$set_data .= ',';
}
}
-
+
// If params are not array, make it
if(!is_array($params)){
$params = array($params);
}
-
+
// Merge fields array and additional SQL data
foreach($params as $param){
$prepared_data[] = $param;
}
-
+
// Build query
$query = "UPDATE `{$table_name}` SET {$set_data} ".$sql;
-
+
// Execute query
return $this->query($query, $prepared_data);
}
-
+
// Alias for all
public final function results(){
trigger_error("Using deprecated method DB::results();. Use DB::all(); instead.");
return $this->all();
}
-
+
// Get all rows
public final function all($type = \PDO::FETCH_ASSOC){
return $this->_query->fetchAll($type);
}
-
+
// Get all values to one dimensional array
public final function columns($column = 0){
return $this->_query->fetchAll(\PDO::FETCH_COLUMN, $column);
}
-
+
// Get first row from result
public final function first($key = null){
$results = $this->all();
-
+
if($key !== null){
return @$results[0][$key];
}
-
+
return @$results[0];
}
-
+
// Get last inserted ID
public final function last_id(){
return $this->_PDO->lastInsertId();
}
-
+
// Exec
public final function exec($sql){
// Try to execute MySQL
@@ -258,10 +258,10 @@ class DB
} catch (PDOException $e) {
throw new DBException($e->getMessage());
}
-
+
return $this;
}
-
+
public final function total_queries(){
return $this->_query_counter;
}
diff --git a/app/image.class.php b/app/image.class.php
index ffed463..5dd8e84 100755
--- a/app/image.class.php
+++ b/app/image.class.php
@@ -6,11 +6,11 @@ class Image
$chr = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$chr_len = strlen($chr);
$random_str = '';
-
+
for($i = 0; $i < $len; $i++){
$random_str .= $chr[rand(0, $chr_len - 1)];
}
-
+
return $random_str;
}
@@ -46,14 +46,14 @@ class Image
private static function thumb($source_path, $thumb_path){
ini_set('memory_limit', '128M');
-
+
$thumb_w = 476;
$thumb_h = 476;
-
+
$source_details = getimagesize($source_path);
$source_w = $source_details[0];
$source_h = $source_details[1];
-
+
if($source_w > $source_h){
$new_w = $thumb_w;
$new_h = intval($source_h * $new_w / $source_w);
@@ -67,25 +67,25 @@ class Image
$imgt = "ImageGIF";
$imgcreatefrom = "ImageCreateFromGIF";
break;
-
+
case IMAGETYPE_JPEG:
$imgt = "ImageJPEG";
$imgcreatefrom = "ImageCreateFromJPEG";
break;
-
+
case IMAGETYPE_PNG:
$imgt = "ImagePNG";
$imgcreatefrom = "ImageCreateFromPNG";
break;
-
+
default:
return false;
}
-
+
$old_image = $imgcreatefrom($source_path);
$new_image = imagecreatetruecolor($new_w, $new_h);
imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_w, $new_h, $source_w, $source_h);
-
+
$new_image = self::fix_orientation($source_path, $new_image);
$old_image = self::fix_orientation($source_path, $old_image);
@@ -93,7 +93,7 @@ class Image
$imgt($old_image, $source_path);
return true;
}
-
+
public static function upload(){
if(!$_FILES){
throw new Exception("No file.");
@@ -101,12 +101,12 @@ class Image
// Create MD5
$md5 = md5_file($_FILES['file']['tmp_name']);
-
+
// Find duplicate
if($d = DB::get_instance()->query("SELECT `path`, `thumb` FROM `images` WHERE `md5` = ? AND `status` = 1 LIMIT 1", $md5)->first()){
return $d;
}
-
+
// Get metadata
$name = $_FILES['file']['name'];
$ext = pathinfo($name, PATHINFO_EXTENSION);
@@ -118,18 +118,18 @@ class Image
"VALUES (NULL, ?, NULL, NULL, ?, ?, NOW(), 1);",
$name, $ext, $md5
)->last_id();
-
+
// Create path name
$name = dechex($id).self::random_str(3).".".$ext;
$path = 'i/'.$name;
$thumb = 't/'.$name;
-
+
// Save path
if(!move_uploaded_file($_FILES['file']['tmp_name'], $path)){
DB::get_instance()->query("UPDATE `images` SET `status` = 0 WHERE `id` = ?", $id);
throw new Exception("Can't write to image folders `i` and `t`.");
}
-
+
// Create thumb
if(!self::thumb($path, $thumb)){
DB::get_instance()->query("UPDATE `images` SET `status` = 0 WHERE `id` = ?", $id);
@@ -137,7 +137,7 @@ class Image
unlink($thumb);
throw new Exception("File is not image.");
}
-
+
// Save to DB
DB::get_instance()->query("UPDATE `images` SET `path` = ?, `thumb` = ?, `status` = 1 WHERE `id` = ?", $path, $thumb, $id);
return [
diff --git a/app/jbbcode/CodeDefinitionBuilder.php b/app/jbbcode/CodeDefinitionBuilder.php
old mode 100644
new mode 100755
index 6e8bbc1..80e4aed
--- a/app/jbbcode/CodeDefinitionBuilder.php
+++ b/app/jbbcode/CodeDefinitionBuilder.php
@@ -156,5 +156,4 @@ class CodeDefinitionBuilder
return $definition;
}
-
}
diff --git a/app/jbbcode/tests/HTMLSafeTest.php b/app/jbbcode/tests/HTMLSafeTest.php
old mode 100644
new mode 100755
index bd9391b..532ee35
--- a/app/jbbcode/tests/HTMLSafeTest.php
+++ b/app/jbbcode/tests/HTMLSafeTest.php
@@ -24,7 +24,7 @@ class HTMLSafeTest extends PHPUnit_Framework_TestCase
$this->assertEquals($html, $parser->getAsHtml());
}
-
+
/**
* Tests escaping quotes and ampersands in simple text
*/
diff --git a/app/jbbcode/tests/ParseContentTest.php b/app/jbbcode/tests/ParseContentTest.php
old mode 100644
new mode 100755
index 1ea2c78..5b9d951
--- a/app/jbbcode/tests/ParseContentTest.php
+++ b/app/jbbcode/tests/ParseContentTest.php
@@ -32,7 +32,7 @@ class ParseContentTest extends PHPUnit_Framework_TestCase
public function testNoParsingWithBufferText()
{
-
+
$parser = new JBBCode\Parser();
$parser->addCodeDefinitionSet(new JBBCode\DefaultCodeDefinitionSet());
$parser->addBBCode('verbatim', '{param}', false, false);
@@ -48,7 +48,7 @@ class ParseContentTest extends PHPUnit_Framework_TestCase
*/
public function testUnclosedTag()
{
-
+
$parser = new JBBCode\Parser();
$parser->addCodeDefinitionSet(new JBBCode\DefaultCodeDefinitionSet());
$parser->addBBCode('verbatim', '{param}', false, false);
diff --git a/app/jbbcode/tests/SimpleEvaluationTest.php b/app/jbbcode/tests/SimpleEvaluationTest.php
old mode 100644
new mode 100755
index 65fb236..7f32ba9
--- a/app/jbbcode/tests/SimpleEvaluationTest.php
+++ b/app/jbbcode/tests/SimpleEvaluationTest.php
@@ -28,7 +28,6 @@ class SimpleEvaluationTest extends PHPUnit_Framework_TestCase
$this->assertEquals($html, $this->defaultParse($bbcode));
}
-
public function testEmptyString()
{
$this->assertProduces('', '');
diff --git a/app/jbbcode/visitors/NestLimitVisitor.php b/app/jbbcode/visitors/NestLimitVisitor.php
old mode 100644
new mode 100755
index f550dd0..c430b7a
--- a/app/jbbcode/visitors/NestLimitVisitor.php
+++ b/app/jbbcode/visitors/NestLimitVisitor.php
@@ -37,7 +37,7 @@ class NestLimitVisitor implements \JBBCode\NodeVisitor
public function visitElementNode(\JBBCode\ElementNode $elementNode)
{
$tagName = strtolower($elementNode->getTagName());
-
+
/* Update the current depth for this tag name. */
if (isset($this->depth[$tagName])) {
$this->depth[$tagName]++;
diff --git a/app/lang.class.php b/app/lang.class.php
old mode 100644
new mode 100755
index b85c84c..d5dbe3f
--- a/app/lang.class.php
+++ b/app/lang.class.php
@@ -3,19 +3,19 @@
class Lang
{
private static $_dictionary = null;
-
+
public static function load($lang = 'en'){
$lang_file = APP_PATH.'lang/'.$lang.'.ini';
if(preg_match('/^[a-z]+$/', $lang) && is_readable($lang_file)){
self::$_dictionary = parse_ini_file($lang_file);
}
}
-
+
public static function get($key){
if(!array_key_exists($key, self::$_dictionary)){
return $key;
}
-
+
return self::$_dictionary[$key];
}
}
diff --git a/app/log.class.php b/app/log.class.php
index 9730767..4da4c38 100755
--- a/app/log.class.php
+++ b/app/log.class.php
@@ -8,9 +8,9 @@ class Log
"login_fails",
"visitors"
];
-
+
private static $_path = 'data/logs/';
-
+
public static function put($_file, $_text = null){
if(!Config::get_safe("logs", false) || !in_array($_file, static::$_files)){
return ;
@@ -20,7 +20,7 @@ class Log
die(sprintf("Can't write to %s.log file.", $_file));
}
}
-
+
private static function line($_text = null){
return date('Y-m-d H:i:s')."\t".$_SERVER["REMOTE_ADDR"]."\t".$_SERVER["HTTP_USER_AGENT"].($_text ? "\t".$_text : "").PHP_EOL;
}
diff --git a/app/post.class.php b/app/post.class.php
index 1824d3e..6c0c068 100755
--- a/app/post.class.php
+++ b/app/post.class.php
@@ -13,7 +13,7 @@ class Post
$parser = new JBBCode\Parser();
$parser->addCodeDefinitionSet(new JBBCode\DefaultCodeDefinitionSet());
-
+
if(Config::get("highlight")){
$c = str_replace("\t", " ", $c);
$c = preg_replace("/\[code(?:=([^\[]+))?\]\s*?(?:\n|\r)?/i", '[code=$1]', $c);
@@ -27,7 +27,7 @@ class Post
$this->setParseContent(false);
$this->setUseOption(true);
}
-
+
public function asHtml(\JBBCode\ElementNode $el){
$content = $this->getContent($el);
return ''.htmlentities($content).'
';
@@ -59,7 +59,7 @@ class Post
$child->accept($this);
}
}
-
+
function visitTextNode(\JBBCode\TextNode $textNode){
$c = $textNode->getValue();
$c = preg_replace('/\"([^\"]+)\"/i', "„$1\"", $c);
@@ -70,7 +70,7 @@ class Post
$c = nl2br($c);
$textNode->setValue($c);
}
-
+
function visitElementNode(\JBBCode\ElementNode $elementNode){
/* We only want to visit text nodes within elements if the element's
* code definition allows for its content to be parsed.
@@ -85,7 +85,7 @@ class Post
return $parser->getAsHtml();
}
-
+
private static function raw_data($raw_input){
$default_input = [
"text" => '',
@@ -97,7 +97,7 @@ class Post
"content" => '',
"privacy" => ''
];
-
+
// Handle only allowed keys
$raw_output = array();
foreach($default_input as $key => $def){
@@ -108,11 +108,11 @@ class Post
$raw_output[$key] = $default_input[$key];
}
}
-
+
if($raw_output['privacy'] != "public" && $raw_output['privacy'] != "friends"){
$raw_output['privacy'] = "private";
}
-
+
return $raw_output;
}
@@ -120,7 +120,7 @@ class Post
self::login_protected();
$data = self::raw_data($r);
-
+
if(empty($data['text'])){
throw new Exception(__("No data."));
}
@@ -129,12 +129,12 @@ class Post
$data['text'] = self::parse_content($data['text']);
$data['datetime'] = 'NOW()';
$data['status'] = '1';
-
+
$data['id'] = DB::get_instance()->insert('posts', $data)->last_id();
-
+
$data['datetime'] = date("d M Y H:i");
unset($data['plain_text']);
-
+
return $data;
}
@@ -142,60 +142,60 @@ class Post
self::login_protected();
$data = self::raw_data($r);
-
+
$data['plain_text'] = $data['text'];
$data['text'] = self::parse_content($data['text']);
-
+
DB::get_instance()->update('posts', $data, "WHERE `id` = ? AND `status` = 1", $r["id"]);
-
+
unset($data['plain_text']);
-
+
return $data;
}
-
+
public static function hide($r){
self::login_protected();
-
+
DB::get_instance()->query("UPDATE `posts` SET `status` = 4 WHERE `id` = ?", $r["id"]);
return true;
}
-
+
public static function delete($r){
self::login_protected();
-
+
DB::get_instance()->query("UPDATE `posts` SET `status` = 5 WHERE `id` = ?", $r["id"]);
return true;
}
-
+
public static function edit_data($r){
self::login_protected();
-
+
return DB::get_instance()->query("SELECT `plain_text`, `feeling`, `persons`, `location`, `privacy`, `content_type`, `content` FROM `posts` WHERE `id` = ? AND `status` = 1", $r["id"])->first();
}
-
+
public static function get_date($r){
self::login_protected();
-
+
$date = DB::get_instance()->query("SELECT DATE_FORMAT(`datetime`,'%Y %c %e %k %i') AS `date_format` FROM `posts` WHERE `id` = ? AND `status` = 1", $r["id"])->first("date_format");
$date = array_map("intval", explode(" ", $date));
$date[4] = floor($date[4]/10)*10;
return $date;
}
-
+
public static function set_date($r){
self::login_protected();
-
+
$d = $r["date"];
$datetime = "{$d[0]}/{$d[1]}/{$d[2]} {$d[3]}:{$d[4]}";
DB::get_instance()->query("UPDATE `posts` SET `datetime` = ? WHERE `id` = ? AND `status` = 1", $datetime, $r["id"]);
return [ "datetime" => date("d M Y H:i", strtotime($datetime)) ];
}
-
+
public static function parse_link($r){
self::login_protected();
-
+
$l = $r["link"];
-
+
preg_match('/^https?:\/\/([^:\/\s]+)([^\/\s]*\/)([^\.\s]+)\.(jpe?g|png|gif)((\?|\#)(.*))?$/i', $l, $img);
if($img){
return [
@@ -207,9 +207,9 @@ class Post
]
];
}
-
+
preg_match('/^https?:\/\/(www\.)?([^:\/\s]+)(.*)?$/i', $l, $url);
-
+
// Get content
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
@@ -220,15 +220,15 @@ class Post
curl_setopt($ch, CURLOPT_REFERER, '');
$html = curl_exec($ch);
curl_close($ch);
-
+
// Parse
$doc = new DOMDocument();
@$doc->loadHTML(''.$html);
-
+
// Get title
$nodes = $doc->getElementsByTagName('title');
$title = $nodes->item(0)->nodeValue;
-
+
// Content
$content = [
"link" => $l,
@@ -236,54 +236,54 @@ class Post
"is_video" => false,
"host" => $url[2]
];
-
+
// Metas
$metas = $doc->getElementsByTagName('meta');
for($i = 0; $i < $metas->length; $i++){
$meta = $metas->item($i);
-
+
$n = $meta->getAttribute('name');
$p = $meta->getAttribute('property');
$c = $meta->getAttribute('content');
-
+
if($n == 'twitter:description' || $p == 'og:description' || $n == 'description'){
$content["desc"] = substr($c, 0, 180);
}
-
+
if($n == 'twitter:title' || $p == 'og:title' || $p == 'title'){
$content["title"] = $c;
}
-
+
if($p == 'og:url'){
$content["link"] = $c;
}
-
+
if($p == 'og:type'){
$content["is_video"] = ($c == "video");
}
-
+
if($n == 'twitter:image:src' || $p == 'og:image'){
$content["thumb"] = $c;
}
-
+
if($n == 'twitter:domain'){
$content["host"] = $c;
}
}
-
+
return [
"valid" => true,
"content_type" => "link",
"content" => $content
];
}
-
+
public static function upload_image(){
self::login_protected();
-
+
return Image::upload();
}
-
+
public static function load($r){
$until = [];
if(preg_match("/^[0-9]{4}-[0-9]{2}$/", $r["filter"]["until"])){
@@ -298,7 +298,7 @@ class Post
if($r["filter"]["id"]){
$id = intval($r["filter"]["id"]);
}
-
+
$tag = [];
if(preg_match("/^[A-Za-z0-9-_]+$/", $r["filter"]["tag"])){
$tag = '#'.$r["filter"]["tag"];
@@ -329,15 +329,15 @@ class Post
"LIMIT ? OFFSET ?", $until, $id, $tag, $loc, $person, $r["limit"], $r["offset"]
)->all();
}
-
+
public static function login($r){
return User::login($r["nick"], $r["pass"]);
}
-
+
public static function logout(){
return User::logout();
}
-
+
public static function handshake($r){
return ["logged_in" => User::is_logged_in(), "is_visitor" => User::is_visitor()];
}
diff --git a/app/splclassloader.class.php b/app/splclassloader.class.php
old mode 100644
new mode 100755
index c1a45c6..8112287
--- a/app/splclassloader.class.php
+++ b/app/splclassloader.class.php
@@ -22,7 +22,7 @@ class SplClassLoader
private $_includePath;
private $_namespaceSeparator = '\\';
private $_excludeNs;
-
+
/**
* Creates a new SplClassLoader that loads classes of the
* specified namespace.
@@ -33,7 +33,7 @@ class SplClassLoader
$this->_namespace = $ns;
$this->_includePath = $includePath;
}
-
+
/**
* Sets the namespace separator used by classes in the namespace of this class loader.
*
@@ -42,11 +42,11 @@ class SplClassLoader
public function setNamespaceSeparator($sep) {
$this->_namespaceSeparator = $sep;
}
-
+
public function setExcludeNs($exclude) {
$this->_excludeNs = $exclude;
}
-
+
/**
* Gets the namespace seperator used by classes in the namespace of this class loader.
*
@@ -55,7 +55,7 @@ class SplClassLoader
public function getNamespaceSeparator() {
return $this->_namespaceSeparator;
}
-
+
/**
* Sets the base include path for all class files in the namespace of this class loader.
*
@@ -64,7 +64,7 @@ class SplClassLoader
public function setIncludePath($includePath) {
$this->_includePath = $includePath;
}
-
+
/**
* Gets the base include path for all class files in the namespace of this class loader.
*
@@ -73,7 +73,7 @@ class SplClassLoader
public function getIncludePath() {
return $this->_includePath;
}
-
+
/**
* Sets the file extension of class files in the namespace of this class loader.
*
@@ -82,7 +82,7 @@ class SplClassLoader
public function setFileExtension($fileExtension) {
$this->_fileExtension = $fileExtension;
}
-
+
/**
* Gets the file extension of class files in the namespace of this class loader.
*
@@ -91,21 +91,21 @@ class SplClassLoader
public function getFileExtension() {
return $this->_fileExtension;
}
-
+
/**
* Installs this class loader on the SPL autoload stack.
*/
public function register() {
spl_autoload_register(array($this, 'loadClass'));
}
-
+
/**
* Uninstalls this class loader from the SPL autoloader stack.
*/
public function unregister() {
spl_autoload_unregister(array($this, 'loadClass'));
}
-
+
/**
* Loads the given class or interface.
*
@@ -116,27 +116,27 @@ class SplClassLoader
if (!empty($this->_excludeNs)) {
$className = str_replace($this->_excludeNs, '', $className);
}
-
+
if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) {
$fileName = '';
$namespace = '';
-
+
if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
-
+
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension;
-
+
$fileName = strtolower($fileName);
-
+
$full = ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;
-
+
if (!file_exists($full)) {
throw new Exception("Class file for '".$className."' not found");
}
-
+
require $full;
}
}
diff --git a/app/user.class.php b/app/user.class.php
index 04d0bf0..7e36e21 100755
--- a/app/user.class.php
+++ b/app/user.class.php
@@ -3,12 +3,12 @@
class user
{
const SESSION_NAME = "logged_in";
-
+
public static function is_visitor(){
if(!Config::get_safe("force_login", false)){
return true;
}
-
+
return !empty($_SESSION[User::SESSION_NAME]) && $_SESSION[User::SESSION_NAME] === 'visitor';
}
@@ -16,19 +16,19 @@ class user
if(!Config::get_safe("force_login", false)){
return true;
}
-
+
return !empty($_SESSION[User::SESSION_NAME]) && $_SESSION[User::SESSION_NAME] === hash("crc32", Config::get("nick").Config::get_safe("pass", ""), false);
}
-
+
public static function login($nick, $pass){
if(!Config::get_safe("force_login", false)){
return true;
}
-
+
if(self::is_logged_in()){
throw new Exception(__("You are already logged in."));
}
-
+
if(Config::get("nick") === $nick && Config::get_safe("pass", "") === $pass){
$_SESSION[User::SESSION_NAME] = hash("crc32", $nick.$pass, false);
return ["logged_in" => true, "is_visitor" => false];
@@ -43,16 +43,16 @@ class user
Log::put("login_fails", $nick);
throw new Exception(__("The nick or password is incorrect."));
}
-
+
public static function logout(){
if(!Config::get_safe("force_login", false)){
throw new Exception(__("You can't log out. There is no account."));
}
-
+
if(!self::is_logged_in() && !self::is_visitor()){
throw new Exception(__("You are not even logged in."));
}
-
+
$_SESSION[User::SESSION_NAME] = false;
return true;
}
diff --git a/index.php b/index.php
index 140e399..84aa46b 100755
--- a/index.php
+++ b/index.php
@@ -50,7 +50,7 @@ if(!empty($scripts)){
if(!is_array($styles)){
$styles = [$styles];
}
-
+
$scripts = array_unique($scripts);
$scripts_html = ''.PHP_EOL.''.PHP_EOL;
}
@@ -65,10 +65,10 @@ if(!empty($scripts)){
-
+
" rel="stylesheet" type="text/css" />
" rel="stylesheet" type="text/css" />
-
+
@@ -84,10 +84,10 @@ if(!empty($scripts)){
-
+
-
+
© 2016-2019
Miroslav Šedivý