27/05/2012 11:41am

PHP | Problem - TravelBlogs DataObject


<?php


class TravelBlog extends DataObject {

static $db = array(
'BlogURL' => 'Varchar(255)',
'RSSFeed' => 'Varchar(255)',
'GooglePageRank' => 'Varchar(200)',
'mozRank' => 'Decimal',
'DomainAuthority' => 'Int',
'TotalLinks' => 'Int',
'ExternalLinks' => 'Int',
'LastPosted' => 'Date',
'BlogStatus' => "Enum('Active, Uncertain, Inactive', 'Active')",
'EmailAddress' => 'Varchar(255)',
'Notes' => 'HTMLText'
);

static $has_one = array(

);

static $many_many = array(

);

static $singular_name = 'TravelBlog';
static $plural_name = 'TravelBlogs';

static $summary_fields = array(
'BlogURL',
'RSSFeed',
'GooglePageRank',
'mozRank',
'TotalLinks',
'ExternalLinks'
);

static $searchable_fields = array(
'BlogURL',
'RSSFeed',
'GooglePageRank',
'EmailAddress'
);


function getCMSFields() {

$fields = parent::getCMSFields();

$fields->addFieldToTab("Root.Main", new TextField('BlogURL', 'Travel Blog URL'));
$fields->addFieldToTab("Root.Main", new TextField('RSSFeed', 'Travel Blog RSS Feed'));
$fields->addFieldToTab("Root.Main", new ReadonlyField('GooglePageRank', 'Google Page Rank'));
$fields->addFieldToTab("Root.Main", new ReadonlyField('mozRank', 'mozRank'));
$fields->addFieldToTab("Root.Main", new ReadonlyField('DomainAuthority', 'Domain Authority'));
$fields->addFieldToTab("Root.Main", new ReadonlyField('TotalLinks', 'Total Links'));
$fields->addFieldToTab("Root.Main", new ReadonlyField('ExternalLinks', 'External Links'));
$fields->addFieldToTab("Root.Main", new ReadonlyField('LastPosted', 'Date of Last Article'));
$fields->addFieldToTab("Root.Main", new ReadonlyField('BlogStatus', 'Blog Status'));
$fields->addFieldToTab("Root.Main", new EmailField('EmailAddress', 'Email Address for Blog'));
$fields->addFieldToTab("Root.Main", new HtmlEditorField('Notes', 'Notes on Blog', 15));

return $fields;

}

function URLWithoutHTTP() {

return str_replace("http://", "", $this->URL);

}

function onBeforeWrite() {

echo "RSS Feed = ".$this->RSSFeed;

// Find the date of the most recent post
$mostRecentPost = file_get_contents($this->RSSFeed);
$mostRecentPost = Convert::xml2array($mostRecentPost);
$this->LastPosted = date("Y-m-d", strtotime($mostRecentPost['channel']['item'][0]['pubDate']));

$googlepr = file_get_contents("http://josh-fowler.com/prapi/?url=".$this->BlogURL);
$this->GooglePageRank = $googlepr;

// MOZSCAPE API KEY
// Access ID = member-7f07f8609b
// Secret Key = 80fb06e15831c4c747934e994cc23c78

//Add your accessID here
$AccessID = 'myAccessID';
//Add your secretKey here
$SecretKey = 'mySuperSecretKey';

include '/Volumes/OSX-HDD/DROPBOX/WebServerRoot/adboutique.org/public/mysite/code/seomoz-api/bootstrap.php';

$authenticator = new SEOMOZAuthenticator();
$authenticator->setAccessID($AccessID);
$authenticator->setSecretKey($SecretKey);

$urlMetricsService = new URLMetricsService($authenticator);
$response = $urlMetricsService->getUrlMetrics($this->BlogURL);

$this->mozRank = number_format($response->umrp, 2);
$this->DomainAuthority = number_format($response->pda);
$this->TotalLinks = $response->uid;
$this->ExternalLinks = $response->ueid;

// Call the Parent function.
parent::onBeforeWrite();

}

}

?>


Post Comment