From 9fe063022e08a4b6fa5f5935f8f185d5d95814a4 Mon Sep 17 00:00:00 2001 From: Sem Date: Wed, 25 Apr 2012 19:09:22 +0200 Subject: Upgraded to Elgg 1.8.4. --- engine/classes/ElggBatch.php | 75 +++++++++++++++++++++++--------- engine/classes/ElggEntity.php | 8 +++- engine/classes/ElggFileCache.php | 19 ++++++-- engine/classes/ElggGroup.php | 27 +++++++----- engine/classes/ElggObject.php | 27 +++++++----- engine/classes/ElggPluginManifest.php | 19 ++++++++ engine/classes/ElggSite.php | 28 ++++++++---- engine/classes/ElggUser.php | 35 +++++++++------ engine/classes/ElggWidget.php | 32 ++++++++++++-- engine/classes/XMLRPCArrayParameter.php | 56 ++++++++++++++++++++++++ engine/classes/XMLRPCBase64Parameter.php | 28 ++++++++++++ engine/classes/XMLRPCBoolParameter.php | 30 +++++++++++++ engine/classes/XMLRPCDateParameter.php | 33 ++++++++++++++ engine/classes/XMLRPCDoubleParameter.php | 29 ++++++++++++ engine/classes/XMLRPCErrorResponse.php | 36 +++++++++++++++ engine/classes/XMLRPCIntParameter.php | 29 ++++++++++++ engine/classes/XMLRPCParameter.php | 16 +++++++ engine/classes/XMLRPCResponse.php | 71 ++++++++++++++++++++++++++++++ engine/classes/XMLRPCStringParameter.php | 30 +++++++++++++ engine/classes/XMLRPCStructParameter.php | 55 +++++++++++++++++++++++ engine/classes/XMLRPCSuccessResponse.php | 22 ++++++++++ 21 files changed, 631 insertions(+), 74 deletions(-) create mode 100644 engine/classes/XMLRPCArrayParameter.php create mode 100644 engine/classes/XMLRPCBase64Parameter.php create mode 100644 engine/classes/XMLRPCBoolParameter.php create mode 100644 engine/classes/XMLRPCDateParameter.php create mode 100644 engine/classes/XMLRPCDoubleParameter.php create mode 100644 engine/classes/XMLRPCErrorResponse.php create mode 100644 engine/classes/XMLRPCIntParameter.php create mode 100644 engine/classes/XMLRPCParameter.php create mode 100644 engine/classes/XMLRPCResponse.php create mode 100644 engine/classes/XMLRPCStringParameter.php create mode 100644 engine/classes/XMLRPCStructParameter.php create mode 100644 engine/classes/XMLRPCSuccessResponse.php (limited to 'engine/classes') diff --git a/engine/classes/ElggBatch.php b/engine/classes/ElggBatch.php index 3d01133fa..0cb13eb32 100644 --- a/engine/classes/ElggBatch.php +++ b/engine/classes/ElggBatch.php @@ -3,47 +3,51 @@ * Efficiently run operations on batches of results for any function * that supports an options array. * - * This is usually used with elgg_get_entities() and friends, elgg_get_annotations() - * and elgg_get_metadata(). + * This is usually used with elgg_get_entities() and friends, + * elgg_get_annotations(), and elgg_get_metadata(). * - * If you pass a valid PHP callback, all results will be run through that callback. - * You can still foreach() through the result set after. Valid PHP callbacks - * can be a string, an array, or a closure. + * If you pass a valid PHP callback, all results will be run through that + * callback. You can still foreach() through the result set after. Valid + * PHP callbacks can be a string, an array, or a closure. * {@link http://php.net/manual/en/language.pseudo-types.php} * - * The callback function must accept 3 arguments: an entity, the getter used, and the options used. + * The callback function must accept 3 arguments: an entity, the getter + * used, and the options used. * - * Results from the callback are stored in callbackResult. - * If the callback returns only booleans, callbackResults will be the combined - * result of all calls. + * Results from the callback are stored in callbackResult. If the callback + * returns only booleans, callbackResults will be the combined result of + * all calls. * - * If the callback returns anything else, callbackresult will be an indexed array - * of whatever the callback returns. If returning error handling information, - * you should include enough information to determine which result you're referring - * to. + * If the callback returns anything else, callbackresult will be an indexed + * array of whatever the callback returns. If returning error handling + * information, you should include enough information to determine which + * result you're referring to. * * Don't combine returning bools and returning something else. * * Note that returning false will not stop the foreach. * + * @warning If your callback or foreach loop deletes or disable entities + * you MUST call setIncrementOffset(false) or set that when instantiating. + * This forces the offset to stay what it was in the $options array. + * * @example * + * // using foreach * $batch = new ElggBatch('elgg_get_entities', array()); + * $batch->setIncrementOffset(false); * * foreach ($batch as $entity) { * $entity->disable(); * } * + * // using both a callback * $callback = function($result, $getter, $options) { - * var_dump("Going to delete annotation id: $result->id"); + * var_dump("Looking at annotation id: $result->id"); * return true; * } * * $batch = new ElggBatch('elgg_get_annotations', array('guid' => 2), $callback); - * - * foreach ($batch as $annotation) { - * $annotation->delete(); - * } * * * @package Elgg.Core @@ -138,6 +142,13 @@ class ElggBatch */ public $callbackResult = null; + /** + * If false, offset will not be incremented. This is used for callbacks/loops that delete. + * + * @var bool + */ + private $incrementOffset = true; + /** * Batches operations on any elgg_get_*() or compatible function that supports * an options array. @@ -156,12 +167,18 @@ class ElggBatch * @param int $chunk_size The number of entities to pull in before requesting more. * You have to balance this between running out of memory in PHP * and hitting the db server too often. + * @param bool $inc_offset Increment the offset on each fetch. This must be false for + * callbacks that delete rows. You can set this after the + * object is created with {@see ElggBatch::setIncrementOffset()}. */ - public function __construct($getter, $options, $callback = null, $chunk_size = 25) { + public function __construct($getter, $options, $callback = null, $chunk_size = 25, + $inc_offset = true) { + $this->getter = $getter; $this->options = $options; $this->callback = $callback; $this->chunkSize = $chunk_size; + $this->setIncrementOffset($inc_offset); if ($this->chunkSize <= 0) { $this->chunkSize = 25; @@ -174,7 +191,7 @@ class ElggBatch // if passed a callback, create a new ElggBatch with the same options // and pass each to the callback. if ($callback && is_callable($callback)) { - $batch = new ElggBatch($getter, $options, null, $chunk_size); + $batch = new ElggBatch($getter, $options, null, $chunk_size, $inc_offset); $all_results = null; @@ -245,9 +262,15 @@ class ElggBatch } } + if ($this->incrementOffset) { + $offset = $this->offset + $this->retrievedResults; + } else { + $offset = $this->offset; + } + $current_options = array( 'limit' => $limit, - 'offset' => $this->offset + $this->retrievedResults + 'offset' => $offset ); $options = array_merge($this->options, $current_options); @@ -269,6 +292,16 @@ class ElggBatch } } + /** + * Increment the offset from the original options array? Setting to + * false is required for callbacks that delete rows. + * + * @param bool $increment + */ + public function setIncrementOffset($increment = true) { + $this->incrementOffset = (bool) $increment; + } + /** * Implements Iterator */ diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index 2fa8e9939..dc38dafbe 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -1311,12 +1311,16 @@ abstract class ElggEntity extends ElggData implements /** * Loads attributes from the entities table into the object. * - * @param int $guid GUID of Entity + * @param mixed $guid GUID of entity or stdClass object from entities table * * @return bool */ protected function load($guid) { - $row = get_entity_as_row($guid); + if ($guid instanceof stdClass) { + $row = $guid; + } else { + $row = get_entity_as_row($guid); + } if ($row) { // Create the array if necessary - all subclasses should test before creating diff --git a/engine/classes/ElggFileCache.php b/engine/classes/ElggFileCache.php index 8304372dc..34178d452 100644 --- a/engine/classes/ElggFileCache.php +++ b/engine/classes/ElggFileCache.php @@ -161,12 +161,25 @@ class ElggFileCache extends ElggCache { } /** - * This was probably meant to delete everything? + * Delete all files in the directory of this file cache * * @return void */ public function clear() { - // @todo writeme + $dir = $this->getVariable("cache_path"); + + $exclude = array(".", ".."); + + $files = scandir($dir); + if (!$files) { + return; + } + + foreach ($files as $f) { + if (!in_array($f, $exclude)) { + unlink($dir . $f); + } + } } /** @@ -184,7 +197,7 @@ class ElggFileCache extends ElggCache { return; } - $exclude = array(".",".."); + $exclude = array(".", ".."); $files = scandir($dir); if (!$files) { diff --git a/engine/classes/ElggGroup.php b/engine/classes/ElggGroup.php index ab223e1a4..f7f67bf41 100644 --- a/engine/classes/ElggGroup.php +++ b/engine/classes/ElggGroup.php @@ -29,12 +29,12 @@ class ElggGroup extends ElggEntity } /** - * Construct a new user entity, optionally from a given id value. + * Construct a new group entity, optionally from a given guid value. * * @param mixed $guid If an int, load that GUID. - * If a db row then will attempt to load the rest of the data. + * If an entity table db row, then will load the rest of the data. * - * @throws Exception if there was a problem creating the user. + * @throws Exception if there was a problem creating the group. */ function __construct($guid = null) { $this->initializeAttributes(); @@ -43,15 +43,15 @@ class ElggGroup extends ElggEntity $this->initialise_attributes(false); if (!empty($guid)) { - // Is $guid is a DB row - either a entity row, or a user table row. + // Is $guid is a entity table DB row if ($guid instanceof stdClass) { // Load the rest - if (!$this->load($guid->guid)) { + if (!$this->load($guid)) { $msg = elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid->guid)); throw new IOException($msg); } - // Is $guid is an ElggGroup? Use a copy constructor + // Is $guid is an ElggGroup? Use a copy constructor } else if ($guid instanceof ElggGroup) { elgg_deprecated_notice('This type of usage of the ElggGroup constructor was deprecated. Please use the clone method.', 1.7); @@ -59,11 +59,11 @@ class ElggGroup extends ElggEntity $this->attributes[$key] = $value; } - // Is this is an ElggEntity but not an ElggGroup = ERROR! + // Is this is an ElggEntity but not an ElggGroup = ERROR! } else if ($guid instanceof ElggEntity) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggGroup')); - // We assume if we have got this far, $guid is an int + // Is it a GUID } else if (is_numeric($guid)) { if (!$this->load($guid)) { throw new IOException(elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid))); @@ -319,11 +319,9 @@ class ElggGroup extends ElggEntity } /** - * Override the load function. - * This function will ensure that all data is loaded (were possible), so - * if only part of the ElggGroup is loaded, it'll load the rest. + * Load the ElggGroup data from the database * - * @param int $guid GUID of an ElggGroup entity + * @param mixed $guid GUID of an ElggGroup entity or database row from entity table * * @return bool */ @@ -333,6 +331,11 @@ class ElggGroup extends ElggEntity return false; } + // Only work with GUID from here + if ($guid instanceof stdClass) { + $guid = $guid->guid; + } + // Check the type if ($this->attributes['type'] != 'group') { $msg = elgg_echo('InvalidClassException:NotValidElggStar', array($guid, get_class())); diff --git a/engine/classes/ElggObject.php b/engine/classes/ElggObject.php index 649e32490..b4bae6825 100644 --- a/engine/classes/ElggObject.php +++ b/engine/classes/ElggObject.php @@ -41,12 +41,12 @@ class ElggObject extends ElggEntity { * * If no arguments are passed, create a new entity. * - * If an argument is passed attempt to load a full Object entity. Arguments - * can be: + * If an argument is passed, attempt to load a full ElggObject entity. + * Arguments can be: * - The GUID of an object entity. - * - A DB result object with a guid property + * - A DB result object from the entities table with a guid property * - * @param mixed $guid If an int, load that GUID. If a db row then will attempt to + * @param mixed $guid If an int, load that GUID. If a db row, then will attempt to * load the rest of the data. * * @throws IOException If passed an incorrect guid @@ -59,15 +59,15 @@ class ElggObject extends ElggEntity { $this->initialise_attributes(false); if (!empty($guid)) { - // Is $guid is a DB row - either a entity row, or a object table row. + // Is $guid is a DB row from the entity table if ($guid instanceof stdClass) { // Load the rest - if (!$this->load($guid->guid)) { + if (!$this->load($guid)) { $msg = elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid->guid)); throw new IOException($msg); } - // Is $guid is an ElggObject? Use a copy constructor + // Is $guid is an ElggObject? Use a copy constructor } else if ($guid instanceof ElggObject) { elgg_deprecated_notice('This type of usage of the ElggObject constructor was deprecated. Please use the clone method.', 1.7); @@ -75,11 +75,11 @@ class ElggObject extends ElggEntity { $this->attributes[$key] = $value; } - // Is this is an ElggEntity but not an ElggObject = ERROR! + // Is this is an ElggEntity but not an ElggObject = ERROR! } else if ($guid instanceof ElggEntity) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggObject')); - // We assume if we have got this far, $guid is an int + // Is it a GUID } else if (is_numeric($guid)) { if (!$this->load($guid)) { throw new IOException(elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid))); @@ -93,17 +93,22 @@ class ElggObject extends ElggEntity { /** * Loads the full ElggObject when given a guid. * - * @param int $guid Guid of an ElggObject + * @param mixed $guid GUID of an ElggObject or the stdClass object from entities table * * @return bool * @throws InvalidClassException */ protected function load($guid) { - // Test to see if we have the generic stuff + // Load data from entity table if needed if (!parent::load($guid)) { return false; } + // Only work with GUID from here + if ($guid instanceof stdClass) { + $guid = $guid->guid; + } + // Check the type if ($this->attributes['type'] != 'object') { $msg = elgg_echo('InvalidClassException:NotValidElggStar', array($guid, get_class())); diff --git a/engine/classes/ElggPluginManifest.php b/engine/classes/ElggPluginManifest.php index 7592eb667..7aa702d47 100644 --- a/engine/classes/ElggPluginManifest.php +++ b/engine/classes/ElggPluginManifest.php @@ -592,4 +592,23 @@ class ElggPluginManifest { return $return; } + + /** + * Returns a category's friendly name. This can be localized by + * defining the string 'admin:plugins:category:'. If no + * localization is found, returns the category with _ and - converted to ' ' + * and then ucwords()'d. + * + * @param str $category The category as defined in the manifest. + * @return str A human-readable category + */ + static public function getFriendlyCategory($category) { + $cat_raw_string = "admin:plugins:category:$category"; + $cat_display_string = elgg_echo($cat_raw_string); + if ($cat_display_string == $cat_raw_string) { + $category = str_replace(array('-', '_'), ' ', $category); + $cat_display_string = ucwords($category); + } + return $cat_display_string; + } } diff --git a/engine/classes/ElggSite.php b/engine/classes/ElggSite.php index ac0c87bf7..6d07778a9 100644 --- a/engine/classes/ElggSite.php +++ b/engine/classes/ElggSite.php @@ -57,8 +57,8 @@ class ElggSite extends ElggEntity { * - A URL as stored in ElggSite->url * - A DB result object with a guid property * - * @param mixed $guid If an int, load that GUID. If a db row then will attempt - * to load the rest of the data. + * @param mixed $guid If an int, load that GUID. If a db row then will + * load the rest of the data. * * @throws IOException If passed an incorrect guid * @throws InvalidParameterException If passed an Elgg* Entity that isn't an ElggSite @@ -70,15 +70,15 @@ class ElggSite extends ElggEntity { $this->initialise_attributes(false); if (!empty($guid)) { - // Is $guid is a DB row - either a entity row, or a site table row. + // Is $guid is a DB entity table row if ($guid instanceof stdClass) { // Load the rest - if (!$this->load($guid->guid)) { + if (!$this->load($guid)) { $msg = elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid->guid)); throw new IOException($msg); } - // Is $guid is an ElggSite? Use a copy constructor + // Is $guid is an ElggSite? Use a copy constructor } else if ($guid instanceof ElggSite) { elgg_deprecated_notice('This type of usage of the ElggSite constructor was deprecated. Please use the clone method.', 1.7); @@ -86,18 +86,18 @@ class ElggSite extends ElggEntity { $this->attributes[$key] = $value; } - // Is this is an ElggEntity but not an ElggSite = ERROR! + // Is this is an ElggEntity but not an ElggSite = ERROR! } else if ($guid instanceof ElggEntity) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggSite')); - // See if this is a URL + // See if this is a URL } else if (strpos($guid, "http") !== false) { $guid = get_site_by_url($guid); foreach ($guid->attributes as $key => $value) { $this->attributes[$key] = $value; } - // We assume if we have got this far, $guid is an int + // Is it a GUID } else if (is_numeric($guid)) { if (!$this->load($guid)) { throw new IOException(elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid))); @@ -111,7 +111,7 @@ class ElggSite extends ElggEntity { /** * Loads the full ElggSite when given a guid. * - * @param int $guid Guid of ElggSite entity + * @param mixed $guid GUID of ElggSite entity or database row object * * @return bool * @throws InvalidClassException @@ -122,6 +122,11 @@ class ElggSite extends ElggEntity { return false; } + // Only work with GUID from here + if ($guid instanceof stdClass) { + $guid = $guid->guid; + } + // Check the type if ($this->attributes['type'] != 'site') { $msg = elgg_echo('InvalidClassException:NotValidElggStar', array($guid, get_class())); @@ -417,6 +422,7 @@ class ElggSite extends ElggEntity { // default public pages $defaults = array( + 'walled_garden/.*', 'action/login', 'register', 'action/register', @@ -427,10 +433,14 @@ class ElggSite extends ElggEntity { 'action/security/refreshtoken', 'ajax/view/js/languages', 'upgrade\.php', + 'xml-rpc\.php', + 'mt/mt-xmlrpc\.cgi', 'css/.*', 'js/.*', 'cache/css/.*', 'cache/js/.*', + 'cron/.*', + 'services/.*', ); // include a hook for plugin authors to include public pages diff --git a/engine/classes/ElggUser.php b/engine/classes/ElggUser.php index bdf57c2c3..d7bb89265 100644 --- a/engine/classes/ElggUser.php +++ b/engine/classes/ElggUser.php @@ -47,7 +47,7 @@ class ElggUser extends ElggEntity * Construct a new user entity, optionally from a given id value. * * @param mixed $guid If an int, load that GUID. - * If a db row then will attempt to load the rest of the data. + * If an entity table db row then will load the rest of the data. * * @throws Exception if there was a problem creating the user. */ @@ -58,15 +58,15 @@ class ElggUser extends ElggEntity $this->initialise_attributes(false); if (!empty($guid)) { - // Is $guid is a DB row - either a entity row, or a user table row. + // Is $guid is a DB entity row if ($guid instanceof stdClass) { // Load the rest - if (!$this->load($guid->guid)) { + if (!$this->load($guid)) { $msg = elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid->guid)); throw new IOException($msg); } - // See if this is a username + // See if this is a username } else if (is_string($guid)) { $user = get_user_by_username($guid); if ($user) { @@ -75,7 +75,7 @@ class ElggUser extends ElggEntity } } - // Is $guid is an ElggUser? Use a copy constructor + // Is $guid is an ElggUser? Use a copy constructor } else if ($guid instanceof ElggUser) { elgg_deprecated_notice('This type of usage of the ElggUser constructor was deprecated. Please use the clone method.', 1.7); @@ -83,11 +83,11 @@ class ElggUser extends ElggEntity $this->attributes[$key] = $value; } - // Is this is an ElggEntity but not an ElggUser = ERROR! + // Is this is an ElggEntity but not an ElggUser = ERROR! } else if ($guid instanceof ElggEntity) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggUser')); - // We assume if we have got this far, $guid is an int + // Is it a GUID } else if (is_numeric($guid)) { if (!$this->load($guid)) { throw new IOException(elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid))); @@ -99,11 +99,9 @@ class ElggUser extends ElggEntity } /** - * Override the load function. - * This function will ensure that all data is loaded (were possible), so - * if only part of the ElggUser is loaded, it'll load the rest. + * Load the ElggUser data from the database * - * @param int $guid ElggUser GUID + * @param mixed $guid ElggUser GUID or stdClass database row from entity table * * @return bool */ @@ -113,6 +111,11 @@ class ElggUser extends ElggEntity return false; } + // Only work with GUID from here + if ($guid instanceof stdClass) { + $guid = $guid->guid; + } + // Check the type if ($this->attributes['type'] != 'user') { $msg = elgg_echo('InvalidClassException:NotValidElggStar', array($guid, get_class())); @@ -384,7 +387,6 @@ class ElggUser extends ElggEntity 'relationship' => 'friend', 'relationship_guid' => $this->guid, 'limit' => $limit, - 'offset' => get_input('offset', 0), 'full_view' => false, ); @@ -458,7 +460,14 @@ class ElggUser extends ElggEntity * @return array|false */ public function getObjects($subtype = "", $limit = 10, $offset = 0) { - return get_user_objects($this->getGUID(), $subtype, $limit, $offset); + $params = array( + 'type' => 'object', + 'subtype' => $subtype, + 'owner_guid' => $this->getGUID(), + 'limit' => $limit, + 'offset' => $offset + ); + return elgg_get_entities($params); } /** diff --git a/engine/classes/ElggWidget.php b/engine/classes/ElggWidget.php index 7914fa140..99708f66a 100644 --- a/engine/classes/ElggWidget.php +++ b/engine/classes/ElggWidget.php @@ -131,11 +131,21 @@ class ElggWidget extends ElggObject { usort($widgets, create_function('$a,$b','return (int)$a->order > (int)$b->order;')); + // remove widgets from inactive plugins + $widget_types = elgg_get_widget_types($this->context); + $inactive_widgets = array(); + foreach ($widgets as $index => $widget) { + if (!array_key_exists($widget->handler, $widget_types)) { + $inactive_widgets[] = $widget; + unset($widgets[$index]); + } + } + if ($rank == 0) { // top of the column - $this->order = $widgets[0]->order - 10; + $this->order = reset($widgets)->order - 10; } elseif ($rank == (count($widgets) - 1)) { - // bottom of the column + // bottom of the column of active widgets $this->order = end($widgets)->order + 10; } else { // reorder widgets @@ -147,7 +157,7 @@ class ElggWidget extends ElggObject { } } - // split the array in two and recombine with the moved array in middle + // split the array in two and recombine with the moved widget in middle $before = array_slice($widgets, 0, $rank); array_push($before, $this); $after = array_slice($widgets, $rank); @@ -159,6 +169,22 @@ class ElggWidget extends ElggObject { $order += 10; } } + + // put inactive widgets at the bottom + if ($inactive_widgets) { + $bottom = 0; + foreach ($widgets as $widget) { + if ($widget->order > $bottom) { + $bottom = $widget->order; + } + } + $bottom += 10; + foreach ($inactive_widgets as $widget) { + $widget->order = $bottom; + $bottom += 10; + } + } + $this->column = $column; } diff --git a/engine/classes/XMLRPCArrayParameter.php b/engine/classes/XMLRPCArrayParameter.php new file mode 100644 index 000000000..a8edccba7 --- /dev/null +++ b/engine/classes/XMLRPCArrayParameter.php @@ -0,0 +1,56 @@ +addField($v); + } + } + } + + /** + * Add a field to the container. + * + * @param XMLRPCParameter $value The value. + * + * @return void + */ + public function addField(XMLRPCParameter $value) { + if (!is_array($this->value)) { + $this->value = array(); + } + + $this->value[] = $value; + } + + /** + * Converts XML array to string + * + * @return string + */ + function __toString() { + $params = ""; + foreach ($this->value as $value) { + $params .= "$value"; + } + + return "$params"; + } +} diff --git a/engine/classes/XMLRPCBase64Parameter.php b/engine/classes/XMLRPCBase64Parameter.php new file mode 100644 index 000000000..7db0a761c --- /dev/null +++ b/engine/classes/XMLRPCBase64Parameter.php @@ -0,0 +1,28 @@ +value = base64_encode($blob); + } + + /** + * Convert to string + * + * @return string + */ + function __toString() { + return "{$value}"; + } +} diff --git a/engine/classes/XMLRPCBoolParameter.php b/engine/classes/XMLRPCBoolParameter.php new file mode 100644 index 000000000..607841cb8 --- /dev/null +++ b/engine/classes/XMLRPCBoolParameter.php @@ -0,0 +1,30 @@ +value = (bool)$value; + } + + /** + * Convert to string + * + * @return string + */ + function __toString() { + $code = ($this->value) ? "1" : "0"; + return "{$code}"; + } +} diff --git a/engine/classes/XMLRPCDateParameter.php b/engine/classes/XMLRPCDateParameter.php new file mode 100644 index 000000000..93bbbd8f5 --- /dev/null +++ b/engine/classes/XMLRPCDateParameter.php @@ -0,0 +1,33 @@ +value = $timestamp; + + if (!$timestamp) { + $this->value = time(); + } + } + + /** + * Convert to string + * + * @return string + */ + function __toString() { + $value = date('c', $this->value); + return "{$value}"; + } +} diff --git a/engine/classes/XMLRPCDoubleParameter.php b/engine/classes/XMLRPCDoubleParameter.php new file mode 100644 index 000000000..b7834650e --- /dev/null +++ b/engine/classes/XMLRPCDoubleParameter.php @@ -0,0 +1,29 @@ +value = (float)$value; + } + + /** + * Convert to string + * + * @return string + */ + function __toString() { + return "{$this->value}"; + } +} diff --git a/engine/classes/XMLRPCErrorResponse.php b/engine/classes/XMLRPCErrorResponse.php new file mode 100644 index 000000000..425c075cc --- /dev/null +++ b/engine/classes/XMLRPCErrorResponse.php @@ -0,0 +1,36 @@ +addParameter( + new XMLRPCStructParameter( + array ( + 'faultCode' => new XMLRPCIntParameter($code), + 'faultString' => new XMLRPCStringParameter($message) + ) + ) + ); + } + + /** + * Output to XML. + * + * @return string + */ + public function __toString() { + return "{$this->parameters[0]}"; + } +} diff --git a/engine/classes/XMLRPCIntParameter.php b/engine/classes/XMLRPCIntParameter.php new file mode 100644 index 000000000..0fc146165 --- /dev/null +++ b/engine/classes/XMLRPCIntParameter.php @@ -0,0 +1,29 @@ +value = (int)$value; + } + + /** + * Convert to string + * + * @return string + */ + function __toString() { + return "{$this->value}"; + } +} diff --git a/engine/classes/XMLRPCParameter.php b/engine/classes/XMLRPCParameter.php new file mode 100644 index 000000000..ffbad8082 --- /dev/null +++ b/engine/classes/XMLRPCParameter.php @@ -0,0 +1,16 @@ +parameters)) { + $this->parameters = array(); + } + + $this->parameters[] = $param; + } + + /** + * Add an integer + * + * @param int $value Value + * + * @return void + */ + public function addInt($value) { + $this->addParameter(new XMLRPCIntParameter($value)); + } + + /** + * Add a string + * + * @param string $value Value + * + * @return void + */ + public function addString($value) { + $this->addParameter(new XMLRPCStringParameter($value)); + } + + /** + * Add a double + * + * @param int $value Value + * + * @return void + */ + public function addDouble($value) { + $this->addParameter(new XMLRPCDoubleParameter($value)); + } + + /** + * Add a boolean + * + * @param bool $value Value + * + * @return void + */ + public function addBoolean($value) { + $this->addParameter(new XMLRPCBoolParameter($value)); + } +} diff --git a/engine/classes/XMLRPCStringParameter.php b/engine/classes/XMLRPCStringParameter.php new file mode 100644 index 000000000..35b28214b --- /dev/null +++ b/engine/classes/XMLRPCStringParameter.php @@ -0,0 +1,30 @@ +value = $value; + } + + /** + * Convert to XML string + * + * @return string + */ + function __toString() { + $value = htmlentities($this->value); + return "{$value}"; + } +} diff --git a/engine/classes/XMLRPCStructParameter.php b/engine/classes/XMLRPCStructParameter.php new file mode 100644 index 000000000..694ddf5df --- /dev/null +++ b/engine/classes/XMLRPCStructParameter.php @@ -0,0 +1,55 @@ + $v) { + $this->addField($k, $v); + } + } + } + + /** + * Add a field to the container. + * + * @param string $name The name of the field. + * @param XMLRPCParameter $value The value. + * + * @return void + */ + public function addField($name, XMLRPCParameter $value) { + if (!is_array($this->value)) { + $this->value = array(); + } + + $this->value[$name] = $value; + } + + /** + * Convert to string + * + * @return string + */ + function __toString() { + $params = ""; + foreach ($this->value as $k => $v) { + $params .= "$k$v"; + } + + return "$params"; + } +} diff --git a/engine/classes/XMLRPCSuccessResponse.php b/engine/classes/XMLRPCSuccessResponse.php new file mode 100644 index 000000000..e02e82c5c --- /dev/null +++ b/engine/classes/XMLRPCSuccessResponse.php @@ -0,0 +1,22 @@ +parameters as $param) { + $params .= "$param\n"; + } + + return "$params"; + } +} -- cgit v1.2.3