summaryrefslogtreecommitdiffstats
path: root/wp-inst/wp-content/smarty-plugins/function.lastposts.php
blob: 60da3766fbf7ad78cf33e83769af307818e121de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

/* $Id: function.lastposts.php,v 1.3 2005/01/09 11:54:18 donncha Exp $ */


/*
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     function
 * Name:     lastposts
 * Purpose:  Returns a list of the last posts to the blog
 * -------------------------------------------------------------
 */

function getposts( $wpblog, $posts )
{
    global $wpdb;

    $query = "SELECT ID, post_title
              FROM ".$wpdb->posts."
              WHERE unix_timestamp( post_date ) < unix_timestamp( NOW() )
              AND   post_status = 'publish'
              ORDER BY `post_date` DESC LIMIT 0, ".intval( $posts );
    $result = $wpdb->get_results( $query );
    if( $result )
    {   
        foreach( $result as $details )
        {
            $postdata[ $details->ID ] = stripslashes( strip_tags( $details->post_title ) );
        }

        return $postdata;
    }
    else
    {
        return false;
    }
}

function smarty_function_lastposts($params, &$smarty)
{

    global $wpblog;

    $posts = 10;
    extract($params);

    if( $posts > 40 )
        $posts = 40;

    if( @include_once( "Cache/Function.php" ) )
    {
        $cache = new Cache_Function( 'file', array('cache_dir' => ABSPATH . "/wp-content/smarty-cache", 'filename_prefix' => 'lastposts_cache_' ), 600 ); 
        $lastposts = $cache->call( "getposts", $wpblog, $posts );
    }
    else
    {
        $lastposts = getposts( $wpblog, $posts );
    }

    $smarty->assign( "lastposts", $lastposts );
}

/* vim: set expandtab: */

?>