Example #1
0
 public function renderStatic(html_form $form, $name, $input, $label, model_editor $editor, model_editor_field $field)
 {
     $value = $this->formatValue($name, $input, $editor, $field);
     $classes = array($this->class, 'date', preg_replace('/\\W/', '', $this->staticFormat));
     $classes = implode(' ', array_filter($classes));
     $form->setRow($name, $label, markup::inline($value, 'static'), $this->isMandatory, null, null, $classes);
     return $this;
 }
Example #2
0
 /**
  * Extracts existing links from provided HTML fragment to be wrapped in a
  * new link prior to appending extracted links.
  *
  * @param callable|null $processor callback invoked per found link to
  *        generate related link to be appended later, omit to keep extracted
  *        link as-is
  * @param string|null $link URL of link to be wrapping provided HTML
  *        fragment, null to extract contained links, but skip eventual
  *        generation of link
  * @param string $label HTML fragment to extract additional links from and
  *        wrap in link afterwards
  * @param string|null $class classes to apply on link generated eventually
  * @param string|null $title title of link generated eventually
  * @param bool $external true if eventually generated link is linking sth.
  *        external
  * @return string resulting HTML fragment
  */
 public static function extendLink($processor, $link, $label, $class = null, $title = null, $external = false)
 {
     if (!is_callable($processor)) {
         $processor = function ($options) {
             return markup::link($options['href'], $options['label'], $options['class'], $options['title'], !array_key_exists('onclick', $options));
         };
     }
     if (preg_match_all('#<a\\s([^>]+)>#i', $label, $links, PREG_SET_ORDER)) {
         $tail = implode(' ', array_map(function ($link) use($processor) {
             $opts = array();
             $index = 0;
             while (preg_match('/\\s*([^=]+)=("[^"]*"|\'[^\']*\')/', $link[1], $next, PREG_OFFSET_CAPTURE, $index)) {
                 $index = $next[0][1] + strlen($next[0][0]);
                 $name = trim($next[1][0]);
                 $value = substr($next[2][0], 1, -1);
                 $opts[$name] = $value;
             }
             return call_user_func($processor, $opts);
         }, $links));
     } else {
         $tail = '';
     }
     $label = strip_tags($label);
     return trim(($link ? markup::link($link, $label, $class, $title, $external) : $label) . ' ' . $tail);
 }
Example #3
0
 /**
  * Retrieves markup/code of databrowser to be embedded in view.
  *
  * @return string markup/code of databrowser
  */
 public function getCode()
 {
     // get items to render in databrowser
     try {
         $this->processInput();
         $items = $this->getItems();
     } catch (\RuntimeException $e) {
         return markup::paragraph(markup::emphasize(_L('Failed to query datasource for listing items.')));
     }
     // render table including related pager widget
     if (count($items)) {
         // fetch form to use optionally
         $form = $this->getForm();
         $volatiles = _A(config::get('databrowser.volatiles', array()))->elements;
         $available = input::listNames();
         foreach ($volatiles as $volatile) {
             if (in_array($volatile, $available)) {
                 $form->setHidden($volatile, input::vget($volatile));
             }
         }
         // split items into raw data and additionally delivered data per row
         $rows = $extras = array();
         foreach ($items as $key => $row) {
             $rows[$key] = $row;
             unset($rows[$key]['|extra']);
             $extras[$key] = $row['|extra'];
         }
         // use local callback to wrap custom cell formatter for enriching
         // with additional data per row
         $browser = $this;
         $cellFormatter = function ($value, $name, $item, $id) use($browser, $extras) {
             return $browser->formatCell($value, $name, $item, $id, $extras[$id]);
         };
         // render table view
         $id = $form ? null : $this->datasource->name();
         $table = html::arrayToTable($rows, $id, $cellFormatter, array(&$this, 'formatHeader'), '', '', $this->className);
         $code = $this->pager . $table;
         // wrap rendered table view in form
         if ($form && !$this->callerForm) {
             $code = (string) $form->addContent($code);
         }
         // return code of rendered databrowser
         return $code;
     }
     $text = $this->emptyText ? $this->emptyText : _L('There is no data to be listed here ...');
     return markup::paragraph(markup::emphasize($text), trim($this->className . ' empty-text'));
 }
Example #4
0
 /**
  * Links all parts of provided code that are not linking already.
  *
  * @param string $in HTML code to be linked
  * @param string $link URL of link target
  * @param string $classes classes to use on linking
  * @param string $title title to use on linking
  * @param boolean $external true if link is considered external (to be opened in new window)
  * @return string revised HTML code
  */
 public static function linkStatic($link, $in, $classes = null, $title = null, $external = false)
 {
     $chunks = preg_split('#(<a\\s|</a>)#', $in, null, PREG_SPLIT_DELIM_CAPTURE);
     $out = '';
     for ($i = 0; $i < count($chunks); $i++) {
         if (strtolower(trim($chunks[$i])) === '<a') {
             $out .= $chunks[$i] . $chunks[$i + 1] . $chunks[$i + 2];
             $i += 2;
         } else {
             $out .= preg_replace_callback('#(^\\]?\\s*[;,.:]?\\s*)(.*?)(\\s*[;,.:]?\\s*\\[?$)#', function ($matches) use($link, $classes, $title, $external) {
                 if ($matches[2]) {
                     return $matches[1] . markup::link($link, $matches[2], $classes, $title, $external) . $matches[3];
                 }
                 return $matches[1] . $matches[3];
             }, $chunks[$i]);
         }
     }
     return $out;
 }
Example #5
0
 /**
  * @brief Loads a wiki page
  *
  * Will attempt to load a wiki page from the database. If revision is not
  * specified, the latest revision will be loaded.
  *
  * @param String $page
  * @param Int $revision
  * @return Boolean True on success, false otherwise
  */
 function loadWikiPage($page, $revision = null)
 {
     $db = new DatabaseConnection();
     list($ns, $name) = $this->splitUri($page, 'wiki');
     if (!$revision) {
         $pd = $db->getSingleRow("SELECT * FROM wikipages WHERE pagens=%s AND pagename=%s " . "ORDER BY revision DESC LIMIT 1;", $ns, $name);
     } else {
         $pd = $db->getSingleRow("SELECT * FROM wikipages WHERE pagens=%s AND pagename=%s AND " . "revision<%d ORDER BY revision DESC LIMIT 1;", $ns, $name, $revision);
     }
     if ($pd) {
         $revs = $db->getSingleRow("SELECT revision FROM wikipages WHERE pagens=%s AND pagename=%s", $ns, $name);
         foreach ($revs as $rev) {
             $this->revisions[] = $rev['revision'];
         }
         if ($pd['format'] != NULL) {
             $this->markup = $pd['markuptype'];
             $this->parser = markup::factory($this->markup);
         }
         $this->content = $pd['content'];
         $this->pagerevision = $pd['revision'];
         $this->modified = false;
         $this->pagens = $pd['pagens'];
         $this->pagename = $pd['pagename'];
         $this->pagetitle = $pd['pagetitle'];
         return true;
     } else {
         return false;
     }
 }