Changeset 1435

Show
Ignore:
Timestamp:
04/13/06 11:20:37 (3 years ago)
Author:
mbonetti
Message:

EXPERIMENTAL: page navigation (only used in /state/*, for testing purpose)

Location:
trunk/rss
Files:
1 added
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/rss/cls/items.php

    r1181 r1435  
    244244    var $unreadIids = array(); 
    245245    var $rss; 
    246      
    247  
     246    var $_template; 
     247     
     248    var $_sqlActualWhat = ""; 
     249    var $_sqlActualFrom = ""; 
     250    var $_sqlActualWhere= ""; 
     251    var $_sqlActualOrder= ""; 
     252    var $_sqlActualLimit= ""; 
    248253     
    249254    function ItemList() { 
    250      
     255        $this -> _template = 'itemlist.php'; 
    251256        $this -> rss = &$GLOBALS['rss']; 
    252257         
     
    277282    function populate($sqlWhere, $sqlOrder="", $startItem = 0, $itemCount = -1, $hint = ITEM_SORT_HINT_MIXED, $includeDeprecated = false) { 
    278283 
    279         _pf('ItemList::populate()'); 
    280         $sql = "select i.title,  c.title, c.id, i.unread, " 
     284      _pf('ItemList::populate()'); 
     285        $this -> _sqlActualWhat = " i.title,  c.title, c.id, i.unread, " 
    281286            ."i.url, i.enclosure, i.author, i.description, c.icon, " 
    282287            ." unix_timestamp(ifnull(i.pubdate,i.added)) as ts, " 
    283             ." i.pubdate is not null as ispubdate, i.id, r.rating  " 
    284             ." from ".getTable("item") ." i " 
     288            ." i.pubdate is not null as ispubdate, i.id, r.rating  "; 
     289        $this -> _sqlActualFrom =   getTable("item") ." i " 
    285290            ." left join " 
    286291            . getTable("rating") ." r on (i.id = r.iid), " 
    287292            .getTable("channels")." c, " 
    288             .getTable("folders") ." f " 
    289  
    290             ." where " 
    291             ." i.cid = c.id and " 
     293            .getTable("folders") ." f "; 
     294 
     295        $this -> _sqlActualWhere = " i.cid = c.id and " 
    292296            ." f.id=c.parent and ". (false == $includeDeprecated ? " not(c.mode & ".RSS_MODE_DELETED_STATE.") and " : "") 
    293297            ." not(i.unread & ".RSS_MODE_DELETED_STATE.") and "; 
     
    296300 
    297301        if (hidePrivate()) { 
    298             $sql .= " not(i.unread & ".RSS_MODE_PRIVATE_STATE.") and "; 
    299         } 
    300  
    301         if ($sqlWhere) { 
    302             $sql .= $sqlWhere ." and "; 
    303         } 
    304         $sql .= " 1=1 "; 
     302            $this -> _sqlActualWhere .= " not(i.unread & ".RSS_MODE_PRIVATE_STATE.") and "; 
     303        } 
     304 
     305        if ($this -> _sqlActualWhere) { 
     306            $this -> _sqlActualWhere .= $sqlWhere ." and "; 
     307        } 
     308        $this -> _sqlActualWhere .= " 1=1 "; 
    305309         
    306310        /// Order by 
     
    318322                    break; 
    319323            } 
    320             $sql .= " order by  "; 
     324 
    321325            if (!getConfig('rss.config.feedgrouping')) { 
    322326                if(getConfig("rss.config.datedesc.$skey")){ 
    323                     $sql .= " ts desc, f.position asc, c.position asc "; 
     327                    $this -> _sqlActualOrder = " ts desc, f.position asc, c.position asc "; 
    324328                }else{ 
    325                     $sql .= " ts asc, f.position asc, c.position asc "; 
     329                    $this -> _sqlActualOrder = " ts asc, f.position asc, c.position asc "; 
    326330                } 
    327331            } elseif (getConfig('rss.config.absoluteordering')) { 
    328                 $sql .= " f.position asc, c.position asc"; 
     332                $this -> _sqlActualOrder = " f.position asc, c.position asc"; 
    329333            } else { 
    330                 $sql .= " f.name asc, c.title asc"; 
     334                $this -> _sqlActualOrder = " f.name asc, c.title asc"; 
    331335            } 
    332336            if(getConfig("rss.config.datedesc.$skey")){ 
    333                 $sql .= ", ts desc, i.id asc"; 
     337                $this -> _sqlActualOrder .= ", ts desc, i.id asc"; 
    334338            }else{ 
    335                 $sql .= ", ts asc, i.id asc"; 
     339                $this -> _sqlActualOrder .= ", ts asc, i.id asc"; 
    336340            } 
    337341        } else { 
    338             $sql .= " $sqlOrder ";   
     342            $this -> _sqlActualOrder = " $sqlOrder ";    
    339343        } 
    340344        if (($itemCount < 0) || ($itemCount > RSS_DB_MAX_QUERY_RESULTS)) { 
    341345            $itemCount = RSS_DB_MAX_QUERY_RESULTS; 
    342346        } 
    343         $sql .= " limit $startItem, $itemCount"; 
    344  
     347        $this -> _sqlActualLimit = " $startItem, $itemCount"; 
     348 
     349        $sql = "select " 
     350            .$this -> _sqlActualWhat 
     351            . " from " 
     352            .$this -> _sqlActualFrom 
     353            . " where " 
     354            . $this -> _sqlActualWhere 
     355            . " order by " 
     356            . $this -> _sqlActualOrder 
     357            . " limit " 
     358            . $this -> _sqlActualLimit; 
     359             
    345360        //echo $sql;         
    346361        $this -> iids = array(); 
     
    461476        rss_plugin_hook('rss.plugins.items.beforeitems', null); 
    462477 
    463         eval($this-> rss ->getCachedTemplateFile("itemlist.php")); 
     478        eval($this-> rss ->getCachedTemplateFile($this -> _template)); 
    464479         
    465480        _pf("done: ItemList -> render()"); 
     
    470485} 
    471486 
    472  
     487class ItemListNavigation { 
     488    var $_parent; 
     489    var $pages; 
     490    function ItemListNavigation($il) { 
     491        $this -> _parent = $il; 
     492        $this -> pages = array(); 
     493        $base = $_SERVER["REQUEST_URI"]; 
     494        if (!preg_match('#page=[0-9]+$#',$base)) { 
     495            $base .= "?page=0"; 
     496        } 
     497        $last = ceil( $this -> _parent -> numItems / $this -> _parent -> itemsPerPage); 
     498        $lastin = 0; 
     499        for ($i = 0; $i < $last; $i++) { 
     500            if ($i == 0 || $i == $last-1 || abs($i - $this -> _parent -> page) < 3) { 
     501                $url = preg_replace('#^(.+)page=[0-9]+$#','${1}page='.$i, $base); 
     502                $this -> pages[$i] = array($url, $i == $this -> _parent -> page, false); 
     503                $lastin = $i; 
     504            } elseif ($i - 1 == $lastin) { 
     505                $this -> pages[$i] = array(null,false,true); 
     506            } 
     507        } 
     508    } 
     509    function render() { 
     510        eval($this-> _parent -> rss ->getCachedTemplateFile('pagination.php')); 
     511    } 
     512} 
     513 
     514class PaginatedItemList extends ItemList { 
     515    var $page; 
     516    var $navigation; 
     517    var $itemsPerPage = 0; 
     518    var $numItems = 0; 
     519    function PaginatedItemList() {  
     520        parent::ItemList();  
     521        if (isset($_REQUEST['page'])) { 
     522            $this -> page = sanitize($_REQUEST['page'], RSS_SANITIZER_NUMERIC); 
     523        } else { 
     524            $this -> page = 0; 
     525        } 
     526         
     527        $this ->  itemsPerPage = getConfig('rss.output.frontpage.numitems'); 
     528    } 
     529    function populate($sqlWhere, $sqlOrder="", $startItem = 0, $itemCount = -1, $hint = ITEM_SORT_HINT_MIXED, $includeDeprecated = false) { 
     530 
     531        $si = $this -> page * $this ->  itemsPerPage; 
     532        parent::populate($sqlWhere, $sqlOrder, $si, $this ->  itemsPerPage, $hint, $includeDeprecated); 
     533         
     534        $sql = "select count(*) as cnt " 
     535            . " from " 
     536            . $this -> _sqlActualFrom 
     537            . " where " 
     538            . $this -> _sqlActualWhere; 
     539        list($this -> numItems) = rss_fetch_row(rss_query($sql)); 
     540        $this -> navigation = new ItemListNavigation(& $this); 
     541    } 
     542} 
    473543?> 
  • trunk/rss/cls/wrappers/itemlist.php

    r1181 r1435  
    9191} 
    9292 
     93function rss_itemlist_navigation() { 
     94    if (isset($GLOBALS['rss'] -> currentItemList -> navigation)) { 
     95        $GLOBALS['rss'] -> currentItemList -> navigation -> render(); 
     96    } 
     97} 
     98 
     99function rss_itemlist_navigation_pages() { 
     100    if (isset($GLOBALS['rss'] -> currentItemList -> navigation)) { 
     101        return $GLOBALS['rss'] -> currentItemList -> navigation -> pages; 
     102    } 
     103} 
    93104?> 
  • trunk/rss/state.php

    r1181 r1435  
    2929require_once('init.php'); 
    3030 
    31 $items = new ItemList(); 
     31$items = new PaginatedItemList(); 
    3232$items -> setRenderOptions(IL_NO_COLLAPSE); 
    3333 
  • trunk/rss/themes/default/web/css/look.css

    r1374 r1435  
    444444    width: 100%; 
    445445} 
     446 
  • trunk/rss/themes/default/web/itemlist.php

    r1302 r1435  
    1515<?php } ?> 
    1616<?php echo rss_itemlist_before_list(); ?> 
     17<?php rss_itemlist_navigation(); ?> 
    1718<?php rss_itemlist_feeds(); ?> 
     19<?php rss_itemlist_navigation(); ?> 
    1820<?php echo rss_itemlist_after_list(); ?>