query($wpdb->prepare("insert IGNORE into $table_name(ID,is_redirected,redirect_from,redirect_to,redirect_type,blog) values(%s,%s,%s,%s,%s,%s); ",$post_id, $is_redirected, $redirect_from, $redirect_to, $redirect_type, get_current_blog_id())); } } /*- Fetch Redirect ----------------------------------------*/ public function fetch_redirect($post_id) { global $wpdb; $table_name = SR_database::WP_SEO_Cache(); return $wpdb->get_row($wpdb->prepare("select * from $table_name where blog='" . get_current_blog_id() . "' and ID=%s; ", $post_id )); } /*- Redirect Cache ----------------------------------------*/ public function redirect_cached($post_id) { $redirect = $this->fetch_redirect($post_id); if($redirect != null && $redirect->redirect_from==SRP_PLUGINS::get_request()->get_current_relative_url() && self::cache_enabled()) { if($redirect->is_redirected==1) { if($redirect->redirect_type==301) { header ('HTTP/1.1 301 Moved Permanently'); header ("Location: " . $redirect->redirect_to); exit(); } else if($redirect->redirect_type==307) { header ('HTTP/1.0 307 Temporary Redirect'); header ("Location: " . $redirect->redirect_to); exit(); } else if($redirect->redirect_type==302) { header ("Location: " . $redirect->redirect_to); exit(); } } return 'not_redirected'; } return 'not_found'; } /*- Delete Redirect ----------------------------------------*/ public function del_redirect($post_id) { global $wpdb; $table_name = SR_database::WP_SEO_Cache(); return $wpdb->get_var("delete from $table_name where blog='" . get_current_blog_id() . "' and ID='$post_id'; "); } /*- Free Cache ----------------------------------------*/ public static function free_cache($force=0) { if(self::cache_enabled() || $force==1){ global $wpdb; $table_name = SR_database::WP_SEO_Cache(); $wpdb->query($wpdb->prepare(" delete from $table_name where blog=%s ",get_current_blog_id() )); if(self::show_notifications() && $force!=2) SRP_PLUGINS::get_app()->echo_message("All cached redirects are deleted!"); } } /*- Free Cache ----------------------------------------*/ public static function free_cache_without_notification(){ self::free_cache(2); } /*- Cache Count ----------------------------------------*/ public function count_cache() { global $wpdb; $table_name = SR_database::WP_SEO_Cache(); return $wpdb->get_var("select count(*) as cnt from $table_name where blog='" . get_current_blog_id() . "'; "); } /* ----------------------------------------------- */ public static function show_notifications() { return self::$show_notifications; } /* ----------------------------------------------- */ public static function cache_enabled() { return (intval(SRP_PLUGINS::get_options()->read_option_value("cache_enable"))!=0); } }}