Fix vchamilo plugin in order to use URL with a url_append

Example, vchamilo with this URL should work

my.chamilo.net/chamilo_site1
my.chamilo.net/chamilo_site2
my.chamilo.net
pull/2487/head
jmontoyaa 8 years ago
parent e1f7f45baf
commit 23c07f91fe
  1. 10
      main/inc/lib/api.lib.php
  2. 3
      plugin/vchamilo/lang/english.php
  3. 53
      plugin/vchamilo/lib/Virtual.php
  4. 3
      plugin/vchamilo/views/editinstance.php
  5. 35
      plugin/vchamilo/views/editinstance_form.php

@ -819,10 +819,12 @@ function api_get_path($path = '', $configuration = [])
global $virtualChamilo;
if (!empty($virtualChamilo)) {
$paths[$root_web][SYS_ARCHIVE_PATH] = $virtualChamilo[SYS_ARCHIVE_PATH].'/';
$paths[$root_web][SYS_HOME_PATH] = $virtualChamilo[SYS_HOME_PATH].'/';
$paths[$root_web][SYS_COURSE_PATH] = $virtualChamilo[SYS_COURSE_PATH].'/';
$paths[$root_web][SYS_UPLOAD_PATH] = $virtualChamilo[SYS_UPLOAD_PATH].'/';
$paths[$root_web][SYS_ARCHIVE_PATH] = api_add_trailing_slash($virtualChamilo[SYS_ARCHIVE_PATH]);
$paths[$root_web][SYS_HOME_PATH] = api_add_trailing_slash($virtualChamilo[SYS_HOME_PATH]);
$paths[$root_web][SYS_COURSE_PATH] = api_add_trailing_slash($virtualChamilo[SYS_COURSE_PATH]);
$paths[$root_web][SYS_UPLOAD_PATH] = api_add_trailing_slash($virtualChamilo[SYS_UPLOAD_PATH]);
//$paths[$root_web][REL_PATH] = $virtualChamilo[REL_PATH];
//$paths[$root_web][REL_COURSE_PATH] = $virtualChamilo[REL_COURSE_PATH];
}
$isInitialized[$root_web] = true;

@ -103,12 +103,13 @@ $strings['syncthis'] = 'Sync this setting';
$strings['SiteNameExample'] = 'Example: Chamilo';
$strings['InstitutionExample'] = 'Example: Chamilo Association';
$strings['RootWebExample'] = 'Example: http://www.chamilo.org/';
$strings['RootWebExample'] = 'Example: http://www.chamilo.org/ (with final slash)';
$strings['DatabaseDescription'] = 'A new database will be created with that name.';
$strings['RootWebExists'] = 'An instance with the same root web exists.';
$strings['ImportInstance'] = 'Import instance';
$strings['ConfigurationPath'] = 'Chamilo configuration path';
$strings['UploadRealRoot'] = 'Upload files';
$strings['DatabaseAccessShouldBeDifferentThanMasterChamilo'] = 'Database server should be different than the Chamilo master';
$strings['UrlAppendExample'] = 'Example: /chamilo_v1 (with first slash)';

@ -24,7 +24,8 @@ class Virtual
return;
}
// provides an effective value for the virtual root_web based on domain analysis
// provides an effective value for the virtual root_web based on domain analysis
self::getHostName($_configuration);
// We are on physical chamilo. Let original config play
@ -40,8 +41,7 @@ class Virtual
/** @var \Doctrine\DBAL\Connection $connection */
$connection = Virtual::bootConnection($_configuration);
$table = 'vchamilo';
$query = "SELECT * FROM $table WHERE root_web = '$virtualChamiloWebRoot'";
$query = "SELECT * FROM vchamilo WHERE root_web = '$virtualChamiloWebRoot'";
$result = $connection->executeQuery($query);
if ($result->rowCount()) {
@ -86,15 +86,19 @@ class Virtual
if ($data && $data['visible'] === '1') {
foreach ($data as $key => $value) {
if (!in_array($key, $excludes)) {
// Avoid empty password_encryption
if ($key == 'password_encryption' && empty($value)) {
continue;
}
$_configuration[$key] = $value;
}
$_configuration['virtual'] = $data['root_web'].'/';
}
$data['SYS_ARCHIVE_PATH'] = $archivePath.'/'.$data['slug'];
$data['SYS_HOME_PATH'] = $homePath.'/'.$data['slug'];
$data['SYS_COURSE_PATH'] = $coursePath.'/'.$data['slug'];
$data['SYS_UPLOAD_PATH'] = $uploadPath.'/'.$data['slug'];
$data['SYS_ARCHIVE_PATH'] = self::addTrailingSlash($archivePath).$data['slug'];
$data['SYS_HOME_PATH'] = self::addTrailingSlash($homePath).$data['slug'];
$data['SYS_COURSE_PATH'] = self::addTrailingSlash($coursePath).$data['slug'];
$data['SYS_UPLOAD_PATH'] = self::addTrailingSlash($uploadPath).$data['slug'];
if (!empty($passwordEncryption)) {
$_configuration['password_encryption'] = $passwordEncryption;
@ -139,7 +143,24 @@ class Virtual
return;
}
$_configuration['vchamilo_web_root'] = "{$protocol}://".@$_SERVER['HTTP_HOST'];
$contentPrefix = '/';
if (isset($_SERVER['CONTEXT_PREFIX']) && !empty($_SERVER['CONTEXT_PREFIX'])) {
$contentPrefix = $_SERVER['CONTEXT_PREFIX'];
} else {
// Getting url_append from URL
if (isset($_SERVER['REQUEST_URI'])) {
$requestUri = $_SERVER['REQUEST_URI'];
if (strpos($requestUri, '/courses/') !== false) {
$result = substr($requestUri, 0, strpos($requestUri, '/courses/'));
if (!empty($result) && $result != '/') {
$contentPrefix = $result;
}
}
}
}
$_configuration['vchamilo_web_root'] = "{$protocol}://".@$_SERVER['HTTP_HOST'].$contentPrefix;
$_configuration['vchamilo_name'] = @$_SERVER['HTTP_HOST'];
if (empty($_configuration['vchamilo_name'])) { // try again with another source if has failed
$_configuration['vchamilo_name'] = "{$protocol}://".$_SERVER['SERVER_NAME'];
@ -150,6 +171,15 @@ class Virtual
}
}
/**
* @param string $path
* @return string
*/
public static function addTrailingSlash($path)
{
return substr($path, -1) == '/' ? $path : $path.'/';
}
/**
* provides a side connection to a vchamilo database
* @param array $_configuration
@ -659,7 +689,7 @@ class Virtual
);
copyDirTo(
self::chopLastSlash($templateDir.'/data/upload'),
self::chopLastSlash($templateDir.'/data/upload/'),
self::chopLastSlash($uploadPath),
false
);
@ -756,7 +786,8 @@ class Virtual
$slugify = new Slugify();
$urlInfo = parse_url($url);
if (isset($urlInfo['host'])) {
return $slugify->slugify($urlInfo['host']);
$path = $urlInfo['path'] != '/' ? '_'.$urlInfo['path'] : '';
return $slugify->slugify($urlInfo['host'].$path);
}
return false;
@ -907,6 +938,8 @@ class Virtual
return ;
}
$data->root_web = api_add_trailing_slash($data->root_web);
self::ctrace('Registering: '.$data->root_web);
$tablename = Database::get_main_table('vchamilo');
$sql = "SELECT * FROM $tablename

@ -39,8 +39,7 @@ if ($data = $form->get_data()) {
case 'registerinstance':
Virtual::addInstance($data);
echo '<a class="btn btn-primary" href="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php'.'">Continue</a>';
// vchamilo_redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
die;
exit;
break;
case 'updateinstance':
unset($data->what);

@ -272,7 +272,7 @@ abstract class ChamiloForm
$status = $this->_upload_manager->preprocess_files();
// now check that we really want each file
foreach ($_FILES as $elname=>$file) {
foreach ($_FILES as $elname => $file) {
if ($mform->elementExists($elname) and $mform->getElementType($elname)=='file') {
$required = $mform->isElementRequired($elname);
if (!empty($this->_upload_manager->files[$elname]['uploadlog']) &&
@ -294,9 +294,7 @@ abstract class ChamiloForm
// return errors if found
if ($status && 0 == count($errors)) {
return true;
} else {
$files = array();
@ -363,6 +361,12 @@ class InstanceForm extends ChamiloForm
);
$form->applyFilter('root_web', 'trim');
$form->addElement(
'text',
'url_append',
['url_append', $plugin->get_lang('UrlAppendExample')]
);
if ($this->_mode == 'update') {
$encryptList = Virtual::getEncryptList();
$encryptMethod = $form->addElement(
@ -427,6 +431,31 @@ class InstanceForm extends ChamiloForm
);
} else {
if ($this->instance) {
$form->addLabel(
'slug',
$this->instance['slug']
);
$form->addLabel(
'archive_real_root',
Virtual::getConfig('vchamilo', 'archive_real_root').$this->instance['slug']
);
$form->addLabel(
'course_real_root',
Virtual::getConfig('vchamilo', 'course_real_root').$this->instance['slug']
);
$form->addLabel(
'home_real_root',
Virtual::getConfig('vchamilo', 'home_real_root').$this->instance['slug']
);
$form->addLabel(
'upload_real_root',
Virtual::getConfig('vchamilo', 'upload_real_root').$this->instance['slug']
);
$form->addLabel(
$this->_plugin->get_lang('template'),
$this->instance['template']

Loading…
Cancel
Save