Skip to content

Commit 32355f6

Browse files
author
xiaogouxo
committed
add likes plugin
1 parent e7361f4 commit 32355f6

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

Likes/Plugin.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,13 @@ public static function deactivate(){}
4949
* @return void
5050
*/
5151
public static function config(Typecho_Widget_Helper_Form $form){
52-
/** 列表A标签点赞的class */
53-
$listLikeClass = new Typecho_Widget_Helper_Form_Element_Text(
54-
'listClass', NULL,'list-like',
55-
_t('列表点赞A标签的class'),
56-
_t('列表页点赞的自定义样式,默认为.list-like可自写CSS样式')
57-
);
58-
$form->addInput($listLikeClass);
5952
/** 文章页A标签点赞的class */
60-
$postLikeClass = new Typecho_Widget_Helper_Form_Element_Text(
61-
'postClass',NULL ,'post-like',
62-
_t('文章点赞A标签的class'),
63-
_t('文章页点赞的自定义样式,默认为.post-like可自写CSS样式')
53+
$likeClass = new Typecho_Widget_Helper_Form_Element_Text(
54+
'likeClass',NULL ,'post-like',
55+
_t('点赞A标签的class'),
56+
_t('点赞的自定义样式,默认为.post-like。可自定义CSS样式,无需加.')
6457
);
65-
$form->addInput($postLikeClass);
58+
$form->addInput($likeClass);
6659
}
6760

6861
/**
@@ -85,15 +78,16 @@ public static function personalConfig(Typecho_Widget_Helper_Form $form){
8578
* 输出: 0
8679
*
8780
* @access public
88-
* @param bool $link 是否输入链接 (false为显示纯数字,用于自定义显示样式)
81+
* @param bool $link 是否输入链接 (false为显示纯数字)
8982
* @return string
9083
*/
9184
public static function theLikes($link = true){
9285
$db = Typecho_Db::get();
9386
$cid = Typecho_Widget::widget('Widget_Archive')->cid;
9487
$row = $db->fetchRow($db->select('likes')->from('table.contents')->where('cid = ?', $cid));
9588
if($link){
96-
echo '<a href="javascript:;" class="post-like" data-pid="'.$cid.'"><i class="fa-thumbs-up"></i>赞 (<span>'.$row['likes'].'</span>)</a>';
89+
$settings = Helper::options()->plugin('Likes');
90+
echo '<a href="javascript:;" class="'.$settings->likeClass.'" data-pid="'.$cid.'"><i class="fa-thumbs-up"></i>赞 (<span>'.$row['likes'].'</span>)</a>';
9791
}else{
9892
return $row['likes'];
9993
}
@@ -111,10 +105,9 @@ public static function theLikes($link = true){
111105
* @param string $after 后字串
112106
* @return string
113107
*/
114-
public static function theMostLiked($limit = 10, $shownum = true, $before = '<br/> - ( 访问: ', $after = ' 次 ) ')
108+
public static function theMostLiked($limit = 10, $shownum = true, $before = '<br/> - ( 点赞: ', $after = ' 次 ) ')
115109
{
116110
$db = Typecho_Db::get();
117-
$options = Typecho_Widget::widget('Widget_Options');
118111
$limit = is_numeric($limit) ? $limit : 10;
119112
$posts = $db->fetchAll($db->select()->from('table.contents')
120113
->where('type = ? AND status = ? AND password IS NULL', 'post', 'publish')

Likes/likes-js.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<script type="text/javascript" src="<?php echo $jqueryScriptUrl; ?>"></script>
88
<script type="text/javascript" src="<?php echo $macaroonScriptUrl; ?>"></script>
99
<script>
10-
$(".<?php echo $settings->listClass; ?>,.<?php echo $settings->postClass; ?>").on("click", function(){
10+
$(".<?php echo $settings->likeClass; ?>").on("click", function(){
1111
var th = $(this);
1212
var id = th.attr('data-pid');
1313
var cookies = $.macaroon('_syan_like') || "";

0 commit comments

Comments
 (0)