/** * Assemble the in-memory representation of the Upload MIME Types * * @since 1.40 * * @param boolean Force a reload/recalculation of types * @return boolean Success (true) or failure (false) of the operation */ private static function _get_upload_mime_templates($force_refresh = false) { self::_get_core_icon_types(); self::_get_current_icon_types(); if (false == $force_refresh && NULL != self::$mla_upload_mime_templates) { return true; } /* * Find the WordPress-standard (unfiltered) extensions */ global $wp_filter; if (isset($wp_filter['mime_types'])) { $save_filters = $wp_filter['mime_types']; unset($wp_filter['mime_types']); $core_types = wp_get_mime_types(); $wp_filter['mime_types'] = $save_filters; } else { $core_types = wp_get_mime_types(); } /* * If this is the first time MLA Upload support is invoked, match to the * filter-enhanced extensions, retain anything new as a custom type. */ $custom_types = array(); $mla_upload_mimes = MLAOptions::mla_get_option(MLAOptions::MLA_UPLOAD_MIMES); if (is_array($mla_upload_mimes)) { $first_time_called = false; $custom_types = $mla_upload_mimes['custom']; } else { $first_time_called = true; $mla_upload_mimes = array('custom' => array(), 'disabled' => array(), 'description' => array(), 'icon_type' => array()); self::$disable_mla_filtering = true; foreach (get_allowed_mime_types() as $key => $value) { if (!isset($core_types[$key])) { $custom_types[$key] = $value; } } self::$disable_mla_filtering = false; } /* * Explode any entries with multiple extensions */ foreach ($core_types as $key => $value) { if (false !== strpos($key, '|')) { unset($core_types[$key]); $extensions = explode('|', $key); foreach ($extensions as $extension) { $core_types[$extension] = $value; } } } foreach ($custom_types as $key => $value) { if (false !== strpos($key, '|')) { unset($custom_types[$key]); $extensions = explode('|', $key); foreach ($extensions as $extension) { $custom_types[$extension] = $value; } } } self::$mla_upload_mime_templates = array(); self::$mla_upload_mime_highest_ID = 0; /* * Start with the MLA extensions, initialized to an inactive state * Save the descriptions for use in _put_upload_mime_types() */ self::$mla_upload_mime_descriptions = array(); $template_array = MLAData::mla_load_template('mla-default-mime-types.tpl'); if (isset($template_array['mla-mime-types'])) { $mla_mime_types = preg_split('/[\\r\\n]+/', $template_array['mla-mime-types']); foreach ($mla_mime_types as $mla_type) { $array = explode(',', $mla_type); /* Anthony Martin debug * / if ( 4 > count( $array ) ) { trigger_error( sprintf( 'mla-default-mime-types.tpl $array = "%1$s".', var_export( $array, true ) ), E_USER_WARNING ); } // */ $key = strtolower($array[0]); self::$mla_upload_mime_descriptions[$key] = $array[4]; self::$mla_upload_mime_templates[$key] = array('post_ID' => ++self::$mla_upload_mime_highest_ID, 'mime_type' => $array[1], 'core_type' => '', 'mla_type' => $array[1], 'source' => 'mla', 'standard_source' => 'mla', 'disabled' => true, 'description' => $array[4], 'icon_type' => $array[2], 'wp_icon_type' => $array[2], 'mla_icon_type' => $array[3], 'core_icon_type' => self::mla_get_core_icon_type($array[0])); if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_ENABLE_MLA_ICONS)) { self::$mla_upload_mime_templates[$key]['icon_type'] = self::$mla_upload_mime_templates[$key]['mla_icon_type']; } } } /* * Add the WordPress-standard (unfiltered) extensions, initialized to an active state */ foreach ($core_types as $key => $value) { $key = strtolower($key); if (isset(self::$mla_upload_mime_templates[$key])) { $post_ID = self::$mla_upload_mime_templates[$key]['post_ID']; $mla_type = self::$mla_upload_mime_templates[$key]['mla_type']; $description = self::$mla_upload_mime_templates[$key]['description']; $icon_type = self::$mla_upload_mime_templates[$key]['icon_type']; $wp_icon_type = self::$mla_upload_mime_templates[$key]['wp_icon_type']; $mla_icon_type = self::$mla_upload_mime_templates[$key]['mla_icon_type']; $core_icon_type = self::$mla_upload_mime_templates[$key]['core_icon_type']; } else { $post_ID = ++self::$mla_upload_mime_highest_ID; $mla_type = ''; $description = ''; // if ( NULL == $icon_type = wp_ext2type( $key ) ) { // $icon_type = 'default'; // } $icon_type = self::mla_get_core_icon_type($key); $wp_icon_type = $icon_type; $mla_icon_type = $icon_type; $core_icon_type = $icon_type; //self::mla_get_core_icon_type( $key ); } self::$mla_upload_mime_templates[$key] = array('post_ID' => $post_ID, 'mime_type' => $value, 'core_type' => $value, 'mla_type' => $mla_type, 'source' => 'core', 'standard_source' => 'core', 'disabled' => false, 'description' => $description, 'icon_type' => $icon_type, 'wp_icon_type' => $wp_icon_type, 'mla_icon_type' => $mla_icon_type, 'core_icon_type' => $core_icon_type); if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_ENABLE_MLA_ICONS)) { self::$mla_upload_mime_templates[$key]['icon_type'] = self::$mla_upload_mime_templates[$key]['mla_icon_type']; } } /* * Add the user-defined custom types */ foreach ($custom_types as $key => $value) { $key = strtolower($key); if (isset(self::$mla_upload_mime_templates[$key])) { extract(self::$mla_upload_mime_templates[$key]); /* * Make sure it's really custom */ if ('core' == $source && $value == $core_type || 'mla' == $source && $value == $mla_type) { continue; } } else { // existing type $core_type = ''; $mla_type = ''; $standard_source = ''; } // brand new type if (NULL == ($icon_type = wp_ext2type($key))) { $icon_type = 'default'; } self::$mla_upload_mime_templates[$key] = array('post_ID' => ++self::$mla_upload_mime_highest_ID, 'mime_type' => $value, 'core_type' => $core_type, 'mla_type' => $mla_type, 'source' => 'custom', 'standard_source' => $standard_source, 'disabled' => false, 'description' => '', 'icon_type' => $icon_type, 'wp_icon_type' => $icon_type, 'mla_icon_type' => $icon_type, 'core_icon_type' => self::mla_get_core_icon_type($key)); } if ($first_time_called) { self::_put_upload_mime_templates(); return true; } /* * Apply the current settings, if any */ foreach (self::$mla_upload_mime_templates as $key => $value) { $default_description = isset(self::$mla_upload_mime_descriptions[$key]) ? self::$mla_upload_mime_descriptions[$key] : ''; self::$mla_upload_mime_templates[$key]['disabled'] = isset($mla_upload_mimes['disabled'][$key]); self::$mla_upload_mime_templates[$key]['description'] = isset($mla_upload_mimes['description'][$key]) ? $mla_upload_mimes['description'][$key] : $default_description; if (isset($mla_upload_mimes['icon_type'][$key])) { self::$mla_upload_mime_templates[$key]['icon_type'] = $mla_upload_mimes['icon_type'][$key]; } } return true; }