. */ //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/'); } //Add the vars so that WP recognizes it add_filter('query_vars','flickrps_insert_query_vars'); function flickrps_insert_query_vars( $vars ) { array_push($vars, 'flickrpsp'); return $vars; } //Register with hook 'wp_enqueue_scripts' which can be used for front end CSS and JavaScript add_action('wp_enqueue_scripts', 'addFlickrPhotostreamCSSandJS'); function addFlickrPhotostreamCSSandJS() { wp_register_style('flickrPsCSS', plugins_url('css/flickr-photostream.css', __FILE__)); wp_register_style('justifiedGalleryCSS', plugins_url('justifiedgallery/css/jquery.justifiedgallery.css', __FILE__)); wp_register_script('justifiedGalleryJS', plugins_url('justifiedgallery/js/jquery.justifiedgallery-min.js', __FILE__)); wp_enqueue_style('flickrPsCSS'); wp_enqueue_style('justifiedGalleryCSS'); wp_enqueue_script('jquery'); wp_enqueue_script('justifiedGalleryJS'); } add_action('parse_request', 'addFlickrPhotostreamURL'); function addFlickrPhotostreamURL() { global $flickrpsp; // Manually parse the URL request if (!empty($_SERVER['REQUEST_URI'])) { $urlvars = explode('/', $_SERVER['REQUEST_URI']); } var_dump($_SERVER['REQUEST_URI']); // Check for querystring variables if ((!empty($urlvars[1])) && (!empty($urlvars[2]))) { $_REQUEST['page'] = $urlvars[1]; $_REQUEST['flickrpsp'] = $urlvars[2]; $flickrpsp = $urlvars[2]; } // ... handle multiple types of URL by checking $urlvars[1] here } //[flickrps] shortcode function flickr_photostream( $atts, $content = null ) { static $shortcode_unique_id = 0; $ris = ""; require_once("phpFlickr/phpFlickr.php"); //Page--------- $permalink = get_permalink(); //if (strpos($permalink,'?') === false) $permalink .= '?'; else $permalink .= '&'; global $flickrpsp; if(empty($flickrpsp)){ //we use local instance of flickrpsp for the multiple instances $l_flickrpsp = 1; }else{ $l_flickrpsp = $flickrpsp; } //Options----------------------- extract( shortcode_atts( array( 'user_id' => get_option('$flickr_photostream_userID'), // Flickr User ID 'images_height' => get_option('$flickr_photostream_imagesHeight'), // Flickr images size 'max_num_photos' => get_option('$flickr_photostream_maxPhotosPP'), // Max number of Photos 'justify_last_row' => (get_option('$flickr_photostream_justifyLastRow') == 1 ? 'true' : 'false'), 'fixed_height' => (get_option('$flickr_photostream_fixedHeight') == 1 ? 'true' : 'false'), 'lightbox' => (get_option('$flickr_photostream_lightbox') == 1 ? 'true' : 'false'), 'captions' => (get_option('$flickr_photostream_captions') == 1 ? 'true' : 'false'), 'no_pages' => (get_option('$flickr_photostream_noPages') == 1 ? 'true' : 'false'), 'margins' => get_option('$flickr_photostream_margins'), ), $atts ) ); $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; $justify_last_row = (strcmp($justify_last_row, 'true') == 0)? TRUE : FALSE; $fixed_height = (strcmp($fixed_height, 'true') == 0)? TRUE : FALSE; $lightbox = (strcmp($lightbox, 'true') == 0)? TRUE : FALSE; $captions = (strcmp($captions, 'true') == 0)? TRUE : FALSE; $margins = (int)$margins; if ($margins < 0) $margins = 1; if ($margins > 30) $margins = 30; $no_pages = (strcmp($no_pages, 'true') == 0) ? TRUE : FALSE; if($no_pages) $l_flickrpsp = 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"); //Errors----------------------- if($f->test_echo() == false){ return('
' . __('Invalid Flickr API Key', 'flickr-photostream') . '
'); } if($f->urls_getUserProfile($user_id) == false){ return('
' . __('The user not exists', 'flickr-photostream') . '
'); } //Photo loading---------------- $photos_url = $f->urls_getUserPhotos($user_id); $photos = $f->people_getPublicPhotos($user_id, NULL, "description", $max_num_photos, $l_flickrpsp); if(count((array)$photos['photos']['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) $usedSuffix = "lt100"; }else if($images_height <= 180){ $imgSize = "small"; //small (longest side:240) $usedSuffix = "lt240"; }else{ //if <= 240 $imgSize = "small_320"; //small (longest side:320) $usedSuffix = "lt320"; } /*$ris .= '' . "\n" . '
'; */ $ris .= '' . "\n" . '
'; $r = 0; foreach ((array)$photos['photos']['photo'] as $photo) { if($lightbox){ $ris .= ''; }else{ $ris .= ''; } $ris .= '' . $photo[title] . '' . ''; } $ris .= '
' . ''; //Navigation--------------------- if(!$no_pages){ $nextPhotos = $f->people_getPublicPhotos($user_id, NULL, "description", $max_num_photos, $l_flickrpsp + 1); if(sizeof($nextPhotos['photos']['photo']) > 0 || $l_flickrpsp > 1){ $ris .= ''; } } $shortcode_unique_id++; return($ris); } add_shortcode('flickrps', 'flickr_photostream'); //Options include("flickr-photostream-setting.php"); ?>