Beispiel #1
0
 /**
  * Generate clean URL
  *
  * @param \XLite\Model\AEntity $entity         Entity
  * @param string               $base           Base OPTIONAL
  *
  * @return string
  */
 public function generateCleanURL(\XLite\Model\AEntity $entity, $base = null)
 {
     $result = '';
     if (null === $base) {
         $base = $this->getURLBase($entity);
     }
     $base = \XLite\Core\Converter::convertToTranslit($base);
     if ($base) {
         $separator = $this->getSeparator($entity);
         $result .= strtolower(preg_replace('/\\W+/S', $separator, $base));
         if ($this->isCapitalizeWords($entity)) {
             $words = explode($separator, $result);
             $words = array_map('ucfirst', $words);
             $result = implode($separator, $words);
         }
         $suffix = '';
         $increment = 1;
         while (!$this->isURLUnique($this->postProcessURL($result . $suffix, $entity), $entity) && static::CLEAN_URL_CHECK_LIMIT > $increment) {
             $suffix = $separator . $increment++;
         }
         if (!empty($suffix)) {
             $result .= $suffix;
         }
         $result = $this->postProcessURL($result, $entity);
     }
     return $result;
 }