system_service.module in Services 5
Same filename and directory in other branches
The module which exposes services related to system activies
File
services/system_service/system_service.moduleView source
<?php
/**
* @file
* The module which exposes services related to system activies
*/
/**
* Implementation of hook_help().
*/
function system_service_help($section) {
switch ($section) {
case 'admin/help#services_node':
return t('<p>Provides node methods to services applications. Requires services.module.</p>');
case 'admin/modules#description':
return t('Provides node methods to services applications. Requires services.module.');
}
}
function system_service_perm() {
return array(
'send mail from remote',
'get variable from remote',
'set variable from remote',
'check module exists from remote',
);
}
/**
* Implementation of hook_service().
*/
function system_service_service() {
return array(
// system.connect
array(
'#method' => 'system.connect',
'#callback' => 'system_service_connect',
'#key' => FALSE,
'#auth' => FALSE,
'#return' => 'struct',
'#help' => t('Returns an object containing a sessid and user.'),
),
// system.mail
array(
'#method' => 'system.mail',
'#callback' => 'system_service_mail',
'#access arguments' => array(
'send mail from remote',
),
'#args' => array(
array(
'#name' => 'mailkey',
'#type' => 'string',
'#description' => t('A key to identify the mail sent, for altering.'),
),
array(
'#name' => 'to',
'#type' => 'string',
'#description' => t('The mail address or addresses where the message will be send to.'),
),
array(
'#name' => 'subject',
'#type' => 'string',
'#description' => t('Subject of the e-mail to be sent. This must not contain any newline characters, or the mail may not be sent properly.'),
),
array(
'#name' => 'body',
'#type' => 'string',
'#description' => t('Message to be sent. Drupal will format the correct line endings for you.'),
),
array(
'#name' => 'from',
'#type' => 'string',
'#optional' => TRUE,
'#description' => t('Sets From, Reply-To, Return-Path and Error-To to this value, if given.'),
),
array(
'#name' => 'headers',
'#type' => 'array',
'#optional' => TRUE,
'#description' => t('Associative array containing the headers to add. This is typically used to add extra headers (From, Cc, and Bcc).'),
),
),
'#return' => 'struct',
'#help' => t('Send an e-mail message, using Drupal variables and default settings.'),
),
// system.getVariable
array(
'#method' => 'system.getVariable',
'#callback' => 'system_service_getvariable',
'#access arguments' => array(
'get variable from remote',
),
'#args' => array(
array(
'#name' => 'name',
'#type' => 'string',
'#description' => t('The name of the variable to return.'),
),
array(
'#name' => 'default',
'#type' => 'string',
'#optional' => TRUE,
'#description' => t('The default value to use if this variable has never been set.'),
),
),
'#return' => 'string',
'#help' => t('Return a persistent variable.'),
),
// system.setVariable
array(
'#method' => 'system.setVariable',
'#callback' => 'system_service_setvariable',
'#access arguments' => array(
'set variable from remote',
),
'#args' => array(
array(
'#name' => 'name',
'#type' => 'string',
'#description' => t('The name of the variable to set.'),
),
array(
'#name' => 'value',
'#type' => 'string',
'#description' => t('The value to set.'),
),
),
'#help' => t('Set a persistent variable.'),
),
// system.moduleExists
array(
'#method' => 'system.moduleExists',
'#callback' => 'system_service_module_exists',
'#access arguments' => array(
'check module exists from remote',
),
'#args' => array(
array(
'#name' => 'module',
'#type' => 'string',
'#description' => t('The name of the module.'),
),
),
'#return' => 'string',
'#help' => t('Check if a module is enabled. If so, return its version.'),
),
);
}
/**
* Returns a specified node.
*/
function system_service_connect() {
global $user;
$return = new stdClass();
$return->sessid = session_id();
$return->user = $user;
return $return;
}
/**
* Send an email via the Services module.
*/
function system_service_mail($mailkey, $to, $subject, $body, $from = NULL, $headers = array()) {
$status = drupal_mail($mailkey, $to, $subject, $body, $from, $headers);
if (!$status) {
return services_error(t('There was a problem sending your email.'));
}
return $status;
}
/**
* Returns a specified variable.
*/
function system_service_getvariable($name, $default = NULL) {
return variable_get($name, $default);
}
/**
* Set a variable.
*/
function system_service_setvariable($name, $value) {
variable_set($name, $value);
}
/**
* Check if a module is enabled. If so, return its version.
*/
function system_service_module_exists($module) {
if (module_exists($module)) {
$modules = module_rebuild_cache();
if (array_key_exists($module, $modules)) {
return (string) $modules[$module]->info['version'];
}
}
return "";
}
Functions
Name | Description |
---|---|
system_service_connect | Returns a specified node. |
system_service_getvariable | Returns a specified variable. |
system_service_help | Implementation of hook_help(). |
system_service_mail | Send an email via the Services module. |
system_service_module_exists | Check if a module is enabled. If so, return its version. |
system_service_perm | |
system_service_service | Implementation of hook_service(). |
system_service_setvariable | Set a variable. |