function keyword ($field, $value) { //获取post过来的关键字,关键字用空格或者‘,’分割的 $data = array(); $data = split('[ ,]', $value); //加载关键字的数据模型 $keyword_db = pc_base::load_model('keyword_model'); $keyword_data_db = pc_base::load_model('keyword_data_model'); pc_base::load_sys_func('iconv'); if (is_array($data) && !empty($data)) { $siteid = get_siteid(); foreach ($data as $v) { $v = defined('IN_ADMIN') ? $v : safe_replace(addslashes($v)); $v = str_replace(array('//','#','.'),' ',$v); if (!$r = $keyword_db->get_one(array('keyword'=>$v, 'siteid'=>$siteid))) { $letters = gbk_to_pinyin($v); $letter = strtolower(implode('', $letters)); $tagid = $keyword_db->insert(array('keyword'=>$v, 'siteid'=>$siteid, 'pinyin'=>$letter, 'videonum'=>1), true); } else { $keyword_db->update(array('videonum'=>'+=1'), array('id'=>$r['id'])); $tagid = $r['id']; } $contentid = $this->id.'-'.$this->modelid; if (!$keyword_data_db->get_one(array('tagid'=>$tagid, 'siteid'=>$siteid, 'contentid'=>$contentid))) { $keyword_data_db->insert(array('tagid'=>$tagid, 'siteid'=>$siteid, 'contentid'=>$contentid)); } unset($contentid, $tagid, $letters); } } return $value; }
public function genPost($v, $parent, $siteid, $template) { $post = $info = $setting = array(); $info['catid'] = $v['NodeID']; $info['parentid'] = $parent; if ($v['TableID'] > 12) { $v['TableID'] = '1'; } $res = $this->getWareModel($v['TableID']); $name = $res['Name']; $res = $this->getModelID($name, $siteid); $info['modelid'] = $res['modelid']; $info['catname'] = $v['Name']; $info['ismenu'] = 0; if ($v['PublishMode'] == 1) { $setting['ishtml'] = 1; $post['category_html_ruleid'] = 41; $setting['content_ishtml'] = 1; $post['show_html_ruleid'] = $this->getRulID($v); $post['category_html_ruleid'] = 1; $post['show_html_ruleid'] = 17; } else { if ($v['PublishMode'] == 2) { $post['category_php_ruleid'] = 1; $post['show_php_ruleid'] = 17; } else { $post['category_php_ruleid'] = 1; $post['show_php_ruleid'] = 17; } } if (!empty($template)) { $setting['template_list'] = $template; } $tmp = $this->genTemplate($v); $setting = array_merge($tmp, $setting); /* $a = $this->getUrlAndCatid($v); if (false !== $a && !empty($a)) { $info['catdir'] = $a['catdir']; $info['url'] = $a['url']; } */ $info['catdir'] = join("", gbk_to_pinyin($v['Name'])); $setting['template_list'] = 'default'; $post['info'] = $info; $post['setting'] = $setting; return $post; }
/** * 保存城市 */ public function save_city() { pc_base::load_sys_func('iconv'); $id = intval($_POST['id']); $city['name'] = iconv('utf-8', CHARSET, addslashes($_POST['name'])); //没有填写拼音默认将城市中文名称转化为拼音 if ($_POST['pinyin'] == '') { if (strtolower(CHARSET) == 'utf-8') { $str_py = gbk_to_pinyin(iconv(CHARSET, gbk, $city['name'])); $city['pinyin'] = strtolower(implode('', $str_py)); } else { $city['pinyin'] = strtolower(implode('', gbk_to_pinyin($city['name']))); } } else { $city['pinyin'] = trim($_POST['pinyin']); } $city['linkageid'] = $_POST['linkageid']; if ($city['name'] == '' || $city['pinyin'] == '') { exit('post_error'); } $city = array2string($city); if ($id == 0) { $insertid = $this->db->insert(array('key' => 'info_city', 'data' => $city), TRUE); $this->_cache(); if ($insertid) { echo $insertid; exit; } else { exit('0'); } } else { $this->db->update(array('data' => $city), array('key' => 'info_city', 'id' => $id)); $this->_cache(); exit('1'); } }
/** * 编辑栏目 * @param type $post 页面提交过来的数据 * @return boolean */ public function editCategory($post) { if (empty($post)) { $this->error = '添加栏目数据不能为空!'; return false; } $catid = $post['catid']; $data = $post['info']; //查询该栏目是否存在 $info = $this->where(array('catid' => $catid))->find(); if (empty($info)) { $this->error = '该栏目不存在!'; return false; } unset($data['catid'], $info['catid'], $data['module'], $data['child']); //表单令牌 $data[C("TOKEN_NAME")] = $post[C("TOKEN_NAME")]; $data['setting'] = $post['setting']; //内部栏目 if ((int) $info['type'] != 2) { if ($data['setting']['ishtml']) { $data['setting']['category_ruleid'] = $post['category_html_ruleid']; } else { $data['setting']['category_ruleid'] = $post['category_php_ruleid']; $data['url'] = ''; } } //栏目生成静态配置 if ($data['setting']['ishtml']) { $data['setting']['category_ruleid'] = $post['category_html_ruleid']; } else { $data['setting']['category_ruleid'] = $post['category_php_ruleid']; } //内容生成静态配置 if ($data['setting']['content_ishtml']) { $data['setting']['show_ruleid'] = $post['show_html_ruleid']; } else { $data['setting']['show_ruleid'] = $post['show_php_ruleid']; } //栏目是否生成静态 $data['sethtml'] = $data['setting']['ishtml'] ? 1 : 0; //判断URL规则是否有设置 if ((int) $info['type'] == 0) { //内部栏目 if (empty($data['setting']['category_ruleid'])) { $this->error = '栏目URL规则没有设置!'; return false; } if (empty($data['setting']['show_ruleid']) && $data['child']) { $this->error = '栏目内容页URL规则没有设置!'; return false; } //添加modelid自动验证规则 array_unshift($this->_validate, array('modelid', 'require', '所属模型不能为空!', 1, 'regex', 3)); } else { if ((int) $info['type'] == 1) { //单页栏目 if (empty($data['setting']['category_ruleid'])) { $this->error = '栏目URL规则没有设置!'; return false; } } } load("@.iconvfunc"); //栏目拼音 $catname = iconv('utf-8', 'gbk', $data['catname']); $letters = gbk_to_pinyin($catname); $data['letter'] = strtolower(implode('', $letters)); //序列化setting数据 $data['setting'] = serialize($data['setting']); $data = $this->create($data, 2); if ($data) { if ((int) $info['type'] != 2) { //绑定域名 $data['domain'] = $data['url']; } if ($this->where(array("catid" => $catid))->save($data) !== false) { //更新附件状态 if ($data['image']) { //更新附件状态,把相关附件和文章进行管理 service("Attachment")->api_update('', 'catid-' . $catid, 1); } //扩展字段处理 if ($post['extend']) { $this->extendField($catid, $post); } return true; } else { $this->error = '栏目修改失败!'; return false; } } else { return false; } }
public function index() { C('TOKEN_ON', false); $seo = seo(); $this->assign("seo", $seo); if (isset($_GET['q'])) { G('search'); //关键字 $q = Input::forSearch(safe_replace($this->_get("q"))); $q = htmlspecialchars(strip_tags($q)); //时间范围 $time = $this->_get("time"); //模型 $mid = (int) $this->_get("modelid"); //栏目 $catid = (int) $this->_get("catid"); //排序 $order = array("adddate" => "DESC", "searchid" => "DESC"); //搜索历史记录 $shistory = cookie("shistory"); if (!$shistory) { $shistory = array(); } $model = F("Model"); $category = F("Category"); if (trim($_GET['q']) == '') { header('Location: ' . U("Search/Index/index")); exit; } array_unshift($shistory, $q); $shistory = array_slice(array_unique($shistory), 0, 10); //加入搜索历史 cookie("shistory", $shistory); $where = array(); //每页显示条数 $pagesize = $this->config['pagesize'] ? $this->config['pagesize'] : 10; //缓存时间 $cachetime = (int) $this->config['cachetime']; //按时间搜索 if ($time == 'day') { //一天 $search_time = time() - 86400; $where['adddate'] = array("GT", $search_time); } elseif ($time == 'week') { //一周 $search_time = time() - 604800; $where['adddate'] = array("GT", $search_time); } elseif ($time == 'month') { //一月 $search_time = time() - 2592000; $where['adddate'] = array("GT", $search_time); } elseif ($time == 'year') { //一年 $search_time = time() - 31536000; $where['adddate'] = array("GT", $search_time); } else { $search_time = 0; } //可用数据源 $this->config['modelid'] = $this->config['modelid'] ? $this->config['modelid'] : array(); //按模型搜索 if ($mid && in_array($mid, $this->config['modelid'])) { $where['modelid'] = array("EQ", (int) $mid); } //按栏目搜索 if ($catid) { //不支持多栏目搜索,和父栏目搜索。 $where['catid'] = array("EQ", (int) $catid); } //分页模板 $TP = '共有{recordcount}条信息 {pageindex}/{pagecount} {first}{prev}{liststart}{list}{listend}{next}{last}'; //如果开启sphinx if ($this->config['sphinxenable']) { import("Sphinxapi", APP_PATH . C("APP_GROUP_PATH") . '/Search/Class/'); $sphinxhost = $this->config['sphinxhost']; $sphinxport = $this->config['sphinxport']; $cl = new SphinxClient(); //设置searchd的主机名和TCP端口 $cl->SetServer($sphinxhost, $sphinxport); //设置连接超时 $cl->SetConnectTimeout(1); //控制搜索结果集的返回格式 $cl->SetArrayResult(true); //设置全文查询的匹配模式 api http://docs.php.net/manual/zh/sphinxclient.setmatchmode.php $cl->SetMatchMode(SPH_MATCH_EXTENDED2); //设置排名模式 api http://docs.php.net/manual/zh/sphinxclient.setrankingmode.php $cl->SetRankingMode(SPH_RANK_PROXIMITY_BM25); //按一种类似SQL的方式将列组合起来,升序或降序排列。用weight是权重排序 $cl->SetSortMode(SPH_SORT_EXTENDED, "@weight desc"); //设置返回结果集偏移量和数目 $page = (int) $this->_get(C("VAR_PAGE")); $page = $page < 1 ? 1 : $page; $offset = $pagesize * ($page - 1); $cl->SetLimits($offset, $pagesize, $pagesize > 1000 ? $pagesize : 1000); if (in_array($time, array("day", "week", "month", "year"))) { //过滤时间 $cl->SetFilterRange('adddate', $search_time, time(), false); } if ($mid && in_array($mid, $this->config['modelid'])) { //过滤模型 $cl->SetFilter('modelid', (int) $mid); } if ($catid) { //过滤栏目 $cl->SetFilter('catid', (int) $catid); } //执行搜索 api http://docs.php.net/manual/zh/sphinxclient.query.php $res = $cl->Query($q, "*"); //信息总数 $count = $res['total']; //如果结果不为空 if (!empty($res['matches'])) { $result_sphinx = $res['matches']; } $result = array(); //数组重新组合 foreach ($result_sphinx as $k => $v) { $result[$k] = array("searchid" => $v['id'], "adddate" => $v['attrs']['adddate'], "catid" => $v['attrs']['catid'], "id" => $v['attrs']['id'], "modelid" => $v['attrs']['modelid']); } $words = array(); //搜索关键字 foreach ($res['words'] as $k => $v) { $words[] = $k; } $page = page($count, $pagesize); $page->SetPager('default', $TP, array("listlong" => "6", "first" => "首页", "last" => "尾页", "prev" => "上一页", "next" => "下一页", "list" => "*", "disabledclass" => "")); $this->assign("Page", $page->show('default')); } else { import("Segment", APP_PATH . C("APP_GROUP_PATH") . '/Search/Class/'); $Segment = new Segment(); //分词结果 $segment_q = $Segment->get_keyword($Segment->split_result($q)); $words = explode(" ", $segment_q); if (!empty($segment_q)) { $where['_string'] = " MATCH (`data`) AGAINST ('{$segment_q}' IN BOOLEAN MODE) "; } else { //这种搜索最不行 $where['data'] = array('like', "%{$q}%"); } //查询结果缓存 if ($cachetime) { //统计 $count = M("Search")->cache(true, $cachetime)->where($where)->count(); $page = page($count, $pagesize); $result = M("Search")->cache(true, $cachetime)->where($where)->limit($page->firstRow . ',' . $page->listRows)->order($order)->select(); } else { $count = M("Search")->where($where)->count(); $page = $this->page($count, $pagesize); $result = M("Search")->where($where)->limit($page->firstRow . ',' . $page->listRows)->order($order)->select(); } $page->SetPager('default', $TP, array("listlong" => "6", "first" => "首页", "last" => "尾页", "prev" => "上一页", "next" => "下一页", "list" => "*", "disabledclass" => "")); $this->assign("Page", $page->show('default')); } //搜索结果处理 if ($result && is_array($result)) { foreach ($result as $k => $r) { $modelid = $r['modelid']; $id = $r['id']; $tablename = ucwords($model[$modelid]['tablename']); if ($tablename) { $result[$k] = M($tablename)->where(array("id" => $id))->find(); } } } //搜索记录 if (strlen($q) < 17 && strlen($q) > 1 && $result) { $res = M("SearchKeyword")->where(array('keyword' => $q))->find(); if ($res) { //关键词搜索数+1 M("SearchKeyword")->where(array('keyword' => $q))->setInc("searchnums"); } else { //关键词转换为拼音 load("@.iconvfunc"); $pinyin = gbk_to_pinyin(iconv('utf-8', 'gbk//IGNORE', $q)); if (is_array($pinyin)) { $pinyin = implode('', $pinyin); } M("SearchKeyword")->add(array('keyword' => $q, 'searchnums' => 1, 'data' => $segment_q, 'pinyin' => $pinyin)); } } //相关搜索功能 if ($this->config['relationenble']) { $map = array(); //相关搜索 if (!empty($segment_q)) { $relation_q = str_replace(' ', '%', $segment_q); } else { $relation_q = $q; } $map['_string'] = " MATCH (`data`) AGAINST ('%{$relation_q}%' IN BOOLEAN MODE) "; $relation = M("SearchKeyword")->where($map)->select(); $this->assign("relation", $relation); } foreach ($this->config['modelid'] as $modelid) { $source[$modelid] = array("name" => $model[$modelid]['name'], "modelid" => $modelid); } //搜索结果 $this->assign("result", $result); //运行时间 $search_time = G('search', 'end', 6); $this->assign("count", $count ? $count : 0); $this->assign("search_time", $search_time); $this->assign("keyword", $q); $this->assign("category", $category); $this->assign("source", $source); $this->assign("time", $time); $this->assign("modelid", $mid); $this->assign("shistory", $shistory); //分词后的搜索关键字 $this->assign("words", $words); $this->display("search"); } else { $this->display(); } }
public function edit() { if (IS_POST) { $this->checkToken(); $cat = $this->db->where("siteid = %d and id = %d", $this->siteid, $_POST['id'])->find(); $data = $_POST['info']; $data['letter'] = join('', gbk_to_pinyin($data['catname'])); $model = $this->model_db->find(intval($data['modelid'])); $data['module'] = $model['name']; $data['setting'] = var_export($_POST['setting'], true); // 是否修改父栏目 if ($data['parentid'] == $cat['parentid']) { // echo "没有修改父栏目"; if ($this->db->where("siteid = %d and id = %d", $this->siteid, $_POST['id'])->save($data) !== false) { // echo $this->db->getLastSql(); $this->success('操作成功!', __MODULE__ . '/Category/index'); } else { $this->error('操作失败!'); } } else { if ($data['parentid']) { // 更新 'parentid' and 'arrparentid' $parentcat = $this->db->where("siteid = %d and id = %d", $this->siteid, $data['parentid'])->find(); if (!$parentcat) { $this->error('父栏目不存在'); exit(0); } $data['arrparentid'] = $parentcat['arrparentid'] . "," . $parentcat['id']; $data['parentdir'] = $parentcat['parentdir'] . $parentcat['catdir'] . "/"; $data['level'] = $parentcat['level'] + 1; $this->db->startTrans(); if ($this->db->where("siteid = %d and id = %d", $this->siteid, $_POST['id'])->save($data) !== false) { /* 更新原父栏目 */ $origin_parentcat = $this->db->where("siteid = %d and id = %d", $this->siteid, $cat['parentid'])->find(); if ($origin_parentcat) { $arrchildid = explode(',', $origin_parentcat['arrchildid']); foreach ($arrchildid as $key => $value) { if ($value == $cat['id']) { unset($arrchildid[$key]); break; } } $arrchildid = join(',', $arrchildid); $origin_parent_data = array('arrchildid' => $arrchildid); if ($arrchildid == $origin_parentcat['id']) { $origin_parent_data['child'] = 0; } if ($this->db->where("siteid = %d and id = %d", $this->siteid, $origin_parentcat['id'])->save($origin_parent_data) === false) { $this->db->rollback(); $this->error("更新原父栏目失败!"); } } /* 更新现父栏目 */ $data_parent = array('child' => 1, 'arrchildid' => $parentcat['arrchildid'] . "," . $cat['id']); if ($this->db->where("siteid = %d and id = %d", $this->siteid, $data['parentid'])->save($data_parent) !== false) { // echo '更新现父栏目成功'; $this->db->commit(); $this->success('操作成功!', __MODULE__ . '/Category/index'); } else { $this->db->rollback(); $this->error("更新现父栏目失败!"); } } else { $this->db->rollback(); $this->error("栏目更新失败!"); } } else { $data['level'] = 1; $data['arrparentid'] = "0"; $this->db->startTrans(); if ($this->db->where("siteid = %d and id = %d", $this->siteid, $_POST['id'])->save($data) !== false) { $origin_parentcat = $this->db->where("siteid = %d and id = %d", $this->siteid, $cat['parentid'])->find(); $arrchildid = explode(',', $origin_parentcat['arrchildid']); foreach ($arrchildid as $key => $value) { if ($value == $cat['id']) { unset($arrchildid[$key]); break; } } $arrchildid = join(',', $arrchildid); $origin_parent_data = array('arrchildid' => $arrchildid); if ($arrchildid == $origin_parentcat['id']) { $origin_parent_data['child'] = 0; } if ($this->db->where("siteid = %d and id = %d", $this->siteid, $origin_parentcat['id'])->save($origin_parent_data) !== false) { $this->db->commit(); $this->success('操作成功!', __MODULE__ . '/Category/index'); } else { $this->db->rollback(); $this->error("更新原父栏目失败!"); } } else { $this->db->rollback(); $this->error("栏目更新失败!"); } } } } else { $cats = list_to_tree($this->db->cat_list(), 'id', 'parentid'); $list = array(); tree_to_array($cats, $list); $cat = $this->db->where("siteid = %d and id = %d", $this->siteid, $_GET['id'])->find(); $model_list = $this->model_db->where(array('siteid' => $this->siteid, 'typeid' => 0))->select(); $cat['setting'] = string2array($cat['setting']); $this->assign('cat', $cat); $this->assign('cat_id', $cat_id); $this->assign('cats', $list); $this->assign("model_list", $model_list); $this->display(); } }
/** * 批量修改 */ public function batch_edit() { $categorys = getcache('category_content_' . $this->siteid, 'commons'); if (isset($_POST['dosubmit'])) { pc_base::load_sys_func('iconv'); $catid = intval($_POST['catid']); $post_setting = $_POST['setting']; //栏目生成静态配置 $infos = $info = array(); $infos = $_POST['info']; if (empty($infos)) { showmessage(L('operation_success')); } $this->attachment_db = pc_base::load_model('attachment_model'); foreach ($infos as $catid => $info) { $setting = string2array($categorys[$catid]['setting']); if ($_POST['type'] != 2) { if ($post_setting[$catid]['ishtml']) { $setting['category_ruleid'] = $_POST['category_html_ruleid'][$catid]; } else { $setting['category_ruleid'] = $_POST['category_php_ruleid'][$catid]; $info['url'] = ''; } } foreach ($post_setting[$catid] as $_k => $_setting) { $setting[$_k] = $_setting; } //内容生成静态配置 if ($post_setting[$catid]['content_ishtml']) { $setting['show_ruleid'] = $_POST['show_html_ruleid'][$catid]; } else { $setting['show_ruleid'] = $_POST['show_php_ruleid'][$catid]; } if ($setting['repeatchargedays'] < 1) { $setting['repeatchargedays'] = 1; } $info['sethtml'] = $post_setting[$catid]['create_to_html_root']; $info['setting'] = array2string($setting); $info['module'] = 'content'; $catname = CHARSET == 'gbk' ? $info['catname'] : iconv('utf-8', 'gbk', $info['catname']); $letters = gbk_to_pinyin($catname); $info['letter'] = strtolower(implode('', $letters)); $this->db->update($info, array('catid' => $catid, 'siteid' => $this->siteid)); //更新附件状态 if ($info['image'] && pc_base::load_config('system', 'attachment_stat')) { $this->attachment_db->api_update($info['image'], 'catid-' . $catid, 1); } } $this->public_cache(); showmessage(L('operation_success'), '?m=admin&c=category&a=init&module=admin&menuid=43'); } else { if (isset($_POST['catids'])) { //获取站点模板信息 pc_base::load_app_func('global'); $template_list = template_list($this->siteid, 0); foreach ($template_list as $k => $v) { $template_list[$v['dirname']] = $v['name'] ? $v['name'] : $v['dirname']; unset($template_list[$k]); } $show_validator = $show_header = ''; $catid = intval($_GET['catid']); $type = $_POST['type'] ? intval($_POST['type']) : 0; pc_base::load_sys_class('form', '', 0); if (empty($_POST['catids'])) { showmessage(L('illegal_parameters')); } $batch_array = $workflows = array(); foreach ($categorys as $catid => $cat) { if ($cat['type'] == $type && in_array($catid, $_POST['catids'])) { $batch_array[$catid] = $cat; } } if (empty($batch_array)) { showmessage(L('please_select_category')); } $workflows = getcache('workflow_' . $this->siteid, 'commons'); if ($workflows) { $workflows_datas = array(); foreach ($workflows as $_k => $_v) { $workflows_datas[$_v['workflowid']] = $_v['workname']; } } if ($type == 1) { include $this->admin_tpl('category_batch_edit_page'); } else { include $this->admin_tpl('category_batch_edit'); } } else { $type = isset($_GET['select_type']) ? intval($_GET['select_type']) : 0; $tree = pc_base::load_sys_class('tree'); $tree->icon = array(' │ ', ' ├─ ', ' └─ '); $tree->nbsp = ' '; $category = array(); foreach ($categorys as $catid => $r) { if ($this->siteid != $r['siteid'] || $r['type'] == 2 && $r['child'] == 0) { continue; } $category[$catid] = $r; } $str = "<option value='\$catid' \$selected>\$spacer \$catname</option>"; $tree->init($category); $string .= $tree->get_tree(0, $str); include $this->admin_tpl('category_batch_select'); } } }
/** * 提示搜索接口 * TODO 暂时未启用,用的是google的接口 */ public function public_suggest_search() { //关键词转换为拼音 pc_base::load_sys_func('iconv'); $pinyin = gbk_to_pinyin($q); if (is_array($pinyin)) { $pinyin = implode('', $pinyin); } $this->keyword_db = pc_base::load_model('search_keyword_model'); $suggest = $this->keyword_db->select("pinyin like '{$pinyin}%'", '*', 10, 'searchnums DESC'); foreach ($suggest as $v) { echo $v['keyword'] . "\n"; } }
/** *获取城市名称 */ public function getcity($ip) { $localinfo = ''; $address = $this->get($ip); if (strpos($address, L('province')) !== false && strpos($address, L('city')) !== false) { $address = explode(L('province'), $address); $address = $address[1]; } $address = str_replace(L('city'), '', $address); $localinfo['city'] = trim($address); $name = CHARSET == 'gbk' ? $localinfo['city'] : iconv('utf-8', 'gbk', $localinfo['city']); $name = str_replace(L('city'), '', $name); $letters = gbk_to_pinyin($name); $localinfo['pinyin'] = strtolower(implode('', $letters)); return $localinfo; }
/** * Function importfalbum * 将专辑载入到专题 * @param array $info 专辑详细信息 */ public function importfalbum($info = array()) { static $siteid, $sitelists; if (!$siteid) { $siteid = get_siteid(); } if (!$sitelists) { $sitelists = getcache('sitelist', 'commons'); } pc_base::load_sys_func('iconv'); if (is_array($info)) { $username = param::get_cookie('admin_username'); $userid = param::get_cookie('userid'); $arr = array('siteid' => $siteid, 'aid' => $info['id'], 'title' => $info['title'], 'thumb' => format_url($info['coverurl']), 'banner' => format_url($info['coverurl']), 'description' => $info['desc'], 'ishtml' => 0, 'ispage' => 0, 'style' => 'default', 'index_template' => 'index_video', 'list_template' => 'list_video', 'show_template' => 'show_video', 'username' => $username, 'userid' => $userid, 'createtime' => SYS_TIME, 'isvideo' => 1); //将数据插入到专题表中 $arr = new_html_special_chars($arr); $specialid = $this->db->insert($arr, true); $url = $sitelists[$siteid]['domain'] . 'index.php?m=special&c=index&id=' . $specialid; $this->db->update(array('url' => $url), array('id' => $specialid)); //组合子分类数组 $letters = gbk_to_pinyin($info['title']); $type_info = array('siteid' => $siteid, 'module' => 'special', 'modelid' => 0, 'name' => new_html_special_chars($info['title']), 'parentid' => $specialid, 'typedir' => strtolower(implode('', $letters)), 'listorder' => 1); $typeid = $this->type_db->insert($type_info, true); $url = $sitelists[$siteid]['domain'] . 'index.php?m=special&c=index&a=type&specialid=' . $specialid . '&typeid=' . $typeid; $this->type_db->update(array('url' => $url), array('typeid' => $typeid)); return $specialid; } else { return false; } }
function getpinyin($str, $ishead = 0, $isclose = 1) { if (!function_exists('gbk_to_pinyin')) { require_once TIPASK_ROOT . '/lib/iconv.func.php'; } if (TIPASK_CHARSET == 'utf-8') { $str = utf8_to_gbk($str); } return gbk_to_pinyin($str, $ishead, $isclose); }
/** * 修复栏目数据 * @param type $categorys 需要修复的栏目数组 * @return boolean */ protected function repair($categorys) { if (is_array($categorys)) { foreach ($categorys as $catid => $cat) { //外部栏目无需修复 if ($cat['type'] == 2) { continue; } //获取父栏目ID列表 $arrparentid = D("Content/Category")->getArrparentid($catid); //栏目配置信息反序列化 $setting = unserialize($cat['setting']); //获取子栏目ID列表 $arrchildid = D("Content/Category")->getArrchildid($catid); //检查所有父id 子栏目id 等相关数据是否正确,不正确更新 if ($categorys[$catid]['arrparentid'] != $arrparentid || $categorys[$catid]['arrchildid'] != $arrchildid) { D("Content/Category")->where(array('catid' => $catid))->save(array('arrparentid' => $arrparentid, 'arrchildid' => $arrchildid)); } //获取父栏目路径 $parentdir = $this->Url->get_categorydir($catid); //获取栏目名称 $catname = iconv('utf-8', 'gbk', $cat['catname']); //返回拼音 $letters = gbk_to_pinyin($catname); $letter = strtolower(implode('', $letters)); //取得栏目相关地址和分页规则 $category_url = $this->Url->category_url($catid); if (false == $category_url) { return false; } $url = $category_url['url']; //更新数据 $save = array(); //更新URL if ($cat['url'] != $url) { $save['url'] = $url; } if ($categorys[$catid]['parentdir'] != $parentdir || $categorys[$catid]['letter'] != $letter) { $save['parentdir'] = $parentdir; $save['letter'] = $letter; } if (count($save) > 0) { D("Content/Category")->where(array('catid' => $catid))->save($save); } //刷新单栏目缓存 getCategory($catid, '', true); } } return true; }
protected function dealSchoolArr($school = array()) { if (empty($school)) { return array("error" => true); } //判断该学校是否已存在 $where['name'] = $school['name']; $where['xiaozhang'] = $school['xiaozhang']; $where['type'] = $school['type']; $M = M('safe_school'); $info = $M->count($where); if ($info) { return array("error" => true); } //学校已存在,返回 //不存在,添加 $school_id = $M->insert($school, true); if (!$school_id) { return array("error" => -1); } //创建学校管理员 pc_base::load_sys_func("iconv"); //构造管理员数据 $manager['username'] = gbk_to_pinyin($school['admin']); $manager['username'] = implode("", $manager['username']); $pwd = password($school['admin_tel']); $manager['password'] = $pwd['password']; $manager['encrypt'] = $pwd['encrypt']; $manager['roleid'] = 10; $manager['school_id'] = $school_id; $manager['realname'] = $school['admin']; $M_admin = M("admin"); $admin_id = $M_admin->insert($manager); if (!$admin_id) { return array("error" => -2); } //是否存在中心校 if (!empty($school['lianxiao'])) { $lianxiao['name'] = $school['lianxiao']; $M_lianxiao = M("safe_data_lianxiao"); $num = $M_lianxiao->count($lianxiao); if (!$num) { $lianxiao_id = $M_lianxiao->insert($lianxiao); if (!$lianxiao_id) { return array("error" => -3); } //添加中心校管理员 $manager['username'] = gbk_to_pinyin($lianxiao['name']); $manager['username'] = implode("", $manager['username']); $pwd = password($manager['username']); $manager['password'] = $pwd['password']; $manager['encrypt'] = $pwd['encrypt']; $manager['roleid'] = 11; $manager['school_id'] = 0; $manager['realname'] = ''; $ladmin_id = $M_admin->insert($manager); if (!$ladmin_id) { return array("error" => -4); } } } return array("error" => true, 'school_id' => $school_id); }
/** * 修复栏目数据 */ protected function repair() { $this->categorys = $categorys = array(); //栏目数据 $categorysdata = M("Category")->select(); foreach ($categorysdata as $v) { $categorys[$v['catid']] = $v; } unset($categorysdata); $this->categorys = $categorys; $this->get_categorys($categorys); if (is_array($this->categorys)) { foreach ($this->categorys as $catid => $cat) { //外部栏目无需修复 if ($cat['type'] == 2) { continue; } //获取父栏目ID列表 $arrparentid = $this->get_arrparentid($catid); //栏目配置信息反序列化 $setting = unserialize($cat['setting']); //获取子栏目ID列表 $arrchildid = $this->get_arrchildid($catid); //检查所有父id 子栏目id 等相关数据是否正确,不正确更新 if ($categorys[$catid]['arrparentid'] != $arrparentid || $categorys[$catid]['arrchildid'] != $arrchildid) { M("Category")->where(array('catid' => $catid))->save(array('arrparentid' => $arrparentid, 'arrchildid' => $arrchildid)); } //获取父栏目路径 $parentdir = $this->get_parentdir($catid); //获取栏目名称 $catname = iconv('utf-8', 'gbk', $cat['catname']); //返回拼音 $letters = gbk_to_pinyin($catname); $letter = strtolower(implode('', $letters)); //检查排序是否正确 $listorder = $cat['listorder'] ? $cat['listorder'] : $catid; //静态和动态处理 if ($setting['ishtml']) { //生成静态时 $url = $this->update_url($catid); if (!preg_match('/^(http|https):\\/\\//i', $url)) { //20120618 //把地址拆成两部分,一部分域名,一部分网站所在目录 // 如果CONFIG_SITEURL是类似“/ed/”栏目URL直接是CONFIG_SITEURL+栏目生成目录 //如果CONFIG_SITEURL是类似“http://www.85zu.com/”栏目URL直接是CONFIG_SITEURL去除域名部分+栏目生成目录 $Domain = urlDomain(CONFIG_SITEURL); if ($Domain) { $url = "/" . str_replace($Domain, "", CONFIG_SITEURL) . $url; } else { $url = CONFIG_SITEURL . $url; } } } else { //不生成静态时 $url = $this->update_url($catid); } //更新URL if ($cat['url'] != $url) { M("Category")->where(array('catid' => $catid))->save(array('url' => $url)); } if ($categorys[$catid]['parentdir'] != $parentdir || $categorys[$catid]['letter'] != $letter || $categorys[$catid]['listorder'] != $listorder) { M("Category")->where(array('catid' => $catid))->save(array('parentdir' => $parentdir, 'letter' => $letter, 'listorder' => $listorder)); } } } //删除在非正常显示的栏目 foreach ($this->categorys as $catid => $cat) { if ($cat['parentid'] != 0 && !isset($this->categorys[$cat['parentid']])) { M("Category")->where(array('catid' => $catid))->delete(); } } return true; }