function show() { $this->count_task_types('ssscrapecontrol.ssscrape_task'); $q = "SELECT t.id, t.type, program, args, state, hostname, periodicity, \n latest_run, resource_id resource, \n f.url, f.id feed_id, '' jobs \n FROM ssscrapecontrol.ssscrape_task t \n LEFT JOIN ssscrape_feed f ON f.url=REPLACE(REPLACE(t.args, '-u ', ''), \"'\", '')\n ?where?"; $this->m->append(ax_p(ax_a_href("Create new task", "editor/?show=tasks&id=NEW"))); $this->run_query($q); }
function display($args) { $show = array_get_default($args, 'show', 'home'); $page = null; foreach ($this->pages as $page) { if ($page['name'] == $show) { break; } } if (!$page) { $show = 'home'; $main_show = 'home'; } else { $main_show = array_key_exists('parent', $page) ? $page['parent'] : $show; } $args['show'] = $show; // Go to monitor if no id is specified $id = array_get_default($args, 'id', ''); if ($id == '') { header('Location: ../?' . http_build_query($args)); exit; } // Display menu $menu = $this->display_menu($main_show); $this->append(ax_ul_items($menu, array('id' => 'tablist'))); foreach ($this->forms as $form) { if ($form['name'] == $show) { break; } } if (!$form or $form['name'] != $show) { return; } $title = $form['descr']; $form = new $form['class']($args); if ($form->get_data($id)) { // Editing existing entity $title .= " {$id}"; } else { // Adding new entity $form->set_control_value('id', ''); $id = ""; unset($args['id']); $title .= " (new)"; } if (Request::is_post()) { $form->fill($_POST); $msg = $form->save_data(); $id = $form->get_control_value('id'); $form->get_data($id); if ($msg != "") { $this->append(ax_p($msg)); } } $fr = new AnewtFormRendererDefault(); $fr->set_form($form); $this->append(ax_h2($title)); $this->append($fr); }
/** * The constructor takes care of the page contents. */ function __construct() { parent::__construct(); $text = 'this page intentionally left blank'; $this->set('title', $text); $link = ax_a_href($text, 'http://www.this-page-intentionally-left-blank.org/whythat.html', array('style' => 'color:black; text-decoration:none;')); $paragraph = ax_p($link, array('style' => 'position: absolute; right: 4em; bottom: 2em; font-size: small;')); $this->append($paragraph); }
function count_feeds() { $q = "SELECT COUNT(DISTINCT i.feed_id) AS num FROM ssscrape_feed_item i, shuffler_track s WHERE s.feed_item_id = i.id AND ?temp-constraint? -- "; //$num_active_feeds = $this->count($this->prepare_query($q, 'sent')); $db = DB::get_instance(); $cnt = $db->prepare_execute_fetch($this->prepare_query($q, 'sent')); $num_active_feeds = array_pop($cnt); $num_feeds = $this->count("SELECT COUNT(*) FROM `ssscrape_feed` -- "); $num_feeds_pct = round($num_active_feeds * 100 / $num_feeds); $this->m->append(ax_p("{$num_active_feeds} feeds out of {$num_feeds} have tracks in this period ({$num_feeds_pct} %)")); }
/** * \private * * Show a simple error page. * * \param $exception * The AnewtHTTPException instance */ protected function show_error_page($exception) { assert('$exception instanceof Exception;'); anewt_include('page'); $p = new AnewtPage(); $p->show_dublin_core = false; /* Title */ if ($exception instanceof AnewtHTTPException) { $title = sprintf('%d - %s', $exception->getCode(), http_status_to_string($exception->getCode())); } else { $title = sprintf('%d - %s', HTTP_STATUS_INTERNAL_SERVER_ERROR, http_status_to_string(HTTP_STATUS_INTERNAL_SERVER_ERROR)); } $p->title = $title; $p->append(ax_h1($title)); /* Add default explanation (instead of just a title) for some exceptions. */ $message = $exception->getMessage(); if ($message) { $p->append(ax_p($message)); } else { switch ($exception->getCode()) { case HTTP_STATUS_NOT_FOUND: $p->append(ax_p('The requested resource cannot be found.')); break; case HTTP_STATUS_FORBIDDEN: $p->append(ax_p('Access to the requested resource was denied.')); break; case HTTP_STATUS_INTERNAL_SERVER_ERROR: $p->append(ax_p('An internal server error occurred while processing your request.')); break; default: break; } } /* Backtrace */ $p->append(ax_pre($exception->getTraceAsString())); $p->flush(); }
<?php echo to_string(ax_div_id(ax_p('This is a paragraph of text wrapped in a div with an id attribute'), 'this-is-the-div-id'));
$ctx1->draw_filled_rectangle_size(3, 3, 4, 3); $ctx1->set('color', $img->color_from_string('#969')); $ctx1->draw_rectangle(3, 3, 6, 7); $ctx1->draw_filled_rectangle_size(15, 2, 2, 2); $ctx1->draw_filled_rectangle_size(15, 2, -1, -1); $col = $img->color_from_string('#36c'); $ctx1->set('color', $col); $ctx1->draw_filled_rectangle(20, 2, 18, 3); assert('$ctx1->color_at(19, 2) == $col'); /* Blow up so we can count the pixels in the result */ $img->resize_relative(10, false); $img->flush_png(); $img->destroy(); } } $test = AnewtRequest::get_string('test'); if (is_null($test)) { /* Show test chooser */ anewt_include('page'); $p = new AnewtPage(); $p->set('title', 'Choose a test'); $p->append(ax_h1('Choose a test')); foreach (get_class_methods('AnewtImageTestCases') as $name) { $url = AnewtURL::build(AnewtRequest::relative_url(), array('test' => $name)); $p->append(ax_p(ax_a_href(sprintf('Test: %s', $name), $url))); } $p->flush(); } else { /* Invoke test function */ AnewtImageTestCases::$test(); }
function build_footer() { return ax_p('Contact: jijkoun@uva.nl'); }
/** * Build an error node. */ protected function _build_error_node($obj) { /* FIXME: share code with _build_description_node */ $error = $obj->_get('error'); if (is_null($error)) { $out = null; return $out; } $error_node = new AnewtXHTMLDiv(); if (is_string($error)) { /* Wrap string in a paragraph. */ $error_node->append_child(ax_p($error)); } else { /* Assume it's an XHTML element and append it directly */ assert('$error instanceof AnewtXMLDomNode;'); $error_node->append_child($error); } if ($obj instanceof AnewtForm) { $class = 'form-error form-error-form'; } elseif ($obj instanceof AnewtFormFieldset) { $class = 'form-error form-error-fieldset'; } elseif ($obj instanceof AnewtFormControl) { $class = 'form-error form-error-control'; } else { assert('false; // not reached'); } $error_node->set_class($class); return $error_node; }
function run_query($q, $extra_field = null) { $q = $this->prepare_query($q, $extra_field); $m = $this->m; $db = DB::get_instance(); $rows = $db->prepare_execute_fetch_all($q); $more_results = false; if (count($rows) == $this->limit + 1) { $more_results = true; array_pop($rows); # remove the extra row } cycle(array('bg1', 'bg0')); $this->stat = array(); $descr = array(); if ($this->query_restriction) { array_push($descr, "Condition: " . $this->query_restriction); } if ($this->interval) { array_push($descr, $this->make_interval_selection($this->interval)); } $m->append(ax_p($descr)); $table = ax_table_class('results'); $table->append_child($this->make_table_header()); $table->append_children($this->make_table_rows($rows)); $table->append_child($this->make_table_footer()); $m->append($table); $m->append($this->make_results_summary(count($rows), $more_results)); $m->append(ax_p(array(ax_raw('Generated with query:<br /><textarea class="query">'), $q, ax_raw('</textarea>')))); }
<?php // Results in <p class="foo">Paragraph text</p> when rendered $p = ax_p_class('Paragraph text', 'foo'); // The same can be achieved like this: $p = ax_p('Paragraph text'); $p->set_class('foo'); // Results in <div id="bar">Text here</div> when rendered $p = ax_div_id('Text here', 'bar'); // The same can be achieved like this: $div = ax_div('Text here'); $div->set_attribute('id', 'bar'); // Hyperlinks can be built like this: $link = ax_a_href('Hyperlink text', 'http://anewt.net'); $link = ax_a_href_title('Hyperlink text', 'http://anewt.net', 'This will be a tooltip'); // Images can be built like this: $img = ax_img_src_alt('example.png', 'An example image');
function build_footer() { return ax_p('This is the footer'); }
<?php // Building a paragraph using the class constructor: $p = new AnewtXHTMLParagraph('This is some text'); // The same, but now using the convenience API: $p = ax_p('This is some text.');
<?php $p = new AnewtPage(); $p->append(ax_p('This is a paragraph of text.')); $p->append(ax_raw('<p>This is some <code>pre-formatted</code> text.</p>')); $p->append('This string will be escaped: <, &, and > are no problem!'); $p->flush();
function TestForm() { parent::__construct(); /* General form setup and test some properties */ $this->setup('test-name', ANEWT_FORM_METHOD_POST, AnewtRequest::url(true)); $this->set('error', 'This is a general form error.'); $this->set('description', 'This is the form\'s description.'); /* Test text entry controls */ $text1 = new AnewtFormControlText('text1'); $text1->set('label', 'Text field:'); $text1->set('secondary-label', 'Secondary label'); $text1->set('value', 'Short string with & spécial chars'); $text1->set('help', 'You can type some text here.'); $text1->set('description', 'Type at least 3 characters here.'); $text1->add_validator(new AnewtValidatorLength(3, null), 'Too short (minimum number of characters is 3).'); $this->add_control($text1); $text2 = new AnewtFormControlTextMultiline('text2'); $this->add_control($text2); /* Set properties after adding to test references */ $text2->set('description', 'You may enter some longer text here.'); $text2->set('value', "Some readonly text\nwith multiple\nlines\nand some spécial characters\nlike &, ', < and >."); $text2->set('label', 'Multiline textfield:'); $text2->set('readonly', true); $text3 = new AnewtFormControlTextMultiline('text3'); $text3->set('value', "A larger control with a\nbit more space (4 lines!)\nto type some text, if only\nit wasn't disabled…"); $text3->set('label', 'Larger multiline:'); $text3->set('secondary-label', 'Secondary label'); $text3->set('rows', 4); $text3->set('columns', 40); $text3->set('disabled', true); $text3->set('error', 'This is an error description.'); $this->add_control($text3); $text4 = new AnewtFormControlTextMultiline('text4'); $text4->set('value', 'Okay, this is multiline text you can edit yourself…'); $text4->set('label', 'Another multiline:'); $text4->set('rows', 2); $text4->set('columns', 50); $this->add_control($text4); /* Test adding custom nodes to the form */ $this->add_node(ax_p('This is a normal paragraph inside the form.')); $this->add_node(ax_raw('<p><strong>Formatted text</strong> can be here as well.</p>')); /* Some more text controls with various property combinations */ $text5 = new AnewtFormControlText('text5'); $text5->set('label', 'A number between 1 and 10:'); $text5->set('description', 'This should be 8 by default. You should not be able to type more than 2 characters into this field.'); $text5->set('value', '7'); // Set again to 8 later using set_control_value! $text5->set('help', 'Enter a number between 1 and 10 inclusive, please.'); $text5->set('size', 2); $text5->set('maxlength', 2); $text5->add_validator(new AnewtValidatorInteger(1, 10), 'This number is not valid.'); $this->add_control($text5); $text6 = new AnewtFormControlPassword('text6'); $text6->set('label', 'Password:'******'description', 'This control can hold only 8 characters. This field is not required and will give a NULL value when left empty.'); $text6->set('size', 8); $text6->set('maxlength', 8); $text6->set('value', 'not-shown'); $text6->set('required', false); $text6->set('help', 'Enter a password, please.'); $this->add_control($text6); $text7 = new AnewtFormControlPassword('text7'); $text7->set('label', 'Echoed password:'******'description', 'This password is echoed back when the form is submitted.'); $text7->set('value', 'shown'); $text7->set('show-value', true); $this->add_control($text7); $text8 = new AnewtFormControlText('text8'); $text8->set('label', 'Email:'); $text8->set('value', '*****@*****.**'); $text8->add_validator(new AnewtValidatorEmail(), 'This does not look like an email address.'); $this->add_control($text8); /* Check box */ $check1 = new AnewtFormControlCheckbox('check1'); $check1->set('label', 'Checkbox:'); $check1->set('secondary-label', 'Check me'); $check1->set('help', 'Feel free to check me!'); $this->add_control($check1); $check2 = new AnewtFormControlCheckbox('check2'); $check2->set('label', 'Disabled checkbox:'); $check2->set('disabled', true); $this->add_control($check2); $check3 = new AnewtFormControlCheckbox('check3'); $check3->set('label', 'Another checkbox:'); $check3->set('secondary-label', 'Check me too'); $check3->set('value', true); $this->add_control($check3); /* Choice control, multiple same values */ $choice_same_values = new AnewtFormControlChoice('choice-same-values'); $choice_same_values->set('label', 'Choose:'); $choice_same_values->set('description', 'Multiple options have the same value. Only the first should be selected.'); $choice_same_values->add_option_value_label('same-value', 'Option 1 (same value as option 2'); $choice_same_values->add_option_value_label('same-value', 'Option 2 (same value as option 1'); $choice_same_values->add_option_value_label('other-value', 'Option 3'); $choice_same_values->set('value', 'same-value'); $this->add_control($choice_same_values); /* Choice control, single select */ $single_choice_fieldset = new AnewtFormFieldset('single-choice'); $single_choice_fieldset->set('label', 'Single select'); $single_choice_fieldset->set('description', 'You can select a single value here. By default, the second option is selected in both cases, and the first option is disabled.'); $choice1 = new AnewtFormControlChoice('choice1'); $choice1->set('label', 'Make a choice:'); $option = new AnewtFormOption('first', 'First option'); $option->set('disabled', true); $choice1->add_option($option); unset($option); $choice1->add_option_value_label('second', 'Second option'); $choice1->add_option_value_label('third', 'Third option'); $choice1->add_option_value_label('fourth', 'Fourth option'); $choice1->set('value', 'second'); $single_choice_fieldset->add_control($choice1); $choice2 = new AnewtFormControlChoice('choice2'); $choice2->set('threshold', 3); $choice2->set('label', 'Make a choice:'); $option = new AnewtFormOption('first', 'First option'); $option->set('disabled', true); $choice2->add_option($option); unset($option); $choice2->add_option_value_label('second', 'Second option'); $choice2->add_option_value_label('third', 'Third option'); $choice2->add_option_value_label('fourth', 'Fourth option'); $choice2->set('value', 'second'); $single_choice_fieldset->add_control($choice2); $choice3 = new AnewtFormControlChoice('choice3'); $choice3->set('threshold', 3); $choice3->set('size', 4); $choice3->set('label', 'Make a choice:'); $option = new AnewtFormOption('first', 'First option'); $option->set('disabled', true); $choice3->add_option($option); unset($option); $choice3->add_option_value_label('second', 'Second option'); $choice3->add_option_value_label('third', 'Third option'); $choice3->add_option_value_label('fourth', 'Fourth option'); $choice3->set('value', 'second'); $single_choice_fieldset->add_control($choice3); $single_choice_fieldset->add_node(ax_p('This is a normal paragraph inside a fieldset.')); $this->add_fieldset($single_choice_fieldset); /* Choice control, multiple select */ $multiple_choice_fieldset = new AnewtFormFieldset('multiple-choice'); $multiple_choice_fieldset->set('label', 'Multiple select'); $multiple_choice_fieldset->set('description', 'You can select multiple values here. By default, the second and third options are selected in both cases, and the first option is disabled.'); $choice4 = new AnewtFormControlChoice('choice4'); $choice4->set('multiple', true); $choice4->set('label', 'Make a choice:'); $option = new AnewtFormOption('first', 'First option'); $option->set('disabled', true); $choice4->add_option($option); unset($option); $choice4->add_option_value_label('second', 'Second option'); $choice4->add_option_value_label('third', 'Third option'); $choice4->add_option_value_label('fourth', 'Fourth option'); /* Value is deliberately set twice to test unsetting of old values */ $choice4->set('value', array('first', 'second')); $choice4->set('value', array('second', 'third')); $multiple_choice_fieldset->add_control($choice4); $choice5 = new AnewtFormControlChoice('choice5'); $choice5->set('multiple', true); $choice5->set('threshold', 3); $choice5->set('label', 'Make a choice:'); $option = new AnewtFormOption('first', 'First option'); $option->set('disabled', true); $choice5->add_option($option); unset($option); $choice5->add_option_value_label('second', 'Second option'); $choice5->add_option_value_label('third', 'Third option'); $choice5->add_option_value_label('fourth', 'Fourth option'); $choice5->set('value', array('second', 'third')); $multiple_choice_fieldset->add_control($choice5); $this->add_fieldset($multiple_choice_fieldset); /* Choice control, with option groups */ $option_groups_fieldset = new AnewtFormFieldset('option-groups-fieldset'); $option_groups_fieldset->set('label', 'Option groups'); $option_groups_fieldset->set('description', 'Single and multiple select controls with option groups.'); $choice6 = new AnewtFormControlChoice('choice6'); $og = new AnewtFormOptionGroup('First group'); $og->add_option_value_label('1a', 'A'); $og->add_option_value_label('1b', 'B'); $choice6->add_option_group($og); $og = new AnewtFormOptionGroup('Second group'); $og->add_option_value_label('2a', 'A'); $og->add_option_value_label('2b', 'B'); $choice6->add_option_group($og); $choice6->set('label', 'Make a choice:'); $choice6->set('description', 'Choice 2a selected by default.'); $choice6->set('value', '2a'); $option_groups_fieldset->add_control($choice6); $choice7 = new AnewtFormControlChoice('choice7'); $choice7->add_option_value_label('o1', 'First option (not in a group)'); $option_group_1 = new AnewtFormOptionGroup('First group'); $option = new AnewtFormOption('g1o1', 'First disabled suboption in first group'); $option->set('disabled', true); $option_group_1->add_option($option); $option_group_1->add_option_value_label('g1o2', 'Second suboption in first group'); $option_group_1->add_option_value_label('g1o3', 'Third suboption in first group'); $choice7->add_option_group($option_group_1); $option_group_2 = new AnewtFormOptionGroup('Second group'); $option_group_2->add_option_value_label('g2o1', 'First suboption in second group'); $option_group_2->add_option_value_label('g2o2', 'Second suboption in second group'); $choice7->add_option_group($option_group_2); $choice7->add_option_value_label('o3', 'Third option (not in a group)'); $option_group_3 = new AnewtFormOptionGroup('Third group (completely disabled)'); $option_group_3->set('disabled', true); $option_group_3->add_option_value_label('g3o1', 'Only suboption in third group'); $choice7->add_option_group($option_group_3); $choice7->add_option_value_label('04', 'Fourth option, not in a group'); $choice7->set('label', 'Make multiple choices:'); $choice7->set('description', 'Options 1 and group 2 option 1 are selected by default.'); $choice7->set('multiple', true); $choice7->set('value', array('g2o1', 'o1')); $option_groups_fieldset->add_control($choice7); $choice8 = new AnewtFormControlChoice('choice8'); $choice8->set('label', 'No selection here:'); $choice8->set('description', 'This choice control only contains disabled options and disabled or empty option groups. The first one should be forcibly selected. Yes, this is a really nasty edge case.'); $og = new AnewtFormOptionGroup('Empty group 1'); $choice8->add_option_group($og); $og = new AnewtFormOptionGroup('Disabled group 2'); $og->set('disabled', true); $og->add_option_value_label('none', '1a'); $og->add_option_value_label('none', '1b'); $choice8->add_option_group($og); $option = new AnewtFormOption('none', 'Disabled option'); $option->set('disabled', true); $choice8->add_option($option); $choice8->set('value', 'too bad this is totally invalid'); $option_groups_fieldset->add_control($choice8); $this->add_fieldset($option_groups_fieldset); /* Hidden controls */ $hidden1 = new AnewtFormControlHidden('hidden1'); $hidden1->set('value', 'sekr1t!'); $this->add_control($hidden1); $this->add_hidden_control('hidden2', 'another && śèkŕ1t'); /* Buttons */ $button_fieldset = new AnewtFormFieldset('buttons'); $button_fieldset->set('label', 'Button fieldset'); $submit = new AnewtFormControlButtonSubmit('submit'); $submit->set('label', 'Submit form'); $submit->set('help', 'Press this button to submit this form'); $button_fieldset->add_control($submit); $submit2 = new AnewtFormControlButtonSubmit('submit2'); $submit2->set('label', 'Disabled submit button'); $submit2->set('disabled', true); $button_fieldset->add_control($submit2); $submit = new AnewtFormControlButtonSubmit('submit3'); $submit->set('label', 'Another submit button'); $button_fieldset->add_control($submit); $reset = new AnewtFormControlButtonReset('reset'); $reset->set('label', 'Reset to default values'); $reset->set('help', 'Reset the values of the form fields to their original values'); $button_fieldset->add_control($reset); $extra = new AnewtFormControlButton('extra-button'); $extra->set('label', 'Extra button that does not do anything'); $button_fieldset->add_control($extra); $this->add_fieldset($button_fieldset); }
<?php require_once dirname(__FILE__) . '/../anewt.lib.php'; define('ANEWT_TEXTILE_DEVELOPMENT', 1); anewt_include('page'); $p = new AnewtPage(); $p->set('title', 'Textile formatting test'); if (AnewtRequest::get_bool('debug')) { header('Content-type: text/plain'); $p->set('content_type', 'text/plain'); } else { list($base_url, $params) = AnewtUrl::parse(AnewtRequest::url()); $params['debug'] = '1'; $debug_url = AnewtUrl::build(array($base_url), $params); $p->append(ax_p(ax_a_href('(Page source for debugging)', $debug_url))); } anewt_include('textformatting'); anewt_include('textile'); $text = file_get_contents(dirname(__FILE__) . '/sample-text.txt'); $formatted_text = TextFormatter::format($text, 'textile'); $p->append(ax_raw($formatted_text)); $p->flush();
<?php $div = ax_blockquote(ax_p('Some text in a blockquote.')); $div = ax_blockquote(array(ax_p('Some text in a blockquote.'), ax_p('Another paragraph in the same blockquote.'))); $p = ax_p(array('This is a ', ax_a_href('hyperlink', 'http://anewt.net'), ' inside some text.'));
function show() { $q = "SELECT f.id, f.url, f.title, t.id task, t.periodicity periodicity, t.state task_state, m.kind, m.tags, f.mod_date, \n count(i.feed_id) items, count(i.feed_id)-count(i.content_clean) errors, f.id 2_weeks\n FROM ssscrape.ssscrape_feed f \n LEFT JOIN ssscrape_feed_metadata m ON f.id=m.feed_id \n LEFT JOIN (SELECT feed_id, content_clean \n FROM ssscrape_feed_item \n WHERE ?temp-constraint?) i \n ON f.id=i.feed_id \n LEFT JOIN ssscrapecontrol.ssscrape_task t ON LOCATE(f.url, t.args)\n ?where?\n GROUP BY f.id"; $this->m->append(ax_p(ax_a_href("Create new feed", "editor/?show=feeds&id=NEW"))); $this->run_query($q, 'pub_date'); }
/** * Create an AnewtXHTMLParagraph element with a class. * \param $content The content for this element * \param $class The class name for this element * \param $attributes Additional element attributes (optional) */ function ax_p_class($content, $class, $attributes = null) { $element = ax_p($content, $attributes); $element->set_attribute('class', $class); return $element; }
$fragment->append_child(new AnewtXHTMLHeader2('Forms')); $form = new AnewtXHTMLForm(null, array('method' => 'GET')); $input_fragment = new AnewtXHTMLFragment(); $input_fragment->append_child(new AnewtXHTMLLabel('Label: ', array('for' => 'test'))); $input_fragment->append_child(new AnewtXHTMLInput(null, array('name' => 'test', 'id' => 'test', 'type' => 'text'))); $form->append_child(new AnewtXHTMLParagraph($input_fragment)); $select = new AnewtXHTMLSelect(null, array('name' => 'select')); $select->append_child(new AnewtXHTMLOption('First', array('value' => 'first'))); $select->append_child(new AnewtXHTMLOption('Second', array('value' => 'second'))); $select->append_child(new AnewtXHTMLOption('Third', array('value' => 'third'))); $form->append_child(new AnewtXHTMLParagraph($select)); $fragment->append_child($form); $form->append_child(new AnewtXHTMLParagraph(new AnewtXHTMLInput(null, array('type' => 'submit')))); /* Convenience API */ $r = array(); $r[] = ax_h2('Convenience API'); $r[] = ax_p('Test with some <& special characters.', array('style' => 'color: #ccc;')); $r[] = ax_p_class(ax_raw('This is <strong>strong</strong>'), 'someclass'); $r[] = ax_p(ax_abbr('ICE', 'InterCity Express')); $r[] = ax_p(array('Test', ax_br(), 'after the break')); $p = ax_p(array('testje', array('1', '2'), ax_strong('blablabla'))); $p->set_attribute('id', 'paragraph-id'); $p->set_class('foo bar baz'); $p->remove_class('bar'); $p->add_class('quux'); $p->append_child(ax_a_href('name', '/url/')); $r[] = $p; $r[] = ax_p(ax_sprintf('%s & %s', ax_span_class('Sugar', 'sweet'), 'Spice')); $fragment->append_child(ax_fragment($r, ax_p('final paragraph'))); /* Final output */ echo to_string($fragment), NL;
/** * \private * * Show a simple error page. * * \param $http_status_code * The http status code. */ function _show_error_page($http_status_code) { anewt_include('page'); $title = sprintf('%d - %s', $http_status_code, http_status_to_string($http_status_code)); $p = new AnewtPage(); $p->set('show-dublin-core', false); $p->set('title', $title); $p->append(ax_h1($title)); switch ($http_status_code) { case HTTP_STATUS_NOT_FOUND: $p->append(ax_p('The requested resource cannot be found.')); break; case HTTP_STATUS_FORBIDDEN: $p->append(ax_p('Access to the requested resource was denied.')); break; default: /* No explanation (just a title) */ break; } $p->flush(); }
<?php // This will result in <a href="#">...</a> showing up in your browser: $p = ax_p('This should be a <a href="#">hyperlink</a>, but it is not.'); // This will result in a functioning hyperlink: $p = ax_p(ax_raw('This is a real <a href="#">hyperlink</a>.')); // This is the same as the previous line of code: $p = new AnewtXHTMLParagraph(new AnewtXHTMLRaw('This is a real <a href="#">hyperlink</a>.'));
<?php anewt_include('page'); $p = new AnewtPage(); $p->append(ax_h1('Hello, world!')); $p->append(ax_p('This is a simple test page.')); $p->flush();
<?php anewt_include('page'); $p = new AnewtPage(); $p->blocks = array('header', 'content', 'footer'); $p->default_block = 'content'; /* Add content to specific blocks */ $p->append_to('header', ax_p('This is the header text.')); $p->append_to('footer', ax_p('This is the footer text.')); /* Add content to the default block */ $p->append(ax_h1('Hello, world!')); $p->append(ax_p('This is a simple test page.')); /* You can add content to the default block using append_to() as well, but that * involves a bit more typing. */ $p->append_to('content', ax_p('Another paragraph.')); $p->flush();
function build_header() { return ax_fragment(array(ax_p('Header line 1'), ax_p('Header line 2'))); }
<?php /* Build a fragment containing a few paragraphs of text */ $paragraphs = array(ax_p('Paragraph one.'), ax_p('Paragraph two.'), ax_p('Paragraph three.')); $fragment = ax_fragment($paragraphs); $fragment->append_child(ax_p('Paragraph four'));