示例#1
0
$sortable_data = array();
if (isset($documentAndFolders) && is_array($documentAndFolders)) {
    if ($groupId == 0 || GroupManager::user_has_access($userId, $groupId, GroupManager::GROUP_TOOL_DOCUMENTS)) {
        $count = 1;
        $countedPaths = array();
        $countedPaths = array();
        foreach ($documentAndFolders as $key => $document_data) {
            $row = array();
            $row['id'] = $document_data['id'];
            $row['type'] = $document_data['filetype'];
            // If the item is invisible, wrap it in a span with class invisible.
            $is_visible = DocumentManager::is_visible_by_id($document_data['id'], $courseInfo, $sessionId, api_get_user_id(), false);
            $invisibility_span_open = $is_visible == 0 ? '<span class="muted">' : '';
            $invisibility_span_close = $is_visible == 0 ? '</span>' : '';
            // Size (or total size of a directory)
            $size = $document_data['filetype'] == 'folder' ? get_total_folder_size($document_data['path'], $is_allowed_to_edit) : $document_data['size'];
            // Get the title or the basename depending on what we're using
            if ($document_data['title'] != '') {
                $document_name = $document_data['title'];
            } else {
                $document_name = basename($document_data['path']);
            }
            $row['name'] = $document_name;
            // Data for checkbox
            if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($documentAndFolders) > 1) {
                $row[] = $document_data['id'];
            }
            if (DocumentManager::is_folder_to_avoid($document_data['path'], $is_certificate_mode)) {
                continue;
            }
            // Show the owner of the file only in groups
示例#2
0
 /**
  * Create a html hyperlink depending on if it's a folder or a file
  *
  * @param array $document_data
  * @param int $show_as_icon - if it is true, only a clickable icon will be shown
  * @param int $visibility (1/0)
  * @param int $show_as_icon - if it is true, only a clickable icon will be shown
  * @return string url
  */
 public static function create_document_link($document_data, $show_as_icon = false, $counter = null, $visibility)
 {
     global $dbl_click_id;
     $course_info = api_get_course_info();
     $www = api_get_path(WEB_COURSE_PATH) . $course_info['path'] . '/document';
     $webOdflist = DocumentManager::get_web_odf_extension_list();
     // Get the title or the basename depending on what we're using
     if ($document_data['title'] != '') {
         $title = $document_data['title'];
     } else {
         $title = basename($document_data['path']);
     }
     $filetype = $document_data['filetype'];
     $size = $filetype == 'folder' ? get_total_folder_size($document_data['path'], api_is_allowed_to_edit(null, true)) : $document_data['size'];
     $path = $document_data['path'];
     $url_path = urlencode($document_data['path']);
     // Add class="invisible" on invisible files
     $visibility_class = $visibility == false ? ' class="muted"' : '';
     $forcedownload_link = null;
     $forcedownload_icon = null;
     $prevent_multiple_click = null;
     if (!$show_as_icon) {
         // Build download link (icon)
         $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'];
         // Folder download or file download?
         $forcedownload_icon = $filetype == 'folder' ? 'save_pack.png' : 'save.png';
         // Prevent multiple clicks on zipped folder download
         $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; }\"" : '';
     }
     $target = '_self';
     $is_browser_viewable_file = false;
     if ($filetype == 'file') {
         // Check the extension
         $ext = explode('.', $path);
         $ext = strtolower($ext[sizeof($ext) - 1]);
         // HTML-files an some other types are shown in a frameset by default.
         $is_browser_viewable_file = self::is_browser_viewable($ext);
         if ($is_browser_viewable_file) {
             if ($ext == 'pdf' || in_array($ext, $webOdflist)) {
                 $url = api_get_self() . '?' . api_get_cidreq() . '&amp;action=download&amp;id=' . $document_data['id'];
             } else {
                 $url = 'showinframes.php?' . api_get_cidreq() . '&id=' . $document_data['id'];
             }
         } else {
             // url-encode for problematic characters (we may not call them dangerous characters...)
             $path = str_replace('%2F', '/', $url_path) . '?' . api_get_cidreq();
             $url = $www . $path;
         }
         /*$path = str_replace('%2F', '/', $url_path); //yox view hack otherwise the image can't be well read
           $url = $www . $path;*/
     } else {
         $url = api_get_self() . '?' . api_get_cidreq() . '&id=' . $document_data['id'];
     }
     // The little download icon
     $tooltip_title = $title;
     $tooltip_title_alt = $tooltip_title;
     if ($path == '/shared_folder') {
         $tooltip_title_alt = get_lang('UserFolders');
     } elseif (strstr($path, 'shared_folder_session_')) {
         $tooltip_title_alt = get_lang('UserFolders') . ' (' . api_get_session_name(api_get_session_id()) . ')';
     } elseif (strstr($tooltip_title, 'sf_user_')) {
         $userinfo = api_get_user_info(substr($tooltip_title, 8));
         $tooltip_title_alt = get_lang('UserFolder') . ' ' . $userinfo['complete_name'];
     } elseif ($path == '/chat_files') {
         $tooltip_title_alt = get_lang('ChatFiles');
     } elseif ($path == '/learning_path') {
         $tooltip_title_alt = get_lang('LearningPaths');
     } elseif ($path == '/video') {
         $tooltip_title_alt = get_lang('Video');
     } elseif ($path == '/audio') {
         $tooltip_title_alt = get_lang('Audio');
     } elseif ($path == '/flash') {
         $tooltip_title_alt = get_lang('Flash');
     } elseif ($path == '/images') {
         $tooltip_title_alt = get_lang('Images');
     } elseif ($path == '/images/gallery') {
         $tooltip_title_alt = get_lang('DefaultCourseImages');
     }
     $current_session_id = api_get_session_id();
     $copy_to_myfiles = $open_in_new_window_link = null;
     $curdirpath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : null;
     $send_to = null;
     $checkExtension = $path;
     if (!$show_as_icon) {
         if ($filetype == 'folder') {
             if (api_is_allowed_to_edit() || api_is_platform_admin() || api_get_setting('students_download_folders') == 'true') {
                 //filter when I am into shared folder, I can show for donwload only my shared folder
                 if (DocumentManager::is_shared_folder($curdirpath, $current_session_id)) {
                     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()) {
                         $force_download_html = $size == 0 ? '' : '<a href="' . $forcedownload_link . '" style="float:right"' . $prevent_multiple_click . '>' . Display::return_icon($forcedownload_icon, get_lang('Download'), array(), ICON_SIZE_SMALL) . '</a>';
                     }
                 } elseif (!preg_match('/shared_folder/', urldecode($forcedownload_link)) || api_is_allowed_to_edit() || api_is_platform_admin()) {
                     $force_download_html = $size == 0 ? '' : '<a href="' . $forcedownload_link . '" style="float:right"' . $prevent_multiple_click . '>' . Display::return_icon($forcedownload_icon, get_lang('Download'), array(), ICON_SIZE_SMALL) . '</a>';
                 }
             }
         } else {
             $force_download_html = $size == 0 ? '' : '<a href="' . $forcedownload_link . '" style="float:right"' . $prevent_multiple_click . '>' . Display::return_icon($forcedownload_icon, get_lang('Download'), array(), ICON_SIZE_SMALL) . '</a>';
         }
         // Copy files to users myfiles
         if (api_get_setting('social.allow_social_tool') == 'true' && api_get_setting('document.users_copy_files') == 'true' && !api_is_anonymous()) {
             $copy_myfiles_link = $filetype == 'file' ? api_get_self() . '?' . api_get_cidreq() . '&action=copytomyfiles&id=' . $document_data['id'] : api_get_self() . '?' . api_get_cidreq();
             if ($filetype == 'file') {
                 $copy_to_myfiles = '<a href="' . $copy_myfiles_link . '" style="float:right"' . $prevent_multiple_click . '>' . Display::return_icon('briefcase.png', get_lang('CopyToMyFiles'), array(), ICON_SIZE_SMALL) . '&nbsp;&nbsp;</a>';
             }
             if ($filetype == 'file') {
                 $send_to = Portfolio::share('document', $document_data['id'], array('style' => 'float:right;'));
             }
         }
         $pdf_icon = '';
         $extension = pathinfo($path, PATHINFO_EXTENSION);
         if (!api_is_allowed_to_edit() && api_get_setting('students_export2pdf') == 'true' && $filetype == 'file' && in_array($extension, array('html', 'htm'))) {
             $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(), ICON_SIZE_SMALL) . '</a> ';
         }
         if ($is_browser_viewable_file) {
             $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(), ICON_SIZE_SMALL) . '&nbsp;&nbsp;</a>';
         }
         if ($filetype == 'file') {
             // Sound preview with jplayer
             if (preg_match('/mp3$/i', urldecode($checkExtension)) || preg_match('/wav$/i', urldecode($checkExtension)) && !preg_match('/_chnano_.wav$/i', urldecode($url)) || preg_match('/ogg$/i', urldecode($checkExtension))) {
                 return '<span style="float:left" ' . $visibility_class . '>' . $title . '</span>' . $force_download_html . $send_to . $copy_to_myfiles . $open_in_new_window_link . $pdf_icon;
             } elseif (preg_match('/swf$/i', urldecode($checkExtension)) || preg_match('/png$/i', urldecode($checkExtension)) || preg_match('/gif$/i', urldecode($checkExtension)) || preg_match('/jpg$/i', urldecode($checkExtension)) || preg_match('/jpeg$/i', urldecode($checkExtension)) || preg_match('/bmp$/i', urldecode($checkExtension)) || preg_match('/svg$/i', urldecode($checkExtension)) || preg_match('/wav$/i', urldecode($checkExtension)) && preg_match('/_chnano_.wav$/i', urldecode($checkExtension)) && api_get_setting('document.enable_nanogong') == 'true') {
                 // Simpler version of showinframesmin.php with no headers
                 $url = 'show_content.php?' . api_get_cidreq() . '&id=' . $document_data['id'];
                 $class = 'ajax';
                 if ($visibility == false) {
                     $class = "ajax invisible";
                 }
                 return Display::url($title, $url, ['class' => $class, 'title' => $tooltip_title_alt, 'data-title' => $title, 'style' => 'float: left;']) . $force_download_html . $send_to . $copy_to_myfiles . $open_in_new_window_link . $pdf_icon;
             } else {
                 // For PDF Download the file.
                 $pdfPreview = null;
                 if ($ext != 'pdf' && !in_array($ext, $webOdflist)) {
                     $url = 'showinframes.php?' . api_get_cidreq() . '&id=' . $document_data['id'];
                 } else {
                     $pdfPreview = Display::url(Display::return_icon('preview.gif', get_lang('Preview')), api_get_path(WEB_CODE_PATH) . 'document/showinframes.php?' . api_get_cidreq() . '&id=' . $document_data['id'], array('style' => 'float:right'));
                 }
                 // No plugin just the old and good showinframes.php page
                 return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" style="float:left" ' . $visibility_class . ' >' . $title . '</a>' . $pdfPreview . $force_download_html . $send_to . $copy_to_myfiles . $open_in_new_window_link . $pdf_icon;
             }
         } else {
             return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" ' . $visibility_class . ' style="float:left">' . $title . '</a>' . $force_download_html . $send_to . $copy_to_myfiles . $open_in_new_window_link . $pdf_icon;
         }
         // end copy files to users myfiles
     } else {
         // Icon column
         if (preg_match('/shared_folder/', urldecode($checkExtension)) && preg_match('/shared_folder$/', urldecode($checkExtension)) == false && preg_match('/shared_folder_session_' . $current_session_id . '$/', urldecode($url)) == false) {
             if ($filetype == 'file') {
                 //Sound preview with jplayer
                 if (preg_match('/mp3$/i', urldecode($checkExtension)) || preg_match('/wav$/i', urldecode($checkExtension)) && !preg_match('/_chnano_.wav$/i', urldecode($url)) || preg_match('/ogg$/i', urldecode($checkExtension))) {
                     $sound_preview = DocumentManager::generate_media_preview($counter);
                     return $sound_preview;
                 } elseif (preg_match('/swf$/i', urldecode($checkExtension)) || preg_match('/png$/i', urldecode($checkExtension)) || preg_match('/gif$/i', urldecode($checkExtension)) || preg_match('/jpg$/i', urldecode($checkExtension)) || preg_match('/jpeg$/i', urldecode($checkExtension)) || preg_match('/bmp$/i', urldecode($checkExtension)) || preg_match('/svg$/i', urldecode($checkExtension)) || preg_match('/wav$/i', urldecode($checkExtension)) && preg_match('/_chnano_.wav$/i', urldecode($checkExtension)) && api_get_setting('document.enable_nanogong') == 'true') {
                     $url = 'showinframes.php?' . api_get_cidreq() . '&id=' . $document_data['id'];
                     return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" ' . $visibility_class . ' style="float:left">' . DocumentManager::build_document_icon_tag($filetype, $path) . Display::return_icon('shared.png', get_lang('ResourceShared'), array()) . '</a>';
                 } else {
                     return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" ' . $visibility_class . ' style="float:left">' . DocumentManager::build_document_icon_tag($filetype, $path) . Display::return_icon('shared.png', get_lang('ResourceShared'), array()) . '</a>';
                 }
             } else {
                 return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" target="' . $target . '"' . $visibility_class . ' style="float:left">' . DocumentManager::build_document_icon_tag($filetype, $path) . Display::return_icon('shared.png', get_lang('ResourceShared'), array()) . '</a>';
             }
         } else {
             if ($filetype == 'file') {
                 // Sound preview with jplayer
                 if (preg_match('/mp3$/i', urldecode($checkExtension)) || preg_match('/wav$/i', urldecode($checkExtension)) && !preg_match('/_chnano_.wav$/i', urldecode($url)) || preg_match('/ogg$/i', urldecode($checkExtension))) {
                     $sound_preview = DocumentManager::generate_media_preview($counter);
                     return $sound_preview;
                 } elseif (preg_match('/html$/i', urldecode($checkExtension)) || preg_match('/htm$/i', urldecode($checkExtension)) || preg_match('/swf$/i', urldecode($checkExtension)) || preg_match('/png$/i', urldecode($checkExtension)) || preg_match('/gif$/i', urldecode($checkExtension)) || preg_match('/jpg$/i', urldecode($checkExtension)) || preg_match('/jpeg$/i', urldecode($checkExtension)) || preg_match('/bmp$/i', urldecode($checkExtension)) || preg_match('/svg$/i', urldecode($checkExtension)) || preg_match('/wav$/i', urldecode($checkExtension)) && preg_match('/_chnano_.wav$/i', urldecode($checkExtension)) && api_get_setting('document.enable_nanogong') == 'true') {
                     $url = 'showinframes.php?' . api_get_cidreq() . '&id=' . $document_data['id'];
                     //without preview
                     return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" ' . $visibility_class . ' style="float:left">' . DocumentManager::build_document_icon_tag($filetype, $path) . '</a>';
                 } else {
                     return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" ' . $visibility_class . ' style="float:left">' . DocumentManager::build_document_icon_tag($filetype, $path) . '</a>';
                 }
             } else {
                 return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" target="' . $target . '"' . $visibility_class . ' style="float:left">' . DocumentManager::build_document_icon_tag($filetype, $path) . '</a>';
             }
         }
     }
 }
/*	GET ALL DOCUMENT DATA FOR CURDIRPATH */
$docs_and_folders = getlist($base_work_dir . '/');
if ($docs_and_folders) {
    //create a sortable table with our data
    $sortable_data = array();
    while (list($key, $id) = each($docs_and_folders)) {
        // Skip directories.
        if ($id['filetype'] != 'file') {
            continue;
        }
        $row = array();
        //if the item is invisible, wrap it in a span with class invisible
        $invisibility_span_open = $id['visibility'] == 0 ? '<span class="invisible">' : '';
        $invisibility_span_close = $id['visibility'] == 0 ? '</span>' : '';
        //size (or total size of a directory)
        $size = $id['filetype'] == 'folder' ? get_total_folder_size($id['path'], $is_allowed_to_edit) : $id[size];
        //get the title or the basename depending on what we're using
        if ($id['title'] != '') {
            $document_name = $id['title'];
        } else {
            $document_name = basename($id['path']);
        }
        //$row[] = $key; //testing
        //data for checkbox
        /*
        if ($is_allowed_to_edit AND count($docs_and_folders) > 1) {
        	$row[] = $id['path'];
        }
        */
        // icons with hyperlinks
        $row[] = '<a href="#" onclick="javascript: OpenFile(\'' . $http_www . '/' . $id['title'] . '\', \'' . $sType . '\');return false;">' . build_document_icon_tag($id['filetype'], $id['path']) . '</a>';