Skip to content

Commit

Permalink
Fix php warning (#426)
Browse files Browse the repository at this point in the history
* Fix "Trying to access array offset on value of type bool"

This happens when value=null.

* Fix "Undefined global variable $formulize_screenCurrentlyRendering"

* Fix "Undefined variable $formulize_mgr"

* Fix "Undefined array key 0"

Warnings for line 613:
- Undefined array key 0
- Trying to access array offset on value of type null

* broader handling of empty/unexpected values

?? only evaluates if the expression is null, but this way we catch empty strings, booleans, whatever might be passed in, from who knows where? Because it should all be clean. But this is more bulletproof.

* Broader, more explicit assignment

* Broader catch of non-empty values

* Reverting change, because new master code supersedes it

* Re-adding missing !

Ooops

---------

Co-authored-by: Julian Egelstaff <[email protected]>
  • Loading branch information
tikyon and jegelstaff authored Mar 12, 2024
1 parent b5aa4db commit 1493c04
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
24 changes: 13 additions & 11 deletions modules/formulize/class/checkboxElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,19 +608,21 @@ function afterSavingLogic($value, $element_id, $entry_id) {
// $handle is the element handle for the field that we're retrieving this for
// $entry_id is the entry id of the entry in the form that we're retrieving this for
function prepareDataForDataset($value, $handle, $entry_id) {
global $xoopsDB;
$newValueq = go("SELECT other_text FROM " . $xoopsDB->prefix("formulize_other")." as o, " . $xoopsDB->prefix("formulize")." as f WHERE o.ele_id = f.ele_id AND f.ele_handle=\"" . formulize_db_escape($handle) . "\" AND o.id_req='".intval($entry_id)."' LIMIT 0,1");
// removing the "Other: " part...we just want to show what people actually typed...doesn't have to be flagged specifically as an "other" value
$value_other = $newValueq[0]['other_text'];
global $xoopsDB;
$newValueq = go("SELECT other_text FROM " . $xoopsDB->prefix("formulize_other")." as o, " . $xoopsDB->prefix("formulize")." as f WHERE o.ele_id = f.ele_id AND f.ele_handle=\"" . formulize_db_escape($handle) . "\" AND o.id_req='".intval($entry_id)."' LIMIT 0,1");
// removing the "Other: " part...we just want to show what people actually typed...doesn't have to be flagged specifically as an "other" value
if (!empty($newValueq)) {
$value_other = $newValueq[0]['other_text'];
$value = preg_replace('/\{OTHER\|+[0-9]+\}/', $value_other, $value);
$values = explode("*=+*:",$value);
$elementObject = $this->get($handle);
if($elementObject->getVar('ele_uitextshow')) {
foreach($values as $i=>$value) {
$values[$i] = formulize_swapUIText($value, $elementObject->getVar('ele_uitext'));
}
}
$values = explode("*=+*:",$value);
$elementObject = $this->get($handle);
if($elementObject->getVar('ele_uitextshow')) {
foreach($values as $i=>$value) {
$values[$i] = formulize_swapUIText($value, $elementObject->getVar('ele_uitext'));
}
return $values;
}
return $values;
}

// this method will take a text value that the user has specified at some point, and convert it to a value that will work for comparing with values in the database. This is used primarily for preparing user submitted text values for saving in the database, or for comparing to values in the database, such as when users search for things. The typical user submitted values would be coming from a condition form (ie: fieldX = [term the user typed in]) or other situation where the user types in a value that needs to interact with the database.
Expand Down
10 changes: 5 additions & 5 deletions modules/formulize/class/fileUploadElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ function adminSave($element, $ele_value) {
// $element is the element object
function loadValue($value, $ele_value, $element) {
$value = unserialize($value); // what we've got in the database is a serialized array, first key is filename, second key is flag for whether the filename is for real (might be an error message)
$ele_value[3] = $value['name']; // add additional keys to ele_value where we'll put the value that is coming from the database for user's to see, plus other flags and so on
$ele_value[4] = $this->getFileDisplayName($value['name']);
$ele_value[5] = $value['isfile'];
$ele_value[3] = $value['name'] ? $value['name'] : null; // add additional keys to ele_value where we'll put the value that is coming from the database for user's to see, plus other flags and so on
$ele_value[4] = $this->getFileDisplayName(strval($value['name']));
$ele_value[5] = $value['isfile'] ? $value['name'] : null;
return $ele_value;
}

Expand Down Expand Up @@ -410,8 +410,8 @@ function createDownloadLink($element, $url, $displayName) {

// this method will return the displayName for a file (ie: remove the obscuring timestamp on the front, if any)
function getFileDisplayName($fileName) {
$fileNameParts = explode("+---+",$fileName);
$displayName = isset($fileNameParts[1]) ? $fileNameParts[1] : $fileNameParts[0];
$fileNameParts = explode("+---+",$fileName);
$displayName = isset($fileNameParts[1]) ? $fileNameParts[1] : $fileNameParts[0];
return $displayName;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/formulize/class/listOfEntriesScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ function cloneScreen($sid) {
// $screen is a screen object
// since the number of params for the render method can vary from screen type to screen type, this should take a single array that we unpack in the method, so the number of params is common to all types, ie: one array
function render($screen, $entry, $loadThisView) {
$previouslyRenderingScreen = $GLOBALS['formulize_screenCurrentlyRendering'];
$previouslyRenderingScreen = $GLOBALS['formulize_screenCurrentlyRendering'] ? $GLOBALS['formulize_screenCurrentlyRendering'] : null;
$formframe = $screen->getVar('frid') ? $screen->getVar('frid') : $screen->getVar('fid');
$mainform = $screen->getVar('frid') ? $screen->getVar('fid') : "";
include_once XOOPS_ROOT_PATH . "/modules/formulize/include/entriesdisplay.php";
Expand Down
2 changes: 1 addition & 1 deletion modules/formulize/class/templateScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function render($screen, $entry_id, $settings = "") {
return;
}

$previouslyRenderingScreen = $GLOBALS['formulize_screenCurrentlyRendering'];
$previouslyRenderingScreen = $GLOBALS['formulize_screenCurrentlyRendering'] ? $GLOBALS['formulize_screenCurrentlyRendering'] : null;

// SOME STANDARDS FOR HOW TO HANDLE 'SAVE' AND 'SAVE AND LEAVE' BUTTONS AND THE DONE DEST NEED TO BE DEVISED FOR TEMPLATE SCREENS!!

Expand Down

0 comments on commit 1493c04

Please sign in to comment.