function _slug($field) { if ($this->edit_slug()) { return true; } if (!empty($this->slug) && $this->slug !== '__generate__') { return true; } $this->load->helper(array('url', 'text', 'string')); $slug = reduce_multiples(strtolower(url_title(convert_accented_characters($this->title), 'dash')), '-', true); if (empty($slug)) { $t = new Album(); $max = $t->select_max('id')->get(); $slug = $max->id + 1; } if (is_numeric($slug)) { $slug = "{$slug}-1"; } $s = new Slug(); while ($s->where('id', "album.{$slug}")->count() > 0) { $slug = increment_string($slug, '-'); } $this->db->query("INSERT INTO {$s->table}(id) VALUES ('album.{$slug}')"); $this->slug = $slug; }
public function urilizeText($text, $strip_char = '-') { if (!function_exists('stripThing')) { function stripThing($delimiter, $offset, $strip_char) { $newtext = explode($delimiter, $offset); $e = ''; for ($i = 0; $i < count($newtext); $i++) { if ($i + 1 == count($newtext)) { $e .= $newtext[$i]; } else { $e .= $newtext[$i] . $strip_char; } } return $newtext = strtolower($e); } } $newtext = convert_accented_characters($text); $newtext = stripThing('\'', $newtext, $strip_char); $newtext = stripThing(' ', $newtext, $strip_char); $newtext = stripThing('.', $newtext, $strip_char); // Removing question mark to avoid security error. $newtext = stripThing('?', $newtext, $strip_char); $newtext = stripThing('\\n', $newtext, $strip_char); return $newtext; }
function get($filename) { $id = $this->input->get('id'); $token = $this->input->get('token'); //Chequeamos permisos del frontend $file = Doctrine_Query::create()->from('File f, f.Tramite t, t.Etapas e, e.Usuario u')->where('f.id = ? AND f.llave = ? AND u.id = ?', array($id, $token, UsuarioSesion::usuario()->id))->fetchOne(); if (!$file) { //Chequeamos permisos en el backend $file = Doctrine_Query::create()->from('File f, f.Tramite.Proceso.Cuenta.UsuariosBackend u')->where('f.id = ? AND f.llave = ? AND u.id = ? AND (u.rol="super" OR u.rol="operacion" OR u.rol="seguimiento")', array($id, $token, UsuarioBackendSesion::usuario()->id))->fetchOne(); if (!$file) { echo 'Usuario no tiene permisos para ver este archivo.'; exit; } } $path = 'uploads/documentos/' . $file->filename; if (preg_match('/^\\.\\./', $file->filename)) { echo 'Archivo invalido'; exit; } if (!file_exists($path)) { echo 'Archivo no existe'; exit; } $friendlyName = str_replace(' ', '-', convert_accented_characters(mb_convert_case($file->Tramite->Proceso->Cuenta->nombre . ' ' . $file->Tramite->Proceso->nombre, MB_CASE_LOWER) . '-' . $file->id)) . '.' . pathinfo($path, PATHINFO_EXTENSION); header('Content-Type: ' . get_mime_by_extension($path)); header('Content-Length: ' . filesize($path)); header('Content-Disposition: attachment; filename="' . $friendlyName . '"'); readfile($path); }
function VennDiagram($names, $abc, $ab, $bc, $ca, $progress = 0) { $height = 300; $width = 400; $radius = 80; $shiftx = 55; $shifty = 45; $names = convert_accented_characters($names); $svg = '<div class="img-question text-center"> <svg width="' . $width . '" height="' . $height . '">'; // $svg .= '<rect width="'.$width.'" height="'.$height.'" fill="black" fill-opacity="0.2" />'; // Circles $svg .= DrawCircle($width / 2 - $shiftx, $height / 2 - $shifty, $radius); $svg .= DrawCircle($width / 2 + $shiftx, $height / 2 - $shifty, $radius); $svg .= DrawCircle($width / 2, $height / 2 + $shifty, $radius); // Labels $letters = array_map('str_split', $names); $svg .= DrawText($width / 2 - $shiftx * 2.3, $height / 2 - $shifty * 2.3, '$' . $letters[0][0] . '$', 13); $svg .= DrawText($width / 2 + $shiftx * 2.3, $height / 2 - $shifty * 2.3, '$' . $letters[1][0] . '$', 13); $svg .= DrawText($width / 2, $height / 2 + $shifty * 3.2, '$' . $letters[2][0] . '$', 13); $svg .= $progress >= 1 ? DrawText($width / 2, $height / 2 - 5, '$\\color{red}{' . $abc . '}$', 13) : ''; $svg .= $progress >= 2 ? DrawText($width / 2, $height / 2 - $shifty * 1.2, '$\\color{blue}{' . $ab . '}$', 13) : ''; $svg .= $progress >= 3 ? DrawText($width / 2 + $shiftx * 0.7, $height / 2 + 15, '$\\color{blue}{' . $bc . '}$', 13) : ''; $svg .= $progress >= 4 ? DrawText($width / 2 - $shiftx * 0.7, $height / 2 + 15, '$\\color{blue}{' . $ca . '}$', 13) : ''; $svg .= '</svg></div>'; return $svg; }
/** * Renvoie une liste de villes * en fonction du nom partiel donné * */ function get_city($partial_name = null) { //$partial_name = "l'Abergement clémen"; if (isset($_GET['q'])) { $partial_name = $_GET['q']; } //code($partial_name); $this->load->helper('text'); // la chaîne miniaturisée, les espaces au milieu remplacés par des tirets $match_elmt = str_replace(' ', '-', strtolower(trim($partial_name))); $match_elmt = convert_accented_characters($match_elmt); if (substr($match_elmt, 0, 2) == "l'") { $match_elmt = substr($match_elmt, 2); } elseif (substr($match_elmt, 0, 3) == 'le-' || substr($match_elmt, 0, 3) == 'la-') { $match_elmt = substr($match_elmt, 3); } elseif (substr($match_elmt, 0, 4) == 'les-') { $match_elmt = substr($match_elmt, 4); } $q = $this->db->select("geo_" . $this->lang . "_city.id, geo_" . $this->lang . "_city.name_city, geo_" . $this->lang . "_city.cp,\r\n geo_" . $this->lang . "_province.name_province")->from("geo_" . $this->lang . "_city")->join('geo_' . $this->lang . "_province", "geo_" . $this->lang . "_province.code = geo_" . $this->lang . "_city.id_province")->like("city_slug", $match_elmt, 'after')->get(); if ($q->num_rows() > 0) { $result = $q->result(); $arr = array(); foreach ($result as $key => $city) { $arr[] = "{\"id\": \"" . $city->id . "\", \"value\": \"" . $city->name_city . ', ' . $city->name_province . "\", \"info\": \"\"}"; } echo "{\"results\": ["; echo implode(', ', $arr); echo "]}"; } else { echo 'pas de résultats'; } }
/** * Index Page for this controller. * * Maps to the following URL * http://example.com/index.php/welcome * - or - * http://example.com/index.php/welcome/index * - or - * Since this controller is set as the default controller in * config/routes.php, it's displayed at http://example.com/ * * So any other public methods not prefixed with an underscore will * map to /index.php/welcome/<method_name> * @see http://codeigniter.com/user_guide/general/urls.html */ public function get($genid = '') { $id = id_from_genid($genid); //Kullanıcı izni var mı? check_perm($id); $person = $this->db->select('id,name,first_name,last_name,gender,locale')->from('liste')->where('id', $id)->limit('1')->get()->row(); if (!isset($person->id) || $person->id < 1) { show_error("Information Removed or Not Exists", "410", "Sorry for inconvenience"); } $person->picture = site_url('picture/large/' . genid_from_id($person->id)); //$person->picture = "http://graph.facebook.com/".$person->id."/picture?type=large"; $data['person'] = $person; $data['same_last'] = $this->db->select('id,name')->from('liste')->where('last_name', $person->last_name)->where('id !=', $person->id)->limit('28')->get()->result(); $data['same_first'] = $this->db->select('id,name')->from('liste')->where('first_name', $person->first_name)->where('id !=', $person->id)->limit('28')->get()->result(); $data['same_wiki'] = $this->db->select('id,name,short_desc')->from('wiki')->or_where_in('last_name', array($person->first_name, $person->last_name))->limit('28')->get()->result(); //Stats Ekle -> Viewed stats_add($person->id, "viewed"); //$this->template->set_master_template('template_get'); $this->template->write('title', convert_accented_characters($person->name)); $this->template->write('description', 'about ' . convert_accented_characters($person->name)); $this->template->write('name', convert_accented_characters($person->name)); $this->template->write('image', site_url('picture/square/' . genid_from_id($person->id))); $this->template->write('picture', $person->picture); $this->template->write_view('page', 'face/get', $data); $this->template->render(); }
/** * Update an existing category * @access public * @param int $id The ID of the category * @param array $input The data to update * @return bool */ public function update($id, $input) { return parent::update($id, array( 'title' => $input['title'], 'slug' => url_title(strtolower(convert_accented_characters($input['title']))) )); }
function _slug($field) { if ($this->edit_slug()) { return true; } if (!empty($this->old_slug)) { return true; } $this->load->helper(array('url', 'text', 'string')); if (empty($this->title)) { $info = pathinfo($this->filename); $base = $info['filename']; } else { $base = $this->title; } $slug = reduce_multiples(strtolower(url_title(convert_accented_characters($base), 'dash')), '-', true); if ($slug === $this->slug) { return true; } if (empty($slug)) { $t = new Content(); $max = $t->select_max('id')->get(); $slug = $max->id + 1; } if (is_numeric($slug)) { $slug = "{$slug}-1"; } $s = new Slug(); // Need to lock the table here to ensure that requests arriving at the same time // still get unique slugs if ($this->has_db_permission('lock tables')) { $this->db->query("LOCK TABLE {$s->table} WRITE"); $locked = true; } else { $locked = false; } while ($s->where('id', "content.{$slug}")->count() > 0) { $slug = increment_string($slug, '-'); } $this->db->query("INSERT INTO {$s->table}(id) VALUES ('content.{$slug}')"); if ($locked) { $this->db->query('UNLOCK TABLES'); } if (empty($this->old_slug)) { if (!empty($this->slug) && $this->slug !== '__generate__') { $this->old_slug = ',' . $this->slug . ','; } else { if (!empty($this->title)) { $this->old_slug = ',' . $slug . ','; } } } $this->slug = $slug; }
public function img_mapcreator($sayfa = '') { $sayfa = (int) $sayfa; $data = $this->db->select('id,name')->from('liste')->order_by('primary', 'asc')->limit('1000', $sayfa * 1000)->get()->result(); $cikti = '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">'; foreach ($data as $k) { $cikti .= '<url><loc>' . base_url() . 'face/get/' . genid_from_id($k->id) . '/' . url_title($k->name) . "</loc><image:image><image:loc>" . site_url('picture/large/' . genid_from_id($k->id)) . "</image:loc><image:title>Photo of " . convert_accented_characters($k->name) . "</image:title></image:image></url>"; } $cikti .= '</urlset>'; echo $cikti; }
public function create() { $rules = $this->menu_model->rules; $this->form_validation->set_rules($rules['insert']); if ($this->form_validation->run() === FALSE) { $this->render('admin/menus/create_menu_view'); } else { $title = url_title(convert_accented_characters($this->input->post('title')), '-', TRUE); if ($this->menu_model->insert(array('title' => $title, 'created_by' => $this->user_id))) { $this->postal->add('The new menu was created.', 'success'); } redirect('admin/menus'); } }
public function edit($r_id = '') { if ($this->functions->get_loged()) { $this->load->library('form_validation'); $data['user_data'] = $this->functions->get_user_data(); $data['nb_comments'] = $this->functions->get_comments(); $this->form_validation->set_rules('r_title', 'Titre', 'trim|required|callback_check_rubric_title'); $this->form_validation->set_rules('r_description', 'Description', 'trim|required'); $r_title = $this->input->post('r_title'); $r_description = $this->input->post('r_description'); // Add a rubric if ($this->uri->total_segments() == 3) { $data['page'] = 'add_rubric'; $data['title'] = 'Ajouter une rubrique'; $r_url_rw = url_title(convert_accented_characters($r_title), '-', TRUE); if ($this->form_validation->run() !== FALSE) { $this->model_rubric->create_rubric($r_title, $r_description, $r_url_rw); $this->session->set_flashdata('success', 'Rubrique "' . $r_title . '" ajoutée'); redirect(base_url(URL_HOME_RUBRIC)); } } else { $rubric = $this->model_rubric->get_rubric($r_id, '')->row(); // Rubric exists if (!empty($rubric)) { $data['page'] = 'edit_rubric'; $data['content'] = $this->model_content->get_content_by_rubric($r_id); $data['r_id'] = $r_id; $data['r_title'] = $rubric->r_title; $data['r_description'] = $rubric->r_description; $data['r_url_rw'] = $rubric->r_url_rw; $data['title'] = 'Modifier la rubrique ' . $data['r_title']; // Vérification pour l'url $this->form_validation->set_rules('r_url_rw', 'Url', 'trim|required|callback_check_rubric_url_rw'); $r_url_rw = $this->input->post('r_url_rw'); if ($this->form_validation->run() !== FALSE) { $this->model_rubric->update_rubric($r_title, $r_description, $r_url_rw, $r_id); $this->session->set_flashdata('success', 'Rubrique "' . $r_title . '" modifiée.'); redirect(base_url(URL_HOME_RUBRIC)); } // Rubric unknown } else { $this->session->set_flashdata('alert', 'Cette rubrique (#' . $r_id . ') n\'existe plus ou n\'a jamais existé.'); redirect(URL_HOME_RUBRIC); } } $this->load->view(URL_LAYOUT, $data); } }
public function edit($content_id) { $content = $this->content_model->get($content_id); if ($content === FALSE) { $this->postal->add('There is no content to edit.', 'error'); redirect('admin/contents/index', 'refresh'); } $this->data['content'] = $content; $this->data['parents'] = $this->content_model->get_parents_list($content->content_type, $content->id); $this->data['slugs'] = $this->slug_model->where(array('content_type' => $content->content_type, 'content_id' => $content->id))->get_all(); $rules = $this->content_model->rules; $this->form_validation->set_rules($rules['update']); if ($this->form_validation->run() === FALSE) { $this->render('admin/contents/edit_view'); } else { $content_id = $this->input->post('content_id'); $content = $this->content_model->get($content_id); if ($content !== FALSE) { $parent_id = $this->input->post('parent_id'); $title = $this->input->post('title'); $short_title = $this->input->post('short_title'); $slug = url_title(convert_accented_characters($this->input->post('slug')), '-', TRUE); $order = $this->input->post('order'); $text = $this->input->post('content'); $teaser = strlen($this->input->post('teaser')) > 0 ? $this->input->post('teaser') : substr($text, 0, strpos($text, '<!--more-->')); $page_title = strlen($this->input->post('page_title')) > 0 ? $this->input->post('page_title') : $title; $page_description = strlen($this->input->post('page_description')) > 0 ? $this->input->post('page_description') : ellipsize($teaser, 160); $page_keywords = $this->input->post('page_keywords'); $published_at = $this->input->post('published_at'); $update_data = array('title' => $title, 'short_title' => $short_title, 'teaser' => $teaser, 'content' => $text, 'page_title' => $page_title, 'page_description' => $page_description, 'page_keywords' => $page_keywords, 'parent_id' => $parent_id, 'published_at' => $published_at, 'order' => $order); if ($this->content_model->update($update_data, $content_id)) { if (strlen($slug) > 0) { $url = $this->_verify_slug($slug); $new_slug = array('content_type' => $content->content_type, 'content_id' => $content->id, 'url' => $url); if ($slug_id = $this->slug_model->insert($new_slug)) { $this->slug_model->where(array('content_type' => $content->content_type, 'id !=' => $slug_id))->update(array('redirect' => $slug_id, 'updated_by' => $this->user_id)); } } $this->rat->log('The user edited the content type "' . $content->content_type . '" with the ID: ' . $content->id . ' having "' . $content->title . '" as title.'); $this->postal->add('The content was updated successfully.', 'success'); } } else { $this->postal->add('There is no content to update.', 'error'); } redirect('admin/contents/index/' . $content->content_type, 'refresh'); } }
function get_is_uri($name, $uri, $tb, $id = 'null') { $uri = trim($uri); $uri = ltrim($uri, 'page'); if (empty($uri)) { $uri = url_title(mb_strtolower(convert_accented_characters(trim($name)))); } else { $uri = url_title(mb_strtolower(convert_accented_characters($uri))); } $i = 0; $uris = $uri; $unuri = $this->uri_is($uri, $tb, $id); while ($unuri > 0) { $i++; $uris = $uri . '_' . $i; $unuri = $this->uri_is($uris, $tb, $id); } return $uris; }
public function category($id, $page = 0) { $this->data['config']["uri_segment"] = 3; $this->data['main_category'] = $this->category_model->get_data_by_id($id); $this->data['config']["total_rows"] = $this->product_model->record_count($this->data['sidebar_filters'], $id); $choice = $this->data['config']["total_rows"] / $this->data['config']["per_page"]; $this->data['config']["num_links"] = round($choice); $this->data['config']["base_url"] = site_url('categorie/' . url_title(convert_accented_characters($this->data['main_category']->{'name_' . $this->data['language']})) . '-' . $this->data['main_category']->id); $this->pagination->initialize($this->data['config']); $this->data['products'] = $this->product_model->fetch_products($this->data['config']["per_page"], $page, $this->data['sidebar_filters'], !empty($_POST['sort_by']) ? $_POST['sort_by'] : false, false, $id); $this->data['links'] = $this->pagination->create_links(); if (!empty($_POST['ajax'])) { $this->load->view('partials/products_inside', $this->data); } else { $this->load->view('partials/header', $this->data); $this->load->view('products', $this->data); $this->load->view('partials/footer', $this->data); } }
/** * Create URL Title * * Takes a "title" string as input and creates a human-friendly URL string * with either a dash or an underscore as the word separator. * Cyrillic alphabet characters are supported. * * @param string $str The string * @param string $separator The separator, dash or underscore. * @param boolean $lowercase Whether it should be converted to lowercase. * * @return string The URL slug */ function url_title($str, $separator = 'dash', $lowercase = false) { $replace = $separator == 'dash' ? '-' : '_'; $trans = array('&\\#\\d+?;' => '', '&\\S+?;' => '', '\\s+' => $replace, '[^a-z0-9\\-\\._]' => '', $replace . '+' => $replace, $replace . '$' => $replace, '^' . $replace => $replace, '\\.+$' => ''); $str = convert_accented_characters($str); $str = strip_tags($str); foreach ($trans as $key => $val) { $str = preg_replace("#" . $key . "#i", $val, $str); } if ($lowercase === true) { if (function_exists('mb_convert_case')) { $str = mb_convert_case($str, MB_CASE_LOWER, "UTF-8"); } else { $str = strtolower($str); } } $CI =& get_instance(); $str = preg_replace('#[^' . $CI->config->item('permitted_uri_chars') . ']#i', '', $str); return trim(stripslashes($str)); }
function _slug($field) { if ($this->edit_slug()) { return true; } $this->load->helper(array('url', 'text', 'string')); $slug = reduce_multiples(strtolower(url_title(convert_accented_characters($this->title), 'dash')), '-', true); if (empty($slug)) { $t = new Text(); $max = $t->select_max('id')->get(); $slug = $max->id + 1; } if (is_numeric($slug)) { $slug = "{$slug}-1"; } if ($this->slug === $slug || !empty($this->slug) && $this->slug !== '__generate__') { return; } $s = new Slug(); // Need to lock the table here to ensure that requests arriving at the same time // still get unique slugs if ($this->has_db_permission('lock tables')) { $this->db->query("LOCK TABLE {$s->table} WRITE"); $locked = true; } else { $locked = false; } $page_type = is_numeric($this->page_type) ? $this->page_type : 0; $prefix = $page_type === 1 ? 'page' : 'essay'; while ($s->where('id', "{$prefix}.{$slug}")->count() > 0) { $slug = increment_string($slug, '-'); } $this->db->query("INSERT INTO {$s->table}(id) VALUES ('{$prefix}.{$slug}')"); if ($locked) { $this->db->query('UNLOCK TABLES'); } $this->slug = $slug; }
function editar_form($idFlujo) { if (!UsuarioBackendSesion::usuario()->tieneRol('editor')) { echo 'No tiene permisos'; exit; } $this->form_validation->set_rules('titulo', 'Título', 'trim|required'); $this->form_validation->set_rules('descripcion', 'Descripción', 'trim|required'); if ($this->form_validation->run() == TRUE) { $flujo = Doctrine::getTable('Flujo')->find($idFlujo); $flujo->titulo = $this->input->post('titulo'); $flujo->alias = convert_accented_characters($this->input->post('titulo')); $flujo->descripcion = $this->input->post('descripcion'); $flujo->save(); $this->session->set_flashdata('message', 'Flujo actualizado exitosamente! :)'); $respuesta->validacion = TRUE; $respuesta->redirect = site_url('backend/flujos'); } else { $respuesta->validacion = FALSE; $respuesta->errores = validation_errors('<p class="error">', '</p>'); } echo json_encode($respuesta); }
public function insert($value = "") { switch ($value) { case 'story': $story_title = $this->input->post('name'); $story_url = string_short(convert_accented_characters($story_title)); $story_thumb = $this->input->post('img'); $story_sumary = $this->input->post('sumary'); $story_realname = $this->input->post('realname'); $story_author = $this->input->post('author'); $story_type = $this->input->post('type'); $story_time = time(); $sql = "INSERT INTO story(story_id, story_title, story_url, story_thumb, story_sumary, story_time, story_realname, story_author, story_type)\n VALUES(NULL, '{$story_title}', '{$story_url}', '{$story_thumb}', '{$story_sumary}', {$story_time}, '{$story_realname}', '{$story_author}', '{$story_type}')"; if (strlen($story_title) > 2) { $this->db->query($sql); } $result = $this->db->query("SELECT story_id FROM story WHERE story_url = '{$story_url}'")->result(); echo $result[0]->story_id; break; case 'chapter': $story_id = $this->input->post('story'); $chapter_title = $this->input->post('title'); $chapter_url = string_short(convert_accented_characters($chapter_title)); $chapter_content = $this->input->post('img'); $chapter_time = time(); $chapter_title = str_replace("Chương ", "", $chapter_title); $sql = "INSERT INTO chapter(chapter_id, story_id, chapter_title, chapter_url, chapter_content, chapter_time)\n VALUES(NULL, {$story_id}, {$chapter_title}, '{$chapter_url}', '{$chapter_content}', {$chapter_time})"; if (strlen($chapter_url) > 2) { $this->db->query($sql); } echo 'TRUE'; break; default: # code... break; } }
/** * Procesa la foto enviada */ public function procesar_imagenes() { // Nombre para el archivo $microtime = '-' . str_replace('.', '', microtime(true)); $titulo = $this->security->xss_clean($this->input->post('titulo')); $nombre_titulo = url_title(convert_accented_characters($titulo), '-', TRUE); $nombre_modificado = $nombre_titulo . $microtime; $nombre_modificado .= '.jpg'; // ID de la publicacion //$pub_id = $this->security->xss_clean($this->input->post('pub_id')); // Configuracion de la libreria Upload $config['upload_path'] = './img/'; $config['allowed_types'] = 'jpg|jpeg|png'; $config['max_size'] = '10000'; $config['file_name'] = $nombre_modificado; $this->load->library('upload', $config); $this->upload->do_upload('userfile'); // Guarda la imagen // $this->Imagenes_model->insertar_imagen($pub_id, $nombre_modificado, $imagen_titulo); // Se carga la libreía de imagenes en este punto // para que este disponible en los proximos // metodos $this->load->library('image_lib'); // Se obtienen las dimensinoes de la imagene $ancho = $this->upload->data('image_width'); $alto = $this->upload->data('image_height'); // Si la imagen es mal alta que ancha se recorta cuadrada if ($alto > $ancho) { $this->recortar($nombre_modificado, $alto, $ancho); } if ($ancho > 600) { $this->redimensionar($nombre_modificado); } $this->crear_thumbs($nombre_modificado); redirect('Fotos', 'refresh'); }
function form($id = false, $duplicate = false) { $this->product_id = $id; $this->load->library('form_validation'); $this->load->model(array('option_model', 'category_model', 'digital_product_model')); $this->lang->load('digital_product'); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); //$data['categories'] = $this->Category_model->get_categories_tierd(); //$data['product_list'] = $this->Product_model->get_products(); $data['file_list'] = $this->digital_product_model->get_list(); $this->template->set('title', 'Products'); //default values are empty if the product is new $data['id'] = ''; $data['sku'] = ''; $data['name'] = ''; $data['slug'] = ''; $data['description'] = ''; $data['excerpt'] = ''; $data['price'] = ''; $data['saleprice'] = ''; $data['weight'] = ''; $data['track_stock'] = ''; $data['seo_title'] = ''; $data['meta'] = ''; $data['shippable'] = ''; $data['taxable'] = ''; $data['fixed_quantity'] = ''; $data['quantity'] = ''; $data['enabled'] = ''; $data['featured'] = ''; $data['related_products'] = array(); $data['product_categories'] = array(); $data['images'] = array(); $data['product_files'] = array(); //create the photos array for later use $data['photos'] = array(); if ($id) { // get the existing file associations and create a format we can read from the form to set the checkboxes $pr_files = $this->digital_product_model->get_associations_by_product($id); foreach ($pr_files as $f) { $data['product_files'][] = $f->file_id; } // get product & options data $data['product_options'] = $this->option_model->get_product_options($id); $product = $this->product_model->get_product($id); //if the product does not exist, redirect them to the product list with an error if (!$product) { $this->session->set_flashdata('error', 'The requested product could not be found.'); redirect('admin/products'); } //helps us with the slug generation $this->product_name = $this->input->post('slug', $product->slug); //set values to db values $data['id'] = $id; $data['sku'] = $product->sku; $data['name'] = $product->name; $data['seo_title'] = $product->seo_title; $data['meta'] = $product->meta; $data['slug'] = $product->slug; $data['description'] = $product->description; $data['excerpt'] = $product->excerpt; $data['price'] = $product->price; $data['saleprice'] = $product->saleprice; $data['weight'] = $product->weight; $data['track_stock'] = $product->track_stock; $data['shippable'] = $product->shippable; $data['quantity'] = $product->quantity; $data['taxable'] = $product->taxable; $data['fixed_quantity'] = $product->fixed_quantity; $data['enabled'] = $product->enabled; $data['featured'] = $product->featured; //make sure we haven't submitted the form yet before we pull in the images/related products from the database if (!$this->input->post('submit')) { $data['product_categories'] = $product->categories; $data['related_products'] = $product->related_products; $data['images'] = (array) json_decode($product->images); } } //if $data['related_products'] is not an array, make it one. if (!is_array($data['related_products'])) { $data['related_products'] = array(); } if (!is_array($data['product_categories'])) { $data['product_categories'] = array(); } //no error checking on these $this->form_validation->set_rules('caption', 'Caption'); $this->form_validation->set_rules('primary_photo', 'Primary'); $this->form_validation->set_rules('name', 'Name', 'trim|required|max_length[64]'); $this->form_validation->set_rules('sku', 'SKU', 'trim|required'); $this->form_validation->set_rules('seo_title', 'SEO Title', 'trim'); $this->form_validation->set_rules('meta', 'Meta description', 'trim'); $this->form_validation->set_rules('slug', 'Slug', 'trim'); $this->form_validation->set_rules('description', 'Description', 'trim|required'); $this->form_validation->set_rules('excerpt', 'Excerpt', 'trim'); $this->form_validation->set_rules('price', 'Price', 'trim|required|numeric|floatval'); $this->form_validation->set_rules('saleprice', 'Sale price', 'trim|required|numeric|floatval'); $this->form_validation->set_rules('weight', 'Weight', 'trim|numeric|floatval'); $this->form_validation->set_rules('track_stock', 'Stock', 'trim|numeric'); $this->form_validation->set_rules('quantity', 'Quantity', 'trim|numeric'); $this->form_validation->set_rules('shippable', 'Shippable', 'trim|numeric'); $this->form_validation->set_rules('taxable', 'Taxable', 'trim|numeric'); $this->form_validation->set_rules('fixed_quantity', 'Quantity', 'trim|numeric'); $this->form_validation->set_rules('enabled', 'Enabled', 'trim|numeric'); $this->form_validation->set_rules('featured', 'Featured', 'trim|numeric'); /* if we've posted already, get the photo stuff and organize it if validation comes back negative, we feed this info back into the system if it comes back good, then we send it with the save item submit button has a value, so we can see when it's posted */ if ($duplicate) { $data['id'] = false; } if ($this->input->post('submit')) { //reset the product options that were submitted in the post $data['product_options'] = $this->input->post('option'); $data['related_products'] = $this->input->post('related_products'); $data['product_categories'] = $this->input->post('categories'); $data['images'] = $this->input->post('images'); $data['product_files'] = $this->input->post('downloads'); } if ($this->form_validation->run() == FALSE) { $this->template->load('templates/admin/brainlight', 'admin/products/product_form', $data); } else { $this->load->helper('text'); //first check the slug field $slug = $this->input->post('slug'); //if it's empty assign the name field if (empty($slug) || $slug == '') { $slug = $this->input->post('name'); } $slug = url_title(convert_accented_characters($slug), 'dash', TRUE); //validate the slug /* $this->load->model('Routes_model'); if($id) { $slug = $this->routes_model->validate_slug($slug, $product->route_id); $route_id = $product->route_id; } else { $slug = $this->Routes_model->validate_slug($slug); $route['slug'] = $slug; $route_id = $this->Routes_model->save($route); } * */ $save['id'] = $id; $save['sku'] = $this->input->post('sku'); $save['name'] = $this->input->post('name'); $save['seo_title'] = $this->input->post('seo_title'); $save['meta'] = $this->input->post('meta'); $save['description'] = $this->input->post('description'); $save['excerpt'] = $this->input->post('excerpt'); $save['price'] = $this->input->post('price'); $save['saleprice'] = $this->input->post('saleprice'); $save['weight'] = $this->input->post('weight'); $save['track_stock'] = $this->input->post('track_stock'); $save['fixed_quantity'] = $this->input->post('fixed_quantity'); $save['quantity'] = $this->input->post('quantity'); $save['shippable'] = $this->input->post('shippable'); $save['taxable'] = $this->input->post('taxable'); $save['enabled'] = $this->input->post('enabled'); $post_images = $this->input->post('images'); $save['slug'] = $slug; if ($primary = $this->input->post('primary_image')) { if ($post_images) { foreach ($post_images as $key => &$pi) { if ($primary == $key) { $pi['primary'] = true; continue; } } } } $save['images'] = json_encode($post_images); if ($this->input->post('related_products')) { $save['related_products'] = json_encode($this->input->post('related_products')); } else { $save['related_products'] = ''; } //save categories $categories = $this->input->post('categories'); if (!$categories) { $categories = array(); } // format options $options = array(); if ($this->input->post('option')) { foreach ($this->input->post('option') as $option) { $options[] = $option; } } // save product $product_id = $this->product_model->save($save, $options, $categories); // add file associations // clear existsing $this->digital_product_model->disassociate(false, $product_id); // save new $downloads = $this->input->post('downloads'); if (is_array($downloads)) { foreach ($downloads as $d) { $this->digital_product_model->associate($d, $product_id); } } /* //save the route $route['id'] = $route_id; $route['slug'] = $slug; $route['route'] = 'cart/product/'.$product_id; $this->Routes_model->save($route); */ $this->session->set_flashdata('message', 'The product has been saved.'); //go back to the product list redirect('admin/products'); } }
function form($id = false) { $config['upload_path'] = 'uploads/images/full'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = $this->config->item('size_limit'); $config['max_width'] = '1024'; $config['max_height'] = '768'; $config['encrypt_name'] = true; $this->load->library('upload', $config); $this->category_id = $id; $this->load->helper('form'); $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); $data['categories'] = $this->Category_model->get_categories(); $data['page_title'] = lang('category_form'); //default values are empty if the customer is new $data['id'] = ''; $data['name'] = ''; $data['slug'] = ''; $data['description'] = ''; $data['excerpt'] = ''; $data['sequence'] = ''; $data['image'] = ''; $data['seo_title'] = ''; $data['meta'] = ''; $data['parent_id'] = 0; $data['error'] = ''; //create the photos array for later use $data['photos'] = array(); if ($id) { $category = $this->Category_model->get_category($id); //if the category does not exist, redirect them to the category list with an error if (!$category) { $this->session->set_flashdata('error', lang('error_not_found')); redirect($this->config->item('admin_folder') . '/categories'); } //helps us with the slug generation $this->category_name = $this->input->post('slug', $category->slug); //set values to db values $data['id'] = $category->id; $data['name'] = $category->name; $data['slug'] = $category->slug; $data['description'] = $category->description; $data['excerpt'] = $category->excerpt; $data['sequence'] = $category->sequence; $data['parent_id'] = $category->parent_id; $data['image'] = $category->image; $data['seo_title'] = $category->seo_title; $data['meta'] = $category->meta; } $this->form_validation->set_rules('name', 'lang:name', 'trim|required|max_length[64]'); $this->form_validation->set_rules('slug', 'lang:slug', 'trim'); $this->form_validation->set_rules('description', 'lang:description', 'trim'); $this->form_validation->set_rules('excerpt', 'lang:excerpt', 'trim'); $this->form_validation->set_rules('sequence', 'lang:sequence', 'trim|integer'); $this->form_validation->set_rules('parent_id', 'parent_id', 'trim'); $this->form_validation->set_rules('image', 'lang:image', 'trim'); $this->form_validation->set_rules('seo_title', 'lang:seo_title', 'trim'); $this->form_validation->set_rules('meta', 'lang:meta', 'trim'); // validate the form if ($this->form_validation->run() == FALSE) { $this->load->view($this->config->item('admin_folder') . '/category_form', $data); } else { $uploaded = $this->upload->do_upload('image'); if ($id) { //delete the original file if another is uploaded if ($uploaded) { if ($data['image'] != '') { $file = array(); $file[] = 'uploads/images/full/' . $data['image']; $file[] = 'uploads/images/medium/' . $data['image']; $file[] = 'uploads/images/small/' . $data['image']; $file[] = 'uploads/images/thumbnails/' . $data['image']; foreach ($file as $f) { //delete the existing file if needed if (file_exists($f)) { unlink($f); } } } } } else { if (!$uploaded) { $error = $this->upload->display_errors(); if ($error != lang('error_file_upload')) { $data['error'] .= $this->upload->display_errors(); $this->load->view($this->config->item('admin_folder') . '/category_form', $data); return; //end script here if there is an error } } } if ($uploaded) { $image = $this->upload->data(); $save['image'] = $image['file_name']; $this->load->library('image_lib'); //this is the larger image $config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/full/' . $save['image']; $config['new_image'] = 'uploads/images/medium/' . $save['image']; $config['maintain_ratio'] = TRUE; $config['width'] = 600; $config['height'] = 500; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); //small image $config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/medium/' . $save['image']; $config['new_image'] = 'uploads/images/small/' . $save['image']; $config['maintain_ratio'] = TRUE; $config['width'] = 300; $config['height'] = 300; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); //cropped thumbnail $config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/small/' . $save['image']; $config['new_image'] = 'uploads/images/thumbnails/' . $save['image']; $config['maintain_ratio'] = TRUE; $config['width'] = 150; $config['height'] = 150; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); } $this->load->helper('text'); //first check the slug field $slug = $this->input->post('slug'); //if it's empty assign the name field if (empty($slug) || $slug == '') { $slug = $this->input->post('name'); } $slug = url_title(convert_accented_characters($slug), 'dash', TRUE); //validate the slug $this->load->model('Routes_model'); if ($id) { $slug = $this->Routes_model->validate_slug($slug, $category->route_id); $route_id = $category->route_id; } else { $slug = $this->Routes_model->validate_slug($slug); $route['slug'] = $slug; $route_id = $this->Routes_model->save($route); } $save['id'] = $id; $save['name'] = $this->input->post('name'); $save['description'] = $this->input->post('description'); $save['excerpt'] = $this->input->post('excerpt'); $save['parent_id'] = intval($this->input->post('parent_id')); $save['sequence'] = intval($this->input->post('sequence')); $save['seo_title'] = $this->input->post('seo_title'); $save['meta'] = $this->input->post('meta'); $save['route_id'] = intval($route_id); $save['slug'] = $slug; $category_id = $this->Category_model->save($save); //save the route $route['id'] = $route_id; $route['slug'] = $slug; $route['route'] = 'cart/category/' . $category_id . ''; $this->Routes_model->save($route); $this->session->set_flashdata('message', lang('message_category_saved')); //go back to the category list redirect($this->config->item('admin_folder') . '/categories'); } }
function gen_seo_url($val = NULL) { $val = strtolower(convert_accented_characters($val)); $val = url_title($val); return $val; }
public function AddToCarrito() { $Carrito = json_decode($this->input->post('MiCarrito')); //Variable Donde se almacenan los productos seleccionados $Cantidad = $Carrito->Cantidad; $idProduc = $Carrito->Id; $Precio = $Carrito->Precio; $Descrip = $Carrito->Descripc; $Control = $Carrito->Control; $row = array(); //If para Checar si el producto ya existe en el y poder aumentar su cantidad if ($cart = $this->cart->contents()) { foreach ($cart as $item) { if ($item['id'] === $idProduc) { $cant = $item['qty'] + $Cantidad; if ($Control == 3) { $cant = $Cantidad; } $row = array('rowid' => $item['rowid'], 'price' => $item['price'], 'qty' => $cant); break; } } } //Si la fila es afectada se actualiza if ($row) { $this->cart->update($row); } else { //De lo contrario se inserta el producto nuevo al carrito $insert = array('id' => $idProduc, 'qty' => $Cantidad, 'price' => $Precio, 'name' => convert_accented_characters($Descrip)); $this->cart->insert($insert); } $add = array(); if ($Cantidad == "-1") { //Si se elimina un producto se manda el mensaje $add = array("Msg" => "Se Elimino al Carrito Correctamente"); } else { //de lo contrario se agrega correctamente y se manda el msj $add = array("Msg" => "Agregado al Carrito Correctamente"); } echo json_encode($add); }
public function test_convert_accented_characters() { $this->assertEquals('AAAeEEEIIOOEUUUeY', convert_accented_characters('ÀÂÄÈÊËÎÏÔŒÙÛÜŸ')); $this->assertEquals('a e i o u n ue', convert_accented_characters('á é í ó ú ñ ü')); }
<div class="span-7 last offresformations"> <?php foreach ($organismes as $row) { echo '<div class="offre">'; if ($row->image != '') { echo '<a href="' . base_url('organisme/' . $row->id_orga . '-' . url_title(convert_accented_characters($row->nom)) . '.html') . '"><img src="' . base_url('img/offres/' . $row->image) . '" width="270"></a>'; } echo '<h2><a href="' . base_url('organisme/' . $row->id_orga . '-' . url_title(convert_accented_characters($row->nom)) . '.html') . '">' . $row->nom . '</a></h2>'; echo '<p>' . $row->details . '</p>'; echo '<p><a href="http://' . $row->web . '">' . $row->web . '</a></p>'; echo '</div>'; } ?> </div>
<p style="text-align: left;"> <span>Quantité : </span> <?php echo $orderDetail->quantite; ?> </p> <p style="text-align: left;"> <span>Ce produit a été commander le</span> <?php $bad_date = $orderDetail->date_commande; $better_date = nice_date($bad_date, 'd-m-Y'); echo $better_date; ?> </p> <a href="<?php echo base_url('single/index/' . strtolower(url_title(convert_accented_characters($orderDetail->nom_produit))) . '/' . $orderDetail->id_produit); ?> " class="btn btn-success" title="Afficher plus">Plus... »</a> </div> </div> <?php } } ?> </div>
/** * Returns all the URLs sent for this element * * @param Boolean $fill_empty_lang Should the empty lang index be filled with '' ? * @return Array Multidimensional array of URLs * ex : $url['en'] = 'my-element-url' */ protected function _get_urls($fill_empty_lang = FALSE) { $urls = array(); foreach (Settings::get_languages() as $l) { // If lang URL exists, use it if ($this->input->post('url_' . $l['lang']) !== '') { $urls[$l['lang']] = url_title(convert_accented_characters($this->input->post('url_' . $l['lang']))); } else { // Try to use the lang title if ($this->input->post('title_' . $l['lang']) !== '') { $urls[$l['lang']] = url_title(convert_accented_characters($this->input->post('title_' . $l['lang']))); } else { if ($fill_empty_lang === TRUE) { $urls[$l['lang']] = ''; } } } } $default_lang_url = $urls[Settings::get_lang('default')]; foreach ($urls as $lang => $url) { if ($url == '') { $urls[$lang] = $default_lang_url; } } return $urls; }
public function analyze($language_slug, $content_id) { $content = $this->content_model->get($content_id); $selected_keywords = $this->keyword_model->where(array('content_type' => $content->content_type, 'content_id' => $content->id, 'language_slug' => $language_slug))->get_all(); $keywords = array(); if ($selected_keywords) { foreach ($selected_keywords as $word) { $keywords[$word->word_id] = array('appearances' => $word->appearances, 'keyword_id' => $word->id); } } $this->data['selected_keywords'] = $keywords; $this->data['language_slug'] = $language_slug; $this->data['content_id'] = $content_id; $this->data['content_type'] = $content->content_type; $translation = $this->content_translation_model->where(array('language_slug' => $language_slug, 'content_id' => $content->id, 'content_type' => $content->content_type))->get(); $this->keyphrase_model->where(array('content_id' => $content->id, 'content_type' => $content->content_type, 'language_slug' => $language_slug))->delete(); $text = strip_tags($translation->title) . '. ' . strip_tags($translation->content); $text = trim($text, "."); $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8'); $text = str_replace(PHP_EOL, ' ', $text); $text = convert_accented_characters($text); $text = $this->_add_stop_signs($text); $blocks = $this->_break_into_blocks($text); $this->data['text'] = implode('<span class="glyphicon glyphicon-stop text-primary"></span>', $blocks); $words = array(); $blocks_as_arrays = array(); $depth = 0; $total_entities = 0; foreach ($blocks as $block) { $block = explode(' ', $block); if (sizeof($block) > $depth) { $depth = sizeof($block); } if (sizeof($block) > 1) { $blocks_as_arrays[] = $block; } foreach ($block as $entity) { $total_entities++; if (!is_numeric(trim($entity)) && !in_array(trim($entity), $words)) { $words[] = strtolower($entity); } } } $not_in_dictionary = array(); foreach ($words as $word) { if (!$this->dictionary_model->where(array('word' => $word, 'language_slug' => $language_slug))->get()) { $not_in_dictionary[] = strtolower($word); } } $this->data['not_in_dictionary'] = $not_in_dictionary; $noise_words = array(); $noises = $this->dictionary_model->where(array('noise' => '1', 'parent_id' => '0', 'language_slug' => $language_slug))->get_all(); if (!empty($noises)) { foreach ($noises as $noise) { $noise_words[] = $noise->id; } } $dictionary = $this->dictionary_model->where('language_slug', $language_slug)->where('verified', '1')->where('word', $words)->get_all(); $word_ids = array(); if (!empty($dictionary)) { foreach ($dictionary as $word_dictionary) { if ($word_dictionary->parent_id == '0') { $word_ids[$word_dictionary->word] = $word_dictionary->id; } else { $word_ids[$word_dictionary->word] = $word_dictionary->parent_id; } } } ksort($word_ids); $the_base_words = array(); if (!empty($word_ids)) { $base_words = $this->dictionary_model->where('language_slug', $language_slug)->where('id', $word_ids, NULL, FALSE)->get_all(); foreach ($base_words as $the_word) { $the_base_words[$the_word->id] = $the_word->word; } } $degs = array(); //aici pastram toate cuvintele impreuna cu numarul aparitiilor $word_appearances = array(); foreach ($blocks_as_arrays as $block_key => $block) { $block_as_ids = array(); foreach ($block as $entity_key => $entity) { $entity = strtolower($entity); if (array_key_exists($entity, $word_ids)) { $entity = $word_ids[$entity]; } else { break; } $block_as_ids[] = $entity; if (!in_array($entity, $noise_words)) { if (!array_key_exists($entity, $word_appearances)) { $word_appearances[$entity] = 1; } else { $word_appearances[$entity] = $word_appearances[$entity] + 1; } $degs[$entity][$block_key][] = $entity_key; } } $blocks_as_ids[] = $block_as_ids; } $candidate_words = array(); foreach ($word_appearances as $key => $word) { if ($word > 1) { $candidate_words[$key] = $word; } } $initial_phrases = array(); foreach ($candidate_words as $word_key => $word) { $the_word = $degs[$word_key]; foreach ($the_word as $block_key => $location) { foreach ($location as $loc) { $new_key = ''; for ($k = 0; $k <= $depth; $k++) { if (array_key_exists($loc + $k, $blocks_as_ids[$block_key])) { $new_key .= $blocks_as_ids[$block_key][$loc + $k]; $new_key .= '|'; $trim_new_key = rtrim($new_key, '|'); if (!array_key_exists($trim_new_key, $initial_phrases)) { $initial_phrases[$trim_new_key] = 1; } else { $initial_phrases[$trim_new_key] = $initial_phrases[$trim_new_key] + 1; } } else { break; } } } } } foreach ($initial_phrases as $phrase => $freq) { $phrase_words = explode('|', $phrase); $number_words = sizeof($phrase_words); for ($i = sizeof($phrase_words) - 1; $i > 0; $i--) { if (in_array($phrase_words[$i], $noise_words)) { array_pop($phrase_words); } else { break; } } $new_phrase = implode('|', $phrase_words); if ($phrase != $new_phrase) { $frequency = $initial_phrases[$phrase]; if (array_key_exists($new_phrase, $initial_phrases)) { $initial_phrases[$new_phrase] = $initial_phrases[$new_phrase] + $frequency; } else { $initial_phrases[$new_phrase] = $frequency; } unset($initial_phrases[$phrase]); } } $candidate_phrases = array(); $previous_key = ''; foreach ($initial_phrases as $phrase_key => $deg) { $word_keys = explode('|', $phrase_key); if (sizeof($word_keys) > 1 && $deg > 1) { $candidate_phrases[$phrase_key] = $deg; } $previous_key = $phrase_key; } $previous_key = ''; $word_frequencies = array(); foreach ($candidate_phrases as $phrase_key => $deg) { $word_keys = explode('|', $phrase_key); foreach ($word_keys as $key) { if (strpos($previous_key, $phrase_key) === FALSE) { if (!in_array($key, $noise_words)) { if (!array_key_exists($key, $word_frequencies)) { $word_frequencies[$key] = 1; } else { $word_frequencies[$key] = $word_frequencies[$key] + 1; } } } } $previous_key = $phrase_key; } arsort($word_frequencies); $extracted_phrases = array(); foreach ($candidate_phrases as $phrase_keys => $appearances) { $score = 0; $word_keys = explode('|', $phrase_keys); foreach ($word_keys as $key) { $word_deg = isset($word_appearances[$key]) ? $word_appearances[$key] : 0; $word_freq = isset($word_frequencies[$key]) ? $word_frequencies[$key] : 0; if (!in_array($key, $noise_words)) { if ($word_deg != 0 & $word_freq != 0) { $add_score = $word_deg / $word_freq; if (in_array($key, $blocks_as_ids[0])) { $add_score = $add_score * 2; } $score = $score + $add_score; } } } $extracted_phrases[$phrase_keys] = number_format($score, 2) * $appearances; } arsort($extracted_phrases); $the_words = array(); foreach ($word_appearances as $key => $number) { $string = ''; if (array_key_exists($key, $the_base_words)) { $string = $the_base_words[$key]; } else { $string = $key; $key = ''; } $density = $number / $total_entities * 100; $density = number_format($density, 2); $the_words[$key] = array('id' => $key, 'string' => $string, 'appearances' => $number, 'density' => $density); } $the_phrases = array(); if (!empty($extracted_phrases)) { $now = date('Y-m-d H:i:s'); foreach ($extracted_phrases as $key => $score) { if ($this->phrase_model->where(array('phrase' => $key, 'language_slug' => $language_slug))->get() === FALSE) { $phrase_id = $this->phrase_model->insert(array('phrase' => $key, 'language_slug' => $language_slug, 'last_check' => $now)); } else { $phrase = $this->phrase_model->where(array('phrase' => $key, 'language_slug' => $language_slug))->get(); $phrase_id = $phrase->id; } $this->keyphrase_model->insert(array('content_id' => $content->id, 'content_type' => $content->content_type, 'phrase_id' => $phrase_id, 'language_slug' => $language_slug, 'score' => $score)); } $this->content_translation_model->where(array('content_id' => $content->id, 'content_type' => $content->content_type, 'language_slug' => $language_slug))->update(array('rake' => '1')); } foreach ($extracted_phrases as $key => $score) { $word_keys = explode('|', $key); $strings = array(); foreach ($word_keys as $word_id) { if (array_key_exists($word_id, $the_words)) { $strings[] = $the_words[$word_id]['string']; } elseif (array_key_exists($word_id, $the_base_words)) { $strings[] = $the_base_words[$word_id]; } else { $strings[] = $word_id; } } $the_phrases[$key] = array('string' => $strings, 'score' => $score); } $score = array(); foreach ($the_words as $key => $row) { $score[$key] = $row['appearances']; } array_multisort($score, SORT_DESC, $the_words); $this->data['the_words'] = $the_words; $this->data['the_phrases'] = $the_phrases; $this->render('admin/rake/edit_view'); }
function form($id = false) { $this->load->helper('url'); $this->load->helper('form'); $this->load->library('form_validation'); //set the default values $data['id'] = ''; $data['title'] = ''; $data['menu_title'] = ''; $data['slug'] = ''; $data['sequence'] = 0; $data['parent_id'] = 0; $data['content'] = ''; $data['seo_title'] = ''; $data['meta'] = ''; $data['page_title'] = lang('page_form'); $data['pages'] = $this->Page_model->get_pages(); if ($id) { $page = $this->Page_model->get_page($id); if (!$page) { //page does not exist $this->session->set_flashdata('error', lang('error_page_not_found')); redirect($this->config->item('admin_folder') . '/pages'); } //set values to db values $data['id'] = $page->id; $data['parent_id'] = $page->parent_id; $data['title'] = $page->title; $data['menu_title'] = $page->menu_title; $data['sequence'] = $page->sequence; $data['content'] = $page->content; $data['seo_title'] = $page->seo_title; $data['meta'] = $page->meta; $data['slug'] = $page->slug; } $this->form_validation->set_rules('title', 'lang:title', 'trim|required'); $this->form_validation->set_rules('menu_title', 'lang:menu_title', 'trim'); $this->form_validation->set_rules('slug', 'lang:slug', 'trim'); $this->form_validation->set_rules('seo_title', 'lang:seo_title', 'trim'); $this->form_validation->set_rules('meta', 'lang:meta', 'trim'); $this->form_validation->set_rules('sequence', 'lang:sequence', 'trim|integer'); $this->form_validation->set_rules('parent_id', 'lang:parent_id', 'trim|integer'); $this->form_validation->set_rules('content', 'lang:content', 'trim'); // Validate the form if ($this->form_validation->run() == false) { $this->view($this->config->item('admin_folder') . '/page_form', $data); } else { $this->load->helper('text'); //first check the slug field $slug = $this->input->post('slug'); //if it's empty assign the name field if (empty($slug) || $slug == '') { $slug = $this->input->post('title'); } $slug = url_title(convert_accented_characters($slug), 'dash', TRUE); //validate the slug if ($id) { $slug = $this->Page_model->validate_slug($slug, $id); } else { $slug = $this->Page_model->validate_slug($slug); } $save = array(); $save['id'] = $id; $save['parent_id'] = $this->input->post('parent_id'); $save['title'] = $this->input->post('title'); $save['menu_title'] = $this->input->post('menu_title'); $save['sequence'] = $this->input->post('sequence'); $save['content'] = $this->input->post('content'); $save['seo_title'] = $this->input->post('seo_title'); $save['meta'] = $this->input->post('meta'); $save['slug'] = $slug; //set the menu title to the page title if if is empty if ($save['menu_title'] == '') { $save['menu_title'] = $this->input->post('title'); } //save the page $page_id = $this->Page_model->save($save); $this->session->set_flashdata('message', lang('message_saved_page')); //go back to the page list redirect($this->config->item('admin_folder') . '/pages'); } }
/** * HOW IT WORKS * 1 - If the idContent is set retrieve all the fields and values for this ID, otherwise retrieve only the fields to show * 2 - On save check the errors on the "normal fields"; for the attachments save everything into the tmp folder and check for errors * 3 - If there aren't errors save the content (insert or update), save the values and moving the attachments from the tmp folder to the content folder * 4 - Process the images, if any * 5 - Empty the TMP folder * 6 - Redirect to the result page * */ public function saveContent($contentType, $content = null) { $result = array(); $uploadData = array(); $redirectURL = '/admin/contents/'; $oldValues = array(); $errors = array(); $result['data_saved'] = FALSE; $contentTypeName = $contentType; $contentType = $this->getContentTypeByName($contentType); $fields = $this->getContentFieldsByIdContentType($contentType['id']); $categories = $this->getCategoriesByContentType($contentType['id']); $oldValues['title'] = ''; $oldValues['relative_path'] = ''; $absolutePath = ''; $oldValues['categories'] = array(); if ($content) { $idContent = $content['id']; } else { $idContent = null; } if ($contentTypeName === 'pages') { $menu = $this->getMenu(true); $flatPagesTree = $this->getFlatPagesTree($menu); $flatPagesTitles = array(); foreach ($flatPagesTree as $id => $page) { $flatPagesTitles[$id] = ltrim(str_repeat('--', $page['level']) . ' ', ' ') . "{$page['title']}"; } // TODO another day // if ($idContent && isset($flatPagesTitles[$idContent])) { // unset($flatPagesTitles[$idContent]); // } } // ================ 1 - RETRIEVING ALL THE CONTENT COMPONENTS (FIELDS, VALUES, ATTACHS, ETC.) =============== // Retrieve the content if the idContent is set if ($idContent) { $this->data['uploadUrl'] = '/uploads/' . $idContent . '/'; $content = $this->getContentById($idContent); $contentValues = $this->getAllContentValuesByIdContent($idContent); $contentCategories = $this->getAllContentCategoriesByIdContent($idContent); $oldValues['title'] = $content['title']; $oldValues['relative_path'] = $content['relative_path']; $oldValues['categories'] = $contentCategories; if (count($oldValues['categories']) > 0) { $tmp = array(); foreach ($oldValues['categories'] as $category) { $tmp[] = $category['id_category']; } $oldValues['categories'] = $tmp; } $tmp = array(); if (count($contentValues) > 0) { foreach ($contentValues as $value) { $tmp[$value['id_content_field']] = $value; } } $contentValues = $tmp; } else { $content = array(); $contentValues = array(); $contentCategories = array(); } $contentAttachments = array(); // Fields transformations (options, images, etc.) if (count($fields) > 0) { foreach ($fields as $index => $field) { if (isset($contentValues[$field['id']]['value']) && $contentValues[$field['id']]['value'] != '') { $field['value'] = $contentValues[$field['id']]['value']; } else { $field['value'] = ''; } if (in_array($field['type'], array('radio', 'select', 'multiselect', 'checkbox', 'multicheckbox'))) { $field['options'] = FM_Utility::convertOptionsTextToArray($field['options']); } if (in_array($field['type'], array('multiselect', 'multicheckbox', 'multiple_linked_content')) && $field['value'] != '') { $field['value'] = FM_Utility::convertMultiOptionsTextToArray($contentValues[$field['id']]['value']); } if ($field['type'] == 'file_upload') { if (isset($contentValues[$field['id']])) { $field['attach'] = array('id_content_value' => $contentValues[$field['id']]['id'], 'file' => $this->data['uploadUrl'] . $contentValues[$field['id']]['value']); } else { $field['attach'] = array(); } } if ($field['type'] == 'image_upload') { if (isset($contentValues[$field['id']])) { $field['attach'] = array('id_content_value' => $contentValues[$field['id']]['id'], 'zoom_image' => $this->data['uploadUrl'] . $contentValues[$field['id']]['value'], 'thumb_image' => $this->data['uploadUrl'] . 'thumbs/' . $contentValues[$field['id']]['value']); } else { $field['attach'] = array(); } } if ($field['type'] == 'gallery') { $contentAttachments[$field['name']] = $this->getAllContentAttachmentsByIdContent($idContent); $field['attachs'] = array(); if (count($contentAttachments[$field['name']]) > 0) { foreach ($contentAttachments[$field['name']] as $att) { array_push($field['attachs'], array('id_content_attachment' => $att['id'], 'zoom_image' => $this->data['uploadUrl'] . $att['filename'], 'thumb_image' => $this->data['uploadUrl'] . 'thumbs/' . $att['filename'])); } } } if ($field['type'] == 'linked_content' || $field['type'] == 'multiple_linked_content') { $ctypeToSelect = $this->getContentTypeById($field['linked_id_content_type']); $contentSearch = new FM_ContentSearch(); $contentSearch->initialize($ctypeToSelect['content_type'])->select('*')->fullInfo(TRUE); $contentList = $contentSearch->getContentList(); $options = array(); foreach ($contentList as $cont) { $options[$cont['id']] = $cont['title']; } $field['options'] = $options; } if ($field['name'] === 'parent_page_id' && $contentTypeName === 'pages' && $field['type'] == 'select') { $field['options'] = $flatPagesTitles; } // PAGE FIELD MANAGEMENT if ($field['name'] == 'content_types_list' && $contentTypeName == 'pages' && $field['type'] == 'select') { $cTypes = $this->getContentTypes('pages'); $options = array(); if (count($cTypes) > 0) { foreach ($cTypes as $ct) { $options[$ct['content_type']] = $ct['content_type']; } } $field['options'] = $options; // If the value exist, I load the options for the content list if ($field['value'] != '') { $contentListOptions = array(); $contentSearch = new FM_ContentSearch(); $contentSearch->initialize($field['value'])->select('*')->fullInfo(TRUE); $tmpContentList = $contentSearch->getContentList(); if (count($tmpContentList) > 0) { foreach ($tmpContentList as $tmpContent) { $contentListOptions[$tmpContent['id']] = $tmpContent['title']; } } } } if ($field['name'] === 'content_list_categories' && $contentTypeName === 'pages' && in_array($field['type'], array('multiselect', 'multicheckbox'))) { $field['options'] = (array) $field['value']; $field['options'] = array_combine($field['options'], $field['options']); } if ($field['name'] == 'content_list' && $contentTypeName == 'pages' && ($field['type'] == 'select' || $field['type'] == 'multiselect')) { // Check if the operation value exist if (isset($contentListOptions) && count($contentListOptions) > 0) { $field['options'] = $contentListOptions; } } $fields[$index] = $field; } } if ($this->ci->input->post('save') || $this->ci->input->post('save_list')) { $redirectURL .= $this->ci->input->post('save') ? 'edit/' : 'index/' . $contentType['content_type']; $tmpFolder = $this->getTmpFolder(); // Generic saving of the values foreach ($this->ci->input->post() as $name => $value) { $oldValues[$name] = $value; } if (count($fields) > 0) { foreach ($fields as $index => $field) { if ($this->ci->input->post($field['name'])) { $field['value'] = $this->ci->input->post($field['name']); } $fields[$index] = $field; } } // Basic content checking if ($this->ci->input->post('title') == '') { $errors['title'] = $this->ci->lang->line('incorrect_content_title'); } if ($this->ci->input->post('relative_path') == '') { $errors['relative_path'] = sprintf($this->ci->lang->line('incorrect_field'), 'relative path'); } else { $_POST['relative_path'] = $relativePath = url_title(convert_accented_characters($this->ci->input->post('relative_path')), '-', true); } // Check for page absolute_path uniqueness if ($contentTypeName === 'pages' && !isset($errors['relative_path']) && isset($flatPagesTitles)) { $absolutePath = "{$relativePath}/"; $parentPageId = $this->ci->input->post('parent_page_id'); if ($parentPageId) { $absolutePath = "{$flatPagesTree[$parentPageId]['absolute_path']}{$absolutePath}"; } $contentSearch = new FM_ContentSearch(); $contentSearch->initialize($contentType['id'])->select('id')->addWhereCondition('absolute_path', '=', $absolutePath)->addWhereCondition('lang', '=', $this->ci->input->post('lang')); $content = current($contentSearch->getContentList()); if ($content && (!$idContent || $content['id'] !== $idContent)) { $errors['relative_path'] = $this->ci->lang->line('non_unique_absolute_path'); } } else { $absolutePath = url_title(convert_accented_characters($oldValues['title'])); } // ================ 2 - CHECKING THE ERRORS ======================== if (count($fields) > 0) { foreach ($fields as $index => $field) { if (!$this->isFilesystemField($field)) { if ($field['mandatory'] == TRUE && $this->ci->input->post($field['name']) == '') { $field['showError'] = TRUE; $field['error'] = sprintf($this->ci->lang->line('incorrect_field'), $field['label']); } if ($field['type'] == 'date' || $field['type'] == 'datetime') { $value = $this->ci->input->post($field['name']); if ($value) { $field['value'] = $value; if ($field['type'] == 'datetime') { list($date, $time) = explode(' ', $value); } else { $date = $value; } list($day, $month, $year) = explode('/', $date); if (!checkdate($month, $day, $year)) { $field['showError'] = TRUE; $field['error'] = sprintf($this->ci->lang->line('incorrect_date_field'), $field['label']); } } } } else { $hidden = $this->ci->input->post($field['name']); if ($field['mandatory'] == TRUE && $_FILES[$field['name']]['error'] != 0 && !$hidden) { $field['showError'] = TRUE; $field['error'] = sprintf($this->ci->lang->line('incorrect_field'), $field['label']); } if ($_FILES[$field['name']]['error'] == 0) { $temp = $this->saveTemporaryAttachments($field); if (isset($temp[$field['name']]['error'])) { $field['showError'] = TRUE; $field['error'] = $temp[$field['name']]['error']; } else { $field['value'] = $temp[$field['name']]['file_name']; $uploadData = array_merge($uploadData, $temp); } } } $fields[$index] = $field; } } $values = array(); $checkErrors = FALSE; // The title and permalink are correct // (??) if (count($errors) == 0) { if (count($fields) > 0) { foreach ($fields as $field) { if (isset($field['error']) && $field['error'] != '') { $checkErrors = TRUE; } } } } // ================ 3 - SAVE THE CONTENT VALUES ======================== if (count($errors) == 0 && !$checkErrors) { $contentData = array('absolute_path' => $absolutePath) + array_intersect_key($this->ci->input->post(), array_flip(array('title', 'relative_path', 'lang'))); // Save the basic content if (!$idContent) { $contentData['id_content_type'] = $contentType['id']; $contentData['id_user'] = $this->ci->fm_users_management->getLoggedUserId(); $idContent = $this->insertContent($contentData); } else { $contentData['id'] = $idContent; $this->updateContent($contentData); if ($contentTypeName === 'pages' && isset($contentData['absolute_path']) && $contentData['absolute_path']) { $this->ci->content->updateSonsPath($contentData['absolute_path'], $idContent); } } $storeFolder = $this->_uploadPath . '/' . $idContent . '/'; // I check if the directory of the content exists or not if (file_exists($storeFolder) == FALSE) { mkdir($storeFolder, 0777); } // Create the thumb folder if image if (file_exists($storeFolder . 'thumbs/') == FALSE) { mkdir($storeFolder . 'thumbs/', 0777); } $redirectURL .= $this->ci->input->post('save') ? $idContent : ''; // Save the content values if (count($fields) > 0) { // Move everything from the tmp folder to the content folder $this->moveTemporaryAttachments($idContent); foreach ($fields as $field) { // ================ 4 - PROCESS THE IMAGES =============== if ($field['type'] == 'image_upload' || $field['type'] == 'gallery') { $hidden = $this->ci->input->post($field['name']); if (isset($uploadData[$field['name']])) { $processResult = $this->processImage($idContent, $field, $uploadData); if (isset($processResult['error'])) { log_message($processResult['error']); } } } // Insert the value if (!isset($contentValues[$field['id']])) { if (!$this->isFilesystemField($field)) { $value = $this->ci->input->post($field['name']); if ($field['type'] == 'xhtml_textarea' && $tmpFolder) { $tmpFolder = $this->ci->config->item('txt_upl_img_path', 'factotum') . '/' . $tmpFolder; $value = str_replace($tmpFolder, $this->_imagesURL . '/' . $idContent, $value); } if ($field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' || $field['type'] == 'multiple_linked_content') { $value = $value ? FM_Utility::convertMultiOptionsArrayToText($value) : ''; } $this->insertContentValue($idContent, $field['id'], $value); } else { // Saving the Image/File Uploaded if (($field['type'] == 'image_upload' || $field['type'] == 'file_upload') && isset($uploadData[$field['name']]['file_name'])) { if (isset($uploadData[$field['name']]['file_name'])) { $value = $uploadData[$field['name']]['file_name']; } else { // Retrieve the hidden value $value = $this->ci->input->post($field['name']); } $this->insertContentValue($idContent, $field['id'], $value); } // Saving the gallery if ($field['type'] == 'gallery' && isset($uploadData[$field['name']])) { $idContentAttachment = $this->insertContentAttachment($idContent, $field['id'], $uploadData[$field['name']]['file_name'], $uploadData[$field['name']]['file_name']); $this->insertContentValue($idContent, $field['id'], $idContentAttachment); } } } else { // Update the existing rows $cValue = $contentValues[$field['id']]; // Normal field type (text/textarea) if (!$this->isFilesystemField($field)) { $value = $this->ci->input->post($field['name']); if ($field['type'] == 'xhtml_textarea' && $tmpFolder) { $tmpFolder = $this->ci->config->item('txt_upl_img_path', 'factotum') . '/' . $tmpFolder; $value = str_replace($tmpFolder, $this->_imagesURL . '/' . $idContent, $value); } if ($field['type'] == 'multiselect' || $field['type'] == 'multicheckbox' || $field['type'] == 'multiple_linked_content') { $value = FM_Utility::convertMultiOptionsArrayToText($value); } $this->updateContentValue($cValue['id'], $value); } else { // Saving the Image/File Uploaded if (($field['type'] == 'image_upload' || $field['type'] == 'file_upload') && isset($uploadData[$field['name']]['file_name'])) { $value = $uploadData[$field['name']]['file_name']; $this->updateContentValue($cValue['id'], $value); } if ($field['type'] == 'gallery' && isset($uploadData[$field['name']])) { $idContentAttachment = $this->insertContentAttachment($idContent, $field['id'], $uploadData[$field['name']]['file_name'], $uploadData[$field['name']]['file_name']); $this->insertContentValue($idContent, $field['id'], $idContentAttachment); } } } } // ================ 5 - EMPTY THE TMP FOLDER =============== $this->deleteTmpFolder(); } // 6 - SAVE THE CONTENT CATEGORIES $tmp = array(); if (count($contentCategories) > 0) { foreach ($contentCategories as $contentCategory) { $tmp[] = $contentCategory['id_category']; } } $contentCategories = $tmp; $postedCategories = $this->ci->input->post('categories'); if ($postedCategories && count($postedCategories) > 0) { if ($postedCategories) { $tmp = array(); foreach ($postedCategories as $idContentCategory) { $tmp[] = $idContentCategory; } $postedCategories = $tmp; } foreach ($categories as $cat) { if (!in_array($cat['id'], $postedCategories)) { $this->deleteContentCategoryByIdContentAndIdCategory($idContent, $cat['id']); } else { if (!in_array($cat['id'], $contentCategories)) { $this->insertContentCategory($idContent, $cat['id']); } } } } else { foreach ($contentCategories as $idCategory) { $this->deleteContentCategoryByIdContentAndIdCategory($idContent, $idCategory); } } // ================ 7 - REDIRECT TO THE RESULT =============== $result['redirectURL'] = $redirectURL; $result['data_saved'] = TRUE; } else { $result['redirectURL'] = ''; } } $result['fields'] = $fields; $result['errors'] = $errors; $result['oldValues'] = $oldValues; return $result; }