<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.6 |
+ | CiviCRM version 4.7 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
* $Id$
*
*/
class CRM_Core_Page_AJAX {
/**
- * Call generic ajax forms
+ * Call generic ajax forms.
*
*/
public static function run() {
}
/**
- * Change is_quick_config priceSet to complex
+ * Change is_quick_config priceSet to complex.
*
*/
public static function setIsQuickConfig() {
// 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>";
}
/**
- * Set headers appropriate for a js file
- */
- public static function setJsHeaders() {
- // Encourage browsers to cache for a long time - 1 year
- $year = 60 * 60 * 24 * 364;
- header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $year));
- header('Content-Type: application/javascript');
- header("Cache-Control: max-age=$year, public");
- }
-
- /**
- * Send autocomplete results to the client. Input can be a simple or nested array.
- * @param array $results
- * If nested array, also provide:.
- * @param string $val
- * Array key to use as the value.
- * @param string $key
- * Array key to use as the key.
- * @deprecated
+ * Set headers appropriate for a js file.
+ *
+ * @param int|NULL $ttl
+ * Time-to-live (seconds).
*/
- public static function autocompleteResults($results, $val = 'label', $key = 'id') {
- $output = array();
- if (is_array($results)) {
- foreach ($results as $k => $v) {
- if (is_array($v)) {
- echo $v[$val] . '|' . $v[$key] . "\n";
- }
- else {
- echo "$v|$k\n";
- }
- }
- }
- CRM_Utils_System::civiExit();
+ public static function setJsHeaders($ttl = NULL) {
+ if ($ttl === NULL) {
+ // Encourage browsers to cache for a long time - 1 year
+ $ttl = 60 * 60 * 24 * 364;
+ }
+ 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");
}
}