[44] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | // This file is part of the Carrington Theme Framework for WordPress
|
---|
| 4 | // http://carringtontheme.com
|
---|
| 5 | //
|
---|
| 6 | // Copyright (c) 2008-2009 Crowd Favorite, Ltd. All rights reserved.
|
---|
| 7 | // http://crowdfavorite.com
|
---|
| 8 | //
|
---|
| 9 | // Released under the GPL license
|
---|
| 10 | // http://www.opensource.org/licenses/gpl-license.php
|
---|
| 11 | //
|
---|
| 12 | // **********************************************************************
|
---|
| 13 | // This program is distributed in the hope that it will be useful, but
|
---|
| 14 | // WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 16 | // **********************************************************************
|
---|
| 17 |
|
---|
| 18 | function cfct_get_adjacent_image_link($prev = true) {
|
---|
| 19 | global $post;
|
---|
| 20 | $post = get_post($post);
|
---|
| 21 | $attachments = array_values(get_children( array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') ));
|
---|
| 22 |
|
---|
| 23 | foreach ( $attachments as $k => $attachment )
|
---|
| 24 | if ( $attachment->ID == $post->ID )
|
---|
| 25 | break;
|
---|
| 26 |
|
---|
| 27 | $k = $prev ? $k - 1 : $k + 1;
|
---|
| 28 |
|
---|
| 29 | if ( isset($attachments[$k]) )
|
---|
| 30 | return wp_get_attachment_link($attachments[$k]->ID, 'thumbnail', true);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | function cfct_post_gallery($unused, $attr) {
|
---|
| 34 | global $post;
|
---|
| 35 |
|
---|
| 36 | // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
|
---|
| 37 | if ( isset( $attr['orderby'] ) ) {
|
---|
| 38 | $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
|
---|
| 39 | if ( !$attr['orderby'] )
|
---|
| 40 | unset( $attr['orderby'] );
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | extract(shortcode_atts(array(
|
---|
| 44 | 'order' => 'ASC',
|
---|
| 45 | 'orderby' => 'menu_order ID',
|
---|
| 46 | 'id' => $post->ID,
|
---|
| 47 | 'itemtag' => 'dl',
|
---|
| 48 | 'icontag' => 'dt',
|
---|
| 49 | 'captiontag' => 'dd',
|
---|
| 50 | 'columns' => 3,
|
---|
| 51 | 'size' => 'thumbnail'
|
---|
| 52 | ), $attr));
|
---|
| 53 |
|
---|
| 54 | $id = intval($id);
|
---|
| 55 | $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
|
---|
| 56 |
|
---|
| 57 | if ( empty($attachments) )
|
---|
| 58 | return '';
|
---|
| 59 |
|
---|
| 60 | if ( is_feed() ) {
|
---|
| 61 | $output = "\n";
|
---|
| 62 | foreach ( $attachments as $id => $attachment )
|
---|
| 63 | $output .= wp_get_attachment_link($id, $size, true) . "\n";
|
---|
| 64 | return $output;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | $itemtag = tag_escape($itemtag);
|
---|
| 68 | $captiontag = tag_escape($captiontag);
|
---|
| 69 | $columns = apply_filters('cfct_post_gallery_columns', intval($columns));
|
---|
| 70 | $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
|
---|
| 71 |
|
---|
| 72 | $output = apply_filters('gallery_style', "
|
---|
| 73 | <style type='text/css'>
|
---|
| 74 | .gallery {
|
---|
| 75 | margin: auto;
|
---|
| 76 | }
|
---|
| 77 | .gallery-item {
|
---|
| 78 | float: left;
|
---|
| 79 | margin-top: 10px;
|
---|
| 80 | text-align: center;
|
---|
| 81 | width: {$itemwidth}%; }
|
---|
| 82 | .gallery img {
|
---|
| 83 | border: 2px solid #cfcfcf;
|
---|
| 84 | }
|
---|
| 85 | .gallery-caption {
|
---|
| 86 | margin-left: 0;
|
---|
| 87 | }
|
---|
| 88 | </style>
|
---|
| 89 | <!-- see cfct_post_gallery() in carrington-core/attachment.php -->
|
---|
| 90 | <div class='gallery'>");
|
---|
| 91 |
|
---|
| 92 | $i = 0;
|
---|
| 93 | foreach ( $attachments as $id => $attachment ) {
|
---|
| 94 | // get full item src
|
---|
| 95 | $item_src = wp_get_attachment_image_src($id, 'full', false);
|
---|
| 96 |
|
---|
| 97 | $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
|
---|
| 98 |
|
---|
| 99 | // add full item src as rel
|
---|
| 100 | $link = str_replace('><img', ' class="thickbox" rel="'.$item_src[0].'"><img', $link);
|
---|
| 101 |
|
---|
| 102 | $output .= "<{$itemtag} class='gallery-item'>";
|
---|
| 103 | $output .= "
|
---|
| 104 | <{$icontag} class='gallery-icon'>
|
---|
| 105 | $link
|
---|
| 106 | </{$icontag}>";
|
---|
| 107 | if ( $captiontag && trim($attachment->post_excerpt) ) {
|
---|
| 108 | $output .= "
|
---|
| 109 | <{$captiontag} class='gallery-caption'>
|
---|
| 110 | {$attachment->post_excerpt}
|
---|
| 111 | </{$captiontag}>";
|
---|
| 112 | }
|
---|
| 113 | $output .= "</{$itemtag}>";
|
---|
| 114 | if ( $columns > 0 && ++$i % $columns == 0 )
|
---|
| 115 | $output .= '<br style="clear: both" />';
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | $output .= "
|
---|
| 119 | <br style='clear: both;' />
|
---|
| 120 | </div>\n";
|
---|
| 121 |
|
---|
| 122 | return $output;
|
---|
| 123 | }
|
---|
| 124 | add_filter('post_gallery', 'cfct_post_gallery', 10, 2);
|
---|
| 125 |
|
---|
| 126 | ?> |
---|