~quam-plures-core/quam-plures/fix-auto_p_plugin

« back to all changes in this revision

Viewing changes to qp_inc/sessions/model/_hit.class.php

  • Committer: EdB
  • Date: 2013-03-18 19:30:14 UTC
  • mfrom: (7602.1.58 quam-plures)
  • Revision ID: 1912webworks@gmail.com-20130318193014-qogr0c0lwd5ix8lj
quam-plures/qp5_colls-blogs_chaps-cats

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/**
3
3
 * This file implements the Hit class
4
4
 *
5
 
 * @todo (1111): vars type 'foo' need useful/valid descriptions
6
 
 *
 
5
 * @todo (1111) vars type 'foo' need useful/valid descriptions
7
6
 * @author {@link http://wonderwinds.com/ Ed Bennett}
8
7
 * @author {@link http://daniel.hahler.de/ Daniel HAHLER}
9
8
 * @author {@link http://fplanque.net/ Francois PLANQUE}
24
23
         * Hit ID
25
24
         *
26
25
         * Stored in T_hitlog as hit_ID, gets set when {@link log()} is called and the hit is logged.
 
26
         *
27
27
         * @var integer
28
28
         */
29
29
        var $ID;
30
30
        /**
31
 
         * Is the hit already logged?
32
 
         * @var boolean
33
 
         */
34
 
        var $logged = false;
35
 
 
36
 
        /**
37
 
         * The referer/referrer.
38
 
         *
39
 
         * @var string
40
 
         */
41
 
        var $referer;
42
 
 
43
 
        /**
44
 
         * The type of referer.
45
 
         *
 
31
         * Referer Type
 
32
         *
 
33
         * Stored in T_hitlog as hit_referer_type, possible values: 'search'|'blacklist'|
 
34
         * 'spam'|'referer'|'direct'|'self'|'admin'. By default this is not set to anything.
46
35
         * Note: "spam" referers do not get logged.
47
 
         * 'search'|'blacklist'|'referer'|'direct'|'spam'
48
36
         *
49
37
         * @var string
50
38
         */
51
39
        var $referer_type;
52
 
 
53
 
        /**
54
 
         * The ID of the referer's base domain in T_basedomains
55
 
         *
 
40
        /**
 
41
         * Referer
 
42
         *
 
43
         * Stored in T_hitlog as hit_referer, from either HTTP_REFERER or _SERVER or getenv().
 
44
         * The stored value is truncated to 500 characters, which should be more than enough.
 
45
         *
 
46
         * @var string
 
47
         */
 
48
        var $referer;
 
49
        /**
 
50
         * Referer's domain ID
 
51
         *
 
52
         * Stored in T_hitlog as hit_referer_dom_ID, the ID of the referer's base domain in T_basedomains.
56
53
         * @var integer
57
54
         */
58
55
        var $referer_domain_ID;
59
 
 
 
56
        /**
 
57
         * SERP rank
 
58
         *
 
59
         * Stored in T_hitlog as hit_serprank, If it is a search hit then the referer's SERP rank, else NULL
 
60
         *
 
61
         * @var integer
 
62
         */
 
63
        var $_serprank = NULL;
 
64
        /**
 
65
         * Remote Address
 
66
         *
 
67
         * Stored in T_hitlog as hit_remote_addr, the remote address (IP) of the hit.
 
68
         *
 
69
         * @var string
 
70
         */
 
71
        var $IP;
 
72
        /**
 
73
         * User Agent
 
74
         *
 
75
         * The user agent string, cut to 500 characters. Stored in T_hitlog as hit_agent_signature,
 
76
         * the user agent string is truncated to 500 characters, which should be more than enough.
 
77
         *
 
78
         * @see Hit::get_user_agent()
 
79
         * @var string
 
80
         */
 
81
        var $user_agent;
 
82
        /**
 
83
         * Type of Hit
 
84
         *
 
85
         * Stored in T_hitlog as hit_agent_type, the default setting ('unknown') is
 
86
         * for hits that are not detected as 'rss'|'robot'|'browser'.
 
87
         *
 
88
         * @see Hit::detect_useragent()
 
89
         * @var string
 
90
         */
 
91
        var $agent_type;
 
92
        /**
 
93
         * Platform
 
94
         *
 
95
         * Stored in T_hitlog as hit_agent_platform, the user agent platform (operating system really)
 
96
         *
 
97
         * @see Hit::detect_useragent()
 
98
         * @var string
 
99
         */
 
100
        var $agent_platform;
 
101
        /**
 
102
         * Ignore this hit?
 
103
         * @var boolean
 
104
         */
 
105
        var $ignore = false;
60
106
        /**
61
107
         * Is this a reload?
 
108
         *
62
109
         * This gets lazy-filled by {@link is_new_view()}.
 
110
         *
63
111
         * @var boolean
64
 
         * @access protected
65
112
         */
66
113
        var $_is_new_view;
67
 
 
68
114
        /**
69
 
         * Ignore this hit?
 
115
         * Is the hit already logged?
70
116
         * @var boolean
71
117
         */
72
 
        var $ignore = false;
73
 
 
74
 
        /**
75
 
         * Remote address (IP).
76
 
         * @var string
77
 
         */
78
 
        var $IP;
79
 
 
80
 
        /**
81
 
         * The user agent.
82
 
         * @see Hit::get_user_agent()
83
 
         * @access protected
84
 
         * @var string
85
 
         */
86
 
        var $user_agent;
87
 
 
 
118
        var $logged = false;
88
119
        /**
89
120
         * The user agent name, eg "safari"
90
121
         * @see Hit::get_agent_name()
91
 
         * @access protected
92
122
         * @var string
93
123
         */
94
124
        var $agent_name;
95
 
 
96
 
        /**
97
 
         * The user agent platform, eg "mac"
98
 
         * @see Hit::get_agent_platform()
99
 
         * @access protected
100
 
         * @var string
101
 
         */
102
 
        var $agent_platform;
103
 
 
104
 
 
105
125
        /**
106
126
         * The user's remote host.
107
127
         * Use {@link get_remote_host()} to access it (lazy filled).
108
128
         * @var string
109
 
         * @access protected
110
129
         */
111
130
        var $_remoteHost;
112
 
 
113
 
        /**
114
 
         * The user agent type.
115
 
         *
116
 
         * The default setting ('unknown') is taken for new entries (into T_useragents),
117
 
         * that are not detected as 'rss', 'robot' or 'browser'.
118
 
         * 'rss'|'robot'|'browser'|'unknown'
119
 
         *
120
 
         * @see Hit::get_agent_type()
121
 
         * @access protected
122
 
         * @var string
123
 
         */
124
 
        var $agent_type;
125
 
 
126
131
        /**
127
132
         * The ID of the user agent entry in T_useragents.
128
133
         * @see Hit::get_agent_ID()
129
 
         * @access protected
130
134
         * @var integer
131
135
         */
132
136
        var $agent_ID;
133
 
 
134
 
 
135
137
        /**
136
138
         * Extracted from search referers:
137
139
         */
138
140
        var $_extracted_keyphrase = false;
 
141
        /**
 
142
         * FIX THIS
 
143
         * @var foo
 
144
         */
139
145
        var $_keyphrase = NULL;
 
146
        /**
 
147
         * FIX THIS
 
148
         * @var foo
 
149
         */
140
150
        var $_extracted_serprank = false;
141
 
        var $_serprank = NULL;
142
151
 
143
152
 
144
153
        /**
151
160
                // Get the first IP in the list of REMOTE_ADDR and HTTP_X_FORWARDED_FOR
152
161
                $this->IP = get_ip_list( true );
153
162
 
154
 
                // Check the REFERER and determine referer_type:
155
 
                // TODO: dh> move this out of here, too, only if "antispam_block_spam_referers" is true,
156
 
                // do something about it (here or somewhere else, but early).
 
163
                // Check the REFERER and determine referer_type
 
164
                // @todo (0000) dh> move this out of here, too, only if "antispam_block_spam_referers"
 
165
                // is true, do something about it (here or somewhere else, but early).
157
166
                $this->detect_referer(); // May EXIT if we are set up to block referer spam.
158
167
        }
159
168
 
160
169
 
161
170
        /**
162
171
         * Detect admin page
 
172
         *
 
173
         * We are inside of admin, this supersedes 'direct' access.
 
174
         * NOTE: this is not really a referer type but more a hit type
163
175
         */
164
176
        function detect_admin_page()
165
177
        {
166
178
                if( is_admin_page() )
167
179
                {
168
 
                        // We are inside of admin, this supersedes 'direct' access
169
 
                        // NOTE: this is not really a referer type but more a hit type
170
180
                        $this->referer_type = 'admin';
171
181
                        return true;
172
182
                }
175
185
 
176
186
 
177
187
        /**
178
 
         * Detect Referer (sic!).
179
 
         * Due to potential non-thread safety with getenv() (fallback), we'd better do this early.
 
188
         * Detect Referer (sic!)
180
189
         *
181
 
         * referer_type: enum('search', 'blacklist', 'referer', 'direct'); 'spam' gets used internally
 
190
         * Due to potential non-thread safety with getenv() (fallback), we'd better do
 
191
         * this early. referer_type: enum('search', 'blacklist', 'referer', 'direct');
 
192
         * 'spam' gets used internally
182
193
         */
183
194
        function detect_referer()
184
195
        {
185
 
                global $HTTP_REFERER; // might be set by PHP (give highest priority)
 
196
                global $blackList;
186
197
                global $debug;
187
 
                global $self_referer_list, $blackList, $search_engines;  // used to detect $referer_type
 
198
                global $HTTP_REFERER; // might be set by PHP
 
199
                global $search_engines;
 
200
                global $self_referer_list;
 
201
                global $Settings;
188
202
                global $templates_path;
189
 
                global $Settings;
190
203
 
 
204
                // detect the referer if possible
191
205
                if( isset( $HTTP_REFERER ) )
192
206
                {
193
207
                        // Referer provided by PHP
195
209
                }
196
210
                else
197
211
                {
198
 
                        if( isset($_SERVER['HTTP_REFERER']) )
 
212
                        // use _SERVER if we can get something
 
213
                        if( isset( $_SERVER['HTTP_REFERER'] ) )
199
214
                        {
200
215
                                $this->referer = $_SERVER['HTTP_REFERER'];
201
216
                        }
202
217
                        else
203
218
                        {
204
 
                                // Fallback method (not thread safe :[[ ) - this function does not work in ISAPI mode
 
219
                                // Fallback method (not thread safe), this function does not work in ISAPI mode
205
220
                                $this->referer = getenv('HTTP_REFERER');
206
221
                        }
207
222
                }
208
223
 
209
 
                if( empty($this->referer) )
 
224
                // still no referer?
 
225
                if( empty( $this->referer ) )
210
226
                {
211
 
                        // NO referer
212
227
                        // This type may be superseeded and set to 'admin'
213
228
                        if( ! $this->detect_admin_page() )
214
229
                        {
215
 
                                // Not an admin page
 
230
                                // Not an admin page, assume 'direct'
216
231
                                $this->referer_type = 'direct';
217
232
                        }
218
233
                        return;
219
234
                }
220
235
 
221
 
                // ANALYZE referer...
222
 
 
223
 
                // Check self referer list, see {@link $self_referer_list}
224
 
                // fplanque: we log these (again), because if we didn't we woudln't detect
225
 
                // reloads on these... and that would be a problem!
 
236
                // Check self referer list (see $self_referer_list)
 
237
                // fplanque: we log these (again), because if we didn't we wouldn't detect
 
238
                // reloads on these ... and that would be a problem!
226
239
                foreach( $self_referer_list as $self_referer )
227
240
                {
228
241
                        $pos = strpos( $this->referer, $self_referer );
229
242
                        // If not starting within in the first 12 chars it's probably an url param as in &url=http://this_blog.com
230
 
                        if( $pos !== false && $pos <= 12
231
 
                                && ! ($debug && strpos( $this->referer, '/search.html' ) ) ) // search simulation
 
243
                        if( $pos !== false && $pos <= 12 && ! ( $debug && strpos( $this->referer, '/search.html' ) ) )
232
244
                        {
233
 
                                // This type may be superseeded by admin page
 
245
                                // This type may be superceded by admin page
234
246
                                if( ! $this->detect_admin_page() )
235
247
                                {
236
 
                                        // Not an admin page
 
248
                                        // Not an admin page, must be self
237
249
                                        $this->referer_type = 'self';
238
250
                                }
239
251
                                return;
240
252
                        }
241
253
                }
242
254
 
243
 
 
244
 
                // Check blacklist, see {@link $blackList}
245
 
                // NOTE: This is NOT the antispam!!
 
255
                // Check blacklist, see {@link $blackList} NOTE: This is NOT the antispam!!
246
256
                // fplanque: we log these (again), because if we didn't we woudln't detect
247
 
                // reloads on these... and that would be a problem!
 
257
                // reloads on these ... and that would be a problem!
248
258
                foreach( $blackList as $lBlacklist )
249
259
                {
250
260
                        $pos = strpos( $this->referer, $lBlacklist );
251
261
                        // If not starting within in the first 12 chars it's probably an url param as in &url=http://this_blog.com
252
262
                        if( $pos !== false && $pos <= 12 )
253
263
                        {
254
 
                                // This type may be superseeded by admin page
255
 
                                // fp> 2009-05-10: because of the 12 char limit above the following is probably no longer needed. Please enable it back if anyone has a problem with admin being detected as blacklist
256
 
                                // if( ! $this->detect_admin_page() )
 
264
                                if( ! $this->detect_admin_page() )
257
265
                                {
258
 
                                        // Not an admin page
 
266
                                        // Not an admin page:
259
267
                                        $this->referer_type = 'blacklist';
260
268
                                }
261
269
                                return;
262
270
                        }
263
271
                }
264
272
 
265
 
 
266
273
                // Check if the referer is valid and does not match the antispam blacklist:
267
 
                // NOTE: requests to admin pages should not arrive here, because they should be matched above through $self_referer_list!
268
 
                if( $error = validate_url( $this->referer, 'commenting' ) )
 
274
                // NOTE: requests to admin pages should not arrive here, because they
 
275
                // should be matched above through $self_referer_list!
 
276
                if( $error = validate_url( $this->referer, 'commenting', true, 'referers' ) )
269
277
                {
270
278
                        // This is most probably referer spam!!
271
279
                        $this->referer_type = 'spam';
272
 
 
273
 
                        if( $Settings->get('antispam_block_spam_referers') )
 
280
                        // In order to preserve server resources, we're going to stop processing immediatly (no logging)!!
 
281
                        if( $Settings->get( 'antispam_block_spam_referers' ) )
274
282
                        {
275
 
                                // In order to preserve server resources, we're going to stop processing immediatly (no logging)!!
276
283
                                require $templates_path.'_403_referer_spam.main.php'; // error & exit
277
284
                                exit(0); // just in case.
278
 
                                // THIS IS THE END!!
279
285
                        }
280
 
 
281
 
                        return; // type "spam"
 
286
                        return;
282
287
                }
283
288
 
284
 
 
285
289
                // Is the referer a search engine?
286
290
                // Note: for debug simulation, you may need to add sth like $search_engines[] = '/credits.html'; into the conf
287
291
                foreach( $search_engines as $lSearchEngine )
288
292
                {
289
 
                        if( stristr($this->referer, $lSearchEngine) ) // search simulation
 
293
                        if( stristr( $this->referer, $lSearchEngine ) ) // search simulation
290
294
                        {
291
295
                                $this->referer_type = 'search';
292
296
                                return;
445
449
                /*
446
450
                 * Detect requests for XML feeds by $template / $viewmode param.
447
451
                 *
448
 
                 * Use $template, if not empty (may be set in /qp_srvc/atom.php
449
 
                 * for example), otherwise $viewmode (and if that isn't set, $tempskin
450
 
                 * for b2evolution backward compatiblity).
 
452
                 * Use $template, if not empty (may be set in /qp_srvc/atom.php for example),
 
453
                 * otherwise $viewmode (and if that isn't set, $tempskin for b2evolution
 
454
                 * backward compatiblity).
451
455
                 *
452
 
                 * @todo (0000): fp> this is WEAK! Do we really need to know before going into the template?
453
 
                 * dh> not necessary, but only where ->agent_type gets used (logging).
454
 
                 * @todo (0000): It would be less "weak" to call Template::get_default_type(), but that
 
456
                 * @todo (0000) fp> this is WEAK! Do we really need to know before going into
 
457
                 * the template? dh> not necessary, but only where ->agent_type gets used (logging).
 
458
                 * @todo (0000) It would be less "weak" to call Template::get_default_type(), but that
455
459
                 * would mean having to instantiate a Template object! Another possibility: Use PHP's
456
460
                 * magic __get() method. I think combining both approaches would be a good solution
457
461
                 * (perhaps we could simply check whether the template name begins with an underscore?
458
462
                 * That would avoid having to instantiate a Template object (hmm, isn't that done
459
 
                 *  in qp_inc/_blog_main.inc.php anyway?).
 
463
                 * in qp_inc/_blog_main.inc.php anyway?).
460
464
                 */
461
465
                if( ! empty( $template ) )
462
466
                {
489
493
        /**
490
494
         * Log a hit on a blog page / rss feed
491
495
         *
492
 
         * This function should be called at the end of the page, otherwise if the page is
493
 
         * displaying previous hits, it may display the current one too. The hit will not be
494
 
         * logged in special occasions, see {@link $ignore} and {@link is_good_hit()}. It will
495
 
         * call {@link Hitlist::dbprune()} to do the automatic pruning of old hits in case of
496
 
         * auto_prune_stats_mode == "page".
 
496
         * This function should be called at the end of the page, otherwise if the page
 
497
         * is displaying previous hits, it may display the current one too. The hit will
 
498
         * not be logged in special occasions, see {@link $ignore} and {@link is_good_hit()}.
 
499
         * It will call {@link Hitlist::dbprune()} to do the automatic pruning of old
 
500
         * hits in case of auto_prune_stats_mode == "page".
 
501
         *
497
502
         * @uses Log::should_be_logged()
498
503
         * @uses Log::record_the_hit()
499
504
         * @return boolean true if the hit gets logged; false if not
568
573
 
569
574
 
570
575
        /**
571
 
         * This records the hit. You should not call this directly, but {@link Hit::log()} instead!
 
576
         * This records the hit
572
577
         *
573
 
         * However, if a Plugin registers the {@link Plugin::AppendHitLog() AppendHitLog event}, it
574
 
         * could be necessary to call this as a shutdown function.
 
578
         * You should not call this directly, but {@link Hit::log()} instead! However,
 
579
         * if a Plugin registers the {@link Plugin::AppendHitLog() AppendHitLog event},
 
580
         * it could be necessary to call this as a shutdown function.
575
581
         */
576
582
        function record_the_hit()
577
583
        {
591
597
                        if( ! is_numeric( $blog ) )
592
598
                        {
593
599
                                // this can be anything given by URL param "blog"! (because it's called on shutdown)
594
 
                          // see todo in param().
 
600
                                // see todo in param().
595
601
                                $blog = NULL;
596
602
                        }
597
603
                        $blog_ID = $blog;
601
607
                        $blog_ID = NULL;
602
608
                }
603
609
 
604
 
                $hit_uri = substr( $ReqURI, 0, 250 ); // VARCHAR(250) and likely to be longer
605
 
                $hit_referer = substr( $this->referer, 0, 250 ); // VARCHAR(250) and likely to be longer
 
610
                // VARCHAR(250) and likely to be longer
 
611
                $hit_uri = substr( $ReqURI, 0, 250 );
 
612
                // VARCHAR(250) and likely to be longer
 
613
                $hit_referer = substr( $this->referer, 0, 250 );
606
614
 
607
 
                // Extract the keyphrase from search referers:
 
615
                // Extract the keyphrase from search referers
608
616
                $keyphrase = $this->get_keyphrase();
609
617
 
610
618
                $keyp_ID = NULL;
623
631
                        }
624
632
                }
625
633
 
626
 
                // Extract the serprank from search referers:
 
634
                // Extract the serprank from search referers
627
635
                $serprank = $this->get_serprank();
628
636
 
629
 
                // insert hit into DB table:
630
 
                $sql = "
631
 
                        INSERT INTO T_hitlog(
632
 
                                hit_sess_ID, hit_datetime, hit_uri, hit_referer_type,
633
 
                                hit_referer, hit_referer_dom_ID, hit_keyphrase_keyp_ID, hit_serprank, hit_blog_ID, hit_remote_addr, hit_agnt_signature, hit_agnt_type )
 
637
                // insert hit into DB table
 
638
                $sql = "INSERT INTO T_hitlog(
 
639
                        hit_sess_ID, hit_datetime, hit_uri, hit_referer_type,
 
640
                        hit_referer, hit_referer_dom_ID, hit_keyphrase_keyp_ID, hit_serprank, hit_blog_ID, hit_remote_addr, hit_agnt_signature, hit_agnt_type )
634
641
                        VALUES( '".$Session->ID."', FROM_UNIXTIME(".$localtimenow."), '".$DB->escape( $hit_uri )."', '".$this->referer_type
635
 
                                ."', '".$DB->escape( $hit_referer )."', ".$DB->null( $this->get_referer_domain_ID() ).', '.$DB->null( $keyp_ID )
636
 
                                .', '.$DB->null( $serprank ).', '.$DB->null( $blog_ID ).", '".$DB->escape( $this->IP )."', ".$DB->quote( $this->get_user_agent() ).", ".$DB->quote( $this->get_agent_type() ).'
637
 
                        )';
 
642
                        ."', '".$DB->escape( $hit_referer )."', ".$DB->null( $this->get_referer_domain_ID() ).', '.$DB->null( $keyp_ID )
 
643
                        .', '.$DB->null( $serprank ).', '.$DB->null( $blog_ID ).", '".$DB->escape( $this->IP )."', ".$DB->quote( $this->get_user_agent() ).", ".$DB->quote( $this->get_agent_type() ).'
 
644
                )';
638
645
 
639
646
                $DB->query( $sql, 'Record the hit' );
640
647
 
691
698
 
692
699
 
693
700
        /**
694
 
         * Get the User agent's signature.
 
701
         * Get the User agent's signature
695
702
         *
696
703
         * @return string False, if not provided or empty, if it included tags.
697
704
         */
729
736
 
730
737
 
731
738
        /**
732
 
         * Get the User agent's name.
 
739
         * Get the User agent's name
733
740
         *
734
741
         * @return string
735
742
         */
744
751
 
745
752
 
746
753
        /**
747
 
         * Get the User agent's platform.
 
754
         * Get the User agent's platform
748
755
         *
749
756
         * @return string
750
757
         */
759
766
 
760
767
 
761
768
        /**
762
 
         * Get the User agent's type.
 
769
         * Get the User agent's type
763
770
         *
764
771
         * @return string
765
772
         */
775
782
 
776
783
 
777
784
        /**
778
 
         * Get the remote hostname.
 
785
         * Get the remote hostname
779
786
         *
780
787
         * @return string
781
788
         */
793
800
                        }
794
801
                        elseif( $allow_nslookup )
795
802
                        {
796
 
                                // We allowed reverse DNS lookup
797
 
                                // This can be terribly time consuming (4/5 seconds!) when there is no reverse dns available!
798
 
                                // This is the case on many intranets and many users' first time installs!!!
799
 
                                // Some people end up considering the application core is very slow just because of this line!
800
 
                                // This cannot be enabled by default.
 
803
                                // We allowed reverse DNS lookup. This can be terribly time consuming (4/5 seconds!)
 
804
                                // when there is no reverse dns available! This is the case on many intranets
 
805
                                // and many users' first time installs!!! Some people end up considering 
 
806
                                // the application core is very slow just because of this line! This cannot
 
807
                                // be enabled by default.
801
808
                                $this->_remoteHost = @gethostbyaddr( $this->IP );
802
809
                        }
803
810
                        else
813
820
 
814
821
 
815
822
        /**
816
 
         * Determine if a hit is a new view (not reloaded or from a robot).
817
 
         *
818
 
         * 'Reloaded' means: visited before from the same user (in a session) or from same
819
 
         * IP/user_agent in the last {@link $Settings reloadpage_timeout} seconds.
820
 
         *
821
 
         * This gets queried by the Item objects before incrementing its view count (if the Item
822
 
         * gets viewed in total ({@link $dispmore})).
823
 
         *
824
 
         * @todo (0000): if this is only useful to display who's online or view counts, provide
825
 
         * option to disable all those resource consuming gadgets. (Those gadgets should be
826
 
         * plugins actually, and they should enable this query only if needed)
 
823
         * Determine if a hit is a new view (not reloaded or from a robot)
 
824
         *
 
825
         * 'Reloaded' means: visited before from the same user (in a session) or from
 
826
         * same IP/user_agent in the last {@link $Settings reloadpage_timeout} seconds.
 
827
         *
 
828
         * This gets queried by the Item objects before incrementing its view count (if
 
829
         * the Item gets viewed in total ({@link $dispmore})).
 
830
         *
 
831
         * @todo (0000) if this is only useful to display who's online or view counts,
 
832
         * provide option to disable all those resource consuming gadgets. (Those gadgets
 
833
         * should be plugins actually, and they should enable this query only if needed)
827
834
         * blueyed>> Move functionality to Plugin (with a hook in Item::content())?!
828
835
         * @return boolean
829
836
         */
846
853
                        // Restrict to current user if logged in
847
854
                        if( ! empty( $current_User->ID ) )
848
855
                        {
849
 
                                // select by user ID: one user counts really just once. May be even faster than the anonymous query below..!?
 
856
                                // select by user ID: one user counts really just once. May be even faster
 
857
                                // than the anonymous query below!?
850
858
                                $sql = "
851
859
                                        SELECT hit_ID FROM T_hitlog INNER JOIN T_sessions ON hit_sess_ID = sess_ID
852
 
                                         WHERE sess_user_ID = ".$current_User->ID."
853
 
                                                 AND hit_uri = '".$DB->escape( substr( $ReqURI, 0, 250 ) )."'
854
 
                                         LIMIT 1";
 
860
                                        WHERE sess_user_ID = ".$current_User->ID."
 
861
                                        AND hit_uri = '".$DB->escape( substr( $ReqURI, 0, 250 ) )."'
 
862
                                        LIMIT 1";
855
863
                        }
856
864
                        else
857
865
                        {
858
866
                                // select by remote_addr/agnt_signature
859
867
                                $sql = "
860
868
                                        SELECT hit_ID
861
 
                                          FROM T_hitlog
862
 
                                         WHERE hit_datetime > '".date( 'Y-m-d H:i:s', $localtimenow - $Settings->get('reloadpage_timeout') )."'
863
 
                                           AND hit_remote_addr = ".$DB->quote( $this->IP )."
864
 
                                           AND hit_uri = '".$DB->escape( substr( $ReqURI, 0, 250 ) )."'
865
 
                                           AND hit_agnt_signature = ".$DB->quote( $this->get_user_agent() )."
866
 
                                         LIMIT 1";
 
869
                                        FROM T_hitlog
 
870
                                        WHERE hit_datetime > '".date( 'Y-m-d H:i:s', $localtimenow - $Settings->get('reloadpage_timeout') )."'
 
871
                                        AND hit_remote_addr = ".$DB->quote( $this->IP )."
 
872
                                        AND hit_uri = '".$DB->escape( substr( $ReqURI, 0, 250 ) )."'
 
873
                                        AND hit_agnt_signature = ".$DB->quote( $this->get_user_agent() )."
 
874
                                        LIMIT 1";
867
875
                        }
868
876
                        if( $DB->get_var( $sql, 0, 0, 'Hit: Check for reload' ) )
869
877
                        {
870
 
                                $this->_is_new_view = false;  // We don't want to log this hit again
 
878
                                $this->_is_new_view = false; // We don't want to log this hit again
871
879
                        }
872
880
                        else
873
881
                        {
900
908
        /**
901
909
         * Extract the keyphrase from a search engine referer url
902
910
         *
903
 
         * Typically http://google.com?s=keyphraz returns keyphraz
 
911
         * Typically http://google.com?s=keyphraz returns keyphrase
 
912
         *
904
913
         * @param string referer
905
914
         * @return string keyphrase
906
915
         */
914
923
                        return NULL;
915
924
                }
916
925
 
917
 
                $known_search_params =  array(
918
 
                                        'q',
919
 
                                        'as_q',         // Google Advanced Search Query
920
 
                                        'as_epq',       // Google Advanced Search Query
921
 
                                        'query',
922
 
                                        'search',
923
 
                                        's',            // google.co.uk
924
 
                                        'p',
925
 
                                        'kw',
926
 
                                        'qs',
927
 
                                        'searchfor',    // mysearch.myway.com
928
 
                                        'r',
929
 
                                        'rdata',        // search.ke.voila.fr
930
 
                                        'string',       // att.net
931
 
                                        'su',           // suche.web.de
932
 
                                        'Gw',           // scroogle.org
933
 
                                        'text',         // yandex.ru
934
 
                                );
 
926
                $known_search_params = array(
 
927
                        'q',
 
928
                        'as_q', // Google Advanced Search Query
 
929
                        'as_epq', // Google Advanced Search Query
 
930
                        'query',
 
931
                        'search',
 
932
                        's', // google.co.uk
 
933
                        'p',
 
934
                        'kw',
 
935
                        'qs',
 
936
                        'searchfor', // mysearch.myway.com
 
937
                        'r',
 
938
                        'rdata', // search.ke.voila.fr
 
939
                        'string', // att.net
 
940
                        'su', // suche.web.de
 
941
                        'Gw', // scroogle.org
 
942
                        'text', // yandex.ru
 
943
                );
935
944
 
936
945
                $ref_params = explode( '&', app_substr( $ref, $pos_question+1 ) );
937
946
                foreach( $ref_params as $ref_param )
954
963
         * Extract the "serp rank" from a search engine referer url
955
964
         *
956
965
         * Typically http://google.com?s=keyphraz&start=18 returns 18
 
966
         *
957
967
         * @param string referer
958
968
         * @return string keyphrase
959
969
         */
970
980
 
971
981
        /**
972
982
         * Is this Lynx?
 
983
         *
973
984
         * @return boolean
974
985
         */
975
986
        function is_lynx()
976
987
        {
977
988
                if( ! isset( $this->is_lynx ) )
 
989
                {
978
990
                        $this->detect_useragent();
 
991
                }
979
992
                return $this->is_lynx;
980
993
        }
981
994
 
982
995
        /**
983
996
         * Is this Firefox?
 
997
         *
984
998
         * @return boolean
985
999
         */
986
1000
        function is_firefox()
987
1001
        {
988
1002
                if( ! isset( $this->is_firefox ) )
 
1003
                {
989
1004
                        $this->detect_useragent();
 
1005
                }
990
1006
                return $this->is_firefox;
991
1007
        }
992
1008
 
993
1009
        /**
994
1010
         * Is this Gecko?
 
1011
         *
995
1012
         * @return boolean
996
1013
         */
997
1014
        function is_gecko()
998
1015
        {
999
1016
                if( ! isset( $this->is_gecko ) )
 
1017
                {
1000
1018
                        $this->detect_useragent();
 
1019
                }
1001
1020
                return $this->is_gecko;
1002
1021
        }
1003
1022
 
1004
1023
        /**
1005
1024
         * Is this WinIE?
 
1025
         *
1006
1026
         * @return boolean
1007
1027
         */
1008
1028
        function is_winIE()
1009
1029
        {
1010
1030
                if( ! isset( $this->is_winIE ) )
 
1031
                {
1011
1032
                        $this->detect_useragent();
 
1033
                }
1012
1034
                return $this->is_winIE;
1013
1035
        }
1014
1036
 
1015
1037
        /**
1016
1038
         * Is this MacIE?
 
1039
         *
1017
1040
         * @return boolean
1018
1041
         */
1019
1042
        function is_macIE()
1020
1043
        {
1021
1044
                if( ! isset( $this->is_macIE ) )
 
1045
                {
1022
1046
                        $this->detect_useragent();
 
1047
                }
1023
1048
                return $this->is_macIE;
1024
1049
        }
1025
1050
 
1026
1051
        /**
1027
1052
         * Is this Safari?
 
1053
         *
1028
1054
         * @return boolean
1029
1055
         */
1030
1056
        function is_safari()
1031
1057
        {
1032
1058
                if( ! isset( $this->is_safari ) )
 
1059
                {
1033
1060
                        $this->detect_useragent();
 
1061
                }
1034
1062
                return $this->is_safari;
1035
1063
        }
1036
1064
 
1037
1065
        /**
1038
1066
         * Is this Opera?
 
1067
         *
1039
1068
         * @return boolean
1040
1069
         */
1041
1070
        function is_opera()
1042
1071
        {
1043
1072
                if( ! isset( $this->is_opera ) )
 
1073
                {
1044
1074
                        $this->detect_useragent();
 
1075
                }
1045
1076
                return $this->is_opera;
1046
1077
        }
1047
1078
 
1048
1079
        /**
1049
1080
         * Is this Netscape4?
 
1081
         *
1050
1082
         * @return boolean
1051
1083
         */
1052
1084
        function is_NS4()
1053
1085
        {
1054
1086
                if( ! isset( $this->NS4 ) )
 
1087
                {
1055
1088
                        $this->detect_useragent();
 
1089
                }
1056
1090
                return $this->is_NS4;
1057
1091
        }
 
1092
 
1058
1093
}
1059
1094
 
1060
1095
?>