/** * 添加栏目 */ public function addAction() { if ($this->post('submit')) { $data = $this->post('data'); if ($data['typeid'] == 1) { if (empty($data['modelid'])) { $this->adminMsg(lang('a-cat-0')); } } elseif ($data['typeid'] == 2) { if (empty($data['content'])) { $this->adminMsg(lang('a-cat-1')); } } elseif ($data['typeid'] == 3) { if (empty($data['urlpath'])) { $this->adminMsg(lang('a-cat-2')); } } else { $this->adminMsg(lang('a-cat-3')); } if ($this->post('addall')) { $names = $this->post('names'); if (empty($names)) { $this->adminMsg(lang('a-cat-4')); } $names = explode(chr(13), $names); $y = $n = 0; foreach ($names as $val) { list($catname, $catdir) = explode('|', $val); $catdir = $catdir ? $catdir : word2pinyin($catname); if ($data['typeid'] != 3 && $this->category->check_catdir(0, $catdir)) { $catdir .= rand(0, 9); } $data['catdir'] = $catdir; $data['catname'] = $catname; $data['setting'] = $this->post('setting'); $catid = $this->category->set(0, $data); if (!is_numeric($catid)) { $n++; } else { $this->category->url($catid, $this->getCaturl($data)); $y++; } } $this->adminMsg($this->getCacheCode('category') . lang('a-cat-5', array('1' => $y, '2' => $n)), url('admin/category/index'), 3, 1, 1); } else { if (empty($data['catname'])) { $this->adminMsg(lang('a-cat-4')); } if ($data['typeid'] != 3 && $this->category->check_catdir(0, $data['catdir'])) { $this->adminMsg(lang('a-cat-6')); } $data['setting'] = $this->post('setting'); $result = $this->category->set(0, $data); if (!is_numeric($result)) { $this->adminMsg($result); } $data['catid'] = $result; $this->category->url($result, $this->getCaturl($data)); $this->adminMsg($this->getCacheCode('category') . lang('success'), url('admin/category/index'), 3, 1, 1); } } $model = $this->get_model(); $catid = (int) $this->get('catid'); $json_m = json_encode($model); $this->view->assign(array('add' => 1, 'model' => $model, 'rolemodel' => $this->user->get_role_list(), 'json_model' => $json_m ? $json_m : '""', 'membergroup' => $this->cache->get('membergroup'), 'membermodel' => $this->membermodel, 'category_select' => $this->tree->get_tree($this->cats, 0, $catid))); $this->view->display('admin/category_add'); }
public function importAction() { if ($this->post('submit')) { $catid = $this->post('catid'); $i = $j = $k = 0; $file = $_FILES['txt']; if ($file['type'] != 'text/plain') { $this->adminMsg(lang('a-tag-3', array('1' => $file['type']))); } if ($file['error']) { $this->adminMsg(lang('a-tag-4')); } if (!file_exists($file['tmp_name'])) { $this->adminMsg(lang('a-tag-5')); } $data = file_get_contents($file['tmp_name']); $data = explode(PHP_EOL, $data); foreach ($data as $t) { $name = trim($t); if ($name) { $row = $this->tag->getOne('name=?', $name); if (empty($row)) { $id = $this->db->replace('tag', array('name' => $name, 'letter' => word2pinyin($name), 'listorder' => 0, 'catid' => $catid)); if ($id) { $i++; } } else { $j++; } } else { $k++; } } $this->adminMsg($this->getCacheCode('tag') . lang('a-tag-6', array('1' => $i, '2' => $k, '3' => $j)), url('admin/tag/index'), 3, 1, 1); } $this->view->assign(array('category' => $this->cat)); $this->view->display('admin/tag_import'); }
/** * Tag标签URL */ function tag_url($word) { global $config; if (empty($word)) { return ''; } return $config['SITE_TAG_URL'] ? str_replace('{tag}', word2pinyin($word), SITE_PATH . $config['SITE_TAG_URL']) : url('tag/list', array('kw' => word2pinyin($word))); }
/** * Tag标签URL */ function tag_url($word) { global $config; if (empty($word)) { return ''; } //print_r($config); // return $config['SITE_TAG_URL'] ? str_replace('{tag}', word2pinyin($word), SITE_PATH . $config['SITE_TAG_URL']) : url('tag/list', array('kw' => word2pinyin($word))); $siteid = isset($_REQUEST['siteid']) && intval($_REQUEST['siteid']) > 1 ? intval($_REQUEST['siteid']) : 1; if ($config['SITE_TAG_URL']) { $val = str_replace('{tag}', word2pinyin($word), SITE_PATH . $config['SITE_TAG_URL']); return str_replace('{site}', $siteid, $val); } else { return url('tag/list', array('kw' => word2pinyin($word), 'siteid' => $siteid)); } }
/** * 生成拼音 */ public function pinyinAction() { echo word2pinyin($this->post('name')); }
/** * 添加、修改内容数据 */ public function set($id, $tablename, $data) { $id = intval($id); if (!$this->is_table_exists($tablename)) { return lang('m-con-37', array('1' => $tablename)); } $table = Controller::model($tablename); //加载附表Model if (empty($data['catid'])) { return lang('m-con-8'); } $_data = $id ? $this->find($id) : null; //数组转化为字符 foreach ($data as $i => $t) { if (is_array($t)) { $data[$i] = array2string($t); } } //描述截取 if (empty($data['description']) && isset($data['content'])) { $len = isset($data['fn_add_introduce']) && $data['fn_add_introduce'] && $data['fn_introcude_length'] ? $data['fn_introcude_length'] : 200; $data['description'] = str_replace(array(PHP_EOL, ' '), array('', ''), strcut(clearhtml($data['content']), $len)); } //下载远程图片 if (isset($data['content']) && isset($data['fn_down_image']) && $data['fn_down_image']) { $content = str_replace(array('\\', '"'), array('', '\''), htmlspecialchars_decode($data['content'])); if (preg_match_all("/(src)=([\"|']?)([^ \"'>]+\\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $imgs)) { $userid = !$data['sysadd'] && $data['userid'] ? $data['userid'] : (!$_data['sysadd'] && $_data['userid'] ? $_data['userid'] : 0); $sysadd = $data['sysadd'] ? $data['sysadd'] : ($_data['sysadd'] ? $_data['sysadd'] : 0); if ($userid) { //表示会员投稿 $member = $this->execute("select groupid from {$this->prefix}member where id=" . $userid, false); $group = $this->execute("select * from {$this->prefix}member_group where id=" . (int) $member['groupid'], false); $result = $this->download_images($imgs[3], $userid, (int) $group['filesize']); } elseif ($sysadd) { //表示管理员投稿 $result = $this->download_images($imgs[3]); } if (isset($result) && $result) { $image = $result['replace'][0]; $data['content'] = str_replace($result['regex'], $result['replace'], $data['content']); } } } //提取缩略图 if (empty($data['thumb']) && isset($data['content']) && isset($data['fn_auto_thumb']) && $data['fn_auto_thumb']) { if (isset($image)) { $data['thumb'] = $image; } else { $content = str_replace(array('\\', '"'), array('', '\''), htmlspecialchars_decode($data['content'])); if (preg_match("/(src)=([\"|']?)([^ \"'>]+\\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $img)) { $data['thumb'] = $img[3]; } } } //关键字处理 if ($data['keywords']) { $data['keywords'] = str_replace(',', ',', $data['keywords']); $tags = @explode(',', $data['keywords']); if ($tags) { foreach ($tags as $t) { $name = trim($t); if ($name) { $d = $this->from('tag', 'id')->where('name=?', $name)->select(false); if (empty($d)) { $this->query('INSERT INTO `' . $this->prefix . 'tag` (`name`,`letter`) VALUES ("' . $name . '", "' . word2pinyin($name) . '")'); } } } } } $status = 1; //用于判断积分增加 $is_add = 0; if ($id) { //修改 if (empty($_data)) { $data['id'] = $id; $data['url'] = getUrl($data); //更新URL $data['status'] = 1; //插入时状态设置为1 $this->insert($data); $table->insert($data); $is_add = 1; } else { $data['id'] = $data['id'] ? $data['id'] : $id; $data['url'] = getUrl($data); //更新URL unset($data['id']); $data['status'] = $data['status'] > 0 ? 1 : 0; //修改时,非0状态设置为1 $this->update($data, 'id=' . $id); $table->update($data, 'id=' . $id); $status = 0; //修改时不作为积分处理 $data['userid'] = $_data['userid']; } } else { //添加 $data['id'] = $id = $this->get_content_id(); if (empty($id)) { return lang('m-con-36'); } $data['url'] = getUrl($data); //更新URL $data['status'] = 1; //插入时状态设置为1 $this->insert($data); $table->insert($data); $is_add = 1; } //积分处理 非系统添加且(增加时,文档状态等于1) if (!$data['sysadd'] && $status == 1) { $this->credits($data['userid'], 1); } //处理内容扩展数据 $this->set_extend_data($id, $data); // 添加数据的处理 if ($is_add) { // 回调函数 $table = str_replace($this->prefix, '', $table->table_name); $function = 'callback_' . $table; $file = MODEL_DIR . 'callback/' . $table . '.php'; if (is_file($file)) { include_once $file; if (function_exists($function)) { $function($data); } } // 执行任务表 $table = $this->db->dbprefix . "sb"; $this->db->query("CREATE TABLE IF NOT EXISTS `" . $table . "` (\n `id` int(10) AUTO_INCREMENT NOT NULL,\n `type` varchar(50) NOT NULL,\n `value` text NOT NULL,\n PRIMARY KEY (`id`),\n KEY `type` (`type`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); $this->db->insert($table, array('type' => 'content_add', 'value' => array2string($data))); // 推送微信 $this->post_weixin($id); } return $id; }
/** * 添加栏目 */ public function addAction() { if ($this->post('submit')) { $data = $this->post('data'); if ($data['typeid'] == 1) { if (empty($data['modelid'])) { $this->show_message('请选择内容模型', 2, 1); } } elseif ($data['typeid'] == 2) { $data['modelid'] = 0; } elseif ($data['typeid'] == 3) { $data['modelid'] = 0; if (empty($data['http'])) { $this->show_message('没有输入外部连接地址', 2, 1); } } else { $this->show_message('请选择栏目类型', 2, 1); } if ($this->post('addall')) { //批量添加 $names = $this->post('names'); if (empty($names)) { $this->show_message('请填写栏目名称', 2, 1); } $names = explode(chr(13), $names); foreach ($names as $val) { list($catname, $catdir) = explode('|', $val); $catdir = $catdir ? $catdir : word2pinyin($catname); if ($data['typeid'] != 3) { $iscatdir = $this->check_catdirAction($catdir); if ($iscatdir) { $catdir .= rand(1, 20); } } $data['catname'] = trim($catname); $data['catdir'] = trim($catdir); $catid = $this->db->setTableName('category')->insert($data, true); if (!is_numeric($catid)) { $this->show_message('添加失败', 2); } } $this->cacheAction(); $html = '<script type="text/javascript">parent.document.getElementById(\'leftMain\').src =\' ?c=index&a=tree\';</script>'; $this->show_message('批量添加成功' . $html, 1, url('category/index')); } else { //单个添加 if (!$data['catname']) { $this->show_message('请填写栏目名称', 2, 1); } $iscatdir = $this->check_catdirAction($data['catdir']); if ($data['typeid'] != 3 && $iscatdir) { $this->show_message('栏目目录为空或者已经存在', 2, 1); } $data['catid'] = $this->db->setTableName('category')->insert($data, true); if (!is_numeric($data['catid'])) { $this->show_message('添加失败', 2); } $this->cacheAction(); $html = '<script type="text/javascript">parent.document.getElementById(\'leftMain\').src =\' ?c=index&a=tree\';</script>'; $this->show_message($data['catname'] . ' 添加成功' . $html, 1, url('category/index')); } } $catdata = $this->db->setTableName('category')->findAll(array('catid', 'catname', 'parentid'), 'listorder DESC,catid ASC'); $catid = (int) $this->get('catid'); $add = 1; $this->tree->icon = array(' ', ' |-', ' |-'); $this->tree->nbsp = ' '; $category_select = array(); if (!empty($catdata)) { foreach ($catdata as $r) { $category_select[$r['catid']] = $r; } } $str = "<option value='\$catid' \$selected>\$spacer \$catname</option>"; $this->tree->init($category_select); $category_select = $this->tree->get_tree_category(0, $str, '2', $catid); include $this->admin_tpl('category_add'); }