Adding PHP connectors in order to use elfinder to upload/rm files

See #6833
1.10.x
Julio Montoya 13 years ago
parent b375b93a5c
commit 5e2db2a6bc
  1. 51
      main/inc/global.inc.php
  2. 67
      main/inc/lib/api.lib.php
  3. 147
      main/inc/lib/document.lib.php
  4. 15
      main/inc/lib/fileManager.lib.php
  5. 19
      main/inc/routes.php
  6. 20
      main/inc/services.php
  7. 9
      main/template/default/javascript/editor/ckeditor/elfinder.tpl
  8. 19
      main/template/default/javascript/editor/elfinder_standalone.tpl
  9. 2
      main/template/default/javascript/editor/tinymce/elfinder.tpl
  10. 15
      main/template/default/user/files.tpl
  11. 3
      src/ChamiloLMS/Component/DataFilesystem/DataFilesystem.php
  12. 11
      src/ChamiloLMS/Component/Editor/CkEditor/CkEditor.php
  13. 412
      src/ChamiloLMS/Component/Editor/Connector.php
  14. 141
      src/ChamiloLMS/Component/Editor/Driver/CourseDriver.php
  15. 35
      src/ChamiloLMS/Component/Editor/Driver/CourseUserDriver.php
  16. 178
      src/ChamiloLMS/Component/Editor/Driver/Driver.php
  17. 52
      src/ChamiloLMS/Component/Editor/Driver/HomeDriver.php
  18. 53
      src/ChamiloLMS/Component/Editor/Driver/PersonalDriver.php
  19. 47
      src/ChamiloLMS/Component/Editor/Editor.php
  20. 58
      src/ChamiloLMS/Component/Editor/Finder.php
  21. 22
      src/ChamiloLMS/Controller/BaseController.php
  22. 20
      src/ChamiloLMS/Controller/User/ProfileController.php
  23. 2
      src/ChamiloLMS/Controller/User/UserController.php

@ -238,7 +238,10 @@ $app->error(
$message = 'Unauthorized';
break;
case 404: // not found
$message = 'The requested page could not be found.';
$message = $e->getMessage();
if (empty($message)) {
$message = 'The requested page could not be found.';
}
break;
default:
//$message = 'We are sorry, but something went terribly wrong.';
@ -250,7 +253,9 @@ $app->error(
if ($e instanceof PDOException) {
$message = "There's an error with the database.";
if ($app['debug']) {
$message = $e->getMessage();
}
return $message;
}
@ -274,7 +279,7 @@ $app->error(
$template->setFooter($app['template.show_footer']);
$template->assign('error', array('code' => $code, 'message' => $message));
$response = $template->render_layout('error.tpl');
$response = $template->renderLayout('error.tpl');
return new Response($response);
}
@ -330,6 +335,7 @@ $app->before(
// Setting session obj
Session::setSession($app['session']);
UserManager::setEntityManager($app['orm.em']);
/** @var ChamiloLMS\Component\DataFilesystem\DataFilesystem $filesystem */
@ -355,7 +361,6 @@ $app->before(
$_configuration['access_url'] = 1;
$access_urls = api_get_access_urls();
//$protocol = ((!empty($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) != 'OFF') ? 'https' : 'http').'://';
$protocol = $request->getScheme().'://';
$request_url1 = $protocol.$_SERVER['SERVER_NAME'].'/';
$request_url2 = $protocol.$_SERVER['HTTP_HOST'].'/';
@ -372,15 +377,15 @@ $app->before(
}
// Loading portal settings from DB.
$settings_refresh_info = api_get_settings_params_simple(array('variable = ?' => 'settings_latest_update'));
$settings_latest_update = $settings_refresh_info ? $settings_refresh_info['selected_value'] : null;
$settingsRefreshInfo = api_get_settings_params_simple(array('variable = ?' => 'settings_latest_update'));
$settingsLatestUpdate = $settingsRefreshInfo ? $settingsRefreshInfo['selected_value'] : null;
$_setting = Session::read('_setting');
$settings = Session::read('_setting');
if (empty($_setting)) {
if (empty($settings)) {
api_set_settings_and_plugins();
} else {
if (isset($_setting['settings_latest_update']) && $_setting['settings_latest_update'] != $settings_latest_update) {
if (isset($settings['settings_latest_update']) && $settings['settings_latest_update'] != $settingsLatestUpdate) {
api_set_settings_and_plugins();
}
}
@ -432,6 +437,7 @@ $app->before(
/** Security component. */
/** @var Symfony\Component\Security\Core\SecurityContext $security */
$security = $app['security'];
if ($security->isGranted('IS_AUTHENTICATED_FULLY')) {
// Checking token in order to get the current user.
@ -536,17 +542,30 @@ $app->before(
}
}));
// Check if we are inside a Chamilo course tool
$isCourseTool = (strpos($request->getPathInfo(), 'courses/') === false) ? false : true;
/*$isCourseTool = (strpos($request->getPathInfo(), 'courses/') === false) ? false : true;
if (!$isCourseTool) {
// @todo add a before in controller in order to load the courses and course_session object
$isCourseTool = (strpos($request->getPathInfo(), 'editor/filemanager') === false) ? false : true;
var_dump($isCourseTool);
var_dump(api_get_course_id());exit;
}*/
// Setting course entity for controllers and templates.
if ($isCourseTool) {
// The course parameter is loaded.
$course = $request->get('course');
// The course parameter is loaded.
$courseCode = $request->get('course');
if (empty($courseCode)) {
$courseCode = api_get_course_id();
}
if (!empty($courseCode)) {
// Converting /courses/XXX/ to a Entity/Course object.
$course = $app['orm.em']->getRepository('Entity\Course')->findOneByCode($course);
$course = $app['orm.em']->getRepository('Entity\Course')->findOneByCode($courseCode);
$app['course'] = $course;
$app['template']->assign('course', $course);
@ -555,6 +574,8 @@ $app->before(
$app['course_session'] = $session;
$app['template']->assign('course_session', $session);
} else {
$app['course'] = null;
}
}
);

@ -3057,23 +3057,48 @@ function api_get_item_visibility($_course, $tool, $id, $session = 0, $user_id =
* Updates or adds item properties to the Item_propetry table
* Tool and lastedit_type are language independant strings (langvars->get_lang!)
*
* @param $_course : array with course properties
* @param $tool : tool id, linked to 'rubrique' of the course tool_list (Warning: language sensitive !!)
* @param $item_id : id of the item itself, linked to key of every tool ('id', ...), "*" = all items of the tool
* @param $lastedit_type : add or update action (1) message to be translated (in trad4all) : e.g. DocumentAdded, DocumentUpdated;
* (2) "delete"; (3) "visible"; (4) "invisible";
* @param $user_id : id of the editing/adding user
* @param $to_group_id : id of the intended group ( 0 = for everybody), only relevant for $type (1)
* @param $to_user_id : id of the intended user (always has priority over $to_group_id !), only relevant for $type (1)
* @param array|\Entity\Course $_course : array with course properties
* @param int $tool : tool id, linked to 'rubrique' of the course tool_list (Warning: language sensitive !!)
* @param int $item_id : id of the item itself, linked to key of every tool ('id', ...), "*" = all items of the tool
* @param string $lastedit_type add or update action (1) message to be translated (in trad4all) : e.g. DocumentAdded, DocumentUpdated;
* (2) "delete"; (3) "visible"; (4) "invisible";
* @param int $user_id : id of the editing/adding user
* @param int $to_group_id : id of the intended group ( 0 = for everybody), only relevant for $type (1)
* @param int $to_user_id : id of the intended user (always has priority over $to_group_id !), only relevant for $type (1)
* @param string $start_visible 0000-00-00 00:00:00 format
* @param string $end_visible 0000-00-00 00:00:00 format
* @param int $session_id
* @return boolean False if update fails.
*
* @author Toon Van Hoecke <Toon.VanHoecke@UGent.be>, Ghent University
* @version January 2005
*
* @desc update the item_properties table (if entry not exists, insert) of the course
*/
function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $user_id, $to_group_id = 0, $to_user_id = 0, $start_visible = 0, $end_visible = 0, $session_id = 0) {
function api_item_property_update(
$_course,
$tool,
$item_id,
$lastedit_type,
$user_id,
$to_group_id = 0,
$to_user_id = 0,
$start_visible = 0,
$end_visible = 0,
$session_id = 0
) {
if (is_array($_course)) {
$course_id = $_course['real_id'];
} else {
if ($_course instanceof \Entity\Course) {
$course_id = $_course->getId();
}
}
if (empty($course_id)) {
return false;
}
// Definition of variables.
$tool = Database::escape_string($tool);
@ -3109,7 +3134,7 @@ function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $us
$condition_session = " AND id_session = '$session_id' ";
}
$course_id = $_course['real_id'];
$filter = " c_id = $course_id AND tool='$tool' AND ref='$item_id' $condition_session ";
if ($item_id == '*') {
@ -6019,8 +6044,8 @@ function api_check_user_access_to_legal($course_visibility) {
* @return bool
*/
function api_is_global_chat_enabled() {
$global_chat_is_enabled = !api_is_anonymous() && api_get_setting('allow_global_chat') == 'true' && api_get_setting('allow_social_tool') == 'true';
return $global_chat_is_enabled;
$enabled = !api_is_anonymous() && api_get_setting('allow_global_chat') == 'true' && api_get_setting('allow_social_tool') == 'true';
return $enabled;
}
/**
@ -6029,13 +6054,14 @@ function api_is_global_chat_enabled() {
* create a new quiz and call this function, if the quiz tool is
* invisible/disabled at course creation, the quiz itself will be set to
* invisible.
* @param array|\Entity\Course $course
* @param int The ID of the item in its own table
* @param string The string identifier of the tool
* @param int The group ID, in case we want to specify it
* @param int The integer course ID, in case we cannot get it from the context
* @todo Fix tool_visible_by_default_at_creation labels
*/
function api_set_default_visibility($courseInfo, $item_id, $tool_id, $group_id = null)
function api_set_default_visibility($course, $item_id, $tool_id, $group_id = null)
{
$original_tool_id = $tool_id;
@ -6063,6 +6089,14 @@ function api_set_default_visibility($courseInfo, $item_id, $tool_id, $group_id =
}
$setting = api_get_setting('tool_visible_by_default_at_creation');
if (is_array($course)) {
$courseId = $course['real_id'];
} else {
if ($course instanceof \Entity\Course) {
$courseId = $course->getId();
}
}
if (isset($setting[$tool_id])) {
$visibility = 'invisible';
if ($setting[$tool_id] == 'true') {
@ -6072,13 +6106,14 @@ function api_set_default_visibility($courseInfo, $item_id, $tool_id, $group_id =
if (empty($group_id)) {
$group_id = api_get_group_id();
}
api_item_property_update($courseInfo, $original_tool_id, $item_id, $visibility, api_get_user_id(), $group_id, null, null, null, api_get_session_id());
//Fixes default visibility for tests
api_item_property_update($course, $original_tool_id, $item_id, $visibility, api_get_user_id(), $group_id, null, null, null, api_get_session_id());
// Fixes default visibility for tests
switch ($original_tool_id) {
case TOOL_QUIZ:
$objExerciseTmp = new Exercise($courseInfo['real_id']);
$objExerciseTmp = new Exercise($courseId);
$objExerciseTmp->read($item_id);
if ($visibility == 'visible') {
$objExerciseTmp->enable();

@ -864,6 +864,12 @@ class DocumentManager
return $result['filetype'] == 'folder';
}
/**
* @param int $document_id
* @param array $course_info
* @param int $session_id
* @param bool $remove_content_from_db
*/
public static function delete_document_from_db(
$document_id,
$course_info = array(),
@ -873,17 +879,19 @@ class DocumentManager
$TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
//Deleting from the DB
// Deleting from the DB
$user_id = api_get_user_id();
$document_id = intval($document_id);
if (empty($course_info)) {
$course_info = api_get_course_info();
}
if (empty($session_id)) {
$session_id = api_get_session_id();
}
//Soft DB delete
// Soft DB delete
api_item_property_update(
$course_info,
TOOL_DOCUMENT,
@ -901,10 +909,11 @@ class DocumentManager
//Hard DB delete
if ($remove_content_from_db) {
$sql = "DELETE FROM $TABLE_ITEMPROPERTY WHERE c_id = {$course_info['real_id']} AND ref = ".$document_id." AND tool='".TOOL_DOCUMENT."'";
$sql = "DELETE FROM $TABLE_ITEMPROPERTY
WHERE c_id = {$course_info['real_id']} AND ref = ".$document_id." AND tool='".TOOL_DOCUMENT."'";
Database::query($sql);
$sql = "DELETE FROM ".$TABLE_DOCUMENT." WHERE c_id = {$course_info['real_id']} AND id = ".$document_id;
$sql = "DELETE FROM $TABLE_DOCUMENT WHERE c_id = {$course_info['real_id']} AND id = ".$document_id;
Database::query($sql);
self::delete_document_metadata($document_id);
@ -923,18 +932,17 @@ class DocumentManager
$mdStore->mds_delete_offspring($eid);
}
/**
* This deletes a document by changing visibility to 2, renaming it to filename_DELETED_#id
* Files/folders that are inside a deleted folder get visibility 2
*
* @param array $_course
* @param array|\Entity\Course $_course
* @param string $path, path stored in the database
* @param string ,$base_work_dir, path to the documents folder
* @param string $base_work_dir, path to the documents folder
* @return boolean true/false
* @todo now only files/folders in a folder get visibility 2, we should rename them too.
*/
public static function delete_document($_course, $path, $base_work_dir)
public static function delete_document($_course, $path, $base_work_dir, $sessionId = null)
{
$TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
@ -942,98 +950,122 @@ class DocumentManager
return false;
}
$course_id = $_course['real_id'];
if (is_array($_course)) {
$course_id = $_course['real_id'];
} else {
if ($_course instanceof \Entity\Course) {
$course_id = $_course->getId();
$_course = api_get_course_info_by_id($course_id);
}
}
if (empty($course_id)) {
return false;
}
if (empty($sessionId)) {
$sessionId = api_get_session_id();
} else {
$sessionId = intval($sessionId);
}
// First, delete the actual document.
$document_id = self::get_document_id($_course, $path, $sessionId);
if (empty($document_id)) {
return false;
}
//first, delete the actual document...
$document_id = self :: get_document_id($_course, $path);
$document_exists_in_disk = file_exists($base_work_dir.$path);
$new_path = $path.'_DELETED_'.$document_id;
$current_session_id = api_get_session_id();
$file_deleted_from_db = false;
$file_deleted_from_disk = false;
$file_renamed_from_disk = false;
if ($document_id) {
self::delete_document_from_db($document_id);
//checking
//$file_exists_in_db = self::get_document_data_by_id($document_id, $_course['code']);
self::delete_document_from_db($document_id, $_course, $sessionId);
// Checking
// $file_exists_in_db = self::get_document_data_by_id($document_id, $_course['code']);
$file_deleted_from_db = true;
}
if ($document_exists_in_disk) {
if (api_get_setting('permanently_remove_deleted_files') == 'true') {
//Deleted files are *really* deleted
$what_to_delete_sql = "SELECT id FROM ".$TABLE_DOCUMENT." WHERE c_id = $course_id AND path='".$path."' OR path LIKE BINARY '".$path."/%'";
//get all id's of documents that are deleted
$what_to_delete_result = Database::query($what_to_delete_sql);
if ($what_to_delete_result && Database::num_rows($what_to_delete_result) != 0) {
//delete all item_property entries
while ($row = Database::fetch_array($what_to_delete_result)) {
//query to delete from item_property table (hard way)
self::delete_document_from_db($row['id'], $_course, $current_session_id, true);
// Deleted files are *really* deleted.
$sql = "SELECT id FROM $TABLE_DOCUMENT
WHERE
c_id = $course_id AND
session_id = $sessionId AND
(path = '".$path."' OR path LIKE BINARY '".$path."/%') ";
// Get all id's of documents that are deleted.
$result = Database::query($sql);
if ($result && Database::num_rows($result) != 0) {
// Delete all item_property entries
while ($row = Database::fetch_array($result)) {
// Query to delete from item_property table (hard way)
self::delete_document_from_db($row['id'], $_course, $sessionId, true);
}
//delete documents, do it like this so metadata get's deleted too
//FileManager::update_db_info('delete', $path);
//throw it away
FileManager::my_delete($base_work_dir.$path);
$file_deleted_from_disk = true;
}
// Delete documents, do it like this so metadata gets deleted too
my_delete($base_work_dir.$path);
$file_deleted_from_disk = true;
} else {
//Set visibility to 2 and rename file/folder to xxx_DELETED_#id (soft delete)
// Set visibility to 2 and rename file/folder to xxx_DELETED_#id (soft delete)
if (is_file($base_work_dir.$path) || is_dir($base_work_dir.$path)) {
if (rename($base_work_dir.$path, $base_work_dir.$new_path)) {
$sql = "UPDATE $TABLE_DOCUMENT set path='".$new_path."' WHERE c_id = $course_id AND id='".$document_id."'";
$sql = "UPDATE $TABLE_DOCUMENT SET path='".$new_path."'
WHERE c_id = $course_id AND session_id = $sessionId AND id = '".$document_id."'";
Database::query($sql);
$sql = "SELECT id, path FROM $TABLE_DOCUMENT WHERE c_id = $course_id AND path LIKE BINARY '".$path."/%'";
$sql = "SELECT id, path FROM $TABLE_DOCUMENT
WHERE
c_id = $course_id AND
session_id = $sessionId AND
(path = '".$path."' OR path LIKE BINARY '".$path."/%') ";
$result = Database::query($sql);
if ($result && Database::num_rows($result) > 0) {
while ($deleted_items = Database::fetch_array($result, 'ASSOC')) {
self::delete_document_from_db($deleted_items['id']);
self::delete_document_from_db($deleted_items['id'], $_course, $sessionId);
//Change path of subfolders and documents in database
// Change path of sub folders and documents in database.
$old_item_path = $deleted_items['path'];
$new_item_path = $new_path.substr($old_item_path, strlen($path));
$sql = "UPDATE $TABLE_DOCUMENT set path = '".$new_item_path."' WHERE c_id = $course_id AND id = ".$deleted_items['id'];
$sql = "UPDATE $TABLE_DOCUMENT
SET path = '".$new_item_path."'
WHERE c_id = $course_id AND session_id = $sessionId AND id = ".$deleted_items['id'];
Database::query($sql);
}
}
$file_renamed_from_disk = true;
} else {
//Couldn't rename - file permissions problem?
error_log(
__FILE__.' '.__LINE__.': Error renaming '.$base_work_dir.$path.' to '.$base_work_dir.$new_path.'. This is probably due to file permissions',
0
);
// Couldn't rename - file permissions problem?
error_log(__FILE__ . ' ' . __LINE__ . ': Error renaming '.$base_work_dir.$path.' to '.$base_work_dir.$new_path.'. This is probably due to file permissions', 0);
}
}
}
}
//Checking inconsistency
// Checking inconsistency
if ($file_deleted_from_db && $file_deleted_from_disk ||
$file_deleted_from_db && $file_renamed_from_disk
) {
return true;
} else {
//Something went wrong
//The file or directory isn't there anymore (on the filesystem)
// This means it has been removed externally. To prevent a
// blocking error from happening, we drop the related items from the
// item_property and the document table.
error_log(
__FILE__.' '.__LINE__.': System inconsistency detected. The file or directory '.$base_work_dir.$path.' seems to have been removed from the filesystem independently from the web platform. To restore consistency, the elements using the same path will be removed from the database',
0
);
error_log(__FILE__.' '.__LINE__.': System inconsistency detected. The file or directory '.$base_work_dir.$path.' seems to have been removed from the filesystem independently from the web platform. To restore consistency, the elements using the same path will be removed from the database', 0);
return false;
}
}
@ -1071,25 +1103,30 @@ class DocumentManager
/**
* Gets the id of a document with a given path
*
* @param array $_course
* @param array $courseInfo
* @param string $path
* @return int id of document / false if no doc found
*/
public static function get_document_id($course_info, $path)
public static function get_document_id($courseInfo, $path, $sessionId = null)
{
$TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
$course_id = $course_info['real_id'];
$course_id = $courseInfo['real_id'];
if (empty($sessionId)) {
$sessionId = api_get_session_id();
} else {
$sessionId = intval($sessionId);
}
$path = Database::escape_string($path);
if (!empty($course_id) && !empty($path)) {
$sql = "SELECT id FROM $TABLE_DOCUMENT WHERE c_id = $course_id AND path LIKE BINARY '$path' LIMIT 1";
$sql = "SELECT id FROM $TABLE_DOCUMENT
WHERE c_id = $course_id AND path LIKE BINARY '$path' AND session_id = $sessionId LIMIT 1";
$result = Database::query($sql);
if ($result && Database::num_rows($result)) {
$row = Database::fetch_array($result);
return intval($row[0]);
}
}
return false;
}

@ -1605,7 +1605,7 @@ class FileManager
* @return id if inserted document
*/
static function add_document(
$_course,
$course,
$path,
$filetype,
$filesize,
@ -1621,8 +1621,15 @@ class FileManager
$path = Database::escape_string($path);
$filetype = Database::escape_string($filetype);
$filesize = intval($filesize);
$title = Database::escape_string(htmlspecialchars($title));
$c_id = $_course['real_id'];
$title = Database::escape_string($title);
if (is_array($course)) {
$c_id = $course['real_id'];
} else {
if ($course instanceof \Entity\Course) {
$c_id = $course->getId();
}
}
$table_document = Database::get_course_table(TABLE_DOCUMENT);
$sql = "INSERT INTO $table_document (c_id, path, filetype, size, title, comment, readonly, session_id)
@ -1632,7 +1639,7 @@ class FileManager
$document_id = Database::insert_id();
if ($document_id) {
if ($save_visibility) {
api_set_default_visibility($_course, $document_id, TOOL_DOCUMENT, $group_id);
api_set_default_visibility($course, $document_id, TOOL_DOCUMENT, $group_id);
}
}

@ -555,12 +555,14 @@ $app->match('/introduction/delete/{tool}', 'introduction_tool.controller:deleteA
/** Course documents */
$app->get('/data/courses/{courseCode}/document/{file}', 'index.controller:getDocumentAction')
->assert('file', '.+')
->assert('type', '.+');
->assert('type', '.+')
->bind('get_document');
/** Scorm documents */
$app->get('/data/courses/{courseCode}/scorm/{file}', 'index.controller:getScormDocumentAction')
->assert('file', '.+')
->assert('type', '.+');
->assert('type', '.+')
->bind('get_scorm_document');
/** Certificates */
$app->match('/certificates/{id}', 'certificate.controller:indexAction', 'GET');
@ -714,17 +716,6 @@ $app->match('/ajax', 'model_ajax.controller:indexAction', 'GET')
->assert('type', '.+')
->bind('model_ajax');
/** Editor */
$app->match('/editor/filemanager', 'editor.controller:filemanagerAction', 'GET|POST')
->assert('type', '.+')
->bind('filemanager');
$app->match('/editor/connector', 'editor.controller:connectorAction', 'GET|POST')
->assert('type', '.+')
->bind('editor_connector');
if ($alreadyInstalled) {
$app->mount('/admin/', new ChamiloLMS\Provider\ReflectionControllerProvider('admin.controller'));
$app->mount('/admin/administrator/upgrade', new ChamiloLMS\Provider\ReflectionControllerProvider('upgrade.controller'));
@ -735,8 +726,6 @@ if ($alreadyInstalled) {
$app->mount('/editor/', new ChamiloLMS\Provider\ReflectionControllerProvider('editor.controller'));
$app->mount('/user/', new ChamiloLMS\Provider\ReflectionControllerProvider('profile.controller'));
$app->mount('/user/', new ChamiloLMS\Provider\ReflectionControllerProvider('profile.controller'));
$app->mount('/courses/{course}/curriculum/category', new ChamiloLMS\Provider\ReflectionControllerProvider('curriculum_category.controller'));
$app->mount('/courses/{course}/curriculum/item', new ChamiloLMS\Provider\ReflectionControllerProvider('curriculum_item.controller'));
$app->mount('/courses/{course}/curriculum/user', new ChamiloLMS\Provider\ReflectionControllerProvider('curriculum_user.controller'));

@ -19,6 +19,7 @@ use MediaAlchemyst\MediaAlchemystServiceProvider;
use MediaVorus\MediaVorusServiceProvider;
use FFMpeg\FFMpegServiceProvider;
use PHPExiftool\PHPExiftoolServiceProvider;
use ChamiloLMS\Component\Editor\Connector;
// Flint
$app->register(new Flint\Provider\ConfigServiceProvider());
@ -665,7 +666,6 @@ class ChamiloServiceProvider implements ServiceProviderInterface
// Registering Chamilo service provider.
$app->register(new ChamiloServiceProvider(), array());
// Controller as services definitions.
$app['pages.controller'] = $app->share(
function () use ($app) {
@ -821,7 +821,21 @@ $app['upgrade.controller'] = $app->share(
);
$app['html_editor'] = $app->share(function($app) {
return new ChamiloLMS\Component\Editor\CkEditor\CkEditor($app['translator'], $app['url_generator']);
return new ChamiloLMS\Component\Editor\CkEditor\CkEditor($app['translator'], $app['url_generator'], $app['course']);
//return new ChamiloLMS\Component\Editor\TinyMce\TinyMce($app['translator'], $app['url_generator']);
});
$app['editor_connector'] = $app->share(function ($app) {
$token = $app['security']->getToken();
$user = $token->getUser();
return new Connector(
$app['paths'],
$app['url_generator'],
$app['translator'],
$app['security'],
$user,
$app['course']
);
});
});

@ -2,11 +2,10 @@
{% block body %}
<!-- elFinder CSS (REQUIRED) -->
<link rel="stylesheet" type="text/css" media="screen" href="{{ _p.web_lib }}elfinder/css/elfinder.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="{{ _p.web_lib }}elfinder/css/theme.css">
<link rel="stylesheet" type="text/css" media="screen" href="{{ _p.web_lib }}elfinder/css/elfinder.full.css">
<!-- elFinder JS (REQUIRED) -->
<script type="text/javascript" src="{{ _p.web_lib }}elfinder/js/elfinder.min.js"></script>
<script type="text/javascript" src="{{ _p.web_lib }}elfinder/js/elfinder.full.js"></script>
<!-- elFinder translation (OPTIONAL) -->
<script type="text/javascript" src="{{ _p.web_lib }}elfinder/js/i18n/elfinder.ru.js"></script>
@ -22,9 +21,9 @@
$().ready(function() {
var funcNum = getUrlParam('CKEditorFuncNum');
var elf = $('#elfinder').elfinder({
url : '{{ url('editor.controller:connectorAction') }}', // connector URL (REQUIRED)
url : '{{ url('editor.controller:connectorAction', {'course' : course.code}) }}', // connector URL (REQUIRED)
getFileCallback : function(file) {
window.opener.CKEDITOR.tools.callFunction(funcNum, file);
window.opener.CKEDITOR.tools.callFunction(funcNum, file.url);
window.close();
},
resizable: false

@ -0,0 +1,19 @@
<!-- elFinder CSS (REQUIRED) -->
<link rel="stylesheet" type="text/css" media="screen" href="{{ _p.web_lib }}elfinder/css/elfinder.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="{{ _p.web_lib }}elfinder/css/theme.css">
<!-- elFinder JS (REQUIRED) -->
<script type="text/javascript" src="{{ _p.web_lib }}elfinder/js/elfinder.min.js"></script>
<!-- elFinder translation (OPTIONAL) -->
<script type="text/javascript" src="{{ _p.web_lib }}elfinder/js/i18n/elfinder.ru.js"></script>
<script type="text/javascript" charset="utf-8">
$().ready(function() {
$('#elfinder').elfinder({
url : '{{ url('editor.controller:connectorAction', {driver_list : driver_list }) }}',
resizable: false
}).elfinder('instance');
});
</script>
<div id="elfinder"></div>

@ -32,7 +32,7 @@
url : '{{ url('editor.controller:connectorAction') }}', // connector URL (REQUIRED)
getFileCallback: function(file) { // editor callback
// actually file.url - doesnt work for me, but file does. (elfinder 2.0-rc1)
FileBrowserDialogue.mySubmit(file); // pass selected file path to TinyMCE
FileBrowserDialogue.mySubmit(file.url); // pass selected file path to TinyMCE
}
}).elfinder('instance');
});

@ -1,16 +1,7 @@
{% extends app.template_style ~ "/layout/layout_2_col.tpl" %}
{% extends app.template_style ~ "/layout/layout_1_col.tpl" %}
{% block left_column %}
<div class="well social-background-content">
<img src="{{ user.avatar }}"/>
</div>
{% endblock %}
{% block right_column %}
<div class="well_border">
<h3>{{ 'MyFiles' | trans }}</h3>
</div>
{% block content %}
<h3>{{ 'MyFiles' | trans }}</h3>
{{ editor }}
{% endblock %}

@ -118,6 +118,9 @@ class DataFilesystem
}
}
/**
* @return Finder
*/
public function getStyleSheetFolders()
{
$finder = new Finder();

@ -37,7 +37,9 @@ class CkEditor extends Editor
*/
public function createHtml()
{
$html = '<textarea id="'.$this->getName().'" name="'.$this->getName().'" class="ckeditor" >'.$this->value.'</textarea>';
$html = '<textarea id="'.$this->getName().'" name="'.$this->getName().'" class="ckeditor" >
'.$this->value.'
</textarea>';
$html .= $this->editorReplace();
return $html;
@ -74,7 +76,6 @@ class CkEditor extends Editor
$templateList = array();
$search = array('{CSS}', '{IMG_DIR}', '{REL_PATH}', '{COURSE_DIR}');
//$url = $this->urlGenerator->generate('get_document_template_action', array('file' => 'file'));
$replace = array(
'',
api_get_path(REL_CODE_PATH).'img/',
@ -87,7 +88,11 @@ class CkEditor extends Editor
$image = $template->getImage();
$image = !empty($image) ? $image : 'empty.gif';
$image = $this->urlGenerator->generate('get_document_template_action', array('file' => $image), UrlGenerator::ABSOLUTE_URL);
$image = $this->urlGenerator->generate(
'get_document_template_action',
array('file' => $image),
UrlGenerator::ABSOLUTE_URL
);
$content = str_replace($search, $replace, $template->getContent());

@ -2,19 +2,132 @@
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor;
use \Entity\User;
use \Entity\Course;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Routing\Router;
use ChamiloLMS\Component\Editor\Driver\Driver;
use Symfony\Component\Security\Core\SecurityContext;
/**
* Class elfinder Connector - editor + Chamilo repository
* @package ChamiloLMS\Component\Editor
*/
class Connector
{
/** @var Course */
public $course;
/** @var User */
public $user;
public $drivers = array();
public $driverList = array();
/** @var Translator */
public $translator;
/** @var Router */
public $urlGenerator;
/** @var SecurityContext */
public $security;
public $paths;
public function __construct(
$paths,
Router $urlGenerator,
Translator $translator,
SecurityContext $security,
User $user,
$course = null
) {
$this->translator = $translator;
$this->user = $user;
$this->course = $course;
$this->urlGenerator = $urlGenerator;
$this->paths = $paths;
$this->security = $security;
$this->driverList = $this->getDefaultDriverList();
}
/**
*
* @param Driver $driver
*/
public function addDriver($driver)
{
if (!empty($driver)) {
$this->drivers[$driver->getName()] = $driver;
}
}
/**
* @return array
*/
public function getDrivers()
{
return $this->drivers;
}
/**
* @param string $driverName
* @return Driver $driver
*/
public function getDriver($driverName)
{
if (isset($this->drivers[$driverName])) {
return $this->drivers[$driverName];
}
return null;
}
/**
* @param bool $processDefaultValues
* @return array
*/
public function __construct()
public function getRoots($processDefaultValues = true)
{
$roots = array();
/** @var Driver $driver */
$drivers = $this->getDrivers();
foreach ($drivers as $driver) {
if ($processDefaultValues) {
$root = $driver->updateWithDefaultValues($driver->getConfiguration());
}
$roots[] = $root;
}
return $roots;
}
/**
* @return array
*/
public function getOperations()
{
//https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options-2.1
$opts = array(
//'debug' => true,
'bind' => array(
'upload rm' => array($this, 'manageCommands')
)
);
foreach ($this->getDriverList() as $driverName) {
$driverClass = $this->getDriverClass($driverName);
/** @var Driver $driver */
$driver = new $driverClass();
$driver->setName($driverName);
$driver->setConnector($this);
$this->addDriver($driver);
}
$opts['roots'] = $this->getRoots();
return $opts;
}
/**
* Simple function to demonstrate how to control file access using "accessControl" callback.
* This method will disable accessing files/folders starting from '.' (dot)
@ -27,260 +140,103 @@ class Connector
**/
public function access($attr, $path, $data, $volume)
{
//error_log($path); error_log($attr);
return strpos(basename($path), '.') === 0 // if file/folder begins with '.' (dot)
? !($attr == 'read' || $attr == 'write') // set read+write to false, other (locked+hidden) set to true
: null; // else elFinder decide it itself
}
/**
* Simple callback catcher
*
* @param string $cmd command name
* @param array $result command result
* @param array $args command arguments from client
* @param \elFinder $elfinder elFinder instance
* @return void|true
**/
function logger($cmd, $result, $args, $elfinder)
* @return array
*/
public function getDriverList()
{
// do something here
// echo $cmd;
$courseInfo = api_get_course_info();
/*error_log($cmd);
error_log(print_r($result, 1));*/
//error_log(print_r($args,1));
//error_log(print_r($elfinder,1));
switch($cmd) {
case 'mkdir':
break;
case 'mkfile':
break;
case 'rename':
break;
case 'duplicate':
break;
case 'upload':
// Files added
if (isset($result['added'])) {
foreach ($result['added'] as $file) {
$name = $file['name'];
$webalized = \URLify::filter($file['name'], 80);
if (strcmp($name, $webalized) != 0) {
$arg = array('target' => $file['hash'], 'name' => $webalized);
$elfinder->exec('rename', $arg);
}
$realPath = $elfinder->realpath($file['hash']);
//error_log($realPath);
if (!empty($realPath)) {
// Getting file info
$info = $elfinder->exec('file', array('target' => $file['hash']));
/** @var elFinderVolumeLocalFileSystem $volume */
$volume = $info['volume'];
$root = $volume->root();
//var/www/chamilogits/data/courses/NEWONE/document
$realPathRoot = $elfinder->realpath($root);
// Removing course path
$realPath = str_replace($realPathRoot, '', $realPath);
\FileManager::add_document($courseInfo, $realPath, 'file', intval($file['size']), $file['name']);
}
}
}
break;
case 'rm':
if (isset($result['removed'])) {
foreach ($result['removed'] as $file) {
$realFilePath = $file['realpath'];
$filePath = str_replace($courseInfo['course_sys_data'].'document', '', $realFilePath);
\DocumentManager::delete_document($courseInfo, $filePath, $courseInfo['course_sys_data'].'document');
}
}
break;
case 'paste':
break;
}
return $this->driverList;
}
/**
* Available driver list.
* @return array
*/
public function getOperations()
public function setDriverList($list)
{
$opts = array(
//'debug' => true,
'bind' => array(
'mkdir mkfile rename duplicate upload rm paste' => array($this, 'logger')
//'mkdir mkfile rename duplicate upload rm paste' => 'chamilo'
)
);
$courseInfo = api_get_course_info();
$userId = api_get_user_id();
$commonAttributes = array(
// Hiding dangerous files
array(
'pattern' => '/\.(php|py|pl|sh|xml)$/i',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
),
// Hiding _DELETED_ files
array(
'pattern' => '/_DELETED_/',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
),
// Hiding thumbnails
array(
'pattern' => '/.tmb/',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
),
array(
'pattern' => '/.thumbs/',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
),
array(
'pattern' => '/.quarantine/',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
)
);
/*
var defaultCommands = [
'open', 'reload', 'home', 'up', 'back', 'forward', 'getfile', 'quicklook',
'download', 'rm', 'duplicate', 'rename', 'mkdir', 'mkfile', 'upload', 'copy',
'cut', 'paste', 'edit', 'extract', 'archive', 'search', 'info', 'view', 'help',
'resize', 'sort'
];
*/
$this->driverList = $list;
}
// for more options: https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options
$commonSettings = array(
'uploadOverwrite' => false, // Replace files on upload or give them new name if the same file was uploaded
//'acceptedName' =>
'uploadAllow' => array(
'image',
'audio',
'video',
'text/html',
'application/pdf',
'application/postscript',
'application/vnd.ms-word',
'application/vnd.ms-excel',
'application/vnd.ms-powerpoint',
'application/pdf',
'application/xml',
'application/vnd.oasis.opendocument.text',
'application/x-shockwave-flash'
), # allow files
//'uploadDeny' => array('text/x-php'),
'uploadOrder' => array('allow'), // only executes allow
'disabled' => array (
'duplicate', 'rename', 'mkdir', 'mkfile', 'copy', 'cut', 'paste', 'edit', 'extract', 'archive', 'help', 'resize'
)
/**
* Available driver list.
* @return array
*/
private function getDefaultDriverList()
{
return array(
'CourseDriver',
'CourseUserDriver',
'HomeDriver',
'PersonalDriver'
);
}
if (!empty($courseInfo)) {
// Adding course driver
$opts['roots'][] = array(
'driver' => 'LocalFileSystem',
'path' => api_get_path(SYS_DATA_PATH).'courses/'.$courseInfo['path'].'/document',
'startPath' => '/',
'URL' => api_get_path(REL_COURSE_PATH).$courseInfo['path'].'/document',
//'alias' => $courseInfo['code'].' documents',
'accessControl' => array($this, 'access'),
'attributes' => array(
// Hide shared_folder
array(
'pattern' => '/shared_folder/',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
),
)
);
/**
* @param string $cmd
* @param array $result
* @param array $args
* @param Finder $elFinder
*/
public function manageCommands($cmd, $result, $args, $elFinder)
{
$cmd = ucfirst($cmd);
$cmd = 'after'.$cmd;
if (isset($args['target'])) {
$driverName = $elFinder->getVolumeDriverNameByTarget($args['target']);
}
// Adding course user file driver
if (isset($args['targets'])) {
foreach ($args['targets'] as $target) {
$driverName = $elFinder->getVolumeDriverNameByTarget($target);
break;
}
}
if (!empty($userId)) {
$opts['roots'][] = array(
'driver' => 'LocalFileSystem',
'path' => api_get_path(SYS_DATA_PATH).'courses/'.$courseInfo['path'].'/document/shared_folder/sf_user_'.$userId,
'startPath' => '/',
//'alias' => $courseInfo['code'].' personal documents',
'URL' => api_get_path(REL_COURSE_PATH).$courseInfo['path'].'/document/shared_folder/sf_user_'.$userId,
'accessControl' => 'access'
);
if (empty($driverName)) {
return false;
}
// Adding user personal files
if (!empty($result['error'])) {
}
$dir = \UserManager::get_user_picture_path_by_id($userId, 'system');
$dirWeb = \UserManager::get_user_picture_path_by_id($userId, 'web');
if (!empty($result['warning'])) {
}
$opts['roots'][] = array(
'driver' => 'LocalFileSystem',
'path' => $dir['dir'].'my_files',
'startPath' => '/',
//'alias' => 'Personal documents',
'URL' => $dirWeb['dir'].'my_files',
'accessControl' => 'access'
);
if (!empty($result['removed'])) {
foreach ($result['removed'] as $file) {
/** @var Driver $driver */
$driver = $this->getDriver($driverName);
$driver->$cmd($file, $args, $elFinder);
// removed file contain additional field "realpath"
//$log .= "\tREMOVED: ".$file['realpath']."\n";
}
} else {
// Adding user personal files
$dir = \UserManager::get_user_picture_path_by_id($userId, 'system');
$dirWeb = \UserManager::get_user_picture_path_by_id($userId, 'web');
$opts['roots'][] = array(
'driver' => 'LocalFileSystem',
'path' => $dir['dir'].'my_files',
'startPath' => '/',
'URL' => $dirWeb['dir'].'my_files',
'accessControl' => 'access'
);
}
// Add home portal
if (api_is_platform_admin()) {
$home = api_get_path(SYS_DATA_PATH).'home';
$opts['roots'][] = array(
'driver' => 'LocalFileSystem',
'path' => $home,
'startPath' => '/',
'URL' => api_get_path(WEB_DATA_PATH).'home',
'accessControl' => 'access'
);
if (!empty($result['added'])) {
foreach ($result['added'] as $file) {
$driver = $this->getDriver($driverName);
$driver->$cmd($file, $args, $elFinder);
}
}
// Injecting common file filters
foreach ($opts['roots'] as &$driver) {
$driver = array_merge($driver, $commonSettings);
if (isset($driver['attributes'])) {
$driver['attributes'] = array_merge($driver['attributes'], $commonAttributes);
} else {
$driver['attributes'] = $commonAttributes;
if (!empty($result['changed'])) {
foreach ($result['changed'] as $file) {
//$log .= "\tCHANGED: ".$elfinder->realpath($file['hash'])."\n";
}
}
}
return $opts;
/**
* @param string $driver
* @return string
*/
private function getDriverClass($driver)
{
return 'ChamiloLMS\Component\Editor\Driver\\'.$driver;
}
}

@ -0,0 +1,141 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\Driver;
use ChamiloLMS\Component\Editor\Finder;
/**
* Class CourseDriver
* @package ChamiloLMS\Component\Editor\Driver
*/
class CourseDriver extends Driver
{
public $name = 'CourseDriver';
/**
* {@inheritdoc}
*/
public function getConfiguration()
{
if ($this->connector->course) {
return array(
'driver' => 'CourseDriver',
'path' => $this->getCourseDocumentSysPath(),
'startPath' => '/',
'URL' => $this->getCourseDocumentWebPath(),
'accessControl' => array($this, 'access'),
'alias' => $this->connector->translator->trans('CourseDocument'),
'attributes' => array(
// Hide shared_folder
array(
'pattern' => '/shared_folder/',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
),
)
);
}
}
/**
* @param array $file
* @param array $args
* @param Finder $elFinder
*/
public function afterUpload($file, $args, $elFinder)
{
if ($file) {
$name = $file['name'];
$filtered = \URLify::filter($file['name'], 80);
if (strcmp($name, $filtered) != 0) {
$arg = array('target' => $file['hash'], 'name' => $filtered);
$elFinder->exec('rename', $arg);
}
$realPath = $elFinder->realpath($file['hash']);
if (!empty($realPath)) {
// Getting file info
//$info = $elFinder->exec('file', array('target' => $file['hash']));
/** @var elFinderVolumeLocalFileSystem $volume */
//$volume = $info['volume'];
//$root = $volume->root();
//var/www/chamilogits/data/courses/NEWONE/document
$realPathRoot = $this->getCourseDocumentSysPath();
// Removing course path
$realPath = str_replace($realPathRoot, '/', $realPath);
\FileManager::add_document(
$this->connector->course,
$realPath,
'file',
intval($file['size']),
$file['name']
);
}
}
}
/**
* @return string
*/
public function getCourseDocumentSysPath()
{
$directory = $this->connector->course->getDirectory();
$dataPath = $this->connector->paths['sys_data_path'];
$url = $dataPath.'courses/'.$directory.'/document/';
return $url;
}
/**
* @return string
*/
public function getCourseDocumentWebPath()
{
$directory = $this->connector->course->getDirectory();
$url = api_get_path(REL_COURSE_PATH).$directory.'/document/';
return $url;
}
/**
* {@inheritdoc}
*/
public function upload($fp, $dst, $name, $tmpname)
{
$result = parent::upload($fp, $dst, $name, $tmpname);
return $result;
}
/**
* @param array $file
* @param array $args
* @param Finder $elFinder
*/
public function afterRm($file, $args, $elFinder)
{
$realFilePath = $file['realpath'];
$coursePath = $this->connector->paths['sys_data_path'].'courses/'.$this->connector->course->getDirectory().'/document';
$filePath = str_replace($coursePath, '', $realFilePath);
\DocumentManager::delete_document($this->connector->course, $filePath, $coursePath);
}
/**
* {@inheritdoc}
*/
public function rm($hash)
{
// elfinder does not delete the file
//parent::rm($hash);
$path = $this->decode($hash);
$stat = $this->stat($path);
$stat['realpath'] = $path;
$this->removed[] = $stat;
return true;
}
}

@ -0,0 +1,35 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\Driver;
/**
* Class CourseUserDriver
* @package ChamiloLMS\Component\Editor\Driver
*/
class CourseUserDriver extends CourseDriver
{
public $name = 'CourseUserDriver';
/**
* {@inheritdoc}
*/
public function getConfiguration()
{
if ($this->connector->course) {
$userId = $this->connector->user->getUserId();
$path = 'shared_folder/sf_user_'.$userId;
if (!empty($userId)) {
return array(
'driver' => 'CourseUserDriver',
'alias' => $this->connector->translator->trans('CourseUserDocument'),
'path' => $this->getCourseDocumentSysPath().$path,
'startPath' => '/',
//'alias' => $courseInfo['code'].' personal documents',
'URL' => $this->getCourseDocumentWebPath().$path,
'accessControl' => 'access'
);
}
}
}
}

@ -0,0 +1,178 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\Driver;
use ChamiloLMS\Component\Editor\Connector;
/**
* Class Driver
* @package ChamiloLMS\Component\Editor\Driver
*/
class Driver extends \elFinderVolumeLocalFileSystem
{
/** @var string */
public $name;
/** @var Connector */
public $connector;
/**
* Gets driver name.
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Gets driver name.
* @param string
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Set connector
* @param Connector $connector
*/
public function setConnector(Connector $connector)
{
$this->connector = $connector;
}
/**
* Get default driver settings.
* @return array
*/
private function getDefaultDriverSettings()
{
// for more options: https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options
return array(
'plugin' => array(
'name' => $this->name
),
'uploadOverwrite' => false, // Replace files on upload or give them new name if the same file was uploaded
//'acceptedName' =>
'uploadAllow' => array(
'image',
'audio',
'video',
'text/html',
'text/csv',
'application/pdf',
'application/postscript',
'application/vnd.ms-word',
'application/vnd.ms-excel',
'application/vnd.ms-powerpoint',
'application/pdf',
'application/xml',
'application/vnd.oasis.opendocument.text',
'application/x-shockwave-flash'
), # allow files
//'uploadDeny' => array('text/x-php'),
'uploadOrder' => array('allow'), // only executes allow
'disabled' => array(
'duplicate',
'rename',
'mkdir',
'mkfile',
'copy',
'cut',
'paste',
'edit',
'extract',
'archive',
'help',
'resize'
),
'attributes' => array(
// Hiding dangerous files
array(
'pattern' => '/\.(php|py|pl|sh|xml)$/i',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
),
// Hiding _DELETED_ files
array(
'pattern' => '/_DELETED_/',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
),
// Hiding thumbnails
array(
'pattern' => '/.tmb/',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
),
array(
'pattern' => '/.thumbs/',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
),
array(
'pattern' => '/.quarantine/',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
)
)
);
}
/**
* Merges the default driver settings.
* @param array $driver
* @return array
*/
public function updateWithDefaultValues($driver)
{
if (empty($driver)) {
return array();
}
$defaultDriver = $this->getDefaultDriverSettings();
if (isset($driver['attributes'])) {
$attributes = array_merge($defaultDriver['attributes'], $driver['attributes']);
} else {
$attributes = $defaultDriver['attributes'];
}
$driverUpdated = array_merge($defaultDriver, $driver);
$driverUpdated['driver'] = 'ChamiloLMS\Component\Editor\Driver\\'.$driver['driver'];
$driverUpdated['attributes'] = $attributes;
return $driverUpdated;
}
/**
* @param array $file
* @param array $args
* @param Finder $elFinder
*/
public function afterUpload($file, $args, $elFinder)
{
}
/**
* @param array $file
* @param array $args
* @param Finder $elFinder
*/
public function afterRm($file, $args, $elFinder)
{
}
}

@ -0,0 +1,52 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\Driver;
/**
* Class HomeDriver
* @package ChamiloLMS\Component\Editor\Driver
*/
class HomeDriver extends Driver
{
public $name = 'HomeDriver';
/**
* {@inheritdoc}
*/
public function getConfiguration()
{
if ($this->connector->security->isGranted('ROLE_ADMIN')) {
$home = api_get_path(SYS_DATA_PATH).'home';
return array(
'driver' => 'HomeDriver',
'alias' => $this->connector->translator->trans('Portal'),
'path' => $home,
'startPath' => '/',
'URL' => api_get_path(WEB_DATA_PATH).'home',
'accessControl' => array($this, 'access'),
);
}
}
/**
* {@inheritdoc}
*/
public function upload($fp, $dst, $name, $tmpname)
{
// error_log(intval($this->connector->security->isGranted('ROLE_ADMIN')));
// can't use $this->connector->security
if (api_is_platform_admin()) {
return parent::upload($fp, $dst, $name, $tmpname);
}
}
/**
* {@inheritdoc}
*/
public function rm($hash)
{
if (api_is_platform_admin()) {
return parent::rm($hash);
}
}
}

@ -0,0 +1,53 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor\Driver;
/**
* Class PersonalDriver
* @package ChamiloLMS\Component\Editor\Driver
*/
class PersonalDriver extends Driver
{
public $name = 'PersonalDriver';
/**
* {@inheritdoc}
*/
public function getConfiguration()
{
$userId = $this->connector->user->getUserId();
if (!empty($userId)) {
// Adding user personal files
$dir = \UserManager::get_user_picture_path_by_id($userId, 'system');
$dirWeb = \UserManager::get_user_picture_path_by_id($userId, 'web');
$driver = array(
'driver' => 'PersonalDriver',
'alias' => $this->connector->translator->trans('MyFiles'),
'path' => $dir['dir'].'my_files',
'startPath' => '/',
'URL' => $dirWeb['dir'].'my_files',
'accessControl' => array($this, 'access'),
);
return $driver;
}
}
/**
* {@inheritdoc}
*/
public function upload($fp, $dst, $name, $tmpname)
{
return parent::upload($fp, $dst, $name, $tmpname);
}
/**
* {@inheritdoc}
*/
public function rm($hash)
{
return parent::rm($hash);
}
}

@ -2,6 +2,10 @@
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Component\Editor;
use \Symfony\Component\Translation\Translator;
use Symfony\Component\Routing\Router;
use \Entity\Course;
/**
* Class Editor
* @package ChamiloLMS\Component\Editor
@ -35,26 +39,28 @@ class Editor
*/
public $config;
/** @var \Symfony\Component\Translation\Translator */
/** @var Translator */
public $translator;
/** @var \Symfony\Component\Routing\Generator\UrlGenerator */
/** @var Router */
public $urlGenerator;
/**
* @param \Symfony\Component\Translation\Translator $translator
* @param \Symfony\Component\Routing\Generator\UrlGenerator $urlGenerator
* @param Translator $translator
* @param Router $urlGenerator
* @param Course $course
*/
public function __construct(\Symfony\Component\Translation\Translator $translator, $urlGenerator)
public function __construct(Translator $translator, Router $urlGenerator, $course)
{
$this->toolbarSet = 'Basic';
$this->value = '';
$this->config = array();
$this->config = array();
$this->setConfigAttribute('width', '100%');
$this->setConfigAttribute('height', '200');
$this->setConfigAttribute('fullPage', false);
$this->translator = $translator;
$this->urlGenerator = $urlGenerator;
$this->course = $course;
}
/**
@ -150,27 +156,6 @@ class Editor
}
}
/**
* This method determines editor's interface language and returns it as compatible with the editor langiage code.
* @return array
*/
private function getEditorLanguage()
{
static $config;
if (!is_array($config)) {
$code_translation_table = array('' => 'en', 'sr' => 'sr-latn', 'zh' => 'zh-cn', 'zh-tw' => 'zh');
$editor_lang = strtolower(str_replace('_', '-', api_get_language_isocode()));
$editor_lang = isset($code_translation_table[$editor_lang]) ? $code_translation_table[$editor_lang] : $editor_lang;
$editor_lang = file_exists(
api_get_path(SYS_PATH).'main/inc/lib/fckeditor/editor/lang/'.$editor_lang.'.js'
) ? $editor_lang : 'en';
$config['DefaultLanguage'] = $editor_lang;
$config['ContentLangDirection'] = api_get_text_direction($editor_lang);
}
return $config;
}
/**
* @param string $key
* @param mixed $value
@ -228,6 +213,14 @@ class Editor
return null;
}
/**
* @return string
*/
public function getEditorStandAloneTemplate()
{
return 'javascript/editor/elfinder_standalone.tpl';
}
/**
* @return null
*/

@ -0,0 +1,58 @@
<?php
namespace ChamiloLMS\Component\Editor;
/**
* elFinder - file manager for web.
* Core class.
*
* @package elfinder
* @author Dmitry (dio) Levashov
* @author Troex Nevelin
* @author Alexey Sukhotin
**/
class Finder extends \elFinder
{
/**
* @param string $target
* @return bool|\elFinderVolumeDriver
*/
public function getVolumeByTarget($target)
{
$volumeParts = explode('_', $target);
$requestVolume = $volumeParts[0];
/** @var \elFinderVolumeDriver $volume */
foreach ($this->volumes as $volume) {
if ($volume->id() == $requestVolume.'_') {
return $volume;
}
}
return false;
}
/**
* @param string $target
* @return bool|\elFinderVolumeDriver
*/
public function getVolumeDriverNameByTarget($target)
{
$volumeParts = explode('_', $target);
$requestVolume = $volumeParts[0];
/** @var \elFinderVolumeDriver $volume */
foreach ($this->volumes as $volume) {
if ($volume->id() == $requestVolume.'_') {
$options = $volume->getOptionsPlugin();
return $options['name'];
}
}
return false;
}
/**
* @return array
*/
public function getVolumes()
{
return $this->volumes;
}
}

@ -76,12 +76,32 @@ abstract class BaseController extends FlintController
return $this->get('html_editor');
}
/**
* @return \ChamiloLMS\Component\Editor\Connector
*/
protected function getEditorConnector()
{
return $this->get('editor_connector');
}
/**
* @return \ChamiloLMS\Component\DataFilesystem\DataFilesystem
*/
protected function getDataFileSystem()
{
return $this->get('chamilo.filesystem');
}
/**
* @return \Entity\User
*/
public function getUser()
{
return parent::getUser();
$user = parent::getUser();
if (empty($user)) {
return $this->abort(404, 'Login required.');
}
return $user;
}
/**

@ -16,7 +16,6 @@ use Symfony\Component\HttpFoundation\Response;
*/
class ProfileController extends CommonController
{
/**
* @Route("/{username}")
* @Method({"GET"})
@ -40,16 +39,33 @@ class ProfileController extends CommonController
*/
public function fileAction($username)
{
if ($this->getUser()->getUsername() != $username) {
return $this->abort(401);
}
$userId = \UserManager::get_user_id_from_username($username);
$userInfo = api_get_user_info($userId);
$editor = $this->getTemplate()->renderTemplate($this->getHtmlEditor()->getEditorTemplate());
$this->getTemplate()->assign('driver_list', 'PersonalDriver');
$editor = $this->getTemplate()->renderTemplate($this->getHtmlEditor()->getEditorStandAloneTemplate());
$this->getTemplate()->assign('user', $userInfo);
$this->getTemplate()->assign('editor', $editor);
$response = $this->getTemplate()->renderTemplate($this->getTemplatePath().'files.tpl');
return new Response($response, 200, array());
}
/**
* Gets that rm.wav sound
* @Route("/{username}/sounds/{file}")
* @Method({"GET"})
*/
public function getSoundAction()
{
$file = api_get_path(LIBRARY_PATH).'elfinder/rm.wav';
return $this->app->sendFile($file);
}
/**
* {@inheritdoc}
*/

@ -37,7 +37,7 @@ class UserController extends CommonController
*/
public function onlineAction(Application $app)
{
$response = $app['template']->render_layout('layout_1_col.tpl');
$response = $app['template']->renderLayout('layout_1_col.tpl');
return new Response($response, 200, array());
}

Loading…
Cancel
Save