PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/package_J15/files/blogger.php

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