Dotclear

Changeset 1429:edca6a120928


Ignore:
Timestamp:
08/17/13 15:30:32 (12 years ago)
Author:
Denis Jean-Christian <contact@…>
Branch:
Ticket#1531
Children:
1430:3b3bd51f7a9d, 1431:656a54cfb1b2
Message:

Increment duplicate category URL. (like post URL), fixes #1531

File:
1 edited

Legend:

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

    r1262 r1429  
    645645     private function checkCategory($title,$url,$id=null) 
    646646     { 
    647           $strReq = 'SELECT cat_id '. 
    648                     'FROM '.$this->prefix.'category '. 
    649                     "WHERE cat_url = '".$this->con->escape($url)."' ". 
    650                     "AND blog_id = '".$this->con->escape($this->id)."' "; 
    651            
    652           if ($id !== null) { 
    653                $strReq .= 'AND cat_id <> '.(integer) $id.' '; 
    654           } 
     647          # Let's check if URL is taken... 
     648          $strReq =  
     649               'SELECT cat_url FROM '.$this->prefix.'category '. 
     650               "WHERE cat_url = '".$this->con->escape($url)."' ". 
     651               ($id ? 'AND cat_id <> '.(integer) $id. ' ' : ''). 
     652               "AND blog_id = '".$this->con->escape($this->id)."' ". 
     653               'ORDER BY cat_url DESC'; 
    655654           
    656655          $rs = $this->con->select($strReq); 
    657656           
    658           if (!$rs->isEmpty()) { 
    659                throw new Exception(__('Category URL must be unique.')); 
    660           } 
     657          if (!$rs->isEmpty()) 
     658          { 
     659               if ($this->con->driver() == 'mysql') { 
     660                    $clause = "REGEXP '^".$this->con->escape($url)."[0-9]+$'"; 
     661               } elseif ($this->con->driver() == 'pgsql') { 
     662                    $clause = "~ '^".$this->con->escape($url)."[0-9]+$'"; 
     663               } else { 
     664                    $clause = "LIKE '".$this->con->escape($url)."%'"; 
     665               } 
     666               $strReq =  
     667                    'SELECT cat_url FROM '.$this->prefix.'category '. 
     668                    "WHERE cat_url ".$clause.' '. 
     669                    ($id ? 'AND cat_id <> '.(integer) $id. ' ' : ''). 
     670                    "AND blog_id = '".$this->con->escape($this->id)."' ". 
     671                    'ORDER BY cat_url DESC '; 
     672                
     673               $rs = $this->con->select($strReq); 
     674               $a = array(); 
     675               while ($rs->fetch()) { 
     676                    $a[] = $rs->cat_url; 
     677               } 
     678                
     679               natsort($a); 
     680               $t_url = end($a); 
     681                
     682               if (preg_match('/(.*?)([0-9]+)$/',$t_url,$m)) { 
     683                    $i = (integer) $m[2]; 
     684                    $url = $m[1]; 
     685               } else { 
     686                    $i = 1; 
     687               } 
     688                
     689               return $url.($i+1); 
     690          } 
     691           
     692          # URL is empty? 
     693          if ($url == '') { 
     694               throw new Exception(__('Empty category URL')); 
     695          } 
     696           
     697          return $url; 
    661698     } 
    662699      
     
    680717           
    681718          # Check if title or url are unique 
    682           $this->checkCategory($cur->cat_title,$cur->cat_url,$id); 
     719          $cur->cat_url = $this->checkCategory($cur->cat_title,$cur->cat_url,$id); 
    683720           
    684721          if ($cur->cat_desc !== null) { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map