-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
236 lines (204 loc) · 8.21 KB
/
init.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
// Kleeja Plugin
// KJ_COMMENT
// Version: 1.0
// Developer: Kleeja Team
// Prevent illegal run
if (! defined('IN_PLUGINS_SYSTEM'))
{
exit();
}
// Plugin Basic Information
$kleeja_plugin['kj_comment']['information'] = [
// The casual name of this plugin, anything can a human being understands
'plugin_title' => [
'en' => 'KJ Comment',
'ar' => 'تعليقات كليجا'
],
// Who wrote this plugin?
'plugin_developer' => 'Kleeja Team',
// This plugin version
'plugin_version' => '1.0.1',
// Explain what is this plugin, why should I use it?
'plugin_description' => [
'en' => 'Add Comments To Files',
'ar' => 'إضافة تعليقات على الملفات'
],
// Min version of Kleeja that's requiered to run this plugin
'plugin_kleeja_version_min' => '3.1.4',
// Max version of Kleeja that support this plugin, use 0 for unlimited
'plugin_kleeja_version_max' => '3.9',
// Should this plugin run before others?, 0 is normal, and higher number has high priority
'plugin_priority' => 0
];
//after installation message, you can remove it, it's not requiered
$kleeja_plugin['kj_comment']['first_run']['ar'] = '
مكون إضافي لإضافة تعليقات للملف ، شكرًا لك على استخدام هذه الإضافة <br>
';
$kleeja_plugin['kj_comment']['first_run']['en'] = '
a plugin to add comments for each file , thank you to use this plugin <br>
Kleeja Team :)
';
// Plugin Installation function
$kleeja_plugin['kj_comment']['install'] = function ($plg_id) {
global $SQL , $dbprefix;
$SQL->query(
"CREATE TABLE IF NOT EXISTS `{$dbprefix}comments` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user` int(11) NOT NULL,
`file_id` int(11) NOT NULL,
`comment` TEXT NOT NULL,
`time` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;"
);
add_olang([
'NO_4_GUEST' => 'You can\'t add comments as guest',
'COMNTS' => 'Comments',
'COMNT' => 'Comment',
'ADD_COMNT' => 'Add a Comment',
'R_COMMENT_MANAGER' => 'Comment Manager'
],
'en', $plg_id);
add_olang([
'NO_4_GUEST' => 'لا يمكنك إضافة تعليقات كضيف',
'COMNTS' => 'تعليقات',
'COMNT' => 'تعليق',
'ADD_COMNT' => 'اضف تعليق',
'R_COMMENT_MANAGER' => 'مدير التعليقات'
],
'ar', $plg_id);
};
//Plugin update function, called if plugin is already installed but version is different than current
$kleeja_plugin['kj_comment']['update'] = function ($old_version, $new_version) {
};
// Plugin Uninstallation, function to be called at unistalling
$kleeja_plugin['kj_comment']['uninstall'] = function ($plg_id) {
delete_olang(null, ['ar', 'en'], $plg_id);
};
// Plugin functions
$kleeja_plugin['kj_comment']['functions'] = [
'b4_showsty_downlaod_id_filename' => function ($args) {
global $tpl , $usrcp;
$file_info = $args['file_info'];
$comments = [];
$kj_comment_file_id = $args['file_info']['id'];
if (! $file_info)
{
return;
}
define('display_comments', true);
global $SQL , $dbprefix , $config;
$comments_query = $SQL->build(
[
'SELECT' => 'c.id , c.user , c.comment , c.file_id , c.time , u.name',
'FROM' => $dbprefix . 'comments c',
'JOINS' =>
[
[
'INNER JOIN' => "{$dbprefix}users u",
'ON' => 'c.user = u.id'
]
],
'WHERE' => 'c.file_id = ' . $file_info['id'],
'ORDER BY' => 'c.id DESC'
]
);
if ($SQL->num_rows($comments_query))
{
while ($cmnt = $SQL->fetch($comments_query))
{
$cmnt['time'] = kleeja_date($cmnt['time']);
$cmnt['user_link'] = $config['siteurl'] . ($config['mod_writer'] ? 'fileuser-' . $cmnt['user'] . '.html' : 'ucp.php?go=fileuser&id=' . $cmnt['user']);
if ($cmnt['user'] == $usrcp->id() || $usrcp->group_id() == 1)
{
$cmnt['del_btn'] = true; // display delete btn if the user is comment auther or admin
}
else
{
$cmnt['del_btn'] = false;
}
$comments[] = $cmnt;
}
}
return compact('comments', 'kj_comment_file_id');
},
'print_Saafooter_func' => function ($args) {
global $tpl , $config , $usrcp;
if (! defined('IN_DOWNLOAD') || ! defined('display_comments'))
{
return;
}
$formAction = $config['siteurl'] . 'ucp.php?go=comment&action=add';
$delFormAction = $config['siteurl'] . 'ucp.php?go=comment&action=del';
$form_key = kleeja_add_form_key('comment_for_' . $usrcp->name());
$is_login = $usrcp->name();
$tpl->assign('is_login', $is_login);
$tpl->assign('formAction', $formAction);
$tpl->assign('delFormAction', $delFormAction);
$tpl->assign('form_key', $form_key);
$theFooter = $args['footer'];
$footer = $tpl->display('comment', dirname(__FILE__));
$footer .= $theFooter;
return compact('footer');
} ,
'default_usrcp_page' => function ($args) {
global $usrcp , $lang , $SQL , $dbprefix , $config;
if (g('go') == 'comment')
{
// all actions in this hook is only for members
if (! $usrcp->name())
{
return;
}
if (! kleeja_check_form_key('comment_for_' . $usrcp->name()))
{
kleeja_err($lang['INVALID_FORM_KEY']);
exit;
}
if (g('action') == 'add')
{
if (ip('submit') && ip('file_id') && ip('comment') && ! empty(p('file_id')) && ! empty(p('comment')))
{
$SQL->build(
[
'INSERT' => 'user , file_id , comment , time',
'INTO' => $dbprefix . 'comments',
'VALUES' => implode(' , ', [$usrcp->id() , p('file_id') , "'" . $SQL->real_escape(str_replace(['"' , "'"], ['"' ,'''], p('comment'))) . "'" , time()])
]
);
redirect($config['siteurl'] . 'do.php?id=' . p('file_id'));
exit;
}
}
elseif (g('action') == 'del')
{
if (ip('del') && ip('file_id') && ip('comment_id'))
{
$SQL->build([
'DELETE' => $dbprefix . 'comments',
'WHERE' => 'file_id = ' . p('file_id') . ' AND id = ' . p('comment_id') . ($usrcp->group_id() != 1 ? ' AND user = ' . $usrcp->id() : '')
]);
if (ip('admin_form'))
{
redirect($config['siteurl'] . 'admin/index.php?cp=comment_manager');
exit;
}
redirect($config['siteurl'] . 'do.php?id=' . p('file_id'));
exit;
}
}
}
} ,
'begin_admin_page' => function ($args) {
$adm_extensions = $args['adm_extensions'];
$ext_icons = $args['ext_icons'];
$adm_extensions[] = 'comment_manager';
$ext_icons['comment_manager'] = 'comment';
return compact('adm_extensions', 'ext_icons');
},
'not_exists_comment_manager' => function() {
$include_alternative = dirname(__FILE__) . '/comment_manager.php';
return compact('include_alternative');
},
];