PageRenderTime 99ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/themes/eclipse/core/core-functions.php

https://github.com/Bochet/festival_lgbt
PHP | 394 lines | 282 code | 60 blank | 52 comment | 91 complexity | c15e4aee766d338146c05925c9cd5ba9 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /**
  3. * CyberChimps response Core Functions
  4. *
  5. * Authors: Tyler Cunningham
  6. * Copyright: Š 2012
  7. * {@link http://cyberchimps.com/ CyberChimps LLC}
  8. *
  9. * Released under the terms of the GNU General Public License.
  10. * You should have received a copy of the GNU General Public License,
  11. * along with this software. In the main directory, see: /licensing/
  12. * If not, see: {@link http://www.gnu.org/licenses/}.
  13. *
  14. * @package response
  15. * @since 1.0
  16. */
  17. /**
  18. * Load styles.
  19. */
  20. function eclipse_styles() {
  21. global $options, $ec_themeslug, $wp_styles;
  22. // set paths to stylesheet dir
  23. $core_path = get_template_directory_uri() ."/core/css";
  24. $path = get_template_directory_uri() ."/css";
  25. // register stylesheets
  26. wp_register_style( 'foundation', $core_path.'/foundation.css' );
  27. wp_register_style( 'foundation_apps', $core_path.'/app.css', array( 'foundation' ) );
  28. wp_register_style( 'shortcode', $path.'/shortcode.css' );
  29. wp_register_style( 'eclipse_style', $path.'/style.css', array( 'foundation' ) );
  30. wp_register_style( 'elements', $path.'/elements.css', array( 'foundation', 'eclipse_style' ) );
  31. // ie conditional stylesheet
  32. wp_register_style( 'eclipse_ie', $core_path.'/ie.css' );
  33. $wp_styles->add_data( 'eclipse_ie', 'conditional', 'IE' );
  34. // child theme support
  35. wp_register_style( 'child_theme', get_stylesheet_directory_uri().'/style.css', array( 'eclipse_style' ) );
  36. if( is_child_theme() ) {
  37. wp_enqueue_style( 'child_theme' );
  38. }
  39. // get fonts
  40. if ($options->get($ec_themeslug.'_font') == "" AND $options->get($ec_themeslug.'_custom_font') == "") {
  41. $font = apply_filters( 'synapse_default_font', 'Arial' );
  42. }
  43. elseif ($options->get($ec_themeslug.'_custom_font') != "" && $options->get($ec_themeslug.'_font') == 'custom') {
  44. $font = $options->get($ec_themeslug.'_custom_font');
  45. }
  46. else {
  47. $font = $options->get($ec_themeslug.'_font');
  48. }
  49. // register font stylesheet
  50. if( $font == 'Actor' ||
  51. $font == 'Coda' ||
  52. $font == 'Maven Pro' ||
  53. $font == 'Metrophobic' ||
  54. $font == 'News Cycle' ||
  55. $font == 'Nobile' ||
  56. $font == 'Tenor Sans' ||
  57. $font == 'Quicksand' ||
  58. $font == 'Ubuntu') {
  59. // Check if SSL is present, if so then use https othereise use http
  60. $protocol = is_ssl() ? 'https' : 'http';
  61. wp_register_style( 'fonts', $protocol . '://fonts.googleapis.com/css?family='.$font, array( 'eclipse_style' ) );
  62. }
  63. // enqueue stylesheets
  64. wp_enqueue_style( 'foundation' );
  65. wp_enqueue_style( 'foundation_apps' );
  66. wp_enqueue_style( 'shortcode' );
  67. wp_enqueue_style( 'eclipse_style' );
  68. wp_enqueue_style( 'elements' );
  69. wp_enqueue_style( 'fonts' );
  70. wp_enqueue_style( 'eclipse_ie' );
  71. }
  72. add_action( 'wp_enqueue_scripts', 'eclipse_styles' );
  73. /**
  74. * Load jQuery and register additional scripts.
  75. */
  76. function response_scripts() {
  77. global $options, $ec_themeslug;
  78. if ( !is_admin() ) {
  79. wp_enqueue_script('jquery');
  80. wp_enqueue_script('jquery-ui-tabs');
  81. }
  82. $path = get_template_directory_uri() ."/core/library";
  83. wp_register_script( 'orbit' ,$path.'/js/foundation/jquery.orbit.js');
  84. wp_register_script( 'apps' ,$path.'/js/foundation/app.js');
  85. wp_register_script( 'placeholder' ,$path.'/js/foundation/jquery.placeholder.min.js');
  86. wp_register_script( 'reveal' ,$path.'/js/foundation/jquery.reveal.js');
  87. wp_register_script( 'tooltips' ,$path.'/js/foundation/jquery.tooltips.js');
  88. wp_register_script( 'modernizr' ,$path.'/js/foundation/modernizr.foundation.js');
  89. wp_register_script( 'menu' ,$path.'/js/menu.js');
  90. wp_register_script( 'slimbox' ,$path.'/js/jquery.slimbox.js');
  91. wp_register_script( 'plusone' ,$path.'/js/plusone.js');
  92. wp_register_script( 'mobilemenu' ,$path.'/js/mobilemenu.js');
  93. wp_register_script( 'oembed' ,$path.'/js/oembed-twitter.js');
  94. wp_enqueue_script ('orbit');
  95. wp_enqueue_script ('apps');
  96. wp_enqueue_script ('placeholder');
  97. wp_enqueue_script ('reveal');
  98. wp_enqueue_script ('tooltips');
  99. wp_enqueue_script ('modernizr');
  100. wp_enqueue_script ('menu');
  101. wp_enqueue_script ('slimbox');
  102. wp_enqueue_script ('plusone');
  103. wp_enqueue_script ('mobilemenu');
  104. wp_enqueue_script ('oembed');
  105. if ( is_singular() ) wp_enqueue_script( 'comment-reply' );
  106. if ($options->get($ec_themeslug.'_responsive_video') == '1' ) {
  107. wp_register_script( 'video' ,$path.'/js/video.js');
  108. wp_enqueue_script ('video');
  109. }
  110. }
  111. add_action('wp_enqueue_scripts', 'response_scripts');
  112. /**
  113. * Custom pagination.
  114. *
  115. * @since 1.0
  116. */
  117. function response_custom_pagination($pages = '', $range = 4)
  118. {
  119. $showitems = ($range * 2)+1;
  120. global $paged;
  121. if(empty($paged)) $paged = 1;
  122. if($pages == '')
  123. {
  124. global $wp_query;
  125. $pages = $wp_query->max_num_pages;
  126. if(!$pages)
  127. {
  128. $pages = 1;
  129. }
  130. }
  131. if(1 != $pages)
  132. {
  133. echo '<div class="pagination"><span>'.__( 'Page', 'core' ).' '.$paged.' of '.$pages.'</span>';
  134. if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo '<a href="'.get_pagenum_link(1).'">'.__( '&laquo; First', 'response' ).'</a>';
  135. if($paged > 1 && $showitems < $pages) echo '<a href="'.get_pagenum_link($paged - 1).'">'.__( '&lsaquo; Previous', 'response' ).'</a>';
  136. for ($i=1; $i <= $pages; $i++)
  137. {
  138. if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
  139. {
  140. echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
  141. }
  142. }
  143. if ($paged < $pages && $showitems < $pages) echo '<a href="'.get_pagenum_link($paged + 1).'"">'.__( 'Next &rsaquo;', 'response').'</a>';
  144. if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo '<a href="'.get_pagenum_link($pages).'">'.__( 'Last &raquo;', 'response' ).'</a>';
  145. echo "</div>\n";
  146. }
  147. }
  148. /**
  149. * Truncate next/previous post link text for post pagination.
  150. *
  151. * @since 1.0
  152. */
  153. function response_shorten_linktext($linkstring,$link) {
  154. $characters = 33;
  155. preg_match('/<a.*?>(.*?)<\/a>/is',$linkstring,$matches);
  156. $displayedTitle = $matches[1];
  157. $newTitle = shorten_with_ellipsis($displayedTitle,$characters);
  158. return str_replace('>'.$displayedTitle.'<','>'.$newTitle.'<',$linkstring);
  159. }
  160. function shorten_with_ellipsis($inputstring,$characters) {
  161. return (strlen($inputstring) >= $characters) ? substr($inputstring,0,($characters-3)) . '...' : $inputstring;
  162. }
  163. add_filter('previous_post_link','response_shorten_linktext',10,2);
  164. add_filter('next_post_link','response_shorten_linktext',10,2);
  165. /**
  166. * Comment function
  167. *
  168. * @since 1.0
  169. */
  170. function response_comment($comment, $args, $depth) {
  171. global $ec_root;
  172. $GLOBALS['comment'] = $comment; ?>
  173. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
  174. <div id="comment-<?php comment_ID(); ?>">
  175. <div class="comment-author vcard">
  176. <?php echo get_avatar( $comment, 66 ); ?>
  177. </div>
  178. <img class="triangle" style="margin-bottom: -30px; margin-left: 7px;" src="<?php echo "$ec_root/images/comment-triangle.png";?>">
  179. <div style="background-color: #1a1a1a; margin-left: 100px; padding: 15px 15px 10px 10px; margin-top: -18px; border-radius: 4px; ;">
  180. <div class="comment-meta commentmetadata"> <span class="comment_author" style="float:left"><?php printf(__('<cite class="fn">%s</cite> <span class="says"></span>'), get_comment_author_link()) ?></span><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s', 'core' ), get_comment_date(), get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)', 'core' ),' ','') ?> | <span class="reply"> <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?></span>
  181. </div>
  182. <?php if ($comment->comment_approved == '0') : ?>
  183. <em><?php _e('Your comment is awaiting moderation.', 'core' ) ?></em>
  184. <br />
  185. <?php endif; ?>
  186. <div class="comment_wrap">
  187. <?php comment_text() ?>
  188. </div>
  189. </div></div>
  190. <?php
  191. }
  192. /**
  193. * Breadcrumbs function
  194. *
  195. * @since 1.0
  196. */
  197. function response_breadcrumbs() {
  198. global $ec_root;
  199. $delimiter = "<img src='$ec_root/images/breadcrumb-arrow.png'>";
  200. $home = 'Home'; // text for the 'Home' link
  201. $before = '<span class="current">'; // tag before the current crumb
  202. $after = '</span>'; // tag after the current crumb
  203. if ( !is_home() && !is_front_page() || is_paged() ) {
  204. echo '<div class="row"><div id="crumbs" class="twelve columns"><div class="crumbs_text">';
  205. global $post;
  206. $homeLink = home_url();
  207. echo '<a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' ';
  208. if ( is_category() ) {
  209. global $wp_query;
  210. $cat_obj = $wp_query->get_queried_object();
  211. $thisCat = $cat_obj->term_id;
  212. $thisCat = get_category($thisCat);
  213. $parentCat = get_category($thisCat->parent);
  214. if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
  215. echo $before . 'Archive for category "' . single_cat_title('', false) . '"' . $after;
  216. } elseif ( is_day() ) {
  217. echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
  218. echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
  219. echo $before . get_the_time('d') . $after;
  220. } elseif ( is_month() ) {
  221. echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
  222. echo $before . get_the_time('F') . $after;
  223. } elseif ( is_year() ) {
  224. echo $before . get_the_time('Y') . $after;
  225. } elseif ( is_single() && !is_attachment() ) {
  226. if ( get_post_type() != 'post' ) {
  227. $post_type = get_post_type_object(get_post_type());
  228. $slug = $post_type->rewrite;
  229. echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';
  230. echo $before . get_the_title() . $after;
  231. } else {
  232. $cat = get_the_category(); $cat = $cat[0];
  233. echo is_wp_error( $cat_parents = get_category_parents($cat, TRUE, ' ' . $delimiter . ' ') ) ? '' : $cat_parents;
  234. echo $before . get_the_title() . $after;
  235. }
  236. } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
  237. $post_type = get_post_type_object(get_post_type());
  238. echo $before . $post_type->labels->singular_name . $after;
  239. } elseif ( is_attachment() ) {
  240. $parent = get_post($post->post_parent);
  241. $cat = get_the_category($parent->ID); $cat = $cat[0];
  242. echo is_wp_error( $cat_parents = get_category_parents($cat, TRUE, ' ' . $delimiter . ' ') ) ? '' : $cat_parents;
  243. echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
  244. echo $before . get_the_title() . $after;
  245. } elseif ( is_page() && !$post->post_parent ) {
  246. echo $before . get_the_title() . $after;
  247. } elseif ( is_page() && $post->post_parent ) {
  248. $parent_id = $post->post_parent;
  249. $breadcrumbs = array();
  250. while ($parent_id) {
  251. $page = get_page($parent_id);
  252. $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
  253. $parent_id = $page->post_parent;
  254. }
  255. $breadcrumbs = array_reverse($breadcrumbs);
  256. foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
  257. echo $before . get_the_title() . $after;
  258. } elseif ( is_search() ) {
  259. echo $before . 'Search results for "' . get_search_query() . '"' . $after;
  260. } elseif ( is_tag() ) {
  261. echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;
  262. } elseif ( is_author() ) {
  263. global $author;
  264. $userdata = get_userdata($author);
  265. echo $before . 'Articles posted by ' . $userdata->display_name . $after;
  266. } elseif ( is_404() ) {
  267. echo $before . 'Error 404' . $after;
  268. }
  269. if ( get_query_var('paged') ) {
  270. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
  271. echo __('Page', 'response') . ' ' . get_query_var('paged');
  272. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
  273. }
  274. echo '</div></div></div>';
  275. }
  276. }
  277. function response_title_tag_filter( $old_title ) {
  278. global $options, $themeslug, $query, $post;
  279. $blogtitle = ($options->get($themeslug.'_home_title'));
  280. if (!is_404()) {
  281. $title = get_post_meta($post->ID, 'seo_title' , true);
  282. }
  283. else {
  284. $title = '';
  285. }
  286. if (function_exists('is_tag') && is_tag()) { /*Title for tags */
  287. $title_tag = get_bloginfo('name').' - Tag Archive for &quot;'.single_tag_title("", FALSE).'&quot; ';
  288. }
  289. elseif( is_feed() ) {
  290. $title_tag = '';
  291. }
  292. elseif (is_archive()) { /*Title for archives */
  293. $title_tag = get_bloginfo('name').$old_title.' Archive ';
  294. }
  295. elseif (is_search()) { /*Title for search */
  296. $title_tag = get_bloginfo('name').' - Search for &quot;'.get_search_query().'&quot; ';
  297. }
  298. elseif (is_404()) { /*Title for 404 */
  299. $title_tag = get_bloginfo('name').' - Not Found ';
  300. }
  301. elseif (is_front_page() AND !is_page() AND $blogtitle == '') { /*Title if front page is latest posts and no custom title */
  302. $title_tag = get_bloginfo('name').' - '.get_bloginfo('description');
  303. }
  304. elseif (is_front_page() AND !is_page() AND $blogtitle != '') { /*Title if front page is latest posts with custom title */
  305. $title_tag = get_bloginfo('name').' - '.$blogtitle ;
  306. }
  307. elseif (is_front_page() AND is_page() AND $title == '') { /*Title if front page is static page and no custom title */
  308. $title_tag = get_bloginfo('name').' - '.get_bloginfo('description');
  309. }
  310. elseif (is_front_page() AND is_page() AND $title != '') { /*Title if front page is static page with custom title */
  311. $title_tag = get_bloginfo('name').' - '.$title ;
  312. }
  313. elseif (is_page() AND $title == '') { /*Title if static page is static page with no custom title */
  314. $title_tag = get_bloginfo('name').$old_title;
  315. }
  316. elseif (is_page() AND $title != '') { /*Title if static page is static page with custom title */
  317. $title_tag = get_bloginfo('name').' - '.$title ;
  318. }
  319. elseif (is_page() AND is_front_page() AND $blogtitle == '') { /*Title if blog page with no custom title */
  320. $title_tag = get_bloginfo('name').$old_title;
  321. }
  322. elseif ($blogtitle != '') { /*Title if blog page with custom title */
  323. $title_tag = get_bloginfo('name').' - '.$blogtitle ;
  324. }
  325. else { /*Title if blog page without custom title */
  326. $title_tag = get_bloginfo('name').$old_title;
  327. }
  328. return $title_tag;
  329. }
  330. add_filter( 'wp_title', 'response_title_tag_filter', 10, 3 )
  331. /**
  332. * End
  333. */
  334. ?>