source: extensions/Back2Front/include/install.inc.php @ 23177

Last change on this file since 23177 was 23177, checked in by mistic100, 11 years ago

use serialized array for config + custom upgrade process

File size: 2.3 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4include_once(PHPWG_PLUGINS_PATH . B2F_ID . '/include/functions.inc.php');
5
6function back2front_install() 
7{
8  global $conf, $prefixeTable;
9 
10  // configuration
11  if (empty($conf['back2front']))
12  {
13    // create virtual private cat for storage
14    $versos_cat = create_virtual_category('Back2Front private album');
15    $versos_cat = array(
16      'id' => $versos_cat['id'],
17      'comment' => 'Used by Back2Front to store backsides.',
18      'status'  => 'private',
19      'visible' => 'false',
20      'commentable' => 'false',
21      );
22   
23    mass_updates(
24      CATEGORIES_TABLE,
25      array(
26        'primary' => array('id'),
27        'update' => array_diff(array_keys($versos_cat), array('id'))
28        ),
29      array($versos_cat)
30      );
31   
32    $Back2Front_default_config = array(
33      'versos_cat' => $versos_cat['id'],
34      'switch_mode' => 'click',
35      'transition' => 'none',
36      'position' => 'top',
37      'link_name' => array('default'=>null),
38      'show_thumbnail' => true,
39      );
40     
41    $conf['back2front'] = serialize($Back2Front_default_config);
42   
43    conf_update_param('back2front', $conf['back2front']);
44  }
45  else
46  {
47    if (is_string($conf['back2front']))
48    {
49      if (($old_conf = @unserialize($conf['back2front'])) === false)
50      {
51        $old_conf = explode(',', $conf['back2front']);
52      }
53    }
54    else
55    {
56      $old_conf = $conf['back2front'];
57    }
58   
59    // convert old comma separated conf
60    if (isset($old_conf[0]))
61    {
62      $new_conf = array(
63        'versos_cat' => $old_conf[0],
64        'switch_mode' => $old_conf[1],
65        'transition' => $old_conf[2],
66        'position' => $old_conf[3],
67        'link_name' => unserialize($old_conf[4]),
68        'show_thumbnail' => @$old_conf[5],
69        );
70   
71      $conf['back2front'] = serialize($new_conf);
72      conf_update_param('back2front', $conf['back2front']);
73    }
74  }
75 
76  // create tables
77  $query = '
78CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'image_verso` (
79  `image_id` mediumint(8) unsigned NOT NULL DEFAULT 0,
80  `verso_id` mediumint(8) unsigned NOT NULL DEFAULT 0,
81  `categories` varchar(128) NULL,
82  PRIMARY KEY (`image_id`),
83  UNIQUE KEY (`verso_id`)
84) ENGINE=MyISAM DEFAULT CHARSET=utf8;
85';
86  pwg_query($query);
87}
88
89?>
Note: See TracBrowser for help on using the repository browser.