public function pre_save($input, $field = null, $stream = null, $row_id = null)
 {
     // Remove any existing applied keywords
     if (!empty($row_id) and !empty($stream)) {
         $this->CI->load->model(array('keywords/keyword_m', 'streams_core/row_m'));
         $row = $this->CI->row_m->get_row($row_id, $stream, false);
         $keyword_hash = $row->keywords;
         $this->CI->keyword_m->delete_applied($keyword_hash);
     }
     return Keywords::process($input);
 }
Example #2
0
 protected function update_search_index($poll, array $options = null)
 {
     // Load the search index model
     $this->load->model('search/search_index_m');
     $options_array = null;
     $options_string = null;
     if (!empty($options)) {
         foreach ($options as $option) {
             $options_array[] = preg_replace('/[^a-z0-9]+/i', ' ', $option['title']);
         }
     }
     $options_string = $options_array ? implode(', ', $options_array) : null;
     $this->search_index_m->index('polls', 'polls:poll', 'polls:polls', $poll['id'], 'polls/' . $poll['slug'], $poll['title'], $poll['description'], array('cp_edit_uri' => 'admin/polls/edit/' . $poll['id'], 'cp_delete_uri' => 'admin/polls/delete/' . $poll['id'], 'keywords' => Keywords::process($options_string)));
 }
Example #3
0
 /**
  * Edit blog post
  *
  * @access public
  * @param int $id the ID of the blog post to edit
  * @return void
  */
 public function edit($id = 0)
 {
     $id or redirect('admin/blog');
     $post = $this->blog_m->get($id);
     $post->keywords = Keywords::get_string($post->keywords);
     // If we have a useful date, use it
     if ($this->input->post('created_on')) {
         $created_on = strtotime(sprintf('%s %s:%s', $this->input->post('created_on'), $this->input->post('created_on_hour'), $this->input->post('created_on_minute')));
     } else {
         $created_on = $post->created_on;
     }
     $this->form_validation->set_rules(array_merge($this->validation_rules, array('title' => array('field' => 'title', 'label' => 'lang:blog_title_label', 'rules' => 'trim|htmlspecialchars|required|max_length[100]|callback__check_title[' . $id . ']'), 'slug' => array('field' => 'slug', 'label' => 'lang:blog_slug_label', 'rules' => 'trim|required|alpha_dot_dash|max_length[100]|callback__check_slug[' . $id . ']'))));
     if ($this->form_validation->run()) {
         // They are trying to put this live
         if ($post->status != 'live' and $this->input->post('status') == 'live') {
             role_or_die('blog', 'put_live');
         }
         $author_id = empty($post->display_name) ? $this->current_user->id : $post->author_id;
         $result = $this->blog_m->update($id, array('title' => $this->input->post('title'), 'slug' => $this->input->post('slug'), 'category_id' => $this->input->post('category_id'), 'keywords' => Keywords::process($this->input->post('keywords')), 'intro' => $this->input->post('intro'), 'body' => $this->input->post('body'), 'status' => $this->input->post('status'), 'created_on' => $created_on, 'comments_enabled' => $this->input->post('comments_enabled'), 'author_id' => $author_id, 'type' => $this->input->post('type'), 'parsed' => $this->input->post('type') == 'markdown' ? parse_markdown($this->input->post('body')) : ''));
         if ($result) {
             $this->session->set_flashdata(array('success' => sprintf(lang('blog_edit_success'), $this->input->post('title'))));
             // They are trying to put this live
             if ($post->status != 'live' and $this->input->post('status') == 'live') {
                 // Fire an event, we're posting a new blog!
                 Events::trigger('blog_article_published', $id);
             }
         } else {
             $this->session->set_flashdata('error', $this->lang->line('blog_edit_error'));
         }
         // Redirect back to the form or main page
         $this->input->post('btnAction') == 'save_exit' ? redirect('admin/blog') : redirect('admin/blog/edit/' . $id);
     }
     // Go through all the known fields and get the post values
     foreach ($this->validation_rules as $key => $field) {
         if (isset($_POST[$field['field']])) {
             $post->{$field}['field'] = set_value($field['field']);
         }
     }
     $post->created_on = $created_on;
     $this->template->title($this->module_details['name'], sprintf(lang('blog_edit_title'), $post->title))->append_metadata($this->load->view('fragments/wysiwyg', $this->data, TRUE))->append_js('jquery/jquery.tagsinput.js')->append_js('module::blog_form.js')->append_css('jquery/jquery.tagsinput.css')->set('post', $post)->build('admin/form');
 }
Example #4
0
 /**
  * Edit blog post
  *
  * @param int $id The ID of the blog post to edit
  */
 public function edit($id = 0)
 {
     $id or redirect('admin/blog');
     $post = $this->blog_m->get($id);
     // They are trying to put this live
     if ($post->status != 'live' and $this->input->post('status') == 'live') {
         role_or_die('blog', 'put_live');
     }
     // If we have keywords before the update, we'll want to remove them from keywords_applied
     $old_keywords_hash = trim($post->keywords) != '' ? $post->keywords : null;
     $post->keywords = Keywords::get_string($post->keywords);
     // If we have a useful date, use it
     if ($this->input->post('created_on')) {
         $created_on = strtotime(sprintf('%s %s:%s', $this->input->post('created_on'), $this->input->post('created_on_hour'), $this->input->post('created_on_minute')));
     } else {
         $created_on = $post->created_on;
     }
     // Load up streams
     $this->load->driver('Streams');
     $stream = $this->streams->streams->get_stream('blog', 'blogs');
     $stream_fields = $this->streams_m->get_stream_fields($stream->id, $stream->stream_namespace);
     // Get the validation for our custom blog fields.
     $blog_validation = $this->streams->streams->validation_array($stream->stream_slug, $stream->stream_namespace, 'new');
     $blog_validation = array_merge($this->validation_rules, array('title' => array('field' => 'title', 'label' => 'lang:global:title', 'rules' => 'trim|htmlspecialchars|required|max_length[100]|callback__check_title[' . $id . ']'), 'slug' => array('field' => 'slug', 'label' => 'lang:global:slug', 'rules' => 'trim|required|alpha_dot_dash|max_length[100]|callback__check_slug[' . $id . ']')));
     // Merge and set our validation rules
     $this->form_validation->set_rules(array_merge($this->validation_rules, $blog_validation));
     $hash = $this->input->post('preview_hash');
     if ($this->input->post('status') == 'draft' and $this->input->post('preview_hash') == '') {
         $hash = $this->_preview_hash();
     } elseif ($this->input->post('status') == 'live') {
         $hash = '';
     }
     if ($this->form_validation->run()) {
         $author_id = empty($post->display_name) ? $this->current_user->id : $post->author_id;
         $extra = array('title' => $this->input->post('title'), 'slug' => $this->input->post('slug'), 'category_id' => $this->input->post('category_id'), 'keywords' => Keywords::process($this->input->post('keywords'), $old_keywords_hash), 'body' => $this->input->post('body'), 'status' => $this->input->post('status'), 'created_on' => $created_on, 'updated_on' => $created_on, 'created' => date('Y-m-d H:i:s', $created_on), 'updated' => date('Y-m-d H:i:s', $created_on), 'comments_enabled' => $this->input->post('comments_enabled'), 'author_id' => $author_id, 'type' => $this->input->post('type'), 'parsed' => $this->input->post('type') == 'markdown' ? parse_markdown($this->input->post('body')) : '', 'preview_hash' => $hash);
         if ($this->streams->entries->update_entry($id, $_POST, 'blog', 'blogs', array('updated'), $extra)) {
             $this->session->set_flashdata(array('success' => sprintf(lang('blog:edit_success'), $this->input->post('title'))));
             // Blog article has been updated, may not be anything to do with publishing though
             Events::trigger('post_updated', $id);
             // They are trying to put this live
             if ($post->status != 'live' and $this->input->post('status') == 'live') {
                 // Fire an event, we're posting a new blog!
                 Events::trigger('post_published', $id);
             }
         } else {
             $this->session->set_flashdata('error', lang('blog:edit_error'));
         }
         // Redirect back to the form or main page
         $this->input->post('btnAction') == 'save_exit' ? redirect('admin/blog') : redirect('admin/blog/edit/' . $id);
     }
     // Go through all the known fields and get the post values
     foreach ($this->validation_rules as $key => $field) {
         if (isset($_POST[$field['field']])) {
             $post->{$field}['field'] = set_value($field['field']);
         }
     }
     $post->created_on = $created_on;
     // Set Values
     $values = $this->fields->set_values($stream_fields, $post, 'edit');
     // Run stream field events
     $this->fields->run_field_events($stream_fields, array(), $values);
     $this->template->title($this->module_details['name'], sprintf(lang('blog:edit_title'), $post->title))->append_metadata($this->load->view('fragments/wysiwyg', array(), true))->append_js('jquery/jquery.tagsinput.js')->append_js('module::blog_form.js')->set('stream_fields', $this->streams->fields->get_stream_fields($stream->stream_slug, $stream->stream_namespace, $values, $post->id))->append_css('jquery/jquery.tagsinput.css')->set('post', $post)->build('admin/form');
 }
Example #5
0
 public function pre_save($input)
 {
     return Keywords::process($input);
 }
Example #6
0
 /**
  * Edit news post
  *
  * @param int $id The ID of the news post to edit
  */
 public function edit($id = 0)
 {
     $id or redirect('admin/news');
     $post = $this->news_m->get($id);
     // They are trying to put this live
     if ($post->status != 'live' and $this->input->post('status') == 'live') {
         role_or_die('news', 'put_live');
     }
     // If we have keywords before the update, we'll want to remove them from keywords_applied
     $old_keywords_hash = trim($post->keywords) != '' ? $post->keywords : null;
     $post->keywords = Keywords::get_string($post->keywords);
     // If we have a useful date, use it
     if ($this->input->post('created_on')) {
         $created_on = strtotime(sprintf('%s %s:%s', $this->input->post('created_on'), $this->input->post('created_on_hour'), $this->input->post('created_on_minute')));
     } else {
         $created_on = $post->created_on;
     }
     // Load up streams
     $this->load->driver('Streams');
     $stream = $this->streams->streams->get_stream('news', 'news');
     $stream_fields = $this->streams_m->get_stream_fields($stream->id, $stream->stream_namespace);
     // Get the validation for our custom news fields.
     $news_validation = $this->streams->streams->validation_array($stream->stream_slug, $stream->stream_namespace, 'new');
     $news_validation = array_merge($this->validation_rules, array('title' => array('field' => 'title', 'label' => 'lang:global:title', 'rules' => 'trim|htmlspecialchars|required|max_length[100]|callback__check_title[' . $id . ']'), 'slug' => array('field' => 'slug', 'label' => 'lang:global:slug', 'rules' => 'trim|required|alpha_dot_dash|max_length[100]|callback__check_slug[' . $id . ']')));
     // Upload image validation
     if ($_FILES) {
         $allowed = array('.jpg', '.jpeg', '.gif', '.png');
         $upload_key = array_keys($_FILES);
         if (!empty($_FILES[$upload_key[0]]['name']) && $_FILES[$upload_key[0]]['error'] == UPLOAD_ERR_OK) {
             $ext = strtolower(strrchr($_FILES[$upload_key[0]]['name'], '.'));
             if (!in_array($ext, $allowed)) {
                 $this->form_validation->set_error('Invalid image file extension. Allowed extension are .jpg, .jpeg, .png, .gif');
             }
         }
     }
     // Merge and set our validation rules
     $this->form_validation->set_rules(array_merge($this->validation_rules, $news_validation));
     $hash = $this->input->post('preview_hash');
     if ($this->input->post('status') == 'draft' and $this->input->post('preview_hash') == '') {
         $hash = $this->_preview_hash();
     } elseif ($this->input->post('status') == 'live') {
         $hash = '';
     }
     if ($this->form_validation->run()) {
         $author_id = empty($post->display_name) ? $this->current_user->id : $post->author_id;
         $extra = array('title' => $this->input->post('title'), 'slug' => $this->input->post('slug'), 'category_id' => $this->input->post('category_id'), 'keywords' => Keywords::process($this->input->post('keywords'), $old_keywords_hash), 'body' => $this->input->post('body'), 'status' => $this->input->post('status'), 'created_on' => $created_on, 'updated_on' => $created_on, 'created' => date('Y-m-d H:i:s', $created_on), 'updated' => date('Y-m-d H:i:s', $created_on), 'comments_enabled' => $this->input->post('comments_enabled'), 'author_id' => $author_id, 'type' => $this->input->post('type'), 'parsed' => $this->input->post('type') == 'markdown' ? parse_markdown($this->input->post('body')) : '', 'preview_hash' => $hash);
         if ($this->streams->entries->update_entry($id, $_POST, 'news', 'news', array('updated'), $extra)) {
             // Upload image
             if ($_FILES) {
                 $upload_key = array_keys($_FILES);
                 if (!empty($_FILES[$upload_key[0]]['name']) && $_FILES[$upload_key[0]]['error'] == UPLOAD_ERR_OK) {
                     $tmp_name = $_FILES[$upload_key[0]]['tmp_name'];
                     $ext = strtolower(strrchr($_FILES[$upload_key[0]]['name'], '.'));
                     $file_name = 'IMG_' . date('Ymd_His') . $ext;
                     if (@move_uploaded_file($tmp_name, $this->_news_base_file_dir . '/' . $file_name)) {
                         @unlink($this->_news_base_file_dir . '/' . $post->image);
                         $this->db->update('news', array('image' => $file_name), array('id' => $id));
                     }
                 }
             }
             $this->session->set_flashdata(array('success' => sprintf(lang('news:edit_success'), $this->input->post('title'))));
             // news article has been updated, may not be anything to do with publishing though
             Events::trigger('post_updated', $id);
             // They are trying to put this live
             if ($post->status != 'live' and $this->input->post('status') == 'live') {
                 // Fire an event, we're posting a new news!
                 Events::trigger('post_published', $id);
             }
         } else {
             $this->session->set_flashdata('error', lang('news:edit_error'));
         }
         // Redirect back to the form or main page
         $this->input->post('btnAction') == 'save_exit' ? redirect('admin/news') : redirect('admin/news/edit/' . $id);
     }
     // Go through all the known fields and get the post values
     foreach ($this->validation_rules as $key => $field) {
         if (isset($_POST[$field['field']])) {
             $post->{$field}['field'] = set_value($field['field']);
         }
     }
     if (file_exists(UPLOAD_PATH . 'news/' . $post->image) && is_file(UPLOAD_PATH . 'news/' . $post->image)) {
         $image = $this->_news_base_file_dir . '/' . $post->image;
         $this->load->model('files/image_m');
         $post->image = $this->_news_base_file_url . '/' . $post->image;
         $post->thumb = $this->image_m->resize($image, 100, 100, 'crop');
     }
     $post->created_on = $created_on;
     // Set Values
     $values = $this->fields->set_values($stream_fields, $post, 'edit');
     // Run stream field events
     $this->fields->run_field_events($stream_fields, array(), $values);
     $this->template->title($this->module_details['name'], sprintf(lang('news:edit_title'), $post->title))->append_metadata($this->load->view('fragments/wysiwyg', array(), true))->append_js('jquery/jquery.tagsinput.js')->append_js('module::news_form.js')->set('stream_fields', $this->streams->fields->get_stream_fields($stream->stream_slug, $stream->stream_namespace, $values, $post->id))->append_css('jquery/jquery.tagsinput.css')->set('post', $post)->build('admin/form');
 }
Example #7
0
 /**
  * Update a Page
  *
  * 
  * @param int $id The ID of the page to update
  * @param array $input The data to update
  * @return void
  */
 public function edit($id, $input)
 {
     $this->db->trans_start();
     if (!empty($input['is_home'])) {
         // Remove other homepages so this one can have the spot
         $this->skip_validation = true;
         $this->update_by('is_home', 1, array('is_home' => 0));
     }
     // validate the data and update
     $result = $this->update($id, array('slug' => $input['slug'], 'title' => $input['title'], 'uri' => null, 'parent_id' => (int) $input['parent_id'], 'layout_id' => (int) $input['layout_id'], 'css' => isset($input['css']) ? $input['css'] : null, 'js' => isset($input['js']) ? $input['js'] : null, 'meta_title' => isset($input['meta_title']) ? $input['meta_title'] : '', 'meta_keywords' => isset($input['meta_keywords']) ? Keywords::process($input['meta_keywords'], isset($input['old_keywords_hash']) ? $input['old_keywords_hash'] : null) : '', 'meta_description' => isset($input['meta_description']) ? $input['meta_description'] : '', 'rss_enabled' => !empty($input['rss_enabled']), 'comments_enabled' => !empty($input['comments_enabled']), 'status' => $input['status'], 'updated_on' => now(), 'restricted_to' => isset($input['restricted_to']) ? implode(',', $input['restricted_to']) : '0', 'strict_uri' => !empty($input['strict_uri']), 'is_home' => !empty($input['is_home'])));
     // did it pass validation?
     if (!$result) {
         return false;
     }
     $this->build_lookup($id);
     // now insert this page's chunks
     $input['page_id'] = $id;
     $this->page_chunk_m->create($input);
     $this->db->trans_complete();
     return (bool) $this->db->trans_status();
 }