forked from ahrencode/Audacity-of-Tanish-for-WP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
406 lines (334 loc) · 12.8 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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<?php
if( ! is_array(get_option('tanish')) )
add_option('tanish', array('init' => 1));
$options = get_option('tanish');
# defaults
if( ! isset($options['showauthors' ]) ) $options['showauthors' ] = 0;
if( ! isset($options['expandfirst' ]) ) $options['expandfirst' ] = 0;
if( ! isset($options['showcredits' ]) ) $options['showcredits' ] = 1;
if( ! isset($options['hidecomments']) ) $options['hidecomments'] = 0;
if( ! isset($options['mainbgimage' ]) ) $options['mainbgimage' ] = 'None';
if( ! isset($options['mainbgtile' ]) ) $options['mainbgtile' ] = 'None';
if( ! isset($options['iewarn' ]) ) $options['iewarn' ] = 0;
# end defaults
update_option('tanish', $options);
# setup admin menu
add_action('admin_menu', 'tanish_admin_menu');
if ( function_exists('register_sidebar') )
add_sidebars();
//-------------------------------------------------------------------------------
function tanish_admin_menu()
{
add_theme_page('Tanish Options', 'Tanish Options', 'edit_themes', "AudacityofTanish", 'tanish_options');
}
//-------------------------------------------------------------------------------
function tanish_options()
{
global $options;
if( $_POST['action'] == 'save' )
save_options();
print options_followinfo();
print
"
<form id='settings' action='' method='post' class='themeform'
style='margin: 20px;'>
<h3>Customise this Theme</h3>
Want to customise this theme? Don't edit the stylesheets or PHP files
of this theme using the Theme Editor. Why not? Because when you use
the WP upgrade mechanism to upgrade this theme, it blows away all your
changes. The/One right way to customise themes is to create a 'child
theme' -- that will be a feature available in an upcoming release of
this theme. In the meantime, if you want to do the manual work, please
<a href='http://ahren.org/code/contact'>contact me</a> for
instructions.
<h3>General</h3>
<input type='hidden' id='action' name='action' value='save'>
<input type='checkbox' name='showauthors' id='showauthors'" .
($options['showauthors'] == 1 ? ' checked' : '') . " />
<label style='margin-left: 5px;' for='showauthors'>Show Authors in Sidebar</label>
<br />
<input type='checkbox' name='expandfirst' id='expandfirst'" .
($options['expandfirst'] == 1 ? ' checked' : '') . " />
<label style='margin-left: 5px;' for='expandfirst'>
In home page (posts mode) expand top most (latest) post
</label>
<br />
<input type='checkbox' name='showcredits' id='showcredits'" .
($options['showcredits'] == 1 ? ' checked' : '') . " />
<label style='margin-left: 5px;' for='showcredits'>
Show credits at the bottom
</label>
<br />
<input type='checkbox' name='hidecomments' id='hidecomments'" .
($options['hidecomments'] == 1 ? ' checked' : '') . " />
<label style='margin-left: 5px;' for='hidecomments'>
Make comments collapsible/expandable on posts/pages
</label>
<br />
<input type='checkbox' name='iewarn' id='iewarn'" .
($options['iewarn'] == 1 ? ' checked' : '') . " />
<label style='margin-left: 5px;' for='iewarn'>
Offer helpful upgrade suggestions to Internet Explorer users ;-)
</label>
<br/>
<br/>
<h3>Background Images</h3>
<label for='mainbgtile'>Choose background (tile):</label><br />
"
. images_dir_html("bgtile", 4, 'mainbgtile') .
"
<label for='mainbgimage'>Choose background image:</label><br />
"
. images_dir_html("bgimage", 4, 'mainbgimage') .
"
</div>
<br clear='all' />
<br/>
<hr size='1'/>
<p class='submit'><input type='submit' value='Save Changes' name='save'/></p>
</form>
<div style='
width: 60%;
margin: 30px 0px;
background-color: #cceeff;
border: 1px solid #88bbcc;
padding: 30px;'
>
All graphics and libraries (jQuery and derivatives)
used in this theme are released by their respective authors as
either free (for unlimited free or commercial use, without
need for attribution), or under the GPL. Many thanks are owed to
them for their contribution to the public domain.
<br/>
</div>
";
}
//------------------------------------------------------------------------------
function options_followinfo()
{
return("
<div style=
'
clear: right;
float: right;
margin: 10px 10px 10px 20px;
background-color: #fff3cc;
color: #000000;
padding: 10px 15px;
border: 2px solid #ddc055; width: 25%;
width: 150px;
'
>
<h3>Keep up with Audacity of Tanish</h3>
<p>
Follow on Twitter, or join the Facebook Page. Subscribe to the blog.
Create bug/feature requests, download the latest code, and more!
</p>
<ul>
<li style='list-style-type: circle; margin-left: 10px;'>
Blog:
<ul>
<li><a href='http://ahren.org/code/tag/tanish-wp'>Audacity of Tanish</a></li>
<li><a href='http://ahren.org/code/'>Ahren Code</a></li>
</ul>
</li>
<li style='list-style-type: circle; margin-left: 10px;'>
Twitter:
<ul>
<li><a href='http://search.twitter.com/search?q=%23tanish-wp'>Audacity of Tanish</a></li>
<li><a href='http://twitter.com/ahrencode/'>Ahren Code</a></li>
</ul>
</li>
<li style='list-style-type: circle; margin-left: 10px;'>
<a
href='http://www.facebook.com/home.php#/pages/Ahren-Code/64305786260'>Facebook</a>
</li>
<li style='list-style-type: circle; margin-left: 10px;'>
<a href='http://github.com/ahrencode/Audacity-of-Tanish-for-WP/issues'>
Changes, Bugs and Features</a>
</li>
</ul>
</div>
");
}
//------------------------------------------------------------------------------
function images_dir_html($dir, $count, $fldname)
{
global $options;
$html =
"
<br/>
<div style=
'
float: left;
padding: 15px;
background-color: #eeeeee;
color: #000000;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
'
>
";
$ctr = $count - 2;
foreach( array_merge(array("None", "Random"), scandir(TEMPLATEPATH . "/images/" . $dir)) as $image )
{
if( $image == '.' || $image == '..' )
continue;
if( $ctr > 0 && ($ctr % $count) == 0 )
$html .= "<br /><br />\n";
$ctr++;
$checked = "";
if( $options[$fldname] == $image )
$checked = "checked";
$html .= "<input type='radio' name='$fldname' id='$fldname$ctr' value='$image' $checked>";
if( $image == "None" || $image == "Random" )
$html .= $image;
else
$html .=
"
<label for='$fldname$ctr'>
<img alt='$image' title='$image' height='64' width='64' align='middle'
src='" . get_bloginfo('template_directory') . "/images/$dir/$image' />
</label>
";
$html .= " ";
}
$html .=
"
</div>
<br clear='left' />
<br />
";
return($html);
}
//------------------------------------------------------------------------------
function comments_hide_html()
{
global $options;
if( $options['hidecomments'] != 1 )
return;
// Could check for is_single() or some such here but do we really
// save much by doing so? The logic is safe even without the check
// since the jQuery will fire only for #single.
print
"
<style type='text/css'>
#commentsheader
{
cursor: pointer;
}
#commentscontainer
{
display: none;
}
</style>
<script language='JavaScript'>
$(document).ready
(
function()
{
$('#commentsheader').click(function() { $('#commentscontainer').toggle(500); });
}
);
</script>
";
}
//------------------------------------------------------------------------------
function bg_images_css($selector, $optname, $imgdir, $pos_repeat)
{
global $options;
$image = $options[$optname];
if( $image == 'None' )
return;
if( $image == "Random" )
{
$images = preg_grep("/^\./", scandir(TEMPLATEPATH . "/images/" . $imgdir), PREG_GREP_INVERT);
$randidx = rand(2, sizeof($images)-1);
$image = $images[$randidx];
}
// the v=$randidx below is because Firefox refuses to reload a background image
// unless the URL has changed.
return
("
$selector
{
background: url(" . get_bloginfo('template_url') .
"/images/$imgdir/$image?v=$randidx) $pos_repeat;
}
");
}
//------------------------------------------------------------------------------
function save_options()
{
global $_POST, $options;
$options['showauthors' ] = ( isset($_POST['showauthors' ]) ) ? 1 : 0;
$options['expandfirst' ] = ( isset($_POST['expandfirst' ]) ) ? 1 : 0;
$options['showcredits' ] = ( isset($_POST['showcredits' ]) ) ? 1 : 0;
$options['hidecomments'] = ( isset($_POST['hidecomments']) ) ? 1 : 0;
$options['iewarn' ] = ( isset($_POST['iewarn' ]) ) ? 1 : 0;
$options['mainbgimage' ] = ( isset($_POST['mainbgimage' ]) ) ? $_POST['mainbgimage'] : "None";
$options['mainbgtile' ] = ( isset($_POST['mainbgtile' ]) ) ? $_POST['mainbgtile' ] : "None";
update_option('tanish', $options);
print
"
<div class='updated fade' id='message'
style='background-color: rgb(255, 251, 204);
width: 300px;
margin-top: 30px;
margin-left: 20px'>
<p>Tanish Settings <strong>saved</strong>.</p>
</div>
";
}
//------------------------------------------------------------------------------
function add_sidebars()
{
register_sidebar(array(
'name' => 'bottombarleft',
'before_widget' => "<div class='sidebarlist'>",
'before_title' => "<p class='sbtitle'>" .
"<img alt='' height='10' src='" .
get_bloginfo('template_directory') .
"/images/down.png' /> ",
'after_title' => "</p><span class='sbcontent'>",
'after_widget' => "</span></div>",
));
register_sidebar(array(
'name' => 'bottombarcenter',
'before_widget' => "<div class='sidebarlist'>",
'before_title' => "<p class='sbtitle'>" .
"<img alt='' height='10' src='" .
get_bloginfo('template_directory') .
"/images/down.png' /> ",
'after_title' => "</p><span class='sbcontent'>",
'after_widget' => "</span></div>",
));
register_sidebar(array(
'name' => 'bottombarright',
'before_widget' => "<div class='sidebarlist'>",
'before_title' => "<p class='sbtitle'>" .
"<img alt='' height='10' src='" .
get_bloginfo('template_directory') .
"/images/down.png' /> ",
'after_title' => "</p><span class='sbcontent'>",
'after_widget' => "</span></div>",
));
}
//------------------------------------------------------------------------------
function ac_admin_error($msg)
{
print
"
<div
style='background-color: #aa4400;
color: #ffffff;
border: 1px solid #660000;
padding: 3px 8px;
width: 300px;
margin-top: 30px;
margin-left: 20px'>
$msg
</div>
";
}
?>