コード例 #1
0
ファイル: Scripts.php プロジェクト: bmarshall511/jobify
 public function run()
 {
     add_action('wp_enqueue_scripts', function () {
         wp_register_script('jobify-indeed', 'https://gdc.indeed.com/ads/apiresults.js', array(), false, false);
         wp_register_script('jobify-geolocation', plugin_dir_url(JOBIFY_PLUGIN) . 'js' . DIRECTORY_SEPARATOR . 'geolocation.js', array('jquery'), '1.1.0', false);
         wp_register_script('jobify-tracker', plugin_dir_url(JOBIFY_PLUGIN) . 'js' . DIRECTORY_SEPARATOR . 'tracker.js', array('jquery'), '1.3.3', false);
         wp_localize_script('jobify-geolocation', 'Jobify', array('ajaxurl' => admin_url('admin-ajax.php'), 'security' => wp_create_nonce('jobify')));
     });
     add_action('wp_ajax_jobify_get_jobs', function () {
         check_ajax_referer('jobify', 'security');
         // Get the jobs
         $job_options = jobify_job_args($_POST['params']);
         // Location
         if (!empty($_POST['params']['lat']) && !empty($_POST['params']['lng'])) {
             $job_options['lat'] = $_POST['params']['lat'];
             $job_options['lng'] = $_POST['params']['lng'];
         } elseif (!empty($_POST['params']['location'])) {
             $job_options['location'] = $args['location'];
         }
         $jobs = jobify_get_jobs($job_options);
         if (count($jobs) > 0) {
             shuffle($jobs);
             $jobs = array_slice($jobs, 0, $job_options['limit']);
         }
         echo json_encode($jobs);
         die;
     });
 }
コード例 #2
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'];
 }
コード例 #3
0
ファイル: Shortcodes.php プロジェクト: bmarshall511/jobify
 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();
 }