Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 11, 2019
1 parent d3479be commit fac329e
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 150 deletions.
2 changes: 1 addition & 1 deletion ChangeLog
Expand Up @@ -15,7 +15,7 @@ WARNING:
Following changes may create regressions for some external modules, but were necessary to make Dolibarr better:
* Method GetUrlTrackingStatus were renamed into getUrlTrackingStatus for consistency with naming rules.
* API getListOfCivility has been renamed into getListOfCivilities for consistency with naming rules.

* Deprecated function img_phone as been removed. You can use img_picto(..., 'call|call_out') instead.;


***** ChangeLog for 9.0.1 compared to 9.0.0 *****
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/lib/accounting.lib.php
Expand Up @@ -145,7 +145,7 @@ function length_accounta($accounta)
* @param string $period Period of report
* @param string $periodlink Link to switch period
* @param string $description Description
* @param timestamp|integer $builddate Date generation
* @param integer $builddate Date of generation
* @param string $exportlink Link for export or ''
* @param array $moreparam Array with list of params to add into form
* @param string $calcmode Calculation mode
Expand Down
10 changes: 5 additions & 5 deletions htdocs/core/lib/admin.lib.php
Expand Up @@ -31,7 +31,7 @@
*
* @param array $versionarray Tableau de version (vermajeur,vermineur,autre)
* @return string Chaine version
* @see versioncompare
* @see versioncompare()
*/
function versiontostring($versionarray)
{
Expand All @@ -55,7 +55,7 @@ function versiontostring($versionarray)
* @return int -4,-3,-2,-1 if versionarray1<versionarray2 (value depends on level of difference)
* 0 if same
* 1,2,3,4 if versionarray1>versionarray2 (value depends on level of difference)
* @see versiontostring
* @see versiontostring()
*/
function versioncompare($versionarray1, $versionarray2)
{
Expand Down Expand Up @@ -432,7 +432,7 @@ function run_sql($sqlfile, $silent = 1, $entity = '', $usesavepoint = 1, $handle
* @param int $entity Multi company id, -1 for all entities
* @return int <0 if KO, >0 if OK
*
* @see dolibarr_get_const, dolibarr_set_const, dol_set_user_param
* @see dolibarr_get_const(), dolibarr_set_const(), dol_set_user_param()
*/
function dolibarr_del_const($db, $name, $entity = 1)
{
Expand Down Expand Up @@ -472,7 +472,7 @@ function dolibarr_del_const($db, $name, $entity = 1)
* @param int $entity Multi company id
* @return string Valeur de la constante
*
* @see dolibarr_del_const, dolibarr_set_const, dol_set_user_param
* @see dolibarr_del_const(), dolibarr_set_const(), dol_set_user_param()
*/
function dolibarr_get_const($db, $name, $entity = 1)
{
Expand Down Expand Up @@ -507,7 +507,7 @@ function dolibarr_get_const($db, $name, $entity = 1)
* @param int $entity Multi company id (0 means all entities)
* @return int -1 if KO, 1 if OK
*
* @see dolibarr_del_const, dolibarr_get_const, dol_set_user_param
* @see dolibarr_del_const(), dolibarr_get_const(), dol_set_user_param()
*/
function dolibarr_set_const($db, $name, $value, $type = 'chaine', $visible = 0, $note = '', $entity = 1)
{
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/lib/ajax.lib.php
Expand Up @@ -369,7 +369,7 @@ function ajax_dialog($title, $message, $w = 350, $h = 150)
* @param int $forcefocus Force focus on field
* @param string $widthTypeOfAutocomplete 'resolve' or 'off'
* @return string Return html string to convert a select field into a combo, or '' if feature has been disabled for some reason.
* @see selectArrayAjax of html.form.class
* @see selectArrayAjax() of html.form.class
*/
function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete = 0, $forcefocus = 0, $widthTypeOfAutocomplete = 'resolve')
{
Expand Down
14 changes: 7 additions & 7 deletions htdocs/core/lib/date.lib.php
Expand Up @@ -149,7 +149,7 @@ function dol_time_plus_duree($time, $duration_value, $duration_unit)
* @param int $iMinutes Minutes
* @param int $iSeconds Seconds
* @return int Time into seconds
* @see convertSecondToTime
* @see convertSecondToTime()
*/
function convertTime2Seconds($iHours = 0, $iMinutes = 0, $iSeconds = 0)
{
Expand Down Expand Up @@ -177,7 +177,7 @@ function convertTime2Seconds($iHours = 0, $iMinutes = 0, $iSeconds = 0)
* @param int $lengthOfWeek Length of week (default 7)
* @return string Formated text of duration
* Example: 0 return 00:00, 3600 return 1:00, 86400 return 1d, 90000 return 1 Day 01:00
* @see convertTime2Seconds
* @see convertTime2Seconds()
*/
function convertSecondToTime($iSecond, $format = 'all', $lengthOfDay = 86400, $lengthOfWeek = 7)
{
Expand Down Expand Up @@ -325,7 +325,7 @@ function dolSqlDateFilter($datefield, $day_date, $month_date, $year_date)
* @return int Date as a timestamp
* 19700101020000 -> 7200 with gm=1
*
* @see dol_print_date, dol_mktime, dol_getdate
* @see dol_print_date(), dol_mktime(), dol_getdate()
*/
function dol_stringtotime($string, $gm = 1)
{
Expand Down Expand Up @@ -603,7 +603,7 @@ function dol_get_first_day_week($day, $month, $year, $gm = false)
* @param string $countrycode Country code
* @param int $lastday Last day is included, 0: no, 1:yes
* @return int Nombre de jours feries
* @see num_between_day, num_open_day
* @see num_between_day(), num_open_day()
*/
function num_public_holiday($timestampStart, $timestampEnd, $countrycode = 'FR', $lastday = 0)
{
Expand Down Expand Up @@ -809,7 +809,7 @@ function num_public_holiday($timestampStart, $timestampEnd, $countrycode = 'FR',
// Easter sunday

// Monday after easter
$date_eastermonday = mktime(
$date_eastermonday = mktime(
date("H", $date_paques),
date("i", $date_paques),
date("s", $date_paques),
Expand Down Expand Up @@ -895,7 +895,7 @@ function num_public_holiday($timestampStart, $timestampEnd, $countrycode = 'FR',
* @param int $timestampEnd Timestamp end UTC
* @param int $lastday Last day is included, 0: no, 1:yes
* @return int Number of days
* @see also num_public_holiday, num_open_day
* @seealso num_public_holiday(), num_open_day()
*/
function num_between_day($timestampStart, $timestampEnd, $lastday = 0)
{
Expand Down Expand Up @@ -925,7 +925,7 @@ function num_between_day($timestampStart, $timestampEnd, $lastday = 0)
* @param int $halfday Tag to define half day when holiday start and end
* @param string $country_code Country code (company country code if not defined)
* @return int Number of days or hours
* @see also num_between_day, num_public_holiday
* @seealso num_between_day(), num_public_holiday()
*/
function num_open_day($timestampStart, $timestampEnd, $inhour = 0, $lastday = 0, $halfday = 0, $country_code = '')
{
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/lib/doc.lib.php
Expand Up @@ -31,7 +31,7 @@
/**
* Return line description translated in outputlangs and encoded into UTF8
*
* @param Line $line Current line number (0 = first line, 1 = second line, ...)
* @param Object $line Object of line
* @param Translate $outputlangs Object langs for output
* @param int $hideref Hide reference
* @param int $hidedesc Hide description
Expand Down
6 changes: 3 additions & 3 deletions htdocs/core/lib/donation.lib.php
Expand Up @@ -43,7 +43,7 @@ function donation_admin_prepare_head()
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules($conf, $langs, null, $head, $h, 'donation_admin');

$head[$h][0] = DOL_URL_ROOT . '/don/admin/donation_extrafields.php';
$head[$h][1] = $langs->trans("ExtraFields");
$head[$h][2] = 'attributes';
Expand All @@ -57,7 +57,7 @@ function donation_admin_prepare_head()
/**
* Prepare array with list of tabs
*
* @param Donation $object Donation
* @param Don $object Donation
* @return array Array of tabs to show
*/
function donation_prepare_head($object)
Expand Down Expand Up @@ -97,7 +97,7 @@ function donation_prepare_head($object)
if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
$head[$h][2] = 'note';
$h++;

$head[$h][0] = DOL_URL_ROOT . '/don/info.php?id=' . $object->id;
$head[$h][1] = $langs->trans("Info");
$head[$h][2] = 'info';
Expand Down
34 changes: 17 additions & 17 deletions htdocs/core/lib/files.lib.php
Expand Up @@ -55,7 +55,7 @@ function dol_basename($pathfile)
* @param string $relativename For recursive purpose only. Must be "" at first call.
* @param string $donotfollowsymlinks Do not follow symbolic links
* @return array Array of array('name'=>'xxx','fullname'=>'/abc/xxx','date'=>'yyy','size'=>99,'type'=>'dir|file',...)
* @see dol_dir_list_indatabase
* @see dol_dir_list_in_database()
*/
function dol_dir_list($path, $types = "all", $recursive = 0, $filter = "", $excludefilter = null, $sortcriteria = "name", $sortorder = SORT_ASC, $mode = 0, $nohook = 0, $relativename = "", $donotfollowsymlinks = 0)
{
Expand Down Expand Up @@ -225,7 +225,7 @@ function dol_dir_list($path, $types = "all", $recursive = 0, $filter = "", $excl
* @param string $sortorder Sort order (SORT_ASC, SORT_DESC)
* @param int $mode 0=Return array minimum keys loaded (faster), 1=Force all keys like description
* @return array Array of array('name'=>'xxx','fullname'=>'/abc/xxx','type'=>'dir|file',...)
* @see dol_dir_list
* @see dol_dir_list()
*/
function dol_dir_list_in_database($path, $filter = "", $excludefilter = null, $sortcriteria = "name", $sortorder = SORT_ASC, $mode = 0)
{
Expand Down Expand Up @@ -449,7 +449,8 @@ function dol_is_dir($folder)
* @param string $dir Path of Directory
* @return boolean True or false
*/
function dol_is_dir_empty($dir) {
function dol_is_dir_empty($dir)
{
if (!is_readable($dir)) return false;
return (count(scandir($dir)) == 2);
}
Expand Down Expand Up @@ -527,7 +528,7 @@ function dol_dir_is_emtpy($folder)
*
* @param string $file Filename
* @return int <0 if KO, Number of lines in files if OK
* @see dol_nboflines
* @see dol_nboflines()
*/
function dol_count_nb_of_line($file)
{
Expand Down Expand Up @@ -588,7 +589,7 @@ function dol_filemtime($pathoffile)
* @param int $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK). Example: '0666'
* @param int $indexdatabase 1=index new file into database.
* @return int <0 if error, 0 if nothing done (dest file already exists), >0 if OK
* @see dol_copy dolReplaceRegExInFile
* @see dol_copy() dolReplaceRegExInFile()
*/
function dolReplaceInFile($srcfile, $arrayreplacement, $destfile = '', $newmask = 0, $indexdatabase = 0)
{
Expand Down Expand Up @@ -658,7 +659,7 @@ function dolReplaceInFile($srcfile, $arrayreplacement, $destfile = '', $newmask
* @param int $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK). Example: '0666'
* @param int $indexdatabase Index new file into database.
* @return int <0 if error, 0 if nothing done (dest file already exists), >0 if OK
* @see dol_copy dolReplaceInFile
* @see dol_copy() dolReplaceInFile()
*/
function dolReplaceRegExInFile($srcfile, $arrayreplacement, $destfile = '', $newmask = 0, $indexdatabase = 0)
{
Expand All @@ -673,7 +674,7 @@ function dolReplaceRegExInFile($srcfile, $arrayreplacement, $destfile = '', $new
* @param int $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK). Example: '0666'
* @param int $overwriteifexists Overwrite file if exists (1 by default)
* @return int <0 if error, 0 if nothing done (dest file already exists and overwriteifexists=0), >0 if OK
* @see dol_delete_file
* @see dol_delete_file() dolCopyDir()
*/
function dol_copy($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1)
{
Expand Down Expand Up @@ -729,7 +730,7 @@ function dol_copy($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1)
* @param int $overwriteifexists Overwrite file if exists (1 by default)
* @param array $arrayreplacement Array to use to replace filenames with another one during the copy (works only on file names, not on directory names).
* @return int <0 if error, 0 if nothing done (all files already exists and overwriteifexists=0), >0 if OK
* @see dol_copy
* @see dol_copy()
*/
function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement = null)
{
Expand Down Expand Up @@ -821,7 +822,7 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayrep
* @param int $testvirus Do an antivirus test. Move is canceled if a virus is found.
* @param int $indexdatabase Index new file into database.
* @return boolean True if OK, false if KO
* @see dol_move_uploaded_file
* @see dol_move_uploaded_file()
*/
function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1)
{
Expand Down Expand Up @@ -1003,7 +1004,7 @@ function dolCheckVirus($src_file)
* @param int $nohook Disable all hooks
* @param string $varfiles _FILES var name
* @return int >0 if OK, <0 or string if KO
* @see dol_move
* @see dol_move()
*/
function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan = 0, $uploaderrorcode = 0, $nohook = 0, $varfiles = 'addedfile')
{
Expand Down Expand Up @@ -1057,7 +1058,7 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable
$checkvirusarray=dolCheckVirus($src_file);
if (count($checkvirusarray))
{
dol_syslog('Files.lib::dol_move_uploaded_file File "'.$src_file.'" (target name "'.$dest_file.'") KO with antivirus: result='.$result.' errors='.join(',', $checkvirusarray), LOG_WARNING);
dol_syslog('Files.lib::dol_move_uploaded_file File "'.$src_file.'" (target name "'.$dest_file.'") KO with antivirus: errors='.join(',', $checkvirusarray), LOG_WARNING);
return 'ErrorFileIsInfectedWithAVirus: '.join(',', $checkvirusarray);
}
}
Expand Down Expand Up @@ -1146,7 +1147,7 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable
* @param boolean $allowdotdot Allow to delete file path with .. inside. Never use this, it is reserved for migration purpose.
* @param int $indexdatabase Try to remove also index entries.
* @return boolean True if no error (file is deleted or if glob is used and there's nothing to delete), False if error
* @see dol_delete_dir
* @see dol_delete_dir()
*/
function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0, $object = null, $allowdotdot = false, $indexdatabase = 1)
{
Expand Down Expand Up @@ -1256,7 +1257,7 @@ function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0,
* @param string $dir Directory to delete
* @param int $nophperrors Disable all PHP output errors
* @return boolean True if success, false if error
* @see dol_delete_file dol_copy
* @see dol_delete_file() dolCopyDir()
*/
function dol_delete_dir($dir, $nophperrors = 0)
{
Expand Down Expand Up @@ -1331,7 +1332,7 @@ function dol_delete_dir_recursive($dir, $count = 0, $nophperrors = 0, $onlysub =
*
* @param object $object Object to clean
* @return int 0 if error, 1 if OK
* @see dol_convert_file
* @see dol_convert_file()
*/
function dol_delete_preview($object)
{
Expand Down Expand Up @@ -2116,7 +2117,7 @@ function dol_most_recent_file($dir, $regexfilter = '', $excludefilter = array('(
* @param string $refname Ref of object to check permission for external users (autodetect if not provided)
* @param string $mode Check permission for 'read' or 'write'
* @return mixed Array with access information : 'accessallowed' & 'sqlprotectagainstexternals' & 'original_file' (as a full path name)
* @see restrictedArea
* @see restrictedArea()
*/
function dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser = '', $refname = '', $mode = 'read')
{
Expand All @@ -2135,6 +2136,7 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity,
if ($modulepart == 'users') $modulepart='user';

dol_syslog('modulepart='.$modulepart.' original_file='.$original_file.' entity='.$entity);

// We define $accessallowed and $sqlprotectagainstexternals
$accessallowed=0;
$sqlprotectagainstexternals='';
Expand All @@ -2143,8 +2145,6 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity,
// Find the subdirectory name as the reference. For exemple original_file='10/myfile.pdf' -> refname='10'
if (empty($refname)) $refname=basename(dirname($original_file)."/");

$relative_original_file = $original_file;

// Define possible keys to use for permission check
$lire='lire'; $read='read'; $download='download';
if ($mode == 'write')
Expand Down

0 comments on commit fac329e

Please sign in to comment.