PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/source/include/portalcp/portalcp_block.php

https://github.com/jinbo51/DiscuzX
PHP | 1061 lines | 944 code | 111 blank | 6 comment | 304 complexity | a57c0bb020a3f8167275d7eb57c6f0be MD5 | raw file
Possible License(s): BSD-3-Clause
  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: portalcp_block.php 32281 2012-12-18 04:48:04Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. include_once libfile('function/block');
  12. $oparr = array('block', 'data', 'style', 'itemdata', 'setting', 'remove', 'item', 'additem', 'blockclass',
  13. 'getblock', 'thumbsetting', 'push', 'recommend', 'verifydata', 'managedata',
  14. 'saveblockclassname', 'saveblocktitle', 'convert', 'favorite', 'banids', 'delrecommend', 'moreurl');
  15. $op = in_array($_GET['op'], $oparr, true) ? $_GET['op'] : 'block';
  16. $_GET['from'] = $_GET['from'] == 'cp' ? 'cp' : null;
  17. $allowmanage = $allowdata = 0;
  18. $block = array();
  19. $bid = !empty($_GET['bid']) ? intval($_GET['bid']) : 0;
  20. if($bid) {
  21. if(!($block = C::t('common_block')->fetch($bid))) {
  22. showmessage('block_not_exist');
  23. }
  24. $blockstyle = array();
  25. if(!empty($block['styleid'])) {
  26. $blockstyle = block_getstyle($block['styleid']);
  27. } else {
  28. $blockstyle = dunserialize($block['blockstyle']);
  29. }
  30. $block['moreurl'] = $blockstyle['moreurl'] && in_array($block['blockclass'], array('forum_thread', 'portal_article', 'group_thread'), true) ? 1 : 0;
  31. $_G['block'][$bid] = $block;
  32. $blockperm = getblockperm($bid);
  33. if($blockperm['allowmanage']) {
  34. $allowmanage = 1;
  35. $allowdata = 1;
  36. }
  37. if ($blockperm['allowrecommend'] && !$blockperm['needverify']) {
  38. $allowdata = 1;
  39. }
  40. }
  41. if(empty($block['bid'])) {
  42. $bid = 0;
  43. }
  44. $_GET['classname'] = !empty($_GET['classname']) ? $_GET['classname'] : ($block ? $block['blockclass'] : 'html_html');
  45. $theclass = block_getclass($_GET['classname'], true);
  46. $theclass['script'] = isset($theclass['script']) ? $theclass['script'] : array();
  47. if(!empty($_GET['styleid']) && isset($theclass['style'][$_GET['styleid']])) {
  48. $thestyle = $theclass['style'][$_GET['styleid']];
  49. } elseif(isset($theclass['style'][$block['styleid']])) {
  50. $_GET['styleid'] = intval($block['styleid']);
  51. $thestyle = $theclass['style'][$_GET['styleid']];
  52. } else {
  53. $_GET['styleid'] = 0;
  54. $thestyle = (array)dunserialize($block['blockstyle']);
  55. }
  56. $_GET['script'] = !empty($_GET['script']) && isset($theclass['script'][$_GET['script']])
  57. ? $_GET['script']
  58. : (!empty($block['script']) ? $block['script'] : key($theclass['script']));
  59. $blocktype = (!empty($_GET['blocktype']) || !empty($block['blocktype'])) ? 1 : 0;
  60. $nocachetime = in_array($_GET['script'], array('blank', 'line', 'banner', 'vedio', 'google')) ? true : false;
  61. $is_htmlblock = ($_GET['classname'] == 'html_html') ? 1 : 0;
  62. $showhtmltip = false;
  63. if($op == 'data' && $is_htmlblock) {
  64. $op = 'block';
  65. $showhtmltip = true;
  66. }
  67. $block['blockclass'] = empty($block['blockclass']) ? $_GET['classname'] : $block['blockclass'];
  68. $is_recommendable = block_isrecommendable($block);
  69. if($op == 'block') {
  70. if($bid && !$allowmanage) {
  71. showmessage('block_edit_nopermission');
  72. }
  73. if(!$bid) {
  74. list($tpl, $id) = explode(':', $_GET['tpl']);
  75. if(trim($tpl)=='portal/portal_topic_content') {
  76. if(!$_G['group']['allowaddtopic'] && !$_G['group']['allowmanagetopic']) {
  77. showmessage('block_topic_nopermission');
  78. }
  79. } elseif(!$_G['group']['allowdiy']) {
  80. showmessage('block_add_nopermission');
  81. }
  82. }
  83. if(submitcheck('blocksubmit')) {
  84. $_POST['cachetime'] = intval($_POST['cachetime']) * 60;
  85. $_POST['styleid'] = intval($_POST['styleid']);
  86. $_POST['shownum'] = intval($_POST['shownum']);
  87. $_POST['picwidth'] = $_POST['picwidth'] ? intval($_POST['picwidth']) : 0;
  88. $_POST['picheight'] = $_POST['picheight'] ? intval($_POST['picheight']) : 0;
  89. $_POST['script'] = isset($theclass['script'][$_POST['script']]) ? $_POST['script'] : key($theclass['script']);
  90. $_POST['a_target'] = in_array($_POST['a_target'], array('blank', 'top', 'self')) ? $_POST['a_target'] : 'blank';
  91. $_POST['dateformat'] = in_array($_POST['dateformat'], array('Y-m-d', 'm-d', 'H:i', 'Y-m-d H:i')) ? $_POST['dateformat'] : 'Y-m-d';
  92. $_POST['isblank'] = intval($_POST['isblank']);
  93. $_POST['cachetimerangestart'] = intval($_POST['cachetimerangestart']);
  94. $_POST['cachetimerangeend'] = intval($_POST['cachetimerangeend']);
  95. $summary = getstr($_POST['summary'], '', 0, 0, 0, 1);
  96. if($summary) {
  97. $tag = block_ckeck_summary($summary);
  98. if($tag != $summary) {
  99. $msg = lang('portalcp', 'block_diy_summary_html_tag').$tag.lang('portalcp', 'block_diy_summary_not_closed');
  100. showmessage($msg);
  101. }
  102. }
  103. $_POST['shownum'] = $_POST['shownum'] > 0 ? $_POST['shownum'] : 10;
  104. $_POST['parameter']['items'] = $_POST['shownum'];
  105. $cachetimerange = $_POST['cachetimerangestart'].','.$_POST['cachetimerangeend'];
  106. if(empty($_G['setting']['blockcachetimerange'])) {
  107. $cachetimerange = $cachetimerange == '0,23' ? '' : $cachetimerange;
  108. } else {
  109. $cachetimerange = $cachetimerange == $_G['setting']['blockcachetimerange'] ? '' : $cachetimerange;
  110. }
  111. include_once libfile('function/home');
  112. $setarr = array(
  113. 'name' => getstr($_POST['name'], 255),
  114. 'summary' => $summary,
  115. 'styleid' => $_POST['styleid'],
  116. 'script' => $_POST['script'],
  117. 'cachetime' => intval($_POST['cachetime']),
  118. 'cachetimerange' => $cachetimerange,
  119. 'punctualupdate' => !empty($_POST['punctualupdate']) ? '1' : '0',
  120. 'shownum' => $_POST['shownum'],
  121. 'picwidth' => $_POST['picwidth'] && $_POST['picwidth'] > 8 && $_POST['picwidth'] < 1960 ? $_POST['picwidth'] : 0,
  122. 'picheight' => $_POST['picheight'] && $_POST['picheight'] > 8 && $_POST['picheight'] < 1960 ? $_POST['picheight'] : 0,
  123. 'target' => $_POST['a_target'],
  124. 'dateuformat' => !empty($_POST['dateuformat']) ? '1' : '0',
  125. 'dateformat' => $_POST['dateformat'],
  126. 'hidedisplay' => $_POST['hidedisplay'] ? '1' : '0',
  127. 'dateline' => TIMESTAMP,
  128. 'isblank' => $_POST['isblank']
  129. );
  130. $picdata = array();
  131. if(!empty($_FILES)) {
  132. foreach($_FILES as $varname => $file) {
  133. if($file['tmp_name']) {
  134. $result = pic_upload($file, 'portal');
  135. $pic = 'portal/'.$result['pic'];
  136. $picdata[] = array('bid' => $bid, 'pic' => $pic, 'picflag' =>$result['remote'] , 'type' => '1');
  137. $pic = $result['remote'] ? $_G['setting']['ftp']['attachurl'].$pic : $_G['setting']['attachurl'].$pic;
  138. $_POST['parameter'][$varname] = $pic;
  139. }
  140. }
  141. }
  142. if(($block['blockclass'] == 'html_html' || $_GET['classname'] == 'html_html') && $_POST['script'] == 'blank' && isset($_POST['parameter']['content'])) {
  143. $_POST['parameter']['content'] = addslashes($_POST['parameter']['content']);
  144. }
  145. $parameter = $_POST['parameter'];
  146. if(isset($block['param'])) {
  147. $blockobj = block_script($block['blockclass'], $block['script']);
  148. if($blockobj) {
  149. $_block_setting = $blockobj->getsetting();
  150. foreach($block['param'] as $_key => $_val) {
  151. if(!isset($parameter[$_key]) && (!isset($_block_setting[$_key]) || (isset($_block_setting[$_key]) && $_block_setting[$_key]['type'] !== 'mcheckbox'))) {
  152. $parameter[$_key] = $_val;
  153. }
  154. }
  155. } else {
  156. $parameter = $parameter + $block['param'];
  157. }
  158. }
  159. $setarr['param'] = serialize($parameter);
  160. if($bid) {
  161. C::t('common_block')->update($bid, $setarr);
  162. } else {
  163. $setarr['blockclass'] = $_GET['classname'];
  164. $setarr['uid'] = $_G['uid'];
  165. $setarr['username'] = $_G['username'];
  166. $setarr['notinherited'] = 0;
  167. if($blocktype == 1) {
  168. $setarr['blocktype'] = '1';
  169. }
  170. $bid = C::t('common_block')->insert($setarr, true);
  171. }
  172. if(!empty($picdata)) {
  173. C::t('common_block_pic')->insert_by_bid($bid, $picdata);
  174. }
  175. $_G['block'][$bid] = C::t('common_block')->fetch($bid);
  176. block_updatecache($bid, true);
  177. showmessage('do_success', 'portal.php?mod=portalcp&ac=block&op=block&bid='.$bid, array('bid'=>$bid, 'eleid'=> $_GET['eleid']));
  178. }
  179. loadcache('blockconvert');
  180. $block['script'] = isset($block['script']) ? $block['script'] : $_GET['script'];
  181. if($block['blockclass'] == 'html_html' && $block['script'] == 'blank'){
  182. $block['param']['content'] = stripslashes($block['param']['content']);
  183. }
  184. $settings = block_setting($_GET['classname'], $block['script'], $block['param']);
  185. $scriptarr = array($block['script'] => ' selected');
  186. $stylearr = array($_GET['styleid'] => ' selected');
  187. $block = block_checkdefault($block);
  188. $cachetimearr = array($block['cachetime'] =>' selected="selected"');
  189. $block['cachetime_min'] = intval($block['cachetime'] / 60);
  190. $targetarr[$block['target']] = ' selected';
  191. $block['cachetimerange'] = empty($block['cachetimerange']) ? (isset($_G['setting']['blockcachetimerange']) ? $_G['setting']['blockcachetimerange'] : '') : $block['cachetimerange'];
  192. $block['cachetimerange'] = empty($block['cachetimerange']) ? array('0', '23') : explode(',', $block['cachetimerange']);
  193. $cachetimerange = range(0, 23);
  194. $dateformats = block_getdateformats($block['dateformat']);
  195. $block['summary'] = dhtmlspecialchars($block['summary']);
  196. $blockclassname = '';
  197. $blockclass = $block['blockclass'] ? $block['blockclass'] : $_GET['classname'];
  198. $arr = explode('_', $blockclass);
  199. if(count($arr) == 2) {
  200. $blockclassname = $_G['cache']['blockclass'][$arr[0]]['subs'][$blockclass]['name'];
  201. }
  202. $blockclassname = empty($blockclassname) ? $blockclass : $blockclassname;
  203. } elseif($op == 'banids') {
  204. if(!$bid || (!$allowmanage && !$allowdata)) {
  205. showmessage('block_edit_nopermission');
  206. }
  207. if(isset($_GET['bannedids']) && $block['param']['bannedids'] != $_GET['bannedids']) {
  208. $arr = explode(',', $_GET['bannedids']);
  209. $arr = array_map('intval', $arr);
  210. $arr = array_filter($arr);
  211. $_GET['bannedids'] = implode(',', $arr);
  212. $block['param']['bannedids'] = $_GET['bannedids'];
  213. C::t('common_block')->update($bid, array('param'=>serialize($block['param'])));
  214. $_G['block'][$bid] = $block;
  215. block_updatecache($bid, true);
  216. }
  217. showmessage('do_success', 'portal.php?mod=portalcp&ac=block&op=data&bid='.$bid, array('bid'=>$bid, 'eleid'=> $_GET['eleid']));
  218. } elseif($op == 'data') {
  219. if(!$bid || (!$allowmanage && !$allowdata)) {
  220. showmessage('block_edit_nopermission');
  221. }
  222. if(submitcheck('updatesubmit')) {
  223. if($_POST['displayorder']) {
  224. asort($_POST['displayorder']);
  225. $orders = $ids = array();
  226. $order = 1;
  227. foreach($_POST['displayorder'] as $k=>$v) {
  228. $k = intval($k);
  229. $ids[] = $k;
  230. $orders[$k] = $order;
  231. $order++;
  232. }
  233. $items = array();
  234. foreach(C::t('common_block_item')->fetch_all($ids) as $value) {
  235. if($value['bid'] == $bid) {
  236. $items[$value['itemid']] = $value;
  237. }
  238. }
  239. foreach($items as $key=>$value) {
  240. $itemtype = !empty($_POST['locked'][$key]) ? '1' : '0';
  241. if($orders[$key] != $value['displayorder'] || $itemtype != $value['itemtype']) {
  242. C::t('common_block_item')->update($key, array('displayorder'=>$orders[$key], 'itemtype'=>$itemtype));
  243. }
  244. }
  245. }
  246. showmessage('do_success', 'portal.php?mod=portalcp&ac=block&op=data&bid='.$bid, array('bid'=>$bid, 'eleid'=> $_GET['eleid']));
  247. }
  248. $itemlist = array();
  249. if($bid) {
  250. $preorders = array();
  251. foreach(C::t('common_block_item')->fetch_all_by_bid($bid, true) as $value) {
  252. if($value['itemtype']==1 && $value['enddate'] && $value['enddate'] <= TIMESTAMP) {
  253. continue;
  254. }
  255. $value['ispreorder'] = false;
  256. if($value['itemtype']==1) {
  257. if($value['startdate'] > TIMESTAMP) {
  258. $value['ispreorder'] = true;
  259. } else {
  260. $preorders[$value['displayorder']] = $value['itemid'];
  261. }
  262. }
  263. $value['itemtypename'] = lang('portalcp', 'itemtypename'.$value['itemtype']);
  264. $itemlist[$value['itemid']] = $value;
  265. }
  266. if($preorders) {
  267. foreach($itemlist as $key=>$value) {
  268. if(isset($preorders[$value['displayorder']]) && $value['itemid'] != $preorders[$value['displayorder']]) {
  269. unset($itemlist[$key]);
  270. }
  271. }
  272. }
  273. }
  274. $block['param']['bannedids'] = !empty($block['param']['bannedids']) ? $block['param']['bannedids'] : '';
  275. } elseif($op == 'style') {
  276. if(!$bid || !$allowmanage) {
  277. showmessage('block_edit_nopermission');
  278. }
  279. if(submitcheck('stylesubmit')) {
  280. $_POST['name'] = trim($_POST['name']);
  281. $arr = array(
  282. 'name' => $_POST['name'],
  283. 'blockclass' => $_GET['classname'],
  284. );
  285. $_POST['template'] = $_POST['template'];
  286. include_once libfile('function/block');
  287. block_parse_template($_POST['template'], $arr);
  288. if(!empty($_POST['name'])) {
  289. $styleid = C::t('common_block_style')->insert($arr, true);
  290. }
  291. $arr['fields'] = dunserialize($arr['fields']);
  292. $arr['template'] = dunserialize($arr['template']);
  293. $arr = serialize($arr);
  294. C::t('common_block')->update($bid, array('blockstyle'=>$arr, 'styleid'=>'0'));
  295. showmessage('do_success', 'portal.php?mod=portalcp&ac=block&op=style&bid='.$bid, array('bid'=>$bid, 'eleid'=> $_GET['eleid']));
  296. }
  297. $template = block_build_template($blockstyle['template']);
  298. $samplecode = '';
  299. if($block['hidedisplay']) {
  300. $samplecode = '<ul>\n'
  301. .'<!--{loop $_G[block_1] $key $value}-->\n'
  302. .'<li><a href="$value[url]">$value[title]</a></li>\n'
  303. .'<!--{/loop}-->\n'
  304. .'</ul>';
  305. $samplecode = dhtmlspecialchars($samplecode);
  306. $samplecode = str_replace('\n', '<br />', $samplecode);
  307. }
  308. } elseif($op == 'itemdata') {
  309. if(!$bid || (!$allowmanage && !$allowdata)) {
  310. showmessage('block_edit_nopermission');
  311. }
  312. if(!$is_recommendable) {
  313. showmessage('block_no_recommend_library');
  314. }
  315. $theurl = 'portal.php?mod=portalcp&ac=block&op=itemdata';
  316. $perpage = 20;
  317. $page = max(1,intval($_GET['page']));
  318. $start = ($page-1)*$perpage;
  319. if($start<0) $start = 0;
  320. if(submitcheck('deletesubmit')) {
  321. if(!empty($_POST['ids'])) {
  322. C::t('common_block_item_data')->delete_by_dataid_bid($_POST['ids'], $bid);
  323. }
  324. $displayorder = array_map('intval', $_POST['displayorder']);
  325. foreach($displayorder as $dataid => $displayorder) {
  326. if($displayorder !== intval($_POST['olddisplayorder'][$dataid])) {
  327. C::t('common_block_item_data')->update($dataid, array('displayorder' => $displayorder));
  328. }
  329. }
  330. showmessage('do_success', "portal.php?mod=portalcp&ac=block&op=itemdata&bid=$bid&page=$page");
  331. }
  332. $count = C::t('common_block_item_data')->count_by_bid($bid);
  333. $multi = '';
  334. $datalist = array();
  335. if($count) {
  336. $datalist = C::t('common_block_item_data')->fetch_all_by_bid($bid, 1, $start, $perpage);
  337. $multi = multi($count, $perpage, $page, "portal.php?mod=portalcp&ac=block&bid=$bid&op=itemdata");
  338. }
  339. } elseif($op == 'setting') {
  340. if(($bid && !$allowmanage)) {
  341. showmessage('block_edit_nopermission');
  342. }
  343. $settings = array();
  344. if($theclass['script'][$_GET['script']]) {
  345. $settings = block_setting($_GET['classname'], $_GET['script'], $block['param']);
  346. }
  347. $block['script'] = isset($block['script']) ? $block['script'] : $_GET['script'];
  348. $scriptarr = array($block['script'] => ' selected');
  349. $stylearr = array($_GET['styleid'] => ' selected');
  350. $block = block_checkdefault($block);
  351. $cachetimearr = array($block['cachetime'] =>' selected="selected"');
  352. $block['cachetime_min'] = intval($block['cachetime'] / 60);
  353. $targetarr[$block['target']] = ' selected';
  354. } elseif($op == 'thumbsetting') {
  355. if(($bid && !$allowmanage)) {
  356. showmessage('block_edit_nopermission');
  357. }
  358. $block = block_checkdefault($block);
  359. $cachetimearr = array($block['cachetime'] =>' selected="selected"');
  360. $block['cachetime_min'] = intval($block['cachetime'] / 60);
  361. $targetarr[$block['target']] = ' selected';
  362. $dateformats = block_getdateformats($block['dateformat']);
  363. } elseif($op == 'remove') {
  364. if(!$bid || (!$allowmanage && !$allowdata)) {
  365. showmessage('block_edit_nopermission');
  366. }
  367. if($_GET['itemid']) {
  368. $_GET['itemid'] = intval($_GET['itemid']);
  369. if(($item = C::t('common_block_item')->fetch($_GET['itemid'])) && $item['bid'] == $bid) {
  370. C::t('common_block_item')->delete($_GET['itemid']);
  371. if($item['itemtype'] != '1') {
  372. block_ban_item($block, $item);
  373. }
  374. block_updatecache($bid, true);
  375. }
  376. }
  377. showmessage('do_success', "portal.php?mod=portalcp&ac=block&op=data&bid=$bid", array('bid'=>$bid));
  378. } elseif( in_array($op, array('item', 'additem', 'push', 'recommend', 'verifydata', 'managedata'))) {
  379. if(!$bid) {
  380. showmessage('block_edit_nopermission');
  381. }
  382. $itemid = $_GET['itemid'] ? intval($_GET['itemid']) : 0;
  383. $dataid = $_GET['dataid'] ? intval($_GET['dataid']) : 0;
  384. $_GET['id'] = intval($_GET['id']);
  385. $_GET['idtype'] = preg_replace('/[^\w]/', '', $_GET['idtype']);
  386. $item = $perm = array();
  387. if($op == 'item' || $op == 'additem') {
  388. if(!$allowmanage && !$allowdata) {
  389. showmessage('block_edit_nopermission');
  390. }
  391. if($itemid && ($item = C::t('common_block_item')->fetch($itemid))) {
  392. $item['fields'] = dunserialize($item['fields']);
  393. }
  394. } elseif($op == 'push') {
  395. $item = get_push_item($block, $thestyle, $_GET['id'], $_GET['idtype']);
  396. if($itemid) {
  397. $item['itemid'] = $itemid;
  398. }
  399. } elseif($op == 'recommend') {
  400. $perm = getblockperm($bid);
  401. if(!$perm['allowmanage'] && !$perm['allowrecommend']) {
  402. showmessage('block_no_right_recommend');
  403. }
  404. $isrepeatrecommend = false;
  405. $idtype = $_GET['idtype'] == 'gtid' ? 'tid' : $_GET['idtype'];
  406. if(($item = C::t('common_block_item_data')->fetch_by_bid_id_idtype($bid, $_GET['id'], $idtype))) {
  407. $item['fields'] = dunserialize($item['fields']);
  408. $isrepeatrecommend = true;
  409. if(!$perm['allowmanage'] && $item['uid'] != $_G['uid']) {
  410. showmessage('data_in_mod_library', null, null, array('striptags' => false));
  411. }
  412. } else {
  413. if(in_array($_GET['idtype'],array('tid', 'gtid', 'aid', 'picid', 'blogid'))) {
  414. $_GET['idtype'] = $_GET['idtype'] == 'gtid' ? 'tids' : $_GET['idtype'].'s';
  415. }
  416. $item = get_push_item($block, $thestyle, $_GET['id'], $_GET['idtype'], $block['blockclass'], $block['script']);
  417. if(empty($item)) showmessage('block_data_type_invalid', null, null, array('msgtype'=>3));
  418. }
  419. } elseif($op=='verifydata' || $op=='managedata') {
  420. if(!$allowmanage && !$allowdata) {
  421. showmessage('no_right_manage_data');
  422. }
  423. if($dataid) {
  424. $item = C::t('common_block_item_data')->fetch($dataid);
  425. $item['fields'] = dunserialize($item['fields']);
  426. }
  427. }
  428. if(!$item && $op != 'additem') {
  429. showmessage('block_edit_nopermission');
  430. }
  431. $item['oldpic'] = $item['pic'];
  432. if($item['picflag'] == '1') {
  433. $item['pic'] = $item['pic'] ? $_G['setting']['attachurl'].$item['pic'] : '';
  434. } elseif($item['picflag'] == '2') {
  435. $item['pic'] = $item['pic'] ? $_G['setting']['ftp']['attachurl'].$item['pic'] : '';
  436. }
  437. $item['startdate'] = $item['startdate'] ? dgmdate($item['startdate']) : dgmdate(TIMESTAMP);
  438. $item['enddate'] = $item['enddate'] ? dgmdate($item['enddate']) : '';
  439. $orders = range(1, $block['shownum']);
  440. $orderarr[$item['displayorder']] = ' selected="selected"';
  441. $item['showstyle'] = !empty($item['showstyle']) ? (array)(dunserialize($item['showstyle'])) : (!empty($item['fields']['showstyle']) ? $item['fields']['showstyle'] : array());
  442. $showstylearr = array();
  443. foreach(array('title_b', 'title_i', 'title_u', 'title_c', 'summary_b', 'summary_i', 'summary_u', 'title_c') as $value) {
  444. if(!empty($item['showstyle'][$value])) {
  445. $showstylearr[$value] = 'class="a"';
  446. }
  447. }
  448. $itemfields = $blockitem = $item;
  449. unset($itemfields['fields']);
  450. $item['fields'] = (array)$item['fields'];
  451. foreach($item['fields'] as $key=>$value) {
  452. if($theclass['fields'][$key]) {
  453. switch($theclass['fields'][$key]['datatype']) {
  454. case 'date':
  455. $itemfields[$key] = dgmdate($value, 'Y-m-d H:i:s');
  456. break;
  457. case 'int':
  458. $itemfields[$key] = intval($value);
  459. break;
  460. case 'string':
  461. $itemfields[$key] = dhtmlspecialchars($value);
  462. break;
  463. default:
  464. $itemfields[$key] = $value;
  465. }
  466. }
  467. }
  468. $showfields = array();
  469. if(empty($thestyle['fields'])) {
  470. $template = block_build_template($thestyle['template']);
  471. $thestyle['fields'] = block_parse_fields($template);
  472. C::t('common_block_style')->update(intval($thestyle['styleid']), array('fields'=>serialize($thestyle['fields'])));
  473. }
  474. foreach($thestyle['fields'] as $fieldname) {
  475. $showfields[$fieldname] = "1";
  476. }
  477. if(submitcheck('itemsubmit') || submitcheck('recommendsubmit') || submitcheck('verifydatasubmit') || submitcheck('managedatasubmit')) {
  478. $item['bid'] = $block['bid'];
  479. $item['displayorder'] = intval($_POST['displayorder']);
  480. $item['startdate'] = !empty($_POST['startdate']) ? strtotime($_POST['startdate']) : 0;
  481. $item['enddate'] = !empty($_POST['enddate']) ? strtotime($_POST['enddate']) : 0;
  482. $item['itemtype'] = !empty($_POST['locked']) ? '1' : '2';
  483. $item['title'] = dhtmlspecialchars($_POST['title']);
  484. $item['url'] = $_POST['url'];
  485. $block['param']['summarylength'] = empty($block['param']['summarylength']) ? 80 : $block['param']['summarylength'];
  486. $block['param']['titlelength'] = empty($block['param']['titlelength']) ? 40 : $block['param']['titlelength'];
  487. $item['summary'] = cutstr($_POST['summary'], $block['param']['summarylength'], '');
  488. if($_FILES['pic']['tmp_name']) {
  489. $result = pic_upload($_FILES['pic'], 'portal');
  490. $item['pic'] = 'portal/'.$result['pic'];
  491. $item['picflag'] = $result['remote'] ? '2' : '1';
  492. $item['makethumb'] = 0;
  493. $item['thumbpath'] = '';
  494. $thumbdata = array('bid' => $block['bid'], 'itemid' => $item['itemid'], 'pic' => $item['pic'], 'picflag' => $result['remote'], 'type' => '1');
  495. C::t('common_block_pic')->insert($thumbdata);
  496. } elseif($_POST['pic']) {
  497. $pic = dhtmlspecialchars($_POST['pic']);
  498. $urls = parse_url($pic);
  499. if(!empty($urls['scheme']) && !empty($urls['host'])) {
  500. $item['picflag'] = '0';
  501. $item['thumbpath'] = '';
  502. } else {
  503. $item['picflag'] = intval($_POST['picflag']);
  504. }
  505. if($item['pic'] != $pic) {
  506. $item['pic'] = $pic;
  507. $item['makethumb'] = 0;
  508. $item['thumbpath'] = block_thumbpath($block, $item);
  509. }
  510. }
  511. unset($item['oldpic']);
  512. $item['showstyle'] = $_POST['showstyle']['title_b'] || $_POST['showstyle']['title_i'] || $_POST['showstyle']['title_u'] || $_POST['showstyle']['title_c'] ? $_POST['showstyle'] : array();
  513. $item['showstyle'] = empty($item['showstyle']) ? '' : serialize($item['showstyle']);
  514. foreach($theclass['fields'] as $key=>$value) {
  515. if(!isset($item[$key]) && isset($_POST[$key])) {
  516. if($value['datatype'] == 'int') {
  517. $_POST[$key] = intval($_POST[$key]);
  518. } elseif($value['datatype'] == 'date') {
  519. $_POST[$key] = strtotime($_POST[$key]);
  520. } else {
  521. $_POST[$key] = $_POST[$key];
  522. }
  523. $item['fields'][$key] = $_POST[$key];
  524. }
  525. }
  526. if(isset($item['fields']['fulltitle'])) {
  527. $item['fields']['fulltitle'] = $item['title'];
  528. }
  529. $item['fields'] = serialize($item['fields']);
  530. $item['title'] = cutstr($item['title'], $block['param']['titlelength'], '');
  531. if($_POST['icflag']) {
  532. $item['makethumb'] = 1;
  533. $item['thumbpath'] = block_thumbpath($block, $item);
  534. }
  535. if(submitcheck('itemsubmit')) {
  536. if($op == 'additem' && !$item['id']) {
  537. $item['id'] = ($pushid = intval($_POST['push_id'])) ? $pushid : mt_rand(1,9999);
  538. $item['idtype'] = 'rand';
  539. }
  540. if($item['startdate'] > $_G['timestamp']) {
  541. C::t('common_block_item')->insert($item, false, true);
  542. } elseif(empty($item['enddate']) || $item['enddate'] > $_G['timestamp']) {
  543. C::t('common_block_item')->delete_by_bid_displayorder($bid, $item['displayorder']);
  544. C::t('common_block_item')->insert($item, false, true);
  545. } else {
  546. C::t('common_block_item')->delete_by_itemid_bid($item['itemid'], $bid);
  547. }
  548. block_updatecache($bid, true);
  549. showmessage('do_success', 'portal.php?mod=portalcp&ac=block&op=data&bid='.$block['bid'], array('bid'=>$bid));
  550. } elseif(submitcheck('recommendsubmit')) {
  551. include_once libfile('function/home');
  552. $thumbpath = $item['thumbpath'];
  553. unset($item['itemid']);
  554. unset($item['thumbpath']);
  555. $item['itemtype'] = '0';
  556. $item['uid'] = $_G['uid'];
  557. $item['username'] = $_G['username'];
  558. $item['dateline'] = TIMESTAMP;
  559. $item['isverified'] = empty($_POST['needverify']) && ($perm['allowmanage'] || empty($perm['needverify'])) ? '1' : '0';
  560. $item['verifiedtime'] = TIMESTAMP;
  561. C::t('common_block_item_data')->insert($item, false, true);
  562. if($_GET['showrecommendtip'] && (in_array($_GET['idtype'], array('tids', 'tid', 'gtid')))) {
  563. $modarr = array(
  564. 'tid' => $item['id'],
  565. 'uid' => $item['uid'],
  566. 'username' => $item['username'],
  567. 'dateline' => TIMESTAMP,
  568. 'action' => 'REB',
  569. 'status' => '1',
  570. 'stamp' => '',
  571. 'reason' => getstr($_GET['recommendto'], 20),
  572. );
  573. C::t('forum_threadmod')->insert($modarr);
  574. $data = array('moderated' => 1);
  575. loadcache('stamptypeid');
  576. if(array_key_exists(4, $_G['cache']['stamptypeid'])) {
  577. $data['stamp'] = $_G['cache']['stamptypeid']['4'];
  578. }
  579. C::t('forum_thread')->update($item['id'], $data);
  580. }
  581. if($_POST['icflag'] && !(C::t('common_block_pic')->count_by_bid_pic($block['bid'], $thumbpath))) {
  582. $picflag = 0; //common_block_pic表中的picflag标识(0本地,1远程)
  583. if($_G['setting']['ftp']['on']) {
  584. $ftp = & discuz_ftp::instance();
  585. $ftp->connect();
  586. if($ftp->connectid && $ftp->ftp_size($thumbpath) > 0 || $ftp->upload($_G['setting']['attachurl'].'/'.$thumbpath, $thumbpath)) {
  587. $picflag = 1; //common_block_pic表中的picflag标识(0本地,1远程)
  588. @unlink($_G['setting']['attachdir'].'./'.$thumbpath);
  589. }
  590. }
  591. $thumbdata = array('bid' => $block['bid'], 'itemid' => 0, 'pic' => $thumbpath, 'picflag' => $picflag, 'type' => '0');
  592. C::t('common_block_pic')->insert($thumbdata);
  593. }
  594. if(!empty($_POST['updateblock'])) {
  595. block_updatecache($bid, true);
  596. }
  597. if(($_G['group']['reasonpm'] == 2 || $_G['group']['reasonpm'] == 3) || !empty($_GET['sendreasonpm'])) {
  598. $sendreasonpm = 1;
  599. } else {
  600. $sendreasonpm = 0;
  601. }
  602. if($sendreasonpm) {
  603. require_once libfile('function/misc');
  604. if((in_array($_GET['idtype'], array('tids', 'tid', 'gtid')))) {
  605. $sendreasonpmcontent = C::t('forum_thread')->fetch($item['id']);
  606. sendreasonpm($sendreasonpmcontent, 'recommend_note_post', array(
  607. 'tid' => $item['id'],
  608. 'subject' => $sendreasonpmcontent['subject'],
  609. 'from_id' => 0,
  610. 'from_idtype' => 'recommend'
  611. ));
  612. }
  613. }
  614. $showrecommendrate = '';
  615. if($_G['group']['raterange'] && (in_array($_GET['idtype'], array('tids', 'tid', 'gtid')))) {
  616. $showrecommendrate = 1;
  617. }
  618. if($showrecommendrate) {
  619. showmessage('do_success', dreferer('portal.php'), array(), array('showdialog' => true, 'closetime' => 0.01, 'extrajs' =>
  620. '<script type="text/javascript" reload="1">
  621. showWindow("rate", "forum.php?mod=misc&action=rate&tid='.$item[id].'&pid='.$_GET[recommend_thread_pid].'&showratetip=1", "get", -1);
  622. </script>'));
  623. } elseif($_GET['showrecommendtip']) {
  624. showmessage('do_success', dreferer('portal.php'), array(), array('showdialog' => true, 'closetime' => true, 'extrajs' =>
  625. '<script type="text/javascript" reload="1">
  626. window.location.reload();
  627. </script>'));
  628. } else {
  629. showmessage('do_success', dreferer('portal.php'), array(), array('showdialog' => true, 'closetime' => true));
  630. }
  631. } elseif(submitcheck('verifydatasubmit')) {
  632. unset($item['thumbpath']);
  633. $item['isverified'] = '1';
  634. $item['verifiedtime'] = TIMESTAMP;
  635. C::t('common_block_item_data')->update($dataid, $item);
  636. if(!empty($_POST['updateblock'])) {
  637. block_updatecache($bid, true);
  638. }
  639. showmessage('do_success', dreferer('portal.php?mod=portalcp&ac=portalblock&op=verifieddata&searchkey=%23'.$bid));
  640. } elseif(submitcheck('managedatasubmit')) {
  641. unset($item['thumbpath']);
  642. $item['stickgrade'] = intval($_POST['stickgrade']);
  643. C::t('common_block_item_data')->update($dataid, $item);
  644. showmessage('do_success', dreferer('portal.php?mod=portalcp&ac=block&op=itemdata&bid='.$bid));
  645. }
  646. }
  647. if(in_array($block['blockclass'], array('forum_thread', 'portal_article', 'group_thread', 'space_blog'), true)) {
  648. $picdatas = array();
  649. $prefix = ($item['picflag'] == 2 ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']);
  650. $itemfields['pics'] = array();
  651. $first = true;
  652. if(empty($_GET['idtype'])) {
  653. $_GET['idtype'] = $itemfields['idtype'].'s';
  654. $_GET['id'] = $itemfields['id'];
  655. }
  656. if(in_array($_GET['idtype'], array('tids', 'tid'))) {
  657. $prefix .= 'forum/';
  658. $firstpost = C::t('forum_post')->fetch_threadpost_by_tid_invisible($_GET['id']);
  659. foreach(C::t('forum_attachment_n')->fetch_all_by_pid_width('pid:'.$firstpost['pid'], $firstpost['pid'], $block['picwidth']) as $pic) {
  660. if($first) {
  661. $first = false;
  662. $itemfields['pics'][0] = '';
  663. if(strpos($itemfields['oldpic'], 'nophoto.gif') !== false) {
  664. $itemfields['oldpic'] = 'forum/'.$pic['attachment'];
  665. }
  666. }
  667. $thumb = $prefix.($pic['thumb'] ? getimgthumbname($pic['attachment']) : $pic['attachment']);
  668. if('forum/'.$pic['attachment'] == $itemfields['oldpic']) {
  669. $itemfields['pics'][0] = array('big' => $prefix.$pic['attachment'], 'thumb' => $thumb, 'attachment' => 'forum/'.$pic['attachment'], 'first' => 1);
  670. } else {
  671. $itemfields['pics'][] = array('big' => $prefix.$pic['attachment'], 'thumb' => $thumb, 'attachment' => 'forum/'.$pic['attachment'], 'first' => 0);
  672. }
  673. }
  674. if(empty($itemfields['pics'][0])) {
  675. unset($itemfields['pics'][0]);
  676. }
  677. } elseif($_GET['idtype'] == 'aids') {
  678. $prefix .= 'portal/';
  679. foreach(C::t('portal_attachment')->fetch_all_by_aid($_GET['id']) as $pic) {
  680. if($first) {
  681. $first = false;
  682. $itemfields['pics'][0] = '';
  683. if(strpos($itemfields['oldpic'], 'nophoto.gif') !== false) {
  684. $itemfields['oldpic'] = 'portal/'.$pic['attachment'];
  685. }
  686. }
  687. $thumb = $prefix.($pic['thumb'] ? getimgthumbname($pic['attachment']) : $pic['attachment']);
  688. if('portal/'.$pic['attachment'] == $itemfields['oldpic']) {
  689. $itemfields['pics'][0] = array('big' => $prefix.$pic['attachment'], 'thumb' => $thumb, 'attachment' => 'portal/'.$pic['attachment'], 'first' => 1);
  690. } else {
  691. $itemfields['pics'][] = array('big' => $prefix.$pic['attachment'], 'thumb' => $thumb, 'attachment' => 'portal/'.$pic['attachment'], 'first' => 0);
  692. }
  693. }
  694. if(empty($itemfields['pics'][0])) {
  695. unset($itemfields['pics'][0]);
  696. }
  697. } elseif($_GET['idtype'] == 'blogids') {
  698. $itemfields['pics'][] = array('big' => $itemfields['pic'], 'thumb' => 1, 'attachment' => $itemfields['oldpic']);
  699. }
  700. }
  701. } elseif ($op == 'getblock') {
  702. if(!$bid || (!$allowmanage && !$allowdata)) {
  703. showmessage('block_edit_nopermission');
  704. }
  705. block_get_batch($bid);
  706. if(!empty($_GET['forceupdate'])) block_updatecache($bid, !empty($_GET['forceupdate']));
  707. if(strexists($block['summary'], '<script')) {
  708. $block['summary'] = lang('portalcp', 'block_diy_nopreview');
  709. $_G['block'][$bid] = $block;
  710. $_G['block'][$bid]['cachetime'] = 0;
  711. $_G['block'][$bid]['nocache'] = true;
  712. }
  713. $html = block_fetch_content($bid, $block['blocktype']);
  714. } elseif ($op == 'saveblockclassname') {
  715. if(!$bid || !$allowmanage) {
  716. showmessage('block_edit_nopermission');
  717. }
  718. if (submitcheck('saveclassnamesubmit')) {
  719. $setarr = array('classname'=>getstr($_POST['classname'], 100, 0, 0, 0, -1));
  720. C::t('common_block')->update($bid, $setarr);
  721. }
  722. C::t('common_block')->clear_cache($bid);
  723. showmessage('do_success');
  724. } elseif ($op == 'saveblocktitle') {
  725. if(!$bid || !$allowmanage) {
  726. showmessage('block_edit_nopermission');
  727. }
  728. if (submitcheck('savetitlesubmit')) {
  729. $_POST['title'] = preg_replace('/\<script|\<iframe|\<\/iframe\>/is', '', $_POST['title']);
  730. $title = $_POST['title'];
  731. $title = preg_replace('/url\([\'"](.*?)[\'"]\)/','url($1)',$title);
  732. $_G['siteurl'] = str_replace(array('/','.'),array('\/','\.'),$_G['siteurl']);
  733. $title = preg_replace('/\"'.$_G['siteurl'].'(.*?)\"/','"$1"',$title);
  734. $setarr = array('title'=>$title);
  735. C::t('common_block')->update($bid, $setarr);
  736. }
  737. C::t('common_block')->clear_cache($bid);
  738. showmessage('do_success');
  739. } elseif ($op == 'convert') {
  740. if(!$bid || !$allowmanage) {
  741. showmessage('block_edit_nopermission');
  742. }
  743. block_convert($bid, $_GET['toblockclass']);
  744. } elseif ($op == 'favorite') {
  745. $perm = getblockperm($bid);
  746. if(!$perm['allowmanage'] && !$perm['allowrecommend']) {
  747. showmessage('block_no_right_recommend');
  748. }
  749. $favoriteop = '';
  750. if(!block_check_favorite($_G['uid'], $bid)) {
  751. $setarr = array(
  752. 'uid' => $_G['uid'],
  753. 'bid' => $bid,
  754. );
  755. block_add_favorite($setarr);
  756. $favoriteop = 'add';
  757. } else {
  758. block_delete_favorite($_G['uid'], $bid);
  759. $favoriteop = 'del';
  760. }
  761. } elseif($op == 'delrecommend') {
  762. $perm = getblockperm($bid);
  763. if(!$perm['allowmanage'] && !$perm['allowrecommend']) {
  764. showmessage('block_no_right_recommend');
  765. }
  766. if(($_GET['dataid'] = dintval($_GET['dataid']))) {
  767. C::t('common_block_item_data')->delete($_GET['dataid']);
  768. block_updatecache($bid, true);
  769. }
  770. showmessage('do_success');
  771. } elseif($op == 'moreurl') {
  772. if(!$bid || !$allowmanage) {
  773. showmessage('block_edit_nopermission');
  774. }
  775. if(submitcheck('moreurlsubmit')) {
  776. $arr = array(
  777. 'perpage' => max(1, intval($_POST['perpage'])),
  778. 'seotitle' => $_POST['seotitle'],
  779. 'seokeywords' => $_POST['seokeywords'],
  780. 'seodescription' => $_POST['seodescription'],
  781. );
  782. $block['param']['moreurl'] = $arr;
  783. C::t('common_block')->update($bid, array('param' => serialize($block['param'])));
  784. showmessage('do_success', 'portal.php?mod=portalcp&ac=block&op=moreurl&bid='.$bid, array('bid'=>$bid));
  785. }
  786. $block['param']['moreurl'] = !empty($block['param']['moreurl']) ? $block['param']['moreurl'] :
  787. array('perpage' => 20, 'seotitle' => $block['name'], 'keywords' => '', 'description' => '');
  788. }
  789. include_once template("portal/portalcp_block");
  790. function block_checkdefault($block) {
  791. if(empty($block['shownum'])) {
  792. $block['shownum'] = 10;
  793. }
  794. if(!isset($block['cachetime'])) {
  795. $block['cachetime'] = '3600';
  796. }
  797. if(empty($block['picwidth'])) {
  798. $block['picwidth'] = "200";
  799. }
  800. if(empty($block['picheight'])) {
  801. $block['picheight'] = "200";
  802. }
  803. if(empty($block['target'])) {
  804. $block['target'] = "blank";
  805. }
  806. return $block;
  807. }
  808. function block_getdateformats($format='') {
  809. $formats = array('Y-m-d', 'm-d', 'H:i', 'Y-m-d H:i');
  810. $return = array();
  811. foreach($formats as $value) {
  812. $return[] = array(
  813. 'format' => $value,
  814. 'selected' => $format==$value ? ' selected="selected"' : '',
  815. 'time' => dgmdate(TIMESTAMP, $value)
  816. );
  817. }
  818. return $return;
  819. }
  820. function block_ban_item($block, $item) {
  821. global $_G;
  822. $parameters = !empty($block['param']) ? $block['param'] : array();
  823. $bannedids = !empty($parameters['bannedids']) ? explode(',', $parameters['bannedids']) : array();
  824. $bannedids[] = intval($item['id']);
  825. $bannedids = array_unique($bannedids);
  826. $parameters['bannedids'] = implode(',', $bannedids);
  827. $_G['block'][$block['bid']]['param'] = $parameters;
  828. $parameters = serialize($parameters);
  829. C::t('common_block')->update($block['bid'], array('param'=>$parameters));
  830. }
  831. function get_push_item($block, $blockstyle, $id, $idtype, $blockclass = '', $script = '') {
  832. $item = array();
  833. $obj = null;
  834. if(empty($blockclass) || empty($script)) {
  835. if($idtype == 'tids') {
  836. $obj = block_script('forum', 'thread');
  837. } elseif($idtype == 'gtids') {
  838. $obj = block_script('group', 'groupthread');
  839. } elseif($idtype == 'aids') {
  840. $obj = block_script('portal', 'article');
  841. } elseif($idtype == 'picids') {
  842. $obj = block_script('space', 'pic');
  843. } elseif($idtype == 'blogids') {
  844. $obj = block_script('space', 'blog');
  845. }
  846. } else {
  847. list($blockclass) = explode('_', $blockclass);
  848. $obj = block_script($blockclass, $script);
  849. }
  850. if($obj && is_object($obj)) {
  851. $paramter = array($idtype => intval($id));
  852. if(isset($block['param']['picrequired'])) {
  853. $paramter['picrequired'] = $block['param']['picrequired'];
  854. }
  855. $return = $obj->getData($blockstyle, $paramter);
  856. if($return['data']) {
  857. $item = array_shift($return['data']);
  858. }
  859. }
  860. return $item;
  861. }
  862. function block_convert($bid, $toblockclass) {
  863. global $_G;
  864. $bid = intval($bid);
  865. if(empty($bid) || empty($toblockclass)) return false;
  866. if(($block = C::t('common_block')->fetch($bid))) {
  867. loadcache('blockconvert');
  868. $fromblockclass = $block['blockclass'];
  869. list($bigclass) = explode('_', $fromblockclass);
  870. $convertrule = null;
  871. if(!empty($_G['cache']['blockconvert']) && !empty($_G['cache']['blockconvert'][$bigclass][$fromblockclass][$toblockclass])) {
  872. $convertrule = $_G['cache']['blockconvert'][$bigclass][$fromblockclass][$toblockclass];
  873. }
  874. if(!empty($convertrule)) {
  875. $blockstyle = array();
  876. if($block['styleid']) {
  877. if(($blockstyle = C::t('common_block_style')->fetch(intval($block['styleid'])))) {
  878. unset($blockstyle['styleid']);
  879. $blockstyle['fields'] = dunserialize($blockstyle['fields']);
  880. $blockstyle['template'] = dunserialize($blockstyle['template']);
  881. }
  882. } elseif($block['blockstyle']) {
  883. $blockstyle = dunserialize($block['blockstyle']);
  884. }
  885. if($blockstyle) {
  886. $blockstyle['name'] = '';
  887. $blockstyle['blockclass'] = $toblockclass;
  888. foreach($blockstyle['fields'] as $key => $value) {
  889. $blockstyle['fields'][$key] = str_replace($convertrule['searchkeys'], $convertrule['replacekeys'], $value);
  890. }
  891. $fun = create_function('&$v','$v = "{".$v."}";');
  892. array_walk($convertrule['searchkeys'], $fun);
  893. array_walk($convertrule['replacekeys'], $fun);
  894. foreach($blockstyle['template'] as $key => $value) {
  895. $blockstyle['template'][$key] = str_replace($convertrule['searchkeys'], $convertrule['replacekeys'], $value);
  896. }
  897. unset($block['bid']);
  898. $block['styleid'] = '0';
  899. $block['script'] = $convertrule['script'];
  900. $block['blockclass'] = $toblockclass;
  901. $block['blockstyle'] = serialize($blockstyle);
  902. $block['param'] = serialize($block['param']);
  903. C::t('common_block')->update($bid, $block);
  904. }
  905. }
  906. }
  907. }
  908. function block_check_favorite($uid, $bid){
  909. $uid = intval($uid);
  910. $bid = intval($bid);
  911. if($uid && $bid) {
  912. return C::t('common_block_favorite')->count_by_uid_bid($uid, $bid);
  913. } else {
  914. return false;
  915. }
  916. }
  917. function block_add_favorite($setarr){
  918. $arr = array(
  919. 'uid' => intval($setarr['uid']),
  920. 'bid' => intval($setarr['bid']),
  921. 'dateline' => TIMESTAMP
  922. );
  923. return C::t('common_block_favorite')->insert($arr, true);
  924. }
  925. function block_delete_favorite($uid, $bid){
  926. $uid = intval($uid);
  927. $bid = intval($bid);
  928. if($uid && $bid) {
  929. return C::t('common_block_favorite')->delete_by_uid_bid($uid, $bid);
  930. } else {
  931. return false;
  932. }
  933. }
  934. function block_ckeck_summary($summary){
  935. if($summary) {
  936. $tags = array('div', 'table', 'tbody', 'tr', 'td', 'th');
  937. foreach($tags as $tag) {
  938. preg_match_all('/(<'.$tag.')|(<\/'.$tag.'>)/i', $summary, $all);
  939. if(!empty($all[1]) && !empty($all[2])) {
  940. $all[1] = array_filter($all[1]);
  941. $all[2] = array_filter($all[2]);
  942. if(count($all[1]) !== count($all[2])) {
  943. return $tag;
  944. }
  945. }
  946. }
  947. }
  948. return $summary;
  949. }
  950. ?>