source: extensions/menalto2piwigo/include/functions.inc.php @ 31033

Last change on this file since 31033 was 29070, checked in by plg, 10 years ago

compatible with Gallery3 (automatic detection)

File size: 1.2 KB
Line 
1<?php
2function m2p_db_connect()
3{
4  global $conf;
5
6  try
7  {
8    pwg_db_connect(
9      $conf['menalto2piwigo']['db_host'],
10      $conf['menalto2piwigo']['db_user'],
11      $conf['menalto2piwigo']['db_password'],
12      $conf['menalto2piwigo']['db_name']
13      );
14  }
15  catch (Exception $e)
16  {
17    my_error(l10n($e->getMessage()), true);
18  }
19
20  pwg_db_check_charset();
21
22  return true;
23}
24
25function m2p_db_disconnect()
26{
27  global $conf;
28
29  // reconnect to the Piwigo database
30  $pwg_db_link = pwg_db_connect(
31    $conf['db_host'],
32    $conf['db_user'],
33    $conf['db_password'],
34    $conf['db_base']
35    );
36
37  pwg_db_check_charset();
38}
39
40function m2p_remove_bbcode($string)
41{
42  $patterns = array(
43    '\[color=\w+\]',
44    '\[/color\]',
45    '\[b\]',
46    '\[/b\]',
47    '\[i\]',
48    '\[/i\]',
49    );
50
51  foreach ($patterns as $pattern)
52  {
53    $string = preg_replace('#'.$pattern.'#', '', $string);
54  }
55
56  return $string;
57}
58
59/**
60 * list all tables in an array
61 *
62 * @return array
63 */
64function m2p_get_tables($prefix='')
65{
66  $tables = array();
67
68  $query = '
69SHOW TABLES
70;';
71  $result = pwg_query($query);
72
73  while ($row = pwg_db_fetch_row($result))
74  {
75    if (preg_match('/^'.$prefix.'/', $row[0]))
76    {
77      $tables[] = $row[0];
78    }
79  }
80
81  return $tables;
82}
Note: See TracBrowser for help on using the repository browser.