public static function Edit($Params) { global $APPLICATION; $name = CFileMan::SecurePathVar($Params['name']); $title = $Params['title']; $description = $Params['description']; $path = CFileMan::SecurePathVar($Params['path']); $template = CFileMan::SecurePathVar($Params['template']); $site = $Params['site']; $code = $Params['code']; $contPath = $_SERVER["DOCUMENT_ROOT"].BX_PERSONAL_ROOT."/templates/".$template."/snippets"; $thumb = $Params['thumb'] === false ? false : CFileMan::SecurePathVar($Params['thumb']); if (!file_exists($_SERVER["DOCUMENT_ROOT"].BX_PERSONAL_ROOT."/templates/".$template)) { ?><script>alert('Error: Incorrect template Id: <?php echo CUtil::JSEscape($template); ?> ');</script><? return; } if ($Params['bNew']) { $location = CUtil::addslashes(CFileMan::SecurePathVar($Params["location"])); $newGroup = CUtil::addslashes(CFileMan::SecurePathVar($Params["newGroup"])); $path = trim(($location ? $location.'/' : '').($newGroup ? $newGroup.'/' : ''), ' /'); if ($name == '') { $name = CSnippets::GetDefaultFileName($_SERVER["DOCUMENT_ROOT"].BX_PERSONAL_ROOT."/templates/".$template."/snippets/".$path); ?><script>window.__bx_res_sn_filename = "<?php echo CUtil::JSEscape($name); ?> ";</script><? } $name = $name.'.snp'; } $key = $path.($path != '' ? '/' : '').$name; // 1. Save new snippet with new content if ($code) $APPLICATION->SaveFileContent($contPath.'/'.$key, $code); // 2. Rewrite title & description in .content.php if ($title || $description) { if (file_exists($contPath."/.content.php")) @include($contPath."/.content.php"); else $SNIPPETS = array(); if ($title) $SNIPPETS[$key]['title'] = $title; if ($description) $SNIPPETS[$key]['description'] = $description; $contentSrc = '<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>'.chr(10); $contentSrc .= '<?'.chr(10).'$SNIPPETS = Array();'.chr(10); foreach ($SNIPPETS as $k=>$_arSn) { if (CSnippets::CheckFile(array('site' => $Params["site"], 'template' => $Params['template'], 'path' => $k))) $contentSrc .= '$SNIPPETS[\''.CUtil::addslashes($k).'\'] = Array("title"=>\''.Cutil::addslashes($_arSn['title']).'\', "description"=>\''.Cutil::addslashes($_arSn['description']).'\');'.chr(10); } $contentSrc .= '?>'; $APPLICATION->SaveFileContent($contPath."/.content.php", $contentSrc); } CSnippets::ClearCache(); // 3. Handle thumbnail if ($thumb !== false) { if (substr($thumb,0,1) == '/') $thumb = substr($thumb,1); $pos = strrpos($name,"."); if ($pos === FALSE) return true; //delete existent thumbnail $f_name = substr($name, 0, $pos); $img_path1 = BX_PERSONAL_ROOT.'/templates/'.$template.'/snippets/images/'.$path.($path == '' ? '' : '/').$f_name; $DOC_ROOT = CSite::GetSiteDocRoot($site); $arExt = array("gif", "jpg", "jpeg", "png", "bmp"); for ($i = 0, $c = count($arExt); $i < $c; $i++) { $p_ = $img_path1.".".$arExt[$i]; if(file_exists($DOC_ROOT.$p_)) CFileman::DeleteFile(Array($site, $p_)); } if (empty($thumb) || strrpos($thumb, '.') === FALSE) return true; // Copy Thumbnail $path_from_1 = $DOC_ROOT."/".$thumb; $path_from = '/'.$thumb; if (file_exists($path_from_1)) { $pos = strrpos($thumb,"."); $f_ext = ($pos !== FALSE) ? strtolower(substr($thumb, $pos + 1)) : ''; if (in_array($f_ext, $arExt)) { $path_to = $img_path1.'.'.$f_ext; $strWarning_tmp = CFileMan::CopyEx(Array($site, $path_from), Array($site, $path_to)); } } } }
?> } setTimeout("start()", 0); </script> <form> <div id="wf1" style="border-bottom: 2px #efefef dotted; background-color: white; border: solid 1px #DCE7ED; padding: 16px;" ></div> <div id="bizprocsavebuttons"> <br> <input type="button" onclick="BCPSaveTemplate(true);" value="<?php echo GetMessage("BIZPROC_WFEDIT_SAVE_BUTTON"); ?> "> <input type="button" onclick="BCPSaveTemplate();" value="<?php echo GetMessage("BIZPROC_WFEDIT_APPLY_BUTTON"); ?> "> <input type="button" onclick="window.location='<?php echo Cutil::addslashes(htmlspecialcharsbx($back_url)); ?> ';" value="<?php echo GetMessage("BIZPROC_WFEDIT_CANCEL_BUTTON"); ?> "> </div> </form> <?php require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php";
/** * Removes snippet * * @param array - list of params (template, path) * @return bool - result */ public static function Remove($params = array()) { global $APPLICATION; $res = false; $template = CFileMan::SecurePathVar($params['template']); $path = CFileMan::SecurePathVar($params["path"]); $contPath = $_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/" . $template . "/snippets"; $snippetPath = $contPath . ($path == '' ? '' : '/' . $path); $io = CBXVirtualIo::GetInstance(); if (!$io->ValidatePathString($snippetPath) || IsFileUnsafe($snippetPath) || HasScriptExtension($snippetPath)) { return false; } //Delete snippet file if ($io->FileExists($snippetPath)) { $res = $io->Delete($snippetPath); } $SNIPPETS = array(); if ($io->FileExists($contPath . "/.content.php")) { @(include $contPath . "/.content.php"); } $contentSrc = '<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>' . chr(10); $contentSrc .= '<?' . chr(10) . '$SNIPPETS = Array();' . chr(10); foreach ($SNIPPETS as $k => $snip) { if ($io->FileExists(CFileMan::SecurePathVar($contPath . '/' . $k))) { $contentSrc .= '$SNIPPETS[\'' . CUtil::addslashes($k) . '\'] = Array('; if (isset($snip['title']) && $snip['title'] !== '') { $contentSrc .= '\'title\' => \'' . Cutil::addslashes($snip['title']) . '\''; if (isset($snip['description']) && $snip['description'] !== '') { $contentSrc .= ', '; } } if (isset($snip['description']) && $snip['description'] !== '') { $contentSrc .= '\'description\' => \'' . Cutil::addslashes($snip['description']) . '\''; } $contentSrc .= ');' . chr(10); } } $contentSrc .= '?>'; $APPLICATION->SaveFileContent($contPath . "/.content.php", $contentSrc); CSnippets::ClearCache(); return $res; }