Merge commit 'b27996fd50fb1089412553a5db281803ccd045d8' as 'GithubCard'

This commit is contained in:
chekun 2014-04-28 17:53:51 +08:00
commit 9aa2aff2d0
4 changed files with 135 additions and 0 deletions

21
GithubCard/LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Che Kun
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

89
GithubCard/Plugin.php Normal file
View File

@ -0,0 +1,89 @@
<?php
/**
* Github Card
*
* @package Github Card
* @author chekun
* @version 1.0.0
* @dependence 9.9.2-*
* @link http://me.dilicms.com/coding/github-card.html
*/
class GithubCard_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('GithubCard_Plugin', 'parse');
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('GithubCard_Plugin', 'parse');
Typecho_Plugin::factory('Widget_Abstract_Comments')->contentEx = array('GithubCard_Plugin', 'parse');
Typecho_Plugin::factory('Widget_Archive')->footer = array('GithubCard_Plugin', 'footer');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate(){}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form){}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
/**
* 输出尾部js
*
* @access public
* @return void
*/
public static function footer() {
$jsUrl = Helper::options()->pluginUrl . '/GithubCard/js/widget.js';
echo '<script src="'.$jsUrl.'"></script>';
}
/**
* 解析card标签
*
* @access public
* @
*/
public static function parse($text, $widget, $lastResult) {
$text = empty($lastResult) ? $text : $lastResult;
if ($widget instanceof Widget_Archive
|| $widget instanceof Widget_Abstract_Comments) {
return preg_replace(
"/(\[card\](.*?)\[\/card\])/is",
'<div class="github-card" data-github=$2></div>',
$text
);
}
return $text;
}
}

24
GithubCard/README.md Normal file
View File

@ -0,0 +1,24 @@
Github Card for Typecho
===================
本插件实现在Typecho中嵌入github的用户或者项目的卡片。
下载插件:
git clone https://github.com/chekun/typecho-github-card.git /typecho-plugin-path/GithubCard
激活后使用:
```
[card]chekun[/card] //嵌入用户卡片
```
```
[card]chekun/typecho-github-card[/card] //嵌入项目卡片
```
本项目使用了 [lepture/github-cards](https://github.com/lepture/github-cards).
使用演示:
[http://me.dilicms.com/coding/github-card.html](http://me.dilicms.com/coding/github-card.html)

1
GithubCard/js/widget.js Normal file
View File

@ -0,0 +1 @@
(function(t){var e,r=0;var i=t.getElementsByTagName("meta");var n="http://lab.lepture.com/github-cards/card.html";var a,c;for(e=0;e<i.length;e++){if(i[e].getAttribute("name")==="gc:url"){n=i[e].getAttribute("content")}else if(i[e].getAttribute("name")==="gc:client-id"){a=i[e].getAttribute("content")}else if(i[e].getAttribute("name")==="gc:client-secret"){c=i[e].getAttribute("content")}}function l(r){if(t.querySelectorAll){return t.querySelectorAll("."+r)}var i=t.getElementsByTagName("div");var n=[];for(e=0;e<i.length;e++){if(~i[e].className.split(" ").indexOf(r)){n.push(i[e])}}return n}function u(t,e){return t.getAttribute("data-"+e)}function d(t){if(window.addEventListener){window.addEventListener("message",function(e){if(t.id===e.data.sender){t.height=e.data.height}},false)}}function g(e,i){var n=u(e,"user");var l=u(e,"repo");var g=u(e,"github");if(g){g=g.split("/");if(g.length&&!n){n=g[0];l=l||g[1]}}if(!n){return}r+=1;var f=u(e,"width");var s=u(e,"height");var o=u(e,"target");var h=u(e,"client-id")||a;var v=u(e,"client-secret")||c;var b="ghcard-"+n+"-"+r;var m=t.createElement("iframe");m.setAttribute("id",b);m.setAttribute("frameborder",0);m.setAttribute("scrolling",0);m.setAttribute("allowtransparency",true);var A=i+"?user="+n+"&identity="+b;if(l){A+="&repo="+l}if(o){A+="&target="+o}if(h&&v){A+="&client_id="+h+"&client_secret="+v}m.src=A;m.width=f||Math.min(e.parentNode.clientWidth||400,400);if(s){m.height=s}d(m);e.parentNode.replaceChild(m,e);return m}var f=l("github-card");for(e=0;e<f.length;e++){g(f[e],n)}if(window.githubCard){window.githubCard.render=g}})(document);