[geeklog-cvs] geeklog-1.3/system lib-trackback.php,1.5,1.6

dhaun at iowaoutdoors.org dhaun at iowaoutdoors.org
Sat Jan 29 17:33:37 EST 2005


Update of /var/cvs/geeklog-1.3/system
In directory www:/tmp/cvs-serv25594

Modified Files:
	lib-trackback.php 
Log Message:
Added a function to auto-detect the Trackback URL in a post.


Index: lib-trackback.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/system/lib-trackback.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** lib-trackback.php	29 Jan 2005 17:52:55 -0000	1.5
--- lib-trackback.php	29 Jan 2005 22:33:35 -0000	1.6
***************
*** 555,557 ****
--- 555,613 ----
  }
  
+ /**
+ * Attempt to auto-detect the Trackback URL of a post.
+ *
+ * @param    string  $url    URL of post with embedded RDF for the Trackback URL
+ * @return   mixed           Trackback URL, or false on error
+ *
+ * Note: The RDF, if found, is only parsed using a regular expression. Using
+ *       the XML parser may be more successful on some occassions ...
+ *
+ */
+ function TRB_detectTrackbackUrl ($url)
+ {
+     $fp = @fopen ($url, 'r');
+     if ($fp === false) {
+         return false;
+     }
+     $page = '';
+     $found_start = false;
+     $pos1 = 0;
+     $pos2 = 0;
+     while (!feof ($fp)) {
+         $page .= fread ($fp, 4096);
+         if (!$found_start) {
+             $pos = strpos ($page, '<rdf:RDF ');
+             if ($pos === false) {
+                 continue;
+             }
+             $found_start = true;
+             $pos1 = $pos;
+         }
+         if ($found_start) {
+             $pos = strpos ($page, '</rdf:RDF>');
+             if ($pos !== false) {
+                 $pos2 = $pos;
+                 break;
+             }
+         }
+     }
+     fclose ($fp);
+ 
+     if ($found_start) {
+         $pos2 += strlen ('</rdf:RDF>');
+         $rdf = substr ($page, $pos1, $pos2 - $pos1);
+ 
+         // Okay, we COULD fire up the XML parser now. But then again ...
+         preg_match ('/trackback:ping="(.*)"/', $rdf, $matches);
+         if (empty ($matches[1])) {
+             $retval = false;
+         } else {
+             $retval = $matches[1];
+         }
+     }
+ 
+     return $retval;
+ }
+ 
  ?>




More information about the geeklog-cvs mailing list