/**
  * @wp_hook admin_enqueue_scripts
  * @return mixed|void
  */
 public function admin_enqueue_scripts()
 {
     global $wp_scripts;
     $aField = $this->getFieldData();
     $data = array('no_image' => $this->get_property('no_image'));
     //form action
     //if($this->get_property('internal_form_action')) {
     $this->config = array('action_url' => $this->get_property('upload'), 'action_path' => $this->get_property('upload_file'), 'uploads_folder' => $this->get_property('uploads_path'), 'uploads_url' => $this->get_property('uploads_directory_uri'), 'image_type' => $this->get_property('image_type'), 'random_filename' => $this->get_property('random_filename'), 'allow_types' => $this->get_property('allow_types'), 'maxsize' => $this->get_property('maxsize'), 'redirect' => $this->get_property('redirect'), 'success_callback_js' => $this->get_property('success_callback_js'), 'error_callback_js' => $this->get_property('error_callback_js'));
     //}
     //else $data['upload_handle'] = $this->get_property('upload');
     $id = md5($this->get_field_name());
     $data[$id] = $this->config;
     $handle = $this->enqueue_script('assets/upload.js', array('jquery'), 'hw-apf-field-upload');
     if ($handle) {
         self::$script_handle = $handle;
         $wp_scripts->add_data($handle, $id, $data[$id]);
     }
     if (!$handle) {
         //$wp_scripts->add_data(self::$script_handle, $id, $data[$id] );  //echo '<textarea>';print_r($wp_scripts);echo '</textarea>';
         $this->add_data(self::$script_handle, '__hw_apf_field_upload', $id, $data[$id]);
     } elseif ($handle) {
         $this->localize_script($handle, '__hw_apf_field_upload', $data);
     }
     $this->enqueue_style('assets/style.css');
     //jquery form lib
     HW_Libraries::enqueue_jquery_libs('jquery-libs/form');
 }
Esempio n. 2
0
 /**
  * fields values validation
  * @param $values
  * @return mixed|void
  */
 public function validation_tab_filter($values)
 {
     //var_dump($values);
     //var_dump($this->create_field_name('upload'));
     APF_hw_upload_field::do_form_action($values, $this->create_field_name('upload'));
     //return array(); //not save any fields value
     exit;
     //the way allow ajax upload work, no any output allow here, if you not specific upload handle
     //return $values;   //allow to save fields value
 }
 /**
  * fields values validation
  * @param $values
  * @return mixed|void
  */
 public function validation_tab_filter($values)
 {
     //var_dump($values);
     //var_dump($this->create_field_name('upload'));
     APF_hw_upload_field::do_form_action($values, $this->create_field_name('uploader'));
     //return array(); //not save any fields value
     //exit(); //the way allow ajax upload work, no any output allow here, if you not specific upload handle
     if (hw__post('s')) {
         $_REQUEST['s'] = hw__post('s');
         HW_SESSION::save_session('search_module', hw__post('s'));
     }
     return $values;
     //allow to save fields value
 }
Esempio n. 4
0
HW_APF_FieldTypes::load_fieldtype('APF_hw_upload_field');

//valid data
//APF_hw_upload_field::config();
//APF_hw_upload_field::valid_form_data();
*/
HW_HOANGWEB::load_class('HW_Ajax');
//check if this is an ajax request
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
    die;
}
$target_dir = !empty($config->uploads_folder) ? rtrim($config->uploads_folder, '/') . '/' : dirname(__FILE__) . "/uploads/";
$ajax = HW_Ajax::create();
//upload multiple files
for ($i = 0; $i < APF_hw_upload_field::get_files_num(); $i++) {
    //validation
    if (!isset($_FILES['file-' . $i])) {
        break;
    }
    $file = $_FILES['file-' . $i];
    $File_Name = strtolower($file['name']);
    $File_Ext = substr($File_Name, strrpos($File_Name, '.'));
    //get file extention
    if ($config->random_filename) {
        $Random_Number = rand(0, 9999999999);
        //Random number to be added to name.
        $target_file = $target_dir . $Random_Number . $File_Ext;
        //new file name
        $filename = $Random_Number . $File_Ext;
    } else {