public static function mm_update() { // Get the RSS feed from Morning Mail $xml = simplexml_load_file('http://morningmail.rpi.edu/rss'); // Begin the transaction Database::beginTransaction(); $count = 0; foreach ($xml->channel->item as $item) { // Check for duplicates (no DB-agnostic way // to ignore duplicate errors) if (self::find($item->link)) { continue; } // Parse data and construct Article objects, // save them to the DB $date = date_create($item->pubDate); $a = new Article($item->title, strip_tags($item->description), $date->format('Y-m-d H:i:s'), $item->link); // Increment row count $count++; if (!$a->save()) { Database::rollBack(); return false; } } // Commit transaction Database::commit(); return $count; }
function restore() { $article = new Article($this->dbcon, $this->getArticleId()); $article->saveVersion(); $article->readVersion($this->id); return $article->save(); }
/** * Store a newly created resource in storage. * POST /articles * * @return Response */ public function store() { $rules = Article::$rules; $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { $messages = $validator->messages(); // return Response::json(['error' => $messages], 400); } $image = Input::file('file'); if (!$image) { return Response::json(['error' => $messages], 400); } else { $admin = Auth::admin(); $article = new Article(); $article->admin_id = Auth::admin()->get()->id; $article->title = Input::get('title'); $article->body = Input::get('body'); $article->category_id = Input::get('category_id'); $article->save(); $thumb = new Photo(); $filename = time() . '-' . $image->getClientOriginalName(); $destinationPath = public_path('thumbs/' . $filename); $a = Image::make($image->getRealPath())->fit(1280, 720)->save($destinationPath, 50); // SAVE TO DB $thumb->image = 'thumbs/' . $filename; $thumb->article_id = $article->id; $thumb->save(); } }
/** * 文章添加 */ public function actionCreate() { $model = new Article(); $addonarticle = new Addonarticle(); if (isset($_POST['Article'])) { $transaction = Yii::app()->db->beginTransaction(); try { $model->attributes = $_POST['Article']; if (!$model->save()) { Tool::logger('article', var_export($model->getErrors(), true)); throw new CException('文章生成失败'); } $aid = $model->primaryKey; $addonarticle->attributes = $_POST['Addonarticle']; if (!$addonarticle->save()) { Tool::logger('article', var_export($addonarticle->getErrors(), true)); throw new CException('文章附表生成失败'); } $this->redirect(array('list')); } catch (Exception $e) { Tool::logger('article', $e->getMessage()); $transaction->rollback(); } } $this->render('create', array('model' => $model, 'addonarticle' => $addonarticle)); }
public function actionCreate() { $author = $this->_checkAuth(); $json = file_get_contents('php://input'); $data = CJSON::decode($json, true); switch ($_GET['model']) { case 'articles': $model = new Article(); break; default: Helper::renderJSONErorr('create is not implemented for model ' . $_GET['model']); } foreach ($data as $var => $value) { if ($model->hasAttribute($var)) { $model->{$var} = $value; } else { Helper::renderJSONErorr("Parameter {$var} is not allowed for model " . $_GET['model']); } } if ($model->hasAttribute('author')) { $model->author = $author->id; } // Try to save the model if ($model->save()) { Helper::renderJSON($model); } $msg = sprintf("Couldn't create model %s\n", $_GET['model']); foreach ($model->errors as $attribute => $attr_errors) { $msg .= "Attribute: {$attribute}\n"; foreach ($attr_errors as $attr_error) { $msg .= "- {$attr_error}\n"; } } Helper::renderJSONErorr($msg); }
public function create() { $article = new Article(); if ($this->post) { $article->title = $this->PostData('title'); $article->permalink = $this->PostData('permalink'); $article->summary = $this->PostData('summary'); $article->published = $this->PostData('published'); if ($this->PostData('publish_now') == 1) { $article->publish_at = time(); } else { $article->set_publish_at($this->PostData('publish_at')); } $article->user_id = Site::CurrentUser()->id; if ($article->save()) { $page = new ArticlePage(); $page->article_id = $article->id; $page->title = $article->title; $page->content = $this->PostData('fullbody'); $page->save(); Site::Flash("notice", "The article has been added"); Redirect("admin/articles/{$article->id}"); } $this->assign("body", $this->PostData('fullbody')); } $this->assign("article", $article); $this->tinymce = true; $this->title = "Add Article"; $this->render("article/create.tpl"); }
function backproject() { $this->load->model("common"); $old_news = $this->common->getall('mf_project'); $newscatalogue = new Newscatalogue(21); foreach ($old_news as $row) { $news = $this->common->getdetaildata('mf_node', array('id' => $row->nid)); $article = new Article(); $article->title_vietnamese = $news->title; $article->title_none = $news->title_seo; $article->full_vietnamese = str_replace('src="/', 'src="', $news->content); $article->short_vietnamese = $news->description; $article->tag = $news->title; $article->old_id = 1; $article->dir = ""; $article->active = 1; $article->image = substr($news->img_url, 1, strlen($news->img_url) - 1); if (!$article->save($newscatalogue)) { foreach ($article->error->all as $error) { echo "<br>" . $error; } } $article->clear(); } }
public function addAction() { if ($this->request->isPost() == true) { $ans = []; try { $title = $this->request->getPost("title"); $date = $this->request->getPost("date"); $body = $this->request->getPost("body"); $section = $this->request->getPost("section"); $existArticle = Article::find(array("conditions" => "title=?1", "bind" => array(1 => $title))); if (count($existArticle) == 0) { $article = new Article(); $article->title = $title; $article->date = $date; $article->body = ${$body}; $article->section = $section; if ($article->save()) { $ans['ret'] = $article->id; echo json_encode($ans); } else { foreach ($article->getMessages() as $message) { throw new BaseException($message, 100); } } } else { $ans['ret'] = -1; $ans['error'] = 201; echo json_encode($ans); throw new BaseException('同名文章已存在', 201); } } catch (BaseException $e) { } } }
function article_create() { $this->load->library('form_validation'); $this->form_validation->set_rules('title', 'Titel', 'required|callback_article_unique_title'); $this->form_validation->set_rules('intro', 'Einführungstext', 'required'); $this->form_validation->set_rules('category[]', 'Kategorie', 'required'); $this->form_validation->set_rules('body', 'Text', 'required'); if ($this->form_validation->run() == TRUE) { $articlecategories = new Articlecategory(); $articlecategories->where_in('id', $this->input->post('category'))->get(); $article = new Article(); $article->title = $this->input->post('title'); $article->alias = $this->_title_to_alias($article->title); $article->intro = $this->input->post('intro'); $article->body = $this->input->post('body'); $article->state = 1; $article->save($articlecategories->all); redirect('artikel'); } else { $articlecategories = new Articlecategory(); $this->template->set('res_articlecategories', $articlecategories->get()); $this->template->set_block('sidebar', 'content/articles/_sidebar_create'); $this->template->set('page_name', 'Artikel schreiben'); $this->template->current_view = 'content/articles/create'; $this->template->render(); } }
public function postAdd() { $rules = array('title' => 'required|min:4', 'link' => "required|unique:articles", 'description' => 'required|min:20|max:500', 'content' => 'required|min:100', 'published_at' => 'required', 'meta_keywords' => 'required', 'parameters' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { $parameters = json_decode(Input::get('parameters')); return Redirect::to("admin/article/add")->with('uploadfile', isset($parameters->name) ? $parameters->name : '')->withErrors($validator)->withInput(Input::except('')); } $table = new Article(); $table->title = Input::get('title'); $table->link = Input::get('link'); $table->user_id = Auth::user()->id; $table->description = Input::get('description'); $table->content = Input::get('content'); $table->meta_title = Input::get('meta_title') ? Input::get('meta_title') : $table->title; $table->meta_description = Input::get('meta_description') ? Input::get('meta_description') : $table->description; $table->meta_keywords = Input::get('meta_keywords'); $table->published_at = Article::toDate(Input::get('published_at')); $table->active = Input::get('active', 0); if ($table->save()) { if (Input::get('parameters')) { $parameters = json_decode(Input::get('parameters')); $img = Image::make($parameters->name); $img->crop($parameters->w, $parameters->h, $parameters->x, $parameters->y); $img->resize(320, 240); $img->save("uploads/images/articles/{$table->id}.jpg"); File::delete($parameters->tmp); $img->resize(200, 150); $img->save("uploads/images/articles/{$table->id}_small.jpg"); } $name = trans("name.article"); return Redirect::to("admin/article")->with('success', trans("message.add", ['name' => $name])); } return Redirect::to("admin/article")->with('error', trans('message.error')); }
public function actionRandomArticle() { $n = rand(0, 1000); $article = new Article(); $article->title = "Title #" . $n; $article->text = "Text #" . $n; $article->save(); Yii::app()->setGlobalState('article', $article->id); echo "OK"; }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { //TODO: should move this to service ( use ioc) $article = new Article(); $article->title = Input::get('title'); $article->body = Input::get('body'); $article->published_at = Carbon::now(); $article->save(); return Response::make(['id' => $article->id], 201); }
public function testAdminUser() { $user = User::create(array('username' => 'testuser')); $user->save(); $group = Group::create(array('name' => 'An admin group', 'is_admin' => true)); $user->groups()->attach($group->id); $article = new Article(); $article->body = 'can you access this?'; $article->save(); $this->assertTrue($this->redoubt->userCan('edit', $article, $user)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Article(); $model->attributes = $_POST['Article']; if (isset($_POST['Article'])) { if ($model->save()) { $this->redirect(array('admin')); } } $this->render('create', array('model' => $model)); }
public function post_or_edit($id = null) { parent::load('model', 'articles'); parent::load('model', 'system/contrib/auth'); $smarty = parent::load('smarty'); $categories = Category::get_select(User::info()); if (!$categories) { $smarty->display('403'); Boot::shutdown(); } if ($id) { $article = ArticleTable::getInstance()->find($id); $has_role = Category::has_role($article->Category->id, User::info()); if ((!$has_role || $article->author != User::info('id')) && !User::has_role('人力资源') && !User::has_role('总经理')) { $this->smarty->display(403); Boot::shutdown(); } if (!$article) { $smarty->display('404'); Boot::shutdown(); } $article->content = stripslashes($article->content); $smarty->assign('article', $article); $smarty->assign('selected_category', $article->category_id); $smarty->assign('page_title', '修改文章'); } else { if ($_GET['category']) { $smarty->assign('selected_category', $_GET['category']); } $article = new Article(); $smarty->assign('page_title', '添加新文章'); } if ($this->is_post()) { $category = Category::has_role($_POST['category_id'], User::info()); if (!$category) { $smarty->display('403'); Boot::shutdown(); } $article->name = trim(strip_tags($_POST['name'])); $article->content = $_POST['content']; $article->Category = $category; $search = array('/', ' ', '?', '&'); $replace = array('_', '-', '.', '-'); $article->alias = str_replace($search, $replace, strip_tags($_POST['alias'])); $article->author = User::info('id'); $article->save(); import('system/share/network/redirect'); $act = $id ? '编辑' : '添加新的'; HTTPRedirect::flash_to('articles/detail/' . $article->id, sprintf('%s %s 成功', $act, $category->name), $smarty); } else { $smarty->assign('categories', $categories); $smarty->display('article/add'); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Article(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model);if (isset($_POST['Article'])) { $model->attributes = $_POST['Article']; if ($model->save()) { $this->redirect(array('admin')); } $this->render('create', array('model' => $model)); }
public static function saveArticle($params) { $article = new Article(); if ($article->checkRequiredColumns($params)) { $article->author_id = 1; $article->title = $params['title']; $article->content = $params['content']; $article->img_preview_url = $params['img_preview_url']; $article->save(); } }
public function testIsDirtyFlag() { $conn = m::mock('\\SimpleAR\\Database\\Connection[insert]'); $conn->shouldReceive('insert')->once()->andReturn(12); DB::setConnection($conn); $article = new Article(); $this->assertFalse($article->isDirty()); $article->foo = 'bar'; $this->assertTrue($article->isDirty()); $article->save(); $this->assertFalse($article->isDirty()); }
public function actionCreate() { $model = new Article(); if (isset($_POST['Article'])) { $model->attributes = $_POST['Article']; $model->user_id = Yii::app()->user->id; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function test_multilingual_setting_by_reference() { $Article = new Article(); $Article->set('headline', array('en' => 'New PHP Framework re-released', 'es' => 'Se ha re-liberado un nuevo Framework para PHP')); $Article->set('body', array('en' => 'The Akelos Framework has been re-released...', 'es' => 'Un equipo de programadores españoles ha re-lanzado un entorno de desarrollo para PHP...')); $Article->set('excerpt_limit', array('en' => 7, 'es' => 3)); $this->assertTrue($Article->save()); $Article = $Article->find($Article->getId()); $this->assertEqual($Article->get('en_headline'), 'New PHP Framework re-released'); $this->assertEqual($Article->get('es_body'), 'Un equipo de programadores españoles ha re-lanzado un entorno de desarrollo para PHP...'); $this->assertEqual($Article->get('en_excerpt_limit'), 7); }
public function create($title, $text, $jssor = null, $meta_descr) { $art = new Article(); $art->data['TITLE'] = $title; $art->data['TEXT'] = $text; $art->data['JSSOR'] = $jssor; $art->data['VANITY'] = translateToGreeklish($title); $art->data['METADESCRIPTION'] = $meta_descr; $art->data['LASTUPDATEON'] = KdObject::now(); /**@todo this is unsafe**/ $art->save(); return $art->id; }
function save($id = FALSE) { if ($_POST) { $article = new Article($id); $_POST['title'] = lang_merge($_POST['title']); $_POST['intro'] = lang_merge($_POST['intro']); $_POST['detail'] = lang_merge($_POST['detail']); $_POST['user_id'] = $this->session->userdata('id'); $article->from_array($_POST); $article->save(); set_notify('success', lang('save_data_complete')); } redirect('articles/admin/articles'); }
function index_post() { $post_data = file_get_contents("php://input"); $post_data = json_decode($post_data, true); $article = new Article(); $article->title = $post_data['title']; $article->type = $post_data['type']; $article->body = $post_data['body']; if ($article->save()) { $this->response('Article Saved'); } else { $this->response('Article Not Saved'); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Article(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Article'])) { // $_POST['Article']['pub_time'] = strtotime(str_replace('-', '', $_POST['Article']['pub_time'])); $_POST['Article']['pub_time'] = strtotime($_POST['Article']['pub_time']); $model->attributes = $_POST['Article']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
protected function createFakeArticles() { $faker = Faker::create(); for ($i = 0; $i < 50; $i++) { $random = mt_rand(1, 5); $article = new Article(); $article->title = $faker->catchPhrase(); $article->tagline = $faker->catchPhrase(); $article->summary = $faker->text(125, 2); $article->content = $faker->text(400, 1); $article->user_id = $random; $article->photo = "http://lorempixel.com/240/240/?" . mt_rand(12100, 12299); $article->save(); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Article(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Article'])) { $_POST['Article']['created'] = date('Y-m-d H:i:s'); $_POST['Article']['edited'] = date('Y-m-d H:i:s'); $model->attributes = $_POST['Article']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function actionModify() { $article; if (isset($_GET['id'])) { $article = Article::findById($_GET['id']); } else { $article = new Article(); //fix $article->title = ''; $article->content = ''; $article->img_preview_url = ''; $article->author_id = 1; $article->save(); } $this->view->render('modifyArticle', ['article' => $article], 'admin'); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // try { $article = new Article(); $article->title = Input::get('title'); $article->description = Input::get('description'); $article->category = Input::get('category'); $article->open_at = Input::get('open_at'); $article->status = Input::get('status'); $article->save(); return Redirect::to('admin/articles?category=' . Input::get('category')); } catch (Exception $e) { return Redirect::back()->withInput()->withErrors('新增失敗'); } }
function executeRandomArticle() { $post = new Article(); $arr = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); for ($i = 0; $i < 6; $i = $i + 1) { $index = rand(0, Count($arr)); $title = $title . $arr[$index]; } $post->setTitle($title); for ($i = 0; $i < 30; $i = $i + 1) { $index = rand(0, Count($arr)); $content = $content . $arr[$index]; } $post->setContent($content); $post->save(); $this->redirect('adminblog/index'); }
public function actionAdd() { $articleModel = new Article(); if (isset($_POST['Article']) && !empty($_POST['Article'])) { $articleModel->attributes = $_POST["Article"]; if ($articleModel->save()) { $this->redirect(array('index')); } } $categoryModel = Category::model(); $categoryInfo = $categoryModel->findAll(); $cateArr = array(); $cateArr[] = "请选择"; foreach ($categoryInfo as $v) { $cateArr[$v->cid] = $v->cname; } $this->render("add", array('articleModel' => $articleModel, 'cateArr' => $cateArr)); }