Commit fc4e9849 authored by Eric Rasmussen's avatar Eric Rasmussen
Browse files

[gh-450] Whitespace and Drupal coding standards

parent 422c628c
......@@ -187,26 +187,25 @@ function unl_user_is_administrator() {
* @param string $url
* @param resource $context
*/
function unl_url_get_contents($url, $context = NULL, &$headers = array())
{
function unl_url_get_contents($url, $context = NULL, &$headers = array()) {
unl_load_zend_framework();
if (!Zend_Uri::check($url)) {
drupal_set_message('A non-url was passed to ' . __FUNCTION__ . '().', 'warning');
return FALSE;
}
// get some per-request static storage
$static = &drupal_static(__FUNCTION__);
if (!isset($static)) {
$static = array();
}
// If cached in the static array, return it.
if (array_key_exists($url, $static)) {
$headers = $static[$url]['headers'];
return $static[$url]['body'];
}
// If cached in the drupla cache, return it.
$data = cache_get(__FUNCTION__ . $url);
if ($data && time() < $data->data['expires']) {
......@@ -217,13 +216,13 @@ function unl_url_get_contents($url, $context = NULL, &$headers = array())
// Make the request
$http_response_header = array();
$body = file_get_contents($url, NULL, $context);
// If an error occured, just return it now.
if ($body === FALSE) {
$static[$url] = $body;
return $body;
}
$headers = array();
foreach ($http_response_header as $rawHeader) {
$headerName = trim(substr($rawHeader, 0, strpos($rawHeader, ':')));
......@@ -233,10 +232,10 @@ function unl_url_get_contents($url, $context = NULL, &$headers = array())
}
}
$lowercaseHeaders = array_change_key_case($headers);
$cacheable = NULL;
$expires = 0;
// Check for a Cache-Control header and the max-age and/or private headers.
if (array_key_exists('cache-control', $lowercaseHeaders)) {
$cacheControl = strtolower($lowercaseHeaders['cache-control']);
......@@ -257,7 +256,7 @@ function unl_url_get_contents($url, $context = NULL, &$headers = array())
$cacheable = TRUE;
$expires = DateTime::createFromFormat(DateTime::RFC1123, $lowercaseHeaders['expires'])->getTimestamp();
}
// Save to the drupal cache if caching is ok
if ($cacheable && time() < $expires) {
$data = array(
......@@ -274,6 +273,6 @@ function unl_url_get_contents($url, $context = NULL, &$headers = array())
'headers' => $headers,
);
}
return $body;
}
......@@ -1517,8 +1517,7 @@ function unl_query_alter(QueryAlterableInterface $query) {
/**
* Implementation of hook_filter_info()
*/
function unl_filter_info()
{
function unl_filter_info() {
return array(
'unl_embed' => array(
'title' => 'UNL Node Embed',
......@@ -1540,8 +1539,7 @@ function unl_filter_info()
*
* Replace any instances of [[node:X]] in the $text with the content of node X's body.
*/
function unl_filter_embed_process($text, $filter, $format, $langcode, $cache, $cache_id)
{
function unl_filter_embed_process($text, $filter, $format, $langcode, $cache, $cache_id) {
static $processed_hashes = array();
$text_hash = hash('sha256', $text);
......@@ -1598,7 +1596,8 @@ function unl_filter_ssi_process($text, $filter, $format, $langcode, $cache, $cac
if (isset($parts['path']) && substr($parts['path'], 0, 1) != '/') {
if (variable_get('unl_use_base_tag')) {
$parts['path'] = $GLOBALS['base_path'] . $parts['path'];
} else {
}
else {
$parts['path'] = $GLOBALS['base_path'] . request_path() . '/' . $parts['path'];
}
}
......@@ -1607,12 +1606,12 @@ function unl_filter_ssi_process($text, $filter, $format, $langcode, $cache, $cac
}
$url = $parts['scheme'] . '://' . $parts['host'] . $parts['path'];
// If this is a request to another UNL site, add format=partial to the query.
if (substr($parts['host'], -7) == 'unl.edu') {
if (isset($parts['query']) && $parts['query']) {
$parts['query'] .= '&';
} else {
}
else {
$parts['query'] = '';
}
$parts['query'] .= 'format=partial';
......@@ -1637,11 +1636,11 @@ function unl_filter_ssi_process($text, $filter, $format, $langcode, $cache, $cac
'header' => "x-unl-ssi-depth: $ssiDepth\r\n",
),
));
if ($ssiDepth > 3) {
watchdog('unl', 'Server Side Include: Recursion depth limit reached.', array(), WATCHDOG_ERROR);
drupal_add_http_header('x-unl-ssi-error', 'Too deep!');
$content = '<!-- Error: Too many recursive includes! Content from ' . $url . ' was not included! -->';
$content = '<!-- Error: Too many recursive includes! Content from ' . $url . ' was not included! -->';
}
else {
$headers = array();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment