/**
  * 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);
     }
 }
 /**
  * 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);
 }
예제 #3
0
 public function onBeforeWrite()
 {
     if (!$this->URLSegment) {
         $filter = URLSegmentFilter::create();
         $this->URLSegment = $filter->filter($this->Title);
     }
     parent::onBeforeWrite();
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if ($this->Title) {
         $filter = URLSegmentFilter::create();
         $this->URLSegment = $filter->filter($this->Title);
         //$this->URLSegment = SiteTree::GenerateURLSegment($this->Title);
     }
 }
 /**
  * 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;
 }
예제 #6
0
 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;
 }
 /**
  * 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;
 }
 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;
 }
 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';
     }
 }
 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;
     }
 }
 /**
  * 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;
 }
예제 #12
0
 /**
  * Based on the title of product it generates a URLSegment for it
  * so that SEO friendly Product pages can be generated.
  *
  * Credit: https://gist.github.com/Zauberfisch/9460395
  *
  * @return string URLSegment /product-title-x-y-z/
  */
 protected function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->ProductDescription) {
         $this->ProductDescription = $this->ProductDescription;
     }
     $filter = URLSegmentFilter::create();
     if (!$this->URLSegment) {
         $this->URLSegment = $this->ProductDescription;
     }
     $this->URLSegment = $filter->filter($this->URLSegment);
     if (!$this->URLSegment) {
         $this->URLSegment = uniqid();
     }
     $count = 2;
     while (static::get_by_url_segment($this->URLSegment, $this->ID)) {
         // add a -n to the URLSegment if it already existed
         $this->URLSegment = preg_replace('/-[0-9]+$/', null, $this->URLSegment) . '-' . $count;
         $count++;
     }
 }
 /**
  * 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;
     }
 }
예제 #14
0
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     $classname = strtolower($this->owner->ClassName);
     $filter = URLSegmentFilter::create();
     if ((!$this->owner->URLSegment || $this->owner->URLSegment == 'new-' . $classname) && $this->owner->Title != 'New ' . $classname) {
         $this->owner->URLSegment = $filter->filter($this->owner->Title);
     } else {
         if ($this->owner->isChanged('URLSegment')) {
             $segment = preg_replace('/[^A-Za-z0-9]+/', '-', $this->owner->URLSegment);
             $segment = preg_replace('/-+/', '-', $segment);
             if (!$segment) {
                 $segment = $classname . "-" . $this->owner->ID;
             }
             $this->owner->URLSegment = $segment;
         }
     }
     $count = 2;
     while ($this->LookForExistingURLSegment($this->owner->URLSegment)) {
         $this->owner->URLSegment = preg_replace('/-[0-9]+$/', null, $this->owner->URLSegment) . '-' . $count;
         $count++;
     }
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     // set URLSegment
     if ($this->Title) {
         $filter = URLSegmentFilter::create();
         $this->URLSegment = $filter->filter($this->Title);
         //$this->URLSegment = SiteTree::GenerateURLSegment($this->Title);
     }
     // Some cleaning up
     //		$this->Title = trim( $this->Title ); // strip spaces
     //		// if multiple with same title, combine in this one & remove duplicates;
     //		$sameTitleTag = FilterCategory::get()->filter('Title', $this->Title)->exclude('ID',$this->ID);
     //		if( $sameTitleTag->count() && $this->ID ){ //only if editing existing (ID is set)
     //			foreach( $sameTitleTag as $duplicate ){
     //				debug::dump($duplicate->Pages());
     ////				foreach( $duplicate->Pages() as $page ){
     ////					//add each page to this cat/tag
     ////					//$this->Pages()->add( $page->ID );
     ////				}
     //			}
     //		}
 }
예제 #16
0
 /**
  * Convert a string (normally a title) to a string suitable for using in
  * urls and other html attributes. Uses {@link URLSegmentFilter}.
  *
  * @param string 
  * @return string
  */
 public static function raw2url($title)
 {
     $f = URLSegmentFilter::create();
     return $f->filter($title);
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     // Only call on first creation, ir if title is changed
     if ($this->ID == 0 || $this->isChanged('Title') || !$this->URLSegment) {
         // Set the URL Segment, so it can be accessed via the controller
         $filter = URLSegmentFilter::create();
         $t = $filter->filter($this->Title);
         // Fallback to generic name if path is empty (= no valid, convertable characters)
         if (!$t || $t == '-' || $t == '-1') {
             $t = "category-{$this->ID}";
         }
         // Ensure that this object has a non-conflicting URLSegment value.
         $existing_cats = ProductCategory::get()->filter('URLSegment', $t)->count();
         $existing_products = Product::get()->filter('URLSegment', $t)->count();
         $existing_pages = class_exists('SiteTree') ? SiteTree::get()->filter('URLSegment', $t)->count() : 0;
         $count = (int) $existing_cats + (int) $existing_products + (int) $existing_pages;
         $this->URLSegment = $count ? $t . '-' . ($count + 1) : $t;
     }
 }
 protected function paginationName()
 {
     $name = $this->ID;
     if (!$name) {
         $name = URLSegmentFilter::create()->filter($this->Title);
     }
     return 'list' . $name;
 }
 /**
  * Generates an Url segment by a given string.
  * You can pass a DataObject as 2nd parameter, which's ClassName
  * and ID will be used if the filtering on title fails.
  * 
  * @param  string $title
  * @param  DataObject $instance
  * @return string
  */
 public static function generate_urlsegment($title, DataObject $instance = null)
 {
     $filter = URLSegmentFilter::create();
     $t = $filter->filter($title);
     if (!$t || $t == '-' || $t == '-1' && $instance != null) {
         $t = "{$instance->ClassName}-{$instance->ID}";
     }
     return $t;
 }
 /**
  * Taken from https://github.com/NightJar/ssrigging-slug/blob/master/code/Slug.php
  */
 public function Slug($regen = false)
 {
     $existing = $this->URLSlug;
     return $existing && !$regen ? $existing : URLSegmentFilter::create()->filter($this->Title);
 }
 function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->IP) {
         $this->IP = $this->getIPAddress();
     }
     if (!$this->Code) {
         $this->Code = substr(hash("md5", uniqid()), 0, 7);
     }
     if ($this->Title) {
         $filter = URLSegmentFilter::create();
         $this->URLSegment = $filter->filter($this->Title);
         // Fallback to generic page name if path is empty (= no valid, convertable characters)
         if (!$this->URLSegment || $this->URLSegment == '-' || $this->URLSegment == '-1') {
             $this->URLSegment = $this->Code;
         }
         $originalURLSegment = $this->URLSegment;
         $originalTitle = $this->Title;
         $id = intval($this->ID) - 0;
         for ($i = 2; $i < 9999; $i++) {
             $count = EVCDataSet::get()->filter(array("URLSegment" => $this->URLSegment))->exclude(array("ID" => $id))->Count();
             if ($count) {
                 $this->URLSegment = $originalURLSegment . "-" . $i;
                 $this->Title = $originalTitle . " #" . $i;
             } else {
                 $i = 9999999;
             }
         }
     }
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     //default title
     if (!$this->Title) {
         $class = get_class($this);
         $objects = DataObject::get($class);
         $this->Title = singleton($class)->i18n_singular_name() . ' ' . ($objects->count() + 1);
     }
     if (!$this->URLSegment) {
         $this->URLSegment = URLSegmentFilter::create()->filter($this->Title);
     } else {
         if ($this->isChanged('URLSegment')) {
             $this->URLSegment = URLSegmentFilter::create()->filter($this->URLSegment);
         }
     }
     if ($this->isChanged('URLSegment') && ($original = $this->URLSegment)) {
         //make sure it is unique
         $safe = false;
         $counter = 1;
         while (!$safe) {
             $counter++;
             if (ContentModule::get()->filter(array('URLSegment' => $this->URLSegment, 'ID' => $this->ID))->first()) {
                 $this->URLSegment = $original . '-' . $counter;
             } else {
                 $safe = true;
             }
         }
     }
 }
 protected function onbeforeWrite()
 {
     parent::onBeforeWrite();
     $filter = URLSegmentFilter::create();
     $this->JsonFileName = $filter->filter($this->Name);
 }
 public function getReference()
 {
     $filter = URLSegmentFilter::create();
     return $filter->filter($this->section->getReference() . '-' . $this->getName());
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     $this->prime();
     // add a URL segment based on the name if one is not already present
     if (!$this->URLSegment) {
         $filter = URLSegmentFilter::create();
         $t = $filter->filter($this->Name);
         $this->URLSegment = $t;
         // Fallback to generic page name if path is empty (= no valid, convertable characters)
         if (!$t || $t == '-' || $t == '-1') {
             echo "Segment fallback\n";
             $this->URLSegment = "station-{$this->OpenWeatherMapStationID}";
         }
     }
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     // If there is no URLSegment set, generate one from Title
     if ((!$this->URLSegment || $this->URLSegment == 'new-product') && $this->Title) {
         $this->URLSegment = $this->generateURLSegment($this->Title);
     } elseif ($this->isChanged('URLSegment', 2)) {
         // Do a strict check on change level, to avoid double encoding caused by
         // bogus changes through forceChange()
         $filter = URLSegmentFilter::create();
         $this->URLSegment = $filter->filter($this->URLSegment);
         // If after sanitising there is no URLSegment, give it a reasonable default
         if (!$this->URLSegment) {
             $this->URLSegment = "page-{$this->ID}";
         }
     }
     // Ensure that this object has a non-conflicting URLSegment value.
     $count = 2;
     while (!$this->validURLSegment()) {
         $this->URLSegment = preg_replace('/-[0-9]+$/', null, $this->URLSegment) . '-' . $count;
         $count++;
     }
     if ($this->ID && $this->config()->auto_stock_id && !$this->StockID) {
         $title = "";
         foreach (explode("-", $this->URLSegment) as $string) {
             $string = substr($string, 0, 1);
             $title .= $string;
         }
         $this->StockID = $title . "-" . $this->ID;
     }
 }
예제 #27
0
 protected function validate()
 {
     $valid = parent::validate();
     if (!$valid->valid()) {
         return $valid;
     }
     if (is_subclass_of(Controller::curr(), "LeftAndMain")) {
         if (empty($this->Name)) {
             return $valid->error('Name is empty!');
         }
         if (empty($this->URL)) {
             return $valid->error('URL is empty!');
         }
         if (empty($this->URLSegment)) {
             $filter = URLSegmentFilter::create();
             $slug = $filter->filter($this->Name);
             // Fallback to generic page name if path is empty (= no valid, convertable characters)
             if (!$slug || $slug == '-' || $slug == '-1') {
                 return $valid->error(sprintf('invalid Autogenerated URLSegment (%s) ! please set one by hand.', $slug));
             }
             $this->URLSegment = $slug;
         }
         if (empty($this->URLSegment)) {
             return $valid->error('URLSegmen is empty!');
         }
         if ($this->LookForExistingURLSegment($this->URLSegment)) {
             return $valid->error(sprintf('invalid URLSegment: %s already exists! choose another one', $this->URLSegment));
         }
     }
     return $valid;
 }
예제 #28
0
 public function Slug($regen = false)
 {
     $name = $this->name;
     $existing = $this->owner->URLSlug;
     return $existing && !$regen ? $existing : URLSegmentFilter::create()->filter($this->owner->{$name});
 }
 /**
  * @param  bool $title
  * @return string
  */
 public function getGeneratedIdentifier($title = false)
 {
     return URLSegmentFilter::create()->filter($title ? $title : $this->owner->Title);
 }
 /**
  * stringToSEOURL()
  *
  * @param $string = The string to convert to an SEO safe URL.
  * @author George Botley <*****@*****.**>
  *
  * @usage Calenadr::stringToSEOURL('Today is Wednesday') outputs as today-is-wednesday
  */
 public function stringToSEOURL($String)
 {
     $filter = URLSegmentFilter::create();
     $t = $filter->filter($String);
     // Fallback to generic page name if path is empty (= no valid, convertable characters)
     if (!$t || $t == '-' || $t == '-1') {
         $t = "page-{$this->ID}";
     }
     return $t;
 }