Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * TwentyTen functions and definitions
- *
- * Sets up the theme and provides some helper functions. Some helper functions
- * are used in the theme as custom template tags. Others are attached to action and
- * filter hooks in WordPress to change core functionality.
- *
- * The first function, twentyten_setup(), sets up the theme by registering support
- * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
- *
- * When using a child theme (see http://codex.wordpress.org/Theme_Development and
- * http://codex.wordpress.org/Child_Themes), you can override certain functions
- * (those wrapped in a function_exists() call) by defining them first in your child theme's
- * functions.php file. The child theme's functions.php file is included before the parent
- * theme's file, so the child theme functions would be used.
- *
- * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
- * to a filter or action hook. The hook can be removed by using remove_action() or
- * remove_filter() and you can attach your own function to the hook.
- *
- * We can remove the parent theme's hook only after it is attached, which means we need to
- * wait until setting up the child theme:
- *
- * <code>
- * add_action( 'after_setup_theme', 'my_child_theme_setup' );
- * function my_child_theme_setup() {
- * // We are providing our own filter for excerpt_length (or using the unfiltered value)
- * remove_filter( 'excerpt_length', 'twentyten_excerpt_length' );
- * ...
- * }
- * </code>
- *
- * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
- *
- * @package WordPress
- * @subpackage Twenty_Ten
- * @since Twenty Ten 1.0
- */
- global $userdata,$user_ID, $user_identity, $user_level;
- $wpdb->cbzipcode = $wpdb->prefix.'cbzipcode';
- function zipcodes_exists($field, $value) {
- global $wpdb;
- if($field == 'zipcode') { $value = $value;}
- if(empty($value)) return false;
- if ( !$result = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->cbzipcode WHERE $field = %s", $value) ) )
- return false;
- return $result;
- }
- function zipcodes_latlng($value) {
- global $wpdb;
- $field = 'zipcode';
- if(empty($value)) return false;
- if ( !$result = $wpdb->get_row( $wpdb->prepare("SELECT latitude, longitude FROM $wpdb->cbzipcode WHERE $field = %s", $value) ) )
- return false;
- return $result;
- }
- $userexpired = false;
- /*
- if(is_user_logged_in()){
- $packageexp = get_user_meta($user_ID, 'packageexp', true); //date in Y-m-d format
- $todays_date = date("Y-m-d");
- $today = strtotime($todays_date);
- $packageexp = strtotime($packageexp);
- //var_dump($today);
- //var_dump($packageexp);
- if(($today > $packageexp) && ($userdata->rdrole == 'parents')) {
- $userexpired = true;
- }
- }
- */
- $codeboxr_invitecode = get_option('codeboxr_invitecode');
- $codeboxr_inviteon = intval(get_option('codeboxr_inviteon'));
- $spages = get_option('codeboxr_spages');
- if(!is_array($spages)){
- $spages = array (
- 'termspage' => 0,
- 'privacypage' => 0,
- 'regipage' => 0,
- 'profilepage' => 0,
- 'jobpostpage' => 0,
- 'cdpage' => 0,
- 'myrdpage' => 0,
- 'racelist' => 0
- /*'jobsearchpage' => 0,
- 'driversearchpage' => 0,
- 'jobapplypage' => 0,
- 'writereviewpage' => 0,
- 'myjobapppage' => 0,
- 'viewjobapppage' => 0,
- 'alljobapppage' => 0,
- 'allreviewpage' => 0,
- 'postedjobpage' => 0,
- 'myreviewspage' => 0,
- 'mytestipage' => 0,
- 'availability' => 0,
- 'sendmessage' => 0,
- 'messaging' => 0,
- 'avatarupload' => 0,
- 'subscription' => 0*/
- );
- }
- $spages = cb_convertArrayToObject($spages);
- /*
- $packagep = get_option('codeboxr_package');
- if(!is_array($packagep)){
- $packagep = array (
- 'package0' => 0,
- 'package1' => 0,
- 'package2' => 0,
- 'package3' => 0
- );
- }
- $packagep = cb_convertArrayToObject($packagep);
- $merchant = get_option('codeboxr_merchant');
- if(!is_array($merchant)){
- $merchant = array(
- 'testmode' => 'no',
- 'homeurl' => '',
- 'retadd' => 0,
- 'vendorid' => '',
- 'vendorname' => '',
- 'vendoridt' => 0,
- 'vendornamet' => '',
- 'showitems' => 0,
- 'acceptcards' => 0,
- 'acceptchecks' => 0,
- 'accepteft' => 0
- );
- }
- $merchant = cb_convertArrayToObject($merchant);
- */
- $mailtemplates = get_option('codeboxr_mailtemplates');
- if(!is_array($mailtemplates)){
- $mailtemplates = array(
- 'footer' => '',
- 'regif' => '',
- 'regid' => '',
- 'msgt' => '',
- 'sub' => '',
- 'subex' => '',
- 'uterm' => '',
- 'preset' => ''
- );
- }
- $mailtemplates = cb_convertArrayToObject($mailtemplates);
- $snetwork = get_option('codeboxr_snetwork');
- if(!is_array($snetwork)){
- $snetwork = array(
- 'rss' => array('url' => '#', 'status' => 0),
- 'fb' => array('url' => '#', 'status' => 0),
- 'tw' => array('url' => '#', 'status' => 0),
- 'yt' => array('url' => '#', 'status' => 0),
- 'ct' => array('url' => '#', 'status' => 0),
- 'ic' => array('url' => '#', 'status' => 0)
- );
- }
- $snetwork = cb_convertArrayToObject($snetwork);
- $slider = get_option('slider');
- if(!is_array($slider)){
- $slider = array(
- 'speed' => 500,
- 'pausetime' => 5000,
- 'slide1' => '',
- 'slide2' => '',
- 'slide3' => '',
- 'slide4' => '',
- 'slide5' => '',
- 'slide6' => ''
- );
- }
- $slider = cb_convertArrayToObject($slider);
- $banner = get_option('banner');
- if(!is_array($banner)){
- $banner = array(
- 'b1' => array('status' => 0, 'col' => 1,
- 'img' => array(
- 'b11img' => '',
- 'b12img' => '',
- 'b13img' => '',
- 'b14img' => ''
- ),
- 'url' => array(
- 'b11url' => '#',
- 'b12url' => '#',
- 'b13url' => '#',
- 'b14url' => '#'
- )
- ),
- 'b2' => array('status' => 0, 'col' => 1,
- 'img' => array(
- 'b21img' => '',
- 'b22img' => '',
- 'b23img' => '',
- 'b24img' => ''
- ),
- 'url' => array(
- 'b21url' => '#',
- 'b22url' => '#',
- 'b23url' => '#',
- 'b24url' => '#'
- )
- ),
- 'b3' => array('status' => 0, 'col' => 1,
- 'img' => array(
- 'b31img' => '',
- 'b32img' => '',
- 'b33img' => '',
- 'b34img' => ''
- ),
- 'url' => array(
- 'b31url' => '#',
- 'b32url' => '#',
- 'b33url' => '#',
- 'b34url' => '#'
- )
- )
- );
- }
- $banner = cb_convertArrayToObject($banner);
- include_once TEMPLATEPATH."/setting.php";
- //recaptcha setting and initialization
- if(!function_exists('recaptcha_get_html')):
- require_once(TEMPLATEPATH.'/libs/recaptcha/recaptchalib.php');
- endif;
- // Get a key from https://www.google.com/recaptcha/admin/create
- // this keys are for codeboxr.com
- $recaptcha = get_option('recaptcha');
- if(!is_array($recaptcha)){
- $recaptcha = array(
- 'publickey' => '6LdRU8kSAAAAAEhXoo5Euowk8cZEuwv9nwOXJd71',
- 'privatekey' => '6LdRU8kSAAAAAC7IDKeJyT0h8RHRtK2hzPZZvgbw'
- );
- }
- $recaptcha = cb_convertArrayToObject($recaptcha);
- //$recaptcha_publickey = "6LdRU8kSAAAAAEhXoo5Euowk8cZEuwv9nwOXJd71";
- //$recaptcha_privatekey = "6LdRU8kSAAAAAC7IDKeJyT0h8RHRtK2hzPZZvgbw";
- $recaptcha_publickey = $recaptcha->publickey;
- $recaptcha_privatekey = $recaptcha->privatekey;
- //end recapctha
- //includes widgets here
- include_once TEMPLATEPATH."/rdwidgets/rdwidgets.php";
- function add_themescript(){
- global $spages;
- if(!is_admin()){
- wp_enqueue_script('jquery');
- //echo $spages->avatarupload;
- //wp_enqueue_script('jqueryeasing', get_bloginfo('template_directory').'/js/slides/jquery.easing.js', array('jquery'), '1.0');
- //wp_enqueue_script('slidejs', get_bloginfo('template_directory').'/js/slides/script.js', array('jquery'), '1.0');
- //wp_enqueue_script('thickbox',null,array('jquery'));
- //wp_enqueue_script('tinycarousel', get_bloginfo('template_directory').'/js/jquery.tinycarousel.min.js', array('jquery'), '10');
- //wp_enqueue_style('thickbox.css', '/'.WPINC.'/js/thickbox/thickbox.css', null, '1.0');
- //wp_enqueue_style('slidecss', get_bloginfo('template_directory').'/js/slides/style.css', null, '1.3');
- wp_enqueue_style('wp-paginate', get_bloginfo('template_directory').'/wp-paginate.css', false, 4, 'screen');
- }
- }
- function add_recaptchajs(){
- echo '<script type="text/javascript">
- var RecaptchaOptions = {
- theme : \'clean\'
- };
- </script>';
- }
- function add_themescript2(){
- global $spages;
- if(is_page($spages->jobpostpage)){
- //var_dump('test is here');
- add_action('wp_head', 'add_recaptchajs');
- wp_enqueue_script("jquery");
- wp_enqueue_style('datepickcss', get_bloginfo('template_directory').'/css/datepicker/ui.datepick.css', null, '2');
- wp_enqueue_script('datepickjs', get_bloginfo('template_directory').'/js/datepicker/jquery.datepick.js', array('jquery'), '1.1');
- }
- if(is_page($spages->racelist)){
- wp_enqueue_script("jquery");
- wp_enqueue_style('datepickcss', get_bloginfo('template_directory').'/css/datepicker/ui.datepick.css', null, '2');
- wp_enqueue_script('datepickjs', get_bloginfo('template_directory').'/js/datepicker/jquery.datepick.js', array('jquery'), '1.1');
- }
- /*
- if(is_page($spages->avatarupload)){
- wp_enqueue_script('imgareaselect', get_bloginfo('template_directory').'/js/crop/jquery.imgareaselect.pack.js', array('jquery'), '1.0');
- wp_enqueue_style('imgareaselect', get_bloginfo('template_directory').'/css/crop/imgareaselect-animated.css', null, '1.3');
- }
- */
- }
- add_action('init','add_themescript');
- add_action('template_redirect', 'add_themescript2');
- /** Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */
- add_action( 'after_setup_theme', 'twentyten_setup' );
- if ( ! function_exists( 'twentyten_setup' ) ):
- /**
- * Sets up theme defaults and registers support for various WordPress features.
- *
- * Note that this function is hooked into the after_setup_theme hook, which runs
- * before the init hook. The init hook is too late for some features, such as indicating
- * support post thumbnails.
- *
- * To override twentyten_setup() in a child theme, add your own twentyten_setup to your child theme's
- * functions.php file.
- *
- * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
- * @uses register_nav_menus() To add support for navigation menus.
- * @uses add_custom_background() To add support for a custom background.
- * @uses add_editor_style() To style the visual editor.
- * @uses load_theme_textdomain() For translation/localization support.
- * @uses add_custom_image_header() To add support for a custom header.
- * @uses register_default_headers() To register the default custom header images provided with the theme.
- * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
- *
- * @since Twenty Ten 1.0
- */
- function twentyten_setup() {
- // This theme styles the visual editor with editor-style.css to match the theme style.
- add_editor_style();
- // Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories.
- //add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
- // This theme uses post thumbnails
- add_theme_support( 'post-thumbnails' );
- // Add default posts and comments RSS feed links to head
- add_theme_support( 'automatic-feed-links' );
- // Make theme available for translation
- // Translations can be filed in the /languages/ directory
- load_theme_textdomain( 'twentyten', TEMPLATEPATH . '/languages' );
- $locale = get_locale();
- $locale_file = TEMPLATEPATH . "/languages/$locale.php";
- if ( is_readable( $locale_file ) )
- require_once( $locale_file );
- // This theme uses wp_nav_menu() in one location.
- register_nav_menus( array(
- 'mainmenu' => __( 'Main Navigation', 'twentyten' ),
- ) );
- register_nav_menus( array(
- 'topmenu' => __( 'Top Navigation', 'twentyten' ),
- ) );
- register_nav_menus( array(
- 'footermenu' => __( 'Footer Navigation', 'twentyten' ),
- ) );
- // This theme allows users to set a custom background
- }
- endif;
- if ( ! function_exists( 'twentyten_admin_header_style' ) ) :
- /**
- * Styles the header image displayed on the Appearance > Header admin panel.
- *
- * Referenced via add_custom_image_header() in twentyten_setup().
- *
- * @since Twenty Ten 1.0
- */
- function twentyten_admin_header_style() {
- ?>
- <style type="text/css">
- /* Shows the same border as on front end */
- #headimg {
- border-bottom: 1px solid #000;
- border-top: 4px solid #000;
- }
- /* If NO_HEADER_TEXT is false, you would style the text with these selectors:
- #headimg #name { }
- #headimg #desc { }
- */
- </style>
- <?php
- }
- endif;
- /**
- * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
- *
- * To override this in a child theme, remove the filter and optionally add
- * your own function tied to the wp_page_menu_args filter hook.
- *
- * @since Twenty Ten 1.0
- */
- function twentyten_page_menu_args( $args ) {
- $args['show_home'] = true;
- return $args;
- }
- add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );
- /**
- * Sets the post excerpt length to 40 characters.
- *
- * To override this length in a child theme, remove the filter and add your own
- * function tied to the excerpt_length filter hook.
- *
- * @since Twenty Ten 1.0
- * @return int
- */
- function twentyten_excerpt_length( $length ) {
- return 40;
- }
- add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
- /**
- * Returns a "Continue Reading" link for excerpts
- *
- * @since Twenty Ten 1.0
- * @return string "Continue Reading" link
- */
- function twentyten_continue_reading_link() {
- return ' <a class="readmore" href="'. get_permalink() . '">' . __( 'Read More', 'twentyten' ) . '</a>';
- }
- /**
- * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link().
- *
- * To override this in a child theme, remove the filter and add your own
- * function tied to the excerpt_more filter hook.
- *
- * @since Twenty Ten 1.0
- * @return string An ellipsis
- */
- function twentyten_auto_excerpt_more( $more ) {
- return ' …' . twentyten_continue_reading_link();
- }
- add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
- /**
- * Adds a pretty "Continue Reading" link to custom post excerpts.
- *
- * To override this link in a child theme, remove the filter and add your own
- * function tied to the get_the_excerpt filter hook.
- *
- * @since Twenty Ten 1.0
- * @return string Excerpt with a pretty "Continue Reading" link
- */
- function twentyten_custom_excerpt_more( $output ) {
- if ( has_excerpt() && ! is_attachment() ) {
- $output .= twentyten_continue_reading_link();
- }
- return $output;
- }
- add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
- /**
- * Remove inline styles printed when the gallery shortcode is used.
- *
- * Galleries are styled by the theme in Twenty Ten's style.css. This is just
- * a simple filter call that tells WordPress to not use the default styles.
- *
- * @since Twenty Ten 1.2
- */
- add_filter( 'use_default_gallery_style', '__return_false' );
- /**
- * Deprecated way to remove inline styles printed when the gallery shortcode is used.
- *
- * This function is no longer needed or used. Use the use_default_gallery_style
- * filter instead, as seen above.
- *
- * @since Twenty Ten 1.0
- * @deprecated Deprecated in Twenty Ten 1.2 for WordPress 3.1
- *
- * @return string The gallery style filter, with the styles themselves removed.
- */
- function twentyten_remove_gallery_css( $css ) {
- return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
- }
- // Backwards compatibility with WordPress 3.0.
- if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) )
- add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
- if ( ! function_exists( 'twentyten_comment' ) ) :
- /**
- * Template for comments and pingbacks.
- *
- * To override this walker in a child theme without modifying the comments template
- * simply create your own twentyten_comment(), and that function will be used instead.
- *
- * Used as a callback by wp_list_comments() for displaying the comments.
- *
- * @since Twenty Ten 1.0
- */
- function twentyten_comment( $comment, $args, $depth ) {
- $GLOBALS['comment'] = $comment;
- switch ( $comment->comment_type ) :
- case '' :
- ?>
- <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
- <div id="comment-<?php comment_ID(); ?>">
- <div class="comment-author vcard">
- <?php echo get_avatar( $comment, 40 ); ?>
- <?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
- </div><!-- .comment-author .vcard -->
- <?php if ( $comment->comment_approved == '0' ) : ?>
- <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
- <br />
- <?php endif; ?>
- <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
- <?php
- /* translators: 1: date, 2: time */
- printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
- ?>
- </div><!-- .comment-meta .commentmetadata -->
- <div class="comment-body"><?php comment_text(); ?></div>
- <div class="reply">
- <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
- </div><!-- .reply -->
- </div><!-- #comment-## -->
- <?php
- break;
- case 'pingback' :
- case 'trackback' :
- ?>
- <li class="post pingback">
- <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p>
- <?php
- break;
- endswitch;
- }
- endif;
- /**
- * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
- *
- * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own
- * function tied to the init hook.
- *
- * @since Twenty Ten 1.0
- * @uses register_sidebar
- */
- function twentyten_widgets_init() {
- // Area 1, located at the top of the sidebar.
- register_sidebar( array(
- 'name' => __( 'Primary Widget Area', 'twentyten' ),
- 'id' => 'primary-widget-area',
- 'description' => __( 'The primary widget area', 'twentyten' ),
- 'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="widget-title">',
- 'after_title' => '</h3>',
- ) );
- // Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
- register_sidebar( array(
- 'name' => __( 'Secondary Widget Area', 'twentyten' ),
- 'id' => 'secondary-widget-area',
- 'description' => __( 'The secondary widget area', 'twentyten' ),
- 'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="widget-title">',
- 'after_title' => '</h3>',
- ) );
- // Sidebar for home page
- register_sidebar( array(
- 'name' => __( 'Home Widget Area', 'twentyten' ),
- 'id' => 'home-widget-area',
- 'description' => __( 'The home widget area', 'twentyten' ),
- 'before_widget' => '<div id="%1$s" class="widget-container homewidget-container %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="widget-title homewidget-title">',
- 'after_title' => '</h3>',
- ) );
- }
- /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
- add_action( 'widgets_init', 'twentyten_widgets_init' );
- /**
- * Removes the default styles that are packaged with the Recent Comments widget.
- *
- * To override this in a child theme, remove the filter and optionally add your own
- * function tied to the widgets_init action hook.
- *
- * This function uses a filter (show_recent_comments_widget_style) new in WordPress 3.1
- * to remove the default style. Using Twenty Ten 1.2 in WordPress 3.0 will show the styles,
- * but they won't have any effect on the widget in default Twenty Ten styling.
- *
- * @since Twenty Ten 1.0
- */
- function twentyten_remove_recent_comments_style() {
- add_filter( 'show_recent_comments_widget_style', '__return_false' );
- }
- add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );
- if ( ! function_exists( 'twentyten_posted_on' ) ) :
- /**
- * Prints HTML with meta information for the current post-date/time and author.
- *
- * @since Twenty Ten 1.0
- */
- function twentyten_posted_on() {
- printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
- 'meta-prep meta-prep-author',
- sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
- get_permalink(),
- esc_attr( get_the_time() ),
- get_the_date()
- ),
- sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
- get_author_posts_url( get_the_author_meta( 'ID' ) ),
- sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
- get_the_author()
- )
- );
- }
- endif;
- if ( ! function_exists( 'twentyten_posted_in' ) ) :
- /**
- * Prints HTML with meta information for the current post (category, tags and permalink).
- *
- * @since Twenty Ten 1.0
- */
- function twentyten_posted_in() {
- // Retrieves tag list of current post, separated by commas.
- $tag_list = get_the_tag_list( '', ', ' );
- if ( $tag_list ) {
- $posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
- } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
- $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
- } else {
- $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
- }
- // Prints the string, replacing the placeholders.
- printf(
- $posted_in,
- get_the_category_list( ', ' ),
- $tag_list,
- get_permalink(),
- the_title_attribute( 'echo=0' )
- );
- }
- endif;
- function walker_nav_menu_start_el_adddepth($item_output, $item, $depth, $args)
- {
- $item_output = str_replace('<a href="', '<a class="level_'.$depth.'" href="',$item_output);
- return $item_output;
- }
- add_filter('walker_nav_menu_start_el','walker_nav_menu_start_el_adddepth', 10,4);
- function cb_convertArrayToObject($myarray) {
- $return = new stdClass();
- foreach ($myarray as $key => $value) {
- if (is_array($value)) {
- $return->$key = cb_convertArrayToObject($value);
- }
- else {
- $return->$key = $value;
- }
- }
- return $return;
- }
- // custom login for theme
- function cb_custom_login() {
- if(stripos($_SERVER['REQUEST_URI'],'wp-login.php') !== false){
- echo '<link rel="stylesheet" type="text/css" href="' . get_bloginfo('template_directory') . '/custom-login.css?v=2" />';
- }
- }
- function cb_change_wp_login_url() {
- echo bloginfo('url');
- }
- function cb_change_wp_login_title() {
- echo 'Welcome to ' . get_option('blogname');
- }
- add_action('login_head', 'cb_custom_login',10);
- add_filter('login_headerurl', 'cb_change_wp_login_url');
- add_filter('login_headertitle', 'cb_change_wp_login_title');
- //Define the function which unsets the boxes
- function remove_dashboard_widgets() {
- global $wp_meta_boxes;
- //myprint_r($wp_meta_boxes);
- //var_dump('<pre>'.$wp_meta_boxes.'</pre>');
- //unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
- # Remove plugins feed
- unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
- unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_plugins']);
- # Remove "WordPress News"
- unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_primary']);
- unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
- unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_secondary']);
- unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
- # Remove incoming links feed
- unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
- unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_incoming_links']);
- unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
- unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
- unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
- //unset($wp_meta_boxes['dashboard']['normal']['core']['events_dashboard_window']);
- }
- // Now hook in to the action
- add_action('wp_dashboard_setup', 'remove_dashboard_widgets', 20, 0);
- function change_footer_content () {
- echo 'Copyright © 2011 '.get_option('blogname').' .All Rights Reserved';
- }
- add_filter('admin_footer_text', 'change_footer_content');
- function custom_admin_branding_header() {
- echo '
- <style>
- #header-logo {
- background-image: none;
- }
- </style>
- ';
- }
- //add_action('admin_head', 'custom_admin_branding_header', 11);
- function hide_some_profilefields( $contactmethods ) {
- unset($contactmethods['aim']);
- unset($contactmethods['jabber']);
- unset($contactmethods['yim']);
- //unset($contactmethods['url']);
- //unset($contactmethods['description']);
- return $contactmethods;
- }
- add_filter('user_contactmethods','hide_some_profilefields',10,1);
- function admin_del_color_options() {
- global $_wp_admin_css_colors;
- $_wp_admin_css_colors = 0;
- }
- add_action('admin_head', 'admin_del_color_options',10,1);
- //add_action('show_user_profile', 'cb_show_user_profile',10,1); //Runs near the end of the user profile editing screen.
- //add_action('edit_user_profile', 'cb_show_user_profile',10,1); //Runs near the end of the user profile editing screen in the admin menus.
- //add_action('profile_update', 'cb_profile_update', 10, 1); //Runs when a user's profile is updated. Action function argument: user ID.
- //add_action("admin_head-profile.php", 'cb_DatepickerHead', 10, 1); //Runs in the HTML <head> section of the admin panel of a page or a plugin-generated page.
- //add_action("admin_head-user-edit.php", 'cb_DatepickerHead', 10, 1); //Runs in the HTML <head> section of the admin panel of a page or a plugin-generated page.
- function cb_show_user_profile($user){
- /*
- $address1 = esc_attr(get_the_author_meta('address1',$user->ID ));
- $address2 = esc_attr(get_the_author_meta('address2',$user->ID ));
- $city = esc_attr(get_the_author_meta('city',$user->ID ));
- $state = esc_attr(get_the_author_meta('state',$user->ID ));
- $zipcode = esc_attr(get_the_author_meta('zipcode',$user->ID ));
- $telephone = esc_attr(get_the_author_meta('telephone',$user->ID ));
- $gender = esc_attr(get_the_author_meta('gender',$user->ID ));
- $birthdate = esc_attr(get_the_author_meta('birthdate',$user->ID ));
- $birthdate = convert_datetous($birthdate);
- $rdrole = esc_attr(get_the_author_meta('rdrole',$user->ID ));
- //noly for drivers
- $rate1 = esc_attr(get_the_author_meta('rate1',$user->ID ));
- $rate2 = esc_attr(get_the_author_meta('rate2',$user->ID ));
- $rateb = esc_attr(get_the_author_meta('rateb',$user->ID ));
- if($rateb == '')$rateb = 'hour';
- $vcapacity = esc_attr(get_the_author_meta('vcapacity',$user->ID ));
- $vinsure = esc_attr(get_the_author_meta('vinsure',$user->ID ));
- $drivingexp = esc_attr(get_the_author_meta('drivingexp',$user->ID ));
- $drivingradius = esc_attr(get_the_author_meta('drivingradius',$user->ID ));
- $currentpickdrop = get_the_author_meta('currentpickdrop',$user->ID, true );
- $package = get_the_author_meta('package', $user->ID);
- $package = ($package == '')? 'package0':$package;
- $actpackage = get_the_author_meta('actpackage', $user->ID);
- $packagestart = get_the_author_meta('packagestart',$user->ID );
- $packagestart = convert_datetous($packagestart);
- $packageexp = get_the_author_meta('packageexp', $user->ID );
- $packageexp = convert_datetous($packageexp);
- */
- ?>
- <!----h3>Custom/Additional fields</h3>
- <table class="form-table">
- <tbody>
- <tr>
- <th><label for="address1">Address Line1</label></th>
- <td>
- <input type="text" name="address1" id="address1" value="<?php echo $address1; ?>" class="regular-text" />
- </td>
- </tr>
- <tr>
- <th><label for="address2">Address Line2</label></th>
- <td>
- <input type="text" name="address2" id="address2" value="<?php echo $address2; ?>" class="regular-text" />
- </td>
- </tr>
- <tr>
- <th><label for="city">City</label></th>
- <td>
- <input type="text" name="city" id="city" value="<?php echo $city; ?>" class="regular-text" />
- </td>
- </tr>
- <tr>
- <th><label for="state">State</label></th>
- <td>
- <input type="text" name="state" id="state" value="<?php echo $state; ?>" class="regular-text" />
- </td>
- </tr>
- <tr>
- <th><label for="zipcode">ZIP Code</label></th>
- <td>
- <input type="text" name="zipcode" id="zipcode" value="<?php echo $zipcode; ?>" class="regular-text" />
- </td>
- </tr>
- <tr>
- <th><label for="telephone">Telephone</label></th>
- <td>
- <input type="text" name="telephone" id="telephone" value="<?php echo $telephone; ?>" class="regular-text" />
- </td>
- </tr>
- <tr>
- <th><label for="birthdate"><?php _e('Birth Date') ?></label></th>
- <td><input type="text" class="input birthdate" id="birthdate" name="birthdate" value="<?php echo esc_attr(stripslashes($birthdate)); ?>" size="25" tabindex="27"> Format: mm-dd-yyyy. Click to select.</td>
- </tr>
- <tr>
- <th><label for="gender"><?php _e('Gender') ?></label></th>
- <td>
- <select id="gender" name="gender" class="input">
- <option value="0" <?php selected(0,intval($gender)); ?>>Male</option>
- <option value="1" <?php selected(1,intval($gender)); ?>>Female</option>
- <option value="2" <?php selected(2,intval($gender)); ?>>Others</option>
- </select>
- </td>
- </tr>
- <tr>
- <th><label for="rdrole"><?php _e('Relativerides role') ?></label></th>
- <td>
- <select id="rdrole" name="rdrole" class="input">
- <option value="driver" <?php selected('driver',$rdrole); ?>>Driver</option>
- <option value="parents" <?php selected('parents',$rdrole); ?>>Parents</option>
- <option value="" <?php selected('',$rdrole); ?>>None</option>
- </select>
- </td>
- </tr>
- </tbody>
- </table>
- <h3>Vehicle & Driving Info</h3>
- <table class="form-table">
- <tbody>
- <tr>
- <th><label for="rate1">Rate range (in whole dollars):</label></th>
- <td>
- <input class="input smallinput" type="text" size="20" name="rate1" value="<?php echo intval($rate1); ?>" /> To <input class="input smallinput" type="text" size="20" name="rate2" value="<?php echo intval($rate2); ?>" /> Per
- <select id="rateb" name="rateb" class="input">
- <option value="hour" <?php selected('hour',$rateb); ?>>Hour</option>
- <option value="week" <?php selected('week',$rateb); ?>>Week</option>
- </select>
- </td>
- </tr>
- <tr>
- <th><label class="editlargelabel avlabel" for="vcapacity"><?php _e('Number of People able to Transport') ?></label></th>
- <td>
- <select id="vcapacity" name="vcapacity" class="input">
- <option value="1" <?php selected(1,intval($vcapacity)); ?>>1</option>
- <option value="2" <?php selected(2,intval($vcapacity)); ?>>2</option>
- <option value="3" <?php selected(3,intval($vcapacity)); ?>>3</option>
- <option value="4" <?php selected(4,intval($vcapacity)); ?>>4</option>
- <option value="5" <?php selected(5,intval($vcapacity)); ?>>5</option>
- <option value="6" <?php selected(6,intval($vcapacity)); ?>>6</option>
- <option value="7" <?php selected(7,intval($vcapacity)); ?>>7</option>
- </select>
- </td>
- </tr>
- <tr>
- <th><label class="editlargelabel avlabel" for="vinsure"><?php _e('Is the vehicle insured?') ?></label></th>
- <td>
- <label for="vinsure1" class="customradiobuttonl"><input type="radio" class="customradiobutton" <?php checked(1, intval($vinsure)); ?> value="1" id="vinsure1" name="vinsure">Yes</label>
- <label for="vinsure0" class="customradiobuttonl"><input type="radio" class="customradiobutton" <?php checked(0, intval($vinsure)); ?> value="0" id="vinsure0" name="vinsure">No</label>
- </td>
- </tr>
- <tr>
- <th><label for="drivingexp"><?php _e('Years driving') ?></label></th>
- <td>
- <input type="text" class="input" id="drivingexp" name="drivingexp" value="<?php echo esc_attr(stripslashes($drivingexp)); ?>" size="25"> years
- </td>
- </tr>
- <tr>
- <th><label for="drivingradius"><?php _e('Driving Radius'); ?></label></th>
- <td>
- <input type="text" class="input" id="drivingradius" name="drivingradius" value="<?php echo esc_attr(stripslashes($drivingradius)); ?>" size="25"> Kilometer
- </td>
- </tr>
- <tr>
- <th><label for="currentpickdrop"><?php _e('Current Public Location Pick Up/Drop Offs'); ?></label></th>
- <td>
- <input type="text" class="input" id="currentpickdrop0" name="currentpickdrop[]" value="<?php echo esc_attr(stripslashes($currentpickdrop[0])); ?>" size="25"><br/>
- <input type="text" class="input" id="currentpickdrop1" name="currentpickdrop[]" value="<?php echo esc_attr(stripslashes($currentpickdrop[1])); ?>" size="25"><br/>
- <input type="text" class="input" id="currentpickdrop2" name="currentpickdrop[]" value="<?php echo esc_attr(stripslashes($currentpickdrop[2])); ?>" size="25"><br/>
- <input type="text" class="input" id="currentpickdrop3" name="currentpickdrop[]" value="<?php echo esc_attr(stripslashes($currentpickdrop[3])); ?>" size="25"><br/>
- <input type="text" class="input" id="currentpickdrop4" name="currentpickdrop[]" value="<?php echo esc_attr(stripslashes($currentpickdrop[4])); ?>" size="25"><br/>
- <input type="text" class="input" id="currentpickdrop5" name="currentpickdrop[]" value="<?php echo esc_attr(stripslashes($currentpickdrop[5])); ?>" size="25"><br/>
- <span class="labelexample">Example: Location - Falls Church Recreation Time -3pm Monday thru Friday</span>
- </td>
- </tr>
- </tbody>
- </table>
- <h3>Subscription Information</h3>
- <table class="form-table">
- <tbody>
- <tr>
- <th><label for="package"><?php _e('Requested Package'); ?></label></th>
- <td>
- <select id="package" name="package" class="input">
- <option value="package0" <?php selected('package0',$package); ?>>Free One Week</option>
- <option value="package1" <?php selected('package1',$package); ?>>One Month</option>
- <option value="package2" <?php selected('package2',$package); ?>> Three Month</option>
- <option value="package3" <?php selected('package3',$package); ?>> Three Month</option>
- </select>
- </td>
- </tr>
- <tr>
- <th><label for="actpackage"><?php _e('Activated Package'); ?></label></th>
- <td>
- <select id="actpackage" name="actpackage" class="input">
- <option value="package0" <?php selected('package0',$actpackage); ?>>Free One Week</option>
- <option value="package1" <?php selected('package1',$actpackage); ?>>One Month</option>
- <option value="package2" <?php selected('package2',$actpackage); ?>> Three Month</option>
- <option value="package3" <?php selected('package3',$actpackage); ?>> Three Month</option>
- </select>
- </td>
- </tr>
- <tr>
- <th><label for="packagestart"><?php _e('Package Start Date'); ?></label></th>
- <td>
- <input type="text" class="input packagestart" id="packagestart" name="packagestart" value="<?php echo esc_attr(stripslashes($packagestart)); ?>" size="25" > Format: mm-dd-yyyy. Click to select.
- </td>
- </tr>
- <tr>
- <th><label for="packageexp"><?php _e('Package Expiration Date'); ?></label></th>
- <td>
- <input type="text" class="input packageexp" id="packageexp" name="packageexp" value="<?php echo esc_attr(stripslashes($packageexp)); ?>" size="25" > Format: mm-dd-yyyy. Click to select.
- </td>
- </tr>
- </tbody>
- </table-->
- <script type="text/javascript">
- /*
- jQuery(window).load(function() {
- //jQuery("#birthdate").datepick({minDate: '01/01/1990',yearRange: 'c-50:c+2',dateFormat: 'yyyy-mm-dd'});
- jQuery("#birthdate").datepick({dateFormat: 'mm-dd-yyyy'});
- jQuery("#packagestart").datepick({dateFormat: 'mm-dd-yyyy'});
- jQuery("#packageexp").datepick({dateFormat: 'mm-dd-yyyy'});
- });
- */
- </script>
- <?php
- }
- function cb_DatepickerHead(){
- if ( empty($jquery_loaded) ) {
- wp_print_scripts("jquery");
- $jquery_loaded = true;
- }
- echo '<link rel="stylesheet" type="text/css" media="all" href="'.get_bloginfo('template_directory').'/css/datepicker/ui.datepick.css?v=2" />';
- echo '<script type="text/javascript" src="'.get_bloginfo('template_directory').'/js/datepicker/jquery.datepick.js"></script>';
- //<script type="text/javascript" src="'.get_bloginfo('template_directory').'/js/datepicker/jquery.datepick.pack.js"></script>
- }
- function cb_profile_update($user_id){
- global $wpdb;
- $address1 = $_POST['address1'];
- $address2 = $_POST['address2'];
- $city = $_POST['city'];
- $state = $_POST['state'];
- $zipcode = $_POST['zipcode'];
- $telephone = $_POST['telephone'];
- $gender = $_POST['gender'];
- $birthdate = $_POST['birthdate'];
- $birthdate = convert_ustodate($birthdate);
- $i_agree = $_POST['i_agree'];
- //only for drivers
- $rate1 = intval($_POST['rate1']);
- $rate2 = intval($_POST['rate2']);
- $rateb = $_POST['rateb'];
- $vcapacity = intval($_POST['vcapacity']);
- if($vcapacity == 0) $vcapacity = 1; // minimum heh !
- $vinsure = intval($_POST['vinsure']);
- if($vinsure == 0) $vinsure = 0;
- $drivingexp = intval($_POST['drivingexp']);
- $drivingradius = intval($_POST['drivingradius']);
- $currentpickdrop = $_POST['currentpickdrop'];
- //var_dump($currentpickdrop);
- $packagestart = $_POST['packagestart'];
- $packagestart = convert_ustodate($packagestart);
- $packageexp = $_POST['packageexp'];
- $packageexp = convert_ustodate($packageexp);
- $package = $_POST['package'];
- $package = ($package == '')? 'package0':$package;
- $actpackage = $_POST['actpackage'];
- $actpackage = ($actpackage == '')? 'package0':$actpackage;
- update_user_meta($user_id, "address1", $wpdb->prepare($address1));
- update_user_meta($user_id, "address2", $wpdb->prepare($address2));
- update_user_meta($user_id, "address2", $wpdb->prepare($address2));
- update_user_meta($user_id, "telephone", $wpdb->prepare($telephone));
- update_user_meta($user_id, "city", $wpdb->prepare($city));
- update_user_meta($user_id, "state", $wpdb->prepare($state));
- update_user_meta($user_id, "zipcode", $wpdb->prepare($zipcode));
- $latlng = zipcodes_latlng($zipcode);
- if($latlng != false){
- update_user_meta($user_id, "latitude", $wpdb->prepare($latlng->latitude));
- update_user_meta($user_id, "longitude", $wpdb->prepare($latlng->longitude));
- }
- update_user_meta($user_id, "birthdate", $wpdb->prepare($birthdate));
- update_user_meta($user_id, "gender", $wpdb->prepare($gender));
- if(is_admin()):
- $rdrole = $_POST['rdrole'];
- update_user_meta($user_id, 'rdrole', $wpdb->prepare($rdrole));
- endif;
- //only for drivers
- update_user_meta($user_id, "rate1", $wpdb->prepare($rate1));
- update_user_meta($user_id, "rate2", $wpdb->prepare($rate2));
- update_user_meta($user_id, "rateb", $wpdb->prepare($rateb));
- update_user_meta($user_id, "vcapacity", $wpdb->prepare($vcapacity));
- update_user_meta($user_id, "vinsure", $wpdb->prepare($vinsure));
- update_user_meta($user_id, "drivingexp", $wpdb->prepare($drivingexp));
- update_user_meta($user_id, "drivingradius", $wpdb->prepare($drivingradius));
- update_user_meta($user_id, "currentpickdrop", $currentpickdrop);
- update_user_meta($user_id, "package", $package);
- update_user_meta($user_id, "actpackage", $actpackage);
- update_user_meta($user_id, "packagestart", $packagestart);
- update_user_meta($user_id, "packageexp", $packageexp);
- }
- add_action( 'user_profile_update_errors', 'cb_validate_new_fields' );
- function cb_validate_new_fields(&$errors, $update = null, &$user = null) {
- //custom fields
- $first_name = $_POST['first_name'];
- $last_name = $_POST['last_name'];
- /*
- $address1 = $_POST['address1'];
- $address2 = $_POST['address2'];
- $city = $_POST['city'];
- $state = $_POST['state'];
- $zipcode = $_POST['zipcode'];
- $telephone = $_POST['telephone'];
- $gender = $_POST['gender'];
- $birthdate = $_POST['birthdate'];
- $i_agree = $_POST['i_agree'];
- $rdrole = $_POST['rdrole'];
- */
- //custom fields valiadtion
- if(empty ($first_name)){
- $errors->add( 'firstname_empty', __( '<strong>ERROR</strong>: First name is empty.' ) );
- }
- if(empty ($last_name)){
- $errors->add( 'lastname_empty', __( '<strong>ERROR</strong>: Last name is empty.' ) );
- }
- /*
- if(empty ($address1)){
- $errors->add( 'address1_empty', __( '<strong>ERROR</strong>: Addres is empty.' ) );
- }
- if(empty ($telephone)){
- $errors->add( 'telephone_empty', __( '<strong>ERROR</strong>: Telephone number missing.' ) );
- }
- if(empty ($city)){
- $errors->add( 'city_empty', __( '<strong>ERROR</strong>: City name is empty.' ) );
- }
- if(empty ($zipcode)){
- $errors->add( 'zip_empty', __( '<strong>ERROR</strong>: ZIP is empty.' ) );
- }
- else if( zipcodes_exists('zipcode', $zipcode ) == false) {
- $errors->add( 'zipcode_exists', __( '<strong>ERROR</strong>: Zipcode doesn\'t exists or not a valid zipcode.' ) );
- }
- if(empty ($birthdate)){
- $errors->add( 'birthdate_empty', __( '<strong>ERROR</strong>: Birthdate is empty.' ) );
- }
- */
- //if ($_POST['telephone'] == '' || !preg_match('/^(\+|)[0-9\-]{6,}$/', $_POST['telephone'])) {
- // $errors->add('empty_telephone', "<strong>ERROR</strong>: Please Enter in a valid telephone number");
- /// }
- }
- // Prepend the new column to the columns array
- function cb_user_extra_cols($cols) {
- //$screen = get_current_screen();
- //var_dump($screen);
- $cols['rdrole'] = 'Relativerdes Role';
- return $cols;
- }
- // Echo the ID for the new column
- function cb_user_extra_col_value($val, $column_name, $user_id) {
- $rdrole_name = '';
- if ($column_name == 'rdrole'){
- $rdrole = get_the_author_meta('rdrole',$user_id );
- switch($rdrole){
- case 'driver':
- $rdrole_name = 'Driver';
- break;
- case 'parents':
- $rdrole_name = 'Parents';
- break;
- default:
- $rdrole_name = 'None';
- }
- }
- return $rdrole_name;
- }
- function cb_user_extra_sortable_cols($columns) {
- //var_dump($columns);
- $custom = array(
- // meta column id => sortby value used in query
- 'rdrole' => 'rdrole',
- );
- return wp_parse_args($custom, $columns);
- }
- function cb_user_extra_orderby( $vars ) {
- if ( isset( $vars['orderby'] ) && 'rdrole' == $vars['orderby'] ) {
- $vars = array_merge( $vars, array(
- 'meta_key' => 'rdrole',
- 'orderby' => 'meta_value'
- ) );
- }
- return $vars;
- }
- function cb_user_extra_col()
- {
- //manage_users_sortable_columns
- //add_filter('manage_users_columns', 'cb_user_extra_cols');
- //add_action('manage_users_custom_column', 'cb_user_extra_col_value', 10, 3);
- //add_filter( 'manage_users_sortable_columns', 'cb_user_extra_sortable_cols' );
- //add_filter( 'request', 'cb_user_extra_orderby' );
- }
- //add_action('admin_init', 'cb_user_extra_col');
- add_action( 'init', 'cb_create_custom_postype_taxonomies', 0 );
- function cb_create_custom_postype_taxonomies(){
- global $wp_rewrite;
- /*
- register_taxonomy('post_vtag',
- array ( 0 => 'post',),
- array( 'hierarchical' => true, 'label' => 'Video Tags','show_ui' => true,'query_var' => true,'rewrite' => array('slug' => 'vtag'),'singular_label' => 'Video Tag')
- );
- register_taxonomy('post_extag',
- array ( 0 => 'post',),
- array( 'hierarchical' => true, 'label' => 'Explore Tags','show_ui' => true,'query_var' => true,'rewrite' => array('slug' => 'extag'),'singular_label' => 'Explore Tag')
- );
- */
- register_post_type('race',
- array(
- 'label' => 'Race','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => false,
- 'rewrite' => array('slug' => 'races', 'with_front' => true),
- //'rewrite' => false,
- 'query_var' => true,
- 'supports' => array('title','editor','trackbacks','custom-fields','comments','thumbnail','author'),
- 'labels' => array (
- 'name' => 'Races',
- 'singular_name' => 'Race',
- 'menu_name' => 'Races',
- 'add_new' => 'Add Race',
- 'add_new_item' => 'Add New Race',
- 'edit' => 'Edit',
- 'edit_item' => 'Edit Race',
- 'new_item' => 'New Race',
- 'view' => 'View Race',
- 'view_item' => 'View Race',
- 'search_items' => 'Search Race',
- 'not_found' => 'No Races Found',
- 'not_found_in_trash' => 'No Races Found in Trash'
- ),
- )
- );//end register custom post type jobs
- /*
- register_post_type('application',
- array(
- 'label' => 'Application','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => false,
- 'rewrite' => array('slug' => 'applications', 'with_front' => true),
- //'rewrite' => false,
- 'query_var' => true,
- 'supports' => array('title','editor','trackbacks','custom-fields','comments','thumbnail','author'),
- 'labels' => array (
- 'name' => 'Applications',
- 'singular_name' => 'Application',
- 'menu_name' => 'Applications',
- 'add_new' => 'Add Application',
- 'add_new_item' => 'Add New Application',
- 'edit' => 'Edit',
- 'edit_item' => 'Edit Application',
- 'new_item' => 'New Application',
- 'view' => 'View Application',
- 'view_item' => 'View Application',
- 'search_items' => 'Search Applications',
- 'not_found' => 'No Application Found',
- 'not_found_in_trash' => 'No Application Found in Trash'
- ),
- )
- );//end register custom post type application
- */
- /*
- register_post_type('review',
- array(
- 'label' => 'Review','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => false,
- 'rewrite' => array('slug' => 'testimonials', 'with_front' => true),
- //'rewrite' => false,
- 'query_var' => true,
- 'supports' => array('title','editor','trackbacks','custom-fields','comments','thumbnail','author'),
- 'labels' => array (
- 'name' => 'Reviews',
- 'singular_name' => 'Review',
- 'menu_name' => 'Reviews',
- 'add_new' => 'Add Review',
- 'add_new_item' => 'Add New Review',
- 'edit' => 'Edit',
- 'edit_item' => 'Edit Review',
- 'new_item' => 'New Review',
- 'view' => 'View Review',
- 'view_item' => 'View Review',
- 'search_items' => 'Search Reviews',
- 'not_found' => 'No Review Found',
- 'not_found_in_trash' => 'No Review Found in Trash'
- ),
- )
- );//end register custom post type application
- */
- /*
- register_post_type('rdmessage',
- array(
- 'label' => 'Message','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => false,
- 'rewrite' => array('slug' => 'messages', 'with_front' => true),
- //'rewrite' => false,
- 'query_var' => true,
- 'supports' => array('title','editor','trackbacks','custom-fields','comments','thumbnail','author'),
- 'labels' => array (
- 'name' => 'Messages',
- 'singular_name' => 'Message',
- 'menu_name' => 'Messages',
- 'add_new' => 'Add Message',
- 'add_new_item' => 'Add New Message',
- 'edit' => 'Edit',
- 'edit_item' => 'Edit Message',
- 'new_item' => 'New Message',
- 'view' => 'View Message',
- 'view_item' => 'View Message',
- 'search_items' => 'Search Messages',
- 'not_found' => 'No Message Found',
- 'not_found_in_trash' => 'No Message Found in Trash'
- ),
- )
- );//end register custom post type application
- */
- //$tagname, $regex
- /*
- add_rewrite_tag( '%job%', '([^/]+)' );
- $extra_post_types = get_post_types( array( '_builtin' => false, 'publicly_queryable' => true ) );
- if( empty( $extra_post_types ) )
- return;
- add_rewrite_tag( '%job%', '('.implode('|',$extra_post_types).')' );
- add_permastruct( 'job', '/%year%/%monthnum%/%job%/', true, 1 );
- */
- /*
- register_taxonomy('childrenage',
- array ( 0 => 'job',),
- array( 'hierarchical' => true,
- 'label' => 'Ages of passenger','show_ui' => true,'query_var' => true,
- 'rewrite' => array('slug' => 'jobsbypassengerage'),'singular_label' => 'Ages of Passenger') );
- register_taxonomy('language',
- array ( 0 => 'job',),
- array( 'hierarchical' => true,
- 'label' => 'Language','show_ui' => true,'query_var' => true,
- 'rewrite' => array('slug' => 'jobsbylanguage'),'singular_label' => 'Language') );
- */
- /*
- register_taxonomy('racetag',
- array ( 0 => 'race',),
- array( 'hierarchical' => true,
- 'label' => 'Race Tag','show_ui' => true,'query_var' => true,
- 'rewrite' => array('slug' => 'racetags'),'singular_label' => 'Race Tag') );
- */
- register_taxonomy('racetype',
- array ( 0 => 'race',),
- array( 'hierarchical' => true,
- 'label' => 'Race Type','show_ui' => true,'query_var' => true,
- 'rewrite' => array('slug' => 'racetypes'),'singular_label' => 'Race Type') );
- register_taxonomy('racedistance',
- array ( 0 => 'race',),
- array( 'hierarchical' => true,
- 'label' => 'Race Distance','show_ui' => true,'query_var' => true,
- 'rewrite' => array('slug' => 'racedistances'),'singular_label' => 'Race Distance') );
- register_taxonomy('racelocation',
- array ( 0 => 'race',),
- array( 'hierarchical' => true,
- 'label' => 'Race Location','show_ui' => true,'query_var' => true,
- 'rewrite' => array('slug' => 'racelocations'),'singular_label' => 'Race Location') );
- register_taxonomy('awards',
- array ( 0 => 'race',),
- array( 'hierarchical' => true,
- 'label' => 'Awards & Prizes','show_ui' => true,'query_var' => true,
- 'rewrite' => array('slug' => 'awards'),'singular_label' => 'Award & Prize') );
- }
- add_action( 'restrict_manage_posts', 'todo_restrict_manage_posts' );
- add_filter('parse_query','todo_convert_restrict');
- function todo_restrict_manage_posts() {
- global $typenow;
- //var_dump($typenow);
- $args = array( 'public' => true, '_builtin' => false );
- //$post_types = get_post_types($args);
- $post_types = array('race');
- //var_dump($post_types);
- if ( in_array($typenow, $post_types) ) {
- //$filters = get_object_taxonomies($typenow);
- $filters = array('racetype','racedistance','racelocation','awards');
- //var_dump($filters);
- foreach ($filters as $tax_slug) {
- $tax_obj = get_taxonomy($tax_slug);
- wp_dropdown_categories(array(
- 'show_option_all' => __('Show All '.$tax_obj->label ),
- 'taxonomy' => $tax_slug,
- 'name' => $tax_obj->name,
- 'orderby' => 'name',
- 'selected' => $_GET[$tax_obj->query_var],
- 'hierarchical' => $tax_obj->hierarchical,
- 'show_count' => true,
- 'hide_empty' => false
- ));
- }
- }
- }
- function todo_convert_restrict($query) {
- global $pagenow;
- global $typenow;
- if ($pagenow=='edit.php') {
- $filters = get_object_taxonomies($typenow);
- foreach ($filters as $tax_slug) {
- $var = &$query->query_vars[$tax_slug];
- if ( isset($var) ) {
- $term = get_term_by('id',$var,$tax_slug);
- $var = $term->slug;
- }
- }
- }
- }
- function override_is_tax_on_post_search($query) {
- global $pagenow;
- $qv = &$query->query_vars;
- if ($pagenow == 'edit.php' && isset($qv['taxonomy']) && isset($qv['s'])) {
- $query->is_tax = true;
- }
- }
- add_filter('parse_query','override_is_tax_on_post_search');
- /**
- * puplish the content in the feed later
- * $where ist default-var in WordPress (wp-includes/query.php)
- * This function an a SQL-syntax
- * Got from this url http://wpengineer.com/publish-the-feed-later/
- */
- function publish_later_on_feed($where) {
- global $wpdb, $post;
- if ( is_feed() ) {
- // timestamp in WP-format
- $now = gmdate('Y-m-d H:i:s');
- // value for wait; + device
- $wait = '30'; // integer
- // http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
- $device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
- // add SQL-sytax to default $where
- $where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
- }
- return $where;
- }
- add_filter('posts_where', 'publish_later_on_feed');
- function cb_add_extrametafields(){
- //add_meta_box( $id, $title, $callback, $page, $context, $priority, $callback_args );
- add_meta_box( 'cbextrametafields', 'Extra Post Options', 'cb_add_extrametafields_html', 'job', 'normal', 'high');
- //add_meta_box( 'videourl2', 'Dailymotion Playlist URL', 'eyeconnect_video_options2', 'post', 'normal', 'high');
- }
- function cb_add_extrametafields_html(){
- global $post;
- $custom = get_post_custom($post->ID);
- $jobzipcode = $custom["jobzipcode"][0]; //job location zipcode
- $jnchild = $custom["jnchild"][0]; //no. of children
- $jrate1 = $custom["jrate1"][0]; //rate start
- $jrate2 = $custom["jrate2"][0]; //rate end
- $jrateb = $custom["jrateb"][0]; //per hour/ per week
- $jstartdate = $custom["jstartdate"][0]; //per hour/ per week
- $jstartdate = convert_datetous($jstartdate); // yyyy-mm-dd to mm-dd-yyyy
- $appstatus = $custom["appstatus"][0]; //application status, open/close
- if($jrateb == ''){$jrateb = 'hour';}
- if($appstatus == ''){$appstatus = 'open';}
- // Use nonce for verification
- wp_nonce_field( plugin_basename( __FILE__ ), 'cb_extrametafields' );
- ?>
- <style type="text/css">
- .cblabel{
- display: inline-block;
- margin: 0 5px 5px 0;
- text-align: left;
- width: 150px;
- }
- </style>
- <div class="detail">
- <p><label class="cblabel">ZIP Code:</label><input size="20" name="jobzipcode" value="<?php echo $jobzipcode; ?>" /></p>
- <p><label class="cblabel">No. Children:</label><input size="20" name="jnchild" value="<?php echo $jnchild; ?>" /></p>
- <p>
- <label class="cblabel">Rate range (in whole dollars)::</label>From <input size="20" name="jrate1" value="<?php echo $jrate1; ?>" /> To <input size="20" name="jrate2" value="<?php echo $jrate2; ?>" /> per
- <select id="jrateb" name="jrateb" class="input">
- <option value="hour" <?php selected('hour',$jrateb); ?>>Hour</option>
- <option value="week" <?php selected('week',$jrateb); ?>>Week</option>
- </select>
- </p>
- <p><label class="cblabel">Job Start Date:</label><input size="20" name="jstartdate" value="<?php echo $jstartdate; ?>" />(Format: mm-dd-yyyy)</p>
- <p>
- <label class="appstatus">Application Status: </label>
- <select id="appstatus" name="appstatus" class="input">
- <option value="open" <?php selected('open',$appstatus); ?>>Open</option>
- <option value="close" <?php selected('close',$appstatus); ?>>Close</option>
- </select>
- </p>
- </div>
- <?php
- }
- function cb_update_extrametafields($post_id){
- global $post;
- // verify if this is an auto save routine.
- // If it is our form has not been submitted, so we dont want to do anything
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
- return;
- // verify this came from the our screen and with proper authorization,
- // because save_post can be triggered at other times
- if ( !wp_verify_nonce( $_POST['cb_extrametafields'], plugin_basename( __FILE__ ) ) )
- return;
- // Check permissions
- //var_dump($_POST['post_type']);
- if ( 'job' == $_POST['post_type'] )
- {
- if ( !current_user_can( 'edit_post', $post_id ) )
- return;
- }
- else { return; }
- // OK, we're authenticated: we need to find and save the data
- //$post_id, $meta_key, $meta_value, $prev_value = ''
- update_post_meta($post->ID, "jobzipcode", $_POST["jobzipcode"]);
- $latlng = zipcodes_latlng($_POST["jobzipcode"]);
- if($latlng != false){
- update_post_meta($post->ID, "latitude", $latlng->latitude);
- update_post_meta($post->ID, "longitude", $latlng->longitude);
- }
- update_post_meta($post->ID, "jnchild", $_POST["jnchild"]);
- update_post_meta($post->ID, "jrate1", $_POST["jrate1"]);
- update_post_meta($post->ID, "jrate2", $_POST["jrate2"]);
- update_post_meta($post->ID, "jrateb", $_POST["jrateb"]);
- $jstartdate = $_POST["jstartdate"];
- $jstartdate = convert_ustodate($jstartdate);
- update_post_meta($post->ID, "jstartdate", $jstartdate );
- update_post_meta($post->ID, "appstatus", $_POST["appstatus"]);
- }
- //add_action("admin_init", "cb_add_extrametafields");
- //add_action('save_post', 'cb_update_extrametafields');
- function myprint_r($my_array) {
- if(is_object($my_array))
- {
- $result = array();
- foreach($my_array as $key => $value)
- {
- $result[$key] = object_to_array($value);
- }
- $my_array = $result;
- }
- //return $data;
- if (is_array($my_array)) {
- echo "<table border=1 cellspacing=0 cellpadding=3 width=100%>";
- echo '<tr><td colspan=2 style="background-color:#333333;"><strong><font color=white>ARRAY</font></strong></td></tr>';
- foreach ($my_array as $k => $v) {
- echo '<tr><td valign="top" style="width:40px;background-color:#F0F0F0;">';
- echo '<strong>' . $k . "</strong></td><td>";
- myprint_r($v);
- echo "</td></tr>";
- }
- echo "</table>";
- return;
- }
- echo $my_array;
- }
- function object_to_array($data)
- {
- if(is_array($data) || is_object($data))
- {
- $result = array();
- foreach($data as $key => $value)
- {
- $result[$key] = object_to_array($value);
- }
- return $result;
- }
- return $data;
- }
- add_action('wp_head', 'cb_addstyle_topmenu');
- function cb_addstyle_topmenu(){
- global $userdata,$user_ID, $user_identity, $user_level;
- /*
- if($userdata->rdrole != 'parents' && $user_level < 10){ //no access for driver , others or having user level less than 10
- //wp_redirect(get_bloginfo('url')); exit;
- ?>
- <style type="text/css">
- #menu-main-menu li.parentsonly{ display: none;}
- </style>
- <?php
- }
- if($userdata->rdrole != 'driver' && $user_level < 10){ //no access for driver , others or having user level less than 10
- //wp_redirect(get_bloginfo('url')); exit;
- ?>
- <style type="text/css">
- #menu-main-menu li.driveronly{ display: none;}
- </style>
- <?php
- }
- if($user_level < 10){ //no access for driver , others or having user level less than 10
- //wp_redirect(get_bloginfo('url')); exit;
- ?>
- <style type="text/css">
- #menu-main-menu li.adminonly{ display: none;}
- </style>
- <?php
- }
- */
- if (!is_user_logged_in()){ // no access for guest
- //wp_redirect(get_bloginfo('url')); exit;
- ?>
- <style type="text/css">
- #menu-main-menu li.registeronly{ display: none;}
- </style>
- <?php
- }
- }
- function cb_wp_rediect($url = ''){
- if($url == '') return;
- else{
- if(headers_sent()){
- echo '<div id="login_error"><a href="'.$url.'">Redirecting you shortly, if your browser doesn\'t redirect automatically then please click here.</a></div>';
- echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
- echo '<script type="text/javascript">
- <!--
- window.location = '.$url.'
- //-->
- </script>'; exit();
- }else{
- wp_redirect($url); exit();
- }
- }
- }
- //better trim or exceprt
- function betterTrim($str1,$limit) {
- $len = strlen($str1);
- $output = '';
- if($len > $limit)
- {
- $str2 = substr($str1, 0, $limit) ;
- if($str1[$limit-1] === ' ' || $str1[$limit] === ' ' ){ $output = $str2; }
- else{
- $findme = ' ';
- $pos = strpos(substr($str1,$limit,$len), $findme);
- if($pos === FALSE ) { $output = $str1; }
- else
- {
- $limit = $limit+$pos;
- $output = substr($str1,0,$limit);
- }
- }
- return $output.'[...]';
- }
- else{ return $str1; }
- }
- //includes widgets here
- //include_once TEMPLATEPATH."/rdwidgets/rdwidgets.php";
- function cb_posts_for_current_author($query) {
- global $pagenow;
- if( 'edit.php' != $pagenow || !$query->is_admin )
- return $query;
- if( !current_user_can( 'manage_options' ) ) {
- global $user_ID;
- $query->set('author', $user_ID );
- }
- return $query;
- }
- add_filter('pre_get_posts', 'cb_posts_for_current_author');
- function cb_relativeTime( $timestamp ){
- if( !is_numeric( $timestamp ) ){
- $timestamp = strtotime( $timestamp );
- if( !is_numeric( $timestamp ) ){
- return "";
- }
- }
- $difference = time() - $timestamp;
- // Customize in your own language.
- $periods = array( "sec", "min", "hour", "day", "week", "month", "year", "decade" );
- $lengths = array( "60","60","24","7","4.35","12","10");
- if ($difference > 0) { // this was in the past
- $ending = "ago";
- }else { // this was in the future
- $difference = -$difference;
- $ending = "to go";
- }
- for( $j=0; $difference>=$lengths[$j] and $j < 7; $j++ )
- $difference /= $lengths[$j];
- $difference = round($difference);
- if( $difference != 1 ){
- // Also change this if needed for an other language
- $periods[$j].= "s";
- }
- $text = "$difference $periods[$j] $ending";
- return $text;
- }
- function cb_checked($val1, $val2){
- if($val1 == $val2 && !empty($val1) && !empty($val2) ) return 'LabelSelected';
- else return '';
- }
- function rdgetPhotoHeight($image) {
- $sizes = getimagesize($image);
- $height = $sizes[1];
- return $height;
- }
- function rdgetPhotoWidth($image) {
- $sizes = getimagesize($image);
- $width = $sizes[0];
- return $width;
- }
- function rdresizeImage($image,$width,$height,$scale) {
- $newImageWidth = ceil($width * $scale);
- $newImageHeight = ceil($height * $scale);
- $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
- $ext = strtolower(substr(basename($image), strrpos(basename($image), ".") + 1));
- $source = "";
- if($ext == "png"){
- $source = imagecreatefrompng($image);
- }elseif($ext == "jpg" || $ext == "jpeg"){
- $source = imagecreatefromjpeg($image);
- }elseif($ext == "gif"){
- $source = imagecreatefromgif($image);
- }
- imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
- if($ext == "png" || $ext == "PNG"){
- imagepng($newImage,$image,0);
- }elseif($ext == "jpg" || $ext == "jpeg" || $ext == "JPG" || $ext == "JPEG"){
- imagejpeg($newImage,$image,90);
- }elseif($ext == "gif" || $ext == "GIF"){
- imagegif($newImage,$image);
- }
- chmod($image, 0777);
- return $image;
- }
- function rdresizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
- $newImageWidth = ceil($width * $scale);
- $newImageHeight = ceil($height * $scale);
- $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
- $ext = strtolower(substr(basename($image), strrpos(basename($image), ".") + 1));
- $source = "";
- if($ext == "png"){
- $source = imagecreatefrompng($image);
- }elseif($ext == "jpg" || $ext == "jpeg"){
- $source = imagecreatefromjpeg($image);
- }elseif($ext == "gif"){
- $source = imagecreatefromgif($image);
- }
- imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
- if($ext == "png" || $ext == "PNG"){
- imagepng($newImage,$thumb_image_name,0);
- }elseif($ext == "jpg" || $ext == "jpeg" || $ext == "JPG" || $ext == "JPEG"){
- imagejpeg($newImage,$thumb_image_name,90);
- }elseif($ext == "gif" || $ext == "GIF"){
- imagegif($newImage,$thumb_image_name);
- }
- chmod($thumb_image_name, 0777);
- return $thumb_image_name;
- }
- function rdcropImage($thumb_width, $x1, $y1, $x2, $y2, $w, $h, $thumbLocation, $imageLocation){
- $scale = $thumb_width/$w;
- $cropped = rdresizeThumbnailImage($thumbLocation, $imageLocation,$w,$h,$x1,$y1,$scale);
- return $cropped;
- }
- //add_filter( 'get_avatar', 'my_avatar' );
- function my_avatar( $avatar ) {
- global $comment;
- if ( $comment->user_id > 0 && $user = get_userdata( $comment->user_id ) ) {
- $img = '';
- $upload_dir = wp_upload_dir();
- $rdupload_url = trailingslashit($upload_dir['baseurl']);
- $large_image = get_user_meta($comment->user_id, 'uphoto', true);
- //var_dump($large_image);
- $dir2 = $upload_dir['basedir'] . '/uphoto/';
- $large_image_location = $dir2.$large_image;
- $thumb_image_location = $dir2.'thumb'.$large_image;
- $large_image_location = str_replace("/", DS,$large_image_location);
- $thumb_image_location = str_replace("/", DS,$thumb_image_location);
- $large_image_location_url = $rdupload_url.'uphoto/'.$large_image;
- $thumb_image_location_url = $rdupload_url.'uphoto/thumb'.$large_image;
- //var_dump($thumb_image_location);
- if(file_exists($thumb_image_location)){
- $img = $thumb_image_location_url;
- }
- else{
- //$img = ($userdata->gender)? 'female':'mail';
- $img = get_bloginfo('template_directory').'/images/bio.gif';
- }
- $avatar = '<img class="avatar" src="'.$thumb_image_location_url.'" alt="'.$user->display_name.'" />';
- }
- return $avatar;
- }
- //input dd-mm-yyyy output mm-dd-yyyy
- function convert_dateuktous($strDate){
- if(empty($strDate)) return '';
- trim($strDate);
- list($d, $m, $y) = explode('-', $strDate);
- $mk = mktime(0,0,0,$m, $d, $y);
- $americanDate = strftime('%m-%d-%Y',$mk);
- return $americanDate;
- }
- //input mm-dd-yyyy output dd-mm-yyyy
- function convert_dateustouk($strDate){
- if(empty($strDate)) return '';
- trim($strDate);
- list($m, $d, $y) = explode('-', $strDate);
- $mk = mktime(0,0,0,$m, $d, $y);
- $europeanDate =strftime('%d-%m-%Y',$mk);
- return $europeanDate;
- }
- //input yyyy-mm-dd output mm-dd-yyyy
- function convert_datetous($strDate){
- if(empty($strDate)) return '';
- trim($strDate);
- list($y, $m, $d) = explode('-', $strDate);
- $mk = mktime(0,0,0,$m, $d, $y);
- $europeanDate =strftime('%m-%d-%Y',$mk);
- return $europeanDate;
- }
- //input mm-dd-yyyy output yyyy-mm-dd
- function convert_ustodate($strDate){
- if(empty($strDate)) return '';
- trim($strDate);
- list($m, $d, $y) = explode('-', $strDate);
- $mk = mktime(0,0,0,$m, $d, $y);
- $europeanDate =strftime('%Y-%m-%d',$mk);
- return $europeanDate;
- }
- //input yyyy-mm-dd output dd-mm-yyyy
- function convert_datetouk($strDate){
- if(empty($strDate)) return '';
- trim($strDate);
- list($y, $m, $d) = explode('-', $strDate);
- $mk = mktime(0,0,0,$m, $d, $y);
- $europeanDate = strftime('%d-%m-%Y',$mk);
- return $europeanDate;
- }
- function get_ipn_readabledate($strDate){
- $y = substr($strDate,0, 4);
- $m = substr($strDate, 4,2);
- $d = substr($strDate, 6,2);
- return $y.'-'.$m.'-'.$d;
- }
- //input in y m d
- function get_ipn_readabletimestamp($strDate){
- $y = substr($strDate,0, 4);
- $m = substr($strDate, 4,2);
- $d = substr($strDate, 6,2);
- $h = substr($strDate, 8,2);
- $min = substr($strDate, 10,2);
- $s = substr($strDate, 12,2);
- return mktime($h, $min, $s,$m, $d, $y);
- }
- // ADD CUSTOM POST TYPES TO THE 'RIGHT NOW' DASHBOARD WIDGET
- function wph_right_now_content_table_end() {
- $args = array(
- 'public' => true ,
- '_builtin' => false
- );
- $output = 'object';
- $operator = 'and';
- $post_types = get_post_types( $args , $output , $operator );
- foreach( $post_types as $post_type ) {
- $num_posts = wp_count_posts( $post_type->name );
- $num = number_format_i18n( $num_posts->publish );
- $text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) );
- if ( current_user_can( 'edit_posts' ) ) {
- $num = "<a href='edit.php?post_type=$post_type->name'>$num</a>";
- $text = "<a href='edit.php?post_type=$post_type->name'>$text</a>";
- }
- echo '<tr><td class="first b b-' . $post_type->name . '">' . $num . '</td>';
- echo '<td class="t ' . $post_type->name . '">' . $text . '</td></tr>';
- }
- $taxonomies = get_taxonomies( $args , $output , $operator );
- foreach( $taxonomies as $taxonomy ) {
- $num_terms = wp_count_terms( $taxonomy->name );
- $num = number_format_i18n( $num_terms );
- $text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name , intval( $num_terms ));
- if ( current_user_can( 'manage_categories' ) ) {
- $num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>";
- $text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>";
- }
- echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>';
- echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>';
- }
- }
- add_action( 'right_now_content_table_end' , 'wph_right_now_content_table_end' );
- // remove unncessary header info
- function remove_header_info() {
- remove_action('wp_head', 'rsd_link');
- remove_action('wp_head', 'wlwmanifest_link');
- remove_action('wp_head', 'wp_generator');
- remove_action('wp_head', 'start_post_rel_link');
- remove_action('wp_head', 'index_rel_link');
- remove_action('wp_head', 'adjacent_posts_rel_link');
- }
- add_action('init', 'remove_header_info');
- // remove extra css that recent comments widget injects
- function remove_recent_comments_style() {
- global $wp_widget_factory;
- remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
- }
- add_action('widgets_init', 'remove_recent_comments_style');
- function generate_posts_per_page_link(){
- $perpage = (isset ($_REQUEST['posts_per_page']))? sanitize_text_field($_REQUEST['posts_per_page']):10;
- $perpage = intval($perpage);
- $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
- $currentpage_link = get_pagenum_link($paged);
- $currentpage_link = str_replace('posts_per_page='.$perpage, '', $currentpage_link);
- if(strpos($currentpage_link, '?') !== false) {
- $currentpage_link = $currentpage_link.'&posts_per_page=';
- }
- else{
- $currentpage_link = $currentpage_link.'?posts_per_page=';
- }
- return $currentpage_link;
- }
- function generate_posts_orderby_link(){
- $orderby = (isset ($_REQUEST['orderby']))? sanitize_text_field($_REQUEST['orderby']):'date';
- $orderbys = array('date', 'jstartdate', 'jrate1');
- if(!in_array($orderby,$orderbys)){$orderby = 'date';}
- $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
- $currentpage_link = get_pagenum_link($paged);
- $currentpage_link = str_replace('orderby='.$orderby, '', $currentpage_link);
- if(strpos($currentpage_link, '?') !== false) {
- $currentpage_link = $currentpage_link.'&orderby=';
- }
- else{
- $currentpage_link = $currentpage_link.'?orderby=';
- }
- return $currentpage_link;
- }
- function generate_posts_order_link(){
- $order = (isset ($_REQUEST['order']))? sanitize_text_field($_REQUEST['order']):'DESC';
- $orders = array('DESC', 'ASC');
- if(!in_array($order,$orders)){$order = 'DESC';}
- $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
- $currentpage_link = get_pagenum_link($paged);
- $currentpage_link = str_replace('order='.$order, '', $currentpage_link);
- if(strpos($currentpage_link, '?') !== false) {
- $currentpage_link = $currentpage_link.'&order=';
- }
- else{
- $currentpage_link = $currentpage_link.'?order=';
- }
- return $currentpage_link;
- }
- function get_cb_permalink($link = ''){
- if($link == '' ){
- $link = get_permalink();
- }
- $link .= (get_option('permalink_structure')) ? '?' : '&';
- return $link;
- }
- function show_classname($value, $currentvalue, $classname, $echo = true){
- if($classname == '') return;
- if(($value == $currentvalue) && !empty ($value) && !empty($currentvalue) ){
- if($echo){
- echo $classname;
- }
- else return $classname;
- }
- }
- function cb_Subcription_Check(){
- global $wpdb;
- $errors = new WP_Error();
- $first_name = $_POST['first_name'];
- $last_name = $_POST['last_name'];
- $user_email = $_POST['user_email'];
- $address1 = $_POST['address1'];
- $city = $_POST['city'];
- $state = $_POST['state'];
- $zipcode = $_POST['zipcode'];
- $telephone = $_POST['telephone'];
- $package = $_POST['package'];
- $package = ($package == '')? 'package0':$package;
- // Check the e-mail address
- $user_email_error = false;
- if ( $user_email == '' ) {
- $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your e-mail address.' ) );
- $user_email_error = true;
- } elseif ( ! is_email( $user_email ) ) {
- $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn’t correct.' ) );
- $user_email = '';
- $user_email_error = true;
- }
- /*
- elseif ( !email_exists( $user_email ) ) {
- $errors->add( 'email_exists', __( '<strong>ERROR</strong>: Wrong email address.' ) );
- $user_email_error = true;
- }
- */
- //custom fields valiadtion
- if(empty ($first_name)){
- $errors->add( 'firstname_empty', __( '<strong>ERROR</strong>: First name is empty.' ) );
- }
- if(empty ($last_name)){
- $errors->add( 'lastname_empty', __( '<strong>ERROR</strong>: Last name is empty.' ) );
- }
- if(empty ($address1)){
- $errors->add( 'address1_empty', __( '<strong>ERROR</strong>: Addres is empty.' ) );
- }
- if(empty ($telephone)){
- $errors->add( 'telephone_empty', __( '<strong>ERROR</strong>: Telephone number missing.' ) );
- }
- if(empty ($city)){
- $errors->add( 'city_empty', __( '<strong>ERROR</strong>: City name is empty.' ) );
- }
- if(empty ($zipcode)){
- $errors->add( 'zip_empty', __( '<strong>ERROR</strong>: ZIP is empty.' ) );
- }
- else if( zipcodes_exists('zipcode', $zipcode ) == false) {
- $errors->add( 'zipcode_exists', __( '<strong>ERROR</strong>: Zipcode doesn\'t exists or not a valid zipcode.' ) );
- }
- if ( $errors->get_error_code() )
- return $errors;
- }
- if ( !function_exists('cb_wp_new_user_notification') ) :
- /**
- * Notify the blog admin of a new user, normally via email.
- *
- * @since 2.0
- *
- * @param int $user_id User ID
- * @param string $plaintext_pass Optional. The user's plaintext password
- */
- function cb_wp_new_user_notification($user_id, $plaintext_pass = '', $verification_code = '') {
- $user = new WP_User($user_id);
- $user_login = stripslashes($user->user_login);
- $user_email = stripslashes($user->user_email);
- $stored_user_login = get_user_meta($user_id, "stored_user_login", true);
- $stored_user_password = get_user_meta($user_id, "stored_user_password", true );
- // The blogname option is escaped with esc_html on the way into the database in sanitize_option
- // we want to reverse this for the plain text arena of emails.
- $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
- $message = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
- $message .= sprintf(__('Username: %s'), $stored_user_login) . "\r\n\r\n";
- $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
- @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
- if ( empty($plaintext_pass) )
- return;
- $message = sprintf(__('Username: %s'), $stored_user_login) . "\r\n";
- $message .= sprintf(__('Password: %s'), $stored_user_password) . "\r\n";
- $message .= '<a href="'.wp_login_url().'">'.wp_login_url().'</a>'. "\r\n";
- global $mailtemplates, $spages;
- $loginurl = get_permalink($spages->regipage);
- $loginurl = cb_getquerylink($loginurl).'action=login';
- $verificationurl = $loginurl.'&verificationcode='.$verification_code;
- $loginurl = '<a href="'.$loginurl.'">'.$loginurl.'</a>';
- $verificationurl = '<a href="'.$verificationurl.'">'.$verificationurl.'</a>';
- $message = stripslashes($mailtemplates->regif);
- $message = str_replace('%displayname%', $user->display_name, $message );
- $message = str_replace('%username%', $stored_user_login, $message );
- $message = str_replace('%password%', $stored_user_password, $message );
- $message = str_replace('%verificationurl%', $verificationurl, $message );
- $message = str_replace('%loginurl%', $loginurl, $message );
- wp_mail($user_email, sprintf(__('Welcome to %s'), $blogname), $message);
- }
- endif;
- if ( !function_exists('cb_wp_password_change_notification') ) :
- /**
- * Notify the blog admin of a user changing password, normally via email.
- *
- * @since 2.7
- *
- * @param object $user User Object
- */
- function cb_wp_password_change_notification(&$user) {
- // send a copy of password change notification to the admin
- // but check to see if it's the admin whose password we're changing, and skip this
- if ( $user->user_email != get_option('admin_email') ) {
- $message = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login) . "\r\n";
- // The blogname option is escaped with esc_html on the way into the database in sanitize_option
- // we want to reverse this for the plain text arena of emails.
- $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
- wp_mail(get_option('admin_email'), sprintf(__('%s Password Lost/Changed'), $blogname), $message);
- }
- }
- endif;
- if ( ! function_exists( 'cb_filter_system_from_mail' ) )
- {
- /**
- * First admin's e-mail address or blog name depending on current filter.
- *
- * @return string
- */
- function cb_filter_system_from_mail()
- {
- return get_option( 'wp_mail_from' == current_filter()
- ? 'admin_email' : 'blogname' );
- }
- add_filter( 'wp_mail_from', 'cb_filter_system_from_mail' );
- add_filter( 'wp_mail_from_name', 'cb_filter_system_from_mail' );
- }
- //add_filter('wp_mail_content_type', 'cb_set_content_type');
- //wp_mail( $to, $subject, $message, $headers, $attachments );
- function cb_set_content_type($content_type){
- add_action('phpmailer_init', 'cb_send_html');
- return "text/html";
- }
- /**
- * Replaces the < & > of the 3.1 email text links
- *
- * @since 0.1.2
- * @param string $body
- * @return string
- */
- function cb_esc_textlinks($body) {
- return preg_replace('#<(https?://[^*]+)>#', '$1', $body);
- }
- function cb_send_html(&$phpmailer){
- $email_template = '<head>
- <meta http-equiv="Content-Type" content="text/html;UTF-8" />
- </head>
- <body>
- <table cellspacing="0" cellpadding="10" border="0" bgcolor="#0A6587" width="620px" style="-webkit-border-radius: 10px;
- -moz-border-radius: 10px;border-radius: 10px;">
- <tbody>
- <tr>
- <td valign="top" align="left">
- <h3 style="color:#E4DE85; font-size: 28px; line-height: 32px; margin: 0; font-family: \'Helvetica Neue\',Arial,Helvetica,\'Nimbus Sans L\',sans-serif;">'.get_bloginfo( 'name' ).'</h3>
- <h2 style="color:#53E9FF; font-size: 14px; line-height: 16px; margin:10px 0 0 0; font-family: \'Helvetica Neue\',Arial,Helvetica,\'Nimbus Sans L\',sans-serif;">'.get_bloginfo( 'description' ).'</h2></td>
- </tr>
- <tr>
- <td valign="top" align="left" style="padding:0;">
- <table width="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#1A7D94" align="center">
- <tbody>
- <tr>
- <td>
- <div style="width:600px; font-size: 14px; line-height: 18px; font-family:Arial, Helvetica, sans-serif;font-size:13px;line-height:21px;margin:15px 0 10px 0;padding:0 20px; color: #ffffff;">
- %emailcontent%
- <br/><br/>Sincerely,<br/>'.get_bloginfo( 'name' ).' Team
- </div>
- </td>
- </tr>
- </tbody>
- </table>
- </td>
- </tr>
- <tr>
- <td bgcolor="#086430" style=" font-size: 14px; line-height: 18px;padding:20px 20px; color: #ffffff; -webkit-border-radius:0 0 10px 10px;-moz-border-radius: 0 0 10px 10px;border-radius: 0 0 10px 10px;">
- %emailfooter%
- </td>
- </tr>
- </tbody>
- </table>
- </body>
- </html>';
- global $mailtemplates;
- $codeboxr_mailfooter = nl2br(stripslashes($mailtemplates->footer));
- // Set the original plain text message
- //$email_template = htmlentities($email_template);
- //$phpmailer->Body = $email_template;
- $phpmailer->AltBody = wp_specialchars_decode($phpmailer->Body, ENT_QUOTES);
- // Clean < and > around text links in WP 3.1
- $mailerbody = nl2br($phpmailer->Body);
- $mailerbody = str_replace('%emailcontent%', $mailerbody, $email_template );
- $mailerbody = str_replace('%emailfooter%', $codeboxr_mailfooter, $mailerbody );
- //$phpmailer->Body = cb_esc_textlinks($phpmailer->Body);
- // Convert line breaks & make links clickable
- $mailerbody = wp_specialchars_decode($mailerbody);
- //$mailerbody = str_replace('<a ', '<a style="color:#ffffff;" ', $mailerbody);
- //$mailerbody = nl2br($mailerbody);
- $mailerbody = html_entity_decode($mailerbody);
- // Add template to message
- //$phpmailer->Body = $this->set_email_template($phpmailer->Body);
- // Replace variables in email
- //$phpmailer->Body = $this->template_vars_replacement($phpmailer->Body);
- $mailerbody = str_replace('<a ', '<a style="color:#31FF71;" ', $mailerbody);
- $phpmailer->Body = $mailerbody;
- }
- //http://www.phaster.com/zip_code.html
- //https://github.com/Quixotix/PHP-ZipCode-Class/blob/master/example.php
- global $wpdb;
- /*
- $wpdb->cbzipcode = $wpdb->prefix.'cbzipcode';
- $wpdb->rdpayments = $wpdb->prefix.'rdpayments';
- $wpdb->rdpaymentserrorlog = $wpdb->prefix.'rdpaymentserrorlog';
- */
- /*
- function zipcodes_exists($field, $value) {
- global $wpdb;
- if($field == 'zipcode') { $value = absint($value);}
- if(empty($value)) return false;
- if ( !$result = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->cbzipcode WHERE $field = %s", $value) ) )
- return false;
- return $result;
- }
- function zipcodes_latlng($value) {
- global $wpdb;
- $field = 'zipcode';
- if(empty($value)) return false;
- if ( !$result = $wpdb->get_row( $wpdb->prepare("SELECT latitude, longitude FROM $wpdb->cbzipcode WHERE $field = %s", $value) ) )
- return false;
- return $result;
- }
- */
- /*
- function posts_where_jobsearch( $where ) {
- global $wpdb;
- global $lng1, $lng2, $lat1, $lat2;
- //var_dump($lng1);
- $distance = (isset ($_REQUEST['distance']))? sanitize_text_field($_REQUEST['distance']):1; //default 1 mile
- //$where . " AND $wpdb->postmeta.longitude between lng1 AND lng2 AND $wpdb->postmeta.latitude between lat1 AND lat2 having cbdistance <= ".$distance ;
- $where .= " AND $wpdb->postmeta.longitude between $lng1 AND $lng2 AND $wpdb->postmeta.latitude between $lat1 AND $lat2 ";
- //var_dump($where);
- return $where;
- }
- function join_jobsearch($join){
- global $wpdb;
- //$join .= " INNER JOIN $wpdb->posts ON ( wp_posts.ID = wp_term_relationships.object_id )";
- return $join;
- }
- */
- function cb_getquerylink($link){
- if(strpos($link, '?') !== false) {
- $link = $link.'&';
- }
- else{
- $link = $link.'?';
- }
- return $link;
- }
- function cb_paginate($found_rows,$perpage, $paged){
- $pagination_options = array(
- 'title' => 'Pages:',
- 'nextpage' => 'Next »',
- 'previouspage' => '« Prev',
- 'css' => true,
- 'before' => '<div class="navigation">',
- 'after' => '</div>',
- 'empty' => true,
- 'range' => 3,
- 'anchor' => 1,
- 'gap' => 3
- );
- $pagination_options = cb_convertArrayToObject($pagination_options);
- $pages = intval(ceil($found_rows / $perpage));
- $prevlink = esc_url(get_pagenum_link($paged - 1));
- $nextlink = esc_url(get_pagenum_link($paged + 1));
- $output = stripslashes($pagination_options->before);
- if ($pages > 1) {
- $output .= sprintf('<ol class="wp-paginate">');
- $output .= sprintf('<li><span class="title">%s</span></li>', stripslashes($pagination_options->title));
- $ellipsis = "<li><span class='gap'>...</span></li>";
- if ($paged > 1 && !empty($pagination_options->previouspage)) {
- $output .= sprintf('<li><a href="%s" class="prev">%s</a></li>', $prevlink, stripslashes($pagination_options->previouspage));
- }
- $min_links = $pagination_options->range * 2 + 1;
- $block_min = min($paged - $pagination_options->range, $pages - $min_links);
- $block_high = max($paged + $pagination_options->range, $min_links);
- $left_gap = (($block_min - $pagination_options->anchor - $pagination_options->gap) > 0) ? true : false;
- $right_gap = (($block_high + $pagination_options->anchor + $pagination_options->gap) < $pages) ? true : false;
- if ($left_gap && !$right_gap) {
- $output .= sprintf('%s%s%s',
- cb_paginate_loop(1, $pagination_options->anchor),
- $ellipsis,
- cb_paginate_loop($block_min, $pages, $paged)
- );
- }
- else if ($left_gap && $right_gap) {
- $output .= sprintf('%s%s%s%s%s',
- cb_paginate_loop(1, $pagination_options->anchor),
- $ellipsis,
- cb_paginate_loop($block_min, $block_high, $paged),
- $ellipsis,
- cb_paginate_loop(($pages - $pagination_options->anchor + 1), $pages)
- );
- }
- else if ($right_gap && !$left_gap) {
- $output .= sprintf('%s%s%s',
- cb_paginate_loop(1, $block_high, $paged),
- $ellipsis,
- cb_paginate_loop(($pages - $pagination_options->anchor + 1), $pages)
- );
- }
- else {
- $output .= cb_paginate_loop(1, $pages, $paged);
- }
- if ($paged < $pages && !empty($pagination_options->nextpage)) {
- $output .= sprintf('<li><a href="%s" class="next">%s</a></li>', $nextlink, stripslashes($pagination_options->nextpage));
- }
- $output .= "</ol>";
- }
- $output .= stripslashes($pagination_options->after);
- if ($pages > 1 || $pagination_options->empty) {
- echo $output;
- }
- }
- /**
- * Helper function for pagination which builds the page links.
- */
- function cb_paginate_loop($start, $max, $page = 0) {
- $output = "";
- for ($i = $start; $i <= $max; $i++) {
- $p = esc_url(get_pagenum_link($i)) ;
- $output .= ($page == intval($i))
- ? "<li><span class='page current'>$i</span></li>"
- : "<li><a href='$p' title='$i' class='page'>$i</a></li>";
- }
- return $output;
- }
- //apply_filters('comment_notification_text', $notify_message, $comment_id);
- //add_filter('comment_notification_text', 'cb_comment_notification_text', 99999,2);
- //apply_filters('comment_notification_subject', $subject, $comment_id);
- //add_filter('comment_notification_subject', 'cb_comment_notification_subject', 99999,2);
- /*
- function cb_comment_notification_text($notify_message, $comment_id){
- $comment = get_comment( $comment_id );
- $post = get_post( $comment->comment_post_ID );
- $author = get_userdata( $comment->user_id );
- $ptype = $post->post_type;
- if( $ptype == 'rdmessage' || $ptype == 'application' ){
- global $mailtemplates, $spages;
- //$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
- $app_link_redirect = get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id;
- $notify_message = stripslashes($mailtemplates->msgt);
- $notify_message = str_replace('%displayname%', $author->display_name, $notify_message );
- $notify_message = str_replace('%msgtext%', $comment->comment_content, $notify_message );
- $notify_message = str_replace('%msglink%', $app_link_redirect, $notify_message );
- }
- return $notify_message;
- }
- function cb_comment_notification_subject($subject, $comment_id){
- $comment = get_comment( $comment_id );
- $post = get_post( $comment->comment_post_ID );
- $author = get_userdata( $post->post_author );
- $ptype = $post->post_type;
- if( $ptype == 'rdmessage' || $ptype == 'application' ){
- global $mailtemplates, $spages;
- $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
- if($ptype == 'rdmessage'){
- return sprintf(__('New Message reply-%s'), $blogname);
- }
- else{
- return sprintf(__('New Comment/Reply on Job Application-%s'), $blogname);
- }
- //wp_mail($to, sprintf(__('New Job Application-%s'), $blogname), $message);
- }
- else return $subject;
- }
- */
- /*Event Calender*/
- function cb_calender_current_link($cur_year,$cur_month){
- global $spages;
- $cdpage_link = get_permalink($spages->cdpage);
- $cdpage_link = get_cb_permalink($cdpage_link);
- return '<a href="' . $cdpage_link . 'month='.$cur_month.'&yr=' . $cur_year . '">Current Month</a>';
- }
- function cb_calender_next_link($cur_year,$cur_month){
- global $spages;
- $cdpage_link = get_permalink($spages->cdpage);
- $cdpage_link = get_cb_permalink($cdpage_link);
- $mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sept','oct','nov','dec');
- $next_year = $cur_year + 1;
- if ($cur_month == 12)
- {
- $rlink = __('Next','calendar');
- return '<a href="' . $cdpage_link . 'month=jan&yr=' . $next_year . '">'.$rlink.' »</a>';
- }
- else
- {
- $next_month = $cur_month + 1;
- $month = $mod_rewrite_months[$next_month];
- $rlink = __('Next','calendar');
- return '<a href="' . $cdpage_link . 'month='.$month.'&yr=' . $cur_year . '">'.$rlink.' »</a>';
- }
- }
- // Configure the "Previous" link in the calendar
- function cb_calender_prev_link($cur_year,$cur_month){
- global $spages;
- $cdpage_link = get_permalink($spages->cdpage);
- $cdpage_link = get_cb_permalink($cdpage_link);
- $mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sept','oct','nov','dec');
- $last_year = $cur_year - 1;
- if ($cur_month == 1)
- {
- $llink = __('Prev','calendar');
- return '<a href="' . $cdpage_link . 'month=dec&yr='. $last_year .'">« '.$llink.'</a>';
- }
- else
- {
- $next_month = $cur_month - 1;
- $month = $mod_rewrite_months[$next_month];
- $llink = __('Prev','calendar');
- return '<a href="' . $cdpage_link . 'month='.$month.'&yr=' . $cur_year . '">« '.$llink.'</a>';
- }
- }
- // Actually do the printing of the calendar
- // Compared to searching for and displaying events
- // this bit is really rather easy!
- function cb_calendar()
- {
- global $wpdb;
- global $spages;
- $cdpage_link = get_permalink($spages->cdpage);
- $cdpage_link = get_cb_permalink($cdpage_link);
- include_once TEMPLATEPATH."/libs/dropdownlist.php";
- // Deal with the week not starting on a monday
- if (get_option('start_of_week') == 0)
- {
- $name_days = array(1=>__('Sunday','calendar'),__('Monday','calendar'),__('Tuesday','calendar'),__('Wednesday','calendar'),__('Thursday','calendar'),__('Friday','calendar'),__('Saturday','calendar'));
- }
- // Choose Monday if anything other than Sunday is set
- else
- {
- $name_days = array(1=>__('Monday','calendar'),__('Tuesday','calendar'),__('Wednesday','calendar'),__('Thursday','calendar'),__('Friday','calendar'),__('Saturday','calendar'),__('Sunday','calendar'));
- }
- // Carry on with the script
- $name_months = array(1=>__('January','calendar'),__('February','calendar'),__('March','calendar'),__('April','calendar'),__('May','calendar'),__('June','calendar'),__('July','calendar'),__('August','calendar'),__('September','calendar'),__('October','calendar'),__('November','calendar'),__('December','calendar'));
- // If we don't pass arguments we want a calendar that is relevant to today
- if (empty($_REQUEST['month']) || empty($_REQUEST['yr']))
- {
- $c_year = date("Y");
- $c_month = date("m");
- $c_day = date("d");
- }
- // Years get funny if we exceed 3000, so we use this check
- if (isset($_REQUEST['yr']))
- {
- if ($_REQUEST['yr'] <= 3000 && $_REQUEST['yr'] >= 0 && (int)$_REQUEST['yr'] != 0)
- {
- // This is just plain nasty and all because of permalinks
- // which are no longer used, this will be cleaned up soon
- if ($_REQUEST['month'] == 'jan' || $_REQUEST['month'] == 'feb' || $_REQUEST['month'] == 'mar' || $_REQUEST['month'] == 'apr' || $_REQUEST['month'] == 'may' || $_REQUEST['month'] == 'jun' || $_REQUEST['month'] == 'jul' || $_REQUEST['month'] == 'aug' || $_REQUEST['month'] == 'sept' || $_REQUEST['month'] == 'oct' || $_REQUEST['month'] == 'nov' || $_REQUEST['month'] == 'dec')
- {
- // Again nasty code to map permalinks into something
- // databases can understand. This will be cleaned up
- $c_year = mysql_escape_string($_REQUEST['yr']);
- $monthlist = array('jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, 'may' => 5, 'jun' => 6, 'jul' => 7, 'aug' => 8, 'sept' => 9, 'oct' => 10, 'nov' => 11, 'dec'=> 12 );
- /*
- if ($_REQUEST['month'] == 'jan') { $t_month = 1; }
- else if ($_REQUEST['month'] == 'feb') { $t_month = 2; }
- else if ($_REQUEST['month'] == 'mar') { $t_month = 3; }
- else if ($_REQUEST['month'] == 'apr') { $t_month = 4; }
- else if ($_REQUEST['month'] == 'may') { $t_month = 5; }
- else if ($_REQUEST['month'] == 'jun') { $t_month = 6; }
- else if ($_REQUEST['month'] == 'jul') { $t_month = 7; }
- else if ($_REQUEST['month'] == 'aug') { $t_month = 8; }
- else if ($_REQUEST['month'] == 'sept') { $t_month = 9; }
- else if ($_REQUEST['month'] == 'oct') { $t_month = 10; }
- else if ($_REQUEST['month'] == 'nov') { $t_month = 11; }
- else if ($_REQUEST['month'] == 'dec') { $t_month = 12; }
- */
- $t_month = $monthlist[$_REQUEST['month']];
- $c_month = $t_month;
- $c_day = date("d");
- }
- // No valid month causes the calendar to default to today
- else
- {
- $c_year = date("Y");
- $c_month = date("m");
- $c_day = date("d");
- }
- }
- }
- // No valid year causes the calendar to default to today
- else
- {
- $c_year = date("Y");
- $c_month = date("m");
- $c_day = date("d");
- }
- // Fix the days of the week if week start is not on a monday
- if (get_option('start_of_week') == 0)
- {
- $first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year));
- $first_weekday = ($first_weekday==0?1:$first_weekday+1);
- }
- // Otherwise assume the week starts on a Monday. Anything other
- // than Sunday or Monday is just plain odd
- else
- {
- $first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year));
- $first_weekday = ($first_weekday==0?7:$first_weekday);
- }
- $days_in_month = date("t", mktime (0,0,0,$c_month,1,$c_year));
- $racetype = (isset ($_REQUEST['racetype']))? $_REQUEST['racetype']:'-1';
- $racedistance = (isset ($_REQUEST['racedistance']))? $_REQUEST['racedistance']:'-1';
- $racelocation = (isset ($_REQUEST['racelocation']))? $_REQUEST['racelocation']:'-1';
- // Start the table and add the header and naviagtion
- $calendar_body = '';
- //$calendar_body .= '<form method="get" action="'.htmlspecialchars($_SERVER['REQUEST_URI']).'">';
- $calendar_body .= '<form method="post" action="'.htmlspecialchars($cdpage_link).'">';
- $calendar_body .= '<table cellspacing="1" cellpadding="0" class="calendar-table">';
- // The header of the calendar table and the links. Note calls to link functions
- $c_year2 = date("Y");
- $c_month2 = date("m");
- $thismonth = false;
- if($c_year === $c_year2 && $c_month === $c_month2){
- $thismonth = true;
- }
- $calendar_body .= '<tr>
- <td colspan="7" class="calendar-heading notopborder">
- <table class="topcdheader" border="0" cellpadding="0" cellspacing="0" width="100%">
- <tr><td class="notopborder">
- <span class="gradientbutton calendar-prev">' . cb_calender_prev_link($c_year,$c_month) . '</span>
- <span class="gradientbutton calendar-next">' . cb_calender_next_link($c_year,$c_month) . '</span>
- '.((!$thismonth)? '<span class="gradientbutton calendar-next">'.cb_calender_current_link($c_year2, $c_month2).'</span>':'').'
- <span class="calendar-month">'.$name_months[(int)$c_month].' '.$c_year.'</span>
- </td></tr>
- </table>
- </td></tr>';
- // We want to know if we should display the date switcher
- //$date_switcher = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_jump'",0,0);
- //if ($date_switcher == 'true')
- //{
- $calendar_body .= '<tr>
- <td colspan="7" class="calendar-date-switcher">';
- $calendar_body .= '<p>Filter By:';
- $calendar_body .= wp_dropdown_categories(array('echo' =>false, 'taxonomy' => 'racetype', 'id' => 'filterracetype', 'name' => 'racetype','show_option_none' => 'Select Race', 'show_count' => 0,'hierarchical' => 1, 'hide_empty' => 0, 'selected' => $racetype));
- $calendar_body .= ' '.wp_dropdown_categories(array('echo' =>false, 'taxonomy' => 'racedistance', 'id' => 'filterracedistance', 'name' => 'racedistance','show_option_none' => 'Select Distance', 'show_count' => 0,'hierarchical' => 1, 'hide_empty' => 0, 'selected' => $racedistance));
- $calendar_body .= ' '.wp_dropdown_categories(array('echo' =>false, 'taxonomy' => 'racelocation', 'id' => 'filterracelocation', 'name' => 'racelocation','show_option_none' => 'Select Location', 'show_count' => 0,'hierarchical' => 1, 'hide_empty' => 0, 'selected' => $racelocation));
- $calendar_body .= '</p>';
- $qsa = array();
- parse_str($_SERVER['QUERY_STRING'],$qsa);
- foreach ($qsa as $name => $argument)
- {
- if ($name != 'month' && $name != 'yr')
- {
- $calendar_body .= '<input type="hidden" name="'.strip_tags($name).'" value="'.strip_tags($argument).'" />';
- }
- }
- // We build the months in the switcher
- $calendar_body .= '
- '.__('Month','calendar').': <select name="month" style="width:100px;">
- <option value="jan"'.cb_calendar_month_comparison('jan').'>'.__('January','calendar').'</option>
- <option value="feb"'.cb_calendar_month_comparison('feb').'>'.__('February','calendar').'</option>
- <option value="mar"'.cb_calendar_month_comparison('mar').'>'.__('March','calendar').'</option>
- <option value="apr"'.cb_calendar_month_comparison('apr').'>'.__('April','calendar').'</option>
- <option value="may"'.cb_calendar_month_comparison('may').'>'.__('May','calendar').'</option>
- <option value="jun"'.cb_calendar_month_comparison('jun').'>'.__('June','calendar').'</option>
- <option value="jul"'.cb_calendar_month_comparison('jul').'>'.__('July','calendar').'</option>
- <option value="aug"'.cb_calendar_month_comparison('aug').'>'.__('August','calendar').'</option>
- <option value="sept"'.cb_calendar_month_comparison('sept').'>'.__('September','calendar').'</option>
- <option value="oct"'.cb_calendar_month_comparison('oct').'>'.__('October','calendar').'</option>
- <option value="nov"'.cb_calendar_month_comparison('nov').'>'.__('November','calendar').'</option>
- <option value="dec"'.cb_calendar_month_comparison('dec').'>'.__('December','calendar').'</option>
- </select>
- '.__('Year','calendar').': <select name="yr" style="width:60px;">';
- // The year builder is string mania. If you can make sense of this, you know your PHP!
- $past = 30;
- $future = 30;
- $fut = 1;
- $f = '';
- $p = '';
- while ($past > 0)
- {
- $p .= ' <option value="';
- $p .= date("Y")-$past;
- $p .= '"'.cb_calendar_year_comparison(date("Y")-$past).'>';
- $p .= date("Y")-$past.'</option>';
- $past = $past - 1;
- }
- while ($fut < $future)
- {
- $f .= ' <option value="';
- $f .= date("Y")+$fut;
- $f .= '"'.cb_calendar_year_comparison(date("Y")+$fut).'>';
- $f .= date("Y")+$fut.'</option>';
- $fut = $fut + 1;
- }
- $calendar_body .= $p;
- $calendar_body .= '<option value="'.date("Y").'"'.cb_calendar_year_comparison(date("Y")).'>'.date("Y").'</option>';
- $calendar_body .= $f;
- $calendar_body .= '</select>
- <input class="gradientbutton" id="calendergo" type="submit" value="'.__('Go','calendar').'" />
- </td>
- </tr>';
- //}
- // Print the headings of the days of the week
- $calendar_body .= '<tr>';
- for ($i=1; $i<=7; $i++)
- {
- // Colours need to be different if the starting day of the week is different
- if (get_option('start_of_week') == 0)
- {
- $calendar_body .= '<td class="'.($i<7&&$i>1?'normal-day-heading':'weekend-heading').'">'.$name_days[$i].'</td>';
- }
- else
- {
- $calendar_body .= '<td class="'.($i<6?'normal-day-heading':'weekend-heading').'">'.$name_days[$i].'</td>';
- }
- }
- $calendar_body .= '</tr>';
- $go = FALSE;
- for ($i=1; $i<=$days_in_month;)
- {
- $calendar_body .= '<tr>';
- for ($ii=1; $ii<=7; $ii++)
- {
- if ($ii==$first_weekday && $i==1)
- {
- $go = TRUE;
- }
- elseif ($i > $days_in_month )
- {
- $go = FALSE;
- }
- if ($go)
- {
- // Colours again, this time for the day numbers
- if (get_option('start_of_week') == 0)
- {
- // This bit of code is for styles believe it or not.
- $grabbed_events = cb_grab_events($c_year,$c_month,$i,'calendar');
- $no_events_class = '';
- if (!count($grabbed_events))
- {
- $no_events_class = ' no-events';
- }
- $calendar_body .= '<td class="'.(date("Ymd", mktime (0,0,0,$c_month,$i,$c_year))==date("Ymd")?'current-day':'day-with-date').$no_events_class.'"><span '.($ii<7&&$ii>1?'class="cddate"':'class="cddate weekend"').'>'.$i++.'</span><span class="event"><br />' . cb_draw_events($grabbed_events) . '</span></td>';
- }
- else
- {
- $grabbed_events = cb_grab_events($c_year,$c_month,$i,'calendar');
- $no_events_class = '';
- if (!count($grabbed_events))
- {
- $no_events_class = ' no-events';
- }
- $calendar_body .= '<td class="'.(date("Ymd", mktime (0,0,0,$c_month,$i,$c_year))==date("Ymd")?'current-day':'day-with-date').$no_events_class.'"><span '.($ii<6?'class="cddate"':'class="cddate weekend"').'>'.$i++.'</span><span class="event"><br />' . cb_draw_events($grabbed_events) . '</span></td>';
- }
- }
- else
- {
- $calendar_body .= '<td class="day-without-date"> </td>';
- }
- }
- $calendar_body .= '</tr>';
- }
- $calendar_body .= '</table></form>';
- //showing legeng color
- /*
- $show_cat = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='enable_categories'",0,0);
- if ($show_cat == 'true')
- {
- $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " ORDER BY category_name ASC";
- $cat_details = $wpdb->get_results($sql);
- $calendar_body .= '<table class="cat-key">
- <tr><td colspan="2" class="cat-key-cell"><strong>'.__('Category Key','calendar').'</strong></td></tr>
- ';
- foreach($cat_details as $cat_detail)
- {
- $calendar_body .= '<tr><td style="background-color:'.$cat_detail->category_colour.'; width:20px; height:20px;" class="cat-key-cell"></td>
- <td class="cat-key-cell"> '.$cat_detail->category_name.'</td></tr>';
- }
- $calendar_body .= '</table>
- ';
- }
- */
- $calendar_body .= '<p class="icalimport"><a href="'. get_home_url().'?ical">iCal import for Latest Race Events</a></p>';
- return $calendar_body;
- }
- // Setup comparison functions for building the calendar later
- function cb_calendar_month_comparison($month)
- {
- $current_month = strtolower(date("M"));
- if (isset($_REQUEST['yr']) && isset($_REQUEST['month']))
- {
- if ($month == $_REQUEST['month'])
- {
- return ' selected="selected"';
- }
- }
- elseif ($month == $current_month)
- {
- return ' selected="selected"';
- }
- }
- function cb_calendar_year_comparison($year)
- {
- $current_year = strtolower(date("Y"));
- if (isset($_REQUEST['yr']) && isset($_REQUEST['month']))
- {
- if ($year == $_REQUEST['yr'])
- {
- return ' selected="selected"';
- }
- }
- else if ($year == $current_year)
- {
- return ' selected="selected"';
- }
- }
- // Grab all events for the requested date from calendar
- function cb_grab_events($y,$m,$d,$typing){
- global $wpdb;
- $racetype = (isset ($_REQUEST['racetype']))? $_REQUEST['racetype']:'-1';
- $racedistance = (isset ($_REQUEST['racedistance']))? $_REQUEST['racedistance']:'-1';
- $racelocation = (isset ($_REQUEST['racelocation']))? $_REQUEST['racelocation']:'-1';
- $arr_events = array();
- // Get the date format right
- $date = $y . '-' . $m . '-' . $d;
- //var_dump($date);
- $order = (isset ($_REQUEST['order']))? sanitize_text_field($_REQUEST['order']):'DESC';
- $orderby = (isset ($_REQUEST['orderby']))? sanitize_text_field($_REQUEST['orderby']):'date';
- $orderby = 'startdate';
- $query_args = array('post_type' => 'race', 'post_status' => 'publish', 'posts_per_page' => 20, 'order' => $order, 'orderby' => $orderby);
- $query_args['meta_key'] = 'startdate';
- $query_args['orderby'] = 'meta_value';
- $meta_query = array();
- $tax_query = array();
- $meta_query[] = array(
- 'key' => 'startdate',
- 'value' => $date,
- 'compare' => '=',
- 'type' => 'DATE',
- );
- if(!empty($meta_query)){
- $query_args['meta_query'] = $meta_query;
- }
- $tax = 0;
- if($racetype != '-1'){
- $tax ++;
- $tax_query[] = array(
- 'taxonomy' => 'racetype',
- 'field' => 'id',
- 'terms' => $racetype,
- 'operator' => 'AND'
- );
- }
- if($racedistance != '-1'){
- $tax ++;
- //var_dump($racedistance);
- $tax_query[] = array(
- 'taxonomy' => 'racedistance',
- 'field' => 'id',
- 'terms' => array($racedistance),
- 'operator' => 'IN'
- );
- }
- if($racelocation != '-1'){
- $tax ++;
- $tax_query[] = array(
- 'taxonomy' => 'racelocation',
- 'field' => 'id',
- 'terms' => $racelocation,
- 'operator' => 'AND'
- );
- }
- if(!empty ($tax_query)){
- if($tax > 1){
- $tax_query['relation'] = 'OR';
- }
- $query_args['tax_query'] = $tax_query;
- }
- query_posts($query_args);
- //var_dump($query_args);
- //var_dump($races);
- while ( have_posts() ) : the_post();
- global $post;
- //var_dump($post);
- array_push($arr_events, $post);
- endwhile;
- //var_dump($arr_events);
- wp_reset_query();
- return $arr_events;
- }
- // Used to draw multiple events
- function cb_draw_events($events)
- {
- // We need to sort arrays of objects by time
- //usort($events, "cbtime_cmp");
- //var_dump($events);
- $output = '<ul class="cbdayevents">';
- // Now process the events
- //$events = $events[0];
- foreach($events as $event)
- {
- //var_dump($event->post_title);
- $title = $event->post_title;
- $title = substr($title,0,15).'...';
- $output .= '<li><a href="'.get_permalink($event->ID).'">'.$title.'</a></li>';
- }
- $output .= '</ul>';
- return $output;
- }
- //cat description editor
- add_action('init', 'catde_init');
- function catde_init() {
- if ( is_admin() || defined('DOING_AJAX') )
- {
- if ( current_user_can('manage_categories') )
- {
- //remove_filter('pre_term_description', 'wp_filter_kses');
- $filters = array('pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description');
- foreach ( $filters as $filter ) {
- remove_filter($filter, 'wp_filter_kses');
- }
- foreach ( array( 'term_description' ) as $filter ) {
- remove_filter( $filter, 'wp_kses_data' );
- }
- }
- }
- }
- add_action('load-categories.php', 'catde_admin_init');
- add_action('load-edit-tags.php', 'catde_admin_init');
- //add_action('profile.php', 'catde_admin_init2');
- function catde_admin_init()
- {
- if ( user_can_richedit() && isset($_GET['action']) && 'edit' === $_GET['action'] && ( !empty($_GET['cat_ID']) || ( !empty($_GET['taxonomy']) && !empty($_GET['tag_ID']) ) ) )
- {
- add_filter( 'tiny_mce_before_init', 'catde_mceinit');
- add_action('admin_footer', 'wp_tiny_mce');
- add_action('admin_head', 'catde_head');
- }
- }
- /*
- if(is_admin() && (false!==strpos($_SERVER['PHP_SELF'], 'profile.php')) && user_can_richedit())
- {
- add_filter( 'tiny_mce_before_init', 'catde_mceinit');
- add_action('admin_footer', 'wp_tiny_mce');
- add_action('admin_head', 'catde_head');
- }
- */
- function catde_mceinit($init)
- {
- $init['mode'] = 'textareas';
- $init['editor_selector'] = '';
- $init['elements'] = 'category_description,description';
- $init['plugins'] = 'safari,inlinepopups,autosave,spellchecker,paste,wordpress,media,fullscreen';
- $init['theme_advanced_buttons1'] .= ',image';
- $init['theme_advanced_buttons2'] .= ',code';
- $init['onpageload'] = '';
- $init['save_callback'] = '';
- return $init;
- }
- function catde_head() { ?>
- <style type="text/css">#category_description_tbl,#description_tbl{border:1px solid #dfdfdf;}.wp_themeSkin .mceStatusbar{border-color:#dfdfdf;}</style>
- <?php }
- // Prepend the new column to the columns array
- function cb_customtag_columns($cols) {
- $cols['racetype'] = 'Race Types';
- $cols['racedistance'] = 'Race Distance';
- $cols['racelocation'] = 'Race Location';
- $cols['awards'] = 'Race Awards';
- return $cols;
- }
- // Echo the ID for the new column
- function cb_customtags_value($column_name, $id) {
- if ($column_name == 'racetype'){
- echo get_the_term_list( $id, 'racetype', '', ', ', '' );
- }
- if ($column_name == 'racedistance'){
- echo get_the_term_list( $id, 'racedistance', '', ', ', '' );
- }
- if ($column_name == 'racelocation'){
- echo get_the_term_list( $id, 'racelocation', '', ', ', '' );
- }
- if ($column_name == 'awards'){
- echo get_the_term_list( $id, 'awards', '', ', ', '' );
- }
- }
- function cb_add_custom_taxonomy_col()
- {
- add_filter('manage_race_posts_columns', 'cb_customtag_columns');
- add_action('manage_race_posts_custom_column', 'cb_customtags_value', 10, 2);
- }
- add_action('admin_init', 'cb_add_custom_taxonomy_col');
- /*
- function rdrole_column_orderby( $vars ) {
- if ( isset( $vars['orderby'] ) && 'rdrole' == $vars['orderby'] ) {
- $vars = array_merge( $vars, array(
- 'meta_key' => 'rdrole',
- 'orderby' => 'meta_value_num'
- ) );
- }
- return $vars;
- }
- add_filter( 'request', 'rdrole_column_orderby' );
- */
- // get the "contributor" role object
- $obj_existing_role = get_role( 'contributor' );
- // add the "organize_gallery" capability
- $obj_existing_role->add_cap( 'edit_published_posts' );
- function cb_yesno($yes){
- $yes = intval($yes);
- if($yes) return 'Yes';
- else return 'No';
- }
- //input yyyy-mm-dd output dd-mm-yyyy
- function convert_datetoukdate($strDate){
- if(empty($strDate)) return '';
- trim($strDate);
- list($y, $m, $d) = explode('-', $strDate);
- $mk = mktime(0,0,0,$m, $d, $y);
- $europeanDate = strftime('%d-%m-%Y',$mk);
- return $europeanDate;
- }
- //input dd-mm-yyyy output yyyy-mm-dd
- function convert_ukdatetodate($strDate){
- if(empty($strDate)) return '';
- trim($strDate);
- list($d, $m, $y) = explode('-', $strDate);
- $mk = mktime(0,0,0,$m, $d, $y);
- $europeanDate = strftime('%Y-%m-%d',$mk);
- return $europeanDate;
- }
- //dd-mm-yyyy
- function cv_isvalid_date($date = ''){
- $return = true;
- if($date == '') $return = false;
- if (preg_match("/([0-9]{2})\-([0-9]{2})\-([0-9]{4})/", $date, $matches)) {
- if (!checkdate($matches[2], $matches[1], $matches[3])) {
- $return = false;
- }
- }else {
- $return = false;
- }
- return $return;
- }
- //possible use in widget
- function cb_merged_custom_wp_tag_cloud( $args = '' ) {
- $defaults = array(
- 'smallest' => 12, 'largest' => 26, 'unit' => 'px', 'number' => 25,
- 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
- 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true
- );
- $args = wp_parse_args( $args, $defaults );
- $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
- if ( empty( $tags ) )
- return;
- foreach ( $tags as $key => $tag ) {
- if ( 'edit' == $args['link'] )
- $link = get_edit_tag_link( $tag->term_id, $tag->taxonomy );
- else
- $link = get_term_link( intval($tag->term_id), $tag->taxonomy );
- if ( is_wp_error( $link ) )
- return false;
- $tags[ $key ]->link = $link;
- $tags[ $key ]->id = $tag->term_id;
- }
- $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
- $return = apply_filters( 'wp_tag_cloud', $return, $args );
- if ( 'array' == $args['format'] || empty($args['echo']) )
- return $return;
- echo $return;
- }
- add_action('init', 'codeboxrical', 0,1);
- function codeboxrical(){
- if (isset($_GET['ical']))
- {
- //add_action('init', 'cbraceical', 1,1);
- //remove_action('widgets_init','');
- cbraceical();
- //remove_action('wp_footer', '');
- }
- if (isset($_GET['icalpid']))
- {
- //add_action('init', 'cbraceicalpid', 1,1);
- //remove_action('widgets_init','');
- cbraceicalpid();
- }
- }
- //outputs ical for latest race events for before or up 2 months.
- function cbraceical(){
- global $wpdb;
- //define('WP_USE_THEMES', false);
- // clean the output buffer
- //$buf = ob_get_clean();
- //echo $buf;
- //ob_clean();
- //exit;
- if (isset($_GET["icaldebug"]))
- {
- define("DEBUG", true);
- }
- $blogName = get_bloginfo('name');
- $blogURL = get_bloginfo('home');
- if (!defined('DEBUG'))
- {
- header('Content-Type: text/calendar; charset=UTF-8');
- header('Content-Disposition: attachment; filename="iCal-Gangsperrelatest20.ics"');
- }
- $number = 20;
- $upmonth = 2;
- $downmonth = 2;
- $meta_query = array();
- if($upmonth > 0){
- $upmonth = strtotime("+" . $upmonth . " month");
- $upmonth = date("Y-m-d", $upmonth);
- $meta_query[] = array(
- 'key' => 'startdate',
- 'value' => $upmonth,
- 'compare' => '<=',
- 'type' => 'DATE',
- );
- }
- if($downmonth > 0){
- $downmonth = strtotime("-" . $downmonth . " month");
- $downmonth = date("Y-m-d", $downmonth);
- $meta_query[] = array(
- 'key' => 'startdate',
- 'value' => $downmonth,
- 'compare' => '>=',
- 'type' => 'DATE',
- );
- }
- $orderby = 'startdate';
- $query_args = array('post_type' => 'race', 'paged' => 1, 'posts_per_page' => $number,'order' => 'DESC', 'orderby' => $orderby);
- $query_args['meta_key'] = 'startdate';
- $query_args['orderby'] = 'meta_value';
- if(!empty($meta_query)){
- $query_args['meta_query'] = $meta_query;
- }
- //var_dump($query_args);
- query_posts($query_args);
- $events = "";
- $space = " ";
- while ( have_posts() ) : the_post();
- $id = get_the_ID();
- $startdate = get_post_meta( $id, 'startdate', true); //yyyy-mm-dd
- $starttime = get_post_meta( $id, 'starttime', true); //hh:mm
- $venue = get_post_meta( $id, 'venue', true);
- $racewebsite = get_post_meta( $id, 'racewebsite', true);
- //$startdate = convert_datetoukdate($startdate); //dd-mm-yyyy
- //echo '<li>: '.$startdate.' <a href="'.get_permalink().'">'.get_the_title().'</a></li>';
- $convertDateStart = explode("-", $startdate);
- //$convertDateEnd = explode("-", $post->eventEndDate);
- if (NULL != $starttime)
- {
- $convertHoursStart = explode(":", $starttime);
- }
- else
- {
- $convertHoursStart = explode(":", "20:00:00");
- }
- /*
- if (NULL != $post->eventEndTime)
- {
- $convertHoursEnd = explode(":", $post->eventEndTime);
- }
- */
- //else
- //{
- $convertHoursEnd = explode(":", "20:00:00");
- //}
- $convertedStart = mktime(
- $convertHoursStart[0] - get_option("gmt_offset"), //hours
- $convertHoursStart[1], //minutes
- $convertHoursStart[2], //seconds
- $convertDateStart[1], //month
- $convertDateStart[2], //day
- $convertDateStart[0] //year
- );
- $convertedEnd = mktime(
- $convertHoursEnd[0] - get_option("gmt_offset"), //hours
- $convertHoursEnd[1], //minutes
- $convertHoursEnd[2], //seconds
- $convertDateEnd[1], //month
- $convertDateEnd[2], //day
- $convertDateEnd[0] //year
- );
- $eventStart = date("Ymd\THis", $convertedStart) . "Z";
- $eventEnd = date("Ymd\THis", $convertedEnd) . "Z";
- $summary = get_the_title($id);
- $summary = str_replace(",", "\,", $summary);
- $summary = str_replace("\\", "\\\\", $summary);
- $summary = str_replace("\n", $space, strip_tags($summary));
- $summary = str_replace("\r", $space, strip_tags($summary));
- $description = get_the_excerpt();
- $description = str_replace(",", "\,", $description);
- $description = str_replace("\\", "\\\\", $description);
- $description = str_replace("\n", $space, strip_tags($description));
- $description = str_replace("\r", $space, strip_tags($description));
- $location = $venue;
- $link = $racewebsite;
- $uid = $id . "@" . get_bloginfo('home');
- $events .= "BEGIN:VEVENT\r\n";
- $events .= "UID:" . $uid . "\r\n";
- $events .= "DTSTART:" . $eventStart . "\r\n";
- $events .= "DTEND:" . $eventEnd . "\r\n";
- $events .= "LOCATION:" . $location . "\r\n";
- $events .= "SUMMARY:" . $summary . "\r\n";
- if (is_null($link))
- {
- // no link out
- $events .= "DESCRIPTION:" . $description . "\r\n";
- }
- else
- {
- // has link out
- $events .= "DESCRIPTION;ALTREP=\"" . $link . "\":";
- $events .= $description . "\r\n";
- }
- $events .= "END:VEVENT\r\n";
- $events .= "\r\n";
- endwhile;
- wp_reset_query(); //reset query
- $content = "BEGIN:VCALENDAR\r\n";
- $content .= "VERSION:2.0\r\n";
- $content .= "PRODID:-//" . $blogName . "//NONSGML v1.0//EN\r\n";
- $content .= "X-WR-CALNAME:" . $blogName . "\r\n";
- $content .= "X-ORIGINAL-URL:" . $blogURL . "\r\n";
- $content .= "X-WR-CALDESC:Events for " . $blogName . "\r\n";
- $content .= "CALSCALE:GREGORIAN\r\n";
- $content .= "METHOD:PUBLISH\r\n";
- $content .= $events;
- $content .= "END:VCALENDAR";
- echo $content;
- if (defined('DEBUG'))
- {
- echo "\n" . $queryEvents . "\n";
- echo $eventStart . "\n";
- }
- exit;
- }
- //outputs ical for latest race events for before or up 2 months.
- function cbraceicalpid(){
- global $wpdb;
- if (isset($_GET["icaldebug"]))
- {
- define("DEBUG", true);
- }
- $blogName = get_bloginfo('name');
- $blogURL = get_bloginfo('home');
- $icalpid = sanitize_text_field($_GET['icalpid']);
- $icalpid = intval($icalpid);
- $postitle = get_the_title($icalpid);
- //var_dump($postitle);
- if (!defined('DEBUG'))
- {
- header('Content-Type: text/calendar; charset=UTF-8');
- header('Content-Disposition: attachment; filename="iCal-Gangsperre-'.$postitle.'.ics"');
- }
- /*
- $number = 20;
- $upmonth = 2;
- $downmonth = 2;
- $meta_query = array();
- if($upmonth > 0){
- $upmonth = strtotime("+" . $upmonth . " month");
- $upmonth = date("Y-m-d", $upmonth);
- $meta_query[] = array(
- 'key' => 'startdate',
- 'value' => $upmonth,
- 'compare' => '<=',
- 'type' => 'DATE',
- );
- }
- if($downmonth > 0){
- $downmonth = strtotime("-" . $downmonth . " month");
- $downmonth = date("Y-m-d", $downmonth);
- $meta_query[] = array(
- 'key' => 'startdate',
- 'value' => $downmonth,
- 'compare' => '>=',
- 'type' => 'DATE',
- );
- }
- $orderby = 'startdate';
- */
- $query_args = array('post_type' => 'race','p' => $icalpid);
- /*
- $query_args['meta_key'] = 'startdate';
- $query_args['orderby'] = 'meta_value';
- if(!empty($meta_query)){
- $query_args['meta_query'] = $meta_query;
- }
- */
- //var_dump($query_args);
- query_posts($query_args);
- $events = "";
- $space = " ";
- while ( have_posts() ) : the_post();
- $id = get_the_ID();
- $startdate = get_post_meta( $id, 'startdate', true); //yyyy-mm-dd
- $starttime = get_post_meta( $id, 'starttime', true); //hh:mm
- $venue = get_post_meta( $id, 'venue', true);
- $racewebsite = get_post_meta( $id, 'racewebsite', true);
- //$startdate = convert_datetoukdate($startdate); //dd-mm-yyyy
- //echo '<li>: '.$startdate.' <a href="'.get_permalink().'">'.get_the_title().'</a></li>';
- $convertDateStart = explode("-", $startdate);
- //$convertDateEnd = explode("-", $post->eventEndDate);
- if (NULL != $starttime)
- {
- $convertHoursStart = explode(":", $starttime);
- }
- else
- {
- $convertHoursStart = explode(":", "20:00:00");
- }
- /*
- if (NULL != $post->eventEndTime)
- {
- $convertHoursEnd = explode(":", $post->eventEndTime);
- }
- */
- //else
- //{
- $convertHoursEnd = explode(":", "20:00:00");
- //}
- $convertedStart = mktime(
- $convertHoursStart[0] - get_option("gmt_offset"), //hours
- $convertHoursStart[1], //minutes
- $convertHoursStart[2], //seconds
- $convertDateStart[1], //month
- $convertDateStart[2], //day
- $convertDateStart[0] //year
- );
- $convertedEnd = mktime(
- $convertHoursEnd[0] - get_option("gmt_offset"), //hours
- $convertHoursEnd[1], //minutes
- $convertHoursEnd[2], //seconds
- $convertDateEnd[1], //month
- $convertDateEnd[2], //day
- $convertDateEnd[0] //year
- );
- $eventStart = date("Ymd\THis", $convertedStart) . "Z";
- $eventEnd = date("Ymd\THis", $convertedEnd) . "Z";
- $summary = get_the_title($id);
- $summary = str_replace(",", "\,", $summary);
- $summary = str_replace("\\", "\\\\", $summary);
- $summary = str_replace("\n", $space, strip_tags($summary));
- $summary = str_replace("\r", $space, strip_tags($summary));
- //$postitle = $summary;
- $description = get_the_excerpt();
- $description = str_replace(",", "\,", $description);
- $description = str_replace("\\", "\\\\", $description);
- $description = str_replace("\n", $space, strip_tags($description));
- $description = str_replace("\r", $space, strip_tags($description));
- $location = $venue;
- $link = $racewebsite;
- $uid = $id . "@" . get_bloginfo('home');
- $events .= "BEGIN:VEVENT\r\n";
- $events .= "UID:" . $uid . "\r\n";
- $events .= "DTSTART:" . $eventStart . "\r\n";
- $events .= "DTEND:" . $eventEnd . "\r\n";
- $events .= "LOCATION:" . $location . "\r\n";
- $events .= "SUMMARY:" . $summary . "\r\n";
- if (is_null($link))
- {
- // no link out
- $events .= "DESCRIPTION:" . $description . "\r\n";
- }
- else
- {
- // has link out
- $events .= "DESCRIPTION;ALTREP=\"" . $link . "\":";
- $events .= $description . "\r\n";
- }
- $events .= "END:VEVENT\r\n";
- $events .= "\r\n";
- endwhile;
- wp_reset_query(); //reset query
- $content = "BEGIN:VCALENDAR\r\n";
- $content .= "VERSION:2.0\r\n";
- $content .= "PRODID:-//" . $blogName . "//NONSGML v1.0//EN\r\n";
- $content .= "X-WR-CALNAME:" . $blogName . "\r\n";
- $content .= "X-ORIGINAL-URL:" . $blogURL . "\r\n";
- $content .= "X-WR-CALDESC:Events for " . $blogName . "\r\n";
- $content .= "CALSCALE:GREGORIAN\r\n";
- $content .= "METHOD:PUBLISH\r\n";
- $content .= $events;
- $content .= "END:VCALENDAR";
- echo $content;
- if (defined('DEBUG'))
- {
- echo "\n" . $queryEvents . "\n";
- echo $eventStart . "\n";
- }
- exit;
- }
- function insert_attachment($file_handler,$post_id,$setthumb='false') {
- // check to make sure its a successful upload
- if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
- //if ($file_handler['error'] !== UPLOAD_ERR_OK) __return_false();
- require_once(ABSPATH . "wp-admin" . '/includes/image.php');
- require_once(ABSPATH . "wp-admin" . '/includes/file.php');
- require_once(ABSPATH . "wp-admin" . '/includes/media.php');
- $attach_id = media_handle_upload( $file_handler, $post_id );
- //var_dump($attach_id);
- if(!is_wp_error($attach_id)):
- if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id);
- endif;
- return $attach_id;
- }
- function cbrtp_display_to_content(){
- $display = '';
- if(function_exists('rtp_display_template')):
- $display = rtp_display_template();
- endif;
- return $display;
- }
- /**
- * Display or retrieve the HTML dropdown list of categories.
- *
- * The list of arguments is below:
- * 'show_option_all' (string) - Text to display for showing all categories.
- * 'show_option_none' (string) - Text to display for showing no categories.
- * 'orderby' (string) default is 'ID' - What column to use for ordering the
- * categories.
- * 'order' (string) default is 'ASC' - What direction to order categories.
- * 'show_last_update' (bool|int) default is 0 - See {@link get_categories()}
- * 'show_count' (bool|int) default is 0 - Whether to show how many posts are
- * in the category.
- * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
- * don't have any posts attached to them.
- * 'child_of' (int) default is 0 - See {@link get_categories()}.
- * 'exclude' (string) - See {@link get_categories()}.
- * 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
- * 'depth' (int) - The max depth.
- * 'tab_index' (int) - Tab index for select element.
- * 'name' (string) - The name attribute value for select element.
- * 'id' (string) - The ID attribute value for select element. Defaults to name if omitted.
- * 'class' (string) - The class attribute value for select element.
- * 'selected' (int) - Which category ID is selected.
- * 'taxonomy' (string) - The name of the taxonomy to retrieve. Defaults to category.
- *
- * The 'hierarchical' argument, which is disabled by default, will override the
- * depth argument, unless it is true. When the argument is false, it will
- * display all of the categories. When it is enabled it will use the value in
- * the 'depth' argument.
- *
- * @since 2.1.0
- *
- * @param string|array $args Optional. Override default arguments.
- * @return string HTML content only if 'echo' argument is 0.
- */
- function cb_wp_dropdown_categories( $args = '' ) {
- $defaults = array(
- 'show_option_all' => '', 'show_option_none' => '',
- 'orderby' => 'id', 'order' => 'ASC',
- 'show_last_update' => 0, 'show_count' => 0,
- 'hide_empty' => 1, 'child_of' => 0,
- 'exclude' => '', 'echo' => 1,
- 'selected' => 0, 'hierarchical' => 0,
- 'name' => 'cat', 'id' => '',
- 'class' => 'postform', 'depth' => 0,
- 'tab_index' => 0, 'taxonomy' => 'category',
- 'hide_if_empty' => false
- );
- $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
- // Back compat.
- if ( isset( $args['type'] ) && 'link' == $args['type'] ) {
- _deprecated_argument( __FUNCTION__, '3.0', '' );
- $args['taxonomy'] = 'link_category';
- }
- $r = wp_parse_args( $args, $defaults );
- if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
- $r['pad_counts'] = true;
- }
- $r['include_last_update_time'] = $r['show_last_update'];
- extract( $r );
- $tab_index_attribute = '';
- if ( (int) $tab_index > 0 )
- $tab_index_attribute = " tabindex=\"$tab_index\"";
- $categories = get_terms( $taxonomy, $r );
- $name = esc_attr( $name );
- $class = esc_attr( $class );
- $id = $id ? esc_attr( $id ) : $name;
- if ( ! $r['hide_if_empty'] || ! empty($categories) )
- $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
- else
- $output = '';
- if ( empty($categories) && ! $r['hide_if_empty'] && !empty($show_option_none) ) {
- $show_option_none = apply_filters( 'list_cats', $show_option_none );
- $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
- }
- if ( ! empty( $categories ) ) {
- if ( $show_option_all ) {
- $show_option_all = apply_filters( 'list_cats', $show_option_all );
- $selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';
- $output .= "\t<option value='0'$selected>$show_option_all</option>\n";
- }
- if ( $show_option_none ) {
- $show_option_none = apply_filters( 'list_cats', $show_option_none );
- $selected = ( '-1' === strval($r['selected']) ) ? " selected='selected'" : '';
- $output .= "\t<option value='-1'$selected>$show_option_none</option>\n";
- }
- if ( $hierarchical )
- $depth = $r['depth']; // Walk the full depth.
- else
- $depth = -1; // Flat.
- $output .= walk_category_dropdown_tree( $categories, $depth, $r );
- }
- if ( ! $r['hide_if_empty'] || ! empty($categories) )
- $output .= "</select>\n";
- $output = apply_filters( 'wp_dropdown_cats', $output );
- if ( $echo )
- echo $output;
- return $output;
- }
- add_action('wp_ajax_cbajaxracevote', 'cbajaxracevote');
- function cbajaxracevote(){
- ob_clean();
- check_ajax_referer('raceresult');
- if(!is_user_logged_in()){echo 'Something wrong!';}
- global $userdata;
- //var_dump($userdata);
- $accessid = $userdata->data->ID;
- //var_dump($accessid);
- $userid = esc_attr($_POST['userid']);
- $postid = esc_attr($_POST['postid']);
- //var_dump($postid);
- $resulturl = esc_url($_POST['resulturl']);
- if($userid != $accessid){ echo 'Something wrong!';}
- else{
- $mypost = get_post($postid);
- //var_dump($mypost);
- $authorid = $mypost->post_author;
- //var_dump($authorid);
- if($authorid != $userid){ echo 'Something wrong!';}
- else{
- $result = update_post_meta($postid, "resulturl", $resulturl);
- if($result) {echo 'Result url updated!';}
- else{echo 'Something wrong!';}
- }
- }
- die();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement