ptObject = $ptObject; unset($ptObject); $this->settings = $this->ptObject->settings; // add WP actions - not limited to is_admin() to be applied also in case of xmlrpc posts by external blogging application add_action('publish_post', array(&$this, 'savePostImage')); add_action('edit_post', array(&$this, 'savePostImage')); add_action('save_post', array(&$this, 'savePostImage')); add_action('wp_insert_post', array(&$this, 'savePostImage')); add_action('delete_post', array(&$this, 'deletePostImage')); // add option screen menu if (is_admin()) { add_action('admin_menu', array(&$this, 'pt_options')); // check if we need to upgrade if ( $this->settings['version'] < $this->PTRVERSION ) { // Execute installation $this->pt_install(); // Update version number in the options $this->settings['version'] = $this->PTRVERSION; // $this->UpdateOptions(); } } } /****************************************************************/ /* Add post-thumb option /****************************************************************/ function pt_options() { if (function_exists('add_options_page')) add_options_page('Post Thumb Revisited', 'Post Thumb', 8, basename(__FILE__), array(&$this, 'pt_MenuOptions')); } /****************************************************************/ /****************************************************************/ function pt_install() { global $wpdb; /* create tags table if it doesn't exist */ $tablename = $this->ptObject->table_pt_post; $found = false; foreach ($wpdb->get_results("SHOW TABLES;", ARRAY_N) as $row) { if ($row[0] == $tablename) { $found = true; break; } } if ($found && $this->settings['version'] < '2.1.4') { $res = $wpdb->query(" DROP TABLE ".$tablename); $found = false; } if (!$found) { $res = $wpdb->get_results("CREATE TABLE $tablename " . $this->tablestruct); $ptr2_options = pt_get_default_options(); $ptr2_options['version'] = $this->PTRVERSION; update_option('post_thumbnail_settings', $ptr2_options); $count_posts = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->posts); $this->UpdatePostDB(0, $count_posts); } } /****************************************************************/ /* Creates all record in DB /****************************************************************/ function UpdatePostDB($llimit, $hlimit) { global $wpdb; echo '

'.__('Posts: ', 'post-thumb').$llimit.' - '.$hlimit.' '.__('updated', 'post-thumb').'

'; $lines = $hlimit-$llimit; $dbresults = $wpdb->get_results(" SELECT * FROM ".$wpdb->posts." LIMIT ".$llimit.",".$lines); foreach ($dbresults as $dbresult) : // Saves post data $this->StorePostData($dbresult); endforeach; unset($dbresults); } /****************************************************************/ /* save new list of post tags to database /****************************************************************/ function savePostImage($id) { // authorization if ( !current_user_can('edit_post', $id) ) return $id; // clear old values first $this->deletePostImage($id); // Retrieve post content as list $post = &get_post($id); // skip drafts if ( !($post->post_status == 'publish' OR $post->post_status == 'static')) return $id; // Saves post data $this->StorePostData($post); } /*******************************************************************************/ /* Deletes a post record /*******************************************************************************/ function GetMetacontent($id) { // finds an attachement to the post if ($this->settings['use_meta'] == 'true') $metaContent = get_post_meta($id, 'pt_meta_thumb', true); else $metaContent = ''; return $metaContent; } /*******************************************************************************/ /* Deletes a post record /*******************************************************************************/ function StorePostData($post) { global $wpdb; $p = new postThumb($post); $metaContent = $this->GetMetacontent($p->post_id); if ($meta_content != '') $p->image = tb_thumb_absolute($meta_content); // finds an image from the post content elseif (preg_match('//i', $post->post_content, $matches)) { // put matches into recognizable vars $p->image = tb_thumb_absolute($matches[2]); // detects if the image is already linked to a thumbnail $img_src = str_replace('/', '\/', $matches[2]); $pattern = '/(.*?)/i'; if (preg_match($pattern,$post->post_content,$matches)) $p->image = tb_thumb_absolute($matches[2].'.'.$matches[3]); } // Search for wordTube MEDIA. Hope it won't change after that. Needs to be refreshed if it does. if ($this->settings['hs_wordtube'] == 'true') { $pattern = '/\[MEDIA=([0-9]+%?)\]/i'; if (preg_match($pattern, $post->post_content, $match)) { $media = $wpdb->get_row("SELECT * FROM $wpdb->wordtube WHERE vid = $match[1] "); $p->image = $media->image; $p->media = $media->file; } } // Search for Youtube video. if ($this->settings['hs_youtube'] == 'true') { $pattern1 = '/\[youtube=\((.*?)\)(.*?)\]/i'; $pattern2 = '/\/i'; $pattern3 = '/\(.*?)\<\/object>/i'; if (preg_match($pattern1, $post->post_content, $match)) { $p->image = 'http://img.youtube.com/vi/'.$match[1].'/0.jpg'; $p->media = $match[1]; } elseif (preg_match($pattern2, $post->post_content, $match)) { $p->image = 'http://img.youtube.com/vi/'.$match[2].'/0.jpg'; $p->media = $match[2]; } elseif (preg_match($pattern3, $post->post_content, $match)) { $p->image = 'http://img.youtube.com/vi/'.$match[2].'/0.jpg'; $p->media = $match[2]; } } if ($p->image != '') { // Retrieve categories. Again, this needs to be refreshed if categories change. $p->categories = $this->retrieveCategories($p->post_id); $this->savePost($p); } unset ($p); } /*******************************************************************************/ /* Deletes a post record /*******************************************************************************/ function deletePostImage($postid) { global $wpdb; if ( is_numeric($postid) || $postid > 0 ) { $wpdb->query("DELETE FROM {$this->ptObject->table_pt_post} WHERE post_id='$postid'"); return true; } else { return false; } } /*******************************************************************************/ /* Saves a post with its image /*******************************************************************************/ function retrieveCategories($postid) { $catList = array(); $categories = get_the_category($postid); foreach ($categories as $cat) : $catList[] = $cat->cat_ID; endforeach; $SerCatList = serialize($catList); return $SerCatList; } /*******************************************************************************/ /* Saves a post with its image /*******************************************************************************/ function savePost($p) { global $wpdb; $p_array = Array(); $p_array['image_url'] = $p->image; $p_array['media_url'] = $p->media; $p_array['categories'] = $p->categories; $p_array['title'] = $p->title; $p_array['date'] = $p->date; $p_array['permalink'] = $p->permalink; $p_array['author'] = $p->author; $pObject = addslashes(serialize($p_array)); $wpdb->query(" INSERT IGNORE INTO {$this->ptObject->table_pt_post} ($this->tablequery) VALUES ( '$p->post_id', '$pObject' )"); } /*******************************************************************************/ /* Option panel /*******************************************************************************/ function pt_MenuOptions() { global $wpdb; // Init parameters $count_posts = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->posts); if ($count_posts < 20) $post_slice = 20; else $post_slice = ceil($count_posts/100)*10; $max_count = ceil($count_posts/$post_slice); $su = SITEURL; $up = UPLOAD_PATH; $pa = parse_url($su); $dn = str_replace($pa['path'],"",$su); $bp = str_replace($pa['path'],"",str_replace( "\\", "/",ABSPATH)); $bp = substr($bp, 0, strlen($bp)-1); $pa['path'] = substr($pa['path'], 1, strlen($pa['path'])-1); // Detects wordTube $se = get_option('wordtube_options'); if ($se == '') { $re=''; $wdet=''; } else { $re = "MEDIA="; $wdet='Wordtube detected'; } $this->pt_admin_include_header(); $new_options = pt_get_default_options(); if (isset($_POST['info_update'])) { $_POST['use_meta'] = pt_GetBooleanOption ($_POST['use_meta']); $_POST['use_catname'] = pt_GetBooleanOption ($_POST['use_catname']); $_POST['stream_check'] = pt_GetBooleanOption ($_POST['stream_check']); $_POST['rounded'] = pt_GetBooleanOption ($_POST['rounded']); $_POST['use_png'] = pt_GetBooleanOption ($_POST['use_png']); $_POST['append'] = pt_GetBooleanOption ($_POST['append']); $_POST['keep_ratio'] = pt_GetBooleanOption ($_POST['keep_ratio']); $_POST['caption'] = pt_GetBooleanOption ($_POST['caption']); $_POST['unsharp'] = pt_GetBooleanOption ($_POST['unsharp']); $_POST['tb_use'] = pt_GetBooleanOption ($_POST['tb_use']); $_POST['hs_use'] = pt_GetBooleanOption ($_POST['hs_use']); $_POST['hs_post'] = pt_GetBooleanOption ($_POST['hs_post']); $_POST['hs_wordtube'] = pt_GetBooleanOption ($_POST['hs_wordtube']); $_POST['wt_media'] = pt_GetBooleanOption ($_POST['wt_media']); $_POST['wt_playlist'] = pt_GetBooleanOption ($_POST['wt_playlist']); $_POST['wt_append'] = pt_GetBooleanOption ($_POST['append']); $_POST['yt_append'] = pt_GetBooleanOption ($_POST['append']); $_POST['hs_youtube'] = pt_GetBooleanOption ($_POST['hs_youtube']); $_POST['pt_replace'] = pt_GetBooleanOption ($_POST['pt_replace']); $_POST['p_rounded'] = pt_GetBooleanOption ($_POST['p_rounded']); $_POST['p_keep_ratio'] = pt_GetBooleanOption ($_POST['p_keep_ratio']); $_POST['p_use_png'] = pt_GetBooleanOption ($_POST['p_use_png']); $_POST['p_unsharp'] = pt_GetBooleanOption ($_POST['p_unsharp']); $_POST['p_caption'] = pt_GetBooleanOption ($_POST['p_caption']); for ($i=1;$i<=$max_count;$i++) : $_POST['db_refresh'.$i] = pt_GetBooleanOption ($_POST['db_refresh'.$i]); $llimit = ($i-1)*$post_slice; if ($i==$max_count) $hlimit = $count_posts; else $hlimit = $i*$post_slice; if ($_POST['db_refresh'.$i] == 'true') { // echo 'TTTT'.$llimit.'RR'.$hlimit; $lines = $hlimit-$llimit; $array_posts = $wpdb->get_col(" SELECT ID FROM ".$wpdb->posts." LIMIT ".$llimit.",".$lines); $array_posts = '( '.implode(',', $array_posts).' )'; // print_r($array_posts); $wpdb->query(" DELETE FROM ".$this->ptObject->table_pt_post." WHERE post_id IN ".$array_posts); $this->UpdatePostDB($llimit, $hlimit); } endfor; if (get_magic_quotes_gpc()) $_POST['video_regex'] = stripslashes($_POST['video_regex']); if (ini_get('safe_mode')) $safe_mode = 'true'; else $safe_mode = 'false'; $new_options = array( 'version' => $this->PTRVERSION, 'default_image' => $_POST['default_image'], 'full_domain_name' => $_POST['full_domain_name'], 'base_path' => $_POST['base_path'], 'folder_name' => $_POST['folder_name'], 'rounded' => $_POST['rounded'], 'append' => $_POST['append'], 'use_meta' => $_POST['use_meta'], 'use_png' => $_POST['use_png'], 'append_text' => $_POST['append_text'], 'resize_width' => $_POST['resize_width'], 'resize_height' => $_POST['resize_height'], 'keep_ratio' => $_POST['keep_ratio'], 'caption' => $_POST['caption'], 'phpversion' => phpversion(), 'tb_use' => $_POST['tb_use'], 'hs_use' => $_POST['hs_use'], 'hs_post' => $_POST['hs_post'], 'hs_wordtube' => $_POST['hs_wordtube'], 'wt_media' => $_POST['wt_media'], 'wt_playlist' => $_POST['wt_playlist'], 'wordtube_width' => $_POST['wordtube_width'], 'wordtube_height' => $_POST['wordtube_height'], 'wordtube_pwidth' => $_POST['wordtube_pwidth'], 'wordtube_pheight' => $_POST['wordtube_pheight'], 'wordtube_text' => $_POST['wordtube_text'], 'wordtube_vtext' => $_POST['wordtube_vtext'], 'wordtube_mtext' => $_POST['wordtube_mtext'], 'hs_youtube' => $_POST['hs_youtube'], 'ovframe' => $_POST['ovframe'], 'hsframe' => $_POST['hsframe'], 'unsharp' => $_POST['unsharp'], 'unsharp_amount' => $_POST['unsharp_amount'], 'unsharp_radius' => $_POST['unsharp_radius'], 'unsharp_threshold' => $_POST['unsharp_threshold'], 'corner_ratio' => $_POST['corner_ratio'], 'youtube_width' => $_POST['youtube_width'], 'youtube_height' => $_POST['youtube_height'], 'youtube_pwidth' => $_POST['youtube_pwidth'], 'youtube_pheight' => $_POST['youtube_pheight'], 'jpg_rate' => $_POST['jpg_rate'], 'png_rate' => $_POST['png_rate'], 'use_catname' => $_POST['use_catname'], 'stream_check' => $_POST['stream_check'], 'video_regex' => $_POST['video_regex'], 'video_default' => $_POST['video_default'], 'bgcolor' => $_POST['bgcolor'], 'pt_replace' => $_POST['pt_replace'], 'p_rounded' => $_POST['p_rounded'], 'p_append_text' => $_POST['p_append_text'], 'p_use_png' => $_POST['p_use_png'], 'p_resize_width' => $_POST['p_width'], 'p_resize_height' => $_POST['p_height'], 'p_keep_ratio' => $_POST['p_keep_ratio'], 'p_caption' => $_POST['p_caption'], 'p_unsharp' => $_POST['p_unsharp'], 'safe_mode' => $safe_mode ); update_option('post_thumbnail_settings',$new_options); } // Validates options & displays error message $this->pt_ValidateOptions($new_options); ?>
update_error) : ?> error_msg; ?>
get_var("SELECT COUNT(*) FROM ".$this->ptObject->table_pt_post); $post_thumbnail_settings = pt_get_default_options('post_thumbnail_settings'); update_option('post_thumbnail_settings',$post_thumbnail_settings); ?>

ptr_version_check()) { ?>

PTRVERSION; ?>


   



 '.$llimit.'-'.$hlimit.' '; endfor; ?>















/>

/>






/>



/>

x
getSliderValue ($post_thumbnail_settings['jpg_rate'] * (2 - 16 / 100), '.slider1'); ?>


=')) { ?> getSliderValue ($post_thumbnail_settings['png_rate'] * (200/9 - 16 / 9), '.slider2'); ?>


/>


/>      

/>


/>





/>

/>

/>




/>

/>

/>

/>

x

x




/>

/>

x

x

/>

x



/>

/>

/>

/>

/>

isError(__("Resize width must be a number")); $new_options['resize_width'] = '60'; } elseif (!is_numeric($new_options['resize_height'])) { $this->isError(__("Resize width 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) $this->isError(__('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) $this->isError(__('Default image not found on server.', 'post-thumb')); // Test folder name $this->TestFolder($new_options['base_path'].'/'.$new_options['folder_name']); } /****************************************************************/ /* Test if a path is writable /****************************************************************/ function isError ($text) { $this->update_error = true; $this->error_msg = $text; } /****************************************************************/ /* Test if a path is writable /****************************************************************/ function TestFolder ($is_writable_dir) { $rs = PT_ABSPATH . 'lib/index.htm'; $rt = $is_writable_dir . '/index.htm'; if (is_dir($is_writable_dir)) { if (@copy($rs, $rt)===false) $this->isError(__('Directory: ', 'post-thumb').$is_writable_dir.' '.__('may not be writeable.', 'post-thumb')); else unlink($rt); } else $this->isError(__('Directory: ', 'post-thumb').$is_writable_dir.' '.__('does not exist!', 'post-thumb')); } /****************************************************************/ /* Includes features in header for admin panel /****************************************************************/ function pt_admin_include_header() { /* js includes ============================== */ ?> _fp_timeout = 10; if (@$client->fetch($this->PTRURL) === false) return false; $remote = $client->results; $server_version = $remote; if ( version_compare($server_version, $this->PTRVERSION, '>')) return true; // come back in 24 hours :-) $check_intervall = time() + 86400; update_option( "ptr_next_update", $check_intervall ); return false; } } return false; } } // End of admin class /****************************************************************/ /* Set checkbox result to boolean /****************************************************************/ function pt_GetBooleanOption($boolean) { if ($boolean == 'on') $boolean = 'true'; else $boolean = 'false'; return $boolean; } /****************************************************************/ /* Validates update options /****************************************************************/ function pt_get_default_options() { // Init parameters $su = SITEURL; $up = get_settings('upload_path'); $pa = parse_url(SITEURL); $dn = str_replace($pa['path'],"",SITEURL); $bp = str_replace($pa['path'],"",str_replace( "\\", "/",ABSPATH)); $bp = substr($bp, 0, strlen($bp)-1); $pa['path'] = substr($pa['path'], 1, strlen($pa['path'])-1); $def = $pa['path'].'/wp-content/plugins/'. PLUGIN_BASENAME.'/images/default.png'; $se = get_option('wordtube_options'); if ($se=='') { $re=''; $wdet=''; } else { $re = "MEDIA="; $wdet='Wordtube detected'; } $settings = get_option('post_thumbnail_settings'); if ($settings['append'] == '') $settings['append'] = 'false'; if ($settings['append_text'] == '') $settings['append_text'] = 'thumb_'; if ($settings['base_path'] == '') $settings['base_path'] = $bp; if ($settings['bgcolor'] == '') $settings['bgcolor'] = '#000000'; $settings['corner_ratio'] = ptr_test_setting($settings['corner_ratio'], '0.150', 1); // if ($settings['default_image'] == '') $settings['default_image'] = $pa['path'].'/'.$up.'/default.jpg'; if ($settings['default_image'] == '') $settings['default_image'] = $def; if ($settings['folder_name'] == '') $settings['folder_name'] = $pa['path'].'/'.$up.'/pth'; if ($settings['full_domain_name'] == '')$settings['full_domain_name'] = str_replace( "\\", "/",$dn); if ($settings['gdversion'] == '') $settings['gdversion'] = gd_version(true); if ($settings['tb_use'] == '') $settings['tb_use'] = 'false'; if ($settings['hs_use'] == '') $settings['hs_use'] = 'false'; if ($settings['caption'] == '') $settings['caption'] = 'false'; if ($settings['hsframe'] == '') $settings['hsframe'] = 'drop-shadow'; if ($settings['hs_post'] == '') $settings['hs_post'] = 'false'; if ($settings['hs_use'] == '') $settings['hs_use'] = 'true'; if ($settings['hs_wordtube'] == '') $settings['hs_wordtube'] = 'false'; if ($settings['hs_youtube'] == '') $settings['hs_youtube'] = 'false'; if ($settings['info_update'] == '') $settings['info_update'] = 'Create'; $settings['jpg_rate'] = ptr_test_setting($settings['jpg_rate'], '75', 100); if ($settings['keep_ratio'] == '') $settings['keep_ratio'] = 'true'; if ($settings['ovframe'] == '') $settings['ovframe'] = 'drop-shadow'; if ($settings['phpversion'] == '') $settings['phpversion'] = phpversion(); $settings['png_rate'] = ptr_test_setting($settings['png_rate'], '6', 9); $settings['resize_width'] = ptr_test_setting($settings['resize_width'], '60'); $settings['resize_height'] = ptr_test_setting($settings['resize_height'], '60'); if ($settings['rounded'] == '') $settings['rounded'] = 'false'; if ($settings['stream_check'] == '') $settings['stream_check'] = 'true'; if ($settings['unsharp'] == '') $settings['unsharp'] = 'false'; $settings['unsharp_amount'] = ptr_test_setting($settings['unsharp_amount'], '80', 100); $settings['unsharp_radius'] = ptr_test_setting($settings['unsharp_radius'], '0.5', 1); $settings['unsharp_threshold'] = ptr_test_setting($settings['unsharp_threshold'], '3', 5); if ($settings['use_catname'] == '') $settings['use_catname'] = 'false'; if ($settings['use_meta'] == '') $settings['use_meta'] = 'true'; if ($settings['use_png'] == '') $settings['use_png'] = 'false'; if ($settings['video_regex'] == '') $settings['video_regex'] = $re; if ($settings['video_default'] == '') $settings['video_default'] = $def; if ($settings['wordtube_text'] == '') $settings['wordtube_text'] = 'wtthumb_'; $settings['wordtube_width'] = ptr_test_setting($settings['wordtube_width'], '160'); $settings['wordtube_height'] = ptr_test_setting($settings['wordtube_height'], '120'); $settings['wordtube_pwidth'] = ptr_test_setting($settings['wordtube_pwidth'], '425'); $settings['wordtube_pheight'] = ptr_test_setting($settings['wordtube_pheight'], '350'); $settings['youtube_width'] = ptr_test_setting($settings['youtube_width'], '160'); $settings['youtube_height'] = ptr_test_setting($settings['youtube_height'], '120'); $settings['youtube_pwidth'] = ptr_test_setting($settings['youtube_pwidth'], '425'); $settings['youtube_pheight'] = ptr_test_setting($settings['youtube_pheight'], '350'); if ($settings['pt_replace'] == '') $settings['pt_replace'] = 'false'; if ($settings['p_append_text'] == '') $settings['p_append_text'] = 'pthumb_'; if ($settings['p_keep_ratio'] == '') $settings['p_keep_ratio'] = 'true'; $settings['p_resize_width'] = ptr_test_setting($settings['p_resize_width'], '120'); $settings['p_resize_height'] = ptr_test_setting($settings['p_resize_height'], '120'); if ($settings['p_rounded'] == '') $settings['p_rounded'] = 'false'; if ($settings['p_unsharp'] == '') $settings['p_unsharp'] = 'false'; if ($settings['p_use_png'] == '') $settings['p_use_png'] = 'false'; if ($settings['p_caption'] == '') $settings['p_caption'] = 'false'; return $settings; } ?>