Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

php-atom-lib update (total change)

  • Loading branch information...
commit 676593854bf70ff0da297fe615528e3d00447c10 1 parent f1b1562
Eko Gunawan authored
View
32 ActivityExtension/ActivityActorExtension_obsoleted.php
@@ -0,0 +1,32 @@
+<?php
+
+require_once 'StructuredActivityExtension.php';
+
+class ActivityActorExtension_obsoleted extends StructuredActivityExtension {
+
+ protected $_objectType;
+
+ public function addObjectType() {
+ $newObjectType = $this->_addElement(ActivityNS::NAMESPACE, ActivityNS::OBJECT_TYPE_ELEMENT);
+ return $this->_objectType[] = new ActivityObjectTypeExtension($newObjectType);
+ }
+
+ public function getObjectType() {
+ return $this->_objectType;
+ }
+
+ public function __construct($data) {
+ parent::__construct($data, AtomNS::AUTHOR_ELEMENT);
+
+ $this->_init();
+ }
+
+ protected function _init() {
+ $this->_objectType = array();
+ if (isset($this->_element[ActivityNS::OBJECT_TYPE_ELEMENT])) {
+ foreach ($this->_element[ActivityNS::OBJECT_TYPE_ELEMENT] as $objectType) {
+ $this->_objectType[] = new SimpleActivityExtension($objectType, ActivityNS::OBJECT_TYPE_ELEMENT);
+ }
+ }
+ }
+}
View
85 ActivityExtension/ActivityEntryExtension.php
@@ -0,0 +1,85 @@
+<?php
+
+require_once 'SimpleActivityExtension.php';
+require_once 'ActivityObjectExtension.php';
+require_once 'StructuredActivityExtension.php';
+
+class ActivityEntryExtension extends StructuredActivityExtension {
+
+ protected $_generator;
+ protected $_object;
+ protected $_target;
+ protected $_verb;
+
+ public function addObject() {
+ $newObject = $this->_addElement(ActivityNS::NAMESPACE, ActivityNS::OBJECT_ELEMENT, null);
+ return $this->_object[] = new ActivityObjectExtension($newObject, ActivityNS::OBJECT_ELEMENT);
+ }
+
+ public function addTarget() {
+ $newTarget = $this->_addElement(ActivityNS::NAMESPACE, ActivityNS::TARGET_ELEMENT, null);
+ return $this->_target[] = new ActivityObjectExtension($newTarget, ActivityNS::TARGET_ELEMENT);
+ }
+
+ public function addVerb() {
+ $newVerb = $this->_addElement(ActivityNS::NAMESPACE, ActivityNS::VERB_ELEMENT, null);
+ return $this->_verb[] = new SimpleActivityExtension($newVerb, ActivityNS::VERB_ELEMENT);
+ }
+
+ public function getGenerator() {
+ return $this->_generator;
+ }
+
+ public function getObject() {
+ return $this->_object;
+ }
+
+ public function getTarget() {
+ return $this->_target;
+ }
+
+ public function getVerb() {
+ return $this->_verb;
+ }
+
+ public function setGenerator($value) {
+ if (!isset($this->_generator)) {
+ $generator = $this->_addElement(AtomNS::NAMESPACE, AtomNS::GENERATOR_ELEMENT, $value);
+ $this->_generator = new AtomGeneratorAdapter($generator);
+ return;
+ }
+ $this->_generator->value = $value;
+ }
+
+ public function __construct($data) {
+ parent::__construct($data, AtomNS::ENTRY_ELEMENT);
+ $this->_init();
+ }
+
+ protected function _init() {
+
+ $this->_object = array();
+ if (isset($this->_element[ActivityNS::OBJECT_ELEMENT])) {
+ foreach ($this->_element[ActivityNS::OBJECT_ELEMENT] as $object) {
+ $this->_object[] = new ActivityObjectExtension($object, ActivityNS::OBJECT_ELEMENT);
+ }
+ }
+ $this->_target = array();
+ if (isset($this->_element[ActivityNS::TARGET_ELEMENT])) {
+ foreach ($this->_element[ActivityNS::TARGET_ELEMENT] as $target) {
+ $this->_target[] = new ActivityObjectExtension($target, ActivityNS::TARGET_ELEMENT);
+ }
+ }
+
+ $this->_verb = array();
+ if (isset($this->_element[ActivityNS::VERB_ELEMENT])) {
+ foreach ($this->_element[ActivityNS::VERB_ELEMENT] as $verb) {
+ $this->_verb[] = new SimpleActivityExtension($verb, ActivityNS::VERB_ELEMENT);
+ }
+ }
+
+ if (isset($this->_element[AtomNS::GENERATOR_ELEMENT][0])) {
+ $this->_generator = new AtomGeneratorAdapter($this->_element[AtomNS::GENERATOR_ELEMENT][0]);
+ }
+ }
+}
View
33 ActivityExtension/ActivityExtensionFactory.php
@@ -0,0 +1,33 @@
+<?php
+require_once 'ActivityEntryExtension.php';
+require_once 'ActivityObjectExtension.php';
+require_once 'ActivityNS.php';
+
+
+class ActivityExtensionException extends Exception { }
+
+class ActivityExtensionFactory implements IAtomExtensionFactory {
+
+ public function adapt(SimpleXMLElement $atomNode) {
+ switch ($atomNode->getName()) {
+ case AtomNS::ENTRY_ELEMENT:
+ return new ActivityEntryExtension($atomNode);
+ break;
+// case ActivityNS::OBJECT_TYPE_ELEMENT:
+// return new SimpleActivityExtension($atomNode, ActivityNS::OBJECT_TYPE_ELEMENT);
+// break;
+// case ActivityNS::OBJECT_ELEMENT:
+// return new ActivityObjectExtension($atomNode, ActivityNS::OBJECT_ELEMENT);
+// break;
+ case AtomNS::AUTHOR_ELEMENT:
+ return new ActivityObjectExtension($atomNode, AtomNS::AUTHOR_ELEMENT);
+ break;
+ default:
+ throw new ExtensionFactoryException('No Adaptor Available for '.$atomNode->getName().' element!');
+ }
+ }
+
+ public function getNamespace() {
+ return ActivityNS::NAMESPACE;
+ }
+}
View
42 ActivityExtension/ActivityNS.php
@@ -0,0 +1,42 @@
+<?php
+
+
+class ActivityNS {
+ const NAMESPACE = 'http://activitystrea.ms/spec/1.0/';
+
+ const VERB_ELEMENT = 'verb';
+ const OBJECT_ELEMENT = 'object';
+ const OBJECT_TYPE_ELEMENT = 'object-type';
+ const TARGET_ELEMENT = 'target';
+
+ const FAVORITE_VERB = 'http://activitystrea.ms/schema/1.0/favorite';
+ const FOLLOWING_VERB = 'http://activitystrea.ms/schema/1.0/follow';
+ const LIKE_VERB = 'http://activitystrea.ms/schema/1.0/like';
+ const MAKE_FRIEND_VERB = 'http://activitystrea.ms/schema/1.0/make-friend';
+ const JOIN_VERB = 'http://activitystrea.ms/schema/1.0/join';
+ const PLAY_VERB = 'http://activitystrea.ms/schema/1.0/play';
+ const POST_VERB = 'http://activitystrea.ms/schema/1.0/post';
+ const SAVE_VERB = 'http://activitystrea.ms/schema/1.0/save';
+ const SHARE_VERB = 'http://activitystrea.ms/schema/1.0/share';
+ const TAG_VERB = 'http://activitystrea.ms/schema/1.0/tag';
+ const UPDATE_VERB = 'http://activitystrea.ms/schema/1.0/update';
+
+ const ARTICLE_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/article';
+ const AUDIO_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/audio';
+ const BOOKMARK_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/bookmark';
+ const COMMENT_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/comment';
+ const FILE_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/file';
+ const FOLDER_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/folder.';
+ const GROUP_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/group';
+ const LIST_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/list';
+ const NOTE_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/note';
+ const PERSON_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/person';
+ const PHOTO_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/photo';
+ const PHOTO_ALBUM_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/photo-album';
+ const PLACE_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/place';
+ const PLAYLIST_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/product';
+ const PRODUCT_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/review';
+ const REVIEW_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/service';
+ const STATUS_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/status';
+ const VIDEO_OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/video';
+}
View
47 ActivityExtension/ActivityObjectExtension.php
@@ -0,0 +1,47 @@
+<?php
+
+require_once 'SimpleActivityExtension.php';
+
+class ActivityObjectExtension extends AtomEntryAdapter {
+
+ protected $_objectType;
+
+ public function addObjectType() {
+ $newObjectType = $this->_addElement(ActivityNS::NAMESPACE, ActivityNS::OBJECT_TYPE_ELEMENT);
+ return $this->_objectType[] = new SimpleActivityExtension($newObjectType, ActivityNS::OBJECT_TYPE_ELEMENT);
+ }
+
+ public function getObjectType() {
+ return $this->_objectType;
+ }
+
+ public function __construct(SimpleXMLElement $data, $extensionType) {
+
+ $this->_atomNode = $data;
+
+ if ($this->_atomNode->getName() != $extensionType) {
+ throw new ActivityExtensionException("Invalid XML Object");
+ }
+
+ $this->_prefix = $this->_getPrefix(ActivityNS::NAMESPACE);
+ if ($this->_prefix === null) {
+ $this->_prefix = 'activity';
+ }
+
+ $this->_fetchChilds(AtomNS::NAMESPACE);
+ $this->_fetchChilds(ActivityNS::NAMESPACE);
+
+ $this->_init();
+ }
+
+ protected function _init() {
+ parent::_init();
+
+ $this->_objectType = array();
+ if (isset($this->_element[ActivityNS::OBJECT_TYPE_ELEMENT])) {
+ foreach ($this->_element[ActivityNS::OBJECT_TYPE_ELEMENT] as $objectType) {
+ $this->_objectType[] = new SimpleActivityExtension($objectType, ActivityNS::OBJECT_TYPE_ELEMENT);
+ }
+ }
+ }
+}
View
18 ActivityExtension/SimpleActivityExtension.php
@@ -0,0 +1,18 @@
+<?php
+
+class SimpleActivityExtension extends SimpleAtomAdapter {
+
+ public function __construct(SimpleXMLElement $data, $extensionType) {
+
+ $this->_atomNode = $data;
+
+ if ($this->_atomNode->getName() != $extensionType) { //check whether $this->_atomNode is the appropriate XML Object, e.g. atom entry node for ActivityEntryExtension
+ throw new ActivityExtensionException("Invalid XML Object");
+ }
+
+ $this->_prefix = $this->_getPrefix(ActivityNS::NAMESPACE);
+ if ($this->_prefix === null) {
+ $this->_prefix = 'activity';
+ }
+ }
+}
View
21 ActivityExtension/StructuredActivityExtension.php
@@ -0,0 +1,21 @@
+<?php
+
+class StructuredActivityExtension extends ExtensibleAtomAdapter {
+
+ public function __construct(SimpleXMLElement $data, $extensionType) {
+
+ $this->_atomNode = $data;
+
+ if ($this->_atomNode->getName() != $extensionType) { //check whether $this->_atomNode is the appropriate XML Object, e.g. atom entry node for ActivityEntryExtension
+ throw new ActivityExtensionException("Invalid XML Object");
+ }
+
+ $this->_prefix = $this->_getPrefix(ActivityNS::NAMESPACE);
+ if ($this->_prefix === null) {
+ $this->_prefix = 'activity';
+ }
+
+ $this->_fetchChilds(AtomNS::NAMESPACE);
+ $this->_fetchChilds(ActivityNS::NAMESPACE);
+ }
+}
View
8 AtomAdapterBasic.php
@@ -0,0 +1,8 @@
+<?php
+
+class ExtensionFactoryException extends Exception { }
+
+interface IAtomExtensionFactory {
+ public function adapt(SimpleXMLElement $domObj);
+ public function getNamespace();
+}
View
34 AtomCategoryAdapter.php
@@ -0,0 +1,34 @@
+<?php
+
+require_once 'StandardAtomAdapter.php';
+
+class AtomCategoryAdapter extends StandardAtomAdapter {
+
+ public function getLabel() {
+ return $this->_getAttribute(AtomNS::LABEL_ATTRIBUTE);
+ }
+
+ public function getScheme() {
+ return $this->_getAttribute(AtomNS::SCHEME_ATTRIBUTE);
+ }
+
+ public function getTerm() {
+ return $this->_getAttribute(AtomNS::TERM_ATTRIBUTE);
+ }
+
+ public function setLabel($value) {
+ $this->_setAttribute(AtomNS::LABEL_ATTRIBUTE, $value);
+ }
+
+ public function setScheme($value) {
+ $this->_setAttribute(AtomNS::SCHEME_ATTRIBUTE, $value);
+ }
+
+ public function setTerm($value) {
+ $this->_setAttribute(AtomNS::TERM_ATTRIBUTE, $value);
+ }
+
+ public function __construct($data, $data_is_url=false) {
+ parent::__construct(AtomNS::CATEGORY_ELEMENT, $data, $data_is_url);
+ }
+}
View
18 AtomContentAdapter.php
@@ -0,0 +1,18 @@
+<?php
+
+require_once 'AtomTextConstructAdapter.php';
+
+class AtomContentAdapter extends AtomTextConstructAdapter {
+
+ public function __construct($data, $data_is_url=false) {
+ parent::__construct(AtomNS::CONTENT_ELEMENT, $data, $data_is_url);
+ }
+
+ public function getSrc() {
+ return $this->_getAttribute(AtomNS::SRC_ATTRIBUTE);
+ }
+
+ public function setSrc($value) {
+ $this->_setAttribute(AtomNS::SRC_ATTRIBUTE, $value);
+ }
+}
View
26 AtomGeneratorAdapter.php
@@ -0,0 +1,26 @@
+<?php
+
+require_once 'StandardAtomAdapter.php';
+
+class AtomGeneratorAdapter extends StandardAtomAdapter {
+
+ public function getUri() {
+ return $this->_getAttribute(AtomNS::URI_ATTRIBUTE);
+ }
+
+ public function getVersion() {
+ return $this->_getAttribute(AtomNS::VERSION_ATTRIBUTE);
+ }
+
+ public function setUri($value) {
+ $this->_setAttribute(AtomNS::URI_ATTRIBUTE, $value);
+ }
+
+ public function setVersion($value) {
+ $this->_setAttribute(AtomNS::VERSION_ATTRIBUTE, $value);
+ }
+
+ public function __construct($data, $data_is_url=false) {
+ parent::__construct(AtomNS::GENERATOR_ELEMENT, $data, $data_is_url);
+ }
+}
View
36 AtomNS.php
@@ -0,0 +1,36 @@
+<?php
+
+class AtomNS {
+ const NAMESPACE = 'http://www.w3.org/2005/Atom';
+
+ const FEED_ELEMENT = 'feed';
+ const ENTRY_ELEMENT = 'entry';
+ const ID_ELEMENT = 'id';
+ const TITLE_ELEMENT = 'title';
+ const AUTHOR_ELEMENT = 'author';
+ const LINK_ELEMENT = 'link';
+ const UPDATED_ELEMENT = 'updated';
+ const PUBLISHED_ELEMENT = 'published';
+ const NAME_ELEMENT = 'name';
+ const URI_ELEMENT = 'uri';
+ const EMAIL_ELEMENT = 'email';
+ const CONTENT_ELEMENT = 'content';
+ const CATEGORY_ELEMENT = 'category';
+ const SUMMARY_ELEMENT = 'summary';
+ const GENERATOR_ELEMENT = 'generator';
+
+ const BASE_ATTRIBUTE = 'base';
+ const LANG_ATTRIBUTE = 'lang';
+ const TYPE_ATTRIBUTE = 'type';
+ const HREF_ATTRIBUTE = 'href';
+ const HREFLANG_ATTRIBUTE = 'hreflang';
+ const REL_ATTRIBUTE = 'rel';
+ const LENGTH_ATTRIBUTE = 'length';
+ const TITLE_ATTRIBUTE = 'title';
+ const SRC_ATTRIBUTE = 'src';
+ const TERM_ATTRIBUTE = 'term';
+ const SCHEME_ATTRIBUTE = 'scheme';
+ const LABEL_ATTRIBUTE = 'label';
+ const URI_ATTRIBUTE = 'uri';
+ const VERSION_ATTRIBUTE = 'version';
+}
View
125 AtomSourceAdapter.php
@@ -0,0 +1,125 @@
+<?php
+
+require_once 'ExtensibleAtomAdapter.php';
+require_once 'SimpleAtomAdapter.php';
+require_once 'AtomTextConstructAdapter.php';
+require_once 'AtomLinkAdapter.php';
+require_once 'AtomPersonConstructAdapter.php';
+require_once 'AtomDateConstructAdapter.php';
+require_once 'AtomCategoryAdapter.php';
+
+class AtomSourceAdapter extends ExtensibleAtomAdapter {
+ protected $_author;
+ protected $_category;
+ protected $_id;
+ protected $_link;
+ protected $_title;
+ protected $_updated;
+
+ public function addAuthor() {
+ $newAuthor = $this->_addElement(AtomNS::NAMESPACE, AtomNS::AUTHOR_ELEMENT);
+ return $this->_author[] = new AtomPersonConstructAdapter(AtomNS::AUTHOR_ELEMENT, $newAuthor);
+ }
+
+ public function addCategory() {
+ $newCategory = $this->_addElement(AtomNS::NAMESPACE, AtomNS::CATEGORY_ELEMENT);
+ return $this->_category[] = new AtomCategoryAdapter($newCategory);
+ }
+
+ public function addLink() {
+ $newLink = $this->_addElement(AtomNS::NAMESPACE, AtomNS::LINK_ELEMENT);
+ return $this->_link[] = new AtomLinkAdapter($newLink);
+ }
+
+ public function getAuthor() {
+ return $this->_author;
+ }
+
+ public function getCategory() {
+ return $this->_category;
+ }
+
+ public function getId() {
+ return $this->_id;
+ }
+
+ public function getLink() {
+ return $this->_link;
+ }
+
+ public function getTitle() {
+ return $this->_title;
+ }
+
+ public function getUpdated() {
+ return $this->_updated;
+ }
+
+ public function setId($value) {
+ if (!isset($this->_id)) {
+ $id = $this->_addElement(AtomNS::NAMESPACE, AtomNS::ID_ELEMENT, $value);
+ $this->_id = new SimpleAtomAdapter(AtomNS::ID_ELEMENT, $id);
+ return;
+ }
+ $this->_id->value = $value;
+ }
+
+ public function setTitle($value) {
+ if (!isset($this->_title)) {
+ $title = $this->_addElement(AtomNS::NAMESPACE, AtomNS::TITLE_ELEMENT, $value);
+ $this->_title = new AtomTextConstructAdapter(AtomNS::TITLE_ELEMENT, $title);
+ return;
+ }
+ $this->_title->value = $value;
+ }
+
+ public function setUpdated($value) {
+ if (!isset($this->_updated)) {
+ $updated = $this->_addElement(AtomNS::NAMESPACE, AtomNS::UPDATED_ELEMENT, $value);
+ $this->_updated = new AtomDateConstructAdapter(AtomNS::UPDATED_ELEMENT, $updated);
+ return;
+ }
+ $this->_updated->value = $value;
+ }
+
+ public function __construct($adapterType, $data, $data_is_url=false) {
+ parent::__construct($adapterType, $data, $data_is_url);
+ $this->_init();
+ }
+
+ protected function _init() {
+
+ if (isset($this->_element[AtomNS::TITLE_ELEMENT][0])) {
+ $this->_title = new AtomTextConstructAdapter(AtomNS::TITLE_ELEMENT, $this->_element[AtomNS::TITLE_ELEMENT][0]);
+ }
+
+ if (isset($this->_element[AtomNS::ID_ELEMENT][0])) {
+ $this->_id = new SimpleAtomAdapter(AtomNS::ID_ELEMENT, $this->_element[AtomNS::ID_ELEMENT][0]);
+ }
+
+ $this->_link = array();
+ if (isset($this->_element[AtomNS::LINK_ELEMENT])) {
+ foreach ($this->_element[AtomNS::LINK_ELEMENT] as $link) {
+ $this->_link[] = new AtomLinkAdapter($link);
+ }
+ }
+
+ $this->_category = array();
+ if (isset($this->_element[AtomNS::CATEGORY_ELEMENT])) {
+ foreach ($this->_element[AtomNS::CATEGORY_ELEMENT] as $category) {
+ $this->_category[] = new AtomCategoryAdapter($category);
+ }
+ }
+
+ $this->_author = array();
+ if (isset($this->_element[AtomNS::AUTHOR_ELEMENT])) {
+ foreach ($this->_element[AtomNS::AUTHOR_ELEMENT] as $author) {
+ $this->_author[] = new AtomPersonConstructAdapter(AtomNS::AUTHOR_ELEMENT, $author);
+ }
+ }
+
+ if (isset($this->_element[AtomNS::UPDATED_ELEMENT][0])) {
+ $this->_updated = new AtomDateConstructAdapter(AtomNS::UPDATED_ELEMENT,$this->_element[AtomNS::UPDATED_ELEMENT][0]);
+ }
+ }
+}
View
40 ExtensibleAtomAdapter.php
@@ -0,0 +1,40 @@
+<?php
+
+require_once 'BaseAtomAdapter.php';
+require_once 'AtomExtensionManager.php';
+
+class ExtensibleAtomAdapter extends BaseAtomAdapter { //I think I have to add setElement method
+
+ protected $_element;
+
+ public function addNamespace($prefix, $namespace) {
+ $this->_atomNode->addAttribute($prefix.':temp',null,$namespace);
+ unset($this->_atomNode->attributes($namespace)->temp);
+ }
+
+ public function getExtension($namespace) {
+ return AtomExtensionManager::getInstance()->getExtensionAdapter($this->_atomNode, $namespace);
+ }
+
+ public function __construct($adapterType, $data, $data_is_url=false) {
+ parent::__construct($adapterType, $data, $data_is_url);
+
+ $this->_fetchChilds(AtomNS::NAMESPACE);
+ }
+
+ protected function _addElement($namespace, $tagName, $value=null) {
+ $prefix = "";
+ $ns = null;
+ if ($this->_prefix != "") {
+ $prefix = $this->_prefix.":";
+ $ns = $namespace;
+ }
+ return $this->_atomNode->addChild($prefix.$tagName, $value, $ns);
+ }
+
+ protected function _fetchChilds($namespace) {
+ foreach($this->_atomNode->children($namespace) as $children) {
+ $this->_element[$children->getName()][] = $children;
+ }
+ }
+}
View
14 SimpleAtomAdapter.php
@@ -0,0 +1,14 @@
+<?php
+
+require_once 'BaseAtomAdapter.php'; //may be the getter method of object of this class can directly go to getContent()
+
+class SimpleAtomAdapter extends BaseAtomAdapter {
+
+ public function getValue() { // I'll handle the HTML and XHTML type for text and content construct later
+ return trim((string)$this->_atomNode);
+ }
+
+ public function setValue($value) { // I'll handle the HTML and XHTML type for text and content construct later
+ $this->_atomNode[0] = $value;
+ }
+}
View
22 StandardAtomAdapter.php
@@ -0,0 +1,22 @@
+<?php
+
+require_once 'SimpleAtomAdapter.php';
+
+class StandardAtomAdapter extends SimpleAtomAdapter {
+
+ protected function _getAttribute($attribute, $namespace=null) {
+ return (string)$this->_atomNode->attributes($namespace)->$attribute;
+ }
+
+ protected function _setAttribute($attribute, $value, $namespace=null) {
+ if ($value !== null)
+ {
+ if (!isset($this->_atomNode->attributes($namespace)->$attribute)) {
+ $this->_atomNode->addAttribute($attribute, $value, $namespace);
+ return;
+ }
+
+ $this->_atomNode->attributes($namespace)->$attribute = $value;
+ }
+ }
+}
View
18 ThreadingExtension/SimpleThreadingExtension.php
@@ -0,0 +1,18 @@
+<?php
+
+class SimpleThreadingExtension extends StandardAtomAdapter {
+
+ public function __construct(SimpleXMLElement $data, $extensionType) {
+
+ $this->_atomNode = $data;
+
+ if ($this->_atomNode->getName() != $extensionType) { //check whether $this->_atomNode is the appropriate XML Object, e.g. atom entry node for ActivityEntryExtension
+ throw new ThreadingExtensionException("Invalid XML Object");
+ }
+
+ $this->_prefix = $this->_getPrefix(ThreadingNS::NAMESPACE);
+ if ($this->_prefix === null) {
+ $this->_prefix = 'thr';
+ }
+ }
+}
View
20 ThreadingExtension/StructuredThreadingExtension.php
@@ -0,0 +1,20 @@
+<?php
+
+class StructuredThreadingExtension extends ExtensibleAtomAdapter {
+
+ public function __construct(SimpleXMLElement $data, $extensionType) {
+
+ $this->_atomNode = $data;
+
+ if ($this->_atomNode->getName() != $extensionType) { //check whether $this->_atomNode is the appropriate XML Object, e.g. atom entry node for ActivityEntryExtension
+ throw new ThreadingExtensionException("Invalid XML Object");
+ }
+
+ $this->_prefix = $this->_getPrefix(ThreadingNS::NAMESPACE);
+ if ($this->_prefix === null) {
+ $this->_prefix = 'thr';
+ }
+
+ $this->_fetchChilds(ThreadingNS::NAMESPACE);
+ }
+}
View
36 ThreadingExtension/ThreadingEntryExtension.php
@@ -0,0 +1,36 @@
+<?php
+
+require_once 'ThreadingInReplyToExtension.php';
+require_once 'StructuredThreadingExtension.php';
+
+class ThreadingEntryExtension extends StructuredThreadingExtension {
+
+ protected $_inReplyTo;
+
+ public function getInReplyTo() {
+ return $this->_inReplyTo;
+ }
+
+ public function setInReplyTo($ref=null, $href=null, $source=null, $type=null) {
+ if (!isset($this->_inReplyTo)) {
+ $inReplyTo = $this->_addElement(ThreadingNS::NAMESPACE, ThreadingNS::IN_REPLY_TO_ELEMENT);
+ $this->_inReplyTo = new ThreadingInReplyToExtension($inReplyTo);
+ }
+ $this->_inReplyTo->ref = $ref;
+ $this->_inReplyTo->href = $href;
+ $this->_inReplyTo->source = $source;
+ $this->_inReplyTo->type = $type;
+ }
+
+ public function __construct($data) {
+ parent::__construct($data, AtomNS::ENTRY_ELEMENT);
+ $this->_init();
+ }
+
+ protected function _init() {
+
+ if (isset($this->_element[ThreadingNS::IN_REPLY_TO_ELEMENT][0])) {
+ $this->_inReplyTo = new ThreadingInReplyToExtension($this->_element[ThreadingNS::IN_REPLY_TO_ELEMENT][0]);
+ }
+ }
+}
View
22 ThreadingExtension/ThreadingExtensionFactory.php
@@ -0,0 +1,22 @@
+<?php
+require_once 'ThreadingNS.php';
+require_once 'ThreadingEntryExtension.php';
+
+class ThreadingExtensionException extends Exception { }
+
+class ThreadingExtensionFactory implements IAtomExtensionFactory {
+
+ public function adapt(SimpleXMLElement $atomNode) {
+ switch ($atomNode->getName()) {
+ case AtomNS::ENTRY_ELEMENT:
+ return new ThreadingEntryExtension($atomNode);
+ break;
+ default:
+ throw new ExtensionFactoryException('No Adaptor Available for '.$atomNode->getName().' element!');
+ }
+ }
+
+ public function getNamespace() {
+ return ThreadingNS::NAMESPACE;
+ }
+}
View
42 ThreadingExtension/ThreadingInReplyToExtension.php
@@ -0,0 +1,42 @@
+<?php
+
+require_once 'SimpleThreadingExtension.php';
+
+class ThreadingInReplyToExtension extends SimpleThreadingExtension {
+
+ public function getHref() {
+ return $this->_getAttribute(ThreadingNS::HREF_ATTRIBUTE);
+ }
+
+ public function getRef() {
+ return $this->_getAttribute(ThreadingNS::REF_ATTRIBUTE);
+ }
+
+ public function getSource() {
+ return $this->_getAttribute(ThreadingNS::SOURCE_ATTRIBUTE);
+ }
+
+ public function getType() {
+ return $this->_getAttribute(ThreadingNS::TYPE_ATTRIBUTE);
+ }
+
+ public function setRef($value) {
+ $this->_setAttribute(ThreadingNS::REF_ATTRIBUTE, $value);
+ }
+
+ public function setHref($value) {
+ $this->_setAttribute(ThreadingNS::HREF_ATTRIBUTE, $value);
+ }
+
+ public function setSource($value) {
+ $this->_setAttribute(ThreadingNS::SOURCE_ATTRIBUTE, $value);
+ }
+
+ public function setType($value) {
+ $this->_setAttribute(ThreadingNS::TYPE_ATTRIBUTE, $value);
+ }
+
+ public function __construct(SimpleXMLElement $data) {
+ parent::__construct($data, ThreadingNS::IN_REPLY_TO_ELEMENT);
+ }
+}
View
13 ThreadingExtension/ThreadingNS.php
@@ -0,0 +1,13 @@
+<?php
+
+
+class ThreadingNS {
+ const NAMESPACE = 'http://purl.org/syndication/thread/1.0';
+
+ const IN_REPLY_TO_ELEMENT = 'in-reply-to';
+
+ const REF_ATTRIBUTE = 'ref';
+ const HREF_ATTRIBUTE = 'href';
+ const SOURCE_ATTRIBUTE = 'source';
+ const TYPE_ATTRIBUTE = 'type';
+}
Please sign in to comment.
Something went wrong with that request. Please try again.