/** * Render the widget. * * @param array $args General widget arguments. * @param array $instance Specific instance arguments. * @uses WebcomicTag::get_webcomic_collection() * @uses WebcomicTag::relative_webcomic_term_link() */ public function widget($args, $instance) { extract($args); extract($instance); $collection = $collection ? $collection : WebcomicTag::get_webcomic_collection(); if (!empty($image) and $image = wp_get_attachment_image($image, 'full')) { $link = preg_replace('/alt=".+?"/', 'alt="' . $link . '"', $image); } if ($output = WebcomicTag::relative_webcomic_term_link('%link', $link, $target, $relative, "{$collection}_character")) { echo $before_widget, empty($title) ? '' : $before_title . $title . $after_title, $output, $after_widget; } }
/** * Render a link to a randomly selected webcomic character. * * <code class="php"> * // render a link to the archive page of a random webcomic * random_webcomic_character_link(); * * // render a link to the last webcomic in a random character with a small avatar preview * random_webcomic_character_link( '%link', '%thumbnail', 'last' ); * * // render a link to the archive page of a random character, even if it doesn't have any webcomics * random_webcomic_character_link( '%link', 'Random Character', 'archive', array( 'hide_empty' => false ) ); * * // render a link to a random page in a random character in collection 42 * random_webcomic_character_link( '%link', 'Random Character', 'random', array(), 'webcomic42' ); * * // render a link to the last webcomic in a random character with a large avatar in collection 42 using a parameterized url * random_webcomic_character_link( '%link', '%large', 'last', array(), 'webcomic42', false ); * </code> * * <code class="bbcode"> * // render a link to the archive page of a random webcomic * [random_webcomic_character_link] * * // render a link to the last webcomic in a random character with a small avatar preview * [random_webcomic_character_link link="%thumbnail" target="last"] * * // render a link to the archive page of a random character, even if it doesn't have any webcomics * [random_webcomic_character_link args="hide_empty=0"]Random Character[/random_webcomic_character_link] * * // render a link to a random page in a random character in collection 42 * [random_webcomic_character_link link="Random Character" target="random" collection="webcomic42"] * * // render a link to the last webcomic in a random character with a large avatar in collection 42 using a parameterized url * [random_webcomic_character_link link="%large" target="last" collection="webcomic42" cache="false"] * </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 and image size tokens. * @param string $target The target url, one of 'archive', 'first', 'last', or 'random'. * @param array $args An array of arguments to pass to get_terms(). * @param string $collection Collection ID to retrieve characters from. * @param boolean $cache Whether to use a parameterized webcomic character link. * @uses WebcomicTag::get_webcomic_collection() * @uses WebcomicTag::relative_webcomic_term_link() */ function random_webcomic_character_link($format = '%link', $link = '', $target = 'archive', $args = array(), $collection = '', $cache = true) { $taxonomy = ($collection and taxonomy_exists("{$collection}_character") or $collection = WebcomicTag::get_webcomic_collection()) ? "{$collection}_character" : ''; if (preg_match('/^webcomic\\d+_character$/', $taxonomy)) { echo WebcomicTag::relative_webcomic_term_link($format, $link, $target, $cache ? 'random' : 'random-nocache', $taxonomy, $args); } }
/** * Handle (relative)_webcomic_(storyline|character)_link shortcodes. * * @param array $atts Shortcode attributes. * @param string $content Shortcode content. * @param string $name Shortcode name. * @return string * @uses WebcomicTag::get_webcomic_collection() * @uses WebcomicTag::get_relative_webcomic_link() */ public function the_webcomic_term_link($atts, $content, $name) { extract(shortcode_atts(array('format' => '%link', 'link' => '', 'target' => 'archive', 'args' => array(), 'collection' => '', 'cache' => true), $atts)); $array = array(); $args = wp_parse_str($args, $array); $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 = '‹ %title'; } elseif ('next' === $relative) { $link = '%title ›'; } elseif ('first' === $relative or 'first-nocache' === $relative) { $link = '« %title'; } elseif ('last' === $relative or 'last-nocache' === $relative) { $link = '%title »'; } elseif ('random' === $relative or 'random-nocache' === $relative) { $link = '%title'; } } if (false !== strpos($name, 'storyline')) { $tax = 'storyline'; } elseif (false !== strpos($name, 'character')) { $tax = 'character'; } else { $tax = ''; } if ('previous' === $relative or 'next' === $relative) { $taxonomy = ((is_tax() or is_single()) and $collection = WebcomicTag::get_webcomic_collection()) ? "{$collection}_{$tax}" : ''; } else { $taxonomy = ($collection and taxonomy_exists("{$collection}_{$tax}") or $collection = WebcomicTag::get_webcomic_collection()) ? "{$collection}_{$tax}" : ''; } return WebcomicTag::relative_webcomic_term_link($format, $link, $target, $relative, $taxonomy, $args); }