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