/** * WordPress Template Tag to Insert Category Icon * @param $fit_width int [-1] Maximum width (or desired width if $expanded=true) of the image. * @param $fit_height int[-1] Macimum height (or desired height if $expanded=true) of the image. * @param $expand boolean [false] Whether the image should be expanded to fit the rectangle specified by fit_xxx. * @param $cat int Category ID. If not specified, the current category is used or the current post's category. * @param $small boolean [false] Use the small icon. * @param $prefix string String to echo before the image tag. If no image, no otuput. * @param $suffix string String to echo after the image tag. Ignored if no image found. * @param $class string [] Class attribute for the image tag. * @param $link boolean [1] If true the image is made a hyperlink (wrapped by anchor tag). * * @return boolean True if image found. */ function get_cat_icon($params="") { parse_str($params, $p); if (!isset($p['fit_width'])) $p['fit_width']=-1; if (!isset($p['fit_height'])) $p['fit_height']=-1; if (!isset($p['expand'])) $p['expand']=false; if (!isset($p['cat'])) $p['cat']=$GLOBALS['cat']; if (!isset($p['small'])) $p['small']=false; if (!isset($p['prefix'])) $p['prefix'] = ''; if (!isset($p['suffix'])) $p['suffix'] = ''; if (!isset($p['class'])) $p['class'] = ''; if (!isset($p['link'])) $p['link'] = 1; stripslaghes_gpc_arr($p); if (empty($p['cat']) && isset($GLOBALS['post'])) { $catlist = get_the_category($GLOBALS['post']->ID); if (is_array($catlist)) { $p['cat'] = $catlist[0]->cat_ID; } } if (!isset($p['cat'])) return; list($icon, $small_icon) = ig_caticons_get_icons($p['cat']); if ($p['small']) { $file = ig_caticons_path()."/$small_icon"; $url = ig_caticons_url()."/$small_icon"; if (!is_file($file)) { $file = ig_caticons_path()."/$icon"; $url = ig_caticons_url()."/$icon"; } } else { $file = ig_caticons_path()."/$icon"; $url = ig_caticons_url()."/$icon"; if (!is_file($file)) { $file = ig_caticons_path()."/$small_icon"; $url = ig_caticons_url()."/$small_icon"; } } if ($p['link']) { $p['prefix'] .= '<a href="'.get_category_link($p['cat']).'">'; $p['suffix'] = '</a>'.$p['suffix']; } if (is_file($file)) { list($width, $height, $type, $attr) = getimagesize($file); list($w, $h) = ig_fit_rect($width, $height, $p['fit_width'], $p['fit_height'], $p['expand']); echo("$p[prefix]<img class=\"$p[class]\" src=\"$url\" width=\"$w\" height=\"$h\"/>$p[suffix]"); return true; } return false; }
/** * get_series_icon() - Template tag for insertion of series-icons * * @package Organize Series WordPress Plugin * @since 2.0 * * @uses parse_str() * @uses stripslaghes_gpc_arr() * @uses get_the_series() * @uses is_array() * @uses series_get_icons() * @uses seriesicons_path() * @uses seriesicons_url() * @uses get_series_link() * @uses getimagesize() * @uses series_fit_rect() * * @param int[-1] $fit_width Maximum width (or desired width if $expanded=true) of the image. * @param int[-1] $fit_height Macimum height (or desired height if $expanded=true) of the image. * @param boolean [false] $expand Whether the image should be expanded to fit the rectangle specified by fit_xxx. * @param int $series Series ID. If not specified, the current series is used or the current post's series. * @param string $prefix String to echo before the image tag. If no image, no otuput. * @param string $suffix String to echo after the image tag. Ignored if no image found. * @param string [] $class Class attribute for the image tag. * @param boolean [1] $link If true the image is made a hyperlink (wrapped by anchor tag). * @param boolean [1] $display If true the function will echo the image. If false the function will return the assembled image as a string. * * @return mixed|bool|string Will return false if image is not found. Will return string containing assembled html code for image if $display is false. Will echo image if the $display param = true. */ function get_series_icon($params = '') { global $orgseries; parse_str($params, $p); if (!isset($p['fit_width'])) { $p['fit_width'] = -1; } if (!isset($p['fit_height'])) { $p['fit_height'] = -1; } if (!isset($p['expand'])) { $p['expand'] = false; } if (!isset($p['series'])) { $p['series'] = get_query_var(SERIES_QUERYVAR); } if (!isset($p['prefix'])) { $p['prefix'] = ''; } if (!isset($p['suffix'])) { $p['suffix'] = ''; } if (!isset($p['class'])) { $p['class'] = 'series-icon-' . $p['series']; } if (!isset($p['link'])) { $p['link'] = 1; } if (!isset($p['display'])) { $p['display'] = 1; } stripslaghes_gpc_arr($p); if (empty($p['series']) && isset($GLOBALS['post'])) { $serieslist = get_the_series($GLOBALS['post']->ID); if (is_array($serieslist)) { $p['series'] = $serieslist[0]->term_id; } } $p['series'] = series_exists($p['series']); if (!isset($p['series'])) { return; } //make sure we get the id for the series (in case just the slug is given $icon = series_get_icons($p['series']); $s_name = get_series_name($p['series']); $file = seriesicons_path() . $icon; $url = seriesicons_url() . $icon; if ($p['link']) { $p['prefix'] .= '<a href="' . get_series_link($p['series']) . '">'; $p['suffix'] = '</a>' . $p['suffix']; } if (is_file($file)) { list($width, $height, $type, $attr) = getimagesize($file); list($w, $h) = series_fit_rect($width, $height, $p['fit_width'], $p['fit_height'], $p['expand']); $series_icon = $p['prefix'] . '<img class="' . $p['class'] . '" src="' . $url . '" width="' . $w . '" height="' . $h . '" alt="' . $icon . '" />' . $p['suffix']; if ($p['display'] == 1) { echo $series_icon; } else { return $series_icon; } } return false; }
/** * WordPress Template Tag to Insert Category Icon * @author Brahim Machkouri * @param boolean $align align attribute for the image tag * @param int $fit_width Maximum width of the image, or desired width if expand is true. Default : -1 * @param int $fit_height Maximum height (or desired height if $expanded=true) of the image. Default : -1 * @param boolean $expand Whether the image should be expanded to fit the rectangle specified by fit_xxx. Default : false * @param int $cat Category ID. If not specified, the current category is used or the current post's category. Default : * @param boolean $small Use the small icon. Default : false * @param string $prefix String to echo before the image tag. If no image, no output. Default : * @param string $suffix String to echo after the image tag. Ignored if no image found. Default : * @param string $class Class attribute for the image tag. Default : * @param boolean $link If true, an anchor tag wraps the image (a hyperlink to the category is made). Default : true * @param boolean $echo If true the html code will be 'echoed'. If no, it'll be returned. Default : true * @param boolean $use_priority If true, only the most prioritized icon will be displayed. Default : false * @param int $max_icons Maximum number of icons to display. Default : 3 * @param boolean $border If true, displays the icon with a border. If false, no border is diplayed. (Don't use this if you want valid Strict XHTML) * @param boolean $hierarchical If true, displays the icon in hierarchical order.(horizontally) * @return boolean True if image found. */ function get_cat_icon($params = '') { $one_category_only = false; if (0 < (int) get_option('igcaticons_iconcatpage', 0)) { $one_category_only = true; } // Compatibility with qTranslate if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) { remove_filter('wp_list_categories', 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage', 0); remove_filter('list_cats', 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage', 0); } // Compatibility with SEO Friendly Images if (function_exists('seo_friendly_images') && 1 == get_option('igcaticons_useseo_plugin')) { add_filter('category_icons', 'seo_friendly_images', 50); } parse_str($params, $p); if (!isset($p['fit_width'])) { $p['fit_width'] = (int) get_option('igcaticons_max_width'); } if (!isset($p['fit_height'])) { $p['fit_height'] = (int) get_option('igcaticons_max_height'); } if (!isset($p['expand'])) { $p['expand'] = false; } if (!isset($p['small'])) { $p['small'] = (int) get_option('igcaticons_use_small'); } if (!isset($p['prefix'])) { $p['prefix'] = ''; } if (!isset($p['suffix'])) { $p['suffix'] = ''; } if (!isset($p['class'])) { $p['class'] = ''; } if (!isset($p['link'])) { $p['link'] = true; } if (!isset($p['echo'])) { $p['echo'] = true; } if (!isset($p['use_priority'])) { $p['use_priority'] = false; } if (!isset($p['max_icons'])) { $p['max_icons'] = (int) get_option('igcaticons_max_icons'); } if (!isset($p['align'])) { $p['align'] = false; } if (!isset($p['hierarchical'])) { $p['hierarchical'] = false; } if (!$p['hierarchical'] === false) { $p['hierarchical'] = bm_caticons_getbool($p['hierarchical']); } if (!isset($p['orderby'])) { $p['orderby'] = 'name'; } $p['expand'] = bm_caticons_getbool($p['expand']); $p['small'] = bm_caticons_getbool($p['small']); $p['echo'] = bm_caticons_getbool($p['echo']); if (isset($p['border'])) { $p['border'] = bm_caticons_getbool($p['border']); } $p['use_priority'] = bm_caticons_getbool($p['use_priority']); if ($p['max_icons'] == 1) { $p['use_priority'] = true; } $p['link'] = bm_caticons_getbool($p['link']); stripslaghes_gpc_arr($p); if (is_category() && in_the_loop() && $one_category_only == true) { $cat = (int) get_query_var('cat'); $category = get_category($cat); if (!isset($p['cat']) || !is_array($p['cat'])) { $p['cat'] = array(); } $p['cat'][] = $category->cat_ID; } else { if (!isset($p['cat']) && isset($GLOBALS['post'])) { $catlist = get_the_category($GLOBALS['post']->ID); if (is_array($catlist)) { $p['cat'] = array(); if ($p['orderby'] != 'name' || $p['hierarchical'] == true) { $p['cat'] = bm_caticons_process_categories('orderby=' . $p['orderby'] . '&hierarchical=' . $p['hierarchical']); } else { foreach ($catlist as $categorie) { $p['cat'][] = $categorie->cat_ID; // Adds all the categories in the array $cat[$categorie->cat_ID] = $categorie->name; } } } } if (!isset($p['cat'][0])) { return; } if (!is_array($p['cat'])) { $categorie = (int) $p['cat']; $p['cat'] = array(); $p['cat'][] = $categorie; } } $nb_icons = 0; $urlbegin = ''; $urlend = ''; $cat_icons = ''; for ($i = 0; $i < count($p['cat']); $i++) { if ($p['use_priority']) { // if you decide to use the priority feature list($p['cat'][$i], $priority, $icon, $small_icon) = ow_caticons_get_priority_icon($p['cat']); } else { list($priority, $icon, $small_icon) = bm_caticons_get_icons($p['cat'][$i]); } if ($p['small']) { // If we choose to display the small icon $file = ig_caticons_path() . '/' . $small_icon; $url = ig_caticons_url() . '/' . $small_icon; if (!is_file($file)) { // if the small icon can't be found, the normal one will be loaded $file = ig_caticons_path() . '/' . $icon; $url = ig_caticons_url() . '/' . $icon; } } else { $file = ig_caticons_path() . '/' . $icon; $url = ig_caticons_url() . '/' . $icon; if (!is_file($file)) { // If the normal icon can't be found, the small one will be loaded $file = ig_caticons_path() . '/' . $small_icon; $url = ig_caticons_url() . '/' . $small_icon; } } if (is_file($file)) { if ($p['link']) { $urlbegin = '<a href="' . get_category_link($p['cat'][$i]) . '" title="'; if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) { // Compatibility with qTranslate $urlbegin .= qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage(get_cat_name($p['cat'][$i])); } else { $urlbegin .= get_cat_name($p['cat'][$i]); } $urlbegin .= '">'; $urlend = '</a>'; } list($width, $height, $type, $attr) = getimagesize($file); $w = (int) $width; $h = (int) $height; if (!empty($p['fit_width']) || !empty($p['fit_height'])) { list($w, $h) = ig_caticons_fit_rect($width, $height, $p['fit_width'], $p['fit_height'], $p['expand']); } $cat_icons .= $p['prefix'] . $urlbegin . '<img '; if (!empty($p['class'])) { $cat_icons .= 'class="' . $p['class'] . '" '; } if (isset($p['border'])) { if ($p['border']) { $cat_icons .= 'border="1" '; } else { $cat_icons .= 'border="0" '; } } if (!$p['align'] === false) { $cat_icons .= 'align="' . $p['align'] . '" '; } $fill_with_catname = get_cat_name($p['cat'][$i]); $title = 'title="' . $fill_with_catname . '"'; $alt = 'alt="' . $fill_with_catname . '"'; //$title; if (function_exists('seo_friendly_images') && 1 == get_option('igcaticons_useseo_plugin')) { $title = ''; } // Compatibility with qTranslate $cat_icons .= 'src="' . $url . '" width="' . $w . '" height="' . $h . '" ' . $alt . ' ' . $title . ' />' . $urlend . $p['suffix']; $nb_icons++; } if ($p['use_priority']) { break; } if ($nb_icons == $p['max_icons']) { break; } } if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) { // Add the filter again, as we finished to process the icon(s) add_filter('wp_list_categories', 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage', 0); add_filter('list_cats', 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage', 0); } $cat_icons = apply_filters('category_icons', $cat_icons); if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) { // Update the compatibility with qTranslate $cat_icons = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($cat_icons); } if ($p['echo']) { if (empty($cat_icons)) { return false; } else { echo $cat_icons; return true; // if echo get_cat_icon() is used, true will be displayed as "1". So the parameter echo=false must be used in this case. } } else { return $cat_icons; } }