Exemple #1
0
 function display_link($link, $row)
 {
     if ($link) {
         $link = ax_a_href_title(ax_raw("→"), $link, "permalink");
     }
     if ($row['link_src']) {
         $link = ax_fragment($link, ax_raw(' '), ax_a_href_title(ax_raw("⇒"), $row['link_src'], "source link"));
     }
     $link = ax_fragment($link, ax_a_href_title(ax_raw("<br/>t&rarr;"), "get_feed_item.php?id=" . $row['id'] . "&what=content_clean", "extracted text content"), ax_a_href_title(ax_raw("<br/>c&rarr;"), "get_feed_item.php?id=" . $row['id'] . "&what=content_clean_html&raw", "cleaned HTML"), ax_a_href_title(ax_raw("<br/>o&rarr;"), "get_feed_item.php?id=" . $row['id'] . "&what=content", "original HTML"));
     return $link;
 }
Exemple #2
0
 function count_jobs_by($table_name, $attr, $print_total_count)
 {
     $db = DB::get_instance();
     $q = "SELECT `{$attr}` as val, COUNT(*) c FROM {$table_name} ?where? group by `{$attr}`";
     $q = $this->prepare_query($q);
     $rows = $db->prepare_execute_fetch_all($q);
     $cnt = 0;
     $counts = array();
     array_push($counts, "By {$attr}: ");
     foreach ($rows as $row) {
         array_push($counts, ax_a_href_title(sprintf("%s: %s, ", $row['val'] ? $row['val'] : '""', $row['c']), $this->make_url(1, array($attr => $row['val'])), "show only " . $row['val'] . " jobs"));
         $cnt += $row['c'];
     }
     array_push($counts, ax_raw("<br/>"));
     if ($print_total_count) {
         array_unshift($counts, ax_raw("Total: {$cnt} jobs found<br/>"));
     }
     $this->m->append(ax_fragment($counts));
 }
Exemple #3
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;
 }
Exemple #4
0
 function build_header()
 {
     return ax_fragment(array(ax_p('Header line 1'), ax_p('Header line 2')));
 }
Exemple #5
0
 function build_header()
 {
     return ax_fragment(ax_javascript_src('js/prototype.js'), ax_javascript_src('js/utils.js'), ax_img_src_alt(IMG_URL . "ssscrape-logo-horizontal.png", "Ssscrape monitor"));
 }
Exemple #6
0
 function display_tags($tags, &$row)
 {
     if ($tags != $this->last_displayed_tags) {
         $row['css_class'] .= " first-row-in-group";
     }
     $this->last_displayed_tags = $tags;
     $f = ax_fragment();
     $tags = split(",", $tags);
     for ($i = 0; $i < count($tags); $i++) {
         $f->append_child(ax_a_href_title($tags[$i], $this->make_url(1, array('tags' => "HAS:" . $tags[$i])), "Only show rows with tag " . $tags[$i]));
         if ($i < count($tags) - 1) {
             $f->append_child(ax_raw(","));
         }
     }
     return $f;
 }
Exemple #7
0
$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;
Exemple #8
0
 function build_widget()
 {
     $value = $this->_get('value');
     if (is_null($value)) {
         $value = "";
     }
     assert('is_string($value); // only plain strings can be used as field value: type: ' . gettype($value));
     $name = $this->get('name');
     $widgets = array();
     if ($this->get('show-img-preview') && $value) {
         $widgets[] = ax_div_class(ax_img_src($this->get('preview-dir') . $value), 'preview');
     } elseif ($this->get('show-link-preview') && $value) {
         $widgets[] = ax_div_class(ax_a_href($value, $this->get('preview-dir') . $value), 'preview');
     }
     $remove_label = $this->_get('remove-label');
     if ($remove_label && $value) {
         $subattr = array('type' => 'checkbox', 'name' => $name . '-remove');
         $widgets[] = new AnewtXHTMLInput(null, $subattr);
         $subattr = array('for' => $name . '-remove');
         $widgets[] = new AnewtXHTMLLabel($remove_label, $subattr);
         $widgets[] = ax_br();
     }
     /* XML tag attributes used both for single line and multiline */
     $attr = array('name' => $this->get('name'), 'id' => $this->get('id'), 'type' => 'file');
     if ($this->_get('readonly')) {
         $attr['readonly'] = 'readonly';
     }
     if ($this->_get('disabled')) {
         $attr['disabled'] = 'disabled';
     }
     $size = $this->_get('size');
     if (!is_null($size)) {
         assert('is_int($size);');
         $attr['size'] = (string) $size;
     }
     $maxlength = $this->_get('maxlength');
     if (!is_null($maxlength)) {
         assert('is_int($maxlength);');
         $attr['maxlength'] = (string) $maxlength;
     }
     $max_file_size = $this->_get('max_file_size');
     if (!is_null($max_file_size)) {
         $subattr = array('type' => 'hidden', 'name' => 'MAX_FILE_SIZE', 'value' => (string) $max_file_size);
         $widgets[] = new AnewtXHMTLInput(null, $subattr);
     }
     $widget = new AnewtXHTMLInput(null, $attr);
     /* Styling */
     $widget->add_class('fileupload');
     if (!$this->_get('required')) {
         $widget->add_class('optional');
     }
     /* Optional extra class value */
     $class = $this->_get('class');
     if (!is_null($class)) {
         $widget->add_class($class);
     }
     /* Help text, if any */
     $help = $this->_get('help');
     if (!is_null($help)) {
         $help_text = to_string($help);
         $widget->set_attribute('title', $help_text);
         $widget->add_class('with-help');
     }
     $widgets[] = $widget;
     /* Add secondary label, if any */
     $secondary_label = $this->_get('secondary-label');
     if (!is_null($secondary_label)) {
         $widgets[] = $secondary_label;
     }
     $out = ax_fragment($widgets);
     return $out;
 }
Exemple #9
0
 function build_widget()
 {
     /* Convert value to string if possible */
     $value = $this->_get('value');
     if (is_null($value)) {
         $value = "";
     } elseif (is_int($value) || is_float($value)) {
         $value = (string) $value;
     }
     if (!is_string($value)) {
         throw new Exception(sprintf('Text control "%s" can only contain strings or numeric values (%s provided)', $this->get('name'), gettype($value)));
     }
     /* XML tag attributes used both for single line and multiline */
     $attr = array('name' => $this->get('name'), 'id' => $this->get('id'));
     if ($this->_get('readonly')) {
         $attr['readonly'] = 'readonly';
     }
     if ($this->_get('disabled')) {
         $attr['disabled'] = 'disabled';
     }
     /* Now differentiate between single and multiline controls */
     if ($this->_get('multiline')) {
         /* Output textarea element */
         $rows = $this->_get('rows');
         assert('is_int($rows)');
         $attr['rows'] = (string) $rows;
         $columns = $this->_get('columns');
         assert('is_int($columns)');
         $attr['cols'] = (string) $columns;
         $widget = new AnewtXHTMLTextarea($value, $attr);
         /* Styling */
         if (!$this->_get('required')) {
             $widget->add_class('optional');
         }
     } else {
         /* Output input element */
         $is_password = $this->_get('password');
         if ($is_password) {
             $attr['type'] = 'password';
         } else {
             $attr['type'] = 'text';
         }
         if ($this->_get('show-value')) {
             $attr['value'] = $value;
         } else {
             $attr['value'] = '';
         }
         $size = $this->_get('size');
         if (!is_null($size)) {
             assert('is_int($size);');
             $attr['size'] = (string) $size;
         }
         $maxlength = $this->_get('maxlength');
         if (!is_null($maxlength)) {
             assert('is_int($maxlength);');
             $attr['maxlength'] = (string) $maxlength;
         }
         $widget = new AnewtXHTMLInput(null, $attr);
         /* Styling */
         $widget->add_class('text');
         if ($is_password) {
             $widget->add_class('password');
         }
         if (!$this->_get('required')) {
             $widget->add_class('text-optional');
         }
     }
     /* Optional extra class value */
     $class = $this->_get('class');
     if (!is_null($class)) {
         $widget->add_class($class);
     }
     /* Help text, if any */
     $help = $this->_get('help');
     if (!is_null($help)) {
         $help_text = to_string($help);
         $widget->set_attribute('title', $help_text);
         $widget->add_class('with-help');
     }
     /* Add secondary label, if any */
     $secondary_label = $this->_get('secondary-label');
     if (is_null($secondary_label)) {
         $out = $widget;
     } else {
         $out = ax_fragment($widget, $secondary_label);
     }
     return $out;
 }
Exemple #10
0
<?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'));