/** * 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']; } } MLAOptions::mla_update_option(MLAOptions::MLA_UPLOAD_MIMES, $mla_upload_mimes); return true; }
/** * 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 = self::mla_get_option('iptc_exif_mapping'); switch ($action) { case 'render': switch ($key) { case 'iptc_exif_standard_mapping': $row_template = self::$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' => self::_compose_iptc_option_list($row_value['iptc_value']), 'exif_size' => self::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(self::$mla_option_templates['iptc-exif-standard-table'], $option_values); case 'iptc_exif_taxonomy_mapping': $row_template = self::$mla_option_templates['iptc-exif-taxonomy-row']; $select_template = self::$mla_option_templates['iptc-exif-select']; $table_rows = ''; $taxonomies = get_taxonomies(array('show_ui' => true), 'objects'); foreach ($taxonomies as $row_name => $row_value) { $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' => self::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'] = self::_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' => self::_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'] = self::_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' => self::_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(self::$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(self::$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 = self::$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' => self::_compose_iptc_option_list($current_value['iptc_value']), 'exif_size' => self::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 = self::$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' => self::MLA_NEW_CUSTOM_RULE, 'field_name_options' => self::_compose_custom_field_option_list('none', $current_values['custom']), 'iptc_field_options' => self::_compose_iptc_option_list('none'), 'exif_size' => self::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 = self::$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' => self::MLA_NEW_CUSTOM_FIELD, 'field_name_size' => '24', 'iptc_field_options' => self::_compose_iptc_option_list('none'), 'exif_size' => self::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(self::$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 = self::_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 = self::_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 = self::_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 = self::_update_iptc_exif_standard_mapping($current_values, $args); $messages .= $results['message']; $current_values = $results['values']; $settings_changed = $results['changed']; $results = self::_update_iptc_exif_taxonomy_mapping($current_values, $args); $messages .= $results['message']; $current_values = $results['values']; $settings_changed |= $results['changed']; $results = self::_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 = MLAOptions::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'] = self::$mla_option_definitions['iptc_exif_mapping']['std']['standard']; $settings_changed = MLAOptions::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'] = self::$mla_option_definitions['iptc_exif_mapping']['std']['taxonomy']; $settings_changed = MLAOptions::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'] = self::$mla_option_definitions['iptc_exif_mapping']['std']['custom']; $settings_changed = MLAOptions::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': self::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 }
/** * 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.', '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.'; return $page_content; } } else { $page_content['message'] = "ERROR: The import settings dropdown selection is missing."; return $page_content; } $settings = @file_get_contents($filename, false); if (false === $settings) { $error_info = error_get_last(); error_log('ERROR: _import_settings $error_info = ' . 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 = '.'; } $page_content['message'] = "ERROR: reading the settings file ( {$filename} ){$php_errormsg}"; return $page_content; } $settings = unserialize($settings); $updated_count = 0; $unchanged_count = 0; foreach ($settings as $key => $value) { if (MLAOptions::mla_update_option($key, $value)) { $updated_count++; $message_list .= "<br>{$key} updated"; } else { $unchanged_count++; $message_list .= "<br>{$key} unchanged"; } } $page_content['message'] = "Settings imported; {$updated_count} updated, {$unchanged_count} unchanged."; /* * Uncomment this for debugging. */ //$page_content['message'] .= $message_list; return $page_content; }
/** * 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) { if (MLAOptions::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; }
/** * 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 = self::mla_get_option('iptc_exif_mapping'); switch ($action) { case 'render': switch ($key) { case 'iptc_exif_standard_mapping': $row_template = self::$mla_option_templates['iptc-exif-standard-row']; $table_rows = ''; foreach ($current_values['standard'] as $row_name => $row_value) { $row_values = array('key' => $row_name, 'name' => $row_value['name'], 'iptc_field_options' => self::_compose_iptc_option_list($row_value['iptc_value']), 'exif_size' => self::MLA_EXIF_SIZE, 'exif_text' => $row_value['exif_value'], 'iptc_selected' => '', 'exif_selected' => '', 'keep_selected' => '', 'replace_selected' => ''); 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('table_rows' => $table_rows, 'help' => $value['help']); return MLAData::mla_parse_template(self::$mla_option_templates['iptc-exif-standard-table'], $option_values); case 'iptc_exif_taxonomy_mapping': $row_template = self::$mla_option_templates['iptc-exif-taxonomy-row']; $select_template = self::$mla_option_templates['iptc-exif-select']; $table_rows = ''; $taxonomies = get_taxonomies(array('show_ui' => true), 'objects'); foreach ($taxonomies as $row_name => $row_value) { $row_values = array('key' => $row_name, 'name' => esc_html($row_value->labels->name), 'hierarchical' => (string) $row_value->hierarchical, 'iptc_field_options' => '', 'exif_size' => self::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => '', 'exif_selected' => '', 'keep_selected' => '', 'replace_selected' => '', 'parent_select' => ''); if (array_key_exists($row_name, $current_values['taxonomy'])) { $current_value = $current_values['taxonomy'][$row_name]; $row_values['iptc_field_options'] = self::_compose_iptc_option_list($current_value['iptc_value']); $row_values['exif_text'] = $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"'; } if ($row_value->hierarchical) { $parent = isset($current_value['parent']) ? (int) $current_value['parent'] : 0; $select_values = array('array' => 'taxonomy', 'key' => $row_name, 'element' => 'parent', 'options' => self::_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'] = self::_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' => $row_name, 'element' => 'parent', 'options' => self::_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('table_rows' => $table_rows, 'help' => $value['help']); return MLAData::mla_parse_template(self::$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(self::$mla_option_templates['iptc-exif-custom-empty-row'], array('column_count' => 5)); } else { $row_template = self::$mla_option_templates['iptc-exif-custom-rule-row']; $table_rows = ''; } /* * One row for each existing rule */ ksort($current_values['custom']); foreach ($current_values['custom'] as $row_name => $current_value) { $row_values = array('column_count' => 5, 'key' => $row_name, 'name' => $row_name, 'iptc_field_options' => '', 'exif_size' => self::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => '', 'exif_selected' => '', 'keep_selected' => '', 'replace_selected' => ''); $row_values['iptc_field_options'] = self::_compose_iptc_option_list($current_value['iptc_value']); $row_values['exif_text'] = $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"'; } $table_rows .= MLAData::mla_parse_template($row_template, $row_values); } // foreach existing rule /* * Add a row for defining a new rule, existing Custom Field */ $row_template = self::$mla_option_templates['iptc-exif-custom-new-rule-row']; $row_values = array('column_count' => 5, 'key' => self::MLA_NEW_CUSTOM_RULE, 'field_name_options' => self::_compose_custom_field_option_list('none', $current_values['custom']), 'iptc_field_options' => self::_compose_iptc_option_list('none'), 'exif_size' => self::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => 'selected="selected"', 'exif_selected' => '', 'keep_selected' => 'selected="selected"', 'replace_selected' => ''); $table_rows .= MLAData::mla_parse_template($row_template, $row_values); /* * Add a row for defining a new rule, new Custom Field */ $row_template = self::$mla_option_templates['iptc-exif-custom-new-field-row']; $row_values = array('column_count' => 5, 'key' => self::MLA_NEW_CUSTOM_FIELD, 'field_name_size' => '24', 'iptc_field_options' => self::_compose_iptc_option_list('none'), 'exif_size' => self::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => 'selected="selected"', 'exif_selected' => '', 'keep_selected' => 'selected="selected"', 'replace_selected' => ''); $table_rows .= MLAData::mla_parse_template($row_template, $row_values); $option_values = array('table_rows' => $table_rows, 'help' => $value['help']); return MLAData::mla_parse_template(self::$mla_option_templates['iptc-exif-custom-table'], $option_values); default: return "<br>ERROR: Render unknown custom {$key}\r\n"; } // switch $key // switch $key case 'update': case 'delete': $settings_changed = false; $messages = ''; switch ($key) { case 'iptc_exif_standard_mapping': $results = self::_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 = self::_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 = self::_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 = self::_update_iptc_exif_standard_mapping($current_values, $args); $messages .= $results['message']; $current_values = $results['values']; $settings_changed = $results['changed']; $results = self::_update_iptc_exif_taxonomy_mapping($current_values, $args); $messages .= $results['message']; $current_values = $results['values']; $settings_changed |= $results['changed']; $results = self::_update_iptc_exif_custom_mapping($current_values, $args); $messages .= $results['message']; $current_values = $results['values']; $settings_changed |= $results['changed']; break; default: return "<br>ERROR: Update/delete unknown custom {$key}\r\n"; } // switch $key if ($settings_changed) { $settings_changed = MLAOptions::mla_update_option('iptc_exif_mapping', $current_values); if ($settings_changed) { $results = "IPTC/EXIF mapping settings updated.\r\n"; } else { $results = "ERROR: IPTC/EXIF settings update failed.\r\n"; } } else { $results = "IPTC/EXIF no mapping changes detected.\r\n"; } return $results . $messages; case 'reset': switch ($key) { case 'iptc_exif_standard_mapping': $current_values['standard'] = self::$mla_option_definitions['iptc_exif_mapping']['std']['standard']; $settings_changed = MLAOptions::mla_update_option('iptc_exif_mapping', $current_values); if ($settings_changed) { return "IPTC/EXIF Standard field settings saved.\r\n"; } else { return "ERROR: IPTC/EXIF Standard field settings update failed.\r\n"; } case 'iptc_exif_taxonomy_mapping': $current_values['taxonomy'] = self::$mla_option_definitions['iptc_exif_mapping']['std']['taxonomy']; $settings_changed = MLAOptions::mla_update_option('iptc_exif_mapping', $current_values); if ($settings_changed) { return "IPTC/EXIF Taxonomy term settings saved.\r\n"; } else { return "ERROR: IPTC/EXIF Taxonomy term settings update failed.\r\n"; } case 'iptc_exif_custom_mapping': $current_values['custom'] = self::$mla_option_definitions['iptc_exif_mapping']['std']['custom']; $settings_changed = MLAOptions::mla_update_option('iptc_exif_mapping', $current_values); if ($settings_changed) { return "IPTC/EXIF Custom field settings saved.\r\n"; } else { return "ERROR: IPTC/EXIF Custom field settings reset failed.\r\n"; } case 'iptc_exif_mapping': self::mla_delete_option($key); return "<br>Reset custom {$key}\r\n"; default: return "<br>ERROR: Reset unknown custom {$key}\r\n"; } // switch $key // switch $key default: return "<br>ERROR: Custom {$key} unknown action: {$action}\r\n"; } // switch $action }