-
Notifications
You must be signed in to change notification settings - Fork 0
/
verpelicula.php
233 lines (205 loc) · 7.72 KB
/
verpelicula.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container-fluid">
<a class="navbar-brand" href="index.php">Star Wars</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="index.php">Inicio
<span class="sr-only">(current)</span>
</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<?php
if(isset($_GET['id'])){
$indice=$_GET['id'];
$err_status = "";
/* Define the URL endpoint where you will get JSON data from */
$apifullurl = "https://swapi.co/api/films/$indice/?format=json";
/* Since we are using GET, attach the name-values to the endpoint URL */
/* Create the CURL Handler */
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $apifullurl);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_MAXREDIRS, 2);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); /* Follow redirects, the number of which is defined in CURLOPT_MAXREDIRS */
curl_setopt($curl, CURLOPT_FORBID_REUSE, TRUE);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($curl);
$err_status = curl_error($curl);
curl_close($curl);
/* Handle Response */
if (strlen($err_status) == 0) {
if (strlen($response) > 0) {
/* Read the JSON, if any */
$apiresponse = json_decode($response, TRUE);
if (count($apiresponse) > 0) {
/* There may be other data aside from the main JSON message, in the JSON response so the example below just shows getting a simple name-value pair */
echo '<div class="col-12"><h4>Información de episodio</h4></div>';
// print_r($apiresponse['results'][$i]);
$idepisodio=$apiresponse['episode_id'];
$titulo="Star Wars ".$idepisodio.": ".$apiresponse['title'];
$fechadelanzamiento=$apiresponse['release_date'];
$director=$apiresponse['director'];
$opening=$apiresponse['opening_crawl'];
$productor=$apiresponse['producer'];
$urlimagen="img/".$idepisodio.".jpg";
?>
<div class="col-12">
<div class="row">
<div class="col-12 col-sm-6 col-md-7">
<h3><?php echo $titulo; ?></h3>
<div class="table-responsive">
<table class="table">
<tbody>
<tr>
<td>Fecha de lanzamiento</td>
<td><?php echo $fechadelanzamiento; ?></td>
</tr>
<tr>
<td>Director</td>
<td><?php echo $director; ?></td>
</tr>
<tr>
<td>Productor</td>
<td><?php echo $productor; ?></td>
</tr>
</tbody>
</table>
</div>
<p><?php echo $opening; ?></p>
</div>
<div class="col-12 col-sm-6 col-md-5 text-center">
<img src="<?php echo $urlimagen; ?>" class="img-fluid img-thumbnail" style="max-height:500px;">
</div>
</div>
</div>
<?php
//ver personajes
echo '<h4>Información de personajes</h4>';
?>
<div class="col-12"><div class="row">
<?php
for($i=0;$i<count($apiresponse['characters']);$i++){
$urlpersonaje=$apiresponse['characters'][$i];
$err_status2 = "";
/* Define the URL endpoint where you will get JSON data from */
$apifullurl2 = $urlpersonaje;
/* Since we are using GET, attach the name-values to the endpoint URL */
/* Create the CURL Handler */
$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_URL, $apifullurl2);
curl_setopt($curl2, CURLOPT_TIMEOUT, 30);
curl_setopt($curl2, CURLOPT_MAXREDIRS, 2);
curl_setopt($curl2, CURLOPT_FOLLOWLOCATION, TRUE); /* Follow redirects, the number of which is defined in CURLOPT_MAXREDIRS */
curl_setopt($curl2, CURLOPT_FORBID_REUSE, TRUE);
curl_setopt($curl2, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, TRUE);
$response2 = curl_exec($curl2);
$err_status2 = curl_error($curl2);
curl_close($curl2);
/* Handle Response */
if (strlen($err_status2) == 0) {
if (strlen($response2) > 0) {
/* Read the JSON, if any */
$apiresponse2 = json_decode($response2, TRUE);
if (count($apiresponse2) > 0) {
/* There may be other data aside from the main JSON message, in the JSON response so the example below just shows getting a simple name-value pair */
$nombrepersonaje=$apiresponse2['name'];
$fechapersonaje=$apiresponse2['birth_year'];
$generopersonaje=$apiresponse2['gender'];
$masapersonaje=$apiresponse2['mass']." kg";
$alturapersonaje="".intval($apiresponse2['height'])." cms";
$enlacepersonaje="verpersonaje.php?id=".$nombrepersonaje;
?>
<div class="col-12 col-md-6" style="padding-top:8px;">
<div class="card">
<div class="card-header bg-dark text-light"><h4 class="text-center"><?php echo $nombrepersonaje; ?></h4></div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<td>Fecha de nacimiento</td>
<td><?php echo $fechapersonaje; ?></td>
</tr>
</thead>
<tbody>
<tr>
<td>Genero</td>
<td><?php echo $generopersonaje; ?></td>
</tr>
<tr>
<td>Masa</td>
<td><?php echo $masapersonaje; ?></td>
</tr>
<tr>
<td>Altura</td>
<td><?php echo $alturapersonaje; ?></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="card-footer"><a href="<?php echo $enlacepersonaje; ?>" class="btn btn-block btn-info">Ver personaje</a></div>
</div>
</div>
<?php
}
else {
print "No es JSON.";
}
}
else {
print "Hay un error y no se obtuvo respuesta.";
}
}
else {
print $err_status2;
}
}
?>
</div></div>
<?php
}
else {
print "No es JSON.";
}
}
else {
print "Hay un error y no se obtuvo respuesta.";
}
}
else {
print $err_status;
}
}else{
?>
<p>No se pudo encontrar pelicula.</p>
<a href="index.php" class="btn btn-block btn-info">Ir a pelicula</a>
<?php
}
?>
</div>
</div>
</body>
</html>