Advertisement
Guest User

Goddardfunctions.php

a guest
Sep 22nd, 2011
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 91.57 KB | None | 0 0
  1. <?php
  2. /**
  3. * Graphene functions and definitions
  4. *
  5. * Sets up the theme and provides some helper functions. Some helper functions
  6. * are used in the theme as custom template tags. Others are attached to action and
  7. * filter hooks in WordPress to change core functionality.
  8. *
  9. * The first function, graphene_setup(), sets up the theme by registering support
  10. * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
  11. *
  12. * When using a child theme (see http://codex.wordpress.org/Theme_Development and
  13. * http://codex.wordpress.org/Child_Themes), you can override certain functions
  14. * (those wrapped in a function_exists() call) by defining them first in your child theme's
  15. * functions.php file. The child theme's functions.php file is included before the parent
  16. * theme's file, so the child theme functions would be used.
  17. *
  18. * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
  19. * to a filter or action hook. The hook can be removed by using remove_action() or
  20. * remove_filter() and you can attach your own function to the hook.
  21. *
  22. * We can remove the parent theme's hook only after it is attached, which means we need to
  23. * wait until setting up the child theme:
  24. *
  25. * <code>
  26. * add_action( 'after_setup_theme', 'my_child_theme_setup' );
  27. * function my_child_theme_setup() {
  28. *
  29. * remove_filter('filter_hook', 'callback_function' );
  30. * ...
  31. * }
  32. * </code>
  33. *
  34. * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
  35. *
  36. * @package WordPress
  37. * @subpackage Graphene
  38. * @since Graphene 1.0
  39. */
  40.  
  41.  
  42. /**
  43. * Before we do anything, let's get the mobile extension's init file if it exists
  44. */
  45. $mobile_path = dirname( dirname( __FILE__ ) ) . '/graphene-mobile/includes/theme-plugin.php';
  46. if ( file_exists($mobile_path) ) { include( $mobile_path ); }
  47.  
  48. /**
  49. * Retrieve the theme's user settings and default settings. Individual files can access
  50. * these setting via a global variable call, so database query is only
  51. * done once.
  52. */
  53. require_once( 'admin/options-defaults.php' );
  54. function graphene_get_settings(){
  55. global $graphene_defaults;
  56. $graphene_settings = array_merge( $graphene_defaults, (array) get_option( 'graphene_settings', array() ) );
  57. return apply_filters( 'graphene_settings', $graphene_settings );
  58. }
  59. global $graphene_settings;
  60. $graphene_settings = graphene_get_settings();
  61.  
  62.  
  63. /**
  64. * If there is no theme settings in the database yet (e.g. first install), add the database entry.
  65. */
  66. if (!function_exists('graphene_db_init')) :
  67. function graphene_db_init(){
  68. global $graphene_settings, $graphene_defaults;
  69.  
  70. /* Run DB updater if $graphene_settings does not exist in db */
  71. if (get_option('graphene_ga_code') === ''){
  72.  
  73. // Updates the database for much older version, when Settings API was not yet implemented
  74. include('admin/db-updater.php');
  75. graphene_update_db();
  76. $graphene_settings = array_merge($graphene_defaults, get_option('graphene_settings', array()));
  77.  
  78. }
  79.  
  80. /* Delete DB Version from the database. This value is now included in the $graphene_defaults array */
  81. delete_option('graphene_dbversion');
  82. }
  83. endif;
  84. add_action('init', 'graphene_db_init');
  85.  
  86.  
  87. /**
  88. * Set the content width based on the theme's design and stylesheet.
  89. *
  90. * Used to set the width of images and content. Should be equal to the width the theme
  91. * is designed for, generally via the style.css stylesheet.
  92. */
  93. if (!isset($content_width)){
  94. $column_mode = graphene_column_mode();
  95. if (strpos($graphene_settings['post_date_display'], 'icon') === 0){
  96. if (strpos($column_mode, 'two-col') === 0){
  97. $content_width = apply_filters('graphene_content_width_two_columns', 590);
  98. } else if (strpos($column_mode, 'three-col-center') === 0) {
  99. $content_width = apply_filters('graphene_content_width_three_columns_center', 360);
  100. } else if (strpos($column_mode, 'three-col') === 0){
  101. $content_width = apply_filters('graphene_content_width_three_columns', 375);
  102. } else {
  103. $content_width = apply_filters('graphene_content_width_one_columns', 875);
  104. }
  105. } else {
  106. if (strpos($column_mode, 'two-col') === 0){
  107. $content_width = apply_filters('graphene_content_width_two_columns_nodate', 645);
  108. } else if (strpos($column_mode, 'three-col-center') === 0) {
  109. $content_width = apply_filters('graphene_content_width_three_columns_center_nodate', 415);
  110. } else if (strpos($column_mode, 'three-col') === 0){
  111. $content_width = apply_filters('graphene_content_width_three_columns_nodate', 430);
  112. } else {
  113. $content_width = apply_filters('graphene_content_width_one_columns_nodate', 930);
  114. }
  115. }
  116. }
  117.  
  118.  
  119. /** Tell WordPress to run graphene_setup() when the 'after_setup_theme' hook is run. */
  120. add_action('after_setup_theme', 'graphene_setup' );
  121.  
  122. if (!function_exists( 'graphene_setup')):
  123. /**
  124. * Sets up theme defaults and registers support for various WordPress features.
  125. *
  126. * Note that this function is hooked into the after_setup_theme hook, which runs
  127. * before the init hook. The init hook is too late for some features, such as indicating
  128. * support post thumbnails.
  129. *
  130. * To override graphene_setup() in a child theme, add your own graphene_setup to your child theme's
  131. * functions.php file.
  132. *
  133. * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
  134. * @uses register_nav_menus() To add support for navigation menus.
  135. * @uses add_custom_background() To add support for a custom background.
  136. * @uses load_theme_textdomain() For translation/localization support.
  137. * @uses add_custom_image_header() To add support for a custom header.
  138. * @uses register_default_headers() To register the default custom header images provided with the theme.
  139. * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  140. *
  141. * @since Graphene 1.0
  142. */
  143. function graphene_setup() {
  144. global $graphene_settings;
  145.  
  146. // Add custom image sizes selectively
  147. if ($graphene_settings['slider_display_style'] == 'bgimage-excerpt') {
  148. $height = ($graphene_settings['slider_height']) ? $graphene_settings['slider_height'] : 240;
  149. add_image_size('graphene_slider', apply_filters('graphene_slider_image_width', 660), $height, true);
  150. add_image_size('graphene_slider_full', apply_filters('graphene_slider_full_image_width', 930), $height, true);
  151. add_image_size('graphene_slider_small', apply_filters('graphene_slider_small_image_width', 445), $height, true);
  152. }
  153. if (get_option('show_on_front') == 'page' && !$graphene_settings['disable_homepage_panes']) {
  154. add_image_size('graphene-homepage-pane', apply_filters('graphene_homepage_pane_image_width', 451), apply_filters('graphene_homepage_pane_image_height', 250), true);
  155. }
  156.  
  157. // Add support for editor syling
  158. add_editor_style();
  159.  
  160. // Add default posts and comments RSS feed links to head
  161. add_theme_support( 'automatic-feed-links' );
  162.  
  163. // This theme uses post thumbnails
  164. add_theme_support( 'post-thumbnails' );
  165.  
  166. // Add supported post formats
  167. add_theme_support('post-formats', array('status', 'audio', 'image', 'video'));
  168.  
  169. // Make theme available for translation
  170. // Translations can be filed in the /languages/ directory
  171. load_theme_textdomain( 'graphene', get_template_directory().'/languages' );
  172.  
  173. // This theme uses wp_nav_menu() in three locations.
  174. register_nav_menus( array(
  175. 'Header Menu' => __('Header Menu', 'graphene'),
  176. 'secondary-menu' => __('Secondary Menu', 'graphene'),
  177. 'footer-menu' => __('Footer Menu', 'graphene'),
  178. ) );
  179.  
  180. // This theme allows users to set a custom background
  181. add_custom_background();
  182.  
  183. // Your changeable header business starts here
  184. define('HEADER_TEXTCOLOR', apply_filters('graphene_header_textcolor', '000000'));
  185. // No CSS, just IMG call. The %s is a placeholder for the theme template directory URI.
  186. define('HEADER_IMAGE', apply_filters('graphene_header_image', '%s/images/headers/flow.jpg'));
  187.  
  188. // The height and width of your custom header. You can hook into the theme's own filters to change these values.
  189. // Add a filter to graphene_header_image_width and graphene_header_image_height to change these values.
  190. define('HEADER_IMAGE_WIDTH', apply_filters('graphene_header_image_width', 960));
  191. define('HEADER_IMAGE_HEIGHT', apply_filters('graphene_header_image_height', 198));
  192.  
  193. // We'll be using post thumbnails for custom header images on posts and pages.
  194. // We want them to be 960 pixels wide by 198 pixels tall.
  195. // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
  196. set_post_thumbnail_size(HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true);
  197.  
  198. // Don't support text inside the header image.
  199. define('NO_HEADER_TEXT', apply_filters('graphene_header_text', false));
  200.  
  201. // Add a way for the custom header to be styled in the admin panel that controls
  202. // custom headers. See graphene_admin_header_style(), below.
  203. add_custom_image_header('', 'graphene_admin_header_style');
  204.  
  205. // ... and thus ends the changeable header business.
  206.  
  207. // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
  208. register_default_headers( graphene_get_default_headers() );
  209.  
  210. do_action('graphene_setup');
  211. }
  212. endif;
  213.  
  214. if (!function_exists('graphene_get_default_headers')) {
  215. function graphene_get_default_headers() {
  216. return array(
  217. 'Schematic' => array(
  218. 'url' => '%s/images/headers/schematic.jpg',
  219. 'thumbnail_url' => '%s/images/headers/schematic-thumb.jpg',
  220. /* translators: header image description */
  221. 'description' => __('Header image by Syahir Hakim', 'graphene')
  222. ),
  223. 'Flow' => array(
  224. 'url' => '%s/images/headers/flow.jpg',
  225. 'thumbnail_url' => '%s/images/headers/flow-thumb.jpg',
  226. /* translators: header image description */
  227. 'description' => __('This is the default Graphene theme header image, cropped from image by Quantin Houyoux at sxc.hu', 'graphene')
  228. ),
  229. 'Fluid' => array(
  230. 'url' => '%s/images/headers/fluid.jpg',
  231. 'thumbnail_url' => '%s/images/headers/fluid-thumb.jpg',
  232. /* translators: header image description */
  233. 'description' => __('Header image cropped from image by Ilco at sxc.hu', 'graphene')
  234. ),
  235. 'Techno' => array(
  236. 'url' => '%s/images/headers/techno.jpg',
  237. 'thumbnail_url' => '%s/images/headers/techno-thumb.jpg',
  238. /* translators: header image description */
  239. 'description' => __('Header image cropped from image by Ilco at sxc.hu', 'graphene')
  240. ),
  241. 'Fireworks' => array(
  242. 'url' => '%s/images/headers/fireworks.jpg',
  243. 'thumbnail_url' => '%s/images/headers/fireworks-thumb.jpg',
  244. /* translators: header image description */
  245. 'description' => __('Header image cropped from image by Ilco at sxc.hu', 'graphene')
  246. ),
  247. 'Nebula' => array(
  248. 'url' => '%s/images/headers/nebula.jpg',
  249. 'thumbnail_url' => '%s/images/headers/nebula-thumb.jpg',
  250. /* translators: header image description */
  251. 'description' => __('Header image cropped from image by Ilco at sxc.hu', 'graphene')
  252. ),
  253. 'Sparkle' => array(
  254. 'url' => '%s/images/headers/sparkle.jpg',
  255. 'thumbnail_url' => '%s/images/headers/sparkle-thumb.jpg',
  256. /* translators: header image description */
  257. 'description' => __('Header image cropped from image by Ilco at sxc.hu', 'graphene')
  258. ),
  259. );
  260. }
  261. }
  262.  
  263.  
  264. /**
  265. * Register and print the main theme stylesheet
  266. */
  267. function graphene_main_stylesheet(){
  268. wp_register_style('graphene-stylesheet', get_stylesheet_uri(), array(), false, 'screen');
  269. wp_enqueue_style('graphene-stylesheet');
  270. }
  271. add_action('wp_print_styles', 'graphene_main_stylesheet');
  272.  
  273.  
  274. if (!function_exists('graphene_admin_header_style')) :
  275. /**
  276. * Styles the header image displayed on the Appearance > Header admin panel.
  277. *
  278. * Referenced via add_custom_image_header() in graphene_setup().
  279. *
  280. * @since graphene 1.0
  281. */
  282. function graphene_admin_header_style(){ ?>
  283. <style type="text/css">
  284. #headimg #name{
  285. position:relative;
  286. top:65px;
  287. left:38px;
  288. width:852px;
  289. font:bold 28px "Trebuchet MS";
  290. text-decoration:none;
  291. }
  292. #headimg #desc{
  293. color:#000;
  294. border-bottom:none;
  295. position:relative;
  296. top:50px;
  297. width:852px;
  298. left:38px;
  299. font:18px arial;
  300. }
  301. </style>
  302.  
  303. <?php
  304. do_action('graphene_admin_header_style');
  305. }
  306. endif;
  307.  
  308.  
  309. /**
  310. * Registers custom scripts that the theme uses
  311. */
  312. function graphene_register_scripts(){
  313. wp_register_script('graphene-jquery-tools', 'http://cdn.jquerytools.org/1.2.5/all/jquery.tools.min.js', array('jquery'), '', true);
  314. }
  315. add_action('init', 'graphene_register_scripts');
  316.  
  317. /**
  318. * Enqueues the custom scripts that the theme uses
  319. */
  320. function graphene_enqueue_scripts(){
  321. if ( ! is_admin() ) { // Front-end only
  322. wp_enqueue_script( 'graphene-jquery-tools' ); // jQuery Tools, required for slider and comments/pingbacks tabs
  323. }
  324. }
  325. add_action('init', 'graphene_enqueue_scripts');
  326.  
  327.  
  328. /**
  329. * Sets the various customised styling according to the options set for the theme
  330. *
  331. * @package WordPress
  332. * @subpackage Graphene
  333. * @since Graphene 1.0.8
  334. */
  335. function graphene_custom_style(){
  336. global $graphene_settings, $graphene_defaults, $content_width;
  337.  
  338. $background = get_theme_mod('background_image', false);
  339. $bgcolor = get_theme_mod('background_color', false);
  340. $widgetcolumn = (is_front_page() && $graphene_settings['alt_home_footerwidget']) ? $graphene_settings['alt_footerwidget_column'] : $graphene_settings['footerwidget_column'];
  341. ?>
  342. <style type="text/css">
  343. <?php /* Disable default background if a custom background colour is defined */ ?>
  344. <?php if (!$background && $bgcolor) : ?>
  345. body{background-image:none;}
  346. <?php endif; ?>
  347.  
  348. <?php /* Set the width of the bottom widget items if number of columns is specified */ ?>
  349. <?php if ($widgetcolumn) : $widget_width = floor((apply_filters('graphene_container_width', 960) - (15+25+2)*$widgetcolumn)/$widgetcolumn); ?>
  350. #sidebar_bottom .sidebar-wrap{width:<?php echo $widget_width; ?>px;}
  351. <?php endif; ?>
  352.  
  353. <?php /* Set the width of the nav menu dropdown menu item width if specified */ ?>
  354. <?php if ($graphene_settings['navmenu_child_width']) : $nav_width = $graphene_settings['navmenu_child_width']; ?>
  355. #nav li ul{width: <?php echo $nav_width; ?>px}
  356. <?php if (!is_rtl()) : ?>
  357. #nav li ul ul{margin-left: <?php echo $nav_width; ?>px}
  358.  
  359. #header-menu ul li.menu-item-ancestor > a {
  360. background-position: <?php echo -652-(200-$nav_width); ?>px -194px;
  361. width: <?php echo $nav_width-35; ?>px;
  362. }
  363. #header-menu ul li.menu-item-ancestor:hover > a,
  364. #header-menu ul li.current-menu-item > a,
  365. #header-menu ul li.current-menu-ancestor > a {
  366. background-position: <?php echo -652-(200-$nav_width); ?>px -238px;
  367. }
  368. #secondary-menu ul li.menu-item-ancestor > a {
  369. background-position: <?php echo -652-(200-$nav_width); ?>px -286px;
  370. width: <?php echo $nav_width-35; ?>px;
  371. }
  372. #secondary-menu ul li.menu-item-ancestor:hover > a,
  373. #secondary-menu ul li.current-menu-item > a,
  374. #secondary-menu ul li.current-menu-ancestor > a {
  375. background-position: <?php echo -652-(200-$nav_width); ?>px -319px;
  376. }
  377.  
  378. <?php else : ?>
  379. #nav li ul ul{margin-right: <?php echo $nav_width; ?>px; margin-left: 0;}
  380.  
  381. #header-menu ul li.menu-item-ancestor > a,
  382. #secondary-menu ul li.menu-item-ancestor > a {
  383. width: <?php echo $nav_width-35; ?>px;
  384. }
  385.  
  386. <?php endif; ?>
  387.  
  388. #header-menu ul li a{width: <?php echo $nav_width-20; ?>px}
  389. #secondary-menu ul li a{width: <?php echo $nav_width-30; ?>px}
  390.  
  391. <?php endif; ?>
  392.  
  393. <?php /* Header title text style */
  394. $font_style = '';
  395. $font_style .= ($graphene_settings['header_title_font_type']) ? 'font-family:'.$graphene_settings['header_title_font_type'].';' : '';
  396. $font_style .= ($graphene_settings['header_title_font_lineheight']) ? 'line-height:'.$graphene_settings['header_title_font_lineheight'].';' : '';
  397. $font_style .= ($graphene_settings['header_title_font_size']) ? 'font-size:'.$graphene_settings['header_title_font_size'].';' : '';
  398. $font_style .= ($graphene_settings['header_title_font_weight']) ? 'font-weight:'.$graphene_settings['header_title_font_weight'].';' : '';
  399. $font_style .= ($graphene_settings['header_title_font_style']) ? 'font-style:'.$graphene_settings['header_title_font_style'].';' : '';
  400.  
  401. if ($font_style) :
  402. ?>
  403. .header_title{<?php echo $font_style; ?>}
  404. <?php endif; ?>
  405.  
  406. <?php /* Header description text style */
  407. $font_style = '';
  408. $font_style .= ($graphene_settings['header_desc_font_type']) ? 'font-family:'.$graphene_settings['header_desc_font_type'].';' : '';
  409. $font_style .= ($graphene_settings['header_desc_font_size']) ? 'font-size:'.$graphene_settings['header_desc_font_size'].';' : '';
  410. $font_style .= ($graphene_settings['header_desc_font_lineheight']) ? 'line-height:'.$graphene_settings['header_desc_font_lineheight'].';' : '';
  411. $font_style .= ($graphene_settings['header_desc_font_weight']) ? 'font-weight:'.$graphene_settings['header_desc_font_weight'].';' : '';
  412. $font_style .= ($graphene_settings['header_desc_font_style']) ? 'font-style:'.$graphene_settings['header_desc_font_style'].';' : '';
  413.  
  414. if ($font_style) :
  415. ?>
  416. .header_desc{<?php echo $font_style; ?>}
  417. <?php endif; ?>
  418.  
  419. <?php /* Content text style */
  420. $font_style = '';
  421. $font_style .= ($graphene_settings['content_font_type']) ? 'font-family:'.$graphene_settings['content_font_type'].';' : '';
  422. $font_style .= ($graphene_settings['content_font_size']) ? 'font-size:'.$graphene_settings['content_font_size'].';' : '';
  423. $font_style .= ($graphene_settings['content_font_lineheight']) ? 'line-height:'.$graphene_settings['content_font_lineheight'].';' : '';
  424. $font_style .= ($graphene_settings['content_font_colour'] != $graphene_defaults['content_font_colour']) ? 'color:'.$graphene_settings['content_font_colour'].';' : '';
  425.  
  426. if ($font_style) :
  427. ?>
  428. .entry-content, .sidebar, .comment-entry{<?php echo $font_style; ?>}
  429. <?php endif; ?>
  430.  
  431. <?php /* Adjust post title if author's avatar is shown */ ?>
  432. <?php if ($graphene_settings['show_post_avatar']) : if (!is_rtl()) : ?>
  433. .post-title a, .post-title a:visited{display:block;margin-right:45px;padding-bottom:0;}
  434. <?php else : ?>
  435. .post-title a, .post-title a:visited{display:block;margin-left:45px;padding-bottom:0;}
  436. <?php endif; endif; ?>
  437.  
  438. <?php /* Slider height */ ?>
  439. <?php if ($graphene_settings['slider_height']) : ?>
  440. .featured_slider #slider_root{height:<?php echo $graphene_settings['slider_height']; ?>px;}
  441. <?php endif; ?>
  442.  
  443. <?php /* Link header image */ ?>
  444. <?php if ($graphene_settings['link_header_img'] && (HEADER_IMAGE_WIDTH != 900 || HEADER_IMAGE_HEIGHT != 198)) : ?>
  445. #header_img_link{width:<?php echo HEADER_IMAGE_WIDTH; ?>px;height:<?php echo HEADER_IMAGE_HEIGHT; ?>px;}
  446. <?php endif;?>
  447.  
  448. <?php // Link style
  449. if ($graphene_settings['link_colour_normal'] != $graphene_defaults['link_colour_normal']) {echo 'a{color:'.$graphene_settings['link_colour_normal'].';}';}
  450. if ($graphene_settings['link_colour_visited'] != $graphene_defaults['link_colour_visited']) {echo 'a:visited{color:'.$graphene_settings['link_colour_visited'].';}';}
  451. if ($graphene_settings['link_colour_hover'] != $graphene_defaults['link_colour_hover']) {echo 'a:hover{color:'.$graphene_settings['link_colour_hover'].';}';}
  452. if ($graphene_settings['link_decoration_normal']) {echo 'a{text-decoration:'.$graphene_settings['link_decoration_normal'].';}';}
  453. if ($graphene_settings['link_decoration_hover']) {echo 'a:hover{text-decoration:'.$graphene_settings['link_decoration_hover'].';}';}
  454. ?>
  455.  
  456. <?php /* Custom css */ ?>
  457. <?php if ($graphene_settings['custom_css']) {echo $graphene_settings['custom_css'];} ?>
  458.  
  459. <?php do_action('graphene_custom_style'); ?>
  460. </style>
  461.  
  462. <?php
  463. }
  464. add_action('wp_head', 'graphene_custom_style');
  465.  
  466. /**
  467. * Sets the customised colour options. This <style> block will be added both to the front end as well as the theme's
  468. * display options page.
  469. */
  470. function graphene_custom_colours(){
  471.  
  472. if ( ! is_admin() || strstr( $_SERVER["REQUEST_URI"], 'page=graphene_options&tab=display' ) ) {
  473.  
  474. global $graphene_settings, $graphene_defaults;
  475.  
  476. /* Customised colours */
  477. $style = '';
  478. // Content area
  479. if ($graphene_settings['bg_content_wrapper'] != $graphene_defaults['bg_content_wrapper']) {$style .= '#content, .menu-bottom-shadow{background-color:'.$graphene_settings['bg_content_wrapper'].';}';}
  480. if ($graphene_settings['bg_content'] != $graphene_defaults['bg_content']) {$style .= '.post{background-color:'.$graphene_settings['bg_content'].';}';}
  481. if ($graphene_settings['bg_meta_border'] != $graphene_defaults['bg_meta_border']) {$style .= '.post-title, .post-title a, .post-title a:visited, .entry-footer{border-color:'.$graphene_settings['bg_meta_border'].';}';}
  482. if ($graphene_settings['bg_post_top_border'] != $graphene_defaults['bg_post_top_border']) {$style .= '.post{border-top-color:'.$graphene_settings['bg_post_top_border'].';}';}
  483. if ($graphene_settings['bg_post_bottom_border'] != $graphene_defaults['bg_post_bottom_border']) {$style .= '.post{border-bottom-color:'.$graphene_settings['bg_post_bottom_border'].';}';}
  484. if ($graphene_settings['bg_post_bottom_border'] != $graphene_defaults['bg_post_bottom_border']) {$style .= '.post{border-bottom-color:'.$graphene_settings['bg_post_bottom_border'].';}';}
  485.  
  486. // Widgets
  487. if ($graphene_settings['bg_widget_item'] != $graphene_defaults['bg_widget_item']) {$style .= '.sidebar div.sidebar-wrap{background-color:'.$graphene_settings['bg_widget_item'].';}';}
  488. if ($graphene_settings['bg_widget_list'] != $graphene_defaults['bg_widget_list']) {$style .= '.sidebar ul li{border-color:'.$graphene_settings['bg_widget_list'].';}';}
  489. if ($graphene_settings['bg_widget_header_border'] != $graphene_defaults['bg_widget_header_border']) {$style .= '.sidebar h3{border-color:'.$graphene_settings['bg_widget_header_border'].';}';}
  490. if ($graphene_settings['bg_widget_title'] != $graphene_defaults['bg_widget_title']) {$style .= '.sidebar h3, .sidebar h3 a, .sidebar h3 a:visited{color:'.$graphene_settings['bg_widget_title'].';}';}
  491. if ($graphene_settings['bg_widget_title_textshadow'] != $graphene_defaults['bg_widget_title_textshadow']) {$style .= '.sidebar h3{text-shadow: 0 -1px '.$graphene_settings['bg_widget_title_textshadow'].';}';}
  492. $grad_top = $graphene_settings['bg_widget_header_top'];
  493. $grad_bottom = $graphene_settings['bg_widget_header_bottom'];
  494. if ($grad_bottom != $graphene_defaults['bg_widget_header_bottom'] || $grad_top != $graphene_defaults['bg_widget_header_top']) {$style .= '.sidebar h3{
  495. background: ' . $grad_top . ';
  496. background: -moz-linear-gradient(' . $grad_top . ', ' . $grad_bottom . ');
  497. background: -webkit-linear-gradient(top, ' . $grad_top . ', ' . $grad_bottom . ');
  498. background: linear-gradient(' . $grad_top . ', ' . $grad_bottom . ');
  499. }';}
  500.  
  501. // Slider
  502. $grad_top = $graphene_settings['bg_slider_top'];
  503. $grad_bottom = $graphene_settings['bg_slider_bottom'];
  504. if ($grad_bottom != $graphene_defaults['bg_slider_bottom'] || $grad_top != $graphene_defaults['bg_slider_top']) {$style .= '.featured_slider {
  505. -pie-background: linear-gradient(left top, ' . $grad_top . ', ' . $grad_bottom . ');
  506. background: ' . $grad_top . ';
  507. background: -moz-linear-gradient(left top, ' . $grad_top . ', ' . $grad_bottom . ');
  508. background: -webkit-linear-gradient(left top, ' . $grad_top . ', ' . $grad_bottom . ');
  509. background: linear-gradient(left top, ' . $grad_top . ', ' . $grad_bottom . ');
  510. }';}
  511.  
  512. // Block button
  513. $grad_top = $graphene_settings['bg_button'];
  514. $grad_bottom = graphene_hex_addition($grad_top, -26);
  515. $grad_bottom_hover = graphene_hex_addition($grad_top, -52);
  516. $font_color = $graphene_settings['bg_button_label'];
  517. $font_shadow = $graphene_settings['bg_button_label_textshadow'];
  518. if ($grad_top != $graphene_defaults['bg_button']) {
  519. $style .= '.block-button, .block-button:visited, .Button {
  520. background: ' . $grad_top . ';
  521. background: -moz-linear-gradient(' . $grad_top . ', ' . $grad_bottom . ');
  522. background: -webkit-linear-gradient(top, ' . $grad_top . ', ' . $grad_bottom . ');
  523. background: linear-gradient(' . $grad_top . ', ' . $grad_bottom . ');
  524. border-color: ' . $grad_bottom . ';
  525. text-shadow: 0 -1px 1px ' . $font_shadow . ';
  526. color: ' . $font_color . ';
  527. }';
  528. $style .= '.block-button:hover {
  529. background: ' . $grad_top . ';
  530. background: -moz-linear-gradient(' . $grad_top . ', ' . $grad_bottom_hover . ');
  531. background: -webkit-linear-gradient(top, ' . $grad_top . ', ' . $grad_bottom_hover . ');
  532. background: linear-gradient(' . $grad_top . ', ' . $grad_bottom_hover . ');
  533. color: ' . $font_color . ';
  534. }';
  535. }
  536.  
  537. if ($style) { echo '<style type="text/css">'.$style.'</style>'; }
  538. }
  539.  
  540. // Admin only
  541. if ( is_admin() && strstr( $_SERVER["REQUEST_URI"], 'page=graphene_options&tab=display' ) ) {
  542.  
  543. // Widgets
  544. $style = '';
  545. if ($graphene_settings['content_font_colour'] != $graphene_defaults['content_font_colour']) {$style .= '.graphene, .graphene li, .graphene p{color:'.$graphene_settings['content_font_colour'].';}';}
  546. if ($graphene_settings['link_colour_normal'] != $graphene_defaults['link_colour_normal']) {$style .= '.graphene a{color:'.$graphene_settings['link_colour_normal'].';}';}
  547. if ($graphene_settings['link_colour_visited'] != $graphene_defaults['link_colour_visited']) {$style .= '.graphene a:visited{color:'.$graphene_settings['link_colour_visited'].';}';}
  548. if ($graphene_settings['link_colour_hover'] != $graphene_defaults['link_colour_hover']) {$style .= '.graphene a:hover{color:'.$graphene_settings['link_colour_hover'].';}';}
  549.  
  550. // Slider
  551. $grad_bottom = $graphene_settings['bg_slider_bottom'];
  552. $grad_top = $graphene_settings['bg_slider_top'];
  553. if ($grad_bottom != $graphene_defaults['bg_slider_bottom'] || $grad_top != $graphene_defaults['bg_slider_top']) {$style .= '#grad-box {
  554. -pie-background: linear-gradient(left top, ' . $grad_top . ', ' . $grad_bottom . ');
  555. background: ' . $grad_top . ';
  556. background: linear-gradient(left top, ' . $grad_top . ', ' . $grad_bottom . ');
  557. background: -moz-linear-gradient(left top, ' . $grad_top . ', ' . $grad_bottom . ');
  558. background: -webkit-gradient(linear, left top, right bottom, from(' . $grad_top . '), to(' . $grad_bottom . '));
  559. }';}
  560.  
  561. if ($style) { echo '<style type="text/css">'.$style.'</style>'; }
  562. }
  563. }
  564. add_action('wp_head', 'graphene_custom_colours');
  565. add_action('admin_head', 'graphene_custom_colours');
  566.  
  567.  
  568. /**
  569. * Convert a hex decimal color code to its RGB equivalent and vice versa
  570. */
  571. function graphene_rgb2hex($c){
  572. if(!$c) return false;
  573. $c = trim($c);
  574. $out = false;
  575. if(preg_match("/^[0-9ABCDEFabcdef\#]+$/i", $c)){
  576. $c = str_replace('#','', $c);
  577. $l = strlen($c) == 3 ? 1 : (strlen($c) == 6 ? 2 : false);
  578.  
  579. if($l){
  580. unset($out);
  581. $out['red'] = hexdec(substr($c, 0,1*$l));
  582. $out['green'] = hexdec(substr($c, 1*$l,1*$l));
  583. $out['blue'] = hexdec(substr($c, 2*$l,1*$l));
  584. }else $out = false;
  585.  
  586. }elseif (preg_match("/^[0-9]+(,| |.)+[0-9]+(,| |.)+[0-9]+$/i", $c)){
  587. $spr = str_replace(array(',',' ','.'), ':', $c);
  588. $e = explode(":", $spr);
  589. if(count($e) != 3) return false;
  590. $out = '#';
  591. for($i = 0; $i<3; $i++)
  592. $e[$i] = dechex(($e[$i] <= 0)?0:(($e[$i] >= 255)?255:$e[$i]));
  593.  
  594. for($i = 0; $i<3; $i++)
  595. $out .= ((strlen($e[$i]) < 2)?'0':'').$e[$i];
  596.  
  597. $out = strtoupper($out);
  598. }else $out = false;
  599.  
  600. return $out;
  601. }
  602.  
  603.  
  604.  
  605. /**
  606. * Perform adding (or subtracting) operation on a hexadecimal colour code
  607. */
  608. function graphene_hex_addition($hex, $num){
  609. $rgb = graphene_rgb2hex($hex);
  610. foreach ($rgb as $key => $val) {
  611. $rgb[$key] += $num;
  612. $rgb[$key] = ($rgb[$key] < 0) ? 0 : $rgb[$key];
  613. }
  614. $hex = graphene_rgb2hex(implode(',', $rgb));
  615.  
  616. return $hex;
  617. }
  618.  
  619.  
  620. /**
  621. * Register and print the stylesheet for alternate lighter header, if enabled in the options
  622. *
  623. * @package WordPress
  624. * @subpackage Graphene
  625. * @since Graphene 1.0.8
  626. */
  627. if ($graphene_settings['light_header']) :
  628. function graphene_lightheader_style(){
  629. wp_register_style('graphene-light-header', get_template_directory_uri().'/style-light.css');
  630. wp_enqueue_style('graphene-light-header');
  631.  
  632. do_action('graphene_light_header');
  633. }
  634. add_action('wp_print_styles', 'graphene_lightheader_style');
  635. endif;
  636.  
  637.  
  638. /**
  639. * Check to see if there's a favicon.ico in wordpress root directory and add
  640. * appropriate head element for the favicon
  641. */
  642. function graphene_favicon(){
  643. global $graphene_settings;
  644. if ($graphene_settings['favicon_url']) { ?>
  645. <link rel="icon" href="<?php echo $graphene_settings['favicon_url']; ?>" type="image/x-icon" />
  646. <?php
  647. } elseif (is_file(ABSPATH.'favicon.ico')){ ?>
  648. <link rel="icon" href="<?php echo home_url(); ?>/favicon.ico" type="image/x-icon" />
  649. <?php }
  650. }
  651. add_action('wp_head', 'graphene_favicon');
  652.  
  653.  
  654.  
  655. /**
  656. * Defines the custom walker that adds description to the display of our Header Menu
  657. */
  658. class Graphene_Description_Walker extends Walker_Nav_Menu {
  659. function start_el(&$output, $item, $depth, $args) {
  660. global $wp_query;
  661.  
  662. $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  663.  
  664. $class_names = $value = '';
  665.  
  666. $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  667.  
  668. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
  669. $class_names = ' class="'. esc_attr( $class_names ) . '"';
  670.  
  671. $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
  672.  
  673. $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
  674. $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
  675. $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
  676. $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
  677.  
  678. $prepend = '<strong>';
  679. $append = '</strong>';
  680.  
  681. // Don't show description if it's longer than the length
  682. $desc_length = apply_filters( 'graphene_menu_desc_length', 50 );
  683.  
  684. if ( strlen( $item->description ) > $desc_length)
  685. $description = '';
  686. else
  687. $description = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';
  688.  
  689. if ( $depth != 0 ) {
  690. $description = $append = $prepend = "";
  691. }
  692.  
  693. $item_output = $args->before;
  694. $item_output .= '<a'. $attributes .'>';
  695. $item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
  696. $item_output .= $description.$args->link_after;
  697. $item_output .= '</a>';
  698. $item_output .= $args->after;
  699.  
  700. $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  701. }
  702. }
  703.  
  704.  
  705. /**
  706. * Define the callback menu, if there is no custom menu.
  707. * This menu automatically lists all Pages as menu items, including their direct
  708. * direct descendant, which will only be displayed for the current parent.
  709. */
  710. if (!function_exists('graphene_default_menu')) :
  711.  
  712. function graphene_default_menu(){ global $graphene_settings; ?>
  713.  
  714. <ul id="header-menu" class="menu clearfix default-menu">
  715. <?php if (get_option('show_on_front') == 'posts') : ?>
  716. <li <?php if ( is_single() || is_front_page()) { echo 'class="current_page_item current-menu-item"'; } ?>>
  717. <a href="<?php echo get_home_url(); ?>">
  718. <strong><?php _e('Home','graphene'); ?></strong>
  719. <?php if ($graphene_settings['navmenu_home_desc']) {echo '<span>'.$graphene_settings['navmenu_home_desc'].'</span>';} ?>
  720. </a>
  721. </li>
  722. <?php endif; ?>
  723. <?php
  724. $args = array(
  725. 'echo' => 1,
  726. 'sort_column' => 'menu_order, post_title',
  727. 'depth' => 5,
  728. 'title_li' => '',
  729. 'walker' => new Walker_PageDescription()
  730. );
  731. wp_list_pages(apply_filters('graphene_default_menu_args', $args));
  732. ?>
  733. </ul>
  734. <?php
  735. do_action('graphene_default_menu');
  736. }
  737.  
  738. endif;
  739.  
  740. class Walker_PageDescription extends Walker_Page {
  741.  
  742. /**
  743. * Code exact copied from: wp-includes\post-template.pgp >> Walker_Page::start_el()
  744. * @since 2.1.0
  745. */
  746. function start_el(&$output, $page, $depth, $args, $current_page) {
  747. if ( $depth )
  748. $indent = str_repeat("\t", $depth);
  749. else
  750. $indent = '';
  751. extract($args, EXTR_SKIP);
  752. $css_class = array('page_item', 'page-item-'.$page->ID);
  753. if ( !empty($current_page) ) {
  754. $_current_page = get_page( $current_page );
  755. _get_post_ancestors($_current_page);
  756. if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) ) {
  757. $css_class[] = 'current_page_ancestor';
  758. $css_class[] = 'current-menu-ancestor';
  759. }
  760. if ( $page->ID == $current_page ) {
  761. $css_class[] = 'current_page_item';
  762. $css_class[] = 'current-menu-item';
  763. }
  764. elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {
  765. $css_class[] = 'current_page_parent';
  766. $css_class[] = 'current-menu-ancestor';
  767. $css_class[] = 'current-menu-parent';
  768. }
  769. } elseif ( $page->ID == get_option('page_for_posts') ) {
  770. $css_class[] = 'current_page_parent';
  771. $css_class[] = 'current-menu-ancestor';
  772. $css_class[] = 'current-menu-parent';
  773. }
  774.  
  775. // Check if page has children
  776. if ( get_pages( array( 'child_of' => $page->ID, 'parent' => $page->ID ) ) ) {
  777. $css_class[] = 'menu-item-ancestor';
  778. }
  779.  
  780. $css_class = implode(' ', apply_filters('page_css_class', $css_class, $page));
  781.  
  782. $title = apply_filters( 'the_title', $page->post_title, $page->ID );
  783.  
  784. // get the graphene description if it is set otherwise the wordpress default -> title
  785. $menu_title = '<strong>'.apply_filters( 'the_title', $page->post_title, $page->ID ).'</strong>';
  786. $menu_title .= (get_post_meta($page->ID, '_graphene_nav_description', true) && !$depth) ?
  787. '<span>'.get_post_meta($page->ID, '_graphene_nav_description', true).'</span>' :
  788. '';
  789.  
  790. $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '" title="' . esc_attr( wp_strip_all_tags( $title ) ) . '">' . $link_before . $menu_title . $link_after . '</a>';
  791.  
  792. if ( !empty($show_date) ) {
  793. if ( 'modified' == $show_date )
  794. $time = $page->post_modified;
  795. else
  796. $time = $page->post_date;
  797.  
  798. $output .= " " . mysql2date($date_format, $time);
  799. }
  800. }
  801. }
  802.  
  803. /**
  804. * Defines the callback function for use with wp_list_comments(). This function controls
  805. * how comments are displayed.
  806. */
  807.  
  808. if (!function_exists('graphene_comment')) :
  809.  
  810. function graphene_comment($comment, $args, $depth) {
  811. $GLOBALS['comment'] = $comment; ?>
  812. <li id="comment-<?php comment_ID(); ?>" <?php comment_class('clearfix'); ?>>
  813. <?php do_action('graphene_before_comment'); ?>
  814.  
  815. <?php /* Added support for comment numbering using Greg's Threaded Comment Numbering plugin */ ?>
  816. <?php if (function_exists('gtcn_comment_numbering')) {gtcn_comment_numbering($comment->comment_ID, $args);} ?>
  817.  
  818. <?php echo get_avatar($comment, apply_filters('graphene_gravatar_size', 40)); ?>
  819. <?php do_action('graphene_comment_gravatar'); ?>
  820.  
  821. <div class="comment-wrap clearfix">
  822. <h5>
  823. <cite><?php comment_author_link(); ?></cite> <?php _e('says:','graphene'); ?>
  824. <?php do_action('graphene_comment_author'); ?>
  825. </h5>
  826. <div class="comment-meta">
  827. <p class="commentmetadata">
  828. <?php /* translators: %1$s is the comment date, %2$s is the comment time */ ?>
  829. <?php printf(__('%1$s at %2$s', 'graphene'), get_comment_date(), get_comment_time()); ?>
  830. <span class="timezone"><?php echo '(UTC '.get_option('gmt_offset').')'; ?></span>
  831. <?php edit_comment_link(__('Edit comment','graphene'),' | ',''); ?>
  832. <?php do_action('graphene_comment_metadata'); ?>
  833. </p>
  834. <p class="comment-reply-link">
  835. <?php comment_reply_link(array('depth' => $depth, 'max_depth' => $args['max_depth'], 'reply_text' => __('Reply', 'graphene'))); ?>
  836.  
  837. <?php do_action('graphene_comment_replylink'); ?>
  838. </p>
  839.  
  840. <?php do_action('graphene_comment_meta'); ?>
  841. </div>
  842. <div class="comment-entry">
  843. <?php do_action('graphene_before_commententry'); ?>
  844.  
  845. <?php if ($comment->comment_approved == '0') : ?>
  846. <p><em><?php _e('Your comment is awaiting moderation.', 'graphene') ?></em></p>
  847. <?php do_action('graphene_comment_moderation'); ?>
  848. <?php else : ?>
  849. <?php comment_text(); ?>
  850. <?php endif; ?>
  851.  
  852. <?php do_action('graphene_after_commententry'); ?>
  853. </div>
  854. </div>
  855.  
  856. <?php do_action('graphene_after_comment'); ?>
  857. <?php
  858.  
  859. do_action('graphene_after_comment');
  860. }
  861.  
  862. endif;
  863.  
  864.  
  865.  
  866. /**
  867. * Function to display ads from adsense
  868. */
  869. $adsense_adcount = 1;
  870. $ad_limit = apply_filters('graphene_adsense_ads_limit', 3);
  871. if (!function_exists('graphene_adsense')) :
  872. function graphene_adsense(){
  873. global $adsense_adcount, $ad_limit, $graphene_settings;
  874.  
  875. if ($graphene_settings['show_adsense'] && $adsense_adcount <= $ad_limit) : ?>
  876. <div class="post adsense_single" id="adsense-ad-<?php echo $adsense_adcount; ?>">
  877. <?php echo stripslashes($graphene_settings['adsense_code']); ?>
  878. </div>
  879. <?php do_action('graphene_show_adsense'); ?>
  880. <?php endif;
  881.  
  882. $adsense_adcount++;
  883.  
  884. do_action('graphene_adsense');
  885. }
  886. endif;
  887.  
  888.  
  889. /**
  890. * Function to display the AddThis social sharing button
  891. */
  892.  
  893. if (!function_exists('graphene_addthis')) :
  894. function graphene_addthis($post_id){
  895. global $graphene_settings;
  896.  
  897. // Get the local setting
  898. $show_addthis_local = (get_post_meta($post_id, '_graphene_show_addthis', true)) ? get_post_meta($post_id, '_graphene_show_addthis', true) : 'global';
  899. $show_addthis_global = $graphene_settings['show_addthis'];
  900. $show_addthis_page = $graphene_settings['show_addthis_page'];
  901.  
  902. // Determine whether we should show AddThis or not
  903. if ($show_addthis_local == 'show')
  904. $show_addthis = true;
  905. elseif ($show_addthis_local == 'hide')
  906. $show_addthis = false;
  907. elseif ($show_addthis_local == 'global'){
  908. if (($show_addthis_global && !is_page()) || ($show_addthis_global && $show_addthis_page))
  909. $show_addthis = true;
  910. else
  911. $show_addthis = false;
  912. }
  913.  
  914. // Show the AddThis button
  915. if ($show_addthis) {
  916. echo '<div class="add-this-right">';
  917. $html = stripslashes($graphene_settings['addthis_code']);
  918. $html = str_replace('[#post-url]', get_permalink($post_id), $html);
  919. $html = str_replace('[#post-title]', get_the_title($post_id), $html);
  920. echo $html;
  921. echo '</div>';
  922.  
  923. do_action('graphene_show_addthis');
  924. }
  925. do_action('graphene_addthis');
  926. }
  927. endif;
  928.  
  929.  
  930. /**
  931. * Register widgetized areas
  932. *
  933. * To override graphene_widgets_init() in a child theme, remove the action hook and add your own
  934. * function tied to the init hook.
  935. *
  936. * @since Graphene 1.0
  937. * @uses register_sidebar
  938. */
  939. function graphene_widgets_init() {
  940. if (function_exists('register_sidebar')) {
  941. global $graphene_settings;
  942.  
  943. register_sidebar(array(
  944. 'name' => __('Sidebar Widget Area', 'graphene'),
  945. 'id' => 'sidebar-widget-area',
  946. 'description' => __( 'The first sidebar widget area (available in two and three column layouts).', 'graphene' ),
  947. 'before_widget' => '<div id="%1$s" class="sidebar-wrap clearfix %2$s">',
  948. 'after_widget' => '</div>',
  949. 'before_title' => "<h3>",
  950. 'after_title' => "</h3>",
  951. ));
  952.  
  953. register_sidebar(array(
  954. 'name' => __('Sidebar Two Widget Area', 'graphene'),
  955. 'id' => 'sidebar-two-widget-area',
  956. 'description' => __( 'The second sidebar widget area (only available in three column layouts).', 'graphene'),
  957. 'before_widget' => '<div id="%1$s" class="sidebar-wrap clearfix %2$s">',
  958. 'after_widget' => '</div>',
  959. 'before_title' => "<h3>",
  960. 'after_title' => "</h3>",
  961. ));
  962.  
  963. register_sidebar(array(
  964. 'name' => __('Footer Widget Area', 'graphene'),
  965. 'id' => 'footer-widget-area',
  966. 'description' => __( "The footer widget area. Leave empty to disable. Set the number of columns to display at the theme's Display Options page.", 'graphene' ),
  967. 'before_widget' => '<div id="%1$s" class="sidebar-wrap clearfix %2$s">',
  968. 'after_widget' => '</div>',
  969. 'before_title' => "<h3>",
  970. 'after_title' => "</h3>",
  971. ));
  972.  
  973. /**
  974. * Register alternate widget areas to be displayed on the front page, if enabled
  975. *
  976. * @package WordPress
  977. * @subpackage Graphene
  978. * @since Graphene 1.0.8
  979. */
  980. if ($graphene_settings['alt_home_sidebar']) {
  981. register_sidebar(array(
  982. 'name' => __('Front Page Sidebar Widget Area', 'graphene'),
  983. 'id' => 'home-sidebar-widget-area',
  984. 'description' => __( 'The first sidebar widget area that will only be displayed on the front page.', 'graphene' ),
  985. 'before_widget' => '<div id="%1$s" class="sidebar-wrap clearfix %2$s">',
  986. 'after_widget' => '</div>',
  987. 'before_title' => "<h3>",
  988. 'after_title' => "</h3>",
  989. ));
  990.  
  991. register_sidebar(array(
  992. 'name' => __('Front Page Sidebar Two Widget Area', 'graphene'),
  993. 'id' => 'home-sidebar-two-widget-area',
  994. 'description' => __( 'The second sidebar widget area that will only be displayed on the front page.', 'graphene' ),
  995. 'before_widget' => '<div id="%1$s" class="sidebar-wrap clearfix %2$s">',
  996. 'after_widget' => '</div>',
  997. 'before_title' => "<h3>",
  998. 'after_title' => "</h3>",
  999. ));
  1000. }
  1001.  
  1002. if ($graphene_settings['alt_home_footerwidget']) {
  1003. register_sidebar(array(
  1004. 'name' => __('Front Page Footer Widget Area', 'graphene'),
  1005. 'id' => 'home-footer-widget-area',
  1006. 'description' => __( "The footer widget area that will only be displayed on the front page. Leave empty to disable. Set the number of columns to display at the theme's Display Options page.", 'graphene' ),
  1007. 'before_widget' => '<div id="%1$s" class="sidebar-wrap clearfix %2$s">',
  1008. 'after_widget' => '</div>',
  1009. 'before_title' => "<h3>",
  1010. 'after_title' => "</h3>",
  1011. ));
  1012. }
  1013.  
  1014. /* Header widget area */
  1015. if ($graphene_settings['enable_header_widget']) :
  1016. register_sidebar(array(
  1017. 'name' => __('Header Widget Area', 'graphene'),
  1018. 'id' => 'header-widget-area',
  1019. 'description' => __("The header widget area.", 'graphene'),
  1020. 'before_widget' => '<div id="%1$s" class="sidebar-wrap clearfix %2$s">',
  1021. 'after_widget' => '</div>',
  1022. 'before_title' => "<h3>",
  1023. 'after_title' => "</h3>",
  1024. ));
  1025. endif;
  1026. }
  1027.  
  1028. do_action('graphene_widgets_init');
  1029. }
  1030. /** Register sidebars by running graphene_widgets_init() on the widgets_init hook. */
  1031. add_action('widgets_init', 'graphene_widgets_init');
  1032.  
  1033.  
  1034. /**
  1035. * Register custom Twitter widgets.
  1036. */
  1037. global $twitter_username;
  1038. global $twitter_tweetcount;
  1039. $twitter_username = '';
  1040. $twitter_tweetcount = 1;
  1041.  
  1042. class Graphene_Widget_Twitter extends WP_Widget{
  1043.  
  1044. function Graphene_Widget_Twitter(){
  1045. // Widget settings
  1046. $widget_ops = array('classname' => 'graphene-twitter', 'description' => __('Display the latest Twitter status updates.', 'graphene'));
  1047.  
  1048. // Widget control settings
  1049. $control_ops = array('id_base' => 'graphene-twitter');
  1050.  
  1051. // Create the widget
  1052. $this->WP_Widget('graphene-twitter', 'Graphene Twitter', $widget_ops, $control_ops);
  1053.  
  1054. }
  1055.  
  1056. function widget($args, $instance){ // This function displays the widget
  1057. extract($args);
  1058.  
  1059. // User selected settings
  1060. global $twitter_username;
  1061. global $twitter_tweetcount;
  1062. $twitter_title = $instance['twitter_title'];
  1063. $twitter_username = $instance['twitter_username'];
  1064. $twitter_tweetcount = $instance['twitter_tweetcount'];
  1065.  
  1066. echo $args['before_widget'].$args['before_title'].$twitter_title.$args['after_title'];
  1067. ?>
  1068. <ul id="twitter_update_list">
  1069. <li>&nbsp;</li>
  1070. </ul>
  1071. <p id="tweetfollow" class="sidebar_ablock"><a href="http://twitter.com/<?php echo $twitter_username; ?>"><?php _e('Follow me on Twitter', 'graphene') ?></a></p>
  1072.  
  1073. <?php do_action('graphene_twitter_widget'); ?>
  1074. <?php echo $args['after_widget']; ?>
  1075.  
  1076. <?php
  1077. add_action('wp_footer', 'graphene_add_twitter_script');
  1078. }
  1079.  
  1080. function update($new_instance, $old_instance){ // This function processes and updates the settings
  1081. $instance = $old_instance;
  1082.  
  1083. // Strip tags (if needed) and update the widget settings
  1084. $instance['twitter_username'] = strip_tags($new_instance['twitter_username']);
  1085. $instance['twitter_tweetcount'] = strip_tags($new_instance['twitter_tweetcount']);
  1086. $instance['twitter_title'] = strip_tags($new_instance['twitter_title']);
  1087.  
  1088. return $instance;
  1089. }
  1090.  
  1091. function form($instance){ // This function sets up the settings form
  1092.  
  1093. // Set up default widget settings
  1094. $defaults = array(
  1095. 'twitter_username' => 'username',
  1096. 'twitter_tweetcount' => 5,
  1097. 'twitter_title' => __('Latest tweets', 'graphene'),
  1098. );
  1099. $instance = wp_parse_args( (array) $instance, $defaults );
  1100. ?>
  1101. <p>
  1102. <label for="<?php echo $this->get_field_id('twitter_title'); ?>"><?php _e('Title:', 'graphene'); ?></label>
  1103. <input id="<?php echo $this->get_field_id('twitter_title'); ?>" type="text" name="<?php echo $this->get_field_name('twitter_title'); ?>" value="<?php echo $instance['twitter_title']; ?>" class="widefat" />
  1104. </p>
  1105. <p>
  1106. <label for="<?php echo $this->get_field_id('twitter_username'); ?>"><?php _e('Twitter Username:', 'graphene'); ?></label>
  1107. <input id="<?php echo $this->get_field_id('twitter_username'); ?>" type="text" name="<?php echo $this->get_field_name('twitter_username'); ?>" value="<?php echo $instance['twitter_username']; ?>" class="widefat" />
  1108. </p>
  1109. <p>
  1110. <label for="<?php echo $this->get_field_id('twitter_tweetcount'); ?>"><?php _e('Number of tweets to display:', 'graphene'); ?></label>
  1111. <input id="<?php echo $this->get_field_id('twitter_tweetcount'); ?>" type="text" name="<?php echo $this->get_field_name('twitter_tweetcount'); ?>" value="<?php echo $instance['twitter_tweetcount']; ?>" size="1" />
  1112. </p>
  1113. <?php
  1114. }
  1115. }
  1116.  
  1117. /* The function that prints the Twitter script to the footer */
  1118. if (!function_exists('graphene_add_twitter_script')) :
  1119. function graphene_add_twitter_script(){
  1120. global $twitter_username;
  1121. global $twitter_tweetcount;
  1122. echo '
  1123. <!-- BEGIN Twitter Updates script -->
  1124. <script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
  1125. <script type="text/javascript" src="http://twitter.com/statuses/user_timeline/'.$twitter_username.'.json?callback=twitterCallback2&amp;count='.$twitter_tweetcount.'"></script>
  1126. <!-- END Twitter Updates script -->
  1127. ';
  1128. }
  1129. endif;
  1130.  
  1131.  
  1132. /**
  1133. * Register the custom widget by passing the graphene_load_widgets() function to widgets_init
  1134. * action hook.
  1135. * To override in a child theme, remove the action hook and add your own
  1136. */
  1137. function graphene_load_widgets(){
  1138. register_widget('Graphene_Widget_Twitter');
  1139. }
  1140. add_action('widgets_init', 'graphene_load_widgets');
  1141.  
  1142.  
  1143. /**
  1144. * Enqueue style for admin page
  1145. */
  1146. if (!function_exists('graphene_admin_options_style')) :
  1147. function graphene_admin_options_style() {
  1148. wp_enqueue_style('graphene-admin-style');
  1149. if (is_rtl()) {wp_enqueue_style('graphene-admin-style-rtl');}
  1150. }
  1151. endif;
  1152.  
  1153.  
  1154. /**
  1155. * Adds the theme options page
  1156. */
  1157. function graphene_options_init() {
  1158. $graphene_options = add_theme_page(__('Graphene Options', 'graphene'), __('Graphene Options', 'graphene'), 'edit_theme_options', 'graphene_options', 'graphene_options');
  1159. $graphene_faq = add_theme_page(__('Graphene FAQs', 'graphene'), __('Graphene FAQs', 'graphene'), 'edit_theme_options', 'graphene_faq', 'graphene_faq');
  1160.  
  1161. wp_register_style('graphene-admin-style', get_template_directory_uri().'/admin/admin.css');
  1162. if (is_rtl()) {wp_register_style('graphene-admin-style-rtl', get_template_directory_uri().'/admin/admin-rtl.css');}
  1163.  
  1164. add_action('admin_print_styles-'.$graphene_options, 'graphene_admin_options_style');
  1165.  
  1166. do_action('graphene_options_init');
  1167. }
  1168. add_action('admin_menu', 'graphene_options_init', 8);
  1169.  
  1170. // Includes the files where our theme options are defined
  1171. include('admin/options.php');
  1172. // include('admin/display.php');
  1173. include('admin/faq.php');
  1174.  
  1175.  
  1176. /**
  1177. * Function that generate the tabs in the theme's options page
  1178. */
  1179. if (!function_exists('graphene_options_tabs')) :
  1180. function graphene_options_tabs($current = 'general', $tabs = array('general' => 'General')){
  1181. $links = array();
  1182. foreach( $tabs as $tab => $name) :
  1183. if ( $tab == $current ) :
  1184. $links[] = "<a class='nav-tab nav-tab-active' href='?page=graphene_options&amp;tab=$tab'>$name</a>";
  1185. else :
  1186. $links[] = "<a class='nav-tab' href='?page=graphene_options&amp;tab=$tab'>$name</a>";
  1187. endif;
  1188. endforeach;
  1189.  
  1190. echo '<h3 class="options-tab">';
  1191. foreach ($links as $link)
  1192. echo $link;
  1193. echo '<a class="toggle-all" href="#">'.__('Toggle all tabs', 'graphene').'</a>';
  1194. echo '</h3>';
  1195. }
  1196. endif;
  1197.  
  1198.  
  1199. /**
  1200. * Include the file for additional user fields
  1201. *
  1202. * @package WordPress
  1203. * @subpackage Graphene
  1204. * @since Graphene 1.1
  1205. */
  1206. include('admin/user.php');
  1207.  
  1208. /**
  1209. * Include the file for additional custom fields in posts and pages editing screens
  1210. *
  1211. * @package WordPress
  1212. * @subpackage Graphene
  1213. * @since Graphene 1.1
  1214. */
  1215. include('admin/custom-fields.php');
  1216.  
  1217.  
  1218.  
  1219. /**
  1220. * Customise the comment form
  1221. */
  1222.  
  1223. // Starting with the default fields
  1224. function graphene_comment_form_fields(){
  1225. $fields = array(
  1226. 'author' => '<p class="comment-form-author clearfix"><label for="author" class="graphene_form_label">'.__('Name:','graphene').'</label><input id="author" name="author" type="text" class="graphene-form-field" /></p>',
  1227. 'email' => '<p class="comment-form-email clearfix"><label for="email" class="graphene_form_label">' . __('Email:','graphene').'</label><input id="email" name="email" type="text" class="graphene-form-field" /></p>',
  1228. 'url' => '<p class="comment-form-url clearfix"><label for="url" class="graphene_form_label">'.__('Website:','graphene').'</label><input id="url" name="url" type="text" class="graphene-form-field" /></p>',
  1229. );
  1230.  
  1231. do_action('graphene_comment_form_fields');
  1232.  
  1233. return $fields;
  1234. }
  1235.  
  1236. // The comment field textarea
  1237. function graphene_comment_textarea(){
  1238. echo '<p class="clearfix"><label class="graphene_form_label">'.__('Message:','graphene').'</label><textarea name="comment" id="comment" cols="40" rows="10" class="graphene-form-field"></textarea></p><div class="graphene_wrap">';
  1239.  
  1240. do_action('graphene_comment_textarea');
  1241. }
  1242.  
  1243. // The submit button
  1244. function graphene_comment_submit_button(){
  1245. echo '<p class="graphene-form-submit"><button type="submit" id="graphene_submit" class="block-button" name="graphene_submit">'.__('Submit Comment', 'graphene').'</button></p></div>';
  1246.  
  1247. do_action('graphene_comment_submit_button');
  1248. }
  1249.  
  1250. // Add all the filters we defined
  1251. add_filter('comment_form_default_fields', 'graphene_comment_form_fields');
  1252. add_filter('comment_form_field_comment', 'graphene_comment_textarea');
  1253. add_filter('comment_form', 'graphene_comment_submit_button');
  1254.  
  1255.  
  1256. /**
  1257. * Returns a "Continue Reading" link for excerpts
  1258. * Based on the function from the Twenty Ten theme
  1259. *
  1260. * @since Graphene 1.0.8
  1261. * @return string "Continue Reading" link
  1262. */
  1263. if (!function_exists('graphene_continue_reading_link')) :
  1264. function graphene_continue_reading_link() {
  1265. global $in_slider;
  1266. if (!is_page() && !$in_slider) {
  1267. $more_link_text = __('Continue reading &raquo;', 'graphene');
  1268. return '</p><p><a class="more-link block-button" href="'.get_permalink().'">'.$more_link_text.'</a>';
  1269. }
  1270. }
  1271. endif;
  1272.  
  1273.  
  1274. /**
  1275. * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and graphene_continue_reading_link().
  1276. * Based on the function from Twenty Ten theme.
  1277. *
  1278. * To override this in a child theme, remove the filter and add your own
  1279. * function tied to the excerpt_more filter hook.
  1280. *
  1281. * @since Graphene 1.0.8
  1282. * @return string An ellipsis
  1283. */
  1284. function graphene_auto_excerpt_more($more) {
  1285. return apply_filters('graphene_auto_excerpt_more', ' &hellip; '.graphene_continue_reading_link());
  1286. }
  1287. add_filter('excerpt_more', 'graphene_auto_excerpt_more' );
  1288.  
  1289.  
  1290. /**
  1291. * Add the Read More link to manual excerpts
  1292. *
  1293. * @since Graphene 1.1.3
  1294. */
  1295. function graphene_manual_except_more($text){
  1296. global $in_slider;
  1297. if (has_excerpt() && !$in_slider){
  1298. $text = explode('</p>', $text);
  1299. $text[count($text)-2] .= graphene_continue_reading_link();
  1300. $text = implode('</p>', $text);
  1301. }
  1302. return $text;
  1303. }
  1304. if ($graphene_settings['show_excerpt_more']) {
  1305. add_filter('the_excerpt', 'graphene_manual_except_more');
  1306. }
  1307.  
  1308.  
  1309. /**
  1310. * Generates the posts navigation links
  1311. */
  1312. if (!function_exists('graphene_posts_nav')) :
  1313. function graphene_posts_nav(){
  1314. $query = $GLOBALS['wp_query'];
  1315. if ($query->max_num_pages > 1) : ?>
  1316. <div class="post-nav clearfix">
  1317. <?php if (function_exists('wp_pagenavi')) : wp_pagenavi(); else : ?>
  1318. <?php if (!is_search()) : ?>
  1319. <p id="previous"><?php next_posts_link(__('Older posts &laquo;', 'graphene')) ?></p>
  1320. <p id="next-post"><?php previous_posts_link(__('&raquo; Newer posts', 'graphene')) ?></p>
  1321. <?php else : ?>
  1322. <p id="next-post"><?php next_posts_link(__('Next page &raquo;', 'graphene')) ?></p>
  1323. <p id="previous"><?php previous_posts_link(__('&laquo; Previous page', 'graphene')) ?></p>
  1324. <?php endif; ?>
  1325. <?php endif; do_action('graphene_posts_nav'); ?>
  1326. </div>
  1327. <?php
  1328. endif;
  1329. }
  1330. endif;
  1331.  
  1332.  
  1333. /**
  1334. * Prints out the scripts required for the featured posts slider
  1335. */
  1336.  
  1337. /* jQuery Scrollable */
  1338. if (!function_exists('graphene_scrollable')) :
  1339. function graphene_scrollable() {
  1340. global $graphene_settings;
  1341.  
  1342. $interval = ($graphene_settings['slider_speed']) ? $graphene_settings['slider_speed'] : 7000;
  1343. ?>
  1344. <!-- Scrollable -->
  1345. <script type="text/javascript">
  1346. //<![CDATA[
  1347. jQuery(document).ready(function($){
  1348. $(function() {
  1349. // initialize scrollable
  1350. $("#slider_root").scrollable({circular: true, speed: <?php echo $graphene_settings['slider_trans_speed']; ?>}).navigator({
  1351. navi: ".slider_nav",
  1352. naviItem: 'a',
  1353. activeClass: 'active'
  1354. }).autoscroll({interval: <?php echo $interval; ?>});
  1355. });
  1356. });
  1357. //]]>
  1358. </script>
  1359. <!-- #Scrollable -->
  1360. <?php
  1361. }
  1362. endif;
  1363.  
  1364.  
  1365. /**
  1366. * Control the excerpt length
  1367. */
  1368. function graphene_excerpt_length($length) {
  1369. global $graphene_settings;
  1370. $column_mode = graphene_column_mode();
  1371. if ($graphene_settings['slider_display_style'] == 'bgimage-excerpt'){
  1372. if (strpos($column_mode, 'three-col') === 0)
  1373. return 24;
  1374. if (strpos($column_mode, 'two-col') === 0)
  1375. return 40;
  1376. if ($column_mode == 'one-column')
  1377. return 55;
  1378. }
  1379.  
  1380. return 55;
  1381. }
  1382. add_filter('excerpt_length', 'graphene_excerpt_length');
  1383.  
  1384.  
  1385.  
  1386. /**
  1387. * Creates the functions that output the slider
  1388. */
  1389. function graphene_slider(){
  1390. global $graphene_settings, $in_slider;
  1391.  
  1392. $in_slider = true;
  1393.  
  1394. do_action('graphene_before_slider'); ?>
  1395. <?php $class = ($graphene_settings['slider_display_style'] == 'bgimage-excerpt') ? ' full-sized' : ''; ?>
  1396. <div class="featured_slider<?php echo $class; ?>">
  1397. <?php do_action('graphene_before_slideritems'); ?>
  1398. <div id="slider_root">
  1399. <div class="slider_items">
  1400. <?php
  1401. /**
  1402. * Get the featured posts to be displayed on the slider
  1403. */
  1404. global $post;
  1405.  
  1406. /**
  1407. * Get the category whose posts should be displayed here. If no
  1408. * category is defined, the 5 latest posts will be displayed
  1409. */
  1410. $slidercat = ($graphene_settings['slider_cat'] != '') ? $graphene_settings['slider_cat'] : false;
  1411.  
  1412. /* Set the post types to be displayed */
  1413. $slider_post_type = ($slidercat == 'posts_pages') ? array('post', 'page') : array('post') ;
  1414. $slider_post_type = apply_filters('graphene_slider_post_type', $slider_post_type);
  1415.  
  1416. /* Get the posts to display in the slider */
  1417.  
  1418. // Get the number of posts to show
  1419. $postcount = ($graphene_settings['slider_postcount']) ? $graphene_settings['slider_postcount'] : 5 ;
  1420.  
  1421. $args = array(
  1422. 'numberposts' => $postcount,
  1423. 'orderby' => 'date',
  1424. 'order' => 'DESC',
  1425. 'suppress_filters' => 0,
  1426. 'post_type' => $slider_post_type,
  1427. );
  1428.  
  1429. if ($slidercat && !in_array($slidercat, array('random', 'posts_pages'))) {
  1430. $args = array_merge($args, array('category' => $slidercat));
  1431. }
  1432.  
  1433. if ($slidercat && $slidercat == 'random') {
  1434. $args = array_merge($args, array('orderby' => 'rand'));
  1435. }
  1436.  
  1437. if ($slidercat && $slidercat == 'posts_pages') {
  1438. $post_ids = $graphene_settings['slider_specific_posts'];
  1439. $args = array_merge($args, array('include' => $post_ids, 'numberposts' => -1, 'orderby' => '', 'order' => ''));
  1440. }
  1441.  
  1442. $sliderposts = get_posts(apply_filters('graphene_slider_args', $args));
  1443.  
  1444. $sliderposts = apply_filters('graphene_slider_posts', $sliderposts);
  1445.  
  1446. /* Display each post in the slider */
  1447. foreach ($sliderposts as $post){
  1448. setup_postdata($post);
  1449.  
  1450. $style = '';
  1451. /* Slider background image*/
  1452. if ($graphene_settings['slider_display_style'] == 'bgimage-excerpt') {
  1453. $column_mode = graphene_column_mode();
  1454. if ($column_mode == 'one-column'){
  1455. $image_size = 'graphene_slider_full';
  1456. } elseif ( strpos($column_mode, 'two-col') === 0){
  1457. $image_size = 'graphene_slider';
  1458. } else if ( strpos($column_mode, 'three-col') === 0 ){
  1459. $image_size = 'graphene_slider_small';
  1460. }
  1461. $image = graphene_get_slider_image($post->ID, $image_size, true);
  1462. if ($image){
  1463. $style .= 'style="background-image:url(';
  1464. $style .= (is_array($image)) ? $image[0] : $image;
  1465. $style .= ');"';
  1466. }
  1467. }
  1468. ?>
  1469.  
  1470. <div class="slider_post clearfix" id="slider-post-<?php echo $post->ID; ?>" <?php echo $style; ?>>
  1471. <?php do_action('graphene_before_sliderpost'); ?>
  1472.  
  1473. <?php if ($graphene_settings['slider_display_style'] == 'thumbnail-excerpt') : ?>
  1474. <?php /* The slider post's featured image */ ?>
  1475. <?php
  1476. if (get_post_meta($post->ID, '_graphene_slider_img', true) != 'disabled' && !((get_post_meta($post->ID, '_graphene_slider_img', true) == 'global' || get_post_meta($post->ID, '_graphene_slider_img', true) == '') && $graphene_settings['slider_img'] == 'disabled')) :
  1477. $image = graphene_get_slider_image($post->ID, apply_filters('graphene_slider_image_size', 'thumbnail'));
  1478. if ($image) :
  1479. ?>
  1480.  
  1481. <div class="sliderpost_featured_image">
  1482. <?php echo $image; ?>
  1483. </div>
  1484.  
  1485. <?php endif; endif; ?>
  1486. <?php endif; ?>
  1487.  
  1488. <div class="slider-entry-wrap">
  1489. <div class="slider-content-wrap">
  1490. <?php /* The slider post's title */ ?>
  1491. <h2 class="slider_post_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
  1492.  
  1493. <?php /* The slider post's excerpt */ ?>
  1494. <div class="slider_post_entry">
  1495. <?php
  1496. if ($graphene_settings['slider_display_style'] != 'full-post'){
  1497. the_excerpt();
  1498. ?>
  1499. <a class="block-button" href="<?php the_permalink(); ?>"><?php _e('View full post', 'graphene'); ?></a>
  1500. <?php } else {the_content();}?>
  1501.  
  1502. <?php do_action('graphene_slider_postentry'); ?>
  1503. </div>
  1504. </div>
  1505. </div>
  1506. </div>
  1507. <?php
  1508. }
  1509. ?>
  1510. </div>
  1511. </div>
  1512.  
  1513. <?php /* The slider navigation */ ?>
  1514. <div class="slider_nav">
  1515. <?php $i = 0; foreach ($sliderposts as $post) : ?>
  1516. <a href="#" <?php if ($i == 0) {echo ' class="active"';} ?>><span><?php the_title(); ?></span></a>
  1517. <?php $i++; endforeach; ?>
  1518.  
  1519. <?php do_action('graphene_slider_nav'); ?>
  1520. </div>
  1521.  
  1522. </div>
  1523. <?php
  1524. wp_reset_query();
  1525. do_action('graphene_after_slider');
  1526. $in_slider = false;
  1527. }
  1528. /* Create an intermediate function that controls where the slider should be displayed */
  1529. if (!function_exists('graphene_display_slider')) :
  1530. function graphene_display_slider(){
  1531. if (is_front_page()){
  1532. graphene_slider();
  1533. add_action('wp_footer', 'graphene_scrollable');
  1534. }
  1535. }
  1536. endif;
  1537. /* Hook the slider to the appropriate action hook */
  1538. if (!$graphene_settings['slider_disable']){
  1539. if (!$graphene_settings['slider_position'])
  1540. add_action('graphene_top_content', 'graphene_display_slider');
  1541. else
  1542. add_action('graphene_bottom_content', 'graphene_display_slider');
  1543. }
  1544.  
  1545.  
  1546. /**
  1547. * This function determines which image to be used as the slider image based on user
  1548. * settings, and returns the <img> tag of the the slider image.
  1549. *
  1550. * It requires the post's ID to be passed in as argument so that the user settings in
  1551. * individual post / page can be retrieved.
  1552. */
  1553. if (!function_exists('graphene_get_slider_image')) :
  1554. function graphene_get_slider_image($post_id = NULL, $size = 'thumbnail', $urlonly = false){
  1555. global $graphene_settings;
  1556.  
  1557. // Throw an error message if no post ID supplied
  1558. if ($post_id == NULL){
  1559. echo '<strong>ERROR:</strong> Post ID must be passed as an input argument to call the function <code>graphene_get_slider_image()</code>.';
  1560. return;
  1561. }
  1562.  
  1563. // First get the settings
  1564. $global_setting = ($graphene_settings['slider_img']) ? $graphene_settings['slider_img'] : 'featured_image';
  1565. $local_setting = (get_post_meta($post_id, '_graphene_slider_img', true)) ? get_post_meta($post_id, '_graphene_slider_img', true) : 'global';
  1566.  
  1567. // Determine which image should be displayed
  1568. $final_setting = ($local_setting == 'global') ? $global_setting : $local_setting;
  1569.  
  1570. // Build the html based on the final setting
  1571. $html = '';
  1572. if ($final_setting == 'disabled'){ // image disabled
  1573.  
  1574. return;
  1575.  
  1576. } elseif ($final_setting == 'featured_image'){ // Featured Image
  1577.  
  1578. if (has_post_thumbnail($post_id)) :
  1579. if ($urlonly)
  1580. $html = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $size);
  1581. else
  1582. $html .= get_the_post_thumbnail($post_id, $size);
  1583. endif;
  1584.  
  1585. } elseif ($final_setting == 'post_image'){ // First image in post
  1586.  
  1587. $html = graphene_get_post_image($post_id, $size, '', $urlonly);
  1588.  
  1589. } elseif ($final_setting == 'custom_url'){ // Custom URL
  1590.  
  1591. if (!$urlonly){
  1592. $html .= '<a href="'.get_permalink($post_id).'">';
  1593. if ($local_setting != 'global') :
  1594. $html .= '<img src="'.get_post_meta($post_id, '_graphene_slider_imgurl', true).'" alt="" />';
  1595. else :
  1596. $html .= '<img src="'.$graphene_settings['slider_imgurl'].'" alt="" />';
  1597. endif;
  1598. $html .= '</a>';
  1599. } else {
  1600. if ($local_setting != 'global') :
  1601. $html .= get_post_meta($post_id, '_graphene_slider_imgurl', true);
  1602. else :
  1603. $html .= $graphene_settings['slider_imgurl'];
  1604. endif;
  1605. }
  1606.  
  1607. }
  1608.  
  1609. // Returns the html
  1610. return $html;
  1611.  
  1612. }
  1613. endif;
  1614.  
  1615.  
  1616. /**
  1617. * This function gets the first image (as ordered in the post's media gallery) attached to
  1618. * the current post. It outputs the complete <img> tag, with height and width attributes.
  1619. * The function returns the thumbnail of the original image, linked to the post's
  1620. * permalink. Returns FALSE if the current post has no image.
  1621. *
  1622. * This function requires the post ID to get the image from to be supplied as the
  1623. * argument. If no post ID is supplied, it outputs an error message. An optional argument
  1624. * size can be used to determine the size of the image to be used.
  1625. *
  1626. * Based on code snippets by John Crenshaw
  1627. * (http://www.rlmseo.com/blog/get-images-attached-to-post/)
  1628. *
  1629. * @package WordPress
  1630. * @subpackage Graphene
  1631. * @since Graphene 1.1
  1632. */
  1633. if (!function_exists('graphene_get_post_image')) :
  1634. function graphene_get_post_image($post_id = NULL, $size = 'thumbnail', $context = '', $urlonly = false){
  1635.  
  1636. /* Display error message if no post ID is supplied */
  1637. if ($post_id == NULL){
  1638. _e('<strong>ERROR: You must supply the post ID to get the image from as an argument when calling the graphene_get_post_image() function.</strong>', 'graphene');
  1639. return;
  1640. }
  1641.  
  1642. /* Get the images */
  1643. $images = get_children(array(
  1644. 'post_type' => 'attachment',
  1645. 'post_mime_type' => 'image',
  1646. 'post_parent' => $post_id,
  1647. 'orderby' => 'menu_order',
  1648. 'order' => 'ASC',
  1649. 'numberposts' => 1,
  1650. ), ARRAY_A);
  1651.  
  1652. $html = '';
  1653.  
  1654. /* Returns generic image if there is no image to show */
  1655. if (empty($images) && $context != 'excerpt' && !$urlonly) {
  1656. $html .= apply_filters('graphene_generic_slider_img', '<img alt="" src="'.get_template_directory_uri().'/images/img_slider_generic.png" />');
  1657. }
  1658.  
  1659. /* Build the <img> tag if there is an image */
  1660. foreach ($images as $image){
  1661. if (!$urlonly) {
  1662. if ($context == 'excerpt') {$html .= '<div class="excerpt-thumb">';};
  1663. $html .= '<a href="'.get_permalink($post_id).'">';
  1664. $html .= wp_get_attachment_image($image['ID'], $size);
  1665. $html .= '</a>';
  1666. if ($context == 'excerpt') {$html .= '</div>';};
  1667. } else {
  1668. $html = wp_get_attachment_image_src($image['ID'], $size);
  1669. }
  1670. }
  1671.  
  1672. /* Returns the image HTMl */
  1673. return $html;
  1674. }
  1675. endif;
  1676.  
  1677.  
  1678. /**
  1679. * This function retrieves the header image for the theme
  1680. */
  1681. if (!function_exists('graphene_get_header_image')) :
  1682. function graphene_get_header_image($post_id = NULL){
  1683. global $graphene_settings;
  1684.  
  1685. if ( is_singular() && has_post_thumbnail( $post_id ) && ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'post-thumbnail' ) ) && $image[1] >= HEADER_IMAGE_WIDTH && !$graphene_settings['featured_img_header']) {
  1686. // Houston, we have a new header image!
  1687. // Gets only the image url. It's a pain, I know! Wish WordPress has better options on this one
  1688. $header_img = get_the_post_thumbnail( $post_id, 'post-thumbnail' );
  1689. $header_img = explode('" class="', $header_img);
  1690. $header_img = $header_img[0];
  1691. $header_img = explode('src="', $header_img);
  1692. $header_img = $header_img[1]; // only the url
  1693. }
  1694. else if ($graphene_settings['use_random_header_img']){
  1695. $default_header_images = graphene_get_default_headers();
  1696. $randomkey = array_rand($default_header_images);
  1697. $header_img = str_replace('%s', get_template_directory_uri(), $default_header_images[$randomkey]['url']);
  1698. } else {
  1699. $header_img = get_header_image();
  1700. }
  1701. return $header_img;
  1702. }
  1703. add_action('graphene_get_header_image', 'graphene_get_header_image');
  1704. endif;
  1705.  
  1706.  
  1707. /**
  1708. * Adds the functionality to count comments by type, eg. comments, pingbacks, tracbacks.
  1709. * Based on the code at WPCanyon (http://wpcanyon.com/tipsandtricks/get-separate-count-for-comments-trackbacks-and-pingbacks-in-wordpress/)
  1710. *
  1711. * In Graphene version 1.3 the $noneText param has been removed
  1712. *
  1713. * @package WordPress
  1714. * @subpackage Graphene
  1715. * @since Graphene 1.3
  1716. */
  1717. function graphene_comment_count($type = 'comments', $oneText = '', $moreText = ''){
  1718. if($type == 'comments') :
  1719. $typeSql = 'comment_type = ""';
  1720. elseif($type == 'pings') :
  1721. $typeSql = 'comment_type != ""';
  1722. elseif($type == 'trackbacks') :
  1723. $typeSql = 'comment_type = "trackback"';
  1724. elseif($type == 'pingbacks') :
  1725. $typeSql = 'comment_type = "pingback"';
  1726. endif;
  1727.  
  1728. global $wpdb;
  1729.  
  1730. $result = $wpdb->get_var('
  1731. SELECT
  1732. COUNT(comment_ID)
  1733. FROM
  1734. '.$wpdb->comments.'
  1735. WHERE
  1736. '.$typeSql.' AND
  1737. comment_approved="1" AND
  1738. comment_post_ID= '.get_the_ID()
  1739. );
  1740.  
  1741. //if($result == 0):
  1742. // echo str_replace('%', $result, $noneText);
  1743. if($result == 1) :
  1744. return str_replace('%', $result, $oneText);
  1745. elseif($result > 1) :
  1746. return str_replace('%', $result, $moreText);
  1747. else :
  1748. return false;
  1749. endif;
  1750. }
  1751.  
  1752. /**
  1753. * Enqueue the jQuery Tools Tabs JS and the necessary script for comments/pings tabs
  1754. */
  1755. function graphene_tabs_js(){
  1756. global $tabbed;
  1757. if ($tabbed) :
  1758. ?>
  1759. <script type="text/javascript">
  1760. //<![CDATA[
  1761. jQuery(document).ready(function($){
  1762. $(function(){
  1763. $("div#comments").tabs("div#comments > ol", {tabs: 'h4', effect: 'fade'});
  1764. });
  1765. });
  1766. //]]>
  1767. </script>
  1768. <?php
  1769. endif;
  1770. }
  1771. add_action('wp_footer', 'graphene_tabs_js');
  1772.  
  1773.  
  1774.  
  1775. /**
  1776. * Add JavaScript for the theme's options page
  1777. */
  1778. function graphene_options_js(){
  1779. if ( strstr( $_SERVER["REQUEST_URI"], 'page=graphene_options' ) ) {
  1780. require('admin/js/admin.js.php');
  1781. }
  1782. }
  1783. add_action('admin_footer', 'graphene_options_js');
  1784.  
  1785.  
  1786. /**
  1787. * This functions adds additional classes to the <body> element. The additional classes
  1788. * are added by filtering the WordPress body_class() function.
  1789. */
  1790. function graphene_body_class($classes){
  1791.  
  1792. $column_mode = graphene_column_mode();
  1793. $classes[] = $column_mode;
  1794. // for easier CSS
  1795. if ( strpos($column_mode, 'two-col') === 0){
  1796. $classes[] = 'two-columns';
  1797. } else if ( strpos($column_mode, 'three-col') === 0 ){
  1798. $classes[] = 'three-columns';
  1799. }
  1800.  
  1801. // Prints the body class
  1802. return $classes;
  1803. }
  1804. add_filter('body_class', 'graphene_body_class');
  1805.  
  1806.  
  1807. /**
  1808. * This functions adds additional classes to the post element. The additional classes
  1809. * are added by filtering the WordPress post_class() function.
  1810. */
  1811. function graphene_post_class($classes){
  1812. global $graphene_settings;
  1813.  
  1814. if (in_array($graphene_settings['post_date_display'], array('hidden', 'text'))) {
  1815. $classes[] = 'nodate';
  1816. }
  1817.  
  1818. // Prints the body class
  1819. return $classes;
  1820. }
  1821. add_filter('post_class', 'graphene_post_class');
  1822.  
  1823. /**
  1824. * Add the .sticky post class to sticky posts in the home page if the "Front page posts
  1825. * categories" option is being used
  1826. */
  1827. function graphene_sticky_post_class($classes){
  1828. if (is_sticky() && !in_array('sticky', $classes) && is_home()){
  1829. $classes[] = 'sticky';
  1830. }
  1831. return $classes;
  1832. }
  1833. add_filter('post_class', 'graphene_sticky_post_class');
  1834.  
  1835.  
  1836. function graphene_column_mode(){
  1837. global $graphene_settings;
  1838.  
  1839. // first check the template
  1840. if (is_page_template('template-onecolumn.php'))
  1841. return 'one-column';
  1842. elseif (is_page_template('template-twocolumnsleft.php'))
  1843. return 'two-col-left';
  1844. elseif (is_page_template('template-twocolumnsright.php'))
  1845. return 'two-col-right';
  1846. elseif (is_page_template('template-threecolumnsleft.php'))
  1847. return 'three-col-left';
  1848. elseif (is_page_template('template-threecolumnsright.php'))
  1849. return 'three-col-right';
  1850. elseif (is_page_template('template-threecolumnscenter.php'))
  1851. return 'three-col-center';
  1852. else // now get the column mode
  1853. return $graphene_settings['column_mode'];
  1854. }
  1855.  
  1856. /**
  1857. * Add the .htc file for partial CSS3 support in Internet Explorer
  1858. */
  1859. function graphene_ie_css3(){ ?>
  1860. <!--[if lte IE 8]>
  1861. <style type="text/css" media="screen">
  1862. #footer, div.sidebar-wrap, .block-button, .featured_slider, #slider_root, #comments li.bypostauthor, #nav li ul, .pie{behavior: url(<?php echo get_template_directory_uri(); ?>/js/PIE.php);}
  1863. .featured_slider{margin-top:0 !important;}
  1864. </style>
  1865. <![endif]-->
  1866. <?php
  1867. }
  1868. add_action('wp_head', 'graphene_ie_css3');
  1869.  
  1870.  
  1871. /**
  1872. * Fix IE8 image scaling issues when using max-width property on images
  1873. */
  1874. function graphene_ie8_img(){ ?>
  1875. <!--[if IE 8]>
  1876. <script type="text/javascript">
  1877. (function($) {
  1878. var imgs, i, w;
  1879. var imgs = document.getElementsByTagName('img');
  1880. maxwidth = 0.98 * $('.entry-content').width();
  1881. for( i = 0; i < imgs.length; i++ ) {
  1882. w = imgs[i].getAttribute( 'width' );
  1883. if ( w > maxwidth ) {
  1884. imgs[i].removeAttribute( 'width' );
  1885. imgs[i].removeAttribute( 'height' );
  1886. }
  1887. }
  1888. })(jQuery);
  1889. </script>
  1890. <![endif]-->
  1891. <?php
  1892. }
  1893. add_action('wp_footer', 'graphene_ie8_img');
  1894.  
  1895.  
  1896. /**
  1897. * Add Google Analytics code if tracking is enabled
  1898. */
  1899. function graphene_google_analytics(){
  1900. global $graphene_settings;
  1901. if ($graphene_settings['show_ga']) : ?>
  1902. <!-- BEGIN Google Analytics script -->
  1903. <?php echo stripslashes($graphene_settings['ga_code']); ?>
  1904. <!-- END Google Analytics script -->
  1905. <?php endif;
  1906. }
  1907. add_action('wp_head', 'graphene_google_analytics', 1000);
  1908.  
  1909.  
  1910. /**
  1911. * This function prints out the title for the website.
  1912. * If present, the theme will display customised site title structure.
  1913. */
  1914. if (!function_exists('graphene_title')) :
  1915. function graphene_title(){
  1916. global $graphene_settings;
  1917.  
  1918. if (is_front_page()) {
  1919. if ($graphene_settings['custom_site_title_frontpage']) {
  1920. $title = $graphene_settings['custom_site_title_frontpage'];
  1921. $title = str_replace('#site-name', get_bloginfo('name'), $title);
  1922. $title = str_replace('#site-desc', get_bloginfo('description'), $title);
  1923. } else {
  1924. $title = get_bloginfo('name') . " &raquo; " . get_bloginfo('description');
  1925. }
  1926.  
  1927. } else {
  1928. if ($graphene_settings['custom_site_title_content']) {
  1929. $title = $graphene_settings['custom_site_title_content'];
  1930. $title = str_replace('#site-name', get_bloginfo('name'), $title);
  1931. $title = str_replace('#site-desc', get_bloginfo('description'), $title);
  1932. $title = str_replace('#post-title', wp_title('', false), $title);
  1933. } else {
  1934. $title = wp_title('', false)." &raquo; ".get_bloginfo('name');
  1935. }
  1936. }
  1937.  
  1938. echo $title;
  1939. }
  1940. endif;
  1941.  
  1942.  
  1943. /*
  1944. * Adds a menu-item-ancestor class to menu items with children for styling.
  1945. * Code taken from the Menu-item-ancestor plugin by Valentinas Bakaitis
  1946. */
  1947. function graphene_add_ancestor_class($classlist, $item){
  1948. global $wp_query, $wpdb;
  1949. //get the ID of the object, to which menu item points
  1950. $id = get_post_meta($item->ID, '_menu_item_object_id', true);
  1951. //get first menu item that is a child of that object
  1952. $children = $wpdb->get_var('SELECT post_id FROM '.$wpdb->postmeta.' WHERE meta_key like "_menu_item_menu_item_parent" AND meta_value='.$item->ID.' LIMIT 1');
  1953. //if there is at least one item, then $children variable will contain it's ID (which is of course more than 0)
  1954. if($children > 0)
  1955. //in that case - add the CSS class
  1956. $classlist[] = 'menu-item-ancestor';
  1957. //return class list
  1958. return $classlist;
  1959. }
  1960.  
  1961. //add filter to nav_menu_css_class list
  1962. add_filter('nav_menu_css_class', 'graphene_add_ancestor_class', 2, 10);
  1963.  
  1964.  
  1965. /**
  1966. * Prints out the content of a variable wrapped in <pre> elements.
  1967. * For development and debugging use
  1968. */
  1969. function disect_it($var = NULL, $exit = true, $comment = false){
  1970. if ($var !== NULL){
  1971. if ($comment) {echo '<!--';}
  1972. echo '<pre>';
  1973. print_r($var);
  1974. echo '</pre>';
  1975. if ($comment) {echo '-->';}
  1976. if ($exit) {exit();}
  1977. } else {
  1978. echo '<strong>ERROR:</strong> You must pass a variable as argument to the <code>disect_it()</code> function.';
  1979. }
  1980. }
  1981.  
  1982. function graphene_page_template_visualizer() {
  1983. global $graphene_settings, $post_id;
  1984. $template_not_found = __('Template preview not found.', 'graphene');
  1985.  
  1986. if (!get_post_meta($post_id, '_wp_page_template', true)){
  1987. $default_template = __('default', 'graphene');
  1988. } else {
  1989. switch($graphene_settings['column_mode']){
  1990. case 'one-column':
  1991. $default_template = 'template-onecolumn.php';
  1992. break;
  1993. case 'two-col-right':
  1994. $default_template = 'template-twocolumnsright.php';
  1995. break;
  1996. case 'three-col-left':
  1997. $default_template = 'template-threecolumnsleft.php';
  1998. break;
  1999. case 'three-col-right':
  2000. $default_template = 'template-threecolumnsright.php';
  2001. break;
  2002. case 'three-col-center':
  2003. $default_template = 'template-threecolumnscenter.php';
  2004. break;
  2005. default:
  2006. $default_template = 'template-twocolumnsleft.php';
  2007. break;
  2008. }
  2009. }
  2010.  
  2011.  
  2012. $preview_img_path = get_template_directory_uri() . '/admin/images/';
  2013. ?>
  2014. <script type="text/javascript">
  2015. //<![CDATA[
  2016. jQuery(document).ready(function($){
  2017. $('#page_template').change(function(){
  2018. update_page_template();
  2019. });
  2020. // $('#page_template').after('<p><span><?php echo $template_not_found;?></span><img id="page_template_img" alt="none" /></p>');
  2021. $('#page_template').after('<p><img id="page_template_img" alt="none" /></p>');
  2022.  
  2023. function update_page_template() {
  2024. var preview_img = $('#page_template').val().replace(/.php$/, '.png');
  2025. //if (preview_img == 'default'){ preview_img = '<?php echo $default_template;?>'; }
  2026. $('#page_template_img').attr('src', '<?php echo $preview_img_path ?>'+preview_img);
  2027. }
  2028.  
  2029. // if the template preview image is not found, hide the image not found and show text
  2030. $('#page_template_img').error(function(){
  2031. $(this).hide();
  2032. $('span', $(this).parent()).show();
  2033. });
  2034. // if the template preview image is found, show the image
  2035. $('#page_template_img').load(function(){
  2036. $(this).show();
  2037. $('span', $(this).parent()).hide();
  2038. });
  2039.  
  2040. // remove the default option (because the theme overrides the template
  2041. $('#page_template option[value="default"]').remove();
  2042. // add the theme default item
  2043. $('#page_template option:first').before($('<option value="default"><?php _e('Theme default', 'graphene'); ?></option>'));
  2044. // select the default template if it isn't already selected
  2045. if ($('#page_template option[selected="selected"]').length == 0){
  2046. // $('#page_template option[text="<?php echo $default_template; ?>"]').attr('selected', 'selected');
  2047. $('#page_template option:contains("<?php _e('Theme default', 'graphene'); ?>")').attr('selected', 'selected');
  2048. }
  2049.  
  2050. update_page_template();
  2051. });
  2052. //]]>
  2053. </script>
  2054. <?php
  2055. }
  2056. add_action('edit_page_form', 'graphene_page_template_visualizer'); // only works on pages
  2057.  
  2058. function graphene_print_style(){
  2059. wp_register_style('graphene-print', get_template_directory_uri().'/print.css', null, true, 'print');
  2060. wp_enqueue_style('graphene-print');
  2061.  
  2062. do_action('graphene_print');
  2063. }
  2064.  
  2065. function graphene_print_only_text($text){
  2066. return sprintf('<p class="printonly">%s</p>', $text);
  2067. }
  2068.  
  2069. function graphene_can_import(){
  2070. // json_encode and json_decode only available from PHP version 5.2.1
  2071. // return version_compare(PHP_VERSION, '5.2.1', '>=');
  2072.  
  2073. // WordPress provides compatibility layer that supports json_encode and json_decode
  2074. if (function_exists('json_encode') && function_exists('json_decode')) {return true;} else {return false;}
  2075. }
  2076.  
  2077. function graphene_export_options(){
  2078.  
  2079. global $graphene_settings;
  2080.  
  2081. ob_clean();
  2082.  
  2083. /* Check authorisation */
  2084. $authorised = true;
  2085. // Check nonce
  2086. if (!wp_verify_nonce($_POST['graphene-export'], 'graphene-export')) {
  2087. $authorised = false;
  2088. }
  2089. // Check permissions
  2090. if (!current_user_can('edit_theme_options')){
  2091. $authorised = false;
  2092. }
  2093. if ($authorised) {
  2094.  
  2095. $name = 'graphene_options.txt';
  2096. $data = json_encode($graphene_settings);
  2097. $size = strlen($data);
  2098.  
  2099. header('Content-Type: text/plain');
  2100. header('Content-Disposition: attachment; filename="'.$name.'"');
  2101. header("Content-Transfer-Encoding: binary");
  2102. header('Accept-Ranges: bytes');
  2103.  
  2104. /* The three lines below basically make the download non-cacheable */
  2105. header("Cache-control: private");
  2106. header('Pragma: private');
  2107. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  2108.  
  2109. header("Content-Length: ".$size);
  2110. print($data);
  2111.  
  2112. } else {
  2113. wp_die(__('ERROR: You are not authorised to perform that operation', 'graphene'));
  2114. }
  2115.  
  2116. die();
  2117. }
  2118.  
  2119. if (isset($_POST['graphene_export'])){
  2120. add_action('init', 'graphene_export_options');
  2121. }
  2122.  
  2123. /**
  2124. * Shortcode handlers
  2125. */
  2126. function warning_block_shortcode_handler( $atts, $content=null, $code="" ) {
  2127. return '<div class="warning_block">' . $content . '</div>';
  2128. }
  2129. add_shortcode( 'warning', 'warning_block_shortcode_handler' );
  2130.  
  2131. function error_block_shortcode_handler( $atts, $content=null, $code="" ) {
  2132. return '<div class="error_block">' . $content . '</div>';
  2133. }
  2134. add_shortcode( 'error', 'error_block_shortcode_handler' );
  2135.  
  2136. function notice_block_shortcode_handler( $atts, $content=null, $code="" ) {
  2137. return '<div class="notice_block">' . $content . '</div>';
  2138. }
  2139. add_shortcode( 'notice', 'notice_block_shortcode_handler' );
  2140.  
  2141. function important_block_shortcode_handler( $atts, $content=null, $code="" ) {
  2142. return '<div class="important_block">' . $content . '</div>';
  2143. }
  2144. add_shortcode( 'important', 'important_block_shortcode_handler' );
  2145.  
  2146.  
  2147. /**
  2148. * Hook the shortcode buttons to the TinyMCE editor
  2149. */
  2150. class Graphene_Shortcodes_Buttons{
  2151.  
  2152. function Graphene_Shortcodes_Buttons(){
  2153. if ( current_user_can('edit_posts') && current_user_can('edit_pages') ) {
  2154. // add_filter('tiny_mce_version', array(&$this, 'tiny_mce_version'));
  2155. add_filter('mce_external_plugins', array(&$this, 'graphene_add_plugin'));
  2156. add_filter('mce_buttons_2', array(&$this, 'graphene_register_button'));
  2157. }
  2158. }
  2159.  
  2160. function graphene_register_button($buttons){
  2161. array_push($buttons, "separator", "warning", "error", "notice", "important");
  2162. return $buttons;
  2163. }
  2164.  
  2165. function graphene_add_plugin($plugin_array){
  2166. $plugin_array['grapheneshortcodes'] = get_template_directory_uri().'/js/mce-shortcodes.js';
  2167. return $plugin_array;
  2168. }
  2169.  
  2170. /*
  2171. function tiny_mce_version($version) {
  2172. return ++$version;
  2173. }
  2174. */
  2175. }
  2176. add_action('init', 'Graphene_Shortcodes_Buttons');
  2177.  
  2178. function Graphene_Shortcodes_Buttons(){
  2179. global $Graphene_Shortcodes_Buttons;
  2180. $Graphene_Shortcodes_Buttons = new Graphene_Shortcodes_Buttons();
  2181. }
  2182.  
  2183.  
  2184. /**
  2185. * Helps to determine if the comments should be shown.
  2186. */
  2187. if ( ! function_exists( 'graphene_should_show_comments' ) ) :
  2188.  
  2189. function graphene_should_show_comments() {
  2190. global $graphene_settings, $post;
  2191. if ($graphene_settings['comments_setting'] == 'disabled_completely'){
  2192. return false;
  2193. }
  2194. if ($graphene_settings['comments_setting'] == 'disabled_pages' && get_post_type($post) == 'page'){
  2195. return false;
  2196. }
  2197. return true;
  2198. }
  2199.  
  2200. endif;
  2201.  
  2202. /**
  2203. * Add a link to the theme's options page in the admin bar
  2204. */
  2205. function graphene_wp_admin_bar_theme_options(){
  2206. global $wp_admin_bar;
  2207. $wp_admin_bar->add_menu(array(
  2208. 'parent' => 'appearance',
  2209. 'id' => 'graphene-options',
  2210. 'title' => 'Graphene Options',
  2211. 'href' => admin_url('themes.php?page=graphene_options')
  2212. ));
  2213. }
  2214. add_action( 'admin_bar_menu', 'graphene_wp_admin_bar_theme_options', 61 );
  2215.  
  2216.  
  2217. /**
  2218. * Adds the content panes in the homepage. The homepage panes are only displayed if using a static
  2219. * front page, before the comments. It is also recommended that the comments section is disabled
  2220. * for the page used as the static front page.
  2221. */
  2222. function graphene_homepage_panes(){
  2223. global $graphene_settings, $graphene_defaults;
  2224.  
  2225. // Get the number of panes to display
  2226. if ($graphene_settings['show_post_type'] == 'latest-posts' || $graphene_settings['show_post_type'] == 'cat-latest-posts'){
  2227. $pane_count = $graphene_settings['homepage_panes_count'];
  2228. } elseif ($graphene_settings['show_post_type'] == 'posts') {
  2229. $pane_count = count(explode(',', $graphene_settings['homepage_panes_posts']));
  2230. }
  2231.  
  2232. // Build the common get_posts() parameter first
  2233. $args = array(
  2234. 'orderby' => 'date',
  2235. 'order' => 'DESC',
  2236. 'suppress_filters' => 0,
  2237. 'post_type' => array('post', 'page'),
  2238. );
  2239.  
  2240. // args specific to latest posts
  2241. if ($graphene_settings['show_post_type'] == 'latest-posts' ){
  2242. $args_merge = array(
  2243. 'numberposts' => $pane_count,
  2244. 'post_type' => array('post'),
  2245. );
  2246. $args = array_merge($args, $args_merge);
  2247. }
  2248.  
  2249. // args specific to latest posts by category
  2250. if ($graphene_settings['show_post_type'] == 'cat-latest-posts' ){
  2251. $args_merge = array(
  2252. 'numberposts' => $pane_count,
  2253. 'category' => $graphene_settings['homepage_panes_cat'],
  2254. );
  2255. $args = array_merge($args, $args_merge);
  2256. }
  2257.  
  2258. // args specific to posts/pages
  2259. if ($graphene_settings['show_post_type'] == 'posts' ){
  2260.  
  2261. $args_merge = array(
  2262. 'numberposts' => $pane_count,
  2263. 'include' => $graphene_settings['homepage_panes_posts'],
  2264. );
  2265. $args = array_merge($args, $args_merge);
  2266. }
  2267.  
  2268. global $post;
  2269.  
  2270. // Get the posts to display as homepage panes
  2271. $posts = get_posts(apply_filters('graphene_homepage_panes_args', $args));
  2272. ?>
  2273.  
  2274. <div class="homepage_panes">
  2275.  
  2276. <?php foreach ($posts as $post) : setup_postdata($post);
  2277. ?>
  2278. <div class="homepage_pane clearfix">
  2279.  
  2280. <a href="<?php the_permalink(); ?>" title="<?php printf(__('Permalink to %s', 'graphene'), esc_attr(get_the_title())); ?>">
  2281. <?php /* Get the post's image */
  2282. if (has_post_thumbnail($post->ID)) {
  2283. the_post_thumbnail('graphene-homepage-pane');
  2284. } else {
  2285. echo graphene_get_post_image($post->ID, 'graphene-homepage-pane', 'excerpt');
  2286. }
  2287. ?>
  2288. </a>
  2289.  
  2290. <?php /* The post title */ ?>
  2291. <h3 class="post-title"><a href="<?php the_permalink(); ?>" title="<?php printf(__('Permalink to %s', 'graphene'), esc_attr(get_the_title())); ?>"><?php the_title(); ?></a></h3>
  2292.  
  2293. <?php /* The post excerpt */ ?>
  2294. <div class="post-excerpt">
  2295. <?php the_excerpt(); ?>
  2296. </div>
  2297.  
  2298. <?php /* Read more button */ ?>
  2299. <p class="post-comments">
  2300. <a href="<?php the_permalink(); ?>" title="<?php printf(__('Permalink to %s', 'graphene'), esc_attr(get_the_title())); ?>" class="block-button"><?php _e('Read more', 'graphene'); ?></a>
  2301. </p>
  2302. </div>
  2303. <?php endforeach; ?>
  2304. </div>
  2305.  
  2306. <?php
  2307. }
  2308.  
  2309. /* Helper function to control when the homepage panes should be displayed. */
  2310. function graphene_display_homepage_panes(){
  2311. global $graphene_settings;
  2312. if (get_option('show_on_front') == 'page' && !$graphene_settings['disable_homepage_panes'] && is_front_page()) {
  2313. graphene_homepage_panes();
  2314. }
  2315. }
  2316. add_action('graphene_bottom_content', 'graphene_display_homepage_panes');
  2317.  
  2318.  
  2319. /**
  2320. * Improves the WordPress default excerpt output. This function will retain HTML tags inside the excerpt.
  2321. * Based on codes by Aaron Russell at http://www.aaronrussell.co.uk/blog/improving-wordpress-the_excerpt/
  2322. */
  2323. function graphene_improved_excerpt($text){
  2324. global $graphene_settings, $post;
  2325.  
  2326. $raw_excerpt = $text;
  2327. if ( '' == $text ) {
  2328. $text = get_the_content('');
  2329. $text = strip_shortcodes( $text );
  2330. $text = apply_filters('the_content', $text);
  2331. $text = str_replace(']]>', ']]&gt;', $text);
  2332.  
  2333. /* Remove unwanted JS code */
  2334. $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
  2335.  
  2336. /* Strip HTML tags, but allow certain tags */
  2337. $text = strip_tags($text, $graphene_settings['excerpt_html_tags']);
  2338.  
  2339. $excerpt_length = apply_filters('excerpt_length', 55);
  2340. $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
  2341. $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
  2342. if ( count($words) > $excerpt_length ) {
  2343. array_pop($words);
  2344. $text = implode(' ', $words);
  2345. $text = $text . $excerpt_more;
  2346. } else {
  2347. $text = implode(' ', $words);
  2348. }
  2349. }
  2350. return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
  2351. }
  2352.  
  2353. /**
  2354. * Only use the custom excerpt trimming function if user decides to retain html tags.
  2355. */
  2356. if ($graphene_settings['excerpt_html_tags']) {
  2357. remove_filter('get_the_excerpt', 'wp_trim_excerpt');
  2358. add_filter('get_the_excerpt', 'graphene_improved_excerpt');
  2359. }
  2360.  
  2361.  
  2362. /**
  2363. * Add Facebook and Twitter icon to top bar
  2364. */
  2365. function graphene_top_bar_social(){
  2366. global $graphene_settings;
  2367.  
  2368. if ($graphene_settings['twitter_url']) : ?>
  2369. <a href="<?php echo $graphene_settings['twitter_url']; ?>" title="<?php printf(esc_attr__('Follow %s on Twitter', 'graphene'), get_bloginfo('name')); ?>" class="twitter_link"><span><?php printf(esc_attr__('Follow %s on Twitter', 'graphene'), get_bloginfo('name')); ?></span></a>
  2370. <?php endif;
  2371. if ($graphene_settings['facebook_url']) : ?>
  2372. <a href="<?php echo $graphene_settings['facebook_url']; ?>" title="<?php printf(esc_attr__("Visit %s's Facebook page", 'graphene'), get_bloginfo('name')); ?>" class="facebook_link"><span><?php printf(esc_attr__("Visit %s's Facebook page", 'graphene'), get_bloginfo('name')); ?></span></a>
  2373. <?php endif;
  2374.  
  2375. /* Loop through the registered custom social modia */
  2376. $social_media = $graphene_settings['social_media'];
  2377. foreach ($social_media as $slug => $social_medium) : if (!empty($slug) && !empty($social_medium['url'])) : ?>
  2378. <?php /* translators: %1$s is the website's name, %2$s is the social media name */ ?>
  2379. <a href="<?php echo $social_medium['url']; ?>" title="<?php printf(esc_attr__('Visit %1$s\'s %2$s page', 'graphene'), get_bloginfo('name'), $social_medium['name']); ?>" class="<?php echo $slug?>-link" style="background-image:url(<?php echo $social_medium['icon']; ?>)"><span><?php printf(esc_attr__('Visit %1$s\'s %2$s page', 'graphene'), get_bloginfo('name'), $social_medium['name']); ?></span></a>
  2380. <?php endif; endforeach;
  2381. }
  2382. add_action('graphene_feed_icon', 'graphene_top_bar_social');
  2383.  
  2384.  
  2385. /**
  2386. * Add breadcrumbs to the top of the content area. Uses the Breadcrumb NavXT plugin
  2387. */
  2388. if (function_exists('bcn_display')) :
  2389. function graphene_breadcrumb_navxt(){
  2390. echo '<div class="breadcrumb">';
  2391. bcn_display();
  2392. echo '</div>';
  2393. }
  2394. add_action('graphene_top_content', 'graphene_breadcrumb_navxt');
  2395. endif;
  2396.  
  2397.  
  2398. /**
  2399. * Truncate a string by specified length
  2400. */
  2401. if ( ! function_exists( 'graphene_substr' ) ) :
  2402.  
  2403. function graphene_substr( $string, $start = 0, $length = '', $append = '' ){
  2404.  
  2405. if ( $length == '' ) return $string;
  2406.  
  2407. if ( strlen( $string ) > $length ) {
  2408. return substr( $string, $start, $length ) . $append;
  2409. } else {
  2410. return $string;
  2411. }
  2412. }
  2413.  
  2414. endif;
  2415.  
  2416.  
  2417. /**
  2418. * Fix to allow <g:plusone> in the social-sharing button code
  2419. */
  2420. function graphene_plusone_fix( $graphene_settings ){
  2421. return str_replace( 'gplusone', 'g:plusone', $graphene_settings );
  2422. }
  2423. add_filter( 'graphene_settings', 'graphene_plusone_fix' );
  2424. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement