PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/MakeInstallClass.php

http://ajax-browser.googlecode.com/
PHP | 377 lines | 350 code | 13 blank | 14 comment | 22 complexity | faff9988e6f808d215e7c723de7f52e3 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**--------------------------------------------------
  3. | PHP MAKE INSTALL CLASSES 0.3
  4. | By LOPEZ Alban - Copyright (c) 2007
  5. | Email: alban.lopez+make.install.class@gmail.com
  6. +--------------------------------------------------
  7. | This script has been created and released under
  8. | the GNU GPL and is free to use and redistribute
  9. | only if this copyright statement is not removed
  10. +--------------------------------------------------*/
  11. /// ************ My exemple of use *************
  12. require 'jsmin.php';
  13. $intaller = new MakeIntall (
  14. array
  15. (
  16. 'version' => $_GET['version'],
  17. 'projetName'=> 'AJAX-Browser',
  18. 'addons' => '<li>For PRO Version <b>PHP5.0 is needed</b> but include</li>
  19. <li>Include Archives functions Download/Extract/Infos for <b>ZIP,TAR,GZIP,BZIP2</b></li>
  20. <li><b>EditArea</b> (Real Time Syntax Highlighting Editor) open, editing and saving your sources code by Christophe Dolivet (www.cdolivet.net) 2008.</li>
  21. <li>Since V1.0.00</li>
  22. <li>Firefox and epiphany run perfectly but IE7, Opera, G-Chrome, Konqueror runs partially</li>
  23. <li>Debug <b>Watermark</b> and improve method (now is on the middle and maximized for image fullsize)</li>
  24. <li>Debug <b>mime</b> detection.</li>
  25. <li><b>New Upload manager</b> Inspired By : Evrard Ludovic (Web-Creator.be) 2008.</li>
  26. <li><b>Improve treeView loading time</b> DirSize are loading after treeView.</li>
  27. ',
  28. 'comment' => '-------------------------------------------------
  29. | %name% - by Alban LOPEZ
  30. | Copyright (c) 2007 Alban LOPEZ
  31. | Email bugs/suggestions to alban.lopez@gmail.com
  32. +--------------------------------------------------
  33. | This script has been created and released under
  34. | the GNU GPL and is free to use and redistribute
  35. | only if this copyright statement is not removed
  36. +--------------------------------------------------',
  37. 'includes'=>array('./AJAX-B/','./AJAX-Browser.php','./UnInstall_AJAX-Browser.php'),
  38. 'excludes'=>array('*~','*.conf','*.svn/*','*Mini/*','*Spy/*', '*/Watermark-*.png'),
  39. 'filesName' => array('../AJAX-B_Pro/AJAX-B_%version%.php','./LastVersion.php','../AJAX-B_Pro/LastVersion.php'),
  40. 'no_replace'=>array('*.conf','*.png','*.gif'),
  41. 'miniphpversion'=>'5.0.0',
  42. 'useful'=>array(
  43. 'functions' => array(
  44. 'rmdir'=>'%this% is not aviable on this serveur, it is not possible to remove empty folder.<br/>',
  45. 'unlink'=>'%this% is not aviable on this serveur, it is not possible to remove file.<br/>',
  46. 'zip_open'=>'%this% is not aviable on this serveur, it is not possible to extract *.zip file.<br/>',
  47. 'copy'=>'%this% is not aviable on this serveur, it is not possible to copy file and folder.<br/>',
  48. 'rename'=>'%this% is not aviable on this serveur, it is not possible to rename or move file and folder.<br/>',
  49. 'imagepng'=>'%this% is not aviable on this serveur, it is not possible to view mini picture.<br/>',
  50. 'filesize'=>'%this% is not aviable on this serveur, it is not possible to know file and folder size.<br/>',
  51. 'posix_getpwuid'=>'%this% is not aviable on this serveur, it is not possible to know owner and group.<br/>',
  52. 'mime_content_type'=>'%this% is not aviable on this serveur, it is not possible to know real file type.<br/>',
  53. 'filemtime'=>'%this% is not aviable on this serveur, it is not possible to know the last change time.<br/>',
  54. 'fileperms'=>'%this% is not aviable on this serveur, it is not possible to know file and folder permissions.<br/>',),
  55. 'modules' => array(
  56. 'gd'=>'%this% is not instaled on this serveur, it is not possible view thumbnail.<br/>',
  57. 'bz'=>'%this% is not instaled on this serveur, it is not possible to manage *.bzip2.<br/>',
  58. 'zlib'=>'%this% is not instaled on this serveur, it is not possible to manage *.zip and *.gzip.<br/>',)
  59. ),
  60. 'required'=>array(
  61. 'functions' => array(
  62. 'session_start'=>'%this% is not aviable on this serveur, it is not possible to login in session.<br/>',
  63. 'opendir'=>'%this% is not aviable on this serveur, it is not possible to open and read folder.<br/>',
  64. 'ereg'=>'%this% is not aviable on this serveur, it is not possible to install !<br/>',
  65. 'md5'=>'%this% is not aviable on this serveur, it is not possible to manage password!<br/>',
  66. 'mkdir'=>'%this% is not aviable on this serveur, it is not possible to make a folder (and install) !<br/>',
  67. 'fopen'=>'%this% is not avaible on this serveur, it is not possible to make a folder (and install) !<br/>',
  68. 'fwrite'=>'%this% is not avaible on this serveur, it is not possible to install !<br/>'),
  69. 'modules' => array(
  70. 'session'=>'%this% is not instaled on this serveur, it is not possible to open session!.<br/>')
  71. ),
  72. 'install_onDownload'=>'@mail("alban.lopez@gmail.com", "New Download on : $projetName $version", var_export($_SERVER,true)."\nidentity : ".$identity);',
  73. 'install_onStart'=>'echo "Intalling : $projetName Version : $version <br/>\n";
  74. echo "<b>Add the following page to bookmarks, go to <a href=\"AJAX-Browser.php\">AJAX-Browser</a></b><br/><br/>\n";',
  75. 'install_onFile'=>'echo "OK => $thisFileName<br/>\n";',
  76. 'install_onSkipFile'=>'echo "SKIP => $thisFileName<br/>\n";',
  77. 'install_onSuccessEnd'=>'echo \'<H2><b>Install SUCCESSFULL</b></H2>
  78. <form class="don_link" action="https://www.paypal.com/cgi-bin/webscr" method="post">
  79. <input type="hidden" name="cmd" value="_xclick">
  80. <input type="hidden" name="business" value="alban.lopez@gmail.com">
  81. <input type="hidden" name="item_name" value="Don AJAX-Browser">
  82. <input type="hidden" name="no_shipping" value="1">
  83. <input type="hidden" name="return" value="http://ajaxbrowser.free.fr/">
  84. <input type="hidden" name="currency_code" value="EUR">
  85. <input type="hidden" name="tax" value="0">
  86. <input type="hidden" name="lc" value="FR">
  87. <input type="hidden" name="bn" value="PP-DonationsBF">
  88. <input type="image" src="https://www.paypal.com/fr_FR/i/btn/x-click-but04.gif" border="0" name="submit" alt="Effectuez vos paiements via PayPal : une solution rapide, gratuite et securisee">
  89. <img alt="" border="0" src="https://www.paypal.com/fr_FR/i/scr/pixel.gif" width="1" height="1">
  90. </form>\';
  91. @mail("alban.lopez@gmail.com", "New install on : $projetName $version", $_SERVER[\'SERVER_NAME\'].dirname($_SERVER[\'PHP_SELF\'])."/AJAX-Browser.php\n ".var_export($_SERVER,true)."\n\nSUCCESSFULL !\n\n");',
  92. 'install_onWarningEnd'=>'echo "<H2><b>WARNING !</b></H2>Install warning list :\n";
  93. var_export($warning);',
  94. 'install_onErrorEnd'=>'
  95. echo "<H2><b>ERROR !</b></H2>Install errors list :\n";
  96. var_export($errors);
  97. @mail("alban.lopez@gmail.com", "New install on : $projetName $version", $_SERVER[\'SERVER_NAME\'].dirname($_SERVER[\'PHP_SELF\'])."/AJAX-Browser.php\n".var_export($_SERVER,true)."\n\nWARNING !\n\n".var_export($warning,true)."\n\nERROR !\n\n".var_export($errors,true));',
  98. )
  99. );
  100. echo $intaller->Make();
  101. /// ************ End of My exemple of use *************
  102. /// **************************************************
  103. /// ************** Real code of this class ***************
  104. if (!function_exists('fnmatch'))
  105. {
  106. function fnmatch($pattern, $string)
  107. {
  108. return @preg_match('/^' . strtr(addcslashes($pattern, '/\\.+^$(){}=!<>|'), array('*' => '.*', '?' => '.?')) . '$/i', $string);
  109. }
  110. }
  111. class MakeIntall
  112. {
  113. var $options = array (
  114. 'projetName' => 'PHP MAKE INSTALL CLASSES', // Nom du ou des fichiers resultas (%version% sera remplace par la version)
  115. 'version' => '0.00.01-alpha', // version, sera la reponce a => http://[...]/projetName.php?version
  116. 'filesName' => array('%name% V%version%.php','LastVersion.php'), // Nom du ou des fichiers resultas ( %name% et %version% seront remplace par leur equivalent)
  117. 'comment' => 'You can include your comment here !', // texte brut a inclure au debut du fichier d'install (%version% sera remplace par la version)
  118. 'addons' => '<html><body>First test with : %name% V%version%<br/>- Frist<br/>- Second<br/></body></html>',
  119. // html string, sera la reponce a => http://[...]/projetName.php?addons (%version% sera remplace par la version)
  120. 'install_onDownload'=>'', // Valid PHP code. Variable disponible : $version, $projetName
  121. 'install_onStart'=>'', // Valid PHP code. Variable disponible : $version, $projetName
  122. 'install_onFile'=>'', // Valid PHP code. Variable disponible : $version, $projetName, $thisFileName, $errors[], $warning[]
  123. 'install_onSkipFile'=>'', // Valid PHP code. Variable disponible : $version, $projetName, $thisFileName, $errors[], $warning[]
  124. 'install_onSuccessEnd'=>'', // Valid PHP code. Variable disponible : $version, $projetName, $errors[], $warning[]
  125. 'install_onWarningEnd'=>'', // Valid PHP code. Variable disponible : $version, $projetName, $errors[], $warning[]
  126. 'install_onErrorEnd'=>'', // Valid PHP code. Variable disponible : $version, $projetName, $errors[], $warning[]
  127. 'useful'=>array('functions'=>array(),'modules'=>array()),
  128. 'required'=>array('functions'=>array(),'modules'=>array()),
  129. 'hidden'=>true,
  130. 'mask'=>array('*'), // Liste des masques a apliquer sur le contenu des dossiers
  131. 'includes' => array (), // Liste des fichiers et dossier
  132. 'excludes' => array (), // fichier et dossier exclu de l'archive
  133. 'overwrite' => true, // ecrase ou pas les fichier de destination si deja existant
  134. 'recurse' => true, // parcoure les dossiers de maniere recussive ou non
  135. 'no_replace'=>array(), // masque des fichiers qui ne seront pas remplace lors de la decompression.
  136. );
  137. var $error = array (); // Liste des erreur rencontrees
  138. var $build = array ();
  139. var $files_list = array ();
  140. function MakeIntall($options)
  141. {
  142. foreach ($options as $key => $value)
  143. $this->options[$key] =$value ;
  144. $this->options['projetName'] = str_replace (array('%version%'),array($this->options['version']),$this->options['projetName']);
  145. $this->options['comment'] = str_replace (array('%version%', '%name%'),array($this->options['version'], $this->options['projetName']),$this->options['comment']);
  146. $this->options['addons'] = str_replace (array('%version%', '%name%'),array($this->options['version'], $this->options['projetName']),$this->options['addons']);
  147. foreach ($this->options['filesName'] as $i => $value)
  148. $this->options['filesName'][$i] = str_replace (array('%version%', '%name%'),array($this->options['version'], $this->options['projetName']),$value);
  149. }
  150. function Make ($write=true)
  151. {
  152. $n=count($this->BuildArrayOfFiles());
  153. $this->make_result();
  154. if ($write) $f=$this->write_files();
  155. else $this->download_file();
  156. if (!count($this->error))
  157. return 'Make Succefull !<br>'.$n.' files in '.$this->options['projetName'].'<br>Total size : '.strlen($this->result_file).' Octs<br/>'.
  158. ereg_replace("[a-zA-Z]+://([(]?[)]?[.]?[..]?[a-zA-Z0-9_/-])*", "<a href=\"\\0\">\\0</a>", 'http://'.$_SERVER['SERVER_NAME'].'/'.$f[0]);
  159. else
  160. return '<pre>'.var_export($this->error, true).'</pre>';
  161. }
  162. function BuildArrayOfFiles()
  163. {
  164. foreach ($this->options['includes'] as $items)
  165. {
  166. if (is_dir($items))
  167. {
  168. foreach ($this->options['mask'] as $mask)
  169. $this->build = array_merge($this->build,$this->globr($items,$mask));
  170. }
  171. }
  172. foreach ($this->build as $item)
  173. {
  174. $no = 0;
  175. foreach ($this->options['excludes'] as $out)
  176. if (fnmatch($out, $item)) $no++;
  177. if (!$no && !in_array($item,$this->files_list))
  178. if (strtolower(pathinfo($item,PATHINFO_EXTENSION))=='js')
  179. $this->files_list[$item] = base64_encode(JSMin::minify(file_get_contents($item)));
  180. else
  181. $this->files_list[$item] = base64_encode(file_get_contents($item));
  182. }
  183. foreach ($this->options['includes'] as $item)
  184. {
  185. if (!is_dir($item) && file_exists($item))
  186. if (strtolower(pathinfo($item,PATHINFO_EXTENSION))=='js')
  187. $this->files_list[$item] = base64_encode(JSMin::minify(file_get_contents($item)));
  188. else
  189. $this->files_list[$item] = base64_encode(file_get_contents($item));
  190. }
  191. return $this->files_list;
  192. }
  193. function globr($sDir, $sPattern, $nFlags = NULL)
  194. {
  195. if (!ereg ("/$", $sDir) && is_dir($sDir))
  196. $sDir .= '/';
  197. $aFiles = array();
  198. foreach ($this->options['hidden'] ? array_merge(glob("$sDir.$sPattern", $nFlags),glob("$sDir$sPattern", $nFlags)) : glob("$sDir$sPattern", $nFlags) as $item)
  199. if (!is_dir($item))
  200. $aFiles[] = $item;
  201. $dirlst = $this->options['hidden'] ? array_merge(glob("$sDir.*", GLOB_ONLYDIR),glob("$sDir*", GLOB_ONLYDIR)) : glob("$sDir*", GLOB_ONLYDIR);
  202. foreach ($dirlst as $sSubDir)
  203. {
  204. if (basename($sSubDir) != '.' && basename($sSubDir) != '..')
  205. {
  206. $aSubFiles = $this->globr($sSubDir.'/', $sPattern, $nFlags);
  207. $aFiles = array_merge($aFiles, $aSubFiles);
  208. }
  209. }
  210. return $aFiles;
  211. }
  212. function write_files ($files_lst=array())
  213. {
  214. if (empty($files_lst))
  215. $files_lst = $this->options['filesName'];
  216. foreach ($files_lst as $dest)
  217. if ($handle = fopen($dest, 'w'))
  218. {
  219. if (!fwrite($handle, $this->result_file))
  220. $this->error = 'Writing error on : '.$dest;
  221. fclose($handle);
  222. }
  223. return $this->options['filesName'];
  224. }
  225. function make_result ()
  226. {
  227. $this->result_file =
  228. '<?php
  229. /**'.$this->options['comment'].'*/
  230. $version = \''.$this->options['version'].'\';
  231. $projetName = \''.$this->options['projetName'].'\';
  232. if (!function_exists(\'fnmatch\'))
  233. {
  234. function fnmatch($pattern, $string)
  235. {
  236. return @preg_match(\'/^\' . strtr(addcslashes($pattern, \'/\\\\.+^$(){}=!<>|\'), array(\'*\' => \'.*\', \'?\' => \'.?\')) . \'$/i\', $string);
  237. }
  238. }
  239. if (isset($_GET[\'version\']))
  240. echo $version;
  241. elseif (isset($_GET[\'name\']))
  242. echo $projetName;
  243. elseif (isset($_GET[\'download\']))
  244. {
  245. '.$this->options['install_onDownload'].'
  246. header(\'Content-Type: application/php\');
  247. header(\'Content-Disposition: attachment; filename="\'.basename($_SERVER[\'PHP_SELF\']).\'"\');
  248. header(\'Content-Length: \'.strlen(file_get_contents("./".basename($_SERVER[\'PHP_SELF\']))));
  249. header(\'Content-Transfer-Encoding: binary\');
  250. header(\'Cache-Control: no-cache, must-revalidate, max-age=60\');
  251. header(\'Expires: Sat, 01 Jan 2000 12:00:00 GMT\');
  252. readfile("./".basename($_SERVER[\'PHP_SELF\']));
  253. }
  254. elseif (isset($_GET[\'addons\']))
  255. { ?>
  256. '.$this->options['addons'].'
  257. <?php }
  258. else
  259. {
  260. $lst64 = '.var_export($this->files_list, true).';
  261. $errors = array();
  262. '.$this->options['install_onStart'].'
  263. $useful = '.var_export($this->options['useful'],true).';
  264. $required = '.var_export($this->options['required'],true).';
  265. foreach ($useful[\'functions\'] as $key => $message)
  266. {
  267. if (!function_exists($key))
  268. $warning[] = str_replace(\'%this%\', $key, $message);
  269. }
  270. foreach ($required[\'functions\'] as $key => $message)
  271. {
  272. if (!function_exists($key))
  273. $errors[] = str_replace(\'%this%\', $key, $message);
  274. }
  275. $modules = get_loaded_extensions();
  276. foreach ($useful[\'modules\'] as $key => $message)
  277. {
  278. if (!in_array($key, $modules))
  279. $warning[] = str_replace(\'%this%\', $key, $message);
  280. }
  281. foreach ($required[\'modules\'] as $key => $message)
  282. {
  283. if (!in_array($key, $modules))
  284. $errors[] = str_replace(\'%this%\', $key, $message);
  285. }
  286. if (version_compare(phpversion(), \''.$this->options['miniphpversion'].'\')==-1)
  287. $errors[] = \'You have \'.phpversion().\' but PHP V'.$this->options['miniphpversion'].' or later is required<br/>
  288. Add a <b>.htaccess<b> file in this folder with a line like that<br/>
  289. * FAI = free : <b>php 1</b><br/>
  290. * FAI = 1and1 : <b>AddType x-mapp-php5 .php</b><br/>
  291. * FAI = OVH : <b>SetEnv PHP_VER 5</b><br/>\';
  292. if (empty($errors))
  293. {
  294. foreach ($lst64 as $thisFileName => $data)
  295. {
  296. if (!file_exists($thisFileName) || toBeReplaced($thisFileName))
  297. {
  298. $newDir=\'\';
  299. if (!is_dir(dirname($thisFileName)))
  300. {
  301. foreach(explode(\'/\',dirname($thisFileName)) as $dirPart)
  302. if (!empty($dirPart) && !is_dir($newDir=$newDir.$dirPart.\'/\')) mkdir($newDir);
  303. if (!is_dir(dirname($thisFileName))) $errors[] = "impossible de creer le dossier : ".dirname($thisFileName)."<br>\n";
  304. }
  305. if ($handle = fopen($thisFileName, \'w\'))
  306. {
  307. if (fwrite($handle, base64_decode($data))!==false)
  308. {
  309. '.$this->options['install_onFile'].'
  310. }
  311. else echo ($errors[] = \'Impossible d\\\'ecrire dans \'.$thisFileName."<br>\n");
  312. fclose($handle);
  313. }
  314. else echo ($errors[] = \'Impossible de creer \'.$thisFileName."<br>\n");
  315. }
  316. else
  317. {
  318. '.$this->options['install_onSkipFile'].'
  319. }
  320. }
  321. }
  322. else
  323. echo "<H2><b>Intall Aborted !</b></H2>";
  324. if (!empty($errors))
  325. {
  326. echo "<pre>";
  327. if (!empty($warning))
  328. {
  329. '.$this->options['install_onWarningEnd'].'
  330. }
  331. '.$this->options['install_onErrorEnd'].'
  332. echo "</pre>";
  333. }
  334. else
  335. {
  336. '.$this->options['install_onSuccessEnd'].'
  337. }
  338. }
  339. function toBeReplaced ($url)
  340. {
  341. $noreplace = '.str_replace(array(' ', "\n"), array('', ' '), var_export($this->options['no_replace'], true)).';
  342. foreach ($noreplace as $mask)
  343. if (fnmatch($mask, $url)) return false;
  344. return true;
  345. }
  346. ?>';
  347. return $this->result_file;
  348. }
  349. function download_file()
  350. {
  351. header("Content-Type: application/php");
  352. header('Content-Disposition: attachment; filename="'.$this->options['projetName'].'.php"');
  353. header("Content-Length: " . strlen($this->result_file));
  354. header("Content-Transfer-Encoding: binary");
  355. header("Cache-Control: no-cache, must-revalidate, max-age=60");
  356. header("Expires: Sat, 01 Jan 2000 12:00:00 GMT");
  357. echo ($this->result_file);
  358. exit();
  359. }
  360. }
  361. ?>