custom.fun.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <?php
  2. function custom($flag = '', $js = 'html')
  3. {
  4. global $db;
  5. global $db_mymps;
  6. global $jswizard_lists;
  7. global $jssettings;
  8. global $jscharset;
  9. global $mymps_global;
  10. global $charset;
  11. global $timestamp;
  12. if (empty($flag)) {
  13. exit($js == 'js' ? html2js('Access Diened!') : 'Access Diened!');
  14. }
  15. $jswizard_lists = array();
  16. $data = '';
  17. $allowflag = '';
  18. include MYMPS_ROOT . '/data/caches/jswizard_lists.php';
  19. $jswizard_lists = $data;
  20. unset($data);
  21. !in_array($flag, array_keys($jswizard_lists)) && exit(html2js('NO flag exists!'));
  22. require_once MYMPS_ROOT . '/include/cache.fun.php';
  23. @include MYMPS_ROOT . '/data/caches/jswizard_settings.php';
  24. $jssettings = $data;
  25. unset($data);
  26. if (empty($jssettings['jsstatus'])) {
  27. exit(html2js('<font color=red>The webmaster did not enable this feature.</font>'));
  28. }
  29. $nocache = empty($jssettings['jscachelife']) ? true : NULL;
  30. $jsrefdomains = isset($jssettings['jsrefdomains']) ? $jssettings['jsrefdomains'] : preg_replace('/([^\\:]+).*/', '\\1', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : NULL);
  31. $REFERER = parse_url($_SERVER['HTTP_REFERER']);
  32. if ($jsrefdomains && (empty($REFERER) || !in_array($REFERER['host'], explode('
  33. ', trim($jsrefdomains))))) {
  34. exit($js == 'js' ? html2js('<font color=red>Referer restriction is taking effect.</font>') : '<font color=red>Referer restriction is taking effect.</font>');
  35. }
  36. $cachefile = MYMPS_ROOT . '/data/caches/custom_' . $flag . '.php';
  37. $expiration = NULL;
  38. @include $cachefile;
  39. if (!$expiration || $timestamp <= $expiration) {
  40. require_once MYMPS_ROOT . '/data/config.db.php';
  41. require_once MYMPS_ROOT . '/include/db.class.php';
  42. $customtag = customtag($flag);
  43. $writedata = procdata($customtag);
  44. if ($js == 'js') {
  45. $datalist = procdata('document.write("' . $customtag . '");');
  46. }
  47. else if ($js == 'html') {
  48. $datalist = $writedata;
  49. }
  50. unset($customtag);
  51. if (!$nocache) {
  52. $writedata = '$datalist = \'' . addcslashes($writedata, '\\\'') . '\';';
  53. UpdateCache($cachefile, $writedata);
  54. }
  55. }
  56. else if ($js == 'js') {
  57. $datalist = procdata('document.write("' . $datalist . '");');
  58. }
  59. return $datalist;
  60. }
  61. function customtag($flag = '')
  62. {
  63. global $db;
  64. global $db_mymps;
  65. global $jswizard_lists;
  66. global $jssettings;
  67. global $jscharset;
  68. global $mymps_global;
  69. global $charset;
  70. global $timestamp;
  71. $parameter = $jswizard_lists[$flag]['parameter'];
  72. $customtype = $jswizard_lists[$flag]['customtype'];
  73. switch ($customtype) {
  74. case 'info':
  75. $catid = is_array($parameter['catid']) ? implode('\',\'', $parameter['catid']) : NULL;
  76. $areaid = is_array($parameter['areaid']) ? implode('\',\'', $parameter['areaid']) : NULL;
  77. $newwindow = !empty($parameter['newwindow']) ? $parameter['newwindow'] : 1;
  78. $items = !empty($parameter['items']) ? intval($parameter['items']) : 10;
  79. $maxlength = !empty($parameter['maxlength']) ? intval($parameter['maxlength']) : 50;
  80. $ids = !empty($parameter['ids']) ? str_replace(',', '\',\'', trim($parameter['ids'])) : NULL;
  81. $keyword = !empty($parameter['keyword']) ? $parameter['keyword'] : NULL;
  82. $special = is_array($parameter['special']) ? $parameter['special'] : NULL;
  83. $orderby = !empty($parameter['orderby']) ? ($parameter['orderby'] == 'views' ? 'hit' : 'begintime') : 'begintime';
  84. $jstemplate = !empty($parameter['jstemplate']) ? $parameter['jstemplate'] : '{title}<br />';
  85. $jscharset = !empty($parameter['jscharset']) ? $parameter['jscharset'] : NULL;
  86. $target = $newwindow == 1 ? 'target=_blank' : 'target=_self';
  87. $jsdateformat = isset($jssettings['jsdateformat']) ? $jssettings['jsdateformat'] : 'Y-m-d';
  88. $datalist = array();
  89. if ($keyword) {
  90. if (preg_match('(AND|\\+|&|\\s)', $keyword) && !preg_match('(OR|\\|)', $keyword)) {
  91. $andor = ' AND ';
  92. $keywordsrch = '1';
  93. $keyword = preg_replace('/( AND |&| )/is', '+', $keyword);
  94. }
  95. else {
  96. $andor = ' OR ';
  97. $keywordsrch = '0';
  98. $keyword = preg_replace('/( OR |\\|)/is', '+', $keyword);
  99. }
  100. $keyword = str_replace('*', '%', addcslashes($keyword, '%_'));
  101. foreach (explode('+', $keyword) as $text) {
  102. $text = trim($text);
  103. if ($text) {
  104. $keywordsrch .= $andor;
  105. $keywordsrch .= 't.title LIKE \'%' . $text . '%\'';
  106. }
  107. }
  108. $keyword = ' AND (' . $keywordsrch . ')';
  109. }
  110. else {
  111. $keyword = '';
  112. }
  113. require_once MYMPS_ROOT . '/data/info_special.inc.php';
  114. $sql = ($catid ? ' AND t.catid IN (\'' . $catid . '\')' : '') . $keyword . ($ids ? ' AND t.id IN (\'' . $ids . '\')' : '') . ($areaid ? ' AND t.areaid IN (\'' . $areaid . '\')' : '');
  115. if (is_array($special) && $special != array('1', '2', '3', '4', '5', '6', '7', '8', '9')) {
  116. foreach ($special as $k => $v) {
  117. switch ($v) {
  118. case 1:
  119. $sql .= ' AND t.upgrade_type = \'2\' AND t.upgrade_time > \'$timestamp\'';
  120. break;
  121. case 2:
  122. $sql .= ' AND t.upgrade_type_list = \'2\' AND t.upgrade_time_list > \'$timestamp\'';
  123. break;
  124. case 3:
  125. $sql .= ' AND t.upgrade_type_index = \'2\' AND t.upgrade_time_index > \'$timestamp\'';
  126. break;
  127. case 4:
  128. $sql .= ' AND t.info_level = \'0\'';
  129. break;
  130. case 5:
  131. $sql .= ' AND t.info_level = \'1\'';
  132. break;
  133. case 6:
  134. $sql .= ' AND t.info_level = \'2\'';
  135. break;
  136. case 7:
  137. $sql .= ' AND t.ifred = \'1\'';
  138. break;
  139. case 8:
  140. $sql .= ' AND t.ifbold = \'1\'';
  141. break;
  142. case 9:
  143. $sql .= ' AND t.certify = \'1\'';
  144. break;
  145. }
  146. }
  147. }
  148. else {
  149. $sql .= ' AND t.info_level > \'0\'';
  150. }
  151. $sqlfrom = ',t.catname,t.dir_typename FROM `' . $db_mymps . 'information` AS t';
  152. $query = $db->query('SELECT t.id,t.areaid,t.img_path,t.catid,t.title,t.content,t.userid,t.contact_who,t.ismember,t.begintime,t.hit,t.ifbold,t.ifred
  153. ' . $sqlfrom . ' WHERE 1
  154. ' . $sql . '
  155. ORDER BY t.' . $orderby . ' DESC
  156. LIMIT 0,' . $items . ';');
  157. while ($data = $db->fetchRow($query)) {
  158. $datalist[$data['id']]['catid'] = $data['catid'];
  159. $datalist[$data['id']]['catname'] = $data['catname'];
  160. $datalist[$data['id']]['caturl'] = Rewrite('category', array('catid' => $data['catid'], 'dir_typename' => $data['dir_typename'], 'areaid' => $data['areaid']));
  161. $datalist[$data['id']]['img_path'] = $data['img_path'];
  162. $datalist[$data['id']]['catnamelength'] = strlen($datalist[$data['id']]['catname']);
  163. $datalist[$data['id']]['title'] = isset($data['title']) ? str_replace('\'', '&nbsp;', addslashes($data['title'])) : NULL;
  164. $datalist[$data['id']]['link'] = $mymps_global[SiteUrl] . Rewrite('info', array('id' => $data['id'], 'dir_typename' => $data['dir_typename'], 'areaid' => $data['areaid']));
  165. $datalist[$data['id']]['begintime'] = date($jsdateformat, $data['begintime']);
  166. $datalist[$data['id']]['hit'] = $data['hit'];
  167. $datalist[$data['id']]['ifbold'] = $data['ifbold'];
  168. $datalist[$data['id']]['ifred'] = $data['ifred'];
  169. $datalist[$data['id']]['introduce'] = str_replace(array('\'', '
  170. ', '
  171. '), array('&nbsp;', '', ''), addslashes(cutstr(mhtmlspecialchars(preg_replace('/(\\[.+\\])/s', '', strip_tags(nl2br($data['content'])))), 255)));
  172. if ($data['userid'] && $data['ismember'] == 1) {
  173. $datalist[$data['id']]['author'] = '<a href=\'' . Rewrite('space', array('user' => $data['userid'])) . '\' target=\'_blank\'>' . $data[userid] . '</a>';
  174. }
  175. else {
  176. $datalist[$data['id']]['author'] = !empty($data['contact_who']) ? $data['contact_who'] : '游客';
  177. }
  178. }
  179. $writedata = '';
  180. if (is_array($datalist)) {
  181. foreach ($datalist as $t => $val) {
  182. $SubjectStyles = '';
  183. $SubjectStyles .= ' style=\'';
  184. $SubjectStyles .= $val['ifbold'] == 1 ? 'font-weight: bold;' : NULL;
  185. $SubjectStyles .= $val['ifred'] == 1 ? 'color: red;' : NULL;
  186. $SubjectStyles .= '\'';
  187. $val['title'] = cutstr($val['title'], $catnamelength ? $maxlength - $val['catnamelength'] : $maxlength);
  188. $replace['{link}'] = $val['link'];
  189. $replace['{title}'] = '<a title=' . $val['title'] . ' href=\'' . $val['link'] . '\' ' . $SubjectStyles . ' ' . $target . '>' . $val['title'] . '</a>';
  190. $replace['{title_nolink}'] = $val['title'];
  191. $replace['{catname}'] = '<a href=\'' . $val['caturl'] . '\' ' . $target . '>' . $val['catname'] . '</a>';
  192. $replace['{begintime}'] = $val['begintime'];
  193. $replace['{introduce}'] = $val['introduce'];
  194. $replace['{author}'] = $val['author'];
  195. $replace['{hit}'] = $val['hit'];
  196. $replace['{imgpath}'] = $mymps_global['SiteUrl'] . ($val['img_path'] ? $val['img_path'] : '/images/nophoto.gif');
  197. $writedata .= str_replace(array_keys($replace), $replace, $jstemplate);
  198. }
  199. }
  200. break;
  201. case 'news':
  202. $catid = $parameter['catid'] ? $parameter['catid'] : NULL;
  203. $newwindow = !empty($parameter['newwindow']) ? $parameter['newwindow'] : 1;
  204. $items = !empty($parameter['items']) ? intval($parameter['items']) : 10;
  205. $maxlength = !empty($parameter['maxlength']) ? intval($parameter['maxlength']) : 40;
  206. $special = $parameter['special'];
  207. $orderby = !empty($parameter['orderby']) ? ($parameter['orderby'] == 'views' ? 'hit' : NULL) : NULL;
  208. $jstemplate = !empty($parameter['jstemplate']) ? $parameter['jstemplate'] : '<li>{title}</li>';
  209. $jscharset = !empty($parameter['jscharset']) ? $parameter['jscharset'] : NULL;
  210. $target = $newwindow == 1 ? 'target=_blank' : 'target=_self';
  211. $jsdateformat = isset($jssettings['jsdateformat']) ? $jssettings['jsdateformat'] : 'Y-m-d';
  212. $if_img = $special[0];
  213. $if_commend = $special[1];
  214. $datalist = mymps_get_news($items, $catid, $if_img, strexists($jstemplate, '{catname}') ? 1 : 0, $if_commend, $orderby);
  215. $writedata = '';
  216. if (is_array($datalist)) {
  217. foreach ($datalist as $t => $val) {
  218. $SubjectStyles = '';
  219. $SubjectStyles .= ' style=\'';
  220. $SubjectStyles .= $val['is_commend'] == 1 ? 'font-weight: bold;' : NULL;
  221. $SubjectStyles .= $val['is_commend'] == 1 ? 'color: red;' : NULL;
  222. $SubjectStyles .= '\'';
  223. $val['title'] = cutstr($val['title'], $maxlength);
  224. $replace['{link}'] = $val['uri'];
  225. $replace['{title}'] = '<a title=' . $val['title'] . ' href=\'' . $val['uri'] . '\' ' . $SubjectStyles . ' ' . $target . '>' . $val['title'] . '</a>';
  226. $replace['{title_nolink}'] = $val['title'];
  227. $replace['{catname}'] = '<a href=\'' . $val['caturi'] . '\' ' . $target . '>' . $val['catname'] . '</a>';
  228. $replace['{begintime}'] = date($jsdateformat, $val['begintime']);
  229. $replace['{introduce}'] = str_replace(array('\'', '
  230. ', '
  231. '), array('&nbsp;', '', ''), addslashes(cutstr(mhtmlspecialchars(preg_replace('/(\\[.+\\])/s', '', strip_tags(nl2br($val['content'])))), 255)));
  232. $replace['{hit}'] = $val['hit'];
  233. $replace['{imgpath}'] = $mymps_global['SiteUrl'] . ($val['imgpath'] ? $val['imgpath'] : '/images/nophoto.gif');
  234. $writedata .= str_replace(array_keys($replace), $replace, $jstemplate);
  235. }
  236. }
  237. break;
  238. case 'store':
  239. $catid = $parameter['catid'] ? $parameter['catid'] : NULL;
  240. $newwindow = !empty($parameter['newwindow']) ? $parameter['newwindow'] : 1;
  241. $items = !empty($parameter['items']) ? intval($parameter['items']) : 10;
  242. $maxlength = !empty($parameter['maxlength']) ? intval($parameter['maxlength']) : 40;
  243. $special = $parameter['special'];
  244. $areaid = $parameter['areaid'];
  245. $levelid = $parameter['levelid'];
  246. $orderby = !empty($parameter['orderby']) ? ($parameter['orderby'] == 'dateline' ? 0 : 1) : 0;
  247. $jstemplate = !empty($parameter['jstemplate']) ? $parameter['jstemplate'] : '<li>{title}</li>';
  248. $jscharset = !empty($parameter['jscharset']) ? $parameter['jscharset'] : NULL;
  249. $target = $newwindow == 1 ? 'target=_blank' : 'target=_self';
  250. $jsdateformat = isset($jssettings['jsdateformat']) ? $jssettings['jsdateformat'] : 'Y-m-d';
  251. $if_certify = $special[0];
  252. $ifindex = $special[1];
  253. $iflist = $special[2];
  254. $datalist = mymps_get_members($items, $levelid, $orderby, 1, $if_certify, $ifindex, $iflist, $areaid, $catid);
  255. $writedata = '';
  256. if (is_array($datalist)) {
  257. foreach ($datalist as $t => $val) {
  258. $val['tname'] = cutstr($val['tname'], $maxlength);
  259. $replace['{link}'] = $val['uri'];
  260. $replace['{tname}'] = '<a title=' . $val['tname'] . ' href=\'' . $val['uri'] . '\' ' . $target . '>' . $val['tname'] . '</a>';
  261. $replace['{tname_nolink}'] = $val['tname'];
  262. $replace['{jointime}'] = date($jsdateformat, $val['jointime']);
  263. $replace['{introduce}'] = str_replace(array('\'', '
  264. ', '
  265. '), array('&nbsp;', '', ''), addslashes(cutstr(mhtmlspecialchars(preg_replace('/(\\[.+\\])/s', '', strip_tags(nl2br($val['content'])))), 255)));
  266. $replace['{hit}'] = $val['hit'];
  267. $replace['{qq}'] = $val['qq'];
  268. $replace['{tel}'] = $val['tel'];
  269. $replace['{address}'] = $val['address'];
  270. $replace['{userid}'] = $val['userid'];
  271. $replace['{prelogo}'] = $mymps_global['SiteUrl'] . $val['prelogo'];
  272. $writedata .= str_replace(array_keys($replace), $replace, $jstemplate);
  273. }
  274. }
  275. break;
  276. case 'goods':
  277. $catid = $parameter['catid'] ? $parameter['catid'] : NULL;
  278. $newwindow = !empty($parameter['newwindow']) ? $parameter['newwindow'] : 1;
  279. $items = !empty($parameter['items']) ? intval($parameter['items']) : 10;
  280. $maxlength = !empty($parameter['maxlength']) ? intval($parameter['maxlength']) : 40;
  281. $special = $parameter['special'];
  282. $areaid = $parameter['areaid'];
  283. $orderby = !empty($parameter['orderby']) ? ($parameter['orderby'] == 'dateline' ? 0 : 1) : 0;
  284. $jstemplate = !empty($parameter['jstemplate']) ? $parameter['jstemplate'] : '<li>{title}</li>';
  285. $jscharset = !empty($parameter['jscharset']) ? $parameter['jscharset'] : NULL;
  286. $target = $newwindow == 1 ? 'target=_blank' : 'target=_self';
  287. $jsdateformat = isset($jssettings['jsdateformat']) ? $jssettings['jsdateformat'] : 'Y-m-d';
  288. if ($special[0] == 1) {
  289. $shuxing = 'tuijian';
  290. }
  291. else if ($special[1] == 1) {
  292. $shuxing = 'remai';
  293. }
  294. else if ($special[2] == 1) {
  295. $shuxing = 'cuxiao';
  296. }
  297. $datalist = mymps_get_goods($items, 1, $shuxing, $catid, $areaid, $orderby);
  298. $writedata = '';
  299. if (is_array($datalist)) {
  300. foreach ($datalist as $t => $val) {
  301. $val['uri'] = $val['uri'];
  302. $val['goodsname'] = cutstr($val['goodsname'], $maxlength);
  303. $replace['{link}'] = $val['uri'];
  304. $replace['{goodsname}'] = '<a title=' . $val['goodsname'] . ' href=\'' . $val['uri'] . '\' ' . $target . '>' . $val['goodsname'] . '</a>';
  305. $replace['{goodsname_nolink}'] = $val['goodsname'];
  306. $replace['{jointime}'] = date($jsdateformat, $val['jointime']);
  307. $replace['{introduce}'] = str_replace(array('\'', '
  308. ', '
  309. '), array('&nbsp;', '', ''), addslashes(cutstr(mhtmlspecialchars(preg_replace('/(\\[.+\\])/s', '', strip_tags(nl2br($val['content'])))), 255)));
  310. $replace['{oldprice}'] = $val['oldprice'];
  311. $replace['{nowprice}'] = $val['nowprice'];
  312. $replace['{userid}'] = $val['userid'];
  313. $replace['{picture}'] = $mymps_global['SiteUrl'] . $val['picture'];
  314. $replace['{prepicture}'] = $mymps_global['SiteUrl'] . $val['prepicture'];
  315. $writedata .= str_replace(array_keys($replace), $replace, $jstemplate);
  316. }
  317. }
  318. break;
  319. }
  320. unset($mymps_global);
  321. return parsenode($writedata);
  322. }
  323. function parsenode($data)
  324. {
  325. global $jstemplate;
  326. if ($jstemplate) {
  327. $data = preg_replace('/\\[node\\](.+?)\\[\\/node\\]/is', $data, $jstemplate, 1);
  328. $data = preg_replace('/\\[node\\](.+?)\\[\\/node\\]/is', '', $data);
  329. }
  330. return $data;
  331. }
  332. function procdata($data)
  333. {
  334. global $jscharset;
  335. global $charset;
  336. if ($jscharset && strtoupper($charset) == 'GBK') {
  337. $data = iconv('GBK', 'UTF-8', $data);
  338. }
  339. return $data;
  340. }
  341. function UpdateCache($cachefile, $data = '')
  342. {
  343. global $timestamp;
  344. global $jscachelife;
  345. if (!($fp = @fopen($cachefile, 'wb'))) {
  346. exit('document.write("Unable to write to cache file!<br />Please chmod ./data/caches to 777 and try again.");');
  347. }
  348. $fp = @fopen($cachefile, 'wb');
  349. $cachedata = 'if(!defined(\'IN_MYMPS\')) exit(\'Access Denied\');
  350. $expiration = \'' . ($timestamp + $jscachelife) . '\';
  351. ' . $data . '
  352. ';
  353. @fwrite($fp, '<?php
  354. //Mymps cache file, DO NOT modify me!' . '
  355. //Created: ' . date('M j, Y, G:i') . '
  356. //Identify: ' . md5(basename($cachefile) . $cachedata) . ('
  357. ' . $cachedata . '?>'));
  358. @fclose($fp);
  359. }
  360. ?>