document_slideshow.inc.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is a plugin for the documents tool. It looks for .jpg, .jpeg, .gif, .png
  5. * files (since these are the files that can be viewed in a browser) and creates
  6. * a slideshow with it by allowing to go to the next/previous image.
  7. * You can also have a quick overview (thumbnail view) of all the images in
  8. * that particular folder.
  9. *
  10. * Each slideshow is folder based. Only
  11. * the images of the chosen folder are shown.
  12. *
  13. * This file has two large sections.
  14. * 1. code that belongs in document.php, but to avoid clutter I put the code here
  15. * (not present) 2. the function resize_image that handles the image resizing
  16. *
  17. * @author Patrick Cool, responsible author
  18. * @author Roan Embrechts, minor cleanup
  19. * @package chamilo.document
  20. */
  21. /**
  22. * General code that belongs in document.php
  23. *
  24. * This code should indeed go in documents.php but since document.php is already a really ugly file with
  25. * too much things in one file , I decided to put the code for document.php here and to include this
  26. * file into document.php
  27. */
  28. $accepted_extensions = array('.jpg', '.jpeg', '.gif', '.png', '.bmp','.svg');
  29. // Resetting the images of the slideshow = destroying the slideshow
  30. if (isset($_GET['action']) && $_GET['action'] == 'exit_slideshow') {
  31. Session::write('image_files_only', null);
  32. unset($image_files_only);
  33. }
  34. // We check if there are images in this folder by searching the extensions for .jpg, .gif, .png
  35. // grabbing the list of all the documents of this folder
  36. //$all_files = $fileList['name'];
  37. $array_to_search = !empty($documentAndFolders) && is_array($documentAndFolders) ? $documentAndFolders : array();
  38. if (count($array_to_search) > 0) {
  39. while (list($key) = each($array_to_search)) {
  40. $all_files[] = basename($array_to_search[$key]['path']);
  41. //echo basename($array_to_search[$key]['path']).'<br />';
  42. }
  43. }
  44. // Always show gallery.
  45. $image_present = 1;
  46. /*
  47. if (isset($all_files) && is_array($all_files) && count($all_files) > 0) {
  48. foreach ($all_files as & $file) {
  49. $slideshow_extension = strrchr($file, '.');
  50. $slideshow_extension = strtolower($slideshow_extension);
  51. if (in_array($slideshow_extension, $accepted_extensions)) {
  52. $image_present = 1;
  53. break;
  54. }
  55. }
  56. }*/
  57. $tablename_column = isset($_GET['tablename_column']) ? Security::remove_XSS($_GET['tablename_column']) : 0;
  58. if ($tablename_column == 0) {
  59. $tablename_column = 1;
  60. } else {
  61. $tablename_column = intval($tablename_column) - 1;
  62. }
  63. $tablename_direction = isset($_GET['tablename_direction']) ? Security::remove_XSS($_GET['tablename_direction']) : 'ASC';
  64. $image_files_only = sort_files($array_to_search);
  65. Session::write('image_files_only', $image_files_only);
  66. function sort_files($table)
  67. {
  68. global $tablename_direction, $accepted_extensions;
  69. $temp = array();
  70. foreach ($table as & $file_array) {
  71. if ($file_array['filetype'] == 'file') {
  72. $slideshow_extension = strrchr($file_array['path'], '.');
  73. $slideshow_extension = strtolower($slideshow_extension);
  74. if (!empty($accepted_extensions)) {
  75. if (in_array($slideshow_extension, $accepted_extensions)) {
  76. $start_date = isset($file_array['insert_date']) ? $file_array['insert_date'] : null;
  77. $temp[] = array(
  78. 'file',
  79. basename($file_array['path']),
  80. $file_array['size'],
  81. $start_date,
  82. );
  83. }
  84. }
  85. }
  86. }
  87. if ($tablename_direction == 'DESC') {
  88. usort($temp, 'rsort_table');
  89. } else {
  90. usort($temp, 'sort_table');
  91. }
  92. $final_array = array();
  93. foreach ($temp as & $file_array) {
  94. $final_array[] = $file_array[1];
  95. }
  96. return $final_array;
  97. }
  98. function sort_table($a, $b) {
  99. global $tablename_column;
  100. return strnatcmp($a[$tablename_column], $b[$tablename_column]);
  101. }
  102. function rsort_table($a, $b) {
  103. global $tablename_column;
  104. return strnatcmp($b[$tablename_column], $a[$tablename_column]);
  105. }