protected function checkslug() { if (!$this->loaded()) { $slug = $this->slug; if (empty($slug)) { $slug = $this->title; } $slug = site::slugify($slug); $orgslug = $slug; $exists = $this->where('slug', '=', $slug)->count_all(); $i = 2; while ((bool) $exists) { $secondtolast = substr($orgslug, strlen($orgslug) - 2, 1); $last = substr($orgslug, strlen($orgslug) - 1, 1); if ($secondtolast == '-' && is_numeric($last)) { $slug = substr($orgslug, 0, strlen($orgslug) - 1) . ($last + 1); } else { $slug = $orgslug . '-' . $i; } $exists = $this->where('slug', '=', $slug)->count_all(); $i++; } $this->slug = $slug; } else { if ($this->changed('slug')) { $slug = $this->slug; $slug = site::slugify($slug); $orgslug = $slug; $exists = $this->where('slug', '=', $slug)->where('id', '!=', $this->id)->count_all(); $i = 2; while ((bool) $exists) { $secondtolast = substr($orgslug, strlen($orgslug) - 2, 1); $last = substr($orgslug, strlen($orgslug) - 1, 1); if ($secondtolast == '-' && is_numeric($last)) { $slug = substr($orgslug, 0, strlen($orgslug) - 1) . ($last + 1); } else { $slug = $orgslug . '-' . $i; } $exists = $this->where('slug', '=', $slug)->where('id', '!=', $this->id)->count_all(); $i++; } $this->slug = $slug; } } }
public function action_addtag() { $file = ORM::factory('File', arr::get($_POST, 'id', false)); if (!$file->loaded()) { ajax::error(__('The file wasn\'t found. Has it been deleted in the meantime?')); } $tagtext = arr::get($_POST, 'tag', false); if (!$tagtext) { ajax::error(__('No tag recieved')); } $slug = site::slugify($tagtext); $tag = ORM::factory('Tag')->where('slug', '=', $slug)->find(); if (!$tag->loaded()) { $tag->tag = $tagtext; $tag->slug = $slug; $tag->save(); } $file->add('tags', $tag); ajax::success('ok', array('tag' => array('id' => $tag->id, 'tag' => $tag->tag, 'slug' => $tag->slug))); }
} } return $new; } public function check_slug_and_guid() { if (empty($this->slug)) { if (empty($this->title)) { $this->slug = $this->id; } else { $this->slug = $this->title; } } elseif ($this->changed('slug')) { } else { return; } $this->slug = site::slugify($this->slug); $newguid = $this->slug; $beforeslug = $this->contenttype->slug; if ($this->parent != 0) { $parent = ORM::factory('Content')->where('id', '=', $this->parent)->find(); if ($parent->loaded()) { $beforeslug = $parent->guid . '/'; $newguid = $parent->guid . '/' . $this->slug; } else { // Parent isn't loaded for some reason. Remove parent id $this->parent = 0; } } else { if ($this->contenttype->slug != '') { $newguid = $this->contenttype->slug . '/' . $this->slug; } } $existing = ORM::factory('Content')->where('guid', '=', $newguid)->where('id', '!=', $this->id)->find(); $i = 2; $orgslug = $this->slug; while ($existing->loaded()) { $this->slug = $this->slug . '-' . $i; $newguid = $beforeslug . $this->slug; $existing = ORM::factory('Content')->where('guid', '=', $newguid)->where('id', '!=', $this->id)->find();
public function create(Validation $val = NULL) { $result = parent::create($val); $slug = site::slugify($this->username); $orgslug = $slug; $existing = ORM::factory('User')->where('slug', '=', $slug)->find(); $i = 2; while ($existing->loaded()) { $slug = $orgslug . '-' . $i; $i++; } $this->slug = $slug; $this->update(); $options = ORM::factory('User_Option'); $options->user_id = $this->id; $options->save(); }