function iframe_save_state($args)
{
    $elem = $args['elem'];
    $obj = $args['obj'];
    if (array_shift(elem_classes($elem)) != 'iframe') {
        return false;
    }
    // make sure the type is set
    $obj['type'] = 'iframe';
    $obj['module'] = 'iframe';
    // hook
    invoke_hook('alter_save', array('obj' => &$obj, 'elem' => $elem));
    load_modules('glue');
    $ret = save_object($obj);
    if ($ret['#error']) {
        log_msg('error', 'iframe_save_state: save_object returned ' . quot($ret['#data']));
        return false;
    } else {
        return true;
    }
}
Exemplo n.º 2
0
/**
 *	implements save_state
 */
function image_save_state($args)
{
    $elem = $args['elem'];
    $obj = $args['obj'];
    // only take responsibility for the element when we are its main class
    if (array_shift(elem_classes($elem)) != 'image') {
        return false;
    }
    // make sure the type is set
    $obj['type'] = 'image';
    $obj['module'] = 'image';
    // by convention the main retrieving of the elements properties takes
    // place in alter_state
    // this way other objects types may "derive" from this one
    // it also allows other modules to chime in
    // notice: obj is passed as reference here
    // obj might be (almost) empty for newly created objects, so rely only
    // on $elem
    invoke_hook('alter_save', array('obj' => &$obj, 'elem' => $elem));
    // see image_alter_save() above
    // we could do some overriding here if we wanted to
    // finally save the object
    load_modules('glue');
    $ret = save_object($obj);
    if ($ret['#error']) {
        log_msg('error', 'image_save_state: save_object returned ' . quot($ret['#data']));
        return false;
    } else {
        return true;
    }
}
Exemplo n.º 3
0
/**
 *	create a snapshot from a page
 *
 *	@param array $args arguments
 *		key 'page' page to shapshot (i.e. page.rev)
 *		key 'rev' (optional) new revision name (i.e. rev2) (if empty or not set 
 *			a revision starting with 'auto-' and the current date will be 
 *			created)
 *	@return array response (holding the page of the newly created revision 
 *		if successful)
 */
function snapshot($args)
{
    if (empty($args['page'])) {
        return response('Required argument "page" missing or empty', 400);
    }
    if (!page_exists($args['page'])) {
        return response('Page ' . quot($args['page']) . ' does not exist', 404);
    }
    // setup revision name
    $a = expl('.', $args['page']);
    if (empty($args['rev'])) {
        $args['rev'] = 'auto-' . date('YmdHis');
    } elseif (page_exists($a[0] . '.' . $args['rev'])) {
        return response('Revision ' . quot($args['rev']) . ' already exists', 400);
    } elseif (!valid_pagename($a[0] . '.' . $args['rev'])) {
        return response('Invalid revision ' . quot($args['rev']), 400);
    }
    // create revision
    $dest = CONTENT_DIR . '/' . $a[0] . '/' . $args['rev'];
    $m = umask(00);
    if (!@mkdir($dest)) {
        umask($m);
        return response('Error creating directory ' . quot($dest), 500);
    }
    umask($m);
    // copy files
    // we go through the files one by one in order to spot symlinks hiding
    $src = CONTENT_DIR . '/' . str_replace('.', '/', $args['page']);
    $files = scandir($src);
    foreach ($files as $f) {
        if ($f == '.' || $f == '..') {
            continue;
        } elseif (is_dir($src . '/' . $f) && substr($f, 0, 1) == '.') {
            // skip directories that start with a dot (like .svn) without a warning
            continue;
        } elseif (is_dir($src . '/' . $f)) {
            log_msg('warn', 'snapshot: skipping ' . quot($src . '/' . $f) . ' as we don\'t support directories inside pages');
        } elseif (is_link($src . '/' . $f) && is_file($src . '/' . $f)) {
            // a proper symlink, copy content
            $s = @file_get_contents($src . '/' . $f);
            $m = umask(0111);
            if (!@file_put_contents($dest . '/' . $f, $s)) {
                log_msg('error', 'snapshot: error writing to ' . quot($dest . '/' . $f) . ', skipping file');
            } else {
                log_msg('debug', 'snapshot: copied the content of symlink ' . quot($args['page'] . '.' . $f));
            }
            umask($m);
            // load the newly created snapshot and give modules a chance to
            // copy referenced files as well
            $dest_name = $a[0] . '.' . $args['rev'] . '.' . $f;
            $dest_obj = load_object(array('name' => $dest_name));
            if ($dest_obj['#error']) {
                log_msg('error', 'snapshot: error loading snapshotted object ' . quot($dest_name) . ', skipping hook');
            } else {
                $dest_obj = $dest_obj['#data'];
                // get the source object's target
                $src_name = $args['page'] . '.' . $f;
                $src_target = object_get_symlink(array('name' => $src_name));
                if ($src_target['#error']) {
                    log_msg('error', 'snapshot: error getting the symlink target of source object ' . quot($src_name) . ', skipping hook');
                } else {
                    $src_target = $src_target['#data'];
                    // hook
                    invoke_hook('snapshot_symlink', array('obj' => $dest_obj, 'origin' => implode('.', array_slice(expl('.', $src_target), 0, 2))));
                }
            }
        } elseif (is_file($src . '/' . $f)) {
            // copy file
            $m = umask(0111);
            if (!@copy($src . '/' . $f, $dest . '/' . $f)) {
                log_msg('error', 'snapshot: error copying ' . quot($src . '/' . $f) . ' to ' . quot($dest . '/' . $f) . ', skipping file');
            }
            umask($m);
        }
    }
    log_msg('info', 'snapshot: created snapshot ' . quot($a[0] . '.' . $args['rev']) . ' from ' . quot($args['page']));
    return response($a[0] . '.' . $args['rev']);
}
Exemplo n.º 4
0
/**
 *	invoke a hook when an update was detected
 */
function handle_updates()
{
    $new = glue_version();
    $write_file = false;
    if (($s = @file_get_contents(CONTENT_DIR . '/version')) !== false) {
        // parse version
        $a = expl('.', $s);
        $old = array(0, 0, 0);
        for ($i = 0; $i < count($a); $i++) {
            $old[$i] = $a[$i];
        }
        // check if an update happened
        if ($old != $new) {
            log_msg('info', 'common: detected hotglue update from version ' . implode('.', $old) . ' to ' . implode('.', $new));
            // hook
            invoke_hook('glue_update', array('old' => $old, 'new' => $new));
            $write_file = true;
        }
    } else {
        $write_file = true;
    }
    if ($write_file) {
        $m = umask(0111);
        @file_put_contents(CONTENT_DIR . '/version', implode('.', $new));
        umask($m);
    }
}
Exemplo n.º 5
0
/**
 *	invoke a hook with a specified module being called last
 *
 *	this function also takes care of loading all modules.
 *	@param string $hook hook to invoke
 *	@param string $last_module name of last module to call
 *	@param array $args arguments-array (can include references)
 *	@return array of results (module=>result)
 */
function invoke_hook_last($hook, $last_module, $args = array())
{
    return invoke_hook($hook, $args, '', $last_module);
}
Exemplo n.º 6
0
function download_save_state($args)
{
    $elem = $args['elem'];
    $obj = $args['obj'];
    if (array_shift(elem_classes($elem)) != 'download') {
        return false;
    }
    // make sure the type is set
    $obj['type'] = 'download';
    $obj['module'] = 'download';
    // hook
    invoke_hook('alter_save', array('obj' => &$obj, 'elem' => $elem));
    // make width and height only be determined by the css
    if (isset($obj['object-width'])) {
        unset($obj['object-width']);
    }
    if (isset($obj['object-height'])) {
        unset($obj['object-height']);
    }
    load_modules('glue');
    $ret = save_object($obj);
    if ($ret['#error']) {
        log_msg('error', 'download_save_state: save_object returned ' . quot($ret['#data']));
        return false;
    } else {
        return true;
    }
}