1111 */
1212
1313if (!function_exists ('importDropletFromZip ' )) {
14- /**
15- * importDropletFromZip
16- * @param string $sZipPath - full path to your droplets zip-file e.g. __DIR__.'/droplets/droplets.zip'
17- * @param string $sTempDir - optional; full path to temporary unzip folder e.g. !must be writeable
18- */
19- function importDropletFromZip ($ sZipPath , $ sTempDir = '' , $ bDeleteTemp = true )
20- {
21- $ errors = array ();
22- $ count = 0 ;
23- $ aReturn = array ();
24-
25- $ sTempDir = $ sTempDir != '' ? $ sTempDir : WB_PATH .'/temp/droplets/ ' ;
26- if (!file_exists ($ sTempDir )) mkdir ($ sTempDir , 0777 , true );
27-
28- $ oZip = new ZipArchive ;
29- if ($ oZip ->open ($ sZipPath ) === TRUE ) {
30- $ oZip ->extractTo ($ sTempDir );
31- $ oZip ->close ();
32- }
33-
34- // now, open the temp directory
35- if (false !== ($ dh = opendir ($ sTempDir ))) {
36- while (false !== ($ sFile = readdir ($ dh )))
37- {
38- // read trough all the files in temp directory
39- if ($ sFile != ". " && $ sFile != ".. " ) {
40- $ feedback = importDropletFromFile ($ sFile , $ sTempDir ); // use import droplet function
41- $ imports [$ feedback ['imported ' ]] = $ feedback ['imported ' ];
42- if (isset ($ feedback ['error ' ])){
43- $ errors [$ feedback ['imported ' ]] = $ feedback ['error ' ];
44- }else {
45- $ count ++;
46- }
14+ /**
15+ * importDropletFromZip
16+ * @param string $sZipPath - full path to your droplets zip-file e.g. __DIR__.'/droplets/droplets.zip'
17+ * @param string $sTempDir - optional; full path to temporary unzip folder e.g. !must be writeable
18+ */
19+ function importDropletFromZip ($ sZipPath , $ sTempDir = '' , $ bDeleteTemp = true )
20+ {
21+ $ errors = array ();
22+ $ count = 0 ;
23+ $ aReturn = array ();
24+
25+ $ sTempDir = $ sTempDir != '' ? $ sTempDir : WB_PATH . '/temp/droplets/ ' ;
26+ if (!file_exists ($ sTempDir ))
27+ mkdir ($ sTempDir , 0777 , true );
28+
29+ $ oZip = new ZipArchive ;
30+ if ($ oZip ->open ($ sZipPath ) === TRUE ) {
31+ $ oZip ->extractTo ($ sTempDir );
32+ $ oZip ->close ();
4733 }
48- }
49- closedir ($ dh );
34+
35+ // now, open the temp directory
36+ if (false !== ($ dh = opendir ($ sTempDir ))) {
37+ while (false !== ($ sFile = readdir ($ dh ))) {
38+ // read trough all the files in temp directory
39+ if ($ sFile != ". " && $ sFile != ".. " ) {
40+ $ feedback = importDropletFromFile ($ sFile , $ sTempDir ); // use import droplet function
41+ $ imports [$ feedback ['imported ' ]] = $ feedback ['imported ' ];
42+ if (isset ($ feedback ['error ' ])) {
43+ $ errors [$ feedback ['imported ' ]] = $ feedback ['error ' ];
44+ } else {
45+ $ count ++;
46+ }
47+ }
48+ }
49+ closedir ($ dh );
50+ }
51+ if (!isset ($ imports )) {
52+ $ imports = array ();
53+ }
54+ if ($ bDeleteTemp == true ) {
55+ rm_full_dir ($ sTempDir ); // wb internal function
56+ }
57+ return array (
58+ 'count ' => $ count ,
59+ 'errors ' => $ errors ,
60+ 'imported ' => $ imports
61+ );
5062 }
51- if (!isset ($ imports )){
52- $ imports = array ();
53- }
54- if ($ bDeleteTemp == true ){
55- rm_full_dir ($ sTempDir ); // wb internal function
56- }
57- return array (
58- 'count ' => $ count ,
59- 'errors ' => $ errors ,
60- 'imported ' => $ imports
61- );
62- }
6363}
6464
65- if (!function_exists ('importDropletFromFile ' )) {
66- /**
67- * importDropletFromFile
68- * @param string $sZipPath - full path to your droplets zip-file e.g. __DIR__.'/droplets/droplets.zip'
69- * @param string $sTempDir - optional; full path to temporary unzip folder e.g. !must be writeable
70- */
71- function importDropletFromFile ($ sFilename = '' , $ sDirPath = '' )
72- {
73- global $ database , $ admin ;
74- $ description = '' ;
75- $ usage = '' ;
76- $ code = '' ;
77- if ($ sDirPath == '' && is_readable ($ sFilename )){
78- $ sDirPath = dirname ($ sFilename );
79- $ sFilename = basename ($ sFilename );
80- }
81- $ aReturn = array ();
82- if (preg_match ('/^(.*)\.php$/i ' , $ sFilename , $ name_match )) {
83- // Name of the Droplet = Filename
84- $ name = $ name_match [1 ];
85- // Slurp file contents
86-
87- $ aLines = file ($ sDirPath . '/ ' . $ sFilename );
88- if (strpos ($ aLines [0 ], '<?php ' ) !== false ){
89- array_shift ($ aLines );
90- }
91- // First line: Description
92- if (preg_match ('#^//\:(.*)$# ' , $ aLines [0 ], $ match )) {
93- $ description = $ match [1 ];
94- }
95- // Second line: Usage instructions
96- if (preg_match ('#^//\:(.*)$# ' , $ aLines [1 ], $ match )) {
97- $ aBreaks = array ("<br /> " , "<br/> " , "<br> " );
98- $ match [1 ] = str_ireplace ($ aBreaks , "\r\n" , $ match [1 ]);
99- $ usage = addslashes ($ match [1 ]);
100- }
101- // Remaining: Droplet code
102- $ code = implode ('' , array_slice ($ aLines , 2 ));
103- // replace 'evil' chars in code
104- $ tags = array (
105- '<?php ' ,
106- '?> ' ,
107- '<? '
108- );
109- $ code = addslashes (str_replace ($ tags , '' , $ code ));
110- // Already in the DB?
111- $ stmt = 'INSERT ' ;
112- $ id = NULL ;
113- $ found = $ database ->get_one ("SELECT * FROM ` " .TABLE_PREFIX ."mod_droplets` WHERE name=' $ name' " );
114- if ($ found && $ found > 0 ) {
115- $ stmt = 'REPLACE ' ;
116- $ id = $ found ;
117- }
118- // execute
119- $ result = $ database ->query ("$ stmt INTO ` " .TABLE_PREFIX ."mod_droplets` VALUES(
120- ' $ id', ' $ name', ' $ code', ' $ description', ' " .time ()."', ' " . $ admin ->get_user_id () . "', 1, 0, 0, 0, ' $ usage'
65+ if (!function_exists ('importDropletFromFile ' )) {
66+ /**
67+ * importDropletFromFile
68+ * @param string $sZipPath - full path to your droplets zip-file e.g. __DIR__.'/droplets/droplets.zip'
69+ * @param string $sTempDir - optional; full path to temporary unzip folder e.g. !must be writeable
70+ */
71+ function importDropletFromFile ($ sFilename = '' , $ sDirPath = '' )
72+ {
73+ global $ database , $ admin ;
74+ $ description = '' ;
75+ $ usage = '' ;
76+ $ code = '' ;
77+ if ($ sDirPath == '' && is_readable ($ sFilename )) {
78+ $ sDirPath = dirname ($ sFilename );
79+ $ sFilename = basename ($ sFilename );
80+ }
81+ $ aReturn = array ();
82+ if (preg_match ('/^(.*)\.php$/i ' , $ sFilename , $ name_match )) {
83+ // Name of the Droplet = Filename
84+ $ name = $ name_match [1 ];
85+ // Slurp file contents
86+
87+ $ aLines = file ($ sDirPath . '/ ' . $ sFilename );
88+ if (strpos ($ aLines [0 ], '<?php ' ) !== false ) {
89+ array_shift ($ aLines );
90+ }
91+ // First line: Description
92+ if (preg_match ('#^//\:(.*)$# ' , $ aLines [0 ], $ match )) {
93+ $ description = $ match [1 ];
94+ }
95+ // Second line: Usage instructions
96+ if (preg_match ('#^//\:(.*)$# ' , $ aLines [1 ], $ match )) {
97+ $ aBreaks = array (
98+ "<br /> " ,
99+ "<br/> " ,
100+ "<br> "
101+ );
102+ $ match [1 ] = str_ireplace ($ aBreaks , "\r\n" , $ match [1 ]);
103+ $ usage = addslashes ($ match [1 ]);
104+ }
105+ // Remaining: Droplet code
106+ $ code = implode ('' , array_slice ($ aLines , 2 ));
107+ // replace 'evil' chars in code
108+ $ tags = array (
109+ '<?php ' ,
110+ '?> ' ,
111+ '<? '
112+ );
113+ $ code = addslashes (str_replace ($ tags , '' , $ code ));
114+ // Already in the DB?
115+ $ stmt = 'INSERT ' ;
116+ $ id = NULL ;
117+ $ found = $ database ->get_one ("SELECT * FROM ` " . TABLE_PREFIX . "mod_droplets` WHERE name=' $ name' " );
118+ if ($ found && $ found > 0 ) {
119+ $ stmt = 'REPLACE ' ;
120+ $ id = $ found ;
121+ }
122+ // execute
123+ $ result = $ database ->query ("$ stmt INTO ` " . TABLE_PREFIX . "mod_droplets` VALUES(
124+ ' $ id', ' $ name', ' $ code', ' $ description', ' " . time () . "', ' " . $ admin ->get_user_id () . "', 1, 0, 0, 0, ' $ usage'
121125 ) " );
122- $ aReturn ['imported ' ] = $ name ;
123- if ($ database ->is_error ()) {
124- $ aReturn ['error ' ] = $ database ->get_error ();
125- }
126- }
127- return $ aReturn ;
128- }
126+ $ aReturn ['imported ' ] = $ name ;
127+ if ($ database ->is_error ()) {
128+ $ aReturn ['error ' ] = $ database ->get_error ();
129+ }
130+ }
131+ return $ aReturn ;
132+ }
129133}
130-
131-
132- if (!function_exists ('isDroplet ' )){
133- /**
134- * simple check if Droplet is already installed
135- * isDroplet
136- * @param string Droplet Name
137- */
138- function isDroplet ($ sDropletName ){
139- $ tmp = $ GLOBALS ['database ' ]->get_one (
140- "SELECT `id` FROM ` " .TABLE_PREFIX ."mod_droplets`
141- WHERE `name` = ' " .$ sDropletName ."' "
142- );
143- return (is_numeric ($ tmp )) ? intval ($ tmp ) : false ;
144- }
134+
135+
136+ if (!function_exists ('isDroplet ' )) {
137+ /**
138+ * simple check if Droplet is already installed
139+ * isDroplet
140+ * @param string Droplet Name
141+ */
142+ function isDroplet ($ sDropletName )
143+ {
144+ $ tmp = $ GLOBALS ['database ' ]->get_one ("SELECT `id` FROM ` " . TABLE_PREFIX . "mod_droplets`
145+ WHERE `name` = ' " . $ sDropletName . "' " );
146+ return (is_numeric ($ tmp )) ? intval ($ tmp ) : false ;
147+ }
145148}
0 commit comments