PageRenderTime 538ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/nooku/libraries/koowa/template/filter/link.php

https://github.com/bhar1red/anahita
PHP | 76 lines | 31 code | 9 blank | 36 comment | 1 complexity | da76f42198403139ecb116e74d7c65d0 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: link.php 4628 2012-05-06 19:56:43Z johanjanssens $
  4. * @package Koowa_Template
  5. * @subpackage Filter
  6. * @copyright Copyright (C) 2007 - 2012 Johan Janssens. All rights reserved.
  7. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
  8. * @link http://www.nooku.org
  9. */
  10. /**
  11. * Template filter to parse link tags
  12. *
  13. * @author Johan Janssens <johan@nooku.org>
  14. * @package Koowa_Template
  15. * @subpackage Filter
  16. */
  17. class KTemplateFilterLink extends KTemplateFilterAbstract implements KTemplateFilterWrite
  18. {
  19. /**
  20. * Find any <link /> elements and render them
  21. *
  22. * @param string Block of text to parse
  23. * @return KTemplateFilterLink
  24. */
  25. public function write(&$text)
  26. {
  27. //Parse the script information
  28. $scripts = $this->_parseLinks($text);
  29. //Prepend the script information
  30. $text = $scripts.$text;
  31. return $this;
  32. }
  33. /**
  34. * Parse the text for script tags
  35. *
  36. * @param string Block of text to parse
  37. * @return string
  38. */
  39. protected function _parseLinks(&$text)
  40. {
  41. $scripts = '';
  42. $matches = array();
  43. if(preg_match_all('#<link\ href="([^"]+)"(.*)\/>#iU', $text, $matches))
  44. {
  45. foreach(array_unique($matches[1]) as $key => $match)
  46. {
  47. $attribs = $this->_parseAttributes( $matches[2][$key]);
  48. $scripts .= $this->_renderScript($match, $attribs);
  49. }
  50. $text = str_replace($matches[0], '', $text);
  51. }
  52. return $scripts;
  53. }
  54. /**
  55. * Render script information
  56. *
  57. * @param string The script information
  58. * @param array Associative array of attributes
  59. * @return string
  60. */
  61. protected function _renderLink($link, $attribs = array())
  62. {
  63. $attribs = KHelperArray::toString($attribs);
  64. $html = '<link href="'.$link.'" '.$attribs.'/>'."\n";
  65. return $html;
  66. }
  67. }