Ayuda con el siguiente codigo.

kazaf Seguir

Gamma
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Desde
20 Abr 2009
Mensajes
187
Hola comunidad la verdad quisiera que me ayudaran en este problema el codigo que les muestro se ve algo largo y es por eso que a la hora de ejecutarlo se pone muy pesado.

Aqui el codigo:

PHP:
<?php

require_once './lib/Unirest.php';

$username = str_replace(" ", "", $_GET['name']);

$key = '';

$lan = 'https://localhost/player/lan/' . $username . '';

$puntos = 'https://localhost/player/lan/' . $username . '/influence_points';

$partidas = 'https://localhost/player/lan/' . $username . '/ingame';

$honor = 'https://localhost/player/lan/' . $username . '/honor';

$seasons = 'https://localhost/player/lan/' . $username . '/past_seasons';

$leagues = 'https://localhost/player/lan/' . $username . '/leagues';

$recent_game = 'https://localhost/player/lan/' . $username . '/recent_games';

$url = $lan;

$url2 = $puntos;

$url3 = $partidas;

$url4 = $honor;

$url5 = $seasons;

$url6 = $leagues;

$url7 =$recent_game;

$json = Unirest::get($url, array("X-Mashape-Authorization" => "$key"));

$json2 = Unirest::get($url2, array("X-Mashape-Authorization" => "$key"));

$json3 = Unirest::get($url3, array("X-Mashape-Authorization" => "$key"));

$json4 = Unirest::get($url4, array("X-Mashape-Authorization" => "$key"));

$json5 = Unirest::get($url5, array("X-Mashape-Authorization" => "$key"));

$json6 = Unirest::get($url6, array("X-Mashape-Authorization" => "$key"));

$json7 = Unirest::get($url7, array("X-Mashape-Authorization" => "$key"));

$json = $json->raw_body; 

$jd = json_decode($json);

$json2 = $json2->raw_body; 

$jd2 = json_decode($json2);

$json3 = $json3->raw_body; 

$jd3 = json_decode($json3);

$json4 = $json4->raw_body;

$jd4 = json_decode($json4);

$json5 = $json5->raw_body;

$jd5 = json_decode($json5);

$json6 = $json6->raw_body;

$jd6 = json_decode($json6);

$json7 = $json7->raw_body;

$jd7 = json_decode($json7);

?>

<div class="layout">
			<hr>
			<div class="row centered">
					<p class="centre" id="p_icon"><img src="http://qfcdn.5v5.me/profileicon/<?php echo $jd->data->icon; ?>.png"></p>
					<div class="p_large3 " id="basic_container">
						<p class="p_large3">
							<span id="p_summoner_name">
								<?php echo $jd->data->name; ?>
							</span>, Level
							<span id="p_summoner_level">
								<?php echo $jd->data->level; ?>
							</span><br /></br ></br >
							<span class="p_large2" id="p_region_proxy">
								Latin America North
							</span>
						</p>
				</div>
			</div>
<hr><div class="row centered">
				<div class="row-item col-1_4">
					<div class="b-service">
						<h3 class="honour-group">Amigable</h3>
						<p class="centered" id="h_friendly"> 
							<?php echo $jd4->data->totals[1]; ?>

							</p>
					</div>
				</div>
				<div class="row-item col-1_4">
					<div class="b-service">
						<h3 class="honour-group">Util</a></h3>
						<p class="centered">
							 <?php echo $jd4->data->totals[2]; ?>
					</p>
					</div>
				</div>
				<div class="row-item col-1_4">
					<div class="b-service">
						<h3 class="honour-group">Trabajo en Equipo</h3>
						<p class="centered">
							 <?php echo $jd4->data->totals[3]; ?>
					</p>
					</div>
				</div>
				<div class="row-item col-1_4">
					<div class="b-service">
						<h3 class="honour-group">Rival Honorable</h3>
						<p class="centered">
							<?php echo $jd4->data->totals[4]; ?>				
					</p>
					</div>
				</div>
			</div>
				<div style="clear:both;">&nbsp;</div>
							
						<div style="clear:both;">&nbsp;</div>
			</div>

<hr>
</div> 
<?php
if($jd3->success){
		?>
<div id="gamestate" style="display: block;">
<div class="one_half ">
<h1><i class="general foundicon-search"></i> Game overview</h1>
<h2 id="game_string"><span id="spec_verb"></span> <span id="spec_hero"></span> <span id="spec_game">Summoners Rift - <?php $title = $jd3->data->game->gameMode; echo str_replace("_", " ", $title) ?> - <?php $title = $jd3->data->game->queueTypeName; echo str_replace("_", " ", $title) ?></span></h2>
<p id="custom_meta_2">
Partido empezado <strong id="custTime"><?php $title = $jd3->requestTime; echo str_replace("-", " ", $title) ?></strong><br>
</p>
</div>
<div class="one_half last">
<h1>Mouseover names for more information.</h1>
<h2 id="game_string"><span id="spec_verb"></span> <span id="spec_hero"></span> <span id="spec_game"></span></h2>
<p id="custom_meta" style="display: block;">
Match name: <strong id="custTitle">N/A</strong><br>
Spectators: <strong id="custObs"></strong><br>
Hidden Elo average: <strong id="custObsAvg">1328.07</strong><br>
<span style="font-size:11px"></span>
</p>
</div>
</div> 
<hr>
<div class="one_half">

<h2 style="color:#fff;background:#007fff;padding:8px;font-size: 1.8em;">Azul</h2>
<p>
</p><table class="table-striped nb">
<thead>
<tr>
<th>
Equipo
</th>
<th>
Invocador
</th>
<th>
Spells
</th>
<th>
Division
</th>
</tr>
</thead>
<tbody id="tbBlue">
<tr class="cm_row">
<?php
$jugador = $jd3->data->game->teamOne->array[0];
$extras[0] = $jd3->data->game->playerChampionSelections->array[0]; 
$extras[1] = $jd3->data->game->playerChampionSelections->array[1];
$extras[2] = $jd3->data->game->playerChampionSelections->array[2];
$extras[3] = $jd3->data->game->playerChampionSelections->array[3];
$extras[4] = $jd3->data->game->playerChampionSelections->array[4];
$extras[5] = $jd3->data->game->playerChampionSelections->array[5];
$extras[6] = $jd3->data->game->playerChampionSelections->array[6];
$extras[7] = $jd3->data->game->playerChampionSelections->array[7];
$extras[8] = $jd3->data->game->playerChampionSelections->array[8];
$extras[9] = $jd3->data->game->playerChampionSelections->array[9];
foreach($extras as $extra){
													if($extra->summonerInternalName == $jugador->summonerInternalName){
if($jugador->teamParticipantId){
   echo '<td class="cm_premade_type"><span class="notification blue">Primate 1</span> </td>';
} else {
				echo '<td class="cm_premade_type"><span class="notification green">Solo Queue</span> </td>';	
	}
	echo '<td class="data-summoner="'.$jugador->summonerName.'" data-realm="lan">
		<img src="http://lkimg.zamimg.com/shared/riot/images/champions/'. $extra->championId . '_104.png" class="itemImage"> <span class="cm_ign"><a style="color:#111" href="/profile/lan/'. $jugador->summonerName .'/" target="_blank">'. $jugador->summonerName .'</a></span>
	</td>
	<td class="cm_summoners">
		<img src="http://lkimg.zamimg.com/images/spells/' .$extra->spell1Id. '.png" class="itemImage">
		<img src="http://lkimg.zamimg.com/images/spells/' .$extra->spell2Id. '.png" class="itemImage">
	</td>';
	}
}
?>
<?php
$key = '';
$invocador = str_replace(" ", "", $jugador->summonerName);
$season = 'https://localhost/player/lan/' . $invocador . '/past_seasons';
$ligas = 'https://localhost/player/lan/' . $invocador . '/leagues';
$json = Unirest::get($season, array("X-Mashape-Authorization" => "$key")); 
$json2 = Unirest::get($ligas, array("X-Mashape-Authorization" => "$key")); 
$json = $json->body; 
$json2 = $json2->body; 
$season = $json;
$ligas = $json2;
?>
<?php
$solo[0] = $ligas->data->summonerLeagues->array[0];
$solo[1] = $ligas->data->summonerLeagues->array[1];
$solo[2] = $ligas->data->summonerLeagues->array[2];
foreach($solo as $sl){
  if($sl->queue == RANKED_SOLO_5x5 && $sl->tier){
    echo '<td class="cmsummoners"><img src="http://lolnexus.com/LAN/images/medals/'. $sl->tier. '.gif" style="width: 28px; height: 28px; margin-right: 0px;" border="0">  '. $sl->tier. ' '. $sl->requestorsRank. ' </td>';
  }
 }
?>
</tr>
<tr class="cm_row">
<?php
$jugador = $jd3->data->game->teamOne->array[1];
$extras[0] = $jd3->data->game->playerChampionSelections->array[0]; 
$extras[1] = $jd3->data->game->playerChampionSelections->array[1];
$extras[2] = $jd3->data->game->playerChampionSelections->array[2];
$extras[3] = $jd3->data->game->playerChampionSelections->array[3];
$extras[4] = $jd3->data->game->playerChampionSelections->array[4];
$extras[5] = $jd3->data->game->playerChampionSelections->array[5];
$extras[6] = $jd3->data->game->playerChampionSelections->array[6];
$extras[7] = $jd3->data->game->playerChampionSelections->array[7];
$extras[8] = $jd3->data->game->playerChampionSelections->array[8];
$extras[9] = $jd3->data->game->playerChampionSelections->array[9];
foreach($extras as $extra){
													if($extra->summonerInternalName == $jugador->summonerInternalName){
if($jugador->teamParticipantId){
   echo '<td class="cm_premade_type"><span class="notification blue">Primate 1</span> </td>';
} else {
				echo '<td class="cm_premade_type"><span class="notification green">Solo Queue</span> </td>';	
	}
	echo '<td class="cm_hero_data hipster-9b66fb40b9ecdc6d3b156fb3a694df30" data-summoner="Dkovich" data-realm="lan" data-token="9b66fb40b9ecdc6d3b156fb3a694df30">
		<img src="http://lkimg.zamimg.com/shared/riot/images/champions/'. $extra->championId . '_104.png" class="itemImage"> <span class="cm_ign"><a style="color:#111" href="/profile/lan/'. $jugador->summonerName .'/" target="_blank">'. $jugador->summonerName .'</a></span>
	</td>
	<td class="cm_summoners">
		<img src="http://lkimg.zamimg.com/images/spells/' .$extra->spell1Id. '.png" class="itemImage">
		<img src="http://lkimg.zamimg.com/images/spells/' .$extra->spell2Id. '.png" class="itemImage">
	</td>';
	}
}
?>
<?php
$key = '';
$invocador = str_replace(" ", "", $jugador->summonerName);
$season = 'https://localhost/player/lan/' . $invocador . '/past_seasons';
$ligas = 'https://localhost/player/lan/' . $invocador . '/leagues';
$json = Unirest::get($season, array("X-Mashape-Authorization" => "$key")); 
$json2 = Unirest::get($ligas, array("X-Mashape-Authorization" => "$key")); 
$json = $json->body; 
$json2 = $json2->body; 
$season = $json;
$ligas = $json2;
?>
<?php
$solo[0] = $ligas->data->summonerLeagues->array[0];
$solo[1] = $ligas->data->summonerLeagues->array[1];
$solo[2] = $ligas->data->summonerLeagues->array[2];
foreach($solo as $sl){
  if($sl->queue == RANKED_SOLO_5x5 && $sl->tier){
    echo '<td class="cmsummoners"><img src="http://lolnexus.com/LAN/images/medals/'. $sl->tier. '.gif" style="width: 28px; height: 28px; margin-right: 0px;" border="0">  '. $sl->tier. ' '. $sl->requestorsRank. ' </td>';
  }
 }
?>
</tr>



</tbody>
</table>
<p></p>
</div>

<hr>



<?php 
} else {
	?><p> <div class="container page-services responsive-center" style="margin-top:60px">      
			<div class="row">
	<div class="span6 offset3" style="text-align:center">
		<br><br><h1>Error: No se encuentra en ninguna partida!</h1><br> <h3><?php echo $jd3->error_message; ?></h3><br><br><br><br><br>
	</div>
		</div></p>
	<?php 

	}
?>

Quisiera saber si hay una manera de poder simplificar esto para no ocupar muchas lineas como ejemplo esta parte.

PHP:
<?php
$key = '';
$invocador = str_replace(" ", "", $jugador->summonerName);
$season = 'https://localhost/player/lan/' . $invocador . '/past_seasons';
$ligas = 'https://localhost/player/lan/' . $invocador . '/leagues';
$json = Unirest::get($season, array("X-Mashape-Authorization" => "$key")); 
$json2 = Unirest::get($ligas, array("X-Mashape-Authorization" => "$key")); 
$json = $json->body; 
$json2 = $json2->body; 
$season = $json;
$ligas = $json2;
?>


Segun como tengo entendido es por eso que se me pone muy lento al cargarlo, que puedo hacer ante esto?

Gracias de ante mano. Bendiciones.
 
S

Strings

Yo esque no hago tantas variables, yo pongo vaya a poner la variable pongo el valor ejemplo: donde vaya a poner $ligas pongo 'https://localhost/player/lan/' . $invocador . '/leagues' y me ahorro una variable
 

kazaf

Gamma
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Desde
20 Abr 2009
Mensajes
187
Eh tratado de hacer eso pero al llamar al siguiente se qda sin datos

---------- Post agregado el 06-sep-2013 hora: 04:51 ----------

Lo que realmente quiero dejar de repetir muchas veces esto

PHP:
<?php 
$key = ''; 
$invocador = str_replace(" ", "", $jugador->summonerName); 
$season = 'https://localhost/player/lan/' . $invocador . '/past_seasons'; 
$ligas = 'https://localhost/player/lan/' . $invocador . '/leagues'; 
$json = Unirest::get($season, array("X-Mashape-Authorization" => "$key"));  
$json2 = Unirest::get($ligas, array("X-Mashape-Authorization" => "$key"));  
$json = $json->body;  
$json2 = $json2->body;  
$season = $json; 
$ligas = $json2; 
?>
 

victorvu

Beta
Programador
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Desde
24 Feb 2013
Mensajes
118
podes hacerlo sobre la misma variable

Insertar CODE, HTML o PHP:
<?php 
$key = ''; 
$invocador = str_replace(" ", "", $jugador->summonerName); 

$season = Unirest::get('https://localhost/player/lan/' . $invocador . '/past_seasons', array("X-Mashape-Authorization" => "$key"));  
$ligas = Unirest::get('https://localhost/player/lan/' . $invocador . '/leagues', array("X-Mashape-Authorization" => "$key"));  

$season = $season->body;  
$ligas = $ligas->body;  
?>
 

Javieer

Gamma
Programador
Desde
2 Ago 2013
Mensajes
161
Por favor, ten en cuenta 📝 que si deseas hacer un trato 🤝 con este usuario, está baneado 🔒.
PHP:
$username = "https://localhost/player/lan/".str_replace(" ", "", $_GET['name']); 
$key = ''; 
$jd1 = json_decode(Unirest::get($username, array("X-Mashape-Authorization" => "$key"))->raw_body); 
$jd2 = json_decode(Unirest::get($username."/influence_points", array("X-Mashape-Authorization" => "$key"))->raw_body);
$jd3 = json_decode(Unirest::get($username."/ingame", array("X-Mashape-Authorization" => "$key"))->raw_body);
$jd4 = json_decode(Unirest::get($username."/honor", array("X-Mashape-Authorization" => "$key"))->raw_body);
$jd5 = json_decode(Unirest::get($username."/past_seasons", array("X-Mashape-Authorization" => "$key"))->raw_body);
$jd6 = json_decode(Unirest::get($username."/leagues", array("X-Mashape-Authorization" => "$key"))->raw_body);
$jd7 = json_decode(Unirest::get($username."/recent_games", array("X-Mashape-Authorization" => "$key"))->raw_body);
 
Arriba