Minor - format code

pull/2487/head
jmontoyaa 9 years ago
parent 41f408aaf5
commit 703a6cb7ae
  1. 308
      main/inc/lib/image.lib.php
  2. 20
      main/lp/learnpathList.class.php
  3. 63
      main/session/add_users_to_session.php

@ -183,19 +183,19 @@ class ImagickWrapper extends ImageWrapper
}
}
public function get_image_size()
public function get_image_size()
{
$imagesize = array('width'=>0, 'height'=>0);
if ($this->image_validated) {
$imagesize = array('width'=>0, 'height'=>0);
if ($this->image_validated) {
$imagesize = $this->image->getImageGeometry();
}
return $imagesize;
}
}
return $imagesize;
}
//@todo implement border logic case for Imagick
public function resize($thumbw, $thumbh, $border, $specific_size = false)
//@todo implement border logic case for Imagick
public function resize($thumbw, $thumbh, $border, $specific_size = false)
{
if (!$this->image_validated) return false;
if (!$this->image_validated) return false;
if ($specific_size) {
$width = $thumbw;
@ -205,10 +205,10 @@ class ImagickWrapper extends ImageWrapper
$width = (int) ($this->width * $scale);
$height = (int) ($this->height * $scale);
}
$result = $this->image->resizeImage($width, $height, $this->filter, 1);
$this->width = $thumbw;
$this->height = $thumbh;
}
$result = $this->image->resizeImage($width, $height, $this->filter, 1);
$this->width = $thumbw;
$this->height = $thumbh;
}
/**
* @author José Loguercio <jose.loguercio@beeznest.com>
@ -219,51 +219,62 @@ class ImagickWrapper extends ImageWrapper
* @param int $src_width the source width of the original image
* @param int $src_height the source height of the original image
*/
public function crop($x, $y, $width, $height, $src_width, $src_height) {
if (!$this->image_validated) return false;
public function crop($x, $y, $width, $height, $src_width, $src_height)
{
if (!$this->image_validated) {
return false;
}
$this->image->cropimage($width, $height, $x, $y);
$this->width = $width;
$this->height = $height;
$this->width = $width;
$this->height = $height;
}
public function send_image($file = '', $compress = -1, $convert_file_to = null)
{
if (!$this->image_validated) return false;
if (!$this->image_validated) {
return false;
}
$type = $this->type;
if (!empty($convert_file_to) && in_array($convert_file_to, $this->allowed_extensions)) {
$type = $convert_file_to;
}
switch ($type) {
case 'jpeg':
case 'jpg':
if (!$file) header("Content-type: image/jpeg");
break;
case 'png':
if (!$file) header("Content-type: image/png");
break;
case 'gif':
if (!$file) header("Content-type: image/gif");
break;
}
$result = false;
try {
$result = $this->image->writeImage($file);
} catch (ImagickException $e) {
if ($this->debug) error_log($e->getMessage());
switch ($type) {
case 'jpeg':
case 'jpg':
if (!$file) {
header("Content-type: image/jpeg");
}
break;
case 'png':
if (!$file) {
header("Content-type: image/png");
}
break;
case 'gif':
if (!$file) {
header("Content-type: image/gif");
}
break;
}
$result = false;
try {
$result = $this->image->writeImage($file);
} catch (ImagickException $e) {
if ($this->debug) {
error_log($e->getMessage());
}
}
if (!$file) {
echo $this->image;
$this->image->clear();
if (!$file) {
echo $this->image;
$this->image->clear();
$this->image->destroy();
} else {
$this->image->clear();
} else {
$this->image->clear();
$this->image->destroy();
return $result;
}
}
return $result;
}
}
}
/**
@ -273,8 +284,8 @@ class ImagickWrapper extends ImageWrapper
class GDWrapper extends ImageWrapper
{
public $bg;
function __construct($path) {
public function __construct($path)
{
parent::__construct($path);
}
@ -284,21 +295,21 @@ class GDWrapper extends ImageWrapper
$this->fill_image_info();
switch ($this->type) {
case 0:
$handler = false;
break;
case 1 :
case 0:
$handler = false;
break;
case 1:
$handler = @imagecreatefromgif($this->path);
$this->type = 'gif';
break;
case 2 :
case 2:
$handler = @imagecreatefromjpeg($this->path);
$this->type = 'jpg';
break;
case 3 :
$handler = @imagecreatefrompng($this->path);
$this->type = 'png';
break;
case 3:
$handler = @imagecreatefrompng($this->path);
$this->type = 'png';
break;
}
if ($handler) {
$this->image_validated = true;
@ -312,29 +323,31 @@ class GDWrapper extends ImageWrapper
{
$return_array = array('width'=>0, 'height'=>0);
if ($this->image_validated) {
$return_array = array('width'=>$this->width, 'height'=>$this->height);
$return_array = array('width'=>$this->width, 'height'=>$this->height);
}
return $return_array;
}
}
public function fill_image_info()
{
if (file_exists($this->path)) {
$image_info = getimagesize($this->path);
$this->width = $image_info[0];
$this->height = $image_info[1];
$this->type = $image_info[2];
} else {
$this->width = 0;
$this->height = 0;
$this->type = 0;
}
if (file_exists($this->path)) {
$image_info = getimagesize($this->path);
$this->width = $image_info[0];
$this->height = $image_info[1];
$this->type = $image_info[2];
} else {
$this->width = 0;
$this->height = 0;
$this->type = 0;
}
}
public function resize($thumbw, $thumbh, $border, $specific_size = false)
{
if (!$this->image_validated) return false;
if ($border == 1) {
if (!$this->image_validated) {
return false;
}
if ($border == 1) {
if ($specific_size) {
$width = $thumbw;
$height = $thumbh;
@ -343,17 +356,17 @@ class GDWrapper extends ImageWrapper
$width = (int) ($this->width * $scale);
$height = (int) ($this->height * $scale);
}
$deltaw = (int) (($thumbw - $width) / 2);
$deltah = (int) (($thumbh - $height) / 2);
$dst_img = @ImageCreateTrueColor($thumbw, $thumbh);
@imagealphablending($dst_img, false);
@imagesavealpha($dst_img, true);
if (!empty($this->color)) {
@imagefill($dst_img, 0, 0, $this->color);
}
$this->width = $thumbw;
$this->height = $thumbh;
} elseif ($border == 0) {
$deltaw = (int) (($thumbw - $width) / 2);
$deltah = (int) (($thumbh - $height) / 2);
$dst_img = @ImageCreateTrueColor($thumbw, $thumbh);
@imagealphablending($dst_img, false);
@imagesavealpha($dst_img, true);
if (!empty($this->color)) {
@imagefill($dst_img, 0, 0, $this->color);
}
$this->width = $thumbw;
$this->height = $thumbh;
} elseif ($border == 0) {
if ($specific_size) {
$width = $thumbw;
$height = $thumbh;
@ -362,19 +375,30 @@ class GDWrapper extends ImageWrapper
$width = (int) ($this->width * $scale);
$height = (int) ($this->height * $scale);
}
$deltaw = 0;
$deltah = 0;
$dst_img = @ImageCreateTrueColor($width, $height);
@imagealphablending($dst_img, false);
@imagesavealpha($dst_img, true);
$this->width = $width;
$this->height = $height;
}
$src_img = $this->bg;
@ImageCopyResampled($dst_img, $src_img, $deltaw, $deltah, 0, 0, $width, $height, ImageSX($src_img), ImageSY($src_img));
$this->bg = $dst_img;
@imagedestroy($src_img);
}
$deltaw = 0;
$deltah = 0;
$dst_img = @ImageCreateTrueColor($width, $height);
@imagealphablending($dst_img, false);
@imagesavealpha($dst_img, true);
$this->width = $width;
$this->height = $height;
}
$src_img = $this->bg;
@ImageCopyResampled(
$dst_img,
$src_img,
$deltaw,
$deltah,
0,
0,
$width,
$height,
ImageSX($src_img),
ImageSY($src_img)
);
$this->bg = $dst_img;
@imagedestroy($src_img);
}
/**
* @author José Loguercio <jose.loguercio@beeznest.com>
@ -385,30 +409,33 @@ class GDWrapper extends ImageWrapper
* @param int $src_width the source width of the original image
* @param int $src_height the source height of the original image
*/
public function crop($x, $y, $width, $height, $src_width, $src_height) {
if (!$this->image_validated) return false;
public function crop($x, $y, $width, $height, $src_width, $src_height)
{
if (!$this->image_validated) {
return false;
}
$this->width = $width;
$this->height = $height;
$this->height = $height;
$src = null;
$dest = @imagecreatetruecolor($width, $height);
$type = $this->type;
switch ($type) {
case 'jpeg' :
case 'jpg' :
case 'jpeg':
case 'jpg':
$src = @imagecreatefromjpeg($this->path);
@imagecopy($dest, $src, 0, 0, $x, $y, $src_width, $src_height);
@imagejpeg($dest, $this->path);
break;
case 'png' :
case 'png':
$src = @imagecreatefrompng($this->path);
@imagecopy($dest, $src, 0, 0, $x, $y, $src_width, $src_height);
@imagepng($dest, $this->path);
break;
case 'gif' :
$src = @imagecreatefromgif($this->path);
case 'gif':
$src = @imagecreatefromgif($this->path);
@imagecopy($dest, $src, 0, 0, $x, $y, $src_width, $src_height);
@imagegif($dest, $this->path);
break;
break;
default:
return 0;
}
@ -416,48 +443,63 @@ class GDWrapper extends ImageWrapper
@imagedestroy($src);
}
public function send_image($file = '', $compress = -1, $convert_file_to = null)
public function send_image($file = '', $compress = -1, $convert_file_to = null)
{
if (!$this->image_validated) return false;
if (!$this->image_validated) {
return false;
}
$compress = (int) $compress;
$type = $this->type;
if (!empty($convert_file_to) && in_array($convert_file_to, $this->allowed_extensions)) {
$type = $convert_file_to;
}
switch ($type) {
case 'jpeg':
case 'jpg':
if (!$file) header("Content-type: image/jpeg");
if ($compress == -1) $compress = 100;
return imagejpeg($this->bg, $file, $compress);
break;
case 'png':
if (!$file) header("Content-type: image/png");
if ($compress != -1) {
@imagetruecolortopalette($this->bg, true, $compress);
}
return imagepng($this->bg, $file, $compress);
break;
case 'gif':
if (!$file) header("Content-type: image/gif");
if ($compress != -1) {
@imagetruecolortopalette($this->bg, true, $compress);
}
return imagegif($this->bg, $file, $compress);
break;
default:
return 0;
}
// TODO: Occupied memory is not released, because the following fragment of code is actually dead.
@imagedestroy($this->bg);
}
switch ($type) {
case 'jpeg':
case 'jpg':
if (!$file) {
header("Content-type: image/jpeg");
}
if ($compress == -1) {
$compress = 100;
}
return imagejpeg($this->bg, $file, $compress);
break;
case 'png':
if (!$file) {
header("Content-type: image/png");
}
if ($compress != -1) {
@imagetruecolortopalette($this->bg, true, $compress);
}
return imagepng($this->bg, $file, $compress);
break;
case 'gif':
if (!$file) {
header("Content-type: image/gif");
}
if ($compress != -1) {
@imagetruecolortopalette($this->bg, true, $compress);
}
return imagegif($this->bg, $file, $compress);
break;
default:
return 0;
}
// TODO: Occupied memory is not released, because the following fragment of code is actually dead.
@imagedestroy($this->bg);
}
/**
* Convert image to black & white
*/
function convert2bw()
{
if (!$this->image_validated) return false;
if (!$this->image_validated) {
return false;
}
$dest_img = imagecreatetruecolor(imagesx($this->bg), imagesy($this->bg));
/* copy ignore the transparent color

@ -7,9 +7,9 @@ use Chamilo\CourseBundle\Entity\CLp;
* Class LearnpathList
* This class is only a learning path list container with several practical methods for sorting the list and
* provide links to specific paths
* @uses Database.lib.php to use the database
* @uses learnpath.class.php to generate learnpath objects to get in the list
* @author Yannick Warnier <ywarnier@beeznest.org>
* @uses Database.lib.php to use the database
* @uses learnpath.class.php to generate learnpath objects to get in the list
* @author Yannick Warnier <ywarnier@beeznest.org>
*
*/
class LearnpathList
@ -28,11 +28,11 @@ class LearnpathList
* This method is the constructor for the learnpathList. It gets a list of available learning paths from
* the database and creates the learnpath objects. This list depends on the user that is connected
* (only displays) items if he has enough permissions to view them.
* @param integer $user_id
* @param string $course_code Optional course code (otherwise we use api_get_course_id())
* @param int $session_id Optional session id (otherwise we use api_get_session_id())
* @param string $order_by
* @param bool $check_publication_dates
* @param integer $user_id
* @param string $course_code Optional course code (otherwise we use api_get_course_id())
* @param int $session_id Optional session id (otherwise we use api_get_session_id())
* @param string $order_by
* @param bool $check_publication_dates
* @param int $categoryId
* @param bool $ignoreCategoryFilter
*/
@ -196,7 +196,7 @@ class LearnpathList
/**
* Gets references to learnpaths for all learnpaths IDs kept in the local list.
* This applies a transformation internally on list and ref_list and returns a copy of the refs list
* @return array List of references to learnpath objects
* @return array List of references to learnpath objects
*/
public function get_refs()
{
@ -209,7 +209,7 @@ class LearnpathList
/**
* Gets a table of the different learnpaths we have at the moment
* @return array Learnpath info as [lp_id] => ([lp_type]=> ..., [lp_name]=>...,[lp_desc]=>...,[lp_path]=>...)
* @return array Learnpath info as [lp_id] => ([lp_type]=> ..., [lp_name]=>...,[lp_desc]=>...,[lp_path]=>...)
*/
public function get_flat_list()
{

@ -2,8 +2,8 @@
/* For licensing terms, see /license.txt */
/**
* @package chamilo.admin
*/
* @package chamilo.admin
*/
// resetting the course id
$cidReset = true;
@ -36,9 +36,8 @@ $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
// setting the name of the tool
$tool_name = get_lang('SubscribeUsersToSession');
$add_type = 'unique';
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
$add_type = Security::remove_XSS($_REQUEST['add_type']);
$add_type = Security::remove_XSS($_REQUEST['add_type']);
}
$page = isset($_GET['page']) ? Security::remove_XSS($_GET['page']) : null;
@ -195,7 +194,7 @@ function search_users($needle, $type)
user.status<>6 '.$cond_user_id.
$order_clause;
break;
case 'any_session' :
case 'any_session':
$sql = 'SELECT DISTINCT user.id, username, lastname, firstname, official_code
FROM '.$tbl_user.' user
LEFT OUTER JOIN '.$tbl_session_rel_user.' s
@ -251,16 +250,13 @@ function search_users($needle, $type)
}
$xajax->processRequests();
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
$htmlHeadXtra[] = '
<script type="text/javascript">
function add_user_to_session (code, content) {
document.getElementById("user_to_add").value = "";
document.getElementById("ajax_list_users_single").innerHTML = "";
destination = document.getElementById("destination_users");
for (i=0;i<destination.length;i++) {
if(destination.options[i].text == content) {
return false;
@ -400,7 +396,7 @@ if ($ajax_search) {
unset($users); //clean to free memory
} else {
//Filter by Extra Fields
// Filter by Extra Fields
$extra_field_result = [];
$use_extra_fields = false;
if (is_array($extra_field_list)) {
@ -431,10 +427,13 @@ if ($ajax_search) {
if ($use_extra_fields) {
$final_result = array();
if (count($extra_field_result) > 1) {
for ($i = 0; $i < count($extra_field_result) - 1; $i++) {
if (count($extra_field_result) > 1) {
for ($i = 0; $i < count($extra_field_result) - 1; $i++) {
if (is_array($extra_field_result[$i + 1])) {
$final_result = array_intersect($extra_field_result[$i], $extra_field_result[$i + 1]);
$final_result = array_intersect(
$extra_field_result[$i],
$extra_field_result[$i + 1]
);
}
}
} else {
@ -512,7 +511,7 @@ if ($ajax_search) {
}
unset($users); //clean to free memory
//filling the correct users in list
// filling the correct users in list
$sql = "SELECT u.id, lastname, firstname, username, session_id, official_code
FROM $tbl_user u
LEFT JOIN $tbl_session_rel_user
@ -574,28 +573,28 @@ $newLinks .= Display::url(
);
?>
<div class="actions">
<?php
<?php
echo $link_add_type_unique;
echo $link_add_type_multiple;
echo $link_add_group;
echo $newLinks;
?>
?>
</div>
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?page=<?php echo $page; ?>&id_session=<?php echo $id_session; ?><?php if (!empty($addProcess)) echo '&add=true'; ?>" <?php if ($ajax_search) { echo ' onsubmit="valide();"'; }?>>
<?php echo '<legend>'.$tool_name.' ('.$session_info['name'].') </legend>'; ?>
<?php
if ($add_type == 'multiple') {
if (is_array($extra_field_list)) {
if (is_array($new_field_list) && count($new_field_list) > 0) {
echo '<h3>'.get_lang('FilterUsers').'</h3>';
foreach ($new_field_list as $new_field) {
echo $new_field['name'];
$varname = 'field_'.$new_field['variable'];
if (is_array($extra_field_list)) {
if (is_array($new_field_list) && count($new_field_list) > 0) {
echo '<h3>'.get_lang('FilterUsers').'</h3>';
foreach ($new_field_list as $new_field) {
echo $new_field['name'];
$varname = 'field_'.$new_field['variable'];
$fieldtype = $new_field['type'];
echo '&nbsp;<select name="'.$varname.'">';
echo '<option value="0">--'.get_lang('Select').'--</option>';
foreach ($new_field['data'] as $option) {
$checked = '';
echo '&nbsp;<select name="'.$varname.'">';
echo '<option value="0">--'.get_lang('Select').'--</option>';
foreach ($new_field['data'] as $option) {
$checked = '';
if ($fieldtype == ExtraField::FIELD_TYPE_TAG) {
if (isset($_POST[$varname])) {
if ($_POST[$varname] == $option['tag']) {
@ -616,11 +615,11 @@ if ($add_type == 'multiple') {
$extraHidden = $fieldtype == ExtraField::FIELD_TYPE_TAG ? '<input type="hidden" name="field_id" value="'.$option['field_id'].'" />' : '';
echo $extraHidden;
echo '&nbsp;&nbsp;';
}
echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
echo '<br /><br />';
}
}
}
echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
echo '<br /><br />';
}
}
}
?>
<input type="hidden" name="form_sent" value="1" />
@ -628,7 +627,7 @@ if ($add_type == 'multiple') {
<?php
if (!empty($errorMsg)) {
echo Display::return_message($errorMsg); //main API
echo Display::return_message($errorMsg); //main API
}
?>
<div id="multiple-add-session" class="row">
@ -675,7 +674,6 @@ if (!empty($errorMsg)) {
<div class="col-md-4">
<?php if ($add_type == 'multiple') { ?>
<?php echo get_lang('FirstLetterUser'); ?> :
<select id="first_letter_user" name="firstLetterUser" onchange = "change_select(this.value);" >
<option value = "%">--</option>
<?php
@ -694,7 +692,6 @@ if (!empty($errorMsg)) {
<em class="fa fa-chevron-left"></em>
</button>
</div>
<?php
} else {
?>

Loading…
Cancel
Save