-
Notifications
You must be signed in to change notification settings - Fork 7
/
get-custom.php
executable file
·343 lines (286 loc) · 11.8 KB
/
get-custom.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?php
/*
=>> Based on coffee2code: Visit the plugin's homepage for more information and latest updates <<=
http://www.coffee2code.com/wp-plugins/
Copyright (c) 2004-2005 by Scott Reilly (aka coffee2code)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
require_once 'RCCWP_Constant.php';
require_once 'tools/debug.php';
/**
* Get number of group duplicates given field name. The function returns 1
* if there are no duplicates (just the original group), 2 if there is one
* duplicate and so on.
*
* @param string $fieldName the name of any field in the group
* @return number of group duplicates
*/
function getGroupDuplicates ($fieldName) {
require_once("RCCWP_CustomField.php");
global $post;
return RCCWP_CustomField::GetFieldGroupDuplicates($post->ID, $fieldName);
}
/**
* Get number of field duplicates given field name and group duplicate index.
* The function returns 1 if there are no duplicates (just the original field),
* 2 if there is one duplicate and so on.
*
* @param string $fieldName
* @param integer $groupIndex
* @return number of field duplicates
*/
function getFieldDuplicates ($fieldName, $groupIndex) {
require_once("RCCWP_CustomField.php");
global $post;
return RCCWP_CustomField::GetFieldDuplicates($post->ID, $fieldName, $groupIndex);
}
/**
* Get the value of an input field.
*
* @param string $fieldName
* @param integer $groupIndex
* @param integer $fieldIndex
* @param boolean $readyForEIP if true and the field type is textbox or
* multiline textbox, the resulting value will be wrapped
* in a div that is ready for EIP. The default value is true
* @return a string or array based on field type
*/
function get ($fieldName, $groupIndex=1, $fieldIndex=1, $readyForEIP=true) {
require_once("RCCWP_CustomField.php");
global $wpdb, $post, $FIELD_TYPES;
$fieldID = RCCWP_CustomField::GetIDByName($fieldName);
$fieldObject = GetFieldInfo($fieldID);
$fieldType = $wpdb->get_var("SELECT type FROM ".RC_CWP_TABLE_GROUP_FIELDS." WHERE id='".$fieldID."'");
$single = true;
switch($fieldType){
case $FIELD_TYPES["checkbox_list"]:
case $FIELD_TYPES["listbox"]:
$single = false;
break;
}
$fieldValues = (array) RCCWP_CustomField::GetCustomFieldValues($single, $post->ID, $fieldName, $groupIndex, $fieldIndex);
$fieldMetaID = RCCWP_CustomField::GetMetaID($post->ID, $fieldName, $groupIndex, $fieldIndex);
$results = GetProcessedFieldValue($fieldValues, $fieldType, $fieldObject->properties);
// Prepare fields for EIP
include_once('RCCWP_Options.php');
$enableEditnplace = RCCWP_Options::Get('enable-editnplace');
if ($readyForEIP && $enableEditnplace == 1 && current_user_can('edit_posts', $post->ID)){
switch($fieldType){
case $FIELD_TYPES["textbox"]:
if(!$results) $results=" ";
$results = "<div class='".EIP_textbox($fieldMetaID)."' >".$results."</div>";
break;
case $FIELD_TYPES["multiline_textbox"]:
if(!$results) $results=" ";
$results = "<div class='".EIP_mulittextbox($fieldMetaID)."' >".$results."</div>";
break;
}
}
return $results;
}
function GetProcessedFieldValue($fieldValues, $fieldType, $fieldProperties=array()){
global $FIELD_TYPES;
$results = array();
$fieldValues = (array) $fieldValues;
foreach($fieldValues as $fieldValue){
switch($fieldType){
case $FIELD_TYPES["audio"]:
case $FIELD_TYPES["file"]:
case $FIELD_TYPES["image"]:
if ($fieldValue != "") $fieldValue = FLUTTER_URI.'files_flutter/'.$fieldValue;
break;
case $FIELD_TYPES["checkbox"]:
if ($fieldValue == 'true') $fieldValue = true; else $fieldValue = false;
break;
case $FIELD_TYPES["date"]:
$fieldValue = date($fieldProperties['format'],strtotime($fieldValue));
break;
}
array_push($results, $fieldValue);
}
// Return array or single value based on field
switch($fieldType){
case $FIELD_TYPES["checkbox_list"]:
case $FIELD_TYPES["listbox"]:
return $results;
break;
}
if (count($results) == 0 )
return "";
else
return $results[0];
}
// Get Image.
function get_image ($fieldName, $groupIndex=1, $fieldIndex=1,$tag_img=1) {
require_once("RCCWP_CustomField.php");
global $wpdb, $post, $FIELD_TYPES;
$fieldID = RCCWP_CustomField::GetIDByName($fieldName);
$fieldObject = GetFieldInfo($fieldID);
$fieldType = $wpdb->get_var("SELECT type FROM ".RC_CWP_TABLE_GROUP_FIELDS." WHERE id='".$fieldID."'");
$single = true;
switch($fieldType){
case $FIELD_TYPES["checkbox_list"]:
case $FIELD_TYPES["listbox"]:
$single = false;
break;
}
$fieldValues = (array) RCCWP_CustomField::GetCustomFieldValues($single, $post->ID, $fieldName, $groupIndex, $fieldIndex);
if(!empty($fieldValues[0]))
$fieldValue = $fieldValues[0];
else
return "";
if (substr($fieldObject->properties['params'], 0, 1) == "?"){
$fieldObject->properties['params'] = substr($fieldObject->properties['params'], 1);
}
if (empty($fieldObject->properties['params']) && (FALSE == strstr($fieldValue, "&"))){
$fieldValue = '../../files_flutter/'.$fieldValue;
}
else{
$path = "../../files_flutter/";
$fieldValue = $path.$fieldValue.$fieldObject->properties['params'];
}
$fieldValue= PHPTHUMB."?src=".$fieldValue;
if($tag_img){
$cssClass = $wpdb->get_results("SELECT CSS FROM ".RC_CWP_TABLE_GROUP_FIELDS." WHERE name='".$fieldName."'");
if (empty($cssClass[0]->CSS)){
$finalString = stripslashes(trim("\<img src=\'".$fieldValue."\' /\>"));
}
else{
$finalString = stripslashes(trim("\<img src=\'".$fieldValue."\' class=\"".$cssClass[0]->CSS."\" \/\>"));
}
}else{
$finalString=$fieldValue;
}
return $finalString;
}
// Get Audio.
function get_audio ($fieldName, $groupIndex=1, $fieldIndex=1) {
require_once("RCCWP_CustomField.php");
global $wpdb, $post, $FIELD_TYPES;
$fieldID = RCCWP_CustomField::GetIDByName($fieldName);
$fieldObject = GetFieldInfo($fieldID);
$fieldType = $wpdb->get_var("SELECT type FROM ".RC_CWP_TABLE_GROUP_FIELDS." WHERE id='".$fieldID."'");
$single = true;
switch($fieldType){
case $FIELD_TYPES["checkbox_list"]:
case $FIELD_TYPES["listbox"]:
$single = false;
break;
}
$fieldValues = (array) RCCWP_CustomField::GetCustomFieldValues($single, $post->ID, $fieldName, $groupIndex, $fieldIndex);
if(!empty($fieldValues))
$fieldValue = $fieldValues[0];
else
return "";
$path = FLUTTER_URI.'files_flutter/';
$fieldValue = $path.$fieldValue;
$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=\'".FLUTTER_URI."js/singlemp3player.swf?file=".urlencode($fieldValue)."\' wmode=\'transparent\' /\>\<param name=\'quality\' value=\'high\' wmode=\'transparent\' /\>\<embed src=\'".FLUTTER_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\>"));
return $finalString;
}
// This works outside "the loop"
function c2c_get_recent_custom ($field, $before='', $after='', $none='', $between=', ', $before_last='', $limit=1, $unique=false, $order='DESC', $include_static=true, $show_pass_post=false) {
global $wpdb;
if (empty($between)) $limit = 1;
if ($order != 'ASC') $order = 'DESC';
$now = current_time('mysql');
$sql = "SELECT ";
if ($unique) $sql .= "DISTINCT ";
$sql .= "meta_value FROM $wpdb->posts AS posts, $wpdb->postmeta AS postmeta ";
$sql .= "WHERE posts.ID = postmeta.post_id AND postmeta.meta_key = '$field' ";
$sql .= "AND ( posts.post_status = 'publish' ";
if ($include_static) $sql .= " OR posts.post_status = 'static' ";
$sql .= " ) AND posts.post_date < '$now' ";
if (!$show_pass_post) $sql .= "AND posts.post_password = '' ";
$sql .= "AND postmeta.meta_value != '' ";
$sql .= "ORDER BY posts.post_date $order LIMIT $limit";
$results = array(); $values = array();
$results = $wpdb->get_results($sql);
if (!empty($results))
foreach ($results as $result) { $values[] = $result->meta_value; };
return c2c__format_custom($field, $values, $before, $after, $none, $between, $before_last);
} //end c2c_get_recent_custom()
/* Helper function */
function c2c__format_custom ($field, $meta_values, $before='', $after='', $none='', $between='', $before_last='') {
$values = array();
if (empty($between)) $meta_values = array_slice($meta_values,0,1);
if (!empty($meta_values))
foreach ($meta_values as $meta) {
$meta = apply_filters("the_meta_$field", $meta);
$values[] = apply_filters('the_meta', $meta);
}
if (empty($values)) $value = '';
else {
$values = array_map('trim', $values);
if (empty($before_last)) $value = implode($values, $between);
else {
switch ($size = sizeof($values)) {
case 1:
$value = $values[0];
break;
case 2:
$value = $values[0] . $before_last . $values[1];
break;
default:
$value = implode(array_slice($values,0,$size-1), $between) . $before_last . $values[$size-1];
}
}
}
if (empty($value)) {
if (empty($none)) return;
$value = $none;
}
return $before . $value . $after;
} //end c2c__format_custom()
function GetFieldInfo($customFieldId)
{
global $wpdb;
$sql = "SELECT properties FROM " . RC_CWP_TABLE_CUSTOM_FIELD_PROPERTIES .
" WHERE custom_field_id = '" . $customFieldId."'";
$results = $wpdb->get_row($sql);
//$results->options = unserialize($results->options);
$results->properties = unserialize($results->properties);
//$results->default_value = unserialize($results->default_value);
return $results;
}
function pt(){
return PHPTHUMB;
}
/**
* Return the value for the layout option
*
*
* @param string $option_name
*
*/
function option($variable_name){
global $wpdb;
$template = get_option('template'); //template name
$module_id = $wpdb->get_var("SELECT block_id FROM ".FLUTTER_TABLE_LAYOUT_MODULES." WHERE theme = '{$template}'"); //module_id to the template
//getting the value
$value = $wpdb->get_var( "SELECT value FROM ".FLUTTER_TABLE_LAYOUT_VARIABLES.
" WHERE parent = {$module_id} and variable_name = '{$variable_name}'"
);
return $value;
}
/**
* Return a array with the all values in one array
*
* @param string $groupName
*/
function getGroupOrder(){
global $post,$wpdb;
$elements = $wpdb->get_results("SELECT group_count FROM ".RC_CWP_TABLE_POST_META." WHERE post_id = ".$post->ID." ORDER BY order_id ASC");
foreach($elements as $element){
$order[] = $element->group_count;
}
return $order;
}
?>