Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 7a2b845a2ef1da9bd6ba325d3101a28947d1ddc2 Mon Sep 17 00:00:00 2001
- From: David Morton <mortonda@dgrmm.net>
- Date: Fri, 24 Oct 2008 22:40:38 -0500
- Subject: [PATCH] Modifying the DisplayURI injector to allow for more flexible output
- This change should make the output more flexible by extending the
- interface supplied and returning an array of tokens as needed.
- Signed-off-by: David Morton <mortonda@dgrmm.net>
- ---
- library/HTMLPurifier/Injector/DisplayLinkURI.php | 35 +++++++++++++++++++++-
- 1 files changed, 34 insertions(+), 1 deletions(-)
- diff --git a/library/HTMLPurifier/Injector/DisplayLinkURI.php b/library/HTMLPurifier/Injector/DisplayLinkURI.php
- index 6fc566d..9ed8f30 100644
- --- a/library/HTMLPurifier/Injector/DisplayLinkURI.php
- +++ b/library/HTMLPurifier/Injector/DisplayLinkURI.php
- -9,6 +9,12 @@ class HTMLPurifier_Injector_DisplayLinkURI extends HTMLPurifier_Injector
- public $name = 'DisplayLinkURI';
- public $needed = array('a');
- + private $strategy;
- +
- + public function setStrategy($strategy) {
- + $this->strategy = $strategy;
- + }
- +
- public function handleElement(&$token) {
- }
- -16,9 +22,36 @@ class HTMLPurifier_Injector_DisplayLinkURI extends HTMLPurifier_Injector
- if (isset($token->start->attr['href'])){
- $url = $token->start->attr['href'];
- unset($token->start->attr['href']);
- - $token = array($token, new HTMLPurifier_Token_Text(" ($url)"));
- + if(! defined($this->strategy)) { // default strategy
- + $this->strategy = new HTMLPurifier_Injector_DisplayLinkURI_Strategy_Simple;
- + }
- + $token = array($this->strategy->LinkAttributes($token, $url),
- + $this->strategy->URIDisplay($url)
- + );
- } else {
- // nothing to display
- }
- }
- +}
- +
- +interface HTMLPurifier_Injector_DisplayLinkURI_Strategy
- +{
- +
- + // Called with text of link
- + // returns
- + public function LinkAttributes(&$token, $url);
- +
- + //called with uri of link
- + public function URIDisplay($url);
- +}
- +
- +class HTMLPurifier_Injector_DisplayLinkURI_Strategy_Simple implements HTMLPurifier_Injector_DisplayLinkURI_Strategy
- +{
- + public function LinkAttributes(&$token, $url) {
- + return $token;
- + }
- +
- + public function URIDisplay($url) {
- + return new HTMLPurifier_Token_Text(" ($url)");
- + }
- }
- \ No newline at end of file
- --
- 1.5.6.5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement