helpers.php 127 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654
  1. <?php
  2. use Illuminate\Support\Facades\Redis;
  3. use Illuminate\Support\Str;
  4. use Illuminate\Support\Arr;
  5. use app\common\services\PermissionService;
  6. use app\common\helpers\Url;
  7. use Ixudra\Curl\Facades\Curl;
  8. use app\common\models\user\WeiQingUsers;
  9. use app\common\services\Utils;
  10. use \app\platform\modules\system\models\SystemSetting;
  11. use \app\common\helpers\Client;
  12. use app\common\helpers\ImageHelper;
  13. if (!function_exists("yz_tpl_ueditor")) {
  14. function yz_tpl_ueditor($id, $value = '', $options = array())
  15. {
  16. if (config('app.framework') == 'platform') {
  17. $file_dir = '';
  18. } else {
  19. $file_dir = '../addons/yun_shop';
  20. }
  21. $s = '';
  22. $fileUploader = resource_get('static/js/fileUploader.min.js');
  23. if (!defined('TPL_INIT_UEDITOR')) {
  24. if (config('app.framework') == 'platform') {
  25. $s .= '<script type="text/javascript" src="' . $file_dir .'/app/common/components/ueditor/ueditor.config.js"></script><script type="text/javascript" src="' . $file_dir . '/app/common/components/ueditor/ueditor.all.min.js"></script><script type="text/javascript" src="' . $file_dir . '/app/common/components/ueditor/lang/zh-cn/zh-cn.js"></script><link href="/static/resource/components/webuploader/webuploader.css" rel="stylesheet"><link href="/static/resource/components/webuploader/style.css" rel="stylesheet">';
  26. } else {
  27. $s .= '<script type="text/javascript" src="' . $file_dir .'/app/common/components/ueditor/ueditor.config.js"></script><script type="text/javascript" src="' . $file_dir . '/app/common/components/ueditor/ueditor.all.min.js"></script><script type="text/javascript" src="' . $file_dir . '/app/common/components/ueditor/lang/zh-cn/zh-cn.js"></script><link href="/web/resource/components/webuploader/webuploader.css" rel="stylesheet"><link href="/web/resource/components/webuploader/style.css" rel="stylesheet">';
  28. }
  29. }
  30. $url = uploadUrl();
  31. $options['height'] = empty($options['height']) ? 200 : $options['height'];
  32. $s .= !empty($id) ? "<textarea id=\"{$id}\" name=\"{$id}\" type=\"text/plain\" style=\"height:{$options['height']}px;\">{$value}</textarea>" : '';
  33. $s .= "
  34. <script type=\"text/javascript\">
  35. var ueditoroption = {
  36. 'autoClearinitialContent' : false,
  37. 'toolbars' : [['fullscreen', 'source', 'preview', '|', 'bold', 'italic', 'underline', 'strikethrough', 'forecolor', 'backcolor', '|',
  38. 'justifyleft', 'justifycenter', 'justifyright', '|', 'insertorderedlist', 'insertunorderedlist', 'blockquote', 'emotion',
  39. 'link', 'removeformat', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight','indent', 'paragraph', 'fontsize', '|',
  40. 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol',
  41. 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', '|', 'anchor', 'map', 'print', 'drafts']],
  42. 'elementPathEnabled' : false,
  43. 'initialFrameHeight': {$options['height']},
  44. 'focus' : false,
  45. 'maximumWords' : 9999999999999
  46. };
  47. var opts = {
  48. type :'image',
  49. direct : false,
  50. multi : true,
  51. tabs : {
  52. 'upload' : 'active',
  53. 'browser' : '',
  54. 'crawler' : ''
  55. },
  56. path : '',
  57. dest_dir : '',
  58. global : false,
  59. thumb : false,
  60. width : 0
  61. };
  62. UE.registerUI('myinsertimage',function(editor,uiName){
  63. editor.registerCommand(uiName, {
  64. execCommand:function(){
  65. require(['fileUploader'], function(uploader){
  66. uploader.upload_url('".$url['upload_url']."');
  67. uploader.image_url('".$url['image_url']."');
  68. uploader.fetch_url('".$url['fetch_url']."');
  69. uploader.delet_url('".$url['delet_url']."');
  70. uploader.show(function(imgs){
  71. if (imgs.length == 0) {
  72. return;
  73. } else if (imgs.length == 1) {
  74. editor.execCommand('insertimage', {
  75. 'src' : imgs[0]['url'],
  76. '_src' : imgs[0]['attachment'],
  77. 'width' : '100%',
  78. 'alt' : imgs[0].filename
  79. });
  80. } else {
  81. var imglist = [];
  82. for (i in imgs) {
  83. imglist.push({
  84. 'src' : imgs[i]['url'],
  85. '_src' : imgs[i]['attachment'],
  86. 'width' : '100%',
  87. 'alt' : imgs[i].filename
  88. });
  89. }
  90. editor.execCommand('insertimage', imglist);
  91. }
  92. }, opts);
  93. });
  94. }
  95. });
  96. var btn = new UE.ui.Button({
  97. name: '插入图片',
  98. title: '插入图片',
  99. cssRules :'background-position: -726px -77px',
  100. onclick:function () {
  101. editor.execCommand(uiName);
  102. }
  103. });
  104. editor.addListener('selectionchange', function () {
  105. var state = editor.queryCommandState(uiName);
  106. if (state == -1) {
  107. btn.setDisabled(true);
  108. btn.setChecked(false);
  109. } else {
  110. btn.setDisabled(false);
  111. btn.setChecked(state);
  112. }
  113. });
  114. return btn;
  115. }, 19);
  116. UE.registerUI('myinsertvideo',function(editor,uiName){
  117. editor.registerCommand(uiName, {
  118. execCommand:function(){
  119. require(['".$fileUploader."'],
  120. function(uploader){
  121. uploader.upload_url('".$url['upload_url']."');
  122. uploader.image_url('".$url['image_url']."');
  123. uploader.fetch_url('".$url['fetch_url']."');
  124. uploader.delet_url('".$url['delet_url']."');
  125. uploader.video_url('".$url['video_url']."');
  126. uploader.show(function(video){
  127. if (!video) {
  128. return;
  129. } else {
  130. var videoType = video.isRemote ? 'iframe' : 'video';
  131. editor.execCommand('insertvideo', {
  132. 'url' : video.url,
  133. 'width' : '100%',
  134. 'height' : 200
  135. }, videoType);
  136. }
  137. }, {type:'video'});
  138. }
  139. );
  140. }
  141. });
  142. var btn = new UE.ui.Button({
  143. name: '插入视频',
  144. title: '插入视频',
  145. cssRules :'background-position: -320px -20px',
  146. onclick:function () {
  147. editor.execCommand(uiName);
  148. }
  149. });
  150. editor.addListener('selectionchange', function () {
  151. var state = editor.queryCommandState(uiName);
  152. if (state == -1) {
  153. btn.setDisabled(true);
  154. btn.setChecked(false);
  155. } else {
  156. btn.setDisabled(false);
  157. btn.setChecked(state);
  158. }
  159. });
  160. return btn;
  161. }, 20);
  162. " . (!empty($id) ? "
  163. $(function(){
  164. var ue = UE.getEditor('{$id}', ueditoroption);
  165. $('#{$id}').data('editor', ue);
  166. $('#{$id}').parents('form').submit(function() {
  167. if (ue.queryCommandState('source')) {
  168. ue.execCommand('source');
  169. }
  170. });
  171. });" : '') . "
  172. </script>";
  173. return $s;
  174. }
  175. }
  176. if (!function_exists("html_images")) {
  177. function html_images($detail = '')
  178. {
  179. $detail = htmlspecialchars_decode($detail);
  180. preg_match_all("/<img.*?src=[\'| \"](.*?(?:[\.gif|\.jpg|\.png|\.jpeg]?))[\'|\"].*?[\/]?>/", $detail, $imgs);
  181. $images = array();
  182. if (isset($imgs[1])) {
  183. foreach ($imgs[1] as $img) {
  184. $im = array(
  185. "old" => $img,
  186. "new" => save_media($img)
  187. );
  188. $images[] = $im;
  189. }
  190. }
  191. foreach ($images as $img) {
  192. $detail = str_replace($img['old'], $img['new'], $detail);
  193. }
  194. return $detail;
  195. }
  196. }
  197. if (!function_exists("xml_to_array")) {
  198. function xml_to_array($xml)
  199. {
  200. $reg = "/<(\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/";
  201. if (preg_match_all($reg, $xml, $matches)) {
  202. $count = count($matches[0]);
  203. for ($i = 0; $i < $count; $i++) {
  204. $subxml = $matches[2][$i];
  205. $key = $matches[1][$i];
  206. if (preg_match($reg, $subxml)) {
  207. $arr[$key] = xml_to_array($subxml);
  208. } else {
  209. $arr[$key] = $subxml;
  210. }
  211. }
  212. }
  213. return $arr;
  214. }
  215. }
  216. if (!function_exists("tomedia")) {
  217. /**
  218. * 获取附件的HTTP绝对路径
  219. * @param string $src 附件地址
  220. * @param bool $local_path 是否直接返回本地图片路径
  221. * @return string
  222. */
  223. function tomedia($src, $local_path = false)
  224. {
  225. if (empty($src)) {
  226. return '';
  227. }
  228. $local = strtolower($src);
  229. if (config('app.framework') == 'platform') {
  230. if (strexists($src, 'storage/')) {
  231. return request()->getSchemeAndHttpHost() . '/' . substr($src, strpos($src, 'storage/'));
  232. }
  233. //判断是否是本地带域名图片地址
  234. if (strexists($src, '/static/')) {
  235. if (strexists($local, 'http://') || strexists($local, 'https://') || substr($local, 0, 2) == '//') {
  236. return $src;
  237. } else {
  238. return request()->getSchemeAndHttpHost() . substr($src, strpos($src, '/static/'));
  239. }
  240. }
  241. } elseif (config('app.framework') != 'platform' && strexists($src, 'addons/')) {
  242. return request()->getSchemeAndHttpHost() . '/' . substr($src, strpos($src, 'addons/'));
  243. }
  244. //如果远程地址中包含本地host也检测是否远程图片
  245. if (strexists($src, request()->getSchemeAndHttpHost()) && !strexists($src, '/addons/')) {
  246. $urls = parse_url($src);
  247. $src = $t = substr($urls['path'], strpos($urls['path'], 'image'));
  248. }
  249. $t = strtolower($src);
  250. if (strexists($t, 'http://') || strexists($t, 'https://') || substr($t, 0, 2) == '//') {
  251. return $src;
  252. }
  253. if (config('app.framework') == 'platform') {
  254. $remote = SystemSetting::settingLoad('remote', 'system_remote');
  255. // $upload_type = \app\platform\modules\application\models\CoreAttach::where('attachment', $src)->first()['upload_type'];
  256. if (($local_path || !$remote['type']) && file_exists(base_path() . '/static/upload/' . $src)) {
  257. $src = request()->getSchemeAndHttpHost() . '/static/upload' . (strpos($src,'/') === 0 ? '':'/') . $src;
  258. } else {
  259. if ($remote['type'] == '2') {
  260. $src = $remote['alioss']['url'] . '/'. $src;
  261. } elseif ($remote['type'] == '4') {
  262. $src = $remote['cos']['url'] . '/'. $src;
  263. }
  264. }
  265. } else {
  266. if (($local_path || empty(YunShop::app()->setting['remote']['type'])) && file_exists(base_path('../../') . '/' . YunShop::app()->config['upload']['attachdir'] . '/' . $src)) {
  267. $src = request()->getSchemeAndHttpHost() . '/attachment/' . $src;
  268. } else {
  269. $src = YunShop::app()->attachurl_remote . $src;
  270. }
  271. }
  272. return $src;
  273. }
  274. }
  275. //内容审核,判断插件是否开启后,抛出事件去审核返回审核结果
  276. if (!function_exists("do_upload_verificaton")) {
  277. //file支持传入图片文件,文字,视频url,语音文件(多种类型:仅支持pcm、wav、amr、m4a),
  278. //type为固定值:img,text,video, audio_pcm(_wav,_amr,_m4a)
  279. function do_upload_verificaton($file,$type) {
  280. return event((new Yunshop\UploadVerification\service\UploadVerificationEvent($file,$type)));
  281. }
  282. }
  283. /**
  284. * 获取附件的HTTP绝对路径
  285. * @param string $src 附件地址
  286. * @param bool $local_path 是否直接返回本地图片路径
  287. * @param null $upload_type 上传图片时的类型,数据表 upload_type 字段(只需要在上传图片时,传参数,获取列表不需要传改参数)
  288. * @return string
  289. */
  290. function yz_tomedia($src, $local_path = false, $upload_type = null,$host = '')
  291. {
  292. if (empty($src)) {
  293. return '';
  294. }
  295. $HttpHost = request()->getSchemeAndHttpHost();
  296. if ($host) {
  297. $HttpHost = $host;
  298. }
  299. $setting = [];
  300. if (config('app.framework') == 'platform') {
  301. $systemSetting = app('SystemSetting');
  302. if ($remote = $systemSetting->get('remote')) {
  303. $setting[$remote['key']] = unserialize($remote['value']);
  304. }
  305. $upload_type = $setting['remote']['type'];
  306. $addons = '/storage/';
  307. $attachment = '/static/upload/';
  308. $file_path = base_path($attachment) . $src;
  309. if (file_exists($file_path)) {//本地图片存在直接返回 示例图片path image/e3a555295b58e043dbf8ea3eb0434647.png
  310. return $HttpHost.$attachment . $src;
  311. }
  312. if (strexists($src, $attachment)) {//本地图片存在直接返回 示例图片path /static/upload/image/e3a555295b58e043dbf8ea3eb0434647.png
  313. $relative_path = substr($src, strpos($src, $attachment));
  314. $file_path = base_path($relative_path);
  315. if (file_exists($file_path)) {
  316. return $HttpHost.$relative_path;
  317. }
  318. }
  319. } else {
  320. //全局配置
  321. global $_W;
  322. //公众号独立配置信息 优先使用公众号独立配置
  323. $uni_setting = app('WqUniSetting')->get()->toArray();
  324. if (!empty($uni_setting['remote']) && iunserializer($uni_setting['remote'])['type'] != 0) {
  325. $setting['remote'] = iunserializer($uni_setting['remote']);
  326. $upload_type = $setting['remote']['type'];
  327. } else {
  328. $setting = $_W['setting'];
  329. $upload_type = $setting['remote']['type'];
  330. }
  331. $addons = '/addons/';
  332. $attachment = '/attachment/';
  333. $file_path = base_path('../../attachment/') . $src;
  334. if (file_exists($file_path)) {//本地图片存在直接返回 示例图片path image/e3a555295b58e043dbf8ea3eb0434647.png
  335. return $HttpHost.'/attachment/'.$src;
  336. }
  337. if (strexists($src, $attachment)) {//本地图片存在直接返回 示例图片path /attachment/image/e3a555295b58e043dbf8ea3eb0434647.png
  338. $relative_path = substr($src, strpos($src, $attachment));
  339. $file_path = base_path('../..'.$relative_path);
  340. if (file_exists($file_path)) {
  341. return $HttpHost.$relative_path;
  342. }
  343. }
  344. }
  345. $os = Client::osType();
  346. if (strexists($src, $addons)) {
  347. if ($os == Client::OS_TYPE_IOS) {
  348. $url_dz = $HttpHost . substr($src, strpos($src, $addons));
  349. return 'https:' . substr($url_dz, strpos($url_dz, '//'));
  350. }
  351. return $HttpHost . substr($src, strpos($src, $addons));
  352. }
  353. $local = strtolower($src);
  354. //todo 临时增加如果是插件图片
  355. if (strexists($src, "plugins/")) {
  356. $attachment = "/plugins/";
  357. if ($os == Client::OS_TYPE_IOS) {
  358. $url_dz = $HttpHost . substr($src, strpos($src, $attachment));
  359. return 'https:' . substr($url_dz, strpos($url_dz, '//'));
  360. }
  361. if (strexists($local, 'http://') || strexists($local, 'https://') || substr($local, 0, 2) == '//') {
  362. return $src;
  363. } else {
  364. return $HttpHost . substr($src, strpos($src, $attachment));
  365. }
  366. }
  367. //装修静态
  368. if (strexists($src, 'static/') && strexists($src, 'yunshop/')) {
  369. $path = substr($src, strpos($src, 'static/'));
  370. if (base_path($path)) {
  371. return $HttpHost.'/'.$path;
  372. }
  373. }
  374. $attach_url_remote = '';
  375. if ($upload_type) {
  376. switch ($upload_type) {
  377. case 1 :
  378. $attach_url_remote = $setting['remote']['ftp']['url'];
  379. break;
  380. case 2 :
  381. $attach_url_remote = $setting['remote']['alioss']['url'];
  382. break;
  383. case 3 :
  384. $attach_url_remote = $setting['remote']['qiniu']['url'];
  385. break;
  386. case 4 :
  387. $attach_url_remote = $setting['remote']['cos']['url'];
  388. break;
  389. }
  390. }
  391. if (strexists($src, $HttpHost) && strexists($src, $attachment) && $upload_type) {
  392. $host_str = $HttpHost.$attachment;
  393. $str_len = strlen($host_str);
  394. $relative_path = substr($src, $str_len);
  395. return $attach_url_remote .'/'. $relative_path;
  396. }
  397. //判断是否是本地不带域名图片地址
  398. if ((strexists($src, $attachment) && (parse_url($src)['scheme'].'://'.parse_url($src)['host']) == $HttpHost) || (strexists($src, $attachment) && !strexists($src, 'http://') && !strexists($src, 'https://'))) {
  399. if ($os == Client::OS_TYPE_IOS) {
  400. $url_dz = $HttpHost . substr($src, strpos($src, $attachment));
  401. return 'https:' . substr($url_dz, strpos($url_dz, '//'));
  402. }
  403. return $HttpHost . substr($src, strpos($src, $attachment));
  404. }
  405. //如果远程地址中包含本地host也检测是否远程图片
  406. if (strexists($local, 'http://') || strexists($local, 'https://') || substr($local, 0, 2) == '//') {
  407. return 'https:' . substr($src, strpos($src, '//'));
  408. }
  409. if ($upload_type) {
  410. return $attach_url_remote.'/'.$src;
  411. }
  412. if (preg_match('/^(\/\/){1}.*/',$src)) {
  413. return $src;
  414. }
  415. if (!config('app.debug')) {
  416. $src = 'https:' . substr($src, strpos($src, '//'));
  417. }
  418. return $src;
  419. }
  420. if (!function_exists("replace_yunshop")) {
  421. function replace_yunshop($url)
  422. {
  423. $moduleName = \Config::get('app.module_name');
  424. return str_replace(DIRECTORY_SEPARATOR . "addons" . DIRECTORY_SEPARATOR . $moduleName, "", $url);
  425. }
  426. }
  427. if (!function_exists("strexists")) {
  428. /**
  429. * 判断字符串是否包含子串
  430. * @param string $string 在该字符串中进行查找
  431. * @param string $find 需要查找的字符串
  432. * @return boolean
  433. */
  434. function strexists($string, $find)
  435. {
  436. return !(strpos($string, $find) === false);
  437. }
  438. }
  439. if (!function_exists("set_medias")) {
  440. function set_medias($list = array(), $fields = null)
  441. {
  442. if (empty($fields)) {
  443. foreach ($list as &$row) {
  444. $row = yz_tomedia($row);
  445. }
  446. return $list;
  447. }
  448. if (!is_array($fields)) {
  449. $fields = explode(',', $fields);
  450. }
  451. if (is_array2($list)) {
  452. foreach ($list as $key => &$value) {
  453. foreach ($fields as $field) {
  454. if (isset($list[$field])) {
  455. $list[$field] = yz_tomedia($list[$field]);
  456. }
  457. if (is_array($value) && isset($value[$field])) {
  458. $value[$field] = yz_tomedia($value[$field]);
  459. }
  460. }
  461. }
  462. return $list;
  463. } else {
  464. foreach ($fields as $field) {
  465. if (isset($list[$field])) {
  466. $list[$field] = yz_tomedia($list[$field]);
  467. }
  468. }
  469. return $list;
  470. }
  471. }
  472. }
  473. if (!function_exists('is_array2')) {
  474. function is_array2($array)
  475. {
  476. if (is_array($array)) {
  477. foreach ($array as $k => $v) {
  478. return is_array($v);
  479. }
  480. return false;
  481. }
  482. return false;
  483. }
  484. }
  485. if (!function_exists("show_json")) {
  486. function show_json($status = 1, $return = null, $variable = null)
  487. {
  488. $ret = array(
  489. 'status' => $status
  490. );
  491. if ($return) {
  492. $ret['result'] = $return;
  493. }
  494. if (Yunshop::isApi()) {
  495. return array(
  496. 'status' => $status,
  497. 'variable' => $variable,
  498. 'json' => $return,
  499. );
  500. }
  501. die(json_encode($ret));
  502. }
  503. }
  504. if (!function_exists("array_column")) {
  505. function array_column($input = null, $columnKey = null, $indexKey = null)
  506. {
  507. // Using func_get_args() in order to check for proper number of
  508. // parameters and trigger errors exactly as the built-in array_column()
  509. // does in PHP 5.5.
  510. $argc = func_num_args();
  511. $params = func_get_args();
  512. if ($argc < 2) {
  513. trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
  514. return null;
  515. }
  516. if (!is_array($params[0])) {
  517. trigger_error(
  518. 'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
  519. E_USER_WARNING
  520. );
  521. return null;
  522. }
  523. if (!is_int($params[1])
  524. && !is_float($params[1])
  525. && !is_string($params[1])
  526. && $params[1] !== null
  527. && !(is_object($params[1]) && method_exists($params[1], '__toString'))
  528. ) {
  529. trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
  530. return false;
  531. }
  532. if (isset($params[2])
  533. && !is_int($params[2])
  534. && !is_float($params[2])
  535. && !is_string($params[2])
  536. && !(is_object($params[2]) && method_exists($params[2], '__toString'))
  537. ) {
  538. trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
  539. return false;
  540. }
  541. $paramsInput = $params[0];
  542. $paramsColumnKey = ($params[1] !== null) ? (string)$params[1] : null;
  543. $paramsIndexKey = null;
  544. if (isset($params[2])) {
  545. if (is_float($params[2]) || is_int($params[2])) {
  546. $paramsIndexKey = (int)$params[2];
  547. } else {
  548. $paramsIndexKey = (string)$params[2];
  549. }
  550. }
  551. $resultArray = array();
  552. foreach ($paramsInput as $row) {
  553. $key = $value = null;
  554. $keySet = $valueSet = false;
  555. if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
  556. $keySet = true;
  557. $key = (string)$row[$paramsIndexKey];
  558. }
  559. if ($paramsColumnKey === null) {
  560. $valueSet = true;
  561. $value = $row;
  562. } elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
  563. $valueSet = true;
  564. $value = $row[$paramsColumnKey];
  565. }
  566. if ($valueSet) {
  567. if ($keySet) {
  568. $resultArray[$key] = $value;
  569. } else {
  570. $resultArray[] = $value;
  571. }
  572. }
  573. }
  574. return $resultArray;
  575. }
  576. }
  577. if (!function_exists('shop_template_compile')) {
  578. function shop_template_compile($from, $to, $inmodule = false)
  579. {
  580. $path = dirname($to);
  581. \app\common\services\Utils::mkdirs($path);
  582. $content = shop_template_parse(file_get_contents($from), $inmodule);
  583. file_put_contents($to, $content);
  584. }
  585. }
  586. if (!function_exists('shop_template_parse')) {
  587. function shop_template_parse($str, $inmodule = false)
  588. {
  589. $str = template_parse($str, $inmodule);
  590. $str = preg_replace('/{ifp\s+(.+?)}/', '<?php if(cv($1)) { ?>', $str);
  591. $str = preg_replace('/{ifpp\s+(.+?)}/', '<?php if(cp($1)) { ?>', $str);
  592. $str = preg_replace('/{ife\s+(\S+)\s+(\S+)}/', '<?php if( ce($1 ,$2) ) { ?>', $str);
  593. return $str;
  594. }
  595. }
  596. if (!function_exists('objectArray')) {
  597. function objectArray($array)
  598. {
  599. if (is_object($array)) {
  600. $array = (array)$array;
  601. }
  602. if (is_array($array)) {
  603. foreach ($array as $key => $value) {
  604. $array[$key] = objectArray($value);
  605. }
  606. }
  607. return $array;
  608. }
  609. }
  610. if (!function_exists('my_link_extra')) {
  611. function my_link_extra($type = 'content')
  612. {
  613. $content = "";
  614. $extraContents = [];
  615. Event::dispatch(new app\common\events\RenderingMyLink($extraContents));
  616. return $type == 'content' ? $content . implode("\n", $extraContents) : implode("\n",
  617. array_keys($extraContents));
  618. }
  619. }
  620. if (!function_exists('can')) {
  621. /**
  622. * 权限判断
  623. * @param $item 可以是item 或者是route
  624. * @param bool $isRoute
  625. * @return bool
  626. */
  627. function can($itemRoute, $isRoute = false)
  628. {
  629. /*if(config('app.menu_key') != 'menu'){
  630. return true;
  631. }*/
  632. if ($isRoute == true) {
  633. $item = \app\common\models\Menu::getItemByRoute($itemRoute);
  634. } else {
  635. $item = $itemRoute;
  636. }
  637. return PermissionService::can($item);
  638. }
  639. }
  640. if (!function_exists('weAccount')) {
  641. /**
  642. * 获取微擎账号体系
  643. * @return NULL|WeAccount
  644. */
  645. function weAccount()
  646. {
  647. /* load()->model('account');
  648. return WeAccount::create();*/
  649. }
  650. }
  651. if (!function_exists('yzWebUrl')) {
  652. function yzWebUrl($route, $params = [])
  653. {
  654. return Url::web($route, $params);
  655. }
  656. }
  657. if (!function_exists('yzAppUrl')) {
  658. function yzAppUrl($route, $params = [])
  659. {
  660. return Url::app($route, $params);
  661. }
  662. }
  663. if (!function_exists('yzApiUrl')) {
  664. function yzApiUrl($route, $params = [])
  665. {
  666. return Url::api($route, $params);
  667. }
  668. }
  669. if (!function_exists('yzPluginUrl')) {
  670. function yzPluginUrl($route, $params = [])
  671. {
  672. return Url::plugin($route, $params);
  673. }
  674. }
  675. if (!function_exists('yzPluginFullUrl')) {
  676. function yzPluginFullUrl($route, $params = [])
  677. {
  678. return Url::absolutePlugin($route, $params);
  679. }
  680. }
  681. if (!function_exists('yzWebFullUrl')) {
  682. function yzWebFullUrl($route, $params = [])
  683. {
  684. return Url::absoluteWeb($route, $params);
  685. }
  686. }
  687. if (!function_exists('yzAppFullUrl')) {
  688. function yzAppFullUrl($route, $params = [])
  689. {
  690. return Url::absoluteApp($route, $params);
  691. }
  692. }
  693. if (!function_exists('yzBusinessFullUrl')) {
  694. function yzBusinessFullUrl($route, $params = [])
  695. {
  696. return request()->getSchemeAndHttpHost() . '/' . yzBusinessUrl($route, $params);
  697. }
  698. }
  699. if (!function_exists('yzBusinessUrl')) {
  700. function yzBusinessUrl($route, $params = [])
  701. {
  702. if (!$params['i']) $params = array_merge(['i' => YunShop::app()->uniacid], $params);
  703. return 'business/business_font/#/' . $route . '?' . http_build_query($params);
  704. }
  705. }
  706. if (!function_exists('yzDiyFullUrl')) {
  707. function yzDiyFullUrl($route, $params = [])
  708. {
  709. return Url::absoluteDiyApp($route, $params);
  710. }
  711. }
  712. if (!function_exists('yzUrl')) {
  713. function yzUrl($route, $params = [])
  714. {
  715. return Url::web($route, $params);
  716. }
  717. }
  718. if (!function_exists('array_child_kv_exists')) {
  719. function array_child_kv_exists($array, $childKey, $value)
  720. {
  721. $result = false;
  722. if (is_array($array)) {
  723. foreach ($array as $v) {
  724. if (is_array($v) && isset($v[$childKey])) {
  725. $result += $v[$childKey] == $value;
  726. }
  727. }
  728. }
  729. return $result;
  730. }
  731. }
  732. if (!function_exists('widget')) {
  733. function widget($class, $params = [])
  734. {
  735. return (new $class($params))->run();
  736. }
  737. }
  738. if (!function_exists('assets')) {
  739. function assets($relativeUri)
  740. {
  741. // add query string to fresh cache
  742. if (Str::startsWith($relativeUri, 'styles') || Str::startsWith($relativeUri, 'scripts')) {
  743. return Url::shopUrl("resources/assets/dist/$relativeUri") . "?v=" . config('app.version');
  744. } elseif (Str::startsWith($relativeUri, 'lang')) {
  745. return Url::shopUrl("resources/$relativeUri");
  746. } else {
  747. return Url::shopUrl("resources/assets/$relativeUri");
  748. }
  749. }
  750. }
  751. if (!function_exists('static_url')) {
  752. function static_url($relativeUri)
  753. {
  754. return Url::shopUrl('static/' . $relativeUri);
  755. }
  756. }
  757. if (!function_exists('plugin')) {
  758. function plugin($id)
  759. {
  760. return app('plugins')->getPlugin($id);
  761. }
  762. }
  763. if (!function_exists('plugin_assets')) {
  764. function plugin_assets($id, $relativeUri)
  765. {
  766. if ($plugin = plugin($id)) {
  767. return $plugin->assets($relativeUri);
  768. } else {
  769. throw new InvalidArgumentException("No such plugin.");
  770. }
  771. }
  772. }
  773. if (!function_exists('json')) {
  774. function json()
  775. {
  776. $args = func_get_args();
  777. if (count($args) == 1 && is_array($args[0])) {
  778. return Response::json($args[0]);
  779. } elseif (count($args) == 3 && is_array($args[2])) {
  780. // the third argument is array of extra fields
  781. return Response::json(array_merge([
  782. 'errno' => $args[1],
  783. 'msg' => $args[0]
  784. ], $args[2]));
  785. } else {
  786. return Response::json([
  787. 'errno' => Arr::get($args, 1, 1),
  788. 'msg' => $args[0]
  789. ]);
  790. }
  791. }
  792. }
  793. if (!function_exists('yz_footer')) {
  794. function yz_footer($page_identification = "")
  795. {
  796. $content = "";
  797. /*
  798. $scripts = [
  799. assets('scripts/app.min.js'),
  800. assets('lang/'.config('app.locale').'/locale.js'),
  801. ];
  802. if ($page_identification !== "") {
  803. $scripts[] = assets("scripts/$page_identification.js");
  804. }
  805. foreach ($scripts as $script) {
  806. $content .= "<script type=\"text/javascript\" src=\"$script\"></script>\n";
  807. }
  808. */
  809. $customJs = option("custom_js");
  810. $customJs && $content .= '<script>' . $customJs . '</script>';
  811. $extraContents = [];
  812. Event::dispatch(new app\common\events\RenderingFooter($extraContents));
  813. return $content . implode("\n", $extraContents);
  814. }
  815. }
  816. if (!function_exists('yz_header')) {
  817. function yz_header($pageIdentification = "")
  818. {
  819. $content = "";
  820. /*
  821. $styles = [
  822. assets('styles/app.min.css'),
  823. assets('styles/skins/'.Option::get('color_scheme').'.min.css')
  824. ];
  825. if ($pageIdentification !== "") {
  826. $styles[] = assets("styles/$pageIdentification.css");
  827. }
  828. foreach ($styles as $style) {
  829. $content .= "<link rel=\"stylesheet\" href=\"$style\">\n";
  830. }
  831. */
  832. $customCss = option("custom_css");
  833. $customCss && $content .= '<style>' . option("custom_css") . '</style>';
  834. $extraContents = [];
  835. Event::dispatch(new app\common\events\RenderingHeader($extraContents));
  836. return $content . implode("\n", $extraContents);
  837. }
  838. }
  839. if (!function_exists('yz_menu')) {
  840. function yz_menu($type)
  841. {
  842. $menu = \app\backend\modules\menu\Menu::current()->getItems();
  843. Event::dispatch($type == "member" ? new app\common\events\ConfigureMemberMenu($menu)
  844. : new app\common\events\ConfigureAdminMenu($menu));
  845. if (!isset($menu[$type])) {
  846. throw new InvalidArgumentException;
  847. }
  848. return yz_menu_render($menu[$type]);
  849. }
  850. function yz_menu_render($data)
  851. {
  852. $content = "";
  853. foreach ($data as $key => $value) {
  854. $active = app('request')->is(@$value['link']);
  855. // also set parent as active if any child is active
  856. foreach ((array)@$value['children'] as $childKey => $childValue) {
  857. if (app('request')->is(@$childValue['link'])) {
  858. $active = true;
  859. }
  860. }
  861. $content .= $active ? '<li class="active">' : '<li>';
  862. if (isset($value['children'])) {
  863. $content .= '<a href="#"><i class="fa ' . $value['icon'] . '"></i> <span>' . trans($value['title']) . '</span><span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span></a>';
  864. // recurse
  865. $content .= '<ul class="treeview-menu" style="display: none;">' . yz_menu_render($value['children']) . '</ul>';
  866. } else {
  867. $content .= '<a href="' . url($value['link']) . '"><i class="fa ' . $value['icon'] . '"></i> <span>' . trans($value['title']) . '</span></a>';
  868. }
  869. $content .= '</li>';
  870. }
  871. return $content;
  872. }
  873. }
  874. if (!function_exists('option')) {
  875. /**
  876. * Get / set the specified option value.
  877. *
  878. * If an array is passed as the key, we will assume you want to set an array of values.
  879. *
  880. * @param array|string $key
  881. * @param mixed $default
  882. * @param raw $raw return raw value without convertion
  883. * @return mixed
  884. */
  885. function option($key = null, $default = null, $raw = false)
  886. {
  887. $options = app('options');
  888. if (is_null($key)) {
  889. return $options;
  890. }
  891. if (is_array($key)) {
  892. foreach ($key as $innerKey => $innerValue) {
  893. $options->set($innerKey, $innerValue);
  894. }
  895. return;
  896. }
  897. //$optionsData = $options->get();
  898. //return $optionsData[$key]['option_value'];
  899. return array_get($options->all(),$key, $default)['option_value'];
  900. }
  901. }
  902. if (!function_exists('float_greater')) {
  903. function float_greater($number, $other_number)
  904. {
  905. return bccomp($number, $other_number) === 1;
  906. }
  907. }
  908. if (!function_exists('float_lesser')) {
  909. function float_lesser($number, $other_number)
  910. {
  911. return bccomp($number, $other_number) === -1;
  912. }
  913. }
  914. if (!function_exists('float_equal')) {
  915. function float_equal($number, $other_number)
  916. {
  917. return bccomp($number, $other_number) === 0;
  918. }
  919. }
  920. if (!function_exists('sdd')) {
  921. function sdd()
  922. {
  923. global $testDd;
  924. $testDd = !$testDd;
  925. }
  926. }
  927. if (!function_exists('tdd')) {
  928. function tdd()
  929. {
  930. global $testDd;
  931. if ($testDd) {
  932. dd(func_get_args());
  933. }
  934. }
  935. }
  936. /*
  937. * 生成一个随机订单号:如果需要唯一性,请自己验证重复调用
  938. *
  939. * @params string $prefix 标示 SN RV
  940. * @params bool $numeric 是否为纯数字
  941. *
  942. * @return mixed
  943. * @Author yitian */
  944. if (!function_exists('createNo')) {
  945. function createNo($prefix, $length = 6, $numeric = FALSE)
  946. {
  947. return $prefix . date('YmdHis') . Client::random($length, $numeric);
  948. }
  949. }
  950. if (!function_exists('yz_array_set')) {
  951. function yz_array_set($array, $key, $value)
  952. {
  953. $keys = explode('.', $key);
  954. while (count($keys) > 1) {
  955. $key = array_shift($keys);
  956. // If the key doesn't exist at this depth, we will just create an empty array
  957. // to hold the next value, allowing us to create the arrays to hold final
  958. // values at the correct depth. Then we'll keep digging into the array.
  959. if (!isset($array[$key]) || !is_array($array[$key])) {
  960. $array[$key] = [];
  961. }
  962. $array = &$array[$key];
  963. }
  964. $array[array_shift($keys)] = $value;
  965. return $array;
  966. }
  967. }
  968. if (!function_exists('trace_log')) {
  969. /**
  970. * @return \Illuminate\Foundation\Application|mixed
  971. */
  972. function trace_log(){
  973. return app('Log.trace');
  974. }
  975. }
  976. if (!function_exists('debug_log')) {
  977. /**
  978. * @return \Illuminate\Foundation\Application|mixed
  979. */
  980. function debug_log(){
  981. return app('Log.debug');
  982. }
  983. }
  984. if (!function_exists('randNum')) {
  985. /**
  986. * 获取随机字符串
  987. * @param number $length 字符串长度
  988. * @param boolean $numeric 是否为纯数字
  989. * @return string
  990. */
  991. function randNum($length, $numeric = FALSE) {
  992. $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
  993. $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
  994. if ($numeric) {
  995. $hash = '';
  996. } else {
  997. $hash = chr(rand(1, 26) + rand(0, 1) * 32 + 64);
  998. $length--;
  999. }
  1000. $max = strlen($seed) - 1;
  1001. for ($i = 0; $i < $length; $i++) {
  1002. $hash .= $seed{mt_rand(0, $max)};
  1003. }
  1004. return $hash;
  1005. }
  1006. }
  1007. if (!function_exists('file_random_name')) {
  1008. function file_random_name($dir, $ext)
  1009. {
  1010. do {
  1011. $filename = random(30) . '.' . $ext;
  1012. } while (file_exists($dir . $filename));
  1013. return $filename;
  1014. }
  1015. }
  1016. if (!function_exists('random')) {
  1017. function random($length, $numeric = FALSE)
  1018. {
  1019. $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
  1020. $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
  1021. if ($numeric) {
  1022. $hash = '';
  1023. } else {
  1024. $hash = chr(rand(1, 26) + rand(0, 1) * 32 + 64);
  1025. $length--;
  1026. }
  1027. $max = strlen($seed) - 1;
  1028. for ($i = 0; $i < $length; $i++) {
  1029. $hash .= $seed{mt_rand(0, $max)};
  1030. }
  1031. return $hash;
  1032. }
  1033. }
  1034. if (!function_exists('is_error')) {
  1035. function is_error($data)
  1036. {
  1037. if (empty($data) || !is_array($data) || !array_key_exists('errno', $data) || (array_key_exists('errno', $data) && $data['errno'] == 0)) {
  1038. return false;
  1039. } else {
  1040. return true;
  1041. }
  1042. }
  1043. }
  1044. if (!function_exists('file_image_quality')) {
  1045. function file_image_quality($src, $to_path, $ext, $global)
  1046. {
  1047. $quality = intval($global['zip_percentage']);
  1048. if ($quality <= 0 || $quality >= 100) {
  1049. return;
  1050. }
  1051. if (filesize($src) / 1024 > 5120) {
  1052. return;
  1053. }
  1054. $result = \app\platform\modules\system\models\Image::create($src, $ext)->saveTo($to_path, $quality);
  1055. return $result;
  1056. }
  1057. }
  1058. if (!function_exists('safe_gpc_path')) {
  1059. function safe_gpc_path($value, $default = '') {
  1060. $path = safe_gpc_string($value);
  1061. $path = str_replace(array('..', '..\\', '\\\\' ,'\\', '..\\\\'), '', $path);
  1062. if (!$path || $path != $value) {
  1063. $path = $default;
  1064. }
  1065. return $path;
  1066. }
  1067. }
  1068. if (!function_exists('safe_gpc_string')) {
  1069. function safe_gpc_string($value, $default = '')
  1070. {
  1071. $value = safe_bad_str_replace($value);
  1072. $value = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4}));)/', '&\\1', $value);
  1073. if (empty($value) && $default != $value) {
  1074. $value = $default;
  1075. }
  1076. return $value;
  1077. }
  1078. }
  1079. if (!function_exists('array_elements')) {
  1080. function array_elements($keys, $src, $default = FALSE)
  1081. {
  1082. $return = array();
  1083. if (!is_array($keys)) {
  1084. $keys = array($keys);
  1085. }
  1086. foreach ($keys as $key) {
  1087. if (isset($src[$key])) {
  1088. $return[$key] = $src[$key];
  1089. } else {
  1090. $return[$key] = $default;
  1091. }
  1092. }
  1093. return $return;
  1094. }
  1095. }
  1096. if (!function_exists('sizecount')) {
  1097. function sizecount($size)
  1098. {
  1099. if ($size >= 1073741824) {
  1100. $size = round($size / 1073741824 * 100) / 100 . ' GB';
  1101. } elseif ($size >= 1048576) {
  1102. $size = round($size / 1048576 * 100) / 100 . ' MB';
  1103. } elseif ($size >= 1024) {
  1104. $size = round($size / 1024 * 100) / 100 . ' KB';
  1105. } else {
  1106. $size = $size . ' Bytes';
  1107. }
  1108. return $size;
  1109. }
  1110. }
  1111. if (!function_exists('file_image_thumb')) {
  1112. function file_image_thumb($srcfile, $desfile = '', $width = 0, $global)
  1113. {
  1114. if (intval($width) == 0) {
  1115. $width = intval($global['thumb_width']);
  1116. }
  1117. if (!$desfile) {
  1118. $ext = pathinfo($srcfile, PATHINFO_EXTENSION);
  1119. $srcdir = dirname($srcfile);
  1120. do {
  1121. $desfile = $srcdir . '/' . random(30) . ".{$ext}";
  1122. } while (file_exists($desfile));
  1123. }
  1124. $des = dirname($desfile);
  1125. if (!file_exists($des)) {
  1126. if (!\app\common\services\Utils::mkdirs($des)) {
  1127. return 1;
  1128. }
  1129. } elseif (!is_writable($des)) {
  1130. return 2;
  1131. }
  1132. $org_info = @getimagesize($srcfile);
  1133. if ($org_info) {
  1134. if ($width == 0 || $width > $org_info[0]) {
  1135. copy($srcfile, $desfile);
  1136. return str_replace(base_path() . '/static/upload/', '', $desfile);
  1137. }
  1138. }
  1139. $scale_org = $org_info[0] / $org_info[1];
  1140. $height = $width / $scale_org;
  1141. $desfile = \app\platform\modules\system\models\Image::create($srcfile)->resize($width, $height)->saveTo($desfile);
  1142. if (!$desfile) {
  1143. return false;
  1144. }
  1145. return str_replace(base_path() . '/static/upload/', '', $desfile);
  1146. }
  1147. }
  1148. if (!function_exists('file_is_image')) {
  1149. function file_is_image($url)
  1150. {
  1151. if (!parse_path($url)) {
  1152. return false;
  1153. }
  1154. $pathinfo = pathinfo($url);
  1155. $extension = strtolower($pathinfo['extension']);
  1156. return !empty($extension) && in_array($extension, array('jpg', 'jpeg', 'gif', 'png'));
  1157. }
  1158. }
  1159. if (!function_exists('file_remote_upload_wq')) {
  1160. function file_remote_upload_wq($filename, $auto_delete_local = true, $remote = [], $frontend = false)
  1161. {
  1162. // $filename 文件名
  1163. // $auto_delete_local 是否自动删除本地资源 true 删除 false 不删除
  1164. // $remote 远程配置信息
  1165. if (!empty($remote)) {
  1166. $remote_setting = $remote;
  1167. $upload_type = $remote['type'];
  1168. } else {
  1169. global $_W;
  1170. $remote_setting = $_W['setting']['remote'];
  1171. $upload_type = $_W['setting']['remote']['type'];
  1172. }
  1173. if (empty($upload_type)) {
  1174. return false;
  1175. }
  1176. if ($upload_type == '1') {
  1177. $ftp_config = array(
  1178. 'hostname' => $remote_setting['ftp']['host'],
  1179. 'username' => $remote_setting['ftp']['username'],
  1180. 'password' => $remote_setting['ftp']['password'],
  1181. 'port' => $remote_setting['ftp']['port'],
  1182. 'ssl' => $remote_setting['ftp']['ssl'],
  1183. 'passive' => $remote_setting['ftp']['pasv'],
  1184. 'timeout' => $remote_setting['ftp']['timeout'],
  1185. 'rootdir' => $remote_setting['ftp']['dir'],
  1186. );
  1187. load()->library('ftp');
  1188. $ftp = new Ftp($ftp_config);
  1189. if (true === $ftp->connect()) {
  1190. $response = $ftp->upload(ATTACHMENT_ROOT . $filename, $filename);
  1191. if ($auto_delete_local) {
  1192. file_deletes($filename);
  1193. }
  1194. if (!empty($response)) {
  1195. return true;
  1196. } else {
  1197. return error(1, '远程附件上传失败,请检查配置并重新上传');
  1198. }
  1199. } else {
  1200. return error(1, '远程附件上传失败,请检查配置并重新上传');
  1201. }
  1202. } elseif ($upload_type == '2') {
  1203. $buckets = attachment_alioss_buctkets($remote_setting['alioss']['key'], $remote_setting['alioss']['secret']);
  1204. $endpoint = 'http://' . $buckets[$remote_setting['alioss']['bucket']]['location'] . '.aliyuncs.com';
  1205. try {
  1206. $ossClient = new \app\common\services\aliyunoss\OssClient($remote_setting['alioss']['key'], $remote_setting['alioss']['secret'], $endpoint);
  1207. $ossClient->uploadFile($remote_setting['alioss']['bucket'], $filename, ATTACHMENT_ROOT . $filename);
  1208. } catch (\app\common\services\aliyunoss\OSS\Core\OssException $e) {
  1209. return error(1, $e->getMessage());
  1210. }
  1211. if ($auto_delete_local) {
  1212. file_deletes($filename);
  1213. }
  1214. } elseif ($upload_type == '3') {
  1215. load()->library('qiniu');
  1216. $auth = new Qiniu\Auth($remote_setting['qiniu']['accesskey'], $remote_setting['qiniu']['secretkey']);
  1217. $config = new Qiniu\Config();
  1218. $uploadmgr = new Qiniu\Storage\UploadManager($config);
  1219. $putpolicy = null;
  1220. $uploadtoken = $auth->uploadToken($remote_setting['qiniu']['bucket'], null, 3600, $putpolicy);
  1221. list($ret, $err) = $uploadmgr->putFile($uploadtoken, $filename, ATTACHMENT_ROOT . $filename);
  1222. if ($auto_delete_local) {
  1223. file_deletes($filename);
  1224. }
  1225. if ($err !== null) {
  1226. return error(1, '远程附件上传失败,请检查配置并重新上传');
  1227. } else {
  1228. return true;
  1229. }
  1230. } elseif ($upload_type == '4') {
  1231. //cosv5
  1232. $result = (new \app\common\services\QcloudCosService(
  1233. $remote_setting['cos']['local'],
  1234. $remote_setting['cos']['secretid'],
  1235. $remote_setting['cos']['secretkey'],
  1236. $remote_setting['cos']['bucket'],
  1237. $remote_setting['cos']['appid']
  1238. ))->upload($filename);
  1239. if ($auto_delete_local) {
  1240. file_deletes($filename);
  1241. }
  1242. if ($result === true) {
  1243. return true;
  1244. } else {
  1245. return error(-1, $result);
  1246. }
  1247. }
  1248. return true;
  1249. }
  1250. }
  1251. if (!function_exists('file_video_remote_upload_wq')) {
  1252. function file_video_remote_upload_wq($filename, $auto_delete_local = true, $remote = '', $frontend = false)
  1253. {
  1254. // $filename 文件名
  1255. // $auto_delete_local 是否自动删除本地资源 true 删除 false 不删除
  1256. // $remote 远程配置信息
  1257. // $frontend 是否前端调用 true 前端 false 后台
  1258. global $_W;
  1259. if (!empty($remote) && $frontend == true) {
  1260. $remote_setting = $remote;
  1261. $upload_type = $remote['type'];
  1262. } else {
  1263. $remote_setting = $_W['setting']['remote'];
  1264. $upload_type = $_W['setting']['remote']['type'];
  1265. }
  1266. if (empty($upload_type)) {
  1267. return false;
  1268. }
  1269. if ($upload_type == '1') {
  1270. $ftp_config = array(
  1271. 'hostname' => $remote_setting['ftp']['host'],
  1272. 'username' => $remote_setting['ftp']['username'],
  1273. 'password' => $remote_setting['ftp']['password'],
  1274. 'port' => $remote_setting['ftp']['port'],
  1275. 'ssl' => $remote_setting['ftp']['ssl'],
  1276. 'passive' => $remote_setting['ftp']['pasv'],
  1277. 'timeout' => $remote_setting['ftp']['timeout'],
  1278. 'rootdir' => $remote_setting['ftp']['dir'],
  1279. );
  1280. load()->library('ftp');
  1281. $ftp = new Ftp($ftp_config);
  1282. if (true === $ftp->connect()) {
  1283. $response = $ftp->upload(ATTACHMENT_ROOT . $filename, $filename);
  1284. if ($auto_delete_local) {
  1285. file_deletes($filename);
  1286. }
  1287. if (!empty($response)) {
  1288. return true;
  1289. } else {
  1290. return error(1, '远程附件上传失败,请检查配置并重新上传');
  1291. }
  1292. } else {
  1293. return error(1, '远程附件上传失败,请检查配置并重新上传');
  1294. }
  1295. } elseif ($upload_type == '2') {
  1296. $buckets = attachment_alioss_buctkets($remote_setting['alioss']['key'], $remote_setting['alioss']['secret']);
  1297. $endpoint = 'http://' . $buckets[$remote_setting['alioss']['bucket']]['location'] . '.aliyuncs.com';
  1298. try {
  1299. $ossClient = new \app\common\services\aliyunoss\OssClient($remote_setting['alioss']['key'], $remote_setting['alioss']['secret'], $endpoint);
  1300. $ossClient->uploadFile($remote_setting['alioss']['bucket'], $filename, ATTACHMENT_ROOT . $filename);
  1301. } catch (\app\common\services\aliyunoss\OSS\Core\OssException $e) {
  1302. return error(1, $e->getMessage());
  1303. }
  1304. if ($auto_delete_local) {
  1305. file_deletes($filename);
  1306. }
  1307. } elseif ($upload_type == '3') {
  1308. load()->library('qiniu');
  1309. $auth = new Qiniu\Auth($remote_setting['qiniu']['accesskey'], $remote_setting['qiniu']['secretkey']);
  1310. $config = new Qiniu\Config();
  1311. $uploadmgr = new Qiniu\Storage\UploadManager($config);
  1312. $putpolicy = null;
  1313. $uploadtoken = $auth->uploadToken($remote_setting['qiniu']['bucket'], null, 3600, $putpolicy);
  1314. list($ret, $err) = $uploadmgr->putFile($uploadtoken, $filename, ATTACHMENT_ROOT . $filename);
  1315. if ($auto_delete_local) {
  1316. file_deletes($filename);
  1317. }
  1318. if ($err !== null) {
  1319. return error(1, '远程附件上传失败,请检查配置并重新上传');
  1320. } else {
  1321. return true;
  1322. }
  1323. } elseif ($upload_type == '4') {
  1324. //cosv5
  1325. $result = (new \app\common\services\QcloudCosService(
  1326. $remote_setting['cos']['local'],
  1327. $remote_setting['cos']['secretid'],
  1328. $remote_setting['cos']['secretkey'],
  1329. $remote_setting['cos']['bucket'],
  1330. $remote_setting['cos']['appid']
  1331. ))->upload($filename);
  1332. if ($auto_delete_local) {
  1333. file_deletes($filename);
  1334. }
  1335. if ($result === true) {
  1336. return true;
  1337. } else {
  1338. return error(-1, $result);
  1339. }
  1340. }
  1341. }
  1342. }
  1343. if (!function_exists('file_remote_upload')) {
  1344. function file_remote_upload($filename, $auto_delete_local = true, $remote)
  1345. {
  1346. if (!$remote['type']) {
  1347. return false;
  1348. }
  1349. if ($remote['type'] == '2') {
  1350. $bucket = rtrim(substr($remote['alioss']['bucket'], 0, strrpos($remote['alioss']['bucket'],'@')), '@');
  1351. $buckets = attachment_alioss_buctkets($remote['alioss']['key'], $remote['alioss']['secret']);
  1352. $host_name = $remote['alioss']['internal'] ? '-internal.aliyuncs.com' : '.aliyuncs.com';
  1353. $endpoint = 'http://' . $buckets[$bucket]['location'] . $host_name;
  1354. try {
  1355. $ossClient = new \app\common\services\aliyunoss\OssClient($remote['alioss']['key'], $remote['alioss']['secret'], $endpoint);
  1356. $ossClient->uploadFile($bucket, $filename, base_path('static/upload/') . $filename);
  1357. } catch (\app\common\services\aliyunoss\OSS\Core\OssException $e) {
  1358. \Log::info('-----alioss上传失败信息-----', $e->getMessage());
  1359. return error(1, $e->getMessage());
  1360. }
  1361. if ($auto_delete_local) {
  1362. file_delete($filename);
  1363. }
  1364. } elseif ($remote['type'] == '4') {
  1365. $result = (new \app\common\services\QcloudCosService(
  1366. $remote['cos']['local'],
  1367. $remote['cos']['secretid'],
  1368. $remote['cos']['secretkey'],
  1369. $remote['cos']['bucket'],
  1370. $remote['cos']['appid']
  1371. ))->upload($filename);
  1372. if ($auto_delete_local) {
  1373. file_delete($filename);
  1374. }
  1375. if ($result === true) {
  1376. return true;
  1377. } else {
  1378. return error(-1, $result);
  1379. }
  1380. }
  1381. }
  1382. }
  1383. if (!function_exists('file_video_remote_upload')) {
  1384. function file_video_remote_upload($filename, $auto_delete_local = true, $remote)
  1385. {
  1386. if (!$remote['type']) {
  1387. return false;
  1388. }
  1389. if ($remote['type'] == '2') {
  1390. $bucket = rtrim(substr($remote['alioss']['bucket'], 0, strrpos($remote['alioss']['bucket'],'@')), '@');
  1391. $buckets = attachment_alioss_buctkets($remote['alioss']['key'], $remote['alioss']['secret']);
  1392. $host_name = $remote['alioss']['internal'] ? '-internal.aliyuncs.com' : '.aliyuncs.com';
  1393. $endpoint = 'http://' . $buckets[$bucket]['location'] . $host_name;
  1394. try {
  1395. $ossClient = new \app\common\services\aliyunoss\OssClient($remote['alioss']['key'], $remote['alioss']['secret'], $endpoint);
  1396. $ossClient->uploadFile($bucket, $filename, base_path() . $filename);
  1397. } catch (\app\common\services\aliyunoss\OSS\Core\OssException $e) {
  1398. \Log::info('-----alioss上传失败信息-----', $e->getMessage());
  1399. return error(1, $e->getMessage());
  1400. }
  1401. if ($auto_delete_local) {
  1402. file_delete($filename);
  1403. }
  1404. } elseif ($remote['type'] == '4') {
  1405. $result = (new \app\common\services\QcloudCosService(
  1406. $remote['cos']['local'],
  1407. $remote['cos']['secretid'],
  1408. $remote['cos']['secretkey'],
  1409. $remote['cos']['bucket'],
  1410. $remote['cos']['appid']
  1411. ))->upload($filename);
  1412. if ($auto_delete_local) {
  1413. file_delete($filename);
  1414. }
  1415. if ($result === true) {
  1416. return true;
  1417. } else {
  1418. return error(-1, $result);
  1419. }
  1420. }
  1421. }
  1422. }
  1423. if (!function_exists('file_remote_upload_new')) {
  1424. function file_remote_upload_new($filename, $auto_delete_local = true, $remote)
  1425. {
  1426. if (!$remote['type']) {
  1427. return false;
  1428. }
  1429. if ($remote['type'] == '2') {
  1430. $bucket = rtrim(substr($remote['alioss']['bucket'], 0, strrpos($remote['alioss']['bucket'],'@')), '@');
  1431. $buckets = attachment_alioss_buctkets($remote['alioss']['key'], $remote['alioss']['secret']);
  1432. $host_name = $remote['alioss']['internal'] ? '-internal.aliyuncs.com' : '.aliyuncs.com';
  1433. $endpoint = 'http://' . $buckets[$bucket]['location'] . $host_name;
  1434. try {
  1435. $ossClient = new \app\common\services\aliyunoss\OssClient($remote['alioss']['key'], $remote['alioss']['secret'], $endpoint);
  1436. $ossClient->uploadFile($bucket, $filename, base_path() . '/static/upload/' . $filename);
  1437. } catch (\app\common\services\aliyunoss\OSS\Core\OssException $e) {
  1438. \Log::info('-----alioss上传失败信息-----', $e->getMessage());
  1439. return error(1, $e->getMessage());
  1440. }
  1441. if ($auto_delete_local) {
  1442. file_delete($filename);
  1443. }
  1444. } elseif ($remote['type'] == '4') {
  1445. $result = (new \app\common\services\QcloudCosService(
  1446. $remote['cos']['local'],
  1447. $remote['cos']['secretid'],
  1448. $remote['cos']['secretkey'],
  1449. $remote['cos']['bucket'],
  1450. $remote['cos']['appid']
  1451. ))->upload($filename);
  1452. if ($auto_delete_local) {
  1453. file_delete($filename);
  1454. }
  1455. if ($result === true) {
  1456. return true;
  1457. } else {
  1458. return error(-1, $result);
  1459. }
  1460. }
  1461. }
  1462. }
  1463. if (!function_exists('attachment_alioss_buctkets')) {
  1464. function attachment_alioss_buctkets($key, $secret)
  1465. {
  1466. $url = 'http://oss-cn-beijing.aliyuncs.com';
  1467. try {
  1468. $ossClient = new \app\common\services\aliyunoss\OssClient($key, $secret, $url);
  1469. } catch(\app\common\services\aliyunoss\OSS\Core\OssException $e) {
  1470. return error(1, $e->getMessage());
  1471. }
  1472. try {
  1473. $bucketlistinfo = $ossClient->listBuckets();
  1474. } catch(\app\common\services\aliyunoss\OSS\Core\OssException $e) {
  1475. return error(1, $e->getMessage());
  1476. }
  1477. $bucketlistinfo = $bucketlistinfo->getBucketList();
  1478. $bucketlist = array();
  1479. foreach ($bucketlistinfo as &$bucket) {
  1480. $bucketlist[$bucket->getName()] = array('name' => $bucket->getName(), 'location' => $bucket->getLocation());
  1481. }
  1482. return $bucketlist;
  1483. }
  1484. }
  1485. if (!function_exists('file_deletes')) {
  1486. function file_deletes($file)
  1487. {
  1488. if (empty($file)) {
  1489. return false;
  1490. }
  1491. if (file_exists($file)) {
  1492. @unlink($file);
  1493. }
  1494. if (strexists($file, 'image/')) {
  1495. $file = str_replace('image/', '', $file);
  1496. }
  1497. if (file_exists(ATTACHMENT_ROOT . 'image/' . $file)) {
  1498. @unlink(ATTACHMENT_ROOT . 'image/' . $file);
  1499. }
  1500. if (file_exists(ATTACHMENT_ROOT . $file)) {
  1501. @unlink(ATTACHMENT_ROOT . $file);
  1502. }
  1503. return true;
  1504. }
  1505. }
  1506. if (!function_exists('file_delete')) {
  1507. function file_delete($file)
  1508. {
  1509. if (empty($file)) {
  1510. return false;
  1511. }
  1512. if (file_exists($file)) {
  1513. @unlink($file);
  1514. }
  1515. if (file_exists(base_path() . '/static/upload/' . $file)) {
  1516. @unlink(base_path() . '/static/upload/' . $file);
  1517. }
  1518. return true;
  1519. }
  1520. }
  1521. if (!function_exists('safe_gpc_html')) {
  1522. function safe_gpc_html($value, $default = '')
  1523. {
  1524. if (empty($value) || !is_string($value)) {
  1525. return $default;
  1526. }
  1527. $value = safe_bad_str_replace($value);
  1528. $value = safe_remove_xss($value);
  1529. if (!$value && $value != $default) {
  1530. $value = $default;
  1531. }
  1532. return $value;
  1533. }
  1534. }
  1535. if (!function_exists('safe_bad_str_replace')) {
  1536. function safe_bad_str_replace($string)
  1537. {
  1538. if (!$string) {
  1539. return '';
  1540. }
  1541. $badstr = array("\0", "%00", "%3C", "%3E", '<?', '<%', '<?php', '{php', '../');
  1542. $newstr = array('_', '_', '&lt;', '&gt;', '_', '_', '_', '_', '.._');
  1543. $string = str_replace($badstr, $newstr, $string);
  1544. return $string;
  1545. }
  1546. }
  1547. if (!function_exists('safe_remove_xss')) {
  1548. function safe_remove_xss($val)
  1549. {
  1550. $val = preg_replace('/([\x0e-\x19])/', '', $val);
  1551. $search = 'abcdefghijklmnopqrstuvwxyz';
  1552. $search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1553. $search .= '1234567890!@#$%^&*()';
  1554. $search .= '~`";:?+/={}[]-_|\'\\';
  1555. for ($i = 0; $i < strlen($search); $i++) {
  1556. $val = preg_replace('/(&#[xX]0{0,8}' . dechex(ord($search[$i])) . ';?)/i', $search[$i], $val);
  1557. $val = preg_replace('/(&#0{0,8}' . ord($search[$i]) . ';?)/', $search[$i], $val);
  1558. }
  1559. preg_match_all('/href=[\'|\"](.*?)[\'|\"]|src=[\'|\"](.*?)[\'|\"]/i', $val, $matches);
  1560. $url_list = array_merge($matches[1], $matches[2]);
  1561. $encode_url_list = array();
  1562. if ($url_list) {
  1563. foreach ($url_list as $key => $url) {
  1564. $val = str_replace($url, 'we7_' . $key . '_we7placeholder', $val);
  1565. $encode_url_list[] = $url;
  1566. }
  1567. }
  1568. $ra1 = array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'script', 'embed', 'object', 'frameset', 'ilayer', 'bgsound', 'base');
  1569. $ra2 = array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload', '@import');
  1570. $ra = array_merge($ra1, $ra2);
  1571. $found = true;
  1572. while ($found == true) {
  1573. $val_before = $val;
  1574. for ($i = 0; $i < sizeof($ra); $i++) {
  1575. $pattern = '/';
  1576. for ($j = 0; $j < strlen($ra[$i]); $j++) {
  1577. if ($j > 0) {
  1578. $pattern .= '(';
  1579. $pattern .= '(&#[xX]0{0,8}([9ab]);)';
  1580. $pattern .= '|';
  1581. $pattern .= '|(&#0{0,8}([9|10|13]);)';
  1582. $pattern .= ')*';
  1583. }
  1584. $pattern .= $ra[$i][$j];
  1585. }
  1586. $pattern .= '/i';
  1587. $replacement = substr($ra[$i], 0, 2) . '<x>' . substr($ra[$i], 2);
  1588. $val = preg_replace($pattern, $replacement, $val);
  1589. if ($val_before == $val) {
  1590. $found = false;
  1591. }
  1592. }
  1593. }
  1594. if ($encode_url_list && is_array($encode_url_list)) {
  1595. foreach ($encode_url_list as $key => $url) {
  1596. $val = str_replace('we7_' . $key . '_we7placeholder', $url, $val);
  1597. }
  1598. }
  1599. return $val;
  1600. }
  1601. }
  1602. if (!function_exists('file_move')) {
  1603. function file_move($filename, $dest)
  1604. {
  1605. \app\common\services\Utils::mkdirs(dirname($dest));
  1606. if (is_uploaded_file($filename)) {
  1607. move_uploaded_file($filename, $dest);
  1608. } else {
  1609. rename($filename, $dest);
  1610. }
  1611. // @chmod($filename, $_W['config']['setting']['filemode']);
  1612. return is_file($dest);
  1613. }
  1614. }
  1615. if (!function_exists('pagination')) {
  1616. function pagination($total, $pageIndex, $pageSize = 15, $url = '', $context = array('before' => 5, 'after' => 4, 'ajaxcallback' => '', 'callbackfuncname' => ''))
  1617. {
  1618. $pdata = array(
  1619. 'tcount' => 0,
  1620. 'tpage' => 0,
  1621. 'cindex' => 0,
  1622. 'findex' => 0,
  1623. 'pindex' => 0,
  1624. 'nindex' => 0,
  1625. 'lindex' => 0,
  1626. 'options' => ''
  1627. );
  1628. if (!$context['before']) {
  1629. $context['before'] = 5;
  1630. }
  1631. if (!$context['after']) {
  1632. $context['after'] = 4;
  1633. }
  1634. if ($context['ajaxcallback']) {
  1635. $context['isajax'] = true;
  1636. }
  1637. if ($context['callbackfuncname']) {
  1638. $callbackfunc = $context['callbackfuncname'];
  1639. }
  1640. $pdata['tcount'] = $total;
  1641. $pdata['tpage'] = (!$pageSize || $pageSize < 0) ? 1 : intval(ceil($total / $pageSize));
  1642. if ($pdata['tpage'] <= 1) {
  1643. return '';
  1644. }
  1645. $cindex = $pageIndex;
  1646. $cindex = min($cindex, $pdata['tpage']);
  1647. $cindex = max($cindex, 1);
  1648. $pdata['cindex'] = $cindex;
  1649. $pdata['findex'] = 1;
  1650. $pdata['pindex'] = $cindex > 1 ? $cindex - 1 : 1;
  1651. $pdata['nindex'] = $cindex < $pdata['tpage'] ? $cindex + 1 : $pdata['tpage'];
  1652. $pdata['lindex'] = $pdata['tpage'];
  1653. if ($context['isajax']) {
  1654. if (!$url) {
  1655. $url = '/index.php/admin/system/upload/image' . '?' . http_build_query($_GET);
  1656. }
  1657. $pdata['faa'] = 'href="javascript:;" page="' . $pdata['findex'] . '" ' . ($callbackfunc ? 'ng-click="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['findex'] . '\', this);"' : '');
  1658. $pdata['paa'] = 'href="javascript:;" page="' . $pdata['pindex'] . '" ' . ($callbackfunc ? 'ng-click="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['pindex'] . '\', this);"' : '');
  1659. $pdata['naa'] = 'href="javascript:;" page="' . $pdata['nindex'] . '" ' . ($callbackfunc ? 'ng-click="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['nindex'] . '\', this);"' : '');
  1660. $pdata['laa'] = 'href="javascript:;" page="' . $pdata['lindex'] . '" ' . ($callbackfunc ? 'ng-click="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['lindex'] . '\', this);"' : '');
  1661. } else {
  1662. if ($url) {
  1663. $pdata['faa'] = 'href="?' . str_replace('*', $pdata['findex'], $url) . '"';
  1664. $pdata['paa'] = 'href="?' . str_replace('*', $pdata['pindex'], $url) . '"';
  1665. $pdata['naa'] = 'href="?' . str_replace('*', $pdata['nindex'], $url) . '"';
  1666. $pdata['laa'] = 'href="?' . str_replace('*', $pdata['lindex'], $url) . '"';
  1667. } else {
  1668. $_GET['page'] = $pdata['findex'];
  1669. $pdata['faa'] = 'href="' . '/index.php/admin/system/upload/image' . '?' . http_build_query($_GET) . '"';
  1670. $_GET['page'] = $pdata['pindex'];
  1671. $pdata['paa'] = 'href="' . '/index.php/admin/system/upload/image' . '?' . http_build_query($_GET) . '"';
  1672. $_GET['page'] = $pdata['nindex'];
  1673. $pdata['naa'] = 'href="' . '/index.php/admin/system/upload/image' . '?' . http_build_query($_GET) . '"';
  1674. $_GET['page'] = $pdata['lindex'];
  1675. $pdata['laa'] = 'href="' . '/index.php/admin/system/upload/image' . '?' . http_build_query($_GET) . '"';
  1676. }
  1677. }
  1678. $html = '<div><ul class="pagination pagination-centered">';
  1679. $html .= "<li><a {$pdata['faa']} class=\"pager-nav\">首页</a></li>";
  1680. empty($callbackfunc) && $html .= "<li><a {$pdata['paa']} class=\"pager-nav\">&laquo;上一页</a></li>";
  1681. if (!$context['before'] && $context['before'] != 0) {
  1682. $context['before'] = 5;
  1683. }
  1684. if (!$context['after'] && $context['after'] != 0) {
  1685. $context['after'] = 4;
  1686. }
  1687. if ($context['after'] != 0 && $context['before'] != 0) {
  1688. $range = array();
  1689. $range['start'] = max(1, $pdata['cindex'] - $context['before']);
  1690. $range['end'] = min($pdata['tpage'], $pdata['cindex'] + $context['after']);
  1691. if ($range['end'] - $range['start'] < $context['before'] + $context['after']) {
  1692. $range['end'] = min($pdata['tpage'], $range['start'] + $context['before'] + $context['after']);
  1693. $range['start'] = max(1, $range['end'] - $context['before'] - $context['after']);
  1694. }
  1695. for ($i = $range['start']; $i <= $range['end']; $i++) {
  1696. if ($context['isajax']) {
  1697. $aa = 'href="javascript:;" page="' . $i . '" ' . ($callbackfunc ? 'ng-click="' . $callbackfunc . '(\'' . $url . '\', \'' . $i . '\', this);"' : '');
  1698. } else {
  1699. if ($url) {
  1700. $aa = 'href="?' . str_replace('*', $i, $url) . '"';
  1701. } else {
  1702. $_GET['page'] = $i;
  1703. $aa = 'href="?' . http_build_query($_GET) . '"';
  1704. }
  1705. }
  1706. if (!empty($context['isajax'])) {
  1707. $html .= ($i == $pdata['cindex'] ? '<li class="active">' : '<li>') . "<a {$aa}>" . $i . '</a></li>';
  1708. } else {
  1709. $html .= ($i == $pdata['cindex'] ? '<li class="active"><a href="javascript:;">' . $i . '</a></li>' : "<li><a {$aa}>" . $i . '</a></li>');
  1710. }
  1711. }
  1712. }
  1713. if ($pdata['cindex'] < $pdata['tpage']) {
  1714. empty($callbackfunc) && $html .= "<li><a {$pdata['naa']} class=\"pager-nav\">下一页&raquo;</a></li>";
  1715. $html .= "<li><a {$pdata['laa']} class=\"pager-nav\">尾页</a></li>";
  1716. }
  1717. $html .= '</ul></div>';
  1718. return $html;
  1719. }
  1720. }
  1721. if (!function_exists('http_build_query')) {
  1722. /**
  1723. * 为了兼容微擎使用此方法
  1724. * @param $formdata
  1725. * @param null $numeric_prefix
  1726. * @param null $arg_separator
  1727. * @return bool|string
  1728. */
  1729. function http_build_query($formdata, $numeric_prefix = null, $arg_separator = null)
  1730. {
  1731. if (!is_array($formdata))
  1732. return false;
  1733. if ($arg_separator == null)
  1734. $arg_separator = '&';
  1735. return http_build_recursive($formdata, $arg_separator);
  1736. }
  1737. }
  1738. if (!function_exists('ihttp_get')) {
  1739. /**
  1740. * 为了兼容微擎使用此方法
  1741. * @param $url
  1742. * @return array
  1743. */
  1744. function ihttp_get($url)
  1745. {
  1746. return ihttp_request($url);
  1747. }
  1748. }
  1749. if (!function_exists('ihttp_request')) {
  1750. /**
  1751. * 为了兼容微擎使用此方法
  1752. * @param $url
  1753. * @param string $post
  1754. * @param array $extra
  1755. * @param int $timeout
  1756. * @return array
  1757. */
  1758. function ihttp_request($url, $post = '', $extra = array(), $timeout = 60)
  1759. {
  1760. if (function_exists('curl_init') && function_exists('curl_exec') && $timeout > 0) {
  1761. $ch = ihttp_build_curl($url, $post, $extra, $timeout);
  1762. if (is_error($ch)) {
  1763. return $ch;
  1764. }
  1765. $data = curl_exec($ch);
  1766. $status = curl_getinfo($ch);
  1767. $errno = curl_errno($ch);
  1768. $error = curl_error($ch);
  1769. curl_close($ch);
  1770. if ($errno || !$data) {
  1771. return error($errno, $error);
  1772. } else {
  1773. return ihttp_response_parse($data);
  1774. }
  1775. }
  1776. $urlset = ihttp_parse_url($url, true);
  1777. if ($urlset['ip']) {
  1778. $urlset['host'] = $urlset['ip'];
  1779. }
  1780. $body = ihttp_build_httpbody($url, $post, $extra);
  1781. if ($urlset['scheme'] == 'https') {
  1782. $fp = ihttp_socketopen('ssl://' . $urlset['host'], $urlset['port'], $errno, $error);
  1783. } else {
  1784. $fp = ihttp_socketopen($urlset['host'], $urlset['port'], $errno, $error);
  1785. }
  1786. stream_set_blocking($fp, $timeout > 0 ? true : false);
  1787. stream_set_timeout($fp, ini_get('default_socket_timeout'));
  1788. if (!$fp) {
  1789. return error(1, $error);
  1790. } else {
  1791. fwrite($fp, $body);
  1792. $content = '';
  1793. if ($timeout > 0) {
  1794. while (!feof($fp)) {
  1795. $content .= fgets($fp, 512);
  1796. }
  1797. }
  1798. fclose($fp);
  1799. return ihttp_response_parse($content, true);
  1800. }
  1801. }
  1802. }
  1803. if (!function_exists('ihttp_build_curl')) {
  1804. /**
  1805. * 为了兼容微擎使用此方法
  1806. * @param $url
  1807. * @param $post
  1808. * @param $extra
  1809. * @param $timeout
  1810. * @return resource
  1811. */
  1812. function ihttp_build_curl($url, $post, $extra, $timeout)
  1813. {
  1814. if (!function_exists('curl_init') || !function_exists('curl_exec')) {
  1815. return error(1, 'curl扩展未开启');
  1816. }
  1817. $urlset = ihttp_parse_url($url);
  1818. if (is_error($urlset)) {
  1819. return $urlset;
  1820. }
  1821. if ($urlset['ip']) {
  1822. $extra['ip'] = $urlset['ip'];
  1823. }
  1824. $ch = curl_init();
  1825. if ($extra['ip']) {
  1826. $extra['Host'] = $urlset['host'];
  1827. $urlset['host'] = $extra['ip'];
  1828. unset($extra['ip']);
  1829. }
  1830. curl_setopt($ch, CURLOPT_URL, $urlset['scheme'] . '://' . $urlset['host'] . ($urlset['port'] == '80' || !$urlset['port'] ? '' : ':' . $urlset['port']) . $urlset['path'] . $urlset['query']);
  1831. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1832. @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  1833. curl_setopt($ch, CURLOPT_HEADER, 1);
  1834. @curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
  1835. if ($post) {
  1836. if (is_array($post)) {
  1837. $filepost = false;
  1838. foreach ($post as $name => &$value) {
  1839. if (version_compare(phpversion(), '5.5') >= 0 && is_string($value) && substr($value, 0, 1) == '@') {
  1840. $post[$name] = new CURLFile(ltrim($value, '@'));
  1841. }
  1842. if ((is_string($value) && substr($value, 0, 1) == '@') || (class_exists('CURLFile') && $value instanceof CURLFile)) {
  1843. $filepost = true;
  1844. }
  1845. }
  1846. if (!$filepost) {
  1847. $post = http_build_query($post);
  1848. }
  1849. }
  1850. curl_setopt($ch, CURLOPT_POST, 1);
  1851. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  1852. }
  1853. if ($GLOBALS['_W']['config']['setting']['proxy']) {
  1854. $urls = parse_url($GLOBALS['_W']['config']['setting']['proxy']['host']);
  1855. if (!empty($urls['host'])) {
  1856. curl_setopt($ch, CURLOPT_PROXY, "{$urls['host']}:{$urls['port']}");
  1857. $proxytype = 'CURLPROXY_' . strtoupper($urls['scheme']);
  1858. if ($urls['scheme'] && defined($proxytype)) {
  1859. curl_setopt($ch, CURLOPT_PROXYTYPE, constant($proxytype));
  1860. } else {
  1861. curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  1862. curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
  1863. }
  1864. if ($GLOBALS['_W']['config']['setting']['proxy']['auth']) {
  1865. curl_setopt($ch, CURLOPT_PROXYUSERPWD, $GLOBALS['_W']['config']['setting']['proxy']['auth']);
  1866. }
  1867. }
  1868. }
  1869. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  1870. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  1871. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1872. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1873. curl_setopt($ch, CURLOPT_SSLVERSION, 1);
  1874. if (defined('CURL_SSLVERSION_TLSv1')) {
  1875. curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
  1876. }
  1877. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1');
  1878. if ($extra && is_array($extra)) {
  1879. $headers = array();
  1880. foreach ($extra as $opt => $value) {
  1881. if (strexists($opt, 'CURLOPT_')) {
  1882. curl_setopt($ch, constant($opt), $value);
  1883. } elseif (is_numeric($opt)) {
  1884. curl_setopt($ch, $opt, $value);
  1885. } else {
  1886. $headers[] = "{$opt}: {$value}";
  1887. }
  1888. }
  1889. if ($headers) {
  1890. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  1891. }
  1892. }
  1893. return $ch;
  1894. }
  1895. }
  1896. if (!function_exists('ihttp_parse_url')) {
  1897. /**
  1898. * 为了兼容微擎使用此方法
  1899. * @param $url
  1900. * @param bool $set_default_port
  1901. * @return array|mixed
  1902. */
  1903. function ihttp_parse_url($url, $set_default_port = false)
  1904. {
  1905. if (!$url) {
  1906. return error(1);
  1907. }
  1908. $urlset = parse_url($url);
  1909. if ($urlset['scheme'] && !in_array($urlset['scheme'], array('http', 'https'))) {
  1910. return error(1, '只能使用 http 及 https 协议');
  1911. }
  1912. if (!$urlset['path']) {
  1913. $urlset['path'] = '/';
  1914. }
  1915. if ($urlset['query']) {
  1916. $urlset['query'] = "?{$urlset['query']}";
  1917. }
  1918. if (strexists($url, 'https://') && !extension_loaded('openssl')) {
  1919. if (!extension_loaded("openssl")) {
  1920. return error(1, '请开启您PHP环境的openssl', '');
  1921. }
  1922. }
  1923. if (!$urlset['host']) {
  1924. $current_url = parse_url($GLOBALS['_W']['siteroot']);
  1925. $urlset['host'] = $current_url['host'];
  1926. $urlset['scheme'] = $current_url['scheme'];
  1927. $urlset['path'] = $current_url['path'] . 'web/' . str_replace('./', '', $urlset['path']);
  1928. $urlset['ip'] = '127.0.0.1';
  1929. } else if (!ihttp_allow_host($urlset['host'])) {
  1930. return error(1, 'host 非法');
  1931. }
  1932. if ($set_default_port && !$urlset['port']) {
  1933. $urlset['port'] = $urlset['scheme'] == 'https' ? '443' : '80';
  1934. }
  1935. return $urlset;
  1936. }
  1937. }
  1938. if (!function_exists('error')) {
  1939. /**
  1940. * 为了兼容微擎使用此方法
  1941. * @param $errno
  1942. * @param string $message
  1943. * @return array
  1944. */
  1945. function error($errno, $message = '')
  1946. {
  1947. return array(
  1948. 'errno' => $errno,
  1949. 'message' => $message,
  1950. );
  1951. }
  1952. }
  1953. if (!function_exists('http_build_recursive')) {
  1954. /**
  1955. * 为了兼容微擎使用此方法
  1956. * @param $formdata
  1957. * @param $separator
  1958. * @param string $key
  1959. * @param string $prefix
  1960. * @return string
  1961. */
  1962. function http_build_recursive($formdata, $separator, $key = '', $prefix = '')
  1963. {
  1964. $rlt = '';
  1965. foreach ($formdata as $k => $v) {
  1966. if (is_array($v)) {
  1967. if ($key)
  1968. $rlt .= http_build_recursive($v, $separator, $key . '[' . $k . ']', $prefix);
  1969. else
  1970. $rlt .= http_build_recursive($v, $separator, $k, $prefix);
  1971. } else {
  1972. if ($key)
  1973. $rlt .= $prefix . $key . '[' . urlencode($k) . ']=' . urldecode($v) . '&';
  1974. else
  1975. $rlt .= $prefix . urldecode($k) . '=' . urldecode($v) . '&';
  1976. }
  1977. }
  1978. return $rlt;
  1979. }
  1980. }
  1981. if (!function_exists('ihttp_response_parse')) {
  1982. /**
  1983. * 为了兼容微擎使用此方法
  1984. * @param $data
  1985. * @param bool $chunked
  1986. * @return array
  1987. */
  1988. function ihttp_response_parse($data, $chunked = false)
  1989. {
  1990. $rlt = array();
  1991. $headermeta = explode('HTTP/', $data);
  1992. if (count($headermeta) > 2) {
  1993. $data = 'HTTP/' . array_pop($headermeta);
  1994. }
  1995. $pos = strpos($data, "\r\n\r\n");
  1996. $split1[0] = substr($data, 0, $pos);
  1997. $split1[1] = substr($data, $pos + 4, strlen($data));
  1998. $split2 = explode("\r\n", $split1[0], 2);
  1999. preg_match('/^(\S+) (\S+) (.*)$/', $split2[0], $matches);
  2000. $rlt['code'] = $matches[2] ? : 200;
  2001. $rlt['status'] = $matches[3] ? : 'OK';
  2002. $rlt['responseline'] = $split2[0] ? : '';
  2003. $header = explode("\r\n", $split2[1]);
  2004. $isgzip = false;
  2005. $ischunk = false;
  2006. foreach ($header as $v) {
  2007. $pos = strpos($v, ':');
  2008. $key = substr($v, 0, $pos);
  2009. $value = trim(substr($v, $pos + 1));
  2010. if (is_array($rlt['headers'][$key])) {
  2011. $rlt['headers'][$key][] = $value;
  2012. } elseif ($rlt['headers'][$key]) {
  2013. $temp = $rlt['headers'][$key];
  2014. unset($rlt['headers'][$key]);
  2015. $rlt['headers'][$key][] = $temp;
  2016. $rlt['headers'][$key][] = $value;
  2017. } else {
  2018. $rlt['headers'][$key] = $value;
  2019. }
  2020. if (!$isgzip && strtolower($key) == 'content-encoding' && strtolower($value) == 'gzip') {
  2021. $isgzip = true;
  2022. }
  2023. if (!$ischunk && strtolower($key) == 'transfer-encoding' && strtolower($value) == 'chunked') {
  2024. $ischunk = true;
  2025. }
  2026. }
  2027. if ($chunked && $ischunk) {
  2028. $rlt['content'] = ihttp_response_parse_unchunk($split1[1]);
  2029. } else {
  2030. $rlt['content'] = $split1[1];
  2031. }
  2032. if ($isgzip && function_exists('gzdecode')) {
  2033. $rlt['content'] = gzdecode($rlt['content']);
  2034. }
  2035. $rlt['meta'] = $data;
  2036. if ($rlt['code'] == '100') {
  2037. return ihttp_response_parse($rlt['content']);
  2038. }
  2039. return $rlt;
  2040. }
  2041. }
  2042. if (!function_exists('ihttp_response_parse_unchunk')) {
  2043. /**
  2044. * 为了兼容微擎使用此方法
  2045. * @param null $str
  2046. * @return bool|string|null
  2047. */
  2048. function ihttp_response_parse_unchunk($str = null)
  2049. {
  2050. if (!is_string($str) or strlen($str) < 1) {
  2051. return false;
  2052. }
  2053. $eol = "\r\n";
  2054. $add = strlen($eol);
  2055. $tmp = $str;
  2056. $str = '';
  2057. do {
  2058. $tmp = ltrim($tmp);
  2059. $pos = strpos($tmp, $eol);
  2060. if ($pos === false) {
  2061. return false;
  2062. }
  2063. $len = hexdec(substr($tmp, 0, $pos));
  2064. if (!is_numeric($len) or $len < 0) {
  2065. return false;
  2066. }
  2067. $str .= substr($tmp, ($pos + $add), $len);
  2068. $tmp = substr($tmp, ($len + $pos + $add));
  2069. $check = trim($tmp);
  2070. } while ($check);
  2071. unset($tmp);
  2072. return $str;
  2073. }
  2074. }
  2075. if (!function_exists('ihttp_build_httpbody')) {
  2076. /**
  2077. * 为了兼容微擎使用此方法
  2078. * @param $url
  2079. * @param $post
  2080. * @param $extra
  2081. * @return array|mixed|string
  2082. */
  2083. function ihttp_build_httpbody($url, $post, $extra)
  2084. {
  2085. $urlset = ihttp_parse_url($url, true);
  2086. if (is_error($urlset)) {
  2087. return $urlset;
  2088. }
  2089. if ($urlset['ip']) {
  2090. $extra['ip'] = $urlset['ip'];
  2091. }
  2092. $body = '';
  2093. if ($post && is_array($post)) {
  2094. $filepost = false;
  2095. $boundary = random(40);
  2096. foreach ($post as $name => &$value) {
  2097. if ((is_string($value) && substr($value, 0, 1) == '@') && file_exists(ltrim($value, '@'))) {
  2098. $filepost = true;
  2099. $file = ltrim($value, '@');
  2100. $body .= "--$boundary\r\n";
  2101. $body .= 'Content-Disposition: form-data; name="' . $name . '"; filename="' . basename($file) . '"; Content-Type: application/octet-stream' . "\r\n\r\n";
  2102. $body .= file_get_contents($file) . "\r\n";
  2103. } else {
  2104. $body .= "--$boundary\r\n";
  2105. $body .= 'Content-Disposition: form-data; name="' . $name . '"' . "\r\n\r\n";
  2106. $body .= $value . "\r\n";
  2107. }
  2108. }
  2109. if (!$filepost) {
  2110. $body = http_build_query($post, '', '&');
  2111. } else {
  2112. $body .= "--$boundary\r\n";
  2113. }
  2114. }
  2115. $method = !$post ? 'GET' : 'POST';
  2116. $fdata = "{$method} {$urlset['path']}{$urlset['query']} HTTP/1.1\r\n";
  2117. $fdata .= "Accept: */*\r\n";
  2118. $fdata .= "Accept-Language: zh-cn\r\n";
  2119. if ($method == 'POST') {
  2120. $fdata .= !$filepost ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data; boundary=$boundary\r\n";
  2121. }
  2122. $fdata .= "Host: {$urlset['host']}\r\n";
  2123. $fdata .= "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1\r\n";
  2124. if (function_exists('gzdecode')) {
  2125. $fdata .= "Accept-Encoding: gzip, deflate\r\n";
  2126. }
  2127. $fdata .= "Connection: close\r\n";
  2128. if ($extra && is_array($extra)) {
  2129. foreach ($extra as $opt => $value) {
  2130. if (!strexists($opt, 'CURLOPT_')) {
  2131. $fdata .= "{$opt}: {$value}\r\n";
  2132. }
  2133. }
  2134. }
  2135. if ($body) {
  2136. $fdata .= 'Content-Length: ' . strlen($body) . "\r\n\r\n{$body}";
  2137. } else {
  2138. $fdata .= "\r\n";
  2139. }
  2140. return $fdata;
  2141. }
  2142. }
  2143. if (!function_exists('ihttp_socketopen')) {
  2144. function ihttp_socketopen($hostname, $port = 80, &$errno, &$errstr, $timeout = 15)
  2145. {
  2146. $fp = '';
  2147. if (function_exists('fsockopen')) {
  2148. $fp = @fsockopen($hostname, $port, $errno, $errstr, $timeout);
  2149. } elseif (function_exists('pfsockopen')) {
  2150. $fp = @pfsockopen($hostname, $port, $errno, $errstr, $timeout);
  2151. } elseif (function_exists('stream_socket_client')) {
  2152. $fp = @stream_socket_client($hostname . ':' . $port, $errno, $errstr, $timeout);
  2153. }
  2154. return $fp;
  2155. }
  2156. }
  2157. if (!function_exists('ihttp_allow_host')) {
  2158. /**
  2159. * 为了兼容微擎使用此方法
  2160. * @param $host
  2161. * @return bool
  2162. */
  2163. function ihttp_allow_host($host)
  2164. {
  2165. if (strexists($host, '@')) {
  2166. return false;
  2167. }
  2168. $pattern = "/^(10|172|192|127)/";
  2169. $global = YunShop::app();
  2170. if (preg_match($pattern, $host) && isset($global['setting']['ip_white_list'])) {
  2171. $ip_white_list = $global['setting']['ip_white_list'];
  2172. if ($ip_white_list && isset($ip_white_list[$host]) && !$ip_white_list[$host]['status']) {
  2173. return false;
  2174. }
  2175. }
  2176. return true;
  2177. }
  2178. }
  2179. if (!function_exists('attachment_cos_auth')) {
  2180. function attachment_cos_auth($bucket, $appid, $key, $secret, $bucket_local = '')
  2181. {
  2182. if (!is_numeric($appid)) {
  2183. return error(-1, '传入appid值不合法, 请重新输入');
  2184. }
  2185. if (!preg_match('/^[a-zA-Z0-9]{36}$/', $key)) {
  2186. return error(-1, '传入secretid值不合法,请重新传入');
  2187. }
  2188. if (!preg_match('/^[a-zA-Z0-9]{32}$/', $secret)) {
  2189. return error(-1, '传入secretkey值不合法,请重新传入');
  2190. }
  2191. $filename = 'logo.png';
  2192. $result = (new \app\common\services\QcloudCosService($bucket_local, $key, $secret, $bucket, $appid))->uploadTest($filename);
  2193. if ($result === true) {
  2194. return true;
  2195. } else {
  2196. return error(-1, $result);
  2197. }
  2198. }
  2199. }
  2200. if (!function_exists('file_tree')) {
  2201. function file_tree($path, $include = array()) {
  2202. $files = array();
  2203. if ($include) {
  2204. $ds = glob($path . '/{' . implode(',', $include) . '}', GLOB_BRACE);
  2205. } else {
  2206. $ds = glob($path . '/*');
  2207. }
  2208. if (is_array($ds)) {
  2209. foreach ($ds as $entry) {
  2210. if (is_file($entry)) {
  2211. $files[] = $entry;
  2212. }
  2213. if (is_dir($entry)) {
  2214. $rs = file_tree($entry);
  2215. foreach ($rs as $f) {
  2216. $files[] = $f;
  2217. }
  2218. }
  2219. }
  2220. }
  2221. return $files;
  2222. }
  2223. }
  2224. if (!function_exists('parse_path')) {
  2225. function parse_path($path)
  2226. {
  2227. $danger_char = array('../', '{php', '<?php', '<%', '<?', '..\\', '\\\\', '\\', '..\\\\', '%00', '\0', '\r');
  2228. foreach ($danger_char as $char) {
  2229. if (strexists($path, $char)) {
  2230. return false;
  2231. }
  2232. }
  2233. return $path;
  2234. }
  2235. }
  2236. if (!function_exists('bytecount')) {
  2237. function bytecount($str)
  2238. {
  2239. if (strtolower($str[strlen($str) - 1]) == 'b') {
  2240. $str = substr($str, 0, -1);
  2241. }
  2242. if (strtolower($str[strlen($str) - 1]) == 'k') {
  2243. return floatval($str) * 1024;
  2244. }
  2245. if (strtolower($str[strlen($str) - 1]) == 'm') {
  2246. return floatval($str) * 1048576;
  2247. }
  2248. if (strtolower($str[strlen($str) - 1]) == 'g') {
  2249. return floatval($str) * 1073741824;
  2250. }
  2251. }
  2252. }
  2253. if (!function_exists('attachment_alioss_datacenters')) {
  2254. function attachment_alioss_datacenters()
  2255. {
  2256. $bucket_datacenter = array(
  2257. 'oss-cn-hangzhou' => '杭州数据中心',
  2258. 'oss-cn-qingdao' => '青岛数据中心',
  2259. 'oss-cn-beijing' => '北京数据中心',
  2260. 'oss-cn-hongkong' => '香港数据中心',
  2261. 'oss-cn-shenzhen' => '深圳数据中心',
  2262. 'oss-cn-shanghai' => '上海数据中心',
  2263. 'oss-us-west-1' => '美国硅谷数据中心',
  2264. );
  2265. return $bucket_datacenter;
  2266. }
  2267. }
  2268. if (!function_exists('attachment_newalioss_auth')) {
  2269. function attachment_newalioss_auth($key, $secret, $bucket, $internal = false)
  2270. {
  2271. $buckets = attachment_alioss_buctkets($key, $secret);
  2272. $host = $internal ? '-internal.aliyuncs.com' : '.aliyuncs.com';
  2273. $url = 'http://' . $buckets[$bucket]['location'] . $host;
  2274. $filename = 'logo.png';
  2275. try {
  2276. $ossClient = new \app\common\services\aliyunoss\OssClient($key, $secret, $url);
  2277. $ossClient->uploadFile($bucket, $filename, base_path() . '/static/' . $filename);
  2278. } catch (\app\common\services\aliyunoss\OSS\Core\OssException $e) {
  2279. return error(1, $e->getMessage());
  2280. }
  2281. return 1;
  2282. }
  2283. }
  2284. if (!function_exists('getimagesizefromstring')) {
  2285. function getimagesizefromstring($string_data) {
  2286. $uri = 'data://application/octet-stream;base64,' . base64_encode($string_data);
  2287. return getimagesize($uri);
  2288. }
  2289. }
  2290. if (!function_exists('yz_buildCustomPostFields')) {
  2291. /**
  2292. * Build custom post fields for safe multipart POST request for php before 5.5.
  2293. * @param $fields array of key -> value fields to post.
  2294. * @return $boundary and encoded post fields.
  2295. */
  2296. function yz_buildCustomPostFields($fields)
  2297. {
  2298. // invalid characters for "name" and "filename"
  2299. static $disallow = array("\0", "\"", "\r", "\n");
  2300. // initialize body
  2301. $body = array();
  2302. // build normal parameters
  2303. foreach ($fields as $key => $value) {
  2304. $key = str_replace($disallow, "_", $key);
  2305. $body[] = implode("\r\n", array(
  2306. "Content-Disposition: form-data; name=\"{$key}\"",
  2307. '',
  2308. filter_var($value),
  2309. ));
  2310. }
  2311. // generate safe boundary
  2312. do {
  2313. $boundary = "---------------------" . md5(mt_rand() . microtime());
  2314. } while (preg_grep("/{$boundary}/", $body));
  2315. // add boundary for each parameters
  2316. foreach ($body as &$part) {
  2317. $part = "--{$boundary}\r\n{$part}";
  2318. }
  2319. unset($part);
  2320. // add final boundary
  2321. $body[] = "--{$boundary}--";
  2322. $body[] = '';
  2323. return array($boundary, implode("\r\n", $body));
  2324. }
  2325. }
  2326. if (!function_exists('resource_get')) {
  2327. function resource_get($file, $depth=2)
  2328. {
  2329. if (config('app.framework') == 'platform') {
  2330. return '/' . $file;
  2331. }
  2332. $path = $depth == 2 ? '../..' : '..';
  2333. return $path . '/addons/yun_shop/' . $file;
  2334. }
  2335. }
  2336. if (!function_exists('tpl_form_field_image')) {
  2337. function tpl_form_field_image($name, $value = '', $default = '', $options = array())
  2338. {
  2339. if (empty($default)) {
  2340. $default = static_url('resource/images/nopic.jpg');
  2341. }
  2342. $val = $default;
  2343. if (!empty($value)) {
  2344. $val = tomedia($value);
  2345. }
  2346. if (!empty($options['global'])) {
  2347. $options['global'] = true;
  2348. } else {
  2349. $options['global'] = false;
  2350. }
  2351. if (empty($options['class_extra'])) {
  2352. $options['class_extra'] = '';
  2353. }
  2354. if (isset($options['dest_dir']) && !empty($options['dest_dir'])) {
  2355. if (!preg_match('/^\w+([\/]\w+)?$/i', $options['dest_dir'])) {
  2356. exit('图片上传目录错误,只能指定最多两级目录,如: "yz_store","yz_store/d1"');
  2357. }
  2358. }
  2359. $options['direct'] = true;
  2360. $options['multiple'] = false;
  2361. if (isset($options['thumb'])) {
  2362. $options['thumb'] = !empty($options['thumb']);
  2363. }
  2364. $param = uploadParam();
  2365. $options['fileSizeLimit'] = $param['fileSizeLimit'];
  2366. $s = '';
  2367. if (!defined('TPL_INIT_IMAGE')) {
  2368. $s = '
  2369. <script type="text/javascript">
  2370. function showImageDialog(elm, opts, options) {
  2371. require(["'.$param['util'].'"], function(util){
  2372. var btn = $(elm);
  2373. var ipt = btn.parent().prev();
  2374. var val = ipt.val();
  2375. var img = ipt.parent().next().children();
  2376. options = '.str_replace('"', '\'', json_encode($options)).';
  2377. util.image(val, function(url){
  2378. if(url.url){
  2379. if(img.length > 0){
  2380. img.get(0).src = url.url;
  2381. }
  2382. ipt.val(url.attachment);
  2383. ipt.attr("filename",url.filename);
  2384. ipt.attr("url",url.url);
  2385. }
  2386. if(url.media_id){
  2387. if(img.length > 0){
  2388. img.get(0).src = "";
  2389. }
  2390. ipt.val(url.media_id);
  2391. }
  2392. }, options);
  2393. });
  2394. }
  2395. function deleteImage(elm){
  2396. $(elm).prev().attr("src", "static/resource/images/nopic.jpg");
  2397. $(elm).parent().prev().find("input").val("");
  2398. }
  2399. </script>';
  2400. define('TPL_INIT_IMAGE', true);
  2401. }
  2402. $s .= '
  2403. <div class="input-group ' . $options['class_extra'] . '">
  2404. <input type="text" name="' . $name . '" value="' . $value . '"' . ($options['extras']['text'] ? $options['extras']['text'] : '') . ' class="form-control" autocomplete="off">
  2405. <span class="input-group-btn">
  2406. <button class="btn btn-default" type="button" onclick="showImageDialog(this);">选择图片</button>
  2407. </span>
  2408. </div>
  2409. <div class="input-group ' . $options['class_extra'] . '" style="margin-top:.5em;">
  2410. <img src="' . $val . '" onerror="this.src=\'' . $default . '\'; this.title=\'图片未找到.\'" class="img-responsive img-thumbnail" ' . ($options['extras']['image'] ? $options['extras']['image'] : '') . ' width="150" />
  2411. <em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除这张图片" onclick="deleteImage(this)">×</em>
  2412. </div>';
  2413. return $s;
  2414. }
  2415. }
  2416. if (!function_exists('tpl_form_field_color')) {
  2417. function tpl_form_field_color($name, $value = '')
  2418. {
  2419. $s = '';
  2420. if (!defined('TPL_INIT_COLOR')) {
  2421. $s = '
  2422. <script type="text/javascript">
  2423. $(function(){
  2424. $(".colorpicker").each(function(){
  2425. var elm = this;
  2426. util.colorpicker(elm, function(color){
  2427. $(elm).parent().prev().prev().val(color.toHexString());
  2428. $(elm).parent().prev().css("background-color", color.toHexString());
  2429. });
  2430. });
  2431. $(".colorclean").click(function(){
  2432. $(this).parent().prev().prev().val("");
  2433. $(this).parent().prev().css("background-color", "#FFF");
  2434. });
  2435. });
  2436. </script>';
  2437. define('TPL_INIT_COLOR', true);
  2438. }
  2439. $s .= '
  2440. <div class="row row-fix">
  2441. <div class="col-xs-8 col-sm-8" style="padding-right:0;">
  2442. <div class="input-group">
  2443. <input class="form-control" type="text" name="'.$name.'" placeholder="请选择颜色" value="'.$value.'">
  2444. <span class="input-group-addon" style="width:35px;border-left:none;background-color:'.$value.'"></span>
  2445. <span class="input-group-btn">
  2446. <button class="btn btn-default colorpicker" type="button">选择颜色 <i class="fa fa-caret-down"></i></button>
  2447. <button class="btn btn-default colorclean" type="button"><span><i class="fa fa-remove"></i></span></button>
  2448. </span>
  2449. </div>
  2450. </div>
  2451. </div>
  2452. ';
  2453. return $s;
  2454. }
  2455. }
  2456. if (!function_exists('safe_gpc_array')) {
  2457. function safe_gpc_array($value, $default = array())
  2458. {
  2459. if (!$value || !is_array($value)) {
  2460. return $default;
  2461. }
  2462. foreach ($value as &$row) {
  2463. if (is_numeric($row)) {
  2464. $row = safe_gpc_int($row);
  2465. } elseif (is_array($row)) {
  2466. $row = safe_gpc_array($row, $default);
  2467. } else {
  2468. $row = safe_gpc_string($row);
  2469. }
  2470. }
  2471. return $value;
  2472. }
  2473. }
  2474. if (!function_exists('safe_gpc_int')) {
  2475. function safe_gpc_int($value, $default = 0)
  2476. {
  2477. if (strpos($value, '.') !== false) {
  2478. $value = floatval($value);
  2479. $default = floatval($default);
  2480. } else {
  2481. $value = intval($value);
  2482. $default = intval($default);
  2483. }
  2484. if (!$value && $default != $value) {
  2485. $value = $default;
  2486. }
  2487. return $value;
  2488. }
  2489. }
  2490. if (!function_exists('file_remote_delete')) {
  2491. function file_remote_delete($file, $upload_type, $remote)
  2492. {
  2493. if (!$file) {
  2494. return true;
  2495. }
  2496. if ($upload_type == '2') {
  2497. $bucket = rtrim(substr($remote['alioss']['bucket'], 0, strrpos($remote['alioss']['bucket'],'@')), '@');
  2498. $buckets = attachment_alioss_buctkets($remote['alioss']['key'], $remote['alioss']['secret']);
  2499. $endpoint = 'https://' . $buckets[$bucket]['location'] . '.aliyuncs.com';
  2500. try {
  2501. $ossClient = new \app\common\services\aliyunoss\OssClient($remote['alioss']['key'], $remote['alioss']['secret'], $endpoint);
  2502. $ossClient->deleteObject($bucket, $file);
  2503. } catch (\app\common\services\aliyunoss\OSS\Core\OssException $e) {
  2504. return error(1, '删除oss远程文件失败');
  2505. }
  2506. } elseif ($upload_type == '4') {
  2507. $bucketName = $remote['cos']['bucket'];
  2508. $path = '/' . $file;
  2509. if ($remote['cos']['local']) {
  2510. \app\common\services\qcloud\Cosapi::setRegion($remote['cos']['local']);
  2511. $result = \app\common\services\qcloud\Cosapi::delFile($bucketName, $path);
  2512. } else {
  2513. $result = \app\common\services\cos\Qcloud_cos\Cosapi::delFile($bucketName, $path);
  2514. }
  2515. if ($result['code']) {
  2516. return error(-1, '删除cos远程文件失败');
  2517. } else {
  2518. return true;
  2519. }
  2520. }
  2521. return true;
  2522. }
  2523. }
  2524. if (!function_exists('material_list')) {
  2525. function material_list($type = '', $server = '', $page = array('page_index' => 1, 'page_size' => 24), $uniacid = 0, $offset)
  2526. {
  2527. $core_attach = array('local' => new \app\platform\modules\application\models\CoreAttach, 'perm' => new app\platform\modules\application\models\WechatAttachment);
  2528. $conditions['uniacid'] = $uniacid;
  2529. $core_attach = $core_attach[$server];
  2530. switch ($type) {
  2531. case 'voice' :
  2532. $conditions['type'] = $server == 'local' ? 2 : 'voice';
  2533. break;
  2534. case 'video' :
  2535. $conditions['type'] = $server == 'local' ? 3 : 'video';
  2536. break;
  2537. default :
  2538. $conditions['type'] = $server == 'local' ? 1 : 'image';
  2539. break;
  2540. }
  2541. if ($server == 'local') {
  2542. $core_attach = $core_attach->where($conditions)->orderBy('created_at', 'desc');
  2543. $total = $core_attach->count();
  2544. $core_attach = $core_attach->offset($offset)->limit($page['page_size'])->get();
  2545. } else {
  2546. $conditions['model'] = 'perm';
  2547. $core_attach = $core_attach->where($conditions)->orderBy('created_at', 'desc');
  2548. $total = $core_attach->count();
  2549. $core_attach = $core_attach->offset($offset)->limit($page['page_size'])->get();
  2550. if ($type == 'video') {
  2551. foreach ($core_attach as &$row) {
  2552. $row['tag'] = $row['tag'] == '' ? array() : iunserializer($row['tag']);
  2553. }
  2554. unset($row);
  2555. }
  2556. }
  2557. $pager = pagination($total, $page['page_index'], $page['page_size'], '', $context = array('before' => 5, 'after' => 4, 'isajax' => '1'));
  2558. $material_news = array('material_list' => $core_attach, 'page' => $pager);
  2559. return $material_news;
  2560. }
  2561. }
  2562. if (!function_exists('iunserializer')) {
  2563. function iunserializer($value)
  2564. {
  2565. if (!$value) {
  2566. return array();
  2567. }
  2568. if (!is_serialized($value)) {
  2569. return $value;
  2570. }
  2571. $result = unserialize($value);
  2572. if ($result === false) {
  2573. $temp = preg_replace_callback('!s:(\d+):"(.*?)";!s', function ($matchs) {
  2574. return 's:' . strlen($matchs[2]) . ':"' . $matchs[2] . '";';
  2575. }, $value);
  2576. return unserialize($temp);
  2577. } else {
  2578. return $result;
  2579. }
  2580. }
  2581. }
  2582. if (!function_exists('is_serialized')) {
  2583. function is_serialized($data, $strict = true)
  2584. {
  2585. if (!is_string($data)) {
  2586. return false;
  2587. }
  2588. $data = trim($data);
  2589. if ('N;' == $data) {
  2590. return true;
  2591. }
  2592. if (strlen($data) < 4) {
  2593. return false;
  2594. }
  2595. if (':' !== $data[1]) {
  2596. return false;
  2597. }
  2598. if ($strict) {
  2599. $lastc = substr($data, -1);
  2600. if (';' !== $lastc && '}' !== $lastc) {
  2601. return false;
  2602. }
  2603. } else {
  2604. $semicolon = strpos($data, ';');
  2605. $brace = strpos($data, '}');
  2606. if (false === $semicolon && false === $brace)
  2607. return false;
  2608. if (false !== $semicolon && $semicolon < 3)
  2609. return false;
  2610. if (false !== $brace && $brace < 4)
  2611. return false;
  2612. }
  2613. $token = $data[0];
  2614. switch ($token) {
  2615. case 's' :
  2616. if ($strict) {
  2617. if ('"' !== substr($data, -2, 1)) {
  2618. return false;
  2619. }
  2620. } elseif (false === strpos($data, '"')) {
  2621. return false;
  2622. }
  2623. case 'a' :
  2624. return (bool)preg_match("/^{$token}:[0-9]+:/s", $data);
  2625. case 'O' :
  2626. return false;
  2627. case 'b' :
  2628. case 'i' :
  2629. case 'd' :
  2630. $end = $strict ? '$' : '';
  2631. return (bool)preg_match("/^{$token}:[0-9.E-]+;$end/", $data);
  2632. }
  2633. return false;
  2634. }
  2635. }
  2636. if (!function_exists('ver_compare')) {
  2637. /**
  2638. * 为了兼容微擎使用此方法
  2639. * @param $version1
  2640. * @param $version2
  2641. * @return mixed
  2642. */
  2643. function ver_compare($version1, $version2)
  2644. {
  2645. $version1 = str_replace('.', '', $version1);
  2646. $version2 = str_replace('.', '', $version2);
  2647. $oldLength = istrlen($version1);
  2648. $newLength = istrlen($version2);
  2649. if (is_numeric($version1) && is_numeric($version2)) {
  2650. if ($oldLength > $newLength) {
  2651. $version2 .= str_repeat('0', $oldLength - $newLength);
  2652. }
  2653. if ($newLength > $oldLength) {
  2654. $version1 .= str_repeat('0', $newLength - $oldLength);
  2655. }
  2656. $version1 = intval($version1);
  2657. $version2 = intval($version2);
  2658. }
  2659. return version_compare($version1, $version2);
  2660. }
  2661. }
  2662. if (!function_exists('istrlen')) {
  2663. /**
  2664. * 为了兼容微擎使用此方法
  2665. * @param $string
  2666. * @param string $charset
  2667. * @return int
  2668. */
  2669. function istrlen($string, $charset = '')
  2670. {
  2671. if (!$charset) {
  2672. $charset = \YunShop::app()['charset'];
  2673. }
  2674. if (strtolower($charset) == 'gbk') {
  2675. $charset = 'gbk';
  2676. } else {
  2677. $charset = 'utf8';
  2678. }
  2679. if (function_exists('mb_strlen') && extension_loaded('mbstring')) {
  2680. return mb_strlen($string, $charset);
  2681. } else {
  2682. $n = $noc = 0;
  2683. $strlen = strlen($string);
  2684. if ($charset == 'utf8') {
  2685. while ($n < $strlen) {
  2686. $t = ord($string[$n]);
  2687. if ($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
  2688. $n++;
  2689. $noc++;
  2690. } elseif (194 <= $t && $t <= 223) {
  2691. $n += 2;
  2692. $noc++;
  2693. } elseif (224 <= $t && $t <= 239) {
  2694. $n += 3;
  2695. $noc++;
  2696. } elseif (240 <= $t && $t <= 247) {
  2697. $n += 4;
  2698. $noc++;
  2699. } elseif (248 <= $t && $t <= 251) {
  2700. $n += 5;
  2701. $noc++;
  2702. } elseif ($t == 252 || $t == 253) {
  2703. $n += 6;
  2704. $noc++;
  2705. } else {
  2706. $n++;
  2707. }
  2708. }
  2709. } else {
  2710. while ($n < $strlen) {
  2711. $t = ord($string[$n]);
  2712. if ($t > 127) {
  2713. $n += 2;
  2714. $noc++;
  2715. } else {
  2716. $n++;
  2717. $noc++;
  2718. }
  2719. }
  2720. }
  2721. return $noc;
  2722. }
  2723. }
  2724. }
  2725. if (!function_exists('mb_strlen')) {
  2726. function mb_strlen($string, $charset = '') {
  2727. return istrlen($string, $charset);
  2728. }
  2729. }
  2730. if (!function_exists('tpl_form_field_daterange')) {
  2731. /**
  2732. * 为了兼容微擎使用此方法
  2733. * @param $name
  2734. * @param array $value
  2735. * @param bool $time
  2736. * @return string
  2737. */
  2738. function tpl_form_field_daterange($name, $value = array(), $time = false) {
  2739. $s = '';
  2740. if (empty($time) && !defined('TPL_INIT_DATERANGE_DATE')) {
  2741. $s = '
  2742. <script type="text/javascript">
  2743. require(["daterangepicker"], function(){
  2744. $(function(){
  2745. $(".daterange.daterange-date").each(function(){
  2746. var elm = this;
  2747. $(this).daterangepicker({
  2748. startDate: $(elm).prev().prev().val(),
  2749. endDate: $(elm).prev().val(),
  2750. format: "YYYY-MM-DD"
  2751. }, function(start, end){
  2752. $(elm).find(".date-title").html(start.toDateStr() + " 至 " + end.toDateStr());
  2753. $(elm).prev().prev().val(start.toDateStr());
  2754. $(elm).prev().val(end.toDateStr());
  2755. });
  2756. });
  2757. });
  2758. });
  2759. </script>
  2760. ';
  2761. define('TPL_INIT_DATERANGE_DATE', true);
  2762. }
  2763. if (!empty($time) && !defined('TPL_INIT_DATERANGE_TIME')) {
  2764. $s = '
  2765. <script type="text/javascript">
  2766. require(["daterangepicker"], function(){
  2767. $(function(){
  2768. $(".daterange.daterange-time").each(function(){
  2769. var elm = this;
  2770. $(this).daterangepicker({
  2771. startDate: $(elm).prev().prev().val(),
  2772. endDate: $(elm).prev().val(),
  2773. format: "YYYY-MM-DD HH:mm",
  2774. timePicker: true,
  2775. timePicker12Hour : false,
  2776. timePickerIncrement: 1,
  2777. minuteStep: 1
  2778. }, function(start, end){
  2779. $(elm).find(".date-title").html(start.toDateTimeStr() + " 至 " + end.toDateTimeStr());
  2780. $(elm).prev().prev().val(start.toDateTimeStr());
  2781. $(elm).prev().val(end.toDateTimeStr());
  2782. });
  2783. });
  2784. });
  2785. });
  2786. </script>
  2787. ';
  2788. define('TPL_INIT_DATERANGE_TIME', true);
  2789. }
  2790. if ($value['starttime'] !== false && $value['start'] !== false) {
  2791. if($value['start']) {
  2792. $value['starttime'] = empty($time) ? date('Y-m-d',strtotime($value['start'])) : date('Y-m-d H:i',strtotime($value['start']));
  2793. }
  2794. $value['starttime'] = empty($value['starttime']) ? (empty($time) ? date('Y-m-d') : date('Y-m-d H:i') ): $value['starttime'];
  2795. } else {
  2796. $value['starttime'] = '请选择';
  2797. }
  2798. if ($value['endtime'] !== false && $value['end'] !== false) {
  2799. if($value['end']) {
  2800. $value['endtime'] = empty($time) ? date('Y-m-d',strtotime($value['end'])) : date('Y-m-d H:i',strtotime($value['end']));
  2801. }
  2802. $value['endtime'] = empty($value['endtime']) ? $value['starttime'] : $value['endtime'];
  2803. } else {
  2804. $value['endtime'] = '请选择';
  2805. }
  2806. $s .= '
  2807. <input name="'.$name . '[start]'.'" type="hidden" value="'. $value['starttime'].'" />
  2808. <input name="'.$name . '[end]'.'" type="hidden" value="'. $value['endtime'].'" />
  2809. <button class="btn btn-default daterange '.(!empty($time) ? 'daterange-time' : 'daterange-date').'" type="button"><span class="date-title">'.$value['starttime'].' 至 '.$value['endtime'].'</span> <i class="fa fa-calendar"></i></button>
  2810. ';
  2811. return $s;
  2812. }
  2813. }
  2814. if (!function_exists('tpl_ueditor')) {
  2815. /**
  2816. * 为了兼容微擎使用此方法
  2817. * @param $id
  2818. * @param string $value
  2819. * @param array $options
  2820. * @return string
  2821. */
  2822. function tpl_ueditor($id, $value = '', $options = array())
  2823. {
  2824. $s = '';
  2825. $options['height'] = empty($options['height']) ? 200 : $options['height'];
  2826. $options['allow_upload_video'] = isset($options['allow_upload_video']) ? $options['allow_upload_video'] : true;
  2827. $param = uploadParam();
  2828. $s .= !empty($id) ? "<textarea id=\"{$id}\" name=\"{$id}\" type=\"text/plain\" style=\"height:{$options['height']}px;\">{$value}</textarea>" : '';
  2829. $s .= "
  2830. <script type=\"text/javascript\">
  2831. require(['".$param['util']."'], function(util){
  2832. util.editor('" . ($id ? $id : "") . "', {
  2833. height : {$options['height']},
  2834. dest_dir : '" . ($options['dest_dir'] ? $options['dest_dir'] : "") . "',
  2835. image_limit : " . (intval($param['global']['image_limit']) * 1024) . ",
  2836. allow_upload_video : " . ($options['allow_upload_video'] ? 'true' : 'false') . ",
  2837. audio_limit : " . (intval($param['global']['audio_limit']) * 1024) . ",
  2838. callback : ''
  2839. });
  2840. });
  2841. </script>";
  2842. return $s;
  2843. }
  2844. }
  2845. if (!function_exists('image_put_path')) {
  2846. function image_put_path()
  2847. {
  2848. if (config('app.framework') == 'platform') {
  2849. return base_path('static/upload/');
  2850. }
  2851. return IA_ROOT . '/attachment/';
  2852. }
  2853. }
  2854. if (!function_exists('iserializer')) {
  2855. /**
  2856. * 为了兼容微擎使用此方法
  2857. * @param $value
  2858. * @return string
  2859. */
  2860. function iserializer($value) {
  2861. return serialize($value);
  2862. }
  2863. }
  2864. if (!function_exists('tpl_form_field_date')) {
  2865. /**
  2866. * 为了兼容微擎使用此方法
  2867. * @param $name
  2868. * @param string $value
  2869. * @param bool $withtime
  2870. * @return string
  2871. */
  2872. function tpl_form_field_date($name, $value = '', $withtime = false)
  2873. {
  2874. return _tpl_form_field_date($name, $value, $withtime);
  2875. }
  2876. }
  2877. if (!function_exists('_tpl_form_field_date')) {
  2878. /**
  2879. * 为了兼容微擎使用此方法
  2880. * @param $name
  2881. * @param string $value
  2882. * @param bool $withtime
  2883. * @return string
  2884. */
  2885. function _tpl_form_field_date($name, $value = '', $withtime = false)
  2886. {
  2887. $s = '';
  2888. $withtime = !$withtime ? false : true;
  2889. if ($value) {
  2890. $value = strexists($value, '-') ? strtotime($value) : $value;
  2891. } else {
  2892. $value = TIMESTAMP;
  2893. }
  2894. $value = ($withtime ? date('Y-m-d H:i:s', $value) : date('Y-m-d', $value));
  2895. $s .= '<input type="text" name="' . $name . '" value="' . $value . '" placeholder="请选择日期时间" readonly="readonly" class="datetimepicker form-control" style="padding-left:12px;" />';
  2896. $s .= '
  2897. <script type="text/javascript">
  2898. require(["datetimepicker"], function(){
  2899. var option = {
  2900. lang : "zh",
  2901. step : 5,
  2902. timepicker : ' . (!empty($withtime) ? "true" : "false") . ',
  2903. closeOnDateSelect : true,
  2904. format : "Y-m-d' . (!empty($withtime) ? ' H:i"' : '"') . '
  2905. };
  2906. $(".datetimepicker[name = \'' . $name . '\']").datetimepicker(option);
  2907. });
  2908. </script>';
  2909. return $s;
  2910. }
  2911. }
  2912. if (!function_exists('user_register')) {
  2913. /**
  2914. * 添加用户(为了兼容微擎使用此方法)
  2915. * @param $user
  2916. * @return mixed
  2917. */
  2918. function user_register ($user, $default = null)
  2919. {
  2920. $data = [
  2921. 'username' => trim($user['username']),
  2922. 'password' => bcrypt($user['password']),
  2923. 'salt' => randNum(8),
  2924. 'lastvisit' => time(),
  2925. 'lastip' => Utils::getClientIp(),
  2926. 'joinip' => Utils::getClientIp(),
  2927. 'status' => 2,
  2928. 'remark' => '',
  2929. 'owner_uid' => 0
  2930. ];
  2931. $users_model = new WeiQingUsers;
  2932. $users_model->fill($data);
  2933. $users_model->save();
  2934. $user_uid = $users_model['uid'];
  2935. return $user_uid;
  2936. }
  2937. }
  2938. if (!function_exists('user_hash')) {
  2939. /**
  2940. * 密码加密(为了兼容微擎使用此方法)
  2941. * @param $new_pwd
  2942. * @param $salt
  2943. * @return string
  2944. */
  2945. function user_hash($new_pwd, $salt)
  2946. {
  2947. if (config('app.framework') == 'platform') {
  2948. $password = bcrypt($new_pwd);
  2949. } else {
  2950. global $_W;
  2951. $password = sha1("{$new_pwd}-{$salt}-{$_W['config']['setting']['authkey']}");
  2952. }
  2953. return $password;
  2954. }
  2955. }
  2956. if (!function_exists('uploadUrl')) {
  2957. /**
  2958. * 上传 相关组件 使用的url
  2959. * @return mixed
  2960. */
  2961. function uploadUrl($type = 'default')
  2962. {
  2963. if (config('app.framework') == 'platform') {
  2964. $url['upload_url'] = '/admin/shop?route=upload.upload.jsUpload&upload_type=';
  2965. $url['image_url'] = '/admin/shop?route=upload.upload.jsImage';
  2966. $url['fetch_url'] = '/admin/shop?route=upload.upload.fetch';
  2967. $url['delet_url'] = '/admin/shop?route=upload.upload.delete';
  2968. $url['video_url'] = '/admin/system/upload/video?local=local&type=video&pagesize=5';
  2969. } else {
  2970. $url['upload_url'] = './index.php?c=site&a=entry&m=yun_shop&do=shop&route=upload.upload.jsUpload&upload_type=';
  2971. if ($type == 'new') {
  2972. $image_url = str_replace('/web','.',yzWebUrl('upload.uploadImage.getImage'));
  2973. $url['image_url'] = $image_url;
  2974. } elseif($type == 'default') {
  2975. $url['image_url'] = './index.php?c=site&a=entry&m=yun_shop&do=shop&route=upload.upload.jsImage';
  2976. }
  2977. $url['fetch_url'] = './index.php?c=site&a=entry&m=yun_shop&do=shop&route=upload.upload.fetch';
  2978. $url['delet_url'] = './index.php?c=site&a=entry&m=yun_shop&do=shop&route=upload.upload.delete';
  2979. $url['video_url'] = './index.php?c=site&a=entry&m=yun_shop&do=shop&route=upload.upload.getVideo&local=local&type=video&pagesize=5';
  2980. }
  2981. return $url;
  2982. }
  2983. }
  2984. if (!function_exists('uploadParam')) {
  2985. /**
  2986. * ImageHelper 上传需要的变量
  2987. * @return mixed
  2988. */
  2989. function uploadParam()
  2990. {
  2991. $util = 'util';
  2992. $u_url = 'static/resource/js/app/';
  2993. if (config('app.framework') == 'platform') {
  2994. $global = SystemSetting::settingLoad('global', 'system_global');
  2995. $result['fileSizeLimitImage'] = intval($global['image_limit']) * 1024;
  2996. $result['fileSizeLimitAudio'] = intval($global['audio_limit']) * 1024;
  2997. $util = 'utils';
  2998. $util_url = '/' . $u_url . $util;
  2999. } else {
  3000. $util_url = '/addons/yun_shop/' . $u_url . $util;
  3001. $global = \YunShop::app()->setting['upload'];
  3002. $result['fileSizeLimitImage'] = intval($global['image']['limit']) * 1024;
  3003. $result['fileSizeLimitAudio'] = intval($global['audio']['limit']) * 1024;
  3004. }
  3005. $result['util'] = $util;
  3006. $result['global'] = $global;
  3007. $result['util_url'] = $util_url;
  3008. return $result;
  3009. }
  3010. }
  3011. if (!function_exists('resource_absolute')) {
  3012. function resource_absolute($file)
  3013. {
  3014. if (config('app.framework') == 'platform') {
  3015. return '/' . $file;
  3016. }
  3017. return '/addons/yun_shop/' . $file;
  3018. }
  3019. }
  3020. if (!function_exists('upload_image_local')) {
  3021. function upload_image_local($file)
  3022. {
  3023. if (config('app.framework') == 'platform') {
  3024. if (strexists($file, 'newimage')) {
  3025. $file = ImageHelper::getImageUrl('static/upload/' . substr($file,strripos($file,"newimage")));
  3026. }else {
  3027. $file = ImageHelper::getImageUrl('static/upload/' . substr($file,strripos($file,"image")));
  3028. }
  3029. } else {
  3030. $file = ImageHelper::getImageUrl('attachment/' . substr($file,strripos($file,"image")));
  3031. }
  3032. return $file;
  3033. }
  3034. }
  3035. if (!function_exists('change_to_local_url')) {
  3036. function change_to_local_url($file)
  3037. {
  3038. if (strexists($file, 'storage')) {
  3039. $file = strstr($file, 'storage');
  3040. return request()->getSchemeAndHttpHost() . DIRECTORY_SEPARATOR . $file;
  3041. }
  3042. if (strexists($file, 'static/upload/')) {
  3043. $file = strstr($file, 'static/upload/');
  3044. return request()->getSchemeAndHttpHost() . DIRECTORY_SEPARATOR . $file;
  3045. }
  3046. if (strexists($file, 'attachment/')) {
  3047. $file = strstr($file, 'attachment/');
  3048. return request()->getSchemeAndHttpHost() . DIRECTORY_SEPARATOR . $file;
  3049. }
  3050. $disks = config('filesystems.disks');
  3051. foreach ($disks as $key => $disk) {
  3052. if (strexists($file, $key)) {
  3053. $file = strstr($file, $key);
  3054. break;
  3055. }
  3056. }
  3057. if (config('app.framework') == 'platform') {
  3058. $file = request()->getSchemeAndHttpHost() . DIRECTORY_SEPARATOR . 'static/upload/' . $file;
  3059. } else {
  3060. $file = request()->getSchemeAndHttpHost() . DIRECTORY_SEPARATOR . 'attachment/' . $file;
  3061. }
  3062. return $file;
  3063. }
  3064. }
  3065. if (!function_exists('setSystemVersion')) {
  3066. function setSystemVersion($version, $file)
  3067. {
  3068. $str = file_get_contents(base_path('config/') . $file);
  3069. $str = preg_replace('/"[\d\.]+"/', '"'. $version . '"', $str);
  3070. file_put_contents(base_path('config/') . $file, $str);
  3071. }
  3072. }
  3073. if (!function_exists('changeUmImgPath')) {
  3074. function changeUmImgPath($str = '')
  3075. {
  3076. $details = htmlspecialchars_decode($str);
  3077. preg_match_all("/(\s+src\s?\=)\s?[\'|\"]([^\'|\"]*)/is", $details, $imgs);
  3078. $old_arr = [];
  3079. $new_arr = [];
  3080. if (isset($imgs[2])) {
  3081. foreach ($imgs[2] as $img) {
  3082. $old_arr[] = $img;
  3083. $new_arr[] = yz_tomedia($img);
  3084. }
  3085. }
  3086. $str = str_replace($old_arr, $new_arr, $details);
  3087. return $str;
  3088. }
  3089. }
  3090. //bc计算金额比例
  3091. if (!function_exists('proportionMath')) {
  3092. function proportionMath($money, $proportion)
  3093. {
  3094. return bcdiv(bcmul($money, $proportion, 2), 100, 2);
  3095. }
  3096. }
  3097. if (!function_exists('changeSpecialSymbols')) {
  3098. function changeSpecialSymbols($str = '')
  3099. {
  3100. $regex = "/\/|\~|\,|\。|\!|\?|\“|\”|\【|\】|\『|\』|\:|\;|\《|\》|\’|\‘|\ |\·|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\`|\-|\=|\\\|\|/";
  3101. return preg_replace($regex,'', $str);
  3102. }
  3103. }
  3104. if (!function_exists('verifyPasswordStrength')) {
  3105. /**
  3106. * 校验密码强度(更多用于操作员之类的密码效验)
  3107. * @param string $password
  3108. * @return bool|\Illuminate\Http\JsonResponse
  3109. */
  3110. function verifyPasswordStrength($password = '')
  3111. {
  3112. // if (preg_match('/[\x{4e00}-\x{9fa5}]/u', $password)>0) {
  3113. // return '密码不能含有中文';
  3114. // }
  3115. $is_check = 0;
  3116. if (config('app.APP_Framework', false) == 'platform') {
  3117. //独立版
  3118. $loginset = SystemSetting::settingLoad('loginset', 'system_loginset');
  3119. $is_check = $loginset['password_verify'];
  3120. }elseif(config('app.APP_Framework', false) != 'platform'){
  3121. //微擎版
  3122. if (\Illuminate\Support\Facades\Schema::hasTable('core_settings')) {
  3123. $setting = \Illuminate\Support\Facades\DB::table('core_settings')->where('key','register')->first();
  3124. if($setting){
  3125. $value = unserialize($setting['value']);
  3126. $is_check = $value['safe']?:0;
  3127. }
  3128. }
  3129. }
  3130. if ($is_check == 1) {
  3131. // if (!preg_match('/(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,30}/', $password)) {
  3132. // return '密码至少为8-16个字符,至少1个大写字母,1个小写字母和一个数字,其他可以任意字符';
  3133. // }
  3134. if (!preg_match('/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[.!~@#$%^&*?\(\)+_-]).{8,18}$/', $password)) {
  3135. return '密码长度至少为8位,要求包括数字,大小写字母和特殊字符';
  3136. }
  3137. }
  3138. return true;
  3139. }
  3140. }
  3141. if (!function_exists('getMiniAccessToken')) {
  3142. /**
  3143. * 获取小程序全局access_token
  3144. * @param false $force_refresh 强制刷新
  3145. * @return false|mixed
  3146. * @throws \GuzzleHttp\Exception\GuzzleException
  3147. */
  3148. function getMiniAccessToken($force_refresh = false)
  3149. {
  3150. $set = \Setting::get('plugin.min_app');
  3151. $cache_key = 'mini_token:'.$set['key'];
  3152. $token = Redis::get($cache_key);
  3153. if ($force_refresh || empty($token)) {
  3154. $get_token_url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s';
  3155. $get_token_url = sprintf($get_token_url, $set['key'],$set['secret']);
  3156. $res = (new \GuzzleHttp\Client)->request('GET', $get_token_url);
  3157. $token = json_decode($res->getBody()->getContents(), JSON_FORCE_OBJECT);
  3158. if (isset($token['errcode'])) {
  3159. \Log::debug('------生成小程序二维码获取token出错------', $token);
  3160. return false;
  3161. }
  3162. Redis::setex($cache_key,$token['expires_in']-1500,$token['access_token']);
  3163. return $token['access_token'];
  3164. }
  3165. return $token;
  3166. }
  3167. }
  3168. if (!function_exists('miniVersionCompare')) {
  3169. /**
  3170. * 小程序版本比较,小于传入版本返回false,其他返回true
  3171. * @param string $version
  3172. * @return bool
  3173. */
  3174. function miniVersionCompare($version = '')
  3175. {
  3176. //不是小程序直接返回
  3177. if (request()->type != 2) {
  3178. return true;
  3179. }
  3180. $mini_version = request()->mini_version;
  3181. $mini_version = str_replace('v','',$mini_version);
  3182. $mini_version = explode('.',$mini_version);
  3183. $version = explode('.',$version);
  3184. //版本验证
  3185. foreach ($mini_version as $key=>$value) {
  3186. if ($mini_version[$key] < $version[$key]) {
  3187. return false;
  3188. }
  3189. }
  3190. return true;
  3191. }
  3192. }
  3193. if (!function_exists('versionCompare')) {
  3194. /**
  3195. * H5版本比较,小于传入版本返回false,其他返回true
  3196. * @param string $version
  3197. * @return bool
  3198. */
  3199. function versionCompare($version = '')
  3200. {
  3201. if (request()->type == 2) {
  3202. return true;
  3203. }
  3204. $front_version = request()->version;
  3205. $front_version = str_replace('v','',$front_version);
  3206. $front_version = explode('.',$front_version);
  3207. $version = explode('.',$version);
  3208. //版本验证
  3209. foreach ($front_version as $key=>$value) {
  3210. if ($front_version[$key] < $version[$key]) {
  3211. return false;
  3212. }
  3213. }
  3214. return true;
  3215. }
  3216. }
  3217. if (!function_exists('substrCut')) {
  3218. /**
  3219. * 只保留字符串首尾字符,隐藏中间用*代替(两个字符时只显示第一个)
  3220. * @param string $user_name 姓名
  3221. * @return string 格式化后的姓名
  3222. */
  3223. function substrCut($user_name) {
  3224. $strlen = mb_strlen($user_name, 'utf-8');
  3225. $firstStr = mb_substr($user_name, 0, 1, 'utf-8');
  3226. $lastStr = mb_substr($user_name, -1, 1, 'utf-8');
  3227. if ($strlen < 2) {
  3228. return $user_name;
  3229. } else {
  3230. return $strlen == 2 ? $firstStr . str_repeat('*', mb_strlen($user_name, 'utf-8') - 1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr;
  3231. }
  3232. }
  3233. }
  3234. if (!function_exists('validatePassword')) {
  3235. /**
  3236. * 密码强度效验统一规则(更多用于平台的密码强度效验)
  3237. * @param $password
  3238. * @return string
  3239. */
  3240. function validatePassword($password) {
  3241. if (!preg_match('/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[.!~@#$%^&*?\(\)+_-]).{8,18}$/', $password)) {
  3242. return '密码长度至少为8位,要求包括数字,大小写字母和特殊字符';
  3243. }
  3244. return true;
  3245. }
  3246. /*
  3247. if (!function_exists("yz_tpl_ueditor")) {
  3248. function yz_tpl_ueditor($id, $value = '', $options = array()){
  3249. $upload_url1 = yzWebFullUrl('upload.uploadV2.upload-vue');
  3250. if (config('app.framework') == 'platform') {
  3251. $file_dir = '';
  3252. } else {
  3253. $file_dir = '../addons/yun_shop';
  3254. }
  3255. $s = '';
  3256. $s .= '<script src="'.$file_dir.'/static/yunshop/tinymce4.7.5/tinymce.min.js"></script>
  3257. <script>
  3258. tinymce.init({
  3259. selector: \'#textarea\',
  3260. fontsize_formats: "8px 10px 12px 14px 18px 24px 36px",
  3261. plugins: [\'advlist anchor autolink autoresize code codesample colorpicker contextmenu directionality emoticons fullscreen hr image imagetools insertdatetime link charmap lists media nonbreaking noneditable pagebreak preview print save searchreplace spellchecker tabfocus table template textcolor textpattern visualblocks visualchars wordcount powerpaste bdmap \'],
  3262. toolbar: [\'forecolor backcolor searchreplace bold italic underline strikethrough fontsizeselect\',\'alignleft aligncenter alignright outdent indent ltr rtl blockquote undo redo removeformat subscript superscript code codesample\', \'hr bullist numlist link image charmap preview anchor pagebreak print insertdatetime media table emoticons fullscreen bdmap \'],
  3263. language:\'zh_CN\',
  3264. height: "500px",
  3265. file_picker_callback: function(callback, value, meta) {
  3266. //文件分类
  3267. var filetype = \'.pdf, .jpg, .jpeg, .png, .gif, .mp3, .mp4\';
  3268. //后端接收上传文件的地址
  3269. var upurl = \''.$upload_url1.'\' +\'&upload_type=video\';
  3270. //为不同插件指定文件类型及后端地址
  3271. switch (meta.filetype) {
  3272. case \'image\':
  3273. upurl = \''.$upload_url1.'\' +\'&upload_type=image\';
  3274. filetype = \'.jpg, .jpeg, .png, .gif\';
  3275. break;
  3276. case \'media\':
  3277. filetype = \'.mp3, .mp4\';
  3278. break;
  3279. case \'file\':
  3280. default:
  3281. }
  3282. //模拟出一个input用于添加本地文件
  3283. var input = document.createElement(\'input\');
  3284. input.setAttribute(\'type\', \'file\');
  3285. input.setAttribute(\'accept\', filetype);
  3286. input.click();
  3287. input.onchange = function(F) {
  3288. var file = this.files[0];
  3289. // const loading = component.$loading({
  3290. // lock: true,
  3291. // text: \'正在上传\',
  3292. // spinner: \'el-icon-loading\',
  3293. // background: \'rgba(0, 0, 0, 0.7)\'
  3294. // });
  3295. var xhr, formData;
  3296. // console.log(file, file.name);
  3297. xhr = new XMLHttpRequest();
  3298. xhr.withCredentials = false;
  3299. xhr.open(\'POST\', upurl);
  3300. xhr.onload = function() {
  3301. var json;
  3302. if (xhr.status != 200) {
  3303. loading.close();
  3304. // failure(\'HTTP Error: \' + xhr.status);
  3305. return;
  3306. }
  3307. json = JSON.parse(xhr.responseText);
  3308. if (!json || typeof json.location != \'string\') {
  3309. // failure(\'Invalid JSON: \' + xhr.responseText);
  3310. return;
  3311. }
  3312. // loading.close();
  3313. callback(encodeURI(json.location), {
  3314. title: file.name
  3315. });
  3316. };
  3317. formData = new FormData();
  3318. formData.append(\'file\', file, file.name);
  3319. xhr.send(formData);
  3320. };
  3321. },
  3322. media_url_resolver: (data, resolve)=> {
  3323. try {
  3324. let videoUri = encodeURI(data.url);
  3325. if(data.url.indexOf(\'.mp4\')>-1) {
  3326. // 判断是否mp4 否则用ifarme嵌套
  3327. let embedHtml = `<p>
  3328. <video src=${ data.url } width="100%" height="auto" style="max-width: 100%;" allowfullscreen="false" controls="controls" controlslist="nodownload">
  3329. </video>
  3330. </p>`;
  3331. resolve({ html: embedHtml });
  3332. }else {
  3333. let embedHtml = `<p>
  3334. <iframe frameborder="0" src=${ data.url } width="100%" height="100%" style="max-width: 100%;">
  3335. </iframe>
  3336. </p>`;
  3337. resolve({ html: embedHtml });
  3338. }
  3339. } catch (e) {
  3340. resolve({ html: "" });
  3341. }
  3342. },
  3343. });
  3344. </script>
  3345. ';
  3346. $s .= '
  3347. <form method="post">
  3348. <textarea id="textarea" name="'.$id.'" style="height:500px;">'.$value.'</textarea>
  3349. </form>';
  3350. return $s;
  3351. }
  3352. }
  3353. */
  3354. }
  3355. if (!function_exists('passwordVerifyStatus')) {
  3356. /**
  3357. * @return bool|string
  3358. */
  3359. function passwordVerifyStatus()
  3360. {
  3361. $is_check = 0;
  3362. if (config('app.APP_Framework', false) == 'platform') {
  3363. //独立版
  3364. $loginset = SystemSetting::settingLoad('loginset', 'system_loginset');
  3365. $is_check = $loginset['password_verify'];
  3366. }elseif(config('app.APP_Framework', false) != 'platform'){
  3367. //微擎版
  3368. if (\Illuminate\Support\Facades\Schema::hasTable('core_settings')) {
  3369. $setting = \Illuminate\Support\Facades\DB::table('core_settings')->where('key','register')->first();
  3370. if($setting){
  3371. $value = unserialize($setting['value']);
  3372. $is_check = $value['safe']?:0;
  3373. }
  3374. }
  3375. }
  3376. if ($is_check == 1) {
  3377. return true;//开启了密码强度效验
  3378. }
  3379. return false;
  3380. }
  3381. }