RedJumpsuit

jobberBase custom development and support

Generating bit.ly URL in jobberBase

i was searching for a php class that interacts easily with the bit.ly API and found a really good one here: http://bit.ly/oDwGX

after studying the code, i thought of a way to integrate this with jobberBase and dynamically create a bit.ly URL when jobs are posted using the PHP class that i found.

just follow the instructions below.

1) create a bit.ly account (if you do not have yet) and grab your API key

2) download the bit.ly API interaction class found in the website i mentioned http://bit.ly/oDwGX and save it as ‘bitly.php’ on your /_includes/ folder

3) run this sql script on your ‘jobs’ table (be sure to make a backup of your table first!)

ALTER TABLE `jobs` ADD `bitly` VARCHAR( 100 ) NULL;

4) open up your root’s ‘config.php’ and below this line:

require_once '_includes/smarty/libs/Smarty.class.php';

add this line:

// bit.ly class
require_once '_includes/bitly.php';

5) open up the bitly.php class you saved on /_includes/ folder and look for this function:

public function shorten($url, $returnHash = false)
{
...
}

below it, paste this new code:

/**
Shorten URL for jobberBase
author: RedJumpsuit <myredjumpsuit@gmail.com>
url: www.redjump.co.cc
**/
public function shorten_jobber($id,$url,$returnHash=false)
{
	global $db;
	$sql = 'SELECT bitly
			FROM jobs
			WHERE id = '. $id;
	$result = $db->query($sql);
	$row = $result->fetch_assoc();
	if ($row['bitly'] == '')
	{
		$bitlyurl = 'http://api.bit.ly/shorten?version='.$this->version.'&longUrl='.$url.'&login='.$this->login.'&apiKey='.$this->apikey.'&format='.$this->format;
		if ( $this->getResult($bitlyurl) !== false )
		{
			$sqlu = 'UPDATE jobs SET bitly = "'. $this->results['shortUrl'] .'" WHERE id = '. $id;
			$db->execute($sqlu);
			if ( $returnHash == true ) {
				return array('shortUrl' => $this->results['shortUrl'], 'hash' => $this->results['hash']);
			} else {
				return $this->results['shortUrl'];
			}
		}
		return false;
	}
}

6) open up ‘page_verify.php’ on your root folder and add this:

// generate bit.ly URL for jobberBase
// author: RedJumpsuit <myredjumpsuit@gmail.com>
// url: www.redjump.co.cc
$joburl = BASE_URL . 'job/' . $id . '/';
$bitly = new bitly('redjumpsuit', 'your API key goes here');
$bitly->shorten_jobber($id,$joburl);

before this block:

$smarty->assign('job', $jobs);
$html_title = stripslashes($jobs['title']) . ' at ' . stripslashes($jobs['company']) . ' / ' . SITE_NAME;
$template = 'publish-verify.tpl';

7) to enable this in the admin panel, open up page_edit_post.php on your /admin/ folder and replace this line:

$job->Create($data);

with this:

$id = $job->Create($data);
 
// generate bit.ly URL for jobberBase
// author: RedJumpsuit <myredjumpsuit@gmail.com>
// url: www.redjump.co.cc
$joburl = BASE_URL_ORIG . 'job/' . $id . '/';
$bitly = new bitly('redjumpsuit', 'your API key goes here');
$bitly->shorten_jobber($id,$joburl);

now it’s up to you to grab the bit.ly url from the ‘jobs’ table, should be easy from this point on right?

if you like my post, use the donate button below :)

1 Comment

  1. I tried using the bit.ly url instead of the regular one, but can’t get it to work. Any help/ tips would be appreciated :)

Leave a Response