'links',
);
}
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($batches, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
$iFilteredTotal = $iTotal;
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
$iFilteredTotal = $iTotal;
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
$iFilteredTotal = $iTotal;
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
$iFilteredTotal = $iTotal;
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
}
public static function groupTree() {
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
$gids = CRM_Utils_Type::escape($_GET['gids'], 'String');
echo CRM_Contact_BAO_GroupNestingCache::json($gids);
CRM_Utils_System::civiExit();
* Delete custom value.
*/
public static function deleteCustomValue() {
- header('Content-Type: text/plain');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain');
$customValueID = CRM_Utils_Type::escape($_REQUEST['valueID'], 'Positive');
$customGroupID = CRM_Utils_Type::escape($_REQUEST['groupID'], 'Positive');
$userEmail
) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
- header('Content-Type: text/plain');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain');
if ($userEmail) {
echo $userEmail;
}
}
}
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
header('HTTP/1.0 403 Forbidden');
return;
}
- header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', CRM_Utils_Time::getTimeRaw() + $ttl));
- header("Content-Type: $mimeType");
- header("Content-Disposition: inline; filename=\"" . basename($file) . "\"");
- header("Cache-Control: max-age=$ttl, public");
- header('Pragma: public');
+ CRM_Utils_System::setHttpHeader('Expires', gmdate('D, d M Y H:i:s \G\M\T', CRM_Utils_Time::getTimeRaw() + $ttl));
+ CRM_Utils_System::setHttpHeader("Content-Type", $mimeType);
+ CRM_Utils_System::setHttpHeader("Content-Disposition", "inline; filename=\"" . basename($file) . "\"");
+ CRM_Utils_System::setHttpHeader("Cache-Control", "max-age=$ttl, public");
+ CRM_Utils_System::setHttpHeader('Pragma', 'public');
readfile($file);
}
*/
public function setWord($fileName = NULL) {
//Mark as a CSV file.
- header('Content-Type: application/vnd.ms-word');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/vnd.ms-word');
//Force a download and name the file using the current timestamp.
if (!$fileName) {
$fileName = 'Contacts_' . $_SERVER['REQUEST_TIME'] . '.doc';
}
- header("Content-Disposition: attachment; filename=Contacts_$fileName");
+ CRM_Utils_System::setHttpHeader("Content-Disposition", "attachment; filename=Contacts_$fileName");
}
/**
*/
public function setExcel($fileName = NULL) {
//Mark as an excel file.
- header('Content-Type: application/vnd.ms-excel');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/vnd.ms-excel');
//Force a download and name the file using the current timestamp.
if (!$fileName) {
$fileName = 'Contacts_' . $_SERVER['REQUEST_TIME'] . '.xls';
}
- header("Content-Disposition: attachment; filename=Contacts_$fileName");
+ CRM_Utils_System::setHttpHeader("Content-Disposition", "attachment; filename=Contacts_$fileName");
}
/**
// CRM-11831 @see http://www.malsup.com/jquery/form/#file-upload
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
}
else {
$output = "<textarea>$output</textarea>";
// Encourage browsers to cache for a long time - 1 year
$ttl = 60 * 60 * 24 * 364;
}
- header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $ttl));
- header('Content-Type: application/javascript');
- header("Cache-Control: max-age=$ttl, public");
+ CRM_Utils_System::setHttpHeader('Expires', gmdate('D, d M Y H:i:s \G\M\T', time() + $ttl));
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/javascript');
+ CRM_Utils_System::setHttpHeader('Cache-Control', "max-age=$ttl, public");
}
}
if ($isError) {
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') {
- header("Status: 500 Internal Server Error");
+ CRM_Utils_System::setHttpHeader("Status", "500 Internal Server Error");
}
else {
header("HTTP/1.1 500 Internal Server Error");
'class',
);
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($options, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
$errorFileName = $parserName::errorFileName($type);
$saveFileName = $parserName::saveFileName($type);
if (!empty($errorFileName) && !empty($saveFileName)) {
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Content-Description: File Transfer');
- header('Content-Type: text/csv');
- header('Content-Length: ' . filesize($errorFileName));
- header('Content-Disposition: attachment; filename=' . $saveFileName);
+ CRM_Utils_System::setHttpHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
+ CRM_Utils_System::setHttpHeader('Content-Description', 'File Transfer');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/csv');
+ CRM_Utils_System::setHttpHeader('Content-Length', filesize($errorFileName));
+ CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . $saveFileName);
readfile($errorFileName);
}
$zip = $config->customFileUploadDir . 'Financial_Transactions_' . date('YmdHis') . '.zip';
$result = $this->createZip($this->_downloadFile, $zip, TRUE);
if ($result) {
- header('Content-Type: application/zip');
- header('Content-Disposition: attachment; filename=' . CRM_Utils_File::cleanFileName(basename($zip)));
- header('Content-Length: ' . filesize($zip));
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/zip');
+ CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . CRM_Utils_File::cleanFileName(basename($zip)));
+ CRM_Utils_System::setHttpHeader('Content-Length', '' . filesize($zip));
ob_clean();
flush();
readfile($config->customFileUploadDir . CRM_Utils_File::cleanFileName(basename($zip)));
}
}
else {
- header('Content-Type: text/plain');
- header('Content-Disposition: attachment; filename=' . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0])));
- header('Content-Length: ' . filesize($this->_downloadFile[0]));
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain');
+ CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0])));
+ CRM_Utils_System::setHttpHeader('Content-Length', '' . filesize($this->_downloadFile[0]));
ob_clean();
flush();
readfile($config->customFileUploadDir . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0])));
'action',
);
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
if (!empty($params['is_unit_test'])) {
return array($groups, $iFilteredTotal);
}
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($groups, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
);
if ($type == 'html') {
- header('Content-Type: text/html; charset=utf-8');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/html; charset=utf-8');
print $mime->getHTMLBody();
}
else {
- header('Content-Type: text/plain; charset=utf-8');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain; charset=utf-8');
print $mime->getTXTBody();
}
CRM_Utils_System::civiExit();
//Load the image
$chart = imagecreatefrompng($uploadUrl);
//convert it into formatted png
- header('Content-type: image/png');
+ CRM_Utils_System::setHttpHeader('Content-type', 'image/png');
//overwrite with same image
imagepng($chart, $uploadImg);
//delete the object
*/
public static function export2csv(&$form, &$rows) {
//Mark as a CSV file.
- header('Content-Type: text/csv');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/csv');
//Force a download and name the file using the current timestamp.
$datetime = date('Ymd-Gi', $_SERVER['REQUEST_TIME']);
- header('Content-Disposition: attachment; filename=Report_' . $datetime . '.csv');
+ CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=Report_' . $datetime . '.csv');
echo self::makeCsv($form, $rows);
CRM_Utils_System::civiExit();
}
public static function send($calendar, $content_type = 'text/calendar', $charset = 'us-ascii', $fileName = NULL, $disposition = NULL) {
$config = CRM_Core_Config::singleton();
$lang = $config->lcMessages;
- header("Content-Language: $lang");
- // header( "Content-Type: $content_type; charset=$charset; profile=\"ICalendar\"" );
- header("Content-Type: $content_type; charset=$charset");
+ CRM_Utils_System::setHttpHeader("Content-Language", $lang);
+ CRM_Utils_System::setHttpHeader("Content-Type", "$content_type; charset=$charset");
if ($content_type == 'text/calendar') {
- header('Content-Length: ' . strlen($calendar));
- header("Content-Disposition: $disposition; filename=\"$fileName\"");
- header("Pragma: no-cache");
- header("Expires: 0");
- header("Cache-Control: no-cache, must-revalidate");
+ CRM_Utils_System::setHttpHeader('Content-Length', strlen($calendar));
+ CRM_Utils_System::setHttpHeader("Content-Disposition", "$disposition; filename=\"$fileName\"");
+ CRM_Utils_System::setHttpHeader("Pragma", "no-cache");
+ CRM_Utils_System::setHttpHeader("Expires", "0");
+ CRM_Utils_System::setHttpHeader("Cache-Control", "no-cache, must-revalidate");
}
echo $calendar;
* @param mixed $input
*/
public static function output($input) {
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo json_encode($input);
CRM_Utils_System::civiExit();
}
return $pdf;
}
else {
- header('Content-Type: application/pdf');
- header('Content-Disposition: attachment; filename="' . $fileName . '"');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/pdf');
+ CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"');
echo $pdf;
}
}
$len = strlen($buf);
if ($echo) {
- header('Content-type: application/pdf');
- header("Content-Length: $len");
- header("Content-Disposition: inline; filename={$output}.pdf");
+ CRM_Utils_System::setHttpHeader('Content-type', 'application/pdf');
+ CRM_Utils_System::setHttpHeader("Content-Length", $len);
+ CRM_Utils_System::setHttpHeader("Content-Disposition", "inline; filename={$output}.pdf");
echo $buf;
CRM_Utils_System::civiExit();
}
}
if (!empty($requestParams['json'])) {
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
if (!empty($requestParams['prettyprint'])) {
// Used by the api explorer
return self::jsonFormated(array_merge($result));
* @param $pearError
*/
public static function fatal($pearError) {
- header('Content-Type: text/xml');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/xml');
$error = array();
$error['code'] = $pearError->getCode();
$error['error_message'] = $pearError->getMessage();
$smarty = CRM_Core_Smarty::singleton();
CRM_Utils_System::setTitle("$entity::$tplfile inline $tpl");
if (!$smarty->template_exists($tpl)) {
- header("Status: 404 Not Found");
+ CRM_Utils_System::setHttpHeader("Status", "404 Not Found");
die ("Can't find the requested template file templates/$tpl");
}
if (array_key_exists('id', $_GET)) {// special treatmenent, because it's often used
));
}
- header('Location: ' . $url);
+ self::setHttpHeader('Location', $url);
self::civiExit();
}
) {
$now = gmdate('D, d M Y H:i:s') . ' GMT';
- header('Content-Type: ' . $mimeType);
- header('Expires: ' . $now);
+ self::setHttpHeader('Content-Type', $mimeType);
+ self::setHttpHeader('Expires', $now);
// lem9 & loic1: IE need specific headers
$isIE = strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE');
$fileString = "filename=\"{$name}\"";
}
if ($isIE) {
- header("Content-Disposition: inline; $fileString");
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
+ self::setHttpHeader("Content-Disposition", "inline; $fileString");
+ self::setHttpHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
+ self::setHttpHeader('Pragma', 'public');
}
else {
- header("Content-Disposition: $disposition; $fileString");
- header('Pragma: no-cache');
+ self::setHttpHeader("Content-Disposition", "$disposition; $fileString");
+ self::setHttpHeader('Pragma', 'no-cache');
}
if ($output) {
return NULL;
}
+ /**
+ * @param string $name
+ * @param string $value
+ */
+ public static function setHttpHeader($name, $value) {
+ CRM_Core_Config::singleton()->userSystem->setHttpHeader($name, $value);
+ }
+
}
public function appendCoreResources(&$list) {
}
+ /**
+ * @param string $name
+ * @param string $value
+ */
+ public function setHttpHeader($name, $value) {
+ header("$name: $value");
+ }
+
}
return $timezone;
}
+ /**
+ * @inheritDoc
+ */
+ public function setHttpHeader($name, $value) {
+ drupal_add_http_header($name, $value);
+ }
+
}
return $timezone;
}
+ /**
+ * @inheritDoc
+ */
+ public function setHttpHeader($name, $value) {
+ drupal_set_header("$name: $value");
+ }
+
}
$cache_backend->deleteAll();
}
}
+
+ /**
+ * @inheritDoc
+ */
+ public function setHttpHeader($name, $value) {
+ \Symfony\Component\HttpFoundation\Response->headers->set($name, $value);
+ }
}
*/
public function logout() {
session_destroy();
- header("Location:index.php");
+ CRM_Utils_System::setHttpHeader("Location", "index.php");
}
/**
*/
public function logout() {
session_destroy();
- header("Location:index.php");
+ CRM_Utils_System::setHttpHeader("Location", "index.php");
}
/**