PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/themes/target/functions.php

https://github.com/Bochet/festival_lgbt
PHP | 409 lines | 280 code | 80 blank | 49 comment | 40 complexity | 0dee523a5c5566a4283fcb8522ffd73c MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. if ( ! isset( $content_width ) )
  3. $content_width = 620;
  4. /** Tell WordPress to run target_setup() when the 'after_setup_theme' hook is run. */
  5. add_action( 'after_setup_theme', 'target_setup' );
  6. if ( ! function_exists( 'target_setup' ) ):
  7. function target_setup() {
  8. // This theme uses post thumbnails
  9. add_theme_support( 'post-thumbnails' );
  10. // Add default posts and comments RSS feed links to head
  11. add_theme_support( 'automatic-feed-links' );
  12. // Make theme available for translation
  13. // Translations can be filed in the /languages/ directory
  14. load_theme_textdomain( 'target', get_template_directory() . '/languages' );
  15. $locale = get_locale();
  16. $locale_file = get_template_directory() . "/languages/$locale.php";
  17. if ( is_readable( $locale_file ) )
  18. require_once( $locale_file );
  19. // This theme uses wp_nav_menu() in one location.
  20. register_nav_menus( array(
  21. 'primary' => __( 'Primary Navigation', 'target' ),
  22. ) );
  23. }
  24. endif;
  25. ?>
  26. <?php
  27. function target_list_pings($comment, $args, $depth) {
  28. $GLOBALS['comment'] = $comment; ?>
  29. <li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
  30. <?php } ?>
  31. <?php
  32. add_filter('get_comments_number', 'target_comment_count', 0);
  33. function target_comment_count( $count ) {
  34. if ( ! is_admin() ) {
  35. global $id;
  36. $comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
  37. return count($comments_by_type['comment']);
  38. } else {
  39. return $count;
  40. }
  41. }
  42. ?>
  43. <?php
  44. if ( ! function_exists( 'target_comment' ) ) :
  45. function target_comment( $comment, $args, $depth ) {
  46. $GLOBALS['comment'] = $comment;
  47. switch ( $comment->comment_type ) :
  48. case '' :
  49. ?>
  50. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  51. <div id="comment-<?php comment_ID(); ?>">
  52. <div class="comment-author vcard">
  53. <?php echo get_avatar( $comment, 40 ); ?>
  54. <?php printf( __( '%s', 'target' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
  55. </div><!-- .comment-author .vcard -->
  56. <?php if ( $comment->comment_approved == '0' ) : ?>
  57. <em><?php _e( 'Your comment is awaiting moderation.', 'target' ); ?></em>
  58. <br />
  59. <?php endif; ?>
  60. <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
  61. <?php
  62. /* translators: 1: date, 2: time */
  63. printf( __( '%1$s at %2$s', 'target' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'target' ), ' ' );
  64. ?>
  65. </div><!-- .comment-meta .commentmetadata -->
  66. <div class="comment-body"><?php comment_text(); ?></div>
  67. <div class="reply">
  68. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  69. </div><!-- .reply -->
  70. </div><!-- #comment-## -->
  71. <?php
  72. break;
  73. case 'pingback' :
  74. case 'trackback' :
  75. ?>
  76. <li class="post pingback">
  77. <p><?php _e( 'Pingback:', 'target' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'target'), ' ' ); ?></p>
  78. <?php
  79. break;
  80. endswitch;
  81. }
  82. endif;
  83. /**
  84. * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
  85. *
  86. * To override target_widgets_init() in a child theme, remove the action hook and add your own
  87. * function tied to the init hook.
  88. */
  89. function target_widgets_init() {
  90. // Area 1, located at the top of the sidebar.
  91. register_sidebar( array(
  92. 'name' => __( 'Primary Widget Area', 'target' ),
  93. 'id' => 'primary-widget-area',
  94. 'description' => __( 'The primary widget area', 'target' ),
  95. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  96. 'after_widget' => '</li>',
  97. 'before_title' => '<h3 class="widget-title">',
  98. 'after_title' => '</h3>',
  99. ) );
  100. // Area 3, located in the footer. Empty by default.
  101. register_sidebar( array(
  102. 'name' => __( 'First Footer Widget Area', 'target' ),
  103. 'id' => 'first-footer-widget-area',
  104. 'description' => __( 'The first footer widget area', 'target' ),
  105. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  106. 'after_widget' => '</li>',
  107. 'before_title' => '<h3 class="widget-title">',
  108. 'after_title' => '</h3>',
  109. ) );
  110. // Area 4, located in the footer. Empty by default.
  111. register_sidebar( array(
  112. 'name' => __( 'Second Footer Widget Area', 'target' ),
  113. 'id' => 'second-footer-widget-area',
  114. 'description' => __( 'The second footer widget area', 'target' ),
  115. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  116. 'after_widget' => '</li>',
  117. 'before_title' => '<h3 class="widget-title">',
  118. 'after_title' => '</h3>',
  119. ) );
  120. // Area 5, located in the footer. Empty by default.
  121. register_sidebar( array(
  122. 'name' => __( 'Third Footer Widget Area', 'target' ),
  123. 'id' => 'third-footer-widget-area',
  124. 'description' => __( 'The third footer widget area', 'target' ),
  125. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  126. 'after_widget' => '</li>',
  127. 'before_title' => '<h3 class="widget-title">',
  128. 'after_title' => '</h3>',
  129. ) );
  130. // Area 6, located in the footer. Empty by default.
  131. register_sidebar( array(
  132. 'name' => __( 'Fourth Footer Widget Area', 'target' ),
  133. 'id' => 'fourth-footer-widget-area',
  134. 'description' => __( 'The fourth footer widget area', 'target' ),
  135. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  136. 'after_widget' => '</li>',
  137. 'before_title' => '<h3 class="widget-title">',
  138. 'after_title' => '</h3>',
  139. ) );
  140. }
  141. if ( ! function_exists( 'target_posted_on' ) ) :
  142. /**
  143. * Prints HTML with meta information for the current post—date/time and author.
  144. */
  145. function target_posted_on() {
  146. printf( __( '%2$s <span class="meta-sep">by</span> %3$s', 'target' ),
  147. 'meta-prep meta-prep-author',
  148. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
  149. get_permalink(),
  150. esc_attr( get_the_time() ),
  151. get_the_date()
  152. ),
  153. sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
  154. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  155. sprintf( esc_attr__( 'View all posts by %s', 'target' ), get_the_author() ),
  156. get_the_author()
  157. )
  158. );
  159. }
  160. endif;
  161. /** Register sidebars by running target_widgets_init() on the widgets_init hook. */
  162. add_action( 'widgets_init', 'target_widgets_init' );
  163. /** Excerpt */
  164. function target_excerpt_length( $length ) {
  165. return 30;
  166. }
  167. add_filter( 'excerpt_length', 'target_excerpt_length' );
  168. function target_auto_excerpt_more( $more ) {
  169. return ' &hellip;' ;
  170. }
  171. add_filter( 'excerpt_more', 'target_auto_excerpt_more' );
  172. /*-----------------------------------------------------------------------------------*/
  173. /* Exclude categories from displaying on the "Blog" page template.
  174. /*-----------------------------------------------------------------------------------*/
  175. // Exclude categories on the "Blog" page template.
  176. add_filter( 'target_blog_template_query_args', 'target_exclude_categories_blogtemplate' );
  177. function target_exclude_categories_blogtemplate ( $args ) {
  178. if ( ! function_exists( 'target_prepare_category_ids_from_option' ) ) { return $args; }
  179. $excluded_cats = array();
  180. // Process the category data and convert all categories to IDs.
  181. $excluded_cats = target_prepare_category_ids_from_option( 'exclude_cat' );
  182. if ( count( $excluded_cats ) > 0 ) {
  183. // Setup the categories as a string, because "category__not_in" doesn't seem to work
  184. // when using query_posts().
  185. foreach ( $excluded_cats as $k => $v ) { $excluded_cats[$k] = '-' . $v; }
  186. $cats = join( ',', $excluded_cats );
  187. $args['cat'] = $cats;
  188. }
  189. return $args;
  190. }
  191. /*-----------------------------------------------------------------------------------*/
  192. /* target_prepare_category_ids_from_option()
  193. /*-----------------------------------------------------------------------------------*/
  194. if ( ! function_exists( 'target_prepare_category_ids_from_option' ) ) {
  195. function target_prepare_category_ids_from_option ( $option ) {
  196. $cats = array();
  197. $stored_cats = of_get_option( $option );
  198. $cats_raw = explode( ',', $stored_cats );
  199. if ( is_array( $cats_raw ) && ( count( $cats_raw ) > 0 ) ) {
  200. foreach ( $cats_raw as $k => $v ) {
  201. $value = trim( $v );
  202. if ( is_numeric( $value ) ) {
  203. $cats_raw[$k] = $value;
  204. } else {
  205. $cat_obj = get_category_by_slug( $value );
  206. if ( isset( $cat_obj->term_id ) ) {
  207. $cats_raw[$k] = $cat_obj->term_id;
  208. }
  209. }
  210. $cats = $cats_raw;
  211. }
  212. }
  213. return $cats;
  214. }
  215. }
  216. // custom function
  217. function target_head_css() {
  218. $output = '';
  219. $custom_css = of_get_option('custom_css');
  220. if ($custom_css <> '') {
  221. $output .= $custom_css . "\n";
  222. }
  223. $main_body_typography = of_get_option('main_body_typography');
  224. if ($main_body_typography) {
  225. $theme_options_styles = '
  226. body{
  227. font-family: ' . $main_body_typography['face'] . ';
  228. font-weight: ' . $main_body_typography['style'] . ';
  229. color: ' . $main_body_typography['color'] . ';
  230. }';
  231. }
  232. $link_color = of_get_option('link_color');
  233. if ($link_color) {
  234. $theme_options_styles .= '
  235. a{
  236. color: ' . $link_color . ';
  237. }';
  238. }
  239. // Output styles
  240. if ($output <> '') {
  241. $output = "<!-- Custom Styling -->\n<style type=\"text/css\">\n" . $output . "</style>\n";
  242. echo $output;
  243. }
  244. if($theme_options_styles){
  245. echo '<style>'
  246. . $theme_options_styles . '
  247. </style>';
  248. }
  249. }
  250. add_action('wp_head', 'target_head_css');
  251. function target_of_analytics(){
  252. $googleanalytics= of_get_option('go_code');
  253. echo stripslashes($googleanalytics);
  254. }
  255. add_action( 'wp_footer', 'target_of_analytics' );
  256. function target_favicon() {
  257. if (of_get_option('favicon_image') != '') {
  258. echo '<link rel="shortcut icon" href="'. of_get_option('favicon_image') .'"/>'."\n";
  259. }
  260. }
  261. add_action('wp_head', 'target_favicon');
  262. function target_date_on() {
  263. printf( __( '<span class="%1$s">Posted on</span> %2$s', 'target' ),
  264. 'meta-prep meta-prep-author',
  265. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
  266. get_permalink(),
  267. esc_attr( get_the_time() ),
  268. get_the_date()
  269. )
  270. );
  271. }
  272. /** filter function for wp_title */
  273. function target_filter_wp_title( $old_title, $sep, $sep_location ){
  274. // add padding to the sep
  275. $ssep = ' ' . $sep . ' ';
  276. // find the type of index page this is
  277. if( is_category() ) $insert = $ssep . 'Category';
  278. elseif( is_tag() ) $insert = $ssep . 'Tag';
  279. elseif( is_author() ) $insert = $ssep . 'Author';
  280. elseif( is_year() || is_month() || is_day() ) $insert = $ssep . 'Archives';
  281. else $insert = NULL;
  282. // get the page number we're on (index)
  283. if( get_query_var( 'paged' ) )
  284. $num = $ssep . 'page ' . get_query_var( 'paged' );
  285. // get the page number we're on (multipage post)
  286. elseif( get_query_var( 'page' ) )
  287. $num = $ssep . 'page ' . get_query_var( 'page' );
  288. // else
  289. else $num = NULL;
  290. // concoct and return new title
  291. return get_bloginfo( 'name' ) . $insert . $old_title . $num;
  292. }
  293. // call our custom wp_title filter, with normal (10) priority, and 3 args
  294. add_filter( 'wp_title', 'target_filter_wp_title', 10, 3 );
  295. function target_of_register_js() {
  296. if (!is_admin()) {
  297. wp_enqueue_script('jquery');
  298. }
  299. }
  300. add_action('init', 'target_of_register_js');
  301. function target_of_single_scripts() {
  302. if(is_singular()) wp_enqueue_script( 'comment-reply' ); // loads the javascript required for threaded comments
  303. }
  304. add_action('wp_print_scripts', 'target_of_single_scripts');
  305. function target_of_styles() {
  306. wp_register_style( 'dropdown', get_template_directory_uri() . '/css/dropdown.css' );
  307. wp_register_style( 'advanced', get_template_directory_uri() . '/css/default.advanced.css' );
  308. wp_enqueue_style( 'dropdown' );
  309. wp_enqueue_style( 'advanced' );
  310. }
  311. add_action('wp_print_styles', 'target_of_styles');
  312. /** redirect */
  313. if ( is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" )
  314. wp_redirect( 'themes.php?page=options-framework');
  315. // include panel file.
  316. if ( !function_exists( 'optionsframework_init' ) ) {
  317. /*-----------------------------------------------------------------------------------*/
  318. /* Options Framework Theme
  319. /*-----------------------------------------------------------------------------------*/
  320. /* Set the file path based on whether the Options Framework Theme is a parent theme or child theme */
  321. if ( get_stylesheet_directory() == get_template_directory_uri() ) {
  322. define('OPTIONS_FRAMEWORK_URL', get_template_directory() . '/admin/');
  323. define('OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/admin/');
  324. } else {
  325. define('OPTIONS_FRAMEWORK_URL', get_template_directory() . '/admin/');
  326. define('OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/admin/');
  327. }
  328. require_once (OPTIONS_FRAMEWORK_URL . 'options-framework.php');
  329. }