Dotclear


Ignore:
Timestamp:
08/23/13 15:40:43 (11 years ago)
Author:
Franck Paul <carnet.franck.paul@…>
Branch:
2.5
Parents:
1538:b956d78197c5 (diff), 1544:44671003d62c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged in lipki/dotclear/Ticket #1430 (pull request #33) - fixes #1430

Files:
2 edited

Legend:

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

    r1429 r1545  
    733733     - no_content: Don't retrieve entry content (excerpt and content) 
    734734     - post_type: Get only entries with given type (default "post", array for many types and '' for no type) 
    735      - post_id: (integer) Get entry with given post_id 
     735     - post_id: (integer or array) Get entry with given post_id 
    736736     - post_url: Get entry with given post_url field 
    737737     - user_id: (integer) Get entries belonging to given user ID 
     
    753753     - limit: Limit parameter 
    754754     - sql_only : return the sql request instead of results. Only ids are selected 
     755     - exclude_post_id : (integer or array) Exclude entries with given post_id 
    755756      
    756757     Please note that on every cat_id or cat_url, you can add ?not to exclude 
     
    846847               } 
    847848               $strReq .= 'AND P.post_id '.$this->con->in($params['post_id']); 
     849          } 
     850           
     851          if (isset($params['exclude_post_id']) && $params['exclude_post_id'] !== '') { 
     852               if (is_array($params['exclude_post_id'])) { 
     853                    array_walk($params['exclude_post_id'],create_function('&$v,$k','if($v!==null){$v=(integer)$v;}')); 
     854               } else { 
     855                    $params['exclude_post_id'] = array((integer) $params['exclude_post_id']); 
     856               } 
     857               $strReq .= 'AND P.post_id NOT '.$this->con->in($params['exclude_post_id']); 
    848858          } 
    849859           
  • inc/core/class.dc.blog.php

    r1544 r1545  
    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