[4410] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[4410] | 4 | // +-----------------------------------------------------------------------+ |
---|
[12922] | 5 | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | |
---|
[4410] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
| 23 | |
---|
| 24 | /** |
---|
| 25 | * loads an sql file and executes all queries |
---|
| 26 | * |
---|
| 27 | * Before executing a query, $replaced is... replaced by $replacing. This is |
---|
| 28 | * useful when the SQL file contains generic words. Drop table queries are |
---|
| 29 | * not executed. |
---|
| 30 | * |
---|
| 31 | * @param string filepath |
---|
| 32 | * @param string replaced |
---|
| 33 | * @param string replacing |
---|
| 34 | * @return void |
---|
| 35 | */ |
---|
[5982] | 36 | function execute_sqlfile($filepath, $replaced, $replacing, $dblayer) |
---|
[4410] | 37 | { |
---|
| 38 | $sql_lines = file($filepath); |
---|
| 39 | $query = ''; |
---|
| 40 | foreach ($sql_lines as $sql_line) |
---|
| 41 | { |
---|
| 42 | $sql_line = trim($sql_line); |
---|
| 43 | if (preg_match('/(^--|^$)/', $sql_line)) |
---|
| 44 | { |
---|
| 45 | continue; |
---|
| 46 | } |
---|
| 47 | $query.= ' '.$sql_line; |
---|
| 48 | // if we reached the end of query, we execute it and reinitialize the |
---|
| 49 | // variable "query" |
---|
| 50 | if (preg_match('/;$/', $sql_line)) |
---|
| 51 | { |
---|
| 52 | $query = trim($query); |
---|
| 53 | $query = str_replace($replaced, $replacing, $query); |
---|
| 54 | // we don't execute "DROP TABLE" queries |
---|
| 55 | if (!preg_match('/^DROP TABLE/i', $query)) |
---|
| 56 | { |
---|
[5982] | 57 | if ('mysql' == $dblayer) |
---|
[4410] | 58 | { |
---|
| 59 | if ( preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches) ) |
---|
| 60 | { |
---|
[5982] | 61 | $query = $matches[1].' DEFAULT CHARACTER SET utf8'.';'; |
---|
[4410] | 62 | } |
---|
| 63 | } |
---|
| 64 | pwg_query($query); |
---|
| 65 | } |
---|
| 66 | $query = ''; |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | /** |
---|
| 72 | * Search for database engines available |
---|
| 73 | * |
---|
| 74 | * We search for functions_DATABASE_ENGINE.inc.php |
---|
| 75 | * and we check if the connect function for that database exists |
---|
| 76 | * |
---|
| 77 | * @return array |
---|
| 78 | */ |
---|
| 79 | function available_engines() |
---|
| 80 | { |
---|
| 81 | $engines = array(); |
---|
| 82 | |
---|
| 83 | $pattern = PHPWG_ROOT_PATH. 'include/dblayer/functions_%s.inc.php'; |
---|
| 84 | include_once PHPWG_ROOT_PATH. 'include/dblayer/dblayers.inc.php'; |
---|
| 85 | |
---|
| 86 | foreach ($dblayers as $engine_name => $engine) |
---|
| 87 | { |
---|
[4985] | 88 | if (file_exists(sprintf($pattern, $engine_name))) |
---|
[4410] | 89 | { |
---|
[4985] | 90 | $engines[$engine_name]['label'] = $engine['engine']; |
---|
[5220] | 91 | $engines[$engine_name]['available'] = false; |
---|
[4985] | 92 | |
---|
| 93 | if (isset($engine['function_available']) |
---|
| 94 | && function_exists($engine['function_available'])) |
---|
| 95 | { |
---|
| 96 | $engines[$engine_name]['available'] = true; |
---|
| 97 | } |
---|
| 98 | elseif (isset($engine['class_available']) |
---|
| 99 | && class_exists($engine['class_available'])) |
---|
| 100 | { |
---|
| 101 | $engines[$engine_name]['available'] = true; |
---|
| 102 | } |
---|
[4410] | 103 | } |
---|
[4985] | 104 | } |
---|
| 105 | |
---|
[5239] | 106 | if ($engines['sqlite']['available'] and !$engines['pdo-sqlite']['available']) |
---|
[4985] | 107 | { |
---|
[5239] | 108 | unset($engines['pdo-sqlite']); |
---|
[4410] | 109 | } |
---|
[5239] | 110 | elseif ($engines['pdo-sqlite']['available'] and !$engines['sqlite']['available']) |
---|
| 111 | { |
---|
| 112 | unset($engines['sqlite']); |
---|
| 113 | } |
---|
| 114 | elseif (DEFAULT_DB_SQLITE=='native') |
---|
| 115 | { |
---|
| 116 | unset($engines['pdo-sqlite']); |
---|
| 117 | } |
---|
| 118 | else |
---|
| 119 | { |
---|
| 120 | unset($engines['sqlite']); |
---|
| 121 | } |
---|
[4985] | 122 | |
---|
[4410] | 123 | return $engines; |
---|
| 124 | } |
---|
[5340] | 125 | |
---|
| 126 | /** |
---|
[5982] | 127 | * Automatically activate all core themes in the "themes" directory. |
---|
[5340] | 128 | * |
---|
| 129 | * @return void |
---|
| 130 | */ |
---|
[5982] | 131 | function activate_core_themes() |
---|
[5340] | 132 | { |
---|
| 133 | include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php'); |
---|
| 134 | $themes = new themes(); |
---|
| 135 | foreach ($themes->fs_themes as $theme_id => $fs_theme) |
---|
| 136 | { |
---|
[5982] | 137 | if (in_array($theme_id, array('Sylvia', 'clear', 'dark'))) |
---|
| 138 | { |
---|
| 139 | $themes->perform_action('activate', $theme_id); |
---|
| 140 | } |
---|
[5340] | 141 | } |
---|
| 142 | } |
---|
[5384] | 143 | |
---|
[5387] | 144 | function install_db_connect(&$infos, &$errors) |
---|
[5384] | 145 | { |
---|
[6090] | 146 | global $pwg_db_link; |
---|
| 147 | |
---|
[5384] | 148 | try |
---|
| 149 | { |
---|
[5982] | 150 | $pwg_db_link = pwg_db_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpasswd'], $_POST['dbname']); |
---|
| 151 | if ($pwg_db_link) |
---|
| 152 | { |
---|
| 153 | pwg_db_check_version(); |
---|
| 154 | } |
---|
[5384] | 155 | } |
---|
| 156 | catch (Exception $e) |
---|
| 157 | { |
---|
| 158 | array_push( $errors, l10n($e->getMessage())); |
---|
| 159 | } |
---|
| 160 | } |
---|
[4410] | 161 | ?> |
---|