forked from t-mark/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RCCWP_ThemeSettingsPage.php
executable file
·310 lines (264 loc) · 11.8 KB
/
RCCWP_ThemeSettingsPage.php
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<?php
/**
* Admin Theme Settings Page
*
*
*/
class RCCWP_ThemeSettingsPage
{
function ApplyHead(){
if (!empty($_GET['page']) && $_GET['page']!='Flutter_ThemeSettings') return;
RCCWP_WritePostPage::CustomFieldsCSSScripts();
}
function AddScripts(){
if (!empty($_GET['page']) && $_GET['page']!='Flutter_ThemeSettings') return;
//wp_enqueue_script('editor');
wp_enqueue_script('tiny_mce');
}
/**
* This function show the panel for
* add new panels and change his values
*
* @author David Valdez <david@freshout.us>
*
*/
function Main() {
global $wpdb,$flutter_domain;
//FlutterLayoutBlock::UpdateModuleSettings(get_template_directory().'/configure.xml', -1, '-', get_option('template'));
$template = get_option('template');
$template_module_id = $wpdb->get_var("SELECT module_id FROM ".FLUTTER_TABLE_LAYOUT_MODULES." WHERE theme = '{$template}'");
$moduleSettings = FlutterLayoutBlock::GetModuleSettings($template_module_id);
if (!$moduleSettings) die(__('This theme has no settings', $flutter_domain));
if (isset($_POST['_savesetttings'])){
foreach($moduleSettings->variables as $varKey => $variable) {
$moduleSettings->variables[$varKey]->value = $_POST[$variable->variable_name];
}
$moduleSettings->SaveValues();
}
?>
<script type="text/javascript">
var wp_root = "<?php echo get_bloginfo('wpurl');?>";
</script>
<script type="text/javascript" src="<?=FLUTTER_URI?>js/ui.core.js"></script>
<div class="wrap">
<h2><?php _e('Flutter Theme Settings', $flutter_domain); ?></h2>
<input type='hidden' id='editorcontainer'/>
<form name="themesettings_form" action="?page=Flutter_ThemeSettings" id="themesettings_form" method="post">
<table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
<?php
foreach($moduleSettings->variables as $variable) {
$variable->properties = array();
$inputName = $variable->variable_name;
$variableValue = $variable->value;
?>
<tr valign="top">
<th scope="row"><?php echo $variable->description ?></th>
<td>
<?php
switch ($variable->type)
{
case 'textbox' :
$variable->properties['size'] = "";
RCCWP_WritePostPage::TextboxInterface($variable, $inputName, 0, 0, $variableValue);
break;
case 'multiline_textbox' :
$variable->properties['height'] = "10";
$variable->properties['width'] = "10";
RCCWP_WritePostPage::MultilineTextboxInterface($variable, $inputName, 0, 0, $variableValue);
break;
case 'checkbox' :
RCCWP_WritePostPage::CheckboxInterface($variable, $inputName, 0, 0, $variableValue);
break;
case 'checkbox_list' :
RCCWP_WritePostPage::CheckboxListInterface($variable, $inputName, 0, 0, $variableValue);
break;
case 'radiobutton_list' :
RCCWP_WritePostPage::RadiobuttonListInterface($variable, $inputName, 0, 0, $variableValue);
break;
case 'dropdown_list' :
RCCWP_WritePostPage::DropdownListInterface($variable, $inputName, 0, 0, $variableValue);
break;
case 'listbox' :
$variable->properties['size'] = "";
RCCWP_WritePostPage::ListboxInterface($variable, $inputName, 0, 0, $variableValue);
break;
case 'file' :
RCCWP_WritePostPage::FileInterface($variable, $inputName, 0, 0, $variableValue);
break;
case 'image' :
RCCWP_WritePostPage::PhotoInterface($variable, $inputName, 0, 0, $variableValue);
break;
case 'date' :
$variable->properties['format'] = "m.d.y";
RCCWP_WritePostPage::DateInterface($variable, $inputName, 0, 0, $variableValue);
break;
case 'audio' :
RCCWP_WritePostPage::AudioInterface($variable, $inputName, 0, 0, $variableValue);
break;
case 'Color Picker' :
RCCWP_WritePostPage::ColorPickerInterface($customField, $inputName, 0, 0,$variableValue);
break;
case 'Slider' :
RCCWP_WritePostPage::SliderInterface($customField, $inputName, 0, 0,$variableValue);
break;
}
?>
</td>
</tr>
<?php
}
?>
</table>
<p class="submit" ><input name="_savesetttings" type="submit" value="<?php _e('Save Settings', $flutter_domain); ?>" /></p>
</form>
</div>
<?php
}
/**
* This function is for add new element at the Flutter i
* layout settings
*
* @author David Valdez <david@freshout.us>
*/
function show_layout_settings(){
global $flutter_domain,$wpdb;
$template = get_option('template');
$registered_layout = $wpdb->get_var("SELECT COUNT(*) FROM ".FLUTTER_TABLE_LAYOUT_MODULES." WHERE theme = '{$template}'");
if($registered_layout == 0){
$wpdb->query("INSERT INTO ".FLUTTER_TABLE_LAYOUT_MODULES." (module_id,theme,page,duplicate_id) VALUES (-1,'{$template}','-',0)");
}else{
$template_module_id = $wpdb->get_var("SELECT module_id FROM ".FLUTTER_TABLE_LAYOUT_MODULES." WHERE theme = '{$template}'");
}
if(!empty($_GET['flutter_action']) && $_GET['flutter_action'] == "create-layout-setting"){
RCCWP_ThemeSettingsPage::create_layout_element();
exit();
} ?>
<script type="text/javascript">
jQuery('document').ready(function(){
jQuery('.del_element').click(function(){
if(!confirm("<?php echo _e("are you sure?",$flutter_domain);?>")){
return false;
}
});
});
</script>
<?php
$modules = FlutterLayoutBlock::GetModuleSettings($template_module_id);
$table_header = "<table cellpadding='3' cellspacing='3' width='100%' class='widefat'>";
$table_header .= "<thead><tr><th scope='col' width='70%'>".__('Name',$flutter_domain)."</th><th scope='col' colspan='2'>".__('Actions',$flutter_domain)."</th></tr></thead><tbody>";
$table_body = "";
$table_footer = "</tbody></table>";
if(empty($modules->variables)){
echo "<h2>".__("You don't have any setting created, start creating one",$flutter_domain)."</h2>";
echo "<br /><a href='?page=RCCWP_ThemeSettingsPage&flutter_action=create-layout-setting'>Add new layout setting</a>";
exit();
}
foreach($modules->variables as $varkey => $variable){
if(empty($class)){
$class = "";
}
$class = $class == '' ? 'alternate' : '';
$table_body .= "<tr class='{$class}'>";
$table_body .= "<td>{$variable->variable_name}</td>";
$table_body .= "<td></td>";
$table_body .= "<td><a class='del_element' id='del_{$variable->variable_id}' href='?page=RCCWP_ThemeSettingsPage&element_id={$variable->variable_id}&flutter_action=delete-theme-settings'>".__("Delete",$flutter_domain)."</a></td>";
$table_body .= "</tr>";
}
echo $table_header.$table_body.$table_footer;
echo "<br /><br /><a href='?page=RCCWP_ThemeSettingsPage&flutter_action=create-layout-setting'>". __('add new template option',$flutter_domain)."</a>";
echo "<br /><br />";
echo '<a href="http://flutter.freshout.us"><img src="'. FLUTTER_URI.'/images/flutter_logo.jpg" /></a>';
}
/**
* Remove a setting layout option
*/
function remove_layout_setting(){
global $wpdb;
if (!is_user_logged_in()){
wp_redirect('?page=' . urlencode(FLUTTER_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php'));
}
if(empty($_GET['element_id']) || !is_int($_GET['element_id'])){
wp_redirect('?page=' . urlencode(FLUTTER_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php'));
}
$wpdb->query("DELETE FROM ".FLUTTER_TABLE_LAYOUT_VARIABLES." WHERE variable_id = ".$_GET['element_id']);
wp_redirect('?page=RCCWP_ThemeSettingsPage');
}
function finish_create_layout_element(){
global $flutter_domain,$wpdb;
$template = get_option('template');
$layout_id = $wpdb->get_var("SELECT block_id FROM ".FLUTTER_TABLE_LAYOUT_MODULES." WHERE theme = '{$template}'");
if(!empty($_POST['variable_name'])){
$types = array(
1 => 'textbox',
2 => 'multiline Textbox',
3 => 'checkbox',
4 => 'checkbox List',
5 => 'radiobutton List',
6 => 'dropdown List',
7 => 'listbox',
8 => 'file',
9 => 'image',
10 => 'date',
11 => 'audio' ,
12 => 'Color Picker',
13 => 'Slider'
);
$_POST['variable_name'] = trim($_POST['variable_name']);
$_POST['variable_name'] = str_replace(" ","_",$_POST['variable_name']);
$wpdb->query("INSERT INTO ".FLUTTER_TABLE_LAYOUT_VARIABLES." (variable_name,type,description,parent) VALUES ('{$_POST['variable_name']}','{$types[$_POST['custom-field-type']]}','{$_POST['description']}',{$layout_id});");
wp_redirect('?page=RCCWP_ThemeSettingsPage');
}
}
function create_layout_element(){
global $flutter_domain;
?>
<div class="wrap">
<h2><?php _e('Create a new layout Setting',$flutter_domain);?></h2>
<br/>
<form method="post" action="?page=RCCWP_ThemeSettingsPage&flutter_action=create-layout-setting&save=true">
<table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
<tbody>
<tr valing="top">
<th><?php _e('Name',$flutter_domain);?></th>
<td>
<input type="text" name="variable_name"/>
</td>
</tr>
<tr valing="top">
<th><?php _e('Description',$flutter_domain);?></th>
<td>
<textarea name="description"></textarea>
</td>
</tr>
<tr valing="top">
<th><?php _e('Type',$flutter_domain);?></th>
<td>
<?php
$field_types = RCCWP_CustomField::GetCustomFieldTypes();
foreach ($field_types as $field) :
$checked =
$field->name == RCCWP_CustomField::GetDefaultCustomFieldType() ?
'checked="checked"' : '';
?>
<label><input name="custom-field-type" value="<?php echo $field->id?>" type="radio" <?php echo $checked;?> >
<?php echo $field->name?></label><br />
<?php
endforeach;
?>
</td>
</tr>
<tr>
<th></th>
<td>
<input type="submit" id="continue-create-custom-field" value="<?php _e('Create',$flutter_domain);?>" onclick="submitForm=true;"/>
</td>
</tr>
</tbody>
</form>
<p class="submit" >
</p>
</div>
<?php
}
}
?>