Want to post new jobs to popular micro-blogging service Twitter? Of course you do. Follow the tutorial below to make your Jobberbase site almost as cool as AllDevJobs.com.

To avoid conflicting with newer versions of Jobberbase, I am writing this tutorial for any version so it should always work. As always, make sure you back up your site before you proceed with the following changes.
This may seem obvious, but yes, you need to create a new account. Create Account »
In the root directory of your Jobberbase installation, you have a ‘config.php’ file. In that file you will want to add your Twitter account information. I added mine at line 41. The bolded text indicates the places you need to add your account info.
/* Twitter username & password */
define('TWITTER_ENABLED',1);
define('TWITTER_USERNAME','username_goes_here');
define('TWITTER_PASSWORD','password_goes_here');
After that’s done, you also need to add a reference to the Twitter function you’ll be creating in Step 4. Around line 87, you should see the following:
// Function and classes includes
require_once '_includes/function.validate_email.php';
require_once '_includes/function.redirect_to.php';
require_once '_includes/function.printr.php';
require_once '_includes/function.escape.php';
require_once '_includes/functions.php';
require_once '_includes/class.phpmailer.php';
require_once '_includes/class.Postman.php';
...
You need to add require_once '_includes/function.Twitter.php'; to this list. I added it just after require_once '_includes/functions.php';.
When done, it should look like this:
// Function and classes includes
require_once '_includes/function.validate_email.php';
require_once '_includes/function.redirect_to.php';
require_once '_includes/function.printr.php';
require_once '_includes/function.escape.php';
require_once '_includes/function.Twitter.php';
require_once '_includes/functions.php';
require_once '_includes/class.phpmailer.php';
require_once '_includes/class.Postman.php';
require_once '_includes/class.Textile.php';
require_once '_includes/class.Sanitizer.php';
require_once '_includes/class.Db.php';
require_once '_includes/class.Job.php';
require_once '_includes/class.JobRequest.php';
require_once '_includes/class.Paginator.php';
require_once '_includes/class.Feed.php';
require_once '_includes/class.SpamReport.php';
require_once '_includes/class.Api.php';
require_once '_includes/class.JobApplication.php';
require_once '_includes/class.SearchKeywords.php';
require_once '_includes/smarty/libs/Smarty.class.php';
You will shortly be creating a new Twitter function that will post the job listings for you, however, you need to find the right place to call that function, which would be immediately after the job listing is activated, not necessarily when it’s been posted, because you don’t want people just posting anything to Twitter before you’ve reviewed it.
Around line 873, you’ll need to replace the entire public function Publish() with the following code:
// Publishes a newly created job post (is_temp => 0)
public function Publish()
{
global $db;
if ($this->CheckPosterEmail())
{
$sql = 'UPDATE jobs SET is_temp = 0, is_active = 1 WHERE id = ' . $this->mId;
$db->query($sql);
$sql = 'SELECT type_id, id, title, company FROM jobs WHERE id = ' . $this->mId;
$result = $db->query($sql);
$row = $result->fetch_assoc();
$formattedMessage = $row['title'] . " at " .$row['company'] . " " . BASE_URL . "job/" .$row['id'] . "/";
Tweet($formattedMessage);
}
else
{
$sql = 'UPDATE jobs SET is_temp = 0, is_active = 0 WHERE id = ' . $this->mId;
$db->query($sql);
}
}
In your main includes directory, you need to create a new file for the script to post Twitter messages. You will need to have cURL enabled on your server for this to work.
Inside the new file, add this:
<?php
/**
* Twitter post API
*/
function Tweet($msg){
if(TWITTER_ENABLED==1){
$username = TWITTER_USERNAME;
$password = TWITTER_PASSWORD;
$message = $msg;
$url = 'http://twitter.com/statuses/update.xml';
// Alternative JSON version
// $url = 'http://twitter.com/statuses/update.json';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
// check for success or failure
if (empty($buffer)) {
echo 'Post failed. Please add listing manually.';
} else {
echo 'Success';
}
}
}
?>
That’s it. Upload your files and you’re ready to post to Twitter. Please let me know if you have any difficulties with this tutorial and I will update it accordingly.
Cool!
That’s a really useful tip – thanks for sharing it. I’ll be adding it as soon as I get the new site up and running
very nice tutorial.
I am trying to figure out how to make auto posting from RSS to jobberbase. Is it possible?
Hi Chris,
I’m trying to add this function to my v1.6. Because your code is writen for v1.5 I’m wondering what I need to change. When using the above code I get a blank page after submitting the ad. Can you help me?
You will need to turn error reporting on for PHP and see what error it outputs. If you have trouble implementing this code, you may want to try Twitterfeed, which will essentially post the RSS feed to Twitter, Identi.ca, or Ping.fm, which may be a better solution since it doesn’t hack the core code in Jobberbase.
Thanks for your quick respons! Turned out I made a type error in another includes-file which I hadn’t noticed. In v1.6 I can now post to Twitter.
You might want to edit this post, because there is a small change in the Publish function (they have moved the sql query).
Again: thank you very much for the script and your help!
Glad to hear you figured it out. Thanks for mentioning the Publish change as well, I will take a look at that.
Can I make two feature request?
Feature request 1: use Tinyurl to shorten url;
feature request 2: prevent the url from ‘falling off’ when you reach the 140 characters limit.
You can make all the feature requests you want
I’m not sure I’ll have time to work on this feature, especially since I think twitterfeed is probably an easier way to integrate posting jobs to twitter.
Hi Chris, so far your script is working flawless for one thing. When activating a (first) new job it’s not being posted on Twitter. Do you have the time to fix that (or can you tell me what I should do)?
I set up a new url shortener service dedicated for jobs.
Feel free to get back to me if you want more information. I think it could be interesting to integrate an url shortener in your script to get the most of social networks and get our jobs spreading.
great tutorial! many many thanks!
I’m also trying to add it to my jb1.6 and i can’t see the posts. Can you please tell me what I need to change.
i doubled check the misspellings and the curl is enabled
thanx again
Hi.
I have problem.
My post url seen on twitter like this: http://ismerkezi.org/admin/job/26/
How fixed?
[...] Post job announcements: Post work study, full-time faculty positions and other job announcements on Twitter. [...]
[...] Post job announcements: Post work study, full-time faculty positions and other job announcements on Twitter. [...]
This add-on works fine on my install of 1.7 and I really like it.
I have just one question;
When my new job is posted I get a return page with just the message “Succes”. It is made by the echo statement in the function.Twitter.php file. Is it possible that it will redirect it to my page instead of a blank page with this message?
Please let me know by e-mail please.
Not necessarily a good idea. ,