-
Notifications
You must be signed in to change notification settings - Fork 0
/
druphone.module
185 lines (136 loc) · 4.16 KB
/
druphone.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
<?php
function druphone_theme() {
return array(
'filter_tips' => array(
'arguments' => array('tips' => NULL, 'long' => FALSE, 'extra' => ''),
'file' => 'druphone.pages.inc',
),
);
}
/**
* Implements hook_menu().
*/
function druphone_menu() {
$items = array();
$items['admin/settings/druphone'] = array(
'title'=>'Druphone Settings',
'description'=>'Edit settings',
'page callback' => 'drupal_get_form',
'page arguments'=>array('admin_settings_druphone'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'access callback' => TRUE,
'access arguments' => array('Admin dphone options'),
);
$items['admin/settings/druphone/options'] = array(
'title' => 'Add input format',
'page callback' => 'druphone_page',
'access arguments' => array('administer filters'),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items['druphone/regions/list'] = array(
'type' => MENU_CALLBACK,
'page callback' => 'druphone_regions_list',
'access callback' => 'user_access',
'access arguments' => array('access content'),
);
$items['druphone/regions'] = array(
'type' => MENU_CALLBACK,
'page callback' => 'druphone_regions',
'access callback' => 'user_access',
'access arguments' => array('access content'),
);
$items['druphone/script.js'] = array(
'type' => MENU_CALLBACK,
'page callback' => 'druphone_script',
'access callback' => 'user_access',
'access arguments' => array('access content'),
);
return $items;
}
function admin_settings_druphone(){
$themes = list_themes();
$theme_list = array();
$db_result = db_query("SELECT theme from {druphone}");
$row = db_fetch_object($db_result);
foreach ($themes as $i => $k)
if ($k -> status)
$theme_list[$k -> name] = $k -> info['name'];
$form = array();
$form['theme']=array(
'#type'=>'select',
'#title'=>t('Select theme'),
'#description' => t('Choose an option.'),
'#required'=>true,
'#default_value'=>$row->theme,
'#options' => $theme_list,
'#validate' => array('admin_settings_druphone_validate')
);
$form['submit']=array(
'#type'=>'submit',
'#value'=>'Save',
'#weight'=>2);
$form ['tabs'] = array(
'#type' => 'tabs',
);
return $form;
}
function admin_settings_druphone_validate($node, &$form_state){
}
function admin_settings_druphone_submit($node, &$form_state){
$theme = mysql_escape_string($form_state['values']['theme']);
db_query("UPDATE {druphone} SET theme='%s'", $theme);
drupal_set_message("Settings save " );
}
function druphone_select_theme(){
$db_result = db_query("SELECT theme from {druphone}");
$row = db_fetch_object($db_result);
return $row -> theme;
}
function druphone_regions_list(){
$list = array();
$theme_selected = druphone_select_theme();
foreach (system_region_list( $theme_selected ) as $var => $key)
$list[$var] = $key;
echo json_encode(array('status' => 0, 'data' => $list ));
}
function druphone_regions(){
global $theme_key;
$tmp_theme = $theme_key;
$tmp_q = $_GET['q'];
$region = mysql_escape_string ($_POST ['r']);
$regions = array();
$theme_key = druphone_select_theme();
$_GET['q'] = mysql_escape_string ($_POST['url']);
$regions[$region] = array("blocks" => json_encode(theme_blocks($region)));
echo json_encode(array('status' => 0, 'data' => $regions ));
//regresamos las variables a las anteriores
$theme_key = $tmp_theme;
$_GET['q'] = $tmp_q;
}
function druphone_script(){
global $base_url;
$jsbu = json_encode($base_url."/");
echo '
var Drupal = Drupal || { "settings": {}, "behaviors": {}, "themes": {}, "locale": {} };
jQuery.extend(Drupal.settings, {"basePath":'.$jsbu.'});
function load_blocks(regions){
jQuery.each(regions, function(i,v){
jQuery.ajax({
type:"POST",
dataType:"json",
data: "r="+i+"&url="+document.location.pathname,
url:"'.$base_url.'/druphone/regions",
success: function( data ) {
if (data.nodes){
console.log(data.nodes);
}
else
$.each(data.data,function(i,v){
$("#"+i).append($.parseJSON(v.blocks));
});
},
});
});
}';
}