• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP URLSegmentFilter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中URLSegmentFilter的典型用法代码示例。如果您正苦于以下问题:PHP URLSegmentFilter类的具体用法?PHP URLSegmentFilter怎么用?PHP URLSegmentFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了URLSegmentFilter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: generateURLSegment

 /**
  * Generates a unique URLSegment from the title.
  *
  * @param int $increment
  *
  * @return string
  */
 public function generateURLSegment($increment = null)
 {
     $filter = new URLSegmentFilter();
     // Setting this to on. Because of the UI flow, it would be quite a lot of work
     // to support turning this off. (ie. the add by title flow would not work).
     // If this becomes a problem we can approach it then.
     // @see https://github.com/silverstripe/silverstripe-blog/issues/376
     $filter->setAllowMultibyte(true);
     $this->owner->URLSegment = $filter->filter($this->owner->Title);
     if (is_int($increment)) {
         $this->owner->URLSegment .= '-' . $increment;
     }
     // Postgres use '' instead of 0 as an emtpy blog ID
     // Without this all the tests fail
     if (!$this->owner->BlogID) {
         $this->owner->BlogID = 0;
     }
     $duplicate = DataList::create($this->owner->ClassName)->filter(array('URLSegment' => $this->owner->URLSegment, 'BlogID' => $this->owner->BlogID));
     if ($this->owner->ID) {
         $duplicate = $duplicate->exclude('ID', $this->owner->ID);
     }
     if ($duplicate->count() > 0) {
         if (is_int($increment)) {
             $increment += 1;
         } else {
             $increment = 0;
         }
         $this->owner->generateURLSegment((int) $increment);
     }
     return $this->owner->URLSegment;
 }
开发者ID:javabrett,项目名称:silverstripe-blog,代码行数:38,代码来源:URLSegmentExtension.php


示例2: generateURLSegment

 /**
  * Generates a unique URLSegment from the title.
  *
  * @param int $increment
  *
  * @return string
  */
 public function generateURLSegment($increment = null)
 {
     $filter = new URLSegmentFilter();
     $this->owner->URLSegment = $filter->filter($this->owner->Title);
     if (is_int($increment)) {
         $this->owner->URLSegment .= '-' . $increment;
     }
     // Postgres use '' instead of 0 as an emtpy blog ID
     // Without this all the tests fail
     if (!$this->owner->BlogID) {
         $this->owner->BlogID = 0;
     }
     $duplicate = DataList::create($this->owner->ClassName)->filter(array('URLSegment' => $this->owner->URLSegment, 'BlogID' => $this->owner->BlogID));
     if ($this->owner->ID) {
         $duplicate = $duplicate->exclude('ID', $this->owner->ID);
     }
     if ($duplicate->count() > 0) {
         if (is_int($increment)) {
             $increment += 1;
         } else {
             $increment = 0;
         }
         $this->owner->generateURLSegment((int) $increment);
     }
     return $this->owner->URLSegment;
 }
开发者ID:micmania1,项目名称:silverstripe-blog,代码行数:33,代码来源:URLSegmentExtension.php


示例3: getCMSFields

 public function getCMSFields()
 {
     $fields = new FieldList([TextField::create('Title')]);
     if ($this->exists()) {
         $folderName = 'Documents';
         $config = $this->Page()->exists() ? $this->Page()->config()->get('page_documents') : null;
         if (is_array($config)) {
             if (isset($config['folder'])) {
                 $folderName = $config['folder'];
             }
             if (isset($config['section']) && $config['section']) {
                 $filter = new URLSegmentFilter();
                 $section = implode('-', array_map(function ($string) {
                     return ucfirst($string);
                 }, explode('-', $filter->filter($this->Title))));
                 $folderName .= '/' . $section;
             }
         }
         $fields->push(SortableUploadField::create('Documents', 'Documents')->setDescription('Drag documents by thumbnail to sort')->setFolderName($folderName));
     } else {
         $fields->push(LiteralField::create('DocumentsNotSaved', '<p>Save category to add documents</p>'));
     }
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
开发者ID:webfox,项目名称:silverstripe-page-documents,代码行数:25,代码来源:PageDocumentCategory.php


示例4: onAfterWrite

 public function onAfterWrite()
 {
     parent::onAfterWrite();
     $class = $this->ownerBaseClass;
     $config = Config::inst()->forClass($class);
     // look for fields to use in slug
     $fields = array('Title');
     if ($config->slug_fields) {
         $fields = $config->slug_fields;
     }
     $needSlug = false;
     foreach ($fields as $field) {
         if ($this->owner->isChanged($field, 2)) {
             $needSlug = true;
             break;
         }
     }
     if (!$this->owner->Slug) {
         $needSlug = true;
     }
     // if we need a slug, compute it
     if ($needSlug && $this->owner->ID) {
         $slug = '';
         foreach ($fields as $field) {
             $slug .= ' ' . $this->owner->{$field};
         }
         $slug = trim($slug);
         $baseSlug = $slug;
         $filter = new URLSegmentFilter();
         $oldSlug = $this->owner->Slug;
         $newSlug = substr($filter->filter($slug), 0, 140);
         $this->owner->Slug = $newSlug;
         // check for existing slugs
         $count = 0;
         $record = self::getBySlug($class, $newSlug, $this->owner->ID);
         while ($record && $record->exists()) {
             $count++;
             $slug = $baseSlug . '-' . $count;
             $newSlug = $filter->filter($slug);
             $this->owner->Slug = $newSlug;
             $record = self::getBySlug($class, $newSlug, $this->owner->ID);
         }
         // prevent infinite loop because of onAfterWrite called multiple times
         if ($oldSlug == $newSlug) {
             return;
         }
         $this->owner->write();
         // store history
         if ($oldSlug && $oldSlug != $this->owner->Slug) {
             $count = SlugHistory::check($class, $oldSlug, $this->owner->ID);
             if ($count) {
                 // it already exists, no need to add twice
                 return;
             }
             SlugHistory::recordFromObject($this->owner, $oldSlug);
         }
     }
 }
开发者ID:lekoala,项目名称:silverstripe-devtoolkit,代码行数:58,代码来源:SlugExtension.php


示例5: testReplacements

 function testReplacements()
 {
     $f = new URLSegmentFilter();
     $this->assertEquals('tim-and-struppi', $f->filter('Tim&Struppi'));
     // Customize replacements
     $rs = $f->getReplacements();
     $rs['/&/u'] = '-und-';
     $f->setReplacements($rs);
     $this->assertEquals('tim-und-struppi', $f->filter('Tim&Struppi'));
 }
开发者ID:nomidi,项目名称:sapphire,代码行数:10,代码来源:URLSegmentFilterTest.php


示例6: getCalcAssetsFolderDirectory

 /**
  * The gallery directory is created based on the page name
  * You can overwrite this behavior by extending this page
  * TODO this could also be made configurable
  * @return string
  */
 function getCalcAssetsFolderDirectory()
 {
     if ($this->ID) {
         $filter = URLSegmentFilter::create();
         return Config::inst()->get('GalleryExtension', 'gallery_folder') . '/' . $this->ID . '-' . $filter->filter($this->Title);
     }
 }
开发者ID:titledk,项目名称:silverstripe-gallery-pagetypes,代码行数:13,代码来源:GalleryPage.php


示例7: onBeforeWrite

 public function onBeforeWrite()
 {
     if (!$this->URLSegment) {
         $filter = URLSegmentFilter::create();
         $this->URLSegment = $filter->filter($this->Title);
     }
     parent::onBeforeWrite();
 }
开发者ID:helpfulrobot,项目名称:plumpss-news,代码行数:8,代码来源:NewsCategory.php


示例8: setURLSegment

 /**
  * custom setter for urlsegment
  * runs param through urlsegment filter to sanitize any unwanted characters
  * calls existsInScope for uniqueness check, otherwise appends random number until unique
  */
 function setURLSegment($value)
 {
     $urlSegment = URLSegmentFilter::create()->filter($value);
     while ($this->existsInScope($urlSegment)) {
         $urlSegment = $urlSegment . rand(1, 9);
     }
     $this->owner->setField("URLSegment", $urlSegment);
 }
开发者ID:helpfulrobot,项目名称:icecaster-urlsegmented,代码行数:13,代码来源:URLSegmented.php


示例9: onBeforeWrite

 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if ($this->Title) {
         $filter = URLSegmentFilter::create();
         $this->URLSegment = $filter->filter($this->Title);
         //$this->URLSegment = SiteTree::GenerateURLSegment($this->Title);
     }
 }
开发者ID:helpfulrobot,项目名称:micschk-silverstripe-filterablearchive,代码行数:9,代码来源:FilterTag.php


示例10: generateURLSegment

 /** 
  * Generates a unique URLSegment from the title.
  *
  * @param $increment
  *
  * @return string URLSegment
  **/
 public function generateURLSegment($increment = null)
 {
     $filter = new URLSegmentFilter();
     $this->owner->URLSegment = $filter->filter($this->owner->Title);
     if (is_int($increment)) {
         $this->owner->URLSegment .= '-' . $increment;
     }
     // Check to see if the URLSegment already exists
     $duplicate = DataList::create($this->owner->ClassName)->filter(array("URLSegment" => $this->owner->URLSegment, "BlogID" => $this->owner->BlogID));
     if ($this->owner->ID) {
         $duplicate = $duplicate->exclude("ID", $this->owner->ID);
     }
     if ($duplicate->count() > 0) {
         $increment = is_int($increment) ? $increment + 1 : 0;
         $this->owner->generateURLSegment((int) $increment);
     }
     return $this->owner->URLSegment;
 }
开发者ID:helpfulrobot,项目名称:micmania1-silverstripe-blog,代码行数:25,代码来源:URLSegmentExtension.php


示例11: getFolderForClass

 /**
  * Get folder for a given class
  * 
  * @param mixed $class
  * @return string
  */
 public static function getFolderForClass($class)
 {
     $folderName = 'Uploads';
     if (is_object($class)) {
         if (method_exists($class, 'hasMethod') && $class->hasMethod('BaseFolder')) {
             $folderName = $class->BaseFolder();
         } else {
             if ($class instanceof Page) {
                 $folderName = get_class($class);
             } else {
                 if ($class instanceof DataObject) {
                     $folderName = $class->baseTable();
                 } else {
                     if ($class instanceof DataExtension) {
                         $folderName = $class->getOwner()->baseTable();
                     } else {
                         $folderName = get_class($class);
                     }
                 }
             }
         }
     } else {
         if (is_string($class)) {
             $folderName = $class;
         }
     }
     if (class_exists('Subsite') && Config::inst()->get(__CLASS__, 'use_subsite_integration')) {
         $subsite = Subsite::currentSubsite();
         if ($subsite) {
             // Subsite extras integration$
             if ($subsite->hasField('BaseFolder')) {
                 $baseFolder = $subsite->BaseFolder;
             } else {
                 $filter = new URLSegmentFilter();
                 $baseFolder = $filter->filter($subsite->getTitle());
                 $baseFolder = str_replace(' ', '', ucwords(str_replace('-', ' ', $baseFolder)));
             }
             if (!empty($baseFolder)) {
                 $folderName = $baseFolder . '/' . $folderName;
             }
         }
     }
     return $folderName;
 }
开发者ID:helpfulrobot,项目名称:lekoala-silverstripe-form-extras,代码行数:50,代码来源:BaseUploadField.php


示例12: generateURLSegment

 private function generateURLSegment($title)
 {
     $filter = URLSegmentFilter::create();
     $t = $filter->filter($title);
     // Fallback to generic page name if path is empty (= no valid, convertable characters)
     if (!$t || $t == '-' || $t == '-1') {
         $t = "page-{$this->ID}";
     }
     return $t;
 }
开发者ID:rbowen,项目名称:openstack-org,代码行数:10,代码来源:VideoPresentation.php


示例13: generateURLSegment

 /**
  * Generate a unique URL segment based on the Member's name.
  *
  * @return string
  */
 public function generateURLSegment()
 {
     $filter = URLSegmentFilter::create();
     $name = $this->owner->FirstName . ' ' . $this->owner->Surname;
     $urlSegment = $filter->filter($name);
     if (!$urlSegment || $urlSegment == '-' || $urlSegment == '-1') {
         $urlSegment = 'profile-' . $this->owner->ID;
     }
     return $urlSegment;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-blog,代码行数:15,代码来源:BlogMemberExtension.php


示例14: generateURLSegment

 /**
  * Generates a unique URLSegment from the title.
  *
  * @param int $increment
  *
  * @return string
  */
 public function generateURLSegment($increment = null)
 {
     $filter = new URLSegmentFilter();
     $this->owner->URLSegment = $filter->filter($this->owner->Title);
     if (is_int($increment)) {
         $this->owner->URLSegment .= '-' . $increment;
     }
     $duplicate = DataList::create($this->owner->ClassName)->filter(array('URLSegment' => $this->owner->URLSegment, 'BlogID' => $this->owner->BlogID));
     if ($this->owner->ID) {
         $duplicate = $duplicate->exclude('ID', $this->owner->ID);
     }
     if ($duplicate->count() > 0) {
         if (is_int($increment)) {
             $increment += 1;
         } else {
             $increment = 0;
         }
         $this->owner->generateURLSegment((int) $increment);
     }
     return $this->owner->URLSegment;
 }
开发者ID:nimeso,项目名称:silverstripe-blog,代码行数:28,代码来源:URLSegmentExtension.php


示例15: generateURLSegment

 /**
  * Generate a URL segment based on the title provided.
  *
  * If {@link Extension}s wish to alter URL segment generation, they can do so by defining
  * updateURLSegment(&$url, $title).  $url will be passed by reference and should be modified.
  * $title will contain the title that was originally used as the source of this generated URL.
  * This lets extensions either start from scratch, or incrementally modify the generated URL.
  *
  * @param string $title the given title
  * @return string generated url segment
  */
 public function generateURLSegment($title)
 {
     $filter = URLSegmentFilter::create();
     $t = $filter->filter($title);
     // Fallback to generic page name if path is empty (= no valid, convertable characters)
     if (!$t || $t == '-' || $t == '-1') {
         $t = $this->fallbackUrl();
     }
     // Hook for extensions
     $this->owner->extend('updateURLSegment', $t, $title);
     return $t;
 }
开发者ID:helpfulrobot,项目名称:ntb-silverstripe-rest-api,代码行数:23,代码来源:SlugableExtension.php


示例16: generateSlug

 public function generateSlug($title, $allowExtension = true)
 {
     $t = \URLSegmentFilter::create()->filter($title);
     // Fallback to generic page name if path is empty (= no valid, convertable characters)
     if (!$t || $t == '-' || $t == '-1') {
         $t = "menu-{$this->ID}";
     }
     // Hook for extensions
     if ($allowExtension) {
         $this->extend('updateSlug', $t, $title);
     }
     return $t;
 }
开发者ID:milkyway-multimedia,项目名称:ss-linkable-menus,代码行数:13,代码来源:LinkableMenu.php


示例17: updateURLSegment

 public function updateURLSegment(&$t, $title)
 {
     $filter = URLSegmentFilter::create();
     // use default transliterator
     $title = $filter->getTransliterator()->toASCII($title);
     // set cyrillic transliterator
     $filter->setTransliterator(CyrillicTransliterator::create());
     $t = $filter->filter($title);
     // Fallback to generic page name if path is empty (= no valid, convertable characters)
     if (!$t || $t == '-' || $t == '-1') {
         $t = "page-" . $this->owner->ID;
     }
 }
开发者ID:helpfulrobot,项目名称:unisolutions-silverstripe-cyrillic-transliterator,代码行数:13,代码来源:CyrillicURLSegmentExtension.php


示例18: onBeforeWrite

 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if ($this->isChanged('URLSegment')) {
         $this->URLSegment = URLSegmentFilter::create()->filter($this->URLSegment);
     }
     if (!$this->URLSegment) {
         $this->URLSegment = URLSegmentFilter::create()->filter($this->Title);
     }
     if (!$this->URLSegment) {
         $this->URLSegment = 'main';
     }
 }
开发者ID:helpfulrobot,项目名称:silverstripe-frontend-dashboards,代码行数:13,代码来源:DashboardPage.php


示例19: generateURLSegment

 /**
  * Generate a URL segment based on the title provided.
  * 
  * @param string $title Page title.
  * @return string Generated url segment
  */
 protected function generateURLSegment($title)
 {
     $filter = URLSegmentFilter::create();
     $t = $filter->filter($title);
     // Fallback to generic name if path is empty (= no valid, convertable characters)
     if (!$t || $t == '-' || $t == '-1') {
         $t = "{$this->owner->ClassName}-{$this->owner->ID}";
     } else {
         // Make sure that it does not already exists for another object
         $class = $this->owner->ClassName;
         $obj = $class::get()->filter(array("URLSegment" => $t))->exclude(array("ID" => $this->owner->ID))->first();
         if ($obj) {
             $t .= "-{$this->owner->ID}";
         }
     }
     return $t;
 }
开发者ID:helpfulrobot,项目名称:linkdup-silverstripe-seofriendlydataobject,代码行数:23,代码来源:SeoFriendlyDataObject.php


示例20: generateURLSegment

 /**
  * COPIED FROM SITETREE
  *
  * Generate a URL segment based on the title provided.
  * 
  * @param string $title Product title
  * @return string Generated url segment
  */
 public function generateURLSegment($title)
 {
     $filter = URLSegmentFilter::create();
     $t = $filter->filter($title);
     // Fallback to generic page name if path is empty (= no valid, convertable characters)
     if (!$t || $t == '-' || $t == '-1') {
         $t = "page-{$this->ID}";
     }
     // Hook for extensions
     $this->extend('updateURLSegment', $t, $title);
     // Check to see if URLSegment exists already, if it does, append -* where * is COUNT()+1
     $seg = new SQLQuery('COUNT(*)');
     $seg->setFrom(get_class($this))->addWhere("`URLSegment` LIKE '%{$t}%'");
     $count = $seg->execute()->value();
     if ($count > 0) {
         $count++;
         return $t . "-" . $count;
     } else {
         return $t;
     }
 }
开发者ID:micschk,项目名称:torindul-silverstripe-shop,代码行数:29,代码来源:Product_Categories.php



注:本文中的URLSegmentFilter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP URLify类代码示例发布时间:2022-05-23
下一篇:
PHP URLHelper类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap