Life Journal

随笔,及其他

我是 Xiao Xiao,在日本的产品经理,偶尔也写代码,iOS/Mac/Web,偶尔也做设计,爱用 Sketch,偶尔写文字,存在这里。


启用新主题+让lifestream支持饭否

cnbeta上看到了这个主题,名为Irresistible,一眼就喜欢上了这个布局设计。于是花了一整天的时间终于将其设置好。这个主题需要插件lifestream支持,并且原生支持google analytics和feedburner,可以选择多种配色方案,自定义LOGO和侧边栏位置,直接可以展示flickr,而且还自带一个archieve.php存档文件模板。搭配上lifestream插件后,更是可以展示你的微博更新——支持许多网站。用了这个主题后,晓晓省掉了许多的第三方插件……顿时舒服了许多。

但是呢,小小的遗憾是,lifestream插件是国外的,所以对国内的插件支持并不好……晓晓花了点时间研究了下这个插件,发现这个插件代码写的非常漂亮,要添加一个新的微博服务非常简单,只需要继承一个类即可。下面是晓晓自己写的用于饭否的代码,只要将其复制到插件目录下的inc\extensions.php文件末尾即可。如果希望使用内置的图标的话,那么把饭否的favicon转换并命名为fanfou.png保存到插件的images文件夹下即可。对于其他国内服务同理哦~只需自己替换相应fanfou字符串即可。

[?](http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples "WP-CodeBox HowTo?")[View Code](javascript:;) PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 class Lifestream_FanfouFeed extends Lifestream_Feed {const ID ='fanfou';const NAME ='Fanfou';const URL ='http://www.fanfou.com/';const LABEL ='Lifestream_MessageLabel';const CAN_GROUP =false;const DESCRIPTION ='Specifying your password will allow Lifestream to pull in protected updates from your profile. Your password is stored in plaintext in the database, so only do this is you have no other option.';   function __toString(){return$this->options['username'];}   function get_options(){return[array](http://www.php.net/array)('username'=>[array](http://www.php.net/array)($this->lifestream->__('Username:'),true,'',''),'password'=>[array](http://www.php.net/array)($this->lifestream->__('Password:'),false,'',''),'hide_replies'=>[array](http://www.php.net/array)($this->lifestream->__('Hide Replies'),false,true,false),);}   function _get_user_link($match){return$match[1].$this->get_user_link($match[2]);}   function _get_search_term_link($match){return$match[1].'.[urlencode](http://www.php.net/urlencode)($match[2]).'">'.[htmlspecialchars](http://www.php.net/htmlspecialchars)($match[2]).'';}   function get_user_link($user){return'.$this->get_user_url($user).'" class="user">@'.[htmlspecialchars](http://www.php.net/htmlspecialchars)($user).'';}   function get_user_url($user){return'http://www.fanfou.com/'.[urlencode](http://www.php.net/urlencode)($user);}   function get_public_url(){return$this->get_user_url($this->options['username']);}   function parse_users($text){return[preg_replace_callback](http://www.php.net/preg_replace_callback)('/([^\w]*)@([a-z0-9_-]+)\b/i',[array](http://www.php.net/array)($this,'_get_user_link'),$text);}   function parse_search_term($text){return[preg_replace_callback](http://www.php.net/preg_replace_callback)('/([^\w]*)(#[a-z0-9_-]+)\b/i',[array](http://www.php.net/array)($this,'_get_search_term_link'),$text);}   function get_url($page=1,$count=4){if($this->options['password']){$url_base='http://'.$this->options['username'].':'.$this->options['password'].'@api.fanfou.com';}else{$url_base='http://api.fanfou.com';}return$url_base.'/statuses/user_timeline/'.$this->options['username'].'.rss?count='.$count.'&page='.$page;}   function save(){$is_new=(bool)!$this->id; parent::save();if($is_new){// new feed -- attempt to import all statuses up to 2k$feed_msg=[array](http://www.php.net/array)(true,'');$page=0;while($feed_msg[0]!==false&&$page<10){$page+=1;$feed_msg=$this->refresh($this->get_url($page,20));}}}   function render_item($row,$item){return$this->parse_search_term($this->parse_users($this->parse_urls([htmlspecialchars](http://www.php.net/htmlspecialchars)($item['description'])))).' [.[htmlspecialchars](http://www.php.net/htmlspecialchars)($item['link']).'">#]';}   function yield($row,$url,$key){$data= parent::yield($row,$url,$key);$string=$this->options['username'].': ';$description=$this->lifestream->html_entity_decode($row->get_description());if(str_startswith([strtolower](http://www.php.net/strtolower)($description),[strtolower](http://www.php.net/strtolower)($string))){$description=[substr](http://www.php.net/substr)($description,[strlen](http://www.php.net/strlen)($string));}if($this->options['hide_replies']&& str_startswith($description,'@')){returnfalse;}$data['description']=$description;return$data;}}$lifestream->register_feed('Lifestream_FanfouFeed');