forked from wikipathways/mediawiki-extensions-WikiPathways
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PathwayWidget.php
139 lines (126 loc) · 3.98 KB
/
PathwayWidget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
Entry point for a pathway viewer widget that can be included in other pages.
This page will display the interactive pathway viewer for a given pathway. It takes the following parameters:
- identifier: the pathway identifier (e.g. WP4)
- version: the version (revision) number of a specific version of the pathway (optional, leave out to display the newest version)
You can include a pathway viewer in another website using an iframe:
<iframe src ="http://www.wikipathways.org/wpi/PathwayWidget.php?id=WP4" width="500" height="500" style="overflow:hidden;"></iframe>
*/
require_once 'extensions/PathwayViewer/PathwayViewer.php';
header( "X-XSS-Protection: 0" );
?>
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
a#wplink {
text-decoration:none;
font-family:serif;
color:black;
font-size:12px;
}
#logolink {
float:right;
top:-20px;
left: -10px;
position:relative;
z-index:2;
opacity: 0.5;
}
html, body {
width:100%;
height:100%;
}
#pvjs-widget {
top:0;
left:0;
font-size:12px;
width:100%;
height:inherit;
}
</style>
<?php
// Initialize javascript
echo '<script type="text/javascript" src="' . $jsJQuery . '"></script>' . "\n";
$imgPath = "$wgServer/$wgScriptPath/extensions/WikiPathways/images/";
$jsSrc = PathwayViewer::getJsDependencies();
foreach ( $jsSrc as $js ) {
echo '<script type="text/javascript" src="' . $js . '"></script>' . "\n";
}
$identifier = $_REQUEST['id'];
$version = isset( $_REQUEST['rev'] ) ? $_REQUEST['rev'] : 0;
$label = isset( $_REQUEST['label'] ) ? $_REQUEST['label'] : null;
$xref = isset( $_REQUEST['xref'] ) ? $_REQUEST['xref'] : null;
$colors = isset( $_REQUEST['colors'] ) ? $_REQUEST['colors'] : null;
$highlights = " ";
if ( ( !is_null( $label ) || !is_null( $xref ) ) && !is_null( $colors ) ) {
$highlights = "[";
$selectors = [];
if ( !is_null( $label ) ) {
if ( is_array( $label ) ) {
foreach ( $label as $l ) {
array_push( $selectors, "{\"selector\":\"$l\"," );
}
} else {
array_push( $selectors, "{\"selector\":\"$label\"," );
}
}
if ( !is_null( $xref ) ) {
if ( is_array( $xref ) ) {
foreach ( $xref as $x ) {
$xParts = explode( ",", $x );
array_push( $selectors, "{\"selector\":\"xref:id:".$xParts[0].",".$xParts[1]."\"," );
}
} else {
$xrefParts = explode( ",", $xref );
array_push( $selectors, "{\"selector\":\"xref:id:".$xrefParts[0].",".$xrefParts[1]."\"," );
}
}
$colorArray = explode( ",", $colors );
$firstColor = $colorArray[0];
if ( count( $selectors ) != count( $colorArray ) ) { // if color list doesn't match selector list, then just use first color
for ( $i = 0; $i < count( $selectors ); $i++ ) {
$colorArray[$i] = $firstColor;
}
}
// if highlight params received
for ( $i = 0; $i < count( $selectors ); $i++ ) {
$highlights .= $selectors[$i]."\"backgroundColor\":\"".$colorArray[$i]."\",\"borderColor\":\"".$colorArray[$i]."\"},";
}
$highlights .= "]";
}
if ( !isset( $highlights ) || empty( $highlights ) || $highlights == " " ) {
$highlights = "[]";
}
$pathway = Pathway::newFromTitle( Title::newFromText( $identifier ) );
if ( $version ) {
$pathway->setActiveRevision( $version );
}
$svg = $pathway->getFileURL( FILETYPE_IMG );
$png = $pathway->getFileURL( FILETYPE_PNG );
echo "<script>kaavioHighlights = " . $highlights . "</script>";
$gpml = $pathway->getFileURL( FILETYPE_GPML );
?>
<title>WikiPathways Pathway Viewer</title>
</head>
<body>
<wikipathways-pvjs
id="pvjs-widget"
src="<?php echo $gpml ?>"
display-errors="true"
display-warnings="true"
fit-to-container="true"
editor="disabled">'
<img src="<?php echo $png ?>" alt="Diagram for pathway <?php echo $identifier ?>" width="600" height="420" class="thumbimage">
</wikipathways-pvjs>
<div style="position:absolute;height:0px;overflow:visible;bottom:0;left:15px;">
<div id="logolink">
<?php
echo "<a id='wplink' target='top' href='{$pathway->getFullUrl()}'>View at ";
echo "<img style='border:none' src='$wgScriptPath/extensions/WikiPathways/images/wikipathways_name.png' /></a>";
?>
</div>
</div>
</body>
</html>