PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/blog/wp-content/themes/zbench/functions.php

https://bitbucket.org/sergiohzlz/reportaprod
PHP | 442 lines | 277 code | 42 blank | 123 comment | 16 complexity | 410bdfd61e7b308c60ab0ccd0df1914b MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @package WordPress
  4. * @subpackage zbench
  5. *
  6. * Large chunk of code borrowed from Toolbox. http://wordpress.org/extend/themes/toolbox
  7. */
  8. /**
  9. * Set theme colours and width
  10. */
  11. $themecolors = array(
  12. 'bg' => 'f7f7f7',
  13. 'border' => 'cccccc',
  14. 'text' => '242424',
  15. 'link' => '333',
  16. 'url' => '333'
  17. );
  18. // Calculate content_width based on layout option
  19. $content_width = 630;
  20. if ( 'three-column sidebar-content-sidebar' == zbench_current_layout() )
  21. $content_width = 472;
  22. /**
  23. * Sets up theme defaults and registers support for various WordPress features.
  24. *
  25. * @uses add_custom_background() To add support for a custom background.
  26. * @uses add_editor_style() To style the visual editor.
  27. * @uses add_custom_image_header() To add support for a custom header.
  28. *
  29. * @since zBench 1.0
  30. */
  31. function zbench_setup() {
  32. // This theme uses wp_nav_menu() in one location.
  33. register_nav_menus(
  34. array(
  35. 'primary-menu' => __( 'Primary Menu' ),
  36. )
  37. );
  38. // This theme has some pretty cool theme options
  39. require ( dirname( __FILE__ ) . '/theme-options.php' );
  40. // This theme allows users to set a custom background
  41. add_custom_background();
  42. // This theme allows users to add a custom image header
  43. add_custom_image_header( 'zbench_header_style', 'zbench_admin_header_style', 'zbench_admin_header_image' );
  44. // Add feed links to the head section
  45. add_theme_support( 'automatic-feed-links' );
  46. // Your changeable header business starts here
  47. define( 'HEADER_TEXTCOLOR', '222' ); // Text colour of custom header
  48. define( 'HEADER_IMAGE_WIDTH', 960 ); // Width of custom header
  49. define( 'HEADER_IMAGE_HEIGHT', 200 ); // Height of custom header
  50. }
  51. add_action( 'after_setup_theme', 'zbench_setup' );
  52. /**
  53. * Included in the site head for custom headers
  54. *
  55. * @since zBench 1.0
  56. */
  57. function zbench_header_style() { ?>
  58. <style type="text/css">
  59. <?php if ( get_header_image() ) : ?>
  60. #header-background {
  61. width: 100%;
  62. height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
  63. -moz-border-radius: 6px;
  64. -khtml-border-radius: 6px;
  65. -webkit-border-radius: 6px;
  66. border-radius: 6px;
  67. background: #454546 url(<?php header_image(); ?>) 50% 0;
  68. margin: 0 0 20px 0;
  69. }
  70. #header-background a {
  71. display: block;
  72. text-decoration: none;
  73. width: <?php echo HEADER_IMAGE_WIDTH; ?>px;
  74. height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
  75. }
  76. #header-background a span {
  77. visibility: hidden;
  78. }
  79. <?php endif;
  80. if ( get_header_textcolor() ) : ?>
  81. #title h1,
  82. #title h1 a,
  83. #title p {
  84. color: #<?php header_textcolor(); ?> !important;
  85. }
  86. <?php endif;
  87. /* If text has been hidden */
  88. if ( 'blank' == get_header_textcolor() ) : ?>
  89. /* Remove title text */
  90. #title h1,
  91. #title p {
  92. display: none;
  93. }
  94. <?php
  95. endif;
  96. ?>
  97. </style><?php
  98. }
  99. /**
  100. * Custom header image markup displayed on the Appearance > Header admin panel.
  101. * Referenced via add_custom_image_header() in zbench_setup().
  102. *
  103. * @since zBench 1.0
  104. */
  105. function zbench_admin_header_image() {
  106. $header = get_header_image();
  107. ?>
  108. <div id="zbench_title">
  109. <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php bloginfo( 'url' ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
  110. <p id="desc" <?php echo $style; ?>><?php bloginfo( 'description' ); ?></P>
  111. <?php if ( '' != $header ) : ?>
  112. <div id="header-background"></div>
  113. <?php endif; ?>
  114. </div>
  115. <?php }
  116. /**
  117. * Included in the admin head for custom headers
  118. *
  119. * @since zBench 1.0
  120. */
  121. function zbench_admin_header_style() { ?>
  122. <style type="text/css">
  123. #zbench_title h1 {
  124. float: left;
  125. font-family: Georgia, "Times New Roman", Times,serif;
  126. font-weight: bold;
  127. color: #555;
  128. margin:0 10px 18px;
  129. padding: 0;
  130. text-shadow: 1px 1px 1px #999;
  131. font-size: 28px;
  132. }
  133. #zbench_title, #zbench_title h1 a {
  134. color: #<?php header_textcolor(); ?>;
  135. text-decoration: none;
  136. }
  137. #zbench_title a:hover {
  138. text-decoration: none;
  139. }
  140. #zbench_title p {
  141. float: left;
  142. line-height: 18px;
  143. margin: 5px 0 0 20px;
  144. padding: 0;
  145. color: #<?php header_textcolor(); ?>;
  146. font-family: Georgia, 'Times New Roman', sans-serif;
  147. font-size: 12px;
  148. font-weight: normal;
  149. text-shadow: 0 1px 0 #fff;
  150. }
  151. #zbench_title #header-background {
  152. -moz-border-radius: 6px;
  153. -khtml-border-radius: 6px;
  154. -webkit-border-radius: 6px;
  155. border-radius: 6px;
  156. float: left;
  157. width: <?php echo HEADER_IMAGE_WIDTH; ?>px;
  158. height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
  159. background: url(<?php header_image(); ?>) no-repeat 0 0;
  160. clear: left;
  161. }
  162. </style><?php
  163. }
  164. /**
  165. * Register widget areas
  166. *
  167. * @since zBench 1.0
  168. */
  169. function zbench_widgets_init() {
  170. // Registers Primary Widget Area
  171. register_sidebar(
  172. array (
  173. 'name' => __( 'Primary Widget Area', 'zbench' ),
  174. 'id' => 'primary-widget-area',
  175. 'description' => __( 'The primary widget area', 'zbench' ),
  176. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  177. 'after_widget' => '</div>',
  178. 'before_title' => '<h3 class="widget-title">',
  179. 'after_title' => '</h3>',
  180. )
  181. );
  182. // Registers Secondary Widget Area
  183. register_sidebar(
  184. array (
  185. 'name' => __( 'Secondary Widget Area', 'zbench' ),
  186. 'id' => 'secondary-widget-area',
  187. 'description' => __( 'The primary widget area', 'zbench' ),
  188. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  189. 'after_widget' => '</div>',
  190. 'before_title' => '<h3 class="widget-title">',
  191. 'after_title' => '</h3>',
  192. )
  193. );
  194. // Registers Featured Widget Area
  195. register_sidebar(
  196. array (
  197. 'name' => __( 'Featured Widget Area', 'zbench' ),
  198. 'id' => 'featured-widget-area',
  199. 'description' => __( 'The featured widget area', 'zbench' ),
  200. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  201. 'after_widget' => '</div>',
  202. 'before_title' => '<h3 class="widget-title">',
  203. 'after_title' => '</h3>',
  204. )
  205. );
  206. // Registers First Footer Widget Area
  207. register_sidebar(
  208. array (
  209. 'name' => __( 'First Footer Widget Area', 'zbench' ),
  210. 'id' => 'first-footer-widget-area',
  211. 'description' => __( 'The first footer widget area', 'zbench' ),
  212. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  213. 'after_widget' => '</div>',
  214. 'before_title' => '<h3 class="widget-title">',
  215. 'after_title' => '</h3>',
  216. )
  217. );
  218. // Registers Second Footer Widget Area
  219. register_sidebar(
  220. array (
  221. 'name' => __( 'Second Footer Widget Area', 'zbench' ),
  222. 'id' => 'second-footer-widget-area',
  223. 'description' => __( 'The second footer widget area', 'zbench' ),
  224. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  225. 'after_widget' => '</div>',
  226. 'before_title' => '<h3 class="widget-title">',
  227. 'after_title' => '</h3>',
  228. )
  229. );
  230. // Registers Third Footer Widget Area
  231. register_sidebar(
  232. array (
  233. 'name' => __( 'Third Footer Widget Area', 'zbench' ),
  234. 'id' => 'third-footer-widget-area',
  235. 'description' => __( 'The third footer widget area', 'zbench' ),
  236. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  237. 'after_widget' => '</div>',
  238. 'before_title' => '<h3 class="widget-title">',
  239. 'after_title' => '</h3>',
  240. )
  241. );
  242. // Registers Fourth Footer Widget Area
  243. register_sidebar(
  244. array (
  245. 'name' => __( 'Fourth Footer Widget Area', 'zbench' ),
  246. 'id' => 'fourth-footer-widget-area',
  247. 'description' => __( 'The fourth footer widget area', 'zbench' ),
  248. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  249. 'after_widget' => '</div>',
  250. 'before_title' => '<h3 class="widget-title">',
  251. 'after_title' => '</h3>',
  252. )
  253. );
  254. }
  255. add_action( 'widgets_init', 'zbench_widgets_init' );
  256. /**
  257. * Make theme available for translation
  258. * Translations can be filed in the /languages/ directory
  259. *
  260. * @since zBench 1.0
  261. */
  262. load_theme_textdomain( 'zbench', dirname( __FILE__ ) . '/languages' );
  263. $locale = get_locale();
  264. $locale_file = get_template_directory() . '/languages/$locale.php';
  265. if ( is_readable( $locale_file ) )
  266. require_once( $locale_file );
  267. /**
  268. * Returns the current zBench layout as selected in the theme options
  269. *
  270. * @since zBench 1.0
  271. */
  272. function zbench_current_layout() {
  273. $options = get_option( 'zbench_theme_options' );
  274. $current_layout = $options['theme_layout'];
  275. $two_columns = array( 'content-sidebar', 'sidebar-content' );
  276. if ( in_array( $current_layout, $two_columns ) )
  277. return 'two-column ' . $current_layout;
  278. else
  279. return 'three-column ' . $current_layout;
  280. }
  281. /**
  282. * Adds zbench_current_layout() to the array of body classes
  283. *
  284. * @since zBench 1.0
  285. */
  286. function zbench_body_class($classes) {
  287. $classes[] = zbench_current_layout();
  288. return $classes;
  289. }
  290. add_filter( 'body_class', 'zbench_body_class' );
  291. /**
  292. * Add class attributes to the first <ul> occurence in wp_page_menu and strip <div> tags and strip title attributes
  293. * Needed for suckerfish script to function correctly
  294. * Code courtesy of Ian Stewart ... http://themeshaper.com/adding-class-wordpress-page-menu/
  295. *
  296. * @since zBench 1.0
  297. */
  298. function zbench_add_menuclass( $menu ) {
  299. $menu = preg_replace( '/<ul>/', '<ul class="nav sf-menu">', $menu, 1 ); // Add classes
  300. $menu = preg_replace( '/<div class="nav sf-menu">/', '', $menu, 1 ); // Remove opening DIV
  301. $menu = preg_replace( '/<\/div>/', '', $menu, 1 ); // Remove closing DIV
  302. $menu = preg_replace( '/title=\"(.*?)\"/','',$menu ); // Strip title attributes
  303. return $menu;
  304. }
  305. add_filter( 'wp_page_menu','zbench_add_menuclass' );
  306. /**
  307. * Adding home link to wp_nav_menu() fallback
  308. *
  309. * @since zBench 1.0
  310. */
  311. function zbench_page_menu_args( $args ) {
  312. $args['show_home'] = true;
  313. return $args;
  314. }
  315. add_filter( 'wp_page_menu_args', 'zbench_page_menu_args' );
  316. /**
  317. * Loading scripts
  318. * Animations script from PixoPoint Animations plugin ... http://pixopoint.com/2010/03/03/pixopoint-menu-animations-beta/
  319. * Suckerfish script for IE6 support combined into animations script (already loading JS file so may as well include it there rather than use conditionals)
  320. *
  321. * @since zBench 1.0
  322. */
  323. function zbench_scripts() {
  324. wp_enqueue_script( 'jquery' );
  325. wp_enqueue_script(
  326. 'menu',
  327. get_bloginfo( 'template_url' ) . '/scripts/menu.js',
  328. array( 'jquery' ),
  329. 1.0,
  330. true
  331. );
  332. if ( is_singular() )
  333. wp_enqueue_script( 'comment-reply' );
  334. }
  335. add_action(
  336. 'wp_print_scripts',
  337. 'zbench_scripts'
  338. );
  339. /**
  340. * Comments callback function
  341. *
  342. * @since zBench 1.0
  343. */
  344. function zbench_comment( $comment, $args, $depth ) {
  345. $GLOBALS ['comment'] = $comment; ?>
  346. <?php
  347. /* Display Comments */
  348. if ( '' == $comment->comment_type ) : ?>
  349. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  350. <div id="comment-<?php comment_ID(); ?>">
  351. <?php
  352. /* Display commenters gravatar */
  353. echo get_avatar( $comment, 40 );
  354. /* Display authors name */
  355. printf( __( '<cite class="fn">%s</cite>', 'zbench' ), get_comment_author_link() );
  356. /* Display comment link, date and time */ ?>
  357. <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"><?php printf( __( '%1$s at %2$s', 'zbench' ), get_comment_date(), get_comment_time() ); ?></a>
  358. <?php
  359. /* Edit comment link */
  360. edit_comment_link( __( '(Edit)', 'zbench' ),' ','' );
  361. /* Message for when comment not approved yet */
  362. if ( $comment->comment_approved == '0' )
  363. echo '<em>' . __( 'Your comment is awaiting moderation.', 'zbench' ) . '</em><br />';
  364. /* Display the comment itself */ ?>
  365. <div class="comment-body"><?php comment_text(); ?></div>
  366. <div class="reply">
  367. <?php
  368. /* Comment reply link */
  369. comment_reply_link(
  370. array_merge(
  371. $args, array(
  372. 'depth' => $depth,
  373. 'max_depth' => $args['max_depth']
  374. )
  375. )
  376. );
  377. ?>
  378. </div>
  379. </div>
  380. <?php
  381. /* Display pingbacks */
  382. else : ?>
  383. <li class="post pingback">
  384. <p><?php _e( 'Pingback: ', 'zbench' ); ?><?php comment_author_link(); ?><?php edit_comment_link ( __( 'edit', 'zbench' ), '&nbsp;&nbsp;', '' ); ?></p>
  385. <?php endif;
  386. }
  387. /*
  388. * Register with hook 'wp_print_styles'
  389. * Enqueue style sheet
  390. *
  391. * @since zBench 1.0
  392. */
  393. add_action( 'wp_print_styles', 'zbench_stylesheet' );
  394. function zbench_stylesheet() {
  395. $options = get_option( 'zbench_theme_options' );
  396. // Register stylesheets
  397. wp_register_style( 'zbench_stylesheet', get_bloginfo( 'stylesheet_url' ) );
  398. // Load stylesheets
  399. wp_enqueue_style( 'zbench_stylesheet' );
  400. }