View source
<?php
define('WSCONFIG_DEFAULT_DEGRADED_BACKOFF', 0);
function wsconfig_flush_caches() {
$connectors = module_invoke_all('wsconfig_connector_info');
variable_set('wsconfig_connectors', $connectors);
$processors = module_invoke_all('wsconfig_processor_info');
variable_set('wsconfig_processors', $processors);
}
function wsconfig_modules_enabled($modules) {
$connectors = module_invoke_all('wsconfig_connector_info');
variable_set('wsconfig_connectors', $connectors);
$processors = module_invoke_all('wsconfig_processor_info');
variable_set('wsconfig_processors', $processors);
}
function wsconfig_modules_disabled($modules) {
$processors = module_invoke_all('wsconfig_processor_info');
variable_set('wsconfig_processors', $processors);
$connectors = module_invoke_all('wsconfig_connector_info');
variable_set('wsconfig_connectors', $connectors);
}
function wsconfig_ctools_plugin_directory($module, $plugin) {
return 'plugins/' . $plugin;
}
function wsconfig_connector_crud($id, $op = NULL) {
}
function wsconfig_entity_info() {
$entities = array(
'wsconfig' => array(
'label' => t('Web Service Configuration'),
'entity class' => 'WsConfig',
'controller class' => 'WsConfigController',
'base table' => 'wsconfig',
'fieldable' => FALSE,
'exportable' => TRUE,
'translation' => array(
'locale' => TRUE,
),
'entity keys' => array(
'id' => 'wsconfig_id',
'name' => 'name',
'bundle' => 'type',
),
'bundle keys' => array(
'bundle' => 'type',
),
'bundles' => array(),
'load hook' => 'wsconfig_load',
'view modes' => array(
'full' => array(
'label' => t('Default'),
'custom settings' => FALSE,
),
),
'label callback' => 'wsconfig_class_label',
'uri callback' => 'wsconfig_uri',
'module' => 'wsconfig',
'access callback' => 'wsconfig_access',
'admin ui' => array(
'path' => 'admin/structure/wsconfig',
'file' => 'wsconfig.admin.inc',
'controller class' => 'WsConfigUIController',
'menu wildcard' => '%wsconfig',
),
),
);
$entities['wsconfig_type'] = array(
'label' => t('Web Service Configuration Type'),
'entity class' => 'WsConfigType',
'controller class' => 'WsConfigTypeController',
'base table' => 'wsconfig_type',
'fieldable' => FALSE,
'bundle of' => 'wsconfig',
'exportable' => TRUE,
'entity keys' => array(
'id' => 'id',
'name' => 'type',
'label' => 'label',
),
'module' => 'wsconfig',
'admin ui' => array(
'path' => 'admin/structure/wsconfig_types',
'file' => 'wsconfig_type.admin.inc',
'controller class' => 'WsConfigTypeUIController',
),
'access callback' => 'wsconfig_type_access',
);
return $entities;
}
function wsconfig_class_label($entity) {
if (isset($entity)) {
return $entity
->label();
}
else {
return "";
}
}
function wsconfig_entity_info_alter(&$entity_info) {
foreach (wsconfig_get_types() as $type => $info) {
$entity_info['wsconfig']['bundles'][$type] = array(
'label' => $info->label,
'admin' => array(
'path' => 'admin/structure/wsconfig_types/%wsconfig_type',
'real path' => 'admin/structure/wsconfig_types/' . $type,
'bundle argument' => 4,
'access arguments' => array(
'administer wsconfig types',
),
),
);
}
}
function wsconfig_permission() {
$permissions = array(
'administer wsconfig types' => array(
'title' => t('Administer web service configuration types'),
'description' => t('Create and delete fields for web service configuration types.'),
),
'administer wsconfig' => array(
'title' => t('Administer web service configurations'),
'description' => t('Edit and delete all web service configurations.'),
),
);
foreach (wsconfig_get_types() as $type) {
$type_name = check_plain($type->type);
$permissions += array(
"edit any {$type_name} wsconfig" => array(
'title' => t('%type_name: Edit any wsconfig of this type.', array(
'%type_name' => $type->label,
)),
),
"view any {$type_name} wsconfig" => array(
'title' => t('%type_name: View any wsconfig of this type.', array(
'%type_name' => $type->label,
)),
),
);
}
return $permissions;
}
function wsconfig_theme($existing, $type, $theme, $path) {
return array(
'wsconfig_add_list' => array(
'variables' => array(
'content' => array(),
),
'file' => 'wsconfig.admin.inc',
),
'wsconfig' => array(
'render element' => 'elements',
'template' => 'wsconfig',
),
'wsconfig_sample_data' => array(
'variables' => array(
'wsconfig_sample_data',
'wsconfig' => NULL,
),
'template' => 'wsconfig-sample-data',
),
);
}
function wsconfig_form_wsconfig_type_overview_form_alter(&$form, &$form_state) {
usort($form['table']['#rows'], '_wsconfig_form_overview_sort');
$name = array_shift($form['table']['#header']);
array_unshift($form['table']['#header'], $name, t('Active'));
$types = wsconfig_get_types();
foreach ($form['table']['#rows'] as $key => $row) {
$type = $types[$row[0]['data']['#name']];
if ($type
->isDisabled()) {
$degraded = $type
->getDegraded();
if ($degraded) {
$active = t('Degraded - Calls to WSConfigs using this type will not be run. Service will be automatically reenabled in %seconds.', array(
'%seconds' => $degraded,
));
}
else {
$active = t('Disabled - Calls to WSConfigs using this type will not be run.');
}
}
else {
$active = t('Enabled');
}
$name = array_shift($form['table']['#rows'][$key]);
array_unshift($form['table']['#rows'][$key], $name, $active);
}
}
function wsconfig_form_wsconfig_overview_form_alter(&$form, &$form_state) {
usort($form['table']['#rows'], '_wsconfig_form_overview_sort');
}
function _wsconfig_form_overview_sort($a, $b) {
return strcasecmp($a[0]['data']['#label'], $b[0]['data']['#label']);
}
function wsconfig_access($op, $wsconfig = NULL, $account = NULL) {
if (user_access('administer wsconfig', $account)) {
return TRUE;
}
if (isset($wsconfig) && ($type_name = $wsconfig->type)) {
$op = $op == 'view' ? 'view' : 'edit';
if (user_access("{$op} any {$type_name} wsconfig", $account)) {
return TRUE;
}
}
return FALSE;
}
function wsconfig_get_types($type_name = NULL) {
$types = entity_load_multiple_by_name('wsconfig_type', isset($type_name) ? array(
$type_name,
) : FALSE);
return isset($type_name) ? reset($types) : $types;
}
function wsconfig_type_access($op, $type = NULL, $account = NULL) {
return user_access('administer wsconfig types', $account);
}
function wsconfig_type_load($type) {
return wsconfig_get_types($type);
}
function wsconfig_type_create($values = array()) {
return entity_get_controller('wsconfig_type')
->create($values);
}
function wsconfig_type_save(WsConfigType $type) {
$type
->save();
}
function wsconfig_type_delete(WsConfigType $type) {
$type
->delete();
}
function wsconfig_get_list() {
$result = _wsconfig_get_list();
$list = array();
while ($record = $result
->fetchObject()) {
$list[$record->wsconfig_id] = $record->title;
}
return $list;
}
function wsconfig_get_list_by_name() {
$result = _wsconfig_get_list();
$list = array();
while ($record = $result
->fetchObject()) {
$list[$record->name] = $record->title;
}
return $list;
}
function wsconfig_get_list_tokens($wsconfig = "") {
$query = db_select('wsconfig', 'w');
$query
->fields('w', array(
'name',
'data',
))
->orderBy('name', 'DESC');
if (!empty($wsconfig)) {
$query
->condition('name', $wsconfig);
}
$result = $query
->execute();
$list = array();
while ($record = $result
->fetchObject()) {
$data = unserialize($record->data);
$tokens = array();
foreach ($data as $calltitle => $call) {
$matches = array();
if (is_string($call)) {
preg_match_all("/%[a-zA-Z0-9_]+/", $call, $matches);
if (count($matches[0]) > 0) {
$calltitle = explode('_data_method', $calltitle);
$list[$record->name][$calltitle[0]] = $matches[0];
}
}
}
}
return $list;
}
function wsconfig_load($wsconfig_id, $reset = FALSE) {
$wsconfigs = wsconfig_load_multiple(array(
$wsconfig_id,
), array(), $reset);
return reset($wsconfigs);
}
function wsconfig_load_by_name($name, $reset = FALSE) {
$id =& drupal_static(__FUNCTION__ . ':' . $name);
if ($reset or !$id) {
$query = new EntityFieldQuery();
$result = $query
->entityCondition('entity_type', 'wsconfig')
->propertyCondition('name', $name)
->execute();
if (!isset($result['wsconfig']) or !is_array($result['wsconfig'])) {
return FALSE;
}
$ids = array_keys($result['wsconfig']);
$id = reset($ids);
}
return wsconfig_load($id, $reset);
}
function wsconfig_load_multiple($wsconfig_ids = array(), $conditions = array(), $reset = FALSE) {
return entity_load('wsconfig', $wsconfig_ids, $conditions, $reset);
}
function wsconfig_exists_by_name($name) {
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'wsconfig')
->propertyCondition('name', $name)
->count();
$result = $query
->execute();
return $result > 0;
}
function wsconfig_delete(WsConfig $wsconfig) {
$wsconfig
->delete();
}
function wsconfig_delete_multiple(array $wsconfig_ids) {
entity_get_controller('wsconfig')
->delete($wsconfig_ids);
}
function wsconfig_create($values = array()) {
return entity_get_controller('wsconfig')
->create($values);
}
function wsconfig_save(WsConfig $wsconfig) {
return $wsconfig
->save();
}
function wsconfig_uri(WsConfig $wsconfig) {
return array(
'path' => 'admin/structure/wsconfig/' . $wsconfig->wsconfig_id,
);
}
function wsconfig_page_title(WsConfig $wsconfig) {
return $wsconfig->title;
}
function wsconfig_page_view($wsconfig, $view_mode = 'full') {
$controller = entity_get_controller('wsconfig');
$content = $controller
->view(array(
$wsconfig->wsconfig_id => $wsconfig,
));
drupal_set_title($wsconfig->title);
return $content;
}
function wsconfig_get_field_processors($types = array()) {
$field_processors = array();
$defined_proc = variable_get('wsconfig_processors', array());
foreach ($defined_proc as $classname => $value) {
if (!empty($value['fields'])) {
foreach ($value['fields'] as $type => $displaytext) {
if (!empty($types) && in_array($type, $types) || empty($types)) {
$field_processors[$classname] = $displaytext;
}
}
}
}
return $field_processors;
}
function wsconfig_get_form_processors() {
$form_processors = array();
$defined_proc = variable_get('wsconfig_processors', array());
foreach ($defined_proc as $classname => $value) {
if (isset($value['form'])) {
$form_processors[$classname] = $value['form'];
}
}
return $form_processors;
}
function wsconfig_get_data_processors() {
$form_processors = array();
$defined_proc = variable_get('wsconfig_processors', array());
foreach ($defined_proc as $classname => $value) {
if (isset($value['data'])) {
$form_processors[$classname] = $value['data'];
}
}
return $form_processors;
}
function _wsconfig_get_list() {
$query = db_select('wsconfig', 'w');
$query
->fields('w', array(
'wsconfig_id',
'title',
'name',
))
->orderBy('name', 'DESC');
$result = $query
->execute();
return $result;
}