PageRenderTime 57ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/falbum/FAlbum.class.php

https://github.com/jdickie/mithpressbeta
PHP | 1980 lines | 1432 code | 449 blank | 99 comment | 394 complexity | 8b79aa14136d5674ae02bc49cbb04a1e MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. Copyright (c) 2007
  4. http://www.gnu.org/licenses/gpl.txt
  5. This file is part of FAlbum.
  6. FAlbum is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. define('FALBUM_VERSION', '0.7.1');
  19. define('FALBUM_PATH', dirname(__FILE__));
  20. define('FALBUM_DO_NOT_CACHE', 0);
  21. define('FALBUM_CACHE_EXPIRE_SHORT', 3600); //How many seconds to wait between refreshing cache (default = 3600 seconds - hour)
  22. define('FALBUM_CACHE_EXPIRE_LONG', 604800); //How many seconds to wait between refreshing cache (default = 604800 seconds - 1 week)
  23. define('FALBUM_API_KEY', '15c8257735c58c6fb497def1ab289f96');
  24. define('FALBUM_SECRET', '9220711d42110dbd');
  25. define('FALBUM_FLICKR_URL_IMAGE_1', 'http://farm');
  26. define('FALBUM_FLICKR_URL_IMAGE_2', '.static.flickr.com');
  27. class FAlbum {
  28. var $options = none;
  29. var $can_edit;
  30. var $show_private;
  31. var $has_error;
  32. var $error_detail;
  33. var $logger;
  34. var $template;
  35. function FAlbum() {
  36. require_once FALBUM_PATH.'/lib/Log.php';
  37. // Init Lang
  38. include_once(FALBUM_PATH . '/falbum-lang.php');
  39. //
  40. $this->has_error = false;
  41. $this->error_detail = null;
  42. $this->options = $this->get_options();
  43. $this->can_edit = $this->_can_edit();
  44. $this->show_private = $this->_show_private();
  45. $this->_construct_template($this->options['style']);
  46. $conf = array ('title' => 'FAlbum Log Output');
  47. if ($this->can_edit == true) {
  48. //this->logger = & Log :: factory('fwin', 'LogWindow', '', $conf);
  49. //$this->logger = & Log :: factory('display', 'LogWindow', '', $conf);
  50. $this->logger = & Log :: factory('null', 'LogWindow');
  51. } else {
  52. //$this->logger = & Log :: factory('fwin', 'LogWindow', '', $conf);
  53. $this->logger = & Log :: factory('null', 'LogWindow');
  54. }
  55. //$mask = Log::UPTO(PEAR_LOG_INFO);
  56. //$this->logger->setMask($mask);
  57. }
  58. /* The main function - called in album.php, and can be called in any WP template. */
  59. function show_photos() {
  60. echo $this->show_photos_main();
  61. }
  62. function show_photos_main() {
  63. $album = $_GET['album'];
  64. $photo = $_GET['photo'];
  65. $page = $_GET['page'];
  66. $tags = $_GET['tags'];
  67. $show = $_GET['show'];
  68. $output = '';
  69. $continue = true;
  70. if (!is_null($show)) {
  71. if ($show == 'tags') {
  72. $output = $this->show_tags();
  73. $continue = false;
  74. }
  75. elseif ($show == 'recent') {
  76. $tags = '';
  77. }
  78. }
  79. if ($continue) {
  80. // Show list of albums/photosets (none have been selected yet)
  81. if (is_null($album) && is_null($tags) && is_null($photo)) {
  82. $output = $this->show_albums($page);
  83. }
  84. // Show list of photos in the selected album/photoset
  85. elseif (!is_null($album) && is_null($photo)) {
  86. $output = $this->show_album_thumbnails($album, $page);
  87. }
  88. // Show list of photos of the selected tags
  89. elseif (!is_null($tags) && is_null($photo)) {
  90. $output = $this->show_tags_thumbnails($tags, $page);
  91. }
  92. // Show the selected photo in the slected album/photoset
  93. elseif ((!is_null($album) || !is_null($tags)) && !is_null($photo)) {
  94. $output = $this->show_photo($album, $tags, $photo, $page);
  95. }
  96. }
  97. if ($this->has_error) {
  98. $this->template->reset('error');
  99. $this->template->set('message', $this->error_detail);
  100. $output = $this->template->fetch();
  101. }
  102. return $output;
  103. }
  104. /* Shows list of all albums - this is the first thing you see */
  105. function show_albums($page = 1) {
  106. $this->logger->info("show_albums($page)");
  107. if ($page == '') {
  108. $page = 1;
  109. }
  110. $output = $this->_get_cached_data("showAlbums-$page");
  111. if (!isset ($output)) {
  112. $this->template->reset('albums');
  113. $this->template->set('page_title', $this->get_page_title());
  114. $output = '';
  115. $count = 0;
  116. $albums_list = array ();
  117. if ($this->options['number_recent'] != 0) {
  118. $count ++;
  119. if ($page == 1) {
  120. $resp = $this->_call_flickr_php('flickr.photos.search', array ("user_id" => $this->options['nsid'], "per_page" => '1', "sort" => 'date-taken-desc'));
  121. if (!isset ($resp)) {
  122. return;
  123. }
  124. $server = $resp['photos']['photo']['0']['server'];
  125. $farm = $resp['photos']['photo']['0']['farm'];
  126. $secret = $resp['photos']['photo']['0']['secret'];
  127. $photo_id = $resp['photos']['photo']['0']['id'];
  128. $thumbnail = $this->_create_flickr_image_url($farm, $server, $photo_id, $secret, $this->options['tsize']);
  129. $data['tsize'] = $this->options['tsize'];
  130. $data['url'] = $this->create_url("show/recent/");
  131. $data['title'] = fa__('Recent Photos');
  132. $data['title_d'] = fa__('View all recent photos');
  133. $data['tags_url'] = $this->create_url("show/tags/");
  134. $data['tags_title'] = fa__('Tags');
  135. $data['tags_title_d'] = fa__('Tags');
  136. $data['description'] = fa__('See the most recent photos posted, regardless of which photo set they belong to.');
  137. $data['thumbnail'] = $thumbnail;
  138. $albums_list[] = $data;
  139. }
  140. }
  141. $resp = $this->_call_flickr_php('flickr.photosets.getList', array ("user_id" => $this->options['nsid']));
  142. if (!isset ($resp)) {
  143. return;
  144. }
  145. $countResult = sizeof($resp['photosets']['photoset']);
  146. $photo_title_array = array ();
  147. for ($i = 0; $i < $countResult; $i ++) {
  148. if (($this->options['albums_per_page'] == 0) || (($count >= ($page -1) * $this->options['albums_per_page']) && ($count < $page * $this->options['albums_per_page']))) {
  149. $photos = $resp['photosets']['photoset'][$i]['photos'];
  150. if ($photos != 0) {
  151. $data = null;
  152. $id = $resp['photosets']['photoset'][$i]['id'];
  153. $server = $resp['photosets']['photoset'][$i]['server'];
  154. $farm = $resp['photosets']['photoset'][$i]['farm'];
  155. $primary = $resp['photosets']['photoset'][$i]['primary'];
  156. $secret = $resp['photosets']['photoset'][$i]['secret'];
  157. $title = $this->_unhtmlentities($resp['photosets']['photoset'][$i]['title']['_content']);
  158. $description = $this->_unhtmlentities($resp['photosets']['photoset'][$i]['description']['_content']);
  159. $link_title = $this->_get_link_title($title, $id, $photo_title_array);
  160. $thumbnail = $this->_create_flickr_image_url($farm, $server, $primary, $secret, $this->options['tsize']);
  161. $data['tsize'] = $this->options['tsize'];
  162. $data['url'] = $this->create_url("album/$link_title/");
  163. $data['title'] = $title;
  164. $data['title_d'] = strtr(fa__('View all pictures in #title#'), array ("#title#" => $title));
  165. $data['meta'] = strtr(fa__('This photoset has #num_photots# pictures'), array ("#num_photots#" => $photos));
  166. $data['description'] = $description;
  167. $data['thumbnail'] = $thumbnail;
  168. $albums_list[] = $data;
  169. } else {
  170. $count --;
  171. }
  172. }
  173. $count ++;
  174. }
  175. $this->template->set('albums', $albums_list);
  176. if ($this->options['albums_per_page'] != 0) {
  177. $pages = ceil($count / $this->options['albums_per_page']);
  178. if ($pages > 1) {
  179. $this->template->set('top_paging', $this->_build_paging($page, $pages, 'page/', 'top'));
  180. $this->template->set('bottom_paging', $this->_build_paging($page, $pages, 'page/', 'bottom'));
  181. }
  182. }
  183. $this->template->set('css_type_thumbnails', $this->options['display_dropshadows']);
  184. $this->template->set('remote_url', $this->options['url_falbum_dir']."/falbum-remote.php");
  185. $this->template->set('url_root', $this->options['url_root']);
  186. $output = $this->template->fetch();
  187. $this->_set_cached_data("showAlbums-$page", $output);
  188. }
  189. return $output;
  190. }
  191. /* Shows Thumbnails of all photos in selected album */
  192. function show_album_thumbnails($album, $page = 1) {
  193. $this->logger->info("show_album_thumbnails($album, $page)");
  194. if ($page == '') {
  195. $page = 1;
  196. }
  197. $output = $this->_get_cached_data("showAlbumThumbnails-$album-$page");
  198. if (!isset ($output)) {
  199. $this->template->reset('album-thumbnails');
  200. $this->template->set('page_title', $this->get_page_title());
  201. list ($album_id, $album_title) = $this->_get_album_info($album);
  202. $resp = $this->_call_flickr_php('flickr.photosets.getPhotos', array ("photoset_id" => $album_id));
  203. if (!isset ($resp)) {
  204. return;
  205. }
  206. $countResult = sizeof($resp['photoset']['photo']);
  207. $photo_title_array = array ();
  208. $thumbnails_list = array ();
  209. $count = 0;
  210. for ($i = 0; $i < $countResult; $i ++) {
  211. if (($this->options['photos_per_page'] == 0) || (($count >= ($page -1) * $this->options['photos_per_page']) && ($count < ($page * $this->options['photos_per_page'])))) {
  212. $photo_id = $resp['photoset']['photo'][$i]['id'];
  213. $photo_title = $resp['photoset']['photo'][$i]['title'];
  214. $server = $resp['photoset']['photo'][$i]['server'];
  215. $farm = $resp['photoset']['photo'][$i]['farm'];
  216. $secret = $resp['photoset']['photo'][$i]['secret'];
  217. $photo_link = $this->_get_link_title($photo_title, $photo_id, $photo_title_array);
  218. $thumbnail = $this->_create_flickr_image_url($farm, $server, $photo_id, $secret, $this->options['tsize']);
  219. $data['tsize'] = $this->options['tsize'];
  220. $data['url'] = $this->create_url("album/$album/page/$page/photo/$photo_link");
  221. $data['title'] = $photo_title;
  222. $data['thumbnail'] = $thumbnail;
  223. $thumbnails_list[] = $data;
  224. }
  225. $count ++;
  226. }
  227. if ($this->options['photos_per_page'] != 0) {
  228. $pages = ceil($countResult / $this->options['photos_per_page']);
  229. if ($pages > 1) {
  230. $this->template->set('top_paging', $this->_build_paging($page, $pages, 'album/'.$album.'/page/', 'top'));
  231. $this->template->set('bottom_paging', $this->_build_paging($page, $pages, 'album/'.$album.'/page/', 'bottom'));
  232. }
  233. }
  234. $this->template->set('url', $this->create_url());
  235. $this->template->set('album_title', $album_title);
  236. $this->template->set('album_id', $album_id);
  237. $this->template->set('photos_label', fa__('Photos'));
  238. $this->template->set('slide_show_label', fa__('View as a slide show'));
  239. $this->template->set('thumbnails', $thumbnails_list);
  240. $this->template->set('css_type_thumbnails', $this->options['display_dropshadows']);
  241. $this->template->set('remote_url', $this->options['url_falbum_dir']."/falbum-remote.php");
  242. $this->template->set('url_root', $this->options['url_root']);
  243. $output = $this->template->fetch();
  244. $this->_set_cached_data("showAlbumThumbnails-$album-$page", $output);
  245. }
  246. return $output;
  247. }
  248. /* Shows thumbnails for all Recent and Tag thumbnails */
  249. function show_tags_thumbnails($tags, $page = 1) {
  250. $this->logger->info("show_tags_thumbnails($tags, $page)");
  251. if ($page == '') {
  252. $page = 1;
  253. }
  254. $output = $this->_get_cached_data("show_tags_thumbnails-$tags-$page");
  255. if (!isset ($output)) {
  256. $this->template->reset('tag-thumbnails');
  257. $this->template->set('page_title', $this->get_page_title());
  258. $output = '';
  259. if ($tags == '') {
  260. // Get recent photos
  261. if ($this->options['number_recent'] == -1) {
  262. $resp = $this->_call_flickr_php('flickr.photos.search', array ('user_id' => $this->options['nsid'], 'sort' => 'date-taken-desc', 'per_page' => $this->options['photos_per_page'], 'page' => $page));
  263. } else {
  264. $resp = $this->_call_flickr_php('flickr.photos.search', array ('user_id' => $this->options['nsid'], 'sort' => 'date-taken-desc', 'per_page' => $this->options['number_recent'], 'page' => '1'));
  265. }
  266. } else {
  267. $resp = $this->_call_flickr_php('flickr.photos.search', array ('user_id' => $this->options['nsid'], 'tags' => $tags, 'tag_mode' => 'all', 'per_page' => $this->options['photos_per_page'], 'page' => $page));
  268. }
  269. if (!isset ($resp)) {
  270. return;
  271. }
  272. $countResult = sizeof($resp['photos']['photo']);
  273. if ($tags == '') {
  274. $urlPrefix = 'show/recent/page/';
  275. $this->template->set('recent_label', fa__('Recent Photos'));
  276. } else {
  277. $urlPrefix = "tags/$tags/page/";
  278. $this->template->set('tag_url', $this->create_url('show/tags'));
  279. $this->template->set('tags_label', fa__('Tags'));
  280. $this->template->set('tags', $tags);
  281. }
  282. $photo_title_array = array ();
  283. $thumbnails_list = array ();
  284. $count = 0;
  285. for ($i = 0; $i < $countResult; $i ++) {
  286. if (($this->options['photos_per_page'] == 0) || $tags != '' || $this->options['number_recent'] == -1 || (($count >= ($page -1) * $this->options['photos_per_page']) && ($count < ($page * $this->options['photos_per_page'])))) {
  287. $photo_id = $resp['photos']['photo'][$i]['id'];
  288. $photo_title = $resp['photos']['photo'][$i]['title'];
  289. $server = $resp['photos']['photo'][$i]['server'];
  290. $farm = $resp['photos']['photo'][$i]['farm'];
  291. $secret = $resp['photos']['photo'][$i]['secret'];
  292. $photo_link = $this->_get_link_title($photo_title, $photo_id, $photo_title_array);
  293. $thumbnail = $this->_create_flickr_image_url($farm, $server, $photo_id, $secret, $this->options['tsize']);
  294. $data['tsize'] = $this->options['tsize'];
  295. $data['url'] = $this->create_url($urlPrefix."$page/photo/$photo_link");
  296. $data['title'] = $photo_title;
  297. $data['thumbnail'] = $thumbnail;
  298. $thumbnails_list[] = $data;
  299. }
  300. $count ++;
  301. }
  302. if ($this->options['photos_per_page'] != 0) {
  303. $this->logger->info("tags($tags)");
  304. $this->logger->info("number_recent->".$this->options['number_recent']);
  305. if ($tags == '' && $this->options['number_recent'] != -1) {
  306. $this->logger->info("here");
  307. $pages = ceil($this->options['number_recent'] / $this->options['photos_per_page']);
  308. } else {
  309. $pages = $resp['photos']['pages'];
  310. }
  311. $this->logger->info("pages($pages)");
  312. if ($pages > 1) {
  313. $this->template->set('top_paging', $this->_build_paging($page, $pages, $urlPrefix, 'top'));
  314. $this->template->set('bottom_paging', $this->_build_paging($page, $pages, $urlPrefix, 'bottom'));
  315. }
  316. }
  317. $this->template->set('thumbnails', $thumbnails_list);
  318. $this->template->set('url', $this->create_url());
  319. $this->template->set('photos_label', fa__('Photos'));
  320. $this->template->set('css_type_thumbnails', $this->options['display_dropshadows']);
  321. $this->template->set('remote_url', $this->options['url_falbum_dir']."/falbum-remote.php");
  322. $this->template->set('url_root', $this->options['url_root']);
  323. $output = $this->template->fetch();
  324. $this->_set_cached_data("show_tags_thumbnails-$tags-$page", $output);
  325. }
  326. return $output;
  327. }
  328. /* Shows the selected photo */
  329. function show_photo($album, $tags, $photo, $page = 1) {
  330. $this->logger->info("show_photo($album, $tags, $photo, $page)");
  331. if ($page == '') {
  332. $page = 1;
  333. }
  334. if ($album == '') {
  335. $album = null;
  336. }
  337. $in_photo = $photo;
  338. $in_album = $album;
  339. $output = $this->_get_cached_data("show_photo-$in_album-$tags-$in_photo-$page");
  340. if (!isset ($output)) {
  341. $this->template->reset('photo');
  342. $this->template->set('page_title', $this->get_page_title());
  343. $this->template->set('album', $album);
  344. $this->template->set('in_tags', $tags);
  345. $output = '';
  346. // Get Prev and Next Photos
  347. if (!is_null($album) && $album != '') {
  348. $url_prefix = "album/$album";
  349. list ($album_id, $album_title) = $this->_get_album_info($album);
  350. $resp = $this->_call_flickr_php('flickr.photosets.getPhotos', array ('photoset_id' => $album_id));
  351. } else {
  352. if ($tags == '') {
  353. $url_prefix = 'show/recent';
  354. $album_title = fa__('Recent Photos');
  355. $resp = $this->_call_flickr_php('flickr.photos.search', array ('user_id' => $this->options['nsid'], 'sort' => 'date-taken-desc', 'per_page' => $this->options['photos_per_page'], 'page' => $page));
  356. } else {
  357. $url_prefix = "tags/$tags";
  358. $album_title = fa__('Tags');
  359. $album_title = $tags;
  360. $resp = $this->_call_flickr_php('flickr.photos.search', array ('user_id' => $this->options['nsid'], 'tags' => $tags, 'tag_mode' => 'all', 'per_page' => $this->options['photos_per_page'], 'page' => $page));
  361. }
  362. }
  363. //Get navigation info
  364. if (!isset ($resp)) {
  365. return;
  366. }
  367. $photo = $this->_get_photo_id($resp, $photo);
  368. if (!is_null($album)) {
  369. $result = $resp['photoset']['photo'];
  370. } else {
  371. $total_pages = $resp['photos']['pages'];
  372. $total_photos = $resp['photos']['total'];
  373. $result = $resp['photos']['photo'];
  374. }
  375. $prev = $tmp_prev = $next = $photo;
  376. $prevPage = $nextPage = $page;
  377. $control = 1;
  378. $photo_title_array = array ();
  379. $tmp_prev_title = '';
  380. $countResult = sizeof($result);
  381. for ($i = 0; $i < $countResult; $i ++) {
  382. $photo_id = $result[$i]['id'];
  383. $photo_title = $result[$i]['title'];
  384. $secret = $result[$i]['secret'];
  385. $server = $result[$i]['server'];
  386. $photo_title = $this->_get_link_title($photo_title, $photo_id, $photo_title_array);
  387. if ($control == 0) {
  388. // Selected photo was the last one, so this one is the next one
  389. $next = $photo_id; // Set ID of the next photo
  390. $next_title = $photo_title;
  391. $next_sec = $secret; // Set ID of the next photo
  392. $next_server = $server; // Set ID of the next photo
  393. break; // Break out of the foreach loop
  394. }
  395. if ($photo_id == $photo) {
  396. // This is the selected photo
  397. $prev = $tmp_prev; // Set ID of the previous photo
  398. $prev_title = $tmp_prev_title;
  399. $control --; // Decrement control variable to tell next iteration of loop that the selected photo was found
  400. if (is_null($album)) {
  401. if ($i == 0 && $page > 1) {
  402. $findPrev = true;
  403. }
  404. if (($i == ($countResult -1)) && ($page < $total_pages)) {
  405. $findNext = true;
  406. }
  407. } else {
  408. if ($this->options['photos_per_page'] > 0) {
  409. $pages = ($countResult / $this->options['photos_per_page']);
  410. if ($page > 1 && ($i % $this->options['photos_per_page']) == 0) {
  411. $prevPage = $prevPage -1;
  412. }
  413. if ($page < $pages && (($i +1) % $this->options['photos_per_page']) == 0) {
  414. $nextPage = $nextPage +1;
  415. }
  416. } else {
  417. $pages = $prevPage = $nextPage = 1;
  418. }
  419. }
  420. }
  421. $tmp_prev = $photo_id; // Keep the last photo in a temporary variable in case next photo is the selected on
  422. $tmp_prev_title = $photo_title;
  423. }
  424. if ($findPrev) {
  425. $prevPage = $prevPage -1;
  426. if ($tags == '') {
  427. $url_prefix = 'show/recent';
  428. $resp = $this->_call_flickr_php('flickr.photos.search', array ('user_id' => $this->options['nsid'], 'sort' => 'date-taken-desc', 'per_page' => $this->options['photos_per_page'], 'page' => $prevPage));
  429. } else {
  430. $url_prefix = "tags/$tags";
  431. $resp = $this->_call_flickr_php('flickr.photos.search', array ('user_id' => $this->options['nsid'], 'tags' => $tags, 'tag_mode' => 'all', 'per_page' => $this->options['photos_per_page'], 'page' => $prevPage));
  432. }
  433. if (!isset ($resp)) {
  434. return;
  435. }
  436. $result = $resp['photos']['photo'];
  437. $countResult = sizeof($result);
  438. $photo_title_array = array ();
  439. for ($i = 0; $i < $countResult; $i ++) {
  440. $prev = $result[$i]['id'];
  441. $prev_title = $result[$i]['title'];
  442. $prev_title = $this->_get_link_title($prev_title, $prev, $photo_title_array);
  443. }
  444. }
  445. if ($findNext) {
  446. $nextPage = $nextPage +1;
  447. if ($tags == '') {
  448. $url_prefix = 'show/recent';
  449. $resp = $this->_call_flickr_php('flickr.photos.search', array ('user_id' => $this->options['nsid'], 'sort' => 'date-taken-desc', 'per_page' => $this->options['photos_per_page'], 'page' => $nextPage));
  450. } else {
  451. $url_prefix = "tags/$tags";
  452. $resp = $this->_call_flickr_php('flickr.photos.search', array ('user_id' => $this->options['nsid'], 'tags' => $tags, 'tag_mode' => 'all', 'per_page' => $this->options['photos_per_page'], 'page' => $nextPage));
  453. }
  454. if (!isset ($resp)) {
  455. return;
  456. }
  457. $result = $resp['photos']['photo'];
  458. $next = $result[0]['id']; // Set ID of the next photo
  459. $next_title = $result[0]['title'];
  460. $next_sec = $result[0]['secret']; // Set ID of the next photo
  461. $next_server = $result[0]['server']; // Set ID of the next photo
  462. $photo_title_array = array ();
  463. $next_title = $this->_get_link_title($next_title, $next, $photo_title_array);
  464. }
  465. $resp = null;
  466. if ($this->options['friendly_urls'] == 'title') {
  467. $nav_next = sanitize_title($next_title);
  468. $nav_prev = sanitize_title($prev_title);
  469. } else {
  470. $nav_next = $next;
  471. $nav_prev = $prev;
  472. }
  473. // Display Photo
  474. $resp = $this->_call_flickr_php('flickr.photos.getInfo', array ('photo_id' => $photo));
  475. if (!isset ($resp)) {
  476. return;
  477. }
  478. $server = $resp['photo']['server'];
  479. $secret = $resp['photo']['secret'];
  480. $photo_id = $resp['photo']['id'];
  481. $title = $this->_unhtmlentities($resp['photo']['title']['_content']);
  482. $date_taken = $resp['photo']['dates']['taken'];
  483. $description = $this->_unhtmlentities(nl2br($resp['photo']['description']['_content']));
  484. $comments = $resp['photo']['comments']['_content'];
  485. //remove $imagex = FALBUM_FLICKR_URL_IMAGE."/{$server}/{$photo}_{$secret}";
  486. //remove $image = $imagex.".jpg"; // Build URL to medium size image
  487. //$next_image = FALBUM_FLICKR_URL_IMAGE."/{$next_server}/{$next}_{$next_sec}.jpg"; // Build URL to medium size image
  488. //$this->template->set('next_image', $next_image);
  489. //Get Next Photo Size Data
  490. $resp_sizes = $this->_call_flickr_php('flickr.photos.getSizes', array ('photo_id' => $next));
  491. if (!isset ($resp_sizes)) {
  492. return;
  493. }
  494. $next_source = '';
  495. $countResult = sizeof($resp_sizes['sizes']['size']);
  496. for ($i = 0; $i < $countResult; $i ++) {
  497. $size = $resp_sizes['sizes']['size'][$i];
  498. if ($size['label'] == 'Medium') {
  499. $next_source = $size['source'];
  500. }
  501. }
  502. $this->template->set('next_image', $next_source);
  503. //Get Current Photo Size Data
  504. $resp_sizes = $this->_call_flickr_php('flickr.photos.getSizes', array ('photo_id' => $photo));
  505. if (!isset ($resp_sizes)) {
  506. return;
  507. }
  508. $orig_w_m = null;
  509. $sizes_list = array ();
  510. $countResult = sizeof($resp_sizes['sizes']['size']);
  511. for ($i = 0; $i < $countResult; $i ++) {
  512. $size = $resp_sizes['sizes']['size'][$i];
  513. $width = $size['width'];
  514. $height = $size['height'];
  515. $source = $size['source'];
  516. if ($size['label'] == 'Square') {
  517. $data['image'] = $source;
  518. $data['display'] = fa__('SQ');
  519. $data['title'] = fa__('Square')." ({$width}x{$height})";
  520. $data['value'] = 'sq';
  521. $sizes_list[] = $data;
  522. }
  523. else if ($size['label'] == 'Thumbnail') {
  524. $data['image'] = $source;
  525. $data['display'] = fa__('T');
  526. $data['title'] = fa__('Thumbnail')." ({$width}x{$height})";
  527. $data['value'] = 't';
  528. $sizes_list[] = $data;
  529. }
  530. else if ($size['label'] == 'Small') {
  531. $data['image'] = $source;
  532. $data['display'] = fa__('S');
  533. $data['title'] = fa__('Small')." ({$width}x{$height})";
  534. $data['value'] = 's';
  535. $sizes_list[] = $data;
  536. }
  537. else if ($size['label'] == 'Medium') {
  538. $image = $source;
  539. $orig_w_m = $width;
  540. $data['image'] = $source;
  541. $data['display'] = fa__('M');
  542. $data['title'] = fa__('Medium')." ({$width}x{$height})";
  543. $data['value'] = 'm';
  544. $sizes_list[] = $data;
  545. }
  546. else if ($size['label'] == 'Large') {
  547. $data['image'] = $source;
  548. $data['display'] = fa__('L');
  549. $data['title'] = fa__('Large')." ({$width}x{$height})";
  550. $data['value'] = 'l';
  551. $sizes_list[] = $data;
  552. }
  553. else if ($size['label'] == 'Original') {
  554. $data['image'] = $source;
  555. $data['display'] = fa__('O');
  556. $data['title'] = fa__('Original')." ({$width}x{$height})";
  557. $data['value'] = 'o';
  558. $sizes_list[] = $data;
  559. }
  560. }
  561. $this->template->set('sizes', $sizes_list);
  562. $this->template->set('home_url', $this->create_url());
  563. $this->template->set('home_label', fa__('Photos'));
  564. $this->template->set('title_url', $this->create_url("$url_prefix/page/{$page}/"));
  565. $this->template->set('title_label', $album_title);
  566. $this->template->set('title', $title);
  567. //Date Taken
  568. $this->template->set('date_taken', strtr(fa__('Taken on: #date_taken#'), array ("#date_taken#" => $date_taken)));
  569. //Tags
  570. $result = $resp['photo']['tags']['tag'];
  571. $countResult = count($result);
  572. if ($countResult > 0) {
  573. $this->template->set('tags_url', $this->create_url('show/tags'));
  574. $this->template->set('tags_label', fa__('Tags'));
  575. $tags_list = array ();
  576. for ($i = 0; $i < $countResult; $i ++) {
  577. $value = $result[$i][raw];
  578. $data['url'] = $this->create_url('tags/'.$result[$i]['_content'].'/');
  579. $data['tag'] = $value;
  580. $tags_list[] = $data;
  581. }
  582. $this->template->set('tags', $tags_list);
  583. }
  584. //Notes
  585. $result = $resp['photo']['notes']['note'];
  586. $notes_countResult = count($result);
  587. if ($notes_countResult > 0) {
  588. if ($this->options['max_photo_width'] > 0 && $this->options['max_photo_width'] < $orig_w_m) {
  589. $scale = $this->options['max_photo_width'] / $orig_w_m; // Notes are relative to Medium Size
  590. } else {
  591. $scale = 1;
  592. }
  593. $notes_list = array ();
  594. for ($i = 0; $i < $notes_countResult; $i ++) {
  595. $value = nl2br($result[$i]['_content']);
  596. $x = 5 + $result[$i]['x'] * $scale;
  597. $y = 5 + $result[$i]['y'] * $scale;
  598. $w = $result[$i]['w'] * $scale;
  599. $h = $result[$i]['h'] * $scale;
  600. $data['title'] = htmlentities($value);
  601. $data['coords'] = ($x).','. ($y).','. ($x + $w -1).','. ($y + $h -1);
  602. $notes_list[] = $data;
  603. }
  604. $this->template->set('notes', $notes_list);
  605. }
  606. //Photo
  607. if ($next != $photo) {
  608. $this->template->set('photo_url', $this->create_url("$url_prefix/page/$nextPage/photo/$nav_next/"));
  609. $this->template->set('photo_title_label', fa__('Click to view next image'));
  610. } else {
  611. $this->template->set('photo_url', $this->create_url("$url_prefix/page/$page/"));
  612. $this->template->set('photo_title_label', fa__('Click to return to album'));
  613. }
  614. $this->template->set('image', $image);
  615. if ($notes_countResult > 0) {
  616. $this->template->set('usemap', " usemap='imgmap'");
  617. }
  618. if ($this->options['max_photo_width'] != '0' && $this->options['max_photo_width'] < $orig_w_m) {
  619. $this->template->set('photo_width', $this->options['max_photo_width']);
  620. } else {
  621. $this->template->set('photo_width', $orig_w_m);
  622. }
  623. // Navigation
  624. if ($prev != $photo) {
  625. $this->template->set('prev_button', $this->_create_button('pageprev', $this->create_url("$url_prefix/page/$prevPage/photo/$nav_prev/"), "&laquo; ".fa__('Previous'), fa__('Previous Photo'), 1));
  626. $this->template->set('prev_page', $prevPage);
  627. $this->template->set('prev_id', $nav_prev);
  628. }
  629. if ($next != $photo) {
  630. $this->template->set('next_button', $this->_create_button('pagenext', $this->create_url("$url_prefix/page/$nextPage/photo/$nav_next/"), "&nbsp;&nbsp; ".fa__('Next')." &raquo;&nbsp;&nbsp;", fa__('Next Photo'), 1));
  631. $this->template->set('next_page', $nextPage);
  632. $this->template->set('next_id', $nav_next);
  633. }
  634. $this->template->set('return_button', $this->_create_button('return', $this->create_url("$url_prefix/page/$page/"), fa__('Album Index'), fa__('Return to album index'), 1));
  635. //Description
  636. $this->template->set('description_orig', $description);
  637. if (trim($description) == '') {
  638. $this->template->set('no_description_text', fa__('click here to add a description'));
  639. $this->template->set('description', '&nbsp;&nbsp;');
  640. } else {
  641. $this->template->set('description', $description);
  642. }
  643. //Meta Information
  644. //Sizes
  645. if ($this->options['display_sizes'] == 'true') {
  646. $this->template->set('sizes_label', fa__('Available Sizes'));
  647. }
  648. // Flickr / Comments
  649. if ($comments > 0) {
  650. $resp_comments = $this->_call_flickr_php('flickr.photos.comments.getList', array ('photo_id' => $photo));
  651. if (isset ($resp_comments)) {
  652. $result = $resp_comments['comments']['comment'];
  653. $notes_countResult = sizeof($result);
  654. $this->logger->info($notes_countResult);
  655. $comments_list = array ();
  656. for ($i = 0; $i < $notes_countResult; $i ++) {
  657. $value = nl2br($result[$i]['_content']);
  658. $author = $result[$i]['author'];
  659. //flickr.people.getInfo
  660. $resp_info = $this->_call_flickr_php('flickr.people.getInfo', array ('user_id' => $author));
  661. if (isset ($resp_info)) {
  662. $data['author_name'] = $resp_info['person']['username']['_content'];
  663. $data['author_url'] = $resp_info['person']['photosurl']['_content'];
  664. $data['author_location'] = $resp_info['person']['location']['_content'];
  665. }
  666. $data['text'] = $this->_unhtmlentities($value);
  667. $comments_list[] = $data;
  668. }
  669. $this->template->set('comments', $comments_list);
  670. }
  671. }
  672. $this->template->set('nsid', $this->options['nsid']);
  673. $this->template->set('photo', $photo);
  674. $this->template->set('flickr_label', fa__('See this photo on Flickr'));
  675. $remote_url = $this->options['url_falbum_dir']."/falbum-remote.php";
  676. $this->template->set('remote_url', $remote_url);
  677. $this->template->set('url_root', $this->options['url_root']);
  678. $this->template->set('photo_id', $photo_id);
  679. //Exif
  680. if (strtolower($this->options['display_exif']) == 'true') {
  681. $this->template->set('exif_data', "{$photo_id}','{$secret}','{$remote_url}");
  682. $this->template->set('exif_label', fa__('Show Exif Data'));
  683. }
  684. $this->template->set('can_edit', $this->can_edit);
  685. //Post Helper
  686. $post_value = '[fa:p:';
  687. if ($tags != '') {
  688. $post_value .= "t=$tags,";
  689. } else
  690. if ($album != '') {
  691. $post_value .= "a=$album,";
  692. }
  693. if ($page != '' and $page != 1) {
  694. $post_value .= "p=$page,";
  695. }
  696. $post_value .= "id=$photo_id,j=l,s=s,l=p]";
  697. $this->template->set('post_value', $post_value);
  698. $this->template->set('css_type_photo', $this->options['display_dropshadows']);
  699. $output = $this->template->fetch();
  700. $this->_set_cached_data("show_photo-$in_album-$tags-$in_photo-$page", $output);
  701. }
  702. return $output;
  703. }
  704. /* Shows all the tag cloud */
  705. function show_tags() {
  706. $this->logger->info("show_tags()");
  707. $output = $this->_get_cached_data('show_tags');
  708. if (!isset ($output)) {
  709. $this->template->reset('show_tags');
  710. $this->template->set('page_title', $this->get_page_title());
  711. $resp = $this->_call_flickr_php('flickr.tags.getListUserPopular', array ('count' => '500', user_id => $this->options['nsid']));
  712. if (!isset ($resp)) {
  713. return;
  714. }
  715. $this->template->reset('tags');
  716. $this->template->set('home_url', $this->create_url());
  717. $this->template->set('home_label', fa__(Photos));
  718. $this->template->set('tags_label', fa__('Tags'));
  719. $result = $resp['who']['tags']['tag'];
  720. $countResult = sizeof($result);
  721. $tagcount = 0;
  722. $maxcount = 0;
  723. for ($i = 0; $i < $countResult; $i ++) {
  724. $tagcount = $result[$i]['count'];
  725. if ($tagcount > $maxcount) {
  726. $maxcount = $tagcount;
  727. }
  728. }
  729. $tags_list = array ();
  730. for ($i = 0; $i < $countResult; $i ++) {
  731. $tagcount = $result[$i]['count'];
  732. $tag = $result[$i]['_content'];
  733. if ($tagcount <= ($maxcount * .1)) {
  734. $tagclass = 'falbum-tag1';
  735. }
  736. elseif ($tagcount <= ($maxcount * .2)) {
  737. $tagclass = 'falbum-tag2';
  738. }
  739. elseif ($tagcount <= ($maxcount * .3)) {
  740. $tagclass = 'falbum-tag3';
  741. }
  742. elseif ($tagcount <= ($maxcount * .5)) {
  743. $tagclass = 'falbum-tag4';
  744. }
  745. elseif ($tagcount <= ($maxcount * .7)) {
  746. $tagclass = 'falbum-tag5';
  747. }
  748. elseif ($tagcount <= ($maxcount * .8)) {
  749. $tagclass = 'falbum-tag6';
  750. } else {
  751. $tagclass = 'falbum-tag7';
  752. }
  753. $data['url'] = $this->create_url("tags/$tag");
  754. $data['class'] = $tagclass;
  755. $data['title'] = $tagcount." ".fa__('photos');
  756. $data['name'] = $tag;
  757. $tags_list[] = $data;
  758. }
  759. $this->template->set('tags', $tags_list);
  760. $remote_url = $this->options['url_falbum_dir']."/falbum-remote.php";
  761. $this->template->set('remote_url', $remote_url);
  762. $output = $this->template->fetch();
  763. $this->_set_cached_data('show_tags', $output);
  764. }
  765. return $output;
  766. }
  767. /* Return EXIF data for the selected photo */
  768. function show_exif($photo_id, $secret) {
  769. $this->logger->info("show_exif($photo_id, $secret)");
  770. $output = $this->_get_cached_data("get_exif-$photo_id-$secret");
  771. if (!isset ($output)) {
  772. $this->template->reset('exif');
  773. $exif_resp = $this->_call_flickr_php('flickr.photos.getExif', array ('photo_id' => $photo_id, 'secret' => $secret), FALBUM_CACHE_EXPIRE_LONG);
  774. if (!isset ($exif_resp)) {
  775. return;
  776. }
  777. $result = $exif_resp['photo']['exif'];
  778. $countResult = sizeof($result);
  779. $exif_list = array ();
  780. for ($i = 0; $i < $countResult; $i ++) {
  781. $label = $result[$i]['label'];
  782. if ($i % 2 == 0) {
  783. $data['class'] = 'even';
  784. } else {
  785. $data['class'] = 'odd';
  786. }
  787. $data['label'] = $label;
  788. $r1 = $result[$i]['clean'];
  789. if (count($r1) > 0) {
  790. $data['data'] = htmlentities($result[$i]['clean']['_content']);
  791. } else {
  792. $data['data'] = htmlentities($result[$i]['raw']['_content']);
  793. }
  794. $exif_list[] = $data;
  795. }
  796. $this->template->set('exif', $exif_list);
  797. $output = $this->template->fetch();
  798. $this->_set_cached_data("get_exif-$photo_id-$secret", $output);
  799. }
  800. return $output;
  801. }
  802. function update_metadata($photo_id, $title, $description) {
  803. $this->logger->info("update_metadata($photo_id, $title, $description)");
  804. if ($this->_can_edit()) {
  805. $resp = $this->_call_flickr_php('flickr.photos.setMeta', array ('photo_id' => $photo_id, 'title' => $title, 'description' => $description), FALBUM_DO_NOT_CACHE, true);
  806. if (!isset ($resp)) {
  807. return;
  808. }
  809. $this->_clear_cached_data();
  810. $resp = $this->_call_flickr_php('flickr.photos.getInfo', array ('photo_id' => $photo_id));
  811. if (!isset ($resp)) {
  812. return;
  813. }
  814. $data['title'] = $resp['photo']['title'];
  815. $data['description'] = nl2br($resp['photo']['description']['_content']);
  816. }
  817. return $data;
  818. }
  819. /* Function to show recent photos - commonly used in the sidebar */
  820. function show_recent($num = 5, $style = 0, $size = '') {
  821. $this->logger->info("show_recent($num, $style, $size)");
  822. if ($size == '') {
  823. $size = $this->options['tsize'];
  824. }
  825. $output = $this->_get_cached_data("show_recent-$num-$style-$size");
  826. if (!isset ($output)) {
  827. $output = '';
  828. $resp = $this->_call_flickr_php('flickr.photos.search', array ('user_id' => $this->options['nsid'], 'per_page' => $num, 'sort' => 'date-taken-desc'));
  829. if (!isset ($resp)) {
  830. return;
  831. }
  832. if ($style == 0) {
  833. $output .= "<ul class='falbum-recent'>\n";
  834. } else {
  835. $output .= "<div class='falbum-recent'>\n";
  836. }
  837. $result = $resp['photos']['photo'];
  838. $countResult = sizeof($result);
  839. for ($i = 0; $i < $countResult; $i ++) {
  840. $server = $result[$i]['server'];
  841. $farm = $result[$i]['farm'];
  842. $secret = $result[$i]['secret'];
  843. $photo_id = $result[$i]['id'];
  844. $photo_title = $result[$i]['title'];
  845. $photo_link = $photo_id;
  846. if ($style == 0) {
  847. $output .= "<li>\n";
  848. } else {
  849. $output .= "<div class='falbum-thumbnail".$this->options['display_dropshadows']."'>";
  850. }
  851. $thumbnail = $this->_create_flickr_image_url($farm, $server, $photo_id, $secret, $size);
  852. $output .= "<a href='".$this->create_url("show/recent/photo/$photo_link/")."'>";
  853. $output .= "<img src='$thumbnail' alt=\"".htmlentities($photo_title)."\" title=\"".htmlentities($photo_title)."\" />";
  854. $output .= "</a>\n";
  855. if ($style == 0) {
  856. $output .= "</li>\n";
  857. } else {
  858. $output .= "</div>\n";
  859. }
  860. }
  861. if ($style == 0) {
  862. $output .= "</ul>\n";
  863. } else {
  864. $output .= "</div>\n";
  865. }
  866. $this->_set_cached_data("show_recent-$num-$style-$size", $output);
  867. }
  868. return $output;
  869. }
  870. /* Function to show a random selection of photos - commonly used in the sidebar */
  871. function show_random($num = 5, $tags = '', $style = 0, $size = '') {
  872. $this->logger->info("show_random($num, $tags, $style, $size)");
  873. if ($size == '') {
  874. $size = $this->options['tsize'];
  875. }
  876. $output = '';
  877. $page = 1;
  878. if ($tags == '') {
  879. $resp = $this->_call_flickr_php('flickr.photos.search', array ('user_id' => $this->options['nsid'], 'sort' => 'date-taken-desc', 'per_page' => $this->options['photos_per_page']));
  880. } else {
  881. $resp = $this->_call_flickr_php('flickr.photos.search', array ('user_id' => $this->options['nsid'], 'tags' => $tags, 'tag_mode' => 'all', 'per_page' => $this->options['photos_per_page'], 'page' => $page));
  882. }
  883. if (!isset ($resp)) {
  884. return;
  885. }
  886. $totalPages = $resp['photos']['pages'];
  887. $total = $resp['photos']['total'];
  888. $no_dups = ($total - $num >= 0);
  889. if ($style == 0) {
  890. $output .= "<ul class='falbum-random'>\n";
  891. } else {
  892. $output .= "<div class='falbum-random'>\n";
  893. }
  894. $rand_array = array ();
  895. for ($j = 0; $j < $num; $j ++) {
  896. $page = mt_rand(1, $totalPages);
  897. if ($tags == '') {
  898. $resp = $this->_call_flickr_php('flickr.photos.search', array ('user_id' => $this->options['nsid'], 'sort' => 'date-taken-desc', 'per_page' => $this->options['photos_per_page'], 'page' => $page));
  899. } else {
  900. $resp = $this->_call_flickr_php('flickr.photos.search', array ('user_id' => $this->options['nsid'], 'tags' => $tags, 'tag_mode' => 'all', 'per_page' => $this->options['photos_per_page'], 'page' => $page));
  901. }
  902. if (!isset ($resp)) {
  903. return;
  904. }
  905. $result = $resp['photos']['photo'];
  906. $countResult = count($result);
  907. $randPhoto = mt_rand(0, $countResult -1);
  908. $photo_id = $result[$randPhoto]['id'];
  909. $dup = false;
  910. if ($no_dups) {
  911. if (in_array($photo_id, $rand_array)) {
  912. $dup = true;
  913. $j --;
  914. } else {
  915. $rand_array[] = $photo_id;
  916. }
  917. }
  918. $this->logger->debug("dup->". ($dup ? 't' : 'f'));
  919. if (!$dup) {
  920. $server = $result[$randPhoto]['server'];
  921. $farm = $result[$randPhoto]['farm'];
  922. $secret = $result[$randPhoto]['secret'];
  923. $photo_title = $result[$randPhoto]['title'];
  924. $photo_link = $photo_id;
  925. if ($style == 0) {
  926. $output .= "<li>\n";
  927. } else {
  928. $output .= "<div class='falbum-thumbnail".$this->options['display_dropshadows']."'>";
  929. }
  930. $thumbnail = $this->_create_flickr_image_url($farm, $server, $photo_id, $secret, $size);
  931. if ($tags != '') {
  932. $output .= "<a href='".$this->create_url("tags/$tags/page/$page/photo/$photo_link/")."'>";
  933. } else {
  934. $output .= "<a href='".$this->create_url("show/recent/page/$page/photo/$photo_link/")."'>";
  935. }
  936. $output .= "<img src='$thumbnail' alt=\"".htmlentities($photo_title)."\" title=\"".htmlentities($photo_title)."\" class='falbum-recent-thumbnail' />";
  937. $output .= "</a>\n";
  938. if ($style == 0) {
  939. $output .= "</li>\n";
  940. } else {
  941. $output .= "</div>\n";
  942. }
  943. }
  944. }
  945. if ($style == 0) {
  946. $output .= "</ul>\n";
  947. } else {
  948. $output .= "</div>\n";
  949. }
  950. return $output;
  951. }
  952. function show_album_tn($album, $size = 'm') {
  953. $this->logger->info("show_album_tn($album)");
  954. $output = $this->_get_cached_data("show_album_tn-$album");
  955. if (!isset ($output)) {
  956. $output = '';
  957. $resp = $this->_call_flickr_php('flickr.photosets.getList', array ("user_id" => $this->options['nsid']));
  958. if (!isset ($resp)) {
  959. return;
  960. }
  961. $photosets = $resp['photosets']['photoset'];
  962. $count = sizeof($photosets);
  963. for ($j = 0; $j < $count; $j ++) {
  964. if ($photosets[$j]['id'] == $album) {
  965. $result = $photosets[$j];
  966. break;
  967. }
  968. }
  969. //$result = $xpath->match("/rsp/photosets/photoset[@id=$album]");
  970. //$result = $result[0];
  971. $photos = $result['photos'];
  972. if ($photos > 0) {
  973. $id = $result['id'];
  974. $server = $result['server'];
  975. $farm = $result['farm'];
  976. $primary = $result['primary'];
  977. $secret = $result['secret'];
  978. $title = $this->_unhtmlentities($result['title']['_content']);
  979. $thumbnail = $this->_create_flickr_image_url($farm, $server, $primary, $secret, $size);
  980. $url = $this->create_url("album/$album/");
  981. $output .= ' <div class=\'falbum-thumbnail'.$this->options['display_dropshadows'].'\'>';
  982. $output .= " <a href='$url' title='$title'>";
  983. $output .= ' <img src="'.$thumbnail.'" alt="" />';
  984. $output .= ' </a>';
  985. $output .= ' </div>';
  986. }
  987. $this->_set_cached_data("show_album_tn-$album", $output);
  988. }
  989. return $output;
  990. }
  991. function show_single_photo($album, $tags, $photo, $page, $size, $linkto) {
  992. $this->logger->info("show_single_photo($album, $tags, $photo, $page, $size, $linkto)");
  993. $output = $this->_get_cached_data("show_single_photo-$album-$tags-$photo-$page-$size-$linkto");
  994. if (!isset ($output)) {
  995. $output = '';
  996. if ($size == 'sq') {
  997. $size = '_s';
  998. }
  999. elseif ($size == 't') {
  1000. $size = '_t';
  1001. }
  1002. elseif ($size == 's') {
  1003. $size = '_m';
  1004. }
  1005. elseif ($size == 'm') {
  1006. $size = '';
  1007. }
  1008. elseif ($size == 'l') {
  1009. $size = '_b';
  1010. }
  1011. elseif ($size == 'o') {
  1012. $size = '_o';
  1013. }
  1014. // Display Photo
  1015. $resp = $this->_call_flickr_php('flickr.photos.getInfo', array ('photo_id' => $photo));
  1016. if (!isset ($resp)) {
  1017. return;
  1018. }
  1019. $id = $resp['photo']['id'];
  1020. $server = $resp['photo']['server'];
  1021. $farm = $resp['photo']['farm'];
  1022. $secret = $resp['photo']['secret'];
  1023. $title = $this->_unhtmlentities($resp['photo']['title']);
  1024. $thumbnail = $this->_create_flickr_image_url($farm, $server, $id, $secret, $size);
  1025. if ($tags != '') {
  1026. $url_prefix = "tags/$tags";
  1027. } else
  1028. if ($album != '') {
  1029. $url_prefix = "album/$album";
  1030. } else {
  1031. $url_prefix = 'show/recent';
  1032. }
  1033. if (isset ($page)) {
  1034. $url_prefix .= '/page/'.$page;
  1035. }
  1036. if (!($linkto == 'i' || $linkto == 'index')) {
  1037. $url_prefix .= '/photo/'.$photo;
  1038. }
  1039. $url = $this->create_url("$url_prefix");
  1040. $output .= ' <div class=\'falbum-thumbnail'.$this->options['display_dropshadows'].'\'>';
  1041. $output .= " <a href='$url' title='$title'>";
  1042. $output .= ' <img src="'.$thumbnail.'" alt="" />';
  1043. $output .= ' </a>';
  1044. $output .= ' </div>';
  1045. $this->_set_cached_data("show_single_photo-$album-$tags-$photo-$page-$size-$linkto", $output);
  1046. }
  1047. return $output;
  1048. }
  1049. /* Creates the URLs used in Falbum */
  1050. function create_url($parms = '') {
  1051. if ($parms != '') {
  1052. $element = explode('/', $parms);
  1053. for ($x = 1; $x < count($element); $x ++) {
  1054. $element[$x] = urlencode($element[$x]);
  1055. }
  1056. if (strtolower($this->options['friendly_urls']) == 'false') {
  1057. $parms = '?'.$element[0].'='.$element[1].'&'.$element[2].'='.$element[3].'&'.$element[4].'='.$element[5].'&'.$element[6].'='.$element[7];
  1058. $parms = str_replace('&=', '', $parms);
  1059. } else {
  1060. $parms = implode('/', $element);
  1061. }
  1062. if ($this->options['photos_per_page'] == 0) {
  1063. $parms = preg_replace("`/page/[0-9]+`", "", $parms);
  1064. }
  1065. }
  1066. return htmlspecialchars($this->options['url_root']."$parms");
  1067. }
  1068. function get_page_title($sep = '&raquo;') {
  1069. $this->logger->info("get_page_title($sep)");
  1070. $_GET = array_merge($_POST,$_GET);
  1071. $album = $_GET['album'];
  1072. $photo = $_GET['photo'];
  1073. $page = $_GET['page'];
  1074. $tags = $_GET['tags'];
  1075. $show = $_GET['show'];
  1076. $this->logger->info("get_page_title_v($album $photo $page $tags $show)");
  1077. if (!is_null($album)) {
  1078. list ($album_id, $album_title) = $this->_get_album_info($album);
  1079. if (!is_null($photo)) {
  1080. $resp = $this->_call_flickr_php('flickr.photosets.getPhotos',
  1081. array ('photoset_id' => $album_id));
  1082. }
  1083. } else {
  1084. if ($show == 'tags') {
  1085. $album_title = fa__('Tags');
  1086. } else
  1087. if ($show == 'recent') {
  1088. $album_title = fa__('Recent Photos');
  1089. if (!is_null($photo)) {
  1090. $resp = $this->_call_flickr_php('flickr.photos.search',
  1091. array ('user_id' => $this->options['nsid'], 'sort' => 'date-taken-desc', 'per_page' => $this->options['photos_per_page'], 'page' => $page));
  1092. }
  1093. } else {
  1094. //$album_title = fa__('Tags');
  1095. $album_title = $tags;
  1096. if (!is_null($photo)) {
  1097. $resp = $this->_call_flickr_php('flickr.photos.search',
  1098. array ('user_id' => $this->options['nsid'], 'tags' => $tags, 'tag_mode' => 'all', 'per_page' => $this->options['photos_per_page'], 'page' => $page));
  1099. }
  1100. }
  1101. }
  1102. if (!is_null($photo)) {
  1103. if (!isset ($resp)) {
  1104. return;
  1105. }
  1106. $photo = $this->_get_photo_id($resp, $photo);
  1107. //$this->logger->debug("photo-$photo");
  1108. //$photo_title = $xpath->getData("//photo[@id='$photo']/@title");
  1109. //$photos = $resp['photos']['photo'];
  1110. if (!is_null($album)) {
  1111. $photos = $resp['photoset']['photo'];
  1112. } else {
  1113. $photos = $resp['photos']['photo'];
  1114. }
  1115. $count = sizeof($photos);
  1116. for ($j = 0; $j < $count; $j ++) {
  1117. if ($photos[$j]['id'] == $photo) {
  1118. $photo_title = $photos[$j]['title'];
  1119. break;
  1120. }
  1121. }
  1122. }
  1123. $title = fa__('Photos');
  1124. if (isset ($album_title)) {
  1125. $title .= '&nbsp;'.$sep.'&nbsp;'.$album_title;
  1126. }
  1127. if (isset ($photo_title)) {
  1128. $title .= '&nbsp;'.$sep.'&nbsp;'.$photo_title;
  1129. }
  1130. return $title;
  1131. }
  1132. function get_options() {
  1133. $falbum_options = array ();
  1134. include('falbum-config.php');
  1135. //echo '<pre>'.print_r($falbum_options, true).'</pre>';
  1136. return $falbum_options;
  1137. }
  1138. /* Function that actually makes the flickr calls */
  1139. function _call_flickr_php($method, $args = array (), $cache_option = FALBUM_CACHE_EXPIRE_SHORT, $post = false) {
  1140. $args = array_merge(array ('method' => $method, 'api_key' => FALBUM_API_KEY, 'format' => 'php_serial'), $args);
  1141. if ($this->_show_private() == 'true' || $post == true) {
  1142. $args = array_merge($args, array ('auth_token' => $this->options['token']));
  1143. }
  1144. ksort($args);
  1145. $auth_sig = '';
  1146. foreach ($args as $key => $data) {
  1147. $auth_sig .= $key.$data;
  1148. }
  1149. $api_sig = '';
  1150. if ($this->_show_private() == 'true' || $post == true) {
  1151. $api_sig = md5(FALBUM_SECRET.$auth_sig);
  1152. }
  1153. $args = array_merge($args, array ('api_sig' => $api_sig));
  1154. ksort($args);
  1155. $url = 'http://www.flickr.com/services/rest/';
  1156. if ($post) {
  1157. $resp = $this->_fopen_url($url, $args, $cache_option, true);
  1158. } else {
  1159. $resp = $this->_get_cached_data($url.implode('-', $args), $cache_option);
  1160. if (!isset ($resp)) {
  1161. $resp = $this->_fopen_url($url, $args, $cache_option, false);
  1162. // only cache successful calls to Flickr
  1163. $pos = strrpos($resp, '"ok"');
  1164. if ($pos !== false) {
  1165. $this->_set_cached_data($url.implode('-', $args), $resp, $cache_option);
  1166. }
  1167. }
  1168. }
  1169. $resp_data = unserialize($resp);
  1170. $this->logger->debug(print_r($resp_data, TRUE));
  1171. return $resp_data;
  1172. }
  1173. /* Function that opens the URLS - uses libcurl by default, else falls back to fsockopen */
  1174. function _fopen_url($url, $args = array (), $cache_option = FALBUM_CACHE_EXPIRE_SHORT, $post = false, $fsocket_timeout = 120) {
  1175. $urlParts = parse_url($url);
  1176. $host = $urlParts['host'];
  1177. $port = (isset ($urlParts['port'])) ? $urlParts['port'] : 80;
  1178. if (!extension_loaded('curl')) {
  1179. /* Use fsockopen */
  1180. $this->logger->debug('request - fsockopen<br />'.htmlentities($url));
  1181. $errno = '';
  1182. $errstr = '';
  1183. if (!$fp = @ fsockopen($host, $port, $errno, $errstr, $fsocket_timeout)) {
  1184. $data = fa__('fsockopen:Flickr server not responding');
  1185. } else {
  1186. $postdata = implode('&', array_map(create_function('$a', 'return $a[0] . \'=\' . urlencode($a[1]);'), $this->_flattenArray('', $args)));
  1187. $this->logger->debug('request - fsockopen<br />'.htmlentities($url).'<br />'.$postdata);
  1188. //if (isset ($postdata)) {
  1189. $post = "POST $url HTTP/1.0\r\nHost: $host\r\nContent-type: application/x-www-form-urlencoded\r\nUser-Agent: Mozilla 4.0\r\nContent-length: ".strlen($postdata)."\r\nConnection: close\r\n\r\n$postdata";
  1190. if (!fwrite($fp, $post)) {
  1191. $data = fa__('fsockopen:Unable to send request');
  1192. }
  1193. //} else {
  1194. // if (!fputs($fp, "GET $url?$postdata HTTP/1.0\r\nHost:$host\r\n\r\n")) {
  1195. // $data = fa__('fsockopen:Unable to send request');
  1196. // }
  1197. //}
  1198. $ndata = null;
  1199. stream_set_timeout($fp, $fsocket_timeout);
  1200. $status = socket_get_status($fp);
  1201. while (!feof($fp) && !$status['timed_out']) {
  1202. $ndata .= fgets($fp, 8192);
  1203. $status = socket_get_status($fp);
  1204. }
  1205. fclose($fp);
  1206. // strip headers
  1207. $sData = split("\r\n\r\n", $ndata, 2);
  1208. $ndata = $sData[1];
  1209. }
  1210. } else {
  1211. /* Use curl */
  1212. $this->logger->debug('request - curl<br />'.htmlentities($url));
  1213. $ch = curl_init();
  1214. curl_setopt($ch, CURLOPT_PORT, $port);
  1215. curl_setopt($ch, CURLOPT_TIMEOUT, $fsocket_timeout);
  1216. curl_setopt($ch, CURLOPT_URL, $url);
  1217. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1218. curl_setopt($ch, CURLOPT_FAILONERROR, 1);
  1219. curl_setopt($ch, CURLOPT_HEADER, false);
  1220. curl_setopt($ch, CURLOPT_POST, true);
  1221. curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
  1222. $ndata = curl_exec($ch);
  1223. $error = curl_error($ch);
  1224. curl_close($ch);
  1225. }
  1226. $this->logger->debug('response - <br />'.htmlentities($ndata));
  1227. return $ndata;
  1228. }
  1229. /* Function that builds the album pages */
  1230. function _build_paging($page, $pages, $urlPrefix, $pos) {
  1231. $sAlbHeader .= "<div class='falbum-navigationBar' id='pages-$pos'>".fa__('Page:')."&nbsp;";
  1232. if ($page > 1 && $pages > 1) {
  1233. $title = strtr(fa__('Go to previous page (#page#)'), array ("#page#" => $page -1));
  1234. $sAlbHeader .= $this->_create_button('pageprev-', $this->create_url($urlPrefix. ($page -1)), fa__('Previous'), $title, 0, '_self', true, $pos);
  1235. }
  1236. for ($i = 1; $i <= $pages; $i ++) {
  1237. // We display 1 ... 14 15 16 17 18 ... 29 when there areā€¦

Large files files are truncated, but you can click here to view the full file