. */ //Defaults $flickr_photostream_imagesHeight_default = '120'; $flickr_photostream_maxPhotosPP_default = '20'; $flickr_photostream_lastRow_default = 'justify'; $flickr_photostream_fixedHeight_default = '0'; $flickr_photostream_pagination_default = 'none'; $flickr_photostream_lightbox_default = 'none'; $flickr_photostream_captions_default = '1'; $flickr_photostream_randomize_default = '0'; $flickr_photostream_margins_default = '1'; $flickr_photostream_openOriginals_default = '0'; $flickr_photostream_bcontextmenu_default = '0'; //Add the link to the plugin page add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'flickrps_plugin_settings_link' ); function flickrps_plugin_settings_link($links) { $settings_link = 'Settings'; array_unshift($links, $settings_link); return $links; } //Activation hook, we check that the upload dir is writable register_activation_hook( __FILE__ , 'flickrps_plugin_activate'); if (!function_exists( 'flickrps_plugin_uninstall')) { function flickrps_plugin_activate() { $upload_dir = wp_upload_dir(); @mkdir($upload_dir['basedir'].'/phpFlickrCache'); if (!is_writable($upload_dir['basedir'].'/phpFlickrCache')) { deactivate_plugins(basename(__FILE__)); // Deactivate ourself wp_die(__('Flickr Photostream can\'t be activated: the cache Folder is not writable', 'flickr-photostream') . ' (' . $upload_dir['basedir'] .'/phpFlickrCache' . ')' ); } } } //Add the language and the permalink add_action('init', 'flickrps_init'); function flickrps_init() { /* languages */ load_plugin_textdomain('flickr-photostream', false, dirname(plugin_basename( __FILE__ )) . '/languages/'); } //Register with hook 'wp_enqueue_scripts' which can be used for front end CSS and JavaScript add_action('wp_enqueue_scripts', 'flickrps_addCSSandJS'); function flickrps_addCSSandJS() { wp_register_style('justifiedGalleryCSS', plugins_url('justifiedgallery/css/justifiedGallery.min.css', __FILE__)); wp_register_style('swipeboxCSS', plugins_url('swipebox/css/swipebox.min.css', __FILE__)); wp_register_script('justifiedGalleryJS', plugins_url('justifiedgallery/js/jquery.justifiedGallery.min.js', __FILE__)); wp_register_script('swipeboxJS', plugins_url('swipebox/js/jquery.swipebox.min.js', __FILE__)); wp_enqueue_style('justifiedGalleryCSS'); wp_enqueue_style('swipeboxCSS'); wp_enqueue_script('jquery'); wp_enqueue_script('justifiedGalleryJS'); wp_enqueue_script('swipeboxJS'); } function flickrps_formatError($errorMsg) { return '
' . __('FlickrPhotostream error', 'flickr-photostream') . ': ' . $errorMsg . '
'; } function flickrps_formatFlickrAPIError($errorMsg) { return '
' . __('Flickr API error', 'flickr-photostream') . ': ' . $errorMsg . '
'; } function flickrps_createGallery($action, $atts) { global $flickr_photostream_imagesHeight_default; global $flickr_photostream_maxPhotosPP_default; global $flickr_photostream_lastRow_default; global $flickr_photostream_fixedHeight_default; global $flickr_photostream_pagination_default; global $flickr_photostream_lightbox_default; global $flickr_photostream_captions_default; global $flickr_photostream_randomize_default; global $flickr_photostream_margins_default; global $flickr_photostream_openOriginals_default; global $flickr_photostream_bcontextmenu_default; static $shortcode_unique_id = 0; $ris = ""; require_once("phpFlickr/phpFlickr.php"); $page_num = (get_query_var('page')) ? get_query_var('page') : 1; //Options----------------------- extract( shortcode_atts( array( //left value: the variable to set (e.g. user_id option in shortcode set the variable $user_id in the function scope) //right value: the default value, in our case we take this values from the options where we store them. 'user_id' => get_option('$flickr_photostream_userID'), 'id' => NULL, 'tags' => NULL, 'tags_mode' => 'any', 'images_height' => get_option('$flickr_photostream_imagesHeight', $flickr_photostream_imagesHeight_default), // Flickr images size 'max_num_photos' => get_option('$flickr_photostream_maxPhotosPP', $flickr_photostream_maxPhotosPP_default), // Max number of Photos 'last_row' => get_option('$flickr_photostream_lastRow', $flickr_photostream_lastRow_default), 'fixed_height' => get_option('$flickr_photostream_fixedHeight', $flickr_photostream_fixedHeight_default) == 1, 'lightbox' => get_option('$flickr_photostream_lightbox', $flickr_photostream_lightbox_default), 'captions' => get_option('$flickr_photostream_captions', $flickr_photostream_captions_default) == 1, 'randomize' => get_option('$flickr_photostream_randomize', $flickr_photostream_randomize_default) == 1, 'pagination' => get_option('$flickr_photostream_pagination', $flickr_photostream_pagination_default), 'margins' => get_option('$flickr_photostream_margins', $flickr_photostream_margins_default), 'open_originals' => get_option('$flickr_photostream_openOriginals', $flickr_photostream_openOriginals_default) == 1, 'block_contextmenu' => get_option('$flickr_photostream_bcontextmenu', $flickr_photostream_bcontextmenu_default) == 1 ), $atts ) ); //LEGACY for the old options if($pagination === '1') $pagination = 'prevnext'; else if ($pagination !== 'none' && $pagination !== 'prevnext' && $pagination !== 'numbers') $pagination = 'none'; if($lightbox === '1') $lightbox = 'colorbox'; if($lightbox === '0') $lightbox = 'none'; $images_height = (int)$images_height; if($images_height < 30) $images_height = 30; $max_num_photos = (int)$max_num_photos; if ($max_num_photos < 1) $max_num_photos = 1; $margins = (int)$margins; if ($margins < 0) $margins = 1; if ($margins > 30) $margins = 30; if($pagination === 'none') $page_num = 1; //----------------------------- //Inizialization--------------- $flickrAPIKey = get_option('$flickr_photostream_APIKey'); //Flickr API Key $f = new phpFlickr($flickrAPIKey); $upload_dir = wp_upload_dir(); $f->enableCache("fs", $upload_dir['basedir']."/phpFlickrCache"); $photos_url = array(); $photos = array(); $photos_main_index = ''; $target_blank = true; //TODO in the settings page? $maximum_pages_nums = 10; //TODO configurable? //Errors----------------------- if ($action === 'phs' || $action === 'gal' || $action === 'tag') { if (!isset($user_id) || strlen($user_id) == 0) return(flickrps_formatError(__('You must specify the user_id for this action, using the "user_id" attribute', 'flickr-photostream'))); } if ($action === 'gal') { if (!isset($id) || strlen($id) == 0) return(flickrps_formatError(__('You must specify the id of the gallery, using the "id" attribute', 'flickr-photostream'))); } if ($action === 'set') { if (!isset($id) || strlen($id) == 0) return(flickrps_formatError(__('You must specify the id of the set, using the "id" attribute', 'flickr-photostream'))); } if ($action === 'tag') { if (!isset($tags) || strlen($tags) == 0) return(flickrps_formatError(__('You must specify the tags using the "tags" attribute', 'flickr-photostream'))); if ($tags_mode !== 'any' && $tags_mode !== 'all') return(flickrps_formatError(__('You must specify a valid tags_mode: "any" or "all"', 'flickr-photostream'))); } if ($action === 'grp') { if (!isset($id) || strlen($id) == 0) return(flickrps_formatError(__('You must specify the id of the group, using the "id" attribute', 'flickr-photostream'))); } if ($pagination !== 'none' && $pagination !== 'prevnext' && $pagination !== 'numbers') { return(flickrps_formatError(__('The pagination attribute can be only "none", "prevnext" or "numbers".', 'flickr-photostream'))); } if ($last_row !== 'hide' && $last_row !== 'justify' && $last_row !== 'nojustify') { return(flickrps_formatError(__('The last_row attribute can be only "hide", "justify" or "nojustify".', 'flickr-photostream'))); } if ($lightbox !== 'none' && $lightbox !== 'colorbox' && $lightbox !== 'swipebox') { return(flickrps_formatError(__('The lightbox attribute can be only "none", "colorbox" or "swipebox".', 'flickr-photostream'))); } //Photo loading---------------- $extras = "description, original_format, url_l, url_z"; if ($action === 'set') { //Show the photos of a particular photoset $photos = $f->photosets_getPhotos($id, $extras, 1, $max_num_photos, $page_num, NULL); $photos_main_index = 'photoset'; } else if ($action === 'gal') { //Show the photos of a particular gallery $photos_url[$user_id] = $f->urls_getUserPhotos($user_id); if ($f->getErrorCode() != NULL) return(flickrps_formatFlickrAPIError($f->getErrorMsg())); $gallery_info = $f->urls_lookupGallery($photos_url[$user_id] . 'galleries/' . $id); if ($f->getErrorCode() != NULL) return(flickrps_formatFlickrAPIError($f->getErrorMsg())); $photos = $f->galleries_getPhotos($gallery_info['gallery']['id'], $extras, $max_num_photos, $page_num); $photos_main_index = 'photos'; } else if ($action === 'tag') { $photos = $f->photos_search(array( 'user_id' => $user_id, 'tags' => $tags, 'tag_mode' => $tags_mode, 'extras' => $extras, 'per_page' => $max_num_photos, 'page' => $page_num )); $photos_main_index = 'photos'; } else if ($action === 'grp') { //Show the photos of a particular group pool //groups_pools_getPhotos ($group_id, $tags = NULL, $user_id = NULL, $jump_to = NULL, $extras = NULL, $per_page = NULL, $page = NULL) { $photos = $f->groups_pools_getPhotos($id, $tags, NULL, NULL, $extras, $max_num_photos, $page_num); $photos_main_index = 'photos'; } else { //Show the classic photostream $photos = $f->people_getPublicPhotos($user_id, NULL, $extras, $max_num_photos, $page_num); //Need the authentication (TODO) //$photos = $f->people_getPhotos($user_id, // array("privacy_filter" => "1", "extras" => "description", "per_page" => $max_num_photos, "page" => $page_num)); $photos_main_index = 'photos'; } if ($f->getErrorCode() != NULL) return(flickrps_formatFlickrAPIError($f->getErrorMsg())); if(count((array)$photos[$photos_main_index]['photo']) == 0) return(__('No photos', 'flickr-photostream')); //we calculate that the aspect ratio has an average of 4:3 if($images_height <= 75) { $imgSize = "thumbnail"; //thumbnail (longest side:100) }else if($images_height <= 180) { $imgSize = "small"; //small (longest side:240) }else{ //if <= 240 $imgSize = "small_320"; //small (longest side:320) } $ris .= '' . "\n" . '' . ''; //Navigation--------------------- if($pagination !== 'none') { $num_pages = $photos[$photos_main_index]['pages']; if ($num_pages > 1) { $permalink = get_permalink(); if ($pagination === 'numbers') { $ris .= ''; } else if ($pagination === 'prevnext') { $ris .= '
'; if ($page_num < $num_pages) { $ris .= ''; } if ($page_num > 1) { //a link to the newer photos $ris .= ''; } $ris .= '
'; } } } $shortcode_unique_id++; return($ris); } $doubleTagDetected = false; if (!shortcode_exists('flickr_photostream')) { //[flickr_photostream user_id="..." ...] function flickr_photostream($atts, $content = null) { return flickrps_createGallery('phs', $atts); } add_shortcode('flickr_photostream', 'flickr_photostream'); add_shortcode('flickrps', 'flickr_photostream'); //TODO to remove, legacy code } else { $doubleTagDetected = true; } if (!shortcode_exists('flickr_set')) { //[flickr_set id="..." ...] function flickr_set($atts, $content = null) { return flickrps_createGallery('set', $atts); } add_shortcode('flickr_set', 'flickr_set'); } else { $doubleTagDetected = true; } if (!shortcode_exists('flickr_gallery')) { //[flickr_gallery user_id="..." id="..." ...] function flickr_gallery($atts, $content = null) { return flickrps_createGallery('gal', $atts); } add_shortcode('flickr_gallery', 'flickr_gallery'); } else { $doubleTagDetected = true; } if (!shortcode_exists('flickr_tags')) { //[flickr_tags user_id="..." tags="..." tags_mode="any/all" ...] function flickr_tags($atts, $content = null) { return flickrps_createGallery('tag', $atts); } add_shortcode('flickr_tags', 'flickr_tags'); } else { $doubleTagDetected = true; } if (!shortcode_exists('flickr_group')) { //[flickr_group id="..."] function flickr_group($atts, $content = null) { return flickrps_createGallery('grp', $atts); } add_shortcode('flickr_group', 'flickr_group'); } else { $doubleTagDetected = true; } function flickr_photostream_double_tag_detected() { ?>