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; }
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; }
function edit_slug() { if (isset($this->current_slug)) { if ($this->current_slug === $this->slug) { return; } $base = strtolower(get_class($this)); if ($base === 'text') { $base = $this->page_type < 1 ? 'essay' : 'page'; } if (preg_match('/[^a-z0-9\\-]/', $this->slug)) { throw new Exception('URL slugs can only contain letters, numbers and hyphens.'); } $s = new Slug(); if ($s->where('id', "{$base}.{$this->slug}")->count() > 0) { throw new Exception('This URL slug is already in use. Please enter a different value.'); } else { $old_slugs = explode(',', trim($this->old_slug, ',')); array_unshift($old_slugs, $this->current_slug); $this->old_slug = ',' . implode(',', $old_slugs) . ','; $this->db->query("DELETE FROM {$s->table} WHERE id = '{$base}.{$this->current_slug}'"); $this->db->query("INSERT INTO {$s->table}(id) VALUES ('{$base}.{$this->slug}')"); return true; } } return false; }
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; }