| 1 |
1420
|
Luisehahne
|
<?php
|
| 2 |
|
|
/**
|
| 3 |
|
|
*
|
| 4 |
|
|
* @category module
|
| 5 |
|
|
* @package droplet
|
| 6 |
|
|
* @author Ruud Eisinga (Ruud) John (PCWacht)
|
| 7 |
|
|
* @author WebsiteBaker Project
|
| 8 |
|
|
* @copyright 2004-2009, Ryan Djurovich
|
| 9 |
|
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
| 10 |
|
|
* @link http://www.websitebaker2.org/
|
| 11 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
| 12 |
|
|
* @platform WebsiteBaker 2.8.x
|
| 13 |
|
|
* @requirements PHP 5.2.2 and higher
|
| 14 |
|
|
* @version $Id$
|
| 15 |
|
|
* @filesource $HeadURL$
|
| 16 |
|
|
* @lastmodified $Date$
|
| 17 |
|
|
*
|
| 18 |
|
|
*/
|
| 19 |
1503
|
Luisehahne
|
/* -------------------------------------------------------- */
|
| 20 |
|
|
// Must include code to stop this file being accessed directly
|
| 21 |
|
|
if(!defined('WB_PATH')) {
|
| 22 |
1420
|
Luisehahne
|
|
| 23 |
1503
|
Luisehahne
|
require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
|
| 24 |
|
|
throw new IllegalFileException();
|
| 25 |
|
|
}
|
| 26 |
|
|
/* -------------------------------------------------------- */
|
| 27 |
|
|
|
| 28 |
1540
|
Luisehahne
|
// global $admin;
|
| 29 |
1420
|
Luisehahne
|
|
| 30 |
1540
|
Luisehahne
|
$msg = array();
|
| 31 |
|
|
$sql = 'DROP TABLE IF EXISTS `'.TABLE_PREFIX.'mod_droplets` ';
|
| 32 |
|
|
if( !$database->query($sql) ) {
|
| 33 |
|
|
$msg[] = $database->get_error();
|
| 34 |
|
|
}
|
| 35 |
1420
|
Luisehahne
|
|
| 36 |
1540
|
Luisehahne
|
$sql = 'CREATE TABLE IF NOT EXISTS `'.TABLE_PREFIX.'mod_droplets` ( ';
|
| 37 |
|
|
$sql .= '`id` INT NOT NULL auto_increment, ';
|
| 38 |
|
|
$sql .= '`name` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, ';
|
| 39 |
|
|
$sql .= '`code` LONGTEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL , ';
|
| 40 |
|
|
$sql .= '`description` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, ';
|
| 41 |
|
|
$sql .= '`modified_when` INT NOT NULL default \'0\', ';
|
| 42 |
|
|
$sql .= '`modified_by` INT NOT NULL default \'0\', ';
|
| 43 |
|
|
$sql .= '`active` INT NOT NULL default \'0\', ';
|
| 44 |
|
|
$sql .= '`admin_edit` INT NOT NULL default \'0\', ';
|
| 45 |
|
|
$sql .= '`admin_view` INT NOT NULL default \'0\', ';
|
| 46 |
|
|
$sql .= '`show_wysiwyg` INT NOT NULL default \'0\', ';
|
| 47 |
|
|
$sql .= '`comments` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, ';
|
| 48 |
|
|
$sql .= 'PRIMARY KEY ( `id` ) ';
|
| 49 |
|
|
$sql .= ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
|
| 50 |
|
|
if( !$database->query($sql) ) {
|
| 51 |
|
|
$msg[] = $database->get_error();
|
| 52 |
|
|
}
|
| 53 |
1420
|
Luisehahne
|
|
| 54 |
1540
|
Luisehahne
|
//add all droplets from the droplet subdirectory
|
| 55 |
|
|
$folder=opendir(WB_PATH.'/modules/droplets/example/.');
|
| 56 |
|
|
$names = array();
|
| 57 |
|
|
while ($file = readdir($folder)) {
|
| 58 |
|
|
$ext=strtolower(substr($file,-4));
|
| 59 |
|
|
if ($ext==".php"){
|
| 60 |
|
|
if ($file<>"index.php" ) {
|
| 61 |
|
|
$names[count($names)] = $file;
|
| 62 |
|
|
}
|
| 63 |
1420
|
Luisehahne
|
}
|
| 64 |
|
|
}
|
| 65 |
1540
|
Luisehahne
|
closedir($folder);
|
| 66 |
1420
|
Luisehahne
|
|
| 67 |
1540
|
Luisehahne
|
foreach ($names as $dropfile)
|
| 68 |
|
|
{
|
| 69 |
|
|
$droplet = addslashes(getDropletCodeFromFile($dropfile));
|
| 70 |
|
|
if ($droplet != "")
|
| 71 |
|
|
{
|
| 72 |
|
|
$description = "Example Droplet";
|
| 73 |
|
|
$comments = "Example Droplet";
|
| 74 |
|
|
$cArray = explode("\n",$droplet);
|
| 75 |
|
|
if (substr($cArray[0],0,3) == "//:") {
|
| 76 |
|
|
$description = trim(substr($cArray[0],3));
|
| 77 |
|
|
array_shift ( $cArray );
|
| 78 |
|
|
}
|
| 79 |
|
|
if (substr($cArray[0],0,3) == "//:") {
|
| 80 |
|
|
$comments = trim(substr($cArray[0],3));
|
| 81 |
|
|
array_shift ( $cArray );
|
| 82 |
|
|
}
|
| 83 |
|
|
$droplet = implode ( "\n", $cArray );
|
| 84 |
|
|
$name = substr($dropfile,0,-4);
|
| 85 |
|
|
$modified_when = time();
|
| 86 |
1544
|
Luisehahne
|
$modified_by = (method_exists($admin, 'get_user_id') && ($admin->get_user_id()!=null) ? $admin->get_user_id() : 1);
|
| 87 |
1540
|
Luisehahne
|
$sql = 'INSERT INTO `'.TABLE_PREFIX.'mod_droplets` SET ';
|
| 88 |
|
|
$sql .= '`name` = \''.$name.'\', ';
|
| 89 |
|
|
$sql .= '`code` = \''.$droplet.'\', ';
|
| 90 |
|
|
$sql .= '`description` = \''.$description.'\', ';
|
| 91 |
|
|
$sql .= '`comments` = \''.$comments.'\', ';
|
| 92 |
|
|
$sql .= '`active` = 1, ';
|
| 93 |
|
|
$sql .= '`modified_when` = '.$modified_when.', ';
|
| 94 |
|
|
$sql .= '`modified_by` = '.$modified_by;
|
| 95 |
|
|
if( !$database->query($sql) ) {
|
| 96 |
|
|
$msg[] = $database->get_error();
|
| 97 |
|
|
}
|
| 98 |
|
|
// do not output anything if this script is called during fresh installation
|
| 99 |
|
|
// if (method_exists($admin, 'get_user_id')) echo "Droplet import: $name<br/>";
|
| 100 |
1420
|
Luisehahne
|
}
|
| 101 |
1540
|
Luisehahne
|
}
|
| 102 |
|
|
|
| 103 |
|
|
function getDropletCodeFromFile ( $dropletfile ) {
|
| 104 |
|
|
$data = '';
|
| 105 |
|
|
$filename = WB_PATH."/modules/droplets/example/".$dropletfile;
|
| 106 |
|
|
if (file_exists($filename)) {
|
| 107 |
|
|
$filehandle = fopen ($filename, "r");
|
| 108 |
|
|
$data = fread ($filehandle, filesize ($filename));
|
| 109 |
|
|
fclose($filehandle);
|
| 110 |
|
|
// unlink($filename); doesnt work in unix
|
| 111 |
1420
|
Luisehahne
|
}
|
| 112 |
1540
|
Luisehahne
|
return $data;
|
| 113 |
1503
|
Luisehahne
|
}
|