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
737280dc
Commit
737280dc
authored
12 years ago
by
Tim Steiner
Browse files
Options
Downloads
Plain Diff
Merge pull request #418 from tsteiner2/issue-124
Issue 124
parents
ced5da35
c74d2a34
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sites/all/modules/unl/unl.module
+127
-0
127 additions, 0 deletions
sites/all/modules/unl/unl.module
with
127 additions
and
0 deletions
sites/all/modules/unl/unl.module
+
127
−
0
View file @
737280dc
...
@@ -1513,3 +1513,130 @@ function unl_query_alter(QueryAlterableInterface $query) {
...
@@ -1513,3 +1513,130 @@ function unl_query_alter(QueryAlterableInterface $query) {
}
}
}
}
}
}
/**
* Implementation of hook_filter_info()
*/
function
unl_filter_info
()
{
return
array
(
'unl_embed'
=>
array
(
'title'
=>
'UNL Node Embed'
,
'description'
=>
"Allow a node's body to be embedded into another node by using tags."
,
'process callback'
=>
'unl_filter_embed_process'
,
'cache'
=>
FALSE
,
),
'unl_ssi'
=>
array
(
'title'
=>
'UNL SSI'
,
'description'
=>
'Implements the <!--#include virtual="some/path"--> Server Side Include directive.'
,
'process callback'
=>
'unl_filter_ssi_process'
,
'cache'
=>
FALSE
,
),
);
}
/**
* Implementation of hook_filter_FILTER_process pseudo-hook
*
* 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
)
{
static
$processed_hashes
=
array
();
$text_hash
=
hash
(
'sha256'
,
$text
);
if
(
in_array
(
$text_hash
,
array_keys
(
$processed_hashes
)))
{
// Possible recursion detected, return the cache result.
return
$processed_hashes
[
$text_hash
];
}
// In case of recursion, set the cached result to this until we have the real result.
$processed_hashes
[
$text_hash
]
=
'Error: Cannot embed a node in itself..'
;
$matches
=
NULL
;
preg_match_all
(
'/\[\[node:([0-9]+)\]\]/'
,
$text
,
$matches
);
$node_ids
=
$matches
[
1
];
$nodes
=
entity_load
(
'node'
,
$node_ids
);
$replace_array
=
array
();
foreach
(
$node_ids
as
$node_id
)
{
$content
=
node_view
(
$nodes
[
$node_id
]);
$replace_array
[
"[[node:
$node_id
]]"
]
=
PHP_EOL
.
"<!-- Node
$node_id
start -->"
.
PHP_EOL
.
render
(
$content
[
'body'
])
.
PHP_EOL
.
"<!-- Node
$node_id
end -->"
.
PHP_EOL
;
}
$text
=
strtr
(
$text
,
$replace_array
);
// Set the cached result to the real result.
$processed_hashes
[
$text_hash
]
=
$text
;
return
$text
;
}
/**
* Implementation of hook_filter_FILTER_process pseudo-hook
*
* Replace any instances of <!--#include virtual="url"--> with the content
* found at that URL. If the url is in the unl.edu domain, format=partial
* will be added to the query string.
*/
function
unl_filter_ssi_process
(
$text
,
$filter
,
$format
,
$langcode
,
$cache
,
$cache_id
)
{
$matches
=
NULL
;
preg_match_all
(
'/<!-- *#include +virtual=((".*")|(\'.*\')) *-->/'
,
$text
,
$matches
);
$replacements
=
array
();
foreach
(
$matches
[
1
]
as
$match_index
=>
$match
)
{
$full_match
=
$matches
[
0
][
$match_index
];
// Break down the URL target then rebuild it as absolute.
$url
=
substr
(
$match
,
1
,
-
1
);
$parts
=
parse_url
(
$url
);
if
(
!
isset
(
$parts
[
'scheme'
]))
{
$parts
[
'scheme'
]
=
$_SERVER
[
'HTTPS'
]
?
'https'
:
'http'
;
}
if
(
!
isset
(
$parts
[
'host'
]))
{
$parts
[
'host'
]
=
$_SERVER
[
'HTTP_HOST'
];
}
if
(
isset
(
$parts
[
'path'
])
&&
substr
(
$parts
[
'path'
],
0
,
1
)
!=
'/'
)
{
if
(
variable_get
(
'unl_use_base_tag'
))
{
$parts
[
'path'
]
=
$GLOBALS
[
'base_path'
]
.
$parts
[
'path'
];
}
else
{
$parts
[
'path'
]
=
$GLOBALS
[
'base_path'
]
.
request_path
()
.
'/'
.
$parts
[
'path'
];
}
}
if
(
!
isset
(
$parts
[
'path'
]))
{
$parts
[
'path'
]
=
'/'
;
}
$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
{
$parts
[
'query'
]
=
''
;
}
$parts
[
'query'
]
.
=
'format=partial'
;
}
// Finish rebuilding the URL.
if
(
isset
(
$parts
[
'query'
]))
{
$url
.
=
'?'
.
$parts
[
'query'
];
}
if
(
isset
(
$parts
[
'fragment'
]))
{
$url
.
=
'#'
.
$parts
[
'fragment'
];
}
$content
=
file_get_contents
(
$url
);
$replacements
[
$full_match
]
=
PHP_EOL
.
'<!-- Begin content from '
.
$url
.
' -->'
.
PHP_EOL
.
$content
.
PHP_EOL
.
'<!-- End content from '
.
$url
.
' -->'
.
PHP_EOL
;
}
foreach
(
$replacements
as
$from
=>
$to
)
{
$text
=
str_replace
(
$from
,
$to
,
$text
);
}
return
$text
;
}
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