functions.php 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814
  1. <?php
  2. /**
  3. * Piratenkleider 3 Theme Optionen
  4. *
  5. * @source http://github.com/xwolfde/Piratenkleider
  6. * @creator xwolf
  7. * @version 3.2
  8. * @licence GPL 2.0
  9. */
  10. // Make theme available for translation
  11. // Translations can be filed in the /languages/ directory
  12. load_theme_textdomain('piratenkleider', get_template_directory() . '/languages');
  13. $locale = get_locale();
  14. $locale_file = get_template_directory() . "/languages/$locale.php";
  15. if ( is_readable( $locale_file ) )
  16. require_once( $locale_file );
  17. require( get_template_directory() . '/inc/constants.php' );
  18. $options = piratenkleider_initoptions();
  19. // adjusts variables for downwards comptability
  20. if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  21. $xffaddrs = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
  22. $_SERVER['REMOTE_ADDR'] = $xffaddrs[0];
  23. }
  24. $_SERVER['REMOTE_ADDR'] = getAnonymIp($_SERVER['REMOTE_ADDR']);
  25. if ($options['anonymize-user']==1) {
  26. /* IP-Adresse überschreiben */
  27. $_SERVER["REMOTE_ADDR"] = "0.0.0.0";
  28. /* UA-String überschreiben */
  29. $_SERVER["HTTP_USER_AGENT"] = "";
  30. update_option('require_name_email',0);
  31. }
  32. require_once ( get_template_directory() . '/inc/theme-options.php' );
  33. require( get_template_directory() . '/inc/custom-posts.php' );
  34. require( get_template_directory() . '/inc/business-cards.php' );
  35. require( get_template_directory() . '/inc/custom-fields.php' );
  36. if ( ! function_exists( 'piratenkleider_setup' ) ):
  37. function piratenkleider_setup() {
  38. global $defaultoptions;
  39. global $options;
  40. if ( ! isset( $content_width ) ) $content_width = $defaultoptions['content-width'];
  41. // This theme styles the visual editor with editor-style.css to match the theme style.
  42. add_editor_style();
  43. // This theme uses post thumbnails
  44. add_theme_support( 'post-thumbnails' );
  45. // Add default posts and comments RSS feed links to head
  46. add_theme_support( 'automatic-feed-links' );
  47. /* Categories also for Pages to make the pageindex over categories work */
  48. add_action( 'init', 'enable_category_taxonomy_for_pages', 500 );
  49. function enable_category_taxonomy_for_pages() {
  50. register_taxonomy_for_object_type('category','page');
  51. }
  52. $args = array(
  53. 'width' => 0,
  54. 'height' => 0,
  55. 'default-image' => $defaultoptions['logo'],
  56. 'uploads' => true,
  57. 'random-default' => false,
  58. 'flex-height' => true,
  59. 'flex-width' => true,
  60. 'header-text' => false,
  61. 'suggested-height' => $defaultoptions['logo-height'],
  62. 'suggested-width' => $defaultoptions['logo-width'],
  63. 'max-width' => 350,
  64. );
  65. add_theme_support( 'custom-header', $args );
  66. $args = array(
  67. 'default-color' => $defaultoptions['background-header-color'],
  68. 'default-image' => $defaultoptions['background-header-image'],
  69. 'background_repeat' => 'repeat-x',
  70. 'default-position-x' => 'left',
  71. 'wp-head-callback' => 'piratenkleider_custom_background_cb',
  72. );
  73. /**
  74. * piratenkleider custom background callback.
  75. *
  76. */
  77. function piratenkleider_custom_background_cb() {
  78. global $defaultoptions;
  79. global $options;
  80. // $background is the saved custom image, or the default image.
  81. $background = set_url_scheme( get_background_image() );
  82. // $color is the saved custom color.
  83. // A default has to be specified in style.css. It will not be printed here.
  84. $color = get_theme_mod( 'background_color' );
  85. if ( ! $background && ! $color )
  86. return;
  87. $style = $color ? "background-color: #$color;" : '';
  88. if ( $background ) {
  89. $image = " background-image: url('$background');";
  90. if ($background == $defaultoptions['background-header-image']) {
  91. $style .= $image;
  92. } else {
  93. $repeat = get_theme_mod( 'background_repeat', 'repeat-x' );
  94. if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) )
  95. $repeat = 'repeat-x';
  96. $repeat = " background-repeat: $repeat;";
  97. $positionx = get_theme_mod( 'background_position_x', 'left' );
  98. if ( ! in_array( $positionx, array( 'center', 'right', 'left' ) ) )
  99. $positionx = 'left';
  100. $positiony = get_theme_mod( 'background_position_y', 'top' );
  101. if ( ! in_array( $positiony, array( 'top', 'bottom' ) ) )
  102. $positiony = 'top';
  103. $position = " background-position: $positionx $positiony;";
  104. $attachment = get_theme_mod( 'background_attachment', 'scroll' );
  105. if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
  106. $attachment = 'scroll';
  107. $attachment = " background-attachment: $attachment;";
  108. $style .= $image . $repeat . $position . $attachment;
  109. }
  110. }
  111. echo '<style type="text/css" id="custom-background-css">';
  112. echo '.header { '.trim( $style ).' } ';
  113. echo '</style>';
  114. }
  115. add_theme_support( 'custom-background', $args );
  116. if ( function_exists( 'add_theme_support' ) ) {
  117. add_theme_support( 'post-thumbnails' );
  118. set_post_thumbnail_size( 150, 150 ); // default Post Thumbnail dimensions
  119. }
  120. if ( function_exists( 'add_image_size' ) ) {
  121. add_image_size( 'teaser-thumb', $options['teaser-thumbnail_width'], $options['teaser-thumbnail_height'], $options['teaser-thumbnail_crop'] );
  122. add_image_size( 'linktipp-thumb', $options['linktipp-thumbnail_width'], $options['linktipp-thumbnail_height'], $options['linktipp-thumbnail_crop'] );
  123. add_image_size( 'person-thumb', $options['person-thumbnail_width'], $options['person-thumbnail_height'], $options['person-thumbnail_crop'] );
  124. add_image_size( $options['sidebar-thumbnail_name'], $options['sidebar-thumbnail_width'], $options['sidebar-thumbnail_height'], $options['sidebar-thumbnail_crop'] );
  125. add_image_size( $options['bannerlink_name'], $options['bannerlink-width'] );
  126. }
  127. // This theme uses wp_nav_menu() in one location.
  128. register_nav_menus( array(
  129. 'primary' => __( 'Main navigation', 'piratenkleider' ),
  130. 'top' => __( 'Website Menu', 'piratenkleider' ),
  131. 'sub' => __( 'Tecnical navigation', 'piratenkleider' ),
  132. ) );
  133. if ($options['login_errors']==0) {
  134. /** Abschalten von Fehlermeldungen auf der Loginseite */
  135. add_filter('login_errors', create_function('$a', "return null;"));
  136. }
  137. /** Entfernen der Wordpressversionsnr im Header */
  138. remove_action('wp_head', 'wp_generator');
  139. /* Zulassen von Shortcodes in Widgets */
  140. add_filter('widget_text', 'do_shortcode');
  141. if ($options['yt-alternativeembed']) {
  142. /* Filter fuer YouTube Embed mit nocookie: */
  143. wp_embed_register_handler( 'ytnocookie', '#https?://www\.youtube\-nocookie\.com/embed/([a-z0-9\-_]+)#i', 'wp_embed_handler_ytnocookie' );
  144. wp_embed_register_handler( 'ytnormal', '#https?://www\.youtube\.com/watch\?v=([a-z0-9\-_]+)#i', 'wp_embed_handler_ytnocookie' );
  145. wp_embed_register_handler( 'ytnormal2', '#https?://www\.youtube\.com/watch\?feature=player_embedded&v=([a-z0-9\-_]+)#i', 'wp_embed_handler_ytnocookie' );
  146. }
  147. function wp_embed_handler_ytnocookie( $matches, $attr, $url, $rawattr ) {
  148. global $defaultoptions;
  149. $relvideo = '';
  150. if ($defaultoptions['yt-norel']==1) {
  151. $relvideo = '?rel=0';
  152. }
  153. $embed = sprintf(
  154. '<div class="embed-youtube" itemprop="video" itemscope itemtype="http://schema.org/VideoObject"><p>YouTube-Video: <a href="https://www.youtube.com/watch?v=%2$s">https://www.youtube.com/watch?v=%2$s</a></p><iframe itemprop="embedUrl" src="https://www.youtube-nocookie.com/embed/%2$s%5$s" width="%3$spx" height="%4$spx" frameborder="0" scrolling="no" marginwidth="0" marginheight="0"></iframe></div>',
  155. get_template_directory_uri(),
  156. esc_attr($matches[1]),
  157. $defaultoptions['yt-content-width'],
  158. $defaultoptions['yt-content-height'],
  159. $relvideo
  160. );
  161. return apply_filters( 'embed_ytnocookie', $embed, $matches, $attr, $url, $rawattr );
  162. }
  163. if (isset($options['feed-overwriteauthorstring']) && (strlen(trim($options['feed-overwriteauthorstring']))>1 )) {
  164. add_filter( 'the_author', 'feed_author' );
  165. function feed_author($name) {
  166. global $options;
  167. if( is_feed() && !is_admin()) {
  168. return $options['feed-overwriteauthorstring'];
  169. } else {
  170. return $name;
  171. }
  172. }
  173. }
  174. }
  175. endif;
  176. add_action( 'after_setup_theme', 'piratenkleider_setup' );
  177. require( get_template_directory() . '/inc/widgets.php' );
  178. function piratenkleider_scripts() {
  179. global $options;
  180. global $defaultoptions;
  181. $userstyle = 0;
  182. if ( !is_admin() ) {
  183. $userstyle = 0;
  184. if ((isset($options['aktiv-stylefile']) && ($options['aktiv-stylefile'] > 0) && (wp_get_attachment_url($options['aktiv-stylefile'])) )
  185. && (isset($options['stylefile-position'])) && ($options['stylefile-position']>0)) {
  186. $userstyle = 1;
  187. }
  188. if (($userstyle==1) && ($options['stylefile-position']==1)) {
  189. wp_enqueue_style( 'stylefile', wp_get_attachment_url($options['aktiv-stylefile']));
  190. }
  191. if (($userstyle==0) || (($userstyle==1) && ($options['stylefile-position']<3))) {
  192. if ((isset($options['aktiv-alternativestyle'])) && ($options['aktiv-alternativestyle'] != 'style.css')) {
  193. wp_enqueue_style( 'alternativestyle', get_template_directory_uri().'/css/'.$options['aktiv-alternativestyle'] );
  194. } else {
  195. $theme = wp_get_theme();
  196. wp_register_style( 'piratenkleider', get_bloginfo( 'stylesheet_url' ), false, $theme['Version'] );
  197. wp_enqueue_style( 'piratenkleider' );
  198. }
  199. }
  200. if (($userstyle==1) && ($options['stylefile-position'] > 1)) {
  201. wp_enqueue_style( 'stylefile', wp_get_attachment_url($options['aktiv-stylefile']));
  202. }
  203. if (($userstyle==0) || (($userstyle==1) && ($options['stylefile-position']!=4))) {
  204. if ((isset($options['css-colorfile'])) && (strlen(trim($options['css-colorfile']))>2)) {
  205. wp_enqueue_style( 'color', get_template_directory_uri().'/css/'.$options['css-colorfile'] );
  206. }
  207. if ((isset($options['aktiv-linkicons'])) && ($options['aktiv-linkicons']==1)) {
  208. wp_enqueue_style( 'basemod_linkicons', $defaultoptions['src-linkicons-css'] );
  209. }
  210. if ( is_singular() ) {
  211. $nosidebar = get_post_meta( get_the_ID(), 'piratenkleider_nosidebar', true );
  212. $custom_fields = get_post_custom();
  213. if ( ( !empty( $nosidebar ) && $nosidebar==1)
  214. || ((isset($custom_fields['fullsize'])) && ($custom_fields['fullsize'][0] == true))) {
  215. wp_enqueue_style( 'basemod_sidebarbottom', $defaultoptions['src-basemod_sidebarbottom'] );
  216. }
  217. }
  218. if ((isset($options['position_sidebarbottom'])) && ($options['position_sidebarbottom'] ==1)) {
  219. wp_enqueue_style( 'basemod_sidebarbottom', $defaultoptions['src-basemod_sidebarbottom'] );
  220. }
  221. }
  222. if ((isset($options['aktiv-hamburger'])) && ($options['aktiv-hamburger']==1)) {
  223. wp_enqueue_style( 'hamburger', $defaultoptions['src-hamburger-css'] );
  224. wp_enqueue_script( 'hamburger', $defaultoptions['src-hamburger-js'], array('jquery', 'jquery-ui-core'), $defaultoptions['js-version'] );
  225. }
  226. wp_enqueue_script( 'layoutjs', $defaultoptions['src-layoutjs'], array('jquery'), $defaultoptions['js-version'] );
  227. if (is_singular() && ($options['aktiv-commentreplylink']==1) && get_option( 'thread_comments' )) {
  228. wp_enqueue_script(
  229. 'comment-reply',
  230. $defaultoptions['src-comment-reply'],
  231. false,
  232. $defaultoptions['js-version']
  233. );
  234. }
  235. }
  236. }
  237. add_action('wp_enqueue_scripts', 'piratenkleider_scripts');
  238. function piratenkleider_dequeue_fonts() {
  239. wp_dequeue_style( 'twentytwelve-fonts' );
  240. }
  241. add_action( 'wp_enqueue_scripts', 'piratenkleider_dequeue_fonts', 11 );
  242. function piratenkleider_addfonts() {
  243. global $options;
  244. global $default_fonts;
  245. $output = "";
  246. $setfont = "";
  247. if ((isset($options['fonts-content'])) && ($options['fonts-content'] != 'none')) {
  248. $setfont = $options['fonts-content'];
  249. $seturl=0;
  250. if (isset($default_fonts[$setfont]['webfont'])
  251. && ($default_fonts[$setfont]['webfont']==1)) {
  252. $output .= '@font-face { font-family: FontPiratenkleiderDefault; local: '.$setfont.'; src: ';
  253. if (isset($default_fonts[$setfont]['eot'])) {
  254. $output .= 'url('.get_template_directory_uri().$default_fonts[$setfont]['eot'].') format("embedded-opentype")';
  255. $seturl = 1;
  256. }
  257. if (isset($default_fonts[$setfont]['ttf'])) {
  258. if ($seturl==1) $output .= ", ";
  259. $output .= 'url('.get_template_directory_uri().$default_fonts[$setfont]['ttf'].') format("truetype")';
  260. $seturl = 1;
  261. }
  262. if (isset($default_fonts[$setfont]['woff'])) {
  263. if ($seturl==1) $output .= ", ";
  264. $output .= 'url('.get_template_directory_uri().$default_fonts[$setfont]['woff'].') format("woff")';
  265. $seturl = 1;
  266. }
  267. if (isset($default_fonts[$setfont]['svg'])) {
  268. if ($seturl==1) $output .= ", ";
  269. $output .= 'url('.get_template_directory_uri().$default_fonts[$setfont]['svg'].') format("svg")';
  270. } $output .= ";}\n";
  271. $output .= "body,.defaultfont,.teaserlinks ul li a span { font-family: FontPiratenkleiderDefault; }\n";
  272. } else {
  273. $output .= 'body,.defaultfont,.teaserlinks ul li a span { font-family: '.$default_fonts[$setfont]['family'].'; }';
  274. $output .= "\n";
  275. }
  276. }
  277. if ((isset($options['fonts-headers'])) && ($options['fonts-headers'] != 'none')) {
  278. $setfont = $options['fonts-headers'];
  279. $seturl=0;
  280. if (isset($default_fonts[$setfont]['webfont'])
  281. && ($default_fonts[$setfont]['webfont']==1)) {
  282. $output .= '@font-face { font-family: FontPiratenkleiderHeadlines; local: '.$setfont.'; src: ';
  283. if (isset($default_fonts[$setfont]['eot'])) {
  284. $output .= 'url('.get_template_directory_uri().$default_fonts[$setfont]['eot'].') format("embedded-opentype")';
  285. $seturl = 1;
  286. }
  287. if (isset($default_fonts[$setfont]['ttf'])) {
  288. if ($seturl==1) $output .= ", ";
  289. $output .= 'url('.get_template_directory_uri().$default_fonts[$setfont]['ttf'].') format("truetype")';
  290. $seturl = 1;
  291. }
  292. if (isset($default_fonts[$setfont]['woff'])) {
  293. if ($seturl==1) $output .= ", ";
  294. $output .= 'url('.get_template_directory_uri().$default_fonts[$setfont]['woff'].') format("woff")';
  295. $seturl = 1;
  296. }
  297. if (isset($default_fonts[$setfont]['svg'])) {
  298. if ($seturl==1) $output .= ", ";
  299. $output .= 'url('.get_template_directory_uri().$default_fonts[$setfont]['svg'].') format("svg")';
  300. } $output .= ";}\n";
  301. $output .= "h1,h2,h3,h4,h5,h6,.headlinefont,.tagcloud,.post-nav a,.first-startpage-widget-area li a { font-family: FontPiratenkleiderHeadlines; }\n";
  302. } else {
  303. $output .= 'h1,h2,h3,h4,h5,h6,.headlinefont,.tagcloud,.post-nav a,.first-startpage-widget-area li a { font-family: '.$default_fonts[$setfont]['family'].'; }';
  304. $output .= "\n";
  305. }
  306. }
  307. if ((isset($options['fonts-menuheaders'])) && ($options['fonts-menuheaders'] != 'none')) {
  308. $setfont = $options['fonts-menuheaders'];
  309. $seturl=0;
  310. if (isset($default_fonts[$setfont]['webfont'])
  311. && ($default_fonts[$setfont]['webfont']==1)) {
  312. $output .= '@font-face { font-family: FontPiratenkleiderMenuHeadlines; local: '.$setfont.'; src: ';
  313. if (isset($default_fonts[$setfont]['eot'])) {
  314. $output .= 'url('.get_template_directory_uri().$default_fonts[$setfont]['eot'].') format("embedded-opentype")';
  315. $seturl = 1;
  316. }
  317. if (isset($default_fonts[$setfont]['ttf'])) {
  318. if ($seturl==1) $output .= ", ";
  319. $output .= 'url('.get_template_directory_uri().$default_fonts[$setfont]['ttf'].') format("truetype")';
  320. $seturl = 1;
  321. }
  322. if (isset($default_fonts[$setfont]['woff'])) {
  323. if ($seturl==1) $output .= ", ";
  324. $output .= 'url('.get_template_directory_uri().$default_fonts[$setfont]['woff'].') format("woff")';
  325. $seturl = 1;
  326. }
  327. if (isset($default_fonts[$setfont]['svg'])) {
  328. if ($seturl==1) $output .= ", ";
  329. $output .= 'url('.get_template_directory_uri().$default_fonts[$setfont]['svg'].') format("svg")';
  330. }
  331. $output .= ";}\n";
  332. $output .= ".menufont, .nav-main ul.menu li a,.cifont,.sticker ul li,.teaserlinks ul li a { font-family: FontPiratenkleiderMenuHeadlines; }\n";
  333. } else {
  334. $output .= '.menufont,.nav-main ul.menu li a,.cifont,.sticker ul li,.teaserlinks ul li a { font-family: '.$default_fonts[$setfont]['family'].'; }';
  335. $output .= "\n";
  336. }
  337. }
  338. $out = '';
  339. if ((isset($output)) && (strlen($output)>1)) {
  340. $out = "<style>";
  341. $out .= $output;
  342. $out .= "</style>\n";
  343. }
  344. echo $out;
  345. }
  346. add_action('wp_head', 'piratenkleider_addfonts');
  347. function piratenkleider_addaltbodybackground() {
  348. global $options;
  349. if ((isset($options['alt-body-background'])) && (isset($options['alt-body-background_id'])) && $options['alt-body-background_id']>0) {
  350. if (isset($options['alt-body-background-orix'])) {
  351. $orix = $options['alt-body-background-orix'];
  352. }
  353. if (isset($options['alt-body-background-oriy'])) {
  354. $oriy = $options['alt-body-background-oriy'];
  355. }
  356. if (isset($options['alt-body-background-repeat'])) {
  357. $repeat = $options['alt-body-background-repeat'];
  358. }
  359. $out = "<style>";
  360. $out .= 'body { background-image: url("'.$options['alt-body-background'].'");';
  361. if (isset($repeat)) {
  362. $out.= 'background-repeat:'.$repeat.';';
  363. }
  364. if ((isset($orix)) &&(isset($oriy))) {
  365. $out.= 'background-position:'.$orix.' '.$oriy.';';
  366. }
  367. $out .= 'background-attachment:fixed; }';
  368. $out .= "</style>\n";
  369. echo $out;
  370. }
  371. }
  372. add_action('wp_head', 'piratenkleider_addaltbodybackground');
  373. function piratenkleider_addmetatags() {
  374. global $options;
  375. $output = "";
  376. $output .= '<meta http-equiv="Content-Type" content="text/html; charset='.get_bloginfo('charset').'" />'."\n";
  377. $output .= '<!--[if IE]> <meta http-equiv="X-UA-Compatible" content="IE=9"> <![endif]-->'."\n";
  378. $output .= '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n";
  379. if ((isset( $options['meta-description'] )) && ( strlen(trim($options['meta-description']))>1 )) {
  380. $output .= '<meta name="description" content="'.$options['meta-description'].'">'."\n";
  381. }
  382. if ((isset( $options['meta-author'] )) && ( strlen(trim($options['meta-author']))>1 )) {
  383. $output .= '<meta name="author" content="'.$options['meta-author'].'">'."\n";
  384. }
  385. if ((isset( $options['meta-verify-v1'] )) && ( strlen(trim($options['meta-verify-v1']))>1 )) {
  386. $output .= '<meta name="google-site-verification" content="'.$options['meta-verify-v1'].'">'."\n";
  387. }
  388. $tags = '';
  389. if ($options['aktiv-autokeywords']) {
  390. $posttags = get_the_tags();
  391. $csv_tags = '';
  392. if ($posttags) {
  393. foreach($posttags as $tag) {
  394. $csv_tags .= $tag->name . ',';
  395. }
  396. $tags = substr( $csv_tags,0,-1);
  397. }
  398. }
  399. if ((isset($options['meta-keywords'])) && (strlen(trim($options['meta-keywords']))>1 )) {
  400. if (strlen($tags) > 0) {
  401. $tags = $options['meta-keywords'].','.$tags;
  402. } else {
  403. $tags = $options['meta-keywords'];
  404. }
  405. }
  406. if ((strlen(trim($tags))>2 )) {
  407. if (strlen(trim($tags))>$options['meta-maxlengthvalue']) {
  408. $tags = substr($tags,0,strpos($tags,",",$options['meta-maxlengthvalue']));
  409. }
  410. $output .= '<meta name="keywords" content="'.$tags.'">'."\n";
  411. }
  412. if ((isset($options['favicon-file'])) && ($options['favicon-file_id']>0 )) {
  413. $output .= '<link rel="shortcut icon" href="'.$options['favicon-file'].'">'."\n";
  414. } else {
  415. $output .= '<link rel="apple-touch-icon" href="'.get_template_directory_uri().'/apple-touch-icon.png">'."\n";
  416. $output .= '<link rel="shortcut icon" href="'.get_template_directory_uri().'/favicon.ico">'."\n";
  417. }
  418. echo $output;
  419. }
  420. add_action('wp_head', 'piratenkleider_addmetatags',1);
  421. /* Anonymize IP */
  422. function getAnonymIp( $ip, $strongness = 2 ) {
  423. if ($strongness==2) {
  424. if( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ){
  425. /* IPv4 - Strong BSI Norm: last two oktetts to 0 */
  426. return preg_replace('/[0-9]+.[0-9]+\z/', '0.0', $ip);
  427. } else {
  428. /* IPv6 */
  429. return preg_replace('/[a-z0-9]*:[a-z0-9]*:[a-z0-9]*:[a-z0-9]*:[a-z0-9]*\z/', '0:0:0:0:0', $ip);
  430. }
  431. } elseif ($strongness==1) {
  432. if( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ){
  433. /* Weak BSI Norm: last two oktetts to 0 */
  434. return preg_replace('/[0-9]+\z/', '0', $ip);
  435. } else {
  436. /* IPv6 */
  437. return preg_replace('/[a-z0-9]*:[a-z0-9]*:[a-z0-9]*:[a-z0-9]*\z/', '0:0:0:0', $ip);
  438. }
  439. } elseif ($strongness==0) {
  440. /* No anonymizing */
  441. return $ip;
  442. } else {
  443. if( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ){
  444. /* IPv4 - Strong BSI Norm: last two oktetts to 0 */
  445. return preg_replace('/[0-9]+.[0-9]+\z/', '0.0', $ip);
  446. } else {
  447. /* IPv6 */
  448. return preg_replace('/[a-z0-9]*:[a-z0-9]*:[a-z0-9]*:[a-z0-9]*:[a-z0-9]*\z/', '0:0:0:0:0', $ip);
  449. }
  450. }
  451. }
  452. function feed_lifetime_cb( ) {
  453. global $options;
  454. return $options['feed_cache_lifetime'];
  455. }
  456. add_filter( 'wp_feed_cache_transient_lifetime' , 'feed_lifetime_cb' );
  457. function piratenkleider_avatar ($avatar_defaults) {
  458. global $defaultoptions;
  459. $myavatar = $defaultoptions['src-default-avatar'];
  460. $avatar_defaults[$myavatar] = "Piratenkleider";
  461. return $avatar_defaults;
  462. }
  463. add_filter( 'avatar_defaults', 'piratenkleider_avatar' );
  464. /* Refuse spam-comments on media */
  465. function filter_media_comment_status( $open, $post_id ) {
  466. $post = get_post( $post_id );
  467. if( $post->post_type == 'attachment' ) {
  468. return false;
  469. }
  470. return $open;
  471. }
  472. add_filter( 'comments_open', 'filter_media_comment_status', 10 , 2 );
  473. /* Format list for Tagclouds also in widgets */
  474. function edit_args_tag_cloud_widget($args) {
  475. $args = array('format' => 'list');
  476. return $args;
  477. }
  478. add_filter('widget_tag_cloud_args','edit_args_tag_cloud_widget');
  479. if ( ! function_exists( 'get_piratenkleider_options' ) ) :
  480. /*
  481. * Erstes Bild aus einem Artikel auslesen, wenn dies vorhanden ist
  482. */
  483. function get_piratenkleider_options( $field ){
  484. global $defaultoptions;
  485. if (!isset($field)) {
  486. $field = 'piratenkleider_theme_options';
  487. }
  488. $orig = get_option($field);
  489. if (!is_array($orig)) {
  490. $orig=array();
  491. }
  492. $alloptions = array_merge( $defaultoptions, $orig );
  493. return $alloptions;
  494. }
  495. endif;
  496. function piratenkleider_initoptions() {
  497. global $defaultoptions;
  498. global $default_toplink_liste;
  499. // $doupdate = 0;
  500. $oldoptions = get_option('piratenkleider_theme_options');
  501. if (isset($oldoptions) && (is_array($oldoptions))) {
  502. $newoptions = array_merge($defaultoptions,$oldoptions);
  503. } else {
  504. $newoptions = $defaultoptions;
  505. $newoptions['toplinkliste'] = $default_toplink_liste;
  506. }
  507. // if ($doupdate==1) {
  508. // update_option('piratenkleider_theme_options', $newoptions);
  509. // }
  510. return $newoptions;
  511. }
  512. if ( ! function_exists( 'piratenkleider_get_image_attributs' ) ) :
  513. function piratenkleider_get_image_attributs($id=0) {
  514. $precopyright = __('Image:','piratenkleider').' ';
  515. if ($id==0) return;
  516. $meta = get_post_meta( $id );
  517. if (!isset($meta)) {
  518. return;
  519. }
  520. $result = array();
  521. if (isset($meta['_wp_attachment_image_alt'][0])) {
  522. $result['alt'] = trim(strip_tags($meta['_wp_attachment_image_alt'][0]));
  523. } else {
  524. $result['alt'] = "";
  525. }
  526. if (isset($meta['_wp_attachment_metadata']) && is_array($meta['_wp_attachment_metadata'])) {
  527. $data = unserialize($meta['_wp_attachment_metadata'][0]);
  528. if (isset($data['image_meta']) && is_array($data['image_meta']) && isset($data['image_meta']['copyright'])) {
  529. $result['copyright'] = trim(strip_tags($data['image_meta']['copyright']));
  530. }
  531. }
  532. $attachment = get_post($id);
  533. $result['beschriftung'] = $result['beschreibung'] = $result['title'] = '';
  534. if (isset($attachment) ) {
  535. if (isset($attachment->post_excerpt)) {
  536. $result['beschriftung'] = trim(strip_tags( $attachment->post_excerpt ));
  537. }
  538. if (isset($attachment->post_content)) {
  539. $result['beschreibung'] = trim(strip_tags( $attachment->post_content ));
  540. }
  541. if (isset($attachment->post_title)) {
  542. $result['title'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title
  543. }
  544. }
  545. $displayinfo = $result['beschriftung'];
  546. if (empty($displayinfo) && !empty($result['copyright'])) $displayinfo = $precopyright.$result['copyright'];
  547. if (empty($displayinfo)) $displayinfo = $result['alt'];
  548. $result['credits'] = $displayinfo;
  549. return $result;
  550. }
  551. endif;
  552. if ( ! function_exists( 'piratenkleider_filter_wp_title' ) ) :
  553. /*
  554. * Sets the title
  555. */
  556. function piratenkleider_filter_wp_title( $title, $separator ) {
  557. // Don't affect wp_title() calls in feeds.
  558. if ( is_feed() )
  559. return $title;
  560. global $paged, $page;
  561. if ( is_search() ) {
  562. $title = sprintf( __( 'Search results for %s', 'piratenkleider' ), '"' . get_search_query() . '"' );
  563. if ( $paged >= 2 )
  564. $title .= " $separator " . sprintf( __( 'Page %s', 'piratenkleider' ), $paged );
  565. $title .= " $separator " . get_bloginfo( 'name', 'display' );
  566. return $title;
  567. }
  568. $title .= get_bloginfo( 'name', 'display' );
  569. $site_description = get_bloginfo( 'description', 'display' );
  570. if ( $site_description && ( is_home() || is_front_page() ) )
  571. $title .= " $separator " . $site_description;
  572. if ( $paged >= 2 || $page >= 2 )
  573. $title .= " $separator " . sprintf( __( 'Page %s', 'piratenkleider' ), max( $paged, $page ) );
  574. return $title;
  575. }
  576. endif;
  577. add_filter( 'wp_title', 'piratenkleider_filter_wp_title', 10, 2 );
  578. function piratenkleider_excerpt_length( $length ) {
  579. global $defaultoptions;
  580. return $defaultoptions['teaser_maxlength'];
  581. }
  582. add_filter( 'excerpt_length', 'piratenkleider_excerpt_length' );
  583. function piratenkleider_continue_reading_link() {
  584. return ' <a class="nobr" title="'.strip_tags(get_the_title()).'" href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'piratenkleider' ) . '</a>';
  585. }
  586. function piratenkleider_auto_excerpt_more( $more ) {
  587. return ' &hellip;' . piratenkleider_continue_reading_link();
  588. }
  589. add_filter( 'excerpt_more', 'piratenkleider_auto_excerpt_more' );
  590. function piratenkleider_custom_excerpt_more( $output ) {
  591. if ( has_excerpt() && ! is_attachment() ) {
  592. $output .= piratenkleider_continue_reading_link();
  593. }
  594. return $output;
  595. }
  596. add_filter( 'get_the_excerpt', 'piratenkleider_custom_excerpt_more' );
  597. function piratenkleider_remove_gallery_css( $css ) {
  598. return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
  599. }
  600. add_filter( 'gallery_style', 'piratenkleider_remove_gallery_css' );
  601. function honor_ssl_for_attachments($url) {
  602. $http = site_url(FALSE, 'http');
  603. $https = site_url(FALSE, 'https');
  604. return is_ssl() ? str_replace($http, $https, $url) : $url;
  605. }
  606. add_filter('wp_get_attachment_url', 'honor_ssl_for_attachments');
  607. if ( ! function_exists( 'piratenkleider_comment' ) ) :
  608. /**
  609. * Template for comments and pingbacks.
  610. */
  611. function piratenkleider_comment( $comment, $args, $depth ) {
  612. $GLOBALS['comment'] = $comment;
  613. global $defaultoptions;
  614. global $options;
  615. switch ( $comment->comment_type ) :
  616. case '' :
  617. ?>
  618. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  619. <div id="comment-<?php comment_ID(); ?>">
  620. <article itemprop="comment" itemscope itemtype="http://schema.org/UserComments">
  621. <header>
  622. <div class="comment-details">
  623. <div class="comment-author vcard" itemprop="creator" itemscope itemtype="http://schema.org/Person">
  624. <?php if ($options['aktiv-avatar']==1) {
  625. echo '<div class="avatar" itemprop="image">';
  626. echo get_avatar( $comment, 48, $defaultoptions['src-default-avatar']);
  627. echo '</div>';
  628. }
  629. printf( __( '%s <span class="says">commented at</span>', 'piratenkleider' ), sprintf( '<cite class="fn" itemprop="name">%s</cite>', get_comment_author_link() ) );
  630. ?>
  631. </div><!-- .comment-author .vcard -->
  632. <?php if ( $comment->comment_approved == '0' ) : ?>
  633. <em><?php _e( 'Comment waits for approval.', 'piratenkleider' ); ?></em>
  634. <br />
  635. <?php endif; ?>
  636. <div class="comment-meta commentmetadata"><a itemprop="url" href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"><time itemprop="commentTime" datetime="<?php comment_time('c'); ?>">
  637. <?php
  638. /* translators: 1: date, 2: time */
  639. printf( __( '%1$s at %2$s', 'piratenkleider' ), get_comment_date(), get_comment_time() ); ?></time></a> Folgendes:<?php edit_comment_link( __( '(Edit)', 'piratenkleider' ), ' ' );
  640. ?>
  641. </div><!-- .comment-meta .commentmetadata -->
  642. </div>
  643. </header>
  644. <div class="comment-body" itemprop="commentText"><?php comment_text(); ?></div>
  645. <?php if ($options['aktiv-commentreplylink']) { ?>
  646. <div class="reply">
  647. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  648. </div> <!-- .reply -->
  649. <?php } ?>
  650. </article>
  651. </div><!-- #comment-## -->
  652. <?php
  653. break;
  654. case 'pingback' :
  655. case 'trackback' :
  656. ?>
  657. <li class="post pingback">
  658. <p><?php _e( 'Pingback:', 'piratenkleider' ); ?> <?php comment_author_link(); edit_comment_link( __('Edit', 'piratenkleider'), ' ' ); ?></p>
  659. <?php
  660. break;
  661. endswitch;
  662. }
  663. endif;
  664. function piratenkleider_remove_recent_comments_style() {
  665. global $wp_widget_factory;
  666. remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
  667. }
  668. add_action( 'widgets_init', 'piratenkleider_remove_recent_comments_style' );
  669. if ( ! function_exists( 'piratenkleider_post_teaser' ) ) :
  670. /**
  671. * Erstellung eines Artikelteasers
  672. */
  673. function piratenkleider_post_teaser($titleup = 1, $showdatebox = 1, $showdateline = 0, $teaserlength = 200, $thumbfallback = 1, $usefloating = 0, $titlenum = 2) {
  674. global $options;
  675. global $post;
  676. $post_id = $post->ID;
  677. $sizeclass='';
  678. $out = '';
  679. if ('linktipps'== get_post_type() ) {
  680. $out = linktipp_display($post);
  681. return $out;
  682. }
  683. $leftbox = '';
  684. $sizeclass = 'p3-column withthumb';
  685. if (($showdatebox>0) && ($showdatebox<5)) {
  686. // Generate Thumb/Pic or Video first to find out which class we need
  687. $leftbox .= '<div class="infoimage">';
  688. $sizeclass = 'p3-column withthumb';
  689. $thumbnailcode = '';
  690. $firstpic = '';
  691. $firstvideo = '';
  692. if (has_post_thumbnail()) {
  693. $thumbnailcode = get_the_post_thumbnail($post->ID, 'teaser-thumb');
  694. }
  695. $firstpic = get_piratenkleider_firstpicture();
  696. $firstvideo = get_piratenkleider_firstvideo();
  697. $fallbackimg = '<img src="'.$options['src-teaser-thumbnail_default'].'" alt="">';
  698. if ($showdatebox==1) {
  699. if (!isset($output)) { $output = $thumbnailcode;}
  700. if (!isset($output)) { $output = $firstpic;}
  701. if ((!isset($output)) && (isset($firstvideo))) { $output = $firstvideo; $sizeclass = 'p3-column withvideo'; }
  702. if (!isset($output)) { $output = $fallbackimg;}
  703. if ((isset($output)) && ( strlen(trim($output))<10 )) {$output = $fallbackimg;}
  704. } elseif ($showdatebox==2) {
  705. if (!isset($output)) { $output = $firstpic;}
  706. if (!isset($output)) { $output = $thumbnailcode;}
  707. if ((!isset($output)) && (isset($firstvideo))) { $output = $firstvideo; $sizeclass = 'p3-column withvideo'; }
  708. if (!isset($output)) { $output = $fallbackimg;}
  709. if ((isset($output)) && ( strlen(trim($output))<10 )) {$output = $fallbackimg;}
  710. } elseif ($showdatebox==3) {
  711. if ((!isset($output)) && (isset($firstvideo))) { $output = $firstvideo; $sizeclass = 'p3-column withvideo'; }
  712. if (!isset($output)) { $output = $thumbnailcode;}
  713. if (!isset($output)) { $output = $firstpic;}
  714. if (!isset($output)) { $output = $fallbackimg;}
  715. if ((isset($output)) && ( strlen(trim($output))<10 )) {$output = $fallbackimg;}
  716. } elseif ($showdatebox==4) {
  717. if ((!isset($output)) && (isset($firstvideo))) { $output = $firstvideo; $sizeclass = 'p3-column withvideo'; }
  718. if (!isset($output)) { $output = $firstpic;}
  719. if (!isset($output)) { $output = $thumbnailcode;}
  720. if (!isset($output)) { $output = $fallbackimg;}
  721. if ((isset($output)) && ( strlen(trim($output))<10 )) {$output = $fallbackimg;}
  722. } else {
  723. $output = $fallbackimg;
  724. }
  725. $leftbox .= $output;
  726. $leftbox .= '</div>';
  727. } else {
  728. $sizeclass = 'p3-column';
  729. }
  730. if ($usefloating==1) {
  731. $sizeclass .= " usefloating";
  732. }
  733. $out .= '<section class="'. implode(' ',get_post_class($sizeclass)).'" id="post-'.$post->ID.'" >';
  734. $titlenum = (int) $titlenum;
  735. if (($titlenum<1) || ($titlenum>6)) {
  736. $titlenum = 2;
  737. }
  738. $htmltitlestart = '<h'.$titlenum.'>';
  739. $htmltitleend = '</h'.$titlenum.'>';
  740. if ($titleup==1) {
  741. $out .= '<header class="post-title p3-cbox">'.$htmltitlestart;
  742. $out .= '<a href="'.get_permalink().'" rel="bookmark">';
  743. $out .= get_the_title();
  744. $out .= '</a>'.$htmltitleend.'</header>';
  745. $out .= "\n";
  746. $out .= '<div class="p3-column">';
  747. }
  748. if ($showdatebox<5) {
  749. $out .= '<div class="post-info p3-col1"><div class="p3-cbox">';
  750. if ($showdatebox==0) {
  751. $num_comments = get_comments_number();
  752. if (($num_comments>0) || ( $options['zeige_commentbubble_null'])) {
  753. $out .= '<div class="commentbubble">';
  754. $link = get_comments_link();
  755. $out .= '<a href="'.$link.'">'.$num_comments.'<span class="skip"> ';
  756. if ($num_comments>0) {
  757. $out .= __('Comments', 'piratenkleider' ).'</span></a>';
  758. } else {
  759. $out .= __('Comment', 'piratenkleider' ).'</span></a>';
  760. }
  761. $out .= "</div>\n";
  762. }
  763. $out .= '<div class="cal-icon">';
  764. $out .= '<span class="day">'.get_the_time('j.').'</span>';
  765. $out .= '<span class="month">'.get_the_time('m.').'</span>';
  766. $out .= '<span class="year">'.get_the_time('Y').'</span>';
  767. $out .= "</div>\n";
  768. } else {
  769. $out .= $leftbox;
  770. }
  771. $out .= "</div></div>\n";
  772. $out .= '<article class="post-entry p3-col3">';
  773. $out .= '<div class="p3-cbox';
  774. if ($usefloating==0) { $out .= ' p3-clearfix'; }
  775. $out .= '">';
  776. } else {
  777. $out .= '<article class="post-entry p3-cbox">';
  778. }
  779. if ($titleup==0) {
  780. $out .= '<header class="post-title">'.$htmltitlestart;
  781. $out .= '<a href="'.get_permalink().'" rel="bookmark">';
  782. $out .= get_the_title();
  783. $out .= "</a>".$htmltitleend."</header>\n";
  784. }
  785. if (($showdatebox!=0) && ($showdateline==1)) {
  786. $out .= '<p class="pubdateinfo">';
  787. $out .= piratenkleider_post_pubdateinfo(0);
  788. $out .= "</p>\n";
  789. }
  790. $out .= get_piratenkleider_custom_excerpt($teaserlength,1,1,$options['continuelink']);
  791. if ($showdatebox<5) {
  792. $out .= "</div>\n";
  793. $out .= '<div class="p3-ie-clearing">&nbsp;</div>';
  794. }
  795. $out .= "</article>\n";
  796. if ($titleup==1) { $out .= '</div>'; }
  797. $out .= "</section>\n";
  798. return $out;
  799. }
  800. endif;
  801. if ( ! function_exists( 'piratenkleider_category_teaser' ) ) :
  802. /**
  803. * Erstellung eines Artikelteasers
  804. */
  805. function piratenkleider_category_teaser() {
  806. global $options;
  807. global $post;
  808. $out = $output = '';
  809. $leftbox = $thumbnailcode = $firstpic = $output = '';
  810. $leftbox .= '<div class="infoimage">';
  811. if (has_post_thumbnail()) {
  812. $output = get_the_post_thumbnail($post->ID, 'teaser-thumb');
  813. if (strlen($output)<1) {
  814. $output = '<img src="'.$options['src-teaser-thumbnail_default'].'" alt="">';
  815. }
  816. } else {
  817. $output = '<img src="'.$options['src-teaser-thumbnail_default'].'" alt="">';
  818. }
  819. $leftbox .= $output;
  820. $leftbox .= '</div>';
  821. $out .= '<section>';
  822. $out .= '<header><h3>';
  823. $out .= '<a href="'.get_permalink().'" rel="bookmark">';
  824. $out .= get_the_title();
  825. $out .= '</a></h3></header>';
  826. $out .= "\n";
  827. $out .= '<div>';
  828. $out .= $leftbox;
  829. $out .= '<article>';
  830. $out .= '<p class="pubdateinfo">';
  831. $out .= piratenkleider_post_pubdateinfo(0);
  832. $out .= "</p>\n";
  833. $out .= get_piratenkleider_custom_excerpt($options['categoryindex-teaserlength'],1,1,$options['continuelink']);
  834. $out .= '<div class="p3-ie-clearing">&nbsp;</div>';
  835. $out .= "</article>\n";
  836. $out .= '</div>';
  837. $out .= "</section>\n";
  838. return $out;
  839. }
  840. endif;
  841. if ( ! function_exists( 'piratenkleider_search_teaser' ) ) :
  842. /**
  843. * Suchausgabe
  844. */
  845. function piratenkleider_search_teaser($teaserlength = 250, $withthumb = 1, $aslist = 1, $search = '') {
  846. global $options;
  847. global $post;
  848. $out = $output = '';
  849. $leftbox = $thumbnailcode = $firstpic = $output = '';
  850. if ($withthumb==1) {
  851. $leftbox .= '<div class="infoimage">';
  852. if (has_post_thumbnail()) {
  853. $output = get_the_post_thumbnail($post->ID, 'teaser-thumb');
  854. if (strlen($output)<1) {
  855. $output = '<img src="'.$options['src-teaser-thumbnail_default'].'" alt="">';
  856. }
  857. } else {
  858. $output = '<img src="'.$options['src-teaser-thumbnail_default'].'" alt="">';
  859. }
  860. $leftbox .= $output;
  861. $leftbox .= '</div>';
  862. }
  863. if ($aslist==1) {
  864. $out .= '<li>';
  865. } else {
  866. $out .= '<div class="searchresults">';
  867. }
  868. $out .= '<h3>';
  869. $out .= '<a href="'.get_permalink().'">';
  870. $out .= get_the_title();
  871. $out .= '</a></h3>';
  872. $out .= "\n";
  873. $out .= '<div>';
  874. $out .= $leftbox;
  875. $excerpt = get_piratenkleider_custom_excerpt($teaserlength, 1, 1, 2);
  876. if (trim($search) !== '') {
  877. $keys = array_diff(explode(" ", $search), array(''));
  878. $excerpt = preg_replace('/('.implode('|', $keys) .')/iu',
  879. '<strong class="search-hit">\0</strong>',
  880. $excerpt);
  881. }
  882. $out .= $excerpt;
  883. $out .= '<p class="meta">';
  884. $out .= '<span class="date">'.__('Created at:','piratenkleider').' '.piratenkleider_post_pubdateinfo(0).'.</span> ';
  885. $typ =get_post_type();
  886. if ($typ == 'post') {
  887. $out .= '<span class="type">'.__('Type: Entry','piratenkleider').'.</span> ';
  888. } elseif ($typ=='page') {
  889. $out .= '<span class="type">'.__('Type: Page','piratenkleider').'.</span> ';
  890. }
  891. $out .= "</p>\n";
  892. $out .= '</div>';
  893. if ($aslist==1) {
  894. $out .= "</li>\n";
  895. } else {
  896. $out .= "</div>\n";
  897. }
  898. return $out;
  899. }
  900. endif;
  901. if ( ! function_exists( 'piratenkleider_post_datumsbox' ) ) :
  902. /**
  903. * Erstellung der Datumsbox
  904. */
  905. function piratenkleider_post_datumsbox() {
  906. global $options;
  907. $out = '<div class="post-info">';
  908. $num_comments = get_comments_number();
  909. if (($num_comments>0) || ( $options['zeige_commentbubble_null'])) {
  910. $out .= '<div class="commentbubble">';
  911. $link = get_comments_link();
  912. $out .= '<meta itemprop="interactionCount" content="UserComments:'.$num_comments.'"/><a itemprop="discussionUrl" href="'.$link.'">'.$num_comments.'<span class="skip">';
  913. if ($num_comments==1) {
  914. $out .= ' '.__('Comment', 'piratenkleider' ).'</span></a>';
  915. } else {
  916. $out .= ' '.__('Comments', 'piratenkleider' ).'</span></a>';
  917. }
  918. $out .= "</div>\n";
  919. }
  920. $out .= '<div class="cal-icon">';
  921. $out .= '<time datetime="'. esc_attr( get_the_date('c') ).'" itemprop="datePublished">';
  922. $out .= '<span class="day">'.get_the_time('j.').'</span>';
  923. $out .= '<span class="month">'.get_the_time('m.').'</span>';
  924. $out .= '<span class="year">'.get_the_time('Y').'</span>';
  925. $out .= '</time>';
  926. $out .= "</div>\n";
  927. $out .= '</div>';
  928. return $out;
  929. }
  930. endif;
  931. if ( ! function_exists( 'piratenkleider_post_pubdateinfo' ) ) :
  932. /**
  933. * Fusszeile unter Artikeln: Ver&ouml;ffentlichungsdatum
  934. */
  935. function piratenkleider_post_pubdateinfo($withtext = 1) {
  936. $out = '';
  937. if ($withtext==1) {
  938. $out .= '<span class="meta-prep">';
  939. $out .= __('Publiced at', 'piratenkleider' );
  940. $out .= '</span> ';
  941. }
  942. $out .= '<span class="entry-date">';
  943. $out .= get_the_date();
  944. $out .= "</span>\n";
  945. return $out;
  946. }
  947. endif;
  948. if ( ! function_exists( 'piratenkleider_post_autorinfo' ) ) :
  949. /**
  950. * Fusszeile unter Artikeln: Autorinfo
  951. */
  952. function piratenkleider_post_autorinfo() {
  953. $out = ' <span class="meta-prep-author">'.__('Author','piratenkleider').':</span> ';
  954. $out .= '<span class="author vcard" itemprop="creator"><a rel="author" class="url fn n" href="';
  955. $out .= get_author_posts_url( get_the_author_meta( 'ID' ) );
  956. $out .= '">';
  957. $out .= get_the_author_meta('display_name');
  958. $out .= '</a></span>';
  959. echo $out;
  960. }
  961. endif;
  962. if ( ! function_exists( 'piratenkleider_post_taxonominfo' ) ) :
  963. /**
  964. * Fusszeile unter Artikeln: Taxonomie
  965. */
  966. function piratenkleider_post_taxonominfo() {
  967. $tag_list = get_the_tag_list( '', ', ' );
  968. if ( $tag_list ) {
  969. $posted_in = __( 'Category: <span itemprop="articleSection">%1$s</span>. Tags: <span itemprop="keywords">%2$s</span>. <br><a href="%3$s" title="%4$s" rel="bookmark" itemprop="url">Permalink</a> for this entry.', 'piratenkleider' );
  970. } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
  971. $posted_in = __( 'Category: <span itemprop="articleSection">%1$s</span>. <br><a href="%3$s" title="%4$s" rel="bookmark" itemprop="url">Permalink</a> for this entry.', 'piratenkleider' );
  972. } else {
  973. $posted_in = __( '<a href="%3$s" title="%4$s" rel="bookmark" itemprop="url">Permalink</a> for this entry.', 'piratenkleider' );
  974. }
  975. // Prints the string, replacing the placeholders.
  976. printf(
  977. ' '.$posted_in,
  978. get_the_category_list( ', ' ),
  979. $tag_list,
  980. get_permalink(),
  981. the_title_attribute( 'echo=0' )
  982. );
  983. }
  984. endif;
  985. // this function initializes the iframe elements
  986. // maybe wont work on multisite installations. please use plugins instead.
  987. function piratenkleider_change_mce_options($initArray) {
  988. $ext = 'iframe[align|longdesc|name|width|height|frameborder|scrolling|marginheight|marginwidth|src]';
  989. if ( isset( $initArray['extended_valid_elements'] ) ) {
  990. $initArray['extended_valid_elements'] .= ',' . $ext;
  991. } else {
  992. $initArray['extended_valid_elements'] = $ext;
  993. }
  994. // maybe; set tiny paramter verify_html
  995. $initArray['verify_html'] = false;
  996. return $initArray;
  997. }
  998. add_filter('tiny_mce_before_init', 'piratenkleider_change_mce_options');
  999. class Piratenkleider_Menu_Walker extends Walker_Nav_Menu {
  1000. public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
  1001. {
  1002. if ( '-' === $item->title ) {
  1003. $item_output = '<li class="menu_separator"><hr>';
  1004. } else {
  1005. global $wp_query;
  1006. $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  1007. $class_names = $value = '';
  1008. $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  1009. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
  1010. $class_names = ' class="'. esc_attr( $class_names ) . '"';
  1011. $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
  1012. $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
  1013. $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
  1014. $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
  1015. $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
  1016. $description = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';
  1017. if($depth != 0) {
  1018. $description = "";
  1019. }
  1020. $item_output = $args->before;
  1021. $item_output .= '<a'. $attributes .'>';
  1022. $item_output .= $args->link_before .apply_filters( 'the_title', $item->title, $item->ID );
  1023. $item_output .= $description;
  1024. $item_output .= $args->link_after;
  1025. $item_output .= '</a>';
  1026. $item_output .= $args->after;
  1027. }
  1028. $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  1029. }
  1030. public function display_element($el, &$children, $max_depth, $depth = 0, $args = array(), &$output){
  1031. $id = $this->db_fields['id'];
  1032. if(isset($children[$el->$id]))
  1033. $el->classes[] = 'has_children';
  1034. parent::display_element($el, $children, $max_depth, $depth, $args, $output);
  1035. }
  1036. }
  1037. if ( ! function_exists( 'get_piratenkleider_socialmediaicons' ) ) :
  1038. /**
  1039. * Displays Social Media Icons
  1040. */
  1041. function get_piratenkleider_socialmediaicons( $darstellung = 1 ){
  1042. global $options;
  1043. global $default_socialmedia_liste;
  1044. $zeigeoption = $options['alle-socialmediabuttons'];
  1045. if ($darstellung ==0) {
  1046. return;
  1047. }
  1048. if ($darstellung!=$zeigeoption) {
  1049. return;
  1050. }
  1051. if ($zeigeoption ==2) {
  1052. /* Links an der Seite */
  1053. echo '<nav id="socialmedia_iconbar" aria-label="'.__('Social Media','piratenkleider').'">';
  1054. } else {
  1055. echo '<nav id="socialmedia_top" aria-label="'.__('Social Media','piratenkleider').'">';
  1056. }
  1057. echo '<ul class="socialmedia">';
  1058. foreach ( $default_socialmedia_liste as $entry => $listdata ) {
  1059. $value = '';
  1060. $active = 0;
  1061. if (isset($options['sm-list'][$entry]['content'])) {
  1062. $value = $options['sm-list'][$entry]['content'];
  1063. if (isset($options['sm-list'][$entry]['active'])) {
  1064. $active = $options['sm-list'][$entry]['active'];
  1065. }
  1066. } else {
  1067. $value = $default_socialmedia_liste[$entry]['content'];
  1068. $active = $default_socialmedia_liste[$entry]['active'];
  1069. }
  1070. if (($active ==1) && ($value)) {
  1071. echo '<li><a class="icon_'.$entry.'" href="'.$value.'">';
  1072. echo $listdata['name'].'</a></li>';
  1073. }
  1074. }
  1075. echo '</ul>';
  1076. echo '</nav>';
  1077. }
  1078. endif;
  1079. if ( ! function_exists( 'get_piratenkleider_seitenmenu' ) ) :
  1080. /*
  1081. * Anzeige des Sidebar-Menus
  1082. */
  1083. function get_piratenkleider_seitenmenu( $zeige_sidebarpagemenu = 1 , $zeige_subpagesonly =1 , $seitenmenu_mode = 0 ){
  1084. global $post;
  1085. $sidelinks = '';
  1086. if ($zeige_sidebarpagemenu==1) {
  1087. if (($seitenmenu_mode == 1) || (!has_nav_menu( 'primary' ))) {
  1088. if ($zeige_subpagesonly==1) {
  1089. //if the post has a parent
  1090. if($post->post_parent){
  1091. if($post->ancestors) {
  1092. $ancestors = end($post->ancestors);
  1093. $sidelinks = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");
  1094. } else {
  1095. $sidelinks .= wp_list_pages("sort_column=menu_order&title_li=&echo=0&depth=5&child_of=".$post->post_parent);
  1096. }
  1097. }else{
  1098. // display only main level and children
  1099. $sidelinks .= wp_list_pages("sort_column=menu_order&title_li=&echo=0&depth=5&child_of=".$post->ID);
  1100. }
  1101. if ($sidelinks) {
  1102. echo '<ul class="menu">';
  1103. echo $sidelinks;
  1104. echo '</ul>';
  1105. }
  1106. } else {
  1107. echo '<ul class="menu">';
  1108. wp_page_menu( );
  1109. echo '</ul>';
  1110. }
  1111. } else {
  1112. if ($zeige_subpagesonly==1) {
  1113. wp_nav_menu( array('depth' => 0, 'container_class' => 'menu-header subpagesonly', 'theme_location' => 'primary', 'walker' => new Piratenkleider_Menu_Walker()) );
  1114. } else {
  1115. wp_nav_menu( array('depth' => 0, 'container_class' => 'menu-header', 'theme_location' => 'primary', 'walker' => new Piratenkleider_Menu_Walker()) );
  1116. }
  1117. }
  1118. }
  1119. }
  1120. endif;
  1121. if ( ! function_exists( 'get_piratenkleider_firstpicture' ) ) :
  1122. /*
  1123. * Erstes Bild aus einem Artikel auslesen, wenn dies vorhanden ist
  1124. */
  1125. function get_piratenkleider_firstpicture(){
  1126. global $post;
  1127. $first_img = '';
  1128. ob_start();
  1129. ob_end_clean();
  1130. $matches = array();
  1131. preg_match('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  1132. if ((is_array($matches)) && (isset($matches[1]))) {
  1133. $first_img = $matches[1];
  1134. if (!empty($first_img)){
  1135. $site_link = home_url();
  1136. $first_img = preg_replace("%$site_link%i",'', $first_img);
  1137. $imagehtml = '<img src="'.$first_img.'" alt="" >';
  1138. return $imagehtml;
  1139. }
  1140. }
  1141. }
  1142. endif;
  1143. if ( ! function_exists( 'get_piratenkleider_firstvideo' ) ) :
  1144. /*
  1145. * Erstes Bild aus einem Artikel auslesen, wenn dies vorhanden ist
  1146. */
  1147. function get_piratenkleider_firstvideo($width = 300, $height = 169, $nocookie =1, $searchplain =1){
  1148. global $post;
  1149. ob_start();
  1150. ob_end_clean();
  1151. $matches = array();
  1152. preg_match('/src="([^\'"]*www\.youtube[^\'"]+)/i', $post->post_content, $matches);
  1153. if ((is_array($matches)) && (isset($matches[1]))) {
  1154. $entry = $matches[1];
  1155. if (!empty($entry)){
  1156. if ($nocookie==1) {
  1157. $entry = preg_replace('/feature=player_embedded&amp;/','',$entry);
  1158. $entry = preg_replace('/feature=player_embedded&/','',$entry);
  1159. $entry = preg_replace('/youtube.com\/watch\?v=/','youtube-nocookie.com/embed/',$entry);
  1160. }
  1161. $htmlout = '<iframe width="'.$width.'" height="'.$height.'" src="'.$entry.'" allowfullscreen="true"></iframe>';
  1162. return $htmlout;
  1163. }
  1164. }
  1165. if ($searchplain==1) {
  1166. preg_match('/\s(https?:\/\/www\.youtube[\-a-z]*\.com\/(watch|embed)[\/a-z0-9\.\-&;\?_=]+)/i', $post->post_content, $matches);
  1167. if ((is_array($matches)) && (isset($matches[1]))) {
  1168. $entry = $matches[1];
  1169. if (!empty($entry)){
  1170. if ($nocookie==1) {
  1171. $entry = preg_replace('/feature=player_embedded&amp;/','',$entry);
  1172. $entry = preg_replace('/feature=player_embedded&/','',$entry);
  1173. $entry = preg_replace('/youtube.com\/watch\?v=/','youtube-nocookie.com/embed/',$entry);
  1174. }
  1175. $htmlout = '<iframe width="'.$width.'" height="'.$height.'" src="'.$entry.'" allowfullscreen></iframe>';
  1176. return $htmlout;
  1177. }
  1178. }
  1179. }
  1180. }
  1181. endif;
  1182. if ( ! function_exists( 'get_piratenkleider_custom_excerpt' ) ) :
  1183. /*
  1184. * Erstellen des Extracts
  1185. */
  1186. function get_piratenkleider_custom_excerpt($length = 0, $continuenextline = 1, $removeyoutube = 1, $alwayscontinuelink = 0){
  1187. global $options;
  1188. global $post;
  1189. global $defaultoptions;
  1190. if (has_excerpt()) {
  1191. return get_the_excerpt();
  1192. } else {
  1193. $excerpt = get_the_content();
  1194. if (!isset($excerpt)) {
  1195. $excerpt = __( 'No content', 'piratenkleider' );
  1196. }
  1197. }
  1198. if ($length==0) {
  1199. $length = $options['teaser_maxlength'];
  1200. if ($length <=0) {
  1201. $length = 100;
  1202. }
  1203. }
  1204. if ($removeyoutube==1) {
  1205. $excerpt = preg_replace('/\s+(https?:\/\/www\.youtube[\/a-z0-9\.\-\?&;=_]+)/i','',$excerpt);
  1206. }
  1207. $excerpt = strip_shortcodes($excerpt);
  1208. $excerpt = strip_tags($excerpt, $defaultoptions['excerpt_allowtags']);
  1209. if (mb_strlen($excerpt)<5) {
  1210. $excerpt = '<!-- '.__( 'No entry for this post', 'piratenkleider' ).' -->';
  1211. }
  1212. $needcontinue =0;
  1213. if (mb_strlen($excerpt) > $length) {
  1214. $the_str = mb_substr($excerpt, 0, $length);
  1215. $the_str .= "...";
  1216. $needcontinue = 1;
  1217. } else {
  1218. $the_str = $excerpt;
  1219. }
  1220. $the_str = '<p>'.$the_str;
  1221. if ($alwayscontinuelink < 2) {
  1222. if (($needcontinue==1) || ($alwayscontinuelink==1)) {
  1223. if ($continuenextline==1) {
  1224. $the_str .= '<br>';
  1225. }
  1226. $the_str .= piratenkleider_continue_reading_link();
  1227. }
  1228. }
  1229. $the_str .= '</p>';
  1230. return $the_str;
  1231. }
  1232. endif;
  1233. if ( ! function_exists( 'short_title' ) ) :
  1234. /*
  1235. * Erstellen des Kurztitels
  1236. */
  1237. function short_title($after = '...', $length = 6, $textlen = 10) {
  1238. $thistitle = get_the_title();
  1239. $mytitle = explode(' ', get_the_title());
  1240. if ((count($mytitle)>$length) || (mb_strlen($thistitle)> $textlen)) {
  1241. while(((count($mytitle)>$length) || (mb_strlen($thistitle)> $textlen)) && (count($mytitle)>1)) {
  1242. array_pop($mytitle);
  1243. $thistitle = implode(" ",$mytitle);
  1244. }
  1245. $morewords = 1;
  1246. } else {
  1247. $morewords = 0;
  1248. }
  1249. if (mb_strlen($thistitle)> $textlen) {
  1250. $thistitle = mb_substr($thistitle, 0, $textlen);
  1251. $morewords = 1;
  1252. }
  1253. if ($morewords==1) {
  1254. $thistitle .= $after;
  1255. }
  1256. return $thistitle;
  1257. }
  1258. endif;
  1259. if ( ! function_exists( 'piratenkleider_fetch_feed' ) ) :
  1260. /*
  1261. * Feet holen mit direkter Angabe der SimplePie-Parameter
  1262. */
  1263. function piratenkleider_fetch_feed($url,$lifetime=0) {
  1264. global $defaultoptions;
  1265. global $options;
  1266. if ($lifetime==0){
  1267. $lifetime= $options['feed_cache_lifetime'];
  1268. }
  1269. if ($lifetime < 600) $lifetime = 1800;
  1270. // Das holen von feeds sollte auf keinen Fall haeufiger als alle 10 Minuten erfolgen
  1271. require_once (ABSPATH . WPINC . '/class-feed.php');
  1272. $feed = new SimplePie();
  1273. if ($defaultoptions['use_wp_feed_defaults']) {
  1274. $feed->set_cache_class('WP_Feed_Cache');
  1275. $feed->set_file_class('WP_SimplePie_File');
  1276. } else {
  1277. if ((isset($defaultoptions['dir_feed_cache'])) && (!empty($defaultoptions['dir_feed_cache']))) {
  1278. if (is_dir($defaultoptions['dir_feed_cache'])) {
  1279. $feed->set_cache_location($defaultoptions['dir_feed_cache']);
  1280. } else {
  1281. mkdir($defaultoptions['dir_feed_cache']);
  1282. if (!is_dir($defaultoptions['dir_feed_cache'])) {
  1283. echo "Wasnt able to create Feed-Cache directory";
  1284. } else {
  1285. $feed->set_cache_location($defaultoptions['dir_feed_cache']);
  1286. }
  1287. }
  1288. }
  1289. }
  1290. $feed->set_feed_url($url);
  1291. $feed->set_cache_duration($lifetime);
  1292. do_action_ref_array( 'wp_feed_options', array( $feed, $url ) );
  1293. $feed->init();
  1294. $feed->handle_content_type();
  1295. if ( $feed->error() )
  1296. return new WP_Error('simplepie-error', $feed->error());
  1297. return $feed;
  1298. }
  1299. endif;
  1300. function wpi_linkexternclass($content){
  1301. return preg_replace_callback('/<a[^>]+/', 'wpi_linkexternclass_callback', $content);
  1302. }
  1303. function wpi_linkexternclass_callback($matches) {
  1304. $link = $matches[0];
  1305. $site_link = home_url();
  1306. if ((strpos($link, 'class') === false)
  1307. && (strpos($link, 'mailto:') === false)
  1308. && (strpos($link, 'http') >0)
  1309. && (strpos($link, $site_link) === false)) {
  1310. $link = preg_replace("%(href=\S(?!($site_link|#)))%i", 'class="extern" $1', $link);
  1311. }
  1312. return $link;
  1313. }
  1314. add_filter('the_content', 'wpi_linkexternclass');
  1315. function wpi_relativeurl($content){
  1316. return preg_replace_callback('/<a[^>]+/', 'wpi_relativeurl_callback', $content);
  1317. }
  1318. function wpi_relativeurl_callback($matches) {
  1319. $link = $matches[0];
  1320. $site_link = wp_make_link_relative(home_url());
  1321. $link = preg_replace("%href=\"$site_link%i", 'href="', $link);
  1322. return $link;
  1323. }
  1324. add_filter('the_content', 'wpi_relativeurl');
  1325. function piratenkleider_breadcrumb() {
  1326. global $defaultoptions;
  1327. $delimiter = $defaultoptions['breadcrumb_delimiter']; // = ' / ';
  1328. $home = $defaultoptions['breadcrumb_homelinktext']; // __( 'Startseite', 'piratenkleider' ); // text for the 'Home' link
  1329. $before = $defaultoptions['breadcrumb_beforehtml']; // '<span class="current">'; // tag before the current crumb
  1330. $after = $defaultoptions['breadcrumb_afterhtml']; // '</span>'; // tag after the current crumb
  1331. $pretitletextstart = '<span>';
  1332. $pretitletextend = '</span>';
  1333. echo '<div id="crumbs" itemprop="breadcrumb">';
  1334. if ( !is_home() && !is_front_page() || is_paged() ) {
  1335. global $post;
  1336. $homeLink = home_url('/');
  1337. echo '<a href="' . $homeLink . '">' . $home . '</a>' . $delimiter;
  1338. if ( is_category() ) {
  1339. global $wp_query;
  1340. $cat_obj = $wp_query->get_queried_object();
  1341. $thisCat = $cat_obj->term_id;
  1342. $thisCat = get_category($thisCat);
  1343. $parentCat = get_category($thisCat->parent);
  1344. if ($thisCat->parent != 0)
  1345. echo(get_category_parents($parentCat, TRUE, $delimiter ));
  1346. echo $before . $pretitletextstart. __( 'Entry of category', 'piratenkleider' ).$pretitletextend. ' "' . single_cat_title('', false) . '"' . $after;
  1347. } elseif ( is_day() ) {
  1348. echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' .$delimiter;
  1349. echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a>' .$delimiter;
  1350. echo $before . get_the_time('d') . $after;
  1351. } elseif ( is_month() ) {
  1352. echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $delimiter;
  1353. echo $before . get_the_time('F') . $after;
  1354. } elseif ( is_year() ) {
  1355. echo $before . get_the_time('Y') . $after;
  1356. } elseif ( is_single() && !is_attachment() ) {
  1357. if ( get_post_type() != 'post' ) {
  1358. $post_type = get_post_type_object(get_post_type());
  1359. $slug = $post_type->rewrite;
  1360. echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a>' .$delimiter;
  1361. echo $before . get_the_title() . $after;
  1362. } else {
  1363. echo $before . get_the_title() . $after;
  1364. }
  1365. } elseif ( !is_single() && !is_page() && !is_search() && get_post_type() != 'post' && !is_404() ) {
  1366. $post_type = get_post_type_object(get_post_type());
  1367. echo $before . $post_type->labels->singular_name . $after;
  1368. } elseif ( is_attachment() ) {
  1369. $parent = get_post($post->post_parent);
  1370. echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a>'. $delimiter;
  1371. echo $before . get_the_title() . $after;
  1372. } elseif ( is_page() && !$post->post_parent ) {
  1373. echo $before . get_the_title() . $after;
  1374. } elseif ( is_page() && $post->post_parent ) {
  1375. $parent_id = $post->post_parent;
  1376. $breadcrumbs = array();
  1377. while ($parent_id) {
  1378. $page = get_page($parent_id);
  1379. $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
  1380. $parent_id = $page->post_parent;
  1381. }
  1382. $breadcrumbs = array_reverse($breadcrumbs);
  1383. foreach ($breadcrumbs as $crumb) echo $crumb . $delimiter;
  1384. echo $before . get_the_title() . $after;
  1385. } elseif ( is_search() ) {
  1386. echo $before .$pretitletextstart. __( 'Search for', 'piratenkleider' ).$pretitletextend.' "' . get_search_query() . '"' . $after;
  1387. } elseif ( is_tag() ) {
  1388. echo $before .$pretitletextstart. __( 'Entries with tag', 'piratenkleider' ).$pretitletextend. ' "' . single_tag_title('', false) . '"' . $after;
  1389. } elseif ( is_author() ) {
  1390. global $author;
  1391. $userdata = get_userdata($author);
  1392. echo $before .$pretitletextstart. __( 'Entry by', 'piratenkleider' ).$pretitletextend.' '.$userdata->display_name . $after;
  1393. } elseif ( is_404() ) {
  1394. echo $before . '404' . $after;
  1395. }
  1396. /*
  1397. if ( get_query_var('paged') ) {
  1398. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
  1399. echo __('Page', 'piratenkleider') . ' ' . get_query_var('paged');
  1400. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
  1401. }
  1402. */
  1403. } elseif (is_front_page() && $defaultoptions['zeige_breadcrump_frontpages']) {
  1404. echo $before . $home . $after;
  1405. } elseif (is_home() && $defaultoptions['zeige_breadcrump_frontpages']) {
  1406. echo $before . get_the_title(get_option('page_for_posts')) . $after;
  1407. }
  1408. echo '</div>';
  1409. }
  1410. function piratenkleider_header_style() {}
  1411. function piratenkleider_admin_style() {
  1412. global $defaultoptions;
  1413. wp_register_style( 'themeadminstyle', $defaultoptions['src-admincss']);
  1414. wp_enqueue_style( 'themeadminstyle' );
  1415. wp_enqueue_media();
  1416. wp_register_script('themeadminscripts', $defaultoptions['src-adminjs'], array('jquery'));
  1417. wp_enqueue_script('themeadminscripts');
  1418. }
  1419. add_action( 'admin_enqueue_scripts', 'piratenkleider_admin_style' );
  1420. function custom_login() {
  1421. global $defaultoptions;
  1422. echo '<link rel="stylesheet" type="text/css" href="'.$defaultoptions['src-customlogincss'].'" />';
  1423. }
  1424. add_action('login_head', 'custom_login');
  1425. add_filter('upload_mimes', 'custom_upload_mimes');
  1426. function custom_upload_mimes ( $existing_mimes=array() ) {
  1427. $existing_mimes['css'] = 'text/plain';
  1428. $existing_mimes['ico'] = 'image/ico';
  1429. return $existing_mimes;
  1430. }
  1431. /*
  1432. * Paging Function
  1433. */
  1434. function piratenkleider_paging_bar($total = 1, $perpage =1) {
  1435. /* Init */
  1436. $count = $total;
  1437. $page = (int)get_query_var('paged');
  1438. $maxpage = intval($total/$perpage);
  1439. /* Kein Paging? */
  1440. if ($count <= $perpage) {
  1441. return false;
  1442. }
  1443. /* Erste Seite? */
  1444. if (!$page) {
  1445. $page = 1;
  1446. }
  1447. $min = $page-2;
  1448. if ($min<=0) $min =1;
  1449. $max= $page+2;
  1450. if ($page==1) { $max = 4;}
  1451. if ($max>$maxpage) {
  1452. $max = $maxpage;
  1453. }
  1454. /* Ausgabe der Links */
  1455. if (!empty($min) && !empty($max)) {
  1456. for($i = $min; $i <= $max; $i++){
  1457. echo sprintf(
  1458. '<a href="%s"%s>%d</a>',
  1459. get_pagenum_link($i),
  1460. ($i == $page ? ' class="active"' : ''),
  1461. $i
  1462. );
  1463. }
  1464. }
  1465. }
  1466. // select the right item type for the page
  1467. function piratenkleider_html_tag_schema() {
  1468. global $options;
  1469. $schema = 'http://schema.org/';
  1470. if (is_single() || is_page()) {
  1471. isset($options['meta-itemtype-aboutpage']) && !empty($options['meta-itemtype-aboutpage'])
  1472. ? $abtpage = trim($options['meta-itemtype-aboutpage']) : $abtpage = false;
  1473. isset($options['meta-itemtype-contactpage']) && !empty($options['meta-itemtype-contactpage'])
  1474. ? $ctcpage = trim($options['meta-itemtype-contactpage']) : $ctcpage = false;
  1475. isset($options['meta-itemtype-ptype1']) && !empty($options['meta-itemtype-ptype1'])
  1476. ? $cstptype1 = trim($options['meta-itemtype-ptype1']) : $cstptype1 = false;
  1477. isset($options['meta-itemtype-ptype2']) && !empty($options['meta-itemtype-ptype2'])
  1478. ? $cstptype2 = trim($options['meta-itemtype-ptype2']) : $cstptype2 = false;
  1479. // Is about page
  1480. if (is_page($abtpage) && $abtpage) {
  1481. $type = 'AboutPage';
  1482. // Is contact page
  1483. } elseif (is_page($ctcpage) && $ctcpage) {
  1484. $type = 'ContactPage';
  1485. // Is person
  1486. } elseif (is_singular('person')) {
  1487. $type = 'Person';
  1488. // Is custom type 1
  1489. } elseif (is_singular($cstptype1) && $cstptype1){
  1490. $type = ''. trim($options['meta-itemtype-cst1']) .'';
  1491. // Is custom type 2
  1492. } elseif (is_singular($cstptype2) && $cstptype2){
  1493. $type = ''. trim($options['meta-itemtype-cst2']) .'';
  1494. // Is some other page
  1495. } elseif (is_single()) {
  1496. $type = 'Article';
  1497. } else {
  1498. // Is single post
  1499. $type = "WebPage";
  1500. }
  1501. } else {
  1502. // Is search results page or other
  1503. is_search() ? $type = 'SearchResultsPage' : $type = 'WebPage';
  1504. }
  1505. $tag = 'itemscope itemtype="' . $schema . $type . '"';
  1506. return $tag;
  1507. }
  1508. //set organization name: either custom value or blog settings
  1509. function piratenkleider_tag_schema_org_name() {
  1510. global $options;
  1511. isset($options['meta-itemtype-org-name']) && !empty($options['meta-itemtype-org-name'])
  1512. ? $name = trim($options['meta-itemtype-org-name']) : $name = bloginfo('name');
  1513. return $name;
  1514. }
  1515. //set organization description: either custom value or blog settings
  1516. function piratenkleider_tag_schema_org_desc() {
  1517. global $options;
  1518. isset($options['meta-itemtype-org-desc']) && !empty($options['meta-itemtype-org-desc'])
  1519. ? $desc = trim($options['meta-itemtype-org-desc']) : $desc = bloginfo( 'description' );
  1520. return $desc;
  1521. }
  1522. /* Compatibility for old templates, former Version 3.2 */
  1523. add_filter('page_template', 'piratenkleider_page_template');
  1524. function piratenkleider_page_template($t) {
  1525. $compatlist = array(
  1526. 'impressum.php' => 'templates/imprint.php',
  1527. 'datenschutzerklaerung.php' => 'templates/privacy-policy.php',
  1528. 'catindex.php' => 'templates/category-index.php',
  1529. 'pageindex.php' => 'templates/page-index.php',
  1530. 'page-actionpage.php' => 'templates/actionpage.php'
  1531. );
  1532. $page_id = get_queried_object_id();
  1533. $template = get_post_meta($page_id, '_wp_page_template', true);
  1534. if($template && 'default'!= $template) {
  1535. foreach ( $compatlist as $key => $value ) {
  1536. if ($key == $template) {
  1537. if(file_exists(trailingslashit(STYLESHEETPATH) . $value)){
  1538. $t = trailingslashit(STYLESHEETPATH) . $value;
  1539. } elseif(file_exists(trailingslashit(TEMPLATEPATH) . $value)) {
  1540. $t = trailingslashit(TEMPLATEPATH) . $value;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. return $t;
  1546. }