public function submit()
 {
     $ip_false = M('option')->where("meta_key='ip_false' AND type='user'")->getField('meta_value', true);
     if ($ip_false && in_array(mc_user_ip(), $ip_false)) {
         $this->error('您的IP被永久禁止登陆!');
     } else {
         $user_name = mc_magic_in(mc_remove_html($_POST['user_name'], 'all'));
         if ($user_name == '') {
             $this->error('账号必须填写!');
         } else {
             $user_login = M('meta')->where("meta_key='user_name' AND type ='user'")->getField('meta_value', true);
             if (in_array(strip_tags($_POST['user_name']), $user_login)) {
                 $this->error('账号已存在!');
             }
         }
         $user_email = mc_magic_in(mc_remove_html($_POST['user_email'], 'all'));
         if (empty($user_email)) {
             $this->error('邮箱必须填写!');
         } else {
             $user_email = M('meta')->where("meta_key='user_email' AND type ='user'")->getField('meta_value', true);
             if (in_array(strip_tags($_POST['user_email']), $user_email)) {
                 $this->error('邮箱已存在!');
             }
         }
         if (empty($_POST['user_pass'])) {
             $this->error('密码必须填写!');
         }
         if ($_POST['user_pass'] != $_POST['user_pass2']) {
             $this->error('两次密码必须一致!');
         }
         $user['title'] = I('param.user_name');
         $user['content'] = '';
         $user['type'] = 'user';
         $user['date'] = strtotime("now");
         $result = M("page")->data($user)->add();
         if ($result) {
             mc_add_meta($result, 'user_name', $user_name, 'user');
             $user_pass = md5(I('param.user_pass') . mc_option('site_key'));
             mc_add_meta($result, 'user_pass', $user_pass, 'user');
             mc_add_meta($result, 'user_email', $user_email, 'user');
             mc_add_meta($result, 'user_level', '1', 'user');
             cookie('user_name', I('param.user_name'), 36000000000);
             cookie('user_pass', $user_pass, 36000000000);
             $ip_array = M('action')->where("page_id='" . mc_user_id() . "' AND action_key='ip'")->getField('action_value', true);
             if ($ip_array && in_array(mc_user_ip(), $ip_array)) {
             } else {
                 if (!mc_is_admin()) {
                     mc_add_action(mc_user_id(), 'ip', mc_user_ip());
                 }
             }
             if ($_POST['comefrom']) {
                 $this->success('注册成功', $_POST['comefrom']);
             } else {
                 $this->success('注册成功', U('user/index/edit?id=' . mc_user_id()));
             }
         } else {
             $this->error('注册失败');
         }
     }
 }
 public function edit()
 {
     if (mc_is_admin() || mc_is_bianji() || mc_author_id($_POST['id']) == mc_user_id()) {
         if (mc_remove_html($_POST['title'], 'all') && $_POST['content'] && is_numeric($_POST['id'])) {
             if (mc_get_page_field($_POST['id'], 'type') == 'pro') {
                 if ($_POST['term']) {
                     mc_update_meta($_POST['id'], 'term', mc_magic_in($_POST['term']));
                 } else {
                     $this->error('请设置分类!');
                 }
                 if ($_POST['price'] > 0) {
                     mc_update_meta($_POST['id'], 'price', mc_magic_in($_POST['price']));
                 } else {
                     $this->error('请填写价格!');
                 }
                 if ($_POST['canshu'] > 0) {
                     mc_delete_meta($_POST['id'], 'kucun');
                     mc_update_meta($_POST['id'], 'parameter', serialize($_POST['parameter']));
                 } else {
                     mc_delete_meta($_POST['id'], 'parameter');
                     if (is_numeric($_POST['kucun'])) {
                         mc_update_meta($_POST['id'], 'kucun', $_POST['kucun']);
                     } else {
                         mc_update_meta($_POST['id'], 'kucun', 0);
                     }
                 }
                 if (is_numeric($_POST['xiaoliang'])) {
                     mc_update_meta($_POST['id'], 'xiaoliang', $_POST['xiaoliang']);
                 }
                 if ($_POST['fmimg']) {
                     mc_delete_meta($_POST['id'], 'fmimg');
                     foreach ($_POST['fmimg'] as $val) {
                         mc_add_meta($_POST['id'], 'fmimg', mc_save_img_base64($val, 1));
                     }
                 } else {
                     $this->error('请设置商品图片!');
                 }
                 mc_update_meta($_POST['id'], 'tb_name', $_POST['tb_name']);
                 mc_update_meta($_POST['id'], 'tb_url', $_POST['tb_url']);
                 mc_update_meta($_POST['id'], 'keywords', $_POST['keywords']);
                 mc_update_meta($_POST['id'], 'description', $_POST['description']);
             }
             if (mc_get_page_field($_POST['id'], 'type') == 'group') {
                 mc_update_meta($_POST['id'], 'fmimg', mc_magic_in(mc_save_img_base64($_POST['fmimg'])));
             }
             if (mc_get_page_field($_POST['id'], 'type') == 'publish') {
                 mc_update_meta($_POST['id'], 'group', mc_magic_in($_POST['group']));
                 if (mc_get_meta($_POST['id'], 'number') && mc_get_page_field($_POST['group'], 'type') == 'pro') {
                     mc_update_meta($_POST['id'], 'buyer_phone', mc_magic_in($_POST['buyer_phone']));
                     mc_update_meta($_POST['id'], 'buyer_address', mc_magic_in($_POST['buyer_address']));
                     mc_update_meta($_POST['id'], 'buyer_city', mc_magic_in($_POST['buyer_city']));
                     mc_update_meta($_POST['id'], 'buyer_province', mc_magic_in($_POST['buyer_province']));
                     mc_update_meta($_POST['id'], 'buyer_name', mc_magic_in($_POST['buyer_name']));
                 }
             }
             if (mc_get_page_field($_POST['id'], 'type') == 'article') {
                 mc_update_meta($_POST['id'], 'fmimg', mc_magic_in(mc_save_img_base64($_POST['fmimg'])));
                 if (I('param.tags')) {
                     mc_delete_meta($_POST['id'], 'tag');
                     $tags = explode(' ', I('param.tags'));
                     foreach ($tags as $tag) {
                         if ($tag) {
                             mc_add_meta($_POST['id'], 'tag', $tag);
                         }
                     }
                 }
                 if ($_POST['term']) {
                     mc_update_meta($_POST['id'], 'term', mc_magic_in($_POST['term']));
                 } else {
                     $this->error('请设置分类!');
                 }
             }
             $page['title'] = mc_magic_in(mc_remove_html($_POST['title'], 'all'));
             $page['content'] = mc_magic_in(mc_remove_html(mc_str_replace_base64($_POST['content'])));
             M('page')->where("id='" . $_POST['id'] . "'")->save($page);
             if (mc_get_page_field($_POST['id'], 'type') == 'pro') {
                 $this->success('编辑成功', U('control/index/pro_index'));
             } elseif (mc_get_page_field($_POST['id'], 'type') == 'publish' || mc_get_page_field($_POST['id'], 'type') == 'pending') {
                 $this->success('编辑成功', U('post/index/single?id=' . $_POST['id']));
             } elseif (mc_get_page_field($_POST['id'], 'type') == 'group') {
                 $this->success('编辑成功', U('post/group/index?id=' . $_POST['id']));
             } elseif (mc_get_page_field($_POST['id'], 'type') == 'article') {
                 $this->success('编辑成功', U('control/index/article_index'));
             } elseif (mc_get_page_field($_POST['id'], 'type') == 'topic') {
                 $page['content'] = mc_magic_in(mc_str_replace_base64($_POST['content']));
                 M('page')->where("id='" . $_POST['id'] . "'")->save($page);
                 $this->success('编辑成功', U('control/index/topic_index'));
             } else {
                 $this->error('未知的Page类型', U('home/index/index'));
             }
         } else {
             $this->error('请完整填写信息!');
         }
     } else {
         $this->error('哥们,你放弃治疗了吗?', U('home/index/index'));
     }
 }
 public function publish()
 {
     if (mc_user_id()) {
         if ($_POST['title'] && $_POST['content']) {
             $page['title'] = mc_magic_in($_POST['title']);
             $page['content'] = mc_magic_in(mc_remove_html($_POST['content']));
             if (mc_option('paixu') == 2) {
                 if (mc_is_admin()) {
                     $page['type'] = 'publish';
                 } else {
                     $page['type'] = 'pending';
                 }
             } else {
                 $page['type'] = 'publish';
             }
             $page['date'] = strtotime("now");
             $result = M('page')->data($page)->add();
             if ($result) {
                 mc_add_meta($result, 'author', mc_user_id());
                 if (is_numeric($_POST['group'])) {
                     mc_add_meta($result, 'group', $_POST['group']);
                     mc_update_page(mc_magic_in($_POST['group']), strtotime("now"), 'date');
                     mc_add_meta($result, 'time', strtotime("now"));
                     if (is_numeric($_POST['number'])) {
                         mc_add_meta($result, 'number', $_POST['number']);
                         $parameter = $_POST['parameter'];
                         if ($parameter) {
                             foreach ($parameter as $key => $valp) {
                                 mc_add_meta($result, 'parameter', $key . '|' . $valp);
                             }
                         }
                     }
                 }
                 do_go('publish_post_end', $result);
                 $this->success('发布成功,请耐心等待审核', U('post/index/single?id=' . $result));
             } else {
                 $this->error('发布失败!');
             }
         } else {
             $this->error('请填写标题和内容');
         }
     } else {
         $this->error('哥们,你放弃治疗了吗?', U('home/index/index'));
     }
 }
 public function edit($id = false)
 {
     if (!is_numeric($id)) {
         $id = mc_user_id();
     }
     if (is_numeric($id)) {
         if (mc_user_id() == $id) {
             if (mc_remove_html($_POST['title'], 'all')) {
                 $title = M('page')->where("title='" . mc_magic_in(mc_remove_html($_POST['title'], 'all')) . "' AND type ='user'")->getField('id');
                 if (is_numeric($title) && $title != $id) {
                     $this->error('昵称已存在!');
                 } else {
                     mc_update_page(mc_user_id(), mc_magic_in(mc_remove_html($_POST['title'], 'all')), 'title');
                 }
                 if ($_POST['content']) {
                     mc_update_page(mc_user_id(), mc_magic_in(mc_remove_html($_POST['content'], 'all')), 'content');
                 }
                 if ($_POST['user_avatar']) {
                     if (mc_get_meta(mc_user_id(), 'user_avatar', true, 'user')) {
                         mc_update_meta(mc_user_id(), 'user_avatar', mc_magic_in(mc_save_img_base64($_POST['user_avatar'], 1, 120, 120)), 'user');
                     } else {
                         mc_add_meta(mc_user_id(), 'user_avatar', mc_magic_in(mc_save_img_base64($_POST['user_avatar'], 1, 120, 120)), 'user');
                     }
                 }
                 if ($_POST['fmimg']) {
                     mc_delete_meta($id, 'fmimg', 'basic');
                     mc_add_meta($id, 'fmimg', mc_magic_in(mc_save_img_base64($_POST['fmimg'])));
                 }
                 mc_delete_meta($id, 'buyer_name', 'user');
                 if ($_POST['buyer_name']) {
                     mc_add_meta($id, 'buyer_name', mc_magic_in($_POST['buyer_name']), 'user');
                 }
                 mc_delete_meta($id, 'buyer_province', 'user');
                 if ($_POST['buyer_province']) {
                     mc_add_meta($id, 'buyer_province', mc_magic_in($_POST['buyer_province']), 'user');
                 }
                 mc_delete_meta($id, 'buyer_city', 'user');
                 if ($_POST['buyer_city']) {
                     mc_add_meta($id, 'buyer_city', mc_magic_in($_POST['buyer_city']), 'user');
                 }
                 mc_delete_meta($id, 'buyer_address', 'user');
                 if ($_POST['buyer_address']) {
                     mc_add_meta($id, 'buyer_address', mc_magic_in($_POST['buyer_address']), 'user');
                 }
                 mc_delete_meta($id, 'buyer_phone', 'user');
                 if ($_POST['buyer_phone']) {
                     mc_add_meta($id, 'buyer_phone', mc_magic_in($_POST['buyer_phone']), 'user');
                 }
                 $user_email_now = mc_get_meta(mc_user_id(), 'user_email', true, 'user');
                 if ($_POST['user_email'] != $user_email_now) {
                     $user_email = M('meta')->where("meta_key='user_email' AND type ='user'")->getField('meta_value', true);
                     if (in_array(strip_tags($_POST['user_email']), $user_email)) {
                         $this->error('邮箱已存在!');
                     } else {
                         mc_update_meta(mc_user_id(), 'user_email', mc_magic_in($_POST['user_email']), 'user');
                     }
                 } elseif ($_POST['user_email'] == '') {
                     $this->error('邮箱必须填写!');
                 } else {
                     mc_update_meta(mc_user_id(), 'user_email', mc_magic_in($_POST['user_email']), 'user');
                 }
                 if (I('param.pass')) {
                     if (I('param.pass2') == I('param.pass')) {
                         mc_update_meta(mc_user_id(), 'user_pass', md5(I('param.pass') . mc_option('site_key')), 'user');
                         $this->success('修改密码成功,请使用新密码登陆', U('User/login/index'));
                     } else {
                         $this->error('两次密码必须填写一致!');
                     }
                 } else {
                     $this->success('更新资料成功', U('User/index/edit?id=' . $id));
                 }
             } else {
                 $this->theme(mc_option('theme'))->display('User/edit');
             }
         } else {
             $this->error('禁止访问!');
         }
     } else {
         $this->error('参数错误!', U('User/login/index'));
     }
 }