/** * Main function that fetches the images associated with the shortcode. * * @param array $attr * @return mixed|string|void */ public function get_gallery_images($attr = array()) { $attr = array_merge(array('style' => 'default', 'show_captions' => false, 'crop' => true, 'display' => 'page', 'max_results' => 1000, 'columns' => 'auto', 'distance' => 1000, 'thumb_size' => 75), $attr); extract($attr); global $photonic_instagram_client_id; if (!isset($photonic_instagram_client_id) || trim($photonic_instagram_client_id) == '') { return __("Instagram Client ID not defined.", 'photonic'); } if (!isset($thumb_size) || isset($thumb_size) && !Photonic::check_integer(ltrim($thumb_size, 'px'))) { $thumb_size = 75; } $auth_required = false; $base_url = 'https://api.instagram.com/v1/'; if (!isset($view) || isset($view) && trim($view) == '') { return __('The <code>view</code> parameter has to be defined.', 'photonic'); } else { if ($view == 'user') { $query_url = $base_url . 'users/'; if (!isset($kind) || isset($kind) && $kind == 'media' && !isset($user_id)) { return __('The <code>user_id</code> parameter has to be defined.', 'photonic'); } else { if ($kind == 'recent' && isset($user_id)) { $query_url .= $user_id . '/media/recent'; $display_what = 'media'; } else { if ($kind == 'follows' && isset($user_id)) { $query_url .= $user_id . '/follows'; $display_what = 'users'; } else { if ($kind == 'followed-by' && isset($user_id)) { $query_url .= $user_id . '/followed-by'; $display_what = 'users'; } else { return __('Invalid <code>kind</code> parameter passed for <code>view=user</code>.', 'photonic'); } } } } $auth_required = true; // recent, relationships } else { if ($view == 'media') { $query_url = $base_url . 'media/'; if (!isset($kind) && !isset($user_id) && !isset($media_id)) { return __('The <code>user_id</code> or <code>media_id</code> parameter has to be defined if the <code>kind</code> parameter is not set', 'photonic'); } else { if (isset($media_id)) { // if media id (shortcode) is specified, we use it irrespective of other parameters $query_url = 'http://api.instagram.com/oembed?url=' . urlencode('http://instagr.am/p/' . $media_id . '/'); $display_what = 'single-media'; } else { if (isset($user_id)) { // if media id is not present, but user id is present we show that user's recent media $query_url = $base_url . 'users/' . $user_id . '/media/recent'; $display_what = 'media'; $auth_required = true; } else { if ($kind == 'popular') { // popular media $query_url .= 'popular'; $display_what = 'media'; } else { if ($kind == 'search') { // search $query_url .= 'search?'; if (!isset($lat) || !isset($lng)) { // Requires latitude and longitude return __('The <code>lat</code> and <code>lng</code> parameters have to be defined for media searches', 'photonic'); } else { $query_url .= 'lat=' . $lat . '&'; $query_url .= 'lng=' . $lng . '&'; $query_url .= 'distance=' . $distance . '&'; // timestamp fields? $display_what = 'media'; } } else { return __('Invalid <code>kind</code> parameter passed for <code>view=media</code>.', 'photonic'); } } } } } } else { if ($view == 'tag') { if (!isset($tag_name)) { return __('The <code>tag_name</code> parameter has to be defined', 'photonic'); } $query_url = $base_url . 'tags/' . $tag_name . '/media/recent'; if (isset($min_id) || isset($max_id)) { $query_url .= '?'; if (isset($min_id)) { $query_url .= 'min_id=' . $min_id . '&'; } if (isset($max_id)) { $query_url .= 'max_id=' . $max_id . '&'; } } $display_what = 'media'; } else { if ($view == 'location') { if (!isset($location_id)) { return __('The <code>location_id</code> parameter has to be defined', 'photonic'); } $query_url = $base_url . 'locations/' . $location_id . '/media/recent'; if (isset($min_id) || isset($max_id) || isset($min_timestamp) || isset($max_timestamp)) { $query_url .= '?'; if (isset($min_id)) { $query_url .= 'min_id=' . $min_id . '&'; } if (isset($max_id)) { $query_url .= 'max_id=' . $max_id . '&'; } if (isset($min_timestamp)) { $query_url .= 'min_timestamp=' . $min_timestamp . '&'; } if (isset($max_timestamp)) { $query_url .= 'max_timestamp=' . $max_timestamp . '&'; } } $display_what = 'media'; } else { return __('Invalid <code>view</code> parameter passed for Instagram.', 'photonic'); } } } } } if (isset($count)) { if (!stripos($query_url, '?')) { $query_url .= '?count=' . $count; } else { if (substr($query_url, -1, 1) != '&' && substr($query_url, -1, 1) != '?') { $query_url .= '&count=' . $count; } else { $query_url .= 'count=' . $count; } } } global $photonic_instagram_allow_oauth; $ret = ''; $post_id = get_the_ID(); if (!empty($photonic_instagram_allow_oauth) && !$this->oauth_done && $auth_required) { $ret .= $this->get_login_box($post_id); } return $ret . $this->make_call($query_url, $display_what, $columns, $thumb_size, $auth_required); }
function generate_level_1_gallery($photos, $title_position, $row_constraints = array(), $columns = 'auto', $display = 'in-page', $sizes = array(), $show_lightbox = true, $type = 'photo', $pagination = array()) { $col_class = ''; if (Photonic::check_integer($columns)) { $col_class = 'photonic-gallery-' . $columns . 'c'; } if ($col_class == '' && $row_constraints['constraint-type'] == 'padding') { $col_class = 'photonic-pad-photos'; } else { if ($col_class == '') { $col_class = 'photonic-gallery-' . $row_constraints['count'] . 'c'; } } $link_attributes = $this->get_lightbox_attributes($display, $col_class, $show_lightbox); $ul_class = "class='title-display-{$title_position}'"; if ($display == 'popup') { $ul_class = "class='slideshow-grid-panel lib-{$this->library} title-display-{$title_position}'"; } $ret = "<ul {$ul_class}>"; global $photonic_external_links_in_new_tab; if (!empty($photonic_external_links_in_new_tab)) { $target = " target='_blank' "; } else { $target = ''; } $counter = 0; global $photonic_gallery_panel_items, $photonic_slideshow_library; foreach ($photos as $photo) { $counter++; $thumb = $photo['thumbnail']; $orig = $photo['main_image']; $url = $photo['main_page']; $title = esc_attr($photo['title']); $alt = esc_attr($photo['alt_title']); $orig = $this->library == 'none' || !$show_lightbox ? $url : $orig; $shown_title = ''; if ($title_position == 'below') { $shown_title = '<span class="photonic-photo-title">' . wp_specialchars_decode($alt, ENT_QUOTES) . '</span>'; } if ($display == 'in-page') { $ret .= "\n\t" . '<li class="photonic-' . $this->provider . '-image photonic-' . $this->provider . '-' . $type . ' ' . $col_class . '">'; } else { if ($counter % $photonic_gallery_panel_items == 1 && $display != 'in-page') { $ret .= "\n\t" . '<li class="photonic-' . $this->provider . '-image photonic-' . $this->provider . '-' . $type . '">'; } } $style = array(); if (!empty($sizes['thumb-width'])) { $style[] = 'width:' . $sizes['thumb-width'] . 'px'; } if (!empty($sizes['thumb-height'])) { $style[] = 'height:' . $sizes['thumb-height'] . 'px'; } if (!empty($style)) { $style = 'style="' . implode(';', $style) . '"'; } else { $style = ''; } $title_link_start = $this->link_lightbox_title && $photonic_slideshow_library != 'thickbox' ? esc_attr("<a href='{$url}' {$target}>") : ''; $title_link_end = $this->link_lightbox_title && $photonic_slideshow_library != 'thickbox' ? esc_attr("</a>") : ''; if ($display == 'in-page') { $ret .= '<a ' . $link_attributes . ' href="' . $orig . '" title="' . $title_link_start . $title . $title_link_end . '" ' . $target . '><img alt="' . $alt . '" src="' . $thumb . '" ' . $style . '/></a>' . $shown_title; } else { $ret .= '<a ' . $link_attributes . ' href="' . $orig . '" title="' . $title_link_start . $title . $title_link_end . '" ' . $target . '><img alt="' . $alt . '" src="' . $thumb . '" ' . $style . '/>' . $shown_title . '</a>'; } /* if (!empty($object['passworded'])) { $prompt_title = esc_attr(__('Enter Password', 'photonic')); $prompt_submit = esc_attr(__('Access', 'photonic')); $form_url = admin_url('admin-ajax.php'); $password_prompt = " <div class='photonic-password-prompter' id='photonic-zenfolio-prompter-{$object['id_1']}-$this->gallery_index' title='$prompt_title'> <form class='photonic-password-form photonic-zenfolio-form' action='$form_url'> <input type='password' name='photonic-zenfolio-password' /> <input type='hidden' name='photonic-zenfolio-realm' value='{$photoset->AccessDescriptor->RealmId}' /> <input type='hidden' name='action' value='photonic_verify_password' /> <input type='submit' name='photonic-zenfolio-submit' value='$prompt_submit' /> </form> </div>"; $ret .= $password_prompt; }*/ if ($display == 'in-page' || $counter % $photonic_gallery_panel_items == 0 && $display != 'in-page') { $ret .= "</li>"; } } if ($ret != "<ul {$ul_class}>") { if (substr($ret, -5) != "</li>") { $ret .= "</li>"; } $ret .= "\n</ul>\n"; if (!empty($pagination) && !empty($pagination['paginate'])) { // Show "Load more" button if (!empty($pagination['current_page']) && !empty($pagination['per_page'])) { if (!empty($pagination['left'])) { // } } } } else { $ret = ''; } if (is_archive()) { global $photonic_archive_thumbs; if (!empty($photonic_archive_thumbs) && $counter < $photonic_archive_thumbs) { $this->is_more_required = false; } } return $ret; }
/** * Builds the markup for a gallery when you choose to use a specific gallery style. The following styles are allowed: * 1. strip-below: Shows thumbnails for the gallery below a larger image * 2. strip-above: Shows thumbnails for the gallery above a larger image * 3. no-strip: Doesn't show thumbnails. Useful if you are making it behave like an automatic slideshow. * 4. launch: Shows a thumbnail for the gallery, which you can click to launch a slideshow. * 5. default: Shows the native WP styling * * @param $images * @param string $style * @param $attr * @return string */ function build_gallery($images, $style = 'strip-below', $attr) { global $photonic_gallery_number, $photonic_slideshow_library, $photonic_wp_thumbnail_title_display; if (!is_array($images)) { return $images; } if (!isset($photonic_gallery_number)) { $photonic_gallery_number = 0; } $attr = array_merge(array('columns' => 3, 'thumb_width' => 75, 'thumb_height' => 75, 'thumb_size' => 'thumbnail', 'slide_size' => 'large', 'slideshow_height' => 500, 'fx' => 'fade', 'timeout' => 4000, 'speed' => 1000, 'pause' => true), $attr); extract($attr); if (!isset($thumb_width) || isset($thumb_width) && !Photonic::check_integer($thumb_width)) { $thumb_width = 75; } if (!isset($thumb_height) || isset($thumb_height) && !Photonic::check_integer($thumb_height)) { $thumb_height = 75; } if (!isset($columns) || isset($columns) && !Photonic::check_integer($columns)) { $columns = 3; } $sources = array(); $thumbs = array(); switch ($style) { case 'strip-below': case 'strip-above': case 'no-strip': $photonic_gallery_number++; $size = $slide_size; $ret = "<div class='photonic-post-gallery {$style} fix'><ul id='gallery-fancy-{$photonic_gallery_number}' class='photonic-post-gallery-content fix' style='height: {$slideshow_height}px;'>"; foreach ($images as $id => $attachment) { // $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false); $sources[$id] = wp_get_attachment_image_src($id, $size, false); $thumbs[$id] = wp_get_attachment_image_src($id, $thumb_size); $ret .= "<li class='photonic-post-gallery-img'>"; if (isset($attachment->post_title)) { $title = wptexturize($attachment->post_title); } else { $title = ''; } $ret .= "<img src='" . $sources[$id][0] . "' alt='{$title}' id='gallery-fancy-{$photonic_gallery_number}-{$id}' />"; $ret .= "</li>"; } $ret .= '</ul></div>'; ob_start(); ?> <script type="text/javascript"> /* <![CDATA[ */ $j = jQuery.noConflict(); $j(document).ready(function() { // Builds a JQuery Cycle gallery based on input parameters $j('ul.photonic-post-gallery-content').each(function() { var parent = $j(this).parent(); <?php $script = ''; if ($style == 'strip-below') { ?> $j("<ul id='" + this.id + "-nav' class='photonic-post-gallery-nav fix'><?php echo $script; ?> </ul>").insertAfter($j(this)); <?php } else { if ($style == 'strip-above') { ?> $j("<ul id='" + this.id + "-nav' class='photonic-post-gallery-nav fix'><?php echo $script; ?> </ul>").insertBefore($j(this)); <?php } } ?> var thisId = this.id; $j(this).cycle({ pause: <?php if (empty($pause)) { echo 0; } else { echo 1; } ?> , fit: 1, width: '100%', <?php if (isset($fx)) { ?> fx: '<?php echo $fx; ?> ', <?php } ?> <?php if (isset($speed)) { ?> speed: '<?php echo $speed; ?> ', <?php } ?> <?php if (isset($timeout)) { ?> timeout: '<?php echo $timeout; ?> ', <?php } ?> <?php if ($style == 'strip-above' || $style == 'strip-below') { ?> pager: '#' + thisId + '-nav', pagerAnchorBuilder: function(idx, slide) { var thumbIds = <?php echo json_encode($thumbs); ?> ; var image = slide.children[0]; var lastDash = image.id.lastIndexOf('-'); var imageId = image.id.substr(lastDash + 1); var thumbDetails = thumbIds[imageId]; return '<li><a href="#" title="' + image.alt + '"><img src="' + thumbDetails[0] + '" width="<?php echo $thumb_width; ?> " height="<?php echo $thumb_height; ?> " alt="' + image.alt + '" /></a></li>'; } <?php } ?> }); }); }); /* ]]> */ </script> <?php $ret .= ob_get_contents(); ob_end_clean(); break; case 'launch': $photonic_gallery_number++; $slideshow_library_class = $photonic_slideshow_library == 'none' ? "" : ($photonic_slideshow_library == 'thickbox' ? " class='thickbox' " : " class='launch-gallery-{$photonic_slideshow_library}' "); $ret = "<div class='photonic-post-gallery {$style} fix'><ul id='gallery-fancy-{$photonic_gallery_number}-nav' class='photonic-post-gallery-nav fix'>"; foreach ($images as $id => $attachment) { $src = wp_get_attachment_image_src($id, 'full'); $thumb = wp_get_attachment_image_src($id, $thumb_size); $ret .= "<li class='photonic-gallery-{$columns}c'>"; if (isset($attachment->post_title)) { $title = wptexturize($attachment->post_title); } else { $title = ''; } if ($photonic_slideshow_library == 'prettyphoto') { $rel = "photonic-prettyPhoto[gallery-fancy-{$photonic_gallery_number}-group]"; } else { $rel = "gallery-fancy-{$photonic_gallery_number}-group"; } $ret .= "<a href=\"" . $src[0] . "\" rel='{$rel}' title='{$title}' {$slideshow_library_class}><img src='" . $thumb[0] . "' alt='{$title}' width='{$thumb_width}' height='{$thumb_height}' /></a>"; $ret .= "</li>"; } $ret .= '</ul></div>'; break; case 'default': default: return ""; } return $ret; }