*/ class Applyonline_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; add_action( 'init', array( $this, 'register_aol_post_types' ) ); add_shortcode( 'aol_ads', array($this, 'shortcode_generator') ); // Hook - Applicant Listing - Column Name add_filter( 'manage_edit-aol_application_columns', array ( $this, 'applicants_list_columns' ) ); // Hook - Applicant Listing - Column Value add_action( 'manage_aol_application_posts_custom_column', array ( $this, 'applicants_list_columns_value' ), 10, 2 ); add_filter('post_row_actions',array($this, 'application_row_actions'), 10, 2); // Add Application data to the Application editor. add_action ( 'edit_form_after_title', array ( $this, 'aol_application_post_editor' ) ); new MetaBoxes(); new AjaxHandler(); } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Applyonline_Loader as all of the hooks are defined * in that particular class. * * The Applyonline_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/applyonline-admin.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Applyonline_Loader as all of the hooks are defined * in that particular class. * * The Applyonline_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/applyonline-admin.js', array( 'jquery' ), $this->version, false ); } function register_aol_post_types(){ /*Register Main Post Type*/ $labels=array( 'add_new' => 'Create an Ad', 'add_new_item' => 'New Ad', 'edit_item' => 'Edit Ad', 'all_items' => 'All Ads', 'menu_name' => 'Apply Online' ); $args=array( 'label' => __( 'All Ads', 'applyonline' ), 'labels'=> $labels, 'public'=> true, 'show_in_nav_menus' => false, 'menu_icon' => 'dashicons-admin-site', 'description' => __( 'Ad Posting' ), 'supports' => array('title', 'editor'), 'rewrite' => array('slug'=>'ads'), ); register_post_type('aol_ad',$args); // Add new taxonomy, make it hierarchical (like categories) $labels = array( 'name' => _x( 'Ad Categories', 'taxonomy singular name', 'applyOnline' ), 'singular_name' => _x( 'Ad Category','taxonomy singular name', 'applyOnline' ), 'search_items' => __( 'Search Categories' ), 'all_items' => __( 'All Categories' ), 'parent_item' => __( 'Parent Category' ), 'parent_item_colon' => __( 'Parent Category:' ), 'edit_item' => __( 'Edit Category' ), 'update_item' => __( 'Update Category' ), 'add_new_item' => __( 'Add New Category' ), 'new_item_name' => __( 'New Category Name' ), ); $args = array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'adcat' ), ); register_taxonomy( 'aol_ad_category', array( 'aol_ad' ), $args ); /*Register Applications Post Type*/ $lables= array( 'edit_item'=>'Application' ); $args=array( 'label' => __( 'Applications', 'applyonline' ), 'labels' => $lables, 'public' => true, 'show_in_nav_menus' => false, 'exclude_from_search'=> true, 'publicly_queryable' => false, 'map_meta_cap' => true, 'show_in_menu' => 'edit.php?post_type=aol_ad', 'description' => __( 'List of Applications with their resume', 'applyonline' ), 'supports' => array('editor'), 'capabilities' => array( 'create_posts' => false, ) ); register_post_type('aol_application',$args); } /** * Shortcode Generator * @param type $atts * @return type */ function shortcode_generator( $atts ) { $a = shortcode_atts( array( 'ads' => '-1', 'excerpt' => 'yes', ), $atts ); $args=array( 'posts_per_page' => $a['ads'], 'post_type' =>'aol_ad', ); query_posts( $args ); function custom_excerpt_more( $more ) { return '....'; } add_filter( 'excerpt_more', 'custom_excerpt_more' ); ob_start(); echo '
    '; if(have_posts()): while(have_posts()): the_post(); ?>
  1. Job Detail
  2. '; $html=ob_get_clean(); wp_reset_query(); return $html; } /** * Applicant Listing - Column Name * * @param array $columns * @access public * @return array */ public function applicants_list_columns( $columns ){ $columns = array ( 'cb' => '', 'title' => __( 'Ad Title', 'applyonline' ), 'applicant'=> __( 'Applicant', 'applyonline' ), 'taxonomy' => __( 'Categories', 'applyonline' ), 'date' => __( 'Date', 'applyonline' ), ); return $columns; } /** * Applicant Listing - Column Value * * @param array $columns * @param int $post_id * @access public * @return void */ // public function applicants_list_columns_value( $column, $post_id ){ $keys = get_post_custom_keys( $post_id ); switch ( $column ) { case 'applicant' : $applicant_name = sprintf( '%s', esc_url( add_query_arg( array ( 'post' => $post_id, 'action' => 'edit' ), 'post.php' ) ), esc_html( get_post_meta( $post_id, $keys[ 0 ], TRUE ) ) ); echo $applicant_name; break; case 'taxonomy' : $parent_id = wp_get_post_parent_id( $post_id ); // get_post_field ( 'post_parent', $post_id ); $terms = get_the_terms( $parent_id, 'aol_ad_category' ); if ( ! empty( $terms ) ) { $out = array (); foreach ( $terms as $term ) { $out[] = sprintf( '%s', esc_url( add_query_arg( array ( 'post_type' => get_post_type( $parent_id ), 'aol_ad_category' => $term->slug ), 'edit.php' ) ), esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'jobpost_category', 'display' ) ) ); } echo join( ', ', $out ); }/* If no terms were found, output a default message. */ else { _e( 'No Categories' , 'applyonline'); } break; } } public function application_row_actions($actions, $post){ if($post->post_type == 'aol_application'){ return null; } else{ return $actions; } } /** * Creates Detail Page for Applicants * * * @access public * @since 1.0.0 * @return void */ public function aol_application_post_editor () { global $post; if ( !empty ( $post ) and $post->post_type =='aol_application' ): $keys = get_post_custom_keys ( $post->ID ); ?>

    ID, '_aol_app_Name', true ); endif; if ( in_array ( 'resume', $keys ) ): ?>    

    '; } endforeach; ?>
    ' . str_replace ( '_', ' ', substr ( $key, 9 ) ) . '' . get_post_meta ( $post->ID, $key, true ) . '

      ID); if($keys != NULL): foreach($keys as $key): if(substr($key, 0, 13)=='_aol_feature_'){ $val=get_post_meta($post->ID, $key, TRUE); echo '
    1. '; echo '  
      Delete
    2. '; } endforeach; endif; ?>
    Add Feature
      'Text Field', 'text_area'=>'Text Area', 'date'=>'Date', 'checkbox'=>'Check Box', 'dropdown'=>'Drop Down', 'radio'=> 'Radio'); $keys=get_post_custom_keys( $post->ID); if($keys != NULL): foreach($keys as $key): if(substr($key, 0, 9)=='_aol_app_'): $val=get_post_meta($post->ID, $key, TRUE); $val= unserialize($val); $fields = NULL; foreach($field_types as $field_key => $field_val){ if($val['type']==$field_key) $fields .= ''; else $fields .= ''; } //if($key.'[type]'=='text'){ echo '
    1. '; if(!($val['type']=='text' or $val['type']=='date' or $val['type']=='text_area' )): echo ''; else: echo ''; endif; echo '  
      Delete
    2. '; //} endif; endforeach; endif; ?>
    Add Field
    $val): if(substr($val, 0, 3) == '_ad') delete_post_meta($post_id, $val); //Remove meta from the db. endforeach; // Add new value. foreach ($_POST as $key => $val): // Make sure that it is set. if ( substr($key, 0, 13)=='_aol_feature_' and isset( $val ) ) { // Sanitize user input. $my_data = sanitize_text_field( $val ); update_post_meta( $post_id, $key, $my_data); // Add new value. } // Make sure that it is set. elseif ( substr($key, 0, 9)=='_aol_app_' and isset( $val ) ) { $my_data = serialize($_POST[$key]); update_post_meta( $post_id, $key, $my_data); // Add new value. } // Update the meta field in the database. endforeach; } } /** * This class is responsible to hanld Ajax data. * * * @since 1.0 * @package AjaxHandler * @author Farhan Noor **/ class AjaxHandler{ public function __construct() { add_action( 'wp_ajax_aol_app_form', array($this, 'aol_process_app_form') ); add_action( 'wp_ajax_nopriv_aol_app_form', array($this, 'aol_process_app_form') ); } public function aol_process_app_form(){ $nonce=$_POST['wp_nonce']; if(!wp_verify_nonce($nonce, 'the_best_aol_ad_security_nonce')) die('Not Working'); /*Initialixing Variables*/ $error = null; $error_assignment = null; if (strlen($_FILES['applicant_resume']['name']) > 3) { $uploadfiles = $_FILES['applicant_resume']; if (is_array($uploadfiles)) { $upload_dir = wp_upload_dir(); $assignment_upload_size = 200; $time = (!empty($_SERVER['REQUEST_TIME'])) ? $_SERVER['REQUEST_TIME'] : (time() + (get_option('gmt_offset') * 3600)); // Fallback of now $post_type = 'aol_ad'; $date = explode(" ", date('Y m d H i s', $time)); $timestamp = strtotime(date('Y m d H i s')); if($post_type) { $upload_dir = array( 'path' => WP_CONTENT_DIR . '/uploads/' . $post_type . '/' . $date[0], 'url' => WP_CONTENT_URL . '/uploads/' . $post_type . '/' . $date[0], 'subdir' => '', 'basedir' => WP_CONTENT_DIR . '/uploads', 'baseurl' => WP_CONTENT_URL . '/uploads', 'error' => false, ); } if(!is_dir($upload_dir['path'])){ wp_mkdir_p($upload_dir['path']); } $var_cp_assigment_type= 'jpg, jpeg, png, doc, docx, pdf, rtf, odt, txt'; $uploadfiles = array( 'name' => $_FILES['applicant_resume']['name'], 'type' => $_FILES['applicant_resume']['type'], 'tmp_name' => $_FILES['applicant_resume']['tmp_name'], 'error' => $_FILES['applicant_resume']['error'], 'size' => $_FILES['applicant_resume']['size'] ); // look only for uploded files if ($uploadfiles['error'] == 0) { $filetmp = $uploadfiles['tmp_name']; $filename = $uploadfiles['name']; $filesize = $uploadfiles['size']; $max_upload_size = $assignment_upload_size*1048576; //Multiply by KBs if($max_upload_size<$filesize){ $assignment_error[] = 'Maximum upload File size allowed '.$assignment_upload_size.'MB'; $error_assignment = 1; } $file_type_match = 0; $var_cp_assigment_type_array = array(); if($var_cp_assigment_type){ $var_cp_assigment_type_array = explode(', ',$var_cp_assigment_type); } if(in_array($uploadfiles['type'], $var_cp_assigment_type_array)){ $file_type_match = 1; } /** * Check File Size */ if($file_type_match == 0){ $assignment_error[] = 'Please upload file with on of extenstions: '.$var_cp_assigment_type; $error_assignment = 1; } // get file info // @fixme: wp checks the file extension.... $filetype = wp_check_filetype( basename( $filename ), null ); $filetitle = preg_replace('/\.[^.]+$/', '', basename( $filename ) ); $filename = $filetitle . $timestamp . '.' . $filetype['ext']; /** * Check if the filename already exist in the directory and rename the * file if necessary */ $i = 0; while ( file_exists( $upload_dir['path'] .'/' . $filename ) ) { $filename = $filetitle . $timestamp . '_' . $i . '.' . $filetype['ext']; $i++; } $filedest = $upload_dir['path'] . '/' . $filename; /** * Check write permissions */ if ( !is_writeable( $upload_dir['path'] ) ) { $assignment_error[] = 'Unable to write to directory %s. Is this directory writable by the server?'; $error_assignment = 1; } /** * Save temporary file to uploads dir */ if($error_assignment <> 1){ if ( !@move_uploaded_file($filetmp, $filedest) ){ $assignment_error[] = 'Error, the file $filetmp could not moved to : $filedest'; $error_assignment = 1; } $newupload = $upload_dir['url'].'/'.$filename; $uploadpath = $upload_dir['path'].'/'.$filename; } } } } if($error_assignment == 1){ $errors = NULL; foreach($assignment_error as $error_value){ $errors .= '

    '.esc_html__($error_value, 'EDULMS').'

    '; } $response = json_encode( array( 'success' => false, 'error' => $errors )); // generate the response. // response output header( "Content-Type: application/json" ); echo $response; exit; } else{ $args= array( 'post_type' =>'aol_application', 'post_content' =>'', 'post_parent' =>$_POST['ad_id'], 'post_title' =>get_the_title($_POST['ad_id']), 'post_status' =>'publish', ); $pid=wp_insert_post($args); foreach($_POST as $key => $val): if(substr($key,0,9) == '_aol_app_') add_post_meta($pid, $key, $val); if(!empty($newupload)) add_post_meta($pid, 'resume', $newupload); endforeach; if($pid>0) $response = json_encode( array( 'success' => true )); // generate the response. else $response = json_encode( array( 'success' => false )); // generate the response. if($error) $response = json_encode( array( 'success' => false, 'error' => $error )); // generate the response with error message. // response output header( "Content-Type: application/json" ); echo $response; exit; } } }