Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 534 lines (466 sloc) 17.945 kB
b2cb842 @hunk add all files
hunk authored
1 <?php
2
3 require_once 'RCCWP_Constant.php';
4 require_once 'tools/debug.php';
5
6 /**
7 * Get number of group duplicates given field name. The function returns 1
8 * if there are no duplicates (just the original group), 2 if there is one
9 * duplicate and so on.
10 *
11 * @param string $fieldName the name of any field in the group
12 * @return number of group duplicates
13 */
14 function getGroupDuplicates ($fieldName) {
15 require_once("RCCWP_CustomField.php");
16 global $post;
17 return RCCWP_CustomField::GetFieldGroupDuplicates($post->ID, $fieldName);
18 }
19
20 /**
21 * Get number of field duplicates given field name and group duplicate index.
22 * The function returns 1 if there are no duplicates (just the original field),
23 * 2 if there is one duplicate and so on.
24 *
25 * @param string $fieldName
26 * @param integer $groupIndex
27 * @return number of field duplicates
28 */
29 function getFieldDuplicates ($fieldName, $groupIndex) {
30 require_once("RCCWP_CustomField.php");
31 global $post;
32 return RCCWP_CustomField::GetFieldDuplicates($post->ID, $fieldName, $groupIndex);
33 }
34
35 /**
36 * Get the value of an input field.
37 *
38 * @param string $fieldName
39 * @param integer $groupIndex
40 * @param integer $fieldIndex
41 * @param boolean $readyForEIP if true and the field type is textbox or
42 * multiline textbox, the resulting value will be wrapped
43 * in a div that is ready for EIP. The default value is true
44 * @return a string or array based on field type
45 */
29e33c5 @hunk get, get_image, get_audio and gen_image works outside WP loop
hunk authored
46 function get ($fieldName, $groupIndex=1, $fieldIndex=1, $readyForEIP=true,$post_id=NULL) {
b2cb842 @hunk add all files
hunk authored
47 require_once("RCCWP_CustomField.php");
2ac281e @hunk clean code
hunk authored
48 global $post, $FIELD_TYPES;
b2cb842 @hunk add all files
hunk authored
49
29e33c5 @hunk get, get_image, get_audio and gen_image works outside WP loop
hunk authored
50 if(!$post_id){ $post_id = $post->ID; }
e696938 @hunk optimization: front-end function only 1 query [get, get_audio, get_im…
hunk authored
51 $field = RCCWP_CustomField::GetDataField($fieldName,$groupIndex, $fieldIndex,$post_id);
09d72aa @hunk reducing the number of querys of the functions of front-end [get, get…
hunk authored
52 if(!$field) return FALSE;
53
54 $fieldType = $field['type'];
55 $fieldID = $field['id'];
56 $fieldObject = $field['properties'];
e696938 @hunk optimization: front-end function only 1 query [get, get_audio, get_im…
hunk authored
57 $fieldValues = (array)$field['meta_value'];
58 $fieldMetaID = $field['meta_id'];
96192b2 @gnuget Fixing the EIP now works fine
gnuget authored
59
09d72aa @hunk reducing the number of querys of the functions of front-end [get, get…
hunk authored
60 $results = GetProcessedFieldValue($fieldValues, $fieldType, $fieldObject);
96192b2 @gnuget Fixing the EIP now works fine
gnuget authored
61
b2cb842 @hunk add all files
hunk authored
62 //filter for multine line
63 if($fieldType == $FIELD_TYPES['multiline_textbox']){
64 $results = apply_filters('the_content', $results);
65 }
66 if($fieldType == $FIELD_TYPES['image']){
67 $results = split('&',$results);
68 $results = $results[0];
69 }
70
71 // Prepare fields for EIP
72 include_once('RCCWP_Options.php');
73 $enableEditnplace = RCCWP_Options::Get('enable-editnplace');
74 if ($readyForEIP && $enableEditnplace == 1 && current_user_can('edit_posts', $post->ID)){
abeef31 @chuyskywalker The non-glorious work of getting the code base switched over to tabs …
chuyskywalker authored
75 switch($fieldType){
76 case $FIELD_TYPES["textbox"]:
77 if(!$results) $results="&nbsp";
78 $results = "<div class='".EIP_textbox($fieldMetaID)."' >".$results."</div>";
79 break;
80 case $FIELD_TYPES["multiline_textbox"]:
81 if(!$results) $results="&nbsp";
82 $results = "<div class='".EIP_mulittextbox($fieldMetaID)."' >".$results."</div>";
83 break;
84 }
85 }
86 return $results;
b2cb842 @hunk add all files
hunk authored
87
88 }
89
90 function GetProcessedFieldValue($fieldValues, $fieldType, $fieldProperties=array()){
91 global $FIELD_TYPES;
92
93 $results = array();
94 $fieldValues = (array) $fieldValues;
95 foreach($fieldValues as $fieldValue){
96
97 switch($fieldType){
98 case $FIELD_TYPES["audio"]:
99 case $FIELD_TYPES["file"]:
100 case $FIELD_TYPES["image"]:
101 if ($fieldValue != "") $fieldValue = MF_FILES_URI.$fieldValue;
102 break;
103
104 case $FIELD_TYPES["checkbox"]:
105 if ($fieldValue == 'true') $fieldValue = true; else $fieldValue = false;
106 break;
107
108 case $FIELD_TYPES["date"]:
109 $fieldValue = date($fieldProperties['format'],strtotime($fieldValue));
110 break;
111 }
112
113 array_push($results, $fieldValue);
114 }
115
116 // Return array or single value based on field
117 switch($fieldType){
118 case $FIELD_TYPES["checkbox_list"]:
119 case $FIELD_TYPES["listbox"]:
120 return $results;
121 break;
122 }
123
124 if (count($results) == 0 )
125 return "";
126 else
127 return $results[0];
128 }
129
130 // Get Audio.
29e33c5 @hunk get, get_image, get_audio and gen_image works outside WP loop
hunk authored
131 function get_audio ($fieldName, $groupIndex=1, $fieldIndex=1,$post_id=NULL) {
b2cb842 @hunk add all files
hunk authored
132 require_once("RCCWP_CustomField.php");
2ac281e @hunk clean code
hunk authored
133 global $post;
b2cb842 @hunk add all files
hunk authored
134
29e33c5 @hunk get, get_image, get_audio and gen_image works outside WP loop
hunk authored
135 if(!$post_id){ $post_id = $post->ID; }
e696938 @hunk optimization: front-end function only 1 query [get, get_audio, get_im…
hunk authored
136 $field = RCCWP_CustomField::GetDataField($fieldName,$groupIndex, $fieldIndex,$post_id);
09d72aa @hunk reducing the number of querys of the functions of front-end [get, get…
hunk authored
137 if(!$field) return FALSE;
138 $fieldType = $field['type'];
139 $fieldID = $field['id'];
e696938 @hunk optimization: front-end function only 1 query [get, get_audio, get_im…
hunk authored
140 $fieldValue = $field['meta_value'];
b2cb842 @hunk add all files
hunk authored
141
abeef31 @chuyskywalker The non-glorious work of getting the code base switched over to tabs …
chuyskywalker authored
142 if(empty($fieldValue)) return FALSE;
b2cb842 @hunk add all files
hunk authored
143
144 $path = MF_FILES_URI;
145 $fieldValue = $path.$fieldValue;
146 $finalString = stripslashes(trim("\<div style=\'padding-top:3px;\'\>\<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\' codebase='\http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\' width=\'95%\' height=\'20\' wmode=\'transparent\' \>\<param name=\'movie\' value=\'".MF_URI."js/singlemp3player.swf?file=".urlencode($fieldValue)."\' wmode=\'transparent\' /\>\<param name=\'quality\' value=\'high\' wmode=\'transparent\' /\>\<embed src=\'".MF_URI."js/singlemp3player.swf?file=".urlencode($fieldValue)."' width=\'50\%\' height=\'20\' quality=\'high\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\' type=\'application/x-shockwave-flash\' wmode=\'transparent\' \>\</embed\>\</object\>\</div\>"));
147 return $finalString;
148 }
149
abeef31 @chuyskywalker The non-glorious work of getting the code base switched over to tabs …
chuyskywalker authored
150 function GetFieldInfo($customFieldId){
151 global $wpdb;
152 $sql = "SELECT properties FROM " . MF_TABLE_CUSTOM_FIELD_PROPERTIES .
153 " WHERE custom_field_id = '" . $customFieldId."'";
154 $results = $wpdb->get_row($sql);
155 //$results->options = unserialize($results->options);
156 $results->properties = unserialize($results->properties);
157 //$results->default_value = unserialize($results->default_value);
158 return $results;
159 }
160
b2cb842 @hunk add all files
hunk authored
161 function pt(){
abeef31 @chuyskywalker The non-glorious work of getting the code base switched over to tabs …
chuyskywalker authored
162 return PHPTHUMB;
b2cb842 @hunk add all files
hunk authored
163 }
164
165
166 /**
167 * Return a array with the order of a group
168 *
169 * @param string $groupName
170 */
29e33c5 @hunk get, get_image, get_audio and gen_image works outside WP loop
hunk authored
171 function getGroupOrder($field_name,$post_id=NULL){
abeef31 @chuyskywalker The non-glorious work of getting the code base switched over to tabs …
chuyskywalker authored
172 global $post,$wpdb;
29e33c5 @hunk get, get_image, get_audio and gen_image works outside WP loop
hunk authored
173
abeef31 @chuyskywalker The non-glorious work of getting the code base switched over to tabs …
chuyskywalker authored
174 if(!$post_id){ $post_id = $post->ID; }
6603429 @hunk fix in getGroupOrder, add DISTINCT in select
hunk authored
175 $elements = $wpdb->get_results("SELECT DISTINCT(group_count) FROM ".MF_TABLE_POST_META." WHERE post_id = ".$post_id." AND field_name = '{$field_name}' ORDER BY order_id ASC");
b2cb842 @hunk add all files
hunk authored
176
abeef31 @chuyskywalker The non-glorious work of getting the code base switched over to tabs …
chuyskywalker authored
177 foreach($elements as $element){
178 $order[] = $element->group_count;
179 }
180
181 return $order;
b2cb842 @hunk add all files
hunk authored
182 }
183
184 /**
185 * Return a array with the order of a field
186 */
29e33c5 @hunk get, get_image, get_audio and gen_image works outside WP loop
hunk authored
187 function getFieldOrder($field_name,$group=1,$post_id=NULL){
b2cb842 @hunk add all files
hunk authored
188 global $post,$wpdb;
189
29e33c5 @hunk get, get_image, get_audio and gen_image works outside WP loop
hunk authored
190 if(!$post_id){ $post_id = $post->ID; }
191 $elements = $wpdb->get_results("SELECT field_count FROM ".MF_TABLE_POST_META." WHERE post_id = ".$post_id." AND field_name = '{$field_name}' AND group_count = {$group} ORDER BY order_id DESC",ARRAY_A);
b2cb842 @hunk add all files
hunk authored
192
193 foreach($elements as $element){
194 $order[] = $element['field_count'];
195 }
196
197 $order = array_reverse($order);
198 sort($order);
199
200 return $order;
201 }
2137a50 @chuyskywalker add a function to pull the panel name for the current post
chuyskywalker authored
202 /**
203 * Return the name of the write panel the current post uses
204 *
205 * @param boolean $safe make the return name 'url safe'
206 */
207 function get_panel_name($safe=true)
208 {
209 global $wpdb, $post;
210
211 $panel_id = $wpdb->get_var("SELECT `meta_value` FROM {$wpdb->postmeta} WHERE post_id = ".$post->ID.' AND meta_key = "'.RC_CWP_POST_WRITE_PANEL_ID_META_KEY.'"');
212 if( (int) $panel_id == 0 )
213 return false;
214
215 $panel_name = $wpdb->get_var("SELECT `name` FROM ".MF_TABLE_PANELS." WHERE id = ".$panel_id);
216 if( ! $panel_name )
217 return false;
218
219 return ($safe) ? sanitize_title_with_dashes($panel_name) : $panel_name;
220 }
221
d074f8a @chuyskywalker combined both gen and get _image functions as there was a LOT of repe…
chuyskywalker authored
222 // Get Image.
223 function get_image ($fieldName, $groupIndex=1, $fieldIndex=1,$tag_img=1,$post_id=NULL,$override_params=NULL) {
224 return create_image(array(
225 'fieldName' => $fieldName,
226 'groupIndex' => $groupIndex,
227 'fieldIndex' => $fieldIndex,
228 'param' => $override_params,
229 'post_id' => $post_id,
230 'tag_img' => (boolean) $tag_img
231 ));
232 }
233
234 // generate image
235 function gen_image ($fieldName, $groupIndex=1, $fieldIndex=1,$param=NULL,$attr=NULL,$post_id=NULL) {
236 return create_image(array(
237 'fieldName' => $fieldName,
238 'groupIndex' => $groupIndex,
239 'fieldIndex' => $fieldIndex,
240 'param' => $param,
241 'attr' => $attr,
242 'post_id' => $post_id
243 ));
244 }
245
246 /*
247 * Generate an image from a field value
248 *
249 * Accepts a single options, an array of settings.
250 * These are the parameteres it supports:
251 *
252 * 'fieldName' => (string) the name of the field which holds the image value,
253 * 'groupIndex' => (int) which group set to display,
254 * 'fieldIndex' => (int) which field set to display,
38e6cb9 @chuyskywalker modifiying the image fnction to key off of arrays or strings
chuyskywalker authored
255 * 'param' => (string|array) a html parameter string to use with PHPThumb for the image, can also be a key/value array
d074f8a @chuyskywalker combined both gen and get _image functions as there was a LOT of repe…
chuyskywalker authored
256 * 'attr' => (array) an array of extra attributes and values for the image tag,
257 * 'post_id' => (int) a specific post id to fetch,
258 * 'tag_img' => (boolean) a flag to determine if an img tag should be created, or just return the link to the image file
259 *
260 */
261 function create_image($options)
262 {
263 require_once("RCCWP_CustomField.php");
2ac281e @hunk clean code
hunk authored
264 global $post;
d074f8a @chuyskywalker combined both gen and get _image functions as there was a LOT of repe…
chuyskywalker authored
265
266 // establish the default values, then override them with
267 // whatever the user has passed in
268 $options = array_merge(array(
269 // the default options
270 'fieldName' => '',
271 'groupIndex' => 1,
272 'fieldIndex' => 1,
273 'param' => NULL,
274 'attr' => NULL,
275 'post_id' => NULL,
276 'tag_img' => true
277 ), (array) $options);
278
279 // finally extract them into variables for this function
280 extract($options);
281
282 // check for a specified post id, or see if the $post global has one
082f43f @hunk fix in create_image (work outside loop and params phpthumb overwite)
hunk authored
283 if($post_id){
284 $post_id = $post_id;
285 }elseif(isset($post->ID)){
286 $post_id = $post->ID;
e696938 @hunk optimization: front-end function only 1 query [get, get_audio, get_im…
hunk authored
287 } else {
d074f8a @chuyskywalker combined both gen and get _image functions as there was a LOT of repe…
chuyskywalker authored
288 return false;
289 }
290
291 // basic check
292 if(empty($fieldName)) return FALSE;
293
e696938 @hunk optimization: front-end function only 1 query [get, get_audio, get_im…
hunk authored
294 $field = RCCWP_CustomField::GetDataField($fieldName,$groupIndex, $fieldIndex,$post_id);
d074f8a @chuyskywalker combined both gen and get _image functions as there was a LOT of repe…
chuyskywalker authored
295 if(!$field) return FALSE;
296
297 $fieldType = $field['type'];
298 $fieldID = $field['id'];
299 $fieldCSS = $field['CSS'];
300 $fieldObject = $field['properties'];
e696938 @hunk optimization: front-end function only 1 query [get, get_audio, get_im…
hunk authored
301 $fieldValue = $field['meta_value'];
d074f8a @chuyskywalker combined both gen and get _image functions as there was a LOT of repe…
chuyskywalker authored
302
e696938 @hunk optimization: front-end function only 1 query [get, get_audio, get_im…
hunk authored
303 if(empty($fieldValue)) return "";
d074f8a @chuyskywalker combined both gen and get _image functions as there was a LOT of repe…
chuyskywalker authored
304
305 // override the default phpthumb parameters if needed
abeef31 @chuyskywalker The non-glorious work of getting the code base switched over to tabs …
chuyskywalker authored
306 // works with both strings and arrays
d074f8a @chuyskywalker combined both gen and get _image functions as there was a LOT of repe…
chuyskywalker authored
307 if(!empty($param)) {
abeef31 @chuyskywalker The non-glorious work of getting the code base switched over to tabs …
chuyskywalker authored
308 if(is_array($param)){
309 $p = array();
310 foreach($param as $k => $v){
311 $p[] = $k."=".$v;
312 }
313 $fieldObject['params'] = implode('&', $p);
314 } else {
315 $fieldObject['params'] = $param;
316 }
d074f8a @chuyskywalker combined both gen and get _image functions as there was a LOT of repe…
chuyskywalker authored
317 }
318 // remove the ? on the params if it happened to be there
319 if (substr($fieldObject['params'], 0, 1) == "?"){
320 $fieldObject['params'] = substr($fieldObject['params'], 1);
321 }
322
323 // check if exist params, if not exist params, return original image
324 if (empty($fieldObject['params']) && (FALSE === strstr($fieldValue, "&"))){
325 $fieldValue = MF_FILES_URI.$fieldValue;
082f43f @hunk fix in create_image (work outside loop and params phpthumb overwite)
hunk authored
326 }else{
d074f8a @chuyskywalker combined both gen and get _image functions as there was a LOT of repe…
chuyskywalker authored
327 //check if exist thumb image, if exist return thumb image
328 $md5_params = md5($fieldObject['params']);
329 if (file_exists(MF_FILES_PATH.'th_'.$md5_params."_".$fieldValue)) {
330 $fieldValue = MF_FILES_URI.'th_'.$md5_params."_".$fieldValue;
331 }else{
332 //generate thumb
333 include_once(dirname(__FILE__)."/thirdparty/phpthumb/phpthumb.class.php");
334 $phpThumb = new phpThumb();
335 $phpThumb->setSourceFilename(MF_FILES_PATH.$fieldValue);
336 $create_md5_filename = 'th_'.$md5_params."_".$fieldValue;
337 $output_filename = MF_FILES_PATH.$create_md5_filename;
338 $final_filename = MF_FILES_URI.$create_md5_filename;
339
340 $params_image = explode("&",$fieldObject['params']);
341 foreach($params_image as $param){
342 if($param){
343 $p_image=explode("=",$param);
344 $phpThumb->setParameter($p_image[0], $p_image[1]);
345 }
346 }
347 if ($phpThumb->GenerateThumbnail()) {
348 if ($phpThumb->RenderToFile($output_filename)) {
349 $fieldValue = $final_filename;
350 }
351 }
352 }
353 }
354
355 if($tag_img){
356 // make sure the attributes are an array
357 if( !is_array($attr) ) $attr = (array) $attr;
358
359 // we're generating an image tag, but there MAY be a default class.
360 // if one was defined, however, override it
361 if( !isset($attr['class']) && !empty($fieldCSS) )
362 $attr['class'] = $fieldCSS;
363
364 // ok, put it together now
365 if(count($attr)){
366 foreach($attr as $k => $v){
367 $add_attr .= $k."='".$v."' ";
368 }
369 $finalString = "<img src='".$fieldValue."' ".$add_attr." />";
370 }else{
371 $finalString = "<img src='".$fieldValue."' />";
abeef31 @chuyskywalker The non-glorious work of getting the code base switched over to tabs …
chuyskywalker authored
372 }
d074f8a @chuyskywalker combined both gen and get _image functions as there was a LOT of repe…
chuyskywalker authored
373 }else{
374 $finalString = $fieldValue;
375 }
376 return $finalString;
377 }
378
8f5a306 @hunk add two new function get_label and get_group
hunk authored
379 function get_group($name_group,$post_id=NULL){
2ac281e @hunk clean code
hunk authored
380 global $wpdb, $post, $FIELD_TYPES;
8f5a306 @hunk add two new function get_label and get_group
hunk authored
381
382 if(!$post_id){ $post_id = $post->ID; }
383
384 $sql = "SELECT pm.field_name, cf.type, pm_wp.meta_value, pm.order_id, pm.field_count, cf.id, fp.properties
385 FROM ".MF_TABLE_POST_META." pm, ".MF_TABLE_PANEL_GROUPS." g, {$wpdb->postmeta} pm_wp,
386 ".MF_TABLE_GROUP_FIELDS." cf
387 LEFT JOIN ".MF_TABLE_CUSTOM_FIELD_PROPERTIES." fp ON fp.custom_field_id = cf.id
388 WHERE pm_wp.post_id = {$post_id} AND cf.name = pm.field_name AND cf.group_id=g.id AND
79e7f30 @hunk fix in get_field_duplicate and get_group (not return fields empty) an…
hunk authored
389 g.name='$name_group' AND pm_wp.meta_id=pm.id AND pm_wp.meta_value <> ''
8f5a306 @hunk add two new function get_label and get_group
hunk authored
390 ORDER BY pm.order_id, cf.display_order, pm.field_count";
391 $data_groups = $wpdb->get_results($sql);
392
393 $info = null;
394 foreach($data_groups as $data){
395 switch($data->type){
396 case $FIELD_TYPES["textbox"]:
397 case $FIELD_TYPES["radiobutton_list"]:
398 case $FIELD_TYPES["dropdown_list"]:
399 case $FIELD_TYPES["color_picker"]:
400 case $FIELD_TYPES["slider"]:
401 $info[$data->order_id][$data->field_name][$data->field_count] = $data->meta_value;
402 break;
403 case $FIELD_TYPES['multiline_textbox']:
404 $info[$data->order_id][$data->field_name][$data->field_count] = apply_filters('the_content', $data->meta_value);
405 break;
406 case $FIELD_TYPES["checkbox"]:
407 if ($data->meta_value == 'true') $fieldValue = 1; else $fieldValue = 0;
408 $info[$data->order_id][$data->field_name][$data->field_count] = $fieldValue;
409 break;
410 case $FIELD_TYPES["checkbox_list"]:
411 case $FIELD_TYPES["listbox"]:
412 $info[$data->order_id][$data->field_name][$data->field_count] = unserialize($data->meta_value);
413 break;
414 case $FIELD_TYPES["audio"]:
415 case $FIELD_TYPES["file"]:
416 if ($data->meta_value != ""){ $fieldValue = MF_FILES_URI.$data->meta_value;}else{$fieldValue= null;}
417 $info[$data->order_id][$data->field_name][$data->field_count] = $fieldValue;
418 break;
419 case $FIELD_TYPES['image']:
420 if($data->meta_value != ""){
421 $format = unserialize($data->properties);
422 if($format) $info[$data->order_id][$data->field_name][$data->field_count]['t'] = aux_image($data->meta_value,$format['params']);
423 $info[$data->order_id][$data->field_name][$data->field_count]['o'] = MF_FILES_URI.$data->meta_value;
424 }
425 break;
426 case $FIELD_TYPES['date']:
427 $format = unserialize($data->properties);
428 $fieldValue = GetProcessedFieldValue($data->meta_value, $data->type, $format);
429 $info[$data->order_id][$data->field_name][$data->field_count] = $fieldValue;
430 break;
431 }
432 }
433 return $info;
434 }
435
436 function aux_image($fieldValue,$params_image){
437 $md5_params = md5($params_image);
438 if (file_exists(MF_FILES_PATH.'th_'.$md5_params."_".$fieldValue)) {
439 $fieldValue = MF_FILES_URI.'th_'.$md5_params."_".$fieldValue;
440 }else{
441 //generate thumb
442 include_once(dirname(__FILE__)."/thirdparty/phpthumb/phpthumb.class.php");
443 $phpThumb = new phpThumb();
444 $phpThumb->setSourceFilename(MF_FILES_PATH.$fieldValue);
445 $create_md5_filename = 'th_'.$md5_params."_".$fieldValue;
446 $output_filename = MF_FILES_PATH.$create_md5_filename;
447 $final_filename = MF_FILES_URI.$create_md5_filename;
448
449 $params_image = explode("&",$params_image);
450 foreach($params_image as $param){
451 if($param){
452 $p_image=explode("=",$param);
453 $phpThumb->setParameter($p_image[0], $p_image[1]);
454 }
455 }
456 if ($phpThumb->GenerateThumbnail()) {
457 if ($phpThumb->RenderToFile($output_filename)) {
458 $fieldValue = $final_filename;
459 }
460 }
461 }
462 return $fieldValue;
463 }
464
465 function get_label($fieldName,$post_id=NULL) {
466 require_once("RCCWP_CustomField.php");
2ac281e @hunk clean code
hunk authored
467 global $post;
8f5a306 @hunk add two new function get_label and get_group
hunk authored
468
469 if(!$post_id){ $post_id = $post->ID; }
470
471 $field = RCCWP_CustomField::GetInfoByName($fieldName,$post_id);
472 if(!$field) return FALSE;
473 return $field['description'];
474 }
d4708d4 @hunk add function get_field_duplicate, this function return one array with…
hunk authored
475
476 function get_field_duplicate($fieldName, $groupIndex=1,$post_id=NULL){
477 global $wpdb, $post, $FIELD_TYPES;
478
479 if(!$post_id){ $post_id = $post->ID; }
480
481 $sql = "SELECT pm.field_name, cf.type, pm_wp.meta_value, pm.order_id, pm.field_count, cf.id, fp.properties
482 FROM ".MF_TABLE_POST_META." pm, ".MF_TABLE_PANEL_GROUPS." g, {$wpdb->postmeta} pm_wp,
483 ".MF_TABLE_GROUP_FIELDS." cf
484 LEFT JOIN ".MF_TABLE_CUSTOM_FIELD_PROPERTIES." fp ON fp.custom_field_id = cf.id
485 WHERE pm_wp.post_id = {$post_id} AND cf.name = pm.field_name AND cf.group_id=g.id AND
79e7f30 @hunk fix in get_field_duplicate and get_group (not return fields empty) an…
hunk authored
486 pm_wp.meta_id=pm.id AND pm.field_name='$fieldName' AND pm.group_count = $groupIndex
487 AND pm_wp.meta_value <> ''
d4708d4 @hunk add function get_field_duplicate, this function return one array with…
hunk authored
488 ORDER BY pm.order_id, cf.display_order, pm.field_count";
79e7f30 @hunk fix in get_field_duplicate and get_group (not return fields empty) an…
hunk authored
489
d4708d4 @hunk add function get_field_duplicate, this function return one array with…
hunk authored
490 $data_fields = $wpdb->get_results($sql);
491
492 $info = null;
493 foreach($data_fields as $data){
494 switch($data->type){
495 case $FIELD_TYPES["textbox"]:
496 case $FIELD_TYPES["radiobutton_list"]:
497 case $FIELD_TYPES["dropdown_list"]:
498 case $FIELD_TYPES["color_picker"]:
499 case $FIELD_TYPES["slider"]:
500 $info[$data->field_count] = $data->meta_value;
501 break;
502 case $FIELD_TYPES['multiline_textbox']:
503 $info[$data->field_count] = apply_filters('the_content', $data->meta_value);
504 break;
505 case $FIELD_TYPES["checkbox"]:
506 if ($data->meta_value == 'true') $fieldValue = 1; else $fieldValue = 0;
507 $info[$data->field_count] = $fieldValue;
508 break;
509 case $FIELD_TYPES["checkbox_list"]:
510 case $FIELD_TYPES["listbox"]:
511 $info[$data->field_count] = unserialize($data->meta_value);
512 break;
513 case $FIELD_TYPES["audio"]:
514 case $FIELD_TYPES["file"]:
515 if ($data->meta_value != ""){ $fieldValue = MF_FILES_URI.$data->meta_value;}else{$fieldValue= null;}
516 $info[$data->field_count] = $fieldValue;
517 break;
518 case $FIELD_TYPES['image']:
519 if($data->meta_value != ""){
520 $format = unserialize($data->properties);
521 if($format) $info[$data->field_count]['t'] = aux_image($data->meta_value,$format['params']);
522 $info[$data->field_count]['o'] = MF_FILES_URI.$data->meta_value;
523 }
524 break;
525 case $FIELD_TYPES['date']:
526 $format = unserialize($data->properties);
527 $fieldValue = GetProcessedFieldValue($data->meta_value, $data->type, $format);
528 $info[$data->field_count] = $fieldValue;
529 break;
530 }
531 }
532 return $info;
533 }
Something went wrong with that request. Please try again.