348 public function __construct($component, $componentName, $componentTemplate, $parentComponent, $bComponentEnabled)
350 $this->component = $component;
351 $this->componentName = $componentName;
352 $this->componentTemplate = $componentTemplate;
353 $this->parentComponent = $parentComponent;
354 $this->bComponentEnabled = $bComponentEnabled;
356 $aTrace = Bitrix\Main\Diag\Helper::getBackTrace(2);
358 $io = CBXVirtualIo::GetInstance();
360 $this->sSrcFile = str_replace("\\", "/", $io->GetLogicalName($aTrace[1]["file"]));
361 $this->iSrcLine = intval($aTrace[1]["line"]);
363 if($this->iSrcLine > 0 && $this->sSrcFile <> "")
365 // try to convert absolute path to file within DOCUMENT_ROOT
366 $lowerScrFile = mb_strtolower($this->sSrcFile);
367 $docRoot = mb_strtolower(str_replace("\\", "/", realpath($_SERVER["DOCUMENT_ROOT"])));
368 if(mb_strpos($lowerScrFile, $docRoot."/") === 0)
371 $this->sSrcFile = mb_substr($this->sSrcFile, mb_strlen($docRoot));
372 $this->bSrcFound = true;
377 $realBitrix = mb_strtolower(str_replace("\\", "/", realpath($_SERVER["DOCUMENT_ROOT"]."/bitrix")));
378 if(mb_strpos($lowerScrFile, mb_substr($realBitrix, 0, -6)) === 0)
380 $this->sSrcFile = mb_substr($this->sSrcFile, mb_strlen($realBitrix) - 7);
381 $this->bSrcFound = true;
386 $realLocal = mb_strtolower(str_replace("\\", "/", realpath($_SERVER["DOCUMENT_ROOT"]."/local")));
387 if($realLocal && mb_strpos($lowerScrFile, mb_substr($realLocal, 0, -5)) === 0)
389 $this->sSrcFile = mb_substr($this->sSrcFile, mb_strlen($realLocal) - 6);
390 $this->bSrcFound = true;
397 public function GetIcons()
400 global $USER, $APPLICATION;
403 $arPanelParams = array();
405 $arComponentDescription = CComponentUtil::GetComponentDescr($this->componentName);
406 $bComponentAccess = ($USER->CanDoOperation('edit_php
') || $this->bSrcFound && $USER->CanDoFileOperation('fm_lpa
', array(SITE_ID, $this->sSrcFile)));
408 if($bComponentAccess && !$this->parentComponent && $this->bSrcFound)
410 $url = $APPLICATION->GetPopupLink(
412 'URL
' => "/bitrix/admin/component_props.php?".
413 "component_name=".urlencode(CUtil::addslashes($this->componentName)). //$rel_path
414 "&component_template=".urlencode(CUtil::addslashes($this->componentTemplate)).
415 "&template_id=".urlencode(CUtil::addslashes(SITE_TEMPLATE_ID)).
416 "&lang=".urlencode(CUtil::addslashes(LANGUAGE_ID)).
417 "&src_path=".urlencode(CUtil::addslashes($this->sSrcFile)).
418 "&src_line=".$this->iSrcLine.
419 "&src_page=".urlencode(CUtil::addslashes($APPLICATION->GetCurPage())).
420 "&src_site=".urlencode(CUtil::addslashes(SITE_ID)),
421 "PARAMS" => Array("min_width" => 450)
426 'TYPE
'=>'components2_props
',
427 'ICON
'=>"bx-context-toolbar-settings-icon",
428 'TITLE
'=>GetMessage("main_incl_file_comp_param"),
433 "TEXT"=>(!empty($arComponentDescription["NAME"])? $arComponentDescription["NAME"] : $this->componentName),
434 "TITLE"=>GetMessage("main_comp_button_menu_title").' '.$this->componentName,
435 "ICON"=>"parameters-2",
438 $APPLICATION->AddPanelButtonMenu("components", $aMenuItem);
441 if($bComponentAccess)
443 $template = $this->component->GetTemplate();
444 if(is_null($template))
446 //the component is possibly disabled, need to init the template
447 $this->component->setTemplateName($this->componentTemplate);
448 if($this->component->InitComponentTemplate())
449 $template = $this->component->GetTemplate();
451 if(!is_null($template))
454 if($this->bSrcFound && $template->IsInTheme() == false)
456 //copy template dialog
457 $urlCopy = "/bitrix/admin/template_copy.php?".
458 "lang=".urlencode(CUtil::addslashes(LANGUAGE_ID)).
459 "&component_name=".urlencode(CUtil::addslashes($this->componentName)).
460 "&component_template=".urlencode(CUtil::addslashes($this->componentTemplate)).
461 "&template_id=".urlencode(CUtil::addslashes(SITE_TEMPLATE_ID)).
462 "&template_site_template=".urlencode(CUtil::addslashes($template->GetSiteTemplate())).
463 "&src_path=".urlencode(CUtil::addslashes($this->sSrcFile)).
464 "&src_line=".$this->iSrcLine.
465 "&src_site=".urlencode(CUtil::addslashes(SITE_ID)).
466 "&edit_file=".urlencode($template->GetPageName()).
467 "&back_path=".urlencode($_SERVER["REQUEST_URI"]);
469 'URL
'=>'javascript:
'.$APPLICATION->GetPopupLink(
472 "PARAMS" => Array("min_width" => 450)
476 'TITLE
'=>GetMessage("main_comp_copy_templ"),
481 if($USER->CanDoOperation('edit_php
') && $template->GetSiteTemplate() <> '')
483 //edit template copied to site template
485 'URL
' => 'javascript:
'.$APPLICATION->GetPopupLink(array(
486 'URL
' => "/bitrix/admin/public_file_edit_src.php?site=".SITE_ID."&".'path=
'.urlencode($template->GetFile())."&back_url=".urlencode($_SERVER["REQUEST_URI"])."&lang=".LANGUAGE_ID,
491 "dialog_type" => 'EDITOR
',
497 'TITLE
' => GetMessage("main_comp_edit_templ"),
500 if($template->GetFolder() <> '')
502 if(file_exists($_SERVER["DOCUMENT_ROOT"].$template->GetFolder()."/style.css"))
504 //edit template CSS copied to site template
506 'URL
' => 'javascript:
'.$APPLICATION->GetPopupLink(array(
507 'URL
' => "/bitrix/admin/public_file_edit_src.php?site=".SITE_ID."&".'path=
'.urlencode($template->GetFolder()."/style.css")."&back_url=".urlencode($_SERVER["REQUEST_URI"])."&lang=".LANGUAGE_ID,
512 "dialog_type" => 'EDITOR
',
517 'ICON
' => 'edit-css
',
518 'TITLE
' => GetMessage("main_comp_edit_css"),
523 if(file_exists($_SERVER["DOCUMENT_ROOT"].$template->GetFolder()."/result_modifier.php"))
526 $arIcons[] = array('SEPARATOR
'=>true);
528 'URL
' => 'javascript:
'.$APPLICATION->GetPopupLink(array(
529 'URL
' => "/bitrix/admin/public_file_edit_src.php?site=".SITE_ID."&".'path=
'.urlencode($template->GetFolder()."/result_modifier.php")."&back_url=".urlencode($_SERVER["REQUEST_URI"])."&lang=".LANGUAGE_ID,
534 "dialog_type" => 'EDITOR
',
539 'TITLE
' => GetMessage("main_comp_edit_res_mod"),
543 if(file_exists($_SERVER["DOCUMENT_ROOT"].$template->GetFolder()."/component_epilog.php"))
546 $arIcons[] = array('SEPARATOR
'=>true);
548 'URL
' => 'javascript:
'.$APPLICATION->GetPopupLink(array(
549 'URL
' => "/bitrix/admin/public_file_edit_src.php?site=".SITE_ID."&".'path=
'.urlencode($template->GetFolder()."/component_epilog.php")."&back_url=".urlencode($_SERVER["REQUEST_URI"])."&lang=".LANGUAGE_ID,
554 "dialog_type" => 'EDITOR
',
559 'TITLE
' => GetMessage("main_comp_edit_epilog"),
565 elseif($urlCopy <> '')
567 //copy template for future editing
568 $urlCopy .= '&system_template=Y
';
570 'URL
'=>'javascript:
'.$APPLICATION->GetPopupLink(
573 "PARAMS" => Array("min_width" => 450)
577 'TITLE
'=>GetMessage("main_comp_edit_templ"),
578 'ALT
'=>GetMessage("main_comp_copy_title"),
585 $aAddIcons = array();
586 $arPanelParams['COMPONENT
'] = $this->componentName;
587 if($arComponentDescription && is_array($arComponentDescription))
589 $arPanelParams['COMPONENT_DESCRIPTION
'] = $arComponentDescription;
591 //component bar tooltip
592 $arPanelParams['TOOLTIP
'] = array(
593 'TITLE
' => $arComponentDescription["NAME"],
594 'TEXT
' => '(
'.GetMessage('main_incl_comp_component
').' '.$this->componentName.')
'.
595 (isset($arComponentDescription["DESCRIPTION"]) && $arComponentDescription["DESCRIPTION"] <> ""? '<br />
'.$arComponentDescription["DESCRIPTION"]:'')
599 if(array_key_exists("CACHE_PATH", $arComponentDescription) && $USER->CanDoOperation('cache_control
'))
601 if($arComponentDescription["CACHE_PATH"] <> '')
604 "URL" => "javascript:jsComponentUtils.ClearCache('component_name=
".urlencode(CUtil::addslashes($this->componentName))."&site_id=
".SITE_ID."&
".bitrix_sessid_get()."');",
605 "ICON" => "del-cache",
606 "TITLE" => GetMessage("MAIN_BX_COMPONENT_CACHE_CLEAR"),
609 $APPLICATION->aCachedComponents[] = $this->componentName;
613 //additional buttons from component description
614 if(array_key_exists("AREA_BUTTONS", $arComponentDescription))
616 $componentRelativePath = CComponentEngine::MakeComponentPath($this->componentName);
617 $localPath = getLocalPath("components".$componentRelativePath);
618 foreach($arComponentDescription["AREA_BUTTONS"] as $value)
620 if (array_key_exists("SRC", $value))
621 $value["SRC"] = $localPath.$value["SRC"];
622 $aAddIcons[] = $value;
627 if(!empty($arIcons) && !empty($aAddIcons))
628 $arIcons[] = array("SEPARATOR"=>true);
629 $arIcons = array_merge($arIcons, $aAddIcons);
631 $aAddIcons = $this->component->GetIncludeAreaIcons();
633 if(!empty($arIcons) && !empty($aAddIcons))
634 $arIcons[] = array("SEPARATOR"=>true);
635 $arIcons = array_merge($arIcons, $aAddIcons);
637 // enable/disable menu item
638 if($bComponentAccess && !$this->parentComponent && $this->bSrcFound)
641 $arIcons[] = array("SEPARATOR"=>true);
643 "URL" => "javascript:jsComponentUtils.EnableComponent('component_name=
".urlencode(CUtil::addslashes($this->componentName)). //$rel_path
644 "&
lang=
".urlencode(CUtil::addslashes(LANGUAGE_ID)).
645 "&src_path=
".urlencode(CUtil::addslashes($this->sSrcFile)).
646 "&src_line=
".$this->iSrcLine.
647 "&src_site=
".urlencode(CUtil::addslashes(SITE_ID)).
648 '&active='.($this->bComponentEnabled? 'N':'Y').
649 '&'.bitrix_sessid_get()."');",
650 "TITLE" => ($this->bComponentEnabled? GetMessage("main_comp_disable"):GetMessage("main_comp_enable")),
651 "ALT" => ($this->bComponentEnabled? GetMessage("main_comp_disable_title"):GetMessage("main_comp_enable_title")),
657 $arPanelParams['COMPONENT_ID
'] = md5($arPanelParams['COMPONENT
'].'|
'.$this->sSrcFile.':
'.$this->iSrcLine);
659 return array("icons"=>$arIcons, "parameters"=>$arPanelParams);