Created
December 21, 2012 22:29
-
-
Save jamesshannon/4356289 to your computer and use it in GitHub Desktop.
Concrete Wall for #concrete5 -- Integration of the core discussion forums addon. This adds wall postings when a user creates a new discussion or replies to an existing one. Add this code anywhere that gets run on every request -- /config/site_events.php is a good place.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// register event so that our SiteDiscussionWallPoster::hookPageAdd() gets called when pages get added | |
Events::extend('on_page_add', 'SiteDiscussionWallPoster', 'hookPageAdd', false); | |
class SiteDiscussionWallPoster { | |
/** | |
* gets called when on_page_add event is fired. adds a wall posting if page of type "discussion_post" was added | |
* @param Page $page page object that was added, passed in by event model | |
*/ | |
public function hookPageAdd(Page $page) { | |
//this is a discussion_post page | |
if ($page->getCollectionTypeHandle() == 'discussion_post') { | |
$wall = Loader::package('lerteco_wall'); | |
$u = new User(); | |
//both the main thread and all replies are of type 'discussion_post' | |
// we want to treat the main thread and replies differently, so we create two different posting types | |
// also, we pass the main thread ID to both | |
$parent = Page::getByID($page->getCollectionParentID()); | |
if ($parent->getCollectionTypeHandle() != 'discussion_post') { | |
//parent page type is NOT discussion_post. we're not a reply | |
$posting_type = array('discussion', 'discussion_post_new', 'New Post', 'posted %1$p', 1, PostingType::SHAREWITH_ALL); | |
$wall->postAndPossiblyRegister($u->getUserID(), $page->getCollectionID(), $posting_type); | |
} else { | |
//the parent is a discusson_post, too, which means this is a reply | |
$posting_type = array('discussion', 'discussion_post_reply', 'Reply', 'replied to %1$p', 1, PostingType::SHAREWITH_ALL); | |
$wall->postAndPossiblyRegister($u->getUserID(), $parent->getCollectionID(), $posting_type); | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment