/
functions.php
executable file
·385 lines (310 loc) · 11.3 KB
/
functions.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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<?php
// helper functions
if ( function_exists('wp_list_bookmarks') ) //used to check WP 2.1 or not
$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type='post' and post_status = 'publish'");
else
$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
if (0 < $numposts) $numposts = number_format($numposts);
$numcmnts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
if (0 < $numcmnts) $numcmnts = number_format($numcmnts);
function find_category_by_name($name){
$cat = null;
$category_ids = get_all_category_ids();
foreach($category_ids as $cat_id) {
if(!strcmp(get_cat_name($cat_id), "Blog")){
$cat = $cat_id;
}
}
return $cat;
}
// ----------------
// For backward Compatiblity to older versions of WordPress
add_filter( 'comments_template', 'legacy_comments' );
function legacy_comments( $file ) {
if ( !function_exists('wp_list_comments') )
$file = TEMPLATEPATH . '/old-comments.php';
return $file;
}
if ( function_exists('register_sidebar') ){
register_sidebar(array(
'name' => 'side_box',
'before_widget' => '<li class="sidebox">',
'after_widget' => '</li>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
register_sidebar(array(
'name' => 'top_list',
'before_widget' => '<div class="topbar_widget">',
'after_widget' => '</div>',
'before_title' => '<!--',
'after_title' => '-->',
));
register_sidebar(array(
'name' => 'bottom_bar',
'before_widget' => '<div class="bottom_bar_widget">',
'after_widget' => '</div>',
'before_title' => '<div class="bottom_bar_title">',
'after_title' => '</div>',
));
}
if ( function_exists('unregister_sidebar_widget') )
{
unregister_sidebar_widget( __('Links') );
}
if ( function_exists('register_sidebar_widget') )
{
register_sidebar_widget(__('Links'), 'mistylook_ShowLinks');
}
if ( function_exists('register_sidebar_widget') )
{
register_sidebar_widget(__('About'), 'mistylook_ShowAbout');
}
function mistylook_ShowAbout() {?>
<li class="sidebox">
<h3><?php _e('About','ml');?></h3>
<p>
<img src="<?php bloginfo('stylesheet_directory');?>/img/profile.jpg" alt="<?php _e('Profile','ml');?>" /><br/>
<strong><?php bloginfo('name');?></strong><br/><?php bloginfo('description');?><br/>
<?php _e('There are','ml');?> <?php global $numposts;echo $numposts; ?> <?php _e('Posts and','ml');?> <?php global $numcmnts;echo $numcmnts;?> <?php _e('Comments so far.','ml');?>
</p>
</li>
<?php }
function mistylook_ShowRecentPosts() {?>
<li class="sidebox">
<h3><?php _e('Recent Posts','ml');?></h3>
<ul><?php wp_get_archives('type=postbypost&limit=6');?></ul>
</li>
<?php }
function mistylook_ShowLinks() {?>
<li class="sidebox" id="sidelinks">
<ul>
<?php
if(function_exists('wp_list_bookmarks'))
{
wp_list_bookmarks();
}
else
{
get_links_list('name');
}
?>
</ul>
</li>
<?php }
function mistylook_add_theme_page() {
if ( $_GET['page'] == basename(__FILE__) ) {
// save settings
if ( 'save' == $_REQUEST['action'] ) {
update_option( 'mistylook_asideid', $_REQUEST[ 's_asideid' ] );
update_option( 'mistylook_sortpages', $_REQUEST[ 's_sortpages' ] );
if( isset( $_POST[ 'excludepages' ] ) ) { update_option( 'mistylook_excludepages', implode(',', $_POST['excludepages']) ); } else { delete_option( 'mistylook_excludepages' ); }
// goto theme edit page
header("Location: themes.php?page=functions.php&saved=true");
die;
// reset settings
} else if( 'reset' == $_REQUEST['action'] ) {
delete_option( 'mistylook_asideid' );
delete_option( 'mistylook_sortpages' );
delete_option( 'mistylook_excludepages' );
// goto theme edit page
header("Location: themes.php?page=functions.php&reset=true");
die;
}
}
add_theme_page(__("MistyLook Options",'ml'), __("MistyLook Options",'ml'), 'edit_themes', basename(__FILE__), 'mistylook_theme_page');
}
function mistylook_theme_page() {
// --------------------------
// MistyLook theme page content
// --------------------------
if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.__('MistyLook Theme: Settings saved.','ml').'</strong></p></div>';
if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.__('MistyLook Theme: Settings reset.','ml').'</strong></p></div>';
?>
<style>
.wrap { border:#ccc 1px dashed;padding:10px;}
.block { margin:1em;padding:1em;line-height:1.6em;}
table tr td {border:#ddd 1px solid;padding:10px;font-family:Verdana, Arial, Serif;font-size:0.9em;}
h4 {font-size:1.3em;color:#265e15;font-weight:bold;margin:0;padding:10px 0;}
</style>
<div class="wrap">
<h2>MistyLook 3.7.2</h2>
<div class="block"><h4><?php _e('Theme Page:','ml');?> <a href="http://wpthemes.info/misty-look/">MistyLook</a> </h4>
<h4><?php _e('Designed & Coded by:','ml');?><a href="http://wprocks.com/" title="WordPress Rocks!" target="_blank">Sadish Bala</a></h4>
</div>
<form method="post">
<!-- blog layout options -->
<fieldset class="options">
<legend><?php _e('Theme Settings','ml');?></legend>
<p><?php _e('Change the way your blog looks and acts with the many blog settings below','ml');?></p>
<table width="100%" cellspacing="5" cellpadding="10" class="editform">
<tr>
<td valign="top" colspan="2" style="border:0px;margin:0;padding:0;">
<input type="hidden" name="action" value="save" />
<?php ml_input( "save", "submit", "", __("Save Settings",'ml') );?>
</td>
</tr>
<tr valign="top">
<td align="left">
<?php
ml_heading(__("List Pages / Navigation",'ml'));
global $wpdb;
if (function_exists('wp_list_bookmarks')) //WP 2.1 or greater
$results = $wpdb->get_results("SELECT ID, post_title from $wpdb->posts WHERE post_type='page' AND post_parent=0 ORDER BY post_title");
else
$results = $wpdb->get_results("SELECT ID, post_title from $wpdb->posts WHERE post_status='static' AND post_parent=0 ORDER BY post_title");
$excludepages = explode(',', get_settings('mistylook_excludepages'));
if($results) {
echo "<br/>";_e('Exclude the Following Pages from the Top Navigation','ml');echo "<br/><br/>";
foreach($results as $page)
{
echo '<input type="checkbox" name="excludepages[]" value="' . $page->ID . '"';
if(in_array($page->ID, $excludepages)==true) { echo ' checked="checked"'; }
echo ' /> <a href="' . get_permalink($page->ID) . '">' . $page->post_title . '</a><br />';
}
}
echo '<br/><br/>';
echo "<br/><strong> ";_e('Sort the List Pages by','ml');echo " </strong><br/>";
ml_input( "s_sortpages", "radio", __("Page Title ?",'ml'), "post_title", get_settings( 'mistylook_sortpages' ) );
ml_input( "s_sortpages", "radio", __("Date ?",'ml'), "post_date", get_settings( 'mistylook_sortpages' ) );
ml_input( "s_sortpages", "radio", __("Page Order ?",'ml'), "menu_order", get_settings( 'mistylook_sortpages' ) );
_e("(Each Page can be given a page order number, from the wordpress admin, edit page area)",'ml');
echo "<br/>";
?>
</td>
<td>
<?php
ml_heading( __("Support for Asides / Side Notes",'ml') );
_e("Asides are the 'quick bits' of information you want to post. They do not have to look like a regular post.",'ml');
echo "<br/><br/>"; _e('Learn More at','ml'); echo " <a href='http://photomatt.net/2004/05/19/asides/'>Matt's Asides technique</a>";
?>
<?php
global $wpdb;
$id = get_option('mistylook_asideid');
$defaults = array(
'show_option_all' => '', 'show_option_none' => '',
'orderby' => 'ID', 'order' => 'ASC',
'show_last_update' => 0, 'show_count' => 0,
'hide_empty' => 1, 'child_of' => 0,
'exclude' => '', 'echo' => 1,
'selected' => 0, 'hierarchical' => 0,
'name' => 'cat', 'class' => 'postform'
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
$asides_cats = get_categories($r);
?>
<p><?php _e('Select the category here. Any posts under this category will look like an Aside.','ml');?></p>
<select name="s_asideid" id="s_asideid">
<option value="0"><?php _e('NOT SELECTED','ml');?></option>
<?php
foreach ($asides_cats as $cat) {
if ($id == $cat->cat_ID)
{
$sIsSelected = "selected='true'";
}
else
{
$sIsSelected = "";
}
echo '<option value="' . $cat->cat_ID . '"'. $sIsSelected. '>' . $cat->cat_name . '</option>';
}?>
</select>
</td>
</td>
</tr>
<tr>
<td valign="top" colspan="2" style="border:0px;margin:0;padding:0;">
<input type="hidden" name="action" value="save" />
<?php ml_input( "save", "submit", "", __("Save Settings",'ml') );?>
</td>
</tr>
</table>
</fieldset>
</form>
<form method="post">
<fieldset class="options">
<legend><?php _e('Reset','ml');?></legend>
<p><?php _e('If for some reason you want to uninstall MistyLook then press the reset button to clean things up in the database.','ml');?></p>
<p><?php _e('You have to make sure to delete the theme folder, if you want to completely remove the theme.','ml');?></p>
<?php
ml_input( "reset", "submit", "", __("Reset Settings",'ml') );
?>
</div>
<input type="hidden" name="action" value="reset" />
</form>
<?php
}
add_action('admin_menu', 'mistylook_add_theme_page');
function ml_input( $var, $type, $description = "", $value = "", $selected="" ) {
// ------------------------
// add a form input control
// ------------------------
echo "\n";
switch( $type ){
case "text":
echo "<input name=\"$var\" id=\"$var\" type=\"$type\" style=\"width: 60%\" class=\"textbox\" value=\"$value\" />";
break;
case "submit":
echo "<p class=\"submit\"><input name=\"$var\" type=\"$type\" value=\"$value\" /></p>";
break;
case "option":
if( $selected == $value ) { $extra = "selected=\"true\""; }
echo "<option value=\"$value\" $extra >$description</option>";
break;
case "radio":
if( $selected == $value ) { $extra = "checked=\"true\""; }
echo "<label><input name=\"$var\" id=\"$var\" type=\"$type\" value=\"$value\" $extra /> $description</label><br/>";
break;
case "checkbox":
if( $selected == $value ) { $extra = "checked=\"true\""; }
echo "<label for=\"$var\"><input name=\"$var\" id=\"$var\" type=\"$type\" value=\"$value\" $extra /> $description</label><br/>";
break;
case "textarea":
echo "<textarea name=\"$var\" id=\"$var\" style=\"width: 80%; height: 10em;\" class=\"code\">$value</textarea>";
break;
}
}
function ml_heading( $title ) {
// ------------------
// add a table header
// ------------------
echo "<h4>" .$title . "</h4>";
}
?>
<?php
define('HEADER_TEXTCOLOR', '');
define('HEADER_IMAGE', '%s/img/misty.jpg'); // %s is theme dir uri
define('HEADER_IMAGE_WIDTH', 760);
define('HEADER_IMAGE_HEIGHT', 200);
define( 'NO_HEADER_TEXT', true );
function mistylook_admin_header_style() {
?>
<style type="text/css">
#headimg {
background: url(<?php header_image() ?>) no-repeat;
}
#headimg {
height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
width: <?php echo HEADER_IMAGE_WIDTH; ?>px;
}
#headimg h1, #headimg #desc {
display: none;
}
</style>
<?php
}
function mistylook_header_style() {
?>
<style type="text/css">
#headerimage {
background: url(<?php header_image() ?>) no-repeat;
}
</style>
<?php
}
if ( function_exists('add_custom_image_header') ) {
add_custom_image_header('mistylook_header_style', 'mistylook_admin_header_style');
}
load_theme_textdomain('ml');
?>