Platforms to show: All Mac Windows Linux Cross-Platform
/Tools/PHP/Pe8Pe/Pe8Pe
Function:
Required plugins for this example: MBS MacBase Plugin, MBS Tools Plugin, MBS MacControls Plugin, MBS Main Plugin, MBS MacCocoa Plugin, MBS MacOSX Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Tools/PHP/Pe8Pe/Pe8Pe
This example is the version from Thu, 6th Apr 2016.
Function:
Required plugins for this example: MBS MacBase Plugin, MBS Tools Plugin, MBS MacControls Plugin, MBS Main Plugin, MBS MacCocoa Plugin, MBS MacOSX Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Tools/PHP/Pe8Pe/Pe8Pe
This example is the version from Thu, 6th Apr 2016.
Project "Pe8Pe.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control Rectangle1 Inherits Rectangle
ControlInstance Rectangle1 Inherits Rectangle
End Control
Control hrefsearchpattern Inherits TextArea
ControlInstance hrefsearchpattern Inherits TextArea
End Control
Control hrefreplacehpattern Inherits TextArea
ControlInstance hrefreplacehpattern Inherits TextArea
End Control
Control hrefsearchpattern2 Inherits TextArea
ControlInstance hrefsearchpattern2 Inherits TextArea
End Control
Control hrefreplacehpattern2 Inherits TextArea
ControlInstance hrefreplacehpattern2 Inherits TextArea
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control HTMLViewer1 Inherits HTMLViewer
ControlInstance HTMLViewer1 Inherits HTMLViewer
EventHandler Sub DocumentBegin(URL as String)
LoadPHPCode(URL)
End EventHandler
EventHandler Sub DocumentComplete(URL as String)
App.HTMLResultLoaded = False
Window1.Title = "Pe8Pe Browser v0.1 - "+App.httpWindowTitle
//onclick.setValue("onclick","Pe8PeCall.navigate("""+TheHREF+""");")
End EventHandler
EventHandler Sub DocumentProgressChanged(URL as String, percentageComplete as Integer)
Window1.Title = "Loading "+App.CurrentDocumentsFolderPath+App.filetoprocess+"... "+Str(percentageComplete)+"% Complete"
End EventHandler
EventHandler Sub TitleChanged(newTitle as String)
App.httpWindowTitle=newTitle
End EventHandler
End Control
EventHandler Sub Close()
Quit()
End EventHandler
EventHandler Function ContextualMenuAction(hitItem as MenuItem) As Boolean
If hitItem.Index=100001 Then
App.CurrentDocumentsFolderPath="documents/"
LoadPHPCode("index.php")
End If
End EventHandler
EventHandler Sub Open()
p=new MYPHP
rex=New RegExMBS
rex.CompileOptionMultiline=True
htmlEvents = new MyFrameEvents
HTMLViewer1.InstallWebFrameLoadDelegateMBS htmlEvents
Dim f As FolderItem
Dim fullpath As String
f = New FolderItem(App.CurrentDocumentsFolderPath+"/index.php")
fullpath = f.ShellPath
f=Nil
f = GetFolderItem(fullpath, FolderItem.PathTypeShell)
if f=Nil Or f.Exists=False Then
MsgBox "No index.php found. Application will quit now."
Quit()
End If
If TargetMacOS Or TargetCocoa Or TargetCarbon Or TargetMachO Then
p.setVariable("RBCurrentOS","0") ' Mac
ElseIf TargetWin32 Then
p.setVariable("RBCurrentOS","1") ' Windows
ElseIf TargetLinux Then
p.setVariable("RBCurrentOS","2") ' Linux
End if
p.setVariable("RBCurrentPath",Replace(f.ShellPath,"/index.php",""))
HTMLViewer1.LoadHTMLStringMBS("","")
f=Nil
'If p.LoadLibrary("mysql") = False Then
'MsgBox "Cannot load MySQL Module"
'End If
End EventHandler
Sub LoadPHPCode(URL As String)
if App.HTMLResultLoaded = False Then
App.HTMLResultLoaded=True
HTMLViewer1.StopLoadingMBS
Dim f As FolderItem
Dim t As TextInputStream
Dim loadhtml As Boolean = False
Dim fullpath As String = ""
Dim isPHPFile As Boolean = False
Dim isHTMLFile As Boolean = False
Dim isFileURL As Boolean = False
if URL.InStr("http://")>0 Or URL.InStr("https://")>0 Then
HTMLViewer1.LoadURLMBS(URL)
Return
End If
If URL.InStr(0,".php")>0 Then //PHP FILE
isPHPFile = True
ElseIf URL.InStr(0,".html")>0 Or URL.InStr(0,".htm")>0 Then //HTML FILE
isHTMLFile = True
End if
if URL.InStr("file://")>0 Then
isFileURL=True
End If
if isPHPFile Or isHTMLFile Then
Dim newurl As String
Dim pathtmparr(-1) As String
Dim newpath As String
Dim currentfoldersarray(-1) As String
if URL.InStr("://")>0 Then
newurl = URL.Mid((URL.InStr(0,"://")+3))
if isFileURL=False Then
newurl = newurl.Mid((newurl.InStr(0,"/")+1))
End If
Else
newurl=URL
End If
if isFileURL=False Then
pathtmparr=newurl.Split("/")
Else
Do
if newurl.InStr(0,"documents")>0 Then
newurl=newurl.Right(newurl.Len-(newurl.InStr(0,"documents")+9))
Else
Exit Do
End If
Loop
pathtmparr=newurl.Split("/")
End If
If pathtmparr.Ubound>0 Then
App.filetoprocess=pathtmparr(pathtmparr.Ubound)
For Each folder As String In pathtmparr
if folder=".." Then
currentfoldersarray=App.CurrentDocumentsFolderPath.Split("/")
App.CurrentDocumentsFolderPath=App.CurrentDocumentsFolderPath.Replace(currentfoldersarray(currentfoldersarray.Ubound-1)+"/","")
currentfoldersarray=Nil
Continue
End if
if folder.InStr(0,"?")>0 And folder.InStr(0,"=")>0 Then
Dim urlqueryparts(-1) As String
urlqueryparts=folder.Split("?")
folder=urlqueryparts(0)
App.filetoprocess=urlqueryparts(0)
ProcessGETQuery(urlqueryparts(1))
urlqueryparts=Nil
End if
App.CurrentDocumentsFolderPath=Replace(App.CurrentDocumentsFolderPath,folder+"/","")
App.CurrentDocumentsFolderPath=Replace(App.CurrentDocumentsFolderPath,"/"+folder,"")
App.CurrentDocumentsFolderPath=Replace(App.CurrentDocumentsFolderPath,folder,"")
if folder<>App.filetoprocess Then newpath=newpath+folder+"/"
Next
App.CurrentDocumentsFolderPath=App.CurrentDocumentsFolderPath+newpath
Else
App.filetoprocess=newurl
End if
f = New FolderItem(App.CurrentDocumentsFolderPath+App.filetoprocess)
fullpath = f.UnixpathMBS
f=Nil
f = GetFolderItem(fullpath, FolderItem.PathTypeShell)
If f <> Nil And f.Exists=True then
loadhtml=true
ElseIf f.Exists=False Then
HTMLViewer1.LoadHTMLStringMBS("<b>File ""+newurl+"" Not Found</b>","")
return
End if
Else
f = New FolderItem("documents/index.php")
fullpath = f.UnixpathMBS
f=Nil
f = GetFolderItem(fullpath, FolderItem.PathTypeShell)
If f <> Nil And f.Exists=True Then
loadhtml=true
isPHPFile = True //default index.php file
ElseIf f.Exists=False Then
HTMLViewer1.LoadHTMLStringMBS("<b>Error loading Index.php. File Not Found.</b>","")
return
End if
End if
If loadhtml = True Then
t=f.OpenAsTextFile
t.Encoding= Encodings.MacRoman
if isPHPFile Then
App.HTMLCode = p.Execute(PHPGetSets+"?>"+t.ReadAll)
ElseIf isHTMLFile Then
App.HTMLCode = t.ReadAll
End if
//Replacing Onclick to contain javascript callback
If rex.Compile(hrefsearchpattern.Text) = True Then
App.HTMLCode=rex.ReplaceAll(App.HTMLCode,hrefreplacehpattern.Text)
End If
//Replacing href by onclick to have javascript callback for navigation
If rex.Compile(hrefsearchpattern2.Text) = True Then
App.HTMLCode=rex.ReplaceAll(App.HTMLCode,hrefreplacehpattern2.Text)
End If
if fullpath.InStr(0,App.filetoprocess)>0 Then
fullpath = "file://"+fullpath
Else
fullpath="file://"+fullpath+App.filetoprocess
End If
HTMLViewer1.LoadHTMLStringMBS(App.HTMLCode,fullpath)
t.Close
Else
MsgBox "Error loading php result."
End If
f=Nil
t=Nil
End If
End Sub
Sub ProcessGETQuery(GetQueryString As String)
If GetQueryString<>"" Then
Dim GetQueryStringParts(-1) As String
Dim PHPVarName As String
Dim PHPVarValue As Variant
PHPGetSets=""
GetQueryStringParts=GetQueryString.Split("&")
For Each item As String In GetQueryStringParts
PHPVarName=item.Left(item.InStr(0,"=")-1)
PHPVarValue=item.Right((item.Len-PHPVarName.Len-1))
if PHPVarValue.IsNumeric() Then
PHPGetSets=PHPGetSets+"$_GET["""+PHPVarName+"""]="+PHPVarValue+";"+Chr(10)
PHPGetSets=PHPGetSets+"$_REQUEST["""+PHPVarName+"""]="+PHPVarValue+";"+Chr(10)
Else
PHPGetSets=PHPGetSets+"$_GET["""+PHPVarName+"""]=urldecode("""+PHPVarValue+""");"+Chr(10)
PHPGetSets=PHPGetSets+"$_REQUEST["""+PHPVarName+"""]=urldecode("""+PHPVarValue+""");"+Chr(10)
End If
Next
End If
End Sub
Property PHPGetSets As String
Property htmlEvents As MyFrameEvents
Property p As PHPMBS
Property rex As RegExMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem mnuReloadIndx(100001) = "&Reload Main Document"
MenuItem FileQuit(100002) = "&Quit"
MenuItem UntitledMenu1 = ""
End MenuBar
Class App Inherits Application
EventHandler Sub Open()
dim f as FolderItem
if TargetWin32 then
if not PHPMBS.LoadLibrary("C:\Programme\PHP\php5ts.dll") then
MsgBox "Failed to load php dll."
quit
end if
elseif TargetMachO then
f=GetFolderItem("libphp5.dylib")
if not PHPMBS.LoadLibrary(f) then
MsgBox "Failed to load php library."
quit
end if
elseif TargetLinux then
f=GetFolderItem("libphp5.so")
if not PHPMBS.LoadLibrary(f) then
MsgBox "Failed to load php library."
quit
end if
end if
htmlEventsCallBack=new MyScriptCallback
End EventHandler
Property CurrentDocumentsFolderPath As String = "documents/"
Property HTMLCode As String
Property HTMLResultLoaded As Boolean = False
Property filetoprocess As String
Property htmlEventsCallBack As MyScriptCallback
Property httpWindowTitle As String
End Class
Class MYPHP Inherits PHPMBS
End Class
Class MyFrameEvents Inherits WebFrameLoadDelegateMBS
EventHandler Function windowScriptObjectAvailable(WebView as WebViewMBS, windowScriptObject as WebScriptObjectMBS) As boolean
// Install an Object called "MyBrowser" on the javascript document object
// Any function call inside will tricker callback event
windowScriptObject.setWebScriptCallback "Pe8Pe", App.htmlEventsCallBack
End EventHandler
End Class
Class MyScriptCallback Inherits WebScriptCallbackMBS
EventHandler Function Callback(Name as string) As variant
Window1.HTMLViewer1.StopLoadingMBS
If Name = "Navigate" Then
Window1.LoadPHPCode(Me.ArgumentValue(0))
End If
End EventHandler
End Class
End Project
The items on this page are in the following plugins: MBS Tools Plugin.
Feedback: Report problem or ask question.