0){$pos1 = strpos($scheck,$s1);} else {$pos1=0;} if($pos1 !== false){ if($s2 == '') return substr($s,$pos1+$L1); $pos2 = strpos(substr($scheck,$pos1+$L1),$s2); if($pos2!==false) return substr($s,$pos1+$L1,$pos2); } return ''; } // find feedburner feed function (parses a users page for a feed link) function findfeedburner($page_url){ // can't open default wordpress feed, use curl to parse users page for a relative link feed if(function_exists(curl_init)) { $ch=curl_init(); $timeout = 10; // set to zero for no timeout curl_setopt ($ch, CURLOPT_URL, $page_url ); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data=curl_exec($ch); curl_close($ch); $lines=explode("\n",$data); // look for feedburner url foreach($lines as $line){ if(strstr($line,"alternate")&&(strstr($line,"rss")||strstr($line,"xml"))){ $pos=strpos($line,"href"); $cut=substr($line,$pos+5); $feed_url=LL_TextBetween("\"","\"",$cut); break; } } } else // no curl here, borrow mine! { $rss=fetch_rss("http://www.commentluv.com/commentluvinc/cl_feedfind.php?url=$page_url"); $items= array_slice($rss->items,0,1); foreach($items as $item){ $feed_post=$item['link']; } return $feed_post; } return $feed_url; } function commentluv_form_alter(&$form, &$form_state, $form_id) { if ($form_id != 'comment_form') { return; } global $user; if($user->uid == 0) { $form['luv'] = array( '#type' => 'checkbox', '#title' => t('Comment Luv'), '#description' => t('This blog uses the CommentLuv Drupal plugin which will try and parse your sites feed and display a link to your last post, please be patient while it tries to find it for you.'), ); } } function commentluv_comment($comment, $op){ switch ($op) { case 'insert': $manual_feed=0; $luv = $comment['luv']; // get checkbox value for commentluv // don't parse for admin posting comment reply,pingback or trackback and checks if last post already added and check for luv box checked global $user; if ($luv!='1' || $user->uid > 0) { return; } // get author url $author_url=$comment['homepage']; // if no author url given, return if(!$author_url){ return; } // clean up author url if it has a trailing forward slash if(substr($author_url,-1)=="/") { $author_url = substr($author_url, 0, -1); // remove trailing slash } // *********************** // *** fun starts here *** // *********************** // check for magpie timeout constant if(!defined('MAGPIE_FETCH_TIME_OUT')){ define('MAGPIE_FETCH_TIME_OUT',5); } // set cache age to 5 minutes so it doesn't show an old last post if a commenter makes a new post and returns to comment again if(!defined('MAGPIE_CACHE_AGE')){ define('MAGPIE_CACHE_AGE',300); } // use wp internal rss.php function (wp 2.1+ only) module_load_include('inc', 'commentluv', 'ss_fetch'); // ************************** // *** identify blog type *** // ************************** // try and determine blog type and locate default location for feed. if(strstr($author_url,"blogspot")){ // blogspot blog $feed_url="$author_url/feeds/posts/default/"; } elseif(strstr($author_url,"typepad")){ // typepad blog $feed_url="$author_url/atom.xml"; } elseif(strstr($author_url,"livejournal")){ // livejournal $feed_url="$author_url/data/rss"; } elseif(strstr($author_url,"web-log")){ // web-log blog // take only the name of the author of http://xxx.web-log.nl preg_match('|http://(.*?).web-log.nl|is', $author_url, $authorid); $feed_url = $author_url . "/" . $authorid[1] . "/rss.xml"; } else { $feed_url="$author_url/feed/"; // own domain or wordpress blog } // *************************** // *** detect manual entry *** // *************************** // here we see if user manually entered their own feed url if(strstr($comment['comment'],"[feed]")){ $feed_url=LL_TextBetween("[feed]","[/feed]",$comment['comment']); // now strip feed bit from comment $manual_feed_pos_start=strpos($comment['comment'],"[feed]"); $comment['comment']=substr($comment['comment'],0,$manual_feed_pos_start); $manual_feed=1; } // ******************************* // *** time to do the fetching *** // ******************************* // fetch feed with WP function $rss=fetch_rss("$feed_url"); // couldn't find it try to parse users page if curl enabled if(!$rss && !$manual_feed){ $feed_url=findfeedburner($author_url); $rss=fetch_rss("$feed_url"); } // couldn't find it! look in other places if(!$rss && !$manual_feed){ $feed_url="$author_url/?feed=rss"; $rss=fetch_rss("$feed_url"); // try own domain blogspot if(!$rss){ $feed_url="$author_url/feeds/posts/default"; $rss=fetch_rss("$feed_url"); } // try typepad own domain if(!$rss) { $feed_url="$author_url/atom.xml"; $rss=fetch_rss("$feed_url"); } } // ************************** // *** do the parse dance *** // ************************** // now we must have a feed to parse, get last post title and link $items= array_slice($rss->items,0,1); foreach($items as $item){ $feed_title=$item['title']; $feed_post=$item['link']; } // try and fix any single quotes that got changed to question marks $search = array("?s", "?t", "?l", "?v", "?m", "?d"); $replace = array("'s", "'t", "'l", "'v", "'m", "'d"); $feed_title=str_replace($search,$replace,$feed_title); $feed_title = utf8_decode($feed_title); // **************************** // *** append the last post *** // **************************** // insert last post data onto the end of the comment content if($feed_title && $feed_post){ // only output if last post found $author_excerpt="\n\n".$comment['name']. t("'s last blog post...") ." $feed_title"; $comment['comment']=substr_replace($comment['comment'], $author_excerpt,strlen($comment['comment']),0); } $result = comment_save($comment); break; } return $comment; }