PageRenderTime 88ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/inc/common.php

http://get-simple-cms.googlecode.com/
PHP | 252 lines | 154 code | 40 blank | 58 comment | 55 complexity | 400d7b67a2d239c9e62ad719805cf1ab MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * Common Setup File
  4. *
  5. * This file initializes up most variables for the site. It is also where most files
  6. * are included from. It also reads and stores certain variables.
  7. *
  8. * @package GetSimple
  9. * @subpackage init
  10. */
  11. /**
  12. * Bad stuff protection
  13. */
  14. define('IN_GS', TRUE);
  15. include_once('security_functions.php');
  16. if (version_compare(PHP_VERSION, "5") >= 0) {
  17. foreach ($_GET as &$xss) $xss = antixss($xss);
  18. }
  19. /**
  20. * Basic file inclusions
  21. */
  22. include('basic.php');
  23. include('template_functions.php');
  24. include('logging.class.php');
  25. define('GSROOTPATH', get_root_path());
  26. if (file_exists(GSROOTPATH . 'gsconfig.php')) {
  27. require_once(GSROOTPATH . 'gsconfig.php');
  28. }
  29. if (defined('GSADMIN')) {
  30. $GSADMIN = GSADMIN;
  31. } else {
  32. $GSADMIN = 'admin';
  33. }
  34. /**
  35. * Define some constants
  36. */
  37. define('GSADMINPATH', get_admin_path());
  38. define('GSADMININCPATH', GSADMINPATH. 'inc/');
  39. define('GSPLUGINPATH', GSROOTPATH. 'plugins/');
  40. define('GSLANGPATH', GSADMINPATH. 'lang/');
  41. define('GSDATAPATH', GSROOTPATH. 'data/');
  42. define('GSDATAOTHERPATH', GSROOTPATH. 'data/other/');
  43. define('GSDATAPAGESPATH', GSROOTPATH. 'data/pages/');
  44. define('GSDATAUPLOADPATH', GSROOTPATH. 'data/uploads/');
  45. define('GSTHUMBNAILPATH', GSROOTPATH. 'data/thumbs/');
  46. define('GSBACKUPSPATH', GSROOTPATH. 'backups/');
  47. define('GSTHEMESPATH', GSROOTPATH. 'theme/');
  48. define('GSUSERSPATH', GSROOTPATH. 'data/users/');
  49. define('GSBACKUSERSPATH', GSROOTPATH. 'backups/users/');
  50. define('GSCACHEPATH', GSROOTPATH. 'data/cache/');
  51. define('GSAUTOSAVEPATH', GSROOTPATH. 'data/pages/autosave/');
  52. /* create new folders */
  53. if (!file_exists(GSCACHEPATH)) {
  54. if (defined('GSCHMOD')) {
  55. $chmod_value = GSCHMOD;
  56. } else {
  57. $chmod_value = 0755;
  58. }
  59. mkdir(GSCACHEPATH, $chmod_value);
  60. }
  61. if (!file_exists(GSAUTOSAVEPATH)) {
  62. if (defined('GSCHMOD')) {
  63. $chmod_value = GSCHMOD;
  64. } else {
  65. $chmod_value = 0755;
  66. }
  67. mkdir(GSAUTOSAVEPATH, $chmod_value);
  68. }
  69. /**
  70. * Variable check to prevent debugging going off
  71. * @todo some of these may not even be needed anymore
  72. */
  73. $admin_relative = (isset($admin_relative)) ? $admin_relative : '';
  74. $lang_relative = (isset($lang_relative)) ? $lang_relative : '';
  75. $load['login'] = (isset($load['login'])) ? $load['login'] : '';
  76. $load['plugin'] = (isset($load['plugin'])) ? $load['plugin'] : '';
  77. /**
  78. * Debugging
  79. */
  80. if ( defined('GSDEBUG') && (GSDEBUG == TRUE) ) {
  81. error_reporting(-1);
  82. ini_set('display_errors', 1);
  83. } else {
  84. error_reporting(0);
  85. ini_set('display_errors', 0);
  86. }
  87. ini_set('log_errors', 1);
  88. ini_set('error_log', GSDATAOTHERPATH .'logs/errorlog.txt');
  89. /**
  90. * Pull data from storage
  91. */
  92. /** grab website data */
  93. $thisfilew = GSDATAOTHERPATH .'website.xml';
  94. if (file_exists($thisfilew)) {
  95. $dataw = getXML($thisfilew);
  96. $SITENAME = stripslashes($dataw->SITENAME);
  97. $SITEURL = $dataw->SITEURL;
  98. $TEMPLATE = $dataw->TEMPLATE;
  99. $PRETTYURLS = $dataw->PRETTYURLS;
  100. $PERMALINK = $dataw->PERMALINK;
  101. } else {
  102. $SITENAME = '';
  103. }
  104. /** grab user data */
  105. if (isset($_COOKIE['GS_ADMIN_USERNAME'])) {
  106. $cookie_user_id = _id($_COOKIE['GS_ADMIN_USERNAME']);
  107. if (file_exists(GSUSERSPATH . $cookie_user_id.'.xml')) {
  108. $datau = getXML(GSUSERSPATH . $cookie_user_id.'.xml');
  109. $USR = stripslashes($datau->USR);
  110. $HTMLEDITOR = $datau->HTMLEDITOR;
  111. $TIMEZONE = $datau->TIMEZONE;
  112. $LANG = $datau->LANG;
  113. } else {
  114. $USR = null;
  115. $TIMEZONE = defined('GSTIMEZONE') ? GSTIMEZONE : "";
  116. }
  117. } else {
  118. $USR = null;
  119. $TIMEZONE = defined('GSTIMEZONE') ? GSTIMEZONE : "";
  120. }
  121. /** grab authorization and security data */
  122. if (file_exists(GSDATAOTHERPATH .'authorization.xml')) {
  123. $dataa = getXML(GSDATAOTHERPATH .'authorization.xml');
  124. $SALT = stripslashes($dataa->apikey);
  125. } else {
  126. $SALT = sha1($SITEURL);
  127. }
  128. $SESSIONHASH = sha1($SALT . $SITENAME);
  129. /**
  130. * Timezone setup
  131. */
  132. if( function_exists('date_default_timezone_set') && ($TIMEZONE != "" || stripos($TIMEZONE, '--')) ) {
  133. date_default_timezone_set($TIMEZONE);
  134. }
  135. /**
  136. * Language control
  137. */
  138. if(!isset($LANG) || $LANG == '') {
  139. $filenames = getFiles(GSLANGPATH);
  140. $cntlang = count($filenames);
  141. if ($cntlang == 1) {
  142. $LANG = basename($filenames[0], ".php");
  143. } elseif($cntlang > 1) {
  144. $LANG = 'en_US';
  145. }
  146. }
  147. include_once(GSLANGPATH . $LANG . '.php');
  148. /**
  149. * Variable Globalization
  150. */
  151. global $SITENAME, $SITEURL, $TEMPLATE, $TIMEZONE, $LANG, $SALT, $i18n, $USR, $PERMALINK, $GSADMIN, $components;
  152. $GS_debug = array();
  153. /**
  154. * $base is if the site is being viewed from the front-end
  155. */
  156. if(isset($base)) {
  157. include_once(GSADMININCPATH.'theme_functions.php');
  158. }
  159. /**
  160. * Check to make sure site is already installed
  161. */
  162. if (get_filename_id() != 'install' && get_filename_id() != 'setup' && get_filename_id() != 'update') {
  163. $fullpath = suggest_site_path();
  164. # if an update file was included in the install package, redirect there first
  165. if (file_exists(GSDATAOTHERPATH .'user.xml')) {
  166. if (file_exists(GSADMINPATH.'update.php')) {
  167. redirect($fullpath . $GSADMIN.'/update.php');
  168. }
  169. }
  170. # if there is no SITEURL set, then it's a fresh install. Start installation process
  171. if ($SITEURL == '') {
  172. redirect($fullpath . $GSADMIN.'/install.php');
  173. }
  174. # if you've made it this far, the site is already installed so remove the installation files
  175. $filedeletionstatus=true;
  176. if (file_exists(GSADMINPATH.'install.php')) {
  177. $filedeletionstatus = unlink(GSADMINPATH.'install.php');
  178. }
  179. if (file_exists(GSADMINPATH.'setup.php')) {
  180. $filedeletionstatus = unlink(GSADMINPATH.'setup.php');
  181. }
  182. if (file_exists(GSADMINPATH.'update.php')) {
  183. $filedeletionstatus = unlink(GSADMINPATH.'update.php');
  184. }
  185. if (!$filedeletionstatus) {
  186. $error = sprintf(i18n_r('ERR_CANNOT_DELETE'), '<code>/'.$GSADMIN.'/install.php</code>, <code>/'.$GSADMIN.'/setup.php</code> or <code>/'.$GSADMIN.'/update.php</code>');
  187. }
  188. }
  189. /**
  190. * Include other files depending if they are needed or not
  191. */
  192. include_once(GSADMININCPATH.'cookie_functions.php');
  193. if(isset($load['plugin']) && $load['plugin']){
  194. # remove the pages.php plugin if it exists.
  195. if (file_exists(GSPLUGINPATH.'pages.php')) {
  196. unlink(GSPLUGINPATH.'pages.php');
  197. }
  198. include_once(GSADMININCPATH.'plugin_functions.php');
  199. if(get_filename_id()=='settings' || get_filename_id()=='load') {
  200. /* this core plugin only needs to be visible when you are viewing the
  201. settings page since that is where it's sidebar item is. */
  202. if (defined('GSEXTAPI') && GSEXTAPI==1) {
  203. include_once('api.plugin.php');
  204. }
  205. }
  206. # include core plugin for page caching
  207. include_once('caching_functions.php');
  208. # main hook for common.php
  209. exec_action('common');
  210. }
  211. if(isset($load['login']) && $load['login']){ include_once(GSADMININCPATH.'login_functions.php'); }
  212. ?>