public function Get($Begin, $End, $Offset = '0', $Limit = '') { // Validate parameters, set today as default $BeginDate = strtotime($Begin); if ($BeginDate <= 0) { $BeginDate = date('Y-m-d'); } else { $BeginDate = date('Y-m-d', $BeginDate); } $EndDate = strtotime($End); if ($EndDate <= 0) { $EndDate = date('Y-m-d'); } else { $EndDate = date('Y-m-d', $EndDate); } if (!is_numeric($Offset)) { $Offset = 0; } if (!is_numeric($Limit)) { $Limit = ''; } $Sql = GDN::SQL(); $Sql->Select('d.Name, d.Body, d.Format')->Select('d.InsertUserID', '', 'UserID')->Select('DAY FROM d.EventCalendarDate', 'EXTRACT', 'EventCalendarDay')->From('Discussion d')->Where('d.EventCalendarDate >=', $BeginDate)->Where('d.EventCalendarDate <=', $EndDate)->OrderBy('d.EventCalendarDate')->Limit($Limit, $Offset); // add permission restrictions if necessary $Perms = DiscussionModel::CategoryPermissions(); if ($Perms !== TRUE) { $Sql->WhereIn('d.CategoryID', $Perms); } // return $Sql->GetSelect(); return $Sql->Get()->ResultArray(); }
/** * This creates the database structure for the plugin. * * @return void */ public function Structure() { GDN::Structure()->Table('AllLikes')->PrimaryKey('ID')->Column('CommentID', 'int(11)', TRUE)->Column('DiscussionID', 'int(11)', TRUE)->Column('UserID', 'int(11)', FALSE)->Set(TRUE); Gdn::Structure()->Table('User')->Column('Liked', 'int(11)', 0)->Column('DisLiked', 'int(11)', 0)->Column('ILiked', 'int(11)', 0)->Set(); }
/** * Give point(s) to the current user if the right conditions are met. * * @param CommentModel $sender Sending controller instance. * @param array $args Event arguments. */ public function commentModel_afterSaveComment_handler($sender, $args) { if (!c('QnA.Points.Enabled', false) || !$args['Insert']) { return; } $discussionModel = new DiscussionModel(); $discussion = $discussionModel->getID($args['CommentData']['DiscussionID'], DATASET_TYPE_ARRAY); $isCommentAnAnswer = $discussion['Type'] === 'Question'; $isQuestionResolved = $discussion['QnA'] === 'Accepted'; $isCurrentUserOriginalPoster = $discussion['InsertUserID'] == GDN::session()->UserID; if (!$isCommentAnAnswer || $isQuestionResolved || $isCurrentUserOriginalPoster) { return; } $userAnswersToQuestion = $sender->getWhere(array('DiscussionID' => $args['CommentData']['DiscussionID'], 'InsertUserId' => GDN::session()->UserID)); // Award point(s) only for the first answer to the question if ($userAnswersToQuestion->count() > 1) { return; } UserModel::givePoints(GDN::session()->UserID, c('QnA.Points.Answer', 1), 'QnA'); }
echo $this->Form->DropDown('CategoryID', $this->CategoryData, array('TextField' => 'Name', 'ValueField' => 'CategoryID')); echo '</div>'; } echo $this->Form->TextBox('Body', array('MultiLine' => TRUE)); $Options = ''; // If the user has any of the following permissions (regardless of junction), show the options // Note: I need to validate that they have permission in the specified category on the back-end // TODO: hide these boxes depending on which category is selected in the dropdown above. if ($Session->CheckPermission('Vanilla.Discussions.Announce')) { $Options .= '<li>' . $this->Form->CheckBox('Announce', GDN::Translate('Announce this discussion'), array('value' => '1')) . '</li>'; } if ($Session->CheckPermission('Vanilla.Discussions.Close')) { $Options .= '<li>' . $this->Form->CheckBox('Closed', GDN::Translate('Close this discussion'), array('value' => '1')) . '</li>'; } if ($Session->CheckPermission('Vanilla.Discussions.Sink')) { $Options .= '<li>' . $this->Form->CheckBox('Sink', GDN::Translate('Sink this discussion'), array('value' => '1')) . '</li>'; } if ($Options != '') { echo '<ul class="PostOptions">' . $Options . '</ul>'; } echo $this->Form->Button(property_exists($this, 'Discussion') ? 'Save' : 'Post Discussion'); if (!property_exists($this, 'Discussion') || !is_object($this->Discussion) || property_exists($this, 'Draft') && is_object($this->Draft)) { echo $this->Form->Button('Save Draft'); } echo $this->Form->Button('Preview'); $this->FireEvent('AfterFormButtons'); echo Anchor(Gdn::Translate('Cancel'), $CancelUrl, 'Cancel'); echo $this->Form->Close(); ?> </div>
public function Base_Render_Before(&$Sender) { $Session = Gdn::Session(); $dblink = mysql_connect(C('Database.Host'), C('Database.User'), C('Database.Password'), FALSE, 128); if (!$dblink) { mysql_close($dblink); return; } mysql_select_db(C('Database.Name')); $check = mysql_query("SELECT * FROM GDN_Shoutbox;"); //Check if table exists, create if table doesnt exist. if (!$check) { mysql_query("CREATE TABLE GDN_Shoutbox (EntryID int(255)AUTO_INCREMENT, PRIMARY KEY(EntryID), Username varchar(256), data varchar(256));", $dblink); $check = mysql_query("SELECT * FROM GDN_Shoutbox;"); if (!$check) { //Maybe wrong password for mysql db? dunno... return; } } if (isset($_GET["clearall"]) && $_GET["clearall"] == "1") { if (!$Session->CheckPermission('Plugins.Van2Shout.Delete')) { return; } $mysqlcmd = mysql_query("DELETE FROM GDN_Shoutbox;", $dblink); if (!$mysqlcmd) { mysql_close($dblink); return; } $mysqlcmd = mysql_query("INSERT INTO GDN_Shoutbox (Username, data) values ('System', '" . GDN::Translate('Database has been cleared') . "');", $dblink); if (!$mysqlcmd) { mysql_close($dblink); return; } } if (isset($_GET["msg"])) { $Session = Gdn::Session(); if ($_GET["msg"] == "") { return; } if (!$Session->CheckPermission('Plugins.Van2Shout.Post')) { return; } if ($Session->User->Name == "") { $username = "******"; } else { $username = $Session->User->Name; } if (strlen($_GET['msg']) > 150) { return; } $filtered = wordwrap(htmlspecialchars(str_replace("'", "\\'", $_GET['msg'])), 30, " ", true); $message = preg_replace('/(http|ftp)+(s)?:(\\/\\/)((\\w|\\.)+)(\\/)?(\\S+)?/i', '<a href="\\0" target="blank">\\0</a>', $filtered); $mysqlcmd = mysql_query("INSERT INTO GDN_Shoutbox (Username, data) values ('" . $username . "','" . $message . "');", $dblink); if (!$mysqlcmd) { mysql_close($dblink); return; } } if (isset($_GET["rm"])) { $Session = Gdn::Session(); if (!$Session->CheckPermission('Plugins.Van2Shout.Delete')) { return; } $mysqlcmd = mysql_query("DELETE FROM GDN_Shoutbox WHERE EntryID = " . $_GET['rm'] . ";", $dblink); if (!mysqlcmd) { mysql_close($dblink); return; } } mysql_close($dblink); include_once PATH_PLUGINS . DS . 'Van2Shout' . DS . 'class.van2shoutmodule.php'; $Van2ShoutModule = new Van2ShoutModule($Sender); $Sender->AddModule($Van2ShoutModule); $Sender->AddJsFile("/plugins/Van2Shout/van2shout.js"); $Sender->AddDefinition('user', $Session->User->Name); $webroot = Gdn::Request()->Webroot(); if ($webroot == "") { $webroot = "/"; } if (substr($webroot, 0, 1) != "/" && $webroot != "/") { $webroot = "/" . $webroot; } if (substr($webroot, 0, strlen($webroot)) != "/" && $webroot != "/") { $webroot = $webroot . "/"; } $Sender->AddDefinition('Van2ShoutRootpath', $webroot); }
public function Structure() { $Px = Gdn::Database()->DatabasePrefix; // Preparing to capture SQL (not execute) for operations that may need to be performed manually by the user Gdn::Structure()->CaptureOnly = TRUE; Gdn::Structure()->Database->CapturedSql = array(); // Comment table threshold check $CurrentComments = GDN::SQL()->Query("show table status where Name = '{$Px}Comment'")->FirstRow()->Rows; if ($CurrentComments > $this->TableRowThreshold) { // Does the number of rows exceed the threshold? // Execute functions for generating the SQL related to structural updates. SQL is saved in CapturedSql Gdn::Structure()->Table('Comment')->Column('OldID', 'int', true, 'key')->Column('ForeignID', 'varchar(32)', true, 'key')->Set(); } // Allow execution of structural operations Gdn::Structure()->CaptureOnly = FALSE; /** * If any SQL commands were captured, it means we have a problem. Throw an exception and report the necessary * SQL commands back to the user */ $CapturedSql = Gdn::Structure()->Database->CapturedSql; if (!empty($CapturedSql)) { throw new Exception("Due to the size of some tables, the following MySQL commands will need to be manually executed:\n" . implode("\n", $CapturedSql)); } Gdn::Structure()->Table('Activity')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('Category')->Column('OldID', 'int', TRUE, 'key')->Column('ForeignID', 'varchar(32)', TRUE, 'key')->Set(); Gdn::Structure()->Table('Comment')->Column('OldID', 'int', true, 'key')->Column('ForeignID', 'varchar(32)', true, 'key')->Set(); Gdn::Structure()->Table('Conversation')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('ConversationMessage')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('Discussion')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('Media')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('Role')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('Tag')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('TagDiscussion')->Column('OldCategoryID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('User')->Column('OldID', 'int', TRUE, 'key')->Set(); $Construct = Gdn::Database()->Structure(); $Construct->Table('Poll'); if ($Construct->TableExists()) { Gdn::Structure()->Table('Poll')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('PollOption')->Column('OldID', 'int', TRUE, 'key')->Set(); } }
/** * This creates the database structure for the plugin. * * @return void */ public function Structure() { $Structure = GDN::Structure(); $Structure->Table('Kudos')->Column('CommentID', 'int(11)', TRUE, 'key')->Column('DiscussionID', 'int(11)', TRUE, 'key')->Column('UserID', 'int(11)', FALSE, 'key')->Column('Action', 'int(1)', TRUE, 'key')->Column('DateUpdated', 'datetime')->Set(TRUE); }