Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaogouxo committed Aug 1, 2014
1 parent 32fe0e4 commit a45e19f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 26 deletions.
8 changes: 4 additions & 4 deletions Likes/Action.php → Like/Action.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
/**
* Likes Plugin
* Like Plugin
*
* @copyright Copyright (c) 2014 skylzl (http://www.woyoudian.com)
* @license GNU General Public License 2.0
*
*/

class Likes_Action extends Typecho_Widget implements Widget_Interface_Do
class Like_Action extends Typecho_Widget implements Widget_Interface_Do
{
private $db;

Expand All @@ -20,7 +20,7 @@ public function __construct($request, $response, $params = NULL)
/**
* 点赞Like
*/
public function like(){
public function up(){
$cid=$this->request->filter('int')->cid;
if($cid){
try {
Expand All @@ -37,7 +37,7 @@ public function like(){
}

public function action(){
$this->on($this->request->is('like'))->like();
$this->on($this->request->is('up'))->up();
$this->response->goBack();
}
}
Expand Down
37 changes: 19 additions & 18 deletions Likes/Plugin.php → Like/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
/**
* Typecho 点赞插件
*
* @package Likes
* @package Like
* @author skylzl
* @version 1.0.0
* @link http://www.phoneshuo.com
*/

class Likes_Plugin implements Typecho_Plugin_Interface
class Like_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
Expand All @@ -20,9 +20,9 @@ class Likes_Plugin implements Typecho_Plugin_Interface
*/
public static function activate()
{
Typecho_Plugin::factory('Widget_Archive')->footer = array('Likes_Plugin', 'header');
Typecho_Plugin::factory('Widget_Archive')->footer = array('Likes_Plugin', 'footer');
Helper::addAction('likes', 'Likes_Action');
Typecho_Plugin::factory('Widget_Archive')->footer = array('Like_Plugin', 'header');
Typecho_Plugin::factory('Widget_Archive')->footer = array('Like_Plugin', 'footer');
Helper::addAction('like', 'Like_Action');
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
// contents 如果没有likes字段,则添加
Expand Down Expand Up @@ -71,22 +71,22 @@ public static function personalConfig(Typecho_Widget_Helper_Form $form){
/**
* 输出点赞链接或者点赞次数
*
* 语法: Likes_Plugin::theLikes();
* 输出: '<a href="javascript:;" class="post-like" data-pid="'.$cid.'">赞 (<span>'.$row['likes'].'</span>)</a>'
* 语法: Like_Plugin::theLike();
* 输出: '<a href="javascript:;" class="post-like" data-pid="'.$cid.'">赞 (<span>'.$row['like'].'</span>)</a>'
*
* 语法: Likes_Plugin::theLikes(false);
* 语法: Like_Plugin::theLike(false);
* 输出: 0
*
* @access public
* @param bool $link 是否输入链接 (false为显示纯数字)
* @return string
*/
public static function theLikes($link = true){
public static function theLike($link = true){
$db = Typecho_Db::get();
$cid = Typecho_Widget::widget('Widget_Archive')->cid;
$row = $db->fetchRow($db->select('likes')->from('table.contents')->where('cid = ?', $cid));
if($link){
$settings = Helper::options()->plugin('Likes');
$settings = Helper::options()->plugin('Like');
echo '<a href="javascript:;" class="'.$settings->likeClass.'" data-pid="'.$cid.'"><i class="fa-thumbs-up"></i>赞 (<span>'.$row['likes'].'</span>)</a>';
}else{
return $row['likes'];
Expand All @@ -96,16 +96,16 @@ public static function theLikes($link = true){
/**
* 输出点赞最多的文章
*
* 语法: Likes_Plugin::theMostLiked();
* 语法: Like_Plugin::theMostLiked();
*
* @access public
* @param int $limit 文章数目
* @param string $shownum 是否显示点赞数量
* @param string $showlink 是否显示点赞链接
* @param string $before 前字串
* @param string $after 后字串
* @return string
*/
public static function theMostLiked($limit = 10, $shownum = true, $before = '<br/> - ( 点赞: ', $after = ' 次 ) ')
public static function theMostLiked($limit = 10, $showlink = true, $before = '<br/> - ( 点赞: ', $after = ' 次 ) ')
{
$db = Typecho_Db::get();
$limit = is_numeric($limit) ? $limit : 10;
Expand All @@ -121,10 +121,11 @@ public static function theMostLiked($limit = 10, $shownum = true, $before = '<br
$post_likes = number_format($result['likes']);
$post_title = htmlspecialchars($result['title']);
$permalink = $result['permalink'];
if($shownum == true){
echo "<li><a href='$permalink' title='$post_title'>$post_title</a><span style='font-size:70%'>$before $post_likes $after</span></li>\n";
$settings = Helper::options()->plugin('Like');
if($showlink == true){
echo "<li><a href='$permalink' title='$post_title'>$post_title</a><span style='font-size:70%'><br/><a href='javascript:;' class='$settings->likeClass' data-pid='$cid'><i class='fa-thumbs-up'></i>赞 (<span>'$post_likes</span>)</a></span></li>\n";
}else{
echo "<li><a href='$permalink' title='$post_title'>$post_title</a></li>\n";
echo "<li><a href='$permalink' title='$post_title'>$post_title</a><span style='font-size:70%'>$before $post_likes $after</span></li>\n";
}
}

Expand All @@ -136,14 +137,14 @@ public static function theMostLiked($limit = 10, $shownum = true, $before = '<br
* 点赞相关css加载在头部
*/
public static function header() {
$cssUrl = Helper::options()->pluginUrl . '/Likes/css/style.css';
$cssUrl = Helper::options()->pluginUrl . '/Like/css/style.css';
echo '<link rel="stylesheet" type="text/css" href="' . $cssUrl . '" />';
}

/**
* 点赞相关js加载在尾部
*/
public static function footer() {
include 'likes-js.php';
include 'like-js.php';
}
}
3 changes: 3 additions & 0 deletions Like/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 插件说明 ##
####typecho点赞like插件,调用<?php Like_Plugin::theLike(); ?>即可
####详细介绍:http://www.phoneshuo.com/PHP/typecho-like-plugin.html
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions Likes/likes-js.php → Like/like-js.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
$jqueryScriptUrl = Helper::options()->pluginUrl . '/Likes/js/jquery.js';
$macaroonScriptUrl = Helper::options()->pluginUrl . '/Likes/js/jquery.fs.macaroon.js';
$settings = Helper::options()->plugin('Likes');
$jqueryScriptUrl = Helper::options()->pluginUrl . '/Like/js/jquery.js';
$macaroonScriptUrl = Helper::options()->pluginUrl . '/Like/js/jquery.fs.macaroon.js';
$settings = Helper::options()->plugin('Like');
?>

<script type="text/javascript" src="<?php echo $jqueryScriptUrl; ?>"></script>
Expand All @@ -16,7 +16,7 @@
cookies ? cookies.length >= 160 ? (cookies = cookies.substring(0, cookies.length - 1), cookies = cookies.substr
(1).split(","), cookies.splice(0, 1), cookies.push(id), cookies = cookies.join(","), $.macaroon("_syan_like", "," + cookies +
",")) : $.macaroon("_syan_like", cookies + id + ",") : $.macaroon("_syan_like", "," + id + ",");
$.post('<?php Helper::options()->index('/action/likes?like'); ?>',{
$.post('<?php Helper::options()->index('/action/like?up'); ?>',{
cid:id
},function(data){
th.addClass('actived');
Expand Down

0 comments on commit a45e19f

Please sign in to comment.