コード例 #1
0
ファイル: tbs_class.php プロジェクト: ssolano/cafe_sigesp
function meth_Locator_Replace(&$Txt,&$Loc,&$Value,$CheckSub) {
// This function enables to merge a locator with a text and returns the position just after the replaced block
// This position can be useful because we don't know in advance how $Value will be replaced.

	// Found the value if there is a subname
	if ($CheckSub and $Loc->SubOk) {
		$SubId = 0;
		while ($SubId<$Loc->SubNbr) {
			$x = $Loc->SubLst[$SubId]; // &$Loc... brings an error with Event Example, I don't know why.
			if (is_array($Value)) {
				if (isset($Value[$x])) {
					$Value =& $Value[$x];
				} elseif (array_key_exists($x,$Value)) {// can happens when value is NULL
					$Value =& $Value[$x];
				} else {
					$Value =& tbs_Misc_UnlinkVar('');
					if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert('Array value','Can\'t merge '.$this->ChrOpen.$Loc->FullName.$this->ChrClose.' because sub-item \''.$x.'\' is not an existing key in the array.',true);
				}
				$SubId++;
			} elseif (is_object($Value)) {
				if (method_exists($Value,$x)) {
					$x = call_user_func(array(&$Value,$x));
				} elseif (isset($Value->$x)) {
					$x = $Value->$x;
				} else {
					if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert('Object value','Can\'t merge '.$this->ChrOpen.$Loc->FullName.$this->ChrClose.' because \''.$x.'\' is neither a method nor a property in the class \''.get_class($Value).'\'.',true);
					$x =& tbs_Misc_UnlinkVar('');
				}
				$Value =& $x;
				$x =& tbs_Misc_UnlinkVar('');
				$SubId++;
			} else {
				if (isset($Loc->PrmLst['selected'])) {
					$SelArray =& $Value;
				} else {
					if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert('Object or Array value expected','Can\'t merge '.$this->ChrOpen.$Loc->FullName.$this->ChrClose.' because the item before \''.$x.'\' is neither an object nor an array. Its type is '.gettype($Value).'.',true);
				}
				$Value =& tbs_Misc_UnlinkVar('');
				$SubId = $Loc->SubNbr;
			}
		}
	}

	$CurrVal = $Value;

	// File inclusion
	if (isset($Loc->PrmLst['file'])) {
		$File = str_replace($this->ChrVal,$CurrVal,$Loc->PrmLst['file']);
		$this->meth_Merge_PhpVar($File,false);
		$OnlyBody = !(isset($Loc->PrmLst['htmlconv']) and (strtolower($Loc->PrmLst['htmlconv'])==='no')); // It's a text file, we don't get the BODY part
		if (tbs_Misc_GetFile($CurrVal,$File)) {
			if ($OnlyBody) $CurrVal = tbs_Html_GetPart($CurrVal,'BODY',false,true);
		} else {
			$CurrVal = '';
			if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert('Parameter \'file\'','Field '.$this->ChrOpen.$Loc->FullName.$this->ChrClose.' : unable to read the file \''.$File.'\'.',true);
		}
		$Loc->ConvHtml = false;
		$Loc->ConvProtect = false;
	}

	// OnFormat event
	if (isset($Loc->PrmLst['onformat'])) {
		if ($Loc->FirstMerge) {
			$Loc->OnFrmInfo = $Loc->PrmLst['onformat'];
			$Loc->OnFrmPrm = array(&$Loc->FullName,'',&$Loc->PrmLst,&$this);
			$ErrMsg = false;
			if (!$this->meth_Misc_UserFctCheck($Loc->OnFrmInfo,$ErrMsg)) {
				unset($Loc->PrmLst['onformat']);
				if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert('Parameter \'onformat\'',$ErrMsg);
				$Loc->OnFrmInfo = 'pi'; // Execute the function pi() just to avoid extra error messages 
			}
		}
		$Loc->OnFrmPrm[1] =& $CurrVal;
		if (isset($Loc->PrmLst['subtpl'])) {
			$this->meth_Misc_ChangeMode(true,$Loc,$CurrVal,true,true);
			call_user_func_array($Loc->OnFrmInfo,$Loc->OnFrmPrm);
			$this->meth_Misc_ChangeMode(false,$Loc,$CurrVal,true,true);
		} else {
			call_user_func_array($Loc->OnFrmInfo,$Loc->OnFrmPrm);
		}
	}

	// Select a value in a HTML option list
	$Select = isset($Loc->PrmLst['selected']);
	if ($Select) {
		if (is_array($CurrVal)) {
			$SelArray =& $CurrVal;
			$CurrVal =& tbs_Misc_UnlinkVar(' ');
		} else {
			$SelArray = false;
		}
	}

	// Convert the value to a string, use format if specified
	if (isset($Loc->PrmLst['frm'])) {
		$CurrVal = tbs_Misc_Format($Loc,$CurrVal);
		$Loc->ConvHtml = false;
	} else {
		if (!is_string($CurrVal)) $CurrVal = @strval($CurrVal);
	}

	// case of an 'if' 'then' 'else' options
	$OVal =& $CurrVal; // Must be assigner after $SelArray, if any
	$Script = isset($Loc->PrmLst['script']);
	if (isset($Loc->PrmLst['if'])) {
		if ($Loc->FirstMerge) {
			$this->meth_Merge_PhpVar($Loc->PrmLst['if'],false);
			if (isset($Loc->PrmLst['then'])) $this->meth_Merge_PhpVar($Loc->PrmLst['then'],true);
			if (isset($Loc->PrmLst['else'])) $this->meth_Merge_PhpVar($Loc->PrmLst['else'],true);
		}
		$x = str_replace($this->ChrVal,$CurrVal,$Loc->PrmLst['if']);
		if (tbs_Misc_CheckCondition($x)) {
			if (isset($Loc->PrmLst['then'])) $CurrVal =& tbs_Misc_UnlinkVar(''.$Loc->PrmLst['then']); // Now $CurrVal and $OVal are different
		} else {
			$Script = false;
			if (isset($Loc->PrmLst['else'])) {
				$CurrVal =& tbs_Misc_UnlinkVar(''.$Loc->PrmLst['else']); // Now $CurrVal and $OVal are different
			} else {
				$CurrVal = '';
			}
		}
	}

	if ($Script) {// Include external PHP script
		$File = str_replace($this->ChrVal,$CurrVal,$Loc->PrmLst['script']);
		$this->meth_Merge_PhpVar($File,false);
		$Switch = isset($Loc->PrmLst['subtpl']);
		$GetOb = ($Switch or isset($Loc->PrmLst['getob']));
		$CurrPrm =& $Loc->PrmLst; // Local var for users
		$this->meth_Misc_ChangeMode(true,$Loc,$CurrVal,$Switch,$GetOb);
		if (isset($Loc->PrmLst['once'])) {$x = @include_once($File);} else {$x = @include($File);}
		if ($x===false) {
			if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert('Parameter \'script\'','Field '.$this->ChrOpen.$Loc->FullName.$this->ChrClose.' cannot be merged because file \''.$File.'\' is not found or not readable.',true);
		}
		$this->meth_Misc_ChangeMode(false,$Loc,$CurrVal,$Switch,$GetOb);
	}

	if ($Loc->FirstMerge) {
		$Loc->FirstMerge = false;
		// Check HtmlConv parameter
		if (isset($Loc->PrmLst['htmlconv'])) {
			$x = strtolower($Loc->PrmLst['htmlconv']);
			$x = '+'.str_replace(' ','',$x).'+';
			if (strpos($x,'+esc+')!==false)  {tbs_Misc_ConvSpe($Loc); $Loc->ConvHtml = false; $Loc->ConvEsc = true; }
			if (strpos($x,'+wsp+')!==false)  {tbs_Misc_ConvSpe($Loc); $Loc->ConvWS = true; }
			if (strpos($x,'+js+')!==false)   {tbs_Misc_ConvSpe($Loc); $Loc->ConvHtml = false; $Loc->ConvJS = true; }
			if (strpos($x,'+no+')!==false)   $Loc->ConvHtml = false;
			if (strpos($x,'+yes+')!==false)  $Loc->ConvHtml = true;
			if (strpos($x,'+nobr+')!==false) {$Loc->ConvHtml = true; $Loc->ConvBr = false; }
			if (strpos($x,'+look+')!==false) {tbs_Misc_ConvSpe($Loc); $Loc->ConvLook = true; }
		} else {
			if ($this->HtmlCharSet===false) $Loc->ConvHtml = false; // No HTML
		}
		// We protect the data that does not come from the source of the template
		if (isset($Loc->PrmLst['protect'])) {
			$x = strtolower($Loc->PrmLst['protect']);
			switch ($x) {
			case 'no' : $Loc->ConvProtect = false; break;
			case 'yes': $Loc->ConvProtect = true; break;
			}
		} else {
			if ($this->Protect===false) $Loc->ConvProtect = false;
		}
	}

	// MaxLength
	if (isset($Loc->PrmLst['max'])) {
		$x = intval($Loc->PrmLst['max']);
		if (strlen($CurrVal)>$x) {
			if ($Loc->ConvHtml or ($this->HtmlCharSet===false)) {
				$CurrVal = substr($CurrVal,0,$x-1).$this->MaxEnd;
			} else {
				tbs_Html_Max($CurrVal,$x);
			}
		}
	}

	// HTML conversion, and TBS protection
	if ($Loc->ConvSpe) { // Using special parameters
		if ($Loc->ConvLook) {
			$Loc->ConvHtml = !tbs_Html_IsHtml($OVal);
			if ($Loc->ConvHtml===false) $OVal = tbs_Html_GetPart($OVal,'BODY',false,true);
		}
		if ($Loc->ConvHtml) {
			$this->meth_Conv_Html($OVal);
			if ($Loc->ConvBr) $OVal = nl2br($OVal);
		}
		if ($Loc->ConvEsc) $OVal = str_replace('\'','\'\'',$OVal);
		if ($Loc->ConvWS) {
			$check = '  ';
			$nbsp = '&nbsp;';
			do {
				$pos = strpos($OVal,$check);
				if ($pos!==false) $OVal = substr_replace($OVal,$nbsp,$pos,1);
			} while ($pos!==false);
		}
		if ($Loc->ConvJS) {
			$OVal = addslashes($OVal); // apply to ('), ("), (\) and (null)
			$OVal = str_replace("\n",'\n',$OVal);
			$OVal = str_replace("\r",'\r',$OVal);
			$OVal = str_replace("\t",'\t',$OVal);
		}
	}	elseif ($Loc->ConvHtml) {
		$this->meth_Conv_Html($OVal);
		if ($Loc->ConvBr) $OVal = nl2br($OVal);
	}
	if ($Loc->ConvProtect) $OVal = str_replace($this->ChrOpen,$this->ChrProtect,$OVal);
	if ($CurrVal!==$OVal) $CurrVal = str_replace($this->ChrVal,$OVal,$CurrVal);

	// Case when it's an empty string
	if ($CurrVal==='') {

		if ($Loc->MagnetId===false) {
			if (isset($Loc->PrmLst['.'])) {
				$Loc->MagnetId = -1;
			} elseif (isset($Loc->PrmLst['ifempty'])) {
				$Loc->MagnetId = -2;
			} elseif (isset($Loc->PrmLst['magnet'])) {
				$Loc->MagnetId = 1;
				$Loc->PosBeg0 = $Loc->PosBeg;
				$Loc->PosEnd0 = $Loc->PosEnd;
				if (isset($Loc->PrmLst['mtype'])) {
					switch ($Loc->PrmLst['mtype']) {
					case 'm+m': $Loc->MagnetId = 2; break;
					case 'm*': $Loc->MagnetId = 3; break;
					case '*m': $Loc->MagnetId = 4; break;
					}
				}
			} else {
				$Loc->MagnetId = 0;
			}
		}

		switch ($Loc->MagnetId) {
		case 0: break;
		case -1: $CurrVal = '&nbsp;'; break; // Enables to avoid blanks in HTML tables
		case -2: $CurrVal = $Loc->PrmLst['ifempty']; break;
		case 1:
			$Loc->Enlarged = true;
			tbs_Locator_EnlargeToTag($Txt,$Loc,$Loc->PrmLst['magnet'],false,false);
			break;
		case 2:
			$Loc->Enlarged = true;
			$CurrVal = tbs_Locator_EnlargeToTag($Txt,$Loc,$Loc->PrmLst['magnet'],false,true);
			break;
		case 3:
			$Loc->Enlarged = true;
			$Loc2 = tbs_Html_FindTag($Txt,$Loc->PrmLst['magnet'],true,$Loc->PosBeg,false,1,false);
			if ($Loc2!==false) {
				$Loc->PosBeg = $Loc2->PosBeg;
				if ($Loc->PosEnd<$Loc2->PosEnd) $Loc->PosEnd = $Loc2->PosEnd;
			}
			break;
		case 4:
			$Loc->Enlarged = true;
			$Loc2 = tbs_Html_FindTag($Txt,$Loc->PrmLst['magnet'],true,$Loc->PosBeg,true,1,false);
			if ($Loc2!==false) $Loc->PosEnd = $Loc2->PosEnd;
			break;
		}
		$NewEnd = $Loc->PosBeg; // Useful when mtype='m+m'
	} else {
		$NewEnd = $Loc->PosBeg + strlen($CurrVal);
	}

	$Txt = substr_replace($Txt,$CurrVal,$Loc->PosBeg,$Loc->PosEnd-$Loc->PosBeg+1);

	if ($Select) tbs_Html_MergeItems($Txt,$Loc,$CurrVal,$SelArray,$NewEnd);

	return $NewEnd; // Returns the new end position of the field

}
コード例 #2
0
ファイル: tbs.php プロジェクト: vivaserver/sys
 function meth_Locator_Replace(&$Txt, &$Loc, &$Value, $SubStart)
 {
     // This function enables to merge a locator with a text and returns the position just after the replaced block
     // This position can be useful because we don't know in advance how $Value will be replaced.
     // Found the value if there is a subname
     if ($SubStart !== false and $Loc->SubOk) {
         for ($i = $SubStart; $i < $Loc->SubNbr; $i++) {
             $x = $Loc->SubLst[$i];
             // &$Loc... brings an error with Event Example, I don't know why.
             if (is_array($Value)) {
                 if (isset($Value[$x])) {
                     $Value =& $Value[$x];
                 } elseif (array_key_exists($x, $Value)) {
                     // can happens when value is NULL
                     $Value =& $Value[$x];
                 } else {
                     if (!isset($Loc->PrmLst['noerr'])) {
                         $this->meth_Misc_Alert($Loc, 'item \'' . $x . '\' is not an existing key in the array.', true);
                     }
                     unset($Value);
                     $Value = '';
                     break;
                 }
             } elseif (is_object($Value)) {
                 $ArgLst = tbs_Misc_CheckArgLst($x);
                 if (method_exists($Value, $x)) {
                     $x = call_user_func_array(array(&$Value, $x), $ArgLst);
                 } elseif (property_exists($Value, $x)) {
                     $x =& $Value->{$x};
                 } else {
                     if (!isset($Loc->PrmLst['noerr'])) {
                         $this->meth_Misc_Alert($Loc, 'item ' . $x . '\' is neither a method nor a property in the class \'' . get_class($Value) . '\'.', true);
                     }
                     unset($Value);
                     $Value = '';
                     break;
                 }
                 $Value =& $x;
                 unset($x);
                 $x = '';
             } else {
                 if (!isset($Loc->PrmLst['noerr'])) {
                     $this->meth_Misc_Alert($Loc, 'item before \'' . $x . '\' is neither an object nor an array. Its type is ' . gettype($Value) . '.', true);
                 }
                 unset($Value);
                 $Value = '';
                 break;
             }
         }
     }
     $CurrVal = $Value;
     // Unlink
     if (isset($Loc->PrmLst['onformat'])) {
         if ($Loc->FirstMerge) {
             $Loc->OnFrmInfo = $Loc->PrmLst['onformat'];
             $Loc->OnFrmArg = array(&$Loc->FullName, '', &$Loc->PrmLst, &$this);
             $ErrMsg = false;
             if (!$this->meth_Misc_UserFctCheck($Loc->OnFrmInfo, $ErrMsg, false)) {
                 unset($Loc->PrmLst['onformat']);
                 if (!isset($Loc->PrmLst['noerr'])) {
                     $this->meth_Misc_Alert($Loc, '(parameter onformat) ' . $ErrMsg);
                 }
                 $Loc->OnFrmInfo = 'pi';
                 // Execute the function pi() just to avoid extra error messages
             }
         }
         $Loc->OnFrmArg[1] =& $CurrVal;
         if (isset($Loc->PrmLst['subtpl'])) {
             $this->meth_Misc_ChangeMode(true, $Loc, $CurrVal);
             call_user_func_array($Loc->OnFrmInfo, $Loc->OnFrmArg);
             $this->meth_Misc_ChangeMode(false, $Loc, $CurrVal);
             $Loc->ConvProtect = false;
             $Loc->ConvHtml = false;
         } else {
             call_user_func_array($Loc->OnFrmInfo, $Loc->OnFrmArg);
         }
     }
     if ($Loc->FirstMerge) {
         if (isset($Loc->PrmLst['frm'])) {
             $Loc->ConvMode = 0;
             // Frm
             $Loc->ConvProtect = false;
         } else {
             // Analyze parameter 'htmlconv'
             if (isset($Loc->PrmLst['htmlconv'])) {
                 $x = strtolower($Loc->PrmLst['htmlconv']);
                 $x = '+' . str_replace(' ', '', $x) . '+';
                 if (strpos($x, '+esc+') !== false) {
                     tbs_Misc_ConvSpe($Loc);
                     $Loc->ConvHtml = false;
                     $Loc->ConvEsc = true;
                 }
                 if (strpos($x, '+wsp+') !== false) {
                     tbs_Misc_ConvSpe($Loc);
                     $Loc->ConvWS = true;
                 }
                 if (strpos($x, '+js+') !== false) {
                     tbs_Misc_ConvSpe($Loc);
                     $Loc->ConvHtml = false;
                     $Loc->ConvJS = true;
                 }
                 if (strpos($x, '+no+') !== false) {
                     $Loc->ConvHtml = false;
                 }
                 if (strpos($x, '+yes+') !== false) {
                     $Loc->ConvHtml = true;
                 }
                 if (strpos($x, '+nobr+') !== false) {
                     $Loc->ConvHtml = true;
                     $Loc->ConvBr = false;
                 }
             } else {
                 if ($this->HtmlCharSet === false) {
                     $Loc->ConvHtml = false;
                 }
                 // No HTML
             }
             // Analyze parameter 'protect'
             if (isset($Loc->PrmLst['protect'])) {
                 $x = strtolower($Loc->PrmLst['protect']);
                 if ($x === 'no') {
                     $Loc->ConvProtect = false;
                 } elseif ($x === 'yes') {
                     $Loc->ConvProtect = true;
                 }
             } elseif ($this->Protect === false) {
                 $Loc->ConvProtect = false;
             }
         }
         if ($Loc->Ope = isset($Loc->PrmLst['ope'])) {
             $ope = $Loc->PrmLst['ope'];
             if ($ope === 'list') {
                 $Loc->OpeId = 1;
                 $Loc->OpeSep = isset($Loc->PrmLst['valsep']) ? $Loc->PrmLst['valsep'] : ',';
             } else {
                 $x = substr($ope, 0, 4);
                 if ($x === 'max:') {
                     $Loc->OpeId = isset($Loc->PrmLst['maxhtml']) ? 2 : 3;
                     $Loc->OpeN = intval(trim(substr($ope, 4)));
                     $Loc->OpeEnd = isset($Loc->PrmLst['maxend']) ? $Loc->PrmLst['maxend'] : '...';
                     if ($Loc->OpeN <= 0) {
                         $Loc->Ope = false;
                     }
                 } elseif ($x === 'mod:') {
                     $Loc->OpeId = 4;
                     $Loc->OpeN = intval(trim(substr($ope, 4)));
                 } elseif ($x === 'add:') {
                     $Loc->OpeId = 5;
                     $Loc->OpeN = intval(trim(substr($ope, 4)));
                 } elseif (isset($this->_piOnOperation)) {
                     $Loc->OpeId = 0;
                     $Loc->OpeArg = array(&$Loc->FullName, &$CurrVal, &$Loc->PrmLst, &$Txt, $Loc->PosBeg, $Loc->PosEnd, &$Loc);
                 } else {
                     $Loc->Ope = false;
                     if (!isset($Loc->PrmLst['noerr'])) {
                         $this->meth_Misc_Alert($Loc, 'parameter ope doesn\'t support value \'' . $ope . '\'.', true);
                     }
                 }
             }
         }
         $Loc->FirstMerge = false;
     }
     $ConvProtect = $Loc->ConvProtect;
     // Plug-in OnFormat
     if ($this->_piOnFrm_Ok) {
         if (isset($Loc->OnFrmArgPi)) {
             $Loc->OnFrmArgPi[1] =& $CurrVal;
         } else {
             $Loc->OnFrmArgPi = array(&$Loc->FullName, &$CurrVal, &$Loc->PrmLst, &$this);
         }
         $this->meth_PlugIn_RunAll($this->_piOnFormat, $Loc->OnFrmArgPi);
     }
     // Operation
     if ($Loc->Ope) {
         switch ($Loc->OpeId) {
             case 0:
                 $Loc->OpeArg[1] =& $CurrVal;
                 $Loc->OpeArg[3] =& $Txt;
                 if (!$this->meth_PlugIn_RunAll($this->_piOnOperation, $Loc->OpeArg)) {
                     return $Loc->PosBeg;
                 }
                 break;
             case 1:
                 if (is_array($CurrVal)) {
                     $CurrVal = implode($Loc->OpeSep, $CurrVal);
                 }
                 break;
             case 2:
                 if (strlen('' . $CurrVal) > $Loc->OpeN) {
                     tbs_Html_Max($CurrVal, $Loc->OpeN, $Loc->OpeEnd);
                 }
                 break;
             case 3:
                 if (strlen('' . $CurrVal) > $Loc->OpeN) {
                     $CurrVal = substr('' . $CurrVal, 0, $Loc->OpeN) . $Loc->OpeEnd;
                 }
                 break;
             case 4:
                 $CurrVal = intval($CurrVal) % $Loc->OpeN;
                 break;
             case 5:
                 $CurrVal = intval($CurrVal) + $Loc->OpeN;
                 break;
         }
     }
     // HTML conversion or format
     if ($Loc->ConvMode === 1) {
         // Html simple
         if (!is_string($CurrVal)) {
             $CurrVal = @strval($CurrVal);
         }
         if ($Loc->ConvHtml) {
             $this->meth_Conv_Html($CurrVal);
             if ($Loc->ConvBr) {
                 $CurrVal = nl2br($CurrVal);
             }
         }
     } elseif ($Loc->ConvMode === 0) {
         // Format
         $CurrVal = $this->meth_Misc_Format($CurrVal, $Loc->PrmLst);
     } elseif ($Loc->ConvMode === 2) {
         // Html special
         if (!is_string($CurrVal)) {
             $CurrVal = @strval($CurrVal);
         }
         if ($Loc->ConvHtml) {
             $this->meth_Conv_Html($CurrVal);
             if ($Loc->ConvBr) {
                 $CurrVal = nl2br($CurrVal);
             }
         }
         if ($Loc->ConvEsc) {
             $CurrVal = str_replace('\'', '\'\'', $CurrVal);
         }
         if ($Loc->ConvWS) {
             $check = '  ';
             $nbsp = '&nbsp;';
             do {
                 $pos = strpos($CurrVal, $check);
                 if ($pos !== false) {
                     $CurrVal = substr_replace($CurrVal, $nbsp, $pos, 1);
                 }
             } while ($pos !== false);
         }
         if ($Loc->ConvJS) {
             $CurrVal = addslashes($CurrVal);
             // apply to ('), ("), (\) and (null)
             $CurrVal = str_replace("\n", '\\n', $CurrVal);
             $CurrVal = str_replace("\r", '\\r', $CurrVal);
             $CurrVal = str_replace("\t", '\\t', $CurrVal);
         }
     }
     // if/then/else process, there may be several if/then
     if ($Loc->PrmIfNbr) {
         $z = false;
         $i = 1;
         while ($i !== false) {
             if ($Loc->PrmIfVar[$i]) {
                 $Loc->PrmIfVar[$i] = $this->meth_Merge_AutoVar($Loc->PrmIf[$i], true);
             }
             $x = str_replace($this->_ChrVal, $CurrVal, $Loc->PrmIf[$i]);
             if (tbs_Misc_CheckCondition($x)) {
                 if (isset($Loc->PrmThen[$i])) {
                     if ($Loc->PrmThenVar[$i]) {
                         $Loc->PrmThenVar[$i] = $this->meth_Merge_AutoVar($Loc->PrmThen[$i], true);
                     }
                     $z = $Loc->PrmThen[$i];
                 }
                 $i = false;
             } else {
                 $i++;
                 if ($i > $Loc->PrmIfNbr) {
                     if (isset($Loc->PrmLst['else'])) {
                         if ($Loc->PrmElseVar) {
                             $Loc->PrmElseVar = $this->meth_Merge_AutoVar($Loc->PrmLst['else'], true);
                         }
                         $z = $Loc->PrmLst['else'];
                     }
                     $i = false;
                 }
             }
         }
         if ($z !== false) {
             if ($ConvProtect) {
                 $CurrVal = str_replace($this->_ChrOpen, $this->_ChrProtect, $CurrVal);
                 // TBS protection
                 $ConvProtect = false;
             }
             $CurrVal = str_replace($this->_ChrVal, $CurrVal, $z);
         }
     }
     if (isset($Loc->PrmLst['file'])) {
         $x = $Loc->PrmLst['file'];
         if ($x === true) {
             $x = $CurrVal;
         }
         $this->meth_Merge_AutoVar($x, false);
         $x = trim(str_replace($this->_ChrVal, $CurrVal, $x));
         $CurrVal = '';
         if ($x !== '') {
             if (tbs_Misc_GetFile($CurrVal, $x)) {
                 if (isset($Loc->PrmLst['getbody'])) {
                     $CurrVal = tbs_Html_GetPart($CurrVal, $Loc->PrmLst['getbody'], false, true);
                 }
             } else {
                 if (!isset($Loc->PrmLst['noerr'])) {
                     $this->meth_Misc_Alert($Loc, 'the file \'' . $x . '\' given by parameter file is not found or not readable.', true);
                 }
             }
             $ConvProtect = false;
         }
     }
     if (isset($Loc->PrmLst['script'])) {
         // Include external PHP script
         $x = $Loc->PrmLst['script'];
         if ($x === true) {
             $x = $CurrVal;
         }
         $this->meth_Merge_AutoVar($x, false);
         $x = trim(str_replace($this->_ChrVal, $CurrVal, $x));
         if ($x !== '') {
             $this->_Subscript = $x;
             $this->CurrPrm =& $Loc->PrmLst;
             $sub = isset($Loc->PrmLst['subtpl']);
             if ($sub) {
                 $this->meth_Misc_ChangeMode(true, $Loc, $CurrVal);
             }
             if ($this->meth_Misc_RunSubscript($CurrVal, $Loc->PrmLst) === false) {
                 if (!isset($Loc->PrmLst['noerr'])) {
                     $this->meth_Misc_Alert($Loc, 'the file \'' . $x . '\' given by parameter script is not found or not readable.', true);
                 }
             }
             if ($sub) {
                 $this->meth_Misc_ChangeMode(false, $Loc, $CurrVal);
             }
             if (isset($Loc->PrmLst['getbody'])) {
                 $CurrVal = tbs_Html_GetPart($CurrVal, $Loc->PrmLst['getbody'], false, true);
             }
             unset($this->CurrPrm);
             $ConvProtect = false;
         }
     }
     // Case when it's an empty string
     if ($CurrVal === '') {
         if ($Loc->MagnetId === false) {
             if (isset($Loc->PrmLst['.'])) {
                 $Loc->MagnetId = -1;
             } elseif (isset($Loc->PrmLst['ifempty'])) {
                 $Loc->MagnetId = -2;
             } elseif (isset($Loc->PrmLst['magnet'])) {
                 $Loc->MagnetId = 1;
                 $Loc->PosBeg0 = $Loc->PosBeg;
                 $Loc->PosEnd0 = $Loc->PosEnd;
                 if (isset($Loc->PrmLst['mtype'])) {
                     switch ($Loc->PrmLst['mtype']) {
                         case 'm+m':
                             $Loc->MagnetId = 2;
                             break;
                         case 'm*':
                             $Loc->MagnetId = 3;
                             break;
                         case '*m':
                             $Loc->MagnetId = 4;
                             break;
                     }
                 }
             } else {
                 $Loc->MagnetId = 0;
             }
         }
         switch ($Loc->MagnetId) {
             case 0:
                 break;
             case -1:
                 $CurrVal = '&nbsp;';
                 break;
                 // Enables to avoid blanks in HTML tables
             // Enables to avoid blanks in HTML tables
             case -2:
                 $CurrVal = $Loc->PrmLst['ifempty'];
                 break;
             case 1:
                 $Loc->Enlarged = true;
                 tbs_Locator_EnlargeToTag($Txt, $Loc, $Loc->PrmLst['magnet'], false);
                 break;
             case 2:
                 $Loc->Enlarged = true;
                 $CurrVal = tbs_Locator_EnlargeToTag($Txt, $Loc, $Loc->PrmLst['magnet'], true);
                 break;
             case 3:
                 $Loc->Enlarged = true;
                 $Loc2 = tbs_Html_FindTag($Txt, $Loc->PrmLst['magnet'], true, $Loc->PosBeg, false, 1, false);
                 if ($Loc2 !== false) {
                     $Loc->PosBeg = $Loc2->PosBeg;
                     if ($Loc->PosEnd < $Loc2->PosEnd) {
                         $Loc->PosEnd = $Loc2->PosEnd;
                     }
                 }
                 break;
             case 4:
                 $Loc->Enlarged = true;
                 $Loc2 = tbs_Html_FindTag($Txt, $Loc->PrmLst['magnet'], true, $Loc->PosBeg, true, 1, false);
                 if ($Loc2 !== false) {
                     $Loc->PosEnd = $Loc2->PosEnd;
                 }
                 break;
         }
         $NewEnd = $Loc->PosBeg;
         // Useful when mtype='m+m'
     } else {
         if ($ConvProtect) {
             $CurrVal = str_replace($this->_ChrOpen, $this->_ChrProtect, $CurrVal);
         }
         // TBS protection
         $NewEnd = $Loc->PosBeg + strlen($CurrVal);
     }
     $Txt = substr_replace($Txt, $CurrVal, $Loc->PosBeg, $Loc->PosEnd - $Loc->PosBeg + 1);
     return $NewEnd;
     // Return the new end position of the field
 }