/** * Defines & retrieves the view and master view. Renders all content within * them to the screen. * * @param string $View * @param string $ControllerName * @param string $ApplicationFolder * @param string $AssetName The name of the asset container that the content should be rendered in. * @todo $View, $ControllerName, and $ApplicationFolder need correct variable types and descriptions. */ public function xRender($View = '', $ControllerName = FALSE, $ApplicationFolder = FALSE, $AssetName = 'Content') { // Remove the deliver type and method from the query string so they don't corrupt calls to Url. $this->Request->SetValueOn(Gdn_Request::INPUT_GET, 'DeliveryType', NULL); $this->Request->SetValueOn(Gdn_Request::INPUT_GET, 'DeliveryMethod', NULL); Gdn::PluginManager()->CallEventHandlers($this, $this->ClassName, $this->RequestMethod, 'Render'); if ($this->_DeliveryType == DELIVERY_TYPE_NONE) { return; } // Handle deprecated StatusMessage values that may have been added by plugins $this->InformMessage($this->StatusMessage); // If there were uncontrolled errors above the json data, wipe them out // before fetching it (otherwise the json will not be properly parsed // by javascript). if ($this->_DeliveryMethod == DELIVERY_METHOD_JSON) { ob_clean(); $this->ContentType('application/json'); $this->SetHeader('X-Content-Type-Options', 'nosniff'); } if ($this->_DeliveryMethod == DELIVERY_METHOD_TEXT) { $this->ContentType('text/plain'); } // Send headers to the browser $this->SendHeaders(); // Make sure to clear out the content asset collection if this is a syndication request if ($this->SyndicationMethod !== SYNDICATION_NONE) { $this->Assets['Content'] = ''; } // Define the view if (!in_array($this->_DeliveryType, array(DELIVERY_TYPE_BOOL, DELIVERY_TYPE_DATA))) { $View = $this->FetchView($View, $ControllerName, $ApplicationFolder); // Add the view to the asset container if necessary if ($this->_DeliveryType != DELIVERY_TYPE_VIEW) { $this->AddAsset($AssetName, $View, 'Content'); } } // Redefine the view as the entire asset contents if necessary if ($this->_DeliveryType == DELIVERY_TYPE_ASSET) { $View = $this->GetAsset($AssetName); } else { if ($this->_DeliveryType == DELIVERY_TYPE_BOOL) { // Or as a boolean if necessary $View = TRUE; if (property_exists($this, 'Form') && is_object($this->Form)) { $View = $this->Form->ErrorCount() > 0 ? FALSE : TRUE; } } } if ($this->_DeliveryType == DELIVERY_TYPE_MESSAGE && $this->Form) { $View = $this->Form->Errors(); } if ($this->_DeliveryType == DELIVERY_TYPE_DATA) { $ExitRender = $this->RenderData(); if ($ExitRender) { return; } } if ($this->_DeliveryMethod == DELIVERY_METHOD_JSON) { // Format the view as JSON with some extra information about the // success status of the form so that jQuery knows what to do // with the result. if ($this->_FormSaved === '') { // Allow for override $this->_FormSaved = property_exists($this, 'Form') && $this->Form->ErrorCount() == 0 ? TRUE : FALSE; } $this->SetJson('FormSaved', $this->_FormSaved); $this->SetJson('DeliveryType', $this->_DeliveryType); $this->SetJson('Data', base64_encode($View instanceof Gdn_IModule ? $View->ToString() : $View)); $this->SetJson('InformMessages', $this->_InformMessages); $this->SetJson('ErrorMessages', $this->_ErrorMessages); $this->SetJson('RedirectUrl', $this->RedirectUrl); // Make sure the database connection is closed before exiting. $this->Finalize(); if (!check_utf8($this->_Json['Data'])) { $this->_Json['Data'] = utf8_encode($this->_Json['Data']); } $Json = json_encode($this->_Json); // Check for jsonp call. if (($Callback = $this->Request->Get('callback', FALSE)) && $this->AllowJSONP()) { $Json = $Callback . '(' . $Json . ')'; } $this->_Json['Data'] = $Json; exit($this->_Json['Data']); } else { if (count($this->_InformMessages) > 0 && $this->SyndicationMethod === SYNDICATION_NONE) { $this->AddDefinition('InformMessageStack', base64_encode(json_encode($this->_InformMessages))); } if ($this->RedirectUrl != '' && $this->SyndicationMethod === SYNDICATION_NONE) { $this->AddDefinition('RedirectUrl', $this->RedirectUrl); } if ($this->_DeliveryMethod == DELIVERY_METHOD_XHTML && Debug()) { $this->AddModule('TraceModule'); } // Render if ($this->_DeliveryType == DELIVERY_TYPE_BOOL) { echo $View ? 'TRUE' : 'FALSE'; } else { if ($this->_DeliveryType == DELIVERY_TYPE_ALL) { // Add definitions to the page if ($this->SyndicationMethod === SYNDICATION_NONE) { $this->AddAsset('Foot', $this->DefinitionList()); } // Render $this->RenderMaster(); } else { if ($View instanceof Gdn_IModule) { $View->Render(); } else { echo $View; } } } } }