Subversion Repositories php-qbpwcf

Rev

Rev 226 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
239 liveuser 6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
8 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
 
25
/*
26
說明:
27
請先運行 php -f sample/webSock:nativeSocketTcpIpServer.php 20250108-paired-with-window.qbpwcf.ws-20250108-from-javaScript::qbpwcfJavaScript
28
*/
29
 
30
#使用命名空間qbpwcf
31
namespace qbpwcf;
32
 
33
#assets dir
34
$assetsDir="assets_of_javaScript::qbpwcfJavaScript_20250108";
35
 
226 liveuser 36
#產生 qbpwcfJavaScript
8 liveuser 37
#函式說明:
38
#建立qbpwcf專屬的js函式庫
39
#回傳結果
40
#$result["funciton"],當前函式的名稱.
41
#$result["status"],執行的狀態,"true"代表正常,"false"代表不正常.
42
#$result["error"],錯誤訊息
43
#$result["content"],語法.
44
#必填參數:
45
#無.
46
#可省略參數:
47
#$conf["noScriptTag"],字串,是否不要輸出<script></script>,預設為"false",代表要輸出;反之為"true",代表不要輸出.
48
$conf["noScriptTag"]="false";
49
#參考資料:
50
#無.
51
#備註:
52
#無.
53
$qbpwcfJavaScript=javaScript::qbpwcfJavaScript($conf);
54
unset($conf);
55
 
56
#如果產生失敗
57
if($qbpwcfJavaScript["status"]==="false")
58
{
59
 
60
	#show detail info
61
	var_dump($qbpwcfJavaScript);
226 liveuser 62
 
8 liveuser 63
	#結束執行,並回傳shell 1.
64
	exit(1);
65
 
66
}#if end
67
 
68
#印出 js
69
echo $qbpwcfJavaScript["content"];
70
 
71
#執行目標程式
72
#函式說明:
73
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
74
#回傳結果:
75
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
76
#$result["error"],錯誤訊息陣列
77
#$result["function"],當前執行的函數名稱
78
#$result["content"],要執行的javaScript語法
79
#必填參數:
80
#$conf["script"],字串,要執行的javaScript語法.
81
$conf["script"]="
82
 
83
	//初始化參數
84
	var params={};
226 liveuser 85
 
8 liveuser 86
	//設定websocket位置
87
	params.url='wss://silverblue-guest.qbpwcf.org/wss';
226 liveuser 88
 
8 liveuser 89
	//要傳輸的資料
90
	params.data={};
226 liveuser 91
 
8 liveuser 92
	//用來識別是所需要資料的id
93
	params.data.id=crypto.randomUUID();
226 liveuser 94
 
8 liveuser 95
	//設置要用get
96
	params.data.Method='GET';
226 liveuser 97
 
8 liveuser 98
	//設置目標host
99
	params.data.Host='silverblue-guest.qbpwcf.org';
226 liveuser 100
 
8 liveuser 101
	//設置要抓取的檔案
102
	params.data.File='index.php';
226 liveuser 103
 
8 liveuser 104
	//取得對應的回應
105
	var response=await window.qbpwcf.ws.init(params);
226 liveuser 106
 
8 liveuser 107
	//debug
108
	console.log('after got response');
226 liveuser 109
 
8 liveuser 110
	//debug
111
	console.log(response);
112
 
113
	";
114
#可省略參數:
115
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
116
#$conf["onReady"]="true";
117
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
118
#$conf["globalJs"]=array();
119
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
120
#$conf["jsFunciton"]=array();
121
#$conf["noScriptTag"],字串,是否不要輸出<script></script>,預設為"false",代表要輸出;反之為"true",代表不要輸出.
122
#$conf["noScriptTag"]="false";
123
#參考資料:
124
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
125
#備註:
126
#無.
127
$toScript=javaScript::toScript($conf);
128
unset($conf);
129
 
130
#如果執行失敗
131
if($toScript["status"]==="false"){
132
 
133
	#show detail info
134
	var_dump($toScript);
226 liveuser 135
 
8 liveuser 136
	#結束執行,並回傳shell 1.
137
	exit(1);
138
 
139
	}#if end
140
 
141
#印出js語法
226 liveuser 142
echo $toScript["content"];