_getStringAsURL($string); // Look for same URL, if so try until we find a unique one $conditions = array($this->name . '.' . $field => 'LIKE ' . $currentUrl . '%'); $result = $this->findAll($conditions, $this->name . '.*', null); if ($result !== false && count($result) > 0) { $sameUrls = array(); foreach($result as $record) { $sameUrls[] = $record[$this->name][$field]; } } if (isset($sameUrls) && count($sameUrls) > 0) { $currentBegginingUrl = $currentUrl; $currentIndex = 1; while($currentIndex > 0) { if (!in_array($currentBegginingUrl . '_' . $currentIndex, $sameUrls)) { $currentUrl = $currentBegginingUrl . '_' . $currentIndex; $currentIndex = -1; } $currentIndex++; } } return $currentUrl; } function _getStringAsURL($string) { // Define the maximum number of characters allowed as part of the URL $currentMaximumURLLength = 100; $string = strtolower($string); // Any non valid characters will be treated as _, also remove duplicate _ $string = preg_replace('/[^a-z0-9_]/i', '_', $string); $string = preg_replace('/_[_]*/i', '_', $string); // Cut at a specified length if (strlen($string) > $currentMaximumURLLength) { $string = substr($string, 0, $currentMaximumURLLength); } // Remove beggining and ending signs $string = preg_replace('/_$/i', '', $string); $string = preg_replace('/^_/i', '', $string); return $string; } } ?>