forked from xwolfde/Piratenkleider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
842 lines (699 loc) · 33.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
<?php
/**
* Piratenkleider Theme Optionen
*
* @source http://github.com/xwolfde/Piratenkleider
* @creator xwolf
* @version 2.12
* @licence CC-BY-SA 3.0
*/
require( get_template_directory() . '/inc/constants.php' );
$options = get_option( 'piratenkleider_theme_options' );
if (!isset($options['anonymize-user']))
$options['anonymize-user'] = $defaultoptions['anonymize-user'];
if ($options['anonymize-user']==1) {
/* IP-Adresse überschreiben */
$_SERVER["REMOTE_ADDR"] = "0.0.0.0";
/* UA-String überschreiben */
$_SERVER["HTTP_USER_AGENT"] = "";
update_option('require_name_email',0);
}
if (!isset($options['feed_cache_lifetime']))
$options['feed_cache_lifetime'] = $defaultoptions['feed_cache_lifetime'];
if (!isset($options['twitter_cache_lifetime']))
$options['twitter_cache_lifetime'] = $defaultoptions['twitter_cache_lifetime'];
if ($options['feed_cache_lifetime'] < 600) {
$options['feed_cache_lifetime'] = 1800;
}
// Das holen von feeds sollte auf keinen Fall haeufiger als alle 10 Minuten erfolgen
if ($options['twitter_cache_lifetime'] > $options['feed_cache_lifetime']) {
$options['twitter_cache_lifetime'] = $options['feed_cache_lifetime'];
}
// Twitter Feeds sollten nicht laenger warten als die allgemeine feeds
function feed_lifetime_cb( ) {
global $options;
// change the default feed cache recreation period to 2 hours
return $options['feed_cache_lifetime'];
}
add_filter( 'wp_feed_cache_transient_lifetime' , 'feed_lifetime_cb' );
if ( ! isset( $content_width ) ) $content_width = $defaultoptions['content-width'];
require_once ( get_template_directory() . '/theme-options.php' );
/** Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */
add_action( 'after_setup_theme', 'piratenkleider_setup' );
if ( ! function_exists( 'piratenkleider_setup' ) ):
function piratenkleider_setup() {
global $defaultoptions;
// This theme styles the visual editor with editor-style.css to match the theme style.
add_editor_style();
// This theme uses post thumbnails
add_theme_support( 'post-thumbnails' );
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );
/*
* Header-Kontrolle, bis WP 3.3
*/
define('HEADER_TEXTCOLOR', '');
define('HEADER_IMAGE', $defaultoptions['logo']);
define('HEADER_IMAGE_WIDTH', $defaultoptions['logo-width'] ); // choose any number you like here
define('HEADER_IMAGE_HEIGHT', $defaultoptions['logo-height'] ); // choose any number you like here
define('NO_HEADER_TEXT', true );
add_custom_image_header('piratenkleider_header_style', 'piratenkleider_admin_header_style');
/* Folgendes erst ab WP 3.4:
* Ich warte aber noch etwas ab, da einige Leute noch 3.3 einsetzen
*
$args = array(
'width' => 279,
'height' => 88,
'default-image' => get_template_directory_uri() . '/images/logo.png',
'uploads' => true,
'random-default' => true,
'flex-height' => true,
'suggested-height' => 90,
'flex-width' => true,
'max-width' => 350,
'suggested-width' => 300,
);
add_theme_support( 'custom-header', $args );
*/
// Make theme available for translation
// Translations can be filed in the /languages/ directory
load_theme_textdomain('piratenkleider', get_template_directory() . '/languages');
$locale = get_locale();
$locale_file = get_template_directory() . "/languages/$locale.php";
if ( is_readable( $locale_file ) )
require_once( $locale_file );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => __( 'Hauptnavigation <br /> (Statische Seiten)', 'piratenkleider' ),
'top' => __( 'Linkmenu <br /> (Links zu Webportalen wie Wiki, Forum, etc)', 'piratenkleider' ),
'sub' => __( 'Technische Navigation <br /> (Kontakt, Impressunm, etc)', 'piratenkleider' ),
) );
/** Abschalten von Fehlermeldungen auf der Loginseite */
// add_filter('login_errors', create_function('$a', "return null;"));
/** Entfernen der Wordpressversionsnr im Header */
remove_action('wp_head', 'wp_generator');
}
endif;
require( get_template_directory() . '/inc/widgets.php' );
function piratenkleider_avatar ($avatar_defaults) {
global $defaultoptions;
$myavatar = $defaultoptions['src-default-avatar'];
$avatar_defaults[$myavatar] = "Piratenkleider";
return $avatar_defaults;
}
add_filter( 'avatar_defaults', 'piratenkleider_avatar' );
if ( ! function_exists( 'piratenkleider_admin_header_style' ) ) :
/**
* Styles the header image displayed on the Appearance > Header admin panel.
*/
function piratenkleider_admin_header_style() {
?>
<style type="text/css">
/* Shows the same border as on front end */
#headimg {
border-bottom: 1px solid #000;
border-top: 4px solid #000;
background-repeat: no-repeat;
}
</style>
<?php
}
endif;
if ( ! function_exists( 'piratenkleider_filter_wp_title' ) ) :
/*
* Sets the title
*/
function piratenkleider_filter_wp_title( $title, $separator ) {
// Don't affect wp_title() calls in feeds.
if ( is_feed() )
return $title;
// The $paged global variable contains the page number of a listing of posts.
// The $page global variable contains the page number of a single post that is paged.
// We'll display whichever one applies, if we're not looking at the first page.
global $paged, $page;
if ( is_search() ) {
// If we're a search, let's start over:
$title = sprintf( __( 'Suchergebnisse für %s', 'piratenkleider' ), '"' . get_search_query() . '"' );
// Add a page number if we're on page 2 or more:
if ( $paged >= 2 )
$title .= " $separator " . sprintf( __( 'Seite %s', 'piratenkleider' ), $paged );
// Add the site name to the end:
$title .= " $separator " . get_bloginfo( 'name', 'display' );
// We're done. Let's send the new title back to wp_title():
return $title;
}
// Otherwise, let's start by adding the site name to the end:
$title .= get_bloginfo( 'name', 'display' );
// If we have a site description and we're on the home/front page, add the description:
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title .= " $separator " . $site_description;
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
$title .= " $separator " . sprintf( __( 'Seite %s', 'piratenkleider' ), max( $paged, $page ) );
// Return the new title to wp_title():
return $title;
}
endif;
add_filter( 'wp_title', 'piratenkleider_filter_wp_title', 10, 2 );
function piratenkleider_excerpt_length( $length ) {
return $defaultoptions['teaser_maxlength'];
}
add_filter( 'excerpt_length', 'piratenkleider_excerpt_length' );
function piratenkleider_continue_reading_link() {
return ' <a title="'.strip_tags(get_the_title()).'" href="'. get_permalink() . '">' . __( 'Weiterlesen <span class="meta-nav">→</span>', 'piratenkleider' ) . '</a>';
}
function piratenkleider_auto_excerpt_more( $more ) {
return ' …' . piratenkleider_continue_reading_link();
}
add_filter( 'excerpt_more', 'piratenkleider_auto_excerpt_more' );
function piratenkleider_custom_excerpt_more( $output ) {
if ( has_excerpt() && ! is_attachment() ) {
$output .= piratenkleider_continue_reading_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'piratenkleider_custom_excerpt_more' );
function piratenkleider_remove_gallery_css( $css ) {
return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
}
add_filter( 'gallery_style', 'piratenkleider_remove_gallery_css' );
function honor_ssl_for_attachments($url) {
$http = site_url(FALSE, 'http');
$https = site_url(FALSE, 'https');
return is_ssl() ? str_replace($http, $https, $url) : $url;
}
add_filter('wp_get_attachment_url', 'honor_ssl_for_attachments');
if ( ! function_exists( 'piratenkleider_comment' ) ) :
/**
* Template for comments and pingbacks.
*/
function piratenkleider_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
global $defaultoptions;
$options = get_option( 'piratenkleider_theme_options' );
if (!isset($options['aktiv-avatar']))
$options['aktiv-avatar'] = $defaultoptions['aktiv-avatar'];
if (!isset($options['aktiv-commentreplylink']))
$options['aktiv-commentreplylink'] = $defaultoptions['aktiv-commentreplylink'];
switch ( $comment->comment_type ) :
case '' :
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-details">
<div class="comment-author vcard">
<?php if ($options['aktiv-avatar']==1) {
echo '<div class="avatar">';
echo get_avatar( $comment, 48, $defaultoptions['src-default-avatar']);
echo '</div>';
}
printf( __( '%s <span class="says">meinte am</span>', 'piratenkleider' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) );
?>
</div><!-- .comment-author .vcard -->
<?php if ( $comment->comment_approved == '0' ) : ?>
<em><?php _e( 'Der Kommentar wartet auf die Freischaltung.', 'piratenkleider' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
printf( __( '%1$s um %2$s', 'piratenkleider' ), get_comment_date(), get_comment_time() ); ?></a> Folgendes:<?php edit_comment_link( __( '(Edit)', 'piratenkleider' ), ' ' );
?>
</div><!-- .comment-meta .commentmetadata -->
</div>
<div class="comment-body"><?php comment_text(); ?></div>
<?php if ($options['aktiv-commentreplylink']) { ?>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div> <!-- .reply -->
<?php } ?>
</div><!-- #comment-## -->
<?php
break;
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php _e( 'Pingback:', 'piratenkleider' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'piratenkleider'), ' ' ); ?></p>
<?php
break;
endswitch;
}
endif;
function piratenkleider_remove_recent_comments_style() {
global $wp_widget_factory;
remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
}
add_action( 'widgets_init', 'piratenkleider_remove_recent_comments_style' );
if ( ! function_exists( 'piratenkleider_post_pubdateinfo' ) ) :
/**
* Fusszeile unter Artikeln: Veröffentlichungsdatum
*/
function piratenkleider_post_pubdateinfo() {
printf( __( '<span class="meta-prep">Veröffentlicht am</span> %1$s ', 'piratenkleider' ),
sprintf( '<span class="entry-date">%1$s</span>',
get_the_date()
)
);
}
endif;
if ( ! function_exists( 'piratenkleider_post_autorinfo' ) ) :
/**
* Fusszeile unter Artikeln: Autorinfo
*/
function piratenkleider_post_autorinfo() {
printf( __( '<span class="meta-prep-author">von</span> %1$s ', 'piratenkleider' ),
sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span> ',
get_author_posts_url( get_the_author_meta( 'ID' ) ),
sprintf( esc_attr__( 'Artikel von %s', 'piratenkleider' ), get_the_author() ),
get_the_author()
)
);
}
endif;
if ( ! function_exists( 'piratenkleider_post_taxonominfo' ) ) :
/**
* Fusszeile unter Artikeln: Taxonomie
*/
function piratenkleider_post_taxonominfo() {
$tag_list = get_the_tag_list( '', ', ' );
if ( $tag_list ) {
$posted_in = __( 'unter %1$s und tagged %2$s. <br>Hier der permanente <a href="%3$s" title="Permalink to %4$s" rel="bookmark">Link</a> zu diesem Artikel.', 'piratenkleider' );
} elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
$posted_in = __( 'unter %1$s. <br><a href="%3$s" title="Permalink to %4$s" rel="bookmark">Permanenter Link</a> zu diesem Artikel.', 'piratenkleider' );
} else {
$posted_in = __( '<a href="%3$s" title="Permalink to %4$s" rel="bookmark">Permanenter Link</a> zu diesem Artikel.', 'piratenkleider' );
}
// Prints the string, replacing the placeholders.
printf(
$posted_in,
get_the_category_list( ', ' ),
$tag_list,
get_permalink(),
the_title_attribute( 'echo=0' )
);
}
endif;
// this function initializes the iframe elements
// maybe wont work on multisite installations. please use plugins instead.
function piratenkleider_change_mce_options($initArray) {
$ext = 'iframe[align|longdesc|name|width|height|frameborder|scrolling|marginheight|marginwidth|src]';
if ( isset( $initArray['extended_valid_elements'] ) ) {
$initArray['extended_valid_elements'] .= ',' . $ext;
} else {
$initArray['extended_valid_elements'] = $ext;
}
// maybe; set tiny paramter verify_html
$initArray['verify_html'] = false;
return $initArray;
}
add_filter('tiny_mce_before_init', 'piratenkleider_change_mce_options');
class My_Walker_Nav_Menu extends Walker_Nav_Menu
{
/**
* Start the element output.
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Menu item data object.
* @param int $depth Depth of menu item. May be used for padding.
* @param array $args Additional strings.
* @return void
*/
public function start_el( &$output, $item, $depth, $args ) {
if ( '-' === $item->title )
{
// you may remove the <hr> here and use plain CSS.
$output .= '<li class="menu_separator"><hr>';
} else{
parent::start_el( $output, $item, $depth, $args );
}
}
/* Klasse has_children einfuegen */
public function display_element($el, &$children, $max_depth, $depth = 0, $args, &$output){
$id = $this->db_fields['id'];
if(isset($children[$el->$id]))
$el->classes[] = 'has_children';
parent::display_element($el, $children, $max_depth, $depth, $args, $output);
}
}
if ( ! function_exists( 'get_piratenkleider_socialmediaicons' ) ) :
/**
* Displays Social Media Icons
*/
function get_piratenkleider_socialmediaicons( $darstellung = 1 ){
$options = get_option( 'piratenkleider_theme_options' );
$zeigeoption = $options['alle-socialmediabuttons'];
if ($darstellung ==0) {
/* Keine Links */
return;
}
if ($darstellung!=$zeigeoption) {
/* Nichts anzeigen, da wir im falschen Modus sind */
return;
}
if ($zeigeoption ==2) {
/* Links an der Seite */
echo '<div id="socialmedia_iconbar">';
}
echo '<ul class="socialmedia">';
if ( $options['social_facebook'] != "" ){ echo '<li class="facebook"><a href="'.$options['social_facebook'].'"><img src="'.get_template_directory_uri().'/images/social-media/facebook-24x24.png" width="24" height="24" alt="Facebook"></a></li>'; }
if ( $options['social_twitter'] != "" ){ echo '<li class="twitter"><a href="'.$options['social_twitter'].'"><img src="'.get_template_directory_uri().'/images/social-media/twitter-24x24.png" width="24" height="24" alt="Twitter"></a></li>'; }
if ( $options['social_gplus'] != "" ){ echo '<li class="gplus"><a href="'.$options['social_gplus'].'"><img src="'.get_template_directory_uri().'/images/social-media/gplus-24x24.png" width="24" height="24" alt="Google+"></a></li>'; }
if ( $options['social_diaspora'] != "" ){ echo '<li class="diaspora"><a href="'.$options['social_diaspora'].'"><img src="'.get_template_directory_uri().'/images/social-media/diaspora-24x24.png" width="24" height="24" alt="Diaspora"></a></li>'; }
if ( $options['social_identica'] != "" ){ echo '<li class="identica"><a href="'.$options['social_identica'].'"><img src="'.get_template_directory_uri().'/images/social-media/identica-24x24.png" width="24" height="24" alt="identi.ca"></a></li>'; }
if ( $options['social_youtube'] != "" ){ echo '<li class="youtube"><a href="'.$options['social_youtube'].'"><img src="'.get_template_directory_uri().'/images/social-media/youtube-24x24.png" width="24" height="24" alt="YouTube"></a></li>'; }
if ( $options['social_itunes'] != "" ){ echo '<li class="itunes"><a href="'.$options['social_itunes'].'"><img src="'.get_template_directory_uri().'/images/social-media/itunes-24x24.png" width="24" height="24" alt="iTunes"></a></li>'; }
if ( $options['social_flickr'] != "" ){ echo '<li class="flickr"><a href="'.$options['social_flickr'].'"><img src="'.get_template_directory_uri().'/images/social-media/flickr-24x24.png" width="24" height="24" alt="flickr"></a></li>'; }
if ( $options['social_delicious'] != "" ){ echo '<li class="delicious"><a href="'.$options['social_delicious'].'"><img src="'.get_template_directory_uri().'/images/social-media/delicious-24x24.png" width="24" height="24" alt="Delicious"></a></li>'; }
if ( $options['social_flattr'] != "" ){ echo '<li class="flattr"><a href="'.$options['social_flattr'].'"><img src="'.get_template_directory_uri().'/images/social-media/flattr-24x24.png" width="24" height="24" alt="Flattr"></a></li>'; }
if ( $options['social_feed'] != "" ){ echo '<li class="feed"><a href="'.$options['social_feed'].'"><img src="'.get_template_directory_uri().'/images/social-media/feed-24x24.png" width="24" height="24" alt="RSS/Atom-Feed"></a></li>'; }
echo '</ul>';
if ($zeigeoption ==2) {
/* Links an der Seite */
echo '</div>';
}
}
endif;
if ( ! function_exists( 'get_piratenkleider_seitenmenu' ) ) :
/*
* Anzeige des Sidebar-Menus
*/
function get_piratenkleider_seitenmenu( $zeige_sidebarpagemenu = 1 , $zeige_subpagesonly =1 ){
global $defaultoptions;
global $post;
if ($zeige_sidebarpagemenu==1) {
if ($zeige_subpagesonly==1) {
//if the post has a parent
if($post->post_parent){
if($post->ancestors) {
$ancestors = end($post->ancestors);
$sidelinks = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");
} else {
$sidelinks .= wp_list_pages("sort_column=menu_order&title_li=&echo=0&depth=5&child_of=".$post->post_parent);
}
}else{
// display only main level and children
$sidelinks .= wp_list_pages("sort_column=menu_order&title_li=&echo=0&depth=5&child_of=".$post->ID);
}
if ($sidelinks) {
echo '<ul class="menu">';
echo $sidelinks;
echo '</ul>';
}
} else {
if ( has_nav_menu( 'primary' ) ) {
wp_nav_menu( array('depth' => 0, 'container_class' => 'menu-header', 'theme_location' => 'primary', 'walker' => new My_Walker_Nav_Menu()) );
} else {
echo '<ul class="menu">';
wp_page_menu( );
echo '</ul>';
}
}
}
}
endif;
if ( ! function_exists( 'get_piratenkleider_firstpicture' ) ) :
/*
* Erstes Bild aus einem Artikel auslesen, wenn dies vorhanden ist
*/
function get_piratenkleider_firstpicture($postid){
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if (!empty($first_img)){
$site_link = home_url();
$first_img = preg_replace("%$site_link%i",'', $first_img);
$imagehtml = '<img src="'.$first_img.'" alt="" width="130">';
return $imagehtml;
}
}
endif;
if ( ! function_exists( 'get_piratenkleider_custom_excerpt' ) ) :
/*
* Erstellen des Extracts
*/
function get_piratenkleider_custom_excerpt( ){
global $defaultoptions;
global $post;
if (has_excerpt()) {
return get_the_excerpt();
} else {
$excerpt = get_the_content();
if (!isset($excerpt)) {
$excerpt = 'Kein Inhalt';
}
}
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
if (mb_strlen($excerpt)<5) {
$excerpt = 'Kein Inhalt';
}
// $excerpt = closetags(strip_html_tags( $excerpt ));
if (mb_strlen($excerpt) > $defaultoptions['teaser_maxlength']) {
$the_str = mb_substr($excerpt, 0, $defaultoptions['teaser_maxlength']);
$the_str .= "...";
} else {
$the_str = $excerpt;
}
$the_str .= piratenkleider_continue_reading_link();
return $the_str;
}
endif;
if ( ! function_exists( 'short_title' ) ) :
/*
* Erstellen des Kurztitels
*/
function short_title($after = '...', $length = 6, $textlen = 10) {
$thistitle = get_the_title();
$mytitle = explode(' ', get_the_title());
if ((count($mytitle)>$length) || (mb_strlen($thistitle)> $textlen)) {
while(((count($mytitle)>$length) || (mb_strlen($thistitle)> $textlen)) && (count($mytitle)>1)) {
array_pop($mytitle);
$thistitle = implode(" ",$mytitle);
}
$morewords = 1;
} else {
$morewords = 0;
}
if (mb_strlen($thistitle)> $textlen) {
$thistitle = mb_substr($thistitle, 0, $textlen);
$morewords = 1;
}
if ($morewords==1) {
$thistitle .= $after;
}
return $thistitle;
}
endif;
if ( ! function_exists( 'piratenkleider_fetch_feed' ) ) :
/*
* Feet holen mit direkter Angabe der SimplePie-Parameter
*/
function piratenkleider_fetch_feed($url,$lifetime=0) {
global $defaultoptions;
$options = get_option( 'piratenkleider_theme_options' );
if (!isset($options['feed_cache_lifetime']))
$options['feed_cache_lifetime'] = $defaultoptions['feed_cache_lifetime'];
if ($lifetime==0){
$lifetime= $options['feed_cache_lifetime'];
}
if ($lifetime < 600) $lifetime = 1800;
// Das holen von feeds sollte auf keinen Fall haeufiger als alle 10 Minuten erfolgen
require_once (ABSPATH . WPINC . '/class-feed.php');
$feed = new SimplePie();
if ($defaultoptions['use_wp_feed_defaults']) {
$feed->set_cache_class('WP_Feed_Cache');
$feed->set_file_class('WP_SimplePie_File');
} else {
if ((isset($defaultoptions['dir_feed_cache'])) && (!empty($defaultoptions['dir_feed_cache']))) {
if (is_dir($defaultoptions['dir_feed_cache'])) {
$feed->set_cache_location($defaultoptions['dir_feed_cache']);
} else {
mkdir($defaultoptions['dir_feed_cache']);
if (!is_dir($defaultoptions['dir_feed_cache'])) {
echo "Wasnt able to create Feed-Cache directory";
} else {
$feed->set_cache_location($defaultoptions['dir_feed_cache']);
}
}
}
}
$feed->set_feed_url($url);
$feed->set_cache_duration($lifetime);
do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) );
$feed->init();
$feed->handle_content_type();
if ( $feed->error() )
return new WP_Error('simplepie-error', $feed->error());
return $feed;
}
endif;
function wpi_linkexternclass($content){
return preg_replace_callback('/<a[^>]+/', 'wpi_linkexternclass_callback', $content);
}
function wpi_linkexternclass_callback($matches)
{
$link = $matches[0];
$site_link = home_url();
if (strpos($link, 'class') === false)
{
$link = preg_replace("%(href=\S(?!$site_link))%i", 'class="extern" $1', $link);
}
return $link;
}
add_filter('the_content', 'wpi_linkexternclass');
add_action( 'template_redirect', 'rw_relative_urls' );
function rw_relative_urls() {
// Don't do anything if:
// - In feed
// - In sitemap by WordPress SEO plugin
if ( is_feed() || get_query_var( 'sitemap' ) )
return;
$filters = array(
'post_link',
'post_type_link',
'page_link',
'attachment_link',
'get_shortlink',
'post_type_archive_link',
'get_pagenum_link',
'get_comments_pagenum_link',
'term_link',
'search_link',
'day_link',
'month_link',
'year_link',
);
foreach ( $filters as $filter ) {
add_filter( $filter, 'wp_make_link_relative' );
}
}
function wpi_relativeurl($content){
return preg_replace_callback('/<a[^>]+/', 'wpi_relativeurl_callback', $content);
}
function wpi_relativeurl_callback($matches) {
$link = $matches[0];
$site_link = home_url();
$link = preg_replace("%href=\"$site_link%i", 'href="', $link);
return $link;
}
add_filter('the_content', 'wpi_relativeurl');
function dimox_breadcrumbs() {
global $defaultoptions;
$delimiter = '/';
$home = __( 'Startseite', 'piratenkleider' ); // text for the 'Home' link
$before = '<span class="current">'; // tag before the current crumb
$after = '</span>'; // tag after the current crumb
if ( !is_home() && !is_front_page() || is_paged() ) {
echo '<div id="crumbs">';
global $post;
$homeLink = home_url('/');
echo '<a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' ';
if ( is_category() ) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$thisCat = $cat_obj->term_id;
$thisCat = get_category($thisCat);
$parentCat = get_category($thisCat->parent);
if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
echo $before . __( 'Artikel der Kategorie ', 'piratenkleider' ). '"' . single_cat_title('', false) . '"' . $after;
} elseif ( is_day() ) {
echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
echo $before . get_the_time('d') . $after;
} elseif ( is_month() ) {
echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
echo $before . get_the_time('F') . $after;
} elseif ( is_year() ) {
echo $before . get_the_time('Y') . $after;
} elseif ( is_single() && !is_attachment() ) {
if ( get_post_type() != 'post' ) {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';
echo $before . get_the_title() . $after;
} else {
$cat = get_the_category(); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo $before . get_the_title() . $after;
}
} elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
$post_type = get_post_type_object(get_post_type());
echo $before . $post_type->labels->singular_name . $after;
} elseif ( is_attachment() ) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
echo $before . get_the_title() . $after;
} elseif ( is_page() && !$post->post_parent ) {
echo $before . get_the_title() . $after;
} elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
echo $before . get_the_title() . $after;
} elseif ( is_search() ) {
echo $before . __( 'Suche', 'piratenkleider' ).'"' . get_search_query() . '"' . $after;
} elseif ( is_tag() ) {
echo $before . __( 'Artikel mit Schlagwort ', 'piratenkleider' ). '"' . single_tag_title('', false) . '"' . $after;
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo $before . __( 'Artikel von ', 'piratenkleider' ). $userdata->display_name . $after;
} elseif ( is_404() ) {
echo $before . '404' . $after;
}
/*
if ( get_query_var('paged') ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
echo __('Page', 'piratenkleider') . ' ' . get_query_var('paged');
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
}
*/
echo '</div>';
}
}
if( !is_admin()){
wp_deregister_script('jquery');
// muss trotz ThemeCheck Warnung drin bleiben, ansonsten wird veraltetes jQuery geladen
// und der Slider und anderes mag dann nicht mehr
wp_register_script('jquery', $defaultoptions['src-jquery'] , false, "1.7.2");
wp_enqueue_script('jquery');
wp_register_script('layoutjs', $defaultoptions['src-layoutjs'] , false, $defaultoptions['js-version']);
wp_enqueue_script('layoutjs');
wp_register_script('yaml-focusfix', $defaultoptions['src-yaml-focusfix'] , false, $defaultoptions['js-version']);
wp_enqueue_script('yaml-focusfix');
wp_deregister_script('comment-reply');
if (!isset($options['aktiv-commentreplylink']))
$options['aktiv-commentreplylink'] = $defaultoptions['aktiv-commentreplylink'];
if ($options['aktiv-commentreplylink']==1) {
wp_register_script('comment-reply', $defaultoptions['src-comment-reply'] , false, $defaultoptions['js-version']);
wp_enqueue_script('comment-reply');
}
if (!isset($options['aktiv-dynamic-sidebar']))
$options['aktiv-dynamic-sidebar'] = $defaultoptions['aktiv-dynamic-sidebar'];
if ($options['aktiv-dynamic-sidebar']==1) {
wp_register_script('dynamic-sidebar', $defaultoptions['src-dynamic-sidebar'] , false, $defaultoptions['js-version']);
wp_enqueue_script('dynamic-sidebar');
}
}
function piratenkleider_header_style() {}
function piratenkleider_admin_head() {
echo '<link rel="stylesheet" type="text/css" href="'.get_template_directory_uri().'/css/admin.css" />';
}
add_action('admin_head', 'piratenkleider_admin_head');
function custom_login() {
echo '<link rel="stylesheet" type="text/css" href="'.get_template_directory_uri().'/css/custom-login.css" />';
}
add_action('login_head', 'custom_login');