示例#1
0
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args     Widget arguments.
  * @param array $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     global $jobifyAPIs;
     // Get the jobs
     $rand = time();
     $job_options = jobify_job_args($instance);
     $jobs = jobify_get_jobs($job_options);
     $openContainer = jobify_open_container($job_options, $rand);
     echo $args['before_widget'];
     if (!empty($instance['title'])) {
         echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
     }
     if (count($jobs) > 0) {
         // Add the tracking script
         wp_enqueue_script('jobify-tracker');
         echo $openContainer;
         shuffle($jobs);
         $cnt = 0;
         foreach ($jobs as $key => $ary) {
             $cnt++;
             if (!empty($instance['limit']) && $cnt > $instance['limit']) {
                 break;
             }
             if (!empty($ary['error'])) {
                 echo '<p>' . $ary['error'] . '</p>';
             } else {
                 echo jobify_job_result($instance['template'], $ary);
             }
         }
         echo '</div>';
     } else {
         echo $openContainer;
         echo '<p>' . __('No jobs available at this time.', 'jobify') . '</p>';
         echo '</div>';
     }
     if ($instance['powered_by']) {
         ?>
   <div class="jobify__powered-by">
     <?php 
         jobify_powered_by();
         ?>
   </div>
   <?php 
     }
     if (!empty($instance['portals']) && is_array($instance['portals'])) {
         if (in_array('indeed', $instance['portals'])) {
             jobify_indeed_attribution();
         }
     }
     // Check if geolocation is enabled
     if ($instance['geolocation']) {
         wp_enqueue_script('jobify-geolocation');
         echo '<div id="jobify-' . $rand . '" style="display: none !important;">' . $instance['template'] . '</div>';
     }
     echo $args['after_widget'];
 }
示例#2
0
 public function jobify($atts, $content = null)
 {
     if (!empty($atts['portals'])) {
         $atts['portals'] = explode(',', $atts['portals']);
     }
     $rand = time();
     $job_options = jobify_job_args($atts);
     $jobs = jobify_get_jobs($job_options);
     $openContainer = jobify_open_container($job_options, $rand);
     if (empty($content)) {
         $content = $this->default_settings['template'];
     }
     ob_start();
     if (count($jobs) > 0) {
         // Add the tracking script
         wp_enqueue_script('jobify-tracker');
         echo $openContainer;
         shuffle($jobs);
         $cnt = 0;
         foreach ($jobs as $key => $ary) {
             $cnt++;
             if (!empty($job_options['limit']) && $cnt > $job_options['limit']) {
                 break;
             }
             if (!empty($ary['error'])) {
                 echo '<p>' . $ary['error'] . '</p>';
             } else {
                 echo jobify_job_result(html_entity_decode($content), $ary);
             }
         }
         echo '</div>';
         if ($job_options['powered_by']) {
             ?>
   <div class="jobify__powered-by">
     <?php 
             jobify_powered_by();
             ?>
   </div>
   <?php 
         }
         if (in_array('indeed', $job_options['portals'])) {
             jobify_indeed_attribution();
         }
         // Check if geolocation is enabled
         if ($job_options['geolocation']) {
             wp_enqueue_script('jobify-geolocation');
             echo '<div id="jobify-' . $rand . '" style="display: none !important;">' . $content . '</div>';
         }
     }
     return ob_get_clean();
 }