From geeklog at langfamily.ca Thu Aug 26 00:15:09 2004 From: geeklog at langfamily.ca (Blaine Lang) Date: Thu, 26 Aug 2004 00:15:09 -0400 Subject: [geeklog-modules] Adding AutoLink Capability to Geeklog Message-ID: <004401c48b23$463a5240$650a10ac@XPBL2> Regarding Adding an [AutoLink] capability to Geeklog For the upcoming 1.3.10, I'd like to add this new capabilty In reference to this post: http://www.geeklog.net/forum/viewtopic.php?forum=8&showtopic=39494&lastpost=true I had added this capability into a new plugin recently and saw the advantage of GL extending the API to allow other plugins and Core GL components to easily be referenced. I have a PLG function as well that is ready to be added and can be added to GL components such as save_story and save_comments so that plugins can parse the content and replace any [tags] that are referencing them and replace the tag with a formatted HREF link. The function that I have developed for my plugin can easily be used by other plugins as it was written to be generic. It parses out the [tag] to extract the two parms after the tagtype identifier. [tagtype: parm1 parm2] Example: [file:1 myfile] or [forum:2023 related forum topic] For most apps 1 parm should be enough to uniquely identify the record and parm2 is the name to be used in the link. Note: PARM1 is from the : to the first space PARM2 can include spaces - I assume its from the end of parm1 to the closing ] tag. My new CMS plugin now has this call that replaces a [autolink] tags with any other referenced plugin links $content = PLG_replacetags($content); Blaine --------- New plugin function prototype --------- function plugin_replacetags_myplugin($content) { global $_CONF; $filetag_prefix = '[file:'; $offset = $prev_offset = 0; $str = " ".$content; $strlen = strlen($str); $tags = array(); while ($offset < $strlen) { $start_pos = strpos( strtolower( $str ), $filetag_prefix, $offset ); if( $start_pos !== FALSE ) { $end_pos = strpos( strtolower( $str ), ']', $start_pos ); if($end_pos > $start_pos) { $taglength = $end_pos - $start_pos + 1; $tag = substr($str,$start_pos,$taglength); $parms = explode(' ',$tag); $label = str_replace(']','',$parms['1']); $parms = explode(':',$parms[0]); $fileid = $parms['1']; $newtag = array ( 'tagstr' => $tag, 'startpos' => $start_pos, 'length' => $taglength, 'parm1' => $fileid, 'parm2' => $label ); $tags[] = $newtag; } else { Return 'ERROR

Matching tag missing. Unable to format content.

'; } $prev_offset = $offset; $offset = $end_pos; } else { $prev_offset = $end_pos; $end_pos = $strlen; $offset = $strlen; } } if (count($tags) > 0) { // Found the [tag] foreach ($tags as $tag) { $filelink = ''.$tag['parm2'].''; $retval = str_replace($tag['tagstr'],$filelink,$content); } } return $retval; } -------------- next part -------------- An HTML attachment was scrubbed... URL: