dedupe 'og:' meta tags

This commit is contained in:
Shish 2018-11-05 19:17:42 +00:00
parent 55e0e32395
commit b93026ac1d
4 changed files with 12 additions and 23 deletions

View file

@ -144,6 +144,7 @@ class ViewImage extends Extension {
$iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user);
send_event($iibbe);
ksort($iibbe->parts);
$this->theme->display_meta_headers($event->get_image());
$this->theme->display_page($event->get_image(), $iibbe->parts);
}
}

View file

@ -1,20 +1,24 @@
<?php
class ViewImageTheme extends Themelet {
public function display_meta_headers(Image $image) {
global $page;
$h_metatags = str_replace(" ", ", ", html_escape($image->get_tag_list()));
$page->add_html_header("<meta name=\"keywords\" content=\"$h_metatags\">");
$page->add_html_header("<meta property=\"og:title\" content=\"$h_metatags\">");
$page->add_html_header("<meta property=\"og:type\" content=\"article\">");
$page->add_html_header("<meta property=\"og:image\" content=\"".make_http($image->get_thumb_link())."\">");
$page->add_html_header("<meta property=\"og:url\" content=\"".make_http(make_link("post/view/{$image->id}"))."\">");
}
/*
* Build a page showing $image and some info about it
*/
public function display_page(Image $image, $editor_parts) {
global $page;
$h_metatags = str_replace(" ", ", ", html_escape($image->get_tag_list()));
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
$page->add_html_header("<meta name=\"keywords\" content=\"$h_metatags\">");
$page->add_html_header("<meta property=\"og:title\" content=\"$h_metatags\">");
$page->add_html_header("<meta property=\"og:type\" content=\"article\">");
$page->add_html_header("<meta property=\"og:image\" content=\"".make_http($image->get_thumb_link())."\">");
$page->add_html_header("<meta property=\"og:url\" content=\"".make_http(make_link("post/view/{$image->id}"))."\">");
$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(null, $this->build_info($image, $editor_parts), "main", 20));

View file

@ -3,14 +3,8 @@
class CustomViewImageTheme extends ViewImageTheme {
public function display_page(Image $image, $editor_parts) {
global $page;
$metatags = str_replace(" ", ", ", html_escape($image->get_tag_list()));
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
$page->set_heading(html_escape($image->get_tag_list()));
$page->add_html_header("<meta name=\"keywords\" content=\"$metatags\">");
$page->add_html_header("<meta property=\"og:title\" content=\"$metatags\">");
$page->add_html_header("<meta property=\"og:type\" content=\"article\">");
$page->add_html_header("<meta property=\"og:image\" content=\"".make_http($image->get_thumb_link())."\">");
$page->add_html_header("<meta property=\"og:url\" content=\"".make_http(make_link("post/view/{$image->id}"))."\">");
$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(null, $this->build_info($image, $editor_parts), "main", 11));

View file

@ -1,22 +1,12 @@
<?php
class CustomViewImageTheme extends ViewImageTheme {
/*
* Build a page showing $image and some info about it
*/
public function display_page(Image $image, $editor_parts) {
global $page;
$h_metatags = str_replace(" ", ", ", html_escape($image->get_tag_list()));
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
$page->add_html_header("<meta name=\"keywords\" content=\"$h_metatags\">");
$page->add_html_header("<meta property=\"og:title\" content=\"$h_metatags\">");
$page->add_html_header("<meta property=\"og:type\" content=\"article\">");
$page->add_html_header("<meta property=\"og:image\" content=\"".make_http($image->get_thumb_link())."\">");
$page->add_html_header("<meta property=\"og:url\" content=\"".make_http(make_link("post/view/{$image->id}"))."\">");
$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_info($image, $editor_parts), "left", 20));