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

/wp-content/plugins/simple-forum/sf-control.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 313 lines | 171 code | 46 blank | 96 comment | 45 complexity | 107e47d582a29cf61a84deaba7e2d35e MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. /*
  3. Plugin Name: Simple:Press
  4. Version: 4.4.5
  5. Plugin URI: http://simple-press.com
  6. Description: Fully featured but simple page-based forum
  7. Author: Andy Staines & Steve Klasen
  8. Author URI: http://simple-press.com
  9. WordPress Versions: 3.1 and above
  10. For full acknowledgements click on the copyright/version strip
  11. at the bottom of forum pages
  12. */
  13. /* Copyright 2006/2010 Andy Staines & Steve Klasen
  14. Please read the 'License' supplied with this plugin (goto help/documentation)
  15. and abide by it's few simple requests. Note that the Highslide JS library is free to use on non-commercial sites.
  16. Commercial sites should seek a license for a small fee of about $29US.
  17. $LastChangedDate: 2011-06-25 07:24:41 -0700 (Sat, 25 Jun 2011) $
  18. $Rev: 6398 $
  19. */
  20. # -------------------------------------------------------------------------------------------------------------------
  21. if (preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF']))
  22. {
  23. die('Access Denied');
  24. }
  25. #==================================
  26. # REMOVE FOR DISTRIBUTION -- UNCOMMENT THE NEXT TWO LINES IF DEBUG INFO REQUIRED.
  27. #include_once (dirname(__FILE__).'/debug/sf-debug.php');
  28. #define("SHOWDEBUG", true);
  29. #==================================
  30. global $is_IIS;
  31. # hack for some IIS installations
  32. if ($is_IIS && @ini_get('error_log') == '') @ini_set('error_log', 'syslog');
  33. # try to increase backtrack limit
  34. if ((int) @ini_get('pcre.backtrack_limit') < 10000000000) @ini_set('pcre.backtrack_limit', 10000000000);
  35. # try to increase php memory
  36. if (function_exists('memory_get_usage') && ((int) @ini_get('memory_limit') < abs(intval('64M')))) @ini_set('memory_limit', '64M');
  37. # ----------------------------------------------------------
  38. # Establist version and system control constants
  39. # ----------------------------------------------------------
  40. define('SFPLUGNAME', 'Simple:Press');
  41. define('SFVERSION', '4.4.5');
  42. define('SFBUILD', 6398);
  43. define('SFRELEASE', 'Release');
  44. # ==================================================================
  45. # Bootstrap
  46. # ==================================================================
  47. # ------------------------------------------------------------------
  48. # Load global components
  49. # Load anything that is required globally
  50. # ------------------------------------------------------------------
  51. global $wpdb, $ISFORUM, $ISFORUMADMIN, $CACHE, $SFSTATUS, $SFPATHS, $CONTENTLOADED, $ACTIVEPANEL, $SFALLOPTIONS;
  52. $ISFORUM = false;
  53. $ISFORUMADMIN = false;
  54. $CONTENTLOADED = false;
  55. $CACHE = array();
  56. $ACTIVEPANEL = array();
  57. # if this is a network upgrade, make sure we switch to the site being updated
  58. # this is so the constants are defined for right blog
  59. if (isset($_GET['sfnetworkid']))
  60. {
  61. switch_to_blog(esc_sql($_GET['sfnetworkid']));
  62. }
  63. # ------------------------------------------------------------------
  64. # DB Tables constants
  65. # ------------------------------------------------------------------
  66. if(!defined('SF_PREFIX')) {
  67. define('SF_PREFIX', $wpdb->prefix);
  68. }
  69. sf_initialise_cache();
  70. include_once (dirname(__FILE__).'/sf-config.php');
  71. include_once (dirname(__FILE__).'/library/sf-primitives.php');
  72. $SFALLOPTIONS = sf_load_alloptions();
  73. $SFPATHS = sf_get_option('sfconfig');
  74. include_once (dirname(__FILE__).'/sf-constants.php');
  75. sf_setup_sitewide_constants();
  76. $SFSTATUS = sfg_get_system_status();
  77. include_once (SF_PLUGIN_DIR.'/sf-includes.php');
  78. sf_setup_global_includes();
  79. include_once (SF_PLUGIN_DIR.'/sf-loader-global.php');
  80. include_once (SF_PLUGIN_DIR.'/sf-hooks.php');
  81. sf_setup_sitewide_hooks();
  82. include_once (SF_PLUGIN_DIR.'/sf-loader-ahah.php');
  83. include_once (SF_PLUGIN_DIR.'/credentials/sf-credentials.php');
  84. # ------------------------------------------------------------------
  85. # Plugin Activation
  86. # ensure that permalink and rewrite rules are set on a re-activation
  87. # after upgrade
  88. # ------------------------------------------------------------------
  89. register_activation_hook(__FILE__, 'sfg_update_permalink');
  90. # ------------------------------------------------------------------
  91. # ------------------------------------------------------------------
  92. # sf_boot_forum()
  93. # Called from hook: 'wp_print_scripts'
  94. # Checks if a forum page (front and back) and loads the required
  95. # javascripts
  96. # ------------------------------------------------------------------
  97. function sf_boot_forum()
  98. {
  99. global $ISFORUM, $ISFORUMADMIN, $ACTIVEPANEL, $wp_query;
  100. if (is_admin())
  101. {
  102. sf_setup_sitewide_late_hooks();
  103. if ((isset($_GET['page'])) && (stristr($_GET['page'], 'simple-forum')) !== false)
  104. {
  105. $ISFORUMADMIN=true;
  106. sfa_set_activepanels();
  107. sfa_admin_load_js();
  108. }
  109. } else {
  110. if ((is_page()) && ($wp_query->post->ID == sf_get_option('sfpage')))
  111. {
  112. $ISFORUM=true;
  113. sf_setup_sitewide_late_hooks();
  114. sf_setup_global_constants();
  115. sf_setup_forum_constants();
  116. sf_setup_forum_includes();
  117. sf_setup_forum_hooks();
  118. sf_load_front_js();
  119. } else {
  120. # non-forum page...
  121. sf_load_front_blog_js();
  122. }
  123. }
  124. return;
  125. }
  126. # ------------------------------------------------------------------
  127. # sf_boot_forum_admin()
  128. # Called from hook: 'admin_menu'
  129. # Starts up the back end loading up the admin menus
  130. # ------------------------------------------------------------------
  131. function sf_boot_forum_admin()
  132. {
  133. sf_setup_global_constants();
  134. sf_setup_admin_constants();
  135. sf_setup_admin_includes();
  136. sf_setup_admin_hooks();
  137. sfa_admin_menu();
  138. return;
  139. }
  140. # ------------------------------------------------------------------
  141. # sf_check_header()
  142. #
  143. # Checks if this is the forum page loading and sets up the incudes
  144. # and the page header
  145. # Called by wp_head filter
  146. # ------------------------------------------------------------------
  147. function sf_check_header()
  148. {
  149. global $ISFORUM, $sfvars, $wp_query, $sfglobals, $aioseop_options;
  150. if ($ISFORUM)
  151. {
  152. sf_setup_header();
  153. # If a PM request load PM files
  154. if (!empty($sfvars['pm']))
  155. {
  156. sf_setup_pm_includes();
  157. }
  158. } else {
  159. if(sf_get_option('sfannounceauto'))
  160. {
  161. echo '<script type="text/javascript" src="'.SFJSCRIPT.'forum/sf-forum.js"></script>' . "\n";
  162. }
  163. # is it a blog linked post and need to point canonical url to linke topic?
  164. $post = $wp_query->get_queried_object();
  165. if (!empty($post->ID) && $sfglobals['canonicalurl'] == false)
  166. {
  167. $sfpostlinking = sf_get_option('sfpostlinking');
  168. $topic = sf_blog_links_control('read', $post->ID);
  169. if (!empty($topic) && $sfpostlinking['sflinkurls'] == 2) # point blog post to linked topic?
  170. {
  171. $forum_slug = sf_get_forum_slug($topic->forum_id);
  172. $topic_slug = sf_get_topic_slug($topic->topic_id);
  173. $url = sf_build_url($forum_slug, $topic_slug, 0, 0);
  174. echo '<link rel="canonical" href="'.$url.'" />'."\n";
  175. $sfglobals['canonicalurl'] = true;
  176. }
  177. }
  178. # let wp canonical url run if we didnt do it
  179. if ($sfglobals['canonicalurl'] == false) rel_canonical();
  180. }
  181. }
  182. # ------------------------------------------------------------------
  183. # sf_initialise_cache()
  184. #
  185. # Create the cache control array to stop wasted and multiple calls
  186. # ro the building of permission caches and extender user object
  187. # ------------------------------------------------------------------
  188. function sf_initialise_cache()
  189. {
  190. global $CACHE;
  191. $CACHE['user']=false;
  192. $CACHE['forumid']='';
  193. $CACHE['membership']=false;
  194. $CACHE['permissions']=false;
  195. $CACHE['roles']=false;
  196. $CACHE['ranks']=false;
  197. $CACHE['member']=false;
  198. $CACHE['globals']=false;
  199. return;
  200. }
  201. # ------------------------------------------------------------------
  202. # sfa_set_activepanels()
  203. #
  204. # Builds contro list of admin panels for later identification
  205. # ------------------------------------------------------------------
  206. function sfa_set_activepanels()
  207. {
  208. global $ACTIVEPANEL;
  209. $ACTIVEPANEL['forums']=0;
  210. $ACTIVEPANEL['options']=1;
  211. $ACTIVEPANEL['components']=2;
  212. $ACTIVEPANEL['usergroups']=3;
  213. $ACTIVEPANEL['permissions']=4;
  214. $ACTIVEPANEL['users']=5;
  215. $ACTIVEPANEL['profiles']=6;
  216. $ACTIVEPANEL['admins']=7;
  217. $ACTIVEPANEL['tags']=8;
  218. $ACTIVEPANEL['toolbox']=9;
  219. $ACTIVEPANEL['config']=10;
  220. $ACTIVEPANEL['integration']=11;
  221. return;
  222. }
  223. # ------------------------------------------------------------------
  224. # sfg_get_system_status()
  225. # Determine if forum can be run or if it requires install/upgrade
  226. # ------------------------------------------------------------------
  227. function sfg_get_system_status()
  228. {
  229. global $wpdb;
  230. $current_version = sf_get_option('sfversion');
  231. $current_build = sf_get_option('sfbuild');
  232. # First find out if build number has changed but check first against the log
  233. # in case it is a glitch or has been changed in the toolbox
  234. if((empty($current_version) || version_compare($current_version, '1.0', '<')) || (($current_build != SFBUILD) || ($current_version != SFVERSION)))
  235. {
  236. # If table SFLOG exists then there is a chance the option records got corrupted (?) or the build has been manually rerset
  237. # so get the values from the log and compare
  238. $sql = "SHOW TABLES LIKE '".SFLOG."'";
  239. $log = $wpdb->query($sql);
  240. if(!empty($log))
  241. {
  242. # So the log table exists. We check the last log entry build number
  243. # aganst the option build number and if option build number is less
  244. # we update it to the last log entry
  245. $sql = "SELECT build, version FROM ".SFLOG." ORDER BY id DESC LIMIT 1";
  246. $log = $wpdb->get_results($sql);
  247. if($current_build != $log[0]->build)
  248. {
  249. # But if the force upgrade flag is set we do NOIT reset build number
  250. if(sf_get_option('sfforceupgrade') == false)
  251. {
  252. sf_update_option('sfbuild', $log[0]->build);
  253. sf_update_option('sfversion', $log[0]->version);
  254. $current_build = $log[0]->build;
  255. $current_version = $log[0]->version;
  256. }
  257. }
  258. }
  259. }
  260. # Has the systen been installed?
  261. if(empty($current_version) || version_compare($current_version, '1.0', '<')) return 'Install';
  262. # Base already installed - check Version and Build Number
  263. if(($current_build < SFBUILD) || ($current_version != SFVERSION)) return 'Upgrade';
  264. return 'ok';
  265. }
  266. ?>