Irev; Rev Cgi; stack as dBase: runs in iFrame in Word Press

Sivakatirswami katir at hindu.org
Mon Nov 2 15:25:57 EST 2009


Thanks to a tip from Andre I have managed to use runRev in a word press 
blog. he says a revlet will also run too...I usually don't contribute 
much here because I feel I'm a "baby" compared to all the wizards ... 
but perhaps this will be useful to  those interested in incorporating 
runRev in PHP CMS frameworks. In this case a Word Press mu blog.

http://himalayanacademy.com/blog/taka/2009/11/02/words-to-ponder/

The "chain" of elements in the framework are interesting, as we use

-- an iFrame
-- Calls a .irev page
-- .irev page calls a rev-cgi
-- rev-cgi "starts using" a stack
-- stack function digs for and returns the content
-- results are posted back to word press.

The thing of it is... it's so easy! and so fast... Total lines of code?

22? (spread over three different files and don't forget a 7MB stack is 
loaded on every instance...but there is no lag time)

with one or two caveats.

In case any one is interested here is the code:

Word Press Post
 (# space and breaks at the beginning to give a little breathing room 
above the iFrame below the post title)

     <br /><br /><iframe name="get-word" style="border: 0px solid 
#ffffff;width:600px;height:400;" src="/resources/lexicon/RandomWord.irev"  >
                    </iframe>

## the css is needed to eliminate the border. iFrames will always 
"borderize" so just set the color of the border to the color of your 
background and it effectively disappears.
# Assumes you have the wp plug in that allows for pasting html into the 
blog and this is set to "allow"


RandomWord.irev # will be displayed into your iFrame, I suspect this 
could be a page that contains a revlet...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; 
charset=x-mac-roman">
    <title>Get
    Random Word</title>
        <link href="css/seva.css" rel="stylesheet" media="screen">
    </head>
<body style="background-image: 
url(/resources/lexicon/images/taka_random-word-bkgnd-ocean.jpg);
    background-repeat: no-repeat;">

<?rev
local tWord, tDefinition
put url 
"http://www.himalayanacademy.com/cgi-bin/getRandomLexiconWord.cgi" into 
tWordOfTheDay
set the itemdel to "|"
put item 1 of tWordOfTheDay into tWord
put item 2 of tWordOfTheDay into tDefinition

?>
<div style="padding:0px 15px 15px 15px;">
<h2><?rev put tWord ?>:</h2>
<p> <?rev put tDefinition ?> </p>
</div>

</body>
</html>

getRandomLexiconWord.cgi

# it would be nice to be able to call stacks directly with the iRev 
engine and
# I think that is on the roster of future for features but for now you 
need to
# do a GET of a a rev-cgi that Starts Using a stack

#!/opt/web/bin/revolution -ui

on startup
    start using stack "../public_html/resources/lexicon/lexicon.rev"
    put getRandomWord() into buffer
      put "Content-Type: text/plain" & cr
  put "Content-Length:" && the length of buffer & cr & cr
  put buffer
end startup

in the stack "lexicon.rev" (a 7 MB stack with about 3500 cards)

I have this function in the stack itself.

function getRandomWord
   put (the number of cards of stack "Lexicon") into tCards
   put random(tCards) into tWord
   put (fld "word" of card  tWord of stack "Lexicon") & "|"& \
   (fld "definition" of card tWord of stack "Lexicon") into tOutput
   return tOutput
end getRandomWord

# Caveat on calling functions in stacks using rev-cgi: a rev.cgi has no 
stack context. There fore you need to declare explicitely the stack 
reference to any objects in your stack. If you are working on the 
desktop in the IDE of course you don't need this and then when you post 
the thing to the web it doesn['t work.. .I had gone thru this a few 
years  back but for got about it  and it was until I reviewed some old 
function in other web stack that I realize again that you must do this:

put (the number of cards) into tCards

# works in the desktop in an IDE or standalone; fails when invoked by cgi

# this is required, for it to work when call by a CGI even though the 
function is in the stack "Lexicon":

put (the number of cards of stack "Lexicon")  into tCards

Again: total lines of runRev code (not including html)

22


















More information about the use-livecode mailing list