Exemple #1
0
 function deleteAdmin()
 {
     $id = getRequest('id');
     $admin = model('admin');
     if ($admin->del($id)) {
         jsonReturn($this->ajaxFromReturn('删除成功', 200, '', '', 'admin'));
     } else {
         jsonReturn($this->ajaxFromReturn('删除失败', 300));
     }
 }
Exemple #2
0
 public function action_changeSite()
 {
     if ($this->request->is_ajax()) {
         $siteId = intval($this->request->post('siteId'));
         $this->siteId = $siteId;
         Session::instance()->set('siteId', $siteId);
         jsonReturn(1001);
     } else {
         $this->request->detect_uri(404);
     }
 }
Exemple #3
0
 public function action_set()
 {
     $modelCategory = ORM::factory('Category');
     if ($this->request->is_ajax()) {
         $post = $this->request->post();
         $post['status'] = isset($post['status']) && $post['status'] == 'on' ? 1 : 0;
         switch ($post['action']) {
             case 'add':
                 $modelCategory->set('pid', $post['pid'])->set('sid', $this->siteId)->set('name', $post['name'])->set('description', $post['description'])->set('types', $post['types'])->set('uri', $post['uri'])->set('orders', $post['orders'])->set('status', $post['status'])->set('created', time())->set('updated', time())->save();
                 jsonReturn(1001);
                 break;
             case 'edit':
                 $modelCategory->where('id', '=', $post['id'])->where('sid', '=', $this->siteId)->find();
                 if ($modelCategory->loaded()) {
                     $modelCategory->set('pid', $post['pid'])->set('name', $post['name'])->set('description', $post['description'])->set('types', $post['types'])->set('uri', $post['uri'])->set('orders', $post['orders'])->set('status', $post['status'])->set('updated', time())->save();
                     jsonReturn(1001);
                 } else {
                     jsonReturn(4444, '在您网站下没有找到此栏目');
                 }
                 break;
             case 'del':
                 $modelCategory->where('id', '=', $post['id'])->where('sid', '=', $this->siteId)->delete();
                 jsonReturn(1001);
                 break;
             default:
                 break;
         }
     } else {
         $this->template = 'category/set';
         $data = array('category' => $modelCategory->getAll($this->siteId), 'types' => $modelCategory->getTypes());
         $id = $this->request->query('id');
         if (!empty($id)) {
             $data['action'] = 'edit';
             $data['id'] = $id;
             $data['cateInfo'] = $modelCategory->where('id', '=', $id)->find();
         } else {
             $data['action'] = 'add';
             $data['id'] = '';
             $cateInfo = array('id' => '', 'pid' => 0, 'name' => '', 'description' => '', 'types' => 0, 'uri' => '', 'orders' => 0, 'status' => FALSE);
             $data['cateInfo'] = json_decode(json_encode($cateInfo));
         }
         $this->data = $data;
         //			print_r($this->data);
     }
 }
Exemple #4
0
 public function action_index()
 {
     if ($this->request->is_ajax()) {
         $data = $this->request->post();
         $action = $data['action'];
         $content = ORM::factory('Content');
         switch ($action) {
             case 'getList':
                 $cid = $data['cid'];
                 $list = $content->getAll($cid, $this->siteId);
                 jsonReturn(1001, '成功', $list);
                 break;
             case 'getDetail':
                 $id = $data['id'];
                 $detail = $content->where('id', '=', $id)->where('sid', '=', $this->siteId)->find();
                 if ($detail->loaded()) {
                     $detail = $detail->as_array();
                     $detail['created'] = date('Y-m-d H:i:s', $detail['created']);
                     $detail['updated'] = date('Y-m-d H:i:s', $detail['updated']);
                     jsonReturn(1001, '成功', $detail);
                 } else {
                     jsonReturn(4444, '文章未找到');
                 }
                 break;
             case 'updateDetail':
                 $id = $data['id'];
                 $detail = $content->where('id', '=', $id)->where('sid', '=', $this->siteId)->find();
                 if ($detail->loaded()) {
                     $detail->set('title', $data['title'])->set('keywords', $data['keywords'])->set('description', mb_substr($data['content'], 0, 150))->set('origin', $data['origin'])->set('cid', $data['cid'])->set('updated', strtotime($data['updated']))->set('created', strtotime($data['created']))->set('content', $data['content'])->save();
                     jsonReturn(1001, '保存成功');
                 } else {
                     jsonReturn(4444, '保存失败');
                 }
                 break;
             default:
                 jsonReturn(4444, '错误');
                 break;
         }
     } else {
         $this->template = 'content/index';
         $category = ORM::factory('Category')->getAll($this->siteId);
         $this->data = array('category' => $category);
     }
 }
Exemple #5
0
 public function action_step1()
 {
     if ($this->request->is_ajax()) {
         $post = $this->request->post();
         $site = ORM::factory('Site');
         $site->uid = $this->user['id'];
         $site->name = $post['name'];
         $site->title = $post['title'];
         $site->description = $post['description'];
         $site->keywords = $post['keywords'];
         $site->created = time();
         $site->updated = time();
         $site->save();
         jsonReturn(1001, '创建成功', '/manage/dashboard/index');
     }
     $this->template = 'step1';
     $modules = ORM::factory('Module')->getAll();
     $this->data = array('modules' => $modules);
 }
Exemple #6
0
 public function action_upload()
 {
     $md5 = md5($_FILES['image']['tmp_name']);
     $file = $md5 . '_' . time() . '.' . pathinfo($_FILES['image']['name'])['extension'];
     $fileValidation = new Validation($_FILES);
     $fileValidation->rule('image', 'upload::valid');
     $fileValidation->rule('image', 'upload::type', array(':value', array('jpg', 'png')));
     if ($fileValidation->check()) {
         if ($path = Upload::save($_FILES['image'], $file, DIR_IMAGE)) {
             ORM::factory('File')->set('sid', $this->siteId)->set('name', $_FILES['image']['name'])->set('path', $file)->set('md5', $md5)->set('types', Model_File::FILE_TYPES_IMG)->set('created', time())->set('updated', time())->save();
             $site = ORM::factory('Site')->where('id', '=', $this->siteId)->where('uid', '=', $this->user['id'])->find();
             $site->set('logo', $file)->set('updated', time())->save();
             jsonReturn(1001, '上传成功!', '/media/image/data/' . $file);
         } else {
             jsonReturn(4444, '图片保存失败');
         }
     } else {
         jsonReturn(4444, '图片上传失败');
     }
 }
Exemple #7
0
 /**
  * 如果没有验证, 返回错误代码
  */
 public function ajax_user_auth()
 {
     if (!is_auth()) {
         jsonReturn(1022);
         //未登录
         exit;
     }
     return true;
 }
Exemple #8
0
 public function action_subscribe()
 {
     $email = $this->request->post('email');
     if (filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) {
         jsonReturn(4444, '请输入正确的邮箱!');
     }
     $find = ORM::factory('Subscribe')->where('sid', '=', $this->siteId)->where('email', '=', $email)->find();
     if ($find->loaded()) {
         jsonReturn(1001, '您已经订阅过!');
     } else {
         ORM::factory('Subscribe')->set('sid', $this->siteId)->set('email', $email)->set('status', 1)->set('created', time())->set('updated', time())->save();
         jsonReturn(1001, '订阅成功!');
     }
 }
Exemple #9
0
function checkLogin()
{
    jsonStart();
    logAction('checkLogin', $_SESSION['user']);
    if (isset($_SESSION['userid'])) {
        jsonAdd("\"login\": \"true\",\"name\": \"{$_SESSION['name']}\"");
    } else {
        jsonAdd("\"login\": \"false\"");
    }
    echo jsonReturn('userLogin');
}
Exemple #10
0
function update_locally()
{
    global $xoopsSecurity, $xoopsLogger, $xoopsConfig;
    $xoopsLogger->activated = false;
    if (!$xoopsSecurity->check()) {
        jsonReturn(__('Wrong action!', 'rmcommon'), 1, array(), 0);
    }
    $dir = RMHttpRequest::post('module', 'string', '');
    $type = RMHttpRequest::post('type', 'string', '');
    if ('' == $dir || '' == $type) {
        jsonReturn(__('Data not valid!', 'rmcommon'));
    }
    if ('module' == $type) {
        if (!is_dir(XOOPS_ROOT_PATH . '/modules/' . $dir)) {
            jsonReturn(__('Module does not exists!', 'rmcommon'));
        }
        xoops_loadLanguage('admin', 'system');
        $file = XOOPS_ROOT_PATH . '/modules/system/language/' . $xoopsConfig['language'] . '/admin/modulesadmin.php';
        if (file_exists($file)) {
            include_once $file;
        } else {
            include_once str_replace($xoopsConfig['language'], 'english', $file);
        }
        include_once XOOPS_ROOT_PATH . '/modules/system/admin/modulesadmin/modulesadmin.php';
        $log = xoops_module_update($dir);
        jsonReturn(__('Module updated locally', 'rmcommon'), 0, array('log' => $log));
    } elseif ('plugin' == $type) {
        if (!is_dir(XOOPS_ROOT_PATH . '/modules/rmcommon/plugins/' . $dir)) {
            jsonReturn(__('Plugin does not exists!', 'rmcommon'));
        }
        $plugin = new RMPlugin($dir);
        if ($plugin->isNew()) {
            jsonReturn(__('Plugin does not exists!', 'rmcommon'));
        }
        if (!$plugin->on_update()) {
            jsonReturn(sprintf(__('Plugins manager could not update the plugin: %s', 'rmcommon'), $plugin->errors()));
        }
        jsonReturn(__('Plugin updated locally', 'rmcommon'), 0);
    }
}
Exemple #11
0
function uploadSmart()
{
    global $uploadDir;
    if (!file_exists($uploadDir . "stats_" . session_id() . ".txt")) {
        jsonStart();
        jsonAdd("\"percent\": 0, \"percentSec\": 0, \"speed\": \"0\", \"secondsLeft\": \"0\", \"done\": \"false\"");
        echo jsonReturn("bindings");
        exit;
    }
    $lines = file($uploadDir . "stats_" . session_id() . ".txt");
    jsonStart();
    $percent = round($lines[0] / 100, 3);
    $percentSec = round($lines[1] / 100, 4);
    $speed = filesize_format($lines[2]) . 's';
    $secondsLeft = secs_to_string(round($lines[3]));
    $size = filesize_format($lines[4]) . 's';
    if ($percent == 1) {
        // cleanup time
        if (isset($_SESSION['uploadPath'])) {
            $path = $_SESSION['uploadPath'];
            $userpath = getUserPath($path) . $path;
            $sessionid = session_id();
            $dh = opendir($uploadDir);
            while (($file = readdir($dh)) !== false) {
                $sessionlen = strlen(session_id());
                if (substr($file, 0, $sessionlen) == session_id()) {
                    $filename = substr($file, $sessionlen + 1);
                    $uploadfile = $filename;
                    $i = 1;
                    while (file_exists($userpath . '/' . $uploadfile)) {
                        $uploadfile = $i . '_' . $filename;
                        $i++;
                    }
                    if (file_exists("{$uploadDir}{$file}") && !rename("{$uploadDir}{$file}", "{$userpath}/{$uploadfile}")) {
                        echo "Error";
                    }
                }
            }
            closedir($dh);
            if (file_exists($uploadDir . "stats_" . session_id() . ".txt")) {
                unlink($uploadDir . "stats_" . session_id() . ".txt");
            }
            if (file_exists($uploadDir . "temp_" . session_id())) {
                unlink($uploadDir . "temp_" . session_id());
            }
        }
        $done = "true";
    } else {
        $done = "false";
    }
    jsonAdd("\"percent\": {$percent}, \"size\": \"{$size}\",\"percentSec\": {$percentSec}, \"speed\": \"{$speed}\", \"secondsLeft\": \"{$secondsLeft}\", \"done\": \"{$done}\"");
    echo jsonReturn("bindings");
}
Exemple #12
0
 function test()
 {
     jsonReturn($this->generator->analysisTable("category"));
 }