using Launch with php

2012-11-01
2012-11-14
  • jeff.sadowski
    jeff.sadowski
    2012-11-01

    Kept trying to look at php code using run "Launch in Firefox" or "Launch in Chrome" or …  and was annoyed that it didn't run a php interpreter on it. I created a script to help

    c:\helpers\wrapper.vbs

    'expects argument of form <browser>;<file_location>
    dim data
    dim url
    data=Split(WScript.Arguments(0),";")
    url=data(1)
    'if the file name ends in php replace c:\apache24\htdocs\ with 127.0.0.1 and replace all \ with /
    url=replace_directory("php","c:\apache24\htdocs\","127.0.0.1",url)
    'if the file name ends in php replace <network drive letter>:<path to root of web server> with <web server address> and replace all \ with /
    url=replace_directory("php","f:\var\www\html\","myserver",url)
    CreateObject("Wscript.Shell").Run data(0)+" """+url+""""
    'if the file name ends in <extension> replace <directory> with <url> and replace all \ with / otherwise return data unmodified
    Function replace_directory(extension,directory,url,data)
     If StrComp(LCase(Mid(data,Len(data)-(Len(extension)-1))),extension) = 0 Then
      If StrComp(LCase(Mid(data,1,Len(directory))),directory) = 0 Then
       replace_directory="http"+"://"+url+"/"+Replace(Mid(data,Len(directory)+1),"\","/")
      Else
       replace_directory=data
      End If
     Else
      replace_directory=data
     End If
    End Function
    

    then I edited his shortcuts.xml file to be as follows

    %APPDATA%\Notepad++\shortcuts.xml

            <Command name="Launch in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="70">wscript &quot;c:\helpers\wrapper.vbs&quot; &quot;firefox;$(FULL_CURRENT_PATH)&quot;</Command>
            <Command name="Launch in IE" Ctrl="yes" Alt="yes" Shift="yes" Key="73">wscript &quot;c:\helpers\wrapper.vbs&quot;  &quot;iexplore;$(FULL_CURRENT_PATH)&quot;</Command>
            <Command name="Launch in Chrome" Ctrl="yes" Alt="yes" Shift="yes" Key="82">wscript &quot;c:\helpers\wrapper.vbs&quot;  &quot;chrome;$(FULL_CURRENT_PATH)&quot;</Command>
            <Command name="Launch in Safari" Ctrl="yes" Alt="yes" Shift="yes" Key="88">wscript &quot;c:\helpers\wrapper.vbs&quot;  &quot;safari;$(FULL_CURRENT_PATH)&quot;</Command>
    

    My code could just as easily be used with perl or asp pages or anything.

    I'd post the entire shortcuts file but this form doesn't allow anything with proper urls

     
  • jeff.sadowski
    jeff.sadowski
    2012-11-01

    Wow that copies horribly. Sourceforge needs work on its forums.

    let me try quotes instead of code and see if copying works any better
    c:\helpers\wrapper.vbs

    'expects argument of form <browser>;<file_location>

    dim data
    dim url
    data=Split(WScript.Arguments(0),";")
    url=data(1)

    'if the file name ends in php replace c:\apache24\htdocs\ with 127.0.0.1 and replace all \ with /
    url=replace_directory("php","c:\apache24\htdocs\","127.0.0.1",url)
    'if the file name ends in php replace <network drive letter>:<path to root of web server> with <web server address> and replace all \ with /
    url=replace_directory("php","f:\var\www\html\","www.mvdwebexpress.com",url)

    CreateObject("Wscript.Shell").Run data(0)+" """+url+""""
    'if the file name ends in <extension> replace <directory> with <url> and replace all \ with / otherwise return data unmodified
    Function replace_directory(extension,directory,url,data)
    If StrComp(LCase(Mid(data,Len(data)-(Len(extension)-1))),extension) = 0 Then
      If StrComp(LCase(Mid(data,1,Len(directory))),directory) = 0 Then
       replace_directory="http"+"://"+url+"/"+Replace(Mid(data,Len(directory)+1),"\","/")
      Else
       replace_directory=data
      End If
    Else
      replace_directory=data
    End If
    End Function

    replacement code for
    %APPDATA%\Notepad++\shortcuts.xml

    <Command name="Launch in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="70">wscript &quot;c:\helpers\wrapper.vbs&quot; &quot;firefox;$(FULL_CURRENT_PATH)&quot;</Command>
            <Command name="Launch in IE" Ctrl="yes" Alt="yes" Shift="yes" Key="73">wscript &quot;c:\helpers\wrapper.vbs&quot;  &quot;iexplore;$(FULL_CURRENT_PATH)&quot;</Command>
            <Command name="Launch in Chrome" Ctrl="yes" Alt="yes" Shift="yes" Key="82">wscript &quot;c:\helpers\wrapper.vbs&quot;  &quot;chrome;$(FULL_CURRENT_PATH)&quot;</Command>
            <Command name="Launch in Safari" Ctrl="yes" Alt="yes" Shift="yes" Key="88">wscript &quot;c:\helpers\wrapper.vbs&quot;  &quot;safari;$(FULL_CURRENT_PATH)&quot;</Command>

     
  • jeff.sadowski
    jeff.sadowski
    2012-11-01

    how can I paste code on sourceforge so that you can copy the return characters?