/** * Insert HTML meta tags into site head. */ public function insert_twitter_card_metadata() { $post_id = get_the_ID(); if (!$post_id) { return; } $episode = \Podlove\Model\Episode::find_one_by_post_id($post_id); if (!$episode) { return; } $podcast = Model\Podcast::get(); $cover_art_url = $episode->cover_art_with_fallback()->url(); // define meta tags $data = array(array('name' => 'twitter:card', 'content' => 'summary'), array('name' => 'twitter:url', 'content' => get_permalink()), array('name' => 'twitter:title', 'content' => get_the_title()), array('name' => 'twitter:description', 'content' => $episode->description())); if ($site = $this->get_module_option('site')) { $data[] = array('name' => 'twitter:site', 'content' => $site); } if ($creator = $this->get_module_option('creator')) { $data[] = array('name' => 'twitter:creator', 'content' => $creator); } if ($cover_art_url) { $data[] = array('name' => 'twitter:image', 'content' => $cover_art_url); } // print meta tags $dom = new DomDocumentFragment(); foreach ($data as $meta_element) { $element = $dom->createElement('meta'); foreach ($meta_element as $attribute => $value) { $element->setAttribute($attribute, $value); } $dom->appendChild($element); } echo $dom; }
public function register_oembed_discovery() { // WordPress does not allow registering custom <link> elements. if (!is_single()) { return; } $post_id = get_the_ID(); if (get_post_type($post_id) !== 'podcast') { return; } $permalink = get_permalink($post_id); $permalink_template = $permalink . (strpos($permalink, '?') === FALSE ? "?" : "&"); $title = get_the_title($post_id); $embed_elements = array(array('rel' => 'alternate', 'type' => 'application/json+oembed', 'href' => $permalink_template . "service=podlove-oembed&format=json", 'title' => $title . " oEmbed Profile"), array('rel' => 'alternate', 'type' => 'application/xml+oembed', 'href' => $permalink_template . "service=podlove-oembed&format=xml", 'title' => $title . " oEmbed Profile")); $dom = new DomDocumentFragment(); foreach ($embed_elements as $link_element) { $element = $dom->createElement('link'); foreach ($link_element as $attribute => $value) { $element->setAttribute($attribute, $value); } $dom->appendChild($element); } echo $dom; }
/** * Insert HTML meta tags into site head. * * @todo caching * @todo let user choose what's in og:description: subtitle, excerpt, ... * @todo handle multiple releases per episode */ public static function get_open_graph_metadata() { $post_id = get_the_ID(); if (!$post_id) { return; } $episode = \Podlove\Model\Episode::find_one_by_post_id($post_id); if (!$episode) { return; } $podcast = Model\Podcast::get(); $cover_art_url = $episode->cover_art_with_fallback()->url(); // determine featured image (thumbnail) $thumbnail = NULL; if (has_post_thumbnail()) { $post_thumbnail_id = get_post_thumbnail_id($post_id); $thumbnailInfo = wp_get_attachment_image_src($post_thumbnail_id); if (is_array($thumbnailInfo)) { list($thumbnail, $width, $height) = $thumbnailInfo; } } $description = NULL; if ($episode->summary && $episode->subtitle) { $description = $episode->subtitle . "\n" . $episode->summary; } elseif ($episode->summary) { $description = $episode->summary; } elseif ($episode->subtitle) { $description = $episode->subtitle; } // define meta tags $data = array(array('property' => 'og:type', 'content' => 'website'), array('property' => 'og:site_name', 'content' => $podcast->title ? $podcast->title : get_the_title()), array('property' => 'og:title', 'content' => get_the_title()), array('property' => 'og:url', 'content' => get_permalink())); if ($description) { $data[] = array('property' => 'og:description', 'content' => $description); } if ($cover_art_url) { $data[] = array('property' => 'og:image', 'content' => $cover_art_url); } if (isset($thumbnail)) { $data[] = array('property' => 'og:image', 'content' => $thumbnail); } foreach ($episode->media_files() as $media_file) { $mime_type = $media_file->episode_asset()->file_type()->mime_type; if (stripos($mime_type, 'audio') !== false) { $data[] = array('property' => 'og:audio', 'content' => $media_file->get_file_url()); $data[] = array('property' => 'og:audio:type', 'content' => $mime_type); } } // print meta tags $dom = new DomDocumentFragment(); foreach ($data as $meta_element) { $element = $dom->createElement('meta'); foreach ($meta_element as $attribute => $value) { $element->setAttribute($attribute, $value); } $dom->appendChild($element); } return $dom; }
private function getContributorXML($contributor) { $contributor_xml = ''; if ($contributor->visibility == 1) { $dom = new \Podlove\DomDocumentFragment(); $xml = $dom->createElement('atom:contributor'); // add the empty name tag $name = $dom->createElement('atom:name'); $xml->appendChild($name); // fill name tag with escaped content $name_text = $dom->createTextNode($contributor->getName()); $name->appendChild($name_text); if ($contributor->guid) { $xml->appendChild($dom->createElement('atom:uri', $contributor->guid)); } $dom->appendChild($xml); $contributor_xml .= (string) $dom; } return $contributor_xml; }