root/trunk/gregarius/admin/dashboard.php

Revision 1577, 5.6 kB (checked in by mbonetti, 2 years ago)

some more l10n stuff

  • Property svn:eol-style set to native
Line 
1<?php
2###############################################################################
3# Gregarius - A PHP based RSS aggregator.
4# Copyright (C) 2003 - 2006 Marco Bonetti
5#
6###############################################################################
7# This program is free software and open source software; you can redistribute
8# it and/or modify it under the terms of the GNU General Public License as
9# published by the Free Software Foundation; either version 2 of the License,
10# or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful, but WITHOUT
13# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14# FITNESS FOR A PARTICULAR PURPOSE.      See the GNU General Public License for
15# more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  or visit
20# http://www.gnu.org/licenses/gpl.html
21#
22###############################################################################
23# E-mail:          mbonetti at gmail dot com
24# Web page:        http://gregarius.net/
25#
26###############################################################################
27
28
29function dashboard() {
30    $idtoken = _VERSION_ . "-" . md5($_SERVER["HTTP_HOST"]);
31   
32    $magpieCacheAge = 60*60*24;
33
34    if (function_exists('apache_request_headers')) {
35        $hdrs = apache_request_headers();
36        if (
37            (isset($hdrs['Pragma']) && $hdrs['Pragma']=='no-cache') ||
38            (isset($hdrs['Cache-Control']) && $hdrs['Cache-Control']=='no-cache')) {
39            $magpieCacheAge = 0;
40        }
41    }
42        define ('MAGPIE_FETCH_TIME_OUT',2);
43    define ('MAGPIE_CACHE_AGE', $magpieCacheAge);
44    $rs = rss_query(
45    "select id, title, position, url, obj, unix_timestamp(daterefreshed), itemcount "
46    ." from " . getTable('dashboard') . " order by position asc");
47    $rss = array();
48    while (list($id, $title,$pos,$url,$obj, $ts, $cnt) = rss_fetch_row($rs)) {
49        if ($obj && (time() - $ts < $magpieCacheAge)) {
50                $rss[$title] = unserialize($obj);
51        } else {
52                $old_level = error_reporting(E_ERROR);
53                $rss[$title]  = fetch_rss($url.$idtoken);
54                error_reporting($old_level);
55                if ($rss[$title] && is_object($rss[$title])) {
56                        $rss[$title] -> items = array_slice($rss[$title] -> items, 0, $cnt);
57                        rss_query('update ' .getTable('dashboard') . " set obj='"
58                                .rss_real_escape_string(serialize($rss[$title])). "', "
59                                ." daterefreshed=now()  where id=$id");
60                }
61        }
62       
63        if ($rss[$title] && is_object($rss[$title])) {
64                if ($pos == 0) {
65                                                echo "
66                                                        <h2 style=\"margin-bottom: 0.5em\">$title</h2>
67                                                        <div id=\"db_main\">
68                                                        <ul>";
69                                foreach ($rss[$title] -> items as $item) {
70                                                        echo "<li class=\"item unread\">\n"
71                                                                ."<h4><a href=\"".$item['link']."\">".$item['title']."</a></h4>\n"
72                                                                ."<h5>Posted: " .time_since(strtotime($item['pubdate'])) . " ago </h5>\n"
73                                                                ."<div class=\"content\">" . $item['content']['encoded'] ."</div>\n</li>\n";                                   
74                                }
75                                echo "</ul></div>\n";                           
76                } else {
77            echo "<div class=\"frame db_side\">\n";
78                                        db_side($title,$rss[$title]);
79                                        echo "</div>";                 
80                }
81        }
82    }
83}
84
85function db_side($title,&$rss) {
86    echo "<h3>$title</h3>\n"
87    ."<ul>";
88    foreach ($rss -> items as $item) {
89        //              var_dump($item);
90        echo "<li>\n"
91        ."<h5><a href=\"".htmlentities($item['link'])."\">".$item['title']."</a></h5>"
92        //                      ."By " . $item['dc']['author'] . ", " . time_since(strtotime($item['pubdate'])) . " ago"
93        ."</li>\n";
94    }
95    echo "</ul>\n";
96}
97
98/*
99Plugin Name: Dunstan's Time Since
100Plugin URI: http://binarybonsai.com/archives/2004/08/17/time-since-plugin/
101Description: Tells the time between the entry being posted and the comment being made.
102Author: Michael Heilemann & Dunstan Orchard
103Author URI: http://binarybonsai.com
104Version: 1.0
105*/
106function time_since($older_date, $newer_date = false) {
107    // array of time period chunks
108    $chunks = array(
109                  array(60 * 60 * 24 * 365 , 'year'),
110                  array(60 * 60 * 24 * 30 , 'month'),
111                  array(60 * 60 * 24 * 7, 'week'),
112                  array(60 * 60 * 24 , 'day'),
113                  array(60 * 60 , 'hour'),
114                  array(60 , 'minute'),
115              );
116
117    // $newer_date will equal false if we want to know the time elapsed between a date and the current time
118    // $newer_date will have a value if we want to work out time elapsed between two known dates
119    $newer_date = ($newer_date == false) ? (time()) : $newer_date;
120
121    // difference in seconds
122    $since = $newer_date - $older_date;
123
124    // we only want to output two chunks of time here, eg:
125    // x years, xx months
126    // x days, xx hours
127    // so there's only two bits of calculation below:
128
129    // step one: the first chunk
130    for ($i = 0, $j = count($chunks); $i < $j; $i++) {
131        $seconds = $chunks[$i][0];
132        $name = $chunks[$i][1];
133
134        // finding the biggest chunk (if the chunk fits, break)
135        if (($count = floor($since / $seconds)) != 0) {
136            break;
137        }
138    }
139
140    // set output var
141    $output = ($count == 1) ? '1 '.$name : "$count {$name}s";
142
143    // step two: the second chunk
144    if ($i + 1 < $j) {
145        $seconds2 = $chunks[$i + 1][0];
146        $name2 = $chunks[$i + 1][1];
147
148        if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) {
149            // add to output var
150            $output .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";
151        }
152    }
153
154    return $output;
155}
156?>
Note: See TracBrowser for help on using the browser.