Skip to content

Commit

Permalink
Stricter types on some variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoFara committed Dec 26, 2023
1 parent da9baf3 commit c30f391
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 38 deletions.
16 changes: 13 additions & 3 deletions do_feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,29 @@ function dummy_function_1(): array
<tr>
<td class="td1 right">Text:</td>
<td class="td1">
<textarea <?php echo getScriptDirectionTag($row['NfLgID']); ?> name="feed[<?php echo $count; ?>][TxText]" class="notempty checkbytes" cols="60" rows="20"><?php echo tohtml($text['TxText']); ?></textarea> <img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" />
<textarea
<?php echo getScriptDirectionTag((int) $row['NfLgID']); ?>
name="feed[<?php echo $count; ?>][TxText]" class="notempty checkbytes"
cols="60" rows="20"
><?php echo tohtml($text['TxText']); ?></textarea>
<img src="icn/status-busy.png" title="Field must not be empty"
alt="Field must not be empty" />
</td>
</tr>
<tr>
<td class="td1 right">Source URI:</td>
<td class="td1">
<input type="text" class="checkurl" name="feed[<?php echo $count; ?>][TxSourceURI]" value="<?php echo $text['TxSourceURI']; ?>" maxlength="1000" size="60" />
<input type="text" class="checkurl"
name="feed[<?php echo $count; ?>][TxSourceURI]"
value="<?php echo $text['TxSourceURI']; ?>" maxlength="1000"
size="60" />
</td>
</tr>
<tr>
<td class="td1 right">Tags:</td>
<td class="td1">
<ul name="feed[<?php echo $count; ?>][TagList][]" style="width:340px;margin-top:0px;margin-bottom:0px;margin-left:2px;">
<ul name="feed[<?php echo $count; ?>][TagList][]"
style="width:340px;margin-top:0px;margin-bottom:0px;margin-left:2px;">
<li>
<?php echo $nf_tag_name; ?>
</li>
Expand Down
8 changes: 4 additions & 4 deletions edit_tword.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@
$sql = 'select WoText, WoLgID, WoTranslation, WoSentence, WoRomanization, WoStatus from ' . $tbpref . 'words where WoID = ' . $wid;
$res = do_mysqli_query($sql);
$record = mysqli_fetch_assoc($res);
if ($record ) {
$term = $record['WoText'];
$lang = $record['WoLgID'];
if ($record) {
$term = (string) $record['WoText'];
$lang = (int) $record['WoLgID'];
$transl = repl_tab_nl($record['WoTranslation']);
if($transl == '*') {
$transl='';
Expand All @@ -159,7 +159,7 @@
}
mysqli_free_result($res);

$termlc = mb_strtolower($term, 'UTF-8');
$termlc = mb_strtolower($term, 'UTF-8');
$titletext = "Edit Term: " . tohtml($term);
pagestart_nobody($titletext);
$scrdir = getScriptDirectionTag($lang);
Expand Down
8 changes: 4 additions & 4 deletions edit_word.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ function edit_word_do_form($wid, $text_id, $ord, $fromAnn)
if ($record === null) {
my_die("Cannot access Term and Language in edit_word.php");
}
$term = $record['Ti2Text'];
$lang = $record['Ti2LgID'];
$term = (string) $record['Ti2Text'];
$lang = (int) $record['Ti2LgID'];
mysqli_free_result($res);

$termlc = mb_strtolower($term, 'UTF-8');
Expand All @@ -274,8 +274,8 @@ function edit_word_do_form($wid, $text_id, $ord, $fromAnn)
if (!$record) {
my_die("Cannot access Term and Language in edit_word.php");
}
$term = $record['WoText'];
$lang = $record['WoLgID'];
$term = (string) $record['WoText'];
$lang = (int) $record['WoLgID'];
mysqli_free_result($res);
$termlc = mb_strtolower($term, 'UTF-8');
$new = false;
Expand Down
2 changes: 1 addition & 1 deletion edit_words.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@

if (isset($_REQUEST['new']) && isset($_REQUEST['lang'])) {
// NEW
$scrdir = getScriptDirectionTag($_REQUEST['lang']);
$scrdir = getScriptDirectionTag((int) $_REQUEST['lang']);

?>

Expand Down
36 changes: 17 additions & 19 deletions inc/session_utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -3993,7 +3993,7 @@ function get_languages(): array
{
global $tbpref;
$langs = array();
$sql = "SELECT LgID, LgName FROM " . $tbpref . "languages WHERE LgName<>''";
$sql = "SELECT LgID, LgName FROM {$tbpref}languages WHERE LgName<>''";
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$langs[(string)$record['LgName']] = (int)$record['LgID'];
Expand All @@ -4016,40 +4016,38 @@ function getLanguage($lid)
if (!isset($lid) || trim($lid) == '' || !is_numeric($lid)) {
return '';
}
$lg_id = (int) $lid;
$r = get_first_value(
"SELECT LgName AS value
FROM " . $tbpref . "languages
WHERE LgID='" . $lid . "'"
FROM {$tbpref}languages
WHERE LgID = $lg_id"
);
if (isset($r)) {
return (string)$r;
}
return '';
}

// -------------------------------------------------------------

/**
* Return a right-to-left direction indication in HTML if language is right-to-left.
*
* @param int $lid Language ID
*
* @return string ' dir="rtl" '|''
*/
function getScriptDirectionTag($lid): string
{
global $tbpref;
if (!isset($lid) ) {
return '';
}
if (trim($lid) == '' ) {
return '';
}
if (!is_numeric($lid) ) {
if (!isset($lid) || trim($lid) == '' || !is_numeric($lid)) {
return '';
}
$r = get_first_value(
"select LgRightToLeft as value
from " . $tbpref . "languages
where LgID='" . $lid . "'"
"SELECT LgRightToLeft as value
from {$tbpref}languages
where LgID = $lid"
);
if (isset($r) ) {
if ($r) {
return ' dir="rtl" ';
}
if (isset($r) && $r) {
return ' dir="rtl" ';
}
return '';
}
Expand Down
14 changes: 8 additions & 6 deletions long_text_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
function long_text_check($max_input_vars): void
{

$langid = $_REQUEST["LgID"];
$title = $_REQUEST["TxTitle"];
$paragraph_handling = (int)$_REQUEST["paragraph_handling"];
$maxsent = $_REQUEST["maxsent"];
$source_uri = $_REQUEST["TxSourceURI"];
$langid = (int) $_REQUEST["LgID"];
$title = (string) $_REQUEST["TxTitle"];
$paragraph_handling = (int) $_REQUEST["paragraph_handling"];
$maxsent = (int) $_REQUEST["maxsent"];
$source_uri = (string) $_REQUEST["TxSourceURI"];
$texttags = null;
if (isset($_REQUEST["TextTags"])) {
$texttags = json_encode($_REQUEST["TextTags"]);
Expand Down Expand Up @@ -142,7 +142,9 @@ function long_text_check($max_input_vars): void
Length:<br /><?php echo $bytes; ?><br />Bytes
</td>
<td class="td1">
<textarea readonly="readonly" <?php echo getScriptDirectionTag($langid); ?> name="text[<?php echo $textno; ?>]" cols="60" rows="10">
<textarea readonly="readonly"
<?php echo getScriptDirectionTag($langid); ?>
name="text[<?php echo $textno; ?>]" cols="60" rows="10">
<?php echo $textstring; ?>
</textarea>
</td>
Expand Down
2 changes: 1 addition & 1 deletion show_word.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

$tags = getWordTagList($wid, '', 0, 0);
$rom = $record['WoRomanization'];
$scrdir = getScriptDirectionTag($record['WoLgID']);
$scrdir = getScriptDirectionTag((int) $record['WoLgID']);

?>

Expand Down

0 comments on commit c30f391

Please sign in to comment.