Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UNL-CMS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
yzha1
UNL-CMS
Commits
f2931e82
Commit
f2931e82
authored
12 years ago
by
Tim Steiner
Browse files
Options
Downloads
Plain Diff
[gh-450] Merge branch 'issue-450' into develop
parents
8e5b0181
e3b766ef
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sites/all/modules/unl/includes/common.php
+15
-8
15 additions, 8 deletions
sites/all/modules/unl/includes/common.php
sites/all/modules/unl/unl.module
+25
-1
25 additions, 1 deletion
sites/all/modules/unl/unl.module
with
40 additions
and
9 deletions
sites/all/modules/unl/includes/common.php
+
15
−
8
View file @
f2931e82
...
...
@@ -187,7 +187,7 @@ function unl_user_is_administrator() {
* @param string $url
* @param resource $context
*/
function
unl_url_get_contents
(
$url
,
$context
=
NULL
)
function
unl_url_get_contents
(
$url
,
$context
=
NULL
,
&
$headers
=
array
()
)
{
unl_load_zend_framework
();
if
(
!
Zend_Uri
::
check
(
$url
))
{
...
...
@@ -203,12 +203,14 @@ function unl_url_get_contents($url, $context = NULL)
// If cached in the static array, return it.
if
(
array_key_exists
(
$url
,
$static
))
{
return
$static
[
$url
];
$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'
])
{
$headers
=
$data
->
data
[
'headers'
];
return
$data
->
data
[
'body'
];
}
...
...
@@ -224,19 +226,20 @@ function unl_url_get_contents($url, $context = NULL)
$headers
=
array
();
foreach
(
$http_response_header
as
$rawHeader
)
{
$headerName
=
strtolower
(
trim
(
substr
(
$rawHeader
,
0
,
strpos
(
$rawHeader
,
':'
)))
)
;
$headerName
=
trim
(
substr
(
$rawHeader
,
0
,
strpos
(
$rawHeader
,
':'
)));
$headerValue
=
trim
(
substr
(
$rawHeader
,
strpos
(
$rawHeader
,
':'
)
+
1
));
if
(
$headerName
&&
$headerValue
)
{
$headers
[
$headerName
]
=
$headerValue
;
}
}
$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'
,
$
h
eaders
))
{
$cacheControl
=
strtolower
(
$
h
eaders
[
'cache-control'
]);
if
(
array_key_exists
(
'cache-control'
,
$
lowercaseH
eaders
))
{
$cacheControl
=
strtolower
(
$
lowercaseH
eaders
[
'cache-control'
]);
$matches
=
array
();
if
(
preg_match
(
'/max-age=([0-9]+)/'
,
$cacheControl
,
$matches
))
{
$expires
=
time
()
+
$matches
[
1
];
...
...
@@ -250,22 +253,26 @@ function unl_url_get_contents($url, $context = NULL)
}
}
// If there was no Cache-Control header, or if it wasn't helpful, check for an Expires header.
if
(
$cacheable
===
NULL
&&
array_key_exists
(
'expires'
,
$
h
eaders
))
{
if
(
$cacheable
===
NULL
&&
array_key_exists
(
'expires'
,
$
lowercaseH
eaders
))
{
$cacheable
=
TRUE
;
$expires
=
DateTime
::
createFromFormat
(
DateTime
::
RFC1123
,
$
h
eaders
[
'expires'
])
->
getTimestamp
();
$expires
=
DateTime
::
createFromFormat
(
DateTime
::
RFC1123
,
$
lowercaseH
eaders
[
'expires'
])
->
getTimestamp
();
}
// Save to the drupal cache if caching is ok
if
(
$cacheable
&&
time
()
<
$expires
)
{
$data
=
array
(
'body'
=>
$body
,
'headers'
=>
$headers
,
'expires'
=>
$expires
,
);
cache_set
(
__FUNCTION__
.
$url
,
$data
,
'cache'
,
$expires
);
}
// Otherwise just save to the static per-request cache
else
{
$static
[
$url
]
=
$body
;
$static
[
$url
]
=
array
(
'body'
=>
$body
,
'headers'
=>
$headers
,
);
}
return
$body
;
...
...
This diff is collapsed.
Click to expand it.
sites/all/modules/unl/unl.module
+
25
−
1
View file @
f2931e82
...
...
@@ -1638,7 +1638,31 @@ function unl_filter_ssi_process($text, $filter, $format, $langcode, $cache, $cac
$url
.
=
'#'
.
$parts
[
'fragment'
];
}
$content
=
unl_url_get_contents
(
$url
);
$ssiDepth
=
0
;
if
(
array_key_exists
(
'HTTP_X_UNL_SSI_DEPTH'
,
$_SERVER
))
{
$ssiDepth
=
$_SERVER
[
'HTTP_X_UNL_SSI_DEPTH'
];
}
$ssiDepth
++
;
$context
=
stream_context_create
(
array
(
'http'
=>
array
(
'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! -->'
;
}
else
{
$headers
=
array
();
$content
=
unl_url_get_contents
(
$url
,
$context
,
$headers
);
if
(
array_key_exists
(
'x-unl-ssi-error'
,
$headers
))
{
watchdog
(
'unl'
,
'Server Side Include: An included URL reached the depth limit.'
,
array
(),
WATCHDOG_WARNING
);
drupal_add_http_header
(
'x-unl-ssi-error'
,
'The included URL caused recursion that was too deep!'
);
}
}
$replacements
[
$full_match
]
=
PHP_EOL
.
'<!-- Begin content from '
.
$url
.
' -->'
.
PHP_EOL
.
$content
.
PHP_EOL
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment