function do_add_channel($original, $cha_code, $cha_name, $word_1, $word_2) { //判断频道是否已存在 $obj = new channel(); $obj->set_where(''); $obj->set_where("cha_code = '{$cha_code}'"); $channel = $obj->get_one(); if (count($channel)) { return 0; } //添加频道记录 $cha_original = get_id('channel', 'cha_code', $original); $obj = new channel(); $obj->set_value('cha_code', $cha_code); $obj->set_value('cha_name', $cha_name); $obj->set_value('cha_original', $cha_original); $obj->set_value('cha_lang', S_LANG); $obj->add(); $obj = new varia(); //添加前台导航(导航管理) if ($original == 'about') { $obj->set_value('var_name', 'nav_stage_' . $cha_code); $obj->set_value('var_value', $cha_name); $obj->add(); } //添加后台导航(导航管理) $obj->clear_value(); $obj->set_value('var_name', 'nav_admin_' . $cha_code); $obj->set_value('var_value', $cha_name); $obj->add(); //添加后台导航菜单 $obj = new menu(); $obj->set_value('men_type', 'admin_header'); $obj->set_value('men_name', $cha_name); $obj->set_value('men_url', $cha_code . '/mod-sheet/'); $obj->add(); $obj->clear_value(); $obj->set_value('men_type', 'admin_' . $cha_code); $obj->set_value('men_name', $cha_name . '列表'); $obj->set_value('men_url', $cha_code . '/mod-sheet/'); $obj->add(); $obj->clear_value(); $obj->set_value('men_type', 'admin_' . $cha_code); $obj->set_value('men_name', '添加' . $cha_name); $obj->set_value('men_url', $cha_code . '/mod-add/'); $obj->add(); if ($original == 'article' || $original == 'goods') { $obj->clear_value(); $obj->set_value('men_type', 'admin_' . $cha_code); $obj->set_value('men_name', $cha_name . '分类'); $obj->set_value('men_url', $cha_code . '/mod-cat_list/'); $obj->add(); } if ($original == 'goods') { $obj->clear_value(); $obj->set_value('men_type', 'admin_' . $cha_code); $obj->set_value('men_name', $cha_name . '属性'); $obj->set_value('men_url', $cha_code . '/mod-att_list/'); $obj->add(); } //添加前台导航菜单 $obj = new menu(); $obj->set_value('men_lang', S_LANG); $obj->set_value('men_type', 'header'); $obj->set_value('men_name', $cha_name); $obj->set_value('men_url', $cha_code . '/'); $obj->add(); //添加属性 if ($original == 'download') { $obj = new att_art(); $obj->set_where(''); $obj->set_where("att_channel_id = {$cha_original}"); $list = $obj->get_list(); $channel_id = get_id('channel', 'cha_code', $cha_code); for ($i = 0; $i < count($list); $i++) { $obj->clear_value(); $obj->set_value('att_channel_id', $channel_id); $obj->set_value('att_lang', $list[$i]['att_lang']); $obj->set_value('att_code', $list[$i]['att_code']); $obj->set_value('att_name', $list[$i]['att_name']); $obj->add(); } } //创建语言包 $path = 'languages/' . S_LANG . '/admin/'; if (file_exists($path . $original . '.txt')) { $str = file_get_contents($path . $original . '.txt'); $str = str_replace($word_1, $word_2, $str); file_put_contents($path . $cha_code . '.txt', $str); } $path = 'languages/' . S_LANG . '/index/'; if (file_exists($path . $original . '.txt')) { $str = file_get_contents($path . $original . '.txt'); $str = str_replace($word_1, $word_2, $str); file_put_contents($path . $cha_code . '.txt', $str); } //修改伪静态文件 $path = 'admin/module/basic/htaccess.txt'; if (file_exists($path)) { $str = file_get_contents($path); $str .= "\n" . 'RewriteRule ^' . $cha_code . '/(.*)$ index.php?/' . $cha_code . '/$1'; $str = str_replace("\n\n", "\n", $str); file_put_contents($path, $str); } return 1; }
function add_or_edit_article() { global $global, $smarty, $lang; $art_id = post('art_id'); $art_title = post('art_title'); $art_cat_id = post('art_cat_id'); $art_author = post('art_author'); $att_url = post('file_path'); $art_text = post('editor', 'loose'); $art_keywords = post('art_keywords'); $art_description = post('art_description'); $art_add_time = time(); $arr = array(); $obj = new att_art(); $obj->set_where(''); $obj->set_where('att_channel_id = ' . $global['channel_id']); $att = $obj->get_list(); for ($i = 0; $i < count($att); $i++) { $att_value = post($att[$i]['att_code']); if ($att_value != '') { $arr[$att[$i]['att_id']] = $att_value; } } $art_attribute = rawurlencode(json_encode($arr)); if ($art_cat_id == '') { $art_cat_id = 0; } $art_text = str_replace('<p><br/></p>', '', $art_text); $art_text = str_replace('<p><br /></p>', '', $art_text); $art_description = cut_str($art_description, 250); $obj = new article(); $obj->set_value('art_title', $art_title); $obj->set_value('art_cat_id', $art_cat_id); $obj->set_value('art_author', $art_author); $obj->set_value('art_text', $art_text); $obj->set_value('art_keywords', $art_keywords); $obj->set_value('art_description', $art_description); $obj->set_value('art_add_time', $art_add_time); $obj->set_value('art_attribute', $art_attribute); if ($art_id != '') { $obj->set_where("art_id = {$art_id}"); $obj->edit(); $info_text = $lang['edit_article_success']; } else { $obj->set_value('art_channel_id', $global['channel_id']); $obj->set_value('art_lang', S_LANG); $obj->add(); $info_text = $lang['add_article_success']; } if (intval(get_varia('single_page_static'))) { $page_id = $art_id; if ($page_id == '') { $obj->set_where("art_add_time = {$art_add_time}"); $one = $obj->get_one(); if (count($one)) { $page_id = $one['art_id']; } } if ($page_id != '') { $domain = get_domain(); $page_url = 'http://' . $domain . S_ROOT . url(array('channel' => $global['channel'], 'id' => $page_id)); $html = file_get_contents($page_url); } } $smarty->assign('info_text', $info_text); $smarty->assign('link_text', $lang['return_list']); $smarty->assign('link_href', url(array('channel' => $global['channel'], 'mod' => 'sheet'))); }