• Ability to easily add file resources (specifically images) to the content.

    By Andrew Luke 1 decade ago

    I wrote this mod for the WikiPage class convertSingleBrackets function.



    '** [image:filename_id!!filename.ext left|right] should become an <img> tag to a file resource within the database



    'This !! syntax is used for entering image resources (images contained in resource documents)

    'If present we need to extract specific information from the string, see above for syntax

    intLoc1 = Instr(newText, "!!")

        <br/>
    

    If intLoc1 <> 0 Then

    'Get the filename id (eg TheFriendlyName) and the specified filename (eg AttachedImage.jpg)<br/>
    'With this we need to generate the image url eg/PATH TO DATABASE/WebFiles/KEY/$File/FILENAME<br/>
    'WebFiles - is the view containing the image documents<br/>
    'Key - is the filename id<br/>
    'Filename - is the image filename with extension<br/>
    intLoc2 = Instr(newText, &quot; &quot;)<br/>
    fileID = Mid(newText, (Instr(newText, &quot;:&quot;)+1), intLoc1-7)<br/>
    If intLoc2 &lt;&gt; 0 Then<br/>
        fileName = Left(Strright(newText, &quot;!!&quot;), Instr(Strright(newText, &quot;!!&quot;), &quot; &quot;)-1)<br/>
    Else<br/>
        fileName = Mid(newText, intLoc1+2,  Len(newText)-intLoc1-2)<br/>
    End If<br/>
    imagePath = Evaluate(|&quot;../webfiles/| &amp; fileID &amp; |/$file/| &amp; fileName &amp; |&quot;|)<br/>
    leftText = &quot;image:&quot; &amp; imagePath(0)<br/>
    rightText = Strright(newText, &quot; &quot;)<br/>
    

    Else

    leftText = Strleft(newText, &quot; &quot;)<br/>
    rightText = Strright(newText, &quot; &quot;)<br/>
    

    End If

    • Further more... links.

      By Andrew Luke 1 decade ago

      Attached code adjusted slightly to also file links.



      Public Function convertSingleBracket (txt As String) As String



      ' special single-bracket cases

      '
      [http://example.com linkname] should be converted to a link

      ' [file:filename linkname] is a link reference to an attached file

      '
      [file:filename_id!!filename.ext linkname] is a link reference to file in a resource document

      ' [image:filename left|right] should become an <img> reference

      '
      [image:filename_id!!filename.ext left|right] should become an <img> tag to a file resource within the database

      '** [wiki:WikiWord alternate text] is a WikiWord link with alternate text



      Dim leftText As String

      Dim rightText As String

      Dim newText As String

      Dim fileWebPath As Variant

      Dim intLoc1, intLoc2 As Integer

      Dim fileID, fileName As String

          <br/>
      

      ' remove any brackets that may have snuck in there

      newText = Trim(Replace(txt, "[", ""))

      '
      get rid of any HTML tags we might have inadvertantly inserted

      newText = ReplaceRangeEnds(newText, "<", ">", "", "", "*", True)



      'This !! syntax is used for entering image resources (images contained in resource documents)

      'If present we need to extract specific information from the string, see above for syntax

      intLoc1 = Instr(newText, "!!")

          <br/>
      

      If intLoc1 <> 0 And (Instr(newText, "image:")=1 Or Instr(newText, "file:")=1) Then

      'Get the filename id (eg TheFriendlyName) and the specified filename (eg AttachedImage.jpg)

      'With this we need to generate the image url eg/PATH TO DATABASE/WebFiles/KEY/$File/FILENAME

      'WebFiles - is the view containing the image documents

      'Key - is the filename id

      'Filename - is the image filename with extension

      intLoc2 = Instr(newText, " ")

      fileID = Mid(newText, (Instr(newText, ":")+1), intLoc1-(Instr(newText, ":")+1))

      If intLoc2 <> 0 Then

      fileName = Left(Strright(newText, &quot;!!&quot;), Instr(Strright(newText, &quot;!!&quot;), &quot; &quot;)-1)<br/>
      

      Else

      fileName = Mid(newText, intLoc1+2,  Len(newText)-(intLoc1-1))<br/>
      

      End If

      'The relative path name to the file in the resource document

      fileWebPath = Evaluate(|"../webfiles/| & fileID & |/$file/| & fileName & |"|)

      'Check if we're creating a file link or an image link

      If Instr(newText, "image:")=1 Then

      leftText = &quot;image:&quot; &amp; fileWebPath(0)<br/>
      

      Else

      leftText = &quot;file:&quot; &amp; fileWebPath(0)<br/>
      

      End If

      'The alignment (for images) or the link name (for files)

      rightText = Strright(newText, " ")

      Else

      leftText = Strleft(newText, " ")

      rightText = Strright(newText, " ")

      End If