// PlayStation 3 Trophy API Example // vi: ts=4 require_once('trophy.class.php'); $portable = false; if (preg_match('/portable/i', $_SERVER['HTTP_USER_AGENT'])) $portable = true; $tfs = new TrophyFilesystem(); if (array_key_exists('id', $_REQUEST) && array_key_exists('title-thumb', $_REQUEST)) { try { $image = $tfs->GetTitleIcon($_REQUEST['id'], true); header('Content-type: image/png'); header('Content-length: ' . strlen($image)); echo $image; } catch (Exception $e) { // TODO: log/handle error? } exit; } if (array_key_exists('id', $_REQUEST) && array_key_exists('title-icon', $_REQUEST)) { try { $image = $tfs->GetTitleIcon($_REQUEST['id']); header('Content-type: image/png'); header('Content-length: ' . strlen($image)); echo $image; } catch (Exception $e) { // TODO: log/handle error? } exit; } if (array_key_exists('id', $_REQUEST) && array_key_exists('trophy-icon', $_REQUEST)) { $hidden = false; if (array_key_exists('hidden', $_REQUEST)) { $hidden = $_REQUEST['hidden'] ? true : false; } try { $image = $tfs->GetTrophyIcon($_REQUEST['id'], $_REQUEST['trophy-icon'], true, $hidden); header('Content-type: image/png'); header('Content-length: ' . strlen($image)); echo $image; } catch (Exception $e) { // TODO: log/handle error? } exit; } $lang = null; if (array_key_exists('lang', $_REQUEST)) { $lang = sprintf('%d', $_REQUEST['lang']); if ($lang == 0) $lang = null; } $sort_title_by = TrophyFilesystem::SORT_BY_TITLE; if (array_key_exists('sort-title', $_REQUEST)) { $sort_title_by = $_REQUEST['sort-title']; } $show_hidden = false; if (array_key_exists('show-hidden', $_REQUEST)) { $show_hidden = $_REQUEST['show-hidden'] ? true : false; } if (array_key_exists('id', $_REQUEST)) { $td = null; try { $td = $tfs->GetTrophyData($_REQUEST['id'], $show_hidden, $lang); } catch (Exception $e) { // TODO: log/handle error? } } ?>
if ($td != null) $title = $td['title']; else $title = 'Trophy Index'; echo "%s | |||||||
%s | |||||||
| ' .
' | ',
$class, $_SERVER['PHP_SELF'], $td['npcommid'], $id,
(!$show_hidden && $trophy['hidden']) ? 1 : 0);
printf('%s %s',
$trophy['name'],
sprintf(' | ||||||
| ' .
' | %s %s',
$trophy['name'],
sprintf(' | ||||||
| Title | ' . 'Total | ', $_SERVER['PHP_SELF'], TrophyFilesystem::SORT_BY_TITLE, $_SERVER['PHP_SELF'], TrophyFilesystem::SORT_BY_TROPHY_PLATINUM, 'trop-plat.png', $_SERVER['PHP_SELF'], TrophyFilesystem::SORT_BY_TROPHY_GOLD, 'trop-gold.png', $_SERVER['PHP_SELF'], TrophyFilesystem::SORT_BY_TROPHY_SILVER, 'trop-silver.png', $_SERVER['PHP_SELF'], TrophyFilesystem::SORT_BY_TROPHY_BRONZE, 'trop-bronze.png', $_SERVER['PHP_SELF'], TrophyFilesystem::SORT_BY_TROPHY_HIDDEN, 'trop-hidden.png', $_SERVER['PHP_SELF'], TrophyFilesystem::SORT_BY_TROPHY_TOTAL); $titles = $tfs->GetTrophyList($lang, $sort_title_by); foreach ($titles as $id => $title) { if ($index % 2) $class = 'rowalt'; else $class = 'row'; printf('||||||
| ' .
' | ',
$class, $_SERVER['PHP_SELF'], $id, $_SERVER['PHP_SELF'], $id);
printf('%s | ', $_SERVER['PHP_SELF'], $id, $title['title']); printf('%d | ', $title['platinum']); printf('%d | ', $title['gold']); printf('%d | ', $title['silver']); printf('%d | ', $title['bronze']); printf('%d | ', $title['hidden']); printf('%d | ', $title['total']); echo "