ig_caticons = $table_prefix.'ig_caticons';
if (basename($_SERVER['SCRIPT_NAME']) == 'plugins.php' && isset($_GET['activate']) && $_GET['activate'] == 'true')
add_action('init', 'ig_caticons_install');
add_action('admin_menu', 'ig_caticons_adminmenu');
/*------------------ Initialization and Hooks END ----------------------------*/
/**
* 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'] .= '';
$p['suffix'] = ''.$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]$p[suffix]");
return true;
}
return false;
}
/**
* Install the plugin
* @access private
*/
function ig_caticons_install() {
global $wpdb, $table_prefix;
$wpdb->query("CREATE TABLE IF NOT EXISTS `$wpdb->ig_caticons` (
`cat_id` INT NOT NULL ,
`icon` TEXT NOT NULL ,
`small_icon` TEXT NOT NULL ,
PRIMARY KEY ( `cat_id` ))");
add_option('igcaticons_path', '');
add_option('igcaticons_url', '');
add_option('igcaticons_filetypes', 'jpg gif jpeg png');
}
function ig_caticons_defupload() {
$def_path = str_replace(ABSPATH, '', get_settings('upload_path'));
$def_url = trailingslashit(get_settings('siteurl')) . $def_path;
return array($def_path, $def_url);
}
/**
* Integrate into the admin menu.
* @access private
*/
function ig_caticons_adminmenu() {
define('IG_ADMIN_SELF', $_SERVER['PHP_SELF'].'?page='.$_REQUEST['page']);
if (function_exists('add_options_page'))
add_options_page(
'Cat Icons',
'Category Icons',
5,
basename(__FILE__),
'ig_caticons_adminpanel');
}
/**
* Handle admin panel
* @access private
*/
function ig_caticons_adminpanel() {
?>