summaryrefslogtreecommitdiff
path: root/init.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-08 11:59:29 +0300
committerAndrew Dolgov <[email protected]>2021-02-08 11:59:29 +0300
commit092b2b5c4461d719e5c728ec6f863d3f8f01570c (patch)
treed3d673207a798b2296a1ebe1734b4f46e1750762 /init.php
parent27872600239a33ecd7b00abe87393757c6bf7ce5 (diff)
fix php8 warnings and some phpstan stuff, cleanup
Diffstat (limited to 'init.php')
-rwxr-xr-xinit.php46
1 files changed, 23 insertions, 23 deletions
diff --git a/init.php b/init.php
index 6abb435..9c389a2 100755
--- a/init.php
+++ b/init.php
@@ -71,7 +71,7 @@ class Af_Img_Phash extends Plugin {
}
else {
try { $res = $this->pdo->query("select 'unique_1bits'::regproc"); } catch (PDOException $e) { ; }
- if (!$res || !$res->fetch()) {
+ if (empty($res) || !$res->fetch()) {
print_error("Required function from count_bits extension not found.");
}
}
@@ -133,10 +133,9 @@ class Af_Img_Phash extends Plugin {
print "</form>";
- $enabled_feeds = $this->host->get($this, "enabled_feeds");
- if (!array($enabled_feeds)) $enabled_feeds = array();
+ $enabled_feeds = $this->filter_unknown_feeds(
+ $this->get_stored_array("enabled_feeds"));
- $enabled_feeds = $this->filter_unknown_feeds($enabled_feeds);
$this->host->set($this, "enabled_feeds", $enabled_feeds);
if (count($enabled_feeds) > 0) {
@@ -157,11 +156,8 @@ class Af_Img_Phash extends Plugin {
print "<header>".$this->__( "Similar images")."</header>";
print "<section>";
- $enabled_feeds = $this->host->get($this, "enabled_feeds");
- if (!array($enabled_feeds)) $enabled_feeds = array();
-
- $key = array_search($feed_id, $enabled_feeds);
- $checked = $key !== FALSE ? "checked" : "";
+ $enabled_feeds = $this->get_stored_array("enabled_feeds");
+ $checked = in_array($feed_id, $enabled_feeds) ? "checked" : "";
print "<fieldset>";
print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='phash_similarity_enabled'
@@ -171,19 +167,26 @@ class Af_Img_Phash extends Plugin {
print "</section>";
}
+ private function get_stored_array($name) {
+ $tmp = $this->host->get($this, $name);
+
+ if (!is_array($tmp)) $tmp = [];
+
+ return $tmp;
+ }
+
function hook_prefs_save_feed($feed_id) {
- $enabled_feeds = $this->host->get($this, "enabled_feeds");
- if (!is_array($enabled_feeds)) $enabled_feeds = array();
+ $enabled_feeds = $this->get_stored_array("enabled_feeds");
- $enable = checkbox_to_sql_bool($_POST["phash_similarity_enabled"]);
+ $enable = checkbox_to_sql_bool($_POST["phash_similarity_enabled"] ?? "");
$key = array_search($feed_id, $enabled_feeds);
if ($enable) {
- if ($key === FALSE) {
+ if ($key === false) {
array_push($enabled_feeds, $feed_id);
}
} else {
- if ($key !== FALSE) {
+ if ($key !== false) {
unset($enabled_feeds[$key]);
}
}
@@ -206,7 +209,7 @@ class Af_Img_Phash extends Plugin {
}
}
- if ($check_uri && $uri) {
+ if (!empty($check_uri) && !empty($uri)) {
$p = $doc->createElement('p');
@@ -242,12 +245,9 @@ class Af_Img_Phash extends Plugin {
$domains_list = explode(" ", $domains_list);
if (!$enable_globally) {
- $enabled_feeds = $this->host->get($this, "enabled_feeds");
+ if (!in_array($article["feed"]["id"],
+ $this->get_stored_array("enabled_feeds"))) {
- if (is_array($enabled_feeds)) {
- $key = array_search($article["feed"]["id"], $enabled_feeds);
- if ($key === FALSE) return $article;
- } else {
return $article;
}
}
@@ -321,7 +321,7 @@ class Af_Img_Phash extends Plugin {
$data_resource = @imagecreatefromstring($data);
if ($data_resource) {
- $hash = $hasher->hash($data_resource);
+ $hash = (string)$hasher->hash($data_resource);
_debug("phash: calculated perceptual hash: $hash");
@@ -430,7 +430,7 @@ class Af_Img_Phash extends Plugin {
foreach ($imgs as $img) {
$src = $img->tagName == "video" ? $img->getAttribute("poster") : $img->getAttribute("src");
- $src = validate_url(rewrite_relative_url($article["link"], $src, $api_mode));
+ $src = validate_url(rewrite_relative_url($article["link"], $src));
$domain_found = $this->check_src_domain($src, $domains_list);
@@ -499,7 +499,7 @@ class Af_Img_Phash extends Plugin {
$src_domain = parse_url($src, PHP_URL_HOST);
foreach ($domains_list as $domain) {
- if (strstr($src_domain, $domain) !== FALSE) {
+ if (strstr($src_domain, $domain) !== false) {
return true;
}
}