-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4888: Undefined Index warnings during IMS CC import #8
base: master
Are you sure you want to change the base?
Changes from all commits
eb0e501
2bb149b
dabd698
64a82d8
bde9900
7dc9105
7076b3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
define('TR_INCLUDE_PATH', '../include/'); | ||
require(TR_INCLUDE_PATH.'vitals.inc.php'); | ||
session_write_close(); | ||
if ($_GET['tile']) { | ||
if (isset($_GET['tile']) && $_GET['tile']) { | ||
$lang_variable = 'tile_progress'; | ||
} else { | ||
$lang_variable = 'upload_progress'; | ||
|
@@ -26,19 +26,19 @@ | |
<html lang="<?php echo $myLang->getCode(); ?>"> | ||
<head> | ||
<title><?php echo _AT($lang_variable); ?></title> | ||
<?php if ($_GET['frame']) { ?> | ||
<?php if (array_key_exists('frame', $_GET)) { ?> | ||
<META HTTP-EQUIV="refresh" content="3;URL=prog.php?frame=1"> | ||
<?php } ?> | ||
<link rel="stylesheet" href="<?php echo $_base_path; ?>themes/<?php echo $_SESSION['prefs']['PREF_THEME']; ?>/styles.css" type="text/css" /> | ||
<meta http-equiv="Content-Type" content="text/html; <?php echo $myLang->getCharacterSet(); ?>" /> | ||
</head> | ||
<body <?php | ||
if ($_SESSION['done']) { | ||
if (array_key_exists('done', $_SESSION)) { | ||
echo 'onload="parent.window.close();"'; | ||
} | ||
?>> | ||
<?php | ||
if (!$_GET['frame']) { ?> | ||
if (!array_key_exists('frame', $_GET)) { ?> | ||
<a href="javascript:window.close();"><?php echo _AT('close'); ?></a> | ||
<h3><?php echo _AT($lang_variable); ?></h3> | ||
<p><small><?php echo _AT('window_auto_close'); ?></small></p> | ||
|
@@ -51,30 +51,32 @@ | |
</iframe> | ||
<?php } else { | ||
$tmp_dir = ini_get('upload_tmp_dir') . DIRECTORY_SEPARATOR; | ||
if (!$_GET['t']) { | ||
$newest_file_name = ''; | ||
$newest_file_time = 0; | ||
// get the name of the temp file. | ||
if ($dir = @opendir($tmp_dir)) { | ||
while (($file = readdir($dir)) !== false) { | ||
if ((strlen($file) == 9) && (substr($file, 0, 3) == 'php')) { | ||
$filedata = stat($tmp_dir . $file); | ||
if ($filedata['mtime'] > $newest_file_time) { | ||
$newest_file_time = $filedata['mtime']; | ||
$newest_file_name = $file; | ||
$size = $filedata['size'] / 1024; | ||
if (isset($_GET['t'])) { | ||
if (!$_GET['t']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 2 lines above are the translation of the original code of "if (!$_GET['t'])". The translation seems missing the condition of (!isset($_GET['t']))? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where the relaxed style of PHP can cause logical failures. As far as I can tell, the intent of the code "if (!$_GET['t'])" is to be TRUE when there is an empty 't' key in $_GET. However, the "!$_GET['t']" logical condition evaluates to TRUE both for "/home/prog.php" and "/home/prog.php?t". Therefore this code branch was being executed unexpectedly when 't' wasn't in $_GET[]. I'm not even sure this code should be in AContent at all - it seems to be a left-over of a copy-paste from ATutor's tools/prog.php to support tile progress. The replacement uses an isset() wrapper around the original code to ensure 't' is set and then checks (!$_GET['t']) it doesn't provide a value (which would be handled in the associated else {} clause) and indents the contained code to help the programmers eye follow it. |
||
$newest_file_name = ''; | ||
$newest_file_time = 0; | ||
// get the name of the temp file. | ||
if ($dir = @opendir($tmp_dir)) { | ||
while (($file = readdir($dir)) !== false) { | ||
if ((strlen($file) == 9) && (substr($file, 0, 3) == 'php')) { | ||
$filedata = stat($tmp_dir . $file); | ||
if ($filedata['mtime'] > $newest_file_time) { | ||
$newest_file_time = $filedata['mtime']; | ||
$newest_file_name = $file; | ||
$size = $filedata['size'] / 1024; | ||
} | ||
} | ||
} | ||
closedir($dir); | ||
} | ||
closedir($dir); | ||
} else { | ||
$filedata = stat($tmp_dir . $_GET['t']); | ||
$size = $filedata['size'] / TR_KBYTE_SIZE; | ||
} | ||
} else { | ||
$filedata = stat($tmp_dir . $_GET['t']); | ||
$size = $filedata['size'] / TR_KBYTE_SIZE; | ||
} | ||
// not sure where these are displayed in the progress popup | ||
// displayed in the small iframe alongside the progress animated image | ||
echo '<small>'; | ||
if ($size == '') { | ||
if (!isset($size) || isset($size) && $size == '') { | ||
echo '<em>'._AT('unknown').' </em> '._AT('kb'); | ||
} else { | ||
echo number_format($size, 2).' '._AT('kb'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 18 uses "isset($_GET['tile']) && $_GET['tile']" to check the presence of the $_GET value while this line uses another approach. Should we make it consistent by using one way through? The same comment applies to line 36, 41.
BTW, I personally likes the line 18 way better. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is that isset() will return false for array keys that have their value set to NULL whereas array_key_exists() only checks that the key exists.
That said, I'm struggling to recall the reason I used these styles of code. I think it was because I believed or saw that some of the GET variables may be NULL e.g. "/home/prog.php" rather than "/home/prog.php?done"