6 * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
9 function gpluspost_install() {
13 function gpluspost_uninstall() {
16 function gpluspost_module() {}
18 function gpluspost_init() {
23 if (isset($a->argv[1])) {
24 $uid = (int)$a->argv[1];
28 $contacts = q("SELECT `name` from contact where ID=%d LIMIT 1", intval($uid));
30 header("content-type: application/atom+xml");
31 echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
32 echo '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
33 echo "\t".'<title type="html"><![CDATA['.$a->config['sitename'].']]></title>'."\n";
34 echo "\t".'<subtitle type="html"><![CDATA['.$contacts[0]["name"]."]]></subtitle>\n";
35 echo "\t".'<link rel="self" href="'.$a->get_baseurl().'/gpluspost"/>'."\n";
36 echo "\t<id>".$a->get_baseurl()."/</id>\n";
37 echo "\t".'<link rel="alternate" type="text/html" href="'.$a->get_baseurl().'"/>'."\n";
38 echo "\t<updated>".date("c")."</updated>\n"; // To-Do
39 // <rights>Copyright ... </rights>
40 echo "\t".'<generator uri="'.$a->get_baseurl().'">'.$a->config['sitename'].'</generator>'."\n";
42 $pidlist = "262568,262567,269154,271508,270121,273721,314735,312616,311570,308771,308247,306100,295372,291096,290390,290389,283242,283060,280465,273725";
43 $pids = explode(",", $pidlist);
45 $items = q("SELECT `id` FROM `item` FORCE INDEX (`received`) WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `item`.`id` = `item`.`parent` ORDER BY `received` DESC LIMIT 50");
46 //foreach ($items AS $item)
47 // gpluspost_feeditem($item["id"]);
48 foreach ($pids AS $pid)
49 gpluspost_feeditem($pid);
55 function gpluspost_feeditem($pid) {
58 require_once('include/bbcode.php');
59 require_once("include/html2plain.php");
63 $items = q("SELECT `uri`, `plink`, `author-link`, `author-name`, `created`, `edited`, `id`, `title`, `body` from `item` WHERE id=%d", intval($pid));
64 foreach ($items AS $item) {
66 // extract the link from the body if there is exactly one link
68 // Looking for the first image
70 if(preg_match("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/is",$item['body'],$matches))
74 if(preg_match("/\[img\](.*?)\[\/img\]/is",$item['body'],$matches))
77 $multipleimages = (strpos($item['body'], "[img") != strrpos($item['body'], "[img"));
79 // When saved into the database the content is sent through htmlspecialchars
80 // That means that we have to decode all image-urls
81 $image = htmlspecialchars_decode($image);
84 // look for bookmark-bbcode and handle it with priority
85 if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$item['body'],$matches))
88 $multiplelinks = (strpos($item['body'], "[bookmark") != strrpos($item['body'], "[bookmark"));
90 $html = bbcode($item["body"], false, false);
91 $msg = trim(html2plain($html, 0, true));
93 // If there is no bookmark element then take the first link
95 $links = collecturls($html);
96 if (sizeof($links) > 0) {
98 $link = current($links);
100 $multiplelinks = (sizeof($links) > 1);
105 $msglink = $item["plink"];
106 else if ($link != "")
108 else if ($multipleimages)
109 $msglink = $item["plink"];
110 else if ($image != "")
113 //if (($msglink == "") and strlen($msg) > $max_char)
115 $msglink = $item["plink"];
117 $html = trim(str_replace($msglink, "", $html));
119 // Fetching the title - or the first line
120 if ($item["title"] != "")
121 $title = $item["title"];
123 $lines = explode("\n", $msg);
126 $title = str_replace("&", "&", $title);
127 //$html = str_replace("&", "&", $html);
129 echo "\t".'<entry xmlns="http://www.w3.org/2005/Atom">'."\n";
130 echo "\t\t".'<title type="html" xml:space="preserve"><![CDATA['.$title."]]></title>\n";
131 echo "\t\t".'<link rel="alternate" type="text/html" href="'.$msglink.'" />'."\n";
132 // <link rel="enclosure" type="audio/mpeg" length="1337" href="http://example.org/audio/ph34r_my_podcast.mp3"/>
133 echo "\t\t<id>".$item["uri"]."</id>\n";
134 //echo "\t\t<updated>".date("c", strtotime($item["edited"]))."</updated>\n";
135 //echo "\t\t<published>".date("c", strtotime($item["created"]))."</published>\n";
136 echo "\t\t<updated>".date("c")."</updated>\n";
137 echo "\t\t<published>".date("c")."</published>\n";
138 echo "\t\t<author>\n\t\t\t<name><![CDATA[".$item["author-name"]."]]></name>\n";
139 echo "\t\t\t<uri>".$item["author-link"]."</uri>\n\t\t</author>\n";
140 //echo '<content type="image/png" src="http://media.example.org/the_beach.png"/>';
141 echo "\t\t".'<content type="html" xml:space="preserve" xml:base="'.$item["plink"].'"><![CDATA['.$html."]]></content>\n";