Skip to content

Commit

Permalink
Add app/upload/badges
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Apr 28, 2015
1 parent 110b310 commit 417f86f
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 250 deletions.
Empty file added app/upload/badges/.gitkeep
Empty file.
35 changes: 14 additions & 21 deletions main/admin/skill_badge_create.php
Expand Up @@ -5,7 +5,7 @@
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.admin.openbadges
*/
use \ChamiloSession as Session;
use ChamiloSession as Session;

$cidReset = true;

Expand All @@ -32,46 +32,39 @@

if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) {
$dirPermissions = api_get_permissions_for_new_directories();
$sysPath = api_get_path(SYS_PATH);
$sysDataPath = api_get_path(SYS_DATA_PATH);

$existsDataDirectory = is_dir($sysDataPath);

if (!$existsDataDirectory) {
$existsDataDirectory = api_create_protected_dir('data', $sysPath);
}

$fileDir = "badges/";
$fileName = sha1($_POST['name']);

$existsBadgesDirectory = is_dir($sysDataPath . 'badges/');
$badgePath = api_get_path(SYS_UPLOAD_PATH).'badges/';

$existsBadgesDirectory = is_dir($badgePath);

if (!$existsBadgesDirectory) {
$existsBadgesDirectory = api_create_protected_dir('badges', $sysDataPath);
$existsBadgesDirectory = api_create_protected_dir('badges', api_get_path(SYS_UPLOAD_PATH));
}

if ($existsBadgesDirectory) {
if (!empty($skill['icon'])) {
$iconFileAbsolutePath = $sysDataPath . $skill['icon'];
$iconDirAbsolutePath = $sysDataPath . $fileDir;

if (Security::check_abs_path($iconFileAbsolutePath, $iconDirAbsolutePath)) {
unlink($sysDataPath . $skill['icon']);
/*if (!empty($skill['icon'])) {
$iconFileAbsolutePath = $badgePath . $skill['icon'];
if (Security::check_abs_path($iconFileAbsolutePath, $badgePath)) {
unlink($badgePath . $skill['icon']);
}
}
}*/

$skillImagePath = sprintf("%s%s%s.png", $sysDataPath, $fileDir, $fileName);
$skillImagePath = sprintf("%s%s.png", $badgePath, $fileName);

$skillImage = new Image($_FILES['image']['tmp_name']);
$skillImage->send_image($skillImagePath, -1, 'png');

$skillThumbPath = sprintf("%s%s%s-small.png", $sysDataPath, $fileDir, $fileName);
$skillThumbPath = sprintf("%s%s-small.png", $badgePath, $fileName);

$skillImageThumb = new Image($skillImagePath);
$skillImageThumb->resize(ICON_SIZE_BIG, ICON_SIZE_BIG);
$skillImageThumb->send_image($skillThumbPath);

$params['icon'] = sprintf("%s%s.png", $fileDir, $fileName);
$params['icon'] = sprintf("%s.png", $fileName);
} else {
Session::write('errorMessage', get_lang('UplUnableToSaveFile'));
}
Expand Down
3 changes: 2 additions & 1 deletion main/admin/skill_badge_list.php
@@ -1,11 +1,12 @@
<?php
/* For licensing terms, see /license.txt */

/**
* Show information about Mozilla OpenBadges
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.admin.openbadges
*/
use \ChamiloSession as Session;
use ChamiloSession as Session;

$cidReset = true;

Expand Down
2 changes: 1 addition & 1 deletion main/badge/class.php
Expand Up @@ -17,7 +17,7 @@
$json = array(
'name' => $skill['name'],
'description' => $skill['description'],
'image' => api_get_path(WEB_DATA_PATH) . $skill['icon'],
'image' => api_get_path(WEB_UPLOAD_PATH) . $skill['icon'],
'criteria' => api_get_path(WEB_CODE_PATH) . "badge/criteria.php?id=$skillId",
'issuer' => api_get_path(WEB_CODE_PATH) . "badge/issuer.php",
);
Expand Down
19 changes: 7 additions & 12 deletions main/inc/lib/api.lib.php
Expand Up @@ -274,6 +274,8 @@
define('SYS_PATH', 'SYS_PATH');
define('SYS_APP_PATH', 'SYS_APP_PATH');
define('SYS_UPLOAD_PATH', 'SYS_UPLOAD_PATH');
define('WEB_UPLOAD_PATH', 'WEB_UPLOAD_PATH');

define('REL_PATH', 'REL_PATH');
define('WEB_SERVER_ROOT_PATH', 'WEB_SERVER_ROOT_PATH');
define('SYS_SERVER_ROOT_PATH', 'SYS_SERVER_ROOT_PATH');
Expand Down Expand Up @@ -303,8 +305,6 @@
define('SYS_TEMPLATE_PATH', 'SYS_TEMPLATE_PATH');
define('WEB_FONTS_PATH', 'WEB_FONTS_PATH');
define('SYS_FONTS_PATH', 'SYS_FONTS_PATH');
define('SYS_DATA_PATH', 'SYS_DATA_PATH');
define('WEB_DATA_PATH', 'WEB_DATA_PATH');

define('SYS_DEFAULT_COURSE_DOCUMENT_PATH', 'SYS_DEFAULT_COURSE_DOCUMENT_PATH');
define('REL_DEFAULT_COURSE_DOCUMENT_PATH', 'REL_DEFAULT_COURSE_DOCUMENT_PATH');
Expand Down Expand Up @@ -580,11 +580,9 @@
* api_get_path(SYS_PATH) /var/www/chamilo/
* api_get_path(SYS_APP_PATH) /var/www/chamilo/app/
* api_get_path(SYS_UPLOAD_PATH) /var/www/chamilo/app/upload/
*
* api_get_path(SYS_ARCHIVE_PATH) /var/www/chamilo/app/cache
* api_get_path(SYS_COURSE_PATH) /var/www/chamilo/app/courses/
* api_get_path(SYS_CODE_PATH) /var/www/chamilo/main/
* api_get_path(SYS_DATA_PATH) /var/www/chamilo/data/
* api_get_path(INCLUDE_PATH) /var/www/chamilo/main/inc/
* api_get_path(LIBRARY_PATH) /var/www/chamilo/main/inc/lib/
* api_get_path(CONFIGURATION_PATH) /var/www/chamilo/main/inc/conf/
Expand All @@ -598,14 +596,15 @@
* api_get_path(WEB_PATH) http://www.mychamilo.org/chamilo/
* api_get_path(WEB_COURSE_PATH) http://www.mychamilo.org/chamilo/courses/
* api_get_path(WEB_CODE_PATH) http://www.mychamilo.org/chamilo/main/
* api_get_path(WEB_DATA_PATH) http://www.mychamilo.org/chamilo/data/
* api_get_path(WEB_PLUGIN_PATH) http://www.mychamilo.org/chamilo/plugin/
* api_get_path(WEB_ARCHIVE_PATH) http://www.mychamilo.org/chamilo/app/cache/
* api_get_path(WEB_IMG_PATH) http://www.mychamilo.org/chamilo/main/img/
* api_get_path(WEB_CSS_PATH) http://www.mychamilo.org/chamilo/main/css/
* api_get_path(WEB_LIBRARY_PATH) http://www.mychamilo.org/chamilo/main/inc/lib/
* api_get_path(WEB_LIBRARY_JS_PATH) http://www.mychamilo.org/chamilo/web/Chamilo/javascript
* api_get_path(WEB_TEMPLATE_PATH) http://www.mychamilo.org/chamilo/main/template/
* api_get_path(WEB_UPLOAD_PATH) http://www.mychamilo.org/chamilo/app/upload/
*
*
*
* This is how we retrieve paths of "registerd" resource files (scripts, players, etc.):
Expand All @@ -626,14 +625,12 @@
function api_get_path($path_type, $path = null)
{
static $paths = array(
SYS_DATA_PATH => '',
WEB_PATH => '',
SYS_PATH => '',
REL_PATH => '',
WEB_SERVER_ROOT_PATH => '',
SYS_SERVER_ROOT_PATH => '',
WEB_COURSE_PATH => '',
WEB_DATA_PATH => '',
SYS_COURSE_PATH => '',
REL_COURSE_PATH => '',
REL_CODE_PATH => '',
Expand All @@ -657,6 +654,7 @@ function api_get_path($path_type, $path = null)
WEB_AJAX_PATH => 'inc/ajax/',
SYS_TEST_PATH => 'tests/',
WEB_TEMPLATE_PATH => 'template/',
WEB_UPLOAD_PATH => 'app/upload/',
SYS_TEMPLATE_PATH => 'template/',
WEB_FONTS_PATH => 'fonts/',
SYS_FONTS_PATH => 'fonts/',
Expand Down Expand Up @@ -759,8 +757,6 @@ function api_get_path($path_type, $path = null)
$paths[REL_CODE_PATH] = $root_rel.$code_folder;
$paths[WEB_CODE_PATH] = $root_web.$code_folder;
$paths[SYS_CODE_PATH] = $root_sys.$code_folder;
$paths[SYS_DATA_PATH] = $root_sys.$data_folder;
$paths[WEB_DATA_PATH] = $root_web.$data_folder;

$paths[WEB_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[WEB_CODE_PATH].'default_course_document/';
$paths[REL_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[REL_PATH].'main/default_course_document/';
Expand Down Expand Up @@ -790,6 +786,7 @@ function api_get_path($path_type, $path = null)
$paths[WEB_ARCHIVE_PATH] = $paths[WEB_PATH].$paths[WEB_ARCHIVE_PATH];

$paths[WEB_TEMPLATE_PATH] = $paths[WEB_CODE_PATH].$paths[WEB_TEMPLATE_PATH];
$paths[WEB_UPLOAD_PATH] = $paths[WEB_PATH].$paths[WEB_UPLOAD_PATH];

$paths[INCLUDE_PATH] = $paths[SYS_CODE_PATH].$paths[INCLUDE_PATH];
$paths[LIBRARY_PATH] = $paths[SYS_CODE_PATH].$paths[LIBRARY_PATH];
Expand All @@ -812,8 +809,7 @@ function api_get_path($path_type, $path = null)
WEB_PLUGIN_PATH => 'plugin/',
WEB_ARCHIVE_PATH => 'archive/',
WEB_LIBRARY_PATH => 'inc/lib/',
WEB_AJAX_PATH => 'inc/ajax/',
WEB_DATA_PATH => '',
WEB_AJAX_PATH => 'inc/ajax/'
);

$root_web = api_add_trailing_slash($root_web);
Expand All @@ -825,7 +821,6 @@ function api_get_path($path_type, $path = null)
$paths[WEB_SERVER_ROOT_PATH] = $server_base_web.'/';
$paths[WEB_COURSE_PATH] = $root_web.$course_folder;
$paths[WEB_CODE_PATH] = $root_web.$code_folder;
$paths[WEB_DATA_PATH] = $root_web.$data_folder;
$paths[WEB_IMG_PATH] = $paths[WEB_CODE_PATH].$web_paths[WEB_IMG_PATH];

$paths[WEB_CSS_PATH] = $paths[WEB_CODE_PATH].$web_paths[WEB_CSS_PATH];
Expand Down
2 changes: 1 addition & 1 deletion main/inc/lib/group_portal_manager.lib.php
Expand Up @@ -960,7 +960,7 @@ public static function get_group_picture_path_by_id($id, $type = 'web', $preview
break;
case 'web': // Base: absolute web path.
default:
$base = api_get_path(WEB_PATH).'app/uploads/';
$base = api_get_path(WEB_UPLOAD_PATH);
break;
}

Expand Down

0 comments on commit 417f86f

Please sign in to comment.