本文整理汇总了PHP中Slug类的典型用法代码示例。如果您正苦于以下问题:PHP Slug类的具体用法?PHP Slug怎么用?PHP Slug使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Slug类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:Atomox,项目名称:benhelmerphotography,代码行数:25,代码来源:album.php
示例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;
}
开发者ID:Atomox,项目名称:benhelmerphotography,代码行数:54,代码来源:content.php
示例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";
}
开发者ID:roobottom,项目名称:roobottom-statamic,代码行数:29,代码来源:pi.wordpress.php
示例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 '';
}
}
}
}
开发者ID:awecode,项目名称:awecms,代码行数:34,代码来源:AweUrlManager.php
示例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');
});
}
}
}
开发者ID:joshreisner,项目名称:avalon,代码行数:37,代码来源:2015_01_17_214846_objects_url.php
示例6: setNameField
public function setNameField($data, $value)
{
if ($data->get(self::SLUG) == null) {
$data->set(self::SLUG, Slug::create($value));
}
return $value;
}
开发者ID:DavBfr,项目名称:BlogMVC,代码行数:7,代码来源:PostsModel.class.php
示例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));
}
开发者ID:awecode,项目名称:awecms,代码行数:29,代码来源:PageController.php
示例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();
});
}
开发者ID:kamaroly,项目名称:shift,代码行数:12,代码来源:Sluggable.php
示例9: updateSlug
public function updateSlug($attr = 'title')
{
if ($attr == 'title') {
$this->slug = Slug::fromTitle($this->title);
} else {
$this->slug = Slug::fromId($this->id);
}
}
开发者ID:floatingpointsoftware,项目名称:grapevine,代码行数:8,代码来源:Sluggable.php
示例10: generateMarkerSlug
public function generateMarkerSlug()
{
$markers = Marker::all();
foreach ($markers as $marker) {
$marker->slug = \Slug::make($marker->name);
$marker->save();
}
}
开发者ID:AngryGantz,项目名称:cms-cookbook,代码行数:8,代码来源:SitemapsController.php
示例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));
}
开发者ID:alexeymezenin,项目名称:laravel-russian-slugs,代码行数:9,代码来源:SlugsTest.php
示例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);
}
开发者ID:andorpandor,项目名称:git-deploy.eu2.frbit.com-yr-prototype,代码行数:18,代码来源:taxonomy.php
示例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;
}
开发者ID:alexeymezenin,项目名称:laravel-russian-slugs,代码行数:19,代码来源:SlugsTrait.php
示例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' => ' техника техника техника техника']);
}
开发者ID:VerticalHorizon,项目名称:Bumagi,代码行数:12,代码来源:CategoriesTableSeeder.php
示例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());
}
}
开发者ID:Khelek,项目名称:ipsol,代码行数:13,代码来源:CategoriesController.php
示例16: update
public function update($id)
{
$news = $this->news->find($id);
if (Input::get('slug') === "") {
Input::merge(['slug' => \Slug::make(Input::get('title'))]);
}
$news->fill(Input::all());
if ($news->updateUniques()) {
return Redirect::route('admin.news.edit', $news->id)->with('success', Lang::get('admin/news/messages.create.success'));
} else {
return Redirect::back()->withInput()->withErrors($news->errors());
}
}
开发者ID:Khelek,项目名称:ipsol,代码行数:13,代码来源:NewsController.php
示例17: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$table = $this->argument('table');
$column = $this->argument('column');
try {
$allRows = \DB::table($table)->select($column)->get();
foreach ($allRows as $row) {
\DB::table($table)->where($column, $row->{$column})->update([config('seoslug.slugColumnName') => \Slug::build($row->{$column})]);
}
} catch (Exception $e) {
$this->error($e->getMessage());
}
$this->info('Table ' . $table . 'has been reslugged successfully');
}
开发者ID:alexeymezenin,项目名称:laravel-russian-slugs,代码行数:19,代码来源:ReslugTableCommand.php
示例18: setForObject
public static function setForObject($object)
{
$slug_source = Slug::source($object->id);
$instances = DB::table($object->name)->get();
$slugs = [];
foreach ($instances as $instance) {
if ($slug_source === null) {
$slug = Slug::make($instance->created_at->format('Y-m-d'), $slugs);
} else {
$slug = Slug::make($instance->{$slug_source}, $slugs);
}
DB::table($object->name)->where('id', $instance->id)->update(['slug' => $slug]);
$slugs[] = $slug;
}
}
开发者ID:joshreisner,项目名称:avalon,代码行数:15,代码来源:Slug.php
示例19: postCreate
/**
* Заносим в БД новую категорию, после проверки ввода
* @param AdminCategoryRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function postCreate(AdminCategoryRequest $request)
{
$data = $request->all();
//Если алиас не задан, то генерируем его
if (!$request->has('alias')) {
$data['alias'] = \Slug::make($request->input('title'));
}
//Проверяем есть ли такой же алиас в БД
if ($this->model->where('alias', '=', $data['alias'])->first()) {
//Алиас такой существует, выводим ошибку
return redirect()->back()->with('error', 'Такой алиас существует!!!');
}
//Создаем новую запись в БД
$this->model->create($data);
return redirect()->route('admin.category.index')->with('success', 'Категория создана!');
}
开发者ID:alexusmai,项目名称:admin,代码行数:21,代码来源:AdminCategoryController.php
示例20: update
public function update($id)
{
$work = $this->work->find($id);
if (Input::get('slug') === "") {
Input::merge(['slug' => \Slug::make(Input::get('title'))]);
}
$work->fill(Input::all());
$work->need_big_preview = Input::get('need_big_preview');
if ($work->updateUniques()) {
if (Input::get('categories')) {
$work->categories()->sync(Input::get('categories'));
}
return Redirect::route('admin.works.edit', $work->id)->with('success', Lang::get('admin/works/messages.create.success'));
} else {
return Redirect::back()->withInput()->withErrors($work->errors());
}
}
开发者ID:Khelek,项目名称:ipsol,代码行数:17,代码来源:WorksController.php
注:本文中的Slug类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论