PageRenderTime 24ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/zentrum_wp_theme/functions.php

https://github.com/torstein1989/Capstone_II
PHP | 315 lines | 193 code | 42 blank | 80 comment | 11 complexity | 727934fc47e6eab28b8258a7d7c2f509 MD5 | raw file
  1. <?php
  2. /**
  3. * Starkers functions and definitions
  4. *
  5. * @package WordPress
  6. * @subpackage Starkers
  7. * @since Starkers HTML5 3.0
  8. */
  9. /** Tell WordPress to run starkers_setup() when the 'after_setup_theme' hook is run. */
  10. add_action( 'after_setup_theme', 'starkers_setup' );
  11. if ( ! function_exists( 'starkers_setup' ) ):
  12. /**
  13. * Sets up theme defaults and registers support for various WordPress features.
  14. *
  15. * @since Starkers HTML5 3.0
  16. */
  17. function starkers_setup() {
  18. // Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories.
  19. add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
  20. // This theme uses post thumbnails
  21. add_theme_support( 'post-thumbnails' );
  22. // Add default posts and comments RSS feed links to head
  23. add_theme_support( 'automatic-feed-links' );
  24. // Make theme available for translation
  25. // Translations can be filed in the /languages/ directory
  26. load_theme_textdomain( 'starkers', TEMPLATEPATH . '/languages' );
  27. $locale = get_locale();
  28. $locale_file = TEMPLATEPATH . "/languages/$locale.php";
  29. if ( is_readable( $locale_file ) )
  30. require_once( $locale_file );
  31. // This theme uses wp_nav_menu() in one location.
  32. register_nav_menus( array(
  33. 'primary' => __( 'Primary Navigation', 'starkers' ),
  34. ) );
  35. }
  36. endif;
  37. /**
  38. * Set our wp_nav_menu() fallback, starkers_menu().
  39. *
  40. * @since Starkers HTML5 3.0
  41. */
  42. function starkers_menu() {
  43. echo '<nav><ul><li><a href="'.get_bloginfo('url').'">Home</a></li>';
  44. wp_list_pages('title_li=');
  45. echo '</ul></nav>';
  46. }
  47. /**
  48. * Remove inline styles printed when the gallery shortcode is used.
  49. *
  50. * @since Starkers HTML5 3.2
  51. */
  52. add_filter( 'use_default_gallery_style', '__return_false' );
  53. /**
  54. * @since Starkers HTML5 3.0
  55. * @deprecated in Starkers HTML5 3.2 for WordPress 3.1
  56. *
  57. * @return string The gallery style filter, with the styles themselves removed.
  58. */
  59. function starkers_remove_gallery_css( $css ) {
  60. return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
  61. }
  62. // Backwards compatibility with WordPress 3.0.
  63. if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) )
  64. add_filter( 'gallery_style', 'starkers_remove_gallery_css' );
  65. if ( ! function_exists( 'starkers_comment' ) ) :
  66. /**
  67. * Template for comments and pingbacks.
  68. *
  69. * @since Starkers HTML5 3.0
  70. */
  71. function starkers_comment( $comment, $args, $depth ) {
  72. $GLOBALS['comment'] = $comment;
  73. switch ( $comment->comment_type ) :
  74. case '' :
  75. ?>
  76. <article <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
  77. <?php echo get_avatar( $comment, 40 ); ?>
  78. <?php printf( __( '%s says:', 'starkers' ), sprintf( '%s', get_comment_author_link() ) ); ?>
  79. <?php if ( $comment->comment_approved == '0' ) : ?>
  80. <?php _e( 'Your comment is awaiting moderation.', 'starkers' ); ?>
  81. <br />
  82. <?php endif; ?>
  83. <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
  84. <?php
  85. /* translators: 1: date, 2: time */
  86. printf( __( '%1$s at %2$s', 'starkers' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'starkers' ), ' ' );
  87. ?>
  88. <?php comment_text(); ?>
  89. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  90. <?php
  91. break;
  92. case 'pingback' :
  93. case 'trackback' :
  94. ?>
  95. <article <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
  96. <p><?php _e( 'Pingback:', 'starkers' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'starkers'), ' ' ); ?></p>
  97. <?php
  98. break;
  99. endswitch;
  100. }
  101. endif;
  102. /**
  103. * Closes comments and pingbacks with </article> instead of </li>.
  104. *
  105. * @since Starkers HTML5 3.0
  106. */
  107. function starkers_comment_close() {
  108. echo '</article>';
  109. }
  110. /**
  111. * Adjusts the comment_form() input types for HTML5.
  112. *
  113. * @since Starkers HTML5 3.0
  114. */
  115. function starkers_fields($fields) {
  116. $commenter = wp_get_current_commenter();
  117. $req = get_option( 'require_name_email' );
  118. $aria_req = ( $req ? " aria-required='true'" : '' );
  119. $fields = array(
  120. 'author' => '<p><label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '*' : '' ) .
  121. '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
  122. 'email' => '<p><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '*' : '' ) .
  123. '<input id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
  124. 'url' => '<p><label for="url">' . __( 'Website' ) . '</label>' .
  125. '<input id="url" name="url" type="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
  126. );
  127. return $fields;
  128. }
  129. add_filter('comment_form_default_fields','starkers_fields');
  130. /**
  131. * Register widgetized areas.
  132. *
  133. * @since Starkers HTML5 3.0
  134. */
  135. function starkers_widgets_init() {
  136. // Area 1, located at the top of the sidebar.
  137. register_sidebar( array(
  138. 'name' => __( 'Logo Widget Area', 'starkers' ),
  139. 'id' => 'logo-widget-area',
  140. 'description' => __( 'The primary widget area', 'starkers' ),
  141. 'before_widget' => '<div id="logo">',
  142. 'after_widget' => '</div>',
  143. 'before_title' => '<h3>',
  144. 'after_title' => '</h3>',
  145. ) );
  146. // Area 3, located in the footer. Empty by default.
  147. register_sidebar( array(
  148. 'name' => __( 'Footer Widget Area', 'starkers' ),
  149. 'id' => 'footer-widget-area',
  150. 'description' => __( 'The first footer widget area', 'starkers' ),
  151. 'before_widget' => null,
  152. 'after_widget' => null,
  153. 'before_title' => '<h3>',
  154. 'after_title' => '</h3>',
  155. ) );
  156. }
  157. /** Register sidebars by running starkers_widgets_init() on the widgets_init hook. */
  158. add_action( 'widgets_init', 'starkers_widgets_init' );
  159. /**
  160. * Removes the default styles that are packaged with the Recent Comments widget.
  161. *
  162. * @updated Starkers HTML5 3.2
  163. */
  164. function starkers_remove_recent_comments_style() {
  165. add_filter( 'show_recent_comments_widget_style', '__return_false' );
  166. }
  167. add_action( 'widgets_init', 'starkers_remove_recent_comments_style' );
  168. if ( ! function_exists( 'starkers_posted_on' ) ) :
  169. /**
  170. * Prints HTML with meta information for the current post—date/time and author.
  171. *
  172. * @since Starkers HTML5 3.0
  173. */
  174. function starkers_posted_on() {
  175. printf( __( 'Posted on %2$s by %3$s', 'starkers' ),
  176. 'meta-prep meta-prep-author',
  177. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time datetime="%3$s" pubdate>%4$s</time></a>',
  178. get_permalink(),
  179. esc_attr( get_the_time() ),
  180. get_the_date('Y-m-d'),
  181. get_the_date()
  182. ),
  183. sprintf( '<a href="%1$s" title="%2$s">%3$s</a>',
  184. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  185. sprintf( esc_attr__( 'View all posts by %s', 'starkers' ), get_the_author() ),
  186. get_the_author()
  187. )
  188. );
  189. }
  190. endif;
  191. if ( ! function_exists( 'starkers_posted_in' ) ) :
  192. /**
  193. * Prints HTML with meta information for the current post (category, tags and permalink).
  194. *
  195. * @since Starkers HTML5 3.0
  196. */
  197. function starkers_posted_in() {
  198. // Retrieves tag list of current post, separated by commas.
  199. $tag_list = get_the_tag_list( '', ', ' );
  200. if ( $tag_list ) {
  201. $posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'starkers' );
  202. } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
  203. $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'starkers' );
  204. } else {
  205. $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'starkers' );
  206. }
  207. // Prints the string, replacing the placeholders.
  208. printf(
  209. $posted_in,
  210. get_the_category_list( ', ' ),
  211. $tag_list,
  212. get_permalink(),
  213. the_title_attribute( 'echo=0' )
  214. );
  215. }
  216. endif;
  217. // zentrum_categories function
  218. function zentrum_categories() { $pages = get_pages('sort_column=menu_order&title_li=');
  219. $i=1;
  220. foreach($pages as $page_data) {
  221. $content = apply_filters('the_content', $page_data->post_content);
  222. $title = $page_data->post_title;
  223. echo "<div class='item'><a href='#' name='content$i'>";
  224. echo "<div class='design-button' id='meny$i' style='background-color: " .get_option('zentrum_color'.$i.''). "'><span class='menybutton'>";
  225. echo '<p>' .$title .'</p>';
  226. echo "</span></div></a></div>";
  227. $i++;
  228. }
  229. }
  230. // zentrum_categories_page function
  231. function zentrum_categories_page() {$pages = get_pages('sort_column=menu_order&title_li=');
  232. $i=1;
  233. foreach($pages as $page_data) {
  234. $content = apply_filters('the_content', $page_data->post_content);
  235. $title = $page_data->post_title;
  236. echo "<div class='item'><a href='#' name='content$i'>";
  237. echo "<div id=\"innhold_meny_tekst\" style='background-color: " .get_option('zentrum_color'.$i.''). "'>";
  238. echo $title;
  239. echo "</div></a></div>";
  240. $i++;
  241. }
  242. }
  243. //zentrum_pages_all
  244. function zentrum_all() { $pages = get_pages('sort_column=menu_order&title_li=');
  245. $i=1;
  246. foreach ($pages as $page_data) {
  247. $content = apply_filters('the_content', $page_data->post_content);
  248. $title = $page_data->post_title;
  249. $title = strtoupper($title);
  250. echo "<span class=\"item\" id=\"content$i\" style=\"display: none;\">
  251. <div class=\"innhold_fix\">
  252. <div id=\"innhold_meny\">";
  253. echo zentrum_categories_page($args);
  254. echo "</div>";
  255. echo "<div id=\"innhold\" style='background-color: " .get_option('zentrum_color'.$i.''). "'>
  256. <div id=\"innhold_current\">";
  257. echo $title;
  258. echo "</div>
  259. <div id=\"innhold_info\">
  260. ";
  261. echo $content; // Skrive ut innhold
  262. echo "</div>
  263. <div id=\"innhold_player\">
  264. <iframe width=\"439\" height=\"308\" src=\"http://www.youtube.com/embed/4PkcfQtibmU\" frameborder=\"0\" allowfullscreen></iframe>
  265. </div>&nbsp;
  266. </div>
  267. </div>
  268. </span>";
  269. $i++;
  270. }
  271. }
  272. include ("zentrum_options_plugin.php");
  273. include ("zentrum_page_order.php");