function xanth_db_install_theme()
{
    //theme
    xanth_db_query("\r\n\t\tCREATE TABLE theme (\r\n\t\tname VARCHAR(32) NOT NULL,\r\n\t\tPRIMARY KEY (name)\r\n\t\t)TYPE=InnoDB");
    //theme to elements
    xanth_db_query("\r\n\t\tCREATE TABLE theme_to_elements (\r\n\t\ttheme_name VARCHAR(32) NOT NULL,\r\n\t\tvisual_element VARCHAR(32) NOT NULL,\r\n\t\tview_mode INT UNSIGNED NOT NULL,\r\n\t\tUNIQUE (theme_name,visual_element),\r\n\t\tINDEX(theme_name),INDEX(visual_element),INDEX(view_mode),\r\n\t\tFOREIGN KEY (theme_name) REFERENCES theme(name) ON DELETE CASCADE,\r\n\t\tFOREIGN KEY (visual_element) REFERENCES visual_element(name) ON DELETE CASCADE,\r\n\t\tFOREIGN KEY (view_mode) REFERENCES view_mode(id) ON DELETE CASCADE\r\n\t\t)TYPE=InnoDB");
    //theme to elements
    xanth_db_query("\r\n\t\tCREATE TABLE theme_area (\r\n\t\tname VARCHAR(32) NOT NULL,\r\n\t\tview_mode INT UNSIGNED,\r\n\t\tPRIMARY KEY (name),\r\n\t\tINDEX(view_mode),\r\n\t\tFOREIGN KEY (view_mode) REFERENCES view_mode(id) ON DELETE SET NULL\r\n\t\t)TYPE=InnoDB");
    //register new visual element
    $element = new xVisualElement('area');
    $element->insert();
    //...and the default view mode
    $proc = '
$output = \'\';
foreach($boxes as $box)
{
	$output .= "<div class=\\"box\\">$box</div>";
}
return $output;
';
    $view = new xViewMode(0, 'Default area view', 'area', TRUE, $proc);
    $view->insert();
    //content area view mode
    $proc = '
		return $page_content;
	';
    $content_view = new xViewMode(0, 'Content area view', 'area', FALSE, $proc);
    $content_view->insert();
    //footer area view mode
    $proc = '
		return \'Page created with \'. xPageElement::get_db_query_count() .\' queries in \'.xPageElement::get_execution_time().\' seconds\';
	';
    $foot_view = new xViewMode(0, 'Footer area view', 'area', FALSE, $proc);
    $foot_view->insert();
    //default theme areas
    $area = new xThemeArea('sidebar left');
    $area->insert();
    $area = new xThemeArea('content', $content_view->id);
    $area->insert();
    $area = new xThemeArea('footer', $foot_view->id);
    $area->insert();
    //access rule
    $access = new xAccessRule('manage theme', 'Theme');
    $access->insert();
}
 function render()
 {
     $theme = xTheme::get_default();
     //retrieve content
     $page_content = xanth_invoke_mono_hook(MONO_HOOK_PAGE_CONTENT_CREATE, $this->xanthpath->base_path, array($this->xanthpath->resource_id));
     if ($page_content === NULL) {
         $page_content = new xPageContent('Page not found', "<b>Page not found</b>");
     }
     $logs = '';
     $log_entries = xanth_get_screen_log();
     //display log messages
     if (!empty($log_entries)) {
         $logs .= '<table border="1" width="90%"><tr><td><ul>';
         foreach ($log_entries as $entry) {
             $logs .= '<li>' . $entry->level . ' ' . $entry->component . ' ' . htmlspecialchars($entry->message) . ' ' . $entry->filename . '@' . $entry->line . '</li>';
         }
         $logs .= '</ul></td></tr></table>' . "\n";
     }
     $page_content->body = $logs . $page_content->body;
     //retrieve areas
     $areas = xThemeArea::find_all();
     $this->areas = array();
     $this->boxes = array();
     //retrieve innermost elements
     foreach ($areas as $area) {
         $xboxes = xBox::find($area->name);
         $this->boxes[$area->name] = array();
         foreach ($xboxes as $xbox) {
             //retrieve box view
             $this->boxes[$area->name][] = $xbox->render();
         }
         //Generate area view (not using view mode)
         $this->areas[$area->name] = $area->render($this->boxes[$area->name], $page_content->body);
     }
     //construct metadata array
     $this->header = array();
     if (empty($page_content->description)) {
         $this->header['description'] = xSettings::get('site_description');
     } else {
         $this->header['description'] = $page_content->description;
     }
     if (empty($page_content->keywords)) {
         $this->header['keywords'] = xSettings::get('site_keywords');
     } else {
         $this->header['keywords'] = $page_content->keywords;
     }
     //retrieve the full page
     $this->header['title'] = xSettings::get('site_name') . ' | ' . $page_content->title;
     $page_ready_to_print = eval($theme->get_view_mode_procedure('page'));
     return $page_ready_to_print;
 }
function xanth_theme_admin_theme_area($hook_primary_id, $hook_secondary_id, $arguments)
{
    if (!xUser::check_current_user_access('manage theme')) {
        return xSpecialPage::access_denied();
    }
    $areas = xThemeArea::find_all();
    $output = "<table>\n";
    $output .= "<tr><th>Name</th><th>View Mode</th><th>Edit</th><th>Delete</th></tr>\n";
    foreach ($areas as $area) {
        $v = xViewMode::get($area->view_mode);
        if ($v === NULL) {
            $vname = 'Theme Default';
        } else {
            $vname = $v->name;
        }
        $output .= "<tr><td>" . $area->name . '</td><td>' . $vname . '</td><td>Edit</td><td>Delete</td></tr>';
    }
    $output .= "</table>\n";
    return new xPageContent('Admin area', $output);
}