Example #1
0
 /**
  * Render this page into XHTML.
  *
  * This methods renders the whole page into a complete XHTML page. Usually
  * you want to use flush() to output the page to the browser.
  *
  * \return
  *   The rendered page as a string.
  *
  * \see AnewtPage::flush
  */
 public function render()
 {
     /* Create basic element nodes */
     $head = new AnewtXMLDomElement('head');
     $body = new AnewtXMLDomElement('body');
     $head->always_render_closing_tag = true;
     $body->always_render_closing_tag = true;
     /* Content-type in meta tag. This must be the first element inside the
      * <head>...</head> element. */
     $head->append_child(ax_meta(array('http-equiv' => 'Content-type', 'content' => $this->build_content_type_charset())));
     /* Base URI */
     $base_uri = $this->_get('base-uri');
     if (!is_null($base_uri)) {
         assert('is_string($base_uri); // base-uri must be a simple string');
         /* Employ a simple heuristic to make sure we use an absolute URI, as
          * is required by the HTML specification. */
         if (!str_contains($base_uri, '://')) {
             $base_uri = AnewtRequest::canonical_base_url() . $base_uri;
         }
         $base = new AnewtXHTMLBase();
         $base->set_attribute('href', $base_uri);
         $head->append_child($base);
     }
     /* Page title (always include, even if empty, since this is required by
      * the HTML specification) */
     $title = $this->_get('title');
     $head->append_child(ax_title($title));
     /* Dublin Core metadata. See http://dublincore.org/documents/dcq-html/ * */
     if ($this->_get('show-dublin-core')) {
         $head->append_child(ax_link(array('rel' => 'schema.DC', 'href' => 'http://purl.org/dc/elements/1.1/')));
         $head->append_child(ax_meta_name_content('DC.language', $this->_get('language')));
         if (!is_null($title)) {
             $head->append_child(ax_meta_name_content('DC.title', $title));
         }
         if ($this->_isset('creator')) {
             $head->append_child(ax_meta_name_content('DC.creator', $this->_get('creator')));
         }
         if ($this->_isset('description')) {
             $head->append_child(ax_meta_name_content('DC.description', $this->_get('description')));
         }
         if ($this->_isset('date')) {
             $date = $this->get('date');
         } else {
             $date = AnewtDateTime::now();
         }
         $head->append_child(ax_meta_name_content('DC.date', AnewtDateTime::date($date)));
     }
     /* Powered by Anewt! */
     $generator = $this->_get('generator');
     if (!is_null($generator)) {
         assert('is_string($generator);');
         $head->append_child(ax_meta_name_content('generator', $generator));
     }
     /* Robots */
     $robots = $this->_get('robots');
     if (!is_null($robots)) {
         assert('is_string($robots);');
         $head->append_child(ax_meta(array('name' => 'robots', 'content' => $robots)));
     }
     /* Links (including stylesheets) and JavaScripts */
     $head->append_children($this->_links);
     $head->append_children($this->_javascripts);
     /* Favicon */
     $favicon = $this->_get('favicon');
     if (!is_null($favicon)) {
         assert('is_string($favicon);');
         $head->append_child(ax_link_favicon($favicon));
     }
     /* Body content */
     if ($this->_get('blocks')) {
         /* This is a page using div blocks */
         if ($this->_content && $this->_content->has_child_nodes()) {
             throw new AnewtException('Pages using blocks should not have content outside blocks.');
         }
         /* The buffer holding all content is either a wrapper div or an
          * invisible fragment (both XML nodes, so the API is the same). */
         if ($this->_get('use-wrapper-div')) {
             $buffer = ax_div_id(null, $this->_get('wrapper-div-id'));
         } else {
             $buffer = ax_fragment();
         }
         /* Add the content */
         foreach ($this->_get('blocks') as $block_name) {
             $block = $this->get_block($block_name);
             $buffer->append_child(ax_div_id($block, $block_name));
             unset($block);
             unset($div);
         }
         $body->append_child($buffer);
     } else {
         /* This page has no blocks, so we use the nodes in _content instead
          * (if any) */
         if ($this->_blocks) {
             throw new AnewtException('Pages not using blocks should not have content in blocks');
         }
         if ($this->_content) {
             $body->append_child($this->_content);
         }
     }
     /* Assemble the top level elements */
     $document = new AnewtXMLDomDocument();
     $document->set_document_type($this->_get('document-type'));
     $document->set_content_type($this->_get('content-type'));
     $document->set_encoding($this->_get('encoding'));
     $html = new AnewtXMLDomElement('html', array('xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => $this->_get('language'), 'lang' => $this->_get('language')));
     $html->append_child($head);
     $html->append_child($body);
     $document->append_child($html);
     return $document;
 }
Example #2
0
<?php

require_once dirname(__FILE__) . '/../anewt.lib.php';
anewt_include('calendar');
$calendar = new AnewtCalendar();
$event = new AnewtCalendarEvent('Title');
$event->date_start = AnewtDateTime::parse_string('2009-01-01 12:00');
$event->date_end = AnewtDateTime::parse_string('2009-01-01 14:00');
$event->summary = 'This is the summary';
$event->location = 'This is the location';
$event->url = 'http://example.org/foo';
$event->uid = 'abc1234567890';
$calendar->add_event($event);
$event = new AnewtCalendarEvent('Another event', AnewtDateTime::now());
$event->summary = "This is a multiline\nsummary";
$event->summary = "This is a multiline\ndescription";
$calendar->add_event($event);
$calendar->flush();
Example #3
0
<?php

error_reporting(E_ALL | E_STRICT);
require_once dirname(__FILE__) . '/../anewt.lib.php';
anewt_include('rss');
$channel = new AnewtRssChannel('Title', 'http://example.com', 'This is a test');
$channel->set('author', 'Anewt test');
$channel->set('build-date', AnewtDateTime::now());
$item = new AnewtRssItem('test', 'http://example.com/some-item');
$item->set('description', 'The description goes here.');
$item->set('guid', 'http://example.com/some-item');
$item->set('date', AnewtDateTime::now());
$channel->add_item($item);
$item = new AnewtRssItem('another test');
$item->set('description', 'The description goes here.');
$item->set('link', 'http://example.com/another-item');
$item->set('guid', 'http://example.com/another-item');
$item->set('date', AnewtDateTime::now());
$channel->add_item($item);
$channel->flush();
Example #4
0
 /**
  * Construct a new AnewtCalendarEvent instance.
  *
  * If you don't specify \c $summary or \c $date_start these values need to
  * be set later.
  *
  * \param $summary
  *   A summary line for this event (optional).
  *
  * \param $date_start
  *   A AnewtDateTimeAtom instance describing the start date for this event
  *   (optional).
  */
 function __construct($summary = null, $date_start = null)
 {
     parent::__construct();
     $now = AnewtDateTime::now();
     $this->_seed(array('uid' => null, 'summary' => null, 'description' => null, 'location' => null, 'url' => null, 'date-start' => $now, 'date-end' => $now, 'all-day' => false, 'transparent' => false));
     if (!is_null($summary)) {
         assert('is_string($summary)');
         $this->summary = $summary;
     }
     if (!is_null($date_start)) {
         assert('$date_start instanceof AnewtDateTimeAtom');
         $this->date_start = $date_start;
     }
 }
Example #5
0
 function valid_values_provider()
 {
     return array(array(null, null, null, null, null, null, null, null, null), array(true, null, null, null, null, null, null, null, null), array(false, null, null, null, null, null, null, null, null), array(null, 2, null, null, null, null, null, null, null), array(null, '3', null, null, null, null, null, null, null), array(null, null, 2.0, null, null, null, null, null, null), array(null, null, 1.234, null, null, null, null, null, null), array(null, null, 3, null, null, null, null, null, null), array(null, null, null, 'Test', null, null, null, null, null), array(null, null, null, 'Te\';st', null, null, null, null, null), array(null, null, null, "\t\n;--'", null, null, null, null, null), array(null, null, null, 2, null, null, null, null, null), array(null, null, null, new StringWrap(), null, null, null, null, null), array(null, null, null, null, '2006-06-06', null, null, null, null), array(null, null, null, null, AnewtDateTime::now(), null, null, null, null), array(null, null, null, null, null, '2006-06-06 06:06:06', null, null, null), array(null, null, null, null, null, AnewtDateTime::now(), null, null, null), array(null, null, null, null, null, AnewtDateTime::sql(AnewtDateTime::now()), null, null, null), array(null, null, null, null, null, null, '2006-06-06 06:06:06', null, null), array(null, null, null, null, null, null, AnewtDateTime::now(), null, null), array(null, null, null, null, null, null, AnewtDateTime::sql(AnewtDateTime::now()), null, null), array(null, null, null, null, null, null, null, '06:06:06', null), array(null, null, null, null, null, null, null, AnewtDateTime::now(), null), array(null, null, null, null, null, null, null, AnewtDateTime::sql_time(AnewtDateTime::now()), null), array(null, null, null, null, null, null, null, null, "'?int?'"), array(true, 3, 2.0, 'Test', '2006-06-06', '2006-06-06 06:06:06', '2006-06-06 06:06:06', '06:06:06', "'?raw?'"));
 }
Example #6
0
 /**
  * Log a message.
  *
  * \param $domain
  * \param $level
  * \param $message
  *
  * \see AnewtLogHandlerBase::log
  */
 public function log($domain, $level, $message)
 {
     $name = AnewtLog::loglevel_to_string($level);
     $output = $this->format_log_message($domain, $level, $message);
     /* Optionally prefix with timestamp */
     if ($this->timestamps) {
         $date = AnewtDateTime::iso8601(AnewtDateTime::now());
         $output = sprintf('[%s] %s', $date, $output);
     }
     /* Make sure there is a trailing newline */
     if (!str_has_prefix($output, NL)) {
         $output .= NL;
     }
     fwrite($this->fp, $output);
 }
Example #7
0
$values->set('datetime_var', '2006-06-06 06:06:06');
$pq->execute($values);
$values->set('datetime_var', AnewtDateTime::now());
$pq->execute($values);
$values->set('datetime_var', AnewtDateTime::sql(AnewtDateTime::now()));
$pq->execute($values);
$values->set('datetime_var', null);
/* Test timestamps */
$values->set('timestamp_var', '2006-06-06 06:06:06');
$pq->execute($values);
$values->set('timestamp_var', AnewtDateTime::now());
$pq->execute($values);
$values->set('timestamp_var', AnewtDateTime::sql(AnewtDateTime::now()));
$pq->execute($values);
$values->set('timestamp_var', null);
/* Test times */
$values->set('time_var', '06:06:06');
$pq->execute($values);
$values->set('time_var', AnewtDateTime::now());
$pq->execute($values);
$values->set('time_var', null);
/* Test raw */
$values->set('raw_var', '"?int?"');
$pq->execute($values);
$values->set('raw_var', null);
/* Test all at once */
$values->seed(array('bool_var' => true, 'int_var' => 3, 'float_var' => 2.0, 'string_var' => 'Test', 'date_var' => '2006-06-06', 'datetime_var' => '2006-06-06 06:06:06', 'timestamp_var' => '2006-06-06 06:06:06', 'time_var' => '06:06:06', 'raw_var' => '"?raw?"'));
$pq->execute($values);
$db->transaction_commit();
/* TODO: test column and table types */
$db->disconnect();
Example #8
0
 /**
  * Return a string representing this event.
  *
  * \return
  *   String with iCalender data.
  */
 function to_ical()
 {
     $r = array();
     $r[] = 'BEGIN:VEVENT';
     /* Generation date */
     $r[] = sprintf('DTSTAMP;VALUE=DATE:%s', AnewtDateTime::iso8601_compact(AnewtDateTime::now()));
     /* Summary */
     $r[] = sprintf('SUMMARY:%s', $this->get('summary'));
     /* Description */
     if (!$this->is_set('description')) {
         $this->set('description', $this->get('summary'));
     }
     $r[] = sprintf('DESCRIPTION:%s', $this->get('description'));
     /* Unique ID */
     if (!$this->is_set('uid')) {
         /* Generate a unique id */
         $uid = strtoupper(sprintf('%s-%s', md5($this->get('summary')), md5(AnewtDateTime::iso8601_compact($this->get('datestart')))));
         $this->set('uid', $uid);
     }
     $r[] = sprintf('UID:%s', $this->get('uid'));
     /* All day event? */
     $all_day = $this->get('all-day');
     assert('is_bool($all_day)');
     /* Start date */
     $datestart = $this->get('datestart');
     $datestart_str = $all_day ? AnewtDateTime::iso8601_date_compact($datestart) : AnewtDateTime::iso8601_compact($datestart);
     /* with time */
     $r[] = sprintf('DTSTART;VALUE=DATE:%s', $datestart_str);
     /* End date */
     if ($this->is_set('dateend')) {
         $dateend = $this->get('dateend');
         assert('$dateend instanceof AnewtDateTimeAtom');
         $dateend_str = $all_day ? AnewtDateTime::iso8601_date_compact($dateend) : AnewtDateTime::iso8601_compact($dateend);
         /* with time */
         $r[] = sprintf('DTEND;VALUE=DATE:%s', $dateend_str);
     }
     /* Transparency */
     $transparent = $this->getdefault('transparent', false);
     assert('is_bool($transparent)');
     $r[] = sprintf('TRANSP:%s', $transparent ? 'TRANSPARENT' : 'OPAQUE');
     /* Location  */
     if ($this->is_set('location')) {
         $r[] = sprintf('LOCATION:%s', $this->get('location'));
     }
     /* URL  */
     if ($this->is_set('url')) {
         $r[] = sprintf('URL:%s', $this->get('url'));
     }
     $r[] = 'END:VEVENT';
     $r[] = '';
     return implode("\r\n", $r);
 }