示例#1
0
	public static function ReadDir(&$arSNIPPETS, &$arKeys, $path, $template, $level = 0, $parent = "")
	{
		$basePath = $_SERVER["DOCUMENT_ROOT"].BX_PERSONAL_ROOT."/templates/".$template."/snippets";
		if (!file_exists($basePath))
			return;
		$imagesPath = $basePath."/images";

		CSnippets::WriteHtaccess($imagesPath);

		$bpPath = $basePath.($path == "" ? "" : "/").$path;
		$handle  = @opendir($bpPath);

		while(false !== ($file = @readdir($handle)))
		{
			if($file == "." || $file == ".." || $file == ".htaccess" || $file == ".content.php" || ($level == 0 && $file == "images"))
				continue;

			$fullPath = $bpPath."/".$file;
			if (is_dir($fullPath))
			{
				$new_path = "".$path.($path == "" ? "" : "/").$file;
				CSnippets::ReadDir($arSNIPPETS, $arKeys, $new_path, $template, $level + 1, $file);
			}
			elseif(is_file($fullPath))
			{
				$name = $file;
				$pos = strrpos($name, ".");
				$f_name = ($pos !== FALSE) ? substr($name, 0, $pos) : $name;
				$f_ext = ($pos !== FALSE) ? substr($name, $pos + 1) : '';

				// Rename file *.* => *.snp
				if ($f_ext != 'snp')
				{
					$name = $f_name.".snp";

					if (!file_exists($bpPath."/".$name))
					{
						rename($fullPath, $bpPath."/".$name);
					}
					else
					{
						for ($n = 1; $n < 256; $n++)
						{
							$test_f_name = $f_name."(".$n.")";
							$name = $test_f_name.".snp";
							if (!file_exists($bpPath."/".$name))
							{
								rename($fullPath, $bpPath."/".$name);
								break;
							}
						}
					}
					$f_ext = 'snp';
				}
				$imgPath = $imagesPath."/".$path;
				//Check thumbnail
				if(file_exists($imgPath."/".$f_name.".gif"))
					$thumb = $f_name.".gif";
				elseif(file_exists($imgPath."/".$f_name.".jpg"))
					$thumb = $f_name.".jpg";
				elseif(file_exists($imgPath."/".$f_name.".jpeg"))
					$thumb = $f_name.".jpeg";
				elseif(file_exists($imgPath."/".$f_name.".png"))
					$thumb = $f_name.".png";
				elseif(file_exists($imgPath."/".$f_name.".bmp"))
					$thumb = $f_name.".bmp";
				else
					$thumb = "";

				$key = $path.($path != '' ? '/' : '').$name;
				$arSNIPPETS[$key] = Array(
					'name' => $name,
					'path' => $path,
					'title' => $name,
					'thumb' => $thumb,
					'code' => CSnippets::GetCode($bpPath."/".$name),
					'description' => "",
					'template' => $template,
					'level' => $level,
					'parent' => $parent
				);

				$arKeys[$key] = Array(
					'name' => $name,
					'path' => $path,
					'title' => $name,
					'description' => ""
				);
			}
		}
	}
示例#2
0
 function ReadDir(&$arSNIPPETS, &$arKeys, $path, $template, $level = 0, $parent = "")
 {
     $basePath = $_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/" . $template . "/snippets";
     $io = CBXVirtualIo::GetInstance();
     if (!$io->DirectoryExists($basePath)) {
         return;
     }
     $imagesPath = $basePath . "/images";
     CSnippets::WriteHtaccess($imagesPath);
     $bpPath = $basePath . ($path == "" ? "" : "/") . $path;
     $d = $io->GetDirectory($bpPath);
     $arChildren = $d->GetChildren();
     foreach ($arChildren as $child) {
         $file = $child->GetName();
         if ($file == ".htaccess" || $file == ".content.php" || $level == 0 && $file == "images") {
             continue;
         }
         $filePath = $child->GetPathWithName();
         if ($child->IsDirectory()) {
             $new_path = "" . $path . ($path == "" ? "" : "/") . $file;
             CSnippets::ReadDir($arSNIPPETS, $arKeys, $new_path, $template, $level + 1, $file);
         } else {
             $name = $file;
             $ext = $child->GetExtension();
             // Rename file *.* => *.snp
             if ($ext != 'snp') {
                 $name = str_replace($ext, "snp", $name);
                 if (strpos($name, ".snp") === false) {
                     $name = $name . ".snp";
                 }
                 if (!$io->FileExists($bpPath . "/" . $name)) {
                     $io->Rename($filePath, $bpPath . "/" . $name);
                 } else {
                     for ($n = 1; $n < 256; $n++) {
                         $name_ = str_replace(".snp", "(" . $n . ").snp", $name);
                         if (!$io->FileExists($bpPath . "/" . $name_)) {
                             $name = $name_;
                             $io->Rename($filePath, $bpPath . "/" . $name);
                             break;
                         }
                     }
                 }
             }
             $key = $path . ($path != '' ? '/' : '') . $name;
             $arSNIPPETS[$key] = array('name' => $name, 'path' => $path, 'title' => $name, 'thumb' => '', 'code' => CSnippets::GetCode($bpPath . "/" . $name), 'description' => "", 'template' => $template, 'level' => $level, 'parent' => $parent);
             $arKeys[$key] = array('name' => $name, 'path' => $path, 'title' => $name, 'description' => "");
         }
     }
 }