Dotclear

Changeset 2143


Ignore:
Timestamp:
03/29/10 12:50:23 (13 years ago)
Author:
JcDenis
Message:

lastpostsExtend 0.8.2:

  • Fixed getPosts status by using sudo
  • Fixed entryFirstImage on non-pushided post
Location:
plugins/lastpostsExtend
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • plugins/lastpostsExtend/_admin.php

    r1966 r2143  
    33# This file is part of lastpostsExtend, a plugin for Dotclear 2. 
    44#  
    5 # Copyright (c) 2009 JC Denis and contributors 
     5# Copyright (c) 2009-2010 JC Denis and contributors 
    66# jcdenis@gdwd.com 
    77#  
  • plugins/lastpostsExtend/_define.php

    r2007 r2143  
    33# This file is part of lastpostsExtend, a plugin for Dotclear 2. 
    44#  
    5 # Copyright (c) 2009 JC Denis and contributors 
     5# Copyright (c) 2009-2010 JC Denis and contributors 
    66# jcdenis@gdwd.com 
    77#  
     
    1717     /* Description*/         "Widget like lastposts with extended options", 
    1818     /* Author */             "JC Denis", 
    19      /* Version */            '0.8.1', 
     19     /* Version */            '0.8.2', 
    2020     /* Permissions */        'admin' 
    2121); 
    22      /* date */          #20091231 
     22     /* date */          #20100329 
    2323?> 
  • plugins/lastpostsExtend/_public.php

    r1966 r2143  
    33# This file is part of lastpostsExtend, a plugin for Dotclear 2. 
    44#  
    5 # Copyright (c) 2009 JC Denis and contributors 
     5# Copyright (c) 2009-2010 JC Denis and contributors 
    66# jcdenis@gdwd.com 
    77#  
  • plugins/lastpostsExtend/_widgets.php

    r2007 r2143  
    33# This file is part of lastpostsExtend, a plugin for Dotclear 2. 
    44#  
    5 # Copyright (c) 2009 JC Denis and contributors 
     5# Copyright (c) 2009-2010 JC Denis and contributors 
    66# jcdenis@gdwd.com 
    77#  
     
    278278          } 
    279279 
    280           $rs = self::getPosts($params); 
     280          //$rs = self::getPosts($params); 
     281          $rs = $core->auth->sudo(array($core->blog,'getPosts'),$params,false); 
    281282 
    282283          # No result 
     
    304305               if ($w->firstimage != '') 
    305306               { 
    306                     $res .= self::entryFirstImage($core,$w->posttype,$rs->post_id,$w->firstimage); 
     307                    $res .= self::entryFirstImage($core,$rs->post_type,$rs->post_id,$w->firstimage); 
    307308               } 
    308309               # Excerpt 
     
    334335          if (!in_array($type,array('post','page','galitem'))) return ''; 
    335336 
    336           $rs = $core->blog->getPosts(array('post_id'=>$id,'post_type'=>$type)); 
     337          $rs = $core->auth->sudo(array($core->blog,'getPosts'),array('post_id'=>$id,'post_type'=>$type),false); 
    337338 
    338339          if ($rs->isEmpty()) return ''; 
     
    375376          '<div class="img-thumbnail">'. 
    376377          '<a title="'.html::escapeHTML($rs->post_title).'" href="'.$rs->getURL().'">'. 
    377           '<img alt="'.$alt.'" src="'.$src.'" />'. 
     378          '<img alt="'.$alt.'" src="'.stripslashes($src).'" />'. 
    378379          '</a></div>'. 
    379380          "</div>\n"; 
     
    412413          return $res ? $res : false; 
    413414     } 
    414  
    415      public static function getPosts($params=array(),$count_only=false) 
    416      { 
    417           global $core; 
    418            
    419           $content_req = ''; 
    420           if (!empty($params['columns']) && is_array($params['columns'])) { 
    421                $content_req .= implode(', ',$params['columns']).', '; 
    422           } 
    423  
    424           $strReq = 
    425           'SELECT P.post_id, P.blog_id, P.user_id, P.cat_id, post_dt, '. 
    426           'post_tz, post_creadt, post_upddt, post_format, post_password, '. 
    427           'post_url, post_lang, post_title, '. 
    428           $content_req. 
    429           'post_type, post_meta, post_status, post_selected, '. 
    430           'nb_comment, '. 
    431           'U.user_name, U.user_firstname, U.user_displayname, U.user_email, '. 
    432           'U.user_url, '. 
    433           'C.cat_title, C.cat_url, C.cat_desc '. 
    434           'FROM '.$core->prefix.'post P '. 
    435           'INNER JOIN '.$core->prefix.'user U ON U.user_id = P.user_id '. 
    436           'LEFT OUTER JOIN '.$core->prefix.'category C ON P.cat_id = C.cat_id '; 
    437            
    438           if (!empty($params['from'])) { 
    439                $strReq .= $params['from'].' '; 
    440           } 
    441            
    442           $strReq .= 
    443           "WHERE P.blog_id = '".$core->con->escape($core->blog->id)."' "; 
    444  
    445           if (isset($params['post_type'])) 
    446           { 
    447                if (is_array($params['post_type']) && !empty($params['post_type'])) { 
    448                     $strReq .= 'AND post_type '.$core->con->in($params['post_type']); 
    449                } elseif ($params['post_type'] != '') { 
    450                     $strReq .= "AND post_type = '".$core->con->escape($params['post_type'])."' "; 
    451                } 
    452           } 
    453           else 
    454           { 
    455                $strReq .= "AND post_type = 'post' "; 
    456           } 
    457  
    458           if (!empty($params['cat_id'])) 
    459           { 
    460                if (!is_array($params['cat_id'])) { 
    461                     $params['cat_id'] = array($params['cat_id']); 
    462                } 
    463                if (!empty($params['cat_id_not'])) { 
    464                     array_walk($params['cat_id'],create_function('&$v,$k','$v=$v." ?not";')); 
    465                } 
    466                $strReq .= 'AND '.self::getPostsCategoryFilter($params['cat_id'],'cat_id').' '; 
    467           } 
    468           elseif (!empty($params['cat_url'])) 
    469           { 
    470                if (!is_array($params['cat_url'])) { 
    471                     $params['cat_url'] = array($params['cat_url']); 
    472                } 
    473                if (!empty($params['cat_url_not'])) { 
    474                     array_walk($params['cat_url'],create_function('&$v,$k','$v=$v." ?not";')); 
    475                } 
    476                $strReq .= 'AND '.self::getPostsCategoryFilter($params['cat_url'],'cat_url').' '; 
    477           } 
    478  
    479           if (isset($params['post_status'])) { 
    480                $strReq .= 'AND post_status = '.(integer) $params['post_status'].' '; 
    481           } 
    482            
    483           if (isset($params['post_selected'])) { 
    484                $strReq .= 'AND post_selected = '.(integer) $params['post_selected'].' '; 
    485           } 
    486  
    487           if (!empty($params['post_lang'])) { 
    488                $strReq .= "AND P.post_lang = '".$core->con->escape($params['post_lang'])."' "; 
    489           } 
    490  
    491           if (!empty($params['search'])) 
    492           { 
    493                $words = text::splitWords($params['search']); 
    494                 
    495                if (!empty($words)) 
    496                { 
    497                     # --BEHAVIOR-- corePostSearch 
    498                     if ($core->hasBehavior('corePostSearch')) { 
    499                          $core->callBehavior('corePostSearch',$core,array(&$words,&$strReq,&$params)); 
    500                     } 
    501                      
    502                     if ($words) 
    503                     { 
    504                          foreach ($words as $i => $w) { 
    505                               $words[$i] = "post_words LIKE '%".$core->con->escape($w)."%'"; 
    506                          } 
    507                          $strReq .= 'AND '.implode(' AND ',$words).' '; 
    508                     } 
    509                } 
    510           } 
    511  
    512           if (!empty($params['sql'])) { 
    513                $strReq .= $params['sql'].' '; 
    514           } 
    515  
    516           $strReq .= 'GROUP BY P.post_id '; 
    517            
    518           if (!empty($params['order'])) { 
    519                $strReq .= 'ORDER BY '.$core->con->escape($params['order']).', P.post_id '; 
    520           } else { 
    521                $strReq .= 'ORDER BY post_dt, P.post_id DESC '; 
    522           } 
    523  
    524           if (!empty($params['limit'])) { 
    525                $strReq .= $core->con->limit($params['limit']); 
    526           } 
    527            
    528           $rs = $core->con->select($strReq); 
    529           $rs->core = $core; 
    530           $rs->_nb_media = array(); 
    531           $rs->extend('rsExtPost'); 
    532            
    533           # --BEHAVIOR-- coreBlogGetPosts 
    534           $core->callBehavior('coreBlogGetPosts',$rs); 
    535            
    536           return $rs; 
    537      } 
    538       
    539      public static function getPostsCategoryFilter($arr,$field='cat_id') 
    540      { 
    541           global $core; 
    542           $field = $field == 'cat_id' ? 'cat_id' : 'cat_url'; 
    543            
    544           $sub = array(); 
    545           $not = array(); 
    546           $queries = array(); 
    547            
    548           foreach ($arr as $v) 
    549           { 
    550                $v = trim($v); 
    551                $args = preg_split('/\s*[?]\s*/',$v,-1,PREG_SPLIT_NO_EMPTY); 
    552                $id = array_shift($args); 
    553                $args = array_flip($args); 
    554                 
    555                if (isset($args['not'])) { $not[$id] = 1; } 
    556                if (isset($args['sub'])) { $sub[$id] = 1; } 
    557                if ($field == 'cat_id') { 
    558                     $queries[$id] = 'P.cat_id = '.(integer) $id; 
    559                } else { 
    560                     $queries[$id] = "C.cat_url = '".$core->con->escape($id)."' "; 
    561                } 
    562           } 
    563            
    564           if (!empty($sub)) { 
    565                $rs = $core->con->select( 
    566                     'SELECT cat_id, cat_url, cat_lft, cat_rgt FROM '.$core->prefix.'category '. 
    567                     "WHERE blog_id = '".$core->con->escape($core->blog->id)."' ". 
    568                     'AND '.$field.' '.$core->con->in(array_keys($sub)) 
    569                ); 
    570                 
    571                while ($rs->fetch()) { 
    572                     $queries[$rs->f($field)] = '(C.cat_lft BETWEEN '.$rs->cat_lft.' AND '.$rs->cat_rgt.')'; 
    573                } 
    574           } 
    575            
    576           # Create queries 
    577           $sql = array( 
    578                0 => array(), # wanted categories 
    579                1 => array()  # excluded categories 
    580           ); 
    581            
    582           foreach ($queries as $id => $q) { 
    583                $sql[(integer) isset($not[$id])][] = $q; 
    584           } 
    585            
    586           $sql[0] = implode(' OR ',$sql[0]); 
    587           $sql[1] = implode(' OR ',$sql[1]); 
    588            
    589           if ($sql[0]) { 
    590                $sql[0] = '('.$sql[0].')'; 
    591           } else { 
    592                unset($sql[0]); 
    593           } 
    594            
    595           if ($sql[1]) { 
    596                $sql[1] = '(P.cat_id IS NULL OR NOT('.$sql[1].'))'; 
    597           } else { 
    598                unset($sql[1]); 
    599           } 
    600            
    601           return implode(' AND ',$sql); 
    602      } 
    603415} 
    604416?> 
  • plugins/lastpostsExtend/release.txt

    r2007 r2143  
     10.8.2 20100329 
     2 * Fixed getPosts by using sudo 
     3 * Fixed entryFirstImage on non-pushided post 
     4 
    150.8.1 20091231 
    26 * Happy new year! 
Note: See TracChangeset for help on using the changeset viewer.

Sites map