PageRenderTime 99ms CodeModel.GetById 40ms app.highlight 32ms RepoModel.GetById 18ms 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
  1<?php
  2if( !defined('SAE_TMP_PATH') )
  3{
  4    @mkdir( AROOT . DS . 'tmp');
  5    define('SAE_TMP_PATH', AROOT . DS . 'tmp' . DS );
  6}
  7
  8function not_empty( $str )
  9{
 10	return strlen( $str ) > 0;
 11}
 12
 13// From aoihome.sinaapp.com/fun via Aoi [is_email]
 14function is_email( $email )
 15{
 16	return filter_var( $email , FILTER_VALIDATE_EMAIL );
 17}
 18
 19function on_sae()
 20{
 21    return defined('SAE_ACCESSKEY') && (substr( SAE_ACCESSKEY , 0 , 4 ) != 'kapp') ;
 22}
 23
 24
 25function is_installed()
 26{
 27    return mysql_query("SHOW COLUMNS FROM `user`",db());
 28}
 29
 30function kset( $key , $value )
 31{
 32    $sql = "REPLACE INTO `keyvalue` ( `key` , `value` ) VALUES ( '" . s($key) . "' , '" . s($value) . "' )";
 33    run_sql( $sql );
 34}
 35
 36function kget( $key )
 37{
 38    return get_var( "SELECT `value` FROM `keyvalue` WHERE `key` = '" . s($key) . "' LIMIT 1" );
 39}
 40
 41function kdel( $key )
 42{
 43    $sql = "DELETE FROM `keyvalue` WHERE `key` = '" . s($key) . "' LIMIT 1" ;
 44    run_sql($sql);
 45}
 46
 47function local_version()
 48{
 49    return intval(file_get_contents(AROOT.'version.txt'));
 50}
 51
 52function db_init()
 53{
 54    
 55    $password = substr( md5( time().rand(1,9999) ) , rand( 1 , 20 ) , 12   );
 56    
 57    $sql_contents = preg_replace( "/(#.+[\r|\n]*)/" , '' , file_get_contents( AROOT . 'misc' . DS . 'install.sql'));
 58
 59    // 更换变量
 60    $sql_contents = str_replace( '{password}' , md5($password) , $sql_contents );
 61
 62    $sqls = split_sql_file( $sql_contents );
 63    foreach ($sqls as $sql) 
 64    {
 65        run_sql( $sql );
 66    }
 67
 68    if(  db_errno() == 0 )
 69    {
 70        info_page('数据库初始化成功,请使用【member@teamtoy.net】和【' . $password . '】<a href="/" target="new">登入并添加用户</a>');
 71        exit;
 72    }
 73    else
 74    {
 75        info_page( db_error() );
 76        exit;
 77    } 
 78        
 79    
 80}
 81
 82function split_sql_file($sql, $delimiter = ';') 
 83{
 84    $sql               = trim($sql);
 85    $char              = '';
 86    $last_char         = '';
 87    $ret               = array();
 88    $string_start      = '';
 89    $in_string         = FALSE;
 90    $escaped_backslash = FALSE;
 91
 92    for ($i = 0; $i < strlen($sql); ++$i) {
 93            $char = $sql[$i];
 94
 95            // if delimiter found, add the parsed part to the returned array
 96            if ($char == $delimiter && !$in_string) {
 97                    $ret[]     = substr($sql, 0, $i);
 98                    $sql       = substr($sql, $i + 1);
 99                    $i         = 0;
100                    $last_char = '';
101            }
102
103            if ($in_string) {
104                    // We are in a string, first check for escaped backslashes
105                    if ($char == '\\') {
106                            if ($last_char != '\\') {
107                                    $escaped_backslash = FALSE;
108                            } else {
109                                    $escaped_backslash = !$escaped_backslash;
110                            }
111                    }
112                    // then check for not escaped end of strings except for
113                    // backquotes than cannot be escaped
114                    if (($char == $string_start)
115                            && ($char == '`' || !(($last_char == '\\') && !$escaped_backslash))) {
116                            $in_string    = FALSE;
117                            $string_start = '';
118                    }
119            } else {
120                    // we are not in a string, check for start of strings
121                    if (($char == '"') || ($char == '\'') || ($char == '`')) {
122                            $in_string    = TRUE;
123                            $string_start = $char;
124                    }
125            }
126            $last_char = $char;
127    } // end for
128
129    // add any rest to the returned array
130    if (!empty($sql)) {
131            $ret[] = $sql;
132    }
133    return $ret;
134}
135
136function is_login()
137{
138	return $_SESSION['level'] > 0;
139}
140
141function is_admin()
142{
143    return $_SESSION['level'] == 9;
144}
145
146function uid()
147{
148	return intval($_SESSION['uid']);
149}
150
151function uname()
152{
153	return t($_SESSION['uname']);
154}
155
156function forward( $url )
157{
158	header( "Location: " . $url );
159}
160
161function jsforword( $url )
162{
163	return '<script>location="' . $url . '"</script>';
164}
165
166function image( $filename )
167{
168	return 'static/image/' . $filename;
169}
170
171function avatar( $url )
172{
173	if( strlen($url) < 1 ) return c('default_avatar');
174	else return $url;
175}
176
177function ctime( $timeline )
178{
179    $time = strtotime($timeline);
180    if( time() > ($time+60*60*24*300) )return date("Y年n月j日 H:i",$time);
181    elseif( time() > ($time+60*60*8) ) return date("n月j日 H:i",$time);
182    else return date("H:i:s",$time);
183}
184
185/*
186function rtime( $timeline )
187{
188	return date("m月d日 H点i分" , strtotime($timeline) );
189}
190*/
191
192function rtime( $time = false, $limit = 86400, $format = 'm月d日 H点i分') 
193{
194	$time = strtotime($time);
195
196	$now = time();
197	$relative = '';
198
199	if ($time === $now) $relative = '刚刚';
200	elseif ($time > $now) $relative = '以后';
201	else 
202	{
203		$diff = $now - $time;
204
205		if ($diff >= $limit) $relative = date($format, $time);
206
207		elseif ($diff < 60) 
208		{
209			$relative = '不到一分钟';
210		}
211		elseif (($minutes = ceil($diff/60)) < 60)
212		{
213			$relative = $minutes.'分钟'.(((int)$minutes === 1) ? '' : '').'前';
214		}
215		else
216		{
217			$hours = ceil($diff/3600);
218			$relative = $hours.'小时'.(((int)$hours === 1) ? '' : '').'前';
219		}
220	}
221
222	return $relative;
223}
224
225function noname( $content , $name )
226{
227	$len = strlen($name);
228	if( substr( $content , 0 , $len ) == $name )
229		return substr( $content , $len  );
230	else
231		return $content;
232}
233
234function render_html( $data , $tpl )
235{
236	ob_start();
237	extract($data);
238	require( $tpl );
239	$content = ob_get_contents();
240	ob_end_clean();
241	return $content;
242	// 
243}
244
245function feed_class(  $type )
246{
247	switch( $type )
248	{
249		case 2:
250			 $class= 'todo';
251			break;
252		case 1:
253			$class= 'notice';
254			break;
255		case 3:
256			$class= 'user';
257			break;
258
259        case 4:
260            $class= 'cast';
261            break;   
262            
263		default:
264			$class = 'normal';		
265	}
266
267	return $class;
268}
269
270function device( $type )
271{
272	if( strtolower($type) == 'mobile' )
273		$ret = '<a href="http://teamtoy.net/?c=download&type=mobile" target="_blank">来自移动版</a>';
274	else
275		$ret = '<a href="http://teamtoy.net/?c=download&type=web" target="_blank">来自网页版</a>';
276	return $ret;
277}
278
279function get_device()
280{
281    if( is_mobile_request()) return 'mobile';
282    else return 'web';
283}
284
285
286// ========================================
287// client functions
288// ========================================
289
290
291function login( $email , $password )
292{
293	if($content = file_get_contents( c('api_server') . '?c=api&a=user_get_token&email=' . u($email) . '&password=' .u($password) ))
294	{
295		$data = json_decode( $content , 1 );
296		if( ($data['err_code'] == 0) && is_array( $data['data'] ) )
297			return $data['data'];
298		else
299			return false;
300	}
301	return null;
302	
303	
304}
305
306function token()
307{
308	return $_SESSION['token'];
309}
310
311function send_request( $action , $param , $token )
312{
313	require_once( AROOT . 'controller' . DS . 'api.class.php' );
314    require_once( AROOT . 'model' . DS . 'api.function.php' );
315    $GLOBALS['API_EMBED_MODE'] = 1;
316        
317    // local request
318    $bake_request = $_REQUEST;
319    $_REQUEST['c'] = 'api';
320    $_REQUEST['a'] = $action;
321    $_REQUEST['token'] = $token;
322
323    if( (is_array( $param )) && (count($param) > 0) )
324        foreach( $param as $key => $value )
325            $_REQUEST[$key] =  $value ;
326
327    $api = new apiController();
328    if( method_exists($api, $action) )
329    {
330        $content = $api->$action();
331        $_REQUEST = $bake_request;
332       
333        return $content;
334        //if($data = json_decode( $content , 1 ))
335        //return json_encode($data['data']);
336    }
337   
338    return null;
339    
340    
341    // remote request ...........
342    /*
343
344    $url = c('api_server') . '?c=api&a=' . u($action) . '&token=' . u($token) ;
345	
346	if( (is_array( $param )) && (count($param) > 0) )
347		foreach( $param as $key => $value )
348			$url .= '&' . $key . '=' . u( $value );
349	
350	
351
352	if($content = file_get_contents( $url ))
353		return $content;
354	
355	return $url;
356	*/
357}
358
359function find_at( $text )
360{
361	$reg = '/@(\S+?(?:\s|$))/is';
362	if( preg_match_all( $reg , $text , $out ) )
363		return $out[1];
364	else
365		return false;
366
367}
368
369function jpeg_up( $source , $dest )
370{
371	$img_info = @exif_read_data( $source , ANY_TAG  );
372  	switch( $img_info['Orientation'] )
373  	{
374  	  	case 6:
375  		  	$r = 270;
376  		  	break;
377                        
378          	case 3:
379                	$r = 180;
380                        break;
381                        
382          	case 8:
383                	$r = 90;
384                        break;
385                        
386          	default:
387                	$r = 0;
388  	}
389  
390  	$img_src = ImageCreateFromJPEG( $source );
391    $rotate = imagerotate($img_src, $r, 0,true);    
392	ImageJPEG($rotate,$dest);
393        
394        
395        
396}
397
398function upload_as_form( $url , $data )
399{
400    $ch = curl_init();
401    curl_setopt($ch, CURLOPT_URL, $url);
402    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
403    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
404    curl_setopt($ch, CURLOPT_POST, true);
405    curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
406    $response = curl_exec($ch);
407    return $response;
408}
409
410
411function pinyin($_string, $_code='utf8')
412{ //gbk页面可改为gb2312,其他随意填写为utf8
413        $_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". 
414                        "|chai|chan|chang|chao|che|chen|cheng|chi|chong|chou|chu|chuai|chuan|chuang|chui|chun|chuo|ci|cong|cou|cu|". 
415                        "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". 
416                        "|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". 
417                        "|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". 
418                        "|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". 
419                        "|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". 
420                        "|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". 
421                        "|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". 
422                        "|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". 
423                        "|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|". 
424                        "she|shen|sheng|shi|shou|shu|shua|shuai|shuan|shuang|shui|shun|shuo|si|song|sou|su|suan|sui|sun|suo|ta|tai|". 
425                        "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". 
426                        "|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". 
427                        "|yu|yuan|yue|yun|za|zai|zan|zang|zao|ze|zei|zen|zeng|zha|zhai|zhan|zhang|zhao|zhe|zhen|zheng|zhi|zhong|". 
428                        "zhou|zhu|zhua|zhuai|zhuan|zhuang|zhui|zhun|zhuo|zi|zong|zou|zu|zuan|zui|zun|zuo"; 
429        $_datavalue = "-20319|-20317|-20304|-20295|-20292|-20283|-20265|-20257|-20242|-20230|-20051|-20036|-20032|-20026|-20002|-19990". 
430                        "|-19986|-19982|-19976|-19805|-19784|-19775|-19774|-19763|-19756|-19751|-19746|-19741|-19739|-19728|-19725". 
431                        "|-19715|-19540|-19531|-19525|-19515|-19500|-19484|-19479|-19467|-19289|-19288|-19281|-19275|-19270|-19263". 
432                        "|-19261|-19249|-19243|-19242|-19238|-19235|-19227|-19224|-19218|-19212|-19038|-19023|-19018|-19006|-19003". 
433                        "|-18996|-18977|-18961|-18952|-18783|-18774|-18773|-18763|-18756|-18741|-18735|-18731|-18722|-18710|-18697". 
434                        "|-18696|-18526|-18518|-18501|-18490|-18478|-18463|-18448|-18447|-18446|-18239|-18237|-18231|-18220|-18211". 
435                        "|-18201|-18184|-18183|-18181|-18012|-17997|-17988|-17970|-17964|-17961|-17950|-17947|-17931|-17928|-17922". 
436                        "|-17759|-17752|-17733|-17730|-17721|-17703|-17701|-17697|-17692|-17683|-17676|-17496|-17487|-17482|-17468". 
437                        "|-17454|-17433|-17427|-17417|-17202|-17185|-16983|-16970|-16942|-16915|-16733|-16708|-16706|-16689|-16664". 
438                        "|-16657|-16647|-16474|-16470|-16465|-16459|-16452|-16448|-16433|-16429|-16427|-16423|-16419|-16412|-16407". 
439                        "|-16403|-16401|-16393|-16220|-16216|-16212|-16205|-16202|-16187|-16180|-16171|-16169|-16158|-16155|-15959". 
440                        "|-15958|-15944|-15933|-15920|-15915|-15903|-15889|-15878|-15707|-15701|-15681|-15667|-15661|-15659|-15652". 
441                        "|-15640|-15631|-15625|-15454|-15448|-15436|-15435|-15419|-15416|-15408|-15394|-15385|-15377|-15375|-15369". 
442                        "|-15363|-15362|-15183|-15180|-15165|-15158|-15153|-15150|-15149|-15144|-15143|-15141|-15140|-15139|-15128". 
443                        "|-15121|-15119|-15117|-15110|-15109|-14941|-14937|-14933|-14930|-14929|-14928|-14926|-14922|-14921|-14914". 
444                        "|-14908|-14902|-14894|-14889|-14882|-14873|-14871|-14857|-14678|-14674|-14670|-14668|-14663|-14654|-14645". 
445                        "|-14630|-14594|-14429|-14407|-14399|-14384|-14379|-14368|-14355|-14353|-14345|-14170|-14159|-14151|-14149". 
446                        "|-14145|-14140|-14137|-14135|-14125|-14123|-14122|-14112|-14109|-14099|-14097|-14094|-14092|-14090|-14087". 
447                        "|-14083|-13917|-13914|-13910|-13907|-13906|-13905|-13896|-13894|-13878|-13870|-13859|-13847|-13831|-13658". 
448                        "|-13611|-13601|-13406|-13404|-13400|-13398|-13395|-13391|-13387|-13383|-13367|-13359|-13356|-13343|-13340". 
449                        "|-13329|-13326|-13318|-13147|-13138|-13120|-13107|-13096|-13095|-13091|-13076|-13068|-13063|-13060|-12888". 
450                        "|-12875|-12871|-12860|-12858|-12852|-12849|-12838|-12831|-12829|-12812|-12802|-12607|-12597|-12594|-12585". 
451                        "|-12556|-12359|-12346|-12320|-12300|-12120|-12099|-12089|-12074|-12067|-12058|-12039|-11867|-11861|-11847". 
452                        "|-11831|-11798|-11781|-11604|-11589|-11536|-11358|-11340|-11339|-11324|-11303|-11097|-11077|-11067|-11055". 
453                        "|-11052|-11045|-11041|-11038|-11024|-11020|-11019|-11018|-11014|-10838|-10832|-10815|-10800|-10790|-10780". 
454                        "|-10764|-10587|-10544|-10533|-10519|-10331|-10329|-10328|-10322|-10315|-10309|-10307|-10296|-10281|-10274". 
455                        "|-10270|-10262|-10260|-10256|-10254"; 
456        $_tdatakey   = explode('|', $_datakey); 
457        $_tdatavalue = explode('|', $_datavalue);
458        $_data = array_combine($_tdatakey, $_tdatavalue);
459        arsort($_data); 
460        reset($_data);
461        if($_code!= 'gb2312') $_string = _u2_utf8_gb($_string); 
462        $_res = ''; 
463        for($i=0; $i<strlen($_string); $i++) { 
464                $_p = ord(substr($_string, $i, 1)); 
465                if($_p>160) { 
466                        $_q = ord(substr($_string, ++$i, 1)); $_p = $_p*256 + $_q - 65536;
467                } 
468                $_res .= _pinyin($_p, $_data); 
469        } 
470        return preg_replace("/[^a-z0-9]*/", '', $_res); 
471} 
472
473function _pinyin($_num, $_data)
474{ 
475        if($_num>0 && $_num<160 ){
476                return chr($_num);
477        }elseif($_num<-20319 || $_num>-10247){
478                return '';
479        }else{ 
480                foreach($_data as $k=>$v){ if($v<=$_num) break; } 
481                return $k; 
482        } 
483}
484
485function _u2_utf8_gb($_c)
486{ 
487        $_string = ''; 
488        if($_c < 0x80){
489                $_string .= $_c;
490        }elseif($_c < 0x800) { 
491                $_string .= chr(0xc0 | $_c>>6); 
492                $_string .= chr(0x80 | $_c & 0x3f); 
493        }elseif($_c < 0x10000){ 
494                $_string .= chr(0xe0 | $_c>>12); 
495                $_string .= chr(0x80 | $_c>>6 & 0x3f); 
496                $_string .= chr(0x80 | $_c & 0x3f); 
497        }elseif($_c < 0x200000) { 
498                $_string .= chr(0xf0 | $_c>>18); 
499                $_string .= chr(0x80 | $_c>>12 & 0x3f); 
500                $_string .= chr(0x80 | $_c>>6 & 0x3f); 
501                $_string .= chr(0x80 | $_c & 0x3f); 
502        } 
503        return iconv('utf-8', 'gb2312', $_string); 
504}
505
506// **************************************************************
507// * Plugins & hooks
508// ************************************************************** 
509function add_filter( $tag , $function_to_add , $priority = 10 , $accepted_args_num = 1 )
510{
511    return add_hook( $tag , $function_to_add , $priority , $accepted_args_num );
512}
513
514function add_action( $tag , $function_to_add , $priority = 10 , $accepted_args_num = 1 )
515{
516    return add_hook( $tag , $function_to_add , $priority , $accepted_args_num );
517}
518
519function add_hook( $tag , $function_to_add , $priority = 10 , $accepted_args_num = 1 )
520{
521    $tag = strtoupper($tag);
522    $idx = build_hook_id( $tag , $function_to_add , $priority );
523    $GLOBALS['TTHOOK'][$tag][$priority][$idx] = array( 'function' => $function_to_add , 'args_num' => $accepted_args_num );
524}
525
526function do_action( $tag , $value = null )
527{
528    return apply_hook( $tag , $value );
529}
530
531function apply_filter( $tag , $value = null )
532{
533    return apply_hook( $tag , $value );
534}
535
536
537
538function apply_hook( $tag , $value )
539{
540    $tag = strtoupper($tag);
541    if( $hooks  = has_hook( $tag ) )
542    {
543        ksort( $hooks );
544        $args = func_get_args();
545        reset( $hooks );
546
547        do
548        {
549            foreach( (array) current( $hooks ) as $hook )
550            {
551                if( !is_null($hook['function']) )
552                {
553                    $args[1] = $value;
554                    $value = call_user_func_array( $hook['function'] , array_slice($args, 1, (int) $hook['args_num']));
555                }
556            }
557        }while( next( $hooks ) !== false );
558
559    }
560
561    return $value;
562}
563
564function has_hook( $tag , $priority = null )
565{
566    $tag = strtoupper($tag);
567    if( is_null($priority) ) return isset( $GLOBALS['TTHOOK'][$tag] )? $GLOBALS['TTHOOK'][$tag]:false;
568    else return isset( $GLOBALS['TTHOOK'][$tag][$priority] )? $GLOBALS['TTHOOK'][$tag][$priority]:false;
569}
570
571function remove_hook( $tag , $priority = null )
572{
573    $tag = strtoupper($tag);
574    if( is_null($priority) ) unset( $GLOBALS['TTHOOK'][$tag] );
575    else unset( $GLOBALS['TTHOOK'][$tag][$priority] );
576}
577// This function is based on wordpress  
578// from  https://raw.github.com/WordPress/WordPress/master/wp-includes/plugin.php
579// requere php5.2+
580
581function build_hook_id( $tag , $function ) 
582{
583    if ( is_string($function) )
584        return $function;
585
586    if ( is_object($function) ) 
587    {
588        // Closures are currently implemented as objects
589        $function = array( $function, '' );
590    }
591    else
592    {
593        $function = (array) $function;
594    }
595
596    if (is_object($function[0]) ) 
597    {
598        // Object Class Calling
599        if ( function_exists('spl_object_hash') ) 
600        {
601            return spl_object_hash($function[0]) . $function[1];
602        }
603        else
604        {
605            return substr( serialize($function[0]) , 0 , 15 ). $function[1];
606        }
607
608    }
609    elseif( is_string($function[0]) )
610    {
611        // Static Calling
612        return $function[0].$function[1];
613    }
614}
615
616// =================================================
617// make mentions
618// =================================================
619function member_info()
620{
621    if( !isset($GLOBALS['TT_MEMBER_INFO']) )
622    {
623        $sql = "SELECT `id` as `uid` , `name` FROM `user` WHERE `level` > 0 AND `is_closed` != 1 ";
624        if($data = get_data($sql))
625        {
626            foreach( $data as $item )
627            {
628                $name = trim($item['name']);
629                $GLOBALS['TT_MEMBER_INFO']['@'.$name] = 
630                '<a href="javascript:void(0);" uid=' . $item['uid'] . ' class="namecard">'. '@'.$name .'</a>';
631
632                if(c('at_short_name'))
633                    if( mb_strlen( $name , 'UTF-8' ) == 3 )
634                        $GLOBALS['TT_MEMBER_INFO']['@'.mb_substr($name , 1 , 2 , 'UTF-8' )] =
635                        '<a href="javascript:void(0);" uid=' . $item['uid'] . ' class="namecard">'. '@'.mb_substr($name , 1 , 2 , 'UTF-8' ).'</a>';
636                        
637            }
638
639        }
640    }
641    return  $GLOBALS['TT_MEMBER_INFO'];
642}
643
644function link_at( $str )
645{
646    $to_replace = array_keys( member_info() );
647    $replace_to = array_values( member_info() );
648    return str_replace( $to_replace , $replace_to , $str );
649}
650
651
652function scan_plugin_info()
653{
654    if( file_exists( c('plugin_path') ) )
655    foreach( glob( c('plugin_path') . DS . "*" , GLOB_ONLYDIR ) as $pfold  )
656    {
657        $app_file = $pfold .DS .'app.php';
658        if( file_exists( $app_file ) )
659            if($pinfo = get_plugin_info( file_get_contents( $app_file ) ))
660            $plist[] = $pinfo;
661    }
662    return isset( $plist ) ? $plist : false;
663}
664
665function get_plugin_info( $content )
666{
667    $reg = '/\*\*\*\s+(.+)\s+\*\*\*/is';
668    if( preg_match( $reg , $content , $out ) )
669    {
670        $info_content = $out[1];
671        $lines = explode('##',$info_content);
672        array_shift($lines);
673        foreach( $lines as $line )
674        {
675            $line = trim($line);
676            list( $key , $value ) = explode( ' ' , $line , 2 );
677            $ret[$key] = z(t($value)); 
678        }
679
680        if( isset($ret) )return $ret;
681
682    }
683
684    return false;
685}
686
687function array_remove( $value , $array )
688{
689    return array_diff($array, array($value));
690}
691
692
693?>