Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezpageview.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezpageview.php 8665 2001-12-02 12:48:02Z kaid $
5 //
6 // Definition of eZPageView class
7 //
8 // Created on: <04-Jan-2001 18:00:08 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
43 // include_once( "classes/ezdb.php" );
44 // include_once( "ezuser/classes/ezuser.php" );
45
46 class eZPageView
47 {
51 function __construct( $id="" )
52 {
53 if ( $id != "" )
54 {
55 $this->ID = $id;
56 $this->get( $this->ID );
57 }
58 }
59
66 function store()
67 {
68 $db =& eZDB::globalDatabase();
69
70 if ( !isset( $this->ID ) )
71 {
72 // parse information which is not relevant reported by browsers like konqueror
73 $userAgent = preg_replace( "#(.*)\‍);.*#", "\\1)", $_SERVER["HTTP_USER_AGENT"] );
74
75 // check if the browser type is already stored in the database, if it it just
76 // create a reference to it.
77
78 // lock
79 $db->begin();
80 $db->lock( "eZStats_BrowserType" );
81 $nextID = $db->nextID( "eZStats_BrowserType", "ID" );
82 $result = false;
83
84 $userAgent = $db->escapeString( $userAgent );
85 $db->array_query( $browser_type_array,
86 "SELECT ID FROM eZStats_BrowserType
87 WHERE BrowserType='$userAgent'" );
88
89 if ( count( $browser_type_array ) == 0 )
90 {
91 $result = $db->query( "INSERT INTO eZStats_BrowserType
92 ( ID, BrowserType )
93 VALUES ( '$nextID', '$userAgent' )" );
94
95 $this->BrowserTypeID = $nextID;
96 }
97 else
98 {
99 $this->BrowserTypeID = $browser_type_array[0][$db->fieldName( "ID" )];
100 }
101 $db->unlock();
102 if ( $result == false )
103 $db->rollback( );
104 else
105 $db->commit();
106
107 // check if the remote host is already stored in the database, if it it just
108 // create a reference to it.
109
110 $remoteIP = $_SERVER["REMOTE_ADDR"];
111
112 $db->begin();
113 $db->lock( "eZStats_RemoteHost" );
114 $nextID = $db->nextID( "eZStats_RemoteHost", "ID" );
115 $result = false;
116
117 $db->array_query( $remote_host_array,
118 "SELECT ID FROM eZStats_RemoteHost
119 WHERE IP='$remoteIP'" );
120
121 if ( count( $remote_host_array ) == 0 )
122 {
123 $remoteHostName =& gethostbyaddr( $remoteIP );
124
125 $result = $db->query( "INSERT INTO eZStats_RemoteHost
126 ( ID, IP, HostName )
127 VALUES ( '$nextID',
128 '$remoteIP',
129 '$remoteHostName' )
130 " );
131
132 $this->RemoteHostID = $nextID;
133 }
134 else
135 {
136 $this->RemoteHostID = $remote_host_array[0][$db->fieldName( "ID" )];
137 }
138 $db->unlock();
139 if ( $result == false )
140 $db->rollback( );
141 else
142 $db->commit();
143
144 // check if the referer url is already stored in the database, if it it just
145 // create a reference to it.
146
147 $refererDomain = "";
148 $refererURI = "";
149
150 if ( isset( $_SERVER["HTTP_REFERER"] ) and preg_match( "#(htt.*?://)(.*?)(/.*)#", $_SERVER["HTTP_REFERER"], $valueArray ) )
151 {
152 // we don't need to store the http:// or the https://
153 // $valueArray[1];
154
155 // store the referer parts
156 $refererDomain =& $valueArray[2];
157 $refererURI =& $valueArray[3];
158 }
159
160 $db->begin();
161 $db->lock( "eZStats_RefererURL" );
162 $nextID = $db->nextID( "eZStats_RefererURL", "ID" );
163 $result = false;
164
165 $refererURI = $db->escapeString( $refererURI );
166
167 $db->array_query( $referer_url_array,
168 "SELECT ID FROM eZStats_RefererURL
169 WHERE Domain='$refererDomain' AND URI='$refererURI'" );
170
171 if ( count( $referer_url_array ) == 0 )
172 {
173 $result = $db->query( "INSERT INTO eZStats_RefererURL
174 ( ID, Domain, URI )
175 VALUES ( '$nextID',
176 '$refererDomain',
177 '$refererURI' )
178 " );
179 $this->RefererURLID = $nextID;
180 }
181 else
182 {
183 $this->RefererURLID = $referer_url_array[0][$db->fieldName( "ID" )];
184 }
185 $db->unlock();
186 if ( $result == false )
187 $db->rollback( );
188 else
189 $db->commit();
190
191 // check if the requested page is already stored. If so store
192 // the id.
193 $requestURI = $_SERVER["REQUEST_URI"];
194 $requestURI = preg_replace( "#/stats/store(.*?)1x1.gif$#", "\\1", $requestURI );
195 $requestURI = preg_replace( "#/rx.*?-(.*)$#", "\\1", $requestURI );
196 // Remove url parameters
197 // preg_match( "([^?]+)", $requestURI, $regs);
198 // $requestURI =& $regs[1];
199 $requestURI = explode( '/stats/store', $requestURI );
200
201 if ( count( $requestURI ) < 2 )
202 {
203 // If the request URI does not contain the stats/store part, we assume it is a full URI.
204 $requestURI = $requestURI[0];
205 }
206 else
207 {
208 $requestURI = $requestURI[1];
209 }
210
211 $db->begin();
212 $db->lock( "eZStats_RequestPage" );
213 $nextID = $db->nextID( "eZStats_RequestPage", "ID" );
214 $result = false;
215
216 $db->array_query( $request_page_array,
217 "SELECT ID FROM eZStats_RequestPage
218 WHERE URI='$requestURI'" );
219
220 if ( count( $request_page_array ) == 0 )
221 {
222 $result = $db->query( "INSERT INTO eZStats_RequestPage
223 ( ID, URI )
224 VALUES ( '$nextID',
225 '$requestURI' )
226 " );
227
228 $this->RequestPageID = $nextID;
229 }
230 else
231 {
232 $this->RequestPageID = $request_page_array[0][$db->fieldName( "ID" )];
233 }
234 $db->unlock();
235 if ( $result == false )
236 $db->rollback( );
237 else
238 $db->commit();
239
240 $user =& eZUser::currentUser();
241 if ( $user )
242 {
243 $this->UserID = $user->id();
244 }
245 else
246 {
247 $this->UserID = 0;
248 }
249
250 $db->begin();
251 $db->lock( "eZStats_PageView" );
252 $nextID = $db->nextID( "eZStats_PageView", "ID" );
253 $result = false;
254 $now = new eZDateTime();
255 $now = $now->timeStamp( true );
256 $date = new eZDate();
257 $date = $date->timestamp( true );
258 $time = new eZTime();
259 $time = $time->timeStamp( true );
260
261 $result = $db->query( "INSERT INTO eZStats_PageView
262 ( ID, UserID, BrowserTypeID, RemoteHostID, RefererURLID, RequestPageID, Date, DateValue, TimeValue )
263 VALUES ( '$nextID',
264 '$this->UserID',
265 '$this->BrowserTypeID',
266 '$this->RemoteHostID',
267 '$this->RefererURLID',
268 '$this->RequestPageID',
269 '$now',
270 '$date',
271 '$time' )
272 " );
273 $db->unlock();
274 if ( $result == false )
275 $db->rollback( );
276 else
277 $db->commit();
278
279 $this->ID = $nextID;
280 }
281 else
282 {
283 $db->begin();
284 $db->lock( "eZStats_PageView" );
285 $result = $db->query( "UPDATE eZStats_PageView SET
286 UserID='$this->UserID',
287 BrowserTypeID='$this->BrowserTypeID',
288 RemoteHostID='$this->RemoteHostID',
289 RefererURLID='$this->RefererURLID'
290 WHERE ID='$this->ID'
291 " );
292 $db->unlock();
293 if ( $result == false )
294 $db->rollback( );
295 else
296 $db->commit();
297 }
298 }
299
303 function get( $id="" )
304 {
305 $db =& eZDB::globalDatabase();
306
307 $ret = false;
308 if ( $id != "" )
309 {
310 $db->array_query( $pageview_array, "SELECT * FROM eZStats_PageView WHERE ID='$id'" );
311 if ( count( $pageview_array ) > 1 )
312 {
313 die( "Error: Pageview's with the same ID was found in the database. This shouldent happen." );
314 }
315 else if ( count( $pageview_array ) == 1 )
316 {
317 $this->ID =& $pageview_array[0][$db->fieldName( "ID" )];
318 $this->UserID =& $pageview_array[0][$db->fieldName( "UserID" )];
319 $this->Date =& $pageview_array[0][$db->fieldName( "Date" )];
320 $this->DateValue =& $pageview_array[0][$db->fieldName( "DateValue" )];
321 $this->TimeValue =& $pageview_array[0][$db->fieldName( "TimeValue" )];
322 $this->BrowserTypeID =& $pageview_array[0][$db->fieldName( "Date" )];
323 $this->RemoteHostID =& $pageview_array[0][$db->fieldName( "RemoteHostID" )];
324 $this->RefererURLID =& $pageview_array[0][$db->fieldName( "RefererURLID" )];
325 $this->RequestPageID =& $pageview_array[0][$db->fieldName( "RequestPageID" )];
326
327 // fetch the remote IP and domain
328 $db->array_query( $pageview_array,
329 "SELECT IP, HostName FROM eZStats_RemoteHost WHERE ID='$this->RemoteHostID'" );
330
331 $this->RemoteIP = $pageview_array[0][$db->fieldName( "IP" )];
332
333 $this->RemoteHostName = $pageview_array[0][$db->fieldName( "HostName" )];
334
335 // check if the domain name is fetched, if not try to fetch it
336 // and store the result in the table.
337 if ( $this->RemoteHostName = "NULL" )
338 {
339 $db->begin();
340 $db->lock( "eZStats_RemoteHost" );
341 $this->RemoteHostName =& gethostbyaddr( $this->RemoteIP );
342
343 $result = $db->query( "UPDATE eZStats_RemoteHost SET HostName='$this->RemoteHostName' WHERE ID='$this->RemoteHostID'" );
344
345 $db->unlock();
346 if ( $result == false )
347 $db->rollback( );
348 else
349 $db->commit();
350 }
351
352 // fetch the requested page
353 $db->array_query( $pageview_array,
354 "SELECT URI FROM eZStats_RequestPage WHERE ID='$this->RequestPageID'" );
355
356 $this->RequestPage = $pageview_array[0][$db->fieldName( "URI" )];
357
358 $ret = true;
359 }
360 }
361 return $ret;
362 }
363
367 function id()
368 {
369 return $this->ID;
370 }
371
375 function user()
376 {
377 $ret = false;
378 if ( $this->UserID != 0 )
379 {
380 // include_once( "ezuser/classes/ezuser.php" );
381 $ret = new eZUser( $this->UserID );
382 }
383 return $ret;
384 }
385
389 function remoteIP()
390 {
391 return $this->RemoteIP;
392 }
393
397 function &dateTime()
398 {
399 $time = new eZDateTime();
400 $time->setTimeStamp( $this->Date );
401
402 return $time;
403 }
404
408 function remoteHostName()
409 {
410 return $this->RemoteHostName;
411 }
412
416 function requestPage()
417 {
418 return $this->RequestPage;
419 }
420
421
425 function requestPageByID( $id )
426 {
427 $db =& eZDB::globalDatabase();
428
429 // fetch the requested page
430 $db->array_query( $pageview_array,
431 "SELECT URI FROM eZStats_RequestPage WHERE ID='$id'" );
432
433 return $pageview_array[0][$db->fieldName( "URI" )];
434 }
435
439 static public function getHostByAddr( $remoteIP )
440 {
441 $remoteHostName =& gethostbyaddr( $remoteIP );
442 return $remoteHostName;
443 }
444
445
446 var $ID;
447 var $UserID;
448 var $Date;
449 var $DateValue;
450 var $TimeValue;
451 var $BrowserTypeID;
452 var $RemoteHostID;
453 var $RefererID;
454 var $RequestPageID;
455
456 var $BrowserType;
457 var $RemoteIP;
458 var $RemoteHostName;
459 var $RefererURL;
460 var $RefererDomain;
461 var $RequestPage;
462 var $RefererURLID;
463 }
464
465 ?>
$date
$date
Definition: bugpreview.php:66
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZDate
Definition: ezdate.php:46
eZPageView
Definition: ezpageview.php:47
eZPageView\$UserID
$UserID
Definition: ezpageview.php:447
eZPageView\$TimeValue
$TimeValue
Definition: ezpageview.php:450
eZPageView\$BrowserTypeID
$BrowserTypeID
Definition: ezpageview.php:451
eZPageView\$RequestPage
$RequestPage
Definition: ezpageview.php:461
eZPageView\$RefererURLID
$RefererURLID
Definition: ezpageview.php:462
eZPageView\$RemoteHostID
$RemoteHostID
Definition: ezpageview.php:452
eZPageView\$RequestPageID
$RequestPageID
Definition: ezpageview.php:454
eZPageView\$ID
$ID
Definition: ezpageview.php:446
eZPageView\__construct
__construct( $id="")
Definition: ezpageview.php:51
eZPageView\$BrowserType
$BrowserType
Definition: ezpageview.php:456
eZPageView\store
store()
Definition: ezpageview.php:66
eZPageView\remoteIP
remoteIP()
Definition: ezpageview.php:389
eZPageView\remoteHostName
remoteHostName()
Definition: ezpageview.php:408
eZPageView\$RefererID
$RefererID
Definition: ezpageview.php:453
eZPageView\$DateValue
$DateValue
Definition: ezpageview.php:449
eZPageView\$RefererDomain
$RefererDomain
Definition: ezpageview.php:460
eZPageView\$RefererURL
$RefererURL
Definition: ezpageview.php:459
eZPageView\id
id()
Definition: ezpageview.php:367
eZPageView\requestPage
requestPage()
Definition: ezpageview.php:416
eZPageView\$RemoteIP
$RemoteIP
Definition: ezpageview.php:457
eZPageView\requestPageByID
requestPageByID( $id)
Definition: ezpageview.php:425
eZPageView\$RemoteHostName
$RemoteHostName
Definition: ezpageview.php:458
eZPageView\dateTime
& dateTime()
Definition: ezpageview.php:397
eZPageView\user
user()
Definition: ezpageview.php:375
eZPageView\getHostByAddr
static getHostByAddr( $remoteIP)
Definition: ezpageview.php:439
eZPageView\$Date
$Date
Definition: ezpageview.php:448
eZTime
Definition: eztime.php:38
eZUser
Definition: ezuser.php:76
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$result
$result
Definition: companysearch.php:94
$id
$id
Definition: companytypelist.php:193
$db
$db
Definition: ezarticle/user/authorlist.php:53
$now
$now
Definition: ezcalendar/user/dayview.php:401
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$time
$time
Definition: homepage.php:327
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.