Skip to content

Instantly share code, notes, and snippets.

View Awilum's full-sized avatar
🧙‍♂️
WORK HARD. PLAY HARD

Sergey Romanenko Awilum

🧙‍♂️
WORK HARD. PLAY HARD
View GitHub Profile
@Awilum
Awilum / blog.php
Created December 16, 2018 12:26
Flextype: List of pages
<?php $posts = Content::getPages('blog', false , 'date') ?>
<?php foreach($posts as $post):?>
<h3><a href="<?= $post['url'] ?>"><?= $post['title'] ?></a></h3>
<?php endforeach ?>
Entry.php
private static function init() : void
{
// Init Parsers
Entry::initParsers();
// Route for all pages
Router::route('*', function(){
Entry::processCurrentEntry();
// Simple text-input, for multi-line fields.
textarea
// The hidden field is like the text field, except it's hidden from the content editor.
hidden
// A WYSIWYG HTML field.
html
// A specific WYSIWYG HTML field for entry content editing
@Awilum
Awilum / multi_language_entries
Created January 18, 2019 13:07
multi_language_entries
$multi_language_entries = true;
// Set current requested entry data to global $entry array
if ($multi_language_entries) {
$locales = ['ru', 'en'];
$default_locale = 'en';
if (in_array(Http::getUriSegment(0), $locales)) {
if (Http::getUriSegment(0) == $default_locale) {
<ul class="navbar-nav">
<?php foreach (Arr::sort(Menus::get('default')['items'], 'order') as $item): ?>
<li class="nav-item">
<a class="nav-link <?php if ($item['url'] !== '' && strpos(Http::getUriString(), $item['url']) !== false): ?>active<?php endif ?>" href="<?php if(isset($item['external'])): ?> <?= $item['url'] ?> <?php else: ?> <?= Http::getBaseUrl() . '/' . $item['url'] ?> <?php endif ?>"><?= $item['title'] ?></a>
</li>
<?php endforeach ?>
</ul>
<?php
/**
* @package Flextype
*
* @author Sergey Romanenko <awilum@yandex.ru>
* @link http://flextype.org
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@Awilum
Awilum / Http
Created February 6, 2019 07:46
<?php
/**
* @package Flextype Components
*
* @author Sergey Romanenko <awilum@yandex.ru>
* @link http://components.flextype.org
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
<?php
namespace Flextype;
use Flextype\Component\Event\Event;
use Flextype\Component\Filesystem\Filesystem;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
// Event: onShortcodesInitialized
Event::addListener('onShortcodesInitialized', function () {
for ($i=0; $i < 10000; $i++) {
mkdir(__DIR__ . '/site/entries/blog/' . 'post' . $i);
file_put_contents(__DIR__ . '/site/entries/blog/' . 'post' . $i . '/entry.md',"
---
title: 'Allamco laboris nisi ut aliquip nisi ut aliquip {$i}'
summary: '<p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>'
template: blog-post
fieldset: blog-post
description: ''
uuid: 81ce89fa-7a95-4a01-b37f-b7f9b7dc2c9a
protected function checkboxField(string $element, string $name, $value, array $property) : string
{
$field = '<div class="form-group ' . $property['size'] . '">';
$field .= '<div class="custom-control custom-checkbox">';
$field .= '<input type="checkbox" value="'. ($value == 'checked' ? 'checked' : '') .'" name="'. $name .'" class="custom-control-input" id="'. $element .'" '. ($value == 'checked' ? 'checked="checked"' : '') .'>';
$field .= ($property['title'] ? '<label class="custom-control-label" for="'. $element .'">'. __($property['title']) .'</label>' : '');
$field .= '</div>';
$field .= '</div>';
return $field;