|
Function isMobile ($ mobile ){
Return preg_match ("/^ (? : 13d | 14d | 15d | 18 [0123456789])-? D {5} (d {3} | * {3}) $/", $ mobile );
}
Function isEmail ($ email ){
Return strlen ($ email)> 6 & preg_match ("/^ [w-.] + @ [w-.] + (. w +) + $/", $ email );
}
/**
* HTTP request sending method. Currently, only CURL requests can be sent.
* @ Param string $ url request URL
* @ Param array $ params Request Parameters
* @ Param string $ method Request method GET/POST
* @ Return array $ data response data
*/
Function http ($ url, $ params, $ method = 'get', $ header = array (), $ multi = false ){
$ Opts = array (
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTPHEADER => $ header
);
/* Set specific parameters based on the request type */
Switch (strtoupper ($ method )){
Case 'get ':
$ Opts [CURLOPT_URL] = $ url .'? '. Http_build_query ($ params );
Break;
Case 'post ':
// Determine whether a file is transmitted
// $ Params = $ multi? $ Params: http_build_query ($ params );
$ Opts [CURLOPT_URL] = $ url;
$ Opts [CURLOPT_POST] = 1;
$ Opts [CURLOPT_POSTFIELDS] = $ params;
Break;
Default:
Throw new Exception ('unsupported request method! ');
}
/* Initialize and execute the curl Request */
$ Ch = curl_init ();
Curl_setopt_array ($ ch, $ opts );
$ Data = curl_exec ($ ch );
$ Error = curl_error ($ ch );
Curl_close ($ ch );
If ($ error) throw new Exception ('request error: '. $ error );
Return $ data;
}
/**
* Do not escape Chinese characters and/json encoding methods
* @ Param array $ array to be encoded
* @ Return string
*/
Function jsencode ($ arr ){
$ Str = str_replace ("\/", "/", json_encode ($ arr ));
$ Search = "# \ u ([0-9a-f] +) # ie ";
If (strpos (strtoupper (PHP_ OS), 'win') === false ){
$ Replace = "iconv ('ucs-2be ', 'utf-8', pack ('h4', '\ 1')"; // LINUX
} Else {
$ Replace = "iconv ('ucos-2', 'utf-8', pack ('h4 ',' \ 1')"; // WINDOWS
}
Return preg_replace ($ search, $ replace, $ str );
}
// Save data to a file
Function data2file ($ filename, $ arr = ''){
If (is_array ($ arr )){
$ Con = var_export ($ arr, true );
$ Con =" ";
} Else {
$ Con = $ arr;
$ Con =" ";
}
Write_file ($ filename, $ con );
}
/**
* System encryption method
* @ Param string $ string to be encrypted by data
* @ Param string $ key encryption key
* @ Param int $ expire expiration time in seconds
* @ Return string
* @ Author winky
*/
Function encrypt ($ data, $ key = '', $ expire = 0 ){
$ Key = md5 (empty ($ key )? C ('data _ AUTH_KEY '): $ key );
$ Data = base64_encode ($ data );
$ X = 0;
$ Len = strlen ($ data );
$ L = strlen ($ key );
$ Char = '';
For ($ I = 0; $ I <$ len; $ I ++ ){
If ($ x = $ l) $ x = 0;
$ Char. = substr ($ key, $ x, 1 );
$ X ++;
}
$ Str = sprintf ('% 010d', $ expire? $ Expire + time (): 0 );
For ($ I = 0; $ I <$ len; $ I ++ ){
$ Str. = chr (ord (substr ($ data, $ I, 1) + (ord (substr ($ char, $ I, 1) % 256 );
}
Return str_replace (array ('+', '/', '='), array ('-', '_', ''), base64_encode ($ str ));
}
/**
* System Decryption Method
* @ Param string $ string to be decrypted by data (it must be a string encrypted by the encrypt method)
* @ Param string $ key encryption key
* @ Return string
* @ Author winky
*/
Function decrypt ($ data, $ key = ''){
$ Key = md5 (empty ($ key )? C ('data _ AUTH_KEY '): $ key );
$ Data = str_replace (array ('-', '_'), array ('+', '/'), $ data );
$ Mod4 = strlen ($ data) % 4;
If ($ mod4 ){
$ Data. = substr ('====', $ mod4 );
}
$ Data = base64_decode ($ data );
$ Expire = substr ($ data, 0, 10 );
$ Data = substr ($ data, 10 );
If ($ expire> 0 & $ expire <time ()){
Return '';
}
$ X = 0;
$ Len = strlen ($ data );
$ L = strlen ($ key );
$ Char = $ str = '';
For ($ I = 0; $ I <$ len; $ I ++ ){
If ($ x = $ l) $ x = 0;
$ Char. = substr ($ key, $ x, 1 );
$ X ++;
}
For ($ I = 0; $ I <$ len; $ I ++ ){
If (ord (substr ($ data, $ I, 1 )) $ Str. = chr (ord (substr ($ data, $ I, 1) + 256)-ord (substr ($ char, $ I, 1 )));
} Else {
$ Str. = chr (ord (substr ($ data, $ I, 1)-ord (substr ($ char, $ I, 1 )));
}
}
Return base64_decode ($ str );
}
Function getTaskStatusStr ($ status = 0, $ type = 'application', $ company = ''){
If ($ type = 'comment') return 'has not been evaluated ';
Switch ($ status ){
Case 0:
Return $ type = 'application '? 'Submitted task requests': $ company. 'You have been invited to the task ';
Break;
Case 1:
Return $ type = 'application '? 'Application accepted by the enterprise ': 'invitation accepted by the enterprise ';
Break;
Case 2:
Return $ type = 'application '? 'Your application has been ignored by the enterprise ': 'You have ignored the invitation by the enterprise ';
Break;
Case 3:
Return $ type = 'application '? 'You have completed this task': 'This task has been completed ';
Break;
Default:
Return 'unknown status ';
Break;
}
}
Function getArea ($ cache = true ){
$ Area = S ('s _ Area ');
If (empty ($ area) |! $ Cache ){
// The cache does not exist or parameters are read from the cache.
$ AreaModel = D ('region ');
$ Area = $ areaModel-> where ('status = 3')-> order ('sort, itemid')-> getField ('itemid, title, pid, arrparentid, child ');
// Provincial the city
Foreach ($ area as $ k => $ v ){
// If it is a top-level
If ($ v ['pid '] = 0 ){
$ Arestmr [$ v ['itemid'] ['itemid'] = $ v ['itemid'];
$ Arestmr [$ v ['itemid'] ['title'] = $ v ['title'];
$ Aresponr [$ v ['itemid'] ['pid'] = $ v ['pid'];
$ Aresponr [$ v ['itemid'] ['arrparentid'] = $ v ['arrparentid'];
$ Aresponr [$ v ['itemid'] ['child '] = $ v ['child'];
// Superior
$ Areitemr [$ v ['itemid'] ['upitemid'] = $ v ['itemid'];
$ AreaArr [$ v ['itemid'] ['uptitle'] = $ v ['title'];
}
// Find the superior name and ID
Else {
$ Arestmr [$ v ['itemid'] ['itemid'] = $ v ['itemid'];
$ Arestmr [$ v ['itemid'] ['title'] = $ v ['title'];
$ Aresponr [$ v ['itemid'] ['pid'] = $ v ['pid'];
$ Aresponr [$ v ['itemid'] ['arrparentid'] = $ v ['arrparentid'];
$ Aresponr [$ v ['itemid'] ['child '] = $ v ['child'];
// Superior
$ Arestmr [$ v ['itemid'] ['upitemid'] = $ area [$ v ['pid'] ['itemid'];
$ AreaArr [$ v ['itemid'] ['uptitle'] = $ area [$ v ['pid'] ['title'];
}
}
$ Area = $ arew.r;
S ('s _ Area ', $ area );
}
Return $ area;
}
?> |