PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/_lp/core/lib/core.function.php

https://github.com/no2key/TeamToy
PHP | 276 lines | 214 code | 53 blank | 9 comment | 36 complexity | ef7c7ae7bd44298d4ffde3f8194bb627 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. function transcribe($aList, $aIsTopLevel = true)
  3. {
  4. $gpcList = array();
  5. $isMagic = get_magic_quotes_gpc();
  6. foreach ($aList as $key => $value) {
  7. if (is_array($value)) {
  8. $decodedKey = ($isMagic && !$aIsTopLevel)?stripslashes($key):$key;
  9. $decodedValue = transcribe($value, false);
  10. } else {
  11. $decodedKey = stripslashes($key);
  12. $decodedValue = ($isMagic)?stripslashes($value):$value;
  13. }
  14. $gpcList[$decodedKey] = $decodedValue;
  15. }
  16. return $gpcList;
  17. }
  18. $_GET = transcribe( $_GET );
  19. $_POST = transcribe( $_POST );
  20. $_REQUEST = transcribe( $_REQUEST );
  21. function v( $str )
  22. {
  23. return isset( $_REQUEST[$str] ) ? $_REQUEST[$str] : false;
  24. }
  25. function z( $str )
  26. {
  27. return strip_tags( $str );
  28. }
  29. function c( $str )
  30. {
  31. return isset( $GLOBALS['config'][$str] ) ? $GLOBALS['config'][$str] : false;
  32. }
  33. function g( $str )
  34. {
  35. return isset( $GLOBALS[$str] ) ? $GLOBALS[$str] : false;
  36. }
  37. function t( $str )
  38. {
  39. return trim($str);
  40. }
  41. function u( $str )
  42. {
  43. return urlencode( $str );
  44. }
  45. // render functiones
  46. function render( $data = NULL , $layout = NULL , $sharp = 'default' , $pathinfo = false )
  47. {
  48. if( $layout == null )
  49. {
  50. if( is_ajax_request() )
  51. {
  52. $layout = 'ajax';
  53. }
  54. elseif( is_mobile_request() )
  55. {
  56. $layout = 'mobile';
  57. }
  58. else
  59. {
  60. $layout = 'web';
  61. }
  62. }
  63. $GLOBALS['layout'] = $layout;
  64. $GLOBALS['sharp'] = $sharp;
  65. $layout_file = AROOT . 'view/layout/' . $layout . '/' . $sharp . '.tpl.html';
  66. $data = apply_filter( 'CTRL_' . g('c'). '_' . g('a') .'_RENDER_FILTER' , $data );
  67. $GLOBALS['LP_RENDER_DATA'] = $data;
  68. if( file_exists( $layout_file ) )
  69. {
  70. @extract( $data );
  71. require( $layout_file );
  72. }
  73. else
  74. {
  75. $layout_file = CROOT . 'view/layout/' . $layout . '/' . $sharp . '.tpl.html';
  76. if( file_exists( $layout_file ) )
  77. {
  78. @extract( $data );
  79. require( $layout_file );
  80. }
  81. }
  82. }
  83. function ajax_echo( $info )
  84. {
  85. if( !headers_sent() )
  86. {
  87. header("Content-Type:text/html;charset=utf-8");
  88. header("Expires: Thu, 01 Jan 1970 00:00:01 GMT");
  89. header("Cache-Control: no-cache, must-revalidate");
  90. header("Pragma: no-cache");
  91. }
  92. echo $info;
  93. }
  94. function info_page( $info , $title = '系统消息' )
  95. {
  96. if( is_ajax_request() )
  97. $layout = 'ajax';
  98. else
  99. $layout = 'web';
  100. $data['top_title'] = $data['title'] = $title;
  101. $data['info'] = $info;
  102. render( $data , $layout , 'info' );
  103. exit;
  104. }
  105. function is_ajax_request()
  106. {
  107. $headers = apache_request_headers();
  108. return (isset( $headers['X-Requested-With'] ) && ( $headers['X-Requested-With'] == 'XMLHttpRequest' )) || (isset( $headers['x-requested-with'] ) && ($headers['x-requested-with'] == 'XMLHttpRequest' ));
  109. }
  110. if (!function_exists('apache_request_headers'))
  111. {
  112. function apache_request_headers()
  113. {
  114. foreach($_SERVER as $key=>$value)
  115. {
  116. if (substr($key,0,5)=="HTTP_")
  117. {
  118. $key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5)))));
  119. $out[$key]=$value;
  120. }
  121. else
  122. {
  123. $out[$key]=$value;
  124. }
  125. }
  126. return $out;
  127. }
  128. }
  129. function is_mobile_request()
  130. {
  131. $_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';
  132. $mobile_browser = '0';
  133. if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))
  134. $mobile_browser++;
  135. if((isset($_SERVER['HTTP_ACCEPT'])) and (strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') !== false))
  136. $mobile_browser++;
  137. if(isset($_SERVER['HTTP_X_WAP_PROFILE']))
  138. $mobile_browser++;
  139. if(isset($_SERVER['HTTP_PROFILE']))
  140. $mobile_browser++;
  141. $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
  142. $mobile_agents = array(
  143. 'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
  144. 'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
  145. 'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
  146. 'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
  147. 'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
  148. 'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
  149. 'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
  150. 'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
  151. 'wapr','webc','winw','winw','xda','xda-'
  152. );
  153. if(in_array($mobile_ua, $mobile_agents))
  154. $mobile_browser++;
  155. if(strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)
  156. $mobile_browser++;
  157. // Pre-final check to reset everything if the user is on Windows
  158. if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false)
  159. $mobile_browser=0;
  160. // But WP7 is also Windows, with a slightly different characteristic
  161. if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)
  162. $mobile_browser++;
  163. if($mobile_browser>0)
  164. return true;
  165. else
  166. return false;
  167. }
  168. function uses( $m )
  169. {
  170. load( 'lib/' . basename($m) );
  171. }
  172. function load( $file_path )
  173. {
  174. $file = AROOT . $file_path;
  175. if( file_exists( $file ) )
  176. {
  177. //echo $file;
  178. require( $file );
  179. }
  180. else
  181. {
  182. //echo CROOT . $file_path;
  183. require( CROOT . $file_path );
  184. }
  185. }
  186. // ===========================================
  187. // load db functions
  188. // ===========================================
  189. if( defined('SAE_APPNAME') )
  190. include_once( CROOT . 'lib/db.sae.function.php' );
  191. else
  192. include_once( CROOT . 'lib/db.function.php' );
  193. if (!function_exists('_'))
  194. {
  195. function _( $string , $data = null )
  196. {
  197. if( !isset($GLOBALS['i18n']) )
  198. {
  199. $c = c('default_language');
  200. if( strlen($c) < 1 ) $c = 'zh_cn';
  201. $lang_file = AROOT . 'local' . DS . basename($c) . '.lang.php';
  202. if( file_exists( $lang_file ) )
  203. {
  204. include_once( $lang_file );
  205. $GLOBALS['i18n'] = $c;
  206. }
  207. else
  208. $GLOBALS['i18n'] = 'zh_cn';
  209. }
  210. //print_r( $GLOBALS['language'][$GLOBALS['i18n']] );
  211. if( isset( $GLOBALS['language'][$GLOBALS['i18n']][$string] ) )
  212. $to = $GLOBALS['language'][$GLOBALS['i18n']][$string];
  213. else
  214. $to = $string;
  215. if( $data == null )
  216. return $to;
  217. else
  218. {
  219. if( !is_array( $data ) ) $data = array( $data );
  220. return vsprintf( $to , $data );
  221. }
  222. }
  223. }