Пример #1
0
/**
 *	check if two directories are different
 *
 *	@param string $a filename
 *	@param string $b filename
 *	@return bool
 */
function dir_is_different($a, $b)
{
    if (substr($a, -1) == '/') {
        $a = substr($a, 0, -1);
    }
    if (substr($b, -1) == '/') {
        $b = substr($b, 0, -1);
    }
    $a_fns = @scandir($a);
    $b_fns = @scandir($b);
    if ($a_fns !== $b_fns) {
        return true;
    }
    foreach ($a_fns as $fn) {
        if ($fn == '.' || $fn == '..') {
            continue;
        }
        if (is_dir($a . '/' . $fn) || is_dir($b . '/' . $fn)) {
            if (dir_is_different($a . '/' . $fn, $b . '/' . $fn)) {
                return true;
            }
        } else {
            if (file_is_different($a . '/' . $fn, $b . '/' . $fn)) {
                return true;
            }
        }
    }
    return false;
}
Пример #2
0
/**
 *	create and delete auto- revisions
 *
 *	this function operates on a specific page and takes SNAPSHOT_MIN_AGE and
 *	SNAPSHOT_MAX_AGE into account.
 *	@param array $args arguments
 *		key 'page' is the page (i.e. page.rev)
 *	@return array response
 *		true if successful
 */
function check_auto_snapshot($args)
{
    if (!isset($args['page'])) {
        return response('Required argument "page" missing', 400);
    }
    if (!page_exists($args['page'])) {
        return response('Page ' . quot($args['page']) . ' does not exist', 400);
    }
    $a = expl('.', $args['page']);
    $revs = revisions_info(array('pagename' => $a[0], 'sort' => 'time'));
    $revs = $revs['#data'];
    if ($a[1] == 'head' && SNAPSHOT_MIN_AGE != 0) {
        // we're dealing with a head revision and taking snapshots
        // find the previous auto- revision
        for ($i = 0; $i < count($revs); $i++) {
            if (substr($revs[$i]['revision'], 0, 5) == 'auto-') {
                // got it, check age
                if (time() - $revs[$i]['time'] < SNAPSHOT_MIN_AGE) {
                    log_msg('debug', 'check_auto_snapshot: age is ' . (time() - $revs[$i]['time']) . ' seconds, not creating a snapshot');
                    break;
                }
                // check if different
                if (dir_is_different(CONTENT_DIR . '/' . str_replace('.', '/', $args['page']), CONTENT_DIR . '/' . str_replace('.', '/', $revs[$i]['page']))) {
                    snapshot($args);
                } else {
                    log_msg('debug', 'check_auto_snapshot: head is identical to ' . $revs[$i]['revision'] . ', not creating a snapshot');
                }
                break;
            }
            if ($i == count($revs) - 1) {
                // no auto- revision?, create one now
                snapshot($args);
            }
        }
    }
    // delete old auto- revisions
    if (SNAPSHOT_MAX_AGE != 0) {
        for ($i = count($revs) - 1; 0 <= $i; $i--) {
            if (substr($revs[$i]['revision'], 0, 5) == 'auto-' && SNAPSHOT_MAX_AGE < time() - $revs[$i]['time']) {
                log_msg('info', 'check_auto_snapshot: deleting an old snapshot');
                delete_page(array('page' => $revs[$i]['page']));
                $i--;
            }
        }
    }
    return response(true);
}