index.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. /**
  3. * Yii Requirement Checker script
  4. *
  5. * This script will check if your system meets the requirements for running
  6. * Yii-powered Web applications.
  7. *
  8. * @author Qiang Xue <qiang.xue@gmail.com>
  9. * @link http://www.yiiframework.com/
  10. * @copyright Copyright &copy; 2008-2011 Yii Software LLC
  11. * @license http://www.yiiframework.com/license/
  12. * @package system
  13. * @since 1.0
  14. */
  15. /**
  16. * @var array List of requirements (name, required or not, result, used by, memo)
  17. */
  18. $requirements=array(
  19. array(
  20. t('yii','PHP version'),
  21. true,
  22. version_compare(PHP_VERSION,"5.1.0",">="),
  23. '<a href="http://www.yiiframework.com">Yii Framework</a>',
  24. t('yii','PHP 5.1.0 or higher is required.')),
  25. array(
  26. t('yii','$_SERVER variable'),
  27. true,
  28. '' === $message=checkServerVar(),
  29. '<a href="http://www.yiiframework.com">Yii Framework</a>',
  30. $message),
  31. array(
  32. t('yii','Reflection extension'),
  33. true,
  34. class_exists('Reflection',false),
  35. '<a href="http://www.yiiframework.com">Yii Framework</a>',
  36. ''),
  37. array(
  38. t('yii','PCRE extension'),
  39. true,
  40. extension_loaded("pcre"),
  41. '<a href="http://www.yiiframework.com">Yii Framework</a>',
  42. ''),
  43. array(
  44. t('yii','SPL extension'),
  45. true,
  46. extension_loaded("SPL"),
  47. '<a href="http://www.yiiframework.com">Yii Framework</a>',
  48. ''),
  49. array(
  50. t('yii','DOM extension'),
  51. false,
  52. class_exists("DOMDocument",false),
  53. '<a href="http://www.yiiframework.com/doc/api/CHtmlPurifier">CHtmlPurifier</a>, <a href="http://www.yiiframework.com/doc/api/CWsdlGenerator">CWsdlGenerator</a>',
  54. ''),
  55. array(
  56. t('yii','PDO extension'),
  57. false,
  58. extension_loaded('pdo'),
  59. t('yii','All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
  60. ''),
  61. array(
  62. t('yii','PDO SQLite extension'),
  63. false,
  64. extension_loaded('pdo_sqlite'),
  65. t('yii','All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
  66. t('yii','This is required if you are using SQLite database.')),
  67. array(
  68. t('yii','PDO MySQL extension'),
  69. false,
  70. extension_loaded('pdo_mysql'),
  71. t('yii','All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
  72. t('yii','This is required if you are using MySQL database.')),
  73. array(
  74. t('yii','PDO PostgreSQL extension'),
  75. false,
  76. extension_loaded('pdo_pgsql'),
  77. t('yii','All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
  78. t('yii','This is required if you are using PostgreSQL database.')),
  79. array(
  80. t('yii','PDO Oracle extension'),
  81. false,
  82. extension_loaded('pdo_oci'),
  83. t('yii','All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
  84. t('yii','This is required if you are using Oracle database.')),
  85. array(
  86. t('yii','PDO MSSQL extension (pdo_mssql)'),
  87. false,
  88. extension_loaded('pdo_mssql'),
  89. t('yii','All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
  90. t('yii','This is required if you are using MSSQL database from MS Windows')),
  91. array(
  92. t('yii','PDO MSSQL extension (pdo_dblib)'),
  93. false,
  94. extension_loaded('pdo_dblib'),
  95. t('yii','All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
  96. t('yii','This is required if you are using MSSQL database from GNU/Linux or other UNIX.')),
  97. array(
  98. t('yii','PDO MSSQL extension (<a href="http://sqlsrvphp.codeplex.com/">pdo_sqlsrv</a>)'),
  99. false,
  100. extension_loaded('pdo_sqlsrv'),
  101. t('yii','All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
  102. t('yii','This is required if you are using MSSQL database with the driver provided by Microsoft.')),
  103. array(
  104. t('yii','Memcache extension'),
  105. false,
  106. extension_loaded("memcache") || extension_loaded("memcached"),
  107. '<a href="http://www.yiiframework.com/doc/api/CMemCache">CMemCache</a>',
  108. extension_loaded("memcached") ? t('yii', 'To use memcached set <a href="http://www.yiiframework.com/doc/api/CMemCache#useMemcached-detail">CMemCache::useMemcached</a> to <code>true</code>.') : ''),
  109. array(
  110. t('yii','APC extension'),
  111. false,
  112. extension_loaded("apc"),
  113. '<a href="http://www.yiiframework.com/doc/api/CApcCache">CApcCache</a>',
  114. ''),
  115. array(
  116. t('yii','Mcrypt extension'),
  117. false,
  118. extension_loaded("mcrypt"),
  119. '<a href="http://www.yiiframework.com/doc/api/CSecurityManager">CSecurityManager</a>',
  120. t('yii','This is required by encrypt and decrypt methods.')),
  121. array(
  122. t('yii','SOAP extension'),
  123. false,
  124. extension_loaded("soap"),
  125. '<a href="http://www.yiiframework.com/doc/api/CWebService">CWebService</a>, <a href="http://www.yiiframework.com/doc/api/CWebServiceAction">CWebServiceAction</a>',
  126. ''),
  127. array(
  128. t('yii','GD extension with<br />FreeType support<br />or ImageMagick<br />extension with<br />PNG support'),
  129. false,
  130. '' === $message=checkCaptchaSupport(),
  131. '<a href="http://www.yiiframework.com/doc/api/CCaptchaAction">CCaptchaAction</a>',
  132. $message),
  133. array(
  134. t('yii','Ctype extension'),
  135. false,
  136. extension_loaded("ctype"),
  137. '<a href="http://www.yiiframework.com/doc/api/CDateFormatter">CDateFormatter</a>, <a href="http://www.yiiframework.com/doc/api/CDateFormatter">CDateTimeParser</a>, <a href="http://www.yiiframework.com/doc/api/CTextHighlighter">CTextHighlighter</a>, <a href="http://www.yiiframework.com/doc/api/CHtmlPurifier">CHtmlPurifier</a>',
  138. ''
  139. )
  140. );
  141. function checkServerVar()
  142. {
  143. $vars=array('HTTP_HOST','SERVER_NAME','SERVER_PORT','SCRIPT_NAME','SCRIPT_FILENAME','PHP_SELF','HTTP_ACCEPT','HTTP_USER_AGENT');
  144. $missing=array();
  145. foreach($vars as $var)
  146. {
  147. if(!isset($_SERVER[$var]))
  148. $missing[]=$var;
  149. }
  150. if(!empty($missing))
  151. return t('yii','$_SERVER does not have {vars}.',array('{vars}'=>implode(', ',$missing)));
  152. if(realpath($_SERVER["SCRIPT_FILENAME"]) !== realpath(__FILE__))
  153. return t('yii','$_SERVER["SCRIPT_FILENAME"] must be the same as the entry script file path.');
  154. if(!isset($_SERVER["REQUEST_URI"]) && isset($_SERVER["QUERY_STRING"]))
  155. return t('yii','Either $_SERVER["REQUEST_URI"] or $_SERVER["QUERY_STRING"] must exist.');
  156. if(!isset($_SERVER["PATH_INFO"]) && strpos($_SERVER["PHP_SELF"],$_SERVER["SCRIPT_NAME"]) !== 0)
  157. return t('yii','Unable to determine URL path info. Please make sure $_SERVER["PATH_INFO"] (or $_SERVER["PHP_SELF"] and $_SERVER["SCRIPT_NAME"]) contains proper value.');
  158. return '';
  159. }
  160. function checkCaptchaSupport()
  161. {
  162. if(extension_loaded('imagick'))
  163. {
  164. $imagick=new Imagick();
  165. $imagickFormats=$imagick->queryFormats('PNG');
  166. }
  167. if(extension_loaded('gd'))
  168. $gdInfo=gd_info();
  169. if(isset($imagickFormats) && in_array('PNG',$imagickFormats))
  170. return '';
  171. elseif(isset($gdInfo))
  172. {
  173. if($gdInfo['FreeType Support'])
  174. return '';
  175. return t('yii','GD installed,<br />FreeType support not installed');
  176. }
  177. return t('yii','GD or ImageMagick not installed');
  178. }
  179. function getYiiVersion()
  180. {
  181. $coreFile=dirname(__FILE__).'/../framework/YiiBase.php';
  182. if(is_file($coreFile))
  183. {
  184. $contents=file_get_contents($coreFile);
  185. $matches=array();
  186. if(preg_match('/public static function getVersion.*?return \'(.*?)\'/ms',$contents,$matches) > 0)
  187. return $matches[1];
  188. }
  189. return '';
  190. }
  191. /**
  192. * Returns a localized message according to user preferred language.
  193. * @param string message category
  194. * @param string message to be translated
  195. * @param array parameters to be applied to the translated message
  196. * @return string translated message
  197. */
  198. function t($category,$message,$params=array())
  199. {
  200. static $messages;
  201. if($messages === null)
  202. {
  203. $messages=array();
  204. if(($lang=getPreferredLanguage()) !== false)
  205. {
  206. $file=dirname(__FILE__)."/messages/$lang/yii.php";
  207. if(is_file($file))
  208. $messages=include($file);
  209. }
  210. }
  211. if(empty($message))
  212. return $message;
  213. if(isset($messages[$message]) && $messages[$message] !== '')
  214. $message=$messages[$message];
  215. return $params !== array() ? strtr($message,$params) : $message;
  216. }
  217. function getPreferredLanguage()
  218. {
  219. if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && ($n=preg_match_all('/([\w\-]+)\s*(;\s*q\s*=\s*(\d*\.\d*))?/',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) > 0)
  220. {
  221. $languages=array();
  222. for($i=0; $i < $n; ++$i)
  223. $languages[$matches[1][$i]]=empty($matches[3][$i]) ? 1.0 : floatval($matches[3][$i]);
  224. arsort($languages);
  225. foreach($languages as $language=>$pref)
  226. {
  227. $lang=strtolower(str_replace('-','_',$language));
  228. if (preg_match("/^en\_?/", $lang))
  229. return false;
  230. if (!is_file($viewFile=dirname(__FILE__)."/views/$lang/index.php"))
  231. $lang=false;
  232. else
  233. break;
  234. }
  235. return $lang;
  236. }
  237. return false;
  238. }
  239. function getServerInfo()
  240. {
  241. $info[]=isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '';
  242. $info[]='<a href="http://www.yiiframework.com/">Yii Framework</a>/'.getYiiVersion();
  243. $info[]=@strftime('%Y-%m-%d %H:%M',time());
  244. return implode(' ',$info);
  245. }
  246. function renderFile($_file_,$_params_=array())
  247. {
  248. extract($_params_);
  249. require($_file_);
  250. }
  251. $result=1; // 1: all pass, 0: fail, -1: pass with warnings
  252. foreach($requirements as $i=>$requirement)
  253. {
  254. if($requirement[1] && !$requirement[2])
  255. $result=0;
  256. else if($result > 0 && !$requirement[1] && !$requirement[2])
  257. $result=-1;
  258. if($requirement[4] === '')
  259. $requirements[$i][4]='&nbsp;';
  260. }
  261. $lang=getPreferredLanguage();
  262. $viewFile=dirname(__FILE__)."/views/$lang/index.php";
  263. if(!is_file($viewFile))
  264. $viewFile=dirname(__FILE__).'/views/index.php';
  265. renderFile($viewFile,array(
  266. 'requirements'=>$requirements,
  267. 'result'=>$result,
  268. 'serverInfo'=>getServerInfo()));