PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/user_tagging/settings/list_ignore.php

https://github.com/mmakaay/Modules
PHP | 196 lines | 158 code | 29 blank | 9 comment | 31 complexity | c23afee24f3f815690f477996fd83472 MD5 | raw file
  1. <?php
  2. if (!defined('PHORUM_ADMIN')) return;
  3. // Build a list of vroot folders and a javascript structure, describing
  4. // the forums inside the vroot.
  5. $forums = phorum_api_forums_get();
  6. $vroot_folders = array();
  7. $vroot2forums = array();
  8. $forumid2name = array(
  9. 0 => "<img src=\"{$PHORUM['http_path']}/mods/user_tagging/settings/folder.gif\" style=\"border:0\"/>&nbsp;Top level forum folder"
  10. );
  11. foreach ($forums as $forum)
  12. {
  13. if ($forum['forum_id'] == $forum['vroot'])
  14. {
  15. $forumid2name[$forum['forum_id']] =
  16. "<img src=\"{$PHORUM['http_path']}/mods/user_tagging/settings/folder.gif\" style=\"border:0\"/>&nbsp;" .
  17. addslashes(strip_tags($forum['name'])) .
  18. " (vroot {$forum['forum_id']})";
  19. $vroot_folders[$forum['forum_id']] =
  20. addslashes(strip_tags($forum['name'])) .
  21. " (vroot {$forum['forum_id']})";
  22. } else {
  23. if (empty($forum['folder_flag'])) {
  24. $vroot2forums[$forum['vroot']][$forum['forum_id']] = $forum;
  25. }
  26. }
  27. }
  28. $forum_js_parts = array();
  29. foreach ($vroot2forums as $vroot => $forums) {
  30. foreach ($forums as $fid => $forum) {
  31. if (!empty($forum['folder_flag'])) continue;
  32. $path = $forum['forum_path'];
  33. $name = strip_tags(implode("::", $path));
  34. $forumid2name[$fid] = "<img src=\"{$PHORUM['http_path']}/mods/user_tagging/settings/forum.gif\" style=\"border:0\"/>&nbsp;$name";
  35. array_shift($path);
  36. $name = strip_tags(implode("::", $path));
  37. $vroot2forums[$vroot][$fid]["strpath"] = $name;
  38. $forum_js_parts[$vroot][] = "'{$forum['forum_id']}':'".addslashes($name)."'";
  39. }
  40. }
  41. $vroot_js_parts = array();
  42. foreach($forum_js_parts as $vroot => $parts) {
  43. $vroot_js_parts[] = "'$vroot': {" . implode(', ', $parts) . "}";
  44. }
  45. $vroot_js = "{".implode(', ', $vroot_js_parts)."}";
  46. // Retrieve current ignore list.
  47. $ignores = user_tagging_get_ignore_list();
  48. // Update the ignore list if required.
  49. if (isset($_POST['delete_id']) || isset($_GET['delete_id'])) {
  50. if (isset($_POST['delete_id'])) {
  51. $id = (int) $_POST['delete_id'];
  52. } else {
  53. $id = (int) $_GET['delete_id'];
  54. }
  55. unset($ignores[$id]);
  56. user_tagging_store_ignore_list($ignores);
  57. }
  58. if (isset($_POST['add'])) {
  59. if (!empty($_POST['forum']) && $_POST['forum'] != -1) {
  60. $id = (int) $_POST['forum'];
  61. $ignores[$id] = $id;
  62. user_tagging_store_ignore_list($ignores);
  63. }
  64. elseif (isset($_POST['vroot']) && $_POST['vroot'] != -1) {
  65. $id = (int) $_POST['vroot'];
  66. $ignores[$id] = $id;
  67. user_tagging_store_ignore_list($ignores);
  68. }
  69. }
  70. ?>
  71. <div class="PhorumAdminTitle">
  72. List of vroots and forums for which to ignore posts for the post counts
  73. </div>
  74. <div style="padding: 10px 0px">
  75. If you have forums or vroots that you do not want to include in
  76. the post counts for this module, then you can list those here.
  77. This could for example be useful if you have a sandbox forum,
  78. which can be used by your users to try out forum features.
  79. </div>
  80. <form action="<?php user_tagging_admin_url() ?>" method="post">
  81. <input type="hidden" name="module" value="modsettings"/>
  82. <input type="hidden" name="mod" value="user_tagging"/>
  83. <input type="hidden" name="list_ignore" value="1" />
  84. <table border="0" cellspacing="2" cellpadding="3" width="100%">
  85. <tr>
  86. <td class="PhorumAdminTableHead">Name</td>
  87. <td class="PhorumAdminTableHead">Actions</td>
  88. </tr>
  89. <?php
  90. if (empty($ignores))
  91. { ?>
  92. <tr>
  93. <td colspan="2" class="PhorumAdminTableRow">
  94. <i>The ignore list is empty</i>
  95. </td>
  96. </tr> <?php
  97. }
  98. else foreach ($ignores as $id)
  99. {
  100. if (!isset($forumid2name[$id])) continue;
  101. ?>
  102. <tr>
  103. <td class="PhorumAdminTableRow">
  104. <?php print $forumid2name[$id] ?>
  105. </td>
  106. <td class="PhorumAdminTableRow">
  107. <a href="<?php user_tagging_admin_url(array('list_ignore=1', 'delete_id='.$id)) ?>">Delete</a>
  108. </td>
  109. </tr> <?php
  110. }
  111. require_once('./include/admin/PhorumInputForm.php');
  112. $frm = new PhorumInputForm ("", "post", "Save rule");
  113. $select = '';
  114. // Create a vroot drop down menu if there are vroots available.
  115. if (!empty($vroot_folders))
  116. {
  117. $vroots = array(
  118. -1 => "Select vroot folder",
  119. 0 => "Top level forum folder"
  120. );
  121. foreach ($vroot_folders as $vroot_folder_id => $vroot_path) {
  122. $vroots[$vroot_folder_id] = $vroot_path;
  123. }
  124. $select .= $frm->select_tag("vroot", $vroots, -1, 'id="vroot_select" onchange="changeVroot()"');
  125. $initforums = array(
  126. -1 => "Any forum"
  127. );
  128. } else {
  129. $initforums = array(
  130. -1 => "Select forum"
  131. );
  132. foreach ($vroot2forums[0] as $f) {
  133. $initforums[$f['forum_id']] = $f['strpath'];
  134. }
  135. }
  136. // Create a forum drop down menu to allow selecting a specific forum.
  137. $select .= $frm->select_tag("forum", $initforums, -1, 'id="forum_select"');
  138. ?>
  139. <tr>
  140. <td colspan="2" class="PhorumAdminTableRow">
  141. <?php print $select ?>
  142. <input type="submit" name="add" value="Add" />
  143. </td>
  144. </tr>
  145. </table>
  146. </form>
  147. <script type="text/javascript">
  148. //<![CDATA[
  149. var vroot_forums = <?php print $vroot_js ?>;
  150. function changeVroot()
  151. {
  152. var vsel = document.getElementById('vroot_select');
  153. var fsel = document.getElementById('forum_select');
  154. if (!vsel || !fsel) return;
  155. var vroot = vsel.options[vsel.selectedIndex].value;
  156. var i = 0;
  157. fsel.options.length = 0;
  158. fsel.options[i++] = new Option('Any forum', -1);
  159. if (vroot >= 0 && vroot_forums[vroot]) {
  160. for (var nr in vroot_forums[vroot]) {
  161. fsel.options[i++] = new Option(vroot_forums[vroot][nr], nr);
  162. }
  163. }
  164. }
  165. //changeVroot();
  166. //]]>
  167. </script>