PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/xinha/plugins/ImageManager/flickr.php

https://github.com/radicaldesigns/amp
PHP | 263 lines | 189 code | 47 blank | 27 comment | 14 complexity | f310410549273813a1bffb9d03464d78 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, AGPL-1.0
  1. <?php
  2. /**
  3. * Show a list of images in a long horizontal table.
  4. * @author $Author: gogo $
  5. * @version $Id: images.php 877 2007-08-12 15:50:03Z gogo $
  6. * @package ImageManager
  7. */
  8. require_once('config.inc.php');
  9. require_once('Classes/ImageManager.php');
  10. require_once('Classes/Flickr.php');
  11. // Search for youtube videos
  12. $opts = array(
  13. 'per_page'=> 20,
  14. 'sort' => 'relevance',
  15. 'extras' => 'license,owner_name,tags',
  16. 'license' => @$_REQUEST['flkLicense'] ? $_REQUEST['flkLicense'] : flickr_get_default_usage_id(),
  17. );
  18. if(@$_REQUEST['flkSearch'])
  19. {
  20. $opts['text'] = $_REQUEST['flkSearch'];
  21. }
  22. if(@$_REQUEST['flkUsername'])
  23. {
  24. $user_id = flickr_get_user_id($_REQUEST['flkUsername']);
  25. if($user_id)
  26. {
  27. $opts['user_id'] = $user_id;
  28. }
  29. }
  30. $data = flickr_request('flickr.photos.search', $opts);
  31. $records = $data['photos']['photo'];
  32. // For future purposes, we may want an image manager
  33. $relative = '/';
  34. $manager = new ImageManager($IMConfig);
  35. /* ================= OUTPUT/DRAW FUNCTIONS ======================= */
  36. function rip_flickr_data($record)
  37. {
  38. $lics = flickr_get_licenses();
  39. // echo '<pre>'; print_r($lics); die();
  40. $title = $record['title'];
  41. $license = $lics[$record['license']];
  42. // echo '<pre>';print_r($license); die();
  43. $description = '';
  44. $sizes = flickr_request('flickr.photos.getSizes', array('photo_id' => $record['id']));
  45. $sizes = $sizes['sizes'];
  46. $thumbs = array(); // w:h => array( file, file, file)
  47. $largest = array(0,'', 0, 0);
  48. $smallest = array(3000*3000,'', 3000, 3000); // Ok, hacky, sosumi
  49. foreach($sizes['size'] as $thumb)
  50. {
  51. if($thumb['label'] == 'Square') continue; // These are a little smaller than default
  52. if(!isset($thumbs["{$thumb['width']}x{$thumb['height']}"]))
  53. {
  54. $thumbs["{$thumb['width']}x{$thumb['height']}"] = array();
  55. if(($thumb['width'] * $thumb['height']) > $largest[0])
  56. $largest = array($thumb['width'] * $thumb['height'], $thumb['width'] . 'x' . $thumb['height'], $thumb['width'] , $thumb['height']);
  57. if(($thumb['width'] * $thumb['height']) < $smallest[0])
  58. $smallest = array($thumb['width'] * $thumb['height'], $thumb['width'] . 'x' . $thumb['height'], $thumb['width'] , $thumb['height']);
  59. }
  60. $thumbs["{$thumb['width']}x{$thumb['height']}"][] = $thumb;
  61. }
  62. // Find the main image link
  63. $mainImage = $thumbs[$largest[1]];
  64. $mainImage = array_pop($mainImage);
  65. // Find the thumb image link
  66. $thumbImage = $thumbs[$smallest[1]];
  67. $thumbImage = array_pop($thumbImage);
  68. // Final image to pass to manager (use query param to record the embed url)
  69. $combinedImage = $mainImage['source'] .
  70. '?x-flickr-photo='.rawurlencode($record['id']) .
  71. '&x-lic='.rawurlencode($license['x-id']) .
  72. '&x-uid='.rawurlencode($record['owner']) .
  73. '&x-by='.rawurlencode($record['ownername']) .
  74. '&x-tn='.rawurlencode($thumbImage['source']);
  75. return array
  76. (
  77. 'title' => $title,
  78. 'description' => $description,
  79. 'dimensions' => "{$mainImage['width']}x{$mainImage['height']}",
  80. 'license' => $license,
  81. 'mainImage' => $mainImage['source'],
  82. 'thumbImage' => $thumbImage['source'],
  83. 'combinedImage' => $combinedImage,
  84. 'smallest' => $smallest,
  85. 'largest' => $largest,
  86. 'thumbs' => $thumbs,
  87. );
  88. }
  89. function drawFiles($list, &$manager)
  90. {
  91. global $relative;
  92. global $IMConfig;
  93. $IMConfig['ViewMode'] = 'thumbs';
  94. switch($IMConfig['ViewMode'])
  95. {
  96. case 'details':
  97. {
  98. ?>
  99. <script language="Javascript">
  100. <!--
  101. function showPreview(f_url)
  102. {
  103. window.parent.document.getElementById('f_preview').src = window.parent._backend_url + '__function=thumbs&img=' + encodeURIComponent(f_url);
  104. }
  105. //-->
  106. </script>
  107. <table class="listview">
  108. <thead>
  109. <tr><th>Title</th><th>Description</th><th>Dimensions</th></tr></thead>
  110. <tbody>
  111. <?php
  112. foreach($list as $record)
  113. {
  114. extract(rip_flickr_data($record));
  115. ?>
  116. <tr>
  117. <th><a href="#" class="thumb" style="cursor: pointer;" onclick="selectImage('<?php echo xinha_js_encode($combinedImage)?>', '<?php echo xinha_js_encode($title); ?>', <?php echo $largest[2];?>, <?php echo $largest[3]; ?>);return false;" title="<?php echo htmlspecialchars($title); ?> - <?php echo htmlspecialchars($dimensions); ?>" onmouseover="showPreview('<?php echo xinha_js_encode($combinedImage);?>')" onmouseout="showPreview(window.parent.document.getElementById('f_url').value)" ><?php echo htmlspecialchars($title) ?></a></th>
  118. <td><?php echo htmlspecialchars($description); ?></td>
  119. <td><?php echo htmlspecialchars($dimensions); ?>
  120. </tr>
  121. <?php
  122. }
  123. ?>
  124. </tbody>
  125. </table>
  126. <?php
  127. }
  128. break;
  129. case 'thumbs':
  130. default :
  131. {
  132. foreach($list as $record)
  133. {
  134. extract(rip_flickr_data($record));
  135. ?>
  136. <div class="thumb_holder" id="holder_<?php echo asc2hex($combinedImage) ?>">
  137. <a href="#" class="thumb" style="cursor: pointer;" onclick="selectImage('<?php echo xinha_js_encode($combinedImage)?>', '<?php echo xinha_js_encode($title); ?>', <?php echo $largest[2];?>, <?php echo $largest[3]; ?>);return false;" title="<?php echo htmlspecialchars($title); ?> - <?php echo htmlspecialchars($dimensions); ?>">
  138. <img src="<?php print $thumbImage ?>" alt="<?php echo $title; ?> - <?php echo htmlspecialchars($dimensions); ?>"/>
  139. </a>
  140. <div class="flk-license"><a href="<?php echo $license['url'] ?>" target="_blank"><?php echo htmlspecialchars($license['name']) ?></a></div>
  141. </div>
  142. <?php
  143. }
  144. }
  145. }
  146. }//function drawFiles
  147. /**
  148. * No directories and no files.
  149. */
  150. function drawNoResults()
  151. {
  152. ?>
  153. <div class="noResult">No Photos Found</div>
  154. <?php
  155. }
  156. /**
  157. * No directories and no files.
  158. */
  159. function drawErrorBase(&$manager)
  160. {
  161. ?>
  162. <div class="error"><span>Invalid base directory:</span> <?php echo $manager->config['images_dir']; ?></div>
  163. <?php
  164. }
  165. /**
  166. * Utility to convert ascii string to hex
  167. */
  168. function asc2hex ($temp)
  169. {
  170. $len = strlen($temp);
  171. $data = "";
  172. for ($i=0; $i<$len; $i++) $data.=sprintf("%02x",ord(substr($temp,$i,1)));
  173. return $data;
  174. }
  175. ?>
  176. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  177. <html>
  178. <head>
  179. <title>Flickr Picture List</title>
  180. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  181. <link href="<?php print $IMConfig['base_url'];?>assets/imagelist.css" rel="stylesheet" type="text/css" />
  182. <script type="text/javascript">
  183. _backend_url = "<?php print $IMConfig['backend_url']; ?>";
  184. </script>
  185. <script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/dialog.js"></script>
  186. <script type="text/javascript">
  187. /*<![CDATA[*/
  188. if(window.top)
  189. HTMLArea = Xinha = window.top.Xinha;
  190. function hideMessage()
  191. {
  192. var topDoc = window.top.document;
  193. var messages = topDoc.getElementById('messages');
  194. if(messages)
  195. messages.style.display = "none";
  196. }
  197. init = function()
  198. {
  199. __dlg_translate('ImageManager');
  200. hideMessage();
  201. var topDoc = window.top.document;
  202. // update_selected();
  203. }
  204. /*]]>*/
  205. </script>
  206. <script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/images.js"></script>
  207. <script type="text/javascript" src="../../popups/popup.js"></script>
  208. <script type="text/javascript" src="assets/popup.js"></script>
  209. </head>
  210. <body class="flickr">
  211. <?php if ($manager->isValidBase() == false) { drawErrorBase($manager); }
  212. elseif(count($records)) { ?>
  213. <?php drawFiles($records, $manager); ?>
  214. <?php } else { drawNoResults(); } ?>
  215. </body>
  216. </html>