PageRenderTime 35ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/mode/ajax.class.php

http://xklog.googlecode.com/
PHP | 212 lines | 173 code | 9 blank | 30 comment | 45 complexity | 48b88252f264ad58c09e53ca72550f21 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. !defined('IN_NOVA') && exit('Access Denied!');
  3. class Ajax {
  4. public function start() {
  5. global $theme,$cache,$request;
  6. // ????
  7. $action = $request->get( 'p' );
  8. @header("content-type: text/html; charset=utf-8");
  9. switch( $action )
  10. {
  11. case 'checkname':
  12. $this->check_name();
  13. break;
  14. case 'addcomment':
  15. $this->add_comment();
  16. break;
  17. default:
  18. echo '????!|$|False';
  19. }
  20. }
  21. private function check_name()
  22. {
  23. global $db,$request,$user;
  24. $user_name = php_unescape( $request->get( 'username' ) );
  25. if( !$user->check_username( $user_name ) ) {
  26. echo '??????????|$|False';
  27. return -1;
  28. }
  29. if( $db->result( "SELECT COUNT(u_id) FROM `" . DB_PREFIX . "user` WHERE u_username='$user_name'" )) {
  30. echo '??????????|$|False';
  31. return -2;
  32. } else {
  33. echo '????????|$|True';
  34. return 1;
  35. }
  36. }
  37. function add_comment(){
  38. global $db,$cache,$user,$theme,$request;
  39. // ????
  40. if( $cache->config['comment'] == 2 ){
  41. echo '??????????????|$|False';
  42. return -1;
  43. }
  44. if( $cache->config['comment'] == 1 && !user_is_login() ){
  45. echo '??????????????????????|$|False';
  46. return -2;
  47. }
  48. //If( CDate( DateDiff( "s", Session("PostDate"), Now() ) ) < CDate( Blogcomtimer ) ){
  49. // echo "??????????????|$|False";
  50. // return -3;
  51. //}
  52. // ?????
  53. //$vdcode = $request->get( 'vcode', 'P' );
  54. //if( ( $cache->config['verify'] == 0 || ( $cache->config['verify'] == 1 && !$user->is_login() ) ) && !check_verify( $vdcode ) ){
  55. // echo '?????????!|$|False';
  56. // return -4;
  57. //}
  58. // ????
  59. if( $user->is_login() ){
  60. $user_name = $user->username;
  61. $temp = array();
  62. $temp = $db->fetch_one_array( "SELECT `u_email`,`u_index` FROM `" . DB_PREFIX . "user` WHERE u_username='$user_name'" );
  63. if( $temp['u_email'] != NULL ){
  64. $email = $temp['u_email'];
  65. }else{
  66. $email = '';
  67. }
  68. if( $temp['u_index'] != NULL ){
  69. $index = $temp['u_index'];
  70. }else{
  71. $index = '';
  72. }
  73. unset( $temp );
  74. }else{
  75. $user_name = trim( php_unescape( $request->get( 'username', 'P' ) ) );
  76. $email = htmlspecialchars( php_unescape( $request->get( 'email', 'P' ) ) );
  77. $index = htmlspecialchars( php_unescape( $request->get( 'index', 'P' ) ) );
  78. $check_name = $user->check_username( $user_name );
  79. if ( $check_name == 0 ) {
  80. echo "????????3-20?????|$|False";
  81. return -5;
  82. } elseif ( $check_name == -1 ) {
  83. echo "???????????|$|False";
  84. return -6;
  85. } elseif ( $check_name == -2 ) {
  86. echo "??????????????|$|False";
  87. return -7;
  88. } elseif ( $db->result( "SELECT COUNT(u_id) FROM `" . DB_PREFIX . "user` WHERE u_username = '" . $user_name . "'" ) ) {
  89. // ????????????????????????
  90. echo "?????????|$|False";
  91. return -8;
  92. }
  93. if ( empty( $email ) ) {
  94. //echo '??????????|$|False';
  95. //return -9;
  96. } elseif ( !$user->check_email( $email ) ) {
  97. echo "?????????????|$|False";
  98. return -10;
  99. } elseif ( $db->result( "SELECT COUNT(u_id) FROM `" . DB_PREFIX . "user` WHERE u_email='$email|" . strtolower( md5( $email ) ) . "'" ) ) {
  100. echo "?????????????|$|False";
  101. return -11;
  102. }
  103. // ????
  104. if ( empty( $index ) ) {
  105. //echo '????????';
  106. //return -12;
  107. } elseif ( !$user->check_index( $index ) ) {
  108. echo "??????????????????????|$|False";
  109. return -13;
  110. }
  111. $remember = $request->get( 'remember', 'P' );
  112. $blog_path = str_replace( ' ','%20', APP_PATH );
  113. if( $remember == 'on' ){
  114. setcookie( APP_PREFIX . 'username', $user_name, PHP_TIME + 31536000,$blog_path );
  115. setcookie( APP_PREFIX . 'email', $email, PHP_TIME + 31536000, $blog_path );
  116. setcookie( APP_PREFIX . 'index', $index, PHP_TIME + 31536000, $blog_path );
  117. setcookie( APP_PREFIX . 'remember', '1', PHP_TIME + 31536000, $blog_path );
  118. } else {
  119. setcookie( APP_PREFIX . 'username', NULL, 0,$blog_path );
  120. setcookie( APP_PREFIX . 'email', NULL, 0, $blog_path );
  121. setcookie( APP_PREFIX . 'index', NULL, 0, $blog_path );
  122. setcookie( APP_PREFIX . 'remember', NULL, 0, $blog_path );
  123. }
  124. if( $email != '' ) $email = $email . '|' . strtolower( md5( $email ) );
  125. }
  126. // ????
  127. $comment = htmlspecialchars( $request->get( 'comment', 'P' ), ENT_QUOTES, 'UTF-8' );
  128. $comment = str_replace( array("\r\n", "\n", "\r"),'<br />',$comment);
  129. $article_id = $request->get( 'aid', 'P', 'int' );
  130. $hide = $request->get( 'hide', 'P' );
  131. // ????
  132. if( trim( $comment ) == '' ){
  133. echo '?????????|$|False';
  134. return -14;
  135. }
  136. if( strlen( $comment ) > $cache->config['commaxlength'] ){
  137. echo '??????????' . $cache->config['commaxlength'] . '??????|$|False';
  138. return -15;
  139. }
  140. // ?? @ ??
  141. $pattern = "/{@[1-9]\d*}/";
  142. $matches = $id_arr = array();
  143. if( preg_match_all ( $pattern, $comment, $matches ) ) {
  144. foreach( $matches[0] as $match ) {
  145. $id_arr[] = str_replace( array( '{@', '}' ), '', $match );
  146. }
  147. unset( $matches );
  148. include nova_lib( 'phpmailer' );
  149. $mail = new PHPMailer();
  150. foreach( $id_arr as $comment_id ) {
  151. // ????? @ ??
  152. $respond = $db->fetch_one_array( "SELECT author,email FROM `" . DB_PREFIX . "comment` WHERE cid=$comment_id" );
  153. // ?? cid ????????
  154. if( !$respond ) continue;
  155. // ?? {@**}
  156. $comment = str_replace( '{@' . $comment_id . '}', '<a href="#comment-' . $comment_id . '">@ ' . $respond['author'] . '</a>', $comment );
  157. // ???? @ ????
  158. if( !$respond['email'] || 0 /* ??????? */ ) continue;
  159. }
  160. unset( $respond, $mail );
  161. }
  162. // ?????????????
  163. $temp = true;
  164. $db->query( "INSERT INTO `" . DB_PREFIX . "comment` (`articleid`,`author`,`time`,`comment`,`email`,`index`,`isshow`) VALUES ($article_id,'$user_name','" . PHP_TIME . "','$comment','$email','$index',1)" );
  165. $cid = $db->insert_id();
  166. $filter_arr = split( "\|", $cache->config['filterwords'] );
  167. if ( count( $filter_arr ) ) {
  168. foreach( $filter_arr as $filter_word ){
  169. if ( empty( $filter_word ) ) continue;
  170. if( !( stripos($comment,$filter_word) === false ) ){
  171. $db->query( "UPDATE `" . DB_PREFIX . "comment` SET isshow = 0 WHERE `cid` = $cid" );
  172. $temp = false;
  173. break;
  174. }
  175. }
  176. }
  177. // ????????
  178. if( $hide == 'on' ) $db->query( "UPDATE `" . DB_PREFIX . "comment` SET isshow = 2 WHERE cid=$cid" );
  179. // ?? ajax ??
  180. $theme->comment = $db->fetch_one_array( "SELECT * FROM `" . DB_PREFIX . "comment` WHERE cid=$cid" );
  181. if( $db->result( "SELECT type FROM `" . DB_PREFIX . "article` WHERE id=$article_id" ) == '??' ){
  182. $theme->comment['comment'] .= '<br /><font color="red">[???????????????]</font>';
  183. $db->query( "UPDATE `" . DB_PREFIX . "article` SET `update`=1 WHERE id=$article_id" );
  184. }else{
  185. if( $temp != false ){
  186. $theme->comment['comment'] .= '<br /><font color="blue">[??????????]</font>';
  187. }
  188. }
  189. if( $article_id != 0 ){
  190. $db->query( "UPDATE `" . DB_PREFIX . "article` SET comment = comment + 1 WHERE id = $article_id" );
  191. }
  192. $theme->show_comment_de();
  193. echo '|$|True';
  194. // ????
  195. if( $article_id == 0 ) {
  196. $cache->refresh( 'guestbook_new', TRUE );
  197. }else{
  198. $cache->refresh( 'comment_new', TRUE );
  199. }
  200. $cache->refresh( 'count', TRUE );
  201. }
  202. }
  203. ?>