PageRenderTime 63ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/core/testMinimumPhpVersion.php

https://github.com/CodeYellowBV/piwik
PHP | 139 lines | 92 code | 12 blank | 35 comment | 20 complexity | d9543891480a65a7377ca0cac4e99572 MD5 | raw file
Possible License(s): LGPL-3.0, JSON, MIT, GPL-3.0, LGPL-2.1, GPL-2.0, AGPL-1.0, BSD-2-Clause, BSD-3-Clause
  1. <?php
  2. /**
  3. * Piwik - free/libre analytics platform
  4. *
  5. * @link http://piwik.org
  6. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  7. *
  8. */
  9. /**
  10. * This file is executed before anything else.
  11. * It checks the minimum PHP version required to run Piwik.
  12. * This file must be compatible PHP4.
  13. */
  14. $piwik_errorMessage = '';
  15. // Minimum requirement: stream_resolve_include_path in 5.3.2, namespaces in 5.3
  16. $piwik_minimumPHPVersion = '5.3.2';
  17. $piwik_currentPHPVersion = PHP_VERSION;
  18. $minimumPhpInvalid = version_compare($piwik_minimumPHPVersion, $piwik_currentPHPVersion) > 0;
  19. if ($minimumPhpInvalid) {
  20. $piwik_errorMessage .= "<p><strong>To run Piwik you need at least PHP version $piwik_minimumPHPVersion</strong></p>
  21. <p>Unfortunately it seems your webserver is using PHP version $piwik_currentPHPVersion. </p>
  22. <p>Please try to update your PHP version, Piwik is really worth it! Nowadays most web hosts
  23. support PHP $piwik_minimumPHPVersion.</p>
  24. <p>Also see the FAQ: <a href='http://piwik.org/faq/how-to-install/#faq_77'>My Web host supports PHP4 by default. How can I enable PHP5?</a></p>";
  25. } else {
  26. if (!class_exists('ArrayObject')) {
  27. $piwik_errorMessage .= "<p><strong>Piwik and Zend Framework require the SPL extension</strong></p>
  28. <p>It appears your PHP was compiled with <pre>--disable-spl</pre>.
  29. To enjoy Piwik, you need PHP compiled without that configure option.</p>";
  30. }
  31. if (!extension_loaded('session')) {
  32. $piwik_errorMessage .= "<p><strong>Piwik and Zend_Session require the session extension</strong></p>
  33. <p>It appears your PHP was compiled with <pre>--disable-session</pre>.
  34. To enjoy Piwik, you need PHP compiled without that configure option.</p>";
  35. }
  36. if (!function_exists('ini_set')) {
  37. $piwik_errorMessage .= "<p><strong>Piwik and Zend_Session require the <code>ini_set()</code> function</strong></p>
  38. <p>It appears your PHP has disabled this function.
  39. To enjoy Piwik, you need remove <pre>ini_set</pre> from your <pre>disable_functions</pre> directive in php.ini, and restart your webserver.</p>";
  40. }
  41. if (!function_exists('json_encode')) {
  42. $piwik_errorMessage .= "<p><strong>Piwik requires the php5-json extension which provides the functions <code>json_encode()</code> and <code>json_decode()</code></strong></p>
  43. <p>It appears your PHP has not yet installed the php5-json extension.
  44. To use Piwik, please ask your web host to install php5-json or install it yourself, for example on debian system: <code>sudo apt-get install php5-json</code>. <br/>Then restart your webserver and refresh this page.</p>";
  45. }
  46. if (!file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php') && !file_exists(PIWIK_INCLUDE_PATH . '/../../autoload.php')) {
  47. $composerInstall = "In the piwik directory, run in the command line the following (eg. via ssh): \n\n"
  48. . "<pre> curl -sS https://getcomposer.org/installer | php \n\n php composer.phar install\n\n</pre> ";
  49. if (DIRECTORY_SEPARATOR === '\\' /* ::isWindows() */) {
  50. $composerInstall = "Download and run <a href=\"https://getcomposer.org/Composer-Setup.exe\"><b>Composer-Setup.exe</b></a>, it will install the latest Composer version and set up your PATH so that you can just call composer from any directory in your command line. "
  51. . " <br>Then run this command in a terminal in the piwik directory: <br> $ php composer.phar update ";
  52. }
  53. $piwik_errorMessage .= "<p>It appears the <a href='https://getcomposer.org/' target='_blank'>composer</a> tool is not yet installed. You can install Composer in a few easy steps:\n\n".
  54. "<br/>" . $composerInstall.
  55. " This will initialize composer for Piwik and download libraries we use in vendor/* directory.".
  56. "\n\n<br/><br/>Then reload this page to access your analytics reports." .
  57. "\n\n<br/><br/>Note: if for some reasons you cannot install composer, instead install the latest Piwik release from ".
  58. "<a href='http://builds.piwik.org/piwik-latest.zip'>builds.piwik.org</a>.</p>";
  59. }
  60. }
  61. if (!function_exists('Piwik_ExitWithMessage')) {
  62. /**
  63. * Returns true if Piwik should print the backtrace with error messages.
  64. *
  65. * To make sure the backtrace is printed, define PIWIK_PRINT_ERROR_BACKTRACE.
  66. *
  67. * @return bool
  68. */
  69. function Piwik_ShouldPrintBackTraceWithMessage()
  70. {
  71. $bool = (defined('PIWIK_PRINT_ERROR_BACKTRACE') && PIWIK_PRINT_ERROR_BACKTRACE)
  72. || !empty($GLOBALS['PIWIK_TRACKER_DEBUG']);
  73. return $bool;
  74. }
  75. /**
  76. * Displays info/warning/error message in a friendly UI and exits.
  77. *
  78. * @param string $message Main message, must be html encoded before calling
  79. * @param bool|string $optionalTrace Backtrace; will be displayed in lighter color
  80. * @param bool $optionalLinks If true, will show links to the Piwik website for help
  81. * @param bool $optionalLinkBack If true, displays a link to go back
  82. */
  83. function Piwik_ExitWithMessage($message, $optionalTrace = false, $optionalLinks = false, $optionalLinkBack = false)
  84. {
  85. @header('Content-Type: text/html; charset=utf-8');
  86. if ($optionalTrace) {
  87. $optionalTrace = '<span class="exception-backtrace">Backtrace:<br /><pre>' . $optionalTrace . '</pre></span>';
  88. }
  89. $isCli = PHP_SAPI == 'cli';
  90. if ($optionalLinks) {
  91. $optionalLinks = '<ul>
  92. <li><a target="_blank" href="http://piwik.org">Piwik.org homepage</a></li>
  93. <li><a target="_blank" href="http://piwik.org/faq/">Piwik Frequently Asked Questions</a></li>
  94. <li><a target="_blank" href="http://piwik.org/docs/">Piwik Documentation</a></li>
  95. <li><a target="_blank" href="http://forum.piwik.org/">Piwik Forums</a></li>
  96. <li><a target="_blank" href="http://demo.piwik.org">Piwik Online Demo</a></li>
  97. </ul>';
  98. }
  99. if ($optionalLinkBack) {
  100. $optionalLinkBack = '<a href="javascript:window.history.back();">Go Back</a><br/>';
  101. }
  102. $headerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutHeader.tpl');
  103. $footerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutFooter.tpl');
  104. $headerPage = str_replace('{$HTML_TITLE}', 'Piwik &rsaquo; Error', $headerPage);
  105. $content = '<p>' . $message . '</p>
  106. <p>'
  107. . $optionalLinkBack
  108. . '<a href="index.php">Go to Piwik</a><br/>
  109. <a href="index.php?module=Login">Login</a>'
  110. . '</p>'
  111. . ' ' . (Piwik_ShouldPrintBackTraceWithMessage() ? $optionalTrace : '')
  112. . ' ' . $optionalLinks;
  113. if($isCli) {
  114. $message = str_replace(array("<br />", "<br>", "<br/>", "</p>"), "\n", $message);
  115. $message = str_replace("\t", "", $message);
  116. echo strip_tags($message);
  117. } else {
  118. echo $headerPage . $content . $footerPage;
  119. }
  120. echo "\n";
  121. exit(1);
  122. }
  123. }
  124. if (!empty($piwik_errorMessage)) {
  125. Piwik_ExitWithMessage($piwik_errorMessage, false, true);
  126. }