protected function get_views() { global $wpdb, $post_mime_types, $avail_post_mime_types; $type_links = array(); $_num_posts = (array) wp_count_attachments(); $_total_posts = array_sum($_num_posts) - $_num_posts['trash']; $total_orphans = $wpdb->get_var("SELECT COUNT( * ) FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1"); $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); foreach ($matches as $type => $reals) { foreach ($reals as $real) { $num_posts[$type] = isset($num_posts[$type]) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real]; } } $selected = empty($_GET['attachment-filter']) ? ' selected="selected"' : ''; $type_links['all'] = "<option value=''{$selected}>" . sprintf(_nx('All (%s)', 'All (%s)', $_total_posts, 'uploaded files'), number_format_i18n($_total_posts)) . '</option>'; foreach ($post_mime_types as $mime_type => $label) { if (!wp_match_mime_types($mime_type, $avail_post_mime_types)) { continue; } $selected = ''; if (!empty($_GET['attachment-filter']) && strpos($_GET['attachment-filter'], 'post_mime_type:') === 0 && wp_match_mime_types($mime_type, str_replace('post_mime_type:', '', $_GET['attachment-filter']))) { $selected = ' selected="selected"'; } if (!empty($num_posts[$mime_type])) { $type_links[$mime_type] = '<option value="post_mime_type:' . sanitize_mime_type($mime_type) . '"' . $selected . '>' . sprintf(translate_nooped_plural($label[2], $num_posts[$mime_type]), number_format_i18n($num_posts[$mime_type])) . '</option>'; } } $type_links['detached'] = '<option value="detached"' . ($this->detached ? ' selected="selected"' : '') . '>' . sprintf(_nx('Unattached (%s)', 'Unattached (%s)', $total_orphans, 'detached files'), number_format_i18n($total_orphans)) . '</option>'; if (!empty($_num_posts['trash'])) { $type_links['trash'] = '<option value="trash"' . (isset($_GET['attachment-filter']) && $_GET['attachment-filter'] == 'trash' ? ' selected="selected"' : '') . '>' . sprintf(_nx('Trash (%s)', 'Trash (%s)', $_num_posts['trash'], 'uploaded files'), number_format_i18n($_num_posts['trash'])) . '</option>'; } return $type_links; }
function test_sanitize_valid_mime_type() { $inputs = array('application/atom+xml', 'application/EDI-X12', 'application/EDIFACT', 'application/json', 'application/javascript', 'application/octet-stream', 'application/ogg', 'application/pdf', 'application/postscript', 'application/soap+xml', 'application/x-woff', 'application/xhtml+xml', 'application/xml-dtd', 'application/xop+xml', 'application/zip', 'application/x-gzip', 'audio/basic', 'image/jpeg', 'text/css', 'text/html', 'text/plain', 'video/mpeg'); foreach ($inputs as $input) { $this->assertEquals($input, sanitize_mime_type($input)); } }
/** * wpuxss_eml_mimes_validate * * @type callback function * @since 1.0 * @created 15/10/13 */ function wpuxss_eml_mimes_validate($input) { if (!$input) { $input = array(); } if (isset($_REQUEST['wpuxss_eml_restore_mimes_backup'])) { $_REQUEST['_wp_http_referer'] .= '&settings-restored=true'; $wpuxss_eml_mimes_backup = get_option('wpuxss_eml_mimes_backup'); $input = $wpuxss_eml_mimes_backup; } else { foreach ($input as $type => $mime) { $sanitized_type = wpuxss_eml_sanitize_extension($type); if ($sanitized_type !== $type) { $input[$sanitized_type] = $input[$type]; unset($input[$type]); $type = $sanitized_type; } if (!isset($input[$type]['filter'])) { $input[$type]['filter'] = 0; } if (!isset($input[$type]['upload'])) { $input[$type]['upload'] = 0; } $input[$type]['filter'] = intval($input[$type]['filter']); $input[$type]['upload'] = intval($input[$type]['upload']); $input[$type]['mime'] = sanitize_mime_type($mime['mime']); $input[$type]['singular'] = sanitize_text_field($mime['singular']); $input[$type]['plural'] = sanitize_text_field($mime['plural']); } } return $input; }
function wpuxss_eml_mimes_validate($input) { if (!$input) { $input = array(); } if (isset($_POST['eml-restore-mime-types-settings'])) { $wpuxss_eml_mimes_backup = get_option('wpuxss_eml_mimes_backup'); $input = $wpuxss_eml_mimes_backup; add_settings_error('wpuxss_eml_mimes', 'eml_mime_types_restored', __('MIME type settings restored.', 'eml'), 'updated'); } elseif (!isset($_POST['eml-settings-import']) && !isset($_POST['eml-settings-restore'])) { add_settings_error('wpuxss_eml_mimes', 'eml_mime_types_saved', __('MIME type settings saved.', 'eml'), 'updated'); } foreach ($input as $type => $mime) { $sanitized_type = wpuxss_eml_sanitize_extension($type); if ($sanitized_type !== $type) { $input[$sanitized_type] = $input[$type]; unset($input[$type]); $type = $sanitized_type; } $input[$type]['filter'] = isset($mime['filter']) && !!$mime['filter'] ? 1 : 0; $input[$type]['upload'] = isset($mime['upload']) && !!$mime['upload'] ? 1 : 0; $input[$type]['mime'] = sanitize_mime_type($mime['mime']); $input[$type]['singular'] = sanitize_text_field($mime['singular']); $input[$type]['plural'] = sanitize_text_field($mime['plural']); } return $input; }
/** * Plupload action. * * @since 1.0.0 * @access public * @return json */ public function plupload() { $imgid = $_POST['imgid']; check_ajax_referer($this->action_nonce, $this->field_nonce); /** Decide whether to send this image to Media. @var String */ $add_to_media_library = isset($_POST['tomedia']) ? $_POST['tomedia'] : false; /** If post ID is set, uploaded image will be attached to it. @var String */ $postid = isset($_POST['topost']) ? intval($_POST['topost']) : ''; $import_type = isset($_POST['import_type']) ? $_POST['import_type'] : 'import'; $method = isset($_POST['import_method']) ? $_POST['import_method'] : 'add'; $import_source = isset($_POST['import_source']) ? $_POST['import_source'] : 'theme'; /** Handle file upload storing file|url|type. @var Array */ $file = wp_handle_upload($_FILES[$imgid . 'async-upload'], array('test_form' => true, 'action' => 'tf_plupload')); if ($file && !isset($file['error'])) { //let's see if it's an image, a zip file or something else $ext = explode('/', $file['type']); // Import routines $allowed_types = array('zip', 'rar', 'plain', 'xml'); if (in_array($ext[1], $allowed_types)) { $url = wp_nonce_url('admin.php?page=themify-flow'); if (false === ($creds = request_filesystem_credentials($url))) { return true; } if (!WP_Filesystem($creds)) { request_filesystem_credentials($url, '', true); return true; } global $wp_filesystem, $TF, $tf_export; if ('zip' == $ext[1] || 'rar' == $ext[1]) { unzip_file($file['file'], $TF->framework_path()); $file_meta = $tf_export->get_filename_data('tf_' . $import_source); $filename = $TF->framework_path() . '/' . sanitize_file_name($file_meta['file']); } else { $filename = $file['file']; } if ($wp_filesystem->exists($filename)) { if ('content_builder' == $import_source) { $import = new TF_Import_Content_Builder(); $import->content_builder_id = $postid; $import->fetch_attachments = true; $import->import($filename); } else { $import = new TF_Import(); $import->fetch_attachments = true; $import->method = $method; $import->source = $import_source; if ('edit' == $method) { $import->edit_import_id = $postid; } $import->import($filename); if ($import->fails()) { $file['error'] = implode('\\n', $import->get_error_messages()); } else { $file['activate_theme_uri'] = wp_nonce_url(admin_url('post.php?post=' . $import->return_ID . '&action=activate_tf_theme'), 'tf_theme_nonce'); } } $wp_filesystem->delete($filename); $wp_filesystem->delete($file['file']); } else { $file['error'] = __('Data could not be loaded because import data not founded in the zip.', 'themify-flow'); // Delete dump file foreach ($tf_export->file_names as $data_file) { if ($wp_filesystem->exists($TF->framework_path() . '/' . $data_file['file'])) { $wp_filesystem->delete($TF->framework_path() . '/' . $data_file['file']); } } } } else { //Image Upload routines if ('tomedia' == $add_to_media_library) { // Insert into Media Library // Set up options array to add this file as an attachment $attachment = array('post_mime_type' => sanitize_mime_type($file['type']), 'post_title' => str_replace('-', ' ', sanitize_file_name(pathinfo($file['file'], PATHINFO_FILENAME))), 'post_status' => 'inherit'); if ($postid) { $attach_id = wp_insert_attachment($attachment, $file['file'], $postid); } else { $attach_id = wp_insert_attachment($attachment, $file['file']); } // Common attachment procedures require_once ABSPATH . "wp-admin" . '/includes/image.php'; $attach_data = wp_generate_attachment_metadata($attach_id, $file['file']); wp_update_attachment_metadata($attach_id, $attach_data); if ($postid) { $full = wp_get_attachment_image_src($attach_id, 'full'); if ($_POST['featured']) { //Set the featured image for the post set_post_thumbnail($postid, $attach_id); } update_post_meta($postid, $_POST['fields'], $full[0]); update_post_meta($postid, '_' . $_POST['fields'] . '_attach_id', $attach_id); $thumb = wp_get_attachment_image_src($attach_id, 'thumbnail'); //Return URL for the image field in meta box $file['thumb'] = $thumb[0]; } } } $file['type'] = $ext[1]; } // send the uploaded file url in response echo json_encode($file); exit; }
/** * Plupload ajax action */ function builder_plupload() { // check ajax nonce $imgid = $_POST['imgid']; //check_ajax_referer( $imgid . 'themify-builder-plupload' ); check_ajax_referer('tfb_load_nonce'); /** If post ID is set, uploaded image will be attached to it. @var String */ $postid = $_POST['topost']; /** Handle file upload storing file|url|type. @var Array */ $file = wp_handle_upload($_FILES[$imgid . 'async-upload'], array('test_form' => true, 'action' => 'themify_builder_plupload_action')); //let's see if it's an image, a zip file or something else $ext = explode('/', $file['type']); // Import routines if ('zip' == $ext[1] || 'rar' == $ext[1] || 'plain' == $ext[1]) { $url = wp_nonce_url('admin.php?page=themify'); $upload_dir = wp_upload_dir(); if (false === ($creds = request_filesystem_credentials($url))) { return true; } if (!WP_Filesystem($creds)) { request_filesystem_credentials($url, '', true); return true; } global $wp_filesystem; if ('zip' == $ext[1] || 'rar' == $ext[1]) { $destination = wp_upload_dir(); $destination_path = $destination['path']; unzip_file($file['file'], $destination_path); if ($wp_filesystem->exists($destination_path . '/builder_data_export.txt')) { $data = $wp_filesystem->get_contents($destination_path . '/builder_data_export.txt'); // Set data here update_post_meta($postid, $this->meta_key, maybe_unserialize($data)); $wp_filesystem->delete($destination_path . '/builder_data_export.txt'); $wp_filesystem->delete($file['file']); } else { _e('Data could not be loaded', 'themify'); } } else { if ($wp_filesystem->exists($file['file'])) { $data = $wp_filesystem->get_contents($file['file']); // set data here update_post_meta($postid, $this->meta_key, maybe_unserialize($data)); $wp_filesystem->delete($file['file']); } else { _e('Data could not be loaded', 'themify'); } } } else { // Insert into Media Library // Set up options array to add this file as an attachment $attachment = array('post_mime_type' => sanitize_mime_type($file['type']), 'post_title' => str_replace('-', ' ', sanitize_file_name(pathinfo($file['file'], PATHINFO_FILENAME))), 'post_status' => 'inherit'); if ($postid) { $attach_id = wp_insert_attachment($attachment, $file['file'], $postid); } // Common attachment procedures require_once ABSPATH . 'wp-admin' . '/includes/image.php'; $attach_data = wp_generate_attachment_metadata($attach_id, $file['file']); wp_update_attachment_metadata($attach_id, $attach_data); if ($postid) { $large = wp_get_attachment_image_src($attach_id, 'large'); $thumb = wp_get_attachment_image_src($attach_id, 'thumbnail'); //Return URL for the image field in meta box $file['large_url'] = $large[0]; $file['thumb'] = $thumb[0]; $file['id'] = $attach_id; } } $file['type'] = $ext[1]; // send the uploaded file url in response echo json_encode($file); exit; }
/** * Update an MLA Upload MIME Type object * * @since 1.40 * * @param array Query variables for new object values, including optional original_slug * * @return array Message(s) reflecting the results of the operation */ public static function mla_update_upload_mime($request = NULL) { if (self::_get_upload_mime_templates()) { $errors = ''; } else { return array('message' => __('ERROR', 'media-library-assistant') . ': ' . __('Cannot load Upload MIME Types', 'media-library-assistant'), 'body' => ''); } /* * $request = NULL is a call from MLASettings::_version_upgrade */ if (NULL == $request) { self::_put_upload_mime_templates(); return; } $messages = ''; $slug = pathinfo('X.' . strtolower(trim($request['slug'])), PATHINFO_EXTENSION); $original_slug = isset($request['original_slug']) ? $request['original_slug'] : $slug; unset($request['original_slug']); if (isset(self::$mla_upload_mime_templates[$original_slug])) { $original_type = self::$mla_upload_mime_templates[$original_slug]; } else { $original_type = array('post_ID' => 0, 'mime_type' => '', 'core_type' => '', 'mla_type' => '', 'source' => '', 'standard_source' => '', 'disabled' => false, 'description' => '', 'wp_icon_type' => '', 'mla_icon_type' => '', 'icon_type' => '', 'core_icon_type' => ''); } /* * Validate changed slug value */ if ($slug != $original_slug) { if ($slug != $request['slug']) { /* translators: 1: element name 2: bad_value 3: good_value */ $messages .= sprintf(__('<br>' . 'Changing new %1$s "%2$s" to valid value "%3$s"', 'media-library-assistant'), __('Extension', 'media-library-assistant'), $request['slug'], $slug); } /* * Make sure new slug is unique */ if (isset(self::$mla_upload_mime_templates[$slug])) { /* translators: 1: ERROR tag 2: slug */ $errors .= '<br>' . sprintf(__('%1$s: Could not add new extension "%2$s"; value already exists', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $slug); } else { /* translators: 1: element name 2: old_value 3: new_value */ $messages .= sprintf('<br>' . __('Changing %1$s from "%2$s" to "%3$s"', 'media-library-assistant'), __('Extension', 'media-library-assistant'), $original_slug, $slug); } /* * A new extension cannot have an $original_type */ $original_type = array('post_ID' => 0, 'mime_type' => '', 'core_type' => '', 'mla_type' => '', 'source' => '', 'standard_source' => '', 'disabled' => false, 'description' => '', 'icon_type' => '', 'wp_icon_type' => '', 'mla_icon_type' => '', 'core_icon_type' => ''); } /* * Validate mime_type */ if (empty($request['mime_type'])) { $clean_mime_type = $original_type['mime_type']; } else { $clean_mime_type = sanitize_mime_type($request['mime_type']); if ($clean_mime_type != $request['mime_type']) { /* translators: 1: ERROR tag 2: clean_mime_type */ $errors .= '<br>' . sprintf(__('%1$s: Bad MIME type; try "%2$s"', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $clean_mime_type); } } if (!empty($errors)) { return array('message' => substr($errors . $messages, 4), 'body' => ''); } $new_type = array(); if (0 == $original_type['post_ID']) { $new_type['post_ID'] = ++self::$mla_upload_mime_highest_ID; } else { $new_type['post_ID'] = $original_type['post_ID']; } $new_type['mime_type'] = $clean_mime_type; $new_type['core_type'] = $original_type['core_type']; $new_type['mla_type'] = $original_type['mla_type']; /* * Determine the source */ if ('core' == $original_type['standard_source'] && $clean_mime_type == $original_type['core_type']) { $new_type['source'] = 'core'; } elseif ('mla' == $original_type['standard_source'] && $clean_mime_type == $original_type['mla_type']) { $new_type['source'] = 'mla'; } else { $new_type['source'] = 'custom'; } /* * Determine new icon types */ $new_type['core_icon_type'] = self::mla_get_core_icon_type($slug); if (isset($request['icon_type'])) { $new_type['icon_type'] = '.none.' == $request['icon_type'] ? 'default' : $request['icon_type']; } elseif (!empty($original_type['icon_type'])) { $new_type['icon_type'] = $original_type['icon_type']; } else { $new_type['icon_type'] = $new_type['core_icon_type']; } if (!empty($original_type['wp_icon_type'])) { $new_type['wp_icon_type'] = $original_type['wp_icon_type']; } else { $new_type['wp_icon_type'] = $new_type['icon_type']; } if (!empty($original_type['mla_icon_type'])) { $new_type['mla_icon_type'] = $original_type['mla_icon_type']; } else { $new_type['mla_icon_type'] = $new_type['icon_type']; } $new_type['standard_source'] = $original_type['standard_source']; $new_type['disabled'] = isset($request['disabled']) ? $request['disabled'] : $original_type['disabled']; $new_type['description'] = isset($request['description']) ? sanitize_text_field($request['description']) : $original_type['description']; if ($slug == $original_slug && self::$mla_upload_mime_templates[$slug] == $new_type) { return array('message' => substr($messages . '<br>' . sprintf(__('Edit type "%1$s"; no changes detected', 'media-library-assistant'), $slug), 4), 'body' => ''); } self::$mla_upload_mime_templates[$slug] = $new_type; if ($slug != $original_slug) { unset(self::$mla_upload_mime_templates[$original_slug]); } if (self::_put_upload_mime_templates()) { return array('message' => substr($messages . '<br>' . sprintf(__('Edit type "%1$s"; updated', 'media-library-assistant'), $slug), 4), 'body' => ''); } return array('message' => __('ERROR', 'media-library-assistant') . ': ' . __('Cannot update Upload MIME Types', 'media-library-assistant'), 'body' => ''); }
function gdwpm_action_callback() { global $wpdb, $cek_kunci, $gdwpm_opt_akun, $gdwpm_service, $gdwpm_apiConfig; $gdwpm_opt_akun = get_option('gdwpm_akun_opt'); // imel, client id, gdwpm_service akun, private key require_once 'gdwpm-api/Google_Client.php'; require_once 'gdwpm-api/contrib/Google_DriveService.php'; if (isset($_POST['folder_pilian'])) { $gdwpm_apiConfig['use_objects'] = true; $gdwpm_service = new GDWPMBantuan($gdwpm_opt_akun[1], $gdwpm_opt_akun[2], $gdwpm_opt_akun[3]); $fld = $_POST['folder_pilian']; if (isset($_POST['pagetoken'])) { $daftar_berkas = $gdwpm_service->getFilesInFolder($fld, $_POST['pilmaxres'], $_POST['pagetoken']); } else { $daftar_berkas = $gdwpm_service->getFilesInFolder($fld, $_POST['pilmaxres']); } //array($daftarfile, $i, $totalhal, $halterlihat) if ($daftar_berkas[1] <= 0) { // total files < 1 if ($daftar_berkas[2] > 1) { // total halaman > 1 if ($daftar_berkas[3] == $daftar_berkas[2]) { echo '<div class="sukses"><p style="text-align:center;"><img src="' . plugins_url('/images/animation/gdwpm_breaker_256.png', __FILE__) . '"><br/>This page is empty.</p></div>'; echo $daftar_berkas[0]; } else { echo '<div class="sukses"><p style="text-align:center;"><img src="' . plugins_url('/images/animation/gdwpm_breaker_256.png', __FILE__) . '"><br/>Your request contains multiple pages, click the page number below.</p></div>'; echo $daftar_berkas[0]; } } else { echo '<div class="sukses"><p style="text-align:center;"><img src="' . plugins_url('/images/animation/gdwpm_breaker_256.png', __FILE__) . '"><br/>This folder is empty.</p></div>'; } } else { echo '<div class="sukses"><p>Folder ID: <strong>' . $fld . '</strong> and items on page: <strong>' . $daftar_berkas[1] . '</strong>.<select style="float:right;" id="pilihBaris" onchange="gantiBaris(this, \'paginasi\');"><option value="5">5 rows/sheet</option><option value="10" selected="selected">10 rows/sheet</option> <option value="15">15 rows/sheet</option><option value="20">20 rows/sheet</option><option value="25">25 rows/sheet</option><option value="30">30 rows/sheet</option><option value="40">40 rows/sheet</option><option value="50">50 rows/sheet</option></select></p></div>'; echo $daftar_berkas[0]; } } elseif (isset($_POST['folder_pilian_file_gal'])) { $gdwpm_apiConfig['use_objects'] = true; $gdwpm_service = new GDWPMBantuan($gdwpm_opt_akun[1], $gdwpm_opt_akun[2], $gdwpm_opt_akun[3]); $fld = $_POST['folder_pilian_file_gal']; if (isset($_POST['pagetoken'])) { $daftar_berkas = $gdwpm_service->getFilesInFolder($fld, $_POST['pilmaxres'], $_POST['pagetoken'], 'gall'); } else { $daftar_berkas = $gdwpm_service->getFilesInFolder($fld, $_POST['pilmaxres'], null, 'gall'); } //array($daftarfile, $i, $totalhal, $halterlihat) if ($daftar_berkas[1] <= 0) { // total files < 1 if ($daftar_berkas[2] > 1) { // total halaman > 1 if ($daftar_berkas[3] == $daftar_berkas[2]) { echo '<div class="sukses_gal"><p style="text-align:center;"><img src="' . plugins_url('/images/animation/gdwpm_breaker_256.png', __FILE__) . '"><br/>This page is empty.</p></div>'; echo $daftar_berkas[0]; } else { echo '<div class="sukses_gal"><p style="text-align:center;"><img src="' . plugins_url('/images/animation/gdwpm_breaker_256.png', __FILE__) . '"><br/>Your request contains multiple pages, click the page number below.</p></div>'; echo $daftar_berkas[0]; } } else { echo '<div class="sukses_gal"><p style="text-align:center;"><img src="' . plugins_url('/images/animation/gdwpm_breaker_256.png', __FILE__) . '"><br/>This folder is empty.</p></div>'; } } else { echo '<div class="sukses_gal"><p>Folder ID: <strong>' . $fld . '</strong> and items on page: <strong>' . $daftar_berkas[1] . '</strong>.<select style="float:right;" id="pilihBaris_gal" onchange="gantiBaris(this, \'paginasi_gal\');"><option value="5">5 rows/sheet</option><option value="10" selected="selected">10 rows/sheet</option> <option value="15">15 rows/sheet</option><option value="20">20 rows/sheet</option><option value="25">25 rows/sheet</option><option value="30">30 rows/sheet</option><option value="40">40 rows/sheet</option><option value="50">50 rows/sheet</option></select></p></div>'; echo $daftar_berkas[0]; } } elseif (isset($_POST['folder_pilian_file_del'])) { $gdwpm_apiConfig['use_objects'] = true; $gdwpm_service = new GDWPMBantuan($gdwpm_opt_akun[1], $gdwpm_opt_akun[2], $gdwpm_opt_akun[3]); $fld = $_POST['folder_pilian_file_del']; if (isset($_POST['pagetoken'])) { $daftar_berkas = $gdwpm_service->getFilesInFolder($fld, $_POST['pilmaxres'], $_POST['pagetoken'], 'checkbox'); } else { $daftar_berkas = $gdwpm_service->getFilesInFolder($fld, $_POST['pilmaxres'], null, 'checkbox'); } $daftarfile = $daftar_berkas[0]; $i = $daftar_berkas[1]; if ($daftar_berkas[1] <= 0) { if ($daftar_berkas[2] > 1) { // total halaman > 1 if ($daftar_berkas[3] == $daftar_berkas[2]) { echo '<div class="sukses_del"><p style="text-align:center;"><img src="' . plugins_url('/images/animation/gdwpm_breaker_256.png', __FILE__) . '"><br/>This page is empty.</p></div>'; echo $daftarfile; } else { echo '<div class="sukses_del"><p style="text-align:center;"><img src="' . plugins_url('/images/animation/gdwpm_breaker_256.png', __FILE__) . '"><br/>Your request contains multiple pages, click the page number below.</p></div>'; echo $daftarfile; } } else { echo '<div class="sukses_del"><p style="text-align:center;"><img src="' . plugins_url('/images/animation/gdwpm_breaker_256.png', __FILE__) . '"><br/>This folder is empty.</p></div>'; } } else { echo '<div class="sukses_del"><p>Folder ID: <strong>' . $fld . '</strong> and items on page: <strong>' . $i . '</strong>.</p></div>'; echo $daftarfile; } } elseif (isset($_POST['dataimages'])) { // insert gallery $unikid = strtotime("now"); $postjudul = base64_decode($_POST['judul']); $postkat = base64_decode($_POST['album']); $postkontenarr = explode(' , ', $_POST['dataimages']); //$postkonten = "<div class='gdwpmgallery'>"; //lightbox //$postkonten = '<div class="fotorama" data-allowfullscreen="native" data-loop="true" data-autoplay="true">'; //fotorama if (isset($_POST['css_effect'])) { $css_effect = $_POST['css_effect']; //default/blackwhite/lighthover } else { $css_effect = 'default'; } switch ($css_effect) { case "default": $efekgbr = ''; break; case "blackwhite": $efekgbr = ' gdwpm-bwefek'; break; case "lighthover": $efekgbr = ' gdwpm-lightefek'; break; default: $efekgbr = ''; } if (isset($_POST['css_style'])) { $css_style = $_POST['css_style']; //default/blackwhite/lighthover } else { $css_style = 'default'; } $jmlkolom = 3; $justproper = '1 | 90 | justify'; if ($css_style == 'justified') { if (isset($_POST['css_style_justified'])) { $justproper = $_POST['css_style_justified']; } $postkonten = '<div id="gdwpmgal-' . $unikid . '" class="gdwpmGallery1' . $efekgbr . '" data-gal1="' . $justproper . '">'; //Justified + lightbox $dataSource = array(); foreach ($postkontenarr as $key => $val) { // id, thumbid, flnme | captionimg $indidata = explode(' | ', $val); $indidatadecode = json_decode(base64_decode($indidata[0]), true); $captionimg = base64_decode($indidata[1]); if ($key == 0) { $sampleImage = $indidatadecode[1]; } //$dataSource[] = array($indidatadecode[0], $indidatadecode[1]) . ' | ' . $captionimg; //$postkonten .= '<div class="galleryItem"><a href="//www.googledrive.com/host/'.$indidatadecode[0].'" data-lightbox="'.$unikid.'" data-title="'.$captionimg.'"><img src="//www.googledrive.com/host/'.$thumbId.'" alt="'.$indidatadecode[1].'"/></a></div>'; //lightbox //$postkonten .= '<a href="//www.googledrive.com/host/'.$thumbId.'" data-full="//www.googledrive.com/host/'.$indidatadecode[0].'" data-caption="'.$captionimg.'"></a>'; //fotorama $boxttl = ''; $jusalt = ''; if (!empty($captionimg)) { $boxttl = 'data-title="' . $captionimg . '" '; $jusalt = 'alt="' . $captionimg . '" '; } $postkonten .= '<a href="https://www.googledrive.com/host/' . $indidatadecode[0] . '" ' . $boxttl . 'data-lightbox="' . $unikid . '"><img ' . $jusalt . 'src="https://www.googledrive.com/host/' . $indidatadecode[1] . '" /></a>'; //justified } } else { if (isset($_POST['css_style_default'])) { $jmlkolom = $_POST['css_style_default']; } $postkonten = '<div class="gdwpmGallery0' . $efekgbr . ' gallery gallery-columns-' . $jmlkolom . '">'; $dataSource = array(); foreach ($postkontenarr as $key => $val) { // id, thumbid, flnme | captionimg $indidata = explode(' | ', $val); $indidatadecode = json_decode(base64_decode($indidata[0]), true); $captionimg = base64_decode($indidata[1]); if ($key == 0) { $sampleImage = $indidatadecode[1]; } $postkonten .= '<dl style="width:' . 100 / $jmlkolom . '%;" class="gallery-item"><dt class="gallery-icon"><a href="https://www.googledrive.com/host/' . $indidatadecode[0] . '" data-lightbox="' . $unikid . '" data-title="' . $captionimg . '"><img class="attachment-thumbnail img-rounded" src="https://www.googledrive.com/host/' . $indidatadecode[1] . '" alt="' . $indidatadecode[2] . '" width="200" /></a></dt><dd class="wp-caption-text gallery-caption">' . $captionimg . '</dd></dl>'; if ($key > 0 && ($key + 1) % $jmlkolom == 0 || $key == count($postkontenarr) - 1) { $postkonten .= '<br style="clear: both" />'; } } } $postkonten .= '</div>'; //$postkonten = base64_decode($_POST['dataimages']); $gallery = array('post_title' => wp_strip_all_tags($postjudul), 'post_name' => sanitize_title_with_dashes($postjudul), 'post_content' => $postkonten, 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'gdwpm_galleries'); if (empty($_POST['galid']) || $_POST['galid'] == '') { $galeri_id = wp_insert_post($gallery); $infokita = 'created'; } else { $gallery['ID'] = $_POST['galid']; $galeri_id = wp_update_post($gallery); $infokita = 'saved'; } if ($galeri_id != 0) { wp_set_object_terms($galeri_id, $postkat, 'gdwpm_album'); update_post_meta($galeri_id, 'sampleImage', $sampleImage); $baseData = base64_encode(json_encode(array($galeri_id, wp_strip_all_tags($postjudul), $postkat, $css_style, $css_effect, 'lightbox', $jmlkolom, $justproper))); $baseData .= ' items:' . $_POST['dataimages']; update_post_meta($galeri_id, 'base64data', $baseData); echo '<strong>' . $postjudul . '</strong> successfully ' . $infokita . '. Gallery ID: <strong>' . $galeri_id . '</strong>. Shortcode: <code>[gdwpm-gallery id="' . $galeri_id . '"]</code>. Permalink: <a href="' . get_permalink($galeri_id) . '" title="Open ' . $postjudul . ' in new window" target="_blank">' . get_permalink($galeri_id) . '</a>'; } else { echo 'Cannot create gallery.'; } } elseif (isset($_POST['masuk_perpus'])) { //$gdwpm_berkas_terpilih_arr = explode(' | ', $_POST['masuk_perpus']); $gdwpm_berkas_terpilih_arr = json_decode(base64_decode($_POST['masuk_perpus']), true); gdwpm_ijin_masuk_perpus(sanitize_mime_type($gdwpm_berkas_terpilih_arr[0]), $gdwpm_berkas_terpilih_arr[1], $gdwpm_berkas_terpilih_arr[2], $gdwpm_berkas_terpilih_arr[3], $gdwpm_berkas_terpilih_arr[4], $gdwpm_berkas_terpilih_arr[5]); echo '<strong>' . $gdwpm_berkas_terpilih_arr[1] . '</strong> has been added to your Media Library'; } elseif (isset($_POST['gdwpm_ukuran_preview_lebar']) || isset($_POST['gdwpm_ukuran_preview_tinggi'])) { $nonce = $_REQUEST['gdwpm_override_nonce']; if (!wp_verify_nonce($nonce, 'gdwpm_override_dir')) { wp_die('<strong>Oops... failed!</strong>'); } else { if (!$gdwpm_ukuran_preview) { $gdwpm_ukuran_preview = get_option('gdwpm_ukuran_preview'); } if (ctype_digit($_POST['gdwpm_ukuran_preview_lebar']) && ctype_digit($_POST['gdwpm_ukuran_preview_tinggi'])) { if ($_POST['gdwpm_ukuran_preview_lebar'] > 20 && $_POST['gdwpm_ukuran_preview_tinggi'] > 10) { if ($_POST['gdwpm_cekbok_embed_video'] == 'checked') { if (isset($_POST['gdwpm_video_play_style']) && $_POST['gdwpm_ukuran_video_lebar'] > 20 && $_POST['gdwpm_ukuran_video_tinggi'] > 20 && ctype_digit($_POST['gdwpm_ukuran_video_lebar']) && ctype_digit($_POST['gdwpm_ukuran_video_tinggi'])) { $gdwpm_ukuran_prev_arr = array($_POST['gdwpm_ukuran_preview_lebar'], $_POST['gdwpm_ukuran_preview_tinggi'], $_POST['gdwpm_cekbok_embed_video'], $_POST['gdwpm_video_play_style'], $_POST['gdwpm_ukuran_video_lebar'], $_POST['gdwpm_ukuran_video_tinggi']); update_option('gdwpm_ukuran_preview', $gdwpm_ukuran_prev_arr); echo '<div id="info">Option saved.</div><div id="hasil">[gdwpm id="<b>YOURGOOGLEDRIVEFILEID</b>" w="<b>' . $gdwpm_ukuran_prev_arr[0] . '</b>" h="<b>' . $gdwpm_ukuran_prev_arr[1] . '</b>"]</div><div id="hasilvid">[gdwpm id="<b>YOURGOOGLEDRIVEFILEID</b>" video="<b>' . $gdwpm_ukuran_prev_arr[3] . '</b>" w="<b>' . $gdwpm_ukuran_prev_arr[4] . '</b>" h="<b>' . $gdwpm_ukuran_prev_arr[5] . '</b>"]</div>'; } else { echo '<div id="info"><strong>Warning:</strong> Minimum value is 20.</div><div id="hasil">[gdwpm id="GOOGLEDRIVEFILEID" w="<b>' . $gdwpm_ukuran_preview[0] . '</b>" h="<b>' . $gdwpm_ukuran_preview[1] . '</b>"]</div>'; } } else { $gdwpm_ukuran_prev_arr = array($_POST['gdwpm_ukuran_preview_lebar'], $_POST['gdwpm_ukuran_preview_tinggi'], $_POST['gdwpm_cekbok_embed_video'], $gdwpm_ukuran_preview[3], $gdwpm_ukuran_preview[4], $gdwpm_ukuran_preview[5]); update_option('gdwpm_ukuran_preview', $gdwpm_ukuran_prev_arr); echo '<div id="info">Option saved.</div><div id="hasil">[gdwpm id="<b>YOURGOOGLEDRIVEFILEID</b>" w="<b>' . $gdwpm_ukuran_prev_arr[0] . '</b>" h="<b>' . $gdwpm_ukuran_prev_arr[1] . '</b>"]</div>'; } } else { echo '<div id="info"><strong>Warning:</strong> Minimum value is 10.</div><div id="hasil">[gdwpm id="GOOGLEDRIVEFILEID" w="<b>' . $gdwpm_ukuran_preview[0] . '</b>" h="<b>' . $gdwpm_ukuran_preview[1] . '</b>"]</div>'; } } else { echo '<div id="info"><strong>Warning:</strong> Numeric only please.</div><div id="hasil">[gdwpm id="GOOGLEDRIVEFILEID" w="<b>' . $gdwpm_ukuran_preview[0] . '</b>" h="<b>' . $gdwpm_ukuran_preview[1] . '</b>"]</div>'; } } } elseif (isset($_POST['gdwpm_cekbok_opsi_value'])) { $nonce = $_REQUEST['gdwpm_override_nonce']; if (!wp_verify_nonce($nonce, 'gdwpm_override_dir')) { wp_die('<strong>Oops... failed!</strong>'); } else { $folder_bawaan = preg_replace("/[^a-zA-Z0-9]+/", " ", $_POST['gdwpm_folder_opsi_value']); $folder_bawaan = sanitize_text_field($folder_bawaan); if (empty($folder_bawaan) && $_POST['gdwpm_cekbok_opsi_value'] == 'checked') { echo 'Folder name cannot be empty!'; } else { $gdwpm_cekbok = array($_POST['gdwpm_cekbok_opsi_value'], $folder_bawaan, $_POST['gdwpm_cekbok_masukperpus_override']); update_option('gdwpm_override_dir_bawaan', $gdwpm_cekbok); echo 'Option saved.'; } } } elseif (isset($_POST['gdwpm_cekbok_opsi_dummy'])) { $nonce = $_REQUEST['gdwpm_override_nonce']; if (!wp_verify_nonce($nonce, 'gdwpm_override_dir')) { die('<strong>Oops... failed!</strong>'); } else { update_option('gdwpm_dummy_folder', $_POST['gdwpm_cekbok_opsi_dummy']); echo 'Option saved.'; } } elseif (isset($_REQUEST['gdwpm_tabulasi'])) { if ($_REQUEST['gdwpm_tabulasi'] == 'opsyen') { $nonce = $_REQUEST['gdwpm_tab_opsi_nonce']; if (!wp_verify_nonce($nonce, 'gdwpm_tab_opsi_key')) { wp_die('<div class="error"><p>Oops.. security check is not ok!</p></div>'); } else { require_once 'google-drive-wp-media-options.php'; } } elseif ($_REQUEST['gdwpm_tabulasi'] == 'infosyen') { $nonce = $_REQUEST['gdwpm_tab_info_nonce']; if (!wp_verify_nonce($nonce, 'gdwpm_tab_opsi_key')) { wp_die('<div class="error"><p>Oops.. security check is not ok!</p></div>'); } else { require_once 'google-drive-wp-media-info.php'; } } elseif ($_REQUEST['gdwpm_tabulasi'] == 'apidoku') { $nonce = $_REQUEST['gdwpm_tabulasi_nonce']; if (!wp_verify_nonce($nonce, 'gdwpm_tabulasi_ajax')) { wp_die('<div class="error"><p>Oops.. security check is not ok!</p></div>'); } else { require_once 'google-drive-wp-media-documentation.php'; } } elseif ($_REQUEST['gdwpm_tabulasi'] == 'themeset') { $nonce = $_REQUEST['gdwpm_tabulasi_themeset_nonce']; if (!wp_verify_nonce($nonce, 'gdwpm_tabulasi_themeset_nonce')) { wp_die('<div class="error"><p>Oops.. security check is not ok!</p></div>'); } else { require_once 'google-drive-wp-media-themes.php'; } } elseif ($_REQUEST['gdwpm_tabulasi'] == 'albums') { $nonce = $_REQUEST['gdwpm_tabulasi_albums_nonce']; if (!wp_verify_nonce($nonce, 'gdwpm_tabulasi_albums_nonce')) { wp_die('<div class="error"><p>Oops.. security check is not ok!</p></div>'); } else { require_once 'google-drive-wp-media-albums.php'; } } elseif ($_REQUEST['gdwpm_tabulasi'] == 'galleries') { $nonce = $_REQUEST['gdwpm_tabulasi_galleries_nonce']; if (!wp_verify_nonce($nonce, 'gdwpm_tabulasi_galleries_nonce')) { wp_die('<div class="error"><p>Oops.. security check is not ok.</p></div>'); } else { if (isset($_REQUEST['paged'])) { $paged = $_REQUEST['paged']; } if (isset($_REQUEST['delete'])) { $gdwpmbuang_gal = wp_delete_post(trim($_REQUEST['delete']), true); if ($gdwpmbuang_gal) { echo '<div class="updated"><p>Gallery ID="' . $_REQUEST['delete'] . '" successfully deleted.</p></div>'; } else { echo '<div class="error"><p>Gallery ID="' . $_REQUEST['delete'] . '" cannot deleted!</p></div>'; } } require_once 'google-drive-wp-media-galleries.php'; } } else { wp_die('<div class="error"><p>Oops.. something goes wrong!</p></div>'); } } elseif (isset($_POST['gdwpm_opsi_theme_css'])) { $nonce = $_REQUEST['gdwpm_theme_setting_nonce']; if (!wp_verify_nonce($nonce, 'gdwpm_theme_setting_nonce')) { die('<strong>Oops... failed!</strong>'); } else { update_option('gdwpm_nama_theme_css', $_POST['gdwpm_opsi_theme_css']); } } elseif (isset($_REQUEST['gdwpm_nonce_aplod_berkas'])) { $nonce = $_REQUEST['gdwpm_nonce_aplod_berkas']; if (!wp_verify_nonce($nonce, 'gdwpm_satpam_aplod_berkas')) { die('<div class="error"><p>Oops.. security check is not ok!</p></div>'); } else { if (empty($_FILES) || $_FILES["file"]["error"]) { wp_die('<div class="error"><p>Oops.. error, upload failed! ' . $_FILES["file"]["error"] . '</p></div>'); } if (isset($_REQUEST["gdpwm_nama_file"])) { $filename = $_REQUEST["gdpwm_nama_file"]; } elseif (!empty($_FILES)) { $filename = $_FILES["file"]["name"]; } else { $filename = uniqid("file_"); } //if(CHUNK_INTERNAL){ $gdwpm_opsi_chunk = get_option('gdwpm_opsi_chunk'); if ($gdwpm_opsi_chunk['local']['cekbok'] == 'checked') { $targetDir = ini_get("upload_tmp_dir"); $maxFileAge = 5 * 3600; // Temp file age in seconds // Create target dir if (!file_exists($targetDir)) { //@mkdir($targetDir); if (!file_exists($targetDir = sys_get_temp_dir())) { $upload_dir = wp_upload_dir(); if (!file_exists($targetDir = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'gdwpm-tmp')) { @mkdir($targetDir); } } } $filePath = $targetDir . DIRECTORY_SEPARATOR . $filename; // Chunking might be enabled $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0; $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0; if (!is_dir($targetDir) || !($dir = opendir($targetDir))) { die('<div class="error"><p>Oops.. error. Failed to open temp directory.</p></div>'); } while (($file = readdir($dir)) !== false) { $tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file; // If temp file is current file proceed to the next if ($tmpfilePath == "{$filePath}.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}.part", $chunks ? "ab" : "wb"))) { die('<div class="error"><p>Oops.. error. Failed to open output stream.</p></div>'); } if (!empty($_FILES)) { if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) { die('<div class="error"><p>Oops.. error. Failed to move uploaded file.</p></div>'); } // Read binary input stream and append it to temp file if (!($in = @fopen($_FILES["file"]["tmp_name"], "rb"))) { die('<div class="error"><p>Oops.. error. Failed to open input stream.</p></div>'); } } else { if (!($in = @fopen("php://input", "rb"))) { die('<div class="error"><p>Oops.. error. Failed to open input stream.</p></div>'); } } while ($buff = fread($in, 4096)) { fwrite($out, $buff); } @fclose($out); @fclose($in); } else { $chunks = true; } // Check if file has been uploaded if (!$chunks || $chunk == $chunks - 1) { // Strip the temp .part suffix off if ($filePath) { rename("{$filePath}.part", $filePath); } else { $filePath = $_FILES["file"]["tmp_name"]; } if (!$gdwpm_service) { $gdwpm_service = new GDWPMBantuan($gdwpm_opt_akun[1], $gdwpm_opt_akun[2], $gdwpm_opt_akun[3]); } $mime_berkas_arr = wp_check_filetype($filename); $mime_berkas = $mime_berkas_arr['type']; if (empty($mime_berkas)) { $mime_berkas = $_FILES['file']['type']; } $folder_ortu = preg_replace("/[^a-zA-Z0-9]+/", " ", $_POST['gdpwm_nm_br']); $folder_ortu = trim(sanitize_text_field($folder_ortu)); $folderId = $_POST['gdpwm_nm_id']; $nama_polder = $_POST['gdpwm_nm_bks']; if ($folder_ortu != '') { //cek folder array id namafolder $last_folder = get_option('gdwpm_new_folder_kecing'); if ($folder_ortu != $last_folder[1]) { $folderId = $gdwpm_service->getFolderIdByName($folder_ortu); if ($folderId) { update_option('gdwpm_new_folder_kecing', array($folderId, $folder_ortu)); } $nama_polder = $folder_ortu; } else { $folderId = $last_folder[0]; $nama_polder = $last_folder[1]; } } $content = $_POST['gdpwm_sh_ds']; if (!$folderId) { $folderId = $gdwpm_service->createFolder($folder_ortu); $gdwpm_service->setPermissions($folderId, $gdwpm_opt_akun[0]); update_option('gdwpm_new_folder_kecing', array($folderId, $nama_polder)); } if (strpos($mime_berkas_arr['type'], 'image') !== false) { // cek gambar if img auto create thumb .. array('checked', '', '122', '122', 'false'); $gdwpm_img_thumbs = get_option('gdwpm_img_thumbs'); // ITUNG DIMENSI $image = wp_get_image_editor($filePath); if (!is_wp_error($image)) { $ukuran_asli = $image->get_size(); // $ukuran_asli['width']; $ukuran_asli['height']; } $idthumb_w_h = ''; if ($gdwpm_img_thumbs[0] == 'checked') { $folderId_thumb = $gdwpm_img_thumbs[1]; if (empty($folderId_thumb) || $folderId_thumb == '') { //$folderId_thumb = $gdwpm_service->getFolderIdByName( 'gdwpm-thumbnails' ); //if(!$folderId_thumb){ $folderId_thumb = $gdwpm_service->createFolder('gdwpm-thumbnails'); $gdwpm_service->setPermissions($folderId_thumb, $gdwpm_opt_akun[0]); //} $gdwpm_img_thumbs[1] = trim($folderId_thumb); update_option('gdwpm_img_thumbs', $gdwpm_img_thumbs); } if ($ukuran_asli) { if ($gdwpm_img_thumbs[4] == 'true') { $image->resize($gdwpm_img_thumbs[2], $gdwpm_img_thumbs[3], true); } else { $image->resize($gdwpm_img_thumbs[2], $gdwpm_img_thumbs[3], false); } $img = $image->save(); // path, file, mime-type $filename_thumb = $img['file']; $filePath_thumb = $img['path']; $mime_berkas_thumb = $img['mime-type']; $imgwidth_thumb = $img['width']; $imgheight_thumb = $img['height']; } $fileParent_thumb = new Google_ParentReference(); $fileParent_thumb->setId($folderId_thumb); $fileId_thumb = $gdwpm_service->createFileFromPath($filePath_thumb, $filename_thumb, $content, $fileParent_thumb); $gdwpm_service->setPermissions($fileId_thumb, 'me', 'reader', 'anyone'); $idthumb_w_h = 'thumbId:' . $fileId_thumb . ' thumbWidth:' . $imgwidth_thumb . ' thumbHeight:' . $imgheight_thumb; } $gdwpm_sizez_meta = 'selfWidth:' . $ukuran_asli['width'] . ' selfHeight:' . $ukuran_asli['height'] . ' ' . $idthumb_w_h; @unlink($filename_thumb); } else { $gdwpm_sizez_meta = ''; } $fileParent = new Google_ParentReference(); $fileParent->setId($folderId); //$fileId = $gdwpm_service->createFileFromPath( $_FILES["file"]["tmp_name"], $filename, $content, $fileParent ); $fileId = $gdwpm_service->createFileFromPath($filePath, $filename, $content, $fileParent); if ($fileId) { $gdwpm_service->setPermissions($fileId, 'me', 'reader', 'anyone'); if (strpos($mime_berkas_arr['type'], 'image') !== false && !empty($gdwpm_sizez_meta)) { $gdwpm_service->insertProperty($fileId, 'gdwpm-sizes', $gdwpm_sizez_meta); } $sukinfo = ''; $metainfo = ''; if (!empty($mime_berkas) && isset($_POST['gdpwm_med_ly']) == '1') { /* if(strpos($mime_berkas_arr['type'], 'video') !== false){ $gdwpm_meta_arr = wp_read_video_metadata( $filePath ); $metainfo = json_encode($gdwpm_meta_arr); }elseif(strpos($mime_berkas_arr['type'], 'audio') !== false){ $gdwpm_meta_arr = wp_read_audio_metadata( $filePath ); $metainfo = json_encode($gdwpm_meta_arr); }elseif(strpos($mime_berkas_arr['type'], 'image') !== false){ $gdwpm_meta_arr = wp_read_image_metadata( $filePath ); $metainfo = json_encode($gdwpm_meta_arr); } */ gdwpm_ijin_masuk_perpus($mime_berkas, $filename, $fileId, $content, $nama_polder, $gdwpm_sizez_meta, $metainfo); $sukinfo = ' and added into your Media Library'; } echo '<div class="updated"><p>' . $filename . ' (<strong>' . $fileId . '</strong>) successfully uploaded to <strong>' . $nama_polder . '</strong>' . $sukinfo . '.</p></div>'; } else { echo '<div class="error"><p>Failed to upload <strong>' . $filename . '</strong> to Google Drive.</p></div>'; } @unlink($filePath); } wp_die(); } } wp_die(); }
/** * AJAX - Plupload execution routines * @since 1.2.2 * @package themify */ function themify_plupload() { $imgid = $_POST['imgid']; check_ajax_referer($imgid . 'themify-plupload'); /** Check whether this image should be set as a preset. @var String */ $haspreset = isset($_POST['haspreset']) ? $_POST['haspreset'] : ''; /** Decide whether to send this image to Media. @var String */ $add_to_media_library = isset($_POST['tomedia']) ? $_POST['tomedia'] : false; /** If post ID is set, uploaded image will be attached to it. @var String */ $postid = isset($_POST['topost']) ? $_POST['topost'] : ''; /** Handle file upload storing file|url|type. @var Array */ $file = wp_handle_upload($_FILES[$imgid . 'async-upload'], array('test_form' => true, 'action' => 'themify_plupload')); //let's see if it's an image, a zip file or something else $ext = explode('/', $file['type']); // Import routines if ('zip' == $ext[1] || 'rar' == $ext[1] || 'plain' == $ext[1]) { $url = wp_nonce_url('admin.php?page=themify'); $upload_dir = wp_upload_dir(); if (false === ($creds = request_filesystem_credentials($url))) { return true; } if (!WP_Filesystem($creds)) { request_filesystem_credentials($url, '', true); return true; } global $wp_filesystem; if ('zip' == $ext[1] || 'rar' == $ext[1]) { unzip_file($file['file'], THEME_DIR); if ($wp_filesystem->exists(THEME_DIR . '/data_export.txt')) { $data = $wp_filesystem->get_contents(THEME_DIR . '/data_export.txt'); themify_set_data(unserialize($data)); $wp_filesystem->delete(THEME_DIR . '/data_export.txt'); $wp_filesystem->delete($file['file']); } else { _e('Data could not be loaded', 'themify'); } } else { if ($wp_filesystem->exists($file['file'])) { $data = $wp_filesystem->get_contents($file['file']); themify_set_data(unserialize($data)); $wp_filesystem->delete($file['file']); } else { _e('Data could not be loaded', 'themify'); } } } else { //Image Upload routines if ('tomedia' == $add_to_media_library) { // Insert into Media Library // Set up options array to add this file as an attachment $attachment = array('post_mime_type' => sanitize_mime_type($file['type']), 'post_title' => str_replace('-', ' ', sanitize_file_name(pathinfo($file['file'], PATHINFO_FILENAME))), 'post_status' => 'inherit'); if ($postid) { $attach_id = wp_insert_attachment($attachment, $file['file'], $postid); } else { $attach_id = wp_insert_attachment($attachment, $file['file']); } // Common attachment procedures require_once ABSPATH . "wp-admin" . '/includes/image.php'; $attach_data = wp_generate_attachment_metadata($attach_id, $file['file']); wp_update_attachment_metadata($attach_id, $attach_data); if ($postid) { $full = wp_get_attachment_image_src($attach_id, 'full'); if ($_POST['featured']) { //Set the featured image for the post set_post_thumbnail($postid, $attach_id); } update_post_meta($postid, $_POST['fields'], $full[0]); update_post_meta($postid, '_' . $_POST['fields'] . '_attach_id', $attach_id); $thumb = wp_get_attachment_image_src($attach_id, 'thumbnail'); //Return URL for the image field in meta box $file['thumb'] = $thumb[0]; } } /** * Presets like backgrounds and such */ if ('haspreset' == $haspreset) { // For the sake of predictability, we're not adding this to Media. $presets = get_option('themify_background_presets'); $presets[$file['file']] = $file['url']; update_option('themify_background_presets', $presets); /*$presets_attach_id = get_option('themify_background_presets_attach_id'); $presets_attach_id[ $file['file'] ] = $attach_id; update_option('themify_background_presets_attach_id', $presets_attach_id);*/ } } $file['type'] = $ext[1]; // send the uploaded file url in response echo json_encode($file); exit; }
/** * Update an MLA Upload MIME Type object * * @since 1.40 * * @param array Query variables for new object values, including optional original_slug * * @return array Message(s) reflecting the results of the operation */ public static function mla_update_upload_mime($request) { if (self::_get_upload_mime_templates()) { $errors = ''; } else { return array('message' => 'ERROR: Cannot load Upload MIME Types', 'body' => ''); } $messages = ''; $slug = pathinfo('X.' . strtolower(trim($request['slug'])), PATHINFO_EXTENSION); $original_slug = isset($request['original_slug']) ? $request['original_slug'] : $slug; unset($request['original_slug']); if (isset(self::$mla_upload_mime_templates[$original_slug])) { $original_type = self::$mla_upload_mime_templates[$original_slug]; } else { $original_type = array('post_ID' => 0, 'mime_type' => '', 'core_type' => '', 'mla_type' => '', 'source' => '', 'standard_source' => '', 'disabled' => false, 'description' => '', 'wp_icon_type' => '', 'mla_icon_type' => '', 'icon_type' => '', 'core_icon_type' => ''); } /* * Validate changed slug value */ if ($slug != $original_slug) { if ($slug != $request['slug']) { $messages .= sprintf('<br>Changing new extension "%1$s" to valid value "%2$s"', $request['slug'], $slug); } /* * Make sure new slug is unique */ if (isset(self::$mla_upload_mime_templates[$slug])) { $errors .= sprintf('<br>ERROR: Could not add new extension "%1$s"; value already exists', $slug); } else { $messages .= sprintf('<br>Changing extension from "%1$s" to "%2$s"', $original_slug, $slug); } /* * A new extension cannot have an $original_type */ $original_type = array('post_ID' => 0, 'mime_type' => '', 'core_type' => '', 'mla_type' => '', 'source' => '', 'standard_source' => '', 'disabled' => false, 'description' => '', 'icon_type' => '', 'wp_icon_type' => '', 'mla_icon_type' => '', 'core_icon_type' => ''); } /* * Validate mime_type */ if (empty($request['mime_type'])) { $clean_mime_type = $original_type['mime_type']; } else { $clean_mime_type = sanitize_mime_type($request['mime_type']); if ($clean_mime_type != $request['mime_type']) { $errors .= sprintf('<br>ERROR: Bad MIME type; try "%1$s"', $clean_mime_type); } } if (!empty($errors)) { return array('message' => substr($errors . $messages, 4), 'body' => ''); } $new_type = array(); if (0 == $original_type['post_ID']) { $new_type['post_ID'] = ++self::$mla_upload_mime_highest_ID; } else { $new_type['post_ID'] = $original_type['post_ID']; } $new_type['mime_type'] = $clean_mime_type; $new_type['core_type'] = $original_type['core_type']; $new_type['mla_type'] = $original_type['mla_type']; /* * Determine the source */ if ('core' == $original_type['standard_source'] && $clean_mime_type == $original_type['core_type']) { $new_type['source'] = 'core'; } elseif ('mla' == $original_type['standard_source'] && $clean_mime_type == $original_type['mla_type']) { $new_type['source'] = 'mla'; } else { $new_type['source'] = 'custom'; } /* * Determine new icon types */ $new_type['core_icon_type'] = self::mla_get_core_icon_type($slug); if (isset($request['icon_type'])) { $new_type['icon_type'] = '.none.' == $request['icon_type'] ? 'default' : $request['icon_type']; } elseif (!empty($original_type['icon_type'])) { $new_type['icon_type'] = $original_type['icon_type']; } else { $new_type['icon_type'] = $new_type['core_icon_type']; } if (!empty($original_type['wp_icon_type'])) { $new_type['wp_icon_type'] = $original_type['wp_icon_type']; } else { $new_type['wp_icon_type'] = $new_type['icon_type']; } if (!empty($original_type['mla_icon_type'])) { $new_type['mla_icon_type'] = $original_type['mla_icon_type']; } else { $new_type['mla_icon_type'] = $new_type['icon_type']; } $new_type['standard_source'] = $original_type['standard_source']; $new_type['disabled'] = isset($request['disabled']) ? $request['disabled'] : $original_type['disabled']; $new_type['description'] = isset($request['description']) ? sanitize_text_field($request['description']) : $original_type['description']; if ($slug == $original_slug && self::$mla_upload_mime_templates[$slug] == $new_type) { return array('message' => substr($messages . sprintf('<br>Edit type "%1$s"; no changes detected', $slug), 4), 'body' => ''); } self::$mla_upload_mime_templates[$slug] = $new_type; if ($slug != $original_slug) { unset(self::$mla_upload_mime_templates[$original_slug]); } if (self::_put_upload_mime_templates()) { return array('message' => substr($messages . sprintf('<br>Edit type "%1$s"; updated', $slug), 4), 'body' => ''); } return array('message' => 'ERROR: Cannot update Upload MIME Types', 'body' => ''); }
/** * Attempt to download a remote files attachments * * @param bool $images * @param array $args * * @return bool|object */ public static function image_fetch($images = false, $args = array()) { $images = array_filter((array) $images); //** Image URLs may be passed as string or array, or none at all */ if (count($images) < 1) { return false; } self::timer_start(__METHOD__); $args = wp_parse_args($args, array('upload_dir' => false, 'timeout' => 30)); /** * Regular Image Download. */ foreach ((array) $images as $count => $url) { $url = esc_url_raw($url); $_image = array('source_url' => $url, 'error' => false); //** Set correct filename ( some URLs can have not valid file extensions ) */ $filename = sanitize_file_name(basename($url)); $ext = false; $filetype = wp_check_filetype($filename); if (!$filetype['ext']) { $file_headers = get_headers($url, 1); if (strpos($file_headers[0], '200 OK')) { if (isset($file_headers['Content-Type'])) { $file_mime = sanitize_mime_type($file_headers['Content-Type']); switch ($file_mime) { case "image/gif": $ext = 'gif'; break; case "image/jpeg": $ext = 'jpg'; break; case "image/png": $ext = 'png'; break; case "image/bmp": $ext = 'bmp'; break; } if ($ext) { $filename .= '.' . $ext; } } } } else { $ext = $filetype['ext']; } $_wp_error_data = array('url' => $url, 'filename' => $filename, 'file_type' => $ext); //** We MUST NOT allow to upload not-image files */ if (!$ext || !in_array($ext, array('gif', 'jpg', 'png', 'bmp', 'jpeg'))) { $_image['error'] = new WP_Error(__METHOD__, __('Invalid file type.', self::$text_domain), $_wp_error_data); } //** Set file path */ if (!empty($args['upload_dir'])) { if (wp_mkdir_p($args['upload_dir'])) { $_image['file'] = trailingslashit($args['upload_dir']) . wp_unique_filename($args['upload_dir'], $filename); } else { $_image['error'] = new WP_Error(__METHOD__, __('Could not create mentioned directory.', self::$text_domain)); } } else { $wp_upload_bits = wp_upload_bits($filename, null, ''); if ($wp_upload_bits['error']) { $_image['error'] = new WP_Error(__METHOD__, $wp_upload_bits['error'], $wp_upload_bits); } $_image = self::extend($_image, $wp_upload_bits); } if (!is_wp_error($_image['error'])) { $wp_remote_request = wp_remote_request($url, array_filter(array('method' => 'GET', 'timeout' => $args['timeout'], 'stream' => true, 'filename' => $_image['file']))); if (is_wp_error($wp_remote_request)) { $wp_remote_request->add_data($_wp_error_data); $_image['error'] = $wp_remote_request; } else { $_image['file'] = $wp_remote_request['filename']; $_image['filesize'] = filesize($_image['file']); /* Disabled. Was failing multiple images if( isset( $wp_remote_request[ 'headers' ][ 'content-length'] ) && $_image[ 'filesize' ] != $wp_remote_request[ 'headers' ][ 'content-length'] ) { $_image[ 'error' ] = new WP_Error( 'image_fetch', __( 'Remote file has incorrect size', self::$text_domain ), array( 'headers' => $wp_remote_request[ 'headers' ], 'image' => $_image )); }*/ if (0 == $_image['filesize']) { $_image['error'] = new WP_Error(__METHOD__, __('Zero size file downloaded', self::$text_domain)); } $_image = self::extend($_image, wp_check_filetype($_image['file'])); //require_once( ABSPATH . 'wp-admin/includes/image.php' ); //wp_update_attachment_metadata( $row->attachment_id, wp_generate_attachment_metadata( $row->attachment_id, $upload[ 'file' ] ) ); } } if (is_wp_error($_image['error'])) { @unlink($_image['file']); } $return[$count] = (object) array_filter($_image); } //** End foreach */ return (object) array('images' => $return, 'timer' => self::timer_stop(__METHOD__)); }
/** * Analyze a Library View/Post MIME Type specification, returning an array of the placeholders it contains * * @since 1.40 * * @param string|array A specification, e.g., "custom:Field,null" or "audio,application/vnd.*ms*" * * @return array ( ['prefix'] => string, ['name'] => string, ['value'] => string, ['option'] => string, optional ['error'] => string ) */ public static function mla_parse_view_specification($specification) { if (is_array($specification)) { $specification = @implode(',', $specification); } $result = array('prefix' => '', 'name' => '', 'value' => '', 'option' => ''); $match_count = preg_match('/^(.+):(.+)/', $specification, $matches); if (1 == $match_count) { $result['prefix'] = trim(strtolower($matches[1])); $tail = $matches[2]; $match_count = preg_match('/([^,=]+)((,|=)(.*))$/', $tail, $matches); if (1 == $match_count) { $result['name'] = $matches[1]; if (',' == $matches[3]) { $result['option'] = trim(strtolower($matches[4])); } else { if (empty($matches[4])) { $result['option'] = 'null'; } elseif ('*' == $matches[4]) { $result['option'] = 'any'; } else { $result['option'] = 'match'; $result['value'] = $matches[4]; } } } else { $result['option'] = 'any'; $result['name'] = $tail; } } else { $result['prefix'] = 'mime'; $result['value'] = $specification; } /* * Validate the results */ if ('mime' == $result['prefix']) { $mime_types = array_map('trim', explode(',', $result['value'])); foreach ((array) $mime_types as $raw_mime_type) { $no_wildcards = str_replace('*', 'X', $raw_mime_type); $clean_mime_type = sanitize_mime_type($no_wildcards); if ($clean_mime_type != $no_wildcards) { /* translators: 1: ERROR tag 2: raw_mime_type */ $result['error'] = '<br>' . sprintf(__('%1$s: Bad specification part "%2$s"', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $raw_mime_type); } } // foreach } elseif ('custom' == $result['prefix']) { if (!in_array($result['option'], array('', 'any', 'match', 'null'))) { /* translators: 1: ERROR tag 2: option, e.g., any, match, null */ $result['error'] = '<br>' . sprintf(__('%1$s: Bad specification option "%2$s"', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $specification['option']); } } else { /* translators: 1: ERROR tag 2: prefix, e.g., custom */ $result['error'] = '<br>' . sprintf(__('%1$s: Bad specification prefix "%2$s"', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $specification['prefix']); } return $result; }
function hocwp_sanitize($data, $type) { switch ($type) { case 'media': return hocwp_sanitize_media_value($data); case 'text': return sanitize_text_field(trim($data)); case 'email': return sanitize_email(trim($data)); case 'file_name': return hocwp_sanitize_file_name($data); case 'html_class': $data = hocwp_remove_vietnamese($data); $data = hocwp_sanitize_id($data); $data = str_replace('_', '-', $data); return $data; case 'key': return sanitize_key($data); case 'mime_type': return sanitize_mime_type($data); case 'sql_orderby': return sanitize_sql_orderby($data); case 'slug': return sanitize_title($data); case 'title_for_query': return sanitize_title_for_query($data); case 'html_id': return hocwp_sanitize_id($data); case 'array': return hocwp_sanitize_array($data); default: return $data; } }
/** * Plupload ajax action */ function builder_plupload() { // check ajax nonce $imgid = $_POST['imgid']; check_ajax_referer($imgid . 'themify-builder-plupload'); /** If post ID is set, uploaded image will be attached to it. @var String */ $postid = $_POST['topost']; /** Handle file upload storing file|url|type. @var Array */ $file = wp_handle_upload($_FILES[$imgid . 'async-upload'], array('test_form' => true, 'action' => 'themify_builder_plupload_action')); //let's see if it's an image, a zip file or something else $ext = explode('/', $file['type']); // Insert into Media Library // Set up options array to add this file as an attachment $attachment = array('post_mime_type' => sanitize_mime_type($file['type']), 'post_title' => str_replace('-', ' ', sanitize_file_name(pathinfo($file['file'], PATHINFO_FILENAME))), 'post_status' => 'inherit'); if ($postid) { $attach_id = wp_insert_attachment($attachment, $file['file'], $postid); } // Common attachment procedures require_once ABSPATH . 'wp-admin' . '/includes/image.php'; $attach_data = wp_generate_attachment_metadata($attach_id, $file['file']); wp_update_attachment_metadata($attach_id, $attach_data); if ($postid) { $large = wp_get_attachment_image_src($attach_id, 'large'); $thumb = wp_get_attachment_image_src($attach_id, 'thumbnail'); //Return URL for the image field in meta box $file['large_url'] = $large[0]; $file['thumb'] = $thumb[0]; } $file['type'] = $ext[1]; // send the uploaded file url in response echo json_encode($file); exit; }