99 *
1010 */
1111
12- class WildcardPluginInstaller010202 implements WildcardPluginInstallerInterface010000
12+ class WildcardPluginInstaller010302 implements WildcardPluginInstallerInterface010000
1313{
1414 /**
1515 * @const version
1616 */
17- const VERSION = '1.2 .2 ' ;
17+ const VERSION = '1.3 .2 ' ;
1818
1919 /**
2020 * @var object a copy of the MyBB db object
@@ -145,8 +145,19 @@ public function __construct($path = '')
145145 }
146146 break ;
147147 case 'columns ' :
148+ if ($ db ->engine == 'pgsql ' ) {
149+ $ this ->columns = $ columns ['pgsql ' ];
150+ } else {
151+ unset($ this ->columns ['pgsql ' ]);
152+ }
148153 case 'images ' :
149154 break ;
155+ case 'tables ' :
156+ if ($ db ->engine == 'pgsql ' ) {
157+ $ this ->tables = $ tables ['pgsql ' ];
158+ } else {
159+ unset($ this ->tables ['pgsql ' ]);
160+ }
150161 default :
151162 $ singular = substr ($ key , 0 , strlen ($ key ) - 1 );
152163 $ property = "{$ singular }Names " ;
@@ -216,8 +227,8 @@ protected function addTable($table, $columns)
216227
217228 // create the table if it doesn't already exist
218229 if (!$ this ->tableExists ($ table )) {
219- $ table = TABLE_PREFIX . $ table ;
220- $ this ->db ->write_query ("CREATE TABLE {$ table } ( {$ columnList }) ENGINE= { $ this -> db -> table_type }{ $ collation }; " );
230+ $ queryExtra = ( $ this -> db -> engine == ' pgsql ' ) ? '' : " ENGINE= { $ this -> db -> table_type }{ $ collation }" ;
231+ $ this ->db ->write_query ("CREATE TABLE {$ this -> db -> table_prefix }{ $ table } ( {$ columnList }) { $ queryExtra }; " );
221232 }
222233 }
223234
@@ -256,8 +267,9 @@ protected function removeTables()
256267 return ;
257268 }
258269
259- $ dropList = implode (', ' . TABLE_PREFIX , $ this ->tableNames );
260- $ this ->db ->drop_table ($ dropList );
270+ foreach ($ this ->tableNames as $ table ) {
271+ $ this ->db ->drop_table ($ table );
272+ }
261273 }
262274
263275 /**
@@ -274,17 +286,11 @@ protected function addColumns($columns = '')
274286 }
275287
276288 foreach ($ columns as $ table => $ allColumns ) {
277- $ sep = $ addedColumns = '' ;
278289 foreach ($ allColumns as $ title => $ definition ) {
279290 if (!$ this ->fieldExists ($ table , $ title )) {
280- $ addedColumns .= "{$ sep }{$ title } {$ definition }" ;
281- $ sep = ', ADD ' ;
291+ $ this ->db ->add_column ($ table , $ title , $ definition );
282292 }
283293 }
284- if (strlen ($ addedColumns ) > 0 ) {
285- // trickery, again
286- $ this ->db ->add_column ($ table , $ addedColumns , '' );
287- }
288294 }
289295 }
290296
@@ -302,17 +308,11 @@ protected function removeColumns()
302308 }
303309
304310 foreach ($ this ->columns as $ table => $ columns ) {
305- $ sep = $ droppedColumns = '' ;
306311 foreach ($ columns as $ title => $ definition ) {
307312 if ($ this ->fieldExists ($ table , $ title )) {
308- $ droppedColumns .= "{$ sep }{$ title }" ;
309- $ sep = ', DROP ' ;
313+ $ this ->db ->drop_column ($ table , $ title );
310314 }
311315 }
312- if (strlen ($ droppedColumns ) > 0 ) {
313- // tricky, tricky xD
314- $ result = $ this ->db ->drop_column ($ table , $ droppedColumns );
315- }
316316 }
317317 }
318318
@@ -551,7 +551,7 @@ protected function addStyleSheets()
551551 // now cache the actual files
552552 require_once MYBB_ROOT . "{$ config ['admin_dir ' ]}/inc/functions_themes.php " ;
553553
554- if (!cache_stylesheet (1 , $ data ['cachefile ' ], $ data ['stylesheet ' ]))
554+ if (!cache_stylesheet (1 , $ styleSheet ['cachefile ' ], $ data ['stylesheet ' ]))
555555 {
556556 $ this ->db ->update_query ("themestylesheets " , array ('cachefile ' => "css.php?stylesheet= {$ sid }" ), "sid=' {$ sid }' " , 1 );
557557 }
@@ -663,7 +663,7 @@ protected function addImages()
663663 !mkdir ("{$ path }/images " , 0777 , true )) ||
664664 ($ mainFolder &&
665665 !is_dir ("{$ path }/images {$ mainFolder }" ) &&
666- !mkdir ("{$ path }/images {$ mainFolder }" , 0777 , true ))) {
666+ !$ this -> createContentFolder ("{$ path }/images {$ mainFolder }" ))) {
667667 continue ;
668668 }
669669
@@ -693,7 +693,7 @@ protected function addImages()
693693 if (!is_dir ($ path ) ||
694694 ($ mainFolder &&
695695 !is_dir ("{$ path }{$ mainFolder }" ) &&
696- !mkdir ("{$ path }{$ mainFolder }" , 0777 , true ))) {
696+ !$ this -> createContentFolder ("{$ path }{$ mainFolder }" ))) {
697697 continue ;
698698 }
699699
@@ -770,14 +770,23 @@ protected function buildTableList()
770770 {
771771 global $ config ;
772772
773- $ query = $ this ->db ->write_query ("
774- SHOW TABLES
775- FROM ` {$ config ['database ' ]['database ' ]}`
776- " );
773+ // PostgreSQL requires a little more work to grab the table names
774+ if ($ this ->db ->engine == 'pgsql ' ) {
775+ $ tableArray = $ this ->db ->list_tables ($ config ['database ' ]['database ' ], $ this ->db ->table_prefix );
777776
778- $ tableList = array ();
779- while ($ row = $ this ->db ->fetch_array ($ query )) {
780- $ tableList [array_pop ($ row )] = 1 ;
777+ foreach ($ tableArray as $ table ) {
778+ $ tableList [$ table ] = 1 ;
779+ }
780+ } else {
781+ $ query = $ this ->db ->write_query ("
782+ SHOW TABLES
783+ FROM ` {$ config ['database ' ]['database ' ]}`
784+ " );
785+
786+ $ tableList = array ();
787+ while ($ row = $ this ->db ->fetch_array ($ query )) {
788+ $ tableList [array_pop ($ row )] = 1 ;
789+ }
781790 }
782791 return $ tableList ;
783792 }
@@ -867,6 +876,52 @@ private function buildThemeList($acp = false)
867876
868877 return $ folderList ;
869878 }
879+
880+ /**
881+ * verify that path exists or can be created
882+ *
883+ * @param folder path
884+ * @return bool
885+ */
886+ private function createContentFolder ($ path )
887+ {
888+ if (mkdir ($ path , 0777 , true )) {
889+ file_put_contents ($ path . '/index.html ' , <<<EOF
890+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
891+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
892+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
893+ <head>
894+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
895+ <meta name="robots" content="noindex, nofollow" />
896+ <title>forbidden</title>
897+ <style type="text/css">
898+ body {
899+ background: #F0F0F0;
900+ color: #010101;
901+ font-family: verdana,arial;
902+ font-size: 14px;
903+ font-weight: bold;
904+ }
905+ #msg {
906+ border: 1px solid #F08080;
907+ background: #FFF0F0;
908+ padding: 20px;
909+ margin: 5px;
910+ }
911+ </style>
912+ </head>
913+ <body>
914+ <div id="msg">you don't have permission to access this resource</div>
915+ </body>
916+ </html>
917+ EOF
918+ );
919+
920+ return true ;
921+ }
922+
923+ return false ;
924+ }
870925}
871926
872927?>
0 commit comments