Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge proto in main #88

Merged
merged 470 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
470 commits
Select commit Hold shift + click to select a range
00692ab
log
Jan 12, 2023
cf53328
log
Jan 12, 2023
b75b132
log
Jan 12, 2023
b8765a5
next
Jan 12, 2023
9980380
array
Jan 12, 2023
a6a575c
corrected and complete
Jan 12, 2023
d65bd2c
insert
Jan 12, 2023
3bc2f33
typo
Jan 12, 2023
b708415
style
Jan 12, 2023
86ed107
css
Jan 12, 2023
3412c4f
update grid creation
Jan 12, 2023
ab03623
debug
Jan 12, 2023
adbab5b
correct
Jan 12, 2023
4b107c3
refactor
Jan 12, 2023
a724c76
simplify
Jan 12, 2023
97bb88a
style
Jan 12, 2023
639fd5a
typo
Jan 12, 2023
ba33fb4
\n
Jan 13, 2023
0f31aa8
innertext
Jan 13, 2023
5f7c5be
innertext
Jan 13, 2023
4efd092
test
Jan 13, 2023
e6a0781
description
Jan 13, 2023
32555ee
test
Jan 13, 2023
17f486d
test
Jan 13, 2023
7c60cd5
test
Jan 13, 2023
ba78e81
indent
Jan 13, 2023
0cd13d5
indent
Jan 13, 2023
f6c916b
cleanup
Jan 13, 2023
5981b98
typo
Jan 13, 2023
912f54b
clean css
Jan 13, 2023
fa826bc
unlock width
Jan 13, 2023
e31ea22
img src
Jan 13, 2023
0365600
typo
Jan 13, 2023
40fadf8
typo
Jan 13, 2023
af43e4b
do not allow hidden or deprecated
Jan 13, 2023
8b0b2ca
typo
Jan 13, 2023
d629bba
log
Jan 13, 2023
6aac0f4
missing parenthesis
Jan 13, 2023
2b82319
log
Jan 13, 2023
dff63e5
debug
Jan 13, 2023
60f7475
log
Jan 13, 2023
a0fc2be
debug
Jan 13, 2023
0ad62cf
log
Jan 13, 2023
5b66f46
log
Jan 13, 2023
99b946f
log
Jan 13, 2023
04cc38b
log
Jan 16, 2023
e90fb73
log
Jan 16, 2023
e656ffb
log
Jan 16, 2023
2d8008e
enum
Jan 16, 2023
af1e2d3
log
Jan 16, 2023
f2aaa88
license
Jan 16, 2023
4c5c84f
insert license
Jan 16, 2023
d99c9e6
debug
Jan 16, 2023
088ba44
license
Jan 16, 2023
cf7641b
test
Jan 16, 2023
679b1a9
license
Jan 16, 2023
a34b0a7
correct
Jan 16, 2023
8a6c746
typo
Jan 16, 2023
d2ced78
typo
Jan 16, 2023
da5d456
skip documentation url
Jan 16, 2023
981c358
typo
Jan 16, 2023
47fead7
test
Jan 16, 2023
3a6dbb8
$
Jan 16, 2023
e2225b7
base_type
Jan 16, 2023
03ba9c5
forge url
Jan 16, 2023
d7673b4
typo
Jan 16, 2023
b8ed37e
name
Jan 16, 2023
3d01c23
debug
Jan 16, 2023
09e3c7a
0
Jan 16, 2023
3f3598b
debug
Jan 16, 2023
abb2f06
typo
Jan 16, 2023
6bba377
log
Jan 16, 2023
9286e6d
debug
Jan 16, 2023
3dfd7d5
debug
Jan 16, 2023
22a5ca8
debug
Jan 16, 2023
f6afdec
needs_robot_content
Jan 16, 2023
d735840
typo
Jan 16, 2023
c733114
typo
Jan 16, 2023
9a47c66
typo
Jan 16, 2023
3286040
typo
Jan 16, 2023
95a1474
slot type
Jan 16, 2023
92bb6cb
;
Jan 16, 2023
c17c9d0
remove log
Jan 16, 2023
57b8127
check for license
Jan 16, 2023
759a79a
fetch doc
Jan 17, 2023
4914e10
log
Jan 17, 2023
496fd77
content
Jan 17, 2023
ff884f7
test
Jan 17, 2023
b6d5780
log
Jan 17, 2023
6102461
test
Jan 17, 2023
1d4e4bd
json
Jan 17, 2023
4b026e6
restrict queried field
Jan 17, 2023
24dffd9
typo
Jan 17, 2023
f274a0d
replace
Jan 17, 2023
294005a
typo
Jan 17, 2023
38e7dcd
log
Jan 17, 2023
09854d3
json
Jan 17, 2023
deaad21
remove log
Jan 17, 2023
1e5d082
try
Jan 17, 2023
6052682
move
Jan 17, 2023
f492a41
test
Jan 17, 2023
30797bf
move
Jan 17, 2023
37cf2e7
path
Jan 17, 2023
4e1afb4
test
Jan 17, 2023
d54492c
htaccess
Jan 17, 2023
db6c502
cors
Jan 17, 2023
a7e7e36
..
Jan 17, 2023
959e208
base_type
Jan 17, 2023
710a2dd
typo
Jan 17, 2023
be03213
free
Jan 17, 2023
d7aa6f0
return
Jan 17, 2023
e3d0a1c
test
Jan 17, 2023
287ef3f
test
Jan 17, 2023
c905a04
test
Jan 17, 2023
b4ecfe6
test
Jan 17, 2023
082f212
result
Jan 17, 2023
b3224e4
branch
Jan 17, 2023
0aed25b
branch
Jan 17, 2023
1eab2b3
branch
Jan 17, 2023
4c4c737
test
Jan 17, 2023
0b03ded
test
Jan 17, 2023
6c0f476
test
Jan 17, 2023
a8d257e
test
Jan 17, 2023
f98c334
rowg
Jan 17, 2023
d9edaa5
test
Jan 17, 2023
fc5892e
test
Jan 17, 2023
963ea1c
test
Jan 17, 2023
58457df
test
Jan 17, 2023
004d26a
array
Jan 17, 2023
41d954c
test
Jan 17, 2023
56a532d
test
Jan 17, 2023
fedf3d5
arrayg
Jan 17, 2023
4657fe5
test
Jan 17, 2023
c2d4090
test
Jan 17, 2023
ff05edf
test
Jan 17, 2023
5e15670
test
Jan 17, 2023
c243773
test
Jan 17, 2023
207be31
condition
Jan 17, 2023
bd4c867
test
Jan 17, 2023
a9d462a
test
Jan 17, 2023
ac9cca5
test
Jan 17, 2023
88141ec
test
Jan 17, 2023
039b9cc
test
Jan 17, 2023
37aadbe
test
Jan 17, 2023
273280b
test
Jan 17, 2023
a870441
test
Jan 17, 2023
eb75eaa
test
Jan 17, 2023
3349d17
test
Jan 17, 2023
5b4e298
test
Jan 17, 2023
a1a0cbf
test
Jan 17, 2023
3403d85
test
Jan 17, 2023
fc7c9b3
test
Jan 17, 2023
bd8332b
test
Jan 17, 2023
0e350e6
slot_type
Jan 17, 2023
d8c3134
test
Jan 17, 2023
88ebfc1
test
Jan 17, 2023
977de55
test
Jan 17, 2023
8592d1d
test
Jan 17, 2023
15baf89
test
Jan 17, 2023
b448678
typo
Jan 17, 2023
b05622a
udpate
Jan 17, 2023
16c41e5
clean up
Jan 17, 2023
05ddc69
cleanup
Jan 17, 2023
33ee5dc
test
Jan 17, 2023
c438980
text
Jan 17, 2023
495a877
typo
Jan 17, 2023
d047150
log
Jan 17, 2023
645367e
test
Jan 17, 2023
cb7c2d5
cleanup
Jan 17, 2023
2b09d8b
empty type slot
Jan 17, 2023
a16e9b2
fix conflicts
Jan 18, 2023
bf7f6f3
update db
Jan 18, 2023
87928cb
clean up
Jan 18, 2023
8007fa8
style
Jan 18, 2023
3c06f75
typo
Jan 18, 2023
18091b1
style
Jan 18, 2023
7599222
stars
Jan 19, 2023
eca4ecf
fix conflicts
Jan 20, 2023
7ee89f5
remove ace
Jan 20, 2023
49d799d
Update httpdocs/js/project.js
Jan 20, 2023
c0de5d7
Update httpdocs/js/project.js
Jan 20, 2023
adf3879
restore testing
Jan 20, 2023
b9d3807
Update httpdocs/js/webots-cloud.js
Jan 20, 2023
e61c187
Update httpdocs/ajax/proto/create.php
Jan 20, 2023
ece6377
Merge branch 'main' into proto
Jan 23, 2023
240fc23
style
Jan 23, 2023
653fa3c
const
Jan 23, 2023
c1261ed
Update httpdocs/ajax/proto/insertable.php
Jan 23, 2023
e96442f
Update httpdocs/ajax/proto/list.php
Jan 23, 2023
27904e0
column
Jan 23, 2023
7630588
try dynamic import
Jan 23, 2023
a89de83
debug
Jan 23, 2023
0272db0
log
Jan 23, 2023
2aebbf4
get the right version
Jan 23, 2023
da68be8
Merge branch 'main' into proto
Jan 27, 2023
a8ea58c
test
Jan 31, 2023
689f310
yaml folder
Jan 31, 2023
312ffec
yaml
Jan 31, 2023
6cd3b2d
test
Jan 31, 2023
e2f8ec4
try with ending slash
Jan 31, 2023
51777b2
escape
Jan 31, 2023
df28c6c
test
Jan 31, 2023
5fd50a7
test
Jan 31, 2023
7865e7f
test
Jan 31, 2023
a2964a0
worlds
Jan 31, 2023
27e559f
Merge branch 'main' into proto
Jan 31, 2023
27615a6
debug
Jan 31, 2023
e86d00b
debug
Jan 31, 2023
9174e18
debug
Jan 31, 2023
509195a
test
Jan 31, 2023
77eee31
test
Jan 31, 2023
f78af6f
remove debug
Jan 31, 2023
5716087
differentiate errors
Jan 31, 2023
1c2ce21
lower case
Jan 31, 2023
5486e7c
base_type
Jan 31, 2023
4b92340
url
Jan 31, 2023
94c7a66
test
Jan 31, 2023
123e078
debug
Jan 31, 2023
2aefc7b
typo
Jan 31, 2023
82ea7c0
debug text
Jan 31, 2023
0f1a6d0
debug
Jan 31, 2023
4650c99
test
Jan 31, 2023
14d27b7
test
Jan 31, 2023
7a5c8fb
test
Jan 31, 2023
0eca751
remove print
Jan 31, 2023
5c01a40
test
Jan 31, 2023
e076a6b
test
Jan 31, 2023
7545acd
test
Jan 31, 2023
d01b406
index
Jan 31, 2023
56ab71b
test
Jan 31, 2023
1ef933f
typo
Jan 31, 2023
16b6052
typo
Jan 31, 2023
5afb4d3
typo
Jan 31, 2023
1a66482
remove print
Jan 31, 2023
d1089ef
page
Jan 31, 2023
f362a81
test
Jan 31, 2023
7faa252
test
Jan 31, 2023
4d3c3d8
test
Jan 31, 2023
d26a414
remove print
Jan 31, 2023
89cd87d
go to last page
Jan 31, 2023
d824f67
test
Jan 31, 2023
761c234
test
Jan 31, 2023
3a366eb
fix title
Feb 2, 2023
73dfed6
Merge branch 'main' into proto
Feb 3, 2023
3dcdfd4
Merge branch 'main' into proto
omichel Feb 7, 2023
21cc81d
remove showdown
Feb 7, 2023
92782fb
test
Feb 7, 2023
ac4493e
test
Feb 7, 2023
3166d71
test
Feb 7, 2023
7d5983e
cleanup
Feb 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions database/webots-cloud.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ALTER TABLE `server`
CREATE TABLE `project` (
`id` int(11) NOT NULL,
`url` varchar(2048) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`viewed` int(11) NOT NULL,
`stars` int(11) NOT NULL,
`title` varchar(256) NOT NULL,
`description` varchar(2048) NOT NULL,
Expand Down Expand Up @@ -82,6 +83,28 @@ CREATE TABLE `server_branch` (
ALTER TABLE `server_branch`
ADD PRIMARY KEY (`id`,`branch`);

CREATE TABLE `proto` (
`id` int(11) NOT NULL,
`url` varchar(2048) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`viewed` int(11) NOT NULL,
`stars` int(11) NOT NULL,
`title` varchar(256) CHARACTER SET utf8mb4 NOT NULL,
`description` varchar(2048) CHARACTER SET utf8mb4 NOT NULL,
`version` varchar(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`branch` varchar(256) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`license_url` varchar(256) CHARACTER SET utf8mb4 NOT NULL,
`license` varchar(256) CHARACTER SET utf8mb4 NOT NULL,
`base_type` varchar(256) CHARACTER SET utf8mb4 NOT NULL,
`needs_robot_ancestor` varchar(256) CHARACTER SET utf8mb4 NOT NULL,
`slot_type` varchar(256) CHARACTER SET utf8mb4 NOT NULL,
`updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE `proto`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `url_branch` (`url`,`branch`) USING BTREE;
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

CREATE TABLE `queue` (
`project` int(11) NOT NULL,
`participant` varchar(2048) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion httpdocs/404.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$uri = strtok($_SERVER['REQUEST_URI'], '?');
if (strlen($uri) == 8 && in_array($uri[1], array('A', 'S')))
$found = file_exists('storage' . $uri);
elseif (in_array($uri, array('/settings', '/terms-of-service', '/privacy-policy', '/scene', '/animation', '/simulation', '/competition', '/server', '/run')))
elseif (in_array($uri, array('/settings', '/terms-of-service', '/privacy-policy', '/scene', '/animation', '/simulation', '/competition', '/server', '/run', 'proto')))
$found = true;
else
$found = false;
Expand Down
10 changes: 5 additions & 5 deletions httpdocs/ajax/project/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function error($message) {
$data = json_decode($json);
require '../../../php/github_oauth.php';
require '../../../php/database.php';
require '../../../php/simulation.php';
require '../../../php/github_asset.php';
$mysqli = new mysqli($database_host, $database_username, $database_password, $database_name);
if ($mysqli->connect_errno)
error("Can't connect to MySQL database: $mysqli->connect_error");
Expand All @@ -23,7 +23,7 @@ function error($message) {
if (!is_array($check_url))
error($check_url);
list($username, $repository, $tag_or_branch, $folder, $world) = $check_url;
$world_url = "https://raw.githubusercontent.com/$username/$repository/$tag_or_branch$folder/worlds/$world";
$world_url = "https://raw.githubusercontent.com/$username/$repository/$tag_or_branch$folder$world";
$world_content = @file_get_contents($world_url);
if ($world_content === false) {
$query = "DELETE FROM project WHERE id=$id";
Expand All @@ -34,7 +34,7 @@ function error($message) {
}

# check and retrieve information from webots.yaml file
$check_yaml = simulation_check_yaml($check_url);
$check_yaml = github_check_yaml($check_url, $proto = false);
if (!is_array($check_yaml)) {
$query = "DELETE FROM project WHERE id=$id";
$mysqli->query($query) or error($mysqli->error);
Expand Down Expand Up @@ -108,9 +108,9 @@ function error($message) {
$mysqli->query($query) or error($mysqli->error);
if ($mysqli->affected_rows != 1) {
if ($id === 0)
error("This simulation already exists");
error("This simulation already exists.");
else
error("Failed to update the simulation");
error("Failed to update the simulation.");
}

# return answer
Expand Down
254 changes: 254 additions & 0 deletions httpdocs/ajax/proto/create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
<?php # This script initializes a new proto
# exit and error message
function error($message) {
die("{\"error\":\"$message\"}");
}

# get content
header('Content-Type: application/json');
$json = file_get_contents('php://input');
$data = json_decode($json);
require '../../../php/github_oauth.php';
require '../../../php/database.php';
require '../../../php/github_asset.php';
$mysqli = new mysqli($database_host, $database_username, $database_password, $database_name);
if ($mysqli->connect_errno)
error("Can't connect to MySQL database: $mysqli->connect_error");
$mysqli->set_charset('utf8');
$url = $mysqli->escape_string($data->url);
$id = isset($data->id) ? intval($data->id) : 0;

# check content
$check_url = proto_check_url($url);
if (!is_array($check_url))
error($check_url);
list($username, $repository, $tag_or_branch, $folder, $proto) = $check_url;
$proto_url = "https://raw.githubusercontent.com/$username/$repository/$tag_or_branch$folder$proto";
$proto_content = @file_get_contents($proto_url);
if ($proto_content === false) {
$query = "DELETE FROM proto WHERE id=$id";
$mysqli->query($query) or error($mysqli->error);
if ($mysqli->affected_rows === 0)
error("Failed to delete proto with proto file '$proto'");
error("Failed to fetch proto file $proto");
}

# check and retrieve information from webots.yaml file
$check_yaml = github_check_yaml($check_url, true);
if (!is_array($check_yaml)) {
$query = "DELETE FROM proto WHERE id=$id";
$mysqli->query($query) or error($mysqli->error);
error($check_yaml);
}

# retrieve the title and infos from the header.
$info = false;
$title = '';
$description = '';
$license = '';
$license_url = '';
$line = strtok($proto_content, "\r\n");
$version = $mysqli->escape_string(substr($line, 10, 6)); // "#VRML_SIM R2022b utf8" -> "R2022b"
$line = strtok("\r\n");
$externprotos = [];
while ($line !== false) {
$line == trim($line);
if ($line[0] === '#') {
$line = trim(str_replace('#', '', $line));
if (strtolower(substr($line, 0, 8)) !== 'template' && strtolower(substr($line, 0, 17)) !== 'documentation url' && substr($line, 0, 4) !== 'VRML') {
if(strtolower(substr($line, 0, 4)) !== 'tags') {
if (strpos($line, 'deprecated') || strpos($line, 'hidden'))
error("This proto is either deprecated or hidden and should not be added.");
elseif (strtolower(substr($line, 0, 11)) === 'license url')
$license_url = trim(preg_replace("/license url\s*:/", '', $line));
elseif (strtolower(substr($line, 0, 7)) === 'license')
$license = trim(preg_replace("/license\s*:/", '', $line));
else {
if ($description !== '')
$description .= "\n";
$description .= $mysqli->escape_string($line);
}
}
}
} elseif (substr($line, 0, 11) === 'EXTERNPROTO') {
$proto_url = trim(str_replace('"', '',str_replace('EXTERNPROTO', '', $line)));
$proto_name = str_replace('.proto', '', $proto_url);
if (strrpos($proto_name, '/'))
$proto_name = substr($proto_name, strrpos($proto_name, '/') + 1);
array_push($externprotos, [$proto_name, $proto_url]);
} elseif (substr($line, 0, 6) === 'PROTO ')
$title = trim(substr($line, 6));
if (!empty($title) && $title[-1] === '[')
$title = trim(substr($title, 0, -1));
$line = strtok("\r\n");
}

$original_externprotos = $externprotos;
$title = $mysqli->escape_string($title);
$license = $mysqli->escape_string($license);
$license_url = $mysqli->escape_string($license_url);

$base_type = '';
preg_match("/(?:\]\s*)\{\s*(?:\%\<[\s\S]*?(?:\>\%\s*))?(?:DEF\s+[^\s]+)?\s+([a-zA-Z0-9\_\-\+]+)\s*\{/", $proto_content, $match);
if ($match)
$base_type = $match[1];
$base_proto = $base_type;
$base_nodes = ['Gyro', 'DistanceSensor', 'Recognition', 'TouchSensor', 'ContactProperties', 'TextureCoordinate', 'Color',
'Camera', 'Accelerometer', 'Slot', 'Radar', 'Transform', 'Zoom', 'RangeFinder', 'PointSet', 'Capsule', 'Speaker', 'Lens',
'Viewpoint', 'IndexedFaceSet', 'Solid', 'Group', 'Muscle', 'Lidar', 'InertialUnit', 'DirectionalLight',
'HingeJointParameters', 'Compass', 'Normal', 'Propeller', 'Physics', 'RotationalMotor', 'Microphone', 'ImageTexture', 'Fog',
'Mesh', 'Track', 'Background', 'LED', 'Material', 'Box', 'PointLight', 'Cylinder', 'Damping', 'GPS', 'Radio', 'Pen', 'Cone',
'WorldInfo', 'SpotLight', 'TextureTransform', 'LinearMotor', 'Receiver', 'Coordinate', 'Hinge2JointParameters', 'CadShape',
'LensFlare', 'TrackWheel', 'PBRAppearance', 'Shape', 'Altimeter', 'PositionSensor', 'Connector', 'HingeJoint', 'Plane',
'Brake', 'Appearance', 'ElevationGrid', 'BallJointParameters', 'Fluid', 'Robot', 'SolidReference', 'Sphere', 'Skin',
'IndexedLineSet', 'ImmersionProperties', 'JointParameters', 'Focus', 'SliderJoint', 'Emitter', 'Hinge2Joint', 'BallJoint',
'LightSensor', 'Display', 'Billboard', 'Charger'];
BenjaminDeleze marked this conversation as resolved.
Show resolved Hide resolved

# search for the base type
$parent_url = $url;
while(!in_array($base_type, $base_nodes)) {
$results = get_parent($externprotos, $base_type, $parent_url);
$externprotos = $results[0];
$base_type = $results[1];
$parent_url = $results[3];
$found_parent = $results[4];
if(!$found_parent)
error("Base type: seems like the parent node is missing from the EXTERNPROTO.");
}

$device_regex = "/(\s+Brake\s*|\s+LinearMotor\s*|\s+PositionSensor\s*|\s+RotationalMotor\s*|\s+Skin\s*|\s+Accelerometer\s*|\s+Altimeter\s*|\s+Camera\s*|\s+Compass\s*|\s+Compass\s*|\s+Display\s*|\s+DistanceSensor\s*|\s+Emitter\s*|\s+GPS\s*|\s+Gyro\s*|\s+InertialUnit\s*|\s+LED\s*|\s+Lidar\s*|\s+LightSensor\s*|\s+Pen\s*|\s+Radar\s*|\s+RangeFinder\s*|\s+Receiver\s*|\s+Speaker\s*|\s+TouchSensor\s*|\s+Track\s*)/";
BenjaminDeleze marked this conversation as resolved.
Show resolved Hide resolved
$needs_robot_ancestor = 0;
if (in_array($base_type, ['Solid', 'Transform', 'Group']))
$needs_robot_ancestor = preg_match($device_regex, $proto_content);

$slot_type = '';
if ($base_type === "Slot") {
$found = false;
$current_proto_content = $proto_content;
$externprotos = $original_externprotos;
$parent_url = $url;
while(!$found) {
preg_match("/type\s+\"([a-zA-Z0-9\_\-\+\s]+)\"/", $current_proto_content, $match);
if ($match) {
$slot_type = $match[1];
$found = true;
} else {
$results = get_parent($externprotos, $base_proto, $parent_url);
$externprotos = $results[0];
$base_proto = $results[1];
$current_proto_content = $results[2];
$parent_url = $results[3];
$found_parent = $results[4];
if(!$found_parent)
error("Slot type: seems like the parent node is missing from the EXTERNPROTO.");
}
}
}


$auth = "Authorization: Basic " . base64_encode("$github_oauth_client_id:$github_oauth_client_secret");
$context = stream_context_create(['http' => ['method' => 'GET', 'header' => ['User-Agent: PHP', $auth]]]);
$info_json = @file_get_contents("https://api.github.com/repos/$username/$repository", false, $context);
$info = json_decode($info_json);
$stars = intval($info->{'stargazers_count'});
$competitors = 0;
$query = "SELECT viewed FROM proto WHERE url=\"$url\" AND id=$id";
$result = $mysqli->query($query) or error($mysqli->error);
$row = $result->fetch_array(MYSQLI_ASSOC);
$viewed = ($result && $row) ? $row['viewed'] : 0;
$branch = basename(dirname(__FILE__, 4));
if ($id === 0)
$query = "INSERT IGNORE INTO proto(url, viewed, stars, title, description, version, branch, license_url, license, "
."base_type, needs_robot_ancestor, slot_type) "
."VALUES(\"$url\", $viewed, $stars, \"$title\", \"$description\", \"$version\", \"$branch\", \"$license_url\", "
."\"$license\", \"$base_type\", \"$needs_robot_ancestor\", \"$slot_type\")";
else
$query = "UPDATE proto SET viewed=$viewed, stars=$stars, title=\"$title\", description=\"$description\", "
."version=\"$version\", updated=NOW(), license_url=\"$license_url\", license=\"$license\", "
."base_type=\"$base_type\", needs_robot_ancestor=\"$needs_robot_ancestor\", slot_type=\"$slot_type\" "
."WHERE url=\"$url\" AND id=$id";
$mysqli->query($query) or error($mysqli->error);
if ($mysqli->affected_rows != 1) {
if ($id === 0)
error("This proto already exists");
else
error("Failed to update the proto");
}

# return answer
$search = isset($data->search) ? $data->search : "";
$condition = "branch=\"$branch\"";
if ($search != "")
$condition .= " AND LOWER(title) LIKE LOWER('%$search%')";

$result = $mysqli->query("SELECT COUNT(*) AS count FROM proto WHERE $condition") or error($mysqli->error);
$count = $result->fetch_array(MYSQLI_ASSOC);
$total = intval($count['count']);

$answer = array();
$answer['id'] = ($id === 0) ? $mysqli->insert_id : $id;
$answer['url'] = $url;
$answer['viewed'] = $viewed;
$answer['stars'] = $stars;
$answer['title'] = $title;
$answer['description'] = $description;
$answer['version'] = $version;
$answer['updated'] = date("Y-m-d H:i:s");
$answer['total'] = $total;
die(json_encode($answer));

function get_parent($externprotos, $base_proto, $parent_url) {
$found_parent = false;
$current_proto_content = false;
for($i = 0; $i < count($externprotos); $i++) {
if ($externprotos[$i][0] === $base_proto) {
$found_parent = true;
$extern_url = $externprotos[$i][1];
if (str_starts_with($extern_url, "webots://"))
$extern_url = str_replace("webots://", "https://github.com/cyberbotics/webots/blob/released/", $extern_url);
else if (!str_starts_with($extern_url, "https"))
$extern_url = substr($parent_url, 0, strrpos($parent_url, '/') + 1).$extern_url;
$parent_url = $extern_url;
$check_url = proto_check_url($extern_url);
if (!is_array($check_url))
error($check_url);
list($extern_username, $extern_repository, $extern_tag_or_branch, $extern_folder, $extern_proto) = $check_url;
$extern_proto_url = "https://raw.githubusercontent.com/$extern_username/$extern_repository/$extern_tag_or_branch$extern_folder$extern_proto";
$extern_proto_content = @file_get_contents($extern_proto_url);
if ($extern_proto_content === false)
error("Could not retrieve parent proto with url'$extern_url'");
$current_proto_content = $extern_proto_content;

$line = strtok($extern_proto_content, "\r\n");
$line = strtok("\r\n");
$externprotos = [];
while ($line !== false) {
$line == trim($line);
if (substr($line, 0, 11) === 'EXTERNPROTO') {
$proto_url = trim(str_replace('"', '',str_replace('EXTERNPROTO', '', $line)));
$proto_name = str_replace('.proto', '', $proto_url);
if (strrpos($proto_name, '/'))
$proto_name = substr($proto_name, strrpos($proto_name, '/') + 1);
array_push($externprotos, [$proto_name, $proto_url]);
}
$line = strtok("\r\n");
}

preg_match("/(?:\]\s*)\{\s*(?:\%\<[\s\S]*?(?:\>\%\s*))?(?:DEF\s+[^\s]+)?\s+([a-zA-Z0-9\_\-\+]+)\s*\{/",
$extern_proto_content, $match);
if ($match)
$base_proto = $match[1];

break;
}
}
if (!$found_parent) {
$str = '';
for($i = 0; $i < count($externprotos); $i++) {
$str .= $externprotos[$i][0];
}
error(" $str base: $base_proto parent_url: $parent_url");
}
return array($externprotos, $base_proto, $current_proto_content, $parent_url, $found_parent);
}
?>
21 changes: 21 additions & 0 deletions httpdocs/ajax/proto/delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
function error($message) {
die("{\"error\":\"$message\"}");
}
header('Content-Type: application/json');
$json = file_get_contents('php://input');
$data = json_decode($json);
require '../../../php/database.php';
$mysqli = new mysqli($database_host, $database_username, $database_password, $database_name);
if ($mysqli->connect_errno)
error("Can't connect to MySQL database: $mysqli->connect_error");
$mysqli->set_charset('utf8');
$user = isset($data->user) ? intval($data->user) : 0;
$password = isset($data->password) ? $mysqli->escape_string($data->password) : '';
$id = isset($data->id) ? intval($data->id) : 0;
$query = "DELETE FROM proto WHERE id=$id AND EXISTS (SELECT * FROM user WHERE id=$user AND password='$password' AND email LIKE '%@cyberbotics.com')";
$mysqli->query($query) or error($mysqli->error);
if ($mysqli->affected_rows === 0)
error("Could not delete proto");
die('{"status":1}');
?>
19 changes: 19 additions & 0 deletions httpdocs/ajax/proto/documentation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php # This script list available protos
function error($message) {
die("{\"error\":\"$message\"}");
}
header('Content-Type: application/json');
$json = file_get_contents('php://input');
$data = json_decode($json);
require '../../../php/database.php';
$mysqli = new mysqli($database_host, $database_username, $database_password, $database_name);
if ($mysqli->connect_errno)
error("Can't connect to MySQL database: $mysqli->connect_error");
$mysqli->set_charset('utf8');
$branch = basename(dirname(__FILE__, 4));
$url = $mysqli->escape_string($data->url);
$condition = "branch=\"$branch\" AND url=\"$url\"";
$query = "SELECT base_type, description, version, license, license_url FROM proto WHERE $condition";
$result = $mysqli->query($query) or error($mysqli->error);
die(json_encode($result->fetch_array(MYSQLI_ASSOC)));
?>
Loading