本文整理汇总了PHP中Slug类的典型用法代码示例。如果您正苦于以下问题:PHP Slug类的具体用法?PHP Slug怎么用?PHP Slug使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Slug类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _slug
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;
}
示例2: _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;
}
示例3: go
public function go()
{
//$feed = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/_add-ons/wordpress/wp_posts.xml');
//$items = simplexml_load_string($feed);
$posts_object = simplexml_load_file($_SERVER['DOCUMENT_ROOT'] . '/_add-ons/wordpress/roobottom_old_posts.xml');
$posts = object_to_array($posts_object);
$yaml_path = $_SERVER['DOCUMENT_ROOT'] . '/_content/01-blog/';
foreach ($posts['table'] as $post) {
if ($post['column'][8] == "publish") {
$slug = Slug::make($post['column'][5]);
$slug = preg_replace('/[^a-z\\d]+/i', '-', $slug);
if (substr($slug, -1) == '-') {
$slug = substr($slug, 0, -1);
}
$date = date('Y-m-d-Hi', strtotime($post['column'][3]));
$file = $date . "-" . $slug . ".md";
if (!File::exists($yaml_path . $file)) {
$yaml = [];
$yaml['title'] = $post['column'][5];
$content = $post['column'][4];
$markdown = new HTML_To_Markdown($content, array('header_style' => 'atx'));
File::put($yaml_path . $file, YAML::dump($yaml) . '---' . "\n" . $markdown);
}
echo $slug . "-" . $date;
echo "<br/><hr/><br/>";
}
}
return "ok";
}
示例4: parseUrl
public function parseUrl($request)
{
if ($this->getUrlFormat() === self::PATH_FORMAT) {
$rawPathInfo = $request->getPathInfo();
if (Settings::get('SEO', 'slugs_enabled') && ($p = Slug::getPath($rawPathInfo))) {
$rawPathInfo = trim($p, '/');
Yii::app()->punish = 0;
}
$pathInfo = $this->removeUrlSuffix($rawPathInfo, $this->urlSuffix);
foreach ($this->_rules as $i => $rule) {
if (is_array($rule)) {
$this->_rules[$i] = $rule = Yii::createComponent($rule);
}
if (($r = $rule->parseUrl($this, $request, $pathInfo, $rawPathInfo)) !== false) {
return isset($_GET[$this->routeVar]) ? $_GET[$this->routeVar] : $r;
}
}
if ($this->useStrictParsing) {
throw new AweException(404, Yii::t('yii', 'Unable to resolve the request "{route}".', array('{route}' => $pathInfo)));
} else {
return $pathInfo;
}
} else {
if (isset($_GET[$this->routeVar])) {
return $_GET[$this->routeVar];
} else {
if (isset($_POST[$this->routeVar])) {
return $_POST[$this->routeVar];
} else {
return '';
}
}
}
}
示例5: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table(DB_OBJECTS, function ($table) {
$table->string('url')->nullable();
});
DB::table(DB_FIELDS)->where('name', 'slug')->delete();
//add slug column to all tables that don't have it
$objects = DB::table(DB_OBJECTS)->get();
foreach ($objects as $object) {
//add slug column
if (Schema::hasColumn($object->name, 'slug')) {
DB::table($object->name)->whereNull('slug')->update(['slug' => '']);
DB::update('ALTER TABLE `' . $object->name . '` MODIFY `slug` VARCHAR(255) NOT NULL');
Schema::table($object->name, function ($table) {
//$table->unique('slug');
});
} else {
Schema::table($object->name, function ($table) {
$table->string('slug');
//->unique();
});
//set slug values
Slug::setForObject($object);
}
//add created_by column, not sure why this wasn't added earlier
if (!Schema::hasColumn($object->name, 'created_by')) {
Schema::table($object->name, function ($table) {
$table->integer('created_by');
});
}
}
}
示例6: setNameField
public function setNameField($data, $value)
{
if ($data->get(self::SLUG) == null) {
$data->set(self::SLUG, Slug::create($value));
}
return $value;
}
示例7: actionUpdate
public function actionUpdate($id)
{
$page = $this->loadModel($id);
if (isset($_POST['Page'])) {
if (Settings::get('SEO', 'slugs_enabled')) {
if (isset($page->slug)) {
if (isset($page->slug->slug) && $_POST['Page']['slug'] != $page->slug->slug) {
if ($_POST['Page']['slug'] == '') {
$page->slug->delete();
$page->slug = NULL;
} else {
$page->slug->change($_POST['Page']['slug']);
}
}
} else {
$page->slug = Slug::create($_POST['Page']['slug'], array('view', 'id' => $id));
$page->save();
}
}
try {
if ($page->save()) {
$this->redirect(array('view', 'id' => $page->id));
}
} catch (Exception $e) {
$page->addError('', $e->getMessage());
}
}
$this->render('update', array('page' => $page));
}
示例8: boot
/**
* When the model boots, register a created event listener that will create a slug,
* using the model's id as the salt value for the generation of thee slug.
*/
public static function boot()
{
parent::boot();
static::created(function ($model) {
$model->slug = Slug::create($model->id);
$model->save();
});
}
示例9: updateSlug
public function updateSlug($attr = 'title')
{
if ($attr == 'title') {
$this->slug = Slug::fromTitle($this->title);
} else {
$this->slug = Slug::fromId($this->id);
}
}
示例10: generateMarkerSlug
public function generateMarkerSlug()
{
$markers = Marker::all();
foreach ($markers as $marker) {
$marker->slug = \Slug::make($marker->name);
$marker->save();
}
}
示例11: testBuildMethodThroughFacade
public function testBuildMethodThroughFacade()
{
$this->assertEquals('the_show_must_go_on', Slug::build('The Show Must Go On', '_'));
$this->assertEquals('ничего_на_свете_лучше_нету', Slug::build('Ничего на свете лучше нету', '_', 1, false));
$this->assertEquals('чем-бродить-друзьям-по-белу-свету', Slug::build('Чем бродить друзьям по белу свету', '-', 1, false));
$this->assertEquals('Тем_кто_дружен', Slug::build('Тем, кто дружен', '_', 1, true));
$this->assertEquals('Ne-strashny-trevogi', Slug::build('Не страшны тревоги...', '-', 2, true));
$this->assertEquals('nam_lyubye_dorogi_dorogi', Slug::build('Нам любые дороги дороги!', '_', 2, false));
}
示例12: getURL
/**
* Returns the URL for a given $taxonomy and $taxonomy_slug
*
* @param string $folder Folder to use
* @param string $taxonomy Taxonomy to use
* @param string $taxonomy_slug Taxonomy slug to use
* @return string
*/
public static function getURL($folder, $taxonomy, $taxonomy_slug)
{
$url = Config::getSiteRoot() . '/' . $folder . '/' . $taxonomy . '/';
$url .= Config::getTaxonomySlugify() ? Slug::make($taxonomy_slug) : $taxonomy_slug;
// if taxonomies are not case-sensitive, make it lowercase
if (!Config::getTaxonomyCaseSensitive()) {
$url = strtolower($url);
}
return Path::tidy($url);
}
示例13: reslug
/**
* Create or recreate slugs in a column.
*
* @param $fromColumn Column to work with. String from this column will be converted to a slug.
* @param bool $force When true, forces recreation of a slug, even if it exists.
* @return $this
*/
public function reslug($fromColumn = false, $force = false)
{
$slugColumn = config('seoslug.slugColumnName');
if ($fromColumn === false) {
$fromColumn = $this->slugFrom;
}
// If slug needs to be created or recreated
if (empty($this->{$slugColumn}) || $force) {
$this->{$slugColumn} = \Slug::build($this->{$fromColumn});
}
return $this;
}
示例14: run
public function run()
{
Category::create(['title' => 'Офисная бумага', 'alias' => Slug::make('Офисная бумага', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => 'бумага бумага бумага бумага ']);
Category::create(['title' => 'Ризография', 'alias' => Slug::make('Ризография', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => 'ручки ручки ручки ручки ручки ручки ручки ']);
Category::create(['title' => 'Картрижди', 'alias' => Slug::make('Картрижди', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => ' техника техника техника техника']);
$category = Category::create(['title' => 'Канцтовары', 'alias' => Slug::make('Канцтовары', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => ' техника техника техника техника']);
Category::create(['title' => 'Бумага для заметок', 'alias' => Slug::make('Бумага для заметок', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => ' техника техника техника техника', 'parent_id' => $category->id]);
Category::create(['title' => 'Дыроколы', 'alias' => Slug::make('Дыроколы', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => ' техника техника техника техника', 'parent_id' => $category->id]);
Category::create(['title' => 'Ежедневники', 'alias' => Slug::make('Ежедневники', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => ' техника техника техника техника', 'parent_id' => $category->id]);
Category::create(['title' => 'Полиграфические материалы', 'alias' => Slug::make('Полиграфические материалы', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => ' техника техника техника техника']);
Category::create(['title' => 'Офисная техника', 'alias' => Slug::make('Офисная техника', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => ' техника техника техника техника']);
}
示例15: update
public function update($id)
{
$category = $this->category->find($id);
if (Input::get('slug') === "") {
Input::merge(['slug' => \Slug::make(Input::get('name'))]);
}
$category->fill(Input::all());
if ($category->updateUniques()) {
return Redirect::route('admin.works.categories.index')->with('success', Lang::get('admin/blogs/messages.create.success'));
} else {
return Redirect::back()->withInput(['only' => []])->withErrors($category->errors());
}
}