/** * render * * @since 2.3.0 * * @param string $url * @param array $options * * @return string */ public static function render($url = null, $options = array()) { $output = ''; $counter = 0; /* html elements */ $titleElement = new Element('h3', array('class' => self::$_config['className']['title'])); $linkElement = new Element('a', array('target' => '_blank')); $boxElement = new Element('div', array('class' => self::$_config['className']['box'])); /* get contents */ $contents = file_get_contents($url); if ($contents) { $feed = new SimpleXMLElement($contents); $result = $feed->entry ? $feed->entry : $feed->channel->item; /* process result */ foreach ($result as $value) { /* break if limit reached */ if (++$counter > $options['limit']) { break; } /* handle feed type */ $url = $value->link['href'] ? (string) $value->link['href'] : (string) $value->link; $text = $value->summary ? $value->summary : $value->description; /* url */ if ($url) { $linkElement->attr('href', $url)->text($value->title); } else { $linkElement = $value->title; } /* collect output */ $output .= $titleElement->html($linkElement) . $boxElement->text($text); } } return $output; }
/** * render * * @since 2.2.0 * * @param mixed $src * @param array $options * * @return string */ public static function render($src = null, $options = array()) { $output = ''; /* device related images */ if (is_array($src)) { /* process source */ foreach ($src as $key => $value) { if (in_array($key, self::$_config['device']) && Registry::get('my' . ucfirst($key))) { $src = $value; } } } /* collect output */ if (file_exists($src)) { $imageElement = new Element('img', array('src' => self::$_config['placeholder'], 'class' => self::$_config['className']['image'] . ' ' . $options['className'], 'alt' => $options['alt'])); /* collect output */ $output = $imageElement->copy()->attr('data-src', $src); /* placeholder */ if (self::$_config['placeholder']) { /* calculate image ratio */ $imageDimensions = getimagesize($src); $imageRatio = $imageDimensions[1] / $imageDimensions[0] * 100; /* placeholder */ $placeholderElement = new Element('div', array('class' => self::$_config['className']['placeholder'], 'style' => 'padding-bottom:' . $imageRatio . '%')); /* collect output */ $output = $placeholderElement->html($output); } /* noscript fallback */ $output .= '<noscript>' . $imageElement . '</noscript>'; } return $output; }
/** * render * * @since 2.2.0 * * @return string */ public static function render() { $output = ''; $outputItem = ''; /* html elements */ $titleElement = new Element('h3', array('class' => self::$_config['className']['title'])); $linkElement = new Element('a'); $listElement = new Element('ul', array('class' => self::$_config['className']['list'])); /* fetch articles */ $articles = Db::forTablePrefix('articles')->where('status', 1)->whereIn('language', array(Registry::get('language'), ''))->orderByDesc('category')->findArray(); /* process articles */ if (empty($articles)) { $error = Language::get('article_no') . Language::get('point'); } else { $accessValidator = new Validator\Access(); $accessDeny = 0; $lastCategory = 0; foreach ($articles as $value) { if ($accessValidator->validate($value['access'], Registry::get('myGroups')) === Validator\ValidatorInterface::PASSED) { $currentCategory = $value['category']; /* collect output */ if ($lastCategory != $currentCategory) { if ($lastCategory > 0) { $output .= $listElement->html($outputItem); $outputItem = ''; } $output .= $titleElement->text($currentCategory < 1 ? Language::get('uncategorized') : Db::forTablePrefix('categories')->whereIdIs($currentCategory)->findOne()->title); } /* collect item output */ $outputItem .= '<li>'; $outputItem .= $linkElement->attr(array('href' => $value['category'] < 1 ? $value['alias'] : build_route('articles', $value['id']), 'title' => $value['description'] ? $value['description'] : $value['title']))->text($value['title']); $outputItem .= '</li>'; /* collect list output */ if (end($articles) === $value) { $output .= $listElement->html($outputItem); $outputItem = ''; } $lastCategory = $currentCategory; } else { $accessDeny++; } } /* handle access */ if (count($articles) === $accessDeny) { $error = Language::get('access_no') . Language::get('point'); } } /* handle error */ if ($error) { $output = $listElement->html('<li>' . $error . '</li>'); } return $output; }
/** * render * * @since 2.2.0 * * @param integer $lat * @param integer $lng * @param integer $zoom * * @return string */ public static function render($lat = 0, $lng = 0, $zoom = 0) { $mapElement = new Element('div', array('class' => self::$_config['className'])); /* collect attributes */ if (is_numeric($lat)) { $mapElement->attr('data-lat', $lat); } if (is_numeric($lng)) { $mapElement->attr('data-lng', $lng); } if (is_numeric($zoom)) { $mapElement->attr('data-zoom', $zoom); } $output = $mapElement; return $output; }
/** * render * * @since 2.2.0 * * @param string $url * * @return string */ public static function render($url = null) { $output = ''; if ($url) { /* html elements */ $linkElement = new Element('a', array('target' => '_blank')); $listElement = new Element('ul', array('class' => self::$_config['className']['list'])); /* process network */ foreach (self::$_config['network'] as $key => $value) { $output .= '<li>'; $output .= $linkElement->attr(array('href' => $value['url'] . $url, 'class' => self::$_config['className']['link'] . ' ' . $value['className'], 'data-type' => $key, 'data-height' => $value['height'], 'data-width' => $value['width']))->text($key); $output .= '</li>'; } /* collect list output */ if ($output) { $output = $listElement->html($output); } } return $output; }
/** * render * * @since 2.2.0 * * @param array $options * * @return string */ public static function render($options = array()) { $output = ''; $counter = 0; $log = self::_log(); /* html elements */ $linkElement = new Element('a'); $listElement = new Element('ul'); /* process log */ foreach ($log as $value) { /* break if limit reached */ if (++$counter > $options['limit']) { break; } $output .= '<li>'; $output .= $linkElement->attr(array('href' => Registry::get('rewriteRoute') . $value, 'title' => $value))->text($value); $output .= '</li>'; } /* collect list output */ if ($output) { $output = $listElement->attr('class', self::$_config['className']['list'])->html($output); } return $output; }
/** * parse the codequote tag * * @since 2.0.0 * * @param string $input content be parsed * * @return string */ protected function _parseCodequote($input = null) { $output = str_replace($this->_tags['codequote']['search'], $this->_delimiter, $input); $parts = array_filter(explode($this->_delimiter, $output)); $preElement = new Element('pre', array('class' => $this->_options['className']['codequote'])); /* parse needed parts */ foreach ($parts as $key => $value) { if ($key % 2) { $parts[$key] = $preElement->html(htmlspecialchars($value)); } } $output = implode($parts); return $output; }
/** * render * * @since 2.2.0 * * @param string $alias * @param string $path * * @return string */ public static function render($alias = null, $path = null) { $titleElement = new Element('h2', array('class' => 'title_content', 'title' => $alias)); $linkElement = new Element('a', array('href' => Registry::get('secondParameter') === $alias ? null : Registry::get('rewriteRoute') . 'preview/' . $alias, 'title' => $alias)); $linkElement->text($alias); /* collect output */ $output = $titleElement->html($linkElement); $output .= Template::partial($path); return $output; }
/** * testClean * * @since 2.2.0 */ public function testClean() { /* setup */ $element = new Element('a'); $element->text('test'); /* expect and actual */ $expect = '<a></a>'; $actual = $element->clean(); /* compare */ $this->assertEquals($expect, $actual); }
/** * render the breadcrumb trail as an unordered list * * @since 2.1.0 * * @return string */ public function render() { $output = Hook::trigger('breadcrumb_start'); $outputItem = ''; /* breadcrumb keys */ $breadcrumbKeys = array_keys($this->_breadcrumbArray); $lastKey = end($breadcrumbKeys); /* html elements */ $linkElement = new Element('a'); $itemElement = new Element('li'); $listElement = new Element('ul', array('class' => $this->_options['className']['list'])); /* collect item output */ foreach ($this->_breadcrumbArray as $key => $value) { $title = array_key_exists('title', $value) ? $value['title'] : null; $route = array_key_exists('route', $value) ? $value['route'] : null; if ($title) { $outputItem .= '<li>'; /* build link if route */ if ($route) { $outputItem .= $linkElement->attr(array('href' => $this->_registry->get('rewriteRoute') . $route, 'title' => $title))->text($title); } else { $outputItem .= $title; } $outputItem .= '</li>'; /* add divider */ if ($key !== $lastKey) { $outputItem .= $itemElement->addClass($this->_options['className']['divider'])->text(Db::getSettings('divider')); } } } /* collect list output */ if ($outputItem) { $output = $listElement->html($outputItem); } $output .= Hook::trigger('breadcrumb_end'); return $output; }