Exemplo n.º 1
0
 /**
  * Loop over all the content in the main loop and do a request for all the items present so that we're only getting
  * a few API hits instead of all of them. Then, when anything else calls `easyazon_get_item` it will get the cached
  * data and not have to hit the API.
  */
 public static function prefetch_items()
 {
     global $wp_query;
     $identifiers = array_fill_keys(array_keys(easyazon_get_locales()), array());
     $preparsed = array();
     $shortcodes = easyazon_get_shortcodes();
     foreach ($wp_query->posts as $post) {
         preg_match_all('/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER);
         foreach ($matches as $match) {
             $shortcode = trim($match[2]);
             if (in_array($shortcode, $shortcodes)) {
                 $attributes = shortcode_parse_atts($match[3]);
                 $locale = isset($attributes['locale']) ? $attributes['locale'] : false;
                 $identifier = isset($attributes['identifier']) ? $attributes['identifier'] : false;
                 if (!is_array($preparsed[$shortcode])) {
                     $preparsed[$shortcode] = array();
                 }
                 $preparsed[$shortcode][] = $attributes;
                 if ($locale && $identifier) {
                     $identifiers[$locale][] = $identifier;
                 }
             }
         }
     }
     foreach ($identifiers as $locale => $queryable) {
         $cached_items = easyazon_get_items($queryable, $locale);
     }
     self::$preparsed_shortcodes = $preparsed;
 }
Exemplo n.º 2
0
 public static function display_settings_field_default_search_locale($args)
 {
     $options = array();
     $default = easyazon_get_setting('default_search_locale');
     $locales = easyazon_get_locales();
     foreach ($locales as $locale => $locale_name) {
         $options[] = sprintf('<option %s value="%s">%s</option>', $default === $locale ? 'selected="selected"' : '', esc_attr($locale), esc_html($locale_name));
     }
     printf('<select id="%s" name="%s">%s</select>', easyazon_get_setting_field_id('default_search_locale'), easyazon_get_setting_field_name('default_search_locale'), implode('', $options));
 }
Exemplo n.º 3
0
function easyazon_get_locale($locale)
{
    $locale = strtoupper($locale);
    $locales = easyazon_get_locales();
    return isset($locales[$locale]) ? $locale : key($locales);
}
Exemplo n.º 4
0
</label></th>
					<td>
						<input type="text" class="large-text" id="easyazon-search-keywords" data-bind="textInput: keywords" />
						<p class="description easyazon-search-result-error" data-bind="text: message, visible: error"></p>
					</td>
				</tr>

				<tr>
					<th scope="row"><label for="easyazon-search-locale"><?php 
_e('Search Locale');
?>
</label></th>
					<td>
						<select id="easyazon-search-locale" data-bind="value: locale">
							<?php 
foreach (easyazon_get_locales() as $locale => $locale_name) {
    ?>
							<option value="<?php 
    echo esc_attr($locale);
    ?>
"><?php 
    echo esc_html($locale_name);
    ?>
</option>
							<?php 
}
?>
						</select>
					</td>
				</tr>