/** * Returns a single message object for the specified id or FALSE if not found. * * @param int $MessageID The MessageID to filter to. * @return array Requested message. */ public function getID($MessageID) { if (Gdn::cache()->activeEnabled()) { return self::messages($MessageID); } else { return parent::getID($MessageID); } }
/** * Returns a single message object for the specified id or FALSE if not found. * * @param int $messageID The MessageID to filter to. * @param string|false $datasetType The format of the message. * @param array $options Options to modify the behavior of the get. * @return array Requested message. */ public function getID($messageID, $datasetType = false, $options = array()) { if (Gdn::cache()->activeEnabled()) { $message = self::messages($messageID); if (!$message) { return $message; } if ($message instanceof Gdn_DataSet) { $message->datasetType($datasetType); } elseif ($datasetType === DATASET_TYPE_OBJECT) { return (object) $message; } else { return (array) $message; } } else { return parent::getID($messageID, $datasetType, $options); } }
/** * 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); }
/** * 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; }
/** * {@inheritDoc} * in addition; We CalculateRow on the record found (Add Attachments) * @see Gdn_Model::GetID */ public function getID($ID, $DatasetType = DATASET_TYPE_ARRAY, $Options = array()) { $DatasetType = DATASET_TYPE_ARRAY; $Row = (array) parent::getID($ID, $DatasetType, $Options); $this->calculateRow($Row); return $Row; }
/** * Get a particular activity record. * * @param int $activityID Unique ID of activity item. * @param string $dataSetType The format of the resulting data. * @param array $options Not used. * @return array|object A single SQL result. */ public function getID($activityID, $dataSetType = false, $options = []) { $Activity = parent::getID($activityID, $dataSetType); if ($Activity) { $this->calculateRow($Activity); $Activities = array($Activity); self::joinUsers($Activities); $Activity = array_pop($Activities); } return $Activity; }