PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/source/include/portalcp/portalcp_article.php

https://github.com/kuaileshike/upload
PHP | 718 lines | 630 code | 82 blank | 6 comment | 148 complexity | f613dc02b1ed9c165b88811cadf7d335 MD5 | raw file
  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_article.php 30779 2012-06-19 05:52:56Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $op = in_array($_GET['op'], array('edit', 'delete', 'related', 'batch', 'pushplus', 'verify')) ? $_GET['op'] : 'add';
  12. $aid = intval($_GET['aid']);
  13. $catid = intval($_GET['catid']);
  14. $seccodecheck = $_G['setting']['seccodestatus'] & 4;
  15. $secqaacheck = $_G['setting']['secqaa']['status'] & 2;
  16. $article = $article_content = array();
  17. if($aid) {
  18. $article = C::t('portal_article_title')->fetch($aid);
  19. if(!$article) {
  20. showmessage('article_not_exist', dreferer());
  21. }
  22. }
  23. loadcache('portalcategory');
  24. $portalcategory = $_G['cache']['portalcategory'];
  25. if($catid && empty($portalcategory[$catid])) {
  26. showmessage('portal_category_not_find', dreferer());
  27. }
  28. if(empty($article) && $catid && $portalcategory[$catid]['disallowpublish']) {
  29. showmessage('portal_category_disallowpublish', dreferer());
  30. }
  31. if(submitcheck("articlesubmit", 0, $seccodecheck, $secqaacheck)) {
  32. if($aid) {
  33. check_articleperm($article['catid'], $aid, $article);
  34. } else {
  35. check_articleperm($catid);
  36. }
  37. $_POST['title'] = getstr(trim($_POST['title']), 80);
  38. if(strlen($_POST['title']) < 1) {
  39. showmessage('title_not_too_little');
  40. }
  41. $_POST['title'] = censor($_POST['title']);
  42. $_POST['pagetitle'] = getstr(trim($_POST['pagetitle']), 60);
  43. $_POST['pagetitle'] = censor($_POST['pagetitle']);
  44. $highlight_style = $_GET['highlight_style'];
  45. $style = '';
  46. $style = implode('|',$highlight_style);
  47. if(empty($_POST['summary'])) $_POST['summary'] = preg_replace("/(\s|\<strong\>##########NextPage(\[title=.*?\])?##########\<\/strong\>)+/", ' ', $_POST['content']);
  48. $summary = portalcp_get_summary($_POST['summary']);
  49. $summary = censor($summary);
  50. $_GET['author'] = dhtmlspecialchars($_GET['author']);
  51. $_GET['url'] = str_replace('&amp;', '&', dhtmlspecialchars($_GET['url']));
  52. $_GET['from'] = dhtmlspecialchars($_GET['from']);
  53. $_GET['fromurl'] = str_replace('&amp;', '&', dhtmlspecialchars($_GET['fromurl']));
  54. $_GET['dateline'] = !empty($_GET['dateline']) ? strtotime($_GET['dateline']) : TIMESTAMP;
  55. if(censormod($_POST['title']) || $_G['group']['allowpostarticlemod']) {
  56. $article_status = 1;
  57. } else {
  58. $article_status = 0;
  59. }
  60. $setarr = array(
  61. 'title' => $_POST['title'],
  62. 'author' => $_GET['author'],
  63. 'from' => $_GET['from'],
  64. 'fromurl' => $_GET['fromurl'],
  65. 'dateline' => intval($_GET['dateline']),
  66. 'url' => $_GET['url'],
  67. 'allowcomment' => !empty($_POST['forbidcomment']) ? '0' : '1',
  68. 'summary' => $summary,
  69. 'catid' => intval($_POST['catid']),
  70. 'tag' => article_make_tag($_POST['tag']),
  71. 'status' => $article_status,
  72. 'highlight' => $style,
  73. 'showinnernav' => empty($_POST['showinnernav']) ? '0' : '1',
  74. );
  75. if(empty($setarr['catid'])) {
  76. showmessage('article_choose_system_category');
  77. }
  78. if($_GET['conver']) {
  79. $converfiles = dunserialize($_GET['conver']);
  80. $setarr['pic'] = $converfiles['pic'];
  81. $setarr['thumb'] = intval($converfiles['thumb']);
  82. $setarr['remote'] = intval($converfiles['remote']);
  83. }
  84. $id = 0;
  85. $idtype = '';
  86. if(empty($article)) {
  87. $setarr['uid'] = $_G['uid'];
  88. $setarr['username'] = $_G['username'];
  89. $setarr['id'] = intval($_POST['id']);
  90. $table = '';
  91. if($setarr['id']) {
  92. if($_POST['idtype']=='blogid') {
  93. $table = 'home_blogfield';
  94. $setarr['idtype'] = 'blogid';
  95. $id = $setarr['id'];
  96. $idtype = $setarr['idtype'];
  97. } else {
  98. $table = 'forum_thread';
  99. $setarr['idtype'] = 'tid';
  100. require_once libfile('function/discuzcode');
  101. $id = C::t('forum_post')->fetch_threadpost_by_tid_invisible($setarr['id']);
  102. $id = $id['pid'];
  103. $idtype = 'pid';
  104. }
  105. }
  106. $aid = C::t('portal_article_title')->insert($setarr, 1);
  107. if($table) {
  108. if($_POST['idtype']=='blogid') {
  109. C::t('home_blogfield')->update($setarr['id'], array('pushedaid' => $aid));
  110. } elseif($setarr['idtype']=='tid') {
  111. $modarr = array(
  112. 'tid' => $setarr['id'],
  113. 'uid' => $_G['uid'],
  114. 'username' => $_G['username'],
  115. 'dateline' => TIMESTAMP,
  116. 'action' => 'PTA',
  117. 'status' => '1',
  118. 'stamp' => '',
  119. );
  120. C::t('forum_threadmod')->insert($modarr);
  121. C::t('forum_thread')->update($setarr['id'], array('moderated' => 1, 'pushedaid' => $aid));
  122. }
  123. }
  124. C::t('common_member_status')->update($_G['uid'], array('lastpost' => TIMESTAMP), 'UNBUFFERED');
  125. C::t('portal_category')->increase($setarr['catid'], array('articles' => 1));
  126. C::t('portal_article_count')->insert(array('aid'=>$aid, 'catid'=>$setarr['catid'], 'viewnum'=>1));
  127. } else {
  128. C::t('portal_article_title')->update($aid, $setarr);
  129. }
  130. $content = getstr($_POST['content'], 0, 0, 0, 0, 1);
  131. $content = censor($content);
  132. if(censormod($content) || $_G['group']['allowpostarticlemod']) {
  133. $article_status = 1;
  134. } else {
  135. $article_status = 0;
  136. }
  137. $regexp = '/(\<strong\>##########NextPage(\[title=(.*?)\])?##########\<\/strong\>)+/is';
  138. preg_match_all($regexp, $content ,$arr);
  139. $pagetitle = !empty($arr[3]) ? $arr[3] : array();
  140. $pagetitle = array_map('trim', $pagetitle);
  141. array_unshift($pagetitle, $_POST['pagetitle']);
  142. $contents = preg_split($regexp, $content);
  143. $cpostcount = count($contents);
  144. $dbcontents = C::t('portal_article_content')->fetch_all($aid);
  145. $pagecount = $cdbcount = count($dbcontents);
  146. if($cdbcount > $cpostcount) {
  147. $cdelete = array();
  148. foreach(array_splice($dbcontents, $cpostcount) as $value) {
  149. $cdelete[$value['cid']] = $value['cid'];
  150. }
  151. if(!empty($cdelete)) {
  152. C::t('portal_article_content')->delete($cdelete);
  153. }
  154. $pagecount = $cpostcount;
  155. }
  156. foreach($dbcontents as $key => $value) {
  157. C::t('portal_article_content')->update($value['cid'], array('title' => $pagetitle[$key], 'content' => $contents[$key], 'pageorder' => $key+1));
  158. unset($pagetitle[$key], $contents[$key]);
  159. }
  160. if($cdbcount < $cpostcount) {
  161. foreach($contents as $key => $value) {
  162. C::t('portal_article_content')->insert(array('aid' => $aid, 'id' => $setarr['id'], 'idtype' => $setarr['idtype'], 'title' => $pagetitle[$key], 'content' => $contents[$key], 'pageorder' => $key+1, 'dateline' => TIMESTAMP));
  163. }
  164. $pagecount = $cpostcount;
  165. }
  166. $updatearticle = array('contents' => $pagecount);
  167. if($article_status == 1) {
  168. $updatearticle['status'] = 1;
  169. updatemoderate('aid', $aid);
  170. manage_addnotify('verifyarticle');
  171. }
  172. C::t('portal_article_title')->update($aid, $updatearticle);
  173. $newaids = array();
  174. $_POST['attach_ids'] = explode(',', $_POST['attach_ids']);
  175. foreach ($_POST['attach_ids'] as $newaid) {
  176. $newaid = intval($newaid);
  177. if($newaid) $newaids[$newaid] = $newaid;
  178. }
  179. if($newaids) {
  180. C::t('portal_attachment')->update_to_used($newaids, $aid);
  181. }
  182. addrelatedarticle($aid, $_POST['raids']);
  183. if($_GET['from_idtype'] && $_GET['from_id']) {
  184. $id = intval($_GET['from_id']);
  185. $notify = array();
  186. switch ($_GET['from_idtype']) {
  187. case 'blogid':
  188. $blog = C::t('home_blog')->fetch($id);
  189. if(!empty($blog)) {
  190. $notify = array(
  191. 'url' => "home.php?mod=space&uid=$blog[uid]&do=blog&id=$id",
  192. 'subject' => $blog['subject']
  193. );
  194. $touid = $blog['uid'];
  195. }
  196. break;
  197. case 'tid':
  198. $thread = C::t('forum_thread')->fetch($id);
  199. if(!empty($thread)) {
  200. $notify = array(
  201. 'url' => "forum.php?mod=viewthread&tid=$id",
  202. 'subject' => $thread['subject']
  203. );
  204. $touid = $thread['authorid'];
  205. }
  206. break;
  207. }
  208. if(!empty($notify)) {
  209. $notify['newurl'] = 'portal.php?mod=view&aid='.$aid;
  210. notification_add($touid, 'pusearticle', 'puse_article', $notify, 1);
  211. }
  212. }
  213. $viewarticleurl = $_POST['url']?"portal.php?mod=list&catid=$_POST[catid]":'portal.php?mod=view&aid='.$aid;
  214. if(trim($_GET['from']) != '') {
  215. $from_cookie = '';
  216. $from_cookie_array = array();
  217. $from_cookie = getcookie('from_cookie');
  218. $from_cookie_array = explode("\t", $from_cookie);
  219. $from_cookie_array[] = $_GET['from'];
  220. $from_cookie_array = array_unique($from_cookie_array);
  221. $from_cookie_array = array_filter($from_cookie_array);
  222. $from_cookie_num = count($from_cookie_array);
  223. $from_cookie_start = $from_cookie_num - 10;
  224. $from_cookie_start = $from_cookie_start > 0 ? $from_cookie_start : 0;
  225. $from_cookie_array = array_slice($from_cookie_array, $from_cookie_start, $from_cookie_num);
  226. $from_cookie = implode("\t", $from_cookie_array);
  227. dsetcookie('from_cookie', $from_cookie);
  228. }
  229. dsetcookie('clearUserdata', 'home');
  230. $op = 'add_success';
  231. $article_add_url = 'portal.php?mod=portalcp&ac=article&catid='.$catid;
  232. include_once template("portal/portalcp_article");dexit();
  233. } elseif(submitcheck('pushplussubmit')) {
  234. if($aid) {
  235. check_articleperm($article['catid'], $aid, $article);
  236. } else {
  237. showmessage('no_article_specified_for_pushplus', dreferer());
  238. }
  239. $tourl = !empty($_POST['toedit']) ? 'portal.php?mod=portalcp&ac=article&op=edit&aid='.$aid : dreferer();
  240. $pids = (array)$_POST['pushpluspids'];
  241. $posts = array();
  242. $tid = intval($_GET['tid']);
  243. if($tid && $pids) {
  244. foreach(C::t('forum_post')->fetch_all('tid:'.$tid, $pids) as $value) {
  245. if($value['tid'] != $tid) {
  246. continue;
  247. }
  248. $posts[$value['pid']] = $value;
  249. }
  250. }
  251. if(empty($posts)) {
  252. showmessage('no_posts_for_pushplus', dreferer());
  253. }
  254. $pageorder = C::t('portal_article_content')->fetch_max_pageorder_by_aid($aid);
  255. $pageorder = intval($pageorder + 1);
  256. $inserts = array();
  257. foreach($posts as $post) {
  258. $summary = portalcp_get_postmessage($post);
  259. $summary .= lang('portalcp', 'article_pushplus_info', array('author'=>$post['author'], 'url'=>'forum.php?mod=redirect&goto=findpost&ptid='.$post['tid'].'&pid='.$post['pid']));
  260. $inserts[] = array('aid'=>$aid, 'content'=>$summary, 'pageorder'=>$pageorder, 'dateline'=>$_G['timestamp'], 'id'=>$post[pid], 'idtype' =>'pid');
  261. $pageorder++;
  262. }
  263. C::t('portal_article_content')->insert_batch($inserts);
  264. $pluscount = C::t('portal_article_content')->count_by_aid($aid);
  265. C::t('portal_article_title')->update($aid, array('contents' => $pluscount, 'owncomment' => 1));
  266. $commentnum = C::t('portal_comment')->count_by_id_idtype($aid, 'aid');
  267. C::t('portal_article_count')->update($aid, array('commentnum'=>intval($commentnum)));
  268. showmessage('pushplus_do_success', $tourl, array(), array('header'=>1, 'refreshtime'=>0));
  269. } elseif(submitcheck('verifysubmit')) {
  270. if($aid) {
  271. check_articleperm($article['catid'], $aid, $article, true);
  272. } else {
  273. showmessage('article_not_exist', dreferer());
  274. }
  275. if($_POST['status'] == '0') {
  276. C::t('portal_article_title')->update($aid, array('status'=>'0'));
  277. updatemoderate('aid', $aid, 2);
  278. $tourl = dreferer('portal.php?mod=view&aid='.$aid);
  279. showmessage('article_passed', $tourl);
  280. } elseif($_POST['status'] == '2') {
  281. C::t('portal_article_title')->update($aid, array('status'=>'2'));
  282. updatemoderate('aid', $aid, 1);
  283. $tourl = dreferer('portal.php?mod=view&aid='.$aid);
  284. showmessage('article_ignored', $tourl);
  285. } elseif($_POST['status'] == '-1') {
  286. include_once libfile('function/delete');
  287. deletearticle(array($aid), 0);
  288. updatemoderate('aid', $aid, 2);
  289. $tourl = dreferer('portal.php?mod=portalcp&catid='.$article['catid']);
  290. showmessage('article_deleted', $tourl);
  291. } else {
  292. showmessage('select_operation');
  293. }
  294. }
  295. if($op == 'delete') {
  296. if(!$aid) {
  297. showmessage('article_edit_nopermission');
  298. }
  299. check_articleperm($article['catid'], $aid, $article);
  300. if(submitcheck('deletesubmit')) {
  301. include_once libfile('function/delete');
  302. $article = deletearticle(array(intval($_POST['aid'])), intval($_POST['optype']));
  303. showmessage('article_delete_success', "portal.php?mod=list&catid={$article[0][catid]}");
  304. }
  305. } elseif($op == 'related') {
  306. $raid = intval($_GET['raid']);
  307. $ra = array();
  308. if($raid) {
  309. $ra = C::t('portal_article_title')->fetch($raid);
  310. }
  311. } elseif($op == 'batch') {
  312. check_articleperm($catid);
  313. $aids = $_POST['aids'];
  314. $optype = $_POST['optype'];
  315. if(empty($optype) || $optype == 'push') showmessage('article_action_invalid');
  316. $aids = array_map('intval', $aids);
  317. $aids = array_filter($aids);
  318. if(empty($aids)) showmessage('article_not_choose');
  319. if (submitcheck('batchsubmit')) {
  320. if ($optype == 'trash' || $optype == 'delete') {
  321. require_once libfile('function/delete');
  322. $istrash = $optype == 'trash' ? 1 : 0;
  323. $article = deletearticle($aids, $istrash);
  324. showmessage('article_delete_success', dreferer("portal.php?mod=portalcp&ac=category&catid={$article[0][catid]}"));
  325. } elseif($optype == 'move') {
  326. if($catid) {
  327. $categoryUpdate = array();
  328. foreach(C::t('portal_article_title')->fetch_all($aids) as $s_article) {
  329. $categoryUpdate[$s_article['catid']] = $categoryUpdate[$s_article['catid']] ? --$categoryUpdate[$s_article['catid']] : -1;
  330. $categoryUpdate[$catid] = $categoryUpdate[$catid] ? ++$categoryUpdate[$catid] : 1;
  331. }
  332. foreach($categoryUpdate as $scatid=>$scatnum) {
  333. if($scatnum) {
  334. C::t('portal_category')->increase($scatid, array('articles' => $scatnum));
  335. }
  336. }
  337. C::t('portal_article_title')->update($aids, array('catid'=>$catid));
  338. showmessage('article_move_success', dreferer("portal.php?mod=portalcp&ac=category&catid=$catid"));
  339. } else {
  340. showmessage('article_move_select_cat', dreferer());
  341. }
  342. }
  343. }
  344. } elseif($op == 'verify') {
  345. if($aid) {
  346. check_articleperm($article['catid'], $aid, $article);
  347. } else {
  348. showmessage('article_not_exist', dreferer());
  349. }
  350. } elseif($op == 'pushplus') {
  351. if($aid) {
  352. check_articleperm($article['catid'], $aid, $article);
  353. } else {
  354. showmessage('no_article_specified_for_pushplus', dreferer());
  355. }
  356. $pids = (array)$_POST['topiclist'];
  357. $tid = intval($_GET['tid']);
  358. $pushedids = array();
  359. $pushcount = $pushedcount = 0;
  360. if(!empty($pids)) {
  361. foreach(C::t('portal_article_content')->fetch_all($aid) as $value) {
  362. $pushedids[] = intval($value['id']);
  363. $pushedcount++;
  364. }
  365. $pids = array_diff($pids, $pushedids);
  366. }
  367. $pushcount = count($pids);
  368. if(empty($pids)) {
  369. showmessage($pushedids ? 'all_posts_pushed_already' : 'no_posts_for_pushplus');
  370. }
  371. } else {
  372. if(empty($_G['cache']['portalcategory'])) {
  373. showmessage('portal_has_not_category');
  374. }
  375. if(!checkperm('allowmanagearticle') && !checkperm('allowpostarticle')) {
  376. $allowcategorycache = array();
  377. if($allowcategory = getallowcategory($_G['uid'])) {
  378. foreach($allowcategory as $catid => $category) {
  379. $allowcategorycache[$catid] = $_G['cache']['portalcategory'][$catid];
  380. }
  381. }
  382. foreach($allowcategorycache as &$_value) {
  383. if($_value['upid'] && !isset($allowcategorycache[$_value['upid']])) {
  384. $_value['level'] = 0;
  385. }
  386. }
  387. $_G['cache']['portalcategory'] = $allowcategorycache;
  388. }
  389. if(empty($_G['cache']['portalcategory'])) {
  390. showmessage('portal_article_add_nopermission');
  391. }
  392. $category = $_G['cache']['portalcategory'];
  393. $cate = $category[$catid];
  394. $categoryselect = category_showselect('portal', 'catid', true, !empty($article['catid']) ? $article['catid'] : $catid);
  395. if($aid) {
  396. $catid = intval($article['catid']);
  397. }
  398. if($aid && $article['highlight']) {
  399. $stylecheck = '';
  400. $stylecheck = explode('|', $article['highlight']);
  401. }
  402. $from_cookie_str = '';
  403. $from_cookie = array();
  404. $from_cookie_str = stripcslashes(getcookie('from_cookie'));
  405. $from_cookie = explode("\t", $from_cookie_str);
  406. $from_cookie = array_filter($from_cookie);
  407. if($article) {
  408. foreach(C::t('portal_article_content')->fetch_all($aid) as $key => $value) {
  409. $nextpage = '';
  410. if($key > 0) {
  411. $pagetitle = $value['title'] ? '[title='.$value['title'].']' : '';
  412. $nextpage = "\r\n".'<strong>##########NextPage'.$pagetitle.'##########</strong>';
  413. } else {
  414. $article_content['title'] = $value['title'];
  415. }
  416. $article_content['content'] .= $nextpage.$value['content'];
  417. }
  418. $article['attach_image'] = $article['attach_file'] = '';
  419. foreach(C::t('portal_attachment')->fetch_all_by_aid($aid) as $value) {
  420. if($value['isimage']) {
  421. if($article['pic']) {
  422. $value['pic'] = $article['pic'];
  423. }
  424. } else {
  425. }
  426. $attachs[] = $value;
  427. }
  428. if($article['idtype'] == 'tid') {
  429. foreach(C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$article['id'], 'tid', $article['id']) as $value) {
  430. if($value['isimage']) {
  431. if($article['pic']) {
  432. $value['pic'] = $article['pic'];
  433. }
  434. $value['attachid'] = $value['aid'];
  435. } else {
  436. }
  437. $value['from'] = 'forum';
  438. $attachs[] = $value;
  439. }
  440. }
  441. if($article['pic']) {
  442. $article['conver'] = addslashes(serialize(array('pic'=>$article['pic'], 'thumb'=>$article['thumb'], 'remote'=>$article['remote'])));
  443. }
  444. $article['related'] = array();
  445. if(($relateds = C::t('portal_article_related')->fetch_all_by_aid($aid))) {
  446. foreach(C::t('portal_article_title')->fetch_all(array_keys($relateds)) as $raid=>$value) {
  447. $article['related'][$raid] = $value['title'];
  448. }
  449. }
  450. }
  451. $_GET['from_id'] = empty ($_GET['from_id'])?0:intval($_GET['from_id']);
  452. if($_GET['from_idtype'] != 'blogid') $_GET['from_idtype'] = 'tid';
  453. $idtypes = array($_GET['from_idtype'] => ' selected');
  454. if($_GET['from_idtype'] && $_GET['from_id']) {
  455. $havepush = C::t('portal_article_title')->fetch_count_for_idtype($_GET['from_id'], $_GET['from_idtype']);
  456. if($havepush) {
  457. if($_GET['from_idtype'] == 'blogid') {
  458. showmessage('article_push_blogid_invalid_repeat', '', array(), array('return'=>true));
  459. } else {
  460. showmessage('article_push_tid_invalid_repeat', '', array(), array('return'=>true));
  461. }
  462. }
  463. switch ($_GET['from_idtype']) {
  464. case 'blogid':
  465. $blog = array_merge(
  466. C::t('home_blog')->fetch($_GET['from_id']),
  467. C::t('home_blogfield')->fetch($_GET['from_id'])
  468. );
  469. if($blog) {
  470. if($blog['friend']) {
  471. showmessage('article_push_invalid_private');
  472. }
  473. $article['title'] = getstr($blog['subject'], 0);
  474. $article['summary'] = portalcp_get_summary($blog['message']);
  475. $article['fromurl'] = 'home.php?mod=space&uid='.$blog[uid].'&do=blog&id='.$blog[blogid];
  476. $article['author'] = $blog['username'];
  477. $article_content['content'] = dhtmlspecialchars($blog['message']);
  478. }
  479. break;
  480. default:
  481. $posttable = getposttablebytid($_GET['from_id']);
  482. $thread = C::t('forum_thread')->fetch($_GET['from_id']);
  483. $thread = array_merge($thread, C::t('forum_post')->fetch_threadpost_by_tid_invisible($_GET['from_id']));
  484. if($thread) {
  485. $article['title'] = $thread['subject'];
  486. $thread['message'] = portalcp_get_postmessage($thread, $_GET['getauthorall']);
  487. $article['summary'] = portalcp_get_summary($thread['message']);
  488. $article['fromurl'] = 'forum.php?mod=viewthread&tid='.$thread['tid'];
  489. $article['author'] = $thread['author'];
  490. $article_content['content'] = dhtmlspecialchars($thread['message']);
  491. $article['attach_image'] = $article['attach_file'] = '';
  492. foreach(C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$thread['tid'], 'pid', $thread['pid'], 'aid DESC') as $attach) {
  493. $attachcode = '[attach]'.$attach['aid'].'[/attach]';
  494. if(!strexists($article_content['content'], $attachcode)) {
  495. $article_content['content'] .= '<br /><br />'.$attachcode;
  496. }
  497. if($attach['isimage']) {
  498. if($article['pic']) {
  499. $attach['pic'] = $article['pic'];
  500. }
  501. } else {
  502. }
  503. $attach['from'] = 'forum';
  504. $attachs[] = $attach;
  505. }
  506. }
  507. break;
  508. }
  509. }
  510. if(!empty($article['dateline'])) {
  511. $article['dateline'] = dgmdate($article['dateline']);
  512. }
  513. if(!empty($attachs)) {
  514. $article['attachs'] = get_upload_content($attachs);
  515. }
  516. $article_tags = article_parse_tags($article['tag']);
  517. $tag_names = article_tagnames();
  518. }
  519. require_once libfile('function/upload');
  520. $swfconfig = getuploadconfig($_G['uid'], 0, false);
  521. require_once libfile('function/spacecp');
  522. $albums = getalbums($_G['uid']);
  523. include_once template("portal/portalcp_article");
  524. function portalcp_get_summary($message) {
  525. $message = preg_replace(array("/\[attach\].*?\[\/attach\]/", "/\&[a-z]+\;/i", "/\<script.*?\<\/script\>/"), '', $message);
  526. $message = preg_replace("/\[.*?\]/", '', $message);
  527. $message = getstr(strip_tags($message), 200);
  528. return $message;
  529. }
  530. function portalcp_get_postmessage($post, $getauthorall = '') {
  531. global $_G;
  532. $forum = C::t('forum_forum')->fetch($post['fid']);
  533. require_once libfile('function/discuzcode');
  534. $language = lang('forum/misc');
  535. if($forum['type'] == 'sub' && $forum['status'] == 3) {
  536. loadcache('grouplevels');
  537. $grouplevel = $_G['grouplevels'][$forum['level']];
  538. $group_postpolicy = $grouplevel['postpolicy'];
  539. if(is_array($group_postpolicy)) {
  540. $forum = array_merge($forum, $group_postpolicy);
  541. }
  542. }
  543. $post['message'] = preg_replace($language['post_edit_regexp'], '', $post['message']);
  544. $_message = '';
  545. if($getauthorall) {
  546. foreach(C::t('forum_post')->fetch_all_by_tid('tid:'.$post['tid'], $post['tid'], true, '', 0, 0, null, null, $post['authorid']) as $value){
  547. if(!$value['first']) {
  548. $value['message'] = preg_replace("/\s?\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s?/is", '', $value['message']);
  549. $value['message'] = discuzcode($value['message'], $value['smileyoff'], $value['bbcodeoff'], $value['htmlon'] & 1, $forum['allowsmilies'], $forum['allowbbcode'], ($forum['allowimgcode'] && $_G['setting']['showimages'] ? 1 : 0), $forum['allowhtml'], 0, 0, $value['authorid'], $forum['allowmediacode'], $value['pid']);
  550. portalcp_parse_postattch($value);
  551. $_message .= '<br /><br />'.$value['message'];
  552. }
  553. }
  554. }
  555. $msglower = strtolower($post['message']);
  556. if(strpos($msglower, '[/media]') !== FALSE) {
  557. $post['message'] = preg_replace("/\[media=([\w,]+)\]\s*([^\[\<\r\n]+?)\s*\[\/media\]/ies", "parsearticlemedia('\\1', '\\2')", $post['message']);
  558. }
  559. if(strpos($msglower, '[/audio]') !== FALSE) {
  560. $post['message'] = preg_replace("/\[audio(=1)*\]\s*([^\[\<\r\n]+?)\s*\[\/audio\]/ies", "parsearticlemedia('mid,0,0', '\\2')", $post['message']);
  561. }
  562. if(strpos($msglower, '[/flash]') !== FALSE) {
  563. $post['message'] = preg_replace("/\[flash(=(\d+),(\d+))?\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/ies", "parsearticlemedia('swf,0,0', '\\4');", $post['message']);
  564. }
  565. $post['message'] = discuzcode($post['message'], $post['smileyoff'], $post['bbcodeoff'], $post['htmlon'] & 1, $forum['allowsmilies'], $forum['allowbbcode'], ($forum['allowimgcode'] && $_G['setting']['showimages'] ? 1 : 0), $forum['allowhtml'], 0, 0, $post['authorid'], $forum['allowmediacode'], $post['pid']);
  566. portalcp_parse_postattch($post);
  567. if(strpos($post['message'], '[/flash1]') !== FALSE) {
  568. $post['message'] = str_replace('[/flash1]', '[/flash]', $post['message']);
  569. }
  570. return $post['message'].$_message;
  571. }
  572. function portalcp_parse_postattch(&$post) {
  573. static $allpostattchs = null;
  574. if($allpostattchs === null) {
  575. foreach(C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$post['tid'], 'tid', $post['tid']) as $attch) {
  576. $allpostattchs[$attch['pid']][$attch['aid']] = $attch['aid'];
  577. }
  578. }
  579. $attachs = $allpostattchs[$post['pid']];
  580. if(preg_match_all("/\[attach\](\d+)\[\/attach\]/i", $post['message'], $matchaids)) {
  581. $attachs = array_diff($allpostattchs[$post['pid']], $matchaids[1]);
  582. }
  583. if($attachs) {
  584. $add = '';
  585. foreach($attachs as $attachid) {
  586. $add .= '<br/>'.'[attach]'.$attachid.'[/attach]';
  587. }
  588. $post['message'] .= $add;
  589. }
  590. }
  591. function parsearticlemedia($params, $url) {
  592. global $_G;
  593. $params = explode(',', $params);
  594. $width = intval($params[1]) > 800 ? 800 : intval($params[1]);
  595. $height = intval($params[2]) > 600 ? 600 : intval($params[2]);
  596. $url = addslashes($url);
  597. if($flv = parseflv($url, 0, 0)) {
  598. if(!empty($flv) && preg_match("/\.flv$/i", $flv['flv'])) {
  599. $flv['flv'] = $_G['style']['imgdir'].'/flvplayer.swf?&autostart=true&file='.urlencode($flv['flv']);
  600. }
  601. $url = $flv['flv'];
  602. $params[0] = 'swf';
  603. }
  604. if(in_array(count($params), array(3, 4))) {
  605. $type = $params[0];
  606. $url = str_replace(array('<', '>'), '', str_replace('\\"', '\"', $url));
  607. switch($type) {
  608. case 'mp3':
  609. case 'wma':
  610. case 'ra':
  611. case 'ram':
  612. case 'wav':
  613. case 'mid':
  614. return '[flash=mp3]'.$url.'[/flash1]';
  615. case 'rm':
  616. case 'rmvb':
  617. case 'rtsp':
  618. return '[flash=real]'.$url.'[/flash1]';
  619. case 'swf':
  620. return '[flash]'.$url.'[/flash1]';
  621. case 'asf':
  622. case 'asx':
  623. case 'wmv':
  624. case 'mms':
  625. case 'avi':
  626. case 'mpg':
  627. case 'mpeg':
  628. case 'mov':
  629. return '[flash=media]'.$url.'[/flash1]';
  630. default:
  631. return '<a href="'.$url.'" target="_blank">'.$url.'</a>';
  632. }
  633. }
  634. return;
  635. }
  636. ?>