-
Notifications
You must be signed in to change notification settings - Fork 20
/
functions.php
1152 lines (1029 loc) · 47.5 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
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* Make OKFN theme available for translation.
* Translations can be added to the /languages/ directory.
*/
//load_theme_textdomain( 'okfn', TEMPLATEPATH.'/languages' );
load_child_theme_textdomain( 'okfn', get_stylesheet_directory() . '/languages' );
load_child_theme_textdomain('buddypress', get_stylesheet_directory() .'/languages/bp-languages' );
/*
* Register a series of DOM-manipulating filters.
*/
add_filter('wp_nav_menu', 'filter_nav_menu');
add_filter('bp_before_account_details_fields', 'register_form_blurb');
/*
* Use the simple_html_dom library to perform
* easy manipulations on wordpress' output.
*/
include('simple_html_dom.php');
/*
* Kill Buddypress' profile links. They are wrong and stupid!
*/
function remove_xprofile_links() {
remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
}
add_action( 'bp_init', 'remove_xprofile_links' );
/*
* Disable the parent theme's stylesheets. We work from scratch.
*/
if ( !function_exists( 'bp_dtheme_enqueue_styles' ) ) :
function bp_dtheme_enqueue_styles() {}
endif;
/*
* Modify the DOM to enable bootstrap dropdown menus.
*/
function filter_nav_menu( $header ) {
$header = str_get_html($header);
foreach ($header->find('li') as $li) {
// "current-menu-item" is marked as "active" for bootstra
if (stristr($li->class, "current-menu-item")) {
$li->class .= " active";
}
// Any <li> containing a <ul> gets a special class
$isDropdown = count($li->find('ul')) > 0;
if ($isDropdown) {
$li->class.=" dropdown";
$tag = 'data-dropdown';
$li->$tag = "dropdown";
$li->find('a',0)->class.=" dropdown-toggle";
$li->find('ul',0)->class.=" dropdown-menu";
}
}
return $header;
}
/* Taken from buddypress:functions.php.bp_dtheme_main_nav. Used by header.php */
function okfn_fallback_nav_menu( $args ) {
global $bp;
$pages_args = array(
'depth' => 0,
'echo' => false,
'exclude' => '',
'title_li' => ''
);
$menu = wp_page_menu( $pages_args );
$menu = str_replace( array( '<div class="menu"><ul>', '</ul></div>' ), array( '<ul id="nav" class="nav">', '</ul><!-- #nav -->' ), $menu );
echo $menu;
do_action( 'bp_nav_items' );
}
function register_form_blurb( $args ) {
echo "<p>Community Membership is a way of "opting in" and publicly acknowledging a connnection with the Open Knowledge Foundation and support for its activities."
." It entails no specific obligations (nor confers specific rights!) and anyone may join.</p>"
."<p><a href=\"/governance/#community-membership\">Read more about Community Membership »</a></p>";
}
/*
* Choose the "best" category (ie. most
* important) category from multiple categories.
*
* This will be displayed on a post tab.
*/
function choose_best_category( $categories) {
// Cannot fathom why my array comes inside an array...
$categories = $categories[0];
global $options;
foreach ($options as $value) {
if(array_key_exists('id', $value)) {
if (get_option( $value['id'] ) === FALSE) {
if (array_key_exists('std', $value)) {
$$value['id'] = $value['std'] or NULL;
}
} else {
$$value['id'] = get_option( $value['id'] );
}
}
}
if (!empty($okfn_category_priority)) {
$category_priority_custom = stripslashes($okfn_category_priority);
$category_priority = explode(',', $category_priority_custom);
}
else {
$category_priority = okfn_load_file( get_bloginfo('stylesheet_directory').'/category-priority.txt');
}
// Choose the first category I have in the priority list
$first = null;
foreach ($category_priority as $priority) {
foreach ($categories as $category) {
if ($priority == $category->name)
return $category->name;
}
}
return $categories[0]->name;
// I have no special categories. Just choose the first one.
return '???';
};
function echo_magazine_post($post, $is_featured) {
$post_class = $is_featured ? 'featured' : 'preview';
$post_category = choose_best_category( array( get_the_category()) );
// Extract the first img src from the post body
$regex = '/magazine.image\s*=\s*"?([^"\s]*)/';
preg_match($regex, get_the_content(), $matches);
if ( has_post_thumbnail() ) {
$post_img = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); // use wp featured image
}
elseif (count($matches)) $post_img = $matches[1]; // else use old featured image
else {
$post_img = 'http://assets.okfn.org/web/images/blog-placeholder.png'; // else use placeholder
}
echo '<div class="box post '.$post_class.'">';
echo '<div class="padder"> <a class="image" href="'.get_permalink().'" style="background-image:url('.$post_img.');"></a>';
echo '<div class="text">';
echo '<h2><a href="'.get_permalink().'" rel="bookmark">'; the_title(); echo '</a></h2>';
echo '<span class="entry-meta"> Posted on ';
printf( __( '%1$s <span>in %2$s</span>', 'buddypress' ), get_the_date(), get_the_category_list( ', ' ) );
echo 'by ' . bp_core_get_userlink( $post->post_author );
echo '</span>';
echo the_excerpt();
echo '</div>';
echo '<a href="'.get_permalink().'" class="btn btn-info">'.__("Full Post", "okfn").'</a> </div>';
echo '<h3 class="ribbon">';
echo $post_category;
echo '</h3>';
echo '</div>';
}
// The height and width of your custom header. You can hook into the theme's own filters to change these values.
// Add a filter to bp_dtheme_header_image_width and bp_dtheme_header_image_height to change these values.
define( 'HEADER_IMAGE_WIDTH', apply_filters( 'bp_dtheme_header_image_width', 60 ) );
define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'bp_dtheme_header_image_height', 60 ) );
/*
* Theme Options
*/
// Get default category priority list to use as placeholder
$default_category_priority = okfn_load_file( get_bloginfo('stylesheet_directory').'/category-priority.txt');
$default_category_priority_string = implode(', ',$default_category_priority);
// Settings
$themename = "OKF Theme";
$shortname = "okfn";
$options = array (
array( "name" => "general_options",
"type" => "open"),
array( "name" => "General Styling",
"type" => "title"),
array("name" => "Flavour",
"id" => $shortname."_colours",
"type" => "radio",
"desc" => "Change the general look of the site",
"options" => array("default" => "Classic", "grey" => "OKF", "blue" => "Ckan", "turquoise" => "Glam", "school" => "School", "white" => "Simple"),
"std" => "grey",
"class" => "thumbs"),
array( "name" => "Favicon",
"desc" => "Replace default favicon with your own ico file",
"id" => $shortname."_favicon",
"type" => "text",
"placeholder" => "enter url"),
array("name" => "Tagline Location",
"id" => $shortname."_tagline_location",
"type" => "radio",
"desc" => "Where would you like the tagline to appear on the page?",
"options" => array("home" => "Top of home page", "default" => "Top of every page", "header" => "In the header", "hide" => "Nowhere"),
"std" => "hide"),
array( "name" => "TopBar",
"type" => "title"),
array( "name" => "Show TopBar?",
"desc" => "Show / hide the BuddyPress bar at the top of this site.",
"id" => $shortname."_buddypress_disable",
"type" => "radio",
"options" => array("true" => "Hide", "false" => "Show"),
"std" => "true"),
array( "name" => "Header",
"type" => "title"),
array( "name" => "Header Height",
"desc" => "Check this box to make the header taller.",
"id" => $shortname."_tall_header",
"type" => "radio",
"options" => array("true" => "Tall", "false" => "Short"),
"std" => "true"),
array( "name" => "Make my logo bigger!",
"desc" => "Check this box to increase font size of site title. Useful when you have a short title. Only works with tall header.",
"id" => $shortname."_large_title",
"type" => "checkbox",
"std" => "false"),
array("name" => "Logo Font",
"id" => $shortname."_logo_font",
"type" => "radio",
"desc" => "Font for header logo text",
"options" => array("default" => "Open Sans", "ubuntu" => "Ubuntu"),
"std" => "default"),
array( "name" => "Hide Logo Icon?",
"desc" => "Check this box if you would like to HIDE the logo image.",
"id" => $shortname."_logo_icon",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Hide Logo Text?",
"desc" => "Check this box if you would like to HIDE the logo text.",
"id" => $shortname."_logo_text",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Custom Header Text",
"desc" => "Check this box to enable custom header text.",
"id" => $shortname."_header_text",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Header Text",
"desc" => "Text or html to display in header.",
"id" => $shortname."_header_textarea",
"type" => "textarea"),
array("name" => "Align Header Text",
"id" => $shortname."_header_text_align",
"type" => "radio",
"desc" => "Which side of the header would you like this to appear?",
"options" => array("left" => "Left", "right" => "Right"),
"std" => "right"),
array( "name" => "Custom Header Text Two",
"desc" => "Check this box to enable custom header text.",
"id" => $shortname."_header_text2",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Header Text",
"desc" => "Text or html to display in header.",
"id" => $shortname."_header_textarea2",
"type" => "textarea"),
array("name" => "Align Header Text",
"id" => $shortname."_header_text_align2",
"type" => "radio",
"desc" => "Which side of the header would you like this to appear?",
"options" => array("left" => "Left", "right" => "Right"),
"std" => "right"),
array( "name" => "Corner Ribbon Toggle",
"desc" => "Check this box to enable text in the top right of the page.",
"id" => $shortname."_corner_ribbon",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Corner Ribbon Text",
"desc" => "Text or html to display in the ribbon.",
"id" => $shortname."_corner_ribbon_text",
"type" => "textarea"),
array( "name" => "Corner Ribbon Link",
"desc" => "url to link to",
"id" => $shortname."_corner_ribbon_link",
"type" => "text"),
array( "name" => "Hide OKF Ribbon",
"desc" => "Check this box to disable OKF Panel hooks.",
"id" => $shortname."_okf_ribbon",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Search Icon",
"desc" => "Enable search bar in header",
"id" => $shortname."_header_search",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Sub-Header",
"type" => "title"),
array( "name" => "Sub-header Bar?",
"desc" => "Check this box to display a bar below the header, inclusing breadcrumbs. (Does not appear on homepage)",
"id" => $shortname."_subheader",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Search in Sub-header?",
"desc" => "Check this box to display add a search field to the sub-header bar.",
"id" => $shortname."_subheader_search",
"type" => "checkbox",
"std" => "false"),
array( "type" => "close"),
array( "name" => "social_options",
"type" => "open"),
array( "name" => "Social",
"type" => "title"),
array( "name" => "Twitter Link",
"desc" => "Add link to Twitter profile.",
"id" => $shortname."_twitter_link",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Twitter Username",
"desc" => "twitter.com/...",
"id" => $shortname."_twitter_username",
"type" => "text"),
array("name" => "Twitter Location",
"id" => $shortname."_twitter_location",
"type" => "radio",
"desc" => "Where to put Twitter icon",
"options" => array("default" => "Header", "footer" => "Footer", "both" => "Header and Footer"),
"std" => "default"),
array( "name" => "Facebook Link",
"desc" => "Add link to Facebook profile.",
"id" => $shortname."_facebook_link",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Facebook Username",
"desc" => "This is what comes after'facebook.com/' in the URL (this will also be used for Open Graph tags).",
"id" => $shortname."_facebook_username",
"type" => "text"),
array("name" => "Facebook Location",
"id" => $shortname."_facebook_location",
"type" => "radio",
"desc" => "Where to put Facebook icon",
"options" => array("default" => "Header", "footer" => "Footer", "both" => "Header and Footer"),
"std" => "default"),
array( "name" => "ShareThis",
"desc" => "Check this box to enable ShareThis.",
"id" => $shortname."_sharethis",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Publisher ID",
"desc" => "If you have a ShareThis account, enter your publisher ID here.",
"id" => $shortname."_sharethis_id",
"std" => "",
"type" => "text"),
array("name" => "ShareThis Location",
"id" => $shortname."_sharethis_location",
"type" => "radio",
"desc" => "Where is it going?",
"options" => array("footer" => "Footer", "elsewhere" => "Elsewhere"),
"std" => "footer"),
// array( "name" => "Enable Tweet",
// "desc" => "Include Seaclouds Tweet script. Uses twitter username specified above.",
// "id" => $shortname."_enable_tweet",
// "type" => "checkbox",
// "std" => "false"),
array( "name" => "Mailing List Bar",
"type" => "title"),
array( "name" => "MailChimp Plugin",
"desc" => "MailChimp form powered by N-Media MailChimp plugin",
"id" => $shortname."_mailchimp_bar",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Mailing List Heading",
"desc" => "Appears next to the form",
"id" => $shortname."_mailchimp_heading",
"type" => "text"),
array( "name" => "Description",
"desc" => "Used if multiple lists",
"id" => $shortname."_mailchimp_description",
"type" => "text"),
array( "name" => "Form ID",
"desc" => "fid number found in shortcode",
"id" => $shortname."_mailchimp_id",
"type" => "text"),
array( "name" => "Native Mailing List 1",
"desc" => "Add mailing list form",
"id" => $shortname."_mailinglist_bar",
"type" => "checkbox",
"std" => "false"),
array("name" => "Type",
"id" => $shortname."_mailinglist_bar_type",
"type" => "radio",
"desc" => "Where is the mailing list",
"options" => array("mailman" => "Mailman", "mailchimp" => "MailChimp"),
"std" => "mailman"),
array( "name" => "Mailing List Heading",
"desc" => "Appears next to the form",
"id" => $shortname."_mailinglist_heading",
"type" => "text"),
array( "name" => "Description",
"desc" => "Used if multiple lists",
"id" => $shortname."_mailinglist_description",
"type" => "text"),
array( "name" => "Action",
"desc" => "URL from form action attribute. Mailman example: http://lists.okfn.org/mailman/subscribe/XYZ",
"id" => $shortname."_mailinglist_action",
"type" => "text"),
array( "name" => "Native Mailing List 2",
"desc" => "Add mailing list form",
"id" => $shortname."_mailinglist_bar2",
"type" => "checkbox",
"std" => "false"),
array("name" => "Type",
"id" => $shortname."_mailinglist_bar_type2",
"type" => "radio",
"desc" => "Where is the mailing list",
"options" => array("mailman" => "Mailman", "mailchimp" => "MailChimp"),
"std" => "mailman"),
array( "name" => "Mailing List Heading",
"desc" => "Appears next to the form",
"id" => $shortname."_mailinglist_heading2",
"type" => "text"),
array( "name" => "Description",
"desc" => "Used if multiple lists",
"id" => $shortname."_mailinglist_description2",
"type" => "text"),
array( "name" => "Action",
"desc" => "URL from form action attribute. Mailman example: http://lists.okfn.org/mailman/subscribe/XYZ",
"id" => $shortname."_mailinglist_action2",
"type" => "text"),
array("name" => "Mailing List Location",
"id" => $shortname."_mailinglist_bar_location",
"type" => "radio",
"desc" => "Where to put bar",
"options" => array("header" => "Header (home page, first list only)", "footer" => "Footer"),
"std" => "footer"),
array( "type" => "close"),
array( "name" => "blog_options",
"type" => "open"),
array( "name" => "Blog",
"type" => "title"),
array( "name" => "Large Blog Avatars",
"desc" => "Check this box to use large avatars on blog post page (requires Gravatar).",
"id" => $shortname."_large_avatars",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Blog Archive",
"desc" => "URL to all blog posts, used in Magazine template.",
"id" => $shortname."_blog_link",
"type" => "text"),
array( "name" => "Magazine Posts",
"desc" => "How many posts to show in the Magazine template.",
"id" => $shortname."_magazine_posts",
"type" => "text"),
array( "name" => "Featured Category",
"desc" => "Name of category to feature on magazine style pages ('Featured' by default).",
"id" => $shortname."_magazine_featured",
"type" => "text"),
array( "name" => "Home Category",
"desc" => "Name of category to feature on homepage ('Featured' by default).",
"id" => $shortname."_home_featured",
"type" => "text"),
array( "name" => "Events Category",
"desc" => "Name of category to feature on events page ('Events' by default).",
"id" => $shortname."_events_featured",
"type" => "text"),
array( "name" => "Narrow Post Column",
"desc" => "Check this box to use alternative post page layout.",
"id" => $shortname."_narrow_blog",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Category Priority",
"type" => "title"),
array( "name" => "Which category is shown, when only room for one?",
"desc" => "List in order of priority. Categories must be comma separated, and are case sensitive.",
"id" => $shortname."_category_priority",
"type" => "textarea",
"rows" => "11",
"placeholder" => $default_category_priority_string),
array( "type" => "close"),
array( "name" => "misc_options",
"type" => "open"),
array( "name" => "Misc",
"type" => "title"),
//array("name" => "Carousel Style",
//"id" => $shortname."_carosel",
//"type" => "radio",
//"desc" => "Change layout style of Bootstrap carousel",
//"options" => array("default" => "Default", "text-right" => "Text on Right (full width)", "stack" => "Text on Right (photo stack)"),
//"std" => "default"),
array( "name" => "Tagline in meta title?",
"desc" => "Check this box to append site title with tagline in the meta title tag.",
"id" => $shortname."_tagline_title",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Flattr OKFN",
"desc" => "Check this box to add a link to donate to the Open Knowledge Foundation.",
"id" => $shortname."_flattr_okfn",
"type" => "checkbox",
"std" => "false"),
array( "name" => "Enable Flags",
"desc" => "https://github.com/lafeber/world-flags-sprite",
"id" => $shortname."_flags_sprite",
"type" => "checkbox",
"std" => "false"),
array( "type" => "close"),
);
function mytheme_add_admin() {
global $themename, $shortname, $options;
if ( $_GET['page'] == basename(__FILE__) ) {
if ( 'save' == $_REQUEST['action'] ) {
foreach ($options as $value) {
update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
foreach ($options as $value) {
if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } }
header("Location: themes.php?page=functions.php&saved=true");
die;
} else if( 'reset' == $_REQUEST['action'] ) {
foreach ($options as $value) {
delete_option( $value['id'] ); }
header("Location: themes.php?page=functions.php&reset=true");
die;
}
}
add_theme_page($themename." Options", "".$themename." Options", 'switch_themes', basename(__FILE__), 'mytheme_admin');
}
function mytheme_admin() {
global $themename, $shortname, $options;
if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
?>
<div class="options wrap">
<style scoped>
.options .group h3 {
font-family: sans-serif;
font-weight:bold;
background-color:#DFDFDF;
}
.options .section {
padding:10px 0;
border-top:solid 1px #ECECEC;
}
.options h3 + .section {
border:none;
}
.options .section .heading {
float:left;
width:25%;
}
.options .section .heading h4,
.options .section .heading .explain {
margin:0;
padding:0 10px;
}
.options .section .heading + .option {
margin-left:25%;
}
.options .section-radio label {
margin-bottom:5px;
display:block;
}
.options .section-radio.thumbs label {
width:240px;
display:inline-block;
padding-top:122px;
margin:0px 15px 15px 0px;
border:solid 1px #DDDDDD;
background-position:center top;
}
.options .section-radio.thumbs label span {
display:block;
padding:3px;
background: rgb(255, 255, 255); /* fallback */
background: rgba(255, 2554, 255, 0.9);
}
.options .submit {
display:block;
float:left;
margin-left:10px;
}
</style>
<h2><?php echo $themename; ?> Options</h2>
<div class="icon32" id="icon-themes"><br></div>
<?php settings_errors(); ?>
<?php $active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general_options'; ?>
<h2 class="nav-tab-wrapper">
<a href="?page=functions.php&tab=general_options" title="General" class="nav-tab<?php echo $active_tab == 'general_options' ? ' nav-tab-active' : ''; ?>" id="of-option-general-tab">General</a>
<a href="?page=functions.php&tab=social_options" title="Social" class="nav-tab<?php echo $active_tab == 'social_options' ? ' nav-tab-active' : ''; ?>" id="of-option-social-tab">Social</a>
<a href="?page=functions.php&tab=blog_options" title="Blog" class="nav-tab<?php echo $active_tab == 'blog_options' ? ' nav-tab-active' : ''; ?>" id="of-option-blog-tab">Blog</a>
<a href="?page=functions.php&tab=misc_options" title="Misc" class="nav-tab<?php echo $active_tab == 'misc_options' ? ' nav-tab-active' : ''; ?>" id="of-option-misc-tab">Misc</a>
</h2>
<div class="metabox-holder">
<form method="post">
<?php foreach ($options as $value) {
switch ( $value['type'] ) {
case "open":
?>
<div id="<?php echo $value['name']; ?>" class="group" <?php if( $active_tab !== $value['name'] ) : ?> style="display:none;"<?php endif; ?> >
<?php break;
case "close":
?>
</div>
<?php break;
case "title":
?>
<h3><?php echo $value['name']; ?></h3>
<?php break;
case 'text':
?>
<div class="section section-text" id="section_<?php echo $value['id']; ?>">
<div class="heading">
<h4><?php echo $value['name']; ?></h4>
<p class="explain"><?php echo $value['desc']; ?></p>
</div>
<div class="option">
<div class="controls">
<input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_option( $value['id'] ) != "") { echo get_option( $value['id'] ); } else { echo $value['std']; } ?>" <?php if ( $value['placeholder'] != "") : ?>placeholder="<?php echo $value['placeholder']; ?>"<?php endif ?>/>
<br>
</div>
<div class="clear"></div>
</div>
</div>
<?php
break;
case 'textarea':
?>
<?php $input = get_option( $value['id'] ); $output = stripslashes ($input); ?>
<div class="section section-textarea" id="section_<?php echo $value['id']; ?>">
<div class="heading">
<h4><?php echo $value['name']; ?></h4>
<p class="explain"><?php echo $value['desc']; ?></p>
</div>
<div class="option">
<div class="controls">
<textarea name="<?php echo $value['id']; ?>" cols="70" rows="<?php if ( $value['rows'] != "") { echo $value['rows']; } else { echo '5'; } ?>" <?php if ( $value['placeholder'] != "") : ?>placeholder="<?php echo $value['placeholder']; ?>"<?php endif ?>><?php if ( get_option( $value['id'] ) != "") { echo $output; } else { echo $value['std']; } ?></textarea>
<br>
</div>
<div class="clear"></div>
</div>
</div>
<?php
break;
case 'select':
?>
<div class="section section-select" id="section_<?php echo $value['id']; ?>">
<div class="heading">
<h4><?php echo $value['name']; ?></h4>
<p class="explain"><?php echo $value['desc']; ?></p>
</div>
<div class="option">
<div class="controls">
<select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"><?php foreach ($value['options'] as $option) { ?><option<?php if ( get_option( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?></select>
<br>
</div>
<div class="clear"></div>
</div>
</div>
<?php break;
case 'media':
$upload_button_text = __( 'Upload', 'okfn' );
?>
<div class="section section-text" id="section_<?php echo $value['id']; ?>">
<div class="heading">
<h4><?php echo $value['name']; ?></h4>
<p class="explain"><?php echo $value['desc']; ?></p>
</div>
<div class="option">
<div class="controls">
<input type="text" id="<?php echo $value['id']; ?>" name="<?php echo $value['id']; ?>" value="<?php if ( get_option( $value['id'] ) != "") { echo get_option( $value['id'] ); } else { echo $value['std']; } ?>" <?php if ( $value['placeholder'] != "") : ?>placeholder="<?php echo $value['placeholder']; ?>"<?php endif ?> />
<!--<input id="<?php echo $value['id']; ?>_upload_button" type="button" class="button" value="<?php echo $upload_button_text; ?>" /> -->
<br>
</div>
<div class="clear"></div>
</div>
</div>
<?php
break;
case "checkbox":
?>
<div class="section section-checkbox" id="section_<?php echo $value['id']; ?>">
<div class="heading">
<h4><?php echo $value['name']; ?></h4>
</div>
<div class="option">
<div class="controls">
<?php if( get_option($value['id'] ) ){ $checked = "checked=\"checked\""; } else { if ( $value['std'] === "true" ){ $checked = "checked=\"checked\""; } else { $checked = ""; } } ?>
<input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
<label for="<?php echo $value['id']; ?>" class="explain"><?php echo $value['desc']; ?></label>
</div>
<div class="clear"></div>
</div>
</div>
<?php break;
case "radio":?>
<div class="section section-radio <?php echo $value['class'] ?>" id="section_<?php echo $value['id']; ?>">
<div class="heading">
<h4><?php echo $value['name']; ?></h4>
<p class="explain"><?php echo $value['desc']; ?></p>
</div>
<div class="option">
<div class="controls">
<?php foreach ($value['options'] as $option_value => $option_text) {
$checked = ' ';
if (get_option($value['id']) == $option_value) {
$checked = ' checked="checked" ';
}
else if (get_option($value['id']) === FALSE && $value['std'] == $option_value){
$checked = ' checked="checked" ';
}
else {
$checked = ' ';
}
if ($value['class'] == "thumbs") {
$bgimage = "".get_bloginfo('stylesheet_directory')."/screenshot-".$option_value.".png";
}
else {
$bgimage = '';
}
echo '<label style="background-image:url('.$bgimage.');"><span><input type="radio" style="margin-right:10px;" name="'.$value['id'].'" value="'.
$option_value.'" '.$checked."/>".$option_text."</span></label>";
} ?>
</div>
<div class="clear"></div>
</div>
</div>
<?php break;
}
}
?>
<span class="submit">
<input name="save" type="submit" value="Save changes" class="button-primary" />
<input type="hidden" name="action" value="save" />
</span>
</form>
<form method="post">
<span class="submit">
<input name="reset" type="submit" value="Reset" class="button" />
<input type="hidden" name="action" value="reset" />
</span>
</form>
</div>
<?php
}
add_action('admin_menu', 'mytheme_add_admin'); ?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'id' => 'sidebar-1',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '',
'after_title' => '',
));
/***********************************************************************
* @Author: Boutros AbiChedid
* @Date: February 14, 2011
* @Copyright: Boutros AbiChedid (http://bacsoftwareconsulting.com/)
* @Licence: Feel free to use it and modify it to your needs but keep the
* Author's credit. This code is provided 'as is' without any warranties.
* @Function Name: wp_bac_breadcrumb()
* @Version: 1.0 -- Tested up to WordPress version 3.1.2
* @Description: WordPress Breadcrumb navigation function. Adding a
* breadcrumb trail to the theme without a plugin.
* This code does not support multi-page split numbering, attachments,
* custom post types and custom taxonomies.
***********************************************************************/
function wp_bac_breadcrumb() {
//Variable (symbol >> encoded) and can be styled separately.
//Use >> for different level categories (parent >> child >> grandchild)
$delimiter = '<span class="delimiter">/</span>';
//Use bullets for same level categories ( parent . parent )
$delimiter1 = '<span class="delimiter1"> • </span>';
//text link for the 'Home' page
$main = 'Home';
//Display only the first 30 characters of the post title.
$maxLength= 30;
//variable for archived year
$arc_year = get_the_time('Y');
//variable for archived month
$arc_month = get_the_time('F');
//variables for archived day number + full
$arc_day = get_the_time('d');
$arc_day_full = get_the_time('l');
//variable for the URL for the Year
$url_year = get_year_link($arc_year);
//variable for the URL for the Month
$url_month = get_month_link($arc_year,$arc_month);
/*is_front_page(): If the front of the site is displayed, whether it is posts or a Page. This is true
when the main blog page is being displayed and the 'Settings > Reading ->Front page displays'
is set to "Your latest posts", or when 'Settings > Reading ->Front page displays' is set to
"A static page" and the "Front Page" value is the current Page being displayed. In this case
no need to add breadcrumb navigation. is_home() is a subset of is_front_page() */
//Check if NOT the front page (whether your latest posts or a static page) is displayed. Then add breadcrumb trail.
if (!is_front_page()) {
//If Breadcrump exists, wrap it up in a div container for styling.
//You need to define the breadcrumb class in CSS file.
echo '<ul class="breadcrumb">';
//global WordPress variable $post. Needed to display multi-page navigations.
global $post, $cat;
//A safe way of getting values for a named option from the options database table.
$homeLink = get_option('home'); //same as: $homeLink = get_bloginfo('url');
//If you don't like "You are here:", just remove it.
echo '<li><a href="' . $homeLink . '">' . $main . '</a></li>' . $delimiter;
//Display breadcrumb for single post
if (is_single()) { //check if any single post is being displayed.
//Returns an array of objects, one object for each category assigned to the post.
//This code does not work well (wrong delimiters) if a single post is listed
//at the same time in a top category AND in a sub-category. But this is highly unlikely.
$category = get_the_category();
$num_cat = count($category); //counts the number of categories the post is listed in.
//If you have a single post assigned to one category.
//If you don't set a post to a category, WordPress will assign it a default category.
if ($num_cat <=1) //I put less or equal than 1 just in case the variable is not set (a catch all).
{
echo get_category_parents($category[0], true,' ' . $delimiter . ' ');
//Display the full post title.
echo ' ' . get_the_title();
}
//then the post is listed in more than 1 category.
else {
//Put bullets between categories, since they are at the same level in the hierarchy.
echo the_category( $delimiter1, multiple);
//Display partial post title, in order to save space.
if (strlen(get_the_title()) >= $maxLength) { //If the title is long, then don't display it all.
echo ' ' . $delimiter . trim(substr(get_the_title(), 0, $maxLength)) . ' ...';
}
else { //the title is short, display all post title.
echo ' ' . $delimiter . get_the_title();
}
}
}
//Display breadcrumb for category and sub-category archive
elseif (is_category()) { //Check if Category archive page is being displayed.
//returns the category title for the current page.
//If it is a subcategory, it will display the full path to the subcategory.
//Returns the parent categories of the current category with links separated by '»'
echo 'Archive Category: "' . get_category_parents($cat, true,' ' . $delimiter . ' ') . '"' ;
}
//Display breadcrumb for tag archive
elseif ( is_tag() ) { //Check if a Tag archive page is being displayed.
//returns the current tag title for the current page.
echo 'Posts Tagged: "' . single_tag_title("", false) . '"';
}
//Display breadcrumb for calendar (day, month, year) archive
elseif ( is_day()) { //Check if the page is a date (day) based archive page.
echo '<a href="' . $url_year . '">' . $arc_year . '</a> ' . $delimiter . ' ';
echo '<a href="' . $url_month . '">' . $arc_month . '</a> ' . $delimiter . $arc_day . ' (' . $arc_day_full . ')';
}
elseif ( is_month() ) { //Check if the page is a date (month) based archive page.
echo '<a href="' . $url_year . '">' . $arc_year . '</a> ' . $delimiter . $arc_month;
}
elseif ( is_year() ) { //Check if the page is a date (year) based archive page.
echo $arc_year;
}
//Display breadcrumb for search result page
elseif ( is_search() ) { //Check if search result page archive is being displayed.
echo 'Search Results for: "' . get_search_query() . '"';
}
//Display breadcrumb for top-level pages (top-level menu)
elseif ( is_page() && !$post->post_parent ) { //Check if this is a top Level page being displayed.
echo get_the_title();
}
//Display breadcrumb trail for multi-level subpages (multi-level submenus)
elseif ( is_page() && $post->post_parent ) { //Check if this is a subpage (submenu) being displayed.
//get the ancestor of the current page/post_id, with the numeric ID
//of the current post as the argument.
//get_post_ancestors() returns an indexed array containing the list of all the parent categories.
$post_array = get_post_ancestors($post);
//Sorts in descending order by key, since the array is from top category to bottom.
krsort($post_array);
//Loop through every post id which we pass as an argument to the get_post() function.
//$post_ids contains a lot of info about the post, but we only need the title.
foreach($post_array as $key=>$postid){
//returns the object $post_ids
$post_ids = get_post($postid);
//returns the name of the currently created objects
$title = $post_ids->post_title;
//Create the permalink of $post_ids
echo '<a href="' . get_permalink($post_ids) . '">' . $title . '</a>' . $delimiter;
}
the_title(); //returns the title of the current page.
}
//Display breadcrumb for author archive
elseif ( is_author() ) {//Check if an Author archive page is being displayed.
global $author;
//returns the user's data, where it can be retrieved using member variables.
$user_info = get_userdata($author);
echo 'Archived Article(s) by Author: ' . $user_info->display_name ;
}
//Display breadcrumb for 404 Error
elseif ( is_404() ) {//checks if 404 error is being displayed
echo 'Error 404 - Not Found.';
}
else {
//All other cases that I missed. No Breadcrumb trail.
}
echo '</ul>';
}
}
/*
* Re-usable RSS feed reader with shortcode
*/
if ( !function_exists('base_rss_feed') ) {
function base_rss_feed($size = 5, $feed = 'http://wordpress.org/news/feed/', $date = false, $cache_time = 1800)
{
// Include SimplePie RSS parsing engine
include_once ABSPATH . WPINC . '/feed.php';
// Set the cache time for SimplePie
add_filter( 'wp_feed_cache_transient_lifetime', create_function( '$a', "return $cache_time;" ) );
// Build the SimplePie object
$rss = fetch_feed($feed);
// Check for errors in the RSS XML
if ( !is_wp_error( $rss ) ) {
// Set a limit for the number of items to parse
$maxitems = $rss->get_item_quantity($size);
$rss_items = $rss->get_items(0, $maxitems);
// Store the total number of items found in the feed
$i = 0;
$total_entries = count($rss_items);
// Output HTML
$html = "<ul class='feedlist'>";
foreach ($rss_items as $item) {
$i++;
// Add a class of "last" to the last item in the list
if( $total_entries == $i ) {
$last = " class='last'";
} else {