Minor - Format code

pull/2487/head
jmontoyaa 10 years ago
parent 76478b8827
commit 502bf8ffdb
  1. 52
      main/inc/lib/security.lib.php
  2. 38
      main/inc/lib/sub_language.class.php
  3. 46
      main/inc/lib/system_announcements.lib.php

@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Component\HTMLPurifier\Filter\AllowIframes;
/**
* This is the security library for Chamilo.
*
@ -23,8 +25,6 @@
* @author Yannick Warnier <ywarnier@beeznest.org>
*/
use Chamilo\CoreBundle\Component\HTMLPurifier\Filter\AllowIframes;
/**
* Security class
*
@ -186,7 +186,7 @@ class Security
*/
public static function get_HTML_token()
{
$token = md5(uniqid(rand(), TRUE));
$token = md5(uniqid(rand(), true));
$string = '<input type="hidden" name="sec_token" value="'.$token.'" />';
$_SESSION['sec_token'] = $token;
@ -235,51 +235,6 @@ class Security
$_SESSION['sec_ua'] = $_SERVER['HTTP_USER_AGENT'].$_SESSION['sec_ua_seed'];
}
/**
* This function filters a variable to the type given, with the options given
* @param mixed The variable to be filtered
* @param string The type of variable we expect (bool,int,float,string)
* @param array Additional options
* @return bool True if variable was filtered and added to the current object, false otherwise
*/
public static function filter($var, $type = 'string', $options = array())
{
// This function has not been finished! Do not use!
$result = false;
// Get variable name and value.
$args = func_get_args();
$names = array_keys($args);
$name = $names[0];
$value = $args[$name];
switch ($type) {
case 'bool':
$result = (bool) $var;
break;
case 'int':
$result = (int) $var;
break;
case 'float':
$result = (float) $var;
break;
case 'string/html':
$result = self::remove_XSS($var);
break;
case 'string/db':
$result = Database::escape_string($var);
break;
case 'array':
// An array variable shouldn't be given to the filter.
return false;
default:
return false;
}
if (!empty($option['save'])) {
self::$clean[$name] = $result;
}
return $result;
}
/**
* This function returns a variable from the clean array. If the variable doesn't exist,
* it returns null
@ -434,7 +389,6 @@ class Security
return $text;
}
/**
* This method provides specific protection (against XSS and other kinds of attacks) for static images (icons) used by the system.
* Image paths are supposed to be given by programmers - people who know what they do, anyway, this method encourages

@ -17,7 +17,8 @@ class SubLanguageManager
/**
* Get all the languages
* @param bool $onlyActive Whether to return only active languages (default false)
* @return Array All information about sub-language
*
* @return array All information about sub-language
*/
public static function getAllLanguages($onlyActive = false)
{
@ -38,10 +39,10 @@ class SubLanguageManager
/**
* Get all files of lang folder (forum.inc.php,gradebook.inc.php,notebook.inc.php)
* @param String The lang path folder (/var/www/my_lms/main/lang/spanish)
* @param string The lang path folder (/var/www/my_lms/main/lang/spanish)
* @param bool true if we only want the "subname" trad4all instead of trad4all.inc.php
*
* @return Array All file of lang folder
* @return array All file of lang folder
*/
public static function get_lang_folder_files_list($path, $only_main_name = false)
{
@ -69,7 +70,7 @@ class SubLanguageManager
* Get all information of sub-language
* @param Integer The parent id(Language father id)
* @param Integer The sub language id
* @return Array All information about sub-language
* @return array All information about sub-language
*/
public static function get_all_information_of_sub_language($parent_id, $sub_language_id)
{
@ -90,7 +91,7 @@ class SubLanguageManager
/**
* Get all information of language
* @param Integer The parent id(Language father id)
* @return Array All information about language
* @return array All information about language
*/
public static function get_all_information_of_language($parent_id)
{
@ -107,9 +108,9 @@ class SubLanguageManager
/**
* Get all information of chamilo file
* @param String The chamilo path file (/var/www/chamilo/main/lang/spanish/gradebook.inc.php)
* @param string The chamilo path file (/var/www/chamilo/main/lang/spanish/gradebook.inc.php)
* @patam Bool Whether we want to remove the '$' prefix in the results or not
* @return Array Contains all information of chamilo file
* @return array Contains all information of chamilo file
*/
public static function get_all_language_variable_in_file($system_path_file, $get_as_string_index = false)
{
@ -136,7 +137,8 @@ class SubLanguageManager
/**
* Add file in sub-language directory and add header(tag php)
* @param String The chamilo path file (/var/www/chamilo/main/lang/spanish/gradebook.inc.php)
* @param string The chamilo path file (/var/www/chamilo/main/lang/spanish/gradebook.inc.php)
*
* @return bool
*/
public static function add_file_in_language_directory($system_path_file)
@ -148,9 +150,9 @@ class SubLanguageManager
/**
* Write in file of sub-language
* @param String The path file (/var/www/chamilo/main/lang/spanish/gradebook.inc.php)
* @param String The new sub-language
* @param String The language variable
* @param string The path file (/var/www/chamilo/main/lang/spanish/gradebook.inc.php)
* @param string The new sub-language
* @param string The language variable
* @return Boolean True on success, False on error
*/
public static function write_data_in_file($path_file, $new_term, $new_variable)
@ -225,7 +227,7 @@ class SubLanguageManager
/**
* Remove directory for sub-language
* @param String The sub-language path directory ( e.g. 'spanish_corporate'' )
* @param string The sub-language path directory ( e.g. 'spanish_corporate'' )
* @return boolean True on success, false on failure
*/
public static function remove_language_directory($sub_language_dir)
@ -275,8 +277,8 @@ class SubLanguageManager
/**
* Get name of language by id
* @param Integer The language id
* @return String The original name of language
* @param int The language id
* @return string The original name of language
*/
public static function get_name_of_language_by_id($language_id)
{
@ -332,7 +334,7 @@ class SubLanguageManager
/**
* Verified if language is father of an sub-language
* @param Integer The language id
* @param int The language id
* @return Boolean
*/
public static function check_if_language_is_father($language_id)
@ -351,7 +353,7 @@ class SubLanguageManager
/**
* Make unavailable the language
* @param Integer The language id
* @param int The language id
* @return void()
*/
public static function make_unavailable_language($language_id)
@ -366,7 +368,7 @@ class SubLanguageManager
/**
* Make available the language
* @param Integer The language id
* @param int The language id
* @return void
*/
public static function make_available_language($language_id)
@ -381,7 +383,7 @@ class SubLanguageManager
/**
* Set platform language
* @param Integer The language id
* @param int The language id
* @return bool
*/
public static function set_platform_language($language_id)

@ -6,9 +6,9 @@
*/
class SystemAnnouncementManager
{
CONST VISIBLE_GUEST = 1;
CONST VISIBLE_STUDENT = 2;
CONST VISIBLE_TEACHER = 3;
const VISIBLE_GUEST = 1;
const VISIBLE_STUDENT = 2;
const VISIBLE_TEACHER = 3;
/**
* Displays all announcements
@ -38,13 +38,13 @@ class SystemAnnouncementManager
(('$now' BETWEEN date_start AND date_end) OR date_end='0000-00-00') ";
switch ($visible) {
case self::VISIBLE_GUEST :
case self::VISIBLE_GUEST:
$sql .= " AND visible_guest = 1 ";
break;
case self::VISIBLE_STUDENT :
case self::VISIBLE_STUDENT:
$sql .= " AND visible_student = 1 ";
break;
case self::VISIBLE_TEACHER :
case self::VISIBLE_TEACHER:
$sql .= " AND visible_teacher = 1 ";
break;
}
@ -160,9 +160,6 @@ class SystemAnnouncementManager
$announcements = Database::query($sql);
$content = '';
if (Database::num_rows($announcements) > 0) {
$query_string = ereg_replace('announcement=[1-9]+', '', $_SERVER['QUERY_STRING']);
$query_string = ereg_replace('&$', '', $query_string);
$url = api_get_self();
$content .= '<div class="system_announcements">';
$content .= '<h3>'.get_lang('SystemAnnouncements').'</h3>';
$content .= '<table align="center">';
@ -208,12 +205,12 @@ class SystemAnnouncementManager
public static function display_arrow($user_id)
{
$start = (int)$_GET['start'];
$nb_announcement = SystemAnnouncementManager :: count_nb_announcement($start,$user_id);
$nb_announcement = SystemAnnouncementManager :: count_nb_announcement($start, $user_id);
$next = ((int)$_GET['start']+19);
$prev = ((int)$_GET['start']-19);
$content = '';
if(!isset($_GET['start']) || $_GET['start'] == 0) {
if($nb_announcement > 20) {
if (!isset($_GET['start']) || $_GET['start'] == 0) {
if ($nb_announcement > 20) {
$content .= '<a href="news_list.php?start='.$next.'">'.get_lang('NextBis').' >> </a>';
}
} else {
@ -265,6 +262,7 @@ class SystemAnnouncementManager
while ($rows = Database::fetch_array($announcements)) {
$i++;
}
return $i;
}
@ -378,7 +376,7 @@ class SystemAnnouncementManager
'visible_student' => $visible_student,
'visible_guest' => $visible_guest,
'lang' => $lang,
'access_url_id' => $current_access_url_id,
'access_url_id' => $current_access_url_id
];
$resultId = Database::insert($db_table, $params);
@ -509,10 +507,9 @@ class SystemAnnouncementManager
$em = Database::getManager();
$announcement = $em->find('ChamiloCoreBundle:SysAnnouncement', $id);
if (!$announcement) {
return false;
}
if (!$announcement) {
return false;
}
$a_dateS = explode(' ', $date_start);
$a_arraySD = explode('-', $a_dateS[0]);
@ -548,8 +545,8 @@ class SystemAnnouncementManager
return false;
}
$start = api_get_utc_datetime($date_start);
$end = api_get_utc_datetime($date_end);
$start = api_get_utc_datetime($date_start);
$end = api_get_utc_datetime($date_end);
//Fixing urls that are sent by email
//$content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content);
@ -576,7 +573,7 @@ class SystemAnnouncementManager
$lang
);
}
}
}
$dateStart = new DateTime($start, new DateTimeZone('UTC'));
$dateEnd = new DateTime($end, new DateTimeZone('UTC'));
@ -609,8 +606,7 @@ class SystemAnnouncementManager
$id = intval($id);
$sql = "DELETE FROM ".$db_table." WHERE id =".$id;
$res = Database::query($sql);
if ($res === false) {
if ($res === false) {
return false;
}
return true;
@ -857,11 +853,11 @@ class SystemAnnouncementManager
}
$announcement = Database::select(
"*",
'*',
$announcementTable,
[
"where" => $whereConditions,
"order" => "date_start"
'where' => $whereConditions,
'order' => 'date_start'
], 'first'
);

Loading…
Cancel
Save