diff --git a/README.markdown b/README.markdown new file mode 100644 index 00000000..125e4337 --- /dev/null +++ b/README.markdown @@ -0,0 +1,149 @@ +``` + _________.__ .__ .__ ________ + / _____/| |__ |__| _____ _____ |__| ____ \_____ \ + \_____ \ | | \ | | / \ / \ | |_/ __ \ / ____/ + / \| Y \| || Y Y \| Y Y \| |\ ___/ / \ + /_______ /|___| /|__||__|_| /|__|_| /|__| \___ >\_______ \ + \/ \/ \/ \/ \/ \/ + +``` + +# Shimmie + +[![Build Status](https://travis-ci.org/shish/shimmie2.svg?branch=master)](https://travis-ci.org/shish/shimmie2) + +This is the main branch of Shimmie, if you know anything at all about running +websites, this is the version to use. + +Alternatively if you want a version that will never have significant changes, +check out one of the versioned branches. + +# Requirements + +- MySQL/MariaDB 5.1+ (with experimental support for PostgreSQL 8+ and SQLite 3) +- PHP 5.3+ +- GD or ImageMagick + +# Installation + +1. Create a blank database +2. Unzip shimmie into a folder on the web host +3. Visit the folder with a web browser +4. Enter the location of the database +5. Click "install". Hopefully you'll end up at the welcome screen; if + not, you should be given instructions on how to fix any errors~ + +## Upgrade from 2.3.X + +1. Backup your current files and database! +2. Unzip into a clean folder +3. Copy across the images, thumbs, and data folders +4. Move `old/config.php` to `new/data/config/shimmie.conf.php` +5. Edit `shimmie.conf.php` to use the new database connection format: + +OLD Format: +```php +$database_dsn = "://:@/"; +``` + +NEW Format: +```php +define("DATABASE_DSN", ":user=;password=;host=;dbname="); +``` + +The rest should be automatic~ + +If there are any errors with the upgrade process, `in_upgrade=true` will +be left in the config table and the process will be paused for the admin +to investigate. + +Deleting this config entry and refreshing the page should continue the upgrade from where it left off. + + +### Upgrade from earlier versions + +I very much recommend going via each major release in turn (eg, 2.0.6 +-> 2.1.3 -> 2.2.4 -> 2.3.0 rather than 2.0.6 -> 2.3.0). + +While the basic database and file formats haven't changed *completely*, it's different +enough to be a pain. + + +## Custom Configuration + +Various aspects of Shimmie can be configured to suit your site specific needs +via the file `data/config/shimmie.conf.php` (created after installation). + +Take a look at `core/sys_config.inc.php` for the available options that can +be used. + + +#### Custom User Classes + +User classes can be added to or altered by placing them in +`data/config/user-classes.conf.php`. + +For example, one can override the default anonymous "allow nothing" permissions like so: + +```php +new UserClass("anonymous", "base", array( + "create_comment" => True, + "edit_image_tag" => True, + "edit_image_source" => True, + "create_image_report" => True, +)); +``` + +For a moderator class, being a regular user who can delete images and comments: + +```php +new UserClass("moderator", "user", array( + "delete_image" => True, + "delete_comment" => True, +)); +``` + +For a list of permissions, see `core/userclass.class.php` + + +# Development Info + +ui-* cookies are for the client-side scripts only; in some configurations +(eg with varnish cache) they will be stripped before they reach the server + +shm-* CSS classes are for javascript to hook into; if you're customising +themes, be careful with these, and avoid styling them, eg: + +- shm-thumb = outermost element of a thumbnail + * data-tags + * data-post-id +- shm-toggler = click this to toggle elements that match the selector + * data-toggle-sel +- shm-unlocker = click this to unlock elements that match the selector + * data-unlock-sel +- shm-clink = a link to a comment, flash the target element when clicked + * data-clink-sel + +Documentation: http://shimmie.shishnet.org/doc/ + +Please tell me if those docs are lacking in any way, so that they can be +improved for the next person who uses them + + +# Contact + +IRC: `#shimmie` on [Freenode](irc.freenode.net) + +Email: webmaster at shishnet.org + +Issue/Bug tracker: http://github.com/shish/shimmie2/issues + + +# Licence + +All code is released under the [GNU GPL Version 2](http://www.gnu.org/licenses/gpl-2.0.html) unless mentioned otherwise. + +If you give shimmie to someone else, you have to give them the source (which should be easy, as PHP +is an interpreted language...). If you want to add customisations to your own +site, then those customisations belong to you, and you can do what you want +with them. diff --git a/README.txt b/README.txt deleted file mode 100644 index de638bec..00000000 --- a/README.txt +++ /dev/null @@ -1,133 +0,0 @@ - - _________.__ .__ .__ ________ - / _____/| |__ |__| _____ _____ |__| ____ \_____ \ - \_____ \ | | \ | | / \ / \ | |_/ __ \ / ____/ - / \| Y \| || Y Y \| Y Y \| |\ ___/ / \ - /_______ /|___| /|__||__|_| /|__|_| /|__| \___ >\_______ \ - \/ \/ \/ \/ \/ \/ - -_________________________________________________________________________ - - -Shimmie Development -~~~~~~~~~~~~~~~~~~~ -This is the main branch of Shimmie, if you know anything at all about -running websites, this is the version to use. Alternatively if you want -a version that will never have significant changes, check out one of the -versioned branches. - - -Requirements -~~~~~~~~~~~~ -MySQL/MariaDB 5.1+ (with experimental support for PostgreSQL 8+ and SQLite 3) -PHP 5.3+ -GD or ImageMagick - - -Installation -~~~~~~~~~~~~ -1) Create a blank database -2) Unzip shimmie into a folder on the web host -3) Visit the folder with a web browser -4) Enter the location of the database -5) Click "install". Hopefully you'll end up at the welcome screen; if - not, you should be given instructions on how to fix any errors~ - - -Upgrade from 2.3.X -~~~~~~~~~~~~~~~~~~ -- Backup your current files and database! -- Unzip into a clean folder -- Copy across the images, thumbs, and data folders -- Move old/config.php to new/data/config/shimmie.conf.php -- Edit shimmie.conf.php to use the new database connection format: - - OLD: $database_dsn = "://:@/"; - NEW: define("DATABASE_DSN", ":user=;password=;host=;dbname="); - -The rest should be automatic~ - -If there are any errors with the upgrade process, "in_upgrade=true" will -be left in the config table and the process will be paused for the admin -to investigate. Deleting this config entry and refreshing the page should -continue the upgrade from where it left off. - - -Upgrade from earlier versions -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -I very much recommend going via each major release in turn (eg, 2.0.6 --> 2.1.3 -> 2.2.4 -> 2.3.0 rather than 2.0.6 -> 2.3.0). While the basic -database and file formats haven't changed *completely*, it's different -enough to be a pain. - - -Custom Configuration -~~~~~~~~~~~~~~~~~~~~ -Various aspects of Shimmie can be configured to suit your site specific needs -via the file "data/config/shimmie.conf.php" (created after installation). -Take a look at "core/sys_config.inc.php" for the available options that can -be used. - - -Custom User Classes -~~~~~~~~~~~~~~~~~~~ -User classes can be added to or altered by placing them in -`data/config/user-classes.conf.php`. For example, one can override the -default anonymous "allow nothing" permissions like so: - -new UserClass("anonymous", "base", array( - "create_comment" => True, - "edit_image_tag" => True, - "edit_image_source" => True, - "create_image_report" => True, -)); - -For a moderator class, being a regular user who can delete images and -comments: - -new UserClass("moderator", "user", array( - "delete_image" => True, - "delete_comment" => True, -)); - -For a list of permissions, see core/userclass.class.php - - -Development Info -~~~~~~~~~~~~~~~~ -ui-* cookies are for the client-side scripts only; in some configurations -(eg with varnish cache) they will be stripped before they reach the server - -shm-* CSS classes are for javascript to hook into; if you're customising -themes, be careful with these, and avoid styling them, eg: - -- shm-thumb = outermost element of a thumbnail - - data-tags - - data-post-id -- shm-toggler = click this to toggle elements that match the selector - - data-toggle-sel -- shm-unlocker = click this to unlock elements that match the selector - - data-unlock-sel -- shm-clink = a link to a comment, flash the target element when clicked - - data-clink-sel - -http://shimmie.shishnet.org/doc/ - -Please tell me if those docs are lacking in any way, so that they can be -improved for the next person who uses them - - -Contact -~~~~~~~ -#shimmie on Freenode -- IRC -webmaster at shishnet.org -- email -https://github.com/shish/shimmie2/issues -- bug tracker - - -Licence -~~~~~~~ -All code is GPLv2 unless mentioned otherwise; ie, if you give shimmie to -someone else, you have to give them the source (which should be easy, as PHP -is an interpreted language...). If you want to add customisations to your own -site, then those customisations belong to you, and you can do what you want -with them. diff --git a/core/block.class.php b/core/block.class.php index bdbc215f..afdb23db 100644 --- a/core/block.class.php +++ b/core/block.class.php @@ -1,17 +1,20 @@ header = $header; @@ -77,9 +82,12 @@ class Block { /** + * Class NavBlock + * * A generic navigation block with a link to the main page. * * Used because "new NavBlock()" is easier than "new Block('Navigation', ..." + * */ class NavBlock extends Block { public function __construct() { diff --git a/core/config.class.php b/core/config.class.php index 7b0f6f1f..c0de6e25 100644 --- a/core/config.class.php +++ b/core/config.class.php @@ -1,94 +1,237 @@ values[$name] = parse_shorthand_int($value); $this->save($name); } + + /** + * @param string $name + * @param null|string $value + * @return void + */ public function set_string(/*string*/ $name, $value) { $this->values[$name] = $value; $this->save($name); } + + /** + * @param string $name + * @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); } + + /** + * @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->save($name); } + /** + * @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))) { $this->values[$name] = $value; } } + + /** + * @param string $name + * @param bool|null|string $value + * @return void + */ public function set_default_bool(/*string*/ $name, $value) { if(is_null($this->get($name))) { $this->values[$name] = (($value == 'on' || $value === true) ? 'Y' : 'N'); } } + + /** + * @param string $name + * @param array $value + * @return void + */ public function set_default_array(/*string*/ $name, $value) { assert(isset($value) && is_array($value)); if(is_null($this->get($name))) { @@ -96,19 +239,47 @@ abstract class BaseConfig implements Config { } } + /** + * @param string $name + * @param null|int $default + * @return int + */ public function get_int(/*string*/ $name, $default=null) { return (int)($this->get($name, $default)); } + + /** + * @param string $name + * @param null|string $default + * @return null|string + */ public function get_string(/*string*/ $name, $default=null) { return $this->get($name, $default); } + + /** + * @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)); } + + /** + * @param string $name + * @param array $default + * @return array + */ public function get_array(/*string*/ $name, $default=array()) { return explode(",", $this->get($name, "")); } + /** + * @param string $name + * @param null|mixed $default + * @return null|mixed + */ private function get(/*string*/ $name, $default=null) { if(isset($this->values[$name])) { return $this->values[$name]; @@ -121,13 +292,19 @@ abstract class BaseConfig implements Config { /** - * For testing, mostly + * Class HardcodeConfig + * + * For testing, mostly. */ class HardcodeConfig extends BaseConfig { public function __construct($dict) { $this->values = $dict; } + /** + * @param null|string $name + * @return mixed|void + */ public function save(/*string*/ $name=null) { // static config is static } @@ -135,6 +312,8 @@ class HardcodeConfig extends BaseConfig { /** + * Class StaticConfig + * * Loads the config list from a PHP file; the file should be in the format: * * */ class StaticConfig extends BaseConfig { + /** + * @param string $filename + * @throws Exception + */ public function __construct($filename) { if(file_exists($filename)) { require_once $filename; @@ -158,6 +341,10 @@ class StaticConfig extends BaseConfig { } } + /** + * @param null|string $name + * @return mixed|void + */ public function save(/*string*/ $name=null) { // static config is static } @@ -165,6 +352,8 @@ class StaticConfig extends BaseConfig { /** + * Class DatabaseConfig + * * Loads the config list from a table in a given database, the table should * be called config and have the schema: * @@ -176,10 +365,13 @@ class StaticConfig extends BaseConfig { * \endcode */ class DatabaseConfig extends BaseConfig { + /** @var \Database|null */ var $database = null; - /* - * Load the config table from a database + /** + * Load the config table from a database. + * + * @param Database $database */ public function __construct(Database $database) { $this->database = $database; @@ -197,8 +389,11 @@ class DatabaseConfig extends BaseConfig { } } - /* - * Save the current values as the new config table + /** + * 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)) { @@ -217,7 +412,13 @@ class DatabaseConfig extends BaseConfig { } } +/** + * Class MockConfig + */ class MockConfig extends HardcodeConfig { + /** + * @param array $config + */ public function __construct($config=array()) { $config["db_version"] = "999"; $config["anon_id"] = "0"; diff --git a/core/database.class.php b/core/database.class.php index 1fbfb2f8..f59ed418 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -2,41 +2,70 @@ /** @privatesection */ // Querylet {{{ class Querylet { - var $sql; - var $variables; + /** @var string */ + public $sql; + /** @var array */ + public $variables; + /** + * @param string $sql + * @param array $variables + */ public function __construct($sql, $variables=array()) { $this->sql = $sql; $this->variables = $variables; } + /** + * @param \Querylet $querylet + */ public function append($querylet) { assert(!is_null($querylet)); $this->sql .= $querylet->sql; $this->variables = array_merge($this->variables, $querylet->variables); } + /** + * @param string $sql + */ public function append_sql($sql) { $this->sql .= $sql; } + /** + * @param mixed $var + */ public function add_variable($var) { $this->variables[] = $var; } } -class TagQuerylet { - var $tag; - var $positive; +class TagQuerylet { + /** @var string */ + public $tag; + /** @var bool */ + public $positive; + + /** + * @param string $tag + * @param bool $positive + */ public function __construct($tag, $positive) { $this->tag = $tag; $this->positive = $positive; } } -class ImgQuerylet { - var $qlet; - var $positive; +class ImgQuerylet { + /** @var \Querylet */ + public $qlet; + /** @var bool */ + public $positive; + + /** + * @param \Querylet $qlet + * @param bool $positive + */ public function __construct($qlet, $positive) { $this->qlet = $qlet; $this->positive = $positive; @@ -45,25 +74,46 @@ class ImgQuerylet { // }}} // {{{ db engines class DBEngine { + /** @var null|string */ public $name = null; + /** + * @param \PDO $db + */ public function init($db) {} + /** + * @param string $scoreql + * @return string + */ public function scoreql_to_sql($scoreql) { return $scoreql; } + /** + * @param string $name + * @param string $data + * @return string + */ public function create_table_sql($name, $data) { return 'CREATE TABLE '.$name.' ('.$data.')'; } } class MySQL extends DBEngine { + /** @var string */ public $name = "mysql"; + /** + * @param \PDO $db + */ public function init($db) { $db->exec("SET NAMES utf8;"); } + /** + * @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_INET", "VARCHAR(45)", $data); @@ -77,6 +127,11 @@ class MySQL extends DBEngine { return $data; } + /** + * @param string $name + * @param string $data + * @return string + */ public function create_table_sql($name, $data) { $data = $this->scoreql_to_sql($data); $ctes = "ENGINE=InnoDB DEFAULT CHARSET='utf8'"; @@ -84,12 +139,20 @@ class MySQL extends DBEngine { } } class PostgreSQL extends DBEngine { + /** @var string */ public $name = "pgsql"; + /** + * @param \PDO $db + */ public function init($db) { $db->exec("SET application_name TO 'shimmie [{$_SERVER['REMOTE_ADDR']}]';"); } + /** + * @param string $data + * @return string + */ public function scoreql_to_sql($data) { $data = str_replace("SCORE_AIPK", "SERIAL PRIMARY KEY", $data); $data = str_replace("SCORE_INET", "INET", $data); @@ -103,6 +166,11 @@ class PostgreSQL extends DBEngine { return $data; } + /** + * @param string $name + * @param string $data + * @return string + */ public function create_table_sql($name, $data) { $data = $this->scoreql_to_sql($data); return 'CREATE TABLE '.$name.' ('.$data.')'; @@ -123,8 +191,12 @@ function _concat($a, $b) { return $a . $b; } function _lower($a) { return strtolower($a); } class SQLite extends DBEngine { + /** @var string */ public $name = "sqlite"; + /** + * @param \PDO $db + */ public function init($db) { ini_set('sqlite.assoc_case', 0); $db->exec("PRAGMA foreign_keys = ON;"); @@ -138,6 +210,10 @@ class SQLite extends DBEngine { $db->sqliteCreateFunction('lower', '_lower', 1); } + /** + * @param string $data + * @return string + */ public function scoreql_to_sql($data) { $data = str_replace("SCORE_AIPK", "INTEGER PRIMARY KEY", $data); $data = str_replace("SCORE_INET", "VARCHAR(45)", $data); @@ -150,6 +226,11 @@ class SQLite extends DBEngine { return $data; } + /** + * @param string $name + * @param string $data + * @return string + */ public function create_table_sql($name, $data) { $data = $this->scoreql_to_sql($data); $cols = array(); @@ -187,8 +268,16 @@ class NoCache implements CacheEngine { public function get_misses() {return 0;} } class MemcacheCache implements CacheEngine { - var $memcache=null, $hits=0, $misses=0; + /** @var \Memcache|null */ + public $memcache=null; + /** @var int */ + private $hits=0; + /** @var int */ + private $misses=0; + /** + * @param string $args + */ public function __construct($args) { $hp = explode(":", $args); if(class_exists("Memcache")) { @@ -197,6 +286,10 @@ class MemcacheCache implements CacheEngine { } } + /** + * @param string $key + * @return array|bool|string + */ public function get($key) { assert(!is_null($key)); if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { @@ -213,19 +306,35 @@ class MemcacheCache implements CacheEngine { } } + /** + * @param string $key + * @param mixed $val + * @param int $time + */ public function set($key, $val, $time=0) { assert(!is_null($key)); $this->memcache->set($key, $val, false, $time); } + /** + * @param string $key + */ public function delete($key) { assert(!is_null($key)); $this->memcache->delete($key); } + /** + * @return int + */ public function get_hits() {return $this->hits;} + + /** + * @return int + */ public function get_misses() {return $this->misses;} } + class APCCache implements CacheEngine { var $hits=0, $misses=0; @@ -267,25 +376,28 @@ class APCCache implements CacheEngine { */ class Database { /** - * The PDO database connection object, for anyone who wants direct access + * The PDO database connection object, for anyone who wants direct access. + * @var null|PDO */ private $db = null; /** - * Meta info about the database engine - * @var DBEngine + * Meta info about the database engine. + * @var DBEngine|null */ private $engine = null; /** - * The currently active cache engine - * @var CacheEngine + * The currently active cache engine. + * @var CacheEngine|null */ public $cache = null; /** * A boolean flag to track if we already have an active transaction. * (ie: True if beginTransaction() already called) + * + * @var bool */ public $transaction = false; @@ -364,6 +476,10 @@ class Database { } } + /** + * @return bool + * @throws SCoreException + */ public function commit() { if(!is_null($this->db)) { if ($this->transaction === true) { @@ -376,6 +492,10 @@ class Database { } } + /** + * @return bool + * @throws SCoreException + */ public function rollback() { if(!is_null($this->db)) { if ($this->transaction === true) { @@ -388,23 +508,39 @@ class Database { } } + /** + * @param string $input + * @return string + */ public function escape($input) { if(is_null($this->db)) $this->connect_db(); return $this->db->Quote($input); } + /** + * @param string $input + * @return string + */ public function scoreql_to_sql($input) { if(is_null($this->engine)) $this->connect_engine(); return $this->engine->scoreql_to_sql($input); } + /** + * @return null|string + */ public function get_driver_name() { if(is_null($this->engine)) $this->connect_engine(); return $this->engine->name; } /** - * Execute an SQL query and return an PDO resultset + * 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 { @@ -433,14 +569,22 @@ class Database { } /** - * Execute an SQL query and return a 2D array + * Execute an SQL query and return a 2D array. + * + * @param string $query + * @param array $args + * @return array */ public function get_all($query, $args=array()) { return $this->execute($query, $args)->fetchAll(); } /** - * Execute an SQL query and return a single row + * Execute an SQL query and return a single row. + * + * @param string $query + * @param array $args + * @return mixed|null */ public function get_row($query, $args=array()) { $row = $this->execute($query, $args)->fetch(); @@ -448,7 +592,11 @@ class Database { } /** - * Execute an SQL query and return the first column of each row + * Execute an SQL query and return the first column of each row. + * + * @param string $query + * @param array $args + * @return array */ public function get_col($query, $args=array()) { $stmt = $this->execute($query, $args); @@ -460,7 +608,11 @@ 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 rown. + * + * @param string $query + * @param array $args + * @return array */ public function get_pairs($query, $args=array()) { $stmt = $this->execute($query, $args); @@ -472,7 +624,11 @@ class Database { } /** - * Execute an SQL query and return a single value + * Execute an SQL query and return a single value. + * + * @param string $query + * @param array $args + * @return mixed */ public function get_one($query, $args=array()) { $row = $this->execute($query, $args)->fetch(); @@ -480,7 +636,10 @@ class Database { } /** - * get the ID of the last inserted row + * Get the ID of the last inserted row. + * + * @param string|null $seq + * @return string */ public function get_last_insert_id($seq) { if($this->engine->name == "pgsql") { @@ -492,15 +651,20 @@ class Database { } /** - * Create a table from pseudo-SQL + * Create a table from pseudo-SQL. + * + * @param string $name + * @param string $data */ public function create_table($name, $data) { - if(is_null($this->engine)) $this->connect_engine(); + if(is_null($this->engine)) { $this->connect_engine(); } $this->execute($this->engine->create_table_sql($name, $data)); } /** * Returns the number of tables present in the current database. + * + * @return int|null */ public function count_tables() { if(is_null($this->db) || is_null($this->engine)) $this->connect_db(); @@ -525,14 +689,26 @@ class Database { } class MockDatabase extends Database { + /** @var int */ var $query_id = 0; + /** @var array */ var $responses = array(); + /** @var \NoCache|null */ var $cache = null; + /** + * @param array $responses + */ public function __construct($responses = array()) { $this->cache = new NoCache(); $this->responses = $responses; } + + /** + * @param string $query + * @param array $params + * @return PDOStatement + */ public function execute($query, $params=array()) { log_debug("mock-database", "QUERY: " . $query . @@ -542,13 +718,51 @@ class MockDatabase extends Database { return $this->responses[$this->query_id++]; } + /** + * @param string $query + * @param array $args + * @return array|PDOStatement + */ public function get_all($query, $args=array()) {return $this->execute($query, $args);} + + /** + * @param string $query + * @param array $args + * @return mixed|null|PDOStatement + */ public function get_row($query, $args=array()) {return $this->execute($query, $args);} + + /** + * @param string $query + * @param array $args + * @return array|PDOStatement + */ public function get_col($query, $args=array()) {return $this->execute($query, $args);} + + /** + * @param string $query + * @param array $args + * @return array|PDOStatement + */ public function get_pairs($query, $args=array()) {return $this->execute($query, $args);} + + /** + * @param string $query + * @param array $args + * @return mixed|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() {} diff --git a/core/email.class.php b/core/email.class.php index 8dd2db58..d43e4dc4 100644 --- a/core/email.class.php +++ b/core/email.class.php @@ -1,21 +1,40 @@ to = $to; diff --git a/core/event.class.php b/core/event.class.php index 2b824e5b..5012ca30 100644 --- a/core/event.class.php +++ b/core/event.class.php @@ -26,8 +26,19 @@ class InitExtEvent extends Event {} * $event->get_arg(0) = "42" */ class PageRequestEvent extends Event { + /** + * @var array + */ public $args; + + /** + * @var int + */ public $arg_count; + + /** + * @var int + */ public $part_count; /** @@ -90,7 +101,7 @@ class PageRequestEvent extends Event { * Get the n th argument of the page request (if it exists.) * * @param int $n - * @return string|null The argmuent (string) or NULL + * @return string|null The argument (string) or NULL */ public function get_arg(/*int*/ $n) { $offset = $this->part_count + $n; @@ -154,9 +165,19 @@ class PageRequestEvent extends Event { * Sent when index.php is called from the command line */ class CommandEvent extends Event { + /** + * @var string + */ public $cmd = "help"; + + /** + * @var array + */ public $args = array(); + /** + * @param string[] $args + */ public function __construct(/*array(string)*/ $args) { global $user; @@ -215,19 +236,28 @@ class CommandEvent extends Event { class TextFormattingEvent extends Event { /** * For reference + * + * @var string */ - var $original; + public $original; /** * with formatting applied + * + * @var string */ - var $formatted; + public $formatted; /** * with formatting removed + * + * @var string */ - var $stripped; + public $stripped; + /** + * @param string $text + */ public function __construct(/*string*/ $text) { $h_text = html_escape(trim($text)); $this->original = $h_text; @@ -244,36 +274,44 @@ class LogEvent extends Event { /** * a category, normally the extension name * - * @return string + * @var string */ - var $section; + public $section; /** * See python... * - * @return int + * @var int */ - var $priority = 0; + public $priority = 0; /** * Free text to be logged * - * @return text + * @var string */ - var $message; + public $message; /** * The time that the event was created * - * @return int + * @var int */ - var $time; + public $time; /** * Extra data to be held separate + * + * @var array */ - var $args; + public $args; + /** + * @param string $section + * @param int $priority + * @param string $message + * @param array $args + */ public function __construct($section, $priority, $message, $args) { $this->section = $section; $this->priority = $priority; diff --git a/core/exceptions.class.php b/core/exceptions.class.php index d627dc3c..14765760 100644 --- a/core/exceptions.class.php +++ b/core/exceptions.class.php @@ -1,11 +1,16 @@ onBlah($event) * * Also loads the theme object into $this->theme if available @@ -96,7 +98,11 @@ abstract class Extension { } /** - * Find the theme object for a given extension + * Find the theme object for a given extension. + * + * @param Extension $class + * @param bool $fatal + * @return bool */ private function get_theme_object(Extension $class, $fatal=true) { $base = get_class($class); @@ -114,7 +120,9 @@ abstract class Extension { /** * Override this to change the priority of the extension, - * lower numbered ones will recieve events first + * lower numbered ones will recieve events first. + * + * @return int */ public function get_priority() { return 50; @@ -122,23 +130,43 @@ abstract class Extension { } /** - * Several extensions have this in common, make a common API + * Class FormatterExtension + * + * Several extensions have this in common, make a common API. */ abstract class FormatterExtension extends Extension { + /** + * @param TextFormattingEvent $event + */ public function onTextFormatting(TextFormattingEvent $event) { $event->formatted = $this->format($event->formatted); $event->stripped = $this->strip($event->stripped); } + /** + * @param string $text + * @return string + */ abstract public function format(/*string*/ $text); + + /** + * @param string $text + * @return string + */ abstract public function strip(/*string*/ $text); } /** + * Class DataHandlerExtension + * * This too is a common class of extension with many methods in common, - * so we have a base class to extend from + * so we have a base class to extend from. */ abstract class DataHandlerExtension extends Extension { + /** + * @param DataUploadEvent $event + * @throws UploadException + */ public function onDataUpload(DataUploadEvent $event) { $supported_ext = $this->supported_ext($event->type); $check_contents = $this->check_contents($event->tmpname); @@ -202,6 +230,9 @@ abstract class DataHandlerExtension extends Extension { } } + /** + * @param ThumbnailGenerationEvent $event + */ public function onThumbnailGeneration(ThumbnailGenerationEvent $event) { if($this->supported_ext($event->type)) { if (method_exists($this, 'create_thumb_force') && $event->force == true) { @@ -213,6 +244,9 @@ abstract class DataHandlerExtension extends Extension { } } + /** + * @param DisplayingImageEvent $event + */ public function onDisplayingImage(DisplayingImageEvent $event) { global $page; if($this->supported_ext($event->image->ext)) { @@ -229,9 +263,29 @@ abstract class DataHandlerExtension extends Extension { protected function setup() {} */ + /** + * @param string $ext + * @return bool + */ abstract protected function supported_ext($ext); + + /** + * @param $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); } diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 8c8e27b0..cb7e3418 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -31,15 +31,38 @@ $order_sql = null; // this feels ugly require_once "lib/flexihash.php"; /** - * An object representing an entry in the images table. As of 2.2, this no - * longer necessarily represents an image per se, but could be a video, - * sound file, or any other supported upload type. + * Class Image + * + * An object representing an entry in the images table. + * + * As of 2.2, this no longer necessarily represents an + * image per se, but could be a video, sound file, or any + * other supported upload type. */ class Image { + /** @var null|int */ public $id = null; - public $height, $width; - public $hash, $filesize; - public $filename, $ext; + + /** @var int */ + public $height; + + /** @var int */ + public $width; + + /** @var string */ + public $hash; + + public $filesize; + + /** @var string */ + public $filename; + + /** @var string */ + public $ext; + + /** @var string[]|null */ + public $tag_array; + public $owner_id, $owner_ip; public $posted, $posted_timestamp; public $source; @@ -47,7 +70,9 @@ class Image { /** * 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 */ public function __construct($row=null) { if(!is_null($row)) { @@ -66,7 +91,7 @@ class Image { } /** - * Find an image by ID + * Find an image by ID. * * @param int $id * @return Image @@ -79,7 +104,7 @@ class Image { } /** - * Find an image by hash + * Find an image by hash. * * @param string $hash * @return Image @@ -92,9 +117,9 @@ class Image { } /** - * Pick a random image out of a set + * Pick a random image out of a set. * - * @param array $tags + * @param string[] $tags * @return Image */ public static function by_random($tags=array()) { @@ -112,9 +137,9 @@ class Image { * * @param int $start * @param int $limit - * @param array $tags + * @param string[] $tags * @throws SCoreException - * @return Array + * @return Image[] */ public static function find_images(/*int*/ $start, /*int*/ $limit, $tags=array()) { assert(is_numeric($start)); @@ -153,7 +178,7 @@ class Image { /** * Count the number of image results for a given search * - * @param array $tags + * @param string[] $tags * @return mixed */ public static function count_images($tags=array()) { @@ -185,7 +210,7 @@ class Image { /** * Count the number of pages for a given search * - * @param array $tags + * @param string[] $tags * @return float */ public static function count_pages($tags=array()) { @@ -205,7 +230,7 @@ class Image { * Rather than simply $this_id + 1, one must take into account * deleted images and search queries * - * @param array $tags + * @param string[] $tags * @param bool $next * @return Image */ @@ -239,7 +264,7 @@ class Image { /** * The reverse of get_next * - * @param array $tags + * @param string[] $tags * @return Image */ public function get_prev($tags=array()) { @@ -269,7 +294,9 @@ class Image { } /** - * Get this image's tags as an array + * Get this image's tags as an array. + * + * @return string[] */ public function get_tag_array() { global $database; @@ -349,7 +376,7 @@ class Image { /** * Get the tooltip for this image, formatted according to the - * configured template + * configured template. * * @return string */ @@ -378,7 +405,7 @@ class Image { } /** - * Figure out where the full size image is on disk + * Figure out where the full size image is on disk. * * @return string */ @@ -387,7 +414,7 @@ class Image { } /** - * Figure out where the thumbnail is on disk + * Figure out where the thumbnail is on disk. * * @return string */ @@ -396,7 +423,7 @@ class Image { } /** - * Get the original filename + * Get the original filename. * * @return string */ @@ -405,7 +432,7 @@ class Image { } /** - * Get the image's mime type + * Get the image's mime type. * * @return string */ @@ -480,7 +507,9 @@ class Image { } /** - * Set the tags for this image + * Set the tags for this image. + * + * @param string[] $tags */ public function set_tags($tags) { global $database; @@ -564,7 +593,7 @@ class Image { /** * Someone please explain this * - * @param $tmpl + * @param string $tmpl * @param string $_escape * @return string */ @@ -637,6 +666,10 @@ class Image { return $tmpl; } + /** + * @param string[] $terms + * @return \Querylet + */ private static function build_search_querylet($terms) { assert(is_array($terms)); global $database; @@ -666,6 +699,9 @@ class Image { * C) Runs really slow on bad databases: * All the subqueries are executed every time for every row in the * images table. Yes, MySQL does suck this much. + * + * @param string[] $terms + * @return \Querylet */ private static function build_accurate_search_querylet($terms) { global $database; @@ -983,9 +1019,12 @@ class Image { } /** + * Class Tag + * * A class for organising the tag related functions. * * All the methods are static, one should never actually use a tag object. + * */ class Tag { /** @@ -1003,7 +1042,11 @@ class Tag { } /** - * Turn any string or array into a valid tag array + * Turn any string or array into a valid tag array. + * + * @param string|string[] $tags + * @param bool $tagme + * @return array */ public static function explode($tags, $tagme=true) { assert(is_string($tags) || is_array($tags)); @@ -1033,7 +1076,7 @@ class Tag { } /** - * @param $tags + * @param string|string[] $tags * @return string */ public static function implode($tags) { @@ -1073,6 +1116,10 @@ class Tag { return $negative ? "-$newtag" : $newtag; } + /** + * @param string $tag + * @return array + */ public static function resolve_wildcard($tag) { // if there is no wildcard, return the tag if(strpos($tag, "*") === false) { @@ -1102,8 +1149,8 @@ class Tag { /** * This function takes a list (array) of tags and changes any tags that have aliases * - * @param array $tags Array of tags - * @return array of tags + * @param string[] $tags Array of tags + * @return array */ public static function resolve_aliases($tags) { assert(is_array($tags)); @@ -1139,7 +1186,11 @@ class Tag { /** * Move a file from PHP's temporary area into shimmie's image storage - * hierarchy, or throw an exception trying + * hierarchy, or throw an exception trying. + * + * @param DataUploadEvent $event + * @return bool + * @throws UploadException */ function move_upload_to_archive(DataUploadEvent $event) { $target = warehouse_path("images", $event->hash); diff --git a/core/page.class.php b/core/page.class.php index db588e94..903014c0 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -28,28 +28,32 @@ /** + * Class Page + * * A data structure for holding all the bits of data that make up a page. * * The various extensions all add whatever they want to this structure, - * then Layout turns it into HTML + * then Layout turns it into HTML. */ class Page { /** @name Overall */ //@{ - /** @private */ - var $mode = "page"; - /** @private */ - var $type = "text/html; charset=utf-8"; + /** @var string */ + public $mode = "page"; + /** @var string */ + public $type = "text/html; charset=utf-8"; /** * Set what this page should do; "page", "data", or "redirect". + * @param string $mode */ public function set_mode($mode) { $this->mode = $mode; } /** - * Set the page's MIME type + * Set the page's MIME type. + * @param string $type */ public function set_type($type) { $this->type = $type; @@ -61,20 +65,23 @@ class Page { /** @name "data" mode */ //@{ - /** @private */ - var $data = ""; - /** @private */ - var $filename = null; + /** @var string */ + private $data = ""; + + /** @var string */ + private $filename = null; /** - * Set the raw data to be sent + * Set the raw data to be sent. + * @param string $data */ public function set_data($data) { $this->data = $data; } /** - * Set the recommended download filename + * Set the recommended download filename. + * @param string $filename */ public function set_filename($filename) { $this->filename = $filename; @@ -86,12 +93,13 @@ class Page { /** @name "redirect" mode */ //@{ - /** @private */ - var $redirect = ""; + /** @var string */ + private $redirect = ""; /** * Set the URL to redirect to (remember to use make_link() if linking - * to a page in the same site) + * to a page in the same site). + * @param string $redirect */ public function set_redirect($redirect) { $this->redirect = $redirect; @@ -103,55 +111,75 @@ class Page { /** @name "page" mode */ //@{ - /** @privatesection */ - var $title = ""; - var $heading = ""; - var $subheading = ""; - var $quicknav = ""; - var $html_headers = array(); - var $http_headers = array(); - var $blocks = array(); - /** @publicsection */ + /** @var string */ + public $title = ""; + + /** @var string */ + public $heading = ""; + + /** @var string */ + public $subheading = ""; + + /** @var string */ + public $quicknav = ""; + + /** @var string[] */ + public $html_headers = array(); + + /** @var string[] */ + public $http_headers = array(); + + /** @var Block[] */ + public $blocks = array(); + /** - * Set the window title + * Set the window title. + * @param string $title */ public function set_title($title) { $this->title = $title; } /** - * Set the main heading + * Set the main heading. + * @param string $heading */ public function set_heading($heading) { $this->heading = $heading; } /** - * Set the sub heading + * Set the sub heading. + * @param string $subheading */ public function set_subheading($subheading) { $this->subheading = $subheading; } /** - * Add a line to the HTML head section + * Add a line to the HTML head section. + * @param string $line + * @param int $position */ public function add_html_header($line, $position=50) { while(isset($this->html_headers[$position])) $position++; $this->html_headers[$position] = $line; } - + /** * Add a http header to be sent to the client. + * @param string $line + * @param int $position */ public function add_http_header($line, $position=50) { while(isset($this->http_headers[$position])) $position++; $this->http_headers[$position] = $line; } - + /** * Get all the HTML headers that are currently set and return as a string. + * @return string */ public function get_all_html_headers() { $data = ''; @@ -162,14 +190,15 @@ class Page { } /** - * Removes all currently set HTML headers. (Be careful..) + * Removes all currently set HTML headers (Be careful..). */ public function delete_all_html_headers() { $this->html_headers = array(); } - + /** - * Add a Block of data + * Add a Block of data to the page. + * @param Block $block */ public function add_block(Block $block) { $this->blocks[] = $block; @@ -180,7 +209,7 @@ class Page { // ============================================== /** - * Display the page according to the mode and data given + * Display the page according to the mode and data given. */ public function display() { global $page, $user; diff --git a/core/user.class.php b/core/user.class.php index 94e22c63..a9e86b5d 100644 --- a/core/user.class.php +++ b/core/user.class.php @@ -6,9 +6,11 @@ function _new_user($row) { /** + * Class User + * * An object representing a row in the "users" table. * - * The currently logged in user will always be accessible via the global variable $user + * The currently logged in user will always be accessible via the global variable $user. */ class User { /** @var int */ @@ -22,10 +24,11 @@ class User { public $join_date; + /** @var string */ public $passhash; /** @var UserClass */ - var $class; + public $class; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Initialisation * @@ -38,7 +41,9 @@ class User { /** * 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 */ public function __construct($row) { global $_user_classes; @@ -145,7 +150,7 @@ class User { /** - * Test if this user is anonymous (not logged in) + * Test if this user is anonymous (not logged in). * * @return bool */ @@ -155,7 +160,7 @@ class User { } /** - * Test if this user is logged in + * Test if this user is logged in. * * @return bool */ @@ -165,7 +170,7 @@ class User { } /** - * Test if this user is an administrator + * Test if this user is an administrator. * * @return bool */ @@ -193,6 +198,9 @@ class User { log_info("core-user", 'Set password for '.$this->name); } + /** + * @param string $address + */ public function set_email(/*string*/ $address) { global $database; $database->Execute("UPDATE users SET email=:email WHERE id=:id", array("email"=>$address, "id"=>$this->id)); @@ -201,7 +209,8 @@ class User { /** * Get a snippet of HTML which will render the user's avatar, be that - * a local file, a remote file, a gravatar, a something else, etc + * a local file, a remote file, a gravatar, a something else, etc. + * * @return String of HTML */ public function get_avatar_html() { @@ -231,7 +240,7 @@ class User { * the form was generated within the session. Salted and re-hashed so that * reading a web page from the user's cache doesn't give access to the session key * - * @return String containing auth token (MD5sum) + * @return string A string containing auth token (MD5sum) */ public function get_auth_token() { global $config; diff --git a/core/userclass.class.php b/core/userclass.class.php index ee6871ea..e1e5ab2d 100644 --- a/core/userclass.class.php +++ b/core/userclass.class.php @@ -1,11 +1,34 @@ $v) { @@ -427,6 +433,10 @@ function make_form($target, $method="POST", $multipart=False, $form_id="", $onsu return '
'.$auth; } +/** + * @param string $file The filename + * @return string + */ function mtimefile($file) { $data_href = get_base_href(); $mtime = filemtime($file); @@ -445,8 +455,11 @@ function get_theme() { return $theme; } -/* - * like glob, with support for matching very long patterns with braces +/** + * Like glob, with support for matching very long patterns with braces. + * + * @param string $pattern + * @return array */ function zglob($pattern) { $results = array(); @@ -470,6 +483,9 @@ function zglob($pattern) { * CAPTCHA abstraction * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/** + * @return string + */ function captcha_get_html() { global $config, $user; @@ -492,6 +508,9 @@ function captcha_get_html() { return $captcha; } +/** + * @return bool + */ function captcha_check() { global $config, $user; @@ -593,7 +612,10 @@ function getMimeType($file, $ext="", $list=false) { return 'application/octet-stream'; } - +/** + * @param string $mime_type + * @return bool|string + */ function getExtension ($mime_type){ if(empty($mime_type)){ return false; @@ -762,6 +784,11 @@ function get_prefixed_cookie(/*string*/ $name) { * The counterpart for get_prefixed_cookie, this works like php's * setcookie method, but prepends the site-wide cookie prefix to * the $name argument before doing anything. + * + * @param string $name + * @param string $value + * @param int $time + * @param string $path */ function set_prefixed_cookie($name, $value, $time, $path) { global $config; @@ -770,13 +797,16 @@ function set_prefixed_cookie($name, $value, $time, $path) { } /** - * Set (or extend) a flash-message cookie + * Set (or extend) a flash-message cookie. * * This can optionally be done at the same time as saving a log message with log_*() * * Generally one should flash a message in onPageRequest and log a message wherever * the action actually takes place (eg onWhateverElse) - but much of the time, actions * are taken from within onPageRequest... + * + * @param string $text + * @param string $type */ function flash_message(/*string*/ $text, /*string*/ $type="info") { $current = get_prefixed_cookie("flash_message"); @@ -816,10 +846,9 @@ function get_base_href() { } /** - * A shorthand way to send a TextFormattingEvent and get the - * results + * A shorthand way to send a TextFormattingEvent and get the results. * - * @param $string + * @param string $string * @return string */ function format_text(/*string*/ $string) { @@ -828,6 +857,12 @@ function format_text(/*string*/ $string) { return $tfe->formatted; } +/** + * @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); $cd = substr($hash, 2, 2); @@ -841,12 +876,21 @@ function warehouse_path(/*string*/ $base, /*string*/ $hash, /*bool*/ $create=tru return $pa; } +/** + * @param string $filename + * @return string + */ function data_path($filename) { $filename = "data/" . $filename; if(!file_exists(dirname($filename))) mkdir(dirname($filename), 0755, true); return $filename; } +/** + * @param string $url + * @param string $mfile + * @return array|bool + */ function transload($url, $mfile) { global $config; @@ -955,12 +999,17 @@ function findHeader ($headers, $name){ $_included = array(); /** * Get the active contents of a .php file + * + * @param string $fname + * @return string|null */ function manual_include($fname) { - if(!file_exists($fname)) return; - global $_included; - if(in_array($fname, $_included)) return; + + if(!file_exists($fname)) return null; + + if(in_array($fname, $_included)) return null; + $_included[] = $fname; print "$fname\n"; @@ -1007,6 +1056,12 @@ define("SCORE_LOG_NOTSET", 0); * $flash = null (default) - log to server only, no flash message * $flash = true - show the message to the user as well * $flash = "some string" - log the message, flash the string + * + * @param string $section + * @param int $priority + * @param string $message + * @param null|bool|string $flash + * @param array $args */ function log_msg(/*string*/ $section, /*int*/ $priority, /*string*/ $message, $flash=null, $args=array()) { send_event(new LogEvent($section, $priority, $message, $args)); @@ -1029,10 +1084,13 @@ function log_warning( /*string*/ $section, /*string*/ $message, $flash=null, $ar function log_error( /*string*/ $section, /*string*/ $message, $flash=null, $args=array()) {log_msg($section, SCORE_LOG_ERROR, $message, $flash, $args);} function log_critical(/*string*/ $section, /*string*/ $message, $flash=null, $args=array()) {log_msg($section, SCORE_LOG_CRITICAL, $message, $flash, $args);} -/** - * Get a unique ID for this request, useful for grouping log messages - */ + $_request_id = null; +/** + * Get a unique ID for this request, useful for grouping log messages. + * + * @return null|string + */ function get_request_id() { global $_request_id; if(!$_request_id) { @@ -1214,7 +1272,11 @@ function full_copy($source, $target) { $_event_listeners = array(); /** - * Register an Extension + * Register an Extension. + * + * @param Extension $extension + * @param int $pos + * @param array $events */ function add_event_listener(Extension $extension, $pos=50, $events=array()) { global $_event_listeners; @@ -1231,7 +1293,9 @@ function add_event_listener(Extension $extension, $pos=50, $events=array()) { $_event_count = 0; /** - * Send an event to all registered Extensions + * Send an event to all registered Extensions. + * + * @param Event $event */ function send_event(Event $event) { global $_event_listeners, $_event_count; @@ -1265,7 +1329,7 @@ $_load_start = microtime(true); * Collects some debug information (execution time, memory usage, queries, etc) * and formats it to stick in the footer of the page. * - * @return String of debug info to add to the page. + * @return string debug info to add to the page. */ function get_debug_info() { global $config, $_event_count, $database, $_execs, $_load_start; @@ -1299,6 +1363,10 @@ function get_debug_info() { /** @privatesection */ +/** + * @param array|string $arr + * @return array|string + */ function _stripslashes_r($arr) { return is_array($arr) ? array_map('_stripslashes_r', $arr) : stripslashes($arr); } @@ -1342,6 +1410,10 @@ function _sanitise_environment() { } } +/** + * @param string $_theme + * @return array + */ function _get_themelet_files($_theme) { $base_themelets = array(); if(file_exists('themes/'.$_theme.'/custompage.class.php')) $base_themelets[] = 'themes/'.$_theme.'/custompage.class.php'; @@ -1424,6 +1496,7 @@ function _load_extensions() { /** * Used to display fatal errors to the web user. + * @param Exception $e */ function _fatal_error(Exception $e) { $version = VERSION; @@ -1455,6 +1528,9 @@ function _fatal_error(Exception $e) { * * Necessary because various servers and various clients * think that / is special... + * + * @param string $str + * @return string */ function _decaret($str) { $out = ""; @@ -1473,6 +1549,9 @@ function _decaret($str) { return $out; } +/** + * @return User + */ function _get_user() { global $config; $user = null; diff --git a/ext/admin/main.php b/ext/admin/main.php index dc8be5f0..25187267 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -24,15 +24,26 @@ * Sent when the admin page is ready to be added to */ class AdminBuildingEvent extends Event { - var $page; + /** @var \Page */ + public $page; + + /** + * @param Page $page + */ public function __construct(Page $page) { $this->page = $page; } } class AdminActionEvent extends Event { - var $action; - var $redirect = true; + /** @var string */ + public $action; + /** @var bool */ + public $redirect = true; + + /** + * @param string $action + */ public function __construct(/*string*/ $action) { $this->action = $action; } diff --git a/ext/admin/theme.php b/ext/admin/theme.php index d1f8c71b..5f1a3c5c 100644 --- a/ext/admin/theme.php +++ b/ext/admin/theme.php @@ -12,6 +12,12 @@ class AdminPageTheme extends Themelet { $page->add_block(new NavBlock()); } + /** + * @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" : ""; $html = make_form(make_link("admin/$action"), "POST", false, null, null, "admin$c_protected"); diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index 883292d9..97446387 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -11,9 +11,15 @@ */ class AddAliasEvent extends Event { - var $oldtag; - var $newtag; + /** @var string */ + public $oldtag; + /** @var string */ + public $newtag; + /** + * @param string $oldtag + * @param string $newtag + */ public function __construct($oldtag, $newtag) { $this->oldtag = trim($oldtag); $this->newtag = trim($newtag); @@ -124,6 +130,10 @@ class AliasEditor extends Extension { } } + /** + * @param Database $database + * @return string + */ private function get_alias_csv(Database $database) { $csv = ""; $aliases = $database->get_pairs("SELECT oldtag, newtag FROM aliases ORDER BY newtag"); @@ -133,6 +143,10 @@ class AliasEditor extends Extension { return $csv; } + /** + * @param Database $database + * @param string $csv + */ private function add_alias_csv(Database $database, /*string*/ $csv) { $csv = str_replace("\r", "\n", $csv); foreach(explode("\n", $csv) as $line) { @@ -148,9 +162,15 @@ class AliasEditor extends Extension { } } - // add alias *after* mass tag editing, else the MTE will - // search for the images and be redirected to the alias, - // missing out the images tagged with the oldtag + /** + * Get the priority for this extension. + * + * Add alias *after* mass tag editing, else the MTE will + * search for the images and be redirected to the alias, + * missing out the images tagged with the old tag. + * + * @return int + */ public function get_priority() {return 60;} } diff --git a/ext/alias_editor/theme.php b/ext/alias_editor/theme.php index 21a984b8..4dc2d2b1 100644 --- a/ext/alias_editor/theme.php +++ b/ext/alias_editor/theme.php @@ -1,11 +1,14 @@ $new_tag) - * $can_manage = whether things like "add new alias" should be shown + * Note: $can_manage = whether things like "add new alias" should be shown + * + * @param array $aliases An array of ($old_tag => $new_tag) + * @param int $pageNumber + * @param int $totalPages */ public function display_aliases($aliases, $pageNumber, $totalPages) { global $page, $user; diff --git a/ext/arrowkey_navigation/main.php b/ext/arrowkey_navigation/main.php index 4d248f32..b808c90f 100644 --- a/ext/arrowkey_navigation/main.php +++ b/ext/arrowkey_navigation/main.php @@ -9,14 +9,22 @@ * Simply enable this extention in the extention manager to enable arrow key navigation. */ class ArrowkeyNavigation extends Extension { - # Adds functionality for post/view on images + /** + * Adds functionality for post/view on images. + * + * @param DisplayingImageEvent $event + */ public function onDisplayingImage(DisplayingImageEvent $event) { $prev_url = make_http(make_link("post/prev/".$event->image->id)); $next_url = make_http(make_link("post/next/".$event->image->id)); $this->add_arrowkeys_code($prev_url, $next_url); } - # Adds functionality for post/list + /** + * Adds functionality for post/list. + * + * @param PageRequestEvent $event + */ public function onPageRequest(PageRequestEvent $event) { if($event->page_matches("post/list")) { $pageinfo = $this->get_list_pageinfo($event); @@ -26,7 +34,12 @@ class ArrowkeyNavigation extends Extension { } } - # adds the javascript to the page with the given urls + /** + * Adds the javascript to the page with the given urls. + * + * @param string $prev_url + * @param string $next_url + */ private function add_arrowkeys_code($prev_url, $next_url) { global $page; @@ -41,8 +54,13 @@ class ArrowkeyNavigation extends Extension { ", 60); } - # returns info about the current page number - private function get_list_pageinfo($event) { + /** + * Returns info about the current page number. + * + * @param PageRequestEvent $event + * @return array + */ + private function get_list_pageinfo(PageRequestEvent $event) { global $config, $database; // get the amount of images per page diff --git a/ext/artists/main.php b/ext/artists/main.php index 43edec08..7bb6238b 100644 --- a/ext/artists/main.php +++ b/ext/artists/main.php @@ -9,9 +9,19 @@ * */ class AuthorSetEvent extends Event { - var $image, $user, $author; + /** @var \Image */ + public $image; + /** @var \User */ + public $user; + /** @var string */ + 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->user = $user; @@ -937,9 +947,12 @@ class Artists extends Extension { return $result; } - /* - * HERE WE GET THE ID OF THE ARTIST - */ + /** + * HERE WE GET THE ID OF THE ARTIST. + * + * @param string $name + * @return string|int + */ private function get_artist_id($name){ global $database; $artistID = $database->get_row("SELECT id FROM artists WHERE name = ?" @@ -1203,7 +1216,8 @@ class Artists extends Extension { /* * HERE WE GET THE INFO OF THE ALIAS */ - private function get_alias($artistID){ + private function get_alias($artistID) + { if (!is_numeric($artistID)) return; global $database; diff --git a/ext/artists/theme.php b/ext/artists/theme.php index 3cecede4..347df0f1 100644 --- a/ext/artists/theme.php +++ b/ext/artists/theme.php @@ -1,6 +1,10 @@ extract_code($text); foreach(array( @@ -62,6 +66,10 @@ class BBCode extends FormatterExtension { return $text; } + /** + * @param string $text + * @return string + */ public function strip(/*string*/ $text) { foreach(array( "b", "i", "u", "s", "sup", "sub", "h1", "h2", "h3", "h4", @@ -81,7 +89,10 @@ class BBCode extends FormatterExtension { return $text; } - + /** + * @param string $text + * @return mixed + */ private function filter_spoiler(/*string*/ $text) { return str_replace( array("[spoiler]","[/spoiler]"), @@ -89,6 +100,10 @@ class BBCode extends FormatterExtension { $text); } + /** + * @param string $text + * @return string + */ private function strip_spoiler(/*string*/ $text) { $l1 = strlen("[spoiler]"); $l2 = strlen("[/spoiler]"); @@ -110,6 +125,10 @@ class BBCode extends FormatterExtension { return $text; } + /** + * @param string $text + * @return string + */ private function extract_code(/*string*/ $text) { # at the end of this function, the only code! blocks should be # the ones we've added -- others may contain malicious content, @@ -137,6 +156,10 @@ class BBCode extends FormatterExtension { return $text; } + /** + * @param string $text + * @return string + */ private function insert_code(/*string*/ $text) { $l1 = strlen("[code!]"); $l2 = strlen("[/code!]"); diff --git a/ext/blocks/main.php b/ext/blocks/main.php index 9cd8f253..314155f0 100644 --- a/ext/blocks/main.php +++ b/ext/blocks/main.php @@ -32,7 +32,7 @@ class Blocks extends Extension { } public function onPageRequest(PageRequestEvent $event) { - global $config, $database, $page, $user; + global $database, $page, $user; $blocks = $database->cache->get("blocks"); if($blocks === false) { diff --git a/ext/chatbox/cp/ajax.php b/ext/chatbox/cp/ajax.php index 8abc43f0..f682649f 100644 --- a/ext/chatbox/cp/ajax.php +++ b/ext/chatbox/cp/ajax.php @@ -4,7 +4,6 @@ $kioskMode = false; include '../php/filestorage.class.php'; include '../preferences.php'; -include '../php/json.class.php'; include '../php/functions.php'; include '../php/yshout.class.php'; include '../php/ajaxcall.class.php'; @@ -41,7 +40,7 @@ function doLogin() { 'html' => cp() ); - echo jsonEncode($result); + echo json_encode($result); return; } @@ -53,7 +52,7 @@ function doLogin() { } else $result['error'] = 'invalid'; - echo jsonEncode($result); + echo json_encode($result); } function doLogout() { @@ -63,7 +62,7 @@ function doLogout() { 'error' => false ); - echo jsonEncode($result); + echo json_encode($result); } function doUnban() { @@ -74,7 +73,7 @@ function doUnban() { 'error' => false ); - echo jsonEncode($result); + echo json_encode($result); return; } @@ -92,7 +91,7 @@ function doUnban() { $result['error'] = 'notbanned'; - echo jsonEncode($result); + echo json_encode($result); } function doUnbanAll() { @@ -103,7 +102,7 @@ function doUnbanAll() { 'error' => false ); - echo jsonEncode($result); + echo json_encode($result); return; } @@ -116,7 +115,7 @@ function doUnbanAll() { 'error' => false ); - echo jsonEncode($result); + echo json_encode($result); } @@ -128,7 +127,7 @@ function doSetPreference() { 'error' => false ); - echo jsonEncode($result); + echo json_encode($result); return; } @@ -150,7 +149,7 @@ function doSetPreference() { 'error' => false ); - echo jsonEncode($result); + echo json_encode($result); } @@ -162,7 +161,7 @@ function doResetPreferences() { 'error' => false ); - echo jsonEncode($result); + echo json_encode($result); return; } @@ -177,7 +176,7 @@ function doResetPreferences() { 'prefs' => $prefs ); - echo jsonEncode($result); + echo json_encode($result); } /* CP Display */ @@ -456,4 +455,3 @@ function about() { return $html; } -?> \ No newline at end of file diff --git a/ext/chatbox/history/index.php b/ext/chatbox/history/index.php index aadd2853..4a9a8b04 100644 --- a/ext/chatbox/history/index.php +++ b/ext/chatbox/history/index.php @@ -3,7 +3,6 @@ include '../php/filestorage.class.php'; include '../preferences.php'; - include '../php/json.class.php'; include '../php/functions.php'; include '../php/yshout.class.php'; diff --git a/ext/chatbox/include.php b/ext/chatbox/include.php index b26589a4..a3d4b7b7 100644 --- a/ext/chatbox/include.php +++ b/ext/chatbox/include.php @@ -2,9 +2,7 @@ $null = null; include 'php/filestorage.class.php'; include 'preferences.php'; - include 'php/json.class.php'; include 'php/functions.php'; include 'php/yshout.class.php'; include 'php/ajaxcall.class.php'; - -?> \ No newline at end of file + diff --git a/ext/chatbox/php/ajaxcall.class.php b/ext/chatbox/php/ajaxcall.class.php index 149a2ecc..78107e09 100644 --- a/ext/chatbox/php/ajaxcall.class.php +++ b/ext/chatbox/php/ajaxcall.class.php @@ -95,7 +95,7 @@ $send['error'] = false; } - echo jsonEncode($send); + echo json_encode($send); } function doUnban() { @@ -115,7 +115,7 @@ $send['error'] = false; } - echo jsonEncode($send); + echo json_encode($send); } function doDelete() { @@ -132,7 +132,7 @@ $send['error'] = false; } - echo jsonEncode($send); + echo json_encode($send); } function banSelf() { @@ -143,7 +143,7 @@ $send = array(); $send['error'] = false; - echo jsonEncode($send); + echo json_encode($send); } function unbanSelf() { @@ -158,7 +158,7 @@ $send['error'] = 'admin'; } - echo jsonEncode($send); + echo json_encode($send); } function reload() { @@ -168,7 +168,7 @@ $posts = $ys->latestPosts($prefs['truncate']); $this->setSessTimestamp($posts); $this->updates['posts'] = $posts; - echo jsonEncode($this->updates); + echo json_encode($this->updates); } function initSession() { @@ -186,7 +186,7 @@ 'banned' => true ); - echo jsonEncode($this->updates); + echo json_encode($this->updates); } function sendUpdates() { @@ -199,7 +199,7 @@ $this->updates['posts'] = $posts; - echo jsonEncode($this->updates); + echo json_encode($this->updates); } function setSessTimestamp(&$posts) { @@ -231,7 +231,7 @@ if ($ys->banned(ip())) $this->updates['banned'] = true; - echo jsonEncode($this->updates); + echo json_encode($this->updates); } function cleanPrefs($prefs) { @@ -253,7 +253,7 @@ $send['error'] = false; } - echo jsonEncode($send); + echo json_encode($send); } function clearLogs() { @@ -277,7 +277,7 @@ $send['error'] = false; } - echo jsonEncode($send); + echo json_encode($send); } } diff --git a/ext/chatbox/php/functions.php b/ext/chatbox/php/functions.php index c61a65e3..2966ce7d 100644 --- a/ext/chatbox/php/functions.php +++ b/ext/chatbox/php/functions.php @@ -45,19 +45,6 @@ return false; } - function jsonEncode(&$array) { - if ($array) { - $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); - return $json->encode($array); - } else - return 'ar'; - } - - function jsonDecode($encoded) { - $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); - return $json->decode($encoded); - } - function validIP($ip) { if ($ip == long2ip(ip2long($ip))) return true; diff --git a/ext/chatbox/php/json.class.php b/ext/chatbox/php/json.class.php deleted file mode 100644 index 21deb10c..00000000 --- a/ext/chatbox/php/json.class.php +++ /dev/null @@ -1,805 +0,0 @@ - -* @author Matt Knapp -* @author Brett Stimmerman -* @copyright 2005 Michal Migurski -* @version CVS: $Id: JSON.php,v 1.30 2006/03/08 16:10:20 migurski Exp $ -* @license http://www.opensource.org/licenses/bsd-license.php -* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198 -*/ - -/** -* Marker constant for Services_JSON::decode(), used to flag stack state -*/ -define('SERVICES_JSON_SLICE', 1); - -/** -* Marker constant for Services_JSON::decode(), used to flag stack state -*/ -define('SERVICES_JSON_IN_STR', 2); - -/** -* Marker constant for Services_JSON::decode(), used to flag stack state -*/ -define('SERVICES_JSON_IN_ARR', 3); - -/** -* Marker constant for Services_JSON::decode(), used to flag stack state -*/ -define('SERVICES_JSON_IN_OBJ', 4); - -/** -* Marker constant for Services_JSON::decode(), used to flag stack state -*/ -define('SERVICES_JSON_IN_CMT', 5); - -/** -* Behavior switch for Services_JSON::decode() -*/ -define('SERVICES_JSON_LOOSE_TYPE', 16); - -/** -* Behavior switch for Services_JSON::decode() -*/ -define('SERVICES_JSON_SUPPRESS_ERRORS', 32); - -/** -* Converts to and from JSON format. -* -* Brief example of use: -* -* -* // create a new instance of Services_JSON -* $json = new Services_JSON(); -* -* // convert a complexe value to JSON notation, and send it to the browser -* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4))); -* $output = $json->encode($value); -* -* print($output); -* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]] -* -* // accept incoming POST data, assumed to be in JSON notation -* $input = file_get_contents('php://input', 1000000); -* $value = $json->decode($input); -* -*/ -class Services_JSON -{ - /** - * constructs a new JSON instance - * - * @param int $use object behavior flags; combine with boolean-OR - * - * possible values: - * - SERVICES_JSON_LOOSE_TYPE: loose typing. - * "{...}" syntax creates associative arrays - * instead of objects in decode(). - * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression. - * Values which can't be encoded (e.g. resources) - * appear as NULL instead of throwing errors. - * By default, a deeply-nested resource will - * bubble up with an error, so all return values - * from encode() should be checked with isError() - */ - function Services_JSON($use = 0) - { - $this->use = $use; - } - - /** - * convert a string from one UTF-16 char to one UTF-8 char - * - * Normally should be handled by mb_convert_encoding, but - * provides a slower PHP-only method for installations - * that lack the multibye string extension. - * - * @param string $utf16 UTF-16 character - * @return string UTF-8 character - * @access private - */ - function utf162utf8($utf16) - { - // oh please oh please oh please oh please oh please - if(function_exists('mb_convert_encoding')) { - return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); - } - - $bytes = (ord($utf16{0}) << 8) | ord($utf16{1}); - - switch(true) { - case ((0x7F & $bytes) == $bytes): - // this case should never be reached, because we are in ASCII range - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - return chr(0x7F & $bytes); - - case (0x07FF & $bytes) == $bytes: - // return a 2-byte UTF-8 character - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - return chr(0xC0 | (($bytes >> 6) & 0x1F)) - . chr(0x80 | ($bytes & 0x3F)); - - case (0xFFFF & $bytes) == $bytes: - // return a 3-byte UTF-8 character - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - return chr(0xE0 | (($bytes >> 12) & 0x0F)) - . chr(0x80 | (($bytes >> 6) & 0x3F)) - . chr(0x80 | ($bytes & 0x3F)); - } - - // ignoring UTF-32 for now, sorry - return ''; - } - - /** - * convert a string from one UTF-8 char to one UTF-16 char - * - * Normally should be handled by mb_convert_encoding, but - * provides a slower PHP-only method for installations - * that lack the multibye string extension. - * - * @param string $utf8 UTF-8 character - * @return string UTF-16 character - * @access private - */ - function utf82utf16($utf8) - { - // oh please oh please oh please oh please oh please - if(function_exists('mb_convert_encoding')) { - return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); - } - - switch(strlen($utf8)) { - case 1: - // this case should never be reached, because we are in ASCII range - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - return $utf8; - - case 2: - // return a UTF-16 character from a 2-byte UTF-8 char - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - return chr(0x07 & (ord($utf8{0}) >> 2)) - . chr((0xC0 & (ord($utf8{0}) << 6)) - | (0x3F & ord($utf8{1}))); - - case 3: - // return a UTF-16 character from a 3-byte UTF-8 char - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - return chr((0xF0 & (ord($utf8{0}) << 4)) - | (0x0F & (ord($utf8{1}) >> 2))) - . chr((0xC0 & (ord($utf8{1}) << 6)) - | (0x7F & ord($utf8{2}))); - } - - // ignoring UTF-32 for now, sorry - return ''; - } - - /** - * encodes an arbitrary variable into JSON format - * - * @param mixed $var any number, boolean, string, array, or object to be encoded. - * see argument 1 to Services_JSON() above for array-parsing behavior. - * if var is a strng, note that encode() always expects it - * to be in ASCII or UTF-8 format! - * - * @return mixed JSON string representation of input var or an error if a problem occurs - * @access public - */ - function encode($var) - { - switch (gettype($var)) { - case 'boolean': - return $var ? 'true' : 'false'; - - case 'NULL': - return 'null'; - - case 'integer': - return (int) $var; - - case 'double': - case 'float': - return (float) $var; - - case 'string': - // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT - $ascii = ''; - $strlen_var = strlen($var); - - /* - * Iterate over every character in the string, - * escaping with a slash or encoding to UTF-8 where necessary - */ - for ($c = 0; $c < $strlen_var; ++$c) { - - $ord_var_c = ord($var{$c}); - - switch (true) { - case $ord_var_c == 0x08: - $ascii .= '\b'; - break; - case $ord_var_c == 0x09: - $ascii .= '\t'; - break; - case $ord_var_c == 0x0A: - $ascii .= '\n'; - break; - case $ord_var_c == 0x0C: - $ascii .= '\f'; - break; - case $ord_var_c == 0x0D: - $ascii .= '\r'; - break; - - case $ord_var_c == 0x22: - case $ord_var_c == 0x2F: - case $ord_var_c == 0x5C: - // double quote, slash, slosh - $ascii .= '\\'.$var{$c}; - break; - - case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): - // characters U-00000000 - U-0000007F (same as ASCII) - $ascii .= $var{$c}; - break; - - case (($ord_var_c & 0xE0) == 0xC0): - // characters U-00000080 - U-000007FF, mask 110XXXXX - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, ord($var{$c + 1})); - $c += 1; - $utf16 = $this->utf82utf16($char); - $ascii .= sprintf('\u%04s', bin2hex($utf16)); - break; - - case (($ord_var_c & 0xF0) == 0xE0): - // characters U-00000800 - U-0000FFFF, mask 1110XXXX - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, - ord($var{$c + 1}), - ord($var{$c + 2})); - $c += 2; - $utf16 = $this->utf82utf16($char); - $ascii .= sprintf('\u%04s', bin2hex($utf16)); - break; - - case (($ord_var_c & 0xF8) == 0xF0): - // characters U-00010000 - U-001FFFFF, mask 11110XXX - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, - ord($var{$c + 1}), - ord($var{$c + 2}), - ord($var{$c + 3})); - $c += 3; - $utf16 = $this->utf82utf16($char); - $ascii .= sprintf('\u%04s', bin2hex($utf16)); - break; - - case (($ord_var_c & 0xFC) == 0xF8): - // characters U-00200000 - U-03FFFFFF, mask 111110XX - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, - ord($var{$c + 1}), - ord($var{$c + 2}), - ord($var{$c + 3}), - ord($var{$c + 4})); - $c += 4; - $utf16 = $this->utf82utf16($char); - $ascii .= sprintf('\u%04s', bin2hex($utf16)); - break; - - case (($ord_var_c & 0xFE) == 0xFC): - // characters U-04000000 - U-7FFFFFFF, mask 1111110X - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, - ord($var{$c + 1}), - ord($var{$c + 2}), - ord($var{$c + 3}), - ord($var{$c + 4}), - ord($var{$c + 5})); - $c += 5; - $utf16 = $this->utf82utf16($char); - $ascii .= sprintf('\u%04s', bin2hex($utf16)); - break; - } - } - - return '"'.$ascii.'"'; - - case 'array': - /* - * As per JSON spec if any array key is not an integer - * we must treat the the whole array as an object. We - * also try to catch a sparsely populated associative - * array with numeric keys here because some JS engines - * will create an array with empty indexes up to - * max_index which can cause memory issues and because - * the keys, which may be relevant, will be remapped - * otherwise. - * - * As per the ECMA and JSON specification an object may - * have any string as a property. Unfortunately due to - * a hole in the ECMA specification if the key is a - * ECMA reserved word or starts with a digit the - * parameter is only accessible using ECMAScript's - * bracket notation. - */ - - // treat as a JSON object - if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) { - $properties = array_map(array($this, 'name_value'), - array_keys($var), - array_values($var)); - - foreach($properties as $property) { - if(Services_JSON::isError($property)) { - return $property; - } - } - - return '{' . join(',', $properties) . '}'; - } - - // treat it like a regular array - $elements = array_map(array($this, 'encode'), $var); - - foreach($elements as $element) { - if(Services_JSON::isError($element)) { - return $element; - } - } - - return '[' . join(',', $elements) . ']'; - - case 'object': - $vars = get_object_vars($var); - - $properties = array_map(array($this, 'name_value'), - array_keys($vars), - array_values($vars)); - - foreach($properties as $property) { - if(Services_JSON::isError($property)) { - return $property; - } - } - - return '{' . join(',', $properties) . '}'; - - default: - return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) - ? 'null' - : new Services_JSON_Error(gettype($var)." can not be encoded as JSON string"); - } - } - - /** - * array-walking function for use in generating JSON-formatted name-value pairs - * - * @param string $name name of key to use - * @param mixed $value reference to an array element to be encoded - * - * @return string JSON-formatted name-value pair, like '"name":value' - * @access private - */ - function name_value($name, $value) - { - $encoded_value = $this->encode($value); - - if(Services_JSON::isError($encoded_value)) { - return $encoded_value; - } - - return $this->encode(strval($name)) . ':' . $encoded_value; - } - - /** - * reduce a string by removing leading and trailing comments and whitespace - * - * @param $str string string value to strip of comments and whitespace - * - * @return string string value stripped of comments and whitespace - * @access private - */ - function reduce_string($str) - { - $str = preg_replace(array( - - // eliminate single line comments in '// ...' form - '#^\s*//(.+)$#m', - - // eliminate multi-line comments in '/* ... */' form, at start of string - '#^\s*/\*(.+)\*/#Us', - - // eliminate multi-line comments in '/* ... */' form, at end of string - '#/\*(.+)\*/\s*$#Us' - - ), '', $str); - - // eliminate extraneous space - return trim($str); - } - - /** - * decodes a JSON string into appropriate variable - * - * @param string $str JSON-formatted string - * - * @return mixed number, boolean, string, array, or object - * corresponding to given JSON input string. - * See argument 1 to Services_JSON() above for object-output behavior. - * Note that decode() always returns strings - * in ASCII or UTF-8 format! - * @access public - */ - function decode($str) - { - $str = $this->reduce_string($str); - - switch (strtolower($str)) { - case 'true': - return true; - - case 'false': - return false; - - case 'null': - return null; - - default: - $m = array(); - - if (is_numeric($str)) { - // Lookie-loo, it's a number - - // This would work on its own, but I'm trying to be - // good about returning integers where appropriate: - // return (float)$str; - - // Return float or int, as appropriate - return ((float)$str == (integer)$str) - ? (integer)$str - : (float)$str; - - } elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) { - // STRINGS RETURNED IN UTF-8 FORMAT - $delim = substr($str, 0, 1); - $chrs = substr($str, 1, -1); - $utf8 = ''; - $strlen_chrs = strlen($chrs); - - for ($c = 0; $c < $strlen_chrs; ++$c) { - - $substr_chrs_c_2 = substr($chrs, $c, 2); - $ord_chrs_c = ord($chrs{$c}); - - switch (true) { - case $substr_chrs_c_2 == '\b': - $utf8 .= chr(0x08); - ++$c; - break; - case $substr_chrs_c_2 == '\t': - $utf8 .= chr(0x09); - ++$c; - break; - case $substr_chrs_c_2 == '\n': - $utf8 .= chr(0x0A); - ++$c; - break; - case $substr_chrs_c_2 == '\f': - $utf8 .= chr(0x0C); - ++$c; - break; - case $substr_chrs_c_2 == '\r': - $utf8 .= chr(0x0D); - ++$c; - break; - - case $substr_chrs_c_2 == '\\"': - case $substr_chrs_c_2 == '\\\'': - case $substr_chrs_c_2 == '\\\\': - case $substr_chrs_c_2 == '\\/': - if (($delim == '"' && $substr_chrs_c_2 != '\\\'') || - ($delim == "'" && $substr_chrs_c_2 != '\\"')) { - $utf8 .= $chrs{++$c}; - } - break; - - case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)): - // single, escaped unicode character - $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2))) - . chr(hexdec(substr($chrs, ($c + 4), 2))); - $utf8 .= $this->utf162utf8($utf16); - $c += 5; - break; - - case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F): - $utf8 .= $chrs{$c}; - break; - - case ($ord_chrs_c & 0xE0) == 0xC0: - // characters U-00000080 - U-000007FF, mask 110XXXXX - //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $utf8 .= substr($chrs, $c, 2); - ++$c; - break; - - case ($ord_chrs_c & 0xF0) == 0xE0: - // characters U-00000800 - U-0000FFFF, mask 1110XXXX - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $utf8 .= substr($chrs, $c, 3); - $c += 2; - break; - - case ($ord_chrs_c & 0xF8) == 0xF0: - // characters U-00010000 - U-001FFFFF, mask 11110XXX - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $utf8 .= substr($chrs, $c, 4); - $c += 3; - break; - - case ($ord_chrs_c & 0xFC) == 0xF8: - // characters U-00200000 - U-03FFFFFF, mask 111110XX - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $utf8 .= substr($chrs, $c, 5); - $c += 4; - break; - - case ($ord_chrs_c & 0xFE) == 0xFC: - // characters U-04000000 - U-7FFFFFFF, mask 1111110X - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $utf8 .= substr($chrs, $c, 6); - $c += 5; - break; - - } - - } - - return $utf8; - - } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) { - // array, or object notation - - if ($str{0} == '[') { - $stk = array(SERVICES_JSON_IN_ARR); - $arr = array(); - } else { - if ($this->use & SERVICES_JSON_LOOSE_TYPE) { - $stk = array(SERVICES_JSON_IN_OBJ); - $obj = array(); - } else { - $stk = array(SERVICES_JSON_IN_OBJ); - $obj = new stdClass(); - } - } - - array_push($stk, array('what' => SERVICES_JSON_SLICE, - 'where' => 0, - 'delim' => false)); - - $chrs = substr($str, 1, -1); - $chrs = $this->reduce_string($chrs); - - if ($chrs == '') { - if (reset($stk) == SERVICES_JSON_IN_ARR) { - return $arr; - - } else { - return $obj; - - } - } - - //print("\nparsing {$chrs}\n"); - - $strlen_chrs = strlen($chrs); - - for ($c = 0; $c <= $strlen_chrs; ++$c) { - - $top = end($stk); - $substr_chrs_c_2 = substr($chrs, $c, 2); - - if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) { - // found a comma that is not inside a string, array, etc., - // OR we've reached the end of the character list - $slice = substr($chrs, $top['where'], ($c - $top['where'])); - array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false)); - //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); - - if (reset($stk) == SERVICES_JSON_IN_ARR) { - // we are in an array, so just push an element onto the stack - array_push($arr, $this->decode($slice)); - - } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) { - // we are in an object, so figure - // out the property name and set an - // element in an associative array, - // for now - $parts = array(); - - if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { - // "name":value pair - $key = $this->decode($parts[1]); - $val = $this->decode($parts[2]); - - if ($this->use & SERVICES_JSON_LOOSE_TYPE) { - $obj[$key] = $val; - } else { - $obj->$key = $val; - } - } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { - // name:value pair, where name is unquoted - $key = $parts[1]; - $val = $this->decode($parts[2]); - - if ($this->use & SERVICES_JSON_LOOSE_TYPE) { - $obj[$key] = $val; - } else { - $obj->$key = $val; - } - } - - } - - } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) { - // found a quote, and we are not inside a string - array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c})); - //print("Found start of string at {$c}\n"); - - } elseif (($chrs{$c} == $top['delim']) && - ($top['what'] == SERVICES_JSON_IN_STR) && - (($chrs{$c - 1} != '\\') || - ($chrs{$c - 1} == '\\' && $chrs{$c - 2} == '\\'))) { - // found a quote, we're in a string, and it's not escaped - array_pop($stk); - //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); - - } elseif (($chrs{$c} == '[') && - in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { - // found a left-bracket, and we are in an array, object, or slice - array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false)); - //print("Found start of array at {$c}\n"); - - } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) { - // found a right-bracket, and we're in an array - array_pop($stk); - //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); - - } elseif (($chrs{$c} == '{') && - in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { - // found a left-brace, and we are in an array, object, or slice - array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false)); - //print("Found start of object at {$c}\n"); - - } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) { - // found a right-brace, and we're in an object - array_pop($stk); - //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); - - } elseif (($substr_chrs_c_2 == '/*') && - in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { - // found a comment start, and we are in an array, object, or slice - array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false)); - $c++; - //print("Found start of comment at {$c}\n"); - - } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) { - // found a comment end, and we're in one now - array_pop($stk); - $c++; - - for ($i = $top['where']; $i <= $c; ++$i) - $chrs = substr_replace($chrs, ' ', $i, 1); - - //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); - - } - - } - - if (reset($stk) == SERVICES_JSON_IN_ARR) { - return $arr; - - } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) { - return $obj; - - } - - } - } - } - - /** - * @todo Ultimately, this should just call PEAR::isError() - */ - function isError($data, $code = null) - { - if (class_exists('pear')) { - return PEAR::isError($data, $code); - } elseif (is_object($data) && (get_class($data) == 'services_json_error' || - is_subclass_of($data, 'services_json_error'))) { - return true; - } - - return false; - } -} - -if (class_exists('PEAR_Error')) { - - class Services_JSON_Error extends PEAR_Error - { - function Services_JSON_Error($message = 'unknown error', $code = null, - $mode = null, $options = null, $userinfo = null) - { - parent::PEAR_Error($message, $code, $mode, $options, $userinfo); - } - } - -} else { - - /** - * @todo Ultimately, this class shall be descended from PEAR_Error - */ - class Services_JSON_Error - { - function Services_JSON_Error($message = 'unknown error', $code = null, - $mode = null, $options = null, $userinfo = null) - { - - } - } - -} - -?> \ No newline at end of file diff --git a/ext/chatbox/php/yshout.class.php b/ext/chatbox/php/yshout.class.php index e0074cba..e3b3f02b 100644 --- a/ext/chatbox/php/yshout.class.php +++ b/ext/chatbox/php/yshout.class.php @@ -246,7 +246,6 @@ class YShout { } } } - } diff --git a/ext/chatbox/yshout.php b/ext/chatbox/yshout.php index edb35f55..0994309f 100644 --- a/ext/chatbox/yshout.php +++ b/ext/chatbox/yshout.php @@ -1,8 +1,10 @@ "$str. \n File: $file \n Line: $line" ); - if (function_exists('jsonEncode')) - echo jsonEncode($err); - else - echo $err['yError']; + echo json_encode($err); + exit; } -?> \ No newline at end of file diff --git a/ext/comment/main.php b/ext/comment/main.php index f64247e2..e8cd8804 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -12,8 +12,18 @@ require_once "lib/akismet.class.php"; class CommentPostingEvent extends Event { - var $image_id, $user, $comment; + /** @var int */ + public $image_id; + /** @var \User */ + public $user; + /** @var string */ + public $comment; + /** + * @param int $image_id + * @param \User $user + * @param string $comment + */ public function __construct($image_id, $user, $comment) { $this->image_id = $image_id; $this->user = $user; @@ -27,8 +37,12 @@ class CommentPostingEvent extends Event { * and what should be kept? */ class CommentDeletionEvent extends Event { - var $comment_id; + /** @var int */ + public $comment_id; + /** + * @param int $comment_id + */ public function __construct($comment_id) { $this->comment_id = $comment_id; } @@ -54,11 +68,18 @@ class Comment { $this->posted = $row['posted']; } + /** + * @param \User $user + * @return mixed + */ public static function count_comments_by_user($user) { global $database; return $database->get_one("SELECT COUNT(*) AS count FROM comments WHERE owner_id=:owner_id", array("owner_id"=>$user->id)); } + /** + * @return null|User + */ public function get_owner() { if(empty($this->owner)) $this->owner = User::by_id($this->owner_id); return $this->owner; @@ -265,19 +286,20 @@ class CommentList extends Extension { } public function onSearchTermParse(SearchTermParseEvent $event) { + global $database; + $matches = array(); + if(preg_match("/^comments([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)$/i", $event->term, $matches)) { $cmp = ltrim($matches[1], ":") ?: "="; $comments = $matches[2]; $event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM comments GROUP BY image_id HAVING count(image_id) $cmp $comments)")); } else if(preg_match("/^commented_by[=|:](.*)$/i", $event->term, $matches)) { - global $database; $user = User::by_name($matches[1]); if(!is_null($user)) { $user_id = $user->id; - } - else { + } else { $user_id = -1; } @@ -290,13 +312,18 @@ class CommentList extends Extension { } // page building {{{ + /** + * @param int $current_page + */ private function build_page(/*int*/ $current_page) { - global $page, $config, $database, $user; + global $database, $user; if(class_exists("Ratings")) { $user_ratings = Ratings::get_user_privs($user); + } else { + $user_ratings = ""; } - + $where = SPEED_HAX ? "WHERE posted > now() - interval '24 hours'" : ""; $total_pages = $database->cache->get("comment_pages"); @@ -341,8 +368,12 @@ class CommentList extends Extension { // }}} // get comments {{{ + /** + * @param int $count + * @return array + */ private function get_recent_comments($count) { - global $config, $database; + global $database; $rows = $database->get_all(" SELECT users.id as user_id, users.name as user_name, users.email as user_email, users.class as user_class, @@ -361,8 +392,14 @@ class CommentList extends Extension { return $comments; } + /** + * @param int $user_id + * @param int $count + * @param int $offset + * @return array + */ private function get_user_comments(/*int*/ $user_id, /*int*/ $count, /*int*/ $offset=0) { - global $config, $database; + global $database; $rows = $database->get_all(" SELECT users.id as user_id, users.name as user_name, users.email as user_email, users.class as user_class, @@ -382,8 +419,12 @@ class CommentList extends Extension { return $comments; } + /** + * @param int $image_id + * @return array + */ private function get_comments(/*int*/ $image_id) { - global $config, $database; + global $database; $i_image_id = int_escape($image_id); $rows = $database->get_all(" SELECT @@ -425,6 +466,9 @@ class CommentList extends Extension { return (count($result) >= $max); } + /** + * @return bool + */ private function hash_match() { return ($_POST['hash'] == $this->get_hash()); } @@ -440,6 +484,10 @@ class CommentList extends Extension { return md5($_SERVER['REMOTE_ADDR'] . date("%Y%m%d")); } + /** + * @param string $text + * @return bool + */ private function is_spam_akismet(/*string*/ $text) { global $config, $user; if(strlen($config->get_string('comment_wordpress_key')) > 0) { @@ -478,11 +526,22 @@ class CommentList extends Extension { return false; } + /** + * @param int $image_id + * @param int $comment + * @return null + */ private function is_dupe(/*int*/ $image_id, /*string*/ $comment) { global $database; return ($database->get_row("SELECT * FROM comments WHERE image_id=:image_id AND comment=:comment", array("image_id"=>$image_id, "comment"=>$comment))); } // do some checks + + /** + * @param int $pagenum + * @param int $maxpage + * @return int + */ private function sanity_check_pagenumber(/*int*/ $pagenum, /*int*/ $maxpage){ if (!is_numeric($pagenum)){ $pagenum=1; @@ -496,6 +555,12 @@ class CommentList extends Extension { return $pagenum; } + /** + * @param int $image_id + * @param User $user + * @param string $comment + * @throws CommentPostingException + */ private function add_comment_wrapper(/*int*/ $image_id, User $user, /*string*/ $comment) { global $database, $config; diff --git a/ext/comment/theme.php b/ext/comment/theme.php index 3a08c695..11f440d1 100644 --- a/ext/comment/theme.php +++ b/ext/comment/theme.php @@ -18,8 +18,12 @@ class CommentListTheme extends Themelet { } /** - * Display a page with a list of images, and for each image, - * the image's comments + * Display a page with a list of images, and for each image, the image's comments. + * + * @param array $images + * @param int $page_number + * @param int $total_pages + * @param bool $can_post */ public function display_comment_list($images, $page_number, $total_pages, $can_post) { global $config, $page, $user; @@ -119,9 +123,9 @@ class CommentListTheme extends Themelet { /** - * Add some comments to the page, probably in a sidebar + * Add some comments to the page, probably in a sidebar. * - * $comments = an array of Comment objects to be shown + * @param \Comment[] $comments An array of Comment objects to be shown */ public function display_recent_comments($comments) { global $page; @@ -136,7 +140,11 @@ class CommentListTheme extends Themelet { /** - * Show comments for an image + * Show comments for an image. + * + * @param Image $image + * @param \Comment[] $comments + * @param bool $postbox */ public function display_image_comments(Image $image, $comments, $postbox) { global $page; @@ -153,9 +161,12 @@ class CommentListTheme extends Themelet { /** - * Show comments made by a user + * Show comments made by a user. + * + * @param \Comment[] $comments + * @param \User $user */ - public function display_recent_user_comments($comments, $user) { + public function display_recent_user_comments($comments, User $user) { global $page; $html = ""; foreach($comments as $comment) { @@ -170,7 +181,13 @@ class CommentListTheme extends Themelet { $page->add_block(new Block("Comments", $html, "left", 70, "comment-list-user")); } - public function display_all_user_comments($comments, $page_number, $total_pages, $user) { + /** + * @param \Comment[] $comments + * @param int $page_number + * @param int $total_pages + * @param \User $user + */ + public function display_all_user_comments($comments, $page_number, $total_pages, User $user) { global $page; assert(is_numeric($page_number)); @@ -203,7 +220,12 @@ class CommentListTheme extends Themelet { $this->display_paginator($page, "comment/beta-search/{$user->name}", null, $page_number, $total_pages); } - protected function comment_to_html($comment, $trim=false) { + /** + * @param \Comment $comment + * @param bool $trim + * @return string + */ + protected function comment_to_html(Comment $comment, $trim=false) { global $config, $user; $tfe = new TextFormattingEvent($comment->comment); @@ -276,6 +298,10 @@ class CommentListTheme extends Themelet { return $html; } + /** + * @param int $image_id + * @return string + */ protected function build_postbox(/*int*/ $image_id) { global $config; diff --git a/ext/emoticons/main.php b/ext/emoticons/main.php index a33b06c7..e6245daf 100644 --- a/ext/emoticons/main.php +++ b/ext/emoticons/main.php @@ -13,18 +13,32 @@ * add more emoticons by uploading images into that folder. */ +/** + * Class Emoticons + */ class Emoticons extends FormatterExtension { + /** + * @param string $text + * @return string + */ public function format(/*string*/ $text) { $data_href = get_base_href(); $text = preg_replace("/:([a-z]*?):/s", "", $text); return $text; } + /** + * @param string $text + * @return string + */ public function strip(/*string*/ $text) { return $text; } } +/** + * Class EmoticonList + */ class EmoticonList extends Extension { public function onPageRequest(PageRequestEvent $event) { if($event->page_matches("emote/list")) { diff --git a/ext/emoticons/theme.php b/ext/emoticons/theme.php index dff9f98a..07f033dd 100644 --- a/ext/emoticons/theme.php +++ b/ext/emoticons/theme.php @@ -1,5 +1,8 @@ $image_id, "user_id"=>$user_id)); } - + + /** + * @param Image $image + * @return array + */ private function list_persons_who_have_favorited(Image $image) { global $database; diff --git a/ext/featured/theme.php b/ext/featured/theme.php index 35a64a36..9fc6a74f 100644 --- a/ext/featured/theme.php +++ b/ext/featured/theme.php @@ -1,26 +1,37 @@ add_block(new Block("Featured Image", $this->build_featured_html($image), "left", 3)); } + /** + * @param int $image_id + * @return string + */ public function get_buttons_html(/*int*/ $image_id) { global $user; return " ".make_form(make_link("featured_image/set"))." ".$user->get_auth_html()." - + "; } - + + /** + * @param Image $image + * @param null|string $query + * @return string + */ public function build_featured_html(Image $image, $query=null) { - global $config; $i_id = int_escape($image->id); $h_view_link = make_link("post/view/$i_id", $query); $h_thumb_link = $image->get_thumb_link(); @@ -29,7 +40,7 @@ class FeaturedTheme extends Themelet { return " - $h_tip + {$h_tip} "; } diff --git a/ext/handle_archive/main.php b/ext/handle_archive/main.php index 3f61ad60..fb423d79 100644 --- a/ext/handle_archive/main.php +++ b/ext/handle_archive/main.php @@ -39,7 +39,10 @@ class ArchiveFileHandler extends Extension { } } - + /** + * @param $ext + * @return bool + */ private function supported_ext($ext) { $exts = array("zip"); return in_array(strtolower($ext), $exts); diff --git a/ext/handle_flash/main.php b/ext/handle_flash/main.php index f84153ad..58d93a3f 100644 --- a/ext/handle_flash/main.php +++ b/ext/handle_flash/main.php @@ -7,15 +7,29 @@ */ class FlashFileHandler extends DataHandlerExtension { + /** + * @param string $hash + * @return bool + */ protected function create_thumb($hash) { copy("ext/handle_flash/thumb.jpg", warehouse_path("thumbs", $hash)); + return true; } + /** + * @param string $ext + * @return bool + */ protected function supported_ext($ext) { $exts = array("swf"); return in_array(strtolower($ext), $exts); } + /** + * @param string $filename + * @param array $metadata + * @return Image|null + */ protected function create_image_from_data(/*string*/ $filename, /*array*/ $metadata) { $image = new Image(); @@ -35,6 +49,10 @@ class FlashFileHandler extends DataHandlerExtension { return $image; } + /** + * @param $file + * @return bool + */ protected function check_contents(/*string*/ $file) { if (!file_exists($file)) return false; diff --git a/ext/handle_ico/main.php b/ext/handle_ico/main.php index dae069c8..185bd7f3 100644 --- a/ext/handle_ico/main.php +++ b/ext/handle_ico/main.php @@ -49,12 +49,20 @@ class IcoFileHandler extends Extension { } } - + /** + * @param $ext + * @return bool + */ private function supported_ext($ext) { $exts = array("ico", "ani", "cur"); return in_array(strtolower($ext), $exts); } + /** + * @param $filename + * @param $metadata + * @return Image + */ private function create_image_from_data($filename, $metadata) { $image = new Image(); @@ -77,6 +85,10 @@ class IcoFileHandler extends Extension { return $image; } + /** + * @param $file + * @return bool + */ private function check_contents($file) { if(!file_exists($file)) return false; $fp = fopen($file, "r"); @@ -85,6 +97,10 @@ class IcoFileHandler extends Extension { return ($header['null'] == 0 && ($header['type'] == 0 || $header['type'] == 1)); } + /** + * @param $hash + * @return bool + */ private function create_thumb($hash) { global $config; diff --git a/ext/handle_mp3/main.php b/ext/handle_mp3/main.php index be807472..691fc644 100644 --- a/ext/handle_mp3/main.php +++ b/ext/handle_mp3/main.php @@ -6,15 +6,29 @@ */ class MP3FileHandler extends DataHandlerExtension { + /** + * @param string $hash + * @return bool + */ protected function create_thumb($hash) { copy("ext/handle_mp3/thumb.jpg", warehouse_path("thumbs", $hash)); + return true; } + /** + * @param string $ext + * @return bool + */ protected function supported_ext($ext) { $exts = array("mp3"); return in_array(strtolower($ext), $exts); } + /** + * @param string $filename + * @param array $metadata + * @return Image|null + */ protected function create_image_from_data($filename, $metadata) { global $config; @@ -47,6 +61,10 @@ class MP3FileHandler extends DataHandlerExtension { return $image; } + /** + * @param $file + * @return bool + */ protected function check_contents($file) { if (file_exists($file)) { require_once('lib/getid3/getid3/getid3.php'); diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index bf345352..77b72be7 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -7,12 +7,21 @@ */ class PixelFileHandler extends DataHandlerExtension { + /** + * @param string $ext + * @return bool + */ protected function supported_ext($ext) { $exts = array("jpg", "jpeg", "gif", "png"); $ext = (($pos = strpos($ext,'?')) !== false) ? substr($ext,0,$pos) : $ext; return in_array(strtolower($ext), $exts); } + /** + * @param string $filename + * @param array $metadata + * @return Image|null + */ protected function create_image_from_data(/*string*/ $filename, /*array*/ $metadata) { $image = new Image(); @@ -32,6 +41,10 @@ class PixelFileHandler extends DataHandlerExtension { return $image; } + /** + * @param string $file + * @return bool + */ protected function check_contents(/*string*/ $file) { $valid = Array(IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG); if(!file_exists($file)) return false; @@ -41,6 +54,10 @@ class PixelFileHandler extends DataHandlerExtension { return false; } + /** + * @param string $hash + * @return bool + */ protected function create_thumb(/*string*/ $hash) { $outname = warehouse_path("thumbs", $hash); if(file_exists($outname)) { @@ -49,6 +66,10 @@ class PixelFileHandler extends DataHandlerExtension { return $this->create_thumb_force($hash); } + /** + * @param $hash + * @return bool + */ protected function create_thumb_force(/*string*/ $hash) { global $config; @@ -69,7 +90,10 @@ class PixelFileHandler extends DataHandlerExtension { return $ok; } - + + /** + * @param ImageAdminBlockBuildingEvent $event + */ public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) { $event->add_part("
@@ -91,6 +115,12 @@ class PixelFileHandler extends DataHandlerExtension { } // IM thumber {{{ + + /** + * @param string $inname + * @param string $outname + * @return bool + */ private function make_thumb_convert(/*string*/ $inname, /*string*/ $outname) { global $config; @@ -124,6 +154,11 @@ class PixelFileHandler extends DataHandlerExtension { } // }}} // epeg thumber {{{ + /** + * @param string $inname + * @param string $outname + * @return bool + */ private function make_thumb_epeg(/*string*/ $inname, /*string*/ $outname) { global $config; $w = $config->get_int("thumb_width"); @@ -132,6 +167,11 @@ class PixelFileHandler extends DataHandlerExtension { } // }}} // GD thumber {{{ + /** + * @param string $inname + * @param string $outname + * @return bool + */ private function make_thumb_gd(/*string*/ $inname, /*string*/ $outname) { global $config; $thumb = $this->get_thumb($inname); @@ -140,6 +180,10 @@ class PixelFileHandler extends DataHandlerExtension { return $ok; } + /** + * @param string $tmpname + * @return resource + */ private function get_thumb(/*string*/ $tmpname) { global $config; diff --git a/ext/handle_svg/main.php b/ext/handle_svg/main.php index d27bb6f0..b6f562be 100644 --- a/ext/handle_svg/main.php +++ b/ext/handle_svg/main.php @@ -51,11 +51,20 @@ class SVGFileHandler extends Extension { } } + /** + * @param $ext + * @return bool + */ private function supported_ext($ext) { $exts = array("svg"); return in_array(strtolower($ext), $exts); } + /** + * @param $filename + * @param $metadata + * @return Image + */ private function create_image_from_data($filename, $metadata) { global $config; @@ -75,21 +84,30 @@ class SVGFileHandler extends Extension { return $image; } + /** + * @param $file + * @return bool + */ private function check_contents($file) { if(!file_exists($file)) return false; $msp = new MiniSVGParser($file); - return $msp->valid; + return bool_escape($msp->valid); } } class MiniSVGParser { - var $valid=false, $width=0, $height=0; + /** @var bool */ + public $valid=false; + /** @var int */ + public $width=0; + /** @var int */ + public $height=0; function __construct($file) { $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, array($this, "startElement"), array($this, "endElement")); - $this->valid = xml_parse($xml_parser, file_get_contents($file), true); + $this->valid = bool_escape(xml_parse($xml_parser, file_get_contents($file), true)); xml_parser_free($xml_parser); } diff --git a/ext/handle_video/main.php b/ext/handle_video/main.php index e08c005a..d9d0cfd3 100644 --- a/ext/handle_video/main.php +++ b/ext/handle_video/main.php @@ -2,6 +2,7 @@ /* * Name: Handle Video * Author: velocity37 + * Modified By: Shish , jgen * License: GPLv2 * Description: Handle FLV, MP4, OGV and WEBM video files. * Documentation: @@ -17,17 +18,87 @@ */ class VideoFileHandler extends DataHandlerExtension { - protected function create_thumb($hash) { - copy("ext/handle_video/thumb.jpg", warehouse_path("thumbs", $hash)); + public function onInitExt(InitExtEvent $event) { + global $config; + $config->set_default_string('video_thumb_engine', 'static'); + $config->set_default_string('thumb_ffmpeg_path', ''); } + public function onSetupBuilding(SetupBuildingEvent $event) { + global $config; + + $thumbers = array(); + $thumbers['None'] = "static"; + $thumbers['ffmpeg'] = "ffmpeg"; + + $sb = new SetupBlock("Video Thumbnail Options"); + + $sb->add_choice_option("video_thumb_engine", $thumbers, "Engine: "); + + //if($config->get_string("video_thumb_engine") == "ffmpeg") { + $sb->add_label("
Path to ffmpeg: "); + $sb->add_text_option("thumb_ffmpeg_path"); + //} + $event->panel->add_block($sb); + } + + /** + * @param string $hash + * @return bool + */ + protected function create_thumb($hash) { + global $config; + + // this is never used... + //$q = $config->get_int("thumb_quality"); + + $ok = false; + + switch($config->get_string("video_thumb_engine")) + { + default: + case 'static': + $outname = warehouse_path("thumbs", $hash); + copy("ext/handle_video/thumb.jpg", $outname); + $ok = true; + break; + case 'ffmpeg': + $ffmpeg = escapeshellarg($config->get_string("thumb_ffmpeg_path")); + + $w = (int)$config->get_int("thumb_width"); + $h = (int)$config->get_int("thumb_height"); + $inname = escapeshellarg(warehouse_path("images", $hash)); + $outname = escapeshellarg(warehouse_path("thumbs", $hash)); + + $cmd = escapeshellcmd("{$ffmpeg} -i {$inname} -s {$w}x{$h} -ss 00:00:00.0 -f image2 -vframes 1 {$outname}"); + exec($cmd, $output, $ret); + + // TODO: We should really check the result of the exec to see if it really succeeded. + $ok = true; + + log_debug('handle_video', "Generating thumbnail with command `$cmd`, returns $ret"); + break; + } + + return $ok; + } + + /** + * @param string $ext + * @return bool + */ protected function supported_ext($ext) { $exts = array("flv", "mp4", "m4v", "ogv", "webm"); return in_array(strtolower($ext), $exts); } + /** + * @param string $filename + * @param array $metadata + * @return Image|null + */ protected function create_image_from_data($filename, $metadata) { - global $config; + //global $config; $image = new Image(); @@ -67,12 +138,21 @@ class VideoFileHandler extends DataHandlerExtension { return $image; } + /** + * @param $file + * @return bool + */ protected function check_contents($file) { if (file_exists($file)) { require_once('lib/getid3/getid3/getid3.php'); $getID3 = new getID3; $ThisFileInfo = $getID3->analyze($file); - if (isset($ThisFileInfo['mime_type']) && ($ThisFileInfo['mime_type'] == "video/webm" || $ThisFileInfo['mime_type'] == "video/quicktime" || $ThisFileInfo['mime_type'] == "application/ogg" || $ThisFileInfo['mime_type'] == 'video/x-flv')) { + if (isset($ThisFileInfo['mime_type']) && ( + $ThisFileInfo['mime_type'] == "video/webm" || + $ThisFileInfo['mime_type'] == "video/quicktime" || + $ThisFileInfo['mime_type'] == "application/ogg" || + $ThisFileInfo['mime_type'] == 'video/x-flv') + ) { return TRUE; } } diff --git a/ext/handle_video/theme.php b/ext/handle_video/theme.php index d6d7f723..3cb88674 100644 --- a/ext/handle_video/theme.php +++ b/ext/handle_video/theme.php @@ -7,27 +7,38 @@ class VideoFileHandlerTheme extends Themelet { $ext = strtolower($image->get_ext()); if ($ext == "mp4") { - $html = "Video not playing? Click here to download the file.
"; } elseif ($ext == "flv") { - $html = "Video not playing? Click here to download the file.
"; + $html = "Video not playing? Click here to download the file.
+ + + + + + + "; } elseif ($ext == "ogv") { - $html = "Video not playing? Click here to download the file.