PRADO PHP Cross Reference Developer Tools

Source: /requirements/index.php - 295 lines - 7512 bytes - Summary - Text - Print

Description: PRADO Requirements Checker script

   1  <?php
   2  /**
   3   * PRADO Requirements Checker script
   4   *
   5   * @author Qiang Xue <qiang.xue@gmail.com>
   6   * @link http://www.pradosoft.com/
   7   * @copyright Copyright &copy; 2005 PradoSoft
   8   * @license http://www.pradosoft.com/license/
   9   * @version $Id: index.php 3281 2013-03-13 21:01:40Z ctrlaltca $
  10   * @package prado
  11   */
  12  
  13  /**
  14   * PRADO Requirements Checker script
  15   *
  16   * This script will check if your system meets the requirements for running PRADO.
  17   * It will check if you are running the right version of PHP, if you included
  18   * the right libraries and if your php.ini file settings are correct.
  19   *
  20   * This script is capable of displaying localized messages.
  21   * All messages are stored in messages.txt. A localized message file is named as
  22   * messsages-<language code>.txt, and it will be used when the client browser
  23   * chooses the corresponding language.
  24   * The script output uses a template named template.html.
  25   * Its localized version is stored in template-<language code>.html.
  26   */
  27  
  28  /**
  29   * @var array List of requirements (required or not, check item, hint)
  30   */
  31  $requirements = array(
  32      array(
  33          true,
  34          version_compare(PHP_VERSION,"5.3.3",">="),
  35          'PHP version check','PHP 5.3.3 or higher required'),
  36      array(
  37          true,
  38          isset($_SERVER["HTTP_ACCEPT"]),
  39          '$_SERVER["HTTP_ACCEPT"] check',
  40          'HTTP_ACCEPT required'),
  41      array(
  42          true,
  43          isset($_SERVER["SCRIPT_FILENAME"]) && realpath($_SERVER["SCRIPT_FILENAME"])===realpath(__FILE__),
  44          '$_SERVER["SCRIPT_FILENAME"] check',
  45          'SCRIPT_FILENAME required'),
  46      array(
  47          true,
  48          isset($_SERVER["REQUEST_URI"]) || isset($_SERVER["QUERY_STRING"]),
  49          '$_SERVER["REQUEST_URI"] check',
  50          'REQUEST_URI required'),
  51      array(
  52          true,
  53          isset($_SERVER["PATH_INFO"]) || strpos($_SERVER["PHP_SELF"],$_SERVER["SCRIPT_NAME"])===0,
  54          '$_SERVER["PATH_INFO"] check',
  55          'PATH_INFO required'),
  56      array(
  57          true,
  58          class_exists('Reflection',false),
  59          'Reflection extension check',
  60          'Reflection extension required'),
  61      array(
  62          true,
  63          class_exists("DOMDocument",false),
  64          'DOM extension check',
  65          'DOM extension required'),
  66      array(
  67          true,
  68          extension_loaded("SPL"),
  69          'SPL extension check',
  70          'SPL extension required'),
  71      array(
  72          true,
  73          extension_loaded("CType"),
  74          'CType extension check',
  75          'CType extension required'),
  76      array(
  77          true,
  78          extension_loaded("pcre"),
  79          'PCRE extension check',
  80          'PCRE extension required'),
  81      array(
  82          true,
  83          extension_loaded("json"),
  84          'JSON extension check',
  85          'JSON extension required'),
  86      array(
  87          false,
  88          class_exists("PDO",false),
  89          'PDO extension check',
  90          'PDO extension optional'),
  91      array(
  92          false,
  93          function_exists("iconv"),
  94          'ICONV extension check',
  95          'ICONV extension optional'),
  96      array(
  97          false,
  98          extension_loaded("zlib"),
  99          'Zlib extension check',
 100          'Zlib extension optional'),
 101      array(
 102          false,
 103          extension_loaded("sqlite"),
 104          'SQLite extension check',
 105          'SQLite extension optional deprecated'),
 106      array(
 107          false,
 108          extension_loaded("memcache"),
 109          'Memcache extension check',
 110          'Memcache extension optional'),
 111      array(
 112          false,
 113          extension_loaded("apc"),
 114          'APC extension check',
 115          'APC extension optional'),
 116      array(
 117          false,
 118          function_exists('eaccelerator_get'),
 119          'eAccelerator extension check',
 120          'eAccelerator extension optional'),
 121      array(
 122          false,
 123          function_exists('xcache_isset'),
 124          'XCache extension check',
 125          'XCache extension optional'),
 126      array(
 127          false,
 128          extension_loaded("mcrypt"),
 129          'Mcrypt extension check',
 130          'Mcrypt extension optional'),
 131      array(
 132          false,
 133          extension_loaded("mbstring"),
 134          'Mbstring extension check',
 135          'Mbstring extension optional'),
 136      array(
 137          false,
 138          extension_loaded("hash"),
 139          'Hash extension check',
 140          'Hash extension optional'),
 141      array(
 142          false,
 143          extension_loaded("xsl"),
 144          'XSL extension check',
 145          'XSL extension optional'),
 146      array(
 147          false,
 148          extension_loaded("soap"),
 149          'SOAP extension check',
 150          'SOAP extension optional'),
 151  );
 152  
 153  $results = "<table class=\"result\">\n";
 154  $conclusion = 0;
 155  foreach($requirements as $requirement)
 156  {
 157      list($required,$expression,$aspect,$hint)=$requirement;
 158      //eval('$ret='.$expression.';');
 159      $ret=$expression;
 160      if($required)
 161      {
 162          if($ret)
 163              $ret='passed';
 164          else
 165          {
 166              $conclusion=1;
 167              $ret='error';
 168          }
 169      }
 170      else
 171      {
 172          if($ret)
 173              $ret='passed';
 174          else
 175          {
 176              if($conclusion!==1)
 177                  $conclusion=2;
 178              $ret='warning';
 179          }
 180      }
 181      $results.="<tr class=\"$ret\"><td class=\"$ret\">".lmessage($aspect)."</td><td class=\"$ret\">".lmessage($hint)."</td></tr>\n";
 182  }
 183  $results .= '</table>';
 184  if($conclusion===0)
 185      $conclusion=lmessage('all passed');
 186  else if($conclusion===1)
 187      $conclusion=lmessage('failed');
 188  else
 189      $conclusion=lmessage('passed with warnings');
 190  
 191  $tokens = array(
 192      '%%Conclusion%%' => $conclusion,
 193      '%%Details%%' => $results,
 194      '%%Version%%' => $_SERVER['SERVER_SOFTWARE'].' <a href="http://www.pradosoft.com/">PRADO</a>/'.getPradoVersion(),
 195      '%%Time%%' => @strftime('%Y-%m-%d %H:%m',time()),
 196  );
 197  
 198  $lang=getPreferredLanguage();
 199  $templateFile=dirname(__FILE__)."/template-$lang.html";
 200  if(!is_file($templateFile))
 201      $templateFile=dirname(__FILE__).'/template.html';
 202  if(($content=@file_get_contents($templateFile))===false)
 203      die("Unable to open template file '$templateFile'.");
 204  
 205  header('Content-Type: text/html; charset=UTF-8');
 206  echo strtr($content,$tokens);
 207  
 208  /**
 209   * Returns a localized message according to user preferred language.
 210   * @param string message to be translated
 211   * @return string translated message
 212   */
 213  function lmessage($token)
 214  {
 215      static $messages=null;
 216      if($messages===null)
 217      {
 218          $lang = getPreferredLanguage();
 219          $msgFile=dirname(__FILE__)."/messages-$lang.txt";
 220          if(!is_file($msgFile))
 221              $msgFile=dirname(__FILE__).'/messages.txt';
 222          if(($entries=@file($msgFile))!==false)
 223          {
 224              foreach($entries as $entry)
 225              {
 226                  @list($code,$message)=explode('=',$entry,2);
 227                  $messages[trim($code)]=trim($message);
 228              }
 229          }
 230      }
 231      return isset($messages[$token])?$messages[$token]:$token;
 232  }
 233  
 234  /**
 235   * Returns a list of user preferred languages.
 236   * The languages are returned as an array. Each array element
 237   * represents a single language preference. The languages are ordered
 238   * according to user preferences. The first language is the most preferred.
 239   * @return array list of user preferred languages.
 240   */
 241  function getUserLanguages()
 242  {
 243      static $languages=null;
 244      if($languages===null)
 245      {
 246          $languages=array();
 247          foreach(explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']) as $language)
 248          {
 249              $array=explode(';q=',trim($language));
 250              $languages[trim($array[0])]=isset($array[1])?(float)$array[1]:1.0;
 251          }
 252          arsort($languages);
 253          $languages=array_keys($languages);
 254          if(empty($languages))
 255              $languages[0]='en';
 256      }
 257      return $languages;
 258  }
 259  
 260  /**
 261   * Returns the most preferred language by the client user.
 262   * @return string the most preferred language by the client user, defaults to English.
 263   */
 264  function getPreferredLanguage()
 265  {
 266      static $language=null;
 267      if($language===null)
 268      {
 269          $langs=getUserLanguages();
 270          $lang=explode('-',$langs[0]);
 271          if(empty($lang[0]) || !function_exists('ctype_alpha') || !ctype_alpha($lang[0]))
 272              $language='en';
 273          else
 274              $language=$lang[0];
 275      }
 276      return $language;
 277  }
 278  
 279  /**
 280   * @return string Prado version
 281   */
 282  function getPradoVersion()
 283  {
 284      $coreFile=dirname(__FILE__).'/../framework/PradoBase.php';
 285      if(is_file($coreFile))
 286      {
 287          $contents=file_get_contents($coreFile);
 288          $matches=array();
 289          if(preg_match('/public static function getVersion.*?return \'(.*?)\'/ms',$contents,$matches)>0)
 290              return $matches[1];
 291      }
 292      return '';
 293  }
 294  
 295  ?>

title

Description

title

Description

title

Description

title

title

Body