We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

user-journal.php 3.02 KB
Newer Older
tobyink's avatar
tobyink committed
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
<?php

/* Libre.fm -- a free network service for sharing your music listening habits

   Copyright (C) 2009 Libre.fm Project

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

require_once('database.php');
require_once('templating.php');
require_once('data/User.php');
require_once('data/TagCloud.php');
require_once('data/Server.php');
require_once('utils/arc/ARC2.php');
tobyink's avatar
Sorted  
tobyink committed
28
require_once('utils/human-time.php');
tobyink's avatar
tobyink committed
29 30 31 32 33 34 35 36 37 38

if(!isset($_GET['user']) && $logged_in == false) {
        $smarty->assign('error', 'Error!');
        $smarty->assign('details', 'User not set! You shouldn\'t be here!');
        $smarty->display('error.tpl');
        die();
}

$user = new User($_GET['user']);

tobyink's avatar
tobyink committed
39 40 41 42 43 44
if(! $user->journal_rss ) {
        $smarty->assign('error', 'Error!');
        $smarty->assign('details', 'You need an RSS feed set up for your account.');
        $smarty->display('error.tpl');
        die();
}
tobyink's avatar
tobyink committed
45

tobyink's avatar
tobyink committed
46 47 48
# We have to implement HTTP caching here!
$parser = ARC2::getRDFParser();
$parser->parse($user->journal_rss);
tobyink's avatar
tobyink committed
49

tobyink's avatar
tobyink committed
50 51 52 53 54 55
$index = $parser->getSimpleIndex();
krsort($index); // Newest last.
$items = array();
foreach ($index as $subject => $data)
{
	if (in_array('http://purl.org/rss/1.0/item', $data['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']))
tobyink's avatar
tobyink committed
56
	{
tobyink's avatar
tobyink committed
57 58 59 60 61 62 63 64 65
		$ts = strtotime($data[ 'http://purl.org/dc/elements/1.1/date' ][0]);
		$items[] = array(
			'subject_uri' => $subject,
			'title' => $data[ 'http://purl.org/rss/1.0/title' ][0],
			'link' => $data[ 'http://purl.org/rss/1.0/link' ][0],
			'date_iso' => $data[ 'http://purl.org/dc/elements/1.1/date' ][0],
			'date_unix' => $ts,
			'date_human' => human_timestamp($ts)
			);
tobyink's avatar
tobyink committed
66
	}
tobyink's avatar
tobyink committed
67
}
tobyink's avatar
tobyink committed
68

69
$aUserTagCloud =  TagCloud::GenerateTagCloud(TagCloud::scrobblesTable('user'), 'artist', 40, $user->name);
tobyink's avatar
tobyink committed
70 71
if (!PEAR::isError ($aUserTagCloud)) {
	$smarty->assign('user_tagcloud',$aUserTagCloud);
tobyink's avatar
tobyink committed
72
}
73
$smarty->assign('isme', ($this_user->name == $user->name));
74 75
$smarty->assign('me', $user);
$smarty->assign('geo', Server::getLocationDetails($user->location_uri));
tobyink's avatar
tobyink committed
76 77 78
$smarty->assign('profile', true);
$smarty->assign('items', $items);
$smarty->assign('extra_head_links', array(
tobyink's avatar
tobyink committed
79 80 81 82 83 84 85 86 87 88
		array(
			'rel'=>'alternate',
			'type' => 'application/rss+xml' ,
			'title' => 'RSS 1.0 Feed (Journal)',
			'href' => $user->journal_rss
			),
		array(
			'rel' => 'meta',
			'type' => 'application/rdf+xml' ,
			'title' => 'FOAF',
89
			'href' => $base_url.'/rdf.php?fmt=xml&page='.urlencode(str_replace($base_url, '', $user->getURL()))
tobyink's avatar
tobyink committed
90
			)
tobyink's avatar
tobyink committed
91 92
	));
$smarty->display('user-journal.tpl');
clint's avatar
clint committed
93