ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/BBClone/trunk/mark_page.php
Revision: 19
Committed: Thu Nov 21 13:14:22 2013 UTC (11 years ago) by matthys
File size: 5133 byte(s)
Log Message:
Setup svn keywords correctly.

File Contents

# User Rev Content
1 matthys 18 <?php
2     /* This file is part of BBClone (A PHP based Web Counter on Steroids)
3     *
4 matthys 19 * SVN FILE $Id$
5 matthys 18 *
6     * Copyright (C) 2001-2013, the BBClone Team (see doc/authors.txt for details)
7     *
8     * This program is free software: you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License as published by
10     * the Free Software Foundation, either version 3 of the License, or
11     * (at your option) any later version.
12     *
13     * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17     *
18     * See doc/copying.txt for details
19     */
20    
21     ////////////////////////////////
22     // Mark Page and Write to Var //
23     ////////////////////////////////
24    
25     if (!defined("_MARK_PAGE")) define("_MARK_PAGE", "1");
26     else return;
27    
28     // Check for PHP 4.0.3 or older
29     if (!function_exists("array_sum")) exit("<hr /><b>Error:</b> PHP ".PHP_VERSION." is too old for BBClone.");
30     elseif ((!defined("_BBCLONE_DIR")) || (!is_readable(_BBCLONE_DIR."constants.php"))) return;
31     else require_once(_BBCLONE_DIR."constants.php");
32    
33     foreach (array($BBC_LIB_PATH."io.php", $BBC_LIB_PATH."marker.php", $BBC_CONFIG_FILE) as $i) {
34     if (is_readable($i)) require_once($i);
35     else {
36     if (empty($BBC_DEBUG)) return;
37     else exit(bbc_msg($i));
38     }
39     }
40    
41     if (extension_loaded("sysvsem") && (stristr("sem", $BBC_USE_LOCK) !== false)) define("_BBC_SEM", 1);
42     if (extension_loaded("dio") && (stristr("dio", $BBC_USE_LOCK) !== false)) define("_BBC_DIO", 1);
43    
44     // locking method must not be empty
45     $BBC_USE_LOCK = empty($BBC_USE_LOCK) ? "flk" : $BBC_USE_LOCK;
46    
47     if (!function_exists("flock") && (stristr("flk", $BBC_USE_LOCK) !== false)) {
48     if (empty($BBC_DEBUG)) return;
49     else exit(bbc_msg("", "l"));
50     }
51    
52     if (!is_readable($BBC_CACHE_PATH)) {
53     if (empty($BBC_DEBUG)) return;
54     else exit(bbc_msg($BBC_CACHE_PATH));
55     }
56    
57     ignore_user_abort(1);
58    
59     // Don't write to counter files if we want to reset stats
60     if (empty($BBC_KILL_STATS)) {
61     // needs to be always executed because otherwise our counter wouldn't work
62     // any longer by the time $BBC_DEBUG was activated
63     $i = bbc_exec_marker();
64    
65     // Don't process anything unless we are told to do so
66     if (!defined("_OK")) {
67     if (empty($BBC_DEBUG)) return ignore_user_abort(0);
68     else exit($i);
69     }
70     else !empty($BBC_DEBUG) ? print($i) : "";
71     }
72    
73     foreach (array("ACCESS_FILE", "LAST_FILE", "LOCK") as $i) {
74     if (!is_readable(${"BBC_".$i})) {
75     if (empty($BBC_DEBUG)) return;
76     else exit(bbc_msg(${"BBC_".$i}));
77     }
78     if (!is_writable(${"BBC_".$i})) {
79     if (empty($BBC_DEBUG)) return;
80     else exit(bbc_msg(${"BBC_".$i}, "w"));
81     }
82     }
83    
84     // Kill'em all if requested and return
85     if (!empty($BBC_KILL_STATS)) {
86     bbc_kill_stats();
87    
88     if (empty($BBC_DEBUG)) return;
89     else exit(bbc_msg("", "k"));
90     }
91    
92     foreach (array($BBC_LOG_PROCESSOR, $BBC_LIB_PATH."new_connect.php", $BBC_LIB_PATH."timecalc.php",
93     $BBC_LIB_PATH."referrer.php", $BBC_LIB_PATH."charconv.php", $BBC_LIB_PATH."browser.php",
94     $BBC_LIB_PATH."os.php", $BBC_LIB_PATH."robot.php") as $i) {
95     if (!is_readable($i)) {
96     if (empty($BBC_DEBUG)) return;
97     else exit(bbc_msg($i));
98     }
99     }
100    
101     // Extension (country) look-up via plugin
102     if ($BBC_EXT_LOOKUP) {
103     $EXT_INCLUDE = $BBC_PLUGIN_PATH."ext_lookup_".strtolower($BBC_EXT_LOOKUP).".php";
104     if (!is_readable($EXT_INCLUDE)) {
105     if (empty($BBC_DEBUG)) return;
106     else exit(bbc_msg($EXT_INCLUDE));
107     }
108     require_once($EXT_INCLUDE);
109     }
110    
111     if (($BBC_TIMESTAMP <= filemtime($BBC_ACCESS_FILE)) || (function_exists("bbc_sort_time_sc"))) return;
112     clearstatcache();
113    
114     if (filesize($BBC_LOCK) !== 0) {
115     // crash recovery if lockfile is older than 30 secs
116     if ($BBC_TIMESTAMP - filemtime($BBC_LOCK) > 30) fclose(fopen($BBC_LOCK, "wb"));
117     return;
118     }
119    
120     // write to lockfile
121     if (($al = bbc_begin_write($BBC_LOCK, "1")) !== false) {
122     foreach (array($BBC_LOG_PROCESSOR, $BBC_LIB_PATH."new_connect.php", $BBC_LIB_PATH."timecalc.php",
123     $BBC_LIB_PATH."referrer.php", $BBC_LIB_PATH."charconv.php") as $i) require_once($i);
124    
125     require($BBC_ACCESS_FILE);
126     require($BBC_LAST_FILE);
127    
128     // global and time stats
129     if (bbc_add_new_connections_to_old()) {
130     $af = bbc_begin_write($BBC_ACCESS_FILE, "<?php\nglobal \$access;\n\$access =\n".bbc_array_to_str($access).";\n?>");
131    
132     bbc_end_write($af);
133     !empty($BBC_DEBUG) ? print(bbc_msg(basename($BBC_ACCESS_FILE), "o")) : "";
134     bbc_update_last_access();
135    
136     $af = bbc_begin_write($BBC_LAST_FILE, "<?php\nglobal \$last;\n\$last =\n".bbc_array_to_str($last).";\n?>");
137     bbc_end_write($af);
138     !empty($BBC_DEBUG) ? print(bbc_msg(basename($BBC_LAST_FILE), "o")) : "";
139     }
140     }
141     else (!empty($BBC_DEBUG) ? print(bbc_msg("", "l")) : "");
142    
143     // once we've finished we unlock and truncate the lock file
144     bbc_end_write($al);
145     fclose(fopen($BBC_LOCK, "wb"));
146     ignore_user_abort(0);
147    
148     // Exit if debug mode is turned on.
149     if (!empty($BBC_DEBUG)) exit();
150     ?>

Properties

Name Value
svn:keywords Id