' ); return $links; } // ------------------------------------------------------------------ // Settings section callback function // ------------------------------------------------------------------ // // This function is needed for the new section. // function adv_file_upload_setting_section () { wp_enqueue_script( 'adv-file-upload-settings' ); wp_enqueue_style ( 'wp-jquery-ui-dialog' ); echo '

Settings for the Advanced uploader plugin

'; } // ------------------------------------------------------------------ // Browser conversion Callback function // ------------------------------------------------------------------ // // creates a checkbox for Wordpress Galleries settings // function adv_file_upload_setting_browser () { $browser = get_option('adv_file_upload_browser'); echo ""; echo " Create additonal images sizes in browser
"; } // ------------------------------------------------------------------ // PDF image Callback function // ------------------------------------------------------------------ // // creates a checkbox for Wordpress Galleries settings // function adv_file_upload_setting_pdf () { $pdf = get_option('adv_file_upload_pdf'); echo ""; echo " Create image of pdf files, This switch does not effect server side, but requires imagick
"; } // ------------------------------------------------------------------ // Wordpress Galleries Callback function // ------------------------------------------------------------------ // // creates a checkbox for Wordpress Galleries settings // function adv_file_upload_setting_gallery () { $gallery = get_option('adv_file_upload_gallery'); echo ""; echo " Selecting this will include Wordpress Galleries as destinations
"; } // ------------------------------------------------------------------ // BWS Galleries Callback function // ------------------------------------------------------------------ // // creates a checkbox for BWS Galleries settings // function adv_file_upload_setting_bws () { $bws = get_option('adv_file_upload_bws'); echo ""; echo " Selecting this will include BWS Galleries as destinations
"; echo "Note: BWS Gallery needs to be active to use this feature"; } // ------------------------------------------------------------------ // Category Callback functions // ------------------------------------------------------------------ // // creates a checkbox for Category settings // function adv_file_upload_setting_cat () { $cat = get_option('adv_file_upload_cat'); echo ""; echo " Selecting this will include Categories as destinations
"; echo "Note: It is recommend to have Media Categories By Eddie Moya to be active to use this feature"; } // // creates a text box for Category exclusion settings // function adv_file_upload_setting_exc_cat () { $cat = get_option('adv_file_upload_exc_cat','Uncategorized'); echo ""; echo "Note: Enter category names separated with a comma, parent categories will exclude child categories"; } // ------------------------------------------------------------------ // Destinations Callback function // ------------------------------------------------------------------ // // creates a boxes for destination settings // function adv_file_upload_setting_dest() { $destinations = get_option('adv_file_upload_destination'); echo "
"; $index=0; //headings echo "
\n"; echo "
Label
\n"; echo "
Destination
\n"; echo "
Add to Library
\n"; echo "
\n"; echo "
\n"; // show default location $upload_dir = wp_upload_dir(); $default_dir = str_replace ( ABSPATH, '', $upload_dir['path'] ); $base_dir = str_replace ( ABSPATH, '', $upload_dir['basedir'] ); echo "\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; if (isset($destinations) && $destinations) { foreach ($destinations as $dest) { $labelStyle = $destStyle = $libStyle = ""; if( array_key_exists( 'error', $dest ) ) { if( array_key_exists( 'label', $dest['error'] ) ) $labelStyle = "background-color: #ffebe8;"; if( array_key_exists( 'dest', $dest['error'] ) ) $destStyle = "background-color: #ffebe8;"; if( array_key_exists( 'library', $dest['error'] ) ) $libStyle = "background-color: #ffebe8;"; } echo "
"; echo ""; echo ""; echo ""; // add delete button echo ""; echo "
"; $index++; } } // add new button echo "
\n"; echo "\n"; echo ''."\n"; echo "
\n"; echo "

"; echo ""; echo " Scan Uploads directory for new destinations

\n"; echo "

Note: Thumbnail images are only created when adding to Wordpress Library
\n"; echo "Note: When adding to Wordpress Library your directory needs to be within the default upload directory

\n"; } // ------------------------------------------------------------------ // Validate destination field // ------------------------------------------------------------------ // // This function is needed to check that the destiantion exist // function adv_file_upload_validate_destination ($input) { if (!isset($input)) return $input; $valid_input = array(); foreach ($input as $id => $dest) { // register destination requires a label if( $dest['label'] == '' ) { add_settings_error( 'Destination', // setting title 0, // error ID __('A label is required for all destinations','wptuts_textdomain'), // error message 'error' // type of message ); $valid_input[$id]['error']['label'] = true; } // register destination does not exist error if( is_dir( ABSPATH . $dest['dest'] ) == FALSE ) { add_settings_error( 'Destination', // setting title 1, // error ID __('Expecting a valid directory! Please fix, the directory needs to exist in the filesystem first.','wptuts_textdomain'), // error message 'error' // type of message ); $valid_input[$id]['error']['dest'] = true; } // register destination does is not in uploads directory error $upload_dir = wp_upload_dir(); //get upload base dir $default_dir = str_replace ( ABSPATH, '', $upload_dir['basedir'] ); //remove site root if( array_key_exists('library',$dest) && !preg_match( '#^' . $default_dir . '/#', $dest['dest'] ) && !preg_match( '#^' . $default_dir . '$#', $dest['dest'] ) ) { add_settings_error( 'Destination', // setting title 2, // error ID __('To add to Wordpress Library Destination must be in within uploads directory! Please fix.','wptuts_textdomain'), // error message 'error' // type of message ); $valid_input[$id]['error']['library'] = true; } $valid_input[$id]['label'] = $dest['label']; $valid_input[$id]['dest'] = rtrim($dest['dest'], "/"); $valid_input[$id]['library'] = array_key_exists('library',$dest) ? $dest['library'] : 0; $valid_input[$id]['type'] = ""; $valid_input[$id]['id'] = ""; } return $valid_input; } // ------------------------------------------------------------------ // Progress Bar Colour Callback function // ------------------------------------------------------------------ // // creates a boxes for destination settings // function adv_file_upload_setting_prog() { $progress = get_option('adv_file_upload_progress'); $errors = get_settings_errors( 'adv_file_upload_progress'); $destStyle = ""; foreach ($errors as $error) { if ($error['code']) { $destStyle = "background-color: #ffebe8;"; $progress = $error['code']; } } // show Progress colour echo ""; echo "This should be an HTML colour code. e.g. #0063a6
"; echo "Note: Leave blank for browser default"; } // ------------------------------------------------------------------ // Validate Progress Bar Colour field // ------------------------------------------------------------------ // // This function is needed to check that the Progress Bar Colour is a valid colour // function adv_file_upload_validate_progress ($input) { //add hash to front of colour code if missing if(preg_match('/^[a-f0-9]{6}$/i', $input)) $input = '#' . $input; //validate valid input (empty for browser default) if(preg_match('/^#[a-f0-9]{6}$/i', $input) || $input == '') return $input; add_settings_error( 'adv_file_upload_progress', // setting title $input, // error ID __('Expecting a valid HTML Colour Code! Please fix Colour of progress bar field.','wptuts_textdomain'), // error message 'error' // type of message ); return get_option('adv_file_upload_progress'); } // ------------------------------------------------------------------ // Override form header calulation Callback function // ------------------------------------------------------------------ // // creates a boxes for Override form header calulation settings // function adv_file_upload_settings_overide_header_calc() { $override = get_option('adv_file_upload_overide_header_calc'); $errors = get_settings_errors( 'adv_file_upload_overide_header_calc'); $destStyle = ""; foreach ($errors as $error) { if ($error['code']) { $destStyle = "background-color: #ffebe8;"; $progress = $error['code']; } } // show Progress colour echo ""; echo "This should be a number of kbytes. e.g. 1
"; echo "Note: Leave blank for automatic calulation"; } // ------------------------------------------------------------------ // Validate Override form header calulation field // ------------------------------------------------------------------ // // This function is needed to check that the Override value is a number // function adv_file_upload_validate_overide_header_calc ($input) { //validate valid input (empty for automatic calulation) if(preg_match('/^[0-9]+$/i', $input) || $input == '') return $input; add_settings_error( 'adv_file_upload_overide_header_calc', // setting title $input, // error ID __('Expecting a number! Please fix Overide form header calulation.','wptuts_textdomain'), // error message 'error' // type of message ); return get_option('adv_file_upload_overide_header_calc'); } function adv_file_upload_show_attachment_thumb( $link, $id, $size, $permalink, $icon, $text) { $id = intval( $id ); //get meta data $meta = wp_get_attachment_metadata($id); if ($meta == false) return $link; $upload_dir = wp_upload_dir(); $rel_path = pathinfo ($meta['file'], PATHINFO_DIRNAME); if(array_key_exists('sizes',$meta)) { $sizes = array_shift($meta['sizes']); $thumb_path = $upload_dir['basedir'] . '/' . $rel_path . '/' . $sizes['file']; $thumb_url = $upload_dir['baseurl'] . '/' . $rel_path . '/' . $sizes['file']; } else { $thumb_path = $upload_dir['basedir'] . '/' . $meta['file']; $thumb_url = $upload_dir['baseurl'] . '/' . $meta['file']; } //if file exists use thumbnail else use icon if (file_exists( $thumb_path )) { $link = preg_replace( '/src=\"(.*?)\"/', 'src="'.$thumb_url.'"', $link ); } return $link; } add_filter( 'wp_get_attachment_link', 'adv_file_upload_show_attachment_thumb', 100, 6 ); function adv_file_upload_attachment_image_src ( $image, $attachment_id, $size, $icon ) { return $image; } add_filter( 'wp_get_attachment_image_src', 'adv_file_upload_attachment_image_src', 100, 6 ); //if thumbnail exist replace default icon function adv_file_upload_change_mime_icon($icon, $mime = null, $post_id = null){ //get the path and URL to thumbnail and store globally global $thumb_path; $thumb_path = ""; //get meta data $meta = wp_get_attachment_metadata($post_id); if ($meta == false || !isset($meta['sizes'])) return $icon; $upload_dir = wp_upload_dir(); $rel_path = pathinfo ($meta['file'] , PATHINFO_DIRNAME); $thumb_path = $upload_dir['basedir'] . '/' . $rel_path . '/' . $meta['sizes']['thumbnail']['file']; $thumb_url = $upload_dir['baseurl'] . '/' . $rel_path . '/' . $meta['sizes']['thumbnail']['file']; //if file exists use thumbnail else use icon if (file_exists( $thumb_path )) return $thumb_url; else return $icon; } add_filter('wp_mime_type_icon', 'adv_file_upload_change_mime_icon', 100, 3); //if thumbnail exist replace default icon function adv_file_upload_change_icon_dir($icon_dir) { //retrive globally stored thumb path global $thumb_path; //if thumbnail exists use instead icon if (file_exists( $thumb_path )) return dirname ($thumb_path); else return $icon_dir; } add_filter('icon_dir', 'adv_file_upload_change_icon_dir', 100, 1); function adv_file_upload_upload_mimes($mimes = array()) { // allow SVG file upload $mimes['svg'] = 'image/svg+xml'; return $mimes; } add_filter( 'upload_mimes', 'adv_file_upload_upload_mimes' ); // Hide image overflow for icons replace with thumbnails in the ADMIN AREA function change_media_send_to_editor($html, $post_id, $attachment) { //get display_attachment_image post data $size = ""; $att_img = get_post_meta($post_id,'display_attachment_image'); if( is_array($att_img) ) $size = $att_img[0]; //get meta data $meta = wp_get_attachment_metadata($post_id); if ($size == '' || $meta == false) return $html; //remove display_attachment_image from post meta so isn't used incorrectly delete_post_meta($post_id, 'display_attachment_image'); $upload_dir = wp_upload_dir(); $rel_path = pathinfo ($meta['file'] , PATHINFO_DIRNAME); $thumb_path = $upload_dir['basedir'] . '/' . $rel_path . '/' . $meta['sizes'][$size]['file']; $thumb_url = $upload_dir['baseurl'] . '/' . $rel_path . '/' . $meta['sizes'][$size]['file']; //if file exists use thumbnail else use icon if (file_exists( $thumb_path )) { $html = preg_replace('/(.*href=.*>)(.*)(<.*)/', '\1\2\3', $html); } return $html; } add_filter('media_send_to_editor', 'change_media_send_to_editor', 20, 3); //add images sizes to pdf attachemnts (if stored in meta) for selection in media library function advupl_attachment_fields_to_edit($form_fields, $post) { if ( !preg_match("/^image/", $post->post_mime_type) ) { $attachment_url = wp_get_attachment_url( $post->ID ); $meta = wp_get_attachment_metadata( $post->ID ); $sizes = array(); $possible_sizes = apply_filters( 'image_size_names_choose', array( 'thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), //'full' => __('Full Size'), ) ); //unset( $possible_sizes['full'] ); if( isset( $meta['sizes'] ) ) { // Loop through all potential sizes that may be chosen. foreach ( $possible_sizes as $size => $label ) { if ( isset( $meta['sizes'][ $size ] ) ) { if ( ! isset( $base_url ) ) $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); // Nothing from the filter, so consult image metadata if we have it. $size_meta = $meta['sizes'][ $size ]; // We have the actual image size, but might need to further constrain it if content_width is narrower. // Thumbnail, medium, and full sizes are also checked against the site's height/width options. list( $width, $height ) = image_constrain_size_for_editor( $size_meta['width'], $size_meta['height'], $size, 'edit' ); $sizes[ $size ] = ""; } } //add image size select if attachment has other images associated if (count ($sizes) > 0) { $sizes['link'] = ""; $sizes_array = array( 'display_attachment_image_heading' => array( 'label' => __('

Attachment Image

', 'display_attachment_image'), 'input' => 'html', 'html' => ' ' ), 'display_attachment_image' => array( 'label' => __('Sizes', 'display_attachment_image'), 'input' => 'html', 'html' => "\n" )); $form_fields = array_merge( $form_fields, $sizes_array ); } } } return $form_fields; } add_filter('attachment_fields_to_edit', 'advupl_attachment_fields_to_edit', 20, 2); function save_display_attachment_image($post, $attachment_data) { // use this filter to add post meta if key exists or delete it if not if ( !empty($attachment_data['display_attachment_image']) && $attachment_data['display_attachment_image'] != 'link' ) update_post_meta($post['ID'], 'display_attachment_image', $attachment_data['display_attachment_image']); else delete_post_meta($post['ID'], 'display_attachment_image'); // return $post in any case, things will break otherwise return $post; } add_filter('attachment_fields_to_save', 'save_display_attachment_image', 20, 2); //create new post for WP Gallery function adv_upload_new_post () { check_ajax_referer('alt_upl_nonce' . get_current_user_id(),'security'); $titles = json_decode(stripcslashes($_REQUEST["title"])); $results = array(); foreach( $titles as $title ) { // Create post object $new_post = array( 'post_title' => $title, ); // Insert the post into the database $results[] = array( 'id' => wp_insert_post( $new_post ), 'title' => $title); } echo json_encode( $results ); wp_die(); } function adv_upload_dropzone() { //check nounce is correct check_ajax_referer('alt_upl_nonce' . get_current_user_id(),'security'); // Make sure file is not cached (as it happens for example on iOS devices) header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // Settings $cleanupTargetDir = true; // Remove old files $maxFileAge = 5 * 3600; // Temp file age in seconds // 5 minutes execution time @set_time_limit(5 * 60); // Get parameters $post_id = 0; $uid = isset($_REQUEST["dzuuid"]) ? $_REQUEST["dzuuid"] : 0; $totalchunkcount = isset($_REQUEST["dztotalchunkcount"]) ? intval($_REQUEST["dztotalchunkcount"]) : 0; $fileName = isset($_REQUEST["filename"]) ? $_REQUEST["filename"] : ''; $sizesObj = isset($_REQUEST['meta']) ? json_decode(stripcslashes($_REQUEST['meta'])) : null; $album = isset($_REQUEST["album"]) ? intval($_REQUEST["album"]) : 0; //get destinations from JSON object $destinations = json_decode(stripcslashes($_REQUEST['destinations'])); $dest = isset($_REQUEST["fileDest"]) ? intval($_REQUEST["fileDest"]) : 0; $targetDir = ABSPATH . $destinations [$dest]->dest; $sourceDir = wp_upload_dir()['basedir'] . DIRECTORY_SEPARATOR . 'adv-upload-dir'; $sourcePath = $sourceDir . DIRECTORY_SEPARATOR . $uid; // get a valid wordpress filesname $fileName = wp_unique_filename($targetDir, $fileName); $filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName; // Open temp file $out = @fopen("{$filePath}", "wb"); if ($out === false) { //send error http_response_code (500); //set Content-Type to JSON header( 'Content-Type: application/json; charset=utf-8' ); die('{"code" : "102", "message": "Failed to open output stream.", "id" : "' . $uid . '"}'); } //loop through the part files and concate them together $chunkFailed = false; for ($chunk = 0; $chunk < $totalchunkcount; $chunk++) { // Open output file $in = @fopen("{$sourcePath}.{$chunk}.part", "rb"); if ($in === false) { $chunkFailed = true; } else { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } @fclose($in); @unlink("{$sourcePath}.{$chunk}.part"); } } @fclose($out); if ($chunkFailed) { //send error http_response_code (500); //set Content-Type to JSON header( 'Content-Type: application/json; charset=utf-8' ); die('{"code" : "102", "message": "Failed to open input stream.", "id" : "' . $uid . '"}'); } //save thumbnails with main file if (array_key_exists('thumbs', $_FILES) && count($_FILES['thumbs']) > 0) { for ($i = 0; $i < count($_FILES['thumbs']['name']); $i++) { $filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName . $_FILES['thumbs']['name'][$i]; $temp_file = $_FILES['thumbs']['tmp_name'][$i]; $error = $_FILES['thumbs']['error'][$i]; // Open temp file if (!$out = @fopen("{$filePath}", "wb")) { //send error http_response_code (500); //set Content-Type to JSON header( 'Content-Type: application/json; charset=utf-8' ); die('{"code" : "102", "message": "Failed to open output stream.", "id" : "' . $uid . '"}'); } if ($error || !is_uploaded_file($temp_file)) { //send error http_response_code (500); //set Content-Type to JSON header( 'Content-Type: application/json; charset=utf-8' ); die('{"code" : "103", "message": "Failed to move uploaded file.", "id" : "' . $uid . '"}'); } // Read binary input stream and append it to temp file if (!$in = @fopen($temp_file, "rb")) { //send error http_response_code (500); //set Content-Type to JSON header( 'Content-Type: application/json; charset=utf-8' ); die('{"code" : "101", "message": "Failed to open input stream.", "id" : "' . $uid . '"}'); } while ($buff = fread($in, 4096)) { fwrite($out, $buff); } @fclose($out); @fclose($in); } } if( $destinations[$dest]->type == 'Wordpress Gallery' ) { if( $destinations[$dest]->id == 'new' ) { $post_id = intval( $album ); } else { $post_id = $destinations[$dest]->id; } } if(file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) { if(isset($sizesObj)) foreach ($sizesObj as $sizeDesc => $array) foreach ($array as $element => $content) if($element == 'file' ) $sizes[$sizeDesc][$element] = $fileName.$content; else $sizes[$sizeDesc][$element] = $content; else $sizes = null; //add to wordpress library if relevant if( $destinations[$dest]->library ) { $attachment_id = adv_upload_add_file ($fileName, $targetDir . DIRECTORY_SEPARATOR, $post_id, $sizes, $destinations [$dest]->label, $destinations [$dest]->type, $destinations [$dest]->id); } else { //set url to mime type icon or file dependant on Mime type $fileInfo = wp_check_filetype( $fileName ); $type = wp_ext2type( $fileInfo['ext'] ); if( preg_match( '/^image/', $fileInfo['type'] ) ) $url = $targetUrl . DIRECTORY_SEPARATOR . $fileName; else $url = wp_mime_type_icon( $type ); $response = json_encode( array( 'code' => 0, 'success' => true, 'data' => array( 'id' => false, 'url' => $url, 'name' => $fileName) )); header( 'Content-Type: application/json; charset=utf-8' ); die("{$response}"); } if( $destinations[$dest]->type == 'Category' ) { wp_set_object_terms( $attachment_id, $album, 'category' ); } if( $destinations[$dest]->type == 'Wordpress Gallery' ) { $gallery = get_post( $post_id ); if( $gallery->post_content == "" ) { $gal_upd = array( 'ID' => $post_id, 'post_content' => '[gallery link="file" ids="' . $attachment_id . '"]' ); // Update the post into the database wp_update_post( $gal_upd ); } elseif( preg_match( '/^(.*\[gallery.+ids=".+)(".*)$/', $gallery->post_content, $matches) ) { $gal_upd = array( 'ID' => $post_id, 'post_content' => $matches[1] . ',' . $attachment_id . $matches[2] ); // Update the post into the database wp_update_post( $gal_upd ); } } if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) ) { //send error http_response_code (500); //set Content-Type to JSON header( 'Content-Type: application/json; charset=utf-8' ); die('{"code" : "110", "message": "Failed to get attachment data.", "id" : "' . $uid . '"}'); } } // Return Success JSON-RPC response $response = json_encode( array( 'code' => 0, 'success' => true, 'data' => $attachment )); header( 'Content-Type: application/json; charset=utf-8' ); die("{$response}"); } function adv_upload_dropzone_chunks() { error_log('test'); //check nounce is correct check_ajax_referer('alt_upl_nonce' . get_current_user_id(),'security'); // Make sure file is not cached (as it happens for example on iOS devices) header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // Settings $cleanupTargetDir = true; // Remove old files $maxFileAge = 5 * 3600; // Temp file age in seconds // 5 minutes execution time @set_time_limit(5 * 60); // Get parameters $uid = isset($_REQUEST["dzuuid"]) ? $_REQUEST["dzuuid"] : 0; $chunkindex = isset($_REQUEST["dzchunkindex"]) ? intval($_REQUEST["dzchunkindex"]) : 0; $totalchunkcount = isset($_REQUEST["dztotalchunkcount"]) ? intval($_REQUEST["dztotalchunkcount"]) : 0; //$targetDir = ABSPATH . $destinations [$dest][1]; $targetDir = wp_upload_dir()['basedir'] . DIRECTORY_SEPARATOR . 'adv-upload-dir'; $filePath = $targetDir . DIRECTORY_SEPARATOR . $uid; // Create target dir if (!file_exists($targetDir)) @mkdir($targetDir); // Remove old temp files if ($cleanupTargetDir) { if (!is_dir($targetDir) || !$dir = opendir($targetDir)) { //send error http_response_code (500); die("Failed to open temp directory."); } while (($file = readdir($dir)) !== false) { $tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file; // If temp file is current file proceed to the next if ($tmpfilePath == "{$filePath}.{$chunkindex}.part") { continue; } // Remove temp file if it is older than the max age and is not the current file if (preg_match('/\.part$/', $file) && (filemtime($tmpfilePath) < time() - $maxFileAge)) { @unlink($tmpfilePath); } } closedir($dir); } // Open temp file if (!$out = @fopen("{$filePath}.{$chunkindex}.part", "wb")) { //send error http_response_code (500); die("Failed to open output stream."); } if (!empty($_FILES)) { if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) { //send error http_response_code (500); die("Failed to move uploaded file."); } // Read binary input stream and append it to temp file if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) { //send error http_response_code (500); die("Failed to open input stream."); } } while ($buff = fread($in, 4096)) { fwrite($out, $buff); } @fclose($out); @fclose($in); die("Success."); } // fix issue with missing full image for PDF file. function adv_uploader_update_attachment_metadata( $metadata, $attachment_id ) { //if( is_admin() && isset( $metadata["sizes"]) && !isset( $metadata["sizes"]["full"] )) // $metadata["sizes"]["full"] = $metadata["sizes"]["large"]; $attachment = get_post( $attachment_id ); if ( get_post_mime_type( $attachment ) == "image/svg+xml" && empty($metadata) ) { $svgfile = simplexml_load_file(get_attached_file( $attachment_id )); $metadata['width'] = (int) $svgfile['width']; $metadata['height'] = (int) $svgfile['height']; } return $metadata; } if( get_option('adv_file_upload_pdf') ) add_filter( 'wp_generate_attachment_metadata', 'adv_uploader_update_attachment_metadata', 20, 2 ); function adv_uploader_pdf_srcset_meta( $image_meta, $size_array, $image_src, $attachment_id ){ if( isset( $image_meta['file'] ) ) { $file_info = new SplFileInfo( $image_meta['file'] ); if( $file_info->getExtension() == 'pdf' ) { $image_meta['file'] = $file_info->getPath() . '/' . $image_meta['sizes']['full']['file']; } } return $image_meta; } if( get_option('adv_file_upload_pdf') ) add_filter( 'wp_calculate_image_srcset_meta', 'adv_uploader_pdf_srcset_meta', 10, 4 ); function adv_uploader_pdf_correct( $downsize, $id, $size ){ $image_meta = wp_get_attachment_metadata($id); if( isset( $image_meta['file'] ) ) { $file_info = new SplFileInfo( $image_meta['file'] ); $update_meta = false; if( $file_info->getExtension() == 'pdf' ) { if( !isset( $image_meta['sizes']['full'] ) ) { $image_meta['sizes']['full'] = $image_meta['sizes']['large']; $update_meta = true; } if( !isset( $image_meta['width'] ) || !is_int( $image_meta['width'] ) ) { $image_meta['width'] = $image_meta['width']['full']['file']['width']; $update_meta = true; } if( !isset( $image_meta['height'] ) || !is_int( $image_meta['height'] ) ) { $image_meta['height'] = $image_meta['width']['full']['file']['height']; $update_meta = true; } if( $update_meta ) { wp_update_attachment_metadata( $id, $image_meta ); } } } return false; } if( get_option('adv_file_upload_pdf') ) add_filter( 'image_downsize', 'adv_uploader_pdf_correct', 10, 3 ); function show_pdf_with_images( $query = array() ) { if( is_array( $query['post_mime_type'] ) && in_array( 'image', $query['post_mime_type'] ) ) $query['post_mime_type'][] = 'application/pdf'; return $query; } //if PDF images is activated allow them to be added as images if( get_option('adv_file_upload_pdf') ) add_filter( 'ajax_query_attachments_args', 'show_pdf_with_images', 10, 1 ); ?> Page not found - Official Blog Of National Marketing Projects



It seems we can’t find what you’re looking for. Perhaps searching can help.