My favorites | Sign in
Project Logo
                
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* @copyright Eric Barnes
* @link http://ericlbarnes.com/68classifieds/modules/classifieds-twitter-feeder/
*/
class twitter_events
{
/**
* Set this to true to debug
*
* @var bool
*/
var $debug = false;

// --------------------------------------------------------------------

/**
* Register the hooks.
*
* @var array
*/
function twitter_events(&$modules)
{
$modules->register('update_order', $this, 'by_order_id');
$modules->register('add_listing', $this, 'change_display_status');
$modules->register('listing_modified', $this, 'change_display_status');
$modules->register('change_display_status', $this, 'change_display_status');
}

// --------------------------------------------------------------------

/**
* Show server info on admin/home
*
* @access public
*/
function by_order_id($id)
{
$Listing = Library::loadLibrary('Listings');
$lid = $Listing->getListingByOrderID($id);
return $this->tweet_it($lid);
}

// --------------------------------------------------------------------

function change_display_status($data)
{
$id = $data['id'];
if(isset($data['display']) && $data['display'] == 'Y')
{
$status= $data['display'];
return $this->tweet_it($id);
}
elseif(isset($data['status']) && $data['status'] == 'Y')
{
$status= $data['status'];
return $this->tweet_it($id);
}
}

function tweet_it($id)
{
global $db;

if($this->debug)
{
echo 'Attempting to tweet it...<br />';
}

require(FILESYSTEM_PATH .'/modules/twitter/settings.php');
require(FILESYSTEM_PATH .'/modules/twitter/Twitter.php');

if($this->debug)
{
echo 'Setting up twitter class...<br />';
}
if($this->debug && ($user == '' || $pass == ''))
{
die '<font color="red">ERROR: Please set username and password in modules/twitter/settings.php</font>...<br />';
}
$twitter = new twitter($user,$pass);

if($this->debug)
{
echo 'Checking if the listing is already tweeted...<br />';
}
$sSQL='SELECT id,title,tweeted FROM '.PREFIX.'listings WHERE id='.$id;
$result=$db->query($sSQL);
if($result->size()>0)
{
$rs=$result->fetch();
$result->freeResult();
$id = $rs['id'];
if($this->debug)
{
echo 'Trimming Title...<br />';
}

$title = String::dot($rs['title'], 70, '...');

if($this->debug)
{
echo 'Shortening URL...<br />';
}
$url = $twitter->doShortenURL(URL.'/viewlisting.php?view='.$id);

$msg = 'New classified: '.$title.' '. $url;

if($this->debug)
{
echo 'Sending Tweet...<br />';
}
if($rs['tweeted']==0 && $twitter->setStatus($msg))
{
if($this->debug)
{
echo 'CONGRATULATIONS: Tweet Sent...<br />';
}
$sSQL = 'UPDATE '.PREFIX.'listings SET tweeted = 1 WHERE id='.$id;
$db->query($sSQL);
return true;
}
else
{
if($this->debug)
{
echo '<font color="red">ERROR: TWEET NOT SENT</font>...<br />';
}
return false;
}
}
else
{
return false;
}
}
}

/* End of file hooks.php */
/* Location: ./trunk/twitter/hooks.php */
Show details Hide details

Change log

r89 by suzkaw68 on Aug 25, 2009   Diff
Added debugging code for when it is sent
to Twitter.
Go to: 
Project members, sign in to write a code review

Older revisions

r59 by suzkaw68 on Mar 27, 2009   Diff
Updated files to v.0.2
r41 by suzkaw68 on Mar 14, 2009   Diff
Added twitter feeder
All revisions of this file

File info

Size: 3125 bytes, 140 lines
Hosted by Google Code