Merge branch 'develop' of https://github.com/shish/shimmie2 into develop

This commit is contained in:
Shish 2017-09-21 05:25:48 +01:00
commit 2628c2c5d9
108 changed files with 1061 additions and 2306 deletions

View File

@ -1,6 +1,5 @@
language: php
php:
- 5.6
- 7.0
- 7.1

View File

@ -29,7 +29,7 @@ check out one of the versioned branches.
# Requirements
- MySQL/MariaDB 5.1+ (with experimental support for PostgreSQL 9+ and SQLite 3)
- [Stable PHP](https://en.wikipedia.org/wiki/PHP#Release_history) (5.6+ as of writing)
- [Stable PHP](https://en.wikipedia.org/wiki/PHP#Release_history) (7.0+ as of writing)
- GD or ImageMagick
# Installation
@ -50,33 +50,6 @@ check out one of the versioned branches.
4. Run `composer install` in the shimmie folder.
5. Follow instructions noted in "Installation" starting from step 3.
## 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 = "<proto>://<username>:<password>@<host>/<database>";
```
NEW Format:
```php
define("DATABASE_DSN", "<proto>:user=<username>;password=<password>;host=<host>;dbname=<database>");
```
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

View File

@ -23,22 +23,23 @@
],
"require" : {
"php" : ">=5.6",
"php" : ">=7.0",
"flexihash/flexihash" : "^2.0.0",
"ifixit/php-akismet" : "1.*",
"google/recaptcha" : "~1.1",
"dapphp/securimage" : "3.6.*",
"shish/libcontext-php" : "dev-master",
"bower-asset/jquery" : "1.12.3",
"bower-asset/jquery-timeago" : "1.5.2",
"bower-asset/tablesorter" : "2.*",
"bower-asset/tablesorter" : "dev-master",
"bower-asset/mediaelement" : "2.21.1",
"bower-asset/js-cookie" : "2.1.1"
},
"require-dev" : {
"phpunit/phpunit" : "5.*"
"phpunit/phpunit" : "6.*"
},
"vendor-copy": {

531
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "a450c93bec1d8f352be123e31bf84ac6",
"content-hash": "eb5180245fbf27fb02d9a4018a2ff059",
"packages": [
{
"name": "bower-asset/jquery",
@ -97,34 +97,12 @@
"type": "zip",
"url": "https://api.github.com/repos/christianbach/tablesorter/zipball/774576308e8a25aa9d68b7fe3069b79543992d7a",
"reference": "774576308e8a25aa9d68b7fe3069b79543992d7a",
"shasum": ""
},
"type": "bower-asset-library",
"extra": {
"bower-asset-main": [
"jquery.metadata.js",
"jquery.tablesorter.min.js"
],
"bower-asset-ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"branch-alias": {
"dev-master": "2.0.5-dev"
}
"shasum": null
},
"type": "bower-asset",
"license": [
"MIT,GPL"
],
"description": "Flexible client-side table sorting",
"keywords": [
"client-side",
"sort",
"table"
],
"time": "2015-12-03T01:22:52+00:00"
},
{
@ -281,37 +259,78 @@
"reference": "fd4ff50eb577457c1b7b887401663e91e77625ae"
},
"type": "library"
},
{
"name": "shish/libcontext-php",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/shish/libcontext-php.git",
"reference": "7c80a23c56cfb207c02c18292720d3bd5aac474d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/shish/libcontext-php/zipball/7c80a23c56cfb207c02c18292720d3bd5aac474d",
"reference": "7c80a23c56cfb207c02c18292720d3bd5aac474d",
"shasum": ""
},
"require": {
"php": ">=7.0"
},
"require-dev": {
"phpunit/phpunit": "6.*"
},
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Shish",
"email": "webmaster@shishnet.org",
"homepage": "http://shishnet.org",
"role": "Developer"
}
],
"description": "A performance monitoring thing",
"homepage": "https://github.com/shish/libcontext-php",
"keywords": [
"performance",
"profiler"
],
"time": "2017-09-21T03:48:29+00:00"
}
],
"packages-dev": [
{
"name": "doctrine/instantiator",
"version": "dev-master",
"version": "1.0.x-dev",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
"reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda"
"reference": "8e884e78f9f0eb1329e445619e04456e64d8051d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda",
"reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d",
"reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
"shasum": ""
},
"require": {
"php": "^7.1"
"php": ">=5.3,<8.0-DEV"
},
"require-dev": {
"athletic/athletic": "~0.1.8",
"ext-pdo": "*",
"ext-phar": "*",
"phpunit/phpunit": "^6.2.3",
"squizlabs/php_codesniffer": "^3.0.2"
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
"dev-master": "1.0.x-dev"
}
},
"autoload": {
@ -336,7 +355,7 @@
"constructor",
"instantiate"
],
"time": "2017-07-22T11:58:36+00:00"
"time": "2015-06-14T21:17:01+00:00"
},
{
"name": "myclabs/deep-copy",
@ -380,6 +399,108 @@
],
"time": "2017-04-12T18:52:22+00:00"
},
{
"name": "phar-io/manifest",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/phar-io/manifest.git",
"reference": "014feadb268809af7c8e2f7ccd396b8494901f58"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phar-io/manifest/zipball/014feadb268809af7c8e2f7ccd396b8494901f58",
"reference": "014feadb268809af7c8e2f7ccd396b8494901f58",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-phar": "*",
"phar-io/version": "^1.0.1",
"php": "^5.6 || ^7.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Arne Blankerts",
"email": "arne@blankerts.de",
"role": "Developer"
},
{
"name": "Sebastian Heuer",
"email": "sebastian@phpeople.de",
"role": "Developer"
},
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "Developer"
}
],
"description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)",
"time": "2017-04-07T07:07:10+00:00"
},
{
"name": "phar-io/version",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/phar-io/version.git",
"reference": "a70c0ced4be299a63d32fa96d9281d03e94041df"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phar-io/version/zipball/a70c0ced4be299a63d32fa96d9281d03e94041df",
"reference": "a70c0ced4be299a63d32fa96d9281d03e94041df",
"shasum": ""
},
"require": {
"php": "^5.6 || ^7.0"
},
"type": "library",
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Arne Blankerts",
"email": "arne@blankerts.de",
"role": "Developer"
},
{
"name": "Sebastian Heuer",
"email": "sebastian@phpeople.de",
"role": "Developer"
},
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "Developer"
}
],
"description": "Library for handling version information and constraints",
"time": "2017-03-05T17:38:23+00:00"
},
{
"name": "phpdocumentor/reflection-common",
"version": "dev-master",
@ -591,40 +712,41 @@
},
{
"name": "phpunit/php-code-coverage",
"version": "4.0.x-dev",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d"
"reference": "77a1ba8076365f943e2a3d75573b6c9822840ac6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef7b2f56815df854e66ceaee8ebe9393ae36a40d",
"reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/77a1ba8076365f943e2a3d75573b6c9822840ac6",
"reference": "77a1ba8076365f943e2a3d75573b6c9822840ac6",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-xmlwriter": "*",
"php": "^5.6 || ^7.0",
"phpunit/php-file-iterator": "^1.3",
"phpunit/php-text-template": "^1.2",
"phpunit/php-token-stream": "^1.4.2 || ^2.0",
"sebastian/code-unit-reverse-lookup": "^1.0",
"sebastian/environment": "^1.3.2 || ^2.0",
"sebastian/version": "^1.0 || ^2.0"
"php": "^7.0",
"phpunit/php-file-iterator": "^1.4.2",
"phpunit/php-text-template": "^1.2.1",
"phpunit/php-token-stream": "^2.0",
"sebastian/code-unit-reverse-lookup": "^1.0.1",
"sebastian/environment": "^3.0",
"sebastian/version": "^2.0.1",
"theseer/tokenizer": "^1.1"
},
"require-dev": {
"ext-xdebug": "^2.1.4",
"phpunit/phpunit": "^5.7"
"ext-xdebug": "^2.5",
"phpunit/phpunit": "^6.0"
},
"suggest": {
"ext-xdebug": "^2.5.1"
"ext-xdebug": "^2.5.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0.x-dev"
"dev-master": "5.2.x-dev"
}
},
"autoload": {
@ -650,7 +772,7 @@
"testing",
"xunit"
],
"time": "2017-04-02T07:44:40+00:00"
"time": "2017-08-25T06:32:04+00:00"
},
{
"name": "phpunit/php-file-iterator",
@ -840,16 +962,16 @@
},
{
"name": "phpunit/phpunit",
"version": "5.7.x-dev",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "4eba3374803c6c0903145e8940844e6f1d665c07"
"reference": "e6e7085fbbd2e25f4ca128ac30c1b0d3dd4ef827"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4eba3374803c6c0903145e8940844e6f1d665c07",
"reference": "4eba3374803c6c0903145e8940844e6f1d665c07",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e6e7085fbbd2e25f4ca128ac30c1b0d3dd4ef827",
"reference": "e6e7085fbbd2e25f4ca128ac30c1b0d3dd4ef827",
"shasum": ""
},
"require": {
@ -858,33 +980,35 @@
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-xml": "*",
"myclabs/deep-copy": "~1.3",
"php": "^5.6 || ^7.0",
"phpspec/prophecy": "^1.6.2",
"phpunit/php-code-coverage": "^4.0.4",
"phpunit/php-file-iterator": "~1.4",
"phpunit/php-text-template": "~1.2",
"phpunit/php-timer": "^1.0.6",
"phpunit/phpunit-mock-objects": "^3.2",
"sebastian/comparator": "^1.2.4",
"sebastian/diff": "^1.4.3",
"sebastian/environment": "^1.3.4 || ^2.0",
"sebastian/exporter": "~2.0",
"sebastian/global-state": "^1.1",
"sebastian/object-enumerator": "~2.0",
"sebastian/resource-operations": "~1.0",
"sebastian/version": "~1.0.3|~2.0",
"symfony/yaml": "~2.1|~3.0"
"myclabs/deep-copy": "^1.6.1",
"phar-io/manifest": "^1.0.1",
"phar-io/version": "^1.0",
"php": "^7.0",
"phpspec/prophecy": "^1.7",
"phpunit/php-code-coverage": "^5.2.2",
"phpunit/php-file-iterator": "^1.4.2",
"phpunit/php-text-template": "^1.2.1",
"phpunit/php-timer": "^1.0.9",
"phpunit/phpunit-mock-objects": "^4.0.3",
"sebastian/comparator": "^2.0.2",
"sebastian/diff": "^2.0",
"sebastian/environment": "^3.1",
"sebastian/exporter": "^3.1",
"sebastian/global-state": "^2.0",
"sebastian/object-enumerator": "^3.0.3",
"sebastian/resource-operations": "^1.0",
"sebastian/version": "^2.0.1"
},
"conflict": {
"phpdocumentor/reflection-docblock": "3.0.2"
"phpdocumentor/reflection-docblock": "3.0.2",
"phpunit/dbunit": "<3.0"
},
"require-dev": {
"ext-pdo": "*"
},
"suggest": {
"ext-xdebug": "*",
"phpunit/php-invoker": "~1.1"
"phpunit/php-invoker": "^1.1"
},
"bin": [
"phpunit"
@ -892,7 +1016,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.7.x-dev"
"dev-master": "6.4.x-dev"
}
},
"autoload": {
@ -918,33 +1042,33 @@
"testing",
"xunit"
],
"time": "2017-09-01T08:38:37+00:00"
"time": "2017-09-01T08:39:38+00:00"
},
{
"name": "phpunit/phpunit-mock-objects",
"version": "3.4.x-dev",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
"reference": "a23b761686d50a560cc56233b9ecf49597cc9118"
"reference": "2f789b59ab89669015ad984afa350c4ec577ade0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/a23b761686d50a560cc56233b9ecf49597cc9118",
"reference": "a23b761686d50a560cc56233b9ecf49597cc9118",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/2f789b59ab89669015ad984afa350c4ec577ade0",
"reference": "2f789b59ab89669015ad984afa350c4ec577ade0",
"shasum": ""
},
"require": {
"doctrine/instantiator": "^1.0.2",
"php": "^5.6 || ^7.0",
"phpunit/php-text-template": "^1.2",
"sebastian/exporter": "^1.2 || ^2.0"
"doctrine/instantiator": "^1.0.5",
"php": "^7.0",
"phpunit/php-text-template": "^1.2.1",
"sebastian/exporter": "^3.0"
},
"conflict": {
"phpunit/phpunit": "<5.4.0"
"phpunit/phpunit": "<6.0"
},
"require-dev": {
"phpunit/phpunit": "^5.4"
"phpunit/phpunit": "^6.0"
},
"suggest": {
"ext-soap": "*"
@ -952,7 +1076,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2.x-dev"
"dev-master": "4.0.x-dev"
}
},
"autoload": {
@ -977,7 +1101,7 @@
"mock",
"xunit"
],
"time": "2017-06-30T09:13:00+00:00"
"time": "2017-08-03T14:08:16+00:00"
},
{
"name": "sebastian/code-unit-reverse-lookup",
@ -1026,30 +1150,30 @@
},
{
"name": "sebastian/comparator",
"version": "1.2.x-dev",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "18a5d97c25f408f48acaf6d1b9f4079314c5996a"
"reference": "fb3213355da37bf91569ca7a944af19bc57b80e9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/18a5d97c25f408f48acaf6d1b9f4079314c5996a",
"reference": "18a5d97c25f408f48acaf6d1b9f4079314c5996a",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/fb3213355da37bf91569ca7a944af19bc57b80e9",
"reference": "fb3213355da37bf91569ca7a944af19bc57b80e9",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"sebastian/diff": "~1.2",
"sebastian/exporter": "~1.2 || ~2.0"
"php": "^7.0",
"sebastian/diff": "^2.0",
"sebastian/exporter": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
"phpunit/phpunit": "^6.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
"dev-master": "2.1.x-dev"
}
},
"autoload": {
@ -1080,38 +1204,38 @@
}
],
"description": "Provides the functionality to compare PHP values for equality",
"homepage": "http://www.github.com/sebastianbergmann/comparator",
"homepage": "https://github.com/sebastianbergmann/comparator",
"keywords": [
"comparator",
"compare",
"equality"
],
"time": "2017-03-07T10:34:43+00:00"
"time": "2017-08-20T14:03:32+00:00"
},
{
"name": "sebastian/diff",
"version": "1.4.x-dev",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
"reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4"
"reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4",
"reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/347c1d8b49c5c3ee30c7040ea6fc446790e6bddd",
"reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd",
"shasum": ""
},
"require": {
"php": "^5.3.3 || ^7.0"
"php": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0"
"phpunit/phpunit": "^6.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
"dev-master": "2.0-dev"
}
},
"autoload": {
@ -1138,32 +1262,32 @@
"keywords": [
"diff"
],
"time": "2017-05-22T07:24:03+00:00"
"time": "2017-08-03T08:09:46+00:00"
},
{
"name": "sebastian/environment",
"version": "2.0.x-dev",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
"reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac"
"reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac",
"reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/cd0871b3975fb7fc44d11314fd1ee20925fce4f5",
"reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5",
"shasum": ""
},
"require": {
"php": "^5.6 || ^7.0"
"php": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "^5.0"
"phpunit/phpunit": "^6.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
"dev-master": "3.1.x-dev"
}
},
"autoload": {
@ -1188,34 +1312,34 @@
"environment",
"hhvm"
],
"time": "2016-11-26T07:53:53+00:00"
"time": "2017-07-01T08:51:00+00:00"
},
{
"name": "sebastian/exporter",
"version": "2.0.x-dev",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
"reference": "5e8e30670c3f36481e75211dbbcfd029a41ebf07"
"reference": "234199f4528de6d12aaa58b612e98f7d36adb937"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/5e8e30670c3f36481e75211dbbcfd029a41ebf07",
"reference": "5e8e30670c3f36481e75211dbbcfd029a41ebf07",
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/234199f4528de6d12aaa58b612e98f7d36adb937",
"reference": "234199f4528de6d12aaa58b612e98f7d36adb937",
"shasum": ""
},
"require": {
"php": "^5.3.3 || ^7.0",
"sebastian/recursion-context": "^2.0"
"php": "^7.0",
"sebastian/recursion-context": "^3.0"
},
"require-dev": {
"ext-mbstring": "*",
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0"
"phpunit/phpunit": "^6.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
"dev-master": "3.1.x-dev"
}
},
"autoload": {
@ -1255,27 +1379,27 @@
"export",
"exporter"
],
"time": "2017-03-07T10:36:49+00:00"
"time": "2017-04-03T13:19:02+00:00"
},
{
"name": "sebastian/global-state",
"version": "1.1.x-dev",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/global-state.git",
"reference": "cea85a84b00f2795341ebbbca4fa396347f2494e"
"reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/cea85a84b00f2795341ebbbca4fa396347f2494e",
"reference": "cea85a84b00f2795341ebbbca4fa396347f2494e",
"url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4",
"reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
"php": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "~4.2|~5.0"
"phpunit/phpunit": "^6.0"
},
"suggest": {
"ext-uopz": "*"
@ -1283,7 +1407,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
"dev-master": "2.0-dev"
}
},
"autoload": {
@ -1306,33 +1430,34 @@
"keywords": [
"global state"
],
"time": "2017-02-23T14:11:06+00:00"
"time": "2017-04-27T15:39:26+00:00"
},
{
"name": "sebastian/object-enumerator",
"version": "2.0.x-dev",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/object-enumerator.git",
"reference": "c956fe7a68318639f694fc6bba0c89b7cdf1b08c"
"reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/c956fe7a68318639f694fc6bba0c89b7cdf1b08c",
"reference": "c956fe7a68318639f694fc6bba0c89b7cdf1b08c",
"url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5",
"reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5",
"shasum": ""
},
"require": {
"php": "^5.6 || ^7.0",
"sebastian/recursion-context": "^2.0"
"php": "^7.0",
"sebastian/object-reflector": "^1.1.1",
"sebastian/recursion-context": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7"
"phpunit/phpunit": "^6.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
"dev-master": "3.0.x-dev"
}
},
"autoload": {
@ -1352,32 +1477,77 @@
],
"description": "Traverses array structures and object graphs to enumerate all referenced objects",
"homepage": "https://github.com/sebastianbergmann/object-enumerator/",
"time": "2017-03-07T10:37:45+00:00"
"time": "2017-08-03T12:35:26+00:00"
},
{
"name": "sebastian/recursion-context",
"version": "2.0.x-dev",
"name": "sebastian/object-reflector",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/recursion-context.git",
"reference": "7e4d7c56f6e65d215f71ad913a5256e5439aca1c"
"url": "https://github.com/sebastianbergmann/object-reflector.git",
"reference": "773f97c67f28de00d397be301821b06708fca0be"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/7e4d7c56f6e65d215f71ad913a5256e5439aca1c",
"reference": "7e4d7c56f6e65d215f71ad913a5256e5439aca1c",
"url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be",
"reference": "773f97c67f28de00d397be301821b06708fca0be",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
"php": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
"phpunit/phpunit": "^6.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
"dev-master": "1.1-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
}
],
"description": "Allows reflection of object attributes, including inherited and non-public ones",
"homepage": "https://github.com/sebastianbergmann/object-reflector/",
"time": "2017-03-29T09:07:27+00:00"
},
{
"name": "sebastian/recursion-context",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/recursion-context.git",
"reference": "a0e54bc9bf04e2c5b302236984cebc277631f0f1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/a0e54bc9bf04e2c5b302236984cebc277631f0f1",
"reference": "a0e54bc9bf04e2c5b302236984cebc277631f0f1",
"shasum": ""
},
"require": {
"php": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
}
},
"autoload": {
@ -1405,7 +1575,7 @@
],
"description": "Provides functionality to recursively process PHP variables",
"homepage": "http://www.github.com/sebastianbergmann/recursion-context",
"time": "2017-03-08T08:21:15+00:00"
"time": "2017-03-07T15:09:59+00:00"
},
{
"name": "sebastian/resource-operations",
@ -1493,62 +1663,44 @@
"time": "2016-10-03T07:35:21+00:00"
},
{
"name": "symfony/yaml",
"version": "3.4.x-dev",
"name": "theseer/tokenizer",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "a0e15688972f012156cf1ffa076fe1203bce6bc9"
"url": "https://github.com/theseer/tokenizer.git",
"reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/a0e15688972f012156cf1ffa076fe1203bce6bc9",
"reference": "a0e15688972f012156cf1ffa076fe1203bce6bc9",
"url": "https://api.github.com/repos/theseer/tokenizer/zipball/cb2f008f3f05af2893a87208fe6a6c4985483f8b",
"reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
},
"conflict": {
"symfony/console": "<3.4"
},
"require-dev": {
"symfony/console": "~3.4|~4.0"
},
"suggest": {
"symfony/console": "For validating YAML files using the lint command"
"ext-dom": "*",
"ext-tokenizer": "*",
"ext-xmlwriter": "*",
"php": "^7.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Yaml\\": ""
},
"exclude-from-classmap": [
"/Tests/"
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
"BSD-3-Clause"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
"name": "Arne Blankerts",
"email": "arne@blankerts.de",
"role": "Developer"
}
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"time": "2017-09-17T10:10:45+00:00"
"description": "A small library for converting tokenized PHP source code into XML and potentially other formats",
"time": "2017-04-07T12:08:54+00:00"
},
{
"name": "webmozart/assert",
@ -1603,11 +1755,14 @@
],
"aliases": [],
"minimum-stability": "dev",
"stability-flags": [],
"stability-flags": {
"shish/libcontext-php": 20,
"bower-asset/tablesorter": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": ">=5.6"
"php": ">=7.0"
},
"platform-dev": []
}

View File

@ -4,11 +4,11 @@
* actually do anything as far as the app is concerned
*/
global $config, $database, $user, $page;
global $config, $database, $user, $page, $_shm_ctx;
require_once "core/sys_config.inc.php";
require_once "core/util.inc.php";
require_once "lib/context.php";
require_once "vendor/shish/libcontext-php/context.php";
require_once "vendor/autoload.php";
require_once "core/imageboard.pack.php";
@ -17,34 +17,34 @@ _version_check();
_sanitise_environment();
// load base files
ctx_log_start("Opening files");
$files = array_merge(
$_shm_ctx->log_start("Opening files");
$_shm_files = array_merge(
zglob("core/*.php"),
zglob("ext/{".ENABLED_EXTS."}/main.php")
);
foreach($files as $filename) {
if(basename($filename)[0] != "_") {
require_once $filename;
foreach($_shm_files as $_shm_filename) {
if(basename($_shm_filename)[0] != "_") {
require_once $_shm_filename;
}
}
unset($files);
unset($filename);
ctx_log_endok();
unset($_shm_files);
unset($_shm_filename);
$_shm_ctx->log_endok();
// connect to the database
ctx_log_start("Connecting to DB");
$_shm_ctx->log_start("Connecting to DB");
$database = new Database();
$config = new DatabaseConfig($database);
ctx_log_endok();
$_shm_ctx->log_endok();
// load the theme parts
ctx_log_start("Loading themelets");
$_shm_ctx->log_start("Loading themelets");
foreach(_get_themelet_files(get_theme()) as $themelet) {
require_once $themelet;
}
unset($themelet);
$page = class_exists("CustomPage") ? new CustomPage() : new Page();
ctx_log_endok();
$_shm_ctx->log_endok();
// hook up event handlers
_load_event_listeners();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -92,10 +92,7 @@ abstract class Extension {
$this->theme = $this->get_theme_object(get_called_class());
}
/**
* @return boolean
*/
public function is_live() {
public function is_live(): bool {
global $database;
return (
empty($this->db_support) ||
@ -107,9 +104,9 @@ abstract class Extension {
* Find the theme object for a given extension.
*
* @param string $base
* @return Themelet
* @return Themelet|null
*/
private function get_theme_object($base) {
private function get_theme_object(string $base) {
$custom = 'Custom'.$base.'Theme';
$normal = $base.'Theme';
@ -126,11 +123,10 @@ abstract class Extension {
/**
* Override this to change the priority of the extension,
* lower numbered ones will recieve events first.
*
* lower numbered ones will receive events first.
* @return int
*/
public function get_priority() {
public function get_priority(): int {
return 50;
}
}
@ -141,25 +137,13 @@ abstract class Extension {
* 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);
abstract public function format(string $text): string;
abstract public function strip(string $text): string;
}
/**
@ -169,10 +153,6 @@ abstract class FormatterExtension extends Extension {
* 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);
@ -236,9 +216,6 @@ 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) {
@ -250,9 +227,6 @@ abstract class DataHandlerExtension extends Extension {
}
}
/**
* @param DisplayingImageEvent $event
*/
public function onDisplayingImage(DisplayingImageEvent $event) {
global $page;
if($this->supported_ext($event->image->ext)) {
@ -269,29 +243,9 @@ abstract class DataHandlerExtension extends Extension {
protected function setup() {}
*/
/**
* @param string $ext
* @return bool
*/
abstract protected function supported_ext($ext);
/**
* @param string $tmpname
* @return bool
*/
abstract protected function check_contents($tmpname);
/**
* @param string $filename
* @param array $metadata
* @return Image|null
*/
abstract protected function create_image_from_data($filename, $metadata);
/**
* @param string $hash
* @return bool
*/
abstract protected function create_thumb($hash);
abstract protected function supported_ext(string $ext): bool;
abstract protected function check_contents(string $tmpname): bool;
abstract protected function create_image_from_data(string $filename, array $metadata);
abstract protected function create_thumb(string $hash): bool;
}

View File

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

View File

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

View File

@ -19,8 +19,7 @@
*
*/
/** @private */
function _d($name, $value) {if(!defined($name)) define($name, $value);}
function _d(string $name, $value) {if(!defined($name)) define($name, $value);}
_d("DATABASE_DSN", null); // string PDO database connection details
_d("DATABASE_KA", true); // string Keep database connection alive
_d("CACHE_DSN", null); // string cache connection details
@ -36,12 +35,12 @@ _d("COMPILE_ELS", false); // boolean pre-build the list of event listeners
_d("NICE_URLS", false); // boolean force niceurl mode
_d("SEARCH_ACCEL", false); // boolean use search accelerator
_d("WH_SPLITS", 1); // int how many levels of subfolders to put in the warehouse
_d("VERSION", '2.6.0+'); // string shimmie version
_d("VERSION", '2.7-beta'); // string shimmie version
_d("TIMEZONE", null); // string timezone
_d("CORE_EXTS", "bbcode,user,mail,upload,image,view,handle_pixel,ext_manager,setup,upgrade,handle_404,comment,tag_list,index,tag_edit,alias_editor"); // extensions to always enable
_d("EXTRA_EXTS", ""); // string optional extra extensions
_d("BASE_URL", null); // string force a specific base URL (default is auto-detect)
_d("MIN_PHP_VERSION", '5.6');// string minium supported PHP version
_d("MIN_PHP_VERSION", '7.0');// string minium supported PHP version
/*
* Calculated settings - you should never need to change these

View File

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

View File

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

View File

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

View File

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

View File

@ -12,13 +12,7 @@ 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) {
protected function button(string $name, string $action, bool $protected=false): string {
$c_protected = $protected ? " protected" : "";
$html = make_form(make_link("admin/$action"), "POST", false, "admin$c_protected");
if($protected) {

View File

@ -16,11 +16,7 @@ class AddAliasEvent extends Event {
/** @var string */
public $newtag;
/**
* @param string $oldtag
* @param string $newtag
*/
public function __construct($oldtag, $newtag) {
public function __construct(string $oldtag, string $newtag) {
$this->oldtag = trim($oldtag);
$this->newtag = trim($newtag);
}
@ -131,11 +127,7 @@ class AliasEditor extends Extension {
}
}
/**
* @param Database $database
* @return string
*/
private function get_alias_csv(Database $database) {
private function get_alias_csv(Database $database): string {
$csv = "";
$aliases = $database->get_pairs("SELECT oldtag, newtag FROM aliases ORDER BY newtag");
foreach($aliases as $old => $new) {
@ -144,11 +136,7 @@ class AliasEditor extends Extension {
return $csv;
}
/**
* @param Database $database
* @param string $csv
*/
private function add_alias_csv(Database $database, /*string*/ $csv) {
private function add_alias_csv(Database $database, string $csv) {
$csv = str_replace("\r", "\n", $csv);
foreach(explode("\n", $csv) as $line) {
$parts = str_getcsv($line);
@ -170,9 +158,8 @@ 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 old tag.
*
* @return int
*/
public function get_priority() {return 60;}
public function get_priority(): int {return 60;}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,8 +5,7 @@ class RegenThumbTest extends ShimmiePHPUnitTestCase {
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
$this->get_page("post/view/$image_id");
$_POST['image_id'] = $image_id;
$this->get_page("regen_thumb");
$this->post_page("regen_thumb/one", ['image_id'=>$image_id]);
$this->assert_title("Thumbnail Regenerated");
# FIXME: test that the thumb's modified time has been updated

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -60,9 +60,9 @@ if(document.getElementById("image-container") !== null) {
}
/*
* konachan | sankakucomplex | gelbooru | etc.
* konachan | sankakucomplex | gelbooru (old versions) | etc.
*/
else if(document.getElementById('tag-sidebar') !== null) {
else if(document.getElementById('tag-sidebar') !== null) {
if (typeof tag !== "ftp://ftp." && chk !==1) {
var tag = document.getElementById('tag-sidebar').innerText.replace(/ /g, "_").replace(/[\?_]*(.*?)_(\(\?\)_)?[0-9]+$/gm, "$1 ");
}
@ -106,6 +106,42 @@ else if(document.getElementById('tag-sidebar') !== null) {
}
}
/*
* gelbooru
*/
else if(document.getElementById('tag-list') !== null){
if(typeof tag !== "ftp://ftp." && chk !==1){
var tags = [];
$('#tag-list h3:contains("Tags")').nextUntil(":not(li)").each(function(index){
tags.push($(this).text()
.replace(/ /g, "_")
.replace(/[\?_]*(.*?)_(\(\?\)_)?[0-9]+$/gm, "$1"));
});
tag = tags.join(" ");
}
var source = "http://" + document.location.hostname + (document.location.href.match("\/post\/show\/[0-9]+") || document.location.href.match(/\/index\.php\?page=post&s=view&id=[0-9]+/));
var rating =
$('#tag-list h3:contains("Statistics")').nextUntil(":not(li)")
.filter(':contains("Rating")')
.text().match("Rating: ([a-zA-Z]+)")[1];
var furl =
$('#tag-list h3:contains("Options")').nextUntil(":not(li)")
.filter(':contains("Original image")').find("a").first()[0].href;
// File size is not supported because it's not provided.
if(supext.search(furl.match("[a-zA-Z0-9]+$")[0]) !== -1){
history.pushState(history.state, document.title, location.href);
var href = ste + furl +
"&tags=" + encodeURIComponent(tag) +
"&rating=" + encodeURIComponent(rating) +
"&source=" + encodeURIComponent(source);
location.href = href;
}
else{
alert(notsup);
}
}
/*
* Shimmie
*

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

Some files were not shown because too many files have changed in this diff Show More