common.fun.php 140 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289
  1. <?php
  2. //decode by qq784939922
  3. function checkhtml($html)
  4. {
  5. global $charset;
  6. preg_match_all('/\\<([^\\<]+)\\>/is', $html, $ms);
  7. $searchs[] = '<';
  8. $replaces[] = '&lt;';
  9. $searchs[] = '>';
  10. $replaces[] = '&gt;';
  11. if ($ms[1]) {
  12. $allowtags = 'img|a|font|div|table|tbody|caption|tr|td|th|br|p|b|strong|i|u|em|span|ol|ul|li|blockquote|object|param|embed';
  13. $ms[1] = array_unique($ms[1]);
  14. foreach ($ms[1] as $value) {
  15. $searchs[] = '&lt;' . $value . '&gt;';
  16. $value = str_replace('&', '_uch_tmp_str_', $value);
  17. $value = mhtmlspecialchars($value);
  18. $value = str_replace('_uch_tmp_str_', '&', $value);
  19. $value = str_replace(array('\\', '/*'), array('.', '/.'), $value);
  20. $skipkeys = 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', 'javascript', 'script', 'eval', 'behaviour', 'expression', 'style', 'class');
  21. $skipstr = implode('|', $skipkeys);
  22. $value = preg_replace(array('/(' . $skipstr . ')/i'), '.', $value);
  23. if (!preg_match('/^[\\/|\\s]?(' . $allowtags . ')(\\s+|$)/is', $value)) {
  24. $value = '';
  25. }
  26. $replaces[] = empty($value) ? '' : '<' . str_replace('&quot;', '"', $value) . '>';
  27. }
  28. }
  29. $html = trim(str_replace($searchs, $replaces, $html));
  30. return $html;
  31. }
  32. function mhtmlspecialchars($string, $flags = NULL)
  33. {
  34. global $charset;
  35. if (is_array($string)) {
  36. foreach ($string as $key => $val) {
  37. $string[$key] = mhtmlspecialchars($val, $flags);
  38. }
  39. } else {
  40. if ($flags === NULL) {
  41. $string = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $string);
  42. if (strpos($string, '&amp;#') !== false) {
  43. $string = preg_replace('/&amp;((#(\\d{3,5}|x[a-fA-F0-9]{4}));)/', '&\\1', $string);
  44. }
  45. } else {
  46. if (PHP_VERSION < '5.4.0') {
  47. $string = htmlspecialchars($string, $flags);
  48. } else {
  49. if ($charset == 'utf-8') {
  50. $charset = 'UTF-8';
  51. } else {
  52. $charset = 'ISO-8859-1';
  53. }
  54. $string = htmlspecialchars($string, $flags, $charset);
  55. }
  56. }
  57. }
  58. return $string;
  59. }
  60. function get_shop_tpl($opt = '', $s_uid = '')
  61. {
  62. global $db;
  63. global $db_mymps;
  64. if ($s_uid) {
  65. $member = get_member_group('', $s_uid);
  66. $option = $member['allow_tpl'];
  67. } else {
  68. $option = $db->getAll('SELECT * FROM `' . $db_mymps . 'member_tpl`');
  69. }
  70. foreach ($option as $key => $v) {
  71. $mymps .= '<option value=' . $v[tpl_path];
  72. if (is_array($opt)) {
  73. $mymps .= in_array($v[tpl_path], $opt) ? ' style = "background-color:#6EB00C;color:white" selected>' : '>';
  74. } else {
  75. $mymps .= $opt == $v[tpl_path] ? ' style = "background-color:#6EB00C;color:white" selected>' : '>';
  76. }
  77. $mymps .= $v[tpl_name] . '</option>';
  78. }
  79. return $mymps;
  80. }
  81. function filter_str($msg)
  82. {
  83. $msg = str_replace('"', '&quot;', $msg);
  84. $msg = str_replace('\'', '&#39;', $msg);
  85. $msg = str_replace('<', '&lt;', $msg);
  86. $msg = str_replace('>', '&gt;', $msg);
  87. $msg = str_replace("\t", ' &nbsp; &nbsp;', $msg);
  88. $msg = str_replace(' ', ' &nbsp; ', $msg);
  89. return $msg;
  90. }
  91. function get_member_docu($num = 10, $userid = '', $if_check = 1, $typeid = 0)
  92. {
  93. global $db;
  94. global $db_mymps;
  95. $where = 'WHERE 1';
  96. $where .= $if_check == 1 ? ' AND a.if_check = \'1\'' : '';
  97. $where .= $typeid ? ' AND a.typeid = \'' . $typeid . '\'' : '';
  98. $where .= $userid ? ' AND a.userid = \'' . $userid . '\'' : '';
  99. $num = $num ? 'LIMIT 0,' . $num : '';
  100. $query = $db->query('SELECT a.*,b.id AS uid,b.tname FROM `' . $db_mymps . 'member_docu` AS a LEFT JOIN `' . $db_mymps . 'member` AS b ON a.userid = b.userid ' . $where . ' ORDER BY a.id DESC ' . $num);
  101. while ($row = $db->fetchRow($query)) {
  102. $arr['id'] = $row['id'];
  103. $arr['uid'] = $row['uid'];
  104. $arr['userid'] = $row['userid'];
  105. $arr['tname'] = $row['tname'];
  106. $arr['typeid'] = $row['typeid'];
  107. $arr['title'] = $row['title'];
  108. $arr['pubtime'] = $row['pubtime'];
  109. $arr['imgpath'] = $row['imgpath'];
  110. $arr['hit'] = $row['hit'];
  111. $arr['pre_imgpath'] = $row['pre_imgpath'];
  112. $arr['tname_uri'] = Rewrite('store', array('uid' => $row['uid'], 'part' => 'index'));
  113. $arr['uri'] = Rewrite('store', array('uid' => $row['uid'], 'id' => $row['id'], 'part' => 'document'));
  114. $arr['uri_m'] = mRewrite('store', array('uid' => $row['uid'], 'id' => $row['id'], 'part' => 'document'));
  115. $docu[] = $arr;
  116. $arr = NULL;
  117. }
  118. return $docu;
  119. }
  120. function msetcookie($var, $val, $life = 0)
  121. {
  122. global $cookiepre;
  123. global $cookiedomain;
  124. global $cookiepath;
  125. global $timestamp;
  126. $cookie_pre = $cookiepre . '_';
  127. $cookie_path = $cookiepath ? $cookiepath : '/';
  128. $life = $life ? $life : 3600;
  129. $life = $timestamp + $life;
  130. setcookie($cookie_pre . $var, $val, $life, $cookie_path, $cookiedomain);
  131. }
  132. function mgetcookie($var)
  133. {
  134. global $cookiepre;
  135. $cookie_pre = $cookiepre . '_';
  136. $tvar = $cookie_pre . $var;
  137. return $_COOKIE[$tvar];
  138. }
  139. function is_email($email)
  140. {
  141. return 6 < strlen($email) && preg_match('/^[\\w\\-\\.]+@[\\w\\-\\.]+(\\.\\w+)+$/', $email);
  142. }
  143. function html2js($str)
  144. {
  145. $str = str_replace('\\', '\\\\', $str);
  146. $str = str_replace('\'', '\\\'', $str);
  147. $str = str_replace('"', '\\"', $str);
  148. $str = str_replace('\\t', '', $str);
  149. $str = explode("\r\n", $str);
  150. for ($i = 0; $i < count($str); $i++) {
  151. $re .= 'document.writeln("' . $str[$i] . '");' . "\r\n";
  152. }
  153. return $re;
  154. }
  155. function textarea_post_change($mymps_string)
  156. {
  157. return nl2br(str_replace(' ', '&nbsp;', mhtmlspecialchars(trim($mymps_string))));
  158. }
  159. function de_textarea_post_change($mymps_string)
  160. {
  161. return str_replace('<br />', ' ', str_replace('&nbsp;', ' ', trim($mymps_string)));
  162. }
  163. function random($length = 5, $strtolower = 1)
  164. {
  165. $hash = '';
  166. $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
  167. $max = strlen($chars) - 1;
  168. mt_srand((double) microtime() * 1000000);
  169. for ($i = 0; $i < $length; $i++) {
  170. $hash .= $chars[mt_rand(0, $max)];
  171. }
  172. if ($strtolower == 1) {
  173. $hash = strtolower($hash);
  174. }
  175. return $hash;
  176. }
  177. function FileExt($filename)
  178. {
  179. if ($filename) {
  180. $temp_arr = explode('.', $filename);
  181. $file_ext = array_pop($temp_arr);
  182. $file_ext = trim($file_ext);
  183. $file_ext = strtolower($file_ext);
  184. } else {
  185. $file_ext = NULL;
  186. }
  187. return $file_ext;
  188. }
  189. function createfile($file, $str)
  190. {
  191. if (is_file($file)) {
  192. @unlink($file);
  193. }
  194. $fp = fopen($file, 'w');
  195. if (!is_writable($file)) {
  196. return false;
  197. }
  198. if (!fwrite($fp, $str)) {
  199. return false;
  200. }
  201. fclose($fp);
  202. return $file;
  203. }
  204. function createdir($path)
  205. {
  206. if (!file_exists($path)) {
  207. createdir(dirname($path));
  208. mkdir($path, 511);
  209. return true;
  210. } else {
  211. if (file_exists($path)) {
  212. return true;
  213. } else {
  214. return false;
  215. }
  216. }
  217. }
  218. function DelDir($dirName)
  219. {
  220. if (!is_dir($dirName)) {
  221. return false;
  222. }
  223. $handle = @opendir($dirName);
  224. while (($file = @readdir($handle)) !== false) {
  225. if ($file != '.' && $file != '..') {
  226. $dir = $dirName . '/' . $file;
  227. is_dir($dir) ? DelDir($dir) : @unlink($dir);
  228. }
  229. }
  230. closedir($handle);
  231. return rmdir($dirName);
  232. }
  233. function die_msg($msg)
  234. {
  235. return '<p style="font-family: Verdana, Tahoma; font-size: 11px;"><b>Mymps info:</b>' . $msg . '</p>';
  236. }
  237. function uc_call($func, $params = NULL)
  238. {
  239. restore_error_handler();
  240. if (!function_exists($func)) {
  241. include_once MYMPS_ROOT . '/uc_client/client.php';
  242. }
  243. $res = call_user_func_array($func, $params);
  244. return $res;
  245. }
  246. function get_editor($editor_name, $type, $value = '', $width = '100%', $height = '400px', $BasePath = '../include/kindeditor')
  247. {
  248. $html = '';
  249. $html .= '<script charset="utf-8" src="' . $BasePath . '/kindeditor-min.js"></script><script charset="utf-8" src="' . $BasePath . '/lang/zh_CN.js"></script>';
  250. switch ($type) {
  251. case 'Member':
  252. $html .= '<script>' . "\r\n\t\t\t" . 'var editor;' . "\r\n\t\t\t" . 'KindEditor.ready(function(K) {' . "\r\n\t\t\t\t" . 'editor = K.create(\'textarea[name="' . $editor_name . '"]\', {' . "\r\n\t\t\t\t\t\t" . 'resizeType : 1,' . "\r\n\t\t\t\t\t\t" . 'filterMode : true,' . "\r\n\t\t\t\t\t\t" . 'afterBlur: function () { this.sync(); },' . "\r\n\t\t\t\t\t\t" . 'uploadJson : \'' . $BasePath . '/upload_user.php\' // 相对于当前页面的路径' . "\r\n\t\t\t\t" . '});' . "\r\n\t\t\t\t\r\n\t\t\t" . '});</script>';
  253. break;
  254. case 'information':
  255. $html .= '<script>' . "\r\n\t\t\t" . 'var editor;' . "\r\n\t\t\t" . 'KindEditor.ready(function(K) {' . "\r\n\t\t\t\t" . 'editor = K.create(\'textarea[name="' . $editor_name . '"]\', {' . "\r\n\t\t\t\t\t\t" . 'resizeType : 1,' . "\r\n\t\t\t\t\t\t" . 'filterMode : true,' . "\r\n\t\t\t\t\t\t" . 'afterBlur: function () { this.sync(); },' . "\r\n\t\t\t\t\t\t" . 'items : [ \'fontname\', \'fontsize\', \'|\' ,\'forecolor\',\'hilitecolor\', \'bold\',\'italic\', \'underline\', \'strikethrough\', \'removeformat\', \'clearhtml\' ]' . "\r\n\t\t\t\t" . '});' . "\r\n\t\t\t\t\r\n\t\t\t" . '});</script>';
  256. break;
  257. default:
  258. $html .= '<script>' . "\r\n\t\t\t" . 'var editor;' . "\r\n\t\t\t" . 'KindEditor.ready(function(K) {' . "\r\n\t\t\t\t" . 'editor = K.create(\'textarea[name="' . $editor_name . '"]\', {' . "\r\n\t\t\t\t\t\t" . 'resizeType : 1,' . "\r\n\t\t\t\t\t\t" . 'filterMode : true,' . "\r\n\t\t\t\t\t\t" . 'afterBlur: function () { this.sync(); },' . "\r\n\t\t\t\t\t\t" . 'uploadJson : \'' . $BasePath . '/upload_admin.php\' // 相对于当前页面的路径' . "\r\n\t\t\t\t" . '});' . "\r\n\t\t\t\t\r\n\t\t\t" . '});</script>';
  259. break;
  260. }
  261. $html .= '<textarea require="true" datatype="limit" msg="请填写信息内容描述" msgid="content" name="' . $editor_name . '" style="width:' . $width . ';height:' . $height . ';visibility:hidden;">' . $value . '</textarea>';
  262. return $html;
  263. }
  264. function mymps_chk_randcode($getcode = '')
  265. {
  266. global $timestamp;
  267. session_start();
  268. $getcode = trim(strtoupper($getcode));
  269. $sessioncode = $_SESSION['chkcode']['code'];
  270. if ($timestamp < $_SESSION['chkcode']['time'] && $sessioncode == $getcode) {
  271. return true;
  272. } else {
  273. return false;
  274. }
  275. }
  276. function CheckUserID($uid, $msgtitle = '用户名')
  277. {
  278. for ($i = 0; isset($uid[$i]); $i++) {
  279. if (128 < ord($ck_uid[$i])) {
  280. if (isset($uid[$i + 1]) && 64 < ord($uid[$i + 1])) {
  281. $i++;
  282. } else {
  283. return $msgtitle . '可能含有乱码,建议你改用英文字母和数字组合!';
  284. }
  285. }
  286. }
  287. return 'ok';
  288. }
  289. function GetIP()
  290. {
  291. if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
  292. $cip = $_SERVER['HTTP_CLIENT_IP'];
  293. } else {
  294. if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  295. $cip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  296. } else {
  297. if (!empty($_SERVER['REMOTE_ADDR'])) {
  298. $cip = $_SERVER['REMOTE_ADDR'];
  299. } else {
  300. if (!pcclient()) {
  301. $cip = 'wap';
  302. } else {
  303. $cip = '';
  304. }
  305. }
  306. }
  307. }
  308. preg_match('/[\\d\\.]{7,15}/', $cip, $cips);
  309. $cip = isset($cips[0]) ? $cips[0] : 'unknown';
  310. unset($cips);
  311. return $cip;
  312. }
  313. function utf8_unserialize($serial_str)
  314. {
  315. $out = @preg_replace('!s:(\\d+):"(.*?)";!se', '\'s:\'.strlen(\'$2\').\':"$2";\'', $serial_str);
  316. return unserialize($out);
  317. }
  318. function write_admin_record($msg)
  319. {
  320. global $admin_id;
  321. global $db_mymps;
  322. global $db;
  323. global $timestamp;
  324. $db->query('INSERT INTO `' . $db_mymps . 'admin_record_action` (id,adminid,ip,pubdate,action) VALUES (\'\',\'' . $admin_id . '\',\'' . getip() . '\',\'' . $timestamp . '\',\'' . $msg . '\')');
  325. }
  326. function write_msg($msg = '', $url = 'javascript:history.go(-1);', $action = '')
  327. {
  328. global $charset;
  329. global $db;
  330. global $db_mymps;
  331. global $mymps_global;
  332. global $mymps_starttime;
  333. !empty($action) && write_admin_record($msg);
  334. if (defined('IN_AJAX')) {
  335. echo '<script language=javascript>alert(\'' . $msg . '\');';
  336. echo $url == 'olmsg' ? '</script>' : 'window.location.href=\'' . $url . '\';</script>';
  337. } else {
  338. $hidden = $url == 'olmsg' ? 1 : '';
  339. if (!empty($msg) && !empty($url)) {
  340. if ($url == 'javascript:history.go(-1);') {
  341. $time_echo = 'setTimeout(\'JumpUrl()\',4000);';
  342. $msg = '<img src=\'' . $mymps_global[SiteUrl] . '/images/warn.gif\' align=\'absmiddle\'> ' . $msg;
  343. $goto = '<a href=\'' . $url . '\'>如果你的浏览器没反应,请点击这里...</a>';
  344. } else {
  345. if ($url == 'olmsg') {
  346. $time_echo = $goto = '';
  347. } else {
  348. $time_echo = 'setTimeout(\'JumpUrl()\',3000);';
  349. $goto = '<a href=\'' . $url . '\'>如果你的浏览器没反应,请点击这里...</a>';
  350. }
  351. }
  352. include MYMPS_ROOT . '/template/global/mymps_message.html';
  353. } else {
  354. if (empty($msg) && !empty($url)) {
  355. Header('HTTP/1.1 303 See Other');
  356. Header('Location: ' . $url);
  357. }
  358. }
  359. }
  360. if (!defined('NO_EXIT')) {
  361. $mymps_global = $db = $db_mymps = $charset = $timestamp = NULL;
  362. exit;
  363. }
  364. }
  365. function show_msg($msgs, $ms = '')
  366. {
  367. global $charset;
  368. global $db;
  369. global $db_mymps;
  370. if (!empty($ms) && $ms == 'record') {
  371. while (list($k, $v) = each($msgs)) {
  372. $str .= '<br>' . $v . '<br>';
  373. }
  374. write_admin_record(SpHtml2Text($str));
  375. } else {
  376. if (!empty($ms) && $ms != 'record') {
  377. write_admin_record($ms);
  378. }
  379. }
  380. $title = $mymps_global[SiteName] . '提示信息!';
  381. include MYMPS_ROOT . '/template/global/mymps_msg.html';
  382. while (list($k, $v) = each($msgs)) {
  383. $str .= '<br>' . $v . '<br>';
  384. }
  385. echo $str . '</div></div></div></center></body></html>';
  386. }
  387. function mymps_goto($url = '')
  388. {
  389. return '<script>window.document.location.href=\'' . $url . '\';</script>';
  390. }
  391. function is_member_info($id, $type = 'public')
  392. {
  393. global $db;
  394. global $db_mymps;
  395. if (empty($id)) {
  396. write_msg('操作失败!您没有选择对象!');
  397. }
  398. $type = $type == 'public' ? 'AND a.info_level != 0' : '';
  399. $post = $db->getRow('SELECT a.*,b.modid FROM `' . $db_mymps . 'information` AS a LEFT JOIN `' . $db_mymps . 'category` AS b ON a.catid = b.catid WHERE a.id = \'' . $id . '\' ' . $type);
  400. return $post;
  401. }
  402. function setParam($param1, $rewrite = 'active', $pre = '', $htmlpath = '')
  403. {
  404. if ($rewrite == 'rewrite') {
  405. $param = $pre;
  406. foreach ($param1 as $key) {
  407. ${$key} =& $GLOBALS[$key];
  408. $param .= ${$key} != NULL ? urlencode($key) . '-' . ${$key} . '-' : '';
  409. }
  410. } else {
  411. if ($rewrite == 'rewrite_py') {
  412. $param = '';
  413. foreach ($param1 as $key) {
  414. ${$key} =& $GLOBALS[$key];
  415. $param .= ${$key} != NULL ? urlencode($key) . '-' . ${$key} . '-' : '';
  416. }
  417. } else {
  418. if ($rewrite == 'html') {
  419. $param = $htmlpath;
  420. } else {
  421. if ($rewrite == 'active') {
  422. if (defined('IN_ADMIN')) {
  423. foreach ($param1 as $key) {
  424. ${$key} =& $GLOBALS[$key];
  425. $param .= urlencode($key) . '=' . ${$key} . '&';
  426. }
  427. } else {
  428. foreach ($param1 as $key) {
  429. ${$key} =& $GLOBALS[$key];
  430. $param .= ${$key} != NULL ? urlencode($key) . '=' . ${$key} . '&' : '';
  431. }
  432. }
  433. }
  434. }
  435. }
  436. }
  437. return $param;
  438. }
  439. function get_page_idin2($column = 'id', $sql = '', $number = '')
  440. {
  441. global $mymps_global;
  442. global $db;
  443. global $db_mymps;
  444. $page = $number ? ' LIMIT 0,' . $number : '';
  445. $query = $db->query($sql . $page);
  446. while ($row = $db->fetchRow($query)) {
  447. $idin .= $row[$column] . ',';
  448. }
  449. $idin = $idin ? substr($idin, 0, -1) : NULL;
  450. return $idin;
  451. }
  452. function get_page_idin($column = 'id', $sql = '', $cfg_page = '')
  453. {
  454. global $page;
  455. global $per_page;
  456. global $per_screen;
  457. global $pages_num;
  458. global $rows_num;
  459. global $mymps_global;
  460. global $db;
  461. global $db_mymps;
  462. $page = empty($page) || $page < 0 || !is_numeric($page) ? 1 : $page;
  463. $per_page = $cfg_page ? $cfg_page : ($per_page ? $per_page : $mymps_global['cfg_page_line']);
  464. $per_screen = !isset($per_screen) ? 10 : $per_screen;
  465. $pages_num = ceil($rows_num / $per_page);
  466. $query = $db->query($sql . ' limit ' . ($page - 1) * $per_page . ', ' . $per_page);
  467. while ($row = $db->fetchRow($query)) {
  468. $idin .= $row[$column] . ',';
  469. }
  470. $idin = $idin ? substr($idin, 0, -1) : NULL;
  471. return $idin;
  472. }
  473. function page1($sqlstr = '', $per_page = '')
  474. {
  475. global $page;
  476. global $per_screen;
  477. global $pages_num;
  478. global $rows_num;
  479. global $mymps_global;
  480. global $db;
  481. global $db_mymps;
  482. $page = empty($page) || $page < 0 || !is_numeric($page) ? 1 : $page;
  483. $per_page = $per_page ? $per_page : $mymps_global['cfg_page_line'];
  484. $per_screen = !isset($per_screen) ? 10 : $per_screen;
  485. $pages_num = ceil($rows_num / $per_page);
  486. return $db->getAll($sqlstr . ' limit ' . ($page - 1) * $per_page . ', ' . $per_page);
  487. }
  488. function page2($rewrite = 'active', $ext = '.html')
  489. {
  490. global $rows_num;
  491. global $page;
  492. global $pages_num;
  493. global $per_page;
  494. global $param;
  495. global $per_screen;
  496. global $dir_typename;
  497. $font_size = '10pt';
  498. $mid = ceil(($per_screen + 1) / 2);
  499. $nav = '';
  500. if ($page <= $mid) {
  501. $begin = 1;
  502. } else {
  503. if ($pages_num - $mid < $page) {
  504. $begin = $pages_num - $per_screen + 1;
  505. } else {
  506. $begin = $page - $mid + 1;
  507. }
  508. }
  509. $begin = $begin < 0 ? 1 : $begin;
  510. if ($rewrite == 'active') {
  511. $nav .= '<span class=anum>共' . $rows_num . '记录</span> ';
  512. if (1 < $page) {
  513. $nav .= '<a href=\'?' . $param . 'page=' . ($page - 1) . '\' title=\'第' . ($page - 1) . '页\'><上一页</a>';
  514. }
  515. if ($begin != 1) {
  516. $nav .= '<a href=\'?' . $param . '\' title=\'第1页\'>1 ...</a>';
  517. }
  518. $end = $pages_num < $begin + $per_screen ? $pages_num + 1 : $begin + $per_screen;
  519. for ($i = $begin; $i < $end; $i++) {
  520. if (!empty($i)) {
  521. $nav .= $page != $i ? '<a href=\'?' . $param . 'page=' . $i . '\' title=\'第' . $i . '页\'>' . $i . '</a> ' : ' <span class=current>' . $i . '</span> ';
  522. }
  523. }
  524. if ($end != $pages_num + 1) {
  525. $nav .= '<a href=\'?' . $param . 'page=' . $pages_num . '\' title=\'第' . $pages_num . '页\'>... ' . $pages_num . '</a>';
  526. }
  527. if ($page < $pages_num) {
  528. $nav .= '<a href=\'?' . $param . 'page=' . ($page + 1) . '\' title=\'第' . ($page + 1) . '页\'>下一页></a>';
  529. }
  530. } else {
  531. if ($rewrite == 'rewrite') {
  532. $nav .= '<span class=anum>共' . $rows_num . '记录</span> ';
  533. if (1 < $page) {
  534. $nav .= '<a href=\'/' . $param . 'page-' . ($page - 1) . '.html\' title=\'第' . ($page - 1) . '页\'><上一页</a>';
  535. }
  536. if ($begin != 1) {
  537. $nav .= '<a href=\'/' . $param . 'page-1.html\' title=\'第1页\'>1 ...</a>';
  538. }
  539. $end = $pages_num < $begin + $per_screen ? $pages_num + 1 : $begin + $per_screen;
  540. for ($i = $begin; $i < $end; $i++) {
  541. if (!empty($i)) {
  542. $nav .= $page != $i ? '<a href=\'/' . $param . 'page-' . $i . '.html\' title=\'第' . $i . '页\'>' . $i . '</a> ' : ' <span class=current>' . $i . '</span> ';
  543. }
  544. }
  545. if ($end != $pages_num + 1) {
  546. $nav .= '<a href=\'/' . $param . 'page-' . $pages_num . '.html\' title=\'第' . $pages_num . '页\'>... ' . $pages_num . '</a>';
  547. }
  548. if ($page < $pages_num) {
  549. $nav .= '<a href=\'/' . $param . 'page-' . ($page + 1) . '.html\' title=\'第' . ($page + 1) . '页\'>下一页></a>';
  550. }
  551. } else {
  552. if ($rewrite == 'rewrite_py') {
  553. $param = '/' . $dir_typename . '/' . $param;
  554. $nav .= '<span class=anum>共' . $rows_num . '记录</span> ';
  555. if (1 < $page) {
  556. $nav .= '<a href=\'' . $param . 'page-' . ($page - 1) . '/\' title=\'第' . ($page - 1) . '页\'><上一页</a>';
  557. }
  558. if ($begin != 1) {
  559. $nav .= '<a href=\'' . $param . 'page-1/\' title=\'第1页\'>1 ...</a>';
  560. }
  561. $end = $pages_num < $begin + $per_screen ? $pages_num + 1 : $begin + $per_screen;
  562. for ($i = $begin; $i < $end; $i++) {
  563. if (!empty($i)) {
  564. $nav .= $page != $i ? '<a href=\'' . $param . 'page-' . $i . '/\' title=\'第' . $i . '页\'>' . $i . '</a> ' : ' <span class=current>' . $i . '</span> ';
  565. }
  566. }
  567. if ($end != $pages_num + 1) {
  568. $nav .= '<a href=\'' . $param . 'page-' . $pages_num . '/\' title=\'第' . $pages_num . '页\'>... ' . $pages_num . '</a>';
  569. }
  570. if ($page < $pages_num) {
  571. $nav .= '<a href=\'' . $param . 'page-' . ($page + 1) . '/\' title=\'第' . ($page + 1) . '页\'>下一页></a>';
  572. }
  573. } else {
  574. if ($rewrite == 'html') {
  575. $nav .= '<span class=anum>共' . $rows_num . '记录</span> ';
  576. if (1 < $page) {
  577. $nav .= '<a href=\'' . $param . 'list_' . ($page - 1) . $ext . '\' title=\'第' . ($page - 1) . '页\'><上一页</a>';
  578. }
  579. if ($begin != 1) {
  580. $nav .= '<a href=\'' . $param . 'list_1' . $ext . '\' title=\'第1页\'>1 ...</a>';
  581. }
  582. $end = $pages_num < $begin + $per_screen ? $pages_num + 1 : $begin + $per_screen;
  583. for ($i = $begin; $i < $end; $i++) {
  584. if (!empty($i)) {
  585. $nav .= $page != $i ? '<a href=\'' . $param . 'list_' . $i . $ext . '\' title=\'第' . $i . '页\'>' . $i . '</a> ' : ' <span class=current>' . $i . '</span> ';
  586. }
  587. }
  588. if ($end != $pages_num + 1) {
  589. $nav .= '<a href=\'' . $param . 'list_' . $pages_num . $ext . '\' title=\'第' . $pages_num . '页\'>... ' . $pages_num . '</a>';
  590. }
  591. if ($page < $pages_num) {
  592. $nav .= '<a href=\'' . $param . 'list_' . ($page + 1) . $ext . '\' title=\'第' . ($page + 1) . '页\'>下一页></a>';
  593. }
  594. }
  595. }
  596. }
  597. }
  598. if (defined('IN_ADMIN') && 1 < $pages_num) {
  599. $nav .= '<form action="?' . substr($param, 0, -1) . '" method="post" name="pageform" id="pageform"><input name="page" type="text" class="page_input"><input type="submit" style="float:left; margin-left:3px" class="gray" value="GO!"></form>';
  600. }
  601. return $nav;
  602. }
  603. function get_advertisement($page = 'index')
  604. {
  605. $data = read_static_cache('adv_' . $page);
  606. return $data;
  607. }
  608. function GetUrl()
  609. {
  610. global $mymps_global;
  611. $url = (strstr($mymps_global['SiteUrl'], 'https:') ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'];
  612. if (isset($_SERVER['REQUEST_URI'])) {
  613. $url .= $_SERVER['REQUEST_URI'];
  614. } else {
  615. $url .= $_SERVER['PHP_SELF'];
  616. if (!empty($_SERVER['QUERY_STRING'])) {
  617. $url .= '?' . $_SERVER['QUERY_STRING'];
  618. }
  619. }
  620. return $url;
  621. }
  622. function GetTime($time = '', $c = 'Y-m-d H:i:s')
  623. {
  624. return $time ? date($c, $time) : '';
  625. }
  626. function globalassign()
  627. {
  628. global $mymps_global;
  629. global $docunav;
  630. global $city;
  631. if (CURSCRIPT == 'store') {
  632. $docunav = get_member_docunav();
  633. }
  634. }
  635. function mymps_tpl($str, $curscript = '')
  636. {
  637. global $mymps_global;
  638. $mymps_global['SiteStat'] = htmlspecialchars_decode($mymps_global['SiteStat']);
  639. $mymps_global['SiteStat'] = str_replace('type=\'/javascript\'', 'type=\'text/javascript\'', $mymps_global['SiteStat']);
  640. $curscript = $curscript ? $curscript : CURSCRIPT;
  641. if (defined('IN_SMT')) {
  642. if ($curscript == 'wap') {
  643. $tpldir = 'm';
  644. $templateid = 8;
  645. $tplfile = MYMPS_ROOT . '/' . $tpldir . '/template/' . $str . '.html';
  646. $objfile = MYMPS_DATA . '/templates/' . $templateid . '_' . $str . '.tpl.php';
  647. } else {
  648. if ($curscript == 'search') {
  649. $tpldir = 'search';
  650. $templateid = 7;
  651. $tplfile = MYMPS_TPL . '/' . $tpldir . '/' . $str . '.html';
  652. $objfile = MYMPS_DATA . '/templates/' . $templateid . '_' . $str . '.tpl.php';
  653. } else {
  654. if ($curscript == 'store') {
  655. $tpldir = 'spaces/store';
  656. $templateid = '6';
  657. $tplfile = MYMPS_TPL . '/' . $tpldir . '/' . $str . '.html';
  658. $objfile = MYMPS_DATA . '/templates/' . $templateid . '_' . $str . '.tpl.php';
  659. } else {
  660. if ($curscript == 'coupon') {
  661. $tpldir = 'plugin/coupon/template';
  662. $templateid = '5';
  663. $tplfile = MYMPS_ROOT . '/' . $tpldir . '/' . $str . '.html';
  664. $objfile = MYMPS_DATA . '/templates/' . $templateid . '_' . $str . '.tpl.php';
  665. } else {
  666. if ($curscript == 'group') {
  667. $tpldir = 'plugin/group/template';
  668. $templateid = '4';
  669. $tplfile = MYMPS_ROOT . '/' . $tpldir . '/' . $str . '.html';
  670. $objfile = MYMPS_DATA . '/templates/' . $templateid . '_' . $str . '.tpl.php';
  671. } else {
  672. if ($curscript == 'goods') {
  673. $tpldir = 'plugin/goods/template';
  674. $templateid = '3';
  675. $tplfile = MYMPS_ROOT . '/' . $tpldir . '/' . $str . '.html';
  676. $objfile = MYMPS_DATA . '/templates/' . $templateid . '_' . $str . '.tpl.php';
  677. } else {
  678. if ($curscript == 'space') {
  679. $tpldir = 'spaces/person';
  680. $templateid = 2;
  681. $tplfile = MYMPS_TPL . '/' . $tpldir . '/' . $str . '.html';
  682. $objfile = MYMPS_DATA . '/templates/' . $templateid . '_' . $str . '.tpl.php';
  683. } else {
  684. $tpldir = $tpldir ? $tpldir : TPLDIR;
  685. $templateid = $templateid ? $templateid : TEMPLATEID;
  686. $tplfile = MYMPS_TPL . '/' . $tpldir . '/' . $str . '.html';
  687. $objfile = MYMPS_DATA . '/templates/' . $templateid . '_' . $str . '.tpl.php';
  688. }
  689. }
  690. }
  691. }
  692. }
  693. }
  694. }
  695. @chktplrefresh($objfile, $tplfile, filemtime($objfile), $templateid, $tpldir);
  696. return $objfile;
  697. } else {
  698. return 'template/' . $str . '.tpl.php';
  699. }
  700. }
  701. function unknown_err_msg()
  702. {
  703. $msgs = '未知错误,可能与你提交的参数有关<br /><br />获取更多帮助请前往<a href=http://mymps.com.cn target=_blank>Mymps官方网站</a>';
  704. write_msg($msgs, 'olmsg');
  705. }
  706. function Spcnw_mid($str, $start, $slen)
  707. {
  708. $str_len = strlen($str);
  709. $strs = array();
  710. for ($i = 0; $i < $str_len; $i++) {
  711. if (128 < ord($str[$i])) {
  712. if ($i + 1 < $str_len) {
  713. $strs[] = $str[$i] . $str[$i + 1];
  714. } else {
  715. $strs[] = '';
  716. }
  717. $i++;
  718. } else {
  719. $strs[] = $str[$i];
  720. }
  721. }
  722. $wlen = count($strs);
  723. if ($wlen < $start) {
  724. return '';
  725. }
  726. $restr = '';
  727. $startdd = $start;
  728. $enddd = $startdd + $slen;
  729. for ($i = $startdd; $i < $enddd; $i++) {
  730. if (!isset($strs[$i])) {
  731. break;
  732. }
  733. $restr .= $strs[$i];
  734. }
  735. return $restr;
  736. }
  737. function Text2Html($txt)
  738. {
  739. $txt = str_replace(' ', ' ', $txt);
  740. $txt = str_replace('<', '&lt;', $txt);
  741. $txt = str_replace('>', '&gt;', $txt);
  742. $txt = preg_replace('/[' . "\r\n" . ']{1,}/isU', '<br/>' . "\r\n", $txt);
  743. return $txt;
  744. }
  745. function SpHtml2Text($str)
  746. {
  747. $str = preg_replace('/<sty(.*)\\/style>|<scr(.*)\\/script>|<!--(.*)-->/isU', '', $str);
  748. $alltext = '';
  749. $start = 1;
  750. for ($i = 0; $i < strlen($str); $i++) {
  751. if ($start == 0 && $str[$i] == '>') {
  752. $start = 1;
  753. } else {
  754. if ($start == 1) {
  755. if ($str[$i] == '<') {
  756. $start = 0;
  757. $alltext .= ' ';
  758. } else {
  759. if (31 < ord($str[$i])) {
  760. $alltext .= $str[$i];
  761. }
  762. }
  763. }
  764. }
  765. }
  766. $alltext = str_replace(' ', ' ', $alltext);
  767. $alltext = preg_replace('/&([^;&]*)(;|&)/', '', $alltext);
  768. $alltext = preg_replace('/[ ]+/s', ' ', $alltext);
  769. return $alltext;
  770. }
  771. function clear_html($str = '', $clearbr = true)
  772. {
  773. $str = preg_replace('/<style .*?<\\/style>/is', '', $str);
  774. $str = preg_replace('/<script .*?<\\/script>/is', '', $str);
  775. $str = preg_replace('/<br \\s*\\/?\\/>/i', "\n", $str);
  776. $str = preg_replace('/<\\/?p>/i', "\n\n", $str);
  777. $str = preg_replace('/<\\/?td>/i', "\n", $str);
  778. $str = preg_replace('/<\\/?div>/i', "\n", $str);
  779. $str = preg_replace('/<\\/?blockquote>/i', "\n", $str);
  780. $str = preg_replace('/<\\/?li>/i', "\n", $str);
  781. $str = preg_replace('/\\&nbsp\\;/i', ' ', $str);
  782. $str = preg_replace('/\\&nbsp/i', ' ', $str);
  783. $str = preg_replace('/\\&amp\\;/i', '&', $str);
  784. $str = preg_replace('/\\&amp/i', '&', $str);
  785. $str = preg_replace('/\\&lt\\;/i', '<', $str);
  786. $str = preg_replace('/\\&lt/i', '<', $str);
  787. $str = preg_replace('/\\&ldquo\\;/i', '"', $str);
  788. $str = preg_replace('/\\&ldquo/i', '"', $str);
  789. $str = preg_replace('/\\&lsquo\\;/i', '\'', $str);
  790. $str = preg_replace('/\\&lsquo/i', '\'', $str);
  791. $str = preg_replace('/\\&rsquo\\;/i', '\'', $str);
  792. $str = preg_replace('/\\&rsquo/i', '\'', $str);
  793. $str = preg_replace('/\\&gt\\;/i', '>', $str);
  794. $str = preg_replace('/\\&gt/i', '>', $str);
  795. $str = preg_replace('/\\&rdquo\\;/i', '"', $str);
  796. $str = preg_replace('/\\&rdquo/i', '"', $str);
  797. $str = strip_tags($str);
  798. $str = html_entity_decode($str, ENT_QUOTES);
  799. $str = preg_replace('/\\&\\#.*?\\;/i', '', $str);
  800. $str = $clearbr ? str_replace(array("\r\n", "\r", "\n", ' ', "\t"), '', $str) : $str;
  801. return $str;
  802. }
  803. function mymps_count($table, $where = '')
  804. {
  805. global $db;
  806. global $db_mymps;
  807. $count = $db->getOne('SELECT count(*) FROM ' . $db_mymps . $table . ' ' . $where);
  808. if ($count) {
  809. return $count;
  810. } else {
  811. return 0;
  812. exit;
  813. }
  814. }
  815. function mymps_delete($table, $where = '')
  816. {
  817. global $db;
  818. global $db_mymps;
  819. $delete = $db->query('DELETE FROM ' . $db_mymps . $table . ' ' . $where);
  820. if ($delete) {
  821. return true;
  822. } else {
  823. return false;
  824. }
  825. }
  826. function mymps_del_all($table, $id, $idor = 'id')
  827. {
  828. global $db;
  829. global $db_mymps;
  830. $id = !empty($id) ? join(',', $id) : 0;
  831. $delete = $db->query('DELETE FROM ' . $db_mymps . $table . ' WHERE ' . $idor . ' IN (' . $id . ')');
  832. if ($delete) {
  833. return $id;
  834. } else {
  835. return false;
  836. }
  837. }
  838. function substring($str, $start, $length)
  839. {
  840. $len = $length;
  841. if ($length < 0) {
  842. $str = strrev($str);
  843. $len = -$length;
  844. }
  845. $len = $len < strlen($str) ? $len : strlen($str);
  846. for ($i = $start; $i < $len; $i++) {
  847. if (160 < ord(substr($str, $i, 1))) {
  848. $tmpstr .= substr($str, $i, 2);
  849. $i++;
  850. } else {
  851. $tmpstr .= substr($str, $i, 1);
  852. }
  853. }
  854. if ($length < 0) {
  855. $tmpstr = strrev($tmpstr);
  856. }
  857. return $tmpstr;
  858. }
  859. function substring_utf8($str, $start, $lenth)
  860. {
  861. $len = strlen($str);
  862. $r = array();
  863. $n = 0;
  864. $m = 0;
  865. for ($i = 0; $i < $len; $i++) {
  866. $x = substr($str, $i, 1);
  867. $a = base_convert(ord($x), 10, 2);
  868. $a = substr('00000000' . $a, -8);
  869. if ($n < $start) {
  870. if (substr($a, 0, 1) == 0) {
  871. } else {
  872. if (substr($a, 0, 3) == 110) {
  873. $i += 1;
  874. } else {
  875. if (substr($a, 0, 4) == 1110) {
  876. $i += 2;
  877. }
  878. }
  879. }
  880. $n++;
  881. } else {
  882. if (substr($a, 0, 1) == 0) {
  883. $r[] = substr($str, $i, 1);
  884. } else {
  885. if (substr($a, 0, 3) == 110) {
  886. $r[] = substr($str, $i, 2);
  887. $i += 1;
  888. } else {
  889. if (substr($a, 0, 4) == 1110) {
  890. $r[] = substr($str, $i, 3);
  891. $i += 2;
  892. } else {
  893. $r[] = '';
  894. }
  895. }
  896. }
  897. if ($lenth <= ++$m) {
  898. break;
  899. }
  900. }
  901. }
  902. return join($r);
  903. }
  904. function get_info_life_time($time)
  905. {
  906. global $timestamp;
  907. if (empty($time)) {
  908. return '<font color=green>长期有效</font>';
  909. } else {
  910. if ($time < $timestamp) {
  911. return '<font color=red>已过期</font>';
  912. }
  913. }
  914. }
  915. function plugin_url($flag, $params = '')
  916. {
  917. global $mymps_global;
  918. $args = array('id' => 0, 'cate_id' => 0, 'areaid' => 0, 'page' => 0, 'orderby' => 0, 'catid' => 0, 'tuijian' => 0, 'cuxiao' => 0);
  919. extract(array_merge($args, $params));
  920. $uri = $mymps_global['SiteUrl'] . '/' . $flag . '.php';
  921. if ($cate_id && $areaid) {
  922. $uri .= '?cate_id=' . $cate_id . '&areaid=' . $areaid;
  923. $uri .= $orderby ? '&orderby=' . $orderby : '';
  924. $uri .= $page ? '&page=' . $page : '';
  925. } else {
  926. if ($cate_id) {
  927. $uri .= '?cate_id=' . $cate_id;
  928. $uri .= $orderby ? '&orderby=' . $orderby : '';
  929. $uri .= $page ? '&page=' . $page : '';
  930. } else {
  931. if ($catid) {
  932. $uri .= '?catid=' . $catid;
  933. $uri .= $orderby ? '&orderby=' . $orderby : '';
  934. $uri .= $page ? '&page=' . $page : '';
  935. } else {
  936. if ($areaid) {
  937. $uri .= '?areaid=' . $areaid;
  938. $uri .= $orderby ? '&orderby=' . $orderby : '';
  939. $uri .= $page ? '&page=' . $page : '';
  940. } else {
  941. if ($id) {
  942. $uri .= '?id=' . $id;
  943. } else {
  944. if ($orderby) {
  945. $uri = $orderby ? '?orderby=' . $orderby : '';
  946. $uri .= $page ? '&page=' . $page : '';
  947. }
  948. }
  949. }
  950. }
  951. }
  952. }
  953. $uri .= $tuijian == 1 ? '&tuijian=1' : '';
  954. $uri .= $cuxiao == 1 ? '&cuxiao=1' : '';
  955. unset($flag);
  956. unset($orderby);
  957. unset($page);
  958. unset($cate_id);
  959. unset($areaid);
  960. unset($id);
  961. unset($params);
  962. return $uri;
  963. }
  964. function Rewrite($types, $params)
  965. {
  966. global $seo;
  967. global $mymps_global;
  968. global $cat_dir;
  969. global $db;
  970. global $db_mymps;
  971. $args = array('id' => 0, 'catid' => 0, 'areaid' => 0, 'page' => 0, 'orderby' => 0, 'tuijian' => 0, 'cuxiao' => 0, 'part' => 0, 'user' => 0, 'typeid' => 0, 'action' => 0, 'html_path' => 0, 'dir_typename' => 0, 'html_dir' => 0, 'type' => 0, 'uid' => 0);
  972. extract(array_merge($args, $params));
  973. if (!$seo) {
  974. $seo = get_seoset();
  975. }
  976. $uri = '';
  977. switch ($types) {
  978. case 'category':
  979. $uri = $mymps_global['SiteUrl'];
  980. if ($seo['seo_force_category'] == 'rewrite_py') {
  981. $rewrite = 3;
  982. } else {
  983. if ($seo['seo_force_category'] == 'rewrite') {
  984. $rewrite = 1;
  985. } else {
  986. $rewrite = 0;
  987. }
  988. }
  989. if ($catid && $rewrite == 1) {
  990. $uri .= '/category-catid-' . $catid;
  991. $uri .= $areaid ? '-areaid-' . $areaid : '';
  992. $uri .= $page ? '-page-' . $page : '';
  993. } else {
  994. if ($catid && $rewrite == 3) {
  995. $uri .= '/' . $dir_typename;
  996. $uri .= $areaid ? '-areaid-' . $areaid : '';
  997. $uri .= $page ? '-page-' . $page : '';
  998. } else {
  999. if ($catid) {
  1000. $uri .= '/category.php?catid=' . $catid;
  1001. if ($areaid) {
  1002. $uri .= '&amp;areaid=' . $areaid;
  1003. }
  1004. if ($page) {
  1005. $uri .= '&amp;page=' . $page;
  1006. }
  1007. }
  1008. }
  1009. }
  1010. break;
  1011. case 'info':
  1012. $uri = '';
  1013. if ($seo['seo_force_info'] == 'rewrite_py') {
  1014. $rewrite = 3;
  1015. } else {
  1016. if ($seo['seo_force_info'] == 'rewrite') {
  1017. $rewrite = 1;
  1018. } else {
  1019. $rewrite = 0;
  1020. }
  1021. }
  1022. if ($rewrite == 1) {
  1023. $uri .= '/information-id-' . $id;
  1024. } else {
  1025. if ($rewrite == 3) {
  1026. if (empty($dir_typename)) {
  1027. $cat_dir = $cat_dir ? $cat_dir : get_category_dir();
  1028. $dir_typename = $cat_dir[$catid];
  1029. }
  1030. $uri .= '/' . $dir_typename . '/' . $id . '.html';
  1031. } else {
  1032. if (empty($rewrite)) {
  1033. $uri .= '/information.php?id=' . $id;
  1034. }
  1035. }
  1036. }
  1037. break;
  1038. case 'about':
  1039. $rewrite = $seo['seo_force_about'] == 'rewrite' ? 1 : 0;
  1040. if (empty($part)) {
  1041. return false;
  1042. } else {
  1043. if ($id && empty($page)) {
  1044. if ($part == 'announce') {
  1045. $uri .= $rewrite ? '/' . $part . '.html#' . $id : '/about.php?part=' . $part . '#' . $id;
  1046. } else {
  1047. $uri .= $rewrite ? '/' . $part . '-id-' . $id : '/about.php?part=' . $part . '&amp;id=' . $id;
  1048. }
  1049. } else {
  1050. if ($page && empty($id)) {
  1051. $uri .= $rewrite ? '/' . $part . '-page-' . $page : '/about.php?part=' . $part . '&amp;page=' . $page;
  1052. } else {
  1053. if (empty($id) && empty($page) && empty($action)) {
  1054. $uri .= $rewrite ? '/' . $part : '/about.php?part=' . $part;
  1055. } else {
  1056. if (empty($id) && empty($page) && $action) {
  1057. $uri .= $rewrite ? '/' . $part . '-action-' . $action : '/about.php?part=' . $part . '&amp;action=' . $action;
  1058. }
  1059. }
  1060. }
  1061. }
  1062. }
  1063. break;
  1064. case 'corp':
  1065. $rewrite = $seo['seo_force_yp'] == 'rewrite' ? 1 : 0;
  1066. if ($action == 'index' && empty($catid) && empty($areaid)) {
  1067. $uri .= $rewrite ? '/corporation' : '/corporation.php';
  1068. } else {
  1069. if (empty($action) && $rewrite) {
  1070. $uri .= '/corporation' . ($catid ? '-catid-' . $catid : '');
  1071. $uri .= $areaid ? '-areaid-' . $areaid : '';
  1072. $uri .= $page ? '-page-' . $page : '';
  1073. } else {
  1074. if (empty($action) && empty($rewrite)) {
  1075. $uri .= '/corporation.php?catid=' . $catid;
  1076. if ($page) {
  1077. $uri .= '&amp;page=' . $page;
  1078. }
  1079. if ($areaid) {
  1080. $uri .= '&amp;areaid=' . $areaid;
  1081. }
  1082. }
  1083. }
  1084. }
  1085. break;
  1086. case 'goods':
  1087. $uri = $mymps_global['SiteUrl'];
  1088. $rewrite = $seo['seo_force_goods'] == 'rewrite' ? 1 : 0;
  1089. if (empty($catid) && empty($orderby) && empty($id)) {
  1090. $uri .= $rewrite ? '/goods' : '/goods.php';
  1091. } else {
  1092. if ($id && empty($catid) && empty($orderby)) {
  1093. $uri .= $rewrite ? '/goods-id-' . $id : '/goods.php?id=' . $id;
  1094. } else {
  1095. if ($rewrite) {
  1096. $uri .= '/goods' . ($catid ? '-catid-' . $catid : '');
  1097. $uri .= $orderby ? '-orderby-' . $orderby : '';
  1098. $uri .= $cuxiao ? '-cuxiao-' . $cuxiao : '';
  1099. $uri .= $tuijian ? '-tuijian-' . $tuijian : '';
  1100. $uri .= $page ? '-page-' . $page : '';
  1101. } else {
  1102. if (empty($rewrite)) {
  1103. $uri .= '/goods.php?' . ($catid ? 'catid=' . $catid : '');
  1104. if ($orderby) {
  1105. $uri .= '&amp;orderby=' . $orderby;
  1106. }
  1107. if ($cuxiao) {
  1108. $uri .= '&amp;cuxiao=' . $cuxiao;
  1109. }
  1110. if ($tuijian) {
  1111. $uri .= '&amp;tuijian=' . $tuijian;
  1112. }
  1113. if ($page) {
  1114. $uri .= '&amp;page=' . $page;
  1115. }
  1116. }
  1117. }
  1118. }
  1119. }
  1120. break;
  1121. case 'news':
  1122. $rewrite = $seo['seo_force_news'] == 'rewrite' ? 1 : 0;
  1123. if ($action == 'index' && empty($catid) && empty($id)) {
  1124. $uri .= $rewrite ? '/news' : '/news.php';
  1125. } else {
  1126. if ($id && empty($catid) && empty($action)) {
  1127. $uri .= $rewrite ? '/news-id-' . $id : '/news.php?id=' . $id;
  1128. } else {
  1129. if ($catid && $rewrite && empty($id) && empty($action)) {
  1130. $uri .= '/news-catid-' . $catid;
  1131. $uri .= $page ? '-page-' . $page : '';
  1132. } else {
  1133. if ($catid && empty($rewrite) && empty($id) && empty($action)) {
  1134. $uri .= '/news.php?catid=' . $catid;
  1135. if ($page) {
  1136. $uri .= '&amp;page=' . $page;
  1137. }
  1138. }
  1139. }
  1140. }
  1141. }
  1142. break;
  1143. case 'space':
  1144. $uri = $mymps_global['SiteUrl'] . '/';
  1145. $rewrite = $seo['seo_force_space'] == 'rewrite' && inchinese($user) ? 1 : 0;
  1146. if (empty($user)) {
  1147. return false;
  1148. } else {
  1149. $uri .= $rewrite ? 'space/' . $user . '/' : 'space.php?user=' . urlencode($user);
  1150. }
  1151. break;
  1152. case 'store':
  1153. $rewrite = $seo['seo_force_store'] == 'domain' ? 2 : ($seo['seo_force_store'] == 'rewrite' ? 1 : 0);
  1154. if ($rewrite == 2) {
  1155. $rootdomain = str_replace('http://www.', '', $mymps_global[SiteUrl]);
  1156. } else {
  1157. $rootdomain = '';
  1158. }
  1159. if (!$part) {
  1160. $part = 'index';
  1161. }
  1162. if (empty($uid)) {
  1163. return false;
  1164. } else {
  1165. if ($uid && $part == 'index' && $rewrite == 2) {
  1166. $uri = 'http://' . $uid . '.' . $rootdomain;
  1167. } else {
  1168. if ($uid && $part == 'index' && $rewrite == 1) {
  1169. $uri .= '/store-' . $uid . '/';
  1170. } else {
  1171. if ($uid && $part == 'index' && !$rewrite) {
  1172. $uri .= '/store.php?uid=' . $uid;
  1173. } else {
  1174. if ($uid && $part && $rewrite == 2) {
  1175. $uri = 'http://' . $uid . '.' . $rootdomain . '/' . $part;
  1176. $uri .= $type ? '-' . $type : '';
  1177. $uri .= $typeid ? '-typeid-' . $typeid : '';
  1178. $uri .= $id ? '-id-' . $id : '';
  1179. $uri .= $page ? '-page-' . $page : '';
  1180. } else {
  1181. if ($uid && $part && $rewrite == 1) {
  1182. $uri .= '/store-' . $uid . '/' . $part;
  1183. $uri .= $type ? '-type-' . $type : '';
  1184. $uri .= $typeid ? '-typeid-' . $typeid : '';
  1185. $uri .= $id ? '-id-' . $id : '';
  1186. $uri .= $page ? '-page-' . $page : '';
  1187. } else {
  1188. if ($uid && $part && !$rewrite) {
  1189. $uri .= '/store.php?uid=' . $uid . '&amp;part=' . $part;
  1190. $uri .= $type ? '&amp;type=' . $type : '';
  1191. $uri .= $typeid ? '&amp;typeid=' . $typeid : '';
  1192. $uri .= $id ? '&amp;id=' . $id : '';
  1193. $uri .= $page ? '&amp;page=' . $page : '';
  1194. }
  1195. }
  1196. }
  1197. }
  1198. }
  1199. }
  1200. }
  1201. break;
  1202. default:
  1203. return false;
  1204. break;
  1205. }
  1206. if ($rewrite == 3 && $types == 'category') {
  1207. $uri .= '/';
  1208. } else {
  1209. if (in_array($rewrite, array(1, 2))) {
  1210. $uri .= (empty($part) || $part == 'index') && in_array($types, array('space', 'store')) ? '/' : $part === 'announce' && !empty($id) ? '' : '.html';
  1211. }
  1212. }
  1213. unset($seo);
  1214. unset($rewrite);
  1215. return $uri;
  1216. }
  1217. function mRewrite($types, $params = array())
  1218. {
  1219. global $seo;
  1220. global $mymps_global;
  1221. global $cat_dir;
  1222. global $db;
  1223. global $db_mymps;
  1224. global $mayimobile;
  1225. $args = array('id' => 0, 'catid' => 0, 'areaid' => 0, 'page' => 0, 'orderby' => 0, 'tuijian' => 0, 'cuxiao' => 0, 'part' => 0, 'user' => 0, 'typeid' => 0, 'action' => 0, 'dir_typename' => 0, 'type' => 0, 'uid' => 0);
  1226. extract(array_merge($args, $params));
  1227. if (!$mayimobile) {
  1228. $mayimobile = get_mobile_settings();
  1229. $mayimobile['mobiledomain'] = $mayimobile['mobiledomain'] ? $mayimobile['mobiledomain'] : $mymps_global['SiteUrl'] . '/m';
  1230. }
  1231. if (!$seo) {
  1232. $seo = get_seoset();
  1233. }
  1234. $uri = $mayimobile['mobiledomain'];
  1235. switch ($types) {
  1236. case 'category':
  1237. if ($seo['seo_force_category'] == 'rewrite_py') {
  1238. $rewrite = 3;
  1239. } else {
  1240. if ($seo['seo_force_category'] == 'rewrite') {
  1241. $rewrite = 1;
  1242. } else {
  1243. $rewrite = 0;
  1244. }
  1245. }
  1246. if ($catid && $rewrite == 1) {
  1247. $uri .= '/category-catid-' . $catid;
  1248. $uri .= $areaid ? '-areaid-' . $areaid : '';
  1249. $uri .= $page ? '-page-' . $page : '';
  1250. } else {
  1251. if ($catid && $rewrite == 3) {
  1252. $uri .= '/' . $dir_typename;
  1253. $uri .= $areaid ? '-areaid-' . $areaid : '';
  1254. $uri .= $page ? '-page-' . $page : '';
  1255. } else {
  1256. if ($catid) {
  1257. $uri .= '/index.php?mod=category&catid=' . $catid;
  1258. if ($areaid) {
  1259. $uri .= '&amp;areaid=' . $areaid;
  1260. }
  1261. if ($page) {
  1262. $uri .= '&amp;page=' . $page;
  1263. }
  1264. }
  1265. }
  1266. }
  1267. break;
  1268. case 'info':
  1269. if ($seo['seo_force_info'] == 'rewrite_py') {
  1270. $rewrite = 3;
  1271. } else {
  1272. if ($seo['seo_force_info'] == 'rewrite') {
  1273. $rewrite = 1;
  1274. } else {
  1275. $rewrite = 0;
  1276. }
  1277. }
  1278. if ($rewrite == 1) {
  1279. $uri .= '/information-id-' . $id;
  1280. } else {
  1281. if ($rewrite == 3) {
  1282. if (empty($dir_typename)) {
  1283. $cat_dir = $cat_dir ? $cat_dir : get_category_dir();
  1284. $dir_typename = $cat_dir[$catid];
  1285. }
  1286. $uri .= '/' . $dir_typename . '/' . $id . '.html';
  1287. } else {
  1288. if (empty($rewrite)) {
  1289. $uri .= '/index.php?mod=information&id=' . $id;
  1290. }
  1291. }
  1292. }
  1293. break;
  1294. case 'about':
  1295. $rewrite = $seo['seo_force_about'] == 'rewrite' ? 1 : 0;
  1296. if (empty($part)) {
  1297. return false;
  1298. } else {
  1299. if ($id) {
  1300. $uri .= $rewrite ? '/' . $part . '-id-' . $id : '/index.php?mod=' . $part . '&amp;id=' . $id;
  1301. } else {
  1302. if (empty($id)) {
  1303. $uri .= $rewrite ? '/' . $part : '/index.php?mod=' . $part;
  1304. }
  1305. }
  1306. }
  1307. break;
  1308. case 'corp':
  1309. $rewrite = $seo['seo_force_yp'] == 'rewrite' ? 1 : 0;
  1310. if ($action == 'index' && empty($catid) && empty($areaid)) {
  1311. $uri .= $rewrite ? '/corporation' : '/index.php?mod=corp';
  1312. } else {
  1313. if (empty($action) && $rewrite) {
  1314. $uri .= '/corporation' . ($catid ? '-catid-' . $catid : '');
  1315. $uri .= $areaid ? '-areaid-' . $areaid : '';
  1316. $uri .= $page ? '-page-' . $page : '';
  1317. } else {
  1318. if (empty($action) && empty($rewrite)) {
  1319. $uri .= '/index.php?mod=corp&catid=' . $catid;
  1320. if ($page) {
  1321. $uri .= '&amp;page=' . $page;
  1322. }
  1323. if ($areaid) {
  1324. $uri .= '&amp;areaid=' . $areaid;
  1325. }
  1326. }
  1327. }
  1328. }
  1329. break;
  1330. case 'goods':
  1331. $rewrite = $seo['seo_force_goods'] == 'rewrite' ? 1 : 0;
  1332. if (empty($catid) && empty($orderby) && empty($id)) {
  1333. $uri .= $rewrite ? '/goods' : '/index.php?mod=goods';
  1334. } else {
  1335. if ($id && empty($catid) && empty($orderby)) {
  1336. $uri .= $rewrite ? '/goods-id-' . $id : '/index.php?mod=goods&id=' . $id;
  1337. } else {
  1338. if ($rewrite) {
  1339. $uri .= '/goods' . ($catid ? '-catid-' . $catid : '');
  1340. $uri .= $orderby ? '-orderby-' . $orderby : '';
  1341. $uri .= $cuxiao ? '-cuxiao-' . $cuxiao : '';
  1342. $uri .= $tuijian ? '-tuijian-' . $tuijian : '';
  1343. $uri .= $page ? '-page-' . $page : '';
  1344. } else {
  1345. if (empty($rewrite)) {
  1346. $uri .= '/index.php?mod=goods' . ($catid ? '&catid=' . $catid : '');
  1347. if ($orderby) {
  1348. $uri .= '&amp;orderby=' . $orderby;
  1349. }
  1350. if ($cuxiao) {
  1351. $uri .= '&amp;cuxiao=' . $cuxiao;
  1352. }
  1353. if ($tuijian) {
  1354. $uri .= '&amp;tuijian=' . $tuijian;
  1355. }
  1356. if ($page) {
  1357. $uri .= '&amp;page=' . $page;
  1358. }
  1359. }
  1360. }
  1361. }
  1362. }
  1363. break;
  1364. case 'news':
  1365. $rewrite = $seo['seo_force_news'] == 'rewrite' ? 1 : 0;
  1366. if ($action == 'index' && empty($catid) && empty($id)) {
  1367. $uri .= $rewrite ? '/news' : '/index.php?mod=news';
  1368. } else {
  1369. if ($id && empty($catid) && empty($action)) {
  1370. $uri .= $rewrite ? '/news-id-' . $id : '/index.php?mod=news&id=' . $id;
  1371. } else {
  1372. if ($catid && $rewrite && empty($id) && empty($action)) {
  1373. $uri .= '/news-catid-' . $catid;
  1374. $uri .= $page ? '-page-' . $page : '';
  1375. } else {
  1376. if ($catid && empty($rewrite) && empty($id) && empty($action)) {
  1377. $uri .= '/index.php?mod=news&catid=' . $catid;
  1378. if ($page) {
  1379. $uri .= '&amp;page=' . $page;
  1380. }
  1381. }
  1382. }
  1383. }
  1384. }
  1385. break;
  1386. case 'space':
  1387. $uri = '/';
  1388. $rewrite = $seo['seo_force_space'] == 'rewrite' && inchinese($user) ? 1 : 0;
  1389. if (empty($user)) {
  1390. return false;
  1391. } else {
  1392. $uri .= $rewrite ? 'space/' . $user . '/' : 'index.php?mod=user&user=' . urlencode($user);
  1393. }
  1394. break;
  1395. case 'store':
  1396. $rewrite = $seo['seo_force_store'] == 'rewrite' ? 1 : 0;
  1397. if (!$part) {
  1398. $part = 'index';
  1399. }
  1400. if (empty($uid)) {
  1401. return false;
  1402. } else {
  1403. if ($uid && $part == 'index' && $rewrite == 1) {
  1404. $uri .= '/store-' . $uid . '/';
  1405. } else {
  1406. if ($uid && $part == 'index' && !$rewrite) {
  1407. $uri .= '/index.php?mod=store&id=' . $uid;
  1408. } else {
  1409. if ($uid && $part && $rewrite == 1) {
  1410. $uri .= '/store-' . $uid . '/' . $part;
  1411. $uri .= $type ? '-type-' . $type : '';
  1412. $uri .= $typeid ? '-typeid-' . $typeid : '';
  1413. $uri .= $id ? '-id-' . $id : '';
  1414. $uri .= $page ? '-page-' . $page : '';
  1415. } else {
  1416. if ($uid && $part && !$rewrite) {
  1417. $uri .= '/index.php?mod=store&id=' . $uid . '&amp;action=' . $part;
  1418. $uri .= $type ? '&amp;type=' . $type : '';
  1419. $uri .= $typeid ? '&amp;typeid=' . $typeid : '';
  1420. $uri .= $id ? '&amp;id=' . $id : '';
  1421. $uri .= $page ? '&amp;page=' . $page : '';
  1422. }
  1423. }
  1424. }
  1425. }
  1426. }
  1427. break;
  1428. default:
  1429. return false;
  1430. break;
  1431. }
  1432. if ($rewrite == 3 && $types == 'category') {
  1433. $uri .= '/';
  1434. } else {
  1435. if (in_array($rewrite, array(1, 2))) {
  1436. $uri .= (empty($part) || $part == 'index') && in_array($types, array('space', 'store')) ? '/' : $part === 'announce' && !empty($id) ? '' : '.html';
  1437. }
  1438. }
  1439. unset($seo);
  1440. unset($rewrite);
  1441. return $uri;
  1442. }
  1443. function inchinese($text)
  1444. {
  1445. return @ereg('^[a-z0-9_.-]+$', $text);
  1446. }
  1447. function get_member_docutype()
  1448. {
  1449. $data = read_static_cache('document_type');
  1450. if ($data === false) {
  1451. $query = $GLOBALS['db']->query('SELECT * FROM `' . $GLOBALS['db_mymps'] . 'member_docutype` WHERE ifview = 2 ORDER BY displayorder,typeid DESC');
  1452. while ($row = $GLOBALS['db']->fetchRow($query)) {
  1453. $res[$row['typeid']]['typeid'] = $row['typeid'];
  1454. $res[$row['typeid']]['typename'] = $row['typename'];
  1455. $res[$row['typeid']]['arrid'] = $row['arrid'];
  1456. }
  1457. write_static_cache('document_type', $res);
  1458. } else {
  1459. $res = $data;
  1460. }
  1461. return $res;
  1462. }
  1463. function mymps_get_lifebox($num = '12')
  1464. {
  1465. global $db;
  1466. global $db_mymps;
  1467. $query = $db->query('SELECT * FROM `' . $db_mymps . 'lifebox` WHERE if_view = 2 ORDER BY displayorder DESC LIMIT 0,' . $num);
  1468. while ($row = $db->fetchRow($query)) {
  1469. $list[$row['id']]['id'] = $row['id'];
  1470. $list[$row['id']]['lifename'] = $row['lifename'];
  1471. $list[$row['id']]['lifeurl'] = $row['lifeurl'];
  1472. }
  1473. return $list;
  1474. }
  1475. function mymps_get_links($ifindex = 2, $catid = 0)
  1476. {
  1477. global $db;
  1478. global $db_mymps;
  1479. global $mymps_global;
  1480. static $links;
  1481. $data = read_static_cache('friendlink');
  1482. if ($data === false) {
  1483. $sql = 'SELECT weblogo, webname, url FROM `' . $db_mymps . 'flink` WHERE ischeck = \'2\' AND ifindex = \'2\' ORDER BY ordernumber ASC';
  1484. $res = $db->getAll($sql);
  1485. $links['index']['img'] = $links['index']['txt'] = array();
  1486. $i = 0;
  1487. foreach ($res as $row) {
  1488. if (!empty($row['weblogo'])) {
  1489. $i++;
  1490. $links['index']['img'][] = array('name' => $row['webname'], 'url' => $row['url'], 'logo' => $row['weblogo']);
  1491. } else {
  1492. $links['index']['txt'][] = array('name' => $row['webname'], 'url' => $row['url']);
  1493. }
  1494. }
  1495. if ($i == 0) {
  1496. $links['index']['img'] = '';
  1497. }
  1498. $sql = 'SELECT id,webname,url,catid FROM `' . $db_mymps . 'flink` WHERE ischeck = \'2\' AND catid > 0 ORDER BY ordernumber ASC';
  1499. $query = $db->query($sql);
  1500. while ($row = $db->fetchRow($query)) {
  1501. $links[$row['catid']][$row['id']]['name'] = $row['webname'];
  1502. $links[$row['catid']][$row['id']]['url'] = $row['url'];
  1503. }
  1504. write_static_cache('friendlink', $links);
  1505. } else {
  1506. $links = $data;
  1507. }
  1508. return $ifindex == 2 ? $links['index'] : $links[$catid];
  1509. }
  1510. function mymps_get_announce($num = '12')
  1511. {
  1512. global $db;
  1513. global $db_mymps;
  1514. global $timestamp;
  1515. $query = $db->query('SELECT * FROM `' . $db_mymps . 'announce` WHERE begintime<\'' . $timestamp . '\' AND (endtime=\'0\' OR endtime>\'' . $timestamp . '\') ORDER BY id DESC LIMIT 0,' . $num);
  1516. while ($row = $db->fetchRow($query)) {
  1517. $list[$row['id']]['id'] = $row['id'];
  1518. $list[$row['id']]['title'] = $row['title'];
  1519. $list[$row['id']]['pubdate'] = $row['pubdate'];
  1520. $list[$row['id']]['begintime'] = $row['begintime'];
  1521. $list[$row['id']]['endtime'] = $row['endtime'];
  1522. $list[$row['id']]['titlecolor'] = $row['titlecolor'];
  1523. $list[$row['id']]['author'] = $row['author'];
  1524. $list[$row['id']]['content'] = $row['content'];
  1525. $list[$row['id']]['uri'] = $row['redirecturl'] ? $row['redirecturl'] : rewrite('about', array('part' => 'announce', 'id' => $row['id'], 'html_path' => '/announce/index' . $seo['seo_htmlext'] . '#' . $row['id']));
  1526. }
  1527. return $list;
  1528. }
  1529. function mymps_get_telephone($num = '20')
  1530. {
  1531. global $db;
  1532. global $db_mymps;
  1533. $query = $db->query('SELECT * FROM `' . $db_mymps . 'telephone` WHERE if_view = 2 ORDER BY displayorder DESC LIMIT 0,' . $num);
  1534. while ($row = $db->fetchRow($query)) {
  1535. $list[$row['id']]['telname'] = $row['telname'];
  1536. $list[$row['id']]['telnumber'] = $row['telnumber'];
  1537. $list[$row['id']]['if_bold'] = $row['if_bold'];
  1538. $list[$row['id']]['color'] = $row['color'];
  1539. }
  1540. return $list;
  1541. }
  1542. function get_member_docunav()
  1543. {
  1544. $data = get_member_docutype();
  1545. foreach ($data as $key => $value) {
  1546. $docu[$value['typeid']]['typename'] = $value['typename'];
  1547. $docu[$value['typeid']]['typeid'] = $value['typeid'];
  1548. $docu[$value['typeid']]['uri'] = rewrite('store', array('uid' => $GLOBALS['uid'], 'part' => 'document', 'typeid' => $value['typeid']));
  1549. }
  1550. return $docu;
  1551. }
  1552. function get_seoset()
  1553. {
  1554. $data = read_static_cache('seoset');
  1555. if ($data === false) {
  1556. $query = $GLOBALS['db']->query('SELECT description,value FROM `' . $GLOBALS['db_mymps'] . 'config` WHERE type = \'seo\'');
  1557. while ($row = $GLOBALS['db']->fetchRow($query)) {
  1558. $res[$row['description']] = $row['value'];
  1559. }
  1560. write_static_cache('seoset', $res);
  1561. } else {
  1562. $res = $data;
  1563. }
  1564. return $res;
  1565. }
  1566. function mayi($agree_domain)
  1567. {
  1568. if (empty($HTTP_HOST)) {
  1569. if (myget('HTTP_HOST')) {
  1570. $HTTP_HOST = myget('HTTP_HOST');
  1571. } else {
  1572. $HTTP_HOST = '';
  1573. }
  1574. }
  1575. $agree_domain = '.127.0.0.1,mayicms.com,mymps.com.cn,' . $agree_domain;
  1576. $now_domain = getRd(htmlspecialchars($HTTP_HOST));
  1577. $now_domain = str_replace(array('.www.', '.cn.'), array('', ''), $now_domain);
  1578. if (!in_array($now_domain, explode(',', $agree_domain))) {
  1579. exit;
  1580. }
  1581. }
  1582. function myget($var_name)
  1583. {
  1584. if (isset($_SERVER[$var_name])) {
  1585. return $_SERVER[$var_name];
  1586. }
  1587. if (isset($_ENV[$var_name])) {
  1588. return $_ENV[$var_name];
  1589. }
  1590. if (getenv($var_name)) {
  1591. return getenv($var_name);
  1592. }
  1593. if (function_exists('apache_getenv') && apache_getenv($var_name, true)) {
  1594. return apache_getenv($var_name, true);
  1595. }
  1596. return '';
  1597. }
  1598. function getRd($domain)
  1599. {
  1600. $suffix = array('ren', 'wang', 'ae', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'as', 'at', 'au', 'aw', 'az', 'ba', 'bb', 'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'bj', 'bm', 'bn', 'bo', 'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cc', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'cq', 'cr', 'cu', 'cv', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do', 'dz', 'ec', 'ee', 'eg', 'eh', 'es', 'et', 'ev', 'fi', 'fj', 'fk', 'fm', 'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg', 'gh', 'gi', 'gl', 'gm', 'gn', 'gp', 'gr', 'gt', 'gu', 'gw', 'gy', 'hk', 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'in', 'io', 'iq', 'ir', 'is', 'it', 'jm', 'jo', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp', 'kr', 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt', 'lu', 'lv', 'ly', 'ma', 'mc', 'md', 'mg', 'mh', 'ml', 'mm', 'mn', 'mo', 'mp', 'mq', 'mr', 'ms', 'mt', 'mv', 'mw', 'mx', 'my', 'mz', 'na', 'nc', 'ne', 'nf', 'ng', 'ni', 'nl', 'no', 'np', 'nr', 'nt', 'nu', 'nz', 'om', 'qa', 'pa', 'pe', 'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'pt', 'pw', 'py', 're', 'ro', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl', 'sm', 'sn', 'so', 'sr', 'st', 'su', 'sy', 'sz', 'tc', 'td', 'tf', 'tg', 'th', 'tj', 'tk', 'tm', 'tn', 'to', 'tp', 'tr', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'us', 'uy', 'va', 'vc', 've', 'vg', 'vn', 'vu', 'wf', 'ws', 'ye', 'yu', 'za', 'zm', 'zr', 'zw', 'com', 'edu', 'gov', 'int', 'mil', 'net', 'org');
  1601. $domainArr = explode('.', $domain);
  1602. $l = count($domainArr);
  1603. $key = 0;
  1604. for ($i = 0; $i < $l; $i++) {
  1605. if (in_array($domainArr[$i], $suffix)) {
  1606. $key = $i;
  1607. break;
  1608. }
  1609. }
  1610. $inSuffixs = '';
  1611. for ($i = $key; $i < $l; $i++) {
  1612. $inSuffixs .= '.' . $domainArr[$i];
  1613. }
  1614. return $domainArr[$key - 1] . $inSuffixs;
  1615. }
  1616. function get_location($type = 'category', $cat = 0, $str = '', $extra = '', $pdetail = '')
  1617. {
  1618. global $seo;
  1619. global $pluginsettings;
  1620. global $mymps_global;
  1621. $raquo = $mymps_global['cfg_raquo'];
  1622. $mymps_global['SiteCity'] = $mymps_global['SiteCity'] && !in_array($type, array('channel', 'news')) ? $mymps_global['SiteCity'] : '';
  1623. if (!$seo) {
  1624. $seo = get_seoset();
  1625. }
  1626. $location = '当前位置:<a href="' . $mymps_global['SiteUrl'] . '">' . $GLOBALS['mymps_global']['SiteName'] . '</a>';
  1627. if ($type == 'news') {
  1628. $page_title = $pluginsettings['news']['seotitle'] ? $pluginsettings['news']['seotitle'] : $mymps_global['SiteName'];
  1629. } else {
  1630. $page_title = $mymps_global['SiteName'];
  1631. }
  1632. if ($seo['seo_sitename'] && $type == 'index' && empty($cat) && empty($str)) {
  1633. $page_title = $page_title . '-' . $seo['seo_sitename'];
  1634. }
  1635. if (in_array($type, array('category', 'channel', 'corp', 'news'))) {
  1636. if (0 < $cat) {
  1637. $cat_arr = get_parent_cats($type, $cat);
  1638. } else {
  1639. $cat_arr = array();
  1640. }
  1641. if ($type == 'channel') {
  1642. $location .= ' <code>' . $raquo . '</code> <a href="' . rewrite('news', array('action' => 'index', 'html_path' => $seo['seo_htmldir'] . $seo['seo_htmlnewsdir'] . '/')) . '">热点资讯</a>';
  1643. $page_title = '热点资讯-' . $page_title;
  1644. } else {
  1645. if ($type == 'corp') {
  1646. $location .= ' <code>' . $raquo . '</code> <a href="' . rewrite('corp', array('action' => 'index')) . '">商家</a>';
  1647. $page_title = '商家-' . $page_title;
  1648. }
  1649. }
  1650. if (!empty($cat_arr)) {
  1651. krsort($cat_arr);
  1652. foreach ($cat_arr as $val) {
  1653. $page_title = mhtmlspecialchars($GLOBALS['cat']['title'] && $GLOBALS['catid'] == $val['catid'] ? $GLOBALS['cat']['title'] : ($type == 'corp' ? $val['corpname'] : $val['catname'])) . '-' . $page_title;
  1654. $location .= ' <code> ' . $raquo . ' </code> <a href="' . $val['uri'] . '">' . mhtmlspecialchars($type == 'corp' ? $val['corpname'] : $mymps_global['SiteCity'] . $val['catname']) . '</a>';
  1655. }
  1656. }
  1657. $page_title = $extra ? $extra . $page_title : $page_title;
  1658. $page_title = $mymps_global['SiteCity'] . $page_title;
  1659. }
  1660. if (!empty($str)) {
  1661. $page_title = $str . ($type == 'space' ? '的个人空间' : '') . '-' . $page_title;
  1662. $location .= ' <code>' . $raquo . '</code> &nbsp;' . $str . ($type == 'space' ? '的个人空间' : '');
  1663. }
  1664. $page_title = $pdetail ? $pdetail : $page_title;
  1665. $cur = array('page_title' => $page_title, 'location' => $location);
  1666. unset($page_title);
  1667. unset($cat);
  1668. unset($location);
  1669. unset($type);
  1670. return $cur;
  1671. }
  1672. function get_location_m($type = 'category', $cat = 0, $str = '', $extra = '', $pdetail = '')
  1673. {
  1674. global $seo;
  1675. global $pluginsettings;
  1676. global $mymps_global;
  1677. $mymps_global['SiteCity'] = $mymps_global['SiteCity'] && !in_array($type, array('channel', 'news', 'goods')) ? $mymps_global['SiteCity'] : '';
  1678. if (!$seo) {
  1679. $seo = get_seoset();
  1680. }
  1681. if ($type == 'news') {
  1682. $page_title = $pluginsettings['news']['seotitle'] ? $pluginsettings['news']['seotitle'] : $mymps_global['SiteName'];
  1683. } else {
  1684. $page_title = $mymps_global['SiteName'];
  1685. }
  1686. if ($seo['seo_sitename'] && $type == 'index' && empty($cat) && empty($str)) {
  1687. $page_title = $page_title . '-' . $seo['seo_sitename'];
  1688. }
  1689. if (in_array($type, array('category', 'channel', 'corp', 'news'))) {
  1690. if (0 < $cat) {
  1691. $cat_arr = get_parent_cats($type, $cat);
  1692. } else {
  1693. $cat_arr = array();
  1694. }
  1695. if ($type == 'channel') {
  1696. $page_title = '热点资讯-' . $page_title;
  1697. } else {
  1698. if ($type == 'goods') {
  1699. $page_title = '商品展示-' . $page_title;
  1700. }
  1701. }
  1702. if (!empty($cat_arr)) {
  1703. krsort($cat_arr);
  1704. foreach ($cat_arr as $val) {
  1705. $page_title = mhtmlspecialchars($GLOBALS['cat']['title'] && $GLOBALS['catid'] == $val['catid'] ? $GLOBALS['cat']['title'] : ($type == 'corp' ? $val['corpname'] : $val['catname'])) . '-' . $page_title;
  1706. }
  1707. }
  1708. $page_title = $extra ? $extra . $page_title : $page_title;
  1709. $page_title = $mymps_global['SiteCity'] . $page_title;
  1710. } else {
  1711. if ($type == 'goods') {
  1712. $cat_arr = goods_parent_cats($catid);
  1713. $page_title = $pluginsettings['goods']['seotitle'] ? $pluginsettings['goods']['seotitle'] : $mymps_global['SiteCity'] . '商品展示-' . $GLOBALS['mymps_global']['SiteName'];
  1714. if (!empty($catid)) {
  1715. if (!empty($cat_arr)) {
  1716. krsort($cat_arr);
  1717. foreach ($cat_arr as $val) {
  1718. $page_title = $val['catname'] . '-' . $page_title;
  1719. }
  1720. }
  1721. }
  1722. }
  1723. }
  1724. if (!empty($str)) {
  1725. $page_title = $str . ($type == 'space' ? '的个人空间' : '') . '-' . $page_title;
  1726. }
  1727. $page_title = $pdetail ? $pdetail : $page_title;
  1728. $cur = array('page_title' => $page_title, 'location' => $location);
  1729. unset($page_title);
  1730. unset($cat);
  1731. unset($location);
  1732. unset($type);
  1733. return $cur;
  1734. }
  1735. function get_areaname($areaid)
  1736. {
  1737. global $db;
  1738. global $db_mymps;
  1739. $data = read_static_cache('area_option_static');
  1740. return $data[$areaid]['areaname'] ? $data[$areaid]['areaname'] : $db->getOne('SELECT areaname FROM `' . $db_mymps . 'area` WHERE areaid = \'' . $areaid . '\'');
  1741. }
  1742. function get_upload_image_view($if_upimg = 1, $infoid = '', $number = '')
  1743. {
  1744. global $mymps_global;
  1745. global $db;
  1746. global $db_mymps;
  1747. if ($if_upimg == 1) {
  1748. $cfg_upimg_number = $number ? $number : ($mymps_global['cfg_upimg_number'] ? $mymps_global['cfg_upimg_number'] : 4);
  1749. $mymps = '<script type="text/javascript">$(function () {';
  1750. for ($i = 0; $i < $cfg_upimg_number; $i++) {
  1751. $mymps .= '$("#mymps_img_' . $i . '").uploadPreview({ Img: "ImgPr' . $i . '", Width: 108, Height: 108, MaxSize:' . $mymps_global['cfg_upimg_size'] . ' });';
  1752. }
  1753. $mymps .= '});</script>';
  1754. for ($i = 0; $i < $cfg_upimg_number; $i++) {
  1755. $mymps .= '<div class="onea_dd">' . "\r\n" . ' <div class="viewarea"><img id="ImgPr' . $i . '" src="' . $mymps_global['SiteUrl'] . '/template/default/images/post/defaultimg.gif"/></div>' . "\r\n\t\t\t\t\t" . '<div class="clearfix"></div>' . "\r\n\t\t\t\t\t" . '<div class="a_ddarea">' . "\r\n" . ' <input type="file" name="mymps_img_' . $i . '" id="mymps_img_' . $i . '" class="comment-pic-upd" />' . "\r\n" . ' <img src="' . $mymps_global['SiteUrl'] . '/template/default/images/post/addimg.gif" alt="上传照片" title="上传图片">' . "\r\n" . ' </div>' . "\r\n" . ' </div>';
  1756. }
  1757. }
  1758. return $mymps;
  1759. }
  1760. function get_upload_image_edit($if_upimg = 1, $infoid, $number = '')
  1761. {
  1762. global $mymps_global;
  1763. global $db;
  1764. global $db_mymps;
  1765. if (empty($infoid)) {
  1766. return '';
  1767. }
  1768. if ($if_upimg == 1) {
  1769. $cfg_upimg_number = $number ? $number : ($mymps_global['cfg_upimg_number'] ? $mymps_global['cfg_upimg_number'] : 4);
  1770. $imagei = array();
  1771. $view = $db->getAll('SELECT image_id,prepath FROM `' . $db_mymps . 'info_img` WHERE infoid = \'' . $infoid . '\'');
  1772. foreach ($view as $k => $v) {
  1773. $imagei[$v['image_id']] = $mymps_global['SiteUrl'] . $v['prepath'];
  1774. }
  1775. $mymps = '<script type="text/javascript">$(function () {';
  1776. for ($i = 0; $i < $cfg_upimg_number; $i++) {
  1777. $mymps .= '$("#mymps_img_' . $i . '").uploadPreview({ Img: "ImgPr' . $i . '", Width: 108, Height: 108, MaxSize:' . $mymps_global['cfg_upimg_size'] . ' });';
  1778. }
  1779. $mymps .= '});</script>';
  1780. for ($i = 0; $i < $cfg_upimg_number; $i++) {
  1781. $mymps .= "\r\n\t\t\t\t" . '<div class="onea_dd">' . "\r\n" . ' <div class="viewarea"><img id="ImgPr' . $i . '" src="' . ($imagei[$i] ? $imagei[$i] : $mymps_global['SiteUrl'] . '/template/default/images/post/defaultimg.gif') . '"/></div>' . "\r\n\t\t\t\t\t" . '<div class="clearfix"></div>' . "\r\n\t\t\t\t\t" . '<div class="a_ddarea">' . "\r\n" . ' <input type="file" name="mymps_img_' . $i . '" id="mymps_img_' . $i . '" class="comment-pic-upd" />' . "\r\n" . ' <img src="' . $mymps_global['SiteUrl'] . '/template/default/images/post/addimg.gif" alt="上传照片" title="上传图片">' . "\r\n" . ' </div>';
  1782. $mymps .= $imagei[$i] ? '<div class="clearfix"></div><div style="text-align:center; font-weight:100; color:#000; font-size:12px; line-height:22px"><label for="label' . $i . '"><input id="label' . $i . '" name="delinfoimg[' . $i . ']" type="checkbox" class="checkbox"><font>删?</font></label></div>' : '';
  1783. $mymps .= '</div>';
  1784. }
  1785. $mymps .= '</td></tr>';
  1786. }
  1787. return $mymps;
  1788. }
  1789. function arraychange($oldarray)
  1790. {
  1791. $oldarray = explode("\r\n", $oldarray);
  1792. $new_array = array();
  1793. foreach ($oldarray as $t) {
  1794. $t = explode('=', $t);
  1795. if (!isset($new_array[$t[0]])) {
  1796. $new_array[$t[0]] = $t[1];
  1797. }
  1798. }
  1799. return $new_array;
  1800. }
  1801. function get_format_time($time)
  1802. {
  1803. global $timestamp;
  1804. $limit = ($timestamp ? $timestamp : time()) - $time;
  1805. if ($limit < 60) {
  1806. $strTime = $limit . '秒钟前';
  1807. } else {
  1808. if ($limit / 60 < 60) {
  1809. $strTime = floor($limit / 60) . '分钟前';
  1810. } else {
  1811. if ($limit / 60 / 60 < 24) {
  1812. $strTime = floor($limit / 60 / 60) . '小时前';
  1813. } else {
  1814. if (24 < $limit / 60 / 60 && $limit / 60 / 60 < 48) {
  1815. $strTime = '昨天' . date('H:i', $time);
  1816. } else {
  1817. if (2 < $limit / 60 / 60 / 24 && $limit / 60 / 60 / 24 < 3) {
  1818. $strTime = '前天' . date('H:i', $time);
  1819. } else {
  1820. if ($limit / 60 / 60 / 24 < 7) {
  1821. $strTime = floor($limit / 60 / 60 / 24) . '天前';
  1822. } else {
  1823. $strTime = date('m-d H:i:s', $time);
  1824. }
  1825. }
  1826. }
  1827. }
  1828. }
  1829. }
  1830. return $strTime;
  1831. }
  1832. function replace_html_style($html = '', $id = '')
  1833. {
  1834. $random = rand();
  1835. $year = date('Y', time());
  1836. $month = date('m', time());
  1837. $day = date('d', time());
  1838. $time = time();
  1839. return preg_replace('/\\{([0-9a-zA-Z]+)\\}/e', '$$1', $html);
  1840. }
  1841. function clearcookies()
  1842. {
  1843. global $s_uid;
  1844. global $admin_id;
  1845. foreach (array('s_uid', 'admin_id') as $k) {
  1846. msetcookie($k);
  1847. }
  1848. $s_uid = $admin_id = $credits = '';
  1849. }
  1850. function submit_check($var, $allowget = 0)
  1851. {
  1852. if ($allowget || $_SERVER['REQUEST_METHOD'] == 'POST' && (empty($_SERVER['HTTP_REFERER']) || preg_replace('/https?:\\/\\/([^\\:\\/]+).*/i', '\\1', $_SERVER['HTTP_REFERER']) == preg_replace('/([^\\:]+).*/', '\\1', $_SERVER['HTTP_HOST']))) {
  1853. return true;
  1854. } else {
  1855. return false;
  1856. }
  1857. }
  1858. function get_sex_option($cursex = '')
  1859. {
  1860. foreach (array('男', '女') as $key) {
  1861. $mymps .= '<option value=' . $key;
  1862. $mymps .= $cursex == $key ? ' style = "background-color:#6EB00C;color:white" selected>' : '>';
  1863. $mymps .= $key . '</option>';
  1864. }
  1865. return $mymps;
  1866. }
  1867. function get_memtpl_options($opt = '')
  1868. {
  1869. $option = $GLOBALS['db']->getAll('SELECT * FROM `' . $GLOBALS['db_mymps'] . 'member_tpl` WHERE if_view = \'2\' ORDER BY displayorder ASC');
  1870. foreach ($option as $key => $v) {
  1871. $mymps .= '<option value=' . $v[tpl_path];
  1872. if (is_array($opt)) {
  1873. $mymps .= in_array($v[tpl_path], $opt) ? ' style = "background-color:#6EB00C;color:white" selected>' : '>';
  1874. } else {
  1875. $mymps .= $opt == $v[tpl_path] ? ' style = "background-color:#6EB00C;color:white" selected>' : '>';
  1876. }
  1877. $mymps .= $v[tpl_name] . '</option>';
  1878. }
  1879. return $mymps;
  1880. }
  1881. function get_htmlpath_type($dir_type, $typename, $id, $mydir)
  1882. {
  1883. if ($dir_type == 1) {
  1884. $html_path = $id;
  1885. } else {
  1886. if ($dir_type == 2) {
  1887. $html_path = GetPinyin($typename);
  1888. } else {
  1889. if ($dir_type == 3) {
  1890. $html_path = GetPinyin($typename, 1);
  1891. } else {
  1892. if ($dir_type == 4) {
  1893. !$mydir && write_msg('请填写自定义栏目名!');
  1894. $html_path = $mydir;
  1895. } else {
  1896. $html_path = false;
  1897. }
  1898. }
  1899. }
  1900. }
  1901. return $html_path;
  1902. }
  1903. function create_in($item_list, $field = '')
  1904. {
  1905. if (empty($item_list)) {
  1906. return $field . ' IN (\'\') ';
  1907. } else {
  1908. if (!is_array($item_list)) {
  1909. $item_list = explode(',', $item_list);
  1910. }
  1911. $item_list = array_unique($item_list);
  1912. $item_list_tmp = '';
  1913. foreach ($item_list as $item) {
  1914. if ($item !== '') {
  1915. $item_list_tmp .= $item_list_tmp ? ',\'' . $item . '\'' : '\'' . $item . '\'';
  1916. }
  1917. }
  1918. if (empty($item_list_tmp)) {
  1919. return $field . ' IN (\'\') ';
  1920. } else {
  1921. return $field . ' IN (' . $item_list_tmp . ') ';
  1922. }
  1923. }
  1924. }
  1925. function GetInfoPostTime($posttime = '', $formname = 'posttime')
  1926. {
  1927. global $info_posttime;
  1928. $info_posttime_form = '<select name=\'' . $formname . '\' id=\'' . $formname . '\'>';
  1929. foreach ($info_posttime as $k => $v) {
  1930. if ($k == $posttime) {
  1931. $info_posttime_form .= '<option value=\'' . $k . '\' selected>' . $v . '</option>' . "\r\n";
  1932. } else {
  1933. $info_posttime_form .= '<option value=\'' . $k . '\'>' . $v . '</option>' . "\r\n";
  1934. }
  1935. }
  1936. $info_posttime_form .= '</select>' . "\r\n";
  1937. return $info_posttime_form;
  1938. }
  1939. function mymps_global_header()
  1940. {
  1941. global $charset;
  1942. global $mymps_global;
  1943. return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\r\n" . '<html xmlns="http://www.w3.org/1999/xhtml">' . "\r\n" . '<head>' . "\r\n" . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8' . $charset . '" />' . "\r\n" . '<meta http-equiv="Content-Language" content="zh-CN"/>' . "\r\n" . '<meta name="generator" content="' . MPS_SOFTNAME . MPS_VERSION . '"/>' . "\r\n" . '<meta name="author" content="' . MPS_SOFTNAME . ' DevTeam Corporation" />' . "\r\n" . '<link rel="shortcut icon" href="' . $mymps_global[SiteUrl] . '/favicon.ico" />';
  1944. }
  1945. function HighLight($str, $keywords, $color = 'red')
  1946. {
  1947. if (empty($keywords)) {
  1948. return $str;
  1949. exit;
  1950. } else {
  1951. if (is_array($keywords) && $str) {
  1952. foreach ($keywords as $k => $v) {
  1953. $str = @preg_replace('/' . $v . '/i', '<font color=' . $color . '>' . $v . '</font>', $str);
  1954. }
  1955. } else {
  1956. if ($str) {
  1957. $str = @preg_replace('/' . $keywords . '/i', '<font color=' . $color . '>' . $keywords . '</font>', $str);
  1958. }
  1959. }
  1960. }
  1961. return $str;
  1962. }
  1963. function convertip_tiny($ip, $ipdatafile)
  1964. {
  1965. static $fp;
  1966. static $offset = array();
  1967. static $index;
  1968. $ipdot = explode('.', $ip);
  1969. $ip = pack('N', ip2long($ip));
  1970. $ipdot[0] = (int) $ipdot[0];
  1971. $ipdot[1] = (int) $ipdot[1];
  1972. if ($fp === NULL && ($fp = @fopen($ipdatafile, 'rb'))) {
  1973. $offset = unpack('Nlen', fread($fp, 4));
  1974. $index = fread($fp, $offset['len'] - 4);
  1975. } else {
  1976. if ($fp == false) {
  1977. return '- Invalid IP data file';
  1978. }
  1979. }
  1980. $length = $offset['len'] - 1028;
  1981. $start = unpack('Vlen', $index[$ipdot[0] * 4] . $index[$ipdot[0] * 4 + 1] . $index[$ipdot[0] * 4 + 2] . $index[$ipdot[0] * 4 + 3]);
  1982. for ($start = $start['len'] * 8 + 1024; $start < $length; $start += 8) {
  1983. if ($ip <= $index[$start] . $index[$start + 1] . $index[$start + 2] . $index[$start + 3]) {
  1984. $index_offset = unpack('Vlen', $index[$start + 4] . $index[$start + 5] . $index[$start + 6] . "\0");
  1985. $index_length = unpack('Clen', $index[$start + 7]);
  1986. break;
  1987. }
  1988. }
  1989. fseek($fp, $offset['len'] + $index_offset['len'] - 1024);
  1990. if ($index_length['len']) {
  1991. return fread($fp, $index_length['len']);
  1992. } else {
  1993. return '- Unknown';
  1994. }
  1995. }
  1996. function ip2area($ip = '')
  1997. {
  1998. global $charset;
  1999. global $mymps_global;
  2000. if (empty($ip) || $ip == '127.0.0.1') {
  2001. return '';
  2002. } else {
  2003. $ip2 = @file_get_contents('http://api.map.baidu.com/location/ip?ak=' . $mymps_global['mapkey'] . '&ip=' . $ip);
  2004. $ip2 = json_decode($ip2);
  2005. $data = array();
  2006. $data['province'] = $ip2->content->address_detail->province;
  2007. $data['city'] = $ip2->content->address_detail->city;
  2008. $data['district'] = $ip2->content->address_detail->district;
  2009. $data['street'] = $ip2->content->address_detail->street;
  2010. $data['province'] = $charset == 'gbk' && $data['province'] ? iconv('UTF-8', 'GBK', $data['province']) : $data['province'];
  2011. $data['city'] = $charset == 'gbk' && $data['city'] ? iconv('UTF-8', 'GBK', $data['city']) : $data['city'];
  2012. $data['district'] = $charset == 'gbk' && $data['district'] ? iconv('UTF-8', 'GBK', $data['district']) : $data['district'];
  2013. $data['street'] = $charset == 'gbk' && $data['street'] ? iconv('UTF-8', 'GBK', $data['street']) : $data['street'];
  2014. return $data['province'] . $data['city'] . $data['district'];
  2015. }
  2016. }
  2017. function filter_bad_words($cfg_badwords, $str)
  2018. {
  2019. $cfg_bwords = explode(',', $cfg_badwords[0]);
  2020. foreach ($cfg_bwords as $i) {
  2021. $str = str_replace($cfg_bwords, $cfg_badwords[1], $str);
  2022. }
  2023. return $str;
  2024. }
  2025. function verify_badwords_filter($ifopenname, $title = '', $content = '')
  2026. {
  2027. global $mymps_global;
  2028. static $res;
  2029. $title = $title ? mhtmlspecialchars(trim($title)) : '';
  2030. $content = $content ? trim($content) : '';
  2031. if ($res === NULL) {
  2032. $data = read_static_cache('badwords');
  2033. if ($data === false) {
  2034. $query = $GLOBALS['db']->query('SELECT words,view,ifcheck FROM `' . $GLOBALS['db_mymps'] . 'badwords`');
  2035. while ($row = $GLOBALS['db']->fetchRow($query)) {
  2036. $cfg_badwords[0] = $row['words'];
  2037. $cfg_badwords[1] = $row['view'];
  2038. $cfg_badwords[2] = $row['ifcheck'];
  2039. }
  2040. write_static_cache('badwords', $cfg_badwords);
  2041. } else {
  2042. $cfg_badwords = $data;
  2043. }
  2044. }
  2045. if ($ifopenname == 1) {
  2046. $info_level = 0;
  2047. if (is_array($cfg_badwords)) {
  2048. $title = $title ? sphtml2text(filter_bad_words($cfg_badwords, $title)) : '';
  2049. $content = $content ? filter_bad_words($cfg_badwords, $content) : '';
  2050. }
  2051. } else {
  2052. if (is_array($cfg_badwords)) {
  2053. if ($cfg_badwords[0] && $cfg_badwords[2] == 1) {
  2054. foreach (explode(',', $cfg_badwords[0]) as $k => $v) {
  2055. if (strstr($title, $v) || strstr($content, $v)) {
  2056. $info_level = 0;
  2057. $title = @str_replace($v, $cfg_badwords[1], $title);
  2058. $content = @str_replace($v, $cfg_badwords[1], $content);
  2059. break;
  2060. } else {
  2061. $info_level = 1;
  2062. }
  2063. }
  2064. } else {
  2065. if ($cfg_badwords[2] == 0) {
  2066. $title = sphtml2text(filter_bad_words($cfg_badwords, $title));
  2067. $content = filter_bad_words($cfg_badwords, $content);
  2068. $info_level = 1;
  2069. } else {
  2070. $info_level = 1;
  2071. }
  2072. }
  2073. } else {
  2074. $info_level = 1;
  2075. }
  2076. }
  2077. $verified_result = array();
  2078. $verified_result['title'] = $title;
  2079. $verified_result['content'] = $content;
  2080. $verified_result['level'] = $info_level;
  2081. return $verified_result;
  2082. }
  2083. function get_info_option_array()
  2084. {
  2085. global $db;
  2086. global $db_mymps;
  2087. $data = read_static_cache('info_typeoptions');
  2088. if ($data === false) {
  2089. $query = $db->query('SELECT title,identifier,rules,type FROM `' . $db_mymps . 'info_typeoptions` WHERE classid >0 ORDER BY displayorder DESC');
  2090. while ($row = $db->fetchRow($query)) {
  2091. $mymps[$row['identifier']]['title'] = $row['title'];
  2092. $mymps[$row['identifier']]['rules'] = $row['rules'];
  2093. $mymps[$row['identifier']]['type'] = $row['type'];
  2094. }
  2095. write_static_cache('info_typeoptions', $mymps);
  2096. } else {
  2097. $mymps = $data;
  2098. }
  2099. return $mymps;
  2100. }
  2101. function get_info_option_titval($option, $value, $class = 'mayi')
  2102. {
  2103. global $charset;
  2104. if (!is_array($option) || empty($option)) {
  2105. return array();
  2106. } else {
  2107. if ($option['type'] == 'radio' || $option['type'] == 'select') {
  2108. $tmp = $charset == 'utf-8' ? utf8_unserialize($option['rules']) : unserialize($option['rules']);
  2109. $new_array = arraychange($tmp['choices']);
  2110. $new_value = $new_array[$value];
  2111. $value = $new_value;
  2112. } else {
  2113. if ($option['type'] == 'checkbox') {
  2114. $value = explode(',', $value);
  2115. $tmp = $charset == 'utf-8' ? utf8_unserialize($option['rules']) : unserialize($option['rules']);
  2116. foreach ($value as $m => $n) {
  2117. $new_array = arraychange($tmp[choices]);
  2118. $nvalue .= '<font class=' . $class . '>' . $new_array[$n] . '</font>';
  2119. }
  2120. $value = $nvalue;
  2121. } else {
  2122. $rules = $charset == 'utf-8' ? utf8_unserialize($option['rules']) : unserialize($option['rules']);
  2123. $value = $value . $rules['units'];
  2124. }
  2125. }
  2126. return array('title' => $option['title'], 'value' => $value);
  2127. }
  2128. }
  2129. function clear_mirror($str)
  2130. {
  2131. $str = str_replace('-', '', $str);
  2132. $str = str_replace('+', '', $str);
  2133. return $str;
  2134. }
  2135. function part_ip($ip)
  2136. {
  2137. return preg_replace('/((?:\\d+\\.){3})\\d+/', '\\1*', $ip);
  2138. }
  2139. function part_tel($num)
  2140. {
  2141. return substr_replace($num, '****', 7, 4);
  2142. }
  2143. function ajax_output($ajax_content)
  2144. {
  2145. global $charset;
  2146. @header('Expires: -1');
  2147. @header('Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0', false);
  2148. @header('Pragma: no-cache');
  2149. @header('Content-Type: text/xml');
  2150. $mymps .= '<?xml version="1.0" encoding="' . ($charset == 'gb2312' ? 'gbk' : 'utf-8') . '"?><root><![CDATA[';
  2151. $mymps .= $ajax_content;
  2152. $mymps .= ']]></root>';
  2153. return $mymps;
  2154. }
  2155. function allow_identifier()
  2156. {
  2157. $data = read_static_cache('mod_search_identifier');
  2158. if ($data === false) {
  2159. require_once MYMPS_DATA . '/info.type.inc.php';
  2160. $query = $GLOBALS['db']->query('SELECT id,options FROM `' . $GLOBALS['db_mymps'] . 'info_typemodels` ORDER BY displayorder DESC');
  2161. while ($row = $GLOBALS['db']->fetchRow($query)) {
  2162. $option = explode(',', $row[options]);
  2163. foreach ($option as $w => $u) {
  2164. $newrow = $GLOBALS['db']->getRow('SELECT identifier,search FROM `' . $GLOBALS['db_mymps'] . 'info_typeoptions` WHERE optionid=\'' . $u . '\'');
  2165. if ($newrow['search'] == 'on') {
  2166. $arr[$row[id]]['identifier'][] = $newrow['identifier'];
  2167. }
  2168. }
  2169. $res = $arr;
  2170. }
  2171. write_static_cache('mod_search_identifier', $res);
  2172. } else {
  2173. $res = $data;
  2174. }
  2175. return $res;
  2176. }
  2177. function mod_identifier()
  2178. {
  2179. $data = read_static_cache('mod_search_option');
  2180. if ($data === false) {
  2181. require_once MYMPS_DATA . '/info.type.inc.php';
  2182. $query = $GLOBALS['db']->query('SELECT id,options FROM `' . $GLOBALS['db_mymps'] . 'info_typemodels` ORDER BY displayorder DESC');
  2183. while ($row = $GLOBALS['db']->fetchRow($query)) {
  2184. $option = explode(',', $row[options]);
  2185. foreach ($option as $w => $u) {
  2186. $nrow = $GLOBALS['db']->getRow('SELECT optionid,title,identifier,type,rules,search FROM `' . $GLOBALS['db_mymps'] . 'info_typeoptions` WHERE optionid=\'' . $u . '\'');
  2187. if ($nrow['search'] == 'on') {
  2188. $extra = $GLOBALS['charset'] == 'utf-8' ? utf8_unserialize($nrow['rules']) : unserialize($nrow['rules']);
  2189. if (in_array($nrow['type'], array('select', 'radio', 'checkbox', 'number'))) {
  2190. if (is_array($extra)) {
  2191. foreach ($extra as $k => $value) {
  2192. if ($nrow[type] == 'radio' || $nrow[type] == 'select' || $nrow[type] == 'checkbox' || $nrow[type] == 'number' && $k == 'choices') {
  2193. $extr = array_merge(array(-1 => '不限'), arraychange($value));
  2194. foreach ($extr as $ekey => $eval) {
  2195. $ar['id'] = $ekey;
  2196. $ar['name'] = $eval;
  2197. $ar['identifier'] = $nrow['identifier'];
  2198. $arr[$row['id']][$nrow['optionid']]['list'][] = $ar;
  2199. }
  2200. }
  2201. $arr[$row['id']][$nrow['optionid']]['title'] = $nrow['title'];
  2202. $arr[$row['id']][$nrow['optionid']]['type'] = $nrow['type'];
  2203. $arr[$row['id']][$nrow['optionid']]['identifier'] = $nrow['identifier'];
  2204. $arr[$row['id']][$nrow['optionid']]['publish'] = get_info_var_type($nrow['type'], $nrow['identifier'], $extr, $get_value, 'front');
  2205. }
  2206. }
  2207. }
  2208. }
  2209. }
  2210. }
  2211. $res = $arr;
  2212. write_static_cache('mod_search_option', $res);
  2213. } else {
  2214. $res = $data;
  2215. }
  2216. return $res;
  2217. }
  2218. function mymps_get_faq($num = 5, $typeid = NULL)
  2219. {
  2220. global $db;
  2221. global $db_mymps;
  2222. global $seo;
  2223. if (!$seo) {
  2224. $seo = get_seoset();
  2225. }
  2226. $where = $typeid ? 'WHERE typeid = ' . $typeid : '';
  2227. $sql = 'SELECT id,typeid,title FROM ' . $db_mymps . 'faq ' . $where . ' ORDER BY id DESC LIMIT 0,' . $num;
  2228. $do_mymps = $db->query($sql);
  2229. while ($row = $db->fetchRow($do_mymps)) {
  2230. $arr['id'] = $row['id'];
  2231. $arr['title'] = $row['title'];
  2232. $arr['uri'] = rewrite('about', array('part' => 'faq', 'id' => $row['id']));
  2233. $faq_list[] = $arr;
  2234. }
  2235. unset($seo);
  2236. return $faq_list;
  2237. }
  2238. function mymps_get_focus($type = 'index', $num = 5)
  2239. {
  2240. global $db;
  2241. global $db_mymps;
  2242. $type_limit = $type == 'index' ? ' AND typename= \'网站首页\'' : ' AND typename = \'新闻首页\'';
  2243. $query = $db->query('SELECT image,pre_image,url,words,id FROM `' . $db_mymps . 'focus` WHERE 1 ' . $type_limit . ' ORDER BY focusorder DESC LIMIT 0,' . $num);
  2244. while ($row = $db->fetchRow($query)) {
  2245. $list[$row['id']]['id'] = $row['id'];
  2246. $list[$row['id']]['image'] = $row['image'];
  2247. $list[$row['id']]['pre_image'] = $row['pre_image'];
  2248. $list[$row['id']]['url'] = $row['url'];
  2249. $list[$row['id']]['words'] = $row['words'];
  2250. }
  2251. return $list;
  2252. }
  2253. function mymps_get_news($num = 10, $catid = NULL, $ifimg = NULL, $leftjoin = NULL, $ifhot = NULL, $orderby = 1)
  2254. {
  2255. global $city;
  2256. global $db;
  2257. global $db_mymps;
  2258. $cat_limit = empty($catid) ? '' : 'AND a.catid IN(' . get_cat_children($catid, 'channel') . ')';
  2259. $img_limit = !$ifimg ? '' : 'AND a.imgpath != \'\'';
  2260. $commend_limit = empty($ifhot) ? '' : ' AND a.iscommend = \'1\'';
  2261. $orderby = empty($orderby) ? 'ORDER BY a.hit DESC' : 'ORDER BY a.id DESC';
  2262. $res = array();
  2263. if ($leftjoin) {
  2264. $query = $db->query('SELECT a.*,b.catname FROM `' . $GLOBALS['db_mymps'] . 'news` AS a LEFT JOIN `' . $GLOBALS['db_mymps'] . 'channel` AS b ON a.catid = b.catid WHERE 1 ' . $cat_limit . ' ' . $img_limit . $city_limit . ' ' . $commend_limit . ' ' . $orderby . ' LIMIT 0,' . $num);
  2265. while ($row = $db->fetchRow($query)) {
  2266. $arr['id'] = $row['id'];
  2267. $arr['title'] = $row['title'];
  2268. $arr['iscommend'] = $row['iscommend'];
  2269. $arr['imgpath'] = $row['imgpath'];
  2270. $arr['content'] = clear_html($row['content']);
  2271. $arr['begintime'] = $row['begintime'];
  2272. $arr['catname'] = $row['catname'];
  2273. $arr['caturi'] = rewrite('news', array('catid' => $row['catid']));
  2274. $arr['caturi_m'] = mrewrite('news', array('catid' => $row['catid']));
  2275. $arr['uri'] = $row['isjump'] ? $row['redirect_url'] : rewrite('news', array('id' => $row['id']));
  2276. $arr['uri_m'] = mrewrite('news', array('id' => $row['id']));
  2277. $res[] = $arr;
  2278. }
  2279. } else {
  2280. $query = $db->query('SELECT a.* FROM `' . $GLOBALS['db_mymps'] . 'news` AS a WHERE 1 ' . $cat_limit . ' ' . $img_limit . $city_limit . $commend_limit . $orderby . ' LIMIT 0,' . $num);
  2281. while ($row = $db->fetchRow($query)) {
  2282. $arr['id'] = $row['id'];
  2283. $arr['title'] = $row['isbold'] == 1 ? '<strong>' . $row['title'] . '</strong>' : $row['title'];
  2284. $arr['title'] = $row['title'];
  2285. $arr['iscommend'] = $row['iscommend'];
  2286. $arr['imgpath'] = $row['imgpath'];
  2287. $arr['content'] = clear_html($row['content']);
  2288. $arr['begintime'] = $row['begintime'];
  2289. $arr['uri'] = $row['isjump'] ? $row['redirect_url'] : rewrite('news', array('id' => $row['id']));
  2290. $arr['uri_m'] = mrewrite('news', array('id' => $row['id']));
  2291. $res[] = $arr;
  2292. }
  2293. }
  2294. return $res;
  2295. }
  2296. function mymps_get_members($num = NULL, $level = NULL, $orderby = NULL, $if_certify = NULL, $ifindex = NULL, $iflist = NULL, $catid = NULL)
  2297. {
  2298. global $db;
  2299. global $db_mymps;
  2300. global $mymps_global;
  2301. global $mayimobile;
  2302. if ($mymps_global['cfg_if_corp'] == 1) {
  2303. $where = $level ? ' WHERE a.levelid = \'' . $level . '\'' : ' WHERE 1';
  2304. $where .= ' AND a.status = \'1\'';
  2305. $where .= ' AND a.if_corp = \'1\'';
  2306. $where .= $if_certify ? ' AND a.com_certify = \'1\'' : ' ';
  2307. $where .= $ifindex ? ' AND a.ifindex = \'2\'' : ' ';
  2308. $where .= $iflist ? ' AND a.iflist = \'2\'' : ' ';
  2309. $where .= !empty($catid) ? ' AND catid IN(' . get_corp_children($catid) . ') ' : '';
  2310. $orderby = $orderby == 1 ? 'ORDER BY a.levelid DESC' : 'ORDER BY a.id DESC';
  2311. $limit = $num ? ' LIMIT 0,' . $num : '';
  2312. $sql = 'SELECT a.* FROM `' . $db_mymps . 'member` AS a ' . $where . ' ' . $orderby . ' ' . $limit;
  2313. $do_mymps = $db->query($sql);
  2314. while ($row = $db->fetchRow($do_mymps)) {
  2315. $arr['id'] = $row['id'];
  2316. $arr['userid'] = $row['userid'];
  2317. $arr['cname'] = $row['cname'];
  2318. $arr['hourstime'] = str_replace(':0', ':00', $row['hourstime']);
  2319. $arr['tname'] = $row['tname'] ? $row['tname'] : $row['userid'];
  2320. $row['prelogo'] = $row['prelogo'] ? $row['prelogo'] : '/images/nophoto.jpg';
  2321. $arr['prelogo'] = !strstr($row['prelogo'], 'http') ? $mymps_global['SiteUrl'] . $row['prelogo'] : $row['prelogo'];
  2322. $arr['jointime'] = $row['jointime'];
  2323. $arr['logintime'] = $row['logintime'];
  2324. $arr['tel'] = $row['tel'];
  2325. $arr['address'] = $row['address'];
  2326. $arr['qq'] = $row['qq'];
  2327. $arr['credits'] = $row['credits'];
  2328. $arr['hit'] = $row['hit'];
  2329. $arr['introduce'] = clear_html($row['introduce']);
  2330. $arr['uri'] = rewrite('store', array('uid' => $row['id']));
  2331. $arr['uri_m'] = mrewrite('store', array('uid' => $row['id']));
  2332. $member_list[] = $arr;
  2333. }
  2334. } else {
  2335. $member_list = array();
  2336. }
  2337. return $member_list;
  2338. }
  2339. function mymps_get_member_docus($num = 10, $userid = NULL, $typeid = NULL, $orderby = 1)
  2340. {
  2341. global $db;
  2342. global $db_mymps;
  2343. global $mayimobile;
  2344. $where = 'WHERE a.if_check = \'1\'';
  2345. $where .= $userid ? ' AND a.userid = \'' . $userid . '\'' : '';
  2346. $where .= $typeid ? ' AND a.typeid = \'' . $typeid . '\'' : '';
  2347. $limit = ' LIMIT 0,' . $num;
  2348. $orderby = $orderby == 1 ? ' ORDER BY a.pubtime DESC ' : ' ORDER BY a.id DESC ';
  2349. $query = $db->query('SELECT a.*,b.id AS uid,b.tname FROM `' . $db_mymps . 'member_docu` AS a LEFT JOIN `' . $db_mymps . 'member` AS b ON a.userid = b.userid ' . $where . ' ' . $orderby . ' ' . $limit);
  2350. while ($row = $db->fetchRow($query)) {
  2351. $arr['id'] = $row['id'];
  2352. $arr['userid'] = $row['userid'];
  2353. $arr['tname'] = $row['tname'];
  2354. $arr['typeid'] = $row['typeid'];
  2355. $arr['title'] = $row['title'];
  2356. $arr['pubtime'] = $row['pubtime'];
  2357. $arr['imgpath'] = $row['imgpath'];
  2358. $arr['hit'] = $row['hit'];
  2359. $arr['pre_imgpath'] = $row['pre_imgpath'];
  2360. $arr['tname_uri'] = rewrite('store', array('uid' => $row['uid'], 'part' => 'index'));
  2361. $arr['uri'] = rewrite('store', array('uid' => $row['uid'], 'id' => $row['id'], 'part' => 'document'));
  2362. $docu[] = $arr;
  2363. }
  2364. return $docu;
  2365. }
  2366. function mymps_get_infos($num = 10, $info_level = NULL, $upgrade_type = NULL, $userid = NULL, $catid = NULL, $certify = NULL, $if_hot = NULL, $tel = NULL)
  2367. {
  2368. global $timestamp;
  2369. global $db_mymps;
  2370. global $mymps_global;
  2371. global $db;
  2372. global $city;
  2373. global $seo;
  2374. global $mayimobile;
  2375. $where .= !$info_level ? 'WHERE (a.info_level =1 OR a.info_level = 2)' : 'WHERE a.info_level = ' . $info_level;
  2376. $where .= $userid ? ' AND a.userid = "' . $userid . '" ' : '';
  2377. $where .= $certify ? ' AND a.certify = "' . $certify . '" ' : '';
  2378. $where .= $tel ? ' AND a.tel = "' . $tel . '" ' : '';
  2379. $where .= $catid ? ' AND ' . get_children($catid, 'a.catid') : '';
  2380. if ($upgrade_type == 1) {
  2381. $where .= ' AND a.upgrade_type_list = 2 ';
  2382. } else {
  2383. if ($upgrade_type == 2) {
  2384. $where .= ' AND a.upgrade_type = 2 ';
  2385. } else {
  2386. if ($upgrade_type == 3) {
  2387. $where .= ' AND a.upgrade_type_index = 2 ';
  2388. }
  2389. }
  2390. }
  2391. $where .= !empty($sql) ? $sql : '';
  2392. $orderby = $if_hot ? ' ORDER BY a.hit DESC ' : ' ORDER BY a.begintime DESC ';
  2393. $info_list = array();
  2394. $idin = get_page_idin('id', 'SELECT a.id FROM `' . $db_mymps . 'information` AS a ' . $where . ' ' . $orderby, $num);
  2395. if ($idin) {
  2396. $sql = 'SELECT a.id,a.email,a.tel,a.contact_who,a.title,a.content,a.begintime,a.catid,a.info_level,a.hit,a.dir_typename,a.ifred,a.ifbold,a.userid,a.catid,a.catname,a.img_path FROM `' . $GLOBALS['db_mymps'] . 'information` AS a WHERE id IN (' . $idin . ') ' . $orderby;
  2397. $do_mymps = $db->query($sql);
  2398. while ($row = $db->fetchRow($do_mymps)) {
  2399. $arr['id'] = $row['id'];
  2400. $arr['face'] = @strstr($row['face'], 'http') ? $row['face'] : $mymps_global['SiteUrl'] . $row['face'];
  2401. $arr['catid'] = $row['catid'];
  2402. $arr['title'] = $row['title'];
  2403. $arr['content'] = clear_html($row['content']);
  2404. $arr['ifred'] = $row['ifred'];
  2405. $arr['ifbold'] = $row['ifbold'];
  2406. $arr['hit'] = $row['hit'];
  2407. $arr['tel'] = $row['tel'];
  2408. $arr['email'] = $row['email'];
  2409. $arr['begintime'] = $row['begintime'];
  2410. $arr['img_path'] = $row['img_path'];
  2411. $arr['catname'] = $row['catname'];
  2412. $arr['info_level'] = $row['info_level'];
  2413. $arr['userid'] = $row['userid'];
  2414. $arr['contact_who'] = $row['contact_who'];
  2415. $arr['uri'] = rewrite('info', array('id' => $row['id'], 'dir_typename' => $row['dir_typename']));
  2416. $arr['uri_m'] = mrewrite('info', array('id' => $row['id'], 'dir_typename' => $row['dir_typename']));
  2417. $arr['uri_tname'] = rewrite('space', array('user' => $row['userid']));
  2418. $arr['uri_cat'] = rewrite('category', array('catid' => $row['catid'], 'dir_typename' => $row['dir_typename']));
  2419. $arr['uri_cat_m'] = mrewrite('category', array('catid' => $row['catid'], 'dir_typename' => $row['dir_typename']));
  2420. $info_list[] = $arr;
  2421. }
  2422. }
  2423. return $info_list ? $info_list : '';
  2424. }
  2425. function mayicms_get_infos($num = 10, $info_level = NULL, $upgrade_type = NULL, $userid = NULL, $catid = NULL, $certify = NULL, $if_hot = NULL, $tel = NULL)
  2426. {
  2427. global $timestamp;
  2428. global $db_mymps;
  2429. global $mymps_global;
  2430. global $db;
  2431. global $seo;
  2432. global $mayimobile;
  2433. $where .= !$info_level ? 'WHERE (a.info_level =1 OR a.info_level = 2)' : 'WHERE a.info_level = ' . $info_level;
  2434. $where .= $userid ? ' AND a.userid = "' . $userid . '" ' : '';
  2435. $where .= $certify ? ' AND a.certify = "' . $certify . '" ' : '';
  2436. $where .= $tel ? ' AND a.tel = "' . $tel . '" ' : '';
  2437. $where .= $catid ? ' AND ' . get_children($catid, 'a.catid') : '';
  2438. if ($upgrade_type == 1) {
  2439. $where .= ' AND a.upgrade_type_list = 2 ';
  2440. } else {
  2441. if ($upgrade_type == 2) {
  2442. $where .= ' AND a.upgrade_type = 2 ';
  2443. } else {
  2444. if ($upgrade_type == 3) {
  2445. $where .= ' AND a.upgrade_type_index = 2 ';
  2446. }
  2447. }
  2448. }
  2449. $where .= !empty($sql) ? $sql : '';
  2450. $orderby = $if_hot ? ' ORDER BY a.hit DESC ' : ' ORDER BY a.begintime DESC ';
  2451. $info_list = array();
  2452. $idin = get_page_idin('id', 'SELECT a.id FROM `' . $db_mymps . 'information` AS a ' . $where . ' ' . $orderby, $num);
  2453. $idin2 = $idin ? ' AND a.infoid IN (' . $idin . ') ' : '';
  2454. if ($idin) {
  2455. $sql = 'SELECT a.zan,a.id,a.face,a.tel,a.contact_who,a.title,a.content,a.begintime,a.catid,a.info_level,a.hit,a.dir_typename,a.ifred,a.ifbold,a.userid,a.catid,a.catname,a.img_path,a.upgrade_type_index,b.areaname FROM `' . $GLOBALS['db_mymps'] . 'information` AS a LEFT JOIN `' . $db_mymps . 'area` AS b ON a.areaid = b.areaid WHERE a.id IN (' . $idin . ') ' . $orderby;
  2456. $do_mymps = $db->query($sql);
  2457. while ($row = $db->fetchRow($do_mymps)) {
  2458. $arr['id'] = $row['id'];
  2459. $arr['face'] = @strstr($row['face'], 'http') ? $row['face'] : $mymps_global['SiteUrl'] . $row['face'];
  2460. $arr['areaname'] = $row['areaname'];
  2461. $arr['catid'] = $row['catid'];
  2462. $arr['title'] = $row['title'];
  2463. $arr['content'] = clear_html($row['content']);
  2464. $arr['ifred'] = $row['ifred'];
  2465. $arr['ifbold'] = $row['ifbold'];
  2466. $arr['hit'] = $row['hit'];
  2467. $arr['tel'] = $row['tel'];
  2468. $arr['zan'] = $row['zan'];
  2469. $arr['begintime'] = $row['begintime'];
  2470. $arr['img_path'] = $row['img_path'];
  2471. $arr['catname'] = $row['catname'];
  2472. $arr['info_level'] = $row['info_level'];
  2473. $arr['userid'] = $row['userid'];
  2474. $arr['upgrade_type_index'] = $row['upgrade_type_index'];
  2475. $arr['contact_who'] = $row['contact_who'];
  2476. $arr['uri'] = rewrite('info', array('id' => $row['id'], 'dir_typename' => $row['dir_typename']));
  2477. $arr['uri_m'] = mrewrite('info', array('id' => $row['id'], 'dir_typename' => $row['dir_typename']));
  2478. $arr['uri_tname'] = rewrite('space', array('user' => $row['userid']));
  2479. $arr['uri_cat'] = rewrite('category', array('catid' => $row['catid'], 'dir_typename' => $row['dir_typename']));
  2480. $arr['uri_cat_m'] = mrewrite('category', array('catid' => $row['catid'], 'dir_typename' => $row['dir_typename']));
  2481. $info_list[$row['id']] = $arr;
  2482. }
  2483. }
  2484. if ($idin2) {
  2485. $iquery = $db->query('SELECT a.infoid,a.prepath FROM `' . $db_mymps . 'info_img` AS a WHERE 1 ' . $idin2);
  2486. while ($r = $db->fetchRow($iquery)) {
  2487. $info_list[$r['infoid']]['img'][] = $r['prepath'];
  2488. }
  2489. }
  2490. return $info_list ? $info_list : '';
  2491. }
  2492. function mymps_get_groups($num = 10, $glevel = NULL)
  2493. {
  2494. global $db;
  2495. global $db_mymps;
  2496. static $res;
  2497. $limit = $num ? ' LIMIT 0,' . $num : '';
  2498. $where = $glevel ? ' WHERE glevel > \'' . $glevel . '\'' : ' WHERE glevel > \'0\'';
  2499. $query = $db->query('SELECT * FROM `' . $db_mymps . 'group` ' . $where . ' ORDER BY dateline DESC ' . $limit);
  2500. while ($row = $db->fetchRow($query)) {
  2501. $res[$row['groupid']]['groupid'] = $row['groupid'];
  2502. $res[$row['groupid']]['gname'] = $row['gname'];
  2503. $res[$row['groupid']]['picture'] = $row['picture'];
  2504. $res[$row['groupid']]['pre_picture'] = $row['pre_picture'];
  2505. $res[$row['groupid']]['userid'] = $row['userid'];
  2506. $res[$row['groupid']]['uri'] = plugin_url('group', array('id' => $row['groupid']));
  2507. $res[$row['groupid']]['gaddress'] = $row['gaddress'];
  2508. $res[$row['groupid']]['meetdate'] = $row['meetdate'];
  2509. $res[$row['groupid']]['enddate'] = $row['enddate'];
  2510. $res[$row['groupid']]['dateline'] = $row['dateline'];
  2511. }
  2512. return $res;
  2513. }
  2514. function mymps_get_goods($num = 10, $onsale = 1, $shuxing = NULL, $catid = NULL, $userid = NULL, $orderby = 1)
  2515. {
  2516. global $db;
  2517. global $db_mymps;
  2518. global $mayimobile;
  2519. $limit = $num ? ' LIMIT 0,' . $num : '';
  2520. $where = $onsale == 1 ? ' WHERE onsale = \'1\'' : ' WHERE 1';
  2521. $where .= $userid ? ' AND userid = \'' . $userid . '\'' : '';
  2522. $where .= $shuxing == 'cuxiao' ? ' AND cuxiao = \'1\'' : '';
  2523. $where .= $shuxing == 'remai' ? ' AND remai = \'1\'' : '';
  2524. $where .= $shuxing == 'tuijian' ? ' AND tuijian = \'1\'' : '';
  2525. $where .= $catid ? ' AND catid IN(' . mymps_get_goods_children($catid) . ')' : '';
  2526. $orderby = empty($orderby) ? ' ORDER BY hit DESC ' : ' ORDER BY dateline DESC ';
  2527. $query = $db->query('SELECT * FROM `' . $db_mymps . 'goods` ' . $where . ' ' . $orderby . ' ' . $limit);
  2528. while ($row = $db->fetchRow($query)) {
  2529. $res[$row['goodsid']]['goodsid'] = $row['goodsid'];
  2530. $res[$row['goodsid']]['goodsname'] = $row['goodsname'];
  2531. $res[$row['goodsid']]['oldprice'] = $row['oldprice'];
  2532. $res[$row['goodsid']]['content'] = clear_html($row['content']);
  2533. $res[$row['goodsid']]['nowprice'] = $row['nowprice'];
  2534. $res[$row['goodsid']]['pre_picture'] = $row['pre_picture'] ? $row['pre_picture'] : $mymps_global['SiteUrl'] . '/images/nophoto.gif';
  2535. $res[$row['goodsid']]['picture'] = $row['picture'] ? $row['picture'] : $mymps_global['SiteUrl'] . '/images/nophoto.gif';
  2536. $res[$row['goodsid']]['uri'] = rewrite('goods', array('id' => $row['goodsid']));
  2537. }
  2538. return $res;
  2539. }
  2540. function mymps_get_coupons($num = 10, $grade = 0)
  2541. {
  2542. global $db;
  2543. global $db_mymps;
  2544. global $city;
  2545. static $res;
  2546. $limit = $num ? ' LIMIT 0,' . $num : '';
  2547. $where = $grade ? ' WHERE grade > \'' . $grade . '\'' : ' WHERE grade > \'0\'';
  2548. $query = $db->query('SELECT * FROM `' . $db_mymps . 'coupon` ' . $where . ' ORDER BY begindate DESC ' . $limit);
  2549. while ($row = $db->fetchRow($query)) {
  2550. $res[$row['id']]['id'] = $row['id'];
  2551. $res[$row['id']]['title'] = $row['title'];
  2552. $res[$row['id']]['des'] = $row['des'];
  2553. $res[$row['id']]['picture'] = $row['picture'];
  2554. $res[$row['id']]['pre_picture'] = $row['pre_picture'];
  2555. $res[$row['id']]['userid'] = $row['userid'];
  2556. $res[$row['id']]['uri'] = plugin_url('coupon', array('id' => $row['id']));
  2557. $res[$row['id']]['begindate'] = $row['begindate'];
  2558. $res[$row['id']]['enddate'] = $row['enddate'];
  2559. $res[$row['id']]['dateline'] = $row['dateline'];
  2560. }
  2561. return 0 < count($res) ? $res : false;
  2562. }
  2563. function mymps_get_navurl($type, $num = '30')
  2564. {
  2565. $data = read_static_cache('navurl_' . $type);
  2566. if ($data === false) {
  2567. if ($type == 'foot') {
  2568. $query = 'SELECT * FROM `' . $GLOBALS['db_mymps'] . 'navurl` WHERE isview = \'2\' AND typeid = \'2\' ORDER BY displayorder ASC LIMIT 0,' . $num;
  2569. } else {
  2570. if ($type == 'header') {
  2571. $query = 'SELECT * FROM `' . $GLOBALS['db_mymps'] . 'navurl` WHERE isview = \'2\' AND typeid = \'3\' ORDER BY displayorder ASC LIMIT 0,' . $num;
  2572. } else {
  2573. if ($type == 'head') {
  2574. $query = 'SELECT * FROM `' . $GLOBALS['db_mymps'] . 'navurl` WHERE isview = \'2\' AND typeid = \'1\' ORDER BY displayorder ASC LIMIT 0,' . $num;
  2575. }
  2576. }
  2577. }
  2578. $res = $GLOBALS['db']->getAll($query);
  2579. write_static_cache('navurl_' . $type, $res);
  2580. } else {
  2581. $res = $data;
  2582. }
  2583. return $res;
  2584. }
  2585. function get_aboutus($id = NULL)
  2586. {
  2587. global $seo;
  2588. if (!$seo) {
  2589. $seo = get_seoset();
  2590. }
  2591. if (!$id) {
  2592. $query = $GLOBALS['db']->query('SELECT id,typename,pubdate,dir_typename FROM `' . $GLOBALS['db_mymps'] . 'about` ORDER BY displayorder,id ASC');
  2593. while ($row = $GLOBALS['db']->fetchRow($query)) {
  2594. $arr['id'] = $row['id'];
  2595. $arr['typename'] = $row['typename'];
  2596. $arr['pubdate'] = $row['pubdate'];
  2597. $arr['uri'] = $row['redirect_url'] ? $row['redirect_url'] : rewrite('about', array('part' => 'aboutus', 'id' => $row['id'], 'html_path' => '/aboutus/' . $row['dir_typename'] . $seo['seo_htmlext']));
  2598. $arr['uri_m'] = mrewrite('about', array('part' => 'aboutus', 'id' => $row['id']));
  2599. $aboutus[] = $arr;
  2600. }
  2601. } else {
  2602. $aboutus = $GLOBALS['db']->getRow('SELECT * FROM ' . $GLOBALS['db_mymps'] . 'about WHERE id =' . $id);
  2603. }
  2604. return $aboutus;
  2605. }
  2606. function get_faq($id = NULL)
  2607. {
  2608. global $seo;
  2609. global $db;
  2610. global $db_mymps;
  2611. if (!$seo) {
  2612. $seo = get_seoset();
  2613. }
  2614. if ($id) {
  2615. $faq = $db->getRow('SELECT id,title,content FROM `' . $db_mymps . 'faq` WHERE id = \'' . $id . '\'');
  2616. } else {
  2617. $query = $db->query('SELECT id,typename FROM `' . $db_mymps . 'faq_type` ORDER BY id ASC');
  2618. while ($row = $db->fetchRow($query)) {
  2619. $faq[$row['id']]['typename'] = $row['typename'];
  2620. }
  2621. $query = $row = NULL;
  2622. $query = $db->query('SELECT * FROM `' . $db_mymps . 'faq` ORDER BY id DESC');
  2623. while ($row = $db->fetchRow($query)) {
  2624. $arr['id'] = $row['id'];
  2625. $arr['title'] = $row['title'];
  2626. $arr['uri'] = rewrite('about', array('part' => 'faq', 'id' => $row['id'], 'html_path' => '/faq/' . $row['id'] . $seo['seo_htmlext']));
  2627. $faq[$row['typeid']]['faq'][$row['id']] = $arr;
  2628. }
  2629. }
  2630. return $faq;
  2631. }
  2632. function get_flink()
  2633. {
  2634. global $db;
  2635. global $db_mymps;
  2636. $query = $db->query('SELECT * FROM `' . $db_mymps . 'flink_type` ORDER BY id ASC');
  2637. while ($row = $db->fetchRow($query)) {
  2638. $flink[$row['id']]['typename'] = $row['typename'];
  2639. }
  2640. $query = $row = NULL;
  2641. $query = $db->query('SELECT * FROM `' . $db_mymps . 'flink` WHERE ischeck = \'2\' ' . $city_limit . ' ORDER BY weblogo DESC,ordernumber DESC,id DESC');
  2642. while ($row = $db->fetchRow($query)) {
  2643. $arr['id'] = $row['id'];
  2644. $arr['webname'] = $row['webname'];
  2645. $arr['weblogo'] = $row['weblogo'];
  2646. $arr['url'] = $row['url'];
  2647. if ($row['weblogo']) {
  2648. $flink[$row['typeid']]['imglink'][$row['id']] = $arr;
  2649. } else {
  2650. $flink[$row['typeid']]['txtlink'][$row['id']] = $arr;
  2651. }
  2652. }
  2653. return $flink;
  2654. }
  2655. function get_member_info($userid = '')
  2656. {
  2657. $row = $GLOBALS['db']->getRow('SELECT * FROM `' . $GLOBALS['db_mymps'] . 'member` WHERE userid = \'' . $userid . '\'');
  2658. return $row;
  2659. }
  2660. function chk_member_purview($purview)
  2661. {
  2662. global $db;
  2663. global $db_mymps;
  2664. global $s_uid;
  2665. $member = get_member_group('', $s_uid);
  2666. if (!in_array($purview, explode(',', $member['purviews']))) {
  2667. write_msg('您当前的会员级别没有该栏目的操作权限!<br />请先升级会员级别!', 'index.php?m=levelup');
  2668. } else {
  2669. return $member;
  2670. }
  2671. }
  2672. function get_member_group($groupid = '', $userid = '')
  2673. {
  2674. if (empty($groupid)) {
  2675. $groupid = $GLOBALS['db']->getOne('SELECT levelid FROM ' . $GLOBALS['db_mymps'] . 'member WHERE userid = \'' . $userid . '\'');
  2676. }
  2677. $data = read_static_cache('member_' . $groupid);
  2678. if ($data === false) {
  2679. $res = $GLOBALS['db']->getRow('SELECT * FROM `' . $GLOBALS['db_mymps'] . 'member_level` WHERE id = \'' . $groupid . '\'');
  2680. $res['allow_tpl'] = empty($res['allow_tpl']) ? '/template/space/theme1' : $res['allow_tpl'];
  2681. $in = create_in(explode(',', $res['allow_tpl']), 'tpl_path');
  2682. $query = $GLOBALS['db']->query('SELECT * FROM `' . $GLOBALS['db_mymps'] . 'member_tpl` WHERE ' . $in . ' AND if_view = \'2\'');
  2683. $res['allow_tpl'] = array();
  2684. while ($row = $GLOBALS['db']->fetchRow($query)) {
  2685. $res['allow_tpl'][$row['id']]['tpl_name'] = $row['tpl_name'];
  2686. $res['allow_tpl'][$row['id']]['tpl_path'] = $row['tpl_path'];
  2687. }
  2688. write_static_cache('member_' . $groupid, $res);
  2689. } else {
  2690. $res = $data;
  2691. }
  2692. return $res;
  2693. }
  2694. function write_pwd_smarty($action = '修改')
  2695. {
  2696. global $smarty;
  2697. global $post;
  2698. global $title;
  2699. global $cat;
  2700. global $part;
  2701. global $id;
  2702. $title = '输入管理密码 - ' . $action . '信息 - ' . $post[title];
  2703. $nav_bar = '<a href="../info.php?id=' . $id . '">' . $post[title] . '</a> &raquo; 输入管理密码 &raquo; ' . $action . '信息</li>';
  2704. $post['part'] = $part;
  2705. tpl_assign();
  2706. $smarty->assign('title', $title);
  2707. $smarty->assign('post', $post);
  2708. $smarty->assign('nav_bar', $nav_bar);
  2709. $smarty->assign('cat', $cat);
  2710. $smarty->assign('action', $action);
  2711. $smarty->display(mymps_tpl('info_write_pwd', 'smarty'));
  2712. }
  2713. function runcron()
  2714. {
  2715. global $timestamp;
  2716. global $db;
  2717. global $db_mymps;
  2718. include MYMPS_ROOT . '/data/cron.cache.php';
  2719. if (is_array($m_cron)) {
  2720. $i = 0;
  2721. foreach ($m_cron as $key => $cron) {
  2722. if ($cron['nextrun'] <= $timestamp) {
  2723. list($yearnow, $monthnow, $daynow) = explode('-', gmdate('Y-m-d', $timestamp + 8 * 3600));
  2724. $nextrun = @gmmktime(0, 0, 0, $monthnow, $daynow + 1, $yearnow) - 8 * 3600;
  2725. include MYMPS_ROOT . '/include/crons/' . $key . '.inc.php';
  2726. $db->query('UPDATE `' . $db_mymps . 'crons` SET lastrun=' . $timestamp . ',nextrun=' . $nextrun . ' WHERE name=\'' . $key . '\'');
  2727. $i++;
  2728. }
  2729. }
  2730. if (0 < $i) {
  2731. write_cron_cache();
  2732. }
  2733. } else {
  2734. write_cron_cache();
  2735. }
  2736. }
  2737. function ifplugin($pluginname = '')
  2738. {
  2739. global $pluginsettings;
  2740. global $mymps_global;
  2741. if (!$pluginsettings) {
  2742. @(include MYMPS_DATA . '/caches/plugin.php');
  2743. $pluginsettings = $data;
  2744. unset($data);
  2745. }
  2746. if ($mymps_global['cfg_if_corp'] != 1) {
  2747. unset($pluginsettings['coupon']);
  2748. unset($pluginsettings['group']);
  2749. unset($pluginsettings['goods']);
  2750. }
  2751. return !$pluginsettings[$pluginname] || $pluginsettings[$pluginname]['disable'] == 1 ? false : true;
  2752. unset($pluginsettings);
  2753. }
  2754. function cutstr($string, $length, $dot = '')
  2755. {
  2756. global $charset;
  2757. if (strlen($string) <= $length) {
  2758. return $string;
  2759. }
  2760. $string = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'), $string);
  2761. $strcut = '';
  2762. if (strtolower($charset) == 'utf-8') {
  2763. $n = $tn = $noc = 0;
  2764. while ($n < strlen($string)) {
  2765. $t = ord($string[$n]);
  2766. if ($t == 9 || $t == 10 || 32 <= $t && $t <= 126) {
  2767. $tn = 1;
  2768. $n++;
  2769. $noc++;
  2770. } else {
  2771. if (194 <= $t && $t <= 223) {
  2772. $tn = 2;
  2773. $n += 2;
  2774. $noc += 2;
  2775. } else {
  2776. if (224 <= $t && $t < 239) {
  2777. $tn = 3;
  2778. $n += 3;
  2779. $noc += 2;
  2780. } else {
  2781. if (240 <= $t && $t <= 247) {
  2782. $tn = 4;
  2783. $n += 4;
  2784. $noc += 2;
  2785. } else {
  2786. if (248 <= $t && $t <= 251) {
  2787. $tn = 5;
  2788. $n += 5;
  2789. $noc += 2;
  2790. } else {
  2791. if ($t == 252 || $t == 253) {
  2792. $tn = 6;
  2793. $n += 6;
  2794. $noc += 2;
  2795. } else {
  2796. $n++;
  2797. }
  2798. }
  2799. }
  2800. }
  2801. }
  2802. }
  2803. if ($length <= $noc) {
  2804. break;
  2805. }
  2806. }
  2807. if ($length < $noc) {
  2808. $n -= $tn;
  2809. }
  2810. $strcut = substr($string, 0, $n);
  2811. } else {
  2812. for ($i = 0; $i < $length; $i++) {
  2813. $strcut .= 127 < ord($string[$i]) ? $string[$i] . $string[++$i] : $string[$i];
  2814. }
  2815. }
  2816. $strcut = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $strcut);
  2817. return $strcut . $dot;
  2818. }
  2819. function mmd5($string, $action = 'EN', $rand = '', $db_mixcode = '')
  2820. {
  2821. global $db_mixcode;
  2822. $secret_string = $db_mixcode . $rand . '^fgfZ4_9dfjdf';
  2823. if ($string == '') {
  2824. return '';
  2825. }
  2826. if ($action == 'EN') {
  2827. $md5code = substr(md5($string), 8, 10);
  2828. } else {
  2829. $md5code = substr($string, -10);
  2830. $string = substr($string, 0, strlen($string) - 10);
  2831. }
  2832. $key = md5($md5code . $secret_string);
  2833. $string = $action == 'EN' ? $string : base64_decode($string);
  2834. $len = strlen($key);
  2835. $code = '';
  2836. for ($i = 0; $i < strlen($string); $i++) {
  2837. $k = $i % $len;
  2838. $code .= $string[$i] ^ $key[$k];
  2839. }
  2840. $code = $action == 'DE' ? substr(md5($code), 8, 10) == $md5code ? $code : NULL : base64_encode($code) . $md5code;
  2841. return $code;
  2842. }
  2843. function mymps_get_goods_children($catid)
  2844. {
  2845. if ($row = $GLOBALS['db']->getAll('SELECT catid FROM `' . $GLOBALS['db_mymps'] . 'goods_category` WHERE parentid = \'' . $catid . '\'')) {
  2846. $cat = array();
  2847. foreach ($row as $k => $v) {
  2848. $cat[$v['catid']] = $v['catid'];
  2849. }
  2850. $cats = implode(',', $cat) . ',' . $catid;
  2851. return $cats;
  2852. } else {
  2853. return $catid;
  2854. }
  2855. }
  2856. function get_groups($num = 10, $glevel = 0)
  2857. {
  2858. global $db;
  2859. global $db_mymps;
  2860. static $res;
  2861. $limit = $num ? ' LIMIT 0,' . $num : '';
  2862. $where = $glevel ? ' WHERE glevel > \'' . $glevel . '\'' : ' WHERE glevel > \'0\'';
  2863. $query = $db->query('SELECT * FROM `' . $db_mymps . 'group` ' . $where . ' ORDER BY dateline DESC ' . $limit);
  2864. while ($row = $db->fetchRow($query)) {
  2865. $res[$row['groupid']]['groupid'] = $row['groupid'];
  2866. $res[$row['groupid']]['gname'] = $row['gname'];
  2867. $res[$row['groupid']]['picture'] = $row['picture'];
  2868. $res[$row['groupid']]['pre_picture'] = $row['pre_picture'];
  2869. $res[$row['groupid']]['userid'] = $row['userid'];
  2870. $res[$row['groupid']]['uri'] = plugin_url('group', array('id' => $row['groupid']));
  2871. $res[$row['groupid']]['gaddress'] = $row['gaddress'];
  2872. $res[$row['groupid']]['meetdate'] = $row['meetdate'];
  2873. $res[$row['groupid']]['enddate'] = $row['enddate'];
  2874. $res[$row['groupid']]['dateline'] = $row['dateline'];
  2875. }
  2876. return 0 < count($res) ? $res : false;
  2877. }
  2878. function get_goods($num = 10, $onsale = 1, $shuxing = '', $catid = '', $userid = '')
  2879. {
  2880. global $db;
  2881. global $db_mymps;
  2882. $limit = $num ? ' LIMIT 0,' . $num : '';
  2883. $where = $onsale == 1 ? ' WHERE onsale = \'1\'' : ' WHERE 1';
  2884. $where .= $userid ? ' AND userid = \'' . $userid . '\'' : '';
  2885. $where .= $shuxing == 'cuxiao' ? ' AND cuxiao = \'1\'' : '';
  2886. $where .= $shuxing == 'remai' ? ' AND remai = \'1\'' : '';
  2887. $where .= $shuxing == 'tuijian' ? ' AND tuijian = \'1\'' : '';
  2888. $where .= $catid ? ' AND catid IN(' . get_goods_children($catid) . ')' : '';
  2889. $query = $db->query('SELECT * FROM `' . $db_mymps . 'goods` ' . $where . ' ORDER BY dateline DESC ' . $limit);
  2890. while ($row = $db->fetchRow($query)) {
  2891. $res[$row['goodsid']]['goodsid'] = $row['goodsid'];
  2892. $res[$row['goodsid']]['goodsname'] = $row['goodsname'];
  2893. $res[$row['goodsid']]['oldprice'] = $row['oldprice'];
  2894. $res[$row['goodsid']]['nowprice'] = $row['nowprice'];
  2895. $res[$row['goodsid']]['pre_picture'] = $row['pre_picture'] ? $row['pre_picture'] : $mymps_global['SiteUrl'] . '/images/nophoto.gif';
  2896. $res[$row['goodsid']]['uri'] = plugin_url('goods', array('id' => $row['goodsid']));
  2897. }
  2898. return 0 < count($res) ? $res : false;
  2899. }
  2900. function get_coupons($num = 10, $grade = 0)
  2901. {
  2902. global $db;
  2903. global $db_mymps;
  2904. static $res;
  2905. $limit = $num ? ' LIMIT 0,' . $num : '';
  2906. $where = $grade ? ' WHERE grade > \'' . $grade . '\'' : ' WHERE grade > \'0\'';
  2907. $query = $db->query('SELECT * FROM `' . $db_mymps . 'coupon` ' . $where . ' ORDER BY begindate DESC ' . $limit);
  2908. while ($row = $db->fetchRow($query)) {
  2909. $res[$row['id']]['id'] = $row['id'];
  2910. $res[$row['id']]['title'] = $row['title'];
  2911. $res[$row['id']]['des'] = $row['des'];
  2912. $res[$row['id']]['picture'] = $row['picture'];
  2913. $res[$row['id']]['pre_picture'] = $row['pre_picture'];
  2914. $res[$row['id']]['userid'] = $row['userid'];
  2915. $res[$row['id']]['uri'] = plugin_url('coupon', array('id' => $row['id']));
  2916. $res[$row['id']]['begindate'] = $row['begindate'];
  2917. $res[$row['id']]['enddate'] = $row['enddate'];
  2918. $res[$row['id']]['dateline'] = $row['dateline'];
  2919. }
  2920. return 0 < count($res) ? $res : false;
  2921. }
  2922. function ifsiteopen()
  2923. {
  2924. global $mymps_global;
  2925. if ($mymps_global['cfg_if_site_open'] != 1) {
  2926. $mymps_global['cfg_site_open_reason'] = str_replace('\\n', '<br />', $mymps_global['cfg_site_open_reason']);
  2927. exit('网站已关闭,关闭原因:<br><br /><b>' . $mymps_global['cfg_site_open_reason'] . '</b>');
  2928. }
  2929. }
  2930. function replace_insidelink($txt, $type = 'information')
  2931. {
  2932. $data = read_static_cache('insidelink');
  2933. if (is_array($data['detail']) && $data['settings']['forward'][$type] == 1) {
  2934. $word = $replacement = array();
  2935. foreach ($data['detail'] as $k => $v) {
  2936. $word[] = $k;
  2937. $replacement[] = '<a href="' . $v . '" target="_blank">' . $k . '</a>';
  2938. }
  2939. $txts = @preg_replace('#(^|>)([^<]+)(?=<|$)#sUe', 'replacelight(\'\\2\', $word, $replacement, \'\\1\')', $txt, 2);
  2940. } else {
  2941. $txts = $txt;
  2942. }
  2943. return $txts;
  2944. }
  2945. function replacelight($txt, $word, $replacement, $pre)
  2946. {
  2947. $txt = str_replace('\\"', '"', $txt);
  2948. $txt = str_replace($word, $replacement, $txt);
  2949. return $pre . $txt;
  2950. }
  2951. function pcclient()
  2952. {
  2953. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  2954. $mobile_agents = array('240x320', 'acer', 'acoon', 'acs-', 'abacho', 'ahong', 'airness', 'alcatel', 'amoi', 'android', 'anywhereyougo.com', 'applewebkit/525', 'applewebkit/532', 'asus', 'audio', 'au-mic', 'avantogo', 'becker', 'benq', 'bilbo', 'bird', 'blackberry', 'blazer', 'bleu', 'cdm-', 'compal', 'coolpad', 'danger', 'dbtel', 'dopod', 'elaine', 'eric', 'etouch', 'fly ', 'fly_', 'fly-', 'go.web', 'goodaccess', 'gradiente', 'grundig', 'haier', 'hedy', 'hitachi', 'htc', 'huawei', 'hutchison', 'inno', 'ipaq', 'ipod', 'jbrowser', 'kddi', 'kgt', 'kwc', 'lenovo', 'lg ', 'lg2', 'lg3', 'lg4', 'lg5', 'lg7', 'lg8', 'lg9', 'lg-', 'lge-', 'lge9', 'longcos', 'maemo', 'mercator', 'meridian', 'micromax', 'midp', 'mini', 'mitsu', 'mmm', 'mmp', 'mobi', 'mot-', 'moto', 'nec-', 'netfront', 'newgen', 'nexian', 'nf-browser', 'nintendo', 'nitro', 'nokia', 'nook', 'novarra', 'obigo', 'palm', 'panasonic', 'pantech', 'philips', 'phone', 'pg-', 'playstation', 'pocket', 'pt-', 'qc-', 'qtek', 'rover', 'sagem', 'sama', 'samu', 'sanyo', 'samsung', 'sch-', 'scooter', 'sec-', 'sendo', 'sgh-', 'sharp', 'siemens', 'sie-', 'softbank', 'sony', 'spice', 'sprint', 'spv', 'symbian', 'tablet', 'talkabout', 'tcl-', 'teleca', 'telit', 'tianyu', 'tim-', 'toshiba', 'tsm', 'up.browser', 'utec', 'utstar', 'verykool', 'virgin', 'vk-', 'voda', 'voxtel', 'vx', 'wap', 'wellco', 'wig browser', 'wii', 'windows ce', 'wireless', 'xda', 'xde', 'zte');
  2955. $is_mobile = true;
  2956. foreach ($mobile_agents as $device) {
  2957. if (stristr($user_agent, $device)) {
  2958. $is_mobile = false;
  2959. break;
  2960. }
  2961. }
  2962. return $is_mobile;
  2963. }
  2964. function get_smplist_cats($cats, $showstyle)
  2965. {
  2966. global $db;
  2967. global $db_mymps;
  2968. global $mymps_global;
  2969. $query = $db->query('SELECT * FROM `' . $db_mymps . 'category` WHERE catid ' . create_in($cats) . ' AND if_view = \'2\' ORDER BY catorder ASC');
  2970. while ($row = $db->fetchRow($query)) {
  2971. $listcats[$row['catid']]['catid'] = $row['catid'];
  2972. $listcats[$row['catid']]['catname'] = $row['catname'];
  2973. $listcats[$row['catid']]['icon'] = $row['icon'];
  2974. $listcats[$row['catid']]['caturi'] = rewrite('category', array('catid' => $row['catid'], 'html_dir' => $row['html_dir'], 'dir_typename' => $row['dir_typename']));
  2975. $listcats[$row['catid']]['showstyle'] = $showstyle[$row['catid']];
  2976. $listcats[$row['catid']]['color'] = $row['color'];
  2977. }
  2978. $query = $db->query('SELECT * FROM `' . $db_mymps . 'category` WHERE parentid ' . create_in($cats) . ' AND if_view = \'2\' ORDER BY catorder ASC');
  2979. while ($r = $db->fetchRow($query)) {
  2980. $listcats[$r['parentid']]['children'][$r['catid']]['catid'] = $r['catid'];
  2981. $listcats[$r['parentid']]['children'][$r['catid']]['catname'] = $r['catname'];
  2982. $listcats[$r['parentid']]['children'][$r['catid']]['color'] = $r['color'];
  2983. $listcats[$r['parentid']]['children'][$r['catid']]['caturi'] = rewrite('category', array('catid' => $r['catid'], 'html_dir' => $r['html_dir'], 'dir_typename' => $r['dir_typename']));
  2984. }
  2985. return $listcats;
  2986. }
  2987. function getbrowser()
  2988. {
  2989. $_SERVER =& $_SERVER;
  2990. $agent = $_SERVER['HTTP_USER_AGENT'];
  2991. $browser = '';
  2992. $browser_ver = '';
  2993. if (preg_match('/OmniWeb\\/(v*)([^\\s|;]+)/i', $agent, $regs)) {
  2994. $browser = 'OmniWeb';
  2995. $browser_ver = $regs[2];
  2996. } else {
  2997. if (preg_match('/Netscape([\\d]*)\\/([^\\s]+)/i', $agent, $regs)) {
  2998. $browser = 'Netscape';
  2999. $browser_ver = $regs[2];
  3000. } else {
  3001. if (preg_match('/Chrome\\/([^\\s]+)/i', $agent, $regs)) {
  3002. $browser = 'Chrome';
  3003. $browser_ver = $regs[1];
  3004. } else {
  3005. if (preg_match('/safari\\/([^\\s]+)/i', $agent, $regs)) {
  3006. $browser = 'Safari';
  3007. $browser_ver = $regs[1];
  3008. } else {
  3009. if (preg_match('/MSIE\\s([^\\s|;]+)/i', $agent, $regs)) {
  3010. $browser = 'Internet Explorer';
  3011. $browser_ver = $regs[1];
  3012. } else {
  3013. if (preg_match('/Opera[\\s|\\/]([^\\s]+)/i', $agent, $regs)) {
  3014. $browser = 'Opera';
  3015. $browser_ver = $regs[1];
  3016. } else {
  3017. if (preg_match('/NetCaptor\\s([^\\s|;]+)/i', $agent, $regs)) {
  3018. $browser = '(Internet Explorer ' . $browser_ver . ') NetCaptor';
  3019. $browser_ver = $regs[1];
  3020. } else {
  3021. if (preg_match('/Maxthon/i', $agent, $regs)) {
  3022. $browser = '(Internet Explorer ' . $browser_ver . ') Maxthon';
  3023. $browser_ver = '';
  3024. } else {
  3025. if (preg_match('/360SE/i', $agent, $regs)) {
  3026. $browser = '(Internet Explorer ' . $browser_ver . ') 360SE';
  3027. $browser_ver = '';
  3028. } else {
  3029. if (preg_match('/SE 2.x/i', $agent, $regs)) {
  3030. $browser = '(Internet Explorer ' . $browser_ver . ') 搜狗';
  3031. $browser_ver = '';
  3032. } else {
  3033. if (preg_match('/FireFox\\/([^\\s]+)/i', $agent, $regs)) {
  3034. $browser = 'FireFox';
  3035. $browser_ver = $regs[1];
  3036. } else {
  3037. if (preg_match('/Lynx\\/([^\\s]+)/i', $agent, $regs)) {
  3038. $browser = 'Lynx';
  3039. $browser_ver = $regs[1];
  3040. }
  3041. }
  3042. }
  3043. }
  3044. }
  3045. }
  3046. }
  3047. }
  3048. }
  3049. }
  3050. }
  3051. }
  3052. if ($browser != '') {
  3053. return $browser . ' ' . $browser_ver;
  3054. } else {
  3055. return '未知浏览器版本';
  3056. }
  3057. }
  3058. function getos()
  3059. {
  3060. $agent = $_SERVER['HTTP_USER_AGENT'];
  3061. $os = false;
  3062. if (@eregi('win', $agent) && strpos($agent, '95')) {
  3063. $os = 'Windows 95';
  3064. } else {
  3065. if (@eregi('win 9x', $agent) && strpos($agent, '4.90')) {
  3066. $os = 'Windows ME';
  3067. } else {
  3068. if (@eregi('win', $agent) && @ereg('98', $agent)) {
  3069. $os = 'Windows 98';
  3070. } else {
  3071. if (@eregi('win', $agent) && @eregi('nt 5.1', $agent)) {
  3072. $os = 'Windows XP';
  3073. } else {
  3074. if (@eregi('win', $agent) && @eregi('nt 5', $agent)) {
  3075. $os = 'Windows 2000';
  3076. } else {
  3077. if (@eregi('win', $agent) && @eregi('nt', $agent)) {
  3078. $os = 'Windows NT';
  3079. } else {
  3080. if (@eregi('win', $agent) && @ereg('32', $agent)) {
  3081. $os = 'Windows 32';
  3082. } else {
  3083. if (@eregi('linux', $agent)) {
  3084. $os = 'Linux';
  3085. } else {
  3086. if (@eregi('unix', $agent)) {
  3087. $os = 'Unix';
  3088. } else {
  3089. if (@eregi('sun', $agent) && @eregi('os', $agent)) {
  3090. $os = 'SunOS';
  3091. } else {
  3092. if (@eregi('ibm', $agent) && @eregi('os', $agent)) {
  3093. $os = 'IBM OS/2';
  3094. } else {
  3095. if (@eregi('Mac', $agent) && @eregi('PC', $agent)) {
  3096. $os = 'Macintosh';
  3097. } else {
  3098. if (@eregi('PowerPC', $agent)) {
  3099. $os = 'PowerPC';
  3100. } else {
  3101. if (@eregi('AIX', $agent)) {
  3102. $os = 'AIX';
  3103. } else {
  3104. if (@eregi('HPUX', $agent)) {
  3105. $os = 'HPUX';
  3106. } else {
  3107. if (@eregi('NetBSD', $agent)) {
  3108. $os = 'NetBSD';
  3109. } else {
  3110. if (@eregi('BSD', $agent)) {
  3111. $os = 'BSD';
  3112. } else {
  3113. if (@ereg('OSF1', $agent)) {
  3114. $os = 'OSF1';
  3115. } else {
  3116. if (@ereg('IRIX', $agent)) {
  3117. $os = 'IRIX';
  3118. } else {
  3119. if (@eregi('FreeBSD', $agent)) {
  3120. $os = 'FreeBSD';
  3121. } else {
  3122. if (@eregi('teleport', $agent)) {
  3123. $os = 'teleport';
  3124. } else {
  3125. if (@eregi('flashget', $agent)) {
  3126. $os = 'flashget';
  3127. } else {
  3128. if (@eregi('webzip', $agent)) {
  3129. $os = 'webzip';
  3130. } else {
  3131. if (@eregi('offline', $agent)) {
  3132. $os = 'offline';
  3133. } else {
  3134. $os = 'Unknown';
  3135. }
  3136. }
  3137. }
  3138. }
  3139. }
  3140. }
  3141. }
  3142. }
  3143. }
  3144. }
  3145. }
  3146. }
  3147. }
  3148. }
  3149. }
  3150. }
  3151. }
  3152. }
  3153. }
  3154. }
  3155. }
  3156. }
  3157. }
  3158. }
  3159. return $os;
  3160. }
  3161. function getport()
  3162. {
  3163. return $_SERVER['REMOTE_PORT'];
  3164. }
  3165. function strexists($haystack, $needle)
  3166. {
  3167. return !strpos($haystack, $needle) === false;
  3168. }
  3169. function is_robot()
  3170. {
  3171. $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
  3172. if (!empty($ua)) {
  3173. $spiderAgentArr = array('Baiduspider', 'Googlebot', '360Spider', 'Sosospider', 'sogou spider');
  3174. foreach ($spiderAgentArr as $val) {
  3175. $spiderAgent = strtolower($val);
  3176. if (strpos($ua, $spiderAgent) !== false) {
  3177. return true;
  3178. }
  3179. }
  3180. return false;
  3181. } else {
  3182. return false;
  3183. }
  3184. }
  3185. function get_gid($catid)
  3186. {
  3187. global $db;
  3188. global $db_mymps;
  3189. global $mymps_global;
  3190. $sid = $db->getOne('SELECT parentid FROM `' . $db_mymps . 'category` WHERE catid=\'' . $catid . '\'');
  3191. if (empty($sid)) {
  3192. return $catid;
  3193. } else {
  3194. $fid = $db->getOne('SELECT parentid FROM `' . $db_mymps . 'category` WHERE catid = \'' . $sid . '\'');
  3195. if (empty($fid)) {
  3196. return $sid;
  3197. } else {
  3198. $did = $db->getOne('SELECT parentid FROM `' . $db_mymps . 'category` WHERE catid = \'' . $fid . '\'');
  3199. if (empty($did)) {
  3200. return $fid;
  3201. }
  3202. }
  3203. }
  3204. }
  3205. function mymps_chk_smsrandcode($getcode = '', $phonenum = '')
  3206. {
  3207. global $timestamp;
  3208. session_start();
  3209. $getcode = trim(strtoupper($getcode));
  3210. $sessioncode = $_SESSION['smscode']['code'];
  3211. if ($phonenum) {
  3212. if ($timestamp < $_SESSION['smscode']['time'] && $sessioncode == $getcode && $phonenum == $_SESSION['smscode']['phonenum']) {
  3213. return true;
  3214. }
  3215. } else {
  3216. if ($timestamp < $_SESSION['smscode']['time'] && $sessioncode == $getcode) {
  3217. return true;
  3218. }
  3219. }
  3220. return false;
  3221. }
  3222. function is_mobile($phonenum)
  3223. {
  3224. return preg_match('/1[3456789]{1}\\d{9}$/', $phonenum) ? true : false;
  3225. }
  3226. function mkFolder($path)
  3227. {
  3228. if (!is_readable($path)) {
  3229. is_file($path) || mkdir($path, 511);
  3230. }
  3231. }
  3232. function GetCurSinImg($goods_desc)
  3233. {
  3234. require_once MYMPS_INC . '/upfile.fun.php';
  3235. global $mymps_global;
  3236. $host = $mymps_global['SiteUrl'];
  3237. $body = stripslashes($goods_desc);
  3238. $img_array = array();
  3239. preg_match_all('/<img.*?src="(.*?)".*?>/is', $body, $img_array);
  3240. $img_array = array_unique($img_array[1]);
  3241. $imgurl = '/editor/' . date('Ymd');
  3242. $imgpath = MYMPS_UPLOAD . $imgurl;
  3243. $millisecond = date('YmdHms') . random(5);
  3244. mkfolder($imgpath);
  3245. if (!is_array($img_array)) {
  3246. return false;
  3247. } else {
  3248. foreach ($img_array as $key => $value) {
  3249. file_put_contents('file.log', $value . "\r\n", FILE_APPEND);
  3250. if (strpos($value, $host) === 0 || strpos($value, 'attachment/editor')) {
  3251. continue;
  3252. }
  3253. $value = trim($value);
  3254. $imgAttr = get_headers($value, true);
  3255. switch ($imgAttr['Content-Type']) {
  3256. case 'image/png':
  3257. $ext = 'png';
  3258. break;
  3259. case 'image/jpeg':
  3260. $ext = 'jpg';
  3261. break;
  3262. case 'image/gif':
  3263. $ext = 'gif';
  3264. break;
  3265. default:
  3266. $ext = 'jpg';
  3267. }
  3268. $get_file = @file_get_contents($value);
  3269. $rndfilename = $imgpath . '/' . $millisecond . $key . '.' . $ext;
  3270. $fileurl = $host . '/attachment' . $imgurl . '/' . $millisecond . $key . '.' . $ext;
  3271. if ($get_file) {
  3272. $fp = @fopen($rndfilename, 'w');
  3273. @fwrite($fp, $get_file);
  3274. @fclose($fp);
  3275. WaterImg($rndfilename);
  3276. }
  3277. $body = str_replace($value, $fileurl, $body);
  3278. }
  3279. }
  3280. $body = addslashes($body);
  3281. return $body;
  3282. }
  3283. if (!function_exists('htmlspecialchars_decode')) {
  3284. function htmlspecialchars_decode($text)
  3285. {
  3286. return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
  3287. }
  3288. }