index.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 2008-2013 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','Required for 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','Required for 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','Required for 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','Required for 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','Required for 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','Required for 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','Required for 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','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. array(
  141. t('yii','Fileinfo extension'),
  142. false,
  143. extension_loaded("fileinfo"),
  144. '<a href="http://www.yiiframework.com/doc/api/CFileValidator">CFileValidator</a>',
  145. t('yii','Required for MIME-type validation')
  146. ),
  147. );
  148. function checkServerVar()
  149. {
  150. $vars=array('HTTP_HOST','SERVER_NAME','SERVER_PORT','SCRIPT_NAME','SCRIPT_FILENAME','PHP_SELF','HTTP_ACCEPT','HTTP_USER_AGENT');
  151. $missing=array();
  152. foreach($vars as $var)
  153. {
  154. if(!isset($_SERVER[$var]))
  155. $missing[]=$var;
  156. }
  157. if(!empty($missing))
  158. return t('yii','$_SERVER does not have {vars}.',array('{vars}'=>implode(', ',$missing)));
  159. if(realpath($_SERVER["SCRIPT_FILENAME"]) !== realpath(__FILE__))
  160. return t('yii','$_SERVER["SCRIPT_FILENAME"] must be the same as the entry script file path.');
  161. if(!isset($_SERVER["REQUEST_URI"]) && isset($_SERVER["QUERY_STRING"]))
  162. return t('yii','Either $_SERVER["REQUEST_URI"] or $_SERVER["QUERY_STRING"] must exist.');
  163. if(!isset($_SERVER["PATH_INFO"]) && strpos($_SERVER["PHP_SELF"],$_SERVER["SCRIPT_NAME"]) !== 0)
  164. 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.');
  165. return '';
  166. }
  167. function checkCaptchaSupport()
  168. {
  169. if(extension_loaded('imagick'))
  170. {
  171. $imagick=new Imagick();
  172. $imagickFormats=$imagick->queryFormats('PNG');
  173. }
  174. if(extension_loaded('gd'))
  175. $gdInfo=gd_info();
  176. if(isset($imagickFormats) && in_array('PNG',$imagickFormats))
  177. return '';
  178. elseif(isset($gdInfo))
  179. {
  180. if($gdInfo['FreeType Support'])
  181. return '';
  182. return t('yii','GD installed,<br />FreeType support not installed');
  183. }
  184. return t('yii','GD or ImageMagick not installed');
  185. }
  186. function getYiiVersion()
  187. {
  188. $coreFile=dirname(__FILE__).'/../framework/YiiBase.php';
  189. if(is_file($coreFile))
  190. {
  191. $contents=file_get_contents($coreFile);
  192. $matches=array();
  193. if(preg_match('/public static function getVersion.*?return \'(.*?)\'/ms',$contents,$matches) > 0)
  194. return $matches[1];
  195. }
  196. return '';
  197. }
  198. /**
  199. * Returns a localized message according to user preferred language.
  200. * @param string message category
  201. * @param string message to be translated
  202. * @param array parameters to be applied to the translated message
  203. * @return string translated message
  204. */
  205. function t($category,$message,$params=array())
  206. {
  207. static $messages;
  208. if($messages === null)
  209. {
  210. $messages=array();
  211. if(($lang=getPreferredLanguage()) !== false)
  212. {
  213. $file=dirname(__FILE__)."/messages/$lang/yii.php";
  214. if(is_file($file))
  215. $messages=include($file);
  216. }
  217. }
  218. if(empty($message))
  219. return $message;
  220. if(isset($messages[$message]) && $messages[$message] !== '')
  221. $message=$messages[$message];
  222. return $params !== array() ? strtr($message,$params) : $message;
  223. }
  224. function getPreferredLanguage()
  225. {
  226. if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && ($n=preg_match_all('/([\w\-]+)\s*(;\s*q\s*=\s*(\d*\.\d*))?/',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) > 0)
  227. {
  228. $languages=array();
  229. for($i=0; $i < $n; ++$i)
  230. $languages[$matches[1][$i]]=empty($matches[3][$i]) ? 1.0 : floatval($matches[3][$i]);
  231. arsort($languages);
  232. foreach($languages as $language=>$pref)
  233. {
  234. $lang=strtolower(str_replace('-','_',$language));
  235. if (preg_match("/^en\_?/", $lang))
  236. return false;
  237. if (!is_file($viewFile=dirname(__FILE__)."/views/$lang/index.php"))
  238. $lang=false;
  239. else
  240. break;
  241. }
  242. return $lang;
  243. }
  244. return false;
  245. }
  246. function getServerInfo()
  247. {
  248. $info[]=isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '';
  249. $info[]='<a href="http://www.yiiframework.com/">Yii Framework</a>/'.getYiiVersion();
  250. $info[]=@strftime('%Y-%m-%d %H:%M',time());
  251. return implode(' ',$info);
  252. }
  253. function renderFile($_file_,$_params_=array())
  254. {
  255. extract($_params_);
  256. require($_file_);
  257. }
  258. $result=1; // 1: all pass, 0: fail, -1: pass with warnings
  259. foreach($requirements as $i=>$requirement)
  260. {
  261. if($requirement[1] && !$requirement[2])
  262. $result=0;
  263. else if($result > 0 && !$requirement[1] && !$requirement[2])
  264. $result=-1;
  265. if($requirement[4] === '')
  266. $requirements[$i][4]='&nbsp;';
  267. }
  268. $lang=getPreferredLanguage();
  269. $viewFile=dirname(__FILE__)."/views/$lang/index.php";
  270. if(!is_file($viewFile))
  271. $viewFile=dirname(__FILE__).'/views/index.php';
  272. renderFile($viewFile,array(
  273. 'requirements'=>$requirements,
  274. 'result'=>$result,
  275. 'serverInfo'=>getServerInfo()));