示例#1
0
 /**
  * 发布
  * @return bool
  */
 public function publishAction()
 {
     if (!$this->getRequest()->isPost()) {
         $this->responseJson(401, '请求方式不正确');
     }
     //$username = $this->getRequest()->getParam('username','');
     //$password = $this->getRequest()->getParam('password','');
     $title = $_POST['title'];
     $content = $_POST['content'];
     if (empty($title) && empty($content)) {
         $this->responseJson(401, '文章title或内容不能为空');
     }
     $article = new ArticleModel();
     $ret = $article->addArticle($title, $content);
     if ($ret[0]) {
         $this->responseJson(200, $ret[1]);
     } else {
         $this->responseJson(401, $ret[1]);
     }
     return false;
 }
示例#2
0
        return Helper::response(false, array(), 'Application error', 500);
    }
    return Helper::response(true, $articles);
});
$app->get('/api-v1.0/article/get/:id/', function ($id) use($app) {
    $article = ArticleModel::getArticle($id);
    if (empty($article)) {
        return Helper::response(false, array(), 'Article not found', 404);
    }
    return Helper::response(true, $article);
});
$app->post('/api-v1.0/article/add/', function () use($app) {
    if (!($account = Helper::checkSecret())) {
        return;
    }
    $artId = ArticleModel::addArticle(array('acc_id' => $account['acc_id'], 'art_title' => $app->request->post('art_title', ''), 'art_body' => $app->request->post('art_body', '')));
    if (empty($artId)) {
        return Helper::response(false, array(), 'Application error', 500);
    }
    return Helper::response(true, array('art_id' => $artId));
});
$app->post('/api-v1.0/article/patch/', function () use($app) {
    if (!($account = Helper::checkSecret())) {
        return;
    }
    $artId = $app->request->post('art_id');
    if (empty($artId)) {
        return Helper::response(false, array(), 'Bad request, art_id required', 400);
    }
    $article = ArticleModel::getArticle($artId);
    if (empty($article)) {
示例#3
0
 public function addArticleSubmit()
 {
     $errors = $this->errors;
     $pdata = $_POST;
     //echo "<pre>";var_dump($pdata['content']);echo "</pre>";exit;
     if (!$pdata['title']) {
         $result['code'] = '038';
         $result['message'] = $errors['038'];
     } elseif (!$pdata['typeId']) {
         $result['code'] = '039';
         $result['message'] = $errors['039'];
     } elseif (!$pdata['content']) {
         $result['code'] = '030';
         $result['message'] = $errors['030'];
     } else {
         //实例化Model
         $articleModel = new ArticleModel();
         if (isset($pdata['content'])) {
             $start = strpos($pdata['content'], '<img');
             $end = strpos($pdata['content'], '/>', $start);
             $img = substr($pdata['content'], $start, $end - $start + 2);
             $preg = '/src="(.*)"[\\s\\n]*\\/>/';
             preg_match($preg, $img, $matche);
             $pdata['picture'] = $matche[1];
         }
         $articleTagModel = new ArticleTagModel();
         if (isset($pdata['tagId']) && $pdata['tagId']) {
             $pdata['tagId'] = array_unique($pdata['tagId']);
             //数组去重
             $tagIds = implode(',', $pdata['tagId']);
             $articleTagModel->setIncByTagIds($tagIds);
             $pdata['tagId'] = ',' . implode(',', $pdata['tagId']) . ',';
         }
         $pdata['adminId'] = $_SESSION['admin']['adminId'];
         $results = $articleModel->addArticle($pdata);
         if ($results) {
             $result['code'] = '0';
             $result['message'] = $errors['0'];
         } else {
             $result['code'] = '034';
             $result['message'] = $errors['034'];
         }
     }
     echo json_encode($result);
     exit;
 }