Advertisement
Guest User

functions

a guest
May 15th, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.34 KB | None | 0 0
  1. <?php
  2.  
  3. /*************************** Localisation ***************************/
  4.  
  5. load_theme_textdomain('gp_lang', TEMPLATEPATH . '/languages');
  6. $locale = get_locale();
  7. $locale_file = TEMPLATEPATH."/languages/$locale.php";
  8. if(is_readable($locale_file)) require_once($locale_file);
  9.  
  10.  
  11. /*************************** Theme Information ***************************/
  12.  
  13. $themename = __('Bounce', 'gp_lang'); // Theme Name
  14. $dirname = "bounce"; // Directory Name
  15.  
  16.  
  17. /*************************** File Directories ***************************/
  18.  
  19. define("ghostpool", TEMPLATEPATH . '/');
  20. define("ghostpool_inc", TEMPLATEPATH . '/lib/inc/');
  21. define("ghostpool_scripts", TEMPLATEPATH . '/lib/scripts/');
  22. define("ghostpool_admin", TEMPLATEPATH . '/lib/admin/inc/');
  23. define("ghostpool_bp", TEMPLATEPATH . '/lib/buddypress/');
  24. define("BP_THEME_URL", get_template_directory_uri());
  25.  
  26.  
  27. /*************************** Additional Functions ***************************/
  28.  
  29. // Main Theme Options
  30. require_once(ghostpool_admin . 'theme-options.php');
  31. require(ghostpool_inc . 'options.php');
  32.  
  33. // Meta Options
  34. require_once(ghostpool_admin . 'theme-meta-options.php');
  35.  
  36. // Sidebars
  37. require_once(ghostpool_admin . 'theme-sidebars.php');
  38.  
  39. // Shortcodes
  40. require_once(ghostpool_admin . 'theme-shortcodes.php');
  41.  
  42. // Custom Post Types
  43. require_once(ghostpool_admin . 'theme-post-types.php');
  44.  
  45. // TinyMCE
  46. require_once (ghostpool_admin . 'tinymce/tinymce.php');
  47.  
  48. // Update Notification
  49. require_once(ghostpool_admin . 'theme-update-notification.php');
  50.  
  51. // WP Show IDs
  52. require_once(ghostpool_admin . 'wp-show-ids/wp-show-ids.php');
  53.  
  54. // Import/Export Widgets
  55. require_once(ghostpool_admin . 'widget-settings-importexport/widget_data.php');
  56.  
  57. // Image Resizer
  58. require_once(ghostpool_scripts . 'image-resizer.php');
  59.  
  60. // BuddyPress Functions
  61. if(function_exists('bp_is_active') && file_exists(ghostpool_bp.'functions-buddypress.php')) { require_once(ghostpool_bp . 'functions-buddypress.php'); }
  62.  
  63.  
  64. /*************************** Enqueue Styles ***************************/
  65.  
  66. function gp_enqueue_styles() {
  67. if(!is_admin()){
  68.  
  69. global $post;
  70. require(ghostpool_inc . 'options.php');
  71.  
  72. wp_enqueue_style('reset', get_template_directory_uri().'/lib/css/reset.css');
  73.  
  74. wp_enqueue_style('style', get_template_directory_uri().'/style.css');
  75.  
  76. wp_enqueue_style('responsive', get_template_directory_uri().'/responsive.css');
  77.  
  78. wp_enqueue_style('prettyphoto', get_template_directory_uri().'/lib/scripts/prettyPhoto/css/prettyPhoto.css');
  79.  
  80. wp_enqueue_style('lato', 'http://fonts.googleapis.com/css?family=Lato:400,300,100');
  81.  
  82. wp_enqueue_style('raleway', 'http://fonts.googleapis.com/css?family=Raleway:100');
  83.  
  84. if(isset($_COOKIE['SkinCookie'])) {
  85. global $skin;
  86. $skin = $_COOKIE['SkinCookie'];
  87. }
  88.  
  89. if(isset($_GET['skin'])) {
  90. global $skin;
  91. $skin = $_GET['skin'];
  92. setcookie('SkinCookie', $skin);
  93. }
  94.  
  95. if(isset($_GET['skin']) && $_GET['skin'] == "default") {
  96. global $skin;
  97. $skin = $theme_skin;
  98. setcookie('SkinCookie', $skin, time()-3600);
  99. }
  100.  
  101. if((isset($_GET['skin']) && $_GET['skin'] != "default") OR (isset($_COOKIE['SkinCookie']) && $_COOKIE['SkinCookie'] != "default")) {
  102.  
  103. function gp_skin_class($classes) {
  104. global $skin;
  105. $classes[] = 'skin-'.$skin;
  106. return $classes;
  107. }
  108. add_filter('body_class','gp_skin_class');
  109.  
  110. wp_enqueue_style('style-skin', get_template_directory_uri().'/style-'.$skin.'.css');
  111.  
  112. } else {
  113.  
  114. if((is_singular() && !is_attachment() && !is_404()) && (get_post_meta($post->ID, 'ghostpool_skin', true) && get_post_meta($post->ID, 'ghostpool_skin', true) != "Default")) {
  115.  
  116. function gp_skin_class($classes) {
  117. global $post;
  118. $classes[] = 'skin-'.get_post_meta($post->ID, 'ghostpool_skin', true);
  119. return $classes;
  120. }
  121. add_filter('body_class','gp_skin_class');
  122.  
  123. wp_enqueue_style('style-skin', get_template_directory_uri().'/style-'.get_post_meta($post->ID, 'ghostpool_skin', true).'.css');
  124.  
  125. } else {
  126.  
  127. function gp_skin_class($classes) {
  128. global $theme_skin;
  129. $classes[] = 'skin-'.$theme_skin;
  130. return $classes;
  131. }
  132. add_filter('body_class','gp_skin_class');
  133.  
  134. wp_enqueue_style('style-skin', get_template_directory_uri().'/style-'.$theme_skin.'.css');
  135.  
  136. }
  137.  
  138. }
  139.  
  140. if($theme_custom_stylesheet) {
  141.  
  142. wp_enqueue_style('style-theme-custom', get_template_directory_uri().'/'.$theme_custom_stylesheet);
  143.  
  144. }
  145.  
  146. if((is_single() OR is_page()) && get_post_meta($post->ID, 'ghostpool_custom_stylesheet', true)) {
  147.  
  148. wp_enqueue_style('style-page-custom', get_template_directory_uri().'/'.get_post_meta($post->ID, 'ghostpool_custom_stylesheet', true));
  149.  
  150. }
  151.  
  152. }
  153. }
  154. add_action('wp_print_styles', 'gp_enqueue_styles');
  155.  
  156.  
  157. /*************************** Enqueue Scripts ***************************/
  158.  
  159. function gp_enqueue_scripts() {
  160. if(!is_admin()){
  161.  
  162. require(ghostpool_inc . 'options.php');
  163.  
  164. wp_enqueue_script('jquery');
  165.  
  166. wp_enqueue_script('jqueryui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js', array('jquery'));
  167.  
  168. if(is_singular()) wp_enqueue_script('comment-reply');
  169.  
  170. wp_enqueue_script('swfobject', 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js');
  171.  
  172. wp_enqueue_script('jwplayer', get_template_directory_uri().'/lib/scripts/mediaplayer/jwplayer.js', array('jquery'));
  173.  
  174. wp_enqueue_script('flex-slider', get_template_directory_uri().'/lib/scripts/jquery.flexslider.js', array('jquery'));
  175.  
  176. wp_enqueue_script('prettyphoto', get_template_directory_uri().'/lib/scripts/prettyPhoto/js/jquery.prettyPhoto.js', array('jquery'));
  177.  
  178. }
  179. }
  180. add_action('wp_print_scripts', 'gp_enqueue_scripts');
  181.  
  182.  
  183. /*************************** WP Header Hooks ***************************/
  184.  
  185. function gp_wp_header() {
  186.  
  187. require(ghostpool_inc . 'options.php');
  188.  
  189. if($theme_favicon_ico) echo '<link rel="shortcut icon" href="'.$theme_favicon_ico.'" /><link rel="icon" href="'.$theme_favicon_ico.'" type="image/vnd.microsoft.icon" />';
  190.  
  191. if($theme_favicon_png) echo '<link rel="icon" type="image/png" href="'.$theme_favicon_png.'" />';
  192.  
  193. if($theme_apple_icon) echo '<link rel="apple-touch-icon" href="'.$theme_apple_icon.'" />';
  194.  
  195. if($theme_custom_css) echo '<style>'.stripslashes($theme_custom_css).'</style>';
  196.  
  197. echo stripslashes($theme_scripts);
  198.  
  199. echo '
  200. <!--[if lte IE 9]>
  201. <style>
  202. dropcap#header-outer, #nav, #top-content, #top-content.top-content-stripe, #top-content #searchform, .author-info, .sc-price-box, .widget_nav_menu a:hover, .widget_nav_menu .current-menu-item > a, .wp-pagenavi span, .wp-pagenavi.cat-navi a, .wp-pagenavi.comment-navi a, .wp-pagenavi.post-navi a span, .gallery img, .frame #content-wrapper, .post-thumbnail, .sc-button, .sc-button:hover, .separate > div, .sc-image.image-border, .dropcap2, .dropcap3, .dropcap4, .dropcap5, .notify, .comment-avatar img, .post-author, #bp-links a, .avatar {
  203. behavior: url("'.get_template_directory_uri().'/lib/scripts/pie/PIE.php");
  204. }
  205. </style>
  206. <![endif]-->';
  207.  
  208. }
  209. add_action('wp_head', 'gp_wp_header');
  210.  
  211.  
  212. /*************************** Featured Image Sizes ***************************/
  213.  
  214. add_theme_support('post-thumbnails');
  215. set_post_thumbnail_size(150, 150, true);
  216.  
  217.  
  218. /*************************** bbPress Support ***************************/
  219.  
  220. if(is_admin() && function_exists('is_bbpress')) { add_theme_support('bbpress'); }
  221.  
  222.  
  223. /*************************** Navigation Menus ***************************/
  224.  
  225. add_action('init', 'register_my_menus');
  226. function register_my_menus() {
  227. register_nav_menus(array(
  228. 'header-nav' => __('Header Navigation', 'gp_lang')
  229. ));
  230. }
  231.  
  232.  
  233. /*************************** Mobile Navigation ***************************/
  234.  
  235. class gp_mobile_menu extends Walker_Nav_Menu{
  236.  
  237. var $to_depth = -1;
  238.  
  239. function start_lvl(&$output, $depth){
  240. $indent = str_repeat("\t", $depth);
  241. }
  242.  
  243. function end_lvl(&$output, $depth){
  244. $indent = str_repeat("\t", $depth);
  245. }
  246.  
  247. function start_el(&$output, $item, $depth, $args){
  248. $item->title = str_repeat("-", $depth * 2).'&nbsp;'.$item->title;
  249. parent::start_el($output, $item, $depth, $args);
  250. $output = str_replace('<li', '<option value="' . $item->url . '"', $output);
  251. }
  252.  
  253. function end_el(&$output, $item, $depth){
  254. $output .= "</option>\n";
  255. }
  256.  
  257. }
  258.  
  259.  
  260. /*************************** Other Features ***************************/
  261.  
  262. // Add support for custom backgrounds
  263. add_custom_background();
  264.  
  265. // This theme styles the visual editor with editor-style.css to match the theme style.
  266. add_editor_style();
  267.  
  268. // Set the content width based on the theme's design and stylesheet.
  269. if(!isset($content_width)) $content_width = 640;
  270.  
  271. // Add default posts and comments RSS feed links to <head>.
  272. add_theme_support('automatic-feed-links');
  273.  
  274.  
  275. /*************************** Excerpts ***************************/
  276.  
  277. // Excerpt Length
  278. function new_excerpt_length($length) {
  279. return 500;
  280. }
  281. add_filter('excerpt_length', 'new_excerpt_length');
  282.  
  283. function excerpt($limit) {
  284. $excerpt = explode(' ', get_the_excerpt(), $limit);
  285. if (count($excerpt)>=$limit) {
  286. array_pop($excerpt);
  287. $excerpt = implode(" ",$excerpt).'...';
  288. } else {
  289. $excerpt = implode(" ",$excerpt);
  290. }
  291. $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
  292. return $excerpt;
  293. }
  294.  
  295. // Replace excerpt ellipsis
  296. function new_excerpt_more($more) {
  297. return '...';
  298. }
  299. add_filter('excerpt_more', 'new_excerpt_more');
  300. remove_filter('the_excerpt', 'wpautop');
  301.  
  302.  
  303. /*************************** Add Excerpt Support To Pages ***************************/
  304.  
  305. add_action( 'init', 'my_add_excerpts_to_pages' );
  306. function my_add_excerpts_to_pages() {
  307. add_post_type_support( 'page', 'excerpt' );
  308. }
  309.  
  310.  
  311. /*************************** Shortcode Support For Text Widget ***************************/
  312.  
  313. add_filter('widget_text', 'do_shortcode');
  314.  
  315.  
  316. /*************************** Breadcrumbs ***************************/
  317.  
  318. function the_breadcrumb() {
  319. global $post;
  320. if (!is_home()) {
  321. echo '<a href="'.home_url().'">'.__('Home', 'gp_lang').'</a>';
  322. if (is_category()) {
  323. echo " &rsaquo; ";
  324. echo single_cat_title();
  325. }
  326. elseif(is_singular('post') && !is_attachment()) {
  327. $cat = get_the_category(); $cat = $cat[0];
  328. echo " &rsaquo; ";
  329. if(get_the_category()) {
  330. $cat = get_the_category(); $cat = $cat[0];
  331. echo get_category_parents($cat, TRUE, ' &rsaquo; ');
  332. }
  333. echo the_title_limit(30);
  334. }
  335. elseif (is_search()) {
  336. echo " &rsaquo; ";
  337. _e('Search', 'gp_lang');
  338. }
  339. elseif (is_page() && $post->post_parent) {
  340. echo ' &rsaquo; <a href="'.get_permalink($post->post_parent).'">';
  341. echo get_the_title($post->post_parent);
  342. echo "</a> &rsaquo; ";
  343. echo the_title_limit(30);
  344. }
  345. elseif (is_page() OR is_attachment()) {
  346. echo " &rsaquo; ";
  347. echo the_title_limit(30);
  348. }
  349. elseif (is_author()) {
  350. echo wp_title(' &rsaquo; ', true, 'left');
  351. echo "'s ".__('Posts', 'gp_lang');
  352. }
  353. elseif (is_404()) {
  354. echo " &rsaquo; ";
  355. _e('Page Not Found', 'gp_lang');;
  356. }
  357. elseif (is_archive()) {
  358. echo wp_title(' &rsaquo; ', true, 'left');
  359. }
  360. }
  361. }
  362.  
  363.  
  364. /*************************** Page Navigation ***************************/
  365.  
  366. function gp_pagination($pages = '', $range = 2)
  367. {
  368. $showitems = ($range * 2)+1;
  369.  
  370. global $paged;
  371.  
  372. if (get_query_var('paged')) {
  373. $paged = get_query_var('paged');
  374. } elseif (get_query_var('page')) {
  375. $paged = get_query_var('page');
  376. } else {
  377. $paged = 1;
  378. }
  379.  
  380. if($pages == '')
  381. {
  382. global $wp_query;
  383. $pages = $wp_query->max_num_pages;
  384. if(!$pages)
  385. {
  386. $pages = 1;
  387. }
  388. }
  389.  
  390. if(1 != $pages)
  391. {
  392. echo "<div class='clear'></div><div class='wp-pagenavi cat-navi'>";
  393. echo '<span class="pages">'.__('Page', 'gp_lang').' '.$paged.' '.__('of', 'gp_lang').' '.$pages.'</span>';
  394. if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
  395. if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";
  396.  
  397. for ($i=1; $i <= $pages; $i++)
  398. {
  399. if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
  400. {
  401. echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
  402. }
  403. }
  404.  
  405. if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>";
  406. if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
  407. echo "</div>\n";
  408. }
  409. }
  410.  
  411.  
  412. /*************************** Shorten Titles ***************************/
  413.  
  414. function the_title_limit($length, $replacer = '...') {
  415. $string = the_title('','',FALSE);
  416. if(strlen($string) > $length)
  417. $string = (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer;
  418. echo $string;
  419. }
  420.  
  421.  
  422. /*************************** Shortcode Empty Paragraph Fix ***************************/
  423.  
  424. // Plugin URI: http://www.johannheyne.de/wordpress/shortcode-empty-paragraph-fix/
  425. add_filter('the_content', 'shortcode_empty_paragraph_fix');
  426. function shortcode_empty_paragraph_fix($content)
  427. {
  428. $array = array (
  429. '<p>[' => '[',
  430. ']</p>' => ']',
  431. ']<br />' => ']'
  432. );
  433.  
  434. $content = strtr($content, $array);
  435.  
  436. return $content;
  437. }
  438.  
  439.  
  440. /*************************** Password Protected Form ***************************/
  441.  
  442. add_filter('the_password_form', 'custom_password_form');
  443. function custom_password_form() {
  444. global $post;
  445. $label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
  446. $form = '<form class="protected-post-form" action="' . get_option('siteurl') . '/wp-pass.php" method="post">
  447. ' .__('This page is password protected. Enter the password below to view this page.', 'gp_lang'). '<br/><input name="post_password" id="' . $label . '" type="password" size="20" /><input type="submit" name="Submit" value="' . esc_attr__('Submit', 'gp_lang') . '" />
  448. </form>';
  449. return $form;
  450. }
  451.  
  452.  
  453. /*************************** Custom Media Gallery Field ***************************/
  454.  
  455. function ghostpool_attachment_fields_to_edit($form_fields, $post) {
  456. $form_fields["ghostpool_video_url"] = array(
  457. "label" => __('Audio/Video URL', 'gp_lang'),
  458. "input" => "text",
  459. "value" => get_post_meta($post->ID, "_ghostpool_video_url", true),
  460. "helps" => __('The URL of your video or audio file (YouTube/Vimeo/FLV/MP4/M4V/MP3).', 'gp_lang'),
  461. );
  462. return $form_fields;
  463. }
  464. add_filter("attachment_fields_to_edit", "ghostpool_attachment_fields_to_edit", null, 2);
  465.  
  466. function ghostpool_attachment_fields_to_save($post, $attachment) {
  467. if(isset($attachment['ghostpool_video_url'])){
  468. update_post_meta($post['ID'], '_ghostpool_video_url', $attachment['ghostpool_video_url']);
  469. }
  470. return $post;
  471. }
  472. add_filter("attachment_fields_to_save", "ghostpool_attachment_fields_to_save", null , 2);
  473.  
  474.  
  475. /*************************** Redirect to Theme Options after Activation ***************************/
  476.  
  477. if(is_admin() && isset($_GET['activated']) && $pagenow == "themes.php") {
  478. add_action('admin_head','ct_option_setup');
  479. header('Location: '.admin_url().'themes.php?page=theme-options.php');
  480. }
  481.  
  482. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement