/usr/share/tdiary/js/flickr.js is in tdiary-contrib 5.0.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | /**
* flickr.js: javascript for flickr.rb plugin of tDiary
*
* Copyright (C) 2011 by MATSUOKA Kohei <kmachu@gmail.com>
* You can distribute it under GPL.
*/
$(function() {
var userId = $tDiary.plugin.flickr.userId;
var apiKey = $tDiary.plugin.flickr.apiKey;
var client = new flickrClient(apiKey);
if (userId == undefined) {
$('#flickr_photos').append('[ERROR] flickr.rb: User ID is not specified.');
}
$('#flickr_search').click(function() {
$('#flickr_photo_size').show();
$('#flickr_photos').empty();
$('#flickr_photos').append('Loading...');
console.log("start getPublicPhotos()");
var searchCount = $('#flickr_search_count').val();
var searchText = $('#flickr_search_text').val();
if (searchText == "") {
client.getPublicPhotos(userId, searchCount, showPhotos);
} else {
client.searchPhotos(userId, searchCount, searchText, showPhotos);
}
});
function showPhotos(data) {
console.log(data);
console.log("end getPublicPhotos()");
var target = $('#flickr_photos');
target.empty();
$.each(data.photos.photo, function(i, photo) {
var src = client.photoUrl(photo, "square");
$('<img>')
.attr({id: photo.id, src: src, title: photo.title})
.css({margin: "2px", border: "1px solid #999", cursor: "pointer"})
.click(function(event) {
var size = $('input[name=flickr_photo_size]:checked').val();
var tag = $.makePluginTag("flickr '" + event.target.id + "', '" + size + "'");
$('#body').insertAtCaret(tag);
})
.appendTo(target);
});
}
$('#flickr_photo_size').hide();
});
/**
* a Flickr API client for JavaScript
*/
flickrClient = function(apiKey) {
this.baseUrl = 'https://api.flickr.com/services/rest/?';
this.apiKey = apiKey;
}
flickrClient.prototype = {
/**
* return photo URL for this photo
* @param {Object} photo
* @param {String} size
* @return
*/
call: function(method, params, callback) {
params = $.extend({
api_key: this.apiKey,
method: method,
format: 'json'
}, params);
$.ajax({
url: this.baseUrl + this.serialize(params),
dataType: "jsonp",
jsonp: "jsoncallback",
success: function(data, textStatus) {
if (data.stat != "ok") {
alert("failed to call Flickr API: " + data.message);
return;
}
callback(data);
}
});
},
/**
* return photo URL for this photo
* @param {Object} photo
* @param {String} size
* @return
*/
photoUrl: function(photo, size) {
if (typeof size == "undefined") {
size = "small";
}
var url = "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/" + photo.id + "_" + photo.secret;
url += {
square: "_s",
thumbnail: "_t",
small: "_m",
medium: "",
large: "_b"
}[size];
return url + ".jpg";
},
/**
* return Flickr web URL for this photo
* @param {Object} user
* @param {Object} photo
* @return
*/
webUrl: function(user, photo) {
return user.photosurl._content + photo.id;
},
/**
* convert hash format parameter to query string
* @param {Object} params
* @return
*/
serialize: function(params) {
var query = [];
$.each(params, function(key, val){ query.push(key + "=" + val)});
return query.join("&");
},
getPublicPhotos: function(userId, perPage, callback) {
var method = 'flickr.people.getPublicPhotos';
var params = {
user_id: userId,
per_page: perPage
};
this.call(method, params, callback);
},
searchPhotos: function(userId, perPage, text, callback) {
var method = 'flickr.photos.search';
var params = {
user_id: userId,
per_page: perPage,
text: text
};
this.call(method, params, callback);
},
findByUsername: function(username, callback) {
var method = 'flickr.people.findByUsername';
var params = {
username: username
};
this.call(method, params, callback);
}
// end of flickrToBlog.flickrClient
};
|