public function getFotos() { $f = new phpFlickr("f8dfa483443f9424a79d73c50344b90c"); //Clase de Api, conseguir en: http://www.flickr.com/services/api/keys/ $nsid = "139950084@N02"; //NSID Usuario, conseguir en: http://idgettr.com/ //Incluir tag, ordenamieno, privacidad, y numero de imagenes a mostrar $tagsList = $f->tags_getListUser($nsid); $j = 0; foreach ($tagsList as $tagl) { $photos = $f->photos_search(array("tags" => $tagl['_content'], "user_id" => $nsid, "sort" => "date-posted-desc", "privacy_filter" => "1")); //$photoList[$tagl['_content']] = $photos['photo']; $i = 0; $photoList[$j]['tag'] = $tagl['_content']; foreach ($photos['photo'] as $photo) { $photoList[$j]['photos'][$i]['id'] = $photo['id']; $photoList[$j]['photos'][$i]['url'] = $f->buildPhotoURL($photo, "Medium 640"); $i++; } $j++; /* if (is_array($photos['photo'])){ $i = 0; foreach ($photos['photo'] as $photo){ $photoList[$tagl['_content']][$i] = $f->buildPhotoURL($photo, "Medium 640"); } }*/ } return $photoList; }
function searchFlickr($keywords, $page) { $retval = array(); $data = array(); $f = new phpFlickr('5bc169cff7b9121c0c93f9b8804b1116'); $args = array("tags" => $keywords, "tag_mode" => "all", "sort" => "relevance", "per_page" => "10", "page" => $page); $photos = $f->photos_search($args); //decide not to show the photo beyond page 400; $totalPages = min($photos['pages'], 400); if ($totalPages > 0) { $i = 0; foreach ($photos['photo'] as $photo) { $user = $f->people_getInfo($photo['owner']); $data[$i] = array('id' => $photo['id'], 'title' => $photo['title'], 'author' => $user['username'], 'image' => $f->buildPhotoURL($photo, "Square")); $i++; } $retval['status'] = 'OK'; $retval['statusmsg'] = 'OK'; $retval['totalpages'] = $totalPages; $retval['currentpage'] = $page; $retval['data'] = $data; } else { $retval['status'] = 'NA'; $retval['statusmsg'] = 'NA'; } return $retval; }
function total_photo($tags) { $o = new phpFlickr('6791ccf468e1c2276c1ba1e0c41683a4'); $d = $o->photos_search(array('tags' => $tags, 'content_type' => 1, 'sort' => 'date-posted-asc', 'extras' => 'url_o,url_l', 'page' => 1, 'per_page' => 500)); print_r("total page :" . $d['pages']); $total_page = $d['pages']; print_r("total photo :" . $d['total']); $total_photo = $d['total']; $dir = str_replace(" ", "_", $tags); system(" mkdir {$dir}"); photo_list($tags, 1, 500); }
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()); }
function total_photo($tags, $camera) { $o = new phpFlickr('6791ccf468e1c2276c1ba1e0c41683a4'); $d = $o->photos_search(array('tags' => $tags, 'content_type' => 1, 'sort' => 'date-posted-asc', 'camera' => $camera, 'extras' => 'url_o,url_l', 'page' => 1, 'per_page' => 500)); print_r("total page :" . $d['pages']); $total_page = $d['pages']; print_r("total photo :" . $d['total']); $total_photo = $d['total']; for ($page = 1; $total_page >= $page; $page++) { print "page {$page} \n"; if ($total_photo >= 500) { $total_photo -= 500; photo_list($tags, $camera, $page, 500); } else { photo_list($tags, $camera, $page, $total_photo); } } }
function total_photo($tags) { $o = new phpFlickr('6791ccf468e1c2276c1ba1e0c41683a4'); $tags = trim(preg_replace('/\\s\\s+/', ' ', $tags)); $d = $o->photos_search(array('user_id' => $tags, 'content_type' => 1, 'sort' => 'date-posted-asc', 'extras' => 'url_m,url_z', 'page' => 1, 'per_page' => 500)); print_r("total page :" . $d['pages']); $total_page = $d['pages']; print_r("total photo :" . $d['total']); $total_photo = $d['total']; for ($page = 1; $total_page >= $page; $page++) { print "page {$page} \n"; if ($total_photo >= 500) { $total_photo -= 500; photo_list($tags, $page, 500); } else { photo_list($tags, $page, $total_photo); } } }
function listafotosflickr() { global $ret, $cp, $key, $texto, $ai, $af, $page; $ret = explode(" ", $ret); $ret = implode(",", $ret); $resultado = ""; if ($ai != "") { $ai = strtotime("1 Jan " . $ai); } // echo strtotime("10 September 2000") if ($af != "") { $af = strtotime("31 Dec " . $af); } $f = new phpFlickr($key); $recent = @$f->photos_search(array("page" => $page, "extras" => "geo", "accuracy" => "11", "min_upload_date" => $ai, "max_upload_date" => $af, "text" => $texto, "bbox" => $ret, "privacy_filter" => "1")); if (!$recent) { $recent = ""; } $cp->set_data($recent); }
function displayFlickrPhotos() { if (isset($_GET['q']) && isset($_GET['maxResults'])) { $flickrKey = 'b1a69066d658530df604321f514b72d0'; $flickrSecret = '9e0e977d109675fa'; require_once 'phpFlickr.php'; $f = new phpFlickr($flickrKey); $recent = $f->photos_search(array("tags" => $_GET['q'], "tag_mode" => "any", "per_page" => $_GET['maxResults'], "extras" => "url_sq")); $url = array(); $urls = array(); if (count($recent['photo']) < 1) { echo '<h5>There are no Results Found</h5>'; } else { foreach ($recent['photo'] as $photo) { $urls[] = $f->buildPhotoURL($photo, "Medium"); } foreach ($urls as $url) { echo '<img src="' . $url . '">'; } } } }
public function index() { $this->template->content = new View('flickrwijit_front'); //fetch flickrwijit settings from db $flickrwijit_settings = ORM::factory('flickrwijit', 1); // include phpflickr library include Kohana::find_file('libraries/phpflickr', 'phpFlickr'); $f = new phpFlickr(Kohana::config('flickrwijit.flick_api_key')); //enable caching if ($flickrwijit_settings->enable_cache == 1) { $f->enableCache("fs", "application/cache"); } $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page'), 'total_items' => $flickrwijit_settings->num_of_photos)); //print_r($pagination); $photos = $f->photos_search(array('page' => $pagination->current_page, 'tags' => $flickrwijit_settings->flickr_tag, 'per_page' => (int) Kohana::config('settings.items_per_page'), 'user_id' => $flickrwijit_settings->flickr_id)); $this->template->content->image_width = $flickrwijit_settings->image_width; $this->template->content->image_height = $flickrwijit_settings->image_height; $this->template->content->num_of_photos = $flickrwijit_settings->num_of_photos; $this->template->content->f = $f; $this->template->content->photos = $photos; $this->template->content->pagination = $pagination; }
public function displayFlickr($FlickrKey, $FlickrWhat, $FlickrWhere, $DisplayCount, $RandomCount, $width) { $f = new phpFlickr($FlickrKey); $returnurl = ''; $trycount = 1; $FlickrSearch = $FlickrWhat . ", " . $FlickrWhere; $photocount = $DisplayCount; //echo "Search - " . $FlickrSearch . "<br />"; //echo "Count - " . $RandomCount . "<br />"; $search = $f->photos_search(array("text" => $FlickrSearch, "tag_mode" => "any", "per_page" => $RandomCount, "license" => "Attribution Creative Commons")); //var_dump($search); $TotalCount = $search['total']; //echo "Count - " . $TotalCount . "<br />"; if ($TotalCount < $RandomCount) { $RandomCount = $TotalCount; } // Create the illusion of random photo $RandomPhoto = rand(1, $RandomCount); foreach ($search['photo'] as $photo) { //echo $photocount . ' == ' . $RandomPhoto . '<br />'; if ($photocount == $RandomPhoto) { $photo_id = $photo['id']; $photo_owner = $photo['owner']; $photo_title = $photo['title']; $photo_farm = $photo['farm']; $photo_server = $photo['server']; $photo_secret = $photo['secret']; $url = "http://www.flickr.com/photos/" . $photo_owner . "/" . $photo_id . "/"; // Build the HTML for an image to return $returnurl = '<center><a href="' . $url . '" class="img">'; $returnurl .= '<img src="http://farm' . $photo_farm . '.staticflickr.com/' . $photo_server . '/' . $photo_id . '_' . $photo_secret . '.jpg" width="' . $width . '" />'; $returnurl .= '<div>' . $FlickrWhere . '</div>'; $returnurl .= '</a></center>'; } $photocount++; } return $returnurl; }
function flickrTagmatch($keywords = "", $mode, $count, $page, $date = 0, $sort = "interestingness-desc", $user = "", $test = false) { global $site; if ($keywords != "") { $keywords = str_replace(".", "", $keywords); $parameters["tags"] = $keywords; $parameters["tag_mode"] = $mode; } $f = new phpFlickr($site["flickr"]["key"]); $f->enableCache("fs", $site["path"] . $site["folder"] . $site["flickr"]["cache"], $site["flickr"]["cacheduration"]); $parameters["sort"] = $sort; if ($user != "") { //No license restrictions when specifying a user. $parameters["user_id"] = $user; } else { $parameters["license"] = "1,2,3,4,5,6,7"; } $parameters["per_page"] = "" . $count; $parameters["page"] = "" . $page; if ($date != 0) { $timeStart = strtotime(date("Y-m-d 0:0:0", $date)); $timeEnd = strtotime(date("Y-m-d 23:59:59", $date)); $parameters["min_taken_date"] = $timeStart; $parameters["max_taken_date"] = $timeEnd; } $parameters["content_type"] = "1"; $parameters["extras"] = "license,owner_name,url_o,url_l,url_c,url_z,url_n"; $tagmatch = $f->photos_search($parameters); if ($test) { print "<pre>"; print_r($parameters); print_r($tagmatch); print "</pre>"; } return $tagmatch; }
</head> <body> <!--[if lt IE 8]> <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> <![endif]--> <div class="container"> <h1 class="title"><?php echo $PAGE_TITLE; ?> </h1> <!-- Example row of columns --> <ul class="photo-gallery"> <?php $f = new phpFlickr($API_KEY); $search = $f->photos_search(array("tags" => $SEARCH_TAGS, "tag_mode" => "any")); foreach ($search['photo'] as $photo) { echo "<li>"; echo "<a class='image-link' href='http://www.flickr.com/photos/" . $photo['owner'] . "/" . $photo['id'] . "/'>" . "<img class='img-circle' src='http://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . "_s.jpg' alt='" . $photo['title'] . "'/>" . "</a> <br>" . "<a class='owner-link' href='http://www.flickr.com/people/" . $photo['owner'] . "/'>credits</a>"; echo "</li>"; } ?> </ul> <hr> <footer> <p>Photos come from Flickr Public API</p> </footer> </div> <!-- /container -->
function getExternalImages($layer_tablename,$row_id){ require_once("phpFlickr/phpFlickr.php"); $f = new phpFlickr("fcd1d2106cda125b6b87f2e131357f12", "cee841f34bf60a97"); $flickr_photos = array(); $query = "select layer_name,layer_type,title_column from \"Meta_Layer\" where layer_tablename = '%s'"; $result = db_query($query, $layer_tablename); if(!$result) { } else { $obj = db_fetch_object($result); $layer_name = $obj->layer_name; $layer_type = $obj->layer_type; $title_column = $obj->title_column; $tags = "india," . $layer_name; switch($layer_type) { case 'POINT': case 'MULTIPOINT': $query = 'select %s as title, asText('.AUTO_DBCOL_PREFIX.'topology) as topo from "%s" where '.AUTO_DBCOL_PREFIX.'id = %d'; $query_args = array(str_replace("'", '"', $title_column), $layer_tablename, $row_id); $result = db_query($query, $query_args); if(!$result) { } else { if($obj = db_fetch_object($result)) { $title = $obj->title; $topo = $obj->topo; $topo = strstr($topo, "("); $topo = str_replace(array("(", ")"), "", $topo); $arr_topo = explode(" ", $topo); $lon = $arr_topo[0]; $lat = $arr_topo[1]; $tags = $tags . "," . $title; $tags = str_replace(" ", ",", $tags); $flickr_photos = $f->photos_search(array("api_keys"=>"fcd1d2106cda125b6b87f2e131357f12", "lon"=>$lon, "lat"=>$lat, "radius"=>"0.095", "tags"=>$tags, "per_page"=>30, "privacy_filter"=>1, "content_type"=>1)); $delta = 0.002; $loc[0] = $lon - $delta; $loc[1] = $lat - $delta; $loc[2] = $lon + $delta; $loc[3] = $lat + $delta; $url = "http://www.panoramio.com/map/get_panoramas.php?order=popularity&set=popular&from=0&to=30&minx=".$loc[0]."&miny=".$loc[1]."&maxx=".$loc[2]."&maxy=".$loc[3]."&size=square"; $panoramio_json = json_decode(file_get_contents($url)); } else { die("No record found"); } } break; default: $query = "select %s as title, ST_XMin(box3d(".AUTO_DBCOL_PREFIX."topology)) || ',' || ST_YMin(box3d(".AUTO_DBCOL_PREFIX."topology)) || ',' || ST_XMax(box3d(".AUTO_DBCOL_PREFIX."topology)) || ',' || ST_YMax(box3d(".AUTO_DBCOL_PREFIX."topology)) as bbox from \"%s\" where ".AUTO_DBCOL_PREFIX."id = %d"; $query_args = array(str_replace("'", "", $title_column), $layer_tablename, $row_id); $result = db_query($query, $query_args); if(!$result) { } else { if($obj = db_fetch_object($result)) { $title = $obj->title; $bbox = $obj->bbox; $tags = $tags . "," . $title; $tags = str_replace(" ", ",", $tags); $flickr_photos = $f->photos_search(array("api_keys"=>"fcd1d2106cda125b6b87f2e131357f12", "bbox"=>$bbox, "tags"=>$tags, "per_page"=>30, "privacy_filter"=>1, "content_type"=>1)); $loc = explode(",", $bbox); $url = "http://www.panoramio.com/map/get_panoramas.php?order=popularity&set=popular&from=0&to=30&minx=".$loc[0]."&miny=".$loc[1]."&maxx=".$loc[2]."&maxy=".$loc[3]."&size=square"; $panoramio_json = json_decode(file_get_contents($url)); } } break; } } return generateUI($flickr_photos,$panoramio_json); }
// Insert your Flickr API here: $f = new phpFlickr("YOUR FLICKR API GOES HERE"); $photos = null; //Cheap-o caching so it's not fetching a list on every refresh. $storedCache = unserialize(file_get_contents("./cache/flickrcache")); if ($storedCache) { if ($storedCache[0] >= time()) { echo "<!-- Cached! -->\n\n"; $photos = $storedCache[1]; } } if (is_null($photos)) { echo "<!-- No cache hit -->\n\n"; $tagToSearch = isset($_REQUEST['tag']) ? $_GET['tag'] : "banana"; // Tag is passed in via query string by requesting HTML. $photos = $f->photos_search(array("tags" => $tagToSearch, "tag_mode" => "all", "per_page" => "500")); // Stick the results in the cache for five minutes $storedCache = array(time() + 300, $photos); file_put_contents("./cache/flickrcache", serialize($storedCache)); } // Pick a random photo from the array of photo objects returned by phpFlickr srand((double) microtime() * 1000000); echo "<!-- Found this many: " . count($photos['photo']) . "-->\n\n"; $randomPhoto = $photos['photo'][rand(0, count($photos['photo']))]; // Construct a link to Flickr's page for the photo. $imgUrl = "http://static.flickr.com/" . $randomPhoto['server'] . "/" . $randomPhoto['id'] . "_" . $randomPhoto['secret'] . ".jpg"; // Get Flickr's info for this photo for use on the credit line. $imgInfo = $f->photos_getInfo($randomPhoto['id'], $randomPhoto['secret']); // Return the display HTML for use by the page (probably in a div). echo "<img src=" . $imgUrl . "><BR>"; echo "<a href='http://www.flickr.com/photos/" . $randomPhoto['owner'] . "/" . $randomPhoto['id'] . "'>" . $imgInfo['title'] . "</a> by <a href='http://www.flickr.com/people/" . $randomPhoto['owner'] . "/'>" . $imgInfo['owner']['username'] . "</a>";
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); }
* * This example file shows you how to call the 100 most recent public * photos. It parses through them and prints out a link to each of them * along with the owner's name. * * Most of the processing time in this file comes from the 100 calls to * flickr.people.getInfo. Enabling caching will help a whole lot with * this as there are many people who post multiple photos at once. * * Obviously, you'll want to replace the "<api key>" with one provided * by Flickr: http://www.flickr.com/services/api/key.gne */ require_once "phpFlickr.php"; $f = new phpFlickr("a28fe4e32f1304273f5562dc12f9559a"); $lifetime = 60 * 60; // One hour $f->enableCache("fs", "../resources/cache", $lifetime); $photos = $f->photos_search(array("tags" => "hongkong, girl", "tag_mode" => "all", "per_page" => "20")); foreach ($photos['photo'] as $photo) { echo "<img src='https://farm" . $photo['farm'] . ".staticflickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . ".jpg'></img>"; $owner = $f->people_getInfo($photo['owner']); echo "<p>" . $owner['username']['_content'] . "</p>"; /* $photoInfo = $f->photos_getInfo($photo['id']); echo "<p>"; foreach ($photoInfo['photo']['tags']['tag'] as $tag) { echo $tag['_content']." "; } echo "</p>";*/ // https://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}.jpg echo "<br><br>"; }
function widget($args, $instance) { extract($args, EXTR_SKIP); echo $before_widget; $s_flickr_title = empty($instance['s_flickr_title']) ? '' : apply_filters('widget_s_flickr_title', $instance['s_flickr_title']); $s_flickr_choice = empty($instance['s_flickr_choice']) ? '14897087@N04' : apply_filters('widget_s_flickr_choice', $instance['s_flickr_choice']); $s_flickr_noi = empty($instance['s_flickr_noi']) ? 6 : apply_filters('widget_s_flickr_noi', $instance['s_flickr_noi']); $s_flickr_tou = empty($instance['s_flickr_tou']) ? 'user' : apply_filters('widget_s_flickr_tou', $instance['s_flickr_tou']); $loop_q = ''; if ($s_flickr_tou == 'user' && vp_option('vpt_option.flickr_key') != '') { $flickr_key_opt = esc_attr(vp_option('vpt_option.flickr_key')); require_once locate_template('/inc/phpFlickr.php'); $f = new phpFlickr($flickr_key_opt); $photos = $f->people_getPublicPhotos($s_flickr_choice, NULL, NULL, $s_flickr_noi); $loop_q = $photos['photos']['photo']; } else { if ($s_flickr_tou == 'all_tag' && vp_option('vpt_option.flickr_key') != '') { $flickr_key_opt = esc_attr(vp_option('vpt_option.flickr_key')); require_once locate_template('/inc/phpFlickr.php'); $f = new phpFlickr($flickr_key_opt); $photos = $f->photos_search(array('tags' => $s_flickr_choice, 'tag_mode' => 'any', 'per_page' => $s_flickr_noi, 'sort' => 'relevance')); $loop_q = $photos['photo']; } } if ($s_flickr_title != '') { echo $before_title . $s_flickr_title . $after_title; } if (!empty($photos)) { $fancybox_uid = k_rnd_key(6); echo '<ul class="list-unstyled clear-margins">'; foreach ($loop_q as $photo) { echo '<li><a href="' . $f->buildPhotoURL($photo, 'large') . '" title="' . $photo['title'] . '" class="swipebox" rel="flickrgal-' . $fancybox_uid . '"><img src="' . $f->buildPhotoURL($photo, 'square') . '" alt="' . $photo['title'] . '" /></a></li>'; } echo '</ul>'; } else { echo '<p>' . __('No photos matching given criteria.', 'kazaz') . '</p>'; } echo $after_widget; }
<?php require_once 'phpFlickr.php'; $flickrObject = new phpFlickr("46dea5f6abb12aed7a823adb7ecf5816"); $pics_file = fopen("pics_file_temp.txt", "w") or die("Unable to open file!"); $photos = $flickrObject->photos_search(array("tags" => "trip,travel,vacation,objects,color,- people,- person,- bikini,- human", "tag_mode" => "any", "per_page" => "50", "sort" => "interestingness-desc", "content_type" => "1", "safe_search" => "1", "license" => "9")); //Initializing variables $imageCounter = 0; $idArrayImages = array(); //For each Picture foreach ($photos['photo'] as $photo) { //Console Log image message counter echo "Image: " . $imageCounter++ . " / "; //We get the Information of each photo giving the Photo_ID $photo_info = $flickrObject->photos_getInfo($photo['id']); echo $photo["id"] . ' - '; if (in_array($photo['id'], $idArrayImages)) { echo "Hay una imagen repetida"; } $idArrayImages[] = $photo['id']; //Uncomment this line to see the PUBLIC URL of the photo //echo $photo_info['photo']['urls']['url'][0]['_content']."\n"; //We stract the TAGS array for each photo $array_tags = $photo_info['photo']['tags']['tag']; //Get the different sizes of the image $photo_sizes = $flickrObject->photos_getSizes($photo['id']); //We look the optimal size foreach ($photo_sizes as $size) { //Only get Medium Images for file sizes proposes if ($size['label'] == 'Medium 640') { $url = $size['source'];
<?php require_once "lib/phpFlickr/phpFlickr.php"; $f = new phpFlickr("", NULL, false); if ($this->attributes['details']['show'] == "automatic") { if (empty($this->attributes['details']['query']) && empty($this->attributes['details']['text'])) { print "No search terms were entered."; } else { if ($this->attributes['details']['searchtype'] == 'tags') { $photos = $f->photos_search(array("tags" => $this->attributes['details']['query'], "tag_mode" => $this->attributes['details']['boolean'], "extras" => "owner_name", "per_page" => $this->attributes['details']['max_photos'])); } else { if ($this->attributes['details']['searchtype'] == 'text') { $tags = trim($this->attributes['details']['tags']); $photos = $f->photos_search(array("text" => $tags, "extras" => "owner_name", "per_page" => $this->attributes['details']['max_photos'])); } } $isError = $f->getErrorMsg(); if (!$isError && isset($photos['photo']) && count($photos['photo']) > 0) { echo "<table cellpadding='3' style='border: none; width: 100%'>\n<tr>"; foreach ($photos['photo'] as $key => $photo) { ?> <td style="vertical-align: top; text-align: center; width: 33%"> <a href="http://www.flickr.com/photos/<?php echo $photo['owner']; ?> /<?php echo $photo['id']; ?> "> <img style="padding: 1px; border: 1px solid black;" alt="<?php echo $photo['title'] . " by " . $photo['ownername'];
$resultdef = mysql_query($db->query) or die("Error in query: {$db->query}. " . mysql_error()); //echo $db->query; $defwords = ''; if (mysql_num_rows($resultdef) > 0) { while ($row = mysql_fetch_object($resultdef)) { $defwords .= "{$row->lifestylewords} OR "; } } //print_r($defwords); $defwords = substr($defwords, 0, strLen($defwords) - 4); //this will eat the last OR //echo $defwords; unset($argst); $argst = array("text" => "" . $defwords . "", "min_taken_date" => "" . $fsdate . "", "max_taken_date" => "" . $fedate . "", "per_page" => "20", "sort" => "relevance", "page" => "1"); //print_r($argst); $triathlondaily = $f->photos_search($argst); //print_r($triathlondaily); for ($x = 0; $x <= 15; $x++) { $photosre = ''; $photosre = $triathlondaily[photo][$x]; $photo_id = ''; $photo_id = $triathlondaily[photo][$x][id]; //echo $photo_id; // need to find photo username to get data to allow form piciture flickr url $photoid = $f->photos_getInfo($photo_id, $secret); //print_r($photoid); //echo $photoid[urls][url][$x][_content]; $image = $f->buildPhotoURL($photosre, $size = "Thumbnail"); $imgtoday[$x][url] = $photoid[urls][url][0][_content]; $imgtoday[$x][title] = $photoid[title]; $imgtoday[$x][image] = $image;
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">←</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">→</span>', 'fjgwpp') . '</a>' . '</div>'; } $ris .= '</div>'; } } } } $shortcode_unique_id++; return $ris; }
$body = isset($data['body']) ? $data['body'] : ''; if (strcmp($username, 'image') == 0) { //Consumer Key $app_key = CONSUMER_KEY; //Consumer Secret $app_secret = CONSUMER_SECRET; //インスタンスを作成する $flickr = new phpFlickr($app_key, $app_secret); //検索ワードの指定 $keyword = $body; //取得件数の指定 $count = 1; //オプションの設定 $option = array("text" => $keyword, "per_page" => $count, "extras" => "url_m", "safe_search" => 1); //検索を実行し、取得したデータを[$result]に代入する $result = $flickr->photos_search($option); var_dump($result); //[$result]をJSONに変換する $json = json_encode($result); var_dump($json); //JSONをオブジェクト型に変換する $obj = json_decode($json); var_dump($obj); //ループ処理 foreach ($obj->photo as $photo) { //データの整理 $body = $photo->url_m; //画像ファイルのURL //出力する //echo '<img src="' . $src . '" width="' . $width . '" height="' . $height . '"/><br/>'; $createdMessage = $app->createMessage($username, $body, base64_encode(file_get_contents($app['icon_image_path'])));
<h3>Últimas fotos</h3> <div class="cajacontenido"> <!-- Aquí vienen las fotos... --> <div id="fotos"> <?php require_once "../eventos/flickr/phpFlickr.php"; //Incluyendo el API de Flickr $f = new phpFlickr("03e1411633d36816cc74fb82204549ec"); //Clase de Api, conseguir en: http://www.flickr.com/services/api/keys/ $nsid = ""; //NSID Usuario, conseguir en: http://idgettr.com/ //Incluir tag, ordenamieno, privacidad, y numero de imagenes a mostrar $photos = $f->photos_search(array("tags" => "mozilla-hispano", "user_id" => $nsid, "sort" => "date-posted-desc", "privacy_filter" => "1", "per_page" => "10")); $url = "//www.flickr.com/photos/" . $photo['id'] . "/"; //Url de la Imgen Original if (is_array($photos['photo'])) { echo "<div><ul>"; $sw = 1; foreach ($photos['photo'] as $photo) { if ($sw == 1) { $salida = "<li class='foto'>"; $salida .= "<a href='" . $f->buildPhotoURL($photo, "medium") . "' title='" . $photo['title'] . "' class='thickbox' rel='mozilla-hispano'><img alt='" . $photo['title'] . "' title='" . $photo['title'] . "' " . "src='" . $f->buildPhotoURL($photo, "square") . "' /></a>"; $sw = 0; } else { $salida .= "<a href='" . $f->buildPhotoURL($photo, "medium") . "' title='" . $photo['title'] . "' class='thickbox' rel='mozilla-hispano'><img alt='" . $photo['title'] . "' title='" . $photo['title'] . "' " . "src='" . $f->buildPhotoURL($photo, "square") . "' /></a>"; echo $salida . "</li>"; $sw = 1; }
<?php include_once "../include.php"; $GET = getMultipleParameters(); require_once "./phpFlickr-3.1/phpFlickr.php"; $f = new phpFlickr("94c57f05ba55563f88348d29bdd54593"); $search_array = array("text" => "amsterdam"); if ($GET['srch']) { $search_array = array("text" => $GET['srch']); } $results = $f->photos_search($search_array); $items = array(); $p2p = array(); foreach ($results['photo'] as $photo) { $item = new obj(); $item->authorid = $photo['owner']; $item->author_link = "http://www.flickr.com/photos/" . $photo['owner'] . "/" . $photo['id']; $item->title = $photo['title']; $item->autor_stream = "http://www.flickr.com/people/" . $photo['owner']; $item->thumbnail = sprintf("http://farm%s.staticflickr.com/%s/%s_%s.jpg", $photo['farm'], $photo['server'], $photo['id'], $photo['secret']); $item->getperson = urlpath() . "getperson.php?id=" . $photo['owner']; $item->getpicture = urlpath() . "getpicture.php?id=" . $photo['id']; array_push($items, $item); $item2 = new obj(); $item2->summary = new obj(); $item2->summary->lines = array("img:" . $item->thumbnail, "h1:" . $item->title, "p: "); $item2->details = new obj(); $item2->details->lines = array("img:" . $item->thumbnail, "h1:" . $item->title, "p: "); array_push($p2p, $item2); } $retval = new obj();
function query() { global $wgRequest, $wgHTTPProxy; $query = $wgRequest->getText('query'); $page = $wgRequest->getVal('page', 1); $sourceId = $wgRequest->getVal('sourceId'); if ($sourceId == 1) { $flickrAPI = new phpFlickr('bac0bd138f5d0819982149f67c0ca734'); $proxyArr = explode(':', $wgHTTPProxy); $flickrAPI->setProxy($proxyArr[0], $proxyArr[1]); $flickrResult = $flickrAPI->photos_search(array('tags' => $query, 'tag_mode' => 'all', 'page' => $page, 'per_page' => 8, 'license' => '4,5', 'sort' => 'interestingness-desc')); $tmpl = new EasyTemplate(dirname(__FILE__) . '/templates/'); $tmpl->set_vars(array('results' => $flickrResult, 'query' => addslashes($query))); return $tmpl->render('results_flickr'); } else { if ($sourceId == 0) { if ((int) $page == 0) { $page = 1; } $mediaService = new MediaQueryService(); $results = $mediaService->searchInTitle($query, $page, 8); $tmpl = new EasyTemplate(dirname(__FILE__) . '/templates/'); $tmpl->set_vars(array('results' => $results, 'query' => addslashes($query))); return $tmpl->render('results_thiswiki'); } } }
function execute($par) { global $wgUser, $wgOut, $wgScriptPath, $wgRequest, $wgLang, $wgIFI_FlickrAPIKey, $wgTmpDirectory; global $wgIFI_ResultsPerPage, $wgIFI_FlickrSort, $wgIFI_FlickrLicense, $wgIFI_ResultsPerRow, $wgIFI_CreditsTemplate; global $wgIFI_GetOriginal, $wgIFI_PromptForFilename, $wgIFI_AppendRandomNumber, $wgIFI_FlickrSearchBy, $wgIFI_ThumbType; global $wgIFI_CheckForExistingFile, $wgIFI_ValidDomains, $wgIFI_ValidLicenses; global $wgIFI_UseAjax, $wgIFI_AjaxKey, $wgIFI_AjaxDomain, $wgIFI_AjaxTemplate; require_once "phpFlickr-2.0.0/phpFlickr.php"; wfLoadExtensionMessages('ImportFreeImages'); $this->setHeaders(); $fname = "wfSpecialImportFreeImages"; $importPage = Title::makeTitle(NS_SPECIAL, "ImportFreeImages"); if ($wgUser->isAnon()) { $wgOut->errorpage('uploadnologin', 'uploadnologintext'); return; } if (empty($wgIFI_FlickrAPIKey)) { // error - need to set $wgIFI_FlickrAPIKey to use this extension $wgOut->errorpage('error', 'importfreeimages_noapikey'); return; } $q = ''; if (isset($_GET['q']) && !$wgRequest->wasPosted()) { $q = $_GET['q']; } $import = ''; if ($wgRequest->wasPosted() && isset($_POST['url'])) { $import = $_POST['url']; $parts = parse_url($import); preg_match("/[^.]+\\.[^.]+\$/", $parts['host'], $domain_only); $domain = $domain_only[0]; if (!isset($wgIFI_ValidDomains[$domain])) { $wgOut->addHTML(wfMsg('importfreeimages_invalidurl', $import)); return; } if ($wgIFI_CheckForExistingFile && $wgRequest->getVal('override', null) == null) { $title = urldecode($wgRequest->getVal('ititle')); $id = $wgRequest->getVal('id'); $x = Title::newFromText($title); if ($x) { $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select("image", array("img_name", "img_description"), array("img_name like '" . $dbr->strencode($x->getDBKey()) . "%'")); $found = false; $wt = ""; while ($row = $dbr->fetchObject($res)) { if (strpos($row->img_description, $id) !== false) { $img = Image::newFromName($row->img_name); $t = Title::makeTitle(NS_IMAGE, $row->img_name); $wt .= "<tr><td>[[Image:{$img->getName()}|thumb|center|{$t->getText()}]]</td>\n\t\t\t\t\t\t\t<td valign='top'>" . wfMsg('image_instructions', $t->getFullText()) . "</td></tr>"; $found = true; } } $dbr->freeResult($res); } if ($found) { $wgOut->addHTML(wfMsg('importfreeimages_similarphotosfound') . "<table>"); $wgOut->addWikiText($wt); $wgOut->addHTML("</table><br clear='all'/><form method='POST'>"); $vals = $wgRequest->getValues(); foreach ($vals as $key => $value) { $wgOut->addHTML("<input type='hidden' name='{$key}' value='" . htmlspecialchars($value) . "'/>"); } $wgOut->addHTML("<input type='hidden' name='override' value='true'/>"); $wgOut->addHTML("<input type='button' onclick='window.location=\"{$importPage->getFullURL()}\";' class='guided-button' value='" . wfMsg('importfreeimages_dontimportduplicate') . "'/> <input class='guided-button' type='submit' value='" . wfMsg('importfreeimages_importduplicate') . "'/></form>"); return; } } if ($wgIFI_GetOriginal && ($domain = "flickr.com")) { // get URL of original :1 $sizes = $f->photos_getSizes($_POST['id']); $original = ''; foreach ($sizes as $size) { if ($size['label'] == 'Original') { $original = $size['source']; $import = $size['source']; } else { if ($size['label'] == 'Large') { $large = $size['source']; } } } //somtimes Large is returned but no Original! if ($original == '' && $large != '') { $import = $large; } } // store the contents of the file $pageContents = file_get_contents($import); $name = $wgTmpDirectory . "/flickr-" . rand(0, 999999); $r = fopen($name, "w"); $size = fwrite($r, $pageContents); fclose($r); chmod($name, 0777); if ($domain == $wgIFI_AjaxDomain) { $caption = "{{{$wgIFI_AjaxTemplate}|{$import}}}"; $id = $wgRequest->getVal('id'); if ($domain == "wikimedia.org") { //maybe we can grab the licnese $yy = str_replace("http://upload.wikimedia.org/", "", $import); $parts = split("/", $yy); $img_title = ""; if (sizeof($parts) == 7) { $img_title = $parts[5]; } else { if (sizeof($parts) == 5) { $img_title = $parts[4]; } } if ($img_title != "") { $url = "http://commons.wikimedia.org/wiki/Image:{$img_title}"; $license = "unknown"; $contents = file_get_contents("http://commons.wikimedia.org/w/index.php?title=Image:{$img_title}&action=raw"); foreach ($wgIFI_ValidLicenses as $lic) { if (strpos($contents, "{{$lic}") !== false || strpos($contents, "{{self|{$lic}") !== false || strpos($contents, "{{self2|{$lic}") !== false) { $license = $lic; break; } } $caption = "{{{$wgIFI_AjaxTemplate}|{$import}|{$url}|{$license}}}"; } } } else { if (!empty($wgIFI_CreditsTemplate)) { $f = new phpFlickr($wgIFI_FlickrAPIKey); $info = $f->photos_getInfo($_POST['id']); $caption = "{{" . $wgIFI_CreditsTemplate . $info['license'] . "|{$_POST['id']}|" . urldecode($_POST['owner']) . "|" . urldecode($_POST['name']) . "}}"; } else { $caption = wfMsg('importfreeimages_filefromflickr', $_POST['t'], "http://www.flickr.com/people/" . urlencode($_POST['owner']) . " " . $_POST['name']) . " <nowiki>{$import}</nowiki>. {{CC by 2.0}} "; } } $caption = trim($caption); $t = $_POST['ititle']; // handle duplicate filenames $i = strrpos($import, "/"); if ($i !== false) { $import = substr($import, $i + 1); } // pretty dumb way to make sure we're not overwriting previously uploaded images $c = 0; $nt =& Title::makeTitle(NS_IMAGE, $import); $fname = $import; while ($nt->getArticleID() && $c < 20) { $fname = $c . "_" . $import; $nt =& Title::makeTitle(NS_IMAGE, $fname); $c++; } $import = $fname; /* $arr = array ( "size" => $size, "tempname" => $name, "caption" => $caption, "url" => $import, "title" => $_POST['t'] ); */ $filename = trim(urldecode($wgRequest->getVal('ititle', null))); if ($filename == "undefined") { $filename = wfTimestampNow(); } $filename .= "_"; if ($wgIFI_AppendRandomNumber) { $filename .= rand(0, 100000); } $parts = parse_url($wgRequest->getVal('url')); $ux = $wgRequest->getVal('url'); $ext = strtolower(substr($ux, strrpos($ux, "."))); switch ($ext) { case ".png": case ".jpeg": case ".jpg": case ".gif": $filename .= $ext; break; default: $filename .= ".jpg"; } $filename = str_replace("?", "", $filename); $filename = str_replace(":", "", $filename); $filename = preg_replace('/ [ ]*/', ' ', $filename); if (!class_exists("UploadForm")) { require_once 'includes/SpecialUpload.php'; } $u = new UploadForm($wgRequest); //MW 1.12+ $u->mTempPath = $name; $u->mFileSize = $size; $u->mComment = $caption; $u->mSrcName = $filename; $u->mUploadTempName = $name; $u->mUploadSize = $size; $u->mUploadDescription = $caption; $u->mRemoveTempFile = true; $u->mIgnoreWarning = true; $u->mOname = $filename; $t = Title::newFromText($filename, NS_IMAGE); if (!$t) { $wgOut->addHTML("Error - could not create title from filename \"{$filename}\""); return; } if ($t->getArticleID() > 0) { $sk = $wgUser->getSkin(); $dlink = $sk->makeKnownLinkObj($t); $warning .= '<li>' . wfMsgHtml('fileexists', $dlink) . '</li>'; // use our own upload warning as we dont have a 'reupload' feature $this->uploadWarning($u); return; } else { $u->execute(); } } $wgOut->addHTML(wfMsg('importfreeimages_description') . "<br/><br/>\n\t\t\t<form method=GET action='" . $importPage->getFullURL() . "'>" . wfMsg('search') . ": <input type=text name=q value='" . htmlspecialchars($q) . "'><input type=submit value=" . wfMsg('search') . ">\n\t\t\t</form>"); if ($q != '') { $page = $_GET['p']; if ($page == '') { $page = 1; } $f = new phpFlickr($wgIFI_FlickrAPIKey); $q = $_GET['q']; // TODO: get the right licenses $photos = $f->photos_search(array("{$wgIFI_FlickrSearchBy}" => "{$q}", "tag_mode" => "any", "page" => $page, "per_page" => $wgIFI_ResultsPerPage, "license" => $wgIFI_FlickrLicense, "sort" => $wgIFI_FlickrSort)); $i = 0; if ($photos == null || !is_array($photos) || sizeof($photos) == 0 || !isset($photos['photo'])) { $wgOut->addHTML(wfMsg("importfreeimages_nophotosfound", $q)); return; } $sk = $wgUser->getSkin(); $wgOut->addHTML("\n\t\t\t\t<style type='text/css' media='all'>/*<![CDATA[*/ @import '/extensions/ImportFreeImages/ifi.css'; /*]]>*/</style>\n\t\t\t\t<div id='photo_results'> " . wfMsg('importfreeimages_results', 'Flickr') . "\n\t\t\t\t<center>\n\t\t\t\t<table cellpadding='4' class='ifi_table'>\n\t\t\t\t<form method='POST' name='uploadphotoform' action='" . $importPage->getFullURL() . "'>\n\t\t\t\t\t<input type='hidden' name='url' value=''/>\n\t\t\t\t\t<input type='hidden' name='id' value=''/>\n\t\t\t\t\t<input type='hidden' name='action' value='submit'/>\n\t\t\t\t\t<input type='hidden' name='owner' value=''/>\n\t\t\t\t\t<input type='hidden' name='name' value=''/>\n\t\t\t\t\t<input type='hidden' name='ititle' value=''/>\n\t\t\t\t</form>\t\n\t\t<script type=\"text/javascript\">\n\t\n\t\t\tfunction s2 (url, id, owner, name, ititle) {\n\t\t\t\tresults = document.getElementById('photo_results');\n\t\t\t\tdocument.uploadphotoform.url.value = url;\n\t\t\t\tdocument.uploadphotoform.id.value = id;\n\t\t\t\tdocument.uploadphotoform.owner.value = owner;\n\t\t\t\tdocument.uploadphotoform.name.value = name;\n\t\t\t\tdocument.uploadphotoform.ititle.value = ititle;\n\t\t\t\tif (" . ($wgIFI_PromptForFilename ? "true" : "false") . ") {\n\t\t\t\t\tititle = ititle.replace(/\\+/g, ' ');\n\t\t\t\t\tdocument.uploadphotoform.ititle.value = prompt('" . wfMsg('importfreeimages_promptuserforfilename') . "', unescape(ititle));\n\t\t\t\t\tif (document.uploadphotoform.ititle.value == '') {\n\t\t\t\t\t\tdocument.uploadphotoform.ititle.value = ititle;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdocument.uploadphotoform.submit();\n\t\t\t\tresults.innerHTML = '" . wfMsg('importfreeimages_uploadingphoto') . "';\n\t\t\t}\n\t\n\t\t</script>\n\t\t\t\t"); $count = 0; foreach ($photos['photo'] as $photo) { $count++; if ($i % $wgIFI_ResultsPerRow == 0) { $wgOut->addHTML("<tr>"); } $owner = $f->people_getInfo($photo['owner']); $wgOut->addHTML("<td><a href='http://www.flickr.com/photos/" . $photo['owner'] . "/" . $photo['id'] . "/'>"); $wgOut->addHTML($photo['title']); $wgOut->addHTML("</a><br/>" . wfMsg('importfreeimages_owner') . ": "); $wgOut->addHTML("<a href='http://www.flickr.com/people/" . $photo['owner'] . "/'>"); $wgOut->addHTML($owner['username']); $wgOut->addHTML("</a><br/>"); //$wgOut->addHTML( "<img src=http://static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . "." . "jpg>" ); $url = "http://farm{$photo['farm']}.static.flickr.com/{$photo['server']}/{$photo['id']}_{$photo['secret']}.jpg"; $wgOut->addHTML("<img src=\"http://farm{$photo['farm']}.static.flickr.com/{$photo['server']}/{$photo['id']}_{$photo['secret']}_{$wgIFI_ThumbType}.jpg\">"); $wgOut->addHTML("<br/>(<a href='#' onclick=\"s2('{$url}', '{$photo['id']}','{$photo['owner']}', '" . urlencode($owner['username']) . "', '" . urlencode($photo['title']) . "');\">" . wfMsg('importfreeimages_importthis') . "</a>)\n"); $wgOut->addHTML("</td>"); if ($i % $wgIFI_ResultsPerRow == $wgIFI_ResultsPerRow - 1) { $wgOut->addHTML("</tr>"); } $i++; } if ($count == 0) { $wgOut->addHTML(wfMsg('importfreeimages_noresults')); } $wgOut->addHTML("</table></center>"); if ($wgIFI_UseAjax) { $s = htmlspecialchars($wgRequest->getVal('q')); $gPage = ($page - 1) * 2; $importjs = HtmlSnips::makeUrlTags('js', array('importfreeimages.js'), '/extensions/ImportFreeImages/', false); $wgOut->addHTML("<br/><br/>" . wfMsg('importfreeimages_results', $wgIFI_AjaxDomain) . "\n\t\t\t\t\t<script type='text/javascript'>\t\t\t\n\t\t\t\t\t\tvar gAjaxDomain = '{$wgIFI_AjaxDomain}';\n\t\t\t\t\t\tvar gInitialSearch = '{$s}';\n\t\t\t\t\t\tvar gPage = {$gPage};\n\t\t\t\t\t\tvar gImportMsg = '" . wfMsg('importfreeimages_importthis') . "';\n\t\t\t\t\t\tvar gImportMsgManual = '" . wfMsg('importfreeimages_importmanual') . "';\n\t\t\t\t\t\tvar gManualURL= '" . Title::makeTitle(NS_PROJECT, 'Manual Import')->getFullURL() . "';\n\t\t\t\t\t\tvar gMoreInfo='" . wfMsg('importfreeimages_moreinfo') . "';\n\t\t\t\t\t</script>\n\t\t\t\t <script src='http://www.google.com/jsapi?key={$wgIFI_AjaxKey}' type='text/javascript'></script>\n\t\t\t\t\t{$importjs}\n\t\t\t\t \t<div id='searchform' style='width:200px; display:none;'>Loading...</div>\n\t \t\t\t<div id='ajax_results'></div>\n\t\t\t\t"); } $page = $page + 1; $wgOut->addHTML("</form>"); $wgOut->addHTML("<br/>" . $sk->makeLinkObj($importPage, wfMsg('importfreeimages_next', $wgIFI_ResultsPerPage), "p={$page}&q=" . urlencode($q))); $wgOut->addHTML("</div>"); } }
/** * List Flickr images matching search terms and our license requirements. * * This method is used by the Findimages class later in this file. * * @param $query search keywords for flickr search * @return JSON listing flickr images */ public function findImagesFlickr($query, $page = 1) { global $IP, $wgUser; require_once $IP . '/extensions/3rdparty/phpFlickr-2.3.1/phpFlickr.php'; $flickr = new phpFlickr(WH_FLICKR_API_KEY); // licence info: // http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html // details on selected licences: // <license id="4" name="Attribution License" // url="http://creativecommons.org/licenses/by/2.0/" /> // <license id="5" name="Attribution-ShareAlike License" // url="http://creativecommons.org/licenses/by-sa/2.0/" /> $images = $flickr->photos_search(array('text' => $query, 'tag_mode' => 'all', 'page' => intval($page), 'per_page' => self::RESULTS_PER_PAGE, 'license' => '4,5', 'extras' => 'url_t,url_l,url_m', 'sort' => 'relevance')); if ($images) { $total = intval($images['total']); $photos = array(); foreach ($images['photo'] as $image) { // remove file extension if there was one in the title $title = preg_replace('@\\.(jpg|gif|png)$@i', '', $image['title']); $details = array('photoid' => @$image['id'], 'ownerid' => @$image['owner'], 'name' => $title . '.jpg', 'url' => @$image['url_m'], 'url_l' => @$image['url_l']); $photos[] = array('found' => true, 'thumb_url' => @$image['url_t'], 'details' => json_encode($details)); } } else { $total = 0; } $next_available = min(self::RESULTS_PER_PAGE, $total - $page * self::RESULTS_PER_PAGE); $userid = $wgUser->getID(); $formattedTotal = number_format($images['total'], 0, '', ','); $vars = array('msg' => wfMsg('eiu-flickrresults', $formattedTotal), 'photos' => $photos, 'page' => $page, 'next_available' => $next_available); //IIA zero results message global $wgRequest; if ($wgRequest->getVal('intro-image-adder')) { if ($formattedTotal == 0) { $vars['msg'] = "<span class='iia_results'>" . wfMsgWikiHtml('iia-eiu-flickrresults-none') . "</span>\n"; } else { $vars['msg'] = "<span class='iia_results'>" . wfMsgWikiHtml('iia-eiu-flickrresults', $formattedTotal) . "</span>\n"; } } return json_encode($vars); }
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; } }
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">←</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">→</span>', 'flickr-photostream') . '</a>' . '</div>'; } $ris .= '</div>'; } } } } $shortcode_unique_id++; return $ris; }
float:left; position:relative; width:100px; height:100px; text-align:center; } section article ul li a { margin:auto auto !important; } </style> </head> <body> <?php require_once "../phpFlickr-3.1/phpFlickr.php"; $f = new phpFlickr("30a76f0599151dad78cec3e6c2ee380e", "422a6372d3fc5dfc"); $recent = $f->photos_search(array("tags" => "race,queen,asian", "tag_mode" => "all", "per_page" => "20", "page" => "1")); $page = $recent['page']; $pages = $recent['pages']; $perpage = $recent['perpage']; $total = $recent['total']; ?> <header> <h1>Resultados de la búsqueda: Total [<?php echo $total; ?> ] pagina: <?php echo $page; ?> </h1> </header> <section>