当前位置: 首页>>代码示例>>PHP>>正文


PHP URLSegmentFilter类代码示例

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


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


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