Advertisement
manchumahara

Functions.php file from Race Calender

Aug 5th, 2012
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 141.11 KB | None | 0 0
  1. <?php
  2. /**
  3.  * TwentyTen functions and definitions
  4.  *
  5.  * Sets up the theme and provides some helper functions. Some helper functions
  6.  * are used in the theme as custom template tags. Others are attached to action and
  7.  * filter hooks in WordPress to change core functionality.
  8.  *
  9.  * The first function, twentyten_setup(), sets up the theme by registering support
  10.  * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
  11.  *
  12.  * When using a child theme (see http://codex.wordpress.org/Theme_Development and
  13.  * http://codex.wordpress.org/Child_Themes), you can override certain functions
  14.  * (those wrapped in a function_exists() call) by defining them first in your child theme's
  15.  * functions.php file. The child theme's functions.php file is included before the parent
  16.  * theme's file, so the child theme functions would be used.
  17.  *
  18.  * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
  19.  * to a filter or action hook. The hook can be removed by using remove_action() or
  20.  * remove_filter() and you can attach your own function to the hook.
  21.  *
  22.  * We can remove the parent theme's hook only after it is attached, which means we need to
  23.  * wait until setting up the child theme:
  24.  *
  25.  * <code>
  26.  * add_action( 'after_setup_theme', 'my_child_theme_setup' );
  27.  * function my_child_theme_setup() {
  28.  *     // We are providing our own filter for excerpt_length (or using the unfiltered value)
  29.  *     remove_filter( 'excerpt_length', 'twentyten_excerpt_length' );
  30.  *     ...
  31.  * }
  32.  * </code>
  33.  *
  34.  * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
  35.  *
  36.  * @package WordPress
  37.  * @subpackage Twenty_Ten
  38.  * @since Twenty Ten 1.0
  39.  */
  40. global  $userdata,$user_ID, $user_identity, $user_level;
  41. $wpdb->cbzipcode = $wpdb->prefix.'cbzipcode';
  42. function zipcodes_exists($field, $value) {
  43.     global $wpdb;
  44.         if($field == 'zipcode') { $value = $value;}
  45.         if(empty($value)) return false;
  46.     if ( !$result = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->cbzipcode WHERE $field = %s", $value) ) )
  47.         return false;  
  48.     return $result;
  49. }
  50.  
  51. function zipcodes_latlng($value) {
  52.     global $wpdb;
  53.         $field = 'zipcode';
  54.         if(empty($value)) return false;
  55.     if ( !$result = $wpdb->get_row( $wpdb->prepare("SELECT latitude, longitude FROM $wpdb->cbzipcode WHERE $field = %s", $value) ) )
  56.         return false;
  57.     return $result;
  58. }
  59.  
  60. $userexpired = false;
  61. /*
  62. if(is_user_logged_in()){
  63.     $packageexp     = get_user_meta($user_ID, 'packageexp', true); //date in Y-m-d format
  64.     $todays_date    = date("Y-m-d");
  65.     $today          = strtotime($todays_date);
  66.     $packageexp     = strtotime($packageexp);
  67.     //var_dump($today);
  68.     //var_dump($packageexp);
  69.     if(($today > $packageexp) && ($userdata->rdrole == 'parents')) {
  70.         $userexpired = true;
  71.      }
  72. }
  73. */
  74. $codeboxr_invitecode        =  get_option('codeboxr_invitecode');
  75. $codeboxr_inviteon          =  intval(get_option('codeboxr_inviteon'));
  76.  
  77. $spages                 = get_option('codeboxr_spages');
  78. if(!is_array($spages)){
  79.     $spages = array (
  80.         'termspage'             => 0,
  81.         'privacypage'           => 0,
  82.         'regipage'              => 0,
  83.         'profilepage'           => 0,
  84.         'jobpostpage'           => 0,
  85.         'cdpage'                => 0,
  86.         'myrdpage'              => 0,
  87.         'racelist'              => 0
  88.         /*'jobsearchpage'         => 0,
  89.         'driversearchpage'      => 0,
  90.         'jobapplypage'          => 0,
  91.         'writereviewpage'       => 0,
  92.         'myjobapppage'          => 0,
  93.         'viewjobapppage'        => 0,
  94.         'alljobapppage'         => 0,
  95.         'allreviewpage'         => 0,
  96.         'postedjobpage'         => 0,
  97.         'myreviewspage'         => 0,
  98.         'mytestipage'           => 0,        
  99.         'availability'          => 0,
  100.         'sendmessage'           => 0,
  101.         'messaging'             => 0,
  102.         'avatarupload'          => 0,
  103.         'subscription'          => 0*/
  104.     );
  105. }
  106. $spages                  = cb_convertArrayToObject($spages);
  107. /*
  108. $packagep                = get_option('codeboxr_package');
  109. if(!is_array($packagep)){
  110.     $packagep = array (
  111.         'package0' => 0,
  112.         'package1' => 0,
  113.         'package2' => 0,
  114.         'package3' => 0
  115.     );
  116. }
  117.  
  118. $packagep   = cb_convertArrayToObject($packagep);
  119.  
  120. $merchant               = get_option('codeboxr_merchant');
  121. if(!is_array($merchant)){
  122.     $merchant = array(
  123.         'testmode'      => 'no',
  124.         'homeurl'       => '',
  125.         'retadd'        => 0,
  126.         'vendorid'      => '',
  127.         'vendorname'    => '',
  128.         'vendoridt'     => 0,
  129.         'vendornamet'   => '',
  130.         'showitems'     => 0,
  131.         'acceptcards'   => 0,
  132.         'acceptchecks'  => 0,
  133.         'accepteft'     => 0
  134.     );
  135. }
  136. $merchant   = cb_convertArrayToObject($merchant);
  137. */
  138. $mailtemplates          = get_option('codeboxr_mailtemplates');
  139. if(!is_array($mailtemplates)){
  140.     $mailtemplates = array(
  141.         'footer'      => '',
  142.         'regif'       => '',
  143.         'regid'       => '',
  144.         'msgt'        => '',
  145.         'sub'         => '',
  146.         'subex'       => '',
  147.         'uterm'       => '',
  148.         'preset'      => ''
  149.  
  150.     );
  151. }
  152. $mailtemplates   = cb_convertArrayToObject($mailtemplates);
  153.  
  154. $snetwork               = get_option('codeboxr_snetwork');
  155. if(!is_array($snetwork)){
  156.     $snetwork = array(
  157.         'rss' => array('url' => '#', 'status' => 0),
  158.         'fb'  => array('url' => '#', 'status' => 0),
  159.         'tw'  => array('url' => '#', 'status' => 0),
  160.         'yt'  => array('url' => '#', 'status' => 0),
  161.         'ct'  => array('url' => '#', 'status' => 0),
  162.         'ic'  => array('url' => '#', 'status' => 0)
  163.     );
  164. }
  165. $snetwork = cb_convertArrayToObject($snetwork);
  166.  
  167. $slider                 = get_option('slider');
  168. if(!is_array($slider)){
  169.     $slider = array(
  170.         'speed'         => 500,
  171.         'pausetime'     => 5000,
  172.         'slide1'        => '',
  173.         'slide2'        => '',
  174.         'slide3'        => '',
  175.         'slide4'        => '',
  176.         'slide5'        => '',
  177.         'slide6'        => ''
  178.     );
  179. }
  180. $slider = cb_convertArrayToObject($slider);
  181.  
  182.  
  183. $banner                 = get_option('banner');
  184. if(!is_array($banner)){
  185.     $banner = array(
  186.         'b1'    => array('status' => 0,    'col' => 1,
  187.                             'img' => array(
  188.                                     'b11img' => '',
  189.                                     'b12img' => '',
  190.                                     'b13img' => '',
  191.                                     'b14img' => ''
  192.                             ),                
  193.                             'url' => array(
  194.                                     'b11url' => '#',
  195.                                     'b12url' => '#',
  196.                                     'b13url' => '#',
  197.                                     'b14url' => '#'
  198.                             )
  199.                          ),
  200.         'b2'    => array('status' => 0,    'col' => 1,
  201.                             'img' => array(
  202.                                     'b21img' => '',
  203.                                     'b22img' => '',
  204.                                     'b23img' => '',
  205.                                     'b24img' => ''
  206.                             ),                
  207.                             'url' => array(
  208.                                     'b21url' => '#',
  209.                                     'b22url' => '#',
  210.                                     'b23url' => '#',
  211.                                     'b24url' => '#'
  212.                             )
  213.                         ),
  214.         'b3'    => array('status' => 0,    'col' => 1,
  215.                         'img' => array(
  216.                                     'b31img' => '',
  217.                                     'b32img' => '',
  218.                                     'b33img' => '',
  219.                                     'b34img' => ''
  220.                             ),                
  221.                             'url' => array(
  222.                                     'b31url' => '#',
  223.                                     'b32url' => '#',
  224.                                     'b33url' => '#',
  225.                                     'b34url' => '#'
  226.                             )    
  227.                         )
  228.                
  229.     );
  230. }
  231. $banner = cb_convertArrayToObject($banner);        
  232.        
  233. include_once TEMPLATEPATH."/setting.php";
  234.  
  235. //recaptcha setting and initialization
  236. if(!function_exists('recaptcha_get_html')):
  237.     require_once(TEMPLATEPATH.'/libs/recaptcha/recaptchalib.php');
  238. endif;
  239. // Get a key from https://www.google.com/recaptcha/admin/create
  240. // this keys are for codeboxr.com
  241.  
  242. $recaptcha                 = get_option('recaptcha');
  243. if(!is_array($recaptcha)){
  244.     $recaptcha = array(
  245.         'publickey'         => '6LdRU8kSAAAAAEhXoo5Euowk8cZEuwv9nwOXJd71',
  246.         'privatekey'        => '6LdRU8kSAAAAAC7IDKeJyT0h8RHRtK2hzPZZvgbw'                
  247.     );
  248. }
  249. $recaptcha = cb_convertArrayToObject($recaptcha);
  250.  
  251. //$recaptcha_publickey    = "6LdRU8kSAAAAAEhXoo5Euowk8cZEuwv9nwOXJd71";
  252. //$recaptcha_privatekey   = "6LdRU8kSAAAAAC7IDKeJyT0h8RHRtK2hzPZZvgbw";
  253. $recaptcha_publickey    = $recaptcha->publickey;
  254. $recaptcha_privatekey   = $recaptcha->privatekey;
  255.  
  256. //end recapctha
  257.  
  258.  
  259. //includes widgets here
  260. include_once TEMPLATEPATH."/rdwidgets/rdwidgets.php";
  261.  
  262. function add_themescript(){
  263.     global $spages;
  264.     if(!is_admin()){
  265.         wp_enqueue_script('jquery');
  266.        
  267.         //echo $spages->avatarupload;
  268.        
  269.         //wp_enqueue_script('jqueryeasing', get_bloginfo('template_directory').'/js/slides/jquery.easing.js', array('jquery'), '1.0');
  270.         //wp_enqueue_script('slidejs', get_bloginfo('template_directory').'/js/slides/script.js', array('jquery'), '1.0');
  271.         //wp_enqueue_script('thickbox',null,array('jquery'));
  272.         //wp_enqueue_script('tinycarousel', get_bloginfo('template_directory').'/js/jquery.tinycarousel.min.js', array('jquery'), '10');
  273.         //wp_enqueue_style('thickbox.css', '/'.WPINC.'/js/thickbox/thickbox.css', null, '1.0');
  274.         //wp_enqueue_style('slidecss', get_bloginfo('template_directory').'/js/slides/style.css', null, '1.3');
  275.         wp_enqueue_style('wp-paginate', get_bloginfo('template_directory').'/wp-paginate.css', false, 4, 'screen');
  276.        
  277.     }
  278.    
  279.  
  280. }
  281. function add_recaptchajs(){
  282.     echo '<script type="text/javascript">
  283. var RecaptchaOptions = {
  284.    theme : \'clean\'
  285. };
  286. </script>';
  287. }
  288. function add_themescript2(){
  289.     global $spages;
  290.     if(is_page($spages->jobpostpage)){
  291.         //var_dump('test is here');
  292.         add_action('wp_head', 'add_recaptchajs');        
  293.         wp_enqueue_script("jquery");          
  294.         wp_enqueue_style('datepickcss', get_bloginfo('template_directory').'/css/datepicker/ui.datepick.css', null, '2');
  295.         wp_enqueue_script('datepickjs', get_bloginfo('template_directory').'/js/datepicker/jquery.datepick.js', array('jquery'), '1.1');                
  296.     }
  297.     if(is_page($spages->racelist)){
  298.         wp_enqueue_script("jquery");        
  299.         wp_enqueue_style('datepickcss', get_bloginfo('template_directory').'/css/datepicker/ui.datepick.css', null, '2');
  300.         wp_enqueue_script('datepickjs', get_bloginfo('template_directory').'/js/datepicker/jquery.datepick.js', array('jquery'), '1.1');        
  301.     }
  302.     /*
  303.     if(is_page($spages->avatarupload)){
  304.         wp_enqueue_script('imgareaselect', get_bloginfo('template_directory').'/js/crop/jquery.imgareaselect.pack.js', array('jquery'), '1.0');
  305.         wp_enqueue_style('imgareaselect', get_bloginfo('template_directory').'/css/crop/imgareaselect-animated.css', null, '1.3');
  306.     }
  307.     */
  308. }
  309. add_action('init','add_themescript');
  310. add_action('template_redirect', 'add_themescript2');
  311.  
  312. /** Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */
  313. add_action( 'after_setup_theme', 'twentyten_setup' );
  314.  
  315. if ( ! function_exists( 'twentyten_setup' ) ):
  316. /**
  317.  * Sets up theme defaults and registers support for various WordPress features.
  318.  *
  319.  * Note that this function is hooked into the after_setup_theme hook, which runs
  320.  * before the init hook. The init hook is too late for some features, such as indicating
  321.  * support post thumbnails.
  322.  *
  323.  * To override twentyten_setup() in a child theme, add your own twentyten_setup to your child theme's
  324.  * functions.php file.
  325.  *
  326.  * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
  327.  * @uses register_nav_menus() To add support for navigation menus.
  328.  * @uses add_custom_background() To add support for a custom background.
  329.  * @uses add_editor_style() To style the visual editor.
  330.  * @uses load_theme_textdomain() For translation/localization support.
  331.  * @uses add_custom_image_header() To add support for a custom header.
  332.  * @uses register_default_headers() To register the default custom header images provided with the theme.
  333.  * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  334.  *
  335.  * @since Twenty Ten 1.0
  336.  */
  337. function twentyten_setup() {
  338.  
  339.     // This theme styles the visual editor with editor-style.css to match the theme style.
  340.     add_editor_style();
  341.  
  342.     // Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories.
  343.     //add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
  344.  
  345.     // This theme uses post thumbnails
  346.     add_theme_support( 'post-thumbnails' );
  347.  
  348.     // Add default posts and comments RSS feed links to head
  349.     add_theme_support( 'automatic-feed-links' );
  350.  
  351.     // Make theme available for translation
  352.     // Translations can be filed in the /languages/ directory
  353.     load_theme_textdomain( 'twentyten', TEMPLATEPATH . '/languages' );
  354.  
  355.     $locale = get_locale();
  356.     $locale_file = TEMPLATEPATH . "/languages/$locale.php";
  357.     if ( is_readable( $locale_file ) )
  358.         require_once( $locale_file );
  359.  
  360.     // This theme uses wp_nav_menu() in one location.
  361.     register_nav_menus( array(
  362.         'mainmenu' => __( 'Main Navigation', 'twentyten' ),
  363.     ) );
  364.         register_nav_menus( array(
  365.         'topmenu' => __( 'Top Navigation', 'twentyten' ),
  366.     ) );
  367.         register_nav_menus( array(
  368.         'footermenu' => __( 'Footer Navigation', 'twentyten' ),
  369.     ) );
  370.  
  371.     // This theme allows users to set a custom background  
  372.  
  373.    
  374.  
  375.    
  376. }
  377. endif;
  378.  
  379. if ( ! function_exists( 'twentyten_admin_header_style' ) ) :
  380. /**
  381.  * Styles the header image displayed on the Appearance > Header admin panel.
  382.  *
  383.  * Referenced via add_custom_image_header() in twentyten_setup().
  384.  *
  385.  * @since Twenty Ten 1.0
  386.  */
  387. function twentyten_admin_header_style() {
  388. ?>
  389. <style type="text/css">
  390. /* Shows the same border as on front end */
  391. #headimg {
  392.     border-bottom: 1px solid #000;
  393.     border-top: 4px solid #000;
  394. }
  395. /* If NO_HEADER_TEXT is false, you would style the text with these selectors:
  396.     #headimg #name { }
  397.     #headimg #desc { }
  398. */
  399. </style>
  400. <?php
  401. }
  402. endif;
  403.  
  404. /**
  405.  * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  406.  *
  407.  * To override this in a child theme, remove the filter and optionally add
  408.  * your own function tied to the wp_page_menu_args filter hook.
  409.  *
  410.  * @since Twenty Ten 1.0
  411.  */
  412. function twentyten_page_menu_args( $args ) {
  413.     $args['show_home'] = true;
  414.     return $args;
  415. }
  416. add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );
  417.  
  418. /**
  419.  * Sets the post excerpt length to 40 characters.
  420.  *
  421.  * To override this length in a child theme, remove the filter and add your own
  422.  * function tied to the excerpt_length filter hook.
  423.  *
  424.  * @since Twenty Ten 1.0
  425.  * @return int
  426.  */
  427. function twentyten_excerpt_length( $length ) {
  428.     return 40;
  429. }
  430. add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
  431.  
  432. /**
  433.  * Returns a "Continue Reading" link for excerpts
  434.  *
  435.  * @since Twenty Ten 1.0
  436.  * @return string "Continue Reading" link
  437.  */
  438. function twentyten_continue_reading_link() {
  439.     return ' <a class="readmore" href="'. get_permalink() . '">' . __( 'Read More', 'twentyten' ) . '</a>';
  440. }
  441.  
  442. /**
  443.  * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link().
  444.  *
  445.  * To override this in a child theme, remove the filter and add your own
  446.  * function tied to the excerpt_more filter hook.
  447.  *
  448.  * @since Twenty Ten 1.0
  449.  * @return string An ellipsis
  450.  */
  451. function twentyten_auto_excerpt_more( $more ) {
  452.     return ' &hellip;' . twentyten_continue_reading_link();
  453. }
  454. add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
  455.  
  456. /**
  457.  * Adds a pretty "Continue Reading" link to custom post excerpts.
  458.  *
  459.  * To override this link in a child theme, remove the filter and add your own
  460.  * function tied to the get_the_excerpt filter hook.
  461.  *
  462.  * @since Twenty Ten 1.0
  463.  * @return string Excerpt with a pretty "Continue Reading" link
  464.  */
  465. function twentyten_custom_excerpt_more( $output ) {
  466.     if ( has_excerpt() && ! is_attachment() ) {
  467.         $output .= twentyten_continue_reading_link();
  468.     }
  469.     return $output;
  470. }
  471. add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
  472.  
  473. /**
  474.  * Remove inline styles printed when the gallery shortcode is used.
  475.  *
  476.  * Galleries are styled by the theme in Twenty Ten's style.css. This is just
  477.  * a simple filter call that tells WordPress to not use the default styles.
  478.  *
  479.  * @since Twenty Ten 1.2
  480.  */
  481. add_filter( 'use_default_gallery_style', '__return_false' );
  482.  
  483. /**
  484.  * Deprecated way to remove inline styles printed when the gallery shortcode is used.
  485.  *
  486.  * This function is no longer needed or used. Use the use_default_gallery_style
  487.  * filter instead, as seen above.
  488.  *
  489.  * @since Twenty Ten 1.0
  490.  * @deprecated Deprecated in Twenty Ten 1.2 for WordPress 3.1
  491.  *
  492.  * @return string The gallery style filter, with the styles themselves removed.
  493.  */
  494. function twentyten_remove_gallery_css( $css ) {
  495.     return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
  496. }
  497. // Backwards compatibility with WordPress 3.0.
  498. if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) )
  499.     add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
  500.  
  501. if ( ! function_exists( 'twentyten_comment' ) ) :
  502. /**
  503.  * Template for comments and pingbacks.
  504.  *
  505.  * To override this walker in a child theme without modifying the comments template
  506.  * simply create your own twentyten_comment(), and that function will be used instead.
  507.  *
  508.  * Used as a callback by wp_list_comments() for displaying the comments.
  509.  *
  510.  * @since Twenty Ten 1.0
  511.  */
  512. function twentyten_comment( $comment, $args, $depth ) {
  513.     $GLOBALS['comment'] = $comment;
  514.     switch ( $comment->comment_type ) :
  515.         case '' :
  516.     ?>
  517.     <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  518.         <div id="comment-<?php comment_ID(); ?>">
  519.         <div class="comment-author vcard">
  520.             <?php echo get_avatar( $comment, 40 ); ?>
  521.             <?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
  522.         </div><!-- .comment-author .vcard -->
  523.         <?php if ( $comment->comment_approved == '0' ) : ?>
  524.             <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
  525.             <br />
  526.         <?php endif; ?>
  527.  
  528.         <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
  529.             <?php
  530.                 /* translators: 1: date, 2: time */
  531.                 printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
  532.             ?>
  533.         </div><!-- .comment-meta .commentmetadata -->
  534.  
  535.         <div class="comment-body"><?php comment_text(); ?></div>
  536.  
  537.         <div class="reply">
  538.             <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  539.         </div><!-- .reply -->
  540.     </div><!-- #comment-##  -->
  541.  
  542.     <?php
  543.             break;
  544.         case 'pingback'  :
  545.         case 'trackback' :
  546.     ?>
  547.     <li class="post pingback">
  548.         <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p>
  549.     <?php
  550.             break;
  551.     endswitch;
  552. }
  553. endif;
  554.  
  555. /**
  556.  * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
  557.  *
  558.  * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own
  559.  * function tied to the init hook.
  560.  *
  561.  * @since Twenty Ten 1.0
  562.  * @uses register_sidebar
  563.  */
  564. function twentyten_widgets_init() {
  565.     // Area 1, located at the top of the sidebar.
  566.     register_sidebar( array(
  567.         'name' => __( 'Primary Widget Area', 'twentyten' ),
  568.         'id' => 'primary-widget-area',
  569.         'description' => __( 'The primary widget area', 'twentyten' ),
  570.         'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
  571.         'after_widget' => '</div>',
  572.         'before_title' => '<h3 class="widget-title">',
  573.         'after_title' => '</h3>',
  574.     ) );
  575.  
  576.     // Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
  577.     register_sidebar( array(
  578.         'name' => __( 'Secondary Widget Area', 'twentyten' ),
  579.         'id' => 'secondary-widget-area',
  580.         'description' => __( 'The secondary widget area', 'twentyten' ),
  581.         'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
  582.         'after_widget' => '</div>',
  583.         'before_title' => '<h3 class="widget-title">',
  584.         'after_title' => '</h3>',
  585.     ) );
  586.        
  587.         // Sidebar for home page
  588.     register_sidebar( array(
  589.         'name' => __( 'Home Widget Area', 'twentyten' ),
  590.         'id' => 'home-widget-area',
  591.         'description' => __( 'The home widget area', 'twentyten' ),
  592.         'before_widget' => '<div id="%1$s" class="widget-container homewidget-container %2$s">',
  593.         'after_widget' => '</div>',
  594.         'before_title' => '<h3 class="widget-title homewidget-title">',
  595.         'after_title' => '</h3>',
  596.     ) );
  597.    
  598. }
  599. /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
  600. add_action( 'widgets_init', 'twentyten_widgets_init' );
  601.  
  602. /**
  603.  * Removes the default styles that are packaged with the Recent Comments widget.
  604.  *
  605.  * To override this in a child theme, remove the filter and optionally add your own
  606.  * function tied to the widgets_init action hook.
  607.  *
  608.  * This function uses a filter (show_recent_comments_widget_style) new in WordPress 3.1
  609.  * to remove the default style. Using Twenty Ten 1.2 in WordPress 3.0 will show the styles,
  610.  * but they won't have any effect on the widget in default Twenty Ten styling.
  611.  *
  612.  * @since Twenty Ten 1.0
  613.  */
  614. function twentyten_remove_recent_comments_style() {
  615.     add_filter( 'show_recent_comments_widget_style', '__return_false' );
  616. }
  617. add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );
  618.  
  619. if ( ! function_exists( 'twentyten_posted_on' ) ) :
  620. /**
  621.  * Prints HTML with meta information for the current post-date/time and author.
  622.  *
  623.  * @since Twenty Ten 1.0
  624.  */
  625. function twentyten_posted_on() {
  626.     printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
  627.         'meta-prep meta-prep-author',
  628.         sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
  629.             get_permalink(),
  630.             esc_attr( get_the_time() ),
  631.             get_the_date()
  632.         ),
  633.         sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
  634.             get_author_posts_url( get_the_author_meta( 'ID' ) ),
  635.             sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
  636.             get_the_author()
  637.         )
  638.     );
  639. }
  640. endif;
  641.  
  642. if ( ! function_exists( 'twentyten_posted_in' ) ) :
  643. /**
  644.  * Prints HTML with meta information for the current post (category, tags and permalink).
  645.  *
  646.  * @since Twenty Ten 1.0
  647.  */
  648. function twentyten_posted_in() {
  649.     // Retrieves tag list of current post, separated by commas.
  650.     $tag_list = get_the_tag_list( '', ', ' );
  651.     if ( $tag_list ) {
  652.         $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' );
  653.     } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
  654.         $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' );
  655.     } else {
  656.         $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
  657.     }
  658.     // Prints the string, replacing the placeholders.
  659.     printf(
  660.         $posted_in,
  661.         get_the_category_list( ', ' ),
  662.         $tag_list,
  663.         get_permalink(),
  664.         the_title_attribute( 'echo=0' )
  665.     );
  666. }
  667. endif;
  668. function walker_nav_menu_start_el_adddepth($item_output, $item, $depth, $args)
  669. {
  670.     $item_output = str_replace('<a href="', '<a class="level_'.$depth.'" href="',$item_output);
  671.     return $item_output;
  672.  
  673. }
  674. add_filter('walker_nav_menu_start_el','walker_nav_menu_start_el_adddepth', 10,4);
  675.  
  676. function cb_convertArrayToObject($myarray) {
  677.     $return = new stdClass();
  678.     foreach ($myarray as $key => $value) {
  679.     if (is_array($value)) {
  680.     $return->$key = cb_convertArrayToObject($value);
  681.     }
  682.     else {
  683.     $return->$key = $value;
  684.     }
  685.     }
  686.     return $return;
  687. }
  688.  
  689. // custom login for theme
  690. function cb_custom_login() {
  691.         if(stripos($_SERVER['REQUEST_URI'],'wp-login.php') !== false){
  692.             echo '<link rel="stylesheet" type="text/css" href="' . get_bloginfo('template_directory') . '/custom-login.css?v=2" />';
  693.         }
  694. }
  695. function cb_change_wp_login_url() {
  696.     echo bloginfo('url');
  697. }
  698.  
  699. function cb_change_wp_login_title() {
  700.     echo 'Welcome to ' . get_option('blogname');
  701. }
  702.  
  703. add_action('login_head', 'cb_custom_login',10);
  704. add_filter('login_headerurl', 'cb_change_wp_login_url');
  705. add_filter('login_headertitle', 'cb_change_wp_login_title');
  706. //Define the function which unsets the boxes
  707. function remove_dashboard_widgets() {
  708.         global $wp_meta_boxes;
  709.         //myprint_r($wp_meta_boxes);
  710.         //var_dump('<pre>'.$wp_meta_boxes.'</pre>');
  711.  
  712.         //unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
  713.         # Remove plugins feed
  714.        unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
  715.         unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_plugins']);
  716.         # Remove "WordPress News"
  717.        unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_primary']);
  718.         unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
  719.         unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_secondary']);
  720.         unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
  721.         # Remove incoming links feed
  722.        unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
  723.         unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_incoming_links']);
  724.  
  725.         unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
  726.         unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
  727.         unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
  728.         //unset($wp_meta_boxes['dashboard']['normal']['core']['events_dashboard_window']);
  729.  
  730. }
  731. // Now hook in to the action
  732. add_action('wp_dashboard_setup', 'remove_dashboard_widgets', 20, 0);
  733.  
  734. function change_footer_content () {
  735.     echo 'Copyright &copy; 2011 '.get_option('blogname').' .All Rights Reserved';
  736. }
  737. add_filter('admin_footer_text', 'change_footer_content');
  738.  
  739. function custom_admin_branding_header() {
  740.     echo '
  741.    <style>
  742.        #header-logo {
  743.            background-image: none;
  744.        }
  745.    </style>
  746.    ';
  747. }
  748. //add_action('admin_head', 'custom_admin_branding_header', 11);
  749. function hide_some_profilefields( $contactmethods ) {
  750.   unset($contactmethods['aim']);
  751.   unset($contactmethods['jabber']);
  752.   unset($contactmethods['yim']);
  753.   //unset($contactmethods['url']);
  754.   //unset($contactmethods['description']);
  755.   return $contactmethods;
  756. }
  757. add_filter('user_contactmethods','hide_some_profilefields',10,1);
  758.  
  759. function admin_del_color_options() {
  760.    global $_wp_admin_css_colors;
  761.    $_wp_admin_css_colors = 0;
  762. }
  763.  
  764. add_action('admin_head', 'admin_del_color_options',10,1);
  765.  
  766. //add_action('show_user_profile', 'cb_show_user_profile',10,1); //Runs near the end of the user profile editing screen.
  767. //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.
  768. //add_action('profile_update', 'cb_profile_update', 10, 1); //Runs when a user's profile is updated. Action function argument: user ID.
  769. //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.
  770. //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.
  771.                        
  772. function cb_show_user_profile($user){
  773.     /*
  774.     $address1       = esc_attr(get_the_author_meta('address1',$user->ID ));
  775.     $address2       = esc_attr(get_the_author_meta('address2',$user->ID ));
  776.     $city           = esc_attr(get_the_author_meta('city',$user->ID ));
  777.     $state          = esc_attr(get_the_author_meta('state',$user->ID ));
  778.     $zipcode        = esc_attr(get_the_author_meta('zipcode',$user->ID ));
  779.     $telephone      = esc_attr(get_the_author_meta('telephone',$user->ID ));
  780.     $gender         = esc_attr(get_the_author_meta('gender',$user->ID ));
  781.     $birthdate      = esc_attr(get_the_author_meta('birthdate',$user->ID ));
  782.     $birthdate      = convert_datetous($birthdate);
  783.     $rdrole         = esc_attr(get_the_author_meta('rdrole',$user->ID ));
  784.  
  785.     //noly for drivers
  786.     $rate1              = esc_attr(get_the_author_meta('rate1',$user->ID ));
  787.     $rate2              = esc_attr(get_the_author_meta('rate2',$user->ID ));
  788.     $rateb              = esc_attr(get_the_author_meta('rateb',$user->ID ));
  789.     if($rateb == '')$rateb = 'hour';
  790.     $vcapacity          = esc_attr(get_the_author_meta('vcapacity',$user->ID ));
  791.     $vinsure            = esc_attr(get_the_author_meta('vinsure',$user->ID ));
  792.     $drivingexp         = esc_attr(get_the_author_meta('drivingexp',$user->ID ));
  793.    
  794.     $drivingradius      = esc_attr(get_the_author_meta('drivingradius',$user->ID ));
  795.     $currentpickdrop    = get_the_author_meta('currentpickdrop',$user->ID, true );
  796.  
  797.     $package        = get_the_author_meta('package', $user->ID);
  798.     $package        = ($package == '')? 'package0':$package;
  799.     $actpackage     = get_the_author_meta('actpackage', $user->ID);
  800.     $packagestart   = get_the_author_meta('packagestart',$user->ID );
  801.     $packagestart   = convert_datetous($packagestart);
  802.     $packageexp     = get_the_author_meta('packageexp', $user->ID );
  803.     $packageexp     = convert_datetous($packageexp);
  804.     */
  805. ?>
  806. <!----h3>Custom/Additional fields</h3>
  807. <table class="form-table">
  808. <tbody>
  809. <tr>
  810.     <th><label for="address1">Address Line1</label></th>
  811.  
  812.     <td>
  813.         <input type="text" name="address1" id="address1" value="<?php echo $address1; ?>" class="regular-text" />  
  814.     </td>
  815. </tr>
  816. <tr>
  817.     <th><label for="address2">Address Line2</label></th>
  818.  
  819.     <td>
  820.         <input type="text" name="address2" id="address2" value="<?php echo $address2; ?>" class="regular-text" />
  821.     </td>
  822. </tr>
  823. <tr>
  824.     <th><label for="city">City</label></th>
  825.  
  826.     <td>
  827.         <input type="text" name="city" id="city" value="<?php echo $city; ?>" class="regular-text" />
  828.     </td>
  829. </tr>
  830. <tr>
  831.     <th><label for="state">State</label></th>
  832.  
  833.     <td>
  834.         <input type="text" name="state" id="state" value="<?php echo $state; ?>" class="regular-text" />
  835.     </td>
  836. </tr>
  837. <tr>
  838.     <th><label for="zipcode">ZIP Code</label></th>
  839.  
  840.     <td>
  841.         <input type="text" name="zipcode" id="zipcode" value="<?php echo $zipcode; ?>" class="regular-text" />
  842.     </td>
  843. </tr>
  844. <tr>
  845.     <th><label for="telephone">Telephone</label></th>
  846.  
  847.     <td>
  848.         <input type="text" name="telephone" id="telephone" value="<?php echo $telephone; ?>" class="regular-text" />
  849.     </td>
  850. </tr>
  851. <tr>
  852.     <th><label for="birthdate"><?php _e('Birth Date') ?></label></th>
  853.     <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>
  854. </tr>
  855. <tr>
  856.     <th><label for="gender"><?php _e('Gender') ?></label></th>
  857.     <td>
  858.         <select id="gender" name="gender" class="input">
  859.             <option value="0" <?php selected(0,intval($gender)); ?>>Male</option>
  860.             <option value="1" <?php selected(1,intval($gender)); ?>>Female</option>
  861.             <option value="2" <?php selected(2,intval($gender)); ?>>Others</option>
  862.         </select>
  863.    </td>
  864. </tr>
  865. <tr>
  866.     <th><label for="rdrole"><?php _e('Relativerides role') ?></label></th>
  867.     <td>
  868.         <select id="rdrole" name="rdrole" class="input">
  869.             <option value="driver" <?php selected('driver',$rdrole); ?>>Driver</option>
  870.             <option value="parents" <?php selected('parents',$rdrole); ?>>Parents</option>
  871.             <option value="" <?php selected('',$rdrole); ?>>None</option>
  872.         </select>
  873.    </td>
  874. </tr>
  875. </tbody>
  876. </table>
  877. <h3>Vehicle & Driving Info</h3>
  878. <table class="form-table">
  879. <tbody>
  880. <tr>
  881.     <th><label for="rate1">Rate range (in whole dollars):</label></th>
  882.     <td>
  883.         <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
  884.         <select id="rateb" name="rateb" class="input">
  885.             <option value="hour" <?php selected('hour',$rateb); ?>>Hour</option>
  886.             <option value="week" <?php selected('week',$rateb); ?>>Week</option>
  887.         </select>
  888.     </td>
  889. </tr>
  890. <tr>
  891.     <th><label class="editlargelabel avlabel" for="vcapacity"><?php _e('Number  of People able to Transport') ?></label></th>
  892.     <td>
  893.         <select id="vcapacity" name="vcapacity" class="input">
  894.             <option value="1" <?php selected(1,intval($vcapacity)); ?>>1</option>
  895.             <option value="2" <?php selected(2,intval($vcapacity)); ?>>2</option>
  896.             <option value="3" <?php selected(3,intval($vcapacity)); ?>>3</option>
  897.             <option value="4" <?php selected(4,intval($vcapacity)); ?>>4</option>
  898.             <option value="5" <?php selected(5,intval($vcapacity)); ?>>5</option>
  899.             <option value="6" <?php selected(6,intval($vcapacity)); ?>>6</option>
  900.             <option value="7" <?php selected(7,intval($vcapacity)); ?>>7</option>
  901.         </select>
  902.      </td>
  903. </tr>
  904. <tr>
  905.     <th><label class="editlargelabel avlabel"  for="vinsure"><?php _e('Is the vehicle insured?') ?></label></th>
  906.     <td>
  907.         <label for="vinsure1" class="customradiobuttonl"><input type="radio" class="customradiobutton" <?php checked(1, intval($vinsure)); ?> value="1" id="vinsure1" name="vinsure">Yes</label>
  908.         <label for="vinsure0" class="customradiobuttonl"><input type="radio" class="customradiobutton" <?php checked(0, intval($vinsure)); ?> value="0" id="vinsure0" name="vinsure">No</label>
  909.     </td>
  910. </tr>    
  911. <tr>
  912.     <th><label for="drivingexp"><?php _e('Years driving') ?></label></th>
  913.     <td>
  914.         <input type="text" class="input" id="drivingexp" name="drivingexp" value="<?php echo esc_attr(stripslashes($drivingexp)); ?>" size="25"> years
  915.     </td>
  916. </tr>
  917. <tr>
  918.     <th><label for="drivingradius"><?php _e('Driving Radius'); ?></label></th>
  919.     <td>
  920.         <input type="text" class="input" id="drivingradius" name="drivingradius" value="<?php echo esc_attr(stripslashes($drivingradius)); ?>" size="25"> Kilometer
  921.     </td>
  922. </tr>
  923. <tr>
  924.     <th><label for="currentpickdrop"><?php _e('Current Public Location Pick Up/Drop Offs'); ?></label></th>
  925.     <td>
  926.         <input type="text" class="input" id="currentpickdrop0" name="currentpickdrop[]" value="<?php echo esc_attr(stripslashes($currentpickdrop[0])); ?>" size="25"><br/>
  927.         <input type="text" class="input" id="currentpickdrop1" name="currentpickdrop[]" value="<?php echo esc_attr(stripslashes($currentpickdrop[1])); ?>" size="25"><br/>
  928.         <input type="text" class="input" id="currentpickdrop2" name="currentpickdrop[]" value="<?php echo esc_attr(stripslashes($currentpickdrop[2])); ?>" size="25"><br/>
  929.         <input type="text" class="input" id="currentpickdrop3" name="currentpickdrop[]" value="<?php echo esc_attr(stripslashes($currentpickdrop[3])); ?>" size="25"><br/>
  930.         <input type="text" class="input" id="currentpickdrop4" name="currentpickdrop[]" value="<?php echo esc_attr(stripslashes($currentpickdrop[4])); ?>" size="25"><br/>
  931.         <input type="text" class="input" id="currentpickdrop5" name="currentpickdrop[]" value="<?php echo esc_attr(stripslashes($currentpickdrop[5])); ?>" size="25"><br/>
  932.         <span class="labelexample">Example: Location - Falls Church Recreation Time -3pm Monday thru Friday</span>            
  933.     </td>
  934. </tr>
  935. </tbody>
  936. </table>
  937. <h3>Subscription Information</h3>
  938. <table class="form-table">
  939. <tbody>
  940. <tr>
  941.     <th><label for="package"><?php _e('Requested Package'); ?></label></th>
  942.     <td>
  943.         <select id="package" name="package" class="input">
  944.             <option value="package0" <?php selected('package0',$package); ?>>Free One Week</option>
  945.             <option value="package1" <?php selected('package1',$package); ?>>One Month</option>
  946.             <option value="package2" <?php selected('package2',$package); ?>> Three Month</option>
  947.             <option value="package3" <?php selected('package3',$package); ?>> Three Month</option>
  948.         </select>        
  949.     </td>
  950. </tr>
  951. <tr>
  952.     <th><label for="actpackage"><?php _e('Activated Package'); ?></label></th>
  953.     <td>
  954.         <select id="actpackage" name="actpackage" class="input">
  955.             <option value="package0" <?php selected('package0',$actpackage); ?>>Free One Week</option>
  956.             <option value="package1" <?php selected('package1',$actpackage); ?>>One Month</option>
  957.             <option value="package2" <?php selected('package2',$actpackage); ?>> Three Month</option>
  958.             <option value="package3" <?php selected('package3',$actpackage); ?>> Three Month</option>
  959.         </select>        
  960.     </td>
  961. </tr>
  962. <tr>
  963.     <th><label for="packagestart"><?php _e('Package Start Date'); ?></label></th>
  964.     <td>
  965.         <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.
  966.     </td>
  967. </tr>
  968. <tr>
  969.     <th><label for="packageexp"><?php _e('Package Expiration Date'); ?></label></th>
  970.     <td>
  971.         <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.
  972.     </td>
  973. </tr>
  974. </tbody>
  975. </table-->
  976. <script type="text/javascript">
  977.     /*
  978.     jQuery(window).load(function() {
  979.         //jQuery("#birthdate").datepick({minDate: '01/01/1990',yearRange: 'c-50:c+2',dateFormat: 'yyyy-mm-dd'});
  980.         jQuery("#birthdate").datepick({dateFormat: 'mm-dd-yyyy'});
  981.         jQuery("#packagestart").datepick({dateFormat: 'mm-dd-yyyy'});
  982.         jQuery("#packageexp").datepick({dateFormat: 'mm-dd-yyyy'});
  983.     });
  984.     */
  985. </script>
  986. <?php
  987. }
  988.  
  989. function cb_DatepickerHead(){
  990.     if ( empty($jquery_loaded) ) {
  991.         wp_print_scripts("jquery");
  992.         $jquery_loaded = true;
  993.     }
  994.     echo '<link rel="stylesheet" type="text/css" media="all" href="'.get_bloginfo('template_directory').'/css/datepicker/ui.datepick.css?v=2" />';
  995.     echo '<script type="text/javascript" src="'.get_bloginfo('template_directory').'/js/datepicker/jquery.datepick.js"></script>';
  996.     //<script type="text/javascript" src="'.get_bloginfo('template_directory').'/js/datepicker/jquery.datepick.pack.js"></script>    
  997. }
  998.  
  999. function cb_profile_update($user_id){
  1000.     global $wpdb;
  1001.  
  1002.     $address1       = $_POST['address1'];
  1003.     $address2       = $_POST['address2'];
  1004.     $city           = $_POST['city'];
  1005.     $state          = $_POST['state'];
  1006.     $zipcode        = $_POST['zipcode'];
  1007.     $telephone      = $_POST['telephone'];
  1008.     $gender         = $_POST['gender'];
  1009.     $birthdate      = $_POST['birthdate'];
  1010.     $birthdate      = convert_ustodate($birthdate);
  1011.     $i_agree        = $_POST['i_agree'];
  1012.  
  1013.     //only for drivers
  1014.     $rate1          = intval($_POST['rate1']);
  1015.     $rate2          = intval($_POST['rate2']);
  1016.     $rateb          = $_POST['rateb'];
  1017.     $vcapacity          = intval($_POST['vcapacity']);
  1018.     if($vcapacity  == 0) $vcapacity = 1; // minimum heh !
  1019.     $vinsure            = intval($_POST['vinsure']);
  1020.     if($vinsure == 0) $vinsure = 0;
  1021.     $drivingexp         = intval($_POST['drivingexp']);
  1022.     $drivingradius      = intval($_POST['drivingradius']);
  1023.     $currentpickdrop    = $_POST['currentpickdrop'];
  1024.     //var_dump($currentpickdrop);
  1025.  
  1026.     $packagestart       = $_POST['packagestart'];
  1027.     $packagestart       = convert_ustodate($packagestart);
  1028.     $packageexp         = $_POST['packageexp'];
  1029.     $packageexp         = convert_ustodate($packageexp);
  1030.  
  1031.     $package        = $_POST['package'];
  1032.     $package        = ($package == '')? 'package0':$package;
  1033.     $actpackage     = $_POST['actpackage'];
  1034.     $actpackage     = ($actpackage == '')? 'package0':$actpackage;
  1035.    
  1036.  
  1037.     update_user_meta($user_id, "address1", $wpdb->prepare($address1));
  1038.     update_user_meta($user_id, "address2", $wpdb->prepare($address2));
  1039.     update_user_meta($user_id, "address2", $wpdb->prepare($address2));
  1040.     update_user_meta($user_id, "telephone", $wpdb->prepare($telephone));
  1041.     update_user_meta($user_id, "city", $wpdb->prepare($city));
  1042.     update_user_meta($user_id, "state", $wpdb->prepare($state));
  1043.     update_user_meta($user_id, "zipcode", $wpdb->prepare($zipcode));
  1044.    
  1045.     $latlng = zipcodes_latlng($zipcode);
  1046.     if($latlng != false){
  1047.         update_user_meta($user_id, "latitude", $wpdb->prepare($latlng->latitude));
  1048.         update_user_meta($user_id, "longitude", $wpdb->prepare($latlng->longitude));
  1049.     }
  1050.  
  1051.     update_user_meta($user_id, "birthdate", $wpdb->prepare($birthdate));
  1052.     update_user_meta($user_id, "gender", $wpdb->prepare($gender));
  1053.     if(is_admin()):
  1054.         $rdrole         = $_POST['rdrole'];
  1055.         update_user_meta($user_id, 'rdrole', $wpdb->prepare($rdrole));
  1056.     endif;
  1057.     //only for drivers
  1058.     update_user_meta($user_id, "rate1", $wpdb->prepare($rate1));
  1059.     update_user_meta($user_id, "rate2", $wpdb->prepare($rate2));
  1060.     update_user_meta($user_id, "rateb", $wpdb->prepare($rateb));
  1061.     update_user_meta($user_id, "vcapacity", $wpdb->prepare($vcapacity));
  1062.     update_user_meta($user_id, "vinsure", $wpdb->prepare($vinsure));
  1063.     update_user_meta($user_id, "drivingexp", $wpdb->prepare($drivingexp));
  1064.     update_user_meta($user_id, "drivingradius", $wpdb->prepare($drivingradius));
  1065.     update_user_meta($user_id, "currentpickdrop", $currentpickdrop);
  1066.  
  1067.     update_user_meta($user_id, "package", $package);
  1068.     update_user_meta($user_id, "actpackage", $actpackage);
  1069.     update_user_meta($user_id, "packagestart", $packagestart);
  1070.     update_user_meta($user_id, "packageexp", $packageexp);
  1071.  
  1072.  
  1073. }
  1074. add_action( 'user_profile_update_errors', 'cb_validate_new_fields' );
  1075.  
  1076. function cb_validate_new_fields(&$errors, $update = null, &$user  = null) {
  1077.     //custom fields
  1078.     $first_name     = $_POST['first_name'];
  1079.     $last_name      = $_POST['last_name'];
  1080.     /*
  1081.     $address1       = $_POST['address1'];
  1082.     $address2       = $_POST['address2'];
  1083.     $city           = $_POST['city'];
  1084.     $state          = $_POST['state'];
  1085.     $zipcode        = $_POST['zipcode'];
  1086.     $telephone      = $_POST['telephone'];
  1087.     $gender         = $_POST['gender'];
  1088.     $birthdate      = $_POST['birthdate'];
  1089.     $i_agree        = $_POST['i_agree'];
  1090.     $rdrole         = $_POST['rdrole'];
  1091.     */
  1092.     //custom fields valiadtion
  1093.     if(empty ($first_name)){
  1094.         $errors->add( 'firstname_empty', __( '<strong>ERROR</strong>: First name is empty.' ) );
  1095.     }
  1096.     if(empty ($last_name)){
  1097.         $errors->add( 'lastname_empty', __( '<strong>ERROR</strong>: Last name is empty.' ) );
  1098.     }
  1099.     /*
  1100.     if(empty ($address1)){
  1101.         $errors->add( 'address1_empty', __( '<strong>ERROR</strong>: Addres is empty.' ) );
  1102.     }
  1103.     if(empty ($telephone)){
  1104.         $errors->add( 'telephone_empty', __( '<strong>ERROR</strong>: Telephone number missing.' ) );
  1105.     }
  1106.     if(empty ($city)){
  1107.         $errors->add( 'city_empty', __( '<strong>ERROR</strong>: City name is empty.' ) );
  1108.     }
  1109.     if(empty ($zipcode)){
  1110.         $errors->add( 'zip_empty', __( '<strong>ERROR</strong>: ZIP is empty.' ) );
  1111.     }
  1112.     else if( zipcodes_exists('zipcode', $zipcode ) == false) {
  1113.             $errors->add( 'zipcode_exists', __( '<strong>ERROR</strong>: Zipcode doesn\'t exists or not a valid zipcode.' ) );
  1114.  
  1115.     }
  1116.     if(empty ($birthdate)){
  1117.         $errors->add( 'birthdate_empty', __( '<strong>ERROR</strong>: Birthdate is empty.' ) );
  1118.     }
  1119.     */
  1120.     //if ($_POST['telephone'] == '' || !preg_match('/^(\+|)[0-9\-]{6,}$/', $_POST['telephone'])) {
  1121.     //  $errors->add('empty_telephone', "<strong>ERROR</strong>: Please Enter in a valid telephone number");
  1122. /// }
  1123. }
  1124.  
  1125. // Prepend the new column to the columns array
  1126. function cb_user_extra_cols($cols) {
  1127.         //$screen = get_current_screen();
  1128.         //var_dump($screen);
  1129.     $cols['rdrole']  = 'Relativerdes Role';        
  1130.     return $cols;
  1131. }
  1132.  
  1133. // Echo the ID for the new column
  1134. function cb_user_extra_col_value($val, $column_name, $user_id) {        
  1135.         $rdrole_name = '';
  1136.     if ($column_name == 'rdrole'){
  1137.             $rdrole = get_the_author_meta('rdrole',$user_id );
  1138.             switch($rdrole){
  1139.                 case 'driver':
  1140.                     $rdrole_name = 'Driver';
  1141.                     break;
  1142.                 case 'parents':
  1143.                     $rdrole_name = 'Parents';
  1144.                     break;
  1145.                 default:
  1146.                     $rdrole_name = 'None';
  1147.  
  1148.             }
  1149.         }
  1150.         return $rdrole_name;
  1151. }
  1152.  
  1153. function cb_user_extra_sortable_cols($columns) {
  1154.   //var_dump($columns);
  1155.   $custom = array(
  1156.       // meta column id => sortby value used in query
  1157.       'rdrole'    => 'rdrole',
  1158.   );
  1159.   return wp_parse_args($custom, $columns);
  1160. }
  1161.  
  1162.  
  1163.  
  1164. function cb_user_extra_orderby( $vars ) {
  1165.     if ( isset( $vars['orderby'] ) && 'rdrole' == $vars['orderby'] ) {
  1166.             $vars = array_merge( $vars, array(
  1167.                     'meta_key' => 'rdrole',
  1168.                     'orderby' => 'meta_value'
  1169.             ) );
  1170.     }
  1171.     return $vars;
  1172. }
  1173.  
  1174. function cb_user_extra_col()
  1175. {
  1176.     //manage_users_sortable_columns
  1177.     //add_filter('manage_users_columns', 'cb_user_extra_cols');
  1178.     //add_action('manage_users_custom_column', 'cb_user_extra_col_value', 10, 3);
  1179.  
  1180.     //add_filter( 'manage_users_sortable_columns', 'cb_user_extra_sortable_cols' );
  1181.     //add_filter( 'request', 'cb_user_extra_orderby' );
  1182. }
  1183. //add_action('admin_init', 'cb_user_extra_col');
  1184.  
  1185. add_action( 'init', 'cb_create_custom_postype_taxonomies', 0 );
  1186.  
  1187. function cb_create_custom_postype_taxonomies(){
  1188.     global $wp_rewrite;
  1189.     /*
  1190.     register_taxonomy('post_vtag',
  1191.             array (  0 => 'post',),
  1192.             array( 'hierarchical' => true, 'label' => 'Video Tags','show_ui' => true,'query_var' => true,'rewrite' => array('slug' => 'vtag'),'singular_label' => 'Video Tag')
  1193.     );
  1194.  
  1195.     register_taxonomy('post_extag',
  1196.             array (  0 => 'post',),
  1197.             array( 'hierarchical' => true, 'label' => 'Explore Tags','show_ui' => true,'query_var' => true,'rewrite' => array('slug' => 'extag'),'singular_label' => 'Explore Tag')
  1198.      );
  1199.     */
  1200.     register_post_type('race',
  1201.             array(
  1202.                 'label' => 'Race','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => false,
  1203.                 'rewrite' => array('slug' => 'races', 'with_front' => true),
  1204.                 //'rewrite' => false,
  1205.                 'query_var' => true,
  1206.                 'supports' => array('title','editor','trackbacks','custom-fields','comments','thumbnail','author'),
  1207.                 'labels' => array (
  1208.                       'name' => 'Races',
  1209.                       'singular_name' => 'Race',
  1210.                       'menu_name' => 'Races',
  1211.                       'add_new' => 'Add Race',
  1212.                       'add_new_item' => 'Add New Race',
  1213.                       'edit' => 'Edit',
  1214.                       'edit_item' => 'Edit Race',
  1215.                       'new_item' => 'New Race',
  1216.                       'view' => 'View Race',
  1217.                       'view_item' => 'View Race',
  1218.                       'search_items' => 'Search Race',
  1219.                       'not_found' => 'No Races Found',
  1220.                       'not_found_in_trash' => 'No Races Found in Trash'
  1221.                      
  1222.                 ),
  1223.             )
  1224.     );//end register custom post type jobs
  1225.     /*
  1226.     register_post_type('application',
  1227.             array(
  1228.                 'label' => 'Application','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => false,
  1229.                 'rewrite' => array('slug' => 'applications', 'with_front' => true),
  1230.                 //'rewrite' => false,
  1231.                 'query_var' => true,
  1232.                 'supports' => array('title','editor','trackbacks','custom-fields','comments','thumbnail','author'),
  1233.                 'labels' => array (
  1234.                       'name' => 'Applications',
  1235.                       'singular_name' => 'Application',
  1236.                       'menu_name' => 'Applications',
  1237.                       'add_new' => 'Add Application',
  1238.                       'add_new_item' => 'Add New Application',
  1239.                       'edit' => 'Edit',
  1240.                       'edit_item' => 'Edit Application',
  1241.                       'new_item' => 'New Application',
  1242.                       'view' => 'View Application',
  1243.                       'view_item' => 'View Application',
  1244.                       'search_items' => 'Search Applications',
  1245.                       'not_found' => 'No Application Found',
  1246.                       'not_found_in_trash' => 'No Application Found in Trash'
  1247.  
  1248.                 ),
  1249.             )
  1250.     );//end register custom post type application
  1251.     */
  1252.     /*
  1253.     register_post_type('review',
  1254.             array(
  1255.                 'label' => 'Review','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => false,
  1256.                 'rewrite' => array('slug' => 'testimonials', 'with_front' => true),
  1257.                 //'rewrite' => false,
  1258.                 'query_var' => true,
  1259.                 'supports' => array('title','editor','trackbacks','custom-fields','comments','thumbnail','author'),
  1260.                 'labels' => array (
  1261.                       'name' => 'Reviews',
  1262.                       'singular_name' => 'Review',
  1263.                       'menu_name' => 'Reviews',
  1264.                       'add_new' => 'Add Review',
  1265.                       'add_new_item' => 'Add New Review',
  1266.                       'edit' => 'Edit',
  1267.                       'edit_item' => 'Edit Review',
  1268.                       'new_item' => 'New Review',
  1269.                       'view' => 'View Review',
  1270.                       'view_item' => 'View Review',
  1271.                       'search_items' => 'Search Reviews',
  1272.                       'not_found' => 'No Review Found',
  1273.                       'not_found_in_trash' => 'No Review Found in Trash'
  1274.  
  1275.                 ),
  1276.             )
  1277.     );//end register custom post type application
  1278.     */
  1279.     /*
  1280.     register_post_type('rdmessage',
  1281.             array(
  1282.                 'label' => 'Message','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => false,
  1283.                 'rewrite' => array('slug' => 'messages', 'with_front' => true),
  1284.                 //'rewrite' => false,
  1285.                 'query_var' => true,
  1286.                 'supports' => array('title','editor','trackbacks','custom-fields','comments','thumbnail','author'),
  1287.                 'labels' => array (
  1288.                       'name' => 'Messages',
  1289.                       'singular_name' => 'Message',
  1290.                       'menu_name' => 'Messages',
  1291.                       'add_new' => 'Add Message',
  1292.                       'add_new_item' => 'Add New Message',
  1293.                       'edit' => 'Edit',
  1294.                       'edit_item' => 'Edit Message',
  1295.                       'new_item' => 'New Message',
  1296.                       'view' => 'View Message',
  1297.                       'view_item' => 'View Message',
  1298.                       'search_items' => 'Search Messages',
  1299.                       'not_found' => 'No Message Found',
  1300.                       'not_found_in_trash' => 'No Message Found in Trash'
  1301.  
  1302.                 ),
  1303.             )
  1304.     );//end register custom post type application
  1305.     */
  1306.  
  1307.     //$tagname, $regex
  1308.     /*
  1309.     add_rewrite_tag( '%job%', '([^/]+)' );
  1310.     $extra_post_types = get_post_types( array( '_builtin' => false, 'publicly_queryable' => true ) );
  1311.     if( empty( $extra_post_types ) )
  1312.         return;
  1313.     add_rewrite_tag( '%job%', '('.implode('|',$extra_post_types).')' );
  1314.     add_permastruct( 'job', '/%year%/%monthnum%/%job%/', true, 1 );
  1315.     */
  1316.     /*
  1317.     register_taxonomy('childrenage',
  1318.             array (  0 => 'job',),
  1319.             array( 'hierarchical' => true,
  1320.                 'label' => 'Ages of passenger','show_ui' => true,'query_var' => true,
  1321.                 'rewrite' => array('slug' => 'jobsbypassengerage'),'singular_label' => 'Ages of Passenger') );
  1322.  
  1323.     register_taxonomy('language',
  1324.             array (  0 => 'job',),
  1325.             array( 'hierarchical' => true,
  1326.                 'label' => 'Language','show_ui' => true,'query_var' => true,
  1327.                 'rewrite' => array('slug' => 'jobsbylanguage'),'singular_label' => 'Language') );
  1328.     */
  1329.     /*
  1330.     register_taxonomy('racetag',
  1331.             array (  0 => 'race',),
  1332.             array( 'hierarchical' => true,
  1333.                 'label' => 'Race Tag','show_ui' => true,'query_var' => true,
  1334.                 'rewrite' => array('slug' => 'racetags'),'singular_label' => 'Race Tag') );
  1335.     */
  1336.     register_taxonomy('racetype',
  1337.             array (  0 => 'race',),
  1338.             array( 'hierarchical' => true,
  1339.                 'label' => 'Race Type','show_ui' => true,'query_var' => true,
  1340.                 'rewrite' => array('slug' => 'racetypes'),'singular_label' => 'Race Type') );
  1341.    
  1342.     register_taxonomy('racedistance',
  1343.             array (  0 => 'race',),
  1344.             array( 'hierarchical' => true,
  1345.                 'label' => 'Race Distance','show_ui' => true,'query_var' => true,
  1346.                 'rewrite' => array('slug' => 'racedistances'),'singular_label' => 'Race Distance') );
  1347.  
  1348.     register_taxonomy('racelocation',
  1349.             array (  0 => 'race',),
  1350.             array( 'hierarchical' => true,
  1351.                 'label' => 'Race Location','show_ui' => true,'query_var' => true,
  1352.                 'rewrite' => array('slug' => 'racelocations'),'singular_label' => 'Race Location') );
  1353.     register_taxonomy('awards',
  1354.             array (  0 => 'race',),
  1355.             array( 'hierarchical' => true,
  1356.                 'label' => 'Awards & Prizes','show_ui' => true,'query_var' => true,
  1357.                 'rewrite' => array('slug' => 'awards'),'singular_label' => 'Award & Prize') );
  1358.  
  1359. }
  1360. add_action( 'restrict_manage_posts', 'todo_restrict_manage_posts' );
  1361. add_filter('parse_query','todo_convert_restrict');
  1362. function todo_restrict_manage_posts() {
  1363.     global $typenow;
  1364.     //var_dump($typenow);
  1365.     $args   =   array( 'public' => true, '_builtin' => false );
  1366.     //$post_types = get_post_types($args);
  1367.     $post_types = array('race');
  1368.     //var_dump($post_types);
  1369.     if ( in_array($typenow, $post_types) ) {
  1370.     //$filters = get_object_taxonomies($typenow);
  1371.     $filters    = array('racetype','racedistance','racelocation','awards');
  1372.     //var_dump($filters);
  1373.         foreach ($filters as $tax_slug) {
  1374.             $tax_obj = get_taxonomy($tax_slug);
  1375.             wp_dropdown_categories(array(
  1376.                 'show_option_all' => __('Show All '.$tax_obj->label ),
  1377.                 'taxonomy' => $tax_slug,
  1378.                 'name' => $tax_obj->name,
  1379.                 'orderby' => 'name',
  1380.                 'selected' => $_GET[$tax_obj->query_var],
  1381.                 'hierarchical' => $tax_obj->hierarchical,
  1382.                 'show_count' => true,
  1383.                 'hide_empty' => false
  1384.             ));
  1385.         }
  1386.     }
  1387. }
  1388. function todo_convert_restrict($query) {
  1389.     global $pagenow;
  1390.     global $typenow;
  1391.     if ($pagenow=='edit.php') {
  1392.         $filters = get_object_taxonomies($typenow);
  1393.         foreach ($filters as $tax_slug) {
  1394.             $var = &$query->query_vars[$tax_slug];
  1395.             if ( isset($var) ) {
  1396.                 $term = get_term_by('id',$var,$tax_slug);
  1397.                 $var = $term->slug;
  1398.             }
  1399.         }
  1400.     }
  1401. }
  1402. function override_is_tax_on_post_search($query) {
  1403.     global $pagenow;
  1404.     $qv = &$query->query_vars;
  1405.     if ($pagenow == 'edit.php' && isset($qv['taxonomy']) && isset($qv['s'])) {
  1406.         $query->is_tax = true;
  1407.     }
  1408. }
  1409. add_filter('parse_query','override_is_tax_on_post_search');
  1410.  
  1411. /**
  1412.  * puplish the content in the feed later
  1413.  * $where ist default-var in WordPress (wp-includes/query.php)
  1414.  * This function an a SQL-syntax
  1415.  * Got from this url http://wpengineer.com/publish-the-feed-later/
  1416.  */
  1417. function publish_later_on_feed($where) {
  1418.     global $wpdb, $post;
  1419.  
  1420.     if ( is_feed() ) {
  1421.         // timestamp in WP-format
  1422.         $now = gmdate('Y-m-d H:i:s');
  1423.  
  1424.         // value for wait; + device
  1425.         $wait = '30'; // integer
  1426.  
  1427.         // http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
  1428.         $device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
  1429.  
  1430.         // add SQL-sytax to default $where
  1431.         $where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
  1432.     }
  1433.     return $where;
  1434. }
  1435.  
  1436. add_filter('posts_where', 'publish_later_on_feed');
  1437.  
  1438. function cb_add_extrametafields(){
  1439.     //add_meta_box( $id, $title, $callback, $page, $context, $priority, $callback_args );
  1440.     add_meta_box( 'cbextrametafields', 'Extra Post Options', 'cb_add_extrametafields_html', 'job', 'normal', 'high');
  1441.     //add_meta_box( 'videourl2', 'Dailymotion Playlist URL', 'eyeconnect_video_options2', 'post', 'normal', 'high');
  1442. }
  1443. function cb_add_extrametafields_html(){
  1444.     global $post;
  1445.     $custom = get_post_custom($post->ID);    
  1446.    
  1447.     $jobzipcode     = $custom["jobzipcode"][0]; //job location zipcode
  1448.     $jnchild        = $custom["jnchild"][0]; //no. of children
  1449.     $jrate1         =  $custom["jrate1"][0]; //rate start
  1450.     $jrate2         =  $custom["jrate2"][0]; //rate end
  1451.     $jrateb         =  $custom["jrateb"][0]; //per hour/ per week
  1452.     $jstartdate     =  $custom["jstartdate"][0]; //per hour/ per week
  1453.     $jstartdate     = convert_datetous($jstartdate); // yyyy-mm-dd  to mm-dd-yyyy
  1454.     $appstatus      =  $custom["appstatus"][0]; //application status, open/close
  1455.     if($jrateb == ''){$jrateb = 'hour';}
  1456.     if($appstatus == ''){$appstatus = 'open';}
  1457.    
  1458.     // Use nonce for verification
  1459.     wp_nonce_field( plugin_basename( __FILE__ ), 'cb_extrametafields' );
  1460.     ?>
  1461.     <style type="text/css">
  1462.         .cblabel{
  1463.             display: inline-block;
  1464.             margin: 0 5px 5px 0;
  1465.             text-align: left;
  1466.             width: 150px;
  1467.         }
  1468.     </style>
  1469.     <div class="detail">
  1470.             <p><label class="cblabel">ZIP Code:</label><input size="20" name="jobzipcode" value="<?php echo $jobzipcode; ?>" /></p>
  1471.             <p><label class="cblabel">No. Children:</label><input size="20" name="jnchild" value="<?php echo $jnchild; ?>" /></p>
  1472.             <p>
  1473.                 <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
  1474.                 <select id="jrateb" name="jrateb" class="input">
  1475.                     <option value="hour" <?php selected('hour',$jrateb); ?>>Hour</option>
  1476.                     <option value="week" <?php selected('week',$jrateb); ?>>Week</option>
  1477.                 </select>
  1478.             </p>
  1479.             <p><label class="cblabel">Job Start Date:</label><input size="20" name="jstartdate" value="<?php echo $jstartdate; ?>" />(Format: mm-dd-yyyy)</p>
  1480.             <p>
  1481.                 <label class="appstatus">Application Status: </label>
  1482.                 <select id="appstatus" name="appstatus" class="input">
  1483.                     <option value="open" <?php selected('open',$appstatus); ?>>Open</option>
  1484.                     <option value="close" <?php selected('close',$appstatus); ?>>Close</option>
  1485.                 </select>
  1486.             </p>
  1487.     </div>    
  1488.     <?php
  1489. }
  1490.  
  1491. function cb_update_extrametafields($post_id){
  1492.     global $post;
  1493.     // verify if this is an auto save routine.
  1494.   // If it is our form has not been submitted, so we dont want to do anything
  1495.   if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
  1496.       return;
  1497.  
  1498.   // verify this came from the our screen and with proper authorization,
  1499.   // because save_post can be triggered at other times
  1500.  
  1501.   if ( !wp_verify_nonce( $_POST['cb_extrametafields'], plugin_basename( __FILE__ ) ) )
  1502.       return;
  1503.  
  1504.   // Check permissions
  1505.   //var_dump($_POST['post_type']);
  1506.   if ( 'job' == $_POST['post_type'] )
  1507.   {
  1508.     if ( !current_user_can( 'edit_post', $post_id ) )
  1509.         return;
  1510.   }
  1511.   else  { return; }
  1512.  
  1513.   // OK, we're authenticated: we need to find and save the data
  1514.   //$post_id, $meta_key, $meta_value, $prev_value = ''
  1515.   update_post_meta($post->ID, "jobzipcode", $_POST["jobzipcode"]);
  1516.   $latlng = zipcodes_latlng($_POST["jobzipcode"]);
  1517.   if($latlng != false){
  1518.         update_post_meta($post->ID, "latitude", $latlng->latitude);
  1519.         update_post_meta($post->ID, "longitude", $latlng->longitude);
  1520.   }
  1521.   update_post_meta($post->ID, "jnchild", $_POST["jnchild"]);
  1522.   update_post_meta($post->ID, "jrate1", $_POST["jrate1"]);
  1523.   update_post_meta($post->ID, "jrate2", $_POST["jrate2"]);
  1524.   update_post_meta($post->ID, "jrateb", $_POST["jrateb"]);
  1525.   $jstartdate = $_POST["jstartdate"];
  1526.   $jstartdate = convert_ustodate($jstartdate);
  1527.   update_post_meta($post->ID, "jstartdate", $jstartdate );
  1528.   update_post_meta($post->ID, "appstatus", $_POST["appstatus"]);
  1529. }
  1530. //add_action("admin_init", "cb_add_extrametafields");
  1531. //add_action('save_post', 'cb_update_extrametafields');
  1532. function myprint_r($my_array) {
  1533.     if(is_object($my_array))
  1534.     {
  1535.         $result = array();
  1536.         foreach($my_array as $key => $value)
  1537.         {
  1538.           $result[$key] = object_to_array($value);
  1539.         }
  1540.         $my_array = $result;
  1541.       }
  1542.       //return $data;
  1543.     if (is_array($my_array)) {
  1544.         echo "<table border=1 cellspacing=0 cellpadding=3 width=100%>";
  1545.         echo '<tr><td colspan=2 style="background-color:#333333;"><strong><font color=white>ARRAY</font></strong></td></tr>';
  1546.         foreach ($my_array as $k => $v) {
  1547.                 echo '<tr><td valign="top" style="width:40px;background-color:#F0F0F0;">';
  1548.                 echo '<strong>' . $k . "</strong></td><td>";
  1549.                 myprint_r($v);
  1550.                 echo "</td></tr>";
  1551.         }
  1552.         echo "</table>";
  1553.         return;
  1554.     }
  1555.     echo $my_array;
  1556. }
  1557. function object_to_array($data)
  1558. {
  1559.   if(is_array($data) || is_object($data))
  1560.   {
  1561.     $result = array();
  1562.     foreach($data as $key => $value)
  1563.     {
  1564.       $result[$key] = object_to_array($value);
  1565.     }
  1566.     return $result;
  1567.   }
  1568.   return $data;
  1569. }
  1570. add_action('wp_head', 'cb_addstyle_topmenu');
  1571. function cb_addstyle_topmenu(){
  1572.     global  $userdata,$user_ID, $user_identity, $user_level;
  1573.     /*
  1574.     if($userdata->rdrole != 'parents' && $user_level  < 10){ //no access for driver , others or having user level less than 10
  1575.         //wp_redirect(get_bloginfo('url')); exit;
  1576.         ?>
  1577.         <style type="text/css">
  1578.             #menu-main-menu li.parentsonly{ display: none;}
  1579.         </style>
  1580.         <?php
  1581.     }
  1582.  
  1583.     if($userdata->rdrole != 'driver' && $user_level  < 10){ //no access for driver , others or having user level less than 10
  1584.         //wp_redirect(get_bloginfo('url')); exit;
  1585.         ?>
  1586.         <style type="text/css">
  1587.             #menu-main-menu li.driveronly{ display: none;}
  1588.         </style>
  1589.         <?php
  1590.     }
  1591.  
  1592.     if($user_level  < 10){ //no access for driver , others or having user level less than 10
  1593.         //wp_redirect(get_bloginfo('url')); exit;
  1594.         ?>
  1595.         <style type="text/css">
  1596.             #menu-main-menu li.adminonly{ display: none;}
  1597.         </style>
  1598.         <?php
  1599.     }
  1600.     */
  1601.     if (!is_user_logged_in()){ // no access for guest
  1602.         //wp_redirect(get_bloginfo('url')); exit;
  1603.         ?>
  1604.         <style type="text/css">
  1605.             #menu-main-menu li.registeronly{ display: none;}
  1606.         </style>
  1607.         <?php
  1608.     }
  1609.        
  1610. }
  1611. function cb_wp_rediect($url = ''){
  1612.     if($url == '') return;
  1613.     else{
  1614.         if(headers_sent()){
  1615.             echo '<div id="login_error"><a href="'.$url.'">Redirecting you shortly, if your browser doesn\'t redirect automatically then please click here.</a></div>';
  1616.             echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
  1617.             echo '<script type="text/javascript">
  1618.                <!--
  1619.                window.location = '.$url.'
  1620.                //-->
  1621.                </script>'; exit();
  1622.         }else{
  1623.             wp_redirect($url); exit();
  1624.         }
  1625.     }
  1626.    
  1627. }
  1628. //better trim or exceprt
  1629. function betterTrim($str1,$limit)   {
  1630.     $len = strlen($str1);
  1631.     $output = '';
  1632.     if($len > $limit)
  1633.     {
  1634.             $str2 = substr($str1, 0, $limit) ;
  1635.             if($str1[$limit-1] === ' ' || $str1[$limit] === ' ' ){ $output = $str2; }
  1636.             else{
  1637.                     $findme   = ' ';
  1638.                     $pos = strpos(substr($str1,$limit,$len), $findme);
  1639.                     if($pos === FALSE ) { $output = $str1; }
  1640.                     else
  1641.                     {
  1642.                             $limit = $limit+$pos;
  1643.                             $output = substr($str1,0,$limit);
  1644.                     }
  1645.             }
  1646.             return $output.'[...]';
  1647.     }
  1648.     else{ return $str1; }
  1649. }
  1650.  
  1651. //includes widgets here
  1652. //include_once TEMPLATEPATH."/rdwidgets/rdwidgets.php";
  1653.  
  1654. function cb_posts_for_current_author($query) {
  1655.      global $pagenow;
  1656.  
  1657.      if( 'edit.php' != $pagenow || !$query->is_admin )
  1658.      return $query;
  1659.  
  1660.      if( !current_user_can( 'manage_options' ) ) {
  1661.      global $user_ID;
  1662.      $query->set('author', $user_ID );
  1663.      }
  1664.      return $query;
  1665. }
  1666. add_filter('pre_get_posts', 'cb_posts_for_current_author');
  1667.  
  1668. function cb_relativeTime( $timestamp ){
  1669.     if( !is_numeric( $timestamp ) ){
  1670.         $timestamp = strtotime( $timestamp );
  1671.         if( !is_numeric( $timestamp ) ){
  1672.             return "";
  1673.         }
  1674.     }
  1675.  
  1676.     $difference = time() - $timestamp;
  1677.         // Customize in your own language.
  1678.     $periods = array( "sec", "min", "hour", "day", "week", "month", "year", "decade" );
  1679.     $lengths = array( "60","60","24","7","4.35","12","10");
  1680.  
  1681.     if ($difference > 0) { // this was in the past
  1682.         $ending = "ago";
  1683.     }else { // this was in the future
  1684.         $difference = -$difference;
  1685.         $ending = "to go";
  1686.     }
  1687.     for( $j=0; $difference>=$lengths[$j] and $j < 7; $j++ )
  1688.         $difference /= $lengths[$j];
  1689.     $difference = round($difference);
  1690.     if( $difference != 1 ){
  1691.                 // Also change this if needed for an other language
  1692.         $periods[$j].= "s";
  1693.     }
  1694.     $text = "$difference $periods[$j] $ending";
  1695.     return $text;
  1696. }
  1697.  
  1698. function cb_checked($val1, $val2){
  1699.     if($val1 == $val2 && !empty($val1) && !empty($val2) ) return 'LabelSelected';
  1700.     else return '';
  1701. }
  1702.  
  1703. function rdgetPhotoHeight($image) {
  1704.     $sizes = getimagesize($image);
  1705.     $height = $sizes[1];
  1706.     return $height;
  1707. }
  1708. function rdgetPhotoWidth($image) {
  1709.     $sizes = getimagesize($image);
  1710.     $width = $sizes[0];
  1711.     return $width;
  1712. }
  1713.  
  1714. function rdresizeImage($image,$width,$height,$scale) {
  1715.     $newImageWidth = ceil($width * $scale);
  1716.     $newImageHeight = ceil($height * $scale);
  1717.     $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
  1718.     $ext = strtolower(substr(basename($image), strrpos(basename($image), ".") + 1));
  1719.     $source = "";
  1720.     if($ext == "png"){
  1721.         $source = imagecreatefrompng($image);
  1722.     }elseif($ext == "jpg" || $ext == "jpeg"){
  1723.         $source = imagecreatefromjpeg($image);
  1724.     }elseif($ext == "gif"){
  1725.         $source = imagecreatefromgif($image);
  1726.     }
  1727.     imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
  1728.     if($ext == "png" || $ext == "PNG"){
  1729.         imagepng($newImage,$image,0);
  1730.     }elseif($ext == "jpg" || $ext == "jpeg" || $ext == "JPG" || $ext == "JPEG"){
  1731.         imagejpeg($newImage,$image,90);
  1732.     }elseif($ext == "gif" || $ext == "GIF"){
  1733.         imagegif($newImage,$image);
  1734.     }
  1735.     chmod($image, 0777);
  1736.     return $image;
  1737. }
  1738.  
  1739. function rdresizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
  1740.     $newImageWidth = ceil($width * $scale);
  1741.     $newImageHeight = ceil($height * $scale);
  1742.     $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
  1743.     $ext = strtolower(substr(basename($image), strrpos(basename($image), ".") + 1));
  1744.     $source = "";
  1745.     if($ext == "png"){
  1746.         $source = imagecreatefrompng($image);
  1747.     }elseif($ext == "jpg" || $ext == "jpeg"){
  1748.         $source = imagecreatefromjpeg($image);
  1749.     }elseif($ext == "gif"){
  1750.         $source = imagecreatefromgif($image);
  1751.     }
  1752.     imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
  1753.  
  1754.     if($ext == "png" || $ext == "PNG"){
  1755.         imagepng($newImage,$thumb_image_name,0);
  1756.     }elseif($ext == "jpg" || $ext == "jpeg" || $ext == "JPG" || $ext == "JPEG"){
  1757.         imagejpeg($newImage,$thumb_image_name,90);
  1758.     }elseif($ext == "gif" || $ext == "GIF"){
  1759.         imagegif($newImage,$thumb_image_name);
  1760.     }
  1761.  
  1762.     chmod($thumb_image_name, 0777);
  1763.     return $thumb_image_name;
  1764. }
  1765.  
  1766. function rdcropImage($thumb_width, $x1, $y1, $x2, $y2, $w, $h, $thumbLocation, $imageLocation){
  1767.     $scale = $thumb_width/$w;
  1768.     $cropped = rdresizeThumbnailImage($thumbLocation, $imageLocation,$w,$h,$x1,$y1,$scale);
  1769.     return $cropped;
  1770. }
  1771.  
  1772. //add_filter( 'get_avatar', 'my_avatar' );
  1773.  
  1774. function my_avatar( $avatar ) {
  1775.     global $comment;
  1776.  
  1777.     if ( $comment->user_id > 0 && $user = get_userdata( $comment->user_id ) ) {
  1778.         $img = '';
  1779.         $upload_dir = wp_upload_dir();
  1780.         $rdupload_url = trailingslashit($upload_dir['baseurl']);
  1781.         $large_image = get_user_meta($comment->user_id, 'uphoto', true);
  1782.         //var_dump($large_image);
  1783.         $dir2 = $upload_dir['basedir'] . '/uphoto/';
  1784.         $large_image_location = $dir2.$large_image;
  1785.         $thumb_image_location = $dir2.'thumb'.$large_image;
  1786.         $large_image_location = str_replace("/", DS,$large_image_location);
  1787.         $thumb_image_location = str_replace("/", DS,$thumb_image_location);
  1788.  
  1789.         $large_image_location_url   = $rdupload_url.'uphoto/'.$large_image;
  1790.         $thumb_image_location_url  = $rdupload_url.'uphoto/thumb'.$large_image;
  1791.         //var_dump($thumb_image_location);
  1792.         if(file_exists($thumb_image_location)){
  1793.             $img = $thumb_image_location_url;
  1794.         }
  1795.         else{
  1796.             //$img = ($userdata->gender)? 'female':'mail';
  1797.             $img = get_bloginfo('template_directory').'/images/bio.gif';
  1798.         }
  1799.         $avatar = '<img class="avatar" src="'.$thumb_image_location_url.'" alt="'.$user->display_name.'" />';
  1800.  
  1801.     }
  1802.     return $avatar;
  1803. }
  1804. //input dd-mm-yyyy  output   mm-dd-yyyy
  1805. function convert_dateuktous($strDate){
  1806.     if(empty($strDate)) return '';
  1807.     trim($strDate);
  1808.     list($d, $m, $y) = explode('-', $strDate);
  1809.     $mk = mktime(0,0,0,$m, $d, $y);
  1810.     $americanDate = strftime('%m-%d-%Y',$mk);
  1811.     return $americanDate;
  1812. }
  1813.  
  1814. //input mm-dd-yyyy  output   dd-mm-yyyy
  1815. function convert_dateustouk($strDate){
  1816.    if(empty($strDate)) return '';
  1817.    trim($strDate);
  1818.    list($m, $d, $y) = explode('-', $strDate);
  1819.    $mk = mktime(0,0,0,$m, $d, $y);
  1820.    $europeanDate =strftime('%d-%m-%Y',$mk);
  1821.    return $europeanDate;
  1822. }
  1823.  
  1824. //input yyyy-mm-dd  output   mm-dd-yyyy
  1825. function convert_datetous($strDate){
  1826.    if(empty($strDate)) return '';
  1827.    trim($strDate);
  1828.    list($y, $m, $d) = explode('-', $strDate);
  1829.    $mk = mktime(0,0,0,$m, $d, $y);
  1830.    $europeanDate =strftime('%m-%d-%Y',$mk);
  1831.    return $europeanDate;
  1832. }
  1833. //input mm-dd-yyyy  output   yyyy-mm-dd
  1834. function convert_ustodate($strDate){
  1835.    if(empty($strDate)) return '';
  1836.    trim($strDate);
  1837.    list($m, $d, $y) = explode('-', $strDate);
  1838.    $mk = mktime(0,0,0,$m, $d, $y);
  1839.    $europeanDate =strftime('%Y-%m-%d',$mk);
  1840.    return $europeanDate;
  1841. }
  1842.  
  1843. //input yyyy-mm-dd  output   dd-mm-yyyy
  1844. function convert_datetouk($strDate){
  1845.    if(empty($strDate)) return '';
  1846.    trim($strDate);
  1847.    list($y, $m, $d) = explode('-', $strDate);
  1848.    $mk = mktime(0,0,0,$m, $d, $y);
  1849.    $europeanDate = strftime('%d-%m-%Y',$mk);
  1850.    return $europeanDate;
  1851. }
  1852.  
  1853. function get_ipn_readabledate($strDate){
  1854.     $y  = substr($strDate,0, 4);
  1855.     $m  = substr($strDate, 4,2);
  1856.     $d  = substr($strDate, 6,2);
  1857.     return $y.'-'.$m.'-'.$d;
  1858. }
  1859. //input in y m d
  1860. function get_ipn_readabletimestamp($strDate){
  1861.     $y  = substr($strDate,0, 4);
  1862.     $m  = substr($strDate, 4,2);
  1863.     $d  = substr($strDate, 6,2);
  1864.     $h  = substr($strDate, 8,2);
  1865.     $min  = substr($strDate, 10,2);
  1866.     $s  = substr($strDate, 12,2);
  1867.     return mktime($h, $min, $s,$m, $d, $y);
  1868. }
  1869. // ADD CUSTOM POST TYPES TO THE 'RIGHT NOW' DASHBOARD WIDGET
  1870. function wph_right_now_content_table_end() {
  1871.  $args = array(
  1872.   'public' => true ,
  1873.   '_builtin' => false
  1874.  );
  1875.  $output = 'object';
  1876.  $operator = 'and';
  1877.  
  1878.  $post_types = get_post_types( $args , $output , $operator );
  1879.  foreach( $post_types as $post_type ) {
  1880.   $num_posts = wp_count_posts( $post_type->name );
  1881.   $num = number_format_i18n( $num_posts->publish );
  1882.   $text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) );
  1883.   if ( current_user_can( 'edit_posts' ) ) {
  1884.    $num = "<a href='edit.php?post_type=$post_type->name'>$num</a>";
  1885.    $text = "<a href='edit.php?post_type=$post_type->name'>$text</a>";
  1886.   }
  1887.   echo '<tr><td class="first b b-' . $post_type->name . '">' . $num . '</td>';
  1888.   echo '<td class="t ' . $post_type->name . '">' . $text . '</td></tr>';
  1889.  }
  1890.  $taxonomies = get_taxonomies( $args , $output , $operator );
  1891.  foreach( $taxonomies as $taxonomy ) {
  1892.   $num_terms  = wp_count_terms( $taxonomy->name );
  1893.   $num = number_format_i18n( $num_terms );
  1894.   $text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name , intval( $num_terms ));
  1895.   if ( current_user_can( 'manage_categories' ) ) {
  1896.    $num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>";
  1897.    $text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>";
  1898.   }
  1899.   echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>';
  1900.   echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>';
  1901.  }
  1902. }
  1903. add_action( 'right_now_content_table_end' , 'wph_right_now_content_table_end' );
  1904. // remove unncessary header info
  1905. function remove_header_info() {
  1906.     remove_action('wp_head', 'rsd_link');
  1907.     remove_action('wp_head', 'wlwmanifest_link');
  1908.     remove_action('wp_head', 'wp_generator');
  1909.     remove_action('wp_head', 'start_post_rel_link');
  1910.     remove_action('wp_head', 'index_rel_link');
  1911.     remove_action('wp_head', 'adjacent_posts_rel_link');
  1912. }
  1913. add_action('init', 'remove_header_info');
  1914.  
  1915. // remove extra css that recent comments widget injects
  1916. function remove_recent_comments_style() {
  1917.     global $wp_widget_factory;
  1918.     remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
  1919. }
  1920. add_action('widgets_init', 'remove_recent_comments_style');
  1921.  
  1922. function generate_posts_per_page_link(){
  1923.     $perpage        = (isset ($_REQUEST['posts_per_page']))? sanitize_text_field($_REQUEST['posts_per_page']):10;
  1924.     $perpage        = intval($perpage);    
  1925.     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  1926.     $currentpage_link = get_pagenum_link($paged);
  1927.     $currentpage_link = str_replace('posts_per_page='.$perpage, '', $currentpage_link);
  1928.     if(strpos($currentpage_link, '?') !== false) {
  1929.         $currentpage_link = $currentpage_link.'&posts_per_page=';
  1930.     }
  1931.     else{
  1932.         $currentpage_link = $currentpage_link.'?posts_per_page=';
  1933.     }
  1934.     return $currentpage_link;
  1935. }
  1936.  
  1937. function generate_posts_orderby_link(){
  1938.     $orderby        = (isset ($_REQUEST['orderby']))? sanitize_text_field($_REQUEST['orderby']):'date';
  1939.     $orderbys       = array('date', 'jstartdate', 'jrate1');
  1940.     if(!in_array($orderby,$orderbys)){$orderby = 'date';}
  1941.     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  1942.     $currentpage_link = get_pagenum_link($paged);
  1943.     $currentpage_link = str_replace('orderby='.$orderby, '', $currentpage_link);
  1944.     if(strpos($currentpage_link, '?') !== false) {
  1945.         $currentpage_link = $currentpage_link.'&orderby=';
  1946.     }
  1947.     else{
  1948.         $currentpage_link = $currentpage_link.'?orderby=';
  1949.     }
  1950.     return $currentpage_link;
  1951. }
  1952.  
  1953. function generate_posts_order_link(){
  1954.     $order        = (isset ($_REQUEST['order']))? sanitize_text_field($_REQUEST['order']):'DESC';
  1955.     $orders       = array('DESC', 'ASC');
  1956.     if(!in_array($order,$orders)){$order = 'DESC';}
  1957.     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  1958.     $currentpage_link = get_pagenum_link($paged);
  1959.     $currentpage_link = str_replace('order='.$order, '', $currentpage_link);
  1960.     if(strpos($currentpage_link, '?') !== false) {
  1961.         $currentpage_link = $currentpage_link.'&order=';
  1962.     }
  1963.     else{
  1964.         $currentpage_link = $currentpage_link.'?order=';
  1965.     }
  1966.     return $currentpage_link;
  1967. }
  1968.  
  1969. function get_cb_permalink($link = ''){
  1970.     if($link == '' ){
  1971.         $link = get_permalink();
  1972.     }
  1973.     $link .= (get_option('permalink_structure')) ? '?' : '&';
  1974.     return $link;
  1975. }
  1976. function show_classname($value, $currentvalue, $classname, $echo = true){
  1977.     if($classname == '') return;
  1978.     if(($value == $currentvalue) && !empty ($value) && !empty($currentvalue) ){
  1979.         if($echo){
  1980.             echo $classname;
  1981.         }
  1982.         else return $classname;
  1983.     }
  1984. }
  1985.  
  1986. function  cb_Subcription_Check(){
  1987.     global $wpdb;
  1988.     $errors = new WP_Error();
  1989.     $first_name     = $_POST['first_name'];
  1990.     $last_name      = $_POST['last_name'];
  1991.     $user_email     = $_POST['user_email'];
  1992.     $address1       = $_POST['address1'];
  1993.     $city           = $_POST['city'];
  1994.     $state          = $_POST['state'];
  1995.     $zipcode        = $_POST['zipcode'];
  1996.     $telephone      = $_POST['telephone'];
  1997.     $package        = $_POST['package'];
  1998.     $package        = ($package == '')? 'package0':$package;
  1999.    
  2000.     // Check the e-mail address
  2001.     $user_email_error = false;
  2002.     if ( $user_email == '' ) {
  2003.             $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your e-mail address.' ) );
  2004.             $user_email_error = true;
  2005.     } elseif ( ! is_email( $user_email ) ) {
  2006.             $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn&#8217;t correct.' ) );
  2007.             $user_email = '';
  2008.             $user_email_error = true;
  2009.     }
  2010.     /*
  2011.     elseif ( !email_exists( $user_email ) ) {
  2012.             $errors->add( 'email_exists', __( '<strong>ERROR</strong>: Wrong email address.' ) );
  2013.             $user_email_error = true;
  2014.     }
  2015.     */
  2016.     //custom fields valiadtion
  2017.     if(empty ($first_name)){
  2018.         $errors->add( 'firstname_empty', __( '<strong>ERROR</strong>: First name is empty.' ) );
  2019.     }
  2020.     if(empty ($last_name)){
  2021.         $errors->add( 'lastname_empty', __( '<strong>ERROR</strong>: Last name is empty.' ) );
  2022.     }
  2023.     if(empty ($address1)){
  2024.         $errors->add( 'address1_empty', __( '<strong>ERROR</strong>: Addres is empty.' ) );
  2025.     }
  2026.     if(empty ($telephone)){
  2027.         $errors->add( 'telephone_empty', __( '<strong>ERROR</strong>: Telephone number missing.' ) );
  2028.     }
  2029.     if(empty ($city)){
  2030.         $errors->add( 'city_empty', __( '<strong>ERROR</strong>: City name is empty.' ) );
  2031.     }
  2032.     if(empty ($zipcode)){
  2033.         $errors->add( 'zip_empty', __( '<strong>ERROR</strong>: ZIP is empty.' ) );
  2034.     }
  2035.     else if( zipcodes_exists('zipcode', $zipcode ) == false) {
  2036.         $errors->add( 'zipcode_exists', __( '<strong>ERROR</strong>: Zipcode doesn\'t exists or not a valid zipcode.' ) );
  2037.     }
  2038.     if ( $errors->get_error_code() )
  2039.             return $errors;
  2040. }
  2041. if ( !function_exists('cb_wp_new_user_notification') ) :
  2042. /**
  2043.  * Notify the blog admin of a new user, normally via email.
  2044.  *
  2045.  * @since 2.0
  2046.  *
  2047.  * @param int $user_id User ID
  2048.  * @param string $plaintext_pass Optional. The user's plaintext password
  2049.  */
  2050. function cb_wp_new_user_notification($user_id, $plaintext_pass = '', $verification_code = '') {
  2051.     $user = new WP_User($user_id);
  2052.  
  2053.     $user_login = stripslashes($user->user_login);
  2054.     $user_email = stripslashes($user->user_email);
  2055.  
  2056.  
  2057.         $stored_user_login      = get_user_meta($user_id, "stored_user_login", true);
  2058.         $stored_user_password   = get_user_meta($user_id, "stored_user_password", true );
  2059.  
  2060.     // The blogname option is escaped with esc_html on the way into the database in sanitize_option
  2061.     // we want to reverse this for the plain text arena of emails.
  2062.     $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  2063.  
  2064.     $message  = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
  2065.     $message .= sprintf(__('Username: %s'), $stored_user_login) . "\r\n\r\n";
  2066.     $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
  2067.  
  2068.     @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
  2069.  
  2070.     if ( empty($plaintext_pass) )
  2071.         return;
  2072.  
  2073.        
  2074.     $message  = sprintf(__('Username: %s'), $stored_user_login) . "\r\n";
  2075.     $message .= sprintf(__('Password: %s'), $stored_user_password) . "\r\n";
  2076.     $message .=  '<a href="'.wp_login_url().'">'.wp_login_url().'</a>'. "\r\n";
  2077.        
  2078.         global $mailtemplates, $spages;  
  2079.  
  2080.         $loginurl = get_permalink($spages->regipage);
  2081.         $loginurl = cb_getquerylink($loginurl).'action=login';
  2082.         $verificationurl = $loginurl.'&verificationcode='.$verification_code;
  2083.         $loginurl = '<a href="'.$loginurl.'">'.$loginurl.'</a>';
  2084.         $verificationurl = '<a href="'.$verificationurl.'">'.$verificationurl.'</a>';
  2085.  
  2086.         $message    = stripslashes($mailtemplates->regif);
  2087.         $message    = str_replace('%displayname%', $user->display_name, $message );
  2088.         $message    = str_replace('%username%', $stored_user_login, $message );
  2089.         $message    = str_replace('%password%', $stored_user_password, $message );
  2090.         $message    = str_replace('%verificationurl%', $verificationurl, $message );
  2091.         $message    = str_replace('%loginurl%', $loginurl, $message );
  2092.  
  2093.  
  2094.         wp_mail($user_email, sprintf(__('Welcome to %s'), $blogname), $message);
  2095.        
  2096.        
  2097.    
  2098.  
  2099. }
  2100. endif;
  2101.  
  2102. if ( !function_exists('cb_wp_password_change_notification') ) :
  2103. /**
  2104.  * Notify the blog admin of a user changing password, normally via email.
  2105.  *
  2106.  * @since 2.7
  2107.  *
  2108.  * @param object $user User Object
  2109.  */
  2110. function cb_wp_password_change_notification(&$user) {
  2111.     // send a copy of password change notification to the admin
  2112.     // but check to see if it's the admin whose password we're changing, and skip this
  2113.     if ( $user->user_email != get_option('admin_email') ) {
  2114.         $message = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login) . "\r\n";
  2115.         // The blogname option is escaped with esc_html on the way into the database in sanitize_option
  2116.         // we want to reverse this for the plain text arena of emails.
  2117.         $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  2118.         wp_mail(get_option('admin_email'), sprintf(__('%s Password Lost/Changed'), $blogname), $message);
  2119.     }
  2120. }
  2121. endif;
  2122.  
  2123.  
  2124. if ( ! function_exists( 'cb_filter_system_from_mail' ) )
  2125. {
  2126.     /**
  2127.      * First admin's e-mail address or blog name depending on current filter.
  2128.      *
  2129.      * @return string
  2130.      */
  2131.     function cb_filter_system_from_mail()
  2132.     {
  2133.         return get_option( 'wp_mail_from' == current_filter()
  2134.             ? 'admin_email' : 'blogname' );
  2135.     }
  2136.  
  2137.     add_filter( 'wp_mail_from',      'cb_filter_system_from_mail' );
  2138.     add_filter( 'wp_mail_from_name', 'cb_filter_system_from_mail' );
  2139. }
  2140. //add_filter('wp_mail_content_type', 'cb_set_content_type');
  2141. //wp_mail( $to, $subject, $message, $headers, $attachments );
  2142. function cb_set_content_type($content_type){
  2143.     add_action('phpmailer_init', 'cb_send_html');
  2144.     return "text/html";
  2145. }
  2146. /**
  2147.  * Replaces the < & > of the 3.1 email text links
  2148.  *
  2149.  * @since 0.1.2
  2150.  * @param string $body
  2151.  * @return string
  2152.  */
  2153. function cb_esc_textlinks($body) {
  2154.         return preg_replace('#<(https?://[^*]+)>#', '$1', $body);
  2155. }
  2156. function cb_send_html(&$phpmailer){
  2157.     $email_template = '<head>
  2158.         <meta http-equiv="Content-Type" content="text/html;UTF-8" />
  2159.     </head>
  2160.    <body>
  2161.        <table cellspacing="0" cellpadding="10" border="0" bgcolor="#0A6587" width="620px" style="-webkit-border-radius: 10px;
  2162. -moz-border-radius: 10px;border-radius: 10px;">
  2163.            <tbody>
  2164.                <tr>
  2165.                    <td valign="top" align="left">
  2166.                        <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>
  2167.                        <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>
  2168.                </tr>
  2169.                <tr>
  2170.                    <td valign="top" align="left" style="padding:0;">
  2171.                        <table width="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#1A7D94" align="center">
  2172.                        <tbody>
  2173.                            <tr>
  2174.                                <td>
  2175.                                    <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;">
  2176.                                        %emailcontent%
  2177.                                        <br/><br/>Sincerely,<br/>'.get_bloginfo( 'name' ).' Team
  2178.                                    </div>
  2179.                                </td>
  2180.                            </tr>
  2181.                        </tbody>
  2182.                        </table>
  2183.                    </td>
  2184.                </tr>
  2185.                <tr>
  2186.                    <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;">
  2187.                        %emailfooter%
  2188.                    </td>
  2189.                </tr>
  2190.            </tbody>
  2191.        </table>
  2192.    </body>
  2193. </html>';
  2194.     global $mailtemplates;
  2195.     $codeboxr_mailfooter    = nl2br(stripslashes($mailtemplates->footer));
  2196.     // Set the original plain text message
  2197.    
  2198.     //$email_template         = htmlentities($email_template);
  2199.     //$phpmailer->Body        = $email_template;
  2200.     $phpmailer->AltBody         = wp_specialchars_decode($phpmailer->Body, ENT_QUOTES);
  2201.     // Clean < and > around text links in WP 3.1
  2202.     $mailerbody                 = nl2br($phpmailer->Body);
  2203.     $mailerbody                 = str_replace('%emailcontent%', $mailerbody, $email_template );
  2204.     $mailerbody                 = str_replace('%emailfooter%', $codeboxr_mailfooter, $mailerbody );
  2205.     //$phpmailer->Body        = cb_esc_textlinks($phpmailer->Body);
  2206.     // Convert line breaks & make links clickable
  2207.     $mailerbody                 = wp_specialchars_decode($mailerbody);
  2208.     //$mailerbody         = str_replace('<a ', '<a style="color:#ffffff;" ', $mailerbody);
  2209.     //$mailerbody        = nl2br($mailerbody);
  2210.     $mailerbody                 = html_entity_decode($mailerbody);
  2211.    
  2212.     // Add template to message
  2213.     //$phpmailer->Body = $this->set_email_template($phpmailer->Body);
  2214.     // Replace variables in email
  2215.     //$phpmailer->Body = $this->template_vars_replacement($phpmailer->Body);
  2216.     $mailerbody                 = str_replace('<a ', '<a style="color:#31FF71;" ', $mailerbody);
  2217.     $phpmailer->Body            = $mailerbody;
  2218. }
  2219. //http://www.phaster.com/zip_code.html
  2220. //https://github.com/Quixotix/PHP-ZipCode-Class/blob/master/example.php
  2221. global $wpdb;
  2222. /*
  2223. $wpdb->cbzipcode = $wpdb->prefix.'cbzipcode';
  2224. $wpdb->rdpayments = $wpdb->prefix.'rdpayments';
  2225. $wpdb->rdpaymentserrorlog = $wpdb->prefix.'rdpaymentserrorlog';
  2226. */
  2227. /*
  2228. function zipcodes_exists($field, $value) {
  2229.     global $wpdb;
  2230.         if($field == 'zipcode') { $value = absint($value);}
  2231.         if(empty($value)) return false;
  2232.     if ( !$result = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->cbzipcode WHERE $field = %s", $value) ) )
  2233.         return false;  
  2234.     return $result;
  2235. }
  2236.  
  2237. function zipcodes_latlng($value) {
  2238.     global $wpdb;
  2239.         $field = 'zipcode';
  2240.         if(empty($value)) return false;
  2241.     if ( !$result = $wpdb->get_row( $wpdb->prepare("SELECT latitude, longitude FROM $wpdb->cbzipcode WHERE $field = %s", $value) ) )
  2242.         return false;
  2243.     return $result;
  2244. }
  2245. */
  2246. /*
  2247. function posts_where_jobsearch( $where ) { 
  2248.         global $wpdb;
  2249.         global $lng1, $lng2, $lat1, $lat2;
  2250.         //var_dump($lng1);
  2251.         $distance       = (isset ($_REQUEST['distance']))? sanitize_text_field($_REQUEST['distance']):1; //default 1 mile
  2252.         //$where . " AND $wpdb->postmeta.longitude between lng1 AND lng2 AND $wpdb->postmeta.latitude between lat1 AND lat2 having cbdistance <= ".$distance ;
  2253.         $where .= " AND $wpdb->postmeta.longitude between $lng1 AND $lng2 AND $wpdb->postmeta.latitude between $lat1 AND $lat2 ";
  2254.     //var_dump($where);
  2255.     return $where;
  2256. }
  2257.  
  2258. function join_jobsearch($join){
  2259.     global $wpdb;
  2260.     //$join .= " INNER JOIN $wpdb->posts ON ( wp_posts.ID = wp_term_relationships.object_id )";
  2261.     return $join;
  2262. }
  2263. */
  2264. function cb_getquerylink($link){
  2265.     if(strpos($link, '?') !== false) {
  2266.         $link     = $link.'&';
  2267.     }
  2268.     else{
  2269.         $link   = $link.'?';
  2270.     }
  2271.     return $link;
  2272. }
  2273. function cb_paginate($found_rows,$perpage, $paged){
  2274.     $pagination_options = array(
  2275.                     'title' => 'Pages:',
  2276.                     'nextpage' => 'Next &raquo;',
  2277.                     'previouspage' => '&laquo; Prev',
  2278.                     'css' => true,
  2279.                     'before' => '<div class="navigation">',
  2280.                     'after' => '</div>',
  2281.                     'empty' => true,
  2282.                     'range' => 3,
  2283.                     'anchor' => 1,
  2284.                     'gap' => 3
  2285.             );
  2286.           $pagination_options                  = cb_convertArrayToObject($pagination_options);
  2287.           $pages = intval(ceil($found_rows / $perpage));
  2288.           $prevlink = esc_url(get_pagenum_link($paged - 1));
  2289.           $nextlink = esc_url(get_pagenum_link($paged + 1));
  2290.           $output = stripslashes($pagination_options->before);
  2291.             if ($pages > 1) {
  2292.                     $output .= sprintf('<ol class="wp-paginate">');
  2293.                     $output .= sprintf('<li><span class="title">%s</span></li>', stripslashes($pagination_options->title));
  2294.                     $ellipsis = "<li><span class='gap'>...</span></li>";
  2295.  
  2296.                     if ($paged > 1 && !empty($pagination_options->previouspage)) {
  2297.                             $output .= sprintf('<li><a href="%s" class="prev">%s</a></li>', $prevlink, stripslashes($pagination_options->previouspage));
  2298.                     }
  2299.  
  2300.                     $min_links = $pagination_options->range * 2 + 1;
  2301.                     $block_min = min($paged - $pagination_options->range, $pages - $min_links);
  2302.                     $block_high = max($paged + $pagination_options->range, $min_links);
  2303.                     $left_gap = (($block_min - $pagination_options->anchor - $pagination_options->gap) > 0) ? true : false;
  2304.                     $right_gap = (($block_high + $pagination_options->anchor + $pagination_options->gap) < $pages) ? true : false;
  2305.  
  2306.                     if ($left_gap && !$right_gap) {
  2307.                             $output .= sprintf('%s%s%s',
  2308.                                     cb_paginate_loop(1, $pagination_options->anchor),
  2309.                                     $ellipsis,
  2310.                                     cb_paginate_loop($block_min, $pages, $paged)
  2311.                             );
  2312.                     }
  2313.                     else if ($left_gap && $right_gap) {
  2314.                             $output .= sprintf('%s%s%s%s%s',
  2315.                                     cb_paginate_loop(1, $pagination_options->anchor),
  2316.                                     $ellipsis,
  2317.                                     cb_paginate_loop($block_min, $block_high, $paged),
  2318.                                     $ellipsis,
  2319.                                     cb_paginate_loop(($pages - $pagination_options->anchor + 1), $pages)
  2320.                             );
  2321.                     }
  2322.                     else if ($right_gap && !$left_gap) {
  2323.                             $output .= sprintf('%s%s%s',
  2324.                                     cb_paginate_loop(1, $block_high, $paged),
  2325.                                     $ellipsis,
  2326.                                     cb_paginate_loop(($pages - $pagination_options->anchor + 1), $pages)
  2327.                             );
  2328.                     }
  2329.                     else {
  2330.                             $output .= cb_paginate_loop(1, $pages, $paged);
  2331.                     }
  2332.  
  2333.                     if ($paged < $pages && !empty($pagination_options->nextpage)) {
  2334.                             $output .= sprintf('<li><a href="%s" class="next">%s</a></li>', $nextlink, stripslashes($pagination_options->nextpage));
  2335.                     }
  2336.                     $output .= "</ol>";
  2337.             }
  2338.             $output .= stripslashes($pagination_options->after);
  2339.  
  2340.             if ($pages > 1 || $pagination_options->empty) {
  2341.                     echo $output;
  2342.             }
  2343. }
  2344. /**
  2345.  * Helper function for pagination which builds the page links.
  2346.  */
  2347. function cb_paginate_loop($start, $max, $page = 0) {
  2348.         $output = "";
  2349.         for ($i = $start; $i <= $max; $i++) {
  2350.                 $p = esc_url(get_pagenum_link($i)) ;
  2351.                 $output .= ($page == intval($i))
  2352.                         ? "<li><span class='page current'>$i</span></li>"
  2353.                         : "<li><a href='$p' title='$i' class='page'>$i</a></li>";
  2354.         }
  2355.         return $output;
  2356. }
  2357. //apply_filters('comment_notification_text', $notify_message, $comment_id);
  2358. //add_filter('comment_notification_text', 'cb_comment_notification_text', 99999,2);
  2359. //apply_filters('comment_notification_subject', $subject, $comment_id);
  2360. //add_filter('comment_notification_subject', 'cb_comment_notification_subject', 99999,2);
  2361. /*
  2362. function cb_comment_notification_text($notify_message, $comment_id){
  2363.     $comment = get_comment( $comment_id );
  2364.     $post    = get_post( $comment->comment_post_ID );
  2365.     $author  = get_userdata( $comment->user_id );
  2366.     $ptype   = $post->post_type;
  2367.     if( $ptype == 'rdmessage' || $ptype == 'application' ){
  2368.         global $mailtemplates, $spages;
  2369.         //$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  2370.         $app_link_redirect = get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id;
  2371.         $notify_message    = stripslashes($mailtemplates->msgt);
  2372.         $notify_message    = str_replace('%displayname%', $author->display_name, $notify_message );
  2373.         $notify_message    = str_replace('%msgtext%', $comment->comment_content, $notify_message );
  2374.         $notify_message    = str_replace('%msglink%', $app_link_redirect, $notify_message );
  2375.     }
  2376.     return $notify_message;
  2377. }
  2378.  
  2379. function cb_comment_notification_subject($subject, $comment_id){
  2380.     $comment = get_comment( $comment_id );
  2381.     $post    = get_post( $comment->comment_post_ID );
  2382.     $author  = get_userdata( $post->post_author );
  2383.     $ptype   = $post->post_type;
  2384.     if( $ptype == 'rdmessage' || $ptype == 'application' ){
  2385.         global $mailtemplates, $spages;
  2386.         $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);      
  2387.         if($ptype == 'rdmessage'){
  2388.             return sprintf(__('New Message reply-%s'), $blogname);
  2389.         }
  2390.         else{
  2391.             return sprintf(__('New Comment/Reply on Job Application-%s'), $blogname);
  2392.         }
  2393.        
  2394.         //wp_mail($to, sprintf(__('New Job Application-%s'), $blogname), $message);
  2395.     }
  2396.     else return $subject;
  2397.    
  2398. }
  2399. */
  2400. /*Event Calender*/
  2401. function cb_calender_current_link($cur_year,$cur_month){
  2402.   global $spages;
  2403.   $cdpage_link =  get_permalink($spages->cdpage);
  2404.   $cdpage_link =  get_cb_permalink($cdpage_link);
  2405.  
  2406.   return '<a href="' . $cdpage_link . 'month='.$cur_month.'&amp;yr=' . $cur_year . '">Current Month</a>';
  2407.  
  2408. }
  2409.  
  2410. function cb_calender_next_link($cur_year,$cur_month){
  2411.   global $spages;
  2412.   $cdpage_link =  get_permalink($spages->cdpage);
  2413.   $cdpage_link =  get_cb_permalink($cdpage_link);
  2414.   $mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sept','oct','nov','dec');
  2415.   $next_year = $cur_year + 1;
  2416.  
  2417.   if ($cur_month == 12)
  2418.     {
  2419.       $rlink = __('Next','calendar');
  2420.       return '<a href="' . $cdpage_link . 'month=jan&amp;yr=' . $next_year . '">'.$rlink.' &raquo;</a>';
  2421.     }
  2422.   else
  2423.     {
  2424.       $next_month = $cur_month + 1;
  2425.       $month = $mod_rewrite_months[$next_month];
  2426.       $rlink = __('Next','calendar');
  2427.       return '<a href="' . $cdpage_link . 'month='.$month.'&amp;yr=' . $cur_year . '">'.$rlink.' &raquo;</a>';
  2428.     }
  2429. }
  2430.  
  2431. // Configure the "Previous" link in the calendar
  2432. function cb_calender_prev_link($cur_year,$cur_month){
  2433.   global $spages;
  2434.   $cdpage_link =  get_permalink($spages->cdpage);
  2435.   $cdpage_link =  get_cb_permalink($cdpage_link);
  2436.   $mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sept','oct','nov','dec');
  2437.   $last_year = $cur_year - 1;
  2438.  
  2439.   if ($cur_month == 1)
  2440.     {
  2441.       $llink = __('Prev','calendar');
  2442.       return '<a href="' . $cdpage_link . 'month=dec&amp;yr='. $last_year .'">&laquo; '.$llink.'</a>';
  2443.     }
  2444.   else
  2445.     {
  2446.       $next_month = $cur_month - 1;
  2447.       $month = $mod_rewrite_months[$next_month];
  2448.       $llink = __('Prev','calendar');
  2449.       return '<a href="' . $cdpage_link . 'month='.$month.'&amp;yr=' . $cur_year . '">&laquo; '.$llink.'</a>';
  2450.     }
  2451. }
  2452.  
  2453. // Actually do the printing of the calendar
  2454. // Compared to searching for and displaying events
  2455. // this bit is really rather easy!
  2456. function cb_calendar()
  2457. {
  2458.   global $wpdb;
  2459.   global $spages;
  2460.   $cdpage_link =  get_permalink($spages->cdpage);
  2461.   $cdpage_link =  get_cb_permalink($cdpage_link);
  2462.   include_once TEMPLATEPATH."/libs/dropdownlist.php";
  2463.  
  2464.     // Deal with the week not starting on a monday
  2465.     if (get_option('start_of_week') == 0)
  2466.       {
  2467.     $name_days = array(1=>__('Sunday','calendar'),__('Monday','calendar'),__('Tuesday','calendar'),__('Wednesday','calendar'),__('Thursday','calendar'),__('Friday','calendar'),__('Saturday','calendar'));
  2468.       }
  2469.     // Choose Monday if anything other than Sunday is set
  2470.     else
  2471.       {
  2472.     $name_days = array(1=>__('Monday','calendar'),__('Tuesday','calendar'),__('Wednesday','calendar'),__('Thursday','calendar'),__('Friday','calendar'),__('Saturday','calendar'),__('Sunday','calendar'));
  2473.       }
  2474.  
  2475.     // Carry on with the script
  2476.     $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'));
  2477.  
  2478.     // If we don't pass arguments we want a calendar that is relevant to today
  2479.     if (empty($_REQUEST['month']) || empty($_REQUEST['yr']))
  2480.     {
  2481.         $c_year = date("Y");
  2482.         $c_month = date("m");
  2483.         $c_day = date("d");
  2484.     }
  2485.  
  2486.     // Years get funny if we exceed 3000, so we use this check
  2487.     if (isset($_REQUEST['yr']))
  2488.     {
  2489.         if ($_REQUEST['yr'] <= 3000 && $_REQUEST['yr'] >= 0 && (int)$_REQUEST['yr'] != 0)
  2490.         {
  2491.             // This is just plain nasty and all because of permalinks
  2492.             // which are no longer used, this will be cleaned up soon
  2493.             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')
  2494.               {
  2495.  
  2496.                    // Again nasty code to map permalinks into something
  2497.                    // databases can understand. This will be cleaned up
  2498.                    $c_year = mysql_escape_string($_REQUEST['yr']);
  2499.                    $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 );
  2500.                    
  2501.                    /*
  2502.                    if ($_REQUEST['month'] == 'jan') { $t_month = 1; }                  
  2503.                    else if ($_REQUEST['month'] == 'feb') { $t_month = 2; }
  2504.                    else if ($_REQUEST['month'] == 'mar') { $t_month = 3; }
  2505.                    else if ($_REQUEST['month'] == 'apr') { $t_month = 4; }
  2506.                    else if ($_REQUEST['month'] == 'may') { $t_month = 5; }
  2507.                    else if ($_REQUEST['month'] == 'jun') { $t_month = 6; }
  2508.                    else if ($_REQUEST['month'] == 'jul') { $t_month = 7; }
  2509.                    else if ($_REQUEST['month'] == 'aug') { $t_month = 8; }
  2510.                    else if ($_REQUEST['month'] == 'sept') { $t_month = 9; }
  2511.                    else if ($_REQUEST['month'] == 'oct') { $t_month = 10; }
  2512.                    else if ($_REQUEST['month'] == 'nov') { $t_month = 11; }
  2513.                    else if ($_REQUEST['month'] == 'dec') { $t_month = 12; }
  2514.                    */
  2515.                    $t_month = $monthlist[$_REQUEST['month']];
  2516.                    $c_month = $t_month;
  2517.                    $c_day = date("d");
  2518.             }
  2519.             // No valid month causes the calendar to default to today
  2520.             else
  2521.             {
  2522.                    $c_year = date("Y");
  2523.                    $c_month = date("m");
  2524.                    $c_day = date("d");
  2525.             }
  2526.         }
  2527.     }
  2528.     // No valid year causes the calendar to default to today
  2529.     else
  2530.     {
  2531.         $c_year = date("Y");
  2532.         $c_month = date("m");
  2533.         $c_day = date("d");
  2534.     }
  2535.  
  2536.     // Fix the days of the week if week start is not on a monday
  2537.     if (get_option('start_of_week') == 0)
  2538.       {
  2539.     $first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year));
  2540.         $first_weekday = ($first_weekday==0?1:$first_weekday+1);
  2541.       }
  2542.     // Otherwise assume the week starts on a Monday. Anything other
  2543.     // than Sunday or Monday is just plain odd
  2544.     else
  2545.       {
  2546.     $first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year));
  2547.     $first_weekday = ($first_weekday==0?7:$first_weekday);
  2548.       }
  2549.  
  2550.     $days_in_month = date("t", mktime (0,0,0,$c_month,1,$c_year));
  2551.    
  2552.     $racetype       = (isset ($_REQUEST['racetype']))? $_REQUEST['racetype']:'-1';        
  2553.     $racedistance   = (isset ($_REQUEST['racedistance']))? $_REQUEST['racedistance']:'-1';
  2554.     $racelocation   = (isset ($_REQUEST['racelocation']))? $_REQUEST['racelocation']:'-1';
  2555.        
  2556.    
  2557.     // Start the table and add the header and naviagtion
  2558.     $calendar_body = '';    
  2559.     //$calendar_body .= '<form method="get" action="'.htmlspecialchars($_SERVER['REQUEST_URI']).'">';
  2560.     $calendar_body .= '<form method="post" action="'.htmlspecialchars($cdpage_link).'">';    
  2561.     $calendar_body .= '<table cellspacing="1" cellpadding="0" class="calendar-table">';
  2562.     // The header of the calendar table and the links. Note calls to link functions
  2563.    
  2564.    
  2565.     $c_year2  = date("Y");
  2566.     $c_month2 = date("m");
  2567.     $thismonth = false;
  2568.    
  2569.     if($c_year ===  $c_year2 && $c_month === $c_month2){
  2570.         $thismonth = true;
  2571.     }
  2572.    
  2573.     $calendar_body .= '<tr>
  2574.                <td colspan="7" class="calendar-heading notopborder">
  2575.                    <table class="topcdheader" border="0" cellpadding="0" cellspacing="0" width="100%">
  2576.                    <tr><td class="notopborder">
  2577.                    <span class="gradientbutton calendar-prev">' . cb_calender_prev_link($c_year,$c_month) . '</span>
  2578.                    <span class="gradientbutton calendar-next">' . cb_calender_next_link($c_year,$c_month) . '</span>
  2579.                    '.((!$thismonth)? '<span class="gradientbutton calendar-next">'.cb_calender_current_link($c_year2, $c_month2).'</span>':'').'    
  2580.                    <span class="calendar-month">'.$name_months[(int)$c_month].' '.$c_year.'</span>                    
  2581.                    </td></tr>
  2582.                    </table>
  2583.                </td></tr>';
  2584.     // We want to know if we should display the date switcher
  2585.     //$date_switcher = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_jump'",0,0);
  2586.  
  2587.     //if ($date_switcher == 'true')
  2588.       //{
  2589.     $calendar_body .= '<tr>
  2590.        <td colspan="7" class="calendar-date-switcher">';
  2591.             $calendar_body .= '<p>Filter By:';
  2592.             $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));
  2593.             $calendar_body .= '&nbsp;&nbsp;'.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));
  2594.             $calendar_body .= '&nbsp;&nbsp;'.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));
  2595.             $calendar_body .= '</p>';    
  2596.    
  2597.     $qsa = array();
  2598.     parse_str($_SERVER['QUERY_STRING'],$qsa);
  2599.     foreach ($qsa as $name => $argument)
  2600.       {
  2601.         if ($name != 'month' && $name != 'yr')
  2602.           {
  2603.         $calendar_body .= '<input type="hidden" name="'.strip_tags($name).'" value="'.strip_tags($argument).'" />';
  2604.           }
  2605.       }
  2606.  
  2607.     // We build the months in the switcher
  2608.     $calendar_body .= '
  2609.            '.__('Month','calendar').': <select name="month" style="width:100px;">
  2610.            <option value="jan"'.cb_calendar_month_comparison('jan').'>'.__('January','calendar').'</option>
  2611.            <option value="feb"'.cb_calendar_month_comparison('feb').'>'.__('February','calendar').'</option>
  2612.            <option value="mar"'.cb_calendar_month_comparison('mar').'>'.__('March','calendar').'</option>
  2613.            <option value="apr"'.cb_calendar_month_comparison('apr').'>'.__('April','calendar').'</option>
  2614.            <option value="may"'.cb_calendar_month_comparison('may').'>'.__('May','calendar').'</option>
  2615.            <option value="jun"'.cb_calendar_month_comparison('jun').'>'.__('June','calendar').'</option>
  2616.            <option value="jul"'.cb_calendar_month_comparison('jul').'>'.__('July','calendar').'</option>
  2617.            <option value="aug"'.cb_calendar_month_comparison('aug').'>'.__('August','calendar').'</option>
  2618.            <option value="sept"'.cb_calendar_month_comparison('sept').'>'.__('September','calendar').'</option>
  2619.            <option value="oct"'.cb_calendar_month_comparison('oct').'>'.__('October','calendar').'</option>
  2620.            <option value="nov"'.cb_calendar_month_comparison('nov').'>'.__('November','calendar').'</option>
  2621.            <option value="dec"'.cb_calendar_month_comparison('dec').'>'.__('December','calendar').'</option>
  2622.            </select>
  2623.            '.__('Year','calendar').': <select name="yr" style="width:60px;">';
  2624.  
  2625.     // The year builder is string mania. If you can make sense of this, you know your PHP!
  2626.  
  2627.     $past = 30;
  2628.     $future = 30;
  2629.     $fut = 1;
  2630.     $f = '';
  2631.     $p = '';
  2632.     while ($past > 0)
  2633.       {
  2634.         $p .= '            <option value="';
  2635.         $p .= date("Y")-$past;
  2636.         $p .= '"'.cb_calendar_year_comparison(date("Y")-$past).'>';
  2637.         $p .= date("Y")-$past.'</option>';
  2638.         $past = $past - 1;
  2639.       }
  2640.     while ($fut < $future)
  2641.       {
  2642.         $f .= '            <option value="';
  2643.         $f .= date("Y")+$fut;
  2644.         $f .= '"'.cb_calendar_year_comparison(date("Y")+$fut).'>';
  2645.         $f .= date("Y")+$fut.'</option>';
  2646.         $fut = $fut + 1;
  2647.       }
  2648.     $calendar_body .= $p;
  2649.     $calendar_body .= '<option value="'.date("Y").'"'.cb_calendar_year_comparison(date("Y")).'>'.date("Y").'</option>';
  2650.     $calendar_body .= $f;
  2651.         $calendar_body .= '</select>
  2652.            <input class="gradientbutton" id="calendergo" type="submit" value="'.__('Go','calendar').'" />            
  2653.        </td>
  2654. </tr>';
  2655.       //}
  2656.  
  2657.    
  2658.  
  2659.     // Print the headings of the days of the week
  2660.     $calendar_body .= '<tr>';
  2661.     for ($i=1; $i<=7; $i++)
  2662.       {
  2663.     // Colours need to be different if the starting day of the week is different
  2664.     if (get_option('start_of_week') == 0)
  2665.       {
  2666.         $calendar_body .= '<td class="'.($i<7&&$i>1?'normal-day-heading':'weekend-heading').'">'.$name_days[$i].'</td>';
  2667.       }
  2668.     else
  2669.       {
  2670.         $calendar_body .= '<td class="'.($i<6?'normal-day-heading':'weekend-heading').'">'.$name_days[$i].'</td>';
  2671.       }
  2672.       }
  2673.     $calendar_body .= '</tr>';
  2674.     $go = FALSE;
  2675.     for ($i=1; $i<=$days_in_month;)
  2676.       {
  2677.         $calendar_body .= '<tr>';
  2678.         for ($ii=1; $ii<=7; $ii++)
  2679.       {
  2680.             if ($ii==$first_weekday && $i==1)
  2681.           {
  2682.         $go = TRUE;
  2683.           }
  2684.             elseif ($i > $days_in_month )
  2685.           {
  2686.             $go = FALSE;
  2687.           }
  2688.             if ($go)
  2689.           {
  2690.         // Colours again, this time for the day numbers
  2691.         if (get_option('start_of_week') == 0)
  2692.           {
  2693.             // This bit of code is for styles believe it or not.
  2694.             $grabbed_events = cb_grab_events($c_year,$c_month,$i,'calendar');
  2695.             $no_events_class = '';
  2696.             if (!count($grabbed_events))
  2697.               {
  2698.             $no_events_class = ' no-events';
  2699.               }
  2700.             $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>';
  2701.           }
  2702.         else
  2703.           {
  2704.             $grabbed_events = cb_grab_events($c_year,$c_month,$i,'calendar');
  2705.             $no_events_class = '';
  2706.                 if (!count($grabbed_events))
  2707.               {
  2708.             $no_events_class = ' no-events';
  2709.               }
  2710.             $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>';
  2711.           }
  2712.           }
  2713.             else
  2714.           {
  2715.         $calendar_body .= '<td class="day-without-date">&nbsp;</td>';
  2716.           }
  2717.         }
  2718.         $calendar_body .= '</tr>';
  2719.     }
  2720.     $calendar_body .= '</table></form>';
  2721.     //showing legeng color
  2722.     /*
  2723.     $show_cat = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='enable_categories'",0,0);
  2724.  
  2725.     if ($show_cat == 'true')
  2726.       {
  2727.     $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " ORDER BY category_name ASC";
  2728.     $cat_details = $wpdb->get_results($sql);
  2729.         $calendar_body .= '<table class="cat-key">
  2730. <tr><td colspan="2" class="cat-key-cell"><strong>'.__('Category Key','calendar').'</strong></td></tr>
  2731. ';
  2732.         foreach($cat_details as $cat_detail)
  2733.       {
  2734.         $calendar_body .= '<tr><td style="background-color:'.$cat_detail->category_colour.'; width:20px; height:20px;" class="cat-key-cell"></td>
  2735. <td class="cat-key-cell">&nbsp;'.$cat_detail->category_name.'</td></tr>';
  2736.       }
  2737.         $calendar_body .= '</table>
  2738. ';
  2739.       }
  2740.       */
  2741.     $calendar_body .= '<p class="icalimport"><a href="'.  get_home_url().'?ical">iCal import for Latest Race Events</a></p>';
  2742.     return $calendar_body;
  2743. }
  2744.  
  2745. // Setup comparison functions for building the calendar later
  2746. function cb_calendar_month_comparison($month)
  2747. {
  2748.   $current_month = strtolower(date("M"));
  2749.   if (isset($_REQUEST['yr']) && isset($_REQUEST['month']))
  2750.     {
  2751.       if ($month == $_REQUEST['month'])
  2752.     {
  2753.       return ' selected="selected"';
  2754.     }
  2755.     }
  2756.   elseif ($month == $current_month)
  2757.     {
  2758.       return ' selected="selected"';
  2759.     }
  2760. }
  2761.  
  2762. function cb_calendar_year_comparison($year)
  2763. {
  2764.   $current_year = strtolower(date("Y"));
  2765.   if (isset($_REQUEST['yr']) && isset($_REQUEST['month']))
  2766.     {
  2767.       if ($year == $_REQUEST['yr'])
  2768.     {
  2769.       return ' selected="selected"';
  2770.     }
  2771.     }
  2772.   else if ($year == $current_year)
  2773.     {
  2774.       return ' selected="selected"';
  2775.     }
  2776. }
  2777. // Grab all events for the requested date from calendar
  2778. function cb_grab_events($y,$m,$d,$typing){
  2779.   global $wpdb;
  2780.   $racetype       = (isset ($_REQUEST['racetype']))? $_REQUEST['racetype']:'-1';        
  2781.   $racedistance   = (isset ($_REQUEST['racedistance']))? $_REQUEST['racedistance']:'-1';
  2782.   $racelocation   = (isset ($_REQUEST['racelocation']))? $_REQUEST['racelocation']:'-1';
  2783.    
  2784.   $arr_events = array();
  2785.   // Get the date format right
  2786.   $date = $y . '-' . $m . '-' . $d;
  2787.   //var_dump($date);
  2788.   $order          = (isset ($_REQUEST['order']))? sanitize_text_field($_REQUEST['order']):'DESC';
  2789.   $orderby        = (isset ($_REQUEST['orderby']))? sanitize_text_field($_REQUEST['orderby']):'date';
  2790.   $orderby        = 'startdate';
  2791.   $query_args     = array('post_type' => 'race', 'post_status' => 'publish', 'posts_per_page' => 20, 'order' => $order, 'orderby' => $orderby);
  2792.  
  2793.   $query_args['meta_key'] = 'startdate';
  2794.   $query_args['orderby']  = 'meta_value';
  2795.  
  2796.   $meta_query     = array();
  2797.   $tax_query      = array();
  2798.   $meta_query[] =  array(
  2799.             'key' => 'startdate',
  2800.             'value' => $date,
  2801.             'compare' => '=',
  2802.             'type' => 'DATE',
  2803.   );
  2804.  
  2805.   if(!empty($meta_query)){
  2806.     $query_args['meta_query'] = $meta_query;
  2807.   }
  2808.   $tax = 0;
  2809.   if($racetype != '-1'){                
  2810.         $tax ++;
  2811.         $tax_query[] = array(
  2812.                 'taxonomy'  => 'racetype',
  2813.                 'field'     => 'id',
  2814.                 'terms'     => $racetype,
  2815.                 'operator' => 'AND'
  2816.         );
  2817.     }
  2818.    
  2819.     if($racedistance != '-1'){  
  2820.         $tax ++;
  2821.         //var_dump($racedistance);
  2822.         $tax_query[] = array(
  2823.                 'taxonomy'  => 'racedistance',
  2824.                 'field'     => 'id',
  2825.                 'terms'     => array($racedistance),
  2826.                 'operator' => 'IN'
  2827.         );
  2828.     }
  2829.    
  2830.     if($racelocation != '-1'){  
  2831.         $tax ++;
  2832.         $tax_query[] = array(
  2833.                 'taxonomy'  => 'racelocation',
  2834.                 'field'     => 'id',
  2835.                 'terms'     => $racelocation,
  2836.                 'operator' => 'AND'
  2837.         );
  2838.     }
  2839.  
  2840.     if(!empty ($tax_query)){                
  2841.         if($tax > 1){
  2842.             $tax_query['relation'] = 'OR';
  2843.         }
  2844.         $query_args['tax_query'] = $tax_query;
  2845.        
  2846.     }
  2847.  
  2848.   query_posts($query_args);
  2849.   //var_dump($query_args);
  2850.  
  2851.   //var_dump($races);
  2852.   while ( have_posts() ) : the_post();
  2853.     global $post;
  2854.     //var_dump($post);
  2855.     array_push($arr_events, $post);
  2856.   endwhile;
  2857.   //var_dump($arr_events);
  2858.   wp_reset_query();
  2859.   return $arr_events;
  2860. }
  2861.  
  2862. // Used to draw multiple events
  2863. function cb_draw_events($events)
  2864. {
  2865.   // We need to sort arrays of objects by time
  2866.   //usort($events, "cbtime_cmp");
  2867.   //var_dump($events);  
  2868.   $output = '<ul class="cbdayevents">';
  2869.   // Now process the events  
  2870.   //$events   = $events[0];    
  2871.   foreach($events as $event)
  2872.   {
  2873.       //var_dump($event->post_title);
  2874.       $title = $event->post_title;
  2875.       $title = substr($title,0,15).'...';
  2876.       $output .= '<li><a href="'.get_permalink($event->ID).'">'.$title.'</a></li>';
  2877.   }
  2878.   $output .= '</ul>';
  2879.  
  2880.   return $output;
  2881. }
  2882.  
  2883. //cat description editor
  2884.  
  2885. add_action('init', 'catde_init');
  2886. function catde_init() {
  2887.     if ( is_admin() || defined('DOING_AJAX') )
  2888.     {
  2889.         if ( current_user_can('manage_categories') )
  2890.         {
  2891.             //remove_filter('pre_term_description', 'wp_filter_kses');
  2892.             $filters = array('pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description');
  2893.             foreach ( $filters as $filter ) {
  2894.                     remove_filter($filter, 'wp_filter_kses');
  2895.             }
  2896.  
  2897.             foreach ( array( 'term_description' ) as $filter ) {
  2898.                     remove_filter( $filter, 'wp_kses_data' );
  2899.             }
  2900.         }
  2901.  
  2902.     }
  2903. }
  2904.  
  2905. add_action('load-categories.php', 'catde_admin_init');
  2906. add_action('load-edit-tags.php', 'catde_admin_init');
  2907. //add_action('profile.php', 'catde_admin_init2');
  2908. function catde_admin_init()
  2909. {
  2910.     if ( user_can_richedit() && isset($_GET['action']) && 'edit' === $_GET['action'] && ( !empty($_GET['cat_ID']) || ( !empty($_GET['taxonomy']) && !empty($_GET['tag_ID']) ) ) )
  2911.     {
  2912.             add_filter( 'tiny_mce_before_init', 'catde_mceinit');
  2913.             add_action('admin_footer', 'wp_tiny_mce');
  2914.             add_action('admin_head', 'catde_head');
  2915.     }
  2916.  
  2917. }
  2918. /*
  2919. if(is_admin() && (false!==strpos($_SERVER['PHP_SELF'], 'profile.php')) && user_can_richedit())
  2920. {
  2921.     add_filter( 'tiny_mce_before_init', 'catde_mceinit');
  2922.     add_action('admin_footer', 'wp_tiny_mce');
  2923.     add_action('admin_head', 'catde_head');
  2924.  
  2925. }
  2926. */
  2927. function catde_mceinit($init)
  2928. {
  2929.     $init['mode'] = 'textareas';
  2930.     $init['editor_selector'] = '';
  2931.     $init['elements'] = 'category_description,description';
  2932.     $init['plugins'] = 'safari,inlinepopups,autosave,spellchecker,paste,wordpress,media,fullscreen';
  2933.     $init['theme_advanced_buttons1'] .= ',image';
  2934.     $init['theme_advanced_buttons2'] .= ',code';
  2935.     $init['onpageload'] = '';
  2936.     $init['save_callback'] = '';
  2937.  
  2938.     return $init;
  2939. }
  2940.  
  2941. function catde_head() { ?>
  2942.     <style type="text/css">#category_description_tbl,#description_tbl{border:1px solid #dfdfdf;}.wp_themeSkin .mceStatusbar{border-color:#dfdfdf;}</style>
  2943. <?php }
  2944.  
  2945. // Prepend the new column to the columns array
  2946. function cb_customtag_columns($cols) { 
  2947.         $cols['racetype']       = 'Race Types';
  2948.         $cols['racedistance']   = 'Race Distance';
  2949.         $cols['racelocation']   = 'Race Location';
  2950.         $cols['awards']         = 'Race Awards';
  2951.     return $cols;
  2952. }
  2953.  
  2954. // Echo the ID for the new column
  2955. function cb_customtags_value($column_name, $id) {  
  2956.         if ($column_name == 'racetype'){
  2957.                     echo get_the_term_list( $id, 'racetype', '', ', ', '' );
  2958.         }
  2959.         if ($column_name == 'racedistance'){
  2960.                     echo get_the_term_list( $id, 'racedistance', '', ', ', '' );
  2961.         }
  2962.         if ($column_name == 'racelocation'){
  2963.                     echo get_the_term_list( $id, 'racelocation', '', ', ', '' );
  2964.         }
  2965.         if ($column_name == 'awards'){
  2966.                     echo get_the_term_list( $id, 'awards', '', ', ', '' );
  2967.         }
  2968. }
  2969.  
  2970. function cb_add_custom_taxonomy_col()
  2971. {
  2972.     add_filter('manage_race_posts_columns', 'cb_customtag_columns');
  2973.     add_action('manage_race_posts_custom_column', 'cb_customtags_value', 10, 2);
  2974. }
  2975. add_action('admin_init', 'cb_add_custom_taxonomy_col');
  2976. /*
  2977. function rdrole_column_orderby( $vars ) {
  2978.    if ( isset( $vars['orderby'] ) && 'rdrole' == $vars['orderby'] ) {
  2979.       $vars = array_merge( $vars, array(
  2980.          'meta_key' => 'rdrole',
  2981.          'orderby' => 'meta_value_num'
  2982.       ) );
  2983.    }
  2984.  
  2985.    return $vars;
  2986. }
  2987. add_filter( 'request', 'rdrole_column_orderby' );
  2988. */
  2989. // get the "contributor" role object
  2990. $obj_existing_role = get_role( 'contributor' );
  2991. // add the "organize_gallery" capability
  2992. $obj_existing_role->add_cap( 'edit_published_posts' );
  2993.  
  2994. function cb_yesno($yes){
  2995.     $yes = intval($yes);
  2996.     if($yes) return 'Yes';
  2997.     else return 'No';
  2998. }
  2999.  
  3000. //input yyyy-mm-dd  output   dd-mm-yyyy
  3001. function convert_datetoukdate($strDate){
  3002.    if(empty($strDate)) return '';
  3003.    trim($strDate);
  3004.    list($y, $m, $d) = explode('-', $strDate);
  3005.    $mk = mktime(0,0,0,$m, $d, $y);
  3006.    $europeanDate = strftime('%d-%m-%Y',$mk);
  3007.    return $europeanDate;
  3008. }
  3009.  
  3010. //input dd-mm-yyyy  output   yyyy-mm-dd
  3011. function convert_ukdatetodate($strDate){
  3012.    if(empty($strDate)) return '';
  3013.    trim($strDate);
  3014.    list($d, $m, $y) = explode('-', $strDate);
  3015.    $mk = mktime(0,0,0,$m, $d, $y);
  3016.    $europeanDate = strftime('%Y-%m-%d',$mk);
  3017.    return $europeanDate;
  3018. }
  3019.  
  3020. //dd-mm-yyyy
  3021. function cv_isvalid_date($date = ''){
  3022.     $return  = true;
  3023.     if($date == '') $return =  false;
  3024.     if (preg_match("/([0-9]{2})\-([0-9]{2})\-([0-9]{4})/", $date, $matches)) {
  3025.         if (!checkdate($matches[2], $matches[1], $matches[3])) {
  3026.             $return = false;
  3027.         }
  3028.     }else {
  3029.     $return =  false;
  3030.     }
  3031.     return $return;
  3032. }
  3033.  
  3034. //possible use in widget
  3035. function cb_merged_custom_wp_tag_cloud( $args = '' ) {
  3036.     $defaults = array(
  3037.         'smallest' => 12, 'largest' => 26, 'unit' => 'px', 'number' => 25,
  3038.         'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
  3039.         'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true
  3040.     );
  3041.     $args = wp_parse_args( $args, $defaults );
  3042.  
  3043.     $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
  3044.  
  3045.     if ( empty( $tags ) )
  3046.         return;
  3047.  
  3048.     foreach ( $tags as $key => $tag ) {
  3049.         if ( 'edit' == $args['link'] )
  3050.             $link = get_edit_tag_link( $tag->term_id, $tag->taxonomy );
  3051.         else
  3052.             $link = get_term_link( intval($tag->term_id), $tag->taxonomy );
  3053.         if ( is_wp_error( $link ) )
  3054.             return false;
  3055.  
  3056.         $tags[ $key ]->link = $link;
  3057.         $tags[ $key ]->id = $tag->term_id;
  3058.     }
  3059.  
  3060.     $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
  3061.  
  3062.     $return = apply_filters( 'wp_tag_cloud', $return, $args );
  3063.  
  3064.     if ( 'array' == $args['format'] || empty($args['echo']) )
  3065.         return $return;
  3066.  
  3067.     echo $return;
  3068. }
  3069.  
  3070. add_action('init', 'codeboxrical', 0,1);
  3071. function codeboxrical(){
  3072.     if (isset($_GET['ical']))
  3073.     {
  3074.         //add_action('init', 'cbraceical', 1,1);
  3075.         //remove_action('widgets_init','');
  3076.         cbraceical();
  3077.         //remove_action('wp_footer', '');
  3078.     }
  3079.  
  3080.     if (isset($_GET['icalpid']))
  3081.     {
  3082.         //add_action('init', 'cbraceicalpid', 1,1);
  3083.         //remove_action('widgets_init','');
  3084.         cbraceicalpid();
  3085.     }
  3086. }
  3087.  
  3088.  
  3089. //outputs ical  for latest race events for before or up 2 months.
  3090. function cbraceical(){
  3091.     global $wpdb;
  3092.     //define('WP_USE_THEMES', false);
  3093.     // clean the output buffer
  3094.    
  3095.     //$buf = ob_get_clean();
  3096.  
  3097.     //echo $buf;
  3098.     //ob_clean();
  3099.     //exit;
  3100.    
  3101.     if (isset($_GET["icaldebug"]))
  3102.     {
  3103.         define("DEBUG", true);
  3104.     }
  3105.    
  3106.     $blogName = get_bloginfo('name');
  3107.     $blogURL = get_bloginfo('home');
  3108.    
  3109.     if (!defined('DEBUG'))
  3110.     {
  3111.             header('Content-Type: text/calendar; charset=UTF-8');
  3112.             header('Content-Disposition: attachment; filename="iCal-Gangsperrelatest20.ics"');
  3113.     }
  3114.    
  3115.     $number     = 20;
  3116.    
  3117.     $upmonth    = 2;
  3118.     $downmonth  = 2;
  3119.     $meta_query     = array();
  3120.     if($upmonth > 0){
  3121.         $upmonth    = strtotime("+" . $upmonth . " month");
  3122.         $upmonth    = date("Y-m-d", $upmonth);
  3123.  
  3124.         $meta_query[] =  array(
  3125.                 'key' => 'startdate',
  3126.                 'value' => $upmonth,
  3127.                 'compare' => '<=',
  3128.                 'type' => 'DATE',
  3129.         );
  3130.  
  3131.     }
  3132.  
  3133.     if($downmonth > 0){
  3134.         $downmonth    = strtotime("-" . $downmonth . " month");
  3135.         $downmonth    = date("Y-m-d", $downmonth);
  3136.         $meta_query[] =  array(
  3137.                 'key' => 'startdate',
  3138.                 'value' => $downmonth,
  3139.                 'compare' => '>=',
  3140.                 'type' => 'DATE',
  3141.         );
  3142.     }
  3143.    
  3144.     $orderby = 'startdate';
  3145.    
  3146.     $query_args = array('post_type' => 'race', 'paged' => 1, 'posts_per_page' => $number,'order' => 'DESC', 'orderby' => $orderby);
  3147.     $query_args['meta_key'] = 'startdate';
  3148.     $query_args['orderby']  = 'meta_value';
  3149.  
  3150.     if(!empty($meta_query)){
  3151.         $query_args['meta_query'] = $meta_query;
  3152.     }
  3153.  
  3154.     //var_dump($query_args);
  3155.    
  3156.     query_posts($query_args);
  3157.     $events = "";
  3158.     $space = "    ";
  3159.    
  3160.     while ( have_posts() ) : the_post();                    
  3161.         $id = get_the_ID();
  3162.         $startdate      = get_post_meta( $id, 'startdate', true); //yyyy-mm-dd
  3163.         $starttime      = get_post_meta( $id, 'starttime', true); //hh:mm
  3164.         $venue          = get_post_meta( $id, 'venue', true);
  3165.         $racewebsite    = get_post_meta( $id, 'racewebsite', true);
  3166.         //$startdate      = convert_datetoukdate($startdate); //dd-mm-yyyy
  3167.         //echo '<li>: '.$startdate.' <a href="'.get_permalink().'">'.get_the_title().'</a></li>';
  3168.         $convertDateStart = explode("-", $startdate);
  3169.         //$convertDateEnd = explode("-", $post->eventEndDate);
  3170.  
  3171.         if (NULL != $starttime)
  3172.         {
  3173.                 $convertHoursStart = explode(":", $starttime);
  3174.         }
  3175.         else
  3176.         {
  3177.                 $convertHoursStart = explode(":", "20:00:00");
  3178.         }
  3179.         /*
  3180.         if (NULL != $post->eventEndTime)
  3181.         {
  3182.                 $convertHoursEnd = explode(":", $post->eventEndTime);
  3183.         }
  3184.         */
  3185.         //else
  3186.         //{
  3187.                 $convertHoursEnd = explode(":", "20:00:00");
  3188.         //}
  3189.        
  3190.         $convertedStart = mktime(
  3191.                 $convertHoursStart[0] - get_option("gmt_offset"),   //hours
  3192.                 $convertHoursStart[1],                              //minutes
  3193.                 $convertHoursStart[2],                              //seconds
  3194.                 $convertDateStart[1],                               //month
  3195.                 $convertDateStart[2],                               //day
  3196.                 $convertDateStart[0]                                //year
  3197.         );
  3198.  
  3199.         $convertedEnd = mktime(
  3200.                 $convertHoursEnd[0] - get_option("gmt_offset"),     //hours
  3201.                 $convertHoursEnd[1],                                //minutes
  3202.                 $convertHoursEnd[2],                                //seconds
  3203.                 $convertDateEnd[1],                                 //month
  3204.                 $convertDateEnd[2],                                 //day
  3205.                 $convertDateEnd[0]                                  //year
  3206.         );
  3207.  
  3208.         $eventStart = date("Ymd\THis", $convertedStart) . "Z";
  3209.         $eventEnd = date("Ymd\THis", $convertedEnd) . "Z";
  3210.         $summary = get_the_title($id);
  3211.        
  3212.         $summary = str_replace(",", "\,", $summary);
  3213.         $summary = str_replace("\\", "\\\\", $summary);
  3214.         $summary = str_replace("\n", $space, strip_tags($summary));
  3215.         $summary = str_replace("\r", $space, strip_tags($summary));
  3216.        
  3217.         $description = get_the_excerpt();
  3218.         $description = str_replace(",", "\,", $description);
  3219.         $description = str_replace("\\", "\\\\", $description);
  3220.         $description = str_replace("\n", $space, strip_tags($description));
  3221.         $description = str_replace("\r", $space, strip_tags($description));
  3222.         $location = $venue;
  3223.         $link = $racewebsite;
  3224.  
  3225.         $uid = $id . "@" . get_bloginfo('home');
  3226.  
  3227.         $events .= "BEGIN:VEVENT\r\n";
  3228.         $events .= "UID:" . $uid . "\r\n";
  3229.         $events .= "DTSTART:" . $eventStart . "\r\n";
  3230.         $events .= "DTEND:" . $eventEnd . "\r\n";
  3231.         $events .= "LOCATION:" . $location . "\r\n";
  3232.         $events .= "SUMMARY:" . $summary . "\r\n";
  3233.         if (is_null($link))
  3234.         {
  3235.                 // no link out
  3236.                 $events .= "DESCRIPTION:" . $description . "\r\n";
  3237.         }
  3238.         else
  3239.         {
  3240.                 // has link out
  3241.                 $events .= "DESCRIPTION;ALTREP=\"" . $link . "\":";
  3242.                 $events .= $description . "\r\n";
  3243.         }
  3244.         $events .= "END:VEVENT\r\n";
  3245.         $events .= "\r\n";
  3246.     endwhile;
  3247.    
  3248.     wp_reset_query(); //reset query
  3249.    
  3250.    
  3251.    
  3252.     $content = "BEGIN:VCALENDAR\r\n";
  3253.     $content .= "VERSION:2.0\r\n";
  3254.     $content .= "PRODID:-//" . $blogName . "//NONSGML v1.0//EN\r\n";
  3255.     $content .= "X-WR-CALNAME:" . $blogName . "\r\n";
  3256.     $content .= "X-ORIGINAL-URL:" . $blogURL . "\r\n";
  3257.     $content .= "X-WR-CALDESC:Events for " . $blogName . "\r\n";
  3258.     $content .= "CALSCALE:GREGORIAN\r\n";
  3259.     $content .= "METHOD:PUBLISH\r\n";
  3260.     $content .= $events;
  3261.     $content .= "END:VCALENDAR";
  3262.  
  3263.     echo $content;
  3264.  
  3265.     if (defined('DEBUG'))
  3266.     {
  3267.             echo "\n" . $queryEvents . "\n";   
  3268.             echo $eventStart . "\n";
  3269.     }
  3270.  
  3271.     exit;
  3272. }
  3273.  
  3274.  
  3275. //outputs ical  for latest race events for before or up 2 months.
  3276. function cbraceicalpid(){
  3277.     global $wpdb;
  3278.     if (isset($_GET["icaldebug"]))
  3279.     {
  3280.         define("DEBUG", true);
  3281.     }
  3282.    
  3283.     $blogName = get_bloginfo('name');
  3284.     $blogURL = get_bloginfo('home');
  3285.    
  3286.     $icalpid = sanitize_text_field($_GET['icalpid']);
  3287.     $icalpid = intval($icalpid);
  3288.    
  3289.     $postitle = get_the_title($icalpid);
  3290.     //var_dump($postitle);
  3291.    
  3292.     if (!defined('DEBUG'))
  3293.     {
  3294.             header('Content-Type: text/calendar; charset=UTF-8');
  3295.             header('Content-Disposition: attachment; filename="iCal-Gangsperre-'.$postitle.'.ics"');
  3296.     }
  3297.        
  3298.     /*
  3299.     $number     = 20;
  3300.    
  3301.     $upmonth    = 2;
  3302.     $downmonth  = 2;
  3303.    
  3304.     $meta_query     = array();
  3305.     if($upmonth > 0){
  3306.         $upmonth    = strtotime("+" . $upmonth . " month");
  3307.         $upmonth    = date("Y-m-d", $upmonth);
  3308.  
  3309.         $meta_query[] =  array(
  3310.                 'key' => 'startdate',
  3311.                 'value' => $upmonth,
  3312.                 'compare' => '<=',
  3313.                 'type' => 'DATE',
  3314.         );
  3315.  
  3316.     }
  3317.  
  3318.     if($downmonth > 0){
  3319.         $downmonth    = strtotime("-" . $downmonth . " month");
  3320.         $downmonth    = date("Y-m-d", $downmonth);
  3321.         $meta_query[] =  array(
  3322.                 'key' => 'startdate',
  3323.                 'value' => $downmonth,
  3324.                 'compare' => '>=',
  3325.                 'type' => 'DATE',
  3326.         );
  3327.     }
  3328.    
  3329.     $orderby = 'startdate';
  3330.     */
  3331.    
  3332.    
  3333.    
  3334.     $query_args = array('post_type' => 'race','p' => $icalpid);
  3335.     /*
  3336.     $query_args['meta_key'] = 'startdate';
  3337.     $query_args['orderby']  = 'meta_value';
  3338.  
  3339.     if(!empty($meta_query)){
  3340.         $query_args['meta_query'] = $meta_query;
  3341.     }
  3342.     */
  3343.     //var_dump($query_args);
  3344.    
  3345.     query_posts($query_args);
  3346.     $events = "";
  3347.     $space = "    ";
  3348.    
  3349.    
  3350.     while ( have_posts() ) : the_post();                    
  3351.         $id = get_the_ID();
  3352.         $startdate      = get_post_meta( $id, 'startdate', true); //yyyy-mm-dd
  3353.         $starttime      = get_post_meta( $id, 'starttime', true); //hh:mm
  3354.         $venue          = get_post_meta( $id, 'venue', true);
  3355.         $racewebsite    = get_post_meta( $id, 'racewebsite', true);
  3356.         //$startdate      = convert_datetoukdate($startdate); //dd-mm-yyyy
  3357.         //echo '<li>: '.$startdate.' <a href="'.get_permalink().'">'.get_the_title().'</a></li>';
  3358.         $convertDateStart = explode("-", $startdate);
  3359.         //$convertDateEnd = explode("-", $post->eventEndDate);
  3360.  
  3361.         if (NULL != $starttime)
  3362.         {
  3363.                 $convertHoursStart = explode(":", $starttime);
  3364.         }
  3365.         else
  3366.         {
  3367.                 $convertHoursStart = explode(":", "20:00:00");
  3368.         }
  3369.         /*
  3370.         if (NULL != $post->eventEndTime)
  3371.         {
  3372.                 $convertHoursEnd = explode(":", $post->eventEndTime);
  3373.         }
  3374.         */
  3375.         //else
  3376.         //{
  3377.                 $convertHoursEnd = explode(":", "20:00:00");
  3378.         //}
  3379.        
  3380.         $convertedStart = mktime(
  3381.                 $convertHoursStart[0] - get_option("gmt_offset"),   //hours
  3382.                 $convertHoursStart[1],                              //minutes
  3383.                 $convertHoursStart[2],                              //seconds
  3384.                 $convertDateStart[1],                               //month
  3385.                 $convertDateStart[2],                               //day
  3386.                 $convertDateStart[0]                                //year
  3387.         );
  3388.  
  3389.         $convertedEnd = mktime(
  3390.                 $convertHoursEnd[0] - get_option("gmt_offset"),     //hours
  3391.                 $convertHoursEnd[1],                                //minutes
  3392.                 $convertHoursEnd[2],                                //seconds
  3393.                 $convertDateEnd[1],                                 //month
  3394.                 $convertDateEnd[2],                                 //day
  3395.                 $convertDateEnd[0]                                  //year
  3396.         );
  3397.  
  3398.         $eventStart = date("Ymd\THis", $convertedStart) . "Z";
  3399.         $eventEnd = date("Ymd\THis", $convertedEnd) . "Z";
  3400.         $summary = get_the_title($id);
  3401.         $summary = str_replace(",", "\,", $summary);
  3402.         $summary = str_replace("\\", "\\\\", $summary);
  3403.         $summary = str_replace("\n", $space, strip_tags($summary));
  3404.         $summary = str_replace("\r", $space, strip_tags($summary));
  3405.        
  3406.         //$postitle = $summary;
  3407.        
  3408.         $description = get_the_excerpt();
  3409.         $description = str_replace(",", "\,", $description);
  3410.         $description = str_replace("\\", "\\\\", $description);
  3411.         $description = str_replace("\n", $space, strip_tags($description));
  3412.         $description = str_replace("\r", $space, strip_tags($description));
  3413.         $location = $venue;
  3414.         $link = $racewebsite;
  3415.  
  3416.         $uid = $id . "@" . get_bloginfo('home');
  3417.  
  3418.         $events .= "BEGIN:VEVENT\r\n";
  3419.         $events .= "UID:" . $uid . "\r\n";
  3420.         $events .= "DTSTART:" . $eventStart . "\r\n";
  3421.         $events .= "DTEND:" . $eventEnd . "\r\n";
  3422.         $events .= "LOCATION:" . $location . "\r\n";
  3423.         $events .= "SUMMARY:" . $summary . "\r\n";
  3424.         if (is_null($link))
  3425.         {
  3426.                 // no link out
  3427.                 $events .= "DESCRIPTION:" . $description . "\r\n";
  3428.         }
  3429.         else
  3430.         {
  3431.                 // has link out
  3432.                 $events .= "DESCRIPTION;ALTREP=\"" . $link . "\":";
  3433.                 $events .= $description . "\r\n";
  3434.         }
  3435.         $events .= "END:VEVENT\r\n";
  3436.         $events .= "\r\n";
  3437.     endwhile;
  3438.    
  3439.     wp_reset_query(); //reset query
  3440.    
  3441.    
  3442.    
  3443.     $content = "BEGIN:VCALENDAR\r\n";
  3444.     $content .= "VERSION:2.0\r\n";
  3445.     $content .= "PRODID:-//" . $blogName . "//NONSGML v1.0//EN\r\n";
  3446.     $content .= "X-WR-CALNAME:" . $blogName . "\r\n";
  3447.     $content .= "X-ORIGINAL-URL:" . $blogURL . "\r\n";
  3448.     $content .= "X-WR-CALDESC:Events for " . $blogName . "\r\n";
  3449.     $content .= "CALSCALE:GREGORIAN\r\n";
  3450.     $content .= "METHOD:PUBLISH\r\n";
  3451.     $content .= $events;
  3452.     $content .= "END:VCALENDAR";
  3453.  
  3454.     echo $content;
  3455.  
  3456.     if (defined('DEBUG'))
  3457.     {
  3458.             echo "\n" . $queryEvents . "\n";   
  3459.             echo $eventStart . "\n";
  3460.     }
  3461.  
  3462.     exit;
  3463. }
  3464.  
  3465. function insert_attachment($file_handler,$post_id,$setthumb='false') {
  3466.  
  3467.   // check to make sure its a successful upload
  3468.   if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
  3469.   //if ($file_handler['error'] !== UPLOAD_ERR_OK) __return_false();
  3470.  
  3471.   require_once(ABSPATH . "wp-admin" . '/includes/image.php');
  3472.   require_once(ABSPATH . "wp-admin" . '/includes/file.php');
  3473.   require_once(ABSPATH . "wp-admin" . '/includes/media.php');
  3474.  
  3475.   $attach_id = media_handle_upload( $file_handler, $post_id );
  3476.   //var_dump($attach_id);
  3477.   if(!is_wp_error($attach_id)):
  3478.     if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id);
  3479.   endif;
  3480.   return $attach_id;
  3481. }
  3482.  
  3483. function cbrtp_display_to_content(){
  3484.     $display = '';
  3485.     if(function_exists('rtp_display_template')):
  3486.         $display = rtp_display_template();
  3487.     endif;
  3488.    
  3489.     return $display;
  3490. }
  3491.  
  3492.  
  3493. /**
  3494.  * Display or retrieve the HTML dropdown list of categories.
  3495.  *
  3496.  * The list of arguments is below:
  3497.  *     'show_option_all' (string) - Text to display for showing all categories.
  3498.  *     'show_option_none' (string) - Text to display for showing no categories.
  3499.  *     'orderby' (string) default is 'ID' - What column to use for ordering the
  3500.  * categories.
  3501.  *     'order' (string) default is 'ASC' - What direction to order categories.
  3502.  *     'show_last_update' (bool|int) default is 0 - See {@link get_categories()}
  3503.  *     'show_count' (bool|int) default is 0 - Whether to show how many posts are
  3504.  * in the category.
  3505.  *     'hide_empty' (bool|int) default is 1 - Whether to hide categories that
  3506.  * don't have any posts attached to them.
  3507.  *     'child_of' (int) default is 0 - See {@link get_categories()}.
  3508.  *     'exclude' (string) - See {@link get_categories()}.
  3509.  *     'echo' (bool|int) default is 1 - Whether to display or retrieve content.
  3510.  *     'depth' (int) - The max depth.
  3511.  *     'tab_index' (int) - Tab index for select element.
  3512.  *     'name' (string) - The name attribute value for select element.
  3513.  *     'id' (string) - The ID attribute value for select element. Defaults to name if omitted.
  3514.  *     'class' (string) - The class attribute value for select element.
  3515.  *     'selected' (int) - Which category ID is selected.
  3516.  *     'taxonomy' (string) - The name of the taxonomy to retrieve. Defaults to category.
  3517.  *
  3518.  * The 'hierarchical' argument, which is disabled by default, will override the
  3519.  * depth argument, unless it is true. When the argument is false, it will
  3520.  * display all of the categories. When it is enabled it will use the value in
  3521.  * the 'depth' argument.
  3522.  *
  3523.  * @since 2.1.0
  3524.  *
  3525.  * @param string|array $args Optional. Override default arguments.
  3526.  * @return string HTML content only if 'echo' argument is 0.
  3527.  */
  3528. function cb_wp_dropdown_categories( $args = '' ) {
  3529.     $defaults = array(
  3530.         'show_option_all' => '', 'show_option_none' => '',
  3531.         'orderby' => 'id', 'order' => 'ASC',
  3532.         'show_last_update' => 0, 'show_count' => 0,
  3533.         'hide_empty' => 1, 'child_of' => 0,
  3534.         'exclude' => '', 'echo' => 1,
  3535.         'selected' => 0, 'hierarchical' => 0,
  3536.         'name' => 'cat', 'id' => '',
  3537.         'class' => 'postform', 'depth' => 0,
  3538.         'tab_index' => 0, 'taxonomy' => 'category',
  3539.         'hide_if_empty' => false
  3540.     );
  3541.  
  3542.     $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
  3543.  
  3544.     // Back compat.
  3545.     if ( isset( $args['type'] ) && 'link' == $args['type'] ) {
  3546.         _deprecated_argument( __FUNCTION__, '3.0', '' );
  3547.         $args['taxonomy'] = 'link_category';
  3548.     }
  3549.  
  3550.     $r = wp_parse_args( $args, $defaults );
  3551.  
  3552.     if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
  3553.         $r['pad_counts'] = true;
  3554.     }
  3555.  
  3556.     $r['include_last_update_time'] = $r['show_last_update'];
  3557.     extract( $r );
  3558.  
  3559.     $tab_index_attribute = '';
  3560.     if ( (int) $tab_index > 0 )
  3561.         $tab_index_attribute = " tabindex=\"$tab_index\"";
  3562.  
  3563.     $categories = get_terms( $taxonomy, $r );
  3564.     $name = esc_attr( $name );
  3565.     $class = esc_attr( $class );
  3566.     $id = $id ? esc_attr( $id ) : $name;
  3567.  
  3568.     if ( ! $r['hide_if_empty'] || ! empty($categories) )
  3569.         $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
  3570.     else
  3571.         $output = '';
  3572.  
  3573.     if ( empty($categories) && ! $r['hide_if_empty'] && !empty($show_option_none) ) {
  3574.         $show_option_none = apply_filters( 'list_cats', $show_option_none );
  3575.         $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
  3576.     }
  3577.  
  3578.     if ( ! empty( $categories ) ) {
  3579.  
  3580.         if ( $show_option_all ) {
  3581.             $show_option_all = apply_filters( 'list_cats', $show_option_all );
  3582.             $selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';
  3583.             $output .= "\t<option value='0'$selected>$show_option_all</option>\n";
  3584.         }
  3585.  
  3586.         if ( $show_option_none ) {
  3587.             $show_option_none = apply_filters( 'list_cats', $show_option_none );
  3588.             $selected = ( '-1' === strval($r['selected']) ) ? " selected='selected'" : '';
  3589.             $output .= "\t<option value='-1'$selected>$show_option_none</option>\n";
  3590.         }
  3591.  
  3592.         if ( $hierarchical )
  3593.             $depth = $r['depth'];  // Walk the full depth.
  3594.         else
  3595.             $depth = -1; // Flat.
  3596.  
  3597.         $output .= walk_category_dropdown_tree( $categories, $depth, $r );
  3598.     }
  3599.     if ( ! $r['hide_if_empty'] || ! empty($categories) )
  3600.         $output .= "</select>\n";
  3601.  
  3602.  
  3603.     $output = apply_filters( 'wp_dropdown_cats', $output );
  3604.  
  3605.     if ( $echo )
  3606.         echo $output;
  3607.  
  3608.     return $output;
  3609. }
  3610.  
  3611. add_action('wp_ajax_cbajaxracevote', 'cbajaxracevote');
  3612.  
  3613. function cbajaxracevote(){
  3614.     ob_clean();
  3615.     check_ajax_referer('raceresult');
  3616.     if(!is_user_logged_in()){echo 'Something wrong!';}
  3617.     global  $userdata;
  3618.     //var_dump($userdata);
  3619.     $accessid = $userdata->data->ID;
  3620.     //var_dump($accessid);
  3621.     $userid     = esc_attr($_POST['userid']);
  3622.     $postid     = esc_attr($_POST['postid']);
  3623.     //var_dump($postid);
  3624.     $resulturl  = esc_url($_POST['resulturl']);
  3625.     if($userid != $accessid){ echo 'Something wrong!';}
  3626.     else{
  3627.         $mypost     = get_post($postid);
  3628.         //var_dump($mypost);
  3629.         $authorid   = $mypost->post_author;  
  3630.         //var_dump($authorid);
  3631.         if($authorid != $userid){ echo 'Something wrong!';}
  3632.         else{
  3633.             $result = update_post_meta($postid, "resulturl", $resulturl);
  3634.             if($result) {echo 'Result url updated!';}
  3635.             else{echo 'Something wrong!';}
  3636.         }
  3637.     }
  3638.     die();
  3639. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement