source: extensions/Back2Front/maintain.inc.php @ 11298

Last change on this file since 11298 was 11219, checked in by mistic100, 13 years ago

add some options, better intégration

File size: 2.6 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4include_once(PHPWG_PLUGINS_PATH.'back2front/functions.inc.php');
5
6function plugin_install() {
7        global $prefixeTable;
8
9  /* create table for recto/veros pairs | stores original verso categories */
10        pwg_query("CREATE TABLE IF NOT EXISTS `" . $prefixeTable . "image_verso` (
11    `image_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
12    `verso_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
13    `categories` varchar(128) NULL,
14    PRIMARY KEY (`image_id`),
15    UNIQUE KEY (`verso_id`)
16        ) DEFAULT CHARSET=utf8;");
17 
18  /* create a virtual category to store versos */
19  $versos_cat = create_virtual_category('Back2Front private album');
20  $versos_cat = array(
21    'id' => $versos_cat['id'],
22    'comment' => 'Used by Back2Front to store backsides.',
23    'status'  => 'private',
24    'visible' => 'false',
25    'commentable' => 'false',
26    );
27  mass_updates(
28    CATEGORIES_TABLE,
29    array(
30      'primary' => array('id'),
31      'update' => array_diff(array_keys($versos_cat), array('id'))
32      ),
33    array($versos_cat)
34    );
35   
36  /* config parameter */
37  pwg_query("INSERT INTO `" . CONFIG_TABLE . "`
38    VALUES ('back2front', '".$versos_cat['id'].",click,none', 'Configuration for Back2Front plugin');");
39}
40
41function plugin_activate()
42{
43  global $conf;
44
45  if (!isset($conf['back2front'])) {
46    pwg_query("INSERT INTO `" . CONFIG_TABLE . "`
47      VALUES ('back2front', '".$versos_cat['id'].",click,none', 'Configuration for Back2Front plugin');");
48  } else {
49    $conf['back2front'] = explode(',', $conf['back2front']);
50    if (!isset($conf['back2front'][3])) {
51      $conf['back2front'][3] = 'top';
52      $conf['back2front'][4] = serialize(array('default'=>null));
53      conf_update_param('back2front', implode (',', $conf['back2front'])); 
54    }
55  }
56}
57
58
59function plugin_uninstall() {
60        global $conf, $prefixeTable;
61 
62  $conf['back2front'] = explode(',',$conf['back2front']);
63 
64  /* versos must be restored to their original categories
65   criterias :
66    - verso € 'versos' cat only => restore verso to original categories
67    - otherwise nothing is changed
68  */
69
70  $query = "SELECT * FROM `" . $prefixeTable . "image_verso`;";
71  $images_versos = pwg_query($query);
72 
73  while ($item = pwg_db_fetch_assoc($images_versos))
74  {
75    back2front_restaure_categories($item);
76  }
77
78  pwg_query("DROP TABLE `" . $prefixeTable . "image_verso`;");
79  pwg_query("DELETE FROM `" . CONFIG_TABLE . "` WHERE param = 'back2front';");
80  pwg_query("DELETE FROM `" . CATEGORIES_TABLE ."`WHERE id = ".$conf['back2front'][0].";");
81 
82  /* rebuild categories cache */
83  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
84  invalidate_user_cache(true);
85}
86?>
Note: See TracBrowser for help on using the repository browser.