Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: TheBliveon - lokakuu 26, 2013, 02:34:25 IP

Otsikko: Problem with twitch status in buttons
Kirjoitti: TheBliveon - lokakuu 26, 2013, 02:34:25 IP
Hello everybody,

I want to include a live/offline script into my buttons. The code is below.
I get the following errors:

LainaaTemplate Parse Error!

There was a problem loading the \Themes\noize_20rc5/index.template.php template or language file. Please check the syntax and try again - remember, single quotes (') often have to be escaped with a slash (\). To see more specific error information from PHP, try accessing the file directly.

You may want to try to refresh this page or use the default theme.

and

LainaaParse error: syntax error, unexpected 'name' (T_STRING), expecting ',' or ';' in E:\xampp\htdocs\website\Themes\noize_20rc5\index.template.php on line 461
Line 461 is showed with <---- LINE 461 (This is not in the original code.

echo '
<li><a href="">Streams<span>Featured Streams</span></a>
<ul class="pngbg">
<li><a href="#">Featured Streams</a></li>
<li><a href="#">Information</a></li>
<li><a class="subchild pngbg" href="#">RiotGames</a>
<ul class="pngbg">
<li><a href="', $scripturl, '?action=riotgames">
<?php
$channel "bliveon"// lowercase or the ****** gonna be serius
$json_file = @file_get_contents("http://api.justin.tv/api/stream/list.json?channel={$channel}"0nullnull);
$json_array json_decode($json_filetrue);
                if (isset($json_array[0]) && $json_array[0]['name'] == "live_user_{$channel}") <---------------- LINE 461
{
$channelTitle $json_array[0]['channel']['title'];
$title $json_array[0]['channel']['status'];
$game $json_array[0]['meta_game'];
?>

<!-- live channel code here -->
<img src="images/online.png">
<!-- end live channel code -->
<?php
}
else
{
?>

<!-- offline channel code here -->
<img src="images/offline.png">
<!-- end offline channel code -->
<?php
}
?>

RiotGames English</a></li>
<li><a href="#"><img src="images/buttons/twitch.png"> GarenaTW</a></li>
<li><a href="#"><img src="noize_20rc5/images/buttons/twitch.png"> OGN_LoL</a></li>
</ul>
</li>
</ul>
</li>';


Could anybody please help me out with this?
I already tried to add , and ; but nothing worked.

The code seperate works on it's own. but in the button it doesnt work.
Sorry for bad english

King regards
Otsikko: Re: Problem with twitch status in buttons
Kirjoitti: Shambles - lokakuu 26, 2013, 03:00:38 IP
All the code you posted is output data being served via an 'echo' statement, whose entire string is delimited by single quote marks.

Because of that, you have to be aware of other single quotes appearing within that string; these you will have to 'escape' as follows:

Koodi (Your Code) [Valitse]
if (isset($json_array[0]) && $json_array[0]['name'] == "live_user_{$channel}") <---------------- LINE 461
{
$channelTitle = $json_array[0]['channel']['title'];
$title = $json_array[0]['channel']['status'];
$game = $json_array[0]['meta_game'];
?>


Koodi (Replace with) [Valitse]
if (isset($json_array[0]) && $json_array[0][\'name\'] == "live_user_{$channel}") <---------------- LINE 461
{
$channelTitle = $json_array[0][\'channel\'][\'title\'];
$title = $json_array[0][\'channel\'][\'status\'];
$game = $json_array[0][\'meta_game\'];
?>
Otsikko: Re: Problem with twitch status in buttons
Kirjoitti: TheBliveon - lokakuu 26, 2013, 05:23:17 IP
Lainaus käyttäjältä: Shambles - lokakuu 26, 2013, 03:00:38 IP
All the code you posted is output data being served via an 'echo' statement, whose entire string is delimited by single quote marks.

Because of that, you have to be aware of other single quotes appearing within that string; these you will have to 'escape' as follows:

Koodi (Your Code) [Valitse]
if (isset($json_array[0]) && $json_array[0]['name'] == "live_user_{$channel}") <---------------- LINE 461
{
$channelTitle = $json_array[0]['channel']['title'];
$title = $json_array[0]['channel']['status'];
$game = $json_array[0]['meta_game'];
?>


Koodi (Replace with) [Valitse]
if (isset($json_array[0]) && $json_array[0][\'name\'] == "live_user_{$channel}") <---------------- LINE 461
{
$channelTitle = $json_array[0][\'channel\'][\'title\'];
$title = $json_array[0][\'channel\'][\'status\'];
$game = $json_array[0][\'meta_game\'];
?>


Now the problem is the green and red button show at the same time, and i don't want that, i want it to be green when the stream is live, and red when the stream is offline.

(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FPEkMUrb.png&hash=e859fe82f1a2b8981d24df36f7cc1c32acd58d7b)
Otsikko: Re: Problem with twitch status in buttons
Kirjoitti: TheBliveon - lokakuu 27, 2013, 06:52:09 IP
Sorry to bump this, but can somebody help me with fixing this?

Basically the green button has to show when the user is live, and the red button has to show when the user is offline. (Twitch Stream Status)

As faced above the 2 images show at the same time now.