diff --git a/Zan/.gitattributes b/Zan/.gitattributes new file mode 100644 index 00000000..412eeda7 --- /dev/null +++ b/Zan/.gitattributes @@ -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 diff --git a/Zan/.gitignore b/Zan/.gitignore new file mode 100644 index 00000000..b9d6bd92 --- /dev/null +++ b/Zan/.gitignore @@ -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 diff --git a/Zan/Action.php b/Zan/Action.php new file mode 100644 index 00000000..0563e2c1 --- /dev/null +++ b/Zan/Action.php @@ -0,0 +1,60 @@ +db = Typecho_Db::get(); + } + + public function showZan($cid){ + $html = '赞 ('; + $html .= self::getZan($cid); + $html .= ')'; + 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('感谢您的赞!'))); + } + } +} +?> \ No newline at end of file diff --git a/Zan/Plugin.php b/Zan/Plugin.php new file mode 100644 index 00000000..aacc0b7e --- /dev/null +++ b/Zan/Plugin.php @@ -0,0 +1,43 @@ +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 "\n"; + } + public static function footlink() { + //echo Typecho_Common::url('action/WeChat?customreply', ''); + $script = "\n"; + echo $script; + } +} diff --git a/Zan/README.md b/Zan/README.md new file mode 100644 index 00000000..8a23c4b6 --- /dev/null +++ b/Zan/README.md @@ -0,0 +1,15 @@ +## 插件说明 ## + - 版本: v1.0.0 + - 作者: [冰剑](https://github.com/binjoo) + - 备注:基于Typecho的插件 + +## 使用方法 ## + + 1. 下载插件 + 2. 将插件上传到 /usr/plugins/ 这个目录下 + 3. 启用当前插件 + 4. 在模版post.php文件中你要插入`赞`的地方加入代码`showZan($this->cid); ?>` + +## 更新记录 ## +####v1.0.0 + - 基本的赞功能 \ No newline at end of file