Пример #1
0
function cached_editlogbin($formatter, $params = array())
{
    global $Config, $DBInfo;
    $cache = new Cache_Text('editlogbin');
    if (!empty($params['title'])) {
        if (!$DBInfo->hasPage($params['title'])) {
            unset($params['title']);
        }
    }
    $args = array();
    $user = !empty($params['q']) ? $params['q'] : '';
    $start = !empty($params['start']) ? $params['start'] : '';
    $domain = !empty($params['domain']) ? $params['domain'] : '';
    $title = !empty($params['title']) ? $params['title'] : '';
    // get timestamp
    $oldest_stamp = !empty($params['.oldest']) ? strtotime($params['.oldest']) : strtotime('-1 year');
    // round timestamp
    $tmp = date('Y-m-d 00:00:00', $oldest_stamp);
    $oldest_stamp = strtotime($tmp);
    if (!empty($start)) {
        if (is_numeric($start)) {
            // timestamp
            $from = $start;
        } else {
            $from = strtotime($start);
        }
        // convert to timestamp
    } else {
        $from = !empty($params['.max_range']) ? strtotime('-' . $params['.max_range']) : strtotime('-1 year');
        // restrict range
        $params['until'] = null;
        // reset
    }
    // round timestamp
    $tmp = date('Y-m-d 23:59:59', $from);
    $from = strtotime($tmp);
    $max_range = !empty($params['.max_range']) ? strtotime($params['.max_range'], $from) : strtotime('1 year', $from);
    $params['until'] = $max_range;
    if ($params['until'] > time()) {
        $params['until'] = null;
    }
    //echo date('Y.m.d H.i.s', $params['until']);
    $mtime = $DBInfo->mtime();
    $key = $user . '.' . $from . '.' . $domain . '.' . $title . $mtime;
    if (empty($formatter->refresh) && ($data = $cache->fetch($key)) !== false) {
        return $data;
    }
    $fp = fopen($Config['editlog_name'], 'r');
    $seek = _editlog_seek($fp, $from);
    $data = _editlog_binning($fp, $seek, $from, 60 * 60 * 24, $params);
    fclose($fp);
    $cache->update($key, $data, 60 * 60 * 24);
    // TTL to 24 hour
    return $data;
}
Пример #2
0
function do_editlogbin($formatter, $params = array())
{
    global $Config, $DBInfo;
    $cache = new Cache_Text('editlogbin');
    if (!empty($params['title'])) {
        if (!$DBInfo->hasPage($params['title'])) {
            unset($params['title']);
        }
    }
    $args = array();
    $user = !empty($params['q']) ? $params['q'] : '';
    $start = !empty($params['start']) ? $params['start'] : '';
    $domain = !empty($params['domain']) ? $params['domain'] : '';
    $title = !empty($params['title']) ? $params['title'] : '';
    // get timestamp
    $oldest_stamp = !empty($Config['editlogbin_datetime_oldest']) ? strtotime($Config['editlogbin_datetime_oldest']) : strtotime('-1 year');
    if ($oldest_stamp < strtotime('-10 years')) {
        // too old
        $oldest_stamp = strtotime('-1 year');
    }
    if (!empty($start)) {
        if (is_numeric($start)) {
            // timestamp
            $from = $start;
        } else {
            $from = strtotime($start);
        }
        // convert to timestamp
    } else {
        $from = $oldest_stamp;
    }
    // restrict range
    $params['until'] = null;
    // reset
    if ($from < $oldest_stamp) {
        $max_range = !empty($Config['editlogbin_datetime_max_range']) ? strtotime($Config['editlogbin_datetime_max_range'], $from) : strtotime('1 year', $from);
        $params['until'] = $max_range;
    }
    //echo date('Y.m.d H.i.s', $params['until']);
    $mtime = $DBInfo->mtime();
    $key = $user . '.' . $from . '.' . $domain . '.' . $title . $mtime;
    if (empty($formatter->refresh) && ($val = $cache->fetch($key)) !== false) {
        header('Content-Type: text/plain');
        echo json_encode($val['data']);
        return;
    }
    $fp = fopen($Config['editlog_name'], 'r');
    $seek = _editlog_seek($fp, $from);
    $data = _editlog_binning($fp, $seek, $from, 60 * 60 * 24, $params);
    fclose($fp);
    header('Content-Type: text/plain');
    $cache->update($key, $data, 60 * 60 * 24);
    // TTL to 24 hour
    echo json_encode($data['data']);
}