/** * Display pagination html code. Must be initialized via (new SimplePagination([params]))->display(['class' => 'test']) * @param array|null $property * @return null|string */ public function display(array $property = null) { // total items is less to pagination requirement if ($this->page * $this->step + 1 > $this->total) { return null; } $lastPage = ceil($this->total / $this->step); // 6/5 ~ 2 = 0..2 if ($lastPage <= 1) { return null; } // prevent hack-boy's any try if ($this->page > $lastPage) { return null; } $items = []; // more then 10 items in pagination if ($lastPage > 10) { if ($this->page < 4 || $lastPage - $this->page <= 4) { // list start, page in [0..4] // from start to 4 $items = $this->generateItems(0, 4); // add "..." button $items[] = ['type' => 'link', 'link' => '#', 'text' => '...', 'property' => ['class' => 'disabled']]; // add middle page $middlePage = ceil($lastPage / 2); $items[] = ['type' => 'link', 'link' => $this->setUrlPage($middlePage), 'text' => $middlePage + 1]; // add "..." button $items[] = ['type' => 'link', 'link' => '#', 'text' => '...', 'property' => ['class' => 'disabled']]; $items = Arr::merge($items, $this->generateItems($lastPage - 4, $lastPage)); } else { // meanwhile on middle // generate 1-2 pages $items = $this->generateItems(0, 2); // add "..." button $items[] = ['type' => 'link', 'link' => '#', 'text' => '...', 'property' => ['class' => 'disabled']]; // add middle variance -3..mid..+3 $items = Arr::merge($items, $this->generateItems($this->page - 3, $this->page + 3)); // add "..." button $items[] = ['type' => 'link', 'link' => '#', 'text' => '...', 'property' => ['class' => 'disabled']]; // add latest 2 items $items = Arr::merge($items, $this->generateItems($lastPage - 2, $lastPage)); } } else { // less then 10 items in pagination $items = $this->generateItems(0, $lastPage); } return Listing::display(['type' => 'ul', 'property' => $property, 'items' => $items]); }
/** * Display language switcher as html or get builded result as array * @return array|null|string */ public function display() { // prevent loading on disabled multi-language property if ($this->multiLangEnabled !== true) { return null; } // check if languages is defined and count more then 1 if (!Obj::isArray($this->langs) || count($this->langs) < 2) { return null; } // build output items for listing $items = []; foreach ($this->langs as $lang) { $items[] = ['type' => 'link', 'link' => App::$Alias->baseUrlNoLang . '/' . $lang . App::$Request->getPathInfo(), 'text' => '<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="flag flag-' . $lang . '" alt="' . $lang . '"/>', 'html' => true, '!secure' => true]; } if ($this->onlyArrayItems) { return $items; } return Listing::display(['type' => 'ul', 'property' => $this->css, 'items' => $items]); }
<hr /> <p><?php echo __('Sitemap its a special application to generate sitemap as xml file over sitemap standart for search engines.'); ?> </p> <p><?php echo __('Sitemap main index'); ?> : <a href="<?php echo \App::$Alias->scriptUrl . '/sitemap'; ?> " target="_blank">/sitemap</a></p> <h3><?php echo __('Sitemap files'); ?> </h3> <?php $items = []; if ($model->files === null || count($model->files) < 1) { echo '<p class="alert alert-warning">' . __('No sitemap files found! Maybe cron manager is not configured') . '</p>'; return; } foreach ($model->files as $file) { $items[] = ['type' => 'link', 'link' => \App::$Alias->scriptUrl . $file, 'text' => $file, 'linkProperty' => ['target' => '_blank']]; } echo \Ffcms\Core\Helper\HTML\Listing::display(['type' => 'ul', 'items' => $items]); ?> <p><?php echo __('Attention! To generate newest sitemaps you should configure cron manager!'); ?> </p>
use Ffcms\Core\Helper\Url; /** @var \Apps\Model\Front\Profile\EntityNotificationsList $model */ /** @var \Ffcms\Core\Helper\HTML\SimplePagination $pagination */ $this->title = __('My notifications'); $this->breadcrumbs = [Url::to('main/index') => __('Home'), Url::to('profile/show', \App::$User->identity()->id) => __('Profile'), $this->title]; ?> <h1><?php echo __('Notifications'); ?> </h1> <hr /> <div class="row"> <div class="col-md-12"> <div class="pull-right"> <?php echo Listing::display(['type' => 'ul', 'property' => ['class' => 'list-inline'], 'items' => [['type' => 'link', 'link' => ['profile/notifications', 'all'], 'text' => __('All')], ['type' => 'link', 'link' => ['profile/notifications', 'unread'], 'text' => __('Unread')]]]); ?> </div> </div> </div> <?php if ($model->items === null || count($model->items) < 1) { echo '<p class="alert alert-warning">' . __('No notifications available') . '</p>'; return; } foreach ($model->items as $item) { ?> <div class="notice<?php echo $item['new'] ? ' notice-new' : ''; ?> ">
?> </div> </div> <hr /> <!-- Example internalization. File with translation: /Apps/View/Front/default/i18n/ru.php --> <?php echo __('Example of usage internalization in template. Test var: %var%', ['var' => 'some value']); ?> <hr /> <!-- Example of usage listing builder --> <?php echo Listing::display(['type' => 'ul', 'property' => ['id' => 'primary'], 'items' => [['type' => 'text', 'text' => 'Text li item', 'property' => ['class' => 'text-text'], 'html' => false], ['type' => 'link', 'link' => ['main/index'], 'text' => 'Link li item', 'property' => ['class' => 'text-text'], 'html' => false, 'activeClass' => 'active'], ['type' => 'link', 'link' => ['main/read', 'somePath1', 'somePath2', ['a' => 'wtf', 'd' => 'test']], 'text' => 'Link li item with params', 'html' => false, 'linkProperty' => ['id' => 'link1', 'class' => 'btn btn-info']]]]); ?> <hr /> <!-- Example of usage navigation builder --> <?php echo Nav::display(['property' => ['class' => 'nav-tabs'], 'tabAnchor' => 'n', 'items' => [['type' => 'link', 'text' => 'Link to main', 'link' => ['main/index', 'test']], ['type' => 'tab', 'text' => 'Tab 1', 'content' => 'This is tab 1 content with allowed <s>html</s> data!', 'htmlContent' => true], ['type' => 'tab', 'text' => 'Tab 2', 'content' => 'This is tab 2 content'], ['type' => 'tab', 'text' => 'Tab 3', 'content' => 'This is a tab 3 content']]]); ?> <hr /> <!-- Example of usage navbar builder --> <?php echo Navbar::display(['nav' => ['class' => 'navbar-default'], 'property' => ['id' => 'headmenu', 'class' => 'navbar-nav'], 'brand' => ['link' => 'main/to', 'text' => 'FFCMS'], 'collapseId' => 'collapse-object', 'items' => [['link' => ['main/index'], 'text' => 'Link 1', 'property' => ['class' => 'test1'], 'position' => 'left'], ['link' => 'main/other', 'text' => 'Link 2', 'position' => 'left'], ['link' => 'main/read', 'text' => 'Link 7', 'position' => 'right'], 'plaintext']]); ?>
$this->title = __('Demo app'); // set breadcrumbs $this->breadcrumbs = [Url::to('main/index') => __('Home'), __('Demo index')]; ?> <h1><?php echo __('Demo app index'); ?> </h1> <hr /> <p><?php echo __('This is a front-end page demoapp package. Here you can see some examples of usage.'); ?> </p> <p><?php echo __('Example of usage ActiveRecord result rendering in table'); ?> :</p> <?php // build items from sql query (activerecord usage) $items = []; foreach ($records as $row) { $items[] = [['text' => $row->id], ['text' => $row->text]]; } // display table with specified structure echo Table::display(['table' => ['class' => 'table table-bordered'], 'thead' => ['titles' => [['text' => 'id'], ['text' => 'text']]], 'tbody' => ['items' => $items]]); ?> <p>Other pages example:</p> <?php echo \Ffcms\Core\Helper\HTML\Listing::display(['type' => 'ul', 'id' => 'example-listing', 'items' => [['type' => 'link', 'link' => ['demoapp/pass', '123', 'test'], 'text' => 'Pass id=123, add=test to action'], ['type' => 'link', 'link' => ['demoapp/auth'], 'text' => 'Only for authorized users page']]]);
<?php } ?> <?php } ?> <?php $userMenu = null; if (true === $isSelf) { $userMenu = [['type' => 'link', 'link' => ['profile/avatar'], 'text' => '<i class="fa fa-camera"></i> ' . __('Avatar'), 'html' => true], ['type' => 'link', 'link' => ['profile/messages'], 'text' => '<i class="fa fa-envelope"></i> ' . __('Messages') . ' <span class="badge pm-count-block">0</span>', 'html' => true], ['type' => 'link', 'link' => ['profile/settings'], 'text' => '<i class="fa fa-cogs"></i> ' . __('Settings'), 'html' => true]]; } elseif (\App::$User->isAuth()) { $userMenu = [['type' => 'link', 'link' => Url::to('profile/messages', null, null, ['newdialog' => $user->id]), 'text' => '<i class="fa fa-pencil-square-o"></i> ' . __('Write message'), 'html' => true], ['type' => 'link', 'link' => Url::to('profile/ignore', null, null, ['id' => $user->id]), 'text' => '<i class="fa fa-user-times"></i> ' . __('Block'), 'html' => true, 'property' => ['class' => 'alert-danger']]]; } ?> <?php echo Listing::display(['type' => 'ul', 'property' => ['class' => 'nav nav-pills nav-stacked'], 'items' => $userMenu]); ?> </div> <div class="col-md-8"> <h2><?php echo __('Profile data'); ?> </h2> <div class="table-responsive"> <table class="table table-striped"> <tr> <td><?php echo __('Join date'); ?> </td> <td><?php
/** * Build bootstrap navbar * @param array $elements * @return NULL|string */ public static function display($elements) { // check if elements passed well if (!Obj::isArray($elements) || count($elements['items']) < 1) { return null; } // set default bootstrap properties if not defined $elements['property']['class'] = Str::concat(' ', 'nav', $elements['property']['class']); $elements['nav']['class'] = Str::concat(' ', 'navbar', $elements['nav']['class']); if ($elements['container'] === null) { $elements['container'] = 'container-fluid'; } // set mobile collapse id for toggle $mobCollapseId = $elements['collapseId']; if (Str::likeEmpty($mobCollapseId)) { $mobCollapseId = Str::randomLatin(mt_rand(6, 12)) . mt_rand(1, 99); } // set element id for toggle $ulId = 1; // prepare array's for left, right and static elements $itemsLeft = []; $itemsRight = []; $itemsStatic = null; foreach ($elements['items'] as $item) { if (Obj::isString($item)) { // sounds like a static object w/o render request $itemsStatic .= $item; } else { if ($item['type'] === 'dropdown') { // build bootstrap dropdown properties $item['dropdown'] = ['class' => 'dropdown-toggle', 'data-toggle' => 'dropdown', 'href' => '#']; $item['property']['class'] = Str::concat(' ', 'dropdown', $item['property']['class']); } else { $item['type'] = 'link'; } // set item with position if ($item['position'] !== null && $item['position'] === 'right') { // right position item $itemsRight[] = $item; } else { // left pos item $itemsLeft[] = $item; } } } // build html dom for left and right elements $leftBuild = null; $rightBuild = null; if (count($itemsLeft) > 0) { $mainElemLeft = $elements['property']; // todo: fix me!! $mainElemLeft['id'] .= $ulId; $ulId++; $leftBuild = Listing::display(['type' => 'ul', 'property' => $mainElemLeft, 'activeOrder' => $elements['activeOrder'], 'items' => $itemsLeft]); } if (count($itemsRight) > 0) { $mainElemRight = $elements['property']; // todo: fix me!! $mainElemRight['class'] .= ' navbar-right'; $mainElemRight['id'] .= $ulId; $ulId++; $rightBuild = Listing::display(['type' => 'ul', 'property' => $mainElemRight, 'activeOrder' => $elements['activeOrder'], 'items' => $itemsRight]); } // generate output dom of bootstrap navbar $dom = new Dom(); $body = $dom->div(function () use($leftBuild, $rightBuild, $itemsStatic) { return $leftBuild . $itemsStatic . $rightBuild; }, ['class' => 'collapse navbar-collapse', 'id' => $mobCollapseId]); // drow <nav @properties>@next</nav> return $dom->nav(function () use($dom, $elements, $mobCollapseId, $body) { // drow <div @container>@next</div> return $dom->div(function () use($dom, $elements, $mobCollapseId, $body) { // drow <div @navbar-header>@next</div> $header = $dom->div(function () use($dom, $elements, $mobCollapseId) { // drow <button @collapse>@next</button> $collapseButton = $dom->button(function () use($dom) { $toggleItem = $dom->span(function () { return 'Toggle menu'; }, ['class' => 'sr-only']); $toggleIcon = null; for ($i = 0; $i < 3; $i++) { $toggleIcon .= $dom->span(function () { return null; }, ['class' => 'icon-bar']); } return $toggleItem . $toggleIcon; }, ['type' => 'button', 'class' => 'navbar-toggle collapsed', 'data-toggle' => 'collapse', 'data-target' => '#' . $mobCollapseId]); // drow <div @brand>@brandtext<?div> $brand = null; if (isset($elements['brand'])) { if (isset($elements['brand']['link'])) { $brand = Url::link($elements['brand']['link'], $elements['brand']['text'], ['class' => 'navbar-brand']); } else { $brand = (new Dom())->span(function () use($elements) { return $elements['brand']['text']; }, ['class' => 'navbar-brand']); } } return $collapseButton . $brand; }, ['class' => 'navbar-header']); // return header and body concat return $header . $body; }, $elements['container']); }, $elements['nav']); }
/** * Display nav listing block * @param array $elements */ public static function display($elements) { // check if elements isn't empty and contains rows if (!Obj::isArray($elements) || count($elements['items']) < 1) { return null; } // prepare tab order if ($elements['tabAnchor'] === null) { $elements['tabAnchor'] = Str::randomLatin(mt_rand(6, 12)); } // set global element properties $blockProperty = []; if ($elements['blockProperty'] !== null) { if (Obj::isArray($elements['blockProperty'])) { $blockProperty = $elements['blockProperty']; } unset($elements['blockProperty']); } // check if items have defined active order $activeDefined = Arr::in(true, Arr::ploke('active', $elements['items'])); // prepare tab content $tabContent = null; $tabIdx = 1; // initialize dom model $dom = new Dom(); // prepare items to drow listing $items = []; foreach ($elements['items'] as $item) { // its just a link, drow it as is if ($item['type'] === 'link') { $items[] = $item; } elseif ($item['type'] === 'dropdown') { // build bootstrap dropdown properties $item['dropdown'] = ['class' => 'dropdown-toggle', 'data-toggle' => 'dropdown', 'href' => '#']; $item['property']['class'] = Str::concat(' ', 'dropdown', $item['property']['class']); $items[] = $item; } elseif ($item['type'] === 'tab') { $activeObject = false; $item['type'] = 'link'; // fix for global Listing builder $item['link'] = '#' . $elements['tabAnchor'] . $tabIdx; $item['property']['role'] = 'presentation'; // check if active definition is exist in elements options if ($activeDefined) { if ($item['active'] === true) { $activeObject = true; } } elseif ($tabIdx === 1) { // if not exist set first as active $activeObject = true; } // mark active tab if ($activeObject === true) { $item['property']['class'] .= (Str::length($item['property']['class']) > 0 ? ' ' : null) . 'active'; } // tab special properties for bootstrap $item['linkProperty']['aria-controls'] = $elements['tabAnchor'] . $tabIdx; $item['linkProperty']['role'] = 'tab'; $item['linkProperty']['data-toggle'] = 'tab'; $itemContent = $item['content']; unset($item['content']); $items[] = $item; // draw tab content $tabContent .= $dom->div(function () use($item, $itemContent) { if ($item['html'] === true) { if ($item['!secure'] === true) { return $itemContent; } else { return self::safe($itemContent, true); } } else { return self::nohtml($itemContent); } }, ['role' => 'tabpanel', 'class' => 'tab-pane fade' . ($activeObject === true ? ' in active' : null), 'id' => $elements['tabAnchor'] . $tabIdx]); $tabIdx++; } } // check if global class "nav" isset if ($elements['property']['class'] !== null) { if (!Str::contains('nav ', $elements['property']['class'])) { $elements['property']['class'] = 'nav ' . $elements['property']['class']; } } else { $elements['property']['class'] = 'nav'; } // render final output return $dom->div(function () use($elements, $items, $tabContent, $dom) { // drow listing $listing = Listing::display(['type' => 'ul', 'property' => $elements['property'], 'activeOrder' => $elements['activeOrder'], 'items' => $items]); // drow tabs if isset if ($tabContent !== null) { $tabContent = $dom->div(function () use($tabContent) { return $tabContent; }, ['class' => 'tab-content']); } return $listing . $tabContent; }, $blockProperty); }
?> <span class="fa arrow"></span></a> <?php echo Listing::display(['type' => 'ul', 'property' => ['class' => 'nav nav-second-level'], 'activeOrder' => 'controller', 'items' => $appMenuItems]); ?> </li> <li<?php echo Arr::in(\App::$Request->getController(), $widgetControllers) ? ' class="active"' : null; ?> > <a href="#"><i class="fa fa-puzzle-piece fa-fw"></i> <?php echo __('Widgets'); ?> <span class="fa arrow"></span></a> <?php echo Listing::display(['type' => 'ul', 'property' => ['class' => 'nav nav-second-level'], 'activeOrder' => 'controller', 'items' => $widgetMenuItems]); ?> </li> </ul> </div> <!-- /.sidebar-collapse --> </div> <!-- /.navbar-static-side --> </nav> <div id="page-wrapper"> <div class="row"> <div class="col-md-12"> <div class="site-index"> <?php if ($this->breadcrumbs !== null && Obj::isArray($this->breadcrumbs)) {