function.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. include('db.php');
  3. $db = false;
  4. function template($name, $data = array())
  5. {
  6. $mobile = mobile();
  7. if($mobile)
  8. {
  9. $path = 'mobile';
  10. }
  11. else
  12. {
  13. $path = 'pc';
  14. }
  15. $path = 'default';
  16. include('template/' . $path . '/' . $name . '.html');
  17. }
  18. function cookie($name, $data = array())
  19. {
  20. $mobile = mobile();
  21. if($mobile)
  22. {
  23. $path = 'mobile';
  24. }
  25. else
  26. {
  27. $path = 'pc';
  28. }
  29. include('template/' . $path . '/' . $name . '.html');
  30. }
  31. function db()
  32. {
  33. global $db;
  34. if($db)
  35. {
  36. return $db;
  37. }
  38. $config = array
  39. (
  40. 'host' => 'localhost',
  41. 'port' => '3306',
  42. 'user' => 'root',
  43. 'passwd' => '123456',
  44. 'dbname' => 'fangweima',
  45. );
  46. $db = new Db($config);
  47. return $db;
  48. }
  49. function input($name)
  50. {
  51. if(isset($_REQUEST[$name]) && $_REQUEST[$name])
  52. {
  53. return $_REQUEST[$name];
  54. }
  55. return false;
  56. }
  57. function error($value)
  58. {
  59. out($value);
  60. die;
  61. }
  62. function out($value)
  63. {
  64. echo $value;
  65. }
  66. function sp($str, $l = 1)
  67. {
  68. if ($l > 0) {
  69. $ret = array();
  70. $len = mb_strlen($str, "UTF-8");
  71. for ($i = 0; $i < $len; $i += $l) {
  72. $ret[] = mb_substr($str, $i, $l, "UTF-8");
  73. }
  74. return $ret;
  75. }
  76. return preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY);
  77. }
  78. function color($num, $value, $index = 0)
  79. {
  80. $config = array
  81. (
  82. 0 => '#000000',
  83. 1 => '#ff0000',
  84. 2 => '#00ff00',
  85. 3 => '#0000ff',
  86. 4 => '#831b1f',
  87. 5 => '#086233',
  88. 6 => '#ffa501',
  89. 7 => '#800080',
  90. );
  91. if($config[$value-1])
  92. {
  93. $html = '<span style="text-decoration:none;font-weight:bold;font-size:25px;color:'.$config[$value-1].'">' . $num . '</span>';
  94. //$html = '<div style="display:inline;text-decoration:none;font-weight:bold;font-size:25px;color:'.$config[$value-1].';">' . $num . '</div>';
  95. if($index > 0 && ($index+1)%4 == 0)
  96. {
  97. $html .= '&nbsp;&nbsp;';
  98. }
  99. return $html;
  100. }
  101. return $num;
  102. }
  103. function mobile()
  104. {
  105. $_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';
  106. $mobile_browser = '0';
  107. if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))
  108. {
  109. $mobile_browser++;
  110. }
  111. if((isset($_SERVER['HTTP_ACCEPT'])) && (strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') !== false))
  112. {
  113. $mobile_browser++;
  114. }
  115. if(isset($_SERVER['HTTP_X_WAP_PROFILE']))
  116. {
  117. $mobile_browser++;
  118. }
  119. if(isset($_SERVER['HTTP_PROFILE']))
  120. {
  121. $mobile_browser++;
  122. }
  123. $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
  124. $mobile_agents = array(
  125. 'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
  126. 'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
  127. 'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
  128. 'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
  129. 'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
  130. 'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
  131. 'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
  132. 'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
  133. 'wapr','webc','winw','winw','xda','xda-'
  134. );
  135. if(in_array($mobile_ua, $mobile_agents))
  136. {
  137. $mobile_browser++;
  138. }
  139. if(strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)
  140. {
  141. $mobile_browser++;
  142. }
  143. // Pre-final check to reset everything if the user is on Windows
  144. if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false)
  145. {
  146. $mobile_browser=0;
  147. }
  148. // But WP7 is also Windows, with a slightly different characteristic
  149. if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)
  150. {
  151. $mobile_browser++;
  152. }
  153. if($mobile_browser>0)
  154. {
  155. return true;
  156. }
  157. else
  158. {
  159. return false;
  160. }
  161. }