function dt_metabox_benefits_options($post) { $box_name = 'dt_benefits_options'; $defaults = array('retina_image' => '', 'retina_image_w' => 0, 'retina_image_h' => 0, 'retina_image_id' => null); $opts = get_post_meta($post->ID, '_' . $box_name, true); $opts = wp_parse_args(maybe_unserialize($opts), $defaults); // Use nonce for verification wp_nonce_field(plugin_basename(__FILE__), $box_name . '_nonce'); // image $img_id = '<input type="hidden" value="' . $opts['retina_image_id'] . '" class="dt-uploader-textfield dt-get-id" name="' . $box_name . '_retina_image_id" />'; // upload button $upload = dt_melement('link', array('description' => _x('Upload Image', 'backend benefits', LANGUAGE_ZONE), 'class' => 'dt-uploader-opener button-primary thickbox', 'href' => get_admin_url() . 'media-upload.php?post_id=' . $post->ID . '&type=image&TB_iframe=1&width=640&height=310')); // delete button $delete = dt_melement('link', array('description' => _x('Clear', 'backend benefits', LANGUAGE_ZONE), 'class' => 'dt-uploader-delete button', 'href' => '#')); ?> <p class="dt_switcher-box"><?php if ($opts['retina_image_id']) { $img = wp_get_attachment_image_src($opts['retina_image_id'], 'medium'); if ($img) { $size = wp_constrain_dimensions($img[1], $img[2], 266, 266); echo '<img class="attachment-266x266 dt-thumb" src="' . $img[0] . '" ' . image_hwstring($size[0], $size[1]) . ' />'; } } echo $img_id . $upload . $delete; ?> </p> <?php }
function zn_logo($logo = null, $use_transparent = false, $tag = null, $class = null) { $transparent_logo = ''; if (!$tag) { if (is_front_page()) { $tag = 'h1'; } else { $tag = 'h3'; } } if ('transparent_header' == get_post_meta(zn_get_the_id(), 'header_style', true) && $use_transparent) { $transparent_logo = zget_option('transparent_logo', 'general_options'); } if ($logo || ($logo = zget_option('logo', 'general_options'))) { // TODO: remove this as it is slow withouth the full path $logo_size = array('300', '100'); //print_z($logo_size); $hwstring = image_hwstring($logo_size[0], $logo_size[1]); $logo = '<img class="non-transparent" src="' . set_url_scheme($logo) . '" ' . $hwstring . ' alt="' . get_bloginfo('name') . '" title="' . get_bloginfo('description') . '" />'; if ($transparent_logo && $transparent_logo != ' ') { $logo .= '<img class="only-transparent" src="' . set_url_scheme($transparent_logo) . '" alt="' . get_bloginfo('name') . '" title="' . get_bloginfo('description') . '" />'; } $logo = "<{$tag} class='logo {$class}' id='logo'><a href='" . home_url('/') . "'>" . $logo . "</a></{$tag}>"; } else { $logo = '<img src="' . THEME_BASE_URI . '/images/logo.png" alt="' . get_bloginfo('name') . '" title="' . get_bloginfo('description') . '" />'; $logo = "<{$tag} class='logo {$class}' id='logo'><a href='" . home_url('/') . "'>" . $logo . "</a></{$tag}>"; } return $logo; }
function widget($args, $instance) { extract($args); $instance = wp_parse_args((array) $instance, self::$widget_defaults); /* Our variables from the widget settings. */ $title = apply_filters('widget_title', $instance['title']); $args = array('no_found_rows' => 1, 'posts_per_page' => $instance['show'], 'post_type' => 'dt_portfolio', 'post_status' => 'publish', 'orderby' => $instance['orderby'], 'order' => $instance['order'], 'tax_query' => array(array('taxonomy' => 'dt_portfolio_category', 'field' => 'term_id', 'terms' => $instance['cats']))); switch ($instance['select']) { case 'only': $args['tax_query'][0]['operator'] = 'IN'; break; case 'except': $args['tax_query'][0]['operator'] = 'NOT IN'; break; default: unset($args['tax_query']); } $p_query = new WP_Query($args); // for usage as shortcode if (!isset($img_size)) { $img_size = array($instance['max_width'], $instance['max_width']); } if (!isset($img_size_origin)) { $img_size_origin = $img_size; } else { $p = $img_size[1] / $img_size[0]; $img_size_origin[1] = round($img_size_origin[0] * $p); } echo $before_widget; // title if ($title) { echo $before_title . $title . $after_title; } if ($p_query->have_posts()) { update_post_thumbnail_cache($p_query); echo '<div class="instagram-photos" data-image-max-width="' . absint($instance['max_width']) . '">'; while ($p_query->have_posts()) { $p_query->the_post(); $thumb_id = get_post_thumbnail_id(get_the_ID()); if (!has_post_thumbnail(get_the_ID())) { $args = array('posts_per_page' => 1, 'no_found_rows' => 1, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => get_the_ID(), 'post_status' => 'inherit'); $images = new WP_Query($args); if ($images->have_posts()) { $thumb_id = $images->posts[0]->ID; } } $thumb_meta = wp_get_attachment_image_src($thumb_id, 'full'); dt_get_thumb_img(array('img_meta' => $thumb_meta ? $thumb_meta : null, 'img_id' => $thumb_id, 'use_noimage' => true, 'class' => 'post-rollover', 'title' => get_the_title(), 'href' => get_permalink(), 'options' => array('w' => $img_size_origin[0], 'h' => $img_size_origin[1]), 'wrap' => "\n" . '<a %HREF% %TITLE% %CLASS% %CUSTOM%><img %IMG_CLASS% %SRC% ' . image_hwstring($img_size[0], $img_size[1]) . ' %ALT% /></a>' . "\n")); } // while have posts wp_reset_postdata(); echo '</div>'; } // if have posts echo $after_widget; }
function wpjam_get_post_thumbnail($post = null, $size = 'thumbnail', $crop = 1, $class = "wp-post-image") { $post_thumbnail_src = wpjam_get_post_thumbnail_src($post, $size, $crop); if ($post_thumbnail_src) { $size = wpjam_get_dimensions($size); extract($size); $hwstring = image_hwstring($width, $height); return '<img src="' . $post_thumbnail_src . '" alt="' . the_title_attribute(array('echo' => false)) . '" class="' . $class . '"' . $hwstring . ' />'; } else { return false; } }
function getImageTag($id, $alt, $title, $align, $size = 'medium', $attrs = array()) { list($img_src, $width, $height) = image_downsize($id, $size); $hwstring = image_hwstring($width, $height); $class = 'align' . esc_attr($align) . ' size-' . esc_attr($size) . ' wp-image-' . $id; $class = apply_filters('get_image_tag_class', $class, $id, $align, $size); $attrs_fields = ''; foreach ($attrs as $name => $attr) { $attrs_fields .= ' ' . $name . '="' . esc_attr($attr) . '" '; } $html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" title="' . esc_attr($title) . '" ' . $hwstring . 'class="' . $class . '" ' . $attrs_fields . ' />'; return $html; }
protected function get_image_html($image_id) { $image_html = ''; if (wp_attachment_is_image($image_id)) { $image_src = wp_get_attachment_image_src($image_id, 'full'); $image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', true); if (presscore_image_title_enabled($image_id)) { $image_title = ' title="' . esc_attr(get_the_title($image_id)) . '"'; } else { $image_title = ''; } $image_html = '<img class="preload-me" src="' . $image_src[0] . '" ' . image_hwstring($image_src[1], $image_src[2]) . $image_title . ' alt="' . esc_attr($image_alt) . '">'; } return $image_html; }
/** * argo_get_image_tag(): Renders an <img /> tag for attachments, scaling it * to $size and guaranteeing that it's not wider than the content well. * * This is largely taken from get_image_tag() in wp-includes/media.php. */ function argo_get_image_tag($html, $id, $alt, $title, $align, $size) { // Never allow an image wider than the LARGE_WIDTH if ($size == 'full') { list($img_src, $width, $height) = wp_get_attachment_image_src($id, $size); if ($width > LARGE_WIDTH) { $size = 'large'; } } list($img_src, $width, $height) = image_downsize($id, $size); $hwstring = image_hwstring($width, $height); // XXX: may not need all these classes $class = 'align' . esc_attr($align) . ' size-' . esc_attr($size) . ' wp-image-' . $id; $class = apply_filters('get_image_tag_class', $class, $id, $align, $size); $html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" title="' . esc_attr($title) . '" ' . $hwstring . 'class="' . $class . '" />'; return $html; }
if (trim($atts['height'])) { $atts['height'] = absint($atts['height']); } //title $atts['title'] = esc_attr(trim($atts['title'])); //src $atts['src'] = trim($atts['src']); if (is_numeric($atts['src'])) { $image_size = apply_filters('wmhook_shortcode_' . $shortcode . '_image_size', 'full', $atts); $attr = array('title' => esc_attr(get_the_title(absint($atts['src'])))); $atts['content'] = wp_get_attachment_image(absint($atts['src']), $image_size, false, $attr); if (trim(image_hwstring($atts['width'], $atts['height']))) { $atts['content'] = preg_replace('/(width|height)="\\d*"\\s/', '', $atts['content']); $atts['content'] = str_replace('<img ', '<img ' . trim(image_hwstring($atts['width'], $atts['height'])), $atts['content']); } if ($atts['margin']) { $atts['content'] = str_replace(' />', $atts['margin'] . ' />', $atts['content']); } } else { $atts['content'] = '<img src="' . esc_url($atts['src']) . '" title="' . esc_attr($atts['title']) . '" alt="' . esc_attr($atts['title']) . '"' . trim(image_hwstring($atts['width'], $atts['height'])) . ' />'; } //link $atts['link'] = trim($atts['link']); if ($atts['link']) { $atts['content'] = '<a href="' . esc_url($atts['link']) . '"' . $atts['attributes'] . '>' . $atts['content'] . '</a>'; } //content filters $atts['content'] = apply_filters('wmhook_shortcode_' . '_content', $atts['content'], $shortcode, $atts); $atts['content'] = apply_filters('wmhook_shortcode_' . $shortcode . '_content', $atts['content'], $atts); //Output $output = '<div class="' . esc_attr($atts['class']) . '">' . $atts['content'] . '</div>';
function raindrops_featured_image() { global $post, $is_IE, $raindrops_featured_image_full_size, $raindrops_use_featured_image_light_box; $raindrops_featured_image_enable = apply_filters('raindrops_featured_image_enable', true); if (is_single() && "hide" == raindrops_warehouse_clone('raindrops_featured_image_singular')) { $raindrops_featured_image_enable = false; } if (post_password_required() || !has_post_thumbnail() || false == $raindrops_featured_image_enable) { return; } /** * Show featured image * * * * */ if (true == $raindrops_featured_image_full_size) { $thumb = get_the_post_thumbnail($post->ID, 'full'); } else { $thumb = get_the_post_thumbnail($post->ID, 'single-post-thumbnail'); } if (has_post_thumbnail() && isset($thumb) && $is_IE && $raindrops_use_featured_image_light_box == false) { /* IE8 img element has width height attribute. and style max-width and height auto makes conflict expand height */ $thumbnailsrc = wp_get_attachment_image_src(get_post_thumbnail_id(), 'single-post-thumbnail'); $thumbnailuri = esc_url($thumbnailsrc[0]); $thumbnailwidth = $thumbnailsrc[1]; if ($thumbnailwidth > $content_width) { $thumbnailheight = $thumbnailsrc[2]; $ratio = round(RAINDROPS_SINGLE_POST_THUMBNAIL_HEIGHT / RAINDROPS_SINGLE_POST_THUMBNAIL_WIDTH, 2); $ie_height = round($content_width * $ratio); $thumbnail_title = basename($thumbnailsrc[0]); $thumbnail_title = esc_attr($thumbnail_title); $size_attribute = image_hwstring($content_width, $ie_height); echo '<div class="single-post-thumbnail">'; echo '<img src="' . $thumbnailuri . '" ' . $size_attribute . '" alt="' . $thumbnail_title . '" />'; echo '</div>'; } else { echo '<div class="single-post-thumbnail">'; echo $thumb; echo '</div>'; } } else { $raindrops_post_thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full', false, ''); $flag = true; if ('w3standard' == raindrops_warehouse('raindrops_style_type') || false == $raindrops_use_featured_image_light_box) { //Sorry w3standard css can not use CSS3 then remove light box $flag = false; } if (!empty($thumb)) { echo '<div class="single-post-thumbnail">'; if ($flag) { echo '<a href="#raindrops-light-box" class="raindrops-light-box">'; } else { printf('<a href="%1$s">', get_attachment_link(get_post_thumbnail_id())); } echo $thumb; if ($flag) { echo '</a>'; } echo '</div>'; /* for light box */ if ($flag) { echo '<div class="raindrops-lightbox-overlay" id="raindrops-light-box">'; echo '<a href="#page" class="lb-close">Close</a>'; echo '<img src="' . $raindrops_post_thumbnail_src[0] . '" alt="single post thumbnail" />'; echo '</div>'; } } } /** * Add navigation link for post thumbnail * * * * */ if (has_post_thumbnail() && true == $raindrops_use_featured_image_light_box) { $raindrops_html_piece = '<p style="text-align:center;font-size:small;"><a href="%1$s">%2$s</a></p>'; printf($raindrops_html_piece, get_attachment_link(get_post_thumbnail_id()), esc_html__('Go to Attachment page', 'raindrops')); } }
function zn_get_image($attachment_id = null, $width, $height = 0, $attr = array(), $popup = false) { if (!$attachment_id) { return; } $html = ''; $image = wp_get_attachment_image_src($attachment_id, 'full'); if ($image) { // print_z($image); $resized = mr_image_resize($image['0'], $width, $height, true, 'c', false); if (is_array($resized)) { $hwstring = image_hwstring($resized['width'], $resized['height']); } else { $hwstring = image_hwstring($width, $height); $resized = array('url' => $resized, 'width' => $width, 'height' => $height); } $attachment = get_post($attachment_id); $default_attr = array('src' => $resized['url'], 'class' => "img-responsive", 'alt' => trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true)))); if (empty($default_attr['alt'])) { $default_attr['alt'] = trim(strip_tags($attachment->post_excerpt)); } if (empty($default_attr['alt'])) { $default_attr['alt'] = trim(strip_tags($attachment->post_title)); } $attr = wp_parse_args($attr, $default_attr); $attr = array_map('esc_attr', $attr); // ADD MAGNIFIC POPUP functionality if ($popup) { $attr['data-mfp-src'] = $image[0]; } $html = rtrim("<img {$hwstring}"); foreach ($attr as $name => $value) { $html .= " {$name}=" . '"' . $value . '"'; } $html .= ' />'; } return $html; }
function start_el(&$output, $item, $depth = 0, $args = array(), $current_id = 0) { $item = apply_filters('dt_nav_menu_item', $item, $args, $depth); $args = apply_filters('dt_nav_menu_args', $args, $item, $depth); $class_names = $value = ''; $classes = empty($item->classes) ? array() : (array) $item->classes; $classes[] = 'menu-item-' . $item->ID; $first_class = ''; $act_class = ''; $item_icon = ''; $if_parent_not_clickable = ''; // mega menu part if (!empty($args->please_be_mega_menu)) { if (0 == $depth) { if (!empty($item->dt_mega_menu_enabled)) { $this->dt_fat_menu = true; $this->dt_fat_menu_columns = $item->dt_mega_menu_columns; } else { $this->dt_fat_menu = false; $this->dt_fat_menu_columns = 3; } } if ($this->dt_fat_menu && !empty($args->please_be_fat)) { $columns_classes = array(1 => 'wf-1', 2 => 'wf-1-2', 3 => 'wf-1-3', 4 => 'wf-1-4', 5 => 'wf-1-5'); if (0 == $depth) { $classes[] = 'dt-mega-menu'; if (!empty($item->dt_mega_menu_fullwidth)) { $classes[] = 'mega-full-width'; } else { $classes[] = 'mega-auto-width'; } if (!empty($item->dt_mega_menu_columns)) { $classes[] = 'mega-column-' . absint($item->dt_mega_menu_columns); } } else { if (1 == $depth) { if (!empty($item->dt_mega_menu_hide_title)) { $classes[] = 'hide-mega-title'; } if (!empty($item->dt_mega_menu_remove_link)) { $item->url = 'javascript: void(0);'; $classes[] = 'no-link'; } $classes[] = 'dt-mega-parent'; if (!empty($this->dt_fat_menu_columns) && isset($columns_classes[$this->dt_fat_menu_columns])) { $classes[] = $columns_classes[$this->dt_fat_menu_columns]; } if (!empty($item->dt_mega_menu_new_row)) { $classes[] = 'new-row'; } $this->dt_parent_description = $item->description; $this->dt_parent_mega_menu_hide_title = $item->dt_mega_menu_hide_title; } else { if (2 == $depth) { if (!empty($item->dt_mega_menu_new_column)) { $fake_column_classes = array('menu-item', 'menu-item-has-children', 'dt-mega-parent', 'has-children', 'new-column'); if (!empty($this->dt_fat_menu_columns) && isset($columns_classes[$this->dt_fat_menu_columns])) { $fake_column_classes[] = $columns_classes[$this->dt_fat_menu_columns]; } if ($this->dt_parent_mega_menu_hide_title) { $fake_column_classes[] = 'hide-mega-title'; } $fake_column_classes = apply_filters('nav_menu_css_class', $fake_column_classes, null, $args, $depth - 1); $output .= $args->dt_submenu_wrap_end . $args->dt_item_wrap_end; $output .= str_replace(array('%ITEM_HREF%', '%ITEM_TITLE%', '%ITEM_CLASS%', '%SPAN_DESCRIPTION%', '%ESC_ITEM_TITLE%', '%IS_FIRST%', '%BEFORE_LINK%', '%AFTER_LINK%', '%DEPTH%', '%ACT_CLASS%', '%RAW_ITEM_HREF%', '%IF_PARENT_NOT_CLICKABLE%', '%DESCRIPTION%', '%ICON%'), array('javascript:void(0)" onclick="return false;" style="cursor: default;', ' ', join(' ', $fake_column_classes), $this->dt_parent_description ? '<span class="menu-subtitle"> </span>' : '', ''), $args->dt_item_wrap_start); $output .= $args->dt_submenu_wrap_start; $this->dt_is_first = true; } } } } } if (!empty($item->dt_mega_menu_icon)) { switch ($item->dt_mega_menu_icon) { case 'image': if (!empty($item->dt_mega_menu_image)) { // get icon size if (!empty($item->dt_mega_menu_image_width) && !empty($item->dt_mega_menu_image_height)) { $icon_size = image_hwstring($item->dt_mega_menu_image_width, $item->dt_mega_menu_image_height); } else { $icon_size = ''; } $item_icon = '<span class="mega-icon"><img src="' . esc_url($item->dt_mega_menu_image) . '" alt="' . esc_attr($item->title) . '" ' . $icon_size . '/></span>'; } break; case 'iconfont': if (!empty($item->dt_mega_menu_iconfont)) { $item_icon = wp_kses($item->dt_mega_menu_iconfont, array('i' => array('class' => array()))); } break; } } } // mega menu part ends // current element if (in_array('current-menu-item', $classes) || in_array('current-menu-parent', $classes) || in_array('current-menu-ancestor', $classes)) { $classes[] = 'act'; } if ($this->dt_is_first) { $classes[] = 'first'; $first_class = 'class="first"'; } if (in_array('current-menu-item', $classes)) { $act_class = isset($args->act_class) ? $args->act_class : 'act'; } $dt_is_parent = in_array($item->ID, $this->dt_menu_parents); // add parent class if ($dt_is_parent) { $classes[] = 'has-children'; } $atts = array(); $atts['title'] = !empty($item->attr_title) ? $item->attr_title : ''; $atts['target'] = !empty($item->target) ? $item->target : ''; $atts['rel'] = !empty($item->xfn) ? $item->xfn : ''; $atts['href'] = !empty($item->url) ? $item->url : ''; if (!$args->parent_clicable && $dt_is_parent) { $atts['onclick'] = 'return false;'; $if_parent_not_clickable = isset($args->if_parent_not_clickable) ? $args->if_parent_not_clickable : ''; $classes[] = 'no-link'; } $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args); $item_href = esc_url($atts['href']); $item_title = esc_attr($atts['title']); unset($atts['href'], $atts['title']); $attributes = ''; foreach ($atts as $attr => $value) { if (!empty($value)) { $value = esc_attr($value); $attributes .= '" ' . $attr . '="' . $value; } } $before_link = $after_link = ''; $class_names = join(' ', apply_filters('nav_menu_css_class', array_unique($classes), $item, $args, $depth)); $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args); $id = strlen($id) ? ' id="' . esc_attr($id) . '"' : ''; $dt_title = apply_filters('the_title', $item->title, $item->ID); $dt_title = apply_filters('dt_nav_menu_title', $dt_title, $item, $args, $depth); $output .= str_replace(array('%ITEM_HREF%', '%ITEM_TITLE%', '%ESC_ITEM_TITLE%', '%ITEM_CLASS%', '%IS_FIRST%', '%BEFORE_LINK%', '%AFTER_LINK%', '%DEPTH%', '%ACT_CLASS%', '%RAW_ITEM_HREF%', '%IF_PARENT_NOT_CLICKABLE%', '%DESCRIPTION%', '%SPAN_DESCRIPTION%', '%ICON%', '%ID%'), array($item_href . $attributes, $args->link_before . $dt_title . $args->link_after, !empty($item_title) ? ' title="' . $item_title . '"' : '', esc_attr($class_names), $first_class, $before_link, $after_link, $depth + 1, $act_class, $item_href, $if_parent_not_clickable, esc_html($item->description), $item->description ? '<span class="menu-subtitle">' . esc_html($item->description) . '</span>' : '', $item_icon, $id), $args->dt_item_wrap_start); $this->dt_count++; }
function om_get_post_thumbnail($thumb_size, $single = true) { $html = ''; $full_image = false; $post_id = get_the_ID(); $post_thumbnail_id = get_post_thumbnail_id($post_id); if ($post_thumbnail_id) { $image = wp_get_attachment_image_src($post_thumbnail_id, 'full'); if ($image) { $full_image = $image; list($src, $width, $height) = $image; $image_resized = om_img_resize($src, $thumb_size, false); if ($image_resized) { list($src, $width, $height) = $image_resized; } $hwstring = image_hwstring($width, $height); $attachment = get_post($post_thumbnail_id); $default_attr = array('src' => $src, 'class' => "attachment-" . $thumb_size, 'alt' => trim(strip_tags(get_post_meta($post_thumbnail_id, '_wp_attachment_image_alt', true)))); if (empty($default_attr['alt'])) { $default_attr['alt'] = trim(strip_tags($attachment->post_excerpt)); } // If not, Use the Caption if (empty($default_attr['alt'])) { $default_attr['alt'] = trim(strip_tags($attachment->post_title)); } // Finally, use the title if (get_option(OM_THEME_PREFIX . 'lazyload') == 'true') { $default_attr['data-original'] = $default_attr['src']; $default_attr['src'] = TEMPLATE_DIR_URI . '/img/e.png'; $default_attr['class'] .= ' lazyload'; } $attr = $default_attr; $attr = apply_filters('wp_get_attachment_image_attributes', $attr, $attachment); $attr = array_map('esc_attr', $attr); $html = rtrim("<img {$hwstring}"); foreach ($attr as $name => $value) { $html .= " {$name}=" . '"' . $value . '"'; } $html .= ' />'; } } if ($single) { return $html; } else { return array('html' => $html, 'full_image' => $full_image); } }
function parseTemplate($id, $type, $template, $orig_filename, $icon = "") { DebugEcho("parseTemplate - before: {$template}"); $size = 'medium'; /* we check template for thumb, thumbnail, large, full and use that as size. If not found, we default to medium */ if ($type == 'image') { $sizes = array('thumbnail', 'medium', 'large'); $hwstrings = array(); $widths = array(); $heights = array(); for ($i = 0; $i < count($sizes); $i++) { list($img_src[$i], $widths[$i], $heights[$i]) = image_downsize($id, $sizes[$i]); $hwstrings[$i] = image_hwstring($widths[$i], $heights[$i]); } } $attachment = get_post($id); $the_parent = get_post($attachment->post_parent); $uploadDir = wp_upload_dir(); $fileName = basename($attachment->guid); $absFileName = $uploadDir['path'] . '/' . $fileName; $relFileName = str_replace(ABSPATH, '', $absFileName); $fileLink = wp_get_attachment_url($id); $pageLink = get_attachment_link($id); $template = str_replace('{TITLE}', $attachment->post_title, $template); $template = str_replace('{ID}', $id, $template); if ($type == 'image') { $template = str_replace('{THUMBNAIL}', $img_src[0], $template); $template = str_replace('{THUMB}', $img_src[0], $template); $template = str_replace('{MEDIUM}', $img_src[1], $template); $template = str_replace('{LARGE}', $img_src[2], $template); $template = str_replace('{THUMBWIDTH}', $widths[0] . 'px', $template); $template = str_replace('{THUMBHEIGHT}', $heights[0] . 'px', $template); $template = str_replace('{MEDIUMWIDTH}', $widths[1] . 'px', $template); $template = str_replace('{MEDIUMHEIGHT}', $heights[1] . 'px', $template); $template = str_replace('{LARGEWIDTH}', $widths[2] . 'px', $template); $template = str_replace('{LARGEHEIGHT}', $heights[2] . 'px', $template); } $template = str_replace('{FULL}', $fileLink, $template); $template = str_replace('{FILELINK}', $fileLink, $template); $template = str_replace('{PAGELINK}', $pageLink, $template); $template = str_replace('{FILENAME}', $orig_filename, $template); $template = str_replace('{IMAGE}', $fileLink, $template); $template = str_replace('{URL}', $fileLink, $template); $template = str_replace('{RELFILENAME}', $relFileName, $template); $template = str_replace('{POSTTITLE}', $the_parent->post_title, $template); $template = str_replace('{ICON}', $icon, $template); DebugEcho("parseTemplate - after: {$template}"); return $template . '<br />'; }
/** * render image tag * * @param int $attachment_id post id of the image * @since 1.6.10 */ public function create_image_tag($attachment_id) { $image = wp_get_attachment_image_src($attachment_id, 'full'); if ($image) { list($src, $width, $height) = $image; $hwstring = image_hwstring($width, $height); $attachment = get_post($attachment_id); $alt = trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true))); $title = trim(strip_tags($attachment->post_title)); // Finally, use the title global $wp_current_filter; $more_attributes = ''; // create srcset and sizes attributes if we are in the the_content filter and in WordPress 4.4 if (isset($wp_current_filter) && in_array('the_content', $wp_current_filter) && !defined('ADVADS_DISABLE_RESPONSIVE_IMAGES')) { if (function_exists('wp_get_attachment_image_srcset')) { $more_attributes .= ' srcset=\'' . wp_get_attachment_image_srcset($attachment_id, 'full') . '\''; } if (function_exists('wp_get_attachment_image_sizes')) { $more_attributes .= ' sizes=\'' . wp_get_attachment_image_sizes($attachment_id, 'full') . '\''; } } echo rtrim("<img {$hwstring}") . " src='{$src}' alt='{$alt}' title='{$title}' {$more_attributes}/>"; } }
/** * Get an HTML img element representing an image attachment * * While `$size` will accept an array, it is better to register a size with * add_image_size() so that a cropped version is generated. It's much more * efficient than having to find the closest-sized image and then having the * browser scale down the image. * * @since 2.5.0 * * @param int $attachment_id Image attachment ID. * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width * and height values in pixels (in that order). Default 'thumbnail'. * @param bool $icon Optional. Whether the image should be treated as an icon. Default false. * @param string|array $attr Optional. Attributes for the image markup. Default empty. * @return string HTML img element or empty string on failure. */ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') { $html = ''; $image = wp_get_attachment_image_src($attachment_id, $size, $icon); if ($image) { list($src, $width, $height) = $image; $hwstring = image_hwstring($width, $height); $size_class = $size; if (is_array($size_class)) { $size_class = join('x', $size_class); } $attachment = get_post($attachment_id); $default_attr = array('src' => $src, 'class' => "attachment-{$size_class} size-{$size_class}", 'alt' => trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true)))); if (empty($default_attr['alt'])) { $default_attr['alt'] = trim(strip_tags($attachment->post_excerpt)); } // If not, Use the Caption if (empty($default_attr['alt'])) { $default_attr['alt'] = trim(strip_tags($attachment->post_title)); } // Finally, use the title $attr = wp_parse_args($attr, $default_attr); // Generate 'srcset' and 'sizes' if not already present. if (empty($attr['srcset'])) { $image_meta = get_post_meta($attachment_id, '_wp_attachment_metadata', true); if (is_array($image_meta)) { $size_array = array(absint($width), absint($height)); $srcset = wp_calculate_image_srcset($size_array, $src, $image_meta, $attachment_id); $sizes = wp_calculate_image_sizes($size_array, $src, $image_meta, $attachment_id); if ($srcset && ($sizes || !empty($attr['sizes']))) { $attr['srcset'] = $srcset; if (empty($attr['sizes'])) { $attr['sizes'] = $sizes; } } } } /** * Filter the list of attachment image attributes. * * @since 2.8.0 * * @param array $attr Attributes for the image markup. * @param WP_Post $attachment Image attachment post. * @param string|array $size Requested size. Image size or array of width and height values * (in that order). Default 'thumbnail'. */ $attr = apply_filters('wp_get_attachment_image_attributes', $attr, $attachment, $size); $attr = array_map('esc_attr', $attr); $html = rtrim("<img {$hwstring}"); foreach ($attr as $name => $value) { $html .= " {$name}=" . '"' . $value . '"'; } $html .= ' />'; } return $html; }
/** * Get an HTML img element representing an attachment icon * * @since 1.40 * * @param string Icon Type, e.g., audio, video, spreadsheet * @param array ( width, height ) optional image size, default (64, 64). * * @return string HTML img element or empty string on failure. */ public static function mla_get_icon_type_image($icon_type, $size = NULL) { $icon_file = wp_mime_type_icon($icon_type); if (is_array($size)) { $width = $size[0]; $height = $size[1]; } else { @(list($width, $height) = getimagesize($icon_file)); } $hwstring = image_hwstring($width, $height); $size = $width . 'x' . $height; $default_attr = array('src' => $icon_file, 'class' => "attachment-{$size}", 'alt' => $icon_type . ' ' . __('icon', 'media-library-assistant')); $attr = array_map('esc_attr', $default_attr); $html = rtrim("<img {$hwstring}"); foreach ($attr as $name => $value) { $html .= " {$name}=" . '"' . $value . '"'; } $html .= ' />'; return $html; }
/** * Render the image html output. * * @param array $instance * @param bool $include_link will only render the link if this is set to true. Otherwise link is ignored. * @return string image html */ private function get_image_html($instance, $include_link = true) { // Backwards compatible image display. if ($instance['attachment_id'] == 0 && $instance['image'] > 0) { $instance['attachment_id'] = $instance['image']; } $output = ''; if ($include_link && !empty($instance['link'])) { $attr = array('href' => $instance['link'], 'target' => $instance['linktarget'], 'class' => $this->widget_options['classname'] . '-image-link', 'title' => !empty($instance['alt']) ? $instance['alt'] : $instance['title']); $attr = apply_filters('image_widget_link_attributes', $attr, $instance); $attr = array_map('esc_attr', $attr); $output = '<a'; foreach ($attr as $name => $value) { $output .= sprintf(' %s="%s"', $name, $value); } $output .= '>'; } $size = $this->get_image_size($instance); if (is_array($size)) { $instance['width'] = $size[0]; $instance['height'] = $size[1]; } elseif (!empty($instance['attachment_id'])) { //$instance['width'] = $instance['height'] = 0; $image_details = wp_get_attachment_image_src($instance['attachment_id'], $size); if ($image_details) { $instance['imageurl'] = $image_details[0]; $instance['width'] = $image_details[1]; $instance['height'] = $image_details[2]; } } $instance['width'] = abs($instance['width']); $instance['height'] = abs($instance['height']); $attr = array(); $attr['alt'] = $instance['title']; if (is_array($size)) { $attr['class'] = 'attachment-' . join('x', $size); } else { $attr['class'] = 'attachment-' . $size; } $attr['style'] = ''; if (!empty($instance['width'])) { $attr['style'] .= "max-width: {$instance['width']}px;"; } if (!empty($instance['height'])) { $attr['style'] .= "max-height: {$instance['height']}px;"; } if (!empty($instance['align']) && $instance['align'] != 'none') { $attr['class'] .= " align{$instance['align']}"; } $attr = apply_filters('image_widget_image_attributes', $attr, $instance); // If there is an imageurl, use it to render the image. Eventually we should kill this and simply rely on attachment_ids. if (!empty($instance['imageurl'])) { // If all we have is an image src url we can still render an image. $attr['src'] = $instance['imageurl']; $attr = array_map('esc_attr', $attr); $hwstring = image_hwstring($instance['width'], $instance['height']); $output .= rtrim("<img {$hwstring}"); foreach ($attr as $name => $value) { $output .= sprintf(' %s="%s"', $name, $value); } $output .= ' />'; } elseif (abs($instance['attachment_id']) > 0) { $output .= wp_get_attachment_image($instance['attachment_id'], $size, false, $attr); } if ($include_link && !empty($instance['link'])) { $output .= '</a>'; } return $output; }
/** * Get an HTML img element representing an image attachment * * While $size will accept an array, it is better to register a size with * add_image_size() so that a cropped version is generated. It's much more * efficient than having to find the closest-sized image and then having the * browser scale down the image. * * @see add_image_size() * @uses apply_filters() Calls 'wp_get_attachment_image_attributes' hook on attributes array * @uses wp_get_attachment_image_src() Gets attachment file URL and dimensions * @since 2.5.0 * * @param int $attachment_id Image attachment ID. * @param string $size Optional, default is 'thumbnail'. * @param bool $icon Optional, default is false. Whether it is an icon. * @param mixed $attr Optional, attributes for the image markup. * @return string HTML img element or empty string on failure. */ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') { $html = ''; $image = wp_get_attachment_image_src($attachment_id, $size, $icon); if ( $image ) { list($src, $width, $height) = $image; $hwstring = image_hwstring($width, $height); if ( is_array($size) ) $size = join('x', $size); $attachment = get_post($attachment_id); $default_attr = array( 'src' => $src, 'class' => "attachment-$size", 'alt' => trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use Alt field first ); if ( empty($default_attr['alt']) ) $default_attr['alt'] = trim(strip_tags( $attachment->post_excerpt )); // If not, Use the Caption if ( empty($default_attr['alt']) ) $default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title $attr = wp_parse_args($attr, $default_attr); $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment ); $attr = array_map( 'esc_attr', $attr ); $html = rtrim("<img $hwstring"); foreach ( $attr as $name => $value ) { $html .= " $name=" . '"' . $value . '"'; } $html .= ' />'; } return $html; }
function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false) { $html = ''; $image = wp_get_attachment_image_src($attachment_id, $size, $icon); if ($image) { list($src, $width, $height) = $image; $hwstring = image_hwstring($width, $height); if (is_array($size)) { $size = join('x', $size); } $html = '<img src="' . attribute_escape($src) . '" ' . $hwstring . 'class="attachment-' . attribute_escape($size) . '" alt="" />'; } return $html; }
function presscore_get_image_with_srcset($logo, $r_logo, $default, $custom = '', $class = '') { $logos = array('1x' => $logo, '2x' => $r_logo); $srcset = array(); foreach ($logos as $xx => $_logo) { if (!empty($_logo)) { $srcset[] = "{$_logo[0]} {$xx}"; } } $srcset = implode(', ', $srcset); $output = '<img class="' . esc_attr($class . ' preload-me') . '" srcset="' . esc_attr($srcset) . '" ' . image_hwstring($default[1], $default[2]) . $custom . ' />'; return $output; }
foreach ($images as $i => $image) { switch ($source) { case 'media_library': if ($image > 0) { $img = wpb_getImageBySize(array('attach_id' => $image, 'thumb_size' => $img_size)); $thumbnail = $img['thumbnail']; $large_img_src = $img['p_img_large'][0]; } else { $large_img_src = $default_src; $thumbnail = '<img src="' . $default_src . '" />'; } break; case 'external_link': $image = esc_attr($image); $dimensions = vcExtractDimensions($external_img_size); $hwstring = $dimensions ? image_hwstring($dimensions[0], $dimensions[1]) : ''; $thumbnail = '<img ' . $hwstring . ' src="' . $image . '" />'; $large_img_src = $image; break; } $link_start = $link_end = ''; switch ($onclick) { case 'img_link_large': $link_start = '<a href="' . $large_img_src . '" target="' . $custom_links_target . '">'; $link_end = '</a>'; break; case 'link_image': $link_start = '<a class="prettyphoto" href="' . $large_img_src . '"' . $pretty_rel_random . '>'; $link_end = '</a>'; break; case 'custom_link':
/** * Sets the $hw_string class var that holds the height/width HTML attribute string. * @param int $width * @param int $height * @return void */ public function setHeightWidthString($width, $height) { $this->hw_string = image_hwstring($width, $height); }
/** * Get an HTML img element representing an image attachment * * While `$size` will accept an array, it is better to register a size with * add_image_size() so that a cropped version is generated. It's much more * efficient than having to find the closest-sized image and then having the * browser scale down the image. * * @since 2.5.0 * * @param int $attachment_id Image attachment ID. * @param string|array $size Optional. Registered image size or flat array of height and width * dimensions. Default 'thumbnail'. * @param bool $icon Optional. Whether the image should be treated as an icon. Default false. * @param string|array $attr Optional. Attributes for the image markup. Default empty. * @return string HTML img element or empty string on failure. */ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') { $html = ''; $image = wp_get_attachment_image_src($attachment_id, $size, $icon); if ($image) { list($src, $width, $height) = $image; $hwstring = image_hwstring($width, $height); $size_class = $size; if (is_array($size_class)) { $size_class = join('x', $size_class); } $attachment = get_post($attachment_id); $default_attr = array('src' => $src, 'class' => "attachment-{$size_class}", 'alt' => trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true)))); if (empty($default_attr['alt'])) { $default_attr['alt'] = trim(strip_tags($attachment->post_excerpt)); } // If not, Use the Caption if (empty($default_attr['alt'])) { $default_attr['alt'] = trim(strip_tags($attachment->post_title)); } // Finally, use the title $attr = wp_parse_args($attr, $default_attr); /** * Filter the list of attachment image attributes. * * @since 2.8.0 * * @param array $attr Attributes for the image markup. * @param WP_Post $attachment Image attachment post. * @param string|array $size Requested size. */ $attr = apply_filters('wp_get_attachment_image_attributes', $attr, $attachment, $size); $attr = array_map('esc_attr', $attr); $html = rtrim("<img {$hwstring}"); foreach ($attr as $name => $value) { $html .= " {$name}=" . '"' . $value . '"'; } $html .= ' />'; } return $html; }
function projectTheme_wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') { $html = ''; $image = wp_get_attachment_image_src($attachment_id, $size, $icon); if ($image) { list($src, $width, $height) = $image; $hwstring = image_hwstring($width, $height); if (is_array($size)) { $size = join('x', $size); } $attachment =& get_post($attachment_id); $default_attr = array('src' => $src, 'class' => "attachment-{$size}", 'alt' => trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true))), 'title' => trim(strip_tags($attachment->post_title))); if (empty($default_attr['alt'])) { $default_attr['alt'] = trim(strip_tags($attachment->post_excerpt)); } // If not, Use the Caption if (empty($default_attr['alt'])) { $default_attr['alt'] = trim(strip_tags($attachment->post_title)); } // Finally, use the title $attr = wp_parse_args($attr, $default_attr); $attr = apply_filters('wp_get_attachment_image_attributes', $attr, $attachment); $attr = array_map('esc_attr', $attr); $html = rtrim("<img {$hwstring}"); $html = $attr['src']; } return $html; }
function file_processValue($Value, $Type, $Field, $Config, $EID) { if (!empty($Value)) { //dump($Value); //dump($Type); //dump($Field); //dump($Config); //die; switch ($Type) { case 'image': $Value = strtok($Value, '?'); $imageWidth = $Config['_ImageSizeX'][$Field] == 'auto' ? '100' : $Config['_ImageSizeX'][$Field]; $imageHeight = $Config['_ImageSizeY'][$Field] == 'auto' ? '100' : $Config['_ImageSizeY'][$Field]; $iconWidth = $Config['_IconSizeX'][$Field] == 'auto' ? '100' : $Config['_IconSizeX'][$Field]; $iconHeight = $Config['_IconSizeY'][$Field] == 'auto' ? '100' : $Config['_IconSizeY'][$Field]; $uploadVars = wp_upload_dir(); $SourceFile = str_replace($uploadVars['baseurl'], $uploadVars['basedir'], $Value); if (!file_exists($SourceFile)) { return 'Image does not exists.'; } $dim = getimagesize($SourceFile); $newDim = image_resize_dimensions($dim[0], $dim[1], $iconWidth, $iconHeight, true); if (!empty($newDim)) { $Sourcepath = pathinfo($SourceFile); $URLpath = pathinfo($Value); $iconURL = $URLpath['dirname'] . '/' . $URLpath['filename'] . '-' . $newDim[4] . 'x' . $newDim[5] . '.' . $URLpath['extension']; if (!file_exists($Sourcepath['dirname'] . '/' . $Sourcepath['filename'] . '-' . $newDim[4] . 'x' . $newDim[5] . '.' . $Sourcepath['extension'])) { $image = image_resize($SourceFile, $imageWidth, $imageHeight, true); $icon = image_resize($SourceFile, $iconWidth, $iconHeight, true); } } else { $iconURL = $Value; $iconWidth = $dim[0]; $iconHeight = $dim[1]; } $ClassName = ''; if (!empty($Config['_ImageClassName'][$Field])) { $ClassName = 'class="' . $Config['_ImageClassName'][$Field] . '" '; } if (!empty($Config['_IconURLOnly'][$Field])) { return $iconURL; } return '<img src="' . $iconURL . '" ' . $ClassName . image_hwstring($iconWidth, $iconHeight) . '>'; break; case 'mp3': $File = explode('?', $Value); $UniID = uniqid($EID . '_'); //$ReturnData = '<span id="'.$UniID.'">'.$File[1].'</span>'; $ReturnData = '<audio id="' . $UniID . '" src="' . $File[0] . '">unavailable</audio>'; $_SESSION['dataform']['OutScripts'] .= "\n\t\t\t\t\tAudioPlayer.embed(\"" . $UniID . "\", {\n\t\t\t\t\t"; if (!empty($Config['_PlayerCFG']['Autoplay'][$Field])) { $_SESSION['dataform']['OutScripts'] .= " autostart: 'yes', "; } if (!empty($Config['_PlayerCFG']['Animation'][$Field])) { $_SESSION['dataform']['OutScripts'] .= " animation: 'yes', "; } $_SESSION['dataform']['OutScripts'] .= "\n transparentpagebg: 'yes',\n\t\t\t\t\t\tsoundFile: \"" . $File[0] . "\",\n\t\t\t\t\t\ttitles: \"" . $File[1] . "\"\n\t\t\t\t\t});\n\n\t\t\t\t"; $_SESSION['dataform']['OutScripts'] .= "\n jQuery(document).ready(function(\$) {\n AudioPlayer.setup(\"" . WP_PLUGIN_URL . "/db-toolkit/data_form/fieldtypes/file/player.swf\", {\n width: '100%',\n initialvolume: 100,\n transparentpagebg: \"yes\",\n left: \"000000\",\n lefticon: \"FFFFFF\"\n });\n });"; return $ReturnData; break; case 'file': case 'multi': if (empty($Config['_fileReturnValue'][$Field])) { $Config['_fileReturnValue'][$Field] = 'iconlink'; } $pathInfo = pathinfo($Value); $s3Enabled = false; $prime = $Field; if (!empty($Config['_CloneField'][$Field]['Master'])) { $prime = $Config['_CloneField'][$Field]['Master']; } if (!empty($Config['_enableS3'][$prime]) && !empty($Config['_AWSAccessKey'][$prime]) && !empty($Config['_AWSSecretKey'][$prime])) { include_once DB_TOOLKIT . 'data_form/fieldtypes/file/s3.php'; $s3 = new S3($Config['_AWSAccessKey'][$prime], $Config['_AWSSecretKey'][$prime]); $s3Enabled = true; } switch ($Config['_fileReturnValue'][$Field]) { case 'iconlink': if (empty($Value)) { return 'no file uploaded'; } if (!empty($Config['_enableS3'][$prime]) && !empty($Config['_AWSAccessKey'][$prime]) && !empty($Config['_AWSSecretKey'][$prime])) { $File = 'http://' . $Config['_AWSBucket'][$prime] . '.s3.amazonaws.com/' . $Value; } else { $File = $Value; } $Dets = pathinfo($File); $ext = strtolower($Dets['extension']); if (file_exists(WP_PLUGIN_DIR . '/db-toolkit/data_form/fieldtypes/file/icons/' . $ext . '.gif')) { $Icon = '<img src="' . WP_PLUGIN_URL . '/db-toolkit/data_form/fieldtypes/file/icons/' . $ext . '.gif" align="absmiddle" /> '; } else { $Icon = '<img src="' . WP_PLUGIN_URL . '/db-toolkit/data_form/fieldtypes/file/icons/file.gif" align="absmiddle" /> '; } return '<a href="' . $File . '">' . $Icon . ' ' . basename($File) . '</a>'; break; case 'filesize': if (!empty($s3Enabled)) { $object = $s3->getObjectInfo($Config['_AWSBucket'][$prime], $Value); return file_return_bytes($object['size']); } else { $uploadDir = wp_upload_dir(); $file = str_replace($uploadDir['baseurl'], $uploadDir['basedir'], $Value); return file_return_bytes(filesize($file)); } break; case 'filesizeraw': if (!empty($s3Enabled)) { $object = $s3->getObjectInfo($Config['_AWSBucket'][$prime], $Value); return $object['size']; } else { $uploadDir = wp_upload_dir(); $file = str_replace($uploadDir['baseurl'], $uploadDir['basedir'], $Value); return filesize($file); } break; case 'filename': if (!empty($s3Enabled)) { return basename($Value); } else { return $pathInfo['basename']; } break; case 'filepath': return $Value; break; case 'ext': return $pathInfo['extension']; break; case 'mimetype': $uploadDir = wp_upload_dir(); $file = str_replace($uploadDir['baseurl'], $uploadDir['basedir'], $Value); $type = wp_check_filetype($file); return $type['type']; break; } break; } return; } }
$link_neww = get_post_meta($post->ID, '_dt_slider_newwin', true); $tmp_arr = array(); if (!empty($post->post_excerpt) && !$hide_desc) { $tmp_arr['caption'] = get_the_excerpt(); } if (!empty($post->post_title) && !$hide_desc) { $tmp_arr['title'] = $post->post_title; } $img = wp_get_attachment_image_src($post->ID, 'full'); if ($img) { if ('fullscreen_slider' != $slider_options['slider']) { $tmp_arr['src'] = str_replace(array('src="', '"'), '', dt_get_thumb_img(array('img_meta' => $img, 'thumb_opts' => $slide_hw[$slider_options['slider']]), '%SRC%', false)); $tmp_arr['size_str'] = image_hwstring($slide_hw[$slider_options['slider']]['w'], $slide_hw[$slider_options['slider']]['h']); } else { $tmp_arr['src'] = $img[0]; $tmp_arr['size_str'] = image_hwstring($img[1], $img[2]); } $tmp_arr['alt'] = get_post_meta($post->ID, '_wp_attachment_image_alt', true); } if ($link) { $tmp_arr['link'] = esc_attr($link); } $tmp_arr['in_neww'] = intval($link_neww); $slides_arr[] = $tmp_arr; } wp_reset_postdata(); $autoslide = intval($slider_options['auto_period']); $autoslide_on = $autoslide ? '1' : '0'; $fs_height = intval($slider_options['fs_height']); $fs_bot_spacing = intval($slider_options['fs_bot_spacing']); $fs_overlay = intval($slider_options['fs_overlay']);
$newDim = image_resize_dimensions($dim[0], $dim[1], $iconWidth, $iconHeight, true); $Sourcepath = pathinfo($SourceFile); $URLpath = pathinfo($Value); $iconURL = $URLpath['dirname'] . '/' . $URLpath['filename'] . '-' . $newDim[4] . 'x' . $newDim[5] . '.' . $URLpath['extension']; if (!file_exists($Sourcepath['dirname'] . '/' . $Sourcepath['filename'] . '-' . $newDim[4] . 'x' . $newDim[5] . '.' . $Sourcepath['extension'])) { $image = image_resize($SourceFile, $imageWidth, $imageHeight, true); $icon = image_resize($SourceFile, $iconWidth, $iconHeight, true); } $ClassName = ''; if (!empty($Config['_ImageClassName'][$Field])) { $ClassName = 'class="' . $Config['_ImageClassName'][$Field] . '" '; } if (!empty($Config['_IconURLOnly'][$Field])) { $Return .= $iconURL; } $Return .= '<img src="' . $iconURL . '" ' . $ClassName . image_hwstring($iconWidth, $iconHeight) . '>'; } $Return .= '<input type="file" name="dataForm[' . $Element['ID'] . '][' . $Field . ']" id="entry_' . $Element['ID'] . '_' . $Field . '" style="width:97%;" class="' . $Req . '" />'; } if ($FieldSet[1] == 'file') { $Return = ''; if (!empty($Defaults[$Field])) { $File = $Defaults[$Field]; $ext = strtolower($Dets['extension']); $UniID = uniqid(); $Icon = '<img src="' . WP_PLUGIN_URL . '/db-toolkit/data_form/fieldtypes/file/icons/file.gif" border="0" align="absmiddle" title="' . $File[1] . '" /> '; $Return .= $Icon . ' <a href="' . $File . '" target="_blank" >' . basename($File) . '</a></div>'; $Return .= '<div style="padding:3px;" class="list_row1"><input type="checkbox" name="deleteImage[' . $Field . ']" id="image_' . $Element['ID'] . '_' . $Field . '" value="1" /> Remove File</div>'; } $Return .= '<input type="file" name="dataForm[' . $Element['ID'] . '][' . $Field . ']" id="entry_' . $Element['ID'] . '_' . $Field . '" class="' . $Req . '" />'; $Return .= '<div id="' . $Element['ID'] . $Field . '_uploaded"></div>';
/** * Get an HTML img element representing an image attachment * * @uses apply_filters() Calls 'wp_get_attachment_image_attributes' hook on attributes array * @uses wp_get_attachment_image_src() Gets attachment file URL and dimensions * @since 2.5.0 * * @param int $attachment_id Image attachment ID. * @param string $size Optional, default is 'thumbnail'. * @param bool $icon Optional, default is false. Whether it is an icon. * @return string HTML img element or empty string on failure. */ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false) { $html = ''; $image = wp_get_attachment_image_src($attachment_id, $size, $icon); if ($image) { list($src, $width, $height) = $image; $hwstring = image_hwstring($width, $height); if (is_array($size)) { $size = join('x', $size); } $attachment =& get_post($attachment_id); $attr = array('src' => $src, 'class' => "attachment-{$size}", 'alt' => trim(strip_tags($attachment->post_excerpt)), 'title' => trim(strip_tags($attachment->post_title))); $attr = apply_filters('wp_get_attachment_image_attributes', $attr, $attachment); $attr = array_map('esc_attr', $attr); $html = rtrim("<img {$hwstring}"); foreach ($attr as $name => $value) { $html .= " {$name}=" . '"' . $value . '"'; } $html .= ' />'; } return $html; }
function widget($args, $instance) { $cache = array(); if (!$this->is_preview()) { $cache = wp_cache_get($this->plugin_slug, 'widget'); } if (!is_array($cache)) { $cache = array(); } if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } if (isset($cache[$args['widget_id']])) { echo do_shortcode($cache[$args['widget_id']]); return; } ob_start(); extract($args); $title = !empty($instance['title']) ? $instance['title'] : ''; /** This filter is documented in wp-includes/default-widgets.php */ $title = apply_filters('widget_title', $title, $instance, $this->id_base); $number_posts = !empty($instance['number_posts']) ? absint($instance['number_posts']) : $this->number_posts; $thumb_width = !empty($instance['thumb_width']) ? absint($instance['thumb_width']) : $this->default_thumb_width; $thumb_height = !empty($instance['thumb_height']) ? absint($instance['thumb_height']) : $this->default_thumb_height; $default_url = !empty($instance['default_url']) ? $instance['default_url'] : $this->default_thumb_url; $keep_aspect_ratio = isset($instance['keep_aspect_ratio']) ? $instance['keep_aspect_ratio'] : false; $hide_title = isset($instance['hide_title']) ? $instance['hide_title'] : false; $show_date = isset($instance['show_date']) ? $instance['show_date'] : false; $show_thumb = isset($instance['show_thumb']) ? $instance['show_thumb'] : false; $use_default = isset($instance['use_default']) ? $instance['use_default'] : false; $try_1st_img = isset($instance['try_1st_img']) ? $instance['try_1st_img'] : false; $only_1st_img = isset($instance['only_1st_img']) ? $instance['only_1st_img'] : false; // sanitizes vars if (!$number_posts) { $number_posts = $this->number_posts; } if (!$thumb_width) { $thumb_width = $this->default_thumb_width; } if (!$thumb_height) { $thumb_height = $this->default_thumb_height; } if (!$default_url) { $default_url = $this->default_thumb_url; } $size = array($thumb_width, $thumb_height); /** * Filter the arguments for the Recent Posts widget. * * @since 1.0 * * @see WP_Query::get_posts() * * @param array $args An array of arguments used to retrieve the recent posts. */ $r = new WP_Query(apply_filters('widget_posts_args', array('posts_per_page' => $number_posts, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true))); if ($r->have_posts()) { ?> <?php echo do_shortcode($before_widget); ?> <?php if ($title) { echo do_shortcode($before_title) . do_shortcode($title) . do_shortcode($after_title); } ?> <ul> <?php while ($r->have_posts()) { $r->the_post(); ?> <li> <div class="recent-thumb"> <?php if ($show_thumb) { $is_thumb = false; // if only first image if ($only_1st_img) { // try to find and display the first post's image and return success $is_thumb = $this->the_first_posts_image(get_the_content(), $size); } else { // else // look for featured image if (has_post_thumbnail()) { // if there is featured image then show featured image $image_url = tb_image_resize(get_post_thumbnail_id(get_the_ID()), $thumb_width, $thumb_height); echo '<img alt="' . get_the_title() . '" class="attachment-featuredImageCropped" src="' . esc_attr($image_url) . '">'; $is_thumb = true; } else { // else // if user wishes first image trial if ($try_1st_img) { // try to find and display the first post's image and return success $is_thumb = $this->the_first_posts_image(get_the_content(), $size); } // try_1st_img } // has_post_thumbnail } // only_1st_img // if there is no image if (!$is_thumb) { // if user allows default image then if ($use_default) { // next line inspired by code of wp_get_attachment_image() $hwstring = image_hwstring($thumb_width, $thumb_height); $dimensions = join('x', $size); $default_attr = array('src' => $default_url, 'class' => "attachment-{$dimensions}", 'alt' => ''); $html = rtrim("<img {$hwstring}"); foreach ($default_attr as $name => $value) { $html .= " {$name}=" . '"' . do_shortcode($value) . '"'; } $html .= ' />'; print $html; } // use_default } // not is_thumb // (else do nothing) } // show_thumb // show title if wished ?> <div class="recent-thumb-overlay"></div> </div> <?php if ($show_date) { ?> <div class="tb-post-date"><span><?php echo get_the_date('d F Y'); ?> </span></div> <?php } ?> <?php if (!$hide_title) { ?> <div class="tb-post-title"> <h3> <?php $trimtitle = get_the_title(); $shorttitle = wp_trim_words($trimtitle, $num_words = 6, $more = ''); echo do_shortcode($shorttitle); ?> </h3> </div> <?php } ?> <div class="tb-post-content"> <?php $trimcontent = get_the_content(); $shortcontent = wp_trim_words($trimcontent, $num_words = 25, $more = '...'); echo "<p>" . do_shortcode($shortcontent) . "</p>"; ?> </div> <!-- Btn read mor --> <a href="<?php the_permalink(); ?> " class="btn btn-green btn-readmore-2"><?php _e('Read More', 'leonard'); ?> </a> </li> <?php } ?> </ul> <?php echo do_shortcode($after_widget); // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); } if (!$this->is_preview()) { $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set($this->plugin_slug, $cache, 'widget'); } else { ob_end_flush(); } }
/** * Get image based on devicePixelRatio coocie and theme options. * * @param $logo array Regular logo. * @param $r_logo array Retina logo. * @param $default array Default logo. * @param $custom string Custom img attributes. * * @return string. */ function dt_get_retina_sensible_image ( $logo, $r_logo, $default, $custom = '', $class = '' ) { if ( empty( $default ) ) { return ''; } if ( $logo && !$r_logo ) { $r_logo = $logo; } elseif ( $r_logo && !$logo ) { $logo = $r_logo; } elseif ( !$r_logo && !$logo ) { $logo = $r_logo = $default; } if ( dt_retina_on() ) { $img_meta = dt_is_hd_device() ? $r_logo : $logo; } else { $img_meta = $logo; } if ( ! isset( $img_meta['size'] ) && isset( $img_meta[1], $img_meta[2] ) ) { $img_meta['size'] = image_hwstring( $img_meta[1], $img_meta[2] ); } $output = dt_get_thumb_img( array( 'wrap' => '<img %IMG_CLASS% %SRC% %SIZE% %CUSTOM% />', 'img_class' => $class, 'img_meta' => $img_meta, 'custom' => $custom, 'echo' => false, // TODO: add alt if it's possible 'alt' => '', ) ); return $output; }