/
linkdatabase.php
151 lines (137 loc) · 3.4 KB
/
linkdatabase.php
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
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* Linkdatabase
* Interacts with the database for links
*
* @package Habari
*
* @version $Id$
* @copyright 2008
*/
class Traffum extends QueryRecord
{
// our definitions for traffum types
const TYPE_SEND_NORMAL = 1;
const TYPE_SEND_ATOM = 2;
const TYPE_VIEW_NORMAL = 3;
const TYPE_VIEW_ATOM = 4;
/**
* static function default_fields
* Returns the defined database columns for a traffum
**/
public static function default_fields()
{
return array(
'id' => 0,
'post_id' => 0,
'date' => HabariDateTime::date_create(),
'type' => self::TYPE_VIEW_NORMAL,
'ip' => sprintf("%u", ip2long( $_SERVER['REMOTE_ADDR'] ) ),
'referrer' => $_SERVER['HTTP_REFERER']
);
}
/**
* constructor __construct
* Constructor for the Traffum class.
* @param array an associative array of initial Traffum field values.
**/
public function __construct( $paramarray = array() )
{
// Defaults
$this->fields = array_merge( self::default_fields(), $this->fields );
parent::__construct( $paramarray );
$this->exclude_fields('id');
}
/**
* static function get
* Returns a single traffum, by ID
*
* @param int An ID
* @return array A single Traffum object
**/
static function get( $ID = 0 )
{
if ( ! $ID ) {
return false;
}
return DB::get_row( 'SELECT * FROM {link_traffic} WHERE id = ?', array( $ID ), 'Traffum' );
}
/**
* static function create
* Creates a traffum and saves it
* @param array An associative array of traffum fields
* $return Traffum The traffum object that was created
**/
static function create($paramarray)
{
$traffum = new Traffum($paramarray);
$traffum->insert();
return $traffum;
}
/**
* function insert
* Saves a new comment to the posts table
*/
public function insert()
{
$result = parent::insertRecord( DB::table('link_traffic') );
$this->newfields['id'] = DB::last_insert_id(); // Make sure the id is set in the comment object to match the row id
$this->fields = array_merge($this->fields, $this->newfields);
$this->newfields = array();
return $result;
}
/**
* function update
* Updates an existing comment in the posts table
*/
public function update()
{
$result = parent::updateRecord( DB::table('link_traffic'), array('id'=>$this->id) );
$this->fields = array_merge($this->fields, $this->newfields);
$this->newfields = array();
return $result;
}
/**
* function delete
* Deletes this comment
*/
public function delete()
{
return parent::deleteRecord( DB::table('link_traffic'), array('id'=>$this->id) );
}
/**
* function __get
* Overrides QueryRecord __get to implement custom object properties
* @param string Name of property to return
* @return mixed The requested field value
**/
public function __get( $name )
{
$fieldnames = array_merge( array_keys( $this->fields ), array('post', 'info' ) );
if( !in_array( $name, $fieldnames ) && strpos( $name, '_' ) !== false ) {
preg_match('/^(.*)_([^_]+)$/', $name, $matches);
list( $junk, $name, $filter ) = $matches;
}
else {
$filter = false;
}
switch($name)
{
default:
$out = parent::__get( $name );
break;
}
return $out;
}
/**
* function __set
* Overrides QueryRecord __set to implement custom object properties
* @param string Name of property to return
* @return mixed The requested field value
**/
public function __set( $name, $value )
{
return parent::__set( $name, $value );
}
}
?>