PHP7 type annotations

This commit is contained in:
Shish 2017-09-19 18:55:43 +01:00
parent c7ca2f4154
commit 977c3db1e3
98 changed files with 624 additions and 1986 deletions

View file

@ -13,8 +13,9 @@ class BaseThemelet {
* @param int $code * @param int $code
* @param string $title * @param string $title
* @param string $message * @param string $message
* @return void
*/ */
public function display_error(/*int*/ $code, /*string*/ $title, /*string*/ $message) { public function display_error(int $code, string $title, string $message) {
global $page; global $page;
$page->set_code($code); $page->set_code($code);
$page->set_title($title); $page->set_title($title);
@ -34,6 +35,7 @@ class BaseThemelet {
/** /**
* A specific, common error message * A specific, common error message
* @return void
*/ */
public function display_permission_denied() { public function display_permission_denied() {
$this->display_error(403, "Permission Denied", "You do not have permission to access this page"); $this->display_error(403, "Permission Denied", "You do not have permission to access this page");
@ -47,7 +49,7 @@ class BaseThemelet {
* @param Image $image * @param Image $image
* @return string * @return string
*/ */
public function build_thumb_html(Image $image) { public function build_thumb_html(Image $image): string {
global $config; global $config;
$i_id = (int) $image->id; $i_id = (int) $image->id;
@ -75,45 +77,18 @@ class BaseThemelet {
"</a>\n"; "</a>\n";
} }
/** public function display_paginator(Page $page, string $base, string $query=null, int $page_number, int $total_pages, bool $show_random = FALSE) {
* Add a generic paginator.
*
* @param Page $page
* @param string $base
* @param string $query
* @param int $page_number
* @param int $total_pages
* @param bool $show_random
*/
public function display_paginator(Page $page, $base, $query, $page_number, $total_pages, $show_random = FALSE) {
if($total_pages == 0) $total_pages = 1; if($total_pages == 0) $total_pages = 1;
$body = $this->build_paginator($page_number, $total_pages, $base, $query, $show_random); $body = $this->build_paginator($page_number, $total_pages, $base, $query, $show_random);
$page->add_block(new Block(null, $body, "main", 90, "paginator")); $page->add_block(new Block(null, $body, "main", 90, "paginator"));
} }
/** private function gen_page_link(string $base_url, string $query=null, string $page, string $name): string {
* Generate a single HTML link.
*
* @param string $base_url
* @param string $query
* @param string $page
* @param string $name
* @return string
*/
private function gen_page_link($base_url, $query, $page, $name) {
$link = make_link($base_url.'/'.$page, $query); $link = make_link($base_url.'/'.$page, $query);
return '<a href="'.$link.'">'.$name.'</a>'; return '<a href="'.$link.'">'.$name.'</a>';
} }
/** private function gen_page_link_block(string $base_url, string $query=null, string $page, int $current_page, string $name): string {
* @param string $base_url
* @param string $query
* @param string $page
* @param int $current_page
* @param string $name
* @return string
*/
private function gen_page_link_block($base_url, $query, $page, $current_page, $name) {
$paginator = ""; $paginator = "";
if($page == $current_page) $paginator .= "<b>"; if($page == $current_page) $paginator .= "<b>";
$paginator .= $this->gen_page_link($base_url, $query, $page, $name); $paginator .= $this->gen_page_link($base_url, $query, $page, $name);
@ -121,17 +96,7 @@ class BaseThemelet {
return $paginator; return $paginator;
} }
/** private function build_paginator(int $current_page, int $total_pages, string $base_url, string $query=null, bool $show_random): string {
* Build the paginator.
*
* @param int $current_page
* @param int $total_pages
* @param string $base_url
* @param string $query
* @param bool $show_random
* @return string
*/
private function build_paginator($current_page, $total_pages, $base_url, $query, $show_random) {
$next = $current_page + 1; $next = $current_page + 1;
$prev = $current_page - 1; $prev = $current_page - 1;
@ -163,4 +128,3 @@ class BaseThemelet {
.'<br>&lt;&lt; '.$pages_html.' &gt;&gt;'; .'<br>&lt;&lt; '.$pages_html.' &gt;&gt;';
} }
} }

View file

@ -52,16 +52,7 @@ class Block {
*/ */
public $is_content = true; public $is_content = true;
/** public function __construct(string $header=null, string $body=null, string $section="main", int $position=50, string $id=null) {
* Construct a block.
*
* @param string $header
* @param string $body
* @param string $section
* @param int $position
* @param null|int $id A unique ID for the block (generated automatically if null).
*/
public function __construct($header, $body, /*string*/ $section="main", /*int*/ $position=50, $id=null) {
$this->header = $header; $this->header = $header;
$this->body = $body; $this->body = $body;
$this->section = $section; $this->section = $section;
@ -79,7 +70,7 @@ class Block {
* @param bool $hidable * @param bool $hidable
* @return string * @return string
*/ */
public function get_html($hidable=false) { public function get_html(bool $hidable=false): string {
$h = $this->header; $h = $this->header;
$b = $this->body; $b = $this->body;
$i = $this->id; $i = $this->id;

View file

@ -12,9 +12,9 @@ interface Config {
* configuration. * configuration.
* *
* @param null|string $name * @param null|string $name
* @return mixed|void * @return void
*/ */
public function save(/*string*/ $name=null); public function save(string $name=null);
//@{ /*--------------------------------- SET ------------------------------------------------------*/ //@{ /*--------------------------------- SET ------------------------------------------------------*/
/** /**
@ -23,7 +23,7 @@ interface Config {
* @param null|int $value * @param null|int $value
* @return void * @return void
*/ */
public function set_int(/*string*/ $name, $value); public function set_int(string $name, $value);
/** /**
* Set a configuration option to a new value, regardless of what the value is at the moment. * Set a configuration option to a new value, regardless of what the value is at the moment.
@ -31,7 +31,7 @@ interface Config {
* @param null|string $value * @param null|string $value
* @return void * @return void
*/ */
public function set_string(/*string*/ $name, $value); public function set_string(string $name, $value);
/** /**
* Set a configuration option to a new value, regardless of what the value is at the moment. * Set a configuration option to a new value, regardless of what the value is at the moment.
@ -39,7 +39,7 @@ interface Config {
* @param null|bool|string $value * @param null|bool|string $value
* @return void * @return void
*/ */
public function set_bool(/*string*/ $name, $value); public function set_bool(string $name, $value);
/** /**
* Set a configuration option to a new value, regardless of what the value is at the moment. * Set a configuration option to a new value, regardless of what the value is at the moment.
@ -47,7 +47,7 @@ interface Config {
* @param array $value * @param array $value
* @return void * @return void
*/ */
public function set_array(/*string*/ $name, $value); public function set_array(string $name, array $value);
//@} /*--------------------------------------------------------------------------------------------*/ //@} /*--------------------------------------------------------------------------------------------*/
//@{ /*-------------------------------- SET DEFAULT -----------------------------------------------*/ //@{ /*-------------------------------- SET DEFAULT -----------------------------------------------*/
@ -63,7 +63,7 @@ interface Config {
* @param int $value * @param int $value
* @return void * @return void
*/ */
public function set_default_int(/*string*/ $name, $value); public function set_default_int(string $name, int $value);
/** /**
* Set a configuration option to a new value, if there is no value currently. * Set a configuration option to a new value, if there is no value currently.
@ -77,7 +77,7 @@ interface Config {
* @param string|null $value * @param string|null $value
* @return void * @return void
*/ */
public function set_default_string(/*string*/ $name, $value); public function set_default_string(string $name, string $value);
/** /**
* Set a configuration option to a new value, if there is no value currently. * Set a configuration option to a new value, if there is no value currently.
@ -91,7 +91,7 @@ interface Config {
* @param bool $value * @param bool $value
* @return void * @return void
*/ */
public function set_default_bool(/*string*/ $name, /*bool*/ $value); public function set_default_bool(string $name, bool $value);
/** /**
* Set a configuration option to a new value, if there is no value currently. * Set a configuration option to a new value, if there is no value currently.
@ -105,7 +105,7 @@ interface Config {
* @param array $value * @param array $value
* @return void * @return void
*/ */
public function set_default_array(/*string*/ $name, $value); public function set_default_array(string $name, array $value);
//@} /*--------------------------------------------------------------------------------------------*/ //@} /*--------------------------------------------------------------------------------------------*/
//@{ /*--------------------------------- GET ------------------------------------------------------*/ //@{ /*--------------------------------- GET ------------------------------------------------------*/
@ -115,7 +115,7 @@ interface Config {
* @param null|int $default * @param null|int $default
* @return int * @return int
*/ */
public function get_int(/*string*/ $name, $default=null); public function get_int(string $name, $default=null);
/** /**
* Pick a value out of the table by name, cast to the appropriate data type. * Pick a value out of the table by name, cast to the appropriate data type.
@ -123,7 +123,7 @@ interface Config {
* @param null|string $default * @param null|string $default
* @return string * @return string
*/ */
public function get_string(/*string*/ $name, $default=null); public function get_string(string $name, $default=null);
/** /**
* Pick a value out of the table by name, cast to the appropriate data type. * Pick a value out of the table by name, cast to the appropriate data type.
@ -131,7 +131,7 @@ interface Config {
* @param null|bool|string $default * @param null|bool|string $default
* @return bool * @return bool
*/ */
public function get_bool(/*string*/ $name, $default=null); public function get_bool(string $name, $default=null);
/** /**
* Pick a value out of the table by name, cast to the appropriate data type. * Pick a value out of the table by name, cast to the appropriate data type.
@ -139,7 +139,7 @@ interface Config {
* @param array|null $default * @param array|null $default
* @return array * @return array
*/ */
public function get_array(/*string*/ $name, $default=array()); public function get_array(string $name, array $default=array());
//@} /*--------------------------------------------------------------------------------------------*/ //@} /*--------------------------------------------------------------------------------------------*/
} }
@ -153,134 +153,67 @@ interface Config {
abstract class BaseConfig implements Config { abstract class BaseConfig implements Config {
public $values = array(); public $values = array();
/** public function set_int(string $name, $value) {
* @param string $name
* @param int|null $value
* @return void
*/
public function set_int(/*string*/ $name, $value) {
$this->values[$name] = parse_shorthand_int($value); $this->values[$name] = parse_shorthand_int($value);
$this->save($name); $this->save($name);
} }
/** public function set_string(string $name, $value) {
* @param string $name
* @param null|string $value
* @return void
*/
public function set_string(/*string*/ $name, $value) {
$this->values[$name] = $value; $this->values[$name] = $value;
$this->save($name); $this->save($name);
} }
/** public function set_bool(string $name, $value) {
* @param string $name $this->values[$name] = bool_escape($value) ? 'Y' : 'N';
* @param bool|null|string $value
* @return void
*/
public function set_bool(/*string*/ $name, $value) {
$this->values[$name] = (($value == 'on' || $value === true) ? 'Y' : 'N');
$this->save($name); $this->save($name);
} }
/** public function set_array(string $name, array $value) {
* @param string $name
* @param array $value
* @return void
*/
public function set_array(/*string*/ $name, $value) {
assert(isset($value) && is_array($value));
$this->values[$name] = implode(",", $value); $this->values[$name] = implode(",", $value);
$this->save($name); $this->save($name);
} }
/** public function set_default_int(string $name, int $value) {
* @param string $name
* @param int $value
* @return void
*/
public function set_default_int(/*string*/ $name, $value) {
if(is_null($this->get($name))) {
$this->values[$name] = parse_shorthand_int($value);
}
}
/**
* @param string $name
* @param null|string $value
* @return void
*/
public function set_default_string(/*string*/ $name, $value) {
if(is_null($this->get($name))) { if(is_null($this->get($name))) {
$this->values[$name] = $value; $this->values[$name] = $value;
} }
} }
/** public function set_default_string(string $name, string $value) {
* @param string $name
* @param bool $value
* @return void
*/
public function set_default_bool(/*string*/ $name, /*bool*/ $value) {
if(is_null($this->get($name))) { if(is_null($this->get($name))) {
$this->values[$name] = (($value == 'on' || $value === true) ? 'Y' : 'N'); $this->values[$name] = $value;
} }
} }
/** public function set_default_bool(string $name, bool $value) {
* @param string $name if(is_null($this->get($name))) {
* @param array $value $this->values[$name] = $value ? 'Y' : 'N';
* @return void }
*/ }
public function set_default_array(/*string*/ $name, $value) {
assert(isset($value) && is_array($value)); public function set_default_array(string $name, array $value) {
if(is_null($this->get($name))) { if(is_null($this->get($name))) {
$this->values[$name] = implode(",", $value); $this->values[$name] = implode(",", $value);
} }
} }
/** public function get_int(string $name, $default=null) {
* @param string $name
* @param null|int $default
* @return int
*/
public function get_int(/*string*/ $name, $default=null) {
return (int)($this->get($name, $default)); return (int)($this->get($name, $default));
} }
/** public function get_string(string $name, $default=null) {
* @param string $name
* @param null|string $default
* @return null|string
*/
public function get_string(/*string*/ $name, $default=null) {
return $this->get($name, $default); return $this->get($name, $default);
} }
/** public function get_bool(string $name, $default=null) {
* @param string $name
* @param null|bool|string $default
* @return bool
*/
public function get_bool(/*string*/ $name, $default=null) {
return bool_escape($this->get($name, $default)); return bool_escape($this->get($name, $default));
} }
/** public function get_array(string $name, array $default=array()): array {
* @param string $name
* @param array $default
* @return array
*/
public function get_array(/*string*/ $name, $default=array()) {
return explode(",", $this->get($name, "")); return explode(",", $this->get($name, ""));
} }
/** private function get(string $name, $default=null) {
* @param string $name
* @param null|mixed $default
* @return null|mixed
*/
private function get(/*string*/ $name, $default=null) {
if(isset($this->values[$name])) { if(isset($this->values[$name])) {
return $this->values[$name]; return $this->values[$name];
} }
@ -297,15 +230,11 @@ abstract class BaseConfig implements Config {
* For testing, mostly. * For testing, mostly.
*/ */
class HardcodeConfig extends BaseConfig { class HardcodeConfig extends BaseConfig {
public function __construct($dict) { public function __construct(array $dict) {
$this->values = $dict; $this->values = $dict;
} }
/** public function save(string $name=null) {
* @param null|string $name
* @return mixed|void
*/
public function save(/*string*/ $name=null) {
// static config is static // static config is static
} }
} }
@ -322,11 +251,7 @@ class HardcodeConfig extends BaseConfig {
* ?> * ?>
*/ */
class StaticConfig extends BaseConfig { class StaticConfig extends BaseConfig {
/** public function __construct(string $filename) {
* @param string $filename
* @throws Exception
*/
public function __construct($filename) {
if(file_exists($filename)) { if(file_exists($filename)) {
$config = array(); $config = array();
require_once $filename; require_once $filename;
@ -342,11 +267,7 @@ class StaticConfig extends BaseConfig {
} }
} }
/** public function save(string $name=null) {
* @param null|string $name
* @return mixed|void
*/
public function save(/*string*/ $name=null) {
// static config is static // static config is static
} }
} }
@ -369,11 +290,6 @@ class DatabaseConfig extends BaseConfig {
/** @var Database */ /** @var Database */
private $database = null; private $database = null;
/**
* Load the config table from a database.
*
* @param Database $database
*/
public function __construct(Database $database) { public function __construct(Database $database) {
$this->database = $database; $this->database = $database;
@ -390,17 +306,11 @@ class DatabaseConfig extends BaseConfig {
} }
} }
/** public function save(string $name=null) {
* Save the current values as the new config table.
*
* @param null|string $name
* @return mixed|void
*/
public function save(/*string*/ $name=null) {
if(is_null($name)) { if(is_null($name)) {
reset($this->values); // rewind the array to the first element reset($this->values); // rewind the array to the first element
foreach($this->values as $name => $value) { foreach($this->values as $name => $value) {
$this->save(/*string*/ $name); $this->save($name);
} }
} }
else { else {
@ -417,10 +327,7 @@ class DatabaseConfig extends BaseConfig {
* Class MockConfig * Class MockConfig
*/ */
class MockConfig extends HardcodeConfig { class MockConfig extends HardcodeConfig {
/** public function __construct(array $config=array()) {
* @param array $config
*/
public function __construct($config=array()) {
$config["db_version"] = "999"; $config["db_version"] = "999";
$config["anon_id"] = "0"; $config["anon_id"] = "0";
parent::__construct($config); parent::__construct($config);

View file

@ -7,34 +7,20 @@ class Querylet {
/** @var array */ /** @var array */
public $variables; public $variables;
/** public function __construct(string $sql, array $variables=array()) {
* @param string $sql
* @param array $variables
*/
public function __construct($sql, $variables=array()) {
$this->sql = $sql; $this->sql = $sql;
$this->variables = $variables; $this->variables = $variables;
} }
/** public function append(Querylet $querylet) {
* @param \Querylet $querylet
*/
public function append($querylet) {
assert('!is_null($querylet)');
$this->sql .= $querylet->sql; $this->sql .= $querylet->sql;
$this->variables = array_merge($this->variables, $querylet->variables); $this->variables = array_merge($this->variables, $querylet->variables);
} }
/** public function append_sql(string $sql) {
* @param string $sql
*/
public function append_sql($sql) {
$this->sql .= $sql; $this->sql .= $sql;
} }
/**
* @param mixed $var
*/
public function add_variable($var) { public function add_variable($var) {
$this->variables[] = $var; $this->variables[] = $var;
} }
@ -46,11 +32,7 @@ class TagQuerylet {
/** @var bool */ /** @var bool */
public $positive; public $positive;
/** public function __construct(string $tag, bool $positive) {
* @param string $tag
* @param bool $positive
*/
public function __construct($tag, $positive) {
$this->tag = $tag; $this->tag = $tag;
$this->positive = $positive; $this->positive = $positive;
} }
@ -62,11 +44,7 @@ class ImgQuerylet {
/** @var bool */ /** @var bool */
public $positive; public $positive;
/** public function __construct(Querylet $qlet, bool $positive) {
* @param \Querylet $qlet
* @param bool $positive
*/
public function __construct($qlet, $positive) {
$this->qlet = $qlet; $this->qlet = $qlet;
$this->positive = $positive; $this->positive = $positive;
} }
@ -77,25 +55,13 @@ class DBEngine {
/** @var null|string */ /** @var null|string */
public $name = null; public $name = null;
/** public function init(PDO $db) {}
* @param \PDO $db
*/
public function init($db) {}
/** public function scoreql_to_sql(string $scoreql): string {
* @param string $scoreql
* @return string
*/
public function scoreql_to_sql($scoreql) {
return $scoreql; return $scoreql;
} }
/** public function create_table_sql(string $name, string $data): string {
* @param string $name
* @param string $data
* @return string
*/
public function create_table_sql($name, $data) {
return 'CREATE TABLE '.$name.' ('.$data.')'; return 'CREATE TABLE '.$name.' ('.$data.')';
} }
} }
@ -103,18 +69,11 @@ class MySQL extends DBEngine {
/** @var string */ /** @var string */
public $name = "mysql"; public $name = "mysql";
/** public function init(PDO $db) {
* @param \PDO $db
*/
public function init($db) {
$db->exec("SET NAMES utf8;"); $db->exec("SET NAMES utf8;");
} }
/** public function scoreql_to_sql(string $data): string {
* @param string $data
* @return string
*/
public function scoreql_to_sql($data) {
$data = str_replace("SCORE_AIPK", "INTEGER PRIMARY KEY auto_increment", $data); $data = str_replace("SCORE_AIPK", "INTEGER PRIMARY KEY auto_increment", $data);
$data = str_replace("SCORE_INET", "VARCHAR(45)", $data); $data = str_replace("SCORE_INET", "VARCHAR(45)", $data);
$data = str_replace("SCORE_BOOL_Y", "'Y'", $data); $data = str_replace("SCORE_BOOL_Y", "'Y'", $data);
@ -127,12 +86,7 @@ class MySQL extends DBEngine {
return $data; return $data;
} }
/** public function create_table_sql(string $name, string $data): string {
* @param string $name
* @param string $data
* @return string
*/
public function create_table_sql($name, $data) {
$data = $this->scoreql_to_sql($data); $data = $this->scoreql_to_sql($data);
$ctes = "ENGINE=InnoDB DEFAULT CHARSET='utf8'"; $ctes = "ENGINE=InnoDB DEFAULT CHARSET='utf8'";
return 'CREATE TABLE '.$name.' ('.$data.') '.$ctes; return 'CREATE TABLE '.$name.' ('.$data.') '.$ctes;
@ -142,10 +96,7 @@ class PostgreSQL extends DBEngine {
/** @var string */ /** @var string */
public $name = "pgsql"; public $name = "pgsql";
/** public function init(PDO $db) {
* @param \PDO $db
*/
public function init($db) {
if(array_key_exists('REMOTE_ADDR', $_SERVER)) { if(array_key_exists('REMOTE_ADDR', $_SERVER)) {
$db->exec("SET application_name TO 'shimmie [{$_SERVER['REMOTE_ADDR']}]';"); $db->exec("SET application_name TO 'shimmie [{$_SERVER['REMOTE_ADDR']}]';");
} }
@ -155,11 +106,7 @@ class PostgreSQL extends DBEngine {
$db->exec("SET statement_timeout TO 10000;"); $db->exec("SET statement_timeout TO 10000;");
} }
/** public function scoreql_to_sql(string $data): string {
* @param string $data
* @return string
*/
public function scoreql_to_sql($data) {
$data = str_replace("SCORE_AIPK", "SERIAL PRIMARY KEY", $data); $data = str_replace("SCORE_AIPK", "SERIAL PRIMARY KEY", $data);
$data = str_replace("SCORE_INET", "INET", $data); $data = str_replace("SCORE_INET", "INET", $data);
$data = str_replace("SCORE_BOOL_Y", "'t'", $data); $data = str_replace("SCORE_BOOL_Y", "'t'", $data);
@ -172,12 +119,7 @@ class PostgreSQL extends DBEngine {
return $data; return $data;
} }
/** public function create_table_sql(string $name, string $data): string {
* @param string $name
* @param string $data
* @return string
*/
public function create_table_sql($name, $data) {
$data = $this->scoreql_to_sql($data); $data = $this->scoreql_to_sql($data);
return "CREATE TABLE $name ($data)"; return "CREATE TABLE $name ($data)";
} }
@ -202,10 +144,7 @@ class SQLite extends DBEngine {
/** @var string */ /** @var string */
public $name = "sqlite"; public $name = "sqlite";
/** public function init(PDO $db) {
* @param \PDO $db
*/
public function init($db) {
ini_set('sqlite.assoc_case', 0); ini_set('sqlite.assoc_case', 0);
$db->exec("PRAGMA foreign_keys = ON;"); $db->exec("PRAGMA foreign_keys = ON;");
$db->sqliteCreateFunction('UNIX_TIMESTAMP', '_unix_timestamp', 1); $db->sqliteCreateFunction('UNIX_TIMESTAMP', '_unix_timestamp', 1);
@ -220,11 +159,7 @@ class SQLite extends DBEngine {
$db->sqliteCreateFunction('ln', '_ln', 1); $db->sqliteCreateFunction('ln', '_ln', 1);
} }
/** public function scoreql_to_sql(string $data): string {
* @param string $data
* @return string
*/
public function scoreql_to_sql($data) {
$data = str_replace("SCORE_AIPK", "INTEGER PRIMARY KEY", $data); $data = str_replace("SCORE_AIPK", "INTEGER PRIMARY KEY", $data);
$data = str_replace("SCORE_INET", "VARCHAR(45)", $data); $data = str_replace("SCORE_INET", "VARCHAR(45)", $data);
$data = str_replace("SCORE_BOOL_Y", "'Y'", $data); $data = str_replace("SCORE_BOOL_Y", "'Y'", $data);
@ -236,12 +171,7 @@ class SQLite extends DBEngine {
return $data; return $data;
} }
/** public function create_table_sql(string $name, string $data): string {
* @param string $name
* @param string $data
* @return string
*/
public function create_table_sql($name, $data) {
$data = $this->scoreql_to_sql($data); $data = $this->scoreql_to_sql($data);
$cols = array(); $cols = array();
$extras = ""; $extras = "";
@ -264,42 +194,19 @@ class SQLite extends DBEngine {
// {{{ cache engines // {{{ cache engines
interface CacheEngine { interface CacheEngine {
/** public function get(string $key);
* @param string $key public function set(string $key, $val, int $time=0);
* @return mixed public function delete(string $key);
*/ public function get_hits(): int;
public function get($key); public function get_misses(): int;
/**
* @param string $key
* @param mixed $val
* @param integer $time
* @return void
*/
public function set($key, $val, $time=0);
/**
* @return void
*/
public function delete($key);
/**
* @return integer
*/
public function get_hits();
/**
* @return integer
*/
public function get_misses();
} }
class NoCache implements CacheEngine { class NoCache implements CacheEngine {
public function get($key) {return false;} public function get(string $key) {return false;}
public function set($key, $val, $time=0) {} public function set(string $key, $val, int $time=0) {}
public function delete($key) {} public function delete(string $key) {}
public function get_hits() {return 0;} public function get_hits(): int {return 0;}
public function get_misses() {return 0;} public function get_misses(): int {return 0;}
} }
class MemcacheCache implements CacheEngine { class MemcacheCache implements CacheEngine {
/** @var \Memcache|null */ /** @var \Memcache|null */
@ -309,21 +216,13 @@ class MemcacheCache implements CacheEngine {
/** @var int */ /** @var int */
private $misses=0; private $misses=0;
/** public function __construct(string $args) {
* @param string $args
*/
public function __construct($args) {
$hp = explode(":", $args); $hp = explode(":", $args);
$this->memcache = new Memcache; $this->memcache = new Memcache;
@$this->memcache->pconnect($hp[0], $hp[1]); @$this->memcache->pconnect($hp[0], $hp[1]);
} }
/** public function get(string $key) {
* @param string $key
* @return array|bool|string
*/
public function get($key) {
assert('!is_null($key)');
$val = $this->memcache->get($key); $val = $this->memcache->get($key);
if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) {
$hit = $val === false ? "miss" : "hit"; $hit = $val === false ? "miss" : "hit";
@ -339,39 +238,22 @@ class MemcacheCache implements CacheEngine {
} }
} }
/** public function set(string $key, $val, int $time=0) {
* @param string $key
* @param mixed $val
* @param integer $time
*/
public function set($key, $val, $time=0) {
assert('!is_null($key)');
$this->memcache->set($key, $val, false, $time); $this->memcache->set($key, $val, false, $time);
if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) {
file_put_contents("data/cache.log", "Cache set: $key ($time)\n", FILE_APPEND); file_put_contents("data/cache.log", "Cache set: $key ($time)\n", FILE_APPEND);
} }
} }
/** public function delete(string $key) {
* @param string $key
*/
public function delete($key) {
assert('!is_null($key)');
$this->memcache->delete($key); $this->memcache->delete($key);
if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) {
file_put_contents("data/cache.log", "Cache delete: $key\n", FILE_APPEND); file_put_contents("data/cache.log", "Cache delete: $key\n", FILE_APPEND);
} }
} }
/** public function get_hits(): int {return $this->hits;}
* @return int public function get_misses(): int {return $this->misses;}
*/
public function get_hits() {return $this->hits;}
/**
* @return int
*/
public function get_misses() {return $this->misses;}
} }
class MemcachedCache implements CacheEngine { class MemcachedCache implements CacheEngine {
/** @var \Memcached|null */ /** @var \Memcached|null */
@ -381,10 +263,7 @@ class MemcachedCache implements CacheEngine {
/** @var int */ /** @var int */
private $misses=0; private $misses=0;
/** public function __construct(string $args) {
* @param string $args
*/
public function __construct($args) {
$hp = explode(":", $args); $hp = explode(":", $args);
$this->memcache = new Memcached; $this->memcache = new Memcached;
#$this->memcache->setOption(Memcached::OPT_COMPRESSION, False); #$this->memcache->setOption(Memcached::OPT_COMPRESSION, False);
@ -393,12 +272,7 @@ class MemcachedCache implements CacheEngine {
$this->memcache->addServer($hp[0], $hp[1]); $this->memcache->addServer($hp[0], $hp[1]);
} }
/** public function get(string $key) {
* @param string $key
* @return array|bool|string
*/
public function get($key) {
assert('!is_null($key)');
$key = urlencode($key); $key = urlencode($key);
$val = $this->memcache->get($key); $val = $this->memcache->get($key);
@ -418,16 +292,11 @@ class MemcachedCache implements CacheEngine {
} }
else { else {
error_log("Memcached error during get($key): $res"); error_log("Memcached error during get($key): $res");
return false;
} }
} }
/** public function set(string $key, $val, int $time=0) {
* @param string $key
* @param mixed $val
* @param int $time
*/
public function set($key, $val, $time=0) {
assert('!is_null($key)');
$key = urlencode($key); $key = urlencode($key);
$this->memcache->set($key, $val, $time); $this->memcache->set($key, $val, $time);
@ -440,11 +309,7 @@ class MemcachedCache implements CacheEngine {
} }
} }
/** public function delete(string $key) {
* @param string $key
*/
public function delete($key) {
assert('!is_null($key)');
$key = urlencode($key); $key = urlencode($key);
$this->memcache->delete($key); $this->memcache->delete($key);
@ -457,26 +322,18 @@ class MemcachedCache implements CacheEngine {
} }
} }
/** public function get_hits(): int {return $this->hits;}
* @return int public function get_misses(): int {return $this->misses;}
*/
public function get_hits() {return $this->hits;}
/**
* @return int
*/
public function get_misses() {return $this->misses;}
} }
class APCCache implements CacheEngine { class APCCache implements CacheEngine {
public $hits=0, $misses=0; public $hits=0, $misses=0;
public function __construct($args) { public function __construct(string $args) {
// $args is not used, but is passed in when APC cache is created. // $args is not used, but is passed in when APC cache is created.
} }
public function get($key) { public function get(string $key) {
assert('!is_null($key)');
$val = apc_fetch($key); $val = apc_fetch($key);
if($val) { if($val) {
$this->hits++; $this->hits++;
@ -488,18 +345,16 @@ class APCCache implements CacheEngine {
} }
} }
public function set($key, $val, $time=0) { public function set(string $key, $val, int $time=0) {
assert('!is_null($key)');
apc_store($key, $val, $time); apc_store($key, $val, $time);
} }
public function delete($key) { public function delete(string $key) {
assert('!is_null($key)');
apc_delete($key); apc_delete($key);
} }
public function get_hits() {return $this->hits;} public function get_hits(): int {return $this->hits;}
public function get_misses() {return $this->misses;} public function get_misses(): int {return $this->misses;}
} }
// }}} // }}}
/** @publicsection */ /** @publicsection */
@ -627,11 +482,7 @@ class Database {
} }
} }
/** public function commit(): bool {
* @return boolean|null
* @throws SCoreException
*/
public function commit() {
if(!is_null($this->db)) { if(!is_null($this->db)) {
if ($this->transaction === true) { if ($this->transaction === true) {
$this->transaction = false; $this->transaction = false;
@ -641,13 +492,12 @@ class Database {
throw new SCoreException("<p><b>Database Transaction Error:</b> Unable to call commit() as there is no transaction currently open."); throw new SCoreException("<p><b>Database Transaction Error:</b> Unable to call commit() as there is no transaction currently open.");
} }
} }
else {
throw new SCoreException("<p><b>Database Transaction Error:</b> Unable to call commit() as there is no connection currently open.");
}
} }
/** public function rollback(): bool {
* @return boolean|null
* @throws SCoreException
*/
public function rollback() {
if(!is_null($this->db)) { if(!is_null($this->db)) {
if ($this->transaction === true) { if ($this->transaction === true) {
$this->transaction = false; $this->transaction = false;
@ -657,39 +507,27 @@ class Database {
throw new SCoreException("<p><b>Database Transaction Error:</b> Unable to call rollback() as there is no transaction currently open."); throw new SCoreException("<p><b>Database Transaction Error:</b> Unable to call rollback() as there is no transaction currently open.");
} }
} }
else {
throw new SCoreException("<p><b>Database Transaction Error:</b> Unable to call rollback() as there is no connection currently open.");
}
} }
/** public function escape(string $input): string {
* @param string $input
* @return string
*/
public function escape($input) {
if(is_null($this->db)) $this->connect_db(); if(is_null($this->db)) $this->connect_db();
return $this->db->Quote($input); return $this->db->Quote($input);
} }
/** public function scoreql_to_sql(string $input): string {
* @param string $input
* @return string
*/
public function scoreql_to_sql($input) {
if(is_null($this->engine)) $this->connect_engine(); if(is_null($this->engine)) $this->connect_engine();
return $this->engine->scoreql_to_sql($input); return $this->engine->scoreql_to_sql($input);
} }
/** public function get_driver_name(): string {
* @return null|string
*/
public function get_driver_name() {
if(is_null($this->engine)) $this->connect_engine(); if(is_null($this->engine)) $this->connect_engine();
return $this->engine->name; return $this->engine->name;
} }
/** private function count_execs(string $sql, array $inputarray) {
* @param null|PDO $db
* @param string $sql
*/
private function count_execs($db, $sql, $inputarray) {
if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) { if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) {
$sql = trim(preg_replace('/\s+/msi', ' ', $sql)); $sql = trim(preg_replace('/\s+/msi', ' ', $sql));
if(isset($inputarray) && is_array($inputarray) && !empty($inputarray)) { if(isset($inputarray) && is_array($inputarray) && !empty($inputarray)) {
@ -706,7 +544,7 @@ class Database {
else $this->query_count++; else $this->query_count++;
} }
private function count_time($method, $start) { private function count_time(string $method, float $start) {
if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) { if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) {
$text = $method.":".(microtime(true) - $start)."\n"; $text = $method.":".(microtime(true) - $start)."\n";
file_put_contents("data/sql.log", $text, FILE_APPEND); file_put_contents("data/sql.log", $text, FILE_APPEND);
@ -714,18 +552,10 @@ class Database {
$this->dbtime += microtime(true) - $start; $this->dbtime += microtime(true) - $start;
} }
/** public function execute(string $query, array $args=array()): PDOStatement {
* Execute an SQL query and return an PDO result-set.
*
* @param string $query
* @param array $args
* @return PDOStatement
* @throws SCoreException
*/
public function execute($query, $args=array()) {
try { try {
if(is_null($this->db)) $this->connect_db(); if(is_null($this->db)) $this->connect_db();
$this->count_execs($this->db, $query, $args); $this->count_execs($query, $args);
$stmt = $this->db->prepare($query); $stmt = $this->db->prepare($query);
if (!array_key_exists(0, $args)) { if (!array_key_exists(0, $args)) {
foreach($args as $name=>$value) { foreach($args as $name=>$value) {
@ -755,7 +585,7 @@ class Database {
* @param array $args * @param array $args
* @return array * @return array
*/ */
public function get_all($query, $args=array()) { public function get_all(string $query, array $args=array()): array {
$_start = microtime(true); $_start = microtime(true);
$data = $this->execute($query, $args)->fetchAll(); $data = $this->execute($query, $args)->fetchAll();
$this->count_time("get_all", $_start); $this->count_time("get_all", $_start);
@ -769,7 +599,7 @@ class Database {
* @param array $args * @param array $args
* @return array|null * @return array|null
*/ */
public function get_row($query, $args=array()) { public function get_row(string $query, array $args=array()) {
$_start = microtime(true); $_start = microtime(true);
$row = $this->execute($query, $args)->fetch(); $row = $this->execute($query, $args)->fetch();
$this->count_time("get_row", $_start); $this->count_time("get_row", $_start);
@ -783,7 +613,7 @@ class Database {
* @param array $args * @param array $args
* @return array * @return array
*/ */
public function get_col($query, $args=array()) { public function get_col(string $query, array $args=array()): array {
$_start = microtime(true); $_start = microtime(true);
$stmt = $this->execute($query, $args); $stmt = $this->execute($query, $args);
$res = array(); $res = array();
@ -795,13 +625,13 @@ class Database {
} }
/** /**
* Execute an SQL query and return the the first row => the second rown. * Execute an SQL query and return the the first row => the second row.
* *
* @param string $query * @param string $query
* @param array $args * @param array $args
* @return array * @return array
*/ */
public function get_pairs($query, $args=array()) { public function get_pairs(string $query, array $args=array()): array {
$_start = microtime(true); $_start = microtime(true);
$stmt = $this->execute($query, $args); $stmt = $this->execute($query, $args);
$res = array(); $res = array();
@ -817,9 +647,9 @@ class Database {
* *
* @param string $query * @param string $query
* @param array $args * @param array $args
* @return mixed * @return mixed|null
*/ */
public function get_one($query, $args=array()) { public function get_one(string $query, array $args=array()) {
$_start = microtime(true); $_start = microtime(true);
$row = $this->execute($query, $args)->fetch(); $row = $this->execute($query, $args)->fetch();
$this->count_time("get_one", $_start); $this->count_time("get_one", $_start);
@ -832,7 +662,7 @@ class Database {
* @param string|null $seq * @param string|null $seq
* @return int * @return int
*/ */
public function get_last_insert_id($seq) { public function get_last_insert_id(string $seq): int {
if($this->engine->name == "pgsql") { if($this->engine->name == "pgsql") {
return $this->db->lastInsertId($seq); return $this->db->lastInsertId($seq);
} }
@ -847,7 +677,7 @@ class Database {
* @param string $name * @param string $name
* @param string $data * @param string $data
*/ */
public function create_table($name, $data) { public function create_table(string $name, string $data) {
if(is_null($this->engine)) { $this->connect_engine(); } if(is_null($this->engine)) { $this->connect_engine(); }
$data = trim($data, ", \t\n\r\0\x0B"); // mysql doesn't like trailing commas $data = trim($data, ", \t\n\r\0\x0B"); // mysql doesn't like trailing commas
$this->execute($this->engine->create_table_sql($name, $data)); $this->execute($this->engine->create_table_sql($name, $data));
@ -856,27 +686,26 @@ class Database {
/** /**
* Returns the number of tables present in the current database. * Returns the number of tables present in the current database.
* *
* @return int|null * @return int
* @throws SCoreException
*/ */
public function count_tables() { public function count_tables(): int {
if(is_null($this->db) || is_null($this->engine)) $this->connect_db(); if(is_null($this->db) || is_null($this->engine)) $this->connect_db();
if($this->engine->name === "mysql") { if($this->engine->name === "mysql") {
return count( return count(
$this->get_all("SHOW TABLES") $this->get_all("SHOW TABLES")
); );
} else if ($this->engine->name === "pgsql") { } else if ($this->engine->name === "pgsql") {
return count( return count(
$this->get_all("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'") $this->get_all("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'")
); );
} else if ($this->engine->name === "sqlite") { } else if ($this->engine->name === "sqlite") {
return count( return count(
$this->get_all("SELECT name FROM sqlite_master WHERE type = 'table'") $this->get_all("SELECT name FROM sqlite_master WHERE type = 'table'")
); );
} else { } else {
// Hard to find a universal way to do this... throw new SCoreException("Can't count tables for database type {$this->engine->name}");
return NULL;
} }
} }
} }
@ -889,20 +718,20 @@ class MockDatabase extends Database {
/** @var \NoCache|null */ /** @var \NoCache|null */
public $cache = null; public $cache = null;
/** public function __construct(array $responses = array()) {
* @param array $responses
*/
public function __construct($responses = array()) {
$this->cache = new NoCache(); $this->cache = new NoCache();
$this->responses = $responses; $this->responses = $responses;
} }
/** public function execute(string $query, array $params=array()): PDOStatement {
* @param string $query log_debug("mock-database",
* @param array $params "QUERY: " . $query .
* @return PDOStatement "\nARGS: " . var_export($params, true) .
*/ "\nRETURN: " . var_export($this->responses[$this->query_id], true)
public function execute($query, $params=array()) { );
return $this->responses[$this->query_id++];
}
public function _execute(string $query, array $params=array()) {
log_debug("mock-database", log_debug("mock-database",
"QUERY: " . $query . "QUERY: " . $query .
"\nARGS: " . var_export($params, true) . "\nARGS: " . var_export($params, true) .
@ -911,53 +740,16 @@ class MockDatabase extends Database {
return $this->responses[$this->query_id++]; return $this->responses[$this->query_id++];
} }
/** public function get_all(string $query, array $args=array()): array {return $this->_execute($query, $args);}
* @param string $query public function get_row(string $query, array $args=array()) {return $this->_execute($query, $args);}
* @param array $args public function get_col(string $query, array $args=array()): array {return $this->_execute($query, $args);}
* @return PDOStatement public function get_pairs(string $query, array $args=array()): array {return $this->_execute($query, $args);}
*/ public function get_one(string $query, array $args=array()) {return $this->_execute($query, $args);}
public function get_all($query, $args=array()) {return $this->execute($query, $args);}
/** public function get_last_insert_id(string $seq): int {return $this->query_id;}
* @param string $query
* @param array $args
* @return PDOStatement
*/
public function get_row($query, $args=array()) {return $this->execute($query, $args);}
/** public function scoreql_to_sql(string $sql): string {return $sql;}
* @param string $query public function create_table(string $name, string $def) {}
* @param array $args
* @return PDOStatement
*/
public function get_col($query, $args=array()) {return $this->execute($query, $args);}
/**
* @param string $query
* @param array $args
* @return PDOStatement
*/
public function get_pairs($query, $args=array()) {return $this->execute($query, $args);}
/**
* @param string $query
* @param array $args
* @return PDOStatement
*/
public function get_one($query, $args=array()) {return $this->execute($query, $args);}
/**
* @param null|string $seq
* @return int|string
*/
public function get_last_insert_id($seq) {return $this->query_id;}
/**
* @param string $sql
* @return string
*/
public function scoreql_to_sql($sql) {return $sql;}
public function create_table($name, $def) {}
public function connect_engine() {} public function connect_engine() {}
} }

View file

@ -29,13 +29,7 @@ class Email {
/** @var null|string */ /** @var null|string */
public $footer; public $footer;
/** public function __construct(string $to, string $subject, string $header, string $body) {
* @param string $to
* @param string $subject
* @param string $header
* @param string $body
*/
public function __construct($to, $subject, $header, $body) {
global $config; global $config;
$this->to = $to; $this->to = $to;
@ -60,7 +54,7 @@ class Email {
$this->footer = $config->get_string("mail_fot"); $this->footer = $config->get_string("mail_fot");
} }
public function send() { public function send(): bool {
$headers = "From: ".$this->sitename." <".$this->siteemail.">\r\n"; $headers = "From: ".$this->sitename." <".$this->siteemail.">\r\n";
$headers .= "Reply-To: ".$this->siteemail."\r\n"; $headers .= "Reply-To: ".$this->siteemail."\r\n";
$headers .= "X-Mailer: PHP/" . phpversion(). "\r\n"; $headers .= "X-Mailer: PHP/" . phpversion(). "\r\n";
@ -84,7 +78,7 @@ class Email {
<table width="550" cellpadding="0" cellspacing="0"> <table width="550" cellpadding="0" cellspacing="0">
<tr> <tr>
<td style="background-color:#FFFFFF;border-top:0px solid #333333;border-bottom:10px solid #FFFFFF;"><center><a href="'.$this->sitedomain.'"><IMG SRC="'.$this->header_img.'" alt="'.$this->sitename.'" name="Header" BORDER="0" align="center" title="'.$this->sitename.'"></a> <td style="background-color:#FFFFFF;border-top:0 solid #333333;border-bottom:10px solid #FFFFFF;"><center><a href="'.$this->sitedomain.'"><IMG SRC="'.$this->header_img.'" alt="'.$this->sitename.'" name="Header" BORDER="0" align="center" title="'.$this->sitename.'"></a>
</center></td> </center></td>
</tr> </tr>

View file

@ -43,10 +43,7 @@ class PageRequestEvent extends Event {
*/ */
public $part_count; public $part_count;
/** public function __construct(string $path) {
* @param string $path
*/
public function __construct($path) {
global $config; global $config;
// trim starting slashes // trim starting slashes
@ -82,7 +79,7 @@ class PageRequestEvent extends Event {
* @param string $name * @param string $name
* @return bool * @return bool
*/ */
public function page_matches(/*string*/ $name) { public function page_matches(string $name): bool {
$parts = explode("/", $name); $parts = explode("/", $name);
$this->part_count = count($parts); $this->part_count = count($parts);
@ -105,7 +102,7 @@ class PageRequestEvent extends Event {
* @param int $n * @param int $n
* @return string|null The argument (string) or NULL * @return string|null The argument (string) or NULL
*/ */
public function get_arg(/*int*/ $n) { public function get_arg(int $n) {
$offset = $this->part_count + $n; $offset = $this->part_count + $n;
if($offset >= 0 && $offset < $this->arg_count) { if($offset >= 0 && $offset < $this->arg_count) {
return $this->args[$offset]; return $this->args[$offset];
@ -119,7 +116,7 @@ class PageRequestEvent extends Event {
* Returns the number of arguments the page request has. * Returns the number of arguments the page request has.
* @return int * @return int
*/ */
public function count_args() { public function count_args(): int {
return int_escape($this->arg_count - $this->part_count); return int_escape($this->arg_count - $this->part_count);
} }
@ -127,10 +124,7 @@ class PageRequestEvent extends Event {
* Many things use these functions * Many things use these functions
*/ */
/** public function get_search_terms(): array {
* @return array
*/
public function get_search_terms() {
$search_terms = array(); $search_terms = array();
if($this->count_args() === 2) { if($this->count_args() === 2) {
$search_terms = Tag::explode($this->get_arg(0)); $search_terms = Tag::explode($this->get_arg(0));
@ -138,10 +132,7 @@ class PageRequestEvent extends Event {
return $search_terms; return $search_terms;
} }
/** public function get_page_number(): int {
* @return int
*/
public function get_page_number() {
$page_number = 1; $page_number = 1;
if($this->count_args() === 1) { if($this->count_args() === 1) {
$page_number = int_escape($this->get_arg(0)); $page_number = int_escape($this->get_arg(0));
@ -153,10 +144,7 @@ class PageRequestEvent extends Event {
return $page_number; return $page_number;
} }
/** public function get_page_size(): int {
* @return int
*/
public function get_page_size() {
global $config; global $config;
return $config->get_int('index_images'); return $config->get_int('index_images');
} }
@ -180,7 +168,7 @@ class CommandEvent extends Event {
/** /**
* @param string[] $args * @param string[] $args
*/ */
public function __construct(/*array(string)*/ $args) { public function __construct(array $args) {
global $user; global $user;
$opts = array(); $opts = array();
@ -257,10 +245,7 @@ class TextFormattingEvent extends Event {
*/ */
public $stripped; public $stripped;
/** public function __construct(string $text) {
* @param string $text
*/
public function __construct(/*string*/ $text) {
$h_text = html_escape(trim($text)); $h_text = html_escape(trim($text));
$this->original = $h_text; $this->original = $h_text;
$this->formatted = $h_text; $this->formatted = $h_text;
@ -308,13 +293,7 @@ class LogEvent extends Event {
*/ */
public $args; public $args;
/** public function __construct(string $section, int $priority, string $message, array $args) {
* @param string $section
* @param int $priority
* @param string $message
* @param array $args
*/
public function __construct($section, $priority, $message, $args) {
$this->section = $section; $this->section = $section;
$this->priority = $priority; $this->priority = $priority;
$this->message = $message; $this->message = $message;

View file

@ -92,10 +92,7 @@ abstract class Extension {
$this->theme = $this->get_theme_object(get_called_class()); $this->theme = $this->get_theme_object(get_called_class());
} }
/** public function is_live(): bool {
* @return boolean
*/
public function is_live() {
global $database; global $database;
return ( return (
empty($this->db_support) || empty($this->db_support) ||
@ -107,9 +104,9 @@ abstract class Extension {
* Find the theme object for a given extension. * Find the theme object for a given extension.
* *
* @param string $base * @param string $base
* @return Themelet * @return Themelet|null
*/ */
private function get_theme_object($base) { private function get_theme_object(string $base) {
$custom = 'Custom'.$base.'Theme'; $custom = 'Custom'.$base.'Theme';
$normal = $base.'Theme'; $normal = $base.'Theme';
@ -126,11 +123,10 @@ abstract class Extension {
/** /**
* Override this to change the priority of the extension, * Override this to change the priority of the extension,
* lower numbered ones will recieve events first. * lower numbered ones will receive events first.
*
* @return int * @return int
*/ */
public function get_priority() { public function get_priority(): int {
return 50; return 50;
} }
} }
@ -141,25 +137,13 @@ abstract class Extension {
* Several extensions have this in common, make a common API. * Several extensions have this in common, make a common API.
*/ */
abstract class FormatterExtension extends Extension { abstract class FormatterExtension extends Extension {
/**
* @param TextFormattingEvent $event
*/
public function onTextFormatting(TextFormattingEvent $event) { public function onTextFormatting(TextFormattingEvent $event) {
$event->formatted = $this->format($event->formatted); $event->formatted = $this->format($event->formatted);
$event->stripped = $this->strip($event->stripped); $event->stripped = $this->strip($event->stripped);
} }
/** abstract public function format(string $text): string;
* @param string $text abstract public function strip(string $text): string;
* @return string
*/
abstract public function format(/*string*/ $text);
/**
* @param string $text
* @return string
*/
abstract public function strip(/*string*/ $text);
} }
/** /**
@ -169,10 +153,6 @@ abstract class FormatterExtension extends Extension {
* so we have a base class to extend from. * so we have a base class to extend from.
*/ */
abstract class DataHandlerExtension extends Extension { abstract class DataHandlerExtension extends Extension {
/**
* @param DataUploadEvent $event
* @throws UploadException
*/
public function onDataUpload(DataUploadEvent $event) { public function onDataUpload(DataUploadEvent $event) {
$supported_ext = $this->supported_ext($event->type); $supported_ext = $this->supported_ext($event->type);
$check_contents = $this->check_contents($event->tmpname); $check_contents = $this->check_contents($event->tmpname);
@ -236,9 +216,6 @@ abstract class DataHandlerExtension extends Extension {
} }
} }
/**
* @param ThumbnailGenerationEvent $event
*/
public function onThumbnailGeneration(ThumbnailGenerationEvent $event) { public function onThumbnailGeneration(ThumbnailGenerationEvent $event) {
if($this->supported_ext($event->type)) { if($this->supported_ext($event->type)) {
if (method_exists($this, 'create_thumb_force') && $event->force == true) { if (method_exists($this, 'create_thumb_force') && $event->force == true) {
@ -250,9 +227,6 @@ abstract class DataHandlerExtension extends Extension {
} }
} }
/**
* @param DisplayingImageEvent $event
*/
public function onDisplayingImage(DisplayingImageEvent $event) { public function onDisplayingImage(DisplayingImageEvent $event) {
global $page; global $page;
if($this->supported_ext($event->image->ext)) { if($this->supported_ext($event->image->ext)) {
@ -269,29 +243,9 @@ abstract class DataHandlerExtension extends Extension {
protected function setup() {} protected function setup() {}
*/ */
/** abstract protected function supported_ext(string $ext): bool;
* @param string $ext abstract protected function check_contents(string $tmpname): bool;
* @return bool abstract protected function create_image_from_data(string $filename, array $metadata);
*/ abstract protected function create_thumb(string $hash): bool;
abstract protected function supported_ext($ext);
/**
* @param string $tmpname
* @return bool
*/
abstract protected function check_contents($tmpname);
/**
* @param string $filename
* @param array $metadata
* @return Image|null
*/
abstract protected function create_image_from_data($filename, $metadata);
/**
* @param string $hash
* @return bool
*/
abstract protected function create_thumb($hash);
} }

View file

@ -72,17 +72,15 @@ class Image {
public $source; public $source;
/** @var boolean */ /** @var boolean */
public $locked; public $locked = false;
/** /**
* One will very rarely construct an image directly, more common * One will very rarely construct an image directly, more common
* would be to use Image::by_id, Image::by_hash, etc. * would be to use Image::by_id, Image::by_hash, etc.
* *
* @param null|mixed $row * @param null|mixed[] $row
*/ */
public function __construct($row=null) { public function __construct(array $row=null) {
assert('is_null($row) || is_array($row)');
if(!is_null($row)) { if(!is_null($row)) {
foreach($row as $name => $value) { foreach($row as $name => $value) {
// some databases use table.name rather than name // some databases use table.name rather than name
@ -97,40 +95,19 @@ class Image {
} }
} }
/** public static function by_id(int $id) {
* Find an image by ID.
*
* @param int $id
* @return Image
*/
public static function by_id(/*int*/ $id) {
assert('is_numeric($id)');
global $database; global $database;
$row = $database->get_row("SELECT * FROM images WHERE images.id=:id", array("id"=>$id)); $row = $database->get_row("SELECT * FROM images WHERE images.id=:id", array("id"=>$id));
return ($row ? new Image($row) : null); return ($row ? new Image($row) : null);
} }
/** public static function by_hash(string $hash) {
* Find an image by hash.
*
* @param string $hash
* @return Image
*/
public static function by_hash(/*string*/ $hash) {
assert('is_string($hash)');
global $database; global $database;
$row = $database->get_row("SELECT images.* FROM images WHERE hash=:hash", array("hash"=>$hash)); $row = $database->get_row("SELECT images.* FROM images WHERE hash=:hash", array("hash"=>$hash));
return ($row ? new Image($row) : null); return ($row ? new Image($row) : null);
} }
/** public static function by_random(array $tags=array()) {
* Pick a random image out of a set.
*
* @param string[] $tags
* @return Image
*/
public static function by_random($tags=array()) {
assert('is_array($tags)');
$max = Image::count_images($tags); $max = Image::count_images($tags);
if ($max < 1) return null; // From Issue #22 - opened by HungryFeline on May 30, 2011. if ($max < 1) return null; // From Issue #22 - opened by HungryFeline on May 30, 2011.
$rand = mt_rand(0, $max-1); $rand = mt_rand(0, $max-1);
@ -148,10 +125,7 @@ class Image {
* @throws SCoreException * @throws SCoreException
* @return Image[] * @return Image[]
*/ */
public static function find_images(/*int*/ $start, /*int*/ $limit, $tags=array()) { public static function find_images(int $start, int $limit, array $tags=array()): array {
assert('is_numeric($start)');
assert('is_numeric($limit)');
assert('is_array($tags)');
global $database, $user, $config; global $database, $user, $config;
$images = array(); $images = array();
@ -185,11 +159,7 @@ class Image {
return $images; return $images;
} }
/** public static function validate_accel(array $tags): bool {
* @param string[] $tags
* @return boolean
*/
public static function validate_accel($tags) {
$yays = 0; $yays = 0;
$nays = 0; $nays = 0;
foreach($tags as $tag) { foreach($tags as $tag) {
@ -202,14 +172,7 @@ class Image {
return ($yays > 1 || $nays > 0); return ($yays > 1 || $nays > 0);
} }
/** public static function get_accelerated_result(array $tags, int $offset, int $limit) {
* @param string[] $tags
* @param int $offset
* @param int $limit
* @return null|PDOStatement
* @throws SCoreException
*/
public static function get_accelerated_result($tags, $offset, $limit) {
global $database; global $database;
if(!Image::validate_accel($tags)) { if(!Image::validate_accel($tags)) {
@ -262,15 +225,14 @@ class Image {
* @param string[] $tags * @param string[] $tags
* @return int * @return int
*/ */
public static function count_images($tags=array()) { public static function count_images(array $tags=array()): int {
assert('is_array($tags)');
global $database; global $database;
$tag_count = count($tags); $tag_count = count($tags);
if($tag_count === 0) { if($tag_count === 0) {
$total = $database->cache->get("image-count"); $total = $database->cache->get("image-count");
if(!$total) { if(!$total) {
$total = $database->get_one("SELECT COUNT(*) FROM images"); $total = $database->get_one("SELECT COUNT(*) FROM images") || 0;
$database->cache->set("image-count", $total, 600); $database->cache->set("image-count", $total, 600);
} }
return $total; return $total;
@ -278,11 +240,11 @@ class Image {
else if($tag_count === 1 && !preg_match("/[:=><\*\?]/", $tags[0])) { else if($tag_count === 1 && !preg_match("/[:=><\*\?]/", $tags[0])) {
return $database->get_one( return $database->get_one(
$database->scoreql_to_sql("SELECT count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"), $database->scoreql_to_sql("SELECT count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"),
array("tag"=>$tags[0])); array("tag"=>$tags[0])) || 0;
} }
else { else {
$querylet = Image::build_search_querylet($tags); $querylet = Image::build_search_querylet($tags);
return $database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables); return $database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables) || 0;
} }
} }
@ -292,8 +254,7 @@ class Image {
* @param string[] $tags * @param string[] $tags
* @return float * @return float
*/ */
public static function count_pages($tags=array()) { public static function count_pages(array $tags=array()): float {
assert('is_array($tags)');
global $config; global $config;
return ceil(Image::count_images($tags) / $config->get_int('index_images')); return ceil(Image::count_images($tags) / $config->get_int('index_images'));
} }
@ -312,9 +273,7 @@ class Image {
* @param bool $next * @param bool $next
* @return Image * @return Image
*/ */
public function get_next($tags=array(), $next=true) { public function get_next(array $tags=array(), bool $next=true) {
assert('is_array($tags)');
assert('is_bool($next)');
global $database; global $database;
if($next) { if($next) {
@ -351,7 +310,7 @@ class Image {
* @param string[] $tags * @param string[] $tags
* @return Image * @return Image
*/ */
public function get_prev($tags=array()) { public function get_prev(array $tags=array()) {
return $this->get_next($tags, false); return $this->get_next($tags, false);
} }
@ -543,7 +502,7 @@ class Image {
* *
* @param string $new_source * @param string $new_source
*/ */
public function set_source(/*string*/ $new_source) { public function set_source(string $new_source) {
global $database; global $database;
$old_source = $this->source; $old_source = $this->source;
if(empty($new_source)) $new_source = null; if(empty($new_source)) $new_source = null;
@ -617,8 +576,8 @@ class Image {
* @param string[] $tags * @param string[] $tags
* @throws Exception * @throws Exception
*/ */
public function set_tags($tags) { public function set_tags(array $tags) {
assert('is_array($tags) && count($tags) > 0', var_export($tags, true)); assert('count($tags) > 0', var_export($tags, true));
global $database; global $database;
if(count($tags) <= 0) { if(count($tags) <= 0) {
@ -792,8 +751,7 @@ class Image {
* @param string[] $terms * @param string[] $terms
* @return \Querylet * @return \Querylet
*/ */
private static function build_search_querylet($terms) { private static function build_search_querylet(array $terms): Querylet {
assert('is_array($terms)');
global $database; global $database;
$tag_querylets = array(); $tag_querylets = array();
@ -935,7 +893,7 @@ class Image {
* @param TagQuerylet[] $tag_querylets * @param TagQuerylet[] $tag_querylets
* @return Querylet * @return Querylet
*/ */
private static function build_accurate_search_querylet($tag_querylets) { private static function build_accurate_search_querylet(array $tag_querylets): Querylet {
global $database; global $database;
$positive_tag_id_array = array(); $positive_tag_id_array = array();
@ -1080,13 +1038,7 @@ class Image {
* *
*/ */
class Tag { class Tag {
/** public static function implode(array $tags): string {
* @param string[] $tags
* @return string
*/
public static function implode($tags) {
assert('is_array($tags)');
sort($tags); sort($tags);
$tags = implode(' ', $tags); $tags = implode(' ', $tags);
@ -1100,9 +1052,8 @@ class Tag {
* @param bool $tagme add "tagme" if the string is empty * @param bool $tagme add "tagme" if the string is empty
* @return string[] * @return string[]
*/ */
public static function explode($tags, $tagme=true) { public static function explode(string $tags, bool $tagme=true): array {
global $database; global $database;
assert('is_string($tags)');
$tags = explode(' ', trim($tags)); $tags = explode(' ', trim($tags));
@ -1266,7 +1217,7 @@ function add_image($tmpname, $filename, $tags) {
* @param int $orig_height * @param int $orig_height
* @return integer[] * @return integer[]
*/ */
function get_thumbnail_size(/*int*/ $orig_width, /*int*/ $orig_height) { function get_thumbnail_size(int $orig_width, int $orig_height) {
global $config; global $config;
if($orig_width === 0) $orig_width = 192; if($orig_width === 0) $orig_width = 192;

View file

@ -47,7 +47,7 @@ class Page {
* Set what this page should do; "page", "data", or "redirect". * Set what this page should do; "page", "data", or "redirect".
* @param string $mode * @param string $mode
*/ */
public function set_mode($mode) { public function set_mode(string $mode) {
$this->mode = $mode; $this->mode = $mode;
} }
@ -55,7 +55,7 @@ class Page {
* Set the page's MIME type. * Set the page's MIME type.
* @param string $type * @param string $type
*/ */
public function set_type($type) { public function set_type(string $type) {
$this->type = $type; $this->type = $type;
} }
@ -75,7 +75,7 @@ class Page {
* Set the raw data to be sent. * Set the raw data to be sent.
* @param string $data * @param string $data
*/ */
public function set_data($data) { public function set_data(string $data) {
$this->data = $data; $this->data = $data;
} }
@ -83,7 +83,7 @@ class Page {
* Set the recommended download filename. * Set the recommended download filename.
* @param string $filename * @param string $filename
*/ */
public function set_filename($filename) { public function set_filename(string $filename) {
$this->filename = $filename; $this->filename = $filename;
} }
@ -101,7 +101,7 @@ class Page {
* to a page in the same site). * to a page in the same site).
* @param string $redirect * @param string $redirect
*/ */
public function set_redirect($redirect) { public function set_redirect(string $redirect) {
$this->redirect = $redirect; $this->redirect = $redirect;
} }
@ -142,31 +142,19 @@ class Page {
* Set the HTTP status code * Set the HTTP status code
* @param int $code * @param int $code
*/ */
public function set_code($code) { public function set_code(int $code) {
$this->code = $code; $this->code = $code;
} }
/** public function set_title(string $title) {
* Set the window title.
* @param string $title
*/
public function set_title($title) {
$this->title = $title; $this->title = $title;
} }
/** public function set_heading(string $heading) {
* Set the main heading.
* @param string $heading
*/
public function set_heading($heading) {
$this->heading = $heading; $this->heading = $heading;
} }
/** public function set_subheading(string $subheading) {
* Set the sub heading.
* @param string $subheading
*/
public function set_subheading($subheading) {
$this->subheading = $subheading; $this->subheading = $subheading;
} }
@ -175,7 +163,7 @@ class Page {
* @param string $line * @param string $line
* @param int $position * @param int $position
*/ */
public function add_html_header($line, $position=50) { public function add_html_header(string $line, int $position=50) {
while(isset($this->html_headers[$position])) $position++; while(isset($this->html_headers[$position])) $position++;
$this->html_headers[$position] = $line; $this->html_headers[$position] = $line;
} }
@ -185,7 +173,7 @@ class Page {
* @param string $line * @param string $line
* @param int $position * @param int $position
*/ */
public function add_http_header($line, $position=50) { public function add_http_header(string $line, int $position=50) {
while(isset($this->http_headers[$position])) $position++; while(isset($this->http_headers[$position])) $position++;
$this->http_headers[$position] = $line; $this->http_headers[$position] = $line;
} }
@ -200,7 +188,7 @@ class Page {
* @param int $time * @param int $time
* @param string $path * @param string $path
*/ */
public function add_cookie($name, $value, $time, $path) { public function add_cookie(string $name, $value, $time, $path) {
$full_name = COOKIE_PREFIX."_".$name; $full_name = COOKIE_PREFIX."_".$name;
$this->cookies[] = array($full_name, $value, $time, $path); $this->cookies[] = array($full_name, $value, $time, $path);
} }
@ -209,7 +197,7 @@ class Page {
* @param string $name * @param string $name
* @return string|null * @return string|null
*/ */
public function get_cookie(/*string*/ $name) { public function get_cookie(string $name) {
$full_name = COOKIE_PREFIX."_".$name; $full_name = COOKIE_PREFIX."_".$name;
if(isset($_COOKIE[$full_name])) { if(isset($_COOKIE[$full_name])) {
return $_COOKIE[$full_name]; return $_COOKIE[$full_name];
@ -223,7 +211,7 @@ class Page {
* Get all the HTML headers that are currently set and return as a string. * Get all the HTML headers that are currently set and return as a string.
* @return string * @return string
*/ */
public function get_all_html_headers() { public function get_all_html_headers(): string {
$data = ''; $data = '';
ksort($this->html_headers); ksort($this->html_headers);
foreach ($this->html_headers as $line) { foreach ($this->html_headers as $line) {

View file

@ -19,8 +19,7 @@
* *
*/ */
/** @private */ function _d(string $name, $value) {if(!defined($name)) define($name, $value);}
function _d($name, $value) {if(!defined($name)) define($name, $value);}
_d("DATABASE_DSN", null); // string PDO database connection details _d("DATABASE_DSN", null); // string PDO database connection details
_d("DATABASE_KA", true); // string Keep database connection alive _d("DATABASE_KA", true); // string Keep database connection alive
_d("CACHE_DSN", null); // string cache connection details _d("CACHE_DSN", null); // string cache connection details

View file

@ -48,10 +48,10 @@ class User {
* One will very rarely construct a user directly, more common * One will very rarely construct a user directly, more common
* would be to use User::by_id, User::by_session, etc. * would be to use User::by_id, User::by_session, etc.
* *
* @param mixed $row * @param mixed[] $row
* @throws SCoreException * @throws SCoreException
*/ */
public function __construct($row) { public function __construct(array $row) {
global $_shm_user_classes; global $_shm_user_classes;
$this->id = int_escape($row['id']); $this->id = int_escape($row['id']);
@ -68,14 +68,7 @@ class User {
} }
} }
/** public static function by_session(string $name, string $session) {
* Construct a User by session.
*
* @param string $name
* @param string $session
* @return null|User
*/
public static function by_session(/*string*/ $name, /*string*/ $session) {
global $config, $database; global $config, $database;
$row = $database->cache->get("user-session:$name-$session"); $row = $database->cache->get("user-session:$name-$session");
if(!$row) { if(!$row) {
@ -91,13 +84,7 @@ class User {
return is_null($row) ? null : new User($row); return is_null($row) ? null : new User($row);
} }
/** public static function by_id(int $id) {
* Construct a User by session.
* @param int $id
* @return null|User
*/
public static function by_id(/*int*/ $id) {
assert('is_numeric($id)', var_export($id, true));
global $database; global $database;
if($id === 1) { if($id === 1) {
$cached = $database->cache->get('user-id:'.$id); $cached = $database->cache->get('user-id:'.$id);
@ -108,27 +95,13 @@ class User {
return is_null($row) ? null : new User($row); return is_null($row) ? null : new User($row);
} }
/** public static function by_name(string $name) {
* Construct a User by name.
* @param string $name
* @return null|User
*/
public static function by_name(/*string*/ $name) {
assert('is_string($name)', var_export($name, true));
global $database; global $database;
$row = $database->get_row($database->scoreql_to_sql("SELECT * FROM users WHERE SCORE_STRNORM(name) = SCORE_STRNORM(:name)"), array("name"=>$name)); $row = $database->get_row($database->scoreql_to_sql("SELECT * FROM users WHERE SCORE_STRNORM(name) = SCORE_STRNORM(:name)"), array("name"=>$name));
return is_null($row) ? null : new User($row); return is_null($row) ? null : new User($row);
} }
/** public static function by_name_and_pass(string $name, string $pass) {
* Construct a User by name and password.
* @param string $name
* @param string $pass
* @return null|User
*/
public static function by_name_and_pass(/*string*/ $name, /*string*/ $pass) {
assert('is_string($name)', var_export($name, true));
assert('is_string($pass)', var_export($pass, true));
$user = User::by_name($name); $user = User::by_name($name);
if($user) { if($user) {
if($user->passhash == md5(strtolower($name) . $pass)) { if($user->passhash == md5(strtolower($name) . $pass)) {
@ -138,65 +111,38 @@ class User {
return $user; return $user;
} }
} }
return null;
} }
/* useful user object functions start here */ /* useful user object functions start here */
public function can(string $ability): bool {
/**
* @param string $ability
* @return bool
*/
public function can($ability) {
return $this->class->can($ability); return $this->class->can($ability);
} }
/** public function is_anonymous(): bool {
* Test if this user is anonymous (not logged in).
*
* @return bool
*/
public function is_anonymous() {
global $config; global $config;
return ($this->id === $config->get_int('anon_id')); return ($this->id === $config->get_int('anon_id'));
} }
/** public function is_logged_in(): bool {
* Test if this user is logged in.
*
* @return bool
*/
public function is_logged_in() {
global $config; global $config;
return ($this->id !== $config->get_int('anon_id')); return ($this->id !== $config->get_int('anon_id'));
} }
/** public function is_admin(): bool {
* Test if this user is an administrator.
*
* @return bool
*/
public function is_admin() {
return ($this->class->name === "admin"); return ($this->class->name === "admin");
} }
/** public function set_class(string $class) {
* @param string $class
*/
public function set_class(/*string*/ $class) {
assert('is_string($class)', var_export($class, true));
global $database; global $database;
$database->Execute("UPDATE users SET class=:class WHERE id=:id", array("class"=>$class, "id"=>$this->id)); $database->Execute("UPDATE users SET class=:class WHERE id=:id", array("class"=>$class, "id"=>$this->id));
log_info("core-user", 'Set class for '.$this->name.' to '.$class); log_info("core-user", 'Set class for '.$this->name.' to '.$class);
} }
/** public function set_name(string $name) {
* @param string $name
* @throws Exception
*/
public function set_name(/*string*/ $name) {
global $database; global $database;
if(User::by_name($name)) { if(User::by_name($name)) {
throw new Exception("Desired username is already in use"); throw new Exception("Desired username is already in use");
@ -207,10 +153,7 @@ class User {
log_info("core-user", "Changed username for {$old_name} to {$this->name}"); log_info("core-user", "Changed username for {$old_name} to {$this->name}");
} }
/** public function set_password(string $password) {
* @param string $password
*/
public function set_password(/*string*/ $password) {
global $database; global $database;
$hash = password_hash($password, PASSWORD_BCRYPT); $hash = password_hash($password, PASSWORD_BCRYPT);
if(is_string($hash)) { if(is_string($hash)) {
@ -223,10 +166,7 @@ class User {
} }
} }
/** public function set_email(string $address) {
* @param string $address
*/
public function set_email(/*string*/ $address) {
global $database; global $database;
$database->Execute("UPDATE users SET email=:email WHERE id=:id", array("email"=>$address, "id"=>$this->id)); $database->Execute("UPDATE users SET email=:email WHERE id=:id", array("email"=>$address, "id"=>$this->id));
log_info("core-user", 'Set email for '.$this->name); log_info("core-user", 'Set email for '.$this->name);
@ -238,7 +178,7 @@ class User {
* *
* @return String of HTML * @return String of HTML
*/ */
public function get_avatar_html() { public function get_avatar_html(): string {
// FIXME: configurable // FIXME: configurable
global $config; global $config;
if($config->get_string("avatar_host") === "gravatar") { if($config->get_string("avatar_host") === "gravatar") {
@ -267,25 +207,25 @@ class User {
* *
* @return string A string containing auth token (MD5sum) * @return string A string containing auth token (MD5sum)
*/ */
public function get_auth_token() { public function get_auth_token(): string {
global $config; global $config;
$salt = DATABASE_DSN; $salt = DATABASE_DSN;
$addr = get_session_ip($config); $addr = get_session_ip($config);
return md5(md5($this->passhash . $addr) . "salty-csrf-" . $salt); return md5(md5($this->passhash . $addr) . "salty-csrf-" . $salt);
} }
public function get_auth_html() { public function get_auth_html(): string {
$at = $this->get_auth_token(); $at = $this->get_auth_token();
return '<input type="hidden" name="auth_token" value="'.$at.'">'; return '<input type="hidden" name="auth_token" value="'.$at.'">';
} }
public function check_auth_token() { public function check_auth_token(): bool {
return (isset($_POST["auth_token"]) && $_POST["auth_token"] == $this->get_auth_token()); return (isset($_POST["auth_token"]) && $_POST["auth_token"] == $this->get_auth_token());
} }
} }
class MockUser extends User { class MockUser extends User {
public function __construct($name) { public function __construct(string $name) {
$row = array( $row = array(
"name" => $name, "name" => $name,
"id" => 1, "id" => 1,

View file

@ -25,12 +25,7 @@ class UserClass {
*/ */
public $abilities = array(); public $abilities = array();
/** public function __construct(string $name, string $parent=null, array $abilities=array()) {
* @param string $name
* @param null|string $parent
* @param array $abilities
*/
public function __construct($name, $parent=null, $abilities=array()) {
global $_shm_user_classes; global $_shm_user_classes;
$this->name = $name; $this->name = $name;
@ -50,7 +45,7 @@ class UserClass {
* @return bool * @return bool
* @throws SCoreException * @throws SCoreException
*/ */
public function can(/*string*/ $ability) { public function can(string $ability): bool {
if(array_key_exists($ability, $this->abilities)) { if(array_key_exists($ability, $this->abilities)) {
$val = $this->abilities[$ability]; $val = $this->abilities[$ability];
return $val; return $val;

View file

@ -11,7 +11,7 @@ require_once "vendor/shish/libcontext-php/context.php";
* @param string $input * @param string $input
* @return string * @return string
*/ */
function html_escape($input) { function html_escape($input): string {
return htmlentities($input, ENT_QUOTES, "UTF-8"); return htmlentities($input, ENT_QUOTES, "UTF-8");
} }
@ -21,7 +21,7 @@ function html_escape($input) {
* @param string $input * @param string $input
* @return string * @return string
*/ */
function html_unescape($input) { function html_unescape($input): string {
return html_entity_decode($input, ENT_QUOTES, "UTF-8"); return html_entity_decode($input, ENT_QUOTES, "UTF-8");
} }
@ -31,7 +31,7 @@ function html_unescape($input) {
* @param string $input * @param string $input
* @return int * @return int
*/ */
function int_escape($input) { function int_escape($input): int {
/* /*
Side note, Casting to an integer is FASTER than using intval. Side note, Casting to an integer is FASTER than using intval.
http://hakre.wordpress.com/2010/05/13/php-casting-vs-intval/ http://hakre.wordpress.com/2010/05/13/php-casting-vs-intval/
@ -45,7 +45,7 @@ function int_escape($input) {
* @param string $input * @param string $input
* @return string * @return string
*/ */
function url_escape($input) { function url_escape($input): string {
/* /*
Shish: I have a feeling that these three lines are important, possibly for searching for tags with slashes in them like fate/stay_night Shish: I have a feeling that these three lines are important, possibly for searching for tags with slashes in them like fate/stay_night
green-ponies: indeed~ green-ponies: indeed~
@ -80,7 +80,7 @@ function url_escape($input) {
* @param string $input * @param string $input
* @return string * @return string
*/ */
function sql_escape($input) { function sql_escape($input): string {
global $database; global $database;
return $database->escape($input); return $database->escape($input);
} }
@ -92,7 +92,7 @@ function sql_escape($input) {
* @param mixed $input * @param mixed $input
* @return boolean * @return boolean
*/ */
function bool_escape($input) { function bool_escape($input): bool {
/* /*
Sometimes, I don't like PHP -- this, is one of those times... Sometimes, I don't like PHP -- this, is one of those times...
"a boolean FALSE is not considered a valid boolean value by this function." "a boolean FALSE is not considered a valid boolean value by this function."
@ -132,13 +132,7 @@ function no_escape($input) {
return $input; return $input;
} }
/** function clamp(int $val, int $min=null, int $max=null): int {
* @param int $val
* @param int|null $min
* @param int|null $max
* @return int
*/
function clamp($val, $min, $max) {
if(!is_numeric($val) || (!is_null($min) && $val < $min)) { if(!is_numeric($val) || (!is_null($min) && $val < $min)) {
$val = $min; $val = $min;
} }
@ -151,13 +145,7 @@ function clamp($val, $min, $max) {
return $val; return $val;
} }
/** function xml_tag(string $name, array $attrs=array(), array $children=array()): string {
* @param string $name
* @param array $attrs
* @param array $children
* @return string
*/
function xml_tag($name, $attrs=array(), $children=array()) {
$xml = "<$name "; $xml = "<$name ";
foreach($attrs as $k => $v) { foreach($attrs as $k => $v) {
$xv = str_replace('&#039;', '&apos;', htmlspecialchars($v, ENT_QUOTES)); $xv = str_replace('&#039;', '&apos;', htmlspecialchars($v, ENT_QUOTES));
@ -184,6 +172,7 @@ function xml_tag($name, $attrs=array(), $children=array()) {
* @param int $limit how long the string should be * @param int $limit how long the string should be
* @param string $break where to break the string * @param string $break where to break the string
* @param string $pad what to add to the end of the string after truncating * @param string $pad what to add to the end of the string after truncating
* @return string
*/ */
function truncate($string, $limit, $break=" ", $pad="...") { function truncate($string, $limit, $break=" ", $pad="...") {
// return with no change if string is shorter than $limit // return with no change if string is shorter than $limit
@ -202,14 +191,10 @@ function truncate($string, $limit, $break=" ", $pad="...") {
/** /**
* Turn a human readable filesize into an integer, eg 1KB -> 1024 * Turn a human readable filesize into an integer, eg 1KB -> 1024
* *
* @param string|integer $limit * @param string $limit
* @return int * @return int
*/ */
function parse_shorthand_int($limit) { function parse_shorthand_int(string $limit): int {
if(is_numeric($limit)) {
return (int)$limit;
}
if(preg_match('/^([\d\.]+)([gmk])?b?$/i', (string)$limit, $m)) { if(preg_match('/^([\d\.]+)([gmk])?b?$/i', (string)$limit, $m)) {
$value = $m[1]; $value = $m[1];
if (isset($m[2])) { if (isset($m[2])) {
@ -235,7 +220,7 @@ function parse_shorthand_int($limit) {
* @param integer $int * @param integer $int
* @return string * @return string
*/ */
function to_shorthand_int($int) { function to_shorthand_int(int $int): string {
if($int >= pow(1024, 3)) { if($int >= pow(1024, 3)) {
return sprintf("%.1fGB", $int / pow(1024, 3)); return sprintf("%.1fGB", $int / pow(1024, 3));
} }
@ -258,7 +243,7 @@ function to_shorthand_int($int) {
* @param bool $html * @param bool $html
* @return string * @return string
*/ */
function autodate($date, $html=true) { function autodate(string $date, bool $html=true): string {
$cpu = date('c', strtotime($date)); $cpu = date('c', strtotime($date));
$hum = date('F j, Y; H:i', strtotime($date)); $hum = date('F j, Y; H:i', strtotime($date));
return ($html ? "<time datetime='$cpu'>$hum</time>" : $hum); return ($html ? "<time datetime='$cpu'>$hum</time>" : $hum);
@ -270,7 +255,7 @@ function autodate($date, $html=true) {
* @param string $dateTime * @param string $dateTime
* @return bool * @return bool
*/ */
function isValidDateTime($dateTime) { function isValidDateTime(string $dateTime): bool {
if (preg_match("/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/", $dateTime, $matches)) { if (preg_match("/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/", $dateTime, $matches)) {
if (checkdate($matches[2], $matches[3], $matches[1])) { if (checkdate($matches[2], $matches[3], $matches[1])) {
return true; return true;
@ -286,7 +271,7 @@ function isValidDateTime($dateTime) {
* @param string $date * @param string $date
* @return bool * @return bool
*/ */
function isValidDate($date) { function isValidDate(string $date): bool {
if (preg_match("/^(\d{4})-(\d{2})-(\d{2})$/", $date, $matches)) { if (preg_match("/^(\d{4})-(\d{2})-(\d{2})$/", $date, $matches)) {
// checkdate wants (month, day, year) // checkdate wants (month, day, year)
if (checkdate($matches[2], $matches[3], $matches[1])) { if (checkdate($matches[2], $matches[3], $matches[1])) {
@ -297,10 +282,7 @@ function isValidDate($date) {
return false; return false;
} }
/** function validate_input(array $inputs): array {
* @param string[] $inputs
*/
function validate_input($inputs) {
$outputs = array(); $outputs = array();
foreach($inputs as $key => $validations) { foreach($inputs as $key => $validations) {
@ -398,7 +380,7 @@ function validate_input($inputs) {
* @param string $ban_reason * @param string $ban_reason
* @return string * @return string
*/ */
function show_ip($ip, $ban_reason) { function show_ip(string $ip, string $ban_reason): string {
global $user; global $user;
$u_reason = url_escape($ban_reason); $u_reason = url_escape($ban_reason);
$u_end = url_escape("+1 week"); $u_end = url_escape("+1 week");
@ -407,26 +389,12 @@ function show_ip($ip, $ban_reason) {
return $ip; return $ip;
} }
/** function startsWith(string $haystack, string $needle): bool {
* Checks if a given string contains another at the beginning.
*
* @param string $haystack String to examine.
* @param string $needle String to look for.
* @return bool
*/
function startsWith(/*string*/ $haystack, /*string*/ $needle) {
$length = strlen($needle); $length = strlen($needle);
return (substr($haystack, 0, $length) === $needle); return (substr($haystack, 0, $length) === $needle);
} }
/** function endsWith(string $haystack, string $needle): bool {
* Checks if a given string contains another at the end.
*
* @param string $haystack String to examine.
* @param string $needle String to look for.
* @return bool
*/
function endsWith(/*string*/ $haystack, /*string*/ $needle) {
$length = strlen($needle); $length = strlen($needle);
$start = $length * -1; //negative $start = $length * -1; //negative
return (substr($haystack, $start) === $needle); return (substr($haystack, $start) === $needle);
@ -446,7 +414,7 @@ function endsWith(/*string*/ $haystack, /*string*/ $needle) {
* @param null|string $query * @param null|string $query
* @return string * @return string
*/ */
function make_link($page=null, $query=null) { function make_link(string $page=null, string $query=null): string {
global $config; global $config;
if(is_null($page)) $page = $config->get_string('main_page'); if(is_null($page)) $page = $config->get_string('main_page');
@ -481,14 +449,14 @@ function make_link($page=null, $query=null) {
/** /**
* Take the current URL and modify some parameters * Take the current URL and modify some parameters
* *
* @param $changes * @param array $changes
* @return string * @return string
*/ */
function modify_current_url($changes) { function modify_current_url(array $changes): string {
return modify_url($_SERVER['QUERY_STRING'], $changes); return modify_url($_SERVER['QUERY_STRING'], $changes);
} }
function modify_url($url, $changes) { function modify_url(string $url, array $changes): string {
// SHIT: PHP is officially the worst web API ever because it does not // SHIT: PHP is officially the worst web API ever because it does not
// have a built-in function to do this. // have a built-in function to do this.
@ -526,7 +494,7 @@ function modify_url($url, $changes) {
* @param string $link * @param string $link
* @return string * @return string
*/ */
function make_http(/*string*/ $link) { function make_http(string $link) {
if(strpos($link, "://") > 0) { if(strpos($link, "://") > 0) {
return $link; return $link;
} }
@ -553,7 +521,7 @@ function make_http(/*string*/ $link) {
* *
* @return string * @return string
*/ */
function make_form($target, $method="POST", $multipart=False, $form_id="", $onsubmit="") { function make_form(string $target, string $method="POST", bool $multipart=False, string $form_id="", string $onsubmit=""): string {
global $user; global $user;
if($method == "GET") { if($method == "GET") {
$link = html_escape($target); $link = html_escape($target);
@ -578,7 +546,7 @@ function make_form($target, $method="POST", $multipart=False, $form_id="", $onsu
* @param string $file The filename * @param string $file The filename
* @return string * @return string
*/ */
function mtimefile($file) { function mtimefile(string $file): string {
$data_href = get_base_href(); $data_href = get_base_href();
$mtime = filemtime($file); $mtime = filemtime($file);
return "$data_href/$file?$mtime"; return "$data_href/$file?$mtime";
@ -589,7 +557,7 @@ function mtimefile($file) {
* *
* @return string * @return string
*/ */
function get_theme() { function get_theme(): string {
global $config; global $config;
$theme = $config->get_string("theme", "default"); $theme = $config->get_string("theme", "default");
if(!file_exists("themes/$theme")) $theme = "default"; if(!file_exists("themes/$theme")) $theme = "default";
@ -602,7 +570,7 @@ function get_theme() {
* @param string $pattern * @param string $pattern
* @return array * @return array
*/ */
function zglob($pattern) { function zglob(string $pattern): array {
$results = array(); $results = array();
if(preg_match('/(.*)\{(.*)\}(.*)/', $pattern, $matches)) { if(preg_match('/(.*)\{(.*)\}(.*)/', $pattern, $matches)) {
$braced = explode(",", $matches[2]); $braced = explode(",", $matches[2]);
@ -621,11 +589,13 @@ function zglob($pattern) {
/** /**
* Gets contact link as mailto: or http: * Gets contact link as mailto: or http:
* @return string * @return string|null
*/ */
function contact_link() { function contact_link() {
global $config; global $config;
$text = $config->get_string('contact_link'); $text = $config->get_string('contact_link');
if(is_null($text)) return null;
if( if(
startsWith($text, "http:") || startsWith($text, "http:") ||
startsWith($text, "https:") || startsWith($text, "https:") ||
@ -650,10 +620,7 @@ function contact_link() {
* CAPTCHA abstraction * * CAPTCHA abstraction *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/** function captcha_get_html(): string {
* @return string
*/
function captcha_get_html() {
global $config, $user; global $config, $user;
if(DEBUG && ip_in_range($_SERVER['REMOTE_ADDR'], "127.0.0.0/8")) return ""; if(DEBUG && ip_in_range($_SERVER['REMOTE_ADDR'], "127.0.0.0/8")) return "";
@ -673,10 +640,7 @@ function captcha_get_html() {
return $captcha; return $captcha;
} }
/** function captcha_check(): bool {
* @return bool
*/
function captcha_check() {
global $config, $user; global $config, $user;
if(DEBUG && ip_in_range($_SERVER['REMOTE_ADDR'], "127.0.0.0/8")) return true; if(DEBUG && ip_in_range($_SERVER['REMOTE_ADDR'], "127.0.0.0/8")) return true;
@ -715,10 +679,27 @@ function captcha_check() {
* *
* @return bool True if HTTPS is enabled * @return bool True if HTTPS is enabled
*/ */
function is_https_enabled() { function is_https_enabled(): bool {
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'); return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
} }
define("MIME_TYPE_MAP", [
'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png',
'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'ico' => 'image/x-icon',
'swf' => 'application/x-shockwave-flash', 'video/x-flv' => 'flv',
'svg' => 'image/svg+xml', 'pdf' => 'application/pdf',
'zip' => 'application/zip', 'gz' => 'application/x-gzip',
'tar' => 'application/x-tar', 'bz' => 'application/x-bzip',
'bz2' => 'application/x-bzip2', 'txt' => 'text/plain',
'asc' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html',
'css' => 'text/css', 'js' => 'text/javascript',
'xml' => 'text/xml', 'xsl' => 'application/xsl+xml',
'ogg' => 'application/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav',
'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg',
'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php',
'mp4' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm'
]);
/** /**
* Get MIME type for file * Get MIME type for file
* *
@ -728,33 +709,13 @@ function is_https_enabled() {
* *
* @param string $file File path * @param string $file File path
* @param string $ext * @param string $ext
* @param bool $list
* @return string * @return string
*/ */
function getMimeType($file, $ext="", $list=false) { function getMimeType(string $file, string $ext=""): string {
// Static extension lookup // Static extension lookup
$ext = strtolower($ext); $ext = strtolower($ext);
static $exts = array(
'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png',
'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'ico' => 'image/x-icon',
'swf' => 'application/x-shockwave-flash', 'video/x-flv' => 'flv',
'svg' => 'image/svg+xml', 'pdf' => 'application/pdf',
'zip' => 'application/zip', 'gz' => 'application/x-gzip',
'tar' => 'application/x-tar', 'bz' => 'application/x-bzip',
'bz2' => 'application/x-bzip2', 'txt' => 'text/plain',
'asc' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html',
'css' => 'text/css', 'js' => 'text/javascript',
'xml' => 'text/xml', 'xsl' => 'application/xsl+xml',
'ogg' => 'application/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav',
'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg',
'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php',
'mp4' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm'
);
if ($list === true){ return $exts; } if (isset($exts[$ext])) { return MIME_TYPE_MAP[$ext]; }
if (isset($exts[$ext])) { return $exts[$ext]; }
$type = false; $type = false;
// Fileinfo documentation says fileinfo_open() will use the // Fileinfo documentation says fileinfo_open() will use the
@ -785,13 +746,12 @@ function getMimeType($file, $ext="", $list=false) {
* @param string $mime_type * @param string $mime_type
* @return bool|string * @return bool|string
*/ */
function getExtension ($mime_type){ function getExtension(string $mime_type) {
if(empty($mime_type)){ if(empty($mime_type)){
return false; return false;
} }
$extensions = getMimeType(null, null, true); $ext = array_search($mime_type, MIME_TYPE_MAP);
$ext = array_search($mime_type, $extensions);
return ($ext ? $ext : false); return ($ext ? $ext : false);
} }
@ -816,7 +776,7 @@ function blockcmp(Block $a, Block $b) {
* *
* @return int * @return int
*/ */
function get_memory_limit() { function get_memory_limit(): int {
global $config; global $config;
// thumbnail generation requires lots of memory // thumbnail generation requires lots of memory
@ -866,7 +826,7 @@ function get_memory_limit() {
* @param Config $config * @param Config $config
* @return string * @return string
*/ */
function get_session_ip(Config $config) { function get_session_ip(Config $config): string {
$mask = $config->get_string("session_hash_mask", "255.255.0.0"); $mask = $config->get_string("session_hash_mask", "255.255.0.0");
$addr = $_SERVER['REMOTE_ADDR']; $addr = $_SERVER['REMOTE_ADDR'];
$addr = inet_ntop(inet_pton($addr) & inet_pton($mask)); $addr = inet_ntop(inet_pton($addr) & inet_pton($mask));
@ -886,7 +846,7 @@ function get_session_ip(Config $config) {
* @param string $text * @param string $text
* @param string $type * @param string $type
*/ */
function flash_message(/*string*/ $text, /*string*/ $type="info") { function flash_message(string $text, string $type="info") {
global $page; global $page;
$current = $page->get_cookie("flash_message"); $current = $page->get_cookie("flash_message");
if($current) { if($current) {
@ -907,7 +867,7 @@ function flash_message(/*string*/ $text, /*string*/ $type="info") {
* *
* @return string * @return string
*/ */
function get_base_href() { function get_base_href(): string {
if(defined("BASE_HREF")) return BASE_HREF; if(defined("BASE_HREF")) return BASE_HREF;
$possible_vars = array('SCRIPT_NAME', 'PHP_SELF', 'PATH_INFO', 'ORIG_PATH_INFO'); $possible_vars = array('SCRIPT_NAME', 'PHP_SELF', 'PATH_INFO', 'ORIG_PATH_INFO');
$ok_var = null; $ok_var = null;
@ -931,19 +891,13 @@ function get_base_href() {
* @param string $string * @param string $string
* @return string * @return string
*/ */
function format_text(/*string*/ $string) { function format_text(string $string): string {
$tfe = new TextFormattingEvent($string); $tfe = new TextFormattingEvent($string);
send_event($tfe); send_event($tfe);
return $tfe->formatted; return $tfe->formatted;
} }
/** function warehouse_path(string $base, string $hash, bool $create=true): string {
* @param string $base
* @param string $hash
* @param bool $create
* @return string
*/
function warehouse_path(/*string*/ $base, /*string*/ $hash, /*bool*/ $create=true) {
$ab = substr($hash, 0, 2); $ab = substr($hash, 0, 2);
$cd = substr($hash, 2, 2); $cd = substr($hash, 2, 2);
if(WH_SPLITS == 2) { if(WH_SPLITS == 2) {
@ -956,11 +910,7 @@ function warehouse_path(/*string*/ $base, /*string*/ $hash, /*bool*/ $create=tru
return $pa; return $pa;
} }
/** function data_path(string $filename): string {
* @param string $filename
* @return string
*/
function data_path($filename) {
$filename = "data/" . $filename; $filename = "data/" . $filename;
if(!file_exists(dirname($filename))) mkdir(dirname($filename), 0755, true); if(!file_exists(dirname($filename))) mkdir(dirname($filename), 0755, true);
return $filename; return $filename;
@ -982,7 +932,7 @@ if (!function_exists('mb_strlen')) {
* @param string $mfile * @param string $mfile
* @return array|bool * @return array|bool
*/ */
function transload($url, $mfile) { function transload(string $url, string $mfile) {
global $config; global $config;
if($config->get_string("transload_engine") === "curl" && function_exists("curl_init")) { if($config->get_string("transload_engine") === "curl" && function_exists("curl_init")) {
@ -1076,7 +1026,7 @@ if (!function_exists('http_parse_headers')) { #http://www.php.net/manual/en/func
* @param string $name * @param string $name
* @return string|bool * @return string|bool
*/ */
function findHeader ($headers, $name) { function findHeader(array $headers, string $name) {
if (!is_array($headers)) { if (!is_array($headers)) {
return false; return false;
} }
@ -1103,7 +1053,7 @@ function findHeader ($headers, $name) {
* @param string $fname * @param string $fname
* @return string|null * @return string|null
*/ */
function manual_include($fname) { function manual_include(string $fname) {
static $included = array(); static $included = array();
if(!file_exists($fname)) return null; if(!file_exists($fname)) return null;
@ -1159,7 +1109,7 @@ define("SCORE_LOG_NOTSET", 0);
* @param bool|string $flash * @param bool|string $flash
* @param array $args * @param array $args
*/ */
function log_msg(/*string*/ $section, /*int*/ $priority, /*string*/ $message, $flash=false, $args=array()) { function log_msg(string $section, int $priority, string $message, $flash=false, $args=array()) {
send_event(new LogEvent($section, $priority, $message, $args)); send_event(new LogEvent($section, $priority, $message, $args));
$threshold = defined("CLI_LOG_LEVEL") ? CLI_LOG_LEVEL : 0; $threshold = defined("CLI_LOG_LEVEL") ? CLI_LOG_LEVEL : 0;
@ -1181,43 +1131,43 @@ function log_msg(/*string*/ $section, /*int*/ $priority, /*string*/ $message, $f
* @param bool|string $flash * @param bool|string $flash
* @param array $args * @param array $args
*/ */
function log_debug( /*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_DEBUG, $message, $flash, $args);} function log_debug( string $section, string $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_DEBUG, $message, $flash, $args);}
/** /**
* @param string $section * @param string $section
* @param string $message * @param string $message
* @param bool|string $flash * @param bool|string $flash
* @param array $args * @param array $args
*/ */
function log_info( /*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_INFO, $message, $flash, $args);} function log_info( string $section, string $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_INFO, $message, $flash, $args);}
/** /**
* @param string $section * @param string $section
* @param string $message * @param string $message
* @param bool|string $flash * @param bool|string $flash
* @param array $args * @param array $args
*/ */
function log_warning( /*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_WARNING, $message, $flash, $args);} function log_warning( string $section, string $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_WARNING, $message, $flash, $args);}
/** /**
* @param string $section * @param string $section
* @param string $message * @param string $message
* @param bool|string $flash * @param bool|string $flash
* @param array $args * @param array $args
*/ */
function log_error( /*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_ERROR, $message, $flash, $args);} function log_error( string $section, string $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_ERROR, $message, $flash, $args);}
/** /**
* @param string $section * @param string $section
* @param string $message * @param string $message
* @param bool|string $flash * @param bool|string $flash
* @param array $args * @param array $args
*/ */
function log_critical(/*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_CRITICAL, $message, $flash, $args);} function log_critical(string $section, string $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_CRITICAL, $message, $flash, $args);}
/** /**
* Get a unique ID for this request, useful for grouping log messages. * Get a unique ID for this request, useful for grouping log messages.
* *
* @return null|string * @return string
*/ */
function get_request_id() { function get_request_id(): string {
static $request_id = null; static $request_id = null;
if(!$request_id) { if(!$request_id) {
// not completely trustworthy, as a user can spoof this // not completely trustworthy, as a user can spoof this
@ -1243,7 +1193,7 @@ function get_request_id() {
* @param mixed $to_remove * @param mixed $to_remove
* @return array * @return array
*/ */
function array_remove($array, $to_remove) { function array_remove(array $array, $to_remove): array {
$array = array_unique($array); $array = array_unique($array);
$a2 = array(); $a2 = array();
foreach($array as $existing) { foreach($array as $existing) {
@ -1263,7 +1213,7 @@ function array_remove($array, $to_remove) {
* @param mixed $element * @param mixed $element
* @return array * @return array
*/ */
function array_add($array, $element) { function array_add(array $array, $element): array {
// Could we just use array_push() ? // Could we just use array_push() ?
// http://www.php.net/manual/en/function.array-push.php // http://www.php.net/manual/en/function.array-push.php
$array[] = $element; $array[] = $element;
@ -1277,7 +1227,7 @@ function array_add($array, $element) {
* @param array $array * @param array $array
* @return array * @return array
*/ */
function array_iunique($array) { function array_iunique(array $array): array {
$ok = array(); $ok = array();
foreach($array as $element) { foreach($array as $element) {
$found = false; $found = false;
@ -1302,7 +1252,7 @@ function array_iunique($array) {
* @param string $CIDR * @param string $CIDR
* @return bool * @return bool
*/ */
function ip_in_range($IP, $CIDR) { function ip_in_range(string $IP, string $CIDR): bool {
list ($net, $mask) = explode("/", $CIDR); list ($net, $mask) = explode("/", $CIDR);
$ip_net = ip2long ($net); $ip_net = ip2long ($net);
@ -1323,7 +1273,7 @@ function ip_in_range($IP, $CIDR) {
* *
* @param string $f * @param string $f
*/ */
function deltree($f) { function deltree(string $f) {
//Because Windows (I know, bad excuse) //Because Windows (I know, bad excuse)
if(PHP_OS === 'WINNT') { if(PHP_OS === 'WINNT') {
$real = realpath($f); $real = realpath($f);
@ -1369,7 +1319,7 @@ function deltree($f) {
* @param string $source * @param string $source
* @param string $target * @param string $target
*/ */
function full_copy($source, $target) { function full_copy(string $source, string $target) {
if(is_dir($source)) { if(is_dir($source)) {
@mkdir($target); @mkdir($target);
@ -1401,7 +1351,7 @@ function full_copy($source, $target) {
* @param string $_sub_dir * @param string $_sub_dir
* @return array file list * @return array file list
*/ */
function list_files(/*string*/ $base, $_sub_dir="") { function list_files(string $base, string $_sub_dir=""): array {
assert(is_dir($base)); assert(is_dir($base));
$file_list = array(); $file_list = array();
@ -1438,11 +1388,7 @@ function list_files(/*string*/ $base, $_sub_dir="") {
return $file_list; return $file_list;
} }
/** function path_to_tags(string $path): string {
* @param string $path
* @return string
*/
function path_to_tags($path) {
$matches = array(); $matches = array();
if(preg_match("/\d+ - (.*)\.([a-zA-Z]+)/", basename($path), $matches)) { if(preg_match("/\d+ - (.*)\.([a-zA-Z]+)/", basename($path), $matches)) {
$tags = $matches[1]; $tags = $matches[1];
@ -1548,7 +1494,7 @@ function _dump_event_listeners($event_listeners, $path) {
* @param string $ext_name Main class name (eg ImageIO as opposed to ImageIOTheme or ImageIOTest) * @param string $ext_name Main class name (eg ImageIO as opposed to ImageIOTheme or ImageIOTest)
* @return bool * @return bool
*/ */
function ext_is_live($ext_name) { function ext_is_live(string $ext_name): bool {
if (class_exists($ext_name)) { if (class_exists($ext_name)) {
/** @var Extension $ext */ /** @var Extension $ext */
$ext = new $ext_name(); $ext = new $ext_name();
@ -1607,7 +1553,7 @@ $_shm_load_start = microtime(true);
* *
* @return string debug info to add to the page. * @return string debug info to add to the page.
*/ */
function get_debug_info() { function get_debug_info(): string {
global $config, $_shm_event_count, $database, $_shm_load_start; global $config, $_shm_event_count, $database, $_shm_load_start;
$i_mem = sprintf("%5.2f", ((memory_get_peak_usage(true)+512)/1024)/1024); $i_mem = sprintf("%5.2f", ((memory_get_peak_usage(true)+512)/1024)/1024);
@ -1705,9 +1651,9 @@ function _sanitise_environment() {
/** /**
* @param string $_theme * @param string $_theme
* @return array * @return string[]
*/ */
function _get_themelet_files($_theme) { function _get_themelet_files(string $_theme): array {
$base_themelets = array(); $base_themelets = array();
if(file_exists('themes/'.$_theme.'/custompage.class.php')) $base_themelets[] = 'themes/'.$_theme.'/custompage.class.php'; if(file_exists('themes/'.$_theme.'/custompage.class.php')) $base_themelets[] = 'themes/'.$_theme.'/custompage.class.php';
$base_themelets[] = 'themes/'.$_theme.'/layout.class.php'; $base_themelets[] = 'themes/'.$_theme.'/layout.class.php';
@ -1758,7 +1704,7 @@ function _fatal_error(Exception $e) {
* @param string $str * @param string $str
* @return string * @return string
*/ */
function _decaret($str) { function _decaret(string $str): string {
$out = ""; $out = "";
$length = strlen($str); $length = strlen($str);
for($i=0; $i<$length; $i++) { for($i=0; $i<$length; $i++) {
@ -1775,10 +1721,7 @@ function _decaret($str) {
return $out; return $out;
} }
/** function _get_user(): User {
* @return User
*/
function _get_user() {
global $config, $page; global $config, $page;
$user = null; $user = null;
if($page->get_cookie("user") && $page->get_cookie("session")) { if($page->get_cookie("user") && $page->get_cookie("session")) {
@ -1796,7 +1739,7 @@ function _get_user() {
} }
/** /**
* @return string * @return string|null
*/ */
function _get_query() { function _get_query() {
return @$_POST["q"]?:@$_GET["q"]; return @$_POST["q"]?:@$_GET["q"];

View file

@ -27,9 +27,6 @@ class AdminBuildingEvent extends Event {
/** @var \Page */ /** @var \Page */
public $page; public $page;
/**
* @param Page $page
*/
public function __construct(Page $page) { public function __construct(Page $page) {
$this->page = $page; $this->page = $page;
} }
@ -41,10 +38,7 @@ class AdminActionEvent extends Event {
/** @var bool */ /** @var bool */
public $redirect = true; public $redirect = true;
/** public function __construct(string $action) {
* @param string $action
*/
public function __construct(/*string*/ $action) {
$this->action = $action; $this->action = $action;
} }
} }

View file

@ -12,13 +12,7 @@ class AdminPageTheme extends Themelet {
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
} }
/** protected function button(string $name, string $action, bool $protected=false): string {
* @param string $name
* @param string $action
* @param bool $protected
* @return string
*/
protected function button(/*string*/ $name, /*string*/ $action, /*boolean*/ $protected=false) {
$c_protected = $protected ? " protected" : ""; $c_protected = $protected ? " protected" : "";
$html = make_form(make_link("admin/$action"), "POST", false, "admin$c_protected"); $html = make_form(make_link("admin/$action"), "POST", false, "admin$c_protected");
if($protected) { if($protected) {

View file

@ -16,11 +16,7 @@ class AddAliasEvent extends Event {
/** @var string */ /** @var string */
public $newtag; public $newtag;
/** public function __construct(string $oldtag, string $newtag) {
* @param string $oldtag
* @param string $newtag
*/
public function __construct($oldtag, $newtag) {
$this->oldtag = trim($oldtag); $this->oldtag = trim($oldtag);
$this->newtag = trim($newtag); $this->newtag = trim($newtag);
} }
@ -131,11 +127,7 @@ class AliasEditor extends Extension {
} }
} }
/** private function get_alias_csv(Database $database): string {
* @param Database $database
* @return string
*/
private function get_alias_csv(Database $database) {
$csv = ""; $csv = "";
$aliases = $database->get_pairs("SELECT oldtag, newtag FROM aliases ORDER BY newtag"); $aliases = $database->get_pairs("SELECT oldtag, newtag FROM aliases ORDER BY newtag");
foreach($aliases as $old => $new) { foreach($aliases as $old => $new) {
@ -144,11 +136,7 @@ class AliasEditor extends Extension {
return $csv; return $csv;
} }
/** private function add_alias_csv(Database $database, string $csv) {
* @param Database $database
* @param string $csv
*/
private function add_alias_csv(Database $database, /*string*/ $csv) {
$csv = str_replace("\r", "\n", $csv); $csv = str_replace("\r", "\n", $csv);
foreach(explode("\n", $csv) as $line) { foreach(explode("\n", $csv) as $line) {
$parts = str_getcsv($line); $parts = str_getcsv($line);
@ -170,9 +158,8 @@ class AliasEditor extends Extension {
* Add alias *after* mass tag editing, else the MTE will * Add alias *after* mass tag editing, else the MTE will
* search for the images and be redirected to the alias, * search for the images and be redirected to the alias,
* missing out the images tagged with the old tag. * missing out the images tagged with the old tag.
*
* @return int * @return int
*/ */
public function get_priority() {return 60;} public function get_priority(): int {return 60;}
} }

View file

@ -16,12 +16,7 @@ class AuthorSetEvent extends Event {
/** @var string */ /** @var string */
public $author; public $author;
/** public function __construct(Image $image, User $user, string $author) {
* @param Image $image
* @param User $user
* @param string $author
*/
public function __construct(Image $image, User $user, /*string*/ $author) {
$this->image = $image; $this->image = $image;
$this->user = $user; $this->user = $user;
$this->author = $author; $this->author = $author;
@ -407,57 +402,32 @@ class Artists extends Extension {
} }
} }
/** private function get_artistName_by_imageID(int $imageID): string {
* @param int $imageID
* @return string
*/
private function get_artistName_by_imageID($imageID) {
assert(is_numeric($imageID));
global $database; global $database;
$result = $database->get_row("SELECT author FROM images WHERE id = ?", array($imageID)); $result = $database->get_row("SELECT author FROM images WHERE id = ?", array($imageID));
return stripslashes($result['author']); return stripslashes($result['author']);
} }
/** private function url_exists_by_url(string $url): bool {
* @param string $url
* @return bool
*/
private function url_exists_by_url($url) {
global $database; global $database;
$result = $database->get_one("SELECT COUNT(1) FROM artist_urls WHERE url = ?", array($url)); $result = $database->get_one("SELECT COUNT(1) FROM artist_urls WHERE url = ?", array($url));
return ($result != 0); return ($result != 0);
} }
/** private function member_exists_by_name(string $member): bool {
* @param string $member
* @return bool
*/
private function member_exists_by_name($member) {
global $database; global $database;
$result = $database->get_one("SELECT COUNT(1) FROM artist_members WHERE name = ?", array($member)); $result = $database->get_one("SELECT COUNT(1) FROM artist_members WHERE name = ?", array($member));
return ($result != 0); return ($result != 0);
} }
/** private function alias_exists_by_name(string $alias): bool {
* @param string $alias
* @return bool
*/
private function alias_exists_by_name($alias) {
global $database; global $database;
$result = $database->get_one("SELECT COUNT(1) FROM artist_alias WHERE alias = ?", array($alias)); $result = $database->get_one("SELECT COUNT(1) FROM artist_alias WHERE alias = ?", array($alias));
return ($result != 0); return ($result != 0);
} }
/** private function alias_exists(int $artistID, string $alias): bool {
* @param int $artistID
* @param string $alias
* @return bool
*/
private function alias_exists($artistID, $alias) {
assert(is_numeric($artistID));
global $database; global $database;
$result = $database->get_one( $result = $database->get_one(
"SELECT COUNT(1) FROM artist_alias WHERE artist_id = ? AND alias = ?", "SELECT COUNT(1) FROM artist_alias WHERE artist_id = ? AND alias = ?",
@ -466,131 +436,66 @@ class Artists extends Extension {
return ($result != 0); return ($result != 0);
} }
/** private function get_artistID_by_url(string $url): int {
* @param string $url
* @return int
*/
private function get_artistID_by_url($url) {
global $database; global $database;
return $database->get_one("SELECT artist_id FROM artist_urls WHERE url = ?", array($url)); return $database->get_one("SELECT artist_id FROM artist_urls WHERE url = ?", array($url));
} }
/** private function get_artistID_by_memberName(string $member): int {
* @param string $member
* @return int
*/
private function get_artistID_by_memberName($member) {
global $database; global $database;
return $database->get_one("SELECT artist_id FROM artist_members WHERE name = ?", array($member)); return $database->get_one("SELECT artist_id FROM artist_members WHERE name = ?", array($member));
} }
/** private function get_artistName_by_artistID(int $artistID): string {
* @param int $artistID
* @return string
*/
private function get_artistName_by_artistID($artistID) {
assert(is_numeric($artistID));
global $database; global $database;
return $database->get_one("SELECT name FROM artists WHERE id = ?", array($artistID)); return $database->get_one("SELECT name FROM artists WHERE id = ?", array($artistID));
} }
/** private function get_artistID_by_aliasID(int $aliasID): int {
* @param int $aliasID
* @return int
*/
private function get_artistID_by_aliasID($aliasID) {
assert(is_numeric($aliasID));
global $database; global $database;
return $database->get_one("SELECT artist_id FROM artist_alias WHERE id = ?", array($aliasID)); return $database->get_one("SELECT artist_id FROM artist_alias WHERE id = ?", array($aliasID));
} }
/** private function get_artistID_by_memberID(int $memberID): int {
* @param int $memberID
* @return int
*/
private function get_artistID_by_memberID($memberID) {
assert(is_numeric($memberID));
global $database; global $database;
return $database->get_one("SELECT artist_id FROM artist_members WHERE id = ?", array($memberID)); return $database->get_one("SELECT artist_id FROM artist_members WHERE id = ?", array($memberID));
} }
/** private function get_artistID_by_urlID(int $urlID): int {
* @param int $urlID
* @return int
*/
private function get_artistID_by_urlID($urlID) {
assert(is_numeric($urlID));
global $database; global $database;
return $database->get_one("SELECT artist_id FROM artist_urls WHERE id = ?", array($urlID)); return $database->get_one("SELECT artist_id FROM artist_urls WHERE id = ?", array($urlID));
} }
/** private function delete_alias(int $aliasID) {
* @param int $aliasID
*/
private function delete_alias($aliasID) {
assert(is_numeric($aliasID));
global $database; global $database;
$database->execute("DELETE FROM artist_alias WHERE id = ?", array($aliasID)); $database->execute("DELETE FROM artist_alias WHERE id = ?", array($aliasID));
} }
/** private function delete_url(int $urlID) {
* @param int $urlID
*/
private function delete_url($urlID) {
assert(is_numeric($urlID));
global $database; global $database;
$database->execute("DELETE FROM artist_urls WHERE id = ?", array($urlID)); $database->execute("DELETE FROM artist_urls WHERE id = ?", array($urlID));
} }
/** private function delete_member(int $memberID) {
* @param int $memberID
*/
private function delete_member($memberID) {
assert(is_numeric($memberID));
global $database; global $database;
$database->execute("DELETE FROM artist_members WHERE id = ?", array($memberID)); $database->execute("DELETE FROM artist_members WHERE id = ?", array($memberID));
} }
/** private function get_alias_by_id(int $aliasID): array {
* @param int $aliasID
* @return array
*/
private function get_alias_by_id($aliasID) {
assert(is_numeric($aliasID));
global $database; global $database;
$result = $database->get_row("SELECT * FROM artist_alias WHERE id = ?", array($aliasID)); $result = $database->get_row("SELECT * FROM artist_alias WHERE id = ?", array($aliasID));
$result["alias"] = stripslashes($result["alias"]); $result["alias"] = stripslashes($result["alias"]);
return $result; return $result;
} }
/** private function get_url_by_id(int $urlID): array {
* @param int $urlID
* @return array
*/
private function get_url_by_id($urlID) {
assert(is_numeric($urlID));
global $database; global $database;
$result = $database->get_row("SELECT * FROM artist_urls WHERE id = ?", array($urlID)); $result = $database->get_row("SELECT * FROM artist_urls WHERE id = ?", array($urlID));
$result["url"] = stripslashes($result["url"]); $result["url"] = stripslashes($result["url"]);
return $result; return $result;
} }
/** private function get_member_by_id(int $memberID): array {
* @param int $memberID
* @return array
*/
private function get_member_by_id($memberID) {
assert(is_numeric($memberID));
global $database; global $database;
$result = $database->get_row("SELECT * FROM artist_members WHERE id = ?", array($memberID)); $result = $database->get_row("SELECT * FROM artist_members WHERE id = ?", array($memberID));
$result["name"] = stripslashes($result["name"]); $result["name"] = stripslashes($result["name"]);
@ -701,15 +606,7 @@ class Artists extends Extension {
$this->save_existing_alias($inputs['aliasID'], $inputs['alias'], $user->id); $this->save_existing_alias($inputs['aliasID'], $inputs['alias'], $user->id);
} }
/** private function save_existing_alias(int $aliasID, string $alias, int $userID) {
* @param int $aliasID
* @param string $alias
* @param int $userID
*/
private function save_existing_alias($aliasID, $alias, $userID) {
assert(is_numeric($userID));
assert(is_numeric($aliasID));
global $database; global $database;
$database->execute( $database->execute(
"UPDATE artist_alias SET alias = ?, updated = now(), user_id = ? WHERE id = ? ", "UPDATE artist_alias SET alias = ?, updated = now(), user_id = ? WHERE id = ? ",
@ -726,15 +623,7 @@ class Artists extends Extension {
$this->save_existing_url($inputs['urlID'], $inputs['url'], $user->id); $this->save_existing_url($inputs['urlID'], $inputs['url'], $user->id);
} }
/** private function save_existing_url(int $urlID, string $url, int $userID) {
* @param int $urlID
* @param string $url
* @param int $userID
*/
private function save_existing_url($urlID, $url, $userID) {
assert(is_numeric($userID));
assert(is_numeric($urlID));
global $database; global $database;
$database->execute( $database->execute(
"UPDATE artist_urls SET url = ?, updated = now(), user_id = ? WHERE id = ?", "UPDATE artist_urls SET url = ?, updated = now(), user_id = ? WHERE id = ?",
@ -751,15 +640,7 @@ class Artists extends Extension {
$this->save_existing_member($inputs['memberID'], $inputs['name'], $user->id); $this->save_existing_member($inputs['memberID'], $inputs['name'], $user->id);
} }
/** private function save_existing_member(int $memberID, string $memberName, int $userID) {
* @param int $memberID
* @param string $memberName
* @param int $userID
*/
private function save_existing_member($memberID, $memberName, $userID) {
assert(is_numeric($memberID));
assert(is_numeric($userID));
global $database; global $database;
$database->execute( $database->execute(
"UPDATE artist_members SET name = ?, updated = now(), user_id = ? WHERE id = ?", "UPDATE artist_members SET name = ?, updated = now(), user_id = ? WHERE id = ?",
@ -826,12 +707,7 @@ class Artists extends Extension {
return $artistID; return $artistID;
} }
/** private function save_new_artist(string $name, string $notes): int {
* @param string $name
* @param string $notes
* @return int
*/
private function save_new_artist($name, $notes) {
global $database, $user; global $database, $user;
$database->execute(" $database->execute("
INSERT INTO artists (user_id, name, notes, created, updated) INSERT INTO artists (user_id, name, notes, created, updated)
@ -840,11 +716,7 @@ class Artists extends Extension {
return $database->get_last_insert_id('artists_id_seq'); return $database->get_last_insert_id('artists_id_seq');
} }
/** private function artist_exists(string $name): bool {
* @param string $name
* @return bool
*/
private function artist_exists($name) {
global $database; global $database;
$result = $database->get_one( $result = $database->get_one(
"SELECT COUNT(1) FROM artists WHERE name = ?", "SELECT COUNT(1) FROM artists WHERE name = ?",
@ -853,13 +725,7 @@ class Artists extends Extension {
return ($result != 0); return ($result != 0);
} }
/** private function get_artist(int $artistID): array {
* @param int $artistID
* @return array
*/
private function get_artist($artistID){
assert(is_numeric($artistID));
global $database; global $database;
$result = $database->get_row( $result = $database->get_row(
"SELECT * FROM artists WHERE id = ?", "SELECT * FROM artists WHERE id = ?",
@ -872,13 +738,7 @@ class Artists extends Extension {
return $result; return $result;
} }
/** private function get_members(int $artistID): array {
* @param int $artistID
* @return array
*/
private function get_members($artistID) {
assert(is_numeric($artistID));
global $database; global $database;
$result = $database->get_all( $result = $database->get_all(
"SELECT * FROM artist_members WHERE artist_id = ?", "SELECT * FROM artist_members WHERE artist_id = ?",
@ -893,13 +753,7 @@ class Artists extends Extension {
return $result; return $result;
} }
/** private function get_urls(int $artistID): array {
* @param int $artistID
* @return array
*/
private function get_urls($artistID) {
assert(is_numeric($artistID));
global $database; global $database;
$result = $database->get_all( $result = $database->get_all(
"SELECT id, url FROM artist_urls WHERE artist_id = ?", "SELECT id, url FROM artist_urls WHERE artist_id = ?",
@ -914,11 +768,7 @@ class Artists extends Extension {
return $result; return $result;
} }
/** private function get_artist_id(string $name): int {
* @param string $name
* @return int
*/
private function get_artist_id($name) {
global $database; global $database;
return (int)$database->get_one( return (int)$database->get_one(
"SELECT id FROM artists WHERE name = ?", "SELECT id FROM artists WHERE name = ?",
@ -926,11 +776,7 @@ class Artists extends Extension {
); );
} }
/** private function get_artistID_by_aliasName(string $alias): int {
* @param string $alias
* @return int
*/
private function get_artistID_by_aliasName($alias) {
global $database; global $database;
return (int)$database->get_one( return (int)$database->get_one(
@ -939,13 +785,7 @@ class Artists extends Extension {
); );
} }
private function delete_artist(int $artistID) {
/**
* @param int $artistID
*/
private function delete_artist($artistID) {
assert(is_numeric($artistID));
global $database; global $database;
$database->execute( $database->execute(
"DELETE FROM artists WHERE id = ? ", "DELETE FROM artists WHERE id = ? ",
@ -1055,17 +895,9 @@ class Artists extends Extension {
$this->save_new_url($artistID, $url, $user->id); $this->save_new_url($artistID, $url, $user->id);
} }
/** private function save_new_url(int $artistID, string $url, int $userID) {
* @param int $artistID
* @param string $url
* @param int $userID
*/
private function save_new_url($artistID, $url, $userID) {
global $database; global $database;
assert(is_numeric($artistID));
assert(is_numeric($userID));
$database->execute( $database->execute(
"INSERT INTO artist_urls (artist_id, created, updated, url, user_id) VALUES (?, now(), now(), ?, ?)", "INSERT INTO artist_urls (artist_id, created, updated, url, user_id) VALUES (?, now(), now(), ?, ?)",
array($artistID, $url, $userID) array($artistID, $url, $userID)
@ -1086,17 +918,9 @@ class Artists extends Extension {
$this->save_new_alias($artistID, $alias, $user->id); $this->save_new_alias($artistID, $alias, $user->id);
} }
/** private function save_new_alias(int $artistID, string $alias, int $userID) {
* @param int $artistID
* @param string $alias
* @param int $userID
*/
private function save_new_alias($artistID, $alias, $userID) {
global $database; global $database;
assert(is_numeric($artistID));
assert(is_numeric($userID));
$database->execute( $database->execute(
"INSERT INTO artist_alias (artist_id, created, updated, alias, user_id) VALUES (?, now(), now(), ?, ?)", "INSERT INTO artist_alias (artist_id, created, updated, alias, user_id) VALUES (?, now(), now(), ?, ?)",
array($artistID, $alias, $userID) array($artistID, $alias, $userID)
@ -1117,33 +941,18 @@ class Artists extends Extension {
$this->save_new_member($artistID, $member, $user->id); $this->save_new_member($artistID, $member, $user->id);
} }
/** private function save_new_member(int $artistID, string $member, int $userID) {
* @param int $artistID
* @param string $member
* @param int $userID
*/
private function save_new_member($artistID, $member, $userID) {
global $database; global $database;
assert(is_numeric($artistID));
assert(is_numeric($userID));
$database->execute( $database->execute(
"INSERT INTO artist_members (artist_id, name, created, updated, user_id) VALUES (?, ?, now(), now(), ?)", "INSERT INTO artist_members (artist_id, name, created, updated, user_id) VALUES (?, ?, now(), now(), ?)",
array($artistID, $member, $userID) array($artistID, $member, $userID)
); );
} }
/** private function member_exists(int $artistID, string $member): bool {
* @param int $artistID
* @param string $member
* @return bool
*/
private function member_exists($artistID, $member) {
global $database; global $database;
assert(is_numeric($artistID));
$result = $database->get_one( $result = $database->get_one(
"SELECT COUNT(1) FROM artist_members WHERE artist_id = ? AND name = ?", "SELECT COUNT(1) FROM artist_members WHERE artist_id = ? AND name = ?",
array($artistID, $member) array($artistID, $member)
@ -1151,16 +960,9 @@ class Artists extends Extension {
return ($result != 0); return ($result != 0);
} }
/** private function url_exists(int $artistID, string $url): bool {
* @param int $artistID
* @param string $url
* @return bool
*/
private function url_exists($artistID, $url) {
global $database; global $database;
assert(is_numeric($artistID));
$result = $database->get_one( $result = $database->get_one(
"SELECT COUNT(1) FROM artist_urls WHERE artist_id = ? AND url = ?", "SELECT COUNT(1) FROM artist_urls WHERE artist_id = ? AND url = ?",
array($artistID, $url) array($artistID, $url)
@ -1170,15 +972,10 @@ class Artists extends Extension {
/** /**
* HERE WE GET THE INFO OF THE ALIAS * HERE WE GET THE INFO OF THE ALIAS
*
* @param int $artistID
* @return array
*/ */
private function get_alias($artistID) { private function get_alias(int $artistID): array {
global $database; global $database;
assert(is_numeric($artistID));
$result = $database->get_all(" $result = $database->get_all("
SELECT id AS alias_id, alias AS alias_name SELECT id AS alias_id, alias AS alias_name
FROM artist_alias FROM artist_alias

View file

@ -5,7 +5,7 @@ class ArtistsTheme extends Themelet {
* @param string $author * @param string $author
* @return string * @return string
*/ */
public function get_author_editor_html(/*string*/ $author) { public function get_author_editor_html(string $author) {
$h_author = html_escape($author); $h_author = html_escape($author);
return " return "
<tr> <tr>
@ -23,7 +23,7 @@ class ArtistsTheme extends Themelet {
* @param null|int $artistID * @param null|int $artistID
* @param bool $is_admin * @param bool $is_admin
*/ */
public function sidebar_options(/*string*/ $mode, $artistID=NULL, $is_admin=FALSE) { public function sidebar_options(string $mode, $artistID=NULL, $is_admin=FALSE) {
global $page, $user; global $page, $user;
$html = ""; $html = "";

View file

@ -6,7 +6,7 @@
*/ */
class AutoComplete extends Extension { class AutoComplete extends Extension {
public function get_priority() {return 30;} // before Home public function get_priority(): int {return 30;} // before Home
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $page, $database; global $page, $database;

View file

@ -111,10 +111,7 @@ xanax
} }
} }
/** private function get_words(): array {
* @return string[]
*/
private function get_words() {
global $config; global $config;
$words = array(); $words = array();
@ -131,6 +128,6 @@ xanax
return $words; return $words;
} }
public function get_priority() {return 30;} public function get_priority(): int {return 30;}
} }

View file

@ -26,11 +26,7 @@
*/ */
class BBCode extends FormatterExtension { class BBCode extends FormatterExtension {
/** public function format(string $text): string {
* @param string $text
* @return string
*/
public function format(/*string*/ $text) {
$text = $this->extract_code($text); $text = $this->extract_code($text);
foreach(array( foreach(array(
"b", "i", "u", "s", "sup", "sub", "h1", "h2", "h3", "h4", "b", "i", "u", "s", "sup", "sub", "h1", "h2", "h3", "h4",
@ -67,11 +63,7 @@ class BBCode extends FormatterExtension {
return $text; return $text;
} }
/** public function strip(string $text): string {
* @param string $text
* @return string
*/
public function strip(/*string*/ $text) {
foreach(array( foreach(array(
"b", "i", "u", "s", "sup", "sub", "h1", "h2", "h3", "h4", "b", "i", "u", "s", "sup", "sub", "h1", "h2", "h3", "h4",
"code", "url", "email", "li", "code", "url", "email", "li",
@ -91,22 +83,14 @@ class BBCode extends FormatterExtension {
return $text; return $text;
} }
/** private function filter_spoiler(string $text): string {
* @param string $text
* @return string
*/
private function filter_spoiler(/*string*/ $text) {
return str_replace( return str_replace(
array("[spoiler]","[/spoiler]"), array("[spoiler]","[/spoiler]"),
array("<span style=\"background-color:#000; color:#000;\">","</span>"), array("<span style=\"background-color:#000; color:#000;\">","</span>"),
$text); $text);
} }
/** private function strip_spoiler(string $text): string {
* @param string $text
* @return string
*/
private function strip_spoiler(/*string*/ $text) {
$l1 = strlen("[spoiler]"); $l1 = strlen("[spoiler]");
$l2 = strlen("[/spoiler]"); $l2 = strlen("[/spoiler]");
while(true) { while(true) {
@ -127,11 +111,7 @@ class BBCode extends FormatterExtension {
return $text; return $text;
} }
/** private function extract_code(string $text): string {
* @param string $text
* @return string
*/
private function extract_code(/*string*/ $text) {
# at the end of this function, the only code! blocks should be # at the end of this function, the only code! blocks should be
# the ones we've added -- others may contain malicious content, # the ones we've added -- others may contain malicious content,
# which would only appear after decoding # which would only appear after decoding
@ -158,11 +138,7 @@ class BBCode extends FormatterExtension {
return $text; return $text;
} }
/** private function insert_code(string $text): string {
* @param string $text
* @return string
*/
private function insert_code(/*string*/ $text) {
$l1 = strlen("[code!]"); $l1 = strlen("[code!]");
$l2 = strlen("[/code!]"); $l2 = strlen("[/code!]");
while(true) { while(true) {
@ -181,4 +157,3 @@ class BBCode extends FormatterExtension {
return $text; return $text;
} }
} }

View file

@ -18,7 +18,7 @@
class BulkAddEvent extends Event { class BulkAddEvent extends Event {
public $dir, $results; public $dir, $results;
public function __construct($dir) { public function __construct(string $dir) {
$this->dir = $dir; $this->dir = $dir;
$this->results = array(); $this->results = array();
} }

View file

@ -90,7 +90,7 @@ class BulkAddCSV extends Extension {
} }
} }
private function add_csv(/*string*/ $csvfile) { private function add_csv(string $csvfile) {
if(!file_exists($csvfile)) { if(!file_exists($csvfile)) {
$this->theme->add_status("Error", "$csvfile not found"); $this->theme->add_status("Error", "$csvfile not found");
return; return;

View file

@ -19,13 +19,7 @@ class CommentPostingEvent extends Event {
/** @var string */ /** @var string */
public $comment; public $comment;
/** public function __construct(int $image_id, User $user, string $comment) {
* @param int $image_id
* @param \User $user
* @param string $comment
*/
public function __construct($image_id, $user, $comment) {
assert('is_numeric($image_id)');
$this->image_id = $image_id; $this->image_id = $image_id;
$this->user = $user; $this->user = $user;
$this->comment = $comment; $this->comment = $comment;
@ -41,11 +35,7 @@ class CommentDeletionEvent extends Event {
/** @var int */ /** @var int */
public $comment_id; public $comment_id;
/** public function __construct(int $comment_id) {
* @param int $comment_id
*/
public function __construct($comment_id) {
assert('is_numeric($comment_id)');
$this->comment_id = $comment_id; $this->comment_id = $comment_id;
} }
} }
@ -339,7 +329,7 @@ class CommentList extends Extension {
/** /**
* @param int $current_page * @param int $current_page
*/ */
private function build_page(/*int*/ $current_page) { private function build_page(int $current_page) {
global $database, $user; global $database, $user;
$where = SPEED_HAX ? "WHERE posted > now() - interval '24 hours'" : ""; $where = SPEED_HAX ? "WHERE posted > now() - interval '24 hours'" : "";
@ -429,7 +419,7 @@ class CommentList extends Extension {
* @param int $offset * @param int $offset
* @return Comment[] * @return Comment[]
*/ */
private function get_user_comments(/*int*/ $user_id, /*int*/ $count, /*int*/ $offset=0) { private function get_user_comments(int $user_id, int $count, int $offset=0) {
return $this->get_generic_comments(" return $this->get_generic_comments("
SELECT SELECT
users.id as user_id, users.name as user_name, users.email as user_email, users.class as user_class, users.id as user_id, users.name as user_name, users.email as user_email, users.class as user_class,
@ -448,7 +438,7 @@ class CommentList extends Extension {
* @param int $image_id * @param int $image_id
* @return Comment[] * @return Comment[]
*/ */
private function get_comments(/*int*/ $image_id) { private function get_comments(int $image_id) {
return $this->get_generic_comments(" return $this->get_generic_comments("
SELECT SELECT
users.id as user_id, users.name as user_name, users.email as user_email, users.class as user_class, users.id as user_id, users.name as user_name, users.email as user_email, users.class as user_class,
@ -513,7 +503,7 @@ class CommentList extends Extension {
* @param string $text * @param string $text
* @return bool * @return bool
*/ */
private function is_spam_akismet(/*string*/ $text) { private function is_spam_akismet(string $text) {
global $config, $user; global $config, $user;
if(strlen($config->get_string('comment_wordpress_key')) > 0) { if(strlen($config->get_string('comment_wordpress_key')) > 0) {
$comment = array( $comment = array(
@ -556,7 +546,7 @@ class CommentList extends Extension {
* @param int $comment * @param int $comment
* @return null * @return null
*/ */
private function is_dupe(/*int*/ $image_id, /*string*/ $comment) { private function is_dupe(int $image_id, string $comment) {
global $database; global $database;
return $database->get_row(" return $database->get_row("
SELECT * SELECT *
@ -572,7 +562,7 @@ class CommentList extends Extension {
* @param string $comment * @param string $comment
* @throws CommentPostingException * @throws CommentPostingException
*/ */
private function add_comment_wrapper(/*int*/ $image_id, User $user, /*string*/ $comment) { private function add_comment_wrapper(int $image_id, User $user, string $comment) {
global $database, $page; global $database, $page;
if(!$user->can("bypass_comment_checks")) { if(!$user->can("bypass_comment_checks")) {
@ -601,7 +591,7 @@ class CommentList extends Extension {
* @param string $comment * @param string $comment
* @throws CommentPostingException * @throws CommentPostingException
*/ */
private function comment_checks(/*int*/ $image_id, User $user, /*string*/ $comment) { private function comment_checks(int $image_id, User $user, string $comment) {
global $config, $page; global $config, $page;
// basic sanity checks // basic sanity checks

View file

@ -303,7 +303,7 @@ class CommentListTheme extends Themelet {
* @param int $image_id * @param int $image_id
* @return string * @return string
*/ */
protected function build_postbox(/*int*/ $image_id) { protected function build_postbox(int $image_id) {
global $config; global $config;
$i_image_id = int_escape($image_id); $i_image_id = int_escape($image_id);

View file

@ -13,7 +13,7 @@
*/ */
class Downtime extends Extension { class Downtime extends Extension {
public function get_priority() {return 10;} public function get_priority(): int {return 10;}
public function onSetupBuilding(SetupBuildingEvent $event) { public function onSetupBuilding(SetupBuildingEvent $event) {
$sb = new SetupBlock("Downtime"); $sb = new SetupBlock("Downtime");

View file

@ -16,7 +16,7 @@ class DowntimeTheme extends Themelet {
* *
* @param string $message * @param string $message
*/ */
public function display_message(/*string*/ $message) { public function display_message(string $message) {
global $config, $user, $page; global $config, $user, $page;
$theme_name = $config->get_string('theme'); $theme_name = $config->get_string('theme');
$data_href = get_base_href(); $data_href = get_base_href();

View file

@ -17,21 +17,13 @@
* Class Emoticons * Class Emoticons
*/ */
class Emoticons extends FormatterExtension { class Emoticons extends FormatterExtension {
/** public function format(string $text): string {
* @param string $text
* @return string
*/
public function format(/*string*/ $text) {
$data_href = get_base_href(); $data_href = get_base_href();
$text = preg_replace("/:([a-z]*?):/s", "<img src='$data_href/ext/emoticons/default/\\1.gif'>", $text); $text = preg_replace("/:([a-z]*?):/s", "<img src='$data_href/ext/emoticons/default/\\1.gif'>", $text);
return $text; return $text;
} }
/** public function strip(string $text): string {
* @param string $text
* @return string
*/
public function strip(/*string*/ $text) {
return $text; return $text;
} }
} }

View file

@ -3,7 +3,7 @@ class EmoticonListTheme extends Themelet {
/** /**
* @param array $list * @param array $list
*/ */
public function display_emotes(/*array*/ $list) { public function display_emotes(array $list) {
global $page; global $page;
$data_href = get_base_href(); $data_href = get_base_href();
$html = "<html><head><title>Emoticon list</title></head><body>"; $html = "<html><head><title>Emoticon list</title></head><body>";

View file

@ -87,7 +87,7 @@ class ExtensionInfo {
* @param string $fname * @param string $fname
* @return bool|null * @return bool|null
*/ */
private function is_enabled(/*string*/ $fname) { private function is_enabled(string $fname) {
$core = explode(",", CORE_EXTS); $core = explode(",", CORE_EXTS);
$extra = explode(",", EXTRA_EXTS); $extra = explode(",", EXTRA_EXTS);
@ -160,7 +160,7 @@ class ExtManager extends Extension {
* @param bool $all * @param bool $all
* @return ExtensionInfo[] * @return ExtensionInfo[]
*/ */
private function get_extensions(/*bool*/ $all) { private function get_extensions(bool $all) {
$extensions = array(); $extensions = array();
if($all) { if($all) {
$exts = zglob("ext/*/main.php"); $exts = zglob("ext/*/main.php");

View file

@ -6,7 +6,7 @@ class ExtManagerTheme extends Themelet {
* @param ExtensionInfo[] $extensions * @param ExtensionInfo[] $extensions
* @param bool $editable * @param bool $editable
*/ */
public function display_table(Page $page, /*array*/ $extensions, /*bool*/ $editable) { public function display_table(Page $page, array $extensions, bool $editable) {
$h_en = $editable ? "<th>Enabled</th>" : ""; $h_en = $editable ? "<th>Enabled</th>" : "";
$html = " $html = "
".make_form(make_link("ext_manager/set"))." ".make_form(make_link("ext_manager/set"))."

View file

@ -21,12 +21,7 @@ class FavoriteSetEvent extends Event {
/** @var bool */ /** @var bool */
public $do_set; public $do_set;
/** public function __construct(int $image_id, User $user, bool $do_set) {
* @param int $image_id
* @param User $user
* @param bool $do_set
*/
public function __construct(/*int*/ $image_id, User $user, /*boolean*/ $do_set) {
assert(is_int($image_id)); assert(is_int($image_id));
assert(is_bool($do_set)); assert(is_bool($do_set));
@ -181,12 +176,7 @@ class Favorites extends Extension {
} }
} }
/** private function add_vote(int $image_id, int $user_id, bool $do_set) {
* @param int $image_id
* @param int $user_id
* @param bool $do_set
*/
private function add_vote(/*int*/ $image_id, /*int*/ $user_id, /*bool*/ $do_set) {
global $database; global $database;
if ($do_set) { if ($do_set) {
$database->Execute( $database->Execute(
@ -206,7 +196,7 @@ class Favorites extends Extension {
* @param Image $image * @param Image $image
* @return string[] * @return string[]
*/ */
private function list_persons_who_have_favorited(Image $image) { private function list_persons_who_have_favorited(Image $image): array {
global $database; global $database;
return $database->get_col( return $database->get_col(

View file

@ -50,7 +50,7 @@ class Featured extends Extension {
if($event->get_arg(0) == "view") { if($event->get_arg(0) == "view") {
$image = Image::by_id($config->get_int("featured_id")); $image = Image::by_id($config->get_int("featured_id"));
if(!is_null($image)) { if(!is_null($image)) {
send_event(new DisplayingImageEvent($image, $page)); send_event(new DisplayingImageEvent($image));
} }
} }
} }

View file

@ -15,7 +15,7 @@ class FeaturedTheme extends Themelet {
* @param int $image_id * @param int $image_id
* @return string * @return string
*/ */
public function get_buttons_html(/*int*/ $image_id) { public function get_buttons_html(int $image_id) {
global $user; global $user;
return " return "
".make_form(make_link("featured_image/set"))." ".make_form(make_link("featured_image/set"))."

View file

@ -179,10 +179,7 @@ class Forum extends Extension {
} }
} }
/** private function get_total_pages_for_thread(int $threadID)
* @param int $threadID
*/
private function get_total_pages_for_thread($threadID)
{ {
global $database, $config; global $database, $config;
$result = $database->get_row("SELECT COUNT(1) AS count FROM forum_posts WHERE thread_id = ?", array($threadID)); $result = $database->get_row("SELECT COUNT(1) AS count FROM forum_posts WHERE thread_id = ?", array($threadID));
@ -243,10 +240,7 @@ class Forum extends Extension {
return array($errors); return array($errors);
} }
/** private function sanity_check_viewed_thread(int $threadID)
* @param int $threadID
*/
private function sanity_check_viewed_thread($threadID)
{ {
$errors = null; $errors = null;
if (!$this->threadExists($threadID)) if (!$this->threadExists($threadID))
@ -256,10 +250,7 @@ class Forum extends Extension {
return array($errors); return array($errors);
} }
/** private function get_thread_title(int $threadID)
* @param int $threadID
*/
private function get_thread_title($threadID)
{ {
global $database; global $database;
$result = $database->get_row("SELECT t.title FROM forum_threads AS t WHERE t.id = ? ", array($threadID)); $result = $database->get_row("SELECT t.title FROM forum_threads AS t WHERE t.id = ? ", array($threadID));
@ -352,10 +343,7 @@ class Forum extends Extension {
return $threadID; return $threadID;
} }
/** private function save_new_post(int $threadID, User $user)
* @param int $threadID
*/
private function save_new_post($threadID, User $user)
{ {
global $config; global $config;
$userID = $user->id; $userID = $user->id;
@ -378,11 +366,7 @@ class Forum extends Extension {
$database->execute("UPDATE forum_threads SET uptodate=now() WHERE id=?", array ($threadID)); $database->execute("UPDATE forum_threads SET uptodate=now() WHERE id=?", array ($threadID));
} }
/** private function retrieve_posts(int $threadID, int $pageNumber)
* @param int $threadID
* @param int $pageNumber
*/
private function retrieve_posts($threadID, $pageNumber)
{ {
global $database, $config; global $database, $config;
$postsPerPage = $config->get_int('forumPostsPerPage', 15); $postsPerPage = $config->get_int('forumPostsPerPage', 15);
@ -398,29 +382,20 @@ class Forum extends Extension {
, array("thread_id"=>$threadID, "offset"=>($pageNumber - 1) * $postsPerPage, "limit"=>$postsPerPage)); , array("thread_id"=>$threadID, "offset"=>($pageNumber - 1) * $postsPerPage, "limit"=>$postsPerPage));
} }
/** private function delete_thread(int $threadID)
* @param int $threadID
*/
private function delete_thread($threadID)
{ {
global $database; global $database;
$database->execute("DELETE FROM forum_threads WHERE id = ?", array($threadID)); $database->execute("DELETE FROM forum_threads WHERE id = ?", array($threadID));
$database->execute("DELETE FROM forum_posts WHERE thread_id = ?", array($threadID)); $database->execute("DELETE FROM forum_posts WHERE thread_id = ?", array($threadID));
} }
/** private function delete_post(int $postID)
* @param int $postID
*/
private function delete_post($postID)
{ {
global $database; global $database;
$database->execute("DELETE FROM forum_posts WHERE id = ?", array($postID)); $database->execute("DELETE FROM forum_posts WHERE id = ?", array($postID));
} }
/** private function threadExists(int $threadID)
* @param int $threadID
*/
private function threadExists($threadID)
{ {
global $database; global $database;
$result=$database->get_one("SELECT EXISTS (SELECT * FROM forum_threads WHERE id= ?)", array($threadID)); $result=$database->get_one("SELECT EXISTS (SELECT * FROM forum_threads WHERE id= ?)", array($threadID));

View file

@ -48,6 +48,6 @@ class Handle404 extends Extension {
return $n; return $n;
} }
public function get_priority() {return 99;} public function get_priority(): int {return 99;}
} }

View file

@ -45,10 +45,6 @@ class ArchiveFileHandler extends Extension {
} }
} }
/**
* @param string $ext
* @return bool
*/
private function supported_ext($ext) { private function supported_ext($ext) {
$exts = array("zip"); $exts = array("zip");
return in_array(strtolower($ext), $exts); return in_array(strtolower($ext), $exts);

View file

@ -7,30 +7,17 @@
*/ */
class FlashFileHandler extends DataHandlerExtension { class FlashFileHandler extends DataHandlerExtension {
/** protected function create_thumb(string $hash): bool {
* @param string $hash
* @return bool
*/
protected function create_thumb($hash) {
copy("ext/handle_flash/thumb.jpg", warehouse_path("thumbs", $hash)); copy("ext/handle_flash/thumb.jpg", warehouse_path("thumbs", $hash));
return true; return true;
} }
/** protected function supported_ext(string $ext): bool {
* @param string $ext
* @return bool
*/
protected function supported_ext($ext) {
$exts = array("swf"); $exts = array("swf");
return in_array(strtolower($ext), $exts); return in_array(strtolower($ext), $exts);
} }
/** protected function create_image_from_data(string $filename, array $metadata) {
* @param string $filename
* @param array $metadata
* @return Image|null
*/
protected function create_image_from_data(/*string*/ $filename, /*array*/ $metadata) {
$image = new Image(); $image = new Image();
$image->filesize = $metadata['size']; $image->filesize = $metadata['size'];
@ -49,14 +36,10 @@ class FlashFileHandler extends DataHandlerExtension {
return $image; return $image;
} }
/** protected function check_contents(string $tmpname): bool {
* @param string $file if (!file_exists($tmpname)) return false;
* @return bool
*/
protected function check_contents(/*string*/ $file) {
if (!file_exists($file)) return false;
$fp = fopen($file, "r"); $fp = fopen($tmpname, "r");
$head = fread($fp, 3); $head = fread($fp, 3);
fclose($fp); fclose($fp);
if (!in_array($head, array("CWS", "FWS"))) return false; if (!in_array($head, array("CWS", "FWS"))) return false;

View file

@ -35,21 +35,12 @@ class IcoFileHandler extends Extension {
} }
} }
/** private function supported_ext(string $ext): bool {
* @param string $ext
* @return bool
*/
private function supported_ext($ext) {
$exts = array("ico", "ani", "cur"); $exts = array("ico", "ani", "cur");
return in_array(strtolower($ext), $exts); return in_array(strtolower($ext), $exts);
} }
/** private function create_image_from_data(string $filename, array $metadata) {
* @param string $filename
* @param mixed[] $metadata
* @return Image
*/
private function create_image_from_data($filename, $metadata) {
$image = new Image(); $image = new Image();
$fp = fopen($filename, "r"); $fp = fopen($filename, "r");
@ -73,11 +64,7 @@ class IcoFileHandler extends Extension {
return $image; return $image;
} }
/** private function check_contents(string $file): bool {
* @param string $file
* @return bool
*/
private function check_contents($file) {
if(!file_exists($file)) return false; if(!file_exists($file)) return false;
$fp = fopen($file, "r"); $fp = fopen($file, "r");
$header = unpack("Snull/Stype/Scount", fread($fp, 6)); $header = unpack("Snull/Stype/Scount", fread($fp, 6));
@ -85,11 +72,7 @@ class IcoFileHandler extends Extension {
return ($header['null'] == 0 && ($header['type'] == 0 || $header['type'] == 1)); return ($header['null'] == 0 && ($header['type'] == 0 || $header['type'] == 1));
} }
/** private function create_thumb(string $hash): bool {
* @param string $hash
* @return bool
*/
private function create_thumb($hash) {
global $config; global $config;
$inname = warehouse_path("images", $hash); $inname = warehouse_path("images", $hash);

View file

@ -6,30 +6,17 @@
*/ */
class MP3FileHandler extends DataHandlerExtension { class MP3FileHandler extends DataHandlerExtension {
/** protected function create_thumb(string $hash): bool {
* @param string $hash
* @return bool
*/
protected function create_thumb($hash) {
copy("ext/handle_mp3/thumb.jpg", warehouse_path("thumbs", $hash)); copy("ext/handle_mp3/thumb.jpg", warehouse_path("thumbs", $hash));
return true; return true;
} }
/** protected function supported_ext(string $ext): bool {
* @param string $ext
* @return bool
*/
protected function supported_ext($ext) {
$exts = array("mp3"); $exts = array("mp3");
return in_array(strtolower($ext), $exts); return in_array(strtolower($ext), $exts);
} }
/** protected function create_image_from_data(string $filename, array $metadata) {
* @param string $filename
* @param mixed[] $metadata
* @return Image|null
*/
protected function create_image_from_data($filename, $metadata) {
$image = new Image(); $image = new Image();
//NOTE: No need to set width/height as we don't use it. //NOTE: No need to set width/height as we don't use it.
@ -49,15 +36,11 @@ class MP3FileHandler extends DataHandlerExtension {
return $image; return $image;
} }
/** protected function check_contents(string $tmpname): bool {
* @param $file
* @return bool
*/
protected function check_contents($file) {
$success = FALSE; $success = FALSE;
if (file_exists($file)) { if (file_exists($tmpname)) {
$mimeType = mime_content_type($file); $mimeType = mime_content_type($tmpname);
$success = ($mimeType == 'audio/mpeg'); $success = ($mimeType == 'audio/mpeg');
} }
@ -65,4 +48,3 @@ class MP3FileHandler extends DataHandlerExtension {
return $success; return $success;
} }
} }

View file

@ -7,22 +7,13 @@
*/ */
class PixelFileHandler extends DataHandlerExtension { class PixelFileHandler extends DataHandlerExtension {
/** protected function supported_ext(string $ext): bool {
* @param string $ext
* @return bool
*/
protected function supported_ext($ext) {
$exts = array("jpg", "jpeg", "gif", "png"); $exts = array("jpg", "jpeg", "gif", "png");
$ext = (($pos = strpos($ext,'?')) !== false) ? substr($ext,0,$pos) : $ext; $ext = (($pos = strpos($ext,'?')) !== false) ? substr($ext,0,$pos) : $ext;
return in_array(strtolower($ext), $exts); return in_array(strtolower($ext), $exts);
} }
/** protected function create_image_from_data(string $filename, array $metadata) {
* @param string $filename
* @param array $metadata
* @return Image|null
*/
protected function create_image_from_data(/*string*/ $filename, /*array*/ $metadata) {
$image = new Image(); $image = new Image();
$info = getimagesize($filename); $info = getimagesize($filename);
@ -41,24 +32,16 @@ class PixelFileHandler extends DataHandlerExtension {
return $image; return $image;
} }
/** protected function check_contents(string $tmpname): bool {
* @param string $file
* @return bool
*/
protected function check_contents(/*string*/ $file) {
$valid = Array(IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG); $valid = Array(IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG);
if(!file_exists($file)) return false; if(!file_exists($tmpname)) return false;
$info = getimagesize($file); $info = getimagesize($tmpname);
if(is_null($info)) return false; if(is_null($info)) return false;
if(in_array($info[2], $valid)) return true; if(in_array($info[2], $valid)) return true;
return false; return false;
} }
/** protected function create_thumb(string $hash): bool {
* @param string $hash
* @return bool
*/
protected function create_thumb(/*string*/ $hash) {
$outname = warehouse_path("thumbs", $hash); $outname = warehouse_path("thumbs", $hash);
if(file_exists($outname)) { if(file_exists($outname)) {
return true; return true;
@ -66,11 +49,7 @@ class PixelFileHandler extends DataHandlerExtension {
return $this->create_thumb_force($hash); return $this->create_thumb_force($hash);
} }
/** protected function create_thumb_force(string $hash): bool {
* @param string $hash
* @return bool
*/
protected function create_thumb_force(/*string*/ $hash) {
global $config; global $config;
$inname = warehouse_path("images", $hash); $inname = warehouse_path("images", $hash);
@ -114,13 +93,7 @@ class PixelFileHandler extends DataHandlerExtension {
} }
// IM thumber {{{ // IM thumber {{{
private function make_thumb_convert(string $inname, string $outname): bool {
/**
* @param string $inname
* @param string $outname
* @return bool
*/
private function make_thumb_convert(/*string*/ $inname, /*string*/ $outname) {
global $config; global $config;
$w = $config->get_int("thumb_width"); $w = $config->get_int("thumb_width");
@ -153,12 +126,7 @@ class PixelFileHandler extends DataHandlerExtension {
} }
// }}} // }}}
// epeg thumber {{{ // epeg thumber {{{
/** private function make_thumb_epeg(string $inname, string $outname): bool {
* @param string $inname
* @param string $outname
* @return bool
*/
private function make_thumb_epeg(/*string*/ $inname, /*string*/ $outname) {
global $config; global $config;
$w = $config->get_int("thumb_width"); $w = $config->get_int("thumb_width");
exec("epeg $inname -c 'Created by EPEG' --max $w $outname"); exec("epeg $inname -c 'Created by EPEG' --max $w $outname");
@ -166,12 +134,7 @@ class PixelFileHandler extends DataHandlerExtension {
} }
// }}} // }}}
// GD thumber {{{ // GD thumber {{{
/** private function make_thumb_gd(string $inname, string $outname): bool {
* @param string $inname
* @param string $outname
* @return bool
*/
private function make_thumb_gd(/*string*/ $inname, /*string*/ $outname) {
global $config; global $config;
$thumb = $this->get_thumb($inname); $thumb = $this->get_thumb($inname);
$ok = imagejpeg($thumb, $outname, $config->get_int('thumb_quality')); $ok = imagejpeg($thumb, $outname, $config->get_int('thumb_quality'));
@ -179,11 +142,7 @@ class PixelFileHandler extends DataHandlerExtension {
return $ok; return $ok;
} }
/** private function get_thumb(string $tmpname) {
* @param string $tmpname
* @return resource
*/
private function get_thumb(/*string*/ $tmpname) {
global $config; global $config;
$info = getimagesize($tmpname); $info = getimagesize($tmpname);
@ -220,4 +179,3 @@ class PixelFileHandler extends DataHandlerExtension {
} }
// }}} // }}}
} }

View file

@ -82,7 +82,7 @@ class VideoFileHandler extends DataHandlerExtension {
* @param string $hash * @param string $hash
* @return bool Returns true on successful thumbnail creation. * @return bool Returns true on successful thumbnail creation.
*/ */
protected function create_thumb($hash) { protected function create_thumb(string $hash): bool {
global $config; global $config;
$ok = false; $ok = false;
@ -132,7 +132,7 @@ class VideoFileHandler extends DataHandlerExtension {
* @param string $ext * @param string $ext
* @return bool * @return bool
*/ */
protected function supported_ext($ext) { protected function supported_ext(string $ext): bool {
$exts = array("flv", "mp4", "m4v", "ogv", "webm"); $exts = array("flv", "mp4", "m4v", "ogv", "webm");
return in_array(strtolower($ext), $exts); return in_array(strtolower($ext), $exts);
} }
@ -142,7 +142,7 @@ class VideoFileHandler extends DataHandlerExtension {
* @param mixed[] $metadata * @param mixed[] $metadata
* @return Image * @return Image
*/ */
protected function create_image_from_data($filename, $metadata) { protected function create_image_from_data(string $filename, array $metadata) {
$image = new Image(); $image = new Image();
//NOTE: No need to set width/height as we don't use it. //NOTE: No need to set width/height as we don't use it.
@ -177,13 +177,13 @@ class VideoFileHandler extends DataHandlerExtension {
} }
/** /**
* @param string $file * @param string $tmpname
* @return bool * @return bool
*/ */
protected function check_contents($file) { protected function check_contents(string $tmpname): bool {
$success = FALSE; $success = FALSE;
if (file_exists($file)) { if (file_exists($tmpname)) {
$mimeType = mime_content_type($file); $mimeType = mime_content_type($tmpname);
$success = in_array($mimeType, [ $success = in_array($mimeType, [
'video/webm', 'video/webm',

View file

@ -49,7 +49,7 @@ class Home extends Extension {
global $config; global $config;
$base_href = get_base_href(); $base_href = get_base_href();
$sitename = $config->get_string('title'); $sitename = $config->get_string('title');
$contact_link = contact_link(); $contact_link = contact_link() || "";
$counter_dir = $config->get_string('home_counter', 'default'); $counter_dir = $config->get_string('home_counter', 'default');
$total = Image::count_images(); $total = Image::count_images();
@ -74,7 +74,7 @@ class Home extends Extension {
$main_links .= ' [url=site://ext_doc]Documentation[/url]'; $main_links .= ' [url=site://ext_doc]Documentation[/url]';
} }
$main_links = format_text($main_links); $main_links = format_text($main_links);
$main_text = $config->get_string('home_text'); $main_text = $config->get_string('home_text', '');
return $this->theme->build_body($sitename, $main_links, $main_text, $contact_link, $num_comma, $counter_text); return $this->theme->build_body($sitename, $main_links, $main_text, $contact_link, $num_comma, $counter_text);
} }

View file

@ -22,7 +22,7 @@ EOD
); );
} }
public function build_body(/*string*/ $sitename, /*string*/ $main_links, /*string*/ $main_text, /*string*/ $contact_link, $num_comma, /*string*/ $counter_text) { public function build_body(string $sitename, string $main_links, string $main_text, string $contact_link, $num_comma, string $counter_text) {
$main_links_html = empty($main_links) ? "" : "<div class='space' id='links'>$main_links</div>"; $main_links_html = empty($main_links) ? "" : "<div class='space' id='links'>$main_links</div>";
$message_html = empty($main_text) ? "" : "<div class='space' id='message'>$main_text</div>"; $message_html = empty($main_text) ? "" : "<div class='space' id='message'>$main_text</div>";
$counter_html = empty($counter_text) ? "" : "<div class='space' id='counter'>$counter_text</div>"; $counter_html = empty($counter_text) ? "" : "<div class='space' id='counter'>$counter_text</div>";

View file

@ -34,10 +34,7 @@ class ImageAdditionEvent extends Event {
class ImageAdditionException extends SCoreException { class ImageAdditionException extends SCoreException {
public $error; public $error;
/** public function __construct(string $error) {
* @param string $error
*/
public function __construct($error) {
$this->error = $error; $this->error = $error;
} }
} }
@ -81,7 +78,7 @@ class ImageReplaceEvent extends Event {
* @param int $id The ID of the image to replace. * @param int $id The ID of the image to replace.
* @param Image $image The image object of the new image to use. * @param Image $image The image object of the new image to use.
*/ */
public function __construct(/*int*/ $id, Image $image) { public function __construct(int $id, Image $image) {
$this->id = $id; $this->id = $id;
$this->image = $image; $this->image = $image;
} }
@ -91,10 +88,7 @@ class ImageReplaceException extends SCoreException {
/** @var string */ /** @var string */
public $error; public $error;
/** public function __construct(string $error) {
* @param string $error
*/
public function __construct(/*string*/ $error) {
$this->error = $error; $this->error = $error;
} }
} }
@ -117,7 +111,7 @@ class ThumbnailGenerationEvent extends Event {
* @param string $type The type of the image * @param string $type The type of the image
* @param bool $force Regenerate the thumbnail even if one already exists * @param bool $force Regenerate the thumbnail even if one already exists
*/ */
public function __construct($hash, $type, $force=false) { public function __construct(string $hash, string $type, bool $force=false) {
$this->hash = $hash; $this->hash = $hash;
$this->type = $type; $this->type = $type;
$this->force = $force; $this->force = $force;
@ -143,17 +137,13 @@ class ParseLinkTemplateEvent extends Event {
* @param string $link The formatted link * @param string $link The formatted link
* @param Image $image The image who's link is being parsed * @param Image $image The image who's link is being parsed
*/ */
public function __construct($link, Image $image) { public function __construct(string $link, Image $image) {
$this->link = $link; $this->link = $link;
$this->original = $link; $this->original = $link;
$this->image = $image; $this->image = $image;
} }
/** public function replace(string $needle, string $replace) {
* @param string $needle
* @param string $replace
*/
public function replace($needle, $replace) {
$this->link = str_replace($needle, $replace, $this->link); $this->link = str_replace($needle, $replace, $this->link);
} }
} }
@ -309,11 +299,6 @@ class ImageIO extends Extension {
// add image {{{ // add image {{{
/**
* @param Image $image
* @return null
* @throws ImageAdditionException
*/
private function add_image(Image $image) { private function add_image(Image $image) {
global $user, $database, $config; global $user, $database, $config;
@ -383,11 +368,7 @@ class ImageIO extends Extension {
// }}} end add // }}} end add
// fetch image {{{ // fetch image {{{
/** private function send_file(int $image_id, string $type) {
* @param int $image_id
* @param string $type
*/
private function send_file($image_id, $type) {
global $config; global $config;
$image = Image::by_id($image_id); $image = Image::by_id($image_id);
@ -438,12 +419,7 @@ class ImageIO extends Extension {
// }}} end fetch // }}} end fetch
// replace image {{{ // replace image {{{
/** private function replace_image(int $id, Image $image) {
* @param int $id
* @param Image $image
* @throws ImageReplaceException
*/
private function replace_image($id, $image) {
global $database; global $database;
/* Check to make sure the image exists. */ /* Check to make sure the image exists. */

View file

@ -7,7 +7,7 @@ class ImageIOTheme extends Themelet {
* @param $image_id integer The image to delete * @param $image_id integer The image to delete
* @return string * @return string
*/ */
public function get_deleter_html(/*int*/ $image_id) { public function get_deleter_html(int $image_id) {
$html = " $html = "
".make_form(make_link("image/delete"))." ".make_form(make_link("image/delete"))."
<input type='hidden' name='image_id' value='$image_id' /> <input type='hidden' name='image_id' value='$image_id' />
@ -24,7 +24,7 @@ class ImageIOTheme extends Themelet {
* @param $image_id integer The image to replace * @param $image_id integer The image to replace
* @return string * @return string
*/ */
public function get_replace_html(/*int*/ $image_id) { public function get_replace_html(int $image_id) {
$html = make_form(make_link("image/replace"))." $html = make_form(make_link("image/replace"))."
<input type='hidden' name='image_id' value='$image_id' /> <input type='hidden' name='image_id' value='$image_id' />
<input type='submit' value='Replace' /> <input type='submit' value='Replace' />

View file

@ -13,10 +13,7 @@
class RemoveImageHashBanEvent extends Event { class RemoveImageHashBanEvent extends Event {
public $hash; public $hash;
/** public function __construct(string $hash) {
* @param string $hash
*/
public function __construct($hash) {
$this->hash = $hash; $this->hash = $hash;
} }
} }
@ -26,11 +23,7 @@ class AddImageHashBanEvent extends Event {
public $hash; public $hash;
public $reason; public $reason;
/** public function __construct(string $hash, string $reason) {
* @param string $hash
* @param string $reason
*/
public function __construct($hash, $reason) {
$this->hash = $hash; $this->hash = $hash;
$this->reason = $reason; $this->reason = $reason;
} }
@ -168,6 +161,6 @@ class ImageBan extends Extension {
} }
// in before resolution limit plugin // in before resolution limit plugin
public function get_priority() {return 30;} public function get_priority(): int {return 30;}
} }

View file

@ -166,33 +166,20 @@ class SearchTermParseEvent extends Event {
/** @var \Querylet[] */ /** @var \Querylet[] */
public $querylets = array(); public $querylets = array();
/** public function __construct(string $term=null, array $context=array()) {
* @param string|null $term
* @param string[] $context
*/
public function __construct($term, array $context) {
$this->term = $term; $this->term = $term;
$this->context = $context; $this->context = $context;
} }
/** public function is_querylet_set(): bool {
* @return bool
*/
public function is_querylet_set() {
return (count($this->querylets) > 0); return (count($this->querylets) > 0);
} }
/** public function get_querylets(): array {
* @return \Querylet[]
*/
public function get_querylets() {
return $this->querylets; return $this->querylets;
} }
/** public function add_querylet(Querylet $q) {
* @param \Querylet $q
*/
public function add_querylet($q) {
$this->querylets[] = $q; $this->querylets[] = $q;
} }
} }
@ -214,11 +201,7 @@ class PostListBuildingEvent extends Event {
$this->search_terms = $search; $this->search_terms = $search;
} }
/** public function add_control(string $html, int $position=50) {
* @param string $html
* @param int $position
*/
public function add_control(/*string*/ $html, /*int*/ $position=50) {
while(isset($this->parts[$position])) $position++; while(isset($this->parts[$position])) $position++;
$this->parts[$position] = $html; $this->parts[$position] = $html;
} }

View file

@ -16,7 +16,7 @@
class RemoveIPBanEvent extends Event { class RemoveIPBanEvent extends Event {
public $id; public $id;
public function __construct($id) { public function __construct(int $id) {
$this->id = $id; $this->id = $id;
} }
} }
@ -27,7 +27,7 @@ class AddIPBanEvent extends Event {
public $reason; public $reason;
public $end; public $end;
public function __construct(/*string(ip)*/ $ip, /*string*/ $reason, /*string*/ $end) { public function __construct(string $ip, string $reason, string $end) {
$this->ip = trim($ip); $this->ip = trim($ip);
$this->reason = trim($reason); $this->reason = trim($reason);
$this->end = trim($end); $this->end = trim($end);
@ -36,7 +36,7 @@ class AddIPBanEvent extends Event {
// }}} // }}}
class IPBan extends Extension { class IPBan extends Extension {
public function get_priority() {return 10;} public function get_priority(): int {return 10;}
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
@ -202,7 +202,7 @@ class IPBan extends Extension {
} }
} }
private function block(/*string*/ $remote) { private function block(string $remote) {
global $config, $database; global $config, $database;
$prefix = ($database->get_driver_name() == "sqlite" ? "bans." : ""); $prefix = ($database->get_driver_name() == "sqlite" ? "bans." : "");

View file

@ -51,7 +51,7 @@ class LinkImageTheme extends Themelet {
50)); 50));
} }
protected function url (/*string*/ $url, /*string*/ $content, /*string*/ $type) { protected function url (string $url, string $content, string $type) {
if ($content == NULL) {$content=$url;} if ($content == NULL) {$content=$url;}
switch ($type) { switch ($type) {
@ -67,7 +67,7 @@ class LinkImageTheme extends Themelet {
return $text; return $text;
} }
protected function img (/*string*/ $src, /*string*/ $type) { protected function img (string $src, string $type) {
switch ($type) { switch ($type) {
case "html": case "html":
$text = "<img src=\"$src\" />"; $text = "<img src=\"$src\" />";
@ -81,7 +81,7 @@ class LinkImageTheme extends Themelet {
return $text; return $text;
} }
protected function link_code(/*string*/ $label, /*string*/ $content, $id=NULL) { protected function link_code(string $label, string $content, $id=NULL) {
return " return "
<tr> <tr>
<td><label for='".$id."' title='Click to select the textbox'>$label</label></td> <td><label for='".$id."' title='Click to select the textbox'>$label</label></td>

View file

@ -46,7 +46,7 @@ class LiveFeed extends Extension {
# $this->msg("Image info set"); # $this->msg("Image info set");
} }
public function get_priority() {return 99;} public function get_priority(): int {return 99;}
/** /**
* @param string $data * @param string $data

View file

@ -1,9 +1,6 @@
<?php <?php
class MassTaggerTheme extends Themelet { class MassTaggerTheme extends Themelet {
/*
* Show $text on the $page
*/
public function display_mass_tagger( Page $page, Event $event, $config ) { public function display_mass_tagger( Page $page, Event $event, $config ) {
$data_href = get_base_href(); $data_href = get_base_href();
$body = " $body = "

View file

@ -7,7 +7,7 @@
* Description: Redirect users to the rules if they use bad tags * Description: Redirect users to the rules if they use bad tags
*/ */
class NotATag extends Extension { class NotATag extends Extension {
public function get_priority() {return 30;} // before ImageUploadEvent and tag_history public function get_priority(): int {return 30;} // before ImageUploadEvent and tag_history
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config, $database; global $config, $database;

View file

@ -13,12 +13,7 @@
class NumericScoreSetEvent extends Event { class NumericScoreSetEvent extends Event {
public $image_id, $user, $score; public $image_id, $user, $score;
/** public function __construct(int $image_id, User $user, int $score) {
* @param int $image_id
* @param User $user
* @param int $score
*/
public function __construct($image_id, User $user, $score) {
$this->image_id = $image_id; $this->image_id = $image_id;
$this->user = $user; $this->user = $user;
$this->score = $score; $this->score = $score;

View file

@ -21,7 +21,7 @@ class SendPMEvent extends Event {
class PM { class PM {
public $id, $from_id, $from_ip, $to_id, $sent_date, $subject, $message, $is_read; public $id, $from_id, $from_ip, $to_id, $sent_date, $subject, $message, $is_read;
public function __construct($from_id=0, $from_ip="0.0.0.0", $to_id=0, $subject="A Message", $message="Some Text", $read=False) { public function __construct($from_id=0, string $from_ip="0.0.0.0", int $to_id=0, string $subject="A Message", string $message="Some Text", bool $read=False) {
# PHP: the P stands for "really", the H stands for "awful" and the other P stands for "language" # PHP: the P stands for "really", the H stands for "awful" and the other P stands for "language"
if(is_array($from_id)) { if(is_array($from_id)) {
$a = $from_id; $a = $from_id;

View file

@ -373,7 +373,7 @@ class Pools extends Extension {
* @param \Page $page * @param \Page $page
* @param int $pageNumber * @param int $pageNumber
*/ */
private function list_pools(Page $page, /*int*/ $pageNumber) { private function list_pools(Page $page, int $pageNumber) {
global $config, $database; global $config, $database;
$pageNumber = clamp($pageNumber, 1, null) - 1; $pageNumber = clamp($pageNumber, 1, null) - 1;
@ -446,7 +446,7 @@ class Pools extends Extension {
* @param int $poolID Array of integers * @param int $poolID Array of integers
* @return array * @return array
*/ */
private function get_pool(/*int*/ $poolID) { private function get_pool(int $poolID) {
global $database; global $database;
return $database->get_all("SELECT * FROM pools WHERE id=:id", array("id"=>$poolID)); return $database->get_all("SELECT * FROM pools WHERE id=:id", array("id"=>$poolID));
} }
@ -456,7 +456,7 @@ class Pools extends Extension {
* @param int $poolID the pool id * @param int $poolID the pool id
* @return array Array with only 1 element in the one dimension * @return array Array with only 1 element in the one dimension
*/ */
private function get_single_pool(/*int*/ $poolID) { private function get_single_pool(int $poolID) {
global $database; global $database;
return $database->get_row("SELECT * FROM pools WHERE id=:id", array("id"=>$poolID)); return $database->get_row("SELECT * FROM pools WHERE id=:id", array("id"=>$poolID));
} }
@ -466,7 +466,7 @@ class Pools extends Extension {
* @param string $poolTitle * @param string $poolTitle
* @return array Array (with only 1 element in the one dimension) * @return array Array (with only 1 element in the one dimension)
*/ */
private function get_single_pool_from_title(/*string*/ $poolTitle) { private function get_single_pool_from_title(string $poolTitle) {
global $database; global $database;
return $database->get_row("SELECT * FROM pools WHERE title=:title", array("title"=>$poolTitle)); return $database->get_row("SELECT * FROM pools WHERE title=:title", array("title"=>$poolTitle));
} }
@ -476,7 +476,7 @@ class Pools extends Extension {
* @param int $imageID Integer ID for the image * @param int $imageID Integer ID for the image
* @return int[] * @return int[]
*/ */
private function get_pool_ids(/*int*/ $imageID) { private function get_pool_ids(int $imageID) {
global $database; global $database;
return $database->get_col("SELECT pool_id FROM pool_images WHERE image_id=:iid", array("iid"=>$imageID)); return $database->get_col("SELECT pool_id FROM pool_images WHERE image_id=:iid", array("iid"=>$imageID));
} }
@ -486,7 +486,7 @@ class Pools extends Extension {
* @param int $userID * @param int $userID
* @return array * @return array
*/ */
private function get_last_userpool(/*int*/ $userID){ private function get_last_userpool(int $userID){
global $database; global $database;
return $database->get_row("SELECT * FROM pools WHERE user_id=:uid ORDER BY id DESC", array("uid"=>$userID)); return $database->get_row("SELECT * FROM pools WHERE user_id=:uid ORDER BY id DESC", array("uid"=>$userID));
} }
@ -495,7 +495,7 @@ class Pools extends Extension {
* HERE WE GET THE IMAGES FROM THE TAG ON IMPORT * HERE WE GET THE IMAGES FROM THE TAG ON IMPORT
* @param int $pool_id * @param int $pool_id
*/ */
private function import_posts(/*int*/ $pool_id) { private function import_posts(int $pool_id) {
global $page, $config; global $page, $config;
$poolsMaxResults = $config->get_int("poolsMaxImportResults", 1000); $poolsMaxResults = $config->get_int("poolsMaxImportResults", 1000);
@ -610,7 +610,7 @@ class Pools extends Extension {
* @param int $imageID * @param int $imageID
* @return bool * @return bool
*/ */
private function check_post(/*int*/ $poolID, /*int*/ $imageID) { private function check_post(int $poolID, int $imageID) {
global $database; global $database;
$result = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid AND image_id=:iid", array("pid"=>$poolID, "iid"=>$imageID)); $result = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid AND image_id=:iid", array("pid"=>$poolID, "iid"=>$imageID));
return ($result != 0); return ($result != 0);
@ -623,7 +623,7 @@ class Pools extends Extension {
* @param int $imageID Integer * @param int $imageID Integer
* @return array Array returning two elements (prev, next) in 1 dimension. Each returns ImageID or NULL if none. * @return array Array returning two elements (prev, next) in 1 dimension. Each returns ImageID or NULL if none.
*/ */
private function get_nav_posts(/*array*/ $pool, /*int*/ $imageID) { private function get_nav_posts(array $pool, int $imageID) {
global $database; global $database;
if (empty($pool) || empty($imageID)) if (empty($pool) || empty($imageID))
@ -674,7 +674,7 @@ class Pools extends Extension {
* @param PageRequestEvent $event * @param PageRequestEvent $event
* @param int $poolID * @param int $poolID
*/ */
private function get_posts($event, /*int*/ $poolID) { private function get_posts($event, int $poolID) {
global $config, $user, $database; global $config, $user, $database;
$pageNumber = int_escape($event->get_arg(2)); $pageNumber = int_escape($event->get_arg(2));
@ -739,7 +739,7 @@ class Pools extends Extension {
* @param int $poolID * @param int $poolID
* @return \Image[] Array of image objects. * @return \Image[] Array of image objects.
*/ */
private function edit_posts(/*int*/ $poolID) { private function edit_posts(int $poolID) {
global $database; global $database;
$result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", array("pid"=>$poolID)); $result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", array("pid"=>$poolID));
@ -760,7 +760,7 @@ class Pools extends Extension {
* @param int $poolID * @param int $poolID
* @return \Image[] * @return \Image[]
*/ */
private function edit_order(/*int*/ $poolID) { private function edit_order(int $poolID) {
global $database; global $database;
$result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", array("pid"=>$poolID)); $result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", array("pid"=>$poolID));
@ -786,7 +786,7 @@ class Pools extends Extension {
* *
* @param int $poolID * @param int $poolID
*/ */
private function nuke_pool(/*int*/ $poolID) { private function nuke_pool(int $poolID) {
global $user, $database; global $user, $database;
$p_id = $database->get_one("SELECT user_id FROM pools WHERE id = :pid", array("pid"=>$poolID)); $p_id = $database->get_one("SELECT user_id FROM pools WHERE id = :pid", array("pid"=>$poolID));
@ -809,7 +809,7 @@ class Pools extends Extension {
* @param string $images * @param string $images
* @param int $count * @param int $count
*/ */
private function add_history(/*int*/ $poolID, $action, $images, $count) { private function add_history(int $poolID, $action, $images, $count) {
global $user, $database; global $user, $database;
$database->execute(" $database->execute("
@ -822,7 +822,7 @@ class Pools extends Extension {
* HERE WE GET THE HISTORY LIST. * HERE WE GET THE HISTORY LIST.
* @param int $pageNumber * @param int $pageNumber
*/ */
private function get_history(/*int*/ $pageNumber) { private function get_history(int $pageNumber) {
global $config, $database; global $config, $database;
if(is_null($pageNumber) || !is_numeric($pageNumber)) if(is_null($pageNumber) || !is_numeric($pageNumber))
@ -855,7 +855,7 @@ class Pools extends Extension {
* HERE GO BACK IN HISTORY AND ADD OR REMOVE POSTS TO POOL. * HERE GO BACK IN HISTORY AND ADD OR REMOVE POSTS TO POOL.
* @param int $historyID * @param int $historyID
*/ */
private function revert_history(/*int*/ $historyID) { private function revert_history(int $historyID) {
global $database; global $database;
$status = $database->get_all("SELECT * FROM pool_history WHERE id=:hid", array("hid"=>$historyID)); $status = $database->get_all("SELECT * FROM pool_history WHERE id=:hid", array("hid"=>$historyID));
@ -905,7 +905,7 @@ class Pools extends Extension {
* @param bool $history * @param bool $history
* @param int $imageOrder * @param int $imageOrder
*/ */
private function add_post(/*int*/ $poolID, /*int*/ $imageID, $history=false, $imageOrder=0) { private function add_post(int $poolID, int $imageID, $history=false, $imageOrder=0) {
global $database, $config; global $database, $config;
if(!$this->check_post($poolID, $imageID)) { if(!$this->check_post($poolID, $imageID)) {
@ -939,7 +939,7 @@ class Pools extends Extension {
* @param int $imageID * @param int $imageID
* @param bool $history * @param bool $history
*/ */
private function delete_post(/*int*/ $poolID, /*int*/ $imageID, $history=false) { private function delete_post(int $poolID, int $imageID, $history=false) {
global $database; global $database;
$database->execute("DELETE FROM pool_images WHERE pool_id = :pid AND image_id = :iid", array("pid"=>$poolID, "iid"=>$imageID)); $database->execute("DELETE FROM pool_images WHERE pool_id = :pid AND image_id = :iid", array("pid"=>$poolID, "iid"=>$imageID));

View file

@ -5,7 +5,7 @@ class PoolsTheme extends Themelet {
* Adds a block to the panel with information on the pool(s) the image is in. * Adds a block to the panel with information on the pool(s) the image is in.
* @param array Multidimensional array containing pool id, info & nav IDs. * @param array Multidimensional array containing pool id, info & nav IDs.
*/ */
public function pool_info(/*array*/ $navIDs) { public function pool_info(array $navIDs) {
global $page; global $page;
$linksPools = array(); $linksPools = array();
@ -37,7 +37,7 @@ class PoolsTheme extends Themelet {
* @param array $pools * @param array $pools
* @return string * @return string
*/ */
public function get_adder_html(Image $image, /*array*/ $pools) { public function get_adder_html(Image $image, array $pools) {
$h = ""; $h = "";
foreach($pools as $pool) { foreach($pools as $pool) {
$h .= "<option value='".$pool['id']."'>".html_escape($pool['title'])."</option>"; $h .= "<option value='".$pool['id']."'>".html_escape($pool['title'])."</option>";
@ -61,7 +61,7 @@ class PoolsTheme extends Themelet {
* @param int $pageNumber * @param int $pageNumber
* @param int $totalPages * @param int $totalPages
*/ */
public function list_pools(Page $page, /*array*/ $pools, /*int*/ $pageNumber, /*int*/ $totalPages) { public function list_pools(Page $page, array $pools, int $pageNumber, int $totalPages) {
$html = ' $html = '
<table id="poolsList" class="zebra"> <table id="poolsList" class="zebra">
<thead><tr> <thead><tr>
@ -125,12 +125,7 @@ class PoolsTheme extends Themelet {
$page->add_block(new Block("Create Pool", $create_html, "main", 20)); $page->add_block(new Block("Create Pool", $create_html, "main", 20));
} }
/** private function display_top(array $pools=null, string $heading, bool $check_all=false) {
* @param array $pools
* @param string $heading
* @param bool $check_all
*/
private function display_top(/*array*/ $pools, /*string*/ $heading, $check_all=false) {
global $page, $user; global $page, $user;
$page->set_title($heading); $page->set_title($heading);
@ -167,7 +162,7 @@ class PoolsTheme extends Themelet {
* @param int $pageNumber * @param int $pageNumber
* @param int $totalPages * @param int $totalPages
*/ */
public function view_pool(/*array*/ $pools, /*array*/ $images, /*int*/ $pageNumber, /*int*/ $totalPages) { public function view_pool(array $pools, array $images, int $pageNumber, int $totalPages) {
global $page; global $page;
$this->display_top($pools, "Pool: ".html_escape($pools[0]['title'])); $this->display_top($pools, "Pool: ".html_escape($pools[0]['title']));
@ -190,7 +185,7 @@ class PoolsTheme extends Themelet {
* @param array $pool * @param array $pool
* @param bool $check_all * @param bool $check_all
*/ */
public function sidebar_options(Page $page, $pool, /*bool*/ $check_all) { public function sidebar_options(Page $page, $pool, bool $check_all) {
global $user; global $user;
$editor = "\n".make_form( make_link('pool/import') ).' $editor = "\n".make_form( make_link('pool/import') ).'
@ -253,7 +248,7 @@ class PoolsTheme extends Themelet {
* @param array $images * @param array $images
* @param array $pool * @param array $pool
*/ */
public function pool_result(Page $page, /*array*/ $images, /*array*/ $pool) { public function pool_result(Page $page, array $images, array $pool) {
$this->display_top($pool, "Importing Posts", true); $this->display_top($pool, "Importing Posts", true);
$pool_images = " $pool_images = "
@ -293,7 +288,7 @@ class PoolsTheme extends Themelet {
* @param array $pools * @param array $pools
* @param array $images * @param array $images
*/ */
public function edit_order(Page $page, /*array*/ $pools, /*array*/ $images) { public function edit_order(Page $page, array $pools, array $images) {
$this->display_top($pools, "Sorting Pool"); $this->display_top($pools, "Sorting Pool");
$pool_images = "\n<form action='".make_link("pool/order")."' method='POST' name='checks'>"; $pool_images = "\n<form action='".make_link("pool/order")."' method='POST' name='checks'>";
@ -326,7 +321,7 @@ class PoolsTheme extends Themelet {
* @param array $pools * @param array $pools
* @param array $images * @param array $images
*/ */
public function edit_pool(Page $page, /*array*/ $pools, /*array*/ $images) { public function edit_pool(Page $page, array $pools, array $images) {
/* EDIT POOL DESCRIPTION */ /* EDIT POOL DESCRIPTION */
$desc_html = " $desc_html = "
".make_form(make_link("pool/edit_description"))." ".make_form(make_link("pool/edit_description"))."
@ -368,7 +363,7 @@ class PoolsTheme extends Themelet {
* @param int $pageNumber * @param int $pageNumber
* @param int $totalPages * @param int $totalPages
*/ */
public function show_history($histories, /*int*/ $pageNumber, /*int*/ $totalPages) { public function show_history($histories, int $pageNumber, int $totalPages) {
global $page; global $page;
$html = ' $html = '
<table id="poolsList" class="zebra"> <table id="poolsList" class="zebra">

View file

@ -47,7 +47,7 @@ class RandomImage extends Extension {
} }
else if($action === "view") { else if($action === "view") {
if(!is_null($image)) { if(!is_null($image)) {
send_event(new DisplayingImageEvent($image, $page)); send_event(new DisplayingImageEvent($image));
} }
} }
else if($action === "widget") { else if($action === "widget") {

View file

@ -35,11 +35,7 @@ class RandomListTheme extends Themelet {
$page->add_block(new Block("Navigation", $nav, "left", 0)); $page->add_block(new Block("Navigation", $nav, "left", 0));
} }
/** protected function build_navigation(array $search_terms): string {
* @param string[] $search_terms
* @return string
*/
protected function build_navigation($search_terms) {
$h_search_string = html_escape(implode(" ", $search_terms)); $h_search_string = html_escape(implode(" ", $search_terms));
$h_search_link = make_link("random"); $h_search_link = make_link("random");
$h_search = " $h_search = "

View file

@ -25,11 +25,7 @@ class RatingSetEvent extends Event {
/** @var string */ /** @var string */
public $rating; public $rating;
/** public function __construct(Image $image, string $rating) {
* @param Image $image
* @param string $rating
*/
public function __construct(Image $image, /*char*/ $rating) {
assert(in_array($rating, array("s", "q", "e", "u"))); assert(in_array($rating, array("s", "q", "e", "u")));
$this->image = $image; $this->image = $image;
@ -43,7 +39,7 @@ class Ratings extends Extension {
/** /**
* @return int * @return int
*/ */
public function get_priority() {return 50;} public function get_priority(): int {return 50;}
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
@ -189,7 +185,7 @@ class Ratings extends Extension {
* @param string $sqes * @param string $sqes
* @return string * @return string
*/ */
public static function privs_to_sql(/*string*/ $sqes) { public static function privs_to_sql(string $sqes) {
$arr = array(); $arr = array();
$length = strlen($sqes); $length = strlen($sqes);
for($i=0; $i<$length; $i++) { for($i=0; $i<$length; $i++) {
@ -203,7 +199,7 @@ class Ratings extends Extension {
* @param string $rating * @param string $rating
* @return string * @return string
*/ */
public static function rating_to_human(/*string*/ $rating) { public static function rating_to_human(string $rating) {
switch($rating) { switch($rating) {
case "s": return "Safe"; case "s": return "Safe";
case "q": return "Questionable"; case "q": return "Questionable";
@ -216,7 +212,7 @@ class Ratings extends Extension {
* @param string $rating * @param string $rating
* @return bool * @return bool
*/ */
public static function rating_is_valid(/*string*/ $rating) { public static function rating_is_valid(string $rating) {
switch($rating) { switch($rating) {
case "s": case "s":
case "q": case "q":
@ -279,7 +275,7 @@ class Ratings extends Extension {
* @param string $rating * @param string $rating
* @param string $old_rating * @param string $old_rating
*/ */
private function set_rating(/*int*/ $image_id, /*string*/ $rating, /*string*/ $old_rating) { private function set_rating(int $image_id, string $rating, string $old_rating) {
global $database; global $database;
if($old_rating != $rating){ if($old_rating != $rating){
$database->Execute("UPDATE images SET rating=? WHERE id=?", array($rating, $image_id)); $database->Execute("UPDATE images SET rating=? WHERE id=?", array($rating, $image_id));

View file

@ -6,7 +6,7 @@ class RatingsTheme extends Themelet {
* @param string $rating * @param string $rating
* @return string * @return string
*/ */
public function get_rater_html(/*int*/ $image_id, /*string*/ $rating, /*bool*/ $can_rate) { public function get_rater_html(int $image_id, string $rating, bool $can_rate) {
$s_checked = $rating == 's' ? " checked" : ""; $s_checked = $rating == 's' ? " checked" : "";
$q_checked = $rating == 'q' ? " checked" : ""; $q_checked = $rating == 'q' ? " checked" : "";
$e_checked = $rating == 'e' ? " checked" : ""; $e_checked = $rating == 'e' ? " checked" : "";

View file

@ -103,7 +103,7 @@ class Relationships extends Extension {
* @param int $imageID * @param int $imageID
* @param int $parentID * @param int $parentID
*/ */
private function set_parent(/*int*/ $imageID, /*int*/ $parentID){ private function set_parent(int $imageID, int $parentID){
global $database; global $database;
if($database->get_row("SELECT 1 FROM images WHERE id = :pid", array("pid"=>$parentID))){ if($database->get_row("SELECT 1 FROM images WHERE id = :pid", array("pid"=>$parentID))){
@ -116,7 +116,7 @@ class Relationships extends Extension {
* @param int $parentID * @param int $parentID
* @param int $childID * @param int $childID
*/ */
private function set_child(/*int*/ $parentID, /*int*/ $childID){ private function set_child(int $parentID, int $childID){
global $database; global $database;
if($database->get_row("SELECT 1 FROM images WHERE id = :cid", array("cid"=>$childID))){ if($database->get_row("SELECT 1 FROM images WHERE id = :cid", array("cid"=>$childID))){
@ -128,7 +128,7 @@ class Relationships extends Extension {
/** /**
* @param int $imageID * @param int $imageID
*/ */
private function remove_parent(/*int*/ $imageID){ private function remove_parent(int $imageID){
global $database; global $database;
$parentID = $database->get_one("SELECT parent_id FROM images WHERE id = :iid", array("iid"=>$imageID)); $parentID = $database->get_one("SELECT parent_id FROM images WHERE id = :iid", array("iid"=>$imageID));

View file

@ -13,10 +13,7 @@ class RemoveReportedImageEvent extends Event {
/** @var int */ /** @var int */
public $id; public $id;
/** public function __construct(int $id) {
* @param int $id
*/
public function __construct($id) {
$this->id = $id; $this->id = $id;
} }
} }
@ -25,10 +22,7 @@ class AddReportedImageEvent extends Event {
/** @var ImageReport */ /** @var ImageReport */
public $report; public $report;
/** public function __construct(ImageReport $report) {
* @param ImageReport $report
*/
public function __construct($report) {
$this->report = $report; $this->report = $report;
} }
} }
@ -41,7 +35,7 @@ class ImageReport {
/** @var string */ /** @var string */
public $reason; public $reason;
public function __construct($image_id, $user_id, $reason) { public function __construct(int $image_id, int $user_id, string $reason) {
$this->image_id = $image_id; $this->image_id = $image_id;
$this->user_id = $user_id; $this->user_id = $user_id;
$this->reason = $reason; $this->reason = $reason;

View file

@ -66,7 +66,7 @@ class ReportImageTheme extends Themelet {
* @param Image $image * @param Image $image
* @param ImageReport[] $reports * @param ImageReport[] $reports
*/ */
public function display_image_banner(Image $image, /*array*/ $reports) { public function display_image_banner(Image $image, array $reports) {
global $config, $page; global $config, $page;
$i_image = int_escape($image->id); $i_image = int_escape($image->id);

View file

@ -7,7 +7,7 @@
* Description: Allows the admin to set min / max image dimentions * Description: Allows the admin to set min / max image dimentions
*/ */
class ResolutionLimit extends Extension { class ResolutionLimit extends Extension {
public function get_priority() {return 40;} // early, to veto ImageUploadEvent public function get_priority(): int {return 40;} // early, to veto ImageUploadEvent
public function onImageAddition(ImageAdditionEvent $event) { public function onImageAddition(ImageAdditionEvent $event) {
global $config; global $config;

View file

@ -164,7 +164,7 @@ class ResizeImage extends Extension {
* @param int $height * @param int $height
* @throws ImageResizeException * @throws ImageResizeException
*/ */
private function resize_image(Image $image_obj, /*int*/ $width, /*int*/ $height) { private function resize_image(Image $image_obj, int $width, int $height) {
global $database; global $database;
if ( ($height <= 0) && ($width <= 0) ) { if ( ($height <= 0) && ($width <= 0) ) {

View file

@ -28,7 +28,7 @@ class ResizeImageTheme extends Themelet {
return $html; return $html;
} }
public function display_resize_error(Page $page, /*string*/ $title, /*string*/ $message) { public function display_resize_error(Page $page, string $title, string $message) {
$page->set_title("Resize Image"); $page->set_title("Resize Image");
$page->set_heading("Resize Image"); $page->set_heading("Resize Image");
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());

View file

@ -113,7 +113,7 @@ class RotateImage extends Extension {
* @param int $deg * @param int $deg
* @throws ImageRotateException * @throws ImageRotateException
*/ */
private function rotate_image(/*int*/ $image_id, /*int*/ $deg) { private function rotate_image(int $image_id, int $deg) {
global $database; global $database;
if ( ($deg <= -360) || ($deg >= 360) ) { if ( ($deg <= -360) || ($deg >= 360) ) {

View file

@ -7,7 +7,7 @@ class RotateImageTheme extends Themelet {
* @param int $image_id * @param int $image_id
* @return string * @return string
*/ */
public function get_rotate_html(/*int*/ $image_id) { public function get_rotate_html(int $image_id) {
$html = " $html = "
".make_form(make_link('rotate/'.$image_id), 'POST')." ".make_form(make_link('rotate/'.$image_id), 'POST')."
<input type='hidden' name='image_id' value='$image_id'> <input type='hidden' name='image_id' value='$image_id'>
@ -26,7 +26,7 @@ class RotateImageTheme extends Themelet {
* @param string $title * @param string $title
* @param string $message * @param string $message
*/ */
public function display_rotate_error(Page $page, /*string*/ $title, /*string*/ $message) { public function display_rotate_error(Page $page, string $title, string $message) {
$page->set_title("Rotate Image"); $page->set_title("Rotate Image");
$page->set_heading("Rotate Image"); $page->set_heading("Rotate Image");
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());

View file

@ -38,7 +38,7 @@ class RSS_Images extends Extension {
* @param array $search_terms * @param array $search_terms
* @param int $page_number * @param int $page_number
*/ */
private function do_rss($images, $search_terms, /*int*/ $page_number) { private function do_rss($images, $search_terms, int $page_number) {
global $page; global $page;
global $config; global $config;
$page->set_mode("data"); $page->set_mode("data");
@ -83,11 +83,7 @@ class RSS_Images extends Extension {
$page->set_data($xml); $page->set_data($xml);
} }
/** private function thumb(Image $image): string {
* @param Image $image
* @return string
*/
private function thumb(Image $image) {
global $database; global $database;
$cached = $database->cache->get("rss-thumb:{$image->id}"); $cached = $database->cache->get("rss-thumb:{$image->id}");

View file

@ -63,28 +63,18 @@ class SetupBlock extends Block {
/** @var string */ /** @var string */
public $body; public $body;
/** public function __construct(string $title) {
* @param string $title
*/
public function __construct($title) {
$this->header = $title; $this->header = $title;
$this->section = "main"; $this->section = "main";
$this->position = 50; $this->position = 50;
$this->body = ""; $this->body = "";
} }
/** public function add_label(string $text) {
* @param string $text
*/
public function add_label($text) {
$this->body .= $text; $this->body .= $text;
} }
/** public function add_text_option(string $name, string $label=null) {
* @param string $name
* @param null|string $label
*/
public function add_text_option($name, $label=null) {
global $config; global $config;
$val = html_escape($config->get_string($name)); $val = html_escape($config->get_string($name));
if(!is_null($label)) { if(!is_null($label)) {
@ -94,11 +84,7 @@ class SetupBlock extends Block {
$this->body .= "<input type='hidden' name='_type_{$name}' value='string'>\n"; $this->body .= "<input type='hidden' name='_type_{$name}' value='string'>\n";
} }
/** public function add_longtext_option(string $name, string $label=null) {
* @param string $name
* @param null|string $label
*/
public function add_longtext_option($name, $label=null) {
global $config; global $config;
$val = html_escape($config->get_string($name)); $val = html_escape($config->get_string($name));
if(!is_null($label)) { if(!is_null($label)) {
@ -109,11 +95,7 @@ class SetupBlock extends Block {
$this->body .= "<input type='hidden' name='_type_$name' value='string'>\n"; $this->body .= "<input type='hidden' name='_type_$name' value='string'>\n";
} }
/** public function add_bool_option(string $name, string $label=null) {
* @param string $name
* @param null|string $label
*/
public function add_bool_option($name, $label=null) {
global $config; global $config;
$checked = $config->get_bool($name) ? " checked" : ""; $checked = $config->get_bool($name) ? " checked" : "";
if(!is_null($label)) { if(!is_null($label)) {
@ -129,11 +111,7 @@ class SetupBlock extends Block {
// $this->body .= "<input type='hidden' id='$name' name='$name' value='$val'>"; // $this->body .= "<input type='hidden' id='$name' name='$name' value='$val'>";
// } // }
/** public function add_int_option(string $name, string $label=null) {
* @param string $name
* @param null|string $label
*/
public function add_int_option($name, $label=null) {
global $config; global $config;
$val = html_escape($config->get_string($name)); $val = html_escape($config->get_string($name));
if(!is_null($label)) { if(!is_null($label)) {
@ -143,11 +121,7 @@ class SetupBlock extends Block {
$this->body .= "<input type='hidden' name='_type_$name' value='int'>\n"; $this->body .= "<input type='hidden' name='_type_$name' value='int'>\n";
} }
/** public function add_shorthand_int_option(string $name, string $label=null) {
* @param string $name
* @param null|string $label
*/
public function add_shorthand_int_option($name, $label=null) {
global $config; global $config;
$val = to_shorthand_int($config->get_string($name)); $val = to_shorthand_int($config->get_string($name));
if(!is_null($label)) { if(!is_null($label)) {
@ -157,12 +131,7 @@ class SetupBlock extends Block {
$this->body .= "<input type='hidden' name='_type_$name' value='int'>\n"; $this->body .= "<input type='hidden' name='_type_$name' value='int'>\n";
} }
/** public function add_choice_option(string $name, array $options, string $label=null) {
* @param string $name
* @param string[] $options
* @param null|string $label
*/
public function add_choice_option($name, $options, $label=null) {
global $config; global $config;
$current = $config->get_string($name); $current = $config->get_string($name);
@ -181,12 +150,7 @@ class SetupBlock extends Block {
$this->body .= $html; $this->body .= $html;
} }
/** public function add_multichoice_option(string $name, array $options, string $label=null) {
* @param string $name
* @param string[] $options
* @param null|string $label
*/
public function add_multichoice_option($name, $options, $label=null) {
global $config; global $config;
$current = $config->get_array($name); $current = $config->get_array($name);

View file

@ -127,12 +127,7 @@ class ShimmieApi extends Extension {
return $res; return $res;
} }
/** private function api_get_user(string $type, string $query): array {
* @param string $type
* @param string $query
* @return array
*/
private function api_get_user($type, $query) {
global $database; global $database;
$all = $database->get_row( $all = $database->get_row(
"SELECT id, name, joindate, class FROM users WHERE $type=?", "SELECT id, name, joindate, class FROM users WHERE $type=?",

View file

@ -122,8 +122,8 @@ class XMLSitemap extends Extension
* @param string $priority * @param string $priority
* @param string $date * @param string $date
*/ */
private function add_sitemap_queue( /*array(urls)*/ $urls, $changefreq = "monthly", private function add_sitemap_queue(array $urls, $changefreq = "monthly",
$priority = "0.5", $date = "2013-02-01") $priority = "0.5", $date = "2013-02-01")
{ {
foreach ($urls as $url) { foreach ($urls as $url) {
$link = make_http(make_link("$url")); $link = make_http(make_link("$url"));

View file

@ -7,7 +7,7 @@
class Source_History extends Extension { class Source_History extends Extension {
// in before source are actually set, so that "get current source" works // in before source are actually set, so that "get current source" works
public function get_priority() {return 40;} public function get_priority(): int {return 40;}
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
@ -207,7 +207,7 @@ class Source_History extends Extension {
* @param int $revert_id * @param int $revert_id
* @return mixed|null * @return mixed|null
*/ */
public function get_source_history_from_revert(/*int*/ $revert_id) { public function get_source_history_from_revert(int $revert_id) {
global $database; global $database;
$row = $database->get_row(" $row = $database->get_row("
SELECT source_histories.*, users.name SELECT source_histories.*, users.name
@ -221,7 +221,7 @@ class Source_History extends Extension {
* @param int $image_id * @param int $image_id
* @return array * @return array
*/ */
public function get_source_history_from_id(/*int*/ $image_id) { public function get_source_history_from_id(int $image_id) {
global $database; global $database;
$row = $database->get_all(" $row = $database->get_all("
SELECT source_histories.*, users.name SELECT source_histories.*, users.name

View file

@ -7,7 +7,7 @@ class Source_HistoryTheme extends Themelet {
* @param int $image_id * @param int $image_id
* @param array $history * @param array $history
*/ */
public function display_history_page(Page $page, /*int*/ $image_id, /*array*/ $history) { public function display_history_page(Page $page, int $image_id, array $history) {
global $user; global $user;
$start_string = " $start_string = "
<div style='text-align: left'> <div style='text-align: left'>
@ -60,7 +60,7 @@ class Source_HistoryTheme extends Themelet {
* @param array $history * @param array $history
* @param int $page_number * @param int $page_number
*/ */
public function display_global_page(Page $page, /*array*/ $history, /*int*/ $page_number) { public function display_global_page(Page $page, array $history, int $page_number) {
$start_string = " $start_string = "
<div style='text-align: left'> <div style='text-align: left'>
".make_form(make_link("source_history/revert"))." ".make_form(make_link("source_history/revert"))."
@ -112,7 +112,7 @@ class Source_HistoryTheme extends Themelet {
* Add a section to the admin page. * Add a section to the admin page.
* @param string $validation_msg * @param string $validation_msg
*/ */
public function display_admin_block(/*string*/ $validation_msg='') { public function display_admin_block(string $validation_msg='') {
global $page; global $page;
if (!empty($validation_msg)) { if (!empty($validation_msg)) {
@ -150,7 +150,7 @@ class Source_HistoryTheme extends Themelet {
* @param string $title * @param string $title
* @param string $body * @param string $body
*/ */
public function add_status(/*string*/ $title, /*string*/ $body) { public function add_status(string $title, string $body) {
$this->messages[] = '<p><b>'. $title .'</b><br>'. $body .'</p>'; $this->messages[] = '<p><b>'. $title .'</b><br>'. $body .'</p>';
} }
} }

View file

@ -84,7 +84,7 @@ class StatsDInterface extends Extension {
/** /**
* @return int * @return int
*/ */
public function get_priority() {return 99;} public function get_priority(): int {return 99;}
/** /**
* @param array $data * @param array $data

View file

@ -52,10 +52,6 @@ class OwnerSetEvent extends Event {
/** @var \User */ /** @var \User */
public $owner; public $owner;
/**
* @param Image $image
* @param User $owner
*/
public function __construct(Image $image, User $owner) { public function __construct(Image $image, User $owner) {
$this->image = $image; $this->image = $image;
$this->owner = $owner; $this->owner = $owner;
@ -63,35 +59,19 @@ class OwnerSetEvent extends Event {
} }
/*
* SourceSetEvent:
* $image_id
* $source
*
*/
class SourceSetEvent extends Event { class SourceSetEvent extends Event {
/** @var \Image */ /** @var \Image */
public $image; public $image;
/** @var string */ /** @var string */
public $source; public $source;
/** public function __construct(Image $image, string $source=null) {
* @param Image $image
* @param string $source
*/
public function __construct(Image $image, $source) {
$this->image = $image; $this->image = $image;
$this->source = $source; $this->source = $source;
} }
} }
/*
* TagSetEvent:
* $image_id
* $tags
*
*/
class TagSetEvent extends Event { class TagSetEvent extends Event {
/** @var \Image */ /** @var \Image */
public $image; public $image;
@ -135,13 +115,7 @@ class LockSetEvent extends Event {
/** @var bool */ /** @var bool */
public $locked; public $locked;
/** public function __construct(Image $image, bool $locked) {
* @param Image $image
* @param bool $locked
*/
public function __construct(Image $image, $locked) {
assert('is_bool($locked)');
$this->image = $image; $this->image = $image;
$this->locked = $locked; $this->locked = $locked;
} }
@ -159,25 +133,13 @@ class TagTermParseEvent extends Event {
/** @var bool */ /** @var bool */
public $parse = TRUE; //marks the tag to be parsed, and not just checked if valid metatag public $parse = TRUE; //marks the tag to be parsed, and not just checked if valid metatag
/** public function __construct(string $term, int $id, bool $parse) {
* @param string $term
* @param int $id
* @param bool $parse
*/
public function __construct($term, $id, $parse) {
assert('is_string($term)');
assert('is_int($id)');
assert('is_bool($parse)');
$this->term = $term; $this->term = $term;
$this->id = $id; $this->id = $id;
$this->parse = $parse; $this->parse = $parse;
} }
/** public function is_metatag(): bool {
* @return bool
*/
public function is_metatag() {
return $this->metatag; return $this->metatag;
} }
} }

View file

@ -19,7 +19,7 @@ class TagEditTheme extends Themelet {
$page->add_block(new Block("Mass Tag Edit", $html)); $page->add_block(new Block("Mass Tag Edit", $html));
} }
public function mss_html($terms) { public function mss_html($terms): string {
$h_terms = html_escape($terms); $h_terms = html_escape($terms);
$html = make_form(make_link("tag_edit/mass_source_set"), "POST") . " $html = make_form(make_link("tag_edit/mass_source_set"), "POST") . "
<input type='hidden' name='tags' value='$h_terms'> <input type='hidden' name='tags' value='$h_terms'>
@ -30,7 +30,7 @@ class TagEditTheme extends Themelet {
return $html; return $html;
} }
public function get_tag_editor_html(Image $image) { public function get_tag_editor_html(Image $image): string {
global $user; global $user;
$tag_links = array(); $tag_links = array();
@ -58,7 +58,7 @@ class TagEditTheme extends Themelet {
"; ";
} }
public function get_user_editor_html(Image $image) { public function get_user_editor_html(Image $image): string {
global $user; global $user;
$h_owner = html_escape($image->get_owner()->name); $h_owner = html_escape($image->get_owner()->name);
$h_av = $image->get_owner()->get_avatar_html(); $h_av = $image->get_owner()->get_avatar_html();
@ -80,7 +80,7 @@ class TagEditTheme extends Themelet {
"; ";
} }
public function get_source_editor_html(Image $image) { public function get_source_editor_html(Image $image): string {
global $user; global $user;
$h_source = html_escape($image->get_source()); $h_source = html_escape($image->get_source());
$f_source = $this->format_source($image->get_source()); $f_source = $this->format_source($image->get_source());
@ -100,11 +100,7 @@ class TagEditTheme extends Themelet {
"; ";
} }
/** protected function format_source(string $source=null): string {
* @param string $source
* @return string
*/
protected function format_source(/*string*/ $source) {
if(!empty($source)) { if(!empty($source)) {
if(!startsWith($source, "http://") && !startsWith($source, "https://")) { if(!startsWith($source, "http://") && !startsWith($source, "https://")) {
$source = "http://" . $source; $source = "http://" . $source;
@ -120,7 +116,7 @@ class TagEditTheme extends Themelet {
return "Unknown"; return "Unknown";
} }
public function get_lock_editor_html(Image $image) { public function get_lock_editor_html(Image $image): string {
global $user; global $user;
$b_locked = $image->is_locked() ? "Yes (Only admins may edit these details)" : "No"; $b_locked = $image->is_locked() ? "Yes (Only admins may edit these details)" : "No";
$h_locked = $image->is_locked() ? " checked" : ""; $h_locked = $image->is_locked() ? " checked" : "";

View file

@ -7,7 +7,7 @@
class Tag_History extends Extension { class Tag_History extends Extension {
// in before tags are actually set, so that "get current tags" works // in before tags are actually set, so that "get current tags" works
public function get_priority() {return 40;} public function get_priority(): int {return 40;}
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
@ -206,7 +206,7 @@ class Tag_History extends Extension {
* @param int $revert_id * @param int $revert_id
* @return mixed|null * @return mixed|null
*/ */
public function get_tag_history_from_revert(/*int*/ $revert_id) { public function get_tag_history_from_revert(int $revert_id) {
global $database; global $database;
$row = $database->get_row(" $row = $database->get_row("
SELECT tag_histories.*, users.name SELECT tag_histories.*, users.name
@ -220,7 +220,7 @@ class Tag_History extends Extension {
* @param int $image_id * @param int $image_id
* @return array * @return array
*/ */
public function get_tag_history_from_id(/*int*/ $image_id) { public function get_tag_history_from_id(int $image_id) {
global $database; global $database;
$row = $database->get_all(" $row = $database->get_all("
SELECT tag_histories.*, users.name SELECT tag_histories.*, users.name

View file

@ -12,7 +12,7 @@ class Tag_HistoryTheme extends Themelet {
* @param int $image_id * @param int $image_id
* @param array $history * @param array $history
*/ */
public function display_history_page(Page $page, /*int*/ $image_id, /*array*/ $history) { public function display_history_page(Page $page, int $image_id, array $history) {
global $user; global $user;
$start_string = " $start_string = "
<div style='text-align: left'> <div style='text-align: left'>
@ -72,7 +72,7 @@ class Tag_HistoryTheme extends Themelet {
* @param array $history * @param array $history
* @param int $page_number * @param int $page_number
*/ */
public function display_global_page(Page $page, /*array*/ $history, /*int*/ $page_number) { public function display_global_page(Page $page, array $history, int $page_number) {
$start_string = " $start_string = "
<div style='text-align: left'> <div style='text-align: left'>
".make_form(make_link("tag_history/revert"))." ".make_form(make_link("tag_history/revert"))."
@ -125,7 +125,7 @@ class Tag_HistoryTheme extends Themelet {
* *
* @param string $validation_msg * @param string $validation_msg
*/ */
public function display_admin_block(/*string*/ $validation_msg='') { public function display_admin_block(string $validation_msg='') {
global $page; global $page;
if (!empty($validation_msg)) { if (!empty($validation_msg)) {
@ -163,7 +163,7 @@ class Tag_HistoryTheme extends Themelet {
* @param string $title * @param string $title
* @param string $body * @param string $body
*/ */
public function add_status(/*string*/ $title, /*string*/ $body) { public function add_status(string $title, string $body) {
$this->messages[] = '<p><b>'. $title .'</b><br>'. $body .'</p>'; $this->messages[] = '<p><b>'. $title .'</b><br>'. $body .'</p>';
} }
} }

View file

@ -137,7 +137,7 @@ class TagList extends Extension {
* @param string $tag * @param string $tag
* @return string * @return string
*/ */
private function tag_link(/*string*/ $tag) { private function tag_link(string $tag) {
$u_tag = url_escape($tag); $u_tag = url_escape($tag);
return make_link("post/list/$u_tag/1"); return make_link("post/list/$u_tag/1");
} }

View file

@ -241,14 +241,7 @@ class TagListTheme extends Themelet {
return array($category, $display_html); return array($category, $display_html);
} }
/** protected function ars(string $tag, array $tags): string {
* @param string $tag
* @param string[] $tags
* @return string
*/
protected function ars(/*string*/ $tag, /*array(string)*/ $tags) {
assert(is_array($tags));
// FIXME: a better fix would be to make sure the inputs are correct // FIXME: a better fix would be to make sure the inputs are correct
$tag = strtolower($tag); $tag = strtolower($tag);
$tags = array_map("strtolower", $tags); $tags = array_map("strtolower", $tags);
@ -261,12 +254,7 @@ class TagListTheme extends Themelet {
return $html; return $html;
} }
/** protected function get_remove_link(array $tags, string $tag): string {
* @param array $tags
* @param string $tag
* @return string
*/
protected function get_remove_link($tags, $tag) {
if(!in_array($tag, $tags) && !in_array("-$tag", $tags)) { if(!in_array($tag, $tags) && !in_array("-$tag", $tags)) {
return ""; return "";
} }
@ -277,12 +265,7 @@ class TagListTheme extends Themelet {
} }
} }
/** protected function get_add_link(array $tags, string $tag): string {
* @param array $tags
* @param string $tag
* @return string
*/
protected function get_add_link($tags, $tag) {
if(in_array($tag, $tags)) { if(in_array($tag, $tags)) {
return ""; return "";
} }
@ -293,12 +276,7 @@ class TagListTheme extends Themelet {
} }
} }
/** protected function get_subtract_link(array $tags, string $tag): string {
* @param array $tags
* @param string $tag
* @return string
*/
protected function get_subtract_link($tags, $tag) {
if(in_array("-$tag", $tags)) { if(in_array("-$tag", $tags)) {
return ""; return "";
} }
@ -309,11 +287,7 @@ class TagListTheme extends Themelet {
} }
} }
/** protected function tag_link(string $tag): string {
* @param string $tag
* @return string
*/
protected function tag_link($tag) {
$u_tag = url_escape($tag); $u_tag = url_escape($tag);
return make_link("post/list/$u_tag/1"); return make_link("post/list/$u_tag/1");
} }

View file

@ -29,7 +29,7 @@ class Tagger extends Extension {
// Tagger AJAX back-end // Tagger AJAX back-end
class TaggerXML extends Extension { class TaggerXML extends Extension {
public function get_priority() {return 10;} public function get_priority(): int {return 10;}
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
if($event->page_matches("tagger/tags")) { if($event->page_matches("tagger/tags")) {

View file

@ -134,10 +134,7 @@ class Tips extends Extension {
$this->theme->showAll($url, $tips); $this->theme->showAll($url, $tips);
} }
/** private function setStatus(int $tipID) {
* @param int $tipID
*/
private function setStatus($tipID) {
global $database; global $database;
$tip = $database->get_row("SELECT * FROM tips WHERE id = ? ", array(int_escape($tipID))); $tip = $database->get_row("SELECT * FROM tips WHERE id = ? ", array(int_escape($tipID)));
@ -151,10 +148,7 @@ class Tips extends Extension {
$database->execute("UPDATE tips SET enable = ? WHERE id = ?", array ($enable, int_escape($tipID))); $database->execute("UPDATE tips SET enable = ? WHERE id = ?", array ($enable, int_escape($tipID)));
} }
/** private function deleteTip(int $tipID) {
* @param int $tipID
*/
private function deleteTip($tipID) {
global $database; global $database;
$database->execute("DELETE FROM tips WHERE id = ?", array(int_escape($tipID))); $database->execute("DELETE FROM tips WHERE id = ?", array(int_escape($tipID)));
} }

View file

@ -129,7 +129,9 @@ class Upgrade extends Extension {
} }
} }
/** @return int */ /**
public function get_priority() {return 5;} * @return int
*/
public function get_priority(): int {return 5;}
} }

View file

@ -28,7 +28,7 @@ class DataUploadEvent extends Event {
* @param string $tmpname The temporary file used for upload. * @param string $tmpname The temporary file used for upload.
* @param array $metadata Info about the file, should contain at least "filename", "extension", "tags" and "source". * @param array $metadata Info about the file, should contain at least "filename", "extension", "tags" and "source".
*/ */
public function __construct(/*string*/ $tmpname, /*array*/ $metadata) { public function __construct(string $tmpname, array $metadata) {
assert('file_exists($tmpname)'); assert('file_exists($tmpname)');
assert('is_string($metadata["filename"])'); assert('is_string($metadata["filename"])');
assert('is_string($metadata["extension"])'); assert('is_string($metadata["extension"])');
@ -60,16 +60,15 @@ class Upload extends Extension {
/** /**
* Early, so it can stop the DataUploadEvent before any data handlers see it. * Early, so it can stop the DataUploadEvent before any data handlers see it.
*
* @return int * @return int
*/ */
public function get_priority() {return 40;} public function get_priority(): int {return 40;}
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_int('upload_count', 3); $config->set_default_int('upload_count', 3);
$config->set_default_int('upload_size', '1MB'); $config->set_default_int('upload_size', parse_shorthand_int('1MB'));
$config->set_default_int('upload_min_free_space', '100MB'); $config->set_default_int('upload_min_free_space', parse_shorthand_int('100MB'));
$config->set_default_bool('upload_tlsource', TRUE); $config->set_default_bool('upload_tlsource', TRUE);
$this->is_full = false; $this->is_full = false;

View file

@ -248,7 +248,7 @@ class UploadTheme extends Themelet {
* @param Page $page * @param Page $page
* @param int $image_id * @param int $image_id
*/ */
public function display_replace_page(Page $page, /*int*/ $image_id) { public function display_replace_page(Page $page, int $image_id) {
global $config, $page; global $config, $page;
$tl_enabled = ($config->get_string("transload_engine", "none") != "none"); $tl_enabled = ($config->get_string("transload_engine", "none") != "none");
@ -295,7 +295,7 @@ class UploadTheme extends Themelet {
* @param Page $page * @param Page $page
* @param bool $ok * @param bool $ok
*/ */
public function display_upload_status(Page $page, /*bool*/ $ok) { public function display_upload_status(Page $page, bool $ok) {
if($ok) { if($ok) {
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link()); $page->set_redirect(make_link());
@ -312,7 +312,7 @@ class UploadTheme extends Themelet {
* @param string $title * @param string $title
* @param string $message * @param string $message
*/ */
public function display_upload_error(Page $page, /*string*/ $title, /*string*/ $message) { public function display_upload_error(Page $page, string $title, string $message) {
$page->add_block(new Block($title, $message)); $page->add_block(new Block($title, $message));
} }

View file

@ -9,12 +9,7 @@ class UserBlockBuildingEvent extends Event {
/** @var array */ /** @var array */
public $parts = array(); public $parts = array();
/** public function add_link(string $name, string $link, int $position=50) {
* @param string $name
* @param string $link
* @param int $position
*/
public function add_link($name, $link, $position=50) {
while(isset($this->parts[$position])) $position++; while(isset($this->parts[$position])) $position++;
$this->parts[$position] = array("name" => $name, "link" => $link); $this->parts[$position] = array("name" => $name, "link" => $link);
} }
@ -26,18 +21,11 @@ class UserPageBuildingEvent extends Event {
/** @var array */ /** @var array */
public $stats = array(); public $stats = array();
/**
* @param User $display_user
*/
public function __construct(User $display_user) { public function __construct(User $display_user) {
$this->display_user = $display_user; $this->display_user = $display_user;
} }
/** public function add_stats(string $html, int $position=50) {
* @param string $html
* @param int $position
*/
public function add_stats($html, $position=50) {
while(isset($this->stats[$position])) { $position++; } while(isset($this->stats[$position])) { $position++; }
$this->stats[$position] = $html; $this->stats[$position] = $html;
} }
@ -51,12 +39,7 @@ class UserCreationEvent extends Event {
/** @var string */ /** @var string */
public $email; public $email;
/** public function __construct(string $name, string $pass, string $email) {
* @param string $name
* @param string $pass
* @param string $email
*/
public function __construct($name, $pass, $email) {
$this->username = $name; $this->username = $name;
$this->password = $pass; $this->password = $pass;
$this->email = $email; $this->email = $email;
@ -67,10 +50,7 @@ class UserDeletionEvent extends Event {
/** @var int */ /** @var int */
public $id; public $id;
/** public function __construct(int $id) {
* @param int $id
*/
public function __construct($id) {
$this->id = $id; $this->id = $id;
} }
} }
@ -207,9 +187,6 @@ class UserPage extends Extension {
} }
} }
/**
* @param UserPageBuildingEvent $event
*/
public function onUserPageBuilding(UserPageBuildingEvent $event) { public function onUserPageBuilding(UserPageBuildingEvent $event) {
global $user, $config; global $user, $config;
@ -240,9 +217,6 @@ class UserPage extends Extension {
} }
} }
/**
* @param UserPageBuildingEvent $event
*/
private function display_stats(UserPageBuildingEvent $event) { private function display_stats(UserPageBuildingEvent $event) {
global $user, $page, $config; global $user, $page, $config;
@ -265,9 +239,6 @@ class UserPage extends Extension {
} }
} }
/**
* @param SetupBuildingEvent $event
*/
public function onSetupBuilding(SetupBuildingEvent $event) { public function onSetupBuilding(SetupBuildingEvent $event) {
global $config; global $config;
@ -303,9 +274,6 @@ class UserPage extends Extension {
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
/**
* @param UserBlockBuildingEvent $event
*/
public function onUserBlockBuilding(UserBlockBuildingEvent $event) { public function onUserBlockBuilding(UserBlockBuildingEvent $event) {
global $user; global $user;
$event->add_link("My Profile", make_link("user")); $event->add_link("My Profile", make_link("user"));
@ -315,17 +283,11 @@ class UserPage extends Extension {
$event->add_link("Log Out", make_link("user_admin/logout"), 99); $event->add_link("Log Out", make_link("user_admin/logout"), 99);
} }
/**
* @param UserCreationEvent $event
*/
public function onUserCreation(UserCreationEvent $event) { public function onUserCreation(UserCreationEvent $event) {
$this->check_user_creation($event); $this->check_user_creation($event);
$this->create_user($event); $this->create_user($event);
} }
/**
* @param SearchTermParseEvent $event
*/
public function onSearchTermParse(SearchTermParseEvent $event) { public function onSearchTermParse(SearchTermParseEvent $event) {
global $user; global $user;
@ -418,10 +380,7 @@ class UserPage extends Extension {
} }
} }
/** private function page_recover(string $username) {
* @param string $username
*/
private function page_recover($username) {
$user = User::by_name($username); $user = User::by_name($username);
if (is_null($user)) { if (is_null($user)) {
$this->theme->display_error(404, "Error", "There's no user with that name"); $this->theme->display_error(404, "Error", "There's no user with that name");
@ -457,10 +416,6 @@ class UserPage extends Extension {
} }
} }
/**
* @param UserCreationEvent $event
* @throws UserCreationException
*/
private function check_user_creation(UserCreationEvent $event) { private function check_user_creation(UserCreationEvent $event) {
$name = $event->username; $name = $event->username;
//$pass = $event->password; //$pass = $event->password;
@ -497,11 +452,7 @@ class UserPage extends Extension {
log_info("user", "Created User #$uid ({$event->username})"); log_info("user", "Created User #$uid ({$event->username})");
} }
/** private function set_login_cookie(string $name, string $pass) {
* @param string $name
* @param string $pass
*/
private function set_login_cookie(/*string*/ $name, /*string*/ $pass) {
global $config, $page; global $config, $page;
$addr = get_session_ip($config); $addr = get_session_ip($config);
@ -514,12 +465,7 @@ class UserPage extends Extension {
} }
//}}} //}}}
// Things done *to* the user {{{ // Things done *to* the user {{{
/** private function user_can_edit_user(User $a, User $b): bool {
* @param User $a
* @param User $b
* @return bool
*/
private function user_can_edit_user(User $a, User $b) {
if($a->is_anonymous()) { if($a->is_anonymous()) {
$this->theme->display_error(401, "Error", "You aren't logged in"); $this->theme->display_error(401, "Error", "You aren't logged in");
return false; return false;
@ -565,12 +511,7 @@ class UserPage extends Extension {
} }
} }
/** private function change_password_wrapper(User $duser, string $pass1, string $pass2) {
* @param User $duser
* @param string $pass1
* @param string $pass2
*/
private function change_password_wrapper(User $duser, $pass1, $pass2) {
global $user; global $user;
if($this->user_can_edit_user($user, $duser)) { if($this->user_can_edit_user($user, $duser)) {
@ -591,11 +532,7 @@ class UserPage extends Extension {
} }
} }
/** private function change_email_wrapper(User $duser, string $address) {
* @param User $duser
* @param string $address
*/
private function change_email_wrapper(User $duser, /*string(email)*/ $address) {
global $user; global $user;
if($this->user_can_edit_user($user, $duser)) { if($this->user_can_edit_user($user, $duser)) {
@ -606,12 +543,7 @@ class UserPage extends Extension {
} }
} }
/** private function change_class_wrapper(User $duser, string $class) {
* @param User $duser
* @param string $class
* @throws NullUserException
*/
private function change_class_wrapper(User $duser, /*string(class)*/ $class) {
global $user; global $user;
if($user->class->name == "admin") { if($user->class->name == "admin") {
@ -622,11 +554,7 @@ class UserPage extends Extension {
} }
// }}} // }}}
// ips {{{ // ips {{{
/** private function count_upload_ips(User $duser): array {
* @param User $duser
* @return array
*/
private function count_upload_ips(User $duser) {
global $database; global $database;
$rows = $database->get_pairs(" $rows = $database->get_pairs("
SELECT SELECT
@ -640,11 +568,7 @@ class UserPage extends Extension {
return $rows; return $rows;
} }
/** private function count_comment_ips(User $duser): array {
* @param User $duser
* @return array
*/
private function count_comment_ips(User $duser) {
global $database; global $database;
$rows = $database->get_pairs(" $rows = $database->get_pairs("
SELECT SELECT
@ -658,12 +582,7 @@ class UserPage extends Extension {
return $rows; return $rows;
} }
/** private function delete_user(Page $page, bool $with_images=false, bool $with_comments=false) {
* @param Page $page
* @param bool $with_images
* @param bool $with_comments
*/
private function delete_user(Page $page, /*boolean*/ $with_images=false, /*boolean*/ $with_comments=false) {
global $user, $config, $database; global $user, $config, $database;
$page->set_title("Error"); $page->set_title("Error");

View file

@ -14,7 +14,7 @@ class UserPageTheme extends Themelet {
* @param User[] $users * @param User[] $users
* @param User $user * @param User $user
*/ */
public function display_user_list(Page $page, $users, User $user) { public function display_user_list(Page $page, array $users, User $user) {
$page->set_title("User List"); $page->set_title("User List");
$page->set_heading("User List"); $page->set_heading("User List");
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
@ -148,12 +148,7 @@ class UserPageTheme extends Themelet {
$page->add_block(new Block("Login", $html, "left", 90)); $page->add_block(new Block("Login", $html, "left", 90));
} }
/** public function display_ip_list(Page $page, array $uploads, array $comments) {
* @param Page $page
* @param array $uploads
* @param array $comments
*/
public function display_ip_list(Page $page, $uploads, $comments) {
$html = "<table id='ip-history'>"; $html = "<table id='ip-history'>";
$html .= "<tr><td>Uploaded from: "; $html .= "<tr><td>Uploaded from: ";
$n = 0; $n = 0;

View file

@ -38,5 +38,5 @@ class VarnishPurger extends Extension {
/** /**
* @return int * @return int
*/ */
public function get_priority() {return 99;} public function get_priority(): int {return 99;}
} }

View file

@ -17,19 +17,12 @@
class DisplayingImageEvent extends Event { class DisplayingImageEvent extends Event {
/** @var \Image */ /** @var \Image */
public $image; public $image;
public $page, $context;
/**
* @param Image $image
*/
public function __construct(Image $image) { public function __construct(Image $image) {
$this->image = $image; $this->image = $image;
} }
/** public function get_image(): Image {
* @return Image
*/
public function get_image() {
return $this->image; return $this->image;
} }
} }
@ -42,20 +35,12 @@ class ImageInfoBoxBuildingEvent extends Event {
/** @var \User */ /** @var \User */
public $user; public $user;
/**
* @param Image $image
* @param User $user
*/
public function __construct(Image $image, User $user) { public function __construct(Image $image, User $user) {
$this->image = $image; $this->image = $image;
$this->user = $user; $this->user = $user;
} }
/** public function add_part(string $html, int $position=50) {
* @param string $html
* @param int $position
*/
public function add_part($html, $position=50) {
while(isset($this->parts[$position])) $position++; while(isset($this->parts[$position])) $position++;
$this->parts[$position] = $html; $this->parts[$position] = $html;
} }
@ -65,9 +50,6 @@ class ImageInfoSetEvent extends Event {
/** @var \Image */ /** @var \Image */
public $image; public $image;
/**
* @param Image $image
*/
public function __construct(Image $image) { public function __construct(Image $image) {
$this->image = $image; $this->image = $image;
} }
@ -81,20 +63,12 @@ class ImageAdminBlockBuildingEvent extends Event {
/** @var null|\User */ /** @var null|\User */
public $user = null; public $user = null;
/**
* @param Image $image
* @param User $user
*/
public function __construct(Image $image, User $user) { public function __construct(Image $image, User $user) {
$this->image = $image; $this->image = $image;
$this->user = $user; $this->user = $user;
} }
/** public function add_part(string $html, int $position=50) {
* @param string $html
* @param int $position
*/
public function add_part(/*string*/ $html, /*int*/ $position=50) {
while(isset($this->parts[$position])) $position++; while(isset($this->parts[$position])) $position++;
$this->parts[$position] = $html; $this->parts[$position] = $html;
} }

View file

@ -14,10 +14,6 @@ class WikiUpdateEvent extends Event {
/** @var \WikiPage */ /** @var \WikiPage */
public $wikipage; public $wikipage;
/**
* @param User $user
* @param WikiPage $wikipage
*/
public function __construct(User $user, WikiPage $wikipage) { public function __construct(User $user, WikiPage $wikipage) {
$this->user = $user; $this->user = $user;
$this->wikipage = $wikipage; $this->wikipage = $wikipage;
@ -52,10 +48,7 @@ class WikiPage {
/** @var string */ /** @var string */
public $body; public $body;
/** public function __construct(array $row=null) {
* @param mixed $row
*/
public function __construct($row=null) {
//assert(!empty($row)); //assert(!empty($row));
if (!is_null($row)) { if (!is_null($row)) {
@ -77,10 +70,7 @@ class WikiPage {
return User::by_id($this->owner_id); return User::by_id($this->owner_id);
} }
/** public function is_locked(): bool {
* @return bool
*/
public function is_locked() {
return $this->locked; return $this->locked;
} }
} }
@ -205,7 +195,7 @@ class Wiki extends Extension {
* @param WikiPage $page * @param WikiPage $page
* @return bool * @return bool
*/ */
public static function can_edit(User $user, WikiPage $page) { public static function can_edit(User $user, WikiPage $page): bool {
// admins can edit everything // admins can edit everything
if($user->is_admin()) return true; if($user->is_admin()) return true;
@ -218,12 +208,7 @@ class Wiki extends Extension {
return false; return false;
} }
/** private function get_page(string $title, int $revision=-1): WikiPage {
* @param string $title
* @param integer $revision
* @return WikiPage
*/
private function get_page($title, $revision=-1) {
global $database; global $database;
// first try and get the actual page // first try and get the actual page
$row = $database->get_row($database->scoreql_to_sql(" $row = $database->get_row($database->scoreql_to_sql("

View file

@ -8,7 +8,7 @@ class WikiTheme extends Themelet {
* @param WikiPage $wiki_page The wiki page, has ->title and ->body * @param WikiPage $wiki_page The wiki page, has ->title and ->body
* @param WikiPage|null $nav_page A wiki page object with navigation, has ->body * @param WikiPage|null $nav_page A wiki page object with navigation, has ->body
*/ */
public function display_page(Page $page, WikiPage $wiki_page, $nav_page) { public function display_page(Page $page, WikiPage $wiki_page, WikiPage $nav_page=null) {
global $user; global $user;
if(is_null($nav_page)) { if(is_null($nav_page)) {

View file

@ -9,7 +9,7 @@
class WordFilter extends Extension { class WordFilter extends Extension {
// before emoticon filter // before emoticon filter
public function get_priority() {return 40;} public function get_priority(): int {return 40;}
public function onTextFormatting(TextFormattingEvent $event) { public function onTextFormatting(TextFormattingEvent $event) {
$event->formatted = $this->filter($event->formatted); $event->formatted = $this->filter($event->formatted);
@ -27,7 +27,7 @@ class WordFilter extends Extension {
* @param string $text * @param string $text
* @return string * @return string
*/ */
private function filter(/*string*/ $text) { private function filter(string $text) {
$map = $this->get_map(); $map = $this->get_map();
foreach($map as $search => $replace) { foreach($map as $search => $replace) {
$search = trim($search); $search = trim($search);

View file

@ -114,10 +114,7 @@ do_install();
// utilities {{{ // utilities {{{
// TODO: Can some of these be pushed into "core/util.inc.php" ? // TODO: Can some of these be pushed into "core/util.inc.php" ?
/** function check_gd_version(): int {
* @return int
*/
function check_gd_version() {
$gdversion = 0; $gdversion = 0;
if (function_exists('gd_info')){ if (function_exists('gd_info')){
@ -132,10 +129,7 @@ function check_gd_version() {
return $gdversion; return $gdversion;
} }
/** function check_im_version(): int {
* @return int
*/
function check_im_version() {
$convert_check = exec("convert"); $convert_check = exec("convert");
return (empty($convert_check) ? 0 : 1); return (empty($convert_check) ? 0 : 1);
@ -475,13 +469,7 @@ EOD;
echo "\n"; echo "\n";
} // }}} } // }}}
/** function handle_db_errors(bool $isPDO, string $errorMessage1, string $errorMessage2, int $exitCode) {
* @param boolean $isPDO
* @param string $errorMessage1
* @param string $errorMessage2
* @param integer $exitCode
*/
function handle_db_errors(/*bool*/ $isPDO, /*str*/ $errorMessage1, /*str*/ $errorMessage2, /*int*/ $exitCode) {
$errorMessage1Extra = ($isPDO ? "Please check and ensure that the database configuration options are all correct." : "Please check the server log files for more information."); $errorMessage1Extra = ($isPDO ? "Please check and ensure that the database configuration options are all correct." : "Please check the server log files for more information.");
print <<<EOD print <<<EOD
<div id="installer"> <div id="installer">

View file

@ -66,25 +66,22 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase {
} }
// page things // page things
protected function assert_title($title) { protected function assert_title(string $title) {
global $page; global $page;
$this->assertContains($title, $page->title); $this->assertContains($title, $page->title);
} }
protected function assert_no_title($title) { protected function assert_no_title(string $title) {
global $page; global $page;
$this->assertNotContains($title, $page->title); $this->assertNotContains($title, $page->title);
} }
/** protected function assert_response(int $code) {
* @param integer $code
*/
protected function assert_response($code) {
global $page; global $page;
$this->assertEquals($code, $page->code); $this->assertEquals($code, $page->code);
} }
protected function page_to_text($section=null) { protected function page_to_text(string $section=null) {
global $page; global $page;
$text = $page->title . "\n"; $text = $page->title . "\n";
foreach($page->blocks as $block) { foreach($page->blocks as $block) {
@ -96,29 +93,20 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase {
return $text; return $text;
} }
protected function assert_text($text, $section=null) { protected function assert_text(string $text, string $section=null) {
$this->assertContains($text, $this->page_to_text($section)); $this->assertContains($text, $this->page_to_text($section));
} }
/** protected function assert_no_text(string $text, string $section=null) {
* @param string $text
*/
protected function assert_no_text($text, $section=null) {
$this->assertNotContains($text, $this->page_to_text($section)); $this->assertNotContains($text, $this->page_to_text($section));
} }
/** protected function assert_content(string $content) {
* @param string $content
*/
protected function assert_content($content) {
global $page; global $page;
$this->assertContains($content, $page->data); $this->assertContains($content, $page->data);
} }
/** protected function assert_no_content(string $content) {
* @param string $content
*/
protected function assert_no_content($content) {
global $page; global $page;
$this->assertNotContains($content, $page->data); $this->assertNotContains($content, $page->data);
} }
@ -143,12 +131,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase {
} }
// post things // post things
/** protected function post_image(string $filename, string $tags): int {
* @param string $filename
* @param string $tags
* @return int
*/
protected function post_image($filename, $tags) {
$dae = new DataUploadEvent($filename, array( $dae = new DataUploadEvent($filename, array(
"filename" => $filename, "filename" => $filename,
"extension" => pathinfo($filename, PATHINFO_EXTENSION), "extension" => pathinfo($filename, PATHINFO_EXTENSION),
@ -160,10 +143,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase {
return $dae->image_id; return $dae->image_id;
} }
/** protected function delete_image(int $image_id) {
* @param int $image_id
*/
protected function delete_image($image_id) {
$img = Image::by_id($image_id); $img = Image::by_id($image_id);
if($img) { if($img) {
$ide = new ImageDeletionEvent($img); $ide = new ImageDeletionEvent($img);

View file

@ -6,7 +6,7 @@ class CustomExtManagerTheme extends ExtManagerTheme {
* @param array $extensions * @param array $extensions
* @param bool $editable * @param bool $editable
*/ */
public function display_table(Page $page, /*array*/ $extensions, /*bool*/ $editable) { public function display_table(Page $page, array $extensions, bool $editable) {
$page->disable_left(); $page->disable_left();
parent::display_table($page, $extensions, $editable); parent::display_table($page, $extensions, $editable);
} }

View file

@ -25,7 +25,7 @@ EOD
); );
} }
public function build_body(/*string*/ $sitename, /*string*/ $main_links, /*string*/ $main_text, /*string*/ $contact_link, $num_comma, /*string*/ $counter_text) { public function build_body(string $sitename, string $main_links, string $main_text, string $contact_link, $num_comma, string $counter_text) {
$message_html = empty($main_text) ? "" : "<div class='space' id='message'>$main_text</div>"; $message_html = empty($main_text) ? "" : "<div class='space' id='message'>$main_text</div>";
$counter_html = empty($counter_text) ? "" : "<div class='mdl-typography--text-center' id='counter'>$counter_text</div>"; $counter_html = empty($counter_text) ? "" : "<div class='mdl-typography--text-center' id='counter'>$counter_text</div>";
$contact_link = empty($contact_link) ? "" : "<br><a href='mailto:$contact_link'>Contact</a> -"; $contact_link = empty($contact_link) ? "" : "<br><a href='mailto:$contact_link'>Contact</a> -";