https://t.me/RX1948
Server : Apache/2.4.18 (Ubuntu)
System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64
User : oppastar ( 1041)
PHP Version : 7.0.33-0ubuntu0.16.04.15
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
Directory :  /proc/self/root/var/www/laciasmara.com/public_html/shop/application/controllers/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/self/root/var/www/laciasmara.com/public_html/shop/application/controllers/admin/Blog.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Blog extends Admin_Controller
{

	//this property is used for validating existing blog title on call back edit blog
	private $blog_current_id = NULL;
	private $image1_filename = NULL;
	private $image2_filename = NULL;
	private $image_konten2_filename = NULL;
	private $image_konten3_filename = NULL;

	//this property is to mark whether we are uploading image in the index page
	private $imageupload_indexpage = FALSE;

	function __construct()
	{
		parent::__construct();
		$this->load->model('blog_m');
		$this->load->helper('form');
	}

	//this is to list all blog
	public function index()
	{

		if (isset($_POST['submit'])) {

			$this->imageupload_indexpage = TRUE;

			//get max image width and height from configuration table
			$this->db->select('blog_image_width, blog_image_height')->from('configuration')->where('id_configuration', 1);
			$image_dimension = $this->db->get()->row();

			//check & processing image banner upload files	
			if ($_FILES['userfile']['size'] !== 0) {

				$config['upload_path'] = './uploads/blog/';
				$config['allowed_types'] = 'jpg|png';
				$config['max_size']	= '300';
				$config['max_width'] = $image_dimension->blog_image_width;
				$config['max_height'] = $image_dimension->blog_image_height;

				$this->load->library('upload', $config);

				if (!$this->upload->do_upload()) {

					//echo $this->upload->display_errors(); die();

					$this->session->set_flashdata('banner_error', '<br>
						<p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');

					if ($this->blog_current_id != NULL) {
						redirect('admin/blog/edit/' . $this->blog_current_id);
					} elseif ($this->blog_current_id == NULL && $this->imageupload_indexpage == FALSE) {
						redirect('admin/blog/add');
					} elseif ($this->blog_current_id == NULL && $this->imageupload_indexpage == TRUE) {
						redirect('admin/blog');
					}
				} else {
					$image = $this->upload->data();
					$image_filename = $image['file_name'];
				}
			}

			//store image information to configuration table
			$data = array(
				'blog_landingpage_link' => $this->security->xss_clean($this->input->post('banner_link')),
				'blog_landingpage_description'	=> $this->security->xss_clean($this->input->post('description')),
			);

			//image upload
			if (isset($image_filename)) {
				$data['blog_landingpage_image'] = $image_filename;
			}

			$this->db->where('id_configuration', 1);
			$this->db->update('configuration', $data);

			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Blog Landing Page Edit Successful</p>');
		}

		//get landingpage banner image, description and link
		$this->db->select('blog_landingpage_description, blog_landingpage_image, blog_landingpage_link')->from('configuration')->where('id_configuration', 1);
		$this->data['blog_landingpage'] = $this->db->get()->row();

		//pagination in action. 100 results per page 
		$this->load->library('pagination');
		$config['base_url'] = base_url() . 'admin/blog/index';
		$config['total_rows'] = $this->blog_m->record_count();
		$config['per_page'] = 100;
		$config["uri_segment"] = 4;
		$config['num_tag_open'] = '<span style="padding-left:10px; padding-right:10px">';
		$config['num_tag_close'] = '</span>';

		$this->pagination->initialize($config);
		$this->data['blog'] = $this->blog_m->get_all_blog(
			$config["per_page"],
			$this->uri->segment(4)
		);

		//load view
		$this->data['subview'] = 'admin/blog/index';
		$this->load->view('admin/templates/header', $this->data_header);
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');
	}

	//to add a new blog 
	public function add()
	{
		$this->data['blog'] = $this->blog_m->get_new();

		//validation in action
		//validation check in action 
		$config = $this->blog_m->rules;

		$this->load->library('form_validation');
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>'); //above is to add class to form validation error, to be styled

		$this->form_validation->set_rules($config);
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

		if ($this->form_validation->run($this) == TRUE) {

			//get max image width and height from configuration table
			$this->db->select('blog_image_width, blog_image_height, blog_thumbnail_width, blog_thumbnail_height')->from('configuration')->where('id_configuration', 1);
			$image_dimension = $this->db->get()->row();

			//check & processing IMAGE INTRO
			if ($_FILES['image1']['size'] !== 0) {

				$config['upload_path'] = './uploads/blog/';
				$config['allowed_types'] = 'jpg|png';
				$config['max_size']	= '300';
				$config['max_width'] = $image_dimension->blog_image_width;
				$config['max_height'] = $image_dimension->blog_image_height;

				$this->load->library('upload', $config);

				if (!$this->upload->do_upload('image1')) {

					// return the error message and kill the script
					//echo $this->upload->display_errors(); 

					$this->session->set_flashdata('image1-error', '<br>
					<p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
					redirect('admin/blog/add');
				} else {
					$image1 = $this->upload->data();
					$this->image1_filename = $image1['file_name'];
				}
			}

			//check & processing IMAGE TOP BANNER
			if ($_FILES['image2']['size'] !== 0) {

				$config['upload_path'] = './uploads/blog/';
				$config['allowed_types'] = 'jpg|png';
				$config['max_size']	= '500';
				$config['max_width'] = $image_dimension->blog_image_width;
				$config['max_height'] = $image_dimension->blog_image_height;

				$this->load->library('upload', $config);

				if (!$this->upload->do_upload('image2')) {

					// return the error message and kill the script
					//echo $this->upload->display_errors(); 

					$this->session->set_flashdata('image2-error', '<br>
					<p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
					redirect('admin/blog/add');
				} else {
					$image2 = $this->upload->data();
					$this->image2_filename = $image2['file_name'];
				}
			}

			//check & processing IMAGE TOP BANNER
			if ($_FILES['image_konten2']['size'] !== 0) {

				$config['upload_path'] = './uploads/blog/';
				$config['allowed_types'] = 'jpg|png';
				$config['max_size']	= '500';
				$config['max_width'] = '1000';
				$config['max_height'] = '565';

				$this->load->library('upload', $config);

				if (!$this->upload->do_upload('image_konten2')) {

					// return the error message and kill the script
					//echo $this->upload->display_errors(); 

					$this->session->set_flashdata('image_konten2', '<br>
					<p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
					redirect('admin/blog/add');
				} else {
					$image_konten2 = $this->upload->data();
					$this->image_konten2_filename = $image_konten2['file_name'];
				}
			}

			//check & processing IMAGE TOP BANNER
			if ($_FILES['image_konten3']['size'] !== 0) {

				$config['upload_path'] = './uploads/blog/';
				$config['allowed_types'] = 'jpg|png';
				$config['max_size']	= '500';
				$config['max_width'] = '1000';
				$config['max_height'] = '565';

				$this->load->library('upload', $config);

				if (!$this->upload->do_upload('image_konten3')) {

					// return the error message and kill the script
					//echo $this->upload->display_errors(); 

					$this->session->set_flashdata('image_konten3', '<br>
					<p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
					redirect('admin/blog/add');
				} else {
					$image_konten3 = $this->upload->data();
					$this->image_konten3_filename = $image_konten3['file_name'];
				}
			}

			$data = $this->table_data_processing($this->input->post('blog_name'), $this->input->post('author'), $this->input->post('status'), $this->input->post('description'), $this->image1_filename, $this->image2_filename, $this->input->post('meta_description'), $this->input->post('meta_keywords'), $this->input->post('publish_date'));

			$this->blog_m->add_blog($data);

			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Blog Add Successful</p>');

			$blog_name = $this->input->post('blog_name');

			$user_id = $this->session->userdata('admin')['id'];
			$activity = 'User menambah artikel (' . $blog_name . ')';

			log_activity($user_id, $activity);

			redirect('admin/blog');
		}
		$this->data['subview'] = 'admin/blog/edit';
		$this->load->view('admin/templates/header', $this->data_header);
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');
	}

	//to edit blog in admin
	public function edit($id = NULL)
	{

		if ($id == NULL) {
			show_404();
		}

		//check if id exist. If not exist, show 404.
		$count = $this->blog_m->count_exist($id);

		if ($count == 0) {
			//page not exist
			show_404();
		}

		$this->data['blog'] = $this->blog_m->get($id);

		$this->blog_current_id = (int) $id;

		//validation check in action
		$config = $this->blog_m->rules;

		$this->load->library('form_validation');
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>'); //above is to add class to form validation error, to be styled

		$this->form_validation->set_rules($config);
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

		if ($this->form_validation->run($this) == TRUE) {

			//get max image width and height from configuration table
			$this->db->select('blog_image_width, blog_image_height, blog_thumbnail_width, blog_thumbnail_height')->from('configuration')->where('id_configuration', 1);
			$image_dimension = $this->db->get()->row();

			//check & processing IMAGE INTRO
			if ($_FILES['image1']['size'] !== 0) {

				$config['upload_path'] = './uploads/blog/';
				$config['allowed_types'] = 'jpg|png';
				$config['max_size']	= '300';
				$config['max_width'] = $image_dimension->blog_image_width;
				$config['max_height'] = $image_dimension->blog_image_height;

				$this->load->library('upload', $config);

				if (!$this->upload->do_upload('image1')) {

					// return the error message and kill the script
					echo $this->upload->display_errors();
					exit();

					$this->session->set_flashdata('image1-error', '<br>
					<p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
					redirect('admin/blog/edit/' . $id);
				} else {
					$image1 = $this->upload->data();
					$this->image1_filename = $image1['file_name'];
				}
			}

			//check & processing IMAGE TOP BANNER
			if ($_FILES['image2']['size'] !== 0) {

				$config['upload_path'] = './uploads/blog/';
				$config['allowed_types'] = 'jpg|png';
				$config['max_size']	= '500';
				$config['max_width'] = $image_dimension->blog_image_width;
				$config['max_height'] = $image_dimension->blog_image_height;

				$this->load->library('upload', $config);

				if (!$this->upload->do_upload('image2')) {

					// return the error message and kill the script
					echo $this->upload->display_errors();
					exit();

					$this->session->set_flashdata('image2-error', '<br>
					<p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
					redirect('admin/blog/edit/' . $id);
				} else {
					$image2 = $this->upload->data();
					$this->image2_filename = $image2['file_name'];
				}
			}

			//check & processing IMAGE TOP BANNER
			if ($_FILES['image_konten2']['size'] !== 0) {

				$config['upload_path'] = './uploads/blog/';
				$config['allowed_types'] = 'jpg|png';
				$config['max_size']	= '500';
				$config['max_width'] = '1000';
				$config['max_height'] = '565';

				$this->load->library('upload', $config);

				if (!$this->upload->do_upload('image_konten2')) {

					// return the error message and kill the script
					//echo $this->upload->display_errors(); 

					$this->session->set_flashdata('image_konten2', '<br>
					<p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
					redirect('admin/blog/add');
				} else {
					$image_konten2 = $this->upload->data();
					$this->image_konten2_filename = $image_konten2['file_name'];
				}
			}

			//check & processing IMAGE TOP BANNER
			if ($_FILES['image_konten3']['size'] !== 0) {

				$config['upload_path'] = './uploads/blog/';
				$config['allowed_types'] = 'jpg|png';
				$config['max_size']	= '500';
				$config['max_width'] = '1000';
				$config['max_height'] = '565';

				$this->load->library('upload', $config);

				if (!$this->upload->do_upload('image_konten3')) {

					// return the error message and kill the script
					//echo $this->upload->display_errors(); 

					$this->session->set_flashdata('image_konten3', '<br>
					<p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
					redirect('admin/blog/add');
				} else {
					$image_konten3 = $this->upload->data();
					$this->image_konten3_filename = $image_konten3['file_name'];
				}
			}

			$data = $this->table_data_processing($this->input->post('blog_name'), $this->input->post('author'), $this->input->post('status'), $this->input->post('description'), $this->image1_filename, $this->image2_filename, $this->input->post('meta_description'), $this->input->post('meta_keywords'), $this->input->post('publish_date'));

			$this->blog_m->edit_blog($id, $data);

			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Blog Edit Successful</p>');

			$blog_name = $this->input->post('blog_name');

			$user_id = $this->session->userdata('admin')['id'];
			$activity = 'User mengedit artikel (' . $blog_name . ')';

			log_activity($user_id, $activity);

			redirect('admin/blog/edit/' .  $id);
		}

		$this->data['subview'] = 'admin/blog/edit';
		$this->load->view('admin/templates/header', $this->data_header);
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');
	}


	//to delete a blog
	public function delete($id)
	{
		//check if id exist. If not exist, show 404.
		$count = $this->blog_m->count_exist($id);

		if ($count == 0) { //page not exist
			show_404();
		}

		//delete image from server
		//check if there is an existing image
		$this->db->select('image1, image2')->from('blog')->where('id_blog', (int) $id);
		$image = $this->db->get()->row();

		if ($image->image1 != '') {
			//Delete the actual image file from server. FCPATH is codeigniter base path
			unlink(FCPATH . '/uploads/blog/' . $image->image1);
		}

		if ($image->image2 != '') {
			//Delete the actual image file from server. FCPATH is codeigniter base path
			unlink(FCPATH . '/uploads/blog/' . $image->image2);
		}
		//logging
		$user_id = $this->session->userdata('admin')['id'];

		$this->db->select('blog');
		$this->db->from('blog');
		$this->db->where('id_blog', $id);
		$query = $this->db->get();
		$data = $query->row();

		if ($data) {
			$activity = 'User menghapus artikel (' . $data->blog . ')';
		} else {
			$activity = 'User menghapus artikel (' . $id . ')';
		}

		log_activity($user_id, $activity);
		//delete blog
		$this->blog_m->delete($id);
		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Blog Delete Successful</p>');
		redirect('admin/blog');
	}

	private function table_data_processing(
		$blog_name,
		$author,
		$status,
		$description,
		$image1_filename,
		$image2_filename,
		$meta_description,
		$meta_keywords,
		$publish_date
	) {

		$publish_date = explode('-', $publish_date);
		$publish_date = $publish_date[2] . '-' . $publish_date[1] . '-' . $publish_date[0];

		$data = array(
			'blog' 			=> $this->security->xss_clean($blog_name),
			'blog_en' 		=> $this->security->xss_clean($this->input->post('blog_name_en')),
			'short_description' 	=> $this->security->xss_clean($this->input->post('short_description')),
			'short_description_en' => $this->security->xss_clean($this->input->post('short_description_en')),
			'author'		=> $author,
			'alias' 		=> url_title($blog_name),
			'alias_en' 		=> url_title($this->input->post('blog_name_en')),
			'status' 		=> $status,
			'description' 	=> $description,
			'description_en' => $this->security->xss_clean($this->input->post('description_en')),
			'description2' 	=> $this->security->xss_clean($this->input->post('description2')),
			'description2_en' => $this->security->xss_clean($this->input->post('description2_en')),
			'description3' 	=> $this->security->xss_clean($this->input->post('description3')),
			'description3_en' => $this->security->xss_clean($this->input->post('description3_en')),
			'publish_date' 	=> $publish_date,
			'featured' 		=> url_title($this->input->post('featured')),
			'image_konten2_caption' => $this->security->xss_clean($this->input->post('image_konten2_caption')),
			'image_konten3_caption' => $this->security->xss_clean($this->input->post('image_konten3_caption')),
			'image_konten2_caption_en' => $this->security->xss_clean($this->input->post('image_konten2_caption_en')),
			'image_konten3_caption_en' => $this->security->xss_clean($this->input->post('image_konten3_caption_en')),
			'video_link' => $this->security->xss_clean($this->input->post('video_link'))
		);

		//image upload
		if (isset($image1_filename)) {
			$data['image1'] = $image1_filename;
		}

		//image upload
		if (isset($image2_filename)) {
			$data['image2'] = $image2_filename;
		}

		//image upload
		if ($this->image_konten2_filename != NULL) {
			$data['image_konten2'] = $this->image_konten2_filename;
		}

		//image upload
		if ($this->image_konten3_filename != NULL) {
			$data['image_konten3'] = $this->image_konten3_filename;
		}

		return $data;
	}

	//callback function validation add new blog
	//make it private by adding _
	public function _cek_existing_blog_title($str)
	{

		$num_rows = $this->blog_m->cek_existing_blog_title($str, $this->blog_current_id);
		if ($num_rows != 0) {
			$this->form_validation->set_message('_cek_existing_blog_title', 'blog name already exist !');
			return FALSE;
		} else {
			return TRUE;
		}
	}

	public function _cek_existing_blog_title_en($str)
	{

		$num_rows = $this->blog_m->cek_existing_blog_title_en($str, $this->blog_current_id);
		if ($num_rows != 0) {
			$this->form_validation->set_message('_cek_existing_blog_title_en', 'blog name english already exist !');
			return FALSE;
		} else {
			return TRUE;
		}
	}

	//To delete blog landingpage banner image file from server, and from database
	public function delete_landingpage_image()
	{

		//get image file name for deletion
		$this->db->select('blog_landingpage_image')->from('configuration')->where('id_configuration', 1);
		$image = $this->db->get()->row()->blog_landingpage_image;

		//Delete the actual image file from server. FCPATH is codeigniter base path
		unlink(FCPATH . '/uploads/blog/' . $image);

		//Delete image field from database
		$data = array(
			'blog_landingpage_image' => '',
		);

		$this->db->where('id_configuration', 1);
		$this->db->update('configuration', $data);

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Image Delete Successful</p>');

		redirect('admin/blog');
	}

	//To delete blog image file from server, and from database
	public function delete_image($id = NULL, $image_type = NULL)
	{

		$count = $this->blog_m->count_exist($id);

		if ($id == NULL || $count == 0) {
			redirect('admin/blog');
		}

		if ($image_type == NULL) {
			redirect('admin/blog');
		}

		//get image file name for deletion
		$this->db->select('image1, image2, image_konten2, image_konten3')->from('blog')->where('id_blog', (int) $id);
		$image = $this->db->get()->row();

		if ($image_type == 'image1') {
			//Delete the actual image file from server. FCPATH is codeigniter base path
			unlink(FCPATH . '/uploads/blog/' . $image->image1);

			//Delete image field from database
			$data = array(
				'image1' => '',
			);
		} elseif ($image_type == 'image2') {
			//Delete the actual image file from server. FCPATH is codeigniter base path
			unlink(FCPATH . '/uploads/blog/' . $image->image2);

			//Delete image field from database
			$data = array(
				'image2' => '',
			);
		} elseif ($image_type == 'image_konten2') {
			//Delete the actual image file from server. FCPATH is codeigniter base path
			unlink(FCPATH . '/uploads/blog/' . $image->image_konten2);

			//Delete image field from database
			$data = array(
				'image_konten2' => '',
			);
		} elseif ($image_type == 'image_konten3') {
			//Delete the actual image file from server. FCPATH is codeigniter base path
			unlink(FCPATH . '/uploads/blog/' . $image->image_konten3);

			//Delete image field from database
			$data = array(
				'image_konten3' => '',
			);
		}

		$this->db->where('id_blog', (int) $id);
		$this->db->update('blog', $data);

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Image Delete Successful</p>');

		redirect('admin/blog/edit/' . $id);
	}
}

https://t.me/RX1948 - 2025