We have images...

Images on old blog posts should be back.  Not perfect yet as the thumbnails are just shrunk rather than resized, but at least there are images..  Wanna see how?  Not the prettiest thing in the world, but it's my first Graffiti Plug-in from scratch.

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Graffiti.Core
Imports Graffiti.Core.GraffitiApplication
Imports System.IO
Imports System.Web
Imports System.Diagnostics
Public Class ImageRedirect
    Inherits GraffitiEvent

    Public Overrides ReadOnly Property Name() As String
        Get
            Return "CS Image Redirect"
        End Get
    End Property

    Public Overrides ReadOnly Property Description() As String
        Get
            Return "CS embedded image plugin"
        End Get
    End Property

    Public Overrides Sub Init(ByVal ga As GraffitiApplication)
        AddHandler ga.BeginRequest, AddressOf ga_BeginRequest
    End Sub

    Private Sub ga_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        Dim thelog As New EventLog
        If Not EventLog.SourceExists("Gregs Log") Then
            EventLog.CreateEventSource("Gregs Log", "GraffitiSite")
        End If

        If HttpContext.Current.Request.Path.Contains("photos/") Then
            Dim s1 As String = HttpContext.Current.Request.Path
            Dim strarr As String()
            strarr = s1.Split("/")
            Dim s2 As String
            s2 = strarr.GetValue(strarr.Length - 2)
            Dim dir As New DirectoryInfo(HttpContext.Current.Server.MapPath("~/photos/storage"))
            Dim files As FileInfo() = dir.GetFiles("1000.*." & s2 & ".*", SearchOption.TopDirectoryOnly)
            If files.Length = 1 Then
                HttpContext.Current.Response.Redirect("~/photos/storage/" & files(0).Name)
            End If 

        End If

    End Sub
End Class

 

Comments

Now I can fall asleep.

I kid! I kid!

Leave a Comment

 
click analytics