document.inc.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * EXTRA FUNCTIONS FOR DOCUMENTS TOOL
  5. * @package chamilo.document
  6. */
  7. /**
  8. * Builds the form thats enables the user to
  9. * select a directory to browse/upload in
  10. *
  11. * @param array An array containing the folders we want to be able to select
  12. * @param string The current folder (path inside of the "document" directory, including the prefix "/")
  13. * @param string Group directory, if empty, prevents documents to be uploaded (because group documents cannot be uploaded in root)
  14. * @param boolean Whether to change the renderer (this will add a template <span> to the QuickForm object displaying the form)
  15. * @return string html form
  16. */
  17. function build_directory_selector($folders, $curdirpath, $group_dir = '', $change_renderer = false) {
  18. $folder_titles = array();
  19. if (api_get_setting('use_document_title') == 'true') {
  20. if (is_array($folders)) {
  21. $escaped_folders = array();
  22. foreach ($folders as $key => & $val) {
  23. $escaped_folders[$key] = Database::escape_string($val);
  24. }
  25. $folder_sql = implode("','", $escaped_folders);
  26. $doc_table = Database::get_course_table(TABLE_DOCUMENT);
  27. $sql = "SELECT * FROM $doc_table WHERE filetype='folder' AND path IN ('".$folder_sql."')";
  28. $res = Database::query($sql);
  29. $folder_titles = array();
  30. while ($obj = Database::fetch_object($res)) {
  31. $folder_titles[$obj->path] = $obj->title;
  32. }
  33. }
  34. } else {
  35. if (is_array($folders)) {
  36. foreach ($folders as & $folder) {
  37. $folder_titles[$folder] = basename($folder);
  38. }
  39. }
  40. }
  41. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  42. $form = new FormValidator('selector', 'POST', api_get_self());
  43. $parent_select = $form->addElement('select', 'curdirpath', get_lang('CurrentDirectory'), '', 'onchange="javascript: document.selector.submit();"');
  44. if ($change_renderer) {
  45. $renderer = $form->defaultRenderer();
  46. $renderer->setElementTemplate('<span>{label} : {element}</span> ','curdirpath');
  47. }
  48. // Group documents cannot be uploaded in the root
  49. if (empty($group_dir)) {
  50. $parent_select -> addOption(get_lang('Documents'), '/');
  51. if (is_array($folders)) {
  52. foreach ($folders as & $folder) {
  53. $selected = ($curdirpath == $folder) ? ' selected="selected"' : '';
  54. $path_parts = explode('/', $folder);
  55. $folder_titles[$folder] = cut($folder_titles[$folder], 80);
  56. $label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$folder_titles[$folder];
  57. $parent_select -> addOption($label, $folder);
  58. if ($selected != '') {
  59. $parent_select->setSelected($folder);
  60. }
  61. }
  62. }
  63. } else {
  64. foreach ($folders as & $folder) {
  65. $selected = ($curdirpath==$folder) ? ' selected="selected"' : '';
  66. $label = $folder_titles[$folder];
  67. if ($folder == $group_dir) {
  68. $label = get_lang('Documents');
  69. } else {
  70. $path_parts = explode('/', str_replace($group_dir, '', $folder));
  71. $label = cut($label, 80);
  72. $label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$label;
  73. }
  74. $parent_select -> addOption($label, $folder);
  75. if ($selected != '') {
  76. $parent_select->setSelected($folder);
  77. }
  78. }
  79. }
  80. $form = $form->toHtml();
  81. return $form;
  82. }
  83. /**
  84. * Create a html hyperlink depending on if it's a folder or a file
  85. *
  86. * @param string $www
  87. * @param string $title
  88. * @param string $path
  89. * @param string $filetype (file/folder)
  90. * @param int $visibility (1/0)
  91. * @param int $show_as_icon - if it is true, only a clickable icon will be shown
  92. * @return string url
  93. */
  94. function create_document_link($document_data, $show_as_icon = false, $counter = null, $visibility) {
  95. global $dbl_click_id;
  96. if (isset($_SESSION['_gid'])) {
  97. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  98. } else {
  99. $req_gid = '';
  100. }
  101. $course_info = api_get_course_info();
  102. $www = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document';
  103. $use_document_title = api_get_setting('use_document_title');
  104. // Get the title or the basename depending on what we're using
  105. if ($use_document_title == 'true' && $document_data['title'] != '') {
  106. $title = $document_data['title'];
  107. } else {
  108. $title = basename($document_data['title']);
  109. }
  110. $filetype = $document_data['filetype'];
  111. $size = $filetype == 'folder' ? get_total_folder_size($document_data['path'], api_is_allowed_to_edit(null, true)) : $document_data['size'];
  112. $path = $document_data['path'];
  113. $url_path = urlencode($document_data['path']);
  114. // Add class="invisible" on invisible files
  115. $visibility_class = ($visibility == false) ? ' class="invisible"' : '';
  116. if (!$show_as_icon) {
  117. // Build download link (icon)
  118. $forcedownload_link = ($filetype == 'folder') ? api_get_self().'?'.api_get_cidreq().'&action=downloadfolder&id='.$document_data['id'] : api_get_self().'?'.api_get_cidreq().'&amp;action=download&amp;id='.$document_data['id'];
  119. // Folder download or file download?
  120. $forcedownload_icon = ($filetype == 'folder') ? 'save_pack.png' : 'save.png';
  121. // Prevent multiple clicks on zipped folder download
  122. $prevent_multiple_click = ($filetype == 'folder') ? " onclick=\"javascript: if(typeof clic_$dbl_click_id == 'undefined' || !clic_$dbl_click_id) { clic_$dbl_click_id=true; window.setTimeout('clic_".($dbl_click_id++)."=false;',10000); } else { return false; }\"":'';
  123. }
  124. $target = '_self';
  125. $is_browser_viewable_file = false;
  126. if ($filetype == 'file') {
  127. // Check the extension
  128. $ext = explode('.', $path);
  129. $ext = strtolower($ext[sizeof($ext) - 1]);
  130. // HTML-files an some other types are shown in a frameset by default.
  131. $is_browser_viewable_file = is_browser_viewable($ext);
  132. if ($is_browser_viewable_file) {
  133. //$url = 'showinframes.php?'.api_get_cidreq().'&amp;file='.$url_path.$req_gid;
  134. $url = 'showinframes.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
  135. } else {
  136. // url-encode for problematic characters (we may not call them dangerous characters...)
  137. $path = str_replace('%2F', '/',$url_path).'?'.api_get_cidreq();
  138. //$new_path = '?id='.$document_data['id'];
  139. $url = $www.$path;
  140. }
  141. //$path = str_replace('%2F', '/',$url_path).'?'.api_get_cidreq();
  142. $path = str_replace('%2F', '/',$url_path); //yox view hack otherwise the image can't be well read
  143. $url = $www.$path;
  144. // Disabled fragment of code, there is a special icon for opening in a new window.
  145. //// Files that we want opened in a new window
  146. //if ($ext == 'txt' || $ext == 'log' || $ext == 'css' || $ext == 'js') { // Add here
  147. // $target = '_blank';
  148. //}
  149. } else {
  150. //$url = api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$url_path.$req_gid;
  151. $url = api_get_self().'?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
  152. }
  153. // The little download icon
  154. //$tooltip_title = str_replace('?cidReq='.$_GET['cidReq'], '', basename($path));
  155. $tooltip_title = explode('?', basename($path));
  156. //$tooltip_title = $tooltip_title[0];
  157. $tooltip_title = $title;
  158. $tooltip_title_alt = $tooltip_title;
  159. if ($path == '/shared_folder') {
  160. $tooltip_title_alt = get_lang('UserFolders');
  161. } elseif(strstr($path, 'shared_folder_session_')) {
  162. $tooltip_title_alt = get_lang('UserFolders').' ('.api_get_session_name(api_get_session_id()).')';
  163. } elseif(strstr($tooltip_title, 'sf_user_')) {
  164. $userinfo = Database::get_user_info_from_id(substr($tooltip_title, 8));
  165. $tooltip_title_alt = get_lang('UserFolder').' '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']);
  166. } elseif($path == '/chat_files') {
  167. $tooltip_title_alt = get_lang('ChatFiles');
  168. } elseif($path == '/video') {
  169. $tooltip_title_alt = get_lang('Video');
  170. } elseif($path == '/audio') {
  171. $tooltip_title_alt = get_lang('Audio');
  172. } elseif($path == '/flash') {
  173. $tooltip_title_alt = get_lang('Flash');
  174. } elseif($path == '/images') {
  175. $tooltip_title_alt = get_lang('Images');
  176. } elseif($path == '/images/gallery') {
  177. $tooltip_title_alt = get_lang('DefaultCourseImages');
  178. }
  179. $current_session_id = api_get_session_id();
  180. $copy_to_myfiles = $open_in_new_window_link = null;
  181. $curdirpath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : null;
  182. if (!$show_as_icon) {
  183. if ($filetype == 'folder') {
  184. if (api_is_allowed_to_edit() || api_is_platform_admin() || api_get_setting('students_download_folders') == 'true') {
  185. //filter when I am into shared folder, I can show for donwload only my shared folder
  186. if (is_shared_folder($curdirpath, $current_session_id)) {
  187. if (preg_match('/shared_folder\/sf_user_'.api_get_user_id().'$/', urldecode($forcedownload_link))|| preg_match('/shared_folder_session_'.$current_session_id.'\/sf_user_'.api_get_user_id().'$/', urldecode($forcedownload_link)) || api_is_allowed_to_edit() || api_is_platform_admin()) {
  188. $force_download_html = ($size == 0) ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon($forcedownload_icon, get_lang('Download'), array(),22).'</a>';
  189. }
  190. } elseif(!preg_match('/shared_folder/', urldecode($forcedownload_link)) || api_is_allowed_to_edit() || api_is_platform_admin()) {
  191. $force_download_html = ($size == 0) ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon($forcedownload_icon, get_lang('Download'), array(),22).'</a>';
  192. }
  193. }
  194. } else {
  195. $force_download_html = ($size==0)?'':'<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon($forcedownload_icon, get_lang('Download'), array(),22).'</a>';
  196. }
  197. //copy files to users myfiles
  198. if (api_get_setting('users_copy_files') == 'true' && api_get_user_id() != 0){
  199. $copy_myfiles_link = ($filetype == 'file') ? api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;action=copytomyfiles&amp;id='.$url_path.$req_gid :api_get_self().'?'.api_get_cidreq();
  200. if ($filetype == 'file') {
  201. $copy_to_myfiles = '<a href="'.$copy_myfiles_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon('briefcase.png', get_lang('CopyToMyFiles'), array(),22).'&nbsp;&nbsp;</a>';
  202. }
  203. }
  204. $pdf_icon = '';
  205. $extension = pathinfo($path, PATHINFO_EXTENSION);
  206. if (!api_is_allowed_to_edit() && api_get_setting('students_export2pdf') == 'true' && $filetype == 'file' && in_array($extension, array('html','htm'))) {
  207. $pdf_icon = ' <a style="float:right".'.$prevent_multiple_click.' href="'.api_get_self().'?'.api_get_cidreq().'&action=export_to_pdf&id='.$document_data['id'].'">'.Display::return_icon('pdf.png', get_lang('Export2PDF'),array(), 22).'</a> ';
  208. }
  209. if ($is_browser_viewable_file) {
  210. $open_in_new_window_link = '<a href="'.$www.str_replace('%2F', '/',$url_path).'?'.api_get_cidreq().'" style="float:right"'.$prevent_multiple_click.' target="_blank">'.Display::return_icon('open_in_new_window.png', get_lang('OpenInANewWindow'), array(),22).'&nbsp;&nbsp;</a>';
  211. }
  212. //target="'.$target.'"
  213. if ($filetype == 'file') {
  214. //Sound preview with jplayer
  215. if ( preg_match('/mp3$/i', urldecode($url)) ||
  216. preg_match('/wav$/i', urldecode($url)) ||
  217. preg_match('/ogg$/i', urldecode($url))) {
  218. return '<span style="float:left" '.$visibility_class.'>'.$title.'</span>'.$force_download_html.$copy_to_myfiles.$open_in_new_window_link.$pdf_icon;
  219. } elseif (
  220. //Show preview sith yoxview
  221. preg_match('/swf$/i', urldecode($url)) ||
  222. preg_match('/png$/i', urldecode($url)) ||
  223. preg_match('/gif$/i', urldecode($url)) ||
  224. preg_match('/jpg$/i', urldecode($url)) ||
  225. preg_match('/jpeg$/i', urldecode($url)) ||
  226. preg_match('/bmp$/i', urldecode($url)) ||
  227. preg_match('/svg$/i', urldecode($url))
  228. //preg_match('/html$/i', urldecode($url)) ||
  229. //preg_match('/htm$/i', urldecode($url))
  230. //|| (preg_match('/wav$/', urldecode($url)) && api_get_setting('enable_nanogong') == 'true')
  231. ) {
  232. //yox view
  233. $url = 'showinframesmin.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
  234. $class = 'yoxview';
  235. if ($visibility == false) {
  236. $class = "yoxview invisible";
  237. }
  238. return '<a href="'.$url.'" class="'.$class.'" title="'.$tooltip_title_alt.'" target="yoxview" style="float:left">'.$title.'</a>'.$force_download_html.$copy_to_myfiles.$open_in_new_window_link.$pdf_icon;
  239. } else {
  240. $url = 'showinframes.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
  241. //No yoxview
  242. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" style="float:left" '.$visibility_class.' >'.$title.'</a>'.$force_download_html.$copy_to_myfiles.$open_in_new_window_link.$pdf_icon;
  243. }
  244. } else {
  245. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" '.$visibility_class.' style="float:left">'.$title.'</a>'.$force_download_html.$copy_to_myfiles.$open_in_new_window_link.$pdf_icon;
  246. }
  247. //end copy files to users myfiles
  248. } else {
  249. //Icon column
  250. if (preg_match('/shared_folder/', urldecode($url)) && preg_match('/shared_folder$/', urldecode($url))==false && preg_match('/shared_folder_session_'.$current_session_id.'$/', urldecode($url))==false){
  251. if ($filetype == 'file') {
  252. //Sound preview with jplayer
  253. if ( preg_match('/mp3$/i', urldecode($url)) ||
  254. preg_match('/wav$/i', urldecode($url)) ||
  255. preg_match('/ogg$/i', urldecode($url))) {
  256. $sound_preview = DocumentManager::generate_media_preview($counter);
  257. return $sound_preview ;
  258. } elseif (
  259. //Show preview sith yoxview
  260. preg_match('/swf$/i', urldecode($url)) ||
  261. preg_match('/html$/i', urldecode($url)) ||
  262. preg_match('/htm$/i', urldecode($url)) //|| (preg_match('/wav$/', urldecode($url)) && api_get_setting('enable_nanogong') == 'true')
  263. ) {
  264. $url = 'showinframesmin.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
  265. return '<a href="'.$url.'" class="yoxview" title="'.$tooltip_title_alt.'" target="yoxview"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).Display::return_icon('shared.png', get_lang('ResourceShared'), array('hspace' => '5', 'align' => 'middle', 'height' => 22, 'width' => 22)).'</a>';
  266. } else {
  267. return '<a href="'.$url.'" class="yoxview" title="'.$tooltip_title_alt.'" target="yoxview"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).Display::return_icon('shared.png', get_lang('ResourceShared'), array('hspace' => '5', 'align' => 'middle', 'height' => 22, 'width' => 22)).'</a>';
  268. }
  269. } else {
  270. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).Display::return_icon('shared.png', get_lang('ResourceShared'), array('hspace' => '5', 'align' => 'middle', 'height' => 22, 'width' => 22)).'</a>';
  271. }
  272. } else {
  273. if ($filetype == 'file') {
  274. //Sound preview with jplayer
  275. if ( preg_match('/mp3$/i', urldecode($url)) ||
  276. preg_match('/wav$/i', urldecode($url)) ||
  277. preg_match('/ogg$/i', urldecode($url))) {
  278. $sound_preview = DocumentManager::generate_media_preview($counter);
  279. return $sound_preview ;
  280. } elseif (
  281. //Show preview sith yoxview
  282. preg_match('/swf$/i', urldecode($url)) ||
  283. preg_match('/html$/i', urldecode($url)) ||
  284. preg_match('/htm$/i', urldecode($url)) //|| (preg_match('/wav$/', urldecode($url)) && api_get_setting('enable_nanogong') == 'true')
  285. ) {
  286. $url = 'showinframesmin.php?'.api_get_cidreq().'&id='.$document_data['id'].$req_gid;
  287. return '<a href="'.$url.'" class="yoxview" title="'.$tooltip_title_alt.'" target="yoxview"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).'</a>';
  288. } else {
  289. return '<a href="'.$url.'" class="yoxview" title="'.$tooltip_title_alt.'" target="yoxview"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).'</a>';
  290. }
  291. } else {
  292. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $path).'</a>';
  293. }
  294. }
  295. }
  296. }
  297. /**
  298. * Builds an img html tag for the filetype
  299. *
  300. * @param string $type (file/folder)
  301. * @param string $path
  302. * @return string img html tag
  303. */
  304. function build_document_icon_tag($type, $path) {
  305. $basename = basename($path);
  306. $current_session_id = api_get_session_id();
  307. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  308. if ($type == 'file') {
  309. $icon = choose_image($basename);
  310. } else {
  311. if ($path == '/shared_folder') {
  312. $icon = 'folder_users.gif';
  313. if ($is_allowed_to_edit) {
  314. $basename = get_lang('HelpUsersFolder');
  315. } else {
  316. $basename = get_lang('UserFolders');
  317. }
  318. }elseif(strstr($basename, 'sf_user_')) {
  319. $userinfo = Database::get_user_info_from_id(substr($basename, 8));
  320. $image_path = UserManager::get_user_picture_path_by_id(substr($basename, 8), 'web', false, true);
  321. if ($image_path['file'] == 'unknown.jpg') {
  322. $icon = $image_path['file'];
  323. } else {
  324. $icon = '../upload/users/'.substr($basename, 8).'/'.$image_path['file'];
  325. }
  326. $basename = get_lang('UserFolder').' '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']);}elseif(strstr($path, 'shared_folder_session_')) {
  327. if ($is_allowed_to_edit) {
  328. $basename = '***('.api_get_session_name($current_session_id).')*** '.get_lang('HelpUsersFolder');
  329. } else {
  330. $basename = get_lang('UserFolders').' ('.api_get_session_name($current_session_id).')';
  331. }
  332. $icon = 'folder_users.gif';
  333. } else {
  334. $icon = 'folder_document.gif';
  335. if($path=='/audio'){
  336. $icon = 'folder_audio.gif';
  337. if(api_is_allowed_to_edit()){
  338. $basename=get_lang('HelpDefaultDirDocuments');
  339. }
  340. else{
  341. $basename=get_lang('Audio');
  342. }
  343. }
  344. elseif($path =='/flash'){
  345. $icon = 'folder_flash.gif';
  346. if(api_is_allowed_to_edit()){
  347. $basename=get_lang('HelpDefaultDirDocuments');
  348. }
  349. else{
  350. $basename=get_lang('Flash');
  351. }
  352. }
  353. elseif($path =='/images'){
  354. $icon = 'folder_images.gif';
  355. if(api_is_allowed_to_edit()){
  356. $basename=get_lang('HelpDefaultDirDocuments');
  357. }
  358. else{
  359. $basename=get_lang('Images');
  360. }
  361. }
  362. elseif($path =='/video'){
  363. $icon = 'folder_video.gif';
  364. if(api_is_allowed_to_edit()){
  365. $basename=get_lang('HelpDefaultDirDocuments');
  366. }
  367. else{
  368. $basename=get_lang('Video');
  369. }
  370. }
  371. elseif($path =='/images/gallery'){
  372. $icon = 'folder_gallery.gif';
  373. if(api_is_allowed_to_edit()){
  374. $basename=get_lang('HelpDefaultDirDocuments');
  375. }
  376. else{
  377. $basename=get_lang('Gallery');
  378. }
  379. }
  380. elseif($path =='/chat_files'){
  381. $icon = 'folder_chat.gif';
  382. if(api_is_allowed_to_edit()){
  383. $basename=get_lang('HelpFolderChat');
  384. }
  385. else{
  386. $basename=get_lang('ChatFiles');
  387. }
  388. }
  389. }
  390. }
  391. return Display::return_icon($icon, $basename, array('hspace' => '5', 'align' => 'middle', 'height' => 22, 'width' => 22));
  392. }
  393. /**
  394. * Creates the row of edit icons for a file/folder
  395. *
  396. * @param string $curdirpath current path (cfr open folder)
  397. * @param string $type (file/folder)
  398. * @param string $path dbase path of file/folder
  399. * @param int $visibility (1/0)
  400. * @param int $id dbase id of the document
  401. * @return string html img tags with hyperlinks
  402. */
  403. function build_edit_icons($document_data, $id, $is_template, $is_read_only = 0, $visibility) {
  404. if (isset($_SESSION['_gid'])) {
  405. $req_gid = '&gidReq='.$_SESSION['_gid'];
  406. } else {
  407. $req_gid = '';
  408. }
  409. $document_id = $document_data['id'];
  410. $type = $document_data['filetype'];
  411. $is_read_only = $document_data['readonly'];
  412. $path = $document_data['path'];
  413. $parent_id = DocumentManager::get_document_id(api_get_course_info(), dirname($path));
  414. $curdirpath = dirname($document_data['path']);
  415. $is_certificate_mode = DocumentManager::is_certificate_mode($path);
  416. $curdirpath = urlencode($curdirpath);
  417. $extension = pathinfo($path, PATHINFO_EXTENSION);
  418. // Build URL-parameters for table-sorting
  419. $sort_params = array();
  420. if (isset($_GET['column'])) {
  421. $sort_params[] = 'column='.Security::remove_XSS($_GET['column']);
  422. }
  423. if (isset($_GET['page_nr'])) {
  424. $sort_params[] = 'page_nr='.Security::remove_XSS($_GET['page_nr']);
  425. }
  426. if (isset($_GET['per_page'])) {
  427. $sort_params[] = 'per_page='.Security::remove_XSS($_GET['per_page']);
  428. }
  429. if (isset($_GET['direction'])) {
  430. $sort_params[] = 'direction='.Security::remove_XSS($_GET['direction']);
  431. }
  432. $sort_params = implode('&amp;', $sort_params);
  433. $visibility_icon = ($visibility == 0) ? 'invisible' : 'visible';
  434. $visibility_command = ($visibility == 0) ? 'set_visible' : 'set_invisible';
  435. $modify_icons = '';
  436. // If document is read only *or* we're in a session and the document
  437. // is from a non-session context, hide the edition capabilities
  438. if ($is_read_only /*or ($session_id!=api_get_session_id())*/) {
  439. if (api_is_course_admin() || api_is_platform_admin()) {
  440. if($extension=='svg' && api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true') {
  441. $modify_icons = '<a href="edit_draw.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
  442. } elseif($extension=='png' || $extension=='jpg' || $extension=='jpeg' || $extension=='bmp' || $extension=='gif' ||$extension=='pxd' && api_get_setting('enabled_support_pixlr') == 'true'){
  443. $modify_icons = '<a href="edit_paint.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
  444. } else {
  445. $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
  446. }
  447. } else {
  448. $modify_icons = Display::return_icon('edit_na.png', get_lang('Modify'),'',22);
  449. }
  450. $modify_icons .= '&nbsp;'.Display::return_icon('move_na.png', get_lang('Move'),array(), 22);
  451. if (api_is_allowed_to_edit() || api_is_platform_admin()) {
  452. $modify_icons .= '&nbsp;'.Display::return_icon($visibility_icon.'.png', get_lang('VisibilityCannotBeChanged'),'',22);
  453. }
  454. $modify_icons .= '&nbsp;'.Display::return_icon('delete_na.png', get_lang('Delete'),array(), 22);
  455. } else {
  456. if ($is_certificate_mode) {
  457. // gradebook category doesn't seem to be taken into account
  458. //$modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'&curdirpath=/certificates&selectcat='.$gradebook_category.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
  459. $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&amp;id='.$document_id.$req_gid.'&curdirpath=/certificates">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
  460. } else {
  461. if (api_get_session_id()) {
  462. if ($document_data['session_id'] == api_get_session_id()) {
  463. if ($extension=='svg' && api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true') {
  464. $modify_icons = '<a href="edit_draw.php?'.api_get_cidreq().'&amp;id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
  465. } elseif($extension=='png' || $extension=='jpg' || $extension=='jpeg' || $extension=='bmp' || $extension=='gif' ||$extension=='pxd' && api_get_setting('enabled_support_pixlr') == 'true'){
  466. $modify_icons = '<a href="edit_paint.php?'.api_get_cidreq().'&amp;id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
  467. } else {
  468. $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&amp;id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
  469. }
  470. } else {
  471. $modify_icons .= '&nbsp;'.Display::return_icon('edit_na.png', get_lang('Edit'),array(), 22).'</a>';
  472. }
  473. } else {
  474. if ($extension=='svg' && api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true') {
  475. $modify_icons = '<a href="edit_draw.php?'.api_get_cidreq().'&amp;id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
  476. } elseif($extension=='png' || $extension=='jpg' || $extension=='jpeg' || $extension=='bmp' || $extension=='gif' ||$extension=='pxd' && api_get_setting('enabled_support_pixlr') == 'true'){
  477. $modify_icons = '<a href="edit_paint.php?'.api_get_cidreq().'&amp;id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
  478. } else {
  479. $modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&amp;id='.$document_id.$req_gid.'">'.Display::return_icon('edit.png', get_lang('Modify'),'',22).'</a>';
  480. }
  481. }
  482. }
  483. if ($is_certificate_mode) {
  484. //$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.'&amp;move='.$document_id.$req_gid.'&selectcat='.$gradebook_category.'">'.Display::return_icon('move.png', get_lang('Move'),array(), 22).'</a>';
  485. $modify_icons .= '&nbsp;'.Display::return_icon('move_na.png', get_lang('Move'),array(), 22).'</a>';
  486. $modify_icons .= '&nbsp;'.Display::return_icon($visibility_icon.'.png', get_lang('VisibilityCannotBeChanged'),array(), 22).'</a>';
  487. Display::return_icon($visibility_icon.'.png', get_lang('VisibilityCannotBeChanged'),array(), 22).'</a>';
  488. } else {
  489. if (api_get_session_id()) {
  490. if ($document_data['session_id'] == api_get_session_id()) {
  491. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$parent_id.'&amp;move='.$document_id.$req_gid.'">'.Display::return_icon('move.png', get_lang('Move'),array(), 22).'</a>';
  492. } else {
  493. $modify_icons .= '&nbsp;'.Display::return_icon('move_na.png', get_lang('Move'),array(), 22).'</a>';
  494. }
  495. } else {
  496. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$parent_id.'&amp;move='.$document_id.$req_gid.'">'.Display::return_icon('move.png', get_lang('Move'),array(), 22).'</a>';
  497. }
  498. if (api_is_allowed_to_edit() || api_is_platform_admin()) {
  499. if ($visibility_icon=='invisible'){
  500. $tip_visibility=get_lang('Show');
  501. }else{
  502. $tip_visibility=get_lang('Hide');
  503. }
  504. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$parent_id.'&amp;'.$visibility_command.'='.$id.$req_gid.'&amp;'.$sort_params.'">'.Display::return_icon($visibility_icon.'.png', $tip_visibility,'',22).'</a>';
  505. }
  506. }
  507. if (in_array($path, array('/audio', '/flash', '/images', '/shared_folder', '/video', '/chat_files', '/certificates'))) {
  508. $modify_icons .= '&nbsp;'.Display::return_icon('delete_na.png', get_lang('ThisFolderCannotBeDeleted'),array(), 22);
  509. } else {
  510. if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates' && DocumentManager::get_default_certificate_id(api_get_course_id())==$id) {
  511. //$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;delete='.urlencode($path).$req_gid.'&amp;'.$sort_params.'delete_certificate_id='.$id.'&selectcat='.$gradebook_category.' " onclick="return confirmation(\''.basename($path).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), 22).'</a>';
  512. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'&amp;delete='.urlencode($path).$req_gid.'&amp;'.$sort_params.'delete_certificate_id='.$id.'" onclick="return confirmation(\''.basename($path).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), 22).'</a>';
  513. } else {
  514. if ($is_certificate_mode) {
  515. //$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;delete='.urlencode($path).$req_gid.'&amp;'.$sort_params.'&selectcat='.$gradebook_category.'" onclick="return confirmation(\''.basename($path).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), 22).'</a>';
  516. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'&amp;delete='.urlencode($path).$req_gid.'&amp;'.$sort_params.'" onclick="return confirmation(\''.basename($path).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), 22).'</a>';
  517. } else {
  518. if (api_get_session_id()) {
  519. if ($document_data['session_id'] == api_get_session_id()) {
  520. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'&amp;delete='.urlencode($path).$req_gid.'&amp;'.$sort_params.'" onclick="return confirmation(\''.basename($path).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), 22).'</a>';
  521. } else {
  522. $modify_icons .= '&nbsp;'.Display::return_icon('delete_na.png', get_lang('ThisFolderCannotBeDeleted'),array(), 22);
  523. }
  524. } else {
  525. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'&amp;delete='.urlencode($path).$req_gid.'&amp;'.$sort_params.'" onclick="return confirmation(\''.basename($path).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),array(), 22).'</a>';
  526. }
  527. }
  528. }
  529. }
  530. }
  531. if ($type == 'file' && ($extension == 'html' || $extension == 'htm')) {
  532. if ($is_template == 0) {
  533. if ((isset($_GET['curdirpath']) && $_GET['curdirpath'] != '/certificates') || !isset($_GET['curdirpath'])) {
  534. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;add_as_template='.$id.$req_gid.'&amp;'.$sort_params.'">'.Display::return_icon('wizard.png', get_lang('AddAsTemplate'),array(), 22).'</a>';
  535. }
  536. if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates') {//allow attach certificate to course
  537. $visibility_icon_certificate='nocertificate';
  538. if (DocumentManager::get_default_certificate_id(api_get_course_id())==$id) {
  539. $visibility_icon_certificate='certificate';
  540. $certificate=get_lang('DefaultCertificate');
  541. $preview=get_lang('PreviewCertificate');
  542. $is_preview=true;
  543. } else {
  544. $is_preview=false;
  545. $certificate=get_lang('NoDefaultCertificate');
  546. }
  547. if (isset($_GET['selectcat'])) {
  548. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;selectcat='.Security::remove_XSS($_GET['selectcat']).'&amp;set_certificate='.$id.$req_gid.'&amp;'.$sort_params.'"><img src="../img/'.$visibility_icon_certificate.'.png" border="0" title="'.$certificate.'" alt="" /></a>';
  549. if ($is_preview) {
  550. $modify_icons .= '&nbsp;<a target="_blank" href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;set_preview='.$id.$req_gid.'&amp;'.$sort_params.'" >'.
  551. Display::return_icon('preview_view.png', $preview,'',22).'</a>';
  552. }
  553. }
  554. }
  555. } else {
  556. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;remove_as_template='.$id.$req_gid.'&amp;'.$sort_params.'">'.
  557. Display::return_icon('wizard_na.png', get_lang('RemoveAsTemplate'),'',22).'</a>';
  558. }
  559. $modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&action=export_to_pdf&id='.$id.'">'.Display::return_icon('pdf.png', get_lang('Export2PDF'),array(), 22).'</a>';
  560. }
  561. return $modify_icons;
  562. }
  563. function build_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '') {
  564. $form = '<form name="move_to" action="'.api_get_self().'" method="post">';
  565. $form .= '<input type="hidden" name="move_file" value="'.$move_file.'" />';
  566. $form .= '<div class="row">';
  567. $form .= '<div class="label">';
  568. $form .= get_lang('MoveTo');
  569. $form .= '</div>';
  570. $form .= '<div class="formw">';
  571. $form .= '<select name="move_to">';
  572. // Group documents cannot be uploaded in the root
  573. if ($group_dir == '') {
  574. if ($curdirpath != '/') {
  575. $form .= '<option value="/">'.get_lang('Documents').'</option>';
  576. }
  577. if (is_array($folders)) {
  578. foreach ($folders as & $folder) {
  579. //Hide some folders
  580. if($folder=='/HotPotatoes_files' || $folder=='/certificates' || basename($folder)=='css'){
  581. continue;
  582. }
  583. //Admin setting for Hide/Show the folders of all users
  584. if(api_get_setting('show_users_folders') == 'false' && (strstr($folder, '/shared_folder') || strstr($folder, 'shared_folder_session_'))){
  585. continue;
  586. }
  587. //Admin setting for Hide/Show Default folders to all users
  588. if(api_get_setting('show_default_folders') == 'false' && ($folder=='/images' || $folder=='/flash' || $folder=='/audio' || $folder=='/video' || strstr($folder, '/images/gallery') || $folder=='/video/flv')){
  589. continue;
  590. }
  591. //Admin setting for Hide/Show chat history folder
  592. if(api_get_setting('show_chat_folder') == 'false' && $folder=='/chat_files'){
  593. continue;
  594. }
  595. // You cannot move a file to:
  596. // 1. current directory
  597. // 2. inside the folder you want to move
  598. // 3. inside a subfolder of the folder you want to move
  599. if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) {
  600. $path_displayed = $folder;
  601. // If document title is used, we have to display titles instead of real paths...
  602. if (api_get_setting('use_document_title')) {
  603. $path_displayed = get_titles_of_path($folder);
  604. }
  605. if (empty($path_displayed)) {
  606. $path_displayed = get_lang('Untitled');
  607. }
  608. $form .= '<option value="'.$folder.'">'.$path_displayed.'</option>';
  609. }
  610. }
  611. }
  612. } else {
  613. foreach ($folders as $folder) {
  614. if (($curdirpath != $folder) && ($folder != $move_file) && (substr($folder, 0, strlen($move_file) + 1) != $move_file.'/')) { // Cannot copy dir into his own subdir
  615. if (api_get_setting('use_document_title')) {
  616. $path_displayed = get_titles_of_path($folder);
  617. }
  618. $display_folder = substr($path_displayed,strlen($group_dir));
  619. $display_folder = ($display_folder == '') ? get_lang('Documents') : $display_folder;
  620. $form .= '<option value="'.$folder.'">'.$display_folder.'</option>';
  621. }
  622. }
  623. }
  624. $form .= ' </select>';
  625. $form .= ' </div>';
  626. $form .= ' </div>';
  627. $form .= '<div class="row">';
  628. $form .= ' <div class="label"></div>';
  629. $form .= ' <div class="formw">';
  630. $form .= ' <button type="submit" class="next" name="move_file_submit">'.get_lang('MoveElement').'</button>';
  631. $form .= ' </div>';
  632. $form .= '</div>';
  633. $form .= '</form>';
  634. $form .= '<div style="clear: both; margin-bottom: 10px;"></div>';
  635. return $form;
  636. }
  637. /**
  638. * Gets the path translated with title of docs and folders
  639. * @param string the real path
  640. * @return the path which should be displayed
  641. */
  642. function get_titles_of_path($path) {
  643. global $tmp_folders_titles;
  644. $nb_slashes = substr_count($path, '/');
  645. $tmp_path = '';
  646. $current_slash_pos = 0;
  647. $path_displayed = '';
  648. for ($i = 0; $i < $nb_slashes; $i++) {
  649. // For each folder of the path, retrieve title.
  650. $current_slash_pos = strpos($path, '/', $current_slash_pos + 1);
  651. $tmp_path = substr($path, strpos($path, '/', 0), $current_slash_pos);
  652. if (empty($tmp_path)) {
  653. // If empty, then we are in the final part of the path
  654. $tmp_path = $path;
  655. }
  656. if (!empty($tmp_folders_titles[$tmp_path])) {
  657. // If this path has soon been stored here we don't need a new query
  658. $path_displayed .= $tmp_folders_titles[$tmp_path];
  659. } else {
  660. $sql = 'SELECT title FROM '.Database::get_course_table(TABLE_DOCUMENT).' WHERE path LIKE BINARY "'.$tmp_path.'"';
  661. $rs = Database::query($sql);
  662. $tmp_title = '/'.Database::result($rs, 0, 0);
  663. $path_displayed .= $tmp_title;
  664. $tmp_folders_titles[$tmp_path] = $tmp_title;
  665. }
  666. }
  667. return $path_displayed;
  668. }
  669. /**
  670. * This function displays the name of the user and makes the link tothe user tool.
  671. *
  672. * @param $user_id
  673. * @param $name
  674. * @return a link to the userInfo.php
  675. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  676. * @version february 2006, dokeos 1.8
  677. */
  678. function display_user_link_document($user_id, $name) {
  679. if ($user_id != 0) {
  680. return '<a href="../user/userInfo.php?uInfo='.$user_id.'">'.$name.'</a>';
  681. } else {
  682. return get_lang('Anonymous');
  683. }
  684. }
  685. /**
  686. * Creates form that asks for the directory name.
  687. * @return string html-output text for the form
  688. */
  689. function create_dir_form($current_dir_id) {
  690. global $document_id;
  691. $new_folder_text = '<form action="'.api_get_self().'" method="post">';
  692. $new_folder_text .= '<input type="hidden" name="dir_id" value="'.intval($document_id).'" />';
  693. $new_folder_text .= '<input type="hidden" name="id" value="'.intval($current_dir_id).'" />';
  694. // Form title
  695. $new_folder_text .= '<div class="row"><div class="form_header">'.get_lang('CreateDir').'</div></div>';
  696. // Folder field
  697. $new_folder_text .= '<div class="row">';
  698. $new_folder_text .= '<div class="label"><span class="form_required">*</span>'.get_lang('NewDir').'</div>';
  699. $new_folder_text .= '<div class="formw"><input type="text" name="dirname" /></div>';
  700. $new_folder_text .= '</div>';
  701. // Submit button
  702. $new_folder_text .= '<div class="row">';
  703. $new_folder_text .= '<div class="label">&nbsp;</div>';
  704. $new_folder_text .= '<div class="formw"><button type="submit" class="add" name="create_dir">'.get_lang('CreateFolder').'</button></div>';
  705. $new_folder_text .= '</div>';
  706. $new_folder_text .= '</form>';
  707. $new_folder_text .= '<div style="clear: both; margin-bottom: 10px;"></div>';
  708. return $new_folder_text;
  709. }
  710. /**
  711. * Checks whether the user is in shared folder
  712. * @return return bool Return true when user is into shared folder
  713. */
  714. function is_shared_folder($curdirpath, $current_session_id) {
  715. $clean_curdirpath = Security::remove_XSS($curdirpath);
  716. if($clean_curdirpath== '/shared_folder'){
  717. return true;
  718. }
  719. elseif($clean_curdirpath== '/shared_folder_session_'.$current_session_id){
  720. return true;
  721. }
  722. else{
  723. return false;
  724. }
  725. }
  726. /**
  727. * Checks whether the user is into any user shared folder
  728. * @return return bool Return true when user is in any user shared folder
  729. */
  730. function is_any_user_shared_folder($path, $current_session_id) {
  731. $clean_path = Security::remove_XSS($path);
  732. if(strpos($clean_path,'shared_folder/sf_user_')){
  733. return true;
  734. }
  735. elseif(strpos($clean_path, 'shared_folder_session_'.$current_session_id.'/sf_user_')){
  736. return true;
  737. }
  738. else{
  739. return false;
  740. }
  741. }
  742. /**
  743. * Checks whether the user is into his shared folder or into a subfolder
  744. * @return return bool Return true when user is in his user shared folder or into a subforder
  745. */
  746. function is_my_shared_folder($user_id, $path, $current_session_id) {
  747. $clean_path = Security::remove_XSS($path).'/';
  748. $main_user_shared_folder = '/shared_folder\/sf_user_'.$user_id.'\//';//for security does not remove the last slash
  749. $main_user_shared_folder_session='/shared_folder_session_'.$current_session_id.'\/sf_user_'.$user_id.'\//';//for security does not remove the last slash
  750. if (preg_match($main_user_shared_folder, $clean_path)){
  751. return true;
  752. } elseif(preg_match($main_user_shared_folder_session, $clean_path)) {
  753. return true;
  754. } else {
  755. return false;
  756. }
  757. }
  758. /**
  759. * Check if the file name or folder searched exist
  760. * @return return bool Return true when exist
  761. */
  762. function search_keyword($document_name, $keyword) {
  763. if (api_strripos($document_name, $keyword) !== false){
  764. return true;
  765. } else {
  766. return false;
  767. }
  768. }
  769. /**
  770. * Checks whether a document can be previewed by using the browser.
  771. * @param string $file_extension The filename extension of the document (it must be in lower case).
  772. * @return bool Returns TRUE or FALSE.
  773. */
  774. function is_browser_viewable($file_extension) {
  775. static $allowed_extensions = array(
  776. 'htm', 'html', 'xhtml', 'gif', 'jpg', 'jpeg', 'png', 'pdf', 'swf', 'mp3', 'mp4', 'ogg', 'ogx', 'oga', 'ogv', 'svg',
  777. 'txt', 'log',
  778. 'mpg', 'mpeg',
  779. 'wav'
  780. );
  781. if (!($result = in_array($file_extension, $allowed_extensions))) { // Assignment + a logical check.
  782. return false;
  783. }
  784. switch ($file_extension) {
  785. case 'ogg':
  786. return api_browser_support('ogg');
  787. case 'svg':
  788. return api_browser_support('svg');
  789. }
  790. return $result;
  791. }