This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_feed.module
280 lines (255 loc) · 9.2 KB
/
simple_feed.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?php
/**
* A simple feed that outputs node/taxonomy_term information in json format
*
* I have included some redundancies in the code for easier parsing, but if this
* does become something of value, it will definitely be further optimized.
*/
/**
* Implements hook_menu()
*/
function simple_feed_menu() {
module_load_include('inc', 'simple_feed');
module_load_include('inc', 'simple_feed', 'resources/db_control');
$items = array();
//----------------------------------------------------------------------------
// welcome page
$feed_dir = 'simple_feed';
$items[$feed_dir] = array(
'page callback' => 'simple_feed_welcome',
'access callback' => TRUE, // expose the page to show that module is enabled
'type' => MENU_CALLBACK,
);
//----------------------------------------------------------------------------
// profile menu
$config_dir = simple_feed_get_config_directory();
$items[$config_dir] = array(
'title' => t('Simple Feed'),
'description' => t('Manage simple feed profiles.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('simple_feed_profile_overview'),
'access arguments' => array('administer site configuration'),
);
// set profiles
$items[$config_dir . '/profiles'] = array(
'title' => t('Profiles'),
'weight' => 0,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
// set default settings
$items[$config_dir . '/default_settings'] = array(
'title' => t('Default Settings'),
'description' => t('Change default settings.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('simple_feed_default_settings_form'),
'access arguments' => array('administer site configuration'),
'weight' => 1,
'type' => MENU_LOCAL_TASK,
);
// profile add
$items[$config_dir . '/profiles/add'] = array(
'title' => t('Add Profile'),
'description' => t('Add new simple feed profile.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('simple_feed_add_profile_form'),
'access arguments' => array('administer site configuration'),
'type' => MENU_LOCAL_ACTION,
);
// profile dependent pages
$profiles = simple_feed_get_all_profiles();
$profile_statuses = variable_get('simple_feed_profile_statuses');
foreach($profiles as $p) {
$name = $p['name'];
// only build the feed menu item if it's enabled
if ($profile_statuses[$name] !== 0) {
// no titles specified because these won't be rendered as drupal pages
//------------------------------------------------------------------------
// welcome page
$items[$feed_dir . '/' . $name] = array(
'page callback' => 'simple_feed_welcome_profile',
'page arguments' => array(1,2),
'access callback' => 'simple_feed_access_callback',
'access arguments' => array(1),
'type' => MENU_CALLBACK,
);
//------------------------------------------------------------------------
// summary
$items[$feed_dir . '/' . $name . '/summary'] = array(
'page callback' => 'simple_feed_summary',
'page arguments' => array(1),
'access callback' => 'simple_feed_access_callback',
'access arguments' => array(1),
'type' => MENU_CALLBACK,
);
//------------------------------------------------------------------------
// node and nodes
$items[$feed_dir . '/' . $name . '/node'] = array(
'page callback' => 'simple_feed_node',
'page arguments' => array(1,3),
'access callback' => 'simple_feed_access_callback',
'access arguments' => array(1),
'type' => MENU_CALLBACK,
);
$items[$feed_dir . '/' . $name . '/nodes'] = array(
'page callback' => 'simple_feed_nodes',
'page arguments' => array(1,3),
'access callback' => 'simple_feed_access_callback',
'access arguments' => array(1),
'type' => MENU_CALLBACK,
);
//------------------------------------------------------------------------
// taxonomy term and terms
$items[$feed_dir . '/' . $name . '/taxonomy_term'] = array(
'page callback' => 'simple_feed_taxonomy_term',
'page arguments' => array(1,3),
'access callback' => 'simple_feed_access_callback',
'access arguments' => array(1),
'type' => MENU_CALLBACK,
);
$items[$feed_dir . '/' . $name . '/taxonomy_terms'] = array(
'page callback' => 'simple_feed_taxonomy_terms',
'page arguments' => array(1,3),
'access callback' => 'simple_feed_access_callback',
'access arguments' => array(1),
'type' => MENU_CALLBACK,
);
}
//--------------------------------------------------------------------------
// Configuration
$items[$config_dir . '/profiles/list/' . $p['name']] = array(
'title' => t('Configure Profile'),
'description' => t('Configure an existing simple feed profile.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('simple_feed_config_profile_form', 6),
'access arguments' => array('administer site configuration'),
);
// Delete
$items[$config_dir . '/profiles/list/' . $p['name'] . '/delete'] = array(
'title' => t('Delete Profile'),
'description' => t('Delete an existing simple feed profile.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('simple_feed_delete_profile_form', 6),
'access arguments' => array('administer site configuration'),
);
}
return $items;
}
//------------------------------------------------------------------------------
// Configuration callbacks, will return fetched forms
/**
* Profile overview form
*/
function simple_feed_profile_overview() {
module_load_include('inc', 'simple_feed', 'config/config_forms');
return simple_feed_get_profile_overview();
}
/**
* Default settings form
*/
function simple_feed_default_settings_form() {
module_load_include('inc', 'simple_feed', 'config/config_forms');
return simple_feed_get_default_settings_form();
}
/**
* Add profile form
*/
function simple_feed_add_profile_form($form, &$form_state) {
module_load_include('inc', 'simple_feed', 'config/config_forms');
return simple_feed_get_add_profile_form();
}
/**
* Configure profile form
*/
function simple_feed_config_profile_form($form, &$form_state, $profile) {
module_load_include('inc', 'simple_feed', 'config/config_forms');
return simple_feed_get_config_profile_form($profile);
}
/**
* Delete profile form
*/
function simple_feed_delete_profile_form($form, &$form_state, $profile) {
module_load_include('inc', 'simple_feed', 'config/config_forms');
return simple_feed_get_delete_profile_form($profile);
}
//------------------------------------------------------------------------------
// Endpoint callbacks, will send json to client
/**
* Welcome json for profile callback
*/
function simple_feed_welcome_profile($profile, $endpoint) {
module_load_include('inc', 'simple_feed', 'endpoints/welcome');
simple_feed_get_welcome_profile($profile, $endpoint);
}
/**
* Summary Listing menu callback
*/
function simple_feed_summary($profile) {
module_load_include('inc', 'simple_feed', 'endpoints/summary');
simple_feed_get_summary($profile);
}
/**
* Node menu callback
*/
function simple_feed_node($profile, $id=NULL) {
module_load_include('inc', 'simple_feed', 'endpoints/node');
simple_feed_get_node($profile, $id);
}
/**
* Nodes menu callback
*/
function simple_feed_nodes($profile, $id=NULL) {
module_load_include('inc', 'simple_feed', 'endpoints/nodes');
simple_feed_get_nodes($profile, $id);
}
/**
* Taxonomy Term menu callback
*/
function simple_feed_taxonomy_term($profile, $id=NULL) {
module_load_include('inc', 'simple_feed', 'endpoints/taxonomy_term');
simple_feed_get_taxonomy_term($profile, $id);
}
/**
* Taxonomy Terms menu callback
*/
function simple_feed_taxonomy_terms($profile, $id=NULL) {
module_load_include('inc', 'simple_feed', 'endpoints/taxonomy_terms');
simple_feed_get_taxonomy_terms($profile, $id);
}
//------------------------------------------------------------------------------
// Access Callback
function simple_feed_access_callback($profile) {
module_load_include('inc', 'simple_feed', 'security/verify_access');
return simple_feed_verify_access($profile);
}
//------------------------------------------------------------------------------
// Misc. page callbacks
/**
* Implements hook_help()
*/
function simple_feed_help($path, $arg) {
module_load_include('inc', 'simple_feed');
$config_dir = simple_feed_get_config_directory();
switch ($path) {
case $config_dir:
$msg = 'Manage your feed profiles below.<br>'
. 'Profile has to be enabled first (checkbox) to be functional.';
return '<p>'.t($msg).'</p>';
case $config_dir.'/default_settings':
$msg = 'Change default settings here.<br>';
return '<p>'.t($msg).'</p>';
}
}
/**
* Welcome message menu callback
*/
function simple_feed_welcome($param=NULL) {
$GLOBALS['devel_shutdown'] = FALSE; // suppressing devel output
if ($param === NULL) {
http_response_code(200);
echo t("Simple Feed module has been enabled successfully!");
} else {
http_response_code(404);
echo t("Simple Feed profile not found. ")."(/simple_feed/$param)";
}
exit();
}