| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489 |
- <?php
- // +----------------------------------------------------------------------
- // | Fanwe 方维直播系统
- // +----------------------------------------------------------------------
- // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Author: 云淡风轻(1956838968@qq.com)
- // +----------------------------------------------------------------------
- //前后台加载的函数库
- //获取真实路径
- function get_real_path()
- {
- return APP_ROOT_PATH;
- }
- //获取GMTime
- function get_gmtime()
- {
- return (time() - date('Z'));
- }
- function to_date($utc_time, $format = 'Y-m-d H:i:s') {
- if (empty ( $utc_time )) {
- return '';
- }
- $timezone = intval(app_conf('TIME_ZONE'));
- $time = $utc_time + $timezone * 3600;
- return date ($format, $time );
- }
- function to_timespan($str, $format = 'Y-m-d H:i:s')
- {
- $timezone = intval(app_conf('TIME_ZONE'));
- //$timezone = 8;
- $time = intval(strtotime($str));
- if($time!=0)
- $time = $time - $timezone * 3600;
- return $time;
- }
- //获取客户端IP
- function get_client_ip() {
- if (getenv ( "HTTP_CLIENT_IP" ) && strcasecmp ( getenv ( "HTTP_CLIENT_IP" ), "unknown" ))
- $ip = getenv ( "HTTP_CLIENT_IP" );
- else if (getenv ( "HTTP_X_FORWARDED_FOR" ) && strcasecmp ( getenv ( "HTTP_X_FORWARDED_FOR" ), "unknown" ))
- $ip = getenv ( "HTTP_X_FORWARDED_FOR" );
- else if (getenv ( "REMOTE_ADDR" ) && strcasecmp ( getenv ( "REMOTE_ADDR" ), "unknown" ))
- $ip = getenv ( "REMOTE_ADDR" );
- else if (isset ( $_SERVER ['REMOTE_ADDR'] ) && $_SERVER ['REMOTE_ADDR'] && strcasecmp ( $_SERVER ['REMOTE_ADDR'], "unknown" ))
- $ip = $_SERVER ['REMOTE_ADDR'];
- else
- $ip = "unknown";
- return ($ip);
- }
- //过滤注入
- function filter_injection(&$request)
- {
- $pattern = "/(select[\s])|(insert[\s])|(update[\s])|(delete[\s])|(from[\s])|(where[\s])/i";
- foreach($request as $k=>$v)
- {
- if(preg_match($pattern,$k,$match))
- {
- die("SQL Injection denied!");
- }
- if(is_array($v))
- {
- filter_injection($request[$k]);
- }
- else
- {
- if(preg_match($pattern,$v,$match))
- {
- die("SQL Injection denied!");
- }
- }
- }
- }
- function filter_ma_request(&$str){
- $search = array("../","\n","\r","\t","\r\n","'","<",">","\"","%","\\",".","/");
- return str_replace($search,"",$str);
- }
- //过滤请求
- function filter_request(&$request)
- {
- if(MAGIC_QUOTES_GPC)
- {
- foreach($request as $k=>$v)
- {
- if(is_array($v))
- {
- filter_request($v);
- }
- else
- {
- $request[$k] = stripslashes(trim($v));
- }
- }
- }
- }
- function adddeepslashes(&$request)
- {
- foreach($request as $k=>$v)
- {
- if(is_array($v))
- {
- adddeepslashes($v);
- }
- else
- {
- $request[$k] = addslashes(trim($v));
- }
- }
- }
- function quotes($content)
- {
- //if $content is an array
- if (is_array($content))
- {
- foreach ($content as $key=>$value)
- {
- //$content[$key] = mysql_real_escape_string($value);
- $content[$key] = addslashes($value);
- }
- } else
- {
- //if $content is not an array
- //$content=mysql_real_escape_string($content);
- $content=addslashes($content);
- }
- return $content;
- }
- //request转码
- function convert_req(&$req)
- {
- foreach($req as $k=>$v)
- {
- if(is_array($v))
- {
- convert_req($req[$k]);
- }
- else
- {
- if(!is_u8($v))
- {
- $req[$k] = iconv("gbk","utf-8",$v);
- }
- }
- }
- }
- function is_u8($string)
- {
- return preg_match('%^(?:
- [\x09\x0A\x0D\x20-\x7E] # ASCII
- | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
- | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
- | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
- | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
- | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
- | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
- | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
- )*$%xs', $string);
- }
- //清除缓存
- function clear_cache()
- {
- //系统后台缓存
- clear_dir_file(get_real_path()."public/runtime/admin/Cache/");
- clear_dir_file(get_real_path()."public/runtime/admin/Data/_fields/");
- clear_dir_file(get_real_path()."public/runtime/admin/Temp/");
- clear_dir_file(get_real_path()."public/runtime/admin/Logs/");
- @unlink(get_real_path()."public/runtime/admin/~app.php");
- @unlink(get_real_path()."public/runtime/admin/~runtime.php");
- @unlink(get_real_path()."public/runtime/admin/lang.js");
- @unlink(get_real_path()."public/runtime/app/config_cache.php");
- //数据缓存
- clear_dir_file(get_real_path()."public/runtime/app/data_caches/");
- clear_dir_file(get_real_path()."public/runtime/app/db_caches/");
- $GLOBALS['cache']->clear();
- clear_dir_file(get_real_path()."public/runtime/data/");
- //模板页面缓存
- clear_dir_file(get_real_path()."public/runtime/app/tpl_caches/");
- clear_dir_file(get_real_path()."public/runtime/app/tpl_compiled/");
- @unlink(get_real_path()."public/runtime/app/lang.js");
- //脚本缓存
- clear_dir_file(get_real_path()."public/runtime/statics/");
- }
- function clear_dir_file($path)
- {
- if ( $dir = opendir( $path ) )
- {
- while ( $file = readdir( $dir ) )
- {
- $check = is_dir( $path. $file );
- if ( !$check )
- {
- @unlink( $path . $file );
- }
- else
- {
- if($file!='.'&&$file!='..')
- {
- clear_dir_file($path.$file."/");
- }
- }
- }
- closedir( $dir );
- rmdir($path);
- return true;
- }
- }
- function check_install()
- {
- if(!file_exists(get_real_path()."public/install.lock"))
- {
- clear_cache();
- header('Location:'.APP_ROOT.'/install');
- exit;
- }
- }
- //utf8 字符串截取
- function msubstr($str, $start=0, $length=15, $charset="utf-8", $suffix=true)
- {
- if(function_exists("mb_substr"))
- {
- $slice = mb_substr($str, $start, $length, $charset);
- if($suffix&$slice!=$str) return $slice."…";
- return $slice;
- }
- elseif(function_exists('iconv_substr')) {
- return iconv_substr($str,$start,$length,$charset);
- }
- $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
- $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
- $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
- $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
- preg_match_all($re[$charset], $str, $match);
- $slice = join("",array_slice($match[0], $start, $length));
- if($suffix&&$slice!=$str) return $slice."…";
- return $slice;
- }
- //字符编码转换
- if(!function_exists("iconv"))
- {
- function iconv($in_charset,$out_charset,$str)
- {
- require 'libs/iconv.php';
- $chinese = new Chinese();
- return $chinese->Convert($in_charset,$out_charset,$str);
- }
- }
- //JSON兼容
- if(!function_exists("json_encode"))
- {
- function json_encode($data)
- {
- require_once 'libs/json.php';
- $JSON = new JSON();
- return $JSON->encode($data);
- }
- }
- if(!function_exists("json_decode"))
- {
- function json_decode($data)
- {
- require_once 'libs/json.php';
- $JSON = new JSON();
- return $JSON->decode($data,1);
- }
- }
- //邮件格式验证的函数
- function check_email($email)
- {
- if(!preg_match("/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/",$email))
- {
- return false;
- }
- else
- return true;
- }
- /*显示隐藏中间的手机号码*/
- function hideMobile($mobile){
- if($mobile!="")
- return preg_replace('#(\d{3})\d{5}(\d{3})#', '${1}*****${2}',$mobile);
- else
- return "";
- }
- /*显示隐藏中间的邮箱号*/
- function hideEmail($email){
- if($email!="")
- {
- return substr($email,0,-8)."*****".substr($email,-3);
- }
- else
- {
- return "";
- }
- }
- //验证手机号码
- function check_mobile($mobile)
- {
- if(!empty($mobile) && !preg_match("/^(1[0-9]{10})?$/",$mobile))
- {
- return false;
- }
- else
- return true;
- }
- //验证邮编
- function check_postcode($postcode)
- {
- if(!empty($postcode) && !preg_match("/^([0-9]{6})(-[0-9]{5})?$/",$postcode))
- {
- return false;
- }
- else
- return true;
- }
- //验证验证码
- function check_verify_coder($verify_coder){
- if(!empty($verify_coder) && !preg_match("/^([0-9]{6})?$/",$verify_coder))
- {
- return false;
- }
- else
- return true;
- }
- function get_verify_code($verify_coder){
- $verify_coder_result = check_user("verify_coder",$verify_coder);
- //var_dump($verify_coder_result);exit;
- if($verify_coder_result['status']==0)
- {
- if($verify_coder_result['data']['error']==EMPTY_ERROR)
- {
- $error = "不能为空";
- $type = "form_tip";
- }
- if($verify_coder_result['data']['error']==EXIST_ERROR)
- {
- $error = "错误";
- $type="form_error";
- }
- return array("type"=>$type,"field"=>"verify_coder","info"=>"验证码".$error);
- }
- else
- {
- return array("type"=>"form_success","field"=>"verify_coder","info"=>"");
- }
- }
- //跳转
- function app_redirect($url,$time=0,$msg='')
- {
- //多行URL地址支持
- $url = str_replace(array("\n", "\r"), '', $url);
- if(empty($msg))
- $msg = "系统将在{$time}秒之后自动跳转到{$url}!";
- if (!headers_sent()) {
- // redirect
- if(0===$time) {
- if(substr($url,0,1)=="/")
- {
- header("Location:".get_domain().$url);
- }
- else
- {
- header("Location:".$url);
- }
- }else {
- header("refresh:{$time};url={$url}");
- echo($msg);
- }
- exit();
- }else {
- $str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>";
- if($time!=0)
- $str .= $msg;
- exit($str);
- }
- }
- /**
- * 验证访问IP的有效性
- * @param ip地址 $ip_str
- * @param 访问页面 $module
- * @param 时间间隔 $time_span
- * @param 数据ID $id
- */
- function check_ipop_limit($ip_str,$module,$time_span=0,$id=0)
- {
- if(intval(app_conf('USER_SUBMIT_TIME'))>0){
- $time_span = intval(app_conf('USER_SUBMIT_TIME'));
- }
- $op = es_session::get($module."_".$id."_ip");
- if(empty($op))
- {
- $check['ip'] = get_client_ip();
- $check['time'] = get_gmtime();
- es_session::set($module."_".$id."_ip",$check);
- return true; //不存在session时验证通过
- }
- else
- {
- $check['ip'] = get_client_ip();
- $check['time'] = get_gmtime();
- $origin = es_session::get($module."_".$id."_ip");
- if($check['ip']==$origin['ip'])
- {
- if($check['time'] - $origin['time'] < $time_span)
- {
- return false;
- }
- else
- {
- es_session::set($module."_".$id."_ip",$check);
- return true; //不存在session时验证通过
- }
- }
- else
- {
- es_session::set($module."_".$id."_ip",$check);
- return true; //不存在session时验证通过
- }
- }
- }
- function gzip_out($content)
- {
- header("Content-type: text/html; charset=utf-8");
- header("Cache-control: private"); //支持页面回跳
- $gzip = app_conf("GZIP_ON");
- if( intval($gzip)==1 )
- {
- if(!headers_sent()&&extension_loaded("zlib")&&preg_match("/gzip/i",$_SERVER["HTTP_ACCEPT_ENCODING"]))
- {
- $content = gzencode($content,9);
- header("Content-Encoding: gzip");
- header("Content-Length: ".strlen($content));
- echo $content;
- }
- else
- echo $content;
- }else{
- echo $content;
- }
- }
- /**
- * 保存图片
- * @param array $upd_file 即上传的$_FILES数组
- * @param array $key $_FILES 中的键名 为空则保存 $_FILES 中的所有图片
- * @param string $dir 保存到的目录
- * @param array $whs
- 可生成多个缩略图
- 数组 参数1 为宽度,
- 参数2为高度,
- 参数3为处理方式:0(缩放,默认),1(剪裁),
- 参数4为是否水印 默认为 0(不生成水印)
- array(
- 'thumb1'=>array(300,300,0,0),
- 'thumb2'=>array(100,100,0,0),
- 'origin'=>array(0,0,0,0), 宽与高为0为直接上传
- ...
- ),
- * @param array $is_water 原图是否水印
- * @return array
- array(
- 'key'=>array(
- 'name'=>图片名称,
- 'url'=>原图web路径,
- 'path'=>原图物理路径,
- 有略图时
- 'thumb'=>array(
- 'thumb1'=>array('url'=>web路径,'path'=>物理路径),
- 'thumb2'=>array('url'=>web路径,'path'=>物理路径),
- ...
- )
- )
- ....
- )
- */
- //$img = save_image_upload($_FILES,'avatar','temp',array('avatar'=>array(300,300,1,1)),1);
- function save_image_upload($upd_file, $key='',$dir='temp', $whs=array(),$is_water=false,$need_return = false)
- {
- require_once APP_ROOT_PATH."system/utils/es_imagecls.php";
- $image = new es_imagecls();
- $image->max_size = intval(app_conf("MAX_IMAGE_SIZE"));
- $list = array();
- if(empty($key))
- {
- foreach($upd_file as $fkey=>$file)
- {
- $list[$fkey] = false;
- $image->init($file,$dir);
- if($image->save())
- {
- $list[$fkey] = array();
- $list[$fkey]['url'] = $image->file['target'];
- $list[$fkey]['path'] = $image->file['local_target'];
- $list[$fkey]['name'] = $image->file['prefix'];
- }
- else
- {
- if($image->error_code==-105)
- {
- if($need_return)
- {
- return array('error'=>1,'message'=>'上传的图片太大');
- }
- else
- echo "上传的图片太大";
- }
- elseif($image->error_code==-104||$image->error_code==-103||$image->error_code==-102||$image->error_code==-101)
- {
- if($need_return)
- {
- return array('error'=>1,'message'=>'非法图像'.$image->error_code);
- }
- else
- echo "非法图像";
- }
- exit;
- }
- }
- }
- else
- {
- $list[$key] = false;
- $image->init($upd_file[$key],$dir);
- if($image->save())
- {
- $list[$key] = array();
- $list[$key]['url'] = $image->file['target'];
- $list[$key]['path'] = $image->file['local_target'];
- $list[$key]['name'] = $image->file['prefix'];
- }
- else
- {
- if($image->error_code==-105)
- {
- if($need_return)
- {
- return array('error'=>1,'message'=>'上传的图片太大');
- }
- else
- echo "上传的图片太大";
- }
- elseif($image->error_code==-104||$image->error_code==-103||$image->error_code==-102||$image->error_code==-101)
- {
- if($need_return)
- {
- return array('error'=>1,'message'=>'非法图像'.$image->error_code);
- }
- else
- echo "非法图像";
- }
- exit;
- }
- }
- $water_image = APP_ROOT_PATH.app_conf("WATER_MARK");
- $alpha = app_conf("WATER_ALPHA");
- $place = app_conf("WATER_POSITION");
- foreach($list as $lkey=>$item)
- {
- //循环生成规格图
- foreach($whs as $tkey=>$wh)
- {
- $list[$lkey]['thumb'][$tkey]['url'] = false;
- $list[$lkey]['thumb'][$tkey]['path'] = false;
- if($wh[0] > 0 || $wh[1] > 0) //有宽高度
- {
- $thumb_type = isset($wh[2]) ? intval($wh[2]) : 0; //剪裁还是缩放, 0缩放 1剪裁
- if($thumb = $image->thumb($item['path'],$wh[0],$wh[1],$thumb_type))
- {
- $list[$lkey]['thumb'][$tkey]['url'] = $thumb['url'];
- $list[$lkey]['thumb'][$tkey]['path'] = $thumb['path'];
- if(isset($wh[3]) && intval($wh[3]) > 0)//需要水印
- {
- $paths = pathinfo($list[$lkey]['thumb'][$tkey]['path']);
- $path = $paths['dirname'];
- $path = $path."/origin/";
- if (!is_dir($path)) {
- @mkdir($path);
- @chmod($path, 0777);
- }
- $filename = $paths['basename'];
- @file_put_contents($path.$filename,@file_get_contents($list[$lkey]['thumb'][$tkey]['path']));
- $image->water($list[$lkey]['thumb'][$tkey]['path'],$water_image,$alpha, $place);
- }
- }
- }
- }
- if($is_water)
- {
- $paths = pathinfo($item['path']);
- $path = $paths['dirname'];
- $path = $path."/origin/";
- if (!is_dir($path)) {
- @mkdir($path);
- @chmod($path, 0777);
- }
- $filename = $paths['basename'];
- @file_put_contents($path.$filename,@file_get_contents($item['path']));
- $image->water($item['path'],$water_image,$alpha, $place);
- }
- }
- return $list;
- }
- function empty_tag($string)
- {
- $string = preg_replace(array("/\[img\]\d+\[\/img\]/","/\[[^\]]+\]/"),array("",""),$string);
- if(trim($string)=='')
- return $GLOBALS['lang']['ONLY_IMG'];
- else
- return $string;
- //$string = str_replace(array("[img]","[/img]"),array("",""),$string);
- }
- /**
- * utf8字符转Unicode字符
- * @param string $char 要转换的单字符
- * @return void
- */
- function utf8_to_unicode($char)
- {
- switch(strlen($char))
- {
- case 1:
- return ord($char);
- case 2:
- $n = (ord($char[0]) & 0x3f) << 6;
- $n += ord($char[1]) & 0x3f;
- return $n;
- case 3:
- $n = (ord($char[0]) & 0x1f) << 12;
- $n += (ord($char[1]) & 0x3f) << 6;
- $n += ord($char[2]) & 0x3f;
- return $n;
- case 4:
- $n = (ord($char[0]) & 0x0f) << 18;
- $n += (ord($char[1]) & 0x3f) << 12;
- $n += (ord($char[2]) & 0x3f) << 6;
- $n += ord($char[3]) & 0x3f;
- return $n;
- }
- }
- /**
- * utf8字符串分隔为unicode字符串
- * @param string $str 要转换的字符串
- * @param string $depart 分隔,默认为空格为单字
- * @return string
- */
- function str_to_unicode_word($str,$depart=' ')
- {
- $arr = array();
- $str_len = mb_strlen($str,'utf-8');
- for($i = 0;$i < $str_len;$i++)
- {
- $s = mb_substr($str,$i,1,'utf-8');
- if($s != ' ' && $s != ' ')
- {
- $arr[] = 'ux'.utf8_to_unicode($s);
- }
- }
- return implode($depart,$arr);
- }
- /**
- * utf8字符串分隔为unicode字符串
- * @param string $str 要转换的字符串
- * @return string
- */
- function str_to_unicode_string($str)
- {
- $string = str_to_unicode_word($str,'');
- return $string;
- }
- //分词
- function div_str($str)
- {
- require_once APP_ROOT_PATH."system/libs/words.php";
- $words = words::segment($str);
- $words[] = $str;
- return $words;
- }
- /**
- *
- * @param $tag //要插入的关键词
- * @param $table //表名
- * @param $id //数据ID
- * @param $field // tag_match/name_match/cate_match/locate_match
- */
- function insert_match_item($tag,$table,$id,$field)
- {
- if($tag=='')
- return;
- $unicode_tag = str_to_unicode_string($tag);
- $sql = "select count(*) from ".DB_PREFIX.$table." where match(".$field.") against ('".$unicode_tag."' IN BOOLEAN MODE) and id = ".$id;
- $rs = $GLOBALS['db']->getOne($sql);
- if(intval($rs) == 0)
- {
- $match_row = $GLOBALS['db']->getRow("select * from ".DB_PREFIX.$table." where id = ".$id);
- if($match_row[$field]=="")
- {
- $match_row[$field] = $unicode_tag;
- $match_row[$field."_row"] = $tag;
- }
- else
- {
- $match_row[$field] = $match_row[$field].",".$unicode_tag;
- $match_row[$field."_row"] = $match_row[$field."_row"].",".$tag;
- }
- $GLOBALS['db']->autoExecute(DB_PREFIX.$table, $match_row, $mode = 'UPDATE', "id=".$id, $querymode = 'SILENT');
- }
- }
- //封装url
- function url($route="index",$param=array())
- {
- $key = md5("URL_KEY_".$route.serialize($param));
- if(isset($GLOBALS[$key]))
- {
- $url = $GLOBALS[$key];
- return $url;
- }
- $url = load_dynamic_cache($key);
- if($url!==false)
- {
- $GLOBALS[$key] = $url;
- return $url;
- }
- $route_array = explode("#",$route);
- if(isset($param)&&$param!=''&&!is_array($param))
- {
- $param['id'] = $param;
- }
- $module = strtolower(trim($route_array[0]));
- $action = strtolower(trim($route_array[1]));
- if(!$module||$module=='index')$module="";
- if(!$action||$action=='index')$action="";
- if(true )
- {
- //原始模式
- $url = APP_ROOT."/index.php";
- if($module!=''||$action!=''||count($param)>0) //有后缀参数
- {
- $url.="?";
- }
- if($module&&$module!='')
- $url .= CTL."=".$module."&";
- if($action&&$action!='')
- $url .= ACT."=".$action."&";
- if(count($param)>0)
- {
- foreach($param as $k=>$v)
- {
- if($k&&$v)
- $url =$url.$k."=".urlencode($v)."&";
- }
- }
- if(substr($url,-1,1)=='&'||substr($url,-1,1)=='?') $url = substr($url,0,-1);
- $GLOBALS[$key] = $url;
- set_dynamic_cache($key,$url);
- return $url;
- }
- else
- {
- //重写的默认
- $url = APP_ROOT;
- if($module==''&&$action==''){
- $url .='/index';
- }else{
- if($module&&$module!='')
- $url .= "/".$module;
- if($action&&$action!='')
- $url .= "-".$action;
- }
- if(count($param)>0)
- {
- $url.="/";
- foreach($param as $k=>$v)
- {
- $url =$url.$k."-".urlencode($v)."-";
- }
- }
- $route = $module."#".$action;
- switch ($route)
- {
- case "xxx":
- break;
- default:
- break;
- }
- // if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-'){
- // $url.='index';
- // }
- if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-') $url = substr($url,0,-1);
- $url=trim($url);
- if($url==''){
- $url="/index.html";
- }else{
- if($module=='article_cate'){
- if($param['id']){
- if($GLOBALS['article_cates'][$param['id']]['seo_title']){
- if($param['p']){
- $url=APP_ROOT."/".$GLOBALS['article_cates'][$param['id']]['seo_title']."?p=".$param['p'];
- }else{
- $url=APP_ROOT."/".$GLOBALS['article_cates'][$param['id']]['seo_title'];
- }
- }else{
- $url.='.html';
- }
- }elseif($param['p']){
- $url=APP_ROOT."/article_cate?p=".$param['p'];
- }elseif($param['tag']){
- $url=APP_ROOT."/article_cate?tag=".$param['tag'];
- }
- else{
- $url=APP_ROOT."/article_cate";
- }
- }elseif($module=='article'){
- if($param['id']){
- if($GLOBALS['article_cates'][$GLOBALS['articles'][$param['id']]['cate_id']]['seo_title']){
- $url=APP_ROOT."/".$GLOBALS['article_cates'][$GLOBALS['articles'][$param['id']]['cate_id']]['seo_title']."/".$param['id'].".html";
- }else{
- $url.='.html';
- }
- }else{
- $url=APP_ROOT."/article_cate";
- }
- }else{
- $url.='.html';
- }
- }
- if($url=='')$url="/";
- $GLOBALS[$key] = $url;
- set_dynamic_cache($key,$url);
- return $url;
- }
- }
- function url_wap($route="index",$param=array())
- {
- if($GLOBALS['is_app']){
- $param['from_type'] = $GLOBALS['is_app'];
- }
- $key = md5("URL_WAP_KEY_".$route.serialize($param));
- if(isset($GLOBALS[$key]))
- {
- $url = $GLOBALS[$key];
- return $url;
- }
- $url = load_dynamic_cache($key);
- if($url!==false)
- {
- $GLOBALS[$key] = $url;
- return $url;
- }
- $route_array = explode("#",$route);
- if(isset($param)&&$param!=''&&!is_array($param))
- {
- $param['id'] = $param;
- }
- $module = strtolower(trim($route_array[0]));
- $action = strtolower(trim($route_array[1]));
- if(!$module||$module=='index')$module="";
- if(!$action||$action=='index')$action="";
- if(true)
- {
- //原始模式
- $url = APP_ROOT."/wap/index.php";
- if($module!=''||$action!=''||count($param)>0) //有后缀参数
- {
- $url.="?";
- }
- if($module&&$module!='')
- $url .= "ctl=".$module."&";
- if($action&&$action!='')
- $url .= "act=".$action."&";
- if(count($param)>0)
- {
- foreach($param as $k=>$v)
- {
- if($k&&$v)
- $url =$url.$k."=".urlencode($v)."&";
- }
- }
- if(substr($url,-1,1)=='&'||substr($url,-1,1)=='?') $url = substr($url,0,-1);
- $GLOBALS[$key] = $url;
- set_dynamic_cache($key,$url);
- return $url;
- }
- else
- {
- //重写的默认
- $url = APP_ROOT."/wap";
- if($module&&$module!='')
- $url .= "/".$module;
- if($action&&$action!='')
- $url .= "-".$action;
- if(count($param)>0)
- {
- $url.="/";
- foreach($param as $k=>$v)
- {
- $url =$url.$k."-".urlencode($v)."-";
- }
- }
- $route = $module."#".$action;
- switch ($route)
- {
- case "xxx":
- break;
- default:
- break;
- }
- if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-') $url = substr($url,0,-1);
- if($url=='')$url="/";
- $GLOBALS[$key] = $url;
- set_dynamic_cache($key,$url);
- return $url;
- }
- }
- //封装url
- function url_mapi($route="index",$param=array())
- {
- $key = md5("URL_APP_KEY_".$route.serialize($param));
- if(isset($GLOBALS[$key]))
- {
- $url = $GLOBALS[$key];
- return $url;
- }
- $url = load_dynamic_cache($key);
- if($url!==false)
- {
- $GLOBALS[$key] = $url;
- return $url;
- }
- $route_array = explode("#",$route);
- if(isset($param)&&$param!=''&&!is_array($param))
- {
- $param['id'] = $param;
- }
- $module = strtolower(trim($route_array[0]));
- $action = strtolower(trim($route_array[1]));
- if(!$module||$module=='index')$module="";
- if(!$action||$action=='index')$action="";
- if(app_conf("URL_MODEL")==0)
- {
- //原始模式
- $url = APP_ROOT."/index.php";
- if($module!=''||$action!=''||count($param)>0) //有后缀参数
- {
- $url.="?";
- }
- if($module&&$module!='')
- $url .= "ctl=".$module."&";
- if($action&&$action!='')
- $url .= "act=".$action."&";
- if(count($param)>0)
- {
- foreach($param as $k=>$v)
- {
- if($k&&$v)
- $url =$url.$k."=".urlencode($v)."&";
- }
- }
- if(substr($url,-1,1)=='&'||substr($url,-1,1)=='?') $url = substr($url,0,-1);
- $GLOBALS[$key] = $url;
- set_dynamic_cache($key,$url);
- return $url;
- }
- else
- {
- //重写的默认
- $url = APP_ROOT;
- if($module&&$module!='')
- $url .= "/".$module;
- if($action&&$action!='')
- $url .= "-".$action;
- if(count($param)>0)
- {
- $url.="/";
- foreach($param as $k=>$v)
- {
- $url =$url.$k."-".urlencode($v)."-";
- }
- }
- $route = $module."#".$action;
- switch ($route)
- {
- case "xxx":
- break;
- default:
- break;
- }
- if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-') $url = substr($url,0,-1);
- if($url=='')$url="/";
- $GLOBALS[$key] = $url;
- set_dynamic_cache($key,$url);
- return $url;
- }
- }
- //封装app_url
- function url_app($route="index",$param=array())
- {
- $route_array = explode("#",$route);
- if(isset($param)&&$param!=''&&!is_array($param))
- {
- $param['id'] = $param;
- }
- if(isset($route_array[0])){
- $module = strtolower(trim($route_array[0]));
- }else{
- $module = "";
- }
- if(isset($route_array[1])){
- $action = strtolower(trim($route_array[1]));
- }else{
- $action = "";
- }
- if(!$module||$module=='index')$module="";
- if(!$action||$action=='index')$action="";
- if(true )
- {
- //原始模式
- $url = APP_ROOT."/index.php";
- if($module!=''||$action!=''||count($param)>0) //有后缀参数
- {
- $url.="?";
- }
- if($module&&$module!='')
- $url .= CTL."=".$module."&";
- if($action&&$action!='')
- $url .= ACT."=".$action."&";
- if(count($param)>0)
- {
- foreach($param as $k=>$v)
- {
- if($k&&$v)
- $url =$url.$k."=".urlencode($v)."&";
- }
- }
- if(substr($url,-1,1)=='&'||substr($url,-1,1)=='?') $url = substr($url,0,-1);
- return $url;
- }
- else
- {
- //重写的默认
- $url = APP_ROOT;
- if($module==''&&$action==''){
- $url .='/index';
- }else{
- if($module&&$module!='')
- $url .= "/".$module;
- if($action&&$action!='')
- $url .= "-".$action;
- }
- if(count($param)>0)
- {
- $url.="/";
- foreach($param as $k=>$v)
- {
- $url =$url.$k."-".urlencode($v)."-";
- }
- }
- $route = $module."#".$action;
- switch ($route)
- {
- case "xxx":
- break;
- default:
- break;
- }
- if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-') $url = substr($url,0,-1);
- $url=trim($url);
- if($url==''){
- $url="/index.html";
- }else{
- if($module=='article_cate'){
- if($param['id']){
- if($GLOBALS['article_cates'][$param['id']]['seo_title']){
- if($param['p']){
- $url=APP_ROOT."/".$GLOBALS['article_cates'][$param['id']]['seo_title']."?p=".$param['p'];
- }else{
- $url=APP_ROOT."/".$GLOBALS['article_cates'][$param['id']]['seo_title'];
- }
- }else{
- $url.='.html';
- }
- }elseif($param['p']){
- $url=APP_ROOT."/article_cate?p=".$param['p'];
- }elseif($param['tag']){
- $url=APP_ROOT."/article_cate?tag=".$param['tag'];
- }
- else{
- $url=APP_ROOT."/article_cate";
- }
- }elseif($module=='article'){
- if($param['id']){
- if($GLOBALS['article_cates'][$GLOBALS['articles'][$param['id']]['cate_id']]['seo_title']){
- $url=APP_ROOT."/".$GLOBALS['article_cates'][$GLOBALS['articles'][$param['id']]['cate_id']]['seo_title']."/".$param['id'].".html";
- }else{
- $url.='.html';
- }
- }else{
- $url=APP_ROOT."/article_cate";
- }
- }else{
- $url.='.html';
- }
- }
- if($url=='')$url="/";
- return $url;
- }
- }
- //PC端 封装url
- function url_pc($route="index",$act="action",$param=array())
- {
- $route_array = explode("#",$route);
- $act_array = explode("#",$act);
- if(isset($param)&&$param!=''&&!is_array($param))
- {
- $param['id'] = $param;
- }
- if(isset($route_array[0])){
- $module = strtolower(trim($route_array[0]));
- }else{
- $module = "";
- }
- if(isset($act_array[0])){
- $action = strtolower(trim($act_array[0]));
- }else{
- $action = "";
- }
- if(!$module||$module=='index')$module="";
- if(!$action||$action=='action')$action="";
- if(true )
- {
- //原始模式
- $url = APP_ROOT."/app/index.php";
- if($module!=''||$action!=''||count($param)>0) //有后缀参数
- {
- $url.="?";
- }
- if($module&&$module!='')
- $url .= 'ctl'."=".$module."&";
- if($action&&$action!='')
- $url .= 'act'."=".$action."&";
- if(count($param)>0)
- {
- foreach($param as $k=>$v)
- {
- if($k&&$v)
- $url =$url.$k."=".urlencode($v)."&";
- }
- }
- if(substr($url,-1,1)=='&'||substr($url,-1,1)=='?') $url = substr($url,0,-1);
- return $url;
- }
- else
- {
- //重写的默认
- $url = APP_ROOT;
- if($module==''&&$action==''){
- $url .='/index';
- }else{
- if($module&&$module!='')
- $url .= "/".$module;
- if($action&&$action!='')
- $url .= "/".$action;
- }
- if(count($param)>0)
- {
- $url.="/";
- foreach($param as $k=>$v)
- {
- $url =$url.$k."-".urlencode($v)."-";
- }
- }
- $route = $module."#".$action;
- $cat = $module."#".$action;
- switch ($route)
- {
- case "xxx":
- break;
- default:
- break;
- }
- switch ($cat)
- {
- case "xxx":
- break;
- default:
- break;
- }
- if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-') $url = substr($url,0,-1);
- $url=trim($url);
- if($url==''){
- $url="/index.html";
- }else{
- if($module=='article_cate'){
- if($param['id']){
- if($GLOBALS['article_cates'][$param['id']]['seo_title']){
- if($param['p']){
- $url=APP_ROOT."/".$GLOBALS['article_cates'][$param['id']]['seo_title']."?p=".$param['p'];
- }else{
- $url=APP_ROOT."/".$GLOBALS['article_cates'][$param['id']]['seo_title'];
- }
- }else{
- $url.='.html';
- }
- }elseif($param['p']){
- $url=APP_ROOT."/article_cate?p=".$param['p'];
- }elseif($param['tag']){
- $url=APP_ROOT."/article_cate?tag=".$param['tag'];
- }
- else{
- $url=APP_ROOT."/article_cate";
- }
- }elseif($module=='article'){
- if($param['id']){
- if($GLOBALS['article_cates'][$GLOBALS['articles'][$param['id']]['cate_id']]['seo_title']){
- $url=APP_ROOT."/".$GLOBALS['article_cates'][$GLOBALS['articles'][$param['id']]['cate_id']]['seo_title']."/".$param['id'].".html";
- }else{
- $url.='.html';
- }
- }else{
- $url=APP_ROOT."/article_cate";
- }
- }else{
- $url.='.html';
- }
- }
- if($url=='')$url="/";
- return $url;
- }
- }
- //微信端 封装url
- function url_wx($route="index",$act="action",$param=array())
- {
- if($GLOBALS['is_app']){
- $param['from_type'] = $GLOBALS['is_app'];
- }
- $key = md5("URL_WAP_KEY_".$route.serialize($param));
- if(isset($GLOBALS[$key]))
- {
- $url = $GLOBALS[$key];
- return $url;
- }
- $url = load_dynamic_cache($key);
- if($url!==false)
- {
- $GLOBALS[$key] = $url;
- return $url;
- }
- $route_array = explode("#",$route);
- if(isset($param)&&$param!=''&&!is_array($param))
- {
- $param['id'] = $param;
- }
- $module = strtolower(trim($route_array[0]));
- $action = strtolower(trim($route_array[1]));
- if(!$module||$module=='index')$module="";
- if(!$action||$action=='index')$action="";
- if(true)
- {
- //原始模式
- $url = APP_ROOT."/index.php";
- if($module!=''||$action!=''||count($param)>0) //有后缀参数
- {
- $url.="?";
- }
- if($module&&$module!='')
- $url .= "ctl=".$module."&";
- if($action&&$action!='')
- $url .= "act=".$action."&";
- if(count($param)>0)
- {
- foreach($param as $k=>$v)
- {
- if($k&&$v)
- $url =$url.$k."=".urlencode($v)."&";
- }
- }
- if(substr($url,-1,1)=='&'||substr($url,-1,1)=='?') $url = substr($url,0,-1);
- $GLOBALS[$key] = $url;
- set_dynamic_cache($key,$url);
- return $url;
- }
- else
- {
- //重写的默认
- $url = APP_ROOT;
- if($module&&$module!='')
- $url .= "/".$module;
- if($action&&$action!='')
- $url .= "-".$action;
- if(count($param)>0)
- {
- $url.="/";
- foreach($param as $k=>$v)
- {
- $url =$url.$k."-".urlencode($v)."-";
- }
- }
- $route = $module."#".$action;
- switch ($route)
- {
- case "xxx":
- break;
- default:
- break;
- }
- if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-') $url = substr($url,0,-1);
- if($url=='')$url="/";
- $GLOBALS[$key] = $url;
- set_dynamic_cache($key,$url);
- return $url;
- }
- }
- //手机端 访问根目录的url
- function url_root($route="index",$param=array())
- {
- $key = md5("URL_KEY_".$route.serialize($param));
- if(isset($GLOBALS[$key]))
- {
- $url = $GLOBALS[$key];
- return $url;
- }
- $url = load_dynamic_cache($key);
- if($url!==false)
- {
- $GLOBALS[$key] = $url;
- return $url;
- }
- $route_array = explode("#",$route);
- if(isset($param)&&$param!=''&&!is_array($param))
- {
- $param['id'] = $param;
- }
- $module = strtolower(trim($route_array[0]));
- $action = strtolower(trim($route_array[1]));
- if(!$module||$module=='index')$module="";
- if(!$action||$action=='index')$action="";
- if(app_conf("URL_MODEL")==0)
- {
- //原始模式
- $url = get_domain().REAL_APP_ROOT."/index.php";
- if($module!=''||$action!=''||count($param)>0) //有后缀参数
- {
- $url.="?";
- }
- if($module&&$module!='')
- $url .= "ctl=".$module."&";
- if($action&&$action!='')
- $url .= "act=".$action."&";
- if(count($param)>0)
- {
- foreach($param as $k=>$v)
- {
- if($k&&$v)
- $url =$url.$k."=".urlencode($v)."&";
- }
- }
- if(substr($url,-1,1)=='&'||substr($url,-1,1)=='?') $url = substr($url,0,-1);
- $GLOBALS[$key] = $url;
- set_dynamic_cache($key,$url);
- return $url;
- }
- else
- {
- //重写的默认
- $url = get_domain().REAL_APP_ROOT;
- if($module&&$module!='')
- $url .= "/".$module;
- if($action&&$action!='')
- $url .= "-".$action;
- if(count($param)>0)
- {
- $url.="/";
- foreach($param as $k=>$v)
- {
- $url =$url.$k."-".urlencode($v)."-";
- }
- }
- $route = $module."#".$action;
- switch ($route)
- {
- case "xxx":
- break;
- default:
- break;
- }
- if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-') $url = substr($url,0,-1);
- if($url=='')$url="/";
- $GLOBALS[$key] = $url;
- set_dynamic_cache($key,$url);
- return $url;
- }
- }
- function unicode_encode($name) {//to Unicode
- $name = iconv('UTF-8', 'UCS-2', $name);
- $len = strlen($name);
- $str = '';
- for($i = 0; $i < $len - 1; $i = $i + 2) {
- $c = $name[$i];
- $c2 = $name[$i + 1];
- if (ord($c) > 0) {// 两个字节的字
- $cn_word = '\\'.base_convert(ord($c), 10, 16).base_convert(ord($c2), 10, 16);
- $str .= strtoupper($cn_word);
- } else {
- $str .= $c2;
- }
- }
- return $str;
- }
- function unicode_decode($name) {//Unicode to
- $pattern = '/([\w]+)|(\\\u([\w]{4}))/i';
- preg_match_all($pattern, $name, $matches);
- if (!empty($matches)) {
- $name = '';
- for ($j = 0; $j < count($matches[0]); $j++) {
- $str = $matches[0][$j];
- if (strpos($str, '\\u') === 0) {
- $code = base_convert(substr($str, 2, 2), 16, 10);
- $code2 = base_convert(substr($str, 4), 16, 10);
- $c = chr($code).chr($code2);
- $c = iconv('UCS-2', 'UTF-8', $c);
- $name .= $c;
- } else {
- $name .= $str;
- }
- }
- }
- return $name;
- }
- //载入动态缓存数据
- function load_dynamic_cache($name)
- {
- if(isset($GLOBALS['dynamic_cache'][$name]))
- {
- return $GLOBALS['dynamic_cache'][$name];
- }
- else
- {
- return false;
- }
- }
- function set_dynamic_cache($name,$value)
- {
- if(!isset($GLOBALS['dynamic_cache'][$name]))
- {
- if(count($GLOBALS['dynamic_cache'])>MAX_DYNAMIC_CACHE_SIZE)
- {
- array_shift($GLOBALS['dynamic_cache']);
- }
- $GLOBALS['dynamic_cache'][$name] = $value;
- }
- }
- function load_auto_cache($key,$param=array(),$is_real=true)
- {
- $keys = array('admin_nav','admin_role','api_list','article','article_agreement','article_cates','article_cates_bs','article_notice','article_privacy','banner_list',
- 'cache_nav_list','cate_id','cate_top','index_image','lottery_luckyers','m_config','message_cate','mobile_code','new_hepls','page_image',
- 'pay_list','prop_id','prop_list','region_list','rule_list','score_cates','tipoff_type_list','user_carry_config','user_level','usersig'
- );
- fanwe_require(APP_ROOT_PATH."system/libs/auto_cache.php");
- //if(!in_array($key,$keys)){
- // return false;
- //}
- $file = APP_ROOT_PATH."system/auto_cache/".$key.".auto_cache.php";
- // if(file_exists($file))
- // {
- fanwe_require($file);
- $class = $key."_auto_cache";
- $obj = new $class;
- $result = $obj->load($param,$is_real);
- // }
- // else
- // $result = false;
- return $result;
- }
- function rm_auto_cache($key,$param=array())
- {
- fanwe_require(APP_ROOT_PATH."system/libs/auto_cache.php");
- $file = APP_ROOT_PATH."system/auto_cache/".$key.".auto_cache.php";
- if(file_exists($file))
- {
- fanwe_require($file);
- $class = $key."_auto_cache";
- $obj = new $class;
- $obj->rm($param);
- }
- }
- function clear_auto_cache($key,$param=array())
- {
- fanwe_require(APP_ROOT_PATH."system/libs/auto_cache.php");
- $file = APP_ROOT_PATH."system/auto_cache/".$key.".auto_cache.php";
- if(file_exists($file))
- {
- fanwe_require($file);
- $class = $key."_auto_cache";
- $obj = new $class;
- $obj->clear_all($param);
- }
- }
- function app_login(){
- $agentArr = agentArr();
- $user_info = es_session::get("user_info");
- if(!$user_info){
- $data['is_login'] = 0;
- $data['user_id'] = '';
- $data['nick_name'] = '';
- $data['mobile'] = '';
- }else{
- $data['is_login'] = 1;
- $data['user_id'] = $user_info['id'];
- $data['nick_name'] = $user_info['nick_name'];
- $data['mobile'] = $user_info['mobile'];
- $data['head_image'] = add_domain_url($user_info['head_image']);
- }
- if($agentArr['sdk_type']=="ios"){
- $data['sdk_data']= "weixin://";
- }
- else{
- $data['sdk_data']= "com.tencent.mm";
- }
- return $data;
- }
- /*ajax返回*/
- function ajax_return($data,$r_type=4,$is_debug=false)
- {
- if(!$is_debug){
- header("Content-Type:text/html; charset=utf-8");
- header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
- filter_null($data);//过滤null
- //过滤false
- $data = filter_all_false($data);
- $encrypt = $GLOBALS['encrypt'];
- $data['act'] = $encrypt['act'];
- $data['ctl'] = $encrypt['ctl'];
- if($encrypt['i_type']){
- ajax_return_aes($data,$r_type);
- }else{
- echo(json_encode($data));
- }
- exit;
- }else{
- var_export($data);
- echo "<br />";
- exit;
- }
- }
- /*admin 后台 ajax返回*/
- function admin_ajax_return($data,$is_debug=false)
- {
- if(!$is_debug){
- header("Content-Type:text/html; charset=utf-8");
- header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
- filter_null($data);//过滤null
- //过滤false
- echo(json_encode($data));
- exit;
- }else{
- var_export($data);
- echo "<br />";
- exit;
- }
- }
- //过滤null 把null改为空;
- function filter_null(&$request)
- {
- foreach($request as $k=>$v)
- {
- if(is_array($v))
- {
- filter_null($request[$k]);
- }
- else
- {
- if(is_null($v))
- {
- $request[$k] = '';
- }
- }
- }
- }
- /*ajax返回*/
- function ajax_file_return($data,$is_debug=false)
- {
- if(!$is_debug){
- header("Content-Type:text/html; charset=utf-8");
- echo(json_encode($data));
- exit;
- }else{
- if($data['status']==0){
- var_export($data);
- echo "<br />";
- exit;
- }
- }
- }
- /**
- * 过滤绑定用户名中的奇葩字符:替换成可以存入的3字节
- */
- function filterEmoji($string){
- return preg_replace('/[\x{10000}-\x{10FFFF}]/u', '',$string);
- }
- /**
- * 屏蔽Emoji表情:去除4字节的表情
- */
- /*function filterEmoji1($string){
- $str = preg_replace_callback(
- '/./u',
- function (array $match) {
- return strlen($match[0]) >= 4 ? '' : $match[0];
- },
- $str);
- return $str;
- }*/
- function is_animated_gif($filename){
- $fp=fopen($filename, 'rb');
- $filecontent=fread($fp, filesize($filename));
- fclose($fp);
- return strpos($filecontent,chr(0x21).chr(0xff).chr(0x0b).'NETSCAPE2.0')===FALSE?0:1;
- }
- function gen_qrcode($str,$size = 5)
- {
- require_once APP_ROOT_PATH."system/phpqrcode/qrlib.php";
- $root_dir = APP_ROOT_PATH."public/images/qrcode/";
- if (!is_dir($root_dir)) {
- @mkdir($root_dir);
- @chmod($root_dir, 0777);
- }
- $filename = md5($str."|".$size);
- $hash_dir = $root_dir. '/c' . substr(md5($filename), 0, 1)."/";
- if (!is_dir($hash_dir))
- {
- @mkdir($hash_dir);
- @chmod($hash_dir, 0777);
- }
- $filesave = $hash_dir.$filename.'.png';
- if(!file_exists($filesave))
- {
- QRcode::png($str, $filesave, 'Q', $size, 2);
- }
- return APP_ROOT."/public/images/qrcode/c". substr(md5($filename), 0, 1)."/".$filename.".png";
- }
- function format_price($v)
- {
- if(!$v){$v = 0;}
- return "¥".number_format($v,2);
- }
- //发密码验证邮件
- function send_user_password_mail($user_id)
- {
- $verify_code = rand(111111,999999);
- $GLOBALS['db']->query("update ".DB_PREFIX."user set password_verify = '".$verify_code."' where id = ".$user_id);
- $user_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where id = ".$user_id);
- if($user_info)
- {
- $tmpl = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."msg_template where name = 'TPL_MAIL_USER_PASSWORD'");
- $tmpl_content= $tmpl['content'];
- $user_info['logo']=app_conf("SITE_LOGO");
- $user_info['site_name']=app_conf("SITE_NAME");
- $time=get_gmtime();
- $user_info['send_time']=to_date($time,'Y年m月d日');
- $user_info['send_time_ms']=to_date($time,'Y年m月d日 H时i分');
- $user_info['password_url'] = get_domain().url("settings#password", array("code"=>$user_info['password_verify'],"id"=>$user_info['id']));
- $GLOBALS['tmpl']->assign("user",$user_info);
- $msg = $GLOBALS['tmpl']->fetch("str:".$tmpl_content);
- $msg_data['dest'] = $user_info['email'];
- $msg_data['send_type'] = 1;
- $msg_data['title'] = "重置密码";
- $msg_data['content'] = addslashes($msg);
- $msg_data['send_time'] = 0;
- $msg_data['is_send'] = 0;
- $msg_data['create_time'] = get_gmtime();
- $msg_data['user_id'] = $user_info['id'];
- $msg_data['is_html'] = $tmpl['is_html'];
- $GLOBALS['db']->autoExecute(DB_PREFIX."deal_msg_list",$msg_data); //插入
- }
- }
- function strim($str)
- {
- return quotes(htmlspecialchars(trim($str)));
- }
- function btrim($str)
- {
- return quotes(trim($str));
- }
- function valid_tag($str)
- {
- return preg_replace("/<(?!div|ol|ul|li|sup|sub|span|br|img|p|h1|h2|h3|h4|h5|h6|\/div|\/ol|\/ul|\/li|\/sup|\/sub|\/span|\/br|\/img|\/p|\/h1|\/h2|\/h3|\/h4|\/h5|\/h6|blockquote|\/blockquote|strike|\/strike|b|\/b|i|\/i|u|\/u)[^>]*>/i","",$str);
- }
- //$type = 1(添加) 2(删除)
- function update_user_weibo($user_id,$weibo_url,$type=1)
- {
- if($weibo_url!="")
- {
- if($type==1)
- {
- if($GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."user_weibo where weibo_url = '".$weibo_url."' and user_id = ".$user_id)==0)
- {
- $weibo_data['user_id'] = $user_id;
- $weibo_data['weibo_url'] = $weibo_url;
- $GLOBALS['db']->autoExecute(DB_PREFIX."user_weibo",$weibo_data);
- }
- }
- if($type==2)
- {
- $GLOBALS['db']->query("delete from ".DB_PREFIX."user_weibo where user_id = ".$user_id." and weibo_url = '".$weibo_url."'");
- }
- }
- }
- //同步到微博
- function syn_weibo($data)
- {
- $api_list = $GLOBALS['db']->getAllCached("select * from ".DB_PREFIX."api_login where is_weibo = 1");
- foreach($api_list as $k=>$v)
- {
- if($GLOBALS['user_info'][strtolower($v['class_name'])."_id"]==""||$GLOBALS['user_info'][strtolower($v['class_name'])."_token"]=="")
- {
- unset($api_list[$k]);
- }
- else
- {
- $class_name = $v['class_name']."_api";
- require_once APP_ROOT_PATH."system/api_login/".$class_name.".php";
- $o = new $class_name($v);
- $o->send_message($data);
- }
- }
- }
- function check_sms_send($mobile){
- $data = array();
- $data['status'] = 1;
- $data['error'] = "未定义限制";
- /*
- if(!SMS_MOBILE_SEND_COUNT&&!SMS_IP_SEND_COUNT){
- //return false;
- $data['status'] = 1;
- $data['error'] = "未定义限制";
- }*/
- $now_ip = get_client_ip();
- $now_date = to_date(get_gmtime(),'Y-m-d');
- //$now_date = to_timespan($now_date);
- //$to_date = $now_date + 24*3600;
- if (defined('SMS_MOBILE_SEND_COUNT') && SMS_MOBILE_SEND_COUNT > 0){
- $mobile_sql = "select count(*) from ".DB_PREFIX."deal_msg_list where send_type = 0 and dest = '".$mobile."' and send_date ='".$now_date."'";
- $mobile_count = $GLOBALS['db']->getOne($mobile_sql);
- $mobile_count = intval($mobile_count);
- if($mobile_count>SMS_MOBILE_SEND_COUNT){
- $data['status'] = 0;
- $data['error'] = "验证码发送失败,当前手机号已超过今天限额";
- }
- }
- if ($data['status'] == 1 && defined('SMS_IP_SEND_COUNT') && SMS_IP_SEND_COUNT > 0){
- $date_h = to_date(get_gmtime(),'H');
- $ip_sql = "select count(*) from ".DB_PREFIX."deal_msg_list where send_type = 0 and client_ip ='".$now_ip."' and send_h = ".$date_h." and send_date ='".$now_date."'";
- $ip_count = $GLOBALS['db']->getOne($ip_sql);
- $ip_count = intval($ip_count);
- if($ip_count>SMS_IP_SEND_COUNT){
- $data['status'] = 0;
- $data['error'] = "验证码发送失败,当前ip已超过今天限额";
- }
- }
- return $data;
- }
- //发短信验证码
- function send_verify_sms($mobile,$code,$type="")
- {
- $type ='sms';
- $dest = $mobile;
- $title='';
- /*
- * 发送验证码
- */
- $user_info = array();
- if(!empty($dest)){
- $user_info = $GLOBALS['db']->getRow("select *,id as user_id from ".DB_PREFIX."user where mobile='".$dest."'");
- $user_info['mobile'] = $dest;
- $user_info['code'] = $code;
- $user_info['tmpl_sms_name'] = 'verify';
- if($title){
- $msg_data['title'] = $title;
- }else{
- $msg_data['title'] = "短信验证码";
- }
- $msg_data['dest'] = $user_info['mobile'];
- $msg_data['user_id'] = $user_info['user_id'];
- $msg_data['is_html'] = 0;
- $msg_data['send_type'] = 0;
- $msg_data['code'] =$code;
- if(app_conf("SMS_ON")!=1&&$type=='sms'){
- return false;
- }
- $tmpl = $GLOBALS['db']->getRowCached("select * from ".DB_PREFIX."msg_template where name = 'TPL_SMS_VERIFY_CODE'");
- //$tmpl = str_replace('{$verify.mobile}',$dest,$tmpl);
- //补充 替换verify.mobile
- $tmpl = str_replace('你的手机号为{$verify.mobile},','',$tmpl);
- $tmpl['content'] = str_replace('{$verify.code}',$code,$tmpl);
- $msg= $tmpl['content'];
- $msg_data['send_type'] = 0;
- $msg_data['content'] = addslashes($msg['content']);
- $msg_data['send_time'] = 0;
- $msg_data['is_send'] = 0;
- $msg_data['create_time'] = get_gmtime();
- $msg_data['is_html'] = 1;
- $msg_data['client_ip'] = get_client_ip();
- $msg_data['send_date'] = to_date(get_gmtime(),'Y-m-d');
- $msg_data['send_h'] = to_date(get_gmtime(),'H');
- if($msg_data){
- $data = $msg_data;
- if(app_conf('IS_SMS_DIRECT')==1){
- if($data['send_type']==0){
- require_once APP_ROOT_PATH."system/utils/es_sms.php";
- $sms = new sms_sender();
- $result = $sms->sendSms($data['dest'],$data['content']);
- $data['is_success'] = intval($result['status']);
- $data['result'] = $result['msg'];
- }
- $data['is_send'] = 1;
- $data['send_time'] = get_gmtime();
- }
- return $GLOBALS['db']->autoExecute(DB_PREFIX."deal_msg_list",$data); //插入
- }
- }
- }
- /**
- * 发送投资通短信验证码
- * @param $mobile 手机号
- * @param $code 验证码
- */
- function send_tzt_verify_sms($mobile, $code){
- $GLOBALS['msg']->manage_msg('TPL_SMS_TZT_VERIFY_CODE',$mobile,array('code'=>$code,'user_id'=>$GLOBALS['user_info']['id']));
- }
- //发邮件验证码
- function send_verify_email($email,$code,$title="")
- {
- $GLOBALS['msg']->manage_msg('TPL_MAIL_USER_VERIFY',$email,array('code'=>$code,'title'=>$title));
- }
- //获取系统运行上传的值
- function get_max_file_size(){
- $system_size=intval(ini_get("post_max_size"))<intval(ini_get("upload_max_filesize"))?intval(ini_get("post_max_size"))*1024*1024:intval(ini_get("upload_max_filesize"))*1024*1024;
- $config_size=app_conf("MAX_IMAGE_SIZE");
- $max_size = $system_size>$config_size?$config_size:$system_size;
- //number_format($system_size/(1024*1024),1)
- if($max_size>=1024*1024){
- return number_format($max_size/(1024*1024),1).'MB';
- }elseif($max_size>=1024){
- return number_format($max_size/(1024),1).'KB';
- }else{
- return $max_size.'B';
- }
- }
- //获取系统运行上传的值
- function get_max_file_size_byte(){
- $system_size=intval(ini_get("post_max_size"))<intval(ini_get("upload_max_filesize"))?intval(ini_get("post_max_size"))*1024*1024:intval(ini_get("upload_max_filesize"))*1024*1024;
- $config_size=app_conf("MAX_IMAGE_SIZE");
- $max_size = $system_size>$config_size?$config_size:$system_size;
- return $max_size;
- }
- function isMobile() {
- // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
- if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])){
- return true;
- }
- //如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
- if (isset ($_SERVER['HTTP_VIA'])) {
- //找不到为flase,否则为true
- return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
- }
- //判断手机发送的客户端标志,兼容性有待提高
- if (isset ($_SERVER['HTTP_USER_AGENT'])) {
- $clientkeywords = array (
- 'nokia',
- 'sony',
- 'ericsson',
- 'mot',
- 'samsung',
- 'htc',
- 'sgh',
- 'lg',
- 'sharp',
- 'sie-',
- 'philips',
- 'panasonic',
- 'alcatel',
- 'lenovo',
- 'iphone',
- 'ipod',
- 'blackberry',
- 'meizu',
- 'android',
- 'netfront',
- 'symbian',
- 'ucweb',
- 'windowsce',
- 'palm',
- 'operamini',
- 'operamobi',
- 'openwave',
- 'nexusone',
- 'cldc',
- 'midp',
- 'wap',
- 'mobile'
- );
- // 从HTTP_USER_AGENT中查找手机浏览器的关键字
- if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
- return true;
- }
- }
- //协议法,因为有可能不准确,放到最后判断
- if (isset ($_SERVER['HTTP_ACCEPT'])) {
- // 如果只支持wml并且不支持html那一定是移动设备
- // 如果支持wml和html但是wml在html之前则是移动设备
- if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
- return true;
- }
- }
- }
- //发起通知用户审核通过或者失败
- function send_investor_status($user_info){
- if($user_info['id']){
- $GLOBALS['msg']->manage_msg("MSG_INVEST_STATUS",$user_info['id'],array('user_info'=>$user_info));
- }
- }
- function get_investor($is_investor){
- switch($is_investor){
- case 0:
- return '普通会员';
- break;
- case 1:
- return '企业会员';
- break;
- /*case 2:
- return '投资机构';
- break;*/
- }
- }
- function get_investor_status($investor_status){
- switch($investor_status){
- case 0:
- return '未审核';
- break;
- case 1:
- return '待审核';
- break;
- case 2:
- return '审核通过';
- break;
- case 3:
- return '审核未通过';
- break;
- }
- }
- function LOGIN_DES_KEY(){
- if(!es_session::is_set("DES_KEY")){
- require_once APP_ROOT_PATH."system/utils/es_string.php";
- es_session::set("DES_KEY",es_string::rand_string(50));
- }
- return es_session::get("DES_KEY");
- }
- //检测手机是否可以绑定
- function check_registor_mobile($check_mobile_info,$ajax=1){
- $mobile = $check_mobile_info['mobile'];
- $login_type = $check_mobile_info['login_type'];
- if(strlen($mobile)< 0 || strlen($mobile)== 0){
- $data['status'] = 0;
- $data['info'] = '请输入手机号码';
- ajax_return($data);
- }
- if(!check_mobile($mobile))
- {
- $data['status'] = 0;
- $data['info'] = '请填写正确的手机号码';
- ajax_return($data);
- }
- if(strlen($mobile)>11){
- $data['status'] = 0;
- $data['info'] = '"手机号码长度不能超过11位';
- ajax_return($data);
- }
- $condition=" mobile ='".$mobile."' and login_type=".$login_type;
- $num=$GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."user where $condition");
- if($num>0){
- $data['status'] = 0;
- $data['info'] = '手机已存在,请重新输入';
- ajax_return($data);
- }
- }
- //检测手机是否可以绑定
- function check_registor_email($email,$ajax=1){
- if(strlen($email)<=0 ){
- showErr("请输入邮箱",$ajax,"");
- }
- if(!check_email($email))
- {
- showErr("请填写正确的邮箱",$ajax,"");
- }
- $condition=" email='$email'";
- $num=$GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."user where $condition");
- if($num>0){
- showErr("邮箱已存在,请重新输入",$ajax,"");
- }
- }
- /**
- * 验证身份证号
- * @param $vStr
- * @return bool
- */
- function isCreditNo($vStr)
- {
- $vCity = array(
- '11','12','13','14','15','21','22',
- '23','31','32','33','34','35','36',
- '37','41','42','43','44','45','46',
- '50','51','52','53','54','61','62',
- '63','64','65','71','81','82','91'
- );
- if (!preg_match('/^([\d]{17}[xX\d]|[\d]{15})$/', $vStr)) return false;
- if (!in_array(substr($vStr, 0, 2), $vCity)) return false;
- $vStr = preg_replace('/[xX]$/i', 'a', $vStr);
- $vLength = strlen($vStr);
- if ($vLength == 18)
- {
- $vBirthday = substr($vStr, 6, 4) . '-' . substr($vStr, 10, 2) . '-' . substr($vStr, 12, 2);
- } else {
- $vBirthday = '19' . substr($vStr, 6, 2) . '-' . substr($vStr, 8, 2) . '-' . substr($vStr, 10, 2);
- }
- if (date('Y-m-d', strtotime($vBirthday)) != $vBirthday) return false;
- if ($vLength == 18)
- {
- $vSum = 0;
- for ($i = 17 ; $i >= 0 ; $i--)
- {
- $vSubStr = substr($vStr, 17 - $i, 1);
- $vSum += (pow(2, $i) % 11) * (($vSubStr == 'a') ? 10 : intval($vSubStr , 11));
- }
- if($vSum % 11 != 1) return false;
- }
- return true;
- }
- //获取来源网站
- function set_source_url(){
- if(!es_session::get("source_url")&&!$GLOBALS['user_info']){
- if($_SERVER['HTTP_REFERER']){
- $source_url=$_SERVER['HTTP_REFERER'];
- $url=parse_url($source_url);
- if($url['host']!=$_SERVER['HTTP_HOST']){
- es_session::set("source_url",$url['host']);
- }
- }
- }
- }
- function get_http()
- {
- return (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
- }
- function get_domain()
- {
- /* 协议 */
- $protocol = get_http();
- if(app_conf("SITE_DOMAIN")!="")
- {
- return $protocol.app_conf("SITE_DOMAIN");
- }
- /* 域名或IP地址 */
- if (isset($_SERVER['HTTP_X_FORWARDED_HOST']))
- {
- $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
- }
- elseif (isset($_SERVER['HTTP_HOST']))
- {
- $host = $_SERVER['HTTP_HOST'];
- }
- else
- {
- /* 端口 */
- if (isset($_SERVER['SERVER_PORT']))
- {
- $port = ':' . $_SERVER['SERVER_PORT'];
- if ((':80' == $port && 'http://' == $protocol) || (':443' == $port && 'https://' == $protocol))
- {
- $port = '';
- }
- }
- else
- {
- $port = '';
- }
- if (isset($_SERVER['SERVER_NAME']))
- {
- $host = $_SERVER['SERVER_NAME'] . $port;
- }
- elseif (isset($_SERVER['SERVER_ADDR']))
- {
- $host = $_SERVER['SERVER_ADDR'] . $port;
- }
- }
- return $protocol . $host;
- }
- function get_host()
- {
- /* 域名或IP地址 */
- if (isset($_SERVER['HTTP_X_FORWARDED_HOST']))
- {
- $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
- }
- elseif (isset($_SERVER['HTTP_HOST']))
- {
- $host = $_SERVER['HTTP_HOST'];
- }
- else
- {
- if (isset($_SERVER['SERVER_NAME']))
- {
- $host = $_SERVER['SERVER_NAME'];
- }
- elseif (isset($_SERVER['SERVER_ADDR']))
- {
- $host = $_SERVER['SERVER_ADDR'];
- }
- }
- return $host;
- }
- /**
- * 将单个图片同步到远程的图片服务器
- * @param string $url 本地的图片地址,"./public/......"
- */
- function syn_to_remote_image_server($url,$is_unlink=true)
- {
- if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']!="NONE")
- {
- if($GLOBALS['distribution_cfg']['OSS_TYPE']=="ES_FILE")
- {
- $pathinfo = pathinfo($url);
- $file = $pathinfo['basename'];
- $dir = $pathinfo['dirname'];
- $dir = str_replace("./public/", "", $dir);
- $filefull = SITE_DOMAIN.APP_ROOT."/public/".$dir."/".$file;
- $syn_url = $GLOBALS['distribution_cfg']['OSS_DOMAIN']."/es_file.php?username=".$GLOBALS['distribution_cfg']['OSS_ACCESS_ID']."&password=".$GLOBALS['distribution_cfg']['OSS_ACCESS_KEY']."&file=".
- $filefull."&path=".$dir."/&name=".$file."&act=0";
- @file_get_contents($syn_url);
- }
- elseif($GLOBALS['distribution_cfg']['OSS_TYPE']=="ALI_OSS")
- {
- $pathinfo = pathinfo($url);
- $file = $pathinfo['basename'];
- $dir = $pathinfo['dirname'];
- $dir = str_replace("./public/", "public/", $dir);
- require_once APP_ROOT_PATH."system/alioss/sdk.class.php";
- $oss_sdk_service = new ALIOSS();
- //设置是否打开curl调试模式
- $oss_sdk_service->set_debug_mode(FALSE);
- $bucket = $GLOBALS['distribution_cfg']['OSS_BUCKET_NAME'];
- $object = $dir."/".$file;
- $file_path = APP_ROOT_PATH.$dir."/".$file;
- $oss_sdk_service->upload_file_by_file($bucket,$object,$file_path);
- if($is_unlink&&intval($GLOBALS['distribution_cfg']['OSS_NO_SAVE_LOCALHOST'])==0){
- $info = (array)$oss_sdk_service->is_object_exist($bucket,$object);
- if(file_exists($file_path)&&$info['status']==200)unlink($file_path);
- }
- }
- }
- }
- function format_image_path($out)
- {
- //对图片路径的修复
- if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']!="NONE")
- {
- $domain = $GLOBALS['distribution_cfg']['OSS_DOMAIN'];
- }
- else
- {
- $domain = SITE_DOMAIN.APP_ROOT;
- }
- $out = str_replace(APP_ROOT."./public/",$domain."/public/",$out);
- $out = str_replace("./public/",$domain."/public/",$out);
- return $out;
- }
- function replace_public($str){
- //对图片路径的修复
- if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']!="NONE")
- {
- $domain = $GLOBALS['distribution_cfg']['OSS_DOMAIN'];
- }
- else
- {
- $domain = SITE_DOMAIN.APP_ROOT;
- }
- return str_replace($domain."/public/","./public/",$str);
- }
- /**
- * 同步脚本样式缓存 $url:'public/runtime/statics/biz/'.$url.'.css';
- * @param unknown_type $url
- */
- function syn_to_remote_file_server($url)
- {
- if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']!="NONE")
- {
- if($GLOBALS['distribution_cfg']['OSS_TYPE']=="ES_FILE")
- {
- $pathinfo = pathinfo($url);
- $file = $pathinfo['basename'];
- $dir = $pathinfo['dirname'];
- $dir = str_replace("public/", "", $dir);
- $filefull = SITE_DOMAIN.APP_ROOT."/public/".$dir."/".$file;
- $syn_url = $GLOBALS['distribution_cfg']['OSS_DOMAIN']."/es_file.php?username=".$GLOBALS['distribution_cfg']['OSS_ACCESS_ID']."&password=".$GLOBALS['distribution_cfg']['OSS_ACCESS_KEY']."&file=".
- $filefull."&path=".$dir."/&name=".$file."&act=0";
- @file_get_contents($syn_url);
- }
- elseif($GLOBALS['distribution_cfg']['OSS_TYPE']=="ALI_OSS")
- {
- $pathinfo = pathinfo($url);
- $file = $pathinfo['basename'];
- $dir = $pathinfo['dirname'];
- require_once APP_ROOT_PATH."system/alioss/sdk.class.php";
- $oss_sdk_service = new ALIOSS();
- //设置是否打开curl调试模式
- $oss_sdk_service->set_debug_mode(FALSE);
- $bucket = $GLOBALS['distribution_cfg']['OSS_BUCKET_NAME'];
- $object = $dir."/".$file;
- $file_path = APP_ROOT_PATH.$dir."/".$file;
- $oss_sdk_service->upload_file_by_file($bucket,$object,$file_path);
- }
- }
- }
- function isWeixin(){
- $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
- $is_weixin = strpos($agent, 'micromessenger') ? true : false ;
- if($is_weixin){
- return true;
- }else{
- return false;
- }
- }
- function isios() {
- //判断手机发送的客户端标志,兼容性有待提高
- if (isset ($_SERVER['HTTP_USER_AGENT'])) {
- $clientkeywords = array (
- 'iphone',
- 'ipod',
- 'mac',
- );
- // 从HTTP_USER_AGENT中查找手机浏览器的关键字
- if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
- return true;
- }
- }
- }
- //显示成功
- function showIpsInfo($msg,$jump='')
- {
- $GLOBALS['tmpl']->assign('msg',$msg);
- $GLOBALS['tmpl']->assign('jump',$jump);
- $GLOBALS['tmpl']->display("ips_show.html");
- exit;
- }
- //日期加减
- function dec_date($date,$dec){
- //$sysc_start_time = to_timespan(to_date(to_timespan($date),'Y-m-d')) - $dec * 86400;
- return to_date(to_timespan($date) - $dec * 86400,'Y-m-d');
- }
- /**
- * 作用:将xml转为array
- */
- function xmlToArray($xml)
- {
- //将XML转为array
- $array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
- return $array_data;
- }
- /**
- * 作用:array转xml
- */
- function arrayToXml($arr)
- {
- $xml = "<xml>";
- foreach ($arr as $key=>$val)
- {
- if (is_numeric($val))
- {
- $xml.="<".$key.">".$val."</".$key.">";
- }
- else
- $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
- }
- $xml.="</xml>";
- return $xml;
- }
- function log_result($word)
- {
- if (is_array($word)) $word = var_export($word,true);
- $file = APP_ROOT_PATH."/public/notify_url.log";
- $fp = fopen($file,"a");
- flock($fp, LOCK_EX) ;
- fwrite($fp,"执行日期:".strftime("%Y-%m-%d-%H:%M:%S",time())."\n".$word."\n\n");
- flock($fp, LOCK_UN);
- fclose($fp);
- }
- function log_result_wx($word)
- {
- if (is_array($word)) $word = var_export($word,true);
- $file = APP_ROOT_PATH."/public/notify_url_wx.log";
- $fp = fopen($file,"a");
- flock($fp, LOCK_EX) ;
- fwrite($fp,"执行日期:".strftime("%Y-%m-%d-%H:%M:%S",time())."\n".$word."\n\n");
- flock($fp, LOCK_UN);
- fclose($fp);
- }
- function log_result_wx_pay_log($word)
- {
- if (!is_dir(APP_ROOT_PATH."public/wx_pay_log")) {
- @mkdir(APP_ROOT_PATH."public/wx_pay_log");
- }
- $file = APP_ROOT_PATH."/public/wx_pay_log/".to_date(get_gmtime()-604800,"Ymd").".log";
- if(file_exists($file)){
- unlink($file);
- }
- $filename = to_date(get_gmtime(),"Ymd");
- if (is_array($word)) $word = var_export($word,true);
- $file = APP_ROOT_PATH."/public/wx_pay_log/".$filename.".log";
- $fp = fopen($file,"a");
- flock($fp, LOCK_EX) ;
- fwrite($fp,"执行日期:".strftime("%Y-%m-%d-%H:%M:%S",time())."\n".$word."\n\n");
- flock($fp, LOCK_UN);
- fclose($fp);
- }
- /**
- * 分页处理
- * @param string $type 所在页面
- * @param array $args 参数
- * @param int $total_count 总数
- * @param int $page 当前页
- * @param int $page_size 分页大小
- * @param string $url 自定义路径
- * @param int $offset 偏移量
- * @return array
- */
- function buildPage($type,$args,$total_count,$page = 1,$page_size = 0,$url='',$offset = 5){
- $pager['total_count'] = intval($total_count);
- $pager['page'] = $page;
- $pager['page_size'] = ($page_size == 0) ? 20 : $page_size;
- /* page 总数 */
- $pager['page_count'] = ($pager['total_count'] > 0) ? ceil($pager['total_count'] / $pager['page_size']) : 1;
- /* 边界处理 */
- if ($pager['page'] > $pager['page_count'])
- $pager['page'] = $pager['page_count'];
- $pager['limit'] = ($pager['page'] - 1) * $pager['page_size'] . "," . $pager['page_size'];
- $page_prev = ($pager['page'] > 1) ? $pager['page'] - 1 : 1;
- $page_next = ($pager['page'] < $pager['page_count']) ? $pager['page'] + 1 : $pager['page_count'];
- $pager['prev_page'] = $page_prev;
- $pager['next_page'] = $page_next;
- if (!empty($url)){
- $pager['page_first'] = $url . 1;
- $pager['page_prev'] = $url . $page_prev;
- $pager['page_next'] = $url . $page_next;
- $pager['page_last'] = $url . $pager['page_count'];
- }
- else{
- $args['page'] = '_page_';
- if(!empty($type)){
- if(strpos($type,'javascript:') === false){
- //$page_url = JKU($type,$args);
- $page_url = u($type,$args);
- }else{
- $page_url = $type;
- }
- }else{
- $page_url = 'javascript:;';
- }
- $pager['page_first'] = str_replace('_page_',1,$page_url);
- $pager['page_prev'] = str_replace('_page_',$page_prev,$page_url);
- $pager['page_next'] = str_replace('_page_',$page_next,$page_url);
- $pager['page_last'] = str_replace('_page_',$pager['page_count'],$page_url);
- }
- $pager['page_nums'] = array();
- if($pager['page_count'] <= $offset * 2){
- for ($i=1; $i <= $pager['page_count']; $i++){
- $pager['page_nums'][] = array('name' => $i,'url' => empty($url) ? str_replace('_page_',$i,$page_url) : $url . $i);
- }
- }else{
- if($pager['page'] - $offset < 2){
- $temp = $offset * 2;
- for ($i=1; $i<=$temp; $i++){
- $pager['page_nums'][] = array('name' => $i,'url' => empty($url) ? str_replace('_page_',$i,$page_url) : $url . $i);
- }
- $pager['page_nums'][] = array('name'=>'...');
- $pager['page_nums'][] = array('name' => $pager['page_count'],'url' => empty($url) ? str_replace('_page_',$pager['page_count'],$page_url) : $url . $pager['page_count']);
- }else{
- $pager['page_nums'][] = array('name' => 1,'url' => empty($url) ? str_replace('_page_',1,$page_url) : $url . 1);
- $pager['page_nums'][] = array('name'=>'...');
- $start = $pager['page'] - $offset + 1;
- $end = $pager['page'] + $offset - 1;
- if($pager['page_count'] - $end > 1){
- for ($i=$start;$i<=$end;$i++){
- $pager['page_nums'][] = array('name' => $i,'url' => empty($url) ? str_replace('_page_',$i,$page_url) : $url . $i);
- }
- $pager['page_nums'][] = array('name'=>'...');
- $pager['page_nums'][] = array('name' => $pager['page_count'],'url' => empty($url) ? str_replace('_page_',$pager['page_count'],$page_url) : $url . $pager['page_count']);
- }else{
- $start = $pager['page_count'] - $offset * 2 + 1;
- $end = $pager['page_count'];
- for ($i=$start;$i<=$end;$i++){
- $pager['page_nums'][] = array('name' => $i,'url' => empty($url) ? str_replace('_page_',$i,$page_url) : $url . $i);
- }
- }
- }
- }
- return $pager;
- }
- function parse_url_tag_coomon($str)
- {
- $str = substr($str,2);
- $str_array = explode("|",$str);
- $route = $str_array[0];
- $param_tmp = explode("&",$str_array[1]);
- $param = array();
- foreach($param_tmp as $item)
- {
- if($item!='')
- $item_arr = explode("=",$item);
- if($item_arr[0]&&$item_arr[1])
- $param[$item_arr[0]] = $item_arr[1];
- }
- return url($route,$param);
- }
- //解析URL标签
- // $str = u:acate#index|id=10&name=abc
- function parse_url_tag($str)
- {
- $key = md5("URL_TAG_".$str);
- if(isset($GLOBALS[$key]))
- {
- return $GLOBALS[$key];
- }
- $url = load_dynamic_cache($key);
- if($url!==false)
- {
- $GLOBALS[$key] = $url;
- return $url;
- }
- $str = substr($str,2);
- $str_array = explode("|",$str);
- $route = $str_array[0];
- $param_tmp = explode("&",$str_array[1]);
- $param = array();
- foreach($param_tmp as $item)
- {
- if($item!='')
- $item_arr = explode("=",$item);
- if($item_arr[0]&&$item_arr[1])
- $param[$item_arr[0]] = $item_arr[1];
- }
- $GLOBALS[$key]= url($route,$param);
- set_dynamic_cache($key,$GLOBALS[$key]);
- return $GLOBALS[$key];
- }
- function parse_url_tag_wap($str)
- {
- $key = md5("URL_TAG_".$str);
- if(isset($GLOBALS[$key]))
- {
- return $GLOBALS[$key];
- }
- $url = load_dynamic_cache($key);
- if($url!==false)
- {
- $GLOBALS[$key] = $url;
- return $url;
- }
- $str = substr($str,2);
- $str_array = explode("|",$str);
- $route = $str_array[0];
- $param_tmp = explode("&",$str_array[1]);
- $param = array();
- foreach($param_tmp as $item)
- {
- if($item!='')
- $item_arr = explode("=",$item);
- if($item_arr[0]&&$item_arr[1])
- $param[$item_arr[0]] = $item_arr[1];
- }
- $GLOBALS[$key]= url_wap($route,$param);
- set_dynamic_cache($key,$GLOBALS[$key]);
- return $GLOBALS[$key];
- }
- function HASH_KEY(){
- if(!es_session::is_set("HASH_KEY")){
- require_once APP_ROOT_PATH."system/utils/es_string.php";
- es_session::set("HASH_KEY",es_string::rand_string(50));
- }
- return es_session::get("HASH_KEY");
- }
- function check_hash_key(){
- if(strim($_REQUEST['fhash'])!="" && md5(HASH_KEY())==md5($_REQUEST['fhash'])){
- return true;
- }
- else
- return false;
- }
- function number_price_format($price)
- {
- if($price*100%100==0)
- $price= number_format(round($price,2));
- else
- $price = number_format(round($price,2),2);
- return $price;
- }
- /** 获取当前时间戳,精确到毫秒 */
- function microtime_float()
- {
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$usec + (float)$sec-date('Z'));
- }
- /** 格式化时间戳,精确到毫秒,x代表毫秒 */
- function microtime_format($utc_time, $format = 'H:i:s.x')
- {
- if (empty ( $utc_time )) {
- return '';
- }
- $timezone = intval(app_conf('TIME_ZONE'));
- $time = $utc_time + $timezone * 3600;
- list($usec, $sec) = explode(".", $time);
- $date = date($format,$usec);
- return str_replace('x', $sec, $date);
- }
- function trim_utf8mb4($str){
- return preg_replace('/[\x{10000}-\x{10FFFF}]/u', '',$str);
- }
- /**
- * 只保留字符串首尾字符,隐藏中间用*代替(两个字符时只显示第一个)
- * @param string $user_name 姓名
- * @return string 格式化后的姓名
- */
- function substr_cut($user_name){
- $strlen = mb_strlen($user_name, 'utf-8');
- $firstStr = mb_substr($user_name, 0, 1, 'utf-8');
- $lastStr = mb_substr($user_name, -1, 1, 'utf-8');
- return $strlen == 2 ? $firstStr . str_repeat('*', mb_strlen($user_name, 'utf-8') - 1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr;
- }
- /*
- * is_wap 0 表示wep 1表示wap 2表示APP
- */
- function create_target_url($target,$is_wap = 0,$cart_id=''){
- $return_url = "";
- if(strpos($target,'URL-dealID-')!==FALSE){
- $deal_id = trim($target,'URL-dealID-');
- if($cart_id!=''){
- $id = trim($cart_id,'URL-cartID-');
- }
- if($is_wap==0){
- $return_url = url("deal#show",array('id'=>$deal_id));
- }elseif($is_wap==1){
- if($id){
- $return_url = url_wap("cart#index",array('id'=>$id,'deal_id'=>$deal_id));
- }else{
- $return_url = url_wap("deal#show",array('id'=>$deal_id));
- }
- }
- }
- return $return_url;
- }
- //验证网址
- function check_url($url)
- {
- $patern ='/^http[s]?:\/\/'.
- '(([0-9]{1,3}\.){3}[0-9]{1,3}'. // IP形式的URL- 199.194.52.184
- '|'. // 允许IP和DOMAIN(域名)
- '([0-9a-z_!~*\'()-]+\.)*'. // 域名- www.
- '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.'. // 二级域名
- '[a-z]{2,6})'. // first level domain- .com or .museum
- '(:[0-9]{1,4})?'. // 端口- :80
- '((\/\?)|'. // a slash isn't required if there is no file name
- '(\/[0-9a-zA-Z_!~\'\(\)\[\]\.;\?:@&=\+\$,%#-\/^\*\|]*)?)$/';
- if(!empty($url) && !preg_match($patern,$url))
- {
- return false;
- }
- else
- return true;
- }
- /*
- * 转成元
- * $money 金额
- */
- function transform_yuan($money){
- $money =intval($money);
- if($money){
- return $money * 10000;
- }
- }
- /*
- * 元转成逆转万元
- * $money 金额
- */
- function transform_wan($money){
- $money =intval($money);
- if($money){
- return $money/10000;
- }
- }
- function create_app_js($app_conf){
- $node_app=APP_ROOT_PATH."public/node_app.js";
- if(is_file($node_app)){
- $content=file_get_contents($node_app);
- $url = get_domain().APP_ROOT;
- $content=str_replace("{domain}",$url,$content);
- if($app_conf['IS_SMS_DIRECT']==0){
- $deal_msg_list= 'true';
- }else{
- $deal_msg_list= 'false';
- }
- $content=str_replace("{deal_msg_list}",$deal_msg_list,$content);
- $time = $app_conf['SEND_SPAN']?$app_conf['SEND_SPAN']*1000:500;
- $content=str_replace("{time}",$time,$content);
- $app=APP_ROOT_PATH."public/app.js";
- file_put_contents($app,$content);
- }
- }
- /* 微信提现
- * */
- function wx_withdraw_cash($refund_id){
- $msg_item = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user_refund where id = ".$refund_id." and is_pay =1 ");
- $order_id = $msg_item['id'];
- $user_info = $GLOBALS['db']->getRow("select gz_openid,nick_name from ".DB_PREFIX."user where id=".$msg_item['user_id']);
- $open_id = $user_info['gz_openid'];
- //过滤中文支付 防止微信发送红包失败 //@、#、【】、
- $user_name = strFilter($user_info['nick_name']);
- $ticket = $msg_item['ticket'];
- if($msg_item)
- {
- $payment_info = $GLOBALS['db']->getRow("select id,config,logo from ".DB_PREFIX."payment where class_name='Wwxjspay'");
- $payment_info['config'] = unserialize($payment_info['config']);
- $wx_config=$payment_info['config'];
- $mch_appid=$wx_config['appid'];
- $mchid=$wx_config['mchid'];//商户号
- $nonce_str='qyzf'.rand(100000, 999999);//随机数
- $partner_trade_no='wx'.$order_id.time().rand(10000, 99999);;//商户订单号
- $openid=$open_id;//用户唯一标识
- $check_name='NO_CHECK';//校验用户姓名选项,NO_CHECK:不校验真实姓名 FORCE_CHECK:强校验真实姓名(未实名认证的用户会校验失败,无法转账)OPTION_CHECK:针对已实名认证的用户才校验真实姓名(未实名认证用户不校验,可以转账成功)
- $re_user_name=$user_name;//用户姓名
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- //$amount=intval(floatval($ticket*$m_config['exchange_rate'])*100);//金额(以分为单位,必须大于100)
- $amount = floatval($msg_item['money']*100);
- $desc='红包';//描述
- require_once APP_ROOT_PATH.'system/extend/ip.php';
- $iplocation = new iplocate();
- $spbill_create_ip = $iplocation->getIP();
- //封装成数据
- $dataArr=array();
- $dataArr['amount']=$amount;
- $dataArr['check_name']=$check_name;
- $dataArr['desc']=$desc;
- $dataArr['mch_appid']=$mch_appid;
- $dataArr['mchid']=$mchid;
- $dataArr['nonce_str']=$nonce_str;
- $dataArr['openid']=$openid;
- $dataArr['partner_trade_no']=$partner_trade_no;
- $dataArr['re_user_name']=$re_user_name;
- $dataArr['spbill_create_ip']=$spbill_create_ip;
- $sign=getSign($dataArr,$wx_config['key']);
- $data="<xml>
- <mch_appid>".$mch_appid."</mch_appid>
- <mchid>".$mchid."</mchid>
- <nonce_str>".$nonce_str."</nonce_str>
- <partner_trade_no>".$partner_trade_no."</partner_trade_no>
- <openid>".$openid."</openid>
- <check_name>".$check_name."</check_name>
- <re_user_name>".$re_user_name."</re_user_name>
- <amount>".$amount."</amount>
- <desc>".$desc."</desc>
- <spbill_create_ip>".$spbill_create_ip."</spbill_create_ip>
- <sign>".$sign."</sign>
- </xml>";
- $ch = curl_init ();
- $MENU_URL="https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";
- curl_setopt ( $ch, CURLOPT_URL, $MENU_URL );
- curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
- curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
- curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
- // $zs1=APP_ROOT_PATH."public/weixin/apiclient_cert.pem";
- // $zs2=APP_ROOT_PATH."public/weixin/apiclient_key.pem";
- $zs1=APP_ROOT_PATH.$wx_config['sslcert'];
- $zs2=APP_ROOT_PATH.$wx_config['sslkey'];
- curl_setopt($ch,CURLOPT_SSLCERT,$zs1);
- curl_setopt($ch,CURLOPT_SSLKEY,$zs2);
- // curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01;
- // Windows NT 5.0)');
- curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
- curl_setopt ( $ch, CURLOPT_AUTOREFERER, 1 );
- curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
- $info = curl_exec ( $ch );
- if (curl_errno ( $ch )) {
- log_result_wx('Errno' . curl_error ( $ch ));
- }
- curl_close ( $ch );
- $return = (array)simplexml_load_string($info, 'SimpleXMLElement', LIBXML_NOCDATA);
- if($return['return_code']=='SUCCESS'&&$return['result_code']=='SUCCESS'){
- $refund_data = array();
- $refund_data = M("UserRefund")->getById($refund_id);
- $refund_data['pay_log'] ='已付款';
- $refund_data['is_pay'] =3;
- $refund_data['partner_trade_no'] =$partner_trade_no;
- $refund_data['ybdrawflowid'] =$return['payment_no'];
- $refund_data['pay_time'] =NOW_TIME;
- $refund_data['confirm_cash_ip'] = get_client_ip();
- M("UserRefund")->save($refund_data);
- $res_up_m = M("UserRefund")->save($refund_data);
- if(!$res_up_m){
- $sql = "update ".DB_PREFIX."user_refund set pay_log='已付款',is_pay = 3,partner_trade_no = '".$partner_trade_no."',ybdrawflowid='".$return['payment_no']."',pay_time = ".NOW_TIME.",confirm_cash_ip = '".get_client_ip()."' where id = ".$order_id;
- $res = $GLOBALS['db']->query($sql);
- }
- $payment_data = array();
- $payment_data = M("Payment")->getById($payment_info['id']);
- $payment_data['total_amount'] =$payment_data['total_amount']+$msg_item['money'];
- $res_p_m = M("Payment")->save($payment_data);
- if(!$res_p_m){
- $sql = "update ".DB_PREFIX."payment set total_amount = total_amount + ".$msg_item['money']." where id = ".$payment_info['id'];
- $res = $GLOBALS['db']->query($sql);
- }
- return true;
- }else{
- $refund_data = array();
- $refund_data = M("UserRefund")->getById($order_id);
- $refund_data['pay_log'] =$return['return_msg'].$return['err_code_des'];
- $refund_data['partner_trade_no'] =$partner_trade_no;
- $refund_data['is_pay'] = 4;
- $refund_data['confirm_cash_ip'] = get_client_ip();
- $res_up_m = M("UserRefund")->save($refund_data);
- if(!$res_up_m){
- $GLOBALS['db']->query("update ".DB_PREFIX."user_refund set confirm_cash_ip = '".get_client_ip()."' is_pay=4,pay_log = '".$return['return_msg']."',partner_trade_no = '".$partner_trade_no."' where id = ".$order_id);
- }
- return false;
- }
- }
- }
- /**
- * 作用:生成签名
- */
- function getSign($Obj,$key)
- {
- //var_dump($Obj);//die;
- foreach ($Obj as $k => $v)
- {
- $Parameters[$k] = $v;
- }
- //签名步骤一:按字典序排序参数
- ksort($Parameters);
- $String = formatBizQueryParaMap($Parameters, false);
- //echo '【string1】'.$String.'</br>';
- //签名步骤二:在string后加入KEY
- $String = $String."&key=".$key;
- //echo "【string2】".$String."</br>";
- //签名步骤三:MD5加密
- $String = md5($String);
- //echo "【string3】 ".$String."</br>";
- //签名步骤四:所有字符转为大写
- $result_ = strtoupper($String);
- //echo "【result】 ".$result_."</br>";
- return $result_;
- }
- /**
- * 作用:格式化参数,签名过程需要使用
- */
- function formatBizQueryParaMap($paraMap, $urlencode)
- {
- $buff = "";
- ksort($paraMap);
- foreach ($paraMap as $k => $v)
- {
- if($urlencode)
- {
- $v = urlencode($v);
- }
- //$buff .= strtolower($k) . "=" . $v . "&";
- $buff .= $k . "=" . $v . "&";
- }
- //$reqPar;
- if (strlen($buff) > 0)
- {
- $reqPar = substr($buff, 0, strlen($buff)-1);
- }
- return $reqPar;
- }
- /**
- * 获得查询次数以及查询时间
- *
- * @access public
- * @return string
- */
- function run_info()
- {
- if(!SHOW_DEBUG)return "";
- $query_time = number_format($GLOBALS['db']->queryTime,6);
- if($GLOBALS['begin_run_time']==''||$GLOBALS['begin_run_time']==0)
- {
- $run_time = 0;
- }
- else
- {
- if (PHP_VERSION >= '5.0.0')
- {
- $run_time = number_format(microtime(true) - $GLOBALS['begin_run_time'], 6);
- }
- else
- {
- list($now_usec, $now_sec) = explode(' ', microtime());
- list($start_usec, $start_sec) = explode(' ', $GLOBALS['begin_run_time']);
- $run_time = number_format(($now_sec - $start_sec) + ($now_usec - $start_usec), 6);
- }
- }
- /* 内存占用情况 */
- if (function_exists('memory_get_usage'))
- {
- $unit=array('B','KB','MB','GB');
- $size = memory_get_usage();
- $used = @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
- $memory_usage = "占用内存 ".$used;
- }
- else
- {
- $memory_usage = '';
- }
- /* 是否启用了 gzip */
- $enabled_gzip = (app_conf("GZIP_ON") && function_exists('ob_gzhandler'));
- $gzip_enabled = $enabled_gzip ? "gzip开启" : "gzip关闭";
- $str = '共执行 '.$GLOBALS['db']->queryCount.' 个查询,用时 '.$query_time.' 秒,'.$gzip_enabled.','.$memory_usage.',程序执行时间 '.$run_time.' 秒';
- foreach($GLOBALS['db']->queryLog as $K=>$sql)
- {
- if($K==0)$str.="<br />SQL语句列表:";
- $str.="<br />行".($K+1).":".$sql;
- }
- return "<div style='width:940px; padding:10px; line-height:22px; border:1px solid #ccc; text-align:left; margin:30px auto; font-size:14px; color:#999; height:150px; overflow-y:auto;'>".$str."</div>";
- }
- function update_sys_config()
- {
- $filename = APP_ROOT_PATH."public/sys_config.php";
- if(!file_exists($filename))
- {
- //定义DB
- require APP_ROOT_PATH.'system/db/db.php';
- $dbcfg = require APP_ROOT_PATH."public/db_config.php";
- define('DB_PREFIX', $dbcfg['DB_PREFIX']);
- if(!file_exists(APP_ROOT_PATH.'public/runtime/app/db_caches/'))
- mkdir(APP_ROOT_PATH.'public/runtime/app/db_caches/',0777);
- $pconnect = false;
- $db = new mysql_db($dbcfg['DB_HOST'].":".$dbcfg['DB_PORT'], $dbcfg['DB_USER'],$dbcfg['DB_PWD'],$dbcfg['DB_NAME'],'utf8',$pconnect);
- //end 定义DB
- $sys_configs = $db->getAll("select * from ".DB_PREFIX."conf");
- $config_str = "<?php\n";
- $config_str .= "return array(\n";
- foreach($sys_configs as $k=>$v)
- {
- $config_str.="'".$v['name']."'=>'".addslashes($v['value'])."',\n";
- }
- $config_str.=");\n ?>";
- file_put_contents($filename,$config_str);
- $url = APP_ROOT."/";
- app_redirect($url);
- }
- }
- function get_admin_nav($role_id,$adm_name){
- if(CHANGE_NAV=='default'||!defined('CHANGE_NAV')){
- if($adm_name == app_conf('DEFAULT_ADMIN')){
- if(defined("MODULE_ADMIN")&&MODULE_ADMIN==1){
- $navs = require_once APP_ROOT_PATH."system/admnav_cfg_pc.php";
- }else{
- $navs = require_once APP_ROOT_PATH."system/admnav_cfg.php";
- }
- }else{
- $navs = load_auto_cache("admin_nav",array('id'=>$role_id));
- }
- if($_REQUEST['change_nav']){
- $navs = require_once APP_ROOT_PATH."system/admnav_cfg_".$_REQUEST['change_nav'].".php";
- }
- }else{
- $navs = require_once APP_ROOT_PATH."system/admnav_cfg_".CHANGE_NAV.".php";
- }
- return deal_admin_nav($navs);
- }
- function deal_admin_nav($navs){
- if(!defined("OPEN_FAMILY_MODULE")||OPEN_FAMILY_MODULE==0){
- unset($navs['user']['groups']['family']);
- unset($navs['payment']['groups']['cash']['nodes'][2]);
- }
- $m_config = load_auto_cache("m_config");//初始化手机端配置 ljz
- if(!defined("OPEN_SOCIETY_MODULE")||OPEN_SOCIETY_MODULE==0||$m_config['society_pattern']==0){//添加公会模式开关
- unset($navs['user']['groups']['society']);
- //unset($navs['user']['groups']['society']['nodes'][1]);
- //unset($navs['payment']['groups']['cash']['nodes'][1]);
- }else{
- unset($navs['user']['groups']['family']);
- unset($navs['payment']['groups']['cash']['nodes'][2]);
- }
- if($m_config['society_pattern']!=2){//非无抽成模式下关闭公会收益列表、公会提现列表
- unset($navs['user']['groups']['society']['nodes'][1]);
- unset($navs['payment']['groups']['cash']['nodes'][1]);
- }
-
- if(!defined("OPEN_LUCK_NUM")||OPEN_LUCK_NUM==0){
- unset($navs['system']['groups']['lucknum']);
- }
- if(!defined("OPEN_ADS")||OPEN_ADS==0){
- unset($navs['system']['groups']['ads']);
- }
- if(intval(OPEN_SLBGROUP)==0){
- unset($navs['system']['groups']['slbgroupconf']);
- }
- if (!defined("OPEN_GAME_MODULE")||OPEN_GAME_MODULE==0) {
- unset($navs['PlugIn']['groups']['gameconf']);
- } else {
- if (!defined("OPEN_BANKER_MODULE")||OPEN_BANKER_MODULE==0) {
- foreach ($navs['PlugIn']['groups']['gameconf']['nodes'] as $key => $value) {
- if ($value['action']=='bankerLog') {
- unset($navs['PlugIn']['groups']['gameconf']['nodes'][$key]);
- }
- }
- }
- if (defined('OPEN_DIAMOND_GAME_MODULE') && OPEN_DIAMOND_GAME_MODULE == 1) {
- foreach ($navs['PlugIn']['groups']['gameconf']['nodes'] as $key => $value) {
- $navs['PlugIn']['groups']['gameconf']['nodes'][$key]['name'] = str_replace('金币', '钻石', $value['name']);
- }
- }
- }
- if (!defined("SHOPPING_GOODS")||SHOPPING_GOODS==0) {
- unset($navs['PlugIn']['groups']['goodsconf']);
- unset($navs['PlugIn']['groups']['user_goodsconf']);
- }
- if((!defined("OPEN_PAI_MODULE")||OPEN_PAI_MODULE==0) && (!defined("SHOPPING_GOODS")||SHOPPING_GOODS==0)){
- unset($navs['PlugIn']['groups']['goods_complaint']);
- }
- if (!defined("OPEN_PAI_MODULE")||OPEN_PAI_MODULE==0) {
- unset($navs['PlugIn']['groups']['pai_goods']);
- unset($navs['PlugIn']['groups']['goods_order']);
- }
- if(!defined("OPEN_PODCAST_GOODS")||OPEN_PODCAST_GOODS==0){
- foreach ($navs['PlugIn']['groups']['user_goodsconf']['nodes'] as $key => $value) {
- if ($value['module']=='PodcastGoods') {
- unset($navs['PlugIn']['groups']['user_goodsconf']['nodes'][$key]);
- }
- }
- }
- if(!defined("PAI_VIRTUAL_BTN")||PAI_VIRTUAL_BTN==0){
- foreach ($navs['PlugIn']['groups']['goods_order']['nodes'] as $key => $value) {
- if ($value['module']=='PaiTags') {
- unset($navs['PlugIn']['groups']['goods_order']['nodes'][$key]);
- }
- }
- }
- if (!defined("OPEN_EDU_MODULE")||OPEN_EDU_MODULE==0) {
- unset($navs['edu_courses']);
- }
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- if($m_config['name_limit']==0){
- unset($navs['system']['groups']['mobile']['nodes'][2]);
- }
- if($m_config['has_dirty_words']==0){
- unset($navs['system']['groups']['mobile']['nodes'][1]);
- }
- if(!defined("OPEN_VIP")||OPEN_VIP==0){
- unset($navs['system']['groups']['sysconf']['nodes'][4]);
- }
- if(!defined("OPEN_DISTRIBUTION")||OPEN_DISTRIBUTION==0){
- unset($navs['user']['groups']['distribution']);
- }
- if(!defined("CHECK_VIDEO")||CHECK_VIDEO==0){
- unset($navs['dealcate']['groups']['video']['nodes'][5]);
- }
- //微信分销
- if (!defined('WEIXIN_DISTRIBUTION') || WEIXIN_DISTRIBUTION==0) {
- unset($navs['user']['groups']['wx_distribution']);
- }
- //推广分销
- if (!defined('GAME_DISTRIBUTION_TOP') || GAME_DISTRIBUTION_TOP==0) {
- unset($navs['user']['groups']['tg_distribution']);
- }
- //子房间
- if(!defined('CHILD_ROOM') || CHILD_ROOM == 0){
- unset($navs['dealcate']['groups']['childroom']);
- }
- //西藏青稞
- if(!defined('QK_TREE') || QK_TREE == 0){
- unset($navs['qk_tree']['groups']['qk_tree']);
- }
-
- return $navs;
- }
- /*
- * @return 删除过期的验证码
- */
- function delete_mobile_verify_code(){
- $time=app_conf("USER_SEND_VERIFY_TIME")?app_conf("USER_SEND_VERIFY_TIME"):300;
- $n_time=get_gmtime()-$time;
- //删除超过时间的验证码
- $GLOBALS['db']->query("DELETE FROM ".DB_PREFIX."mobile_verify_code WHERE create_time <=".$n_time);
- }
- function theme_parse_css($urls)
- {
- $url = md5(implode(',',$urls));
- $css_url = 'public/runtime/statics/'.$url.'.css';
- $url_path = APP_ROOT_PATH.$css_url;
- if(!file_exists($url_path))
- {
- if(!file_exists(APP_ROOT_PATH.'public/runtime/statics/'))
- mkdir(APP_ROOT_PATH.'public/runtime/statics/',0777);
- $tmpl_path = get_domain().APP_ROOT."/theme";
- $css_content = '';
- foreach($urls as $url)
- {
- $css_content .= @file_get_contents($url);
- }
- $css_content = preg_replace("/[\r\n]/",'',$css_content);
- $css_content = str_replace("../../images",$tmpl_path."/images/",$css_content);
- $css_content = str_replace("../images/",$tmpl_path."/images/",$css_content);
- // @file_put_contents($url_path, unicode_encode($css_content));
- @file_put_contents($url_path, $css_content);
- }
- return get_domain().APP_ROOT."/".$css_url."?v=1.0";
- }
- //添加图片前缀
- function add_domain_url($image){
- if(strpos($image, 'http://')===false){
- $image = str_replace('images/',file_domain().'/theme/images/',$image);
- $image = str_replace('./public/',file_domain().'/public/',$image);
- }
- return $image;
- }
- //删除图片前缀
- function del_domain_url($image){
- if(strchr($image,'http://')!==false){
- $image = str_replace(file_domain().'/public/','/public/',$image);
- /*$index = strpos($image,'/public');
- $image = '.'.substr($image,$index);*/
- }
- return $image;
- }
- //检查会员等级
- /*function chack_grade($user_id){
- //$user_info= $GLOBALS['db']->getRow("select u.score,u.online_time,u.user_level from ".DB_PREFIX."user as u where u.id=".$user_id);
- //redis 读取
- require_once(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
- require_once(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
- $user_redis = new UserRedisService();
- $user_info = $user_redis->getRow_db($user_id,array('score','online_time','user_level'));
- $up_score = $user_info['score']+floor($user_info['online_time']/app_conf('ONLINETIME_TO_EXPERIENCE'));
- $level_info = $GLOBALS['db']->getRow("select ul.name as level_name,ul.level as level,ul.icon as icon from ".DB_PREFIX."user_level as ul where ul.score<=".$up_score." ORDER BY ul.id DESC limit 0,1");
- if(intval($user_id)>0&&$user_info['user_level']<$level_info['level']){
- $status =$GLOBALS['db']->query("update ".DB_PREFIX."user set user_level=".$level_info['level']." where id=".$user_id);
- //redis 更新
- $user['user_level'] = $level_info['level'];
- $status = $user_redis->update_db($user_id,$user);
- }
- }*/
- function agentArr(){
- $agent = $_SERVER['HTTP_USER_AGENT'];
- $agent_array = array();
- if($agent){
- $agent_arr = explode(" ",$agent);
- foreach($agent_arr as $k=>$v){
- $kkv = explode("/",$v);
- $agent_array[$kkv[0]] = strim($kkv[1]);
- }
- }
- return $agent_array;
- }
- /**
- * 散列算法
- * @param unknown_type $value 计算散列的基础值
- * @param unknown_type $count 散列的总基数
- * @return number
- */
- function hash_table($value,$count)
- {
- $pid = intval(round(hexdec(md5($value))/pow(10,32))%$count);
- return $pid;
- }
- function file_domain(){
- if($GLOBALS['distribution_cfg']['CSS_JS_OSS']&&$GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']!="NONE")
- {
- $domain = $GLOBALS['distribution_cfg']['OSS_FILE_DOMAIN'];
- }
- else
- {
- $domain = get_domain().APP_ROOT;
- }
- return $domain;
- }
- //发登录超时短信
- function send_tips_sms($mobile,$overtime)
- {
- return $GLOBALS['msg']->sms_tips($mobile,$overtime);
- }
- //获取一个新的用户号,同时记录分配给那个系统使用
- function get_max_user_id($sysid=0){
- $user_id = get_max_user_id_fun($sysid);
- if (OPEN_LUCK_NUM == 1){//如果开启了新版靓号功能
- if(check_luck_num($user_id)){
- //重新生成
- $user_id = get_max_user_id($sysid);
- }
- }else {//没开启靓号,继续使用最初版幸运号逻辑
- if (chack_lucky_num($user_id)) {
- $data=array();
- $data['id'] = $user_id ;
- $data['nick_name']= "系统保留吉祥号";
- $data['is_effect'] = 1;
- $data['sex']= 1;
- $data['create_time']= NOW_TIME;
- $data['user_pwd']= md5(rand(100000,999999));
- $data['login_ip'] = CLIENT_IP;
- $data['login_time'] = to_date(NOW_TIME);
- $data['synchronize'] = 0;
- $data['emotional_state'] ='保密';
- if($data['city']==''&&$data['province']==''){
- $data['province'] = '火星';
- }
- $data['job'] = '主播';
- $data['user_level'] = 1;
- $GLOBALS['db']->autoExecute(DB_PREFIX."user",$data);
- $user_info = $data;
- // ===========add start ===========
- fanwe_require (APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
- $user_redis = new UserRedisService();
- $ridis_data = $user_redis->reg_data($data);
- $user_redis->insert_db($user_id,$ridis_data);
- $user_info = $data;
- // 登录成功 同步信息
- accountimport($user_info);
- }
- }
- return $user_id;
- }
- //获取一个新的用户号,同时记录分配给那个系统使用
- function get_max_user_id_fun($sysid=0){
- $sql = "insert into ".DB_PREFIX."user_id (id,sysid) values(0,$sysid)";
- $GLOBALS['db']->query($sql);
- $user_id = $GLOBALS['db']->insert_id();
- return $user_id;
- }
- //判断 吉祥号
- function chack_lucky_num($user_id=0){
- $m_config = load_auto_cache("m_config");
- $lucky_num = explode(",",$m_config['lucky_num']);
- return in_array($user_id, $lucky_num);
- }
- //判断id是否是靓号
- function check_luck_num($user_id=0){
- $sql = "SELECT * FROM ".DB_PREFIX."luck_num where luck_num = ".$user_id;
- $result = array();
- $result = $GLOBALS['db']->getRow($sql,true,true);
- return $result;
- }
- function log_file($word,$file_name='log_file')
- {
- if(!IS_DEBUG){
- return false;
- }
- $file = APP_ROOT_PATH."/public/".$file_name.".log";
- if (is_array($word)) $word = var_export($word,true);
- $fp = fopen($file,"a");
- flock($fp, LOCK_EX) ;
- fwrite($fp,"执行日期:".strftime("%Y-%m-%d-%H:%M:%S",time())."\n".$word."\n\n");
- flock($fp, LOCK_UN);
- fclose($fp);
- }
- function get_abs_img_root($content)
- {
- return str_replace("./public/",file_domain()."/public/",$content);
- //return str_replace('/mapi/','/',$str);
- }
- /**
- *更新会员等
- *$user_data 要包括会员id,会员等级,会员信用值
- * */
- function user_leverl_syn($user_data)
- {
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
- //$user_redis = new UserRedisService($user_data['id']);
- $user_redis = new UserRedisService();
- $m_config = load_auto_cache("m_config");
- //合并等级 判断,用户当前等级积分
- $ote = floatval($m_config['onlinetime_to_experience']);
- if ($ote > 0){
- $user_score = $user_data['score']+floor($user_data['online_time']*$ote);
- }else{
- $user_score = $user_data['score'];
- }
- //$user_score = $user_data['score']+floor($user_data['online_time']/app_conf('ONLINETIME_TO_EXPERIENCE'));
- //$user_score = $user_data['score'];
- //用户获取当前等级
- //旧的,获取等级
- // $user_current_level = $GLOBALS['db']->getRow("select point from ".DB_PREFIX."user_level where `level` = ".intval($user_data['user_level']),true,true);
- //$user_current_level = load_auto_cache("user_level_lv",array('lv'=>intval($user_data['user_level'])));
- //新的,通过redis获取等级
- $user_level_info = load_auto_cache("user_level");
- $user_level = null;
- foreach($user_level_info as $v){
- // 两层关系即可
- unset($user_level['next_level']);
- $v['next_level'] = $user_level;
- $user_level = $v;
- if($v['point']<=intval($user_score)){
- break;
- }
- }
- //旧的,获取最高等级积分信息
- //$user_level = $GLOBALS['db']->getRow("select point,level from ".DB_PREFIX."user_level where point <=".intval($user_score)." order by point desc",true,true);
- if(intval($user_data['user_level'])<$user_level['level'])
- {
- //$user_data['user_level'] = intval($user_level['level']);
- $GLOBALS['db']->query("update ".DB_PREFIX."user set user_level = ".$user_level['level']." where id = ".$user_data['id']);
- $data = array();
- $data['user_level'] = $user_level['level'];
- $user_redis->update_db($user_data['id'],$data);
- //$pm_content = "恭喜您,您已经成为".$user_level['name']."等级的会员!";
- //send_notify($user_data['id'], $pm_content, "account#point");
- }
- /*
- if($user_current_level['point']>$user_level['point'])
- {
- $user_data['user_level'] = intval($user_level['level']);
- $GLOBALS['db']->query("update ".DB_PREFIX."user set user_level = ".$user_data['user_level']." where id = ".$user_data['id']);
- $data = array();
- $data['user_level'] = $user_data['user_level'];
- $user_redis->update_db($user_data['id'],$user_data);
- //$pm_content = "很报歉,您的会员等级已经降为".$user_level['name']."!";
- //send_notify($user_data['id'], $pm_content, "account#point");
- }
- */
- $user_level['u_score'] = $user_score;
- return $user_level;
- }
- /**
- *更新会员等
- *$user_data 要包括会员id,会员等级,会员信用值
- * */
- function family_level_syn($family_info)
- {
- $family_score = $family_info['score'];
- $family_level_info = load_auto_cache("family_level");
- $family_level = null;
- foreach($family_level_info as $v) {
- // 两层关系即可
- unset($family_level['next_level']);
- $v['next_level'] = $family_level;
- $family_level = $v;
- if ($v['point'] <= intval($family_score)) {
- break;
- }
- }
- if($family_level && intval($family_info['family_level']) < $family_level['level'])
- {
- $GLOBALS['db']->query("update ".DB_PREFIX."family set family_level = ".$family_level['level']." where id = ".$family_info['family_id']);
- // $data = array();
- // $data['family_level'] = $family_level['level'];
- // $$family_redis->update_db($family_info['id'],$data);
- }
- return $family_level;
- }
- function fanwe_require($file){
- static $_importFile = array();
- $filename = realpath($file);
- if(!isset($_importFile[$filename])){
- //做兼容性,只有强制定义了 FANWE_REQUIRE 常量后,才使用 后台用require,否则使用:require_once
- if(defined('FANWE_REQUIRE')){
- $_importFile[$filename] = require $file;
- }else{
- $_importFile[$filename] = require_once $file;
- }
- }
- return $_importFile[$filename];
- }
- function FanweServiceCall($class='index',$act='index',$data=array())
- {
- if(file_exists(APP_ROOT_PATH."service/config.php")){
- $config = fanwe_require(APP_ROOT_PATH."service/config.php");
- }
- if(!isset($config[$class])){
- $config[$class] = "fanwe";
- }
- @fanwe_require(APP_ROOT_PATH."service/".$config[$class]."/".$class.".service.php");
- $objClass = $class."Service";
- if(class_exists($objClass)){
- $obj=new $objClass;
- if(method_exists($obj, $act)){
- return $obj->$act($data);
- }
- else{
- $error["status"] = 10006;
- $error["error"] = "接口方法不存在";
- ajax_return($error);
- }
- }
- else{
- $error["status"] = 10005;
- $error["error"] = "接口不存在";
- ajax_return($error);
- }
- }
- /**
- * 获取毫秒
- */
- function get_microtime(){
- list($usec, $sec) = explode(" ", microtime());
- $microtime = ((int)($usec * 1000) + (float)$sec * 1000);
- return $microtime;
- }
- /*
- * 获取不在 $array_2数组中的值
- */
- function array_diff_info($array_2,$array_1 ) {
- $array_2 = array_flip($array_2);
- foreach ($array_1 as $key => $item) {
- if (isset($array_2[$item])) {
- unset($array_1[$key]);
- }
- }
- return $array_1;
- }
- /**
- * TimApi推送
- * 'MsgType' => 'TIMCustomElem',
- */
- function get_tim_api($data){
- #构造高级接口所需参数
- $msg_content = array();
- //创建array 所需元素
- $msg_content_elem = array(
- 'MsgType' => 'TIMCustomElem', //自定义类型
- 'MsgContent' => array(
- 'Data' => json_encode($data['ext']),
- 'Desc' => '',
- )
- );
- //将创建的元素$msg_content_elem, 加入array $msg_content
- array_push($msg_content, $msg_content_elem);
- fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
- $api = createTimAPI();
- return $api->group_send_group_msg2(trim($data['podcast_id']), $data['group_id'], $msg_content);
- }
- function timSystemNotify($group_id,$msg,$to = array()){
- fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
- $msg['timestamp'] = microtime(1);
- $msg['user_id'] = sizeof($to) == 1 ? intval($to[0]) : 0;
- $api = createTimAPI();
- return $api->group_send_group_system_notification2($group_id,json_encode($msg),$to);
- }
- function isApp(){
- $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
- $is_app = strpos($agent, 'fanwe_app_sdk') ? true : false ;
- if($is_app){
- return true;
- }else{
- return false;
- }
- }
- /**
- * 将 diamonds,use_diamonds,score,ticket,user_level,refund_ticket 几个字段值,同步到redis
- * @param array $user_ids
- */
- function user_deal_to_reids($user_ids)
- {
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
- $user_redis = new UserRedisService();
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- /*$fields = 'id,nick_name,head_image,sex,diamonds,use_diamonds,score,ticket,user_level,refund_ticket,is_authentication,v_icon,v_explain,v_type,emotional_state,province,city,job,signature,birthday,video_count';
- if(defined('OPEN_VIP')&&OPEN_VIP==1){
- $fields.=',is_vip,vip_expire_time';
- }
- if((defined('OPEN_GAME_MODULE')&&OPEN_GAME_MODULE==1)){
- $fields.=',coin';
- }*/
- $fields = ' * ';
- foreach ($user_ids as $user_id) {
- $sql = "select ".$fields." from ".DB_PREFIX."user where id = ".$user_id;
- //echo $sql."<br>";
- $user_data = $GLOBALS['db']->getRow($sql);
- //print_r($user_data);
- $user_redis->update_db($user_id, $user_data);
- }
- }
- //将机器人同步到IM
- function accountimport_robots($user_id){
- fanwe_require(APP_ROOT_PATH."system/libs/user.php");
- $user_data = $GLOBALS['db']->getRow("SELECT id,nick_name,head_image,synchronize FROM ".DB_PREFIX."user where id=".$user_id." and is_robot=1 ");
- accountimport($user_data);
- }
- function account_log_com($data,$user_id,$log_msg='',$param=array())
- {
- fanwe_require(APP_ROOT_PATH."system/libs/user.php");
- account_log($data,$user_id,$log_msg,$param);
- }
- function origin_image_info($img_path)
- {
- if (!isset($GLOBALS['distribution_cfg']['OSS_TYPE']) || $GLOBALS['distribution_cfg']['OSS_TYPE'] != "ALI_OSS") {
- return array('file_name' => $img_path);
- }
- $i = strrpos($img_path, '@');
- if ($i === false) {
- return array('file_name' => $img_path);
- }
- $result = array('file_name' => substr($img_path, 0, $i));
- foreach (explode('_', substr($img_path, $i + 1, strrpos($img_path, '.') - $i - 1)) as $str) {
- $key = substr($str, -1);
- if (strpos($str, '-') === false) {
- $result[$key] = substr($str, 0, -1);
- } else {
- $result[$key] = explode('-', substr($str, 0, -1));
- }
- }
- return $result;
- }
- /*
- * 获取裁剪规格的图片地址(https://help.aliyun.com/document_detail/32228.html?spm=5176.doc32228.6.558.59iwnS)
- * @param string $img_path 图片地址,只支持阿里云oss图片地址
- * @param int $x ===》x轴起始坐标
- * @param int $y===》y轴起始坐标
- * @param int $width ===》高
- * @param int $height===》宽
- * @param int $rotate ===》旋转角度
- * @return String 返回格式化后的图片地址
- *
- *图片旋转, https://help.aliyun.com/document_detail/32230.html?spm=5176.doc32228.6.560.R1A6Ki
- */
- function get_cut_image($img_path,$x=0, $y=0, $width=0,$height=0,$rotate=0)
- {
- if (!isset($GLOBALS['distribution_cfg']['OSS_TYPE']) || $GLOBALS['distribution_cfg']['OSS_TYPE'] != "ALI_OSS") {
- return $img_path;
- }
- $pos = strpos($img_path, $GLOBALS['distribution_cfg']['OSS_DOMAIN']);
- $httppos = strpos($img_path, 'http');
- $pathinfo = pathinfo($img_path);
- if ($pos === false && $httppos === false) {
- //未定位到
- $file = $pathinfo['basename'];
- $dir = $pathinfo['dirname'];
- $dir = str_replace("./public/", "/public/", $dir);
- $file_name = $GLOBALS['distribution_cfg']['OSS_DOMAIN'] . $dir . "/" . $file;
- $pos = 0;
- } else {
- $file_name = $img_path;
- }
- if ($pos === 0) {
- if($rotate < 0){
- $rotate = 360 + $rotate;
- }
- if ($GLOBALS['distribution_cfg']['NEW_OSS']) {
- $file_name .= "?x-oss-process=image/crop,x_{$x},y_{$y},w_{$width},h_{$height}/rotate,{$rotate}";
- } else {
- $format = "@{$x}-{$y}-{$width}-{$height}a_{$rotate}r.";
- if (isset($pathinfo['extension'])) {
- $extension = strtolower($pathinfo['extension']);
- } else {
- $extension = "jpg";
- }
- $file_name .= $format . $extension;
- }
- }
- return $file_name;
- }
- /*
- * 获取相应规格的图片地址(https://help.aliyun.com/document_detail/32206.html?spm=5176.doc32206.6.488.Y4uU6M)
- * @param string $img_path 图片地址,只支持阿里云oss图片地址
- * @param int $width ===》高
- * @param int $height===》宽
- * @param int $gen gen=0:保持比例缩放,不剪裁,如高为0,则保证宽度按比例缩放 gen=1:保证长宽,剪裁
- *
- * @param int $radius ===》模糊效果,取值在 [1,50], radius越大,越模糊
- * @param int $sigma===》模糊效果 ,取值 [1,50],越大,越模糊
- * @return String 返回格式化后的图片地址
- *
- *模糊效果, https://help.aliyun.com/document_detail/32234.html?spm=5176.doc32233.6.516.zuzpF7
- */
- function get_spec_image($img_path,$width=0,$height=0,$gen=0, $radius=0,$sigma=0)
- {
- if($img_path==''){
- return ;
- }
- //关于ALIOSS的生成
- if ($GLOBALS['distribution_cfg']['OSS_TYPE'] && $GLOBALS['distribution_cfg']['OSS_TYPE'] == "ALI_OSS") {
- $pos = strpos($img_path, $GLOBALS['distribution_cfg']['OSS_DOMAIN']);
- $httppos = strpos($img_path, 'http');
- if ($pos === false && $httppos === false) {
- //未定位到
- $pathinfo = pathinfo($img_path);
- $file = $pathinfo['basename'];
- $dir = $pathinfo['dirname'];
- $dir = str_replace("./public/", "/public/", $dir);
- $allow_extension = array('mp4','flv','m3u8');
- $extension = pathinfo($file, PATHINFO_EXTENSION);
- $is_allow = in_array($extension,$allow_extension);
- if($width!=0||$height!=0||$gen!=0||$radius!=0||$sigma!=0||$GLOBALS['distribution_cfg']['OSS_DOMAIN_HTTPS']==''||$is_allow){
- $file_name = $GLOBALS['distribution_cfg']['OSS_DOMAIN'] . $dir . "/" . $file;
- }else{
- $file_name = $GLOBALS['distribution_cfg']['OSS_DOMAIN_HTTPS'] . $dir . "/" . $file;
- return $file_name;
- }
- $pos = 0;
- } else {
- $file_name = $img_path;
- }
- if ($GLOBALS['distribution_cfg']['NEW_OSS']) {
- if ($pos === 0) {
- $format = "";
- if ($width == 0 && $height > 0) {
- $format = "/resize,h_".$height; //高固定,宽按图片大小等比缩放
- } else if ($height == 0 && $width > 0) {
- $format = "/resize,w_".$width;//宽固定,高按图片大小等比缩放
- } else if ($width > 0 && $height > 0) {
- if ($gen == 0)
- $format = "/resize,m_mfit,h_" . $height . ",w_". $width;//宽,高固定,以短边缩放 1e 不剪裁
- else
- $format = "/resize,m_fill,m_mfit,h_" . $height . ",w_". $width;//宽,高固定,以短边缩放 1e 剪裁
- }
- if ($radius > 0 && $sigma > 0) {
- if ($format == '')
- $format = "/blur,r_" . $radius . ",s_" . $sigma;
- else
- $format = $format."/blur,r_" . $radius . ",s_" . $sigma;
- }
- if ($format != '') {
- $i = strrpos($file_name, '?x-oss-process=image');
- if ($i === false) {
- $file_name = $file_name . '?x-oss-process=image' . $format;
- } else {
- $file_name .= $format;
- }
- }
- }
- }else{
- if ($pos === 0) {
- $format = "";
- if ($width == 0 && $height > 0) {
- $format = $height . "h_1l_1x"; //高固定,宽按图片大小等比缩放
- } else if ($height == 0 && $width > 0) {
- $format = $width . "w_1l_1x";//宽固定,高按图片大小等比缩放
- } else if ($width > 0 && $height > 0) {
- if ($gen == 0)
- $format = $width . "w_" . $height . "h_0c_1e_1x"; //宽,高固定,以短边缩放 1e 不剪裁
- else
- $format = $width . "w_" . $height . "h_1c_1e_1x"; //宽,高固定,以短边缩放 1e 剪裁
- }
- if ($radius > 0 && $sigma > 0) {
- if ($format == '')
- $format = $radius . "-" . $sigma . "bl";
- else
- $format = "_" . $radius . "-" . $sigma . "bl";
- }
- if ($format != '') {
- $i = strrpos($file_name, '@');
- if ($i === false) {
- $file_name = $file_name . '@' . $format . ".jpg";
- } else {
- $i = strrpos($file_name, '.');
- $file_name = substr($file_name, 0, $i) . '_' . $format . substr($file_name, $i);
- }
- }
- }
- }
- return $file_name;
- } else {
- $domain = get_domain();
- if($GLOBALS['distribution_cfg']['LOCAL_IMAGE_URL'] != "") {
- $domain = $GLOBALS['distribution_cfg']['LOCAL_IMAGE_URL'];
- }
- $img_path = str_replace("./public/",$domain.APP_ROOT."/public/",$img_path);
- return $img_path;
- }
- }
- //登录提示
- function login_prompt($user_id){
- $root = array('first_login'=>0,'new_level'=>0);
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- $login_send_score = intval($m_config['login_send_score']);//每日首次登录赠送积分数
- $upgrade_level = intval($m_config['upgrade_level']);//首次登录升级提示等级
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
- $user_redis = new UserRedisService($user_id);
- //每日首次登录赠送积分
- if(defined("OPEN_LOGIN_SEND_SCORE")&&OPEN_LOGIN_SEND_SCORE == 1){
- if($login_send_score>0){
- $now_time = NOW_TIME;
- /*$now_time = to_date($now_time,"Y-m-d 00:00:00");
- $timezone = intval(app_conf('TIME_ZONE')) * 3600;
- $user_log_id = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "user_log where user_id = ".intval($user_id)." and type = 5 and FROM_UNIXTIME(log_time+".$timezone.",'%Y-%m-%d')='".to_date(NOW_TIME,'Y-m-d')."'");
- */
- $s_now_time = to_timespan(to_date($now_time,"Y-m-d 00:00:00"));
- $e_now_time = to_timespan(to_date($now_time,"Y-m-d 23:59:59"));
- $user_log_id = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "user_log where " .
- "user_id = ".intval($user_id)." and type = 5 and log_time>".$s_now_time." and log_time<".$e_now_time);
- if(intval($user_log_id)==0){
- $user = $user_redis->getRow_db($user_id,array("login_time"));
- if($user['login_time']<$now_time){
- $GLOBALS['db']->query("update ".DB_PREFIX."user set score = score+".$login_send_score." where id =".$user_id);
- user_deal_to_reids(array($user_id));
- $user = $user_redis->getRow_db($user_id,array('id','score','online_time','user_level'));
- user_leverl_syn($user);
- $root['first_login'] = 1;
- //写入用户日志
- $data = array();
- $data['score'] = $login_send_score;
- $data['log_admin_id'] = 0;
- $param['type'] = 5;//类型 0表示充值 1表示提现 2赠送道具 3 兑换印票 4 分享获得印票 5 登录赠送积分
- $log_msg ='每日首次登录获得'.$login_send_score.'积分';
- account_log_com($data,$user_id,$log_msg,$param);
- }
- }
- }
- }
- //每次登录等级提示
- if(defined("OPEN_UPGRADE_PROMPT")&&OPEN_UPGRADE_PROMPT == 1){
- if($upgrade_level){
- $user = $user_redis->getRow_db($user_id,array("user_level","last_login_level"));
- if($user['user_level']>=$upgrade_level && $user["last_login_level"]<$user['user_level']){//等级大于等于升级提示并且上一次登录时的等级小于现在的等级
- $root['new_level'] = $user['user_level'];
- //修改上一次登录时的等级
- $GLOBALS['db']->query("update ".DB_PREFIX."user set last_login_level = ".$user['user_level']." where id =".$user_id);
- $user_redis->update_db($user_id,array("last_login_level"=>$user['user_level']));
- }
- }
- }
- return $root;
- }
- //管理员结束直播
- function admin_do_end_video($video,$video_vid,$is_aborted = 0,$cate_id = 0){
- fanwe_require(APP_ROOT_PATH.'mapi/lib/core/common.php');
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
- //请求同步redis数据到mysql,防止结束时候mysql数据未同步导致的当前处理的数据错误;
- $sql = "SELECT id FROM " . DB_PREFIX . "video";
- $list = $GLOBALS['db']->getAll($sql, true, true);
- if (count($list) > 0) {
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
- $video_redis_syn = new VideoRedisService();
- foreach ($list as $k => $v) {
- $video_id_syn = $v['id'];
- //计算权重
- $video_redis_syn ->syn_sort_num($video_id_syn);
- $fields = array('share_count','like_count','fans_count', 'sort_num', 'vote_number', 'robot_num','watch_number', 'virtual_watch_number', 'max_watch_number');
- $video_syn = $video_redis_syn->getRow_db($video_id_syn, $fields);
- $GLOBALS['db']->autoExecute(DB_PREFIX . "video", $video_syn, "UPDATE", "id=" . $video_id_syn);
- }
- }
- $result = do_end_video($video,$video_vid,$is_aborted,$cate_id);
- return $result;
- }
- //获取后台地址
- function get_manage_url_name(){
- $url_name = "m.php";
- $urlname = app_conf("URL_NAME");
- if($urlname!=$url_name&&$urlname!=''){
- $url_name = $urlname;
- }
- return $url_name;
- }
- function strFilter($str){
- $str = str_replace('`', '', $str);
- $str = str_replace('·', '', $str);
- $str = str_replace('~', '', $str);
- $str = str_replace('!', '', $str);
- $str = str_replace('!', '', $str);
- $str = str_replace('@', '', $str);
- $str = str_replace('#', '', $str);
- $str = str_replace('$', '', $str);
- $str = str_replace('¥', '', $str);
- $str = str_replace('%', '', $str);
- $str = str_replace('^', '', $str);
- $str = str_replace('……', '', $str);
- $str = str_replace('&', '', $str);
- $str = str_replace('*', '', $str);
- $str = str_replace('(', '', $str);
- $str = str_replace(')', '', $str);
- $str = str_replace('(', '', $str);
- $str = str_replace(')', '', $str);
- $str = str_replace('-', '', $str);
- $str = str_replace('_', '', $str);
- $str = str_replace('——', '', $str);
- $str = str_replace('+', '', $str);
- $str = str_replace('=', '', $str);
- $str = str_replace('|', '', $str);
- $str = str_replace('\\', '', $str);
- $str = str_replace('[', '', $str);
- $str = str_replace(']', '', $str);
- $str = str_replace('【', '', $str);
- $str = str_replace('】', '', $str);
- $str = str_replace('{', '', $str);
- $str = str_replace('}', '', $str);
- $str = str_replace(';', '', $str);
- $str = str_replace(';', '', $str);
- $str = str_replace(':', '', $str);
- $str = str_replace(':', '', $str);
- $str = str_replace('\'', '', $str);
- $str = str_replace('"', '', $str);
- $str = str_replace('“', '', $str);
- $str = str_replace('”', '', $str);
- $str = str_replace(',', '', $str);
- $str = str_replace(',', '', $str);
- $str = str_replace('<', '', $str);
- $str = str_replace('>', '', $str);
- $str = str_replace('《', '', $str);
- $str = str_replace('》', '', $str);
- $str = str_replace('.', '', $str);
- $str = str_replace('。', '', $str);
- $str = str_replace('/', '', $str);
- $str = str_replace('、', '', $str);
- $str = str_replace('?', '', $str);
- $str = str_replace('?', '', $str);
- return trim($str);
- }
- //系统错误日志
- function log_err_file($word,$file_name='error_file')
- {
- //log_err_file(array(__FILE__,__LINE__,__METHOD__,$data));
- if (!is_dir(APP_ROOT_PATH."public/sys_error/")) {
- @mkdir(APP_ROOT_PATH."public/sys_error/");
- @chmod(APP_ROOT_PATH."public/sys_error/", 0777);
- }
- $file = APP_ROOT_PATH."/public/sys_error/".$file_name."_".date('Ymd').".log";
- if (is_array($word)) $word = var_export($word,true);
- $fp = fopen($file,"a");
- flock($fp, LOCK_EX) ;
- fwrite($fp,"执行日期:".strftime("%Y-%m-%d-%H:%M:%S",time())."\n".$word."\n\n");
- flock($fp, LOCK_UN);
- fclose($fp);
- //删除大于一个月的日志文件
- $file_time = getlastMonthDays();//获取上个月时间
- $file_name_old = $file_name."_".$file_time;
- $file_old = APP_ROOT_PATH."public/sys_error/".$file_name_old.".log";
- if (file_exists($file_old)) {
- @unlink ($file_old);
- }
- }
- //获取直播信息
- function c_get_vodset_by_video_id($video_id){
- fanwe_require(APP_ROOT_PATH.'mapi/lib/core/common.php');
- $result = get_vodset_by_video_id($video_id);
- return $result;
- }
- /*
- * $url 文件地址
- * $qrcode_name 生成的源文件
- * $qrcode_dir_logo 带logo的源文件
- */
- function get_qrcode_png($url,$qrcode_name,$qrcode_dir_logo){
- require_once APP_ROOT_PATH.'system/utils/phpqrcode.php';
- $value = $url; //二维码内容
- $errorCorrectionLevel = 'L';//容错级别
- $matrixPointSize = 6;//生成图片大小
- //生成二维码图片
- QRcode::png($value, $qrcode_name, $errorCorrectionLevel, $matrixPointSize, 2);
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- $logo = $m_config['app_logo'];//准备好的logo图片
- $QR = $qrcode_name;//已经生成的原始二维码图
- if ($logo !== FALSE) {
- $QR = imagecreatefromstring(file_get_contents($QR));
- $logo = imagecreatefromstring(file_get_contents($logo));
- $QR_width = imagesx($QR);//二维码图片宽度
- $QR_height = imagesy($QR);//二维码图片高度
- $logo_width = imagesx($logo);//logo图片宽度
- $logo_height = imagesy($logo);//logo图片高度
- $logo_qr_width = $QR_width / 5;
- $scale = $logo_width/$logo_qr_width;
- $logo_qr_height = $logo_height/$scale;
- $from_width = ($QR_width - $logo_qr_width) / 2;
- //重新组合图片并调整大小
- imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,
- $logo_qr_height, $logo_width, $logo_height);
- }
- //输出图片
- imagepng($QR, $qrcode_dir_logo);
- }
- /*
- * 数据传输加密
- * @param array $date 输出的数组
- * @param int $r_type 0=>base64;1=>json_encode;2=>array; 4=>aec
- */
- function ajax_return_aes($data,$r_type=1,$is_debug=0){
- header("Content-Type:text/html; charset=utf-8");
- filter_null($data);//过滤null
- //过滤false
- $data = filter_all_false($data);
- $encrypt = $GLOBALS['encrypt'];
- //if(strstr($encrypt['sdk_version_name'],'2.4')||floatval($encrypt['sdk_version_name'])>=2.5||floatval($encrypt['sdk_version_name'])==0){
- $aes_key_list = get_privatekey();
- if(is_array($aes_key_list[0]['aes_key'])){
- $privatekey = $aes_key_list[0]['aes_key'][0];
- }else{
- $privatekey = $aes_key_list[0]['aes_key'];
- }
- $is_aes_extra = get_aes_extra();
- if($encrypt['now_aes_key']!=''&&$is_aes_extra){
- $privatekey = $encrypt['now_aes_key'];
- }
- /*}else{
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- $privatekey = $m_config['tim_sdkappid'];//对称加密KEY
- if(trim($privatekey)==''){
- $ret = array('error'=>'tim_sdkappid为空');
- log_err_file(array(__FILE__,__LINE__,__METHOD__,$ret));
- }
- //判断KEY是否16位,如果不是自动填充0,进行16位截取
- //$privatekey = str_pad($privatekey,16,"0",STR_PAD_RIGHT);
- if(strlen(trim($privatekey))<16){
- $privatekey = trim($privatekey).'0000000000000000';
- }
- }*/
- $privatekey = substr($privatekey,0,16);
- $r_type = intval($r_type);//返回数据格式类型;
- ob_start();
- ob_end_clean();
- if ($r_type == 0)
- {
- echo base64_encode(json_encode($data));
- }else if ($r_type == 1)
- {
- echo json_encode($data);
- }else if ($r_type == 2)
- {
- print_r($data);
- }else if($r_type == 4){
- require_once APP_ROOT_PATH.'system/libs/crypt_aes.php';
- $aes = new CryptAES();
- $aes->set_key($privatekey);
- $aes->require_pkcs5();
- $encText = array();
- $encText['output'] = $aes->encrypt(json_encode($data));
- if(intval(DE_BUGE)){
- $encText['output_debug']['sdk_version_name'] = $encrypt['sdk_version_name'];
- $encText['output_debug']['privatekey'] = $privatekey;
- $encText['output_debug']['data'] = $data;
- $encText['output_debug']['request'] = $_REQUEST;
- }
- echo json_encode($encText);
- };
- exit;
- }
- /*
- * 接收的数据解密
- * @param array $_REQUEST['requestData'] 接收的数据集
- */
- function aes_request_decode(){
- $encrypt = $GLOBALS['encrypt'];
- if($encrypt['i_type']){
- $request = get_aes_decstring();
- $_REQUEST = array_merge($_REQUEST,$request);
- }
- }
- //获得时间时长
- function time_len($time){
- $total_time_format = '';
- if($time/3600>=1){
- $total_time_format.=intval($time/3600).'小时';
- $time = $time%3600;
- }
- if($time/60>=1){
- $total_time_format.=intval($time/60).'分钟';
- $time = $time%60;
- }
- if($time){
- $total_time_format.=intval($time).'秒';
- }
- return $total_time_format;
- }
- //登录日志
- function log_login($date)
- {
- $login_log = array();
- $now_time = get_gmtime();
- $login_log['create_time'] = $now_time;
- $login_log['ip'] = get_client_ip();
- $login_log['login_date'] = to_date($now_time);
- $login_log['login_time'] = $now_time;
- $login_log['user_id'] = $date['user_id'];
- $login_log['login_type'] = $date['login_type'];
- $login_log['request'] = $date['request'];
- $login_log['ctl_act'] =$GLOBALS['encrypt']['ctl'].'#'.$GLOBALS['encrypt']['act'];
- $GLOBALS['db']->autoExecute(DB_PREFIX."login_log", $login_log,'INSERT');
- }
- //处理解密
- function get_aes_decstring(){
- require_once APP_ROOT_PATH.'system/libs/crypt_aes.php';
- //获取aes_key
- $is_aes_extra = get_aes_extra();
- $aes_key_list = get_privatekey();
- //获取aes_key
- if($aes_key_list) {
- if(count($aes_key_list)>1){
- foreach($aes_key_list as $k=>$v){
- $privatekey = $v['aes_key'];
- if(count($privatekey)>1){
- foreach($privatekey as $v){
- $request = get_aes_request($v);
- if($request!=''){
- $privatekey = $v;
- break;
- }
- }
- }else{
- $request = get_aes_request($privatekey[0]);
- }
- if($request&&$is_aes_extra){
- $privatekey = $privatekey[0];
- $GLOBALS['encrypt']['now_aes_key'] = $privatekey;
- break;
- }else{
- $GLOBALS['encrypt']['now_aes_key'] = '';
- }
- }
- }else{
- $privatekey = $aes_key_list[0]['aes_key'];
- if(count($privatekey)>1){
- foreach($privatekey as $v){
- $request = get_aes_request($v);
- if($request!=''){
- $privatekey = $v;
- break;
- }
- }
- }else{
- if($privatekey) {
- $privatekey = $privatekey[0];
- $request = get_aes_request($privatekey);
- }
- }
- if($request&&$is_aes_extra){
- $GLOBALS['encrypt']['now_aes_key'] = $privatekey;
- }else{
- $GLOBALS['encrypt']['now_aes_key'] = '';
- }
- }
- }else{
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- $privatekey = $m_config['tim_sdkappid'];//对称加密KEY
- $request = get_aes_request($privatekey);
- if($request!=''&&$is_aes_extra){
- $GLOBALS['encrypt']['now_aes_key'] = $privatekey;
- }else{
- $GLOBALS['encrypt']['now_aes_key'] = '';
- }
- }
- return $request;
- }
- //获取动态秘钥
- function get_privatekey(){
- $is_aes_extra = get_aes_extra();
- if(intval($is_aes_extra)){
- $sql = "SELECT * from ".DB_PREFIX."key_list where is_effect=1 and is_delete=0 order by id desc ";
- }else{
- $sql = "SELECT * from ".DB_PREFIX."key_list where is_effect=1 and is_delete=0 order by id desc limit 1 ";
- }
- $aes_key_list = $GLOBALS['db']->getAll($sql);
- if($aes_key_list){
- foreach($aes_key_list as $k=>$v){
- $aes_key_arr = explode("<br />",nl2br($v['aes_key']));
- if($aes_key_arr){
- foreach($aes_key_arr as &$item){
- $item = trim($item);
- }
- $aes_key_list[$k]['aes_key']=$aes_key_arr;
- }
- }
- }else{
- $aes_key_list = array();
- }
- if($GLOBALS['encrypt']['now_aes_key']){
- $aes_key_list[0]['aes_key'] = $GLOBALS['encrypt']['now_aes_key'];
- }
- return $aes_key_list;
- }
- //解密
- function get_aes_request($privatekey){
- //判断KEY是否16位,如果不是自动填充0,进行16位截取
- $privatekey = trim($privatekey);
- if(trim($privatekey)==''){
- $ret = array('error'=>'tim_sdkappid为空');
- log_err_file(array(__FILE__,__LINE__,__METHOD__,$ret));
- }
- if(strlen(trim($privatekey))<16){
- $privatekey = trim($privatekey).'0000000000000000';
- }
- $privatekey = substr($privatekey,0,16);
- $aes = new CryptAES();
- $aes->set_key($privatekey);
- $aes->require_pkcs5();
- $decString = $aes->decrypt(trim($_REQUEST['requestData']));
- $request = json_decode($decString, 1);
- return $request;
- }
- //判断是否要循环解密
- function get_aes_extra(){
- $encrypt = $GLOBALS['encrypt'];
- $is_aes_extra = 0;
- $ctl_act = $encrypt['ctl']."#".$encrypt['act'];
- if(count($GLOBALS['distribution_cfg']['AES_EXTRA_FUN'])>0&&in_array($ctl_act,$GLOBALS['distribution_cfg']['AES_EXTRA_FUN'])){
- $is_aes_extra = 1;//需要循环解密
- }
- return $is_aes_extra;
- }
- //对emoji表情转义
- function emoji_encode($str){
- $strEncode = '';
- $length = mb_strlen($str,'utf-8');
- for ($i=0; $i < $length; $i++) {
- $_tmpStr = mb_substr($str,$i,1,'utf-8');
- if(strlen($_tmpStr) >= 4){
- $strEncode .= '[[EMOJI:'.rawurlencode($_tmpStr).']]';
- }else{
- $strEncode .= $_tmpStr;
- }
- }
- return $strEncode;
- }
- //对emoji表情转反义
- function emoji_decode($str){
- $strDecode = preg_replace_callback('|\[\[EMOJI:(.*?)\]\]|', function($matches){
- return rawurldecode($matches[1]);
- }, $str);
- return $strDecode;
- }
- //日志输出
- function log_ljz($word)
- {
- if (is_array($word)) $word = var_export($word,true);
- $file = APP_ROOT_PATH."/public/log_ljz.log";
- $fp = fopen($file,"a");
- flock($fp, LOCK_EX) ;
- $res = debug_backtrace();//回溯跟踪
- fwrite($fp,"执行日期:".strftime("%Y-%m-%d-%H:%M:%S",time())."\n 文件所在位置:".$res[0]['file'].",位于第".$res[0]['line']."行\n".$word."\n\n");
- flock($fp, LOCK_UN);
- fclose($fp);
- }
- //获取上个月时间
- function getlastMonthDays($date=0){
- if(!$date){
- $date = date('Ymd',time());
- }else{
- $date = date('Ymd',$date);
- }
- $lastday=date('Ymd',strtotime("$date -1 month "));
- return $lastday;
- }
- //删除文件
- function clear_file($path){
- $result = false;
- if(is_file($path)){
- $result = @unlink($path);
- if(!$result){
- log_err_file(array(__FILE__,__LINE__,__METHOD__,'删除文件 '.$path.' 失败'),'clear_file_error');
- }
- }
- return $result;
- }
- ?>
|