Advertisement
Guest User

Untitled

a guest
Jan 26th, 2012
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.92 KB | None | 0 0
  1.  
  2.  /** COMIENZO BUSCADOR REGION */
  3.  
  4. class JobmanRegionWidget extends WP_Widget {
  5.     /** constructor */
  6.     function JobmanRegionWidget() {
  7.         $name = __( 'Job Manager: Categories', 'jobman');
  8.         $options = array( 'description' => __( 'A list or dropdown of Job Manager categories', 'jobman' ) );
  9.        
  10.         parent::WP_Widget( false, $name, $options );   
  11.     }
  12.  
  13.     function widget( $args, $instance ) {
  14.         global $wp_query;
  15.        
  16.         extract( $args );
  17.         $title = apply_filters( 'widget_title', $instance['title'] );
  18.        
  19.         echo $before_widget;
  20.        
  21.         if ( $title )
  22.             echo $before_title . $title . $after_title;
  23.            
  24.         $dropdown = 0;
  25.         if( array_key_exists( 'dropdown', $instance ) )
  26.             $dropdown = $instance['dropdown'];
  27.        
  28.         $show_counts = 0;
  29.         if( array_key_exists( 'show_counts', $instance ) )
  30.             $show_counts = $instance['show_counts'];
  31.  
  32.         $hide_empty = 0;
  33.         if( array_key_exists( 'hide_empty', $instance ) )
  34.             $hide_empty = $instance['hide_empty'];
  35.  
  36.         $categories = get_terms( 'jobman_category', 'hide_empty=0' );
  37.         if( count( $categories ) > 0 ) {
  38.             if( $dropdown ) {
  39.                 echo '<select id="jobman-catlist">';
  40.                 echo '<option value="">' . __( 'Busqueda por Region', 'jobman' ) . '</option>';
  41.             }
  42.             else {
  43.                 echo '<ul>';
  44.             }
  45.            
  46.             $count_args = array(
  47.                             'post_type' => 'jobman_job',
  48.                             'numberposts' => -1,
  49.                             'suppress_filters' => false
  50.                         );
  51.  
  52.             foreach( $categories as $cat ) {
  53.                 $selected = '';
  54.                 if( array_key_exists( 'jcat', $wp_query->query_vars ) && $wp_query->query_vars['jcat'] == $cat->slug )
  55.                     $selected = ' selected="selected"';
  56.                
  57.                 $jobs = array();
  58.                 if( $hide_empty || $show_counts ) {
  59.                     $count_args['jcat'] = $cat->slug;
  60.                     add_filter( 'posts_where', 'jobman_job_live_where' );
  61.                     add_filter( 'posts_join', 'jobman_job_live_join' );
  62.                     add_filter( 'posts_distinct', 'jobman_job_live_distinct' );
  63.                    
  64.                     $jobs = get_posts( $count_args );
  65.                    
  66.                     remove_filter( 'posts_where', 'jobman_job_live_where' );
  67.                     remove_filter( 'posts_join', 'jobman_job_live_join' );
  68.                     remove_filter( 'posts_distinct', 'jobman_job_live_distinct' );
  69.                 }
  70.                
  71.                 if( $hide_empty && empty( $jobs ) )
  72.                     continue;
  73.                
  74.                 $count = '';
  75.                 if( $show_counts ) {
  76.                     $count = ' (' . count( $jobs ) . ')';
  77.                 }
  78.                
  79.                 if( $dropdown )
  80.                     echo "<option value='$cat->slug'$selected>$cat->name$count</option>";
  81.                 else
  82.                     echo "<li><a href='" . get_term_link( $cat->slug, 'jobman_category' ) . "'>$cat->name$count</a></li>";
  83.             }
  84.  
  85.             if( $dropdown ) {
  86. ?>
  87.         </select>
  88.        
  89. <script type='text/javascript'>
  90. /* <![CDATA[ */
  91.     var jobman_dropdown = document.getElementById("jobman-catlist");
  92.     function onJobmanCatChange() {
  93.         if ( jobman_dropdown.options[jobman_dropdown.selectedIndex].value != '' ) {
  94.             location.href = "<?php echo get_option( 'home' ) ?>/?jcat="+jobman_dropdown.options[jobman_dropdown.selectedIndex].value;
  95.         }
  96.     }
  97.     jobman_dropdown.onchange = onJobmanCatChange;
  98. /* ]]> */
  99. </script>
  100. <?php
  101.             }
  102.             else {
  103.                 echo '</ul>';
  104.             }
  105.         }
  106.         else {
  107.             echo '<p>' . __( 'There are no categories to display at this time.', 'jobman' ) . '</p>';
  108.         }
  109.                    
  110.         echo $after_widget;
  111.     }
  112.  
  113.     function update( $new_instance, $old_instance ) {
  114.         return $new_instance;
  115.     }
  116.  
  117.     function form( $instance ) {
  118.         $title = '';
  119.         if( array_key_exists( 'title', $instance ) )
  120.             $title = esc_attr( $instance['title'] );
  121. ?>
  122.             <p>
  123.                 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'jobman' ); ?>:
  124.                     <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
  125.                 </label>
  126.             </p>
  127. <?php
  128.         $dropdown = 0;
  129.         if( array_key_exists( 'dropdown', $instance ) )
  130.             $dropdown = $instance['dropdown'];
  131.        
  132.         $show_counts = 0;
  133.         if( array_key_exists( 'show_counts', $instance ) )
  134.             $show_counts = $instance['show_counts'];
  135.  
  136.         $hide_empty = 0;
  137.         if( array_key_exists( 'hide_empty', $instance ) )
  138.             $hide_empty = $instance['hide_empty'];
  139. ?>
  140.             <p>
  141.                 <input id="<?php echo $this->get_field_id( 'dropdown' ); ?>" name="<?php echo $this->get_field_name( 'dropdown' ); ?>" type="checkbox" value="1" <?php echo ( $dropdown )?( 'checked="checked" ' ):( '' )?>/> <?php _e( 'Show as dropdown', 'jobman' ) ?><br/>
  142.                 <input id="<?php echo $this->get_field_id( 'show_counts' ); ?>" name="<?php echo $this->get_field_name( 'show_counts' ); ?>" type="checkbox" value="1" <?php echo ( $show_counts )?( 'checked="checked" ' ):( '' )?>/> <?php _e( 'Show job counts', 'jobman' ); ?><br/>
  143.                 <input id="<?php echo $this->get_field_id( 'hide_empty' ); ?>" name="<?php echo $this->get_field_name( 'hide_empty' ); ?>" type="checkbox" value="1" <?php echo ( $hide_empty )?( 'checked="checked" ' ):( '' )?>/> <?php _e( 'Hide empty categories', 'jobman' ); ?>
  144.             </p>
  145. <?php
  146.     }
  147.  
  148. }
  149.  /** FIN REGION */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement