コード例 #1
0
 private function html()
 {
     if (!count($this->args['data']['feeds'])) {
         return '';
     }
     $dataAccessor = 'podcastData' . self::get_random_string();
     $dom = new \Podlove\DomDocumentFragment();
     $script_data_tag = $dom->createElement('script');
     $script_data_tag->appendChild($dom->createTextNode(sprintf("window.{$dataAccessor} = %s;", json_encode($this->args['data']))));
     $script_button_tag = $dom->createElement('script');
     $script_button_tag->setAttribute('class', 'podlove-subscribe-button');
     $script_button_tag->setAttribute('src', 'https://cdn.podlove.org/subscribe-button/javascripts/app.js');
     $script_button_tag->setAttribute('data-json-data', $dataAccessor);
     $script_button_tag->setAttribute('data-language', self::language($this->args['language']));
     $script_button_tag->setAttribute('data-size', self::size($this->args['size'], $this->args['width']));
     if ($this->args['colors']) {
         $script_button_tag->setAttribute('data-colors', $this->args['colors']);
     }
     if ($this->args['buttonid']) {
         $script_button_tag->setAttribute('data-buttonid', $this->args['buttonid']);
     }
     if ($this->args['hide'] && in_array($args['hide'], [1, '1', true, 'true', 'on'])) {
         $script_button_tag->setAttribute('data-hide', true);
     }
     // ensure there is a closing script tag
     $script_button_tag->appendChild($dom->createTextNode(' '));
     $dom->appendChild($script_data_tag);
     $dom->appendChild($script_button_tag);
     return (string) $dom;
 }
コード例 #2
0
function override_feed_head($hook, $podcast, $feed, $format)
{
    $filter_hooks = array('podlove_feed_itunes_author', 'podlove_feed_itunes_owner', 'podlove_feed_itunes_subtitle', 'podlove_feed_itunes_keywords', 'podlove_feed_itunes_summary', 'podlove_feed_itunes_complete', 'podlove_feed_itunes_explicit');
    foreach ($filter_hooks as $filter) {
        add_filter($filter, 'convert_chars');
    }
    add_filter('podlove_feed_content', '\\Podlove\\Feeds\\prepare_for_feed');
    remove_action($hook, 'the_generator');
    add_action($hook, function () use($hook) {
        switch ($hook) {
            case 'rss2_head':
                $gen = '<generator>' . \Podlove\get_plugin_header('Name') . ' v' . \Podlove\get_plugin_header('Version') . '</generator>';
                break;
            case 'atom_head':
                $gen = '<generator uri="' . \Podlove\get_plugin_header('PluginURI') . '" version="' . \Podlove\get_plugin_header('Version') . '">' . \Podlove\get_plugin_header('Name') . '</generator>';
                break;
        }
        echo $gen;
    });
    add_action($hook, function () use($feed) {
        echo $feed->get_self_link();
        echo $feed->get_alternate_links();
    }, 9);
    // add rss image
    add_action($hook, function () use($podcast, $hook) {
        $image = ['url' => $podcast->cover_art()->url(), 'title' => $podcast->title, 'link' => apply_filters('podlove_feed_link', \Podlove\get_landing_page_url())];
        $image = apply_filters('podlove_feed_image', $image);
        if (!$image['url']) {
            return;
        }
        // remove WordPress provided favicon
        remove_action($hook, 'rss2_site_icon');
        // generate our own image tag
        $dom = new \Podlove\DomDocumentFragment();
        $image_tag = $dom->createElement('image');
        foreach ($image as $tag_name => $tag_text) {
            if ($tag_text) {
                $tag = $dom->createElement($tag_name);
                $tag_text = $dom->createTextNode($tag_text);
                $tag->appendChild($tag_text);
                $image_tag->appendChild($tag);
            }
        }
        $dom->appendChild($image_tag);
        echo (string) $dom;
    }, 5);
    // let it run early so we can stop the `rss2_site_icon` call
    add_action($hook, function () use($podcast, $feed, $format) {
        echo PHP_EOL;
        $author = "\t" . sprintf('<itunes:author>%s</itunes:author>', $podcast->author_name);
        echo apply_filters('podlove_feed_itunes_author', $author);
        echo PHP_EOL;
        $summary = "\t" . sprintf('<itunes:summary>%s</itunes:summary>', $podcast->summary);
        echo apply_filters('podlove_feed_itunes_summary', $summary);
        echo PHP_EOL;
        $categories = \Podlove\Itunes\categories(false);
        $category_html = '';
        for ($i = 1; $i <= 3; $i++) {
            $category_id = $podcast->{'category_' . $i};
            if (!$category_id) {
                continue;
            }
            list($cat, $subcat) = explode('-', $category_id);
            if ($subcat == '00') {
                $category_html .= sprintf('<itunes:category text="%s"></itunes:category>', htmlspecialchars($categories[$category_id]));
            } else {
                $category_html .= sprintf('<itunes:category text="%s"><itunes:category text="%s"></itunes:category></itunes:category>', htmlspecialchars($categories[$cat . '-00']), htmlspecialchars($categories[$category_id]));
            }
        }
        echo apply_filters('podlove_feed_itunes_categories', $category_html);
        echo PHP_EOL;
        $owner = sprintf('
	<itunes:owner>
		<itunes:name>%s</itunes:name>
		<itunes:email>%s</itunes:email>
	</itunes:owner>', $podcast->owner_name, $podcast->owner_email);
        echo "\t" . apply_filters('podlove_feed_itunes_owner', $owner);
        echo PHP_EOL;
        if ($podcast->cover_art()->url()) {
            $coverimage = sprintf('<itunes:image href="%s" />', $podcast->cover_art()->url());
        } else {
            $coverimage = '';
        }
        echo "\t" . apply_filters('podlove_feed_itunes_image', $coverimage);
        echo PHP_EOL;
        $subtitle = sprintf('<itunes:subtitle>%s</itunes:subtitle>', $podcast->subtitle);
        echo "\t" . apply_filters('podlove_feed_itunes_subtitle', $subtitle);
        echo PHP_EOL;
        $keywords = sprintf('<itunes:keywords>%s</itunes:keywords>', $podcast->keywords);
        echo "\t" . apply_filters('podlove_feed_itunes_keywords', $keywords);
        echo PHP_EOL;
        $block = sprintf('<itunes:block>%s</itunes:block>', $feed->enable ? 'no' : 'yes');
        echo "\t" . apply_filters('podlove_feed_itunes_block', $block);
        echo PHP_EOL;
        $explicit = sprintf('<itunes:explicit>%s</itunes:explicit>', $podcast->explicit == 2 ? 'clean' : ($podcast->explicit ? 'yes' : 'no'));
        echo "\t" . apply_filters('podlove_feed_itunes_explicit', $explicit);
        echo PHP_EOL;
        $complete = sprintf('<itunes:complete>%s</itunes:complete>', $podcast->complete ? 'yes' : 'no');
        echo apply_filters('podlove_feed_itunes_complete', $podcast->complete ? "\t{$complete}" : '');
        echo PHP_EOL;
        do_action('podlove_append_to_feed_head', $podcast, $feed, $format);
    });
}