source: trunk/admin/include/functions_install.inc.php @ 5408

Last change on this file since 5408 was 5408, checked in by plg, 14 years ago

Simplify installation message, no need to explain the following step, the
"no photo yet" feature makes the explanations useless at this point.

.infos admin block is used to display messages, I've set the background
transparent here, because it's the only message of the page. Anyway, I don't
think using .infos blocks are relevant if that's the only message on the page.

File size: 4.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
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 */
36function execute_sqlfile($filepath, $replaced, $replacing)
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      {
57        global $install_charset_collate;
58        if ( !empty($install_charset_collate) )
59        {
60          if ( preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches) )
61          {
62            $query = $matches[1].' '.$install_charset_collate.';';
63          }
64        }
65        pwg_query($query);
66      }
67      $query = '';
68    }
69  }
70}
71
72/**
73 * Search for database engines available
74 *
75 * We search for functions_DATABASE_ENGINE.inc.php
76 * and we check if the connect function for that database exists
77 *
78 * @return array
79 */
80function available_engines()
81{
82  $engines = array();
83
84  $pattern = PHPWG_ROOT_PATH. 'include/dblayer/functions_%s.inc.php';
85  include_once PHPWG_ROOT_PATH. 'include/dblayer/dblayers.inc.php';
86
87  foreach ($dblayers as $engine_name => $engine)
88  {
89    if (file_exists(sprintf($pattern, $engine_name))) 
90    {
91      $engines[$engine_name]['label'] = $engine['engine'];
92      $engines[$engine_name]['available'] = false;
93
94      if (isset($engine['function_available'])
95          && function_exists($engine['function_available']))
96      {
97        $engines[$engine_name]['available'] = true;
98      }
99      elseif (isset($engine['class_available']) 
100              && class_exists($engine['class_available']))
101      {
102        $engines[$engine_name]['available'] = true;
103      } 
104    }
105  }
106
107  if ($engines['sqlite']['available'] and !$engines['pdo-sqlite']['available'])
108  {
109    unset($engines['pdo-sqlite']);
110  }
111  elseif ($engines['pdo-sqlite']['available'] and !$engines['sqlite']['available'])
112  {
113    unset($engines['sqlite']);
114  }
115  elseif (DEFAULT_DB_SQLITE=='native')
116  {
117    unset($engines['pdo-sqlite']);
118  }
119  else
120  {
121    unset($engines['sqlite']);
122  }
123
124  return $engines;
125}
126
127/**
128 * Automatically activate all themes in the "themes" directory.
129 *
130 * @return void
131 */
132function activate_all_themes()
133{
134  include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
135  $themes = new themes();
136  foreach ($themes->fs_themes as $theme_id => $fs_theme)
137  {
138    $themes->perform_action('activate', $theme_id);
139  }
140}
141
142function install_db_connect(&$infos, &$errors)
143{
144  try
145  {
146    $pwg_db_link = pwg_db_connect($_POST['dbhost'], $_POST['dbuser'], 
147                                  $_POST['dbpasswd'], $_POST['dbname']);
148 
149    return true;
150  }
151  catch (Exception $e)
152  {
153    array_push( $errors, l10n($e->getMessage()));
154  }
155  return false;
156}
157?>
Note: See TracBrowser for help on using the repository browser.