PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/index.php

https://github.com/zshall/shimmie2
PHP | 153 lines | 34 code | 7 blank | 112 comment | 4 complexity | 3598383758695ada37d533cb81f38047 MD5 | raw file
Possible License(s): 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", true);
  54. define("COVERAGE", true);
  55. define("CACHE_MEMCACHE", false);
  56. define("CACHE_DIR", false);
  57. define("VERSION", 'trunk-prefs');
  58. define("SCORE_VERSION", 's2hack/'.VERSION);
  59. define("COOKIE_PREFIX", 'shm');
  60. if(!file_exists("config.php")) {
  61. header("Location: install.php");
  62. exit;
  63. }
  64. require_once "config.php";
  65. require_once "core/util.inc.php";
  66. if(COVERAGE) {_start_coverage();}
  67. _version_check();
  68. _sanitise_environment();
  69. _start_cache();
  70. try {
  71. // load base files
  72. $files = array_merge(glob("core/*.php"), glob("ext/*/main.php"));
  73. foreach($files as $filename) {
  74. require_once $filename;
  75. }
  76. // connect to the database
  77. $database = new Database();
  78. $database->db->fnExecute = '_count_execs';
  79. $config = new DatabaseConfig($database);
  80. $user = _get_user($config, $database);
  81. $userprefs = new DatabasePrefs($database, $user->id);
  82. // load the theme parts
  83. $_theme = $config->get_string("theme", "default");
  84. if(!file_exists("themes/$_theme")) $_theme = "default";
  85. if(file_exists("themes/$_theme/custompage.class.php")) require_once "themes/$_theme/custompage.class.php";
  86. require_once "themes/$_theme/layout.class.php";
  87. require_once "themes/$_theme/themelet.class.php";
  88. $themelets = glob("ext/*/theme.php");
  89. foreach($themelets as $filename) {
  90. require_once $filename;
  91. }
  92. $custom_themelets = glob("themes/$_theme/*.theme.php");
  93. if($custom_themelets) {
  94. $m = array();
  95. foreach($custom_themelets as $filename) {
  96. if(preg_match("/themes\/$_theme\/(.*)\.theme\.php/",$filename,$m)
  97. && in_array("ext/{$m[1]}/theme.php", $themelets)) {
  98. require_once $filename;
  99. }
  100. }
  101. }
  102. // initialise the extensions
  103. foreach(get_declared_classes() as $class) {
  104. if(is_subclass_of($class, "SimpleExtension")) {
  105. $c = new $class();
  106. $c->i_am($c);
  107. add_event_listener($c);
  108. }
  109. }
  110. // start the page generation waterfall
  111. $page = class_exists("CustomPage") ? new CustomPage() : new Page();
  112. send_event(new InitExtEvent());
  113. send_event(_get_page_request());
  114. $page->display();
  115. // for databases which support transactions
  116. if($database->engine->name != "sqlite") {
  117. $database->db->CommitTrans(true);
  118. }
  119. _end_cache();
  120. }
  121. catch(Exception $e) {
  122. $version = VERSION;
  123. $message = $e->getMessage();
  124. header("HTTP/1.0 500 Internal Error");
  125. print <<<EOD
  126. <html>
  127. <head>
  128. <title>Internal error - SCore-$version</title>
  129. </head>
  130. <body>
  131. <h1>Internal Error</h1>
  132. <p>$message
  133. </body>
  134. </html>
  135. EOD;
  136. }
  137. if(COVERAGE) {_end_coverage();}
  138. ?>