use strict types
This commit is contained in:
parent
f5ccffdaf4
commit
9eb5acf2dc
414 changed files with 957 additions and 897 deletions
|
@ -16,6 +16,7 @@ RUN mkdir -p data/config && \
|
|||
echo "<?php define(\"DATABASE_DSN\", \"sqlite:data/shimmie.sqlite\");" > data/config/auto_install.conf.php && \
|
||||
echo === Installing === && php index.php && \
|
||||
echo === Smoke Test === && php index.php get-page /post/list && \
|
||||
echo === Unit Tests === && ./vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-text && \
|
||||
echo === Unit Tests === && ./vendor/bin/phpunit --configuration tests/phpunit.xml && \
|
||||
echo === Cleaning === && rm -rf data
|
||||
#echo === Unit Tests === && ./vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-text && \
|
||||
CMD "/app/tests/docker-init.sh"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* Load all the files into memory, sanitise the environment, but don't
|
||||
* actually do anything as far as the app is concerned
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Class BaseThemelet
|
||||
|
@ -85,13 +85,13 @@ class BaseThemelet
|
|||
$page->add_block(new Block(null, $body, "main", 90, "paginator"));
|
||||
}
|
||||
|
||||
private function gen_page_link(string $base_url, ?string $query, string $page, string $name): string
|
||||
private function gen_page_link(string $base_url, ?string $query, int $page, string $name): string
|
||||
{
|
||||
$link = make_link($base_url.'/'.$page, $query);
|
||||
return '<a href="'.$link.'">'.$name.'</a>';
|
||||
}
|
||||
|
||||
private function gen_page_link_block(string $base_url, ?string $query, string $page, int $current_page, string $name): string
|
||||
private function gen_page_link_block(string $base_url, ?string $query, int $page, int $current_page, string $name): string
|
||||
{
|
||||
$paginator = "";
|
||||
if ($page == $current_page) {
|
||||
|
@ -129,7 +129,7 @@ class BaseThemelet
|
|||
|
||||
$pages = [];
|
||||
foreach (range($start, $end) as $i) {
|
||||
$pages[] = $this->gen_page_link_block($base_url, $query, $i, $current_page, $i);
|
||||
$pages[] = $this->gen_page_link_block($base_url, $query, $i, $current_page, (string)$i);
|
||||
}
|
||||
$pages_html = implode(" | ", $pages);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Class Block
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
interface CacheEngine
|
||||
{
|
||||
public function get(string $key);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
||||
* CAPTCHA abstraction *
|
||||
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Interface Config
|
||||
|
@ -18,12 +18,12 @@ interface Config
|
|||
/**
|
||||
* Set a configuration option to a new value, regardless of what the value is at the moment.
|
||||
*/
|
||||
public function set_int(string $name, ?string $value): void;
|
||||
public function set_int(string $name, ?int $value): void;
|
||||
|
||||
/**
|
||||
* Set a configuration option to a new value, regardless of what the value is at the moment.
|
||||
*/
|
||||
public function set_float(string $name, ?string $value): void;
|
||||
public function set_float(string $name, ?float $value): void;
|
||||
|
||||
/**
|
||||
* Set a configuration option to a new value, regardless of what the value is at the moment.
|
||||
|
@ -32,9 +32,8 @@ interface Config
|
|||
|
||||
/**
|
||||
* Set a configuration option to a new value, regardless of what the value is at the moment.
|
||||
* @param null|bool|string $value
|
||||
*/
|
||||
public function set_bool(string $name, $value): void;
|
||||
public function set_bool(string $name, ?bool $value): void;
|
||||
|
||||
/**
|
||||
* Set a configuration option to a new value, regardless of what the value is at the moment.
|
||||
|
@ -133,13 +132,13 @@ abstract class BaseConfig implements Config
|
|||
{
|
||||
public $values = [];
|
||||
|
||||
public function set_int(string $name, ?string $value): void
|
||||
public function set_int(string $name, ?int $value): void
|
||||
{
|
||||
$this->values[$name] = is_null($value) ? null : parse_shorthand_int($value);
|
||||
$this->values[$name] = is_null($value) ? null : $value;
|
||||
$this->save($name);
|
||||
}
|
||||
|
||||
public function set_float(string $name, ?string $value): void
|
||||
public function set_float(string $name, ?float $value): void
|
||||
{
|
||||
$this->values[$name] = $value;
|
||||
$this->save($name);
|
||||
|
@ -151,9 +150,9 @@ abstract class BaseConfig implements Config
|
|||
$this->save($name);
|
||||
}
|
||||
|
||||
public function set_bool(string $name, $value): void
|
||||
public function set_bool(string $name, ?bool $value): void
|
||||
{
|
||||
$this->values[$name] = bool_escape($value) ? 'Y' : 'N';
|
||||
$this->values[$name] = $value ? 'Y' : 'N';
|
||||
$this->save($name);
|
||||
}
|
||||
|
||||
|
@ -277,10 +276,10 @@ class StaticConfig extends BaseConfig
|
|||
if (!empty($config)) {
|
||||
$this->values = $config;
|
||||
} else {
|
||||
throw new Exception("Config file '$filename' doesn't contain any config");
|
||||
throw new ScoreException("Config file '$filename' doesn't contain any config");
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Config file '$filename' missing");
|
||||
throw new ScoreException("Config file '$filename' missing");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
use FFSPHP\PDO;
|
||||
|
||||
abstract class DatabaseDriver
|
||||
|
@ -168,7 +168,7 @@ class Database
|
|||
$this->connect_db();
|
||||
}
|
||||
return $this->db->execute(
|
||||
"-- " . str_replace("%2F", "/", urlencode(@$_GET['q'])). "\n" .
|
||||
"-- " . str_replace("%2F", "/", urlencode($_GET['q'] ?? '')). "\n" .
|
||||
$query,
|
||||
$args
|
||||
);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
abstract class SCORE
|
||||
{
|
||||
const AIPK = "SCORE_AIPK";
|
||||
|
@ -169,7 +169,7 @@ class SQLite extends DBEngine
|
|||
|
||||
public function init(PDO $db)
|
||||
{
|
||||
ini_set('sqlite.assoc_case', 0);
|
||||
ini_set('sqlite.assoc_case', '0');
|
||||
$db->exec("PRAGMA foreign_keys = ON;");
|
||||
$db->sqliteCreateFunction('UNIX_TIMESTAMP', '_unix_timestamp', 1);
|
||||
$db->sqliteCreateFunction('now', '_now', 0);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Class Email
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Generic parent class for all events.
|
||||
*
|
||||
|
@ -58,6 +58,7 @@ class PageRequestEvent extends Event
|
|||
|
||||
public function __construct(string $path)
|
||||
{
|
||||
parent::__construct();
|
||||
global $config;
|
||||
|
||||
// trim starting slashes
|
||||
|
@ -140,7 +141,7 @@ class PageRequestEvent extends Event
|
|||
*/
|
||||
public function count_args(): int
|
||||
{
|
||||
return int_escape($this->arg_count - $this->part_count);
|
||||
return $this->arg_count - $this->part_count;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -198,6 +199,7 @@ class CommandEvent extends Event
|
|||
*/
|
||||
public function __construct(array $args)
|
||||
{
|
||||
parent::__construct();
|
||||
global $user;
|
||||
|
||||
$opts = [];
|
||||
|
@ -278,6 +280,7 @@ class TextFormattingEvent extends Event
|
|||
|
||||
public function __construct(string $text)
|
||||
{
|
||||
parent::__construct();
|
||||
$h_text = html_escape(trim($text));
|
||||
$this->original = $h_text;
|
||||
$this->formatted = $h_text;
|
||||
|
@ -328,6 +331,7 @@ class LogEvent extends Event
|
|||
|
||||
public function __construct(string $section, int $priority, string $message, array $args)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->section = $section;
|
||||
$this->priority = $priority;
|
||||
$this->message = $message;
|
||||
|
|
|
@ -1,15 +1,22 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Class SCoreException
|
||||
*
|
||||
* A base exception to be caught by the upper levels.
|
||||
*/
|
||||
class SCoreException extends Exception
|
||||
class SCoreException extends RuntimeException
|
||||
{
|
||||
/** @var string|null */
|
||||
public $query;
|
||||
|
||||
/** @var string */
|
||||
public $error;
|
||||
|
||||
public function __construct(string $msg, ?string $query=null)
|
||||
{
|
||||
parent::__construct($msg);
|
||||
$this->error = $msg;
|
||||
$this->query = $query;
|
||||
}
|
||||
}
|
||||
|
@ -47,15 +54,10 @@ class InvalidInput extends SCoreException
|
|||
class InsufficientMemoryException extends SCoreException
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* This is used by the image resizing code when there is an error while resizing
|
||||
*/
|
||||
class ImageResizeException extends SCoreException
|
||||
{
|
||||
public $error;
|
||||
|
||||
public function __construct(string $error)
|
||||
{
|
||||
$this->error = $error;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* \page eande Events and Extensions
|
||||
*
|
||||
|
@ -83,11 +83,13 @@
|
|||
*/
|
||||
abstract class Extension
|
||||
{
|
||||
/** @var string */
|
||||
public $key;
|
||||
|
||||
/** @var Themelet this theme's Themelet object */
|
||||
public $theme;
|
||||
/** @var Themelet */
|
||||
protected $theme;
|
||||
|
||||
/** @var ExtensionInfo */
|
||||
public $info;
|
||||
|
||||
private static $enabled_extensions = [];
|
||||
|
@ -98,7 +100,7 @@ abstract class Extension
|
|||
$this->theme = $this->get_theme_object($class);
|
||||
$this->info = ExtensionInfo::get_for_extension_class($class);
|
||||
if ($this->info===null) {
|
||||
throw new Exception("Info class not found for extension $class");
|
||||
throw new ScoreException("Info class not found for extension $class");
|
||||
}
|
||||
$this->key = $this->info->key;
|
||||
}
|
||||
|
@ -213,7 +215,10 @@ abstract class ExtensionInfo
|
|||
/** @var array which DBs this ext supports (blank for 'all') */
|
||||
public $db_support = [];
|
||||
|
||||
/** @var bool */
|
||||
private $supported = null;
|
||||
|
||||
/** @var string */
|
||||
private $support_info = null;
|
||||
|
||||
public function is_supported(): bool
|
||||
|
@ -302,12 +307,10 @@ abstract class ExtensionInfo
|
|||
{
|
||||
foreach (get_declared_classes() as $class) {
|
||||
$rclass = new ReflectionClass($class);
|
||||
if ($rclass->isAbstract()) {
|
||||
// don't do anything
|
||||
} elseif (is_subclass_of($class, "ExtensionInfo")) {
|
||||
if (!$rclass->isAbstract() && is_subclass_of($class, "ExtensionInfo")) {
|
||||
$extension_info = new $class();
|
||||
if (array_key_exists($extension_info->key, self::$all_info_by_key)) {
|
||||
throw new Exception("Extension Info $class with key $extension_info->key has already been loaded");
|
||||
throw new ScoreException("Extension Info $class with key $extension_info->key has already been loaded");
|
||||
}
|
||||
|
||||
self::$all_info_by_key[$extension_info->key] = $extension_info;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* An image is being added to the database.
|
||||
|
@ -20,18 +20,13 @@ class ImageAdditionEvent extends Event
|
|||
*/
|
||||
public function __construct(Image $image)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->image = $image;
|
||||
}
|
||||
}
|
||||
|
||||
class ImageAdditionException extends SCoreException
|
||||
{
|
||||
public $error;
|
||||
|
||||
public function __construct(string $error)
|
||||
{
|
||||
$this->error = $error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,6 +48,7 @@ class ImageDeletionEvent extends Event
|
|||
*/
|
||||
public function __construct(Image $image, bool $force = false)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->image = $image;
|
||||
$this->force = $force;
|
||||
}
|
||||
|
@ -77,6 +73,7 @@ class ImageReplaceEvent extends Event
|
|||
*/
|
||||
public function __construct(int $id, Image $image)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->id = $id;
|
||||
$this->image = $image;
|
||||
}
|
||||
|
@ -84,13 +81,6 @@ class ImageReplaceEvent extends Event
|
|||
|
||||
class ImageReplaceException extends SCoreException
|
||||
{
|
||||
/** @var string */
|
||||
public $error;
|
||||
|
||||
public function __construct(string $error)
|
||||
{
|
||||
$this->error = $error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,12 +98,12 @@ class ThumbnailGenerationEvent extends Event
|
|||
/** @var bool */
|
||||
public $generated;
|
||||
|
||||
|
||||
/**
|
||||
* Request a thumbnail be made for an image object
|
||||
*/
|
||||
public function __construct(string $hash, string $type, bool $force=false)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->hash = $hash;
|
||||
$this->type = $type;
|
||||
$this->force = $force;
|
||||
|
@ -139,6 +129,7 @@ class ParseLinkTemplateEvent extends Event
|
|||
|
||||
public function __construct(string $link, Image $image)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->link = $link;
|
||||
$this->original = $link;
|
||||
$this->image = $image;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Class Image
|
||||
*
|
||||
|
@ -27,6 +27,7 @@ class Image
|
|||
/** @var string */
|
||||
public $hash;
|
||||
|
||||
/** @var int */
|
||||
public $filesize;
|
||||
|
||||
/** @var string */
|
||||
|
@ -65,7 +66,6 @@ class Image
|
|||
/** @var int */
|
||||
public $length = null;
|
||||
|
||||
|
||||
/**
|
||||
* One will very rarely construct an image directly, more common
|
||||
* would be to use Image::by_id, Image::by_hash, etc.
|
||||
|
@ -76,17 +76,18 @@ class Image
|
|||
foreach ($row as $name => $value) {
|
||||
// some databases use table.name rather than name
|
||||
$name = str_replace("images.", "", $name);
|
||||
$this->$name = $value; // hax, this is likely the cause of much scrutinizer-ci complaints.
|
||||
|
||||
// hax, this is likely the cause of much scrutinizer-ci complaints.
|
||||
if(in_array($name, ["locked", "lossless", "video", "audio"])) {
|
||||
$this->$name = bool_escape($value);
|
||||
}
|
||||
elseif(in_array($name, ["id", "owner_id", "height", "width", "filesize", "length"])) {
|
||||
$this->$name = int_escape($value);
|
||||
}
|
||||
else {
|
||||
$this->$name = $value;
|
||||
}
|
||||
}
|
||||
$this->locked = bool_escape($this->locked);
|
||||
|
||||
assert(is_numeric($this->id));
|
||||
assert(is_numeric($this->height));
|
||||
assert(is_numeric($this->width));
|
||||
|
||||
$this->id = int_escape($this->id);
|
||||
$this->height = int_escape($this->height);
|
||||
$this->width = int_escape($this->width);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,12 +302,12 @@ class Image
|
|||
if ($tag_count === 0) {
|
||||
$total = $cache->get("image-count");
|
||||
if (!$total) {
|
||||
$total = $database->get_one("SELECT COUNT(*) FROM images");
|
||||
$total = (int)$database->get_one("SELECT COUNT(*) FROM images");
|
||||
$cache->set("image-count", $total, 600);
|
||||
}
|
||||
} elseif ($tag_count === 1 && !preg_match("/[:=><\*\?]/", $tags[0])) {
|
||||
$total = $database->get_one(
|
||||
$database->scoreql_to_sql("SELECT count FROM tags WHERE LOWER(tag) = LOWER(:tag)"),
|
||||
$total = (int)$database->get_one(
|
||||
"SELECT count FROM tags WHERE LOWER(tag) = LOWER(:tag)",
|
||||
["tag"=>$tags[0]]
|
||||
);
|
||||
} else {
|
||||
|
@ -317,7 +318,7 @@ class Image
|
|||
$total = Image::get_accelerated_count($tag_conditions, $img_conditions);
|
||||
if (is_null($total)) {
|
||||
$querylet = Image::build_search_querylet($tag_conditions, $img_conditions);
|
||||
$total = $database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables);
|
||||
$total = (int)$database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables);
|
||||
}
|
||||
}
|
||||
if (is_null($total)) {
|
||||
|
@ -331,10 +332,10 @@ class Image
|
|||
*
|
||||
* #param string[] $tags
|
||||
*/
|
||||
public static function count_pages(array $tags=[]): float
|
||||
public static function count_pages(array $tags=[]): int
|
||||
{
|
||||
global $config;
|
||||
return ceil(Image::count_images($tags) / $config->get_int(IndexConfig::IMAGES));
|
||||
return (int)ceil(Image::count_images($tags) / $config->get_int(IndexConfig::IMAGES));
|
||||
}
|
||||
|
||||
private static function terms_to_conditions(array $terms): array
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
||||
* Misc functions *
|
||||
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class Querylet
|
||||
{
|
||||
/** @var string */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Class Tag
|
||||
*
|
||||
|
@ -88,13 +88,13 @@ class Tag
|
|||
public static function sanitize(string $tag): string
|
||||
{
|
||||
$tag = preg_replace("/\s/", "", $tag); # whitespace
|
||||
$tag = preg_replace('/\x20(\x0e|\x0f)/', '', $tag); # unicode RTL
|
||||
$tag = preg_replace('/\x20[\x0e\x0f]/', '', $tag); # unicode RTL
|
||||
$tag = preg_replace("/\.+/", ".", $tag); # strings of dots?
|
||||
$tag = preg_replace("/^(\.+[\/\\\\])+/", "", $tag); # trailing slashes?
|
||||
$tag = trim($tag, ", \t\n\r\0\x0B");
|
||||
|
||||
if (mb_strlen($tag, 'UTF-8') > 255) {
|
||||
throw new Exception("The tag below is longer than 255 characters, please use a shorter tag.\n$tag\n");
|
||||
throw new ScoreException("The tag below is longer than 255 characters, please use a shorter tag.\n$tag\n");
|
||||
}
|
||||
return $tag;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
||||
* Logging convenience *
|
||||
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* \page themes Themes
|
||||
*
|
||||
|
@ -44,8 +44,6 @@ abstract class PageMode
|
|||
*/
|
||||
class Page
|
||||
{
|
||||
/** @name Overall */
|
||||
//@{
|
||||
/** @var string */
|
||||
public $mode = PageMode::PAGE;
|
||||
/** @var string */
|
||||
|
@ -75,11 +73,7 @@ class Page
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//@}
|
||||
// ==============================================
|
||||
/** @name "data" mode */
|
||||
//@{
|
||||
|
||||
/** @var string; public only for unit test */
|
||||
public $data = "";
|
||||
|
@ -114,11 +108,7 @@ class Page
|
|||
$this->disposition = $disposition;
|
||||
}
|
||||
|
||||
|
||||
//@}
|
||||
// ==============================================
|
||||
/** @name "redirect" mode */
|
||||
//@{
|
||||
|
||||
/** @var string */
|
||||
private $redirect = "";
|
||||
|
@ -132,11 +122,7 @@ class Page
|
|||
$this->redirect = $redirect;
|
||||
}
|
||||
|
||||
|
||||
//@}
|
||||
// ==============================================
|
||||
/** @name "page" mode */
|
||||
//@{
|
||||
|
||||
/** @var int */
|
||||
public $code = 200;
|
||||
|
@ -268,8 +254,6 @@ class Page
|
|||
$this->blocks[] = $block;
|
||||
}
|
||||
|
||||
|
||||
//@}
|
||||
// ==============================================
|
||||
|
||||
/**
|
||||
|
@ -553,6 +537,7 @@ class PageSubNavBuildingEvent extends Event
|
|||
|
||||
public function __construct(string $parent)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->parent= $parent;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
abstract class Permissions
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
||||
* Things which should be in the core API *
|
||||
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
@ -162,9 +162,7 @@ function list_files(string $base, string $_sub_dir=""): array
|
|||
foreach ($files as $filename) {
|
||||
$full_path = "$base/$_sub_dir/$filename";
|
||||
|
||||
if (is_link($full_path)) {
|
||||
// ignore
|
||||
} elseif (is_dir($full_path)) {
|
||||
if (!is_link($full_path) && is_dir($full_path)) {
|
||||
if (!($filename == "." || $filename == "..")) {
|
||||
//subdirectory found
|
||||
$file_list = array_merge(
|
||||
|
@ -549,7 +547,7 @@ function xml_tag(string $name, array $attrs=[], array $children=[]): string
|
|||
{
|
||||
$xml = "<$name ";
|
||||
foreach ($attrs as $k => $v) {
|
||||
$xv = str_replace(''', ''', htmlspecialchars($v, ENT_QUOTES));
|
||||
$xv = str_replace(''', ''', htmlspecialchars((string)$v, ENT_QUOTES));
|
||||
$xml .= "$k=\"$xv\" ";
|
||||
}
|
||||
if (count($children) > 0) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
||||
* Event API *
|
||||
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
@ -37,9 +37,7 @@ function _set_event_listeners(): void
|
|||
|
||||
foreach (get_declared_classes() as $class) {
|
||||
$rclass = new ReflectionClass($class);
|
||||
if ($rclass->isAbstract()) {
|
||||
// don't do anything
|
||||
} elseif (is_subclass_of($class, "Extension")) {
|
||||
if (!$rclass->isAbstract() && is_subclass_of($class, "Extension")) {
|
||||
/** @var Extension $extension */
|
||||
$extension = new $class();
|
||||
|
||||
|
@ -68,8 +66,7 @@ function _dump_event_listeners(array $event_listeners, string $path): void
|
|||
|
||||
foreach (get_declared_classes() as $class) {
|
||||
$rclass = new ReflectionClass($class);
|
||||
if ($rclass->isAbstract()) {
|
||||
} elseif (is_subclass_of($class, "Extension")) {
|
||||
if (!$rclass->isAbstract() && is_subclass_of($class, "Extension")) {
|
||||
$p .= "\$$class = new $class(); ";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* First, load the user-specified settings
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
require_once "core/polyfills.php";
|
||||
|
||||
class PolyfillsTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
require_once "core/util.php";
|
||||
|
||||
class UtilTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
||||
* HTML Generation *
|
||||
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
function _new_user(array $row): User
|
||||
{
|
||||
|
@ -107,7 +107,7 @@ class User
|
|||
{
|
||||
$u = User::by_name($name);
|
||||
if (is_null($u)) {
|
||||
throw SCoreException("Can't find any user named " . html_escape($name));
|
||||
throw new ScoreException("Can't find any user named " . html_escape($name));
|
||||
} else {
|
||||
return $u->id;
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ class User
|
|||
{
|
||||
global $database;
|
||||
if (User::by_name($name)) {
|
||||
throw new Exception("Desired username is already in use");
|
||||
throw new ScoreException("Desired username is already in use");
|
||||
}
|
||||
$old_name = $this->name;
|
||||
$this->name = $name;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* @global UserClass[] $_shm_user_classes
|
||||
*/
|
||||
|
@ -48,8 +48,7 @@ class UserClass
|
|||
public function can(string $ability): bool
|
||||
{
|
||||
if (array_key_exists($ability, $this->abilities)) {
|
||||
$val = $this->abilities[$ability];
|
||||
return $val;
|
||||
return $this->abilities[$ability];
|
||||
} elseif (!is_null($this->parent)) {
|
||||
return $this->parent->can($ability);
|
||||
} else {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
use function MicroHTML\emptyHTML;
|
||||
use function MicroHTML\FORM;
|
||||
use function MicroHTML\INPUT;
|
||||
|
@ -79,7 +79,7 @@ function blockcmp(Block $a, Block $b): int
|
|||
if ($a->position == $b->position) {
|
||||
return 0;
|
||||
} else {
|
||||
return ($a->position > $b->position);
|
||||
return ($a->position > $b->position) ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ function get_memory_limit(): int
|
|||
|
||||
// thumbnail generation requires lots of memory
|
||||
$default_limit = 8*1024*1024; // 8 MB of memory is PHP's default.
|
||||
$shimmie_limit = parse_shorthand_int($config->get_int(MediaConfig::MEM_LIMIT));
|
||||
$shimmie_limit = $config->get_int(MediaConfig::MEM_LIMIT);
|
||||
|
||||
if ($shimmie_limit < 3*1024*1024) {
|
||||
// we aren't going to fit, override
|
||||
|
@ -117,7 +117,7 @@ function get_memory_limit(): int
|
|||
// Shimmie wants more memory than what PHP is currently set for.
|
||||
|
||||
// Attempt to set PHP's memory limit.
|
||||
if (ini_set("memory_limit", $shimmie_limit) === false) {
|
||||
if (ini_set("memory_limit", "$shimmie_limit") === false) {
|
||||
/* We can't change PHP's limit, oh well, return whatever its currently set to */
|
||||
return $memory;
|
||||
}
|
||||
|
@ -344,20 +344,17 @@ function join_url(string $base, string ...$paths)
|
|||
|
||||
function get_dir_contents(string $dir): array
|
||||
{
|
||||
if (empty($dir)) {
|
||||
throw new Exception("dir required");
|
||||
}
|
||||
assert(!empty($dir));
|
||||
|
||||
if (!is_dir($dir)) {
|
||||
return [];
|
||||
}
|
||||
$results = array_diff(
|
||||
return array_diff(
|
||||
scandir(
|
||||
$dir
|
||||
),
|
||||
['..', '.']
|
||||
);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -460,8 +457,8 @@ function _sanitise_environment(): void
|
|||
date_default_timezone_set(TIMEZONE);
|
||||
}
|
||||
|
||||
# ini_set('zend.assertions', 1); // generate assertions
|
||||
ini_set('assert.exception', 1); // throw exceptions when failed
|
||||
# ini_set('zend.assertions', '1'); // generate assertions
|
||||
ini_set('assert.exception', '1'); // throw exceptions when failed
|
||||
if (DEBUG) {
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
|
@ -695,13 +692,11 @@ function SHM_FORM(string $target, string $method="POST", bool $multipart=false,
|
|||
if ($onsubmit) {
|
||||
$attrs["onsubmit"] = $onsubmit;
|
||||
}
|
||||
$f = FORM(
|
||||
return FORM(
|
||||
$attrs,
|
||||
INPUT(["type"=>"hidden", "name"=>"q", "value"=>$target]),
|
||||
$method != "GET" ? "" : $user->get_auth_html()
|
||||
);
|
||||
|
||||
return $f;
|
||||
}
|
||||
|
||||
function SHM_SIMPLE_FORM($target, ...$children) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class AdminPageInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Sent when the admin page is ready to be added to
|
||||
|
@ -10,6 +10,7 @@ class AdminBuildingEvent extends Event
|
|||
|
||||
public function __construct(Page $page)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->page = $page;
|
||||
}
|
||||
}
|
||||
|
@ -23,12 +24,16 @@ class AdminActionEvent extends Event
|
|||
|
||||
public function __construct(string $action)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->action = $action;
|
||||
}
|
||||
}
|
||||
|
||||
class AdminPage extends Extension
|
||||
{
|
||||
/** @var AdminPageTheme */
|
||||
protected $theme;
|
||||
|
||||
public function onPageRequest(PageRequestEvent $event)
|
||||
{
|
||||
global $page, $user;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class AdminPageTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testAuth()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class AdminPageTheme extends Themelet
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class AliasEditorInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use MicroCRUD\ActionColumn;
|
||||
use MicroCRUD\TextColumn;
|
||||
|
@ -33,6 +33,7 @@ class AddAliasEvent extends Event
|
|||
|
||||
public function __construct(string $oldtag, string $newtag)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->oldtag = trim($oldtag);
|
||||
$this->newtag = trim($newtag);
|
||||
}
|
||||
|
@ -44,6 +45,9 @@ class AddAliasException extends SCoreException
|
|||
|
||||
class AliasEditor extends Extension
|
||||
{
|
||||
/** @var AliasEditorTheme */
|
||||
protected $theme;
|
||||
|
||||
public function onPageRequest(PageRequestEvent $event)
|
||||
{
|
||||
global $config, $database, $page, $user;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class AliasEditorTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testAliasList()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class AliasEditorTheme extends Themelet
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class ApprovalInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
abstract class ApprovalConfig
|
||||
{
|
||||
|
@ -9,6 +9,9 @@ abstract class ApprovalConfig
|
|||
|
||||
class Approval extends Extension
|
||||
{
|
||||
/** @var ApprovalTheme */
|
||||
protected $theme;
|
||||
|
||||
public function onInitExt(InitExtEvent $event)
|
||||
{
|
||||
global $config;
|
||||
|
@ -59,8 +62,6 @@ class Approval extends Extension
|
|||
|
||||
public function onAdminBuilding(AdminBuildingEvent $event)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$this->theme->display_admin_form();
|
||||
}
|
||||
|
||||
|
@ -128,7 +129,7 @@ class Approval extends Extension
|
|||
$event->add_querylet(new Querylet($database->scoreql_to_sql("approved = SCORE_BOOL_Y ")));
|
||||
}
|
||||
|
||||
|
||||
if(is_null($event->term)) return;
|
||||
if (preg_match(self::SEARCH_REGEXP, strtolower($event->term), $matches)) {
|
||||
if ($user->can(Permissions::APPROVE_IMAGE) && $matches[1] == "no") {
|
||||
$event->add_querylet(new Querylet($database->scoreql_to_sql("approved = SCORE_BOOL_N ")));
|
||||
|
@ -177,7 +178,7 @@ class Approval extends Extension
|
|||
|
||||
public static function disapprove_image($image_id)
|
||||
{
|
||||
global $database, $user;
|
||||
global $database;
|
||||
|
||||
$database->execute(
|
||||
$database->scoreql_to_sql(
|
||||
|
@ -236,7 +237,6 @@ class Approval extends Extension
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
|
||||
{
|
||||
global $database;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class ApprovalTheme extends Themelet
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class ArrowkeyNavigationInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class ArrowkeyNavigation extends Extension
|
||||
{
|
||||
|
@ -85,11 +85,9 @@ class ArrowkeyNavigation extends Extension
|
|||
}
|
||||
|
||||
// Create return array
|
||||
$pageinfo = [
|
||||
return [
|
||||
"prev" => $prefix.$prev,
|
||||
"next" => $prefix.$next,
|
||||
];
|
||||
|
||||
return $pageinfo;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class ArtistsInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class AuthorSetEvent extends Event
|
||||
{
|
||||
|
@ -11,6 +11,7 @@ class AuthorSetEvent extends Event
|
|||
|
||||
public function __construct(Image $image, User $user, string $author)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->image = $image;
|
||||
$this->user = $user;
|
||||
$this->author = $author;
|
||||
|
@ -19,6 +20,9 @@ class AuthorSetEvent extends Event
|
|||
|
||||
class Artists extends Extension
|
||||
{
|
||||
/** @var ArtistsTheme */
|
||||
protected $theme;
|
||||
|
||||
public function onImageInfoSet(ImageInfoSetEvent $event)
|
||||
{
|
||||
global $user;
|
||||
|
@ -38,6 +42,8 @@ class Artists extends Extension
|
|||
|
||||
public function onSearchTermParse(SearchTermParseEvent $event)
|
||||
{
|
||||
if(is_null($event->term)) return;
|
||||
|
||||
$matches = [];
|
||||
if (preg_match("/^(author|artist)[=|:](.*)$/i", $event->term, $matches)) {
|
||||
$char = $matches[1];
|
||||
|
@ -195,7 +201,7 @@ class Artists extends Extension
|
|||
|
||||
case "view":
|
||||
{
|
||||
$artistID = $event->get_arg(1);
|
||||
$artistID = int_escape($event->get_arg(1));
|
||||
$artist = $this->get_artist($artistID);
|
||||
$aliases = $this->get_alias($artist['id']);
|
||||
$members = $this->get_members($artist['id']);
|
||||
|
@ -222,7 +228,7 @@ class Artists extends Extension
|
|||
|
||||
case "edit":
|
||||
{
|
||||
$artistID = $event->get_arg(1);
|
||||
$artistID = int_escape($event->get_arg(1));
|
||||
$artist = $this->get_artist($artistID);
|
||||
$aliases = $this->get_alias($artistID);
|
||||
$members = $this->get_members($artistID);
|
||||
|
@ -262,7 +268,7 @@ class Artists extends Extension
|
|||
}
|
||||
case "nuke":
|
||||
{
|
||||
$artistID = $event->get_arg(1);
|
||||
$artistID = int_escape($event->get_arg(1));
|
||||
$this->delete_artist($artistID); // this will delete the artist, its alias, its urls and its members
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("artist/list"));
|
||||
|
@ -300,7 +306,7 @@ class Artists extends Extension
|
|||
}
|
||||
case "delete":
|
||||
{
|
||||
$aliasID = $event->get_arg(2);
|
||||
$aliasID = int_escape($event->get_arg(2));
|
||||
$artistID = $this->get_artistID_by_aliasID($aliasID);
|
||||
$this->delete_alias($aliasID);
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
|
@ -341,7 +347,7 @@ class Artists extends Extension
|
|||
}
|
||||
case "delete":
|
||||
{
|
||||
$urlID = $event->get_arg(2);
|
||||
$urlID = int_escape($event->get_arg(2));
|
||||
$artistID = $this->get_artistID_by_urlID($urlID);
|
||||
$this->delete_url($urlID);
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
|
@ -415,7 +421,7 @@ class Artists extends Extension
|
|||
{
|
||||
global $database;
|
||||
$result = $database->get_row("SELECT author FROM images WHERE id = :id", ['id'=>$imageID]);
|
||||
return stripslashes($result['author']);
|
||||
return $result['author'] ?? "";
|
||||
}
|
||||
|
||||
private function url_exists_by_url(string $url): bool
|
||||
|
@ -435,7 +441,6 @@ class Artists extends Extension
|
|||
private function alias_exists_by_name(string $alias): bool
|
||||
{
|
||||
global $database;
|
||||
|
||||
$result = $database->get_one("SELECT COUNT(1) FROM artist_alias WHERE alias = :alias", ['alias'=>$alias]);
|
||||
return ($result != 0);
|
||||
}
|
||||
|
@ -507,25 +512,19 @@ class Artists extends Extension
|
|||
private function get_alias_by_id(int $aliasID): array
|
||||
{
|
||||
global $database;
|
||||
$result = $database->get_row("SELECT * FROM artist_alias WHERE id = :id", ['id'=>$aliasID]);
|
||||
$result["alias"] = stripslashes($result["alias"]);
|
||||
return $result;
|
||||
return $database->get_row("SELECT * FROM artist_alias WHERE id = :id", ['id'=>$aliasID]);
|
||||
}
|
||||
|
||||
private function get_url_by_id(int $urlID): array
|
||||
{
|
||||
global $database;
|
||||
$result = $database->get_row("SELECT * FROM artist_urls WHERE id = :id", ['id'=>$urlID]);
|
||||
$result["url"] = stripslashes($result["url"]);
|
||||
return $result;
|
||||
return $database->get_row("SELECT * FROM artist_urls WHERE id = :id", ['id'=>$urlID]);
|
||||
}
|
||||
|
||||
private function get_member_by_id(int $memberID): array
|
||||
{
|
||||
global $database;
|
||||
$result = $database->get_row("SELECT * FROM artist_members WHERE id = :id", ['id'=>$memberID]);
|
||||
$result["name"] = stripslashes($result["name"]);
|
||||
return $result;
|
||||
return $database->get_row("SELECT * FROM artist_members WHERE id = :id", ['id'=>$memberID]);
|
||||
}
|
||||
|
||||
private function update_artist()
|
||||
|
@ -850,7 +849,7 @@ class Artists extends Extension
|
|||
{
|
||||
global $config, $database;
|
||||
|
||||
$pageNumber = clamp($event->get_arg(1), 1, null) - 1;
|
||||
$pageNumber = clamp(int_escape($event->get_arg(1)), 1, null) - 1;
|
||||
$artistsPerPage = $config->get_int("artistsPerPage");
|
||||
|
||||
$listing = $database->get_all(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class ArtistTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testSearch()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class ArtistsTheme extends Themelet
|
||||
{
|
||||
public function get_author_editor_html(string $author): string
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class AutoCompleteInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class AutoComplete extends Extension
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class AutoCompleteTheme extends Themelet
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BanWordsInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BanWords extends Extension
|
||||
{
|
||||
|
@ -75,7 +75,7 @@ xanax
|
|||
/**
|
||||
* Throws if the comment contains banned words.
|
||||
*/
|
||||
private function test_text(string $comment, Exception $ex): void
|
||||
private function test_text(string $comment, SCoreException $ex): void
|
||||
{
|
||||
$comment = strtolower($comment);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class BanWordsTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function check_blocked($image_id, $words)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BBCodeInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
|
||||
class BBCode extends FormatterExtension
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class BBCodeTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testBasics()
|
||||
|
|
|
@ -4,7 +4,7 @@ class Blocks extends Extension
|
|||
{
|
||||
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
|
||||
{
|
||||
global $config, $database;
|
||||
global $database;
|
||||
if ($this->get_version("ext_blocks_version") < 1) {
|
||||
$database->create_table("blocks", "
|
||||
id SCORE_AIPK,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BlotterInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class Blotter extends Extension
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class BlotterTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testLogin()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class BlotterTheme extends Themelet
|
||||
{
|
||||
public function display_editor($entries)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BrowserSearchInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BrowserSearch extends Extension
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class BrowserSearchTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testBasic()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BulkActionsInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BulkActionBlockBuildingEvent extends Event
|
||||
{
|
||||
|
@ -39,13 +39,11 @@ class BulkActionEvent extends Event
|
|||
public $action;
|
||||
/** @var array */
|
||||
public $items;
|
||||
/** @var PageRequestEvent */
|
||||
public $page_request;
|
||||
|
||||
public function __construct(String $action, PageRequestEvent $pageRequestEvent, Generator $items)
|
||||
public function __construct(String $action, Generator $items)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->action = $action;
|
||||
$this->page_request = $pageRequestEvent;
|
||||
$this->items = $items;
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +106,7 @@ class BulkActions extends Extension
|
|||
}
|
||||
$query = $event->args[0];
|
||||
$items = $this->yield_search_results($event->args[1]);
|
||||
$newEvent = new BulkActionEvent($event->args[0], $event, $items);
|
||||
$newEvent = new BulkActionEvent($event->args[0], $items);
|
||||
var_dump($newEvent);
|
||||
# send_event($newEvent);
|
||||
}
|
||||
|
@ -177,11 +175,10 @@ class BulkActions extends Extension
|
|||
}
|
||||
|
||||
if (is_iterable($items)) {
|
||||
$newEvent = new BulkActionEvent($action, $event, $items);
|
||||
$newEvent = new BulkActionEvent($action, $items);
|
||||
send_event($newEvent);
|
||||
}
|
||||
|
||||
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
if (!isset($_SERVER['HTTP_REFERER'])) {
|
||||
$_SERVER['HTTP_REFERER'] = make_link();
|
||||
|
@ -228,7 +225,7 @@ class BulkActions extends Extension
|
|||
send_event(new ImageDeletionEvent($image));
|
||||
$total++;
|
||||
} catch (Exception $e) {
|
||||
$page->flash("Error while removing {$image->id}: " . $e->getMessage(), "error");
|
||||
$page->flash("Error while removing {$image->id}: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
return $total;
|
||||
|
@ -283,7 +280,7 @@ class BulkActions extends Extension
|
|||
send_event(new SourceSetEvent($image, $source));
|
||||
$total++;
|
||||
} catch (Exception $e) {
|
||||
$page->flash("Error while setting source for {$image->id}: " . $e->getMessage(), "error");
|
||||
$page->flash("Error while setting source for {$image->id}: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
return $total;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BulkActionsTheme extends Themelet
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BulkAddInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BulkAddEvent extends Event
|
||||
{
|
||||
|
@ -7,6 +7,7 @@ class BulkAddEvent extends Event
|
|||
|
||||
public function __construct(string $dir)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dir = $dir;
|
||||
$this->results = [];
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BulkAddTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testBulkAdd()
|
||||
|
@ -26,15 +27,15 @@ class BulkAddTest extends ShimmiePHPUnitTestCase
|
|||
# FIXME: test that the output here makes sense, no "adding foo.php ... ok"
|
||||
|
||||
$this->get_page("post/list/hash=17fc89f372ed3636e28bd25cc7f3bac1/1");
|
||||
$this->assert_title(new PatternExpectation("/^Image \d+: data/"));
|
||||
$this->assert_title_matches(new PatternExpectation("/^Image \d+: data/"));
|
||||
$this->click("Delete");
|
||||
|
||||
$this->get_page("post/list/hash=feb01bab5698a11dd87416724c7a89e3/1");
|
||||
$this->assert_title(new PatternExpectation("/^Image \d+: data/"));
|
||||
$this->assert_title_matches(new PatternExpectation("/^Image \d+: data/"));
|
||||
$this->click("Delete");
|
||||
|
||||
$this->get_page("post/list/hash=e106ea2983e1b77f11e00c0c54e53805/1");
|
||||
$this->assert_title(new PatternExpectation("/^Image \d+: data/"));
|
||||
$this->assert_title_matches(new PatternExpectation("/^Image \d+: data/"));
|
||||
$this->click("Delete");
|
||||
|
||||
$this->log_out();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BulkAddTheme extends Themelet
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BulkAddCSVInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BulkAddCSV extends Extension
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BulkAddCSVTheme extends Themelet
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class BulkRemoveInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
//todo: removal by tag returns 1 less image in test for some reason, actually a combined search doesn't seem to work for shit either
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class CommentListInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
require_once "vendor/ifixit/php-akismet/akismet.class.php";
|
||||
|
||||
|
@ -13,6 +13,7 @@ class CommentPostingEvent extends Event
|
|||
|
||||
public function __construct(int $image_id, User $user, string $comment)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->image_id = $image_id;
|
||||
$this->user = $user;
|
||||
$this->comment = $comment;
|
||||
|
@ -31,6 +32,7 @@ class CommentDeletionEvent extends Event
|
|||
|
||||
public function __construct(int $comment_id)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->comment_id = $comment_id;
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +71,7 @@ class Comment
|
|||
public static function count_comments_by_user(User $user): int
|
||||
{
|
||||
global $database;
|
||||
return $database->get_one("
|
||||
return (int)$database->get_one("
|
||||
SELECT COUNT(*) AS count
|
||||
FROM comments
|
||||
WHERE owner_id=:owner_id
|
||||
|
@ -102,7 +104,7 @@ class CommentList extends Extension
|
|||
|
||||
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
|
||||
{
|
||||
global $config, $database;
|
||||
global $database;
|
||||
if ($this->get_version("ext_comments_version") < 3) {
|
||||
// shortcut to latest
|
||||
if ($this->get_version("ext_comments_version") < 1) {
|
||||
|
@ -202,7 +204,7 @@ class CommentList extends Extension
|
|||
if ($user->can(Permissions::DELETE_COMMENT)) {
|
||||
// FIXME: post, not args
|
||||
if ($event->count_args() === 3) {
|
||||
send_event(new CommentDeletionEvent($event->get_arg(1)));
|
||||
send_event(new CommentDeletionEvent(int_escape($event->get_arg(1))));
|
||||
$page->flash("Deleted comment");
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
if (!empty($_SERVER['HTTP_REFERER'])) {
|
||||
|
@ -254,7 +256,7 @@ class CommentList extends Extension
|
|||
$duser = User::by_name($search);
|
||||
$i_comment_count = Comment::count_comments_by_user($duser);
|
||||
$com_per_page = 50;
|
||||
$total_pages = ceil($i_comment_count / $com_per_page);
|
||||
$total_pages = (int)ceil($i_comment_count / $com_per_page);
|
||||
$page_num = clamp($page_num, 1, $total_pages);
|
||||
$comments = $this->get_user_comments($duser->id, $com_per_page, ($page_num - 1) * $com_per_page);
|
||||
$this->theme->display_all_user_comments($comments, $page_num, $total_pages, $duser);
|
||||
|
@ -340,8 +342,9 @@ class CommentList extends Extension
|
|||
|
||||
public function onSearchTermParse(SearchTermParseEvent $event)
|
||||
{
|
||||
$matches = [];
|
||||
if(is_null($event->term)) return;
|
||||
|
||||
$matches = [];
|
||||
if (preg_match("/^comments([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)$/i", $event->term, $matches)) {
|
||||
$cmp = ltrim($matches[1], ":") ?: "=";
|
||||
$comments = $matches[2];
|
||||
|
@ -399,7 +402,7 @@ class CommentList extends Extension
|
|||
|
||||
$images = [];
|
||||
while ($row = $result->fetch()) {
|
||||
$image = Image::by_id($row["image_id"]);
|
||||
$image = Image::by_id((int)$row["image_id"]);
|
||||
if (
|
||||
Extension::is_enabled(RatingsInfo::KEY) && !is_null($image) &&
|
||||
!in_array($image->rating, $user_ratings)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class CommentListTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class CommentListTheme extends Themelet
|
||||
{
|
||||
private $show_anon_id = false;
|
||||
|
@ -274,16 +274,15 @@ class CommentListTheme extends Themelet
|
|||
{
|
||||
global $config;
|
||||
|
||||
$i_image_id = int_escape($image_id);
|
||||
$hash = CommentList::get_hash();
|
||||
$h_captcha = $config->get_bool("comment_captcha") ? captcha_get_html() : "";
|
||||
|
||||
return '
|
||||
<div class="comment comment_add">
|
||||
'.make_form(make_link("comment/add")).'
|
||||
<input type="hidden" name="image_id" value="'.$i_image_id.'" />
|
||||
<input type="hidden" name="image_id" value="'.$image_id.'" />
|
||||
<input type="hidden" name="hash" value="'.$hash.'" />
|
||||
<textarea id="comment_on_'.$i_image_id.'" name="comment" rows="5" cols="50"></textarea>
|
||||
<textarea id="comment_on_'.$image_id.'" name="comment" rows="5" cols="50"></textarea>
|
||||
'.$h_captcha.'
|
||||
<br><input type="submit" value="Post Comment" />
|
||||
</form>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
|
||||
abstract class CronUploaderConfig
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Name: Cron Uploader
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
require_once "config.php";
|
||||
|
||||
|
@ -109,13 +109,13 @@ class CronUploader extends Extension
|
|||
{
|
||||
global $page;
|
||||
if (empty($folder)) {
|
||||
throw new Exception("folder empty");
|
||||
throw new SCoreException("folder empty");
|
||||
}
|
||||
$queue_dir = $this->get_queue_dir();
|
||||
$stage_dir = join_path($this->get_failed_dir(), $folder);
|
||||
|
||||
if (!is_dir($stage_dir)) {
|
||||
throw new Exception("Could not find $stage_dir");
|
||||
throw new SCoreException("Could not find $stage_dir");
|
||||
}
|
||||
|
||||
$this->prep_root_dir();
|
||||
|
@ -123,7 +123,7 @@ class CronUploader extends Extension
|
|||
$results = get_dir_contents($queue_dir);
|
||||
|
||||
if (count($results) > 0) {
|
||||
$page->flash("Queue folder must be empty to re-stage", "error");
|
||||
$page->flash("Queue folder must be empty to re-stage");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -293,7 +293,7 @@ class CronUploader extends Extension
|
|||
}
|
||||
|
||||
$output_subdir = date('Ymd-His', time());
|
||||
$image_queue = $this->generate_image_queue($upload_count);
|
||||
$image_queue = $this->generate_image_queue(CronUploaderConfig::get_dir(), $upload_count);
|
||||
|
||||
|
||||
// Throw exception if there's nothing in the queue
|
||||
|
@ -408,9 +408,8 @@ class CronUploader extends Extension
|
|||
send_event($event);
|
||||
|
||||
// Generate info message
|
||||
$infomsg = ""; // Will contain info message
|
||||
if ($event->image_id == -1) {
|
||||
throw new Exception("File type not recognised. Filename: {$filename}");
|
||||
throw new UploadException("File type not recognised. Filename: {$filename}");
|
||||
} elseif ($event->merged === true) {
|
||||
$infomsg = "Image merged. ID: {$event->image_id} - Filename: {$filename}";
|
||||
} else {
|
||||
|
@ -473,8 +472,6 @@ class CronUploader extends Extension
|
|||
|
||||
private function log_message(int $severity, string $message): void
|
||||
{
|
||||
global $database;
|
||||
|
||||
log_msg(self::NAME, $severity, $message);
|
||||
|
||||
$time = "[" . date('Y-m-d H:i:s') . "]";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class CronUploaderTheme extends Themelet
|
||||
{
|
||||
|
@ -100,7 +100,7 @@ class CronUploaderTheme extends Themelet
|
|||
|
||||
public function display_form(array $failed_dirs)
|
||||
{
|
||||
global $page, $database;
|
||||
global $page;
|
||||
|
||||
$link = make_http(make_link("cron_upload"));
|
||||
$html = "<a href='$link'>Cron uploader documentation</a>";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class CustomHtmlHeadersInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class CustomHtmlHeaders extends Extension
|
||||
{
|
||||
|
@ -15,9 +15,9 @@ class CustomHtmlHeaders extends Extension
|
|||
|
||||
// modified title
|
||||
$sb->add_choice_option("sitename_in_title", [
|
||||
"none" => 0,
|
||||
"as prefix" => 1,
|
||||
"as suffix" => 2
|
||||
"none" => "none",
|
||||
"as prefix" => "prefix",
|
||||
"as suffix" => "suffix"
|
||||
], "<br>Add website name in title");
|
||||
|
||||
$event->panel->add_block($sb);
|
||||
|
@ -26,7 +26,7 @@ class CustomHtmlHeaders extends Extension
|
|||
public function onInitExt(InitExtEvent $event)
|
||||
{
|
||||
global $config;
|
||||
$config->set_default_int("sitename_in_title", 0);
|
||||
$config->set_default_string("sitename_in_title", "none");
|
||||
}
|
||||
|
||||
# Load Analytics tracking code on page request
|
||||
|
@ -52,17 +52,16 @@ class CustomHtmlHeaders extends Extension
|
|||
|
||||
// get config values
|
||||
$site_title = $config->get_string(SetupConfig::TITLE);
|
||||
$sitename_in_title = $config->get_int("sitename_in_title");
|
||||
$sitename_in_title = $config->get_string("sitename_in_title");
|
||||
|
||||
// if feature is enabled & sitename isn't already in title
|
||||
// (can occur on index & other pages)
|
||||
if ($sitename_in_title != 0 && !strstr($page->title, $site_title)) {
|
||||
if ($sitename_in_title == 1) {
|
||||
// sitename is already in title (can occur on index & other pages)
|
||||
if(strstr($page->title, $site_title)) return;
|
||||
|
||||
if ($sitename_in_title == "prefix") {
|
||||
$page->title = "$site_title - $page->title";
|
||||
} // as prefix
|
||||
elseif ($sitename_in_title == 2) {
|
||||
}
|
||||
elseif ($sitename_in_title == "suffix") {
|
||||
$page->title = "$page->title - $site_title";
|
||||
} // as suffix
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class DanbooruApiInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class DanbooruApi extends Extension
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class DanbooruApiTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testSearch()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class DowntimeInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class Downtime extends Extension
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class DowntimeTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function tearDown(): void
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class DowntimeTheme extends Themelet
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class EmoticonsInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class EmoticonTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testEmoticons()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class EmoticonListInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Class EmoticonList
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
class EmoticonListTheme extends Themelet
|
||||
{
|
||||
public function display_emotes(array $list)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class ETInfo extends ExtensionInfo
|
||||
{
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue