post_content); } /***********************************************************************************/ /* Get thumbs with default options /* /* ALTAPPEND : text to append to create thumbnail name. Overide default if exists. /* WIDTH : resize width. Overide default if greater than 0. /* HEIGHT : resize height. Overide default if greater than 0. /* HCROP : horizontal crop. Crop if greater than 0. /* VCROP : vertical crop. Crop if greater than 0. /* KEEPRATIO : if set to 1, image ratio is kept. Overide default if exists. /* BASENAME : force generation of thumbnail and use generic name. Default to 0. /* TEXTBOX : write post title at the bottom of the thumbnail if = 1. Default to 0. /* MYCLASS : output class name in html /***********************************************************************************/ function get_thumb ($arg='') { global $post; return tb_post_thumb('URL='.get_permalink($post->ID).'&ALTTEXT='.$post->post_title.'&'.$arg); } /***********************************************************************************/ /* Get thumbs with default options - return array /* /* ALTAPPEND : text to append to create thumbnail name. Overide default if exists. /* WIDTH : resize width. Overide default if greater than 0. /* HEIGHT : resize height. Overide default if greater than 0. /* HCROP : horizontal crop. Crop if greater than 0. /* VCROP : vertical crop. Crop if greater than 0. /* KEEPRATIO : if set to 1, image ratio is kept. Overide default if exists. /* BASENAME : force generation of thumbnail and use generic name. Default to 0. /* TEXTBOX : write post title at the bottom of the thumbnail if = 1. Default to 0. /***********************************************************************************/ function get_thumb_array ($arg='') { global $post; return tb_post_thumb_array ('URL='.get_permalink($post->ID).'&ALTTEXT='.$post->post_title.'&'.$arg); } /***********************************************************************************/ /* Return a random thumb with permalink and post title. /* /* LIMIT : number of posts to test to obtain an image. Default is 5. /* WIDTH : resize width. Overide default if greater than 0. /* HEIGHT : resize height. Overide default if greater than 0. /* HCROP : horizontal crop. Crop if greater than 0. /* VCROP : vertical crop. Crop if greater than 0. /* KEEPRATIO : if set to 1, image ratio is kept. Overide default if exists. /* TEXTBOX : write post title at the bottom of the thumbnail if = 1. Default to 0. /* MYCLASS : output class name in html /***********************************************************************************/ function get_random_thumb ($arg='') { global $post; parse_str($arg, $new_args); $new_args = array_change_key_case($new_args, CASE_UPPER); if (isset($new_args['LIMIT'])) { $limit = $new_args['LIMIT']; settype($limit,"integer"); } else $limit = 5; if (isset($new_args['MYCLASSHREF'])) $myclasshref = $new_args['MYCLASSHREF']; else $myclasshref = ''; if (isset($new_args['MYCLASSIMG'])) $myclassimg = $new_args['MYCLASSIMG']; else $myclassimg = ''; if (isset($new_args['LB_EFFECT'])) { if ($new_args['LB_EFFECT']==1) $LB_effect = true; else $LB_effect = false;} else $LB_effect = false; $post_its = random_post($limit); foreach ($post_its as $post_it) : if (tb_content_test(true, $post_it->post_content)) { $post = wp_get_single_post($post_it->ID); setup_postdata($post); if ($LB_effect) { $post_array = get_thumb_array ($arg.'&ALTAPPEND=thumbrandom_&BASENAME=1'); echo LB_effect ('hs_overlay', 'drop-shadow', 700, 500, $post_array); } else { $post_array = tb_post_thumb_array('URL='.get_permalink($post->ID).'&ALTTEXT='.$post->post_title.'&ALTAPPEND=thumbrandom_&BASENAME=1&'.$arg); $post_link = tb_post_thumb_gen_image($post_array['post_url'], $post_array['server_image'], $post_array['image_location'], $post_array['alt_text'], $post_array['show_title'], $myclasshref, $myclassimg); if (empty($post_link)) echo _e('No image found'); else print $post_link; } break; } endforeach; flush(); } /***********************************************************************************/ /* Display recent posts /***********************************************************************************/ function get_recent_thumbs ($arg) { global $post; parse_str($arg, $new_args); $new_args = array_change_key_case($new_args, CASE_UPPER); if (isset($new_args['LIMIT'])) { $limit = $new_args['LIMIT']; settype($limit,"integer"); } else $limit = 8; if (isset($new_args['LB_EFFECT'])) { if ($new_args['LB_EFFECT']==1) $LB_effect = true; else $LB_effect = false;} else $LB_effect = false; if (isset($new_args['CATEGORY'])) { $cat_ID = $new_args['CATEGORY']; $posts = get_posts('category='.$cat_ID.'&numberposts='.$limit.'&offset=0'); } else $posts = get_posts('numberposts='.$limit.'&offset=0'); foreach ($posts as $post) : setup_postdata($post); $test_img = tb_post_thumb_test(true); $html_body = $post->post_content; if ($LB_effect) { $post_array = get_thumb_array ($arg); ?>
  • /* MYCLASSIMG : output class name in html
    /***********************************************************************************/ function tb_post_thumb($arg='') { global $post; parse_str($arg, $new_args); $new_args = array_change_key_case($new_args, CASE_UPPER); if (isset($new_args['MYCLASSHREF'])) $myclasshref = $new_args['MYCLASSHREF']; else $myclasshref = ''; if (isset($new_args['MYCLASSIMG'])) $myclassimg = $new_args['MYCLASSIMG']; else $myclassimg = ''; $thumb_array = tb_post_thumb_array ($arg); return tb_post_thumb_gen_image($thumb_array['post_url'], $thumb_array['server_image'], $thumb_array['image_location'], $thumb_array['alt_text'], $thumb_array['show_title'], $myclasshref, $myclassimg); } /***********************************************************************************/ /* Generate thumbnail and return array /* /* Parameters: /* URL : must be a valid URL. Text to link to thumbnail. /* ALTTEXT : text to show on mouseover /* ALTAPPEND : text to append to create thumbnail name. Overide default if exists. /* WIDTH : resize width. Overide default if greater than 0. /* HEIGHT : resize height. Overide default if greater than 0. /* HCROP : horizontal crop. Crop if greater than 0. /* VCROP : vertical crop. Crop if greater than 0. /* KEEPRATIO : if set to 1, image ratio is kept. Overide default if exists. /* BASENAME : force generation of thumbnail and use generic name. Default to 0. /* TEXTBOX : write post title at the bottom of the thumbnail if = 1. Default to 0. /* USECATNAME : will use a specific default image for each category if 1. Default to 0. /* /* Array: /* 'post_url' = post url (permalink) /* 'server_image' = absolute path to thumbnail /* 'image_location' = thumbnail url /* 'alt_text' = post title /* 'post_ID' = post ID /* 'the_image' = image url /* 'show_title' = SHOWTITLE result (html code string) /* /***********************************************************************************/ function tb_post_thumb_array ($arg='') { global $post; $settings = get_option('post_thumbnail_settings'); parse_str($arg, $new_args); $new_args = array_change_key_case($new_args, CASE_UPPER); if (isset($new_args['URL'])) $post_url = $new_args['URL']; else $post_url =''; if (isset($new_args['ALTTEXT'])) $alt_text = str_clean ($new_args['ALTTEXT']); else $alt_text =''; if (isset($new_args['ALTAPPEND'])) $alt_append = $new_args['ALTAPPEND']; else $alt_append =''; if ($alt_append != '') $settings['append_text'] = $alt_append; if (isset($new_args['WIDTH'])) $resize_width = $new_args['WIDTH']; else $resize_width = 0; if ($resize_width > 0) $settings['resize_width'] = $resize_width; if (isset($new_args['HEIGHT'])) $resize_height = $new_args['HEIGHT']; else $resize_height = 0; if ($resize_height > 0) $settings['resize_height'] = $resize_height; if (isset($new_args['HCROP'])) $crop_x = $new_args['HCROP']; else $crop_x = 0; if (isset($new_args['VCROP'])) $crop_y = $new_args['VCROP']; else $crop_y = 0; if (isset($new_args['KEEPRATIO'])) { if ($new_args['KEEPRATIO']==1) $keep_ratio = true; else $keep_ratio = false; $settings['keep_ratio'] = $keep_ratio; } else $keep_ratio = $settings['keep_ratio']; if (isset($new_args['USECATNAME'])) { if ($new_args['USECATNAME']==1) $use_catname = true; else $use_catname = false; $settings['use_catname'] = $use_catname; } else { if ($settings['use_catname']=='true') $use_catname = true; else $use_catname = false; } if (isset($new_args['BASENAME'])) { if ($new_args['BASENAME']==1) $base_name = true; else $base_name = false;} else $base_name = false; if (isset($new_args['SHOWTITLE'])) $show_title = tb_return_title($new_args['SHOWTITLE']); else $show_title = ''; if (isset($new_args['TEXTBOX'])) { if ($new_args['TEXTBOX']==1) $textBox = true; else $textBox = false;} else $textBox = false; define('POSTTHUMB_URLPATH', str_replace($settings['full_domain_name'], '/',get_settings('siteurl')).'/wp-content/plugins/' . dirname(plugin_basename(__FILE__)).'/'); // finds an image from the post content if (preg_match('/post_content,$matches)) { // put matches into recognizable vars $the_image = tb_thumb_absolute($matches[2]); // detects if an image is already linked to a thumbnail $pattern = '/(.*?)/i'; if (preg_match($pattern,$post->post_content,$matches)) $the_image = tb_thumb_absolute($matches[2].'.'.$matches[3]); $the_image_server = str_replace($settings['full_domain_name'], $settings['base_path'], $the_image); // check if image exists on server // if doesn't exist, can't do anything so return default image if (!remote_file_exists($the_image_server)) { $thumb_array = return_default_image ($post_url, $alttext, $settings, $post->ID, $use_catname); } $dest_path = pathinfo($the_image_server); if ($base_name) $dest_path_temp['basename'] = 'azerty123456789'.'.'.$dest_path['extension']; else $dest_path_temp['basename'] = $dest_path['basename']; // dir to save thumbnail to $save_dir = $settings['base_path'].'/'.$settings['folder_name']; // name to save to - Adds append text if ($settings['append'] == 'true') { $filename = substr($dest_path_temp['basename'], 0, strrpos($dest_path_temp['basename'], ".")); $rename_to = $filename.$settings['append_text'].'.'.$dest_path['extension']; } else $rename_to = $settings['append_text'].$dest_path_temp['basename']; // checks if file already exists - returns location if it does if (remote_file_exists($save_dir.'/'.$rename_to) && (!$base_name)) { $imagelocation = $settings['full_domain_name'].'/'.$settings['folder_name'].'/'.$rename_to; $thumb_array['post_url'] = $post_url; $thumb_array['server_image'] = $save_dir.'/'.$rename_to; $thumb_array['image_location'] = $imagelocation; $thumb_array['alt_text'] = $alt_text; $thumb_array['post_ID'] = $post->ID; $thumb_array['the_image'] = $the_image; $thumb_array['show_title'] = $show_title; } else { // if file has to be generated, generates thumbnails $thumb = new ImageEditor($dest_path['basename'],$dest_path['dirname'].'/'); $thumb->resize($settings['resize_width'], $settings['resize_height'], $crop_x, $crop_y, $settings['keep_ratio']); // Adds text box if option is checked if ($textBox) $thumb->AddBox (true, 0, 0, 0, 15, $post->post_title, 255, 255, 255, 15); $thumb->outputFile($save_dir."/".$rename_to, ""); $imagelocation = $settings['full_domain_name']."/".$settings['folder_name']."/".$rename_to; $thumb_array['post_url'] = $post_url; $thumb_array['server_image'] = $save_dir.'/'.$rename_to; $thumb_array['image_location'] = $imagelocation; $thumb_array['alt_text'] = $alt_text; $thumb_array['post_ID'] = $post->ID; $thumb_array['the_image'] = $the_image; $thumb_array['show_title'] = $show_title; } } // If no image found in the post content - checks for video else { if (!empty($settings['video_regex']) && tb_post_thumb_check_video($settings['video_regex'])) { $settings['default_image'] = $settings['video_default']; } if ($settings['stream_check']) { $settings['default_image'] = tb_post_thumb_check_stream($settings['default_image']); } $thumb_array = return_default_image ($post_url, $alt_text, $settings, $post->ID, $show_title, $use_catname); } return $thumb_array; } /***********************************************************************************/ /* Generate thumbnail and return array /* /* Parameters: /* URL : must be a valid URL. Text to link to thumbnail. /* ALTTEXT : text to show on mouseover /* ALTAPPEND : text to append to create thumbnail name. Overide default if exists. /* WIDTH : resize width. Overide default if greater than 0. /* HEIGHT : resize height. Overide default if greater than 0. /* HCROP : horizontal crop. Crop if greater than 0. /* VCROP : vertical crop. Crop if greater than 0. /* KEEPRATIO : if set to 1, image ratio is kept. Overide default if exists. /* BASENAME : force generation of thumbnail and use generic name. Default to 0. /* TEXTBOX : write post title at the bottom of the thumbnail if = 1. Default to 0. /* USECATNAME : will use a specific default image for each category if 1. Default to 0. /* /* Array: /* 'post_url' = post url (permalink) /* 'server_image' = absolute path to thumbnail /* 'image_location' = thumbnail url /* 'alt_text' = post title /* 'post_ID' = post ID /* 'the_image' = image url /* 'show_title' = SHOWTITLE result (html code string) /* /***********************************************************************************/ function tb_image_thumb_array ($arg='') { $settings = get_option('post_thumbnail_settings'); parse_str($arg, $new_args); $new_args = array_change_key_case($new_args, CASE_UPPER); if (isset($new_args['IMG'])) $img_url = $new_args['IMG']; else $img_url =''; if (isset($new_args['URL'])) $post_url = $new_args['URL']; else $post_url =''; if (isset($new_args['ALTTEXT'])) $alt_text = str_clean ($new_args['ALTTEXT']); else $alt_text =''; if (isset($new_args['ALTAPPEND'])) $alt_append = $new_args['ALTAPPEND']; else $alt_append =''; if ($alt_append != '') $settings['append_text'] = $alt_append; if (isset($new_args['WIDTH'])) $resize_width = $new_args['WIDTH']; else $resize_width = 0; if ($resize_width > 0) $settings['resize_width'] = $resize_width; if (isset($new_args['HEIGHT'])) $resize_height = $new_args['HEIGHT']; else $resize_height = 0; if ($resize_height > 0) $settings['resize_height'] = $resize_height; if (isset($new_args['HCROP'])) $crop_x = $new_args['HCROP']; else $crop_x = 0; if (isset($new_args['VCROP'])) $crop_y = $new_args['VCROP']; else $crop_y = 0; if (isset($new_args['KEEPRATIO'])) { if ($new_args['KEEPRATIO']==1) $keep_ratio = true; else $keep_ratio = false; $settings['keep_ratio'] = $keep_ratio; } else $keep_ratio = $settings['keep_ratio']; if (isset($new_args['USECATNAME'])) { if ($new_args['USECATNAME']==1) $use_catname = true; else $use_catname = false; $settings['use_catname'] = $use_catname; } else { if ($settings['use_catname']=='true') $use_catname = true; else $use_catname = false; } if (isset($new_args['BASENAME'])) { if ($new_args['BASENAME']==1) $base_name = true; else $base_name = false;} else $base_name = false; if (isset($new_args['SHOWTITLE'])) $show_title = tb_return_title($new_args['SHOWTITLE']); else $show_title = ''; if (isset($new_args['TEXT'])) $text = $new_args['TEXT']; else $text = ''; if (isset($new_args['TEXTBOX'])) { if ($new_args['TEXTBOX']==1) $textBox = true; else $textBox = false;} else $textBox = false; define('POSTTHUMB_URLPATH', str_replace($settings['full_domain_name'], '/',get_settings('siteurl')).'/wp-content/plugins/' . dirname(plugin_basename(__FILE__)).'/'); // put matches into recognizable vars $the_image = $img_url; $the_image_server = str_replace($settings['full_domain_name'], $settings['base_path'], $the_image); // check if image exists on server // if doesn't exist, can't do anything so return default image if (!remote_file_exists($the_image_server)) { $thumb_array = return_default_image ($post_url, $alttext, $settings, $post->ID, $use_catname); } $dest_path = pathinfo($the_image_server); if ($base_name) $dest_path_temp['basename'] = 'azerty123456789'.'.'.$dest_path['extension']; else $dest_path_temp['basename'] = $dest_path['basename']; // dir to save thumbnail to $save_dir = $settings['base_path'].'/'.$settings['folder_name']; // name to save to - Adds append text if ($settings['append'] == 'true') { $filename = substr($dest_path_temp['basename'], 0, strrpos($dest_path_temp['basename'], ".")); $rename_to = $filename.$settings['append_text'].'.'.$dest_path['extension']; } else $rename_to = $settings['append_text'].$dest_path_temp['basename']; // checks if file already exists - returns location if it does if (remote_file_exists($save_dir.'/'.$rename_to) && (!$base_name)) { $imagelocation = $settings['full_domain_name'].'/'.$settings['folder_name'].'/'.$rename_to; $thumb_array['post_url'] = $post_url; $thumb_array['server_image'] = $save_dir.'/'.$rename_to; $thumb_array['image_location'] = $imagelocation; $thumb_array['alt_text'] = $alt_text; $thumb_array['post_ID'] = $post->ID; $thumb_array['the_image'] = $the_image; $thumb_array['show_title'] = $show_title; } else { // if file has to be generated, generates thumbnails $thumb = new ImageEditor($dest_path['basename'],$dest_path['dirname'].'/'); $thumb->resize($settings['resize_width'], $settings['resize_height'], $crop_x, $crop_y, $settings['keep_ratio']); // Adds text box if option is checked if ($textBox) $thumb->AddBox (true, 0, 0, 0, 15, $text, 255, 255, 255, 15); $thumb->outputFile($save_dir."/".$rename_to, ""); $imagelocation = $settings['full_domain_name']."/".$settings['folder_name']."/".$rename_to; $thumb_array['post_url'] = $post_url; $thumb_array['server_image'] = $save_dir.'/'.$rename_to; $thumb_array['image_location'] = $imagelocation; $thumb_array['alt_text'] = $alt_text; $thumb_array['post_ID'] = $post->ID; $thumb_array['the_image'] = $the_image; $thumb_array['show_title'] = $show_title; } return $thumb_array; } /*========================================================================================================*/ /* Utility functions /*========================================================================================================*/ /***********************************************************************************/ /* Test if image in content /* $img_only = true : return true if an image is found in the current post /* $img_only = false : return true if an image or a video is found in the current post /***********************************************************************************/ function tb_content_test($img_only=false, $content='') { $settings = get_option('post_thumbnail_settings'); // find an image from the post content if (preg_match('/'.$show_title.''; } // return the html code if ($post_url=='') return $a.'href="#">'.$img.'src="'.$site_image.'" '.$attr.' alt="'.$alt_text.'" />'; else return $a.'href="'.$post_url.'" title="'.$alt_text.'">'.$img.'src="'.$site_image.'" alt="'.$alt_text.'" />'.$slasha; } /****************************************************************/ /* Return LB_effect for current post /****************************************************************/ function pt_LB_effect ($arg='', $hs_function='hs_link', $hs_style='beveled', $hs_width=700, $hs_height=500) { global $post; $html_body = $post->post_content; $post_link = get_thumb_array ($arg); echo $post_link; echo LB_effect ($hs_function, $hs_style, $hs_width, $hs_height, $post_link, $html_body); } /****************************************************************/ /* Return html string including effect depending on gb_function /****************************************************************/ function LB_effect ($hs_function='hs_html', $style='rounded-white', $width='700', $height='500', $arg_array, $html_content='', $tag='') { $post_url = $arg_array['post_url']; $site_image = $arg_array['image_location']; $alt_text = $arg_array['alt_text']; $id_ID = $arg_array['post_ID'].$tag; $show_title = $arg_array['show_title']; $html_body = __($html_content); $img_url = $arg_array['the_image']; $title = $arg_array['alt_text']; $position = "align: 'center'"; $outlineType = "outlineType: '".$style."'"; if ($show_title == '') $slasha = ''; else { $slasha = '
    '.$show_title.''; } return pt_get_effect ($hs_function, $style, $post_url, $width, $height, $id_ID, $alt_text, $site_image, $img_url, $slasha, $html_body, '', $title); } /****************************************************************/ /* Check if there is a video in content using REGEX /****************************************************************/ function tb_content_check_video($regex, $content) { if (preg_match('/'.$regex.'/i',$content,$matches)) return true; else return false; } /****************************************************************/ /* Check if there is a video in post using REGEX /****************************************************************/ function tb_post_thumb_check_video($regex) { global $post; return tb_content_check_video($regex, $post->post_content); } /****************************************************************/ /* Check if there is a video stream in content using pre-formatted strings /****************************************************************/ function tb_content_test_stream($content) { if (!(strpos($content, 'http://www.youtube.com/watch') === false)) { return true; } if (!(strpos($content, 'http://www.dailymotion.com/swf') === false)) { return true; } if (!(strpos($content, 'http://video.google.fr/videoplay') === false)) { return true; } if (!(strpos($content, 'http://video.google.com/videoplay') === false)) { return true; } return false; } /****************************************************************/ /* Check if there is a video stream in post using pre-formatted strings /****************************************************************/ function tb_post_thumb_test_stream() { global $post; return tb_content_test_stream($post->post_content); } /****************************************************************/ /* Returns adhoc thumbnail for videostream /****************************************************************/ function tb_post_thumb_check_stream($default_img) { global $post; $def_img = $default_img ; if (!(strpos($post->post_content, 'http://www.youtube.com/watch') === false)) { $def_img = POSTTHUMB_URLPATH.'images/youtube.png'; } if (!(strpos(strtoupper($post->post_content), '[YOUTUBE=(') === false)) { $def_img = POSTTHUMB_URLPATH.'images/youtube.png'; } if (!(strpos(strtoupper($post->post_content), '[DAILYMOTION=(') === false)) { $def_img = POSTTHUMB_URLPATH.'/images/dailymotion.png'; } if (!(strpos($post->post_content, 'http://www.dailymotion.com/swf') === false)) { $def_img = POSTTHUMB_URLPATH.'/images/dailymotion.png'; } if (!(strpos($post->post_content, 'http://video.google.fr/videoplay') === false)) { $def_img = POSTTHUMB_URLPATH.'/images/gvideo.png'; } if (!(strpos($post->post_content, 'http://video.google.com/videoplay') === false)) { $def_img = POSTTHUMB_URLPATH.'/images/gvideo.png'; } return $def_img; } /**************************************************************** * Test if remote image exists * @param url to test * @return true if file exists ****************************************************************/ function remote_file_exists ($url) { $url_fopen_is_allowed = ini_set('allow_url_fopen', '1'); if (($url_fopen_is_allowed === false) && (allow_url_open != true)) return file_exists($url); if (allow_url_fopen == true) if (@fclose(@fopen($url, 'r'))) {return true;} else {return false;} else {return @file_exists($url);} } /****************************************************************/ /* Test if remote image exists /****************************************************************/ function remote_file_exists2 ($url) { $file_exists = @file_exists($url); if ($file_exists) return true; else // file_exists not working on remote url { //check if allow_url_fopen is enabled $url_fopen_is_allowed = ini_set('allow_url_fopen', '1'); if (($url_fopen_is_allowed === false) && (ALLOW_URL_OPEN != true)) return @file_exists($url); // If enabled, check remote url if (ALLOW_URL_FOPEN == true) { $imgfile = @fopen($url, 'r'); if ($imgfile) { @close($imgfile); return true; } else { return false; } } else // If not, probably return false^^ { return @file_exists($url); } } } /****************************************************************/ /* Get random post /****************************************************************/ function random_post ($limit) { global $wpdb, $wp_version, $tableposts; if ($wp_version < '2.1') $post_type_sql = "AND post_status = 'publish'"; else $post_type_sql = "AND post_status = 'publish' AND post_type = 'post'"; $order_by_sql = "rand()"; // query records that contain img tags, ordered randomly // do not select images from password protected posts $sql = "SELECT $wpdb->posts.ID, $wpdb->posts.post_title, $wpdb->posts.post_content, $wpdb->posts.post_date, $wpdb->posts.post_author FROM $wpdb->posts WHERE post_password = '' $post_type_sql ORDER BY $order_by_sql LIMIT $limit"; return $wpdb->get_results($sql); } /****************************************************************/ /* Return absolute path /****************************************************************/ function tb_thumb_absolute ($the_image) { $test_img = parse_url($the_image); if (empty($test_img['scheme'])) $the_img = canonicalize(str_replace( "\\", "/",get_settings('siteurl').str_replace( "//", "/",'/../'.$the_image))); else $the_img = canonicalize($the_image); return $the_img; } /****************************************************************/ /* retourne un chemin canonique a partir d'un chemin contenant des ../ /****************************************************************/ function canonicalize($address) { $address = explode('/', $address); $keys = array_keys($address, '..'); foreach($keys AS $keypos => $key) { array_splice($address, $key - ($keypos * 2 + 1), 2); } $address = implode('/', $address); $address = str_replace('./', '', $address); return $address; } /****************************************************************/ /* Return default image /****************************************************************/ function return_default_image ($post_url, $alt_text, $settings, $post_ID, $show_title='', $use_catname=false) { if ($use_catname) { if (get_bloginfo('version')>='2.1') $myposts = wp_get_post_categories($post_ID); else $myposts = wp_get_post_cats('1', $post_ID); $array_def = pathinfo($settings['default_image']); $filename = substr($array_def['basename'], 0, strrpos($array_def['basename'], ".")); $i=0; foreach ($myposts as $mypost) { $new_def = $array_def['dirname'].'/'.$filename.'cat-'.$mypost.'.'.$array_def['extension']; if (remote_file_exists($settings['full_domain_name']."/".$new_def)) { $settings['default_image']=$new_def; break; } } } $default_array['post_url'] = $post_url; $default_array['server_image'] = $settings['base_path']."/".$settings['default_image']; $default_array['image_location'] = $settings['full_domain_name']."/".$settings['default_image']; $default_array['alt_text'] = $alt_text; $default_array['generate'] = true; $default_array['post_ID'] = $post_ID; $default_array['the_image'] = $post_url; $default_array['show_title'] = $show_title; return $default_array; } /****************************************************************/ /* Add post-thumb option /****************************************************************/ function tb_post_thumb_options() { if (function_exists('add_options_page')) { add_options_page('Post Thumbnails', 'Post Thumbs', 8, basename(__FILE__), 'tb_post_thumb_options_subpanel'); } } /****************************************************************/ /* Add post-thumb option /****************************************************************/ function tb_return_title ($showtitle='') { global $post; $arg = strtoupper($showtitle); $ret = ''; $sep = ', '; while ($arg <>'') : if (strlen($arg)==1) $sep = ''; $test = substr($arg, 0, 1); switch ($test) { case 'A': $ret .= get_author_name($post->post_author).$sep; break; case 'D': $ret .= substr($post->post_date, 0, 10).$sep; break; case 'T': $ret .= $post->post_title.$sep; break; } $arg = substr($arg, 1); endwhile; return $ret; } /****************************************************************/ /* Return a string cleaned of annoying '\' /****************************************************************/ function str_clean ($item) { return str_replace(array("\`", "\'", '\"'), array("`", "'", '"'), $item); } /****************************************************************/ /* Test if a path is writable /****************************************************************/ function test_folder_name ($is_writable_dir) { $rs = ABSPATH.'/wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/index.htm'; $rt = $is_writable_dir.'/index.htm'; if (is_dir($is_writable_dir)) { if (@copy($rs, $rt)===false) { $iswritable['error_writable'] = false; $iswritable['error_msg'] = __('Directory: ', 'post-thumb').$is_writable_dir.' '.__('may not be writeable.', 'post-thumb'); } else { unlink($rt); $iswritable['error_writable'] = true; $iswritable['error_msg'] = ''; } } else { $iswritable['error_writable'] = false; $iswritable['error_msg'] = __('Directory: ', 'post-thumb').$is_writable_dir.' '.__('does not exist!', 'post-thumb'); } return $iswritable; } /****************************************************************/ /* Validates update options /****************************************************************/ function pt_validate_options($new_options) { $update_error=''; // Test resize values if (!is_numeric($new_options['resize_width'])) { $update_error = __("Resize width must be a number"); $new_options['resize_width'] = '60'; } else if (!is_numeric($new_options['resize_height'])) { $update_error = __("Resize height must be a number"); $new_options['resize_height'] = '60'; } // Test default image $video_exists = file_exists($new_options['base_path'].'/'.$new_options['video_default']); if (!$video_exists) $update_error = __('Video default image not found on server.', 'post-thumb'); // Test default image $default_exists = file_exists($new_options['base_path'].'/'.$new_options['default_image']); if (!$default_exists) $update_error = __('Default image not found on server.', 'post-thumb'); // Test folder name $writable = test_folder_name($new_options['base_path'].'/'.$new_options['folder_name']); if (!$writable['error_writable']) $update_error = $writable['error_msg']; return $update_error; } ?>