Example #1
0
 public function update_user($id)
 {
     $config['upload_path'] = './uploads/';
     $config['allowed_types'] = 'gif|jpg|png';
     $config['max_size'] = '1000';
     $config['max_width'] = '1024';
     $config['max_height'] = '768';
     $this->load->library('upload', $config);
     if (!$this->upload->do_upload('images')) {
         $error = array('error' => $this->upload->display_errors());
     } else {
         $data_file = array('upload_data' => $this->upload->data());
     }
     $post = new Post();
     $post->title = $this->input->post('title-post');
     $post->slug = url_title($post->title, '-', TRUE);
     $post->content = $this->input->post('content');
     if ($data_file) {
         $post->image_feature = 'uploads/' . $data_file['upload_data']['file_name'];
     }
     $post->updated_at = now();
     $post->updated_by = $this->session->userdata('user_id');
     $post->post_type = 'page';
     $post->flag_sticky = $this->input->post('sticky');
     $post->save();
     if ($this->input->post('categories')) {
         $cats = explode(",", $this->input->post('categories'));
         foreach ($cats as $caty) {
             if (!Category::find_by_title(trim($caty))) {
                 $cat = new Category();
                 $cat->title = trim($caty);
                 $cat->save();
             } else {
                 $cat = Category::find_by_title(trim($caty));
             }
             if (!Post_to_category::find('all', array('post_id' => $post->id, 'category_id' => $cat->id))) {
                 $ptc = new Post_to_category();
                 $ptc->post_id = $post->id;
                 $ptc->category_id = $cat->id;
                 $ptc->save();
             }
         }
     }
     if ($this->input->post('tags')) {
         $tags = explode(",", $this->input->post('tags'));
         foreach ($tags as $tagy) {
             if (!Tag::find_by_title(trim($tagy))) {
                 $tag = new Tag();
                 $tag->title = trim($tagy);
                 $tag->save();
             } else {
                 $tag = Tag::find_by_title(trim($tagy));
             }
             if (!Post_to_tag::find('all', array('post_id' => $post->id, 'tag_id' => $tag->id))) {
                 $ptc = new Post_to_tag();
                 $ptc->post_id = $post->id;
                 $ptc->tag_id = $tag->id;
                 $ptc->save();
             }
         }
     }
     $this->session->set_flashdata('info', 'The Page #' . $post->id . ' has been updated <br/> ' . (isset($error) ? $error['error'] : ''));
     redirect('admin/posts');
 }