Kanarie Functionality Question

new topic     » topic index » view thread      » older message » newer message

Tommy,

When using my own code library, I've got embedded field items in my site
content database that look like this

   {LINK:Google,http://www.google.com/}

that get converted to the proper HTML by my parser:

   <a href="http://www.google.com/">Google</a>

I'm starting to convert my current main site over to using Kanarie and have
run into this problem. How do you suggest I go about doing this in Kanarie?

Here's the code I use... maybe you could do something similar for Kanarie as
some advanced functionality? It could be a Kanarie field with parameters.

{* sample knr template *}
{NORMAL_VAR} {* normal function *}
{ADVANCED_VAR:param1,param2} {* now we're gettin' fancy... :) *}

which is passed to a user-defined routine (in this case, "ADVANCED_VAR")...

   my_func = routine_id("ADVANCED_VAR")
   result = call_func(my_func,{param1,param2})

(Actually, in my GURPS manager, I could call functions like this:

   result = GURPS( "my_function", {params} )

so Kanarie could do

   result = userKanarie( "ADVANCED_VAR", {param1,param2} )

Nice!!(?) :)

Anyway, here's some prewritten code for what I'm doing. Think about it! :)

global function insertLink(sequence lname, sequence llink )
sequence result
	if length(lname) > 0 and length(llink) > 0 then
		if match("NEW:",llink) = 1 then -- wants in new window!
result = "<a href=\"" & llink[5..length(llink)] & "\" target=\"_blank\">" &
lname & "</a>"
elsif match("www.mysitename",llink) = 0 and llink[1] != '?' then -- not on my
website
			result = "<a href=\"" & llink & "\" target=\"_blank\">" & lname & "</a>"
		else
			result = "<a href=\"" & llink & "\">" & lname & "</a>"
		end if
	else
		result = "<b>*BAD LINK*</b>"
	end if
	return result
end function

-- POST KANARIE PROCESSING
-- for LINK, imageName is the TEXT, altName is the URL
spot = match("{LINK:", theBody )
while spot > 0 do
	endspot = match("}",theBody[spot..length(theBody)]) + spot - 1
	colon = match(",",theBody[spot..endspot])
	if colon > 0 then
		colon += spot - 1
		imageName = theBody[spot+6..colon-1]
		altName = theBody[colon+1..endspot-1]
	else
		imageName = theBody[spot+6..endspot-1]
		altName = imageName
	end if
theBody = theBody[1..spot-1] & insertLink(imageName, altName) &
theBody[endspot+1..length(theBody)]
	spot = match("{LINK:", theBody )
end while


-=ck
"Programming in a state of EUPHORIA."
http://www.cklester.com/euphoria/

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu