/** * The MLA Tag Cloud support function. * * This is an alternative to the WordPress wp_tag_cloud function, with additional * options to customize the hyperlink behind each term. * * @since 1.60 * * @param array $attr Attributes of the shortcode. * * @return string HTML content to display the tag cloud. */ public static function mla_tag_cloud($attr) { global $post; /* * These are the default parameters for tag cloud display */ $mla_item_specific_arguments = array('mla_link_attributes' => '', 'mla_link_class' => '', 'mla_link_style' => '', 'mla_link_href' => '', 'mla_link_text' => '', 'mla_nolink_text' => '', 'mla_rollover_text' => '', 'mla_caption' => ''); $mla_arguments = array_merge(array('mla_output' => 'flat', 'mla_style' => NULL, 'mla_markup' => NULL, 'mla_float' => is_rtl() ? 'right' : 'left', 'mla_itemwidth' => MLAOptions::mla_get_option('mla_tag_cloud_itemwidth'), 'mla_margin' => MLAOptions::mla_get_option('mla_tag_cloud_margin'), 'mla_target' => '', 'mla_debug' => false, 'term_id' => NULL, 'mla_end_size' => 1, 'mla_mid_size' => 2, 'mla_prev_text' => '« ' . __('Previous', 'media-library-assistant'), 'mla_next_text' => __('Next', 'media-library-assistant') . ' »', 'mla_page_parameter' => 'mla_cloud_current', 'mla_cloud_current' => NULL, 'mla_paginate_total' => NULL, 'mla_paginate_type' => 'plain'), $mla_item_specific_arguments); $defaults = array_merge(self::$mla_get_terms_parameters, array('smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'separator' => "\n", 'single_text' => '%d item', 'multiple_text' => '%d items', 'echo' => false, 'link' => 'view', 'current_item' => '', 'current_item_class' => 'mla_current_item', 'itemtag' => 'ul', 'termtag' => 'li', 'captiontag' => '', 'columns' => MLAOptions::mla_get_option('mla_tag_cloud_columns')), $mla_arguments); /* * The mla_paginate_current parameter can be changed to support multiple galleries per page. */ if (!isset($attr['mla_page_parameter'])) { $attr['mla_page_parameter'] = $defaults['mla_page_parameter']; } $mla_page_parameter = $attr['mla_page_parameter']; /* * Special handling of mla_page_parameter to make * "MLA pagination" easier. Look for this parameter in $_REQUEST * if it's not present in the shortcode itself. */ if (!isset($attr[$mla_page_parameter])) { if (isset($_REQUEST[$mla_page_parameter])) { $attr[$mla_page_parameter] = $_REQUEST[$mla_page_parameter]; } } // $instance supports multiple clouds in one page/post static $instance = 0; $instance++; /* * Some values are already known, and can be used in data selection parameters */ $upload_dir = wp_upload_dir(); $page_values = array('instance' => $instance, 'selector' => "mla_tag_cloud-{$instance}", 'site_url' => site_url(), 'base_url' => $upload_dir['baseurl'], 'base_dir' => $upload_dir['basedir'], 'id' => $post->ID, 'page_ID' => $post->ID, 'page_author' => $post->post_author, 'page_date' => $post->post_date, 'page_content' => $post->post_content, 'page_title' => $post->post_title, 'page_excerpt' => $post->post_excerpt, 'page_status' => $post->post_status, 'page_name' => $post->post_name, 'page_modified' => $post->post_modified, 'page_guid' => $post->guid, 'page_type' => $post->post_type, 'page_url' => get_page_link()); /* * Look for 'request' substitution parameters, * which can be added to any input parameter */ foreach ($attr as $attr_key => $attr_value) { /* * item-specific Display Content parameters must be evaluated * later, when all of the information is available. */ if (array_key_exists($attr_key, $mla_item_specific_arguments)) { continue; } $attr_value = str_replace('{+', '[+', str_replace('+}', '+]', $attr_value)); $replacement_values = MLAData::mla_expand_field_level_parameters($attr_value, NULL, $page_values); $attr[$attr_key] = MLAData::mla_parse_template($attr_value, $replacement_values); } $attr = apply_filters('mla_tag_cloud_attributes', $attr); $arguments = shortcode_atts($defaults, $attr); /* * $mla_page_parameter, if non-default, doesn't make it through the shortcode_atts filter, * so we handle it separately */ if (!isset($arguments[$mla_page_parameter])) { if (isset($attr[$mla_page_parameter])) { $arguments[$mla_page_parameter] = $attr[$mla_page_parameter]; } else { $arguments[$mla_page_parameter] = $defaults['mla_cloud_current']; } } /* * Process the pagination parameter, if present */ if (isset($arguments[$mla_page_parameter])) { $arguments['offset'] = $arguments['limit'] * ($arguments[$mla_page_parameter] - 1); } /* * Clean up the current_item to separate term_id from slug */ if (!empty($arguments['current_item']) && ctype_digit($arguments['current_item'])) { $arguments['current_item'] = absint($arguments['current_item']); } $arguments = apply_filters('mla_tag_cloud_arguments', $arguments); self::$mla_debug = !empty($arguments['mla_debug']) ? trim(strtolower($arguments['mla_debug'])) : false; if (self::$mla_debug) { if ('true' == self::$mla_debug) { MLA::mla_debug_mode('buffer'); } elseif ('log' == self::$mla_debug) { MLA::mla_debug_mode('log'); } else { self::$mla_debug = false; } } if (self::$mla_debug) { MLA::mla_debug_add('<strong>' . __('mla_debug attributes', 'media-library-assistant') . '</strong> = ' . var_export($attr, true)); MLA::mla_debug_add('<strong>' . __('mla_debug arguments', 'media-library-assistant') . '</strong> = ' . var_export($arguments, true)); } /* * Determine output type and templates */ $output_parameters = array_map('strtolower', array_map('trim', explode(',', $arguments['mla_output']))); if ($is_grid = 'grid' == $output_parameters[0]) { $default_style = MLAOptions::mla_get_option('default_tag_cloud_style'); $default_markup = MLAOptions::mla_get_option('default_tag_cloud_markup'); if (NULL == $arguments['mla_style']) { $arguments['mla_style'] = $default_style; } if (NULL == $arguments['mla_markup']) { $arguments['mla_markup'] = $default_markup; $arguments['itemtag'] = 'dl'; $arguments['termtag'] = 'dt'; $arguments['captiontag'] = 'dd'; } } if ($is_list = 'list' == $output_parameters[0]) { $default_style = 'none'; if (empty($arguments['captiontag'])) { $default_markup = 'tag-cloud-ul'; } else { $default_markup = 'tag-cloud-dl'; if ('dd' == $arguments['captiontag']) { $arguments['itemtag'] = 'dl'; $arguments['termtag'] = 'dt'; } } if (NULL == $arguments['mla_style']) { $arguments['mla_style'] = $default_style; } if (NULL == $arguments['mla_markup']) { $arguments['mla_markup'] = $default_markup; } } $is_pagination = in_array($output_parameters[0], array('previous_link', 'current_link', 'next_link', 'previous_page', 'next_page', 'paginate_links')); /* * Convert lists to arrays */ if (is_string($arguments['taxonomy'])) { $arguments['taxonomy'] = explode(',', $arguments['taxonomy']); } if (is_string($arguments['post_type'])) { $arguments['post_type'] = explode(',', $arguments['post_type']); } if (is_string($arguments['post_status'])) { $arguments['post_status'] = explode(',', $arguments['post_status']); } $tags = self::mla_get_terms($arguments); if (self::$mla_debug) { $cloud = MLA::mla_debug_flush(); } else { $cloud = ''; } /* * Invalid taxonomy names return WP_Error */ if (is_wp_error($tags)) { $cloud .= '<strong>' . __('ERROR', 'media-library-assistant') . ': ' . $tags->get_error_message() . '</strong>, ' . $tags->get_error_data($tags->get_error_code()); if ('array' == $arguments['mla_output']) { return array($cloud); } if (empty($arguments['echo'])) { return $cloud; } echo $cloud; return; } if (empty($tags)) { if (self::$mla_debug) { MLA::mla_debug_add('<strong>' . __('mla_debug empty cloud', 'media-library-assistant') . '</strong>, query = ' . var_export($arguments, true)); $cloud = MLA::mla_debug_flush(); } $cloud .= $arguments['mla_nolink_text']; if ('array' == $arguments['mla_output']) { return array($cloud); } if (empty($arguments['echo'])) { return $cloud; } echo $cloud; return; } /* * Fill in the item_specific link properties, calculate cloud parameters */ if (isset($tags['found_rows'])) { $found_rows = $tags['found_rows']; unset($tags['found_rows']); } else { $found_rows = count($tags); } $min_count = 0x7fffffff; $max_count = 0; $min_scaled_count = 0x7fffffff; $max_scaled_count = 0; foreach ($tags as $key => $tag) { $tag_count = isset($tag->count) ? $tag->count : 0; $tag->scaled_count = apply_filters('mla_tag_cloud_scale', round(log10($tag_count + 1) * 100), $attr, $arguments, $tag); if ($tag_count < $min_count) { $min_count = $tag_count; } if ($tag_count > $max_count) { $max_count = $tag_count; } if ($tag->scaled_count < $min_scaled_count) { $min_scaled_count = $tag->scaled_count; } if ($tag->scaled_count > $max_scaled_count) { $max_scaled_count = $tag->scaled_count; } $link = get_edit_tag_link($tag->term_id, $tag->taxonomy); if (!is_wp_error($link)) { $tags[$key]->edit_link = $link; $link = get_term_link(intval($tag->term_id), $tag->taxonomy); $tags[$key]->term_link = $link; } if (is_wp_error($link)) { $cloud = '<strong>' . __('ERROR', 'media-library-assistant') . ': ' . $link->get_error_message() . '</strong>, ' . $link->get_error_data($link->get_error_code()); if ('array' == $arguments['mla_output']) { return array($cloud); } if (empty($arguments['echo'])) { return $cloud; } echo $cloud; return; } if ('edit' == $arguments['link']) { $tags[$key]->link = $tags[$key]->edit_link; } else { $tags[$key]->link = $tags[$key]->term_link; } } // foreach tag /* * The default MLA style template includes "margin: 1.5%" to put a bit of * minimum space between the columns. "mla_margin" can be used to change * this. "mla_itemwidth" can be used with "columns=0" to achieve a * "responsive" layout. */ $columns = absint($arguments['columns']); $margin_string = strtolower(trim($arguments['mla_margin'])); if (is_numeric($margin_string) && 0 != $margin_string) { $margin_string .= '%'; // Legacy values are always in percent } if ('%' == substr($margin_string, -1)) { $margin_percent = (double) substr($margin_string, 0, strlen($margin_string) - 1); } else { $margin_percent = 0; } $width_string = strtolower(trim($arguments['mla_itemwidth'])); if ('none' != $width_string) { switch ($width_string) { case 'exact': $margin_percent = 0; // fallthru // fallthru case 'calculate': $width_string = $columns > 0 ? floor(1000 / $columns) / 10 - 2.0 * $margin_percent : 100 - 2.0 * $margin_percent; // fallthru // fallthru default: if (is_numeric($width_string) && 0 != $width_string) { $width_string .= '%'; // Legacy values are always in percent } } } // $use_width $float = strtolower($arguments['mla_float']); if (!in_array($float, array('left', 'none', 'right'))) { $float = is_rtl() ? 'right' : 'left'; } /* * Calculate cloud parameters */ $spread = $max_scaled_count - $min_scaled_count; if ($spread <= 0) { $spread = 1; } $font_spread = $arguments['largest'] - $arguments['smallest']; if ($font_spread < 0) { $font_spread = 1; } $font_step = $font_spread / $spread; $style_values = array_merge($page_values, array('mla_output' => $arguments['mla_output'], 'mla_style' => $arguments['mla_style'], 'mla_markup' => $arguments['mla_markup'], 'taxonomy' => implode('-', $arguments['taxonomy']), 'current_item' => $arguments['current_item'], 'itemtag' => tag_escape($arguments['itemtag']), 'termtag' => tag_escape($arguments['termtag']), 'captiontag' => tag_escape($arguments['captiontag']), 'columns' => $columns, 'itemwidth' => $width_string, 'margin' => $margin_string, 'float' => $float, 'found_rows' => $found_rows, 'min_count' => $min_count, 'max_count' => $max_count, 'min_scaled_count' => $min_scaled_count, 'max_scaled_count' => $max_scaled_count, 'spread' => $spread, 'smallest' => $arguments['smallest'], 'largest' => $arguments['largest'], 'unit' => $arguments['unit'], 'font_spread' => $font_spread, 'font_step' => $font_step, 'separator' => $arguments['separator'], 'single_text' => $arguments['single_text'], 'multiple_text' => $arguments['multiple_text'], 'echo' => $arguments['echo'], 'link' => $arguments['link'])); $style_template = $gallery_style = ''; $use_mla_tag_cloud_style = ($is_grid || $is_list) && 'none' != strtolower($style_values['mla_style']); if (apply_filters('use_mla_tag_cloud_style', $use_mla_tag_cloud_style, $style_values['mla_style'])) { $style_template = MLAOptions::mla_fetch_gallery_template($style_values['mla_style'], 'style'); if (empty($style_template)) { $style_values['mla_style'] = $default_style; $style_template = MLAOptions::mla_fetch_gallery_template($default_style, 'style'); } if (!empty($style_template)) { /* * Look for 'query' and 'request' substitution parameters */ $style_values = MLAData::mla_expand_field_level_parameters($style_template, $attr, $style_values); /* * Clean up the template to resolve width or margin == 'none' */ if ('none' == $margin_string) { $style_values['margin'] = '0'; $style_template = preg_replace('/margin:[\\s]*\\[\\+margin\\+\\][\\%]*[\\;]*/', '', $style_template); } if ('none' == $width_string) { $style_values['itemwidth'] = 'auto'; $style_template = preg_replace('/width:[\\s]*\\[\\+itemwidth\\+\\][\\%]*[\\;]*/', '', $style_template); } $style_values = apply_filters('mla_tag_cloud_style_values', $style_values); $style_template = apply_filters('mla_tag_cloud_style_template', $style_template); $gallery_style = MLAData::mla_parse_template($style_template, $style_values); $gallery_style = apply_filters('mla_tag_cloud_style_parse', $gallery_style, $style_template, $style_values); } // !empty template } // use_mla_tag_cloud_style $markup_values = $style_values; if ($is_grid || $is_list) { $open_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-open', 'markup'); if (false === $open_template) { $markup_values['mla_markup'] = $default_markup; $open_template = MLAOptions::mla_fetch_gallery_template($default_markup, 'markup'); } if (empty($open_template)) { $open_template = ''; } if ($is_grid) { $row_open_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-row-open', 'markup'); if (empty($row_open_template)) { $row_open_template = ''; } } else { $row_open_template = ''; } $item_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-item', 'markup'); if (empty($item_template)) { $item_template = ''; } if ($is_grid) { $row_close_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-row-close', 'markup'); if (empty($row_close_template)) { $row_close_template = ''; } } else { $row_close_template = ''; } $close_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-close', 'markup'); if (empty($close_template)) { $close_template = ''; } /* * Look for gallery-level markup substitution parameters */ $new_text = $open_template . $row_open_template . $row_close_template . $close_template; $markup_values = MLAData::mla_expand_field_level_parameters($new_text, $attr, $markup_values); $markup_values = apply_filters('mla_tag_cloud_open_values', $markup_values); $open_template = apply_filters('mla_tag_cloud_open_template', $open_template); if (empty($open_template)) { $gallery_open = ''; } else { $gallery_open = MLAData::mla_parse_template($open_template, $markup_values); } $gallery_open = apply_filters('mla_tag_cloud_open_parse', $gallery_open, $open_template, $markup_values); $cloud .= $gallery_style . $gallery_open; } elseif ($is_pagination) { /* * Handle 'previous_page', 'next_page', and 'paginate_links' */ if (isset($attr['limit'])) { $attr['posts_per_page'] = $attr['limit']; } $pagination_result = self::_process_pagination_output_types($output_parameters, $markup_values, $arguments, $attr, $found_rows); if (false !== $pagination_result) { return $pagination_result; } /* * For "previous_link", "current_link" and "next_link", discard all of the $tags except the appropriate choice */ $link_type = $output_parameters[0]; if (!in_array($link_type, array('previous_link', 'current_link', 'next_link'))) { return ''; // unknown output type } $is_wrap = isset($output_parameters[1]) && 'wrap' == $output_parameters[1]; if (empty($arguments['term_id'])) { $target_id = -2; // won't match anything } else { $current_id = $arguments['term_id']; foreach ($tags as $id => $tag) { if ($tag->term_id == $current_id) { break; } } switch ($link_type) { case 'previous_link': $target_id = $id - 1; break; case 'next_link': $target_id = $id + 1; break; case 'current_link': default: $target_id = $id; } // link_type } $target = NULL; if (isset($tags[$target_id])) { $target = $tags[$target_id]; } elseif ($is_wrap) { switch ($link_type) { case 'previous_link': $target = array_pop($tags); break; case 'next_link': $target = array_shift($tags); } // link_type } // is_wrap if (isset($target)) { $tags = array($target); } elseif (!empty($arguments['mla_nolink_text'])) { return self::_process_shortcode_parameter($arguments['mla_nolink_text'], $markup_values) . '</a>'; } else { return ''; } } // is_pagination /* * Accumulate links for flat and array output */ $tag_links = array(); $column_index = 0; foreach ($tags as $key => $tag) { $item_values = $markup_values; /* * fill in item-specific elements */ $item_values['index'] = (string) 1 + $column_index; if ($item_values['columns'] > 0 && (1 + $column_index) % $item_values['columns'] == 0) { $item_values['last_in_row'] = 'last_in_row'; } else { $item_values['last_in_row'] = ''; } $item_values['key'] = $key; $item_values['term_id'] = $tag->term_id; $item_values['name'] = wptexturize($tag->name); $item_values['slug'] = wptexturize($tag->slug); $item_values['term_group'] = $tag->term_group; $item_values['term_taxonomy_id'] = $tag->term_taxonomy_id; $item_values['taxonomy'] = wptexturize($tag->taxonomy); $item_values['current_item_class'] = ''; $item_values['description'] = wptexturize($tag->description); $item_values['parent'] = $tag->parent; $item_values['count'] = isset($tag->count) ? $tag->count : 0; $item_values['scaled_count'] = $tag->scaled_count; $item_values['font_size'] = str_replace(',', '.', $item_values['smallest'] + ($item_values['scaled_count'] - $item_values['min_scaled_count']) * $item_values['font_step']); $item_values['link_url'] = $tag->link; $item_values['editlink_url'] = $tag->edit_link; $item_values['termlink_url'] = $tag->term_link; // Added in the code below: // 'caption', 'link_attributes', 'current_item_class', 'rollover_text', 'link_style', 'link_text', 'editlink', 'termlink', 'thelink' if (!empty($arguments['current_item'])) { if (is_integer($arguments['current_item'])) { if ($arguments['current_item'] == $tag->term_id) { $item_values['current_item_class'] = $arguments['current_item_class']; } } else { if ($arguments['current_item'] == $tag->slug) { $item_values['current_item_class'] = $arguments['current_item_class']; } } } /* * Add item_specific field-level substitution parameters */ $new_text = isset($item_template) ? $item_template : ''; foreach ($mla_item_specific_arguments as $index => $value) { $new_text .= str_replace('{+', '[+', str_replace('+}', '+]', $arguments[$index])); } $item_values = MLAData::mla_expand_field_level_parameters($new_text, $attr, $item_values); if ($item_values['captiontag']) { $item_values['caption'] = wptexturize($tag->description); if (!empty($arguments['mla_caption'])) { $item_values['caption'] = wptexturize(self::_process_shortcode_parameter($arguments['mla_caption'], $item_values)); } } else { $item_values['caption'] = ''; } if (!empty($arguments['mla_link_text'])) { $link_text = self::_process_shortcode_parameter($arguments['mla_link_text'], $item_values); } else { $link_text = false; } /* * Apply the Display Content parameters. */ if (!empty($arguments['mla_target'])) { $link_attributes = 'target="' . $arguments['mla_target'] . '" '; } else { $link_attributes = ''; } if (!empty($arguments['mla_link_attributes'])) { $link_attributes .= self::_process_shortcode_parameter($arguments['mla_link_attributes'], $item_values) . ' '; } if (!empty($arguments['mla_link_class'])) { $link_attributes .= 'class="' . self::_process_shortcode_parameter($arguments['mla_link_class'], $item_values) . '" '; } $item_values['link_attributes'] = $link_attributes; $item_values['rollover_text'] = sprintf(_n($item_values['single_text'], $item_values['multiple_text'], $item_values['count'], 'media-library-assistant'), number_format_i18n($item_values['count'])); if (!empty($arguments['mla_rollover_text'])) { $item_values['rollover_text'] = esc_attr(self::_process_shortcode_parameter($arguments['mla_rollover_text'], $item_values)); } if (!empty($arguments['mla_link_href'])) { $link_href = self::_process_shortcode_parameter($arguments['mla_link_href'], $item_values); $item_values['link_url'] = $link_href; } else { $link_href = ''; } if (!empty($arguments['mla_link_style'])) { $item_values['link_style'] = esc_attr(self::_process_shortcode_parameter($arguments['mla_link_style'], $item_values)); } else { $item_values['link_style'] = 'font-size: ' . $item_values['font_size'] . $item_values['unit']; } if (!empty($arguments['mla_link_text'])) { $item_values['link_text'] = esc_attr(self::_process_shortcode_parameter($arguments['mla_link_text'], $item_values)); } else { $item_values['link_text'] = $item_values['name']; } /* * Editlink, termlink and thelink */ $item_values['editlink'] = sprintf('<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $item_values['editlink_url'], $item_values['rollover_text'], $item_values['link_style'], $item_values['link_text']); $item_values['termlink'] = sprintf('<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $item_values['termlink_url'], $item_values['rollover_text'], $item_values['link_style'], $item_values['link_text']); if (!empty($link_href)) { $item_values['thelink'] = sprintf('<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $link_href, $item_values['rollover_text'], $item_values['link_style'], $item_values['link_text']); } elseif ('edit' == $arguments['link']) { $item_values['thelink'] = $item_values['editlink']; } elseif ('view' == $arguments['link']) { $item_values['thelink'] = $item_values['termlink']; } elseif ('span' == $arguments['link']) { $item_values['thelink'] = sprintf('<span %1$sstyle="%2$s">%3$s</a>', $link_attributes, $item_values['link_style'], $item_values['link_text']); } else { $item_values['thelink'] = $item_values['link_text']; } if ($is_grid || $is_list) { /* * Start of row markup */ if ($is_grid && ($markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0)) { $markup_values = apply_filters('mla_tag_cloud_row_open_values', $markup_values); $row_open_template = apply_filters('mla_tag_cloud_row_open_template', $row_open_template); $parse_value = MLAData::mla_parse_template($row_open_template, $markup_values); $cloud .= apply_filters('mla_tag_cloud_row_open_parse', $parse_value, $row_open_template, $markup_values); } /* * item markup */ $column_index++; $item_values = apply_filters('mla_tag_cloud_item_values', $item_values); $item_template = apply_filters('mla_tag_cloud_item_template', $item_template); $parse_value = MLAData::mla_parse_template($item_template, $item_values); $cloud .= apply_filters('mla_tag_cloud_item_parse', $parse_value, $item_template, $item_values); /* * End of row markup */ if ($is_grid && ($markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0)) { $markup_values = apply_filters('mla_tag_cloud_row_close_values', $markup_values); $row_close_template = apply_filters('mla_tag_cloud_row_close_template', $row_close_template); $parse_value = MLAData::mla_parse_template($row_close_template, $markup_values); $cloud .= apply_filters('mla_tag_cloud_row_close_parse', $parse_value, $row_close_template, $markup_values); } } elseif ($is_pagination) { return $item_values['thelink']; } else { $column_index++; $item_values = apply_filters('mla_tag_cloud_item_values', $item_values); $tag_links[] = apply_filters('mla_tag_cloud_item_parse', $item_values['thelink'], NULL, $item_values); } } // foreach tag if ($is_grid || $is_list) { /* * Close out partial row */ if ($is_grid && !($markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0)) { $markup_values = apply_filters('mla_tag_cloud_row_close_values', $markup_values); $row_close_template = apply_filters('mla_tag_cloud_row_close_template', $row_close_template); $parse_value = MLAData::mla_parse_template($row_close_template, $markup_values); $cloud .= apply_filters('mla_tag_cloud_row_close_parse', $parse_value, $row_close_template, $markup_values); } $markup_values = apply_filters('mla_tag_cloud_close_values', $markup_values); $close_template = apply_filters('mla_tag_cloud_close_template', $close_template); $parse_value = MLAData::mla_parse_template($close_template, $markup_values); $cloud .= apply_filters('mla_tag_cloud_close_parse', $parse_value, $close_template, $markup_values); } else { switch ($markup_values['mla_output']) { case 'array': $cloud =& $tag_links; break; case 'flat': default: $cloud .= join($markup_values['separator'], $tag_links); break; } // switch format } //$cloud = wp_generate_tag_cloud( $tags, $arguments ); if ('array' == $arguments['mla_output'] || empty($arguments['echo'])) { return $cloud; } echo $cloud; }
/** * The MLA Gallery shortcode. * * This is a superset of the WordPress Gallery shortcode for displaying images on a post, * page or custom post type. It is adapted from /wp-includes/media.php gallery_shortcode. * Enhancements include many additional selection parameters and full taxonomy support. * * @since .50 * * @param array $attr Attributes of the shortcode. * * @return string HTML content to display gallery. */ public static function mla_gallery_shortcode($attr) { global $post; /* * Some do_shortcode callers may not have a specific post in mind */ if (!is_object($post)) { $post = (object) array('ID' => 0); } /* * 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); } /* * The mla_paginate_current parameter can be changed to support multiple galleries per page. */ if (!isset($attr['mla_page_parameter'])) { $attr['mla_page_parameter'] = 'mla_paginate_current'; } $mla_page_parameter = $attr['mla_page_parameter']; /* * Special handling of the mla_paginate_current parameter to make * "MLA pagination" easier. Look for this parameter in $_REQUEST * if it's not present in the shortcode itself. */ if (!isset($attr[$mla_page_parameter])) { if (isset($_REQUEST[$mla_page_parameter])) { $attr[$mla_page_parameter] = $_REQUEST[$mla_page_parameter]; } } // else // $attr[ $mla_page_parameter ] = ''; /* * These are the parameters for gallery display */ $mla_arguments = array('mla_output' => 'gallery', 'mla_style' => MLAOptions::mla_get_option('default_style'), 'mla_markup' => MLAOptions::mla_get_option('default_markup'), 'mla_float' => is_rtl() ? 'right' : 'left', 'mla_itemwidth' => MLAOptions::mla_get_option('mla_gallery_itemwidth'), 'mla_margin' => MLAOptions::mla_get_option('mla_gallery_margin'), 'mla_link_attributes' => '', 'mla_link_class' => '', 'mla_link_href' => '', 'mla_link_text' => '', 'mla_nolink_text' => '', 'mla_rollover_text' => '', 'mla_image_class' => '', 'mla_image_alt' => '', 'mla_image_attributes' => '', 'mla_caption' => '', 'mla_target' => '', 'mla_debug' => false, 'mla_viewer' => false, 'mla_viewer_extensions' => 'doc,xls,ppt,pdf,txt', 'mla_viewer_page' => '1', 'mla_viewer_width' => '150', 'mla_alt_shortcode' => NULL, 'mla_alt_ids_name' => 'ids', 'mla_end_size' => 1, 'mla_mid_size' => 2, 'mla_prev_text' => '« Previous', 'mla_next_text' => 'Next »', 'mla_paginate_type' => 'plain'); $default_arguments = array_merge(array('size' => 'thumbnail', 'itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => MLAOptions::mla_get_option('mla_gallery_columns'), 'link' => 'permalink', 'id' => NULL, 'style' => NULL, 'type' => 'default', 'thumb_width' => 75, 'thumb_height' => 75, 'thumbnail_size' => 'thumbnail', 'slide_size' => 'large', 'slideshow_height' => 500, 'fx' => 'fade', 'timeout' => 4000, 'speed' => 1000, 'pause' => NULL), $mla_arguments); /* * Look for 'request' substitution parameters, * which can be added to any input parameter */ foreach ($attr as $attr_key => $attr_value) { /* * attachment-specific Gallery Display Content parameters must be evaluated * later, when all of the information is available. */ if (in_array($attr_key, array('mla_link_attributes', 'mla_link_class', 'mla_link_href', 'mla_link_text', 'mla_nolink_text', 'mla_rollover_text', 'mla_image_class', 'mla_image_alt', 'mla_image_attributes', 'mla_caption'))) { continue; } $attr_value = str_replace('{+', '[+', str_replace('+}', '+]', $attr_value)); $replacement_values = MLAData::mla_expand_field_level_parameters($attr_value); if (!empty($replacement_values)) { $attr[$attr_key] = MLAData::mla_parse_template($attr_value, $replacement_values); } } /* * Merge gallery arguments with defaults, pass the query arguments on to mla_get_shortcode_attachments. */ $attr = apply_filters('mla_gallery_attributes', $attr); $arguments = shortcode_atts($default_arguments, $attr); $arguments = apply_filters('mla_gallery_arguments', $arguments); self::$mla_debug = !empty($arguments['mla_debug']) && 'true' == strtolower($arguments['mla_debug']); /* * Determine output type */ $output_parameters = array_map('strtolower', array_map('trim', explode(',', $arguments['mla_output']))); $is_gallery = 'gallery' == $output_parameters[0]; $is_pagination = in_array($output_parameters[0], array('previous_page', 'next_page', 'paginate_links')); $attachments = self::mla_get_shortcode_attachments($post->ID, $attr, $is_pagination); if (is_string($attachments)) { return $attachments; } if (empty($attachments)) { if (self::$mla_debug) { $output = '<p><strong>mla_debug empty gallery</strong>, query = ' . var_export($attr, true) . '</p>'; $output .= self::$mla_debug_messages; self::$mla_debug_messages = ''; } else { $output = ''; } $output .= $arguments['mla_nolink_text']; return $output; } // empty $attachments /* * Look for user-specified alternate gallery shortcode */ if (is_string($arguments['mla_alt_shortcode'])) { /* * Replace data-selection parameters with the "ids" list */ $blacklist = array_merge($mla_arguments, self::$data_selection_parameters); $new_args = ''; foreach ($attr as $key => $value) { if (array_key_exists($key, $blacklist)) { continue; } $slashed = addcslashes($value, chr(0) . chr(7) . chr(8) . "\f\n\r\t\v\"\\\$"); if (false !== strpos($value, ' ') || false !== strpos($value, '\'') || $slashed != $value) { $value = '"' . $slashed . '"'; } $new_args .= empty($new_args) ? $key . '=' . $value : ' ' . $key . '=' . $value; } // foreach $attr $new_ids = ''; foreach ($attachments as $value) { $new_ids .= empty($new_ids) ? (string) $value->ID : ',' . $value->ID; } // foreach $attachments $new_ids = $arguments['mla_alt_ids_name'] . '="' . $new_ids . '"'; if (self::$mla_debug) { $output = self::$mla_debug_messages; self::$mla_debug_messages = ''; } else { $output = ''; } /* * Execute the alternate gallery shortcode with the new parameters */ return $output . do_shortcode(sprintf('[%1$s %2$s %3$s]', $arguments['mla_alt_shortcode'], $new_ids, $new_args)); } // mla_alt_shortcode /* * Look for Photonic-enhanced gallery */ global $photonic; if (is_object($photonic) && !empty($arguments['style'])) { if ('default' != strtolower($arguments['type'])) { return '<p><strong>Photonic-enhanced [mla_gallery]</strong> type must be <strong>default</strong>, query = ' . var_export($attr, true) . '</p>'; } $images = array(); foreach ($attachments as $key => $val) { $images[$val->ID] = $attachments[$key]; } if (isset($arguments['pause']) && 'false' == $arguments['pause']) { $arguments['pause'] = NULL; } $output = $photonic->build_gallery($images, $arguments['style'], $arguments); return $output; } $size = $size_class = $arguments['size']; if ('icon' == strtolower($size)) { if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_ENABLE_MLA_ICONS)) { $size = array(64, 64); } else { $size = array(60, 60); } $show_icon = true; } else { $show_icon = false; } /* * Feeds such as RSS, Atom or RDF do not require styled and formatted output */ if (is_feed()) { $output = "\n"; foreach ($attachments as $att_id => $attachment) { $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; } return $output; } /* * Check for Google File Viewer arguments */ $arguments['mla_viewer'] = !empty($arguments['mla_viewer']) && 'true' == strtolower($arguments['mla_viewer']); if ($arguments['mla_viewer']) { $arguments['mla_viewer_extensions'] = array_filter(array_map('trim', explode(',', $arguments['mla_viewer_extensions']))); $arguments['mla_viewer_page'] = absint($arguments['mla_viewer_page']); $arguments['mla_viewer_width'] = absint($arguments['mla_viewer_width']); } // $instance supports multiple galleries in one page/post static $instance = 0; $instance++; /* * The default MLA style template includes "margin: 1.5%" to put a bit of * minimum space between the columns. "mla_margin" can be used to change * this. "mla_itemwidth" can be used with "columns=0" to achieve a "responsive" * layout. */ $columns = absint($arguments['columns']); $margin_string = strtolower(trim($arguments['mla_margin'])); if (is_numeric($margin_string) && 0 != $margin_string) { $margin_string .= '%'; } // Legacy values are always in percent if ('%' == substr($margin_string, -1)) { $margin_percent = (double) substr($margin_string, 0, strlen($margin_string) - 1); } else { $margin_percent = 0; } $width_string = strtolower(trim($arguments['mla_itemwidth'])); if ('none' != $width_string) { switch ($width_string) { case 'exact': $margin_percent = 0; /* fallthru */ /* fallthru */ case 'calculate': $width_string = $columns > 0 ? floor(1000 / $columns) / 10 - 2.0 * $margin_percent : 100 - 2.0 * $margin_percent; /* fallthru */ /* fallthru */ default: if (is_numeric($width_string) && 0 != $width_string) { $width_string .= '%'; } // Legacy values are always in percent } } // $use_width $float = strtolower($arguments['mla_float']); if (!in_array($float, array('left', 'none', 'right'))) { $float = is_rtl() ? 'right' : 'left'; } $style_values = array('mla_style' => $arguments['mla_style'], 'mla_markup' => $arguments['mla_markup'], 'instance' => $instance, 'id' => $post->ID, 'itemtag' => tag_escape($arguments['itemtag']), 'icontag' => tag_escape($arguments['icontag']), 'captiontag' => tag_escape($arguments['captiontag']), 'columns' => $columns, 'itemwidth' => $width_string, 'margin' => $margin_string, 'float' => $float, 'selector' => "mla_gallery-{$instance}", 'size_class' => sanitize_html_class($size_class)); $style_template = $gallery_style = ''; $use_mla_gallery_style = 'none' != strtolower($style_values['mla_style']); if (apply_filters('use_mla_gallery_style', $use_mla_gallery_style, $style_values['mla_style'])) { $style_template = MLAOptions::mla_fetch_gallery_template($style_values['mla_style'], 'style'); if (empty($style_template)) { $style_values['mla_style'] = 'default'; $style_template = MLAOptions::mla_fetch_gallery_template('default', 'style'); } if (!empty($style_template)) { /* * Look for 'query' and 'request' substitution parameters */ $style_values = MLAData::mla_expand_field_level_parameters($style_template, $attr, $style_values); /* * Clean up the template to resolve width or margin == 'none' */ if ('none' == $margin_string) { $style_values['margin'] = '0'; $style_template = preg_replace('/margin:[\\s]*\\[\\+margin\\+\\][\\%]*[\\;]*/', '', $style_template); } if ('none' == $width_string) { $style_values['itemwidth'] = 'auto'; $style_template = preg_replace('/width:[\\s]*\\[\\+itemwidth\\+\\][\\%]*[\\;]*/', '', $style_template); } $style_values = apply_filters('mla_gallery_style_values', $style_values); $style_template = apply_filters('mla_gallery_style_template', $style_template); $gallery_style = MLAData::mla_parse_template($style_template, $style_values); $gallery_style = apply_filters('mla_gallery_style_parse', $gallery_style, $style_template, $style_values); /* * Clean up the styles to resolve extra "%" suffixes on width or margin (pre v1.42 values) */ $preg_pattern = array('/([margin|width]:[^\\%]*)\\%\\%/', '/([margin|width]:.*)auto\\%/', '/([margin|width]:.*)inherit\\%/'); $preg_replacement = array('${1}%', '${1}auto', '${1}inherit'); $gallery_style = preg_replace($preg_pattern, $preg_replacement, $gallery_style); } // !empty template } // use_mla_gallery_style $upload_dir = wp_upload_dir(); $markup_values = $style_values; $markup_values['site_url'] = site_url(); $markup_values['base_url'] = $upload_dir['baseurl']; $markup_values['base_dir'] = $upload_dir['basedir']; $open_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-open', 'markup'); if (false === $open_template) { $markup_values['mla_markup'] = 'default'; $open_template = MLAOptions::mla_fetch_gallery_template('default-open', 'markup'); } if (empty($open_template)) { $open_template = ''; } $row_open_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-row-open', 'markup'); if (empty($row_open_template)) { $row_open_template = ''; } $item_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-item', 'markup'); if (empty($item_template)) { $item_template = ''; } $row_close_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-row-close', 'markup'); if (empty($row_close_template)) { $row_close_template = ''; } $close_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-close', 'markup'); if (empty($close_template)) { $close_template = ''; } /* * Look for gallery-level markup substitution parameters */ $new_text = $open_template . $row_open_template . $row_close_template . $close_template; $markup_values = MLAData::mla_expand_field_level_parameters($new_text, $attr, $markup_values); if (self::$mla_debug) { $output = self::$mla_debug_messages; self::$mla_debug_messages = ''; } else { $output = ''; } if ($is_gallery) { $markup_values = apply_filters('mla_gallery_open_values', $markup_values); $open_template = apply_filters('mla_gallery_open_template', $open_template); if (empty($open_template)) { $gallery_div = ''; } else { $gallery_div = MLAData::mla_parse_template($open_template, $markup_values); } $gallery_div = apply_filters('mla_gallery_open_parse', $gallery_div, $open_template, $markup_values); $output .= apply_filters('mla_gallery_style', $gallery_style . $gallery_div, $style_values, $markup_values, $style_template, $open_template); } else { if (!isset($attachments['found_rows'])) { $attachments['found_rows'] = 0; } /* * Handle 'previous_page', 'next_page', and 'paginate_links' */ $pagination_result = self::_process_pagination_output_types($output_parameters, $markup_values, $arguments, $attr, $attachments['found_rows'], $output); if (false !== $pagination_result) { return $pagination_result; } unset($attachments['found_rows']); } /* * For "previous_link" and "next_link", discard all of the $attachments except the appropriate choice */ if (!$is_gallery) { $is_previous = 'previous_link' == $output_parameters[0]; $is_next = 'next_link' == $output_parameters[0]; if (!($is_previous || $is_next)) { return ''; } // unknown outtput type $is_wrap = isset($output_parameters[1]) && 'wrap' == $output_parameters[1]; $current_id = empty($arguments['id']) ? $markup_values['id'] : $arguments['id']; foreach ($attachments as $id => $attachment) { if ($attachment->ID == $current_id) { break; } } $target_id = $is_previous ? $id - 1 : $id + 1; if (isset($attachments[$target_id])) { $attachments = array($attachments[$target_id]); } elseif ($is_wrap) { if ($is_next) { $attachments = array(array_shift($attachments)); } else { $attachments = array(array_pop($attachments)); } } elseif (!empty($arguments['mla_nolink_text'])) { return self::_process_shortcode_parameter($arguments['mla_nolink_text'], $markup_values) . '</a>'; } else { return ''; } } // ! is_gallery $column_index = 0; foreach ($attachments as $id => $attachment) { $item_values = $markup_values; /* * fill in item-specific elements */ $item_values['index'] = (string) 1 + $column_index; $item_values['excerpt'] = wptexturize($attachment->post_excerpt); $item_values['attachment_ID'] = $attachment->ID; $item_values['mime_type'] = $attachment->post_mime_type; $item_values['menu_order'] = $attachment->menu_order; $item_values['date'] = $attachment->post_date; $item_values['modified'] = $attachment->post_modified; $item_values['parent'] = $attachment->post_parent; $item_values['parent_title'] = '(unattached)'; $item_values['parent_type'] = ''; $item_values['parent_date'] = ''; $item_values['title'] = wptexturize($attachment->post_title); $item_values['slug'] = wptexturize($attachment->post_name); $item_values['width'] = ''; $item_values['height'] = ''; $item_values['image_meta'] = ''; $item_values['image_alt'] = ''; $item_values['base_file'] = ''; $item_values['path'] = ''; $item_values['file'] = ''; $item_values['description'] = wptexturize($attachment->post_content); $item_values['file_url'] = wptexturize($attachment->guid); $item_values['author_id'] = $attachment->post_author; $user = get_user_by('id', $attachment->post_author); if (isset($user->data->display_name)) { $item_values['author'] = wptexturize($user->data->display_name); } else { $item_values['author'] = 'unknown'; } $post_meta = MLAData::mla_fetch_attachment_metadata($attachment->ID); $base_file = $post_meta['mla_wp_attached_file']; $sizes = isset($post_meta['mla_wp_attachment_metadata']['sizes']) ? $post_meta['mla_wp_attachment_metadata']['sizes'] : array(); if (!empty($post_meta['mla_wp_attachment_metadata']['width'])) { $item_values['width'] = $post_meta['mla_wp_attachment_metadata']['width']; } if (!empty($post_meta['mla_wp_attachment_metadata']['height'])) { $item_values['height'] = $post_meta['mla_wp_attachment_metadata']['height']; } if (!empty($post_meta['mla_wp_attachment_metadata']['image_meta'])) { $item_values['image_meta'] = wptexturize(var_export($post_meta['mla_wp_attachment_metadata']['image_meta'], true)); } if (!empty($post_meta['mla_wp_attachment_image_alt'])) { $item_values['image_alt'] = wptexturize($post_meta['mla_wp_attachment_image_alt']); } if (!empty($base_file)) { $last_slash = strrpos($base_file, '/'); if (false === $last_slash) { $file_name = $base_file; $item_values['base_file'] = wptexturize($base_file); $item_values['file'] = wptexturize($base_file); } else { $file_name = substr($base_file, $last_slash + 1); $item_values['base_file'] = wptexturize($base_file); $item_values['path'] = wptexturize(substr($base_file, 0, $last_slash + 1)); $item_values['file'] = wptexturize($file_name); } } else { $file_name = ''; } $parent_info = MLAData::mla_fetch_attachment_parent_data($attachment->post_parent); if (isset($parent_info['parent_title'])) { $item_values['parent_title'] = wptexturize($parent_info['parent_title']); } if (isset($parent_info['parent_date'])) { $item_values['parent_date'] = wptexturize($parent_info['parent_date']); } if (isset($parent_info['parent_type'])) { $item_values['parent_type'] = wptexturize($parent_info['parent_type']); } /* * Add attachment-specific field-level substitution parameters */ $new_text = $item_template . str_replace('{+', '[+', str_replace('+}', '+]', $arguments['mla_link_attributes'] . $arguments['mla_link_class'] . $arguments['mla_link_href'] . $arguments['mla_link_text'] . $arguments['mla_nolink_text'] . $arguments['mla_rollover_text'] . $arguments['mla_image_class'] . $arguments['mla_image_alt'] . $arguments['mla_image_attributes'] . $arguments['mla_caption'])); $item_values = MLAData::mla_expand_field_level_parameters($new_text, $attr, $item_values, $attachment->ID); if ($item_values['captiontag']) { $item_values['caption'] = wptexturize($attachment->post_excerpt); if (!empty($arguments['mla_caption'])) { $item_values['caption'] = wptexturize(self::_process_shortcode_parameter($arguments['mla_caption'], $item_values)); } } else { $item_values['caption'] = ''; } if (!empty($arguments['mla_link_text'])) { $link_text = self::_process_shortcode_parameter($arguments['mla_link_text'], $item_values); } else { $link_text = false; } $item_values['pagelink'] = wp_get_attachment_link($attachment->ID, $size, true, $show_icon, $link_text); $item_values['filelink'] = wp_get_attachment_link($attachment->ID, $size, false, $show_icon, $link_text); /* * Apply the Gallery Display Content parameters. * Note that $link_attributes and $rollover_text * are used in the Google Viewer code below */ if (!empty($arguments['mla_target'])) { $link_attributes = 'target="' . $arguments['mla_target'] . '" '; } else { $link_attributes = ''; } if (!empty($arguments['mla_link_attributes'])) { $link_attributes .= self::_process_shortcode_parameter($arguments['mla_link_attributes'], $item_values) . ' '; } if (!empty($arguments['mla_link_class'])) { $link_attributes .= 'class="' . self::_process_shortcode_parameter($arguments['mla_link_class'], $item_values) . '" '; } if (!empty($link_attributes)) { $item_values['pagelink'] = str_replace('<a href=', '<a ' . $link_attributes . 'href=', $item_values['pagelink']); $item_values['filelink'] = str_replace('<a href=', '<a ' . $link_attributes . 'href=', $item_values['filelink']); } if (!empty($arguments['mla_rollover_text'])) { $rollover_text = esc_attr(self::_process_shortcode_parameter($arguments['mla_rollover_text'], $item_values)); /* * Replace single- and double-quote delimited values */ $item_values['pagelink'] = preg_replace('# title=\'([^\']*)\'#', " title='{$rollover_text}'", $item_values['pagelink']); $item_values['pagelink'] = preg_replace('# title=\\"([^\\"]*)\\"#', " title=\"{$rollover_text}\"", $item_values['pagelink']); $item_values['filelink'] = preg_replace('# title=\'([^\']*)\'#', " title='{$rollover_text}'", $item_values['filelink']); $item_values['filelink'] = preg_replace('# title=\\"([^\\"]*)\\"#', " title=\"{$rollover_text}\"", $item_values['filelink']); } else { $rollover_text = $item_values['title']; } /* * Process the <img> tag, if present * Note that $image_attributes, $image_class and $image_alt * are used in the Google Viewer code below */ if (!empty($arguments['mla_image_attributes'])) { $image_attributes = self::_process_shortcode_parameter($arguments['mla_image_attributes'], $item_values) . ' '; } else { $image_attributes = ''; } if (!empty($arguments['mla_image_class'])) { $image_class = esc_attr(self::_process_shortcode_parameter($arguments['mla_image_class'], $item_values)); } else { $image_class = ''; } if (!empty($arguments['mla_image_alt'])) { $image_alt = esc_attr(self::_process_shortcode_parameter($arguments['mla_image_alt'], $item_values)); } else { $image_alt = ''; } if (false !== strpos($item_values['pagelink'], '<img ')) { if (!empty($image_attributes)) { $item_values['pagelink'] = str_replace('<img ', '<img ' . $image_attributes, $item_values['pagelink']); $item_values['filelink'] = str_replace('<img ', '<img ' . $image_attributes, $item_values['filelink']); } /* * Extract existing class values and add to them */ if (!empty($image_class)) { $match_count = preg_match_all('# class=\\"([^\\"]+)\\" #', $item_values['pagelink'], $matches, PREG_OFFSET_CAPTURE); if (!($match_count == false || $match_count == 0)) { $class = $matches[1][0][0] . ' ' . $image_class; } else { $class = $image_class; } $item_values['pagelink'] = preg_replace('# class=\\"([^\\"]*)\\"#', " class=\"{$class}\"", $item_values['pagelink']); $item_values['filelink'] = preg_replace('# class=\\"([^\\"]*)\\"#', " class=\"{$class}\"", $item_values['filelink']); } if (!empty($image_alt)) { $item_values['pagelink'] = preg_replace('# alt=\\"([^\\"]*)\\"#', " alt=\"{$image_alt}\"", $item_values['pagelink']); $item_values['filelink'] = preg_replace('# alt=\\"([^\\"]*)\\"#', " alt=\"{$image_alt}\"", $item_values['filelink']); } } // process <img> tag switch ($arguments['link']) { case 'permalink': case 'post': $item_values['link'] = $item_values['pagelink']; break; case 'file': case 'full': $item_values['link'] = $item_values['filelink']; break; default: $item_values['link'] = $item_values['filelink']; /* * Check for link to specific (registered) file size */ if (array_key_exists($arguments['link'], $sizes)) { $target_file = $sizes[$arguments['link']]['file']; $item_values['link'] = str_replace($file_name, $target_file, $item_values['filelink']); } } // switch 'link' /* * Extract target and thumbnail fields */ $match_count = preg_match_all('#href=\'([^\']+)\'#', $item_values['pagelink'], $matches, PREG_OFFSET_CAPTURE); if (!($match_count == false || $match_count == 0)) { $item_values['pagelink_url'] = $matches[1][0][0]; } else { $item_values['pagelink_url'] = ''; } $match_count = preg_match_all('#href=\'([^\']+)\'#', $item_values['filelink'], $matches, PREG_OFFSET_CAPTURE); if (!($match_count == false || $match_count == 0)) { $item_values['filelink_url'] = $matches[1][0][0]; } else { $item_values['filelink_url'] = ''; } $match_count = preg_match_all('#href=\'([^\']+)\'#', $item_values['link'], $matches, PREG_OFFSET_CAPTURE); if (!($match_count == false || $match_count == 0)) { $item_values['link_url'] = $matches[1][0][0]; } else { $item_values['link_url'] = ''; } /* * Override the link value; leave filelink and pagelink unchanged * Note that $link_href is used in the Google Viewer code below */ if (!empty($arguments['mla_link_href'])) { $link_href = self::_process_shortcode_parameter($arguments['mla_link_href'], $item_values); /* * Replace single- and double-quote delimited values */ $item_values['link'] = preg_replace('# href=\'([^\']*)\'#', " href='{$link_href}'", $item_values['link']); $item_values['link'] = preg_replace('# href=\\"([^\\"]*)\\"#', " href=\"{$link_href}\"", $item_values['link']); } else { $link_href = ''; } $match_count = preg_match_all('#\\<a [^\\>]+\\>(.*)\\</a\\>#', $item_values['link'], $matches, PREG_OFFSET_CAPTURE); if (!($match_count == false || $match_count == 0)) { $item_values['thumbnail_content'] = $matches[1][0][0]; } else { $item_values['thumbnail_content'] = ''; } $match_count = preg_match_all('# width=\\"([^\\"]+)\\" height=\\"([^\\"]+)\\" src=\\"([^\\"]+)\\" #', $item_values['link'], $matches, PREG_OFFSET_CAPTURE); if (!($match_count == false || $match_count == 0)) { $item_values['thumbnail_width'] = $matches[1][0][0]; $item_values['thumbnail_height'] = $matches[2][0][0]; $item_values['thumbnail_url'] = $matches[3][0][0]; } else { $item_values['thumbnail_width'] = ''; $item_values['thumbnail_height'] = ''; $item_values['thumbnail_url'] = ''; } /* * Check for Google file viewer substitution, uses above-defined * $link_attributes (includes target), $rollover_text, $link_href (link only), * $image_attributes, $image_class, $image_alt */ if ($arguments['mla_viewer'] && empty($item_values['thumbnail_url'])) { $last_dot = strrpos($item_values['file'], '.'); if (!(false === $last_dot)) { $extension = substr($item_values['file'], $last_dot + 1); if (in_array($extension, $arguments['mla_viewer_extensions'])) { /* * <img> tag (thumbnail_text) */ if (!empty($image_class)) { $image_class = ' class="' . $image_class . '"'; } if (!empty($image_alt)) { $image_alt = ' alt="' . $image_alt . '"'; } elseif (!empty($item_values['caption'])) { $image_alt = ' alt="' . $item_values['caption'] . '"'; } $item_values['thumbnail_content'] = sprintf('<img %1$ssrc="http://docs.google.com/viewer?url=%2$s&a=bi&pagenumber=%3$d&w=%4$d"%5$s%6$s>', $image_attributes, $item_values['filelink_url'], $arguments['mla_viewer_page'], $arguments['mla_viewer_width'], $image_class, $image_alt); /* * Filelink, pagelink and link */ $item_values['pagelink'] = sprintf('<a %1$shref="%2$s" title="%3$s">%4$s</a>', $link_attributes, $item_values['pagelink_url'], $rollover_text, $item_values['thumbnail_content']); $item_values['filelink'] = sprintf('<a %1$shref="%2$s" title="%3$s">%4$s</a>', $link_attributes, $item_values['filelink_url'], $rollover_text, $item_values['thumbnail_content']); if (!empty($link_href)) { $item_values['link'] = sprintf('<a %1$shref="%2$s" title="%3$s">%4$s</a>', $link_attributes, $link_href, $rollover_text, $item_values['thumbnail_content']); } elseif ('permalink' == $arguments['link']) { $item_values['link'] = $item_values['pagelink']; } else { $item_values['link'] = $item_values['filelink']; } } // viewer extension } // has extension } // mla_viewer if ($is_gallery) { /* * Start of row markup */ if ($markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0) { $markup_values = apply_filters('mla_gallery_row_open_values', $markup_values); $row_open_template = apply_filters('mla_gallery_row_open_template', $row_open_template); $parse_value = MLAData::mla_parse_template($row_open_template, $markup_values); $output .= apply_filters('mla_gallery_row_open_parse', $parse_value, $row_open_template, $markup_values); } /* * item markup */ $column_index++; if ($item_values['columns'] > 0 && $column_index % $item_values['columns'] == 0) { $item_values['last_in_row'] = 'last_in_row'; } else { $item_values['last_in_row'] = ''; } $item_values = apply_filters('mla_gallery_item_values', $item_values); $item_template = apply_filters('mla_gallery_item_template', $item_template); $parse_value = MLAData::mla_parse_template($item_template, $item_values); $output .= apply_filters('mla_gallery_item_parse', $parse_value, $item_template, $item_values); /* * End of row markup */ if ($markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0) { $markup_values = apply_filters('mla_gallery_row_close_values', $markup_values); $row_close_template = apply_filters('mla_gallery_row_close_template', $row_close_template); $parse_value = MLAData::mla_parse_template($row_close_template, $markup_values); $output .= apply_filters('mla_gallery_row_close_parse', $parse_value, $row_close_template, $markup_values); } } elseif ($is_previous || $is_next) { return $item_values['link']; } } // foreach attachment if ($is_gallery) { /* * Close out partial row */ if (!($markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0)) { $markup_values = apply_filters('mla_gallery_row_close_values', $markup_values); $row_close_template = apply_filters('mla_gallery_row_close_template', $row_close_template); $parse_value = MLAData::mla_parse_template($row_close_template, $markup_values); $output .= apply_filters('mla_gallery_row_close_parse', $parse_value, $row_close_template, $markup_values); } $markup_values = apply_filters('mla_gallery_close_values', $markup_values); $close_template = apply_filters('mla_gallery_close_template', $close_template); $parse_value = MLAData::mla_parse_template($close_template, $markup_values); $output .= apply_filters('mla_gallery_close_parse', $parse_value, $close_template, $markup_values); } // is_gallery return $output; }