Advertisement
Guest User

Untitled

a guest
May 25th, 2013
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 58.35 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * MyShoutBox for MyBB 1.4.x (MYBB_ROOT/inc/plugins/shoutbox.php)
  5.  * Copyright © 2009 Pirata Nervo, All Rights Reserved!
  6.  *
  7.  * Website: http://www.mybb-plugins.com
  8.  * License:
  9.  * "This plugin is offered "as is" with no guarantees.
  10.  * You may redistribute it provided the code and credits
  11.  * remain intact with no changes. This is not distributed
  12.  * under GPL, so you may NOT re-use the code in any other
  13.  * module, plugin, or program.
  14.  * ~~Shoutbox Exploit-fix v1 by Obloquy
  15.  *
  16.  * Free for non-commercial purposes!"
  17.  *
  18.  * This plugin is based off Asad Niazi's spicefuse shoutbox plugin.
  19.  * Spicefuse Shoutbox website: www.spicefuse.com
  20.  *
  21.  *
  22.  * File description: MyShoutbox main file
  23.  */
  24.  
  25.  
  26. if(!defined('IN_MYBB'))
  27.     die('This file cannot be accessed directly.');
  28.  
  29. $plugins->add_hook("index_end", "myshoutbox_index");
  30. $plugins->add_hook("xmlhttp", "myshoutbox_load");
  31. $plugins->add_hook("pre_output_page", "myshoutbox_output_control");
  32.  
  33. $plugins->add_hook('admin_load', 'myshoutbox_admin');
  34. $plugins->add_hook('admin_tools_menu', 'myshoutbox_admin_tools_menu');
  35. $plugins->add_hook('admin_tools_action_handler', 'myshoutbox_admin_tools_action_handler');
  36. $plugins->add_hook('admin_tools_permissions', 'myshoutbox_admin_permissions');
  37.  
  38. // reported shouts notice
  39. $plugins->add_hook('admin_home_menu', 'myshoutbox_admin_home_menu');
  40.  
  41. function myshoutbox_info()
  42. {
  43.     return array(
  44.         'name'          => 'MyShoutbox',
  45.         'description'   => 'A powerful AJAX shoutbox for MyBB.',
  46.         'website'       => 'http://consoleaddicted.com/',
  47.         'author'        => 'Pirata Nervo',
  48.         'authorsite'    => 'http://consoleaddicted.com/',
  49.         'version'       => '1.7',
  50.         'guid'          => 'c7e5e6c1a57f0639ea52d7813b23579f',
  51.         'compatibility' => '14*,15*,16*',
  52.     );
  53. }
  54.  
  55. function myshoutbox_install()
  56. {
  57.     global $db;
  58.    
  59.     $shoutbox_group = array(
  60.         "name"      => "mysb_shoutbox",
  61.         "title"     => "MyShoutbox",
  62.         "description"   => "Settings for the MyShoutbox plugin.",
  63.         "disporder" => "1",
  64.         "isdefault" => "no",
  65.     );
  66.    
  67.     $db->insert_query("settinggroups", $shoutbox_group);
  68.     $gid = $db->insert_id();
  69.    
  70.     $shoutbox_setting_1 = array(
  71.         "name"      => "mysb_shouts_main",
  72.         "title"     => "# of Shouts to display",
  73.         "description"   => "The maximum number of shouts you want to be displayed.",
  74.         "optionscode"   => "text",
  75.         "value"     => "30",
  76.         "disporder" => "1",
  77.         "gid"       => intval($gid),
  78.     );
  79.    
  80.     $shoutbox_setting_2 = array(
  81.         "name"      => "mysb_refresh_interval",
  82.         "title"     => "Refresh Interval",
  83.         "description"   => "How many seconds before the shoutbox is reloaded using AJAX transparently. ",
  84.         "optionscode"   => "text",
  85.         "value"     => "15",
  86.         "disporder" => "2",
  87.         "gid"       => intval($gid),
  88.     );
  89.    
  90.     $shoutbox_setting_3 = array(
  91.         "name"      => "mysb_allow_mycode",
  92.         "title"     => "Allow MyCode?",
  93.         "description"   => "Allow MyBB code in shouts to format text using [b], [i] etc..?",
  94.         "optionscode"   => "yesno",
  95.         "value"     => "yes",
  96.         "disporder" => "3",
  97.         "gid"       => intval($gid),
  98.     );
  99.    
  100.     $shoutbox_setting_4 = array(
  101.         "name"      => "mysb_allow_smilies",
  102.         "title"     => "Allow Smilies?",
  103.         "description"   => "Allow smilies in shouts?",
  104.         "optionscode"   => "yesno",
  105.         "value"     => "yes",
  106.         "disporder" => "4",
  107.         "gid"       => intval($gid),
  108.     );
  109.    
  110.     $shoutbox_setting_5 = array(
  111.         "name"      => "mysb_allow_imgcode",
  112.         "title"     => "Allow IMGCode?",
  113.         "description"   => "Allow images in shoutbox? Note: Some can post too big images and mess up your layout.",
  114.         "optionscode"   => "yesno",
  115.         "value"     => "no",
  116.         "disporder" => "5",
  117.         "gid"       => intval($gid),
  118.     );
  119.    
  120.     $shoutbox_setting_6 = array(
  121.         "name"      => "mysb_height",
  122.         "title"     => "ShoutBox Height",
  123.         "description"   => "Set the height for shoutbox here.",
  124.         "optionscode"   => "text",
  125.         "value"     => "125",
  126.         "disporder" => "6",
  127.         "gid"       => intval($gid),
  128.     );
  129.    
  130.     $shoutbox_setting_7 = array(
  131.         "name"      => "mysb_datetime",
  132.         "title"     => "ShoutBox Date/Time",
  133.         "description"   => "PHP date time format for shoutbox. <a href=\"http://php.net/date\" target=\"_blank\">check here</a> for more info.",
  134.         "optionscode"   => "text",
  135.         "value"     => "d-m-H:i",
  136.         "disporder" => "7",
  137.         "gid"       => intval($gid),
  138.     );
  139.    
  140.     $shoutbox_setting_8 = array(
  141.         "name"      => "mysb_full_ppage",
  142.         "title"     => "Shouts per page on full view?",
  143.         "description"   => "The number of shouts you want to be displayed, per page, on the full shoutbox view.",
  144.         "optionscode"   => "text",
  145.         "value"     => "50",
  146.         "disporder" => "8",
  147.         "gid"       => intval($gid),
  148.     );
  149.    
  150.     $shoutbox_setting_9 = array(
  151.         "name"      => "mysb_allow_smods",
  152.         "title"     => "Allow super moderators to delete?",
  153.         "description"   => "Allow super mods to delete shouts in the shoutbox?",
  154.         "optionscode"   => "yesno",
  155.         "value"     => "yes",
  156.         "disporder" => "9",
  157.         "gid"       => intval($gid),
  158.     );
  159.    
  160.     $shoutbox_setting_10 = array(
  161.         "name"      => "mysb_allow_html",
  162.         "title"     => "Allow HTML?",
  163.         "description"   => "Allow html in shoutbox?",
  164.         "optionscode"   => "yesno",
  165.         "value"     => "no",
  166.         "disporder" => "10",
  167.         "gid"       => intval($gid),
  168.     );
  169.    
  170.     $shoutbox_setting_11 = array(
  171.         "name"      => "mysb_allow_video",
  172.         "title"     => "Allow Videos?",
  173.         "description"   => "Allow videos in shoutbox? (MyBB 1.6 only)",
  174.         "optionscode"   => "yesno",
  175.         "value"     => "no",
  176.         "disporder" => "11",
  177.         "gid"       => intval($gid),
  178.     );
  179.    
  180.     $shoutbox_setting_12 = array(
  181.         "name"      => "mysb_flood_time",
  182.         "title"     => "Flood Check?",
  183.         "description"   => "Add a flood check for everyone but the moderators. Enter a time in seconds here. Enter 0 to disable.",
  184.         "optionscode"   => "text",
  185.         "value"     => "5",
  186.         "disporder" => "12",
  187.         "gid"       => intval($gid),
  188.     );
  189.    
  190.     $shoutbox_setting_13 = array(
  191.         "name"      => "mysb_usergroups",
  192.         "title"     => "Groups allowed to view the shoutbox",
  193.         "description"   => "The groupd ids of the users allowed to view the shoutbox. (Seperated by a comma. Leave blank to allow all.)",
  194.         "optionscode"   => "text",
  195.         "value"     => "",
  196.         "disporder" => "13",
  197.         "gid"       => intval($gid),
  198.     );
  199.    
  200.     $shoutbox_setting_14 = array(
  201.         "name"      => "mysb_additional_groups",
  202.         "title"     => "Check additional groups?",
  203.         "description"   => "Set this to yes if you want additional groups to be checked. (This setting will only take effect if the above one is not blank)",
  204.         "optionscode"   => "yesno",
  205.         "value"     => "no",
  206.         "disporder" => "14",
  207.         "gid"       => intval($gid),
  208.     );
  209.        
  210.     $shoutbox_setting_15 = array(
  211.         "name"      => "mysb_allow_mods",
  212.         "title"     => "Allow moderators to delete?",
  213.         "description"   => "Allow moderators to delete shouts in the shoutbox?",
  214.         "optionscode"   => "yesno",
  215.         "value"     => "yes",
  216.         "disporder" => "15",
  217.         "gid"       => intval($gid),
  218.     );
  219.    
  220.     $shoutbox_setting_16 = array(
  221.         "name"      => "mysb_display_message",
  222.         "title"     => "Do you want to show a message to banned users?",
  223.         "description"   => "Do you want to show a message to banned users? The message can be changed in the language files of MyShoutbox. (it is displayed instead of the shoutbox)",
  224.         "value"     => 1,
  225.         "optionscode"   => "yesno",
  226.         "disporder" => "16",
  227.         "gid"       => intval($gid),
  228.     );
  229.    
  230.     $shoutbox_setting_17 = array(
  231.         "name"      => "mysb_text_size",
  232.         "title"     => "Font size",
  233.         "description"   => "Enter the font size of the shouts. Default is 12.",
  234.         "value"     => 12,
  235.         "optionscode"   => "text",
  236.         "disporder" => "17",
  237.         "gid"       => intval($gid),
  238.     );
  239.    
  240.     $shoutbox_setting_18 = array(
  241.         "name"          => "mysb_key",
  242.         "title"         => "Key",
  243.         "description"   => "Enter a random string for your key. All {myshoutbox_KEY} entries found in your templates or anywhere else will be replaced with the actual shoutbox.",
  244.         "value"         => "abcd",
  245.         "optionscode"   => "text",
  246.         "disporder"     => "18",
  247.         "gid"           => intval($gid),
  248.     );
  249.    
  250.     $db->insert_query("settings", $shoutbox_setting_1);
  251.     $db->insert_query("settings", $shoutbox_setting_2);
  252.     $db->insert_query("settings", $shoutbox_setting_3);
  253.     $db->insert_query("settings", $shoutbox_setting_4);
  254.     $db->insert_query("settings", $shoutbox_setting_5);
  255.     $db->insert_query("settings", $shoutbox_setting_6);
  256.     $db->insert_query("settings", $shoutbox_setting_7);
  257.     $db->insert_query("settings", $shoutbox_setting_8);
  258.     $db->insert_query("settings", $shoutbox_setting_9);
  259.     $db->insert_query("settings", $shoutbox_setting_10);
  260.     $db->insert_query("settings", $shoutbox_setting_11);
  261.     $db->insert_query("settings", $shoutbox_setting_12);
  262.     $db->insert_query("settings", $shoutbox_setting_13);
  263.     $db->insert_query("settings", $shoutbox_setting_14);
  264.     $db->insert_query("settings", $shoutbox_setting_15);
  265.     $db->insert_query("settings", $shoutbox_setting_16);
  266.     $db->insert_query("settings", $shoutbox_setting_17);
  267.     $db->insert_query("settings", $shoutbox_setting_18);
  268.    
  269.     // create table
  270.     $db->write_query("CREATE TABLE `".TABLE_PREFIX."mysb_shouts` (
  271.       `id` int(10) NOT NULL auto_increment,
  272.       `uid` int(10) NOT NULL,
  273.       `shout_msg` text NOT NULL,
  274.       `shout_date` int(10) NOT NULL,
  275.       `shout_ip` varchar(30) NOT NULL,
  276.       `hidden` varchar(10) NOT NULL,
  277.       PRIMARY KEY  (`id`)
  278.         ) ENGINE=MyISAM");
  279.    
  280.     // create reports table
  281.     $db->write_query("CREATE TABLE `".TABLE_PREFIX."mysb_reports` (
  282.       `rid` int(10) NOT NULL auto_increment,
  283.       `username` varchar(100) NOT NULL DEFAULT '',
  284.       `uid` int(10) NOT NULL DEFAULT 0,
  285.       `reason` varchar(255) NOT NULL DEFAULT '',
  286.       `date` bigint(30) NOT NULL DEFAULT 0,
  287.       `sid` int(10) NOT NULL DEFAULT 0,
  288.       `marked` tinyint(1) NOT NULL DEFAULT 0,
  289.       `author_uid` int(10) NOT NULL DEFAULT 0,
  290.       `author_username` varchar(30) NOT NULL DEFAULT '',
  291.       PRIMARY KEY  (`rid`), KEY(`date`)
  292.         ) ENGINE=MyISAM");
  293.        
  294.     $db->write_query("INSERT INTO ".TABLE_PREFIX."mysb_shouts VALUES (NULL, 1, 'Test Shout! Without any shout, shoutbox will display Loading... forever.. you need at least one shout, so here it is.', ".time().", '127.0.0.1', 'no')");
  295.    
  296.     $db->write_query("ALTER TABLE `".TABLE_PREFIX."users` ADD `mysb_banned` smallint(1) NOT NULL DEFAULT 0;");
  297.     $db->write_query("ALTER TABLE `".TABLE_PREFIX."users` ADD `mysb_banned_reason` varchar(255) NOT NULL DEFAULT '';");
  298.    
  299.     // rebuild settings...
  300.     rebuild_settings();
  301. }
  302.  
  303. function myshoutbox_activate()
  304. {
  305.     global $db, $mybb;
  306.    
  307.     // load templates
  308.     $mysb_shoutbox_tpl = '
  309.     <script type="text/javascript" src="jscripts/myshoutbox.js?ver=1400"></script>
  310. <style type="text/css">
  311.  
  312. .shoutbox {
  313.     margin: 0;
  314.     padding: 0;
  315.     left: 0;
  316. }
  317.  
  318.  
  319. li.shoutbox_normal {
  320.     list-style: none;
  321.     margin: 0;
  322.     position: relative;
  323.     cursor: pointer;
  324.     color: transparent;
  325.     display: inline ;
  326.     border: 1px;
  327.     border-color: #FFFFFF;
  328. }
  329.  
  330. li.shoutbox_color {
  331.     list-style: none;
  332.     position: relative;
  333.     cursor: pointer;
  334.     color: transparent;
  335.     display: inline ;
  336.     border: 0px;
  337.     float: left;
  338.     margin: 1px;
  339. }
  340.  
  341. .shoutbox_button_color a {
  342.     width: 9px;
  343.     height: 9px;
  344.     display: block;
  345.     border: 1px solid #FFF;
  346. }
  347.  
  348. </style>
  349.  
  350. <table border="0" cellspacing="1" cellpadding="4" class="tborder">
  351. <thead>
  352. <tr>
  353. <td class="thead" colspan="2">
  354. <div class="expcolimage"><img src="{$theme[\'imgdir\']}/collapse.gif" id="shoutbox_img" class="expander" alt="[-]" /></div>
  355. <div><strong>{$lang->mysb_shoutbox}</strong> (<a href="index.php?action=full_shoutbox">{$lang->mysb_fullsbox}</a> - <a href="pspshoutbox.php">{$lang->mysb_portable}</a>)<br /></div>
  356. </td>
  357. </tr>
  358. </thead>
  359.  
  360. <tbody id="shoutbox_e">
  361. <tr>
  362. <td class="trow2" width="66%" align="center"><form onsubmit="ShoutBox.postShout(); $(\'shout_data\').value = \'\'; return false;">{$lang->mysb_shout} <input type="text" id="shout_data" size="50" /> - <input type="submit" value="{$lang->mysb_shoutnow}" id="shouting-status" /></form></td>
  363. <td class="trow2" width="12%" align="center">{$lang->mysb_options}</td>
  364. </tr>
  365. <tr>
  366. <td class="trow1" width="76%"><div id="shoutbox_data" style="height: {$mybb->settings[\'mysb_height\']}px; overflow: auto;">{$lang->mysb_loading}</div></td>
  367. <td class="trow1" width="12%" align="center">
  368.     <a style="cursor: pointer;" id="smilies" onclick="window.open(\'misc.php?action=smilies&amp;popup=true&amp;editor=clickableEditor\',\'{$lang->mysb_smilies}\',\'scrollbars=yes, menubar=no,width=460,height=360,toolbar=no\');">{$lang->mysb_smilies}</a>
  369.     <br />
  370.     <a style="cursor: pointer;" onclick="window.open(\'shoutbox.php\',\'{$lang->mysb_shoutbox}\',\'scrollbars=yes, menubar=no,width=825,height=449,toolbar=no\');">{$lang->mysb_popup_shoutbox}</a>
  371. </td>
  372. </tr>
  373. </tbody>
  374. </table>
  375.  
  376. <script type="text/javascript">
  377. ShoutBox.refreshInterval = {$mybb->settings[\'mysb_refresh_interval\']};
  378. ShoutBox.MaxEntries = {$mybb->settings[\'mysb_shouts_main\']};
  379. ShoutBox.lang = [\'{$lang->mysb_posting}\', \'{$lang->mysb_shoutnow}\', \'{$lang->mysb_loading}\', \'{$lang->mysb_flood_check}\', \'{$lang->mysb_no_perform}\', \'{$lang->mysb_already_sent}\', \'{$lang->mysb_deleted}\', \'{$lang->mysb_invalid}\', \'{$lang->mysb_self}\', \'{$lang->mysb_report_invalid_sid}\', \'{$lang->mysb_shout_reported}\', \'{$lang->mysb_shout_already_reported}\'];
  380. {$extra_js}
  381. Event.observe(window, \'load\', ShoutBox.showShouts);
  382. </script>
  383.  
  384. <br />';
  385.  
  386.     $mysb_boxfull_tpl = '<html>
  387. <head>
  388. <title>Full Shoutbox</title>
  389. {$headerinclude}
  390. </head>
  391. <body>
  392. {$header}
  393.  
  394. <table border="0" cellspacing="1" cellpadding="4" class="tborder">
  395. <thead>
  396. <tr>
  397. <td class="thead" colspan="2">
  398. <div><strong>{$lang->mysb_shoutbox}</strong><br /></div>
  399. </td>
  400. </tr>
  401. </thead>
  402.  
  403. <tr>
  404. {$mysb_shoutbox_data}
  405. </tr>
  406. </table>
  407.  
  408. <br />
  409.  
  410. <center>$multipage</center>
  411.  
  412. {$footer}
  413. </body>
  414. </html>
  415. ';
  416.  
  417.     $mysb_popup_shoutbox_tpl = '
  418.     <html>
  419. <head>
  420. <title>{$lang->mysb_shoutbox}</title>
  421. {$headerinclude}
  422. <script type="text/javascript" src="jscripts/myshoutbox.js?ver=1400"></script>
  423. </head>
  424. <body>
  425.  
  426. <style type="text/css">
  427.  
  428. .shoutbox {
  429.     margin: 0;
  430.     padding: 0;
  431.     left: 0;
  432. }
  433.  
  434.  
  435. li.shoutbox_normal {
  436.     list-style: none;
  437.     margin: 0;
  438.     position: relative;
  439.     cursor: pointer;
  440.     color: transparent;
  441.     display: inline ;
  442.     border: 1px;
  443.     border-color: #FFFFFF;
  444. }
  445.  
  446. li.shoutbox_color {
  447.     list-style: none;
  448.     position: relative;
  449.     cursor: pointer;
  450.     color: transparent;
  451.     display: inline ;
  452.     border: 0px;
  453.     float: left;
  454.     margin: 1px;
  455. }
  456.  
  457. .shoutbox_button_color a {
  458.     width: 9px;
  459.     height: 9px;
  460.     display: block;
  461.     border: 1px solid #FFF;
  462. }
  463.  
  464. </style>
  465.  
  466. <table border="0" cellspacing="1" cellpadding="4" class="tborder">
  467. <thead>
  468. <tr>
  469. <td class="thead" colspan="2">
  470. <div class="expcolimage"><img src="{$theme[\'imgdir\']}/collapse.gif" id="shoutbox_img" class="expander" alt="[-]" /></div>
  471. <div><strong>{$lang->mysb_shoutbox}</strong> (<a href="index.php?action=full_shoutbox">{$lang->mysb_fullsbox}</a> - <a href="pspshoutbox.php">{$lang->mysb_portable}</a>)<br /></div>
  472. </td>
  473. </tr>
  474. </thead>
  475.  
  476. <tbody id="shoutbox_e">
  477. <tr>
  478. <td class="trow2" width="66%" align="center"><form onSubmit="ShoutBox.postShout(); $(\'shout_data\').value = \'\'; return false;">{$lang->mysb_shout} <input type="text" id="shout_data" size="50" /> - <input type="submit" value="{$lang->mysb_shoutnow}" id="shouting-status" /></form></td>
  479. <td class="trow2" width="12%" align="center">{$lang->mysb_options}</td>
  480. </tr>
  481. <tr>
  482. <td class="trow1" width="76%"><div align="left" id="shoutbox_data" style="height: {$mybb->settings[\'mysb_height\']}px; overflow: auto;">{$lang->mysb_loading}</div></td>
  483.  <td class="trow1" width="12%" align="center">
  484.     <a style="cursor: pointer;" id="smilies" onclick="window.open(\'misc.php?action=smilies&popup=true&editor=clickableEditor\',\'{$lang->mysb_smilies}\',\'scrollbars=yes, menubar=no,width=460,height=360,toolbar=no\');">{$lang->mysb_smilies}</a>
  485.     <br />
  486.     <a style="cursor: pointer;" onclick="window.open(\'shoutbox.php\',\'{$lang->mysb_shoutbox}\',\'scrollbars=yes, menubar=no,width=825,height=449,toolbar=no\');">{$lang->mysb_popup_shoutbox}</a>
  487. </td>
  488. </tbody>
  489. </table>
  490.  
  491. <script>
  492. ShoutBox.refreshInterval = {$mybb->settings[\'mysb_refresh_interval\']};
  493. ShoutBox.MaxEntries = {$mybb->settings[\'mysb_shouts_main\']};
  494. ShoutBox.lang = [\'{$lang->mysb_posting}\', \'{$lang->mysb_shoutnow}\', \'{$lang->mysb_loading}\', \'{$lang->mysb_flood_check}\', \'{$lang->mysb_no_perform}\', \'{$lang->mysb_already_sent}\', \'{$lang->mysb_deleted}\', \'{$lang->mysb_invalid}\', \'{$lang->mysb_self}\', \'{$lang->mysb_report_invalid_sid}\', \'{$lang->mysb_shout_reported}\', \'{$lang->mysb_shout_already_reported}\'];
  495. {$extra_js}
  496. Event.observe(window, \'load\', ShoutBox.showShouts);
  497. </script>
  498.  
  499. </body>
  500. </html>';
  501.  
  502.     $mysb_portable_tpl = '
  503.     <html>
  504. <head>
  505. <title>{$lang->mysb_shoutbox}</title>
  506. {$headerinclude}
  507. <!--<SCRIPT>var timeID = setTimeout("document.forms[0].submit()", 30000)</SCRIPT>-->
  508. </head>
  509. <body>
  510.  
  511. <form id="0" action="pspshoutbox.php"></form>
  512.  
  513. <table border="0" cellspacing="1" cellpadding="4" class="tborder">
  514. <thead>
  515. <tr>
  516. <td class="thead" colspan="2">
  517. <form id="1" action="pspshoutbox.php?action=shout" method="post">{$lang->mysb_shout} <input type="hidden" name="postcode" value="{$mybb->post_code}" /> <input type="text" name="shout_data" size="50" /> - <input type="submit" value="{$lang->mysb_shoutnow}" id="shouting-status" /></form>
  518. </td>
  519. </tr>
  520. <tr>
  521. <td class="thead" colspan="2">
  522. <div><strong>{$lang->mysb_shoutbox}</strong> - <!--<a href="pspshoutbox.php">Refresh</a> --><small>(<a href="pspshoutbox.php?action=refresh">Refresh</a>)</small> <br /></div>
  523. </td>
  524. </tr>
  525. </thead>
  526.  
  527. <tr>
  528. {$mysb_shoutbox_data}
  529. </tr>
  530. </table>
  531.  
  532. </body>
  533.  
  534. </html>';
  535.  
  536.     $mysb_banned = '<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
  537. <tr>
  538. <td class="thead"><strong>{$lang->mysb_shoutbox}</strong></td>
  539. </tr>
  540. <tr>
  541. <td class="trow1">{$lang->mysb_error_ban}</td>
  542. </tr>
  543. </table><br />';
  544.  
  545.    
  546.     // insert templates
  547.     $db->insert_query('templates', array('title' => 'mysb_shoutbox', 'sid' => '-1', 'template' => $db->escape_string($mysb_shoutbox_tpl), 'version' => '1411', 'status' => '', 'dateline' => TIME_NOW));
  548.     $db->insert_query('templates', array('title' => 'mysb_shoutbox_full', 'sid' => '-1', 'template' => $db->escape_string($mysb_boxfull_tpl), 'version' => '1411', 'status' => '', 'dateline' => TIME_NOW));
  549.     $db->insert_query('templates', array('title' => 'mysb_shoutbox_popup', 'sid' => '-1', 'template' => $db->escape_string($mysb_popup_shoutbox_tpl), 'version' => '1411', 'status' => '', 'dateline' => TIME_NOW));
  550.     $db->insert_query('templates', array('title' => 'mysb_shoutbox_psp', 'sid' => '-1', 'template' => $db->escape_string($mysb_portable_tpl), 'version' => '1411', 'status' => '', 'dateline' => TIME_NOW));
  551.     $db->insert_query('templates', array('title' => 'mysb_shoutbox_banned', 'sid' => '-1', 'template' => $db->escape_string($mysb_banned), 'version' => '1411', 'status' => '', 'dateline' => TIME_NOW));
  552.    
  553.     require_once MYBB_ROOT.'inc/adminfunctions_templates.php';
  554.    
  555.     find_replace_templatesets('index', '#{\$boardstats}#', "{myshoutbox_".$mybb->settings['mysb_key']."}\n{\$boardstats}");
  556.  
  557. }
  558.  
  559. function myshoutbox_uninstall()
  560. {
  561.     global $db;
  562.    
  563.     $db->write_query("DROP TABLE ".TABLE_PREFIX."mysb_shouts");
  564.     $db->write_query("DROP TABLE ".TABLE_PREFIX."mysb_reports");
  565.     $db->write_query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name = 'mysb_shoutbox'");
  566.     $db->write_query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('mysb_shouts_main','mysb_refresh_interval','mysb_allow_mycode',
  567.                             'mysb_allow_smilies','mysb_allow_imgcode','mysb_height','mysb_datetime','mysb_full_ppage','mysb_allow_smods',
  568.                             'mysb_allow_html','mysb_flood_time','mysb_usergroups','mysb_additional_groups','mysb_allow_mods','mysb_display_message','mysb_allow_video')");
  569.    
  570.     $db->write_query("ALTER TABLE `".TABLE_PREFIX."users` DROP `mysb_banned`;");
  571.     $db->write_query("ALTER TABLE `".TABLE_PREFIX."users` DROP `mysb_banned_reason`;");
  572. }
  573.  
  574. function myshoutbox_is_installed()
  575. {
  576.     global $db;
  577.    
  578.     if ($db->table_exists('mysb_shouts'))
  579.         return true;
  580.    
  581.     return false;
  582. }
  583.  
  584. function myshoutbox_deactivate()
  585. {
  586.     global $db, $mybb;
  587.     $db->write_query("DELETE FROM ".TABLE_PREFIX."templates WHERE title IN('mysb_shoutbox','mysb_shoutbox_full','mysb_shoutbox_popup','mysb_shoutbox_popup_full','mysb_shoutbox_psp','mysb_shoutbox_banned') AND sid='-1'");
  588.    
  589.     require_once MYBB_ROOT.'inc/adminfunctions_templates.php';
  590.  
  591.     find_replace_templatesets('index', '#{myshoutbox_'.$mybb->settings['mysb_key'].'}#', '', 0);
  592. }
  593.  
  594. function myshoutbox_load()
  595. {
  596.     global $mybb, $lang, $charset;
  597.  
  598.     $lang->load("myshoutbox");
  599.    
  600.     // Send our headers.
  601.     header("Content-type: text/html; charset={$charset}");
  602.    
  603.     switch ($mybb->input['action'])
  604.     {
  605.         case 'show_shouts':
  606.             myshoutbox_show_shouts(intval($mybb->input['last_id']));
  607.         break;
  608.            
  609.         case 'add_shout':
  610.             myshoutbox_add_shout();
  611.         break;
  612.        
  613.         case 'delete_shout':
  614.             myshoutbox_delete_shout(intval($mybb->input['id']));
  615.         break;
  616.            
  617.         case 'remove_shout':
  618.             myshoutbox_remove_shout(intval($mybb->input['id']));
  619.         break;
  620.        
  621.         case 'recover_shout':
  622.             myshoutbox_recover_shout(intval($mybb->input['id']));
  623.         break;
  624.        
  625.         case 'report_shout':
  626.             myshoutbox_report_shout($mybb->input['reason'], intval($mybb->input['sid']));
  627.         break;
  628.     }
  629. }
  630.  
  631. function myshoutbox_psp_show()
  632. {
  633.     global $db, $mybb, $templates, $lang, $footer, $headerinclude, $header, $charset;
  634.    
  635.     $lang->load('myshoutbox');
  636.    
  637.     // Send our headers.
  638.     header("Content-type: text/html; charset={$charset}");
  639.    
  640.     // Make navigation
  641.     add_breadcrumb($lang->mysb_shoutbox, "pspshoutbox.php");
  642.     $per_page = intval($mybb->settings['mysb_full_ppage']);
  643.  
  644.     // pagination
  645.     $query = $db->simple_select("mysb_shouts", "COUNT(*) as shouts_count");
  646.     $shouts_count = $db->fetch_field($query, 'shouts_count');
  647.    
  648.     // Pagination
  649.     $per_page = intval($mybb->settings['mysb_full_ppage']);;
  650.     if(intval($mybb->input['page']) > 0)
  651.     {
  652.         $page = (int)$mybb->input['page'];
  653.         $start = ($page-1) * $per_page;
  654.         $pages = $shouts_count / $per_page;
  655.         $pages = ceil($pages);
  656.         if($page > $pages)
  657.         {
  658.             $start = 0;
  659.             $page = 1;
  660.         }
  661.     }
  662.     else
  663.     {
  664.         $start = 0;
  665.         $page = 1;
  666.     }
  667.    
  668.     // multi-page
  669.     if ($shouts_count > $per_page) {
  670.         $multipage = multipage($shouts_count, $per_page, $page, "pspshoutbox.php?action=full");    
  671.     }
  672.    
  673.     // get data
  674.     require_once MYBB_ROOT.'inc/class_parser.php';
  675.     $parser = new postParser;
  676.    
  677.     $usernames_cache = array();
  678.    
  679.     $query = $db->write_query("SELECT s.*, u.username, u.usergroup, u.displaygroup FROM ".TABLE_PREFIX."mysb_shouts s
  680.                             LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = s.uid)
  681.                          ORDER by s.id DESC LIMIT {$start}, {$per_page}");
  682.    
  683.     while ($row = $db->fetch_array($query))
  684.     {
  685.         $parser_options = array(
  686.                 'allow_mycode' => $mybb->settings['mysb_allow_mycode'],
  687.                 'allow_smilies' => $mybb->settings['mysb_allow_smilies'],
  688.                 'allow_imgcode' => $mybb->settings['mysb_allow_imgcode'],
  689.                 'allow_html' => $mybb->settings['mysb_allow_html'],
  690.                 "allow_videocode" => $mybb->settings['mysb_allow_video'],
  691.                 'me_username' => $row['username']
  692.             );
  693.            
  694.         $message = $parser->parse_message($row['shout_msg'], $parser_options);
  695.        
  696.         $find = stripos($message, "/pvt");
  697.         if($find == 0 && $find !== false)
  698.         {
  699.             sscanf($message, "/pvt %d", $userID);
  700.             $userID = (int)$userID;
  701.             $message = str_replace("/pvt ".$userID." ", "", $message);
  702.             if ($mybb->user['uid'] == intval($userID) || $mybb->user['uid'] == $row['uid'])
  703.             {
  704.                 if ($mybb->user['uid'] == intval($userID))
  705.                 {
  706.                     $userName = $mybb->user['username'];
  707.                 }
  708.                 else {
  709.                     // Unfortunately, we do not have this username...let's check our cache, if it's not in cache, query it
  710.                     if (!empty($usernames_cache[$userID]))
  711.                     {
  712.                         $userName = $usernames_cache[$userID];
  713.                     }
  714.                     else {
  715.                         $userName = $db->fetch_field($db->simple_select('users', 'username', 'uid=\''.$userID.'\''), 'username');
  716.                         $usernames_cache[$userID] = $userName;
  717.                     }
  718.                 }
  719.                
  720.                 $message = "<span style=\"background-color: #AF4300; font-weight: bold;\">{$lang->mysb_pvt_to} ".htmlspecialchars_uni($userName).": ".$message."</span>";
  721.        
  722.                 $row['username'] = format_name($row['username'], $row['usergroup'], $row['displaygroup']);
  723.  
  724.                 $extra = ($mybb->usergroup['cancp'] == 1 ? "title='{$row[shout_ip]}'" : "");
  725.  
  726.                 $username = '<a href="./member.php?action=profile&uid='.$row['uid'].'" {$extra}>'.$row['username'].'</a>';
  727.                 $date_time = my_date($mybb->settings['mysb_datetime'], $row['shout_date']);
  728.                 $class = alt_trow();
  729.                
  730.                 if (myshoutbox_can_delete() && $row['hidden'] == "yes") {
  731.                     $mysb_shoutbox_data .= "<tr id='shout-{$row[id]}'><td align=\"left\" class='{$class}'>&raquo; <strong><span style=\"color: #FF0000\";>{$lang->mysb_deleted_info}</span></strong> &raquo; {$username} - {$date_time} -- {$message}</td></tr>";
  732.                 }
  733.                 elseif ($row['hidden'] == "no")
  734.                 {
  735.                     $mysb_shoutbox_data .= "<tr id='shout-{$row[id]}'><td align=\"left\" class='{$class}'>&raquo; {$username} - {$date_time} -- {$message}</td></tr>";
  736.                 }
  737.             }
  738.         }      
  739.         else {
  740.             $row['username'] = format_name($row['username'], $row['usergroup'], $row['displaygroup']);
  741.  
  742.             $extra = ($mybb->usergroup['cancp'] == 1 ? "title='{$row[shout_ip]}'" : "");
  743.  
  744.             $username = '<a href="./member.php?action=profile&uid='.$row['uid'].'" {$extra}>'.$row['username'].'</a>';
  745.             $date_time = my_date($mybb->settings['mysb_datetime'], $row['shout_date']);
  746.             $class = alt_trow();
  747.            
  748.             if (myshoutbox_can_delete() && $row['hidden'] == "yes") {
  749.                 $mysb_shoutbox_data .= "<tr id='shout-{$row[id]}'><td align=\"left\" class='{$class}'><span style=\"font-size: {$mybb->settings['mysb_text_size']}px\">&raquo; <strong><span style=\"color: #FF0000\";>{$lang->mysb_deleted_info}</span></strong> &raquo; {$username} - {$date_time} -- {$message}</span></td></tr>";
  750.             }
  751.             elseif ($row['hidden'] == "no")
  752.             {
  753.                 $mysb_shoutbox_data .= "<tr id='shout-{$row[id]}'><td align=\"left\" class='{$class}'><span style=\"font-size: {$mybb->settings['mysb_text_size']}px\">&raquo; {$username} - {$date_time} -- {$message}</span></td></tr>";
  754.             }
  755.         }
  756.     }
  757.    
  758.    
  759.     eval("\$shoutbox = \"".$templates->get("mysb_shoutbox_psp")."\";");
  760.    
  761.     $db->write_query("SELECT * FROM ".TABLE_PREFIX."mysb_shouts ORDER by id DESC LIMIT 10");
  762.    
  763.     output_page($shoutbox);
  764.     exit;
  765. }
  766.  
  767. function myshoutbox_show_full()
  768. {
  769.     global $db, $mybb, $templates, $lang, $footer, $headerinclude, $header, $charset;
  770.    
  771.     $lang->load('myshoutbox');
  772.    
  773.     // Send our headers.
  774.     header("Content-type: text/html; charset={$charset}");
  775.    
  776.     // Make navigation
  777.     add_breadcrumb($lang->mysb_shoutbox, "index.php?action=full_shoutbox");
  778.  
  779.     // pagination
  780.     $query = $db->simple_select("mysb_shouts", "COUNT(*) as shouts_count");
  781.     $shouts_count = $db->fetch_field($query, 'shouts_count');
  782.    
  783.     // Pagination
  784.     $per_page = intval($mybb->settings['mysb_full_ppage']);;
  785.     if(intval($mybb->input['page']) > 0)
  786.     {
  787.         $page = (int)$mybb->input['page'];
  788.         $start = ($page-1) * $per_page;
  789.         $pages = $shouts_count / $per_page;
  790.         $pages = ceil($pages);
  791.         if($page > $pages)
  792.         {
  793.             $start = 0;
  794.             $page = 1;
  795.         }
  796.     }
  797.     else
  798.     {
  799.         $start = 0;
  800.         $page = 1;
  801.     }
  802.    
  803.     // multi-page
  804.     if ($shouts_count > $per_page) {
  805.         $multipage = multipage($shouts_count, $per_page, $page, "index.php?action=full_shoutbox");     
  806.     }
  807.    
  808.     // get data
  809.     require_once MYBB_ROOT.'inc/class_parser.php';
  810.     $parser = new postParser;
  811.    
  812.     $usernames_cache = array();
  813.    
  814.     $query = $db->write_query("SELECT s.*, u.username, u.usergroup, u.displaygroup FROM ".TABLE_PREFIX."mysb_shouts s
  815.                             LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = s.uid)
  816.                          ORDER by s.id DESC LIMIT {$start}, {$per_page}");
  817.    
  818.     while ($row = $db->fetch_array($query))
  819.     {
  820.         $parser_options = array(
  821.                 'allow_mycode' => $mybb->settings['mysb_allow_mycode'],
  822.                 'allow_smilies' => $mybb->settings['mysb_allow_smilies'],
  823.                 'allow_imgcode' => $mybb->settings['mysb_allow_imgcode'],
  824.                 'allow_html' => $mybb->settings['mysb_allow_html'],
  825.                 "allow_videocode" => $mybb->settings['mysb_allow_video'],
  826.                 'me_username' => $row['username']
  827.             );     
  828.            
  829.         $message = $parser->parse_message($row['shout_msg'], $parser_options);
  830.  
  831.         $find = stripos($message, "/pvt");
  832.         if($find == 0 && $find !== false)
  833.         {
  834.             sscanf($message, "/pvt %d", $userID);
  835.             $userID = (int)$userID;
  836.             $message = str_replace("/pvt ".$userID." ", "", $message);
  837.             if ($mybb->user['uid'] == intval($userID) || $mybb->user['uid'] == $row['uid'])
  838.             {
  839.                 if ($mybb->user['uid'] == intval($userID))
  840.                 {
  841.                     $userName = $mybb->user['username'];
  842.                 }
  843.                 else {
  844.                     // Unfortunately, we do not have this username...let's check our cache, if it's not in cache, query it
  845.                     if (!empty($usernames_cache[$userID]))
  846.                     {
  847.                         $userName = $usernames_cache[$userID];
  848.                     }
  849.                     else {
  850.                         $userName = $db->fetch_field($db->simple_select('users', 'username', 'uid=\''.$userID.'\''), 'username');
  851.                         $usernames_cache[$userID] = $userName;
  852.                     }
  853.                 }
  854.                
  855.                 $message = "<span style=\"background-color: #AF4300; font-weight: bold;\">{$lang->mysb_pvt_to} ".htmlspecialchars_uni($userName).": ".$message."</span>";
  856.        
  857.                 $row['username'] = format_name($row['username'], $row['usergroup'], $row['displaygroup']);
  858.  
  859.                 $extra = ($mybb->usergroup['cancp'] == 1 ? "title='{$row[shout_ip]}'" : "");
  860.  
  861.                 $username = '<a href="./member.php?action=profile&uid='.$row['uid'].'" {$extra}>'.$row['username'].'</a>';
  862.                 $date_time = my_date($mybb->settings['mysb_datetime'], $row['shout_date']);
  863.                 $class = alt_trow();
  864.    
  865.                 $mysb_shoutbox_data .= "<tr id='shout-{$row[id]}'><td class='{$class}'><span style=\"font-size: {$mybb->settings['mysb_text_size']}px\">&raquo; {$report}{$username} - {$date_time} -- {$message}</span></td></tr>";
  866.             }
  867.         }      
  868.         else {
  869.             $row['username'] = format_name($row['username'], $row['usergroup'], $row['displaygroup']);
  870.  
  871.             $extra = ($mybb->usergroup['cancp'] == 1 ? "title='{$row[shout_ip]}'" : "");
  872.  
  873.             $username = '<a href="./member.php?action=profile&uid='.$row['uid'].'" {$extra}>'.$row['username'].'</a>';
  874.             $date_time = my_date($mybb->settings['mysb_datetime'], $row['shout_date']);
  875.             $class = alt_trow();
  876.        
  877.             $mysb_shoutbox_data .= "<tr id='shout-{$row[id]}'><td class='{$class}'><span style=\"font-size: {$mybb->settings['mysb_text_size']}px\">&raquo; {$report}{$username} - {$date_time} -- {$message}</span></td></tr>";
  878.         }
  879.     }
  880.    
  881.    
  882.     eval("\$shoutbox_full = \"".$templates->get("mysb_shoutbox_full")."\";");
  883.    
  884.     $db->write_query("SELECT * FROM ".TABLE_PREFIX."mysb_shouts ORDER by id DESC LIMIT 10");
  885.    
  886.     output_page($shoutbox_full);
  887.     exit;
  888. }
  889.  
  890. function myshoutbox_index()
  891. {
  892.     global $mybb, $lang;
  893.    
  894.     // show full shoutbox
  895.     if ($mybb->input['action'] == 'full_shoutbox')
  896.     {
  897.         $lang->load('myshoutbox');
  898.    
  899.         $perms = myshoutbox_can_view();
  900.  
  901.         if ($perms && $perms !== 2) {
  902.  
  903.             myshoutbox_show_full();
  904.             exit;
  905.         }
  906.         elseif ($perms === 2 && $mybb->settings['mysb_display_message'] == 1)
  907.         {
  908.             $lang->mysb_error_ban = $lang->sprintf($lang->mysb_error_ban, htmlspecialchars_uni($mybb->user['mysb_banned_reason']));
  909.  
  910.             error($lang->mysb_error_ban);
  911.         }
  912.         else {
  913.             error_no_permission();
  914.         }
  915.     }
  916. }
  917.  
  918. /**
  919.  * Add shoutbox template before output
  920.  */
  921. function myshoutbox_output_control(&$page_data)
  922. {
  923.     global $mybb, $templates, $mysb_shoutbox, $lang, $theme, $db, $mysb_message;
  924.    
  925.     $perms = myshoutbox_can_view();
  926.    
  927.     if ($perms && $perms !== 2) {
  928.         $lang->load('myshoutbox');
  929.    
  930.         // no shout button for guests
  931.         if ($mybb->user['usergroup'] == 1)
  932.             $extra_js = "ShoutBox.disableShout();";
  933.         else
  934.             $extra_js = "";
  935.        
  936.         eval("\$mysb_shoutbox = \"".$templates->get("mysb_shoutbox")."\";");
  937.     }
  938.     elseif ($perms === 2 && $mybb->settings['mysb_display_message'] == 1)
  939.     {
  940.         $lang->load('myshoutbox');
  941.        
  942.         $lang->mysb_error_ban = $lang->sprintf($lang->mysb_error_ban, htmlspecialchars_uni($mybb->user['mysb_banned_reason']));
  943.    
  944.         // display banned from shoutbox message
  945.         eval("\$mysb_shoutbox = \"".$templates->get("mysb_shoutbox_banned")."\";");
  946.     }
  947.     else {
  948.         $mysb_shoutbox = '';
  949.     }
  950.  
  951.     return str_replace('{myshoutbox_'.$mybb->settings['mysb_key'].'}', $mysb_shoutbox, $page_data); // still allow the shoutbox to be placed anywhere the admin wants
  952. }
  953.  
  954. function myshoutbox_show_shouts($last_id = 0)
  955. {
  956.     global $db, $mybb, $parser, $charset, $lang;
  957.    
  958.     $perms = myshoutbox_can_view();
  959.     if (!$perms || $perms === 2) return;
  960.    
  961.     require_once MYBB_ROOT.'inc/class_parser.php';
  962.     $parser = new postParser;
  963.    
  964.     $last_id = (int)$last_id; // not needed here since when we call the function it converts $last_id to int already
  965.  
  966.     $query = $db->write_query("SELECT s.*, u.username, u.usergroup, u.displaygroup FROM ".TABLE_PREFIX."mysb_shouts s
  967.                             LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = s.uid)
  968.                         WHERE s.id>{$last_id} ORDER by s.id DESC LIMIT {$mybb->settings['mysb_shouts_main']}");
  969.    
  970.     // fetch results
  971.     $messages = "";
  972.     $entries = 0;
  973.     $usernames_cache = array();
  974.     while ($row = $db->fetch_array($query))
  975.     {
  976.         $report = "(<a id=\"report_".$row['id']."\" href=\"#shoutbox\" onclick=\"javascript: return ShoutBox.promptReason(".$row['id'].");\" style=\"cursor: pointer;\">{$lang->mysb_report_button}</a>) ";
  977.        
  978.         $parser_options = array(
  979.                 'allow_mycode' => $mybb->settings['mysb_allow_mycode'],
  980.                 'allow_smilies' => $mybb->settings['mysb_allow_smilies'],
  981.                 'allow_imgcode' => $mybb->settings['mysb_allow_imgcode'],
  982.                 'allow_html' => $mybb->settings['mysb_allow_html'],
  983.                 "allow_videocode" => $mybb->settings['mysb_allow_video'],
  984.                 'me_username' => $row['username']
  985.             );     
  986.            
  987.         $message = $parser->parse_message($row['shout_msg'], $parser_options);
  988.        
  989.         $find = stripos($message, "/pvt");
  990.         if($find == 0 && $find !== false)
  991.         {
  992.             sscanf($message, "/pvt %d", $userID);
  993.             $userID = (int)$userID;
  994.             $message = str_replace("/pvt ".$userID." ", "", $message);
  995.             if ($mybb->user['uid'] == intval($userID) || $mybb->user['uid'] == $row['uid'])
  996.             {
  997.                 if ($mybb->user['uid'] == intval($userID))
  998.                 {
  999.                     $userName = $mybb->user['username'];
  1000.                 }
  1001.                 else {
  1002.                     // Unfortunately, we do not have this username...let's check our cache, if it's not in cache, query it
  1003.                     if (!empty($usernames_cache[$userID]))
  1004.                     {
  1005.                         $userName = $usernames_cache[$userID];
  1006.                     }
  1007.                     else {
  1008.                         $userName = $db->fetch_field($db->simple_select('users', 'username', 'uid=\''.$userID.'\''), 'username');
  1009.                         $usernames_cache[$userID] = $userName;
  1010.                     }
  1011.                 }
  1012.                
  1013.                 $message = "<span style=\"background-color: #AF4300; font-weight: bold;\">{$lang->mysb_pvt_to} ".htmlspecialchars_uni($userName).": ".$message."</span>";
  1014.            
  1015.                 $row['username'] = format_name($row['username'], $row['usergroup'], $row['displaygroup']);
  1016.                 $extra = ($mybb->usergroup['cancp'] == 1 ? "title='{$row[shout_ip]}'" : "");
  1017.        
  1018.                 $username = $row['username'];
  1019.                 $date_time = my_date($mybb->settings['mysb_datetime'], $row['shout_date']);
  1020.  
  1021.                 if (myshoutbox_can_delete()) {
  1022.                     $delete = "(<a href='#shoutbox' onclick='javascript: return ShoutBox.deleteShout({$row[id]}, 1,\"{$lang->mysb_delconfirm}\");'>{$lang->mysb_delete}</a>) ";
  1023.                     if ($row['hidden'] == "yes"){
  1024.                         $recover = "(<a href='#shoutbox' onclick='javascript: return ShoutBox.recoverShout({$row[id]}, 1, \"{$lang->mysb_recconfirm}\");'>{$lang->mysb_recover}</a>) ";
  1025.                         $remove = "(<a href='#shoutbox' onclick='javascript: return ShoutBox.removeShout({$row[id]}, 1, \"{$lang->mysb_remconfirm}\");'>{$lang->mysb_remove}</a>) ";
  1026.                     }
  1027.                 }
  1028.                 else {
  1029.                     $delete = '&nbsp;';
  1030.                     $recover = '&nbsp;';
  1031.                     $remove = '&nbsp;';
  1032.                 }
  1033.        
  1034.                 if (myshoutbox_can_delete() && $row['hidden'] == "yes") {
  1035.                     $messages .= "<span style=\"font-size: {$mybb->settings['mysb_text_size']}px\">&raquo; <strong><span style=\"color: #FF0000\";>{$lang->mysb_deleted_info}</span></strong> &raquo; {$remove}{$recover}{$report}<a href='#' onClick=\"javascript: ShoutBox.pvtAdd(".$row['uid']."); return false;\" {$extra}>{$username}</a> - {$date_time} -- {$message}</span><br />\r\n";
  1036.                 }
  1037.                 elseif ($row['hidden'] == "no") $messages .= "<span style=\"font-size: {$mybb->settings['mysb_text_size']}px\">&raquo; {$delete}{$recover}{$report}<span style=\"\"><a href='#' onClick=\"javascript: ShoutBox.pvtAdd(".$row['uid']."); return false;\" {$extra}>{$username}</a></span> - {$date_time} -- {$message}</span><br />\r\n";
  1038.        
  1039.                 $entries++;
  1040.        
  1041.                 if ($entries == 1) {
  1042.                     $maxid = $row['id'];
  1043.                 }
  1044.             }
  1045.         }
  1046.         else {
  1047.             $row['username'] = format_name($row['username'], $row['usergroup'], $row['displaygroup']);
  1048.        
  1049.             $extra = ($mybb->usergroup['cancp'] == 1 ? "title='{$row[shout_ip]}'" : "");
  1050.        
  1051.             $username = ''.$row['username'].'';
  1052.             $date_time = my_date($mybb->settings['mysb_datetime'], $row['shout_date']);
  1053.  
  1054.             if (myshoutbox_can_delete()) {
  1055.                 $delete = "(<a href='#shoutbox' onclick='javascript: return ShoutBox.deleteShout({$row[id]}, 1,\"{$lang->mysb_delconfirm}\");'>{$lang->mysb_delete}</a>) ";
  1056.                 if ($row['hidden'] == "yes"){
  1057.                     $recover = "(<a href='#shoutbox' onclick='javascript: return ShoutBox.recoverShout({$row[id]}, 1, \"{$lang->mysb_recconfirm}\");'>{$lang->mysb_recover}</a>) ";
  1058.                     $remove = "(<a href='#shoutbox' onclick='javascript: return ShoutBox.removeShout({$row[id]}, 1, \"{$lang->mysb_remconfirm}\");'>{$lang->mysb_remove}</a>) ";
  1059.                 }
  1060.             }
  1061.             else {
  1062.                 $delete = '&nbsp;';
  1063.                 $recover = '&nbsp;';
  1064.                 $remove = '&nbsp;';
  1065.             }
  1066.        
  1067.             if (myshoutbox_can_delete() && $row['hidden'] == "yes") {
  1068.                 $messages .= "<span style=\"font-size: {$mybb->settings['mysb_text_size']}px\">&raquo; <strong><span style=\"color: #FF0000\";>{$lang->mysb_deleted_info}</span></strong> &raquo; {$remove}{$recover}{$report}<a href='#' onClick=\"javascript: ShoutBox.pvtAdd(".$row['uid']."); return false;\" {$extra}>{$username}</a> - {$date_time} -- {$message}</span><br />\r\n";
  1069.             }
  1070.             elseif ($row['hidden'] == "no") $messages .= "<span style=\"font-size: {$mybb->settings['mysb_text_size']}px\">&raquo; {$delete}{$recover}{$report}<a href='#' onClick=\"javascript: ShoutBox.pvtAdd(".$row['uid']."); return false;\" {$extra}>{$username}</a> - {$date_time} -- {$message}</span><br />\r\n";
  1071.        
  1072.             $entries++;
  1073.        
  1074.             if ($entries == 1) {
  1075.                 $maxid = $row['id'];
  1076.             }
  1077.         }
  1078.     }
  1079.    
  1080.     if (!$maxid) {
  1081.         $maxid = $last_id;
  1082.     }
  1083.    
  1084.     echo "{$maxid}^--^{$entries}^--^{$messages}^--^{$chat_messages}";
  1085.     exit;
  1086. }
  1087.  
  1088. function myshoutbox_report_shout($reason, $sid)
  1089. {
  1090.     global $db, $mybb;
  1091.    
  1092.     $sid = intval($sid); // shout id
  1093.    
  1094.     if ($mybb->user['uid'] <= 0)
  1095.         return false; // guests can't report shouts
  1096.    
  1097.     // cannot report an invalid shout
  1098.     // get shout
  1099.     $query = $db->simple_select('mysb_shouts', '*', 'id=\''.intval($sid).'\'');
  1100.     $shout = $db->fetch_array($query);
  1101.     if (empty($shout))
  1102.     {
  1103.         echo "invalid_shout";
  1104.         exit;
  1105.     }
  1106.  
  1107.     // make sure we haven't reported it already
  1108.     if (($rid = $db->fetch_field($db->simple_select('mysb_reports', 'rid', 'sid='.intval($sid).' AND username=\''.$db->escape_string($mybb->user['username']).'\''),'rid')))
  1109.     {
  1110.         echo "already_reported";
  1111.         exit;
  1112.     }
  1113.    
  1114.     // get username of the author of the shout
  1115.     $query = $db->simple_select('users', 'username', 'uid=\''.intval($shout['uid']).'\'');
  1116.     $username = $db->fetch_field($query, 'username');
  1117.    
  1118.     $report = array(
  1119.             'username' => $db->escape_string($mybb->user['username']),
  1120.             'uid' => intval($mybb->user['uid']),
  1121.             'reason' => $db->escape_string($reason),
  1122.             'date' => TIME_NOW,
  1123.             'sid' => $sid,
  1124.             'author_uid' => intval($shout['uid']),
  1125.             'author_username' => $db->escape_string($username)
  1126.     );
  1127.        
  1128.     $db->insert_query('mysb_reports', $report);
  1129.    
  1130.     echo 'shout_reported';
  1131.     exit;
  1132. }
  1133.  
  1134. function myshoutbox_psp_add_shout()
  1135. {
  1136.     global $db, $mybb;
  1137.    
  1138.     $perms = myshoutbox_can_view();
  1139.    
  1140.     // guests not allowed! neither banned people
  1141.     if (!$perms || $perms === 2 || $mybb->user['usergroup'] == 1 || !$mybb->user['uid'])
  1142.     {
  1143.         die("failed!");
  1144.     }
  1145.    
  1146.     $shout_data = array(
  1147.             'uid' => (int)$mybb->user['uid'],
  1148.             'shout_msg' => $db->escape_string(str_replace('^--^', '-', $mybb->input['shout_data'])),
  1149.             'shout_date' => TIME_NOW,
  1150.             'shout_ip' => get_ip(),
  1151.             'hidden' => "no"
  1152.         );
  1153.        
  1154.     if ($db->insert_query('mysb_shouts', $shout_data)) {
  1155.         redirect("pspshoutbox.php", "Success! Redirecting..", "Success!");
  1156.     } else {
  1157.         redirect("pspshoutbox.php", "Failed! Redirecting..", "Failed!");
  1158.     }
  1159.    
  1160.     exit;
  1161. }
  1162.  
  1163. function myshoutbox_add_shout()
  1164. {
  1165.     global $db, $mybb;
  1166.    
  1167.     $perms = myshoutbox_can_view();
  1168.  
  1169.     // guests not allowed! neither banned users
  1170.     if (!$perms || $perms === 2 || $mybb->user['usergroup'] == 1 || $mybb->user['uid'] < 1)
  1171.     {
  1172.         die("failed!");
  1173.     }
  1174.    
  1175.     // purge database?
  1176.     $postData = trim($mybb->input['shout_data']);
  1177.     if ($mybb->usergroup['cancp'] == 1 && substr($postData, 0, 7) == '/delete') {
  1178.        
  1179.         preg_match('/\/delete\s{1,}(all|older than|newer than)($|\s{1,}([0-9]+\-[0-9]+\-[0-9]+)|\s{1,}[0-9]+)/i', $postData, $match);
  1180.        
  1181.         // we have date?
  1182.         if (stristr($match[2], '-'))
  1183.             $date = explode('-', $match[2]);
  1184.        
  1185.         // purge?
  1186.         if ($match[1] == 'all') {
  1187.             $db->delete_query('mysb_shouts');
  1188.             $db->insert_query('mysb_shouts', array('uid' => intval($mybb->user['uid']), 'shout_msg' => 'First shout', 'shout_date' => time(), 'shout_ip' => get_ip()));
  1189.         }
  1190.         elseif (strtolower($match[1]) == 'older than')
  1191.         {
  1192.            
  1193.             if ($date) {
  1194.                 $timeStamp = mktime(23, 59, 59, $date[0], ($date[1]-1), $date[2]);
  1195.                 $db->delete_query('mysb_shouts', 'shout_date <= ' . $timeStamp);
  1196.             }
  1197.             else // delete based on id
  1198.                 $db->delete_query('mysb_shouts', 'id < ' . intval($match[2]));
  1199.         }
  1200.         elseif (strtolower($match[1]) == 'newer than')
  1201.         {
  1202.             if ($date) {
  1203.  
  1204.                 $timeStamp = mktime(1, 1, 1, $date[0], ($date[1]+1), $date[2]);
  1205.                 $db->delete_query('mysb_shouts', 'shout_date >= ' . $timeStamp);
  1206.             }
  1207.             else // delete based on id
  1208.                 $db->delete_query('mysb_shouts', 'id > ' . intval($match[2]));
  1209.         }
  1210.        
  1211.         die("deleted");
  1212.     }
  1213.    
  1214.     // flood check
  1215.     if (intval($mybb->settings['mysb_flood_time']) && !is_moderator()) {
  1216.         $lastShout = $db->fetch_field($db->simple_select('mysb_shouts', 'MAX(shout_date) as lastShout', 'uid = '.intval($mybb->user['uid'])), 'lastShout');
  1217.         $interval = time() - $lastShout;
  1218.        
  1219.         if ($interval <= $mybb->settings['mysb_flood_time'])
  1220.             die("flood|" . ($mybb->settings['mysb_flood_time'] - $interval));
  1221.     }
  1222.    
  1223.     // Uid cannot be lower than 1
  1224.     $ret = sscanf($postData, "/pvt %d", $userID);
  1225.     if ($ret)
  1226.     {
  1227.         $userID = (int)$userID;
  1228.         if ($userID < 1)
  1229.             die("failed!");
  1230.     }
  1231.    
  1232.     $shout_data = array(
  1233.             'uid' => $mybb->user['uid'],
  1234.             'shout_msg' => $db->escape_string(str_replace('^--^', '-', $mybb->input['shout_data'])),
  1235.             'shout_date' => time(),
  1236.             'shout_ip' => get_ip(),
  1237.             'hidden' => "no"
  1238.         );
  1239.        
  1240.     if ($db->insert_query('mysb_shouts', $shout_data)) {
  1241.         echo "success!!";
  1242.     } else {
  1243.         echo "failed!";
  1244.     }
  1245.    
  1246.     exit;
  1247. }
  1248.  
  1249. function myshoutbox_delete_shout($shout_id)
  1250. {
  1251.     global $db;
  1252.    
  1253.     $shout_id = intval($shout_id);
  1254.    
  1255.     if (myshoutbox_can_delete()) {
  1256.         $db->update_query("mysb_shouts", array('hidden' => "yes"), "id='".$shout_id."'", 1);
  1257.         echo "success!";
  1258.     }
  1259.     else
  1260.         echo "failed!";
  1261.    
  1262.     exit;
  1263. }
  1264.  
  1265. function myshoutbox_remove_shout($shout_id)
  1266. {
  1267.     global $db;
  1268.    
  1269.     $shout_id = intval($shout_id);
  1270.    
  1271.     if (myshoutbox_can_delete()) {
  1272.         $db->write_query("DELETE FROM ".TABLE_PREFIX."mysb_shouts WHERE id = {$shout_id}");
  1273.         echo "success!";
  1274.     }
  1275.     else
  1276.         echo "failed!";
  1277.    
  1278.     exit;
  1279. }
  1280.  
  1281. function myshoutbox_recover_shout($shout_id)
  1282. {
  1283.     global $db;
  1284.    
  1285.     $shout_id = intval($shout_id);
  1286.    
  1287.     if (myshoutbox_can_delete()) {
  1288.         $db->update_query("mysb_shouts", array('hidden' => "no"), "id='".$shout_id."'", 1);
  1289.         echo "success!";
  1290.     }
  1291.     else
  1292.         echo "failed!";
  1293.    
  1294.     exit;
  1295. }
  1296.  
  1297. function myshoutbox_can_delete()
  1298. {
  1299.     global $mybb;
  1300.  
  1301.     if ($mybb->usergroup['cancp'] == 1 || ($mybb->settings['mysb_allow_smods'] == 1 && $mybb->usergroup['issupermod'] == 1) || ($mybb->settings['mysb_allow_mods'] == 1 && $mybb->usergroup['canmodcp'] == 1))
  1302.         return true;
  1303.    
  1304.     return false;
  1305. }
  1306.  
  1307. function myshoutbox_can_view()
  1308. {
  1309.     global $mybb;
  1310.    
  1311.     if ($mybb->usergroup['canview'] == 0) // can view the board?
  1312.         return false;  
  1313.        
  1314.     // verify if is banned user before checking usergroups
  1315.     if (intval($mybb->user['mysb_banned']) == 1) // banned from the shoutbox
  1316.         return 2; // 2 means we have been banned
  1317.    
  1318.     if (empty($mybb->settings['mysb_usergroups']))
  1319.         return true;
  1320.  
  1321.     // can guests view the shoutbox?
  1322.     /*if ($mybb->settings['mysb_guestview'] == 0 && $mybb->user['usergroup'] == 1)
  1323.         return false;*/
  1324.        
  1325.     $groups = explode(",", $mybb->settings['mysb_usergroups']);
  1326.     $add_groups = "";
  1327.    
  1328.     if ($mybb->settings['mysb_additional_groups'] == 1 && $mybb->user['additionalgroups'])
  1329.         $add_groups = explode(",", $mybb->user['additionalgroups']);
  1330.    
  1331.     if (!in_array($mybb->user['usergroup'], $groups)) { // is the user allowed to view the shoutbox?
  1332.         // didn't find gid (primary) in allowed list, check additonal groups if setting is set to yes and if any were found
  1333.        
  1334.         if ($add_groups) {
  1335.             if (count(array_intersect($add_groups, $groups)) == 0)
  1336.                 return false;
  1337.         }
  1338.         else
  1339.             return false;
  1340.     }
  1341.  
  1342.     return true;
  1343.  
  1344. }
  1345.  
  1346. function myshoutbox_admin_home_menu(&$sub_menu)
  1347. {
  1348.     global $lang, $db;
  1349.    
  1350.     $lang->load('myshoutbox');
  1351.  
  1352.     $reports = $db->fetch_field($db->simple_select("mysb_reports", "COUNT(rid) as reports", "marked='0'"), "reports");
  1353.    
  1354.     //$reports = $db->fetch_field($db->simple_select("plaza_mydownloads_downloads", "COUNT(did) as comments", "hidden=0"), "comments");
  1355.    
  1356.     $sub_menu[] = array('id' => 'myshoutbox', 'title' => $lang->sprintf($lang->myshoutbox_unread_reports, $reports), 'link' => 'index.php?module=tools/myshoutbox&action=reports');
  1357. }
  1358.  
  1359. function myshoutbox_admin_tools_menu(&$sub_menu)
  1360. {
  1361.     global $lang;
  1362.    
  1363.     $lang->load('myshoutbox');
  1364.     $sub_menu[] = array('id' => 'myshoutbox', 'title' => $lang->myshoutbox_index, 'link' => 'index.php?module=tools/myshoutbox');
  1365. }
  1366.  
  1367. function myshoutbox_admin_tools_action_handler(&$actions)
  1368. {
  1369.     $actions['myshoutbox'] = array('active' => 'myshoutbox', 'file' => 'myshoutbox');
  1370. }
  1371.  
  1372. function myshoutbox_admin_permissions(&$admin_permissions)
  1373. {
  1374.     global $db, $mybb, $lang;
  1375.  
  1376.     $lang->load("mysb_shoutbox", false, true);
  1377.     $admin_permissions['mysb_shoutbox'] = $lang->mysb_shoutbox_canmanage;
  1378.    
  1379. }
  1380.  
  1381. function myshoutbox_admin()
  1382. {
  1383.     global $db, $lang, $mybb, $page, $run_module, $action_file, $mybbadmin, $plugins;
  1384.    
  1385.     $lang->load("myshoutbox", false, true);
  1386.    
  1387.     if($run_module == 'tools' && $action_file == 'myshoutbox')
  1388.     {  
  1389.         if ($mybb->input['action'] == 'ban')
  1390.         {
  1391.             if ($mybb->request_method == "post")
  1392.             {
  1393.                 if(!isset($mybb->input['my_post_key']) || $mybb->post_code != $mybb->input['my_post_key'] || !$mybb->input['username'])
  1394.                 {
  1395.                     $mybb->request_method = "get";
  1396.                     flash_message($lang->myshoutbox_error, 'error');
  1397.                     admin_redirect("index.php?module=tools/myshoutbox");
  1398.                 }
  1399.  
  1400.                 $db->update_query('users', array('mysb_banned' => 1, 'mysb_banned_reason' => $db->escape_string($mybb->input['reason'])), 'username=\''.$db->escape_string($mybb->input['username']).'\'', 1);
  1401.                
  1402.                 $lang->myshoutbox_log_banned = $lang->sprintf($lang->myshoutbox_log_banned, $mybb->input['username']);
  1403.                 log_admin_action($lang->myshoutbox_log_banned);
  1404.                
  1405.                 flash_message($lang->myshoutbox_user_banned, 'success');
  1406.                 admin_redirect("index.php?module=tools/myshoutbox");
  1407.             }
  1408.         }
  1409.         elseif ($mybb->input['action'] == 'unban')
  1410.         {
  1411.             if ($mybb->request_method == "post")
  1412.             {
  1413.                 if(!isset($mybb->input['my_post_key']) || $mybb->post_code != $mybb->input['my_post_key'] || !$mybb->input['username'])
  1414.                 {
  1415.                     $mybb->request_method = "get";
  1416.                     flash_message($lang->myshoutbox_error, 'error');
  1417.                     admin_redirect("index.php?module=tools/myshoutbox");
  1418.                 }
  1419.                
  1420.                 $db->update_query('users', array('mysb_banned' => 0, 'mysb_banned_reason' => ''), 'username=\''.$db->escape_string($mybb->input['username']).'\'', 1);
  1421.                
  1422.                 $lang->myshoutbox_log_unbanned = $lang->sprintf($lang->myshoutbox_log_unbanned, $mybb->input['username']);
  1423.                 log_admin_action($lang->myshoutbox_log_unbanned);
  1424.                
  1425.                 flash_message($lang->myshoutbox_user_unbanned, 'success');
  1426.                 admin_redirect("index.php?module=tools/myshoutbox");
  1427.             }
  1428.         }
  1429.         elseif ($mybb->input['action'] == 'delete_report')
  1430.         {
  1431.             if ($mybb->request_method == "post")
  1432.             {
  1433.                 if(!isset($mybb->input['my_post_key']) || $mybb->post_code != $mybb->input['my_post_key'] || !$mybb->input['rid'])
  1434.                 {
  1435.                     $mybb->request_method = "get";
  1436.                     flash_message($lang->myshoutbox_error, 'error');
  1437.                     admin_redirect("index.php?module=tools/myshoutbox");
  1438.                 }
  1439.                
  1440.                 // don't check if the report id exists, just try to delete it
  1441.                 $db->delete_query('mysb_reports', 'rid='.intval($mybb->input['rid']), 1);
  1442.                
  1443.                 log_admin_action($lang->myshoutbox_log_deleted_report);
  1444.                
  1445.                 flash_message($lang->myshoutbox_report_deleted, 'success');
  1446.                 admin_redirect("index.php?module=tools/myshoutbox&amp;action=reports");
  1447.             }
  1448.         }
  1449.         elseif ($mybb->input['action'] == 'mark_report')
  1450.         {
  1451.             if ($mybb->request_method == "post")
  1452.             {
  1453.                 if(!isset($mybb->input['my_post_key']) || $mybb->post_code != $mybb->input['my_post_key'] || !$mybb->input['rid'])
  1454.                 {
  1455.                     $mybb->request_method = "get";
  1456.                     flash_message($lang->myshoutbox_error, 'error');
  1457.                     admin_redirect("index.php?module=tools/myshoutbox");
  1458.                 }
  1459.                
  1460.                 // don't check if the report id exists, just try to mark it as read
  1461.                 $db->update_query('mysb_reports', array('marked' => 1), 'rid=\''.intval($mybb->input['rid']).'\'', 1);
  1462.                
  1463.                 log_admin_action($lang->myshoutbox_log_marked_report);
  1464.                
  1465.                 flash_message($lang->myshoutbox_report_marked, 'success');
  1466.                 admin_redirect("index.php?module=tools/myshoutbox&amp;action=reports");
  1467.             }
  1468.         }
  1469.         elseif ($mybb->input['action'] == 'reports')
  1470.         {
  1471.             $page->add_breadcrumb_item($lang->myshoutbox_reported_shouts, 'index.php?module=tools/myshoutbox');
  1472.        
  1473.             $page->output_header($lang->myshoutbox_reported_shouts);
  1474.            
  1475.             $sub_tabs['myshoutbox'] = array(
  1476.                 'title'         => $lang->myshoutbox_home,
  1477.                 'link'          => 'index.php?module=tools/myshoutbox',
  1478.                 'description'   => $lang->myshoutbox_description
  1479.             );
  1480.            
  1481.             $sub_tabs['myshoutbox_reports'] = array(
  1482.                 'title'         => $lang->myshoutbox_reported_shouts." (".intval($db->fetch_field($db->simple_select("mysb_reports", "COUNT(rid) as reports", "marked='0'"), "reports")).")",
  1483.                 'link'          => 'index.php?module=tools/myshoutbox&amp;action=reports',
  1484.                 'description'   => $lang->myshoutbox_myshoutbox_reported_shouts_description
  1485.             );
  1486.            
  1487.             $page->output_nav_tabs($sub_tabs, 'myshoutbox_reports');
  1488.  
  1489.             // table
  1490.             $table = new Table;
  1491.             $table->construct_header($lang->myshoutbox_sid, array('width' => '10%'));
  1492.             $table->construct_header($lang->myshoutbox_username);
  1493.             $table->construct_header($lang->myshoutbox_reported_by);
  1494.             $table->construct_header($lang->myshoutbox_reason);
  1495.             $table->construct_header($lang->myshoutbox_date, array('width' => '15%'));
  1496.             $table->construct_header($lang->myshoutbox_view);
  1497.             $table->construct_header($lang->myshoutbox_delete);
  1498.             $table->construct_header($lang->myshoutbox_mark);
  1499.            
  1500.             // pagination
  1501.             $per_page = 15;
  1502.             if($mybb->input['page'] && intval($mybb->input['page']) > 1)
  1503.             {
  1504.                 $mybb->input['page'] = intval($mybb->input['page']);
  1505.                 $start = ($mybb->input['page']*$per_page)-$per_page;
  1506.             }
  1507.             else
  1508.             {
  1509.                 $mybb->input['page'] = 1;
  1510.                 $start = 0;
  1511.             }
  1512.            
  1513.             $query = $db->simple_select("mysb_reports", "COUNT(rid) as reports");
  1514.             $total_rows = $db->fetch_field($query, "reports");
  1515.        
  1516.             echo "<br />".draw_admin_pagination($mybb->input['page'], $per_page, $total_rows, "index.php?module=tools/myshoutbox&amp;action=reports&amp;page={page}");
  1517.            
  1518.             $query = $db->write_query("
  1519.                 SELECT s.*, r.*
  1520.                 FROM ".TABLE_PREFIX."mysb_reports r
  1521.                 LEFT JOIN ".TABLE_PREFIX."mysb_shouts s ON (s.id=r.sid)
  1522.                 ORDER BY r.date DESC LIMIT {$start}, {$per_page}
  1523.             ");
  1524.             while($r = $db->fetch_array($query)) {
  1525.                
  1526.                 if ($r['marked'] == 0)
  1527.                 {
  1528.                     $styles = 'background-color: #FFD7D7';
  1529.                 }
  1530.                 else
  1531.                     $styles = '';
  1532.                
  1533.                 $table->construct_cell(htmlspecialchars_uni($r['sid']), array('width' => '10%', 'style' => $styles));
  1534.                 $table->construct_cell(build_profile_link($r['author_username'], $r['author_uid']), array('style' => $styles));
  1535.                 $table->construct_cell(build_profile_link($r['username'], $r['uid']), array('style' => $styles));
  1536.                 $table->construct_cell(htmlspecialchars_uni($r['reason']), array('style' => $styles));
  1537.                
  1538.                 $html_data = " <input type=\"submit\" class=\"submit_button\" value=\"{$lang->myshoutbox_view}\" onclick=\"alert('".myshoutbox_jsspecialchars(htmlspecialchars_uni($r['shout_msg']))."')\" />";
  1539.                
  1540.                 $table->construct_cell(my_date($mybb->settings['dateformat'], $r['date'], '', false).", ".my_date($mybb->settings['timeformat'], $r['date']), array('width' => '15%', 'style' => $styles));
  1541.                
  1542.                 $table->construct_cell($html_data, array('width' => '10%', 'style' => $styles));
  1543.                
  1544.                 $form = new Form("index.php?module=tools/myshoutbox&amp;action=delete_report", "post", 'myshoutbox" onsubmit="return confirm(\''.myshoutbox_jsspecialchars($lang->myshoutbox_delete_report_confirm).'\');', 0, "", true);
  1545.                 $html_data = $form->construct_return;
  1546.                 $html_data .= $form->generate_hidden_field("rid", $r['rid']);
  1547.                 $html_data .= "<input type=\"submit\" class=\"submit_button\" value=\"{$lang->myshoutbox_delete}\" />";
  1548.                 $html_data .= $form->end();
  1549.                
  1550.                 $table->construct_cell($html_data, array('width' => '10%', 'style' => $styles));
  1551.                
  1552.                 $form = new Form("index.php?module=tools/myshoutbox&amp;action=mark_report", "post", 'myshoutbox" onsubmit="return confirm(\''.myshoutbox_jsspecialchars($lang->myshoutbox_mark_report_confirm).'\');', 0, "", true);
  1553.                 $html_data = $form->construct_return;
  1554.                 $html_data .= $form->generate_hidden_field("rid", $r['rid']);
  1555.                 $html_data .= "<input type=\"submit\" class=\"submit_button\" value=\"{$lang->myshoutbox_mark}\" />";
  1556.                 $html_data .= $form->end();
  1557.                
  1558.                 $table->construct_cell($html_data, array('width' => '10%', 'style' => $styles));
  1559.                
  1560.                 $table->construct_row();
  1561.                 $found = true;
  1562.             }
  1563.            
  1564.             if (!$found)
  1565.             {
  1566.                 $table->construct_cell($lang->myshoutbox_no_shouts_reported, array('colspan' => 8));
  1567.                 $table->construct_row();
  1568.             }
  1569.            
  1570.             $table->output($lang->myshoutbox_reported_shouts);
  1571.            
  1572.             $page->output_footer();
  1573.        
  1574.             exit;
  1575.         }
  1576.        
  1577.         // no action
  1578.         $page->add_breadcrumb_item($lang->myshoutbox_home, 'index.php?module=tools/myshoutbox');
  1579.        
  1580.         $page->output_header($lang->myshoutbox_home);
  1581.        
  1582.         $sub_tabs['myshoutbox'] = array(
  1583.             'title'         => $lang->myshoutbox_home,
  1584.             'link'          => 'index.php?module=tools/myshoutbox',
  1585.             'description'   => $lang->myshoutbox_description
  1586.         );
  1587.        
  1588.         $sub_tabs['myshoutbox_reports'] = array(
  1589.             'title'         => $lang->myshoutbox_reported_shouts." (".intval($db->fetch_field($db->simple_select("mysb_reports", "COUNT(rid) as reports", "marked='0'"), "reports")).")",
  1590.             'link'          => 'index.php?module=tools/myshoutbox&amp;action=reports',
  1591.             'description'   => $lang->myshoutbox_myshoutbox_reported_shouts_description
  1592.         );
  1593.        
  1594.         $page->output_nav_tabs($sub_tabs, 'myshoutbox');
  1595.        
  1596.         $tabs = array(
  1597.             'banuser' => $lang->myshoutbox_quick_ban,
  1598.             'unbanuser' => $lang->myshoutbox_quick_unban
  1599.         );
  1600.        
  1601.         $page->output_tab_control($tabs);
  1602.        
  1603.         // quick ban user form
  1604.         echo "<div id=\"tab_banuser\">\n";
  1605.         $form = new Form("index.php?module=tools/myshoutbox&amp;action=ban", "post", "myshoutbox");
  1606.        
  1607.         $form_container = new FormContainer($lang->myshoutbox_ban_user);
  1608.         $form_container->output_row($lang->myshoutbox_ban_username, htmlspecialchars_uni($lang->myshoutbox_ban_username_desc), $form->generate_text_box('username', htmlspecialchars_uni($mybb->input['username']), array('id' => 'username')), 'username');
  1609.         $form_container->output_row($lang->myshoutbox_ban_reason, htmlspecialchars_uni($lang->myshoutbox_ban_reason_desc), $form->generate_text_box('reason', htmlspecialchars_uni($mybb->input['reason']), array('id' => 'reason')), 'reason');
  1610.        
  1611.         $form_container->end();
  1612.        
  1613.         $buttons = "";
  1614.         $buttons[] = $form->generate_submit_button($lang->myshoutbox_submit);
  1615.         $buttons[] = $form->generate_reset_button($lang->myshoutbox_reset);
  1616.         $form->output_submit_wrapper($buttons);
  1617.         $form->end();
  1618.        
  1619.         echo "</div>\n";
  1620.        
  1621.         // quick unban user form
  1622.         echo "<div id=\"tab_unbanuser\">\n";
  1623.         $form = new Form("index.php?module=tools/myshoutbox&amp;action=unban", "post", "myshoutbox");
  1624.        
  1625.         $form_container = new FormContainer($lang->myshoutbox_unban_user);
  1626.         $form_container->output_row($lang->myshoutbox_unban_username, htmlspecialchars_uni($lang->myshoutbox_unban_username_desc), $form->generate_text_box('username', htmlspecialchars_uni($mybb->input['username']), array('id' => 'username')), 'username');
  1627.        
  1628.         $form_container->end();
  1629.    
  1630.         $buttons = "";
  1631.         $buttons[] = $form->generate_submit_button($lang->myshoutbox_submit);
  1632.         $buttons[] = $form->generate_reset_button($lang->myshoutbox_reset);
  1633.         $form->output_submit_wrapper($buttons);
  1634.         $form->end();
  1635.        
  1636.         echo "</div>\n";
  1637.        
  1638.         // pagination
  1639.         $per_page = 15;
  1640.         if($mybb->input['page'] && intval($mybb->input['page']) > 1)
  1641.         {
  1642.             $mybb->input['page'] = intval($mybb->input['page']);
  1643.             $start = ($mybb->input['page']*$per_page)-$per_page;
  1644.         }
  1645.         else
  1646.         {
  1647.             $mybb->input['page'] = 1;
  1648.             $start = 0;
  1649.         }
  1650.        
  1651.         $query = $db->simple_select("users", "COUNT(uid) as users", 'mysb_banned=1');
  1652.         $total_rows = $db->fetch_field($query, "users");
  1653.    
  1654.         echo "<br />".draw_admin_pagination($mybb->input['page'], $per_page, $total_rows, "index.php?module=tools/myshoutbox&amp;page={page}");
  1655.        
  1656.         // table
  1657.         $table = new Table;
  1658.         $table->construct_header("<div style=\"width: 30%;\">".$lang->myshoutbox_username."</div>");
  1659.         $table->construct_header("<div style=\"width: 70%;\">".$lang->myshoutbox_reason."</div>");
  1660.        
  1661.         $query = $db->simple_select('users', 'uid,username,mysb_banned_reason', 'mysb_banned=1', array('order_by' => 'uid', 'order_dir' => 'ASC', 'limit' => "{$start}, {$per_page}"));
  1662.         while($r = $db->fetch_array($query)) {
  1663.             $table->construct_cell(htmlspecialchars_uni($r['username']));
  1664.             $table->construct_cell(htmlspecialchars_uni($r['mysb_banned_reason']));
  1665.             $table->construct_row();
  1666.             $found = true;
  1667.         }
  1668.        
  1669.         if (!$found)
  1670.         {
  1671.             $table->construct_cell($lang->myshoutbox_no_users_banned, array('colspan' => 2));
  1672.             $table->construct_row();
  1673.         }
  1674.        
  1675.         $table->output($lang->myshoutbox_banned_users);
  1676.        
  1677.         $page->output_footer();
  1678.        
  1679.         exit;
  1680.     }
  1681. }
  1682.  
  1683. /**
  1684.  * Somewhat like htmlspecialchars_uni but for JavaScript strings
  1685.  *
  1686.  * @param string: The string to be parsed
  1687.  * @return string: Javascript compatible string
  1688.  */
  1689. function myshoutbox_jsspecialchars($str)
  1690. {
  1691.     // Converts & -> &amp; allowing Unicode
  1692.     // Parses out HTML comments as the XHTML validator doesn't seem to like them
  1693.     $string = preg_replace(array("#\<\!--.*?--\>#", "#&(?!\#[0-9]+;)#"), array('','&amp;'), $str);
  1694.     return strtr($string, array("\n" => '\n', "\r" => '\r', '\\' => '\\\\', '"' => '\x22', "'" => '\x27', '<' => '&lt;', '>' => '&gt;'));
  1695. }
  1696.  
  1697. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement