Added window title option to post title extension
This commit is contained in:
parent
c3f2d2e1bd
commit
dd6c3b2321
@ -5,4 +5,5 @@ abstract class PostTitlesConfig
|
|||||||
{
|
{
|
||||||
public const VERSION = "ext_post_titles_version";
|
public const VERSION = "ext_post_titles_version";
|
||||||
public const DEFAULT_TO_FILENAME = "post_titles_default_to_filename";
|
public const DEFAULT_TO_FILENAME = "post_titles_default_to_filename";
|
||||||
|
public const SHOW_IN_WINDOW_TITLE = "post_titles_show_in_window_title";
|
||||||
}
|
}
|
@ -1 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
class PostTitleSetEvent extends Event
|
||||||
|
{
|
||||||
|
public $image;
|
||||||
|
public $title;
|
||||||
|
|
||||||
|
public function __construct(Image $image, String $title)
|
||||||
|
{
|
||||||
|
$this->image = $image;
|
||||||
|
$this->title = $title;
|
||||||
|
}
|
||||||
|
}
|
@ -11,11 +11,17 @@ require_once "events/post_title_set_event.php";
|
|||||||
|
|
||||||
class PostTitles extends Extension
|
class PostTitles extends Extension
|
||||||
{
|
{
|
||||||
|
public function get_priority(): int
|
||||||
|
{
|
||||||
|
return 60;
|
||||||
|
}
|
||||||
|
|
||||||
public function onInitExt(InitExtEvent $event)
|
public function onInitExt(InitExtEvent $event)
|
||||||
{
|
{
|
||||||
global $config, $database;
|
global $config, $database;
|
||||||
|
|
||||||
$config->set_default_bool(PostTitlesConfig::DEFAULT_TO_FILENAME, false);
|
$config->set_default_bool(PostTitlesConfig::DEFAULT_TO_FILENAME, false);
|
||||||
|
$config->set_default_bool(PostTitlesConfig::SHOW_IN_WINDOW_TITLE, false);
|
||||||
|
|
||||||
if ($config->get_int(PostTitlesConfig::VERSION) < 1) {
|
if ($config->get_int(PostTitlesConfig::VERSION) < 1) {
|
||||||
$this->install();
|
$this->install();
|
||||||
@ -32,6 +38,15 @@ class PostTitles extends Extension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onDisplayingImage(DisplayingImageEvent $event)
|
||||||
|
{
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if($config->get_bool(PostTitlesConfig::SHOW_IN_WINDOW_TITLE)) {
|
||||||
|
$event->set_title(self::get_title($event->get_image()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event)
|
public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event)
|
||||||
{
|
{
|
||||||
global $user;
|
global $user;
|
||||||
@ -59,11 +74,14 @@ class PostTitles extends Extension
|
|||||||
$sb = new SetupBlock("Post Titles");
|
$sb = new SetupBlock("Post Titles");
|
||||||
$sb->start_table();
|
$sb->start_table();
|
||||||
$sb->add_bool_option(PostTitlesConfig::DEFAULT_TO_FILENAME,"Default to filename", true);
|
$sb->add_bool_option(PostTitlesConfig::DEFAULT_TO_FILENAME,"Default to filename", true);
|
||||||
|
$sb->add_bool_option(PostTitlesConfig::SHOW_IN_WINDOW_TITLE,"Show in window title", true);
|
||||||
$sb->end_table();
|
$sb->end_table();
|
||||||
|
|
||||||
$event->panel->add_block($sb);
|
$event->panel->add_block($sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private function set_title(int $image_id, string $title)
|
private function set_title(int $image_id, string $title)
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
@ -78,7 +96,11 @@ class PostTitles extends Extension
|
|||||||
$title = $image->title??"";
|
$title = $image->title??"";
|
||||||
if(empty($title) && $config->get_bool(PostTitlesConfig::DEFAULT_TO_FILENAME)) {
|
if(empty($title) && $config->get_bool(PostTitlesConfig::DEFAULT_TO_FILENAME)) {
|
||||||
$info = pathinfo($image->filename);
|
$info = pathinfo($image->filename);
|
||||||
$title = basename($image->filename,'.'.$info['extension']);
|
if(array_key_exists("extension",$info)) {
|
||||||
|
$title = basename($image->filename, '.' . $info['extension']);
|
||||||
|
} else {
|
||||||
|
$title = $image->filename;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $title;
|
return $title;
|
||||||
}
|
}
|
||||||
|
23
ext/view/events/displaying_image_event.php
Normal file
23
ext/view/events/displaying_image_event.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class DisplayingImageEvent extends Event
|
||||||
|
{
|
||||||
|
/** @var Image */
|
||||||
|
public $image;
|
||||||
|
|
||||||
|
public $title;
|
||||||
|
|
||||||
|
public function __construct(Image $image)
|
||||||
|
{
|
||||||
|
$this->image = $image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_image(): Image
|
||||||
|
{
|
||||||
|
return $this->image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_title(String $title) {
|
||||||
|
$this->title = $title;
|
||||||
|
}
|
||||||
|
}
|
25
ext/view/events/image_admin_block_building_event.php
Normal file
25
ext/view/events/image_admin_block_building_event.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ImageAdminBlockBuildingEvent extends Event
|
||||||
|
{
|
||||||
|
/** @var string[] */
|
||||||
|
public $parts = [];
|
||||||
|
/** @var ?Image */
|
||||||
|
public $image = null;
|
||||||
|
/** @var ?User */
|
||||||
|
public $user = null;
|
||||||
|
|
||||||
|
public function __construct(Image $image, User $user)
|
||||||
|
{
|
||||||
|
$this->image = $image;
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_part(string $html, int $position=50)
|
||||||
|
{
|
||||||
|
while (isset($this->parts[$position])) {
|
||||||
|
$position++;
|
||||||
|
}
|
||||||
|
$this->parts[$position] = $html;
|
||||||
|
}
|
||||||
|
}
|
25
ext/view/events/image_info_box_building_event.php
Normal file
25
ext/view/events/image_info_box_building_event.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ImageInfoBoxBuildingEvent extends Event
|
||||||
|
{
|
||||||
|
/** @var array */
|
||||||
|
public $parts = [];
|
||||||
|
/** @var Image */
|
||||||
|
public $image;
|
||||||
|
/** @var User */
|
||||||
|
public $user;
|
||||||
|
|
||||||
|
public function __construct(Image $image, User $user)
|
||||||
|
{
|
||||||
|
$this->image = $image;
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_part(string $html, int $position=50)
|
||||||
|
{
|
||||||
|
while (isset($this->parts[$position])) {
|
||||||
|
$position++;
|
||||||
|
}
|
||||||
|
$this->parts[$position] = $html;
|
||||||
|
}
|
||||||
|
}
|
12
ext/view/events/image_info_set_event.php
Normal file
12
ext/view/events/image_info_set_event.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ImageInfoSetEvent extends Event
|
||||||
|
{
|
||||||
|
/** @var Image */
|
||||||
|
public $image;
|
||||||
|
|
||||||
|
public function __construct(Image $image)
|
||||||
|
{
|
||||||
|
$this->image = $image;
|
||||||
|
}
|
||||||
|
}
|
@ -14,80 +14,12 @@
|
|||||||
* wish to appear on the "view" page should listen for this,
|
* wish to appear on the "view" page should listen for this,
|
||||||
* which only appears when an image actually exists.
|
* which only appears when an image actually exists.
|
||||||
*/
|
*/
|
||||||
class DisplayingImageEvent extends Event
|
|
||||||
{
|
|
||||||
/** @var Image */
|
|
||||||
public $image;
|
|
||||||
|
|
||||||
public function __construct(Image $image)
|
require_once "events/displaying_image_event.php";
|
||||||
{
|
require_once "events/image_info_box_building_event.php";
|
||||||
$this->image = $image;
|
require_once "events/image_info_set_event.php";
|
||||||
}
|
require_once "events/image_admin_block_building_event.php";
|
||||||
|
|
||||||
public function get_image(): Image
|
|
||||||
{
|
|
||||||
return $this->image;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ImageInfoBoxBuildingEvent extends Event
|
|
||||||
{
|
|
||||||
/** @var array */
|
|
||||||
public $parts = [];
|
|
||||||
/** @var Image */
|
|
||||||
public $image;
|
|
||||||
/** @var User */
|
|
||||||
public $user;
|
|
||||||
|
|
||||||
public function __construct(Image $image, User $user)
|
|
||||||
{
|
|
||||||
$this->image = $image;
|
|
||||||
$this->user = $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add_part(string $html, int $position=50)
|
|
||||||
{
|
|
||||||
while (isset($this->parts[$position])) {
|
|
||||||
$position++;
|
|
||||||
}
|
|
||||||
$this->parts[$position] = $html;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ImageInfoSetEvent extends Event
|
|
||||||
{
|
|
||||||
/** @var Image */
|
|
||||||
public $image;
|
|
||||||
|
|
||||||
public function __construct(Image $image)
|
|
||||||
{
|
|
||||||
$this->image = $image;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ImageAdminBlockBuildingEvent extends Event
|
|
||||||
{
|
|
||||||
/** @var string[] */
|
|
||||||
public $parts = [];
|
|
||||||
/** @var ?Image */
|
|
||||||
public $image = null;
|
|
||||||
/** @var ?User */
|
|
||||||
public $user = null;
|
|
||||||
|
|
||||||
public function __construct(Image $image, User $user)
|
|
||||||
{
|
|
||||||
$this->image = $image;
|
|
||||||
$this->user = $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add_part(string $html, int $position=50)
|
|
||||||
{
|
|
||||||
while (isset($this->parts[$position])) {
|
|
||||||
$position++;
|
|
||||||
}
|
|
||||||
$this->parts[$position] = $html;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ViewImage extends Extension
|
class ViewImage extends Extension
|
||||||
{
|
{
|
||||||
@ -140,7 +72,9 @@ class ViewImage extends Extension
|
|||||||
$image = Image::by_id($image_id);
|
$image = Image::by_id($image_id);
|
||||||
|
|
||||||
if (!is_null($image)) {
|
if (!is_null($image)) {
|
||||||
send_event(new DisplayingImageEvent($image));
|
$die = new DisplayingImageEvent($image);
|
||||||
|
send_event($die);
|
||||||
|
$page->set_title(html_escape($die->title));
|
||||||
$iabbe = new ImageAdminBlockBuildingEvent($image, $user);
|
$iabbe = new ImageAdminBlockBuildingEvent($image, $user);
|
||||||
send_event($iabbe);
|
send_event($iabbe);
|
||||||
ksort($iabbe->parts);
|
ksort($iabbe->parts);
|
||||||
@ -169,6 +103,9 @@ class ViewImage extends Extension
|
|||||||
send_event($iibbe);
|
send_event($iibbe);
|
||||||
ksort($iibbe->parts);
|
ksort($iibbe->parts);
|
||||||
$this->theme->display_meta_headers($event->get_image());
|
$this->theme->display_meta_headers($event->get_image());
|
||||||
|
|
||||||
|
$event->title = "Image {$event->get_image()->id}: ".$event->get_image()->get_tag_list();
|
||||||
|
|
||||||
$this->theme->display_page($event->get_image(), $iibbe->parts);
|
$this->theme->display_page($event->get_image(), $iibbe->parts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,6 @@ class ViewImageTheme extends Themelet
|
|||||||
public function display_page(Image $image, $editor_parts)
|
public function display_page(Image $image, $editor_parts)
|
||||||
{
|
{
|
||||||
global $page;
|
global $page;
|
||||||
|
|
||||||
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
|
|
||||||
$page->set_heading(html_escape($image->get_tag_list()));
|
$page->set_heading(html_escape($image->get_tag_list()));
|
||||||
$page->add_block(new Block("Navigation", $this->build_navigation($image), "left", 0));
|
$page->add_block(new Block("Navigation", $this->build_navigation($image), "left", 0));
|
||||||
$page->add_block(new Block(null, $this->build_info($image, $editor_parts), "main", 20));
|
$page->add_block(new Block(null, $this->build_info($image, $editor_parts), "main", 20));
|
||||||
|
@ -5,7 +5,6 @@ class CustomViewImageTheme extends ViewImageTheme
|
|||||||
public function display_page(Image $image, $editor_parts)
|
public function display_page(Image $image, $editor_parts)
|
||||||
{
|
{
|
||||||
global $page;
|
global $page;
|
||||||
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
|
|
||||||
$page->set_heading(html_escape($image->get_tag_list()));
|
$page->set_heading(html_escape($image->get_tag_list()));
|
||||||
$page->add_block(new Block("Navigation", $this->build_navigation($image), "left", 0));
|
$page->add_block(new Block("Navigation", $this->build_navigation($image), "left", 0));
|
||||||
$page->add_block(new Block("Statistics", $this->build_stats($image), "left", 15));
|
$page->add_block(new Block("Statistics", $this->build_stats($image), "left", 15));
|
||||||
|
@ -5,7 +5,6 @@ class CustomViewImageTheme extends ViewImageTheme
|
|||||||
public function display_page(Image $image, $editor_parts)
|
public function display_page(Image $image, $editor_parts)
|
||||||
{
|
{
|
||||||
global $page;
|
global $page;
|
||||||
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
|
|
||||||
$page->set_heading(html_escape($image->get_tag_list()));
|
$page->set_heading(html_escape($image->get_tag_list()));
|
||||||
$page->add_block(new Block("Search", $this->build_navigation($image), "left", 0));
|
$page->add_block(new Block("Search", $this->build_navigation($image), "left", 0));
|
||||||
$page->add_block(new Block("Information", $this->build_information($image), "left", 15));
|
$page->add_block(new Block("Information", $this->build_information($image), "left", 15));
|
||||||
|
@ -5,7 +5,6 @@ class CustomViewImageTheme extends ViewImageTheme
|
|||||||
public function display_page(Image $image, $editor_parts)
|
public function display_page(Image $image, $editor_parts)
|
||||||
{
|
{
|
||||||
global $page;
|
global $page;
|
||||||
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
|
|
||||||
$page->set_heading(html_escape($image->get_tag_list()));
|
$page->set_heading(html_escape($image->get_tag_list()));
|
||||||
$page->add_block(new Block(null, $this->build_info($image, $editor_parts), "main", 10));
|
$page->add_block(new Block(null, $this->build_info($image, $editor_parts), "main", 10));
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ class CustomViewImageTheme extends ViewImageTheme
|
|||||||
public function display_page(Image $image, $editor_parts)
|
public function display_page(Image $image, $editor_parts)
|
||||||
{
|
{
|
||||||
global $page;
|
global $page;
|
||||||
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
|
|
||||||
$page->set_heading(html_escape($image->get_tag_list()));
|
$page->set_heading(html_escape($image->get_tag_list()));
|
||||||
$page->add_block(new Block("Navigation", $this->build_navigation($image), "left", 0));
|
$page->add_block(new Block("Navigation", $this->build_navigation($image), "left", 0));
|
||||||
$page->add_block(new Block("Statistics", $this->build_stats($image), "left", 15));
|
$page->add_block(new Block("Statistics", $this->build_stats($image), "left", 15));
|
||||||
|
@ -8,7 +8,6 @@ class CustomViewImageTheme extends ViewImageTheme
|
|||||||
public function display_page(Image $image, $editor_parts)
|
public function display_page(Image $image, $editor_parts)
|
||||||
{
|
{
|
||||||
global $page;
|
global $page;
|
||||||
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
|
|
||||||
$page->set_heading(html_escape($image->get_tag_list()));
|
$page->set_heading(html_escape($image->get_tag_list()));
|
||||||
$page->add_block(new Block(null, $this->build_pin($image), "subtoolbar", 0));
|
$page->add_block(new Block(null, $this->build_pin($image), "subtoolbar", 0));
|
||||||
$page->add_block(new Block(null, $this->build_info($image, $editor_parts), "left", 20));
|
$page->add_block(new Block(null, $this->build_info($image, $editor_parts), "left", 20));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user