forked from Moidea/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'aba9cde99189175624e6853ffbfef036b516f9d9' as 'Zan'
- Loading branch information
Showing
5 changed files
with
355 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
|
||
# Custom for Visual Studio | ||
*.cs diff=csharp | ||
*.sln merge=union | ||
*.csproj merge=union | ||
*.vbproj merge=union | ||
*.fsproj merge=union | ||
*.dbproj merge=union | ||
|
||
# Standard to msysgit | ||
*.doc diff=astextplain | ||
*.DOC diff=astextplain | ||
*.docx diff=astextplain | ||
*.DOCX diff=astextplain | ||
*.dot diff=astextplain | ||
*.DOT diff=astextplain | ||
*.pdf diff=astextplain | ||
*.PDF diff=astextplain | ||
*.rtf diff=astextplain | ||
*.RTF diff=astextplain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
################# | ||
## Eclipse | ||
################# | ||
|
||
*.pydevproject | ||
.project | ||
.metadata | ||
bin/ | ||
tmp/ | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
local.properties | ||
.classpath | ||
.settings/ | ||
.loadpath | ||
|
||
# External tool builders | ||
.externalToolBuilders/ | ||
|
||
# Locally stored "Eclipse launch configurations" | ||
*.launch | ||
|
||
# CDT-specific | ||
.cproject | ||
|
||
# PDT-specific | ||
.buildpath | ||
|
||
|
||
################# | ||
## Visual Studio | ||
################# | ||
|
||
## Ignore Visual Studio temporary files, build results, and | ||
## files generated by popular Visual Studio add-ons. | ||
|
||
# User-specific files | ||
*.suo | ||
*.user | ||
*.sln.docstates | ||
|
||
# Build results | ||
|
||
[Dd]ebug/ | ||
[Rr]elease/ | ||
x64/ | ||
build/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
|
||
# MSTest test Results | ||
[Tt]est[Rr]esult*/ | ||
[Bb]uild[Ll]og.* | ||
|
||
*_i.c | ||
*_p.c | ||
*.ilk | ||
*.meta | ||
*.obj | ||
*.pch | ||
*.pdb | ||
*.pgc | ||
*.pgd | ||
*.rsp | ||
*.sbr | ||
*.tlb | ||
*.tli | ||
*.tlh | ||
*.tmp | ||
*.tmp_proj | ||
*.log | ||
*.vspscc | ||
*.vssscc | ||
.builds | ||
*.pidb | ||
*.log | ||
*.scc | ||
|
||
# Visual C++ cache files | ||
ipch/ | ||
*.aps | ||
*.ncb | ||
*.opensdf | ||
*.sdf | ||
*.cachefile | ||
|
||
# Visual Studio profiler | ||
*.psess | ||
*.vsp | ||
*.vspx | ||
|
||
# Guidance Automation Toolkit | ||
*.gpState | ||
|
||
# ReSharper is a .NET coding add-in | ||
_ReSharper*/ | ||
*.[Rr]e[Ss]harper | ||
|
||
# TeamCity is a build add-in | ||
_TeamCity* | ||
|
||
# DotCover is a Code Coverage Tool | ||
*.dotCover | ||
|
||
# NCrunch | ||
*.ncrunch* | ||
.*crunch*.local.xml | ||
|
||
# Installshield output folder | ||
[Ee]xpress/ | ||
|
||
# DocProject is a documentation generator add-in | ||
DocProject/buildhelp/ | ||
DocProject/Help/*.HxT | ||
DocProject/Help/*.HxC | ||
DocProject/Help/*.hhc | ||
DocProject/Help/*.hhk | ||
DocProject/Help/*.hhp | ||
DocProject/Help/Html2 | ||
DocProject/Help/html | ||
|
||
# Click-Once directory | ||
publish/ | ||
|
||
# Publish Web Output | ||
*.Publish.xml | ||
*.pubxml | ||
|
||
# NuGet Packages Directory | ||
## TODO: If you have NuGet Package Restore enabled, uncomment the next line | ||
#packages/ | ||
|
||
# Windows Azure Build Output | ||
csx | ||
*.build.csdef | ||
|
||
# Windows Store app package directory | ||
AppPackages/ | ||
|
||
# Others | ||
sql/ | ||
*.Cache | ||
ClientBin/ | ||
[Ss]tyle[Cc]op.* | ||
~$* | ||
*~ | ||
*.dbmdl | ||
*.[Pp]ublish.xml | ||
*.pfx | ||
*.publishsettings | ||
|
||
# RIA/Silverlight projects | ||
Generated_Code/ | ||
|
||
# Backup & report files from converting an old project file to a newer | ||
# Visual Studio version. Backup files are not needed, because we have git ;-) | ||
_UpgradeReport_Files/ | ||
Backup*/ | ||
UpgradeLog*.XML | ||
UpgradeLog*.htm | ||
|
||
# SQL Server files | ||
App_Data/*.mdf | ||
App_Data/*.ldf | ||
|
||
############# | ||
## Windows detritus | ||
############# | ||
|
||
# Windows image file caches | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Mac crap | ||
.DS_Store | ||
|
||
|
||
############# | ||
## Python | ||
############# | ||
|
||
*.py[co] | ||
|
||
# Packages | ||
*.egg | ||
*.egg-info | ||
dist/ | ||
build/ | ||
eggs/ | ||
parts/ | ||
var/ | ||
sdist/ | ||
develop-eggs/ | ||
.installed.cfg | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
||
# Unit test / coverage reports | ||
.coverage | ||
.tox | ||
|
||
#Translations | ||
*.mo | ||
|
||
#Mr Developer | ||
.mr.developer.cfg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
class Zan_Action extends Typecho_Widget implements Widget_Interface_Do { | ||
protected $db; | ||
|
||
public function __construct($request, $response, $params = NULL) { | ||
parent::__construct($request, $response, $params); | ||
$this->db = Typecho_Db::get(); | ||
} | ||
|
||
public function showZan($cid){ | ||
$html = '<a href="javascript:;" class="post-zan" data-cid="'; | ||
$html .= $cid; | ||
$html .= '">赞 (<span>'; | ||
$html .= self::getZan($cid); | ||
$html .= '</span>)</a>'; | ||
echo $html; | ||
} | ||
|
||
private function getZan($cid){ | ||
$exist = $this->db->fetchRow($this->db->select('int_value')->from('table.fields')->where('cid = ? AND name = ?', $cid, 'zan')); | ||
if (empty($exist)) { | ||
return 0; | ||
}else{ | ||
return $exist['int_value']; | ||
} | ||
} | ||
|
||
private function addZan($cid){ | ||
$exist = $this->db->fetchRow($this->db->select('int_value')->from('table.fields')->where('cid = ? AND name = ?', $cid, 'zan')); | ||
$zan = array('cid'=>$cid, 'name'=>'zan', 'type'=>'int', 'str_value'=>NULL, 'int_value'=>1, 'float_value'=>0); | ||
$result = null; | ||
if (empty($exist)) { | ||
$result = $this->db->query($this->db->insert('table.fields')->rows($zan)); | ||
} else { | ||
$zan['int_value'] = $exist['int_value'] + 1; | ||
$result = $this->db->query($this->db->update('table.fields')->rows($zan)->where('cid = ? AND name = ?', $cid, 'zan')); | ||
} | ||
|
||
if($result){ | ||
$cookie = Typecho_Cookie::get("__zan_cids"); | ||
$cids = null; | ||
if($cookie){ | ||
$cids = Json::decode($cookie, true); | ||
$cids[$cid] = isset($cids[$cid]) ? $cids[$cid] + 1 : 0; | ||
}else{ | ||
$cids = array($cid=>0); | ||
} | ||
Typecho_Cookie::set("__zan_cids", Json::encode($cids)); | ||
} | ||
} | ||
|
||
public function action() { | ||
//if($this->request->isGet() && $this->request->is('cid')){ | ||
if($this->request->isPost() && $this->request->is('cid')){ | ||
$this->addZan($this->request->get('cid')); | ||
$this->response->throwJson(array('result' => 1, 'message' => _t('感谢您的赞!'))); | ||
} | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* 赞一个 | ||
* | ||
* @package Zan | ||
* @author 冰剑 | ||
* @version 1.0.0 | ||
* @link http://www.binjoo.net | ||
*/ | ||
class Zan_Plugin implements Typecho_Plugin_Interface { | ||
public static function activate() { | ||
//Typecho_Plugin::factory('Widget_Archive')->header = array('Zan_Plugin', 'headlink'); | ||
Typecho_Plugin::factory('Widget_Archive')->footer = array('Zan_Plugin', 'footlink'); | ||
Helper::addAction('Zan', 'Zan_Action'); | ||
} | ||
public static function deactivate(){ | ||
Helper::removeAction('Zan'); | ||
} | ||
public static function config(Typecho_Widget_Helper_Form $form){} | ||
public static function personalConfig(Typecho_Widget_Helper_Form $form){} | ||
public static function headlink() { | ||
$css_url = Typecho_Common::url('Zan/css/Zan.min.css', Helper::options()->pluginUrl); | ||
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$css_url}\" media=\"all\" />\n"; | ||
} | ||
public static function footlink() { | ||
//echo Typecho_Common::url('action/WeChat?customreply', ''); | ||
$script = "<script type=\"text/javascript\">"; | ||
$script .= '$(document).ready(function(){ | ||
$(".post-zan").on("click", function(){ | ||
var zan = $(this); | ||
$.post("' . Typecho_Widget::widget('Widget_Security')->getIndex('action/Zan') . '", {cid: zan.attr("data-cid")},function(data){ | ||
if(data.result == 1){ | ||
var val = zan.find("span").text(); | ||
zan.find("span").text(parseInt(val) + 1); | ||
} | ||
//alert(data.message); | ||
}, "json"); | ||
}) | ||
})'; | ||
$script .= "</script>\n"; | ||
echo $script; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## 插件说明 ## | ||
- 版本: v1.0.0 | ||
- 作者: [冰剑](https://github.com/binjoo) | ||
- 备注:基于Typecho的插件 | ||
|
||
## 使用方法 ## | ||
|
||
1. 下载插件 | ||
2. 将插件上传到 /usr/plugins/ 这个目录下 | ||
3. 启用当前插件 | ||
4. 在模版post.php文件中你要插入`赞`的地方加入代码`<?php Typecho_Widget::widget('Zan_Action')->showZan($this->cid); ?>` | ||
|
||
## 更新记录 ## | ||
####v1.0.0 | ||
- 基本的赞功能 |