resource_setting.inc.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: resource_setting.inc.php 34815 2014-08-07 02:04:50Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. require_once DISCUZ_ROOT.'./source/plugin/wechat/wechat.lib.class.php';
  12. require_once DISCUZ_ROOT.'./source/plugin/wechat/setting.class.php';
  13. WeChatSetting::menu();
  14. define('RSELF', 'action=plugins&operation=config&identifier=wechat&pmod=resource_setting&ac=');
  15. $select = array(-1 => lang('plugin/wechat', 'resource_type_all'), 0 => lang('plugin/wechat', 'resource_type_s'), 1 => lang('plugin/wechat', 'resource_type_m'));
  16. $ac = !empty($_GET['ac']) ? $_GET['ac'] : '';
  17. $filter = isset($_GET['filter']) ? intval($_GET['filter']) : -1;
  18. if(!$_POST) {
  19. if(!$ac) {
  20. $ppp = 9;
  21. $page = max(1, $_GET['page']);
  22. $start = ($page - 1) * $ppp;
  23. $count = C::t('#wechat#mobile_wechat_resource')->count_by_type($filter >= 0 ? $filter : null);
  24. $resource = C::t('#wechat#mobile_wechat_resource')->fetch_by_type($filter >= 0 ? $filter : null, $start, $ppp);
  25. $multi = multi($count, $ppp, $page, ADMINSCRIPT.'?'.RSELF.'&filter='.$filter);
  26. wxbox_style();
  27. echo <<<EOF
  28. <script>
  29. var cookiepre = '{$_G[config][cookie][cookiepre]}', cookiedomain = '{$_G[config][cookie][cookiedomain]}', cookiepath = '{$_G[config][cookie][cookiepath]}';
  30. function merge(id, type) {
  31. mids = getcookie('wechat_rids');
  32. var re = new RegExp('_' + id + '_', "g");
  33. mids = mids.replace(re, '');
  34. if(type) {
  35. mids += '_' + id + '_';
  36. }
  37. setcookie('wechat_rids', mids);
  38. showmerge();
  39. }
  40. function clearmerge() {
  41. setcookie('wechat_rids', '', -1);
  42. location.href = location.href;
  43. }
  44. function showmerge() {
  45. $('mergebtn').style.display = getcookie('wechat_rids') ? '' : 'none';
  46. }
  47. </script>
  48. EOF;
  49. showtableheader();
  50. $wechat_rids = explode('_', $_G['cookie']['wechat_rids']);
  51. foreach($select as $k => &$row) {
  52. $row = '<option value="'.$k.'"'.($k == $filter ? ' selected' : '').'>'.$row.'</option>';
  53. }
  54. $select = '<select onchange="location.href=\''.ADMINSCRIPT.'?'.RSELF.'&filter=\' + this.value">'.implode('', $select).'</select> ';
  55. foreach($resource as $row) {
  56. $row = dhtmlspecialchars($row);
  57. echo '<table class="left tb2 wxbox">'
  58. . '<tr class="header"><th class="partition">'.$row['name'].'<br />'
  59. . '<div>'
  60. . '<span>'
  61. . (!$row['type']
  62. ? '<label><input class="pc" type="checkbox" '.(in_array($row['id'], $wechat_rids)
  63. ? 'checked '
  64. : '')
  65. . 'onclick="merge('.$row['id'].', this.checked)"><a>'.lang('plugin/wechat', 'resource_merge').'</a></label> '
  66. : '<a href="'.ADMINSCRIPT.'?'.RSELF.'addmerge&id='.$row['id'].'" class="addtr">'.lang('plugin/wechat', 'resource_append_merge').'</a> ')
  67. . '<a href="'.ADMINSCRIPT.'?'.RSELF.'edit&id='.$row['id'].'">'.lang('plugin/wechat', 'resource_edit').'</a> '
  68. . '<a href="'.ADMINSCRIPT.'?'.RSELF.'delete&id='.$row['id'].'">'.lang('plugin/wechat', 'resource_del').'</a>'
  69. . '</span>'
  70. . dgmdate($row['dateline']).'</div></th></tr>'
  71. . (!$row['type']
  72. ? '<tr><td class="l1" title="'.$row['data']['title'].'">'.$row['data']['title'].'</td></tr>'
  73. . '<tr><td class="l2"><div>'.($row['data']['pic'] ? '<img src="'.$row['data']['pic'].'" />' : '').'</div></td></tr>'
  74. . '<tr><td class="l3">'.$row['data']['desc'].'</td></tr>'
  75. : '<tr><td class="l1">'.lang('plugin/wechat', 'resource_type_m').'</td></tr>'
  76. . '<tr><td class="l2">'.lang('plugin/wechat', 'resource_merge_count', array('count' => count($row['data']['mergeids']))).'<br /><a href="'.ADMINSCRIPT.'?'.RSELF.'edit&id='.$row['id'].'">'.lang('plugin/wechat', 'resource_view').'</a></td></tr>'
  77. . '<tr><td class="l3"></td></tr>')
  78. . '</table>';
  79. }
  80. showtablefooter();
  81. echo '<br style="clear:both"><div class="right pg">'.$multi.'</div>';
  82. echo $select.'<a href="'.ADMINSCRIPT.'?'.RSELF.'add" class="addtr">'.lang('plugin/wechat', 'resource_add').'</a> &nbsp;'
  83. . '<span id="mergebtn" '.($_G['cookie']['wechat_rids'] ? '' : ' style="display:none"').'>'
  84. . '<a href="'.ADMINSCRIPT.'?'.RSELF.'addmerge" class="addtr">'.lang('plugin/wechat', 'resource_type_m').'</a>'
  85. . '<a href="javascript:;" onclick="clearmerge()" class="lightfont">'.lang('plugin/wechat', 'resource_cancel_merge').'</a>'
  86. . '</span>';
  87. } elseif($ac == 'add') {
  88. showformheader('plugins&operation=config&identifier=wechat&pmod=resource_setting&ac=add', 'enctype');
  89. showtableheader();
  90. showsetting(lang('plugin/wechat', 'resource_name'), 'name', '', 'text');
  91. showsetting(lang('plugin/wechat', 'resource_title'), 'data[title]', '', 'text');
  92. showsetting(lang('plugin/wechat', 'resource_pic'), 'pic', '', 'filetext');
  93. showsetting(lang('plugin/wechat', 'resource_desc'), 'data[desc]', '', 'textarea');
  94. showsetting(lang('plugin/wechat', 'resource_content'), 'data[content]', '', 'textarea');
  95. showsetting(lang('plugin/wechat', 'resource_url'), 'data[url]', '', 'text');
  96. showsubmit('addsubmit');
  97. showtablefooter();
  98. showformfooter();
  99. } elseif($ac == 'addmerge') {
  100. $wechat_rids = explode('_', $_G['cookie']['wechat_rids']);
  101. $resource = C::t('#wechat#mobile_wechat_resource')->fetch_all($wechat_rids);
  102. if($_GET['id']) {
  103. $aresource = C::t('#wechat#mobile_wechat_resource')->fetch($_GET['id']);
  104. foreach($resource as $row) {
  105. if(!$aresource['data']['mergeids'][$row['id']]) {
  106. $aresource['data']['mergeids'][$row['id']] = 0;
  107. }
  108. }
  109. asort($aresource['data']['mergeids']);
  110. $data = array(
  111. 'data' => $aresource['data'],
  112. );
  113. C::t('#wechat#mobile_wechat_resource')->update($_GET['id'], $data);
  114. dsetcookie('wechat_rids', '', -1);
  115. dheader('location: '.ADMINSCRIPT.'?'.RSELF.'edit&id='.$_GET['id']);
  116. }
  117. showformheader('plugins&operation=config&identifier=wechat&pmod=resource_setting&ac=add');
  118. showtableheader();
  119. showsetting(lang('plugin/wechat', 'resource_name'), 'name', '', 'text');
  120. showtablefooter();
  121. showtableheader();
  122. echo '<tr class="header"><th>'.lang('plugin/wechat', 'resource_name').'</th><th>'.lang('plugin/wechat', 'resource_order').'</th></tr>';
  123. $i = 0;
  124. foreach($resource as $row) {
  125. echo '<tr><td><a href="'.ADMINSCRIPT.'?'.RSELF.'edit&id='.$row['id'].'">'.$row['name'].'</a></td><td><input name="data[mergeids]['.$row['id'].']" value="'.(++$i).'"></td></tr>';
  126. }
  127. showsubmit('addmergesubmit');
  128. showtablefooter();
  129. showformfooter();
  130. } elseif($ac == 'edit') {
  131. $resource = C::t('#wechat#mobile_wechat_resource')->fetch($_GET['id']);
  132. if(!$resource) {
  133. cpmsg(lang('plugin/wechat', 'resource_msg_nofound'), '', 'error');
  134. }
  135. if(!$resource['type']) {
  136. showformheader('plugins&operation=config&identifier=wechat&pmod=resource_setting&ac=edit&id='.$_GET['id'], 'enctype');
  137. showtableheader();
  138. showsetting(lang('plugin/wechat', 'resource_name'), 'name', $resource['name'], 'text');
  139. showsetting(lang('plugin/wechat', 'resource_title'), 'data[title]', $resource['data']['title'], 'text');
  140. showsetting(lang('plugin/wechat', 'resource_pic'), 'pic', $resource['data']['pic'], 'filetext');
  141. showsetting(lang('plugin/wechat', 'resource_desc'), 'data[desc]', $resource['data']['desc'], 'textarea');
  142. showsetting(lang('plugin/wechat', 'resource_content'), 'data[content]', $resource['data']['content'], 'textarea');
  143. showsetting(lang('plugin/wechat', 'resource_url'), 'data[url]', $resource['data']['url'], 'text');
  144. showsubmit('editsubmit');
  145. showtablefooter();
  146. showformfooter();
  147. } else {
  148. $mergeids = array_keys($resource['data']['mergeids']);
  149. if(!$mergeids) {
  150. cpmsg(lang('plugin/wechat', 'resource_msg_nofound'), '', 'error');
  151. }
  152. $sresource = C::t('#wechat#mobile_wechat_resource')->fetch_all($mergeids);
  153. showformheader('plugins&operation=config&identifier=wechat&pmod=resource_setting&ac=edit&id='.$_GET['id']);
  154. showtableheader();
  155. showsetting(lang('plugin/wechat', 'resource_name'), 'name', $resource['name'], 'text');
  156. showtablefooter();
  157. showtableheader();
  158. $i = 0;
  159. wxbox_style();
  160. foreach($resource['data']['mergeids'] as $id => $order) {
  161. $row = dhtmlspecialchars($sresource[$id]);
  162. echo '<table class="left tb2 wxbox">'
  163. . '<tr class="header"><th class="partition">'.$row['name'].'<br />'
  164. . '<div>'
  165. . '<span>'
  166. . '<a href="'.ADMINSCRIPT.'?'.RSELF.'edit&id='.$row['id'].'" target="_blank">'.lang('plugin/wechat', 'resource_edit').'</a> '
  167. . '<a href="'.ADMINSCRIPT.'?'.RSELF.'removemerge&id='.$row['id'].'&fromid='.$_GET['id'].'">'.lang('plugin/wechat', 'resource_remove').'</a> '
  168. . lang('plugin/wechat', 'resource_order').'<input name="data[mergeids]['.$id.']" class="txt" value="'.$order.'">'
  169. . '</span>'
  170. . dgmdate($row['dateline']).'</div></th></tr>'
  171. . '<tr><td class="l1" title="'.$row['data']['title'].'">'.$row['data']['title'].'</td></tr>'
  172. . '<tr><td class="l2"><div>'.($row['data']['pic'] ? '<img src="'.$row['data']['pic'].'" />' : '').'</div></td></tr>'
  173. . '<tr><td class="l3">'.$row['data']['desc'].'</td></tr>'
  174. . '</table>';
  175. }
  176. showtablefooter();
  177. showtableheader();
  178. showsubmit('editmergesubmit');
  179. showtablefooter();
  180. showformfooter();
  181. }
  182. } elseif($ac == 'delete') {
  183. cpmsg(lang('plugin/wechat', 'resource_msg_del'), RSELF.'&id='.$_GET['id'].'&delsubmit=yes', 'form');
  184. } elseif($ac == 'removemerge') {
  185. cpmsg(lang('plugin/wechat', 'resource_msg_remove'), RSELF.'&id='.$_GET['id'].'&fromid='.$_GET['fromid'].'&removesubmit=yes', 'form');
  186. } elseif($ac == 'select') {
  187. include template('common/header_ajax');
  188. $ppp = 6;
  189. $page = max(1, $_GET['page']);
  190. $start = ($page - 1) * $ppp;
  191. $count = C::t('#wechat#mobile_wechat_resource')->count_by_type($filter >= 0 ? $filter : null);
  192. $resource = C::t('#wechat#mobile_wechat_resource')->fetch_by_type($filter >= 0 ? $filter : null, $start, $ppp);
  193. $multi = multi($count, $ppp, $page, ADMINSCRIPT.'?action=plugins&operation=config&identifier=wechat&pmod=resource_setting&ac=select&filter='.$filter);
  194. wxbox_style();
  195. foreach($select as $k => &$row) {
  196. $row = '<option value="'.$k.'"'.($k == $filter ? ' selected' : '').'>'.$row.'</option>';
  197. }
  198. $select = '<select onchange="ajaxget(\''.ADMINSCRIPT.'?action=plugins&operation=config&identifier=wechat&pmod=resource_setting&ac=select&filter=\' + this.value, \'rsel_content\')">'.implode('', $select).'</select> ';
  199. echo '<div class="pg"><div class="right">'.$multi.'</div>'.$select.'</div>';
  200. showtableheader();
  201. $wechat_rids = explode('_', $_G['cookie']['wechat_rids']);
  202. foreach($resource as $row) {
  203. $row = dhtmlspecialchars($row);
  204. echo '<table class="left tb2 wxbox hover" onclick="selResource('.$row['id'].', \''.$row['name'].'\')">'
  205. . '<tr class="header"><th class="partition">'.$row['name'].'</tr>'
  206. . (!$row['type']
  207. ? '<tr><td class="l1" title="'.$row['data']['title'].'">'.$row['data']['title'].'</td></tr>'
  208. . '<tr><td class="l2"><div>'.($row['data']['pic'] ? '<img src="'.$row['data']['pic'].'" width="290" />' : '').'</div></td></tr>'
  209. : '<tr><td class="l1">'.lang('plugin/wechat', 'resource_type_m').'</td></tr>'
  210. . '<tr><td class="l2">'.lang('plugin/wechat', 'resource_merge_count', array('count' => count($row['data']['mergeids']))).'<br /><a href="javascript:;" onclick="window.open(\''.ADMINSCRIPT.'?'.RSELF.'edit&id='.$row['id'].'\');doane(event)" target="_blank">'.lang('plugin/wechat', 'resource_view').'</a></td></tr>')
  211. . '</table>';
  212. }
  213. showtablefooter();
  214. include template('common/footer_ajax');
  215. }
  216. } elseif(submitcheck('addsubmit')) {
  217. if(dstrlen($_GET['data']['desc'], CHARSET) > 120) {
  218. cpmsg(lang('plugin/wechat', 'resource_msg_desc_toolong'), '', 'error');
  219. }
  220. if($_FILES['pic']['tmp_name']) {
  221. $upload = new discuz_upload();
  222. if(!getimagesize($_FILES['pic']['tmp_name']) || !$upload->init($_FILES['pic'], 'common', random(3, 1), random(8)) || !$upload->save()) {
  223. cpmsg($upload->errormessage(), '', 'error');
  224. }
  225. $_GET['data']['pic'] = (preg_match('/^http:/', $_G['setting']['attachurl']) ? '' : $_G['siteurl']).$_G['setting']['attachurl'].'common/'.$upload->attach['attachment'];
  226. $_GET['data']['local'] = $upload->attach['attachment'];
  227. } else {
  228. $_GET['data']['pic'] = $_GET['pic'];
  229. }
  230. $data = array(
  231. 'name' => $_GET['name'],
  232. 'data' => $_GET['data'],
  233. );
  234. C::t('#wechat#mobile_wechat_resource')->insert($data);
  235. cpmsg('setting_update_succeed', RSELF, 'succeed');
  236. } elseif(submitcheck('editsubmit')) {
  237. $resource = C::t('#wechat#mobile_wechat_resource')->fetch($_GET['id']);
  238. if(!$resource) {
  239. cpmsg(lang('plugin/wechat', 'resource_msg_nofound'), '', 'error');
  240. }
  241. if(dstrlen($_GET['data']['desc'], CHARSET) > 120) {
  242. cpmsg(lang('plugin/wechat', 'resource_msg_desc_toolong'), '', 'error');
  243. }
  244. if($_FILES['pic']['tmp_name']) {
  245. $upload = new discuz_upload();
  246. if(!getimagesize($_FILES['pic']['tmp_name']) || !$upload->init($_FILES['pic'], 'common', random(3, 1), random(8)) || !$upload->save()) {
  247. cpmsg($upload->errormessage(), '', 'error');
  248. }
  249. $_GET['data']['pic'] = (preg_match('/^http:/', $_G['setting']['attachurl']) ? '' : $_G['siteurl']).$_G['setting']['attachurl'].'common/'.$upload->attach['attachment'];
  250. $_GET['data']['local'] = $upload->attach['attachment'];
  251. @unlink($_G['setting']['attachdir'].'common/'.$resource['data']['local']);
  252. } else {
  253. $_GET['data']['pic'] = $_GET['pic'];
  254. }
  255. $data = array(
  256. 'name' => $_GET['name'],
  257. 'data' => $_GET['data'],
  258. );
  259. C::t('#wechat#mobile_wechat_resource')->update($_GET['id'], $data);
  260. cpmsg('setting_update_succeed', RSELF, 'succeed');
  261. } elseif(submitcheck('delsubmit')) {
  262. $resource = C::t('#wechat#mobile_wechat_resource')->fetch($_GET['id']);
  263. if(!$resource) {
  264. cpmsg(lang('plugin/wechat', 'resource_msg_nofound'), '', 'error');
  265. }
  266. if($resource['data']['local']) {
  267. @unlink($_G['setting']['attachdir'].'common/'.$resource['data']['local']);
  268. }
  269. C::t('#wechat#mobile_wechat_resource')->delete($_GET['id']);
  270. cpmsg('setting_update_succeed', RSELF, 'succeed');
  271. } elseif(submitcheck('addmergesubmit')) {
  272. asort($_GET['data']['mergeids']);
  273. $data = array(
  274. 'name' => $_GET['name'],
  275. 'type' => 1,
  276. 'data' => $_GET['data'],
  277. );
  278. C::t('#wechat#mobile_wechat_resource')->insert($data);
  279. dsetcookie('wechat_rids', '', -1);
  280. cpmsg('setting_update_succeed', RSELF, 'succeed');
  281. } elseif(submitcheck('editmergesubmit')) {
  282. asort($_GET['data']['mergeids']);
  283. $data = array(
  284. 'name' => $_GET['name'],
  285. 'data' => $_GET['data'],
  286. );
  287. C::t('#wechat#mobile_wechat_resource')->update($_GET['id'], $data);
  288. dsetcookie('wechat_rids', '', -1);
  289. cpmsg('setting_update_succeed', RSELF.'edit&id='.$_GET['id'], 'succeed');
  290. } elseif(submitcheck('removesubmit')) {
  291. $resource = C::t('#wechat#mobile_wechat_resource')->fetch($_GET['fromid']);
  292. if(!$resource) {
  293. cpmsg(lang('plugin/wechat', 'resource_msg_nofound'), '', 'error');
  294. }
  295. unset($resource['data']['mergeids'][$_GET['id']]);
  296. $data = array(
  297. 'data' => $resource['data'],
  298. );
  299. C::t('#wechat#mobile_wechat_resource')->update($_GET['fromid'], $data);
  300. cpmsg('setting_update_succeed', RSELF.'edit&id='.$_GET['fromid'], 'succeed');
  301. }
  302. function wxbox_style() {
  303. echo <<<EOF
  304. <style>
  305. .wxbox { table-layout: fixed; margin:0 5px 10px 0;width:300px;height:300px; }
  306. .wxbox td { padding:0 2px;border: none; }
  307. .wxbox th { height: 50px; white-space: nowrap; }
  308. .wxbox th div { font-weight:normal; }
  309. .wxbox th div span { float:right; }
  310. .wxbox th div .txt { width: 40px; }
  311. .wxbox .l1 { height: 30px; line-height: 30px;overflow:hidden;text-overflow:ellipsis;white-space: nowrap; }
  312. .wxbox .l2 { text-align:center; }
  313. .wxbox .l2 img { width: 290px; }
  314. .wxbox .l2 div { width: 290px;height: 160px; display:block; overflow:hidden; }
  315. .wxbox .l3 { height: 80px; vertical-align:top;line-height:25px; }
  316. .wxbox.hover { height:220px; }
  317. .wxbox.hover th { height:20px; }
  318. </style>
  319. EOF;
  320. }
  321. ?>