View source
<?php
define('DRD_API_VERSION', '1.0.20');
function drd_server_xmlrpc() {
include_once 'drd_server.domain.inc';
include_once 'drd_server.server.inc';
return array(
'drd.api' => 'drd_server_check_api',
'drd.connect' => 'drd_server_connect',
'drd.session.valid' => 'drd_server_check_session',
'drd.info' => 'drd_server_domain_info',
'drd.cache.flush' => 'drd_server_domain_flush_cache',
'drd.run.cron' => 'drd_server_domain_run_cron',
'drd.switch.maintenance' => 'drd_server_domain_switch_maintenance',
'drd.list.updates' => 'drd_server_domain_list_updates',
'drd.run.update' => 'drd_server_domain_run_update',
'drd.update.translation' => 'drd_server_domain_update_translation',
'drd.server.domains' => 'drd_server_server_domains',
'drd.server.svn.status' => 'drd_server_server_svn_status',
'drd.server.svn.update' => 'drd_server_server_svn_update',
'drd.server.php.error.log' => 'drd_server_server_php_error_log',
);
}
function drd_server_check_api($api) {
return drd_server_result('api', $api == DRD_API_VERSION);
}
function drd_server_connect($username, $password) {
$form_state['values']['name'] = $username;
$form_state['values']['pass'] = $password;
$form_state['values']['op'] = t('Login');
$GLOBALS['drd_xmlrpc_mode'] = TRUE;
drupal_form_submit('user_login', $form_state);
if (!form_get_errors()) {
if (user_access('administer site configuration')) {
return drd_server_result('connect', session_id());
}
else {
return drd_server_error(t('You do not have permission to access system data.'));
}
}
else {
return drd_server_error(t('Wrong username or password.'));
}
}
function drd_server_get_account_by_session($sid) {
try {
$account = db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid", array(
':sid' => $sid,
))
->fetchObject();
} catch (Exception $e) {
}
return $account;
}
function drd_server_check_session($sid) {
$account = drd_server_get_account_by_session($sid);
return drd_server_result('session.valid', isset($account) && $account && $account->uid > 0);
}
function drd_server_load_user($sid) {
$account = drd_server_get_account_by_session($sid);
if (isset($account) && $account && $account->uid > 0) {
$account = drupal_unpack($account);
$account->roles = array();
$account->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
$account->roles += db_query("SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = :uid", array(
':uid' => $account->uid,
))
->fetchAllKeyed(0, 1);
}
else {
return t('You are not logged in.');
}
if (user_access('administer site configuration', $account)) {
global $user;
$user = $account;
return $user;
}
return t('You do not have permission to access system data.');
}
function drd_server_result() {
$args = func_get_args();
$mode = $args[0];
$drd_result = $args[1];
unset($args[0], $args[1]);
foreach (module_implements('drd_server') as $module) {
$drd_result = module_invoke($module, 'drd_server', $mode, $drd_result, $args);
}
drupal_alter('drd_server', $mode, $drd_result);
$result = new stdClass();
$result->is_error = FALSE;
$result->message = $drd_result;
return drupal_json_encode($result);
}
function drd_server_error($message) {
static $xmlrpcusererr;
if (!is_array($message)) {
$message = array(
$message,
);
}
$message = implode(' ', $message);
return drupal_json_encode(xmlrpc_error($xmlrpcusererr + 1, strip_tags($message)));
}
function drd_server_block_info() {
$blocks = array();
if (module_exists('admin')) {
$blocks['drd'] = array(
'info' => t('Admin Extras Dashboard'),
'cache' => DRUPAL_CACHE_PER_ROLE,
'admin' => TRUE,
);
}
return $blocks;
}
function drd_server_block_view($delta) {
switch ($delta) {
case 'drd':
module_load_include('inc', 'drd_server', 'drd_server.admin');
return drd_server_admin_block();
}
}
function drd_server_permission() {
return array(
'flush cache' => array(
'title' => t('Flush Cache'),
),
);
}
function drd_server_menu() {
$items['admin/drd_server/flush/cache'] = array(
'title' => 'Flush Cache',
'page callback' => 'drd_server_admin_flush_cache',
'access arguments' => array(
'flush cache',
),
'file' => 'drd_server.admin.inc',
'type' => MENU_CALLBACK,
);
$items['admin/drd_server/update/translation'] = array(
'title' => 'Update translation',
'page callback' => 'drd_server_admin_update_translation',
'access arguments' => array(
'translate interface',
),
'file' => 'drd_server.admin.inc',
'type' => MENU_CALLBACK,
);
return $items;
}