Dotclear


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.blog.php

    r1353 r1468  
    634634     private function checkCategory($title,$url,$id=null) 
    635635     { 
    636           $strReq = 'SELECT cat_id '. 
    637                     'FROM '.$this->prefix.'category '. 
    638                     "WHERE cat_url = '".$this->con->escape($url)."' ". 
    639                     "AND blog_id = '".$this->con->escape($this->id)."' "; 
    640            
    641           if ($id !== null) { 
    642                $strReq .= 'AND cat_id <> '.(integer) $id.' '; 
    643           } 
     636          # Let's check if URL is taken... 
     637          $strReq =  
     638               'SELECT cat_url FROM '.$this->prefix.'category '. 
     639               "WHERE cat_url = '".$this->con->escape($url)."' ". 
     640               ($id ? 'AND cat_id <> '.(integer) $id. ' ' : ''). 
     641               "AND blog_id = '".$this->con->escape($this->id)."' ". 
     642               'ORDER BY cat_url DESC'; 
    644643           
    645644          $rs = $this->con->select($strReq); 
    646645           
    647           if (!$rs->isEmpty()) { 
    648                throw new Exception(__('Category URL must be unique.')); 
    649           } 
     646          if (!$rs->isEmpty()) 
     647          { 
     648               if ($this->con->driver() == 'mysql') { 
     649                    $clause = "REGEXP '^".$this->con->escape($url)."[0-9]+$'"; 
     650               } elseif ($this->con->driver() == 'pgsql') { 
     651                    $clause = "~ '^".$this->con->escape($url)."[0-9]+$'"; 
     652               } else { 
     653                    $clause = "LIKE '".$this->con->escape($url)."%'"; 
     654               } 
     655               $strReq =  
     656                    'SELECT cat_url FROM '.$this->prefix.'category '. 
     657                    "WHERE cat_url ".$clause.' '. 
     658                    ($id ? 'AND cat_id <> '.(integer) $id. ' ' : ''). 
     659                    "AND blog_id = '".$this->con->escape($this->id)."' ". 
     660                    'ORDER BY cat_url DESC '; 
     661                
     662               $rs = $this->con->select($strReq); 
     663               $a = array(); 
     664               while ($rs->fetch()) { 
     665                    $a[] = $rs->cat_url; 
     666               } 
     667                
     668               natsort($a); 
     669               $t_url = end($a); 
     670                
     671               if (preg_match('/(.*?)([0-9]+)$/',$t_url,$m)) { 
     672                    $i = (integer) $m[2]; 
     673                    $url = $m[1]; 
     674               } else { 
     675                    $i = 1; 
     676               } 
     677                
     678               return $url.($i+1); 
     679          } 
     680           
     681          # URL is empty? 
     682          if ($url == '') { 
     683               throw new Exception(__('Empty category URL')); 
     684          } 
     685           
     686          return $url; 
    650687     } 
    651688      
     
    669706           
    670707          # Check if title or url are unique 
    671           $this->checkCategory($cur->cat_title,$cur->cat_url,$id); 
     708          $cur->cat_url = $this->checkCategory($cur->cat_title,$cur->cat_url,$id); 
    672709           
    673710          if ($cur->cat_desc !== null) { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map