home.html.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. use lithium\core\Libraries;
  9. use lithium\core\Environment;
  10. use lithium\data\Connections;
  11. $this->title('Home');
  12. $self = $this;
  13. $notify = function($status, $message, $solution = null) {
  14. $html = "<div class=\"test-result test-result-{$status}\">{$message}</div>";
  15. $html .= "<div class=\"test-result solution\">{$solution}</div>";
  16. return $html;
  17. };
  18. $support = function($classes) {
  19. $result = '<ul class="indicated">';
  20. foreach ($classes as $class => $enabled) {
  21. $name = substr($class, strrpos($class, '\\') + 1);
  22. $url = 'http://lithify.me/docs/' . str_replace('\\', '/', $class);
  23. $class = $enabled ? 'enabled' : 'disabled';
  24. $title = $enabled ? "Adapter `{$name}` is enabled." : "Adapter `{$name}` is disabled.";
  25. $result .= "<li><a href=\"{$url}\" title=\"{$title}\" class=\"{$class}\">{$name}</a></li>";
  26. }
  27. $result .= '</ul>';
  28. return $result;
  29. };
  30. $compiled = function($flag) {
  31. ob_start();
  32. phpinfo(INFO_GENERAL);
  33. return strpos(ob_get_clean(), $flag) !== false;
  34. };
  35. $checks = array(
  36. 'resourcesWritable' => function() use ($notify) {
  37. if (is_writable($path = Libraries::get(true, 'resources'))) {
  38. return $notify('success', 'Resources directory is writable');
  39. }
  40. $path = str_replace(dirname(LITHIUM_APP_PATH) . '/', null, $path);
  41. $solution = null;
  42. if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
  43. $solution = 'To fix this, run the following from the command line: ';
  44. $solution .= "<code>$ chmod -R 0777 {$path}</code>.";
  45. } else {
  46. $path = realpath($path);
  47. $solution = 'To fix this, give <code>modify</code> rights to the user ';
  48. $solution .= "<code>Everyone</code> on directory <code>{$path}</code>.";
  49. }
  50. return $notify(
  51. 'fail',
  52. 'Your resource path is not writeable',
  53. $solution
  54. );
  55. },
  56. 'magicQuotes' => function() use ($notify) {
  57. if (!get_magic_quotes_gpc()) {
  58. return;
  59. }
  60. return $notify(
  61. 'fail',
  62. 'Magic quotes are enabled in your PHP configuration',
  63. 'Please set <code>magic_quotes_gpc = Off</code> in your <code>php.ini</code> settings.'
  64. );
  65. },
  66. 'registerGlobals' => function() use ($notify) {
  67. if (!ini_get('register_globals')) {
  68. return;
  69. }
  70. return $notify(
  71. 'fail',
  72. 'Register globals is enabled in your PHP configuration',
  73. 'Please set <code>register_globals = Off</code> in your <code>php.ini</code> settings.'
  74. );
  75. },
  76. 'curlwrappers' => function() use ($notify, $compiled) {
  77. if (!$compiled('with-curlwrappers')) {
  78. return;
  79. }
  80. return $notify(
  81. 'fail',
  82. 'Curlwrappers are enabled, some things might not work as expected.',
  83. "This is an expiremental and usually broken feature of PHP.
  84. Please recompile your PHP binary without using the <code>--with-curlwrappers</code>
  85. flag or use a precompiled binary that was compiled without the flag."
  86. );
  87. },
  88. 'shortOpenTag' => function() use ($notify, $compiled) {
  89. if (!ini_get('short_open_tag')) {
  90. return;
  91. }
  92. return $notify(
  93. 'notice',
  94. 'Short open tags are enabled, you may want to disable them.',
  95. "It is recommended to not rely on this option being enabled.
  96. To increase the portability of your code disable this option by setting
  97. <code>short_open_tag = Off</code> in your <code>php.ini</code>."
  98. );
  99. },
  100. 'dbSupport' => function() use ($notify, $support) {
  101. $paths = array('data.source', 'adapter.data.source.database', 'adapter.data.source.http');
  102. $list = array();
  103. foreach ($paths as $path) {
  104. $list = array_merge($list, Libraries::locate($path, null, array('recursive' => false)));
  105. }
  106. $list = array_filter($list, function($class) { return method_exists($class, 'enabled'); });
  107. $map = array_combine($list, array_map(function($c) { return $c::enabled(); }, $list));
  108. return $notify('notice', 'Database support', $support($map));
  109. },
  110. 'cacheSupport' => function() use ($notify, $support) {
  111. $list = Libraries::locate('adapter.storage.cache', null, array('recursive' => false));
  112. $list = array_filter($list, function($class) { return method_exists($class, 'enabled'); });
  113. $map = array_combine($list, array_map(function($c) { return $c::enabled(); }, $list));
  114. return $notify('notice', 'Cache support', $support($map));
  115. },
  116. 'database' => function() use ($notify) {
  117. if ($config = Connections::config()) {
  118. return $notify('success', 'Database connection(s) configured');
  119. }
  120. return $notify(
  121. 'notice',
  122. 'No database connection defined',
  123. "To create a database connection:
  124. <ol>
  125. <li>Edit the file <code>config/bootstrap.php</code>.</li>
  126. <li>
  127. Uncomment the line having
  128. <code>require __DIR__ . '/bootstrap/connections.php';</code>.
  129. </li>
  130. <li>Edit the file <code>config/bootstrap/connections.php</code>.</li>
  131. </ol>"
  132. );
  133. },
  134. 'change' => function() use ($notify, $self) {
  135. $template = $self->html->link('template', 'http://lithify.me/docs/lithium/template');
  136. return $notify(
  137. 'notice',
  138. "You're using the application's default home page",
  139. "To change this {$template}, edit the file
  140. <code>views/pages/home.html.php</code>.
  141. To change the layout,
  142. (that is what's wrapping content)
  143. edit the file <code>views/layouts/default.html.php</code>."
  144. );
  145. },
  146. 'routing' => function() use ($notify, $self) {
  147. $routing = $self->html->link('routing', 'http://lithify.me/docs/lithium/net/http/Router');
  148. return $notify(
  149. 'notice',
  150. 'Use custom routing',
  151. "Routes allow you to map custom URLs to your application code. To change the
  152. {$routing}, edit the file <code>config/routes.php</code>."
  153. );
  154. },
  155. 'tests' => function() use ($notify, $self) {
  156. if (Environment::is('production')) {
  157. $docsLink = $self->html->link(
  158. 'the documentation',
  159. 'http://lithify.me/docs/lithium/core/Environment::is()'
  160. );
  161. return $notify(
  162. 'fail',
  163. "Can't run tests",
  164. "<p>Lithium's default environment detection rules have determined that you are
  165. running in production mode. Therefore, you will not be able to run tests from the
  166. web interface. You can do any of the following to remedy this:</p>
  167. <ul>
  168. <li>Run this application locally</li>
  169. <li>Run tests from the console, using the <code>li3 test</code> command</li>
  170. <li>
  171. Implementing custom environment detection rules;
  172. see {$docsLink} for examples
  173. </li>
  174. </ul>"
  175. );
  176. }
  177. $tests = $self->html->link('run all tests', array(
  178. 'controller' => 'lithium\test\Controller',
  179. 'args' => 'all'
  180. ));
  181. $dashboard = $self->html->link('test dashboard', array(
  182. 'controller' => 'lithium\test\Controller'
  183. ));
  184. $ticket = $self->html->link(
  185. 'file a ticket', 'https://github.com/UnionOfRAD/lithium/issues'
  186. );
  187. return $notify(
  188. 'notice',
  189. 'Run the tests',
  190. "Check the builtin {$dashboard} or {$tests} now to ensure Lithium
  191. is working as expected. Do not hesitate to {$ticket} in case a test fails."
  192. );
  193. }
  194. );
  195. ?>
  196. <?php foreach ($checks as $check): ?>
  197. <?php echo $check(); ?>
  198. <?php endforeach; ?>
  199. <ul class="additional-resources">
  200. <li>
  201. <div class="test-result test-result-notice">Getting started</div>
  202. <div class="test-result solution">
  203. <?php echo $this->html->link(
  204. 'Quickstart', 'http://lithify.me/docs/manual/quickstart'
  205. ); ?> is a guide for PHP users who are looking to get a good idea of what Lithium can
  206. do. The guide is part of the official Lithium manual, <?php echo $this->html->link(
  207. 'The Definitive Guide', 'http://lithify.me/docs/manual'
  208. ); ?>.
  209. </div>
  210. </li>
  211. <li>
  212. <div class="test-result test-result-notice">Learn more</div>
  213. <div class="test-result solution">
  214. The
  215. <?php echo $this->html->link('API documentation', 'http://lithify.me/docs/lithium'); ?>
  216. has all the implementation details you've been looking for.
  217. </div>
  218. </li>
  219. <li>
  220. Chat with other Lithium users and the team developing Lithium.
  221. For <em>general support</em> hop on the
  222. <?php echo $this->html->link('#li3 channel', 'irc://irc.freenode.net/#li3'); ?>
  223. or read the
  224. <?php echo $this->html->link('logs', 'http://lithify.me/bot/logs/li3'); ?>.
  225. For <em>core discussions</em> join us in the
  226. <?php echo $this->html->link('#li3-core channel', 'irc://irc.freenode.net/#li3-core'); ?>
  227. or read the
  228. <?php echo $this->html->link('logs', 'http://lithify.me/bot/logs/li3-core'); ?>.
  229. </li>
  230. <li>
  231. Browse the Lithium
  232. <?php echo $this->html->link('Repository', 'https://github.com/UnionOfRAD/lithium'); ?>
  233. or read the
  234. <?php echo $this->html->link('Wiki', 'https://github.com/UnionOfRAD/lithium/wiki'); ?>.
  235. </li>
  236. </ul>