PageRenderTime 226ms CodeModel.GetById 25ms RepoModel.GetById 13ms app.codeStats 0ms

/src/testSource/phpcms/content/application/controllers/zixun_message.php

https://gitlab.com/loda.sun.suryani/qijiatuku
PHP | 379 lines | 278 code | 27 blank | 74 comment | 59 complexity | 7055defe6fb002500fa1ce9bf32663d9 MD5 | raw file
  1. <?php
  2. if (! defined ( 'BASEPATH' ))
  3. exit ( 'No direct script access allowed' );
  4. class Zixun_message extends CI_Controller {
  5. function __construct() {
  6. parent::__construct ();
  7. $this->load->library ( 'form_validation' ); //表单验证类
  8. $this->load->library ( 'datagrid' ); //文本控件
  9. $this->load->helper ( 'url' );
  10. $this->load->helper ( 'html' );
  11. $this->load->library ( 'editors' );
  12. $this->load->library ( 'session' ); //session类
  13. $this->load->helper ( 'pagenav' ); //分页类
  14. $this->load->helper ( 'toolkit' );
  15. $this->load->helper ( 'security' );
  16. $this->load->library ( 'CommonCache', '', 'cache' );
  17. $this->count_page = 10; //分页每页显示条数
  18. }
  19. function index() {
  20. $view_data = array ();
  21. $page_id = $this->input->get ( 'page_id' ); //page_id
  22. //$user_id = $this->input->get ( 'user_id' ); //会员ID
  23. //$user_name = $this->input->get ( 'user_name' ); //user_name
  24. $ip = $_SERVER ["REMOTE_ADDR"];
  25. $theverify = $this->input->get ( 'theverify' );
  26. $pass = "cms_fuwu.jia.com"; //这里是说好的密码
  27. if (isset ( $_COOKIE ["www_jia_user_name"] )) {
  28. $username = $_COOKIE ["www_jia_user_name"];
  29. $user_name = $username;
  30. } else {
  31. $user_name = "游客";
  32. }
  33. if (isset ( $_COOKIE ["jia_html_id"] )) {
  34. $user_id = $_COOKIE ["jia_html_id"];
  35. $user_id = $this->uid ( $user_id );
  36. } else {
  37. $user_id = 0;
  38. }
  39. if (! $page_id) {
  40. $page_id = "0";
  41. }
  42. $view_data ["page_id"] = $page_id;
  43. $view_data ["user_name"] = $user_name;
  44. $view_data ["user_id"] = $user_id;
  45. //$check_key = cms_inner_verify ( $user_id, $ip, $pass );
  46. //my_debug($check_key);
  47. //if ($theverify != $check_key) {
  48. //echo "验证不通过!";
  49. //exit ();
  50. //}
  51. //
  52. /*验证
  53. $this->form_validation->set_rules ( 'comment_content', '文本框', 'required' );
  54. $this->form_validation->set_rules ( 'code', '验证码', 'required' );
  55. if ($this->form_validation->run () == TRUE) {
  56. $code = trim ( $this->input->post ( 'code' ) );
  57. $verify = trim ( $this->input->post ( 'verify' ) ); //获取验证码日期间
  58. if ($verify && $code) {
  59. $verify_code = $this->db->get_record_by_sql (
  60. "SELECT count(*) as tcount FROM com_verify_code WHERE verify='$verify' AND code='$code' " );
  61. $tcount = $verify_code ['tcount'];
  62. } else {
  63. $tcount = 0;
  64. }
  65. $comment_content = $this->input->post ( "comment_content" ); //复制给哪个用户的user_id
  66. if (! $user_name) {
  67. $user_name = "zixun";
  68. }
  69. $insert = array (
  70. 'page_id' => $page_id,
  71. 'user_name' => $user_name,
  72. 'user_id' => $user_id,
  73. 'comment_content' => $comment_content,
  74. 'is_arbitrated' => 0,
  75. "create_time" => time () );
  76. //exit;
  77. if ($tcount) {
  78. $db_ret = $this->db->insert ( "data_iframe_comment", $insert );
  79. if ($db_ret) {
  80. //msg ( "ok", );
  81. echo ('<script language="JavaScript">');
  82. echo ("alert('成功');");
  83. echo "function timeout(){";
  84. echo ("location.href='" . modify_build_url () . "';");
  85. echo "}";
  86. echo "setTimeout(timeout,2000);";
  87. echo ('</script>');
  88. exit ();
  89. } else {
  90. echo "<span class=error>失败</span>";
  91. }
  92. } else {
  93. echo "<span class=error>失败</span>";
  94. }
  95. }*/
  96. $view_data ['grid'] = '';
  97. $view_data ['getpageinfo'] = '';
  98. $data_base = "data_iframe_comment";
  99. $ORDER = "auto_id";
  100. //=========列表===={{=============================================================
  101. $sql_where = "WHERE page_id = '$page_id' AND is_arbitrated='1' ";
  102. //my_debug($sql_where);
  103. if ($this->input->get_post ( 'count_page' ) != '') {
  104. $count_page = $this->input->get_post ( 'count_page' );
  105. } else {
  106. $count_page = $this->count_page;
  107. }
  108. if ($this->input->get_post ( 'page' ) <= 0 || $this->input->get_post ( 'page' ) == '') {
  109. $page = 1;
  110. } else {
  111. $page = $this->input->get_post ( 'page' );
  112. }
  113. $sql_count = "SELECT count(*) as tot FROM $data_base $sql_where";
  114. $row = $this->db->get_record_by_sql ( $sql_count, 'num' );
  115. $t_count = $row [0];
  116. $p_count = ceil ( $t_count / $count_page );
  117. if ($page > $p_count && $p_count > 0) {
  118. $page = $p_count;
  119. }
  120. $t_first = ($page - 1) * $count_page;
  121. $sql = "SELECT * FROM $data_base $sql_where ORDER BY $ORDER DESC";
  122. $sql = "$sql LIMIT $t_first,$count_page";
  123. //my_debug($sql);
  124. $data = $this->db->get_rows_by_sql ( $sql );
  125. if (count ( $data )) {
  126. foreach ( $data as $k => $row ) {
  127. $data [$k] ['create_time'] = date ( "Y-m-d H:i:s", $row ['create_time'] );
  128. $data [$k] ['arbitrate_time'] = date ( "Y-m-d H:i:s", $row ['arbitrate_time'] );
  129. }
  130. }
  131. $view_data ['grid'] = $data;
  132. $getpageinfo = toolkit_pages_zixun ( $page, $t_count, modify_build_url ( array ('page' => '' ) ),
  133. $count_page, 8, '' );
  134. if ($getpageinfo) {
  135. $view_data ['getpageinfo'] = $getpageinfo ['pagecode'];
  136. }
  137. $contenttext = $this->load->view ( 'comment_admin/show_ajax_view', $view_data, TRUE );
  138. $view_data ["contenttext"] = $contenttext;
  139. $this->load->view ( 'comment_admin/zixun_index_view', $view_data );
  140. }
  141. function show_ajax() {
  142. $page_id = $this->input->get ( 'page_id' ); //page_id
  143. $user_id = $this->input->get ( 'user_id' ); //会员ID
  144. $view_data = array ();
  145. $view_data ['grid'] = '';
  146. $view_data ['getpageinfo'] = '';
  147. $data_base = "data_iframe_comment";
  148. $ORDER = "auto_id";
  149. //=========列表===={{=============================================================
  150. $sql_where = "WHERE page_id = '$page_id' AND is_arbitrated='1' ";
  151. //my_debug($sql_where);
  152. if ($this->input->get_post ( 'count_page' ) != '') {
  153. $count_page = $this->input->get_post ( 'count_page' );
  154. } else {
  155. $count_page = $this->count_page;
  156. }
  157. if ($this->input->get_post ( 'page' ) <= 0 || $this->input->get_post ( 'page' ) == '') {
  158. $page = 1;
  159. } else {
  160. $page = $this->input->get_post ( 'page' );
  161. }
  162. $sql_count = "SELECT count(*) as tot FROM $data_base $sql_where";
  163. $row = $this->db->get_record_by_sql ( $sql_count, 'num' );
  164. $t_count = $row [0];
  165. $p_count = ceil ( $t_count / $count_page );
  166. if ($page > $p_count && $p_count > 0) {
  167. $page = $p_count;
  168. }
  169. $t_first = ($page - 1) * $count_page;
  170. $sql = "SELECT * FROM $data_base $sql_where ORDER BY $ORDER DESC";
  171. $sql = "$sql LIMIT $t_first,$count_page";
  172. //my_debug($sql);
  173. $data = $this->db->get_rows_by_sql ( $sql );
  174. if (count ( $data )) {
  175. foreach ( $data as $k => $row ) {
  176. $data [$k] ['create_time'] = date ( "Y-m-d H:i:s", $row ['create_time'] );
  177. }
  178. }
  179. $view_data ['grid'] = $data;
  180. $getpageinfo = toolkit_pages_zixun ( $page, $t_count, modify_build_url ( array ('page' => '' ) ),
  181. $count_page, 8, '' );
  182. if ($getpageinfo) {
  183. $view_data ['getpageinfo'] = $getpageinfo ['pagecode'];
  184. }
  185. echo $this->load->view ( 'comment_admin/show_ajax_view', $view_data, TRUE );
  186. }
  187. function fuwu_del() {
  188. $comment_id = intval ( $this->input->get_post ( 'id' ) );
  189. $this->db->where ( 'comment_id', $comment_id );
  190. $success = $this->db->update ( 'com_comment', array ('is_arbitrated' => '2' ) );
  191. echo $success;
  192. }
  193. function addajax() {
  194. /*验证*/
  195. $page_id = $this->input->get ( 'page_id' ); //page_id
  196. //$user_id = $this->input->get ( 'user_id' ); //会员ID
  197. //$username = $this->input->get ( 'user_name' ); //user_name
  198. $this->form_validation->set_rules ( 'comment_content', '文本框', 'required' );
  199. $this->form_validation->set_rules ( 'code', '验证码', 'required' );
  200. /*验证入库*/
  201. if ($this->form_validation->run () == TRUE) {
  202. $code = trim ( $this->input->get_post ( 'code' ) );
  203. $verify = trim ( $this->input->get_post ( 'verify' ) ); //获取验证码日期间
  204. if ($verify && $code) {
  205. $verify_code = $this->db->get_record_by_sql (
  206. "SELECT count(*) as tcount FROM com_verify_code WHERE verify='$verify' AND code='$code' " );
  207. $tcount = $verify_code ['tcount'];
  208. } else {
  209. $tcount = 0;
  210. }
  211. $comment_content = $this->js_unescape ( $this->input->get_post ( "comment_content" ) ); //复制给哪个用户的user_id
  212. //获取cookie
  213. if (isset ( $_COOKIE ["www_jia_user_name"] )) {
  214. $username = $_COOKIE ["www_jia_user_name"];
  215. $user_name = $username;
  216. } else {
  217. $user_name = "游客";
  218. }
  219. if (isset ( $_COOKIE ["jia_html_id"] )) {
  220. $user_id = $_COOKIE ["jia_html_id"];
  221. $user_id = $this->uid ( $user_id );
  222. } else {
  223. $user_id = 0;
  224. }
  225. $insert = array (
  226. 'page_id' => $page_id,
  227. 'user_name' => $user_name,
  228. 'user_id' => $user_id,
  229. 'comment_content' => $comment_content,
  230. 'is_arbitrated' => 0,
  231. "create_time" => time () );
  232. //exit;
  233. if ($tcount) {
  234. $db_ret = $this->db->insert ( "data_iframe_comment", $insert );
  235. if ($db_ret) {
  236. $this->db->where ( 'verify', $verify );
  237. $this->db->where ( 'code', $code );
  238. $this->db->delete ( 'com_verify_code' );
  239. echo $db_ret;
  240. } else {
  241. echo 0;
  242. }
  243. } else {
  244. echo $tcount;
  245. }
  246. }
  247. }
  248. private function js_unescape($str) {
  249. $ret = '';
  250. $len = strlen ( $str );
  251. for($i = 0; $i < $len; $i ++) {
  252. if ($str [$i] == '%' && $str [$i + 1] == 'u') {
  253. $val = hexdec ( substr ( $str, $i + 2, 4 ) );
  254. if ($val < 0x7f)
  255. $ret .= chr ( $val );
  256. else if ($val < 0x800)
  257. $ret .= chr ( 0xc0 | ($val >> 6) ) . chr ( 0x80 | ($val & 0x3f) );
  258. else
  259. $ret .= chr ( 0xe0 | ($val >> 12) ) . chr ( 0x80 | (($val >> 6) & 0x3f) ) . chr (
  260. 0x80 | ($val & 0x3f) );
  261. $i += 5;
  262. } else if ($str [$i] == '%') {
  263. $ret .= urldecode ( substr ( $str, $i, 3 ) );
  264. $i += 2;
  265. } else
  266. $ret .= $str [$i];
  267. }
  268. return $ret;
  269. }
  270. private function pass($shop_id, $theverify) {
  271. //服务商家
  272. $ip = $_SERVER ["REMOTE_ADDR"];
  273. $pass = "cms_diaoding.jia.com"; //这里是说好的密码
  274. $check_key = cms_inner_verify ( $shop_id, $ip, $pass );
  275. my_debug ( $check_key );
  276. if ($theverify != $check_key) {
  277. echo "验证不通过!";
  278. exit ();
  279. }
  280. }
  281. function validationcode() {
  282. $str = $this->random ( 4 ); //随机生成的字符串
  283. $width = 50; //验证码图片的宽度
  284. $height = 22; //验证码图片的高度
  285. @header ( "Content-Type:image/png" );
  286. $im = imagecreate ( $width, $height );
  287. //背景色
  288. $back = imagecolorallocate ( $im, 0xff, 0xff, 0xff );
  289. //模糊点颜色
  290. $pix = imagecolorallocate ( $im, 255, 255, 255 ); //187,230,247//255,255,255
  291. //字体色
  292. $font = imagecolorallocate ( $im, 41, 163, 238 );
  293. //绘模糊作用的点
  294. mt_srand ();
  295. for($i = 0; $i < 1000; $i ++) {
  296. imagesetpixel ( $im, mt_rand ( 0, $width ), mt_rand ( 0, $height ), $pix );
  297. }
  298. imagestring ( $im, 5, 7, 5, $str, $font );
  299. imagerectangle ( $im, 0, 0, $width - 1, $height - 1, $font );
  300. imagepng ( $im );
  301. imagedestroy ( $im );
  302. //$this->session->set_userdata ( 'validationcode', $str );
  303. $time_now = time ();
  304. //删除1小时前的临时page
  305. $this->db->query (
  306. sprintf ( "DELETE FROM com_verify_code WHERE create_time<%s", $time_now - 3600 * 1 ) );
  307. $verify = trim ( $this->input->get ( 'nowtime' ) );
  308. $up = array ('verify' => $verify, 'code' => $str, 'create_time' => time () );
  309. $success = $this->db->insert ( "com_verify_code", $up );
  310. echo $str;
  311. }
  312. private function random($len) {
  313. $srcstr = "0123456789"; //ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
  314. mt_srand ();
  315. $strs = "";
  316. for($i = 0; $i < $len; $i ++) {
  317. $strs .= $srcstr [mt_rand ( 0, 9 )];
  318. }
  319. return strtoupper ( $strs );
  320. }
  321. private function uid($user_id) {
  322. $api_server = "http://10.10.21.126:10005/user/"; //外网测试
  323. $api = "getDecodeUID";
  324. $req_body = "{'app_id':'201','encode_uid':'$user_id'}";
  325. $array = json_decode ( $this->do_post_api ( $api_server, $api, $req_body ), true );
  326. if (count ( $array )) {
  327. $user_id = $array ["result"];
  328. } else {
  329. $user_id = 0;
  330. }
  331. return $user_id;
  332. }
  333. private function do_post_api($api_server, $api, $req_body, $port = 9091) {
  334. $ch = curl_init ();
  335. curl_setopt ( $ch, CURLOPT_URL, "$api_server$api" );
  336. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  337. @curl_setopt ( $ch, CURLOPT_TIMEOUT_MS, 2000 );
  338. curl_setopt ( $ch, CURLOPT_POST, 1 );
  339. curl_setopt ( $ch, CURLOPT_POSTFIELDS, $req_body );
  340. $data = curl_exec ( $ch );
  341. $curl_errno = curl_errno ( $ch );
  342. $curl_error = curl_error ( $ch );
  343. curl_close ( $ch );
  344. if ($curl_errno > 0) {
  345. exit (
  346. "function do_post_api error; <br>\ncURL Error ({$curl_errno}): {$curl_error}<br>\n{$api_server}{$api}<br>\n$req_body" );
  347. }
  348. return $data;
  349. }
  350. }