本文整理汇总了PHP中JResponse::setHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP JResponse::setHeader方法的具体用法?PHP JResponse::setHeader怎么用?PHP JResponse::setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JResponse
的用法示例。
在下文中一共展示了JResponse::setHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: displayListMention
/**
* Method to return list of users by ajax request for userlist and search user
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @since K4.0
* @return JSon
*/
public function displayListMention($tpl = null)
{
$response = array();
if ($this->me->exists())
{
$users = $this->get('Items');
foreach ($users as $user)
{
$user_obj = new stdClass();
$user_obj->id = $user->id;
$user_obj->photo = $user->getAvatarURL();
$user_obj->name = $user->username;
$response[] = $user_obj;
}
}
// Set the MIME type and header for JSON output.
$this->document->setMimeEncoding('application/json');
JResponse::setHeader('Content-Disposition', 'attachment; filename="' . $this->getName() . '.' . $this->getLayout() . '.json"');
echo json_encode($response);
}
示例2: sendError
private function sendError($exception)
{
JResponse::setHeader('status', $exception->getCode());
$error = new APIException($exception->getMessage(), $exception->getCode());
JFactory::getDocument()->setMimeEncoding('application/json');
return json_encode($error->toArray());
}
示例3: render
/**
* Render the document
*
* @param boolean $cache If true, cache the output
* @param array $params Associative array of attributes
*
* @return string The rendered data
*
* @since 11.1
*/
public function render($cache = false, $params = array())
{
// If no error object is set return null
if (!isset($this->_error)) {
return;
}
//Set the status header
JResponse::setHeader('status', $this->_error->getCode() . ' ' . str_replace("\n", ' ', $this->_error->getMessage()));
$file = 'error.php';
// check template
$directory = isset($params['directory']) ? $params['directory'] : 'templates';
$template = isset($params['template']) ? JFilterInput::getInstance()->clean($params['template'], 'cmd') : 'system';
if (!file_exists($directory . '/' . $template . '/' . $file)) {
$template = 'system';
}
//set variables
$this->baseurl = JURI::base(true);
$this->template = $template;
$this->debug = isset($params['debug']) ? $params['debug'] : false;
$this->error = $this->_error;
// load
$data = $this->_loadTemplate($directory . '/' . $template, $file);
parent::render();
return $data;
}
示例4: calc
function calc()
{
//decode incoming JSON string
$jsonRequest = JRequest::getVar("jsonString", "", "get");
$jsonRequest = json_decode($jsonRequest);
$calc_result = $this->_model->calcPrice($jsonRequest);
$data = new stdclass();
$data->amount = $calc_result['amount'];
$data->amount_value = $calc_result['amount_value'];
$data->tax = $calc_result['tax'];
$data->tax_value = $calc_result['tax_value'];
$data->discount_sign = $calc_result['discount_sign'];
$data->discount = $calc_result['discount'];
$data->total = $calc_result['total'];
$data->total_value = $calc_result['total_value'];
$data->currency = $calc_result['currency'];
// Get the document object.
$document = JFactory::getDocument();
// Set the MIME type for JSON output.
$document->setMimeEncoding('application/json');
// Change the suggested filename.
JResponse::setHeader('Content-Disposition', 'attachment;filename="orders.json"');
// Output the JSON data.
echo json_encode($data);
JFactory::getApplication()->close();
}
示例5: getErrorResponse
public final function getErrorResponse($code = 400, $message = '', $set_status = true)
{
if (true === $set_status) {
JResponse::setHeader('status', $code, true);
}
return (object) array('error' => true, 'code' => $code, 'message' => JText::_($message));
}
示例6: render
/**
* Render the document.
*
* @param boolean $cache If true, cache the output
* @param array $params Associative array of attributes
*
* @return The rendered data
*
* @since 11.1
*/
public function render($cache = false, $params = array())
{
parent::render();
JResponse::setHeader('Content-disposition', 'inline; filename="' . $this->getName() . '.xml"', true);
return $this->getBuffer();
}
示例7: append
/**
* Method for to append new track into database
*
*/
function append()
{
$dispatcher = JDispatcher::getInstance();
// Send the appropriate error code response.
JResponse::clearHeaders();
JResponse::setHeader('Content-Type', 'application/json; charset=utf-8');
JResponse::sendHeaders();
$total = $_GET['total'];
$one_procent = 1 / ($total / 100);
$curr_index = number_format($_GET['total'] * $_GET['status'] / 100, 0, '', '');
$path_from_cache = explode('*|*', JFactory::getApplication()->getUserState('com_playjoom.path.array'));
$php_array['status'] = $_GET['status'] + $one_procent;
//$dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__.":".__LINE__, 'message' => 'Add track no '.$curr_index.' in path: '.base64_decode(($path_from_cache[$curr_index] - 1)), 'priority' => JLog::INFO, 'section' => 'admin')));
if (isset($path_from_cache[$curr_index])) {
$model = $this->getModel('savetracks');
$model->AddTrackItem(base64_decode($path_from_cache[$curr_index]), 'audio');
}
// Bei 100% ist Schluss ;)
if ($php_array['status'] > 100) {
$php_array['status'] = 100;
}
if ($php_array['status'] != 100 && isset($path_from_cache[$curr_index])) {
$php_array['message'] = JText::_('COM_PLAYJOOM_SAVETRACKS_CURRENT_STATUS') . ' ' . ($curr_index + 1) . ' / ' . $total . ' - ' . round($php_array['status'], 1) . '%';
$php_array['message_path'] = JText::_('COM_PLAYJOOM_SAVETRACKS_PATH_STATUS') . ' ' . base64_decode($path_from_cache[$curr_index]);
} else {
//Clear UserStates in session
JFactory::getApplication()->setUserState('com_playjoom.savetracks', null);
JFactory::getApplication()->setUserState('com_playjoom.path.array', null);
JFactory::getApplication()->setUserState('com_playjoom.path.data', null);
$php_array['message'] = 'done';
}
// Output as PHP arrays as JSON Objekt
echo json_encode($php_array);
}
示例8: render
/**
* Render the document.
*
* @param boolean $cache If true, cache the output
* @param array $params Associative array of attributes
*
* @return The rendered data
*
* @since 11.1
*/
public function render($cache = false, $params = array())
{
JResponse::allowCache(false);
JResponse::setHeader('Content-disposition', 'attachment; filename="' . $this->getName() . '.json"', true);
parent::render();
return $this->getBuffer();
}
示例9: display
/**
* Display the view
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*/
public function display($tpl = null)
{
$basename = $this->get('BaseName');
$filetype = $this->get('FileType');
$mimetype = $this->get('MimeType');
$content = $this->get('Content');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
$document = JFactory::getDocument();
$document->setMimeEncoding($mimetype);
// Joomla 3
if (version_compare(JVERSION, '3.0', 'ge')) {
JFactory::getApplication()->setHeader('Content-disposition', 'attachment; filename="' . $basename . '.' . $filetype . '"; creation-date="' . JFactory::getDate()->toRFC822() . '"', true);
} else {
JResponse::setHeader('Content-disposition', 'attachment; filename="' . $basename . '.' . $filetype . '"; creation-date="' . JFactory::getDate()->toRFC822() . '"', true);
}
// Open file pointer to standard output
// $fp = fopen('php://output', 'w');
// Add BOM to fix UTF-8 in Excel
// fputs($fp, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));
// fclose($fp);
echo $content;
}
示例10: display
/**
* Display the template
*
* @param sting $tpl template
*
* @return void
*/
public function display($tpl = null)
{
if (parent::display($tpl) !== false) {
$app = JFactory::getApplication();
if (!$app->isAdmin()) {
$this->state = $this->get('State');
$this->params = $this->state->get('params');
$this->document = JFactory::getDocument();
if ($this->params->get('menu-meta_description')) {
$this->document->setDescription($this->params->get('menu-meta_description'));
}
if ($this->params->get('menu-meta_keywords')) {
$this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
}
if ($this->params->get('robots')) {
$this->document->setMetadata('robots', $this->params->get('robots'));
}
}
// Set the response to indicate a file download
JResponse::setHeader('Content-Type', 'application/vnd.ms-word');
$name = $this->getModel()->getTable()->label;
$name = JStringNormalise::toDashSeparated($name);
JResponse::setHeader('Content-Disposition', "attachment;filename=\"" . $name . ".doc\"");
$this->document->setMimeEncoding('text/html; charset=Windows-1252', false);
$this->output();
}
}
示例11: display
public function display()
{
// Get model data.
$state = $this->get('State');
$item = $this->get('Item');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseWarning(500, implode("\n", $errors));
return false;
}
$doc = JFactory::getDocument();
$doc->setMetaData('Content-Type', 'text/directory', true);
// Initialise variables.
$app = JFactory::getApplication();
$params = $app->getParams();
$user = JFactory::getUser();
$dispatcher = JEventDispatcher::getInstance();
// Compute lastname, firstname and middlename
$item->name = trim($item->name);
// "Lastname, Firstname Midlename" format support
// e.g. "de Gaulle, Charles"
$namearray = explode(',', $item->name);
if (count($namearray) > 1) {
$lastname = $namearray[0];
$card_name = $lastname;
$name_and_midname = trim($namearray[1]);
$firstname = '';
if (!empty($name_and_midname)) {
$namearray = explode(' ', $name_and_midname);
$firstname = $namearray[0];
$middlename = count($namearray) > 1 ? $namearray[1] : '';
$card_name = $firstname . ' ' . ($middlename ? $middlename . ' ' : '') . $card_name;
}
} else {
$namearray = explode(' ', $item->name);
$middlename = count($namearray) > 2 ? $namearray[1] : '';
$firstname = array_shift($namearray);
$lastname = count($namearray) ? end($namearray) : '';
$card_name = $firstname . ($middlename ? ' ' . $middlename : '') . ($lastname ? ' ' . $lastname : '');
}
$rev = date('c', strtotime($item->modified));
JResponse::setHeader('Content-disposition', 'attachment; filename="' . $card_name . '.vcf"', true);
$vcard = array();
$vcard[] .= 'BEGIN:VCARD';
$vcard[] .= 'VERSION:3.0';
$vcard[] = 'N:' . $lastname . ';' . $firstname . ';' . $middlename;
$vcard[] = 'FN:' . $item->name;
$vcard[] = 'TITLE:' . $item->con_position;
$vcard[] = 'TEL;TYPE=WORK,VOICE:' . $item->telephone;
$vcard[] = 'TEL;TYPE=WORK,FAX:' . $item->fax;
$vcard[] = 'TEL;TYPE=WORK,MOBILE:' . $item->mobile;
$vcard[] = 'ADR;TYPE=WORK:;;' . $item->address . ';' . $item->suburb . ';' . $item->state . ';' . $item->postcode . ';' . $item->country;
$vcard[] = 'LABEL;TYPE=WORK:' . $item->address . "\n" . $item->suburb . "\n" . $item->state . "\n" . $item->postcode . "\n" . $item->country;
$vcard[] = 'EMAIL;TYPE=PREF,INTERNET:' . $item->email_to;
$vcard[] = 'URL:' . $item->webpage;
$vcard[] = 'REV:' . $rev . 'Z';
$vcard[] = 'END:VCARD';
echo implode("\n", $vcard);
return true;
}
示例12: render
/**
* Render the document.
*
* @param boolean $cache If true, cache the output
* @param array $params Associative array of attributes
*
* @return The rendered data
*
* @since 3.1
*/
public function render($cache = false, $params = array())
{
JResponse::allowCache($cache);
JResponse::setHeader('Content-disposition', 'attachment; filename="' . $this->getName() . '.json"', true);
// Unfortunately, the exact syntax of the Content-Type header
// is not defined, so we have to try to be a bit clever here.
$contentType = $this->_mime;
if (stripos($contentType, 'json') === false) {
$contentType .= '+' . $this->_type;
}
$this->_mime = $contentType;
parent::render();
// Get the HAL object from the buffer.
$hal = $this->getBuffer();
// If required, change relative links to absolute.
if ($this->absoluteHrefs && is_object($hal) && isset($hal->_links)) {
// Adjust hrefs in the _links object.
$this->relToAbs($hal->_links);
// Adjust hrefs in the _embedded object (if there is one).
if (isset($hal->_embedded)) {
foreach ($hal->_embedded as $rel => $resources) {
foreach ($resources as $id => $resource) {
if (isset($resource->_links)) {
$this->relToAbs($resource->_links);
}
}
}
}
}
// Return it as a JSON string.
return json_encode($hal);
}
示例13: display
/**
* Return statistics XLS file
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*/
function display($tpl = null)
{
$this->item = $this->get('Item');
// Get parameters
$jinput = JFactory::getApplication()->input;
$type = $jinput->get('type', null, 'string');
$begin = $jinput->get('begin', null, 'string');
$end = $jinput->get('end', null, 'string');
// Convert date strings to JDate objects
$beginDate = new JDate($begin);
$endDate = new JDate($end . ' 23:59:59');
// Get statistic model
$statisticModel = JModelLegacy::getInstance('statistic', 'IsbnregistryModel');
// Get statistics
$data = $statisticModel->getStats($type, $beginDate, $endDate);
// Set document properties
$document = JFactory::getDocument();
$document->setMimeEncoding('application/vnd.ms-excel; charset="UTF-8"');
JResponse::setHeader('Content-disposition', 'attachment; filename="statistics.xml"', true);
// Get Excel helper
require_once JPATH_COMPONENT . '/helpers/php-export-data.class.php';
// Create new Excled worksheet
$excel = new ExportDataExcel('browser');
$excel->filename = "statistics.xml";
$excel->initialize();
// Loop through data array
foreach ($data as $row) {
// Add rows
$excel->addRow($row);
}
// Finalize
$excel->finalize();
}
示例14: display
/**
* Generates a list of JSON items.
*
* @return void
*/
function display($tpl = null)
{
$ta = (int) JRequest::getUInt('typeahead');
$s2 = (int) JRequest::getUInt('select2');
$resp = array();
// Get model data
$rows = $this->get('Items');
if ($ta) {
$tmp_rows = array();
foreach ($rows as &$row) {
$id = (int) $row->id;
$tmp_rows[$id] = $this->escape($row->title);
}
$rows = $tmp_rows;
} elseif ($s2) {
$tmp_rows = array();
foreach ($rows as &$row) {
$id = (int) $row->id;
$item = new stdClass();
$item->id = $id;
$item->text = $this->escape($row->title);
$tmp_rows[] = $item;
}
$rows = $tmp_rows;
$total = (int) $this->get('Total');
$rows = array('total' => $total, 'items' => $rows);
}
// Set the MIME type for JSON output.
JFactory::getDocument()->setMimeEncoding('application/json');
// Change the suggested filename.
JResponse::setHeader('Content-Disposition', 'attachment;filename="' . $this->getName() . '.json"');
// Output the JSON data.
echo json_encode($rows);
jexit();
}
示例15: plgSh404sefofflinecode
/**
* Output a correct response code when site is offline
* to let know search engines that site data
* should not be discarded or discounted
*/
function plgSh404sefofflinecode()
{
$app = JFactory::getApplication();
// are we in the backend, or not offline ?
if (!defined('SH404SEF_IS_RUNNING') || $app->isAdmin() || !$app->getCfg('offline')) {
return;
}
// get plugin params
$plugin =& JPluginHelper::getPlugin('sh404sefcore', 'sh404sefofflinecode');
$pluginParams = new JRegistry();
$pluginParams->loadString($plugin->params);
$disallowAdminAccess = $pluginParams->get('disallowAdminAccess', 0);
if (!$disallowAdminAccess) {
// admins are allowed, lets check if current user
// is an admin, or if user is trying to log in
$user =& JFactory::getUser();
$option = JRequest::getCmd('option');
$task = JRequest::getCmd('task');
if ($option == 'com_users' && $task == 'user.login') {
// Check for request forgeries
JRequest::checkToken() or jexit('Invalid Token');
$loggingIn = true;
} else {
$loggingIn = false;
}
// if already logged inadmin, or admin logging in, let it go
if ($user->authorize('core.manage', 'com_sh404sef') || $loggingIn) {
return;
}
}
// need to render offline screen
if ($disallowAdminAccess) {
// admins not allowed, use our own
// simplified template. Most likely being hacked so
// close doors as much as possible
$template = '';
$file = 'sh404sef_offline_template.php';
$directory = JPATH_ROOT . DS . 'plugins' . DS . 'sh404sefcore';
} else {
// admin can access, use Joomla! offline template,
// that includes a login form
$template = $app->getTemplate();
$file = 'offline.php';
$directory = JPATH_THEMES;
}
$params = array('template' => $template, 'file' => $file, 'directory' => $directory);
$document =& JFactory::getDocument();
$data = $document->render($app->getCfg('caching'), $params);
// header : service unavailable
JResponse::setHeader('HTTP/1.0 503', true);
// give it some time
$retryAfter = $pluginParams->get('retry_after_delay', 7400);
// set header
Jresponse::setheader('Retry-After', gmdate('D, d M Y H:i:s', time() + $retryAfter) . ' GMT');
// echo document
JResponse::setBody($data);
echo JResponse::toString($app->getCfg('gzip'));
// and terminate
$app->close();
}