diff --git a/core/extension.php b/core/extension.php
index e97e2d38..cc0f334c 100644
--- a/core/extension.php
+++ b/core/extension.php
@@ -139,6 +139,11 @@ abstract class Extension
continue;
}
self::$enabled_extensions[] = $ext->key;
+ if(!empty($ext->dependencies)) {
+ foreach ($ext->dependencies as $dep) {
+ self::$enabled_extensions[] = $dep;
+ }
+ }
}
}
@@ -170,7 +175,8 @@ abstract class ExtensionInfo
public const LICENSE_WTFPL = "WTFPL";
public const VISIBLE_ADMIN = "admin";
- private const VALID_VISIBILITY = [self::VISIBLE_ADMIN];
+ public const VISIBLE_HIDDEN = "hidden";
+ private const VALID_VISIBILITY = [self::VISIBLE_ADMIN, self::VISIBLE_HIDDEN];
public $key;
@@ -183,6 +189,7 @@ abstract class ExtensionInfo
public $link;
public $license;
public $version;
+ public $dependencies = [];
public $visibility;
public $description;
public $documentation;
@@ -230,6 +237,9 @@ abstract class ExtensionInfo
if(!is_array($this->authors)) {
throw new Exception("authors has to be an array for extension $this->key");
}
+ if(!is_array($this->dependencies)) {
+ throw new Exception("dependencies has to be an array for extension $this->key");
+ }
}
public function is_enabled(): bool
diff --git a/ext/emoticons/info.php b/ext/emoticons/info.php
index cac52af5..601001f7 100644
--- a/ext/emoticons/info.php
+++ b/ext/emoticons/info.php
@@ -19,6 +19,7 @@ class EmoticonsInfo extends ExtensionInfo
public $url = self::SHIMMIE_URL;
public $authors = self::SHISH_AUTHOR;
public $license = self::LICENSE_GPLV2;
+ public $dependencies = [EmoticonListInfo::KEY];
public $description = "Lets users use graphical smilies";
public $documentation =
"This extension will turn colon-something-colon into a link
@@ -28,14 +29,3 @@ becomes a link to smile.gif
add more emoticons by uploading images into that folder.";
}
-class EmoticonListInfo extends ExtensionInfo
-{
- public const KEY = "emoticons_list";
-
- public $key = self::KEY;
- public $name = "Emoticon List";
- public $url = self::SHIMMIE_URL;
- public $authors = self::SHISH_AUTHOR;
- public $license = self::LICENSE_GPLV2;
- public $description = "Lists available graphical smilies";
-}
diff --git a/ext/emoticons/main.php b/ext/emoticons/main.php
index b3514425..422c7610 100644
--- a/ext/emoticons/main.php
+++ b/ext/emoticons/main.php
@@ -19,15 +19,3 @@ class Emoticons extends FormatterExtension
}
}
-/**
- * Class EmoticonList
- */
-class EmoticonList extends Extension
-{
- public function onPageRequest(PageRequestEvent $event)
- {
- if ($event->page_matches("emote/list")) {
- $this->theme->display_emotes(glob("ext/emoticons/default/*"));
- }
- }
-}
diff --git a/ext/emoticons_list/info.php b/ext/emoticons_list/info.php
new file mode 100644
index 00000000..601ad61d
--- /dev/null
+++ b/ext/emoticons_list/info.php
@@ -0,0 +1,15 @@
+page_matches("emote/list")) {
+ $this->theme->display_emotes(glob("ext/emoticons/default/*"));
+ }
+ }
+}
diff --git a/ext/emoticons/theme.php b/ext/emoticons_list/theme.php
similarity index 100%
rename from ext/emoticons/theme.php
rename to ext/emoticons_list/theme.php
diff --git a/ext/ext_manager/theme.php b/ext/ext_manager/theme.php
index 0c1702be..6a19757e 100644
--- a/ext/ext_manager/theme.php
+++ b/ext/ext_manager/theme.php
@@ -22,7 +22,8 @@ class ExtManagerTheme extends Themelet
";
foreach ($extensions as $extension) {
- if (!$editable && $extension->visibility == "admin") {
+ if ((!$editable && $extension->visibility === ExtensionInfo::VISIBLE_ADMIN)
+ || $extension->visibility === ExtensionInfo::VISIBLE_HIDDEN) {
continue;
}
diff --git a/ext/tagger/info.php b/ext/tagger/info.php
index f165b654..b240b70b 100644
--- a/ext/tagger/info.php
+++ b/ext/tagger/info.php
@@ -14,5 +14,6 @@ class TaggerInfo extends ExtensionInfo
public $key = self::KEY;
public $name = "Tagger";
public $authors = ["Artanis (Erik Youngren)"=>"artanis.00@gmail.com"];
+ public $dependencies = [TaggerXMLInfo::KEY];
public $description = "Advanced Tagging v2";
}
diff --git a/ext/tagger/main.php b/ext/tagger/main.php
index 637f08bf..a0541e6a 100644
--- a/ext/tagger/main.php
+++ b/ext/tagger/main.php
@@ -23,133 +23,3 @@ class Tagger extends Extension
$event->panel->add_block($sb);
}
}
-
-// Tagger AJAX back-end
-class TaggerXML extends Extension
-{
- public function get_priority(): int
- {
- return 10;
- }
-
- public function onPageRequest(PageRequestEvent $event)
- {
- if ($event->page_matches("tagger/tags")) {
- global $page;
-
- //$match_tags = null;
- //$image_tags = null;
- $tags=null;
- if (isset($_GET['s'])) { // tagger/tags[/...]?s=$string
- // return matching tags in XML form
- $tags = $this->match_tag_list($_GET['s']);
- } elseif ($event->get_arg(0)) { // tagger/tags/$int
- // return arg[1] AS image_id's tag list in XML form
- $tags = $this->image_tag_list($event->get_arg(0));
- }
-
- $xml = "\n".
- "".
- $tags.
- "";
-
- $page->set_mode(PageMode::DATA);
- $page->set_type("text/xml");
- $page->set_data($xml);
- }
- }
-
- private function match_tag_list(string $s)
- {
- global $database, $config;
-
- $max_rows = $config->get_int("ext_tagger_tag_max", 30);
- $limit_rows = $config->get_int("ext_tagger_limit", 30);
-
- $values = [];
-
- // Match
- $p = strlen($s) == 1? " ":"\_";
- $sq = "%".$p.sql_escape($s)."%";
- $match = "concat(?,tag) LIKE ?";
- array_push($values, $p, $sq);
- // Exclude
- // $exclude = $event->get_arg(1)? "AND NOT IN ".$this->image_tags($event->get_arg(1)) : null;
-
- // Hidden Tags
- $hidden = $config->get_string('ext-tagger_show-hidden', 'N')=='N' ?
- "AND substring(tag,1,1) != '.'" : null;
-
- $q_where = "WHERE {$match} {$hidden} AND count > 0";
-
- // FROM based on return count
- $count = $this->count($q_where, $values);
- if ($count > $max_rows) {
- $q_from = "FROM (SELECT * FROM `tags` {$q_where} ".
- "ORDER BY count DESC LIMIT 0, {$limit_rows}) AS `c_tags`";
- $q_where = null;
- $count = ["max"=>$count];
- } else {
- $q_from = "FROM `tags`";
- $count = null;
- }
-
- $tags = $database->Execute(
- "
- SELECT *
- {$q_from}
- {$q_where}
- ORDER BY tag",
- $values
- );
-
- return $this->list_to_xml($tags, "search", $s, $count);
- }
-
- private function image_tag_list(int $image_id)
- {
- global $database;
- $tags = $database->Execute("
- SELECT tags.*
- FROM image_tags JOIN tags ON image_tags.tag_id = tags.id
- WHERE image_id=? ORDER BY tag", [$image_id]);
- return $this->list_to_xml($tags, "image", $image_id);
- }
-
- private function list_to_xml(PDOStatement $tags, string $type, string $query, ?array$misc=null): string
- {
- $r = $tags->_numOfRows;
-
- $s_misc = "";
- if (!is_null($misc)) {
- foreach ($misc as $attr => $val) {
- $s_misc .= " ".$attr."=\"".$val."\"";
- }
- }
-
- $result = "";
- foreach ($tags as $tag) {
- $result .= $this->tag_to_xml($tag);
- }
- return $result."
";
- }
-
- private function tag_to_xml(PDORow $tag): string
- {
- return
- "".
- html_escape($tag['tag']).
- "";
- }
-
- private function count(string $query, $values)
- {
- global $database;
- return $database->Execute(
- "SELECT COUNT(*) FROM `tags` $query",
- $values
- )->fields['COUNT(*)'];
- }
-}
diff --git a/ext/tagger_xml/info.php b/ext/tagger_xml/info.php
new file mode 100644
index 00000000..395951e5
--- /dev/null
+++ b/ext/tagger_xml/info.php
@@ -0,0 +1,12 @@
+"artanis.00@gmail.com"];
+ public $visibility = self::VISIBLE_HIDDEN;
+ public $description = "Advanced Tagging v2 AJAX backend";
+}
diff --git a/ext/tagger_xml/main.php b/ext/tagger_xml/main.php
new file mode 100644
index 00000000..a1429225
--- /dev/null
+++ b/ext/tagger_xml/main.php
@@ -0,0 +1,131 @@
+page_matches("tagger/tags")) {
+ global $page;
+
+ //$match_tags = null;
+ //$image_tags = null;
+ $tags=null;
+ if (isset($_GET['s'])) { // tagger/tags[/...]?s=$string
+ // return matching tags in XML form
+ $tags = $this->match_tag_list($_GET['s']);
+ } elseif ($event->get_arg(0)) { // tagger/tags/$int
+ // return arg[1] AS image_id's tag list in XML form
+ $tags = $this->image_tag_list($event->get_arg(0));
+ }
+
+ $xml = "\n".
+ "".
+ $tags.
+ "";
+
+ $page->set_mode(PageMode::DATA);
+ $page->set_type("text/xml");
+ $page->set_data($xml);
+ }
+ }
+
+ private function match_tag_list(string $s)
+ {
+ global $database, $config;
+
+ $max_rows = $config->get_int("ext_tagger_tag_max", 30);
+ $limit_rows = $config->get_int("ext_tagger_limit", 30);
+
+ $values = [];
+
+ // Match
+ $p = strlen($s) == 1? " ":"\_";
+ $sq = "%".$p.sql_escape($s)."%";
+ $match = "concat(?,tag) LIKE ?";
+ array_push($values, $p, $sq);
+ // Exclude
+ // $exclude = $event->get_arg(1)? "AND NOT IN ".$this->image_tags($event->get_arg(1)) : null;
+
+ // Hidden Tags
+ $hidden = $config->get_string('ext-tagger_show-hidden', 'N')=='N' ?
+ "AND substring(tag,1,1) != '.'" : null;
+
+ $q_where = "WHERE {$match} {$hidden} AND count > 0";
+
+ // FROM based on return count
+ $count = $this->count($q_where, $values);
+ if ($count > $max_rows) {
+ $q_from = "FROM (SELECT * FROM `tags` {$q_where} ".
+ "ORDER BY count DESC LIMIT 0, {$limit_rows}) AS `c_tags`";
+ $q_where = null;
+ $count = ["max"=>$count];
+ } else {
+ $q_from = "FROM `tags`";
+ $count = null;
+ }
+
+ $tags = $database->Execute(
+ "
+ SELECT *
+ {$q_from}
+ {$q_where}
+ ORDER BY tag",
+ $values
+ );
+
+ return $this->list_to_xml($tags, "search", $s, $count);
+ }
+
+ private function image_tag_list(int $image_id)
+ {
+ global $database;
+ $tags = $database->Execute("
+ SELECT tags.*
+ FROM image_tags JOIN tags ON image_tags.tag_id = tags.id
+ WHERE image_id=? ORDER BY tag", [$image_id]);
+ return $this->list_to_xml($tags, "image", $image_id);
+ }
+
+ private function list_to_xml(PDOStatement $tags, string $type, string $query, ?array$misc=null): string
+ {
+ $r = $tags->_numOfRows;
+
+ $s_misc = "";
+ if (!is_null($misc)) {
+ foreach ($misc as $attr => $val) {
+ $s_misc .= " ".$attr."=\"".$val."\"";
+ }
+ }
+
+ $result = "";
+ foreach ($tags as $tag) {
+ $result .= $this->tag_to_xml($tag);
+ }
+ return $result."
";
+ }
+
+ private function tag_to_xml(PDORow $tag): string
+ {
+ return
+ "".
+ html_escape($tag['tag']).
+ "";
+ }
+
+ private function count(string $query, $values)
+ {
+ global $database;
+ return $database->Execute(
+ "SELECT COUNT(*) FROM `tags` $query",
+ $values
+ )->fields['COUNT(*)'];
+ }
+}