-
Notifications
You must be signed in to change notification settings - Fork 0
/
advanced_custom_data.php
286 lines (242 loc) · 8.63 KB
/
advanced_custom_data.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
<?php
/**
* Provides custom data fields.
*
* @package plugins
* @author Philip Ullrich
*/
$plugin_is_filter = 9|CLASS_PLUGIN;
$plugin_description = gettext("Provides advanced custom data functionality.");
$plugin_author = "Philip Ullrich";
$plugin_version = '0.3.5';
$option_interface = 'advanced_custom_data';
zp_register_filter('admin_utilities_buttons', 'advanced_custom_data::overviewbutton');
zp_register_filter('save_album_custom_data', 'custom_data_save_album');
zp_register_filter('edit_album_custom_data', 'custom_data_edit_album');
zp_register_filter('save_image_custom_data', 'custom_data_save_image');
zp_register_filter('edit_image_custom_data', 'custom_data_edit_image');
zp_register_filter('admin_head', 'custom_admin_head');
/**
* Returns a processed custom data item
* called when an image is saved on the backend
*
* @param string $discard always empty
* @param int $i prefix for the image being saved
* @return string
*/
function custom_data_save_image($discard, $i) {
$result = $_POST[$i.'-custom_data'];
if(is_array($result)) {
foreach ($result as &$row) {
$row = sanitize($row,1);
}
}
return serialize($result);
}
/**
* Returns table row(s) for the edit of an image custom data field
*
* @param string $discard always empty
* @param int $currentimage prefix for the image being edited
* @param object $image the image object
* @return string
*/
function custom_data_edit_image($discard, $image, $currentimage) {
$answer;
$current = unserialize($image->getCustomData("all"));
$acds = advanced_custom_data::getAllAcds("images");
$checked = 'checked="checked"';
$answer = "\n<tr id='acd_admin_table'>
\n<td id='acd_admin_table_left' align='left' valign='top'>".gettext('Custom Settings:')."</td>
\n<td id='acd_admin_table_right'>";
foreach($acds as $id=>$row) {
$title = trim(strtolower($row['acd_title']));
$answer.= "<div class='acd_admin_table-field'>";
$answer.= "\n<p class='acd_title'><strong>".$row['acd_title']."</strong></p>";
switch($row['acd_type']) {
case "checkbox" :
$val = (is_array($current) && isset($current[$id])) ? $current[$id] : false;
$answer .= "\n<input type='checkbox' name='".$currentimage."-custom_data[".$id."]'"
.(!$val?:$checked)." value='1' />";
break;
case "input" :
$val = (is_array($current) && isset($current[$id])) ? $current[$id] : false;
$size = $row['acd_opt_input_length'] ? $row['acd_opt_input_length'] : 32;
$answer.= "\n<input type='text' name='".$currentimage."-custom_data[".$id."]' size='".min($size,64)."' maxlength='".$size."' value='".$val."'/>";
break;
case "textarea" :
$val = (is_array($current) && isset($current[$id])) ? $current[$id] : false;
$rows = $row['acd_opt_textarea_rows'] ? $row['acd_opt_textarea_rows'] : 32;
$cols = $row['acd_opt_textarea_cols'] ? $row['acd_opt_textarea_cols'] : 5;
$answer.= "\n<textarea name='".$currentimage."-custom_data[".$id."]' cols='".$cols
."' cols ='".$cols."'>".$val."</textarea>";
break;
}
if($row['acd_desc']) {
$answer.= "\n<p class='acd_desc'>".$row['acd_desc']."</p>";
}
$answer.= "\n</div>";
}
$answer.= "\n</td>\n</tr>";
return $answer;
}
/**
* Returns a processed album custom data item
* called when an album is saved on the backend
*
* @param string $discard always empty
* @param int $prefix the prefix for the album being saved
* @return string
*/
function custom_data_save_album($discard, $prefix) {
$result = $_POST[$prefix.'x_album_custom_data'];
if(is_array($result)) {
foreach ($result as &$row) {
$row=sanitize($row,1);
}
}
return serialize($result);
}
/**
* Returns table row(s) for the edit of an album custom data field
*
* @param string $discard always empty
* @param int $prefix prefix of the album being edited
* @param object $album the album object
* @return string
*/
function custom_data_edit_album($discard, $album, $prefix) {
$answer;
$acds = advanced_custom_data::getAllAcds("albums");
$current = unserialize($album->getCustomData("all"));
$checked = 'checked="checked"';
$answer = "\n<tr id='acd_admin_table'>
\n<td id='acd_admin_table_left' align='left' valign='top'>".gettext('Custom Settings:')."</td>
\n<td id='acd_admin_table_right'>";
foreach($acds as $id=>$row) {
$title = trim(strtolower($row['acd_title']));
$answer.= "<div class='acd_admin_table-field'>";
$answer.= "\n<p class='acd_title'><strong>".$row['acd_title']."</strong></p>";
switch($row['acd_type']) {
case "checkbox" :
$val = (is_array($current) && isset($current[$id])) ? $current[$id] : false;
$answer .= "\n<input type='checkbox' name='".$prefix."x_album_custom_data[".$id."]'"
.(!$val?:$checked)." value='1' />";
break;
case "input" :
$val = (is_array($current) && isset($current[$id])) ? $current[$id] : false;
$size = $row['acd_opt_input_length'] ? $row['acd_opt_input_length'] : 32;
$answer.= "\n<input type='text' name='".$prefix."x_album_custom_data[".$id."]' size='".min($size,64)."' maxlength='".$size."' value='".$val."'/>";
break;
case "textarea" :
$val = (is_array($current) && isset($current[$id])) ? $current[$id] : false;
$rows = $row['acd_opt_textarea_rows'] ? $row['acd_opt_textarea_rows'] : 32;
$cols = $row['acd_opt_textarea_cols'] ? $row['acd_opt_textarea_cols'] : 5;
$answer.= "\n<textarea name='".$prefix."x_album_custom_data[".$id."]' cols='".$cols
."' cols ='".$cols."'>".$val."</textarea>";
break;
}
if($row['acd_desc']) {
$answer.= "\n<p class='acd_desc'>".$row['acd_desc']."</p>";
}
$answer.= "\n</div>";
}
$answer.= "\n</td>\n</tr>";
return $answer;
}
function custom_admin_head($discard) {
echo '<link rel="stylesheet" href="'.WEBPATH.'/plugins/advanced_custom_data/acd_admin.css" type="text/css" />';
}
function getAcd($type, $field = FALSE) {
$allAcds = advanced_custom_data::getAllAcds();
if($type == "album") {
global $_zp_current_album;
$curAcd = unserialize($_zp_current_album->getCustomData("all"));
} elseif ($type == "image") {
global $_zp_current_image;
$curAcd = unserialize($_zp_current_image->getCustomData("all"));
} else return false;
if (!is_array($curAcd)) return NULL;
$answer = array();
foreach($curAcd as $id=>$value) {
if(isset($allAcds[$id])) {
$answer[$allAcds[$id]['aux']] = $value;
}
}
if ($field && isset($answer[$field])) {
return $answer[$field];
} else if ($field) {
return NULL;
}
return $answer;
}
// OPTION INTERFACE CLASS
class advanced_custom_data {
var $ratingstate;
/**
* class instantiation function
*
*/
function advanced_custom_data() {
setOptionDefault('show_button', 1);
}
/**
* Reports the supported options
*
* @return array
*/
function getOptionsSupported() {
return array(gettext('new_field') => array('key' => 'show_button', 'type' => OPTION_TYPE_CHECKBOX_ARRAY,
'checkboxes' => array(gettext("Show Button") => "1"),
'order' =>1,
'desc' => gettext('Whether to show the button')),
);
}
function handleOption($option, $currentValue) {
}
static function overviewbutton($buttons) {
$buttons[] = array(
'category'=>gettext('Advanced Custom Data'),
'enable'=>'true',
'button_text'=>gettext('Create ACD entries'),
'formname'=>'advanced_custom_data_button',
'action'=>WEBPATH.'/plugins/advanced_custom_data/acd_create.php?page=overview&tab=create_fields',
'icon'=>'images/arrow_up.png',
'alt'=>'',
'hidden'=>'<input type="hidden" name="tab" value="create_fields" />',
'rights'=>ADMIN_RIGHTS,
'title'=>'Create new custom data fields'
);
$buttons[] = array(
'category'=>gettext('Advanced Custom Data'),
'enable'=>'true',
'button_text'=>gettext('Edit exisiting ACD entries'),
'formname'=>'advanced_custom_data_button',
'action'=>WEBPATH.'/plugins/advanced_custom_data/acd_edit.php?page=overview&tab=manage_fields',
'icon'=>'images/arrow_up.png',
'alt'=>'',
'hidden'=>'<input type="hidden" name="tab" value="manage_fields" />',
'rights'=>ADMIN_RIGHTS,
'title'=>'Manage your custom data fields'
);
return $buttons;
}
static function getAllAcds($category = FALSE) {
$acd = array();
$count = 0;
$result = query('SELECT * FROM'.prefix('plugin_storage').' WHERE `type`="advanced_custom_data" ');
while ($row = db_fetch_assoc($result)) {
$id = $row['id'];
$data = unserialize($row['data']);
if (!$category || ($data['acd_category'] == $category) || ($data['acd_category'] == 'both')) {
$acd[$id]['aux'] = $row['aux'];
foreach($data as $key=>$value) {
$acd[$id][$key] = $value;
$acd[$id][$key] = $value;
}
}
}
return ($result) ? $acd : false;
}
}
?>