function xanth_db_install_content_format()
{
    //content format
    xanth_db_query("\r\n\t\tCREATE TABLE content_format (\r\n\t\tname VARCHAR(64) NOT NULL,\r\n\t\tdescription VARCHAR(256) NOT NULL,\r\n\t\tPRIMARY KEY(name)\r\n\t\t)TYPE=InnoDB");
    $cf = new xContentFormat('Php source', 'Php scripts are allowed and executed.');
    $cf->insert();
    $cf = new xContentFormat('Full Html', 'All html tags are allowed.');
    $cf->insert();
    $cf = new xContentFormat('BBCode', 'Enable the use of a slightly modified version of BBCode tags. 
		Also converts all special html chars in html entities and line breaks in br');
    $cf->insert();
    $cf = new xContentFormat('Filtered text', 'Converts all special html chars in html entities and line breaks in br.');
    $cf->insert();
}
 /**
  * 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;
 }
function xanth_entry_admin_entry_create($hook_primary_id, $hook_secondary_id, $arguments)
{
    if (!xUser::check_current_user_access('create entry')) {
        return xSpecialPage::access_denied();
    }
    //create form
    $form = new xForm('?p=admin/entry/create');
    //types
    $types = xEntryType::find_all();
    $options = array();
    foreach ($types as $type) {
        $options[$type->name] = $type->name;
    }
    $form->elements[] = new xFormElementOptions('entry_type', 'Select type', '', '', $options, FALSE, TRUE, new xInputValidatorTextNameId(32));
    //title
    $form->elements[] = new xFormElementTextField('content_title', 'Title', '', '', TRUE, new xInputValidatorTextNoTags(256));
    //body
    $form->elements[] = new xFormElementTextArea('content_body', 'Body', '', '', TRUE, new xInputValidatorText(256));
    //content formats
    $content_formats = xContentFormat::find_all();
    $content_formats_radio_group = new xFormRadioGroup(array(), 'Content format');
    foreach ($content_formats as $content_format) {
        $content_formats_radio_group->elements[] = new xFormElementRadio('content_format', $content_format->name, $content_format->description, $content_format->name, FALSE, TRUE, new xInputValidatorText(64));
    }
    $content_formats_radio_group->elements[0]->checked = TRUE;
    $form->elements[] = $content_formats_radio_group;
    //categories
    $categories = xCategory::find_all();
    $options = array();
    foreach ($categories as $category) {
        $options[$category->title] = $category->id;
    }
    $form->elements[] = new xFormElementOptions('entry_categories', 'Categories', '', '', $options, TRUE, FALSE, new xInputValidatorInteger());
    //parameters
    $parameters = new xFormGroup(array(), 'Parameters');
    $parameters->elements[] = new xFormElementCheckbox('param_published', 'Published', '', '1', TRUE, FALSE, new xInputValidatorInteger());
    $form->elements[] = $parameters;
    //metadata
    $metadata = new xFormGroup(array(), 'Metadata');
    $metadata->elements[] = new xFormElementTextField('meta_description', 'Description', '', '', FALSE, new xInputValidatorTextNoTags(512));
    $metadata->elements[] = new xFormElementTextField('meta_keywords', 'Keywords', '', '', FALSE, new xInputValidatorTextNoTags(128));
    $form->elements[] = $metadata;
    //submit buttom
    $form->elements[] = new xFormSubmit('submit', 'Create');
    $ret = $form->validate_input();
    if (isset($ret->valid_data['submit'])) {
        if (empty($ret->errors)) {
            //no error,lets create the entry
            $author = xUser::get_current_username() !== NULL ? xUser::get_current_username() : 'anonymous';
            //translate categories
            $cat_ids = $ret->valid_data['entry_categories'];
            $categories = array();
            if (!empty($cat_ids)) {
                foreach ($cat_ids as $cat_id) {
                    $categories[] = new xCategory($cat_id);
                }
            }
            $entry = new xEntry(NULL, $ret->valid_data['content_title'], $ret->valid_data['entry_type'], $author, $ret->valid_data['content_body'], $ret->valid_data['content_format'], $ret->valid_data['param_published'], $ret->valid_data['meta_description'], $ret->valid_data['meta_keywords'], $categories);
            $entry->insert();
            return new xPageContent('Entry created', 'Entry created, <a href="?p=entry//' . $entry->id . '">view it</a>');
        } else {
            foreach ($ret->errors as $error) {
                xanth_log(LOG_LEVEL_USER_MESSAGE, $error);
            }
        }
    }
    return new xPageContent('Create entry', $form->render());
}