示例#1
0
function node_controller()
{
    require "Modules/node/node_model.php";
    global $session, $route;
    $output['content'] = "";
    $output['message'] = "";
    if ($route['action'] == 'create' && $session['write']) {
        $nodeid = create_node($session['userid'], "(new)", "");
        $output['message'] = "Node created";
    }
    if ($route['action'] == 'list' && $session['read']) {
        $list = get_node_list($session['userid']);
        $output['content'] = view('node/node_list.php', array('list' => $list));
    }
    if ($route['action'] == 'edit' && $session['write']) {
        $nodeid = intval($_GET['id']);
        $title = get_node_title($nodeid);
        $content = get_node_content($nodeid);
        $output['content'] = view('node/node_edit.php', array('id' => $nodeid, 'title' => $title, 'content' => $content));
    }
    if ($route['action'] == 'save' && $session['write']) {
        $nodeid = intval($_POST['id']);
        $title = $_POST['title'];
        $content = $_POST['content'];
        $content = db_real_escape_string($content);
        set_node_title($nodeid, $title);
        set_node_content($nodeid, $content);
        $output['message'] = "Node saved";
    }
    if ($route['action'] == 'view') {
        $nodeid = intval($_GET['id']);
        $title = get_node_title($nodeid);
        $content = get_node_content($nodeid);
        include_once "Modules/node/markdown/markdown.php";
        $content = Markdown($content);
        $output['content'] = view('node/node_view.php', array('title' => $title, 'content' => $content));
    }
    if ($route['action'] == 'delete' && $session['write']) {
        $nodeid = intval($_GET['id']);
        delete_node($nodeid);
        $output['message'] = "Node deleted";
    }
    return $output;
}
 /**
  * 访问授权页面
  * @author 朱亚杰 <*****@*****.**>
  */
 public function auth($member_group_id = null)
 {
     if (empty($member_group_id)) {
         $this->error('非法访问');
     }
     $this->meta_title = '访问授权->' . get_member_group($member_group_id, 'title');
     if (IS_POST) {
         //处理权限数据
         $model = D('MemberGroup');
         $data = array('member_group_id' => $member_group_id, 'auth' => json_encode(I('post.auth')), 'update_time' => NOW_TIME);
         if ($model->create($data)) {
             $result = $model->save();
             F('membegroupnodelist' . $member_group_id, null);
             if (0 < $result) {
                 $this->success(L('_UPDATE_SUCCESS_'), U('index'));
             } else {
                 $this->error(L('_UPDATE_FAIL_'));
             }
         } else {
             $this->error($model->geterror());
         }
     }
     //分组信息
     $data = get_member_group($member_group_id);
     if (!empty($data['auth'])) {
         $data['auth'] = json_decode($data['auth'], true);
         $data['auth'] = '[' . implode(',', $data['auth']) . ']';
     }
     $this->assign('data', $data);
     $this->assign('_list', get_node_list());
     $this->display('managergroup');
 }