View source
<?php
function wsdata_wsconfig_processor_info() {
return array(
'wsdata_simple_xml_processor' => array(
'fields' => array(
'list_boolean' => t('WSData Simple XML Processor'),
'number_decimal' => t('WSData Simple XML Processor'),
'number_float' => t('WSData Simple XML Processor'),
'number_integer' => t('WSData Simple XML Processor'),
'list_float' => t('WSData Simple XML Processor'),
'list_integer' => t('WSData Simple XML Processor'),
'list_text' => t('WSData Simple XML Processor'),
'text_long' => t('WSData Simple XML Processor'),
'text_with_summary' => t('WSData Simple XML Processor'),
'text' => t('WSData Simple XML Processor'),
),
'data' => t('WSData Simple XML Processor'),
),
'wsdata_simple_json_processor' => array(
'fields' => array(
'list_boolean' => t('WSData Simple JSON Processor'),
'number_decimal' => t('WSData Simple JSON Processor'),
'number_float' => t('WSData Simple JSON Processor'),
'number_integer' => t('WSData Simple JSON Processor'),
'list_float' => t('WSData Simple JSON Processor'),
'list_integer' => t('WSData Simple JSON Processor'),
'list_text' => t('WSData Simple JSON Processor'),
'text_long' => t('WSData Simple JSON Processor'),
'text_with_summary' => t('WSData Simple JSON Processor'),
'text' => t('WSData Simple JSON Processor'),
),
'data' => t('WSData Simple JSON Processor'),
),
);
}
function wsdata_wsdata_language_plugin() {
return array(
'header' => array(
'settings' => array(
'header' => 'Accept-Language',
),
'form' => 'wsdata_language_plugin_header_form',
'file' => 'wsdata.admin',
'file type' => 'inc',
'module' => 'wsdata',
),
'argument' => array(
'settings' => array(
'argument' => 'lang',
),
'form' => 'wsdata_language_plugin_argument_form',
'file' => 'wsdata.admin',
'file type' => 'inc',
'module' => 'wsdata',
),
'path' => array(
'settings' => array(
'position' => 0,
),
'form' => 'wsdata_language_plugin_path_form',
'file' => 'wsdata.admin',
'file type' => 'inc',
'module' => 'wsdata',
),
'uri' => array(
'settings' => array(),
'form' => 'wsdata_language_plugin_path_form',
'file' => 'wsdata.admin',
'file type' => 'inc',
'module' => 'wsdata',
),
'replace' => array(
'settings' => array(
'default' => '',
),
'form' => 'wsdata_language_plugin_replace_form',
'file' => 'wsdata.admin',
'file type' => 'inc',
'module' => 'wsdata',
),
'default' => array(
'settings' => array(),
'form' => 'wsdata_language_plugin_default_form',
'file' => 'wsdata.admin',
'file type' => 'inc',
'module' => 'wsdata',
),
);
}
function wsdata_get_language_plugins($plugin = NULL) {
$plugins = module_invoke_all('wsdata_language_plugin');
if (!empty($plugin)) {
if (array_key_exists($plugin, $plugins)) {
return $plugins[$plugin];
}
else {
return FALSE;
}
}
return $plugins;
}
abstract class WsData {
public $data;
protected $error;
protected $languages = FALSE;
public function __construct($data = NULL, &$entity = NULL, $lang = NULL) {
$this->entity = $entity;
if (isset($data) and $data) {
$this
->addData($data, $lang);
}
}
public function getError() {
return $this->error;
}
public function getData($key = NULL, $lang = NULL) {
$return_data = FALSE;
if (is_array($this->data)) {
$paths = array();
if ($this->languages) {
if (!is_null($lang) and array_key_exists($lang, $this->data)) {
$paths[$lang] = !empty($key) ? $lang . ':' . $key : $lang;
}
else {
foreach ($this->languages as $lang) {
$paths[$lang] = !empty($key) ? $lang . ':' . $key : $lang;
}
}
}
else {
if (!empty($key)) {
$paths[$key] = $key;
}
}
$return_data = $this->data;
if (empty($paths)) {
return $return_data;
}
if (!empty($paths[$key])) {
$location = explode(':', $paths[$key]);
foreach ($location as $l) {
if (isset($return_data[$l])) {
$return_data = $return_data[$l];
}
else {
$return_data = FALSE;
}
}
return $return_data;
}
if (!empty($paths[$lang]) and count($paths) == 1) {
$location = explode(':', $path[$lang]);
foreach ($location as $l) {
if (isset($return_data[$l])) {
$return_data = $return_data[$l];
}
else {
$return_data = FALSE;
}
}
$return_data[$lang] = $return_data;
return $return_data;
}
if ($this->languages and count($paths) > 1) {
$keyed_data = array();
foreach ($paths as $p => $path) {
$return_data = $this->data;
$location = explode(':', $path);
foreach ($location as $l) {
if (isset($return_data[$l])) {
$return_data = $return_data[$l];
}
else {
$return_data = FALSE;
}
}
$keyed_data[$p] = $return_data;
}
return $keyed_data;
}
}
return $return_data;
}
public function addData($data, $lang = NULL) {
if (!is_null($lang) and !empty($data)) {
$this->languages[$lang] = $lang;
$this->data[$lang] = $this
->parse($data);
}
else {
$this->data = $this
->parse($data);
}
}
public abstract function accepts();
protected abstract function parse($data);
}
abstract class WsConnector {
protected $expires;
protected $cacheDefaultTime;
protected $cacheDefaultOverride;
protected $staleCache;
protected $endpoint;
protected $error;
protected $languagePlugins = array(
'default',
);
public function getEndpoint() {
return $this->endpoint;
}
public function __construct($endpoint) {
$this->endpoint = trim($endpoint);
$this->expires = 0;
$this->cacheDefaultTime = 0;
$this->cacheDefaultOverride = FALSE;
$this->staleCache = FALSE;
}
public function supportsCaching() {
return FALSE;
}
public function getError() {
return $this->error;
}
public function getSupportedLanguagePlugins() {
return $this->languagePlugins;
}
public function defaultCache($mintime = 0, $override = FALSE, $stale = FALSE) {
$this->cacheDefaultTime = $mintime;
$this->cacheDefaultOverride = $override;
$this->staleCache = $stale;
}
abstract function getMethods();
public abstract function wscall($type, $method, $argument, $options);
public function create($method, $object, $options = array()) {
$this->expires = 0;
return $this
->wscall('create', $method, $object, $options);
}
public function read($method, $id, $options = array()) {
$this->expires = 0;
return $this
->wscall('read', $method, $id, $options);
}
public function update($id, $method, $object, $options = array()) {
$this->expires = 0;
return $this
->wscall('update', $method, array(
$id,
$object,
), $options);
}
public function delete($id, $method, $options = array()) {
$this->expires = 0;
return $this
->wscall('delete', $method, $id, $options);
}
public function index($method, $options = array()) {
$this->expires = 0;
return $this
->wscall('index', $method, array(), $options);
}
public function expires() {
if ($this->expires > 0) {
return $this->expires;
}
else {
return FALSE;
}
}
public function isDegraded() {
return FALSE;
}
protected function setError($code, $message) {
$this->error = array(
'code' => $code,
'message' => $message,
);
}
protected function clearError() {
$this->error = NULL;
}
}