File: Notifications_Twitter.php

package info (click to toggle)
spotweb 20130826%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,132 kB
  • ctags: 11,281
  • sloc: php: 31,367; xml: 1,009; sh: 148; makefile: 83
file content (55 lines) | stat: -rwxr-xr-x 2,087 bytes parent folder | download | duplicates (3)
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
<?php
require_once "lib/notifications/twitter/twitteroauth.php";

class Notifications_Twitter extends Notifications_abs {
	private $dataArray;
	private $_appName;
	var $twitterObj;

	function __construct($appName, array $dataArray) {
		$this->_appName = $appName;
		$this->dataArray = $dataArray;
	} # ctor

	function register() {
		return;
	} # register

	function requestAuthorizeURL() {
		$this->twitterObj = new TwitterOAuth($this->dataArray['consumer_key'], $this->dataArray['consumer_secret']);
		$request_token = $this->twitterObj->getRequestToken();

		switch ($this->twitterObj->http_code) {
			case 200	: $registerURL = $this->twitterObj->getAuthorizeURL($request_token); break;
			default		: $registerURL = '';
		} # switch

		return array($this->twitterObj->http_code, $request_token, $registerURL);
	} # requestAuthorizeURL

	function verifyPIN($pin) {
		$this->twitterObj = new TwitterOAuth($this->dataArray['consumer_key'], $this->dataArray['consumer_secret'], $this->dataArray['request_token'], $this->dataArray['request_token_secret']);
		$access_token = $this->twitterObj->getAccessToken($pin);

		switch ($this->twitterObj->http_code) {
			case 200	: break;
			default		: $access_token = array();
		} # switch

		return array($this->twitterObj->http_code, $access_token);
	} # verifyPIN

	function sendMessage($type, $title, $body, $sourceUrl) {
		$this->twitterObj = new TwitterOAuth($this->dataArray['consumer_key'], $this->dataArray['consumer_secret'], $this->dataArray['access_token'], $this->dataArray['access_token_secret']);

		$message = array();
		$message['status'] = substr($this->_appName . ': ' . $body, 0, 140);
		if (empty($sourceUrl)) {
			$this->twitterObj->post('statuses/update', array('status' => $message));
		} else {
			$annotations = array(array('webpage' => array('title' => $this->_appName, 'url' => $sourceUrl)));
			$this->twitterObj->post('statuses/update', array('status' => $message, 'annotations' => json_encode($annotations)));
		} # if
	} # sendMessage

} # Notifications_Twitter