/**
* Init function
* @ingroup Core
*/
function xanth_init()
{
    global $start_time;
    $start_time = gettimeofday(TRUE);
    ob_start();
    xanth_db_query_reset_count();
    set_error_handler('xanth_php_error_handler');
    xanth_db_connect(xanth_conf_get('db_host', ''), xanth_conf_get('db_name', ''), xanth_conf_get('db_user', ''), xanth_conf_get('db_pass', ''), xanth_conf_get('db_port', ''));
    session_set_save_handler("on_session_start", "on_session_end", "on_session_read", "on_session_write", "on_session_destroy", "on_session_gc");
    session_start();
    xComponent::init_all();
    xModule::init_all();
    //xTheme::find_default()->init();
    xanth_invoke_multi_hook(MULTI_HOOK_PAGE_CREATE_EVT, NULL);
    xanth_invoke_mono_hook(MONO_HOOK_PAGE_CREATE, NULL);
    //print log
    echo '<br />';
    echo '<br />';
    echo '<br />';
    echo '<br />';
    echo '<br />';
    foreach (xanth_get_screen_log() as $entry) {
        echo '<br />' . $entry->level . ' ' . $entry->component . ' ' . $entry->message . ' ' . $entry->filename . '@' . $entry->line;
    }
    session_write_close();
    echo ob_get_clean();
}
 /**
  * @return The eleborated content or FALSE on failure. Check if the last error is empty to see if effectively there was an error.
  */
 function apply_to($content)
 {
     $this->last_error = '';
     $error = '';
     $result = xanth_invoke_mono_hook(MONO_HOOK_CONTENT_FORMAT_APPLY, $this->name, array($content, &$error));
     $this->last_error = $error;
     return $result;
 }
 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;
 }
 /**
  * List all box in an area.
  */
 function find($area = '')
 {
     $boxes = array();
     if (empty($area)) {
         $result = xanth_db_query("SELECT * FROM box");
     } else {
         $result = xanth_db_query("SELECT * FROM box WHERE area = '%s'", $area);
     }
     while ($row = xanth_db_fetch_array($result)) {
         $current_box = new xBox($row['name'], $row['title'], $row['content'], $row['content_format'], $row['is_user_defined'], $row['area']);
         if (!$current_box->user_defined) {
             //retrieve built-in box content
             $current_box->content = xanth_invoke_mono_hook(MONO_HOOK_CREATE_BOX_CONTENT, $current_box->name);
         } else {
             $content_format = new xContentFormat($row['content_format'], '');
             $current_box->content = $content_format->apply_to($current_box->content);
         }
         $boxes[] = $current_box;
     }
     return $boxes;
 }