PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/newscoop/include/phorum/admin.php

https://github.com/nistormihai/Newscoop
PHP | 305 lines | 192 code | 65 blank | 48 comment | 58 complexity | d15ca6e7256d7d64805e0d0a60db88ba MD5 | raw file
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // //
  4. // Copyright (C) 2006 Phorum Development Team //
  5. // http://www.phorum.org //
  6. // //
  7. // This program is free software. You can redistribute it and/or modify //
  8. // it under the terms of either the current Phorum License (viewable at //
  9. // phorum.org) or the Phorum License that was distributed with this file //
  10. // //
  11. // This program is distributed in the hope that it will be useful, //
  12. // but WITHOUT ANY WARRANTY, without even the implied warranty of //
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
  14. // //
  15. // You should have received a copy of the Phorum License //
  16. // along with this program. //
  17. ////////////////////////////////////////////////////////////////////////////////
  18. // Phorum 5 Admin
  19. define("PHORUM_ADMIN", 1);
  20. // set a sane error level for our admin.
  21. // this will make the coding time faster and
  22. // the code run faster.
  23. error_reporting (E_ERROR | E_WARNING | E_PARSE);
  24. include_once "./common.php";
  25. include_once "./include/users.php";
  26. // if we are installing or upgrading, we don't need to check for a session
  27. // 2005081000 was the internal version that introduced the installed flag
  28. if(!isset($PHORUM['internal_version']) || (!isset($PHORUM['installed']) && $PHORUM['internal_version']>='2005081000')) {
  29. // this is an install
  30. $module="install";
  31. } elseif (isset($PHORUM['internal_version']) && $PHORUM['internal_version'] < PHORUMINTERNAL) {
  32. // this is an upgrade
  33. $module="upgrade";
  34. } else {
  35. // check for a session
  36. phorum_user_check_session("phorum_admin_session");
  37. if(!isset($GLOBALS["PHORUM"]["user"]) || !$GLOBALS["PHORUM"]["user"]["admin"]){
  38. // if not an admin
  39. unset($GLOBALS["PHORUM"]["user"]);
  40. $module="login";
  41. } else {
  42. // load the default module if none is specified
  43. if(!empty($_REQUEST["module"])){
  44. $module = basename($_REQUEST["module"]);
  45. } else {
  46. $module = "default";
  47. }
  48. }
  49. }
  50. ob_start();
  51. if($module!="help") include_once "./include/admin/header.php";
  52. @include_once "./include/admin/$module.php";
  53. if($module!="help") include_once "./include/admin/footer.php";
  54. ob_end_flush();
  55. /////////////////////////////////////////////////
  56. function phorum_admin_error($error)
  57. {
  58. echo "<div class=\"PhorumAdminError\">$error</div>\n";
  59. }
  60. function phorum_admin_okmsg($error)
  61. {
  62. echo "<div class=\"PhorumAdminOkMsg\">$error</div>\n";
  63. }
  64. // phorum_get_language_info and phorum_get_template_info moved to common.php (used in the cc too)
  65. function phorum_get_folder_info()
  66. {
  67. $folders=array();
  68. $folder_data=array();
  69. $forums = phorum_db_get_forums();
  70. foreach($forums as $forum){
  71. if($forum["folder_flag"]){
  72. $path = $forum["name"];
  73. $parent_id=$forum["parent_id"];
  74. while($parent_id!=0 && $parent_id!=$forum["forum_id"]){
  75. $path=$forums[$parent_id]["name"]."::$path";
  76. $parent_id=$forums[$parent_id]["parent_id"];
  77. }
  78. $folders[$forum["forum_id"]]=$path;
  79. }
  80. }
  81. asort($folders);
  82. $tmp=array("--None--");
  83. foreach($folders as $id => $folder){
  84. $tmp[$id]=$folder;
  85. }
  86. $folders=$tmp;
  87. return $folders;
  88. }
  89. function phorum_get_forum_info($forums_only=0)
  90. {
  91. $folders=array();
  92. $folder_data=array();
  93. $forums = phorum_db_get_forums();
  94. foreach($forums as $forum){
  95. if($forums_only == 0 || $forum['folder_flag']==0 || ($forums_only=2 && $forum['vroot'] && $forum['vroot'] == $forum['forum_id'])) {
  96. $path = $forum["name"];
  97. $parent_id=$forum["parent_id"];
  98. while($parent_id!=0){
  99. $path=$forums[$forum["parent_id"]]["name"]."::$path";
  100. $parent_id=$forums[$parent_id]["parent_id"];
  101. }
  102. if($forum['vroot'] && $forum['vroot']==$forum['forum_id']) {
  103. $path.=" (Virtual Root)";
  104. }
  105. $folders[$forum["forum_id"]]=$path;
  106. }
  107. }
  108. asort($folders);
  109. return $folders;
  110. }
  111. /*
  112. * Sets the given vroot for the descending forums / folders
  113. * which are not yet in another descending vroot
  114. *
  115. * $folder = folder from which we should go down
  116. * $vroot = virtual root we set the folders/forums to
  117. * $old_vroot = virtual root which should be overrideen with the new value
  118. *
  119. */
  120. function phorum_admin_set_vroot($folder,$vroot=-1,$old_vroot=0) {
  121. // which vroot
  122. if($vroot == -1) {
  123. $vroot=$folder;
  124. }
  125. // get the desc forums/folders
  126. $descending=phorum_admin_get_descending($folder);
  127. $valid=array();
  128. // collecting vroots
  129. $vroots=array();
  130. foreach($descending as $id => $data) {
  131. if($data['folder_flag'] == 1 && $data['vroot'] != 0 && $data['forum_id'] == $data['vroot']) {
  132. $vroots[$data['vroot']]=true;
  133. }
  134. }
  135. // getting forums which are not in a vroot or not in *this* vroot
  136. foreach($descending as $id => $data) {
  137. if($data['vroot'] == $old_vroot || !isset($vroots[$data['vroot']])) {
  138. $valid[$id]=$data;
  139. }
  140. }
  141. // $valid = forums/folders which are not in another vroot
  142. $set_ids=array_keys($valid);
  143. $set_ids[]=$folder;
  144. $new_forum_data=array('forum_id'=>$set_ids,'vroot'=>$vroot);
  145. $returnval=phorum_db_update_forum($new_forum_data);
  146. return $returnval;
  147. }
  148. function phorum_admin_get_descending($parent) {
  149. $ret_data=array();
  150. $arr_data=phorum_db_get_forums(0,$parent);
  151. foreach($arr_data as $key => $val) {
  152. $ret_data[$key]=$val;
  153. if($val['folder_flag'] == 1) {
  154. $more_data=phorum_db_get_forums(0,$val['forum_id']);
  155. $ret_data=$ret_data + $more_data; // array_merge reindexes the array
  156. }
  157. }
  158. return $ret_data;
  159. }
  160. function phorum_upgrade_tables($fromversion,$toversion) {
  161. $PHORUM=$GLOBALS['PHORUM'];
  162. if(empty($fromversion) || empty($toversion)){
  163. die("Something is wrong with the upgrade script. Please contact the Phorum Dev Team. ($fromversion,$toversion)");
  164. }
  165. $msg="";
  166. $upgradepath="./include/db/upgrade/{$PHORUM['DBCONFIG']['type']}/";
  167. // read in all existing files
  168. $dh=opendir($upgradepath);
  169. $upgradefiles=array();
  170. while ($file = readdir ($dh)) {
  171. if (substr($file,-4,4) == ".php") {
  172. $upgradefiles[]=$file;
  173. }
  174. }
  175. unset($file);
  176. closedir($dh);
  177. // sorting by number
  178. sort($upgradefiles,SORT_NUMERIC);
  179. reset($upgradefiles);
  180. // advance to current version
  181. while(list($key,$val)=each($upgradefiles)) {
  182. if($val == $fromversion.".php")
  183. break;
  184. }
  185. // get the file for the next version (which we will upgrade to)
  186. list($dump,$file) = each($upgradefiles);
  187. // extract the pure version, needed as internal version
  188. $pure_version = basename($file,".php");
  189. if(empty($pure_version)){
  190. die("Something is wrong with the upgrade script. Please contact the Phorum Dev Team. ($fromversion,$toversion)");
  191. }
  192. $upgradefile=$upgradepath.$file;
  193. if(file_exists($upgradefile)) {
  194. if (! is_readable($upgradefile))
  195. die("$upgradefile is not readable. Make sure the file has got the neccessary permissions and try again.");
  196. $msg.="Upgrading from db-version $fromversion to $pure_version ... ";
  197. $upgrade_queries=array();
  198. include($upgradefile);
  199. $err=phorum_db_run_queries($upgrade_queries);
  200. if($err){
  201. $msg.= "an error occured: $err ... try to continue.<br />\n";
  202. } else {
  203. $msg.= "done.<br />\n";
  204. }
  205. $GLOBALS["PHORUM"]["internal_version"]=$pure_version;
  206. phorum_db_update_settings(array("internal_version"=>$pure_version));
  207. } else {
  208. $msg="Ooops, the upgradefile is missing. How could this happen?";
  209. }
  210. return $msg;
  211. }
  212. function phorum_admin_gen_compare($txt) {
  213. $func = 0;
  214. if($txt == "gt") {
  215. $func = create_function('$a, $b', 'return $a > $b;');
  216. } elseif($txt == "gte") {
  217. $func = create_function('$a, $b', 'return $a >= $b;');
  218. } elseif($txt == "lt") {
  219. $func = create_function('$a, $b', 'return $a < $b;');
  220. } elseif($txt == "lte") {
  221. $func = create_function('$a, $b', 'return $a <= $b;');
  222. } elseif($txt == "eq") {
  223. $func = create_function('$a, $b', 'return $a == $b;');
  224. }
  225. if(!$func) {
  226. phorum_admin_error("Invalid posts comparison operator.");
  227. return NULL;
  228. }
  229. return $func;
  230. }
  231. function phorum_admin_filter_arr($arr,$field,$value,$cmpfn) {
  232. $new = array();
  233. foreach($arr as $item){
  234. if(isset($item[$field]) && $cmpfn($item[$field],$value)) {
  235. array_push($new,$item);
  236. }
  237. }
  238. return $new;
  239. }
  240. ?>