From 9f751d3f86f8fc89a7476ea88081143f071ada55 Mon Sep 17 00:00:00 2001 From: Ronak Gandhi Date: Tue, 13 May 2014 16:30:49 -0700 Subject: [PATCH 1/3] Handle deleted, unconfigured galleries - Check if the gallery is absent, return an error message - Make afg_error() function in afg_libs.php take an error_msg argument isntead of showing error from pf object --- afg_libs.php | 5 ++--- index.php | 28 ++++++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/afg_libs.php b/afg_libs.php index 974ef96..2343dd6 100644 --- a/afg_libs.php +++ b/afg_libs.php @@ -164,9 +164,8 @@ function create_afgFlickr_obj() { $pf->setToken(get_option('afg_flickr_token')); } -function afg_error() { - global $pf; - return "

Awesome Flickr Gallery Error - $pf->error_msg

"; +function afg_error($error_msg) { + return "

Awesome Flickr Gallery Error - $error_msg

"; } function date_taken_cmp_newest($a, $b) { diff --git a/index.php b/index.php index e8cd729..936a573 100644 --- a/index.php +++ b/index.php @@ -159,6 +159,10 @@ function afg_display_gallery($atts) { else $url_separator = '&'; $galleries = get_option('afg_galleries'); + if (!isset($galleries) || array_key_exists($id, $galleries) == false) { + return afg_error("Gallery ID {$id} has been either deleted or not configured."); + } + $gallery = $galleries[$id]; $api_key = get_option('afg_api_key'); @@ -234,33 +238,33 @@ function afg_display_gallery($atts) { if (isset($photoset_id) && $photoset_id) { $rsp_obj = $pf->photosets_getInfo($photoset_id); - if ($pf->error_code) return afg_error(); + if ($pf->error_code) return afg_error($pf->error_msg); $total_photos = $rsp_obj['photos']; } else if (isset($gallery_id) && $gallery_id) { $rsp_obj = $pf->galleries_getInfo($gallery_id); - if ($pf->error_code) return afg_error(); + if ($pf->error_code) return afg_error($pf->error_msg); $total_photos = $rsp_obj['gallery']['count_photos']['_content']; } else if (isset($group_id) && $group_id) { $rsp_obj = $pf->groups_pools_getPhotos($group_id, NULL, NULL, NULL, NULL, 1, 1); - if ($pf->error_code) return afg_error(); + if ($pf->error_code) return afg_error($pf->error_msg); $total_photos = $rsp_obj['photos']['total']; if ($total_photos > 500) $total_photos = 500; } else if (isset($tags) && $tags) { $rsp_obj = $pf->photos_search(array('user_id'=>$user_id, 'tags'=>$tags, 'extras'=>$extras, 'per_page'=>1)); - if ($pf->error_code) return afg_error(); + if ($pf->error_code) return afg_error($pf->error_msg); $total_photos = $rsp_obj['photos']['total']; } else if (isset($popular) && $popular) { $rsp_obj = $pf->photos_search(array('user_id'=>$user_id, 'sort'=>'interestingness-desc', 'extras'=>$extras, 'per_page'=>1)); - if ($pf->error_code) return afg_error(); + if ($pf->error_code) return afg_error($pf->error_msg); $total_photos = $rsp_obj['photos']['total']; } else { $rsp_obj = $pf->people_getInfo($user_id); - if ($pf->error_code) return afg_error(); + if ($pf->error_code) return afg_error($pf->error_msg); $total_photos = $rsp_obj['photos']['count']['_content']; } @@ -274,33 +278,33 @@ function afg_display_gallery($atts) { if ($photoset_id) { $flickr_api = 'photoset'; $rsp_obj_total = $pf->photosets_getPhotos($photoset_id, $extras, NULL, 500, $i); - if ($pf->error_code) return afg_error(); + if ($pf->error_code) return afg_error($pf->error_msg); } else if ($gallery_id) { $flickr_api = 'photos'; $rsp_obj_total = $pf->galleries_getPhotos($gallery_id, $extras, 500, $i); - if ($pf->error_code) return afg_error(); + if ($pf->error_code) return afg_error($pf->error_msg); } else if ($group_id) { $flickr_api = 'photos'; $rsp_obj_total = $pf->groups_pools_getPhotos($group_id, NULL, NULL, NULL, $extras, 500, $i); - if ($pf->error_code) return afg_error(); + if ($pf->error_code) return afg_error($pf->error_msg); } else if ($tags) { $flickr_api = 'photos'; $rsp_obj_total = $pf->photos_search(array('user_id'=>$user_id, 'tags'=>$tags, 'extras'=>$extras, 'per_page'=>500, 'page'=>$i)); - if ($pf->error_code) return afg_error(); + if ($pf->error_code) return afg_error($pf->error_msg); } else if ($popular) { $flickr_api = 'photos'; $rsp_obj_total = $pf->photos_search(array('user_id'=>$user_id, 'sort'=>'interestingness-desc', 'extras'=>$extras, 'per_page'=>500, 'page'=>$i)); - if ($pf->error_code) return afg_error(); + if ($pf->error_code) return afg_error($pf->error_msg); } else { $flickr_api = 'photos'; if (get_option('afg_flickr_token')) $rsp_obj_total = $pf->people_getPhotos($user_id, array('extras' => $extras, 'per_page' => 500, 'page' => $i)); else $rsp_obj_total = $pf->people_getPublicPhotos($user_id, NULL, $extras, 500, $i); - if ($pf->error_code) return afg_error(); + if ($pf->error_code) return afg_error($pf->error_msg); } $photos = array_merge($photos, $rsp_obj_total[$flickr_api]['photo']); } From 8f5004e0af25173a548cd31f640bbd250911358f Mon Sep 17 00:00:00 2001 From: Ronak Gandhi Date: Wed, 14 May 2014 13:42:42 -0700 Subject: [PATCH 2/3] Support for providing update packages directly from Github --- afg_libs.php | 2 +- afg_update.php | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/afg_libs.php b/afg_libs.php index 2343dd6..297967b 100644 --- a/afg_libs.php +++ b/afg_libs.php @@ -1,5 +1,5 @@ when updating from GitHub zip files + * + * See: https://github.com/YahnisElsts/plugin-update-checker/issues/1 + * + * @param string $source + * @param string $remote_source + * @param object $thiz + * @return string + */ +function afg_rename_update_zip( $source, $remote_source, $thiz ) +{ + if( strpos( $source, PLUGIN_SLUG) === false ) + return $source; + + $path_parts = pathinfo( $source ); + $newsource = trailingslashit( $path_parts['dirname'] ) . trailingslashit( PLUGIN_SLUG ); + rename( $source, $newsource ); + return $newsource; +} + function afg_check_for_plugin_update($checked_data) { global $api_url, $plugin_slug, $plugin_slug_file, $package_type; From cdaa4b66d369985a8186c2ad53ce2660de0334f9 Mon Sep 17 00:00:00 2001 From: Ronak Gandhi Date: Sun, 27 Jul 2014 11:25:38 -0700 Subject: [PATCH 3/3] Add option to select cache refresh interval. Add option to select cache refresh interval in advanced settings. Setting applies to all galleries, but is enforced individually on each gallery. This should help users who load multiple galleries on same page as even basic REST calls to Flickr are now not made. Don't load codemirror scripts on all wordpress admin pages. Changes to support serving AFG updates directly from Github to avoid manually uploading files on dropbox. This will come into effect from next version. --- afg_admin_settings.php | 12 +++-- afg_advanced_settings.php | 36 +++++++++++---- afg_libs.php | 29 +++++++++++- afg_update.php | 10 ++--- index.php | 93 +++++++++++++++++++++------------------ 5 files changed, 120 insertions(+), 60 deletions(-) diff --git a/afg_admin_settings.php b/afg_admin_settings.php index 0faeae9..7e32b50 100644 --- a/afg_admin_settings.php +++ b/afg_admin_settings.php @@ -96,6 +96,7 @@ function afg_get_all_options() { 'afg_api_secret' => get_option('afg_api_secret'), 'afg_flickr_token' => get_option('afg_flickr_token'), 'afg_slideshow_option' => get_option('afg_slideshow_option'), + 'afg_cache_refresh_interval' => get_option('afg_cache_refresh_interval'), ); } @@ -155,6 +156,7 @@ function afg_admin_init() { register_setting('afg_settings_group', 'afg_custom_size_square'); register_setting('afg_settings_group', 'afg_custom_css'); register_setting('afg_settings_group', 'afg_sort_order'); + register_setting('afg_settings_group', 'afg_cache_refresh_interval'); // Register javascripts wp_register_script('edit-galleries-script', BASE_URL . '/js/afg_edit_galleries.js'); @@ -185,6 +187,10 @@ function upgrade_handler() { } unset($gallery); + $afg_cache_refresh_interval = get_option('afg_cache_refresh_interval'); + if (!isset($afg_cache_refresh_interval)) { + update_option('afg_cache_refresh_interval', '1d'); + } } upgrade_handler(); @@ -287,8 +293,8 @@ function upgrade_handler() { echo " -
ONLY If you want to include your Private Photos in your galleries, enter your Flickr API Secret here and click Save Changes. -
+ ONLY If you want to include your Private Photos in your galleries, enter your Flickr API Secret here and click Save Changes. + @@ -307,7 +313,7 @@ function upgrade_handler() { - diff --git a/afg_advanced_settings.php b/afg_advanced_settings.php index 0076bb9..e6440cd 100644 --- a/afg_advanced_settings.php +++ b/afg_advanced_settings.php @@ -2,13 +2,15 @@ require_once('afg_libs.php'); function afg_admin_enqueue_scripts() { - wp_enqueue_script('jquery'); - wp_enqueue_script('afg_custom_css_js', BASE_URL . "/CodeMirror/lib/codemirror.js"); - wp_enqueue_script('afg_custom_css_theme_js', BASE_URL . "/CodeMirror/mode/css/css.js"); - wp_enqueue_style('afg_custom_css_style', BASE_URL . "/CodeMirror/lib/codemirror.css"); - wp_enqueue_style('afg_custom_css_theme_css', BASE_URL . "/CodeMirror/theme/cobalt.css"); - wp_enqueue_style('afg_custom_css_style', BASE_URL . "/CodeMirror/css/docs.css"); - wp_enqueue_style('afg_admin_css', BASE_URL . "/afg_admin.css"); + if ( ! empty( $_GET[ 'page' ] ) && 0 === strpos( $_GET[ 'page' ], 'afg_' )) { + wp_enqueue_script('jquery'); + wp_enqueue_script('afg_custom_css_js', BASE_URL . "/CodeMirror/lib/codemirror.js"); + wp_enqueue_script('afg_custom_css_theme_js', BASE_URL . "/CodeMirror/mode/css/css.js"); + wp_enqueue_style('afg_custom_css_style', BASE_URL . "/CodeMirror/lib/codemirror.css"); + wp_enqueue_style('afg_custom_css_theme_css', BASE_URL . "/CodeMirror/theme/cobalt.css"); + wp_enqueue_style('afg_custom_css_style', BASE_URL . "/CodeMirror/css/docs.css"); + wp_enqueue_style('afg_admin_css', BASE_URL . "/afg_admin.css"); + } } if (is_admin()) { @@ -33,15 +35,31 @@ function afg_advanced_settings_page() {

Settings updated successfully.

"; } ?> -
+
+

Advanced Settings

+
Sort order of Photos Set the sort order of the photos as per your liking and forget about how photos are arranged on Flickr.
+ + + + + + + + + + +
Cache Refresh Interval
How frequently should cached galleries update? Select a value that relates to your photos upload frequency on Flickr. Default is set to 1 day.

Custom CSS

Check ' target='_blank'>afg.css to see existing classes and properties for gallery which you can redefine here. Note that there is no validation applied to CSS Code entered here, so make sure that you enter valid CSS. diff --git a/afg_libs.php b/afg_libs.php index fc14cbe..b9a2a01 100644 --- a/afg_libs.php +++ b/afg_libs.php @@ -3,7 +3,7 @@ define('BASE_URL', plugins_url() . '/' . basename(dirname(__FILE__))); define('SITE_URL', site_url()); define('DEBUG', false); -define('VERSION', '3.5.0'); +define('VERSION', '3.5.1'); $afg_sort_order_map = array( 'default' => 'Default', @@ -110,6 +110,33 @@ 'White' => 'Black', ); +$afg_cache_refresh_interval_map = array( + '6h' => '6 Hours', + '12h' => '12 Hours', + '1d' => '1 Day', + '3d' => '3 Days', + '1w' => '1 Week', +); + +function afg_get_cache_refresh_interval_secs ($interval) +{ + if ($interval == '6h') { + return 6 * 60 * 60; + } + else if ($interval == '12h') { + return 12 * 60 * 60; + } + else if ($interval == '1d') { + return 24 * 60 * 60; + } + else if ($interval == '3d') { + return 3 * 24 * 60 * 60; + } + else if ($interval == '1w') { + return 7 * 24 * 60 * 60; + } +} + function afg_get_sets_groups_galleries (&$photosets_map, &$groups_map, &$galleries_map, $user_id) { global $pf; diff --git a/afg_update.php b/afg_update.php index af0b9fb..a8ea427 100644 --- a/afg_update.php +++ b/afg_update.php @@ -36,10 +36,10 @@ function afg_ssl_verify($args, $url) { * @wp-hook plugins_loaded * @return object of this class */ -add_filter( 'upgrader_source_selection', 'afg_rename_update_zip', 1, 3); +add_filter( 'upgrader_source_selection', 'afg_rename_github_zip', 1, 3); /** - * Removes the suffix - when updating from GitHub zip files + * Removes the prefix "-master" when updating from GitHub zip files * * See: https://github.com/YahnisElsts/plugin-update-checker/issues/1 * @@ -48,13 +48,13 @@ function afg_ssl_verify($args, $url) { * @param object $thiz * @return string */ -function afg_rename_update_zip( $source, $remote_source, $thiz ) +function afg_rename_github_zip( $source, $remote_source, $thiz ) { - if( strpos( $source, PLUGIN_SLUG) === false ) + if( strpos( $source, 'awesome-flickr-gallery-plugin') === false ) return $source; $path_parts = pathinfo( $source ); - $newsource = trailingslashit( $path_parts['dirname'] ) . trailingslashit( PLUGIN_SLUG ); + $newsource = trailingslashit( $path_parts['dirname'] ) . trailingslashit( 'awesome-flickr-gallery-plugin' ); rename( $source, $newsource ); return $newsource; } diff --git a/index.php b/index.php index 936a573..7f24b85 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ Plugin Name: Awesome Flickr Gallery Plugin URI: http://www.ronakg.com/projects/awesome-flickr-gallery-wordpress-plugin/ Description: Awesome Flickr Gallery is a simple, fast and light plugin to create a gallery of your Flickr photos on your WordPress enabled website. This plugin aims at providing a simple yet customizable way to create stunning Flickr gallery. - Version: 3.5.0 + Version: 3.5.1 Author: Ronak Gandhi Author URI: http://www.ronakg.com License: GPL2 @@ -180,6 +180,7 @@ function afg_display_gallery($atts) { $credit_note = get_afg_option($gallery, 'credit_note'); $gallery_width = get_afg_option($gallery, 'width'); $pagination = get_afg_option($gallery, 'pagination'); + $cache_refresh_interval = get_afg_option($gallery, 'cache_refresh_interval'); if ($photo_size == 'custom') { $custom_size = get_afg_option($gallery, 'custom_size'); @@ -236,44 +237,45 @@ function afg_display_gallery($atts) { $extras = 'url_l, description, date_upload, date_taken, owner_name'; - if (isset($photoset_id) && $photoset_id) { - $rsp_obj = $pf->photosets_getInfo($photoset_id); - if ($pf->error_code) return afg_error($pf->error_msg); - $total_photos = $rsp_obj['photos']; - } - else if (isset($gallery_id) && $gallery_id) { - $rsp_obj = $pf->galleries_getInfo($gallery_id); - if ($pf->error_code) return afg_error($pf->error_msg); - $total_photos = $rsp_obj['gallery']['count_photos']['_content']; - } - else if (isset($group_id) && $group_id) { - $rsp_obj = $pf->groups_pools_getPhotos($group_id, NULL, NULL, NULL, NULL, 1, 1); - if ($pf->error_code) return afg_error($pf->error_msg); - $total_photos = $rsp_obj['photos']['total']; - if ($total_photos > 500) $total_photos = 500; - } - else if (isset($tags) && $tags) { - $rsp_obj = $pf->photos_search(array('user_id'=>$user_id, 'tags'=>$tags, 'extras'=>$extras, 'per_page'=>1)); - if ($pf->error_code) return afg_error($pf->error_msg); - $total_photos = $rsp_obj['photos']['total']; - } - else if (isset($popular) && $popular) { - $rsp_obj = $pf->photos_search(array('user_id'=>$user_id, 'sort'=>'interestingness-desc', 'extras'=>$extras, 'per_page'=>1)); - if ($pf->error_code) return afg_error($pf->error_msg); - $total_photos = $rsp_obj['photos']['total']; - } - else { - $rsp_obj = $pf->people_getInfo($user_id); - if ($pf->error_code) return afg_error($pf->error_msg); - $total_photos = $rsp_obj['photos']['count']['_content']; + if (!DEBUG) { + $photos = get_transient('afg_id_' . $id); } - $photos = get_transient('afg_id_' . $id); - if (DEBUG) - $photos = NULL; - - if ($photos == false || $total_photos != count($photos)) { + if ($photos === false) { $photos = array(); + + if (isset($photoset_id) && $photoset_id) { + $rsp_obj = $pf->photosets_getInfo($photoset_id); + if ($pf->error_code) return afg_error($pf->error_msg); + $total_photos = $rsp_obj['photos']; + } + else if (isset($gallery_id) && $gallery_id) { + $rsp_obj = $pf->galleries_getInfo($gallery_id); + if ($pf->error_code) return afg_error($pf->error_msg); + $total_photos = $rsp_obj['gallery']['count_photos']['_content']; + } + else if (isset($group_id) && $group_id) { + $rsp_obj = $pf->groups_pools_getPhotos($group_id, NULL, NULL, NULL, NULL, 1, 1); + if ($pf->error_code) return afg_error($pf->error_msg); + $total_photos = $rsp_obj['photos']['total']; + if ($total_photos > 500) $total_photos = 500; + } + else if (isset($tags) && $tags) { + $rsp_obj = $pf->photos_search(array('user_id'=>$user_id, 'tags'=>$tags, 'extras'=>$extras, 'per_page'=>1)); + if ($pf->error_code) return afg_error($pf->error_msg); + $total_photos = $rsp_obj['photos']['total']; + } + else if (isset($popular) && $popular) { + $rsp_obj = $pf->photos_search(array('user_id'=>$user_id, 'sort'=>'interestingness-desc', 'extras'=>$extras, 'per_page'=>1)); + if ($pf->error_code) return afg_error($pf->error_msg); + $total_photos = $rsp_obj['photos']['total']; + } + else { + $rsp_obj = $pf->people_getInfo($user_id); + if ($pf->error_code) return afg_error($pf->error_msg); + $total_photos = $rsp_obj['photos']['count']['_content']; + } + for($i=1; $i<($total_photos/500)+1; $i++) { if ($photoset_id) { $flickr_api = 'photoset'; @@ -309,11 +311,18 @@ function afg_display_gallery($atts) { $photos = array_merge($photos, $rsp_obj_total[$flickr_api]['photo']); } if (!DEBUG) - set_transient('afg_id_' . $id, $photos, 60 * 60 * 24 * 3); + set_transient('afg_id_' . $id, $photos, afg_get_cache_refresh_interval_secs($cache_refresh_interval)); + } + else { + $total_photos = count($photos); } - if (($total_photos % $per_page) == 0) $total_pages = (int)($total_photos / $per_page); - else $total_pages = (int)($total_photos / $per_page) + 1; + if (($total_photos % $per_page) == 0) { + $total_pages = (int)($total_photos / $per_page); + } + else { + $total_pages = (int)($total_photos / $per_page) + 1; + } if ($gallery_width == 'auto') $gallery_width = 100; $text_color = isset($afg_text_color_map[$bg_color])? $afg_text_color_map[$bg_color]: ''; @@ -391,12 +400,12 @@ function afg_display_gallery($atts) { if ($slideshow_option == 'highslide' && $p_description) { $photo_title_text .= '
' . $p_description . ''; } - $photo_title_text .= ' • View on Flickr'; + $photo_title_text .= ' • View on Flickr'; $photo_title_text = esc_attr($photo_title_text); if ($slideshow_option == 'flickr') { - $photo_page_url = "http://www.flickr.com/photos/" . $photo['owner'] . "/" . $photo['id']; + $photo_page_url = "https://www.flickr.com/photos/" . $photo['owner'] . "/" . $photo['id']; } } @@ -434,7 +443,7 @@ function afg_display_gallery($atts) { if ($size_heading_map[$photo_size] && $photo_title == 'on') { if ($group_id || $gallery_id) - $owner_title = "- by {$photo['ownername']}"; + $owner_title = "- by {$photo['ownername']}"; else $owner_title = '';