Example #1
0
 public static function setup($output, $attr)
 {
     global $post;
     $html5 = current_theme_supports('html5');
     $atts = shortcode_atts(array('order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post ? $post->ID : 0, 'itemtag' => $html5 ? 'figure' : 'dl', 'icontag' => $html5 ? 'div' : 'dt', 'captiontag' => $html5 ? 'figcaption' : 'dd', 'columns' => 3, 'size' => 'thumbnail', 'include' => '', 'exclude' => '', 'link' => ''), $attr, 'gallery');
     $id = intval($atts['id']);
     if (!empty($atts['include'])) {
         $posts = get_posts(array('include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby']));
         $attachments = array();
         foreach ($posts as $key => $val) {
             $attachments[$val->ID] = $posts[$key];
         }
     } elseif (!empty($atts['exclude'])) {
         $attachments = get_children(array('post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby']));
     } else {
         $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby']));
     }
     if (count($attachments)) {
         foreach ($attachments as &$attachment) {
             $attachment = new \TimberImage($attachment);
         }
         // add a static incrementer for the gallery HTML ID to allow more than one per page.
         static $gallery_inc = 0;
         $gallery_inc++;
         $data['id'] = sprintf("gallery-%s", $gallery_inc);
         $data['thumbnails'] = $attachments;
         return \Timber::compile('gallery.twig', $data);
     }
 }
Example #2
0
/**
 * Clean up gallery_shortcode()
 *
 * Re-create the [gallery] shortcode and use thumbnails styling from Bootstrap
 *
 * @link http://twitter.github.com/bootstrap/components.html#thumbnails
 */
function roots_gallery($attr)
{
    $post = get_post();
    static $instance = 0;
    $instance++;
    if (!empty($attr['ids'])) {
        if (empty($attr['orderby'])) {
            $attr['orderby'] = 'post__in';
        }
        $attr['include'] = $attr['ids'];
    }
    $output = apply_filters('post_gallery', '', $attr);
    if ($output != '') {
        return $output;
    }
    if (isset($attr['orderby'])) {
        $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
        if (!$attr['orderby']) {
            unset($attr['orderby']);
        }
    }
    extract(shortcode_atts(array('order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'itemtag' => '', 'icontag' => '', 'captiontag' => '', 'columns' => 3, 'size' => 'thumbnail', 'include' => '', 'exclude' => '', 'link' => 'file'), $attr));
    $id = intval($id);
    if ($order === 'RAND') {
        $orderby = 'none';
    }
    if (!empty($include)) {
        $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
        $attachments = array();
        foreach ($_attachments as $key => $val) {
            $attachments[$val->ID] = $_attachments[$key];
        }
    } elseif (!empty($exclude)) {
        $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
    } else {
        $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
    }
    if (empty($attachments)) {
        return '';
    }
    if (is_feed()) {
        $output = "\n";
        foreach ($attachments as $att_id => $attachment) {
            $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
        }
        return $output;
    }
    $output = '<ul class="thumbnails gallery">';
    $i = 0;
    foreach ($attachments as $id => $attachment) {
        $image = 'file' == $link ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
        $output .= '<li>' . $image;
        if (trim($attachment->post_excerpt)) {
            $output .= '<div class="caption hidden">' . wptexturize($attachment->post_excerpt) . '</div>';
        }
        $output .= '</li>';
    }
    $output .= '</ul>';
    return $output;
}
 function tclm()
 {
     if (!isset($_POST['fid']) or empty($_POST['fid'])) {
         $path = 0;
     } else {
         $fid = $_POST['fid'];
         $a = $this->where('typeid=' . $fid)->field('path,typeid')->find();
         if ($a) {
             $path = $a['path'] . '-' . $a['typeid'];
         } else {
             $path = '0';
         }
     }
     //修改时注意将自身的子孙path也修改下
     if (isset($_POST['typeid']) && intval($_POST['typeid']) > 0) {
         $typeid = intval($_POST['typeid']);
         $substr = get_children($typeid, 0);
         if ($substr != '') {
             $old_path = $this->where('typeid=' . $typeid)->getField('path');
             $new_str = 'replace(`path`,\'' . $old_path . '-' . $typeid . '\',\'' . $path . '-' . $typeid . '\')';
             $sql = "UPDATE `" . C('DB_PREFIX') . "type` SET `path`=" . $new_str . " WHERE typeid in(" . $substr . ")";
             M()->query($sql);
         }
     }
     return $path;
 }
Example #4
0
 /**
  * Determine the correct image to use for the post
  */
 function get_image()
 {
     // Get the arguments
     $args = $this->args;
     $image = array();
     extract($args);
     // First use the "Featured Image" thumbnail if set
     $thumb_id = get_post_thumbnail_id($post_id);
     if (!empty($thumb_id)) {
         $thumb_id = get_post_thumbnail_id($post_id);
         $src = wp_get_attachment_image_src($thumb_id, $size);
         $img = $src[0];
         // Next try scanning the post for attachments
     } else {
         $att_args = array('numberposts' => 1, 'post_type' => 'attachment', 'post_parent' => $post_id, 'post_mime_type' => 'image', 'post_status' => null);
         $attachments = get_children($att_args);
         // If attachments were found, grab the first one which is a valid image
         if ($attachments) {
             foreach ($attachments as $att) {
                 $src = wp_get_attachment_image_src($att->ID, $size);
                 $img = $src[0];
                 if (!empty($img)) {
                     break;
                 }
             }
         }
         // If we still have nothing, grab a default
         if (empty($img)) {
             $img = THEME_URI . '/images/avatars/foundry-thumb.jpg';
         }
     }
     // Return the image
     return $img;
 }
function photoline_modified_post_gallery($output, $attr)
{
    global $post;
    static $instance = 0;
    $instance++;
    //disable all filter
    if (empty($attr['type']) || $attr['type'] != 'slider') {
        return;
    }
    if (isset($attr['orderby'])) {
        $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
        if (!$attr['orderby']) {
            unset($attr['orderby']);
        }
    }
    extract(shortcode_atts(array('order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'size' => 'photoline-featured', 'include' => '', 'exclude' => ''), $attr));
    $id = intval($id);
    if ('RAND' == $order) {
        $orderby = 'none';
    }
    if (!empty($include)) {
        $include = preg_replace('/[^0-9,]+/', '', $include);
        $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
        $attachments = array();
        foreach ($_attachments as $key => $val) {
            $attachments[$val->ID] = $_attachments[$key];
        }
    } elseif (!empty($exclude)) {
        $exclude = preg_replace('/[^0-9,]+/', '', $exclude);
        $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
    } else {
        $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
    }
    if (empty($attachments)) {
        return '';
    }
    if (is_feed()) {
        $output = "\n";
        foreach ($attachments as $att_id => $attachment) {
            $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
        }
        return $output;
    }
    $selector = "gallery-{$instance}";
    $size_class = sanitize_html_class($size);
    $gallery_div = "<div id='{$selector}' class='gallery galleryid-{$id} gallery-size-{$size_class} flexslider'>";
    $output = apply_filters('gallery_style', $gallery_div);
    $output .= '<ul class="slides">';
    $i = 0;
    foreach ($attachments as $id => $attachment) {
        $caption = !empty($attachment->post_excerpt) ? '<p class="flex-caption wp-caption-text gallery-caption">' . wptexturize($attachment->post_excerpt) . '</p>' : '';
        $image = wp_get_attachment_image($id, $size);
        $output .= '<li>';
        $output .= $image;
        $output .= $caption;
        $output .= '</li>';
    }
    $output .= "\r\n            </ul><!-- .slides -->\r\n        </div>\n";
    return $output;
}
Example #6
0
function my_custom_columns($column)
{
    global $post;
    // Bildstorlek
    $width = (int) 200;
    $height = (int) 125;
    if ('ID' == $column) {
        echo $post->ID;
    } elseif ('thumbnail' == $column) {
        // thumbnail of WP 2.9
        $thumbnail_id = get_post_meta($post->ID, '_thumbnail_id', true);
        // image from gallery
        $attachments = get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image'));
        if ($thumbnail_id) {
            $thumb = wp_get_attachment_image($thumbnail_id, array($width, $height), true);
        } elseif ($attachments) {
            foreach ($attachments as $attachment_id => $attachment) {
                $thumb = wp_get_attachment_image($attachment_id, array($width, $height), true);
            }
        }
        if (isset($thumb) && $thumb) {
            echo $thumb;
        } else {
            echo __('None');
        }
    } elseif ('description' == $column) {
        echo $post->post_content;
    }
}
 public function prettyfilelist_shortcode($atts, $content = null)
 {
     //Get attributes from shortcode
     extract(shortcode_atts(array("type" => "excel,pdf,doc,zip,ppt", "filesperpage" => "7"), $atts));
     $html = '';
     //Set paging numbers
     $params = array('pageAt' => $filesperpage);
     wp_localize_script('prettylistjs', 'prettylistScriptParams', $params);
     wp_enqueue_script("jquery");
     wp_enqueue_script('prettylistjs');
     //Get a string of mime types we want
     $mimeTypesToGet = $this->TypeToMime($type);
     //Check to see if we want all types
     //If all types add filters
     //Get all attachments of the right type
     //TODO:Add option for 'orderby' => 'title'
     $args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => get_the_id(), 'post_mime_type' => $mimeTypesToGet);
     $attachments = get_children($args);
     if ($attachments) {
         $html .= '<div class="prettyFileList">';
         foreach ($attachments as $attachment) {
             $html .= $this->srf_get_formatted_link($attachment);
         }
         $html .= '</div>';
     }
     return $html;
 }
 public function shortcode($attr)
 {
     $post = get_post();
     if (!empty($attr['ids'])) {
         // 'ids' is explicitly ordered, unless you specify otherwise.
         if (empty($attr['orderby'])) {
             $attr['orderby'] = 'post__in';
         }
         $attr['include'] = $attr['ids'];
     }
     $atts = shortcode_atts(array('order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post ? $post->ID : 0, 'include' => '', 'exclude' => '', 'size' => array($this->args['width'], $this->args['height'])), $attr, 'gallery');
     $id = intval($atts['id']);
     if (!empty($atts['include'])) {
         $attachments = get_posts(array('include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids'));
     } elseif (!empty($atts['exclude'])) {
         $attachments = get_children(array('post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids'));
     } else {
         $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids'));
     }
     if (empty($attachments)) {
         return '';
     }
     $urls = array();
     foreach ($attachments as $attachment_id) {
         list($url, $width, $height) = wp_get_attachment_image_src($attachment_id, $atts['size'], true);
         if (!$url) {
             continue;
         }
         $urls[] = array('url' => $url, 'width' => $width, 'height' => $height);
     }
     return $this->render(array('images' => $urls));
 }
Example #9
0
 /**
  * Cache images on post's saving
  */
 function check_post_for_images($post_ID, $ablog, $item)
 {
     // Get the post so we can edit it.
     $post = get_post($post_ID);
     $images = $this->get_remote_images_in_content($post->post_content);
     if (!empty($images)) {
         // Include the file and media libraries as they have the functions we want to use
         require_once ABSPATH . 'wp-admin/includes/file.php';
         require_once ABSPATH . 'wp-admin/includes/media.php';
         foreach ($images as $image) {
             preg_match('/[^\\?]+\\.(jpe?g|jpe|gif|png)\\b/i', $image, $matches);
             if (!empty($matches)) {
                 $this->grab_image_from_url($image, $post_ID);
             }
         }
         // Set the first image as the featured one - from a snippet at http://wpengineer.com/2460/set-wordpress-featured-image-automatically/
         $imageargs = array('numberposts' => 1, 'order' => 'ASC', 'post_mime_type' => 'image', 'post_parent' => $post_ID, 'post_status' => NULL, 'post_type' => 'attachment');
         $cachedimages = get_children($imageargs);
         if (!empty($cachedimages)) {
             foreach ($cachedimages as $image_id => $image) {
                 set_post_thumbnail($post_ID, $image_id);
             }
         }
     }
     // Returning the $post_ID even though it's an action and we really don't need to
     return $post_ID;
 }
Example #10
0
 public function showImagesList($post_id)
 {
     $attachments = array();
     if ($post_id) {
         $post = get_post($post_id);
         if ($post && $post->post_type == 'attachment') {
             $attachments = array($post->ID => $post);
         } else {
             $attachments = get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC'));
         }
     } else {
         if (is_array($GLOBALS['wp_the_query']->posts)) {
             foreach ($GLOBALS['wp_the_query']->posts as $attachment) {
                 $attachments[$attachment->ID] = $attachment;
             }
         }
     }
     $output = '';
     foreach ((array) $attachments as $id => $attachment) {
         if ($attachment->post_status == 'trash') {
             continue;
         }
         if ($item = $this->getMediaItem($id, array('used' => in_array((string) $id, $this->selected_ids), 'errors' => isset($this->errors[$id]) ? $this->errors[$id] : null))) {
             $output .= "\n{$item}\n";
         }
     }
     return $output;
 }
Example #11
0
function thumb_or_first($post_id = null, $path = true, $nopic = false, $size = 'large', $details = false)
{
    global $root;
    global $default_img;
    $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $size);
    if (!empty($thumb)) {
        $thumb = $thumb[0];
    } else {
        $imgs = array();
        $images = get_children(array('post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $post_id, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_mime_type' => 'image'));
        if (count($images)) {
            foreach ($images as $image) {
                $attachment = wp_get_attachment_image_src($image->ID, 'large');
                if (file_exists($root . str_replace('http://' . $_SERVER['HTTP_HOST'], '', $attachment[0]))) {
                    $thumb = $attachment[0];
                } else {
                    if ($nopic) {
                        $thumb = 'http://' . $_SERVER['HTTP_HOST'] . $default_img;
                    }
                }
            }
        } else {
            if ($nopic) {
                $thumb = 'http://' . $_SERVER['HTTP_HOST'] . $default_img;
            }
        }
    }
    if ($path) {
        $thumb = str_replace('http://' . $_SERVER['HTTP_HOST'], '', $thumb);
    }
    return $thumb;
}
 protected function lists($typeid, $mode, $limit, $param, $order = 'addtime desc')
 {
     //查询数据库
     $article = D('ArticleView');
     $type = M('type');
     //封装条件
     $map['status'] = 1;
     //准备工作
     //追影 QQ:279197963修改让其支持无限极
     $arr = get_children($typeid);
     //模式判断
     switch ($mode) {
         case 0:
             $map['article.typeid'] = array('in', $arr);
             break;
         case 1:
             $map['article.typeid'] = $typeid;
             break;
         case 2:
             $map['article.typeid'] = array('in', $arr);
             break;
     }
     $alist = $article->where($map)->order($order)->limit($limit)->select();
     $this->assign($param, $alist);
 }
Example #13
0
function eventon_create_duplicate_from_event($post, $parent = 0, $post_status = '')
{
    global $wpdb;
    $new_post_author = wp_get_current_user();
    $new_post_date = current_time('mysql');
    $new_post_date_gmt = get_gmt_from_date($new_post_date);
    if ($parent > 0) {
        $post_parent = $parent;
        $post_status = $post_status ? $post_status : 'publish';
        $suffix = '';
    } else {
        $post_parent = $post->post_parent;
        $post_status = $post_status ? $post_status : 'draft';
        $suffix = ' ' . __('(Copy)', 'eventon');
    }
    // Insert the new template in the post table
    $wpdb->insert($wpdb->posts, array('post_author' => $new_post_author->ID, 'post_date' => $new_post_date, 'post_date_gmt' => $new_post_date_gmt, 'post_content' => $post->post_content, 'post_content_filtered' => $post->post_content_filtered, 'post_title' => $post->post_title . $suffix, 'post_excerpt' => $post->post_excerpt, 'post_status' => $post_status, 'post_type' => $post->post_type, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_password' => $post->post_password, 'to_ping' => $post->to_ping, 'pinged' => $post->pinged, 'post_modified' => $new_post_date, 'post_modified_gmt' => $new_post_date_gmt, 'post_parent' => $post_parent, 'menu_order' => $post->menu_order, 'post_mime_type' => $post->post_mime_type));
    $new_post_id = $wpdb->insert_id;
    // Copy the taxonomies
    eventon_duplicate_post_taxonomies($post->ID, $new_post_id, $post->post_type);
    // Copy the meta information
    eventon_duplicate_post_meta($post->ID, $new_post_id);
    // ONLY for ticket addon event duplication
    if ($post->post_type == 'product') {
        $exclude = apply_filters('woocommerce_duplicate_product_exclude_children', false);
        if (!$exclude && ($children_products = get_children('post_parent=' . $post->ID . '&post_type=product_variation'))) {
            foreach ($children_products as $child) {
                eventon_create_duplicate_from_event(eventon_get_event_to_duplicate($child->ID), $new_post_id, $child->post_status);
            }
        }
    }
    return $new_post_id;
}
Example #14
0
function social_ring_get_first_image()
{
    global $post, $posts;
    if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
        $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'post-thumbnail');
        if ($thumbnail) {
            $image = $thumbnail[0];
        }
        // If that's not there, grab the first attached image
    } else {
        $files = get_children(array('post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image'));
        if ($files) {
            $keys = array_reverse(array_keys($files));
            $image = image_downsize($keys[0], 'thumbnail');
            $image = $image[0];
        }
    }
    //if there's no attached image, try to grab first image in content
    if (empty($image)) {
        ob_start();
        ob_end_clean();
        $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
        if (!empty($matches[1][0])) {
            $image = $matches[1][0];
        }
    }
    return $image;
}
function jQuery_gallery($null, $attr)
{
    global $post;
    $attachments = get_children(array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
    $lis = array();
    foreach ($attachments as $key => $attachment) {
        array_push($lis, '<li>' . wp_get_attachment_link($key, 'thumbnail', false, false) . '</li>');
    }
    $output = '
	<div id="gallery" class="ad-gallery">
		<div class="ad-image-wrapper"></div>
		<div class="ad-controls"></div>
		<div class="ad-nav">
			<div class="ad-thumbs">
				<ul class="ad-thumb-list">
					' . implode('', $lis) . '
				</ul>
			</div>
		</div>
	</div>
	<script type="text/javascript">
	$("div.ad-gallery").adGallery({
		loader_image: "/i/loader.gif",
		slideshow:{enable:false},
		callbacks: {
			init: function() {
				this.preloadAll();
			}
		}
	});
	</script>
	';
    return $output;
}
 public function cleanGallery($output, $attr)
 {
     static $cleaner_gallery_instance = 0;
     $cleaner_gallery_instance++;
     if (is_feed()) {
         return $output;
     }
     /* Default gallery settings. */
     $defaults = array('order' => 'ASC', 'orderby' => 'ID', 'id' => get_the_ID(), 'link' => '', 'itemtag' => 'figure', 'icontag' => '', 'captiontag' => '', 'columns' => 3, 'size' => 'thumbnail', 'ids' => '', 'include' => '', 'exclude' => '', 'numberposts' => -1, 'offset' => '');
     $attr = array_merge($defaults, $attr);
     extract($attr);
     $id = intval($id);
     /* Arguments for get_children(). */
     $children = array('post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'exclude' => $exclude, 'include' => $include, 'numberposts' => $numberposts, 'offset' => $offset, 'suppress_filters' => true);
     if (empty($include)) {
         $attachments = get_children(array_merge(array('post_parent' => $id), $children));
     } else {
         $attachments = get_posts($children);
     }
     $attr['link'] = get_option('yopress_gallery_clean_link');
     if ($attr['link'] == '' || $attr['link'] == null) {
         $attr['link'] = 'big-thumbnail';
         update_option('yopress_gallery_clean_link', 'full');
     }
     $size = get_option('yopress_theme_gallery_def_size');
     if ($size == '' || $size == null) {
         $size = 'thumbnail';
         update_option('yopress_gallery_clean_size', 'thumbnail');
     }
     if (empty($attachments)) {
         return '<!-- No images. -->';
     }
     $itemtag = tag_escape($itemtag);
     $icontag = tag_escape($icontag);
     $captiontag = tag_escape($captiontag);
     $columns = intval($columns);
     $i = 0;
     $galleryWidth = floor(100 / $columns);
     $style = '<style type="text/css">#gallery-' . $cleaner_gallery_instance . ' .gallery-item			{ width : ' . $galleryWidth . '%}</style>';
     $output = $style;
     $output .= '<div id="gallery-' . $cleaner_gallery_instance . '" class="gallery gallery-columns-' . $columns . ' gallery-size-thumbnail">';
     $itemInColum = 0;
     foreach ($attachments as $attachment) {
         $output .= '<dl class="gallery-item"><dt class="gallery-icon">';
         $image = isset($attr['link']) && 'full' == $attr['link'] ? wp_get_attachment_link($attachment->ID, $size, false, false) : wp_get_attachment_link($attachment->ID, $size, true, false);
         $lightbox = $attr['link'] == 'full' ? 'class="apply-lightbox"' : '';
         $output .= "<div " . $lightbox . ">";
         $output .= apply_filters('cleaner_gallery_image', $image, $attachment->ID, $attr, $cleaner_gallery_instance);
         $output .= '</div>';
         $output .= '</dt></dl>';
         $itemInColum++;
         if ($itemInColum == $columns) {
             $itemInColum = 0;
             $output .= '<br class="clearfix">';
         }
     }
     $output .= '<br class="clearfix">';
     $output .= "</div><!-- .gallery -->";
     return $output;
 }
Example #17
0
function attachment_toolbox($size = thumbnail, $type = 'house', $gallcount = '0', $ulClass = '', $emptyMsg = '')
{
    $images = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order'));
    $count = 0;
    $out = '<ul class="' . $ulClass . '">';
    foreach ($images as $image) {
        $attimg = wp_get_attachment_image_src($image->ID, $size);
        $attimgurl = $attimg[0];
        $atturl = wp_get_attachment_url($image->ID);
        $attlink = get_attachment_link($image->ID);
        $postlink = get_permalink($image->post_parent);
        $atttitle = apply_filters('the_title', $image->post_title);
        $attcontent = $image->post_content;
        $attimgtype = get_post_meta($image->ID, "_mySelectBox", true);
        $imglink = $image->guid;
        if ($attimgtype == $type) {
            $count++;
            $out .= '<li><a href=' . $imglink . ' rel="prettyPhoto[gallery' . $gallcount . ']"><img class="primary" src="' . $attimgurl . '"/></a></li>';
        }
    }
    $out .= '</ul>';
    if ($count > 0) {
        echo $out;
    } else {
        echo $emptyMsg;
    }
    return $count;
}
Example #18
0
 function create_duplicate($project_id)
 {
     //Get all data post type project, message, task_list, milestone
     $prev_pro_data = $this->fatch_projcet_data($project_id);
     $new_pro_arg = $this->fill_array($prev_pro_data[$project_id]);
     //create duplicate new project
     $new_pro_id = $this->insert_duplicate($new_pro_arg, $project_id);
     if (!$new_pro_id) {
         wp_send_json_error('Unknown Error', 'cpm');
     }
     //remove project post type from data array
     unset($prev_pro_data[$project_id]);
     foreach ($prev_pro_data as $prev_post_id => $post_obj) {
         if ($post_obj->post_type == 'milestone') {
             $args = $this->fill_array($post_obj, $new_pro_id);
             //Insert message, task list and milestone
             $new_milestone_id[$post_obj->ID] = $this->insert_duplicate($args, $post_obj->ID);
             unset($prev_pro_data[$prev_post_id]);
         }
     }
     foreach ($prev_pro_data as $prev_post_id => $post_obj) {
         $args = $this->fill_array($post_obj, $new_pro_id);
         $new_milestone_id = isset($new_milestone_id) ? $new_milestone_id : array();
         //Insert message, task list and milestone
         $id = $this->insert_duplicate($args, $post_obj->ID, $new_milestone_id);
         //If post type task list then fatch task and insert duplicate
         if ($post_obj->post_type == 'task_list') {
             $task = array('post_parent' => $post_obj->ID, 'post_type' => 'task', 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'ID');
             $task_data = get_children($task);
             $this->insert_duplicate_task($task_data, $id);
         }
     }
     return $new_pro_id;
 }
Example #19
0
/**
* 获得cat_id精品列表。
*
* @access  private
* @param   integer
* @return  array
*/
function index_get_cat_id_goods_best_list($cat_id, $num)
{
    $sql = 'Select g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price, g.promote_price, ' . "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, " . "g.is_best, g.is_new, g.is_hot, g.is_promote " . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . "Where g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.is_best = 1 AND (" . $cat_id . " OR " . get_extension_goods($cat_id) . ")";
    $cats = get_children($cat_id);
    $where = !empty($cats) ? "AND ({$cats} OR " . get_extension_goods($cats) . ") " : '';
    $sql .= $where . " LIMIT {$num}";
    $res = $GLOBALS['db']->getAll($sql);
    $goods = array();
    foreach ($res as $idx => $row) {
        $goods[$idx]['id'] = $row['article_id'];
        $goods[$idx]['id'] = $row['goods_id'];
        $goods[$idx]['name'] = $row['goods_name'];
        $goods[$idx]['brief'] = $row['goods_brief'];
        $goods[$idx]['brand_name'] = $row['brand_name'];
        $goods[$idx]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']);
        $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
        $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']);
        $goods[$idx]['market_price'] = price_format($row['market_price']);
        $goods[$idx]['shop_price'] = price_format($row['shop_price']);
        $goods[$idx]['thumb'] = empty($row['goods_thumb']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_thumb'];
        $goods[$idx]['goods_img'] = empty($row['goods_img']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_img'];
        $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
    }
    return $goods;
}
/**
 * Show featured gallery for gallery post format
 */
function azeria_post_gallery()
{
    $post_id = get_the_ID();
    // first - try to get images from galleries in post
    $post_gallery = get_post_gallery($post_id, false);
    if (!empty($post_gallery['ids'])) {
        $post_gallery = explode(',', $post_gallery['ids']);
    } elseif (!empty($post_gallery['src'])) {
        $post_gallery = $post_gallery['src'];
    } else {
        $post_gallery = false;
    }
    // if can't try to catch images inserted into post
    if (!$post_gallery) {
        $post_gallery = azeria_post_images($post_id, 15);
    }
    // and if not find any images - try to get images attached to post
    if (!$post_gallery || empty($post_gallery)) {
        $attachments = get_children(array('post_parent' => $post_id, 'posts_per_page' => 3, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image'));
        if ($attachments && is_array($attachments)) {
            $post_gallery = array_keys($attachments);
        }
    }
    if (!$post_gallery || empty($post_gallery)) {
        return false;
    }
    $output = azeria_get_gallery_html($post_gallery);
    echo $output;
}
Example #21
0
File: brand.php Project: qgz/ecshop
function brand_get_goodsex($brand_id, $cate, $size, $page, $sort, $order)
{
    $cate_where = $cate > 0 ? 'AND ' . get_children($cate) : '';
    /* 获得商品列表 */
    $sql = 'SELECT g.goods_id, g.goods_name, g.goods_sn, g.market_price, g.shop_price AS org_price, g.is_new,' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, g.promote_price, " . '(select AVG(r.comment_rank) from ' . $GLOBALS['ecs']->table('comment') . ' as r where r.id_value = g.goods_id AND r.comment_type = 0 AND r.parent_id = 0 AND r.status = 1) AS comment_rank, ' . '(select IFNULL(sum(og.goods_number), 0) from ' . $GLOBALS['ecs']->table('order_goods') . ' as og where og.goods_id = g.goods_id) AS sell_number, ' . 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . "WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.brand_id = '{$brand_id}' {$cate_where}" . "ORDER BY {$sort} {$order}";
    $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);
    $arr = array();
    while ($row = $GLOBALS['db']->fetchRow($res)) {
        if ($row['promote_price'] > 0) {
            $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
        } else {
            $promote_price = 0;
        }
        $arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
        if ($GLOBALS['display'] == 'grid') {
            $arr[$row['goods_id']]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
        }
        $arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
        $arr[$row['goods_id']]['goods_sn'] = $row['goods_sn'];
        $arr[$row['goods_id']]['comment_rank'] = $row['comment_rank'];
        $arr[$row['goods_id']]['sell_number'] = $row['sell_number'];
        $arr[$row['goods_id']]['is_new'] = $row['is_new'];
        $arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
        $arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
        $arr[$row['goods_id']]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
        $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief'];
        $arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
        $arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
        $arr[$row['goods_id']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
    }
    return $arr;
}
Example #22
0
function img3($width, $height)
{
    global $post;
    $custom_field_value_2 = get_post_meta($post->ID, 'Image', true);
    $attachments = get_children(array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => 1));
    if (has_post_thumbnail()) {
        $domsxe = simplexml_load_string(get_the_post_thumbnail($post->ID, 'full'));
        $thumbnailsrc = $domsxe->attributes()->src;
        $img_url = parse_url($thumbnailsrc, PHP_URL_PATH);
        $img = get_bloginfo('template_url') . "/thumb.php?src={$img_url}&amp;w={$width}&amp;h={$height}&amp;q=100";
    } elseif ($custom_field_value_2 == true) {
        $img = $custom_field_value_2;
    } elseif ($attachments == true) {
        foreach ($attachments as $id => $attachment) {
            $img = wp_get_attachment_image_src($id, 'full');
            $image = $image[0];
            $img_url = parse_url($img[0], PHP_URL_PATH);
            $img = get_bloginfo('template_url') . "/thumb.php?src={$img_url}&amp;w={$width}&amp;h={$height}&amp;q=70";
        }
    } else {
        global $post, $posts;
        $first_img = '';
        ob_start();
        ob_end_clean();
        $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
        $first_img = $matches[1][0];
        if ($first_img) {
            $img = "{$first_img}";
        } else {
            $img = "http://thugianviet.net/wp-content/themes/thugianviet_net/images/logo.png";
        }
    }
    return $img;
}
Example #23
0
 /**
  * Return list of attachments
  * 
  * <code>
  * [attachments]
  * [attachments type=image]
  * [attachments type=video preview=1]
  * </code>
  */
 function attachments($attributes)
 {
     global $post;
     $mimetypes = array('image', 'video', 'audio', 'application');
     if (isset($attributes['type']) && in_array($attributes['type'], $mimetypes)) {
         $mimetype = $attributes['type'];
     } else {
         $mimetype = null;
     }
     $args = array('post_type' => 'attachment', 'numberposts' => null, 'post_status' => null, 'post_parent' => $post->ID, 'post_mime_type' => $mimetype);
     $attachments = get_children($args);
     if (!is_array($attachments) or !sizeof($attachments)) {
         return '';
     }
     if (isset($attributes['preview'])) {
         $output = '<ul class="attachment-list preview ' . $mimetype . '">';
         foreach ($attachments as $attachment) {
             $output .= '<li>' . get_the_attachment_link($attachment->ID, false) . '</li>';
         }
         $output .= '</ul>';
     } else {
         $output = '<ul class="attachment-list ' . $mimetype . '">';
         foreach ($attachments as $attachment) {
             $output .= '<li><a title="' . $attachment->post_title . '" href="' . wp_get_attachment_url($attachment->ID) . '">' . apply_filters('the_title', $attachment->post_title) . '</a></li>';
         }
         $output .= '</ul>';
     }
     return $output;
 }
/**
* Retrieves the attachment data such as Title, Caption, Alt Text, Description
* @param int $post_id the ID of the Post, Page, or Custom Post Type
* @param String $size The desired image size, e.g. thumbnail, medium, large, full, or a custom size
* @return stdClass If there is only one result, this method returns a generic
* stdClass object representing each of the image's properties, and an array if otherwise.
*/
function getImageAttachmentData($post_id, $size = 'thumbnail', $count = 1)
{
    $objMeta = array();
    $meta;
    // (stdClass)
    $args = array('numberposts' => $count, 'post_parent' => $post_id, 'post_type' => 'attachment', 'nopaging' => false, 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'post_status' => 'any');
    $attachments =& get_children($args);
    if ($attachments) {
        foreach ($attachments as $attachment) {
            $meta = new stdClass();
            $meta->ID = $attachment->ID;
            $meta->title = $attachment->post_title;
            $meta->caption = $attachment->post_excerpt;
            $meta->description = $attachment->post_content;
            $meta->alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
            // Image properties
            $props = wp_get_attachment_image_src($attachment->ID, $size, false);
            $meta->properties['url'] = $props[0];
            $meta->properties['width'] = $props[1];
            $meta->properties['height'] = $props[2];
            $objMeta[] = $meta;
        }
        return count($attachments) == 1 ? $meta : $objMeta;
    }
}
Example #25
0
/**
 * 取得访问和购买次数统计数据
 *
 * @param   int             $cat_id          分类编号
 * @param   int             $brand_id        品牌编号
 * @param   int             $show_num        显示个数
 * @return  array           $click_sold_info  访问购买比例数据
 */
function click_sold_info($cat_id, $brand_id, $show_num)
{
    global $db, $ecs;
    $where = " WHERE o.order_id = og.order_id AND g.goods_id = og.goods_id " . order_query_sql('finished', 'o.');
    $limit = " LIMIT " . $show_num;
    if ($cat_id > 0) {
        $where .= " AND " . get_children($cat_id);
    }
    if ($brand_id > 0) {
        $where .= " AND g.brand_id = '{$brand_id}' ";
    }
    $click_sold_info = array();
    $sql = "SELECT og.goods_id, g.goods_sn, g.goods_name, g.click_count,  COUNT(og.goods_id) AS sold_times " . " FROM " . $ecs->table('goods') . " AS g, " . $ecs->table('order_goods') . " AS og, " . $ecs->table('order_info') . " AS o " . $where . " GROUP BY og.goods_id ORDER BY g.click_count DESC " . $limit;
    $res = $db->query($sql);
    while ($item = $db->fetchRow($res)) {
        if ($item['click_count'] <= 0) {
            $item['scale'] = 0;
        } else {
            /* 每一百个点击的订单比率 */
            $item['scale'] = sprintf("%0.2f", $item['sold_times'] / $item['click_count'] * 100) . '%';
        }
        $click_sold_info[] = $item;
    }
    return $click_sold_info;
}
Example #26
0
function the_shortcode_excerpt()
{
    # Determine if the post_content column contains the string [gallery]
    if (gallery_shortcode_exists()) {
        # Get the first three attachments using the posts_per_page parameter
        $args = array('post_type' => 'attachment', 'post_mime_type' => 'image', 'posts_per_page' => 3, 'post_parent' => get_the_ID());
        $attachments = get_children($args);
        # If any attachments are returned, proceed
        if ($attachments) {
            # Spin cycle to collate attachment IDs
            foreach ($attachments as $attachment) {
                $includes[] = $attachment->ID;
            }
            # Format our IDs in a comma-delimited string
            $includes = implode(',', $includes);
            # Inject your include argument
            $shortcode = str_replace('[gallery', "[gallery include='{$includes}' ", get_the_content());
            # Render the Gallery using the standard editorial input syntax
            echo do_shortcode($shortcode);
            # Add a View More link
            echo '<a href="' . get_permalink() . '">' . __('View more', 'domain') . '</a>';
        } else {
            _e('Foo Bar - No attachments found and no excerpt to display', 'domain');
        }
    } else {
        # Whatever fallback you desire
        the_excerpt();
    }
}
Example #27
0
/**
 * OVERRIDES: gallery_shortcode()
 *
 * This implements the functionality of the Gallery Shortcode for displaying
 * WordPress images on a post.
 */
function vanilla_gallery($attr)
{
    global $post, $tpl;
    // BUG: I'm doing something wrong, because $attr is not the array of attributes from gallery_shortcode function. Why not??
    // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
    if (isset($attr['orderby'])) {
        $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
        if (!$attr['orderby']) {
            unset($attr['orderby']);
        }
    }
    extract(shortcode_atts(array('order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 3, 'size' => 'thumbnail'), $attr));
    $id = intval($id);
    $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
    if (empty($attachments)) {
        return '';
    }
    if (is_feed()) {
        $output = "\n";
        foreach ($attachments as $id => $attachment) {
            $output .= wp_get_attachment_link($id, $size, true) . "\n";
        }
        return $output;
    }
    $images = array();
    foreach ($attachments as $id => $attachment) {
        $images[] = array("link" => wp_get_attachment_link($id, $size, true), "caption" => $captiontag && trim($attachment->post_excerpt) ? $attachment->post_excerpt : 0);
    }
    // Prepare the template data
    $tpl["gallery"] = array("tpl_file" => "shortcodes/gallery.html", "itemtag" => tag_escape($itemtag), "icontag" => tag_escape($icontag), "captiontag" => tag_escape($captiontag), "columns" => intval($columns), "itemwidth" => $columns > 0 ? floor(100 / $columns) - 1 : 100, "images" => $images);
    // Execute the template
    return vanilla_shortcode("gallery");
}
function ewf_projects_sc_slider($atts, $content)
{
    global $paged, $post;
    $src = null;
    extract(shortcode_atts(array("featuredimage" => "true"), $atts));
    $image_id = get_post_thumbnail_id();
    $arrImages = get_children('post_type=attachment&post_mime_type=image&post_parent=' . $post->ID . '&orderby=menu_order&order=ASC');
    if (count($arrImages) > 0) {
        $src .= '<div id="portfolio-item-slider">';
        if ($arrImages) {
            $src .= '<div class="flexslider"><ul class="slides">';
            foreach ($arrImages as $oImage) {
                if ($featuredimage == 'false') {
                    if ($oImage->ID != $image_id) {
                        $cr_image_large_preview = wp_get_attachment_image_src($oImage->ID, 'project-preview-large');
                        $src .= '<li><img alt="" src="' . $cr_image_large_preview[0] . '" style="opacity: 1;"></li>';
                    }
                } else {
                    $cr_image_large_preview = wp_get_attachment_image_src($oImage->ID, 'project-preview-large');
                    $src .= '<li><img alt="" src="' . $cr_image_large_preview[0] . '" style="opacity: 1;"></li>';
                }
            }
            $src .= '</ul></div>';
        }
        $src .= '</div> <div class="hr"></div>';
    } else {
        $src .= ewf_message(__('Please add a featured image and/or other images in the page gallery to show the slider!', EWF_SETUP_THEME_DOMAIN));
    }
    return $src;
}
function display_images_from_media_library($type, $mediaID = NULL)
{
    if ($type == 'bg') {
        $thumb_type = 'st-bg-thumb';
    } else {
        $thumb_type = 'st-thumb';
    }
    if ($mediaID == NULL || $mediaID == 0) {
        $image_return = '<img style="opacity: 1; filter: alpha(opacity=100);" width="80" height="80" class="thumb ' . $thumb_type . '" src="' . plugins_url('images/no-image.png', __FILE__) . '" alt="" data-pid="" />';
    } else {
        $image_return = '<img style="opacity: 0.2; filter: alpha(opacity=2);" width="80" height="80" class="thumb ' . $thumb_type . '" src="' . plugins_url('images/no-image.png', __FILE__) . '" alt="" data-pid="" />';
    }
    $images = get_children(array('post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order'));
    if ($images) {
        foreach ($images as $id => $image) {
            $opacity_out = 'style="opacity: 0.2; filter: alpha(opacity=2);"';
            if ($mediaID !== NULL) {
                if ($image->ID == $mediaID) {
                    $opacity_out = 'style="opacity: 1; filter: alpha(opacity=100);"';
                }
            }
            $img = wp_get_attachment_thumb_url($image->ID);
            $image_return .= '<img ' . @$opacity_out . 'width="80" height="80" class="thumb ' . $thumb_type . '" src="' . $img . '" alt="" data-pid="' . $image->ID . '" />';
        }
    }
    return $image_return;
}
function jquery_slides()
{
    global $post;
    $qry = new WP_Query('post_type=slide&showposts=-1');
    if ($qry->have_posts()) {
        $classPrefix = get_option('slides_class_prefix');
        $html = '<div class="' . $classPrefix . 'slides"><div class="' . $classPrefix . 'slides-container" style="width: ' . get_option('slides_width') . 'px; height: ' . get_option('slides_height') . 'px">';
        while ($qry->have_posts()) {
            $qry->the_post();
            $html .= '<div class="' . $classPrefix . 'slides-item">';
            $html .= '<div class="' . $classPrefix . 'caption">' . get_the_content($post->ID) . '</div>';
            $thumbnail_id = get_post_thumbnail_id($post->ID);
            if ($thumbnail_id) {
                $html .= wp_get_attachment_image($thumbnail_id, 'full');
            } else {
                $images = get_children(array('post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999));
                if ($images) {
                    $image = array_shift($images);
                    $html .= wp_get_attachment_image($image->ID, 'full');
                }
            }
            $html .= '</div>';
        }
        $html .= '</div></div>';
    }
    wp_reset_postdata();
    return $html;
}