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

/wp-content/themes/news/library/functions/core.php

https://bitbucket.org/lgorence/quickpress
PHP | 216 lines | 60 code | 30 blank | 126 comment | 8 complexity | 8fee48a31c04f28b4f640cf9a2a0bfea MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * The core functions file for the Hybrid framework. Functions defined here are generally
  4. * used across the entire framework to make various tasks faster. This file should be loaded
  5. * prior to any other files because its functions are needed to run the framework.
  6. *
  7. * @package HybridCore
  8. * @subpackage Functions
  9. * @author Justin Tadlock <justin@justintadlock.com>
  10. * @copyright Copyright (c) 2008 - 2012, Justin Tadlock
  11. * @link http://themehybrid.com/hybrid-core
  12. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  13. */
  14. /**
  15. * Defines the theme prefix. This allows developers to infinitely change the theme. In theory,
  16. * one could use the Hybrid core to create their own theme or filter 'hybrid_prefix' with a
  17. * plugin to make it easier to use hooks across multiple themes without having to figure out
  18. * each theme's hooks (assuming other themes used the same system).
  19. *
  20. * @since 0.7.0
  21. * @access public
  22. * @uses get_template() Defines the theme prefix based on the theme directory.
  23. * @global object $hybrid The global Hybrid object.
  24. * @return string $hybrid->prefix The prefix of the theme.
  25. */
  26. function hybrid_get_prefix() {
  27. global $hybrid;
  28. /* If the global prefix isn't set, define it. Plugin/theme authors may also define a custom prefix. */
  29. if ( empty( $hybrid->prefix ) )
  30. $hybrid->prefix = sanitize_key( apply_filters( 'hybrid_prefix', get_template() ) );
  31. return $hybrid->prefix;
  32. }
  33. /**
  34. * Adds contextual action hooks to the theme. This allows users to easily add context-based content
  35. * without having to know how to use WordPress conditional tags. The theme handles the logic.
  36. *
  37. * An example of a basic hook would be 'hybrid_header'. The do_atomic() function extends that to
  38. * give extra hooks such as 'hybrid_singular_header', 'hybrid_singular-post_header', and
  39. * 'hybrid_singular-post-ID_header'.
  40. *
  41. * @since 0.7.0
  42. * @access public
  43. * @uses hybrid_get_prefix() Gets the theme prefix.
  44. * @uses hybrid_get_context() Gets the context of the current page.
  45. * @param string $tag Usually the location of the hook but defines what the base hook is.
  46. * @param mixed $arg,... Optional additional arguments which are passed on to the functions hooked to the action.
  47. */
  48. function do_atomic( $tag = '', $arg = '' ) {
  49. if ( empty( $tag ) )
  50. return false;
  51. /* Get the theme prefix. */
  52. $pre = hybrid_get_prefix();
  53. /* Get the args passed into the function and remove $tag. */
  54. $args = func_get_args();
  55. array_splice( $args, 0, 1 );
  56. /* Do actions on the basic hook. */
  57. do_action_ref_array( "{$pre}_{$tag}", $args );
  58. /* Loop through context array and fire actions on a contextual scale. */
  59. foreach ( (array)hybrid_get_context() as $context )
  60. do_action_ref_array( "{$pre}_{$context}_{$tag}", $args );
  61. }
  62. /**
  63. * Adds contextual filter hooks to the theme. This allows users to easily filter context-based content
  64. * without having to know how to use WordPress conditional tags. The theme handles the logic.
  65. *
  66. * An example of a basic hook would be 'hybrid_entry_meta'. The apply_atomic() function extends
  67. * that to give extra hooks such as 'hybrid_singular_entry_meta', 'hybrid_singular-post_entry_meta',
  68. * and 'hybrid_singular-post-ID_entry_meta'.
  69. *
  70. * @since 0.7.0
  71. * @access public
  72. * @uses hybrid_get_prefix() Gets the theme prefix.
  73. * @uses hybrid_get_context() Gets the context of the current page.
  74. * @param string $tag Usually the location of the hook but defines what the base hook is.
  75. * @param mixed $value The value on which the filters hooked to $tag are applied on.
  76. * @param mixed $var,... Additional variables passed to the functions hooked to $tag.
  77. * @return mixed $value The value after it has been filtered.
  78. */
  79. function apply_atomic( $tag = '', $value = '' ) {
  80. if ( empty( $tag ) )
  81. return false;
  82. /* Get theme prefix. */
  83. $pre = hybrid_get_prefix();
  84. /* Get the args passed into the function and remove $tag. */
  85. $args = func_get_args();
  86. array_splice( $args, 0, 1 );
  87. /* Apply filters on the basic hook. */
  88. $value = $args[0] = apply_filters_ref_array( "{$pre}_{$tag}", $args );
  89. /* Loop through context array and apply filters on a contextual scale. */
  90. foreach ( (array)hybrid_get_context() as $context )
  91. $value = $args[0] = apply_filters_ref_array( "{$pre}_{$context}_{$tag}", $args );
  92. /* Return the final value once all filters have been applied. */
  93. return $value;
  94. }
  95. /**
  96. * Wraps the output of apply_atomic() in a call to do_shortcode(). This allows developers to use
  97. * context-aware functionality alongside shortcodes. Rather than adding a lot of code to the
  98. * function itself, developers can create individual functions to handle shortcodes.
  99. *
  100. * @since 0.7.0
  101. * @access public
  102. * @param string $tag Usually the location of the hook but defines what the base hook is.
  103. * @param mixed $value The value to be filtered.
  104. * @return mixed $value The value after it has been filtered.
  105. */
  106. function apply_atomic_shortcode( $tag = '', $value = '' ) {
  107. return do_shortcode( apply_atomic( $tag, $value ) );
  108. }
  109. /**
  110. * The theme can save multiple things in a transient to help speed up page load times. We're
  111. * setting a default of 12 hours or 43,200 seconds (60 * 60 * 12).
  112. *
  113. * @since 0.8.0
  114. * @access public
  115. * @return int Transient expiration time in seconds.
  116. */
  117. function hybrid_get_transient_expiration() {
  118. return apply_filters( hybrid_get_prefix() . '_transient_expiration', 43200 );
  119. }
  120. /**
  121. * Function for formatting a hook name if needed. It automatically adds the theme's prefix to
  122. * the hook, and it will add a context (or any variable) if it's given.
  123. *
  124. * @since 0.7.0
  125. * @access public
  126. * @param string $tag The basic name of the hook (e.g., 'before_header').
  127. * @param string $context A specific context/value to be added to the hook.
  128. */
  129. function hybrid_format_hook( $tag, $context = '' ) {
  130. return hybrid_get_prefix() . ( ( !empty( $context ) ) ? "_{$context}" : "" ). "_{$tag}";
  131. }
  132. /**
  133. * Function for setting the content width of a theme. This does not check if a content width has been set; it
  134. * simply overwrites whatever the content width is.
  135. *
  136. * @since 1.2.0
  137. * @access public
  138. * @global int $content_width The width for the theme's content area.
  139. * @param int $width Numeric value of the width to set.
  140. */
  141. function hybrid_set_content_width( $width = '' ) {
  142. global $content_width;
  143. $content_width = absint( $width );
  144. }
  145. /**
  146. * Function for getting the theme's content width.
  147. *
  148. * @since 1.2.0
  149. * @access public
  150. * @global int $content_width The width for the theme's content area.
  151. * @return int $content_width
  152. */
  153. function hybrid_get_content_width() {
  154. global $content_width;
  155. return $content_width;
  156. }
  157. /**
  158. * Gets theme data and stores it in the global $hybrid variable. By storing it, it can be accessed quickly without
  159. * having to run through the get_theme_data() function again.
  160. *
  161. * @since 1.2.0
  162. * @access public
  163. * @param string $path Whether to use the template (parent theme) or stylesheet (child theme) path.
  164. */
  165. function hybrid_get_theme_data( $path = 'template' ) {
  166. global $hybrid;
  167. /* If 'template' is requested, get the parent theme data. */
  168. if ( 'template' == $path ) {
  169. /* If the parent theme data isn't set, grab it with the get_theme_data() function. */
  170. if ( empty( $hybrid->theme_data ) )
  171. $hybrid->theme_data = get_theme_data( trailingslashit( TEMPLATEPATH ) . 'style.css' );
  172. /* Return the parent theme data. */
  173. return $hybrid->theme_data;
  174. }
  175. /* If 'stylesheet' is requested, get the child theme data. */
  176. elseif ( 'stylesheet' == $path ) {
  177. /* If the child theme data isn't set, grab it with the get_theme_data() function. */
  178. if ( empty( $hybrid->child_theme_data ) )
  179. $hybrid->child_theme_data = get_theme_data( trailingslashit( STYLESHEETPATH ) . 'style.css' );
  180. /* Return the child theme data. */
  181. return $hybrid->child_theme_data;
  182. }
  183. /* Return false for everything else. */
  184. return false;
  185. }
  186. ?>