aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/sys
diff options
context:
space:
mode:
Diffstat (limited to 'ratatoeskr/sys')
-rw-r--r--ratatoeskr/sys/models.php15
-rw-r--r--ratatoeskr/sys/plugin_api.php2
-rw-r--r--ratatoeskr/sys/pwhash.php2
-rw-r--r--ratatoeskr/sys/translation.php3
-rw-r--r--ratatoeskr/sys/utils.php155
5 files changed, 13 insertions, 164 deletions
diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php
index 626b237..9f81fcf 100644
--- a/ratatoeskr/sys/models.php
+++ b/ratatoeskr/sys/models.php
@@ -278,10 +278,9 @@ class User extends BySQLRowEnabled
*/
public static function create($username, $pwhash)
{
- global $ratatoeskr_settings;
global $db_con;
try {
- $obj = self::by_name($username);
+ self::by_name($username);
} catch (DoesNotExistError $e) {
global $ratatoeskr_settings;
qdb(
@@ -301,7 +300,7 @@ class User extends BySQLRowEnabled
return $obj;
}
- throw new AlreadyExistsError("\"$name\" is already in database.");
+ throw new AlreadyExistsError("\"$username\" is already in database.");
}
protected function populate_by_sqlrow($sqlrow)
@@ -504,7 +503,7 @@ class Group extends BySQLRowEnabled
{
global $db_con;
try {
- $obj = self::by_name($name);
+ self::by_name($name);
} catch (DoesNotExistError $e) {
qdb("INSERT INTO `PREFIX_groups` (`name`) VALUES (?)", $name);
$obj = new self();
@@ -1787,7 +1786,7 @@ class Section extends BySQLRowEnabled
}
try {
- $obj = self::by_name($name);
+ self::by_name($name);
} catch (DoesNotExistError $e) {
$obj = new self();
$obj->name = $name;
@@ -2056,7 +2055,7 @@ class Tag extends BySQLRowEnabled
}
try {
- $obj = self::by_name($name);
+ self::by_name($name);
} catch (DoesNotExistError $e) {
$obj = new self();
@@ -2634,7 +2633,7 @@ class Repository extends BySQLRowEnabled
$this->name = $repometa["name"];
$this->description = $repometa["description"];
- $this->packages = @unserialize(@file_get_contents($this->baseurl . "/packagelist", false, $ctx));
+ $this->packages = @unserialize(@file_get_contents($this->baseurl . "/packagelist", false, $this->stream_ctx));
$this->lastrefresh = time();
@@ -3259,6 +3258,8 @@ class ArticleExtradata extends KVStorage
*/
function dbversion()
{
+ global $config;
+
/* Is the meta table present? If no, the version is 0. */
$stmt = qdb(
"SELECT COUNT(*) FROM `information_schema`.`tables` WHERE `table_schema` = ? AND `table_name` = ?",
diff --git a/ratatoeskr/sys/plugin_api.php b/ratatoeskr/sys/plugin_api.php
index 65b43e2..18e129b 100644
--- a/ratatoeskr/sys/plugin_api.php
+++ b/ratatoeskr/sys/plugin_api.php
@@ -35,7 +35,7 @@ $url_handlers = []; /* master URL handler */
* $name - The name of the new URL
* $callback - The Function to be called (see <url_process>).
*/
-function register_url_handler($name, $callback)
+function register_url_handler($name, callable $callback)
{
global $url_handlers;
$url_handlers[$name] = $callback;
diff --git a/ratatoeskr/sys/pwhash.php b/ratatoeskr/sys/pwhash.php
index 3d3c589..f52ae03 100644
--- a/ratatoeskr/sys/pwhash.php
+++ b/ratatoeskr/sys/pwhash.php
@@ -70,7 +70,7 @@ class PasswordHash
*/
public static function validate($password, $pwhash)
{
- list($iterations, $hexsalt, $hash) = explode('$', $pwhash);
+ list($iterations, $hexsalt) = explode('$', $pwhash);
return self::hash($password, pack("H*", $hexsalt), $iterations) == $pwhash;
}
}
diff --git a/ratatoeskr/sys/translation.php b/ratatoeskr/sys/translation.php
index 5a763ce..fd494c1 100644
--- a/ratatoeskr/sys/translation.php
+++ b/ratatoeskr/sys/translation.php
@@ -12,6 +12,9 @@
require_once(dirname(__FILE__) . "/utils.php");
require_once(dirname(__FILE__) . "/init_ste.php");
+/** @var \ste\STECore $ste */
+assert(isset($ste));
+
if (!defined("SETUP")) {
require_once(dirname(__FILE__) . "/models.php");
}
diff --git a/ratatoeskr/sys/utils.php b/ratatoeskr/sys/utils.php
index 89f779d..a285bcd 100644
--- a/ratatoeskr/sys/utils.php
+++ b/ratatoeskr/sys/utils.php
@@ -32,100 +32,6 @@ function array_repeat($val, $n)
}
/*
- * Function: array_blend
- *
- * Blend multiple arrays together.
- *
- * Example:
- *
- * array_blend(array(1,2,3), array(4,5,6), array(7,8,9));
- * will return array(1,4,7,2,5,8,3,6,9)
- */
-function array_blend()
-{
- $arrays = array_filter(func_get_args(), "is_array");
-
- switch (count($arrays)) {
- case 0: return []; break;
- case 1: return $arrays[0]; break;
- default:
- $rv = [];
- while (array_sum(array_map("count", $arrays)) > 0) {
- for ($i = 0; $i < count($arrays); ++$i) {
- $val = array_shift($arrays[$i]);
- if ($val === null) {
- continue;
- }
- array_push($rv, $val);
- }
- }
- return $rv;
- break;
- }
-}
-
-/*
- * Function: array_filter_empty
- *
- * Filters all empty elements out of an array.
- *
- * Parameters:
- *
- * $input - The input array
- *
- * Returns:
- *
- * The $input without its empty elements.
- */
-function array_filter_empty($input)
-{
- return array_filter($input, function ($x) {
- return !empty($x);
- });
-}
-
-/*
- * Function: array_filter_keys
- *
- * Like PHPs `array_filter`, but callback will get the key, not the value of the array element.
- */
-function array_filter_keys($input, $callback)
-{
- if (!is_array($input)) {
- throw new InvalidArgumentException("Argument 1 must be an array");
- }
- if (empty($input)) {
- return [];
- }
- $delete_keys = array_filter(array_keys($input), function ($x) use ($callback) {
- return !$callback($x);
- });
- foreach ($delete_keys as $key) {
- unset($input[$key]);
- }
- return $input;
-}
-
-/*
- * Function: array_kvpairs_to_assoc
- * Convert array of key-value pairs to an associative array.
- *
- * Parameters:
- * $input - Array of key-value pairs
- *
- * Returns:
- * An associative array.
- */
-function array_kvpairs_to_assoc($input)
-{
- $rv = [];
- foreach ($input as $kvpair) {
- $rv[$kvpair[0]] = $kvpair[1];
- }
- return $rv;
-}
-
-/*
* Function: intcmp
* Compare integers (equavilent to strcmp)
*/
@@ -135,67 +41,6 @@ function intcmp($a, $b)
}
/*
- * Function: ucount
- *
- * Count elements of an array matching unser-defined rules.
- *
- * Parameters:
- * $array - The input array.
- * $callback - A callback function. It will be called with the current value as the only parameter. The value is counted, if callback returns TRUE.
- *
- * Returns:
- *
- * Number of elements where $callback returned TRUE.
- */
-function ucount($array, $callback)
-{
- return count(array_filter($array, $callback));
-}
-
-/*
- * Function: vcount
- *
- * Counts how often $value appears in $array.
- *
- * Parameters:
- *
- * $array -
- * $value -
- *
- * Returns:
- *
- * How often $value appears in $array.
- */
-function vcount($array, $value)
-{
- return ucount($array, function ($x) {
- return $x===$value;
- });
-}
-
-/*
- * Function: self_url
- *
- * Gets current URL.
- *
- * From: http://dev.kanngard.net/Permalinks/ID_20050507183447.html
- */
-function self_url()
-{
- $s = empty($_SERVER["HTTPS"]) ? ''
- : ($_SERVER["HTTPS"] == "on") ? "s"
- : "";
- $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
- $port = ($_SERVER["SERVER_PORT"] == "80") ? ""
- : (":".$_SERVER["SERVER_PORT"]);
- return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
-}
-function strleft($s1, $s2)
-{
- return substr($s1, 0, strpos($s1, $s2));
-}
-
-/*
* Function: htmlesc
* Escape HTML (shorter than htmlspecialchars)
*