public static function ProcessStats(&$p_statsOnly)
{
global $Campsite;
$p_statsOnly = false;
$output_html = ' ';
//looking whether the request is of form used for statistics, i.e.
//http(s)://newscoop_domain/(newscoop_dir/)_statistics(/...)(?...)
$path_request_parts = explode('?', $_SERVER['REQUEST_URI']);
$path_request = strtolower($path_request_parts[0]);
if ('' == $path_request || '/' != $path_request[strlen($path_request) - 1]) {
$path_request .= '/';
}
$campsite_subdir = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/', -2));
// the path prefix that should be considered when checking the statistics directory
// it is an empty string for domain based installations
$stat_start = strtolower($campsite_subdir);
if ('' == $stat_start || '/' != $stat_start[strlen($stat_start) - 1]) {
$stat_start .= '/';
}
// the path (as of request_uri) that is for the statistics part
$stat_start .= '_statistics/';
$stat_start_len = strlen($stat_start);
// if request_uri starts with the statistics path, it is just for the statistics things
if (substr($path_request, 0, $stat_start_len) == $stat_start) {
$p_statsOnly = true;
}
// if not on statistics, just return and let run the standard newscoop processing
if (!$p_statsOnly) {
return true;
}
// taking the statistics specification part of the request uri
$stat_info = substr($path_request, $stat_start_len);
$stat_info_arr = array();
foreach (explode('/', $stat_info) as $one_part) {
$one_part = trim($one_part);
// here we take that '0' is not valid id for any db object
if (!empty($one_part)) {
$stat_info_arr[] = $one_part;
}
}
$art_read_action = false;
// for now, the only known action is to update statistics on article readering, i.e. for
// uri path of form (/newscoop_path)/statistics/reader/article/object_id/?...
if (3 <= count($stat_info_arr)) {
if ('reader' == $stat_info_arr[0] && is_numeric($stat_info_arr[1])) {
$art_read_action = true;
}
}
if (!$art_read_action) {
return false;
}
// if the article was read by a user (incl. an anonymous one)
if ($art_read_action) {
$object_type_id = (int) $stat_info_arr[1];
$object_id = (int) $stat_info_arr[2];
$correct = self::WriteStats($object_type_id, $object_id);
if (!$correct) {
return false;
}
}
// end of the stats action on article reading
// the output string for stats only requests; nothing for now
echo $output_html;
// whether the stats processing was correct
// the return value not used actually anywhere now
return true;
}