userlogic = new UserLogic (); include './protected/config/index.conf.php'; $this->column=$column; Doo::loadModel('Article'); $article=new Article(); $cid=$this->column['COMPANY']; $this->comart=$article->getArticleByCid($cid,4); } /** * 进入问答网首页 */ public function index() { $data ['category_info'] = $this->userlogic->get_category_info (); if (isset ( $data ['category_info'] [0] ['rsort'] [0] ['aid'] )) $id = $data ['category_info'] [0] ['rsort'] [0] ['aid']; elseif (isset ( $data ['category_info'] [0] ['rsort'] [0] ['cid'] )) $id = $data ['category_info'] [0] ['rsort'] [0] ['cid']; $data ['index_info'] = array ("sort" => array () ); if (isset ( $data ['category_info'] [0] ['rsort'] [0] ['cid'] )) $data ['index_info'] = $this->userlogic->get_category_by_pid ( $data ['category_info'] [0] ['rsort'] [0] ['cid'] ); $data ['title'] = ""; if (isset ( $data ['category_info'] [0] ['rsort'] [0] ['name'] )) $data ['title'] = $data ['category_info'] [0] ['rsort'] [0] ['name']; $data['map']='help'; $data['comart']=$this->comart; $this->render ( 'helpIndex', $data ); } /** * 显示帮助中心详情页 */ public function show_index_info() { $cid = $this->check_params ( 'cid' ); $sid = $this->check_params ( 'sid' ); //获取上一级分类 $data ['catetory'] = $this->userlogic->get_category_by_cid ( $cid ); //获取点击分类 $data ['click_catetory'] = $this->userlogic->get_category_by_cid ( $sid ); //获取点击分类的子分类 $data ['catetory_child'] = $this->userlogic->get_category_by_pid ( $cid ); $data ['defualt_info'] = array ("child_category" => array (), "article" => array () ); $data ['title'] = ""; $data ['defualt_info'] = $this->userlogic->get_category_by_pid ( $sid ); if (isset ( $data ['catetory_child'] ['sort'] [0] ['name'] )) { $data ['title'] = $data ['click_catetory'] ['name']; } else { $data ['title'] = $data ['click_catetory'] ['name']; } $data ['id'] = $sid; $this->render ( 'index_info', $data, true ); } /** * ajax显示文章 */ public function ajax_show_article() { $aid = $this->get_args ( 'aid' ); $data = $this->userlogic->get_article_by_aid ( $aid ); $e = json_encode ( $data ); echo $e; } //显示首页文章 public function show_index_article() { $cid = $this->check_params ( 'cid' ); $aid = $this->check_params ( 'aid' ); $data ['catetory'] = $this->userlogic->get_category_by_cid ( $cid ); $data ['catetory_child'] = $this->userlogic->get_category_by_pid ( $cid ); $data ['defualt_info'] = array ("child_category" => array (), "article" => array () ); $data ['title'] = ""; if (isset ( $data ['catetory_child'] ['child_category'] [0] )) { $data ['defualt_info'] = $this->userlogic->get_category_by_pid ( $data ['catetory_child'] ['child_category'] [0] ['cid'] ); $data ['title'] = $data ['catetory_child'] ['child_category'] [0] ['name']; } $data ['article_info'] = $this->userlogic->get_article_by_aid ( $aid ); $data ['id'] = $aid; $data['comart']=$this->comart; $this->render ( 'index_article', $data ); } /** * ajax详情 */ public function ajax_show_catetory() { $cid = $this->get_args ( 'cid' ); $data ['catetory'] = $this->userlogic->get_category_by_pid ( $cid ); $e = json_encode ( $data ); echo $e; } public function searchHelpNews(){ $k = $this->get_args('k') ? $this->get_args('k') : ""; $data ['article_list']=array('articles'=>array()); if (!empty($k)){ Doo::loadModel('ArticleDao'); $ArticleDao=new ArticleDao(); Doo::loadModel ( 'CategoryDao' ); $categorydao = new CategoryDao (); $ArticleDaoList['articles']=$ArticleDao->find(array ( 'where' => 'title like "%'.$k.'%"', 'asArray' => TRUE )); foreach ( $ArticleDaoList['articles'] as $key => $value ) { $ArticleDaoList['articles'] [$key] ['category'] = $categorydao->get_category_by_cid ( $value ['cid'] ); } $data ['article_list'] = $ArticleDaoList; } $data ['category'] = $this->userlogic->get_category_by_grade (); $data ['mod'] = 'article'; $data ['cid'] = 0; $this->render ( "poslistHelpSearch", $data );die; $list=array();$next=0;$previous=0; if (!empty($k)){ Doo::loadModel('Down'); $down=new Down(); $article=new Article(); if ($onPage <= 0) $onPage = 1; $pageSize = 20; $o=$onPage; $lower = (-- $o) * $pageSize; $previous = $onPage != 0 ? $onPage - 1 : $onPage; if ($kind==2){ $list=$down->find(array('where'=>'title like "%'.$k.'%" or key_number like "%'.$k.'%"','limit'=>$lower.','.$pageSize ,'asArray' => TRUE)); $totalCount = $down->count(array('where'=>'title like "%'.$k.'%" or key_number like "%'.$k.'%"','limit'=>$lower.','.$pageSize ,'asArray' => TRUE)); $total = intval ( $totalCount / $pageSize ); $totalPage = ($totalCount % $pageSize) == 0 ? $total : $total + 1; $next = $onPage == $totalPage ? $totalPage : $onPage + 1; foreach ($list as $key=>$value){ $url=explode("{b}", $value['down_url']); $list[$key]['down_url']=$url; } }elseif($kind==3){ Doo::loadModel('ArticleDao'); $ArticleDao=new ArticleDao(); $list=$ArticleDao->find(array('select'=>'title,aid,cid,time','where'=>'title like "%'.$k.'%" ', 'limit'=>$lower.','.$pageSize ,'asArray' => TRUE)); $totalCount = $ArticleDao->count(array('where'=>'title like "%'.$k.'%" ','asArray' => TRUE)); $total = intval ( $totalCount / $pageSize ); $totalPage = ($totalCount % $pageSize) == 0 ? $total : $total + 1; $next = $onPage == $totalPage ? $totalPage : $onPage + 1; }else{//or content like "%'.$k.'%" $list=$article->find(array('select'=>'title,aid,cid,time','where'=>'title like "%'.$k.'%" and ( cid=4 or cid=5 or cid=3 or cid=7)', 'limit'=>$lower.','.$pageSize ,'asArray' => TRUE)); $totalCount = $article->count(array('where'=>'title like "%'.$k.'%" and ( cid=4 or cid=5 or cid=3 or cid=7)','asArray' => TRUE)); $total = intval ( $totalCount / $pageSize ); $totalPage = ($totalCount % $pageSize) == 0 ? $total : $total + 1; $next = $onPage == $totalPage ? $totalPage : $onPage + 1; foreach ($list as $key=>$value){ if($value['cid']==4) $list[$key]['c']='公司新闻'; elseif ($value['cid']==5) $list[$key]['c']='行业新闻'; elseif ($value['cid']==3) $list[$key]['c']='培训教育'; elseif ($value['cid']==7) $list[$key]['c']='软件更新'; } } } $data['next']=$next; $data['previous']=$previous; $data['k']=$k; $data['onPage']=$onPage; $data['list']=$list; $data['kind']=$kind; $data['map']='sNews'; $this->render ( "poslistHelpSearch", $data ); } /** * 显示文章 */ public function show_article() { $cid = $this->check_params ( 'cid' ); if ($cid === false) $cid = $this->get_args ( 'cid' ); $cid = is_numeric ( $cid ) ? $cid : 0; $on_page = $this->check_params ( 'on_page' ); $on_page = is_numeric ( $on_page ) && $on_page > 0 ? $on_page : 1; $action = '/article/' . $cid . '/'; $page_size = 20; $condition = ""; if ($cid >= 1) $condition .= " and cid = " . $cid; $page = $this->userlogic->get_page ( 'zhhelp_article', $condition, $on_page, $page_size, $action ); $limit = " order by time desc limit " . $page ['lower'] . ", " . $page_size . " "; $page ['articles'] = $this->userlogic->get_article_list ( array (), $condition, $limit, 'zhhelp_article' ); $data ['article_list'] = $page; $data ['category'] = $this->userlogic->get_category_by_grade (); $data ['mod'] = 'article'; $data ['cid'] = $cid; $this->render ( 'poslist', $data ); } /** * 进入添加文章 */ public function add_article() { $data ['category'] = $this->userlogic->get_category_by_grade (); $data ['mod'] = 'add_article'; $this->render ( 'postnews', $data ); } /** * 进入编辑文章 */ public function edit_article() { $aid = $this->check_params ( 'aid' ); $data ['category'] = $this->userlogic->get_category_by_grade (); $data ['article'] = $this->userlogic->get_article_by_aid ( $aid ); $data ['category_name'] = $this->userlogic->get_category_by_cid ( $data ['article'] ['cid'] ); $data ['mod'] = 'article'; $this->render ( 'edit_postnews', $data ); } /** * 编辑文章 */ public function do_edit_article(){ $data['aid']=$this->get_args('aid'); $data ['cid'] = $this->get_args ( 'cid' ); $data ['title'] = $this->get_args ( 'title' ); $str = $_POST ['content']; $data ['content'] = $str; $data ['order'] = $this->get_args ( 'order' ); if ( empty ( $data ['title'] ) || empty ( $data ['content'] )) die ( "填入数据不正确" ); $this->userlogic->edit_article($data); header ( 'Content-Type:text/html;charset=utf-8' ); @header ( "Location: " . WEB_SITE . "/article" ); } /** * 添加文章 */ public function do_add_article() { $data ['cid'] = $this->get_args ( 'cid' ); $data ['title'] = $this->get_args ( 'title' ); $str = $_POST ['content']; $data ['content'] = $str; $data ['order'] = $this->get_args ( 'order' ); if (empty ( $data ['cid'] ) || $data ['cid'] == 0 || empty ( $data ['title'] ) || empty ( $data ['content'] )) die ( "填入数据不正确" ); $this->userlogic->add_article ( $data ); $data ['category'] = $this->userlogic->get_category_by_grade (); $data ['mod'] = 'add_article'; $this->render ( 'postnews', $data ); } /** * 添加分类 */ public function add_categroy() { $data ['mod'] = 'add_categroy'; $data ['category'] = $this->userlogic->get_category_by_grade (); $data ['category_lv2'] = $this->userlogic->get_category_by_grade ( 2 ); $data ['cid'] = ""; $this->render ( 'categroy', $data ); } /** * 添加分类 */ public function do_add_categroy() { $data ['pid'] = $this->get_args ( 'pid' ); $data ['name'] = $this->get_args ( 'name' ); $data ['grade'] = $this->get_args ( 'grade' ); $data ['displayorder'] = $this->get_args ( 'displayorder' ); if (empty ( $data ['name'] )) die ( "填入数据不正确" ); $this->userlogic->add_categroy ( $data ); $data ['mod'] = 'add_categroy'; $data ['category'] = $this->userlogic->get_category_by_grade (); $data ['category_lv2'] = $this->userlogic->get_category_by_grade ( 2 ); $data ['cid'] = ""; $this->render ( 'categroy', $data ); } /** * 删除分类--删除子类和文章 */ function delete_categroy() { $cid = $this->check_params ( 'cid' ); if (empty ( $cid )) die ( "填入数据不正确" ); $this->userlogic->delete_categroy ( $cid ); echo "success返回"; } /** * 删除文章 */ function delete_article() { $aid = $this->check_params ( 'aid' ); if (empty ( $aid )) die ( "填入数据不正确" ); $this->userlogic->delete_article ( $aid ); echo "success返回"; } /** * 上传问题图片--移动到user */ public function upload_article_img() { require_once (SITE_PATH . '/protected/plugin/Uploader.class.php'); //上传配置 $config = array ("savePath" => SITE_PATH . "/global/upload/img/", "maxSize" => 2000, //单位KB "allowFiles" => array (".gif", ".png", ".jpg", ".jpeg", ".bmp" ) ); //上传图片框中的描述表单名称, $title = htmlspecialchars ( $_POST ['pictitle'], ENT_QUOTES ); //生成上传实例对象并完成上传 $up = new Uploader ( "upfile", $config ); /** * 得到上传文件所对应的各个参数,数组结构 * array( * "originalName" => "", //原始文件名 * "name" => "", //新文件名 * "url" => "", //返回的地址 * "size" => "", //文件大小 * "type" => "" , //文件类型 * "state" => "" //上传状态,上传成功时必须返回"SUCCESS" * ) */ $info = $up->getFileInfo (); echo "{'url' :'" . $info ["name"] . "', 'title':'" . $title . "','original' :'" . $info ["originalName"] . "', 'state' :'" . $info ['state'] . "' }"; /** * 向浏览器返回数据json数据 * { * 'url' :'a.jpg', //保存后的文件路径 * 'title' :'hello', //文件描述,对图片来说在前端会添加到title属性上 * 'original' :'b.jpg', //原始文件名 * 'state' :'SUCCESS' //上传状态,成功时返回SUCCESS,其他任何值将原样返回至图片上传框中 * } */ } /** * 获取get或者POST值 * @param string $name 属性名称 * @return fixed 值 */ function get_args($name) { if (isset ( $_GET [$name] )) { if (is_array ( $_GET [$name] )) return $_GET [$name]; else return $_GET [$name] ; } elseif (isset ( $_POST [$name] )) { if (is_array ( $_POST [$name] )) return $_POST [$name]; else return $_POST [$name] ; } else { return false; } } /** * 检测数据输入的非法字符和转义非法字符 */ function check_params($name = "") { if (isset ( $this->params [$name] )) { return $this->params [$name] ; } else { return false; } } } ?>