/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(UserRequest $request, Article $article) { $input = $request->all(); $article->update(['title' => $input['titolo'], 'text' => $input['Descrizione']]); if ($request->ajax() || $request->wantsJson()) { return new JsonResponse($user); } flash()->success('aggiornato con successo!'); return redirect('article'); }
public function update(&$data) { if (parent::update($data)) { if (!self::same_txt($this->price, $data['price'])) { $this->insertItem(PRICE, preg_replace('/\\D/', '', $data['price'])); } if ($this->pub_on > 0) { $this->get($this->id, false); $this->updateSearch(); Cache::set($this->id, $this); Cache::regflush($this->folder->path); } return true; } return false; }
public function update(&$data) { if (parent::update($data)) { foreach ($this->options as $k => &$v) { $i = 'opt' . $k; if (isset($data[$i])) { if ($data[$i] && $data[$i] != $v) { $this->updateOption($k, $data[$i]); } } else { $this->delOption($k); } } foreach ($data['opt'] as &$opt) { if ($opt) { $this->insertOption($opt); } } return true; } return false; }
public function update(&$data) { if (parent::update($data)) { if (!self::same_txt($this->question, $data['question'])) { $this->insertItem(QUESTION, $data['question']); } if (!self::same_txt($this->alias, $data['alias'])) { $this->insertItem(ALIAS, $data['alias']); } if (!self::same_txt($this->answer, $data['answer'])) { $this->insertItem(ANSWER, $data['answer']); $this->setFlag(FLAG_HAVE_ANSWER); } if ($this->pub_on > 0) { $this->get($this->id, false); $this->updateSearch(); Cache::set($this->id, $this); Cache::regflush($this->folder->path); } return true; } return false; }
/** * 发布一篇文章 * * @param array $article 文件内容 * @param int $publish 是否真正发布(如果为否,则仅为预览,输出至Buffer中) * * @return array */ public static function article(array $article, $publish = true) { \Model\User::validateAuth($article['uid']); $path = sprintf('article/%u.html', $article['id']); $message = sprintf('update article %u [%s]', $article['id'], date('Y-m-d H:i:s')); $blog = Blog::show(); $category = Category::show($article['category_id']); $now = time(); $publish_time = date('Y-m-d H:i:s', $now); $tpl_vars = array('blog' => $blog, 'category' => $category, 'article' => $article, 'publish' => $publish, 'publish_date' => date('Y-m-d', $now)); $smarty = \Comm\Smarty::init(); if ($publish) { $content = $smarty->render('tpl:article', $tpl_vars); $result = self::publishUserRespos($path, $content, $message); //发布成功,更新发布时间与发布状态 try { Article::update($article, ['state' => 1, 'publish_time' => $publish_time]); } catch (\Exception $e) { } } else { $result = $smarty->display('tpl:article', $tpl_vars); } return $result; }
public function post($post_id) { $this->model('User'); $this->model('Article'); $user = new User(); $article = new Article(); $this->loginRequired($user); // If new post is to be created if (empty($post_id) || $post_id == 'new') { if (Input::exists()) { $validate = new Validate(); // Validation for Inputs $validation = $validate->check($_POST, array('title' => array('name' => 'Post title', 'required' => true, 'min' => 5), 'description' => array('name' => 'description', 'required' => true, 'min' => 50), 'featuredimage' => array('name' => 'Featured Image', 'required' => true), 'link' => array('name' => 'Article Link', 'required' => true, 'unique' => ARTICLE_TABLE))); if (empty(Input::get('type'))) { $type = 0; } else { $type = 1; } if ($validate->passed()) { $template = Strings::get('catagory'); try { $article->create(array('TITLE' => Input::get('title'), 'SECURL' => Input::get('catagory'), 'SUBSEC' => Input::get('subsec'), 'CREATED_DATE' => date("Y-m-d H:i:s", time()), 'IMG' => Input::get('featuredimage'), 'DES' => Input::get('description'), 'LINK' => Input::get('link'), 'TYPE' => $type, 'TEMPLATE' => Input::get('template'))); // Get the created article details from LINK to redirect the user to edit it. $newarticle = new Article(Input::get('link')); Redirect::to(ADMINPATH . 'post/' . $newarticle->data()->SL_NO); } catch (Exception $e) { die($e->getMessage()); } if (isset($data)) { $submissionData = Input::values($_POST); $data = array_merge($data, $submissionData); } else { $data = Input::values($_POST); } } else { $data = $validate->errors(); } } if (isset($data)) { $submissionData = Input::values($_POST); $data = array_merge($data, $submissionData); } else { $data = Input::values($_POST); } $data['CATAGORY'] = Strings::get('catagory'); $data['SUBCATAGORY'] = Strings::get('subcatagory'); $data['TEMPLATES'] = Strings::get('templates'); $data['token'] = Token::generate(); $data['TITLE'] = "Create New Post"; $this->view('admin/post.new.html', $data); } else { /** * Edit Post section * * The edit and after creation events happen here */ $article = new Article($post_id); if (Input::exists()) { $validate = new Validate(); // Validation for Inputs $validation = $validate->check($_POST, array('title' => array('name' => 'Post title', 'required' => true, 'min' => 5), 'description' => array('name' => 'description', 'required' => true, 'min' => 50), 'featuredimage' => array('name' => 'Featured Image', 'required' => true))); // If Article URL is changed check if it already exist if ($validate->passed() && $article->data()->LINK != Input::get('link')) { $validation = $validate->check($_POST, array('link' => array('name' => 'Article Link', 'required' => true, 'unique' => ARTICLE_TABLE))); } if (empty(Input::get('type'))) { $type = 0; } else { $type = 1; } if (empty(Input::get('featured'))) { $featured = 0; } else { $featured = 1; } if (Input::get('publish') == 1) { $publish = $article->data()->STATUS ? 0 : 1; } else { $publish = $article->data()->STATUS; } if ($validation) { $template = Strings::get('catagory'); try { $article->update(array('TITLE' => Input::get('title'), 'SECURL' => Input::get('catagory'), 'SUBSEC' => Input::get('subsec'), 'CONTENT' => Input::get('content'), 'DATE' => Input::get('date'), 'IMG' => Input::get('featuredimage'), 'DES' => Input::get('description'), 'LINK' => Input::get('link'), 'TYPE' => $type, 'TEMPLATE' => Input::get('template'), 'FEATURED' => $featured, 'STATUS' => $publish), $post_id); Redirect::to(ADMINPATH . 'post/' . $post_id); } catch (Exception $e) { die($e->getMessage()); } if (isset($data)) { $submissionData = Input::values($_POST); $data = array_merge($data, $submissionData); } else { $data = Input::values($_POST); } } else { $data = $validate->errors(); } } if ($article->count()) { if (isset($data)) { $data = array_merge($data, objectToArray($article->data())); } else { $data = objectToArray($article->data()); } $data['CATAGORY'] = Strings::get('catagory'); $data['SUBCATAGORY'] = Strings::get('subcatagory'); $data['TEMPLATES'] = Strings::get('templates'); $data['CONTENT_RAW'] = $data['CONTENT']; $data['CONTENT'] = str_replace('[IMAGE]', MEDIAPATH, $data['CONTENT']); $data['CONTENT'] = $data['CONTENT']; $data['token'] = Token::generate(); $this->view('admin/post.html', $data); } } }