Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

testMinimumPhpVersion.php 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 (!extension_loaded('session')) {
  27. $piwik_errorMessage .= "<p><strong>Piwik and Zend_Session require the session extension</strong></p>
  28. <p>It appears your PHP was compiled with <pre>--disable-session</pre>.
  29. To enjoy Piwik, you need PHP compiled without that configure option.</p>";
  30. }
  31. if (!function_exists('ini_set')) {
  32. $piwik_errorMessage .= "<p><strong>Piwik and Zend_Session require the <code>ini_set()</code> function</strong></p>
  33. <p>It appears your PHP has disabled this function.
  34. 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>";
  35. }
  36. if (!function_exists('json_encode')) {
  37. $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>
  38. <p>It appears your PHP has not yet installed the php5-json extension.
  39. 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>";
  40. }
  41. if (!file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php')
  42. && !file_exists(PIWIK_INCLUDE_PATH . '/../../autoload.php')) {
  43. $composerInstall = "In the piwik directory, run in the command line the following (eg. via ssh): \n\n"
  44. . "<pre> curl -sS https://getcomposer.org/installer | php \n\n php composer.phar install\n\n</pre> ";
  45. if (DIRECTORY_SEPARATOR === '\\' /* ::isWindows() */) {
  46. $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. "
  47. . " <br>Then run this command in a terminal in the piwik directory: <br> $ php composer.phar update ";
  48. }
  49. $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".
  50. "<br/>" . $composerInstall.
  51. " This will initialize composer for Piwik and download libraries we use in vendor/* directory.".
  52. "\n\n<br/><br/>Then reload this page to access your analytics reports." .
  53. "\n\n<br/><br/>For more information check out this FAQ: <a href='http://piwik.org/faq/how-to-install/faq_18271/' target='_blank'>How do I use Piwik from the Git repository?</a>." .
  54. "\n\n<br/><br/>Note: if for some reasons you cannot install composer, instead install the latest Piwik release from ".
  55. "<a href='http://builds.piwik.org/piwik.zip'>builds.piwik.org</a>.</p>";
  56. }
  57. }
  58. define('PAGE_TITLE_WHEN_ERROR', 'Piwik &rsaquo; Error');
  59. if (!function_exists('Piwik_ExitWithMessage')) {
  60. /**
  61. * Returns true if Piwik should print the backtrace with error messages.
  62. *
  63. * To make sure the backtrace is printed, define PIWIK_PRINT_ERROR_BACKTRACE.
  64. *
  65. * @return bool
  66. */
  67. function Piwik_ShouldPrintBackTraceWithMessage()
  68. {
  69. $bool = (defined('PIWIK_PRINT_ERROR_BACKTRACE') && PIWIK_PRINT_ERROR_BACKTRACE)
  70. || !empty($GLOBALS['PIWIK_TRACKER_DEBUG']);
  71. return $bool;
  72. }
  73. /**
  74. * Displays info/warning/error message in a friendly UI and exits.
  75. *
  76. * @param string $message Main message, must be html encoded before calling
  77. * @param bool|string $optionalTrace Backtrace; will be displayed in lighter color
  78. * @param bool $optionalLinks If true, will show links to the Piwik website for help
  79. * @param bool $optionalLinkBack If true, displays a link to go back
  80. */
  81. function Piwik_ExitWithMessage($message, $optionalTrace = false, $optionalLinks = false, $optionalLinkBack = false)
  82. {
  83. if (!headers_sent()) {
  84. header('Content-Type: text/html; charset=utf-8');
  85. header('HTTP/1.1 500 Internal Server Error');
  86. }
  87. if ($optionalTrace) {
  88. $optionalTrace = '<span class="exception-backtrace">Backtrace:<br /><pre>' . $optionalTrace . '</pre></span>';
  89. }
  90. $isCli = PHP_SAPI == 'cli';
  91. if ($optionalLinks) {
  92. $optionalLinks = '<ul>
  93. <li><a target="_blank" href="http://piwik.org">Piwik.org homepage</a></li>
  94. <li><a target="_blank" href="http://piwik.org/faq/">Piwik Frequently Asked Questions</a></li>
  95. <li><a target="_blank" href="http://piwik.org/docs/">Piwik Documentation</a></li>
  96. <li><a target="_blank" href="http://forum.piwik.org/">Piwik Forums</a></li>
  97. <li><a target="_blank" href="http://demo.piwik.org">Piwik Online Demo</a></li>
  98. </ul>';
  99. }
  100. if ($optionalLinkBack) {
  101. $optionalLinkBack = '<a href="javascript:window.history.back();">Go Back</a><br/>';
  102. }
  103. $headerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutHeader.tpl');
  104. $footerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutFooter.tpl');
  105. $headerPage = str_replace('{$HTML_TITLE}', PAGE_TITLE_WHEN_ERROR, $headerPage);
  106. $content = '<p>' . $message . '</p>
  107. <p>'
  108. . $optionalLinkBack
  109. . '<a href="index.php">Go to Piwik</a><br/>
  110. <a href="index.php?module=Login">Login</a>'
  111. . '</p>'
  112. . ' ' . (Piwik_ShouldPrintBackTraceWithMessage() ? $optionalTrace : '')
  113. . ' ' . $optionalLinks;
  114. $message = str_replace(array("<br />", "<br>", "<br/>", "</p>"), "\n", $message);
  115. $message = str_replace("\t", "", $message);
  116. $message = strip_tags($message);
  117. if($isCli) {
  118. echo $message;
  119. } else {
  120. echo $headerPage . $content . $footerPage;
  121. }
  122. echo "\n";
  123. error_log(sprintf("Error in Piwik: %s", str_replace("\n", " ", $message)));
  124. exit(1);
  125. }
  126. }
  127. if (!empty($piwik_errorMessage)) {
  128. Piwik_ExitWithMessage($piwik_errorMessage, false, true);
  129. }