Esempio n. 1
0
        $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();
}
Esempio n. 2
0
<?php

require_once dirname(__FILE__) . '/../anewt.lib.php';
anewt_include('page');
class TestPage extends AnewtPage
{
    function __construct()
    {
        parent::__construct();
        $this->set('blocks', array('header', 'main', 'footer'));
    }
    function build_header()
    {
        return ax_fragment(array(ax_p('Header line 1'), ax_p('Header line 2')));
    }
}
$p = new TestPage();
$p->title = 'Anewt Page test';
$p->default_block = 'main';
$p->add_stylesheet_href('1.css');
$p->add_stylesheet_href('2.css');
$p->add_stylesheet(ax_stylesheet_href('3.css'));
$p->add_stylesheet(ax_stylesheet_href_media('screen.css', 'screen'));
$p->add_stylesheet_href_media('print.css', 'print');
$p->add_javascript_content('function test() {alert("test");}');
$p->add_javascript_src('foo.js');
$p->append_to('main', ax_h1('Title'));
$p->append(ax_p('Test paragraph'));
$p->append(ax_p(ax_a_href('Click me!', 'javascript:test()')));
$p->append_to('footer', ax_p('This is the footer text'));
$p->flush();
Esempio n. 3
0
<?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();
Esempio n. 4
0
 /**
  * \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();
 }
Esempio n. 5
0
 /**
  * \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();
 }
Esempio n. 6
0
/**
 * Create an AnewtXHTMLHeader element for the specified header level.
 * \param $level The header level (1, 2, 3, 4, 5, or 6)
 * \param $content The content for this element
 * \param $attributes Additional element attributes (optional)
 */
function ax_h($level, $content, $attributes = null)
{
    assert('is_int($level);');
    $level = max(min($level, 6), 1);
    switch ($level) {
        case 1:
            return ax_h1($content, $attributes);
        case 2:
            return ax_h2($content, $attributes);
        case 3:
            return ax_h3($content, $attributes);
        case 4:
            return ax_h4($content, $attributes);
        case 5:
            return ax_h5($content, $attributes);
        case 6:
            return ax_h6($content, $attributes);
    }
}
Esempio n. 7
0
        $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'));