One-step image tag needing debugging.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

One-step image tag needing debugging.

Douglas Burchard
On May 18, 2005, at 2:57 PM, Mikael Sundström wrote:
(was: Re: Lasso 8.04 return image from FMSA FMContainer)

> No one is  asking me to create secondary files to present text  
> fields - why should it be harder to present pictures? And  
> unfortunately the [IMG] tag is incompatible with FMSA 7.

Okay, I was already to explain why displaying an image is  
dramatically different than displaying text, then two things  
happened: Adam explained this more than adequately, and I had a  
moment of inspiration...  ;-)

The following code is written completely in the blind, I have no FMA  
setup right now, so have nothing to test against (I'm also up against  
two deadlines). Hopefully Fletcher or someone who has more time on  
their hands and a platform to work with can test and debug what I  
present here. The opening comments in the code should explain what  
the code does and how to install it on a server. Whoever does debug  
this please let me know and report any necessary changes back to the  
list.

Sorry about going a bit nuts with the commenting, Have fun, and good  
luck.


<?LassoScript

     /*

     Compile this file as a LassoApp named ImgFMA.LassoApp, place
     this in your Lasso Startup directory, and restart Lasso.

     Once installed you should be able to use the new tag like so:

         [ImgFMA: 'myimagefield', -Type='image/jpeg']

     The resulting URL should look something like:

         ImgFMA.LassoApp?id=97101e53cec9241fb895ffaf870e5fe5

     The way this works is to take all of your parameters and to
     store them in a global map keyed with an ID unique to your
     parameters. The resulting URL passes this unique ID back to
     the LassoApp which returns the image using the stored
     parameters.

     The size of the global variable is limited by the size of
     your table. A parameter group (database, table, key, field,
     and type) which exactly matches another group already stored
     in the map will harmlessly overwrite the first.

     */

     //
     // Define a global map we can later use to store values.
     If: !(Global_Defined: 'ImgFMAValues');
         Global: 'ImgFMAValues' = (Map);
     /If;

     //
     // Define a custom tag used as an interface to store
     // values in our global map.
     If: !(Lasso_TagExists: 'ImgFMA');
         Define_Tag: 'ImgFMA',
                 -Required='field',
                 -Required='type';
             //
             // Establish the current environment this tag was
             // called under.
             Local: 'database' = (Database_Name);
             Local: 'table' = (Table_Name);
             Local: 'key' = (KeyField_Value);
             //
             // Create a key that will be unique to the passed
             // parameter group and environment. By creating the
             // key in this way we can ensure no two items in our
             // global map will contain the same parameter group.
             // This helps keep the size of our global map under
             // control.
             Local: 'id' = (Encrypt_MD5: (#database + '::' +
                     #table + '::' + #key + '::' +
                     #field + '::' + #type));
             //
             // Store the passed parameter group in our global
             // map.
             Local: 'occurance' = (Array);
             #occurance -> (Insert: #database);
             #occurance -> (Insert: #table);
             #occurance -> (Insert: #key);
             #occurance -> (Insert: #field);
             #occurance -> (Insert: #type);
             (Global: 'ImgFMAValues') -> (Insert: #id=#occurance);
             //
             // Return a URL pointing to our LassoApp with the
             // key we created earlier as a query parameter.
             Return: ('ImgFMA.LassoApp?id=' + #id);
         /Define_Tag;
     /If;

     //
     // Define a custom tag used to serve the image from our
     // LassoApp. By enclosing this code in a custom tag, and
     // having the admin user define that tag during startup,
     // we can avoid needing a username and password to access
     // the database.
     //
     // This custom tag should only be used from within our
     // LassoApp, so I've prefaced the tag name with an
     // underscore.
     If: !(Lasso_TagExists: '_ImgFMAserve');
         Define_Tag: '_ImgFMAserve',
                 -Required='id';
             //
             // Retrieve our previously stored parameter group
             // from our global variable based on the passed ID.
             Local: 'foundoccurances' = ((Global: 'ImgFMAValues') ->
                     (Find: #id));
             Local: 'occurancepair' = (#foundoccurances -> Last);
             Local: 'occurance' = (#occurancepair -> Value);
             //
             // It's unlikely anything would ever go wrong with
             // our global map, but I like to code defensively.
             // So we double check that the value we've retrieved
             // is of the correct type (array) and size (five items).
             If: (#occurancepair -> Type) == (Array -> Type) &&
                     (#occurancepair -> Size) == (5);
                 //
                 // Perform the database transaction using the
                 // parameters previously stored in our global
                 // map.
                 Inline:
                         -Database=($occurance -> (Get: 1)),
                         -Table=($occurance -> (Get: 2)),
                         -KeyValue=($occurance -> (Get: 3)),
                         -NoValueLists,
                         -MaxRecords=(1),
                         -Search;
                     //
                     // Write the binary contents of the field
                     // to the HTML buffer, set the content type
                     // and end processing.
                     Content_Type: ($occurance -> (Get: 5));
                     $__html_reply__ = (Database_FMContainer:
                             ($occurance -> (Get: 4)));
                      Abort;
                  /Inline;
              /If;
         /Define_Tag;
     /If;

     //
     // Process requests to our LassoApp.
     If: (Action_Param: 'id');
         _ImgFMAserve: -ID=(Action_Param: 'id');
     /If;

?>


--
Douglas Burchard, President
DouglasBurchard.com, Web Applications
15024 NE 66th Street
Redmond, WA  98052, USA

direct: (206) 227-8161
[hidden email]
http://www.douglasburchard.com/


--
------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage