portalcp_article.php 26 KB

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