/** * 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; }
function getValidation($username, $apiKey, $secretKey) { $this->loadPhpFlickrClasses(); $service = new phpFlickr($apiKey, $secretKey); $nsid = $service->people_findByUsername($username); return $nsid; }
function flickrUser($userName) { global $site; $f = new phpFlickr($site["flickr"]["key"]); $f->enableCache("fs", $site["path"] . $site["folder"] . $site["flickr"]["cache"], $site["flickr"]["cacheduration"]); $user = $f->people_findByUsername($userName); return $user; }
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>'; } }
function display() { $flickr = new phpFlickr(ModUtil::getVar('Content', 'flickrApiKey')); $flickr->enableCache("fs", System::getVar('temp')); // Find the NSID of the username $person = $flickr->people_findByUsername($this->userName); // Get the photos //$photos = $flickr->people_getPublicPhotos($person['id'], NULL, $this->photoCount); $photos = $flickr->photos_search(array('user_id' => $person['id'], 'tags' => $this->tags, 'per_page' => $this->photoCount)); $photoData = array(); foreach ((array) $photos['photo'] as $photo) { $photoData[] = array('title' => DataUtil::formatForDisplayHTML($this->decode($photo['title'])), 'src' => $flickr->buildPhotoURL($photo, "Square"), 'url' => "http://www.flickr.com/photos/{$photo['owner']}/{$photo['id']}"); } $this->view->assign('photos', $photoData); return $this->view->fetch($this->getTemplate()); }
<?php require_once 'phpFlickr/phpFlickr.php'; $username = '******'; $apiKey = 'c7f9162017db946e75f485b47eb10641'; $apiSecret = '08e1ed973d7fd8f4'; $flickr = new phpFlickr($apiKey, $apiSecret); $nsid = $flickr->people_findByUsername($username); function getLatestPhoto($tags, $mode = 'any') { global $flickr, $nsid; $tagList = join(",", $tags); $photos = $flickr->photos_search(array('user_id' => $nsid['nsid'], 'tags' => $tagList, 'tag_mode' => $mode, 'extras' => 'tags')); return $flickr->buildPhotoUrl($photos['photo'][0]); return null; }
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; } }
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; }
function save_settings() { global $wpdb; check_admin_referer('flickr-gallery'); $options = explode(',', $_POST['page_options']); $out = array(); include_once dirname(__FILE__) . '/phpFlickr.php'; $phpFlickr = new phpFlickr($_POST['fg-API-key'], empty($_POST['fg-secret']) ? null : $_POST['fg-secret']); switch ($_POST['fg-user_id-type']) { case 'name': $user = $phpFlickr->people_findByUsername($_POST['fg-user_id']); $_POST['fg-user_id'] = $user['id']; break; case 'email': $user = $phpFlickr->people_findByEmail($_POST['fg-user_id']); $_POST['fg-user_id'] = $user['id']; break; case 'url': $user = $phpFlickr->urls_lookupUser($_POST['fg-user_id']); $_POST['fg-user_id'] = $user['id']; break; } if ($_POST['fg-db-cache'] == 1) { if (isset($wpdb->charset) && !empty($wpdb->charset)) { $charset = ' DEFAULT CHARSET=' . $wpdb->charset; } elseif (defined(DB_CHARSET) && DB_CHARSET != '') { $charset = ' DEFAULT CHARSET=' . DB_CHARSET; } else { $charset = ''; } $query = ' CREATE TABLE IF NOT EXISTS `' . $wpdb->prefix . 'phpflickr_cache` ( `request` CHAR( 35 ) NOT NULL , `response` MEDIUMTEXT NOT NULL , `expiration` DATETIME NOT NULL , PRIMARY KEY ( `request` ) ) ' . $charset . ' '; $wpdb->query($query); } /* if ( empty($_POST['fg-token']) && !empty($_POST['fg-frob']) ) { $token = $phpFlickr->auth_getToken($_POST['fg-frob']); $_POST['fg-token'] = $token['token']; } */ foreach ($options as $o) { if (get_option($o) === false) { add_option($o, $_POST[$o], null, no); } else { update_option($o, $_POST[$o]); } if (is_array($_POST[$o])) { $out[] = '"' . $o . '":["' . implode('","', $_POST[$o]) . '"]'; } else { $out[] = '"' . $o . '":"' . addslashes($_POST[$o]) . '"'; } } echo '{' . implode(', ', $out) . '}'; exit; }
function widget($args, $instance) { extract($args, EXTR_SKIP); $tit = empty($instance['tit']) ? ' ' : 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 } }
*/ ini_set("display_errors", "on"); include_once dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php"; require_once dirname(dirname(__FILE__)) . "/lib/phpFlickr/phpFlickr.php"; $f = new phpFlickr("26b2abba37182aca62fe0eb2c7782050"); $flickr_username = get_input("flickr_username"); $album_id = get_input("album_id"); $return_url = get_input("return_url"); $user = get_loggedin_user(); if (empty($flickr_username)) { register_error(elgg_echo('flickr:enterusername')); forward($return_url); die; //just in case } else { $flickr_user = $f->people_findByUsername($flickr_username); if (!empty($flickr_user["id"])) { create_metadata($user->guid, "flickr_username", $flickr_username, "text", $user->guid, ACCESS_PUBLIC); create_metadata($user->guid, "flickr_id", $flickr_user["id"], "text", $user->guid, ACCESS_PUBLIC); if ($album_id) { create_metadata($user->guid, "flickr_album_id", $album_id, "text", $user->guid, ACCESS_PUBLIC); $album = get_entity($album_id); } system_message(sprintf(elgg_echo('flickr:savedusername'), $flickr_username)); system_message(sprintf(elgg_echo('flickr:saveduserid'), $flickr_user["id"])); system_message(sprintf(elgg_echo('flickr:savedalbum'), $album->title)); } else { register_error(sprintf(elgg_echo('flickr:errorusername'), $flickr_username)); } } forward($_SERVER['HTTP_REFERER']);
public function getItems() { jimport('joomla.filesystem.folder'); $api_key = '2a4dbf07ad5341b2b06d60c91d44e918'; $cache_path = JPATH_ROOT . '/cache/test/flickr'; $nsid = ''; $photos = array(); // create cache folder if not exist JFolder::create($cache_path, 0755); if (!class_exists('phpFlickr')) { require_once 'api/phpFlickr.php'; } $f = new phpFlickr($api_key); $f->enableCache('fs', $cache_path, $this->get('cache_time')); //enable caching if ($this->get('flickr_search_from') == 'user') { $username = $this->get('flickr_search_from'); if ($username != NULL) { $person = $f->people_findByUsername($username); $nsid = $person['id']; } else { return ''; } $photos = $f->people_getPublicPhotos($nsid, NULL, NULL, $this->get('item_count')); $source = $photos['photos']['photo']; } if ($this->get('flickr_search_from') == 'tags' or $this->get('flickr_search_from') == 'text') { $tags = $this->get('flickr_attrs'); if (!empty($tags)) { $attrs = ''; if ($this->get('flickr_search_from') == 'tags') { $attrs = 'tags'; } if ($this->get('flickr_search_from') == 'text') { $attrs = 'text'; } $photos = $f->photos_search(array($attrs => $tags, 'per_page' => $this->get('item_count'))); $source = $photos['photo']; } else { return ''; } } if ($this->get('flickr_search_from') == 'recent') { $photos = $f->photos_getRecent(NULL, $this->get('item_count')); $source = $photos['photo']; } //$extras = 'description,date_upload,owner_name,tags'; $items = array(); $i = 0; if (count($source) > 0) { foreach ($source as $photo) { $id = $photo['id']; $obj = new stdClass(); $info = $f->photos_getInfo($id); $nsid = $info['owner']['username']; $obj->title = $info['title']; $obj->image = $f->buildPhotoURL($photo, '_b'); $obj->link = $info['urls']['url'][0]['_content']; $obj->introtext = $info['description']; $obj->date = date('Y.M.d : H:i:s A', $info['dateuploaded']); $items[$i] = $obj; $i++; } } //return $items; var_dump($f); }
} ?> <?php get_template_part('partial', 'links'); ?> </div> <?php $key = get_field('flickr_key'); if (!$key) { $key = '2926a701327d02571c68efacf6406bf0'; } $username = get_field('flickr_user'); // $page = isset($_GET['page']) ? $_GET['page'] : 1; $f = new phpFlickr($key); $f->enableCache('fs', TEMPLATEPATH . '/inc/cache'); $result = $f->people_findByUsername($username); $nsid = $result['id']; // $photos = $f->people_getPublicPhotos( $nsid, NULL, NULL, 100, $page ); $photos = $f->favorites_getPublicList($nsid, NULL, NULL, NULL, NULL, NULL, $page); // $pages = $photos[photos][pages]; // $total = $photos[photos][total]; ?> <div class="content"> <div class="gallery"> <?php foreach ($photos['photos']['photo'] as $photo) { ?> <div class="gallery-item"><a href="<?php echo $f->buildPhotoURL($photo, 'large'); ?> " class="fancy" rel="photos"><img class="lazy" data-original="<?php
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; }
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'] . '&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'] . '&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; }
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 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&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 ' '; 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; } }
<?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>'; }
</div> <div id="overview"> <?php the_content('Read more on "' . the_title('', '', false) . '" »'); ?> </div> <?php $flickr_photoset_id = '72157626966312775'; $flickr_api_key = '2d589541fd6f617409903e97d0e10bbe'; $flickr_username = '******'; $flickr_gallery = new phpFlickr($flickr_api_key); $flickr_gallery->enableCache('fs', 'cache'); $flickr_gallery_people = $flickr_gallery->people_findByUsername($flickr_username); $flickr_gallery_user_id = $flickr_gallery_people['id']; $flickr_gallery_photos = $flickr_gallery->photosets_getPhotos($flickr_photoset_id, null, null); ?> <div id="slider" class="flickr-gallery"> <h2>Interior Design Gallery</h2> <div class="infiniteCarousel"> <div class="wrapper"> <ul> <?php foreach ($flickr_gallery_photos['photoset']['photo'] as $photo) { ?> <li><a href="<?php echo $flickr_gallery->buildPhotoURL($photo, 'Large'); ?>
function afsp_flickr_embed($photo) { // define outputs $flickr_gallery = ''; $flickr_nav = ''; $flickr_display = ''; // define access $api = '238309aa246837711a82e3616d5666b1'; $username = $photo; require_once get_template_directory() . '/inc/flickr/phpFlickr.php'; $photo_count = 20; $nav_width = 100 / $photo_count . '%'; $f = new phpFlickr($api); $user = $f->people_findByUsername($username); $nsid = $user['nsid']; $photos = $f->people_getPublicPhotos($nsid, 1, '', $photo_count); $flickr_gallery .= '<div class="gallery gallery--flickr js-flickity" data-flickity-options=\'{ "wrapAround": true, "pageDots": false, "autoPlay": true }\'>'; foreach ($photos['photos']['photo'] as $photo) { $src = 'https://farm' . $photo['farm'] . '.staticflickr.com/' . $photo['server'] . '/' . $photo['id'] . '_' . $photo['secret'] . '_c.jpg'; $flickr_gallery .= '<div class="gallery-cell gallery-cell__carousel">'; $flickr_gallery .= '<a target="_blank" href="https://www.flickr.com/photos/' . $nsid . '/' . $photo['id'] . '">'; $flickr_gallery .= '<img src="' . $src . '" />'; $flickr_gallery .= '</a>'; $flickr_gallery .= '</div>'; } $flickr_gallery .= '</div>'; $flickr_nav .= '<div class="gallery-nav gallery-nav--flickr js-flickity" data-flickity-options=\'{"asNavFor": ".gallery--flickr", "contain": true, "prevNextButtons": false, "pageDots": false}\'>'; foreach ($photos['photos']['photo'] as $photo) { $src = 'https://farm' . $photo['farm'] . '.staticflickr.com/' . $photo['server'] . '/' . $photo['id'] . '_' . $photo['secret'] . '_c.jpg'; $flickr_nav .= '<div class="gallery-cell" style="width:' . $nav_width . ';">'; $flickr_nav .= '<img src="' . $src . '" />'; $flickr_nav .= '</div>'; } $flickr_nav .= '</div>'; $flickr_display .= $flickr_gallery; $flickr_display .= $flickr_nav; echo $flickr_display; }
<?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) {
<input type="text" name="modules[id][details][desc_<?php echo $photo['id']; ?> ]" id="desc_<?php echo $photo['id']; ?> " style="margin: 0px; margin-top: 3px; margin-right: 10px; width: 300px" value="<?php echo $description; ?> " /> </li> <?php } } } elseif ($_POST['method'] == "getPhotosets") { $nsid = $f->people_findByUsername($_POST['username']); if ($f->getErrorCode()) { echo "Username \"" . $_POST['username'] . "\" not found on Flickr."; } else { $photosets = $f->photosets_getList($nsid); if (!isset($_POST['photoset_id'])) { $_POST['photoset_id'] = 0; } if (count($photosets['photoset'])) { echo '<h2>Photosets of ' . $_POST['username'] . "</h2>"; echo '<input type="hidden" id="photoset_count" value="' . count($photosets['photoset']) . '">'; echo '<input type="hidden" id="photoset_owner" value="' . $nsid . '">'; echo "<table cellpadding='3' style='border: none; width: 100%'>\n<tr>"; foreach ($photosets['photoset'] as $key => $photoset) { ?> <td style="vertical-align: top; text-align: center; width: 33%">