atomcategory.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. if (!defined('STATUSNET')) {
  29. exit(1);
  30. }
  31. class AtomCategory
  32. {
  33. public $term;
  34. public $scheme;
  35. public $label;
  36. function __construct($element=null)
  37. {
  38. if ($element && $element->attributes) {
  39. $this->term = $this->extract($element, 'term');
  40. $this->scheme = $this->extract($element, 'scheme');
  41. $this->label = $this->extract($element, 'label');
  42. }
  43. }
  44. protected function extract($element, $attrib)
  45. {
  46. $node = $element->attributes->getNamedItemNS(Activity::ATOM, $attrib);
  47. if ($node) {
  48. return trim($node->textContent);
  49. }
  50. $node = $element->attributes->getNamedItem($attrib);
  51. if ($node) {
  52. return trim($node->textContent);
  53. }
  54. return null;
  55. }
  56. function asString()
  57. {
  58. $xs = new XMLStringer();
  59. $this->outputTo($xs);
  60. return $xs->getString();
  61. }
  62. function outputTo($xo)
  63. {
  64. $attribs = array();
  65. if ($this->term !== null) {
  66. $attribs['term'] = $this->term;
  67. }
  68. if ($this->scheme !== null) {
  69. $attribs['scheme'] = $this->scheme;
  70. }
  71. if ($this->label !== null) {
  72. $attribs['label'] = $this->label;
  73. }
  74. $xo->element('category', $attribs);
  75. }
  76. }