Пример #1
0
function lock_alter_render_early($args)
{
    $elem =& $args['elem'];
    $obj = $args['obj'];
    if (!elem_has_class($elem, 'object')) {
        return false;
    }
    if (!empty($obj['object-lock'])) {
        elem_add_class($elem, 'locked');
    }
    return true;
}
function webvideo_render_object($args)
{
    $obj = $args['obj'];
    if (!isset($obj['type']) || $obj['type'] != 'webvideo') {
        return false;
    }
    $e = elem('div');
    elem_attr($e, 'id', $obj['name']);
    elem_add_class($e, 'webvideo');
    elem_add_class($e, 'resizable');
    elem_add_class($e, 'object');
    // hooks
    invoke_hook_first('alter_render_early', 'webvideo', array('obj' => $obj, 'elem' => &$e, 'edit' => $args['edit']));
    $html = elem_finalize($e);
    invoke_hook_last('alter_render_late', 'webvideo', array('obj' => $obj, 'html' => &$html, 'elem' => $e, 'edit' => $args['edit']));
    return $html;
}
Пример #3
0
/**
 *	implements render_object
 */
function image_render_object($args)
{
    $obj = $args['obj'];
    if (!isset($obj['type']) || $obj['type'] != 'image') {
        return false;
    }
    // the outer element must be a div or something else that can contain
    // other elements
    // we only set up the most basic element here - all the other work is
    // done inside the alter_render_early hook
    // this way also object that "derive" from this (which don't have their
    // $obj['type'] set to image) can use this code
    $e = elem('div');
    elem_attr($e, 'id', $obj['name']);
    elem_add_class($e, 'image');
    elem_add_class($e, 'resizable');
    elem_add_class($e, 'object');
    // hook
    // elem is passed as reference here
    // it is suggested that we first call our own function before any others
    // that might want to modify the element that is being set up
    invoke_hook_first('alter_render_early', 'image', array('obj' => $obj, 'elem' => &$e, 'edit' => $args['edit']));
    $html = elem_finalize($e);
    // html is passed as reference here
    // it is suggested that we call our own function after all others
    invoke_hook_last('alter_render_late', 'image', array('obj' => $obj, 'html' => &$html, 'elem' => $e, 'edit' => $args['edit']));
    return $html;
}
Пример #4
0
/**
 *	turn a page into an html string
 *
 *	the function also appends the resulting string to the output in 
 *	html.inc.php.
 *	@param array $args arguments
 *		key 'page' is the page (i.e. page.rev)
 *		key 'edit' are we editing or not
 *	@return array response
 *		html
 */
function render_page($args)
{
    // maybe move this to common.inc.php in the future and get rid of some of
    // these checks in the beginning
    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);
    }
    if (!isset($args['edit'])) {
        return response('Required argument "edit" missing', 400);
    }
    if ($args['edit']) {
        $args['edit'] = true;
    } else {
        $args['edit'] = false;
    }
    log_msg('debug', 'render_page: rendering ' . quot($args['page']));
    $bdy =& body();
    elem_add_class($bdy, 'page');
    elem_attr($bdy, 'id', $args['page']);
    invoke_hook('render_page_early', array('page' => $args['page'], 'edit' => $args['edit']));
    // for every file in the page directory
    $files = @scandir(CONTENT_DIR . '/' . str_replace('.', '/', $args['page']));
    foreach ($files as $f) {
        $fn = CONTENT_DIR . '/' . str_replace('.', '/', $args['page']) . '/' . $f;
        if ($f == '.' || $f == '..') {
            continue;
        } elseif (is_link($fn) && !is_file($fn) && !is_dir($fn)) {
            // delete dangling symlink
            if (@unlink($fn)) {
                log_msg('info', 'render_page: deleted dangling symlink ' . quot($args['page'] . '.' . $f));
            } else {
                log_msg('error', 'render_page: error deleting dangling symlink ' . quot($args['page'] . '.' . $f));
            }
            continue;
        }
        // render object
        render_object(array('name' => $args['page'] . '.' . $f, 'edit' => $args['edit']));
    }
    invoke_hook('render_page_late', array('page' => $args['page'], 'edit' => $args['edit']));
    log_msg('debug', 'render_page: finished ' . quot($args['page']));
    // return the body element as html-string as well
    return response(elem_finalize($bdy));
}
Пример #5
0
function download_render_object($args)
{
    $obj = $args['obj'];
    if (!isset($obj['type']) || $obj['type'] != 'download') {
        return false;
    }
    $e = elem('div');
    elem_attr($e, 'id', $obj['name']);
    elem_add_class($e, 'download');
    elem_add_class($e, 'object');
    // hooks
    invoke_hook_first('alter_render_early', 'download', array('obj' => $obj, 'elem' => &$e, 'edit' => $args['edit']));
    $html = elem_finalize($e);
    invoke_hook_last('alter_render_late', 'download', array('obj' => $obj, 'html' => &$html, 'elem' => $e, 'edit' => $args['edit']));
    if (!$args['edit']) {
        // put link to file around the element
        if (SHORT_URLS) {
            $link = base_url() . urlencode($obj['name']) . '&download=1';
        } else {
            $link = base_url() . '?' . urlencode($obj['name']) . '&download=1';
        }
        $html = '<a href="' . htmlspecialchars($link, ENT_COMPAT, 'UTF-8') . '">' . "\n\t" . str_replace("\n", "\n\t", $html) . "\n" . '</a>' . "\n";
    }
    return $html;
}