$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(); }
/** * \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 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 require_once dirname(__FILE__) . '/../../anewt.lib.php'; anewt_include('page'); anewt_include('renderer/grid'); $grid = new AnewtGridRenderer(); $column = new AnewtGridColumn('col-2', 'Second column', 2); $grid->add_column($column); $column = new AnewtGridColumn('somecol', 'First column', 1); $cell_renderer = new AnewtGridCellRenderer('col-1a', 'Column 1a'); $cell_renderer->set('title', 'Column 1a'); $column->add_cell_renderer($cell_renderer); $cell_renderer = new AnewtGridCellRenderer('col-1b', 'Column 1b'); $cell_renderer->set('title', 'Column 1b'); $column->add_cell_renderer($cell_renderer); $grid->add_column($column); $rows = array(array('col-1a' => 'r1c1a', 'col-1b' => 'r1c1b', 'col-2' => 'r1c2'), array('col-1a' => 'r2c1a', 'col-1b' => 'r2c1b', 'col-2' => 'r2c2')); $grid->set_rows($rows); $grid->add_row(array('col-1a' => 'r3c1a', 'col-2' => 'r3c2')); $p = new AnewtPage(); $p->set('title', 'Anewt Grid Renderer'); $p->append($grid); $p->flush();
} if (str_has_prefix($arg, '--')) { continue; } $fd = fopen($arg, 'r'); $title = $arg; break; } /* Input */ $input_chunks = array(); while (!feof($fd)) { $input_chunks[] = fread($fd, 16384); } $input = join('', $input_chunks); fclose($fd); /* Output */ $output = TextFormatter::format($input, 'textile'); $output = trim($output); if ($use_page) { anewt_include('page'); $page = new AnewtPage(); $page->enable_dublin_core = false; $page->content_type = 'application/xhtml+xml'; $page->charset = 'UTF-8'; $page->title = $title; $page->add_stylesheet_href_media('style.css', 'screen'); $page->append(ax_raw($output)); echo to_string($page), NL; } else { echo $output, NL; }
/** * \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(); }
$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')); $r[] = ax_p(ax_vsprintf('%s & %s', array(ax_span_class('Sugar', 'sweet'), 'Spice'))); $values = array('this', ax_strong('is'), 'a', ax_span('test')); $r[] = ax_p(ax_join(', ', $values)); $r[] = ax_p(ax_join(ax_em(' & '), $values)); $fragment->append_child(ax_fragment($r, ax_p('final paragraph'))); /* Final output */ anewt_include('page'); $page = new AnewtPage(); $page->title = 'Anewt XHTML output test'; $page->append($fragment); $page->flush();
<?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 $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();
$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); } } /* Show a page and test the form */ $page = new AnewtPage(); $page->set('title', 'Anewt form test page'); $page->add_stylesheet(ax_stylesheet($css)); $page->append(ax_h1('Test form')); $form = new TestForm(); assert('$form->get_control_value("text5") === "7"'); $form->set_control_value('text5', '8'); if ($form->autofill()) { if ($form->process()) { $page->append(ax_p('Form succesfully processed!')); } else { $page->append(ax_p('Error while processing form!')); } } else { $page->append(ax_p('Form not processed.')); } $fr = new AnewtFormRendererDefault(); $fr->set_form($form); $page->append(ax_h2('The form'));