示例#1
0
 public function insert_main_content($data)
 {
     $data_source = $data;
     $column_idsarr = explode(',', $data['column_id']);
     //根据栏目 获取站点id
     include_once CUR_CONF_PATH . 'lib/column.class.php';
     $column_obj = new column();
     $column_detail_datas = $column_obj->get_column_by_id(' id,site_id,name,support_client,column_url,folderformat,fileformat,syn_id,parents ', $data['column_id'], 'id');
     $this->obj->update('column', ' id in (' . $data['column_id'] . ')', array('content_update_time' => TIMENOW));
     //对keywords每个字进行转码
     $keywordstr = '';
     if (!empty($data['keywords'])) {
         $keywordstr = str_utf8_unicode($data['keywords']);
     }
     //对title每个字进行转码
     $titlestr = '';
     if (!empty($data['title'])) {
         $titlestr = $this->get_titleResult($data['title']);
         $title_pinyin_str = get_spell_title($data['title']);
     }
     foreach ($column_idsarr as $kc => $vc) {
         $firstcolumn = array();
         $firstcolumn = $column_detail_datas[$vc];
         if (empty($firstcolumn)) {
             continue;
         }
         $site_id = $firstcolumn['site_id'];
         if (!$firstcolumn['support_client']) {
             continue;
         }
         $client_typearr = explode(',', $firstcolumn['support_client']);
         $data['site_id'] = $firstcolumn['site_id'];
         $data['column_id'] = $vc;
         //查看内容是否存在,如果在相同模块下内容已存在,则报错,如果内容相同,但栏目不同,则只插入内容关联表中
         $check_result = $this->obj->check_content($data);
         if (!$check_result) {
             $content_status[$vc] = 0;
             //表示这条内容在几个栏目中已发布的
             continue;
         }
         //检测文稿内容正文里有无视频跟图集
         if ($data['content']) {
             $material_result = $this->obj->check_material_by_content($data['content']);
         }
         if ($check_result != 'new') {
             $content_status[$vc] = 0;
             //表示这条内容在几个栏目中后面几个个发布的
             //$check_result就是content_id(content表中内容id)
             //插入数据到关联表中
             $content_relation_data = array('site_id' => $data['site_id'], 'bundle_id' => $data['bundle_id'], 'module_id' => $data['module_id'], 'struct_id' => $data['struct_id'], 'column_id' => $data['column_id'], 'column_name' => $firstcolumn['name'], 'content_fromid' => $data['content_fromid'], 'content_id' => $check_result, 'weight' => $data['weight'], 'is_have_indexpic' => empty($data['indexpic']) ? 0 : 1, 'is_have_video' => empty($data['video']) ? 0 : 1, 'keywords_unicode' => addslashes($keywordstr), 'title_unicode' => addslashes($titlestr), 'title_pinyin' => $title_pinyin_str, 'share_num' => $data['share_num'], 'comment_num' => $data['comment_num'], 'click_num' => $data['click_num'], 'publish_time' => empty($data['publish_time']) ? TIMENOW : $data['publish_time'], 'create_time' => empty($data['create_time']) ? TIMENOW : $data['create_time'], 'verify_time' => empty($data['verify_time']) ? TIMENOW : $data['verify_time'], 'publish_user' => $data['publish_user'], 'create_user' => $data['user_name'], 'verify_user' => $data['verify_user'], 'file_domain' => $data['file_domain'], 'file_dir' => $data['file_dir'], 'file_custom_filename' => $data['file_custom_filename'], 'status' => $this->settings['is_need_audit'] ? 0 : 1, 'is_complete' => 0, 'praise_count' => $data['praise_count'], 'is_have_content_video' => intval($material_result['video']), 'is_have_content_tuji' => intval($material_result['tuji']));
             $crd_id = $this->obj->insert('content_relation', $content_relation_data);
             $this->obj->update_column_content_num($data['column_id']);
             //插入到对应的客户端Liv_content_client表中
             foreach ($client_typearr as $kct => $vct) {
                 //对客户端的处理
                 $content_client_data['client_type'] = $vct;
                 $content_client_data['relation_id'] = $crd_id;
                 $client_check_result = $this->obj->get_content_client('id', $content_client_data);
                 if ($client_check_result) {
                     continue;
                 } else {
                     $this->obj->insert('content_client_relation', $content_client_data);
                 }
             }
             //查询各自内容表的id
             $c_detail = $this->obj->get_content_by_id(' * ', $check_result);
             $expand_id = $c_detail['expand_id'];
             if ($data['use_maincolumn']) {
                 $relate_info = $this->obj->get_relate_by_cc($check_result, $c_detail['column_id']);
                 $file_name = $relate_info['file_name'];
             } else {
                 //计算出内容整个目录
                 if ($data['make_content_dir']) {
                     $file_name = make_content_dir($data['publish_id'] ? $data['publish_id'] : $crd_id, $content_relation_data['create_time'], $firstcolumn['folderformat'], $firstcolumn['fileformat'], $data['file_custom_filename']);
                 } else {
                     $file_name = make_content_dir($data['publish_id'] ? $data['publish_id'] : $crd_id, $content_relation_data['create_time'], $firstcolumn['folderformat'], $firstcolumn['fileformat'], $data['custom_filename']) . $this->settings['make_content_file_suffix'];
                 }
             }
             $this->obj->update_content_relation_by_id($crd_id, array('order_id' => $crd_id, 'file_name' => $file_name));
             if (!$this->settings['is_need_audit']) {
                 //整理内容栏目的信息,插入到xunsearch中;先查出现有的content_columns
                 $content_columns = $this->obj->get_content_columns(' * ', array('content_id' => $check_result));
                 $column_datas = @unserialize($content_columns['column_datas']);
                 $column_datas[$firstcolumn['id']] = array('id' => $firstcolumn['id'], 'column_url' => $firstcolumn['column_url'], 'name' => $firstcolumn['name'], 'relation_id' => $crd_id, 'parents' => $firstcolumn['parents']);
                 $new_content_columns = array('column_ids' => $content_columns['column_ids'] . ',' . $vc, 'column_datas' => serialize($column_datas));
                 $this->obj->update_content_columns($check_result, $new_content_columns);
                 if (!empty($data['video'])) {
                     //更新百度视频收录
                     $this->obj->update_video_record($data + array('rid' => $crd_id, 'file_name' => $file_name));
                 }
                 //判断有无推送,有则插入到content_push表中
                 //$this->obj->content_push($data,$check_result,$crd_id,true);
                 //插入到xunsearch中
                 $this->opration_xunsearch($c_detail + $content_relation_data, $new_content_columns, 'update', $column_detail_datas);
                 //判断是否之前有is_complete=1的relation记录,如有,则直接生成,如没有则至is_complete=0并不生成
                 $cr_datas = $this->obj->get_content_relation($check_result, ' AND is_complete=1 AND column_id!=' . $data['column_id']);
                 if ($cr_datas && is_array($cr_datas)) {
                     //表示之前有完成的记录
                     $this->obj->update_content_relation_by_id($crd_id, array('is_complete' => 1));
                     //插入到content_publish_time表中
                     if (!$data['use_maincolumn']) {
                         $this->obj->insert('content_publish_time', array('content_id' => $crd_id, 'publish_time' => empty($data['publish_time']) ? TIMENOW : $data['publish_time']));
                     }
                 }
             }
         } else {
             $content_status[$vc] = 1;
             //表示这条内容在几个栏目中第一个发布的
             //查询出所需插入的字段
             $tablename = get_tablename($data['bundle_id'], $data['module_id'], $data['struct_id'], $data['struct_ast_id']);
             $sql = "SELECT * FROM " . DB_PREFIX . "content_field WHERE bundle_id='" . $data['bundle_id'] . "' AND module_id='" . $data['module_id'] . "' AND struct_id='" . $data['struct_id'] . "' ";
             if (!empty($data['struct_ast_id'])) {
                 $sql .= " AND struct_ast_id='" . $data['struct_ast_id'] . "'";
             } else {
                 $sql .= " AND struct_ast_id=''";
             }
             $fields = $this->db->query_first($sql);
             if (empty($fields['field'])) {
                 $result['msg'] = '数据表中没有相关字段';
                 $result['error'] = '2';
                 $this->addItem($result);
                 $this->output();
             }
             $fieldsarr = explode(',', $fields['field']);
             $sqlstr = '';
             //插入数据到模块对应表中
             //					unset($data['id']);
             foreach ($data as $k => $v) {
                 if (in_array($k, $fieldsarr)) {
                     //如果值是数组,串行化存储
                     $v = is_array($v) ? serialize($v) : $v;
                     $sqlstr .= $k . "='" . $v . "',";
                 }
             }
             $sqlstr = trim($sqlstr, ',');
             if (empty($sqlstr)) {
                 $result['msg'] = '数据插入到模块表失败,缺少相关参数';
                 $result['error'] = '2';
                 $this->addItem($result);
                 $this->output();
             }
             $expand_id = $this->obj->insert($tablename, $sqlstr);
             if (!$expand_id) {
                 $result['msg'] = '数据插入到模块表失败';
                 $result['error'] = '2';
                 $this->addItem($result);
                 $this->output();
             }
             $content_data = array('site_id' => $data['site_id'], 'column_id' => $data['column_id'], 'bundle_id' => $data['bundle_id'], 'module_id' => $data['module_id'], 'struct_id' => $data['struct_id'], 'expand_id' => $expand_id, 'plan_set_id' => $data['plan_set_id'], 'content_fromid' => $data['content_fromid'], 'title' => $data['title'], 'subtitle' => $data['subtitle'], 'brief' => $data['brief'], 'keywords' => $data['keywords'], 'indexpic' => is_array($data['indexpic']) ? serialize($data['indexpic']) : $data['indexpic'], 'video' => is_array($data['video']) ? serialize($data['video']) : $data['video'], 'outlink' => $data['outlink'], 'child_num' => $data['child_num'], 'source' => $data['source'], 'appid' => $data['appid'], 'appname' => $data['appname'], 'ip' => $data['ip'], 'publish_user' => $data['publish_user'], 'create_user' => $data['user_name'], 'verify_user' => $data['verify_user'], 'template_sign' => $data['template_sign'], 'catalog' => $data['catalog'], 'tcolor' => $data['tcolor'], 'isbold' => $data['isbold'], 'isitalic' => $data['isitalic'], 'use_maincolumn' => $data['use_maincolumn'] ? 1 : 0, 'author' => $data['author'], 'iscomment' => $data['iscomment'] ? 1 : 0, 'is_praise' => $data['is_praise'] ? 1 : 0);
             $content_id = $this->obj->insert('content', $content_data);
             if (!$content_id) {
                 $result['msg'] = '数据插入到模块表失败';
                 $result['error'] = '2';
                 $this->addItem($result);
                 $this->output();
             }
             //插入数据到关联表中
             $content_relation_data = array('site_id' => $data['site_id'], 'bundle_id' => $data['bundle_id'], 'module_id' => $data['module_id'], 'struct_id' => $data['struct_id'], 'column_id' => $data['column_id'], 'column_name' => $firstcolumn['name'], 'content_fromid' => $data['content_fromid'], 'content_id' => $content_id, 'weight' => $data['weight'], 'is_have_indexpic' => empty($data['indexpic']) ? 0 : 1, 'is_have_video' => empty($data['video']) ? 0 : 1, 'keywords_unicode' => addslashes($keywordstr), 'title_unicode' => addslashes($titlestr), 'title_pinyin' => $title_pinyin_str, 'share_num' => $data['share_num'], 'comment_num' => $data['comment_num'], 'click_num' => $data['click_num'], 'publish_time' => empty($data['publish_time']) ? TIMENOW : $data['publish_time'], 'create_time' => empty($data['create_time']) ? TIMENOW : $data['create_time'], 'verify_time' => empty($data['verify_time']) ? TIMENOW : $data['verify_time'], 'publish_user' => $data['publish_user'], 'create_user' => $data['user_name'], 'verify_user' => $data['verify_user'], 'file_domain' => $data['file_domain'], 'file_dir' => $data['file_dir'], 'file_custom_filename' => $data['file_custom_filename'], 'status' => $this->settings['is_need_audit'] ? 0 : 1, 'is_complete' => $data['is_complete'] ? 1 : 0, 'praise_count' => $data['praise_count'], 'is_have_content_video' => intval($material_result['video']), 'is_have_content_tuji' => intval($material_result['tuji']));
             /**
              if($data['publish_id'])
              {
              $content_relation_data['id'] = $data['publish_id'];
              }
             */
             $crd_id = $this->obj->insert('content_relation', $content_relation_data);
             if (!$crd_id) {
                 $result['msg'] = '数据插入到关联表失败';
                 $result['error'] = '2';
                 $this->addItem($result);
                 $this->output();
             }
             $this->obj->update_column_content_num($data['column_id']);
             //生成内容url
             $this->obj->update_content_relation_by_id($crd_id, array('order_id' => $crd_id, 'file_name' => $data['file_custom_filename'] ? make_content_dir($data['publish_id'] ? $data['publish_id'] : $crd_id, $content_relation_data['create_time'], $firstcolumn['folderformat'], $firstcolumn['fileformat'], $data['file_custom_filename']) : make_content_dir($data['publish_id'] ? $data['publish_id'] : $crd_id, $content_relation_data['create_time'], $firstcolumn['folderformat'], $firstcolumn['fileformat'], $data['custom_filename']) . $this->settings['make_content_file_suffix']));
             //插入到对应的客户端Liv_content_client表中
             $content_client_data['relation_id'] = $crd_id;
             foreach ($client_typearr as $kct => $vct) {
                 //对客户端的处理
                 $content_client_data['client_type'] = $vct;
                 $check_result = $this->obj->get_content_client('id', $content_client_data);
                 if ($check_result) {
                     continue;
                 } else {
                     $this->obj->insert('content_client_relation', $content_client_data);
                 }
             }
             if (!$this->settings['is_need_audit']) {
                 //插入到Liv_content_columns,栏目的相关信息
                 $column_datas = array($data['column_id'] => array('id' => $data['column_id'], 'column_url' => $firstcolumn['column_url'], 'name' => $firstcolumn['name'], 'relation_id' => $crd_id, 'parents' => $firstcolumn['parents']));
                 $content_columns = array('content_id' => $content_id, 'column_ids' => $data['column_id'], 'column_datas' => serialize($column_datas));
                 $content_columns_id = $this->obj->insert('content_columns', $content_columns);
                 if (!empty($data['video'])) {
                     //更新百度视频收录
                     $this->obj->update_video_record($data + array('rid' => $crd_id));
                 }
                 //判断有无推送,有则插入到content_push表中
                 $this->obj->content_push($data, $content_id, $crd_id, false);
                 if ($data['is_complete']) {
                     //插入到content_publish_time表中
                     $this->obj->insert('content_publish_time', array('content_id' => $crd_id, 'publish_time' => $content_relation_data['publish_time']));
                 }
                 //插入到xunsearch中
                 $content_data['content_id'] = $content_id;
                 $this->opration_xunsearch($content_data + $content_relation_data, $content_columns, 'add', $column_detail_datas);
             }
         }
         //对视频跟电视剧处理
         if ($data['bundle_id'] == 'livmedia' && $data['app_uniqueid'] == 'tv_play') {
             $content_detail = $this->obj->get_all_content_by_relationid($crd_id, true);
             if ($content_detail && $content_detail['content_fromid']) {
                 include_once ROOT_PATH . 'lib/class/tv_play.class.php';
                 $tv_playobj = new tv_play();
                 $tv_playobj->update_tv($content_detail['content_fromid'], $content_detail['content_url']);
             }
         }
         $content_rid[$vc] = $crd_id;
     }
     if ($expand_id) {
         //清除memcache缓存
         $this->memcache_flush(APP_UNIQUEID);
         $result['msg'] = 'ok';
         $result['expand_id'] = $expand_id;
         $result['content_rid'] = $content_rid;
         $result['content_status'] = $content_status;
     } else {
         $result['msg'] = '同一内容,同一栏目,同一客户端内容重复';
         $result['error'] = '3';
     }
     $this->addItem($result);
     $this->output();
 }
示例#2
0
 /**
  * 给需要搜索的标题进行分词后格式转换
  * 如标题:纠结“单独二胎” 折射理性生育观
  * 转换后:7ea07ed3 535572ec 4e8c 4e8c80ce 62985c04 74066027 751f80b2 89c2
  *      :纠结      单独    二
  */
 public function get_titleResult($title)
 {
     $title_result = $this->xs_getResult($title);
     if ($title_result && is_array($title_result)) {
         foreach ($title_result as $tr_v) {
             $title_resultstr .= $tr_tag . $tr_v['word'];
             $tr_tag = ',';
         }
         $title = str_utf8_unicode($title_resultstr);
     } else {
         $title = str_utf8_unicode($title);
     }
     return $title;
 }
示例#3
0
文件: content.php 项目: h3len/Project
 public function update()
 {
     $con = $content_con = '';
     $data = $this->input['data'];
     if (!$data['content_fromid']) {
         exit;
     }
     $fromid = $data['content_fromid'];
     $data['struct_ast_id'] = empty($data['struct_ast_id']) ? '' : $data['struct_ast_id'];
     $field = $this->obj->get_field($data['bundle_id'], $data['module_id'], $data['struct_id'], $data['struct_ast_id']);
     $tablename = get_tablename($data['bundle_id'], $data['module_id'], $data['struct_id'], $data['struct_ast_id']);
     $fieldsarr = explode(',', $field['field']);
     unset($data['id']);
     unset($data['expand_id']);
     foreach ($data as $ku => $vu) {
         if (in_array($ku, $fieldsarr)) {
             $con .= $ku . "='" . (is_array($vu) ? serialize($vu) : $vu) . "',";
         }
     }
     $con = trim($con, ',');
     if (!$con) {
         exit;
     }
     $this->obj->update_child_table($tablename, $con, $fromid);
     //请求前端更新,插入到content_publish_time表中,查询关联表里的id
     $relation_ids_arr = $this->obj->get_relationid_by_expand_id($data['bundle_id'], $data['module_id'], $data['struct_id'], $fromid);
     //如果没有子表,则同时更新content表
     if (!$data['struct_ast_id']) {
         $content_con = '';
         //对keywords每个字进行转码
         $keywordstr = '';
         if (!empty($data['keywords'])) {
             $keywordstr = str_utf8_unicode($data['keywords']);
         }
         //对title每个字进行转码
         $titlestr = '';
         if (!empty($data['title'])) {
             $titlestr = $this->get_titleResult($data['title']);
             $title_pinyin_str = get_spell_title($data['title']);
         }
         //检测文稿内容正文里有无视频跟图集
         if ($data['content']) {
             $material_result = $this->obj->check_material_by_content($data['content']);
         }
         $update_content_data = array('title' => $data['title'], 'subtitle' => $data['subtitle'], 'brief' => $data['brief'], 'keywords' => $data['keywords'], 'indexpic' => is_array($data['indexpic']) ? serialize($data['indexpic']) : $data['indexpic'], 'video' => is_array($data['video']) ? serialize($data['video']) : $data['video'], 'outlink' => $data['outlink'], 'child_num' => $data['child_num'], 'source' => $data['source'], 'ip' => $data['ip'], 'create_user' => $data['user_name'], 'verify_user' => $data['verify_user'], 'template_sign' => $data['template_sign'], 'catalog' => $data['catalog'], 'tcolor' => $data['tcolor'], 'isbold' => $data['isbold'], 'isitalic' => $data['isitalic'], 'author' => $data['author'], 'iscomment' => $data['iscomment'] ? 1 : 0, 'is_praise' => $data['is_praise'] ? 1 : 0);
         $sql_extra = $space = ' ';
         foreach ($update_content_data as $k => $v) {
             $sql_extra .= $space . $k . "='" . $v . "'";
             $space = ',';
         }
         //更新content表并返回新信息
         $content_detail = $this->obj->update_content($data['bundle_id'], $data['module_id'], $data['struct_id'], $fromid, $sql_extra);
         $update_content_relation_data = array('is_have_indexpic' => empty($data['indexpic']) ? 0 : 1, 'is_have_video' => empty($data['video']) ? 0 : 1, 'keywords_unicode' => addslashes($keywordstr), 'title_unicode' => addslashes($titlestr), 'title_pinyin' => addslashes($title_pinyin_str), 'share_num' => $data['share_num'], 'comment_num' => $data['comment_num'], 'click_num' => $data['click_num'], 'create_time' => empty($data['create_time']) ? TIMENOW : $data['create_time'], 'verify_time' => empty($data['verify_time']) ? TIMENOW : $data['verify_time'], 'praise_count' => $data['praise_count'], 'is_have_content_video' => intval($material_result['video']), 'is_have_content_tuji' => intval($material_result['tuji']));
         if ($this->settings['is_support_update_weight']) {
             $update_content_relation_data['weight'] = $data['weight'];
         }
         $this->obj->update('content_relation', ' content_id=' . $content_detail['id'], $update_content_relation_data);
         $sql = "select * from " . DB_PREFIX . "content_relation where content_id=" . $content_detail['id'];
         $rinfo = $this->db->query($sql);
         while ($rrow = $this->db->fetch_array($rinfo)) {
             $rid_column_id[$rrow['id']] = $rrow['column_id'];
             $rid_column_data[$rrow['column_id']] = $rrow;
             $last_relation_data = $rrow;
         }
         /**
          //更新relation表
          $update_relation_data = array(
          'file_domain' => $data['file_domain'],
          'file_dir' => $data['file_dir'],
          'file_custom_filename' => $data['file_custom_filename'],
          );
          $sql                  = "select id,column_id,file_custom_filename,file_name from " . DB_PREFIX . "content_relation where content_id=" . $content_detail['id'];
          $rinfo                = $this->db->query($sql);
          while ($rrow                 = $this->db->fetch_array($rinfo))
          {
          $rid_column_id[$rrow['id']] = $rrow['column_id'];
          if ($data['file_custom_filename'])
          {
          if (strrpos($v['file_name'], '/') === false)
          {
          $update_relation_data['file_name'] = $data['file_custom_filename'];
          }
          else
          {
          $update_relation_data['file_name'] = substr($v['file_name'], 0, strrpos($v['file_name'], '/') + 1) . $v['file_custom_filename'];
          }
          }
          $this->obj->update('content_relation', ' id=' . $rrow['id'], $update_relation_data);
          }
         */
         //更新百度视频收录
         if ($content_detail['is_have_video']) {
             $this->obj->update_content_video_record(implode(',', $relation_ids_arr), $content_detail);
         }
         //判断有无推送,有则插入到content_push表中
         $this->obj->content_push($data, $content_detail['id'], $rid_column_data[$content_detail['column_id']]['id'], true);
         //更新xunsearch
         $content_columns = $this->obj->get_content_columns(' * ', array('content_id' => $content_detail['id']));
         $this->update_xunsearch($data, $content_detail + $last_relation_data, $content_columns, '');
     }
     //删除缓存
     if ($data['struct_ast_id']) {
         $data_id = $this->obj->get_update_child_id($tablename, $con, $fromid, false);
     } else {
         $data_id = $this->obj->get_update_child_id($tablename, $con, $fromid);
     }
     if ($data_id) {
         include CUR_CONF_PATH . 'lib/cache.class.php';
         $this->cache = new Cache();
         $this->cache->initialize(CUR_CONF_PATH . 'cache/' . $tablename . '/');
         $this->cache->delete($data_id);
     }
     //清除memcache缓存
     $this->memcache_flush(APP_UNIQUEID);
     foreach ($relation_ids_arr as $v) {
         if ($data['use_maincolumn']) {
             if ($rid_column_id[$v] == $content_detail['column_id']) {
                 $this->obj->insert('content_publish_time', array('content_id' => $v, 'publish_time' => TIMENOW));
             }
         } else {
             $this->obj->insert('content_publish_time', array('content_id' => $v, 'publish_time' => TIMENOW));
         }
     }
     //更新主内容childs_data内容
     if ($data['bundle_id'] == 'tuji') {
         $this->obj->insert_childs_to_content($data['bundle_id'], $data['module_id'], $data['struct_id'], 'tuji_pics', '', $v);
     }
 }
示例#4
0
文件: content.php 项目: h3len/Project
 public function get_content_condition($to_count = false)
 {
     $condition = $other_field = '';
     $condition .= " WHERE 1 ";
     if ($client_type = intval($this->input['client_type'])) {
         $condition .= " AND cr.client_type='" . $client_type . "'";
     }
     $condition .= " AND r.is_complete=1 ";
     if ($this->settings['is_need_audit']) {
         $condition .= " AND r.status=1";
     }
     //支持多个栏目
     if ($min_id = intval($this->input['min_id'])) {
         $condition .= " AND r.id>" . $min_id;
     }
     if ($this->input['id']) {
         $ids = hg_filter_ids($this->input['id']);
         $condition .= " AND r.id IN (" . $ids . ')';
     }
     if ($site_id = intval($this->input['site_id'])) {
         $condition .= " AND r.site_id=" . $site_id;
     }
     $column_id = urldecode($this->input['column_id']);
     if (!$column_id && ($column_name = trim($this->input['column_name']))) {
         $fid = intval($this->input['fid']);
         $column_name = explode(',', $column_name);
         if (!$this->input['child_column']) {
             $sql = 'SELECT parents FROM ' . DB_PREFIX . "column  WHERE id=" . $fid;
             $info = $this->db->query_first($sql);
             if ($info['parents']) {
                 $parents = explode(',', $info['parents']);
                 $fid = $parents[count($parents) - 1];
             }
             if ($fid) {
                 $sql = 'SELECT id FROM ' . DB_PREFIX . "column  WHERE concat(',', parents, ',') LIKE '%," . $fid . ",%' AND  name IN ('" . implode("','", $column_name) . "')";
             } else {
                 $sql = 'SELECT id FROM ' . DB_PREFIX . "column  WHERE  name IN ('" . implode("','", $column_name) . "')";
             }
         } else {
             $sql = 'SELECT id FROM ' . DB_PREFIX . "column  WHERE fid={$fid} AND  name IN ('" . implode("','", $column_name) . "')";
         }
         $tmp_column = array();
         $info = $this->db->query($sql);
         while ($row = $this->db->fetch_array($info)) {
             $tmp_column[] = $row['id'];
         }
         $column_id = implode(',', $tmp_column);
         if (!$column_id && $fid) {
             $column_id = $fid;
         }
     }
     if ($column_id) {
         $column_ids = '';
         $column_id = explode(',', $column_id);
         $column_id = "'" . implode("','", $column_id) . "'";
         if (!$this->input['not_need_child_column']) {
             $columns_data = $this->column->get_column_by_id(' id,name,fid,parents,childs,content_num ', $column_id, 'id');
             $tag = '';
             if (is_array($columns_data) && $columns_data) {
                 foreach ($columns_data as $k => $v) {
                     $column_ids .= $tag . $v['childs'];
                     $tag = ',';
                 }
             }
         } else {
             $column_ids = $column_id;
         }
         if ($column_ids) {
             $column_idarr = @array_unique(explode(',', $column_ids));
             $column_ids = implode(',', $column_idarr);
             $condition .= " AND r.column_id in (" . $column_ids . ")";
         } else {
             $this->errorOutput(NO_COLUMN_ID);
         }
     }
     if ($bundle_id = urldecode($this->input['bundle_id'])) {
         $bundle_idarr = explode(',', $bundle_id);
         $condition .= " AND r.bundle_id in ('" . implode("','", $bundle_idarr) . "')";
     }
     if ($this->input['exclude_special']) {
         $condition .= " AND r.bundle_id != '" . $this->input['exclude_special'] . "'";
     }
     if ($this->input['exclude_bundle']) {
         $exclude_bundle = explode(',', $this->input['exclude_bundle']);
         $condition .= " AND r.bundle_id NOT IN('" . implode("','", $exclude_bundle) . "')";
     }
     if ($module_id = urldecode($this->input['module_id'])) {
         $condition .= " AND r.module_id='" . $module_id . "'";
     }
     if (isset($this->input['weight']) && $this->input['weight'] !== '' && $this->input['weight'] != -1) {
         $condition .= " AND r.weight='" . intval($this->input['weight']) . "'";
     }
     if ($exclude_id = $this->input['exclude_id']) {
         $condition .= " AND r.content_id not in (" . $exclude_id . ")";
     }
     if ($cid = $this->input['cid']) {
         $cid = hg_filter_ids($this->input['cid']);
         $condition .= " AND r.content_id in (" . $cid . ")";
     }
     //查询权重
     if (isset($this->input['start_weight']) && intval($this->input['start_weight']) >= 0) {
         $condition .= " AND r.weight >= " . $this->input['start_weight'];
     }
     if (isset($this->input['end_weight']) && intval($this->input['end_weight']) >= 0) {
         $condition .= " AND r.weight <= " . $this->input['end_weight'];
     }
     if (isset($this->input['except_weight']) && $this->input['except_weight'] !== '') {
         $condition .= " AND r.weight != " . intval($this->input['except_weight']);
     }
     if (isset($this->input['is_have_indexpic']) && $this->input['is_have_indexpic'] !== '') {
         $condition .= " AND r.is_have_indexpic=" . intval($this->input['is_have_indexpic']);
     }
     if (isset($this->input['is_have_video']) && $this->input['is_have_video'] !== '') {
         $condition .= " AND r.is_have_video=" . intval($this->input['is_have_video']);
     }
     if ($start_time = trim(urldecode($this->input['starttime']))) {
         if ($start_time = strtotime($start_time)) {
             $condition .= " AND r.publish_time >= '" . $start_time . "'";
         }
     }
     if ($end_time = trim(urldecode($this->input['endtime']))) {
         if ($end_time = strtotime($end_time)) {
             $condition .= " AND r.publish_time <= '" . $end_time . "'";
         }
     }
     if ($create_user = trim($this->input['create_user'], ' ')) {
         $condition .= " AND r.create_user='******'create_user'] . "' ";
     }
     if ($publish_user = trim($this->input['publish_user'], ' ')) {
         $condition .= " AND r.publish_user='******'publish_user'] . "' ";
     }
     //查询发布的时间
     if ($this->input['date_search']) {
         $today = strtotime(date('Y-m-d'));
         $tomorrow = strtotime(date('Y-m-d', TIMENOW + 24 * 3600));
         switch (intval($this->input['date_search'])) {
             case 1:
                 //所有时间段
                 break;
             case 2:
                 //昨天的数据
                 $yesterday = strtotime(date('y-m-d', TIMENOW - 24 * 3600));
                 $condition .= " AND  r.publish_time > '" . $yesterday . "' AND r.publish_time < '" . $today . "'";
                 break;
             case 3:
                 //今天的数据
                 $condition .= " AND  r.publish_time > '" . $today . "' AND r.publish_time < '" . $tomorrow . "'";
                 break;
             case 4:
                 //最近3天
                 $last_threeday = strtotime(date('y-m-d', TIMENOW - 2 * 24 * 3600));
                 $condition .= " AND r.publish_time > '" . $last_threeday . "' AND r.publish_time < '" . $tomorrow . "'";
                 break;
             case 5:
                 //最近7天
                 $last_sevenday = strtotime(date('y-m-d', TIMENOW - 6 * 24 * 3600));
                 $condition .= " AND  r.publish_time > '" . $last_sevenday . "' AND r.publish_time < '" . $tomorrow . "'";
                 break;
             default:
                 //所有时间段
                 break;
         }
     }
     //标题
     if ($this->input['k'] || $this->input['title']) {
         $title = $this->input['title'] ? $this->input['title'] : $this->input['k'];
         $title = $this->get_titleResult($title . ' ');
         if ($title) {
             if ($this->settings['App_textsearch'] && !$this->input['normal_search']) {
                 $condition .= " AND MATCH (title_unicode) AGAINST ('" . $title . "' IN BOOLEAN MODE )";
                 $other_field = ",MATCH (title_unicode) AGAINST ('" . $title . "' IN BOOLEAN MODE ) AS title_score";
             } else {
                 $condition .= " AND r.title_unicode like '%" . $title . "%'";
                 $not_use_title_score = true;
             }
         }
     }
     if ($keywords = urldecode($this->input['keywords'])) {
         $keywordsstr = str_utf8_unicode($keywords);
         if ($keywordsstr) {
             if ($this->settings['App_textsearch'] && !$this->input['normal_search']) {
                 $condition .= " AND MATCH (keywords_unicode) AGAINST ('" . $keywordsstr . "' IN BOOLEAN MODE )";
                 $other_field = ",MATCH (keywords_unicode) AGAINST ('" . $keywordsstr . "' IN BOOLEAN MODE ) AS score";
             } else {
                 $condition .= " AND r.keywords_unicode like '%" . $keywordsstr . "%'";
                 $not_use_score = true;
             }
         }
     }
     if ($title_pinyin_str = urldecode($this->input['spell_title'])) {
         $title_pinyin_str = get_spell_title($title_pinyin_str);
         if ($title_pinyin_str) {
             $condition .= " AND MATCH (title_pinyin) AGAINST ('" . $title_pinyin_str . "' IN BOOLEAN MODE )";
             $other_field = ",MATCH (title_pinyin) AGAINST ('" . $title_pinyin_str . "' IN BOOLEAN MODE ) AS title_pinyin";
         }
     }
     if ($this->input['need_group_cid']) {
         $condition .= " GROUP BY r.content_id ";
     }
     if (!$to_count) {
         $order_tag = true;
         $condition .= " ORDER BY ";
         if ($keywordsstr && !$not_use_score) {
             $condition .= " score DESC ";
             $order_tag = false;
         } else {
             if ($title && !$not_use_title_score) {
                 $condition .= " title_score DESC ";
                 $order_tag = false;
             } else {
                 if ($spell_title_str) {
                     $condition .= " title_pinyin DESC ";
                     $order_tag = false;
                 }
             }
         }
         //排序
         if ($sort_field = urldecode($this->input['sort_field'])) {
             if (in_array($sort_field, array('weight', 'id', 'order_id', 'publish_time'))) {
                 $condition .= ($order_tag ? " " : ",") . 'r.' . $sort_field . ' ';
                 $order_tag = false;
                 if ($sort_type = urldecode($this->input['sort_type'])) {
                     $condition .= in_array($sort_type, $this->settings['sort_keyword']) ? $sort_type : 'DESC';
                 }
                 if ($sort_field == 'weight') {
                     $condition .= ' ,r.order_id DESC';
                 }
             } else {
                 if (in_array($sort_field, $this->settings['content_field'])) {
                     $condition .= ($order_tag ? " " : ",") . 'r.' . $sort_field . ' ';
                     $order_tag = false;
                     if ($sort_type = urldecode($this->input['sort_type'])) {
                         $condition .= in_array($sort_type, $this->settings['sort_keyword']) ? $sort_type : 'DESC';
                     }
                 } else {
                     $condition .= ($order_tag ? ' ' : ',') . "r.publish_time DESC ";
                     $order_tag = false;
                 }
             }
         } else {
             $condition .= ($order_tag ? ' ' : ',') . "r.order_id DESC ";
         }
         //$condition .= ($order_tag ? ' ' : ',') . "cr.id DESC ";
     }
     $result['condition'] = $condition;
     $result['other_field'] = $other_field;
     return $result;
 }