cvs: pearweb /include/Damblan Trackback.php
| From: | Tobias Schlitt | Date: | Wed, 15 Dec 2004 14:31:21 +0000 |
| Subject: | cvs: pearweb /include/Damblan Trackback.php | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-cvs+get-27439@lists.php.net to get a copy of this message | ||
toby Wed Dec 15 09:31:21 2004 EDT
Modified files:
/pearweb/include/Damblan Trackback.php
Log:
* PHP4rifying.
http://cvs.php.net/diff.php/pearweb/include/Damblan/Trackback.php?r1=1.2&r2=1.3&ty=u
Index: pearweb/include/Damblan/Trackback.php
diff -u pearweb/include/Damblan/Trackback.php:1.2 pearweb/include/Damblan/Trackback.php:1.3
--- pearweb/include/Damblan/Trackback.php:1.2 Mon Dec 13 06:55:40 2004
+++ pearweb/include/Damblan/Trackback.php Wed Dec 15 09:31:20 2004
@@ -10,7 +10,7 @@
* @var int
* @since
*/
- private $_timestamp;
+ var $_timestamp;
/**
* Boolean flag, if the trackback has been improved by a PEAR developer, yet.
@@ -18,7 +18,7 @@
* @var bool
* @since
*/
- private $_approved;
+ var $_approved;
/**
* __construct
@@ -42,9 +42,9 @@
* @param bool $approved Wether the trackback is approved, yet. Default is false.
* @return void
*/
- public function __construct($data, $timestamp, $approved = true)
+ function Damblan_Trackback($data, $timestamp, $approved = false)
{
- parent::__construct($data);
+ $this->_fromArray($data);
$this->_timestamp = (int)$timestamp;
$this->_approved = $approved;
}
@@ -58,14 +58,17 @@
* @param mixed $key The name of the property to receive.
* @return mixed $val The value of the property.
*/
- public function __get($key)
+ function __get($key, &$val)
{
$testKey = '_'.$key;
if (isset($this->$testKey)) {
- return $this->$testKey;
- } else {
- return $this->_data[$key];
- }
+ $val = $this->$testKey;
+ return true;
+ } else if (isset($this->_data[$key])) {
+ $val = $this->_data[$key];
+ return true;
+ }
+ return false;
}
/**
@@ -79,7 +82,7 @@
* @param object DB $dbh Database connection object (PEAR::DB).
* @return void
*/
- public function save ( $dbh )
+ function save(&$dbh)
{
$necessaryData = array('id', 'title', 'url',
'excerpt', 'blog_name');
$this->_checkData($necessaryData);
@@ -97,7 +100,7 @@
)";
$res = $dbh->query($sql);
if (DB::isError($res)) {
- throw new Exception('Unable to save trackback: '.$res->getMessage());
+ return PEAR::raiseError('Unable to save trackback: '.$res->getMessage());
}
return true;
}
@@ -113,11 +116,14 @@
* @param int $timestamp The timestamp of the trackback to load.
* @return void
*/
- public function load ( $dbh )
+ function load(&$dbh)
{
$necessaryData = array('id');
+ if (PEAR::isError($necessaryData)) {
+ return $necessaryData;
+ }
if (!isset($this->_timestamp) || !is_int($this->_timestamp)) {
- throw new Exception('Necessary attribute timestamp missing.');
+ return PEAR::raiseError('Necessary attribute timestamp missing.');
}
$this->_checkData($necessaryData);
$data = $this->_getDecodedData($necessaryData);
@@ -126,7 +132,7 @@
AND timestamp = ".$dbh->quoteSmart($this->_timestamp);
$res = $dbh->getRow($sql, null, DB_FETCHMODE_ASSOC);
if (DB::isError($res) || !is_array($res) || !count($res)) {
- throw new Exception('Unable to load trackback: '.$res->getMessage());
+ return PEAR::raiseError('Unable to load trackback: '.$res->getMessage());
}
foreach ($res as $key => $val) {
if (($key != 'timestamp') && ($key != 'approved')) {
@@ -156,16 +162,22 @@
* @param int $timestamp The timestamp of the trackback to load.
* @return void
*/
- public function approve($dbh)
+ function approve(&$dbh)
{
$necessaryData = array('id');
+ if (!isset($this->_timestamp)) {
+ return PEAR::raiseError('Could not approve trackback. Timestamp missing.');
+ }
$data = $this->_getDecodedData($necessaryData);
+ if (PEAR::isError($data)) {
+ return $data;
+ }
$sql = "UPDATE trackbacks SET approved =
".$dbh->quoteSmart('true')." WHERE
id = ".$dbh->quoteSmart($data['id'])."
AND timestamp = ".$dbh->quoteSmart($this->_timestamp);
$res = $dbh->query($sql) ;
if (DB::isError($res)) {
- throw new Exception('Could not approve trackback.');
+ return PEAR::raiseError('Could not approve trackback.');
}
$this->_approved = true;
return true;
@@ -180,17 +192,23 @@
* @param
* @return void
*/
- public function delete($dbh)
+ function delete(&$dbh)
{
$necessaryData = array('id');
$data = $this->_getDecodedData($necessaryData);
- $this->load($dbh, $this->_timestamp);
+ if (PEAR::isError($data)) {
+ return $data;
+ }
+ $res = $this->load($dbh, $this->_timestamp);
+ if (PEAR::isError($res)) {
+ return $res;
+ }
$sql = "DELETE FROM trackbacks WHERE
id = ".$dbh->quoteSmart($data['id'])."
AND timestamp = ".$dbh->quoteSmart($this->_timestamp);
$res = $dbh->query($sql) ;
if (DB::isError($res)) {
- throw new Exception('Could not delete trackback.');
+ return PEAR::raiseError('Could not delete trackback:
'.$res->getMessage());
}
return true;
}
@@ -211,7 +229,7 @@
* @return array Array of PEAR_Trackback objects.
* @throws Exception If no results are received.
*/
- public static function listTrackbacks($dbh, $id, $approvedOnly = true, $orderBy =
'timestamp DESC', $limit = 10)
+ function listTrackbacks(&$dbh, $id, $approvedOnly = true, $orderBy = 'timestamp
DESC', $limit = 10)
{
$sql = 'SELECT id, title, excerpt, blog_name, url, timestamp, approved FROM trackbacks
WHERE
id LIKE '.$dbh->quoteSmart($id);
@@ -222,7 +240,7 @@
$sql .= ' LIMIT '.$limit;
$res = $dbh->getAll($sql, null, DB_FETCHMODE_ASSOC);
if (DB::isError($res)) {
- throw new Exception('Could not receive trackback list:
'.$res->getMessage());
+ return PEAR::raiseError('Could not receive trackback list:
'.$res->getMessage());
}
$ret = array();
foreach ($res as $row) {
@@ -247,7 +265,7 @@
* @param bool $admin Wether to output administrative links or not.
* @return void
*/
- public static function printList ($trackbackList, $admin = false)
+ function printList ($trackbackList, $admin = false)
{
print '<table border="0" cellspacing="0"
cellpadding="2" style="width: 100%">';
foreach ($trackbackList as $trackback) {
@@ -284,7 +302,7 @@
print 'Date:';
print '</th>';
print '<td class="ulcell">';
- print date('D M d H:i:s Y', $trackback->timestamp - date('Z',
$trackback->timestamp)) . ' UTC';
+ print make_utc_date($trackback->timestamp, 'Y-m-d');
print '</td>';
print '</tr>';
@@ -315,4 +333,7 @@
print '</table>';
}
}
+
+overload('Damblan_Trackback');
+
?>