remove empty lines with spaces

This commit is contained in:
Miroslav Šedivý 2019-12-20 18:38:48 +01:00
parent af9735497e
commit cfe7171b5f
16 changed files with 193 additions and 195 deletions

10
ajax.php Normal file → Executable file
View file

@ -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) {

12
app/ajax.class.php Normal file → Executable file
View file

@ -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');

18
app/config.class.php Normal file → Executable file
View file

@ -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;
}
}

View file

@ -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 "<!-- ".$sql." + ".json_encode($params)." -->\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 <strong>DB::results();</strong>. Use <strong>DB::all();</strong> 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;
}

View file

@ -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 [

1
app/jbbcode/CodeDefinitionBuilder.php Normal file → Executable file
View file

@ -156,5 +156,4 @@ class CodeDefinitionBuilder
return $definition;
}
}

2
app/jbbcode/tests/HTMLSafeTest.php Normal file → Executable file
View file

@ -24,7 +24,7 @@ class HTMLSafeTest extends PHPUnit_Framework_TestCase
$this->assertEquals($html, $parser->getAsHtml());
}
/**
* Tests escaping quotes and ampersands in simple text
*/

4
app/jbbcode/tests/ParseContentTest.php Normal file → Executable file
View file

@ -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);

1
app/jbbcode/tests/SimpleEvaluationTest.php Normal file → Executable file
View file

@ -28,7 +28,6 @@ class SimpleEvaluationTest extends PHPUnit_Framework_TestCase
$this->assertEquals($html, $this->defaultParse($bbcode));
}
public function testEmptyString()
{
$this->assertProduces('', '');

2
app/jbbcode/visitors/NestLimitVisitor.php Normal file → Executable file
View file

@ -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]++;

6
app/lang.class.php Normal file → Executable file
View file

@ -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];
}
}

View file

@ -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;
}

View file

@ -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 '<code class="'.$el->getAttribute().'">'.htmlentities($content).'</code>';
@ -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('<?xml encoding="utf-8" ?>'.$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()];
}

36
app/splclassloader.class.php Normal file → Executable file
View file

@ -22,7 +22,7 @@ class SplClassLoader
private $_includePath;
private $_namespaceSeparator = '\\';
private $_excludeNs;
/**
* Creates a new <tt>SplClassLoader</tt> 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;
}
}

View file

@ -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;
}

View file

@ -50,7 +50,7 @@ if(!empty($scripts)){
if(!is_array($styles)){
$styles = [$styles];
}
$scripts = array_unique($scripts);
$scripts_html = '<script src="'.implode('" type="text/javascript"></script>'.PHP_EOL.'<script src="', $scripts).'" type="text/javascript"></script>'.PHP_EOL;
}
@ -65,10 +65,10 @@ if(!empty($scripts)){
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<link href="static/styles/main.css?v=<?php echo Config::get("version"); ?>" rel="stylesheet" type="text/css" />
<link href="static/styles/design.css?v=<?php echo Config::get("version"); ?>" rel="stylesheet" type="text/css" />
<link href="https://fonts.googleapis.com/css?family=Open+Sans&amp;subset=all" rel="stylesheet">
<link href="static/styles/lightbox.css" rel="stylesheet" type="text/css" />
@ -84,10 +84,10 @@ if(!empty($scripts)){
<!-- Login Button -->
<button type="button" class="button blue login_btn"><?php echo __("Login"); ?></button>
<!-- Logout Button -->
<button type="button" class="button gray logout_btn"><?php echo __("Logout"); ?></button>
<!-- Login Modal -->
<div class="modal login_modal">
<div class="modal-dialog" style="max-width: 350px;">
@ -112,7 +112,7 @@ if(!empty($scripts)){
</div>
</div>
</div>
<!-- Post Link -->
<a class="b_link" target="_blank">
<div class="thumb">
@ -125,7 +125,7 @@ if(!empty($scripts)){
<div class="host"></div>
</div>
</a>
<!-- Post Image Link -->
<a class="b_imglink">
<img>
@ -135,10 +135,10 @@ if(!empty($scripts)){
<div class="desc"></div>
</div>
</a>
<!-- Post Image -->
<a class="b_img"><img></a>
<!-- New Post -->
<div class="b_post new_post">
<div class="modal-header">
@ -146,7 +146,7 @@ if(!empty($scripts)){
</div>
<div class="edit-form"></div>
</div>
<!-- Post Tools -->
<ul class="b_dropdown post_tools">
<li><a class="edit_post"><?php echo __("Edit Post"); ?></a></li>
@ -154,7 +154,7 @@ if(!empty($scripts)){
<li><a class="hide"><?php echo __("Hide from Timeline"); ?></a></li>
<li><a class="delete_post"><?php echo __("Delete Post"); ?></a></li>
</ul>
<!-- Edit Modal -->
<div class="modal edit_modal">
<div class="modal-dialog">
@ -198,7 +198,7 @@ if(!empty($scripts)){
</div>
</div>
</div>
<!-- Edit Date Modal -->
<div class="modal edit_date_modal">
<div class="modal-dialog small">
@ -248,7 +248,7 @@ if(!empty($scripts)){
</div>
</div>
</div>
<!-- Delete Modal -->
<div class="modal delete_modal">
<div class="modal-dialog small">
@ -267,7 +267,7 @@ if(!empty($scripts)){
</div>
</div>
</div>
<!-- Post Row -->
<div class="b_post post_row">
<div class="b_header">
@ -284,7 +284,7 @@ if(!empty($scripts)){
<div class="b_text"></div>
<div class="b_content"></div>
</div>
<!-- Pirvacy Settings -->
<ul class="b_dropdown privacy_settings">
<li><a class="set" data-val="public"><i class="public"></i><?php echo __("Public"); ?></a></li>
@ -292,11 +292,11 @@ if(!empty($scripts)){
<li><a class="set" data-val="private"><i class="private"></i><?php echo __("Only me"); ?></a></li>
</ul>
</div>
<div class="bluebar">
<h1><?php echo Config::get("title"); ?></h1>
</div>
<div class="headbar">
<div class="cover">
<?php echo $header; ?>
@ -309,14 +309,14 @@ if(!empty($scripts)){
</div>
<div id="headline"></div>
</div>
<div id="b_feed">
<div class="more_posts">
<a href="#" class="button"><?php echo __("Show all posts"); ?></a>
</div>
<div id="posts"></div>
</div>
<div id="eof_feed">
<img src="static/images/zpEYXu5Wdu6.png">
<p><?php echo Config::get("version"); ?> &copy; 2016-2019 <br>Miroslav Šedivý</p>