/**
  * update branding : logo, mobile icon
  */
 function upload_image()
 {
     global $user_ID;
     $res = array('success' => false, 'msg' => __('There is an error occurred', 'aecore-class-ae-page-backend'), 'code' => 400);
     /**
      * User must login to upload image
      */
     if (!$user_ID) {
         $res['msg'] = __("You must login to upload image.", 'aecore-class-ae-page-backend');
         wp_send_json($res);
     }
     // check fileID
     if (!isset($_POST['fileID']) || empty($_POST['fileID']) || !isset($_POST['imgType']) || empty($_POST['imgType'])) {
         $res['msg'] = __('Missing image ID', 'aecore-class-ae-page-backend');
     } else {
         $fileID = $_POST["fileID"];
         $imgType = $_POST['imgType'];
         // check ajax nonce
         if (!de_check_ajax_referer($imgType . '_et_uploader', false, false) && !check_ajax_referer($imgType . '_et_uploader', false, false)) {
             $res['msg'] = __('Security error!', 'aecore-class-ae-page-backend');
         } elseif (isset($_FILES[$fileID])) {
             //
             $upload_mimes = apply_filters('et_upload_file_upload_mimes', array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff', 'doc|docx' => 'application/msword', 'ppt' => 'application/vnd.ms-powerpoint', 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation'));
             // handle file upload
             $attach_id = et_process_file_upload($_FILES[$fileID], 0, 0, $upload_mimes);
             if (!is_wp_error($attach_id)) {
                 try {
                     $attach_data = et_get_attachment_data($attach_id);
                     $options = AE_Options::get_instance();
                     // save this setting to theme options
                     // $options->$imgType = $attach_data;
                     // $options->save();
                     /** 
                      * do action to control how to store data
                      * @param $attach_data the array of image data
                      * @param $request['data']
                      * @param $attach_id the uploaded file id
                      */
                     do_action('ae_upload_image', $attach_data, $_POST['data'], $attach_id);
                     $res = array('success' => true, 'msg' => __('Branding image has been uploaded successfully', 'aecore-class-ae-page-backend'), 'data' => $attach_data);
                 } catch (Exception $e) {
                     $res['msg'] = __('Error when updating settings.', 'aecore-class-ae-page-backend');
                 }
             } else {
                 $res['msg'] = $attach_id->get_error_message();
             }
         } else {
             $res['msg'] = __('Uploaded file not found', 'aecore-class-ae-page-backend');
         }
     }
     // send json to client
     wp_send_json($res);
 }
示例#2
0
 public function change_logo()
 {
     $res = array('success' => false, 'msg' => __('There is an error occurred', ET_DOMAIN), 'code' => 400);
     // check fileID
     if (!isset($_POST['fileID']) || empty($_POST['fileID'])) {
         $res['msg'] = __('Missing image ID', ET_DOMAIN);
     } else {
         $fileID = $_POST["fileID"];
         // check author
         if (!isset($_POST['author']) || empty($_POST['author']) || !is_numeric($_POST['author'])) {
             $res['msg'] = __('Missing user data', ET_DOMAIN);
         } else {
             $author = $_POST['author'];
             // check ajax nonce
             if (!check_ajax_referer('user_avatar_et_uploader', '_ajax_nonce', false)) {
                 $res['msg'] = __('Security error!', ET_DOMAIN);
             } elseif (isset($_FILES[$fileID])) {
                 // handle file upload
                 $attach_id = et_process_file_upload($_FILES[$fileID], $author, 0, array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff'));
                 if (!is_wp_error($attach_id)) {
                     // Update the author meta with this logo
                     try {
                         $user_avatar = et_get_attachment_data($attach_id);
                         /**
                          * get old logo and delete it
                          */
                         $old_logo = get_user_meta($author, 'et_avatar', true);
                         if (isset($old_logo['attach_id'])) {
                             $old_logo_id = $old_logo['attach_id'];
                             wp_delete_attachment($old_logo_id, true);
                         }
                         /**
                          * update new user logo
                          */
                         QA_Member::update(array('ID' => $author, 'et_avatar' => $user_avatar));
                         $res = array('success' => true, 'msg' => __('User logo has been uploaded successfully!', ET_DOMAIN), 'data' => $user_avatar);
                     } catch (Exception $e) {
                         $res['msg'] = __('Problem occurred while updating user field', ET_DOMAIN);
                     }
                 } else {
                     $res['msg'] = $attach_id->get_error_message();
                 }
             } else {
                 $res['msg'] = __('Uploaded file not found', ET_DOMAIN);
             }
         }
     }
     return $res;
 }
示例#3
0
function fre_upload_file()
{
    $res = array('success' => false, 'msg' => __('There is an error occurred', 'theme-backend'), 'code' => 400);
    // check fileID
    if (!isset($_POST['fileID']) || empty($_POST['fileID'])) {
        $res['msg'] = __('Missing image ID', 'theme-backend');
    } else {
        $fileID = $_POST["fileID"];
        $imgType = $_POST['imgType'];
        // check ajax nonce
        if (!de_check_ajax_referer('file_et_uploader', false, false) && !check_ajax_referer('file_et_uploader', false, false)) {
            $res['msg'] = __('Security error!', 'theme-backend');
        } elseif (isset($_FILES[$fileID])) {
            // handle file upload
            $attach_id = et_process_file_upload($_FILES[$fileID], 0, 0, array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff', 'pdf' => 'application/pdf', 'doc|docx' => 'application/msword', 'odt' => 'application/vnd.oasis.opendocument.text', 'zip' => 'application/zip', 'rar' => 'application/rar'));
            if (!is_wp_error($attach_id)) {
                try {
                    $attach_data = et_get_attachment_data($attach_id);
                    $options = AE_Options::get_instance();
                    // save this setting to theme options
                    // $options->$imgType = $attach_data;
                    // $options->save();
                    /** 
                     * do action to control how to store data
                     * @param $attach_data the array of image data
                     * @param $request['data']
                     * @param $attach_id the uploaded file id
                     */
                    //do_action('ae_upload_image' , $attach_data , $_POST['data'], $attach_id );
                    $res = array('success' => true, 'msg' => __('File has been uploaded successfully', 'theme-backend'), 'data' => $attach_data);
                } catch (Exception $e) {
                    $res['msg'] = __('Error when updating settings.', 'theme-backend');
                }
            } else {
                $res['msg'] = $attach_id->get_error_message();
            }
        } else {
            $res['msg'] = __('Uploaded file not found', 'theme-backend');
        }
    }
    // send json to client
    wp_send_json($res);
}
示例#4
0
 function mobile_upload()
 {
     global $user_ID;
     $resp = array('success' => false, 'msg' => __('Upload file fail!', ET_DOMAIN), 'data' => '');
     if (!isset($_GET['resume_id']) || !is_numeric($_GET['resume_id'])) {
         $post = get_posts(array('post_type' => 'resume', 'author' => $user_ID, 'post_status' => 'any', 'posts_per_page' => 1));
         $_GET['resume_id'] = $post[0]->ID;
     }
     $this->check_permission_upload($_GET);
     if (isset($_FILES["file"]["error"]) && $_FILES["file"]["error"] > 0) {
         wp_send_json(array('success' => false, 'msg' => __('File size is too large!')));
     } else {
         // for signup new resume
         $this->check_limit_files($_GET);
         $arg_type = $this->get_file_type_accept($_GET['field_type']);
         $_FILES['files']['name'] = $_FILES['files']['name'][0];
         $_FILES['files']['type'] = $_FILES['files']['type'][0];
         $_FILES['files']['tmp_name'] = $_FILES['files']['tmp_name'][0];
         $_FILES['files']['size'] = $_FILES['files']['size'][0];
         $_FILES['files']['error'] = $_FILES['files']['error'][0];
         $attach_id = et_process_file_upload($_FILES['files'], $author = 0, $_GET['resume_id'], $arg_type);
         if (!is_wp_error($attach_id)) {
             update_post_meta($attach_id, $_GET['field_name'], 1);
             $resp['success'] = true;
             $resp['id'] = $attach_id;
             $resp['temp'] = isset($_GET['field_type']) ? $_GET['field_type'] : 'file';
             $resp['name'] = basename(wp_get_attachment_url($attach_id));
             $resp['url'] = wp_get_attachment_url($attach_id);
             $args_att = et_get_attachment_data($attach_id);
             $args_att['name'] = $resp['name'];
             $resp['files'][] = $args_att;
             $resp['msg'] = __('Upload file has successfully!', ET_DOMAIN);
         } else {
             // Size of file  upload > limit size.
             $resp['msg'] = $attach_id->get_error_message();
         }
     }
     wp_send_json($resp);
 }
示例#5
0
 function et_attachment_upload()
 {
     header('HTTP/1.0 200 OK');
     header('Content-type: text/html');
     //header( "Content-Type: application/json" );
     $res = array('success' => false, 'msg' => __('There is an error occurred', ET_DOMAIN), 'code' => 400);
     // check fileID
     if (!isset($_POST['fileID']) || empty($_POST['fileID'])) {
         $res['msg'] = __('Missing image ID', ET_DOMAIN);
     } else {
         $fileID = $_POST["fileID"];
         $author = 1;
         // check ajax nonce
         if (!check_ajax_referer('slider_thumb_et_uploader', '_ajax_nonce', false)) {
             $res['msg'] = __('Security error!', ET_DOMAIN);
         } elseif (isset($_FILES[$fileID])) {
             // handle file upload
             $attach_id = et_process_file_upload($_FILES[$fileID], $author, 0, array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff'));
             if (!is_wp_error($attach_id)) {
                 // Update the author meta with this logo
                 try {
                     $attach_img = et_get_attachment_data($attach_id);
                     $res = array('success' => true, 'msg' => __('Company logo has been uploaded successfully!', ET_DOMAIN), 'data' => $attach_img);
                 } catch (Exception $e) {
                     $res['msg'] = __('Problem occurred while updating user field', ET_DOMAIN);
                 }
             } else {
                 $res['msg'] = $attach_id->get_error_message();
             }
         } else {
             $res['msg'] = __('Uploaded file not found', ET_DOMAIN);
         }
     }
     echo json_encode($res);
     exit;
 }
示例#6
0
 /**
  * Upload Images via TinyMCE
  */
 public function upload_images()
 {
     try {
         if (!check_ajax_referer('et_upload_images', '_ajax_nonce', false)) {
             throw new Exception(__('Security error!', ET_DOMAIN));
         }
         // check fileID
         if (!isset($_POST['fileID']) || empty($_POST['fileID'])) {
             throw new Exception(__('Missing image ID', ET_DOMAIN));
         } else {
             $fileID = $_POST["fileID"];
         }
         if (!isset($_FILES[$fileID])) {
             throw new Exception(__('Uploaded file not found', ET_DOMAIN));
         }
         if ($_FILES[$fileID]['size'] > 1024 * 1024) {
             throw new Exception(__('Image file size is too big.Size must be less than < 1MB.', ET_DOMAIN));
         }
         // handle file upload
         $attach_id = et_process_file_upload($_FILES[$fileID], 0, 0, array());
         if (is_wp_error($attach_id)) {
             throw new Exception($attach_id->get_error_message());
         }
         $image_link = wp_get_attachment_image_src($attach_id, 'full');
         // no errors happened, return success response
         $res = array('success' => true, 'msg' => __('The file was uploaded successfully', ET_DOMAIN), 'data' => $image_link[0]);
     } catch (Exception $e) {
         $res = array('success' => false, 'msg' => $e->getMessage());
     }
     wp_send_json($res);
 }
示例#7
0
 /**
  * update branding : logo, mobile icon
  */
 function change_branding()
 {
     $res = array('success' => false, 'msg' => __('There is an error occurred', ET_DOMAIN), 'code' => 400);
     // check fileID
     if (!isset($_POST['fileID']) || empty($_POST['fileID']) || !isset($_POST['imgType']) || empty($_POST['imgType'])) {
         $res['msg'] = __('Missing image ID', ET_DOMAIN);
     } else {
         $fileID = $_POST["fileID"];
         $imgType = $_POST['imgType'];
         // check ajax nonce
         if (!check_ajax_referer($imgType . '_et_uploader', '_ajax_nonce', false)) {
             $res['msg'] = __('Security error!', ET_DOMAIN);
         } elseif (isset($_FILES[$fileID])) {
             // handle file upload
             $attach_id = et_process_file_upload($_FILES[$fileID], 0, 0, array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff'));
             if (!is_wp_error($attach_id)) {
                 try {
                     $attach_data = et_get_attachment_data($attach_id);
                     $options = AE_Options::get_instance();
                     // save this setting to theme options
                     $options->{$imgType} = $attach_data;
                     $options->save();
                     $res = array('success' => true, 'msg' => __('Branding image has been uploaded successfully', ET_DOMAIN), 'data' => $attach_data);
                 } catch (Exception $e) {
                     $res['msg'] = __('Error when updating settings.', ET_DOMAIN);
                 }
             } else {
                 $res['msg'] = $attach_id->get_error_message();
             }
         } else {
             $res['msg'] = __('Uploaded file not found', ET_DOMAIN);
         }
     }
     wp_send_json($res);
 }
示例#8
0
 /**
  * update branding : logo, mobile icon
  */
 function upload_image()
 {
     $res = array('success' => FALSE, 'msg' => __('There is an error occurred', ET_DOMAIN), 'code' => 400);
     // check fileID
     if (!isset($_POST['fileID']) || empty($_POST['fileID']) || !isset($_POST['imgType']) || empty($_POST['imgType'])) {
         $res['msg'] = __('Missing image ID', ET_DOMAIN);
     } else {
         $fileID = $_POST["fileID"];
         $imgType = $_POST['imgType'];
         // check ajax nonce
         if (!de_check_ajax_referer($imgType . '_et_uploader', FALSE, FALSE) && !check_ajax_referer($imgType . '_et_uploader', FALSE, FALSE)) {
             $res['msg'] = __('Security error!', ET_DOMAIN);
         } elseif (isset($_FILES[$fileID])) {
             // handle file upload
             $attach_id = et_process_file_upload($_FILES[$fileID], 0, 0, array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff'));
             if (!is_wp_error($attach_id)) {
                 try {
                     $attach_data = et_get_attachment_data($attach_id);
                     $options = AE_Options::get_instance();
                     // save this setting to theme options
                     // $options->$imgType = $attach_data;
                     // $options->save();
                     /**
                      * do action to control how to store data
                      *
                      * @param $attach_data the array of image data
                      * @param $request     ['data']
                      * @param $attach_id   the uploaded file id
                      */
                     do_action('ae_upload_image', $attach_data, $_POST['data'], $attach_id);
                     $res = array('success' => TRUE, 'msg' => __('Branding image has been uploaded successfully', ET_DOMAIN), 'data' => $attach_data);
                 } catch (Exception $e) {
                     $res['msg'] = __('Error when updating settings.', ET_DOMAIN);
                 }
             } else {
                 $res['msg'] = $attach_id->get_error_message();
             }
         } else {
             $res['msg'] = __('Uploaded file not found', ET_DOMAIN);
         }
     }
     // send json to client
     wp_send_json($res);
 }