Permalink
Browse files

php-atom-lib update (total change)

  • Loading branch information...
1 parent f1b1562 commit 676593854bf70ff0da297fe615528e3d00447c10 Eko Gunawan committed Apr 19, 2010
@@ -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);
+ }
+ }
+ }
+}
@@ -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]);
+ }
+ }
+}
@@ -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;
+ }
+}
@@ -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';
+}
@@ -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);
+ }
+ }
+ }
+}
@@ -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';
+ }
+ }
+}
@@ -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
@@ -0,0 +1,8 @@
+<?php
+
+class ExtensionFactoryException extends Exception { }
+
+interface IAtomExtensionFactory {
+ public function adapt(SimpleXMLElement $domObj);
+ public function getNamespace();
+}
View
@@ -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
@@ -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
@@ -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);
+ }
+}
Oops, something went wrong.

0 comments on commit 6765938

Please sign in to comment.