function xanth_user_login_box($hook_primary_id, $hook_secondary_id, $arguments) { $username = xUser::get_current_username(); if (!empty($username)) { return "Logged as user {$username}<br /><a href=\"?p=user/logout\">Logout</a>"; } return "User not logged in<br /><a href=\"?p=user/login\">Login</a>"; }
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()); }