本文整理汇总了PHP中gbk_to_pinyin函数的典型用法代码示例。如果您正苦于以下问题:PHP gbk_to_pinyin函数的具体用法?PHP gbk_to_pinyin怎么用?PHP gbk_to_pinyin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gbk_to_pinyin函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: keyword
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;
}
示例2: genPost
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;
}
示例3: save_city
/**
* 保存城市
*/
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');
}
}
示例4: editCategory
/**
* 编辑栏目
* @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;
}
}
示例5: index
//.........这里部分代码省略.........
//数组重新组合
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();
}
}
示例6: edit
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();
//.........这里部分代码省略.........
示例7: batch_edit
/**
* 批量修改
*/
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;
}
//.........这里部分代码省略.........
示例8: public_suggest_search
/**
* 提示搜索接口
* 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";
}
}
示例9: getcity
/**
*获取城市名称
*/
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;
}
示例10: importfalbum
/**
* 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;
}
}
示例11: getpinyin
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);
}
示例12: repair
/**
* 修复栏目数据
* @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;
}
示例13: dealSchoolArr
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);
}
示例14: repair
/**
* 修复栏目数据
*/
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;
}