logo

New Response

« Return to the main article

You are replying to:

    • avatar
    • Leif
    • Posted on Thu 12 Sep 2002

    Hi,

    Here´s an example of how the same thing can be coded using a Lotus Script agent.

    Basically this example code works on some documents that contains the redirect-url stored in a field. The documents are also used for logging hit information for each url.

    A view displays the documents and generates the urls (... redirect?OpenAgent&url=http://www.lotus.com) that when clicked activates the agent. The agent also checks if the same IP is repeatingly hitting the same link, if so only 1 hit per hour is counted.

    /Leif

    ========= CODE STARTS ====================

    ' This agent is run when a link is clicked in the TopLinks form (see the form in action at http://www.just-in-mind.net/toplinks.nsf/toplinks) ' The agent saves hit information and redirects the user to the selected url

    Sub Initialize On Error Goto ErrH 'Variable Declarations Dim session As New NotesSession Dim db As NotesDatabase Dim view As NotesView Dim dc As NotesDocumentCollection Dim docContext As NotesDocument Dim docLink As NotesDocument Dim referenceDateTime As New NotesDateTime( "01/01/2002" ) Dim hitDateTime As New NotesDateTime( "Today" ) Dim linkURL As String Dim secs As Long Dim days As Integer 'Variable Initialization Set docContext = session.DocumentContext linkURL = GetParameter(docContext.Query_String_Decoded(0), "url") Set db = session.CurrentDatabase Set view = db.GetView("LinksURL") Set dc = view.GetAllDocumentsByKey(linkURL, True) 'Looping all matching Link documents Set docLink = dc.GetFirstDocument 'check if the same IP is hitting the same link repeatedly - if so, don´t save hit info Dim DateNow As Variant Dim diffDouble1 As Double Dim diffDouble2 As Double DateNow = Now If docContext.Remote_Addr(0) = docLink.Remote_Addr(0) Then diffDouble1 = Round(DateNow - docLink.LastModified, 4) diffDouble2 = 0.02 If diffDouble1 < diffDouble2 Then Print "[" & linkURL & "]" Exit Sub End If End If 'saving Hit info While Not docLink Is Nothing docLink.Hits = docLink.Hits(0) + 1 secs = hitDateTime.TimeDifference(referenceDateTime) days = Int( secs / 86400 ) docLink.DateScore = docLink.DateScore(0) + days docLink.Remote_Addr = docContext.Remote_Addr(0) docLink.Remote_User = docContext.Remote_User(0) Call docLink.Save(False, False) Set docLink = dc.GetNextDocument(docLink) Wend 'Redirecting user to selected URL Print "[" & linkURL & "]" Exit Sub ErrH: Print "Error " & Str(Err) & ": " & Error$ & " in redirect agent at line: " &Str(Erl) & " Agent run by: " & session.EffectiveUsername End Sub

    Function GetParameter(queryString As String, paramName As String) As String On Error Goto ErrH Dim v As Variant v = Evaluate ({@Middle("&} & queryString & {&";"&} & paramName & {=";"&")}) GetParameter = v(0) Exit Function ErrH: Print "Error " & Str(Err) & ": " & Error$ & " in GetParameter function in agent redirect at line: " &Str(Erl) End Function

    ============= CODE ENDS ======================

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment: