admincp_blockstyle.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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: admincp_blockstyle.php 32661 2013-02-28 06:29:46Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. cpheader();
  12. $operation = in_array($operation, array('add', 'edit', 'delete')) ? $operation : 'list';
  13. loadcache('blockclass');
  14. shownav('portal', 'blockstyle');
  15. if($operation=='add' || $operation=='edit') {
  16. if($operation=='edit') {
  17. showsubmenu('blockstyle', array(
  18. array('list', 'blockstyle', 0),
  19. array('edit', 'blockstyle&operation=edit&blockclass='.$_GET['blockclass'].'&styleid='.$_GET['styleid'], 1)
  20. ));
  21. } else {
  22. showsubmenu('blockstyle', array(
  23. array('list', 'blockstyle', 0),
  24. array('add', 'blockstyle&operation=add', 1)
  25. ));
  26. }
  27. include_once libfile('function/block');
  28. if(empty($_GET['blockclass'])) {
  29. $blockclass_sel = '<select name="blockclass">';
  30. $blockclass_sel .= '<option value="">'.cplang('blockstyle_blockclass_sel').'</option>';
  31. foreach($_G['cache']['blockclass'] as $key=>$value) {
  32. foreach($value['subs'] as $subkey=>$subvalue) {
  33. $blockclass_sel .= "<option value=\"$subkey\">$subvalue[name]</option>";
  34. }
  35. }
  36. $blockclass_sel .= '</select>';
  37. $adminscript = ADMINSCRIPT;
  38. $lang_blockclasssel = cplang('blockstyle_blockclass_sel');
  39. $lang_submit = cplang('submit');
  40. echo <<<BLOCKCLASSSEL
  41. <form method="get" autocomplete="off" action="$adminscript">
  42. <div style="margin-top:8px;">
  43. <table cellspacing="3" cellpadding="3">
  44. <tr>
  45. <th>$lang_blockclasssel</th><td>$blockclass_sel</td>
  46. </tr>
  47. <tr>
  48. <th>&nbsp;</th>
  49. <td>
  50. <input type="hidden" name="action" value="blockstyle" />
  51. <input type="hidden" name="operation" value="add" />
  52. <input type="submit" value="$lang_submit" class="btn" />
  53. </td>
  54. </tr>
  55. </table>
  56. </div>
  57. </form>
  58. BLOCKCLASSSEL;
  59. } else {
  60. showtips('blockstyle_add_tips');
  61. if(submitcheck('stylesubmit')) {
  62. $arr = array(
  63. 'name' => $_POST['name'],
  64. 'blockclass' => $_GET['blockclass'],
  65. );
  66. $_POST['template'] = $_POST['template'];
  67. include_once libfile('function/block');
  68. block_parse_template($_POST['template'], $arr);
  69. if($_GET['styleid']) {
  70. $styleid = intval($_GET['styleid']);
  71. C::t('common_block_style')->update($styleid, $arr);
  72. require_once libfile('function/cache');
  73. updatecache('blockclass');
  74. cpmsg('blockstyle_edit_succeed', 'action=blockstyle&operation=edit&blockclass='.$_GET['blockclass'].'&styleid='.$styleid.'&preview='.($_POST['preview']?'1':'0'), 'succeed');
  75. } else {
  76. $styleid = C::t('common_block_style')->insert($arr, true);
  77. $msg = 'blockstyle_create_succeed';
  78. require_once libfile('function/cache');
  79. updatecache('blockclass');
  80. cpmsg('blockstyle_create_succeed', 'action=blockstyle&operation=edit&blockclass='.$_GET['blockclass'].'&styleid='.$styleid.'&preview='.($_POST['preview']?'1':'0'), 'succeed');
  81. }
  82. }
  83. if($_GET['styleid']) {
  84. $_GET['styleid'] = intval($_GET['styleid']);
  85. include_once libfile('function/block');
  86. $thestyle = block_getstyle($_GET['styleid']);
  87. if(!$thestyle) {
  88. cpmsg('blockstyle_not_found!');
  89. }
  90. $thestyle['template'] = block_build_template($thestyle['template']);
  91. $_GET['blockclass'] = $thestyle['blockclass'];
  92. } else {
  93. $_GET['styleid'] = 0;
  94. $thestyle = array(
  95. 'template' => "<div class=\"module cl\">\n<ul>\n[loop]\n\t<li><a href=\"{url}\"{target}>{title}</a></li>\n[/loop]\n</ul>\n</div>"
  96. );
  97. }
  98. $theclass = block_getclass($_GET['blockclass']);
  99. if($preview) {
  100. echo '<h4 style="margin-bottom:15px;">'.lang('preview').'</h4>'.$preview;
  101. }
  102. showformheader('blockstyle&operation='.$operation.'&blockclass='.$_GET['blockclass'].'&styleid='.$_GET['styleid']);
  103. showtableheader();
  104. if($_GET['styleid']) {
  105. showtitle('blockstyle_add_editstyle');
  106. } else {
  107. showtitle('blockstyle_add_addstyle');
  108. }
  109. showsetting('blockstyle_name', 'name', $thestyle['name'], 'text');
  110. showtablefooter();
  111. $template = '';
  112. foreach($theclass['fields'] as $key=>$value) {
  113. if($value['name']) {
  114. $template .= $value['name']. ': <a href="###" onclick="insertunit($(\'jstemplate\'), \'{'.$key.'}\')">{'.$key.'}</a>';
  115. }
  116. }
  117. $template .= '<br />';
  118. $template .= cplang('blockstyle_add_loop').': <a href="###" onclick="insertunit($(\'jstemplate\'), \'[loop]\n\n[/loop]\')">[loop]...[/loop]</a>';
  119. $template .= cplang('blockstyle_add_order').': <a href="###" onclick="insertunit($(\'jstemplate\'), \'[order=N]\n\n[/order]\')">[order=N]...[/order]</a>';
  120. $template .= cplang('blockstyle_add_index').': <a href="###" onclick="insertunit($(\'jstemplate\'), \'[index=N]\n\n[/index]\')">[index=N]...[/index]</a>';
  121. $template .= cplang('blockstyle_add_urltitle').': <a href="###" onclick=\'insertunit($("jstemplate"), "<a href=\"{url}\"{target}>{title}</a>")\'>&lt;a href=...</a>';
  122. $template .= cplang('blockstyle_add_picthumb').': <a href="###" onclick=\'insertunit($("jstemplate"), "<img src=\"{pic}\" width=\"{picwidth}\" height=\"{picheight}\" />")\'>&lt;img src=...&gt;</a>';
  123. if(in_array($_GET['blockclass'], array('forum_thread', 'portal_article', 'group_thread'), true)) {
  124. $template .= cplang('blockstyle_add_moreurl').': <a href="###" onclick="insertunit($(\'jstemplate\'), \'{moreurl}\')">{moreurl}</a>';
  125. }
  126. $template .= cplang('blockstyle_add_currentorder').': <a href="###" onclick="insertunit($(\'jstemplate\'), \'{currentorder}\')">{currentorder}</a>';
  127. $template .= cplang('blockstyle_add_parity').': <a href="###" onclick="insertunit($(\'jstemplate\'), \'{parity}\')">{parity}</a>';
  128. $template .= '</div><br />';
  129. $template .= '<textarea cols="100" rows="5" id="jstemplate" name="template" style="width: 95%;" onkeyup="textareasize(this)" onkeydown="textareakey(this, event)">'.$thestyle['template'].'</textarea>';
  130. $template .= '<input type="hidden" name="preview" value="0" /><input type="hidden" name="stylesubmit" value="1" />';
  131. $template .= '<br /><!--input type="button" class="btn" onclick="this.form.preview=\'1\';this.form.submit()" value="'.$lang['preview'].'">&nbsp; &nbsp;--><input type="submit" class="btn" value="'.$lang['submit'].'"></div><br /><br />';
  132. echo '<div class="colorbox">';
  133. echo '<div class="extcredits">';
  134. echo $template;
  135. echo '</div>';
  136. showformfooter();
  137. }
  138. } elseif($operation=='delete') {
  139. $_GET['styleid'] = intval($_GET['styleid']);
  140. $thestyle = C::t('common_block_style')->fetch($_GET['styleid']);
  141. if(empty($thestyle)) {
  142. cpmsg('blockstyle_not_found', 'action=blockstyle', 'error');
  143. }
  144. $styles = array();
  145. if(($styles = C::t('common_block_style')->fetch_all_by_blockclass($thestyle['blockclass']))) {
  146. unset($styles[$_GET['styleid']]);
  147. }
  148. if(empty($styles)) {
  149. cpmsg('blockstyle_should_be_kept', 'action=blockstyle', 'error');
  150. }
  151. if(submitcheck('deletesubmit')) {
  152. $_POST['moveto'] = intval($_POST['moveto']);
  153. $newstyle = C::t('common_block_style')->fetch($_POST['moveto']);
  154. if($newstyle['blockclass'] != $thestyle['blockclass']) {
  155. cpmsg('blockstyle_blockclass_not_match', 'action=blockstyle', 'error');
  156. }
  157. C::t('common_block')->update_by_styleid($styleid, array('styleid' => $_POST[moveto]));
  158. C::t('common_block_style')->delete($_GET['styleid']);
  159. updatecache('blockclass');
  160. cpmsg('blockstyle_delete_succeed', 'action=blockstyle', 'succeed');
  161. }
  162. if(C::t('common_block')->fetch_by_styleid($_GET['styleid'])) {
  163. showtips('blockstyle_delete_tips');
  164. showformheader('blockstyle&operation=delete&styleid='.$_GET['styleid']);
  165. showtableheader();
  166. $movetoselect = '<select name="moveto">';
  167. foreach($styles as $key=>$value) {
  168. $movetoselect .= "<option value=\"$key\">$value[name]</option>";
  169. }
  170. $movetoselect .= '</select>';
  171. showsetting('blockstyle_moveto', '', '', $movetoselect);
  172. showsubmit('deletesubmit');
  173. showtablefooter();
  174. showformfooter();
  175. } else {
  176. C::t('common_block_style')->delete($_GET['styleid']);
  177. updatecache('blockclass');
  178. cpmsg('blockstyle_delete_succeed', 'action=blockstyle', 'succeed');
  179. }
  180. } else {
  181. $_GET = $_GET + $_POST;
  182. $searchctrl = '<span style="float: right; padding-right: 40px;">'
  183. .'<a href="javascript:;" onclick="$(\'tb_search\').style.display=\'\';$(\'a_search_show\').style.display=\'none\';$(\'a_search_hide\').style.display=\'\';" id="a_search_show" style="display:none">'.cplang('show_search').'</a>'
  184. .'<a href="javascript:;" onclick="$(\'tb_search\').style.display=\'none\';$(\'a_search_show\').style.display=\'\';$(\'a_search_hide\').style.display=\'none\';" id="a_search_hide">'.cplang('hide_search').'</a>'
  185. .'</span>';
  186. showsubmenu('blockstyle', array(
  187. array('list', 'blockstyle', 1),
  188. array('add', 'blockstyle&operation=add', 0)
  189. ), $searchctrl);
  190. $mpurl = ADMINSCRIPT.'?action=blockstyle';
  191. $intkeys = array('styleid');
  192. $strkeys = array('blockclass');
  193. $randkeys = array();
  194. $likekeys = array('name', 'template');
  195. $results = getwheres($intkeys, $strkeys, $randkeys, $likekeys);
  196. foreach($likekeys as $k) {
  197. $_GET[$k] = dhtmlspecialchars($_GET[$k]);
  198. }
  199. $wherearr = $results['wherearr'];
  200. $mpurl .= '&'.implode('&', $results['urls']);
  201. $wheresql = empty($wherearr)?'1':implode(' AND ', $wherearr);
  202. $orders = getorders(array('blockclass'), 'styleid');
  203. $ordersql = $orders['sql'];
  204. if($orders['urls']) $mpurl .= '&'.implode('&', $orders['urls']);
  205. $orderby = array($_GET['orderby']=>' selected');
  206. $ordersc = array($_GET['ordersc']=>' selected');
  207. $perpage = empty($_GET['perpage'])?0:intval($_GET['perpage']);
  208. if(!in_array($perpage, array(10,20,50,100))) $perpage = 20;
  209. $perpages = array($perpage=>' selected');
  210. $mpurl .= '&perpage='.$perpage;
  211. $searchlang = array();
  212. $keys = array('search', 'likesupport', 'resultsort', 'defaultsort', 'orderdesc', 'orderasc', 'perpage_10', 'perpage_20', 'perpage_50', 'perpage_100',
  213. 'blockstyle_id', 'blockstyle_name', 'blockstyle_blockclass', 'blockstyle_template');
  214. foreach ($keys as $key) {
  215. $searchlang[$key] = cplang($key);
  216. }
  217. $blockclass_sel = '<select name="blockclass">';
  218. $blockclass_sel .= '<option value="">'.cplang('blockstyle_blockclass_sel').'</option>';
  219. foreach($_G['cache']['blockclass'] as $key=>$value) {
  220. foreach($value['subs'] as $subkey=>$subvalue) {
  221. $selected = (!empty($_GET['blockclass']) && $subkey == $_GET['blockclass'] ? ' selected' : '');
  222. $blockclass_sel .= "<option value=\"$subkey\"$selected>$subvalue[name]</option>";
  223. }
  224. }
  225. $blockclass_sel .= '</select>';
  226. $adminscript = ADMINSCRIPT;
  227. echo <<<SEARCH
  228. <form method="post" autocomplete="off" action="$adminscript" id="tb_search">
  229. <div style="margin-top:8px;">
  230. <table cellspacing="3" cellpadding="3">
  231. <tr>
  232. <th>$searchlang[blockstyle_id]</th><td><input type="text" class="txt" name="styleid" value="$_GET[styleid]"></td>
  233. <th>$searchlang[blockstyle_name]*</th><td><input type="text" class="txt" name="name" value="$_GET[name]">*$searchlang[likesupport]</td>
  234. </tr>
  235. <tr>
  236. <th>$searchlang[blockstyle_blockclass]</th><td>$blockclass_sel</td>
  237. <th>$searchlang[blockstyle_template]*</th><td><input type="text" name="template" value="$_GET[template]">*$searchlang[likesupport]</td>
  238. </tr>
  239. <tr>
  240. <th>$searchlang[resultsort]</th>
  241. <td colspan="3">
  242. <select name="orderby">
  243. <option value="styleid">$searchlang[defaultsort]</option>
  244. <option value="blockclass"$orderby[blockclass]>$searchlang[blockstyle_blockclass]</option>
  245. </select>
  246. <select name="ordersc">
  247. <option value="desc"$ordersc[desc]>$searchlang[orderdesc]</option>
  248. <option value="asc"$ordersc[asc]>$searchlang[orderasc]</option>
  249. </select>
  250. <select name="perpage">
  251. <option value="10"$perpages[10]>$searchlang[perpage_10]</option>
  252. <option value="20"$perpages[20]>$searchlang[perpage_20]</option>
  253. <option value="50"$perpages[50]>$searchlang[perpage_50]</option>
  254. <option value="100"$perpages[100]>$searchlang[perpage_100]</option>
  255. </select>
  256. <input type="hidden" name="action" value="blockstyle">
  257. <input type="submit" name="searchsubmit" value="$searchlang[search]" class="btn">
  258. </td>
  259. </tr>
  260. </table>
  261. </div>
  262. </form>
  263. SEARCH;
  264. $start = ($page-1)*$perpage;
  265. showformheader('blockstyle');
  266. showtableheader('blockstyle_list');
  267. showsubtitle(array('blockstyle_name', 'blockstyle_blockclass', 'operation'));
  268. $multipage = '';
  269. if(($count = C::t(common_block_style)->count_by_where($wheresql))) {
  270. include_once libfile('function/block');
  271. foreach(C::t('common_block_style')->fetch_all_by_where($wheresql, $ordersql, $start, $perpage) as $value) {
  272. $theclass = block_getclass($value['blockclass']);
  273. list($c1, $c2) = explode('_', $value['blockclass']);
  274. showtablerow('', array('class=""', 'class=""', 'class="td28"'), array(
  275. $value['name'],
  276. $theclass['name'],
  277. "<a href=\"".ADMINSCRIPT."?action=blockstyle&operation=edit&blockclass=$value[blockclass]&styleid=$value[styleid]\">".cplang('blockstyle_edit')."</a>&nbsp;&nbsp;".
  278. "<a href=\"".ADMINSCRIPT."?action=blockstyle&operation=delete&styleid=$value[styleid]\">".cplang('blockstyle_delete')."</a>"
  279. ));
  280. }
  281. $multipage = multi($count, $perpage, $page, $mpurl);
  282. }
  283. showsubmit('', '', '', '', $multipage);
  284. showtablefooter();
  285. showformfooter();
  286. }
  287. ?>