document.inc.php 44 KB

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