public function new_content($cname, $pid) { $page = Page::factory((int) $pid); $ctype = ContentType::factory()->where('classname', "Gallery")->limit(1)->get(); $content = Content::factory(); $content->div = $cname; $content->editor_id = $this->user->id; $content->page_id = $page->id; $content->contenttype_id = $ctype->id; $content->save(); $redir = site_url('administration/images/gallery_add_new/' . $content->id . '/' . $cname . '/' . $pid) . '?iu-popup'; redirect($redir); }
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)); }
public function save($id) { $relations = array(); //file_put_contents('post', json_encode($_POST)); $pid = $this->input->post('pid'); //$div_id = $this->input->post('div'); $html = $this->input->post('html'); if (!empty($pid)) { $page = Page::factory()->get_by_id((int) $pid); $relations[] = $page; } $content = Content::factory()->get_by_id($id); if (!$this->user->can_edit_content($content)) { if ($this->is_ajax_request()) { die(json_encode(array('status' => 'Error', 'message' => __("You don't have enough permissions to edit this content!")))); } else { $this->templatemanager->notify_next("You don't have enough permissions to edit this content!", 'failure'); redirect('administration/dashboard'); } } $old_html = $content->contents; $old_editor = $content->editor_id; $old_ts = !empty($content->updated) ? $content->updated : $content->created; //set/unset editors $editors = $this->input->post('editors'); if (!empty($editors)) { $editors_users = User::factory()->where_in('id', $editors)->get(); $not_editors_users = User::factory()->where_not_in('id', $editors)->get(); } //set page and content editor $page->editor_id = $this->user->id; $content->editor_id = $this->user->id; //set contents $content->contents = empty($html) ? '' : $html; //save page and contents $page->save(); //set content type $ctype_id = (int) $this->input->post('type'); if ($ctype_id > 0 && $this->user->owns_page($page)) { $relations[] = ContentType::factory($ctype_id); } if ($this->user->owns_page($page)) { $content->is_global = $this->input->post('global') == 'yes'; } //remove non and save editors if (!empty($editors) && $this->user->owns_page($page)) { $content->delete_editor($not_editors_users->all); $content->save_editor($editors_users->all); } $content->save($relations); //create revision $rev = new ContentRevision(); $rev->contents = $old_html; $rev->user_id = $old_editor; $rev->created = $old_ts; $rev->save(array($content, $this->user)); $this->templatemanager->notify_next(__("Content \"%s\" is saved!", $content->div), 'success'); if ($this->is_ajax_request()) { echo json_encode(array('status' => 'OK', 'message' => __("Content \"%s\" is saved!", $div_id))); } else { redirect('administration/contents/edit/' . $content->id . '/' . $content->div); } }