Denis & Liu Yang Version: 3.0 Author: Denis & LiuYang Author URI: http://17fav.com/ */ //=== Please DO NOT edit following lines unless you know actually what you do :P === define('BS_ALREADY_JQUERY',0); //if your template or plugin has been loaded jQuery without using wp_enquenue_script, change the value to 1 define('BS_ALREADY_JQUERY_DIMENSIONS',0); //if your template or plugin has been loaded jQuery-Dimensions plugin without using wp_enquenue_script, or with a name differ from jquery-dimensions change the value to 1 //===END JQUERY=== class WPBS { var $version = "3.0.1"; var $uid; var $popwin; var $insert2; var $insert2feed; var $insert2home; var $bs_server_url = 'http://17fav.com/'; var $imgbtn; var $iconbtn; var $postids; var $footer_forms; function WPBS() { $this->uid = get_option('bs_uid'); if ($this->uid === false) { // uid did not exists, we create it. $this->uid = $this->_generate_uid(); update_option('bs_uid',$this->uid); } if (false === get_option('bs_popwin')) { $this->popwin = false; } else { $this->popwin = get_option('bs_popwin'); } //load jquery & dimensions plugin if (!defined('WP_ADMIN')) $this->_load_jquery_lib(); //initialize post ids $this->postids = array(); //auto add to single? if (false === get_option('bs_insert2')) { $this->insert2 = true; update_option('bs_insert2',$this->insert2); } else { $this->insert2 = get_option('bs_insert2'); } if (false === get_option('bs_insert2home')) { $this->insert2home = false; update_option('bs_insert2home',$this->insert2home); } else { $this->insert2home = get_option('bs_insert2home'); } if (false === get_option('bs_insert2feed')) { $this->insert2feed = true; update_option('bs_insert2feed',$this->insert2feed); } else { $this->insert2feed = get_option('bs_insert2feed'); } add_filter('the_content',array(&$this,'bs_add_content')); //actions add_action('wp_header',array(&$this,'bs_header')); add_action('wp_footer',array(&$this,'bs_footer')); add_action('admin_menu',array(&$this,'admin_page')); } function bs_add_content($text) { if (is_home() && $this->insert2home) { return $text . $this->bs_string(false); } if(is_single() && $this->insert2) { return $text . $this->bs_string(false); } if(is_feed() && $this->insert2feed) { return $text . $this->bs_string(true); } return $text; } function bs_header() { $this->footer_forms = ''; } function bs_footer() { echo $this->bs_code(); echo '
'; echo $this->footer_forms; echo '
'; } function bs_string($feed_mode = false) { global $post; $fitems = array(); $fitems['v'] = $this->version; $fitems['hash'] = $this->uid; $fitems['url'] = get_permalink($post->ID); $fitems['title'] = get_the_title($post->ID); if (has_excerpt($post->ID)) { $fitems['description'] = get_the_excerpt(); } else { $fitems['description'] = $this->_utrim(strip_tags($post->post_content),100); } $fitems['tags'] = ''; $tags = get_the_tags($post->ID); if (!is_wp_error($tags) && is_array($tags) && count($tags)) { $tagline = ''; foreach($tags as $tag) { if (strlen($tagline)) $tagline .= ","; $tagline .= $tag->name; } $fitems['tags'] = $tagline; } if (!$feed_mode) { $fitems['server'] = ''; $formd = '"; $this->footer_forms .= $formd; $this->postids[] = $post->ID; $feed_str = ''; } else { $feed_str = ''; foreach ($fitems as $k=>$v) { $feed_str .= "$k=".urlencode($v)."&"; } $feed_str = "?$feed_str"; $feed_str = substr($feed_str,0,-1); } // $r = $this->_get_color_schemes(); $btnurl = $this->_get_btn_url($r[0]); $btn = '17fav 收藏本文'; $btn = sprintf($btn,$feed_str,$post->ID,$btnurl); return $btn; } function bs_code($preview = false) { $all_servs = $this->_get_all_services(); $serv_slugs = $this->_get_services(); $servs = array(); foreach($serv_slugs as $serv) { foreach($all_servs->detail as $s) { if ($serv == $s->slug) { $servs[] = $s; break; } } } list( $bs_btn, $bg_color, $bg_border_color, $title_bg_color, $title_text_color, $item_text_color, $item_hover_border_color ) = $this->_get_color_schemes(); $css = ''; $js = ''; $html = '
'; $html .= '

收藏 & 分享

'; $html .= ''; $html .= '

Powered by 17fav.com

'; $html .= '
'; return $css.$js.$html; } function admin_page() { add_options_page('收藏&分享','收藏&分享', 9, 'bookmark-share', array(&$this,'admin')); } function admin() { $allserv = $this->_get_all_services(); if (!empty($_POST['bs_submit'])) { update_option('bs_popwin',(bool)$_POST['bs_popwin']); update_option('bs_insert2',(bool)$_POST['bs_insert2']); update_option('bs_insert2home',(bool)$_POST['bs_insert2home']); update_option('bs_insert2feed',(bool)$_POST['bs_insert2feed']); $servs = explode(',',$_POST['bs_selservs']); update_option('bs_servs',$servs); $tmpc = explode(",",$_POST['bs_colors']); $color_schemes = array(); $color_schemes[] = intval($_POST['bs_button_type']); foreach($tmpc as $c) $color_schemes[] = $c; update_option("bs_color_scheme",$color_schemes); } $currserv = $this->_get_services(); $icourl = $allserv->url; $allserv = $allserv->detail; list($bs_btn,$bsc_bg,$bsc_border,$bsc_tbg,$bsc_tt,$bsc_it,$bsc_ihb) = $this->_get_color_schemes(); //var_dump($allserv); ?>

17fav.com - 收藏&分享

开启收藏页面 />在新窗口中 />在原页面
自动插入按钮 />自动插入按钮 />手动插入按钮
首页文章列表中插入按钮 />是 />否
自动插入到 Feed />是 />否
选择收藏服务

样式设定和预览

选择按钮样式

/>

设定颜色

预览

bs_code(true);?>

3600*24) { $s = $this->_reqapi('icon'); $sponslug = array(); if (count($s->detail)) foreach ($s->detail as $i) { if ($i->is_sponsor) array_push($sponslug,$i->slug); } update_option('bs_sp_services',$sponslug); update_option('bs_all_services',$s); update_option('bs_all_services_time',time()); } else { $s = get_option('bs_all_services'); } return $s; } function _get_btn_url($which = 1) { if ( !defined('WP_CONTENT_URL') ) define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); if ( !defined('WP_PLUGIN_URL') ) define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' ); $url = WP_PLUGIN_URL . '/' .dirname(plugin_basename(__FILE__))."/bookmark-%s.gif"; switch($which) { case 1: return sprintf($url,'blue'); case 2: return sprintf($url,'green'); case 3: return sprintf($url,'orange'); case 4: return sprintf($url,'purple'); case 5: return sprintf($url,'red'); case 6: return sprintf($url,'yellow'); } } function _reqapi($cmd,$params='') { require_once(ABSPATH.WPINC.'/class-snoopy.php'); $snoopy = new Snoopy; $snoopy->agent = "17fav Bookmark Share Wordpress Plugin v"+$this->version+"($this->uid)"; if (!function_exists('json_encode')) { require_once(dirname(__FILE__)."/portable-pear-json.php"); } $snoopy->submit($this->bs_server_url . "api/?cmd=$cmd",$params); if ($snoopy->status == 200) { $r=json_decode($snoopy->results); return $r; } else return false; } function _generate_uid() { return md5(get_bloginfo('home')); } function _utrim($str,$length) { $char = get_bloginfo('charset'); if (function_exists('iconv_substr')) { $l = iconv_strlen($str,$char); if ($l<=$length) return $str; else { return iconv_substr($str,0,$length,$char) . "..."; } } elseif (function_exists('mb_substr')) { $l = mb_strlen($str,$char); if ($l<=$length) return $str; else { return mb_substr($str,0,$length,$char) . "..."; } } else { $l = strlen($str); if ($l<$length) return $str; else { $r = substr($str,0,$length); for ($i=strlen($r)-1; $i>=0; $i-=1){ $hex .= ' '.ord($r[$i]); $ch = ord($r[$i]); if (($ch & 128)==0) return substr($r,0,$i)."..."; if (($ch & 192)==192) return substr($r,0,$i)."..."; } return $r.$hex."..."; } } } function _load_jquery_lib() { if (!defined('BS_ALREADY_JQUERY') || !BS_ALREADY_JQUERY) { wp_enqueue_script('jquery-dimensions',get_bloginfo('siteurl'). "/" .PLUGINDIR . "/" . dirname(plugin_basename (__FILE__)).'/jquery.dimensions.js',array('jquery'),'1.2.6'); } else { if (!defined('BS_ALREADY_JQUERY_DIMENSIONS') || !BS_ALREADY_JQUERY_DIMENSIONS) { wp_enqueue_script('jquery-dimensions',get_bloginfo('siteurl'). "/" .PLUGINDIR . "/" . dirname(plugin_basename (__FILE__)).'/jquery.dimensions.js',array(),'1.1.2'); } } } } $wpbs = new WPBS; function bookmark_share() { global $wpbs; echo $wpbs->bs_string(false); } ?>