Наследование: extends Gdn_Pluggable
Пример #1
0
 /**
  * Set the sort order for data on an arbitrary database table.
  *
  * Expect post values TransientKey, Target (redirect URL), Table (database table name),
  * and TableID (an array of sort order => unique ID).
  *
  * @since 2.0.0
  * @access public
  */
 public function sort()
 {
     $this->permission('Garden.Settings.Manage');
     if (Gdn::request()->isAuthenticatedPostBack()) {
         $TableID = Gdn::request()->Post('TableID');
         if ($TableID) {
             $Rows = Gdn::request()->Post($TableID);
             if (is_array($Rows)) {
                 $Table = str_replace(array('Table', '`'), '', $TableID);
                 $ModelName = $Table . 'Model';
                 if (class_exists($ModelName)) {
                     $TableModel = new $ModelName();
                 } else {
                     $TableModel = new Gdn_Model($Table);
                 }
                 foreach ($Rows as $Sort => $ID) {
                     if (strpos($ID, '_') !== false) {
                         list(, $ID) = explode('_', $ID, 2);
                     }
                     if (!$ID) {
                         continue;
                     }
                     $TableModel->setField($ID, 'Sort', $Sort);
                 }
                 $this->setData('Result', true);
             }
         }
     }
     $this->render('Blank');
 }
 public function Sort() {
    $Session = Gdn::Session();
    $TransientKey = GetPostValue('TransientKey', '');
    $Target = GetPostValue('Target', '');
    if ($Session->ValidateTransientKey($TransientKey)) {
       $TableID = GetPostValue('TableID', FALSE);
       if ($TableID) {
          $Rows = GetPostValue($TableID, FALSE);
          if (is_array($Rows)) {
             try {
                $Table = str_replace('Table', '', $TableID);
                $TableModel = new Gdn_Model($Table);
                foreach ($Rows as $Sort => $ID) {
                   $TableModel->Update(array('Sort' => $Sort), array($Table.'ID' => $ID));
                }
             } catch (Exception $ex) {
                $this->Form->AddError($ex->getMessage());
             }
          }
       }
    }
    if ($this->DeliveryType() != DELIVERY_TYPE_BOOL)
       Redirect($Target);
       
    $this->Render();
 }
 /**
  * Allows customization of categories which allow new discussions to be events 
  * Sets config value Plugins.EventCalendar.CategoryIDs
  *
  * @param object $Sender SettingsController
  */
 public function SettingsController_EventCalendar_Create($Sender)
 {
     $Sender->Permission('Garden.Settings.Manage');
     $Sender->Title(T('Event Calendar Settings'));
     $Sender->AddSideMenu('settings/EventCalendar');
     $Sender->SetData('Info', T('Event Calendar Info', 'Creation of events can be regulated by category <strong>and</strong> user role. You can set up the categories here, but don\'t forget to assign some permissions in the <a href="/index.php?p=dashboard/role">standard permission section</a> in the dashboard, otherwise you users wouldn\'t be able to use this plugin!'));
     $Sender->SetData('CategoriesLabel', 'Please choose categories in which the creation of events should be allowed');
     $Validation = new Gdn_Validation();
     // $Validation->ApplyRule('Plugins.EventCalendar.CategoryIDs', 'RequiredArray', T('You have to choose at least one category. If you don\'t want to use the plugin any longer, please deactivate it'));
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->SetField(array('Plugins.EventCalendar.CategoryIDs'));
     $Form = $Sender->Form;
     $Sender->Form->SetModel($ConfigurationModel);
     if ($Sender->Form->AuthenticatedPostBack() != FALSE) {
         if ($Sender->Form->Save() != FALSE) {
             $Sender->StatusMessage = T('Saved');
         }
     } else {
         $Sender->Form->SetData($ConfigurationModel->Data);
     }
     $CategoryModel = new Gdn_Model('Category');
     $Sender->CategoryData = $CategoryModel->GetWhere(array('AllowDiscussions' => 1, 'CategoryID <>' => -1));
     $Sender->EventCategory = C('Plugins.EventCalendar.CategoryIDs');
     $Sender->Render('settings', '', 'plugins/EventCalendar');
 }
Пример #4
0
 public function Save($FormPostValues, $Settings = FALSE)
 {
     // Get the ID of an existing tag with the same name.
     $ExistingTag = $this->GetWhere(array('Name' => $FormPostValues['Name'], 'TagID <>' => GetValue('TagID', $FormPostValues)))->FirstRow(DATASET_TYPE_ARRAY);
     if ($ExistingTag) {
         if (!GetValue('TagID', $FormPostValues)) {
             return $ExistingTag['TagID'];
         }
         // This tag will be merged with the existing one.
         $Px = $this->Database->DatabasePrefix;
         $FromID = $FormPostValues['TagID'];
         $ToID = $ExistingTag['TagID'];
         try {
             $this->Database->BeginTransaction();
             // Delete all of the overlapping tags.
             $Sql = "delete tg.*\n               from {$Px}TagDiscussion tg\n               join {$Px}TagDiscussion tg2\n                 on tg.DiscussionID = tg2.DiscussionID\n                   and tg.TagID = :FromID and tg2.TagID = :ToID";
             $this->Database->Query($Sql, array(':FromID' => $FromID, ':ToID' => $ToID));
             // Update the tagged discussions.
             $Sql = "update {$Px}TagDiscussion\n               set TagID = :ToID\n               where TagID = :FromID";
             $this->Database->Query($Sql, array(':FromID' => $FromID, ':ToID' => $ToID));
             // Update the counts.
             $Sql = "update {$Px}Tag t\n               set CountDiscussions = (\n                  select count(DiscussionID)\n                  from {$Px}TagDiscussion td\n                  where td.TagID = t.TagID)\n                where t.TagID = :ToID";
             $this->Database->Query($Sql, array(':ToID' => $ToID));
             // Delete the old tag.
             $Sql = "delete from {$Px}Tag where TagID = :FromID";
             $this->Database->Query($Sql, array(':FromID' => $FromID));
             $this->Database->CommitTransaction();
         } catch (Exception $Ex) {
             $this->Database->RollbackTransaction();
             throw $Ex;
         }
     } else {
         parent::Save($FormPostValues, $Settings);
     }
 }
Пример #5
0
 /**
  * Class constructor. Defines the related database table name.
  */
 public function __construct()
 {
     self::$MemoryCache = array();
     parent::__construct('UserMeta');
     $this->SQL = clone Gdn::sql();
     $this->SQL->reset();
 }
Пример #6
0
 public function Save($PostValues, $EditingData = False)
 {
     ReplaceEmpty($PostValues, Null);
     $Insert = GetValue('ChunkID', $PostValues) === False;
     if ($Insert) {
         $this->AddUpdateFields($PostValues);
     }
     $RowID = parent::Save($PostValues);
     return $RowID;
 }
 public function Delete($ActivityID)
 {
     // Get the activity first
     $Activity = $this->GetID($ActivityID);
     if (is_object($Activity)) {
         $Users = array();
         $Users[] = $Activity->ActivityUserID;
         if (is_numeric($Activity->RegardingUserID) && $Activity->RegardingUserID > 0) {
             $Users[] = $Activity->RegardingUserID;
         }
         // Update the user's dateupdated field so that profile pages will not
         // be cached and will reflect this deletion.
         $this->SQL->Update('User')->Set('DateUpdated', Gdn_Format::ToDateTime())->WhereIn('UserID', $Users)->Put();
         // Delete comments on the activity item
         parent::Delete(array('CommentActivityID' => $ActivityID), FALSE, TRUE);
         // Delete the activity item
         parent::Delete(array('ActivityID' => $ActivityID));
     }
 }
Пример #8
0
 /**
  * Class constructor. Defines the related database table name.
  *
  * @since 2.0.0
  * @access public
  *
  * @param string $Name Database table name.
  */
 public function __construct($Name = '')
 {
     parent::__construct($Name);
 }
Пример #9
0
 /**
  * Class constructor. Defines the related database table name.
  */
 public function __construct()
 {
     parent::__construct('Regarding');
 }
Пример #10
0
 public function __construct($ImportPath = '')
 {
     $this->ImportPath = $ImportPath;
     parent::__construct();
 }
Пример #11
0
 /**
  * Get a user by ID.
  *
  * @param int $ID The ID of the user.
  * @param string|false $DatasetType Whether to return an array or object.
  * @param array $Options Additional options to affect fetching. Currently unused.
  * @return array|object|false Returns the user or **false** if the user wasn't found.
  */
 public function getID($ID, $DatasetType = false, $Options = [])
 {
     if (!$ID) {
         return false;
     }
     $DatasetType = $DatasetType ?: DATASET_TYPE_OBJECT;
     // Check page cache, then memcached
     $User = $this->getUserFromCache($ID, 'userid');
     // If not, query DB
     if ($User === Gdn_Cache::CACHEOP_FAILURE) {
         $User = parent::getID($ID, DATASET_TYPE_ARRAY);
         // We want to cache a non-existent user no-matter what.
         if (!$User) {
             $User = null;
         }
         $this->userCache($User, $ID);
     } elseif (!$User) {
         return false;
     }
     // Apply calculated fields
     $this->setCalculatedFields($User);
     // Allow FALSE returns
     if ($User === false || is_null($User)) {
         return false;
     }
     if (is_array($User) && $DatasetType == DATASET_TYPE_OBJECT) {
         $User = (object) $User;
     }
     if (is_object($User) && $DatasetType == DATASET_TYPE_ARRAY) {
         $User = (array) $User;
     }
     $this->EventArguments['LoadedUser'] =& $User;
     $this->fireEvent('AfterGetID');
     return $User;
 }
 /**
  * Class constructor. Defines the related database table name.
  */
 public function __construct()
 {
     parent::__construct('Invitation');
 }
Пример #13
0
 public function Picture($UserReference = '')
 {
     $this->Permission('Garden.SignIn.Allow');
     $Session = Gdn::Session();
     if (!$Session->IsValid()) {
         $this->Form->AddError('You must be authenticated in order to use this form.');
     }
     $this->GetUserInfo($UserReference);
     $this->Form->SetModel($this->UserModel);
     $this->Form->AddHidden('UserID', $this->User->UserID);
     if ($this->Form->AuthenticatedPostBack() === TRUE) {
         $UploadImage = new Gdn_UploadImage();
         try {
             // Validate the upload
             $TmpImage = $UploadImage->ValidateUpload('Picture');
             // Generate the target image name
             $TargetImage = $UploadImage->GenerateTargetName(PATH_ROOT . DS . 'uploads');
             $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
             // Delete any previously uploaded images
             @unlink(PATH_ROOT . DS . 'uploads' . DS . 'p' . $this->User->Photo);
             // Don't delete this one because it hangs around in activity streams:
             // @unlink(PATH_ROOT . DS . 'uploads' . DS . 't' . $this->User->Photo);
             @unlink(PATH_ROOT . DS . 'uploads' . DS . 'n' . $this->User->Photo);
             // Save the uploaded image in profile size
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'p' . $ImageBaseName, Gdn::Config('Garden.Profile.MaxHeight', 1000), Gdn::Config('Garden.Profile.MaxWidth', 250));
             // Save the uploaded image in preview size
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 't' . $ImageBaseName, Gdn::Config('Garden.Preview.MaxHeight', 100), Gdn::Config('Garden.Preview.MaxWidth', 75));
             // Save the uploaded image in thumbnail size
             $ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 50);
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'n' . $ImageBaseName, $ThumbSize, $ThumbSize, TRUE);
         } catch (Exception $ex) {
             $this->Form->AddError($ex->getMessage());
         }
         // If there were no errors, associate the image with the user
         if ($this->Form->ErrorCount() == 0) {
             $PhotoModel = new Gdn_Model('Photo');
             $PhotoID = $PhotoModel->Insert(array('Name' => $ImageBaseName));
             if (!$this->UserModel->Save(array('UserID' => $this->User->UserID, 'PhotoID' => $PhotoID, 'Photo' => $ImageBaseName))) {
                 $this->Form->SetValidationResults($this->UserModel->ValidationResults());
             }
         }
         // If there were no problems, redirect back to the user account
         if ($this->Form->ErrorCount() == 0) {
             Redirect('garden/profile/' . $UserReference);
         }
     }
     $this->Render();
 }
Пример #14
0
 public function Edit($UserID)
 {
     $this->Permission('Garden.Users.Edit');
     $this->AddJsFile('user.js');
     $this->AddSideMenu('garden/user');
     $RoleModel = new Gdn_Model('Role');
     $this->RoleData = $RoleModel->Get();
     $UserModel = new Gdn_UserModel();
     $this->User = $UserModel->Get($UserID);
     // Set the model on the form.
     $this->Form->SetModel($UserModel);
     // Make sure the form knows which item we are editing.
     $this->Form->AddHidden('UserID', $UserID);
     if (!$this->Form->AuthenticatedPostBack()) {
         $this->Form->SetData($this->User);
         $this->UserRoleData = $UserModel->GetRoles($UserID);
     } else {
         // If a new password was specified, add it to the form's collection
         $ResetPassword = $this->Form->GetValue('ResetPassword', FALSE);
         $NewPassword = $this->Form->GetValue('NewPassword', '');
         if ($ResetPassword !== FALSE) {
             $this->Form->SetFormValue('Password', $NewPassword);
         }
         if ($this->Form->Save(array('SaveRoles' => TRUE)) !== FALSE) {
             if ($this->Form->GetValue('Password', '') != '') {
                 $UserModel->SendPasswordEmail($UserID, $NewPassword);
             }
             $this->StatusMessage = T('Your changes have been saved successfully.');
         }
         $this->UserRoleData = $this->Form->GetFormValue('RoleID');
     }
     $this->Render();
 }
Пример #15
0
 /**
  * Class constructor. Defines the related database table name.
  */
 public function __construct()
 {
     parent::__construct('Permission');
 }
Пример #16
0
 public function Save($FormPostValues, $Settings = FALSE)
 {
     // The "location" is packed into a single input with a / delimiter. Need to explode it into three different fields for saving
     $Location = ArrayValue('Location', $FormPostValues, '');
     if ($Location != '') {
         $Location = explode('/', $Location);
         if ($Location[0] == 'Base') {
             $FormPostValues['Controller'] = 'Base';
         } else {
             if (count($Location) >= 1) {
                 $FormPostValues['Application'] = $Location[0];
             }
             if (count($Location) >= 2) {
                 $FormPostValues['Controller'] = $Location[1];
             }
             if (count($Location) >= 3) {
                 $FormPostValues['Method'] = $Location[2];
             }
         }
     }
     // Make sure that messages on the dashboard get dropped below the page heading.
     if ($FormPostValues['Application'] == 'Garden' && $FormPostValues['Controller'] == 'Settings' && $FormPostValues['Method'] == 'Index') {
         $FormPostValues['AssetTarget'] = 'Messages';
     }
     return parent::Save($FormPostValues, $Settings);
 }
 /**
  * Class constructor. Defines the related database table name.
  * 
  * @since 2.0.0
  * @access public
  */
 public function __construct()
 {
     parent::__construct('ConversationMessage');
     $this->PrimaryKey = 'MessageID';
 }
 public function __construct()
 {
     parent::__construct('UserAuthenticationProvider');
 }
Пример #19
0
 /**
  * Class constructor. Defines the related database table name.
  */
 public function __construct()
 {
     parent::__construct('Role');
 }
 /**
  *
  */
 public function __construct()
 {
     parent::__construct('UserAuthenticationProvider');
     $this->PrimaryKey = self::COLUMN_KEY;
 }
Пример #21
0
 /**
  * Class constructor. Defines the related database table name.
  */
 public function __construct()
 {
     parent::__construct('User');
 }
Пример #22
0
 /**
  * Delete a screenshot from an addon.
  *
  * @param string $AddonPictureID Picture id to remove.
  * @throws Gdn_UserException No permission to delete this picture.
  */
 public function deletePicture($AddonPictureID = '')
 {
     $AddonPictureModel = new Gdn_Model('AddonPicture');
     $Picture = $AddonPictureModel->getWhere(array('AddonPictureID' => $AddonPictureID))->firstRow();
     $AddonModel = new AddonModel();
     $Addon = $AddonModel->getID($Picture->AddonID);
     $Session = Gdn::session();
     if ($Session->UserID != $Addon['InsertUserID'] && !$Session->checkPermission('Addons.Addon.Manage')) {
         throw permissionException();
     }
     if ($this->Form->authenticatedPostBack() && $this->Form->getFormValue('Yes')) {
         if ($Picture) {
             $Upload = new Gdn_Upload();
             $Upload->delete(changeBasename($Picture->File, 'ao%s'));
             $Upload->delete(changeBasename($Picture->File, 'at%s'));
             $AddonPictureModel->delete(array('AddonPictureID' => $AddonPictureID));
         }
         $this->RedirectUrl = url('/addon/' . $Picture->AddonID);
     }
     $this->render('deletepicture');
 }
Пример #23
0
 /**
  * Class constructor. Defines the related database table name.
  * 
  * @since 2.0.0
  * @access public
  */
 public function __construct()
 {
     parent::__construct('Conversation');
 }
 public function GetID($ID, $DatasetType = DATASET_TYPE_OBJECT)
 {
     if (!$ID) {
         return FALSE;
     }
     // Check page cache, then memcached
     $User = $this->GetUserFromCache($ID, 'userid');
     // If not, query DB
     if ($User === Gdn_Cache::CACHEOP_FAILURE) {
         $User = parent::GetID($ID, DATASET_TYPE_ARRAY);
         if ($User) {
             // If success, build more data, then cache user
             $this->SetCalculatedFields($User);
             $this->UserCache($User);
         }
     }
     // Allow FALSE returns
     if ($User === FALSE || is_null($User)) {
         return FALSE;
     }
     if (is_array($User) && $DatasetType == DATASET_TYPE_OBJECT) {
         $User = (object) $User;
     }
     if (is_object($User) && $DatasetType == DATASET_TYPE_ARRAY) {
         $User = (array) $User;
     }
     $this->EventArguments['LoadedUser'] =& $User;
     $this->FireEvent('AfterGetID');
     return $User;
 }
Пример #25
0
 /**
  * Save a message.
  *
  * @param array $FormPostValues Message data.
  * @param bool $Settings
  * @return int The MessageID.
  */
 public function save($FormPostValues, $Settings = false)
 {
     // The "location" is packed into a single input with a / delimiter. Need to explode it into three different fields for saving
     $Location = val('Location', $FormPostValues, '');
     if ($Location != '') {
         $Location = explode('/', $Location);
         $Application = val(0, $Location, '');
         if (in_array($Application, $this->_SpecialLocations)) {
             $FormPostValues['Application'] = null;
             $FormPostValues['Controller'] = $Application;
             $FormPostValues['Method'] = null;
         } else {
             $FormPostValues['Application'] = $Application;
             $FormPostValues['Controller'] = val(1, $Location, '');
             $FormPostValues['Method'] = val(2, $Location, '');
         }
     }
     Gdn::cache()->remove('Messages');
     return parent::save($FormPostValues, $Settings);
 }
Пример #26
0
 /**
  * Class constructor. Defines the related database table name.
  *
  * @since 2.0.0
  * @access public
  */
 public function __construct()
 {
     parent::__construct('Category');
     $this->collection = new CategoryCollection();
     $this->collection->setConfig(Gdn::config());
 }
Пример #27
0
 /**
  * Class constructor. Defines the related database table name.
  * 
  * @since 2.0.0
  * @access public
  */
 public function __construct()
 {
     parent::__construct('Category');
 }
Пример #28
0
 /**
  * Save data about ban from form.
  *
  * @since 2.0.18
  * @access public
  * 
  * @param array $FormPostValues
  * @param array $Settings
  */
 public function Save($FormPostValues, $Settings = FALSE)
 {
     $CurrentBanID = GetValue('BanID', $FormPostValues);
     // Get the current ban before saving.
     if ($CurrentBanID) {
         $CurrentBan = $this->GetID($CurrentBanID, DATASET_TYPE_ARRAY);
     } else {
         $CurrentBan = NULL;
     }
     $this->SetCounts($FormPostValues);
     $BanID = parent::Save($FormPostValues, $Settings);
     $FormPostValues['BanID'] = $BanID;
     $this->ApplyBan($FormPostValues, $CurrentBan);
 }
Пример #29
0
 /**
  * Create and display a thumbnail of an uploaded file.
  */
 public function utilityController_mediaThumbnail_create($sender, $media_id)
 {
     // When it makes it into core, it will be available in
     // functions.general.php
     require 'generate_thumbnail.php';
     $model = new Gdn_Model('Media');
     $media = $model->getID($media_id, DATASET_TYPE_ARRAY);
     if (!$media) {
         throw notFoundException('File');
     }
     // Get actual path to the file.
     $local_path = Gdn_Upload::copyLocal($media['Path']);
     if (!file_exists($local_path)) {
         throw notFoundException('File');
     }
     $file_extension = pathinfo($local_path, PATHINFO_EXTENSION);
     // Generate new path for thumbnail
     $thumb_path = $this->getBaseUploadDestinationDir() . '/' . 'thumb';
     // Grab full path with filename, and validate it.
     $thumb_destination_path = $this->getAbsoluteDestinationFilePath($local_path, $file_extension, $thumb_path);
     // Create thumbnail, and grab debug data from whole process.
     $thumb_payload = generate_thumbnail($local_path, $thumb_destination_path, array('height' => c('Plugins.FileUpload.ThumbnailHeight', 128)));
     if ($thumb_payload['success'] === true) {
         // Thumbnail dimensions
         $thumb_height = round($thumb_payload['result_height']);
         $thumb_width = round($thumb_payload['result_width']);
         // Move the thumbnail to its proper location. Calling SaveAs with
         // cloudfiles enabled will trigger the move to cloudfiles, so use
         // same path for each arg in SaveAs. The file will be removed from the local filesystem.
         $parsed = Gdn_Upload::parse($thumb_destination_path);
         $target = $thumb_destination_path;
         // $parsed['Name'];
         $Upload = new Gdn_Upload();
         $filepath_parsed = $Upload->saveAs($thumb_destination_path, $target, array('source' => 'content'));
         // Save thumbnail information to DB.
         $model->save(array('MediaID' => $media_id, 'StorageMethod' => $filepath_parsed['Type'], 'ThumbWidth' => $thumb_width, 'ThumbHeight' => $thumb_height, 'ThumbPath' => $filepath_parsed['SaveName']));
         // Remove cf scratch copy, typically in cftemp, if there was actually a file pulled in from CF.
         if (strpos($local_path, 'cftemp') !== false) {
             if (!unlink($local_path)) {
                 // Maybe add logging for local cf copies not deleted.
             }
         }
         $url = $filepath_parsed['Url'];
     } else {
         // Fix the thumbnail information so this isn't requested again and again.
         $model->save(array('MediaID' => $media_id, 'ImageWidth' => 0, 'ImageHeight' => 0, 'ThumbPath' => ''));
         $url = asset('/plugins/FileUpload/images/file.png');
     }
     redirect($url, 301);
 }
Пример #30
0
 /**
  * Get a particular activity record.
  *
  * @since 2.0.0
  * @access public
  * @param int $ActivityID Unique ID of activity item.
  * @return array|object A single SQL result.
  */
 public function GetID($ActivityID, $DataType = FALSE)
 {
     $Activity = parent::GetID($ActivityID, $DataType);
     if ($Activity) {
         $this->CalculateRow($Activity);
         $Activities = array($Activity);
         self::JoinUsers($Activities);
         $Activity = array_pop($Activities);
     }
     return $Activity;
 }