Skip to content

Commit

Permalink
Merge pull request #34 from ronakg/3.5.1
Browse files Browse the repository at this point in the history
3.5.1
  • Loading branch information
ronakg committed Jul 27, 2014
2 parents e96df29 + cdaa4b6 commit e0dce9d
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 66 deletions.
12 changes: 9 additions & 3 deletions afg_admin_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
}

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -287,8 +293,8 @@ function upgrade_handler() {
echo "<input type='button' class='button-secondary' value='Grant Access' disabled=''";
} ?>
</td>
<td> <div class="afg-help"><b>ONLY</b> If you want to include your <b>Private Photos</b> in your galleries, enter your Flickr API Secret here and click Save Changes.
</div></td>
<td class="afg-help"><b>ONLY</b> If you want to include your <b>Private Photos</b> in your galleries, enter your Flickr API Secret here and click Save Changes.
</td>
</tr>
</table>
<table class='widefat afg-settings-box'>
Expand All @@ -307,7 +313,7 @@ function upgrade_handler() {

<tr>
<td>Sort order of Photos</td>
<td><select type='text' name='afg_sort_order' id='afg_sort_order'>
<td><select name='afg_sort_order' id='afg_sort_order'>
<?php echo afg_generate_options($afg_sort_order_map, get_option('afg_sort_order', 'flickr')); ?>
</select>
<td class="afg-help">Set the sort order of the photos as per your liking and forget about how photos are arranged on Flickr.</td>
Expand Down
36 changes: 27 additions & 9 deletions afg_advanced_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -33,15 +35,31 @@ function afg_advanced_settings_page() {
<?php
if (isset($_POST['afg_advanced_save_changes']) && $_POST['afg_advanced_save_changes']) {
update_option('afg_disable_slideshow', isset($_POST['afg_disable_slideshow'])? $_POST['afg_disable_slideshow']: '');
update_option('afg_slideshow_option', $_POST['afg_slideshow_option']);
update_option('afg_custom_css', $_POST['afg_custom_css']);
update_option('afg_cache_refresh_interval', $_POST['afg-cache-refresh-interval']);
echo "<div class='updated'><p><strong>Settings updated successfully.</strong></p></div>";
}
?>
<form method='post' action='<?php echo $url ?>'>
<?php echo afg_generate_version_line() ?>
<div id='afg-wrap'>
<?php global $afg_cache_refresh_interval_map;
echo afg_generate_version_line();
?>
<div id="afg-main-box">
<h3>Advanced Settings</h3>
<table class='widefat afg-settings-box'>
<tr>
<th class="afg-label"></th>
<th class="afg-input"></th>
<th class="afg-help-bubble"></th>
</tr>
<tr>
<td>Cache Refresh Interval</td>
<td><select name='afg-cache-refresh-interval' id='afg-cache-refresh-interval'> <?php echo afg_generate_options($afg_cache_refresh_interval_map, get_option('afg_cache_refresh_interval', '1d')); ?>
</select></td>
<td> <div class="afg-help">How frequently should cached galleries update? Select a value that relates to your photos upload frequency on Flickr. Default is set to 1 day.</div></td>
</tr>
</table>
<h3>Custom CSS</h3>
<div style="background-color:#FFFFE0; border-color:#E6DB55; maargin:5px 0 15px; border-radius:3px 3px 3px 3px; border-width: 1px; border-style: solid; padding: 8px 10px; line-height: 20px">
Check <a href='<?php echo BASE_URL . '/afg.css';?>' target='_blank'>afg.css</a> 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.
Expand Down
36 changes: 31 additions & 5 deletions afg_libs.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

define('PLUGIN_SLUG', 'awesome-flickr-gallery-plugin');
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',
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -164,9 +191,8 @@ function create_afgFlickr_obj() {
$pf->setToken(get_option('afg_flickr_token'));
}

function afg_error() {
global $pf;
return "<h3>Awesome Flickr Gallery Error - $pf->error_msg</h3>";
function afg_error($error_msg) {
return "<h3>Awesome Flickr Gallery Error - $error_msg</h3>";
}

function date_taken_cmp_newest($a, $b) {
Expand Down
31 changes: 30 additions & 1 deletion afg_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// TEMP: Show which variables are being requested when query plugin API
add_filter('plugins_api_result', 'afg_aaa_result', 10, 3);
function afg_aaa_result($res, $action, $args) {
print_r($res);
//print_r($res);
return $res;
}
}
Expand All @@ -30,6 +30,35 @@ function afg_ssl_verify($args, $url) {
return $args;
}

/**
* Access this plugin’s working instance
*
* @wp-hook plugins_loaded
* @return object of this class
*/
add_filter( 'upgrader_source_selection', 'afg_rename_github_zip', 1, 3);

/**
* Removes the prefix "-master" 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_github_zip( $source, $remote_source, $thiz )
{
if( strpos( $source, 'awesome-flickr-gallery-plugin') === false )
return $source;

$path_parts = pathinfo( $source );
$newsource = trailingslashit( $path_parts['dirname'] ) . trailingslashit( 'awesome-flickr-gallery-plugin' );
rename( $source, $newsource );
return $newsource;
}

function afg_check_for_plugin_update($checked_data) {
global $api_url, $plugin_slug, $plugin_slug_file, $package_type;

Expand Down
109 changes: 61 additions & 48 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand All @@ -176,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');
Expand Down Expand Up @@ -232,84 +237,92 @@ 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();
$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();
$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();
$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();
$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();
$total_photos = $rsp_obj['photos']['total'];
if (!DEBUG) {
$photos = get_transient('afg_id_' . $id);
}
else {
$rsp_obj = $pf->people_getInfo($user_id);
if ($pf->error_code) return afg_error();
$total_photos = $rsp_obj['photos']['count']['_content'];
}

$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';
$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']);
}
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]: '';
Expand Down Expand Up @@ -387,12 +400,12 @@ function afg_display_gallery($atts) {
if ($slideshow_option == 'highslide' && $p_description) {
$photo_title_text .= '<br /><span style="font-size:0.8em;">' . $p_description . '</span>';
}
$photo_title_text .= ' • <a style="font-size:0.8em;" href="http://www.flickr.com/photos/' . $photo['owner'] . '/' . $photo['id'] . '/" target="_blank">View on Flickr</a>';
$photo_title_text .= ' • <a style="font-size:0.8em;" href="https://www.flickr.com/photos/' . $photo['owner'] . '/' . $photo['id'] . '/" target="_blank">View on Flickr</a>';

$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'];
}
}

Expand Down Expand Up @@ -430,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 <a href='http://www.flickr.com/photos/{$photo['owner']}/' target='_blank'>{$photo['ownername']}</a>";
$owner_title = "- by <a href='https://www.flickr.com/photos/{$photo['owner']}/' target='_blank'>{$photo['ownername']}</a>";
else
$owner_title = '';

Expand Down

0 comments on commit e0dce9d

Please sign in to comment.