Programming

Dynamic Video Player Selection with iframe Embeds

Its a real challenge providing a video on your web site that can be viewed on any device accessing it, i.e. desktop computer, smart phone, PDA, or tablet. HTML5 is gaining ground against Flash, but not all devices will support this format and may only have one type of video player installed. A computer that does not have the correct version of Flash will not be able to play certain Flash videos.

The solution to make videos cross platform is iframe embedding. This will allow a device to choose the right player for a video embedded on a web site.

iframe Embed on YouTube

A video can be embedded in YouTube with the following code:

<iframe class="youtube-player" type="text/html" width="640" height="385"
        src="http://www.youtube.com/watch?v=bu06YnJlmiQ?fs=1&amp;h1=en_US" frameborder="0>
</iframe>http://www.youtube.com/v/bu06YnJlmiQ?fs=1&amp;hl=en_US

The URL in red is the URL of the video on YouTube. You need to include ?fs=1&amp;hl=en_US after the video URL otherwise the HTML page will be embedded in the page as opposed to just the video.

The following is an example of iframe embedding.

Updating RSVP from the Delivery Message in a DFS Notification

I had complaints from customers that the Viewed column in the Notification RSVP Status Results wasn’t updated when they sent out a notification (see below). Normally, there should be a date and time when the customer clicked on a link in their notification e-mail that lead them to the planroom.

Notification RSVP Status Result

The problem is that if you set the e-mail link to go right to the project, the Viewed column won’t be updated. This column will only be updated if the URL will take you to the Display HTML page in the notification. The URL needs to point to (%NP:NotificationURL%) to open the Display HTML page and then the Viewed column will be updated with the date and time they entered that page.

The notification that you create may not necessarily require a Display HTML page and should go directly to the DFS project. In situations like this, its best to direct the link to Display HTML, and then in that page redirect the user automatically to the project with (%NAN:Project URL%) as the URL.

The notification will need Project URL defined in the Attributes tab. The only required fields that should be set are Type = Text and Length = 200.

Notifications will then update the Viewed column in RSVP every time a user clicks on a link to enter a project. They won’t see the Delivery Message because it has no content to display.

Below is an example of URL redirection. The Delivery Message is an e-mail the customer receives and when they click on the link, it will take them to their project. The e-mail only sends the customer’s user name and password to use their planroom. There is no need for a Display HTML page and the client should be go directly to the planroom when they click on the enter planroom link. The link here will open the Delivery Message which then redirects them to the Project using Refresh in a metatag.

 

[== Code: Delivery Message ============================]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>DFS Account Information</title>
  </head>

  <body>
    <p>The following user account will allow you to login to a DFS Plan Room, where you can view and order documents.</p>

    <p>User Name: <strong>(%NRP:LoginName%)</strong><br />
    Password: <strong>(%NRP:Password%)</strong></p>

    <p>Click <a href="(%NP:NotificationURL%)">here</a> to enter the planroom.</p>
  </body>
</html>

[== Code ==============================================]

 

[== Code: Display HTML ================================]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta http-equiv="Refresh" content="0; url=
(%NAN:Project URL%)">
    <title></title>
  </head>

  <body>
  </body>
</html>

[== Code ==============================================]

Getting the PowerShell Version

To find out which version of PowerShell is installed in your computer, you need to do more than just run it. When you start the command line interface, your lead to believe that version 1.0 is installed from the directory location displayed in the dialog box.

The text in the dialog box shows C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe, which would make it seem like you were running version 1.0. The best way to determine which version is installed is to run the PowerShell command line interface and execute the following command:

    $Host.Version

This will give you the major and minor versions, along with the build and revision.

image

SendMail Function for PowerShell

The SendMail function for PowerShell will send an e-mail through an SMTP server. I’m currently using it for backing up a web server to a virtual machine and sending a confirmation by e-mail on the status of the backup.

Usage is very simple:

          SendMail Host From To Subject Message UserName Password

The Host is the mail server address, i.e. smtp.mail.com. The From and To are the sender and receiver of the e-mail. The Subject and Message are the title and contents of the e-mail. If authentication is required, then enter values for the UserName and Password, otherwise make them blank using single quotes, i.e. ‘’.

The function will return a boolean value: true if the mail was sent successfully, false if it couldn’t be sent. See example in this post.

 

SendMail Code

The following is the code for the SendMail function which can be pasted in your PowerShell application.

[== Code ==============================================]

function SendMail ([string] $sHost, [string] $sFrom, [string] $sTo, [string] $sSubject, [string] $sMessage, [string] $sUserName, [string] $sPassword)

####################################################################################################
# PURPOSE:
#   Sends an e-mail to an SMTP server. It will also authenticate to the server if a user name and
#   password are sent to the function. If authentication is not used, leave $sUserName and $sPassowrd
#   blank, i.e. ”.
#
# PARAMETERS:
#   $sHost (in) – host name of mail server
#   $sFrom (in) – e-mail address of mail sender
#   $sTo (in) – e-mail address of mail recipient
#   $sSubject (in) – subject title of message
#   $sMessage (in) – message sent to recipient
#   $sUserName (in) – user name for authentication
#   $sPassword (in) – password for authentication
#
# RETURN:
#   True – mail was sent succesfully
#   False – mail was not sent
####################################################################################################

{
  [bool] $bSuccess = 1                 # was mail sent without problems?

  $SmtpClient = new-object system.net.mail.smtpClient 
  $smtpclient.Host = $sHost

  # Authenticate only if a user name and password are set.
  if (($sUsername -ne ”) -band ($sPassword -ne ”))
  {
    $Credentials = new-object System.Net.networkCredential

    $Credentials.domain = ""
    $Credentials.UserName = $sUserName
    $Credentials.Password = $sPassword
    $SMTPClient.Credentials = $Credentials
  } # if (($sUsername -ne ”) -band ($sPassword -ne ”))

  # Send the mail.
  try
  {
    $smtpclient.Send($sFrom, $sTo, $sSubject, $sMessage)
  }
  catch
  {
    $bSuccess = 0
  }
  $bSuccess
} # SendMail

[== Code ==============================================]

 

Example of the SendMail Function

This is an example of how the SendMail function should be used.

[== Code ==============================================]

$bSent = SendMail ‘smtp.mail.com’ ‘sender@website.com’ ‘recipient@website.com’ ‘Test’ ‘This is a test.’ ‘sender@website.com’ ‘abc123′

if ($bSent)
{
  "Mail sent successfully."
}


else
{
  "Mail not sent."
}

[== Code ==============================================]

 

You can download the SendMail code and example here.

How to Redirect Web Pages (Part 1)

Redirecting web pages becomes necessary when a web site is updated and old pages are replaced with new ones. This is very common when a site is upgraded to a CMS which typically displays pages as folders (i.e. www.website.com/about) as opposed to www.website.com/about.htm.

Its important to redirect old pages to new ones because if the old page is bookmarked in a web browser, it will lead to a 404 error page and the user will probably not try to manually change the URL to go to the home page. Also, its better for SEO to have a consistent page structure in your site.

Redirection in IIS

The easiest way to redirect web pages is through the Management Console in IIS in Windows. Find the page you want to redirect, right click on it, and select Properties. This will give you the following dialog box.

Redirecting a Page in IIS

Select the A redirection to a URL radio button and enter the URL of the new page in the Redirect to textbox. Press the OK button to save the settings. When the page is viewed in a web browser, it will automatically redirect the browser to http://www.website.com/about.

Redirecting Using HTML

You can also give instructions to redirect in a web page. The page that needs to be directed will contain the code below. The meta tag should be enough to do the redirect, but on some web servers it may not work. The JavaScript below will redirect only if JavaScript is enabled on the user’s web browser. The meta redirect is done on the server side and doesn’t require any settings on the user’s part.

<html>
<head>
<meta http-equiv=”Refresh” content=”0; http://www.website.com/about”>
</head>

<body>
<script language=”javascript”>
window.location = “http://www.website.com/about”;
</script>
</body>
</html>

In Part 2, I’ll show you how to redirect web pages in Apache using .htaccess.