daily pastebin goal
7%
SHARE
TWEET

DGM

a guest Oct 24th, 2008 1,902 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. From 7a2b845a2ef1da9bd6ba325d3101a28947d1ddc2 Mon Sep 17 00:00:00 2001
  2. From: David Morton <mortonda@dgrmm.net>
  3. Date: Fri, 24 Oct 2008 22:40:38 -0500
  4. Subject: [PATCH] Modifying the DisplayURI injector to allow for more flexible output
  5.  
  6. This change should make the output more flexible by extending the
  7. interface supplied and returning an array of tokens as needed.
  8.  
  9. Signed-off-by: David Morton <mortonda@dgrmm.net>
  10. ---
  11.  library/HTMLPurifier/Injector/DisplayLinkURI.php |   35 +++++++++++++++++++++-
  12.  1 files changed, 34 insertions(+), 1 deletions(-)
  13.  
  14. diff --git a/library/HTMLPurifier/Injector/DisplayLinkURI.php b/library/HTMLPurifier/Injector/DisplayLinkURI.php
  15. index 6fc566d..9ed8f30 100644
  16. --- a/library/HTMLPurifier/Injector/DisplayLinkURI.php
  17. +++ b/library/HTMLPurifier/Injector/DisplayLinkURI.php
  18.  -9,6 +9,12 @@ class HTMLPurifier_Injector_DisplayLinkURI extends HTMLPurifier_Injector
  19.      public $name = 'DisplayLinkURI';
  20.      public $needed = array('a');
  21.      
  22. +    private $strategy;
  23. +    
  24. +    public function setStrategy($strategy) {
  25. +        $this->strategy = $strategy;
  26. +    }
  27. +    
  28.      public function handleElement(&$token) {
  29.      }
  30.      
  31.  -16,9 +22,36 @@ class HTMLPurifier_Injector_DisplayLinkURI extends HTMLPurifier_Injector
  32.          if (isset($token->start->attr['href'])){
  33.              $url = $token->start->attr['href'];
  34.              unset($token->start->attr['href']);
  35. -            $token = array($token, new HTMLPurifier_Token_Text(" ($url)"));
  36. +            if(! defined($this->strategy)) {  // default strategy
  37. +                $this->strategy = new HTMLPurifier_Injector_DisplayLinkURI_Strategy_Simple;
  38. +            }
  39. +            $token = array($this->strategy->LinkAttributes($token, $url),
  40. +                           $this->strategy->URIDisplay($url)
  41. +                           );
  42.          } else {
  43.              // nothing to display
  44.          }
  45.      }
  46. +}
  47. +
  48. +interface HTMLPurifier_Injector_DisplayLinkURI_Strategy
  49. +{
  50. +
  51. +    // Called with text of link
  52. +    // returns
  53. +    public function LinkAttributes(&$token, $url);
  54. +    
  55. +    //called with uri of link
  56. +    public function URIDisplay($url);
  57. +}
  58. +
  59. +class HTMLPurifier_Injector_DisplayLinkURI_Strategy_Simple implements HTMLPurifier_Injector_DisplayLinkURI_Strategy
  60. +{
  61. +    public function LinkAttributes(&$token, $url) {
  62. +        return $token;
  63. +    }
  64. +    
  65. +    public function URIDisplay($url) {
  66. +        return new HTMLPurifier_Token_Text(" ($url)");
  67. +    }
  68.  }
  69. \ No newline at end of file
  70. --
  71. 1.5.6.5
RAW Paste Data
Top