PageRenderTime 65ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/AP_ChatBox.php

https://github.com/neofutur/MyBestBB
PHP | 246 lines | 186 code | 30 blank | 30 comment | 38 complexity | f7ade96d13ef96abf037cee7ba19ddbf MD5 | raw file
  1. <?php
  2. /***********************************************************************
  3. Copyright (C) 2005 Connor Dunn (Connorhd@mypunbb.com)
  4. This software is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 2 of the License,
  7. or (at your option) any later version.
  8. This software is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  15. MA 02111-1307 USA
  16. ************************************************************************/
  17. // Make sure no one attempts to run this script "directly"
  18. if (!defined('PUN'))
  19. exit;
  20. // Tell admin_loader.php that this is indeed a plugin and that it is loaded
  21. define('PUN_PLUGIN_LOADED', 1);
  22. if (!$pun_config['cb_pbb_version'])
  23. message('Poki BB Chatbox is not installed correctly. Please make sure you have launch install_mod.php');
  24. if (isset($_POST['form_sent']))
  25. {
  26. // Lazy referer check (in case base_url isn't correct)
  27. if (!preg_match('#/admin_loader\.php#i', $_SERVER['HTTP_REFERER']))
  28. message($lang_common['Bad referrer']);
  29. $form = array_map('trim', $_POST['form']);
  30. while (list($key, $input) = @each($form))
  31. {
  32. // Only update values that have changed
  33. if ((isset($pun_config['cb_'.$key])) || ($pun_config['cb_'.$key] == NULL)) {
  34. if ($pun_config['cb_'.$key] != $input)
  35. {
  36. if ($input != '' || is_int($input))
  37. $value = '\''.$db->escape($input).'\'';
  38. else
  39. $value = 'NULL';
  40. $db->query('UPDATE '.$db->prefix.'config SET conf_value='.$value.' WHERE conf_name=\'cb_'.$key.'\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
  41. }
  42. }
  43. }
  44. // Regenerate the config cache
  45. require_once PUN_ROOT.'include/cache.php';
  46. generate_config_cache();
  47. redirect('admin_loader.php?plugin=AP_ChatBox.php', 'Options updated. Redirecting &hellip;');
  48. }
  49. // Edit a group (stage 1)
  50. if (isset($_GET['edit_group']))
  51. {
  52. $group_id = intval($_GET['edit_group']);
  53. if ($group_id < 1)
  54. message($lang_common['Bad request']);
  55. $result = $db->query('SELECT g_id, g_title, g_read_chatbox,g_post_chatbox, g_title_chatbox, g_post_flood_chatbox FROM '.$db->prefix.'groups WHERE g_id='.$group_id) or error('Unable to fetch user group info', __FILE__, __LINE__, $db->error());
  56. if (!$db->num_rows($result))
  57. message($lang_common['Bad request']);
  58. $group = $db->fetch_assoc($result);
  59. generate_admin_menu($plugin);
  60. ?>
  61. <div class="blockform">
  62. <h2><span>Group settings</span></h2>
  63. <div class="box">
  64. <form id="groups2" method="post" action="admin_loader.php?plugin=AP_ChatBox.php">
  65. <p class="submittop"><input type="submit" name="add_edit_group" value=" Save " /></p>
  66. <div class="inform">
  67. <input type="hidden" name="group_id" value="<?php echo $group_id ?>" />
  68. <fieldset>
  69. <legend>Setup group options and permissions</legend>
  70. <div class="infldset">
  71. <p>Below options and permissions are the default permissions for the user group.</p>
  72. <table class="aligntop" cellspacing="0">
  73. <tr>
  74. <th scope="row">Group title</th>
  75. <td>
  76. <?php echo pun_htmlspecialchars($group['g_title']); ?>
  77. </td>
  78. </tr>
  79. <tr>
  80. <th scope="row">ChatBox title (HTML)</th>
  81. <td>
  82. <input type="text" name="title_chatbox" size="50" value="<?php echo pun_htmlspecialchars($group['g_title_chatbox']) ?>" tabindex="2" />
  83. <span>Leave blank to use no title.</span>
  84. </td>
  85. </tr>
  86. <?php if ($group['g_id'] != PUN_ADMIN): ?> <tr>
  87. <th scope="row">Read ChatBox</th>
  88. <td>
  89. <input type="radio" name="read_chatbox" value="1"<?php if ($group['g_read_chatbox'] == '1') echo ' checked="checked"' ?> tabindex="3" />&nbsp;<strong>Yes</strong>&nbsp;&nbsp;&nbsp;<input type="radio" name="read_chatbox" value="0"<?php if ($group['g_read_chatbox'] == '0') echo ' checked="checked"' ?> tabindex="4" />&nbsp;<strong>No</strong>
  90. <span>Allow users in this group to view the ChatBox.</span>
  91. </td>
  92. </tr>
  93. <tr>
  94. <th scope="row">Post ChatBox</th>
  95. <td>
  96. <input type="radio" name="post_chatbox" value="1"<?php if ($group['g_post_chatbox'] == '1') echo ' checked="checked"' ?> tabindex="5" />&nbsp;<strong>Yes</strong>&nbsp;&nbsp;&nbsp;<input type="radio" name="post_chatbox" value="0"<?php if ($group['g_post_chatbox'] == '0') echo ' checked="checked"' ?> tabindex="6" />&nbsp;<strong>No</strong>
  97. <span>Allow users in this group to post messages in ChatBox.</span>
  98. </td>
  99. </tr>
  100. <?php if ($group['g_id'] != PUN_MOD): ?> <tr>
  101. <th scope="row">Post flood interval</th>
  102. <td>
  103. <input type="text" name="post_flood_chatbox" size="5" maxlength="4" value="<?php echo $group['g_post_flood_chatbox'] ?>" tabindex="24" />
  104. <span>Number of seconds that users in this group have to wait between posts. Set to 0 to disable.</span>
  105. </td>
  106. </tr>
  107. <?php endif; ?><?php endif; ?> </table>
  108. </div>
  109. </fieldset>
  110. </div>
  111. <p class="submitend"><input type="submit" name="add_edit_group" value=" Save " tabindex="26" /></p>
  112. </form>
  113. </div>
  114. </div>
  115. <?php
  116. }
  117. // Edit a group (stage 2)
  118. else if (isset($_POST['add_edit_group']))
  119. {
  120. // Lazy referer check (in case base_url isn't correct)
  121. if (!preg_match('#/admin_loader\.php#i', $_SERVER['HTTP_REFERER']))
  122. message($lang_common['Bad referrer']);
  123. // Is this the admin group? (special rules apply)
  124. $is_admin_group = (isset($_POST['group_id']) && $_POST['group_id'] == PUN_ADMIN) ? true : false;
  125. $title_chatbox = trim($_POST['title_chatbox']);
  126. $read_chatbox = isset($_POST['read_chatbox']) ? intval($_POST['read_chatbox']) : '1';
  127. $post_chatbox = isset($_POST['post_chatbox']) ? intval($_POST['post_chatbox']) : '1';
  128. $post_flood_chatbox = isset($_POST['post_flood_chatbox']) ? intval($_POST['post_flood_chatbox']) : '0';
  129. $title_chatbox = ($title_chatbox != '') ? '\''.$db->escape($title_chatbox).'\'' : 'NULL';
  130. $result = $db->query('SELECT 1 FROM '.$db->prefix.'groups WHERE g_id!='.$_POST['group_id']) or error('Unable to check group title collision', __FILE__, __LINE__, $db->error());
  131. $db->query('UPDATE '.$db->prefix.'groups SET g_title_chatbox='.$title_chatbox.', g_read_chatbox='.$read_chatbox.', g_post_chatbox='.$post_chatbox.', g_post_flood_chatbox='.$post_flood_chatbox.' WHERE g_id='.$_POST['group_id']) or error('Unable to update group', __FILE__, __LINE__, $db->error());
  132. // Regenerate the quickjump cache
  133. require_once PUN_ROOT.'include/cache.php';
  134. generate_quickjump_cache();
  135. redirect('admin_loader.php?plugin=AP_ChatBox.php', 'Group edited. Redirecting &hellip;');
  136. }
  137. else
  138. {
  139. generate_admin_menu($plugin);
  140. ?>
  141. <div class="block">
  142. <h2><span>Poki BB ChatBox <?php echo ' - v'.$pun_config['cb_pbb_version'] ?> - by <a href="mailto:pokemonjojo@mibhouse.org">Pokemon_JOJO</a></span></h2>
  143. <div class="box">
  144. <div class="inbox">
  145. <p>This plugin allows you to change the chatbox settings.</p>
  146. </div>
  147. </div>
  148. </div>
  149. <div class="blockform">
  150. <h2 class="block2"><span>Options</span></h2>
  151. <div class="box">
  152. <form method="post" action="admin_loader.php?plugin=AP_ChatBox.php">
  153. <div class="inform">
  154. <input type="hidden" name="form_sent" value="1" />
  155. <fieldset>
  156. <legend>Settings</legend>
  157. <div class="infldset">
  158. <table class="aligntop" cellspacing="0">
  159. <tr>
  160. <th scope="row">ChatBox Height</th>
  161. <td>
  162. <input type="text" name="form[height]" size="50" maxlength="255" value="<?php echo $pun_config['cb_height'] ?>" />
  163. <span>The Height in pixel of your ChatBox.</span>
  164. </td>
  165. </tr>
  166. <tr>
  167. <th scope="row">Max Length of Messages</th>
  168. <td>
  169. <input type="text" name="form[msg_maxlength]" size="50" maxlength="255" value="<?php echo $pun_config['cb_msg_maxlength'] ?>" />
  170. <span>The max length of messages.</span>
  171. </td>
  172. </tr>
  173. <tr>
  174. <th scope="row">Max Messages in ChatBox</th>
  175. <td>
  176. <input type="text" name="form[max_msg]" size="50" maxlength="255" value="<?php echo $pun_config['cb_max_msg'] ?>" />
  177. <span>Number of maximum messages.</span>
  178. </td>
  179. </tr>
  180. <tr>
  181. <th scope="row">Messages display (Parsing)</th>
  182. <td>
  183. <textarea name="form[disposition]" rows="5" cols="50"><?php echo $pun_config['cb_disposition'] ?></textarea>
  184. <span>How display the messages in your ChatBox. You can use HTML. <strong>Default exemple:</strong>
  185. <textarea rows="5" cols="50"><strong><pun_username></strong> - <pun_date> - [ <pun_nbpost><pun_nbpost_txt> ] <pun_admin><br /><pun_message><br /><br /></textarea>
  186. </span>
  187. </td>
  188. </tr>
  189. </table>
  190. </div>
  191. </fieldset>
  192. <fieldset>
  193. <legend>Groups setting</legend>
  194. <div class="infldset">
  195. <p>You can configure some chatbox options and permissions for each group (Read/Post permission, ChatBox title, Post flood interval). Please note though, that in some groups, some options are unavailable. (e.g. the Read/Post permission for admin)</p>
  196. <table cellspacing="0">
  197. <?php
  198. $result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups ORDER BY g_id') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
  199. while ($cur_group = $db->fetch_assoc($result))
  200. echo "\t\t\t\t\t\t\t\t".'<tr><th scope="row"><a href="admin_loader.php?plugin=AP_ChatBox.php&amp;edit_group='.$cur_group['g_id'].'">Edit Setting</a></th><td>'.pun_htmlspecialchars($cur_group['g_title']).'</td></tr>'."\n";
  201. ?>
  202. </table>
  203. </div>
  204. </fieldset>
  205. </div>
  206. <p class="submitend"><input type="submit" name="save" value="Save changes" /></p>
  207. </form>
  208. </div>
  209. </div>
  210. <?php
  211. }