Added dependency support for extensions
Separated a few extensions that had multiple extension classes in the same file
This commit is contained in:
parent
744dcd63e1
commit
ac6ded877f
11 changed files with 187 additions and 155 deletions
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -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/*"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
15
ext/emoticons_list/info.php
Normal file
15
ext/emoticons_list/info.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
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";
|
||||
|
||||
public $visibility = self::VISIBLE_HIDDEN;
|
||||
}
|
14
ext/emoticons_list/main.php
Normal file
14
ext/emoticons_list/main.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* 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/*"));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,7 +22,8 @@ class ExtManagerTheme extends Themelet
|
|||
<tbody>
|
||||
";
|
||||
foreach ($extensions as $extension) {
|
||||
if (!$editable && $extension->visibility == "admin") {
|
||||
if ((!$editable && $extension->visibility === ExtensionInfo::VISIBLE_ADMIN)
|
||||
|| $extension->visibility === ExtensionInfo::VISIBLE_HIDDEN) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".
|
||||
"<tags>".
|
||||
$tags.
|
||||
"</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 = "<list id=\"$type\" query=\"$query\" rows=\"$r\"{$s_misc}>";
|
||||
foreach ($tags as $tag) {
|
||||
$result .= $this->tag_to_xml($tag);
|
||||
}
|
||||
return $result."</list>";
|
||||
}
|
||||
|
||||
private function tag_to_xml(PDORow $tag): string
|
||||
{
|
||||
return
|
||||
"<tag ".
|
||||
"id=\"".$tag['id']."\" ".
|
||||
"count=\"".$tag['count']."\">".
|
||||
html_escape($tag['tag']).
|
||||
"</tag>";
|
||||
}
|
||||
|
||||
private function count(string $query, $values)
|
||||
{
|
||||
global $database;
|
||||
return $database->Execute(
|
||||
"SELECT COUNT(*) FROM `tags` $query",
|
||||
$values
|
||||
)->fields['COUNT(*)'];
|
||||
}
|
||||
}
|
||||
|
|
12
ext/tagger_xml/info.php
Normal file
12
ext/tagger_xml/info.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
class TaggerXMLInfo extends ExtensionInfo
|
||||
{
|
||||
public const KEY = "tagger_xml";
|
||||
|
||||
public $key = self::KEY;
|
||||
public $name = "Tagger AJAX backend";
|
||||
public $authors = ["Artanis (Erik Youngren)"=>"artanis.00@gmail.com"];
|
||||
public $visibility = self::VISIBLE_HIDDEN;
|
||||
public $description = "Advanced Tagging v2 AJAX backend";
|
||||
}
|
131
ext/tagger_xml/main.php
Normal file
131
ext/tagger_xml/main.php
Normal file
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
|
||||
// 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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".
|
||||
"<tags>".
|
||||
$tags.
|
||||
"</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 = "<list id=\"$type\" query=\"$query\" rows=\"$r\"{$s_misc}>";
|
||||
foreach ($tags as $tag) {
|
||||
$result .= $this->tag_to_xml($tag);
|
||||
}
|
||||
return $result."</list>";
|
||||
}
|
||||
|
||||
private function tag_to_xml(PDORow $tag): string
|
||||
{
|
||||
return
|
||||
"<tag ".
|
||||
"id=\"".$tag['id']."\" ".
|
||||
"count=\"".$tag['count']."\">".
|
||||
html_escape($tag['tag']).
|
||||
"</tag>";
|
||||
}
|
||||
|
||||
private function count(string $query, $values)
|
||||
{
|
||||
global $database;
|
||||
return $database->Execute(
|
||||
"SELECT COUNT(*) FROM `tags` $query",
|
||||
$values
|
||||
)->fields['COUNT(*)'];
|
||||
}
|
||||
}
|
Reference in a new issue