PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/index.php

https://bitbucket.org/kxz/shimmie2
PHP | 180 lines | 48 code | 11 blank | 121 comment | 6 complexity | e325c01b62f40e9a038f061b3d2eddb5 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * \mainpage Shimmie2 / SCore Documentation
  4. *
  5. * SCore is a framework designed for writing flexible, extendable applications.
  6. * Whereas most PHP apps are built monolithicly, score's event-based nature
  7. * allows parts to be mixed and matched. For instance, the most famous
  8. * collection of score extensions is the Shimmie image board, which includes
  9. * user management, a wiki, a private messaging system, etc. But one could
  10. * easily remove the image board bits and simply have a wiki with users and
  11. * PMs; or one could replace it with a blog module; or one could have a blog
  12. * which links to images on an image board, with no wiki or messaging, and so
  13. * on and so on...
  14. *
  15. * To learn about the innards of SCore, start with the \ref overview.
  16. *
  17. *
  18. * \page overview High Level Overview
  19. *
  20. * Dijkstra will kill me for personifying my architecture, but I can't think
  21. * of a better way without going into all the little details.
  22. *
  23. * There are a bunch of Extension subclasses, they talk to eachother by sending
  24. * and recieving Event subclasses. The topic of conversation is decided by the
  25. * initial PageRequestEvent, and each extension puts its notes into the shared
  26. * Page data store. Once the conversation is over, the Page is passed to the
  27. * current theme's Layout class which will tidy up the data and present it to
  28. * the user.
  29. *
  30. * To learn more about the architecture:
  31. *
  32. * \li \ref eande
  33. * \li \ref themes
  34. *
  35. * To learn more about practical development:
  36. *
  37. * \li \ref scglobals
  38. * \li \ref unittests
  39. * \li \ref hello
  40. *
  41. * \page scglobals SCore Globals
  42. *
  43. * There are four global variables which are pretty essential to most extensions:
  44. *
  45. * \li $config -- some variety of Config subclass
  46. * \li $database -- a Database object used to get raw SQL access
  47. * \li $page -- a Page to holds all the loose bits of extension output
  48. * \li $user -- the currently logged in User
  49. *
  50. * Each of these can be imported at the start of a function with eg "global $page, $user;"
  51. */
  52. // set up and purify the environment
  53. define("DEBUG", false);
  54. define("COVERAGE", false);
  55. define("CONTEXT", false);
  56. define("CACHE_MEMCACHE", false);
  57. define("CACHE_DIR", false);
  58. define("VERSION", '2.3.5');
  59. define("SCORE_VERSION", 's2hack/'.VERSION);
  60. define("COOKIE_PREFIX", 'shm');
  61. if(empty($database_dsn) && !file_exists("config.php")) {
  62. header("Location: install.php");
  63. exit;
  64. }
  65. require_once "config.php";
  66. // DokuWiki authentication includes
  67. require_once(DOKU_INC.'inc/init.php');
  68. require_once "core/util.inc.php";
  69. require_once "lib/context.php";
  70. if(CONTEXT) {
  71. ctx_set_log(CONTEXT);
  72. }
  73. ctx_log_start($_SERVER["REQUEST_URI"], true, true);
  74. if(COVERAGE) {
  75. _start_coverage();
  76. register_shutdown_function("_end_coverage");
  77. }
  78. _version_check();
  79. _sanitise_environment();
  80. _start_cache();
  81. try {
  82. // load base files
  83. ctx_log_start("Initialisation");
  84. ctx_log_start("Opening files");
  85. $files = array_merge(glob("core/*.php"), glob("ext/*/main.php"));
  86. foreach($files as $filename) {
  87. require_once $filename;
  88. }
  89. ctx_log_endok();
  90. ctx_log_start("Connecting to DB");
  91. // connect to the database
  92. $database = new Database();
  93. $database->db->fnExecute = '_count_execs';
  94. $config = new DatabaseConfig($database);
  95. ctx_log_endok();
  96. ctx_log_start("Loading themelets");
  97. // load the theme parts
  98. $_theme = $config->get_string("theme", "default");
  99. if(!file_exists("themes/$_theme")) $_theme = "default";
  100. if(file_exists("themes/$_theme/custompage.class.php")) require_once "themes/$_theme/custompage.class.php";
  101. require_once "themes/$_theme/layout.class.php";
  102. require_once "themes/$_theme/themelet.class.php";
  103. $themelets = glob("ext/*/theme.php");
  104. foreach($themelets as $filename) {
  105. require_once $filename;
  106. }
  107. $custom_themelets = glob("themes/$_theme/*.theme.php");
  108. if($custom_themelets) {
  109. $m = array();
  110. foreach($custom_themelets as $filename) {
  111. if(preg_match("/themes\/$_theme\/(.*)\.theme\.php/",$filename,$m)
  112. && in_array("ext/{$m[1]}/theme.php", $themelets)) {
  113. require_once $filename;
  114. }
  115. }
  116. }
  117. ctx_log_endok();
  118. // initialise the extensions
  119. foreach(get_declared_classes() as $class) {
  120. if(is_subclass_of($class, "SimpleExtension")) {
  121. $c = new $class();
  122. $c->i_am($c);
  123. add_event_listener($c, $c->get_priority());
  124. }
  125. }
  126. ctx_log_endok("Initialisation");
  127. ctx_log_start("Page generation");
  128. // start the page generation waterfall
  129. $page = class_exists("CustomPage") ? new CustomPage() : new Page();
  130. $user = _get_user($config, $database);
  131. send_event(new InitExtEvent());
  132. send_event(_get_page_request());
  133. $page->display();
  134. ctx_log_endok("Page generation");
  135. // for databases which support transactions
  136. // XXX: removed since we never start a transaction, and postgres
  137. // fills the disk with warnings about that
  138. //if($database->engine->name != "sqlite") {
  139. // $database->db->CommitTrans(true);
  140. //}
  141. _end_cache();
  142. ctx_log_endok();
  143. }
  144. catch(Exception $e) {
  145. $version = VERSION;
  146. $message = $e->getMessage();
  147. header("HTTP/1.0 500 Internal Error");
  148. print <<<EOD
  149. <html>
  150. <head>
  151. <title>Internal error - SCore-$version</title>
  152. </head>
  153. <body>
  154. <h1>Internal Error</h1>
  155. <p>$message
  156. </body>
  157. </html>
  158. EOD;
  159. ctx_log_ender();
  160. }
  161. ?>