Index: branches/5.2.x/units/topics/topics_tag_processor.php =================================================================== diff -u -N -r15155 -r15286 --- branches/5.2.x/units/topics/topics_tag_processor.php (.../topics_tag_processor.php) (revision 15155) +++ branches/5.2.x/units/topics/topics_tag_processor.php (.../topics_tag_processor.php) (revision 15286) @@ -1,6 +1,6 @@ Application->ProcessParsedTag('m', 'Link', $params); } + + /** + * Detects if current user is subscribed to new topics in this category + * + * @param Array $params + * @return bool + */ + function SubscribedToCategoryTopics($params) + { + static $subscribed = null; + + if ( !isset($subscribed) ) { + $post_helper = $this->Application->recallObject('PostHelper'); + /* @var $post_helper PostHelper */ + + $subscribed = $post_helper->getSubscriptionManager('CategoryTopics')->subscribed(); + } + + return $subscribed; + } + + /** + * Detects if current user is subscribed to this topic posts + * + * @param Array $params + * @return bool + */ + function SubscribedToTopicPosts($params) + { + static $subscribed = null; + + if ( !isset($subscribed) ) { + $object = $this->getObject($params); + /* @var $object kDBItem */ + + $post_helper = $this->Application->recallObject('PostHelper'); + /* @var $post_helper PostHelper */ + + $subscribed = $post_helper->getSubscriptionManager('TopicPosts', Array ($object->GetID()))->subscribed(); + } + + return $subscribed; + } } \ No newline at end of file Index: branches/5.2.x/install/english.lang =================================================================== diff -u -N -r15218 -r15286 --- branches/5.2.x/install/english.lang (.../english.lang) (revision 15218) +++ branches/5.2.x/install/english.lang (.../english.lang) (revision 15286) @@ -136,6 +136,10 @@ TmV3IFRvcGljIFJlcGx5IGhhcyBiZWVuIEFkZGVk TmV3IHJlcGx5IGhhcyBiZWVuIGFkZGVkIHRvIHRoZSBUb3BpYzogIDxhIGhyZWY9IjxpbnAyOmJiX1RvcGljTGluayB0ZW1wbGF0ZT0iX19kZWZhdWx0X18iLz4iPjxpbnAyOmJiX0ZpZWxkIG5hbWU9IlRvcGljVGV4dCIvPjwvYT4= + + TmV3IFJlcGx5IGhhcyBiZWVuIGFkZGVkIHRvIFRvcGljICI8aW5wMjpiYl9GaWVsZCBuYW1lPSdUb3BpY1RleHQnLz4i + Tm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XMgYXBwcm92ZWQ= WW91ciB0b3BpYyBoYXMgYmVlbiBhcHByb3ZlZCBvbiA8aW5wMjptX0Jhc2VVcmwvPjxicj48YnI+DQoNClRvcGljOiA8aW5wMjpiYl9GaWVsZCBuYW1lPSJUb3BpY1RleHQiLz4= Index: branches/5.2.x/install/install_data.sql =================================================================== diff -u -N -r15008 -r15286 --- branches/5.2.x/install/install_data.sql (.../install_data.sql) (revision 15008) +++ branches/5.2.x/install/install_data.sql (.../install_data.sql) (revision 15286) @@ -76,6 +76,8 @@ INSERT INTO EmailEvents (EventId, Event, ReplacementTags, Enabled, FrontEndOnly, Module, Description, Type, AllowChangingSender, AllowChangingRecipient) VALUES(DEFAULT, 'POST.MODIFY', NULL, 1, 1, 'In-Bulletin', 'Post Modified', 1, 1, 1); INSERT INTO EmailEvents (EventId, Event, ReplacementTags, Enabled, FrontEndOnly, Module, Description, Type, AllowChangingSender, AllowChangingRecipient) VALUES(DEFAULT, 'POST.ADD', NULL, 1, 0, 'In-Bulletin', 'Post Added', 0, 1, 1); INSERT INTO EmailEvents (EventId, Event, ReplacementTags, Enabled, FrontEndOnly, Module, Description, Type, AllowChangingSender, AllowChangingRecipient) VALUES(DEFAULT, 'PM.ADD', NULL, 1, 0, 'In-Bulletin', 'New Private Message', 0, 1, 1); +INSERT INTO EmailEvents (EventId, Event, ReplacementTags, Enabled, FrontEndOnly, Module, Description, Type, AllowChangingSender, AllowChangingRecipient, BindToSystemEvent) VALUES(DEFAULT, 'POST.ADD.SUB', NULL, 1, 0, 'In-Bulletin', 'Post Added (for subscribers)', 0, 1, 0, 'bb-post:OnCreate'); +INSERT INTO EmailEvents (EventId, Event, ReplacementTags, Enabled, FrontEndOnly, Module, Description, Type, AllowChangingSender, AllowChangingRecipient, BindToSystemEvent) VALUES(DEFAULT, 'TOPIC.ADD.SUB', NULL, 1, 0, 'In-Bulletin', 'Topic Added (for subscribers)', 0, 1, 0, 'bb:OnCreate'); INSERT INTO ItemTypes VALUES (3, 'In-Bulletin', 'bb', 'Topic', 'TopicText', 'OwnerId', 'Views', 'CachedRating', 'la_ItemTab_Topics', 1, '', 'clsTopic', 'Topic'); INSERT INTO ItemTypes VALUES (30, 'In-Bulletin', 'posting', 'Posting', 'Subject', 'CreatedById', NULL, NULL, 'la_ItemTab_Posts', 0, '', '', 'Post'); Index: branches/5.2.x/units/helpers/post_helper.php =================================================================== diff -u -N -r15249 -r15286 --- branches/5.2.x/units/helpers/post_helper.php (.../post_helper.php) (revision 15249) +++ branches/5.2.x/units/helpers/post_helper.php (.../post_helper.php) (revision 15286) @@ -1,6 +1,6 @@ Application->makeClass('kSubscriptionManager'); + /* @var $manager kSubscriptionManager */ + + $fields_hash = Array (); + + $user_id = isset($arguments[1]) ? $arguments[1] : $this->Application->RecallVar('user_id'); + + switch ( $name ) { + case 'CategoryTopics': + $category_id = isset($arguments[0]) ? $arguments[0] : $this->Application->GetVar('m_cat_id'); + + $fields_hash = Array ( + 'EmailEventId' => $manager->getEmailEventId('TOPIC.ADD.SUB'), + 'UserId' => $user_id, + 'CategoryId' => $category_id, + ); + break; + + case 'TopicPosts': + $fields_hash = Array ( + 'EmailEventId' => $manager->getEmailEventId('POST.ADD.SUB'), + 'UserId' => $user_id, + 'ParentItemId' => $arguments[0], + ); + break; + } + + $manager->add($fields_hash); + + return $manager; + } } \ No newline at end of file Index: branches/5.2.x/units/topics/topics_event_handler.php =================================================================== diff -u -N -r15148 -r15286 --- branches/5.2.x/units/topics/topics_event_handler.php (.../topics_event_handler.php) (revision 15148) +++ branches/5.2.x/units/topics/topics_event_handler.php (.../topics_event_handler.php) (revision 15286) @@ -1,6 +1,6 @@ Name == 'OnToogleCategoryTopicsSubscribe' || $event->Name == 'OnToogleTopicPostsSubscribe' ) { + return $this->Application->LoggedIn(); + } + return parent::CheckPermission($event); } @@ -249,4 +253,51 @@ $this->Application->setUnitOption($event->MasterEvent->Prefix, 'Clones', $clones); } } + + /** + * Subscribes/unsubscribes to new topics in given current category + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnToogleCategoryTopicsSubscribe(kEvent $event) + { + $post_helper = $this->Application->recallObject('PostHelper'); + /* @var $post_helper PostHelper */ + + $manager = $post_helper->getSubscriptionManager('CategoryTopics'); + + if ( $manager->subscribed() ) { + $manager->unsubscribe(); + } + else { + $manager->subscribe(); + } + } + + /** + * Subscribes/unsubscribes to new posts in current topic + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnToogleTopicPostsSubscribe(kEvent $event) + { + $object = $event->getObject(); + /* @var $object kDBItem */ + + $post_helper = $this->Application->recallObject('PostHelper'); + /* @var $post_helper PostHelper */ + + $manager = $post_helper->getSubscriptionManager('TopicPosts', Array ($object->GetID())); + + if ( $manager->subscribed() ) { + $manager->unsubscribe(); + } + else { + $manager->subscribe(); + } + } } \ No newline at end of file Index: branches/5.2.x/install/upgrades.sql =================================================================== diff -u -N -r15218 -r15286 --- branches/5.2.x/install/upgrades.sql (.../upgrades.sql) (revision 15218) +++ branches/5.2.x/install/upgrades.sql (.../upgrades.sql) (revision 15286) @@ -257,3 +257,5 @@ SET main_table.CachedReviewsQty = (SELECT COUNT(*) FROM <%TABLE_PREFIX%>CatalogReviews review_table WHERE review_table.ItemId = main_table.ResourceId); # ===== v 5.2.0-B3 ===== +INSERT INTO EmailEvents (EventId, Event, ReplacementTags, Enabled, FrontEndOnly, Module, Description, Type, AllowChangingSender, AllowChangingRecipient, BindToSystemEvent) VALUES(DEFAULT, 'POST.ADD.SUB', NULL, 1, 0, 'In-Bulletin', 'Post Added (for subscribers)', 0, 1, 0, 'bb-post:OnCreate'); +INSERT INTO EmailEvents (EventId, Event, ReplacementTags, Enabled, FrontEndOnly, Module, Description, Type, AllowChangingSender, AllowChangingRecipient, BindToSystemEvent) VALUES(DEFAULT, 'TOPIC.ADD.SUB', NULL, 1, 0, 'In-Bulletin', 'Topic Added (for subscribers)', 0, 1, 0, 'bb:OnCreate');