public function safeUp() { $this->execute("\n CREATE TABLE IF NOT EXISTS `Articles` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `type` int(11) NOT NULL DEFAULT 0 COMMENT 'Тип статьи, см. Articles',\n `title` text NOT NULL DEFAULT '' COMMENT 'Заголовок',\n `text` text NOT NULL DEFAULT '' COMMENT 'Текст',\n `visible` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Видимость',\n PRIMARY KEY (`id`),\n KEY `type` (`type`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n "); $this->execute("\n CREATE TABLE IF NOT EXISTS `Articles_lang` (\n `l_id` int(11) NOT NULL AUTO_INCREMENT,\n `articleId` int(11) NOT NULL,\n `lang_id` varchar(6) NOT NULL,\n `l_title` text NOT NULL default '',\n `l_text` text NOT NULL default '',\n PRIMARY KEY (`l_id`),\n KEY `menuId` (`articleId`),\n KEY `lang_id` (`lang_id`),\n CONSTRAINT `fk_articles_lang` FOREIGN KEY (`articleId`) REFERENCES `Articles` (`id`) ON DELETE CASCADE ON UPDATE CASCADE\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n "); $article = new Articles(); $article->multilang(); $attr = array_merge($this->createLangData('title', 'В разработке', 'content'), $this->createLangData('text', 'Раздел находится в разработке', 'content'), array('type' => Articles::TYPE_UNDER_CONSTRUCTION)); $article->setAttributes($attr); $article->save(); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreateArticles() { $model = new Articles(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Articles'])) { $model->attributes = $_POST['Articles']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function actionCreate() { $model = new Articles(); if (isset($_POST['Articles'])) { $model->attributes = $_POST['Articles']; $model->author_id = Yii::app()->user->id; if ($model->validate()) { $model->save(); Yii::app()->user->setFlash('success', Yii::t('main', 'Успішно додано!')); $this->redirect('index'); } } $this->render('update', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Articles(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Articles'])) { $model->attributes = $_POST['Articles']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } else { $model->status = STATUS_ACTIVE; } $this->render('create', array('model' => $model, 'actions' => $this->listActionsCanAccess)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Articles(); Yii::import("xupload.models.XUploadForm"); $files = new XUploadForm(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Articles'])) { $model->attributes = $_POST['Articles']; if ($model->save()) { $this->redirect(array('index')); } } $this->render('create', array('model' => $model, 'files' => $files)); }
/** * Creates a new article */ public function createAction() { if (!$this->request->isPost()) { return $this->dispatcher->forward(array("controller" => "articles", "action" => "index")); } $article = new Articles(); $article->setTitle($this->request->getPost("title")); $article->setCategoryId($this->request->getPost("category_id")); $article->setDescription($this->request->getPost("description")); $article->setImages($this->request->getPost("images")); $article->setStatus($this->request->getPost("status")); if (!$article->save()) { foreach ($article->getMessages() as $message) { $this->flash->error($message); } return $this->dispatcher->forward(array("controller" => "articles", "action" => "new")); } $this->flash->success("article was created successfully"); return $this->dispatcher->forward(array("controller" => "articles", "action" => "index")); }
public function actionCreate() { $model = new Articles(); if (isset($_POST['Articles'])) { $model->attributes = $_POST['Articles']; if ($model->save()) { /* * Save attributes at once * Also can save one at one. Example: TsTranslation::save($model, 'fullText'); * Third parameter of TsTranslation::save() is language * - as default uses TsTranslation::getDtLanguage() returned value: * - $this->widget('tstranslation.widgets.TsLanguageWidget', array( 'dynamicTranslate' => true, )); */ TsTranslation::save($model, array('title', 'introText', 'fullText')); } $this->redirect(array('update', 'id' => $model->id)); } $this->render('create', array('model' => $model)); }
public function articleBatchAdd() { $cus_id = Auth::id(); $ArticleArray = Input::get('ArticleBatch'); $c_id = Input::get('c_id'); $pc_show = Input::get('pc_show'); $mobile_show = Input::get('mobile_show'); foreach ($ArticleArray as $Article) { $article = new Articles(); $article->cus_id = $cus_id; $article->c_id = $c_id; $article->pc_show = $pc_show; $article->mobile_show = $mobile_show; $article->is_top = ' '; $article->is_star = ' '; $article->is_star = ' '; $article->sort = 1000000; $article->title = $Article['title']; $article->img = $Article['img']; $article->pushed = 1; $ret = $article->save(); if (!$ret) { $return_mag = array('err' => 3001, 'msg' => '添加失败'); return Response::json($return_msg); } } $return_msg = array('err' => 0, 'msg' => ''); return Response::json($return_msg); }
/** * Добавление статьи пользователем */ public function actionNew_article() { if (Yii::app()->request->isAjaxRequest) { if (isset($_POST['idMenu'])) { $category1 = array('' => 'Без категории'); $category2 = Categorys::getAllCategories($_POST['idMenu']); $category = $category1 + $category2; $filteredCategory = array(); $i = 0; foreach ($category as $key => $val) { $filteredCategory[$i]['id'] = $key; $filteredCategory[$i]['title'] = $val; $i++; } echo CJSON::encode(array('categorys' => $filteredCategory)); exit; } } // Проверки на доступ к странице if (Yii::app()->user->isGuest) { $this->redirect(Yii::app()->homeUrl); } if (isset($_POST['cancel'])) { $this->redirect(Yii::app()->homeUrl); } $model = new Articles('create'); // Нажата кнопка "Редактировать" или "Добавить" if (isset($_POST['Articles'])) { $oldFile = null; $oldFile = $model->photo; // Генерим имя фото if ('' != $_FILES['Articles']['name']['image']) { $fileName = AuxiliaryFunctions::getUniquNamePhoto($_FILES['Articles']['name']['image']); $_POST['Articles']['photo'] = $fileName; $oldFile = $model->photo; } $model->attributes = $_POST['Articles']; $model->idUser = Yii::app()->user->id; if ($model->validate()) { if ($model->save()) { if ($fileName) { AuxiliaryFunctions::savePhoto($model, $fileName, $oldFile); } if (1 == $model->public && 1 == $model->moderationAppruv) { $this->redirect($this->createAbsoluteUrl('articles/view_article', array('idArticle' => $model->idArticle, 'idMenu' => $model->idMenu))); } $this->redirect($this->createAbsoluteUrl('base/index', array('referrer' => 'new_article'))); } } } $menus = Mainmenu::model()->getDropDownMenu(); $idMenu = !empty($model->idMenu) ? $model->idMenu : key($menus); $category1 = array('' => 'Без категории'); $category2 = Categorys::getAllCategories($idMenu); $category = $category1 + $category2; $this->render('new_article', array('model' => $model, 'menus' => $menus, 'category' => $category)); }
$time = date("H_m_i"); $final_article_picture_name = $name[0] . $time . "." . $name[1]; $final_article_picture_small_name = $name[0] . $time . "small." . $name[1]; $final_article_slider_picture = $name[0] . $time . "slider." . $name[1]; $final_article_slider_picture_small = $name[0] . $time . "slider_small." . $name[1]; /*********************************************************************************************************************************/ //article picture $article_picture = new SimpleImage(); $article_picture->load($_FILES['img']['tmp_name'])->resize(620, 387)->save("../view/images/" . $final_article_picture_name); //article picture small $article_picture_small = new SimpleImage(); $article_picture_small->load($_FILES['img']['tmp_name'])->resize(145, 100)->save("../view/images/" . $final_article_picture_small_name); //article slider picture $article_slider_picture = new SimpleImage(); $article_slider_picture->load($_FILES['img']['tmp_name'])->resize(636, 331)->save("../view/images/" . $final_article_slider_picture); //article slider small $article_slider_picture_small = new SimpleImage(); $article_slider_picture_small->load($_FILES['img']['tmp_name'])->resize(636, 331)->save("../view/images/" . $final_article_slider_picture_small); /*******************************************************************************************************************************************************/ $article = new Articles(); $article->article_id = $_SESSION['article_id']; $article->article_picture_small = $final_article_picture_small_name; $article->article_picture = $final_article_picture_name; $article->article_picture_slider_small = $final_article_slider_picture_small; $article->article_picture_slider = $final_article_slider_picture; $_SESSION['change_picture'] = $final_article_picture_small_name; $article->save(); //$_SESSION['change_picture'] = Articles::get($_SESSION['article_id']); //var_dump($_SESSION['change_picture']); header("location:home.php?page=5"); }
public function articleAdd() { $id = Input::get('id'); if ($id) { //修改操作 $article = Articles::find($id); } else { //新增操作 $article = new Articles(); } $cus_id = Auth::id(); $article->title = trim(Input::get('title')); $article->c_id = Input::get('c_id'); $article->viewcount = Input::get('viewcount') ? Input::get('viewcount') : 0; $article->title_bold = Input::get('title_bold'); $article->title_color = Input::get('title_color'); $article->keywords = Input::get('keywords'); $article->introduction = Input::get('introduction'); $article->content = trim(Input::get('content')); if ($article->title == "" || $article->content == "") { return Response::json(array('err' => 3001, 'msg' => '标题或内容不能为空')); } $article->pushed = 1; $img_arr = explode(',', Input::get('src')); if (count($img_arr)) { $article->img = $img_arr[0]; unset($img_arr[0]); } $is_show = empty(Input::get('is_show')) ? array() : explode(',', Input::get('is_show')); $article->pc_show = 0; $article->mobile_show = 0; $article->wechat_show = 0; if (count($is_show)) { foreach ($is_show as $val) { $article->{$val} = 1; } } $pubdate = Input::get('pubdate'); if ($pubdate) { $article->created_at = date('Y-m-d H:i:s', strtotime($pubdate)); } $article->cus_id = $cus_id; $result = $article->save(); if ($result) { if ($id) { MoreImg::where('a_id', $id)->delete(); } if (count($img_arr)) { foreach ($img_arr as $img) { $moreimg = new Moreimg(); $moreimg->title = ''; $moreimg->img = $img; $moreimg->url = ''; $moreimg->sort = ''; $moreimg->a_id = $article->id; $moreimg->save(); } } $return_msg = array('err' => 0, 'msg' => '', 'data' => array($article->id)); } else { $return_msg = array('err' => 3001, 'msg' => '文章添加失败'); } return Response::json($return_msg); }
/** * 发布新闻 * */ function actionCreate() { $this->_viewname = 'edit'; $form = Form_Admin_News::createForm('article', url('article/create')); if ($this->_context->isPOST() && $form->validate($_POST)) { //是否post提交及通过验证 try { $news = new Articles($form->values()); $user = $this->_app->currentUser(); $news['user_id'] = $user['id']; //更新该栏目下的新闻条数 $newSort = Articlesorts::meta()->find('id =?', $form['sort_id']->value)->query(); $newSort->news_count++; $newSort->save(); //保存更新 $news->save(); return $this->_redirectMessage('发表文章成功', '如果你不做出选择系统将自动跳转', url('article/index'), 3); } catch (QValidator_ValidateFailedException $ex) { $form->invalidate($ex); } } $this->_view['form'] = $form; }
public function actionSave_article() { $idArticle = null; // Проверки на доступ к странице if (Yii::app()->user->isGuest) { $this->redirect($this->createAbsoluteUrl('default/index')); } if (isset($_POST['cancel'])) { $this->redirect($this->createAbsoluteUrl('default/list_articles', $_GET)); } if (isset($_POST['delete'])) { $this->actionDelete_article(); $this->redirect($this->createAbsoluteUrl('default/list_articles', $_GET)); } // Автокомплитер тегов if (isset($_GET['q'])) { $lastTag = end(explode(",", $_GET['q'])); $criteria = new CDbCriteria(); $criteria->condition = 'textTag LIKE :tag'; $criteria->params = array(':tag' => '%' . trim(htmlspecialchars($lastTag)) . '%'); if (isset($_GET['limit']) && is_numeric($_GET['limit'])) { $criteria->limit = $_GET['limit']; } $tags = Tags::model()->findAll($criteria); if ($tags) { $resStr = ''; foreach ($tags as $tag) { $resStr .= $tag->textTag . "\n"; } echo $resStr; } exit; } // Редактирование или добавление новой if (isset($_GET['idArticle'])) { $idArticle = $_GET['idArticle']; $model = Articles::model()->findByPk($_GET['idArticle']); $model['tagArray'] = AuxiliaryFunctions::getTagsList($model->tagstoarticles, false); } else { $model = new Articles('create'); } // Нажата кнопка "Редактировать" или "Добавить" if (isset($_POST['Articles'])) { $oldFile = null; $oldFile = $model->photo; $fileName = null; // Генерим имя фото if ('' != $_FILES['Articles']['name']['image']) { $fileName = AuxiliaryFunctions::getUniquNamePhoto($_FILES['Articles']['name']['image']); $_POST['Articles']['photo'] = $fileName; $oldFile = $model->photo; } $model->attributes = $_POST['Articles']; if (empty($model->idUser)) { $model->idUser = Users::getIdUserForAdmin(); } if ($model->validate()) { if ($model->save()) { $idArticle = $model->idArticle; if ($fileName) { AuxiliaryFunctions::savePhoto($model, $fileName, $oldFile); } // Теги для статьи if (isset($_POST['textTag'])) { $tagsArray = explode(",", $_POST['textTag']); $idArray = array(); foreach ($tagsArray as $item) { $tagId = null; if (!empty($item)) { $item = trim(htmlspecialchars($item)); } else { continue; } $tagResult = Tags::model()->findByAttributes(array('textTag' => $item)); if (null === $tagResult) { $newTag = new Tags(); $newTag->textTag = $item; if ($newTag->save()) { $tagId = $newTag->idTag; } } else { $tagId = $tagResult->idTag; } $idArray[] = $tagId; } if ($idArray) { foreach ($idArray as $item) { $item = (int) $item; $idArticle = (int) $idArticle; if (!TagsToArticles::model()->exists('idArticle = :idArticle AND idTag = :idTag', array(':idArticle' => $idArticle, ':idTag' => $item))) { $newTags2Art = new TagsToArticles(); $newTags2Art->idArticle = $idArticle; $newTags2Art->idTag = (int) $item; $newTags2Art->save(); } } } } $this->redirect($this->createAbsoluteUrl('default/list_articles', $_GET)); } } } $menus = Mainmenu::model()->getDropDownMenu(); $idMenu = !empty($model->idMenu) ? $model->idMenu : key($menus); $category1 = array('' => 'Без категории'); $category2 = Categorys::getAllCategories($idMenu); $category = $category1 + $category2; $tags = new Tags(); $this->render('//articles/save_article', array('model' => $model, 'menus' => $menus, 'category' => $category, 'tags' => $tags)); }