2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
2009-07-21 06:36:12 +00:00
|
|
|
* \page eande Events and Extensions
|
2014-02-22 20:42:09 +00:00
|
|
|
*
|
2009-07-21 03:18:40 +00:00
|
|
|
* An event is a little blob of data saying "something happened", possibly
|
|
|
|
* "something happened, here's the specific data". Events are sent with the
|
|
|
|
* send_event() function. Since events can store data, they can be used to
|
|
|
|
* return data to the extension which sent them, for example:
|
2014-02-22 20:42:09 +00:00
|
|
|
*
|
2009-07-21 03:18:40 +00:00
|
|
|
* \code
|
|
|
|
* $tfe = new TextFormattingEvent($original_text);
|
|
|
|
* send_event($tfe);
|
|
|
|
* $formatted_text = $tfe->formatted;
|
|
|
|
* \endcode
|
2014-02-22 20:42:09 +00:00
|
|
|
*
|
2012-02-08 12:07:01 +00:00
|
|
|
* An extension is something which is capable of reacting to events.
|
2009-07-21 06:36:12 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* \page hello The Hello World Extension
|
|
|
|
*
|
|
|
|
* \code
|
|
|
|
* // ext/hello/main.php
|
2012-03-05 13:56:36 +00:00
|
|
|
* public class HelloEvent extends Event {
|
|
|
|
* public function __construct($username) {
|
|
|
|
* $this->username = $username;
|
|
|
|
* }
|
|
|
|
* }
|
2014-02-22 20:42:09 +00:00
|
|
|
*
|
2012-02-08 12:07:01 +00:00
|
|
|
* public class Hello extends Extension {
|
2012-03-05 18:42:05 +00:00
|
|
|
* public function onPageRequest(PageRequestEvent $event) { // Every time a page request is sent
|
|
|
|
* global $user; // Look at the global "currently logged in user" object
|
|
|
|
* send_event(new HelloEvent($user->name)); // Broadcast a signal saying hello to that user
|
2012-03-05 13:56:36 +00:00
|
|
|
* }
|
2012-03-05 18:42:05 +00:00
|
|
|
* public function onHello(HelloEvent $event) { // When the "Hello" signal is recieved
|
|
|
|
* $this->theme->display_hello($event->username); // Display a message on the web page
|
2009-07-21 06:36:12 +00:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* // ext/hello/theme.php
|
|
|
|
* public class HelloTheme extends Themelet {
|
2012-03-05 13:58:04 +00:00
|
|
|
* public function display_hello($username) {
|
2012-03-05 13:56:36 +00:00
|
|
|
* global $page;
|
2012-03-05 18:42:05 +00:00
|
|
|
* $h_user = html_escape($username); // Escape the data before adding it to the page
|
|
|
|
* $block = new Block("Hello!", "Hello there $h_user"); // HTML-safe variables start with "h_"
|
|
|
|
* $page->add_block($block); // Add the block to the page
|
2009-07-21 06:36:12 +00:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* // ext/hello/test.php
|
2015-08-09 11:14:28 +00:00
|
|
|
* public class HelloTest extends SCorePHPUnitTestCase {
|
2012-03-05 13:58:04 +00:00
|
|
|
* public function testHello() {
|
2012-03-05 18:42:05 +00:00
|
|
|
* $this->get_page("post/list"); // View a page, any page
|
|
|
|
* $this->assert_text("Hello there"); // Check that the specified text is in that page
|
2009-07-21 06:36:12 +00:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* // themes/mytheme/hello.theme.php
|
2012-03-05 18:42:05 +00:00
|
|
|
* public class CustomHelloTheme extends HelloTheme { // CustomHelloTheme overrides HelloTheme
|
|
|
|
* public function display_hello($username) { // the display_hello() function is customised
|
|
|
|
* global $page;
|
|
|
|
* $h_user = html_escape($username);
|
2009-07-21 06:36:12 +00:00
|
|
|
* $page->add_block(new Block(
|
|
|
|
* "Hello!",
|
|
|
|
* "Hello there $h_user, look at my snazzy custom theme!"
|
|
|
|
* );
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* \endcode
|
|
|
|
*
|
2009-07-19 07:38:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-04-29 05:33:03 +00:00
|
|
|
* Class Extension
|
|
|
|
*
|
2009-05-15 08:52:55 +00:00
|
|
|
* send_event(BlahEvent()) -> onBlah($event)
|
|
|
|
*
|
|
|
|
* Also loads the theme object into $this->theme if available
|
|
|
|
*
|
2012-02-08 12:07:01 +00:00
|
|
|
* The original concept came from Artanis's Extension extension
|
2009-05-15 08:52:55 +00:00
|
|
|
* --> http://github.com/Artanis/simple-extension/tree/master
|
|
|
|
* Then re-implemented by Shish after he broke the forum and couldn't
|
|
|
|
* find the thread where the original was posted >_<
|
2009-05-11 21:08:32 +00:00
|
|
|
*/
|
2019-05-28 16:59:38 +00:00
|
|
|
abstract class Extension
|
|
|
|
{
|
2019-08-07 19:53:59 +00:00
|
|
|
public $key;
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
/** @var Themelet this theme's Themelet object */
|
|
|
|
public $theme;
|
|
|
|
|
2019-08-01 16:20:09 +00:00
|
|
|
public $info;
|
|
|
|
|
2019-08-07 19:53:59 +00:00
|
|
|
private static $enabled_extensions = [];
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2019-08-07 19:53:59 +00:00
|
|
|
public function __construct($class = null)
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2019-08-07 19:53:59 +00:00
|
|
|
$class = $class ?? get_called_class();
|
|
|
|
$this->theme = $this->get_theme_object($class);
|
|
|
|
$this->info = ExtensionInfo::get_for_extension_class($class);
|
2019-09-29 13:30:55 +00:00
|
|
|
if ($this->info===null) {
|
2019-08-07 19:53:59 +00:00
|
|
|
throw new Exception("Info class not found for extension $class");
|
2019-08-01 16:20:09 +00:00
|
|
|
}
|
2019-08-07 19:53:59 +00:00
|
|
|
$this->key = $this->info->key;
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the theme object for a given extension.
|
|
|
|
*/
|
|
|
|
private function get_theme_object(string $base): ?Themelet
|
|
|
|
{
|
|
|
|
$custom = 'Custom'.$base.'Theme';
|
|
|
|
$normal = $base.'Theme';
|
|
|
|
|
|
|
|
if (class_exists($custom)) {
|
|
|
|
return new $custom();
|
|
|
|
} elseif (class_exists($normal)) {
|
|
|
|
return new $normal();
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override this to change the priority of the extension,
|
|
|
|
* lower numbered ones will receive events first.
|
|
|
|
*/
|
|
|
|
public function get_priority(): int
|
|
|
|
{
|
|
|
|
return 50;
|
|
|
|
}
|
2019-08-07 19:53:59 +00:00
|
|
|
|
|
|
|
public static function determine_enabled_extensions()
|
|
|
|
{
|
|
|
|
self::$enabled_extensions = [];
|
2019-09-29 13:30:55 +00:00
|
|
|
foreach (array_merge(
|
|
|
|
ExtensionInfo::get_core_extensions(),
|
|
|
|
explode(",", EXTRA_EXTS)
|
|
|
|
) as $key) {
|
2019-08-07 19:53:59 +00:00
|
|
|
$ext = ExtensionInfo::get_by_key($key);
|
2019-09-29 13:30:55 +00:00
|
|
|
if ($ext===null) {
|
2019-08-07 19:53:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
self::$enabled_extensions[] = $ext->key;
|
2019-09-29 13:30:55 +00:00
|
|
|
if (!empty($ext->dependencies)) {
|
2019-08-07 21:32:28 +00:00
|
|
|
foreach ($ext->dependencies as $dep) {
|
|
|
|
self::$enabled_extensions[] = $dep;
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 19:53:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function is_enabled(string $key): ?bool
|
|
|
|
{
|
|
|
|
return in_array($key, self::$enabled_extensions);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_enabled_extensions(): array
|
|
|
|
{
|
|
|
|
return self::$enabled_extensions;
|
|
|
|
}
|
|
|
|
public static function get_enabled_extensions_as_string(): string
|
|
|
|
{
|
2019-09-29 13:30:55 +00:00
|
|
|
return implode(",", self::$enabled_extensions);
|
2019-08-07 19:53:59 +00:00
|
|
|
}
|
2009-05-11 21:08:32 +00:00
|
|
|
}
|
2008-08-23 12:05:24 +00:00
|
|
|
|
2019-08-01 16:20:09 +00:00
|
|
|
abstract class ExtensionInfo
|
|
|
|
{
|
2019-08-07 19:53:59 +00:00
|
|
|
// Every credit you get costs us RAM. It stops now.
|
|
|
|
public const SHISH_NAME = "Shish";
|
|
|
|
public const SHISH_EMAIL = "webmaster@shishnet.org";
|
|
|
|
public const SHIMMIE_URL = "http://code.shishnet.org/shimmie2/";
|
|
|
|
public const SHISH_AUTHOR = [self::SHISH_NAME=>self::SHISH_EMAIL];
|
|
|
|
|
|
|
|
public const LICENSE_GPLV2 = "GPLv2";
|
|
|
|
public const LICENSE_MIT = "MIT";
|
|
|
|
public const LICENSE_WTFPL = "WTFPL";
|
|
|
|
|
|
|
|
public const VISIBLE_ADMIN = "admin";
|
2019-08-07 21:32:28 +00:00
|
|
|
public const VISIBLE_HIDDEN = "hidden";
|
|
|
|
private const VALID_VISIBILITY = [self::VISIBLE_ADMIN, self::VISIBLE_HIDDEN];
|
2019-08-07 19:53:59 +00:00
|
|
|
|
|
|
|
public $key;
|
|
|
|
|
|
|
|
public $core = false;
|
|
|
|
|
|
|
|
public $beta = false;
|
|
|
|
|
2019-08-01 16:20:09 +00:00
|
|
|
public $name;
|
2019-08-07 19:53:59 +00:00
|
|
|
public $authors = [];
|
2019-08-01 16:20:09 +00:00
|
|
|
public $link;
|
|
|
|
public $license;
|
|
|
|
public $version;
|
2019-08-07 21:32:28 +00:00
|
|
|
public $dependencies = [];
|
2019-08-01 16:20:09 +00:00
|
|
|
public $visibility;
|
|
|
|
public $description;
|
|
|
|
public $documentation;
|
|
|
|
|
2019-08-07 19:53:59 +00:00
|
|
|
/** @var array which DBs this ext supports (blank for 'all') */
|
|
|
|
public $db_support = [];
|
|
|
|
|
|
|
|
private $supported = null;
|
|
|
|
private $support_info = null;
|
|
|
|
|
|
|
|
public function is_supported(): bool
|
2019-08-01 16:20:09 +00:00
|
|
|
{
|
2019-09-29 13:30:55 +00:00
|
|
|
if ($this->supported===null) {
|
2019-08-07 19:53:59 +00:00
|
|
|
$this->check_support();
|
|
|
|
}
|
|
|
|
return $this->supported;
|
2019-08-01 16:20:09 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 19:53:59 +00:00
|
|
|
public function get_support_info(): string
|
|
|
|
{
|
2019-09-29 13:30:55 +00:00
|
|
|
if ($this->supported===null) {
|
2019-08-07 19:53:59 +00:00
|
|
|
$this->check_support();
|
|
|
|
}
|
|
|
|
return $this->support_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static $all_info_by_key = [];
|
|
|
|
private static $all_info_by_class = [];
|
|
|
|
private static $core_extensions = [];
|
|
|
|
|
|
|
|
protected function __construct()
|
|
|
|
{
|
2019-09-29 13:30:55 +00:00
|
|
|
if (empty($this->key)) {
|
2019-08-07 19:53:59 +00:00
|
|
|
throw new Exception("key field is required");
|
|
|
|
}
|
2019-09-29 13:30:55 +00:00
|
|
|
if (empty($this->name)) {
|
2019-08-07 19:53:59 +00:00
|
|
|
throw new Exception("name field is required for extension $this->key");
|
|
|
|
}
|
2019-09-29 13:30:55 +00:00
|
|
|
if (!empty($this->visibility)&&!in_array($this->visibility, self::VALID_VISIBILITY)) {
|
2019-08-07 19:53:59 +00:00
|
|
|
throw new Exception("Invalid visibility for extension $this->key");
|
|
|
|
}
|
2019-09-29 13:30:55 +00:00
|
|
|
if (!is_array($this->db_support)) {
|
2019-08-07 19:53:59 +00:00
|
|
|
throw new Exception("db_support has to be an array for extension $this->key");
|
|
|
|
}
|
2019-09-29 13:30:55 +00:00
|
|
|
if (!is_array($this->authors)) {
|
2019-08-07 19:53:59 +00:00
|
|
|
throw new Exception("authors has to be an array for extension $this->key");
|
2019-08-07 21:32:28 +00:00
|
|
|
}
|
2019-09-29 13:30:55 +00:00
|
|
|
if (!is_array($this->dependencies)) {
|
2019-08-07 21:32:28 +00:00
|
|
|
throw new Exception("dependencies has to be an array for extension $this->key");
|
2019-08-07 19:53:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function is_enabled(): bool
|
|
|
|
{
|
|
|
|
return Extension::is_enabled($this->key);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function check_support()
|
2019-08-01 16:20:09 +00:00
|
|
|
{
|
|
|
|
global $database;
|
2019-08-07 19:53:59 +00:00
|
|
|
$this->support_info = "";
|
2019-09-29 13:30:55 +00:00
|
|
|
if (!empty($this->db_support)&&!in_array($database->get_driver_name(), $this->db_support)) {
|
2019-08-07 19:53:59 +00:00
|
|
|
$this->support_info .= "Database not supported. ";
|
|
|
|
}
|
|
|
|
// Additional checks here as needed
|
|
|
|
|
|
|
|
$this->supported = empty($this->support_info);
|
2019-08-01 16:20:09 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 19:53:59 +00:00
|
|
|
public static function get_all(): array
|
|
|
|
{
|
|
|
|
return array_values(self::$all_info_by_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_all_keys(): array
|
|
|
|
{
|
|
|
|
return array_keys(self::$all_info_by_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_core_extensions(): array
|
|
|
|
{
|
|
|
|
return self::$core_extensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_by_key(string $key): ?ExtensionInfo
|
|
|
|
{
|
2019-09-29 13:30:55 +00:00
|
|
|
if (array_key_exists($key, self::$all_info_by_key)) {
|
2019-08-07 19:53:59 +00:00
|
|
|
return self::$all_info_by_key[$key];
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_for_extension_class(string $base): ?ExtensionInfo
|
2019-08-01 16:20:09 +00:00
|
|
|
{
|
|
|
|
$normal = $base.'Info';
|
|
|
|
|
2019-08-07 19:53:59 +00:00
|
|
|
if (array_key_exists($normal, self::$all_info_by_class)) {
|
|
|
|
return self::$all_info_by_class[$normal];
|
2019-08-01 16:20:09 +00:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 19:53:59 +00:00
|
|
|
|
|
|
|
public static function load_all_extension_info()
|
|
|
|
{
|
|
|
|
foreach (get_declared_classes() as $class) {
|
|
|
|
$rclass = new ReflectionClass($class);
|
|
|
|
if ($rclass->isAbstract()) {
|
|
|
|
// don't do anything
|
|
|
|
} elseif (is_subclass_of($class, "ExtensionInfo")) {
|
|
|
|
$extension_info = new $class();
|
2019-09-29 13:30:55 +00:00
|
|
|
if (array_key_exists($extension_info->key, self::$all_info_by_key)) {
|
2019-08-07 19:53:59 +00:00
|
|
|
throw new Exception("Extension Info $class with key $extension_info->key has already been loaded");
|
|
|
|
}
|
|
|
|
|
|
|
|
self::$all_info_by_key[$extension_info->key] = $extension_info;
|
|
|
|
self::$all_info_by_class[$class] = $extension_info;
|
2019-09-29 13:30:55 +00:00
|
|
|
if ($extension_info->core===true) {
|
2019-08-07 19:53:59 +00:00
|
|
|
self::$core_extensions[] = $extension_info->key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-01 16:20:09 +00:00
|
|
|
}
|
|
|
|
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
2014-04-29 05:33:03 +00:00
|
|
|
* Class FormatterExtension
|
|
|
|
*
|
|
|
|
* Several extensions have this in common, make a common API.
|
2008-08-23 12:05:24 +00:00
|
|
|
*/
|
2019-05-28 16:59:38 +00:00
|
|
|
abstract class FormatterExtension extends Extension
|
|
|
|
{
|
|
|
|
public function onTextFormatting(TextFormattingEvent $event)
|
|
|
|
{
|
|
|
|
$event->formatted = $this->format($event->formatted);
|
|
|
|
$event->stripped = $this->strip($event->stripped);
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract public function format(string $text): string;
|
|
|
|
abstract public function strip(string $text): string;
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
2009-07-16 19:20:53 +00:00
|
|
|
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
2014-04-29 05:33:03 +00:00
|
|
|
* Class DataHandlerExtension
|
|
|
|
*
|
2009-07-19 03:48:25 +00:00
|
|
|
* This too is a common class of extension with many methods in common,
|
2014-04-29 05:33:03 +00:00
|
|
|
* so we have a base class to extend from.
|
2009-07-19 03:48:25 +00:00
|
|
|
*/
|
2019-05-28 16:59:38 +00:00
|
|
|
abstract class DataHandlerExtension extends Extension
|
|
|
|
{
|
|
|
|
public function onDataUpload(DataUploadEvent $event)
|
|
|
|
{
|
|
|
|
$supported_ext = $this->supported_ext($event->type);
|
|
|
|
$check_contents = $this->check_contents($event->tmpname);
|
|
|
|
if ($supported_ext && $check_contents) {
|
|
|
|
move_upload_to_archive($event);
|
|
|
|
send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
|
|
|
|
|
|
|
|
/* Check if we are replacing an image */
|
|
|
|
if (array_key_exists('replace', $event->metadata) && isset($event->metadata['replace'])) {
|
|
|
|
/* hax: This seems like such a dirty way to do this.. */
|
|
|
|
|
|
|
|
/* Validate things */
|
|
|
|
$image_id = int_escape($event->metadata['replace']);
|
|
|
|
|
|
|
|
/* Check to make sure the image exists. */
|
|
|
|
$existing = Image::by_id($image_id);
|
|
|
|
|
|
|
|
if (is_null($existing)) {
|
|
|
|
throw new UploadException("Image to replace does not exist!");
|
|
|
|
}
|
|
|
|
if ($existing->hash === $event->metadata['hash']) {
|
|
|
|
throw new UploadException("The uploaded image is the same as the one to replace.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// even more hax..
|
|
|
|
$event->metadata['tags'] = $existing->get_tag_list();
|
2019-06-15 16:18:52 +00:00
|
|
|
$image = $this->create_image_from_data(warehouse_path(Image::IMAGE_DIR, $event->metadata['hash']), $event->metadata);
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
if (is_null($image)) {
|
|
|
|
throw new UploadException("Data handler failed to create image object from data");
|
|
|
|
}
|
|
|
|
|
|
|
|
$ire = new ImageReplaceEvent($image_id, $image);
|
|
|
|
send_event($ire);
|
|
|
|
$event->image_id = $image_id;
|
|
|
|
} else {
|
2019-06-15 16:18:52 +00:00
|
|
|
$image = $this->create_image_from_data(warehouse_path(Image::IMAGE_DIR, $event->hash), $event->metadata);
|
2019-05-28 16:59:38 +00:00
|
|
|
if (is_null($image)) {
|
|
|
|
throw new UploadException("Data handler failed to create image object from data");
|
|
|
|
}
|
|
|
|
$iae = new ImageAdditionEvent($image);
|
|
|
|
send_event($iae);
|
|
|
|
$event->image_id = $iae->image->id;
|
2019-06-20 00:40:25 +00:00
|
|
|
$event->merged = $iae->merged;
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
// Rating Stuff.
|
|
|
|
if (!empty($event->metadata['rating'])) {
|
|
|
|
$rating = $event->metadata['rating'];
|
|
|
|
send_event(new RatingSetEvent($image, $rating));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Locked Stuff.
|
|
|
|
if (!empty($event->metadata['locked'])) {
|
|
|
|
$locked = $event->metadata['locked'];
|
|
|
|
send_event(new LockSetEvent($image, !empty($locked)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif ($supported_ext && !$check_contents) {
|
|
|
|
throw new UploadException("Invalid or corrupted file");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onThumbnailGeneration(ThumbnailGenerationEvent $event)
|
|
|
|
{
|
2019-06-09 18:22:48 +00:00
|
|
|
$result = false;
|
2019-05-28 16:59:38 +00:00
|
|
|
if ($this->supported_ext($event->type)) {
|
2019-06-14 12:47:50 +00:00
|
|
|
if ($event->force) {
|
2019-06-14 17:34:53 +00:00
|
|
|
$result = $this->create_thumb($event->hash, $event->type);
|
2019-05-28 16:59:38 +00:00
|
|
|
} else {
|
2019-06-15 16:18:52 +00:00
|
|
|
$outname = warehouse_path(Image::THUMBNAIL_DIR, $event->hash);
|
2019-06-14 12:47:50 +00:00
|
|
|
if (file_exists($outname)) {
|
2019-06-09 18:22:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-06-14 17:34:53 +00:00
|
|
|
$result = $this->create_thumb($event->hash, $event->type);
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-14 12:47:50 +00:00
|
|
|
if ($result) {
|
2019-06-09 18:22:48 +00:00
|
|
|
$event->generated = true;
|
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function onDisplayingImage(DisplayingImageEvent $event)
|
|
|
|
{
|
|
|
|
global $page;
|
|
|
|
if ($this->supported_ext($event->image->ext)) {
|
|
|
|
$this->theme->display_image($page, $event->image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
public function onSetupBuilding(SetupBuildingEvent $event) {
|
|
|
|
$sb = $this->setup();
|
|
|
|
if($sb) $event->panel->add_block($sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function setup() {}
|
|
|
|
*/
|
|
|
|
|
|
|
|
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);
|
2019-06-14 17:34:53 +00:00
|
|
|
abstract protected function create_thumb(string $hash, string $type): bool;
|
2009-07-16 19:20:53 +00:00
|
|
|
}
|