Fixing document public URLs

skala
Julio Montoya 12 years ago
parent 20d06fd085
commit 69de65f784
  1. 17
      .htaccess
  2. 2
      main/inc/lib/usermanager.lib.php
  3. 17
      main/inc/routes.php
  4. 2
      main/inc/services.php
  5. 13
      src/ChamiloLMS/Controller/IndexController.php

@ -3,7 +3,7 @@
Options +FollowSymLinks
RewriteEngine On
RewriteBase /chamilogits
RewriteBase /
# Courses home
RewriteCond %{QUERY_STRING} ^id_session=0
@ -15,27 +15,22 @@
RewriteRule ^courses/(.*)/index.php$ web/courses/$1? [R,L]
RewriteRule ^courses/(.*)/$ web/courses/$1? [R,L]
# Courses documents
# Courses documents
# courses/MATHS/document/folder1/picture.jpg --> courses/MATHS/document/?file=folder1/picture.jpg
RewriteRule ^courses/(.*)/document/(.*)$ web/courses/$1/document/?file=$2 [R,L]
# Portal default_platform_document files
RewriteRule ^data/default_platform_document/(.*)$ web/data/default_platform_document/?file=$1 [R,L]
RewriteRule ^courses/(.*)/document/(.*)$ web/data/courses/$1/document/$2 [R,L]
# Certificates
# certificates/index.php?id=123 --> web/certificates/123
# Redirection: certificates/index.php?id=123 -> web/certificates/123
RewriteCond %{QUERY_STRING} ^id=([0-9]*)
RewriteRule ^certificates/(.*)$ web/certificates/%1? [R,L]
# User profile
# user.php?jmontoya --> web/user/jmontoya
# Redirection: user.php?jmontoya -> web/user/jmontoya
RewriteCond %{QUERY_STRING} ^([a-z0-9A-z]*)
RewriteRule ^user.php?$ web/user/%1? [R,L]
# User images
# Portal news
# news_list.php?id=5 --> web/news/5
RewriteCond %{QUERY_STRING} ^id=([0-9]*)
RewriteRule ^news_list.php?$ web/news/%1? [R,L]
</IfModule>
</IfModule>

@ -1220,7 +1220,7 @@ class UserManager
if ($type == 'system') {
$dir = $base.'upload/users/'.substr((string)$user_id, 0, 1).'/'.$user_id.'/';
} else {
$dir = $base.'upload/users/?file='.substr((string)$user_id, 0, 1).'/'.$user_id.'/';
$dir = $base.'upload/users/'.substr((string)$user_id, 0, 1).'/'.$user_id.'/';
}
/* @todo check this validation

@ -444,13 +444,14 @@ $app->match('/courses/{cidReq}/', 'course_home.controller:indexAction', 'GET|POS
->before($userPermissionsInsideACourse); //allowing slash "/"
/** Course documents */
$app->get('/courses/{courseCode}/document/', 'index.controller:getDocumentAction')
$app->get('/data/courses/{courseCode}/document/{file}', 'index.controller:getDocumentAction')
->assert('file', '.+')
->assert('type', '.+');
/** Certificates */
$app->match('/certificates/{id}', 'certificate.controller:indexAction', 'GET');
/** Username */
/** Username */
$app->match('/user/{username}', 'user.controller:indexAction', 'GET');
/** Who is online */
@ -471,15 +472,17 @@ $app->get('/data/document_templates/{file}', 'index.controller:getDocumentTempla
->bind('data');
/** Data default_platform_document files */
$app->get('/data/default_platform_document/', 'index.controller:getDefaultPlatformDocumentAction')
$app->get('/data/default_platform_document/{file}', 'index.controller:getDefaultPlatformDocumentAction')
->assert('file', '.+')
->assert('type', '.+');
/** User files */
$app->match('/data/upload/users/{file}', 'index.controller:getUserFile', 'GET|POST')
->assert('file', '.+');
/** Group files */
$app->get('/data/upload/groups/{groupId}/{file}', 'index.controller:getGroupFile')
->assert('type', '.+');
/** User files */
$app->match('/data/upload/users/', 'index.controller:getUserFile', 'GET|POST')
->assert('file', '.+')
->assert('type', '.+');
/** Question manager - admin */

@ -462,4 +462,4 @@ $app['question_manager.controller'] = $app->share(
function () use ($app) {
return new ChamiloLMS\Controller\Admin\QuestionManager\QuestionManagerController();
}
);
);

@ -314,11 +314,10 @@ class IndexController extends CommonController
* @param $courseCode
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void
*/
public function getDocumentAction(Application $app, $courseCode)
public function getDocumentAction(Application $app, $courseCode, $file)
{
try {
$filePath = $app['request']->get('file');
$file = $app['chamilo.filesystem']->getCourseDocument($courseCode, $filePath);
$file = $app['chamilo.filesystem']->getCourseDocument($courseCode, $file);
return $app->sendFile($file->getPathname());
} catch (\InvalidArgumentException $e) {
return $app->abort(404, 'File not found');
@ -330,10 +329,9 @@ class IndexController extends CommonController
* @param Application $app
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void
*/
public function getDefaultPlatformDocumentAction(Application $app)
public function getDefaultPlatformDocumentAction(Application $app, $file)
{
try {
$file = $app['request']->get('file');
$file = $app['chamilo.filesystem']->get('default_platform_document/'.$file);
return $app->sendFile($file->getPathname());
} catch (\InvalidArgumentException $e) {
@ -362,10 +360,9 @@ class IndexController extends CommonController
* @param $file
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void
*/
public function getUserFile(Application $app)
public function getUserFile(Application $app, $file)
{
try {
$file = $app['request']->get('file');
$file = $app['chamilo.filesystem']->get('upload/users/'.$file);
return $app->sendFile($file->getPathname());
} catch (\InvalidArgumentException $e) {
@ -414,4 +411,4 @@ class IndexController extends CommonController
}
return \Display::return_message($message, 'error');
}
}
}

Loading…
Cancel
Save