Question regarding returned links.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fyveonit
Forum Newbie
Posts: 1
Joined: Mon Jul 25, 2011 10:19 am

Question regarding returned links.

Post by fyveonit »

Hey guys forgive me, I have been working with PHP for a grand total of 6 days now. I am very basic you might have to talk to me like a 5 year old, I have no formal training.

I have been trying to advance myself, I am a 3d graphics major but I would love to be able to do websites etc as well. So Last year I took on the task to learn HTML etc. I am having a blast, and have been working on 2 hobbies at once. I created a website for my team on the video game World of Warcraft. It has been pretty basic up until the developer announced that it's releasing its "Community API" using JSON and PHP etc.

So I have spent last week trying to get familiar with the AP :banghead: I. I found some very basic guides etc, and thankfully got a nice feed working that shows my teams activity in the game.

http://www.judgement-firetree.com/test/index_test.php


I am stuck now with one problem, and its very minor....here is the code.

Code: Select all

		<?php
		
// your Guild Activity feed goes here
$json = file_get_contents('http://wowfeeds.wipeitau.com/GuildActivity.php?location=US&rn=Firetree&gn=Judgement&callback=?');

// strip the return json of unneeded characters
$json = str_replace(')', '', $json);
$json = str_replace('(', '', $json);
$json = str_replace('Achievement', 'achievement', $json);
$json = str_replace('Item', 'item', $json);					  

$json = substr($json, 1);

// decode the json into objects

$data = json_decode($json);


echo '<p>';

// guildactivity is a collection of objects
// properties list
// name -> 			name of the character who is tied with the activity
// type -> 			what kind activity is this
// numId -> 		numId attached to the activity (you need this if you want to link to the WoW API)
// achText -> 		the text which typically follows the character to describe the activity
// achObjective -> 	the objective reached
// achImage -> 		the full URL fo the achievement image
// achTime -> 		when the achievement occured

// this loop outputs each achievement as a line
foreach ($data->guildActivity as $activity)  
{
	echo 	'<img src="' . $activity->achImage . '">' . 
			'<a target="_new" href="http://us.battle.net/wow/en/character/' . $data->realmName . '/' . $activity->name . '/simple">' . $activity->name . '</a> ' .
			$activity->achText . ' ' . 
			'<a href="http://www.wowhead.com/' . $activity->type .  '=' . $activity->numId . '">' . $activity->achObjective . '</a>' .
			' (' . $activity->achTime . ') ' .
			'<br />'
			;
}
echo '</p>';


?>
Ok so that returns 3 types of links. The Characters name is one, the other two are either an "item" or an "achievement"

Code: Select all

'<a href="http://www.wowhead.com/' . $activity->type .  '=' . $activity->numId . '">' . $activity->achObjective . '</a>' .
This line I think sorts out if the link either directs to:
<a href="http://www.wowhead.com/achievement=
<a href="http://www.wowhead.com/item=


Now here is my question...

Is there any possible...SIMPLE...way to have the links that come from:

<a href="http://www.wowhead.com/achievement= to be styled as a yellow color

AND

<a href="http://www.wowhead.com/item= to be styled as a purple color


when printed as links?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Question regarding returned links.

Post by Benjamin »

:arrow: Moved to PHP - Code
kalarm
Forum Newbie
Posts: 2
Joined: Mon Jul 25, 2011 11:23 pm

Re: Question regarding returned links.

Post by kalarm »

Code: Select all

<?php
                
// your Guild Activity feed goes here
$json = file_get_contents('http://wowfeeds.wipeitau.com/GuildActivity.php?location=US&rn=Firetree&gn=Judgement&callback=?');

// strip the return json of unneeded characters
$json = str_replace(')', '', $json);
$json = str_replace('(', '', $json);
$json = str_replace('Achievement', 'achievement', $json);
$json = str_replace('Item', 'item', $json);                                       

$json = substr($json, 1);

// decode the json into objects

$data = json_decode($json);
$whichstyle="";

echo '<p>';

// guildactivity is a collection of objects
// properties list
// name ->                      name of the character who is tied with the activity
// type ->                      what kind activity is this
// numId ->             numId attached to the activity (you need this if you want to link to the WoW API)
// achText ->           the text which typically follows the character to describe the activity
// achObjective ->      the objective reached
// achImage ->          the full URL fo the achievement image
// achTime ->           when the achievement occured

// this loop outputs each achievement as a line
foreach ($data->guildActivity as $activity)  
{
$whichactivity=$activity->type;

if($whichactivity=="item"){
	$whichstyle='style="color:red;"';

}

        echo    '<img src="' . $activity->achImage . '">' . 
                        '<a target="_new" href="http://us.battle.net/wow/en/character/' . $data->realmName . '/' . $activity->name . '/simple">' . $activity->name . '</a> ' .
                        '<span '.$whichstyle.'>'.$activity->achText . '</span> ' . 
                        '<a href="http://www.wowhead.com/' . $activity->type .  '=' . $activity->numId . '">' . $activity->achObjective . '</a>'.$activity->achText.'' .
                        ' (' . $activity->achTime . ') ' .
                        '<br />'
                        ;
}
echo '</p>';


?>
would look something like this. Of course there is still several things you can do to make it cleaner and stuff. (dont forget to test for "achievement" or others too. You might want to use a switch).
Last edited by Benjamin on Mon Jul 25, 2011 11:36 pm, edited 1 time in total.
Reason: Added [syntax=php|sql|css|javascript] and/or [text] tags.
kalarm
Forum Newbie
Posts: 2
Joined: Mon Jul 25, 2011 11:23 pm

Re: Question regarding returned links.

Post by kalarm »

Now that I think about it, there was a much simplier way to do this.

Could of just done 2 CSS class. One named "achievement" and one "item". You would just need to add class='.$activity->type.' in the span.

The text would of taken the right class everytime without needing to actually test for which activity it is.

Damn, how did I miss that D:.
Post Reply