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

Last change on this file since 25312 was 25278, checked in by plg, 11 years ago

feature 2994: only activate elegant and smartpocket themes during install

File size: 3.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 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, $dblayer)
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        if ('mysql' == $dblayer)
58        {
59          if ( preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches) )
60          {
61            $query = $matches[1].' DEFAULT CHARACTER SET utf8'.';';
62          }
63        }
64        pwg_query($query);
65      }
66      $query = '';
67    }
68  }
69}
70
71/**
72 * Automatically activate all core themes in the "themes" directory.
73 *
74 * @return void
75 */
76function activate_core_themes()
77{
78  include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
79  $themes = new themes();
80  foreach ($themes->fs_themes as $theme_id => $fs_theme)
81  {
82    if (in_array($theme_id, array('elegant', 'smartpocket')))
83    {
84      $themes->perform_action('activate', $theme_id);
85    }
86  }
87}
88
89function install_db_connect(&$infos, &$errors)
90{
91  try
92  {
93    pwg_db_connect($_POST['dbhost'], $_POST['dbuser'],
94                   $_POST['dbpasswd'], $_POST['dbname']);
95    pwg_db_check_version();
96  }
97  catch (Exception $e)
98  {
99    $errors[] = l10n($e->getMessage());
100  }
101}
102?>
Note: See TracBrowser for help on using the repository browser.