Permalink
Browse files

Merge branch 'unstable' of github.com:vanillaforums/Garden into unstable

  • Loading branch information...
markosullivan committed Jan 1, 2011
2 parents 1051911 + 6c786f9 commit 874efe4da7c84e2e558c764474278aa8ba151d9f
@@ -7,9 +7,19 @@
You should have received a copy of the GNU General Public License along with Garden. If not, see <http://www.gnu.org/licenses/>.
Contact Vanilla Forums Inc. at support [at] vanillaforums [dot] com
*/
-
+/**
+ * Conversations Controller
+ *
+ * @package Conversations
+ */
+
+/**
+ * Master controller for Conversations for others to extend.
+ *
+ * @since 2.0.0
+ * @package Conversations
+ */
class ConversationsController extends Gdn_Controller {
-
/**
* Returns an array of pages that contain settings information for this application.
*
@@ -19,10 +29,23 @@ public function GetSettingsPages(&$Menu) {
// There are no configuration pages for Conversations
}
+ /**
+ * Do-nothing construct to let children constructs bubble up.
+ *
+ * @access public
+ */
public function __construct() {
parent::__construct();
}
+ /**
+ * Include JS, CSS, and modules used by all methods.
+ *
+ * Always called by dispatcher before controller's requested method.
+ *
+ * @since 2.0.0
+ * @access public
+ */
public function Initialize() {
$this->Permission('Garden.SignIn.Allow');
if ($this->DeliveryType() == DELIVERY_TYPE_ALL) {
@@ -7,21 +7,66 @@
You should have received a copy of the GNU General Public License along with Garden. If not, see <http://www.gnu.org/licenses/>.
Contact Vanilla Forums Inc. at support [at] vanillaforums [dot] com
*/
-
+/**
+ * Messages Controller
+ *
+ * @package Conversations
+ */
+
/**
* MessagesController handles displaying lists of conversations and conversation messages.
+ *
+ * @since 2.0.0
+ * @package Conversations
*/
class MessagesController extends ConversationsController {
-
+ /**
+ * Models to include.
+ *
+ * @since 2.0.0
+ * @access public
+ * @var array
+ */
public $Uses = array('Form', 'ConversationModel', 'ConversationMessageModel');
+ /**
+ * A dataset of users taking part in this discussion. Used by $this->Index.
+ *
+ * @since 2.0.0
+ * @access public
+ * @var object
+ */
+ public $RecipientData;
+
+ /**
+ * The current offset of the paged data set. Defined and used by $this->Index and $this->All.
+ *
+ * @since 2.0.0
+ * @access public
+ * @var int
+ */
+ public $Offset;
+
+ /**
+ * Highlight route and include JS, CSS, and modules used by all methods.
+ *
+ * Always called by dispatcher before controller's requested method.
+ *
+ * @since 2.0.0
+ * @access public
+ */
public function Initialize() {
parent::Initialize();
$this->Menu->HighlightRoute('/messages/all');
}
/**
- * Add a new conversations.
+ * Start a new conversation.
+ *
+ * @since 2.0.0
+ * @access public
+ *
+ * @param string $Recipient Username of the recipient.
*/
public function Add($Recipient = '') {
$this->Form->SetModel($this->ConversationModel);
@@ -49,6 +94,11 @@ public function Add($Recipient = '') {
/**
* Add a message to a conversation.
+ *
+ * @since 2.0.0
+ * @access public
+ *
+ * @param int $ConversationID Unique ID of the conversation.
*/
public function AddMessage($ConversationID = '') {
$this->Form->SetModel($this->ConversationMessageModel);
@@ -84,21 +134,33 @@ public function AddMessage($ConversationID = '') {
/**
* Show all conversations for the currently authenticated user.
+ *
+ * @since 2.0.0
+ * @access public
+ *
+ * @param int $Offset Number to skip.
+ * @param int $Limit Number to show.
+ * @param bool $BookmarkedOnly Whether to limit to only bookmarked conversations.
*/
public function All($Offset = 0, $Limit = '', $BookmarkedOnly = FALSE) {
+ $Session = Gdn::Session();
$this->Title(T('Conversations'));
+
+ // Calculate offset
$this->Offset = $Offset;
- $Session = Gdn::Session();
if (!is_numeric($this->Offset) || $this->Offset < 0)
$this->Offset = 0;
+ // Calculate limit
if ($Limit == '' || !is_numeric($Limit) || $Limit < 0)
$Limit = Gdn::Config('Conversations.Conversations.PerPage', 50);
-
+
+ // Limit to bookmarks?
$Wheres = array();
if ($BookmarkedOnly !== FALSE)
$Wheres['Bookmarked'] = '1';
-
+
+ // Fetch from model
$this->ConversationData = $this->ConversationModel->Get(
$Session->UserID,
$this->Offset,
@@ -128,56 +190,70 @@ public function All($Offset = 0, $Limit = '', $BookmarkedOnly = FALSE) {
$this->View = 'conversations';
}
+ // Build and display page
$this->AddModule('SignedInModule');
$this->AddModule('NewConversationModule');
$this->Render();
}
/**
* Clear the message history for a specific conversation & user.
+ *
+ * @since 2.0.0
+ * @access public
+ *
+ * @param int $ConversationID Unique ID of conversation to clear.
*/
public function Clear($ConversationID = FALSE) {
$Session = Gdn::Session();
+
+ // Yes/No response
$this->_DeliveryType = DELIVERY_TYPE_BOOL;
+
+ // Clear it
if (is_numeric($ConversationID) && $ConversationID > 0 && $Session->IsValid())
$this->ConversationModel->Clear($ConversationID, $Session->UserID);
-
+
$this->StatusMessage = T('The conversation has been cleared.');
$this->RedirectUrl = Url('/messages/all');
$this->Render();
}
- /**
- * A dataset of users taking part in this discussion. Used by $this->Index.
- */
- public $RecipientData;
-
- /**
- * The current offset of the paged data set. Defined and used by $this->Index and $this->All.
- */
- public $Offset;
-
/**
* Shows all uncleared messages within a conversation for the viewing user
+ *
+ * @since 2.0.0
+ * @access public
+ *
+ * @param int $ConversationID Unique ID of conversation to view.
+ * @param int $Offset Number to skip.
+ * @param int $Limit Number to show.
*/
public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '') {
$this->Offset = $Offset;
$Session = Gdn::Session();
+
+ // Figure out Conversation ID
if (!is_numeric($ConversationID) || $ConversationID < 0)
$ConversationID = 0;
+ // Form setup for adding comments
$this->Form->SetModel($this->ConversationMessageModel);
$this->Form->AddHidden('ConversationID', $ConversationID);
+ // Get conversation data
$this->RecipientData = $this->ConversationModel->GetRecipients($ConversationID);
$this->Conversation = $this->ConversationModel->GetID($ConversationID, $Session->UserID);
+ // Bad conversation? Redirect
if ($this->Conversation === FALSE)
Redirect('dashboard/home/filenotfound');
-
+
+ // Get limit
if ($Limit == '' || !is_numeric($Limit) || $Limit < 0)
$Limit = Gdn::Config('Conversations.Messages.PerPage', 50);
+ // Calculate counts
if (!is_numeric($this->Offset) || $this->Offset < 0) {
// Round down to the appropriate offset based on the user's read messages & messages per page
$CountReadMessages = $this->Conversation->CountMessages - $this->Conversation->CountNewMessages;
@@ -190,14 +266,16 @@ public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '') {
// (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
$this->Offset = floor($CountReadMessages / $Limit) * $Limit;
}
-
+
+ // Fetch message data
$this->MessageData = $this->ConversationMessageModel->Get(
$ConversationID,
$Session->UserID,
$this->Offset,
$Limit
);
+ // Figure out who's participating.
$this->Participants = '';
$Count = 0;
$Users = array();
@@ -241,6 +319,7 @@ public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '') {
$this->View = 'messages';
}
+ // Add modules
$this->AddModule('SignedInModule');
$this->AddModule('NewConversationModule');
@@ -254,16 +333,25 @@ public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '') {
$this->AddModule('AddPeopleModule');
+ // Render view
$this->Render();
}
/**
* Allows users to bookmark conversations.
+ *
+ * @since 2.0.0
+ * @access public
+ *
+ * @param int $ConversationID Unique ID of conversation to view.
+ * @param string $TransientKey Single-use hash to prove intent.
*/
public function Bookmark($ConversationID = '', $TransientKey = '') {
$Session = Gdn::Session();
$Success = FALSE;
$Star = FALSE;
+
+ // Validate & do bookmarking
if (
is_numeric($ConversationID)
&& $ConversationID > 0
@@ -273,6 +361,7 @@ public function Bookmark($ConversationID = '', $TransientKey = '') {
$Bookmark = $this->ConversationModel->Bookmark($ConversationID, $Session->UserID);
}
+ // Report success or error
if ($Bookmark === FALSE)
$this->Form->AddError('ErrorBool');
else
@@ -288,14 +377,27 @@ public function Bookmark($ConversationID = '', $TransientKey = '') {
/**
* Show bookmarked conversations for the current user.
*
- * @param int
- * @param string
+ * @since 2.0.0
+ * @access public
+ *
+ * @param int $Offset Number to skip.
+ * @param string $Limit Number to show.
*/
public function Bookmarked($Offset = 0, $Limit = '') {
$this->View = 'All';
$this->All($Offset, $Limit, TRUE);
}
+ /**
+ * Show bookmarked conversations for the current user.
+ *
+ * @since 2.0.0
+ * @access public
+ *
+ * @param int $Offset Number to skip.
+ * @param string $Limit Number to show.
+ * @param bool $BookmarkedOnly Whether to show only bookmarks
+ */
public function Inbox($Offset = 0, $Limit = '', $BookmarkedOnly = FALSE) {
$this->View = 'All';
$this->All($Offset, $Limit, $BookmarkedOnly);
@@ -55,7 +55,7 @@
$Construct
->PrimaryKey('UserID')
- ->Column('Name', 'varchar(20)', FALSE, 'key')
+ ->Column('Name', 'varchar(50)', FALSE, 'key')
->Column('Password', 'varbinary(100)') // keep this longer because of some imports.
->Column('HashMethod', 'varchar(10)', TRUE)
->Column('Photo', 'varchar(255)', NULL)
@@ -299,6 +299,10 @@ public function GetAnnouncements($Wheres = '') {
$this->AddDiscussionColumns($Data);
+ // Prep and fire event
+ $this->EventArguments['Data'] = $Data;
+ $this->FireEvent('AfterAddColumns');
+
return $Data;
}
@@ -608,7 +608,7 @@ public static function Mentions($Mixed) {
// Handle @mentions.
if(C('Garden.Format.Mentions')) {
$Mixed = preg_replace(
- '/(^|[\s,\.])@(\w{1,20})\b/i', //{3,20}
+ '/(^|[\s,\.])@(\w{1,50})\b/i', //{3,20}
'\1'.Anchor('@\2', '/profile/\\2'),
$Mixed
);
Oops, something went wrong.

0 comments on commit 874efe4

Please sign in to comment.