Advertisement
Guest User

Untitled

a guest
Dec 11th, 2014
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 7.27 KB | None | 0 0
  1. add_shortcode( 'app_random_service_providers', 'process_random_service_providers_shortcode');
  2. function process_random_service_providers_shortcode ($args=array(), $content='') {
  3.  
  4.   $defaults = array(
  5.       'select' => array(
  6.         'value' => __('Your Service Provider:', 'appointments'),
  7.         'help' => __('Text above the select menu. Default: "Please select a service"', 'appointments'),
  8.         'example' => __('Please choose a service provider:', 'appointments'),
  9.       ),
  10.       'description' => array(
  11.         'value' => 'excerpt',
  12.         'help' => __('Selects which part of the bio page will be displayed under the dropdown menu when a service provider is selected . Selectable values are "none", "excerpt", "content". Default: "excerpt"', 'appointments'),
  13.         'allowed_values' => array('none', 'excerpt', 'content',),
  14.         'example' => 'content',
  15.       ),
  16.       'thumb_size' => array(
  17.         'value' => '96,96',
  18.         'help' => __('Inserts the post thumbnail if page has a featured image. Selectable values are "none", "thumbnail", "medium", "full" or a 2 numbers separated by comma representing width and height in pixels, e.g. 32,32. Default: "96,96"', 'appointments'),
  19.         'example' => 'thumbnail',
  20.       ),
  21.       'thumb_class' => array(
  22.         'value' => 'alignleft',
  23.         'help' => __('css class that will be applied to the thumbnail. Default: "alignleft"', 'appointments'),
  24.         'example' => 'my-class',
  25.       ),
  26.       'autorefresh' => array(
  27.         'value' => 0,
  28.         'help' => __('If set as 1, Show button will not be displayed and page will be automatically refreshed as client changes selection. Note: Client cannot browse through the selections and thus check descriptions on the fly (without the page is refreshed). Default: "0" (disabled)', 'appointments'),
  29.         'example' => '1',
  30.       ),
  31.       'order_by' => array(
  32.         'value' => 'ID',
  33.         'help' => __('Sort order of the service providers. Possible values: ID, name. Optionally DESC (descending) can be used, e.g. "name DESC" will reverse the order. Default: "ID"', 'appointments'),
  34.         'example' => 'ID',
  35.       ),
  36.       'service' => array(
  37.         'value' => 0,
  38.         'help' => __('In some cases, you may want to force to display providers who give only a certain service. In that case enter service ID here. Default: "0" (list is determined by services dropdown). Note: Multiple selections are not allowed.', 'appointments'),
  39.         'example' => '12',
  40.       ),
  41.       'require_service' => array(
  42.         'value' => 0,
  43.         'help' => __('Do not show service provider selection at all until the service has been previously selected.', 'appointments'),
  44.         'example' => '1',
  45.       ),
  46.       '_noscript' => array('value' => 0),
  47.  
  48.     );
  49.     $ret = array();
  50.     foreach ($defaults as $key => $item) {
  51.       $ret[$key] = $item['value'];
  52.     }
  53.     $defaults = $ret;
  54.     extract(wp_parse_args($args, $defaults));
  55.  
  56.     if (!empty($require_service) && empty($service) && empty($_REQUEST['app_service_id'])) return $content;
  57.  
  58.     global $wpdb, $appointments;
  59.     $appointments->get_lsw();
  60.  
  61.     if ( !trim( $order_by ) )
  62.       $order_by = 'ID';
  63.  
  64.     if ( !$service ) {
  65.       if ( 0 == $appointments->service )
  66.         $workers = $appointments->get_workers( $order_by );
  67.       else
  68.         $workers = $appointments->get_workers_by_service( $appointments->service, $order_by ); // Select only providers that can give this service
  69.     }
  70.     else
  71.       $workers = $appointments->get_workers_by_service( $service, $order_by );
  72.  
  73.     $workers = apply_filters( 'app_workers', $workers );
  74.  
  75.     // If there are no workers do nothing
  76.     if ( !$workers || empty( $workers) )
  77.       return;
  78.  
  79.     $script ='';
  80.     $s = $e = '';
  81.  
  82.     $s .= '<div class="app_workers" >';
  83.     $s .= '<div class="app_workers_dropdown">';
  84.     $s .= '<div class="app_workers_dropdown_title">';
  85.     $s .= $select;
  86.     $s .= '</div>';
  87.     $s .= '<div class="app_workers_dropdown_select">';
  88.     $s .= '<select name="app_select_workers" class="app_select_workers" disabled>';
  89.     // Do not show "Anyone" if there is only ONE provider
  90.     if ( 1 != count( $workers ) )
  91.     $w_count = count( $workers );
  92.     $rand_n = rand( 0, ( $w_count - 1 ) );
  93.     foreach ( $workers as $key => $worker ) {
  94.       $worker_description = '';
  95.  
  96.       if ( $appointments->worker == $worker->ID || 1 == count( $workers ) ||  ( $key == $rand_n ) ) {
  97.         $d = '';
  98.         $sel = ' selected="selected"';
  99.       }
  100.       else {
  101.         $d = ' style="display:none"';
  102.         $sel = '';
  103.       }
  104.       $s .= '<option value="'.$worker->ID.'"'.$sel.'>'. $appointments->get_worker_name( $worker->ID )  . '</option>';
  105.       // Include excerpts
  106.       $e .= '<div '.$d.' class="app_worker_excerpt" id="app_worker_excerpt_'.$worker->ID.'" >';
  107.       // Let addons modify worker bio page
  108.       $page = apply_filters( 'app_worker_page', $worker->page, $worker->ID );
  109.       switch ( $description ) {
  110.         case 'none'     :       break;
  111.         case 'excerpt'  :       $worker_description .= $appointments->get_excerpt( $page, $thumb_size, $thumb_class, $worker->ID ); break;
  112.         case 'content'  :       $worker_description .= $appointments->get_content( $page, $thumb_size, $thumb_class, $worker->ID ); break;
  113.         default         :       $worker_description .= $appointments->get_excerpt( $page, $thumb_size, $thumb_class, $worker->ID ); break;
  114.       }
  115.       $e .= apply_filters('app-workers-worker_description', $worker_description, $worker, $description) . '</div>';
  116.     }
  117.  
  118.     $s .= '</select>';
  119.     $s .= '</div>';
  120.     $s .= '</div>';
  121.     $s .= '<div class="app_worker_excerpts">';
  122.     $s .= $e;
  123.     $s .= '</div>';
  124.  
  125.     $s .= '</div>';
  126.     if ( isset( $_GET['wcalendar'] ) )
  127.       $wcalendar = $_GET['wcalendar'];
  128.     else
  129.       $wcalendar = false;
  130.     // First remove these parameters and add them again to make wcalendar appear before js variable
  131.     $href = add_query_arg( array( "wcalendar"=>false, "app_provider_id" =>false ) );
  132.     $href = apply_filters( 'app_worker_href', add_query_arg( array( "wcalendar"=>$wcalendar, "app_provider_id" => "'+selected_worker" ), $href ) );
  133.  
  134.     if ( $autorefresh ) {
  135.       $script .= "$('.app_workers_button').hide();";
  136.     }
  137.     $script .= "$('.app_select_workers').change(function(){";
  138.     $script .= "var selected_worker=$('.app_select_workers option:selected').val();";
  139.     $script .= "if (typeof selected_worker=='undefined' || selected_worker==null){";
  140.     $script .= "selected_worker=0;";
  141.     $script .= "}";
  142.     $script .= "$('.app_worker_excerpt').hide();";
  143.     $script .= "$('#app_worker_excerpt_'+selected_worker).show();";
  144.     if ( $autorefresh ) {
  145.       $script .= "var redirection_url='" . $href . " + (!!parseInt(selected_worker, 10) ? '#app_worker_excerpt_'+selected_worker : '');";
  146.       $script .= "window.location.href=redirection_url;";
  147.     }
  148.     $script .= "});";
  149.  
  150.     $script .= "$('.app_workers_button').click(function(){";
  151.     $script .= "var selected_worker=$('.app_select_workers option:selected').val();";
  152.     $script .= "var redirection_url='" . $href . " + (!!parseInt(selected_worker, 10) ? '#app_worker_excerpt_'+selected_worker : '');";
  153.     $script .= "window.location.href=redirection_url;";
  154.     $script .= "});";
  155.  
  156.     if (!$_noscript) $appointments->add2footer( $script );
  157.  
  158.     return $s;
  159.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement