summaryrefslogtreecommitdiffstats
path: root/modules/twitter/twitter_update.php
blob: 9fe779d65c0e4181e87af35a714a028dcce09733 (plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
 *
 * Adapted for Ampache by Chris Slamar
 * FIXME: Adapted? Have we stolen this code?
 *
 * LICENSE: GNU General Public License, version 2 (GPLv2)
 * Copyright 2001 - 2013 Ampache.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License v2
 * as published by the Free Software Foundation.
 *
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

	require_once '../../lib/init.php';
	require_once( Config::get('prefix') . "/modules/twitter/twitteroauth/twitteroauth.php");
        session_start();
	

	if(!empty($_SESSION['twitterusername'])) {

		$nowplayingQuery = "SELECT song.title,artist.name FROM song,now_playing,artist WHERE song.id = now_playing.object_id AND artist.id = song.artist";
		debug_event("Twitter", "Now Playing query: " . $nowplayingQuery, "6");
		
		$nowplayingRun = Dba::read($nowplayingQuery);
		$nowplayingResults = Dba::fetch_assoc($nowplayingRun);

		$return = $nowplayingResults['title'] . " by " . $nowplayingResults['name'];
		debug_event("Twitter", "Song from DB is: " . $return, "5");

		$selectquery = "SELECT * FROM twitter_users WHERE username = '" . $_SESSION['twitterusername'] . "' AND ampache_id = " . $_SESSION['userdata']['uid'];
		debug_event("Twitter", "Select query: " . $selectquery, "6");

		$selectrun = Dba::read($selectquery);
		$result = Dba::fetch_assoc($selectrun);

		$twitteroauth = new TwitterOAuth( Config::get('twitter_consumer_key'), Config::get('twitter_consumer_secret'), $result['oauth_token'], $result['oauth_secret']);
		$user_info = $twitteroauth->get('account/verify');
		if( $user_info->error == 'Not found' ) {
			debug_event("Twitter", "Auth Successful! Posting Status", "5");
			$twitteroauth->post('statuses/update', array('status' => 'is rocking out to ' . $return));
			header('Location: ' . Config::get('web_path') );
		}
		
	} else {
			debug_event("Twitter", "Auth Error going back to home.", "5");
			header('Location: ' . Config::get('web_path') );
	}
?>