/** * Builds the List shortcode output. * * @since 1.0.0 * @param array $atts Attributes of the list shortcode. * @param string $content Shortcode content. * @return string HTML content to display the list. */ public static function list_($atts = null, $content = null) { $atts = shortcode_atts(array('icon' => '', 'class' => ''), $atts, 'list'); $icon_type = false === strpos($atts['icon'], 'icon:') ? 'image-icon' : 'font-icon'; $uniq_class = 'cherry-list_' . rand(1000, 9999); $classes = apply_filters('cherry_shortcodes_list_classes', array('cherry-list', $icon_type, $uniq_class, cherry_esc_class_attr($atts)), $atts); $class = implode(' ', $classes); $output = '<div class="' . $class . '">'; $output .= Cherry_Shortcodes_Tools::append_icons($content, $atts['icon']); if ('image-icon' == $icon_type) { $image = Cherry_Shortcodes_Tools::get_image_url($atts['icon']); $style = '.' . $uniq_class . ' ul li:before {background-image: url(' . $image . '); }'; $output .= sprintf('<style>%s</style>', $style); } $output .= '</div>'; return apply_filters('cherry_shortcodes_output', $output, $atts, 'list'); }
/** * Get icon HTML markup from icon attr value in shortcode. * Get icon HTML for Cherry shortcodes. * * @since 1.0.0 * * @param string $icon Passed icon. * @param string $class Custom class for icon. * @param string $alt Alt attribute value if icon is image. * @return string Icon HTML markup. */ public static function get_icon_html($icon, $class = 'cherry-icon', $alt = null, $style = array()) { if (!$icon || 'none' == $icon) { return false; } if (false !== strpos($icon, 'icon:')) { $icon = trim(str_replace('icon:', '', $icon)); $style = Cherry_Shortcodes_Tools::prepare_styles($style); $rand_class = Cherry_Shortcodes_Tools::rand_class('icon'); $style = sprintf('%s{%s}', $rand_class, $style); $class .= ' ' . Cherry_Shortcodes_Tools::esc_class($rand_class); Cherry_Shortcodes_Tools::print_styles($style); return sprintf('<span class="%1$s %2$s"></span>', esc_attr($icon), esc_attr($class)); } else { $icon = Cherry_Shortcodes_Tools::get_image_url($icon); return sprintf('<span class="%2$s"><img src="%1$s" alt="%3$s"></span>', esc_url($icon), esc_attr($class), esc_attr($alt)); } }
/** * Retrieve a post image. * * @since 1.0.0 * @global WP_Post $post WP_Post object. * @param string $size Image size. * @return string Image tag. */ public function image($size = '') { global $post; $shortcode = Cherry_Shortcodes_Handler::get_shortcode_name(); if ('banner' == $shortcode) { return Cherry_Shortcodes_Tools::get_image_url($this->atts['image']); } if (!post_type_supports(get_post_type($post->ID), 'thumbnail')) { return; } if (!has_post_thumbnail($post->ID)) { return; } $url = get_permalink($post->ID); $image_classes = array(); $image_classes[] = 'post-thumbnail_link'; switch ($shortcode) { case 'posts': if (empty($size)) { $size = sanitize_key($this->atts['image_size']); } if (isset($this->atts['lightbox_image']) && 'yes' === $this->atts['lightbox_image']) { $image_classes[] = 'cherry-popup-img'; $image_classes[] = 'popup-img'; $thumbnail_id = get_post_thumbnail_id($post->ID); $url = wp_get_attachment_url($thumbnail_id); if (!$url) { $url = get_permalink($post->ID); } wp_enqueue_script('magnific-popup'); } $thumbnail = get_the_post_thumbnail($post->ID, $size); break; case 'swiper_carousel': $post_id = get_the_ID(); $crop_image = (bool) ('yes' === $this->atts['crop_image']) ? true : false; $crop_width = intval($this->atts['crop_width']); $crop_height = intval($this->atts['crop_height']); if ($crop_image) { $img_url = wp_get_attachment_url(get_post_thumbnail_id(), 'full'); $thumbnail = Cherry_Shortcodes_Tools::get_crop_image($img_url, get_post_thumbnail_id(), $crop_width, $crop_height); } else { $thumbnail = get_the_post_thumbnail($post->ID, 'large'); } break; default: if (empty($this->atts['image_size'])) { $thumbnail = get_the_post_thumbnail($post->ID, 'large'); } else { $thumbnail = get_the_post_thumbnail($post->ID, sanitize_key($this->atts['image_size'])); } break; } $wrap = 'no' === $this->atts['linked_image'] ? '%3$s' : '<a href="%1$s" title="%2$s" class="%4$s">%3$s</a>'; $image_classes = apply_filters('cherry_shortcodes_image_classes_template_callbacks', $image_classes, $shortcode); $image_classes = array_unique($image_classes); $image_classes = array_map('sanitize_html_class', $image_classes); $image = sprintf($wrap, esc_url($url), esc_attr(the_title_attribute(array('before' => '', 'after' => '', 'echo' => false, 'post' => $post->ID))), $thumbnail, join(' ', $image_classes)); /** * Filter a image. * * @since 1.0.0 * @param string $image Image tag. * @param array $atts Shortcode attributes. * @param string $shortcode Shortcode name. */ return apply_filters('cherry_shortcodes_image_template_callbacks', $image, $this->atts, $shortcode); }