· 6 years ago · Sep 12, 2019, 05:16 PM
1<?php
2
3/**
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2015 Mohamed Benjelloun
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26// Disallow direct access to this file for security reasons
27if (!defined("IN_MYBB")) {
28 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
29}
30
31/* ajax */
32$plugins->add_hook("xmlhttp", array(MyProfileComments::get_instance(), "xmlhttp"));
33
34/* no ajax */
35$plugins->add_hook("misc_start", array(MyProfileComments::get_instance(), "misc_start"));
36
37/* admincp */
38$plugins->add_hook("admin_formcontainer_end", array(MyProfileComments::get_instance(), "admin_formcontainer_end"));
39$plugins->add_hook("admin_user_groups_edit_commit", array(MyProfileComments::get_instance(), "admin_user_groups_edit_commit"));
40
41/* modcp */
42/* - next version $plugins->add_hook("modcp_nav", array(MyProfileComments::get_instance(), "modcp_nav"));
43 $plugins->add_hook("modcp_start", array(MyProfileComments::get_instance(), "modcp_start")); */
44$plugins->add_hook("modcp_reports_report", array(MyProfileComments::get_instance(), "modcp_reports_report"));
45
46/* usercp */
47$plugins->add_hook("usercp_do_options_end", array(MyProfileComments::get_instance(), "usercp_do_options_end"));
48$plugins->add_hook("usercp_options_start", array(MyProfileComments::get_instance(), "usercp_options_start"));
49
50/* report */
51$plugins->add_hook("report_start", array(MyProfileComments::get_instance(), "report_start"));
52$plugins->add_hook("report_end", array(MyProfileComments::get_instance(), "report_end"));
53$plugins->add_hook("report_type", array(MyProfileComments::get_instance(), "report_type"));
54
55/* member profile */
56$plugins->add_hook("member_profile_end", array(MyProfileComments::get_instance(), "member_profile_end"));
57
58/* comment notification */
59$plugins->add_hook("global_start", array(MyProfileComments::get_instance(), "global_start"));
60$plugins->add_hook("global_intermediate", array(MyProfileComments::get_instance(), "global_intermediate"));
61
62/* permission viewer */
63$plugins->add_hook("tools_permissionviewer_general_zero", array(MyProfileComments::get_instance(), "tools_permissionviewer_general_zero"));
64
65
66/* A custom MyAlerts Formatter for MyProfile Comments */
67if (class_exists("MybbStuff_MyAlerts_Formatter_AbstractFormatter")) {
68
69 class MyProfileCommentsMyAlertsFormatter extends MybbStuff_MyAlerts_Formatter_AbstractFormatter {
70
71 /**
72 * Format an alert into it's output string to be used in both the main alerts listing page and the popup.
73 *
74 * @param MybbStuff_MyAlerts_Entity_Alert $alert The alert to format.
75 * @return string The formatted alert string.
76 */
77 public function formatAlert(MybbStuff_MyAlerts_Entity_Alert $alert, array $outputAlert) {
78 global $lang;
79 $from_user = get_user($alert->getFromUserId());
80 $this->buildShowLink($alert);
81 return $lang->sprintf($lang->myprofile_alert, format_name(htmlspecialchars_uni($from_user["username"]), $from_user["usergroup"], $from_user["displaygroup"]));
82 }
83
84 /**
85 * Init function called before running formatAlert(). Used to load language files and initialize other required resources.
86 *
87 * @return void
88 */
89 public function init() {
90 MyProfileUtils::lang_load_myprofile();
91 }
92
93 public function buildShowLink(MybbStuff_MyAlerts_Entity_Alert $alert) {
94 $alertContent = $alert->getExtraDetails();
95 return MyProfileComments::get_instance()->build_comment_link($alertContent["cid"]);
96 }
97
98 /**
99 * Let's not get lost in between things, this will return the alert type code
100 */
101 public static function alert_type_code() {
102 return "myprofilecomments";
103 }
104
105 }
106
107}
108
109class MyProfileComments {
110
111 private static $instance = null;
112
113 /* upgrading from version 0.3 */
114
115 public function upgrade_0_3() {
116 global $db;
117 $update_array = array("optionscode" => "select
1182=2
1193=3
1204=4
1215=5
1226=6
1237=7
1248=8
1259=9
12610=10
12715=15
12825=25
12930=30");
130 $db->update_query("settings", $update_array, "name='mpcommentsperpage'", "1");
131 rebuild_settings();
132 }
133
134 public function install() {
135 global $db, $cache, $lang;
136 MyProfileUtils::lang_load_config_myprofile();
137 $tables = array();
138 $collation = $db->build_create_table_collation();
139
140 if (!$db->table_exists("myprofilecomments")) {
141 $tables[] = "CREATE TABLE " . TABLE_PREFIX . "myprofilecomments (
142 `cid` int unsigned NOT NULL auto_increment,
143 `userid` int unsigned NOT NULL,
144 `cuid` int unsigned NOT NULL,
145 `message` text NOT NULL,
146 `approved` int(1) NOT NULL default '0',
147 `isprivate` int(1) NOT NULL default '0',
148 `time` varchar(10) NOT NULL,
149 PRIMARY KEY (`cid`)
150 ) ENGINE=MyISAM{$collation};";
151 }
152
153 foreach ($tables as $table) {
154 $db->write_query($table);
155 }
156
157 if (!$db->field_exists("canmanagecomments", "usergroups")) {
158 $db->add_column("usergroups", "canmanagecomments", "int(1) NOT NULL default '0'");
159 }
160 if (!$db->field_exists("cansendcomments", "usergroups")) {
161 $db->add_column("usergroups", "cansendcomments", "int(1) NOT NULL default '1'");
162 }
163 if (!$db->field_exists("caneditowncomments", "usergroups")) {
164 $db->add_column("usergroups", "caneditowncomments", "int(1) NOT NULL default '1'");
165 }
166 if (!$db->field_exists("candeleteowncomments", "usergroups")) {
167 $db->add_column("usergroups", "candeleteowncomments", "int(1) NOT NULL default '0'");
168 }
169 if (!$db->field_exists("commentsperday", "usergroups")) {
170 $db->add_column("usergroups", "commentsperday", "int unsigned NOT NULL DEFAULT 0");
171 }
172
173 /* giving "manage" access to administrators, and delete own comments */
174 $db->update_query("usergroups", array("canmanagecomments" => "1", "candeleteowncomments" => "1"), "gid='4'");
175 /* revoking commenting + editing access from guests, banned and awaiting activation users */
176 $db->update_query("usergroups", array("cansendcomments" => "0", "caneditowncomments" => "0"), "gid IN ('1', '5', '7')");
177
178 $cache->update_usergroups();
179
180 if (!$db->field_exists("mpcommentsopen", "users")) {
181 $db->add_column("users", "mpcommentsopen", "int(10) NOT NULL default '1'");
182 }
183
184 if (!$db->field_exists("mpcommentnotification", "users")) {
185 $db->add_column("users", "mpcommentnotification", "int(10) NOT NULL default '1'");
186 }
187
188 if (!$db->field_exists("mpwhocancomment", "users")) {
189 $db->add_column("users", "mpwhocancomment", "int(10) NOT NULL default '2'"); // 0=no one, 1=friendlist, 2=everyone
190 }
191
192 if (!$db->field_exists("mpnewcomments", "users")) {
193 $db->add_column("users", "mpnewcomments", "int(10) NOT NULL default '0'");
194 }
195
196 if (!$db->field_exists("mpcommentsapprove", "users")) {
197 $db->add_column("users", "mpcommentsapprove", "int(10) NOT NULL default '0'");
198 }
199
200
201 $settinggroups = array(
202 "name" => "myprofilecomments",
203 "title" => $lang->mp_myprofile_comments,
204 "description" => $lang->mp_myprofile_comments_desc,
205 "isdefault" => 0
206 );
207
208 $gid = MyProfileUtils::insert_settinggroups($settinggroups);
209
210 $settings = array();
211 $settings[] = array(
212 "name" => "mpcommentsenabled",
213 "title" => $lang->mp_myprofile_comments_enabled,
214 "description" => $lang->mp_myprofile_comments_enabled_desc,
215 "optionscode" => "yesno",
216 "value" => "1",
217 "gid" => $gid
218 );
219
220 $settings[] = array(
221 "name" => "mpcommentsajaxenabled",
222 "title" => $lang->mp_myprofile_comments_ajax_enabled,
223 "description" => $lang->mp_myprofile_comments_ajax_enabled_desc,
224 "optionscode" => "yesno",
225 "value" => "1",
226 "gid" => $gid
227 );
228
229 $settings[] = array(
230 "name" => "mpcommentsnotification",
231 "title" => $lang->mp_myprofile_comments_notification,
232 "description" => $lang->mp_myprofile_comments_notification_desc,
233 "optionscode" => "select
234myalertsoralertbar={$lang->mp_myprofile_comments_notification_myalerts_alertbar}
235myalerts={$lang->mp_myprofile_comments_notification_myalerts}
236alertbar={$lang->mp_myprofile_comments_notification_alertbar}
237none={$lang->mp_myprofile_comments_notification_none}",
238 "value" => "myalertsoralertbar",
239 "gid" => $gid
240 );
241
242 $settings[] = array(
243 "name" => "mpcommentsperpage",
244 "title" => $lang->mp_myprofile_comments_perpage,
245 "description" => $lang->mp_myprofile_comments_perpage_desc,
246 "optionscode" => "select
2472=2
2483=3
2494=4
2505=5
2516=6
2527=7
2538=8
2549=9
25510=10
25615=15
25725=25
25830=30",
259 "value" => "10",
260 "gid" => $gid
261 );
262
263 $settings[] = array(
264 "name" => "mpcommentsminlength",
265 "title" => $lang->mp_myprofile_comments_min_length,
266 "description" => $lang->mp_myprofile_comments_min_length_desc,
267 "optionscode" => "text",
268 "value" => "2",
269 "gid" => $gid
270 );
271
272 $settings[] = array(
273 "name" => "mpcommentsmaxlength",
274 "title" => $lang->mp_myprofile_comments_max_length,
275 "description" => $lang->mp_myprofile_comments_max_length_desc,
276 "optionscode" => "text",
277 "value" => "5000",
278 "gid" => $gid
279 );
280
281 $settings[] = array(
282 "name" => "mpcommentsignoreenabled",
283 "title" => $lang->mp_myprofile_comments_ignore,
284 "description" => $lang->mp_myprofile_comments_ignore_desc,
285 "optionscode" => "yesno",
286 "value" => "1",
287 "gid" => $gid
288 );
289
290 $settings[] = array(
291 "name" => "mpcommentstimeedit",
292 "title" => $lang->mp_myprofile_comments_edit_time,
293 "description" => $lang->mp_myprofile_comments_edit_time_desc,
294 "optionscode" => "select
2950=0
2965=5
29710=10
29815=15
29920=20
30030=30
30145=45
30260=60",
303 "value" => "0",
304 "gid" => $gid
305 );
306
307 $settings[] = array(
308 "name" => "mpcommentstimeflood",
309 "title" => $lang->mp_myprofile_comments_flood_time,
310 "description" => $lang->mp_myprofile_comments_flood_time_desc,
311 "optionscode" => "select
3120=0
3135=5
31410=10
31515=15
31620=20
31730=30
31845=45
31960=60",
320 "value" => "20",
321 "gid" => $gid
322 );
323
324 $settings[] = array(
325 "name" => "mpcommentsstatusenabled",
326 "title" => $lang->mp_myprofile_comments_status_enabled,
327 "description" => $lang->mp_myprofile_comments_status_enabled_desc,
328 "optionscode" => "yesno",
329 "value" => "1",
330 "gid" => $gid
331 );
332
333 $settings[] = array(
334 "name" => "mpcommentsallowimg",
335 "title" => $lang->mp_myprofile_comments_allow_img,
336 "description" => $lang->mp_myprofile_comments_allow_img_desc,
337 "optionscode" => "yesno",
338 "value" => "1",
339 "gid" => $gid
340 );
341
342 $settings[] = array(
343 "name" => "mpcommentsallowvideo",
344 "title" => $lang->mp_myprofile_comments_allow_video,
345 "description" => $lang->mp_myprofile_comments_allow_video_desc,
346 "optionscode" => "yesno",
347 "value" => "1",
348 "gid" => $gid
349 );
350
351 $settings[] = array(
352 "name" => "mpcommentsallowsmilies",
353 "title" => $lang->mp_myprofile_comments_allow_smilies,
354 "description" => $lang->mp_myprofile_comments_allow_smilies_desc,
355 "optionscode" => "yesno",
356 "value" => "1",
357 "gid" => $gid
358 );
359
360 $settings[] = array(
361 "name" => "mpcommentsallowmycode",
362 "title" => $lang->mp_myprofile_comments_allow_mycode,
363 "description" => $lang->mp_myprofile_comments_allow_mycode_desc,
364 "optionscode" => "yesno",
365 "value" => "1",
366 "gid" => $gid
367 );
368
369 $settings[] = array(
370 "name" => "mpcommentsfilterbadwords",
371 "title" => $lang->mp_myprofile_comments_filter_badwords,
372 "description" => $lang->mp_myprofile_comments_filter_badwords_desc,
373 "optionscode" => "yesno",
374 "value" => "1",
375 "gid" => $gid
376 );
377
378 $settings[] = array(
379 "name" => "mpcommentsallowhtml",
380 "title" => $lang->mp_myprofile_comments_allow_html,
381 "description" => $lang->mp_myprofile_comments_allow_html_desc,
382 "optionscode" => "yesno",
383 "value" => "0",
384 "gid" => $gid
385 );
386
387 $settings[] = array(
388 "name" => "mpcommentsshowwysiwyg",
389 "title" => $lang->mp_myprofile_comments_show_wysiwyg,
390 "description" => $lang->mp_myprofile_comments_show_wysiwyg_desc,
391 "optionscode" => "yesno",
392 "value" => "1",
393 "gid" => $gid
394 );
395
396 $settings[] = array(
397 "name" => "mpcommentsclosedonbanned",
398 "title" => $lang->mp_myprofile_comments_closed_on_banned,
399 "description" => $lang->mp_myprofile_comments_closed_on_banned_desc,
400 "optionscode" => "yesno",
401 "value" => "1",
402 "gid" => $gid
403 );
404
405 $settings[] = array(
406 "name" => "mpcommentsshowstats",
407 "title" => $lang->mp_myprofile_comments_show_stats,
408 "description" => $lang->mp_myprofile_comments_show_stats_desc,
409 "optionscode" => "yesno",
410 "value" => "1",
411 "gid" => $gid
412 );
413
414 MyProfileUtils::insert_settings($settings);
415 }
416
417 public function is_installed() {
418 global $db;
419 return $db->table_exists("myprofilecomments");
420 }
421
422 public function uninstall() {
423 global $db, $cache;
424
425 $db->drop_table("myprofilecomments");
426
427 if ($db->field_exists("canmanagecomments", "usergroups")) {
428 $db->drop_column("usergroups", "canmanagecomments");
429 }
430
431 if ($db->field_exists("cansendcomments", "usergroups")) {
432 $db->drop_column("usergroups", "cansendcomments");
433 }
434
435 if ($db->field_exists("caneditowncomments", "usergroups")) {
436 $db->drop_column("usergroups", "caneditowncomments");
437 }
438
439 if ($db->field_exists("candeleteowncomments", "usergroups")) {
440 $db->drop_column("usergroups", "candeleteowncomments");
441 }
442 if ($db->field_exists("commentsperday", "usergroups")) {
443 $db->drop_column("usergroups", "commentsperday");
444 }
445
446 $cache->update_usergroups();
447
448 if ($db->field_exists("mpcommentsopen", "users")) {
449 $db->drop_column("users", "mpcommentsopen");
450 }
451
452 if ($db->field_exists("mpcommentnotification", "users")) {
453 $db->drop_column("users", "mpcommentnotification");
454 }
455
456 if ($db->field_exists("mpwhocancomment", "users")) {
457 $db->drop_column("users", "mpwhocancomment");
458 }
459
460 if ($db->field_exists("mpnewcomments", "users")) {
461 $db->drop_column("users", "mpnewcomments");
462 }
463
464 if ($db->field_exists("mpcommentsapprove", "users")) {
465 $db->drop_column("users", "mpcommentsapprove");
466 }
467
468 $settings = array(
469 "mpcommentsenabled",
470 "mpcommentsajaxenabled",
471 "mpcommentsnotification",
472 "mpcommentsperpage",
473 "mpcommentsminlength",
474 "mpcommentsmaxlength",
475 "mpcommentsignoreenabled",
476 "mpcommentstimeedit",
477 "mpcommentsstatusenabled",
478 "mpcommentsallowimg",
479 "mpcommentsallowvideo",
480 "mpcommentsallowsmilies",
481 "mpcommentsallowmycode",
482 "mpcommentsfilterbadwords",
483 "mpcommentsallowhtml",
484 "mpcommentsshowwysiwyg",
485 "mpcommentsclosedonbanned",
486 "mpcommentsshowstats"
487 );
488 MyProfileUtils::delete_settings($settings);
489
490 $settinggroups = array(
491 "myprofilecomments"
492 );
493 MyProfileUtils::delete_settinggroups($settinggroups);
494 }
495
496 public function activate() {
497 global $db, $cache;
498 require_once MYBB_ROOT . "inc/adminfunctions_templates.php";
499
500 $templates = array();
501
502 $templates["myprofile_comments_content"] = '{$comments_form}
503{$comment_form_script}
504{$comments_table}';
505
506 $templates["myprofile_comments_form"] = '<form action="misc.php" method="post" name="comments-form" id="comments-form">
507<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
508<input type="hidden" name="action" value="comments-add" />
509<input type="hidden" name="memberuid" value="{$memprofile[\'uid\']}" />
510<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
511<tr>
512<td class="thead" colspan="2"><strong>{$lang->mp_profile_comments_add_comment}</strong></td>
513</tr>
514{$status}
515<tr>
516<td class="trow2">
517<textarea id="message" name="message" rows="10" cols="70" tabindex="2"></textarea>
518{$codebuttons}
519</td>
520</tr>
521<tr>
522<td class="trow2">
523<input id="submit_comment" type="submit" class="button" name="submit" value="{$lang->mp_profile_comments_add_comment}" tabindex="3" />
524<span id="spinner_span"></span>
525</td>
526</tr>
527{$modoptions}
528</table>
529</form>';
530
531 $templates["myprofile_comments_form_modoptions"] = '<tr>
532<td class="trow2">
533<span><strong>{$lang->mp_comments_moderation} : </strong></span>
534<button type="button" class="button comment-action comments-delete-all">{$lang->mp_comments_action_delete_all_comments}</button>
535<span class="spinner_delete_all_span"></span>
536</td>
537</tr>';
538
539 $templates["myprofile_comments_stats"] = '<tr>
540<td class="trow2"><strong>{$lang->mp_profile_comments_comments}</strong></td>
541<td class="trow2">{$stats_total} ({$stats_sent} {$lang->mp_comments_stats_sent} | {$stats_received} {$lang->mp_comments_stats_received})</td>
542</tr>';
543
544 $templates["myprofile_comments_form_script"] = '<script>
545lang.mp_comments_comment_wrong_length = "{$lang->mp_comments_comment_wrong_length}";
546lang.mp_comments_confirm_delete = "{$lang->mp_comments_confirm_delete}";
547lang.mp_comments_confirm_delete_all = "{$lang->mp_comments_confirm_delete_all}";
548lang.mp_comments_comment_approved_successfully = "{$lang->mp_comments_comment_approved_successfully}";
549lang.mp_comments_comment_added_successfully = "{$lang->mp_comments_comment_added_successfully}";
550lang.mp_comments_comment_deleted_successfully = "{$lang->mp_comments_comment_deleted_successfully}";
551lang.mp_comments_comments_deleted_successfully = "{$lang->mp_comments_comments_deleted_successfully}";
552lang.mp_comments_comment_edited_successfully = "{$lang->mp_comments_comment_edited_successfully}";
553
554MyProfile.memberUid = {$comments_memberuid};
555MyProfile.ajax = {$comments_ajax};
556MyProfile.commentsMinLength = {$comments_minlength};
557MyProfile.commentsMaxLength = {$comments_maxlength};
558MyProfile.commentsSCEditor = {$comments_sceditor};
559MyProfile.commentsPage = {$comments_page};
560</script>';
561
562 $templates["myprofile_comments_form_status"] = '<tr>
563<td class="trow1">
564<span>{$lang->mp_comments_comment_status} : </span>
565<select class="{$status_select_class}" name="isprivate">
566<option value="0" {$comment_public_selected}>{$lang->mp_comments_comment_public}</option>
567<option value="1" {$comment_private_selected}>{$lang->mp_comments_comment_private}</option>
568</select>
569</td>
570</tr>';
571
572 $templates["myprofile_comments_table"] = '{$comments_separator}
573<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
574<tr>
575<td class="thead" colspan="2"><strong>{$lang->mp_profile_comments_comments} ({$lang->mp_profile_comments_total} <span id="comments-total">{$comments_total}</span>{$useroptions})</strong></td>
576</tr>
577<tr class="comments-pagination">
578<td colspan="2" {$comments_pagination_style}>{$comments_pagination}</td>
579</tr>
580<tbody class="comments-content">
581{$comments_content}
582</tbody>
583<tr class="comments-pagination">
584<td colspan="2" {$comments_pagination_style}>{$comments_pagination}</td>
585</tr>
586</table>
587<br />';
588
589 $templates["myprofile_comments_comment"] = '<tr width="100%" data-cid="{$comment[\'cid\']}">
590<td class="trow2 {$trow_class}" rowspan="2" style="text-align: center; vertical-align: top;" data-cid="{$comment[\'cid\']}">
591<img src="{$avatar_src}" {$avatar_width_height} alt />
592</td>
593<td style="height: 20px;" class="trow1 {$trow_class}" width="100%" data-cid="{$comment[\'cid\']}">
594{$profile_link} <small style="font-size: 10px;">({$date} - {$time}) <em>{$comment_private}</em></small><br />
595<span style="font-size: 10px;" data-cid="{$comment[\'cid\']}">
596{$comments_approve}
597{$comments_reply}
598{$comments_edit}
599{$comments_delete}
600{$comments_report}
601</span>
602</td>
603</tr>
604<tr>
605<td class="trow2 comment_message scaleimages {$trow_class}" style="max-width: 400px; overflow: hidden;" data-cid="{$comment[\'cid\']}">
606{$message}
607</td>
608</tr>';
609
610 $templates["myprofile_comments_no_comment"] = '<tr width="100%">
611<td class="trow2">{$lang->mp_comments_no_comment_to_display}</td>
612</tr>';
613
614 $templates["myprofile_comments_comment_approve"] = '<form action="misc.php" method="post" style="display: inline;">
615<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
616<input type="hidden" name="action" value="comments-approve" />
617<input type="hidden" name="cid" value="{$comment[\'cid\']}" />
618<input type="hidden" name="memberuid" value="{$comment[\'userid\']}" />
619<button class="comments-approve comments-action button" style="font-size: 11px;">{$lang->mp_comments_action_approve}</button>
620</form>';
621
622 $templates["myprofile_comments_comment_reply"] = '<form action="{$mybb->settings[\'bburl\']}/member.php" method="get" style="display: inline;">
623<input type="hidden" name="action" value="profile" />
624<input type="hidden" name="uid" value="{$commentor_uid}" />
625<button style="font-size: 11px;">{$lang->mp_comments_action_reply}</button>
626</form>';
627
628 $templates["myprofile_comments_comment_edit"] = '<button class="comments-edit comments-action button" style="font-size: 11px;">{$lang->mp_comments_action_edit}</button>';
629
630 $templates["myprofile_comments_comment_delete"] = '<form action="misc.php" method="post" style="display: inline;">
631<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
632<input type="hidden" name="action" value="comments-delete" />
633<input type="hidden" name="cid" value="{$comment[\'cid\']}" />
634<input type="hidden" name="memberuid" value="{$comment[\'userid\']}" />
635<button class="comments-delete comments-action button" style="font-size: 11px;">{$lang->mp_comments_action_delete}</button>
636</form>';
637
638 $templates["myprofile_comments_comment_report"] = '<button class="comments-report comments-action button" style="font-size: 11px;">{$lang->mp_comments_action_report}</button>';
639
640 $templates["myprofile_comments_report_reasons"] = '<tr>
641<td class="trow1" align="left" style="width: 25%"><span class="smalltext"><strong>{$lang->report_reason}</strong></span></td>
642<td class="trow1" align="left">
643<select name="reason" id="report_reason">
644<option value="rules">{$lang->report_reason_rules}</option>
645<option value="bad">{$lang->report_reason_bad}</option>
646<option value="spam">{$lang->report_reason_spam}</option>
647<option value="other">{$lang->report_reason_other}</option>
648</select>
649</td>
650</tr>
651<tr id="reason">
652<td class="trow2"> </td>
653<td class="trow2" align="left">
654<div>{$lang->report_reason_other_description}</div>
655<input type="text" class="textbox" name="comment" size="40" maxlength="250" />
656</td>
657</tr>
658<tr>
659 <td colspan="2" class="tfoot"><input type="submit" class="button" value="{$report_title}" /></td>
660</tr>';
661
662 $templates["myprofile_comments_usercp"] = '<legend><strong>{$lang->mp_my_profile}</strong></legend>
663<table cellspacing="0" cellpadding="2">
664<tr>
665<td valign="top" width="1"><input type="checkbox" class="checkbox" name="mpcommentsopen" id="mpcommentsopen" value="1" {$mpcommentsopen} /></td>
666<td><span class="smalltext"><label for="mpcommentsopen">{$lang->mp_comments_open}</label></span></td>
667</tr>
668<tr>
669<td colspan="2"><span class="smalltext">{$lang->mp_who_can_leave_comments}</span></td>
670</tr>
671<tr>
672<td colspan="2">
673<select name="mpwhocancomment" id="mpwhocancomment">
674<option value="0" {$nobodycanleavecomments}>{$lang->mp_nobody_can_leave_comments}</option>
675<option value="1" {$friendlistcanleavecomment}>{$lang->mp_friendlist_can_leave_comments}</option>
676<option value="2" {$anyonecanleavecomments}>{$lang->mp_anyone_can_leave_comments}</option>
677</td>
678</tr>
679<tr>
680<td valign="top" width="1"><input type="checkbox" class="checkbox" name="mpcommentsapprove" id="mpcommentsapprove" value="1" {$mpcommentsapprove} /></td>
681<td><span class="smalltext"><label for="mpcommentsapprove">{$lang->mp_comments_approve}</label></span></td>
682</tr>
683<tr>
684<td valign="top" width="1"><input type="checkbox" class="checkbox" name="mpcommentnotification" id="mpcommentnotification" value="1" {$mpcommentnotification} /></td>
685<td><span class="smalltext"><label for="mpcommentnotification">{$lang->mp_comments_notification}</label></span></td>
686</tr>
687</table>
688</fieldset>
689<br />
690<fieldset class="trow2">';
691
692 $templates["myprofile_modcp_nav_comments"] = '<tr><td class="trow1 smalltext"><a href="modcp.php?action=myprofilecomments" class="modcp_nav_item modcp_nav_ipsearch">{$lang->mp_myprofile_comments}</a></td></tr>';
693
694 $templates["myprofile_comments_edit"] = '
695<div class="modal" id="modal-edit-comments">
696<div style="overflow-y: auto; max-height: 400px;" class="modal_2">
697<form action="misc.php" method="post" id="comments-edit-form" name="comments-edit-form">
698<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
699<input type="hidden" name="action" value="comments-do-edit" />
700<input type="hidden" name="memberuid" value="{$memprofile[\'uid\']}" />
701<input type="hidden" name="no_modal" value="1" />
702<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
703<tr>
704 <td class="thead" colspan="2"><strong>{$lang->mp_profile_comments_edit_comment}</strong></td>
705</tr>
706{$status}
707<tr>
708<td class="trow2">
709<textarea id="message_edit" name="message_edit" rows="10" cols="70" tabindex="2"></textarea>
710</td>
711</tr>
712<tr>
713<td class="trow2">
714<input type="submit" class="comments-edit-submit button" name="submit" value="{$lang->mp_profile_comments_edit_comment}" tabindex="3" data-cid="{$cid}" />
715</td>
716</tr>
717</table>
718</form>
719<script>
720$(function() {
721var original_text = {$original_text};
722var instance = {};
723//Problem with SCEditor in new object
724//if(MyProfile.commentsSCEditor) {
725//$("#message_edit").sceditor(opt_editor);
726//instance = $("#message_edit").sceditor(\'instance\');
727//}
728//else {
729instance = $("#message_edit");
730//}
731instance.val(original_text.message);
732});
733</script>
734</div>
735</div>';
736
737 $templates["myprofile_comments_alertbar"] = '<div class="pm_alert" id="mp_comments_notice">
738<div class="float_right"><a href="#" id="mp_comments_notice_url" title="{$lang->mp_comments_dismiss_notice}"><img src="{$theme[\'imgdir\']}/dismiss_notice.png" alt="{$lang->mp_comments_dismiss_notice}" title="{$lang->mp_comments_dismiss_notice}"></a></div>
739<div>{$comments_text}</div>
740</div>
741<script>
742$(document).ready(function() {
743 $(document).on("click", "a#mp_comments_notice_url", myprofile_dismiss_alertbar);
744
745 function myprofile_dismiss_alertbar() {
746 $.ajax({
747 "url": rootpath + "/xmlhttp.php",
748 "data": {
749 "action" : "comments-dismiss",
750 "my_post_key" : my_post_key
751 },
752 "type": "POST"
753 });
754 $("#mp_comments_notice").remove();
755 }
756});
757</script>';
758 /* - next version
759 $templates["myprofile_comments_modcp_start"] = '<html>
760 <head>
761 <title>{$mybb->settings[\'bbname\']} - {$lang->warning_logs}</title>
762 {$headerinclude}
763 </head>
764 <body>
765 {$header}
766 <table width="100%" border="0" align="center">
767 <tr>
768 {$modcp_nav}
769 <td valign="top">
770 <form action="modcp.php" method="get">
771 <input type="hidden" name="action" value="warninglogs" />
772 <table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
773 <tr>
774 <td class="thead" colspan="2"><strong>{$lang->filter_warning_logs}</strong></td>
775 </tr>
776 <tr>
777 <td class="trow1" width="25%"><strong>{$lang->filter_warned_user}</strong></td>
778 <td class="trow1" width="75%"><input type="text" name="filter[username]" id="username" value="{$mybb->input[\'filter\'][\'username\']}" class="textbox" /></td>
779 </tr>
780 <tr>
781 <td class="trow2" width="25%"><strong>{$lang->filter_issued_by}</strong></td>
782 <td class="trow2" width="75%"><input type="text" name="filter[mod_username]" value="{$mybb->input[\'filter\'][\'mod_username\']}" class="textbox" /></td>
783 </tr>
784 <tr>
785 <td class="trow1" width="25%"><strong>{$lang->filter_reason}</strong></td>
786 <td class="trow1" width="75%"><input type="text" name="filter[reason]" value="{$mybb->input[\'filter\'][\'reason\']}" class="textbox" /></td>
787 </tr>
788 <tr>
789 <td class="trow2" width="25%"><strong>{$lang->sort_by}</strong></td>
790 <td class="trow2" width="75%">
791 <select name="filter[sortby]">
792 <option value="username"{$sortbysel[\'username\']}>{$lang->username}</option>
793 <option value="issuedby"{$sortbysel[\'issuedby\']}>{$lang->issued_by}</option>
794 <option value="dateline"{$sortbysel[\'dateline\']}>{$lang->issued_date}</option>
795 <option value="expires"{$sortbysel[\'expires\']}>{$lang->expiry_date}</option>
796 </select>
797 {$lang->in}
798 <select name="filter[order]">
799 <option value="asc"{$ordersel[\'asc\']}>{$lang->asc}</option>
800 <option value="desc"{$ordersel[\'desc\']}>{$lang->desc}</option>
801 </select>
802 {$lang->order}
803 </td>
804 </tr>
805 <tr>
806 <td class="trow1" width="25%"><strong>{$lang->per_page}</strong></td>
807 <td class="trow1" width="75%"><input type="text" name="filter[per_page]" value="{$per_page}" class="textbox" /></td>
808 </tr>
809 </table>
810 <br />
811 <div align="center">
812 <input type="submit" class="button" value="{$lang->filter_warning_logs}" />
813 </div>
814 </form>
815 {$multipage}
816 <br />
817 <form action="modcp.php" method="get">
818 <input type="hidden" name="action" value="warninglogs" />
819 <table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
820 <tr>
821 <td class="thead" colspan="2"><strong>{$lang->filter_warning_logs}</strong></td>
822 </tr>
823 <tr>
824 <td class="trow1" width="25%"><strong>{$lang->filter_warned_user}</strong></td>
825 <td class="trow1" width="75%"><input type="text" name="filter[username]" id="username" value="{$mybb->input[\'filter\'][\'username\']}" class="textbox" /></td>
826 </tr>
827 <tr>
828 <td class="trow2" width="25%"><strong>{$lang->filter_issued_by}</strong></td>
829 <td class="trow2" width="75%"><input type="text" name="filter[mod_username]" value="{$mybb->input[\'filter\'][\'mod_username\']}" class="textbox" /></td>
830 </tr>
831 <tr>
832 <td class="trow1" width="25%"><strong>{$lang->filter_reason}</strong></td>
833 <td class="trow1" width="75%"><input type="text" name="filter[reason]" value="{$mybb->input[\'filter\'][\'reason\']}" class="textbox" /></td>
834 </tr>
835 <tr>
836 <td class="trow2" width="25%"><strong>{$lang->sort_by}</strong></td>
837 <td class="trow2" width="75%">
838 <select name="filter[sortby]">
839 <option value="username"{$sortbysel[\'username\']}>{$lang->username}</option>
840 <option value="issuedby"{$sortbysel[\'issuedby\']}>{$lang->issued_by}</option>
841 <option value="dateline"{$sortbysel[\'dateline\']}>{$lang->issued_date}</option>
842 <option value="expires"{$sortbysel[\'expires\']}>{$lang->expiry_date}</option>
843 </select>
844 {$lang->in}
845 <select name="filter[order]">
846 <option value="asc"{$ordersel[\'asc\']}>{$lang->asc}</option>
847 <option value="desc"{$ordersel[\'desc\']}>{$lang->desc}</option>
848 </select>
849 {$lang->order}
850 </td>
851 </tr>
852 <tr>
853 <td class="trow1" width="25%"><strong>{$lang->per_page}</strong></td>
854 <td class="trow1" width="75%"><input type="text" name="filter[per_page]" value="{$per_page}" class="textbox" /></td>
855 </tr>
856 </table>
857 <br />
858 <div align="center">
859 <input type="submit" class="button" value="{$lang->filter_warning_logs}" />
860 </div>
861 </form>
862 </td>
863 </tr>
864 </table>
865 {$footer}
866 <link rel="stylesheet" href="{$mybb->asset_url}/jscripts/select2/select2.css">
867 <script type="text/javascript" src="{$mybb->asset_url}/jscripts/select2/select2.min.js"></script>
868 <script type="text/javascript">
869 <!--
870 if(use_xmlhttprequest == "1")
871 {
872 MyBB.select2();
873 $("#username").select2({
874 placeholder: "{$lang->search_user}",
875 minimumInputLength: 3,
876 maximumSelectionSize: 3,
877 multiple: false,
878 ajax: { // instead of writing the function to execute the request we use Select2\'s convenient helper
879 url: "xmlhttp.php?action=get_users",
880 dataType: \'json\',
881 data: function (term, page) {
882 return {
883 query: term, // search term
884 };
885 },
886 results: function (data, page) { // parse the results into the format expected by Select2.
887 // since we are using custom formatting functions we do not need to alter remote JSON data
888 return {results: data};
889 }
890 },
891 initSelection: function(element, callback) {
892 var value = $(element).val();
893 if (value !== "") {
894 callback({
895 id: value,
896 text: value
897 });
898 }
899 },
900 });
901 }
902 // -->
903 </script>
904 </body>
905 </html>';
906 */
907 MyProfileUtils::insert_templates($templates);
908 find_replace_templatesets("usercp_options", '#' . preg_quote('<legend><strong>{$lang->date_time_options}</strong></legend>') . '#i', '{$myprofile_comments_usercp}<legend><strong>{$lang->date_time_options}</strong></legend>');
909 find_replace_templatesets("modcp_nav_users", "#" . preg_quote('{$nav_editprofile}') . "#i", '{$nav_editprofile}{$nav_myprofilecomments}');
910 find_replace_templatesets("member_profile", "#" . preg_quote('{$modoptions}') . "#i", '{$modoptions}{$myprofile_comments}');
911 find_replace_templatesets("member_profile", "#" . preg_quote('{$warning_level}') . "#i", '{$warning_level}{$myprofile_comments_stats}');
912 find_replace_templatesets('header', "#" . preg_quote('{$unreadreports}') . "#i", '{$unreadreports}{$myprofile_alertbar}');
913 /* let's integrate with MyAlerts 2.0 if it's not already the case */
914 if (MyProfileUtils::myalerts_exists()) {
915 if (MyProfileComments::myalerts_can_integrate()) {
916 $alertTypeManager = MybbStuff_MyAlerts_AlertTypeManager::createInstance($db, $cache);
917 $alertType = new MybbStuff_MyAlerts_Entity_AlertType();
918 $alertType->setCode(MyProfileCommentsMyAlertsFormatter::alert_type_code());
919 $alertType->setEnabled(true);
920 $alertTypeManager->add($alertType);
921 }
922 }
923 }
924
925 public function deactivate() {
926 global $db, $cache;
927 require_once MYBB_ROOT . "inc/adminfunctions_templates.php";
928
929 $templates = array(
930 "myprofile_comments_content",
931 "myprofile_comments_stats",
932 "myprofile_comments_form",
933 "myprofile_comments_form_modoptions",
934 "myprofile_comments_form_script",
935 "myprofile_comments_form_status",
936 "myprofile_comments_table",
937 "myprofile_comments_comment",
938 "myprofile_comments_no_comment",
939 "myprofile_comments_comment_approve",
940 "myprofile_comments_comment_reply",
941 "myprofile_comments_comment_edit",
942 "myprofile_comments_comment_delete",
943 "myprofile_comments_comment_report",
944 "myprofile_comments_report_reasons",
945 "myprofile_comments_usercp",
946 "myprofile_modcp_nav_comments",
947 "myprofile_comments_edit",
948 "myprofile_comments_alertbar",
949 // - next version "myprofile_comments_modcp_start"
950 );
951 MyProfileUtils::delete_templates($templates);
952
953 find_replace_templatesets("member_profile", "#" . preg_quote('{$myprofile_comments}') . "#i", '', 0);
954 find_replace_templatesets("member_profile", "#" . preg_quote('{$myprofile_comments_stats}') . "#i", '', 0);
955 find_replace_templatesets("usercp_options", '#' . preg_quote('{$myprofile_comments_usercp}') . '#i', '', 0);
956 find_replace_templatesets("modcp_nav_users", "#" . preg_quote('{$nav_myprofilecomments}') . "#i", '', 0);
957 find_replace_templatesets('header', "#" . preg_quote('{$myprofile_alertbar}') . "#i", '', 0);
958
959 if (MyProfileUtils::myalerts_exists()) {
960 if (MyProfileComments::myalerts_can_deintegrate()) {
961 $alertTypeManager = MybbStuff_MyAlerts_AlertTypeManager::createInstance($db, $cache);
962 $alertTypeManager->deleteByCode(MyProfileCommentsMyAlertsFormatter::alert_type_code());
963 }
964 }
965 }
966
967 public function global_start() {
968 global $mybb, $db, $settings, $lang, $templates, $myprofile_alertbar, $templatelist, $theme;
969 if (defined('THIS_SCRIPT') && THIS_SCRIPT == "member.php") {
970 /* load our templates */
971 $templatelist .= ",myprofile_comments_content,myprofile_comments_stats,myprofile_comments_form,myprofile_comments_form_modoptions,myprofile_comments_form_script,myprofile_comments_form_status,myprofile_comments_table,myprofile_comments_comment,myprofile_comments_no_comment,myprofile_comments_comment_approve,myprofile_comments_comment_reply,myprofile_comments_comment_edit,myprofile_comments_comment_delete,myprofile_comments_comment_report,multipage_page_current,multipage_page,multipage_nextpage,multipage,codebuttons";
972 /* if we are in member.php, and there is logged in user, or the user is viewing own profile */
973 if (isset($mybb->user["uid"], $mybb->input["uid"], $mybb->input["action"]) && $mybb->input["action"] == "profile" && $mybb->user["uid"] > 0 && $mybb->input["uid"] == $mybb->user["uid"]) {
974 /* if the user has no new comments, why reset? */
975 if ($mybb->user["mpnewcomments"] != "0") {
976 $update_array = array(
977 "mpnewcomments" => "0"
978 );
979 $db->update_query("users", $update_array, "uid='{$mybb->user['uid']}'", "1");
980 /* be kind and update the user? */
981 $mybb->user["mpnewcomments"] = "0";
982 }
983 }
984 }
985
986 /* now if the admin has chosen to activate MyAlerts, hook my custom alert formatter classe on global_start */
987 if (in_array($settings["mpcommentsnotification"], array("myalertsoralertbar", "myalerts")) && MyProfileUtils::myalerts_exists()) {
988 if (class_exists("MyProfileCommentsMyAlertsFormatter")) {
989 $formatterManager = MybbStuff_MyAlerts_AlertFormatterManager::createInstance($mybb, $lang);
990 $formatterManager->registerFormatter(new MyProfileCommentsMyAlertsFormatter($mybb, $lang, MyProfileCommentsMyAlertsFormatter::alert_type_code()));
991 }
992 }
993 }
994
995 public function global_intermediate() {
996 global $mybb, $db, $settings, $lang, $templates, $myprofile_alertbar, $templatelist, $theme;
997 /* did the user choose to see notification? and is the notification system "MyAlerts or alert bar" or "Alert bar"? and does the user have new comments */
998 if ($mybb->user["uid"] > 0 && $mybb->user["mpcommentnotification"] == "1" && $mybb->user["mpnewcomments"] > 0 && in_array($settings["mpcommentsnotification"], array("myalertsoralertbar", "alertbar"))) {
999 /* we will only keep going on if the admin selected "Alert bar" / "MyAlerts or Alert bar" and MyAlerts isn't installed */
1000 if ($settings["mpcommentsnotification"] == "alertbar" || !MyProfileUtils::myalerts_exists()) {
1001 /* ok show that bar! */
1002 MyProfileUtils::lang_load_myprofile();
1003 $comments_text = $lang->sprintf($lang->mp_comments_new_comments, "<a href=\"{$settings['bburl']}/member.php?action=profile&uid={$mybb->user['uid']}\">", $mybb->user["mpnewcomments"], "</a>");
1004 eval("\$myprofile_alertbar .= \"" . $templates->get("myprofile_comments_alertbar") . "\";");
1005 }
1006 }
1007 }
1008
1009 public function xmlhttp() {
1010 global $mybb, $settings;
1011 /* are we providing a string action ? */
1012 if (!isset($mybb->input["action"]) || !is_string($mybb->input["action"])) {
1013 return;
1014 }
1015 if ($mybb->input["action"] == "comments-do-edit") {
1016 $this->xmlhttp_comments_do_edit();
1017 return;
1018 } elseif ($mybb->input["action"] == "comments-dismiss") {
1019 $this->xmlhttp_comments_dismiss();
1020 return;
1021 } elseif ($mybb->input["action"] == "comments-delete-all") {
1022 $this->xmlhttp_comments_delete_all();
1023 return;
1024 }
1025 /* are we allowed to perform ajax ? */
1026 if ($settings["mpcommentsajaxenabled"] != "1") {
1027 /* bad admin :( */
1028 return;
1029 }
1030 switch ($mybb->input["action"]) {
1031 case "comments-retrieve":
1032 $this->xmlhttp_comments_retrieve();
1033 break;
1034 case "comments-add":
1035 $this->xmlhttp_comments_add();
1036 break;
1037 case "comments-approve":
1038 $this->xmlhttp_comments_approve();
1039 break;
1040 case "comments-delete":
1041 $this->xmlhttp_comments_delete();
1042 break;
1043 default:
1044 return; /* no need to break, but.. */
1045 break;
1046 }
1047 }
1048
1049 public function xmlhttp_comments_dismiss() {
1050 global $mybb, $db;
1051 if ($mybb->request_method != "post") {
1052 return;
1053 }
1054 /* do we have a valid post key? */
1055 if (!isset($mybb->input["my_post_key"]) || !is_string($mybb->input["my_post_key"]) || !verify_post_check($mybb->input["my_post_key"], true)) {
1056 return;
1057 }
1058 if ($mybb->user["uid"] > 0 && $mybb->user["mpnewcomments"] > "0") {
1059 $update_array = array(
1060 "mpnewcomments" => "0"
1061 );
1062 $db->update_query("users", $update_array, "uid='{$mybb->user['uid']}'", "1");
1063 echo "1";
1064 }
1065 }
1066
1067 public function xmlhttp_comments_retrieve() {
1068 global $mybb, $settings, $db, $lang, $templates;
1069 /* are we making a POST request? */
1070 if ($mybb->request_method != "post") {
1071 return;
1072 }
1073 /* do we have a valid post key? */
1074 if (!isset($mybb->input["my_post_key"]) || !is_string($mybb->input["my_post_key"]) || !verify_post_check($mybb->input["my_post_key"], true)) {
1075 return;
1076 }
1077
1078 MyProfileUtils::lang_load_myprofile();
1079
1080 $result = new stdClass();
1081 $result->error = false;
1082 $result->error_message = "";
1083
1084 if (!isset($mybb->input["memberuid"]) || !is_numeric($mybb->input["memberuid"]) || $mybb->input["memberuid"] <= 0) {
1085 $result->error = true;
1086 $result->error_message = $lang->mp_profile_comments_invalid_user;
1087 MyProfileUtils::output_json($result);
1088 }
1089
1090 $memberuid = (int) $mybb->input["memberuid"];
1091 $memprofile = get_user($memberuid);
1092
1093 $page = isset($mybb->input["page"]) && is_numeric($mybb->input["page"]) && $mybb->input["page"] >= 1 ? (int) $mybb->input["page"] : 1;
1094 // math PRO :D
1095 $limit_start = ($page - 1) * $settings["mpcommentsperpage"];
1096
1097 $comments = $this->comments_retrieve_from_db($page, $memprofile);
1098 $result->comments = $comments;
1099 if (count($comments) == 0) {
1100 eval("\$result->empty = \"" . $templates->get('myprofile_comments_no_comment') . "\";");
1101 }
1102 $rows = $this->comments_count($memprofile);
1103 $result->rows = $rows;
1104 $result->pagination = multipage($rows, $settings['mpcommentsperpage'], $page, "#comments/{page}");
1105
1106 /* wait, is the user requesting comments for own profile? then maybe dismiss any notifications he's got */
1107 if ($mybb->user["uid"] > 0 && $memprofile["uid"] == $mybb->user["uid"]) {
1108 $update_array = array(
1109 "mpnewcomments" => "0"
1110 );
1111 $db->update_query("users", $update_array, "uid='{$mybb->user['uid']}'", "1");
1112 $mybb->user["mpnewcomments"] = "0";
1113 }
1114
1115 MyProfileUtils::output_json($result);
1116 }
1117
1118 /**
1119 * Retrieve comments from DB, for the page number {$id}, corresponding to the user with a uid {$memberuid}.
1120 * If you are retrieving a comment, change $type to 'comment', and provide the comment's ID you're looking for as $id. $type can either be 'comment' or 'page'.
1121 * @return array either way, this function will return an array of comments already processed, ONLY comments that the user has the right to read will be returned.
1122 */
1123 public function comments_retrieve_from_db($id, $memprofile, $type = 'page') {
1124 global $db, $settings, $mybb;
1125 /* memberuid = 0 if no memberprofile have been provided */
1126
1127 $memberuid = !empty($memprofile) ? $memprofile["uid"] : 0;
1128 $where = "c.cuid=u.uid AND c.userid='{$memberuid}'";
1129 $fields = "*";
1130
1131 /* If I'm not visiting my profile, and I cannot manage comments, add some restrictions */
1132 if ($memprofile["uid"] != $mybb->user["uid"] && !$this->can_manage_comments()) {
1133 /* Fetch comments that are either approved, or not yet approved but I'm their author. And comments that are either public, or private but I'm their author */
1134 $where .= " AND (c.approved='1' OR (c.approved='0' AND c.cuid='{$mybb->user['uid']}')) AND (c.isprivate='0' OR (c.isprivate='1' AND c.cuid='{$mybb->user['uid']}'))";
1135 }
1136
1137 /* If I'm the author, I shall always see my own comments */
1138 if ($type == "comment") {
1139 $where .= " AND c.cid='{$id}'";
1140 $limit = " LIMIT 1";
1141 } elseif ($type == "page") {
1142 $limit_start = ($id - 1) * $settings['mpcommentsperpage'];
1143 $limit = " LIMIT {$limit_start}, {$settings['mpcommentsperpage']}";
1144 } else {
1145 $limit = "";
1146 $fields = "COUNT(*) AS rows";
1147 }
1148
1149 $query = $db->query("SELECT {$fields} FROM " . TABLE_PREFIX . "myprofilecomments c, " . TABLE_PREFIX . "users u
1150 WHERE {$where} ORDER BY c.time DESC{$limit}");
1151
1152 if ($type == "comment") {
1153 return $db->fetch_array($query);
1154 } elseif ($type == "page") {
1155 $results = array();
1156 while ($comment = $db->fetch_array($query)) {
1157 $results[] = $this->comment_process($comment, $memprofile);
1158 }
1159 return $results;
1160 } else {
1161 return $db->fetch_field($query, "rows");
1162 }
1163 }
1164
1165 /**
1166 * Retrieve only one comment from DB, alias for comments_retrieve_from_db($cid, $memberuid, 'comment');
1167 * This function will return an array containing exactly ONE comment if the $cid has been found, and the user requesting is able to see it. An empty array otherwise.
1168 */
1169 public function comment_retrieve_from_db($cid, $memprofile) {
1170 return $this->comments_retrieve_from_db($cid, $memprofile, "comment");
1171 }
1172
1173 public function comments_count($memprofile) {
1174 return $this->comments_retrieve_from_db(null, $memprofile, "count");
1175 }
1176
1177 public function xmlhttp_comments_add() {
1178 global $mybb, $lang, $settings;
1179 /* post request ? */
1180 if ($mybb->request_method != "post") {
1181 return;
1182 }
1183 /* valid post key ? */
1184 if (!isset($mybb->input["my_post_key"]) || !is_string($mybb->input["my_post_key"]) || !verify_post_check($mybb->input["my_post_key"], true)) {
1185 return;
1186 }
1187 /* have we provided all the necessary fields ? With the appropriate types ? */
1188 if (!isset($mybb->input["message"], $mybb->input["memberuid"]) || !is_string($mybb->input["message"]) || !is_numeric($mybb->input["memberuid"])) {
1189 return;
1190 }
1191 MyProfileUtils::lang_load_myprofile();
1192 $memberuid = (int) $mybb->input["memberuid"];
1193 $memprofile = get_user($memberuid);
1194
1195 $result = new stdClass();
1196 $result->error = false;
1197 $result->error_message = "";
1198
1199 /* can the user send comments to the profile's owner? */
1200 if (!$this->can_send_comments($mybb->user, $memprofile, $result->error_message)) {
1201 $result->error = true;
1202 MyProfileUtils::output_json($result);
1203 }
1204
1205 $message = $mybb->input["message"];
1206 /* is the comment private? is the sneaky user trying to set it to private while the private status is globally disabled? */
1207 $isprivate = isset($mybb->input["isprivate"]) && in_array($mybb->input["isprivate"], array("0", "1")) && $settings["mpcommentsstatusenabled"] == "1" ? (int) $mybb->input["isprivate"] : 0;
1208 /* are we respecting the comment lengths? */
1209 if (my_strlen(trim($message)) < $settings["mpcommentsminlength"] || my_strlen($message) > $settings["mpcommentsmaxlength"]) {
1210 $result->error = true;
1211 $result->error_message = $lang->sprintf($lang->mp_comments_comment_wrong_length, $settings["mpcommentsminlength"], $settings["mpcommentsmaxlength"]);
1212 MyProfileUtils::output_json($result);
1213 }
1214
1215 /* go get em */
1216 $result = $this->insert_comment($message, $memberuid, $isprivate);
1217 MyProfileUtils::output_json($result);
1218 }
1219
1220 public function xmlhttp_comments_do_edit() {
1221 global $mybb, $lang, $settings;
1222 /* post request ? */
1223 if ($mybb->request_method != "post") {
1224 return;
1225 }
1226 /* valid post key ? */
1227 if (!isset($mybb->input["my_post_key"]) || !is_string($mybb->input["my_post_key"]) || !verify_post_check($mybb->input["my_post_key"], true)) {
1228 return;
1229 }
1230 /* have we provided all the necessary fields ? With the appropriate types ? */
1231 if (!isset($mybb->input["message"], $mybb->input["memberuid"], $mybb->input["cid"]) || !is_string($mybb->input["message"]) || !is_numeric($mybb->input["memberuid"]) || !is_numeric($mybb->input["cid"])) {
1232 return;
1233 }
1234 MyProfileUtils::lang_load_myprofile();
1235 $memberuid = (int) $mybb->input["memberuid"];
1236 $memprofile = get_user($memberuid);
1237
1238 $cid = (int) $mybb->input["cid"];
1239 $comment = $this->comment_retrieve_from_db($cid, $memprofile);
1240 $message = $mybb->input["message"];
1241
1242 $result = new stdClass();
1243 $result->error = false;
1244 $result->error_message = "";
1245
1246 if (empty($comment) || !$this->can_edit_comment($comment)) {
1247 $result->error = true;
1248 $result->error_message = $lang->mp_comments_cannot_edit_comment;
1249 MyProfileUtils::output_json($result);
1250 }
1251 $isprivate = isset($mybb->input["isprivate"]) && in_array($mybb->input["isprivate"], array("0", "1")) && $settings["mpcommentsstatusenabled"] == "1" ? (int) $mybb->input["isprivate"] : 0;
1252
1253 if (my_strlen(trim($message)) < $settings["mpcommentsminlength"] || my_strlen($message) > $settings["mpcommentsmaxlength"]) {
1254 $result->error = true;
1255 $result->error_message = $lang->sprintf($lang->mp_comments_comment_wrong_length, $settings["mpcommentsminlength"], $settings["mpcommentsmaxlength"]);
1256 MyProfileUtils::output_json($result);
1257 }
1258
1259 $result = $this->update_comment($cid, $message, $memberuid, $isprivate);
1260 MyProfileUtils::output_json($result);
1261 }
1262
1263 public function xmlhttp_comments_approve() {
1264 global $mybb, $db, $settings, $lang;
1265 /* post request? */
1266 if ($mybb->request_method != "post") {
1267 return;
1268 }
1269 /* valid post key? */
1270 if (!isset($mybb->input["my_post_key"]) || !is_string($mybb->input["my_post_key"]) || !verify_post_check($mybb->input["my_post_key"], true)) {
1271 return;
1272 }
1273 if (!isset($mybb->input["cid"]) || !is_numeric($mybb->input["cid"])) {
1274 return;
1275 }
1276
1277 MyProfileUtils::lang_load_myprofile();
1278
1279 $result = $this->approve_comment((int) $mybb->input["cid"]);
1280 MyProfileUtils::output_json($result);
1281 }
1282
1283 public function comment_process($comment, $memprofile) {
1284 global $templates, $cache, $settings, $mybb, $lang;
1285 MyProfileUtils::lang_load_myprofile();
1286
1287 $usergroups = $cache->read("usergroups");
1288 $editable = $this->can_edit_comment($comment);
1289 $approvable = $this->can_approve_comment($comment);
1290 $deletable = $this->can_delete_comment($comment);
1291 /* replyable: well, it's replyable if I'm memprofile, and I'm trying to send a comment to the commentor (but I am not the commentor, otherwise it will be an infinite loop) */
1292 $replyable = $mybb->user["uid"] == $memprofile["uid"] && $comment["cuid"] != $comment["userid"] && $this->can_send_comments($memprofile, $comment);
1293 $reportable = $this->can_report_comment($comment);
1294
1295 /* now we add html content to the comment */
1296 list($avatar_src, $avatar_width_height) = array_values(format_avatar($comment["avatar"], $comment["avatardimensions"]));
1297
1298 $date = my_date($settings["dateformat"], $comment["time"]);
1299 $time = my_date($settings["timeformat"], $comment["time"]);
1300
1301 $username = format_name(htmlspecialchars_uni($comment["username"]), $comment["usergroup"], $comment["displaygroup"]);
1302 $profile_link = build_profile_link($username, $comment["cuid"]);
1303
1304 $message = $this->parse_comment($comment["message"]);
1305
1306 if ($editable) {
1307 eval("\$comments_edit = \"" . $templates->get('myprofile_comments_comment_edit') . "\";");
1308 }
1309
1310 if ($approvable) {
1311 $trow_class = "trow_shaded";
1312 eval("\$comments_approve = \"" . $templates->get('myprofile_comments_comment_approve') . "\";");
1313 }
1314
1315 if ($deletable) {
1316 eval("\$comments_delete = \"" . $templates->get('myprofile_comments_comment_delete') . "\";");
1317 }
1318
1319 if ($replyable) {
1320 $commentor_uid = $comment["cuid"];
1321 eval("\$comments_reply = \"" . $templates->get('myprofile_comments_comment_reply') . "\";");
1322 }
1323
1324 if ($reportable) {
1325 eval("\$comments_report = \"" . $templates->get('myprofile_comments_comment_report') . "\";");
1326 }
1327
1328 if ($comment["isprivate"] == "1") {
1329 $comment_private = $lang->mp_comments_comment_private;
1330 }
1331
1332 if (isset($mybb->input["highlight"]) && $mybb->input["highlight"] == $comment["cid"]) {
1333 $trow_class = "trow_selected";
1334 }
1335
1336 /* last eval() */
1337 eval("\$comment_content = \"" . $templates->get('myprofile_comments_comment') . "\";");
1338
1339 //$comment["html"] = $comment_content;
1340
1341 return $comment_content;
1342 }
1343
1344 public function can_report_comment($comment) {
1345 global $mybb;
1346 /* if the user isn't a guest, and the user's usergroup isn't banned, can report */
1347 if ($this->can_manage_comments()) {
1348 return true;
1349 }
1350 return $mybb->user["uid"] > 0 && $mybb->user["uid"] != $comment["cuid"] && $mybb->usergroup["usergroup"]["isbannedgroup"] != "1";
1351 }
1352
1353 /**
1354 * Can $user comment on $memprofile ? An empty $user means a guest
1355 * Provide an empty variable as third parameter to receive the error message to why the $user can't send a comment to the $target
1356 * $ignore_flood should be true if you want to ignore flood time, this is useful when you want to show the comment form if the only error is flood time.
1357 */
1358 public function can_send_comments($user, $target, &$error_message = "", $ignore_flood = false) {
1359 global $mybb, $settings, $cache, $lang, $db;
1360 MyProfileUtils::lang_load_myprofile();
1361 $usergroups = $cache->read("usergroups");
1362 /* if the user is a mod, always return true please */
1363 if ($this->can_manage_comments($user)) {
1364 return true;
1365 }
1366
1367 $usergroup = $usergroups[$user["usergroup"]];
1368 /* if user's usergroup can't make comments */
1369 if ($usergroup["cansendcomments"] == "0") {
1370 $error_message = $lang->mp_comments_cannot_send_comments;
1371 return false;
1372 }
1373 /* if the target user is banned */
1374 if ($usergroups[$target["usergroup"]]["isbannedgroup"] == "1" && $settings["mpcommentsclosedonbanned"] == "1") {
1375 $error_message = $lang->mp_comments_banned_user;
1376 return false;
1377 }
1378 /* if the user has chosen to close all comments */
1379 if ($target["mpwhocancomment"] == "0" || $target["mpcommentsopen"] == "0") {
1380 $error_message = $lang->mp_comments_user_closed_comments;
1381 return false;
1382 }
1383 /* the target is on ignorelist of the user */
1384 if ($settings["mpcommentsignoreenabled"] == "1" && in_array($user["uid"], explode(",", $target["ignorelist"]))) {
1385 $error_message = $lang->mp_comments_user_ignored_you;
1386 return false;
1387 }
1388 /* check flood time ? */
1389 if (!$ignore_flood && $settings["mpcommentstimeflood"] > "0") {
1390 $flood_time = TIME_NOW - $settings["mpcommentstimeflood"];
1391 $query = $db->simple_select("myprofilecomments", "`time`", "cuid = '{$mybb->user["uid"]}' AND `time` > {$flood_time}", array("limit" => 1));
1392 if ($db->num_rows($query) > 0) {
1393 $time = $db->fetch_field($query, "time");
1394 $seconds = $time - $flood_time;
1395 $error_message = $lang->sprintf($lang->mp_comments_wait_flood_time, $seconds);
1396 return false;
1397 }
1398 }
1399 /* Make sure they still have comments remaining */
1400 $cutoff = TIME_NOW - 86400;
1401 $countquery = $db->simple_select("myprofilecomments", "COUNT(cid) as dailycommenttotal", "time >= $cutoff");
1402 $dailycommenttotal = $db->fetch_field($countquery, "dailycommenttotal");
1403 // Because the $zerogroupgreater array can't be edited at this time, we have to do this the hard way.
1404 $myusergroups = $user['usergroup'];
1405 if ($user['additionalgroups']) {
1406 $myusergroups .= "," . $useradditionalgroups;
1407 }
1408 $explodedgroups = explode(",", $myusergroups);
1409 $commentsallowed = -1;
1410 foreach ($explodedgroups as $exgroup) {
1411 $groupcommentsallowed = $usergroups[$exgroup]['commentsperday'];
1412 if ($groupcommentsallowed == 0) {
1413 $commentsallowed = 0;
1414 break;
1415 } else {
1416 if ($groupcommentsallowed > $commentsallowed) {
1417 $commentsallowed = $groupcommentsallowed;
1418 }
1419 }
1420 }
1421
1422 if ($commentsallowed != 0) {
1423 if ($dailycommenttotal >= $commentsallowed) {
1424 return false;
1425 }
1426 }
1427
1428 /* I'm making a comment on my profile */
1429 if ($user["uid"] == $target["uid"]) {
1430 return true;
1431 }
1432 /* If the user is only accepting comments from friends */
1433 if ($target["mpwhocancomment"] == "1" && !in_array($user["uid"], explode(",", $target["buddylist"]))) {
1434 $error_message = $lang->mp_comments_not_friend_with_user;
1435 return false;
1436 }
1437 /* all well that ends well */
1438 return true;
1439 }
1440
1441 function can_approve_comment($comment) {
1442 global $mybb;
1443 /* approvable: it's approvable if not already approved, and the user is seeing own profile, and the user is the comment's receiver, or it's a moderator */
1444 return $comment["approved"] == "0" ? $this->can_manage_comments() || $mybb->user["uid"] == $comment["userid"] : false;
1445 ;
1446 }
1447
1448 /* if $user provided, it will check if they can manage comments, otherwise it will look if the connected user can do that */
1449
1450 public function can_manage_comments($user = null) {
1451 global $mybb, $cache;
1452 $usergroups = $cache->read("usergroups");
1453 return !empty($user) ? $usergroups[$user["usergroup"]]["canmanagecomments"] == "1" : $mybb->usergroup["canmanagecomments"] == "1";
1454 }
1455
1456 public function can_delete_comment($comment) {
1457 global $mybb;
1458 /* deletable: it's deletable if we're a mod, or we're the author of the comment and we can delete own comments */
1459 return $this->can_manage_comments() || ($comment["cuid"] == $mybb->user["uid"] && $mybb->usergroup["candeleteowncomments"] == "1");
1460 }
1461
1462 public function can_edit_comment($comment) {
1463 global $mybb, $settings;
1464 /* editable: it's editable if we are a moderator, or if we are the author and we can edit own comments */
1465 if ($this->can_manage_comments()) {
1466 return true;
1467 }
1468 $editable = $comment["cuid"] == $mybb->user["uid"] && $mybb->usergroup["caneditowncomments"] == "1";
1469 /* did the allowed time to edit expire? */
1470 if ($settings["mpcommentstimeedit"] > "0") {
1471 $time_limit = TIME_NOW - ($settings["mpcommentstimeedit"] * 60);
1472 $editable = $comment["time"] > $time_limit;
1473 }
1474 /* if the user has already approved the message, the user shouldn't be able to edit it anyway. we add $editable so it doesn't perform the other tests if it's not editable anyway. */
1475 if ($editable && $comment["approved"] == "1") {
1476 $memprofile = get_user($comment["userid"]);
1477 if ($memprofile["mpcommentsapprove"] == "1") {
1478 $editable = false;
1479 }
1480 }
1481 return $editable;
1482 }
1483
1484 public function xmlhttp_comments_delete() {
1485 global $mybb, $db, $settings, $lang;
1486 /* post request? */
1487 if ($mybb->request_method != "post") {
1488 return;
1489 }
1490 /* valid post key? */
1491 if (!isset($mybb->input["my_post_key"]) || !is_string($mybb->input["my_post_key"]) || !verify_post_check($mybb->input["my_post_key"], true)) {
1492 return;
1493 }
1494 MyProfileUtils::lang_load_myprofile();
1495
1496 if (!isset($mybb->input["cid"]) || !is_numeric($mybb->input["cid"])) {
1497 return;
1498 }
1499 $result = $this->delete_comment((int) $mybb->input["cid"]);
1500 MyProfileUtils::output_json($result);
1501 }
1502
1503 public function xmlhttp_comments_delete_all() {
1504 global $mybb, $db, $settings, $lang;
1505 if ($mybb->request_method != "post") {
1506 return;
1507 }
1508 if (!isset($mybb->input["my_post_key"]) || !is_string($mybb->input["my_post_key"]) || !verify_post_check($mybb->input["my_post_key"], true)) {
1509 return;
1510 }
1511 if (!$this->can_manage_comments()) {
1512 /* nice try! */
1513 return;
1514 }
1515 MyProfileUtils::lang_load_myprofile();
1516
1517 $result = new stdClass();
1518 $result->error = false;
1519 $result->error_message = "";
1520
1521 if (!isset($mybb->input["memberuid"]) || !is_numeric($mybb->input["memberuid"])) {
1522 $result->error = true;
1523 $result->error_message = $lang->mp_profile_comments_no_user_selected;
1524
1525 MyProfileUtils::output_json($result);
1526 }
1527
1528 $memberuid = (int) $mybb->input["memberuid"];
1529 $query = $db->delete_query("myprofilecomments", "userid='{$memberuid}'");
1530 MyProfileUtils::output_json($result);
1531 }
1532
1533 /*
1534 public function xmlhttp_comments_edit_get() {
1535 global $mybb, $db, $settings, $lang;
1536 if(! isset($mybb->input["action"]) || $mybb->input["action"] != "comments_edit_get") {
1537 return;
1538 }
1539 if(! isset($mybb->input["my_post_key"]) || ! is_string($mybb->input["my_post_key"]) || ! verify_post_check($mybb->input["my_post_key"], true)) {
1540 return;
1541 }
1542 MyProfileUtils::lang_load_myprofile();
1543
1544 $result = new stdClass();
1545 $result->error = false;
1546 $result->error_message = "";
1547
1548 if(! isset($mybb->input["cid"]) || ! is_numeric($mybb->input["cid"])) {
1549 $result->error = true;
1550 $result->error_message = $lang->mp_profile_comments_no_comment_selected;
1551
1552 MyProfileUtils::output_json($result);
1553 }
1554
1555 $cid = (int) $mybb->input["cid"];
1556 $query = $db->simple_select("myprofilecomments", "message", "cid='{$cid}'");
1557
1558 if($db->num_rows($query) != 1) {
1559 $result->error = true;
1560 $result->error_message = $lang->mp_profile_comments_no_comment_selected;
1561
1562 MyProfileUtils::output_json($result);
1563 }
1564
1565 $message = $db->fetch_field($query, "message");
1566
1567 $result->message = $message;
1568
1569 MyProfileUtils::output_json($result);
1570 }
1571
1572 public function xmlhttp_comments_edit_set() {
1573 global $mybb, $db, $settings, $lang;
1574 if(! isset($mybb->input["action"]) || $mybb->input["action"] != "comments_edit_set" || $mybb->request_method != "post") {
1575 return;
1576 }
1577 if(! isset($mybb->input["my_post_key"]) || ! is_string($mybb->input["my_post_key"]) || ! verify_post_check($mybb->input["my_post_key"], true)) {
1578 return;
1579 }
1580 MyProfileUtils::lang_load_myprofile();
1581
1582 $result = new stdClass();
1583 $result->error = false;
1584 $result->error_message = "";
1585
1586 if(! isset($mybb->input["cid"], $mybb->input["message"]) || ! is_numeric($mybb->input["cid"]) || ! is_string($mybb->input["message"])) {
1587 $result->error = true;
1588 $result->error_message = $lang->mp_profile_comments_no_comment_selected;
1589
1590 MyProfileUtils::output_json($result);
1591 }
1592
1593 $cid = (int) $mybb->input["cid"];
1594 $message = $mybb->input["message"];
1595
1596 $query = $db->simple_select("myprofilecomments", "message", "cid='{$cid}'");
1597
1598 if($db->num_rows($query) != 1) {
1599 $result->error = true;
1600 $result->error_message = $lang->mp_profile_comments_no_comment_selected;
1601
1602 MyProfileUtils::output_json($result);
1603 }
1604
1605 $db->update_query("myprofilecomments", array("message" => $db->escape_string($message)), "cid='{$cid}'");
1606 $query = $db->simple_select("myprofilecomments", "message", "cid='{$cid}'");
1607
1608 $message = $db->fetch_field($query, "message");
1609
1610 $result->message = $this->parse_comment($message);
1611
1612 MyProfileUtils::output_json($result);
1613 } */
1614
1615 /* insert a comment to $uid, that is private or not */
1616
1617 public function insert_comment($message, $uid, $isprivate = 0) {
1618 global $mybb, $settings, $db, $lang;
1619 MyProfileUtils::lang_load_myprofile();
1620 $user = get_user($uid);
1621
1622 $result = new stdClass();
1623 $result->error = false;
1624 $result->error_message = "";
1625
1626 if (empty($user)) {
1627 $result->error = true;
1628 $result->error_message = $lang->mp_profile_comments_no_user_selected;
1629 return $result;
1630 }
1631
1632 /* should the user approve the message first? */
1633 $approved = $user["mpcommentsapprove"] == "0";
1634
1635 $insert_array = array(
1636 "userid" => (int) $user["uid"],
1637 "cuid" => (int) $mybb->user["uid"],
1638 "message" => $db->escape_string($message),
1639 "approved" => $approved,
1640 "isprivate" => $isprivate,
1641 "time" => TIME_NOW
1642 );
1643 $cid = $db->insert_query("myprofilecomments", $insert_array);
1644 $this->alert_comment($user, $mybb->user, $cid);
1645
1646 // all's well that ends well
1647 return $result;
1648 }
1649
1650 public function update_comment($cid, $message, $uid, $isprivate = 0) {
1651 global $mybb, $settings, $db, $lang;
1652 MyProfileUtils::lang_load_myprofile();
1653 $user = get_user($uid);
1654
1655 $result = new stdClass();
1656 $result->error = false;
1657 $result->error_message = "";
1658
1659 if (empty($user)) {
1660 $result->error = true;
1661 $result->error_message = $lang->mp_profile_comments_no_user_selected;
1662 return $result;
1663 }
1664
1665 /* should the user approve the message first? */
1666 $approved = $user["mpcommentsapprove"] == "0";
1667
1668 $update_array = array(
1669 "message" => $db->escape_string($message),
1670 "approved" => $approved,
1671 "isprivate" => $isprivate
1672 );
1673 $cid = $db->update_query("myprofilecomments", $update_array, "cid='{$cid}'", "1");
1674
1675 // all's well that ends well
1676 return $result;
1677 }
1678
1679 public function alert_comment($user, $commentor, $cid) {
1680 global $mybb, $db, $settings, $cache, $plugins;
1681 /* if the admin choosed alertbar, or "MyAlerts or Alert bar" but MyAlerts don't exist, notify the user */
1682 if ($settings["mpcommentsnotification"] == "alertbar" || ($settings["mpcommentsnotification"] == "myalertsoralertbar" && !MyProfileUtils::myalerts_exists())) {
1683 $update_array = array(
1684 "mpnewcomments" => $user["mpnewcomments"] + 1
1685 );
1686 $db->update_query("users", $update_array, "uid='{$user['uid']}'", "1");
1687 $user["mpnewcomments"] ++;
1688 }
1689 /* if the admin choosed myalerts and it exists */ elseif (($settings["mpcommentsnotification"] == "myalerts" || $settings["mpcommentsnotification"] == "myalertsoralertbar") && MyProfileUtils::myalerts_exists()) {
1690 $myalerts_plugins = $cache->read('mybbstuff_myalerts_alert_types');
1691 if (isset($myalerts_plugins[MyProfileCommentsMyAlertsFormatter::alert_type_code()])
1692 && $myalerts_plugins[MyProfileCommentsMyAlertsFormatter::alert_type_code()]['enabled'] == 1) {
1693 $alertType = MybbStuff_MyAlerts_AlertTypeManager
1694 ::createInstance($db, $cache)
1695 ->getByCode(MyProfileCommentsMyAlertsFormatter::alert_type_code());
1696 $alert = MybbStuff_MyAlerts_Entity_Alert::make($user["uid"], $alertType, null, array("cid" => $cid));
1697 MybbStuff_MyAlerts_AlertManager::createInstance($mybb, $db, $cache, $alertType)->addAlert($alert);
1698 }
1699 }
1700 }
1701
1702 public function delete_comment($cid) {
1703 global $db, $lang;
1704 MyProfileUtils::lang_load_myprofile();
1705 $query = $db->simple_select("myprofilecomments", "*", "cid='{$cid}'");
1706
1707 $result = new stdClass();
1708 $result->error = false;
1709 $result->error_message = "";
1710
1711 if ($db->num_rows($query) != 1) {
1712 $result->error = true;
1713 $result->error_message = $lang->mp_comments_comment_not_found;
1714 return $result;
1715 }
1716
1717 $comment = $db->fetch_array($query);
1718
1719 if (!$this->can_delete_comment($comment)) {
1720 $result->error = true;
1721 $result->error_message = $lang->mp_comments_cannot_delete_comment;
1722 return $result;
1723 }
1724
1725 $query = $db->delete_query("myprofilecomments", "cid='{$cid}'");
1726 return $result;
1727 }
1728
1729 public function approve_comment($cid) {
1730 global $db, $lang;
1731 MyProfileUtils::lang_load_myprofile();
1732 $query = $db->simple_select("myprofilecomments", "*", "cid='{$cid}'");
1733
1734 $result = new stdClass();
1735 $result->error = false;
1736 $result->error_message = "";
1737
1738 if ($db->num_rows($query) != 1) {
1739 $result->error = true;
1740 $result->error_message = $lang->mp_comments_comment_not_found;
1741 return $result;
1742 }
1743
1744 $comment = $db->fetch_array($query);
1745 if (!$this->can_approve_comment($comment)) {
1746 $result->error = true;
1747 $result->error_message = $lang->mp_comments_cannot_approve_comment;
1748 return $result;
1749 }
1750
1751 $update_array = array(
1752 "approved" => "1"
1753 );
1754 $db->update_query("myprofilecomments", $update_array, "cid='{$cid}'", "1");
1755 return $result;
1756 }
1757
1758 public function misc_start() {
1759 global $mybb, $settings;
1760 if (!isset($mybb->input["action"]) || !is_string($mybb->input["action"])) {
1761 return;
1762 }
1763 /* is ajax activated? */
1764 /* version 0.5 - removing this restriction
1765 if($settings["mpcommentsajaxenabled"] != "0") {
1766 return;
1767 }
1768 */
1769 switch ($mybb->input["action"]) {
1770 case "comments-add" :
1771 $this->misc_comments_add();
1772 break;
1773 case "comments-delete" :
1774 $this->misc_comments_delete();
1775 break;
1776 case "comments-delete-all" :
1777 $this->misc_comments_delete_all();
1778 break;
1779 case "comments-approve" :
1780 $this->misc_comments_approve();
1781 break;
1782 case "comments-edit" :
1783 $this->misc_comments_edit();
1784 break;
1785 case "comments-do-edit" :
1786 $this->misc_comments_do_edit();
1787 break;
1788 default :
1789 return; /* again, no need to break after a return but I'm a paranoid */
1790 break;
1791 }
1792 }
1793
1794 public function misc_comments_add() {
1795 global $mybb, $lang, $settings;
1796 /* post request ? */
1797 if ($mybb->request_method != "post") {
1798 return;
1799 }
1800 /* valid post key ? */
1801 verify_post_check($mybb->input["my_post_key"]);
1802
1803 /* have we provided all the necessary fields ? With the appropriate types ? */
1804 if (!isset($mybb->input["message"], $mybb->input["memberuid"]) || !is_string($mybb->input["message"]) || !is_numeric($mybb->input["memberuid"])) {
1805 return;
1806 }
1807 MyProfileUtils::lang_load_myprofile();
1808 $memberuid = (int) $mybb->input["memberuid"];
1809 $memprofile = get_user($memberuid);
1810
1811 $error_message = "";
1812
1813 /* can the user send comments to the profile's owner? */
1814 if (!$this->can_send_comments($mybb->user, $memprofile, $error_message)) {
1815 $this->redirect($memberuid, $error_message);
1816 }
1817
1818 $message = $mybb->input["message"];
1819 /* is the comment private? is the sneaky user trying to set it to private while the private status is globally disabled? */
1820 $isprivate = isset($mybb->input["isprivate"]) && in_array($mybb->input["isprivate"], array("0", "1")) && $settings["mpcommentsstatusenabled"] == "1" ? (int) $mybb->input["isprivate"] : 0;
1821 /* are we respecting the comment lengths? */
1822 if (my_strlen(trim($message)) < $settings["mpcommentsminlength"] || my_strlen($message) > $settings["mpcommentsmaxlength"]) {
1823 $error_message = $lang->sprintf($lang->mp_comments_comment_wrong_length, $settings["mpcommentsminlength"], $settings["mpcommentsmaxlength"]);
1824 $this->redirect($memberuid, $error_message);
1825 }
1826
1827 /* go get em */
1828 $result = $this->insert_comment($message, $memberuid, $isprivate);
1829 if ($result->error) {
1830 $this->redirect($memberuid, $result->error_message);
1831 } else {
1832 $this->redirect($memberuid, $lang->mp_comments_comment_added_successfully);
1833 }
1834 }
1835
1836 public function misc_comments_delete() {
1837 global $mybb, $db, $settings, $lang;
1838 /* post request? */
1839 if ($mybb->request_method != "post") {
1840 return;
1841 }
1842 /* valid post key? */
1843 verify_post_check($mybb->input["my_post_key"]);
1844 if (!isset($mybb->input["cid"], $mybb->input["memberuid"]) || !is_numeric($mybb->input["cid"]) || !is_numeric($mybb->input["memberuid"])) {
1845 return;
1846 }
1847 MyProfileUtils::lang_load_myprofile();
1848 $result = $this->delete_comment((int) $mybb->input["cid"]);
1849 if ($result->error) {
1850 $this->redirect($mybb->input["memberuid"], $result->error_message);
1851 } else {
1852 $this->redirect($mybb->input["memberuid"], $lang->mp_comments_comment_deleted_successfully);
1853 }
1854 }
1855
1856 public function misc_comments_delete_all() {
1857 global $mybb, $lang;
1858 if ($mybb->request_method != "get") {
1859 return;
1860 }
1861 verify_post_check($mybb->input["my_post_key"]);
1862 if (!isset($mybb->input["memberuid"]) || !is_numeric($mybb->input["memberuid"])) {
1863 return;
1864 }
1865 if (!$this->can_manage_comments()) {
1866 error_no_permission();
1867 } else {
1868 MyProfileUtils::lang_load_myprofile();
1869 $this->redirect((int) $mybb->input["memberuid"], $lang->mp_comments_comments_deleted_successfully);
1870 }
1871 }
1872
1873 public function misc_comments_approve() {
1874 global $mybb, $db, $settings, $lang;
1875 /* post request? */
1876 if ($mybb->request_method != "post") {
1877 return;
1878 }
1879 /* valid post key? */
1880 verify_post_check($mybb->input["my_post_key"]);
1881 if (!isset($mybb->input["cid"], $mybb->input["memberuid"]) || !is_numeric($mybb->input["cid"]) || !is_numeric($mybb->input["memberuid"])) {
1882 return;
1883 }
1884
1885 MyProfileUtils::lang_load_myprofile();
1886
1887 $memberuid = (int) $mybb->input["memberuid"];
1888
1889 $result = $this->approve_comment((int) $mybb->input["cid"]);
1890
1891 if ($result->error) {
1892 $this->redirect($memberuid, $result->error_message);
1893 } else {
1894 $this->redirect($memberuid, $lang->mp_comments_comment_approved_successfully);
1895 }
1896 }
1897
1898 public function misc_comments_edit() {
1899 global $mybb, $settings, $lang, $theme, $templates, $db;
1900 if (!isset($mybb->input["cid"], $mybb->input["my_post_key"], $mybb->input["memberuid"]) || !is_numeric($mybb->input["cid"]) || !is_numeric($mybb->input["memberuid"]) || !is_string($mybb->input["my_post_key"])) {
1901 return;
1902 }
1903
1904 $memprofile = get_user($mybb->input["memberuid"]);
1905
1906 $comment = $this->comment_retrieve_from_db((int) $mybb->input["cid"], $memprofile);
1907
1908 MyProfileUtils::lang_load_myprofile();
1909 if (empty($comment) || !$this->can_edit_comment($comment)) {
1910 MyProfileUtils::output_error($lang->mp_comments_cannot_edit_comment, 400);
1911 }
1912
1913 $original_text = new stdClass();
1914 $original_text->message = $comment["message"];
1915 $original_text = json_encode($original_text);
1916 if ($settings["mpcommentsstatusenabled"] == "1") {
1917 if ($comment["isprivate"] == "0") {
1918 $comment_public_selected = 'selected="selected"';
1919 } else {
1920 $comment_private_selected = 'selected="selected"';
1921 }
1922 $status_select_class = "select-comments-edit";
1923 eval("\$status .= \"" . $templates->get('myprofile_comments_form_status') . "\";");
1924 }
1925 $cid = $comment["cid"];
1926 eval("\$comments_edit .= \"" . $templates->get('myprofile_comments_edit', 1, 0) . "\";");
1927 echo $comments_edit;
1928 }
1929
1930 public function misc_comments_do_edit() {
1931 global $mybb, $lang;
1932 if (!isset($mybb->input["my_post_key"], $mybb->input["page"], $mybb->input["memberuid"]) || !is_string($mybb->input["my_post_key"]) ||
1933 !is_numeric($mybb->input["page"]) || !is_numeric($mybb->input["memberuid"])) {
1934 return;
1935 }
1936 if (!verify_post_check($mybb->input["my_post_key"], true)) {
1937 return;
1938 }
1939 MyProfileUtils::lang_load_myprofile();
1940 $this->redirect((int) $mybb->input["memberuid"], $lang->mp_comments_comment_edited_successfully, "&page={$mybb->input['page']}");
1941 }
1942
1943 public function redirect($uid, $message, $supplement = "") {
1944 redirect(get_profile_link((int) $uid) . $supplement, $message);
1945 }
1946
1947 public function member_profile_end() {
1948 global $templates, $theme, $memprofile, $settings, $db, $mybb, $lang, $myprofile_comments, $theme, $myprofile_comments_stats;
1949
1950 if ($settings["mpcommentsenabled"] != "1") {
1951 return;
1952 }
1953
1954 MyProfileUtils::lang_load_myprofile();
1955 $page = isset($mybb->input["page"]) && is_numeric($mybb->input["page"]) && $mybb->input["page"] >= 1 ? (int) $mybb->input["page"] : 1;
1956
1957 $comments_memberuid = $memprofile["uid"];
1958 $comments_ajax = $settings["mpcommentsajaxenabled"] == "1" ? 1 : 0;
1959 $comments_minlength = $settings["mpcommentsminlength"];
1960 $comments_maxlength = $settings["mpcommentsmaxlength"];
1961 $comments_page = $page;
1962 $comments_sceditor = 0;
1963
1964 if ($this->can_send_comments($mybb->user, $memprofile, $ignored_error_message, true)) {
1965 $show_smilies = $settings["mpcommentsallowsmilies"] == "1";
1966 if ($settings["mpcommentsshowwysiwyg"] == "1") {
1967 $codebuttons = build_mycode_inserter("message", $show_smilies);
1968 /* small hack to shrink the sceditor */
1969 $codebuttons = str_replace(array('|left,center,right,justify', '|bulletlist,orderedlist'), '', $codebuttons);
1970 $comments_sceditor = 1;
1971 } else {
1972 $comments_sceditor = 0;
1973 }
1974 if ($this->can_manage_comments()) {
1975 eval("\$modoptions .= \"" . $templates->get('myprofile_comments_form_modoptions') . "\";");
1976 }
1977 if ($settings["mpcommentsstatusenabled"] == "1") {
1978 $comment_public_selected = 'selected="selected"';
1979 $status_select_class = "select-comments-add";
1980 eval("\$status .= \"" . $templates->get('myprofile_comments_form_status') . "\";");
1981 }
1982 eval("\$comments_form .= \"" . $templates->get('myprofile_comments_form') . "\";");
1983 }
1984
1985 if ($settings["mpcommentsajaxenabled"] == "0") {
1986 /* ajax disabled, do the dirty work */
1987 $comments_content = "";
1988 $comments = $this->comments_retrieve_from_db($page, $memprofile);
1989 if (is_array($comments) && count($comments) > 0) {
1990 foreach ($comments as $comment) {
1991 $comments_content .= $comment;
1992 }
1993 } else {
1994 eval("\$comments_content = \"" . $templates->get('myprofile_comments_no_comment') . "\";");
1995 }
1996 $comments_total = $this->comments_count($memprofile);
1997 $comments_pagination = multipage($comments_total, $settings['mpcommentsperpage'], $page, get_profile_link($memprofile["uid"]) . "&page={page}");
1998 if ($comments_pagination == null) {
1999 $comments_pagination_style = 'style="display: none;"';
2000 }
2001 }
2002
2003 eval("\$comment_form_script .= \"" . $templates->get('myprofile_comments_form_script') . "\";");
2004
2005 /* darn that <br /> bug! */
2006 if (!empty($GLOBALS['modoptions']) || !empty($comments_form)) {
2007 $comments_separator = "<br />";
2008 }
2009
2010 eval("\$comments_table .= \"" . $templates->get('myprofile_comments_table') . "\";");
2011
2012 eval("\$myprofile_comments .= \"" . $templates->get('myprofile_comments_content') . "\";");
2013
2014 if ($settings["mpcommentsshowstats"] == "1") {
2015 $result = $this->user_statistics($memprofile["uid"]);
2016 $stats_sent = $result["sent"];
2017 $stats_received = $result["received"];
2018 $stats_total = $result["total"];
2019 eval("\$myprofile_comments_stats .= \"" . $templates->get('myprofile_comments_stats') . "\";");
2020 }
2021 }
2022
2023 public function admin_formcontainer_end() {
2024 global $run_module, $form_container, $lang, $form, $mybb, $usergroup;
2025
2026 if ($run_module == "user" && !empty($form_container->_title) && !empty($lang->users_permissions) && $form_container->_title == $lang->users_permissions) {
2027 MyProfileUtils::lang_load_config_myprofile();
2028
2029 $mp_options = array();
2030 $mp_options[] = $form->generate_check_box("canmanagecomments", 1, $lang->mp_options_can_manage_comments, array('checked' => $mybb->input["canmanagecomments"]));
2031 $mp_options[] = $form->generate_check_box("cansendcomments", 1, $lang->mp_options_can_send_comments, array('checked' => $mybb->input["cansendcomments"]));
2032 $mp_options[] = $form->generate_check_box("caneditowncomments", 1, $lang->mp_options_can_edit_own_comments, array('checked' => $mybb->input["caneditowncomments"]));
2033 $mp_options[] = $form->generate_check_box("candeleteowncomments", 1, $lang->mp_options_can_delete_own_comments, array('checked' => $mybb->input["candeleteowncomments"]));
2034 $mp_options[] = $lang->mp_options_comments_per_day . "<br />" . $form->generate_text_box("commentsperday", $usergroup['commentsperday']);
2035
2036 $form_container->output_row($lang->mp_myprofile, '', '<div class="group_settings_bit">' . implode('</div><div class="group_settings_bit">', $mp_options) . '</div>');
2037 }
2038 }
2039
2040 public function admin_user_groups_edit_commit() {
2041 global $updated_group, $mybb;
2042
2043 $updated_group['canmanagecomments'] = $mybb->input['canmanagecomments'];
2044 $updated_group['cansendcomments'] = $mybb->input['cansendcomments'];
2045 $updated_group['caneditowncomments'] = $mybb->input['caneditowncomments'];
2046 $updated_group['candeleteowncomments'] = $mybb->input['candeleteowncomments'];
2047 $updated_group['commentsperday'] = (int) $mybb->input['commentsperday'];
2048 }
2049
2050 public function report_start() {
2051 global $lang;
2052 MyProfileUtils::lang_load_myprofile();
2053 }
2054
2055 public function report_end() {
2056 global $templates, $error, $report, $report_reasons, $mybb, $lang, $report_title;
2057 if (empty($error) && empty($report)) {
2058 eval("\$report_reasons = \"" . $templates->get("myprofile_comments_report_reasons") . "\";");
2059 }
2060 }
2061
2062 public function report_type() {
2063 global $mybb, $db, $lang, $report_type, $report_type_db, $verified, $id, $id2, $id3, $error;
2064 if ($report_type == 'comment') {
2065 if (!isset($mybb->input["pid"]) || !is_numeric($mybb->input["pid"])) {
2066 $error = $lang->error_invalid_report;
2067 } else {
2068 $cid = (int) $mybb->input["pid"];
2069 $query = $db->simple_select("myprofilecomments", "*", "cid = '" . $cid . "'");
2070 if (!$db->num_rows($query)) {
2071 $error = $lang->error_invalid_report;
2072 } else {
2073 $verified = true;
2074 $comment = $db->fetch_array($query);
2075 $id = $comment["cid"];
2076 $id2 = $comment["userid"]; // user who received the comment
2077 $id3 = $comment["cuid"]; // user who made the comment
2078 $report_type_db = "type = 'comment'";
2079 }
2080 }
2081 }
2082 }
2083
2084 public function modcp_reports_report() {
2085 global $report, $report_data, $lang;
2086 if ($report["type"] == "comment") {
2087 MyProfileUtils::lang_load_myprofile();
2088 $from_user = get_user($report['id3']);
2089 $to_user = get_user($report['id2']);
2090 $from_profile_link = build_profile_link(htmlspecialchars_uni($from_user["username"]), $from_user["uid"]);
2091 $to_profile_link = build_profile_link(htmlspecialchars_uni($to_user["username"]), $to_user["uid"]);
2092 $comment_link = $this->build_comment_link($report["id"]);
2093 $report_data["content"] = $lang->sprintf($lang->mp_report_from, $comment_link, $from_profile_link);
2094 $report_data["content"] .= $lang->sprintf($lang->mp_report_to, $to_profile_link);
2095 }
2096 }
2097
2098 public function usercp_do_options_end() {
2099 global $mybb, $db;
2100
2101 // basically, if the my profile params are submitted, and they are equivalent to the old ones, return.
2102 if (isset($mybb->input["mpcommentsopen"]) && $mybb->user["mpcommentsopen"] == $mybb->input["mpcommentsopen"] && isset($mybb->input["mpwhocancomment"]) && $mybb->user["mpwhocancomment"] == $mybb->input["mpwhocancomment"] && isset($mybb->input["mpcommentnotification"]) && $mybb->user["mpcommentnotification"] == $mybb->input["mpcommentnotification"] && isset($mybb->input["mpcommentsapprove"]) && $mybb->user["mpcommentsapprove"] == $mybb->input["mpcommentsapprove"]) {
2103 return;
2104 }
2105
2106 $update_array = array();
2107 // in_array is also a great way to escape strings without calling the database :D
2108 if (isset($mybb->input["mpcommentsopen"]) && in_array($mybb->input["mpcommentsopen"], array("0", "1"))) {
2109 $update_array["mpcommentsopen"] = $mybb->input["mpcommentsopen"];
2110 } elseif (!isset($mybb->input["mpcommentsopen"])) {
2111 $update_array["mpcommentsopen"] = "0";
2112 }
2113
2114 if (in_array($mybb->input["mpwhocancomment"], array("0", "1", "2"))) {
2115 $update_array["mpwhocancomment"] = $mybb->input["mpwhocancomment"];
2116 }
2117
2118 if (isset($mybb->input["mpcommentnotification"]) && in_array($mybb->input["mpcommentnotification"], array("0", "1"))) {
2119 $update_array["mpcommentnotification"] = $mybb->input["mpcommentnotification"];
2120 } elseif (!isset($mybb->input["mpcommentnotification"])) {
2121 $update_array["mpcommentnotification"] = "0";
2122 }
2123
2124 if (isset($mybb->input["mpcommentsapprove"]) && in_array($mybb->input["mpcommentsapprove"], array("0", "1"))) {
2125 $update_array["mpcommentsapprove"] = $mybb->input["mpcommentsapprove"];
2126 } elseif (!isset($mybb->input["mpcommentsapprove"])) {
2127 $update_array["mpcommentsapprove"] = "0";
2128 }
2129
2130 if (count($update_array) > 0) {
2131 $db->update_query("users", $update_array, "uid='{$mybb->user['uid']}'", "1");
2132 }
2133 }
2134
2135 public function usercp_options_start() {
2136 global $templates, $myprofile_comments_usercp, $lang, $mybb;
2137 MyProfileUtils::lang_load_myprofile();
2138 $mpcommentsopen = $mybb->user["mpcommentsopen"] == "1" ? "checked=\"checked\"" : "";
2139 $nobodycanleavecomments = $mybb->user["mpwhocancomment"] == "0" ? "selected=\"selected\"" : "";
2140 $friendlistcanleavecomment = $mybb->user["mpwhocancomment"] == "1" ? "selected=\"selected\"" : "";
2141 $anyonecanleavecomments = $mybb->user["mpwhocancomment"] == "2" ? "selected=\"selected\"" : "";
2142 $mpcommentnotification = $mybb->user["mpcommentnotification"] == "1" ? "checked=\"checked\"" : "";
2143 $mpcommentsapprove = $mybb->user["mpcommentsapprove"] == "1" ? "checked=\"checked\"" : "";
2144 eval("\$myprofile_comments_usercp = \"" . $templates->get("myprofile_comments_usercp") . "\";");
2145 }
2146
2147 public function modcp_nav() {
2148 global $templates, $nav_myprofilecomments, $lang, $mybb;
2149 if ($mybb->usergroup["canmanagecomments"] == "1") {
2150 MyProfileUtils::lang_load_myprofile();
2151 eval("\$nav_myprofilecomments = \"" . $templates->get("myprofile_modcp_nav_comments") . "\";");
2152 }
2153 }
2154
2155 public function modcp_start() {
2156 global $mybb, $lang, $theme, $settings, $templates, $headerinclude, $header, $modcp_nav;
2157 if (isset($mybb->input["action"]) && is_string($mybb->input["action"])) {
2158 $action = $mybb->input["action"];
2159 if ($action == "myprofilecomments") {
2160 if ($mybb->usergroup["canmanagecomments"] == "0") {
2161 error_no_permission();
2162 } else {
2163 add_breadcrumb($lang->mcp_nav_users, "modcp.php?action=myprofile");
2164 eval("\$myprofile = \"" . $templates->get("myprofile_comments_modcp_start") . "\";");
2165 output_page($myprofile);
2166 }
2167 }
2168 }
2169 }
2170
2171 /**
2172 * This will try to guess the exact page on which the comment identified by $cid exists.
2173 * @param int $cid The comment ID
2174 * @param boolean $href whether or not to surround the link with an anchor
2175 * @param string $link_name if $href is enabled, enter the link name that will be displayed between the anchor opening and closing tags
2176 * @param string $other_params if you wish to include some other parameters such as target="_blank", do that here, include a space at the beginning
2177 * @return string the comment link, or an empty string if no comment has been found
2178 */
2179 public function build_comment_link($cid, $href = false, $link_name = "", $other_params = "") {
2180 global $db, $settings, $mybb;
2181 $cid = (int) $cid;
2182 //SELECT a.*, (select count(*) from `mybb_myprofilecomments` b where a.cid >= b.cid) as cnt FROM `mybb_myprofilecomments` a WHERE a.cid='2'
2183 $query = $db->query("SELECT a.*, (SELECT COUNT(*) FROM " . TABLE_PREFIX . "myprofilecomments b WHERE a.cid <= b.cid) AS rownum FROM " . TABLE_PREFIX . "myprofilecomments a WHERE a.cid='{$cid}'");
2184
2185 if ($db->num_rows($query) != 1) {
2186 return "";
2187 }
2188 $comment = $db->fetch_array($query);
2189 $user = get_user($comment["userid"]);
2190 $page = ceil($comment["rownum"] / $settings["mpcommentsperpage"]);
2191 $profile_link = "{$mybb->settings['bburl']}/" . get_profile_link($user["uid"]);
2192 if ($settings["mpcommentsajaxenabled"]) {
2193 $complement = "#comments/" . $page . "/highlight/" . $cid;
2194 } else {
2195 $complement = "&page={$page}&highlight={$cid}";
2196 }
2197 $profile_link .= $complement;
2198 if ($href) {
2199 $profile_link = "<a href=\"{$profile_link}\"{$other_params}>{$link_name}</a>";
2200 }
2201 return $profile_link;
2202 }
2203
2204 public function parse_comment($message) {
2205 global $mybb, $parser, $settings;
2206
2207 if (!isset($parser)) {
2208 require_once MYBB_ROOT . "inc/class_parser.php";
2209 $parser = new postParser;
2210 }
2211
2212 $options = array(
2213 "allow_html" => (int) $settings["mpcommentsallowhtml"],
2214 "allow_mycode" => (int) $settings["mpcommentsallowmycode"],
2215 "allow_smilies" => (int) $settings["mpcommentsallowsmilies"],
2216 "allow_imgcode" => (int) $settings["mpcommentsallowimg"],
2217 "allow_videocode" => (int) $settings["mpcommentsallowvideo"],
2218 "filter_badwords" => (int) $settings["mpcommentsfilterbadwords"]
2219 );
2220
2221 return $parser->parse_message($message, $options);
2222 }
2223
2224 public function user_statistics($uid) {
2225 global $db;
2226 $result = array();
2227 $query = $db->simple_select("myprofilecomments", "COUNT(*) as `sent`", "cuid='{$uid}'", array("limit" => 1));
2228 $result["sent"] = $db->fetch_field($query, "sent");
2229 $query = $db->simple_select("myprofilecomments", "COUNT(*) as `received`", "userid='{$uid}'", array("limit" => 1));
2230 $result["received"] = $db->fetch_field($query, "received");
2231 $result["total"] = $result["sent"] + $result["received"];
2232 return $result;
2233 }
2234
2235 public function tools_permissionviewer_general_zero(&$groupzerogreater) {
2236 $groupzerogreater[] = "commentsperday";
2237 }
2238
2239 private function __construct() {
2240
2241 }
2242
2243 private function __clone() {
2244
2245 }
2246
2247 public static function myalerts_can_integrate() {
2248 global $db, $cache;
2249 if (function_exists("myalerts_info")) {
2250 $info = myalerts_info();
2251 if($info["version"] >= "2.0.0" && $db->table_exists("alert_types")) {
2252 // if our plugin is already integrated for some weird reason, let it be!
2253 $myalerts_plugins = $cache->read('mybbstuff_myalerts_alert_types');
2254 return !isset($myalerts_plugins[MyProfileCommentsMyAlertsFormatter::alert_type_code()]);
2255 }
2256 }
2257 return false;
2258 }
2259
2260 public static function myalerts_can_deintegrate() {
2261 global $db;
2262 if (function_exists("myalerts_info")) {
2263 $info = myalerts_info();
2264 return $info["version"] >= "2.0.0" && $db->table_exists("alert_types");
2265 }
2266 return false;
2267 }
2268
2269 /**
2270 *
2271 * @return MyProfileComments
2272 */
2273 public static function get_instance() {
2274 if (null === self::$instance) {
2275 self::$instance = new self();
2276 }
2277 return self::$instance;
2278 }
2279
2280}