Guest User

functions.php

a guest
May 22nd, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.16 KB | None | 0 0
  1. <?php
  2.  
  3. // Theme Prefix: dcs_
  4.  
  5. /* ========================================= Constants ========================================= */
  6.  
  7. if(!defined('DCS_THEME_DIR')) {
  8. define('DCS_THEME_DIR', dirname(__FILE__));
  9. }
  10.  
  11. /* ========================================= File Includes ========================================= */
  12.  
  13. include(DCS_THEME_DIR . '/includes/scripts.php');
  14.  
  15. /* ========================================= General Things We Need ========================================= */
  16.  
  17. add_editor_style(); // Adds CSS to the editor to match the front end of the site.
  18. add_theme_support('automatic-feed-links');
  19. if ( ! isset( $content_width ) ) $content_width = 590; // This is the max width of the content, thus the max width of large images that are uploaded.
  20. require_once(dirname(__FILE__) . "/includes/support/support.php"); // Load support tab
  21.  
  22. // Load Language File
  23. load_theme_textdomain( 'designcrumbs', TEMPLATEPATH.'/languages' );
  24. $locale = get_locale();
  25. $locale_file = TEMPLATEPATH."/languages/$locale.php";
  26. if ( is_readable($locale_file) )
  27. require_once($locale_file);
  28.  
  29. // Check for Options Framework Plugin
  30. of_check();
  31.  
  32. function of_check()
  33. {
  34. if ( !function_exists('of_get_option') )
  35. {
  36. wp_enqueue_script('thickbox', null, array('jquery')); // Required for the plugin install dialog.
  37. add_action('admin_notices', 'of_check_notice');
  38. }
  39. }
  40.  
  41. // The Admin Notice
  42. function of_check_notice()
  43. {
  44. ?>
  45. <div class='updated fade'>
  46. <p>The <strong>Options Framework plugin</strong> is required for this theme to function properly. <a href="<?php echo network_admin_url('plugin-install.php?tab=plugin-information&plugin=options-framework&TB_iframe=true&width=640&height=517'); ?>" class="thickbox onclick">Install now</a>.</p>
  47. </div>
  48. <?php
  49. }
  50.  
  51. /* =================================== Options Framework =================================== */
  52.  
  53. if ( !function_exists( 'of_get_option' ) ) {
  54. function of_get_option($name, $default = 'false') {
  55.  
  56. $optionsframework_settings = get_option('optionsframework');
  57.  
  58. // Gets the unique option id
  59. $option_name = $optionsframework_settings['id'];
  60.  
  61. if ( get_option($option_name) ) {
  62. $options = get_option($option_name);
  63. }
  64.  
  65. if ( !empty($options[$name]) ) {
  66. return $options[$name];
  67. } else {
  68. return $default;
  69. }
  70. }
  71. }
  72.  
  73. add_action('optionsframework_custom_scripts', 'optionsframework_custom_scripts');
  74.  
  75. function optionsframework_custom_scripts() { ?>
  76.  
  77. <script type="text/javascript">
  78. jQuery(document).ready(function() {
  79.  
  80. // adds support tab
  81. jQuery(".embed-themes").html("<iframe width='770' height='390' src='http://themes.designcrumbs.com/iframe/index.html'></iframe>");
  82.  
  83. // Checks for home page video content
  84. jQuery('#outreach-video_type-none').click(function() {
  85. jQuery('#section-youtube_id').hide();
  86. jQuery('#section-vimeo_id').hide();
  87. jQuery('#section-video_title').hide();
  88. jQuery('#section-video_desc').hide();
  89. });
  90.  
  91. jQuery('#outreach-video_type-youtube').click(function() {
  92. jQuery('#section-vimeo_id').hide();
  93. jQuery('#section-youtube_id').fadeIn(400);
  94. jQuery('#section-video_title').fadeIn(400);
  95. jQuery('#section-video_desc').fadeIn(400);
  96. });
  97.  
  98. jQuery('#outreach-video_type-vimeo').click(function() {
  99. jQuery('#section-youtube_id').hide();
  100. jQuery('#section-vimeo_id').fadeIn(400);
  101. jQuery('#section-video_title').fadeIn(400);
  102. jQuery('#section-video_desc').fadeIn(400);
  103. });
  104.  
  105. if (jQuery('#outreach-video_type-none').is(':checked')) {
  106. jQuery('#section-youtube_id').hide();
  107. jQuery('#section-vimeo_id').hide();
  108. jQuery('#section-video_title').hide();
  109. jQuery('#section-video_desc').hide();
  110. };
  111.  
  112. if (jQuery('#outreach-video_type-youtube').is(':checked')) {
  113. jQuery('#section-vimeo_id').hide();
  114. };
  115.  
  116. if (jQuery('#outreach-video_type-vimeo').is(':checked')) {
  117. jQuery('#section-youtube_id').hide();
  118. };
  119.  
  120. // Checks for home page post cats
  121. jQuery('#outreach-home_posts_selection-posts_specific').click(function() {
  122. jQuery('#section-home_posts_cat').fadeIn(400);
  123. });
  124.  
  125. jQuery('#outreach-home_posts_selection-posts_all').click(function() {
  126. jQuery('#section-home_posts_cat').fadeOut(400);
  127. });
  128.  
  129. if (jQuery('#outreach-home_posts_selection-posts_all').is(':checked')) {
  130. jQuery('#section-home_posts_cat').hide();
  131. };
  132.  
  133. });
  134. </script>
  135.  
  136. <?php
  137. }
  138.  
  139. /* Removes the code stripping */
  140.  
  141. add_action('admin_init','optionscheck_change_santiziation', 100);
  142.  
  143. function optionscheck_change_santiziation() {
  144. remove_filter( 'of_sanitize_textarea', 'of_sanitize_textarea' );
  145. add_filter( 'of_sanitize_textarea', 'of_sanitize_textarea_custom' );
  146. }
  147.  
  148. function of_sanitize_textarea_custom($input) {
  149. global $allowedposttags;
  150. $of_custom_allowedtags["embed"] = array(
  151. "src" => array(),
  152. "type" => array(),
  153. "allowfullscreen" => array(),
  154. "allowscriptaccess" => array(),
  155. "height" => array(),
  156. "width" => array()
  157. );
  158. $of_custom_allowedtags["script"] = array(
  159. "type" => array()
  160. );
  161. $of_custom_allowedtags["iframe"] = array(
  162. "height" => array(),
  163. "width" => array(),
  164. "src" => array(),
  165. "frameborder" => array(),
  166. "allowfullscreen" => array()
  167. );
  168. $of_custom_allowedtags["object"] = array(
  169. "height" => array(),
  170. "width" => array()
  171. );
  172. $of_custom_allowedtags["param"] = array(
  173. "name" => array(),
  174. "value" => array()
  175. );
  176.  
  177. $of_custom_allowedtags = array_merge($of_custom_allowedtags, $allowedposttags);
  178. $output = wp_kses( $input, $of_custom_allowedtags);
  179. return $output;
  180. }
  181.  
  182. /* =================================== Add Fancybox to linked Images =================================== */
  183.  
  184. /**
  185. * Attach a class to linked images' parent anchors
  186. * e.g. a img => a.img img
  187. */
  188. function dcs_give_linked_images_class($html, $id, $caption, $title, $align, $url, $size, $alt = '' ){
  189. $classes = 'lightbox'; // separated by spaces, e.g. 'img image-link'
  190.  
  191. // check if there are already classes assigned to the anchor
  192. if ( preg_match('/<a.*? class=".*?">/', $html) ) {
  193. $html = preg_replace('/(<a.*? class=".*?)(".*?>)/', '$1 ' . $classes . '$2', $html);
  194. } else {
  195. $html = preg_replace('/(<a.*?)>/', '$1 class="' . $classes . '" >', $html);
  196. }
  197. return $html;
  198. }
  199. add_filter('image_send_to_editor','dcs_give_linked_images_class',10,8);
  200.  
  201. /* =================================== Add Menus =================================== */
  202. add_theme_support( 'menus' );
  203.  
  204. register_nav_menus( array(
  205. 'primary' => __( 'Header Menu', 'designcrumbs' ),
  206. 'secondary' => __( 'Footer Menu', 'designcrumbs' )
  207. ) );
  208.  
  209. /* ========================================= Featured Images ========================================= */
  210.  
  211. add_theme_support( 'post-thumbnails', array( 'post', 'slides' ) ); /* ===== ADDS FEATURED IMAGE TO PAGES ===== */
  212. add_image_size( 'blog_image', 1200, 800, true ); /* ===== SETS FEATURED IMAGE SIZE ===== */
  213. add_image_size( 'slide_image', 1480, 604, true ); /* ===== SETS FEATURED IMAGE SIZE ===== */
  214. add_image_size( 'single_latest', 540, 390, true ); /* ===== SETS FEATURED IMAGE SIZE ===== */
  215.  
  216. /* =================================== Add Slides Post Type =================================== */
  217.  
  218. register_post_type('slides', array(
  219. 'label' => __('Slides', 'designcrumbs'),
  220. 'singular_label' => __('Slide', 'designcrumbs'),
  221. 'public' => true,
  222. 'show_ui' => true, // UI in admin panel
  223. '_builtin' => false, // It's a custom post type, not built in!
  224. '_edit_link' => 'post.php?post=%d',
  225. 'capability_type' => 'post',
  226. 'hierarchical' => false,
  227. 'has_archive' => false,
  228. 'supports' => array(
  229. 'title',
  230. 'thumbnail',)
  231. ));
  232.  
  233. /* ====================================================== Slide Meta Box ====================================================== */
  234.  
  235. add_filter( 'cmb_meta_boxes', 'dcs_metaboxes' );
  236. function dcs_metaboxes( array $meta_boxes ) {
  237.  
  238. $prefix = '_dc_';
  239.  
  240. $meta_boxes[] = array(
  241. 'id' => 'dc_slides_info',
  242. 'title' => __('Slide Contents (optional)', 'designcrumbs'),
  243. 'pages' => array('slides'), // post type
  244. 'context' => 'normal',
  245. 'priority' => 'high',
  246. 'show_names' => true, // Show field names on the left
  247. 'fields' => array(
  248. array(
  249. 'name' => __('Slide Text', 'designcrumbs'),
  250. 'desc' => __('Enter text to be overlaid on the bottom of the slide image. Optional.', 'designcrumbs'),
  251. 'id' => $prefix . 'slide_text',
  252. 'type' => 'text'
  253. ),
  254. array(
  255. 'name' => __('Link', 'designcrumbs'),
  256. 'desc' => __('Enter a link (including the http://) if you would like the slide to link to somewhere. Optional.', 'designcrumbs'),
  257. 'id' => $prefix . 'slide_link',
  258. 'type' => 'text'
  259. ),
  260. )
  261. );
  262. $meta_boxes[] = array(
  263. 'id' => 'dc_media',
  264. 'title' => __('Video Embeds', 'designcrumbs'),
  265. 'pages' => array('post'), // post type
  266. 'context' => 'normal',
  267. 'priority' => 'high',
  268. 'show_names' => true, // Show field names on the left
  269. 'fields' => array(
  270. array(
  271. 'name' => __('YouTube Video ID', 'designcrumbs'),
  272. 'desc' => __('If the YouTube link is http://www.youtube.com/watch?v=Iv69kB_e9KY, the ID is Iv69kB_e9KY. Enter that ID above.', 'designcrumbs'),
  273. 'id' => $prefix . 'media_youtube',
  274. 'type' => 'text'
  275. ),
  276. array(
  277. 'name' => __('Vimeo Video ID', 'designcrumbs'),
  278. 'desc' => __('If the Vimeo link is http://vimeo.com/22639018, the ID is 22639018. Enter that ID above.', 'designcrumbs'),
  279. 'id' => $prefix . 'media_vimeo',
  280. 'type' => 'text'
  281. ),
  282. )
  283. );
  284.  
  285. return $meta_boxes;
  286. }
  287.  
  288. add_action( 'init', 'dcs_initialize_cmb_meta_boxes', 9999 );
  289. function dcs_initialize_cmb_meta_boxes() {
  290.  
  291. if ( ! class_exists( 'cmb_Meta_Box' ) )
  292. require_once 'lib/metabox/init.php';
  293.  
  294. }
  295.  
  296. /* =================================== The Excerpt =================================== */
  297.  
  298. function dcs_improved_trim_excerpt($text) {
  299. global $post;
  300. if ( '' == $text ) {
  301. $text = get_the_content('');
  302. $text = apply_filters('the_content', $text);
  303. $text = str_replace('\]\]\>', ']]&gt;', $text);
  304. $text = strip_tags($text, '<p>');
  305. $excerpt_length = 85;
  306. $words = explode(' ', $text, $excerpt_length + 1);
  307. if (count($words)> $excerpt_length) {
  308. array_pop($words);
  309. array_push($words, '...');
  310. $text = implode(' ', $words);
  311. }
  312. }
  313. return $text;
  314. }
  315.  
  316. remove_filter('get_the_excerpt', 'wp_trim_excerpt');
  317. add_filter('get_the_excerpt', 'dcs_improved_trim_excerpt');
  318.  
  319. /* =================================== Count How Many Widgets are in a Sidebar =================================== */
  320.  
  321. function count_sidebar_widgets( $sidebar_id, $echo = true ) {
  322. $the_sidebars = wp_get_sidebars_widgets();
  323. if( !isset( $the_sidebars[$sidebar_id] ) )
  324. return __( 'Invalid sidebar ID', 'designcrumbs' );
  325. if( $echo )
  326. echo count( $the_sidebars[$sidebar_id] );
  327. else
  328. return count( $the_sidebars[$sidebar_id] );
  329. }
  330.  
  331. // To call it on the front end - count_sidebar_widgets( 'some-sidebar-id' );
  332.  
  333. /* ========================================= Checks for subcategories for the archives ========================================= */
  334.  
  335. // If is category or subcategory of $cat_id
  336. if (!function_exists('is_category_or_sub')) {
  337. function is_category_or_sub($cat_id = 0) {
  338. foreach (get_the_category() as $cat) {
  339. if ($cat_id == $cat->cat_ID || cat_is_ancestor_of($cat_id, $cat)) return true;
  340. }
  341. return false;
  342. }
  343. }
  344.  
  345. /* ========================================= Sidebars ========================================= */
  346.  
  347. if ( function_exists('register_sidebars') )
  348. register_sidebar(array(
  349. 'name' => 'Overall_Sidebar',
  350. 'id' => 'Overall_Sidebar',
  351. 'description' => __('These widgets will show up on every page and post, including to the side of the home page.', 'designcrumbs'),
  352. 'before_widget' => '<div class="widget">',
  353. 'after_widget' => '</div>',
  354. 'before_title' => '<h4 class="widgettitle">',
  355. 'after_title' => '</h4>'
  356. ));
  357. register_sidebar(array(
  358. 'name' => 'Pages_Sidebar',
  359. 'id' => 'Pages_Sidebar',
  360. 'description' => __('These widgets will show up only on all pages, except the home page.', 'designcrumbs'),
  361. 'before_widget' => '<div class="widget">',
  362. 'after_widget' => '</div>',
  363. 'before_title' => '<h4 class="widgettitle">',
  364. 'after_title' => '</h4>'
  365. ));
  366. register_sidebar(array(
  367. 'name' => 'Blog_Sidebar',
  368. 'id' => 'Blog_Sidebar',
  369. 'description' => __('These widgets will show up in the blog and on blog posts.', 'designcrumbs'),
  370. 'before_widget' => '<div class="widget">',
  371. 'after_widget' => '</div>',
  372. 'before_title' => '<h4 class="widgettitle">',
  373. 'after_title' => '</h4>'
  374. ));
  375. register_sidebar(array(
  376. 'name' => 'Home_Page_Banner',
  377. 'id' => 'Home_Page_Banner',
  378. 'description' => __('These widgets show up in the banner just below the slider. I recomend a text widget first, and then the WP Email Capture widget second as there is specific styling for the combination.', 'designcrumbs'),
  379. 'before_widget' => '<div class="widget">',
  380. 'after_widget' => '</div>',
  381. 'before_title' => '<h3 class="widgettitle">',
  382. 'after_title' => '</h3>'
  383. ));
  384. register_sidebar(array(
  385. 'name' => 'Top_Sidebar',
  386. 'id' => 'Top_Sidebar',
  387. 'description' => __('These widgets will show up everywhere except the home page. You can place the WP Email Capture widget here in addition to the Home Page Banner.', 'designcrumbs'),
  388. 'before_widget' => '<div class="widget">',
  389. 'after_widget' => '</div>',
  390. 'before_title' => '<h4 class="widgettitle">',
  391. 'after_title' => '</h4>'
  392. ));
  393. register_sidebar(array(
  394. 'name' => 'Footer',
  395. 'id' => 'Footer',
  396. 'description' => __('These widgets will appear in the footer.', 'designcrumbs'),
  397. 'before_widget' => '<div class="footer_widget">',
  398. 'after_widget' => '</div>',
  399. 'before_title' => '<h6 class="widgettitle">',
  400. 'after_title' => '</h6>'
  401. ));
  402.  
  403.  
  404. /* =================================== User Extras =================================== */
  405.  
  406. add_action( 'show_user_profile', 'dcs_show_extra_profile_fields' );
  407. add_action( 'edit_user_profile', 'dcs_show_extra_profile_fields' );
  408.  
  409. function dcs_show_extra_profile_fields( $user ) { ?>
  410.  
  411. <h3><?php _e('Extra profile information', 'designcrumbs') ?></h3>
  412.  
  413. <table class="form-table">
  414.  
  415. <tr>
  416. <th><label for="twitter"><?php _e('Twitter', 'designcrumbs') ?></label></th>
  417.  
  418. <td>
  419. <input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
  420. <span class="description"><?php _e('Please enter your Twitter username without the @.', 'designcrumbs') ?></span>
  421. </td>
  422. </tr>
  423.  
  424. </table>
  425. <?php }
  426.  
  427. add_action( 'personal_options_update', 'dcs_save_extra_profile_fields' );
  428. add_action( 'edit_user_profile_update', 'dcs_save_extra_profile_fields' );
  429.  
  430. function dcs_save_extra_profile_fields( $user_id ) {
  431.  
  432. if ( !current_user_can( 'edit_user', $user_id ) )
  433. return false;
  434.  
  435. update_user_meta( $user_id, 'twitter', $_POST['twitter'] );
  436. }
  437.  
  438. function dcs_author_box() { ?>
  439. <div class="about_the_author">
  440. <?php echo get_avatar( get_the_author_meta('email'), '70' ); ?>
  441. <div class="author_info">
  442. <div class="author_title"><?php _e('This post was written by', 'designcrumbs') ?> <?php the_author_posts_link(); ?>
  443. </div>
  444. <div class="author_about">
  445. <?php the_author_meta( 'description' ); ?>
  446. </div>
  447. <?php if (get_the_author_meta('twitter') != '' || get_the_author_meta('url') != '' ) { ?>
  448. <div class="author_links">
  449. <?php if (get_the_author_meta('twitter') != '' ) { ?>
  450. <a href="http://twitter.com/<?php the_author_meta('twitter'); ?>" title="Follow <?php the_author_meta( 'display_name' ); ?> on Twitter"><?php _e('My Twitter', 'designcrumbs') ?> &raquo;</a>
  451. <?php } if (get_the_author_meta('url') != '' ) { ?>
  452. <a href="<?php the_author_meta('url'); ?>" title="My Website"><?php _e('My Website', 'designcrumbs') ?> &raquo;</a>
  453. <?php } ?>
  454. <div class="clear"></div>
  455. </div>
  456. <?php } // End check for twitter & url ?>
  457. </div>
  458. <div class="clear"></div>
  459. </div>
  460. <?php
  461. }
  462.  
  463. /* =================================== Specific User Widget =================================== */
  464.  
  465. class dcs_featured_user_widget extends WP_Widget {
  466.  
  467. //function to set up widget in admin
  468. function dcs_featured_user_widget() {
  469.  
  470. $widget_ops = array( 'classname' => 'featured-user',
  471. 'description' => __('A widget that will display a specified user&#39;s gravatar, display name, bio, and link to their author post archive.', 'designcrumbs') );
  472.  
  473. $control_ops = array( 'width' => 200, 'height' => 350, 'id_base' => 'featured-user' );
  474. $this->WP_Widget( 'featured-user', __('Featured User', 'designcrumbs'), $widget_ops, $control_ops );
  475.  
  476. }
  477.  
  478.  
  479. //function to echo out widget on sidebar
  480. function widget( $args, $instance ) {
  481. extract( $args );
  482.  
  483. $title = $instance['title'];
  484.  
  485. echo $before_widget;
  486. echo "<div class='featured_user'>";
  487.  
  488. // if user written title echo out
  489. if ( $title ){
  490. echo $before_title . $title . $after_title;
  491. }
  492. //don't touch this!
  493. $userid = $instance['user_id'];
  494.  
  495. //user information array
  496. //refer to http://codex.wordpress.org/Function_Reference/get_userdata
  497. $userinfo = get_userdata($userid);
  498.  
  499. //user meta data
  500. //refer to http://codex.wordpress.org/Function_Reference/get_user_meta
  501. $userbio = get_user_meta($userid,'description',true);
  502.  
  503. //user post url
  504. //refer to http://codex.wordpress.org/Function_Reference/get_author_posts_url
  505. $userposturl = get_author_posts_url($userid);
  506.  
  507. ?>
  508.  
  509. <!--Now we print out speciifc user informations to screen!-->
  510. <div class='specific_user'>
  511. <a href='<?php echo $userposturl; ?>' title='<?php echo $userinfo->display_name; ?>'>
  512. <?php echo get_avatar($userid,58); ?>
  513. </a>
  514. <strong>
  515. <a href='<?php echo $userposturl; ?>' title='<?php echo $userinfo->display_name; ?>' class='featured_user_name'>
  516. <?php echo $userinfo->display_name; ?>
  517. </a></strong>
  518. <?php echo $userbio; ?>
  519. <?php/* <a href='<?php echo $userposturl; ?>' title='<?php echo $userinfo->display_name; ?>'>
  520. View Author's Posts &raquo;
  521. </a> */ ?>
  522. <div class="clear"></div>
  523. </div>
  524. <!--end-->
  525.  
  526. <?php
  527.  
  528. echo '</div>';
  529. echo $after_widget;
  530.  
  531. }//end of function widget
  532.  
  533.  
  534.  
  535. //function to update widget setting
  536. function update( $new_instance, $old_instance ) {
  537.  
  538. $instance = $old_instance;
  539. $instance['title'] = strip_tags( $new_instance['title'] );
  540. $instance['user_id'] = strip_tags( $new_instance['user_id'] );
  541. return $instance;
  542.  
  543. }//end of function update
  544.  
  545.  
  546. //function to create Widget Admin form
  547. function form($instance) {
  548.  
  549. $instance = wp_parse_args( (array) $instance, array( 'title' => '','user_id' => '') );
  550.  
  551. $instance['title'] = $instance['title'];
  552. $instance['user_id'] = $instance['user_id'];
  553.  
  554. ?>
  555.  
  556. <p>
  557. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title:', 'designcrumbs') ?></label>
  558. <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>"
  559. type="text" value="<?php echo $instance['title']; ?>" />
  560. </p>
  561.  
  562. <p>
  563. <label for="<?php echo $this->get_field_id( 'user_id' ); ?>"><?php _e('Select User:', 'designcrumbs') ?></label>
  564. <select id="<?php echo $this->get_field_id( 'user_id' );?>" name="<?php echo $this->get_field_name( 'user_id' );?>" class="widefat" style="width:100%;">
  565.  
  566. <?php
  567. $instance = $instance['user_id'];
  568. $option_list = user_get_users_list_option($instance);
  569. echo $option_list;
  570. ?>
  571. </select>
  572.  
  573. </p>
  574.  
  575.  
  576. <?php
  577.  
  578. }//end of function form($instance)
  579.  
  580. }//end of Class
  581.  
  582. //function to get all users
  583. function user_get_users_list_option($instance){
  584. $output = '';
  585. global $wpdb;
  586. $users = $wpdb->get_results("SELECT display_name, ID FROM $wpdb->users");
  587. foreach($users as $u){
  588. $uname = $u->display_name;
  589. $uid = $u->ID;
  590. $output .="<option value='$uid'";
  591. if($instance == $uid){
  592. $output.= 'selected="selected"';
  593. }
  594. $output.= ">$uname</option>";
  595. }
  596. return $output;
  597. }
  598.  
  599. register_widget('dcs_featured_user_widget');
  600.  
  601. /* =================================== Testimonial Widget =================================== */
  602.  
  603. class dcs_TestimonialWidget extends WP_Widget
  604. {
  605. /**
  606. * Declares the dcs_TestimonialWidget class.
  607. *
  608. */
  609. function dcs_TestimonialWidget(){
  610. $widget_ops = array('classname' => 'widget_testimonial', 'description' => __('Displays a testimonial along with a name, company, and URL.', 'designcrumbs') );
  611. $control_ops = array('width' => 300, 'height' => 300);
  612. $this->WP_Widget('testimonial', __('Testimonial', 'designcrumbs'), $widget_ops, $control_ops);
  613. }
  614.  
  615. /**
  616. * Displays the Widget
  617. *
  618. */
  619. function widget($args, $instance){
  620. extract($args);
  621. $testi_title = apply_filters('widget_title', empty($instance['testi_title']) ? '' : $instance['testi_title']);
  622. $testi_name = empty($instance['testi_name']) ? '' : $instance['testi_name'];
  623. $testi_company = empty($instance['testi_company']) ? '' : $instance['testi_company'];
  624. $testi_url = empty($instance['testi_url']) ? '' : $instance['testi_url'];
  625. $testi_testimonial = empty($instance['testi_testimonial']) ? '' : $instance['testi_testimonial'];
  626.  
  627. # Before the widget
  628. echo '<div class="widget_testimonial widget">';
  629.  
  630. # The title
  631. if ( $testi_title )
  632. echo $before_title . $testi_title . $after_title;
  633. echo '<div class="the_testimonial">'.$testi_testimonial . '</div>';
  634. echo '<div class="the_testimonial_author">';
  635. echo '<strong>- ' . $testi_name . '</strong>';
  636. if ( $testi_url ) {
  637. echo '<span><a href="'.$testi_url.'" title="'.$testi_company.'">' . $testi_company . '</a></span>';
  638. } else {
  639. echo '<span>' . $testi_company .'</span>';}
  640. echo '</div>';
  641. echo '<div class="clear"></div>';
  642.  
  643. # After the widget
  644. echo '</div>';
  645. }
  646.  
  647. /**
  648. * Saves the widgets settings.
  649. *
  650. */
  651. function update($new_instance, $old_instance){
  652. $instance = $old_instance;
  653. $instance['testi_title'] = strip_tags(stripslashes($new_instance['testi_title']));
  654. $instance['testi_name'] = strip_tags(stripslashes($new_instance['testi_name']));
  655. $instance['testi_company'] = strip_tags(stripslashes($new_instance['testi_company']));
  656. $instance['testi_url'] = strip_tags(stripslashes($new_instance['testi_url']));
  657. $instance['testi_testimonial'] = strip_tags(stripslashes($new_instance['testi_testimonial']));
  658.  
  659. return $instance;
  660. }
  661.  
  662. /**
  663. * Creates the edit form for the widget.
  664. *
  665. */
  666. function form($instance){
  667. //Defaults
  668.  
  669. $testi_title = htmlspecialchars($instance['testi_title']);
  670. $testi_name = htmlspecialchars($instance['testi_name']);
  671. $testi_company = htmlspecialchars($instance['testi_company']);
  672. $testi_url = htmlspecialchars($instance['testi_url']);
  673. $testi_testimonial = htmlspecialchars($instance['testi_testimonial']);
  674.  
  675. //output
  676. # Title
  677. echo '<p><label for="' . $this->get_field_name('testi_title') . '">' . __('Title (Optional):', 'designcrumbs') . '</label><input class="widefat" id="' . $this->get_field_id('testi_title') . '" name="' . $this->get_field_name('testi_title') . '" type="text" value="' . $testi_title . '" /></p>';
  678. # Name
  679. echo '<p><label for="' . $this->get_field_name('testi_name') . '">' . __('Name:', 'designcrumbs') . '</label><input class="widefat" id="' . $this->get_field_id('testi_name') . '" name="' . $this->get_field_name('testi_name') . '" type="text" value="' . $testi_name . '" /></p>';
  680. # Company
  681. echo '<p><label for="' . $this->get_field_name('testi_company') . '">' . __('Company:', 'designcrumbs') . '</label><input class="widefat" id="' . $this->get_field_id('testi_company') . '" name="' . $this->get_field_name('testi_company') . '" type="text" value="' . $testi_company . '" /></p>';
  682. # URL
  683. echo '<p><label for="' . $this->get_field_name('testi_url') . '">' . __('URL:', 'designcrumbs') . '</label><input class="widefat" id="' . $this->get_field_id('testi_url') . '" name="' . $this->get_field_name('testi_url') . '" type="text" value="' . $testi_url . '" /></p>';
  684. # Testimonial
  685. echo '<p><label for="' . $this->get_field_name('testi_testimonial') . '">' . __('The Testimonial:', 'designcrumbs') . '</label><textarea class="widefat" id="' . $this->get_field_id('testi_testimonial') . '" cols="20" rows="6" value="' . $testi_testimonial . '" name="' . $this->get_field_name('testi_testimonial') . '">' . $testi_testimonial . '</textarea></p>';
  686. }
  687.  
  688. }// END class
  689.  
  690. function dcs_TestimonialInit() {
  691. register_widget('dcs_TestimonialWidget');
  692. }
  693. add_action('widgets_init', 'dcs_TestimonialInit');
  694.  
  695. /* =================================== Text with a Button Widget =================================== */
  696.  
  697. class dcs_TextButtonWidget extends WP_Widget
  698. {
  699. /**
  700. * Declares the dcs_TextButtonWidget class.
  701. *
  702. */
  703. function dcs_TextButtonWidget(){
  704. $widget_ops = array('classname' => 'widget_text_button', 'description' => __('Arbitrary text or HTML along with a button.', 'designcrumbs') );
  705. $control_ops = array('width' => 300, 'height' => 300);
  706. $this->WP_Widget('text_button', __('Text with a Button', 'designcrumbs'), $widget_ops, $control_ops);
  707. }
  708.  
  709. /**
  710. * Displays the Widget
  711. *
  712. */
  713. function widget($args, $instance){
  714. extract($args);
  715. $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
  716. $the_button_text = empty($instance['the_button_text']) ? '' : $instance['the_button_text'];
  717. $the_button_link = empty($instance['the_button_link']) ? '' : $instance['the_button_link'];
  718. $button_type = empty($instance['button_type']) ? 'button' : $instance['button_type'];
  719. $the_message = empty($instance['the_message']) ? '' : $instance['the_message'];
  720.  
  721. # Before the widget
  722. echo $before_widget;
  723.  
  724. # The title
  725. if ( $title )
  726. echo $before_title . $title . $after_title;
  727.  
  728. echo '<div>' . $the_message . '</div><a href="' . $the_button_link . '" class="' . $button_type . '">' . $the_button_text . '</a>';
  729.  
  730. # After the widget
  731. echo $after_widget;
  732. }
  733.  
  734. /**
  735. * Saves the widgets settings.
  736. *
  737. */
  738. function update($new_instance, $old_instance){
  739. $instance = $old_instance;
  740. $instance['title'] = strip_tags(stripslashes($new_instance['title']));
  741. $instance['the_button_text'] = strip_tags(stripslashes($new_instance['the_button_text']));
  742. $instance['the_button_link'] = strip_tags(stripslashes($new_instance['the_button_link']));
  743. $instance['button_type'] = strip_tags(stripslashes($new_instance['button_type']));
  744. $instance['the_message'] = strip_tags(stripslashes($new_instance['the_message']));
  745.  
  746. return $instance;
  747. }
  748.  
  749. /**
  750. * Creates the edit form for the widget.
  751. *
  752. */
  753. function form($instance){
  754. //Defaults
  755.  
  756. $title = htmlspecialchars($instance['title']);
  757. $the_button_text = htmlspecialchars($instance['the_button_text']);
  758. $the_button_link = htmlspecialchars($instance['the_button_link']);
  759. $button_type = htmlspecialchars($instance['button_type']);
  760. $the_message = htmlspecialchars($instance['the_message']);
  761.  
  762. //output
  763. # Title
  764. echo '<label for="' . $this->get_field_name('title') . '">' . __('Title:', 'designcrumbs') . '</label><input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" />';
  765. # Message
  766. echo '<label for="' . $this->get_field_name('the_message') . '">' . __('The Message:', 'designcrumbs') . '</label><textarea class="widefat" id="' . $this->get_field_id('the_message') . '" cols="20" rows="6" value="' . $the_message . '" name="' . $this->get_field_name('the_message') . '">' . $the_message . '</textarea>';
  767. # Button Text
  768. echo '<label for="' . $this->get_field_name('the_button_text') . '">' . __('Button Text:', 'designcrumbs') . '</label><input class="widefat" id="' . $this->get_field_id('the_button_text') . '" name="' . $this->get_field_name('the_button_text') . '" type="text" value="' . $the_button_text . '" />';
  769. # Button Link
  770. echo '<label for="' . $this->get_field_name('the_button_link') . '">' . __('Button Link (including http):', 'designcrumbs') . '</label><input class="widefat" id="' . $this->get_field_id('the_button_link') . '" name="' . $this->get_field_name('the_button_link') . '" type="text" value="' . $the_button_link . '" />';
  771. # Button Type
  772. echo '<label for="' . $this->get_field_name('button_type') . '">' . __('Button Color:', 'designcrumbs') . '</label><select class="widefat" id="' . $this->get_field_id('button_type') . '" name="' . $this->get_field_name('button_type') . '"><option value="button button_blue" '. ( ($button_type == "button button_blue") ? "selected='selected'" : "") .'>' . __('Blue', 'designcrumbs') . '</option><option value="button button_red" '. ( ($button_type == "button button_red") ? "selected='selected'" : "") .'>' . __('Red', 'designcrumbs') . '</option><option value="button button_gray" '. ( ($button_type == "button button_gray") ? "selected='selected'" : "") .'>' . __('Gray', 'designcrumbs') . '</option><option value="button button_yellow" '. ( ($button_type == "button button_yellow") ? "selected='selected'" : "") .'>' . __('Yellow', 'designcrumbs') . '</option><option value="button button_orange" '. ( ($button_type == "button button_orange") ? "selected='selected'" : "") .'>' . __('Orange', 'designcrumbs') . '</option><option value="button button_green" '. ( ($button_type == "button button_green") ? "selected='selected'" : "") .'>' . __('Green', 'designcrumbs') . '</option><option value="button button_purple" '. ( ($button_type == "button button_purple") ? "selected='selected'" : "") .'>' . __('Purple', 'designcrumbs') . '</option></select>';
  773.  
  774.  
  775. }
  776.  
  777. }// END class
  778.  
  779. function dcs_TextButtonInit() {
  780. register_widget('dcs_TextButtonWidget');
  781. }
  782. add_action('widgets_init', 'dcs_TextButtonInit');
  783.  
  784. /* =================================== SlabText Widget =================================== */
  785.  
  786. class dcs_SlabTextWidget extends WP_Widget
  787. {
  788. /**
  789. * Declares the dcs_SlabTextWidget class.
  790. *
  791. */
  792. function dcs_SlabTextWidget(){
  793. $widget_ops = array('classname' => 'widget_slabtext', 'description' => __('Text headline that forms the area it&#39;s in to make some cool typography.', 'designcrumbs') );
  794. $control_ops = array('width' => 300, 'height' => 300);
  795. $this->WP_Widget('slabtext', __('Slab Text', 'designcrumbs'), $widget_ops, $control_ops);
  796. }
  797.  
  798. /**
  799. * Displays the Widget
  800. *
  801. */
  802. function widget($args, $instance){
  803. extract($args);
  804. $line1 = empty($instance['line1']) ? '' : $instance['line1'];
  805. $line2 = empty($instance['line2']) ? '' : $instance['line2'];
  806. $line3 = empty($instance['line3']) ? '' : $instance['line3'];
  807. $line4 = empty($instance['line4']) ? '' : $instance['line4'];
  808. $line5 = empty($instance['line5']) ? '' : $instance['line5'];
  809.  
  810. # Before the widget
  811. echo $before_widget;
  812.  
  813. echo '<div class="slabload">
  814. <div class="slabwrap">
  815. <h1 class="slabtextdone">
  816. <span class="slabtext">'. strtoupper($line1) .'</span>
  817. <span class="slabtext">'. strtoupper($line2) .'</span>
  818. <span class="slabtext">'. strtoupper($line3) .'</span>
  819. <span class="slabtext">'. strtoupper($line4) .'</span>
  820. <span class="slabtext">'. strtoupper($line5) .'</span>
  821. </h1>
  822. </div>
  823. </div>';
  824.  
  825. # After the widget
  826. echo $after_widget;
  827. }
  828.  
  829. /**
  830. * Saves the widgets settings.
  831. *
  832. */
  833. function update($new_instance, $old_instance){
  834. $instance = $old_instance;
  835. $instance['line1'] = strip_tags(stripslashes($new_instance['line1']));
  836. $instance['line2'] = strip_tags(stripslashes($new_instance['line2']));
  837. $instance['line3'] = strip_tags(stripslashes($new_instance['line3']));
  838. $instance['line4'] = strip_tags(stripslashes($new_instance['line4']));
  839. $instance['line5'] = strip_tags(stripslashes($new_instance['line5']));
  840.  
  841. return $instance;
  842. }
  843.  
  844. /**
  845. * Creates the edit form for the widget.
  846. *
  847. */
  848. function form($instance){
  849. //Defaults
  850.  
  851. $line1 = htmlspecialchars($instance['line1']);
  852. $line2 = htmlspecialchars($instance['line2']);
  853. $line3 = htmlspecialchars($instance['line3']);
  854. $line4 = htmlspecialchars($instance['line4']);
  855. $line5 = htmlspecialchars($instance['line5']);
  856.  
  857. //output
  858. # Line1
  859. echo '<label for="' . $this->get_field_name('line1') . '">' . __('Line 1:', 'designcrumbs') . '</label><input class="widefat" id="' . $this->get_field_id('line1') . '" name="' . $this->get_field_name('line1') . '" type="text" value="' . $line1 . '" />';
  860. # Line2
  861. echo '<label for="' . $this->get_field_name('line2') . '">' . __('Line 2:', 'designcrumbs') . '</label><input class="widefat" id="' . $this->get_field_id('line2') . '" name="' . $this->get_field_name('line2') . '" type="text" value="' . $line2 . '" />';
  862. # Line3
  863. echo '<label for="' . $this->get_field_name('line3') . '">' . __('Line 3:', 'designcrumbs') . '</label><input class="widefat" id="' . $this->get_field_id('line3') . '" name="' . $this->get_field_name('line3') . '" type="text" value="' . $line3 . '" />';
  864. # Line4
  865. echo '<label for="' . $this->get_field_name('line4') . '">' . __('Line 4:', 'designcrumbs') . '</label><input class="widefat" id="' . $this->get_field_id('line4') . '" name="' . $this->get_field_name('line4') . '" type="text" value="' . $line4 . '" />';
  866. # Line5
  867. echo '<label for="' . $this->get_field_name('line5') . '">' . __('Line 5:', 'designcrumbs') . '</label><input class="widefat" id="' . $this->get_field_id('line5') . '" name="' . $this->get_field_name('line5') . '" type="text" value="' . $line5 . '" />';
  868. }
  869.  
  870. }// END class
  871.  
  872. function dcs_SlabTextWidget() {
  873. register_widget('dcs_SlabTextWidget');
  874. }
  875. add_action('widgets_init', 'dcs_SlabTextWidget');
  876.  
  877. /* ====================================================== COMMENTS ====================================================== */
  878.  
  879. function custom_comment($comment, $args, $depth) {
  880. $GLOBALS['comment'] = $comment; ?>
  881. <li <?php comment_class(); ?> id="comment-<?php comment_ID( ); ?>">
  882. <div class="the_comment">
  883. <?php if(function_exists('get_avatar')) { echo get_avatar($comment, '50'); } ?>
  884. <div class="the_comment_author"><strong><?php comment_author_link() ?></strong> <?php _e('says', 'designcrumbs'); ?></div>
  885. <?php if ($comment->comment_approved == '0') : //message if comment is held for moderation ?>
  886. <br><em><?php _e('Your comment is awaiting moderation', 'designcrumbs'); ?>.</em><br>
  887. <?php endif; ?>
  888. <div class="the_comment_text"><?php comment_text() ?></div>
  889. <small class="commentmetadata">
  890. <?php comment_date('F d, Y') ?> <?php _e('at', 'designcrumbs'); ?> <?php comment_date('g:i a') ?>
  891. </small>
  892. <div class="reply">
  893. <?php edit_comment_link( __('Edit', 'designcrumbs'),'',' &nbsp;|&nbsp; '); ?><?php echo comment_reply_link(array('reply_text' => __('Reply', 'designcrumbs'), 'depth' => $depth, 'max_depth' => $args['max_depth'])); ?>
  894. </div>
  895. <div class="clear"></div>
  896. </div>
  897. <?php } ?>
  898. <?php function custom_pings($comment, $args, $depth) {
  899. $GLOBALS['comment'] = $comment; ?>
  900. <li <?php comment_class(); ?> id="comment-<?php comment_ID( ); ?>">
  901. <?php _e('Trackback from', 'designcrumbs'); ?> <em><?php comment_author_link() ?></em>
  902. <br /><small><?php comment_date('l, j F, Y') ?></small>
  903. <br /><?php comment_text() ?>
  904. <?php edit_comment_link( __('Edit', 'designcrumbs'),'<br /> &nbsp;|&nbsp; ',''); ?>
  905. <?php } ?>
  906. <?php
  907. add_filter('get_comments_number', 'comment_count', 0);
  908. function comment_count( $count ) {
  909. global $id;
  910. $comments_by_type = &separate_comments(get_comments('post_id=' . $id));
  911. return count($comments_by_type['comment']);
  912. }
  913.  
  914. /* ====================================================== PRESSTRENDS ====================================================== */
  915. if (of_get_option('presstrends') == 'optin') {
  916. function presstrends() {
  917.  
  918. // PressTrends Account API Key
  919. $api_key = '1x4ox5f40ysz73fsqt9x0npg9a2dswj0164d';
  920.  
  921. // Start of Metrics
  922. global $wpdb;
  923. $data = get_transient( 'presstrends_data' );
  924. if (!$data || $data == ''){
  925. $api_base = 'http://api.presstrends.io/index.php/api/sites/update/api/';
  926. $url = $api_base . $api_key . '/';
  927. $data = array();
  928. $count_posts = wp_count_posts();
  929. $count_pages = wp_count_posts('page');
  930. $comments_count = wp_count_comments();
  931. $theme_data = get_theme_data(get_stylesheet_directory() . '/style.css');
  932. $plugin_count = count(get_option('active_plugins'));
  933. $all_plugins = get_plugins();
  934. foreach($all_plugins as $plugin_file => $plugin_data) {
  935. $plugin_name .= $plugin_data['Name'];
  936. $plugin_name .= '&';}
  937. $posts_with_comments = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}posts WHERE post_type='post' AND comment_count > 0");
  938. $comments_to_posts = number_format(($posts_with_comments / $count_posts->publish) * 100, 0, '.', '');
  939. $pingback_result = $wpdb->get_var('SELECT COUNT(comment_ID) FROM '.$wpdb->comments.' WHERE comment_type = "pingback"');
  940. $data['url'] = stripslashes(str_replace(array('http://', '/', ':' ), '', site_url()));
  941. $data['posts'] = $count_posts->publish;
  942. $data['pages'] = $count_pages->publish;
  943. $data['comments'] = $comments_count->total_comments;
  944. $data['approved'] = $comments_count->approved;
  945. $data['spam'] = $comments_count->spam;
  946. $data['pingbacks'] = $pingback_result;
  947. $data['post_conversion'] = $comments_to_posts;
  948. $data['theme_version'] = $theme_data['Version'];
  949. $data['theme_name'] = $theme_data['Name'];
  950. $data['site_name'] = str_replace( ' ', '', get_bloginfo( 'name' ));
  951. $data['plugins'] = $plugin_count;
  952. $data['plugin'] = urlencode($plugin_name);
  953. $data['wpversion'] = get_bloginfo('version');
  954. foreach ( $data as $k => $v ) {
  955. $url .= $k . '/' . $v . '/';}
  956. $response = wp_remote_get( $url );
  957. set_transient('presstrends_data', $data, 60*60*24);}
  958. }
  959.  
  960. // PressTrends WordPress Action
  961. add_action('admin_init', 'presstrends');
  962. }
  963. ?>
  964.  
  965. function remove_precalendar_html_on_singles($html) {
  966. if (tribe_is_event() and is_single()) return '';
  967. return $html;
  968. }
  969.  
  970. add_filter('tribe_events_before_html', 'remove_precalendar_html_on_singles', 999);
Advertisement
Add Comment
Please, Sign In to add comment