function meth_Misc_ChangeMode($Init,&$Loc,&$CurrVal,$Switch,$GetOb) { if ($Init) { // Save contents configuration if ($Switch) { $Loc->SaveSrc =& $this->Source; $Loc->SaveRender = $this->Render; $Loc->SaveCache = $this->_CacheFile; $Loc->SaveMode = $this->_Mode; $this->Source =& tbs_Misc_UnlinkVar(''); $this->Render = TBS_OUTPUT; $this->_CacheFile = false; $this->_Mode = 1; $File = $Loc->PrmLst['subtpl']; if (is_string($File) and (strlen($File)>0)) { $File = str_replace($this->ChrVal,$CurrVal,$File); $this->meth_Merge_PhpVar($File,false); if (tbs_Misc_GetFile($this->Source,$File)) { $this->meth_Merge_Auto($this->Source,'onload',true,true); } else { if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert('Parameter subtpl','Unable to read the file \''.$File.'\'.'); } } } if ($GetOb) ob_start(); } else { // Restore contents configuration if ($Switch) { $this->Source =& $Loc->SaveSrc; $this->Render = $Loc->SaveRender; $this->_CacheFile = $Loc->SaveCache; $this->_Mode = $Loc->SaveMode; } if ($GetOb) { $CurrVal = ob_get_contents(); ob_end_clean(); } $Loc->ConvHtml = false; $Loc->ConvProtect = false; } }
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 = ' '; 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 = ' '; 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 }