Changeset 17922 for extensions/Subscribe_to_comments
- Timestamp:
- Sep 15, 2012, 11:14:27 AM (12 years ago)
- Location:
- extensions/Subscribe_to_comments
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Subscribe_to_comments/main.inc.php
r16106 r17922 13 13 global $prefixeTable; 14 14 15 define('SUBSCRIBE_TO_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');15 define('SUBSCRIBE_TO_PATH' , PHPWG_PLUGINS_PATH . 'Subscribe_to_comments/'); 16 16 define('SUBSCRIBE_TO_TABLE', $prefixeTable . 'subscribe_to_comments'); 17 define('SUBSCRIBE_TO_VERSION', '2.0.3'); 18 17 19 18 20 add_event_handler('init', 'stc_init'); 19 21 22 20 23 function stc_init() 21 24 { 22 global $conf, $user ;25 global $conf, $user, $pwg_loaded_plugins; 23 26 24 27 // no comments on luciano 25 28 if ($user['theme'] == 'luciano') return; 26 29 30 // apply upgrade if needed 31 if ( 32 $pwg_loaded_plugins['Subscribe_to_comments']['version'] == 'auto' or 33 version_compare($pwg_loaded_plugins['Subscribe_to_comments']['version'], SUBSCRIBE_TO_VERSION, '<') 34 ) 35 { 36 include_once(SUBSCRIBE_TO_PATH . 'include/install.inc.php'); 37 stc_install(); 38 39 if ($pwg_loaded_plugins['Subscribe_to_comments']['version'] != 'auto') 40 { 41 $query = ' 42 UPDATE '. PLUGINS_TABLE .' 43 SET version = "'. SUBSCRIBE_TO_VERSION .'" 44 WHERE id = "Subscribe_to_comments"'; 45 pwg_query($query); 46 47 $pwg_loaded_plugins['Subscribe_to_comments']['version'] = SUBSCRIBE_TO_VERSION; 48 49 if (defined('IN_ADMIN')) 50 { 51 $_SESSION['page_infos'][] = 'Subscribe to comments updated to version '. SUBSCRIBE_TO_VERSION; 52 } 53 } 54 } 55 56 // load language and conf 27 57 load_language('plugin.lang', SUBSCRIBE_TO_PATH); 28 58 $conf['Subscribe_to_Comments'] = unserialize($conf['Subscribe_to_Comments']); 59 29 60 30 61 include_once(SUBSCRIBE_TO_PATH.'include/functions.inc.php'); 31 62 include_once(SUBSCRIBE_TO_PATH.'include/subscribe_to_comments.inc.php'); 32 63 64 33 65 // send mails 34 66 add_event_handler('user_comment_insertion', 'stc_comment_insertion'); … … 54 86 } 55 87 88 56 89 function stc_admin_menu($menu) 57 90 { … … 62 95 return $menu; 63 96 } 97 64 98 ?> -
extensions/Subscribe_to_comments/maintain.inc.php
r15641 r17922 2 2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 3 3 4 global $prefixeTable; 5 6 define('STC_TABLE', $prefixeTable . 'subscribe_to_comments'); 7 8 define( 9 'stc_default_config', 10 serialize(array( 11 'notify_admin_on_subscribe' => false, 12 'allow_global_subscriptions' => true, 13 )) 14 ); 4 include_once(PHPWG_PLUGINS_PATH . 'Subscribe_to_comments/include/install.inc.php'); 15 5 16 6 17 7 function plugin_install() 18 8 { 19 /* create table to store subscribtions */ 20 pwg_query(' 21 CREATE TABLE IF NOT EXISTS '.STC_TABLE.' ( 22 `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 23 `type` enum("image","album-images","album","all-images","all-albums") NOT NULL DEFAULT "image", 24 `element_id` mediumint(8) DEFAULT NULL, 25 `language` varchar(64) NOT NULL, 26 `email` varchar(255) NOT NULL, 27 `registration_date` datetime NOT NULL, 28 `validated` enum("true","false") NOT NULL DEFAULT "false", 29 PRIMARY KEY (`id`), 30 UNIQUE KEY `UNIQUE` (`email` , `type` , `element_id`) 31 ) DEFAULT CHARSET=utf8 32 ;'); 33 34 /* config parameter */ 35 conf_update_param('Subscribe_to_Comments', stc_default_config); 36 9 stc_install(); 10 define('stc_installed', true); 37 11 } 38 12 39 13 function plugin_activate() 40 14 { 41 global $conf; 42 43 // new config in 1.1 44 if (empty($conf['Subscribe_to_Comments'])) 15 if (!defined('stc_installed')) 45 16 { 46 conf_update_param('Subscribe_to_Comments', stc_default_config); 47 } 48 49 // table structure upgrade in 1.1 50 $result = pwg_query('SHOW COLUMNS FROM '.STC_TABLE.' LIKE "element_id";'); 51 if (!pwg_db_num_rows($result)) 52 { 53 // backup subscriptions 54 $query = 'SELECT * FROM '.STC_TABLE.' ORDER BY registration_date;'; 55 $subscriptions = hash_from_query($query, 'id'); 56 57 // upgrade the table 58 pwg_query('TRUNCATE TABLE '.STC_TABLE.';'); 59 pwg_query('ALTER TABLE '.STC_TABLE.' DROP `image_id`, DROP `category_id`;'); 60 pwg_query('ALTER TABLE '.STC_TABLE.' AUTO_INCREMENT = 1;'); 61 62 $query = ' 63 ALTER TABLE '.STC_TABLE.' 64 ADD `type` ENUM( "image", "album-images", "album", "all-images", "all-albums" ) NOT NULL DEFAULT "image" AFTER `id`, 65 ADD `element_id` MEDIUMINT( 8 ) NULL AFTER `type`, 66 ADD `language` VARCHAR( 64 ) NOT NULL AFTER `element_id` 67 ;'; 68 pwg_query($query); 69 70 pwg_query('ALTER TABLE '.STC_TABLE.' DROP INDEX `UNIQUE`, ADD UNIQUE `UNIQUE` ( `email` , `type` , `element_id` );'); 71 72 // convert datas and fill the table 73 $inserts = array(); 74 75 foreach ($subscriptions as $row) 76 { 77 if (!empty($row['category_id'])) 78 { 79 $row['type'] = 'album'; 80 $row['element_id'] = $row['category_id']; 81 } 82 else if (!empty($row['image_id'])) 83 { 84 $row['type'] = 'image'; 85 $row['element_id'] = $row['image_id']; 86 } 87 else 88 { 89 continue; 90 } 91 92 unset($row['id'], $row['image_id'], $row['category_id']); 93 $row['language'] = 'en_UK'; 94 95 array_push($inserts, $row); 96 } 97 98 if (count($inserts) > 0) 99 { 100 $dbfields = array('type', 'element_id', 'language', 'email', 'registration_date', 'validated'); 101 mass_inserts(STC_TABLE, $dbfields, $inserts); 102 } 17 stc_install(); 103 18 } 104 19 } … … 106 21 function plugin_uninstall() 107 22 { 108 /* delete table and config */ 109 pwg_query('DROP TABLE '.STC_TABLE.';'); 23 global $prefixeTable; 24 25 pwg_query('DROP TABLE `'. $prefixeTable . 'subscribe_to_comments`;'); 110 26 pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "Subscribe_to_Comments" LIMIT 1;'); 111 27 }
Note: See TracChangeset
for help on using the changeset viewer.