Esempio n. 1
0
 /**
  * get images from flickr
  * @author - Henry Addo
  * @access - public 
  * @return - Array of images
  */
 public function get_images()
 {
     $username = "";
     $photo_urls = "http://www.flickr.com/photos/eyedol/";
     $tags = "tedglobal2007";
     // create instance of phpFlickr class
     $flickr = new phpFlickr('');
     //enable caching
     $flickr->enableCache("");
     //authenticate
     //$flickr->auth();
     //get token
     //$token = $token['user']['nsid'];
     // get NSID of the username
     $nsid = $token['user']['nsid'];
     $user = $flickr->people_findByUsername($username);
     //get the friendly URL of the the users' photos
     $photos_url = $flickr->urls_getUserPhotos($username);
     // get 20 images of public images of the user
     //$photos = $flickr->photos_search( array( 'tags'=>$tags,
     //'per_page'=> 200 ) );
     $photos = $flickr->people_getPublicPhotos($username, NULL, 36);
     // loop through the photos
     foreach ((array) $photos['photo'] as $photo) {
         $this->images[] = "<li><a href=\"#\">\n        <img  alt='{$photo['title']}' title='{$photo['title']}'\n        src=\"" . $flickr->buildPhotoURL($photo, 'Square') . "\" \n        onclick=\"get_image_id('" . $flickr->buildPhotoURL($photo) . "','{$photo['title']}')\"/></a></li>";
         $owner = $flickr->people_getInfo($photo[owner]);
         $this->owner = $owner['username'];
     }
     return $this->images;
 }
Esempio n. 2
0
function flickr_stream($username, $api_key)
{
    require_once "phpflickr/phpFlickr.php";
    $phpFlickrObj = new phpFlickr($api_key);
    $phpFlickrObj->enableCache("fs", TEMPLATEPATH . "/cache");
    $user = $phpFlickrObj->people_findByUsername($username);
    $user_url = $phpFlickrObj->urls_getUserPhotos($user['id']);
    $photos = $phpFlickrObj->people_getPublicPhotos($user['id'], NULL, NULL, 9);
    foreach ($photos['photos']['photo'] as $photo) {
        echo '<a href="' . $user_url . $photo['id'] . '" title="' . $photo['title'] . ' (on Flickr)" target="_blank">';
        echo '<img style="width: 64px; height: 64px; margin: 1px; padding: 2px; border: 3px solid #ddd; background: #fff;" class="wp-image" alt="' . $photo['title'] . '" src="' . $phpFlickrObj->buildPhotoURL($photo, "square") . '" />';
        echo '</a>';
    }
}
Esempio n. 3
0
function jeg_get_flickr_photo($flickrapi, $flickrid, $totalimage)
{
    require_once JEG_PLUGIN_DIR . "util/phpFlickr/phpFlickr.php";
    $f = new phpFlickr($flickrapi);
    $result = $f->people_getPublicPhotos($flickrid, null, null, $totalimage, null);
    $photos = array();
    if (empty($result)) {
        echo $f->getErrorMsg();
    } else {
        $photosUrl = $f->urls_getUserPhotos($flickrid);
        foreach ($result['photos']['photo'] as $photo) {
            $photos[] = array('s' => $f->buildPhotoURL($photo, 'square'), 'url' => $photosUrl . $photo['id'], 'title' => $photo['title']);
        }
    }
    return $photos;
}
 function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     if (empty($title)) {
         $title = false;
     }
     $flickr_api = $instance['flickr_api'];
     $flickr_id = $instance['flickr_id'];
     $number = absint($instance['number']);
     require_once get_template_directory() . "/includes/widgets/phpFlickr/phpFlickr.php";
     $f = new phpFlickr($flickr_api);
     //Insert API key here
     $f->enableCache("fs", get_template_directory() . "/includes/widgets/cache/");
     if (!empty($flickr_id)) {
         echo $before_widget;
         if ($title) {
             echo $before_title;
             echo $title;
             echo $after_title;
         }
         $apikey = $f->people_findByUsername($flickr_api);
         $person = $f->people_findByUsername($flickr_id);
         $photos_url = $f->urls_getUserPhotos($person['id']);
         $photos = $f->people_getPublicPhotos($person['id'], NULL, NULL, $number);
         echo "<ul class='flickr_images clearfix'>";
         foreach ((array) $photos['photos']['photo'] as $photo) {
             $photo_url = $f->buildPhotoURL($photo, "Large");
             echo "<li><a class='view flickr-img-link' rel='flickr-gallery' target='_blank' href={$photo_url}>";
             echo "<img class='flickr' alt='{$photo['title']}' " . "src=" . $f->buildPhotoURL($photo, "Small") . ">";
             echo "</a></li>";
         }
         echo "</ul>";
         echo $after_widget;
     }
 }
Esempio n. 5
0
function flickrbadge($params = array())
{
    $defaults = array('key' => false, 'username' => false, 'limit' => 10, 'format' => 'square', 'cache' => true, 'refresh' => 60 * 60 * 2);
    $options = array_merge($defaults, $params);
    // check the cache dir
    $cacheDir = c::get('root.cache') . '/flickrbadge';
    dir::make($cacheDir);
    // disable the cache if adding the cache dir failed
    if (!is_dir($cacheDir) || !is_writable($cacheDir)) {
        $options['cache'] = false;
    }
    if (!$options['key']) {
        return false;
    }
    if (!$options['username']) {
        return false;
    }
    $cacheID = 'flickrbadge/data.' . md5(serialize($options)) . '.php';
    if ($options['cache']) {
        $cache = cache::modified($cacheID) < time() - $options['refresh'] ? false : cache::get($cacheID);
    } else {
        $cache = false;
    }
    if (!empty($cache)) {
        return $cache;
    }
    $flickr = new phpFlickr($options['key']);
    $userCacheID = 'flickrbadge/user.' . md5($options['username']) . '.php';
    $userCache = $options['cache'] ? cache::get($userCacheID) : false;
    $user = false;
    $url = false;
    if (!empty($userCache)) {
        $user = a::get($userCache, 'user');
        $url = a::get($userCache, 'url');
    }
    if (!$user || !$url) {
        $user = $flickr->people_findByUsername($options['username']);
        $url = $flickr->urls_getUserPhotos($user['id']);
        if ($options['cache']) {
            cache::set($userCacheID, array('user' => $user, 'url' => $url));
        }
    }
    $photos = $flickr->people_getPublicPhotos($user['id'], NULL, NULL, $options['limit']);
    $result = array();
    foreach ($photos['photos']['photo'] as $photo) {
        $photoCacheID = 'flickrbadge/photo.' . $photo['id'] . '.php';
        $info = $options['cache'] ? cache::get($photoCacheID) : false;
        if (empty($info)) {
            $info = $flickr->photos_getInfo($photo['id']);
            if ($options['cache']) {
                cache::set($photoCacheID, $info);
            }
        }
        $info = a::get($info, 'photo', array());
        $dates = a::get($info, 'dates', array());
        $tags = array();
        foreach ((array) $info['tags']['tag'] as $t) {
            if (!empty($t['raw']) && !$t['machine_tag']) {
                $tags[] = $t['raw'];
            }
        }
        $result[] = new obj(array('url' => $url . $photo['id'], 'title' => a::get($info, 'title', $photo['title']), 'description' => @$info['description'], 'src' => $flickr->buildPhotoURL($photo, $options['format']), 'taken' => isset($dates['taken']) ? strtotime($dates['taken']) : false, 'posted' => isset($dates['posted']) ? $dates['posted'] : false, 'lastupdate' => isset($dates['lastupdate']) ? $dates['lastupdate'] : false, 'views' => a::get($info, 'views', 0), 'comments' => a::get($info, 'comments', 0), 'tags' => $tags));
    }
    $result = new obj($result);
    if ($options['cache']) {
        cache::set($cacheID, $result);
    }
    return $result;
}
Esempio n. 6
0
         $album['U_LIST'] = FLICKR_ADMIN . '-import&amp;action=list_photos&amp;album=' . $album['id'];
     }
     unset($album);
     // not classed
     $wo_albums = $flickr->photos_getNotInSet(NULL, NULL, NULL, NULL, 'photos', NULL, NULL, 1);
     if ($wo_albums['photos']['total'] > 0) {
         $albums[] = array('id' => 'not_in_set', 'title' => l10n('Pictures without album'), 'description' => null, 'photos' => $wo_albums['photos']['total'], 'U_LIST' => FLICKR_ADMIN . '-import&amp;action=list_photos&amp;album=not_in_set');
     }
     $template->assign(array('total_albums' => $total_albums, 'albums' => $albums));
     break;
     // list photos of an album
 // list photos of an album
 case 'list_photos':
     $self_url = FLICKR_ADMIN . '-import&amp;action=list_photos&amp;album=' . $_GET['album'];
     $flickr_prefix = 'flickr-' . $u['username'] . '-';
     $flickr_root_url = $flickr->urls_getUserPhotos($u['id']);
     // pagination
     if (isset($_GET['start'])) {
         $page['start'] = intval($_GET['start']);
     } else {
         $page['start'] = 0;
     }
     if (isset($_GET['display'])) {
         $page['display'] = $_GET['display'] == 'all' ? 500 : intval($_GET['display']);
     } else {
         $page['display'] = 20;
     }
     // get photos
     if ($_GET['album'] == 'not_in_set') {
         $all_photos = $flickr->photos_getNotInSet(NULL, NULL, NULL, NULL, 'photos', NULL, NULL, 500);
         $all_photos = $all_photos['photos']['photo'];
Esempio n. 7
0
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('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), 'max_num_photos' => get_option('$flickr_photostream_maxPhotosPP', $flickr_photostream_maxPhotosPP_default), '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 .= '<!-- Flickr Photostream by Miro Mannino -->' . "\n" . '<div id="flickrGal' . $shortcode_unique_id . '" class="justified-gallery" >';
    $r = 0;
    $use_large_thumbnails = true;
    $photo_array = $photos[$photos_main_index]['photo'];
    foreach ($photo_array as $photo) {
        if (!isset($photo['url_l'])) {
            $use_large_thumbnails = false;
        }
        if ($lightbox !== 'none') {
            $ris .= '<a href="';
            if ($open_originals) {
                if (isset($photo['originalsecret'])) {
                    $ris .= $f->buildPhotoURL($photo, "original");
                } else {
                    if (isset($photo['url_l'])) {
                        $ris .= $photo['url_l'];
                    } else {
                        $ris .= $photo['url_z'];
                    }
                }
            } else {
                if (isset($photo['url_l'])) {
                    $ris .= $photo['url_l'];
                } else {
                    $ris .= $photo['url_z'];
                }
            }
            $ris .= '" rel="flickrGal' . $shortcode_unique_id . '" title="' . $photo['title'] . '">';
        } else {
            //If it is a gallery the photo has an owner, else is the photoset owner (or the photostream owner)
            $photo_owner = isset($photo['owner']) ? $photo['owner'] : $photos[$photos_main_index]['owner'];
            //Save the owner url
            if (!isset($photos_url[$photo_owner])) {
                $photos_url[$photo_owner] = $f->urls_getUserPhotos($photo_owner);
                if ($f->getErrorCode() != NULL) {
                    return flickrps_formatFlickrAPIError($f->getErrorMsg());
                }
            }
            if ($action === 'set') {
                $photos_url_in = '/in/set-' . $id . '/lightbox';
            } else {
                $photos_url_in = '/in/photostream/lightbox';
            }
            $ris .= '<a href="' . $photos_url[$photo_owner] . $photo['id'] . $photos_url_in . '" ';
            if ($target_blank) {
                $ris .= 'target="_blank" ';
            }
            $ris .= 'title="' . $photo['title'] . '">';
        }
        $ris .= '<img alt="' . htmlspecialchars($photo['title'], ENT_QUOTES, 'UTF-8') . '" src="' . $f->buildPhotoURL($photo, $imgSize) . '" data-safe-src="' . $f->buildPhotoURL($photo, $imgSize) . '" /></a>';
    }
    $ris .= '</div>' . '<script type="text/javascript">';
    if ($block_contextmenu) {
        $ris .= '	function fpDisableContextMenu(imgs) {
								function absorbEvent_(event) {
									var e = event || window.event;
									e.preventDefault && e.preventDefault();
									e.stopPropagation && e.stopPropagation();
									e.cancelBubble = true;
									e.returnValue = false;
									return false;
								}

								imgs.on("contextmenu", absorbEvent_);
								imgs.on("ontouchstart", absorbEvent_);
								imgs.on("ontouchmove", absorbEvent_);
								imgs.on("ontouchend", absorbEvent_);
								imgs.on("ontouchcancel", absorbEvent_);
							}';
    }
    $ris .= 'jQuery(document).ready(function(){ jQuery("#flickrGal' . $shortcode_unique_id . '")';
    if ($lightbox === 'colorbox') {
        $ris .= '.on(\'jg.rowflush\', function() {
							jQuery(this).find("> a").colorbox({
								maxWidth : "85%",
								maxHeight : "85%",
								current : "",';
        if ($block_contextmenu) {
            $ris .= '	onComplete: function() {
										fpDisableContextMenu(jQuery("#colorbox .cboxPhoto"));
									}';
        }
        $ris .= '});
						})';
    } else {
        if ($lightbox === 'swipebox') {
            $ris .= '	.on(\'jg.complete\', function() {
								jQuery("#flickrGal' . $shortcode_unique_id . '").find("> a").swipebox({
										afterOpen : function () { 
											setTimeout(function() {
												fpDisableContextMenu(jQuery("#swipebox-overlay .slide img"));
											}, 100);
										}
								});
							})';
        }
    }
    $ris .= '.justifiedGallery({' . '\'lastRow\': \'' . $last_row . '\', ' . '\'rowHeight\':' . $images_height . ', ' . '\'fixedHeight\':' . ($fixed_height ? 'true' : 'false') . ', ' . '\'captions\':' . ($captions ? 'true' : 'false') . ', ' . '\'randomize\':' . ($randomize ? 'true' : 'false') . ', ' . '\'margins\':' . $margins;
    if (!$use_large_thumbnails) {
        $ris .= ', \'sizeRangeSuffixes\': {
								\'lt100\':\'_t\',
								\'lt240\':\'_m\',
								\'lt320\':\'_n\',
								\'lt500\':\'\',
								\'lt640\':\'_z\',
								\'lt1024\':\'_z\'
							}';
    }
    $ris .= '});';
    if ($block_contextmenu) {
        $ris .= 'fpDisableContextMenu(jQuery("#flickrGal' . $shortcode_unique_id . '").find("> a"));';
    }
    $ris .= ' });' . '</script>';
    //Navigation---------------------
    if ($pagination !== 'none') {
        $num_pages = $photos[$photos_main_index]['pages'];
        if ($num_pages > 1) {
            $permalink = get_permalink();
            if ($pagination === 'numbers') {
                $ris .= '<div class="page-links">' . '<span class="page-links-title">Pages:</span> ';
                $low_num = $page_num - floor($maximum_pages_nums / 2);
                $high_num = $page_num + ceil($maximum_pages_nums / 2) - 1;
                if ($low_num < 1) {
                    $high_num += 1 - $low_num;
                    $low_num = 1;
                }
                if ($high_num > $num_pages) {
                    $high_num = $num_pages;
                }
                if ($low_num > 1) {
                    $ris .= '<a href="' . add_query_arg('page', $low_num - 1, $permalink) . '"><span>...</span></a> ';
                }
                for ($i = $low_num; $i <= $high_num; $i++) {
                    if ($i == $page_num) {
                        $ris .= '<span>' . $i . '</span> ';
                    } else {
                        $ris .= '<a href="' . add_query_arg('page', $i, $permalink) . '"><span>' . $i . '</span></a> ';
                    }
                }
                if ($high_num < $num_pages) {
                    $ris .= '<a href="' . add_query_arg('page', $high_num + 1, $permalink) . '"><span>...</span></a> ';
                }
                $ris .= '</div>';
            } else {
                if ($pagination === 'prevnext') {
                    $ris .= '<div>';
                    if ($page_num < $num_pages) {
                        $ris .= '<div class="nav-previous">' . '<a href="' . add_query_arg('page', (int) $page_num + 1, $permalink) . '">' . __('<span class="meta-nav">&larr;</span> Older photos', 'flickr-photostream') . '</a>' . '</div>';
                    }
                    if ($page_num > 1) {
                        //a link to the newer photos
                        $ris .= '<div class="nav-next">' . '<a href="' . add_query_arg('page', (int) $page_num - 1, $permalink) . '">' . __('Newer photos <span class="meta-nav">&rarr;</span>', 'flickr-photostream') . '</a>' . '</div>';
                    }
                    $ris .= '</div>';
                }
            }
        }
    }
    $shortcode_unique_id++;
    return $ris;
}
Esempio n. 8
0
if (!empty($username)) {
    $temp_user = get_user_by_username($username);
} else {
    $temp_user = get_loggedin_user();
}
$flickr_username = get_metadata_byname($temp_user->guid, "flickr_username");
if (empty($flickr_username)) {
    register_error("No Flickr username set");
    echo "<pre>No flickr username set: {$temp_user->guid}";
    die;
    forward("/");
    die;
}
$flickr_user = $f->people_findByUsername($flickr_username->value);
// Get the friendly URL of the user's photos
$photos_url = $f->urls_getUserPhotos($flickr_user["id"]);
if (!empty($flickr_user)) {
    $recent = $f->people_getPublicPhotos($flickr_user['id'], NULL, NULL, 5);
} else {
    echo "user not found";
    die;
}
//echo "<pre>"; var_dump( $recent ); echo "</pre>";
//echo "<pre>"; var_dump( $user ); echo "</pre>";
$body = elgg_view_title("Flickr photos for {$flickr_user['username']}");
$count = 0;
foreach ($recent['photos']['photo'] as $photo) {
    $photo_info = $f->photos_getInfo($photo["id"], $photo["secret"]);
    $body .= "<div class='tidypics_album_images'>";
    $body .= "{$photo_info['title']}<br />Views: {$photo_info['views']}<br />";
    $body .= "<a href={$photos_url}{$photo['id']}>";
Esempio n. 9
0
 public function retornaGaleriaflickr()
 {
     $site = site_dados();
     require_once "flickr/phpFlickr.php";
     $f = new phpFlickr("KEY", "SECRET");
     $person = $f->people_findByUsername($flickr_channel);
     // Get the friendly URL of the user's photos
     $photos_url = $f->urls_getUserPhotos($person['id']);
     // Get the user's first 36 public photos
     $photos = $f->people_getPublicPhotos($person['id'], NULL, NULL, 9);
     $i = 0;
     foreach ((array) $photos['photos']['photo'] as $photo) {
         $retorno[$i]['photo'] = $photo;
         $retorno[$i]['photos_url'] = $photos_url;
         $retorno[$i]['url']['square'] = $f->buildPhotoURL($photo, "square");
         $retorno[$i]['url']['thumbnail'] = $f->buildPhotoURL($photo, "thumbnail");
         $retorno[$i]['url']['small'] = $f->buildPhotoURL($photo, "small");
         $retorno[$i]['url']['medium'] = $f->buildPhotoURL($photo, "medium");
         $retorno[$i]['url']['large'] = $f->buildPhotoURL($photo, "large");
         $retorno[$i]['url']['original'] = $f->buildPhotoURL($photo, "original");
         $i++;
     }
     return $retorno;
 }
function fjgwpp_createGallery($action, $atts)
{
    global $fjgwpp_imagesHeight_default;
    global $fjgwpp_maxPhotosPP_default;
    global $fjgwpp_lastRow_default;
    global $fjgwpp_fixedHeight_default;
    global $fjgwpp_pagination_default;
    global $fjgwpp_lightbox_default;
    global $fjgwpp_captions_default;
    global $fjgwpp_showDescriptions_default;
    global $fjgwpp_randomize_default;
    global $fjgwpp_margins_default;
    global $fjgwpp_openOriginals_default;
    global $fjgwpp_bcontextmenu_default;
    global $fjgwpp_flickrAPIWrapperVersion_default;
    static $shortcode_unique_id = 0;
    $ris = "";
    $page_num = get_query_var('page') ? get_query_var('page') : 1;
    $flickrGalID = 'flickrGal' . $shortcode_unique_id;
    //Options-----------------------
    extract(shortcode_atts(array('user_id' => fjgwpp_getOption('userID'), 'id' => NULL, 'tags' => NULL, 'tags_mode' => 'any', 'images_height' => fjgwpp_getOption('imagesHeight', $fjgwpp_imagesHeight_default), 'max_num_photos' => fjgwpp_getOption('maxPhotosPP', $fjgwpp_maxPhotosPP_default), 'last_row' => fjgwpp_getOption('lastRow', $fjgwpp_lastRow_default), 'fixed_height' => fjgwpp_getOption('fixedHeight', $fjgwpp_fixedHeight_default) == 1, 'lightbox' => fjgwpp_getOption('lightbox', $fjgwpp_lightbox_default), 'captions' => fjgwpp_getOption('captions', $fjgwpp_captions_default) == 1, 'show_descriptions' => fjgwpp_getOption('showDescriptions', $fjgwpp_showDescriptions_default) == 1, 'randomize' => fjgwpp_getOption('randomize', $fjgwpp_randomize_default) == 1, 'pagination' => fjgwpp_getOption('pagination', $fjgwpp_pagination_default), 'margins' => fjgwpp_getOption('margins', $fjgwpp_margins_default), 'open_originals' => fjgwpp_getOption('openOriginals', $fjgwpp_openOriginals_default) == 1, 'block_contextmenu' => fjgwpp_getOption('bcontextmenu', $fjgwpp_bcontextmenu_default) == 1, 'flickrAPIWrapperVersion' => fjgwpp_getOption('flickrAPIWrapperVersion', $fjgwpp_flickrAPIWrapperVersion_default) == 0), $atts));
    //Trim string options
    $user_id = trim($user_id);
    $id = trim($id);
    $lightbox = trim($lightbox);
    $last_row = trim($last_row);
    if ($flickrAPIWrapperVersion == 0) {
        require_once "phpFlickr/phpFlickr.php";
    } else {
        require_once "phpFlickr_a" . $flickrAPIWrapperVersion . "/phpFlickr.php";
    }
    //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 = trim(fjgwpp_getOption('APIKey'));
    //Flickr API Key
    $flickrAPISecret = trim(fjgwpp_getOption('APISecret'));
    //Flickr API Secret
    $flickrAPIToken = trim(fjgwpp_getOption('APIToken'));
    //Flickr API Token
    if ($flickrAPISecret && $flickrAPIToken) {
        // fully authenticated call
        $f = new phpFlickr($flickrAPIKey, $flickrAPISecret);
        $f->setToken($flickrAPIToken);
        $f->auth("read");
    } else {
        // standard call
        $f = new phpFlickr($flickrAPIKey);
    }
    $upload_dir = wp_upload_dir();
    $f->enableCache("fs", $upload_dir['basedir'] . "/phpFlickrCache");
    $photos_url = array();
    $photos = array();
    $photos_main_index = '';
    $maximum_pages_nums = 10;
    //TODO configurable?
    //Errors-----------------------
    if ($action === 'phs' || $action === 'gal' || $action === 'tag') {
        if (!isset($user_id) || strlen($user_id) == 0) {
            return fjgwpp_formatError(__('You must specify the user_id for this action, using the "user_id" attribute', 'fjgwpp'));
        }
    }
    if ($action === 'gal') {
        if (!isset($id) || strlen($id) == 0) {
            return fjgwpp_formatError(__('You must specify the id of the gallery, using the "id" attribute', 'fjgwpp'));
        }
    }
    if ($action === 'set') {
        if (!isset($id) || strlen($id) == 0) {
            return fjgwpp_formatError(__('You must specify the id of the set, using the "id" attribute', 'fjgwpp'));
        }
    }
    if ($action === 'tag') {
        if (!isset($tags) || strlen($tags) == 0) {
            return fjgwpp_formatError(__('You must specify the tags using the "tags" attribute', 'fjgwpp'));
        }
        if ($tags_mode !== 'any' && $tags_mode !== 'all') {
            return fjgwpp_formatError(__('You must specify a valid tags_mode: "any" or "all"', 'fjgwpp'));
        }
    }
    if ($action === 'grp') {
        if (!isset($id) || strlen($id) == 0) {
            return fjgwpp_formatError(__('You must specify the id of the group, using the "id" attribute', 'fjgwpp'));
        }
    }
    if ($pagination !== 'none' && $pagination !== 'prevnext' && $pagination !== 'numbers') {
        return fjgwpp_formatError(__('The pagination attribute can be only "none", "prevnext" or "numbers".', 'fjgwpp'));
    }
    if ($last_row !== 'hide' && $last_row !== 'justify' && $last_row !== 'nojustify') {
        return fjgwpp_formatError(__('The last_row attribute can be only "hide", "justify" or "nojustify".', 'fjgwpp'));
    }
    if ($lightbox !== 'none' && $lightbox !== 'colorbox' && $lightbox !== 'swipebox') {
        return fjgwpp_formatError(__('The lightbox attribute can be only "none", "colorbox" or "swipebox".', 'fjgwpp'));
    }
    //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, NULL, $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 fjgwpp_formatFlickrAPIError($f->getErrorMsg());
            }
            $gallery_info = $f->urls_lookupGallery($photos_url[$user_id] . 'galleries/' . $id);
            if ($f->getErrorCode() != NULL) {
                return fjgwpp_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 fjgwpp_formatFlickrAPIError($f->getErrorMsg());
    }
    $photos_pool = $photos[$photos_main_index];
    if (count((array) $photos_pool['photo']) == 0) {
        return __('No photos', 'fjgwpp');
    }
    //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 .= '<!-- Flickr Justified Gallery Wordpress Plugin by Miro Mannino -->' . "\n" . '<div id="' . $flickrGalID . '" class="justified-gallery" >';
    $r = 0;
    $use_large_thumbnails = true;
    foreach ($photos_pool['photo'] as $photo) {
        if (!isset($photo['url_l'])) {
            $use_large_thumbnails = false;
        }
        fjgwpp_entryLink($id, $f, $ris, $photo, $photos_pool, $photos_url, $lightbox, $open_originals, $flickrGalID, $action);
        $ris .= '<img alt="' . htmlspecialchars($photo['title'], ENT_QUOTES, 'UTF-8') . '" src="' . $f->buildPhotoURL($photo, $imgSize) . '" data-safe-src="' . $f->buildPhotoURL($photo, $imgSize) . '" />';
        if ($captions) {
            $ris .= '<div class="caption">' . '<div class="photo-title' . ($show_descriptions ? ' photo-title-with-desc' : '') . '">' . htmlspecialchars($photo['title'], ENT_QUOTES, 'UTF-8') . '</div>';
            if ($show_descriptions && isset($photo['description']) && isset($photo['description']['_content'])) {
                $ris .= '<div class="photo-desc">' . fjgwpp_filterDescription($photo['description']['_content']) . '</div>';
            }
            $ris .= '</div>';
        }
        $ris .= '</a>';
        //end link
    }
    $ris .= '</div>' . '<script type="text/javascript">';
    $ris .= 'function fjgwppInit_' . $flickrGalID . '() {
				jQuery("#' . $flickrGalID . '")';
    if ($lightbox === 'colorbox') {
        $ris .= '.on(\'jg.rowflush jg.complete\', function() {
					jQuery(this).find("> a").colorbox({
						title:function() {
        					var tit= \'<div class="boxTitle">\'+jQuery(this).find(\'.photo-title\').html()+\'</div>\';
        					var cap =\'<div class="boxCaption">\'+jQuery(this).find(\'.photo-desc\').html()+\'</div>\';
        					return tit+cap;
        				},
						maxWidth : "85%",
						maxHeight : "85%",
						current : "",';
        if ($block_contextmenu) {
            $ris .= 'onComplete: function() {
							fjgwppDisableContextMenu(jQuery("#colorbox .cboxPhoto"));
						}';
        }
        $ris .= '});
				})';
    } else {
        if ($lightbox === 'swipebox') {
            $ris .= '.on(\'jg.complete\', function() {
					jQuery("#' . $flickrGalID . '").find("> a").swipebox(';
            if ($block_contextmenu) {
                $ris .= '{
						afterOpen : function () {
							setTimeout(function() {
								fjgwppDisableContextMenu(jQuery("#swipebox-overlay .slide img"));
							}, 100);
						}
					}';
            }
            $ris .= ');
				})';
        }
    }
    $ris .= '.justifiedGallery({' . '\'lastRow\': \'' . $last_row . '\', ' . '\'rowHeight\':' . $images_height . ', ' . '\'fixedHeight\':' . ($fixed_height ? 'true' : 'false') . ', ' . '\'captions\':' . ($captions ? 'true' : 'false') . ', ' . '\'randomize\':' . ($randomize ? 'true' : 'false') . ', ' . '\'margins\':' . $margins . ', ' . '\'sizeRangeSuffixes\': {
			 			\'lt100\':\'_t\', \'lt240\':\'_m\', \'lt320\':\'_n\',
						\'lt500\':\'\', \'lt640\':\'_z\',' . ($use_large_thumbnails ? '\'lt1024\':\'_b\'' : '\'lt1024\':\'_z\'') . '}});';
    if ($block_contextmenu) {
        $ris .= 'fpDisableContextMenu(jQuery("#' . $flickrGalID . '").find("> a"));';
    }
    $ris .= '}' . 'if (typeof fjgwpp_galleriesInit_functions === "undefined") fjgwpp_galleriesInit_functions = [];' . 'fjgwpp_galleriesInit_functions.push(fjgwppInit_' . $flickrGalID . ');' . '</script>';
    //Navigation---------------------
    if ($pagination !== 'none') {
        $num_pages = $photos[$photos_main_index]['pages'];
        if ($num_pages > 1) {
            $permalink = get_permalink();
            if ($pagination === 'numbers') {
                $ris .= '<div class="page-links">' . '<span class="page-links-title">Pages:</span> ';
                $low_num = $page_num - floor($maximum_pages_nums / 2);
                $high_num = $page_num + ceil($maximum_pages_nums / 2) - 1;
                if ($low_num < 1) {
                    $high_num += 1 - $low_num;
                    $low_num = 1;
                }
                if ($high_num > $num_pages) {
                    $high_num = $num_pages;
                }
                if ($low_num > 1) {
                    $ris .= '<a href="' . add_query_arg('page', $low_num - 1, $permalink) . '"><span>...</span></a> ';
                }
                for ($i = $low_num; $i <= $high_num; $i++) {
                    if ($i == $page_num) {
                        $ris .= '<span>' . $i . '</span> ';
                    } else {
                        $ris .= '<a href="' . add_query_arg('page', $i, $permalink) . '"><span>' . $i . '</span></a> ';
                    }
                }
                if ($high_num < $num_pages) {
                    $ris .= '<a href="' . add_query_arg('page', $high_num + 1, $permalink) . '"><span>...</span></a> ';
                }
                $ris .= '</div>';
            } else {
                if ($pagination === 'prevnext') {
                    $ris .= '<div>';
                    if ($page_num < $num_pages) {
                        $ris .= '<div class="nav-previous">' . '<a href="' . add_query_arg('page', (int) $page_num + 1, $permalink) . '">' . __('<span class="meta-nav">&larr;</span> Older photos', 'fjgwpp') . '</a>' . '</div>';
                    }
                    if ($page_num > 1) {
                        //a link to the newer photos
                        $ris .= '<div class="nav-next">' . '<a href="' . add_query_arg('page', (int) $page_num - 1, $permalink) . '">' . __('Newer photos <span class="meta-nav">&rarr;</span>', 'fjgwpp') . '</a>' . '</div>';
                    }
                    $ris .= '</div>';
                }
            }
        }
    }
    $shortcode_unique_id++;
    return $ris;
}
Esempio n. 11
0
require_once dirname(dirname(__FILE__)) . "/lib/phpFlickr/phpFlickr.php";
$f = new phpFlickr("26b2abba37182aca62fe0eb2c7782050");
$set_id = get_input("set_id");
$album_id = get_input("album_id");
$page_pp = get_input("page");
$return_url = get_input("return_url");
$user = get_loggedin_user();
$flickr_id = get_metadata_byname($user->guid, "flickr_id");
if (empty($flickr_id)) {
    register_error(elgg_echo('flickr:errorusername2'));
    forward($return_url);
    die;
    //just in case
}
// Get the friendly URL of the user's photos
$photos_url = $f->urls_getUserPhotos($flickr_id->value);
$photos = $f->photosets_getPhotos($set_id, null, null, 10, $page_pp);
$photos_to_upload = array();
foreach ($photos["photoset"]["photo"] as $photo) {
    //check if we already have this image
    $meta = get_metadata_byname($user->guid, $photo["id"]);
    /*
    	if ($meta->value == 1) { //we've downloaded this already
    		register_error( elgg_echo( 'flickr:errorimageimport' ));
    		continue;
    	} */
    /* Disabled By Rijo Joy  */
    //store this so we don't download the same photo multiple times
    create_metadata($user->guid, $photo["id"], "1", "text", $user->guid, ACCESS_PUBLIC);
    $photo_info = $f->photos_getInfo($photo["id"], $photo["secret"]);
    $tags = array();
Esempio n. 12
0
<?php

require_once "phpFlickr.php";
$phpFlickrObj = new phpFlickr('665302ccbe82f5ae7aa2328d7ce4f886');
$user = $phpFlickrObj->people_findByUsername('codemastersnake');
$user_url = $phpFlickrObj->urls_getUserPhotos($user['id']);
$photos = $phpFlickrObj->people_getPublicPhotos($user['id'], NULL, NULL, 4);
foreach ($photos['photos']['photo'] as $photo) {
    echo '<a href="' . $user_url . $photo['id'] . '" title="' . $photo['title'] . ' (on Flickr)" target="_blank">';
    echo '<img style="border:1px solid" alt="' . $photo['title'] . '" src="' . $phpFlickrObj->buildPhotoURL($photo, "square") . '" />';
    echo '</a>';
}
Esempio n. 13
0
    function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
        $username = esc_attr($instance['username']);
        $api_key = esc_attr($instance['api_key']);
        $nos = esc_attr($instance['nos']);
        echo $before_widget;
        include HPATH . "/lib/phpFlickr.php";
        if ($title != "") {
            echo $before_title . " " . $title . $after_title;
        }
        if (!$api_key) {
            echo '<h4> No API KEY ADDED </h4>';
        } else {
            $f = new phpFlickr($api_key);
            $person = $f->people_findByUsername($username);
            $photos_url = $f->urls_getUserPhotos($person['id']);
            $photos = $f->people_getPublicPhotos($person['id'], NULL, NULL, 16);
            ?>
        <div class="flickr-pictures clearfix">
        <?php 
            $i = 0;
            foreach ((array) $photos['photos']['photo'] as $photo) {
                if ($i >= $nos) {
                    break;
                }
                $theImageSrc = $f->buildPhotoURL($photo, "thumbnail");
                $lb = $f->buildPhotoURL($photo, "large");
                echo "<a href='" . $lb . "' class='lightbox' rel='prettyPhoto[pp_gal]' title='{$photo['title']}' ><img src='" . $theImageSrc . "' alt=\"" . $photos_url . $photo["id"] . "\" title='' /></a>";
                $i++;
            }
            ?>
        </div>



        <?php 
        }
        echo $after_widget;
    }
Esempio n. 14
0
<?php

require_once "phpFlickr/phpFlickr.php";
$f = new phpFlickr("44449d9d74ed80abe095ab2a6f137dbe", "abde3a1309b8d8e1");
/*
$f->enableCache(
	"db",
	"mysql://[username]:[password]@[server]/[database]"
);
*/
$photos_url = $f->urls_getUserPhotos('28973605@N00');
$photos = $f->people_getPublicPhotos('28973605@N00', NULL, NULL, 11);
$sets = $f->photosets_getList('28973605@N00');
?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="./css/reset-min.css" type="text/css" media="screen" /> 
<link rel="stylesheet" href="./css/style.css" type="text/css" media="screen" />
<link rel="stylesheet" href="./css/jquery.lightbox-0.5.css" type="text/css" media="screen" />
<title>上禾友</title>
<script type="text/javascript" src="./js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="./js/jquery.lightbox-0.5.min.js"></script>
<script type="text/javascript">
(function() {
	$(document).ready(function() {
		$('#gallery a').lightBox({fixedNavigation:true});
		$('.setBox a.more').click(function() {
			alert($(this).attr('set_id'));
			return false;
 function generate_content(&$title)
 {
     global $serendipity;
     $title = $this->get_config('title');
     $username = $this->get_config('email');
     $num = $this->get_config('perpage');
     $choices = $this->get_config('numberOfChoices');
     //added 110730 by artodeto
     $useChoices = $this->get_config('useChoices');
     //added 110730 by artodeto
     $apiKey = $this->get_config('apikey');
     $apiSecret = $this->get_config('apisecret');
     $sourceimgtype = $this->get_config('sourceimgtype');
     $targetimgtype = $this->get_config('targetimgtype');
     $errors = array();
     /* 		Get image data from flickr */
     $f = new phpFlickr($apiKey, $apiSecret);
     $f->enableCache("fs", $serendipity['serendipityPath'] . 'templates_c/', $this->get_config('cachetimeout'));
     if (stristr($username, '@')) {
         $nsid = $f->people_findByEmail($username);
     } else {
         $nsid = $f->people_findByUsername($username);
     }
     if ($nsid === false) {
         $errors[] = PLUGIN_SIDEBAR_FLICKR_ERROR_WRONGUSER;
     }
     /* Can't find user */
     $photos_url = $f->urls_getUserPhotos($nsid['nsid']);
     if ($useChoices === true) {
         $photos = $f->photos_search(array("user_id" => $nsid['nsid'], "per_page" => $choices, "sort" => "date-posted-desc", "extras" => "date_taken"));
     } else {
         $photos = $f->photos_search(array("user_id" => $nsid['nsid'], "per_page" => $num, "sort" => "date-posted-desc", "extras" => "date_taken"));
     }
     if ($photos[total] > 0 && $f) {
         $sizelist = array("0" => "Square", "1" => "Thumbnail", "2" => "Small", "3" => "Medium", "4" => "Large", "5" => "Original");
         if ($useChoices === true) {
             //added 110730 by artodeto
             shuffle($photos['photo']);
             array_splice($photos['photo'], $num);
         }
         foreach ($photos['photo'] as $photo) {
             if ($photo['ispublic'] !== 1) {
                 continue;
             }
             $imgdate = strftime("%d.%m.%y %H:%M", strtotime($photo['datetaken']));
             $imgtitle = $photo['title'];
             /* 				Choose available image size */
             $sizes_available = $f->photos_getSizes($photo[id]);
             $photosize = $sourceimgtype;
             $imgsrcdata = NULL;
             while ($imgsrcdata == NULL && $photosize >= 0) {
                 $imgsrcdata = getsizedata($sizes_available, $sizelist[$photosize]);
                 $photosize--;
             }
             /* If updating from previous versions, $targetimgtype could be -1. So we set it to the next legal value 2. */
             $photosize = max($targetimgtype, 2);
             $imgtrgdata = NULL;
             while ($imgtrgdata == NULL && $photosize >= 0) {
                 $imgtrgdata = getsizedata($sizes_available, $sizelist[$photosize]);
                 $photosize--;
             }
             $img_width = $imgsrcdata['width'];
             $img_height = $imgsrcdata['height'];
             $img_url = $imgsrcdata['source'];
             if ($this->get_config('targetlink') == "JPG") {
                 $link_url = $imgtrgdata['source'];
             } else {
                 $link_url = $imgtrgdata['url'];
             }
             if ($this->get_config('showdate') || $this->get_config('showtitle')) {
                 unset($info);
                 if ($this->get_config('showdate')) {
                     $info .= '<span class="serendipity_plugin_flickr_date">' . $imgdate . '</span>';
                 }
                 if ($this->get_config('showtitle')) {
                     $info .= '<span class="serendipity_plugin_flickr_title">' . $imgtitle . '</span>';
                 }
                 if ($this->get_config('lightbox') != '') {
                     $lightbox = 'rel="' . $this->get_config('lightbox') . '" ';
                 }
                 $images .= sprintf('<dd style="width:%spx;"><a %shref="%s" ><img src="%s" width="%s" height="%s" title="%s" alt="%s"/></a></dd><dt style="width:%spx;margin-left:-%spx;">%s</dt>' . "\n", $img_width, $lightbox, $link_url, $img_url, $img_width, $img_height, $photo[title], $photo[title], $img_width, $img_width + 5, $info);
             } else {
                 $images .= sprintf('<dd style="width:%spx;"><a href="%s"><img src="%s" width="%s" height="%s" alt="%s"/></a></dd>' . "\n", $img_width, $link_url, $img_url, $img_width, $img_height, $photo[title]);
             }
             $i++;
         }
     } else {
         $errors[] = PLUGIN_SIDEBAR_FLICKR_ERROR_NOIMG;
         /* No images available */
     }
     $content = '<dl class="serendipity_plugin_flickr">' . "\n";
     $content .= "\n" . $images;
     $content .= '</dl>';
     $footer = array();
     if ($this->get_config('showrss')) {
         $rssicon = serendipity_getTemplateFile('img/xml.gif');
         $footer[] = '<a class="serendipity_xml_icon" href="http://api.flickr.com/services/feeds/photos_public.gne?id=' . $nsid['nsid'] . '&amp;format=rss_200"><img src="' . $rssicon . '" alt="XML" style="border: 0px" /></a>' . "\n" . '<a href="http://api.flickr.com/services/feeds/photos_public.gne?id=' . $nsid['nsid'] . '&amp;format=rss_200">' . PLUGIN_SIDEBAR_FLICKR_LINK_SHOWRSS . '</a>';
     }
     if ($this->get_config('showphotostream')) {
         $footer[] = '<a href="http://www.flickr.com/photos/' . $username . '/">' . PLUGIN_SIDEBAR_FLICKR_LINK_PHOTOSTREAM . '</a>';
     }
     if (count($footer) > 0) {
         $content .= '<p class="serendipity_plugin_flickr_links">';
         $content .= join("<br />\n", $footer) . "\n";
         $content .= '</p>';
     }
     if (count($errors) > 0) {
         $content .= '<p class="serendipity_plugin_flickr_errors">';
         $content .= join("<br />\n", $errors) . "\n";
         $content .= '</p>';
     }
     echo $content;
 }
    function event_hook($event, &$bag, &$eventData, $addData = null)
    {
        global $serendipity;
        $hooks =& $bag->get('event_hooks');
        if (isset($hooks[$event])) {
            switch ($event) {
                // called when admin sidebar is being "built"
                case 'backend_sidebar_entries_images':
                    ?>
<li class="serendipitySideBarMenuLink serendipitySideBarMenuMediaLinks"><a href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=flickr">
                        <?php 
                    echo PLUGIN_EVENT_FLICKR_NAME;
                    ?>
</a></li><?php 
                    break;
                    // called when admin sidebar is been "drawn"
                // called when admin sidebar is been "drawn"
                case 'backend_sidebar_entries_event_display_flickr':
                    // he, is user allowed to import images ?!?
                    if (!serendipity_checkPermission('adminImagesAdd')) {
                        // TODO: add a message to the user ?!?
                        break;
                    }
                    // if method is POST, we must have a valid form token !
                    if ($_SERVER['REQUEST_METHOD'] == 'POST' && !serendipity_checkFormToken()) {
                        // TODO: add a message to the user ?!?
                        break;
                    }
                    ?>
                <?php 
                    echo PLUGIN_EVENT_FLICKR_IMPORT_BLAHBLAH;
                    ?>
                <script type="text/javascript">
                function flickr_showPage(p) {
                    var f = document.getElementById('flickr_uploadform');
                    f.elements['serendipity[flickr_page]'].value = p;
                    f.submit();
                }
                function flickr_doImport(url) {
                    var f = document.getElementById('flickr_uploadform');
                    f.elements['serendipity[adminModule]'].value = 'images';
                    f.elements['serendipity[adminAction]'].value = 'add';
                    f.elements['serendipity[imageurl]'].value = url;
                    f.submit();
                }
                function flickr_toggleExtended() {
                    var d = document.getElementById('flickr_extendedCriteria');
                    d.style.display = (d.style.display != '') ? '' : 'none';
                }
                </script>
                <h3><? echo PLUGIN_EVENT_FLICKR_IMPORT; ?></h3>
                <form action="?" method="POST" id="flickr_uploadform" enctype="multipart/form-data" onsubmit="">
                    <?php 
                    echo serendipity_setFormToken();
                    ?>
                    <?php 
                    // these two fields will only be used when an image has been chosen for dl
                    ?>
                    <input type="hidden" name="serendipity[imageurl]" value="" />
                    <input type="hidden" name="serendipity[imageimporttype]" value="image" />

                    <input type="hidden" name="serendipity[action]"      value="admin" />
                    <input type="hidden" name="serendipity[adminModule]" value="event_display" />
                    <input type="hidden" name="serendipity[adminAction]" value="flickr" />

                    <input type="hidden" name="serendipity[flickr_page]" value="1" />
                    Flickr username: <input class="input_textbox" name="serendipity[flickr_username]" value="<?php 
                    echo function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['flickr_username']) : htmlspecialchars($serendipity['POST']['flickr_username'], ENT_COMPAT, LANG_CHARSET);
                    ?>
" />
                    <input type="submit" value="<?php 
                    echo GO;
                    ?>
" class="serendipityPrettyButton input_button" /><br /><br />
                    <a style="border: 0pt none ; text-decoration: none;" href="#" onclick="flickr_toggleExtended(); return false"
                         title="<?php 
                    echo TOGGLE_OPTION;
                    ?>
">
                    <img border="0" src="<?php 
                    echo serendipity_getTemplateFile('img/plus.png');
                    ?>
" /> <?php 
                    echo TOGGLE_ALL;
                    ?>
</a>
                    <div id="flickr_extendedCriteria" <?php 
                    echo strlen($serendipity['POST']['flickr_username']) ? '' : 'style="display:none;"';
                    ?>
>
                        <p><?php 
                    echo PLUGIN_EVENT_FLICKR_TAGS;
                    ?>
 <input class="input_textbox" name="serendipity[flickr_tags]" value="<?php 
                    echo function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['flickr_tags']) : htmlspecialchars($serendipity['POST']['flickr_tags'], ENT_COMPAT, LANG_CHARSET);
                    ?>
" />
                        <?php 
                    echo PLUGIN_EVENT_FLICKR_KEYWORDS;
                    ?>
 <input class="input_textbox" name="serendipity[flickr_keywords]" value="<?php 
                    echo function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['flickr_keywords']) : htmlspecialchars($serendipity['POST']['flickr_keywords'], ENT_COMPAT, LANG_CHARSET);
                    ?>
" size="30" /></p>
                        <?php 
                    echo SORT_BY;
                    ?>
 <select id="flickr_sort" name="serendipity[flickr_sort]">
                        <option value=""></option>
                        <?
                            // See API for details (http://www.flickr.com/services/api/flickr.photos.search.html)
                            $flickr_goodSortOrders = array(
                                'date-posted-asc'=>'By date of post, ascending',
                                'date-posted-desc'=>'By date of post, descending',
                                'date-taken-asc'=>'By date of take, ascending',
                                'date-taken-desc'=>'By date of take, descending',
                                'interestingness-asc'=>'By interestingness, ascending',
                                'interestingness-desc'=>'By interestingness, ascending',
                                'relevance'=>'By revelance'
                            );

                            // compute sort order
                            $sortOrder = (isset($serendipity['POST']['flickr_keywords']) &&
                                array_key_exists($serendipity['POST']['flickr_keywords'], $flickr_goodSortOrders) ?
                                (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['flickr_keywords']) : htmlspecialchars($serendipity['POST']['flickr_keywords'], ENT_COMPAT, LANG_CHARSET)) : '');

                            // display possible options for sort order
                            foreach($flickr_goodSortOrders as $value => $description) {
                                echo '<option value="'.$value.'"';
                                if($sortOrder == $value) echo(' selected="true"');
                                echo '>'.$description.'</option>';
                            }
                        ?>
                        </select>
                    </div>
                </form>
                <?php 
                    // in the second step, we show latest photos (thumbs) for given username
                    if ($serendipity['POST']['adminAction'] == 'flickr') {
                        // make use of phpFlikr lib (http://www.phpflickr.com/)
                        require_once dirname(__FILE__) . '/phpFlickr/phpFlickr.php';
                        $f = new phpFlickr($this->get_config('api_key'));
                        $i = 0;
                        if (!empty($serendipity['POST']['flickr_username'])) {
                            // Find the NSID of the username inputted via the form
                            $nsid = $f->people_findByUsername($serendipity['POST']['flickr_username']);
                            // Get the friendly URL of the user's photos
                            $photos_url = $f->urls_getUserPhotos($nsid);
                            echo '<h4 style="margin-bottom: 0; padding-bottom: 0;">Photos of <em>';
                            echo (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['flickr_username']) : htmlspecialchars($serendipity['POST']['flickr_username'], ENT_COMPAT, LANG_CHARSET)) . '</em> at ';
                            echo '<a href="' . $photos_url . '" target="_blank">' . $photos_url . '</a></h4>';
                            // default page is number one
                            if (empty($serendipity['POST']['flickr_page']) || !is_numeric($serendipity['POST']['flickr_page'])) {
                                $serendipity['POST']['flickr_page'] = 1;
                            }
                            // make sure page is a number between 1 and 500 (range allowed by flickr API)
                            $serendipity['POST']['flickr_page'] = min(500, max(1, (int) $serendipity['POST']['flickr_page']));
                            echo '<h5 style="margin-top: 0; padding-top: 0;">Displaying page ' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['flickr_page']) : htmlspecialchars($serendipity['POST']['flickr_page'], ENT_COMPAT, LANG_CHARSET)) . '</h5>';
                            // Search is made depending on selected criterias
                            $searchCriteria = array();
                            // make sure sort order is non empty AND valid
                            if (isset($serendipity['POST']['flickr_sort']) && strlen(trim($serendipity['POST']['flickr_sort'])) && array_key_exists($serendipity['POST']['flickr_keywords'], $flickr_goodSortOrders)) {
                                $searchCriteria['sort'] = function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['flickr_sort']) : htmlspecialchars($serendipity['POST']['flickr_sort'], ENT_COMPAT, LANG_CHARSET);
                            }
                            // TODO: clean up tags of unwanted characters (keep only [a-zA-Z0-9_-])
                            if (isset($serendipity['POST']['flickr_tags']) && strlen(trim($serendipity['POST']['flickr_tags']))) {
                                $searchCriteria['tags'] = implode(',', explode(' ', function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['flickr_tags']) : htmlspecialchars($serendipity['POST']['flickr_tags'], ENT_COMPAT, LANG_CHARSET)));
                            }
                            // TODO: cleanup keywords
                            if (isset($serendipity['POST']['flickr_keywords']) && strlen(trim($serendipity['POST']['flickr_keywords']))) {
                                $searchCriteria['text'] = function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['flickr_keywords']) : htmlspecialchars($serendipity['POST']['flickr_keywords'], ENT_COMPAT, LANG_CHARSET);
                            }
                            if (count($searchCriteria)) {
                                // It seems the user wants an advanced search
                                $searchCriteria['user_id'] = $nsid;
                                $photos = $f->photos_search($searchCriteria);
                            } else {
                                // No extra criteria, get the user's next 12 public photos (+1 to show > next or not !)
                                $photos = $f->people_getPublicPhotos($nsid, NULL, 13, $serendipity['POST']['flickr_page']);
                                // Get user's tags (if any)
                                /*$tags = $f->tags_getListUser($nsid);
                                  if(is_array($tags['tags']['tag'])) {
                                      echo implode(',', $tags['tags']['tag']);
                                      echo "<br />\n";
                                  }*/
                            }
                            // Loop through the photos and output the html
                            foreach ($photos['photo'] as $photo) {
                                echo '<a title="Add to library" href="javascript:flickr_doImport(\'' . $f->buildPhotoURL($photo, 'Original') . '\');" ';
                                echo 'onclick="return confirm(\'Import this photo into the media library ?\');">';
                                echo '<img border="0" alt="' . $photo['title'] . '" src=' . $f->buildPhotoURL($photo, 'Square') . ' />';
                                echo '</a>';
                                // break before the 13th photo (if any)
                                if (++$i == 12) {
                                    break;
                                }
                                // If it reaches the sixth photo, insert a line break
                                if ($i % 6 == 0) {
                                    echo "<br />\n";
                                }
                            }
                            // end foreach
                            echo "<br />\n";
                            // navigate through pages of photos
                            if ($serendipity['POST']['flickr_page'] > 1) {
                                echo '<a href="javascript:flickr_showPage(' . (int) ($serendipity['POST']['flickr_page'] - 1) . ');">Previous</a>';
                            }
                            echo '&nbsp;&nbsp;';
                            if (count($photos['photo']) > 12) {
                                echo '<a href="javascript:flickr_showPage(' . (int) ($serendipity['POST']['flickr_page'] + 1) . ');">Next</a>';
                            }
                        }
                        // end if
                    }
                    // end if
                    return true;
                    break;
                default:
                    return false;
                    break;
            }
        } else {
            return false;
        }
    }
Esempio n. 17
0
<?php

//Include the phpflickr file
require_once "/phpFlickr.php";
//Create new phpFlickr object
$f = new phpFlickr("7ae9545cbd914bc57555aeef73248a98");
//username on flickr
$user = "******";
//Find the NSID of the username
$person = $f->people_findByUsername($user);
echo $person;
// Get the friendly URL of the user's photos (this is the one you can define, not the random numbers with the at sign in it
$photos_url = $f->urls_getUserPhotos($person['id']);
//set the number of photos per page
$photos_per_page = 16;
//set page if there is one, otherwise get the first page
if (0) {
    //$page = $_GET['page'];
} else {
    $page = 1;
}
// Get the user photos based on photos per page and page
$photos = $f->people_getPublicPhotos($person['id'], NULL, $photos_per_page, $page);
//loop photos and titles out
foreach ((array) $photos['photo'] as $photo) {
    //Now for an item.
    $photo_html .= '<div class="left"><a href="' . $photos_url . $photo[id] . '"><img border="0" alt="' . $photo[title] . '" src="' . $f->buildPhotoURL($photo, "square") . '" /></a><br /><p>' . $photo[title] . '</p></div>';
}
//work out HTML for pagination
for ($i = 1; $i < $photos['pages'] + 1; $i++) {
    if ($page != $i) {
Esempio n. 18
0
    function widget($args, $instance)
    {
        extract($args, EXTR_SKIP);
        $tit = empty($instance['tit']) ? '&nbsp;' : strip_tags(apply_filters('widget_tit', $instance['tit']));
        $count = empty($instance['count']) ? '8' : (int) $instance['count'];
        $cols = empty($instance['cols']) ? '4' : (int) $instance['cols'];
        $par3 = empty($instance['par3']) ? '' : $instance['par3'];
        if (empty($instance['username'])) {
        } else {
            ?>

<li class="cb4_flickr widget"><?php 
            if ($tit) {
                echo '<h3 class="tit">' . $tit . '</h3>';
            }
            ?>
 <?php 
            $username = sanitize_text_field($instance['username']);
            require_once "phpFlickr/phpFlickr.php";
            // Create new phpFlickr object
            $f = new phpFlickr("c9df4cb224dd88f2f63a2cf8ef77ed66");
            /*$f->enableCache(
             "db",
             "mysql://[username]:[password]@[server]/[database]"
             );
             */
            $i = 0;
            // Find the NSID of the username inputted via the form
            $person = $f->people_findByUsername($username);
            // Get the friendly URL of the user's photos
            $photos_url = $f->urls_getUserPhotos($person['id']);
            // Get the user's first $count public photos
            $photos = $f->people_getPublicPhotos($person['id'], NULL, NULL, $count);
            //	$photos = $f->photos_search(array("user_id"=>$person['id'],"per_page"=>$count ));
            // Loop through the photos and output the html
            foreach ((array) $photos['photos']['photo'] as $photo) {
                $i++;
                if ($par3 == 'page') {
                    $link = 'href=' . $photos_url . $photo['id'] . ' target="_blank"';
                } else {
                    $link = 'href="' . $f->buildPhotoURL($photo, "large") . '"  data-rel=pp[flickr]';
                }
                if ($i % $cols == 0) {
                    echo "<div class=\"col{$cols} fade\" style=\"margin-right:0;\"><div class=\"fade_c\"><a " . $link . " class=\"flickr_a\"><i class=\"icon-search\"></i></a></div>";
                } else {
                    echo "<div class=\"col{$cols} fade \"><div class=\"fade_c\"><a " . $link . " class=\"flickr_a\"><i class=\"icon-search\"></i></a></div>";
                }
                if ($cols > 2) {
                    echo "<img alt='{$photo['title']}' " . "src=" . $f->buildPhotoURL($photo, "thumbnail") . ">";
                } else {
                    echo "<img border='0' alt='{$photo['title']}' " . "src=" . $f->buildPhotoURL($photo, "") . ">";
                }
                echo "</div>";
                // If it reaches the $cols photo, insert a line break
                if ($i % $cols == 0) {
                    if ($cols != 1) {
                        echo "<div class=\"cl\"></div>";
                    }
                }
            }
            ?>
<div class="cl"></div></li>
<?php 
        }
    }