source: trunk/www.guidonia.net/wp/wp-content/plugins/wordpress-mobile-edition/carrington-mobile-1.0.2/carrington-core/admin.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 9.8 KB
Line 
1<?php
2
3// This file is part of the Carrington Theme Framework for WordPress
4// http://carringtontheme.com
5//
6// Copyright (c) 2008-2009 Crowd Favorite, Ltd. All rights reserved.
7// http://crowdfavorite.com
8//
9// Released under the GPL license
10// http://www.opensource.org/licenses/gpl-license.php
11//
12// **********************************************************************
13// This program is distributed in the hope that it will be useful, but
14// WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16// **********************************************************************
17
18if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) { die(); }
19
20// - add admin page for config settings
21
22function cfct_admin_menu() {
23 if (!current_user_can('manage_options')) {
24 return;
25 }
26 add_submenu_page(
27 'themes.php'
28 , __('Carrington Settings', 'carrington')
29 , __('Carrington', 'carrington')
30 , 0
31 , 'carrington-settings'
32 , 'cfct_settings_form'
33 );
34}
35add_action('admin_menu', 'cfct_admin_menu');
36
37function cfct_admin_request_handler() {
38 if (isset($_POST['cf_action'])) {
39 switch ($_POST['cf_action']) {
40 case 'cfct_update_settings':
41 call_user_func($_POST['cf_action']);
42 wp_redirect(trailingslashit(get_bloginfo('wpurl')).'wp-admin/themes.php?page=carrington-settings&updated=true');
43 }
44 }
45}
46
47function cfct_update_settings() {
48 if (!current_user_can('manage_options')) {
49 return;
50 }
51 global $cfct_options;
52 foreach ($cfct_options as $option) {
53 if (isset($_POST[$option])) {
54 update_option($option, stripslashes($_POST[$option]));
55 }
56 }
57 do_action('cfct_update_settings');
58}
59
60function cfct_settings_form() {
61 if (isset($_GET['updated'])) {
62 print('
63<div id="message" class="updated fade">
64 <p>'.__('Settings updated.', 'carrington').'</p>
65</div>
66 ');
67 }
68 print('
69<div class="wrap">
70 <h2>'.__('Carrington Settings', 'carrington').'</h2>
71 <form action="options.php" method="post">
72 ');
73 do_action('cfct_settings_form_top');
74 print('
75 <table class="form-table">
76 <tbody>'
77// .cfct_options_home_column('1')
78// .cfct_options_home_column('2')
79// .cfct_options_home_column('3')
80 .cfct_options_misc()
81 .'</tbody>
82 </table>
83 ');
84 do_action('cfct_settings_form_bottom');
85 do_action('cfct_settings_form');
86 print('
87 <p class="submit" style="padding-left: 230px;">
88 <input type="hidden" name="cf_action" value="cfct_update_settings" />
89 <input type="submit" name="submit_button" class="button-primary" value="'.__('Save Changes', 'carrington').'" />
90 </p>
91 </form>
92</div>
93 ');
94 do_action('cfct_settings_form_after');
95}
96
97function cfct_options_home_column($key) {
98 $categories = get_categories('hide_empty=0');
99 $cat_options = '';
100 foreach ($categories as $category) {
101 if ($category->term_id == get_option('cfct_home_col_'.$key.'_cat')) {
102 $selected = 'selected="selected"';
103 }
104 else {
105 $selected = '';
106 }
107 $cat_options .= "\n\t<option value='$category->term_id' $selected>$category->name</option>";
108 }
109 $show_options = '';
110 $show_option = cfct_get_option('cfct_home_column_'.$key.'_content');
111 if ($show_option == 'latest') {
112 $latest_selected = 'selected="selected"';
113 $list_selected = '';
114 }
115 else {
116 $latest_selected = '';
117 $list_selected = 'selected="selected"';
118 }
119 $html = '
120 <tr valign="top">
121 <th scope="row">'.sprintf(__('Home Column %s', 'carrington'), $key).'</td>
122 <td>
123 <fieldset>
124 <p>
125 <label for="cfct_home_column_'.$key.'_cat">'.__('Category:', 'carrington').'</label>
126 <select name="cfct_home_column_'.$key.'_cat" id="cfct_home_column_'.$key.'_cat">'.$cat_options.'</select>
127 </p>
128 <p>
129 <label for="cfct_home_column_'.$key.'_content">'.__('Show:', 'carrington').'</label>
130 <select name="cfct_home_column_'.$key.'_content" id="cfct_home_column_'.$key.'_content" class="home_column_select">
131 <option value="latest" '.$latest_selected.'>'.__('Latest Post Preview', 'carrington').'</option>
132 <option value="list" '.$list_selected.'>'.__('List of Recent Post Titles', 'carrington').'</option>
133 </select>
134 </p>
135 <p id="cfct_latest_limit_'.$key.'_option" class="hidden">
136 <label for="cfct_latest_limit_'.$key.'">'.__('Length of preview, in characters (250 recommended):', 'carrington').'</label>
137 <input type="text" name="cfct_latest_limit_'.$key.'" id="cfct_latest_limit_'.$key.'" value="'.cfct_get_option('cfct_latest_limit_'.$key).'" />
138 </p>
139 <p id="cfct_list_limit_'.$key.'_option" class="hidden">
140 <label for="cfct_list_limit_'.$key.'">'.__('Number of titles to show in list (5 recommended):', 'carrington').'</label>
141 <input type="text" name="cfct_list_limit_'.$key.'" id="cfct_list_limit_'.$key.'" value="'.cfct_get_option('cfct_list_limit_'.$key).'" />
142 </p>
143 </fieldset>
144 </td>
145 </tr>
146 ';
147 return $html;
148}
149
150function cfct_options_misc() {
151 $options = array(
152 'yes' => __('Yes', 'carrington'),
153 'no' => __('No', 'carrington')
154 );
155 $credit_options = '';
156 foreach ($options as $k => $v) {
157 if ($k == get_option('cfct_credit')) {
158 $credit_selected = 'selected="selected"';
159 }
160 else {
161 $credit_selected = '';
162 }
163 $credit_options .= "\n\t<option value='$k' $credit_selected>$v</option>";
164 }
165 $html = '
166 <tr valign="top">
167 <th scope="row">'.sprintf(__('Misc.', 'carrington'), $key).'</td>
168 <td>
169 <fieldset>
170 <p>
171 <label for="cfct_about_text">'.__('About text (shown in sidebar):', 'carrington').'</label>
172 <br />
173 <textarea name="cfct_about_text" id="cfct_about_text" cols="40" rows="8">'.htmlspecialchars(get_option('cfct_about_text')).'</textarea>
174 </p>
175 <p>
176 <label for="cfct_wp_footer">'.__('Footer code (for analytics, etc.):', 'carrington').'</label>
177 <br />
178 <textarea name="cfct_wp_footer" id="cfct_wp_footer" cols="40" rows="5">'.htmlspecialchars(get_option('cfct_wp_footer')).'</textarea>
179 </p>
180 <p>
181 <label for="cfct_credit">'.__('Give <a href="http://crowdfavorite.com">Crowd Favorite</a> credit in footer:', 'carrington').'</label>
182 <select name="cfct_credit" id="cfct_credit">'.$credit_options.'</select>
183 </p>
184 </fieldset>
185 </td>
186 </tr>
187 ';
188 return $html;
189}
190
191function cfct_header_image_form() {
192 global $wpdb;
193
194 $images = $wpdb->get_results("
195 SELECT * FROM $wpdb->posts
196 WHERE post_type = 'attachment'
197 AND post_mime_type LIKE 'image%'
198 AND post_parent = 0
199 ORDER BY post_date_gmt DESC
200 LIMIT 50
201 ");
202 $upload_url = trailingslashit(get_bloginfo('wpurl')).'wp-admin/media-new.php';
203 $checked_attr = ' checked="checked"';
204 $output = '
205<ul style="width: '.((count($images) + 1) * 152).'px">
206 <li style="background: #666;">
207 <label for="cfct_header_image_0">
208 <input type="radio" name="cfct_header_image" value="0" id="cfct_header_image_0" '.$default_checked.'/>'.__('No Image', 'carrington-core').'
209 </label>
210 </li>
211 ';
212 if (count($images)) {
213 $header_image = get_option('cfct_header_image');
214 if (empty($header_image)) {
215 $header_image = 0;
216 $default_checked = $checked_attr;
217 }
218 else {
219 $default_checked = '';
220 }
221 foreach ($images as $image) {
222 $id = 'cfct_header_image_'.$image->ID;
223 $thumbnail = wp_get_attachment_image_src($image->ID);
224 $header_image == $image->ID ? $checked = $checked_attr : $checked = '';
225 $output .= '
226 <li style="background-image: url('.$thumbnail[0].')">
227 <label for="'.$id.'">
228 <input type="radio" name="cfct_header_image" value="'.$image->ID.'" id="'.$id.'"'.$checked.' />'.wp_specialchars($image->post_title).'
229 </label>
230 </li>';
231 }
232 }
233 $output .= '</ul>';
234 return '<p>'.sprintf(__('Header Image &mdash; <a href="%s">Upload Images</a>', 'carrington-core'), $upload_url).'</p><div class="cfct_header_image_carousel">'.$output.'</div>';
235}
236
237if (is_admin()) {
238 wp_enqueue_script('jquery-colorpicker', get_bloginfo('template_directory').'/carrington-core/js/colorpicker.js', array('jquery'), '1.0');
239// removing until we drop 2.5 compatibility
240// wp_enqueue_style('jquery-colorpicker', get_bloginfo('template_directory').'/carrington-core/css/colorpicker.css');
241}
242
243function cfct_admin_head() {
244// see enqueued style above, we'll activate that in the future
245 if ($_GET['page'] == 'carrington-settings') {
246 echo '
247<link rel="stylesheet" type="text/css" media="screen" href="'.get_bloginfo('template_directory').'/carrington-core/css/colorpicker.css" />
248 ';
249 cfct_admin_css();
250 }
251// cfct_admin_js();
252}
253add_action('admin_head', 'cfct_admin_head');
254
255function cfct_admin_css() {
256?>
257<style type="text/css">
258div.cfct_header_image_carousel {
259 height: 170px;
260 overflow: auto;
261 width: 600px;
262}
263div.cfct_header_image_carousel ul {
264 height: 150px;
265}
266div.cfct_header_image_carousel li {
267 background: #fff url() center center no-repeat;
268 float: left;
269 height: 150px;
270 margin-right: 2px;
271 overflow: hidden;
272 position: relative;
273 width: 150px;
274}
275div.cfct_header_image_carousel li label {
276 background: #000;
277 color: #fff;
278 display: block;
279 height: 50px;
280 line-height: 25px;
281 overflow: hidden;
282 position: absolute;
283 top: 110px;
284 width: 150px;
285 filter:alpha(opacity=75);
286 -moz-opacity:.75;
287 opacity:.75;
288}
289div.cfct_header_image_carousel li label input {
290 margin: 0 5px;
291}
292</style>
293<?php
294}
295
296function cfct_admin_js() {
297?>
298<script type="text/javascript">
299jQuery(function() {
300 jQuery('select.home_column_select').each(function() {
301 cfct_home_columns(jQuery(this), false);
302 }).change(function() {
303 cfct_home_columns(jQuery(this), true);
304 });
305});
306
307function cfct_home_columns(elem, slide) {
308 var id = elem.attr('id').replace('cfct_home_column_', '').replace('_content', '');
309 var val = elem.val();
310 var option_show = '#cfct_latest_limit_' + id + '_option';
311 var option_hide = '#cfct_list_limit_' + id + '_option';
312 if (val == 'list') {
313 option_show = '#cfct_list_limit_' + id + '_option';
314 option_hide = '#cfct_latest_limit_' + id + '_option';
315 }
316 if (slide) {
317 jQuery(option_hide).slideUp(function() {
318 jQuery(option_show).slideDown();
319 });
320 }
321 else {
322 jQuery(option_show).show();
323 jQuery(option_hide).hide();
324 }
325}
326</script>
327<?php
328}
329
330?>
Note: See TracBrowser for help on using the repository browser.