public function renderRaw()
 {
     $attachment = $this->_params['attachment'];
     if (!headers_sent() && function_exists('header_remove')) {
         header_remove('Expires');
         header('Cache-control: private');
     }
     $extension = XenForo_Helper_File::getFileExtension($attachment['filename']);
     $imageTypes = array('svg' => 'image/svg+xml', 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png');
     if (isset($imageTypes[$extension]) && ($attachment['width'] && $attachment['height'])) {
         $this->_response->setHeader('Content-type', $imageTypes[$extension], true);
         $this->setDownloadFileName($attachment['filename'], true);
     } else {
         $this->_response->setHeader('Content-type', 'application/octet-stream', true);
         $this->setDownloadFileName($attachment['filename']);
     }
     $this->_response->setHeader('ETag', '"' . $attachment['attach_date'] . '"', true);
     $this->_response->setHeader('Content-Length', $attachment['file_size'], true);
     $this->_response->setHeader('X-Content-Type-Options', 'nosniff');
     $attachmentFile = $this->_params['attachmentFile'];
     $options = XenForo_Application::getOptions();
     if ($options->SV_AttachImpro_XAR) {
         if (SV_AttachmentImprovements_AttachmentHelper::ConvertFilename($attachmentFile)) {
             if (XenForo_Application::debugMode() && $options->SV_AttachImpro_log) {
                 XenForo_Error::debug('X-Accel-Redirect:' . $attachmentFile);
             }
             $this->_response->setHeader('X-Accel-Redirect', $attachmentFile);
             return '';
         }
         if (XenForo_Application::debugMode() && $options->SV_AttachImpro_log) {
             XenForo_Error::debug('X-Accel-Redirect skipped');
         }
     }
     return new XenForo_FileOutput($attachmentFile);
 }
Example #2
0
 private function refreshDiscordId($discordId)
 {
     $options = XenForo_Application::get('options');
     if ($options->botSocket === '') {
         return;
     }
     XenForo_Error::debug("Refreshing user {$discordId}");
     $so = socket_create(AF_UNIX, SOCK_DGRAM, 0);
     if ($so === false) {
         $msg = socket_strerror(socket_last_error());
         $error = "Bot socket create failed: {$msg}";
         throw new Exception($error);
     }
     $res = socket_connect($so, $options->botSocket);
     if ($res === false) {
         $msg = socket_strerror(socket_last_error());
         $error = "Bot socket connect failed: {$msg}";
         throw new Exception($error);
     }
     $payload = json_encode(array('action' => 'refresh', 'user_id' => $discordId));
     $res = socket_write($so, $payload);
     socket_shutdown($so);
     socket_close($so);
     if ($res === false) {
         $error = "Bot socket send failed";
         throw new Exception($error);
     } else {
         if ($res < strlen($payload)) {
             // This will probably never happen.
             $error = "Bot socket did not send all data";
             throw new Exception($error);
         }
     }
 }
Example #3
0
 public function actionRespond()
 {
     $form = $this->_getFormOrError($this->_input->filterSingle('form_id', XenForo_Input::UINT));
     $fieldModel = $this->_getFieldModel();
     $destinationOptionModel = $this->_getDestinationOptionModel();
     $attachmentModel = $this->getModelFromCache('XenForo_Model_Attachment');
     $attachmentParams = array();
     $constraints = $attachmentModel->getAttachmentConstraints();
     // check to see if attachments are enabled
     $attachmentTypes = $destinationOptionModel->getAttachmentsDestinationHandlers($form['form_id']);
     if ($attachmentTypes) {
         $attachmentParams = array('hash' => md5(uniqid('', true)), 'content_type' => 'form', 'content_data' => array('form_id' => $form['form_id']));
         $attachmentHandler = $attachmentModel->getAttachmentHandler($attachmentParams['content_type']);
         if (!$attachmentHandler || !$attachmentHandler->canUploadAndManageAttachments($attachmentParams['content_data'])) {
             XenForo_Error::debug('form_destination_id ' . $form_destination_id . ' does not accept attachments for the user ' . XenForo_Visitor::getUserId());
             throw new XenForo_Exception(new XenForo_Phrase('attachment_cannot_be_shown_at_this_time'), true);
         }
         $constraints = $attachmentHandler->getAttachmentConstraints();
     }
     $params = array();
     if (XenForo_Visitor::getUserId()) {
         $params['visitor'] = XenForo_Visitor::getInstance();
     } else {
         $params['visitor'] = array('username' => 'Guest');
     }
     // process GET supplied default values
     $fields = $fieldModel->prepareFields($fieldModel->getFields(array('form_id' => $form['form_id'])), true);
     foreach ($fields as $fieldId => &$field) {
         $field['default_value'] = $this->_renderTemplate($field['default_value'], $params);
         $getDefaultValue = $this->_input->filterSingle($field['field_name'], XenForo_Input::STRING);
         if ($getDefaultValue) {
             $field['default_value'] = $getDefaultValue;
         }
     }
     $viewParams = array('form' => $form, 'fields' => $fields, 'attachmentManager' => !empty($attachmentTypes), 'attachmentParams' => $attachmentParams, 'attachmentConstraints' => $constraints, 'captcha' => XenForo_Captcha_Abstract::createDefault());
     return $this->responseView('LiquidPro_SimpleForms_ViewPublic_Form_Respond', 'form_respond', $viewParams);
 }
 public static function _getAttachmentConstraints($form_destination_id, $contentType, $contentData)
 {
     if (self::$attachmentModel === null) {
         self::$attachmentModel = XenForo_Model::create('XenForo_Model_Attachment');
     }
     $attachmentHandler = self::$attachmentModel->getAttachmentHandler($contentType);
     if (!$attachmentHandler || !$attachmentHandler->canUploadAndManageAttachments($contentData)) {
         XenForo_Error::debug('form_destination_id ' . $form_destination_id . ' does not accept attachments for the user ' . XenForo_Visitor::getUserId());
         throw new XenForo_Exception(new XenForo_Phrase('attachment_cannot_be_shown_at_this_time'), true);
     }
     return $attachmentHandler->getAttachmentConstraints();
 }