示例#1
0
文件: surfer.php 项目: rair/yacs
 /**
  * update surfer presence
  *
  * This function is used to track presence information.
  * Errors are not reported, if any
  *
  * @param string web address of visited page
  * @param string related title
  * @param string the target anchor, if any
  * @param string level of visibility for this anchor (e.g., 'Y', 'R' or 'N')
  */
 public static function is_visiting($link, $label, $anchor = NULL, $active = 'Y')
 {
     global $context;
     // don't track crawlers
     if (Surfer::is_crawler()) {
         return;
     }
     // update the history stack
     if (!isset($context['pages_without_history']) || $context['pages_without_history'] != 'Y') {
         // put at top of stack
         if (!isset($_SESSION['visited'])) {
             $_SESSION['visited'] = array();
         }
         $_SESSION['visited'] = array_merge(array($link => $label), $_SESSION['visited']);
         // limit to 20 most recent pages
         if (count($_SESSION['visited']) > 20) {
             array_pop($_SESSION['visited']);
         }
     }
     // no anchor to remember
     if (!$anchor) {
         return;
     }
     // ensure regular operation of the server
     if (!file_exists($context['path_to_root'] . 'parameters/switch.on')) {
         return;
     }
     // nothing remembered for anonymous surfers
     if (!Surfer::get_id()) {
         return;
     }
     // we need a GET
     if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] != 'GET') {
         return;
     }
     // Firefox pre-fetch is not a real visit
     if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
         return;
     }
     // ensure the back-end is there
     if (!is_callable(array('SQL', 'query'))) {
         return;
     }
     // update the record of the surfer
     $query = "UPDATE " . SQL::table_name('users') . " SET click_anchor='" . SQL::escape($anchor) . "', click_date='" . gmstrftime('%Y-%m-%d %H:%M:%S') . "'" . " WHERE id = " . SQL::escape(Surfer::get_id());
     SQL::query($query, FALSE, $context['users_connection']);
     // also update recent visits
     include_once $context['path_to_root'] . 'users/visits.php';
     Visits::track($anchor, $active);
     // job done
     return;
 }
示例#2
0
文件: visit.php 项目: rair/yacs
// get the related anchor, if any
if ($anchor) {
    $anchor = Anchors::get($anchor);
}
// required to format the roster
load_skin('users');
// stop crawlers
if (Surfer::is_crawler()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // an anchor is mandatory
} elseif (!is_object($anchor)) {
    Safe::header('Status: 404 Not Found', TRUE, 404);
    die(i18n::s('No anchor has been found.'));
    // provide updated information for this anchor
} else {
    // silently record this visit
    Visits::track($anchor->get_reference(), $anchor->get_active());
    // return an updated list of current visitors, to be used in AJAX
    $output = Visits::list_users_at_anchor($anchor->get_reference());
    // ensure we are producing some text -- open links in separate pages
    if (is_array($output)) {
        $output =& Skin::build_list($output, 'compact', NULL, TRUE);
    }
    // actual transmission except on a HEAD request
    if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'HEAD') {
        echo $output;
    }
    // the post-processing hook, then exit
    finalize_page(TRUE);
}