Beispiel #1
0
 public function __construct($component, $componentName, $componentTemplate, $parentComponent, $bComponentEnabled)
 {
     $this->component = $component;
     $this->componentName = $componentName;
     $this->componentTemplate = $componentTemplate;
     $this->parentComponent = $parentComponent;
     $this->bComponentEnabled = $bComponentEnabled;
     $aTrace = Freetrix\Main\Diag\Helper::getBackTrace(2);
     $io = CBXVirtualIo::GetInstance();
     $this->sSrcFile = str_replace("\\", "/", $io->GetLogicalName($aTrace[1]["file"]));
     $this->iSrcLine = intval($aTrace[1]["line"]);
     if ($this->iSrcLine > 0 && $this->sSrcFile != "") {
         // try to convert absolute path to file within DOCUMENT_ROOT
         $doc_root = strtolower(str_replace("\\", "/", realpath($_SERVER["DOCUMENT_ROOT"])));
         if (strpos(strtolower($this->sSrcFile), $doc_root . "/") === 0) {
             //within
             $this->sSrcFile = substr($this->sSrcFile, strlen($doc_root));
             $this->bSrcFound = true;
         } else {
             //outside
             $sRealFreetrix = strtolower(str_replace("\\", "/", realpath($_SERVER["DOCUMENT_ROOT"] . "/freetrix")));
             if (strpos(strtolower($this->sSrcFile), substr($sRealFreetrix, 0, -6)) === 0) {
                 $this->sSrcFile = substr($this->sSrcFile, strlen($sRealFreetrix) - 7);
                 $this->bSrcFound = true;
             }
         }
     }
 }
Beispiel #2
0
 function addDebugQuery($strSql, $exec_time, $node_id = 0)
 {
     $this->cntQuery++;
     $this->timeQuery += $exec_time;
     if (defined("FX_NO_SQL_BACKTRACE")) {
         $trace = false;
     } else {
         $trace = array();
         foreach (Freetrix\Main\Diag\Helper::getBackTrace(8) as $i => $tr) {
             if ($i > 0) {
                 $args = array();
                 if (is_array($tr["args"])) {
                     foreach ($tr["args"] as $k1 => $v1) {
                         if (is_array($v1)) {
                             foreach ($v1 as $k2 => $v2) {
                                 if (is_scalar($v2)) {
                                     $args[$k1][$k2] = $v2;
                                 } elseif (is_object($v2)) {
                                     $args[$k1][$k2] = get_class($v2);
                                 } else {
                                     $args[$k1][$k2] = gettype($v2);
                                 }
                             }
                         } else {
                             if (is_scalar($v1)) {
                                 $args[$k1] = $v1;
                             } elseif (is_object($v1)) {
                                 $args[$k1] = get_class($v1);
                             } else {
                                 $args[$k1] = gettype($v1);
                             }
                         }
                     }
                 }
                 $trace[] = array("file" => $tr["file"], "line" => $tr["line"], "class" => $tr["class"], "type" => $tr["type"], "function" => $tr["function"], "args" => $args);
             }
             if ($i == 7) {
                 break;
             }
         }
     }
     $this->arQueryDebug[] = array("QUERY" => $strSql, "TIME" => $exec_time, "TRACE" => $trace, "FX_STATE" => $GLOBALS["FX_STATE"], "NODE_ID" => $node_id);
 }
Beispiel #3
0
					</font><br>
					<?if (is_object($GLOBALS["USER"]) && $GLOBALS["USER"]->IsAdmin()):?>
						</form>
						<form method="post" action="/freetrix/admin/site_checker.php?tabControl_active_tab=edit5#edit5">
							<?
							$strSupportErrorText = "";
							$strSupportErrorText .= "File: ".__FILE__."\n";

							if (strlen($error_position)>0)
								$strSupportErrorText .= "[".$error_position."]\n";
							if (strlen($strSql)>0)
								$strSupportErrorText .= "Query: ".$strSql."\n";
							if (is_object($this) && strlen($this->db_Error)>0)
								$strSupportErrorText .= "[".$this->db_Error."]\n";

							$d = Freetrix\Main\Diag\Helper::getBackTrace();
							$trace = array();  // due to memory limitations
							foreach($d as $tmp)
							{
								$trace[] = array(
									'file' => $tmp['file'],
									'line' => $tmp['line'],
									'class' =>  $tmp['class'],
									'function' => $tmp['function'],
									'args' => $tmp['args']
								);
							}
							$strSupportErrorText .= "debug_backtrace:\n".print_r($trace, True)."\n";
							?>
							<input type="hidden" name="last_error_query" value="<?php 
echo htmlspecialcharsbx($strSupportErrorText);
Beispiel #4
0
function AddMessage2Log($sText, $sModule = "", $traceDepth = 6, $bShowArgs = false)
{
	if (defined("LOG_FILENAME") && strlen(LOG_FILENAME)>0)
	{
		if(!is_string($sText))
		{
			$sText = var_export($sText, true);
		}
		if (strlen($sText)>0)
		{
			ignore_user_abort(true);
			if ($fp = @fopen(LOG_FILENAME, "ab"))
			{
				if (flock($fp, LOCK_EX))
				{
					@fwrite($fp, "Host: ".$_SERVER["HTTP_HOST"]."\nDate: ".date("Y-m-d H:i:s")."\nModule: ".$sModule."\n".$sText."\n");
					$arBacktrace = Freetrix\Main\Diag\Helper::getBackTrace($traceDepth, ($bShowArgs? null : DEBUG_BACKTRACE_IGNORE_ARGS));
					$strFunctionStack = "";
					$strFilesStack = "";
					$iterationsCount = min(count($arBacktrace), $traceDepth);
					for ($i = 1; $i < $iterationsCount; $i++)
					{
						if (strlen($strFunctionStack)>0)
							$strFunctionStack .= " < ";

						if (isset($arBacktrace[$i]["class"]))
							$strFunctionStack .= $arBacktrace[$i]["class"]."::";

						$strFunctionStack .= $arBacktrace[$i]["function"];

						if(isset($arBacktrace[$i]["file"]))
							$strFilesStack .= "\t".$arBacktrace[$i]["file"].":".$arBacktrace[$i]["line"]."\n";
						if($bShowArgs && isset($arBacktrace[$i]["args"]))
						{
							$strFilesStack .= "\t\t";
							if (isset($arBacktrace[$i]["class"]))
								$strFilesStack .= $arBacktrace[$i]["class"]."::";
							$strFilesStack .= $arBacktrace[$i]["function"];
							$strFilesStack .= "(\n";
							foreach($arBacktrace[$i]["args"] as $value)
								$strFilesStack .= "\t\t\t".$value."\n";
							$strFilesStack .= "\t\t)\n";

						}
					}

					if (strlen($strFunctionStack)>0)
					{
						@fwrite($fp, "    ".$strFunctionStack."\n".$strFilesStack);
					}

					@fwrite($fp, "----------\n");
					@fflush($fp);
					@flock($fp, LOCK_UN);
					@fclose($fp);
				}
			}
			ignore_user_abort(false);
		}
	}
}
Beispiel #5
0
	function GetComponentID($componentName, $componentTemplate, $additionalID)
	{
		$aTrace = Freetrix\Main\Diag\Helper::getBackTrace(0, DEBUG_BACKTRACE_IGNORE_ARGS);

		$trace_count = count($aTrace);
		$trace_current = $trace_count-1;
		for ($i = 0; $i<$trace_count; $i++)
		{
			if (strtolower($aTrace[$i]['function']) == 'includecomponent' && (($c = strtolower($aTrace[$i]['class'])) == 'callmain' || $c == 'cmain'))
			{
				$trace_current = $i;
				break;
			}
		}

		$sSrcFile = strtolower(str_replace("\\", "/", $aTrace[$trace_current]["file"]));
		$iSrcLine = intval($aTrace[$trace_current]["line"]);

		$bSrcFound = false;

		if($iSrcLine > 0 && $sSrcFile <> "")
		{
			// try to covert absolute path to file within DOCUMENT_ROOT
			$doc_root = rtrim(str_replace(Array("\\\\", "//", "\\"), Array("\\", "/", "/"), realpath($_SERVER["DOCUMENT_ROOT"])), "\\/");
			$doc_root = strtolower($doc_root);

			if(strpos($sSrcFile, $doc_root."/") === 0)
			{
				//within
				$sSrcFile = substr($sSrcFile, strlen($doc_root));
				$bSrcFound = true;
			}
			else
			{
				//outside
				$sRealFreetrix = strtolower(str_replace("\\", "/", realpath($_SERVER["DOCUMENT_ROOT"]."/freetrix")));

				if(strpos($sSrcFile, substr($sRealFreetrix, 0, -6)) === 0)
				{
					$sSrcFile = substr($sSrcFile, strlen($sRealFreetrix) - 7);
					$bSrcFound = true;
				}
				else
				{
					// special hack
					$sRealFreetrixModules = strtolower(str_replace("\\", "/", realpath($_SERVER["DOCUMENT_ROOT"]."/freetrix/modules")));
					if(strpos($sSrcFile, $sRealFreetrixModules) === 0)
					{
						$sSrcFile = "/freetrix/modules".substr($sSrcFile, strlen($sRealFreetrixModules));
						$bSrcFound = true;
					}
				}
			}
		}

		if (!$bSrcFound)
			return false;

		$session_string = $sSrcFile.'|'.$iSrcLine.'|'.$componentName;

		if (strlen($componentTemplate) > 0)
			$session_string .= '|'.$componentTemplate;
		else
			$session_string .= '|.default';

		$session_string .= '|'.$additionalID;

		return md5($session_string);
	}
Beispiel #6
0
 function IncludeFile($rel_path, $arParams = array(), $arFunctionParams = array())
 {
     /** @global CMain $APPLICATION */
     /** @noinspection PhpUnusedLocalVariableInspection */
     global $APPLICATION, $USER, $DB, $MESS, $DOCUMENT_ROOT;
     if ($_SESSION["SESS_SHOW_INCLUDE_TIME_EXEC"] == "Y" && ($USER->CanDoOperation('edit_php') || $_SESSION["SHOW_SQL_STAT"] == "Y")) {
         $debug = new CDebugInfo();
         $debug->Start();
     } elseif ($APPLICATION->ShowIncludeStat) {
         $debug = new CDebugInfo();
         $debug->Start();
     } else {
         $debug = null;
     }
     $sType = "TEMPLATE";
     $bComponent = false;
     if (substr($rel_path, 0, 1) != "/") {
         $bComponent = true;
         $path = FX_PERSONAL_ROOT . "/templates/" . SITE_TEMPLATE_ID . "/" . $rel_path;
         if (!file_exists($_SERVER["DOCUMENT_ROOT"] . $path)) {
             $sType = "DEFAULT";
             $path = FX_PERSONAL_ROOT . "/templates/.default/" . $rel_path;
             if (!file_exists($_SERVER["DOCUMENT_ROOT"] . $path)) {
                 $path = FX_PERSONAL_ROOT . "/templates/" . SITE_TEMPLATE_ID . "/" . $rel_path;
                 $module_id = substr($rel_path, 0, strpos($rel_path, "/"));
                 if (strlen($module_id) > 0) {
                     $path = "/freetrix/modules/" . $module_id . "/install/templates/" . $rel_path;
                     $sType = "MODULE";
                     if (!file_exists($_SERVER["DOCUMENT_ROOT"] . $path)) {
                         $sType = "TEMPLATE";
                         $path = FX_PERSONAL_ROOT . "/templates/" . SITE_TEMPLATE_ID . "/" . $rel_path;
                     }
                 }
             }
         }
     } else {
         $path = $rel_path;
     }
     if ($arFunctionParams["WORKFLOW"] && !IsModuleInstalled("workflow")) {
         $arFunctionParams["WORKFLOW"] = false;
     } elseif ($sType != "TEMPLATE" && $arFunctionParams["WORKFLOW"]) {
         $arFunctionParams["WORKFLOW"] = false;
     }
     $bDrawIcons = $arFunctionParams["SHOW_BORDER"] !== false && $APPLICATION->GetShowIncludeAreas() && ($USER->CanDoFileOperation('fm_edit_existent_file', array(SITE_ID, $path)) || $arFunctionParams["WORKFLOW"] && $USER->CanDoFileOperation('fm_edit_in_workflow', array(SITE_ID, $path)));
     $iSrcLine = 0;
     $sSrcFile = '';
     $arIcons = array();
     if ($bDrawIcons) {
         $path_url = "path=" . $path;
         $encSiteTemplateId = urlencode(SITE_TEMPLATE_ID);
         $editor = '';
         $resize = 'false';
         if (!in_array($arFunctionParams['MODE'], array('html', 'text', 'php'))) {
             $arFunctionParams['MODE'] = $bComponent ? 'php' : 'html';
         }
         if ($sType != 'TEMPLATE') {
             switch ($arFunctionParams['MODE']) {
                 case 'html':
                     $editor = "/freetrix/admin/fileman_html_edit.php?site=" . SITE_ID . "&";
                     break;
                 case 'text':
                     $editor = "/freetrix/admin/fileman_file_edit.php?site=" . SITE_ID . "&";
                     break;
                 case 'php':
                     $editor = "/freetrix/admin/fileman_file_edit.php?full_src=Y&site=" . SITE_ID . "&";
                     break;
             }
             $editor .= "templateID=" . $encSiteTemplateId . "&";
         } else {
             switch ($arFunctionParams['MODE']) {
                 case 'html':
                     $editor = '/freetrix/admin/public_file_edit.php?bxpublic=Y&from=includefile&templateID=' . $encSiteTemplateId . '&';
                     $resize = 'false';
                     break;
                 case 'text':
                     $editor = '/freetrix/admin/public_file_edit.php?bxpublic=Y&from=includefile&noeditor=Y&';
                     $resize = 'true';
                     break;
                 case 'php':
                     $editor = '/freetrix/admin/public_file_edit_src.php?templateID=' . $encSiteTemplateId . '&';
                     $resize = 'true';
                     break;
             }
         }
         if ($arFunctionParams["TEMPLATE"]) {
             $arFunctionParams["TEMPLATE"] = "&template=" . urlencode($arFunctionParams["TEMPLATE"]);
         }
         if ($arFunctionParams["BACK_URL"]) {
             $arFunctionParams["BACK_URL"] = "&back_url=" . urlencode($arFunctionParams["BACK_URL"]);
         } else {
             $arFunctionParams["BACK_URL"] = "&back_url=" . urlencode($_SERVER["REQUEST_URI"]);
         }
         if ($arFunctionParams["LANG"]) {
             $arFunctionParams["LANG"] = "&lang=" . urlencode($arFunctionParams["LANG"]);
         } else {
             $arFunctionParams["LANG"] = "&lang=" . LANGUAGE_ID;
         }
         $arPanelParams = array();
         $bDefaultExists = false;
         if ($USER->CanDoOperation('edit_php') && $bComponent) {
             $bDefaultExists = true;
             $arPanelParams["TOOLTIP"] = array('TITLE' => GetMessage("main_incl_component1"), 'TEXT' => $rel_path);
             $aTrace = Freetrix\Main\Diag\Helper::getBackTrace(1, DEBUG_BACKTRACE_IGNORE_ARGS);
             $sSrcFile = $aTrace[0]["file"];
             $iSrcLine = intval($aTrace[0]["line"]);
             $arIcons[] = array('URL' => 'javascript:' . $APPLICATION->GetPopupLink(array('URL' => "/freetrix/admin/component_props.php?" . "path=" . urlencode(CUtil::addslashes($rel_path)) . "&template_id=" . urlencode(CUtil::addslashes(SITE_TEMPLATE_ID)) . "&lang=" . LANGUAGE_ID . "&src_path=" . urlencode(CUtil::addslashes($sSrcFile)) . "&src_line=" . $iSrcLine . "")), 'ICON' => "parameters", 'TITLE' => GetMessage("main_incl_file_comp_param"), 'DEFAULT' => true);
         }
         if ($sType == "MODULE") {
             $arIcons[] = array('URL' => 'javascript:if(confirm(\'' . GetMessage("MAIN_INC_BLOCK_MODULE") . '\'))window.location=\'' . $editor . '&path=' . urlencode(FX_PERSONAL_ROOT . '/templates/' . SITE_TEMPLATE_ID . '/' . $rel_path) . $arFunctionParams["BACK_URL"] . $arFunctionParams["LANG"] . '&template=' . $path . '\';', 'ICON' => 'copy', 'TITLE' => str_replace("#MODE#", $arFunctionParams["MODE"], str_replace("#BLOCK_TYPE#", !is_set($arFunctionParams, "NAME") ? GetMessage("MAIN__INC_BLOCK") : $arFunctionParams["NAME"], GetMessage("main_incl_file_edit_copy"))));
         } elseif ($sType == "DEFAULT") {
             $arIcons[] = array('URL' => 'javascript:if(confirm(\'' . GetMessage("MAIN_INC_BLOCK_COMMON") . '\'))window.location=\'' . $editor . $path_url . $arFunctionParams["BACK_URL"] . $arFunctionParams["LANG"] . $arFunctionParams["TEMPLATE"] . '\';', 'ICON' => 'edit-common', 'TITLE' => str_replace("#MODE#", $arFunctionParams["MODE"], str_replace("#BLOCK_TYPE#", !is_set($arFunctionParams, "NAME") ? GetMessage("MAIN__INC_BLOCK") : $arFunctionParams["NAME"], GetMessage("MAIN_INC_BLOCK_EDIT"))));
             $arIcons[] = array('URL' => $editor . '&path=' . urlencode(FX_PERSONAL_ROOT . '/templates/' . SITE_TEMPLATE_ID . '/' . $rel_path) . $arFunctionParams["BACK_URL"] . $arFunctionParams["LANG"] . '&template=' . $path, 'ICON' => 'copy', 'TITLE' => str_replace("#MODE#", $arFunctionParams["MODE"], str_replace("#BLOCK_TYPE#", !is_set($arFunctionParams, "NAME") ? GetMessage("MAIN__INC_BLOCK") : $arFunctionParams["NAME"], GetMessage("MAIN_INC_BLOCK_COMMON_COPY"))));
         } else {
             $arPanelParams["TOOLTIP"] = array('TITLE' => GetMessage('main_incl_file'), 'TEXT' => $path);
             $arIcons[] = array('URL' => 'javascript:' . $APPLICATION->GetPopupLink(array('URL' => $editor . $path_url . $arFunctionParams["BACK_URL"] . $arFunctionParams["LANG"] . $arFunctionParams["TEMPLATE"], "PARAMS" => array('width' => 770, 'height' => 470, 'resize' => $resize))), 'ICON' => 'bx-context-toolbar-edit-icon', 'TITLE' => str_replace("#MODE#", $arFunctionParams["MODE"], str_replace("#BLOCK_TYPE#", !is_set($arFunctionParams, "NAME") ? GetMessage("MAIN__INC_BLOCK") : $arFunctionParams["NAME"], GetMessage("MAIN_INC_ED"))), 'DEFAULT' => !$bDefaultExists);
             if ($arFunctionParams["WORKFLOW"]) {
                 $arIcons[] = array('URL' => '/freetrix/admin/workflow_edit.php?' . $arFunctionParams["LANG"] . '&fname=' . urlencode($path) . $arFunctionParams["TEMPLATE"] . $arFunctionParams["BACK_URL"], 'ICON' => 'bx-context-toolbar-edit-icon', 'TITLE' => str_replace("#BLOCK_TYPE#", !is_set($arFunctionParams, "NAME") ? GetMessage("MAIN__INC_BLOCK") : $arFunctionParams["NAME"], GetMessage("MAIN_INC_ED_WF")));
             }
         }
         echo $this->IncludeStringBefore();
     }
     $res = null;
     if (is_file($_SERVER["DOCUMENT_ROOT"] . $path)) {
         if (is_array($arParams)) {
             extract($arParams, EXTR_SKIP);
         }
         $res = (include $_SERVER["DOCUMENT_ROOT"] . $path);
     }
     if ($_SESSION["SESS_SHOW_INCLUDE_TIME_EXEC"] == "Y" && ($USER->CanDoOperation('edit_php') || $_SESSION["SHOW_SQL_STAT"] == "Y")) {
         echo $debug->Output($rel_path, $path);
     } elseif (is_object($debug)) {
         $debug->Stop($rel_path, $path);
     }
     if ($bDrawIcons) {
         $comp_id = $path;
         if ($sSrcFile) {
             $comp_id .= '|' . $sSrcFile;
         }
         if ($iSrcLine) {
             $comp_id .= '|' . $iSrcLine;
         }
         $arPanelParams['COMPONENT_ID'] = md5($comp_id);
         echo $this->IncludeStringAfter($arIcons, $arPanelParams);
     }
     return $res;
 }