Skip to content

Commit 28edb98

Browse files
committed
Minor - format code
1 parent e49f7df commit 28edb98

File tree

1 file changed

+64
-74
lines changed

1 file changed

+64
-74
lines changed

main/inc/lib/document.lib.php

Lines changed: 64 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ public static function check_readonly(
835835
$_course,
836836
$user_id,
837837
$file = null,
838-
$document_id = '',
838+
$document_id = 0,
839839
$to_delete = false,
840840
$sessionId = null,
841841
$documentId = null
@@ -1017,16 +1017,14 @@ public static function delete_document(
10171017
) {
10181018
$TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
10191019

1020+
$groupId = intval($groupId);
10201021
if (empty($groupId)) {
10211022
$groupId = api_get_group_id();
1022-
} else {
1023-
$groupId = intval($groupId);
10241023
}
10251024

1025+
$sessionId = intval($sessionId);
10261026
if (empty($sessionId)) {
10271027
$sessionId = api_get_session_id();
1028-
} else {
1029-
$sessionId = intval($sessionId);
10301028
}
10311029

10321030
$course_id = $_course['real_id'];
@@ -1419,22 +1417,21 @@ public static function unset_document_as_template(
14191417
$course_code = Database::escape_string($course_code);
14201418
$user_id = intval($user_id);
14211419
$document_id = intval($document_id);
1422-
14231420
$sql = 'SELECT id FROM '.$table_template.'
14241421
WHERE
1425-
course_code="' . $course_code.'" AND
1426-
user_id="' . $user_id.'" AND
1427-
ref_doc="' . $document_id.'"';
1422+
course_code="'.$course_code.'" AND
1423+
user_id="'.$user_id.'" AND
1424+
ref_doc="'.$document_id.'"';
14281425
$result = Database::query($sql);
14291426
$template_id = Database::result($result, 0, 0);
14301427

14311428
my_delete(api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/'.$template_id.'.jpg');
14321429

14331430
$sql = 'DELETE FROM '.$table_template.'
14341431
WHERE
1435-
course_code="' . $course_code.'" AND
1436-
user_id="' . $user_id.'" AND
1437-
ref_doc="' . $document_id.'"';
1432+
course_code="'.$course_code.'" AND
1433+
user_id="'.$user_id.'" AND
1434+
ref_doc="'.$document_id.'"';
14381435

14391436
Database::query($sql);
14401437
}
@@ -1459,7 +1456,8 @@ public static function is_visible(
14591456
$propTable = Database::get_course_table(TABLE_ITEM_PROPERTY);
14601457

14611458
$course_id = $course['real_id'];
1462-
//note the extra / at the end of doc_path to match every path in the document table that is part of the document path
1459+
// note the extra / at the end of doc_path to match every path in
1460+
// the document table that is part of the document path
14631461

14641462
$session_id = intval($session_id);
14651463
$condition = "AND d.session_id IN ('$session_id', '0') ";
@@ -1709,7 +1707,7 @@ public static function get_default_certificate_id($course_id, $session_id = 0)
17091707
$sql_session = '';
17101708
}
17111709
$sql = 'SELECT document_id FROM '.$tbl_category.'
1712-
WHERE course_code="' . Database::escape_string($course_id).'" '.$sql_session;
1710+
WHERE course_code="'.Database::escape_string($course_id).'" '.$sql_session;
17131711

17141712
$rs = Database::query($sql);
17151713
$num = Database::num_rows($rs);
@@ -1727,7 +1725,7 @@ public static function get_default_certificate_id($course_id, $session_id = 0)
17271725
* @param string $course_code
17281726
* @param int $sessionId
17291727
* @param bool $is_preview
1730-
* @return string The html content of the certificate
1728+
* @return array
17311729
*/
17321730
public static function replace_user_info_into_html(
17331731
$user_id,
@@ -1926,8 +1924,8 @@ public static function remove_attach_certificate($course_id, $default_certificat
19261924

19271925
$sql = 'UPDATE '.$tbl_category.' SET document_id = null
19281926
WHERE
1929-
course_code = "' . Database::escape_string($course_id).'" AND
1930-
document_id="' . $default_certificate_id.'" '.$sql_session;
1927+
course_code = "'.Database::escape_string($course_id).'" AND
1928+
document_id="'.$default_certificate_id.'" '.$sql_session;
19311929
Database::query($sql);
19321930
}
19331931
}
@@ -1945,7 +1943,6 @@ public static function create_directory_certificate_in_course($courseInfo)
19451943
$course_dir = $courseInfo['path']."/document/";
19461944
$sys_course_path = api_get_path(SYS_COURSE_PATH);
19471945
$base_work_dir = $sys_course_path.$course_dir;
1948-
$base_work_dir_test = $base_work_dir.'certificates';
19491946
$dir_name = '/certificates';
19501947
$post_dir_name = get_lang('CertificatesFiles');
19511948
$visibility_command = 'invisible';
@@ -2088,8 +2085,12 @@ public static function get_resources_from_source_html(
20882085
case 'shtml':
20892086
case 'css':
20902087
$file_content = file_get_contents($abs_path);
2091-
//get an array of attributes from the HTML source
2092-
$attributes = self::parse_HTML_attributes($file_content, $wanted_attributes, $explode_attributes);
2088+
// get an array of attributes from the HTML source
2089+
$attributes = self::parse_HTML_attributes(
2090+
$file_content,
2091+
$wanted_attributes,
2092+
$explode_attributes
2093+
);
20932094
break;
20942095
default:
20952096
break;
@@ -2407,11 +2408,11 @@ public static function get_resources_from_source_html(
24072408
/**
24082409
* Parses the HTML attributes given as string.
24092410
*
2410-
* @param string HTML attribute string
2411-
* @param array List of attributes that we want to get back
2412-
* @param array
2413-
* @return array An associative array of attributes
2414-
* @author Based on a function from the HTML_Common2 PEAR module *
2411+
* @param string HTML attribute string
2412+
* @param array List of attributes that we want to get back
2413+
* @param array
2414+
* @return array An associative array of attributes
2415+
* @author Based on a function from the HTML_Common2 PEAR module *
24152416
*/
24162417
public static function parse_HTML_attributes($attrString, $wanted = [], $explode_variables = [])
24172418
{
@@ -2505,7 +2506,7 @@ public static function parse_HTML_attributes($attrString, $wanted = [], $explode
25052506
* @param string $origin_course_path_from_zip
25062507
* @param string $origin_course_info_path
25072508
*
2508-
* @return string new content html with replaced urls or return false if content is not a string
2509+
* @return string new content html with replaced urls or return false if content is not a string
25092510
*/
25102511
public static function replaceUrlWithNewCourseCode(
25112512
$content_html,
@@ -2577,7 +2578,11 @@ public static function replaceUrlWithNewCourseCode(
25772578
$perm = api_get_permissions_for_new_directories();
25782579
$result = @mkdir($filepath_dir, $perm, true);
25792580
if ($result) {
2580-
$filepath_to_add = str_replace([$dest_course_path, 'document'], '', $filepath_dir);
2581+
$filepath_to_add = str_replace(
2582+
[$dest_course_path, 'document'],
2583+
'',
2584+
$filepath_dir
2585+
);
25812586

25822587
//Add to item properties to the new folder
25832588
$doc_id = add_document(
@@ -2604,7 +2609,11 @@ public static function replaceUrlWithNewCourseCode(
26042609
if (!file_exists($destination_filepath)) {
26052610
$result = @copy($origin_filepath, $destination_filepath);
26062611
if ($result) {
2607-
$filepath_to_add = str_replace([$dest_course_path, 'document'], '', $destination_filepath);
2612+
$filepath_to_add = str_replace(
2613+
[$dest_course_path, 'document'],
2614+
'',
2615+
$destination_filepath
2616+
);
26082617
$size = filesize($destination_filepath);
26092618

26102619
// Add to item properties to the file
@@ -2632,12 +2641,13 @@ public static function replaceUrlWithNewCourseCode(
26322641

26332642
// Replace origin course path by destination course path.
26342643
if (strpos($content_html, $real_orig_url) !== false) {
2635-
$url_course_path = str_replace($orig_course_info_path.'/'.$document_file, '', $real_orig_path);
2636-
2637-
//$destination_url = $url_course_path . $destination_course_directory . '/' . $document_file . $dest_url_query;
2644+
$url_course_path = str_replace(
2645+
$orig_course_info_path.'/'.$document_file,
2646+
'',
2647+
$real_orig_path
2648+
);
26382649
// See BT#7780
26392650
$destination_url = $dest_course_path_rel.$document_file.$dest_url_query;
2640-
26412651
// If the course code doesn't exist in the path? what we do? Nothing! see BT#1985
26422652
if (strpos($real_orig_path, $origin_course_code) === false) {
26432653
$url_course_path = $real_orig_path;
@@ -2935,12 +2945,12 @@ public static function documents_total_space($course_id = null, $group_id = null
29352945
$course_id = api_get_course_int_id();
29362946
}
29372947

2938-
$group_condition = null;
2948+
$group_condition = '';
29392949
if ($group_id) {
29402950
$group_condition = " AND props.to_group_id='".$group_id."' ";
29412951
}
29422952

2943-
$session_condition = null;
2953+
$session_condition = '';
29442954
if ($session_id) {
29452955
$session_condition = " AND props.session_id='".$session_id."' ";
29462956
}
@@ -3042,7 +3052,7 @@ public static function generate_jplayer_jquery($params = [])
30423052
* Shows a play icon next to the document title in the document list
30433053
* @param int
30443054
* @param string
3045-
* @return string html content
3055+
* @return string html content
30463056
*/
30473057
public static function generate_media_preview($i, $type = 'simple')
30483058
{
@@ -3073,7 +3083,6 @@ public static function generate_media_preview($i, $type = 'simple')
30733083
</div>
30743084
</div>
30753085
</div>';
3076-
//<div id="jplayer_inspector_'.$i.'"></div>
30773086
return $html;
30783087
}
30793088

@@ -3083,7 +3092,6 @@ public static function generate_media_preview($i, $type = 'simple')
30833092
*/
30843093
public static function generate_video_preview($document_data = [])
30853094
{
3086-
//<button class="jp-video-play-icon" role="button" tabindex="0">play</button>
30873095
$html = '
30883096
<div id="jp_container_1" class="jp-video center-block" role="application" aria-label="media player">
30893097
<div class="jp-type-single">
@@ -3529,7 +3537,6 @@ private static function parseFile(
35293537
}
35303538

35313539
$return .= '<div class="item_data" style="margin-left:'.($num * 5).'px;margin-right:5px;">';
3532-
35333540
if ($add_move_button) {
35343541
$return .= '<a class="moved" href="#">';
35353542
$return .= Display::return_icon('move_everywhere.png', get_lang('Move'), [], ICON_SIZE_TINY);
@@ -3576,22 +3583,7 @@ private static function parseFolder($folderId, $resource, $lp_id)
35763583
return null;
35773584
}
35783585

3579-
//trad some titles
3580-
/*
3581-
if ($key == 'images') {
3582-
$key = get_lang('Images');
3583-
} elseif ($key == 'gallery') {
3584-
$key = get_lang('Gallery');
3585-
} elseif ($key == 'flash') {
3586-
$key = get_lang('Flash');
3587-
} elseif ($key == 'audio') {
3588-
$key = get_lang('Audio');
3589-
} elseif ($key == 'video') {
3590-
$key = get_lang('Video');
3591-
}*/
3592-
35933586
$onclick = '';
3594-
35953587
// if in LP, hidden folder are displayed in grey
35963588
$folder_class_hidden = '';
35973589
if ($lp_id) {
@@ -4143,12 +4135,7 @@ public static function getFormatTypeListConvertor($mode = 'from', $extension)
41434135
$formatTypesList = [];
41444136
$formatTypes = ['text', 'spreadsheet', 'presentation', 'drawing'];
41454137
foreach ($formatTypes as $formatType) {
4146-
if (
4147-
in_array(
4148-
$extension,
4149-
self::getJodconverterExtensionList($mode, $formatType)
4150-
)
4151-
) {
4138+
if (in_array($extension, self::getJodconverterExtensionList($mode, $formatType))) {
41524139
$formatTypesList[] = $formatType;
41534140
}
41544141
}
@@ -5722,12 +5709,12 @@ private static function getButtonDelete(
57225709

57235710
/**
57245711
* Creates the row of edit icons for a file/folder
5725-
*
5726-
* @param string $curdirpath current path (cfr open folder)
5727-
* @param string $type (file/folder)
5728-
* @param string $path dbase path of file/folder
5712+
* @param array $document_data
5713+
* @param int $id
5714+
* @param bool $is_template
5715+
* @param int $is_read_only
57295716
* @param int $visibility (1/0)
5730-
* @param int $id dbase id of the document
5717+
*
57315718
* @return string html img tags with hyperlinks
57325719
*/
57335720
public static function build_edit_icons($document_data, $id, $is_template, $is_read_only = 0, $visibility)
@@ -5978,7 +5965,7 @@ public static function get_titles_of_path($path)
59785965
$path_displayed .= $tmp_folders_titles[$tmp_path];
59795966
} else {
59805967
$sql = 'SELECT title FROM '.Database::get_course_table(TABLE_DOCUMENT).'
5981-
WHERE c_id = ' . $course_id.' AND path LIKE BINARY "'.$tmp_path.'"';
5968+
WHERE c_id = '.$course_id.' AND path LIKE BINARY "'.$tmp_path.'"';
59825969
$rs = Database::query($sql);
59835970
$tmp_title = '/'.Database::result($rs, 0, 0);
59845971
$path_displayed .= $tmp_title;
@@ -6028,15 +6015,15 @@ public static function is_shared_folder($curdirpath, $current_session_id)
60286015
/**
60296016
* Checks whether the user is into any user shared folder
60306017
* @param string $path
6031-
* @param int $current_session_id
6018+
* @param int $sessionId
60326019
* @return bool Return true when user is in any user shared folder
60336020
*/
6034-
public static function is_any_user_shared_folder($path, $current_session_id)
6021+
public static function is_any_user_shared_folder($path, $sessionId)
60356022
{
60366023
$clean_path = Security::remove_XSS($path);
60376024
if (strpos($clean_path, 'shared_folder/sf_user_')) {
60386025
return true;
6039-
} elseif (strpos($clean_path, 'shared_folder_session_'.$current_session_id.'/sf_user_')) {
6026+
} elseif (strpos($clean_path, 'shared_folder_session_'.$sessionId.'/sf_user_')) {
60406027
return true;
60416028
} else {
60426029
return false;
@@ -6121,16 +6108,16 @@ public static function createUserSharedFolder($userId, array $courseInfo, $sessi
61216108
* Checks whether the user is into his shared folder or into a subfolder
61226109
* @param int $user_id
61236110
* @param string $path
6124-
* @param int $current_session_id
6111+
* @param int $sessionId
61256112
* @return bool Return true when user is in his user shared folder or into a subfolder
61266113
*/
6127-
public static function is_my_shared_folder($user_id, $path, $current_session_id)
6114+
public static function is_my_shared_folder($user_id, $path, $sessionId)
61286115
{
61296116
$clean_path = Security::remove_XSS($path).'/';
61306117
//for security does not remove the last slash
61316118
$main_user_shared_folder = '/shared_folder\/sf_user_'.$user_id.'\//';
61326119
//for security does not remove the last slash
6133-
$main_user_shared_folder_session = '/shared_folder_session_'.$current_session_id.'\/sf_user_'.$user_id.'\//';
6120+
$main_user_shared_folder_session = '/shared_folder_session_'.$sessionId.'\/sf_user_'.$user_id.'\//';
61346121

61356122
if (preg_match($main_user_shared_folder, $clean_path)) {
61366123
return true;
@@ -6172,15 +6159,16 @@ public static function isBrowserViewable($file_extension)
61726159

61736160
/*
61746161
//TODO: make a admin switch to strict mode
6175-
1. global default $allowed_extensions only: 'htm', 'html', 'xhtml', 'gif', 'jpg', 'jpeg', 'png', 'bmp', 'txt', 'log'
6162+
1. global default $allowed_extensions
61766163
if (in_array($file_extension, $allowed_extensions)) { // Assignment + a logical check.
61776164
return true;
61786165
}
61796166
2. check native support
61806167
3. check plugins: quicktime, mediaplayer, vlc, acrobat, flash, java
61816168
*/
61826169

6183-
if (!($result = in_array($file_extension, $allowed_extensions))) { // Assignment + a logical check.
6170+
if (!($result = in_array($file_extension, $allowed_extensions))) {
6171+
// Assignment + a logical check.
61846172
return false;
61856173
}
61866174

@@ -6469,7 +6457,9 @@ public static function updateDbInfo($action, $old_path, $new_path = '')
64696457
$new_path = Database::escape_string($new_path);
64706458
$query = "UPDATE $dbTable SET
64716459
path = CONCAT('".$new_path."', SUBSTRING(path, LENGTH('".$old_path."')+1) )
6472-
WHERE c_id = $course_id AND (path LIKE BINARY '".$old_path."' OR path LIKE BINARY '".$old_path."/%')";
6460+
WHERE
6461+
c_id = $course_id AND
6462+
(path LIKE BINARY '".$old_path."' OR path LIKE BINARY '".$old_path."/%')";
64736463
Database::query($query);
64746464
break;
64756465
}

0 commit comments

Comments
 (0)