/ Gists

Gists

On gists

Transition mixin

SCSS

usage.css #

a {
  color: gray;
  @include transition(color .3s ease);
  &:hover {
    color: black;
  }
}

On gists

Keyframes mixin

SCSS

usage.css #

@include keyframes(slide-down) {
  0% { opacity: 1; }
  90% { opacity: 0; }
}

.element {
  width: 100px;
  height: 100px;
  background: black;
  @include animation('slide-down 5s 3');
}

On gists

Prefixer mixin

SCSS

Prefixer.scss #

@mixin prefixer($property, $value) {
    @each $prefix in -webkit-, -moz-, -ms-, -o-, '' {
    #{$prefix}#{$property}: $value;
    }
}

On gists

Spojení pole do multitříd

SCSS

SassMeister-output.css #

.netolicak, kcko {
  color: pink;
}

On gists

Partial rendering - nette, latte, formuláře

Nette-Tricks

Partial rendering.latte #

{foreach $form[gender]->items as $key => $label}
    <label n:name="gender:$key"><input n:name="gender:$key"> {$label}</label>
{/foreach}

On gists

Serverová ochrana PHP AUTH

PHP

PHP AUTH.php #

<?

$LoginSuccessful = false;
$login = $password = 'xxx';
 
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){
 
    $Username = $_SERVER['PHP_AUTH_USER'];
    $Password = $_SERVER['PHP_AUTH_PW'];
 
    if ($Username == $login && $Password == $password){
        $LoginSuccessful = true;
    }
}

if (!$LoginSuccessful)
{

    header('WWW-Authenticate: Basic realm="Secret page"');
    header('HTTP/1.0 401 Unauthorized');
 
    print "Login failed!\n";
    exit(0);
 
}




On gists

Ajaxové načítaní při onscrollu

jQuery

LoadNext-Onscroll.js #

    if($('.load-next').length > 0) {

        var $window = $(window);

        $(window).scroll(function(){

            var $loadNext = $('.load-next');

            if($loadNext.length) {

                var winHeight = $window.height();
                var scrollTop  = $window.scrollTop();
                var loadNextOffset = $loadNext.offset();

                if((winHeight + scrollTop + 200) > loadNextOffset.top) {
                    $loadNext.trigger('click').remove();
                }

            }


        });

    }

On gists

Z latte sablony sahnuti do presenteru / contextu

Nette-Latte

Z latte sablony pres context.php #

{var $database = $presenter->context->getByType('Nette\Database\Context')}

On gists

Přesmerování z lokální na dev - obrázky

Nette

Local redirect to develop server #

RewriteCond %{REQUEST_URI} ^/storage/images/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://domena/$1 [R=301,QSA]

On gists

Nette antispam control

Nette

AntispamControl.php #

<?php

use Nette\Forms\Controls\TextInput,
	Nette\Forms\Form,
	Nette\Utils\Html;



/**
 * AntispamControl
 * add basic antispam feature to Nette forms. 
 *
 * <code>
 * // Register extension
 * AntispamControl::register();
 * 
 * // Add antispam to form
 * $form->addAntispam();
 * </code>
 *
 * @version 0.4
 * @author  Michal Mikoláš <nanuqcz@gmail.com>
 * @license CC BY <http://creativecommons.org/licenses/by/3.0/cz/>
 */
class AntispamControl extends TextInput
{
	/** @var int  minimum delay [sec] to send form */
	public static $minDelay = 5;

	
	/**
	 * Register Antispam to Nette Forms
	 * @return void
	 */
	public static function register()
	{
		Form::extensionMethod('addAntispam', function(Form $form, $name = 'spam', $label = 'Toto pole vymažte', $msg = 'Byl detekován pokus o spam.'){
			// "All filled" protection
			$form[$name] = new AntispamControl($label, NULL, NULL, $msg);
			
			// "Send delay" protection
			$form->addHidden('form_created', strtr(time(), '0123456789', 'jihgfedcba'))
				->addRule(
					function($item){
						if (AntispamControl::$minDelay <= 0) return TRUE;  // turn off "Send delay protection"

						$value = (int)strtr($item->value, 'jihgfedcba', '0123456789');
						return $value <= (time() - AntispamControl::$minDelay);
					}, 
					$msg
				);
			
			return $form;
		});
	}



	/**
	 * @param string|Html
	 * @param int
	 * @param int
	 * @param string
	 */
	public function __construct($label = '', $cols = NULL, $maxLength = NULL, $msg = '')
	{
		parent::__construct($label, $cols, $maxLength);

		$this->setDefaultValue('http://');
		$this->addRule(Form::BLANK, $msg);
	}



	/**
	 * @return TextInput
	 */
	public function getControl()
	{
		$control = parent::getControl();
		
		$control = $this->addAntispamScript($control);
		return $control;
	}



	/**
	 * @param Html
	 * @return Html
	 */
	protected function addAntispamScript(Html $control)
	{
		$control = Html::el('')->add($control);
		$control->add( Html::el('script', array('type' => 'text/javascript'))->setHtml("
				// Clear input value
				var input = document.getElementById('" . $control[0]->id . "');
				input.value = '';				
				
				// Hide input and label
				if (input.parentNode.parentNode.nodeName == 'TR') {
					// DefaultFormRenderer
					input.parentNode.parentNode.style.display = 'none';
				} else {
					// Manual render
					input.style.display = 'none';
					var labels = input.parentNode.getElementsByTagName('label');
					for (var i = 0; i < labels.length; i++) {  // find and hide label
						if (labels[i].getAttribute('for') == '" . $control[0]->id . "') {
							labels[i].style.display = 'none';
						}
					}
				}
			") 
		);

		return $control;
	}

}