install.php

Go to the documentation of this file.
00001 <?php
00002 
00033 require_once('domit/xml_domit_include.php');
00034 require_once('domit/xml_domit_utilities.php');
00035 require_once('embient.util.php');
00036 
00038 define('XMLINST', 'install.xml');
00039 
00041 define('INSTMAINSEC', 'embient');
00042 
00043 // -----------------------------------------------------------------------------------
00044 // Begin of Main
00045 // -----------------------------------------------------------------------------------
00046 
00047 // server's doc root
00048 $docroot = $_SERVER['DOCUMENT_ROOT'];
00049 
00050 // embient's root
00051 $embient_dir = dirname(__FILE__);
00052 
00053 // load scripts from install.xml
00054 $script = embient_load_install();
00055 
00056 // execute them!
00057 foreach ( $script as $system => $sc )
00058 {
00059   $dir = embient_search($docroot, $sc['detector']['filename'], $sc['detector']['signature']);
00060 
00061   if ( ! empty($dir) )
00062   {
00063     echo "Found $system in $dir. Installing Embient for $system<br>";
00064     flush();
00065 
00066     if ( ! empty($sc['create']) )
00067     {
00068       eval("\$content = \"". $sc['create']['content'] ."\";");
00069       embient_create("$dir/". $sc['create']['filename'], $content);
00070     }
00071 
00072     if ( ! empty($sc['append']) )
00073     {
00074       eval("\$content = \"". $sc['append']['content'] ."\";");
00075       embient_append("$dir/". $sc['append']['filename'], $content);
00076     }
00077   }
00078 }
00079 
00080 echo "Done!";
00081 
00082 // -----------------------------------------------------------------------------------
00083 // End of Main
00084 // -----------------------------------------------------------------------------------
00085 
00099 function embient_search($dir, $name, $sig)
00100 {
00101   global $embient_dir;
00102 
00103   $curdir = getcwd();
00104   chdir($dir);
00105 
00106   foreach ( glob("*") as $filename )
00107   {
00108     // excluding embient's directory
00109     if ( $filename == basename($dir) )
00110     {
00111       continue;
00112     }
00113 
00114     // we found a directory, dig into it
00115     if ( is_dir($filename) )
00116     {
00117       $nextlevel = embient_search("$dir/$filename", $name, $sig);
00118 
00119       if ( ! empty($nextlevel) )
00120       {
00121         return $nextlevel;
00122       }
00123     }
00124 
00125     if ( $filename != $name )
00126     {
00127       continue;
00128     }
00129 
00130     // check the signature
00131     $content = implode("", file("$dir/$filename"));
00132 
00133     if ( strstr($content, $sig) )
00134     {
00135       return "$dir";
00136     }
00137   }
00138 
00139   chdir($curdir);
00140   return false;
00141 }
00142 
00143 
00157 function embient_append($filename, $content)
00158 {
00159   if ( ! file_exists($filename) )
00160   {
00161     embient_create($filename, $content);
00162     return;
00163   }
00164 
00165   $orig   = file($filename);
00166   $output = array();
00167   $added  = false;
00168 
00169   foreach ($orig as $line)
00170   {
00171     $line = rtrim($line);
00172 
00173     if ( strstr($line, "<?") )
00174     {
00175       continue;
00176     }
00177 
00178     if ( strstr($line, "?>") )
00179     {
00180       $output = array_merge($output, $content);
00181       $added  = true;
00182       break;
00183     }
00184 
00185     array_push($output, $line);
00186   }
00187 
00188   if ( ! $added )
00189   {
00190       $output = array_merge($output, $content);
00191   }
00192 
00193   $str = implode("\n", $output);
00194 
00195   embient_create($filename, $str);
00196 }
00197 
00198 
00214 function embient_create($filename, $content)
00215 {
00216   $file = fopen("$filename", "w");
00217   fwrite($file, "<?php\n");
00218   fwrite($file, "$content\n");
00219   fwrite($file, "?>");
00220   fclose($file);
00221 }
00222 
00229 function embient_load_install()
00230 {
00231   global $embient_dir;
00232 
00233   $xmlinst = new DOMIT_Document(); //instance of a DOMIT! document
00234 
00235   if ( ! $xmlinst->loadXML("$embient_dir/". XMLINST) )
00236   {
00237     embient_error("Cannot load installation file - ". $xmlinst->getErrorString());
00238     return array();
00239   }
00240 
00241   return embient_create_XML_tree($xmlinst->documentElement);
00242 }

Generated on Fri Feb 10 15:05:54 2006 for Embient by  doxygen 1.4.6-NO