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;
}
Beispiel #2
0
/**
 *	turn the page into a html string
 *
 *	@param bool &$cache is output cachable (will only modified if $cache is 
 *	true before)
 *	@return string html
 */
function html_finalize(&$cache = false)
{
    global $html;
    // return html5
    $ret = '<!DOCTYPE html>' . nl();
    $ret .= '<html';
    if (@is_array($html['header']['style'])) {
        $ret .= ' style="';
        ksort($html['header']['style']);
        foreach ($html['header']['style'] as $key => $val) {
            $ret .= htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . ': ' . htmlspecialchars($val, ENT_COMPAT, 'UTF-8') . '; ';
        }
        // strip the last space
        $ret = substr($ret, 0, -1);
        $ret .= '"';
    }
    $ret .= '>' . nl();
    $ret .= '<head>' . nl();
    $ret .= '<title>' . htmlspecialchars($html['header']['title'], ENT_NOQUOTES, 'UTF-8') . '</title>' . nl();
    $ret .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . nl();
    if (@is_array($html['header']['alternate'])) {
        foreach ($html['header']['alternate'] as $e) {
            $ret .= '<link rel="alternate" type="' . htmlspecialchars($e['type'], ENT_COMPAT, 'UTF-8') . '" href="' . htmlspecialchars($e['url'], ENT_COMPAT, 'UTF-8') . '" title="' . htmlspecialchars($e['title'], ENT_COMPAT, 'UTF-8') . '">' . nl();
        }
    }
    if (!empty($html['header']['favicon'])) {
        $ret .= '<link rel="shortcut icon" href="' . htmlspecialchars($html['header']['favicon'], ENT_COMPAT, 'UTF-8') . '">' . nl();
    }
    if (@is_array($html['header']['css'])) {
        _array_sort_by_prio($html['header']['css']);
        // removed the removal of duplicates here as two different media might point to the same url
        //array_unique_element($html['header']['css'], 'url');
        foreach ($html['header']['css'] as $e) {
            $ret .= '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars($e['url'], ENT_COMPAT, 'UTF-8') . '"';
            if (!empty($e['media'])) {
                $ret .= ' media="' . htmlspecialchars($e['media'], ENT_COMPAT, 'UTF-8') . '"';
            }
            $ret .= '>' . nl();
        }
    }
    if (@is_array($html['header']['css_inline'])) {
        _array_sort_by_prio($html['header']['css_inline']);
        if (0 < count($html['header']['css_inline'])) {
            $ret .= '<style type="text/css">' . nl();
        }
        foreach ($html['header']['css_inline'] as $c) {
            $rule = $c['rule'];
            // if the rule ends with a newline character, remove it
            if (substr($rule, -1) == "\n") {
                $rule = substr($rule, 0, -1);
            }
            // move rule in by one tab
            $rule = str_replace("\n", "\n\t", $rule);
            $ret .= tab() . $rule . nl();
        }
        if (0 < count($html['header']['css_inline'])) {
            $ret .= '</style>' . nl();
        }
    }
    if (@is_array($html['header']['js'])) {
        _array_sort_by_prio($html['header']['js']);
        array_unique_element($html['header']['js'], 'url');
        foreach ($html['header']['js'] as $e) {
            $ret .= '<script type="text/javascript" src="' . htmlspecialchars($e['url'], ENT_COMPAT, 'UTF-8') . '"></script>' . nl();
        }
    }
    if (@is_array($html['header']['js_var'])) {
        $ret .= array_to_js($html['header']['js_var']);
    }
    if (@is_array($html['header']['js_inline'])) {
        _array_sort_by_prio($html['header']['js_inline']);
        foreach ($html['header']['js_inline'] as $c) {
            if (!empty($c['reason'])) {
                $ret .= '<!-- ' . $c['reason'] . ' -->' . nl();
                $ret .= '<script type="text/javascript">' . nl();
                // if the code ends with a newline character, remove it
                if (substr($c['code'], -1) == "\n") {
                    $c['code'] = substr($c['code'], 0, -1);
                }
                // move code in by one tab
                $c = str_replace("\n", "\n\t", $c);
                $ret .= tab() . $c['code'] . nl();
                $ret .= '</script>' . nl();
            }
        }
    }
    $ret .= '</head>' . nl();
    $ret .= elem_finalize($html['body']);
    $ret .= '</html>';
    // pass caching information up if requested
    if ($cache) {
        if (!$html['cache']) {
            $cache = false;
        }
    }
    return $ret;
}
Beispiel #3
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));
}
/**
 *	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;
}
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;
}