Advertisement
Guest User

Untitled

a guest
Apr 5th, 2015
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. /**
  2. * Expand the acronyms for SEO
  3. * @param string $txt
  4. */
  5. protected function _seoAcronymExpansion( $txt )
  6. {
  7. if ( $txt == '' )
  8. {
  9. return $txt;
  10. }
  11.  
  12. $acronyms = $this->cache->getCache('ipseo_acronyms');
  13.  
  14. if( !is_array($acronyms) OR !count($acronyms) )
  15. {
  16. return $txt;
  17. }
  18.  
  19. $temp_text = $txt;
  20. $urls = array();
  21. $tags = array();
  22. $txt = str_replace( '<#EMO_DIR#>', '-#-#-#EMO_DIR#-#-#-', $txt );
  23.  
  24. /* Grab images */
  25. preg_match_all( '#<img([^>]+?)>#i', $txt, $matches );
  26.  
  27. foreach( $matches[0] as $m )
  28. {
  29. $c = count( $urls );
  30. $urls[ $c ] = $m;
  31.  
  32. $txt = str_replace( $m, '<!--url{' . $c . '}-->', $txt );
  33. }
  34.  
  35. /* Grab <a> */
  36. preg_match_all( '#<a([^>]+?)>#i', $txt, $matches );
  37.  
  38. foreach( $matches[0] as $m )
  39. {
  40. $c = count( $urls );
  41. $urls[ $c ] = $m;
  42.  
  43. $txt = str_replace( $m, '<!--url{' . $c . '}-->', $txt );
  44. }
  45.  
  46. /* Grab all other tags */
  47. preg_match_all( '#<(?:[/a-z]{1,})([^>]+?)>#i', $txt, $matches );
  48.  
  49. foreach( $matches[0] as $m )
  50. {
  51. $c = count( $tags );
  52. $tags[ $c ] = $m;
  53.  
  54. $txt = str_replace( $m, '<!--tag{' . $c . '}-->', $txt );
  55. }
  56.  
  57. /* Grab non linked URLs */
  58. preg_match_all( '#((http|https|news|ftp)://(?:[^<>\)\[\"\s]+|[a-zA-Z0-9/\._\-!&\#;,%\+\?:=]+))#is', $txt, $matches );
  59.  
  60. foreach( $matches[0] as $m )
  61. {
  62. $c = count( $urls );
  63. $urls[ $c ] = $m;
  64.  
  65. $txt = str_replace( $m, '<!--url{' . $c . '}-->', $txt );
  66. }
  67.  
  68. //-----------------------------------------
  69. // Convert back entities
  70. //-----------------------------------------
  71.  
  72. for( $i = 65; $i <= 90; $i++ )
  73. {
  74. $txt = str_replace( "&#" . $i . ";", chr($i), $txt );
  75. }
  76.  
  77. for( $i = 97; $i <= 122; $i++ )
  78. {
  79. $txt = str_replace( "&#" . $i . ";", chr($i), $txt );
  80. }
  81.  
  82. //-----------------------------------------
  83. // Go all loopy
  84. //-----------------------------------------
  85.  
  86. if ( is_array($acronyms) && count($acronyms) )
  87. {
  88. foreach( $acronyms as $r )
  89. {
  90. $this->_currentAcronym = $r;
  91.  
  92. /* vv Ticket #835804 */
  93. $wordModifier = ( IPS_DOC_CHAR_SET == 'UTF-8' && IPSText::isUTF8( $txt ) ) ? '[^<>\p{L}]|\b' : '[^<>a-zA-Z0-9-_&;]';
  94. $caseModifier = empty($r['a_casesensitive']) ? 'i' : '';
  95. $r['a_short'] = preg_quote( $r['a_short'], "/" );
  96.  
  97. $txt = preg_replace_callback( '/(^|\b|\W)(' . $r['a_short'] . ')(\b|\W|$)/' . $caseModifier, array( $this, '_replaceAcronym' ), $txt );
  98. }
  99. }
  100.  
  101. /* replace urls */
  102. if ( count( $urls ) )
  103. {
  104. foreach( $urls as $k => $v )
  105. {
  106. $txt = str_replace( "<!--url{" . $k . "}-->", $v, $txt );
  107. }
  108. }
  109.  
  110. /* replace tags */
  111. if ( count( $tags ) )
  112. {
  113. foreach( $tags as $k => $v )
  114. {
  115. $txt = str_replace( "<!--tag{" . $k . "}-->", $v, $txt );
  116. }
  117. }
  118.  
  119. $txt = str_replace( '-#-#-#EMO_DIR#-#-#-', '<#EMO_DIR#>', $txt );
  120.  
  121. return $txt ? $txt : $temp_text;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement