Fixing document public URLs

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

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

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

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

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

Loading…
Cancel
Save