root/afridex/plugins/fresh-page/backup_RCCWP_CustomField.php

Revision 21, 7.0 kB (checked in by admin, 18 years ago)
Line 
1<?php
2include_once('RC_Format.php');
3
4class RCCWP_CustomField
5{
6        function Create($customWritePanelId, $name, $description, $order = 1, $type, $options = null, $default_value = null, $properties = null)
7        {
8                global $wpdb;
9       
10                $sql = sprintf(
11                        "INSERT INTO " . RC_CWP_TABLE_PANEL_CUSTOM_FIELD .
12                        " (panel_id, name, description, display_order, type) values (%d, %s, %s, %d, %d)",
13                        $customWritePanelId,
14                        RC_Format::TextToSql($name),
15                        RC_Format::TextToSql($description),
16                        $order,
17                        $type
18                        );
19                $wpdb->query($sql);
20               
21                $customFieldId = $wpdb->insert_id;
22               
23                $field_type = RCCWP_CustomField::GetCustomFieldTypes($type);
24                if ($field_type->has_options == "true")
25                {
26                        $options = explode("\n", $options);
27                        array_walk($options, array(RC_Format, TrimArrayValues));
28                       
29                        $default_value = explode("\n", $default_value);
30                        array_walk($default_value, array(RC_Format, TrimArrayValues));
31                       
32                        $sql = sprintf(
33                                "INSERT INTO " . RC_CWP_TABLE_CUSTOM_FIELD_OPTIONS .
34                                " (custom_field_id, options, default_option) values (%d, %s, %s)",
35                                $customFieldId,
36                                RC_Format::TextToSql(serialize($options)),
37                                RC_Format::TextToSql(serialize($default_value))
38                                );     
39                        $wpdb->query($sql);     
40                }
41               
42                if ($field_type->has_properties == "true")
43                {
44                        $sql = sprintf(
45                                "INSERT INTO " . RC_CWP_TABLE_CUSTOM_FIELD_PROPERTIES .
46                                " (custom_field_id, properties) values (%d, %s)",
47                                $customFieldId,
48                                RC_Format::TextToSql(serialize($properties))
49                                );     
50                        $wpdb->query($sql);     
51                }
52        }
53       
54        function Delete($customFieldId = null)
55        {
56                global $wpdb;
57               
58                $customField = RCCWP_CustomField::Get($customFieldId);
59               
60                $sql = sprintf(
61                        "DELETE FROM " . RC_CWP_TABLE_PANEL_CUSTOM_FIELD .
62                        " WHERE id = %d",
63                        $customFieldId
64                        );
65                $wpdb->query($sql);
66               
67                if ($customField->has_options == "true")
68                {
69                        $sql = sprintf(
70                                "DELETE FROM " . RC_CWP_TABLE_CUSTOM_FIELD_OPTIONS .
71                                " WHERE custom_field_id = %d",
72                                $customFieldId
73                                );     
74                        $wpdb->query($sql);     
75                }
76        }
77       
78        function Get($customFieldId)
79        {
80                global $wpdb;
81                $sql = "SELECT cf.id, cf.name, tt.name AS type, cf.description, cf.display_order, co.options, co.default_option AS default_value, tt.has_options, cp.properties, tt.has_properties, tt.allow_multiple_values FROM " . RC_CWP_TABLE_PANEL_CUSTOM_FIELD .
82                        " cf LEFT JOIN " . RC_CWP_TABLE_CUSTOM_FIELD_OPTIONS . " co ON cf.id = co.custom_field_id" .
83                        " LEFT JOIN " . RC_CWP_TABLE_CUSTOM_FIELD_PROPERTIES . " cp ON cf.id = cp.custom_field_id" .
84                        " JOIN " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " tt ON cf.type = tt.id" . 
85                        " WHERE cf.id = " . $customFieldId;
86                $results = $wpdb->get_row($sql);
87                       
88                $results->options = unserialize($results->options);
89                $results->properties = unserialize($results->properties);
90                $results->default_value = unserialize($results->default_value);
91                return $results;
92        }
93       
94        function GetCustomFieldNames($customFieldTypeId = null)
95        {
96                $customFieldNames = array();
97                $customFields = RCCWP_CustomField::GetCustomFieldTypes($customFieldTypeId);
98                foreach ($customFields as $field)
99                {
100                        $customFieldNames[] = $field->name;
101                }
102               
103                return $customFieldNames;
104        }
105       
106        function GetCustomFieldTypes($customFieldTypeId = null)
107        {
108                global $wpdb;
109       
110                if (isset($customFieldTypeId))
111                {
112                        $sql = "SELECT id, name, description, has_options, has_properties, allow_multiple_values FROM " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES .
113                                " WHERE id = " . (int)$customFieldTypeId;
114                        $results = $wpdb->get_row($sql);       
115                }
116                else
117                {
118                        $sql = "SELECT id, name, description, has_options, has_properties, allow_multiple_values FROM " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES;
119                        $results = $wpdb->get_results($sql);
120                        if (!isset($results))
121                                $results = array();
122                }
123                return $results;
124        }
125       
126        function GetCustomFieldValue($postId, $customFieldName)
127        {
128                return get_post_meta($postId, $customFieldName, true);
129        }
130       
131        function GetCustomFieldValues($postId, $customFieldName)
132        {
133                return get_post_meta($postId, $customFieldName, false);
134        }
135       
136        function GetDefaultCustomFieldType()
137        {
138                return 'Textbox';
139        }
140       
141        function GetOptions()
142        {
143
144        }
145
146        function GetProperties()
147        {
148
149        }
150       
151        function Update($customFieldId, $name, $description, $order = 1, $type, $options = null, $default_value = null, $properties = null)
152        {
153                global $wpdb;
154               
155                $oldCustomField = RCCWP_CustomField::Get($customFieldId);
156               
157                if ($oldCustomField->name != $name)
158                {
159                        $sql = sprintf(
160                                "UPDATE $wpdb->postmeta" .
161                                " SET meta_key = %s" .
162                                " WHERE meta_key = %s",
163                                RC_Format::TextToSql($name),
164                                RC_Format::TextToSql($oldCustomField->name)
165                                );
166                       
167                        $wpdb->query($sql);
168                }
169               
170                $sql = sprintf(
171                        "UPDATE " . RC_CWP_TABLE_PANEL_CUSTOM_FIELD .
172                        " SET name = %s" .
173                        " , description = %s" .
174                        " , display_order = %d" .
175                        " , type = %d" .
176                        " WHERE id = %d",
177                        RC_Format::TextToSql($name),
178                        RC_Format::TextToSql($description),
179                        $order,
180                        $type,
181                        $customFieldId
182                        );
183                $wpdb->query($sql);
184
185
186                $field_type = RCCWP_CustomField::GetCustomFieldTypes($type);
187                if ($field_type->has_options == "true")
188                {
189                        $options = explode("\n", $options);
190                        array_walk($options, array(RC_Format, TrimArrayValues));
191                       
192                        $default_value = explode("\n", $default_value);
193                        array_walk($default_value, array(RC_Format, TrimArrayValues));
194                       
195                        $sql = sprintf(
196                                "INSERT INTO " . RC_CWP_TABLE_CUSTOM_FIELD_OPTIONS .
197                                " (custom_field_id, options, default_option) values (%d, %s, %s)" . 
198                                " ON DUPLICATE KEY UPDATE options = %s, default_option = %s",
199                                $customFieldId,
200                                RC_Format::TextToSql(serialize($options)),
201                                RC_Format::TextToSql(serialize($default_value)),
202                                RC_Format::TextToSql(serialize($options)),
203                                RC_Format::TextToSql(serialize($default_value))
204                                );     
205                        $wpdb->query($sql);     
206                }
207                else
208                {
209                        $sql = sprintf(
210                                "DELETE FROM " . RC_CWP_TABLE_CUSTOM_FIELD_OPTIONS .
211                                " WHERE custom_field_id = %d",
212                                $customFieldId
213                                );
214                        $wpdb->query($sql);     
215                }
216               
217                if ($field_type->has_properties == "true")
218                {
219                        $sql = sprintf(
220                                "INSERT INTO " . RC_CWP_TABLE_CUSTOM_FIELD_PROPERTIES .
221                                " (custom_field_id, properties) values (%d, %s)" .
222                                " ON DUPLICATE KEY UPDATE properties = %s",
223                                $customFieldId,
224                                RC_Format::TextToSql(serialize($properties)),
225                                RC_Format::TextToSql(serialize($properties))
226                                );     
227                        $wpdb->query($sql);     
228                }
229                else
230                {
231                        $sql = sprintf(
232                                "DELETE FROM " . RC_CWP_TABLE_CUSTOM_FIELD_PROPERTIES .
233                                " WHERE custom_field_id = %d",
234                                $customFieldId
235                                );
236                        $wpdb->query($sql);     
237                }
238/*
239                if(isset($_POST['custom-photo-height']) && !empty($_POST['custom-photo-height']) && isset($_POST['custom-photo-width']) && !empty($_POST['custom-photo-width']))
240                {
241                        $prop = 'a:1:{s:6:"params";s:12:"&h='.$_POST['custom-photo-height'].'&w='.$_POST['custom-photo-width'].'";}';
242                        $sql = "UPDATE wp_rc_cwp_custom_field_properties SET properties='".$prop."' WHERE custom_field_id='".$_POST['custom-field-id']."'";
243                        $wpdb->query($sql);     
244               
245//echo "<pre>";
246//print_r($_POST);
247//die();
248
249                }*/
250        }
251}
252?>
Note: See TracBrowser for help on using the browser.