Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Expand the acronyms for SEO
- * @param string $txt
- */
- protected function _seoAcronymExpansion( $txt )
- {
- if ( $txt == '' )
- {
- return $txt;
- }
- $acronyms = $this->cache->getCache('ipseo_acronyms');
- if( !is_array($acronyms) OR !count($acronyms) )
- {
- return $txt;
- }
- $temp_text = $txt;
- $urls = array();
- $tags = array();
- $txt = str_replace( '<#EMO_DIR#>', '-#-#-#EMO_DIR#-#-#-', $txt );
- /* Grab images */
- preg_match_all( '#<img([^>]+?)>#i', $txt, $matches );
- foreach( $matches[0] as $m )
- {
- $c = count( $urls );
- $urls[ $c ] = $m;
- $txt = str_replace( $m, '<!--url{' . $c . '}-->', $txt );
- }
- /* Grab <a> */
- preg_match_all( '#<a([^>]+?)>#i', $txt, $matches );
- foreach( $matches[0] as $m )
- {
- $c = count( $urls );
- $urls[ $c ] = $m;
- $txt = str_replace( $m, '<!--url{' . $c . '}-->', $txt );
- }
- /* Grab all other tags */
- preg_match_all( '#<(?:[/a-z]{1,})([^>]+?)>#i', $txt, $matches );
- foreach( $matches[0] as $m )
- {
- $c = count( $tags );
- $tags[ $c ] = $m;
- $txt = str_replace( $m, '<!--tag{' . $c . '}-->', $txt );
- }
- /* Grab non linked URLs */
- preg_match_all( '#((http|https|news|ftp)://(?:[^<>\)\[\"\s]+|[a-zA-Z0-9/\._\-!&\#;,%\+\?:=]+))#is', $txt, $matches );
- foreach( $matches[0] as $m )
- {
- $c = count( $urls );
- $urls[ $c ] = $m;
- $txt = str_replace( $m, '<!--url{' . $c . '}-->', $txt );
- }
- //-----------------------------------------
- // Convert back entities
- //-----------------------------------------
- for( $i = 65; $i <= 90; $i++ )
- {
- $txt = str_replace( "&#" . $i . ";", chr($i), $txt );
- }
- for( $i = 97; $i <= 122; $i++ )
- {
- $txt = str_replace( "&#" . $i . ";", chr($i), $txt );
- }
- //-----------------------------------------
- // Go all loopy
- //-----------------------------------------
- if ( is_array($acronyms) && count($acronyms) )
- {
- foreach( $acronyms as $r )
- {
- $this->_currentAcronym = $r;
- /* vv Ticket #835804 */
- $wordModifier = ( IPS_DOC_CHAR_SET == 'UTF-8' && IPSText::isUTF8( $txt ) ) ? '[^<>\p{L}]|\b' : '[^<>a-zA-Z0-9-_&;]';
- $caseModifier = empty($r['a_casesensitive']) ? 'i' : '';
- $r['a_short'] = preg_quote( $r['a_short'], "/" );
- $txt = preg_replace_callback( '/(^|\b|\W)(' . $r['a_short'] . ')(\b|\W|$)/' . $caseModifier, array( $this, '_replaceAcronym' ), $txt );
- }
- }
- /* replace urls */
- if ( count( $urls ) )
- {
- foreach( $urls as $k => $v )
- {
- $txt = str_replace( "<!--url{" . $k . "}-->", $v, $txt );
- }
- }
- /* replace tags */
- if ( count( $tags ) )
- {
- foreach( $tags as $k => $v )
- {
- $txt = str_replace( "<!--tag{" . $k . "}-->", $v, $txt );
- }
- }
- $txt = str_replace( '-#-#-#EMO_DIR#-#-#-', '<#EMO_DIR#>', $txt );
- return $txt ? $txt : $temp_text;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement