/** * コンテンツデータを登録する * コンテンツデータを次のように作成して引き渡す * array('Content' => * array( 'model_id' => 'モデルでのID' * 'category' => 'カテゴリ名', * 'title' => 'コンテンツタイトル', // 検索対象 * 'detail' => 'コンテンツ内容', // 検索対象 * 'url' => 'URL', * 'status' => '公開ステータス' * )) * * @param Model $model * @param array $data * @return boolean * @access public */ public function saveContent(Model $model, $data) { if (!$data) { return; } $data['Content']['model'] = $model->alias; // タグ、空白を除外 $data['Content']['detail'] = str_replace(array("\r\n", "\r", "\n", "\t", "\\s"), '', trim(strip_tags($data['Content']['detail']))); // 検索用データとして保存 $id = ''; $this->Content = ClassRegistry::init('Content'); if (!empty($data['Content']['model_id'])) { $before = $this->Content->find('first', array('fields' => array('Content.id', 'Content.category'), 'conditions' => array('Content.model' => $data['Content']['model'], 'Content.model_id' => $data['Content']['model_id']))); } if ($before) { $data['Content']['id'] = $before['Content']['id']; $this->Content->set($data); } else { if (empty($data['Content']['priority'])) { $data['Content']['priority'] = '0.5'; } $this->Content->create($data); } $result = $this->Content->save(); // カテゴリを site_configsに保存 if ($result) { return $this->updateContentMeta($model, $data['Content']['category']); } return $result; }
public function actionAdd() { $this->layout = '//layouts/admin'; $this->pageTitle = 'Новая страница'; $this->breadcrumbs = array('Страницы контента' => array('/admin/content'), 'Новая страница'); $success = false; if (isset($_POST['data'])) { $model = new Content(); $dataArray = $_POST['data']; $dataArray['timestamp'] = time(); $dataArray['views_count'] = 0; $dataArray['is_active'] = isset($_POST['data']['is_active']) && $_POST['data']['is_active'] == 1 ? 1 : 0; $model->setAttributes($dataArray); if ($model->save()) { $success = true; if (isset($_FILES['anons_pic']) && $_FILES["anons_pic"]["name"] || isset($_FILES['content_pic']) && $_FILES["content_pic"]["name"]) { $uploaddir = 'images/upload/' . date("d.m.Y", time()); if (!is_dir($uploaddir)) { mkdir($uploaddir); } if (isset($_FILES['anons_pic'])) { $tmp_name = $_FILES["anons_pic"]["tmp_name"]; $name = $_FILES["anons_pic"]["name"]; if ($name) { $uploadfile = $uploaddir . '/na_' . $model->id . '_' . md5(basename($name) . time()) . "." . end(explode(".", $name)); if (move_uploaded_file($tmp_name, $uploadfile)) { $model->setAttributes(array("anons_pic" => "/" . $uploadfile)); if (!$model->save()) { print_r($model->errors); die; } } } } if (isset($_FILES['content_pic'])) { $tmp_name = $_FILES["content_pic"]["tmp_name"]; $name = $_FILES["content_pic"]["name"]; if ($name) { $uploadfile = $uploaddir . '/nc_' . $model->id . '_' . md5(basename($name) . time()) . "." . end(explode(".", $name)); if (move_uploaded_file($tmp_name, $uploadfile)) { $model->setAttributes(array("content_pic" => "/" . $uploadfile)); $model->save(); } } } } } } if ($success) { $this->redirect("/admin/content"); } if (!isset($model) || !is_object($model)) { $model = new Content(); } $this->render('add', array("errors" => $model->errors)); }
/** * After Saving of records of type content, automatically add/bind the * corresponding content to it. * * If the automatic wall adding (autoAddToWall) is enabled, also create * wall entry for this content. * * NOTE: If you overwrite this method, e.g. for creating activities ensure * this (parent) implementation is invoked BEFORE your implementation. Otherwise * the Content Object is not available. */ public function afterSave() { // Auto follow this content if (get_class($this) != 'Activity') { $this->follow($this->created_by); } if ($this->isNewRecord) { $this->content->user_id = $this->created_by; $this->content->object_model = get_class($this); $this->content->object_id = $this->getPrimaryKey(); $this->content->created_at = $this->created_at; $this->content->created_by = $this->created_by; } $this->content->updated_at = $this->updated_at; $this->content->updated_by = $this->updated_by; $this->content->save(); parent::afterSave(); if ($this->isNewRecord && $this->autoAddToWall) { $this->content->addToWall(); } // When Space Content, update also last visit if ($this->content->space_id) { $membership = $this->content->space->getMembership(Yii::app()->user->id); if ($membership) { $membership->updateLastVisit(); } } }
/** * Saves Announcement in database * @access public */ public function save() { Logger::log("Enter: Announcement::save_announcement"); Logger::log("Calling: Content::save"); if ($this->content_id) { parent::save(); //for child class $data = array(); $update = ''; $field_array = array('announcement_time', 'position', 'status'); foreach ($field_array as $key => $value) { if ($this->{$value}) { $update .= ' ' . $value . ' = ?,'; array_push($data, $this->{$value}); } } if (!empty($update)) { $update = substr($update, 0, -1); $sql = 'UPDATE {announcements} SET ' . $update . ' WHERE content_id = ?'; array_push($data, $this->content_id); } $res = Dal::query($sql, $data); } else { parent::save(); $sql = "INSERT INTO {announcements} (content_id, announcement_time, position, status, is_active) VALUES (?, ?, ?, ?, ?)"; $data = array($this->content_id, $this->announcement_time, $this->position, $this->status, $this->is_active); $res = Dal::query($sql, $data); return array('aid' => $this->content_id); } Logger::log("Exit: Image::save_announcement"); return $this->content_id; }
/** * Saves blog post in db * @access public */ public function save() { Logger::log("Enter: BlogPost::save"); Logger::log("Calling: Content::save"); parent::save(); Logger::log("Exit: BlogPost::save"); return; }
public function ajax_save() { $id = (int) $this->input->post('id'); $pid = (int) $this->input->post('page_id'); $div = $this->input->post('div'); $title = $this->input->post('title'); $text = $this->input->post('text'); $img = $this->input->post('image'); //file_put_contents('post', json_encode($_POST));die; $page = Page::factory($pid); $content = Content::factory()->where('div', $div)->where_related_page('id', $pid)->limit(1)->get(); if (!$content->exists()) { $content = new Content(); $content->div = $div; $ctype = ContentType::factory()->where('classname', 'Repeatable')->limit(1)->get(); $content->editor_id = $this->user->id; $content->save(array($page, $ctype)); } else { $content->editor_id = $this->user->id; $content->save(); } if (empty($id)) { $item = new RepeatableItem(); $item->timestamp = time(); } else { $item = RepeatableItem::factory($id); } $item->title = $title; $item->text = $text; $item->image = trim($img, '/'); if (empty($id)) { $item->save(array($content, $this->user)); } else { $item->save(); } if (empty($id)) { $msg = __("New item published: \"%s\"", $title); } else { $msg = __("Changes saved in \"%s\"", $title); } echo json_encode(array('status' => 'OK', 'message' => $msg, 'id' => $item->id)); }
function after_content_create($content) { $s = new Setting(); $s->where('name', 'uploading_publish_on_captured_date')->get(); if ($s->exists() && $s->value === 'true') { $fresh = new Content(); $fresh->get_by_id($content['id']); $fresh->published_on = $content['captured_on']['utc'] ? $content['captured_on']['timestamp'] : 'captured_on'; $fresh->save(); } }
public function save() { if (!$this->validate()) { return false; } $model = new Content(); $model->setAttributes($this->getAttributes()); if (!$model->save()) { $this->addErrors($model->getErrors()); return false; } return true; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Content(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Content'])) { $model->attributes = $_POST['Content']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
function save_orderlist($id = FALSE) { if ($_POST) { foreach ($_POST['orderlist'] as $key => $item) { if ($item) { $content = new Content(@$_POST['orderid'][$key]); $content->from_array(array('orderlist' => $item)); $content->save(); } } set_notify('success', lang('save_data_complete')); } redirect($_SERVER['HTTP_REFERER']); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $this->addToolbar(); $model = new Content(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Content'])) { $model->attributes = $_POST['Content']; $model->title = $model->title; if ($model->save()) { $this->redirect(array('index')); } } $this->render('form', array('model' => $model)); }
/** * Implementation for 'POST' method for Rest API * * @param mixed $conCategory, $conParent, $conId, $conLang Primary key * * @return array $result Returns array within multiple records or a single record depending if * a single selection was requested passing id(s) as param */ protected function post($conCategory, $conParent, $conId, $conLang, $conValue) { try { $result = array(); $obj = new Content(); $obj->setConCategory($conCategory); $obj->setConParent($conParent); $obj->setConId($conId); $obj->setConLang($conLang); $obj->setConValue($conValue); $obj->save(); } catch (Exception $e) { throw new RestException(412, $e->getMessage()); } }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aContent !== null) { if ($this->aContent->isModified() || $this->aContent->isNew()) { $affectedRows += $this->aContent->save($con); } $this->setContent($this->aContent); } if ($this->isNew()) { $this->modifiedColumns[] = DisciplinaPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = DisciplinaPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += DisciplinaPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collGradeunits !== null) { foreach ($this->collGradeunits as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
public function save() { if ($this->perm->can_create == 'y') { $data = new Content(); if ($_POST['id'] == '') { $_POST['created_by'] = $this->current_user->id; $_POST['created'] = date("Y-m-d H:i:s"); } else { $_POST['updated_by'] = $this->current_user->id; $_POST['updated'] = date("Y-m-d H:i:s"); } $data->from_array($_POST); $data->save(); save_logs($this->menu_id, 'Update', $this->session->userdata("id"), ' Update Explanation '); } redirect($_SERVER['HTTP_REFERER']); }
public function actionAdd() { date_default_timezone_set('Asia/Shanghai'); $model = new Content(); $model->postdate = date("Y-m-d H:i:s"); if (isset($_POST['Content'])) { $model->attributes = $_POST['Content']; // validate user input and redirect to the previous page if valid if ($model->save()) { $this->redirect(Yii::app()->createURL("manage/index")); } else { print_r($model->errors); exit; } } $this->render('add', array("model" => $model)); }
public function saveNewDownload() { if (Input::hasFile('download_file')) { $content = new Content(); $content->type = 'download'; $content->active = 0; $content->candidate_facing = 1; $content->client_facing = 0; $content->body = uniqid() . '.' . Input::file('download_file')->getClientOriginalExtension(); Input::file('download_file')->move(public_path() . '/docs/', $content->body); $content->title = Input::get('name'); $content->save(); return Redirect::to('dashboard/downloads'); } else { $content = new Content(); $content->title = Input::get('name'); } }
public function postSavenewhomepagemessage() { $validator = Validator::make(Input::all(), array('text' => 'required|min:5')); if ($validator->fails()) { $output = array('result' => 0, 'error' => ''); foreach ($validator->messages()->all() as $m) { $output['error'] .= $m . ' '; } return json_encode($output); } $message = new Content(); $message->type = 'homepage'; $message->body = Input::get('text'); $message->save(); $output['result'] = 1; $output['content'] = View::make('snippets.messagebox', array('message' => $message, 'position' => Content::get()->count()))->render(); return Response::json($output); }
function create() { $model = new Content(); $model->cid = $this->getCateId(); $model->status = MDbModel::STATUS_ONLINE; $model->uid = $this->user->id; if ($this->isPost()) { if ($content = $this->post('Content.content')) { $model->content = htmlentities($content); unset($_POST['Content']['content']); } $model->setAttributes($this->post('Content')); if ($model->save()) { $this->redirect(url('/admin/' . $this->cate->alias)); } } $this->render('../content/create', array('model' => $model)); }
public function add($pid, $name) { $page = Page::factory($pid); if (!$this->user->can_edit_page($page)) { $this->templatemanager->notify_next("You don't have enough permissions to add contents to this page!", 'failure'); redirect('administration/dashboard'); } $url_suffix = isset($_GET['iu-popup']) ? '?iu-popup' : ''; $c = $page->content->where('div', $name)->get(); if (!$c->exists()) { $html = $page->body()->find('div[id=' . trim($name) . ']', 0)->innertext; $c = new Content(); $c->div = $name; $c->contents = $html; $c->type = 'static'; $c->editor_id = $this->user->id; $c->save(array($page)); } redirect('administration/contents/edit/' . $c->id . '/' . $c->div . $url_suffix); }
public function createAction() { $this->view->Title = "Management content"; $this->view->headTitle($this->view->Title); if ($this->getRequest()->isPost()) { $request = $this->getRequest()->getParams(); $error = $this->_checkForm($request); if (count($error) == 0) { $Content = new Content(); $Content->merge($request); $Content->save(); $this->Member->log('Create:' . $Content->content_title . '(' . $Content->content_id . ')', 'Content'); My_Plugin_Libs::setSplash('Posts: <b>' . $Content->content_title . '</b> has been created. '); $this->_redirect($this->_helper->url('index', 'content', 'admin')); } if (count($error)) { $this->view->error = $error; } } }
/** * Function used to save some information into our system * @access public */ public function save() { Logger::log("Enter: TekVideo::save()"); $this->video_id = $this->file_name; // so that this content will not display on the recent post module $this->is_default_content = FALSE; $this->type = TEK_VIDEO; parent::save(); if (empty($this->status)) { $this->status = -1; Tag::add_tags_to_content($this->content_id, $this->tags); $sql = 'INSERT INTO {media_videos} (content_id, video_id, email_id, views, author_id, status, video_perm) values (?, ?, ?, ?, ?, ?, ?)'; Dal::query($sql, array($this->content_id, $this->video_id, $this->email_id, 0, $this->author_id, $this->status, $this->video_perm)); } else { $params['key_value'] = array('video_perm' => $this->video_perm); $this->update($this->content_id, $params); } Logger::log("Exit: TekVideo::save()"); return; }
public function createAction() { $this->view->Title = "Quản lý bài viết"; $this->view->headTitle($this->view->Title); if ($this->getRequest()->isPost()) { $request = $this->getRequest()->getParams(); $error = $this->_checkForm($request); if (count($error) == 0) { $Content = new Content(); $Content->merge($request); $Content->created_date = date("Y-m-d H:i:s"); $Content->save(); $this->Member->log('Bài viết:' . $Content->content_title . '(' . $Content->content_id . ')', 'Tạo mới'); My_Plugin_Libs::setSplash('Bài viết: <b>' . $Content->content_title . '</b> đã tạo thành công. '); $this->_redirect($this->_helper->url('index', 'content', 'admin')); } if (count($error)) { $this->view->error = $error; } } }
function update_slug($obj) { // Generate the slug. $slug_name = $this->generate_slug($obj['id'], substr($obj['uploaded_on']['timestamp'], -5)); /* Following doesn't work because Slug model isn't implemented properly. // Get slug from the database. $slug = new Slug; $slug->get_by_id('content.' . $slug_name); // Add it to the database if it doesn't exist. if (!$slug->exists()) { $slug->id = 'content.' . $slug_name; $slug->save(); } */ // Construct content object. $content = new Content($obj['id']); // Set the new slug. $content->slug = $slug_name; $content->old_slug = $slug_name; $content->save(); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($type) { $Content = new Content(); $Content->setType($type); $Content->published = true; if (isset($_POST['Content'])) { $Content->attributes = $_POST['Content']; $ContentType = $Content->ContentType; $ContentType->attributes = $_POST['ContentType']; $contentSaved = $Content->save(); $ContentType->content_id = $Content->id; $contentTypeSaved = $ContentType->save(); $menuItemsSaved = true; if (isset($_POST['MenuItem'])) { foreach ($_POST['MenuItem'] as $data) { if (isset($data['include'])) { $MenuItem = $this->_populateMenuItem(new MenuItem(), $data, $Content); $menuItemsSaved = $MenuItem->save(); } } } if ($contentSaved && $menuItemsSaved) { Yii::app()->user->setFlash('success', 'Content Created'); if (!$contentTypeSaved) { Yii::app()->user->setFlash('error', 'Problem saving Content Type'); } Yii::log(CHtml::link($Content->UserCreated->full_name, array('user/view', 'id' => $Content->created_by)) . ' created ' . $Content->ContentType->name . ' ' . CHtml::link($Content->title, $this->createFrontendUrl('content/view', array('id' => $Content->id))), 'info', 'Content'); if (isset($_POST['save_and_continue'])) { $this->redirect(array('content/update', 'id' => $Content->id)); } else { $this->redirect(array('content/admin')); } } } $this->layout = '//layouts/column1'; $this->render('create', array('Content' => $Content)); }
/** * Store a newly created resource in storage. * POST /admin * * @return Response */ public function store() { $rules = array_merge(Content::$rules, Image::rules()); $validation = Validator::make(Input::all(), $rules); if ($validation->passes()) { if (Input::hasFile('featured_image')) { $file = Input::file('featured_image'); if ($file->isValid()) { $file->move(__DIR__ . '/storage/', $file->getClientOriginalName()); //($destinationPath, $fileName); } } $content = new Content(); $content->page_title = Input::get('page_title'); $content->page_content = Input::get('page_content'); $content->save(); return Redirect::route('create')->with('success', 'Registro criado com sucesso'); } /* metodo alternativo */ // return Redirect::route('create') // ->withInput(Input::except('password','re_password')) // ->with('error', $validation->errors()->first()); return Redirect::route('create')->withInput(Input::all())->withErrors($validation); }
/** * Enter description here... * * @param string $token * @param integer $editMode * @return string */ function show($token = "", $editMode = true) { if (empty($token)) { return ''; } $out = ""; $id = ""; $ses_LNG = $this->Session->read('User.Lang'); $langId = $ses_LNG['id']; $objContent = new Content(); $content = $objContent->find('first', array('contain' => array(), 'conditions' => array('token' => $token, 'language_id' => $langId))); if (!empty($content)) { $out = $content['Content']['content']; $id = $content['Content']['id']; } else { //Get content for default Language $content = $objContent->find('first', array('contain' => array(), 'conditions' => array('token' => $token, 'language_id' => DEFAULT_LANG_ID))); if (!empty($content)) { $out = $content['Content']['content']; $id = $content['Content']['id']; } else { /*Create New content*/ $defaultContent = array('Content' => array('token' => $token, 'language_id' => DEFAULT_LANG_ID, 'title' => '', 'content' => $token)); //array $objContent->save($defaultContent); $id = $objContent->getLastInsertID(); $out = $token; } } //else if ($editMode) { $out = '<span class="token">' . '<span class="data" id="token' . $id . '" >' . $out . '</span>' . $this->Html->link($this->Html->image('editable.gif', array('alt' => 'edit')), "/contents/edittoken/{$id}?KeepThis=true&TB_iframe=true&height=500&width=680", array('class' => 'thickbox', 'title' => 'edit'), null, false) . '</span>'; } //if return $out; }
if ($contents) { foreach ($contents as $content) { $content['Content']['priority'] = '0.5'; switch ($content['Content']['model']) { case 'Page': $type = 'ページ'; break; case 'BlogPost': $type = 'ブログ'; break; default: $type = ''; } $content['Content']['type'] = $type; $Content->set($content); if (!$Content->save()) { $result = false; } } if ($result) { $this->setMessage('contents テーブルのデータ更新に成功しました。'); } else { $this->setMessage('contents テーブルのデータ更新に失敗しました。', true); } } /** * page_categories データ更新 */ App::import('Model', 'PageCategory'); $PageCategory = new PageCategory(); $data = array('PageCategory' => array('name' => 'smartphone', 'title' => 'スマートフォン', 'created' => date('Y-m-d H:i:s')));
/** * 创建对象时,保存 many_to_many 关联 */ function testCreateWithManyToMany() { $tags = array('PHP', 'C++', 'Java'); $content = new Content(array('title' => 'title - ' . mt_rand(), 'author_id' => 0)); foreach ($tags as $tag_name) { $content->tags[] = new Tag(array('name' => $tag_name)); } $content->save(); $this->assertNotNull($content->id()); $row = $this->_queryContent($content->id()); $this->_checkContent($row, $content); foreach ($tags as $offset => $tag_name) { $row = $this->_queryTag($tag_name); $this->assertType('array', $row); $this->_checkTag($row, $content->tags[$offset]); } $mid_table_name = $content->getMeta()->associations['tags']->mid_table->qtable_name; $sql = "SELECT * FROM {$mid_table_name} WHERE content_id = ?"; $rowset = $this->_conn->getAll($sql, array($content->id())); $this->assertEquals(count($tags), count($rowset)); $tags = array_flip($tags); foreach ($rowset as $row) { $this->assertTrue(isset($tags[$row['tag_name']])); unset($tags[$row['tag_name']]); } }
public function createDefaultContent() { $existing = \Content::where('is_home', 1)->first(); if ($existing == false) { $content = new \Content(); $content->title = "Home"; $content->url = 'home'; $content->parent = 0; $content->is_home = 1; $content->is_active = 1; $content->content_type = "page"; $content->subtype = "static"; $content->layout_file = "index.php"; $content->save(); $menu = new \Menu(); $menu->title = "header_menu"; $menu->item_type = "menu"; $menu->is_active = 1; $menu->save(); $menu = new \Menu(); $menu->parent_id = 1; $menu->content_id = 1; $menu->item_type = "menu_item"; $menu->is_active = 1; $menu->save(); $menu = new \Menu(); $menu->title = "footer_menu"; $menu->item_type = "menu"; $menu->is_active = 1; $menu->save(); $menu = new \Menu(); $menu->parent_id = 2; $menu->content_id = 1; $menu->item_type = "menu_item"; $menu->is_active = 1; $menu->save(); } }
function insertContent($ConCategory, $ConParent, $ConId, $ConLang, $ConValue) { try { $con = new Content(); $con->setConCategory($ConCategory); $con->setConParent($ConParent); $con->setConId($ConId); $con->setConLang($ConLang); $con->setConValue($ConValue); if ($con->validate()) { $res = $con->save(); return $res; } else { $e = new Exception("Error in addcontent, the row {$ConCategory}, {$ConParent}, {$ConId}, {$ConLang} is not Valid"); throw $e; } } catch (Exception $e) { throw $e; } }