Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * 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);
 }