PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/package_J10/files/blogger.php

http://jumi.googlecode.com/
PHP | 97 lines | 82 code | 9 blank | 6 comment | 10 complexity | 80bd9f1ceb55da894ad773f8155c8ddc MD5 | raw file
 1<?php
 2/**
 3* @version   $Id: blogger.php 75 2009-01-11 11:33:17Z edo888 $
 4* @package   Jumi
 5* @copyright Copyright (C) 2008 Edvard Ananyan. All rights reserved.
 6* @license   GNU/GPL, see LICENSE.php
 7*/
 8
 9defined("_VALID_MOS") or die("Restricted access");
10
11$blogId    = isset($blogId) ? $blogId : '1748567850225926498';
12$login     = isset($login) ? $login : 'joomla-jumi';
13$cacheTime = isset($cacheTime) ? (int)$cacheTime : 86400;
14
15$myBlog = new blog($blogId, $login, $cacheTime);
16$myBlog->printAllPosts();
17
18echo '<style type="text/css">
19.post {margin:0 0 1.5em;font-family:Verdana,sans-serif;color:#000000;}
20.post div {margin:0 0 .75em;line-height:1.3em;}
21.post img {padding:4px;border:1px solid #cccccc;}
22.post blockquote {margin:1em 20px;}
23.post blockquote p {margin:.75em 0;}
24.date-header {margin:1.5em 0 0;font-weight:normal;color:#999999;font-size:100%;}
25.post-title {margin:0;padding:0;font-size:110%;font-weight:bold;line-height:1.1em;}
26.post-title a, .post-title a:visited, .post-title strong {text-decoration:none;color:#333333;font-weight:bold;}
27.post-footer {color:#333333;font-size:87%;}
28.post-footer .span {margin-right:.3em;}
29</style>';
30
31class blog {
32    public $id;
33    public $login;
34    public $posts;
35    public $cacheTime;
36
37    function __construct($id, $login, $cacheTime) {
38        $this->id = $id;
39        $this->login = $login;
40        $this->cacheTime = $cacheTime;
41        $postsURL = 'http://www.blogger.com/feeds/'.$id.'/posts/default';
42        $fileName = 'cache/'.md5($postsURL);
43        if(file_exists($fileName) and time() - filemtime($fileName) < $this->cacheTime) {
44            $this->posts = simplexml_load_string(file_get_contents($fileName));
45        } else {
46            $feed = file_get_contents($postsURL);
47            if(strlen($feed) > 1000) {
48                file_put_contents($fileName, $feed);
49                $this->posts = simplexml_load_string($feed);
50            } else {
51                $this->posts = simplexml_load_string(file_get_contents($fileName));
52            }
53        }
54    }
55
56    public function printAllPosts() {
57        echo '<div class="blog-posts">';
58        $prev_date = '';
59        foreach ($this->posts->entry as $entry) {
60            for ($i = 0; $i < 5; $i++)
61                $entry->link[$i] = $entry->link[$i]->attributes();
62            if($prev_date != date('l, F j, Y', strtotime($entry->published))) {
63                echo '<h2 class="date-header">'.date('l, F j, Y', strtotime($entry->published)).'</h2>';
64                $prev_date = date('l, F j, Y', strtotime($entry->published));
65            }
66            echo '<div class="post">';
67            echo '<h3 class="post-title"><a href="'.$entry->link[0]['href'].'">'.$entry->title.'</a></h3>';
68            echo '<div class="post-header-line-1"></div>';
69            echo '<div class="post-body">'.$entry->content.'</div>';
70            echo '<div class="post-footer">';
71            echo '<div class="post-footer-line-1">';
72            echo '<span class="post-author">Posted by '.$entry->author->name.'</span> ';
73            echo '<span class="post-timestamp">at <a href="'.$entry->link[0]['href'].'">'.date('H:i', strtotime($entry->published)).'</a></span> ';
74            echo '<span class="post-comment-link"><a title="View or Add Comments" onclick="javascript:window.open(this.href,\'bloggerPopup\',\'toolbar=0,location=0,statusbar=1,menubar=0,scrollbars=yes,width=400,height=450\');return false;" href="'.str_replace('&', '&amp;', $entry->link[1]['href']).'" class="comment-link">'.$entry->link[1]['title'].'</a></span> ';
75            echo '</div>';
76            $labels = '';
77            if(isset($entry->category)) {
78                $labels = 'Labels: ';
79                for ($i = 0; isset($entry->category[$i]); $i++) {
80                    $entry->category[$i] = $entry->category[$i]->attributes();
81                    $labels .= '<a href="http://'.$this->login.'.blogspot.com/search/label/'.$entry->category[$i]['term'].'">'.$entry->category[$i]['term'].'</a>';
82                    if (isset($entry->category[$i+1]))
83                        $labels .= ', ';
84                }
85            }
86            echo '<div class="post-footer-line-2"><span class="post-labels">'.$labels.'</span></div>';
87            echo '</div>';
88            echo '</div>';
89        }
90        echo '</div>';
91        echo '<small>Last updated: '.date('j M, Y H:i', filemtime('cache/'.md5('http://www.blogger.com/feeds/'.$this->id.'/posts/default'))).'</small>';
92    }
93
94    public function printComments($postId) { echo ''; }
95
96    public function getPostId($id) {return substr($id, -19); }
97}