PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/gp-settings.php

https://bitbucket.org/moodsdesign-ondemand/reglot
PHP | 368 lines | 264 code | 70 blank | 34 comment | 63 complexity | 19acf9886913028b60abfb7e182d72bf MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Loads needed libraries and does the preliminary work. You should not have to
  4. * edit this file. Everything should be configurable from the outside. Starts the
  5. * routing logic in the end.
  6. */
  7. if ( defined( 'GP_DEBUG' ) && GP_DEBUG ) {
  8. error_reporting( E_ALL );
  9. } else {
  10. if ( defined( 'E_RECOVERABLE_ERROR' ) )
  11. error_reporting( E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
  12. else
  13. error_reporting( E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING );
  14. }
  15. require_once( GP_PATH . GP_INC . '/system.php' );
  16. gp_unregister_GLOBALS();
  17. if ( !defined( 'BACKPRESS_PATH' ) ) {
  18. define( 'BACKPRESS_PATH', GP_PATH . GP_INC . 'backpress/' );
  19. }
  20. if ( !defined( 'GP_POMO_PATH' ) ) {
  21. define( 'GP_POMO_PATH', GP_PATH . 'pomo/' );
  22. }
  23. if ( !defined( 'GP_LOCALES_PATH' ) ) {
  24. define( 'GP_LOCALES_PATH', GP_PATH . 'locales/' );
  25. }
  26. if ( !defined( 'GP_LANG_PATH' ) ) {
  27. define( 'GP_LANG_PATH', GP_PATH . 'languages/' );
  28. }
  29. if ( !defined( 'GP_PLUGINS_PATH' ) ) {
  30. define( 'GP_PLUGINS_PATH', GP_PATH . 'plugins/' );
  31. }
  32. if ( !defined( 'DATE_MYSQL' ) ) {
  33. define( 'DATE_MYSQL', 'Y-m-d H:i:s' );
  34. }
  35. if ( !defined( 'GP_TESTS_PATH' ) ) {
  36. define( 'GP_TESTS_PATH', GP_PATH . 't/' );
  37. }
  38. require_once( GP_PATH . GP_INC . 'gp.php');
  39. /*
  40. * In most cases the default internal encoding is latin1, which is of no use,
  41. * since we want to use the mb_ functions for UTF-8 strings
  42. */
  43. if (function_exists('mb_internal_encoding')) {
  44. mb_internal_encoding('UTF-8');
  45. }
  46. require_once( BACKPRESS_PATH . 'class.bp-log.php' );
  47. $gp_log = new BP_Log();
  48. if ( defined( 'GP_LOG_LEVEL' ) ) {
  49. $gp_log->set_level( GP_LOG_LEVEL );
  50. }
  51. if ( defined( 'GP_LOG_TYPE' ) ) {
  52. $gp_log->set_type( GP_LOG_TYPE );
  53. }
  54. if ( defined( 'GP_LOG_FILENAME' ) ) {
  55. $gp_log->set_filename( GP_LOG_FILENAME );
  56. }
  57. $gp_log->notice('Logging started');
  58. // Load core BackPress functions
  59. require_once( BACKPRESS_PATH . 'functions.core.php' );
  60. require_once( BACKPRESS_PATH . 'functions.compat.php' );
  61. require_once( BACKPRESS_PATH . 'functions.formatting.php' );
  62. // alleviate the magic_quotes_gpc effects
  63. if ( get_magic_quotes_gpc() ) {
  64. $_GET = stripslashes_deep( $_GET );
  65. $_POST = stripslashes_deep( $_POST );
  66. $_COOKIE = stripslashes_deep( $_COOKIE );
  67. }
  68. $_GET = gp_urldecode_deep( $_GET );
  69. require_once( BACKPRESS_PATH . 'class.wp-error.php' );
  70. if ( !defined('GP_INSTALLING') || !GP_INSTALLING ) {
  71. if ( !defined( 'GP_DATABASE_CLASS_INCLUDE' ) ) {
  72. define( 'GP_DATABASE_CLASS_INCLUDE', BACKPRESS_PATH . 'class.bpdb-multi.php' );
  73. }
  74. if ( GP_DATABASE_CLASS_INCLUDE ) {
  75. require_once( GP_DATABASE_CLASS_INCLUDE );
  76. }
  77. if ( !defined( 'GP_DATABASE_CLASS' ) ) {
  78. define( 'GP_DATABASE_CLASS', 'BPDB_Multi' );
  79. }
  80. if ( in_array( GP_DATABASE_CLASS, array( 'BPDB', 'BPDB_Multi' ) ) ) {
  81. /**
  82. * Define BackPress Database errors if not already done - no localisation at this stage
  83. */
  84. if ( !defined( 'BPDB__CONNECT_ERROR_MESSAGE' ) ) {
  85. define( 'BPDB__CONNECT_ERROR_MESSAGE', 'ERROR: Could not establish a database connection' );
  86. }
  87. if ( !defined( 'BPDB__CONNECT_ERROR_MESSAGE' ) ) {
  88. define( 'BPDB__SELECT_ERROR_MESSAGE', 'ERROR: Can\'t select database.' );
  89. }
  90. if ( !defined( 'BPDB__ERROR_STRING' ) ) {
  91. define( 'BPDB__ERROR_STRING', 'ERROR: GlotPress database error - "%s" for query "%s" via caller "%s"' );
  92. }
  93. if ( !defined( 'BPDB__ERROR_HTML' ) ) {
  94. define( 'BPDB__ERROR_HTML', '<div id="error"><p class="bpdberror"><strong>Database error:</strong> [%s]<br /><code>%s</code><br />Caller: %s</p></div>' );
  95. }
  96. if ( !defined( 'BPDB__DB_VERSION_ERROR' ) ) {
  97. define( 'BPDB__DB_VERSION_ERROR', 'ERROR: GlotPress requires MySQL 4.0.0 or higher' );
  98. }
  99. if ( !defined( 'BPDB__PHP_EXTENSION_MISSING' ) ) {
  100. define( 'BPDB__PHP_EXTENSION_MISSING', 'ERROR: GlotPress requires The MySQL PHP extension' );
  101. }
  102. }
  103. // Die if there is no database table prefix
  104. if ( !$gp_table_prefix ) {
  105. die( 'You must specify a table prefix in your <code>gp-config.php</code> file.' );
  106. }
  107. // Setup the global database connection
  108. $gpdb_class = GP_DATABASE_CLASS;
  109. $gpdb = new $gpdb_class( array(
  110. 'name' => GPDB_NAME,
  111. 'user' => GPDB_USER,
  112. 'password' => GPDB_PASSWORD,
  113. 'host' => GPDB_HOST,
  114. 'charset' => defined( 'GPDB_CHARSET' ) ? GPDB_CHARSET : false,
  115. 'collate' => defined( 'GPDB_COLLATE' ) ? GPDB_COLLATE : false
  116. ) );
  117. unset( $gpdb_class );
  118. $gpdb->table_names = array('translations', 'translation_sets', 'originals', 'projects', 'users', 'usermeta', 'meta', 'permissions', 'api_keys', );
  119. foreach( $gpdb->table_names as $table ) {
  120. $gpdb->tables[$table] = false;
  121. }
  122. unset( $table );
  123. // Set the prefix on the tables
  124. if ( is_wp_error( $gpdb->set_prefix( $gp_table_prefix ) ) ) {
  125. die( 'Your table prefix may only contain letters, numbers and underscores.' );
  126. }
  127. if ( defined( 'CUSTOM_USER_TABLE' ) )
  128. $gpdb->users = CUSTOM_USER_TABLE;
  129. if ( defined( 'CUSTOM_USER_META_TABLE' ) )
  130. $gpdb->usermeta = CUSTOM_USER_META_TABLE;
  131. if ( defined( 'CUSTOM_PERMISSIONS_TABLE' ) )
  132. $gpdb->permissions = CUSTOM_PERMISSIONS_TABLE;
  133. }
  134. if ( !function_exists( 'add_filter' ) ) {
  135. require_once( BACKPRESS_PATH . 'functions.plugin-api.php' );
  136. }
  137. if ( !defined( 'GP_TMPL_PATH' ) )
  138. define( 'GP_TMPL_PATH', GP_PATH . 'gp-templates/bootstrap/' );
  139. require_once( GP_PATH . GP_INC . 'lambda.php');
  140. require_once( GP_PATH . GP_INC . 'meta.php' );
  141. require_once( GP_PATH . GP_INC . 'misc.php' );
  142. require_once( GP_PATH . GP_INC . 'url.php' );
  143. require_once( GP_PATH . GP_INC . 'strings.php' );
  144. require_once( GP_PATH . GP_INC . 'template.php' );
  145. require_once( GP_PATH . GP_INC . 'template-links.php' );
  146. require_once( GP_PATH . GP_INC . 'cli.php' );
  147. if ( !defined('GP_INSTALLING') || !GP_INSTALLING ) {
  148. /**
  149. * Define the full path to the object cache functions include
  150. */
  151. if ( !defined( 'GP_OBJECT_CACHE_FUNCTIONS_INCLUDE' ) ) {
  152. define( 'GP_OBJECT_CACHE_FUNCTIONS_INCLUDE', BACKPRESS_PATH . 'loader.wp-object-cache.php' );
  153. }
  154. // Load the database class
  155. if ( GP_OBJECT_CACHE_FUNCTIONS_INCLUDE && !function_exists( 'wp_cache_init' ) ) {
  156. require_once( GP_OBJECT_CACHE_FUNCTIONS_INCLUDE );
  157. }
  158. // Instantiate the $wp_object_cache object using wp_cache_init()
  159. if ( !isset( $wp_object_cache ) && function_exists( 'wp_cache_init' ) ) {
  160. wp_cache_init();
  161. if ( function_exists( 'wp_cache_add_global_groups' ) ) {
  162. wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'usermail', 'usernicename' ) );
  163. }
  164. }
  165. }
  166. require_once( GP_PATH . GP_INC . 'class.bp-options.php' );
  167. require_once( BACKPRESS_PATH . 'functions.bp-options.php' );
  168. require_once( BACKPRESS_PATH . 'class.wp-http.php' );
  169. require_once( BACKPRESS_PATH . 'class.wp-dependencies.php' );
  170. require_once( BACKPRESS_PATH . 'class.wp-styles.php' );
  171. require_once( BACKPRESS_PATH . 'functions.wp-styles.php' );
  172. require_once( BACKPRESS_PATH . 'class.wp-scripts.php' );
  173. require_once( BACKPRESS_PATH . 'functions.wp-scripts.php' );
  174. require_once( GP_PATH . GP_INC . 'assets-loader.php' );
  175. require_once( GP_PATH . GP_INC . 'default-filters.php' );
  176. require_once( BACKPRESS_PATH . 'functions.kses.php' );
  177. require_once( GP_POMO_PATH . 'mo.php' );
  178. require_once( GP_POMO_PATH . 'po.php' );
  179. require_once( GP_PATH . GP_INC . 'l10n.php' );
  180. require_once( GP_LOCALES_PATH . 'locales.php' );
  181. if ( defined('GP_INSTALLING') && GP_INSTALLING ) {
  182. // Users and authentication
  183. require_once(GP_PATH . GP_INC . 'class.gp-userauth.php');
  184. foreach( glob(GP_PATH . GP_INC . 'authentication/userauth_*.php') as $auth_file ) {
  185. require_once $auth_file;
  186. }
  187. unset($auth_file);
  188. } else {
  189. if ( defined('GP_AUTH') ) {
  190. $auth = GP_AUTH;
  191. } else {
  192. $auth = 'wordpress';
  193. }
  194. require_once(GP_PATH . GP_INC . 'class.gp-userauth.php');
  195. require_once(GP_PATH . GP_INC . "authentication/userauth_$auth.php");
  196. $wp_user_auth = GP::$userauths[$auth];
  197. }
  198. if ( !defined( 'WP_AUTH_COOKIE_VERSION' ) ) {
  199. define( 'WP_AUTH_COOKIE_VERSION', 2 );
  200. }
  201. // WP_Pass
  202. if ( !class_exists( 'WP_Pass' ) ) {
  203. require_once( BACKPRESS_PATH . 'class.wp-pass.php' );
  204. }
  205. // We assume all variables set in this file will be global.
  206. // If the file is inovked inside a function, we will lose them all.
  207. // So, make all local variables, global
  208. gp_set_globals( get_defined_vars() );
  209. if ( !defined('GP_INSTALLING') || !GP_INSTALLING ) {
  210. /**
  211. * It is possible to define this in wp-config.php and it will be used as the domain for all cookies.
  212. * Set it carefully for sharing cookies amonst subdomains
  213. *
  214. * @link http://curl.haxx.se/rfc/cookie_spec.html
  215. */
  216. if ( !defined('GP_COOKIE_DOMAIN') )
  217. define('GP_COOKIE_DOMAIN', false);
  218. if ( !class_exists( 'WP_Auth' ) ) {
  219. require_once( BACKPRESS_PATH . 'class.wp-auth.php' );
  220. $cookies = array();
  221. $cookies['auth'][] = array(
  222. 'domain' => GP_COOKIE_DOMAIN,
  223. 'path' => gp_url_path(),
  224. 'name' => gp_const_get( 'GP_AUTH_COOKIE', 'glotpress_auth' ),
  225. );
  226. $cookies['secure_auth'][] = array(
  227. 'domain' => GP_COOKIE_DOMAIN,
  228. 'path' => gp_url_path(),
  229. 'name' => gp_const_get( 'GP_SECURE_AUTH_COOKIE', 'glotpress_sec_auth' ),
  230. 'secure' => 'true',
  231. );
  232. $cookies['logged_in'][] = array(
  233. 'domain' => GP_COOKIE_DOMAIN,
  234. 'path' => gp_url_path(),
  235. 'name' => gp_const_get( 'GP_LOGGED_IN_COOKIE', 'glotpress_logged_in' ),
  236. );
  237. $wp_auth_object = new WP_Auth( $gpdb, $wp_users_object, $cookies );
  238. unset( $cookies );
  239. }
  240. }
  241. require_once( GP_PATH . GP_INC . 'warnings.php' );
  242. require_once( GP_PATH . GP_INC . 'validation.php' );
  243. require_once( GP_PATH . GP_INC . 'google.php' );
  244. require_once( GP_PATH . GP_INC . 'advanced-permissions.php' );
  245. if ( !defined('GP_INSTALLING') || !GP_INSTALLING ) {
  246. require_once GP_PATH . GP_INC . 'thing.php';
  247. foreach( glob( GP_PATH . GP_INC . 'things/*.php' ) as $thing_file ) {
  248. require_once $thing_file;
  249. }
  250. }
  251. require_once( GP_PATH . GP_INC . 'route.php' );
  252. require_once( GP_PATH . GP_INC . 'router.php' );
  253. foreach( glob( GP_PATH . GP_INC . 'routes/*.php' ) as $route_file ) {
  254. require_once $route_file;
  255. }
  256. if ( !defined('GP_INSTALLING') || !GP_INSTALLING ) {
  257. GP::$translation_warnings = new GP_Translation_Warnings();
  258. GP::$builtin_translation_warnings = new GP_Builtin_Translation_Warnings();
  259. GP::$builtin_translation_warnings->add_all( GP::$translation_warnings );
  260. GP::$router = new GP_Router();
  261. GP::$formats = array();
  262. require_once( GP_PATH . GP_INC . 'class.gp-format.php' );
  263. foreach( glob( GP_PATH . GP_INC . 'formats/format_*.php' ) as $format_file ) {
  264. require_once $format_file;
  265. }
  266. unset( $format_file );
  267. // Let's do it again, there are more variables added since last time we called it
  268. gp_set_globals( get_defined_vars() );
  269. require_once( GP_PATH . GP_INC . 'plugin.php' );
  270. $plugins = glob( GP_PLUGINS_PATH . '*.php' );
  271. if ( $plugins ) {
  272. foreach( $plugins as $plugin ) {
  273. require_once $plugin;
  274. }
  275. }
  276. $plugin_dirs = glob( GP_PLUGINS_PATH . '*', GLOB_ONLYDIR );
  277. if ( $plugin_dirs ) {
  278. foreach( $plugin_dirs as $plugin_dir ) {
  279. $plugin = "$plugin_dir/" . basename( $plugin_dir ) . '.php';
  280. if ( is_readable( $plugin ) ) require_once $plugin;
  281. }
  282. }
  283. unset( $plugins, $plugin, $plugin_dirs, $plugin_dir );
  284. do_action( 'plugins_loaded' );
  285. }
  286. if ( !defined( 'GP_ROUTING') ) {
  287. define( 'GP_ROUTING', false );
  288. }
  289. gp_populate_notices();
  290. function gp_shutdown_action_hook() {
  291. do_action( 'shutdown' );
  292. }
  293. register_shutdown_function( 'gp_shutdown_action_hook' );
  294. do_action( 'init' );
  295. if ( GP_ROUTING ) {
  296. GP::$router->route();
  297. }
  298. define('GP_TOT_INSTALL_PAGES', 3);