Exemple #1
0
 /**
 Make a metadata ID URL-proof.
 
 @param	str		<b>string</b>	the metadata ID.
 
 @return	<b>string</b>	The sanitized metadata
 */
 public static function sanitizeMetaID($str)
 {
     return text::tidyURL($str, false, true);
 }
Exemple #2
0
 /**
 Returns URL for a post according to blog setting <var>post_url_format</var>.
 It will try to guess URL and append some figures if needed.
 
 @param	url			<b>string</b>		Origin URL, could be empty
 @param	post_dt		<b>string</b>		Post date (in YYYY-MM-DD HH:mm:ss)
 @param	post_title	<b>string</b>		Post title
 @param	post_id		<b>integer</b>		Post ID
 @return	<b>string</b>	result URL
 */
 public function getPostURL($url, $post_dt, $post_title, $post_id)
 {
     $url = trim($url);
     $url_patterns = array('{y}' => date('Y', strtotime($post_dt)), '{m}' => date('m', strtotime($post_dt)), '{d}' => date('d', strtotime($post_dt)), '{t}' => text::tidyURL($post_title), '{id}' => (int) $post_id);
     # If URL is empty, we create a new one
     if ($url == '') {
         # Transform with format
         $url = str_replace(array_keys($url_patterns), array_values($url_patterns), $this->settings->system->post_url_format);
     } else {
         $url = text::tidyURL($url);
     }
     # Let's check if URL is taken...
     $strReq = 'SELECT post_url FROM ' . $this->prefix . 'post ' . "WHERE post_url = '" . $this->con->escape($url) . "' " . 'AND post_id <> ' . (int) $post_id . ' ' . "AND blog_id = '" . $this->con->escape($this->id) . "' " . 'ORDER BY post_url DESC';
     $rs = $this->con->select($strReq);
     if (!$rs->isEmpty()) {
         if ($this->con->driver() == 'mysql' || $this->con->driver() == 'mysqli') {
             $clause = "REGEXP '^" . $this->con->escape($url) . "[0-9]+\$'";
         } elseif ($this->con->driver() == 'pgsql') {
             $clause = "~ '^" . $this->con->escape($url) . "[0-9]+\$'";
         } else {
             $clause = "LIKE '" . $this->con->escape($url) . "%'";
         }
         $strReq = 'SELECT post_url FROM ' . $this->prefix . 'post ' . "WHERE post_url " . $clause . ' ' . 'AND post_id <> ' . (int) $post_id . ' ' . "AND blog_id = '" . $this->con->escape($this->id) . "' " . 'ORDER BY post_url DESC ';
         $rs = $this->con->select($strReq);
         $a = array();
         while ($rs->fetch()) {
             $a[] = $rs->post_url;
         }
         natsort($a);
         $t_url = end($a);
         if (preg_match('/(.*?)([0-9]+)$/', $t_url, $m)) {
             $i = (int) $m[2];
             $url = $m[1];
         } else {
             $i = 1;
         }
         return $url . ($i + 1);
     }
     # URL is empty?
     if ($url == '') {
         throw new Exception(__('Empty entry URL'));
     }
     return $url;
 }
Exemple #3
0
 /**
  * Transform a string in slug regarding to configuration.
  *
  * @param string $str
  */
 public static function strToSlug($str, $with_slashes = true)
 {
     /*
     static $sType = null;
     
     if (is_null($sType))
     {
     	global $okt;
     
     	if (isset($okt) && !empty($okt->config->slug_type)) {
     		$sType = $okt->config->slug_type;
     	}
     	else {
     		$sType = 'ascii';
     	}
     }
     */
     switch ($GLOBALS['okt']->config->slug_type) {
         case 'utf8':
             return text::tidyURL($str, $with_slashes);
         case 'ascii':
         default:
             return self::strToLowerURL($str, $with_slashes);
     }
 }