/**
  * Get a request token
  * @return void
  */
 public function run()
 {
     if (AjaxInput::post('action') == 'getRequestToken') {
         $objResponse = new HtmlResponse(\RequestToken::get());
         $objResponse->send();
     }
 }
예제 #2
0
 /**
  * Log a message in Contao
  * @return void
  */
 public function run()
 {
     if (AjaxInput::get('action') == 'logMessage' && AjaxInput::get('logDetails')) {
         \System::log(AjaxInput::get('logDetails'), AjaxInput::get('logMethod') ?: __METHOD__, AjaxInput::get('logCategory') ?: TL_GENERAL);
         $objResponse = new HtmlResponse(1);
         $objResponse->send();
     }
 }
 /**
  * Generate a content element and return it as string
  *
  * @param mixed  $intId     A content element ID or a Model object
  * @param string $strColumn The column the element is in
  *
  * @return string The content element HTML markup
  */
 protected static function getContentElementAjax($intId, $strColumn = 'main')
 {
     if (is_object($intId)) {
         $objRow = $intId;
     } else {
         if (!strlen($intId) || $intId < 1) {
             return '';
         }
         $objRow = \ContentModel::findByPk($intId);
         if ($objRow === null) {
             return '';
         }
     }
     // Check the visibility (see #6311)
     if (!static::isVisibleElement($objRow)) {
         return '';
     }
     $strClass = \ContentElement::findClass($objRow->type);
     // Return if the class does not exist
     if (!class_exists($strClass)) {
         \System::log('Content element class "' . $strClass . '" (content element "' . $objRow->type . '") does not exist', __METHOD__, TL_ERROR);
         return '';
     }
     $objRow->typePrefix = 'ce_';
     $objElement = new $strClass($objRow, $strColumn);
     $strBuffer = AjaxInput::get('g') == '1' ? $objElement->generate() : $objElement->generateAjax();
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['getContentElement']) && is_array($GLOBALS['TL_HOOKS']['getContentElement'])) {
         foreach ($GLOBALS['TL_HOOKS']['getContentElement'] as $callback) {
             $strBuffer = static::importStatic($callback[0])->{$callback}[1]($objRow, $strBuffer, $objElement);
         }
     }
     return $strBuffer;
 }
예제 #4
0
 /**
  * Process the AJAX request, store POST vars in AJAXInput object, and run hooks
  *
  * @param	void
  * @return	void
  */
 public function run()
 {
     $intPage = (int) AjaxInput::get('pageId');
     if (!$intPage) {
         $intPage = (int) AjaxInput::get('page');
     }
     if ($intPage > 0) {
         // Get the current page object
         global $objPage;
         $objPage = $this->getPageDetails($intPage);
         // Define the static URL constants
         define('TL_FILES_URL', $objPage->staticFiles != '' && !$GLOBALS['TL_CONFIG']['debugMode'] ? $objPage->staticFiles . TL_PATH . '/' : '');
         define('TL_SCRIPT_URL', $objPage->staticSystem != '' && !$GLOBALS['TL_CONFIG']['debugMode'] ? $objPage->staticSystem . TL_PATH . '/' : '');
         define('TL_PLUGINS_URL', $objPage->staticPlugins != '' && !$GLOBALS['TL_CONFIG']['debugMode'] ? $objPage->staticPlugins . TL_PATH . '/' : '');
         // Get the page layout
         $objLayout = $this->getPageLayout($objPage);
         $objPage->template = strlen($objLayout->template) ? $objLayout->template : 'fe_page';
         $objPage->templateGroup = $objLayout->getRelated('pid')->templates;
         // Store the output format
         list($strFormat, $strVariant) = explode('_', $objLayout->doctype);
         $objPage->outputFormat = $strFormat;
         $objPage->outputVariant = $strVariant;
         // Use the global date format if none is set
         if ($objPage->dateFormat == '') {
             $objPage->dateFormat = $GLOBALS['TL_CONFIG']['dateFormat'];
         }
         if ($objPage->timeFormat == '') {
             $objPage->timeFormat = $GLOBALS['TL_CONFIG']['timeFormat'];
         }
         if ($objPage->datimFormat == '') {
             $objPage->datimFormat = $GLOBALS['TL_CONFIG']['datimFormat'];
         }
         // Set the admin e-mail address
         if ($objPage->adminEmail != '') {
             list($GLOBALS['TL_ADMIN_NAME'], $GLOBALS['TL_ADMIN_EMAIL']) = $this->splitFriendlyName($objPage->adminEmail);
         } else {
             list($GLOBALS['TL_ADMIN_NAME'], $GLOBALS['TL_ADMIN_EMAIL']) = $this->splitFriendlyName($GLOBALS['TL_CONFIG']['adminEmail']);
         }
         $GLOBALS['TL_LANGUAGE'] = $objPage->language;
     }
     $this->User->authenticate();
     // Set language from _GET
     if (strlen(AjaxInput::get('language'))) {
         $GLOBALS['TL_LANGUAGE'] = AjaxInput::get('language');
     }
     unset($GLOBALS['TL_HOOKS']['outputFrontendTemplate']);
     unset($GLOBALS['TL_HOOKS']['parseFrontendTemplate']);
     \System::loadLanguageFile('default');
     // HOOK:
     if (isset($GLOBALS['TL_HOOKS']['ajaxRequest']) && is_array($GLOBALS['TL_HOOKS']['ajaxRequest'])) {
         foreach ($GLOBALS['TL_HOOKS']['ajaxRequest'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]();
         }
     }
     // Generate a 412 error response if no output
     header('HTTP/1.1 412 Precondition Failed');
     die('Contao: Invalid AJAX call.');
 }