]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/atomcategory.php
Opps, PEAR sucks. Need to call find() before fetch() ... :-(
[quix0rs-gnu-social.git] / lib / atomcategory.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * PHP version 5
6  *
7  * LICENCE: This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  * @category  Feed
21  * @package   StatusNet
22  * @author    Evan Prodromou <evan@status.net>
23  * @author    Zach Copley <zach@status.net>
24  * @copyright 2010 StatusNet, Inc.
25  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
26  * @link      http://status.net/
27  */
28
29 if (!defined('STATUSNET')) {
30     exit(1);
31 }
32
33 class AtomCategory
34 {
35     public $term;
36     public $scheme;
37     public $label;
38
39     function __construct($element=null)
40     {
41         if ($element && $element->attributes) {
42             $this->term = $this->extract($element, 'term');
43             $this->scheme = $this->extract($element, 'scheme');
44             $this->label = $this->extract($element, 'label');
45         }
46     }
47
48     protected function extract($element, $attrib)
49     {
50         $node = $element->attributes->getNamedItemNS(Activity::ATOM, $attrib);
51         if ($node) {
52             return trim($node->textContent);
53         }
54         $node = $element->attributes->getNamedItem($attrib);
55         if ($node) {
56             return trim($node->textContent);
57         }
58         return null;
59     }
60
61     function asString()
62     {
63         $xs = new XMLStringer();
64         $this->outputTo($xs);
65         return $xs->getString();
66     }
67
68     function outputTo($xo)
69     {
70         $attribs = array();
71         if ($this->term !== null) {
72             $attribs['term'] = $this->term;
73         }
74         if ($this->scheme !== null) {
75             $attribs['scheme'] = $this->scheme;
76         }
77         if ($this->label !== null) {
78             $attribs['label'] = $this->label;
79         }
80         $xo->element('category', $attribs);
81     }
82 }