PageRenderTime 49ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/common/module/post.php

http://lazycms.googlecode.com/
PHP | 655 lines | 443 code | 6 blank | 206 comment | 80 complexity | 2012e6a5f174577b3f1413b28b93ee99 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * +---------------------------------------------------------------------------+
  4. * | LL LLLL LL L LLLL LLLL |
  5. * | LL LL L LLL LL LL L LL LL |
  6. * | LL LLLL LLLLL LL LL LL LLLL LLL LL LL LL LL |
  7. * | LL LL LL LL LL LL L LLL LL LLLLL LL LL LL |
  8. * | LL LLLLL LL LLLL LL L L LL LLLLL LL LL LL |
  9. * | LL LL LL LL LLLL LL L LL LL LLLL LL |
  10. * | LL LL LL LL LL LL L L LL L LL LLLL LL |
  11. * | LLLLLL LLLLL LLLLL LL LLLL L LL LLLL LL LLLLLL |
  12. * | LL |
  13. * | LL |
  14. * +---------------------------------------------------------------------------+
  15. * | Copyright (C) 2007-2010 LazyCMS.com All rights reserved. |
  16. * +---------------------------------------------------------------------------+
  17. * | LazyCMS is free software. See LICENSE for copyright notices and details. |
  18. * +---------------------------------------------------------------------------+
  19. */
  20. defined('COM_PATH') or die('Restricted access!');
  21. /**
  22. * ????
  23. *
  24. * @param $title
  25. * @param $content
  26. * @param $path
  27. * @param $data
  28. * @return array
  29. */
  30. function post_add($title,$content,$path,$data=null) {
  31. $postid = get_conn()->insert('#@_post',array(
  32. 'title' => $title,
  33. 'content' => $content,
  34. 'path' => $path,
  35. 'type' => 'post',
  36. 'approved' => 'passed',
  37. 'datetime' => time(),
  38. 'edittime' => time(),
  39. ));
  40. $data['path'] = $path;
  41. return post_edit($postid,$data);
  42. }
  43. /**
  44. * ??????
  45. *
  46. * @param int $postid
  47. * @param array $data
  48. * @return array
  49. */
  50. function post_edit($postid,$data) {
  51. $postid = intval($postid);
  52. if ($post = post_get($postid)) {
  53. $tpl = tpl_init('page-404');
  54. $data = is_array($data) ? $data : array();
  55. // ?????
  56. if (isset($data['path'])) {
  57. $data['path'] = path_format($data['path'],array(
  58. 'ID' => $postid,
  59. 'PY' => $post['title'],
  60. 'MD5' => $postid,
  61. ));
  62. // ?????
  63. if ($data['path'] != $post['path']) {
  64. $post['path'] = post_get_path($post['listid'],$post['path']);
  65. $post['edittime'] = $post['edittime'] ? $post['edittime'] : time();
  66. // ??????24??
  67. if (time()-$post['edittime'] > 86400) {
  68. // ????????
  69. if (strncmp($data['path'],'/',1) === 0) {
  70. $path = ltrim($data['path'], '/');
  71. } elseif ($post['listid'] > 0) {
  72. $taxonomy = taxonomy_get($post['listid']);
  73. $path = $taxonomy['path'].'/'.$data['path'];
  74. }
  75. $html = tpl_loadfile(ABS_PATH.'/'.system_themes_path().'/'.esc_html(C('TPL-404')));
  76. tpl_clean($tpl);
  77. tpl_set_var(array(
  78. 'path' => ROOT.$post['path'],
  79. 'url' => ROOT.$path,
  80. 'title' => $post['title'],
  81. 'keywords' => post_get_taxonomy($post['keywords']),
  82. 'description' => $post['description'],
  83. ), $tpl);
  84. $html = tpl_parse($html, $tpl);
  85. $file = ABS_PATH.'/'.$post['path'];
  86. mkdirs(dirname($file));
  87. file_put_contents($file,$html);
  88. // ??????
  89. $data['edittime'] = time();
  90. }
  91. // ?????
  92. elseif (is_file(ABS_PATH.'/'.$post['path'])){
  93. unlink(ABS_PATH.'/'.$post['path']);
  94. }
  95. }
  96. }
  97. $category = isset($data['category']) ? $data['category'] : null;
  98. $keywords = isset($data['keywords']) ? $data['keywords'] : null;
  99. unset($data['category'],$data['keywords']);
  100. $meta_rows = empty($data['meta']) ? array() : $data['meta']; unset($data['meta']);
  101. $post_rows = $data; $data['meta'] = $meta_rows; $data['category'] = $category;
  102. // ????
  103. if (!empty($post_rows)) {
  104. get_conn()->update('#@_post',$post_rows,array('postid' => $postid));
  105. }
  106. if (!empty($meta_rows)) {
  107. post_edit_meta($postid,$meta_rows);
  108. }
  109. // ??????
  110. if ($data['category']) {
  111. taxonomy_make_relation('category',$postid,$data['category']);
  112. }
  113. // ?????
  114. if ($keywords) {
  115. $taxonomies = array();
  116. if (!is_array($keywords)) {
  117. // ????????????
  118. $keywords = str_replace(array('?','?'),array(',',' '),$keywords);
  119. // ??,?????
  120. $keywords = explode(',',$keywords);
  121. // ??????????????
  122. if (count($keywords)==1) $keywords = explode(' ',$keywords[0]);
  123. }
  124. // ????????
  125. $keywords = array_unique($keywords);
  126. // ?????????????HTML
  127. array_walk($keywords,create_function('&$s','$s=esc_html(trim($s));'));
  128. // ???????
  129. foreach($keywords as $key) {
  130. $taxonomies[] = taxonomy_add_tag($key, 'post_tag');
  131. }
  132. $data['keywords'] = implode(',',$keywords);
  133. // ????
  134. taxonomy_make_relation('post_tag',$postid,$taxonomies);
  135. }
  136. // ????
  137. post_clean_cache($postid);
  138. return array_merge($post,$data);
  139. }
  140. return null;
  141. }
  142. /**
  143. * ????????
  144. *
  145. * @param $postid
  146. * @param $path ???format_path()???????
  147. * @return bool
  148. */
  149. function post_path_exists($postid,$path) {
  150. if (strpos($path,'%ID')!==false && strpos($path,'%MD5')!==false) return false;
  151. if ($postid) {
  152. $sql = sprintf("SELECT COUNT(`postid`) FROM `#@_post` WHERE `path`='%s' AND `postid`<>'%d';", esc_sql($path), esc_sql($postid));
  153. } else {
  154. $sql = sprintf("SELECT COUNT(`postid`) FROM `#@_post` WHERE `path`='%s';",esc_sql($path));
  155. }
  156. return !(get_conn()->result($sql) == 0);
  157. }
  158. /**
  159. * ??????
  160. *
  161. * @param string $type
  162. * @return int
  163. */
  164. function post_count($type) {
  165. return get_conn()->result(sprintf("SELECT COUNT(`postid`) FROM `#@_post` WHERE `type`='%s' AND `approved`='passed';", $type));
  166. }
  167. /**
  168. * ???????
  169. *
  170. * @param int $postid
  171. * @return array
  172. */
  173. function post_get($postid) {
  174. $db = get_conn();
  175. $ckey = sprintf('post.%d',$postid);
  176. $post = fcache_get($ckey);
  177. if (fcache_not_null($post)) return $post;
  178. $rs = $db->query("SELECT * FROM `#@_post` WHERE `postid`=%d LIMIT 1 OFFSET 0;",$postid);
  179. // ????????
  180. if ($post = $db->fetch($rs)) {
  181. // ??????
  182. $post['content'] = media_decode($post['content']);
  183. // ??????
  184. $post['category'] = taxonomy_get_relation('category',$postid);
  185. $post['keywords'] = taxonomy_get_relation('post_tag',$postid);
  186. if ($meta = post_get_meta($post['postid'])) {
  187. $post['meta'] = $meta;
  188. }
  189. // ?????
  190. fcache_set($ckey,$post);
  191. return $post;
  192. }
  193. return null;
  194. }
  195. /**
  196. * ??????
  197. *
  198. * @param int $listid
  199. * @param string $path
  200. * @param string $prefix
  201. * @return string
  202. */
  203. function post_get_path($listid,$path,$prefix='') {
  204. if ($prefix) {
  205. $prefix = !substr_compare($prefix,'/',strlen($prefix)-1,1) ? $prefix : $prefix.'/';
  206. if (strncmp($prefix,'/',1) === 0) {
  207. return ltrim($prefix,'/').ltrim($path, '/');
  208. }
  209. }
  210. if (strncmp($path,'/',1) === 0) {
  211. $path = ltrim($prefix,'/').ltrim($path, '/');
  212. } elseif ($listid > 0) {
  213. $taxonomy = taxonomy_get($listid);
  214. if (isset($taxonomy['path'])) {
  215. $path = $taxonomy['path'].'/'.$prefix.$path;
  216. }
  217. } else {
  218. $path = $prefix.$path;
  219. }
  220. return $path;
  221. }
  222. /**
  223. * ???????
  224. *
  225. * @param int $postid
  226. * @param string $suffixs
  227. * @return array
  228. */
  229. function post_get_medias($postid, $suffixs='*') {
  230. $medias = array();
  231. if ($post = post_get($postid)) {
  232. if (isset($post['meta']['__medias__']) && $post['meta']['__medias__']) {
  233. foreach (explode(',', $post['meta']['__medias__']) as $id) {
  234. if (($media=media_get($id)) && ($suffixs=='*' || instr($media['suffix'], $suffixs))) {
  235. $medias[] = $media;
  236. }
  237. }
  238. }
  239. }
  240. return $medias;
  241. }
  242. /**
  243. * ?????
  244. *
  245. * @param array $keywords
  246. * @param bool $isjoin
  247. * @return array|string
  248. */
  249. function post_get_taxonomy($keywords, $isjoin=false) {
  250. $result = array();
  251. foreach((array)$keywords as $taxonomyid) {
  252. $taxonomy = taxonomy_get($taxonomyid);
  253. $result[$taxonomyid] = str_replace(chr(44), '&#44;', $taxonomy['name']);
  254. }
  255. return $isjoin ? implode(',', $result) : $result;
  256. }
  257. /**
  258. * ?????????
  259. *
  260. * @param $postid
  261. * @return array
  262. */
  263. function post_get_meta($postid) {
  264. $db = get_conn(); $result = array(); $postid = intval($postid);
  265. $rs = $db->query("SELECT * FROM `#@_post_meta` WHERE `postid`=%d;",$postid);
  266. while ($row = $db->fetch($rs)) {
  267. $result[$row['key']] = is_serialized($row['value']) ? unserialize($row['value']) : $row['value'];
  268. }
  269. return $result;
  270. }
  271. /**
  272. * ?????????
  273. *
  274. * @param $postid
  275. * @param $data
  276. * @return bool
  277. */
  278. function post_edit_meta($postid,$data) {
  279. $db = get_conn(); $postid = intval($postid);
  280. if (!is_array($data)) return false;
  281. foreach ($data as $key=>$value) {
  282. // ????????????
  283. $length = (int) $db->result(vsprintf("SELECT COUNT(*) FROM `#@_post_meta` WHERE `postid`=%d AND `key`='%s';",array($postid,esc_sql($key))));
  284. // update
  285. if ($length > 0) {
  286. $db->update('#@_post_meta',array(
  287. 'value' => $value,
  288. ),array(
  289. 'postid' => $postid,
  290. 'key' => $key,
  291. ));
  292. }
  293. // insert
  294. else {
  295. // ???????
  296. $db->insert('#@_post_meta',array(
  297. 'postid' => $postid,
  298. 'key' => $key,
  299. 'value' => $value,
  300. ));
  301. }
  302. }
  303. return true;
  304. }
  305. /**
  306. * ??????
  307. *
  308. * @param $postid
  309. * @return bool
  310. */
  311. function post_clean_cache($postid) {
  312. return fcache_delete('post.'.$postid);
  313. }
  314. /**
  315. * ??????
  316. *
  317. * @param $postid
  318. * @return bool
  319. */
  320. function post_delete($postid) {
  321. $db = get_conn();
  322. $postid = intval($postid);
  323. if (!$postid) return false;
  324. if ($post = post_get($postid)) {
  325. // ????
  326. $post['path'] = post_get_path($post['listid'],$post['path']);
  327. // ????
  328. if (is_file(ABS_PATH.'/'.$post['path'])) {
  329. if (!unlink(ABS_PATH.'/'.$post['path'])) {
  330. return false;
  331. }
  332. }
  333. // ??????
  334. foreach($post['category'] as $taxonomyid) {
  335. taxonomy_delete_relation($postid,$taxonomyid);
  336. }
  337. // ???????
  338. foreach($post['keywords'] as $taxonomyid) {
  339. taxonomy_delete_relation($postid,$taxonomyid);
  340. }
  341. $db->delete('#@_post_meta',array('postid' => $postid));
  342. $db->delete('#@_post',array('postid' => $postid));
  343. // ????
  344. post_clean_cache($postid);
  345. return true;
  346. }
  347. return false;
  348. }
  349. /**
  350. * ????
  351. *
  352. * @param $postid
  353. * @return bool
  354. */
  355. function post_create($postid,&$preid=0,&$nextid=0) {
  356. $postid = intval($postid);
  357. if (!$postid) return false;
  358. if ($post = post_get($postid)) {
  359. $tpl = tpl_init('post');
  360. $b_guid = $inner = ''; comment_create($post['postid']); // ????
  361. // ????
  362. $post['list'] = taxonomy_get($post['listid']);
  363. $post['cmt_path'] = post_get_path($post['listid'],$post['path'], C('CMT-Path'));
  364. $post['path'] = post_get_path($post['listid'],$post['path']);
  365. // ????????????>????>????
  366. if (empty($post['template'])) {
  367. if ($post['listid'] > 0) {
  368. $taxonomy = taxonomy_get($post['listid']);
  369. $post['template'] = $taxonomy['page'];
  370. }
  371. // ??????
  372. if (empty($post['template'])) {
  373. $model = model_get_bycode($post['model']);
  374. $post['template'] = $model['page'];
  375. }
  376. }
  377. // ????
  378. $html = tpl_loadfile(ABS_PATH.'/'.system_themes_path().'/'.esc_html($post['template']));
  379. $vars = array(
  380. 'postid' => $post['postid'],
  381. 'userid' => $post['userid'],
  382. 'author' => $post['author'],
  383. 'views' => '<script type="text/javascript" src="'.ROOT.'common/gateway.php?func=post_views&postid='.$post['postid'].'&updated=true"></script>',
  384. 'comment' => '<script type="text/javascript" src="'.ROOT.'common/gateway.php?func=post_comment&postid='.$post['postid'].'"></script>',
  385. 'people' => '<script type="text/javascript" src="'.ROOT.'common/gateway.php?func=post_comment_people&postid='.$post['postid'].'"></script>',
  386. 'digg' => $post['digg'],
  387. 'date' => $post['datetime'],
  388. 'edittime' => $post['edittime'],
  389. 'keywords' => post_get_taxonomy($post['keywords']),
  390. 'prepage' => post_prepage($post['listid'],$post['postid'],$preid),
  391. 'nextpage' => post_nextpage($post['listid'],$post['postid'],$nextid),
  392. 'cmt_state' => $post['comments'],
  393. 'cmt_ajaxinfo' => ROOT.'common/gateway.php?func=post_ajax_comment&postid='.$post['postid'],
  394. 'cmt_replyurl' => ROOT.'common/gateway.php?func=post_send_comment&postid='.$post['postid'],
  395. 'cmt_listsurl' => ROOT.$post['cmt_path'],
  396. 'description' => $post['description'],
  397. );
  398. // ????????
  399. $images = post_get_medias($post['postid'], C('UPIMG-Exts'));
  400. foreach($images as $k=>$image) {
  401. if ($k == 0) $vars['image'] = $image['url'];
  402. $vars['images'][($k+1)] = $image['url'];
  403. }
  404. // ??????
  405. if (isset($post['list'])) {
  406. $vars['list'] = array(
  407. 'id' => $post['list']['taxonomyid'],
  408. 'name' => $post['list']['name'],
  409. 'path' => ROOT.$post['list']['path'].'/',
  410. 'count' => '<script type="text/javascript" src="'.ROOT.'common/gateway.php?func=taxonomy_count&listid='.$post['list']['taxonomyid'].'"></script>',
  411. );
  412. if (isset($post['list']['meta'])) {
  413. foreach((array)$post['list']['meta'] as $k=>$v) {
  414. $vars['list'][$k] = $v;
  415. }
  416. }
  417. }
  418. // ????
  419. tpl_clean($tpl);
  420. tpl_set_var($b_guid, $inner, $tpl);
  421. tpl_set_var($vars, $tpl);
  422. // ???????
  423. if (isset($post['meta'])) {
  424. tpl_set_var('post', $post['meta'], $tpl);
  425. }
  426. // ????
  427. $guide = system_category_guide($post['listid']);
  428. // ????
  429. if ($post['content'] && strpos($post['content'],'<!--pagebreak-->')!==false) {
  430. $contents = explode('<!--pagebreak-->',$post['content']);
  431. // ???
  432. $pages = count($contents);
  433. if (($pos=strrpos($post['path'],'.')) !== false) {
  434. $basename = substr($post['path'],0,$pos);
  435. $suffix = substr($post['path'],$pos);
  436. } else {
  437. $basename = $post['path'];
  438. $suffix = '';
  439. }
  440. foreach($contents as $i=>$content) {
  441. $page = $i + 1;
  442. if ($page == 1) {
  443. $path = $basename.$suffix;
  444. $title = $post['title'];
  445. } else {
  446. $path = $basename.'_'.$page.$suffix;
  447. $title = $post['title'].' ('.$page.')';
  448. tpl_set_var('views', '<script type="text/javascript" src="'.ROOT.'common/gateway.php?func=post_views&postid='.$post['postid'].'"></script>', $tpl);
  449. }
  450. tpl_set_var(array(
  451. 'guide' => $guide ? $guide.' &gt;&gt; '.$title : $title,
  452. 'title' => $title,
  453. 'content' => $content,
  454. 'path' => ROOT.$path,
  455. ), $tpl);
  456. $pagehtml = tpl_parse($html, $tpl);
  457. // ??????
  458. if (stripos($pagehtml,'{pagelist') !== false) {
  459. $pagehtml = preg_replace('/\{(pagelist)[^\}]*\/\}/isU',
  460. pages_list(ROOT.$basename.'_$'.$suffix, '!_$', $page, $pages, 1),
  461. $pagehtml
  462. );
  463. }
  464. // ???????
  465. $file = ABS_PATH.'/'.$path;
  466. // ????
  467. mkdirs(dirname($file));
  468. // ????
  469. file_put_contents($file,$pagehtml);
  470. }
  471. }
  472. // ????
  473. else {
  474. tpl_set_var(array(
  475. 'guide' => $guide ? $guide.' &gt;&gt; '.$post['title'] : $post['title'],
  476. 'title' => $post['title'],
  477. 'content' => $post['content'],
  478. 'path' => ROOT.$post['path'],
  479. ), $tpl);
  480. // ??????
  481. if (stripos($html,'{pagelist') !== false) {
  482. $html = preg_replace('/\{(pagelist)[^\}]*\/\}/isU','',$html);
  483. }
  484. $html = tpl_parse($html, $tpl);
  485. // ???????
  486. $file = ABS_PATH.'/'.$post['path'];
  487. // ????
  488. mkdirs(dirname($file));
  489. // ????
  490. return file_put_contents($file,$html);
  491. }
  492. }
  493. return true;
  494. }
  495. /**
  496. * ???
  497. *
  498. * @param int $listid
  499. * @param int $postid
  500. * @param int &$preid
  501. * @return string
  502. */
  503. function post_prepage($listid,$postid,&$preid=0) {
  504. $preid = get_conn()->result(sprintf("SELECT `objectid` FROM `#@_term_relation` WHERE `taxonomyid`=%d AND `objectid`<%d ORDER BY `objectid` DESC LIMIT 1 OFFSET 0;", esc_sql($listid), esc_sql($postid)));
  505. if ($preid) {
  506. $post = post_get($preid);
  507. $post['path'] = post_get_path($post['listid'],$post['path']);
  508. $result = '<a href="'.ROOT.$post['path'].'">'.$post['title'].'</a>';
  509. } elseif($listid) {
  510. $post = post_get($postid);
  511. $post['list'] = taxonomy_get($post['listid']);
  512. $result = '<a href="'.ROOT.$post['list']['path'].'/">['.$post['list']['name'].']</a>';
  513. } else {
  514. $result = '['.__('Not Supported').']';
  515. }
  516. return $result;
  517. }
  518. /**
  519. * ???
  520. *
  521. * @param int $listid
  522. * @param int $postid
  523. * @param int &$nextid
  524. * @return string
  525. */
  526. function post_nextpage($listid,$postid,&$nextid=0) {
  527. $nextid = get_conn()->result(sprintf("SELECT `objectid` FROM `#@_term_relation` WHERE `taxonomyid`=%d AND `objectid`>%d ORDER BY `objectid` ASC LIMIT 1 OFFSET 0;", esc_sql($listid), esc_sql($postid)));
  528. if ($nextid) {
  529. $post = post_get($nextid);
  530. $post['path'] = post_get_path($post['listid'],$post['path']);
  531. $result = '<a href="'.ROOT.$post['path'].'">'.$post['title'].'</a>';
  532. } elseif($listid) {
  533. $post = post_get($postid);
  534. $post['list'] = taxonomy_get($post['listid']);
  535. $result = '<a href="'.ROOT.$post['list']['path'].'/">['.$post['list']['name'].']</a>';
  536. } else {
  537. $result = '['.__('Not Supported').']';
  538. }
  539. return $result;
  540. }
  541. /**
  542. * ??????
  543. *
  544. * @return
  545. */
  546. function post_gateway_ajax_comment() {
  547. $postid = isset($_GET['postid']) ? $_GET['postid'] : 0;
  548. $comment_count = comment_count($postid);
  549. $comment_people = comment_people($postid);
  550. return array($comment_count,$comment_people);
  551. }
  552. /**
  553. * ?????
  554. *
  555. * @return string
  556. */
  557. function post_gateway_views() {
  558. $postid = isset($_GET['postid']) ? $_GET['postid'] : 0;
  559. $updated = isset($_GET['updated']) ? $_GET['updated'] : null;
  560. if (post_get($postid)) {
  561. $db = get_conn();
  562. $views = $db->result(sprintf("SELECT `views` FROM `#@_post` WHERE `postid`=%d", esc_sql($postid)));
  563. if ($updated=='true' || $updated=='1') {
  564. $views++; no_cache();
  565. $db->update('#@_post',array('views' => $views),array( 'postid' => $postid));
  566. }
  567. } else {
  568. $views = 0;
  569. }
  570. return 'document.write('.$views.');';
  571. }
  572. /**
  573. * ????
  574. *
  575. * @return string
  576. */
  577. function post_gateway_comment() {
  578. $postid = isset($_GET['postid']) ? $_GET['postid'] : 0;
  579. return 'document.write('.comment_count($postid).');';
  580. }
  581. /**
  582. * ?????
  583. *
  584. * @return string
  585. */
  586. function post_gateway_comment_people() {
  587. $postid = isset($_GET['postid']) ? $_GET['postid'] : 0;
  588. return 'document.write('.comment_people($postid).');';
  589. }
  590. /**
  591. * ????
  592. *
  593. * @return void
  594. */
  595. function post_gateway_send_comment() {
  596. $postid = isset($_REQUEST['postid']) ? $_REQUEST['postid'] : 0;
  597. // ????????
  598. if (!($post = post_get($postid))) {
  599. return ajax_error(__('The post doesn\'t exist or has been deleted!'));
  600. }
  601. // ????????
  602. if ($post['comments'] != 'Yes') {
  603. return ajax_error(__('The post doesn\'t comment!'));
  604. }
  605. $parent = isset($_REQUEST['parent']) ? $_REQUEST['parent'] : 0;
  606. $content = isset($_REQUEST['content']) ? $_REQUEST['content'] : '';
  607. $content = esc_html(trim($content));
  608. // ??????
  609. if (!$content) return ajax_alert(__('Please enter a comment on the contents!'));
  610. if (mb_strlen($content,'UTF-8') > 500) return ajax_alert(sprintf(__('Maximum %d characters of Comment content!'), 500));
  611. global $_USER;
  612. if (!isset($_USER)) {
  613. $email = isset($_REQUEST['mail']) ? esc_html(trim($_REQUEST['mail'])) : '';
  614. if (!validate_is($email,VALIDATE_IS_EMAIL)) return ajax_alert(__('You must provide an e-mail address.'));
  615. $_USER = array(
  616. 'mail' => $email,
  617. 'name' => isset($_REQUEST['author']) ? esc_html(trim($_REQUEST['author'])) : '',
  618. 'url' => isset($_REQUEST['url']) ? esc_html(trim($_REQUEST['url'])) : '',
  619. );
  620. }
  621. // ????????
  622. $authcode = authcode();
  623. $cachekey = sprintf('comment.send.%s', $authcode);
  624. $session = fcache_get($cachekey);
  625. if (fcache_not_null($session)) {
  626. // ?????????
  627. if (time()-$session['time'] <= 3) {
  628. return ajax_error(__('You speak too fast, rest!'));
  629. }
  630. // ?????????
  631. if ($session['content'] == $content) {
  632. return ajax_error(__('You can not send duplicate comment!'));
  633. }
  634. // ?????????
  635. fcache_delete($cachekey);
  636. }
  637. // ????
  638. if (comment_add($postid,$content,$parent,$_USER)) {
  639. // ??????
  640. fcache_set($cachekey, array(
  641. 'time' => time(),
  642. 'content' => $content
  643. ), 86400);
  644. comment_create($postid);
  645. return ajax_success(__('Comment on the success!'));
  646. } else {
  647. return ajax_error(__('Comment failed!'));
  648. }
  649. }