document_slideshow.inc.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php // $Id: document_slideshow.inc.php 21529 2009-06-20 14:01:55Z ivantcholakov $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. * This is a plugin for the documents tool. It looks for .jpg, .jpeg, .gif, .png
  20. * files (since these are the files that can be viewed in a browser) and creates
  21. * a slideshow with it by allowing to go to the next/previous image.
  22. * You can also have a quick overview (thumbnail view) of all the images in
  23. * that particular folder.
  24. *
  25. * Each slideshow is folder based. Only
  26. * the images of the chosen folder are shown.
  27. *
  28. * This file has two large sections.
  29. * 1. code that belongs in document.php, but to avoid clutter I put the code here
  30. * (not present) 2. the function resize_image that handles the image resizing
  31. *
  32. * @author Patrick Cool, responsible author
  33. * @author Roan Embrechts, minor cleanup
  34. * @package dokeos.document
  35. ==============================================================================
  36. */
  37. /*
  38. ==============================================================================
  39. general code that belongs in document.php
  40. this code should indeed go in documents.php but since document.php is already a really ugly file with
  41. too much things in one file , I decided to put the code for document.php here and to include this
  42. file into document.php
  43. ==============================================================================
  44. */
  45. $accepted_extensions = array('.jpg','.jpeg','.gif','.png');
  46. // resetting the images of the slideshow = destroying the slideshow
  47. if (isset($_GET['action']) && $_GET['action'] == 'exit_slideshow') {
  48. $_SESSION['image_files_only'] = null;
  49. unset($image_files_only);
  50. }
  51. // We check if there are images in this folder by searching the extensions for .jpg, .gif, .png
  52. // grabbing the list of all the documents of this folder
  53. //$all_files=$fileList['name'];
  54. $array_to_search = (is_array($docs_and_folders)) ? $docs_and_folders : array();
  55. if (count($array_to_search) > 0) {
  56. while(list ($key) = each ($array_to_search)) {
  57. $all_files[] = basename($array_to_search[$key]['path']);
  58. //echo basename($array_to_search[$key]['path']).'<br>';
  59. }
  60. }
  61. $image_present = 0;
  62. if (count($all_files) > 0) {
  63. foreach ($all_files as $file) {
  64. $slideshow_extension = strrchr($file,'.');
  65. $slideshow_extension = strtolower($slideshow_extension);
  66. if (in_array($slideshow_extension,$accepted_extensions)) {
  67. $image_present = 1;
  68. $image_files_only[] = $file;
  69. }
  70. }
  71. }
  72. $tablename_column = (isset($_GET['tablename_column']) ? Security::remove_XSS($_GET['tablename_column']) : 0);
  73. if ($tablename_column == 0) {
  74. $tablename_column = 1;
  75. } else {
  76. $tablename_column = intval($tablename_column) - 1;
  77. }
  78. $tablename_direction = (isset($_GET['tablename_direction']) ? Security::remove_XSS($_GET['tablename_direction']) : 'ASC');
  79. $image_files_only = sort_files($array_to_search);
  80. $_SESSION['image_files_only'] = $image_files_only;
  81. function sort_files($table) {
  82. global $tablename_direction, $accepted_extensions;
  83. $temp = array();
  84. foreach ($table as $file_array) {
  85. if ($file_array['filetype'] == 'file') {
  86. $slideshow_extension = strrchr($file_array['path'],'.');
  87. $slideshow_extension = strtolower($slideshow_extension);
  88. if (in_array($slideshow_extension,$accepted_extensions)) {
  89. $temp[] = array('file', basename($file_array['path']), $file_array['size'], $file_array['insert_date']);
  90. }
  91. }
  92. }
  93. if ($tablename_direction == 'DESC') {
  94. usort($temp, 'rsort_table');
  95. } else {
  96. usort($temp, 'sort_table');
  97. }
  98. $final_array = array();
  99. foreach ($temp as $file_array) {
  100. $final_array[] = $file_array[1];
  101. }
  102. return $final_array;
  103. }
  104. function sort_table($a, $b) {
  105. global $tablename_column;
  106. return strnatcmp($a[$tablename_column], $b[$tablename_column]);
  107. }
  108. function rsort_table($a, $b) {
  109. global $tablename_column;
  110. return strnatcmp($b[$tablename_column], $a[$tablename_column]);
  111. }
  112. ?>