]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/atomnoticefeed.php
Merge branch 'master' of gitorious.org:statusnet/mainline
[quix0rs-gnu-social.git] / lib / atomnoticefeed.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Class for building an Atom feed from a collection of notices
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Feed
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2010 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET'))
31 {
32     exit(1);
33 }
34
35 /**
36  * Class for creating a feed that represents a collection of notices. Builds the
37  * feed in memory. Get the feed as a string with AtomNoticeFeed::getString().
38  *
39  * @category Feed
40  * @package  StatusNet
41  * @author   Zach Copley <zach@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43  * @link     http://status.net/
44  */
45 class AtomNoticeFeed extends Atom10Feed
46 {
47     function __construct($indent = true) {
48         parent::__construct($indent);
49
50         // Feeds containing notice info use these namespaces
51
52         $this->addNamespace(
53             'thr',
54             'http://purl.org/syndication/thread/1.0'
55         );
56
57         $this->addNamespace(
58             'georss',
59             'http://www.georss.org/georss'
60         );
61
62         $this->addNamespace(
63             'activity',
64             'http://activitystrea.ms/spec/1.0/'
65         );
66
67         $this->addNamespace(
68             'media',
69             'http://purl.org/syndication/atommedia'
70         );
71
72         $this->addNamespace(
73             'poco',
74             'http://portablecontacts.net/spec/1.0'
75         );
76
77         // XXX: What should the uri be?
78         $this->addNamespace(
79             'ostatus',
80             'http://ostatus.org/schema/1.0'
81         );
82
83         $this->addNamespace(
84             'statusnet',
85             'http://status.net/ont/'
86         );
87     }
88
89     /**
90      * Add more than one Notice to the feed
91      *
92      * @param mixed $notices an array of Notice objects or handle
93      *
94      */
95     function addEntryFromNotices($notices)
96     {
97         if (is_array($notices)) {
98             foreach ($notices as $notice) {
99                 $this->addEntryFromNotice($notice);
100             }
101         } else {
102             while ($notices->fetch()) {
103                 $this->addEntryFromNotice($notices);
104             }
105         }
106     }
107
108     /**
109      * Add a single Notice to the feed
110      *
111      * @param Notice $notice a Notice to add
112      */
113     function addEntryFromNotice($notice)
114     {
115         $source = $this->showSource();
116         $author = $this->showAuthor();
117
118         $cur = common_current_user();
119
120         $this->addEntryRaw($notice->asAtomEntry(false, $source, $author, $cur));
121     }
122
123     function showSource()
124     {
125         return true;
126     }
127
128     function showAuthor()
129     {
130         return true;
131     }
132 }