Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Untuk membersihkan data dari Form_Input
- (1) tools_helper
- function id_clean($id,$size=11){
- return intval(substr($id,0,$size));
- }
- function db_clean($string,$size=255){
- return xss_clean(substr($string,0,$size));
- }
- function createfoldername($string){
- $string = mb_strtolower($string,'utf-8');
- $regexp = '/( |g)/iU';
- // $regexp = '/( |å|ø|æ|Å|Ø|Æ|Ã¥|ø|æ|Ã…|Ø|Æ)/iU';
- $replace_char = '_';
- $data = preg_replace($regexp, $replace_char, $string);
- return $data;
- }
- /*
- * This will replace non English to similar letter in English
- *
- */
- function createdirname($string){
- $forbidden = array(" ", "å", "Å","ø", "Ø", "æ", "Æ", "ã…", "ã˜","ã†", "ã¥", "ã¸", "ã¦" );
- // order is space, å, Å,ø, Ø,æ, Æ, and Å, Ø, Æ, å,ø,æ
- $normal = array("_", "aa", "aa", "o", "o", "ae", "ae","aa","o", "ae", "aa", "o", "ae" );
- $string = str_replace($forbidden, $normal, $string);
- $data = mb_strtolower($string,'utf-8');
- return $data;
- }
- function create_path($folder)
- {
- // create dir if not exists
- $folder = explode( "/" , $folder );
- $mkfolder = "";
- //sets the complete directory path
- for( $i=0 ; isset( $folder[$i] ) ; $i++ )
- {
- $mkfolder .= $folder[$i] . '/';
- if(!is_dir($mkfolder )) {
- mkdir("$mkfolder");
- mkdir("$mkfolder/thumbnails");
- }
- }
- }
- function recursive_remove_directory($directory, $empty=FALSE)
- {
- // if the path has a slash at the end we remove it here
- if(substr($directory,-1) == '/')
- {
- $directory = substr($directory,0,-1);
- }
- // if the path is not valid or is not a directory ...
- if(!file_exists($directory) || !is_dir($directory))
- {
- // ... we return false and exit the function
- return FALSE;
- // ... if the path is not readable
- }elseif(!is_readable($directory))
- {
- // ... we return false and exit the function
- return FALSE;
- // ... else if the path is readable
- }else{
- // we open the directory
- $handle = opendir($directory);
- // and scan through the items inside
- while (FALSE !== ($item = readdir($handle)))
- {
- // if the filepointer is not the current directory
- // or the parent directory
- if($item != '.' && $item != '..')
- {
- // we build the new path to delete
- $path = $directory.'/'.$item;
- // if the new path is a directory
- if(is_dir($path))
- {
- // we call this function with the new path
- // you need to change to $this->recursive_remove_directory($path);
- // in controller.
- recursive_remove_directory($path);
- // if the new path is a file
- }else{
- // we remove the file
- unlink($path);
- }
- }
- }
- // close the directory
- closedir($handle);
- // if the option to empty is not set to true
- if($empty == FALSE)
- {
- // try to delete the now empty directory
- if(!rmdir($directory))
- {
- // return false if not possible
- return FALSE;
- }
- }
- // return success
- return TRUE;
- }
- }
- function findOrphans($id, $orphan_id, $db_table){
- // delete a customer from omc_customer table
- // if $db_table is omc_customer, this will create customer_id
- // then find customer_id in omc_order table to find orphans
- /**
- * delete an order from omc_order table. this will create order_items orphans in omc_order_item
- * find order_item where order_id is
- *
- *
- */
- $tablename = explode("-", $db_table);
- $tableid = $tablename[1]."_id";
- // or
- // $id_name = preg_replace('/.*_(.*)/', '${1}_id', $db_table);
- $data = array();
- // $this->db->select($tableid.',name');
- $this->db->select($tableid,'name');
- $this->db->where($orphan_id,id_clean($id));
- $Q = $this->db->get($db_table);
- if ($Q->num_rows() > 0){
- foreach ($Q->result_array() as $row){
- $data[$row['id']] = $row['name'];
- }
- }
- $Q->free_result();
- return $data;
- }
- function convert_image_path ($imageinfo){
- $str = $imageinfo;
- $m = array();
- if (preg_match('#<.*?/([^\.]+\.(jpg|jpeg|gif|png))"#', $str, $m)) {
- $image = $m[1];
- }else{
- $image = $imageinfo;
- }
- $tags = array("<p>", "</p>");
- $image = str_replace($tags, "", $image);
- return $image;
- }
- function multiple_img ($image_path){
- $search = array("../../../");
- $new_images = str_replace($search,"",$image_path);
- return $new_images;
- }
- (2) Hal tersebut, di-dasarkan dari security php
- if ( ! function_exists('xss_clean'))
- {
- function xss_clean($str, $is_image = FALSE)
- {
- $CI =& get_instance();
- return $CI->security->xss_clean($str, $is_image);
- }
- }
- // ------------------------------------------------------------------------
- /**
- * Sanitize Filename
- *
- * @access public
- * @param string
- * @return string
- */
- if ( ! function_exists('sanitize_filename'))
- {
- function sanitize_filename($filename)
- {
- $CI =& get_instance();
- return $CI->security->sanitize_filename($filename);
- }
- }
- // --------------------------------------------------------------------
- /**
- * Hash encode a string
- *
- * @access public
- * @param string
- * @return string
- */
- if ( ! function_exists('do_hash'))
- {
- function do_hash($str, $type = 'sha1')
- {
- if ($type == 'sha1')
- {
- return sha1($str);
- }
- else
- {
- return md5($str);
- }
- }
- }
- // ------------------------------------------------------------------------
- /**
- * Strip Image Tags
- *
- * @access public
- * @param string
- * @return string
- */
- if ( ! function_exists('strip_image_tags'))
- {
- function strip_image_tags($str)
- {
- $str = preg_replace("#<img\s+.*?src\s*=\s*[\"'](.+?)[\"'].*?\>#", "\\1", $str);
- $str = preg_replace("#<img\s+.*?src\s*=\s*(.+?).*?\>#", "\\1", $str);
- return $str;
- }
- }
- // ------------------------------------------------------------------------
- /**
- * Convert PHP tags to entities
- *
- * @access public
- * @param string
- * @return string
- */
- if ( ! function_exists('encode_php_tags'))
- {
- function encode_php_tags($str)
- {
- return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('<?php', '<?PHP', '<?', '?>'), $str);
- }
- }
- /* End of file security_helper.php */
- /* Location: ./system/helpers/security_helper.php */
- (3) contoh penggunaan :
- function tambah()
- {
- if(isset($_POST['simpan']))
- {
- $client = db_clean($this->input->post('client'));
- $type = db_clean($this->input->post('id_type_client'));
- $jenis = db_clean($this->input->post('id_jenis_client'));
- if ((!is_null($client)) && (!is_null($type)) && (!is_null($jenis)))
- $proses = TRUE;
- else $proses = FALSE;
- if ($proses)
- {
- $propinsi = db_clean($this->input->post('provinsi_id'));
- $kota = db_clean($this->input->post('kota_id'));
- $carikota = $this->m_all->cari($kota, $propinsi, NULL, NULL, NULL, 'kota_id', NULL, NULL, 'kota_kabupaten')->result();
- foreach ($carikota as $row)
- {
- $newkota = $row->kota_id;
- }
- $this->_set_rules_tambah();
- if($this->form_validation->run() == true)
- {
- $arr = array($type, $jenis, $newkota, $propinsi, $client);
- $telp_1 = db_clean($this->input->post('telp_client_1'));
- if (empty($telp_1))
- {
- $telp_1 = NULL;
- }
- $telp_2 = db_clean($this->input->post('telp_client_2'));
- if(empty($telp_2))
- {
- $telp_2 = NULL;
- }
- $pinbbm = db_clean($this->input->post('pin_bbm'));
- if(empty($pinbbm))
- {
- $pinbbm = NULL;
- }
- $alamat = db_clean($this->input->post('alamat'));
- if(empty($alamat))
- {
- $alamat = NULL;
- }
- $tgl = date('Y/m/d');
- $user = $this->session->userdata('username');
- $info = array(
- 'id' => $this->db->insert_id(),
- 'id_client' => join('_', $arr),
- 'client' => $client,
- 'telp_client_1' => $telp_1,
- 'telp_client_2' => $telp_2,
- 'pin_bbm' => $pinbbm,
- 'alamat' => $alamat,
- 'updated' => $tgl,
- 'username' => $user,
- 'keterangan' => db_clean($this->input->post('keterangan')),
- 'hapus' => '0'
- );
- $this->m_all->simpan($info, $this->table);
- echo "<meta http-equiv='refresh' content='0; url=".site_url('data_client/index/add_success')."'>";
- }
- else
- {
- ?>
- <script type="text/javascript">
- alert("Harap Periksa Validitas Data");
- </script>
- <?php
- echo "<meta http-equiv='refresh' content='0; url=".site_url('data_client/tambah')."'>";
- }
- }
- else
- {
- ?>
- <script type="text/javascript">
- alert("Penambahan data tidak boleh kosong");
- </script>
- <?php
- echo "<meta http-equiv='refresh' content='0; url=".site_url('data_client/tambah')."'>";
- }
- }
- if (isset($_POST['cancel']))
- {
- echo "<meta http-equiv='refresh' content='0; url=".site_url('data_client/index')."'>";
- }
- $ktgr_alamat = $this->auth->find_ktgr_alamat('data_client/index', 'menu_uri', 'menu', 'id_kategori', 'kategori_menu');
- $var = explode('+', $ktgr_alamat);
- $data['kategori'] = $var['0'];
- $data['alamat'] = $var['1'];
- $data['alamat1'] = 'data_client/index';
- $data['title']="Index Data Client";
- $data['alamat2'] = 'data_client/tambah';
- $data['title1'] = 'Tambah Data';
- $data['list_type_client'] = $this->m_all->getList('tb_type_client','id_type_client', null,'0');
- $data['list_jns_client'] = $this->m_all->getList('tb_jenis_client','id_jenis_client', null, '0');
- $data['list_propinsi'] = $this->m_all->getList('propinsi','propinsi_id', null, null);
- $this->template->display('data_client/tambah', $data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement