/**
  * Set user preference for sorting discussions.
  */
 public function Sort($Target = '')
 {
     if (!Gdn::Session()->IsValid()) {
         throw PermissionException();
     }
     if (!$this->Request->IsAuthenticatedPostBack()) {
         throw ForbiddenException('GET');
     }
     // Get param
     $SortField = Gdn::Request()->Post('DiscussionSort');
     $SortField = 'd.' . StringBeginsWith($SortField, 'd.', TRUE, TRUE);
     // Use whitelist here too to keep database clean
     if (!in_array($SortField, DiscussionModel::AllowedSortFields())) {
         throw new Gdn_UserException("Unknown sort {$SortField}.");
     }
     // Set user pref
     Gdn::UserModel()->SavePreference(Gdn::Session()->UserID, 'Discussions.SortField', $SortField);
     if ($Target) {
         Redirect($Target);
     }
     // Send sorted discussions.
     $this->DeliveryMethod(DELIVERY_METHOD_JSON);
     $this->Render();
 }
 /**
  * Getter/setter for protected $AllowedSortFields array.
  */
 public static function allowedSortFields($Allowed = null)
 {
     if (is_array($Allowed)) {
         self::$AllowedSortFields = $Allowed;
     }
     return self::$AllowedSortFields;
 }
Example #3
0
      <?php 
$Options = array('10' => '10', '15' => '15', '20' => '20', '25' => '25', '30' => '30', '40' => '40', '50' => '50', '100' => '100');
$Fields = array('TextField' => 'Code', 'ValueField' => 'Code');
echo $this->Form->Label('Discussions per Page', 'Vanilla.Discussions.PerPage');
echo $this->Form->DropDown('Vanilla.Discussions.PerPage', $Options, $Fields);
?>
   </li>
   <li>
      <?php 
echo $this->Form->Label('Comments per Page', 'Vanilla.Comments.PerPage');
echo $this->Form->DropDown('Vanilla.Comments.PerPage', $Options, $Fields);
?>
   </li>
   <li>
      <?php 
$AllowedSortFields = DiscussionModel::AllowedSortFields();
$SortFields = array();
foreach ($AllowedSortFields as $Field) {
    $SortFields[$Field] = DiscussionSortText($Field);
}
echo $this->Form->Label('Sort discussions by', 'Vanilla.Discussions.SortField');
echo $this->Form->DropDown('Vanilla.Discussions.SortField', $SortFields, $Fields);
?>
   </li>
   <li>
      <?php 
$Options = array('0' => T('Authors may never edit'), '350' => sprintf(T('Authors may edit for %s'), T('5 minutes')), '900' => sprintf(T('Authors may edit for %s'), T('15 minutes')), '3600' => sprintf(T('Authors may edit for %s'), T('1 hour')), '14400' => sprintf(T('Authors may edit for %s'), T('4 hours')), '86400' => sprintf(T('Authors may edit for %s'), T('1 day')), '604800' => sprintf(T('Authors may edit for %s'), T('1 week')), '2592000' => sprintf(T('Authors may edit for %s'), T('1 month')), '-1' => T('Authors may always edit'));
$Fields = array('TextField' => 'Text', 'ValueField' => 'Code');
echo $this->Form->Label('Discussion & Comment Editing', 'Garden.EditContentTimeout');
echo $this->Form->DropDown('Garden.EditContentTimeout', $Options, $Fields);
echo Wrap(T('EditContentTimeout.Notes', 'If a user is in a role that has permission to edit content, those permissions will override this.'), 'div', array('class' => 'Info'));