PageRenderTime 60ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/source/include/portalcp/portalcp_article.php

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