-
Notifications
You must be signed in to change notification settings - Fork 0
/
dotgo_api.module
executable file
·154 lines (140 loc) · 4.65 KB
/
dotgo_api.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
* @file
* Code for the DOTGO API module.
*/
include_once 'includes/dotgo_api.util.inc';
include_once 'includes/dotgo_api.error.inc';
/**
* Define the XMLNS for DOTGO CMRL
*/
define('DOTGO_XMLNS', 'http://dotgo.com/cmrl/1.0');
/**
* Implementation of hook_menu
*/
function dotgo_api_menu() {
$items = array();
$items['index.cmrl'] = array(
'title' => 'index.cmrl',
'page callback' => 'dotgo_api_index_cmrl',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['dotgo'] = array(
'title' => 'DOTGO',
'page callback' => 'dotgo_api_page_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['admin/config/services/dotgo'] = array(
'title' => 'Dotgo',
'description' => "Manage Dotgo Configuration",
'page callback' => 'drupal_get_form',
'page arguments' => array('dotgo_api_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'dotgo_api.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
$items['admin/config/services/dotgo/settings'] = array(
'title' => 'Dotgo Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('dotgo_api_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'dotgo_api.admin.inc',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
return $items;
}
/**
* Implementation of hook_perm
*/
function dotgo_api_perm() {
return array(
'dotgo basic access',
'dotgo user access',
'dotgo administration access',
);
}
/**
* Implements index.cmrl menu callback.
*/
function dotgo_api_index_cmrl() {
//check address to make sure it is either dotgo or a privileged user, after all sensitive info may be accessed anonymously otherwise.
$visitor = $_SERVER['REMOTE_ADDR'];
if (variable_get('dotgo_debug', 1)) {
// header info
header('Content-Type: text/xml');
$xml = new DOMDocument();
$cmrl = $xml->createElement('cmrl');
$cmrl = $xml->appendChild($cmrl);
$cmrl->setAttribute('account', variable_get('dotgo_account', 'dotgo_account'));
dotgo_api_render_engines($cmrl);
print $xml->saveXML();
}
}
/**
* Implements engine menu callback.
*/
function dotgo_api_page_callback() {
// callback to generic dotgo/%, display help text if no argument
// otherwise, look for a function with same name as arg(1); error if not found
if (variable_get('dotgo_debug', 1)) {
// did not give us an argument
$function = arg(1);
if ($function == '') {
return t('This page is not meant to be called directly.');
}
else {
// Set to DOTGO module functions.
$function = 'dotgo_'.arg(1);
// Set alt functions for modules with alternative naming schemes.
$alt_function = arg(1);
if (function_exists($function)) {
$arg = isset($_REQUEST['sys_argument']) ? trim($_REQUEST['sys_argument']) : NULL;
print $function($arg);
}
elseif (function_exists($alt_function)) {
$arg = isset($_REQUEST['sys_argument']) ? trim($_REQUEST['sys_argument']) : NULL;
print $alt_function($arg);
}
else {
print _dotgo_message(t('The server you have contacted is not correctly configured. Contact the site administrator.'));
}
}
}
}
/**
* Implements dotgo_api_render_engines.
*/
function dotgo_api_render_engines(&$cmrl){
$engines = module_invoke_all('dotgo_engine');
ksort($engines);
foreach ($engines as $e) {
if(isset($e['match'])){
if (!empty($e['children'])) {
$match = _dotgo_make_match($cmrl, $e['match']);
$default = _dotgo_make_match($match, '');
$engine = _dotgo_make_engine($default, $e['engine_href']);
ksort($e['children']);
foreach ($e['children'] as $child) {
$childmatch = _dotgo_make_match($match, $child['match']);
//checks if this is a follow engine
if ($child['follow'] && $child['follow_allow']) {
$block = _dotgo_make_block($childmatch);
$follow = _dotgo_make_follow($block, $child['follow_allow']);
$follow = _dotgo_make_engine($follow, $child['engine_href'], array('query' => array('register' => TRUE)));
$query = _dotgo_make_query($block, $child['follow']);
}
else {
$engine = _dotgo_make_engine($childmatch, $child['engine_href']);
}
}
}
else {
$match = _dotgo_make_match($cmrl, $e['match']);
$engine = _dotgo_make_engine($match, $e['engine_href']);
}
}
}
}