/files/layout_files_as_simple.php

https://github.com/agnesrambaud/yacs · PHP · 82 lines · 33 code · 17 blank · 32 comment · 10 complexity · 040e58cdaedffd622c9f4563a4db9701 MD5 · raw file

  1. <?php
  2. /**
  3. * layout files as a compact list
  4. *
  5. * This has more than compact, and less than decorated.
  6. *
  7. * @see files/files.php
  8. *
  9. * @author Bernard Paques
  10. * @reference
  11. * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
  12. */
  13. Class Layout_files_as_simple extends Layout_interface {
  14. /**
  15. * list files
  16. *
  17. * @param resource the SQL result
  18. * @return array of resulting items, or NULL
  19. *
  20. * @see skins/layout.php
  21. **/
  22. function &layout(&$result) {
  23. global $context;
  24. // we return an array of ($url => $attributes)
  25. $items = array();
  26. // empty list
  27. if(!SQL::count($result))
  28. return $items;
  29. // sanity check
  30. if(!isset($this->layout_variant))
  31. $this->layout_variant = 'full';
  32. // process all items in the list
  33. while($item =& SQL::fetch($result)) {
  34. // get the main anchor
  35. $anchor =& Anchors::get($item['anchor']);
  36. // download the file directly
  37. $url = Files::get_url($item['id'], 'fetch', $item['file_name']);
  38. // initialize variables
  39. $prefix = $suffix = '';
  40. // flag files that are dead, or created or updated very recently
  41. if($item['create_date'] >= $context['fresh'])
  42. $suffix .= NEW_FLAG;
  43. elseif($item['edit_date'] >= $context['fresh'])
  44. $suffix .= UPDATED_FLAG;
  45. // signal restricted and private files
  46. if($item['active'] == 'N')
  47. $prefix .= PRIVATE_FLAG;
  48. elseif($item['active'] == 'R')
  49. $prefix .= RESTRICTED_FLAG;
  50. // file title or file name
  51. $label = Codes::beautify_title($item['title']);
  52. if(!$label)
  53. $label = ucfirst(str_replace(array('%20', '-', '_'), ' ', $item['file_name']));
  54. // the main anchor link, except on user profiles
  55. if(is_object($anchor) && ($anchor->get_reference() != $this->layout_variant))
  56. $suffix .= ' - <span class="details">'.sprintf(i18n::s('in %s'), Skin::build_link($anchor->get_url(), ucfirst($anchor->get_title()))).'</span>';
  57. // list all components for this item
  58. $items[$url] = array($prefix, $label, $suffix, 'basic', NULL);
  59. }
  60. // end of processing
  61. SQL::free($result);
  62. return $items;
  63. }
  64. }
  65. ?>