-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgathercontent.module
160 lines (147 loc) · 5.26 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
<?php
function gathercontent_menu() {
$items = array();
$path = drupal_get_path('module', 'gathercontent').'/includes';
$items['admin/config/content/gathercontent'] = array(
'title' => 'GatherContent',
'description' => 'Import GatherContent pages 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/pages'] = array(
'title' => 'GatherContent',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer gathercontent'),
'file' => 'pages.inc',
'file path' => $path,
'type' => MENU_CALLBACK,
'page arguments' => array('gathercontent_pages_form'),
);
$items['admin/config/content/gathercontent/pages_import'] = array(
'title' => 'GatherContent',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer gathercontent'),
'file' => 'pages_import.inc',
'file path' => $path,
'type' => MENU_CALLBACK,
'page arguments' => array('gathercontent_pages_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_page'] = array(
'page callback' => 'gathercontent_import_page',
'access arguments' => array('administer gathercontent'),
'file' => 'pages_import.inc',
'file path' => $path,
'type' => MENU_CALLBACK,
);
return $items;
}
function gathercontent_permission() {
return array(
'administer gathercontent' => array(
'title' => t('Administer GatherContent'),
'description' => t('Change settings and import pages from GatherContent'),
'restrict access' => TRUE,
),
);
}
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 GatherContent_Curl();
}
return $obj;
}
function gathercontent_check_step($step='') {
$checks = array('projects', 'login', 'pages', 'pages_import', 'media', 'finished');
$step = in_array($step,$checks) ? $step : 'projects';
$checks = array(
'projects' => array('fields'=>array('api_key','api_url'),'prev'=>'login'),
'pages' => array('fields'=>array('project_id'),'prev'=>'projects'),
'pages_import' => array('fields'=>array('project_id','selected_pages'),'prev'=>'projects'),
'media' => array('fields'=>array('project_id','selected_pages'),'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;
}
function gathercontent_theme() {
$path = drupal_get_path('module', 'gathercontent').'/includes/';
return array(
'gathercontent_pages_form' => array(
'render element' => 'form',
'file' => 'pages.inc',
'path' => $path,
),
'gathercontent_pages_import_form' => array(
'render element' => 'form',
'file' => 'pages_import.inc',
'path' => $path,
),
);
}
function gathercontent_file_delete($file) {
db_delete('gathercontent_media')->condition('fid', $file->fid)->execute();
}