Location: PHPKode > projects > WebMachinek > WMinst-0.62/upload.php
<?php
$urlpublic = "http://pc195025.stofanet.dk/public";
$urlinternal = "http://pc195025.stofanet.dk/private";
$dbase = "nova";
$dbuser = "apache";
$dbsuperuser = "mypostgres";
$general = "/home/apache/htdocs/public";
$internal = "/home/apache/htdocs/private";

################################################
#### YOU DON'T NEED TO TOUCH THE CODE BELLOW ###
################################################

exec ("./upload.sh $internal $general");

$conn = pg_connect("dbname=template1 user=$dbuser port=5432");
pg_exec($conn, "CREATE DATABASE $dbase");
pg_close($conn);

$conn = pg_connect("dbname=$dbase user=$dbuser port=5432");
pg_exec($conn, 'CREATE TABLE "category" (
           "dir" text NOT NULL,
           "pos" int4 DEFAULT 0);');
pg_exec($conn, 'CREATE TABLE "page" (
           "file" text NOT NULL, 
           "dir" text NOT NULL,
           "page_pos" int4 DEFAULT 1 NOT NULL,
           "created" timestamp DEFAULT now(),
           "modified" timestamp DEFAULT now() NOT NULL,
           "child" bool DEFAULT bool \'f\',
           "visible" bool DEFAULT bool \'t\');');
pg_exec($conn, 'CREATE TABLE "page_descr" (
           "file" text NOT NULL,
           "dir" text NOT NULL,
           "nav" text NOT NULL,
           "title" text,
           "descr" text,
           "keyword" text);');
pg_exec($conn, 'CREATE TABLE "page_layout" (
           "file" text NOT NULL,
           "dir" text NOT NULL,
           "layout" text DEFAULT \'default\' NOT NULL);');
pg_close($conn);



$conn = pg_connect("dbname=$dbase user=$dbsuperuser port=5432");
pg_exec($conn,"COPY category FROM '$internal/category.sql' USING DELIMITERS '|';");
pg_exec($conn,"COPY page FROM '$internal/page.sql' USING DELIMITERS '|'; ");
pg_exec($conn,"COPY page_descr FROM '$internal/page_descr.sql' USING DELIMITERS '|'; ");
pg_exec($conn,"COPY page_layout FROM '$internal/page_layout.sql' USING DELIMITERS '|'; ");
pg_close($conn);

#########################################################
############# UPDATE (INSTALL VERSION)
#########################################################
function startpage ($file, $dir, $child, $edit, $path) {
global $general;
$phpsource = "<?php\n".
"require(\"$general/.sys/.conf.php\");\n".
'$file = "'."$file\";\n".
'$dir = "'."$dir\";\n".
'$child = "'."$child\";\n".
'$edit = "'."$edit\";\n".
"require(\"\$general/.sys/wm.php\");\nphp?>";
$fp1 = fopen("$path", "w");
fwrite($fp1, $phpsource);
fclose($fp1);
}

function dynimage ($napis, $path) {
global $general;
global $font;
global $color;
$napis = ereg_replace('»','&#357;', $napis);
$napis = ereg_replace('Ì','&#282;', $napis);
$napis = ereg_replace('©','&#352;', $napis);
$napis = ereg_replace('®','&#381;', $napis);
$napis = ereg_replace('Ø','&#344;', $napis);
$napis = ereg_replace('Ï','&#270;', $napis);
$napis = ereg_replace('«','&#356;', $napis);
$napis = ereg_replace('¹','&#353;', $napis);
$napis = ereg_replace('¾','&#382;', $napis);
$fp = fopen($path, "w+");
$image = "<?php\n";
$image .= 'Header("Content-type: image/gif");'."\n";
$image .= "require('$general/.sys/.conf.php');\n";
$image .= "\$mes = ImageTTFBBox(38, 0, \$font, \"$napis\");\n";
$image .= "\$width = \$mes[2]+11;\n";
$image .= '$im = ImageCreate($width,40);'."\n";
$image .= '$pozadi = ImageColorAllocate($im, 250,220,210);'."\n";
$image .= '$transparent = ImageColorTransparent($im, $pozadi);'."\n";
$image .= '$colored = ImageColorAllocate($im, $R, $G, $B);'."\n";
$image .= 'ImageTTFText($im, 38, 0, 2, 32, $colored, $font,'." \"$napis\");\n";
$image .= 'ImageGif($im);'."\n";
$image .= 'ImageDestroy($im);'."\n".'php?>'."\n";
fwrite($fp, $image);
fclose($fp);
}


################# QUERY FOR DATA IN POSTGRESQL
$conn = pg_connect("dbname=$dbase user=$dbuser port=5432");
$prikaz1 = "SELECT page_descr.dir, page_descr.file, page_descr.title, page.child FROM page_descr, page WHERE page_descr.dir=page.dir AND page_descr.file=page.file ORDER BY dir";
$dotaz1 = pg_exec($conn, $prikaz1);
$pocetSouboru = pg_numrows($dotaz1);
  echo $pocetSouboru;
for ($i = 0; $i < $pocetSouboru; $i++) {
    $radek = pg_fetch_array($dotaz1, $i);
    $path[$i] = "$general/$radek[0]/$radek[1]";
    $pathloc[$i] = "$internal/$radek[0]/$radek[1]";
    $repos[$i] = "$internal/.repos/$radek[0]/$radek[1]";
    $title[$i] = $radek[2];
    $child[$i] = $radek[3];
    $file[$i] = $radek[1];
    $dir[$i] = $radek[0];
    
}

pg_close($conn);

############# CHECK FOLDERS, WRITING FOLDERS AND FILES!

$index = "index";

if(!is_dir("$internal/.repos")) {
mkdir("$internal/.repos", 0755);
}

##PUBLIC
for ($i = 0; $i < $pocetSouboru; $i++) {
$directory = dirname($path[$i]);

$slash = strstr($dir[$i], "/");

if ($slash == ""){ 	###1 WRITING PAGES NOT IN SUBCATEGORY

if (is_dir($directory)) {	###1.1 CATEGORY WITH EXISTING FOLDER
	if ($file[$i] == $index) { #1.1.1 MAIN PAGE
		startpage ($file[$i], $dir[$i], $child[$i], "f", "$path[$i].php");
		dynimage($title[$i], "$path[$i]_img.php");
		}
	elseif  (is_dir($path[$i])){ #1.1.2  PAGE WITH EXISTING FOLDER
		$indexpath = "$path[$i]/index.php";
		startpage ($file[$i], $dir[$i], $child[$i], "f", $indexpath);
		dynimage($title[$i], "$path[$i]/$file[$i]_img.php");
		}
	else { #1.1.3  PAGE WITHOUT FOLDER
		mkdir ($path[$i], 0755);
		exec("ln -s $general/.img $path[$i]/.img");
		$indexpath = "$path[$i]/index.php";
		startpage ($file[$i], $dir[$i], $child[$i], "f", $indexpath);
		dynimage($title[$i], "$path[$i]/$file[$i]_img.php");
		}

} else {				###1.2  NO FOLDER FOR CATEGORY
	mkdir ($directory, 0755);
	exec("ln -s $general/.img $directory/.img");
	if ($file[$i] == $index) { 	#1.2.1 MAIN PAGE
		startpage ($file[$i], $dir[$i], $child[$i], "f", "$path[$i].php");
		dynimage($title[$i], "$path[$i]_img.php");
		}
	else { 				#1.2.2 PAGE WITHOUT FOLDER
		mkdir ($path[$i], 0755);
		exec("ln -s $general/.img $path[$i]/.img");
		startpage ($file[$i], $dir[$i], $child[$i], "f", "$path[$i]/index.php");
		dynimage($title[$i], "$path[$i]/$file[$i]_img.php");
		}
}
} else {		###2 WRITING FILES IN SUBCATEGORIES (WORK BECAUSE QUERY IS ORDER BY dir)
	startpage ($file[$i], $dir[$i], $child[$i], "f", "$path[$i].php");
	dynimage($title[$i], "$path[$i]_img.php");
	}
}

##LOCAL
for ($i = 0; $i < $pocetSouboru; $i++) {
$directory = dirname($pathloc[$i]);
$slash = strstr($dir[$i], "/");

if ($slash == ""){ 	###1 WRITING FILES OUT OF ANY SUBCATEGORY

if (is_dir($directory)) {	###1.1 CATEGORY WITH EXISTING FOLDER
	if ($file[$i] == $index) { #1.1.1 MAIN PAGE
		startpage ($file[$i], $dir[$i], $child[$i], "t", "$pathloc[$i].php");
		dynimage($title[$i], "$pathloc[$i]_img.php");
		}
	elseif  (is_dir($pathloc[$i])){ #1.1.2  PAGE WITH EXISTING FOLDER
		$indexpath = "$pathloc[$i]/index.php";
		startpage ($file[$i], $dir[$i], $child[$i], "t", $indexpath);
		dynimage($title[$i], "$pathloc[$i]/$file[$i]_img.php");
		}
	else { #1.1.3  PAGE WITHOUT FOLDER
		mkdir ($pathloc[$i], 0755);
		exec("ln -s $general/.img $pathloc[$i]/.img");
		$indexpath = "$pathloc[$i]/index.php";
		startpage ($file[$i], $dir[$i], $child[$i], "t", $indexpath);
		dynimage($title[$i], "$pathloc[$i]/$file[$i]_img.php");
		}

} else {				###1.2  NO FOLDER FOR CATEGORY
	mkdir ($directory, 0755);
	exec("ln -s $general/.img $directory/.img");
	if ($file[$i] == $index) { 	#1.2.1 MAIN PAGE
		startpage ($file[$i], $dir[$i], $child[$i], "t", "$pathloc[$i].php");
		dynimage($title[$i], "$pathloc[$i]_img.php");
		}
	else { 				#1.2.2 PAGE WITHOUT FOLDER
		mkdir ($pathloc[$i], 0755);
		exec("ln -s $general/.img $pathloc[$i]/.img");
		startpage ($file[$i], $dir[$i], $child[$i], "t", "$pathloc[$i]/index.php");
		dynimage($title[$i], "$pathloc[$i]/$file[$i]_img.php");
		}
}
} else {		###2 WRITING FILES IN SUBCATEGORIES (WORK BECAUSE QUERY IS ORDER BY dir)
	startpage ($file[$i], $dir[$i], $child[$i], "t", "$pathloc[$i].php");
	dynimage($title[$i], "$pathloc[$i]_img.php");
	}
}

echo "WELL DONE<br />YOU HAVE TO EDIT .conf FILE!!!";
php?>
Return current item: WebMachinek