| 1 | <?php |
|---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
|---|
| 3 | |
|---|
| 4 | global $prefixeTable; |
|---|
| 5 | define('smart_table', $prefixeTable . 'category_filters'); |
|---|
| 6 | |
|---|
| 7 | define('smart_default_config', serialize(array( |
|---|
| 8 | 'update_on_upload' => false, |
|---|
| 9 | 'show_list_messages' => true, |
|---|
| 10 | ))); |
|---|
| 11 | |
|---|
| 12 | function plugin_install() |
|---|
| 13 | { |
|---|
| 14 | /* create table to store filters */ |
|---|
| 15 | pwg_query( |
|---|
| 16 | 'CREATE TABLE IF NOT EXISTS `' . smart_table . '` ( |
|---|
| 17 | `category_id` smallint(5) unsigned NOT NULL, |
|---|
| 18 | `type` varchar(16) NOT NULL, |
|---|
| 19 | `cond` varchar(16) NULL, |
|---|
| 20 | `value` text |
|---|
| 21 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
|---|
| 22 | ;'); |
|---|
| 23 | |
|---|
| 24 | /* add a collumn to image_category_table */ |
|---|
| 25 | pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` ADD `smart` ENUM(\'true\', \'false\') NOT NULL DEFAULT \'false\';'); |
|---|
| 26 | |
|---|
| 27 | /* config parameter */ |
|---|
| 28 | conf_update_param('SmartAlbums', smart_default_config); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | function plugin_activate() |
|---|
| 32 | { |
|---|
| 33 | global $conf; |
|---|
| 34 | |
|---|
| 35 | if (!isset($conf['SmartAlbums'])) |
|---|
| 36 | { |
|---|
| 37 | conf_update_param('SmartAlbums', smart_default_config); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | /* some filters renamed in 1.2 */ |
|---|
| 41 | $name_changes = array( |
|---|
| 42 | 'the' => 'the_post', |
|---|
| 43 | 'before' => 'before_post', |
|---|
| 44 | 'after' => 'after_post', |
|---|
| 45 | 'the_crea' => 'the_taken', |
|---|
| 46 | 'before_crea' => 'before_taken', |
|---|
| 47 | 'after_crea' => 'after_taken', |
|---|
| 48 | ); |
|---|
| 49 | foreach ($name_changes as $old => $new) |
|---|
| 50 | { |
|---|
| 51 | pwg_query('UPDATE ' . smart_table . ' SET cond = "'.$new.'" WHERE cond = "'.$old.'";'); |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | function plugin_uninstall() |
|---|
| 56 | { |
|---|
| 57 | pwg_query('DROP TABLE `' . smart_table . '`;'); |
|---|
| 58 | pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` DROP `smart`;'); |
|---|
| 59 | pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = \'SmartAlbums\' LIMIT 1;'); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | ?> |
|---|