/** * Initialization function, similar to __construct() * * @since 0.60 * * @return void */ public static function initialize() { MLATest::$wp_3dot5 = version_compare(get_bloginfo('version'), '3.5.0', '>=') && version_compare(get_bloginfo('version'), '3.5.99', '<='); MLATest::$wp_4dot3_plus = version_compare(get_bloginfo('version'), '4.2.99', '>='); /* * This is the earliest effective place to change error_reporting */ MLACore::$original_php_log = ini_get('error_log'); MLACore::$original_php_reporting = sprintf('0x%1$04X', error_reporting()); $php_reporting = trim(MLACore::mla_get_option(MLACoreOptions::MLA_DEBUG_REPLACE_PHP_REPORTING)); if (!empty($php_reporting)) { @error_reporting(0 + $php_reporting); } /* * This is the earliest effective place to localize values in other plugin components */ MLACoreOptions::mla_localize_option_definitions_array(); if (class_exists('MLASettings')) { MLASettings::mla_localize_tablist(); } if (class_exists('MLAQuery')) { MLAQuery::mla_localize_default_columns_array(); } if (class_exists('MLA_Upload_List_Table')) { MLA_Upload_List_Table::mla_localize_default_columns_array(); } if (class_exists('MLA_Upload_Optional_List_Table')) { MLA_Upload_Optional_List_Table::mla_localize_default_columns_array(); } if (class_exists('MLA_View_List_Table')) { MLA_View_List_Table::mla_localize_default_columns_array(); } }
/** * Adds flat checklist taxonomy support to the Media Manager Modal Window. * Declared public because it is an action. * * @since 2.20 */ public static function mla_admin_init_action() { //error_log( 'DEBUG: MLA_Ajax::mla_admin_init_action() $_REQUEST = ' . var_export( $_REQUEST, true ), 0 ); /* * If there's no action variable, we have nothing more to do */ if (!isset($_POST['action'])) { return; } /* * For flat taxonomies that use the checklist meta box, substitute our own handler * for /wp-admin/includes/ajax-actions.php function _wp_ajax_add_hierarchical_term(). */ if (defined('DOING_AJAX') && DOING_AJAX && 'add-' == substr($_POST['action'], 0, 4)) { $key = substr($_POST['action'], 4); if (MLACore::mla_taxonomy_support($key, 'flat-checklist')) { self::_mla_ajax_add_flat_term($key); /* note: this function sends an Ajax response and then dies; no return */ } } add_action('wp_ajax_' . 'mla_find_posts', 'MLA_Ajax::mla_find_posts_ajax_action'); add_action('wp_ajax_' . MLACore::JAVASCRIPT_INLINE_EDIT_SLUG . '-set-parent', 'MLA_Ajax::mla_set_parent_ajax_action'); }
/** * WordPress Filter for edit taxonomy "Attachments" column, * which returns a count of the attachments assigned a given term * * @since 0.30 * * @param string current column value; filled in by earlier filter handlers * @param string name of the column * @param integer ID of the term for which the count is desired * * @return array HTML markup for the column content; number of attachments in the category * and alink to retrieve a list of them */ public static function mla_taxonomy_column_filter($current_value, $column_name, $term_id) { static $taxonomy = NULL, $tax_object = NULL, $count_terms = false, $terms = array(); /* * Do setup tasks once per page load */ if (NULL == $taxonomy) { /* * Adding or inline-editing a tag is done with AJAX, and there's no current screen object */ if (defined('DOING_AJAX') && DOING_AJAX) { $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag'; } else { $screen = get_current_screen(); $taxonomy = !empty($screen->taxonomy) ? $screen->taxonomy : 'post_tag'; } } $filter_content = apply_filters('mla_taxonomy_column', NULL, $current_value, $column_name, $term_id, $taxonomy); if (!empty($filter_content)) { return $filter_content; } if ('attachments' !== $column_name) { return $current_value; } /* * Do setup tasks once per page load */ if (NULL == $tax_object) { /* * Adding or inline-editing a tag is done with AJAX, and there's no current screen object */ if (defined('DOING_AJAX') && DOING_AJAX) { $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag'; } else { $screen = get_current_screen(); $taxonomy = !empty($screen->taxonomy) ? $screen->taxonomy : 'post_tag'; } $tax_object = get_taxonomy($taxonomy); $count_terms = 'checked' == MLACore::mla_get_option(MLACore::MLA_COUNT_TERM_ATTACHMENTS); if ($count_terms) { $terms = get_transient(MLA_OPTION_PREFIX . 't_term_counts_' . $taxonomy); if (!is_array($terms)) { /* * The MLAShortcodes class is only loaded when needed. */ if (!class_exists('MLAShortcodes')) { require_once MLA_PLUGIN_PATH . 'includes/class-mla-shortcodes.php'; } $cloud = MLAShortcodes::mla_get_terms(array('taxonomy' => $taxonomy, 'fields' => 't.term_id, t.name, t.slug, COUNT(p.ID) AS `count`', 'number' => 0, 'no_orderby' => true)); unset($cloud['found_rows']); foreach ($cloud as $term) { $terms[$term->term_id] = $term; } set_transient(MLA_OPTION_PREFIX . 't_term_counts_' . $taxonomy, $terms, 300); // five minutes } // build the array } // set $terms } // setup tasks if (isset($terms[$term_id])) { $term = $terms[$term_id]; $column_text = number_format_i18n($term->count); } else { $term = get_term($term_id, $taxonomy); if (is_wp_error($term)) { /* translators: 1: ERROR tag 2: taxonomy 3: error message */ error_log(sprintf(_x('%1$s: mla_taxonomy_column_filter( "%2$s" ) - get_term failed: "%3$s"', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $taxonomy, $term->get_error_message()), 0); return 0; } elseif ($count_terms) { $column_text = number_format_i18n(0); } else { $column_text = __('click to search', 'media-library-assistant'); } } return sprintf('<a href="%1$s">%2$s</a>', esc_url(add_query_arg(array('page' => MLACore::ADMIN_PAGE_SLUG, 'mla-tax' => $taxonomy, 'mla-term' => $term->slug, 'heading_suffix' => urlencode($tax_object->label . ':' . $term->name)), 'upload.php')), $column_text); }
/** * Retrieve the terms in one or more taxonomies. * * Alternative to WordPress /wp-includes/taxonomy.php function get_terms() that provides * an accurate count of attachments associated with each term. * * taxonomy - string containing one or more (comma-delimited) taxonomy names * or an array of taxonomy names. Default 'post_tag'. * * post_mime_type - MIME type(s) of the items to include in the term-specific counts. Default 'all'. * * post_type - The post type(s) of the items to include in the term-specific counts. * The default is "attachment". * * post_status - The post status value(s) of the items to include in the term-specific counts. * The default is "inherit". * * ids - A comma-separated list of attachment ID values for an item-specific cloud. * * include - An array, comma- or space-delimited string of term ids to include * in the return array. * * exclude - An array, comma- or space-delimited string of term ids to exclude * from the return array. If 'include' is non-empty, 'exclude' is ignored. * * parent - term_id of the terms' immediate parent; 0 for top-level terms. * * minimum - minimum number of attachments a term must have to be included. Default 0. * * no_count - 'true', 'false' (default) to suppress term-specific attachment-counting process. * * number - maximum number of term objects to return. Terms are ordered by count, * descending and then by term_id before this value is applied. Default 0. * * orderby - 'count', 'id', 'name' (default), 'none', 'random', 'slug' * * order - 'ASC' (default), 'DESC' * * no_orderby - 'true', 'false' (default) to suppress ALL sorting clauses else false. * * preserve_case - 'true', 'false' (default) to make orderby case-sensitive. * * pad_counts - 'true', 'false' (default) to to include the count of all children in their parents' count. * * limit - final number of term objects to return, for pagination. Default 0. * * offset - number of term objects to skip, for pagination. Default 0. * * @since 2.20 * * @param array taxonomies to search and query parameters * * @return array array of term objects, empty if none found */ public static function mla_get_terms($attr) { global $wpdb; /* * Make sure $attr is an array, even if it's empty */ if (empty($attr)) { $attr = array(); } elseif (is_string($attr)) { $attr = shortcode_parse_atts($attr); } /* * Merge input arguments with defaults */ $attr = apply_filters('mla_get_terms_query_attributes', $attr); $arguments = shortcode_atts(self::$mla_get_terms_parameters, $attr); $arguments = apply_filters('mla_get_terms_query_arguments', $arguments); /* * Build an array of individual clauses that can be filtered */ $clauses = array('fields' => '', 'join' => '', 'where' => '', 'order' => '', 'orderby' => '', 'limits' => ''); /* * If we're not counting attachments per term, strip * post fields out of list and adjust the orderby value */ if ($no_count = 'true' == (string) $arguments['no_count']) { $field_array = explode(',', $arguments['fields']); foreach ($field_array as $index => $field) { if (false !== strpos($field, 'p.')) { unset($field_array[$index]); } } $arguments['fields'] = implode(',', $field_array); $arguments['minimum'] = 0; $arguments['post_mime_type'] = 'all'; if ('count' == strtolower($arguments['orderby'])) { $arguments['orderby'] = 'none'; } } $clauses['fields'] = $arguments['fields']; $clause = array('INNER JOIN `' . $wpdb->term_taxonomy . '` AS tt ON t.term_id = tt.term_id'); $clause_parameters = array(); if (!$no_count) { $clause[] = 'LEFT JOIN `' . $wpdb->term_relationships . '` AS tr ON tt.term_taxonomy_id = tr.term_taxonomy_id'; $clause[] = 'LEFT JOIN `' . $wpdb->posts . '` AS p ON tr.object_id = p.ID'; /* * Add type and status constraints */ if (is_array($arguments['post_type'])) { $post_types = $arguments['post_type']; } else { $post_types = array($arguments['post_type']); } $placeholders = array(); foreach ($post_types as $post_type) { $placeholders[] = '%s'; $clause_parameters[] = $post_type; } $clause[] = 'AND p.post_type IN (' . join(',', $placeholders) . ')'; if (is_array($arguments['post_status'])) { $post_stati = $arguments['post_status']; } else { $post_stati = array($arguments['post_status']); } $placeholders = array(); foreach ($post_stati as $post_status) { if ('private' != $post_status || is_user_logged_in()) { $placeholders[] = '%s'; $clause_parameters[] = $post_status; } } $clause[] = 'AND p.post_status IN (' . join(',', $placeholders) . ')'; } $clause = join(' ', $clause); $clauses['join'] = $wpdb->prepare($clause, $clause_parameters); /* * Start WHERE clause with a taxonomy constraint */ if (is_array($arguments['taxonomy'])) { $taxonomies = $arguments['taxonomy']; } else { $taxonomies = array($arguments['taxonomy']); } foreach ($taxonomies as $taxonomy) { if (!taxonomy_exists($taxonomy)) { $error = new WP_Error('invalid_taxonomy', __('Invalid taxonomy', 'media-library-assistant'), $taxonomy); return $error; } } $clause_parameters = array(); $placeholders = array(); foreach ($taxonomies as $taxonomy) { $placeholders[] = '%s'; $clause_parameters[] = $taxonomy; } $clause = array('tt.taxonomy IN (' . join(',', $placeholders) . ')'); /* * The "ids" parameter can build an item-specific cloud. * Compile a list of all the terms assigned to the items. */ if (!empty($arguments['ids']) && empty($arguments['include'])) { $ids = wp_parse_id_list($arguments['ids']); $placeholders = implode("','", $ids); $clause[] = "AND p.ID IN ( '{$placeholders}' )"; $includes = array(); foreach ($ids as $id) { foreach ($taxonomies as $taxonomy) { $terms = get_the_terms($id, $taxonomy); if (is_array($terms)) { foreach ($terms as $term) { $includes[$term->term_id] = $term->term_id; } // terms } } // taxonomies } // ids /* * If there are no terms we want an empty cloud */ if (empty($includes)) { $arguments['include'] = (string) 0x7fffffff; } else { ksort($includes); $arguments['include'] = implode(',', $includes); } } /* * Add include/exclude and parent constraints to WHERE cluse */ if (!empty($arguments['include'])) { $placeholders = implode("','", wp_parse_id_list($arguments['include'])); $clause[] = "AND t.term_id IN ( '{$placeholders}' )"; } elseif (!empty($arguments['exclude'])) { $placeholders = implode("','", wp_parse_id_list($arguments['exclude'])); $clause[] = "AND t.term_id NOT IN ( '{$placeholders}' )"; } if ('' !== $arguments['parent']) { $parent = (int) $arguments['parent']; $clause[] = "AND tt.parent = '{$parent}'"; } if ('all' !== strtolower($arguments['post_mime_type'])) { $where = str_replace('%', '%%', wp_post_mime_type_where($arguments['post_mime_type'], 'p')); if (0 == absint($arguments['minimum'])) { $clause[] = ' AND ( p.post_mime_type IS NULL OR ' . substr($where, 6); } else { $clause[] = $where; } } $clause = join(' ', $clause); $clauses['where'] = $wpdb->prepare($clause, $clause_parameters); /* * For the inner/initial query, always select the most popular terms */ if ($arguments['no_orderby']) { $arguments['orderby'] = 'count'; $arguments['order'] = 'DESC'; } /* * Add sort order */ $orderby = strtolower($arguments['orderby']); $order = strtoupper($arguments['order']); if ('DESC' != $order) { $order = 'ASC'; } $clauses['order'] = $order; $clauses['orderby'] = "ORDER BY {$orderby}"; /* * Count, Descending, is the default order so no further work * is needed unless a different order is specified */ if ('count' != $orderby || 'DESC' != $order) { if ('true' == strtolower($arguments['preserve_case'])) { $binary_keys = array('name', 'slug'); } else { $binary_keys = array(); } $allowed_keys = array('empty_orderby_default' => 'name', 'count' => 'count', 'id' => 'term_id', 'name' => 'name', 'random' => 'RAND()', 'slug' => 'slug'); $clause = 'ORDER BY ' . self::_validate_sql_orderby($arguments, '', $allowed_keys, $binary_keys); $clauses['orderby'] = substr($clause, 0, strrpos($clause, ' ' . $order)); } // add ORDER BY /* * Add pagination */ $clauses['limits'] = ''; $offset = absint($arguments['offset']); $limit = absint($arguments['limit']); if (0 < $offset && 0 < $limit) { $clauses['limits'] = "LIMIT {$offset}, {$limit}"; } elseif (0 < $limit) { $clauses['limits'] = "LIMIT {$limit}"; } elseif (0 < $offset) { $clause_parameters = 0x7fffffff; $clauses['limits'] = "LIMIT {$offset}, {$clause_parameters}"; } $clauses = apply_filters('mla_get_terms_clauses', $clauses); /* * Build the final query */ $query = array('SELECT'); $query[] = $clauses['fields']; $query[] = 'FROM `' . $wpdb->terms . '` AS t'; $query[] = $clauses['join']; $query[] = 'WHERE ('; $query[] = $clauses['where']; $query[] = ') GROUP BY tt.term_taxonomy_id'; $clause_parameters = absint($arguments['minimum']); if (0 < $clause_parameters) { $query[] = "HAVING count >= {$clause_parameters}"; } /* * If specifically told to omit the ORDER BY clause or the COUNT, * supply a sort order for the initial/inner query only */ if (!($arguments['no_orderby'] || $no_count)) { $query[] = 'ORDER BY count DESC, t.term_id ASC'; } /* * Limit the total number of terms returned */ $terms_limit = absint($arguments['number']); if (0 < $terms_limit) { $query[] = "LIMIT {$terms_limit}"; } /* * $final_clauses, if present, require an SQL subquery */ $final_clauses = array(); if ('count' != $orderby || 'DESC' != $order) { $final_clauses[] = $clauses['orderby']; $final_clauses[] = $clauses['order']; } if ('' !== $clauses['limits']) { $final_clauses[] = $clauses['limits']; } /* * If we're limiting the final results, we need to get an accurate total count first */ if (!$no_count && (0 < $offset || 0 < $limit)) { $count_query = 'SELECT COUNT(*) as count FROM (' . join(' ', $query) . ' ) as subQuery'; $count = $wpdb->get_results($count_query); $found_rows = $count[0]->count; } if (!empty($final_clauses)) { if (!$no_count) { array_unshift($query, 'SELECT * FROM ('); $query[] = ') AS subQuery'; } $query = array_merge($query, $final_clauses); } $query = join(' ', $query); $tags = $wpdb->get_results($query); if (!isset($found_rows)) { $found_rows = $wpdb->num_rows; } if (self::$mla_debug) { MLACore::mla_debug_add('<strong>' . __('mla_debug query arguments', 'media-library-assistant') . '</strong> = ' . var_export($arguments, true)); MLACore::mla_debug_add('<strong>' . __('mla_debug last_query', 'media-library-assistant') . '</strong> = ' . var_export($wpdb->last_query, true)); MLACore::mla_debug_add('<strong>' . __('mla_debug last_error', 'media-library-assistant') . '</strong> = ' . var_export($wpdb->last_error, true)); MLACore::mla_debug_add('<strong>' . __('mla_debug num_rows', 'media-library-assistant') . '</strong> = ' . var_export($wpdb->num_rows, true)); MLACore::mla_debug_add('<strong>' . __('mla_debug found_rows', 'media-library-assistant') . '</strong> = ' . var_export($found_rows, true)); } if ('true' == strtolower(trim($arguments['pad_counts']))) { self::_pad_term_counts($tags, reset($taxonomies), $post_types, $post_stati); } $tags['found_rows'] = $found_rows; $tags = apply_filters('mla_get_terms_query_results', $tags); return $tags; }
/** * Extra controls to be displayed between bulk actions and pagination * * Modeled after class-wp-posts-list-table.php in wp-admin/includes. * * @since 0.1 * * @param string 'top' or 'bottom', i.e., above or below the table rows * * @return void */ function extra_tablenav($which) { /* * Decide which actions to show */ if ('top' == $which) { $actions = array('month', 'mla_filter_term', 'mla_filter'); $term_search_taxonomies = MLACore::mla_supported_taxonomies('term-search'); if (!empty($term_search_taxonomies)) { $actions[] = 'terms_search'; } } else { $actions = array(); } if (self::mla_submenu_arguments(true) != self::mla_submenu_arguments(false)) { $actions[] = 'clear_filter_by'; } if ($this->is_trash && current_user_can('edit_others_posts')) { $actions[] = 'delete_all'; } $actions = apply_filters('mla_list_table_extranav_actions', $actions, $which); if (empty($actions)) { return; } echo '<div class="alignleft actions">'; foreach ($actions as $action) { switch ($action) { case 'month': $this->months_dropdown('attachment'); break; case 'mla_filter_term': echo self::mla_get_taxonomy_filter_dropdown(isset($_REQUEST['mla_filter_term']) ? $_REQUEST['mla_filter_term'] : 0); break; case 'mla_filter': submit_button(__('Filter', 'media-library-assistant'), 'secondary', 'mla_filter', false, array('id' => 'post-query-submit')); break; case 'terms_search': submit_button(__('Terms Search', 'media-library-assistant'), 'secondary', 'mla_terms_search', false, array('id' => 'mla-terms-search-open', 'onclick' => 'mlaTaxonomy.termsSearch.open()')); break; case 'clear_filter_by': submit_button(__('Clear Filter-by', 'media-library-assistant'), 'button apply', 'clear_filter_by', false); break; case 'delete_all': submit_button(__('Empty Trash', 'media-library-assistant'), 'button apply', 'delete_all', false); break; default: do_action('mla_list_table_extranav_custom_action', $action, $which); } } echo '</div>'; }
/** * Fetch and filter IPTC and EXIF, XMP or PDF metadata for an image attachment * * @since 0.90 * * @param int post ID of attachment * @param string optional; if $post_id is zero, path to the image file. * * @return array Meta data variables, IPTC and EXIF or PDF */ public static function mla_fetch_attachment_image_metadata($post_id, $path = '') { $results = array('post_id' => $post_id, 'mla_iptc_metadata' => array(), 'mla_exif_metadata' => array(), 'mla_xmp_metadata' => array(), 'mla_pdf_metadata' => array()); if (0 != $post_id) { $path = get_attached_file($post_id); } if (!empty($path)) { if ('pdf' == strtolower(pathinfo($path, PATHINFO_EXTENSION))) { if (!class_exists('MLAPDF')) { require_once MLA_PLUGIN_PATH . 'includes/class-mla-data-pdf.php'; } $pdf_metadata = MLAPDF::mla_extract_pdf_metadata($path); $results['mla_xmp_metadata'] = $pdf_metadata['xmp']; $results['mla_pdf_metadata'] = $pdf_metadata['pdf']; return $results; } $size = getimagesize($path, $info); if (is_callable('iptcparse')) { if (!empty($info['APP13'])) { //set_error_handler( 'MLAData::mla_IPTC_EXIF_error_handler' ); $iptc_values = iptcparse($info['APP13']); //restore_error_handler(); if (!empty(MLAData::$mla_IPTC_EXIF_errors)) { $results['mla_iptc_errors'] = MLAData::$mla_IPTC_EXIF_errors; MLAData::$mla_IPTC_EXIF_errors = array(); MLACore::mla_debug_add(__LINE__ . __('ERROR', 'media-library-assistant') . ': ' . '$results[mla_iptc_errors] = ' . var_export($results['mla_exif_errors'], true), MLACore::MLA_DEBUG_CATEGORY_ANY); } if (!is_array($iptc_values)) { $iptc_values = array(); } foreach ($iptc_values as $key => $value) { if (in_array($key, array('1#000', '1#020', '1#022', '1#120', '1#122', '2#000', '2#200', '2#201'))) { $value = unpack('nbinary', $value[0]); $results['mla_iptc_metadata'][$key] = (string) $value['binary']; } elseif (1 == count($value)) { $results['mla_iptc_metadata'][$key] = $value[0]; } else { $results['mla_iptc_metadata'][$key] = $value; } } // foreach $value } // ! empty } // iptcparse if (is_callable('exif_read_data') && in_array($size[2], array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM))) { //set_error_handler( 'MLAData::mla_IPTC_EXIF_error_handler' ); $results['mla_exif_metadata'] = $exif_data = @exif_read_data($path); //restore_error_handler(); if (!empty(MLAData::$mla_IPTC_EXIF_errors)) { $results['mla_exif_errors'] = MLAData::$mla_IPTC_EXIF_errors; MLAData::$mla_IPTC_EXIF_errors = array(); MLACore::mla_debug_add(__LINE__ . __('ERROR', 'media-library-assistant') . ': ' . '$results[mla_exif_errors] = ' . var_export($results['mla_exif_errors'], true), MLACore::MLA_DEBUG_CATEGORY_ANY); } } // exif_read_data $results['mla_xmp_metadata'] = self::mla_parse_xmp_metadata($path, 0); if (NULL == $results['mla_xmp_metadata']) { $results['mla_xmp_metadata'] = array(); } // experimental damage repair for Robert O'Conner (Rufus McDufus) if (isset($exif_data['DateTimeOriginal']) && 8 > strlen($exif_data['DateTimeOriginal'])) { if (isset($results['mla_xmp_metadata']['CreateDate']) && is_numeric(strtotime($results['mla_xmp_metadata']['CreateDate']))) { $exif_data['BadDateTimeOriginal'] = $exif_data['DateTimeOriginal']; $results['mla_exif_metadata']['BadDateTimeOriginal'] = $exif_data['DateTimeOriginal']; $exif_data['DateTimeOriginal'] = $results['mla_xmp_metadata']['CreateDate']; $results['mla_exif_metadata']['DateTimeOriginal'] = $results['mla_xmp_metadata']['CreateDate']; } } // experimental damage repair for Elsie Gilmore (earthnutvt) if (isset($exif_data['Keywords']) && '????' == substr($exif_data['Keywords'], 0, 4)) { if (isset($results['mla_xmp_metadata']['Keywords'])) { $exif_data['Keywords'] = $results['mla_xmp_metadata']['Keywords']; $results['mla_exif_metadata']['Keywords'] = $results['mla_xmp_metadata']['Keywords']; } else { unset($exif_data['Keywords']); unset($results['mla_exif_metadata']['Keywords']); } } } /* * Expand EXIF Camera-related values: * * ExposureBiasValue * ExposureTime * Flash * FNumber * FocalLength * ShutterSpeed from ExposureTime */ $new_data = array(); if (isset($exif_data['FNumber'])) { if (false !== ($value = self::_rational_to_string($exif_data['FNumber'], '%1$d', '%1$d/%2$d', '%1$.1f'))) { $new_data['FNumber'] = $value; } } // FNumber if (isset($exif_data['ExposureBiasValue'])) { $fragments = array_map('intval', explode('/', $exif_data['ExposureBiasValue'])); if (!is_null($fragments[1])) { $numerator = $fragments[0]; $denominator = $fragments[1]; // Clean up some common format issues, e.g. 4/6, 2/4 while (0 == ($numerator & 0x1) && 0 == ($denominator & 0x1)) { $numerator = $numerator >> 1; $denominator = $denominator >> 1; } // Remove excess precision if ($denominator > $numerator && 1000 < $numerator && 1000 < $denominator) { $exif_data['ExposureBiasValue'] = sprintf('%1$+.3f', $numerator / $denominator); } else { $fragments[0] = $numerator; $fragments[1] = $denominator; $exif_data['ExposureBiasValue'] = $numerator . '/' . $denominator; } } if (false !== ($value = self::_rational_to_string($exif_data['ExposureBiasValue'], '%1$+d', '%1$+d/%2$d', '%1$+.2f'))) { $new_data['ExposureBiasValue'] = $value; } } // ExposureBiasValue if (isset($exif_data['Flash'])) { $value = absint($exif_data['Flash']); if ($value & 0x1) { $new_data['Flash'] = __('Yes', 'media-library-assistant'); } else { $new_data['Flash'] = __('No', 'media-library-assistant'); } } // Flash if (isset($exif_data['FocalLength'])) { if (false !== ($value = self::_rational_to_string($exif_data['FocalLength'], '%1$d', '%1$d/%2$d', '%1$.2f'))) { $new_data['FocalLength'] = $value; } } // FocalLength if (isset($exif_data['ExposureTime'])) { if (false !== ($value = self::_rational_to_string($exif_data['ExposureTime'], '%1$d', '%1$d/%2$d', '%1$.2f'))) { $new_data['ExposureTime'] = $value; } } // ExposureTime /* * ShutterSpeed in "1/" format, from ExposureTime * Special logic for "fractional shutter speed" values 1.3, 1.5, 1.6, 2.5 */ if (isset($exif_data['ExposureTime'])) { $fragments = array_map('intval', explode('/', $exif_data['ExposureTime'])); if (!is_null($fragments[1] && $fragments[0])) { if (1 == $fragments[1]) { $new_data['ShutterSpeed'] = $new_data['ExposureTime'] = sprintf('%1$d', $fragments[0]); } elseif (0 != $fragments[1]) { $value = $fragments[0] / $fragments[1]; if (0 < $value && 1 > $value) { // Convert to "1/" value for shutter speed if (1 == $fragments[0]) { $new_data['ShutterSpeed'] = $new_data['ExposureTime']; } else { $test = (double) number_format(1.0 / $value, 1, '.', ''); if (in_array($test, array(1.3, 1.5, 1.6, 2.5))) { $new_data['ShutterSpeed'] = '1/' . number_format(1.0 / $value, 1, '.', ''); } else { $new_data['ShutterSpeed'] = '1/' . number_format(1.0 / $value, 0, '.', ''); } } } else { $new_data['ShutterSpeed'] = $new_data['ExposureTime'] = sprintf('%1$.2f', $value); } } // fractional value } // valid denominator and non-zero numerator } // ShutterSpeed if (isset($exif_data['UndefinedTag:0xA420'])) { $new_data['ImageUniqueID'] = $exif_data['UndefinedTag:0xA420']; } if (isset($exif_data['UndefinedTag:0xA430'])) { $new_data['CameraOwnerName'] = $exif_data['UndefinedTag:0xA430']; } if (isset($exif_data['UndefinedTag:0xA431'])) { $new_data['BodySerialNumber'] = $exif_data['UndefinedTag:0xA431']; } if (isset($exif_data['UndefinedTag:0xA432']) && is_array($exif_data['UndefinedTag:0xA432'])) { $array = $new_data['LensSpecification'] = $exif_data['UndefinedTag:0xA432']; if (isset($array[0])) { if (false !== ($value = self::_rational_to_string($array[0], '%1$d', '%1$d/%2$d', '%1$.2f'))) { $new_data['LensMinFocalLength'] = $value; } } if (isset($array[1])) { if (false !== ($value = self::_rational_to_string($array[1], '%1$d', '%1$d/%2$d', '%1$.2f'))) { $new_data['LensMaxFocalLength'] = $value; } } if (isset($array[2])) { if (false !== ($value = self::_rational_to_string($array[2], '%1$d', '%1$d/%2$d', '%1$.1f'))) { $new_data['LensMinFocalLengthFN'] = $value; } } if (isset($array[3])) { if (false !== ($value = self::_rational_to_string($array[3], '%1$d', '%1$d/%2$d', '%1$.1f'))) { $new_data['LensMaxFocalLengthFN'] = $value; } } } if (isset($exif_data['UndefinedTag:0xA433'])) { $new_data['LensMake'] = $exif_data['UndefinedTag:0xA433']; } if (isset($exif_data['UndefinedTag:0xA434'])) { $new_data['LensModel'] = $exif_data['UndefinedTag:0xA434']; } if (isset($exif_data['UndefinedTag:0xA435'])) { $new_data['LensSerialNumber'] = $exif_data['UndefinedTag:0xA435']; } if (!empty($new_data)) { $results['mla_exif_metadata']['CAMERA'] = $new_data; } /* * Expand EXIF GPS values */ $new_data = array(); if (isset($exif_data['GPSVersion'])) { $new_data['Version'] = sprintf('%1$d.%2$d.%3$d.%4$d', ord($exif_data['GPSVersion'][0]), ord($exif_data['GPSVersion'][1]), ord($exif_data['GPSVersion'][2]), ord($exif_data['GPSVersion'][3])); } if (isset($exif_data['GPSLatitudeRef'])) { $new_data['LatitudeRef'] = $exif_data['GPSLatitudeRef']; $new_data['LatitudeRefS'] = 'N' == $exif_data['GPSLatitudeRef'] ? '' : '-'; $ref = $new_data['LatitudeRef']; $refs = $new_data['LatitudeRefS']; } else { $ref = ''; $refs = ''; } if (isset($exif_data['GPSLatitude'])) { $rational = $exif_data['GPSLatitude']; $new_data['LatitudeD'] = $degrees = self::_rational_to_decimal($rational[0]); $new_data['LatitudeM'] = $minutes = self::_rational_to_decimal($rational[1]); $new_data['LatitudeS'] = sprintf('%1$01.4f', $seconds = self::_rational_to_decimal($rational[2])); $decimal_minutes = $minutes + $seconds / 60; $decimal_degrees = $decimal_minutes / 60; $new_data['Latitude'] = sprintf('%1$dd %2$d\' %3$01.4f" %4$s', $degrees, $minutes, $seconds, $ref); $new_data['LatitudeDM'] = sprintf('%1$d %2$01.4f', $degrees, $decimal_minutes); $new_data['LatitudeDD'] = sprintf('%1$01f', $degrees + $decimal_degrees); $new_data['LatitudeMinDec'] = substr($new_data['LatitudeDM'], strpos($new_data['LatitudeDM'], ' ') + 1); $new_data['LatitudeDegDec'] = substr($new_data['LatitudeDD'], strpos($new_data['LatitudeDD'], '.')); $new_data['LatitudeSDM'] = $refs . $new_data['LatitudeDM']; $new_data['LatitudeSDD'] = $refs . $new_data['LatitudeDD']; $new_data['LatitudeDM'] = $new_data['LatitudeDM'] . $ref; $new_data['LatitudeDD'] = $new_data['LatitudeDD'] . $ref; } if (isset($exif_data['GPSLongitudeRef'])) { $new_data['LongitudeRef'] = $exif_data['GPSLongitudeRef']; $new_data['LongitudeRefS'] = 'E' == $exif_data['GPSLongitudeRef'] ? '' : '-'; $ref = $new_data['LongitudeRef']; $refs = $new_data['LongitudeRefS']; } else { $ref = ''; $refs = ''; } if (isset($exif_data['GPSLongitude'])) { $rational = $exif_data['GPSLongitude']; $new_data['LongitudeD'] = $degrees = self::_rational_to_decimal($rational[0]); $new_data['LongitudeM'] = $minutes = self::_rational_to_decimal($rational[1]); $new_data['LongitudeS'] = sprintf('%1$01.4f', $seconds = self::_rational_to_decimal($rational[2])); $decimal_minutes = $minutes + $seconds / 60; $decimal_degrees = $decimal_minutes / 60; $new_data['Longitude'] = sprintf('%1$dd %2$d\' %3$01.4f" %4$s', $degrees, $minutes, $seconds, $ref); $new_data['LongitudeDM'] = sprintf('%1$d %2$01.4f', $degrees, $decimal_minutes); $new_data['LongitudeDD'] = sprintf('%1$01f', $degrees + $decimal_degrees); $new_data['LongitudeMinDec'] = substr($new_data['LongitudeDM'], strpos($new_data['LongitudeDM'], ' ') + 1); $new_data['LongitudeDegDec'] = substr($new_data['LongitudeDD'], strpos($new_data['LongitudeDD'], '.')); $new_data['LongitudeSDM'] = $refs . $new_data['LongitudeDM']; $new_data['LongitudeSDD'] = $refs . $new_data['LongitudeDD']; $new_data['LongitudeDM'] = $new_data['LongitudeDM'] . $ref; $new_data['LongitudeDD'] = $new_data['LongitudeDD'] . $ref; } if (isset($exif_data['GPSAltitudeRef'])) { $new_data['AltitudeRef'] = sprintf('%1$d', ord($exif_data['GPSAltitudeRef'][0])); $new_data['AltitudeRefS'] = '0' == $new_data['AltitudeRef'] ? '' : '-'; $refs = $new_data['AltitudeRefS']; } else { $refs = ''; } if (isset($exif_data['GPSAltitude'])) { $new_data['Altitude'] = sprintf('%1$s%2$01.4f', $refs, $meters = self::_rational_to_decimal($exif_data['GPSAltitude'])); $new_data['AltitudeFeet'] = sprintf('%1$s%2$01.2f', $refs, $meters * 3.280839895013); } if (isset($exif_data['GPSTimeStamp'])) { $rational = $exif_data['GPSTimeStamp']; $new_data['TimeStampH'] = sprintf('%1$02d', $hours = self::_rational_to_decimal($rational[0])); $new_data['TimeStampM'] = sprintf('%1$02d', $minutes = self::_rational_to_decimal($rational[1])); $new_data['TimeStampS'] = sprintf('%1$02d', $seconds = self::_rational_to_decimal($rational[2])); $new_data['TimeStamp'] = sprintf('%1$02d:%2$02d:%3$02d', $hours, $minutes, $seconds); } if (isset($exif_data['GPSDateStamp'])) { $parts = explode(':', $exif_data['GPSDateStamp']); $new_data['DateStampY'] = $parts[0]; $new_data['DateStampM'] = $parts[1]; $new_data['DateStampD'] = $parts[2]; $new_data['DateStamp'] = $exif_data['GPSDateStamp']; } if (isset($exif_data['GPSMapDatum'])) { $new_data['MapDatum'] = $exif_data['GPSMapDatum']; } if (!empty($new_data)) { $results['mla_exif_metadata']['GPS'] = $new_data; } //error_log( __LINE__ . " mla_fetch_attachment_image_metadata( {$post_id} ) results = " . var_export( $results, true ), 0 ); return $results; }
/** * Build the hidden form for the "Search Terms" popup modal window * * @since 1.90 * * @return string HTML <form> markup for hidden form */ public static function mla_terms_search_form() { $page_template_array = MLACore::mla_load_template('admin-terms-search-form.tpl'); if (!is_array($page_template_array)) { /* translators: 1: ERROR tag 2: function name 3: non-array value */ error_log(sprintf(_x('%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), 'MLA::_build_terms_search_form', var_export($page_template_array, true)), 0); return ''; } $taxonomies = array(); foreach (get_object_taxonomies('attachment', 'objects') as $taxonomy) { if (MLACore::mla_taxonomy_support($taxonomy->name, 'support')) { $taxonomies[] = $taxonomy; } } if (empty($taxonomies)) { $page_values = array('Search Terms' => __('Search Terms', 'media-library-assistant'), 'message' => __('There are no taxonomies to search', 'media-library-assistant')); $terms_search_tpl = MLAData::mla_parse_template($page_template_array['mla-terms-search-empty-div'], $page_values); } else { $taxonomy_list = ''; foreach ($taxonomies as $taxonomy) { $page_values = array('taxonomy_checked' => MLACore::mla_taxonomy_support($taxonomy->name, 'term-search') ? 'checked="checked"' : '', 'taxonomy_slug' => $taxonomy->name, 'taxonomy_label' => esc_attr($taxonomy->label)); $taxonomy_list .= MLAData::mla_parse_template($page_template_array['mla-terms-search-taxonomy'], $page_values); } $page_values = array('Search Terms' => __('Search Terms', 'media-library-assistant'), 'Search' => __('Search', 'media-library-assistant'), 'phrases_and_checked' => 'checked="checked"', 'All phrases' => __('All phrases', 'media-library-assistant'), 'phrases_or_checked' => '', 'Any phrase' => __('Any phrase', 'media-library-assistant'), 'terms_and_checked' => '', 'All terms' => __('All terms', 'media-library-assistant'), 'terms_or_checked' => 'checked="checked"', 'Any term' => __('Any term', 'media-library-assistant'), 'exact_checked' => '', 'Exact' => __('Exact', 'media-library-assistant'), 'mla_terms_search_taxonomies' => $taxonomy_list); $terms_search_tpl = MLAData::mla_parse_template($page_template_array['mla-terms-search-div'], $page_values); } $page_values = array('mla_terms_search_url' => esc_url(add_query_arg(array_merge(MLA_List_Table::mla_submenu_arguments(false), array('page' => MLACore::ADMIN_PAGE_SLUG)), admin_url('upload.php'))), 'mla_terms_search_action' => MLA::MLA_ADMIN_TERMS_SEARCH, 'wpnonce' => wp_nonce_field(MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false), 'mla_terms_search_div' => $terms_search_tpl); $terms_search_tpl = MLAData::mla_parse_template($page_template_array['mla-terms-search-form'], $page_values); return $terms_search_tpl; }
/** * Ajax handler for Media Manager "Query Attachments" queries * * Adapted from wp_ajax_query_attachments in /wp-admin/includes/ajax-actions.php * * @since 2.20 * * @return void passes array of post arrays to wp_send_json_success() for JSON encoding and transmission */ public static function mla_query_attachments_action() { if (!current_user_can('upload_files')) { wp_send_json_error(); } /* * Pick out and clean up the query terms we can process */ $raw_query = isset($_REQUEST['query']) ? (array) $_REQUEST['query'] : array(); $query = array_intersect_key($raw_query, array_flip(array('order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type', 'post_parent', 'post__in', 'post__not_in', 'mla_filter_month', 'mla_filter_term', 'mla_terms_search', 'mla_search_value', 's', 'mla_search_fields', 'mla_search_connector'))); $query = apply_filters('mla_media_modal_query_initial_terms', $query, $raw_query); if (isset($query['post_mime_type'])) { if ('detached' == $query['post_mime_type']) { $query['detached'] = '1'; unset($query['post_mime_type']); } elseif ('attached' == $query['post_mime_type']) { $query['detached'] = '0'; unset($query['post_mime_type']); } elseif ('trash' == $query['post_mime_type']) { $query['status'] = 'trash'; unset($query['post_mime_type']); } else { $view = $query['post_mime_type']; unset($query['post_mime_type']); $query = array_merge($query, MLACore::mla_prepare_view_query('view', $view)); } } /* * Convert mla_filter_month back to the WordPress "m" parameter */ if (isset($query['mla_filter_month'])) { if ('0' != $query['mla_filter_month']) { $query['m'] = $query['mla_filter_month']; } unset($query['mla_filter_month']); } /* * Process the enhanced search box OR fix up the default search box */ if (isset($query['mla_search_value'])) { if (!empty($query['mla_search_value'])) { $query['s'] = $query['mla_search_value']; } unset($query['mla_search_value']); } if (isset($query['posts_per_page'])) { $count = $query['posts_per_page']; $offset = $count * (isset($query['paged']) ? $query['paged'] - 1 : 0); } else { $count = 0; $offset = 0; } /* * Check for sorting override */ $option = MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_ORDERBY); if ('default' != $option) { /* * Make sure the current orderby choice still exists or revert to default. */ $default_orderby = array_merge(array('none' => array('none', false)), MLAQuery::mla_get_sortable_columns()); $found_current = false; foreach ($default_orderby as $key => $value) { if ($option == $value[0]) { $found_current = true; break; } } if (!$found_current) { MLACore::mla_delete_option(MLACoreOptions::MLA_DEFAULT_ORDERBY); $option = MLACore::mla_get_option(MLACoreOptions::MLA_DEFAULT_ORDERBY); } $query['orderby'] = $option; } $option = MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_ORDER); if ('default' != $option) { $query['order'] = $option; } $query['post_type'] = 'attachment'; if (empty($query['status'])) { $query['post_status'] = 'inherit'; if (current_user_can(get_post_type_object('attachment')->cap->read_private_posts)) { $query['post_status'] .= ',private'; } } $query = apply_filters('mla_media_modal_query_filtered_terms', $query, $raw_query); $query = MLAQuery::mla_query_media_modal_items($query, $offset, $count); $posts = array_map('wp_prepare_attachment_for_js', $query->posts); $posts = array_filter($posts); wp_send_json_success($posts); }
/** * Add rollover actions to a table column * * @since 1.40 * * @param object An MLA post_mime_type object * @param string Current column name * * @return array Names and URLs of row-level actions */ private function _build_rollover_actions($item, $column) { $actions = array(); /* * Compose view arguments */ $view_args = array('page' => MLACore::MLA_SETTINGS_SLUG . '-view', 'mla_tab' => 'view', 'mla_item_slug' => urlencode($item->slug)); if (isset($_REQUEST['paged'])) { $view_args['paged'] = $_REQUEST['paged']; } if (isset($_REQUEST['order'])) { $view_args['order'] = $_REQUEST['order']; } if (isset($_REQUEST['orderby'])) { $view_args['orderby'] = $_REQUEST['orderby']; } /* * Get the standard and custom types */ $mla_types = MLACore::mla_get_option(MLACore::MLA_POST_MIME_TYPES, true); if (!is_array($mla_types)) { $mla_types = array(); } $custom_types = MLACore::mla_get_option(MLACore::MLA_POST_MIME_TYPES, false, true); if (!is_array($custom_types)) { $custom_types = array(); } $actions['edit'] = '<a href="' . add_query_arg($view_args, wp_nonce_url('?mla_admin_action=' . MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME)) . '" title="' . __('Edit this item', 'media-library-assistant') . '">' . __('Edit', 'media-library-assistant') . '</a>'; $actions['inline hide-if-no-js'] = '<a class="editinline" href="#" title="' . __('Edit this item inline', 'media-library-assistant') . '">' . __('Quick Edit', 'media-library-assistant') . '</a>'; if (isset($custom_types[$item->slug])) { if (isset($mla_types[$item->slug])) { $actions['delete'] = '<a class="delete-tag"' . ' href="' . add_query_arg($view_args, wp_nonce_url('?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_DELETE, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME)) . '" title="' . __('Revert to standard item', 'media-library-assistant') . '">' . __('Revert to Standard', 'media-library-assistant') . '</a>'; } else { $actions['delete'] = '<a class="delete-tag"' . ' href="' . add_query_arg($view_args, wp_nonce_url('?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_DELETE, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME)) . '" title="' . __('Delete this item Permanently', 'media-library-assistant') . '">' . __('Delete Permanently', 'media-library-assistant') . '</a>'; } } // custom type return $actions; }
/** * Store the options portion of the Upload MIME Types * * @since 1.40 * * @return boolean Success (true) or failure (false) of the operation */ private static function _put_upload_mime_templates() { $mla_upload_mimes = array('custom' => array(), 'disabled' => array(), 'description' => array(), 'icon_type' => array()); foreach (self::$mla_upload_mime_templates as $key => $value) { if ('custom' == $value['source']) { $mla_upload_mimes['custom'][$key] = $value['mime_type']; } if ($value['disabled']) { $mla_upload_mimes['disabled'][$key] = true; } $description = trim($value['description']); if (!empty($description) && $description != self::$mla_upload_mime_descriptions[$key]) { $mla_upload_mimes['description'][$key] = $description; } if ($value['icon_type'] != $value['core_icon_type']) { $mla_upload_mimes['icon_type'][$key] = $value['icon_type']; } } MLACore::mla_update_option(MLACore::MLA_UPLOAD_MIMES, $mla_upload_mimes); return true; }
/** * Flush debug information and clear buffer * * @since 2.12 * * @param string $destination Destination: 'buffer' (default), 'console', 'log' or 'none' * @param boolean $stop_collecting true (default) to stop, false to continue collection * * @return string debug content if $destination == 'buffer' else empty string */ public static function mla_debug_flush($destination = 'buffer', $stop_collecting = true) { $results = ''; switch ($destination) { case 'buffer': $results = MLACore::mla_debug_content(); break; case 'console': foreach (self::$mla_debug_messages as $message) { trigger_error($message, E_USER_WARNING); } break; case 'log': foreach (self::$mla_debug_messages as $message) { self::_debug_log($message); } break; } self::$mla_debug_messages = array(); if ($stop_collecting) { self::$mla_debug_mode = 'none'; } return $results; }
/** * MLA_List_Table inline edit parse * * @since 2.13 * * Adds Bulk Translate form and the Language dropdown * markup used for the Quick and Bulk Edit forms. * * @param string HTML markup returned by the template parser * @param string template used to generate the HTML markup * @param array parameter_name => parameter_value pairs * * @return array updated HTML markup for the Quick and Bulk Edit forms */ public static function mla_list_table_inline_parse($html_markup, $item_template, $item_values) { /* * Add the Thumbnail Generation Markup */ $page_template_array = MLACore::mla_load_template('mla-thumbnail-generation.tpl'); if (!is_array($page_template_array)) { error_log('ERROR: mla-thumbnail-generation.tpl path = ' . var_export(plugin_dir_path(__FILE__) . 'mla-thumbnail-generation.tpl', true), 0); error_log('ERROR: mla-thumbnail-generation.tpl non-array result = ' . var_export($page_template_array, true), 0); return $html_markup; } $page_values = array('colspan' => $item_values['colspan'], 'Generate Thumbnails' => __('Generate Thumbnails', 'media-library-assistant'), 'See Documentation' => __('Pull down the Help menu and select Thumbnail Generation for setting details', 'media-library-assistant'), 'Width' => __('Width', 'media-library-assistant'), 'Height' => __('Height', 'media-library-assistant'), 'Best Fit' => __('Best Fit', 'media-library-assistant'), 'Page' => __('Page', 'media-library-assistant'), 'Resolution' => __('Resolution', 'media-library-assistant'), 'Quality' => __('Quality', 'media-library-assistant'), 'Type' => __('Type', 'media-library-assistant'), 'Existing Items' => __('Existing Items', 'media-library-assistant'), 'Keep' => __('Keep', 'media-library-assistant'), 'Ignore' => __('Ignore', 'media-library-assistant'), 'Trash' => __('Trash', 'media-library-assistant'), 'Delete' => __('Delete', 'media-library-assistant'), 'Suffix' => __('Suffix', 'media-library-assistant'), 'default_suffix' => '-' . __('Thumbnail', 'media-library-assistant'), 'Options' => __('Options', 'media-library-assistant'), 'Clear Filter-by' => __('Clear Filter-by', 'media-library-assistant'), 'Cancel' => __('Cancel', 'media-library-assistant')); $parse_value = MLAData::mla_parse_template($page_template_array['page'], $page_values); return $html_markup . "\n" . $parse_value; }
/** * Load an HTML template from a file * * Loads a template to a string or a multi-part template to an array. * Multi-part templates are divided by comments of the form <!-- template="key" -->, * where "key" becomes the key part of the array. * * @since 0.1 * * @param string Complete path and/or name of the template file, option name or the raw template * @param string Optional type of template source; 'path', 'file' (default), 'option', 'string' * * @return string|array|false|NULL * string for files that do not contain template divider comments, * array for files containing template divider comments, * false if file or option does not exist, * NULL if file could not be loaded. */ public static function mla_load_template($source, $type = 'file') { switch ($type) { case 'file': /* * Look in three places, in this order: * 1) Custom templates * 2) Language-specific templates * 3) Standard templates */ $text_domain = 'media-library-assistant'; $locale = apply_filters('mla_plugin_locale', get_locale(), $text_domain); $path = trailingslashit(WP_LANG_DIR) . $text_domain . '/tpls/' . $locale . '/' . $source; if (file_exists($path)) { $source = $path; } else { $path = MLA_PLUGIN_PATH . 'languages/tpls/' . $locale . '/' . $source; if (file_exists($path)) { $source = $path; } else { $source = MLA_PLUGIN_PATH . 'tpls/' . $source; } } // fallthru // fallthru case 'path': if (!file_exists($source)) { return false; } $template = file_get_contents($source, true); if ($template == false) { /* translators: 1: ERROR tag 2: path and file name */ error_log(sprintf(_x('%1$s: mla_load_template file "%2$s" not found.', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), var_export($source, true)), 0); return NULL; } break; case 'option': $template = MLACore::mla_get_option($source); if ($template == false) { return false; } break; case 'string': $template = $source; if (empty($template)) { return false; } break; default: /* translators: 1: ERROR tag 2: path and file name 3: source type, e.g., file, option, string */ error_log(sprintf(_x('%1$s: mla_load_template file "%2$s" bad source type "%3$s".', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $source, $type), 0); return NULL; } $match_count = preg_match_all('#\\<!-- template=".+" --\\>#', $template, $matches, PREG_OFFSET_CAPTURE); if ($match_count == false || $match_count == 0) { return $template; } $matches = array_reverse($matches[0]); $template_array = array(); $current_offset = strlen($template); foreach ($matches as $key => $value) { $template_key = preg_split('#"#', $value[0]); $template_key = $template_key[1]; $template_value = substr($template, $value[1] + strlen($value[0]), $current_offset - ($value[1] + strlen($value[0]))); /* * Trim exactly one newline sequence from the start of the value */ if (0 === strpos($template_value, "\r\n")) { $offset = 2; } elseif (0 === strpos($template_value, "\n\r")) { $offset = 2; } elseif (0 === strpos($template_value, "\n")) { $offset = 1; } elseif (0 === strpos($template_value, "\r")) { $offset = 1; } else { $offset = 0; } $template_value = substr($template_value, $offset); /* * Trim exactly one newline sequence from the end of the value */ $length = strlen($template_value); if ($length > 2) { $postfix = substr($template_value, $length - 2, 2); } else { $postfix = $template_value; } if (0 === strpos($postfix, "\r\n")) { $length -= 2; } elseif (0 === strpos($postfix, "\n\r")) { $length -= 2; } elseif (0 === strpos($postfix, "\n")) { $length -= 1; } elseif (0 === strpos($postfix, "\r")) { $length -= 1; } $template_array[$template_key] = substr($template_value, 0, $length); $current_offset = $value[1]; } // foreach $matches return $template_array; }
/** * Read a serialized file of option settings and write them to the database * * @since 1.50 * * @return array Message(s) reflecting the results of the operation */ private static function _import_settings() { $page_content = array('message' => __('No settings imported.', 'media-library-assistant'), 'body' => ''); $message_list = ''; if (isset($_REQUEST['mla-import-settings-file'])) { $filename = $_REQUEST['mla-import-settings-file']; if ('none' != $filename) { $filename = MLA_BACKUP_DIR . $filename; } else { $page_content['message'] = __('Please select an import settings file from the dropdown list.', 'media-library-assistant'); return $page_content; } } else { $page_content['message'] = __('ERROR', 'media-library-assistant') . ': ' . __('The import settings dropdown selection is missing.', 'media-library-assistant'); return $page_content; } $settings = @file_get_contents($filename, false); if (false === $settings) { $error_info = error_get_last(); /* translators: 1: ERROR tag 2: PHP error information */ error_log(sprintf(_x('%1$s: _import_settings $error_info = "%2$s".', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), var_export($error_info, true)), 0); if (false !== ($tail = strpos($error_info['message'], '</a>]: '))) { $php_errormsg = ':<br>' . substr($error_info['message'], $tail + 7); } else { $php_errormsg = '.'; } /* translators: 1: ERROR tag 2: backup file name 3: error message*/ $page_content['message'] = sprintf(__('%1$s: Reading the settings file ( %2$s ) "%3$s".', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $filename, $php_errormsg); return $page_content; } $settings = unserialize($settings); $updated_count = 0; $unchanged_count = 0; foreach ($settings as $key => $value) { /* * These are WordPress options, not MLA options */ if (in_array($key, array('image_default_align', 'image_default_link_type', 'image_default_size'))) { $stored_value = get_option($key); if (empty($stored_value)) { $stored_value = 'default'; } if ($stored_value !== $value) { $updated_count++; $message_list .= "<br>{$key} " . _x('updated', 'message_list', 'media-library-assistant'); } else { $unchanged_count++; $message_list .= "<br>{$key} " . _x('unchanged', 'message_list', 'media-library-assistant'); } if ('default' === $value) { $value = ''; } update_option($key, $value); continue; } if (MLACore::mla_update_option($key, $value)) { $updated_count++; $message_list .= "<br>{$key} " . _x('updated', 'message_list', 'media-library-assistant'); } else { $unchanged_count++; $message_list .= "<br>{$key} " . _x('unchanged', 'message_list', 'media-library-assistant'); } } /* translators: 1: number of option settings updated 2: number of option settings unchanged */ $page_content['message'] = sprintf(__('Settings imported; %1$s updated, %2$s unchanged.', 'media-library-assistant'), $updated_count, $unchanged_count); /* * Uncomment this for debugging. */ //$page_content['message'] .= $message_list; return $page_content; }
/** * Begin an MLA_List_Table bulk action * * Prepare the thumbnail generation options. * * @since 2.13 * * @param array $item_content NULL, to indicate no handler. * @param string $bulk_action the requested action. */ public static function mla_list_table_begin_bulk_action($item_content, $bulk_action) { if (self::MLA_GFI_ACTION != $bulk_action) { return $item_content; } self::$bulk_action_options = array(); $request_options = isset($_REQUEST['mla_thumbnail_options']) ? $_REQUEST['mla_thumbnail_options'] : array(); $request_options['ghostscript_path'] = MLACore::mla_get_option('ghostscript_path'); if (empty($request_options['existing_thumbnails'])) { $request_options['existing_thumbnails'] = 'keep'; } foreach ($request_options as $key => $value) { if (!empty($value)) { self::$bulk_action_options[$key] = $value; } } // Convert checkboxes to booleans self::$bulk_action_options['best_fit'] = isset($request_options['best_fit']); self::$bulk_action_options['clear_filters'] = isset($request_options['clear_filters']); // Convert page number to frame if (isset(self::$bulk_action_options['page'])) { $page = abs(intval(self::$bulk_action_options['page'])); self::$bulk_action_options['frame'] = 0 < $page ? $page - 1 : 0; unset(self::$bulk_action_options['page']); } return $item_content; }
/** * Delete saved settings, restoring default values * * @since 2.11 * * @return array Message(s) reflecting the results of the operation */ private static function _reset_language_settings() { $message_list = ''; foreach (MLA_Polylang::$mla_language_option_definitions as $key => $value) { if ('language' == $value['tab']) { if ('custom' == $value['type'] && isset($value['reset'])) { $message = MLA_Polylang::$value['reset']('reset', $key, $value, $_REQUEST); } elseif ('header' == $value['type'] || 'hidden' == $value['type']) { $message = ''; } else { MLACore::mla_delete_option($key, MLA_Polylang::$mla_language_option_definitions); /* translators: 1: option name */ $message = '<br>' . sprintf(_x('delete_option "%1$s"', 'message_list', 'media-library-assistant'), $key); } $message_list .= $message; } } $page_content = array('message' => __('Language settings reset to default values.', 'media-library-assistant') . "\n", 'body' => ''); /* * Uncomment this for debugging. */ //$page_content['message'] .= $message_list; return $page_content; }
/** * Build the hidden row templates for inline editing (quick and bulk edit) * * inspired by inline_edit() in wp-admin\includes\class-wp-posts-list-table.php. * * @since 0.20 * * @param object MLA List Table object * * @return string HTML <form> markup for hidden rows */ private static function _build_inline_edit_form($MLAListTable) { $taxonomies = get_object_taxonomies('attachment', 'objects'); $hierarchical_taxonomies = array(); $flat_taxonomies = array(); foreach ($taxonomies as $tax_name => $tax_object) { if ($tax_object->hierarchical && $tax_object->show_ui && MLACore::mla_taxonomy_support($tax_name, 'quick-edit')) { $hierarchical_taxonomies[$tax_name] = $tax_object; } elseif ($tax_object->show_ui && MLACore::mla_taxonomy_support($tax_name, 'quick-edit')) { $flat_taxonomies[$tax_name] = $tax_object; } } $page_template_array = MLAData::mla_load_template('admin-inline-edit-form.tpl'); if (!is_array($page_template_array)) { /* translators: 1: ERROR tag 2: function name 3: non-array value */ error_log(sprintf(_x('%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), 'MLA::_build_inline_edit_form', var_export($page_template_array, true)), 0); return ''; } if ($authors = self::mla_authors_dropdown()) { $authors_dropdown = ' <label class="inline-edit-author">' . "\n"; $authors_dropdown .= ' <span class="title">' . __('Author', 'media-library-assistant') . '</span>' . "\n"; $authors_dropdown .= $authors . "\n"; $authors_dropdown .= ' </label>' . "\n"; } else { $authors_dropdown = ''; } $custom_fields = ''; foreach (MLACore::mla_custom_field_support('quick_edit') as $slug => $details) { $page_values = array('slug' => $slug, 'label' => esc_attr($details['name'])); $custom_fields .= MLAData::mla_parse_template($page_template_array['custom_field'], $page_values); } /* * The middle column contains the hierarchical taxonomies, e.g., Attachment Category */ $quick_middle_column = ''; $bulk_middle_column = ''; if (count($hierarchical_taxonomies)) { $quick_category_blocks = ''; $bulk_category_blocks = ''; foreach ($hierarchical_taxonomies as $tax_name => $tax_object) { if (current_user_can($tax_object->cap->assign_terms)) { ob_start(); wp_terms_checklist(NULL, array('taxonomy' => $tax_name)); $tax_checklist = ob_get_contents(); ob_end_clean(); $page_values = array('tax_html' => esc_html($tax_object->labels->name), 'more' => __('more', 'media-library-assistant'), 'less' => __('less', 'media-library-assistant'), 'tax_attr' => esc_attr($tax_name), 'tax_checklist' => $tax_checklist, 'Add' => __('Add', 'media-library-assistant'), 'Remove' => __('Remove', 'media-library-assistant'), 'Replace' => __('Replace', 'media-library-assistant')); $category_block = MLAData::mla_parse_template($page_template_array['category_block'], $page_values); $taxonomy_options = MLAData::mla_parse_template($page_template_array['taxonomy_options'], $page_values); $quick_category_blocks .= $category_block; $bulk_category_blocks .= $category_block . $taxonomy_options; } // current_user_can } // foreach $hierarchical_taxonomies $page_values = array('category_blocks' => $quick_category_blocks); $quick_middle_column = MLAData::mla_parse_template($page_template_array['category_fieldset'], $page_values); $page_values = array('category_blocks' => $bulk_category_blocks); $bulk_middle_column = MLAData::mla_parse_template($page_template_array['category_fieldset'], $page_values); } // count( $hierarchical_taxonomies ) /* * The right-hand column contains the flat taxonomies, e.g., Attachment Tag */ $quick_right_column = ''; $bulk_right_column = ''; if (count($flat_taxonomies)) { $quick_tag_blocks = ''; $bulk_tag_blocks = ''; foreach ($flat_taxonomies as $tax_name => $tax_object) { if (current_user_can($tax_object->cap->assign_terms)) { $page_values = array('tax_html' => esc_html($tax_object->labels->name), 'tax_attr' => esc_attr($tax_name), 'Add' => __('Add', 'media-library-assistant'), 'Remove' => __('Remove', 'media-library-assistant'), 'Replace' => __('Replace', 'media-library-assistant')); $tag_block = MLAData::mla_parse_template($page_template_array['tag_block'], $page_values); $taxonomy_options = MLAData::mla_parse_template($page_template_array['taxonomy_options'], $page_values); $quick_tag_blocks .= $tag_block; $bulk_tag_blocks .= $tag_block . $taxonomy_options; } // current_user_can } // foreach $flat_taxonomies $page_values = array('tag_blocks' => $quick_tag_blocks); $quick_right_column = MLAData::mla_parse_template($page_template_array['tag_fieldset'], $page_values); $page_values = array('tag_blocks' => $bulk_tag_blocks); $bulk_right_column = MLAData::mla_parse_template($page_template_array['tag_fieldset'], $page_values); } // count( $flat_taxonomies ) if ($authors = self::mla_authors_dropdown(-1)) { $bulk_authors_dropdown = ' <label class="inline-edit-author alignright">' . "\n"; $bulk_authors_dropdown .= ' <span class="title">' . __('Author', 'media-library-assistant') . '</span>' . "\n"; $bulk_authors_dropdown .= $authors . "\n"; $bulk_authors_dropdown .= ' </label>' . "\n"; } else { $bulk_authors_dropdown = ''; } $bulk_custom_fields = ''; foreach (MLACore::mla_custom_field_support('bulk_edit') as $slug => $details) { $page_values = array('slug' => $slug, 'label' => esc_attr($details['name'])); $bulk_custom_fields .= MLAData::mla_parse_template($page_template_array['custom_field'], $page_values); } $set_parent_form = MLA::mla_set_parent_form(); $page_values = array('colspan' => $MLAListTable->get_column_count(), 'Quick Edit' => __('Quick Edit', 'media-library-assistant'), 'Title' => __('Title', 'media-library-assistant'), 'Name/Slug' => __('Name/Slug', 'media-library-assistant'), 'Caption' => __('Caption', 'media-library-assistant'), 'Description' => __('Description', 'media-library-assistant'), 'ALT Text' => __('ALT Text', 'media-library-assistant'), 'Parent ID' => __('Parent ID', 'media-library-assistant'), 'Select' => __('Select', 'media-library-assistant'), 'Menu Order' => __('Menu Order', 'media-library-assistant'), 'authors' => $authors_dropdown, 'custom_fields' => $custom_fields, 'quick_middle_column' => $quick_middle_column, 'quick_right_column' => $quick_right_column, 'Cancel' => __('Cancel', 'media-library-assistant'), 'Reset' => __('Reset', 'media-library-assistant'), 'Update' => __('Update', 'media-library-assistant'), 'Bulk Edit' => __('Bulk Edit', 'media-library-assistant'), 'bulk_middle_column' => $bulk_middle_column, 'bulk_right_column' => $bulk_right_column, 'bulk_authors' => $bulk_authors_dropdown, 'Comments' => __('Comments', 'media-library-assistant'), 'Pings' => __('Pings', 'media-library-assistant'), 'No Change' => __('No Change', 'media-library-assistant'), 'Allow' => __('Allow', 'media-library-assistant'), 'Do not allow' => __('Do not allow', 'media-library-assistant'), 'bulk_custom_fields' => $bulk_custom_fields, 'Map IPTC/EXIF metadata' => __('Map IPTC/EXIF metadata', 'media-library-assistant'), 'Map Custom Field metadata' => __('Map Custom Field metadata', 'media-library-assistant'), 'Bulk Waiting' => __('Waiting', 'media-library-assistant'), 'Bulk Running' => __('In-process', 'media-library-assistant'), 'Bulk Complete' => __('Complete', 'media-library-assistant'), 'Refresh' => __('Refresh', 'media-library-assistant'), 'set_parent_form' => $set_parent_form); $page_values = apply_filters('mla_list_table_inline_values', $page_values); $page_template = apply_filters('mla_list_table_inline_template', $page_template_array['page']); $parse_value = MLAData::mla_parse_template($page_template, $page_values); return apply_filters('mla_list_table_inline_parse', $parse_value, $page_template, $page_values); }
/** * Filters all clauses for shortcode queries, post caching plugins * * This is for debug purposes only. * Defined as public because it's a filter. * * @since 1.80 * * @param array query clauses before modification * * @return array query clauses after modification (none) */ public static function mla_query_posts_clauses_request_filter($pieces) { /* translators: 1: DEBUG tag 2: SQL clauses */ MLACore::mla_debug_add(sprintf(_x('%1$s: mla_query_posts_clauses_request_filter = "%2$s".', 'error_log', 'media-library-assistant'), __('DEBUG', 'media-library-assistant'), var_export($pieces, true))); return $pieces; }
/** * Assemble the in-memory representation of the (read-only) Optional Upload MIME Types * * @since 1.40 * * @return boolean Success (true) or failure (false) of the operation */ private static function _get_optional_upload_mime_templates() { if (NULL != self::$mla_optional_upload_mime_templates) { return true; } self::$mla_optional_upload_mime_templates = array(); $template_array = MLACore::mla_load_template('mla-default-mime-types.tpl'); if (isset($template_array['mla-optional-mime-types'])) { $mla_mime_types = preg_split('/[\\r\\n]+/', $template_array['mla-optional-mime-types']); $ID = 0; foreach ($mla_mime_types as $mla_type) { // Ignore blank lines if (empty($mla_type)) { continue; } $array = explode(',', $mla_type); // Bypass damaged entries if (3 > count($array)) { MLACore::mla_debug_add(__LINE__ . " _get_upload_mime_templates mla-default-mime-types.tpl section mla-optional-mime-types( {$ID} '{$mla_type}' ) \$array = " . var_export($array, true), MLACore::MLA_DEBUG_CATEGORY_ANY); continue; } $slug = $array[0]; if ($matched_type = self::mla_get_upload_mime($slug)) { $core_type = $matched_type['core_type']; $mla_type = $matched_type['mla_type']; } else { $core_type = ''; $mla_type = ''; } self::$mla_optional_upload_mime_templates[++$ID] = array('ID' => $ID, 'slug' => $slug, 'mime_type' => $array[1], 'core_type' => $core_type, 'mla_type' => $mla_type, 'description' => $array[2]); } } return true; }
/** * Log debug information * * @since 2.12 * * @param string $message Error message. */ private static function _mla_debug_add($message) { if (self::$mla_debug) { if (class_exists('MLACore')) { MLACore::mla_debug_add($message); } else { error_log($message, 0); } } }
/** * Add contextual help tabs to the WordPress Edit Media page * * @since 0.90 * * @param string title as shown on the screen * @param string title as shown in the HTML header * * @return void */ public static function mla_edit_add_help_tab($admin_title, $title) { $screen = get_current_screen(); /* * Upload New Media Bulk Edit Area */ if ('media' == $screen->id && 'add' == $screen->action) { $template_array = MLACore::mla_load_template('help-for-upload-new-media.tpl'); if (empty($template_array)) { return $admin_title; } /* * Replace sidebar content */ if (!empty($template_array['sidebar'])) { $page_values = array('settingsURL' => admin_url('options-general.php')); $content = MLAData::mla_parse_template($template_array['sidebar'], $page_values); $screen->set_help_sidebar($content); } unset($template_array['sidebar']); /* * Provide explicit control over tab order */ $tab_array = array(); foreach ($template_array as $id => $content) { $match_count = preg_match('#\\<!-- title="(.+)" order="(.+)" --\\>#', $content, $matches, PREG_OFFSET_CAPTURE); if ($match_count > 0) { $tab_array[$matches[2][0]] = array('id' => $id, 'title' => $matches[1][0], 'content' => $content); } else { /* translators: 1: ERROR tag 2: function name 3: template key */ error_log(sprintf(_x('%1$s: %2$s discarding "%3$s"; no title/order', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), 'mla_edit_add_help_tab', $id), 0); } } ksort($tab_array, SORT_NUMERIC); foreach ($tab_array as $indx => $value) { $screen->add_help_tab($value); } return $admin_title; } /* * Media/Edit Media submenu */ if ('attachment' != $screen->id || 'attachment' != $screen->post_type || 'post' != $screen->base) { return $admin_title; } $template_array = MLACore::mla_load_template('help-for-edit_attachment.tpl'); if (empty($template_array)) { return $admin_title; } /* * Provide explicit control over tab order */ $tab_array = array(); foreach ($template_array as $id => $content) { $match_count = preg_match('#\\<!-- title="(.+)" order="(.+)" --\\>#', $content, $matches, PREG_OFFSET_CAPTURE); if ($match_count > 0) { $tab_array[$matches[2][0]] = array('id' => $id, 'title' => $matches[1][0], 'content' => $content); } else { /* translators: 1: ERROR tag 2: function name 3: template key */ error_log(sprintf(_x('%1$s: %2$s discarding "%3$s"; no title/order', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), 'mla_edit_add_help_tab', $id), 0); } } ksort($tab_array, SORT_NUMERIC); foreach ($tab_array as $indx => $value) { $screen->add_help_tab($value); } return $admin_title; }
/** * Builds the $mla_galleries or $galleries array * * @since 0.70 * * @param string name of the gallery's cache/option variable * @param array by reference to the private static galleries array variable * @param string the shortcode to be searched for and processed * @param boolean true to exclude revisions from the search * * @return boolean true if the galleries array is not empty */ private static function _build_mla_galleries($option_name, &$galleries_array, $shortcode, $exclude_revisions) { global $wpdb, $post; if (is_array($galleries_array)) { if (!empty($galleries_array)) { return true; } else { return false; } } $option_value = MLACore::mla_get_option($option_name); if ('disabled' == $option_value) { return false; } elseif ('cached' == $option_value) { $galleries_array = get_transient(MLA_OPTION_PREFIX . 't_' . $option_name); if (is_array($galleries_array)) { if (!empty($galleries_array)) { return true; } else { return false; } } else { $galleries_array = NULL; } } // cached /* * The MLAShortcodes class is only loaded when needed. */ if (!class_exists('MLAShortcodes')) { require_once MLA_PLUGIN_PATH . 'includes/class-mla-shortcodes.php'; } /* * $galleries_array is null, so build the array */ $galleries_array = array(); if ($exclude_revisions) { $exclude_revisions = "(post_type <> 'revision') AND "; } else { $exclude_revisions = ''; } if (MLAQuery::$wp_4dot0_plus) { $like = $wpdb->esc_like($shortcode); } else { $like = like_escape($shortcode); } $results = $wpdb->get_results($wpdb->prepare("\r\n\t\t\t\tSELECT ID, post_type, post_status, post_title, post_content\r\n\t\t\t\tFROM {$wpdb->posts}\r\n\t\t\t\tWHERE {$exclude_revisions}(\r\n\t\t\t\t\tCONVERT(`post_content` USING utf8 )\r\n\t\t\t\t\tLIKE %s)\r\n\t\t\t\t", "%{$like}%")); if (empty($results)) { return false; } foreach ($results as $result) { $count = preg_match_all("/\\{$shortcode}([^\\]]*)\\]/", $result->post_content, $matches, PREG_PATTERN_ORDER); if ($count) { $result_id = $result->ID; $galleries_array[$result_id]['parent_title'] = $result->post_title; $galleries_array[$result_id]['parent_type'] = $result->post_type; $galleries_array[$result_id]['parent_status'] = $result->post_status; $galleries_array[$result_id]['results'] = array(); $galleries_array[$result_id]['galleries'] = array(); $instance = 0; foreach ($matches[1] as $index => $match) { /* * Filter out shortcodes that are not an exact match */ if (empty($match) || ' ' == substr($match, 0, 1)) { $instance++; /* * Remove trailing "/" from XHTML-style self-closing shortcodes */ $galleries_array[$result_id]['galleries'][$instance]['query'] = trim(rtrim($matches[1][$index], '/')); $galleries_array[$result_id]['galleries'][$instance]['results'] = array(); $post = $result; // set global variable for mla_gallery_shortcode $attachments = MLAShortcodes::mla_get_shortcode_attachments($result_id, $galleries_array[$result_id]['galleries'][$instance]['query'] . ' cache_results=false update_post_meta_cache=false update_post_term_cache=false where_used_query=this-is-a-where-used-query'); if (is_string($attachments)) { /* translators: 1: post_type, 2: post_title, 3: post ID, 4: query string, 5: error message */ trigger_error(htmlentities(sprintf(__('(%1$s) %2$s (ID %3$d) query "%4$s" failed, returning "%5$s"', 'media-library-assistant'), $result->post_type, $result->post_title, $result->ID, $galleries_array[$result_id]['galleries'][$instance]['query'], $attachments)), E_USER_WARNING); } elseif (!empty($attachments)) { foreach ($attachments as $attachment) { $galleries_array[$result_id]['results'][$attachment->ID] = $attachment->ID; $galleries_array[$result_id]['galleries'][$instance]['results'][] = $attachment->ID; } } } // exact match } // foreach $match } // if $count } // foreach $result /* * Maybe cache the results */ if ('cached' == $option_value) { set_transient(MLA_OPTION_PREFIX . 't_' . $option_name, $galleries_array, 900); // fifteen minutes } return true; }
/** * Filter the MLA_List_Table columns * * Inserts the language columns just after the item thumbnail column. * Defined as static because it is called before the List_Table object is created. * Added as a filter when the file is loaded. * * @since 2.11 * * @param array $columns An array of columns. * format: column_slug => Column Label * * @return array updated array of columns. */ public static function mla_list_table_get_columns($columns) { global $sitepress, $wpdb; if (is_null(self::$language_columns) && $sitepress->is_translated_post_type('attachment')) { /* * Build language management columns */ $show_language = 'checked' == MLACore::mla_get_option('language_column', false, false, MLA_WPML::$mla_language_option_definitions); $current_language = $sitepress->get_current_language(); $languages = $sitepress->get_active_languages(); $view_status = isset($_REQUEST['status']) ? $_REQUEST['status'] : ''; if (1 < count($languages) && $view_status != 'trash') { $show_translations = 'checked' == MLACore::mla_get_option('translations_column', false, false, MLA_WPML::$mla_language_option_definitions); } else { $show_translations = false; } self::$language_columns = array(); if ($show_language && 'all' == $current_language) { self::$language_columns['language'] = __('Language', 'wpml-media'); } if ($show_translations) { $language_codes = array(); foreach ($languages as $language) { if ($current_language != $language['code']) { $language_codes[] = $language['code']; } } $results = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\tSELECT f.lang_code, f.flag, f.from_template, l.name\n\t\t\t\t\tFROM {$wpdb->prefix}icl_flags f\n\t\t\t\t\t\tJOIN {$wpdb->prefix}icl_languages_translations l ON f.lang_code = l.language_code\n\t\t\t\t\tWHERE l.display_language_code = %s AND f.lang_code IN(" . wpml_prepare_in($language_codes) . ")", $sitepress->get_admin_language())); $wp_upload_dir = wp_upload_dir(); foreach ($results as $result) { if ($result->from_template) { $flag_path = $wp_upload_dir['baseurl'] . '/flags/'; } else { $flag_path = ICL_PLUGIN_URL . '/res/flags/'; } $flags[$result->lang_code] = '<img src="' . $flag_path . $result->flag . '" width="18" height="12" alt="' . $result->name . '" title="' . $result->name . '" />'; } $flags_column = ''; foreach ($languages as $language) { if (isset($flags[$language['code']])) { $flags_column .= $flags[$language['code']]; } } self::$language_columns['icl_translations'] = $flags_column; } // multi-language not trash } // add columns if (!empty(self::$language_columns)) { $end = array_slice($columns, 2); $columns = array_slice($columns, 0, 2); $columns = array_merge($columns, self::$language_columns, $end); } return $columns; }
/** * Define the Media/Assistant submenu screen to the Admin Columns plugin * * @since 2.22 * * @param array $storage_models List of storage model class instances ( [key] => [CPAC_Storage_Model object] ) * @param object $cpac CPAC, the root CodePress Admin Columns object */ public static function admin_columns_support($storage_models, $cpac) { require_once MLA_PLUGIN_PATH . 'includes/class-mla-admin-columns-support.php'; MLACore::$admin_columns_storage_model = new CPAC_Storage_Model_MLA(); /* * Put MLA before/after WP Media Library so is_columns_screen() will work */ $new_models = array(); foreach ($storage_models as $key => $model) { if ('wp-media' == $key) { if (version_compare(CPAC_VERSION, '2.4.9', '>=')) { $new_models[$key] = $model; $new_models[MLACore::$admin_columns_storage_model->key] = MLACore::$admin_columns_storage_model; } else { $new_models[MLACore::$admin_columns_storage_model->key] = MLACore::$admin_columns_storage_model; $new_models[$key] = $model; } } else { $new_models[$key] = $model; } } /* * If we didn't find wp-media, add our entry to the end */ if (count($storage_models) == count($new_models)) { $new_models[$storage_model->key] = MLACore::$admin_columns_storage_model; } return $new_models; }
/** * Extra controls to be displayed between bulk actions and pagination * * Modeled after class-wp-posts-list-table.php in wp-admin/includes. * * @since 0.1 * * @param string 'top' or 'bottom', i.e., above or below the table rows * * @return array Contains all the bulk actions: 'slugs'=>'Visible Titles' */ function extra_tablenav($which) { echo '<div class="alignleft actions">'; if ('top' == $which) { $this->months_dropdown('attachment'); echo self::mla_get_taxonomy_filter_dropdown(isset($_REQUEST['mla_filter_term']) ? $_REQUEST['mla_filter_term'] : 0); submit_button(__('Filter', 'media-library-assistant'), 'secondary', 'mla_filter', false, array('id' => 'post-query-submit')); $term_search_taxonomies = MLACore::mla_supported_taxonomies('term-search'); if (!empty($term_search_taxonomies)) { submit_button(__('Terms Search', 'media-library-assistant'), 'secondary', 'mla_filter', false, array('id' => 'mla-terms-search-open', 'onclick' => 'mlaTaxonomy.termsSearch.open()')); } } if (self::mla_submenu_arguments(true) != self::mla_submenu_arguments(false)) { submit_button(__('Clear Filter-by', 'media-library-assistant'), 'button apply', 'clear_filter_by', false); } if ($this->is_trash && current_user_can('edit_others_posts')) { submit_button(__('Empty Trash', 'media-library-assistant'), 'button apply', 'delete_all', false); } echo '</div>'; }
<?php /** * Backbone/JavaScript template for Media Library Assistant Media Manager enhancements * * @package Media Library Assistant * @since 1.80 */ /** * Harmless declaration to suppress phpDocumentor "No page-level DocBlock" error * * @global $post */ global $post; $supported_taxonomies = MLACore::mla_supported_taxonomies('support'); if (empty($supported_taxonomies)) { $terms_style = 'style="display: none;"'; } else { $terms_style = 'style="display: inline;"'; } ?> <script type="text/html" id="tmpl-mla-search-box"> <div style="display: inline-block"> <label class="screen-reader-text" for="mla-media-search-input"><?php _e('Search Media', 'media-library-assistant'); ?> :</label> <input name="s[mla_search_value]" class="search" id="mla-media-search-input" style="width: 100%; max-width: 100%" type="search" value="{{ data.searchValue }}" placeholder="{{ data.searchBoxPlaceholder }}" /> </div> <input name="mla_search_submit" class="button media-button mla-search-submit-button" id="mla-search-submit" type="submit" style="float: none" value="<?php _e('Search', 'media-library-assistant');
/** * Render and manage iptc/exif support options * * @since 1.00 * @uses $mla_option_templates contains row and table templates * * @param string 'render', 'update', 'delete', or 'reset' * @param string option name, e.g., 'iptc_exif_mapping' * @param array option parameters * @param array Optional. null (default) for 'render' else option data, e.g., $_REQUEST * * @return string HTML table row markup for 'render' else message(s) reflecting the results of the operation. */ public static function mla_iptc_exif_option_handler($action, $key, $value, $args = NULL) { $current_values = MLACore::mla_get_option('iptc_exif_mapping'); switch ($action) { case 'render': switch ($key) { case 'iptc_exif_standard_mapping': $row_template = MLAOptions::$mla_option_templates['iptc-exif-standard-row']; $table_rows = ''; foreach ($current_values['standard'] as $row_name => $row_value) { $row_values = array('key' => esc_attr($row_name), 'name_attr' => esc_attr($row_value['name']), 'name' => esc_html($row_value['name']), 'iptc_field_options' => MLAOptions::_compose_iptc_option_list($row_value['iptc_value']), 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => esc_attr($row_value['exif_value']), 'iptc_selected' => '', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => '', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant')); if ($row_value['iptc_first']) { $row_values['iptc_selected'] = 'selected="selected"'; } else { $row_values['exif_selected'] = 'selected="selected"'; } if ($row_value['keep_existing']) { $row_values['keep_selected'] = 'selected="selected"'; } else { $row_values['replace_selected'] = 'selected="selected"'; } $table_rows .= MLAData::mla_parse_template($row_template, $row_values); } // foreach row $option_values = array('Field Title' => __('Field Title', 'media-library-assistant'), 'IPTC Value' => __('IPTC Value', 'media-library-assistant'), 'EXIF/Template Value' => __('EXIF/Template Value', 'media-library-assistant'), 'Priority' => __('Priority', 'media-library-assistant'), 'Existing Text' => __('Existing Text', 'media-library-assistant'), 'table_rows' => $table_rows, 'help' => $value['help']); return MLAData::mla_parse_template(MLAOptions::$mla_option_templates['iptc-exif-standard-table'], $option_values); case 'iptc_exif_taxonomy_mapping': $row_template = MLAOptions::$mla_option_templates['iptc-exif-taxonomy-row']; $select_template = MLAOptions::$mla_option_templates['iptc-exif-select']; $table_rows = ''; $taxonomies = get_taxonomies(array('show_ui' => true), 'objects'); foreach ($taxonomies as $row_name => $row_value) { if (!MLACore::mla_taxonomy_support($row_name, 'support')) { continue; } $row_values = array('key' => esc_attr($row_name), 'name' => esc_html($row_value->labels->name), 'hierarchical' => (string) $row_value->hierarchical, 'iptc_field_options' => '', 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => '', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => '', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant'), 'delimiters_size' => 4, 'delimiters_text' => '', 'parent_select' => ''); if (array_key_exists($row_name, $current_values['taxonomy'])) { $current_value = $current_values['taxonomy'][$row_name]; $row_values['iptc_field_options'] = MLAOptions::_compose_iptc_option_list($current_value['iptc_value']); $row_values['exif_text'] = esc_attr($current_value['exif_value']); if ($current_value['iptc_first']) { $row_values['iptc_selected'] = 'selected="selected"'; } else { $row_values['exif_selected'] = 'selected="selected"'; } if ($current_value['keep_existing']) { $row_values['keep_selected'] = 'selected="selected"'; } else { $row_values['replace_selected'] = 'selected="selected"'; } $row_values['delimiters_text'] = $current_value['delimiters']; if ($row_value->hierarchical) { $parent = isset($current_value['parent']) ? (int) $current_value['parent'] : 0; $select_values = array('array' => 'taxonomy', 'key' => esc_attr($row_name), 'element' => 'parent', 'options' => MLAOptions::_compose_parent_option_list($row_name, $parent)); $row_values['parent_select'] = MLAData::mla_parse_template($select_template, $select_values); } } else { $row_values['iptc_field_options'] = MLAOptions::_compose_iptc_option_list('none'); $row_values['iptc_selected'] = 'selected="selected"'; $row_values['keep_selected'] = 'selected="selected"'; if ($row_value->hierarchical) { $select_values = array('array' => 'taxonomy', 'key' => esc_attr($row_name), 'element' => 'parent', 'options' => MLAOptions::_compose_parent_option_list($row_name, 0)); $row_values['parent_select'] = MLAData::mla_parse_template($select_template, $select_values); } } $table_rows .= MLAData::mla_parse_template($row_template, $row_values); } // foreach row $option_values = array('Field Title' => __('Field Title', 'media-library-assistant'), 'IPTC Value' => __('IPTC Value', 'media-library-assistant'), 'EXIF/Template Value' => __('EXIF/Template Value', 'media-library-assistant'), 'Priority' => __('Priority', 'media-library-assistant'), 'Existing Text' => __('Existing Text', 'media-library-assistant'), 'Delimiter(s)' => __('Delimiter(s)', 'media-library-assistant'), 'Parent' => __('Parent', 'media-library-assistant'), 'table_rows' => $table_rows, 'help' => $value['help']); return MLAData::mla_parse_template(MLAOptions::$mla_option_templates['iptc-exif-taxonomy-table'], $option_values); case 'iptc_exif_custom_mapping': if (empty($current_values['custom'])) { $table_rows = MLAData::mla_parse_template(MLAOptions::$mla_option_templates['iptc-exif-custom-empty-row'], array('No Mapping Rules' => __('No Custom Field Mapping Rules Defined', 'media-library-assistant'), 'column_count' => 5)); } else { $row_template = MLAOptions::$mla_option_templates['iptc-exif-custom-rule-row']; $table_rows = ''; $index = 0; } /* * One row for each existing rule, case insensitive "natural order" */ $sorted_keys = array(); foreach ($current_values['custom'] as $row_name => $current_value) { $sorted_keys[$current_value['name']] = $current_value['name']; } natcasesort($sorted_keys); $sorted_names = array(); foreach ($sorted_keys as $row_name) { $sorted_names[$row_name] = array(); } /* * Allow for multiple rules mapping the same name (an old bug) */ foreach ($current_values['custom'] as $row_name => $current_value) { $sorted_names[$current_value['name']][] = $row_name; } foreach ($sorted_names as $sorted_keys) { foreach ($sorted_keys as $row_name) { $current_value = $current_values['custom'][$row_name]; $row_values = array('column_count' => 5, 'column_count_meta' => 5 - 2, 'index' => $index++, 'key' => esc_attr($row_name), 'name_attr' => esc_attr($current_value['name']), 'name' => esc_html($current_value['name']), 'iptc_field_options' => MLAOptions::_compose_iptc_option_list($current_value['iptc_value']), 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => esc_attr($current_value['exif_value']), 'iptc_selected' => '', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => '', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant'), 'Format' => __('Format', 'media-library-assistant'), 'native_format' => '', 'Native' => __('Native', 'media-library-assistant'), 'commas_format' => '', 'Commas' => __('Commas', 'media-library-assistant'), 'raw_format' => '', 'Raw' => __('Raw', 'media-library-assistant'), 'Option' => __('Option', 'media-library-assistant'), 'text_option' => '', 'Text' => __('Text', 'media-library-assistant'), 'single_option' => '', 'Single' => __('Single', 'media-library-assistant'), 'export_option' => '', 'Export' => __('Export', 'media-library-assistant'), 'array_option' => '', 'Array' => __('Array', 'media-library-assistant'), 'multi_option' => '', 'Multi' => __('Multi', 'media-library-assistant'), 'no_null_checked' => '', 'Delete NULL values' => __('Delete NULL values', 'media-library-assistant'), 'Delete Rule' => __('Delete Rule', 'media-library-assistant'), 'Delete Field' => __('Delete Rule AND Field', 'media-library-assistant'), 'Update Rule' => __('Update Rule', 'media-library-assistant'), 'Map All Attachments' => __('Map All Attachments', 'media-library-assistant')); if ($current_value['iptc_first']) { $row_values['iptc_selected'] = 'selected="selected"'; } else { $row_values['exif_selected'] = 'selected="selected"'; } if ($current_value['keep_existing']) { $row_values['keep_selected'] = 'selected="selected"'; } else { $row_values['replace_selected'] = 'selected="selected"'; } switch ($current_value['format']) { case 'commas': $row_values['commas_format'] = 'selected="selected"'; break; case 'raw': $row_values['raw_format'] = 'selected="selected"'; break; default: $row_values['native_format'] = 'selected="selected"'; } // format switch ($current_value['option']) { case 'single': $row_values['single_option'] = 'selected="selected"'; break; case 'export': $row_values['export_option'] = 'selected="selected"'; break; case 'array': $row_values['array_option'] = 'selected="selected"'; break; case 'multi': $row_values['multi_option'] = 'selected="selected"'; break; default: $row_values['text_option'] = 'selected="selected"'; } // option if ($current_value['no_null']) { $row_values['no_null_checked'] = 'checked="checked"'; } $table_rows .= MLAData::mla_parse_template($row_template, $row_values); } // foreach current_values key } // foreach sorted_name /* * Add a row for defining a new rule, existing Custom Field */ $row_template = MLAOptions::$mla_option_templates['iptc-exif-custom-new-rule-row']; $row_values = array('column_count' => 5, 'column_count_meta' => 5 - 2, 'Add new Rule' => __('Add a new Mapping Rule', 'media-library-assistant'), 'index' => MLACoreOptions::MLA_NEW_CUSTOM_RULE, 'field_name_options' => MLAOptions::_compose_custom_field_option_list('none', $current_values['custom']), 'iptc_field_options' => MLAOptions::_compose_iptc_option_list('none'), 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => 'selected="selected"', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => 'selected="selected"', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant'), 'Format' => __('Format', 'media-library-assistant'), 'native_format' => 'selected="selected"', 'Native' => __('Native', 'media-library-assistant'), 'commas_format' => '', 'Commas' => __('Commas', 'media-library-assistant'), 'raw_format' => '', 'Raw' => __('Raw', 'media-library-assistant'), 'Option' => __('Option', 'media-library-assistant'), 'text_option' => '', 'Text' => __('Text', 'media-library-assistant'), 'single_option' => '', 'Single' => __('Single', 'media-library-assistant'), 'export_option' => '', 'Export' => __('Export', 'media-library-assistant'), 'array_option' => '', 'Array' => __('Array', 'media-library-assistant'), 'multi_option' => '', 'Multi' => __('Multi', 'media-library-assistant'), 'no_null_checked' => '', 'Delete NULL values' => __('Delete NULL values', 'media-library-assistant'), 'Add Rule' => __('Add Rule', 'media-library-assistant'), 'Map All Attachments' => __('Add Rule and Map All Attachments', 'media-library-assistant')); $table_rows .= MLAData::mla_parse_template($row_template, $row_values); /* * Add a row for defining a new rule, new Custom Field */ $row_template = MLAOptions::$mla_option_templates['iptc-exif-custom-new-field-row']; $row_values = array('column_count' => 5, 'column_count_meta' => 5 - 2, 'Add new Field' => __('Add a new Field and Mapping Rule', 'media-library-assistant'), 'index' => MLACoreOptions::MLA_NEW_CUSTOM_FIELD, 'field_name_size' => '24', 'iptc_field_options' => MLAOptions::_compose_iptc_option_list('none'), 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => 'selected="selected"', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => 'selected="selected"', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant'), 'Format' => __('Format', 'media-library-assistant'), 'native_format' => 'selected="selected"', 'Native' => __('Native', 'media-library-assistant'), 'commas_format' => '', 'Commas' => __('Commas', 'media-library-assistant'), 'raw_format' => '', 'Raw' => __('Raw', 'media-library-assistant'), 'Option' => __('Option', 'media-library-assistant'), 'text_option' => '', 'Text' => __('Text', 'media-library-assistant'), 'single_option' => '', 'Single' => __('Single', 'media-library-assistant'), 'export_option' => '', 'Export' => __('Export', 'media-library-assistant'), 'array_option' => '', 'Array' => __('Array', 'media-library-assistant'), 'multi_option' => '', 'Multi' => __('Multi', 'media-library-assistant'), 'no_null_checked' => '', 'Delete NULL values' => __('Delete NULL values', 'media-library-assistant'), 'Add Field' => __('Add Field', 'media-library-assistant'), 'Map All Attachments' => __('Add Field and Map All Attachments', 'media-library-assistant')); $table_rows .= MLAData::mla_parse_template($row_template, $row_values); $option_values = array('Field Title' => __('Field Title', 'media-library-assistant'), 'IPTC Value' => __('IPTC Value', 'media-library-assistant'), 'EXIF/Template Value' => __('EXIF/Template Value', 'media-library-assistant'), 'Priority' => __('Priority', 'media-library-assistant'), 'Existing Text' => __('Existing Text', 'media-library-assistant'), 'table_rows' => $table_rows, 'help' => $value['help']); return MLAData::mla_parse_template(MLAOptions::$mla_option_templates['iptc-exif-custom-table'], $option_values); default: /* translators: 1: ERROR tag 2: option name */ return '<br>' . sprintf(__('%1$s: Render unknown custom %2$s.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $key) . "\r\n"; } // switch $key // switch $key case 'update': case 'delete': $settings_changed = false; $messages = ''; switch ($key) { case 'iptc_exif_standard_mapping': $results = MLAOptions::_update_iptc_exif_standard_mapping($current_values, $args); $messages .= $results['message']; $current_values = $results['values']; $settings_changed = $results['changed']; break; case 'iptc_exif_taxonomy_mapping': $results = MLAOptions::_update_iptc_exif_taxonomy_mapping($current_values, $args); $messages .= $results['message']; $current_values = $results['values']; $settings_changed = $results['changed']; break; case 'iptc_exif_custom_mapping': $results = MLAOptions::_update_iptc_exif_custom_mapping($current_values, $args); $messages .= $results['message']; $current_values = $results['values']; $settings_changed = $results['changed']; break; case 'iptc_exif_mapping': $results = MLAOptions::_update_iptc_exif_standard_mapping($current_values, $args); $messages .= $results['message']; $current_values = $results['values']; $settings_changed = $results['changed']; $results = MLAOptions::_update_iptc_exif_taxonomy_mapping($current_values, $args); $messages .= $results['message']; $current_values = $results['values']; $settings_changed |= $results['changed']; $results = MLAOptions::_update_iptc_exif_custom_mapping($current_values, $args); $messages .= $results['message']; $current_values = $results['values']; $settings_changed |= $results['changed']; break; default: /* translators: 1: ERROR tag 2: option name */ return '<br>' . sprintf(__('%1$s: Update/delete unknown custom %2$s.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $key) . "\r\n"; } // switch $key if ($settings_changed) { $settings_changed = MLACore::mla_update_option('iptc_exif_mapping', $current_values); if ($settings_changed) { $results = __('IPTC/EXIF mapping settings updated.', 'media-library-assistant') . "\r\n"; } else { $results = __('ERROR', 'media-library-assistant') . ': ' . __('IPTC/EXIF settings update failed.', 'media-library-assistant') . "\r\n"; } } else { $results = __('IPTC/EXIF no mapping changes detected.', 'media-library-assistant') . "\r\n"; } return $results . $messages; case 'reset': switch ($key) { case 'iptc_exif_standard_mapping': $current_values['standard'] = MLACoreOptions::$mla_option_definitions['iptc_exif_mapping']['std']['standard']; $settings_changed = MLACore::mla_update_option('iptc_exif_mapping', $current_values); if ($settings_changed) { /* translators: 1: field type */ return sprintf(__('%1$s settings saved.', 'media-library-assistant'), 'IPTC/EXIF ' . __('Standard field', 'media-library-assistant')) . "\r\n"; } else { /* translators: 1: ERROR tag 2: field type */ return sprintf(__('%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), __('Standard field', 'media-library-assistant')) . "\r\n"; } case 'iptc_exif_taxonomy_mapping': $current_values['taxonomy'] = MLACoreOptions::$mla_option_definitions['iptc_exif_mapping']['std']['taxonomy']; $settings_changed = MLACore::mla_update_option('iptc_exif_mapping', $current_values); if ($settings_changed) { /* translators: 1: field type */ return sprintf(__('%1$s settings saved.', 'media-library-assistant'), 'IPTC/EXIF ' . __('Taxonomy term', 'media-library-assistant')) . "\r\n"; } else { /* translators: 1: ERROR tag 2: field type */ return sprintf(__('%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), __('Taxonomy term', 'media-library-assistant')) . "\r\n"; } case 'iptc_exif_custom_mapping': $current_values['custom'] = MLACoreOptions::$mla_option_definitions['iptc_exif_mapping']['std']['custom']; $settings_changed = MLACore::mla_update_option('iptc_exif_mapping', $current_values); if ($settings_changed) { /* translators: 1: field type */ return sprintf(__('%1$s settings saved.', 'media-library-assistant'), 'IPTC/EXIF ' . __('Custom field', 'media-library-assistant')) . "\r\n"; } else { /* translators: 1: ERROR tag 2: field type */ return sprintf(__('%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), __('Custom field', 'media-library-assistant')) . "\r\n"; } case 'iptc_exif_mapping': MLACore::mla_delete_option($key); /* translators: 1: option name, e.g., taxonomy_support */ return '<br>' . sprintf(__('Reset custom %1$s', 'media-library-assistant'), $key) . "\r\n"; default: /* translators: 1: ERROR tag 2: option name, e.g., taxonomy_support */ return '<br>' . sprintf(__('%1$s: Reset unknown custom %2$s', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $key) . "\r\n"; } // switch $key // switch $key default: /* translators: 1: ERROR tag 2: option name 3: action, e.g., update, delete, reset */ return '<br>' . sprintf(__('%1$s: Custom %2$s unknown action "%3$s"', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $key, $action) . "\r\n"; } // switch $action }
/** * Put user-defined markup templates to $mla_custom_templates and database * * @since 2.30 * * @param array name => value for all user-defined markup templates * @return boolean true if success, false if failure */ public static function mla_put_markup_templates($templates) { if (MLACore::mla_update_option('markup_templates', $templates)) { MLATemplate_Support::mla_load_custom_templates(); return true; } return false; }
/** * Registers meta boxes for the Edit Media screen. * Declared public because it is an action. * * @since 0.80 * * @param string type of the current post, e.g., 'attachment' (optional, default 'unknown') * @param object current post (optional, default (object) array ( 'ID' => 0 )) * * @return void */ public static function mla_add_meta_boxes_action($post_type = 'unknown', $post = NULL) { /* * Plugins call this action with varying numbers of arguments! */ if (NULL == $post) { $post = (object) array('ID' => 0); } if ('attachment' != $post_type) { return; } /* * Use the mla_checklist_meta_box callback function for MLA supported taxonomies */ global $wp_meta_boxes; $screen = convert_to_screen('attachment'); $page = $screen->id; if ('checked' == MLACore::mla_get_option(MLACore::MLA_EDIT_MEDIA_SEARCH_TAXONOMY)) { $taxonomies = get_taxonomies(array('show_ui' => true), 'objects'); foreach ($taxonomies as $key => $value) { if (MLACore::mla_taxonomy_support($key)) { if ($value->hierarchical) { foreach (array_keys($wp_meta_boxes[$page]) as $a_context) { foreach (array('high', 'sorted', 'core', 'default', 'low') as $a_priority) { if (isset($wp_meta_boxes[$page][$a_context][$a_priority][$key . 'div'])) { $box =& $wp_meta_boxes[$page][$a_context][$a_priority][$key . 'div']; if ('post_categories_meta_box' == $box['callback']) { $box['callback'] = 'MLACore::mla_checklist_meta_box'; } } // isset $box } // foreach priority } // foreach context } elseif (MLACore::mla_taxonomy_support($key, 'flat-checklist')) { foreach (array_keys($wp_meta_boxes[$page]) as $a_context) { foreach (array('high', 'sorted', 'core', 'default', 'low') as $a_priority) { if (isset($wp_meta_boxes[$page][$a_context][$a_priority]['tagsdiv-' . $key])) { $box =& $wp_meta_boxes[$page][$a_context][$a_priority]['tagsdiv-' . $key]; if ('post_tags_meta_box' == $box['callback']) { $box['callback'] = 'MLACore::mla_checklist_meta_box'; } } // isset $box } // foreach priority } // foreach context } // flat checklist } // is supported } // foreach } // MLA_EDIT_MEDIA_SEARCH_TAXONOMY if ('checked' == MLACore::mla_get_option(MLACore::MLA_EDIT_MEDIA_META_BOXES)) { $active_boxes = apply_filters('mla_edit_media_meta_boxes', array('mla-parent-info' => 'mla-parent-info', 'mla-menu-order' => 'mla-menu-order', 'mla-image-metadata' => 'mla-image-metadata', 'mla-featured-in' => 'mla-featured-in', 'mla-inserted-in' => 'mla-inserted-in', 'mla-gallery-in' => 'mla-gallery-in', 'mla-mla-gallery-in' => 'mla-mla-gallery-in')); if (isset($active_boxes['mla-parent-info'])) { add_meta_box('mla-parent-info', __('Parent Info', 'media-library-assistant'), 'MLAEdit::mla_parent_info_handler', 'attachment', 'normal', 'core'); } if (isset($active_boxes['mla-menu-order'])) { add_meta_box('mla-menu-order', __('Menu Order', 'media-library-assistant'), 'MLAEdit::mla_menu_order_handler', 'attachment', 'normal', 'core'); } if (isset($active_boxes['mla-image-metadata'])) { $image_metadata = get_metadata('post', $post->ID, '_wp_attachment_metadata', true); if (!empty($image_metadata)) { add_meta_box('mla-image-metadata', __('Attachment Metadata', 'media-library-assistant'), 'MLAEdit::mla_image_metadata_handler', 'attachment', 'normal', 'core'); } } if (isset($active_boxes['mla-featured-in']) && MLACore::$process_featured_in) { add_meta_box('mla-featured-in', __('Featured in', 'media-library-assistant'), 'MLAEdit::mla_featured_in_handler', 'attachment', 'normal', 'core'); } if (isset($active_boxes['mla-inserted-in']) && MLACore::$process_inserted_in) { add_meta_box('mla-inserted-in', __('Inserted in', 'media-library-assistant'), 'MLAEdit::mla_inserted_in_handler', 'attachment', 'normal', 'core'); } if (isset($active_boxes['mla-gallery-in']) && MLACore::$process_gallery_in) { add_meta_box('mla-gallery-in', __('Gallery in', 'media-library-assistant'), 'MLAEdit::mla_gallery_in_handler', 'attachment', 'normal', 'core'); } if (isset($active_boxes['mla-mla-gallery-in']) && MLACore::$process_mla_gallery_in) { add_meta_box('mla-mla-gallery-in', __('MLA Gallery in', 'media-library-assistant'), 'MLAEdit::mla_mla_gallery_in_handler', 'attachment', 'normal', 'core'); } } }