This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
forked from cosmicdreams/drupal-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgathercontent.module
211 lines (196 loc) · 5.94 KB
/
gathercontent.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
<?php
/**
* @file
* Imports items from GatherContent (http://gathercontent.com/) into Drupal as
* nodes.
*/
/**
* Implements hook_menu().
*/
function gathercontent_menu() {
$items = array();
$path = drupal_get_path('module', 'gathercontent') . '/includes';
$items['admin/config/content/gathercontent'] = array(
'title' => 'GatherContent',
'description' => 'Import GatherContent items to your Drupal CMS',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer gathercontent'),
'file' => 'project.inc',
'file path' => $path,
'page arguments' => array('gathercontent_project_form'),
);
$items['admin/config/content/gathercontent/login'] = array(
'title' => 'GatherContent',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer gathercontent'),
'file' => 'login.inc',
'file path' => $path,
'type' => MENU_CALLBACK,
'page arguments' => array('gathercontent_login_form'),
);
$items['admin/config/content/gathercontent/items'] = array(
'title' => 'GatherContent',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer gathercontent'),
'file' => 'items.inc',
'file path' => $path,
'type' => MENU_CALLBACK,
'page arguments' => array('gathercontent_item_form'),
);
$items['admin/config/content/gathercontent/item_import'] = array(
'title' => 'GatherContent',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer gathercontent'),
'file' => 'item_import.inc',
'file path' => $path,
'type' => MENU_CALLBACK,
'page arguments' => array('gathercontent_item_import_form'),
);
$items['admin/config/content/gathercontent/media'] = array(
'title' => 'GatherContent',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer gathercontent'),
'file' => 'media.inc',
'file path' => $path,
'type' => MENU_CALLBACK,
'page arguments' => array('gathercontent_media_form'),
);
$items['admin/config/content/gathercontent/finished'] = array(
'title' => 'GatherContent',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer gathercontent'),
'file' => 'finished.inc',
'file path' => $path,
'type' => MENU_CALLBACK,
'page arguments' => array('gathercontent_finished_form'),
);
$items['admin/config/content/gathercontent/set_project_id/%'] = array(
'page callback' => 'gathercontent_set_project_id',
'access arguments' => array('administer gathercontent'),
'file' => 'project.inc',
'file path' => $path,
'type' => MENU_CALLBACK,
'page arguments' => array(5),
);
$items['admin/config/content/gathercontent/download_media'] = array(
'page callback' => 'gathercontent_ajax_media_download',
'access arguments' => array('administer gathercontent'),
'file' => 'media.inc',
'file path' => $path,
'type' => MENU_CALLBACK,
);
$items['admin/config/content/gathercontent/import_item'] = array(
'page callback' => 'gathercontent_import_item',
'access arguments' => array('administer gathercontent'),
'file' => 'item_import.inc',
'file path' => $path,
'type' => MENU_CALLBACK,
);
return $items;
}
function gathercontent_get_post_type($input){
$entity_key = explode(':', $input);
return $entity_key;
}
function gathercontent_put_post_type($entity_type, $bundle){
return "$entity_type:$bundle";
}
/**
* Implements hook_permission().
*/
function gathercontent_permission() {
return array(
'administer gathercontent' => array(
'title' => t('Administer GatherContent'),
'description' => t('Change settings and import items from GatherContent'),
'restrict access' => TRUE,
),
);
}
/**
* Used to get GatherContentCurl object.
*/
function gathercontent_get_obj() {
static $obj;
if (!isset($obj)) {
module_load_include('inc', 'gathercontent', 'includes/functions');
module_load_include('inc', 'gathercontent', 'includes/curl');
$obj = new GatherContentCurl();
}
return $obj;
}
/**
* Used to get current step from the URL.
*/
function gathercontent_check_step($step = '') {
$checks = array(
'projects',
'login',
'items',
'item_import',
'media',
'finished'
);
$step = in_array($step, $checks) ? $step : 'projects';
$checks = array(
'projects' => array(
'fields' => array('api_key','api_url'),
'prev' => 'login'
),
'items' => array(
'fields' => array('project_id'),
'prev' => 'projects'
),
'item_import' => array(
'fields' => array('project_id','selected_items'),
'prev' => 'projects'
),
'media' => array(
'fields' => array('project_id','selected_items'),
'prev' => 'projects'
),
);
if (isset($checks[$step])) {
$error = FALSE;
foreach ($checks[$step]['fields'] as $chk) {
if (variable_get('gathercontent_' . $chk, '') == '') {
$error = TRUE;
}
}
if ($error) {
$step = $checks[$step]['prev'];
drupal_goto('admin/config/content/gathercontent' . ($step == 'projects' ? '' : '/' . $step));
return FALSE;
}
}
$path = drupal_get_path('module', 'gathercontent');
drupal_add_css($path . '/css/main.css');
drupal_add_js($path . '/js/jquery-1.9.1.min.js');
drupal_add_js($path . '/js/bootstrap.min.js');
drupal_add_js($path . '/js/main.js');
return TRUE;
}
/**
* Implements hook_theme().
*/
function gathercontent_theme() {
$path = drupal_get_path('module', 'gathercontent') . '/includes';
return array(
'gathercontent_item_form' => array(
'render element' => 'form',
'file' => 'items.inc',
'path' => $path,
),
'gathercontent_item_import_form' => array(
'render element' => 'form',
'file' => 'item_import.inc',
'path' => $path,
),
);
}
/**
* Implements hook_file_delete().
*/
function gathercontent_file_delete($file) {
db_delete('gathercontent_media')->condition('fid', $file->fid)->execute();
}