root/afridex/plugins/Flutter/get-custom.php @ 23

Revision 21, 10.4 kB (checked in by admin, 18 years ago)
Line 
1<?php
2/*
3
4=>> Based on coffee2code: Visit the plugin's homepage for more information and latest updates  <<=
5                http://www.coffee2code.com/wp-plugins/
6
7Copyright (c) 2004-2005 by Scott Reilly (aka coffee2code)
8
9Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
10files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
11modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
12Software is furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
19IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20*/
21
22
23require_once 'RCCWP_Constant.php';
24
25/**
26 * Get number of group duplicates given field name. The function returns 1
27 * if there are no duplicates (just the original group), 2 if there is one
28 * duplicate and so on.
29 *
30 * @param string $fieldName the name of any field in the group
31 * @return number of group duplicates
32 */
33function getGroupDuplicates ($fieldName) {
34        require_once("RCCWP_CustomField.php");
35        global $post;
36        return RCCWP_CustomField::GetFieldGroupDuplicates($post->ID, $fieldName);
37}
38
39/**
40 * Get number of field duplicates given field name and group duplicate index.
41 * The function returns 1 if there are no duplicates (just the original field),
42 * 2 if there is one duplicate and so on.
43 *
44 * @param string $fieldName
45 * @param integer $groupIndex
46 * @return number of field duplicates
47 */
48function getFieldDuplicates ($fieldName, $groupIndex) {
49        require_once("RCCWP_CustomField.php");
50        global $post;
51        return RCCWP_CustomField::GetFieldDuplicates($post->ID, $fieldName, $groupIndex);
52}
53
54/**
55 * Get the value of an input field.
56 *
57 * @param string $fieldName
58 * @param integer $groupIndex
59 * @param integer $fieldIndex
60 * @param boolean $readyForEIP if true and the field type is textbox or
61 *                              multiline textbox, the resulting value will be wrapped
62 *                              in a div that is ready for EIP. The default value is true
63 * @return a string or array based on field type
64 */
65function get ($fieldName, $groupIndex=1, $fieldIndex=1, $readyForEIP=true) {
66        require_once("RCCWP_CustomField.php");
67        global $wpdb, $post, $FIELD_TYPES;
68       
69        $fieldID = RCCWP_CustomField::GetIDByName($fieldName);
70        $fieldObject = GetFieldInfo($fieldID);
71        $fieldType = $wpdb->get_var("SELECT type FROM ".RC_CWP_TABLE_GROUP_FIELDS." WHERE id='".$fieldID."'");
72        $single = true;
73        switch($fieldType){
74                case $FIELD_TYPES["checkbox_list"]:
75                case $FIELD_TYPES["listbox"]:
76                        $single = false;
77                        break;
78        } 
79       
80        $fieldValues = (array) RCCWP_CustomField::GetCustomFieldValues($single, $post->ID, $fieldName, $groupIndex, $fieldIndex);
81        $fieldMetaID = RCCWP_CustomField::GetMetaID($post->ID, $fieldName, $groupIndex, $fieldIndex);
82       
83        $results = array();
84       
85        foreach($fieldValues as $fieldValue){
86       
87                switch($fieldType){
88                        case $FIELD_TYPES["audio"]:
89                        case $FIELD_TYPES["file"]:
90                        case $FIELD_TYPES["image"]:
91                                if ($fieldValue != "") $fieldValue = FLUTTER_URI.'files_flutter/'.$fieldValue;
92                                break;
93       
94                        case $FIELD_TYPES["checkbox"]:         
95                                if ($fieldValue == 'true')  $fieldValue = true; else $fieldValue = false; 
96                                break;
97       
98                        case $FIELD_TYPES["date"]: 
99                                $fieldValue = date($fieldObject->properties['format'],strtotime($fieldValue)); 
100                                break;
101                }
102               
103                array_push($results, $fieldValue); 
104        }
105       
106        // Return array or single value based on field
107        switch($fieldType){
108               
109                case $FIELD_TYPES["checkbox_list"]:
110                case $FIELD_TYPES["listbox"]:
111                        return $results;
112                        break;
113        }
114       
115        // Prepare fields for EIP
116        if ($readyForEIP){
117                switch($fieldType){
118                        case $FIELD_TYPES["textbox"]:
119                                $results[0] = "<div class='".EIP_textbox($fieldMetaID)."' >".$results[0]."</div>";
120                                break;
121                               
122                        case $FIELD_TYPES["multiline_textbox"]:
123                                $results[0] = "<div class='".EIP_mulittextbox($fieldMetaID)."' >".$results[0]."</div>";
124                                break;
125                }
126               
127        }
128
129        if (count($results) == 0 )
130                return "";
131        else
132                return $results[0];
133
134}
135
136// Get Image.
137function get_image ($fieldName, $groupIndex=1, $fieldIndex=1) {
138        require_once("RCCWP_CustomField.php");
139        global $wpdb, $post, $FIELD_TYPES;
140       
141        $fieldID = RCCWP_CustomField::GetIDByName($fieldName);
142        $fieldObject = GetFieldInfo($fieldID);
143        $fieldType = $wpdb->get_var("SELECT type FROM ".RC_CWP_TABLE_GROUP_FIELDS." WHERE id='".$fieldID."'");
144        $single = true;
145        switch($fieldType){
146                case $FIELD_TYPES["checkbox_list"]:
147                case $FIELD_TYPES["listbox"]:
148                        $single = false;
149                        break;
150        } 
151       
152        $fieldValues = (array) RCCWP_CustomField::GetCustomFieldValues($single, $post->ID, $fieldName, $groupIndex, $fieldIndex);
153         
154        if(!empty($fieldValues))
155                $fieldValue = $fieldValues[0];
156        else 
157                return "";
158       
159        if (substr($fieldObject->properties['params'], 0, 1) == "?"){
160                $fieldObject->properties['params'] = substr($fieldObject->properties['params'], 1);
161        }
162
163
164        if (empty($fieldObject->properties['params']) && (FALSE == strstr($fieldValue, "&"))){
165                $fieldValue = FLUTTER_URI.'files_flutter/'.$fieldValue; 
166        }
167        else{
168                $path = FLUTTER_URI.'phpThumb.php?src=files_flutter/';
169                $fieldValue = $path.$fieldValue.$fieldObject->properties['params'];
170        }
171
172        $cssClass = $wpdb->get_results("SELECT CSS FROM ".RC_CWP_TABLE_GROUP_FIELDS." WHERE name='".$field."'");
173        if (empty($cssClass[0]->CSS)){
174                $finalString = stripslashes(trim("\<img src=\'".$fieldValue."\' /\>"));
175        }
176        else{
177                $finalString = stripslashes(trim("\<img src=\'".$fieldValue."\' class=\"".$cssClass[0]->CSS."\" \/\>"));
178        }
179        return $finalString;
180}
181
182// Get Audio.
183function get_audio ($fieldName, $groupIndex=1, $fieldIndex=1) {
184        require_once("RCCWP_CustomField.php");
185        global $wpdb, $post, $FIELD_TYPES;
186       
187        $fieldID = RCCWP_CustomField::GetIDByName($fieldName);
188        $fieldObject = GetFieldInfo($fieldID);
189        $fieldType = $wpdb->get_var("SELECT type FROM ".RC_CWP_TABLE_GROUP_FIELDS." WHERE id='".$fieldID."'");
190        $single = true;
191        switch($fieldType){
192                case $FIELD_TYPES["checkbox_list"]:
193                case $FIELD_TYPES["listbox"]:
194                        $single = false;
195                        break;
196        } 
197       
198        $fieldValues = (array) RCCWP_CustomField::GetCustomFieldValues($single, $post->ID, $fieldName, $groupIndex, $fieldIndex);
199       
200        if(!empty($fieldValues))
201                $fieldValue = $fieldValues[0];
202        else 
203                return "";
204               
205        $path = FLUTTER_URI.'files_flutter/';
206        $fieldValue = $path.$fieldValue;
207        $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\>"));
208        return $finalString;
209}
210
211// This works outside "the loop"
212function c2c_get_recent_custom ($field, $before='', $after='', $none='', $between=', ', $before_last='', $limit=1, $unique=false, $order='DESC', $include_static=true, $show_pass_post=false) {
213        global $wpdb;
214        if (empty($between)) $limit = 1;
215        if ($order != 'ASC') $order = 'DESC';
216        $now = current_time('mysql');
217
218        $sql = "SELECT ";
219        if ($unique) $sql .= "DISTINCT ";
220        $sql .= "meta_value FROM $wpdb->posts AS posts, $wpdb->postmeta AS postmeta ";
221        $sql .= "WHERE posts.ID = postmeta.post_id AND postmeta.meta_key = '$field' ";
222        $sql .= "AND ( posts.post_status = 'publish' ";
223        if ($include_static) $sql .= " OR posts.post_status = 'static' ";
224        $sql .= " ) AND posts.post_date < '$now' ";
225        if (!$show_pass_post) $sql .= "AND posts.post_password = '' ";
226        $sql .= "AND postmeta.meta_value != '' ";
227        $sql .= "ORDER BY posts.post_date $order LIMIT $limit";
228        $results = array(); $values = array();
229        $results = $wpdb->get_results($sql);
230        if (!empty($results))
231                foreach ($results as $result) { $values[] = $result->meta_value; };
232        return c2c__format_custom($field, $values, $before, $after, $none, $between, $before_last);
233} //end c2c_get_recent_custom()
234
235/* Helper function */
236function c2c__format_custom ($field, $meta_values, $before='', $after='', $none='', $between='', $before_last='') {
237        $values = array();
238        if (empty($between)) $meta_values = array_slice($meta_values,0,1);
239        if (!empty($meta_values))
240                foreach ($meta_values as $meta) {
241                        $meta = apply_filters("the_meta_$field", $meta);
242                        $values[] = apply_filters('the_meta', $meta);
243                }
244
245        if (empty($values)) $value = '';
246        else {
247                $values = array_map('trim', $values);
248                if (empty($before_last)) $value = implode($values, $between);
249                else {
250                        switch ($size = sizeof($values)) {
251                                case 1:
252                                        $value = $values[0];
253                                        break;
254                                case 2:
255                                        $value = $values[0] . $before_last . $values[1];
256                                        break;
257                                default:
258                                        $value = implode(array_slice($values,0,$size-1), $between) . $before_last . $values[$size-1];
259                        }
260                }
261        }
262        if (empty($value)) {
263                if (empty($none)) return;
264                $value = $none;
265        }
266        return $before . $value . $after;
267} //end c2c__format_custom()
268
269function GetFieldInfo($customFieldId)
270        {
271                global $wpdb;
272                $sql = "SELECT properties FROM " . RC_CWP_TABLE_CUSTOM_FIELD_PROPERTIES  .
273                        " WHERE custom_field_id = " . $customFieldId;
274                $results = $wpdb->get_row($sql);
275                //$results->options = unserialize($results->options);
276                $results->properties = unserialize($results->properties);
277                //$results->default_value = unserialize($results->default_value);
278                return $results;
279        }
280
281// Some filters you may wish to perform: (these are filters typically done to 'the_content' (post content))
282//add_filter('the_meta', 'convert_chars');
283//add_filter('the_meta', 'wptexturize');
284
285// Other optional filters (you would need to obtain and activate these plugins before trying to use these)
286//add_filter('the_meta', 'c2c_hyperlink_urls', 9);
287//add_filter('the_meta', 'text_replace', 2);
288//add_filter('the_meta', 'textile', 6);
289
290?>
Note: See TracBrowser for help on using the browser.