Files
ultimatemember/includes/lib/upload/um-image-upload.php
T

93 lines
2.2 KiB
PHP
Raw Normal View History

2014-12-15 22:38:07 +02:00
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
2014-12-15 22:38:07 +02:00
2015-05-02 02:49:05 +03:00
$dirname = dirname( __FILE__ );
do {
$dirname = dirname( $dirname );
$wp_config = "{$dirname}/wp-config.php";
$wp_load = "{$dirname}/wp-load.php";
2015-05-02 02:49:05 +03:00
}
2017-07-01 21:53:05 +08:00
while( !file_exists( $wp_config ) );
if ( !file_exists( $wp_load ) ) {
$dirs = glob( $dirname . '/*' , GLOB_ONLYDIR );
2017-07-01 21:53:05 +08:00
2017-12-18 15:36:04 +02:00
foreach ( $dirs as $key => $value ) {
$wp_load = "{$value}/wp-load.php";
if ( file_exists( $wp_load ) ) {
break;
}
}
2017-07-01 21:53:05 +08:00
}
2015-05-02 02:49:05 +03:00
require_once( $wp_load );
2014-12-15 22:38:07 +02:00
2016-06-17 11:39:04 +08:00
$ret['error'] = null;
$ret = array();
2014-12-15 22:38:07 +02:00
$id = $_POST['key'];
2016-06-17 11:39:04 +08:00
$timestamp = $_POST['timestamp'];
$nonce = $_POST['_wpnonce'];
UM()->fields()->set_id = $_POST['set_id'];
UM()->fields()->set_mode = $_POST['set_mode'];
2014-12-15 22:38:07 +02:00
2018-03-02 09:55:49 +02:00
/**
* UM hook
*
* @type filter
* @title um_image_upload_nonce
* @description Change Image Upload nonce
* @input_vars
* [{"var":"$nonce","type":"bool","desc":"Nonce"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_image_upload_nonce', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_image_upload_nonce', 'my_image_upload_nonce', 10, 1 );
* function my_image_upload_nonce( $nonce ) {
* // your code here
* return $nonce;
* }
* ?>
*/
$um_image_upload_nonce = apply_filters( "um_image_upload_nonce", true );
if( $um_image_upload_nonce ){
if ( ! wp_verify_nonce( $nonce, 'um_upload_nonce-'.$timestamp ) && is_user_logged_in() ) {
// This nonce is not valid.
$ret['error'] = 'Invalid nonce';
die( json_encode( $ret ) );
}
2016-06-17 11:39:04 +08:00
}
2014-12-15 22:38:07 +02:00
if(isset($_FILES[$id]['name'])) {
if(!is_array($_FILES[$id]['name'])) {
$temp = $_FILES[$id]["tmp_name"];
2017-01-19 02:47:03 -07:00
$file = $id."-".$_FILES[$id]["name"];
2015-11-05 19:51:31 +08:00
$file = sanitize_file_name($file);
$ext = strtolower( pathinfo($file, PATHINFO_EXTENSION) );
2015-11-16 21:42:58 +08:00
$error = UM()->files()->check_image_upload( $temp, $id );
2014-12-15 22:38:07 +02:00
if ( $error ){
2014-12-15 22:38:07 +02:00
$ret['error'] = $error;
2014-12-15 22:38:07 +02:00
} else {
2015-11-16 21:42:58 +08:00
$file = "stream_photo_".md5($file)."_".uniqid().".".$ext;
2017-12-11 09:53:38 +02:00
$ret[ ] = UM()->files()->new_image_upload_temp( $temp, $file, UM()->options()->get('image_compression') );
2014-12-15 22:38:07 +02:00
}
}
2015-03-14 23:39:33 +02:00
} else {
$ret['error'] = __('A theme or plugin compatibility issue','ultimate-member');
2014-12-15 22:38:07 +02:00
}
2017-01-19 02:47:03 -07:00
echo json_encode($ret);