-
Notifications
You must be signed in to change notification settings - Fork 7
/
functions.php
600 lines (526 loc) · 20.4 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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
<?php
/**
* @package WordPress
* @subpackage RawApps iPhone Theme
*/
automatic_feed_links();
//LOAD DEFAULTS IF NONE PRESENT
if(get_option('rt_appname') == NULL){
update_option('rt_appname','YOUR APP NAME');
}
if(get_option('rt_appdescriptiontitle') == NULL){
update_option('rt_appdescriptiontitle','HEADLINE');
}
if(get_option('rt_appdescription') == NULL){
update_option('rt_appdescription','Use the <a href="/wp-admin/admin.php?page=rt_handle">settings page</a> on the wordpress admin panel to customize your new theme!');
}
if(get_option('rt_bannerenable') == NULL){
update_option('rt_bannerenable','text');
}
if(get_option('rt_bannertext') == NULL){
update_option('rt_bannertext','LOGO TEXT');
}
if(get_option('rt_apporient') == NULL){
update_option('rt_apporient','vert');
}
if(get_option('rt_icon') == NULL){
update_option('rt_icon','');
}
if(get_option('rt_banner') == NULL){
update_option('rt_banner','');
}
if(get_option('rt_screens') == NULL){
update_option('rt_screens','');
}
include(dirname(__FILE__) .'/includes/widgets.php');
if ( function_exists('register_sidebar') ){
register_sidebar(array(
'name' => 'Bottom Left',
'id' => 'rtwid_bottomleft',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Bottom Right',
'id' => 'rtwid_bottomright',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
}
if ( is_admin() ){
add_action('save_post', 'rt_save_thumbnail', 1, 2);
add_action('admin_menu', 'rt_menu');
add_action('admin_menu', 'rt_add_uploadbox');
add_action('admin_init', 'rt_settings');
add_action('template_redirect', 'rt_templates');
if($_GET['reset']){
update_option( 'rt_testimonial', null);
}
if($_GET['delete']){
$existing = get_option('rt_screens');
if (!empty($existing)) {
foreach ($existing as &$value) {
if ($value['hash'] == $_GET['delete']) {
unset($existing[array_search($value,$existing)]);
}
}
}
update_option( 'rt_screens', $existing );
}
if($_GET['tdelete']){
$existing = get_option('rt_testimonial');
if (!empty($existing)) {
foreach ($existing as &$value) {
if ($value['hash'] == $_GET['tdelete']){
unset($existing[array_search($value,$existing)]);
}
}
}
update_option( 'rt_testimonial', $existing );
}
if($_GET['createcontact']){
$contact_page = get_page_by_title('Contact','ARRAY_A');
if ($contact_page === null){
rt_generate_contactpage();
}elseif($contact_page['post_status'] == "trash"){
wp_delete_post( $contact_page['ID'], true );
rt_generate_contactpage();
}
}
if($_GET['deletecontact']){
$contact_page = get_page_by_title('Contact','ARRAY_A');
if ($contact_page !== null){
wp_delete_post( $contact_page['ID'], true );
}
}
if($_GET['updated']){
}
} else {
}
function rt_save_thumbnail($post_id, $post) {
if ( !wp_verify_nonce( $_POST['rt_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
if ( 'page' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_page', $post->ID ))
return $post->ID;
} else {
if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;
}
$pdata = $_POST['rt_thumb'];
echo $pdata;
if( $post->post_type == 'revision' ) return;
if(get_post_meta($post->ID, 'rt_thumb', FALSE)) {
update_post_meta($post->ID, 'rt_thumb', $pdata);
} else {
add_post_meta($post->ID, 'rt_thumb', $pdata);
}
}
function rt_templates() {
include(TEMPLATEPATH . '/contact.php');
exit;
}
function rt_settings() {
register_setting( 'rt_options', 'rt_appname' );
register_setting( 'rt_options', 'rt_authorname' );
register_setting( 'rt_options', 'rt_authorcontact' );
register_setting( 'rt_options', 'rt_authortwitter' );
register_setting( 'rt_options', 'rt_appversion' );
register_setting( 'rt_options', 'rt_appprice' );
register_setting( 'rt_options', 'rt_appdescription' );
register_setting( 'rt_options', 'rt_appdescriptiontitle' );
register_setting( 'rt_options', 'rt_apporient' );
register_setting( 'rt_options', 'rt_appmediatype' );
register_setting( 'rt_options', 'rt_bannerenable' );
register_setting( 'rt_options', 'rt_bannertext' );
register_setting( 'rt_options', 'rt_ituneslink','rt_validate_itunes' );
register_setting( 'rt_options', 'rt_displaycat' );
register_setting( 'rt_options', 'rt_theme' );
register_setting( 'rt_video', 'rt_embedcode' );
register_setting( 'rt_icon', 'rt_icon', 'rt_upload_validate' );
register_setting( 'rt_banner', 'rt_banner', 'rt_validate_banner' );
register_setting( 'rt_screens', 'rt_screens', 'rt_upload_screens' );
register_setting( 'rt_testimonial', 'rt_testimonial', 'rt_validate_testimonial' );
register_setting( 'rt_testimonial', 'rt_testimonialsource' );
}
function rt_head() {
echo '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>' . "\n";
echo '<script type="text/javascript" src="'.get_bloginfo("template_directory").'/javascript/rt_slideshow.js"></script>' . "\n";
}
function rt_menu() {
add_menu_page('apptheme','RAWapps.com', 8, 'rt_handle', rt_options);
add_submenu_page('rt_handle', 'General Settings', 'Settings', 8, 'rt_handle', rt_options);
add_submenu_page('rt_handle', 'Application Media', 'Media', 8, 'rt_handle_images', rt_options_images);
add_submenu_page('rt_handle', 'Manage Testimonials', 'Testimonials', 8, 'rt_handle_testimonials', rt_options_testimonials);
}
function rt_generate_contactpage() {
if (function_exists('wpcf7')){
$contact_vars = array();
$contact_vars['post_title'] = 'Contact';
$contact_vars['post_content'] = '[contact-form 1 "Contact form 1"]';
$contact_vars['post_status'] = 'publish';
$contact_vars['post_author'] = 1;
$contact_vars['post_type'] = 'page';
wp_insert_post( $contact_vars );
}
}
function rt_upload_gettext($optname = 'rt_icon') {
$options = get_option($optname);
if ($file = $options['file']) {
// var_dump($file);
if(!strstr($file['error'],'Unable to create directory')){
echo "<img src='{$file['url']}' />";
}else{
echo "There was an error in uploading files to the wp-content folder, please check the folder permissions and try again.";
}
}
}
function rt_upload_getinput($optname = 'rt_icon') {
echo '<input type="file" name="'.$optname.'" size="40" />';
}
function rt_add_uploadbox() {
if( function_exists( 'add_meta_box' )) {
add_meta_box( 'rt_post_uploadbox', 'Post Thumbnail', 'rt_post_uploadbox', 'post', 'normal', 'high' );
}
}
function rt_post_uploadbox() {
global $post;
echo '<input type="hidden" name="rt_noncename" id="rt_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
?>
<p>
<label for="rt_thumb">Thumbnail URL</label>
<input style="width:99%;" class="code" type="text" id="rt_thumb" name="rt_thumb" value="<?php echo get_post_meta($post->ID, 'rt_thumb', true); ?>" />
<p><a href="media-upload.php?type=image&TB_iframe=true" id="add_image" class="thickbox" title="Add an Image" onclick="return false;">Upload an image</a></strong> and paste the URL here.</p>
</p>
<?php
}
//DISPLAY FUNCTIONS
function rt_render_appicon(){
$options = get_option('rt_icon');
if ($file = $options['file']) {
echo "<img src='{$file['url']}' />";
}
else{
echo "<div style='width:73px;height:73px;display:inline;'> </div>";
}
}
function rt_render_banner(){
$options = get_option('rt_banner');
if ($file = $options['file']) {
echo "<img src='{$file['url']}' />";
}
}
function rt_render_slider() {
$existing = array();
$existing = get_option('rt_screens');
echo "<div id='slider' class='".get_option("rt_apporient")."'><ul>";
if (!empty($existing)) {
foreach ($existing as $value) {
if (!$value['error']){
echo "<li><img src='{$value['url']}' /></li";
}
}
}
echo "</ul></div>";
}
function rt_render_testimonials() {
$existing = array();
$existing = get_option('rt_testimonial');
if (!empty($existing)) {
$value = $existing[array_rand($existing, 1)];
echo '<div class="rt_testimonial_text">"'.$value["text"].'"</div>';
echo '<div class="rt_testimonial_src"> - '.$value["source"].'</div>';
}
}
function rt_preview_screens() {
$existing = array();
$existing = get_option('rt_screens');
if (!empty($existing)) {
foreach ($existing as $value) {
if (!$value['error']){
echo "<div style='float:left;border:1px solid #ddd;padding:10px;background-color:white;margin-right:6px;'><img style='height:135px;width:90px;' src='{$value['url']}' /><div style='text-align:center;height:11px;'><a href='admin.php?page=".$_GET['page']."&delete={$value['hash']}'>Delete</a></div></div>";
}
}
}
}function rt_preview_testimonials() {
$existing = array();
$existing = get_option('rt_testimonial');
if (!empty($existing)) {
foreach ($existing as $value) {
echo '<tr valign="top">';
echo '<th scope="row">'.$value["source"].'</th>';
echo '<td>'.$value["text"].'<div><a href="admin.php?page='.$_GET['page'].'&tdelete='.$value['hash'].'">Delete</a></div></td>';
echo '</tr>';
}
}
}
//VALIDATION FUNCTIONS
function rt_validate_testimonial($input) {
$new = array();
$new['source'] = $_POST['rt_testimonialsource'];
$new['text'] = $_POST['rt_testimonial'];
$new['hash'] = substr(base64_encode($new['text']), -8, 6);
if (get_option('rt_testimonial')){
$testimonials = get_option('rt_testimonial');
}else{
$testimonials = array();
}
array_push($testimonials, $new);
//var_dump($input);
return $testimonials;
}
function rt_upload_validate($input,$optname = 'rt_icon') {
$newinput = array();
if ($_FILES[$optname]) {
$overrides = array('test_form' => false);
$file = wp_handle_upload($_FILES[$optname], $overrides);
$newinput['file'] = $file;
}
return $newinput;
}
function rt_validate_banner($input,$optname = 'rt_banner') {
$newinput = array();
if ($_FILES[$optname]) {
$overrides = array('test_form' => false);
$file = wp_handle_upload($_FILES[$optname], $overrides);
$newinput['file'] = $file;
}
return $newinput;
}
function rt_validate_itunes($input) {
$link = $input;
if(substr($link,0,7) == "http://"){
return $link;
}else{
return "http://".$link;
}
}
function rt_upload_screens() {
if (get_option('rt_screens')){
$existing = get_option('rt_screens');
}else{
$existing = array();
}
if ($_FILES['rt_screens']) {
$overrides = array('test_form' => false);
$file = wp_handle_upload($_FILES['rt_screens'], $overrides);
if (!$file['error']){
$file['hash'] = substr(base64_encode($file['url']), -8, 6);
array_push($existing, $file);
}
}
return $existing;
}
function rt_options() {
?>
<div class="wrap">
<h2>Theme Options</h2>
<p><img src="http://www.rawapps.com/wp-content/uploads/promoimages/themebanner.jpg"></p>
<p>This is the general settings for the RawApps iPhone theme, this and the other settings pages will help you configure your theme with all the available options.</p>
<form method="post" enctype="multipart/form-data" action="options.php">
<table class="form-table">
<tr valign="top">
<th scope="row">Application Name </th>
<td><input class="regular-text" type="text" name="rt_appname" value="<?php echo get_option('rt_appname'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Author Name </th>
<td><input class="regular-text" type="text" name="rt_authorname" value="<?php echo get_option('rt_authorname'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Headline</th>
<td><input class="regular-text" type="text" name="rt_appdescriptiontitle" value="<?php echo get_option('rt_appdescriptiontitle'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Description</th>
<td><textarea class="large-text" cols="50" rows="6" name="rt_appdescription"><?php echo get_option('rt_appdescription'); ?></textarea></td>
</tr>
</table>
<h3>Application Details</h3>
<p>Details about your actual application that will be used to better present your app.</p>
<table class="form-table">
<tr valign="top">
<th scope="row">Application Price </th>
<td><input type="text" name="rt_appprice" value="<?php echo get_option('rt_appprice'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Application Version </th>
<td><input type="text" name="rt_appversion" value="<?php echo get_option('rt_appversion'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">iTunes Link</th>
<td><input class="regular-text" type="text" name="rt_ituneslink" value="<?php echo get_option('rt_ituneslink'); ?>" /></td>
</tr>
</table>
<h3>Theme Settings</h3>
<p>Theme specific settings to customize the presentation and layout of your theme.</p>
<table class="form-table">
<tr valign="top">
<th scope="row">iPhone Orientation</th>
<td>
<select class="postform" id="rt_apporient" name="rt_apporient">
<option <?php if (get_option('rt_apporient') == 'vert'): ?>selected="selected"<?php endif;?> value="vert" >Vertical</option>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row">Header Type</th>
<td>
<select class="postform" id="rt_bannerenable" name="rt_bannerenable">
<option <?php if (get_option('rt_bannerenable') == 'text'): ?>selected="selected"<?php endif;?> value="text" >Text Title</option>
<option <?php if (get_option('rt_bannerenable') == 'image'): ?>selected="selected"<?php endif;?> value="image" >Image Logo</option>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row">Header Text</th>
<td>
<input type="text" class="regular-text" name="rt_bannertext" value="<?php echo get_option('rt_bannertext'); ?>" />
<p>If your Header Type is set to Image Logo, you can upload an image on the <a href="admin.php?page=rt_handle_images">media page</a>.</p>
</td>
</tr>
<tr valign="top">
<th scope="row">iPhone Display</th>
<td>
<select class="postform" id="rt_appmediatype" name="rt_appmediatype">
<option <?php if (get_option('rt_appmediatype') == 'slider'): ?>selected="selected"<?php endif;?> value="vslide" >Screenshot Slideshow</option>
</select>
<p>You can upload screenshots on the <a href="admin.php?page=rt_handle_images">media page</a>.</p>
</td>
</tr>
</table>
<h3>Contact Form 7 Settings</h3>
<p>Contact Form 7 is a very powerful and customizeable contact form. In order to use it's features you must <a href="http://wordpress.org/extend/plugins/contact-form-7/">download and install</a> the plugin seperately, it is not included in the theme by default. (Don't worry, it's free!)</p>
<?php if (function_exists('wpcf7')) { ?>
<table class="form-table">
<?php $contact_page = get_page_by_title('Contact','ARRAY_A');
if ($contact_page === null || $contact_page['post_status'] == "trash"){?>
<tr valign="top">
<th scope="row">Create Contact Page</th>
<td>
<p>If you do not already have a Contact Page, Apptheme can automatically attempt to create one for you with the default settings. You can later customize it to suit your needs with the very flexible Contact Form 7 plugin.</p>
<p>Ready? <a href="admin.php?page=<?php echo $_GET['page'];?>&createcontact=true">Create a Contact Page</a></p>
</td>
</tr>
<?php }else{?>
<tr valign="top">
<th scope="row">Delete Contact Page</th>
<td>
<p>It seems you have a contact page already set up, Apptheme can automatically delete your contact page if you no longer want it.</p>
<p><a href="admin.php?page=<?php echo $_GET['page'];?>&deletecontact=true">Delete my Contact Page</a> </p>
<p>NOTE: You can recreate the page, but custom modifications may be lost.</p>
</td>
</tr>
<?php }?>
<tr valign="top">
<th scope="row">Manage Contact Page</th>
<td>
<p>The Contact Form 7 plugin is very customizeable and has its own configuration page you can use to edit the form.</p>
<p><a href="admin.php?page=wpcf7">Contact Form 7 Configuration</a> </p>
</td>
</tr>
</table>
<?php }else{?>
<table class="form-table">
<tr valign="top">
<th scope="row">Install Plugin</th>
<td>
You must <a href="http://wordpress.org/extend/plugins/contact-form-7/">download and install</a> the Contact Form 7 plugin in order to use this feature.
</td>
</tr>
</table>
<?php }?>
<?php settings_fields('rt_options'); ?>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Settings') ?>" />
</p>
</form>
</div>
<?php
}
function rt_options_images() {
?>
<div class="wrap">
<h2>Theme Media</h2>
<p><img src="http://www.rawapps.com/wp-content/uploads/promoimages/themebanner.jpg"></p>
<form method="post" enctype="multipart/form-data" action="options.php">
<h3>Application Icon</h3>
<p>Your application icon is display on every page to the left of the content, it is automatically adjusted to 73 x 73 pixels. We recommend using an image this size or larger for best quality.</p>
<table class="form-table"><tbody><tr valign="top"><th scope="row">Change Application Icon</th><td><?php rt_upload_getinput(); ?><p><?php rt_upload_gettext(); ?></p></td></tr></tbody></table>
<?php settings_fields('rt_icon'); ?>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Update Icon') ?>" />
</p>
</form>
<form method="post" enctype="multipart/form-data" action="options.php">
<h3>Page Logo</h3>
<p>By default the area above the navigation uses text for the logo, you can upload an image here to use instead of the text.</p>
<table class="form-table"><tbody><tr valign="top"><th scope="row">Change Image</th><td><?php rt_upload_getinput('rt_banner'); ?><p><?php rt_upload_gettext('rt_banner'); ?></p></td></tr></tbody></table>
<?php settings_fields('rt_banner'); ?>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Update Logo') ?>" />
</p>
</form>
<form method="post" enctype="multipart/form-data" action="options.php">
<h3>Screenshots</h3>
<p>Uploading Screenshots adds them to the slideshow that appears on the iPhone, you can delete individual screenshots by clicking the delete label underneath.</p>
<table class="form-table"><tbody><tr valign="top"><th scope="row">Add Screenshot</th><td><?php rt_upload_getinput('rt_screens'); ?><p><?php rt_preview_screens(); ?></p></td></tr></tbody></table>
<?php settings_fields('rt_screens'); ?>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Add Screenshot') ?>" />
</p>
</form>
</div>
<?php
}
function rt_options_testimonials() {
?>
<div class="wrap">
<h2>Manage Testimonials</h2>
<p><img src="http://www.rawapps.com/wp-content/uploads/promoimages/themebanner.jpg"></p>
<p>Use this page to add and manage rotating testimonials that can be used with the testimonials widget or inserted in other locations.</p>
<form method="post" enctype="multipart/form-data" action="options.php">
<h3>Add Additional Testimonials</h3>
<p>Testimonials added with this form are automatically included in the rotation.</p>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">Testimonial</th>
<td><textarea class="regular-text" cols="50" rows="6" name="rt_testimonial"></textarea></td>
</tr>
<tr valign="top">
<th scope="row">Source</th>
<td><input class="regular-text" type="text" name="rt_testimonialsource" value="" /></td>
</tr>
</tbody>
</table>
<?php settings_fields('rt_testimonial'); ?>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Add Testimonial') ?>" />
</p>
</form>
<h3>Manage Testimonials</h3>
<p>A list of your active testimonials, click the delete label to permanently remove the testimonial.</p>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row"><b>Source</b></th>
<td><b>Testimonial</b></td>
</tr>
<?php rt_preview_testimonials();?>
</tbody>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Add Testimonial') ?>" />
</p>
</div>
<?php
}
add_action('wp_head', 'rt_head');
?>