/** * Render the widget. * * @param array $args General widget arguments. * @param array $instance Specific instance arguments. * @uses WebcomicTag::get_webcomic_collection() * @uses WebcomicTag::relative_webcomic_link() */ public function widget($args, $instance) { extract($args); extract($instance); $relative = $cache ? "{$relative}-nocache" : $relative; $collection = isset($collection) ? $collection : WebcomicTag::get_webcomic_collection(); if (!empty($image) and $image = wp_get_attachment_image($image, 'full')) { $link = preg_replace('/alt=".+?"/', 'alt="' . esc_attr($link) . '"', $image); } if ($output = WebcomicTag::relative_webcomic_link('%link', $link, $relative, (bool) $in_same_term, false, $in_same_term, $collection)) { echo $before_widget, empty($title) ? '' : $before_title . $title . $after_title, $output, $after_widget; } }
/** * Render a link to a randomly selected webcomic. * * <code class="php"> * // render a link to a random webcomic * random_webcomic_link(); * * // render a link to a random webcomic with a small preview * random_webcomic_link( '%link', '%thumbnail' ); * * // render a link to a random webcomic in the current storylines, excluding the storyline with an ID of 42 * random_webcomic_link( '<b>%link</b>', 'Random Comic', true, 42 ); * * // render a link to a random webcomic with a large preview in collection 42 using a parameterized url * random_webcomic_link( '%link', '%large', false, false, '', 'webcomic42', false ); * </code> * * <code class="bbcode"> * // render a link to a random webcomic * [random_webcomic_link] * * // render a link to a random webcomic with a small preview * [random_webcomic_link link="%thumbnail"] * * // render a link to a random webcomic in the current storylines, excluding the storyline with an ID of 42 * [random_webcomic_link format="<b>%link</b>" in_same_term="true" excluded_terms="42"]Random Comic[/random_webcomic_link] * * // render a link to a random webcomic with a large preview in collection 42 using a parameterized url * [random_webcomic_link collection="webcomic42" cache="false"]%large[/random_webcomic_link] * </code> * * @package Webcomic * @param string $format Format string for the link. Should include the %link token, which will be replaced by the actual link. * @param string $link Format string for the link text. Accepts %title, %date, and image size tokens. * @param mixed $in_same_term Whether the linked webcomic should be in a same term. May also be an array or comma-separated list of inclusive term IDs. * @param mixed $excluded_terms An array or comma-separated list of excluded term IDs. * @param string $taxonomy The taxonomy of the terms specified in the $in_same_term and $excluded_terms arguments. The shorthand 'storyline' or 'character' may be used. * @param string $collection The collection to retrieve from. Used when linking first, last, or random webcomics outside of the loop. * @param boolean $cache Whether to use a parameterized URL. * @uses WebcomicTag::relative_webcomic_link() */ function random_webcomic_link($format = '%link', $link = '', $in_same_term = false, $excluded_terms = false, $taxonomy = 'storyline', $collection = '', $cache = true) { echo WebcomicTag::relative_webcomic_link($format, $link, $cache ? 'random' : 'random-nocache', $in_same_term, $excluded_terms, $taxonomy, $collection); }
/** * Handle (relative)_webcomic_link shortcodes. * * @param array $atts Shortcode attributes. * @param string $content Shortcode content. * @param string $name Shortcode name. * @return string * @uses WebcomicTag::relative_webcomic_link() * @uses WebcomicTag::purchase_webcomic_link() */ public function the_webcomic_link($atts, $content, $name) { extract(shortcode_atts(array('format' => '%link', 'link' => '', 'in_same_term' => false, 'excluded_terms' => '', 'taxonomy' => 'storyline', 'collection' => '', 'the_post' => false, 'cache' => true), $atts)); $relative = substr($name, 0, strpos($name, '_')); if ('first' === $relative and !$cache) { $relative = 'first-nocache'; } elseif ('last' === $relative and !$cache) { $relative = 'last-nocache'; } elseif ('random' === $relative and !$cache) { $relative = 'random-nocache'; } if (!$link) { if ($content) { $link = do_shortcode($content); } elseif ('previous' === $relative) { $link = '‹'; } elseif ('next' === $relative) { $link = '›'; } elseif ('first' === $relative or 'first-nocache' === $relative) { $link = '«'; } elseif ('last' === $relative or 'last-nocache' === $relative) { $link = '»'; } elseif ('random' === $relative or 'random-nocache' === $relative) { $link = '∞'; } elseif ('purchase' === $relative) { $link = '¤'; } } return 'purchase' === $relative ? WebcomicTag::purchase_webcomic_link($format, $link, $the_post) : WebcomicTag::relative_webcomic_link($format, $link, $relative, $in_same_term, $excluded_terms, $taxonomy, $collection); }