-
Notifications
You must be signed in to change notification settings - Fork 591
Expand file tree
/
Copy pathPlugin.php
More file actions
82 lines (71 loc) · 1.98 KB
/
Copy pathPlugin.php
File metadata and controls
82 lines (71 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace TypechoPlugin\YetAnotherLike;
use Typecho\Plugin\PluginInterface;
use Typecho\Widget\Helper\Form;
use Utils\Helper;
use Typecho\Widget\Helper\Form\Element\Radio;
if (!defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
/**
* Typecho 点赞插件
*
* @package YetAnotherLike
* @author Ect07
* @version 1.0.0
* @since 1.3.0
* @link https://ect.fyi/
*/
class Plugin implements PluginInterface
{
/**
* 激活插件方法
*/
public static function activate()
{
try {
Helper::addAction('like', 'TypechoPlugin\YetAnotherLike\Like_Action');
} catch (\Exception $e) {
throw new \Typecho\Plugin\Exception('插件激活失败: ' . $e->getMessage());
}
}
/**
* 禁用插件方法
*/
public static function deactivate()
{
Helper::removeAction('like');
}
/**
* 获取插件配置面板
*/
public static function config(Form $form)
{
$login = new Radio('login', array('0'=> '任何用户', '1'=> '仅登录用户'), 0, '对哪些用户启用',
'设置哪些用户可以点赞。如果选择“任何用户”,对于未登录的情况,每个IP地址只能点赞一次。');
$form->addInput($login);
}
/**
* 个人用户的配置面板
*/
public static function personalConfig(Form $form)
{
}
public static function like() {
include __DIR__ . '/like-button.php';
}
public static function likeCount() {
$db = \Typecho\Db::get();
$LIKE_FIELD_NAME = "likes";
$cid = \Widget\Archive::alloc()->cid;
$userlist = ",";
$already_exists = $db->fetchRow(
$db->select()->from("table.fields")->where("cid = ?", $cid)->where("name = ?", $LIKE_FIELD_NAME)
);
if (!is_null($already_exists)) {
$userlist = $already_exists["str_value"];
}
$like_count = substr_count($userlist, ",") - 1;
echo $like_count;
}
}