Icontem

File: color_palettes/convert_palette_format.php

Recommend this page to a friend!
  Classes of Joseph  >  JS Master Color Picker script  >  color_palettes/convert_palette_format.php  >  Download  
File: color_palettes/convert_palette_format.php
Role: Auxiliary data
Content type: text/plain
Description: converts desktop to-from server formats
Class: JS Master Color Picker script
Pick colors from a palette
Author: By
Last change: added SoftMoon. namespace as needed
Date: 4 years ago
Size: 1,227 bytes
 

Contents

Class file image Download
<?php
$filematch= ($_GET['newFormat']==='desktop') ?  '/^(.+)\.json_palette\.[^.]+$/' : '/^(.+)\.desktop_palette\.[^.]+$/';

$files=getFiles('./');
$targetDir=($_GET['newFormat']==='desktop') ? "./desktop/" : "./json/";
if (!is_dir($targetDir))  mkdir($targetDir);
for ($i=0, $c=count($files);  $i<$c;  $i++)  {
	$F=file_get_contents($files[$i][0]);  echo "===",($files[$i][0]),"===\t→→→\t";
	if ($_GET['newFormat']==='desktop')  {
		if (!preg_match("/^\s*SoftMoon[.]loaded_palettes.push\(/", $F))  $F="SoftMoon.loaded_palettes.push(\n" .$F. ");\n";  }
	else  {
		$F=preg_replace('/^\s*SoftMoon[.]loaded_palettes.push\([\r\n]*/', "",  $F);
		$F=preg_replace('/\);[\r\n]*$/', "", $F);  }
	$name= $targetDir
				.$files[$i][1]
				.(($_GET['newFormat']==='desktop')  ?  ".desktop_palette.js" : ".json_palette.txt");
	echo $name, '<br />';
	file_put_contents($name, $F);  }

function getFiles($dir)  { global $filematch;
	$D=opendir($dir);  $files=array();
	while ($F=readdir($D))  {
		if ($F==='.'  or  $F==='..')  continue;
		if (is_dir($dir.$F))  {$files=array_merge($files, getFiles($dir.$F.'/'));  continue;}
		if (preg_match($filematch, $F, $name))  {$name[0]=$dir.$name[0];  $files[]=$name;}  }
	return $files;  }
?>