Guest User

yep

a guest
Sep 2nd, 2014
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.95 KB | None | 0 0
  1. if(!function_exists('avia_link_content_filter'))
  2. {
  3.     function avia_link_content_filter($current_post)
  4.     {
  5.         //retrieve the link for the post
  6.         $link       = "";
  7.  
  8.         $pattern1   = '$^\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$i';
  9.         $pattern2   = "!^\<a.+?<\/a>!";
  10.         $pattern3   = "!\<a.+?<\/a>!";
  11.  
  12.         //if the url is at the begnning of the content extract it
  13.         preg_match($pattern1, $current_post['content'] , $link);
  14.         if(!empty($link[0]))
  15.         {
  16.             $link = $link[0];
  17.             $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false));
  18.             $current_post['title'] = "<a target='_blank' href='$link' rel='bookmark' title='".__('Link to:','avia_framework')." ".the_title_attribute('echo=0')."' $markup>".get_the_title()."</a>";
  19.             $current_post['content'] = preg_replace("!".str_replace("?", "\?", $link)."!", "", $current_post['content'], 1);
  20.         }
  21.         else
  22.         {
  23.             preg_match($pattern2, $current_post['content'] , $link);
  24.             if(!empty($link[0]))
  25.             {
  26.                 $link = $link[0];
  27.                 $current_post['title'] = $link;
  28.                 $current_post['content'] = preg_replace("!".str_replace("?", "\?", $link)."!", "", $current_post['content'], 1);
  29.             }
  30.             else
  31.             {
  32.                 preg_match($pattern3,  $current_post['content'] , $link);
  33.                 if(!empty($link[0]))
  34.                 {
  35.                     $current_post['title'] = $link[0];
  36.                 }
  37.             }
  38.         }
  39.  
  40.         if($link)
  41.         {
  42.             if(is_array($link)) $link = $link[0];
  43.        
  44.             $heading = is_singular() ? "h1" : "h2";
  45.  
  46.             //$current_post['title'] = "<{$heading} class='post-title entry-title ". avia_offset_class('meta', false). "'>".$current_post['title']."</{$heading}>";
  47.             $current_post['title'] = "<{$heading} class='post-title entry-title' ".avia_markup_helper(array('context' => 'entry_title','echo'=>false)).">".$current_post['title']."</{$heading}>";
  48.            
  49.             //needs to be set for masonry
  50.             $current_post['url'] = $link;
  51.         }
  52.         else
  53.         {
  54.             $current_post = avia_default_title_filter($current_post);
  55.         }
  56.  
  57.         return $current_post;
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment