PageRenderTime 47ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/loda.sun.suryani/qijiatuku
PHP | 415 lines | 350 code | 32 blank | 33 comment | 76 complexity | 2d04e87f3f077394d264671459d844aa MD5 | raw file
  1. <?php
  2. if (! defined ( 'BASEPATH' ))
  3. exit ( 'No direct script access allowed' );
  4. class Zixun_single_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 = 4; //分页每页显示条数
  18. //$this->db_single = $this->load->database ( 'single', TRUE );
  19. $this->db_single = $this->db;
  20. }
  21. function index() {
  22. $view_data = array ();
  23. $page_id = $this->input->get ( 'page_id' ); //page_id
  24. //$user_id = $this->input->get ( 'user_id' ); //会员ID
  25. //$user_name = $this->input->get ( 'user_name' ); //user_name
  26. $ip = $_SERVER ["REMOTE_ADDR"];
  27. $theverify = $this->input->get ( 'theverify' );
  28. $pass = "cms_fuwu.jia.com"; //这里是说好的密码
  29. if (isset ( $_COOKIE ["www_jia_user_name"] )) {
  30. $username = $_COOKIE ["www_jia_user_name"];
  31. $user_name = $username;
  32. } else {
  33. $user_name = "游客";
  34. }
  35. if (isset ( $_COOKIE ["jia_html_id"] )) {
  36. $user_id = $_COOKIE ["jia_html_id"];
  37. $user_id = $this->uid ( $user_id );
  38. } else {
  39. $user_id = 0;
  40. }
  41. if (! $page_id) {
  42. $page_id = "0";
  43. }
  44. $view_data ["page_id"] = $page_id;
  45. $view_data ["user_name"] = $user_name;
  46. $view_data ["user_id"] = $user_id;
  47. $view_data ['grid'] = '';
  48. $view_data ['getpageinfo'] = '';
  49. $data_base = "data_oupu_comment";
  50. $ORDER = "auto_id";
  51. //=========列表===={{=============================================================
  52. $sql_where = "WHERE page_id = '$page_id' AND is_arbitrated='1' ";
  53. //my_debug($sql_where);
  54. if ($this->input->get_post ( 'count_page' ) != '') {
  55. $count_page = $this->input->get_post ( 'count_page' );
  56. } else {
  57. $count_page = $this->count_page;
  58. }
  59. if ($this->input->get_post ( 'page' ) <= 0 || $this->input->get_post ( 'page' ) == '') {
  60. $page = 1;
  61. } else {
  62. $page = $this->input->get_post ( 'page' );
  63. }
  64. $sql_count = "SELECT count(*) as tot FROM $data_base $sql_where";
  65. $row = $this->db_single->get_record_by_sql ( $sql_count, 'num' );
  66. $t_count = $row [0];
  67. $p_count = ceil ( $t_count / $count_page );
  68. if ($page > $p_count && $p_count > 0) {
  69. $page = $p_count;
  70. }
  71. $t_first = ($page - 1) * $count_page;
  72. $sql = "SELECT * FROM $data_base $sql_where ORDER BY $ORDER DESC";
  73. $sql = "$sql LIMIT $t_first,$count_page";
  74. //my_debug($sql);
  75. $data = $this->db_single->get_rows_by_sql ( $sql );
  76. if (count ( $data )) {
  77. foreach ( $data as $k => $row ) {
  78. $data [$k] ['create_time'] = date ( "Y-m-d H:i:s", $row ['create_time'] );
  79. $data [$k] ['arbitrate_time'] = date ( "Y-m-d H:i:s", $row ['arbitrate_time'] );
  80. }
  81. }
  82. $view_data ['grid'] = $data;
  83. $uuuuuuuu=modify_build_url ( array ('page' => ''));
  84. $getpageinfo = $this->toolkit_pages_zixun ( $page, $t_count, $uuuuuuuu,
  85. $count_page, 8 );
  86. if ($getpageinfo) {
  87. $view_data ['getpageinfo'] = $getpageinfo ['pagecode'];
  88. }
  89. $contenttext = $this->load->view ( 'independent/show_ajax_view', $view_data, TRUE );
  90. $view_data ["contenttext"] = $contenttext;
  91. $this->load->view ( 'independent/zixun_index_view', $view_data );
  92. }
  93. function show_ajax() {
  94. $page_id = $this->input->get ( 'page_id' ); //page_id
  95. $user_id = $this->input->get ( 'user_id' ); //会员ID
  96. $view_data = array ();
  97. $view_data ['grid'] = '';
  98. $view_data ['getpageinfo'] = '';
  99. $data_base = "data_oupu_comment";
  100. $ORDER = "auto_id";
  101. //=========列表===={{=============================================================
  102. $sql_where = "WHERE page_id = '$page_id' AND is_arbitrated='1' ";
  103. //my_debug($sql_where);
  104. if ($this->input->get_post ( 'count_page' ) != '') {
  105. $count_page = $this->input->get_post ( 'count_page' );
  106. } else {
  107. $count_page = $this->count_page;
  108. }
  109. if ($this->input->get_post ( 'page' ) <= 0 || $this->input->get_post ( 'page' ) == '') {
  110. $page = 1;
  111. } else {
  112. $page = $this->input->get_post ( 'page' );
  113. }
  114. $sql_count = "SELECT count(*) as tot FROM $data_base $sql_where";
  115. $row = $this->db_single->get_record_by_sql ( $sql_count, 'num' );
  116. $t_count = $row [0];
  117. $p_count = ceil ( $t_count / $count_page );
  118. if ($page > $p_count && $p_count > 0) {
  119. $page = $p_count;
  120. }
  121. $t_first = ($page - 1) * $count_page;
  122. $sql = "SELECT * FROM $data_base $sql_where ORDER BY $ORDER DESC";
  123. $sql = "$sql LIMIT $t_first,$count_page";
  124. //my_debug($sql);
  125. $data = $this->db_single->get_rows_by_sql ( $sql );
  126. if (count ( $data )) {
  127. foreach ( $data as $k => $row ) {
  128. $data [$k] ['create_time'] = date ( "Y-m-d H:i:s", $row ['create_time'] );
  129. }
  130. }
  131. $view_data ['grid'] = $data;
  132. $uuuuuuuu=modify_build_url ( array ('page' => ''));
  133. $getpageinfo = $this->toolkit_pages_zixun ( $page, $t_count,$uuuuuuuu,
  134. $count_page, 8);
  135. if ($getpageinfo) {
  136. $view_data ['getpageinfo'] = $getpageinfo ['pagecode'];
  137. }
  138. echo $this->load->view ( 'independent/show_ajax_view', $view_data, TRUE );
  139. }
  140. function fuwu_del() {
  141. $comment_id = intval ( $this->input->get_post ( 'id' ) );
  142. $this->db_single->where ( 'comment_id', $comment_id );
  143. $success = $this->db_single->update ( 'com_comment', array ('is_arbitrated' => '2' ) );
  144. echo $success;
  145. }
  146. function addajax() {
  147. /*验证*/
  148. $page_id = $this->input->get ( 'page_id' ); //page_id
  149. //$user_id = $this->input->get ( 'user_id' ); //会员ID
  150. //$username = $this->input->get ( 'user_name' ); //user_name
  151. $this->form_validation->set_rules ( 'comment_content', '文本框', 'required' );
  152. $this->form_validation->set_rules ( 'code', '验证码', 'required' );
  153. /*验证入库*/
  154. if ($this->form_validation->run () == TRUE) {
  155. $code = trim ( $this->input->get_post ( 'code' ) );
  156. $verify = trim ( $this->input->get_post ( 'verify' ) ); //获取验证码日期间
  157. if ($verify && $code) {
  158. $verify_code = $this->db_single->get_record_by_sql (
  159. "SELECT count(*) as tcount FROM com_verify_code WHERE verify='$verify' AND code='$code' " );
  160. $tcount = $verify_code ['tcount'];
  161. } else {
  162. $tcount = 0;
  163. }
  164. $comment_content = $this->js_unescape ( $this->input->get_post ( "comment_content" ) ); //复制给哪个用户的user_id
  165. //获取cookie
  166. if (isset ( $_COOKIE ["www_jia_user_name"] )) {
  167. $username = $_COOKIE ["www_jia_user_name"];
  168. $user_name = $username;
  169. } else {
  170. $user_name = "游客";
  171. }
  172. if (isset ( $_COOKIE ["jia_html_id"] )) {
  173. $user_id = $_COOKIE ["jia_html_id"];
  174. $user_id = $this->uid ( $user_id );
  175. } else {
  176. $user_id = 0;
  177. }
  178. $insert = array (
  179. 'page_id' => $page_id,
  180. 'user_name' => $user_name,
  181. 'user_id' => $user_id,
  182. 'comment_content' => $comment_content,
  183. 'is_arbitrated' => 0,
  184. "create_time" => time () );
  185. //exit;
  186. if ($tcount) {
  187. $db_ret = $this->db_single->insert ( "data_oupu_comment", $insert );
  188. if ($db_ret) {
  189. $this->db_single->where ( 'verify', $verify );
  190. $this->db_single->where ( 'code', $code );
  191. $this->db_single->delete ( 'com_verify_code' );
  192. echo $db_ret;
  193. } else {
  194. echo 0;
  195. }
  196. } else {
  197. echo $tcount;
  198. }
  199. }
  200. }
  201. private function js_unescape($str) {
  202. $ret = '';
  203. $len = strlen ( $str );
  204. for($i = 0; $i < $len; $i ++) {
  205. if ($str [$i] == '%' && $str [$i + 1] == 'u') {
  206. $val = hexdec ( substr ( $str, $i + 2, 4 ) );
  207. if ($val < 0x7f)
  208. $ret .= chr ( $val );
  209. else if ($val < 0x800)
  210. $ret .= chr ( 0xc0 | ($val >> 6) ) . chr ( 0x80 | ($val & 0x3f) );
  211. else
  212. $ret .= chr ( 0xe0 | ($val >> 12) ) . chr ( 0x80 | (($val >> 6) & 0x3f) ) . chr (
  213. 0x80 | ($val & 0x3f) );
  214. $i += 5;
  215. } else if ($str [$i] == '%') {
  216. $ret .= urldecode ( substr ( $str, $i, 3 ) );
  217. $i += 2;
  218. } else
  219. $ret .= $str [$i];
  220. }
  221. return $ret;
  222. }
  223. private function pass($shop_id, $theverify) {
  224. //服务商家
  225. $ip = $_SERVER ["REMOTE_ADDR"];
  226. $pass = "cms_diaoding.jia.com"; //这里是说好的密码
  227. $check_key = cms_inner_verify ( $shop_id, $ip, $pass );
  228. my_debug ( $check_key );
  229. if ($theverify != $check_key) {
  230. echo "验证不通过!";
  231. exit ();
  232. }
  233. }
  234. function validationcode() {
  235. $str = $this->random ( 4 ); //随机生成的字符串
  236. $width = 50; //验证码图片的宽度
  237. $height = 22; //验证码图片的高度
  238. @header ( "Content-Type:image/png" );
  239. $im = imagecreate ( $width, $height );
  240. //背景色
  241. $back = imagecolorallocate ( $im, 0xff, 0xff, 0xff );
  242. //模糊点颜色
  243. $pix = imagecolorallocate ( $im, 255, 255, 255 ); //187,230,247//255,255,255
  244. //字体色
  245. $font = imagecolorallocate ( $im, 41, 163, 238 );
  246. //绘模糊作用的点
  247. mt_srand ();
  248. for($i = 0; $i < 1000; $i ++) {
  249. imagesetpixel ( $im, mt_rand ( 0, $width ), mt_rand ( 0, $height ), $pix );
  250. }
  251. imagestring ( $im, 5, 7, 5, $str, $font );
  252. imagerectangle ( $im, 0, 0, $width - 1, $height - 1, $font );
  253. imagepng ( $im );
  254. imagedestroy ( $im );
  255. //$this->session->set_userdata ( 'validationcode', $str );
  256. $time_now = time ();
  257. //删除1小时前的临时page
  258. $this->db_single->query (
  259. sprintf ( "DELETE FROM com_verify_code WHERE create_time<%s", $time_now - 3600 * 1 ) );
  260. $verify = trim ( $this->input->get ( 'nowtime' ) );
  261. $up = array ('verify' => $verify, 'code' => $str, 'create_time' => time () );
  262. $success = $this->db_single->insert ( "com_verify_code", $up );
  263. echo $str;
  264. }
  265. private function random($len) {
  266. $srcstr = "0123456789"; //ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
  267. mt_srand ();
  268. $strs = "";
  269. for($i = 0; $i < $len; $i ++) {
  270. $strs .= $srcstr [mt_rand ( 0, 9 )];
  271. }
  272. return strtoupper ( $strs );
  273. }
  274. private function toolkit_pages_zixun($page, $total, $phpfile, $pagesize = 3, $pagelen = 3, $link = "&") {
  275. $phpfile=str_replace("&&position=page=","&page=",$phpfile);
  276. $phpfile = str_replace ( "page=", "", $phpfile );
  277. $num_t_count = $total;
  278. $pagecode = ''; //定义变量,存放分页生成的HTML
  279. $page = intval ( $page ); //避免非数字页码
  280. $total = intval ( $total ); //保证总记录数值类型正确
  281. if (! $total)
  282. return array (); //总记录数为零返回空数组
  283. $pages = ceil ( $total / $pagesize ); //计算总分页
  284. //处理页码合法性
  285. if ($page < 1)
  286. $page = 1;
  287. if ($page > $pages)
  288. $page = $pages;
  289. //计算查询偏移量
  290. $offset = $pagesize * ($page - 1);
  291. //页码范围计算
  292. $init = 1; //起始页码数
  293. $max = $pages; //结束页码数
  294. $pagelen = ($pagelen % 2) ? $pagelen : $pagelen + 1; //页码个数
  295. $pageoffset = ($pagelen - 1) / 2; //页码个数左右偏移量
  296. //生成html
  297. if ($page != 1) {
  298. $pagecode .= "<a href=\"{$phpfile}page=1" . $link . "\">首页</a>"; //第一页
  299. $pagecode .= "<a href=\"{$phpfile}page=" . ($page - 1) . "" . $link . "\">上一页</a>"; //上一页
  300. }
  301. //分页数大于页码个数时可以偏移
  302. if ($pages > $pagelen) {
  303. //如果当前页小于等于左偏移
  304. if ($page <= $pageoffset) {
  305. $init = 1;
  306. $max = $pagelen;
  307. } else { //如果当前页大于左偏移
  308. //如果当前页码右偏移超出最大分页数
  309. if ($page + $pageoffset >= $pages + 1) {
  310. $init = $pages - $pagelen + 1;
  311. } else {
  312. //左右偏移都存在时的计算
  313. $init = $page - $pageoffset;
  314. $max = $page + $pageoffset;
  315. }
  316. }
  317. }
  318. //生成html
  319. for($i = $init; $i <= $max; $i ++) {
  320. if ($i == $page) {
  321. $pagecode .= "<a href='#' class='cur_page'>{$i}</a>";
  322. } else {
  323. $pagecode .= "<a href=\"{$phpfile}page={$i}" . $link . "\">$i</a>";
  324. }
  325. }
  326. if ($pages > $page + $pagelen) {
  327. $pagecode .= "<a href=\"{$phpfile}page={$i}" . $link . "\">...</a>";
  328. // $pagecode .= "<span class=\"page_skip\"> <a href=\"{$phpfile}page={$i}" . $link . "\">...</a></span>";
  329. }
  330. if ($page != $pages) {
  331. $next = $page + 1;
  332. $pagecode .= "<a href=\"{$phpfile}page=" . ($page + 1) . $link . "\">下一页</a>"; //下一页
  333. $pagecode .= "<a href=\"{$phpfile}page={$pages}" . $link . "\">>></a>"; //最后一页
  334. }
  335. $pagecode .= "<input type=hidden size=4 name=page id=page><span class='g6 mg0'>到第<input type=text size=4 name=value_num id=value_num value={$page}></span>
  336. <span class='g6 mg0'></span>";
  337. $pagecode .= " <span class='btn_gray'><i></i><em><a href='#' id=\"btn_jump\" onclick = \"page_jump()\">确定</a></em><i class='r_i'></i></span>";
  338. $pagecode .= "<script type=\"text/javascript\">
  339. function page_jump(){
  340. var num = $(\"#value_num\").val();
  341. //alert(num);
  342. $(\"#page\").attr('value',num);
  343. $(\"#theform\").submit();//提交
  344. return false ;
  345. }
  346. function change_page(num){
  347. $(\"#page\").attr('value',num);
  348. $(\"#theform\").submit();//提交
  349. return false;
  350. }
  351. </script>";
  352. return array ('pagecode' => $pagecode, 'sqllimit' => ' limit ' . $offset . ',' . $pagesize );
  353. }
  354. private function uid($user_id) {
  355. $api_server = "http://10.10.21.126:10005/user/"; //外网测试
  356. $api = "getDecodeUID";
  357. $req_body = "{'app_id':'201','encode_uid':'$user_id'}";
  358. $array = json_decode ( $this->do_post_api ( $api_server, $api, $req_body ), true );
  359. if (count ( $array )) {
  360. $user_id = $array ["result"];
  361. } else {
  362. $user_id = 0;
  363. }
  364. return $user_id;
  365. }
  366. private function do_post_api($api_server, $api, $req_body, $port = 9091) {
  367. $ch = curl_init ();
  368. curl_setopt ( $ch, CURLOPT_URL, "$api_server$api" );
  369. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  370. @curl_setopt ( $ch, CURLOPT_TIMEOUT_MS, 2000 );
  371. curl_setopt ( $ch, CURLOPT_POST, 1 );
  372. curl_setopt ( $ch, CURLOPT_POSTFIELDS, $req_body );
  373. $data = curl_exec ( $ch );
  374. $curl_errno = curl_errno ( $ch );
  375. $curl_error = curl_error ( $ch );
  376. curl_close ( $ch );
  377. if ($curl_errno > 0) {
  378. exit (
  379. "function do_post_api error; <br>\ncURL Error ({$curl_errno}): {$curl_error}<br>\n{$api_server}{$api}<br>\n$req_body" );
  380. }
  381. return $data;
  382. }
  383. }