Integrade OneUpFlySystem to create admin blocks #2321

pull/2650/head
Angel Fernando Quiroz Campos 7 years ago
parent d340fde79b
commit 4d43e7fe01
  1. 9
      config/packages/oneup_flysystem.yaml
  2. 40
      main/admin/index.php
  3. 33
      main/inc/ajax/admin.ajax.php

@ -4,6 +4,10 @@ oneup_flysystem:
local:
directory: '%kernel.project_dir%/var/courses'
home_adapter:
local:
directory: '%kernel.project_dir%/var/home'
# s3.adapter:
# awss3v3:
# client: s3_client # add service "s3_client"
@ -16,3 +20,8 @@ oneup_flysystem:
cache: ~
alias: ~
mount: ~
home:
adapter: home_adapter
visibility: private
alias: home_filesystem

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use League\Flysystem\Filesystem;
/**
* Index page of the admin tools.
@ -23,7 +24,9 @@ api_protect_admin_script(true);
$nameTools = get_lang('PlatformAdmin');
$accessUrlId = 0;
$adminExtraContentDir = api_get_path(SYS_APP_PATH)."home/admin/";
/** @var Filesystem $fileSystem */
$fileSystem = Container::$container->get('home_filesystem');
$adminExtraContentDir = 'admin/';
if (api_is_multiple_url_enabled()) {
$accessUrlId = api_get_current_access_url_id();
@ -32,7 +35,7 @@ if (api_is_multiple_url_enabled()) {
$urlInfo = api_get_access_url($accessUrlId);
$url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $urlInfo['url']));
$cleanUrl = str_replace('/', '-', $url);
$adminExtraContentDir = api_get_path(SYS_APP_PATH)."home/$cleanUrl/admin/";
$adminExtraContentDir = "$cleanUrl/admin/";
}
}
@ -82,8 +85,8 @@ $blocks['users']['class'] = 'block-admin-users';
$usersBlockExtraFile = "{$adminExtraContentDir}block-admin-users_extra.html";
if (file_exists($usersBlockExtraFile)) {
$blocks['users']['extraContent'] = file_get_contents($usersBlockExtraFile);
if ($fileSystem->has($usersBlockExtraFile)) {
$blocks['users']['extraContent'] = $fileSystem->read($usersBlockExtraFile);
}
$search_form = '
@ -148,8 +151,8 @@ if (api_is_platform_admin()) {
$coursesBlockExtraFile = "{$adminExtraContentDir}block-admin-courses_extra.html";
if (file_exists($coursesBlockExtraFile)) {
$blocks['courses']['extraContent'] = file_get_contents($coursesBlockExtraFile);
if ($fileSystem->has($coursesBlockExtraFile)) {
$blocks['courses']['extraContent'] = $fileSystem->read($coursesBlockExtraFile);
}
$search_form = ' <form method="get" class="form-inline" action="course_list.php">
@ -207,8 +210,8 @@ if (api_is_platform_admin()) {
$platformBlockExtraFile = "{$adminExtraContentDir}block-admin-platform_extra.html";
if (file_exists($platformBlockExtraFile)) {
$blocks['platform']['extraContent'] = file_get_contents($platformBlockExtraFile);
if ($fileSystem->has($platformBlockExtraFile)) {
$blocks['platform']['extraContent'] = $fileSystem->read($platformBlockExtraFile);
}
$search_form = ' <form method="get" action="'.api_get_path(WEB_PUBLIC_PATH).'admin/settings/search_settings'.'" class="form-inline">
@ -298,8 +301,8 @@ $blocks['sessions']['class'] = 'block-admin-sessions';
$sessionsBlockExtraFile = "{$adminExtraContentDir}block-admin-sessions_extra.html";
if (file_exists($sessionsBlockExtraFile)) {
$blocks['sessions']['extraContent'] = file_get_contents($sessionsBlockExtraFile);
if ($fileSystem->has($sessionsBlockExtraFile)) {
$blocks['sessions']['extraContent'] = $fileSystem->read($sessionsBlockExtraFile);
}
if (api_is_platform_admin()) {
@ -682,22 +685,7 @@ if (api_is_platform_admin()) {
$extraData = array_map(['Security', 'remove_XSS'], $extraData);
if (!empty($extraData['block'])) {
if (!is_dir($adminExtraContentDir)) {
mkdir(
$adminExtraContentDir,
api_get_permissions_for_new_directories(),
true
);
}
if (!is_writable($adminExtraContentDir)) {
die;
}
$fullFilePath = $adminExtraContentDir.$extraData['block'];
$fullFilePath .= "_extra.html";
file_put_contents($fullFilePath, $extraData['extra_content']);
$fileSystem->put('admin/'.$extraData['block'].'_extra.html', $extraData['extra_content']);
header('Location: '.api_get_self());
exit;

@ -3,6 +3,8 @@
use Chamilo\CoreBundle\Entity\BranchSync;
use Chamilo\CoreBundle\Entity\Repository\BranchSyncRepository;
use Chamilo\CoreBundle\Framework\Container;
use League\Flysystem\Filesystem;
/**
* Responses to AJAX calls.
@ -43,34 +45,27 @@ switch ($action) {
die;
}
/** @var Filesystem $fileSystem */
$fileSystem = Container::$container->get('home_filesystem');
$dir = 'admin/';
if (api_is_multiple_url_enabled()) {
$accessUrlId = api_get_current_access_url_id();
if ($accessUrlId == -1) {
die;
if ($accessUrlId != -1) {
$urlInfo = api_get_access_url($accessUrlId);
$url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $urlInfo['url']));
$cleanUrl = str_replace('/', '-', $url);
$dir = "$cleanUrl/admin/";
}
$urlInfo = api_get_access_url($accessUrlId);
$url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $urlInfo['url']));
$cleanUrl = str_replace('/', '-', $url);
$newUrlDir = api_get_path(SYS_APP_PATH)."home/$cleanUrl/admin/";
} else {
$newUrlDir = api_get_path(SYS_APP_PATH)."home/admin/";
}
if (!file_exists($newUrlDir)) {
die;
}
$filePath = $dir.$blockName.'_extra.html';
if (!Security::check_abs_path("{$newUrlDir}{$blockName}_extra.html", $newUrlDir)) {
die;
}
if (!file_exists("{$newUrlDir}{$blockName}_extra.html")) {
die;
if ($fileSystem->has($filePath)) {
echo $fileSystem->read($dir.$blockName.'_extra.html');
}
echo file_get_contents("{$newUrlDir}{$blockName}_extra.html");
break;
}

Loading…
Cancel
Save