*/ /** * default options */ function aml_default_options() { return array( 'aml_amazon_id' => '', 'aml_secret_key' => '', 'aml_associate' => '', 'aml_domain' => 'us', 'aml_image_size' => 'med', 'aml_per_page' => 20, 'aml_use_tags' => 1, 'aml_use_categories' => 0, 'aml_use_shelves' => 1, 'aml_slug_base' => 'library', 'aml_slug_product' => 'product', 'aml_slug_person' => 'person', 'aml_slug_tag' => 'tag', 'aml_slug_review' => 'review', 'aml_slug_shelf' => 'shelf', 'aml_version' => AML_VERSION, ); } /** * shortcut for handling meta updates * * @param string name of meta field * @param int post id for meta * @param mixed new value (default is null) * @return bool true on success */ function aml_update_meta ($field, $post, $new=null) { $old = get_post_meta($post, $field, true); if(empty($new)) { $ret = delete_post_meta($post, $field, $old); } elseif (empty($old)) { $ret = add_post_meta($post, $field, $new); } elseif ($new != $old) { $ret = update_post_meta($post, $field, $new, $old); } else { $ret = false; } return $ret; } /** * shortcut for getting option from the aml_options array * * @param string name of option * @param mixed default value override (if null, will give from aml_default_options) * @return mixed option value */ function aml_get_option ($key='', $def=null) { static $options; static $defaults; if (!is_array($defaults)) { $defaults = aml_default_options(); } if (!is_array($options)) { $options = get_option('aml_options', $defaults); } if (false === strpos($key, 'aml_')) { $key = 'aml_' . $key; } $def = (is_null($def) && isset($defaults[$key])) ? $defaults[$key] : $def; return (isset($options[$key])) ? $options[$key] : $def; } /** * hack to use our templates * * @param string found template (passed from the filter) * @param string type of taxonomy to check * @param string type of page (archive, single, or taxonomy) * @return string path to template */ function aml_insert_template ($template, $check, $page='archive') { if ($page == 'taxonomy') { $term = get_queried_object(); $type = $term->taxonomy; } else { $type = get_query_var('post_type'); } // not ours to worry about! if ($check != $type) { return $template; } $file = $page.'-'.$check.'.php'; // template not found in theme folder, so insert our default if ($file != basename($template)) { $path = dirname(__FILE__) . '/templates/' . $file; if ( file_exists($path)) { return $path; } } return $template; } /** * options page display */ function aml_options_page() { ?>

Amazon Media Libraries

" />

here.', 'amazon-library'), 'https://aws-portal.amazon.com/gp/aws/developer/registration/index.html'); ?>

" />

here.', 'amazon-library'), 'https://aws-portal.amazon.com/gp/aws/developer/registration/index.html'); ?>

" />

get one.', 'amazon-library'), 'http://associates.amazon.com/'); ?>