public function resolve(ResourceLocator $locator) { if ($locator->hasResourceId()) { $context = Claro_Context::getCurrentContext(); $context[CLARO_CONTEXT_COURSE] = $locator->getCourseId(); if ($locator->inGroup()) { $context[CLARO_CONTEXT_GROUP] = $locator->getGroupId(); } $path = get_path('coursesRepositorySys') . claro_get_course_path($locator->getCourseId()); // in a group if ($locator->inGroup()) { $groupData = claro_get_group_data($context); $path .= '/group/' . $groupData['directory']; $groupId = $locator->getGroupId(); } else { $path .= '/document'; } $path .= '/' . $this->urlDecodePath(ltrim($locator->getResourceId(), '/')); $resourcePath = '/' . $this->urlDecodePath(ltrim($locator->getResourceId(), '/')); $path = secure_file_path($path); if (!file_exists($path)) { // throw new Exception("Resource not found {$path}"); return false; } elseif (is_dir($path)) { $url = new Url(get_module_entry_url('CLDOC')); $url->addParam('cmd', 'exChDir'); $url->addParam('file', base64_encode($resourcePath)); return $url->toUrl(); } else { return claro_get_file_download_url($resourcePath, Claro_Context::getUrlContext($context)); } } else { return get_module_entry_url('CLDOC'); } }
// skip the display of this file } } else { $style = ''; } //modify style if the file is recently added since last login if (claro_is_user_authenticated() && $claro_notifier->is_a_notified_document(claro_get_current_course_id(), $date, claro_get_current_user_id(), claro_get_current_group_id(), claro_get_current_tool_id(), $thisFile)) { $classItem = ' hot'; } else { $classItem = ''; } if ($thisFile['type'] == A_FILE) { $image = choose_image($thisFile['path']); $size = format_file_size($thisFile['size']); $date = format_date($thisFile['date']); $urlFileName = claro_htmlspecialchars(claro_get_file_download_url($thisFile['path'])); //$urlFileName = "goto/?doc_url=".rawurlencode($cmdFileName); //format_url($baseServUrl.$courseDir.$curDirPath."/".$fileName)); $target = get_conf('openNewWindowForDoc') ? 'target="_blank"' : ''; } elseif ($thisFile['type'] == A_DIRECTORY) { $image = 'folder'; $size = ' '; $date = ' '; $urlFileName = claro_htmlspecialchars(Url::Contextualize($_SERVER['PHP_SELF'] . '?cmd=exChDir&file=' . $cmdFileName)); $target = ''; } $out .= '<tr align="center">' . "\n" . '<td align="left">'; if (is_image($thisFile['path'])) { $out .= '<a class="' . $style . ' item' . $classItem . '" href="' . claro_htmlspecialchars(Url::Contextualize($_SERVER['PHP_SELF'] . '?docView=image&file=' . download_url_encode($thisFile['path']) . '&cwd=' . $curDirPath . $searchCmdUrl)) . '">'; } else { $out .= '<a class="' . $style . ' item' . $classItem . '" href="' . $urlFileName . '" ' . $target . ' >';
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past if ($cmd == 'getFileList') { $it = new DirectoryIterator($pathSys . $relPath); /* * Output */ $out = "\n" . '<ul id="files">' . "\n"; if (!empty($relPath)) { $parentPath = dirname($relPath); $out .= '<li>' . "\n" . '<a href="#" onclick="setFileList(\'' . $parentPath . '\')">' . '<img src="' . get_icon_url('parent') . '" />' . '..' . '</a>' . '</li>' . "\n"; } // directories foreach ($it as $file) { if ($file->isDir() && !$file->isDot()) { // get relative path from allowed root (document/img or platform/document) to target $relativePath = str_replace(realpath($pathSys), '', realpath($file->getPathname())); $out .= '<li>' . "\n" . '<a href="#" class="selectFolder" onclick="setFileList(\'' . str_replace('\\', '/', $relativePath) . '\')">' . '<img src="' . get_icon_url('folder') . '" />' . claro_htmlspecialchars($file->getFileName()) . '</a>' . '</li>' . "\n"; } } // then the files foreach ($it as $file) { if ($file->isFile() && is_image($file->getFileName())) { $path = '/' . $relPath . $file->getFileName(); $url = claro_get_file_download_url($path); $out .= '<li>' . "\n" . '<a href="#" onclick="selectImage(\'' . $url . '\')">' . '<img src="' . get_icon_url(choose_image($file->getFileName())) . '" />' . claro_htmlspecialchars($file->getFileName()) . '</a>' . '</li>' . "\n"; } } $out .= '</ul>' . "\n"; echo claro_utf8_encode($out); }
/** * Returns the documents contained into args['curDirPath'] * @param array $args array of parameters, can contain : * - (boolean) recursive : if true, return the content of the requested directory and its subdirectories, if any. Default = true * - (String) curDirPath : returns the content of the directory specified by this path. Default = '' (root) * @throws InvalidArgumentException if $cid is missing * @webservice{/module/MOBILE/CLDOC/getResourceList/cidReq/[?recursive=BOOL&curDirPath='']} * @ws_arg{Method,getResourcesList} * @ws_arg{cidReq,SYSCODE of requested cours} * @ws_arg{recursive,[Optionnal: if true\, return the content of the requested directory and its subdirectories\, if any. Default = true]} * @ws_arg{curDirPath,[Optionnal: returns the content of the directory specified by this path. Default = '' (root)]} * @return array of document object */ function getResourcesList($args) { $recursive = isset($args['recursive']) ? $args['recursive'] : true; $curDirPath = isset($args['curDirPath']) ? $args['curDirPath'] : ''; $cid = claro_get_current_course_id(); if (is_null($cid)) { throw new InvalidArgumentException('Missing cid argument!'); } elseif (!claro_is_course_allowed()) { throw new RuntimeException('Not allowed', 403); } /* READ CURRENT DIRECTORY CONTENT = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ $claroline = Claroline::getInstance(); $exSearch = false; $groupContext = FALSE; $courseContext = TRUE; $dbTable = get_module_course_tbl(array('document'), $cid); $dbTable = $dbTable['document']; $docToolId = get_course_tool_id('CLDOC'); $groupId = claro_get_current_group_id(); $date = $claroline->notification->getLastActionBeforeLoginDate(claro_get_current_user_id()); if (!defined('A_DIRECTORY')) { define('A_DIRECTORY', 1); } if (!defined('A_FILE')) { define('A_FILE', 2); } $baseWorkDir = get_path('coursesRepositorySys') . claro_get_course_path($cid) . '/document'; /*---------------------------------------------------------------------------- LOAD FILES AND DIRECTORIES INTO ARRAYS ----------------------------------------------------------------------------*/ $searchPattern = ''; $searchRecursive = false; $searchBasePath = $baseWorkDir . $curDirPath; $searchExcludeList = array(); $searchBasePath = secure_file_path($searchBasePath); if (false === ($filePathList = claro_search_file(search_string_to_pcre($searchPattern), $searchBasePath, $searchRecursive, 'ALL', $searchExcludeList))) { switch (claro_failure::get_last_failure()) { case 'BASE_DIR_DONT_EXIST': pushClaroMessage($searchBasePath . ' : call to an unexisting directory in groups'); break; default: pushClaroMessage('Search failed'); break; } $filePathList = array(); } for ($i = 0; $i < count($filePathList); $i++) { $filePathList[$i] = str_replace($baseWorkDir, '', $filePathList[$i]); } if ($exSearch && $courseContext) { $sql = "SELECT path FROM `" . $dbTable . "`\n\t\t\t\t\tWHERE comment LIKE '%" . claro_sql_escape($searchPattern) . "%'"; $dbSearchResult = claro_sql_query_fetch_all_cols($sql); $filePathList = array_unique(array_merge($filePathList, $dbSearchResult['path'])); } $fileList = array(); if (count($filePathList) > 0) { /*-------------------------------------------------------------------------- SEARCHING FILES & DIRECTORIES INFOS ON THE DB ------------------------------------------------------------------------*/ /* * Search infos in the DB about the current directory the user is in */ if ($courseContext) { $sql = "SELECT `path`, `visibility`, `comment`\n\t\t\t\t\t\tFROM `" . $dbTable . "`\n\t\t\t\t\t\t\t\tWHERE path IN ('" . implode("', '", array_map('claro_sql_escape', $filePathList)) . "')"; $xtraAttributeList = claro_sql_query_fetch_all_cols($sql); } else { $xtraAttributeList = array('path' => array(), 'visibility' => array(), 'comment' => array()); } foreach ($filePathList as $thisFile) { $fileAttributeList['cours']['sysCode'] = $cid; $fileAttributeList['path'] = $thisFile; $fileAttributeList['resourceId'] = $thisFile; $tmp = explode('/', $thisFile); if (is_dir($baseWorkDir . $thisFile)) { $fileYear = date('n', time()) < 8 ? date('Y', time()) - 1 : date('Y', time()); $fileAttributeList['title'] = $tmp[count($tmp) - 1]; $fileAttributeList['isFolder'] = true; $fileAttributeList['type'] = A_DIRECTORY; $fileAttributeList['size'] = 0; $fileAttributeList['date'] = $fileYear . '-09-20'; $fileAttributeList['extension'] = ""; $fileAttributeList['url'] = null; } elseif (is_file($baseWorkDir . $thisFile)) { $fileAttributeList['title'] = implode('.', explode('.', $tmp[count($tmp) - 1], -1)); $fileAttributeList['type'] = A_FILE; $fileAttributeList['isFolder'] = false; $fileAttributeList['size'] = claro_get_file_size($baseWorkDir . $thisFile); $fileAttributeList['date'] = date('Y-m-d', filemtime($baseWorkDir . $thisFile)); $fileAttributeList['extension'] = get_file_extension($baseWorkDir . $thisFile); $fileAttributeList['url'] = $_SERVER['SERVER_NAME'] . claro_get_file_download_url($thisFile); } $xtraAttributeKey = array_search($thisFile, $xtraAttributeList['path']); if ($xtraAttributeKey !== false) { $fileAttributeList['description'] = $xtraAttributeList['comment'][$xtraAttributeKey]; $fileAttributeList['visibility'] = $xtraAttributeList['visibility'][$xtraAttributeKey] == 'v'; unset($xtraAttributeList['path'][$xtraAttributeKey]); } else { $fileAttributeList['description'] = null; $fileAttributeList['visibility'] = true; } $notified = $claroline->notification->isANotifiedDocument($cid, $date, claro_get_current_user_id(), $groupId, $docToolId, $fileAttributeList, false); $fileAttributeList['notifiedDate'] = $notified ? $date : $fileAttributeList['date']; $d = new DateTime($date); $d->sub(new DateInterval('P1D')); $fileAttributeList['seenDate'] = $d->format('Y-m-d'); if ($fileAttributeList['visibility'] || claro_is_allowed_to_edit()) { $fileList[] = $fileAttributeList; } } // end foreach $filePathList } if ($recursive) { foreach ($fileList as $thisFile) { if ($thisFile['type'] == A_DIRECTORY) { $args = array('curDirPath' => $thisFile['path'], 'recursive' => true); $new_list = $this->getResourcesList($args); $fileList = array_merge($fileList, $new_list); } } } return $fileList; }
$pathContents = file_get_contents($pathInfo); $extension = get_file_extension($pathInfo); // add a variable to set CLLNP mode in downloader // @todo : use a token and pass it as extra parameter to claro_get_file_download_url $_SESSION['fromCLLNP'] = true; if ($extension == 'url') { // $matches = array(); if (preg_match('/<meta http-equiv="refresh" content="0;url=(.*?)">/', $pathContents, $matches) && isset($matches[1])) { $redirectionURL = $matches[1]; $moduleStartAssetPage = 'viewExternalPage.php?url=' . rawurlencode($redirectionURL); } else { $moduleStartAssetPage = claro_get_file_download_url($startAssetPage, null, 'CLLNP'); } } else { $moduleStartAssetPage = claro_get_file_download_url($startAssetPage, null, 'CLLNP'); } $withFrames = true; break; case CTEXERCISE_: // clean session vars of exercise unset($_SESSION['serializedExercise']); unset($_SESSION['serializedQuestionList']); unset($_SESSION['exeStartTime']); $_SESSION['inPathMode'] = true; $startAssetpage = get_module_url('CLQWZ') . '/exercise_submit.php'; $moduleStartAssetPage = $startAssetpage . '?exId=' . $assetPath; break; case CTSCORM_: // real scorm content method $startAssetPage = $assetPath;