-
Notifications
You must be signed in to change notification settings - Fork 2
/
codolike.php
74 lines (57 loc) · 2.44 KB
/
codolike.php
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
<?php
/**
* CodoLike
* @copyright Copyright (c) 2015 Riccardo Tempesta (http://www.riccardotempesta.com)
*/
require_once('adapters/Codoforum.php');
require_once('arg.php');
require_once('server/codolike.php');
$codoLikeAdapter = new CodoLikeAdapter();
$codoLikeAdapter->setup_tables();
codolike::$path = $codoLikeAdapter->get_abs_path();
codolike::$db_prefix = PREFIX . 'codo_';
codolike::$like_post_path = RURI . 'codolike/like';
codolike::$like_update_path = RURI . 'codolike/update';
codolike::$db = \DB::getPDO();
function codolike_add_assets() {
$codoLikeAdapter = new CodoLikeAdapter();
$codoLikeAdapter->add_css(codolike::$path . "client/css/app.css");
//$codoLikeAdapter->add_js("http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js");
$codoLikeAdapter->add_js(codolike::$path . "client/js/app.js");
}
function codolike_like_js() {
include("block/like_js.php");
}
function codolike_body_start() {
include('block/body_start.php');
}
function codolike_after_notify_insert() {
$notifier = new \CODOF\Forum\Notification\Notifier();
$res = codolike::$db->query(
"SELECT "
."q.id, q.nid, t.data, q.type "
."FROM ".PREFIX."codo_notify_queue as q "
."INNER JOIN codo_notify_text as t on "
."q.nid=t.id "
."where q.type='new_like'");
$queue = $res->fetchAll();
foreach ($queue as $queuedLike) {
$data = json_decode($queuedLike['data'], true);
$notifier->notify(array($data['puid']), $queuedLike['type'], $queuedLike['nid']);
// Automatically dequeue notification
codolike::$db->query("delete from ".PREFIX."codo_notify_queue where id=".intval($queuedLike['id']));
}
}
\CODOF\Hook::add('block_body_start', 'codolike_body_start');
\CODOF\Hook::add('block_topic_info_after', 'codolike_like_js');
\CODOF\Hook::add('tpl_before_forum_topic', 'codolike_add_assets');
\CODOF\Hook::add('after_like_post', 'codolike_after_notify_insert'); // This runs just before item queue deletion
//\CODOF\Hook::add('on_cron_notify_new_like', array(new \CODOF\Forum\Notification\Notifier, 'dequeueNotify'));
dispatch("codolike/like", function(){
$codoLikeAdapter = new CodoLikeAdapter();
echo json_encode(codolike_add_like($codoLikeAdapter->get_user(), $_GET['id']));
});
dispatch("codolike/update", function(){
$codoLikeAdapter = new CodoLikeAdapter();
echo json_encode(codolike_get_likes($codoLikeAdapter->get_user()->id, $_GET['ids']));
});