PageRenderTime 37ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/app.function.php

https://github.com/no2key/TeamToy
PHP | 693 lines | 570 code | 83 blank | 40 comment | 58 complexity | 49d74784c8fa37e8fabfd9b632a5c2b7 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. if( !defined('SAE_TMP_PATH') )
  3. {
  4. @mkdir( AROOT . DS . 'tmp');
  5. define('SAE_TMP_PATH', AROOT . DS . 'tmp' . DS );
  6. }
  7. function not_empty( $str )
  8. {
  9. return strlen( $str ) > 0;
  10. }
  11. // From aoihome.sinaapp.com/fun via Aoi [is_email]
  12. function is_email( $email )
  13. {
  14. return filter_var( $email , FILTER_VALIDATE_EMAIL );
  15. }
  16. function on_sae()
  17. {
  18. return defined('SAE_ACCESSKEY') && (substr( SAE_ACCESSKEY , 0 , 4 ) != 'kapp') ;
  19. }
  20. function is_installed()
  21. {
  22. return mysql_query("SHOW COLUMNS FROM `user`",db());
  23. }
  24. function kset( $key , $value )
  25. {
  26. $sql = "REPLACE INTO `keyvalue` ( `key` , `value` ) VALUES ( '" . s($key) . "' , '" . s($value) . "' )";
  27. run_sql( $sql );
  28. }
  29. function kget( $key )
  30. {
  31. return get_var( "SELECT `value` FROM `keyvalue` WHERE `key` = '" . s($key) . "' LIMIT 1" );
  32. }
  33. function kdel( $key )
  34. {
  35. $sql = "DELETE FROM `keyvalue` WHERE `key` = '" . s($key) . "' LIMIT 1" ;
  36. run_sql($sql);
  37. }
  38. function local_version()
  39. {
  40. return intval(file_get_contents(AROOT.'version.txt'));
  41. }
  42. function db_init()
  43. {
  44. $password = substr( md5( time().rand(1,9999) ) , rand( 1 , 20 ) , 12 );
  45. $sql_contents = preg_replace( "/(#.+[\r|\n]*)/" , '' , file_get_contents( AROOT . 'misc' . DS . 'install.sql'));
  46. // 更换变量
  47. $sql_contents = str_replace( '{password}' , md5($password) , $sql_contents );
  48. $sqls = split_sql_file( $sql_contents );
  49. foreach ($sqls as $sql)
  50. {
  51. run_sql( $sql );
  52. }
  53. if( db_errno() == 0 )
  54. {
  55. info_page('数据库初始化成功,请使用【member@teamtoy.net】和【' . $password . '】<a href="/" target="new">登入并添加用户</a>');
  56. exit;
  57. }
  58. else
  59. {
  60. info_page( db_error() );
  61. exit;
  62. }
  63. }
  64. function split_sql_file($sql, $delimiter = ';')
  65. {
  66. $sql = trim($sql);
  67. $char = '';
  68. $last_char = '';
  69. $ret = array();
  70. $string_start = '';
  71. $in_string = FALSE;
  72. $escaped_backslash = FALSE;
  73. for ($i = 0; $i < strlen($sql); ++$i) {
  74. $char = $sql[$i];
  75. // if delimiter found, add the parsed part to the returned array
  76. if ($char == $delimiter && !$in_string) {
  77. $ret[] = substr($sql, 0, $i);
  78. $sql = substr($sql, $i + 1);
  79. $i = 0;
  80. $last_char = '';
  81. }
  82. if ($in_string) {
  83. // We are in a string, first check for escaped backslashes
  84. if ($char == '\\') {
  85. if ($last_char != '\\') {
  86. $escaped_backslash = FALSE;
  87. } else {
  88. $escaped_backslash = !$escaped_backslash;
  89. }
  90. }
  91. // then check for not escaped end of strings except for
  92. // backquotes than cannot be escaped
  93. if (($char == $string_start)
  94. && ($char == '`' || !(($last_char == '\\') && !$escaped_backslash))) {
  95. $in_string = FALSE;
  96. $string_start = '';
  97. }
  98. } else {
  99. // we are not in a string, check for start of strings
  100. if (($char == '"') || ($char == '\'') || ($char == '`')) {
  101. $in_string = TRUE;
  102. $string_start = $char;
  103. }
  104. }
  105. $last_char = $char;
  106. } // end for
  107. // add any rest to the returned array
  108. if (!empty($sql)) {
  109. $ret[] = $sql;
  110. }
  111. return $ret;
  112. }
  113. function is_login()
  114. {
  115. return $_SESSION['level'] > 0;
  116. }
  117. function is_admin()
  118. {
  119. return $_SESSION['level'] == 9;
  120. }
  121. function uid()
  122. {
  123. return intval($_SESSION['uid']);
  124. }
  125. function uname()
  126. {
  127. return t($_SESSION['uname']);
  128. }
  129. function forward( $url )
  130. {
  131. header( "Location: " . $url );
  132. }
  133. function jsforword( $url )
  134. {
  135. return '<script>location="' . $url . '"</script>';
  136. }
  137. function image( $filename )
  138. {
  139. return 'static/image/' . $filename;
  140. }
  141. function avatar( $url )
  142. {
  143. if( strlen($url) < 1 ) return c('default_avatar');
  144. else return $url;
  145. }
  146. function ctime( $timeline )
  147. {
  148. $time = strtotime($timeline);
  149. if( time() > ($time+60*60*24*300) )return date("Y年n月j日 H:i",$time);
  150. elseif( time() > ($time+60*60*8) ) return date("n月j日 H:i",$time);
  151. else return date("H:i:s",$time);
  152. }
  153. /*
  154. function rtime( $timeline )
  155. {
  156. return date("m月d日 H点i分" , strtotime($timeline) );
  157. }
  158. */
  159. function rtime( $time = false, $limit = 86400, $format = 'm月d日 H点i分')
  160. {
  161. $time = strtotime($time);
  162. $now = time();
  163. $relative = '';
  164. if ($time === $now) $relative = '刚刚';
  165. elseif ($time > $now) $relative = '以后';
  166. else
  167. {
  168. $diff = $now - $time;
  169. if ($diff >= $limit) $relative = date($format, $time);
  170. elseif ($diff < 60)
  171. {
  172. $relative = '不到一分钟';
  173. }
  174. elseif (($minutes = ceil($diff/60)) < 60)
  175. {
  176. $relative = $minutes.'分钟'.(((int)$minutes === 1) ? '' : '').'前';
  177. }
  178. else
  179. {
  180. $hours = ceil($diff/3600);
  181. $relative = $hours.'小时'.(((int)$hours === 1) ? '' : '').'前';
  182. }
  183. }
  184. return $relative;
  185. }
  186. function noname( $content , $name )
  187. {
  188. $len = strlen($name);
  189. if( substr( $content , 0 , $len ) == $name )
  190. return substr( $content , $len );
  191. else
  192. return $content;
  193. }
  194. function render_html( $data , $tpl )
  195. {
  196. ob_start();
  197. extract($data);
  198. require( $tpl );
  199. $content = ob_get_contents();
  200. ob_end_clean();
  201. return $content;
  202. //
  203. }
  204. function feed_class( $type )
  205. {
  206. switch( $type )
  207. {
  208. case 2:
  209. $class= 'todo';
  210. break;
  211. case 1:
  212. $class= 'notice';
  213. break;
  214. case 3:
  215. $class= 'user';
  216. break;
  217. case 4:
  218. $class= 'cast';
  219. break;
  220. default:
  221. $class = 'normal';
  222. }
  223. return $class;
  224. }
  225. function device( $type )
  226. {
  227. if( strtolower($type) == 'mobile' )
  228. $ret = '<a href="http://teamtoy.net/?c=download&type=mobile" target="_blank">来自移动版</a>';
  229. else
  230. $ret = '<a href="http://teamtoy.net/?c=download&type=web" target="_blank">来自网页版</a>';
  231. return $ret;
  232. }
  233. function get_device()
  234. {
  235. if( is_mobile_request()) return 'mobile';
  236. else return 'web';
  237. }
  238. // ========================================
  239. // client functions
  240. // ========================================
  241. function login( $email , $password )
  242. {
  243. if($content = file_get_contents( c('api_server') . '?c=api&a=user_get_token&email=' . u($email) . '&password=' .u($password) ))
  244. {
  245. $data = json_decode( $content , 1 );
  246. if( ($data['err_code'] == 0) && is_array( $data['data'] ) )
  247. return $data['data'];
  248. else
  249. return false;
  250. }
  251. return null;
  252. }
  253. function token()
  254. {
  255. return $_SESSION['token'];
  256. }
  257. function send_request( $action , $param , $token )
  258. {
  259. require_once( AROOT . 'controller' . DS . 'api.class.php' );
  260. require_once( AROOT . 'model' . DS . 'api.function.php' );
  261. $GLOBALS['API_EMBED_MODE'] = 1;
  262. // local request
  263. $bake_request = $_REQUEST;
  264. $_REQUEST['c'] = 'api';
  265. $_REQUEST['a'] = $action;
  266. $_REQUEST['token'] = $token;
  267. if( (is_array( $param )) && (count($param) > 0) )
  268. foreach( $param as $key => $value )
  269. $_REQUEST[$key] = $value ;
  270. $api = new apiController();
  271. if( method_exists($api, $action) )
  272. {
  273. $content = $api->$action();
  274. $_REQUEST = $bake_request;
  275. return $content;
  276. //if($data = json_decode( $content , 1 ))
  277. //return json_encode($data['data']);
  278. }
  279. return null;
  280. // remote request ...........
  281. /*
  282. $url = c('api_server') . '?c=api&a=' . u($action) . '&token=' . u($token) ;
  283. if( (is_array( $param )) && (count($param) > 0) )
  284. foreach( $param as $key => $value )
  285. $url .= '&' . $key . '=' . u( $value );
  286. if($content = file_get_contents( $url ))
  287. return $content;
  288. return $url;
  289. */
  290. }
  291. function find_at( $text )
  292. {
  293. $reg = '/@(\S+?(?:\s|$))/is';
  294. if( preg_match_all( $reg , $text , $out ) )
  295. return $out[1];
  296. else
  297. return false;
  298. }
  299. function jpeg_up( $source , $dest )
  300. {
  301. $img_info = @exif_read_data( $source , ANY_TAG );
  302. switch( $img_info['Orientation'] )
  303. {
  304. case 6:
  305. $r = 270;
  306. break;
  307. case 3:
  308. $r = 180;
  309. break;
  310. case 8:
  311. $r = 90;
  312. break;
  313. default:
  314. $r = 0;
  315. }
  316. $img_src = ImageCreateFromJPEG( $source );
  317. $rotate = imagerotate($img_src, $r, 0,true);
  318. ImageJPEG($rotate,$dest);
  319. }
  320. function upload_as_form( $url , $data )
  321. {
  322. $ch = curl_init();
  323. curl_setopt($ch, CURLOPT_URL, $url);
  324. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  325. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  326. curl_setopt($ch, CURLOPT_POST, true);
  327. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  328. $response = curl_exec($ch);
  329. return $response;
  330. }
  331. function pinyin($_string, $_code='utf8')
  332. { //gbk页面可改为gb2312,其他随意填写为utf8
  333. $_datakey = "a|ai|an|ang|ao|ba|bai|ban|bang|bao|bei|ben|beng|bi|bian|biao|bie|bin|bing|bo|bu|ca|cai|can|cang|cao|ce|ceng|cha".
  334. "|chai|chan|chang|chao|che|chen|cheng|chi|chong|chou|chu|chuai|chuan|chuang|chui|chun|chuo|ci|cong|cou|cu|".
  335. "cuan|cui|cun|cuo|da|dai|dan|dang|dao|de|deng|di|dian|diao|die|ding|diu|dong|dou|du|duan|dui|dun|duo|e|en|er".
  336. "|fa|fan|fang|fei|fen|feng|fo|fou|fu|ga|gai|gan|gang|gao|ge|gei|gen|geng|gong|gou|gu|gua|guai|guan|guang|gui".
  337. "|gun|guo|ha|hai|han|hang|hao|he|hei|hen|heng|hong|hou|hu|hua|huai|huan|huang|hui|hun|huo|ji|jia|jian|jiang".
  338. "|jiao|jie|jin|jing|jiong|jiu|ju|juan|jue|jun|ka|kai|kan|kang|kao|ke|ken|keng|kong|kou|ku|kua|kuai|kuan|kuang".
  339. "|kui|kun|kuo|la|lai|lan|lang|lao|le|lei|leng|li|lia|lian|liang|liao|lie|lin|ling|liu|long|lou|lu|lv|luan|lue".
  340. "|lun|luo|ma|mai|man|mang|mao|me|mei|men|meng|mi|mian|miao|mie|min|ming|miu|mo|mou|mu|na|nai|nan|nang|nao|ne".
  341. "|nei|nen|neng|ni|nian|niang|niao|nie|nin|ning|niu|nong|nu|nv|nuan|nue|nuo|o|ou|pa|pai|pan|pang|pao|pei|pen".
  342. "|peng|pi|pian|piao|pie|pin|ping|po|pu|qi|qia|qian|qiang|qiao|qie|qin|qing|qiong|qiu|qu|quan|que|qun|ran|rang".
  343. "|rao|re|ren|reng|ri|rong|rou|ru|ruan|rui|run|ruo|sa|sai|san|sang|sao|se|sen|seng|sha|shai|shan|shang|shao|".
  344. "she|shen|sheng|shi|shou|shu|shua|shuai|shuan|shuang|shui|shun|shuo|si|song|sou|su|suan|sui|sun|suo|ta|tai|".
  345. "tan|tang|tao|te|teng|ti|tian|tiao|tie|ting|tong|tou|tu|tuan|tui|tun|tuo|wa|wai|wan|wang|wei|wen|weng|wo|wu".
  346. "|xi|xia|xian|xiang|xiao|xie|xin|xing|xiong|xiu|xu|xuan|xue|xun|ya|yan|yang|yao|ye|yi|yin|ying|yo|yong|you".
  347. "|yu|yuan|yue|yun|za|zai|zan|zang|zao|ze|zei|zen|zeng|zha|zhai|zhan|zhang|zhao|zhe|zhen|zheng|zhi|zhong|".
  348. "zhou|zhu|zhua|zhuai|zhuan|zhuang|zhui|zhun|zhuo|zi|zong|zou|zu|zuan|zui|zun|zuo";
  349. $_datavalue = "-20319|-20317|-20304|-20295|-20292|-20283|-20265|-20257|-20242|-20230|-20051|-20036|-20032|-20026|-20002|-19990".
  350. "|-19986|-19982|-19976|-19805|-19784|-19775|-19774|-19763|-19756|-19751|-19746|-19741|-19739|-19728|-19725".
  351. "|-19715|-19540|-19531|-19525|-19515|-19500|-19484|-19479|-19467|-19289|-19288|-19281|-19275|-19270|-19263".
  352. "|-19261|-19249|-19243|-19242|-19238|-19235|-19227|-19224|-19218|-19212|-19038|-19023|-19018|-19006|-19003".
  353. "|-18996|-18977|-18961|-18952|-18783|-18774|-18773|-18763|-18756|-18741|-18735|-18731|-18722|-18710|-18697".
  354. "|-18696|-18526|-18518|-18501|-18490|-18478|-18463|-18448|-18447|-18446|-18239|-18237|-18231|-18220|-18211".
  355. "|-18201|-18184|-18183|-18181|-18012|-17997|-17988|-17970|-17964|-17961|-17950|-17947|-17931|-17928|-17922".
  356. "|-17759|-17752|-17733|-17730|-17721|-17703|-17701|-17697|-17692|-17683|-17676|-17496|-17487|-17482|-17468".
  357. "|-17454|-17433|-17427|-17417|-17202|-17185|-16983|-16970|-16942|-16915|-16733|-16708|-16706|-16689|-16664".
  358. "|-16657|-16647|-16474|-16470|-16465|-16459|-16452|-16448|-16433|-16429|-16427|-16423|-16419|-16412|-16407".
  359. "|-16403|-16401|-16393|-16220|-16216|-16212|-16205|-16202|-16187|-16180|-16171|-16169|-16158|-16155|-15959".
  360. "|-15958|-15944|-15933|-15920|-15915|-15903|-15889|-15878|-15707|-15701|-15681|-15667|-15661|-15659|-15652".
  361. "|-15640|-15631|-15625|-15454|-15448|-15436|-15435|-15419|-15416|-15408|-15394|-15385|-15377|-15375|-15369".
  362. "|-15363|-15362|-15183|-15180|-15165|-15158|-15153|-15150|-15149|-15144|-15143|-15141|-15140|-15139|-15128".
  363. "|-15121|-15119|-15117|-15110|-15109|-14941|-14937|-14933|-14930|-14929|-14928|-14926|-14922|-14921|-14914".
  364. "|-14908|-14902|-14894|-14889|-14882|-14873|-14871|-14857|-14678|-14674|-14670|-14668|-14663|-14654|-14645".
  365. "|-14630|-14594|-14429|-14407|-14399|-14384|-14379|-14368|-14355|-14353|-14345|-14170|-14159|-14151|-14149".
  366. "|-14145|-14140|-14137|-14135|-14125|-14123|-14122|-14112|-14109|-14099|-14097|-14094|-14092|-14090|-14087".
  367. "|-14083|-13917|-13914|-13910|-13907|-13906|-13905|-13896|-13894|-13878|-13870|-13859|-13847|-13831|-13658".
  368. "|-13611|-13601|-13406|-13404|-13400|-13398|-13395|-13391|-13387|-13383|-13367|-13359|-13356|-13343|-13340".
  369. "|-13329|-13326|-13318|-13147|-13138|-13120|-13107|-13096|-13095|-13091|-13076|-13068|-13063|-13060|-12888".
  370. "|-12875|-12871|-12860|-12858|-12852|-12849|-12838|-12831|-12829|-12812|-12802|-12607|-12597|-12594|-12585".
  371. "|-12556|-12359|-12346|-12320|-12300|-12120|-12099|-12089|-12074|-12067|-12058|-12039|-11867|-11861|-11847".
  372. "|-11831|-11798|-11781|-11604|-11589|-11536|-11358|-11340|-11339|-11324|-11303|-11097|-11077|-11067|-11055".
  373. "|-11052|-11045|-11041|-11038|-11024|-11020|-11019|-11018|-11014|-10838|-10832|-10815|-10800|-10790|-10780".
  374. "|-10764|-10587|-10544|-10533|-10519|-10331|-10329|-10328|-10322|-10315|-10309|-10307|-10296|-10281|-10274".
  375. "|-10270|-10262|-10260|-10256|-10254";
  376. $_tdatakey = explode('|', $_datakey);
  377. $_tdatavalue = explode('|', $_datavalue);
  378. $_data = array_combine($_tdatakey, $_tdatavalue);
  379. arsort($_data);
  380. reset($_data);
  381. if($_code!= 'gb2312') $_string = _u2_utf8_gb($_string);
  382. $_res = '';
  383. for($i=0; $i<strlen($_string); $i++) {
  384. $_p = ord(substr($_string, $i, 1));
  385. if($_p>160) {
  386. $_q = ord(substr($_string, ++$i, 1)); $_p = $_p*256 + $_q - 65536;
  387. }
  388. $_res .= _pinyin($_p, $_data);
  389. }
  390. return preg_replace("/[^a-z0-9]*/", '', $_res);
  391. }
  392. function _pinyin($_num, $_data)
  393. {
  394. if($_num>0 && $_num<160 ){
  395. return chr($_num);
  396. }elseif($_num<-20319 || $_num>-10247){
  397. return '';
  398. }else{
  399. foreach($_data as $k=>$v){ if($v<=$_num) break; }
  400. return $k;
  401. }
  402. }
  403. function _u2_utf8_gb($_c)
  404. {
  405. $_string = '';
  406. if($_c < 0x80){
  407. $_string .= $_c;
  408. }elseif($_c < 0x800) {
  409. $_string .= chr(0xc0 | $_c>>6);
  410. $_string .= chr(0x80 | $_c & 0x3f);
  411. }elseif($_c < 0x10000){
  412. $_string .= chr(0xe0 | $_c>>12);
  413. $_string .= chr(0x80 | $_c>>6 & 0x3f);
  414. $_string .= chr(0x80 | $_c & 0x3f);
  415. }elseif($_c < 0x200000) {
  416. $_string .= chr(0xf0 | $_c>>18);
  417. $_string .= chr(0x80 | $_c>>12 & 0x3f);
  418. $_string .= chr(0x80 | $_c>>6 & 0x3f);
  419. $_string .= chr(0x80 | $_c & 0x3f);
  420. }
  421. return iconv('utf-8', 'gb2312', $_string);
  422. }
  423. // **************************************************************
  424. // * Plugins & hooks
  425. // **************************************************************
  426. function add_filter( $tag , $function_to_add , $priority = 10 , $accepted_args_num = 1 )
  427. {
  428. return add_hook( $tag , $function_to_add , $priority , $accepted_args_num );
  429. }
  430. function add_action( $tag , $function_to_add , $priority = 10 , $accepted_args_num = 1 )
  431. {
  432. return add_hook( $tag , $function_to_add , $priority , $accepted_args_num );
  433. }
  434. function add_hook( $tag , $function_to_add , $priority = 10 , $accepted_args_num = 1 )
  435. {
  436. $tag = strtoupper($tag);
  437. $idx = build_hook_id( $tag , $function_to_add , $priority );
  438. $GLOBALS['TTHOOK'][$tag][$priority][$idx] = array( 'function' => $function_to_add , 'args_num' => $accepted_args_num );
  439. }
  440. function do_action( $tag , $value = null )
  441. {
  442. return apply_hook( $tag , $value );
  443. }
  444. function apply_filter( $tag , $value = null )
  445. {
  446. return apply_hook( $tag , $value );
  447. }
  448. function apply_hook( $tag , $value )
  449. {
  450. $tag = strtoupper($tag);
  451. if( $hooks = has_hook( $tag ) )
  452. {
  453. ksort( $hooks );
  454. $args = func_get_args();
  455. reset( $hooks );
  456. do
  457. {
  458. foreach( (array) current( $hooks ) as $hook )
  459. {
  460. if( !is_null($hook['function']) )
  461. {
  462. $args[1] = $value;
  463. $value = call_user_func_array( $hook['function'] , array_slice($args, 1, (int) $hook['args_num']));
  464. }
  465. }
  466. }while( next( $hooks ) !== false );
  467. }
  468. return $value;
  469. }
  470. function has_hook( $tag , $priority = null )
  471. {
  472. $tag = strtoupper($tag);
  473. if( is_null($priority) ) return isset( $GLOBALS['TTHOOK'][$tag] )? $GLOBALS['TTHOOK'][$tag]:false;
  474. else return isset( $GLOBALS['TTHOOK'][$tag][$priority] )? $GLOBALS['TTHOOK'][$tag][$priority]:false;
  475. }
  476. function remove_hook( $tag , $priority = null )
  477. {
  478. $tag = strtoupper($tag);
  479. if( is_null($priority) ) unset( $GLOBALS['TTHOOK'][$tag] );
  480. else unset( $GLOBALS['TTHOOK'][$tag][$priority] );
  481. }
  482. // This function is based on wordpress
  483. // from https://raw.github.com/WordPress/WordPress/master/wp-includes/plugin.php
  484. // requere php5.2+
  485. function build_hook_id( $tag , $function )
  486. {
  487. if ( is_string($function) )
  488. return $function;
  489. if ( is_object($function) )
  490. {
  491. // Closures are currently implemented as objects
  492. $function = array( $function, '' );
  493. }
  494. else
  495. {
  496. $function = (array) $function;
  497. }
  498. if (is_object($function[0]) )
  499. {
  500. // Object Class Calling
  501. if ( function_exists('spl_object_hash') )
  502. {
  503. return spl_object_hash($function[0]) . $function[1];
  504. }
  505. else
  506. {
  507. return substr( serialize($function[0]) , 0 , 15 ). $function[1];
  508. }
  509. }
  510. elseif( is_string($function[0]) )
  511. {
  512. // Static Calling
  513. return $function[0].$function[1];
  514. }
  515. }
  516. // =================================================
  517. // make mentions
  518. // =================================================
  519. function member_info()
  520. {
  521. if( !isset($GLOBALS['TT_MEMBER_INFO']) )
  522. {
  523. $sql = "SELECT `id` as `uid` , `name` FROM `user` WHERE `level` > 0 AND `is_closed` != 1 ";
  524. if($data = get_data($sql))
  525. {
  526. foreach( $data as $item )
  527. {
  528. $name = trim($item['name']);
  529. $GLOBALS['TT_MEMBER_INFO']['@'.$name] =
  530. '<a href="javascript:void(0);" uid=' . $item['uid'] . ' class="namecard">'. '@'.$name .'</a>';
  531. if(c('at_short_name'))
  532. if( mb_strlen( $name , 'UTF-8' ) == 3 )
  533. $GLOBALS['TT_MEMBER_INFO']['@'.mb_substr($name , 1 , 2 , 'UTF-8' )] =
  534. '<a href="javascript:void(0);" uid=' . $item['uid'] . ' class="namecard">'. '@'.mb_substr($name , 1 , 2 , 'UTF-8' ).'</a>';
  535. }
  536. }
  537. }
  538. return $GLOBALS['TT_MEMBER_INFO'];
  539. }
  540. function link_at( $str )
  541. {
  542. $to_replace = array_keys( member_info() );
  543. $replace_to = array_values( member_info() );
  544. return str_replace( $to_replace , $replace_to , $str );
  545. }
  546. function scan_plugin_info()
  547. {
  548. if( file_exists( c('plugin_path') ) )
  549. foreach( glob( c('plugin_path') . DS . "*" , GLOB_ONLYDIR ) as $pfold )
  550. {
  551. $app_file = $pfold .DS .'app.php';
  552. if( file_exists( $app_file ) )
  553. if($pinfo = get_plugin_info( file_get_contents( $app_file ) ))
  554. $plist[] = $pinfo;
  555. }
  556. return isset( $plist ) ? $plist : false;
  557. }
  558. function get_plugin_info( $content )
  559. {
  560. $reg = '/\*\*\*\s+(.+)\s+\*\*\*/is';
  561. if( preg_match( $reg , $content , $out ) )
  562. {
  563. $info_content = $out[1];
  564. $lines = explode('##',$info_content);
  565. array_shift($lines);
  566. foreach( $lines as $line )
  567. {
  568. $line = trim($line);
  569. list( $key , $value ) = explode( ' ' , $line , 2 );
  570. $ret[$key] = z(t($value));
  571. }
  572. if( isset($ret) )return $ret;
  573. }
  574. return false;
  575. }
  576. function array_remove( $value , $array )
  577. {
  578. return array_diff($array, array($value));
  579. }
  580. ?>