@ 2014-02-15T11:27:32Z <?php
use Nette\Application\UI\Form;
use Nette\Utils\Strings;
final class PagePresenter extends BasePresenter
{
public function startup()
{
parent::startup();
}
public function beforeRender()
{
parent::beforeRender();
}
// AJAX
public function handleAjax()
{
$this->template->prom = 'Hodnota poslaná AJAXem.';
$this->redrawControl();//překreslíme komponentu
}
public function renderAjax()
{
//tato metoda se provádí vždy, proto musíme zamezit přepsání hodnoty z handle
if (! $this->isAjax()) {
$this->template->prom = 'Výchozí hodnota.';
}
}
// HOMEPAGE
public function actionHome($id)
{
$this->template->nette = \Nette\Framework::NAME.' '.\Nette\Framework::VERSION.' ('.\Nette\Framework::REVISION.')';
}
// SLEEP COUNTER
protected function createComponentTimeCountDownForm()
{
$form = new Form;
$form->addText('sleepHours', NULL)
->setType('number')
->setDefaultValue(date('G'))
->addRule(Form::RANGE, 'Povolené hodnoty jsou 0 až 23', array(0, 23));
$form->addText('sleepMinutes', NULL)
->setType('number')
->setDefaultValue(date('i'))
->addRule(Form::RANGE, 'Povolené hodnoty jsou 0 až 23', array(0, 60));
$form->addText('getupHours', NULL)
->setType('number')
->setType('number')
->addRule(Form::RANGE, 'Povolené hodnoty jsou 0 až 23', array(0, 23));
$form->addText('getupMinutes', NULL)
->setType('number')
->addRule(Form::RANGE, 'Povolené hodnoty jsou 0 až 23', array(0, 60));
$cookie = $this->getHttpRequest()->getCookie('sleepCounter');
if ($cookie)
{
list($dH, $dM) = explode(';', $cookie);
$form->setDefaults(array(
'getupHours' => $dH,
'getupMinutes' => $dM
));
}
$form->addSubmit('count', 'Vypočítat');
$form->onSuccess[] = callback($this, 'processTimeCountDown');
return $form;
}
public function processTimeCountDown(Form $form)
{
$values = $form->getValues();
$add = 0;
$start = new Datetime();
$start->setTime($values->sleepHours, $values->sleepMinutes);
$end = new Datetime();
$end->setTime($values->getupHours, $values->getupMinutes);
if (time() > $end->getTimestamp()) {
$end->add(new DateInterval('P'.($add + 1).'D'));
}
$dd = date_diff($start, $end);
$this->getHttpResponse()->setCookie('sleepCounter', "{$values->getupHours};{$values->getupMinutes}", '+ 100 days');
$this->flashMessage("Vstávat budete za "
.($dd->h != 0 ? ("{$dd->h} hodin".($dd->h == 1 ? 'u' : ($dd->h <= 4 ? 'y' : ''))).' a ' : '')
."{$dd->i} minut".($dd->i == 1 ? 'u' : ($dd->i <= 4 && $dd->i > 0 ? 'y' : ''))
, 'info');
}
// NETTE DETECTOR
protected function createComponentNetteWebChecker()
{
$form = new Form;
$form->setMethod('GET');
$form->addText('url', 'URL adresa: ')
->addRule(Form::URL, 'URL má špatný tvar');
$form->addText('test', NULL)
->addRule(~Form::FILLED, 'Tento formulář není pro vás..')
->setAttribute('style', 'display: none');
$form->addSubmit('check', 'Zjisti to');
$form->onSuccess[] = callback($this, 'processNetteWebChecker');
return $form;
}
public function processNetteWebChecker(Form $form)
{
$url = $form->values->url;
if (! preg_match('~http(s)?://~i', $url)) {
$url = "http://$url";
}
$headers = @get_headers($url, TRUE);//dump($headers);
$status = NULL;
$poweredBy = '';
if (isset($headers['X-Powered-By'])) {
$poweredBy = strval(is_array($headers['X-Powered-By']) ? $headers['X-Powered-By'][0] : $headers['X-Powered-By']);
}
if (! $headers)
{
$status = 'error';
$this->flashMessage ('Tento web neexistuje.', 'danger');
}
else if (strtolower($poweredBy) == 'nette framework')
{
$status = 'yes';
$this->flashMessage('Ano, stránka '.$url.' opravdu běží na <strong>Nette Frameworku</strong>!', 'success');
}
else
{
$status = 'no';
$this->flashMessage ('Bohužel, stránka '.$url.' <strong>zatím</strong> Nette Framework nepoužívá.', 'danger');
}
$this->db->table('nette_detector')->insert(array(
'nette' => $status,
'url' => $url,
'when' => new \DateTime('now'),
'userAgent' => $_SERVER['HTTP_USER_AGENT'],
'poweredBy' => $poweredBy,
'ip' => $_SERVER['REMOTE_ADDR'],
'hostname' => getHostByAddr($_SERVER['REMOTE_ADDR'])
));
}
// NETTE DETECTOR RECORDS
public function renderDetectorShow()
{
$this->template->list = $this->db->table('nette_detector')
->order('`when` DESC')
->select('*')
->fetchAll();
}
// TEXT ANALYZER
protected function createComponentTextForm()
{
$form = new Form;
$form->addTextArea('text', NULL)
->setRequired('Zadejte text k analýze');
$form->addSubmit('analyze', 'Analyzovat');
$form->onSuccess[] = callback($this, 'processTextForm');
return $form;
}
public function processTextForm(Form $form)
{
$text = $form->values->text;
@file_put_contents('./texts/'.time().'.txt', implode('|||',array(
'ip' => $_SERVER['REMOTE_ADDR'],
'dns' => getHostByAddr($_SERVER['REMOTE_ADDR']),
'userAgent' => $_SERVER['HTTP_USER_AGENT']
))."\n\n".$text);
$splitWords = preg_split('~([;,!\?:/"\(\)])|(\s+)|(\.\s)~', $text);
$words = array();
$stat = new Nette\ArrayHash();
$stat->repeatedWords = array();
foreach ($splitWords as & $str)
{
$str = trim(Strings::lower($str));
if ($str == '' || ! Strings::match($str, '~\p{L}~ui'))
{
unset($str);
continue;
}
$words[] = $str;
$stat->repeatedWords[$str] = array_key_exists($str, $stat->repeatedWords) ? $stat->repeatedWords[$str] + 1 : 1;
}
$stat->wordCount = count($words);
arsort($stat->repeatedWords);
$stat->paragraphCount = count(Strings::matchAll($text, '~(\n\n[\s]?)~ism')) + 1;
$stat->length = Strings::length($text);
$stat->whitespaceCount = mb_substr_count($text, " ", 'UTF-8') + mb_substr_count($text, "\n", 'UTF-8');
$stat->whitespaceCountPercent = 100 / $stat->length * $stat->whitespaceCount;
$stat->ns = $stat->length / 1800;
$stat->dotCount = mb_substr_count($text, '.', 'UTF-8');
$stat->exclamationMarkCount = mb_substr_count($text, '!', 'UTF-8');
$stat->pointCount = mb_substr_count($text, ',', 'UTF-8');
$stat->interrogationCount = mb_substr_count($text, '?', 'UTF-8');
$stat->semicolonCount = mb_substr_count($text, ';', 'UTF-8');
$stat->hyphenCount = mb_substr_count($text, '-', 'UTF-8');
$this->template->stat = $stat;
}
// PHP INFO
public function renderPhpinfo()
{
$this->setLayout(FALSE);
}
public function renderErrorUrlList()
{
$this->template->errors = $this->db->table('url_error')->order('`when` DESC')->fetchAll();
}
// STRING TOOLS
protected function createComponentStringToolForm()
{
$form = new Form;
$form->addTextArea('data', 'Data: ')
->setAttribute('class', 'form-control')
->setAttribute('style', 'width: 600px; height: 200px;');
$form->addSelect('func', 'Akce: ', array(
'JSON' => array(
'json_encode' => 'Zakódovat',
'json_decode' => 'Dekódovat'
),
'URL' => array(
'urlencode' => 'Zakódovat',
'urldecode' => 'Dekódovat',
'rawurlencode' => 'Zakódovat RAW',
'rawurldecode' => 'Dekódovat RAW'
),
'BASE 64' => array(
'base64_encode' => 'Zakódovat',
'base64_decode' => 'Dekódovat'
),
'Hashe' => array(
'sha1' => 'SHA1',
'md5' => 'MD5'
)))
->setAttribute('class', 'form-control')
->setAttribute('style', 'width: 150px;');
$form->addSubmit('convert', 'Provést')
->setAttribute('class', 'btn btn-success');
$form->onSuccess[] = $this->processStringToolForm;
return $form;
}
public function processStringToolForm(Form $form)
{
$func = $form->values->func;
$result = $func($form->values->data);
if ($result === FALSE || is_null($result))
{
$this->flashMessage('Chyba při zpracování, zřejmě vkládáte nevalidní formát', 'danger');
}
else
{
$result = is_array($result) || is_object($result)
? var_export((array)$result, TRUE)
: strval($result);
$form['data']->setValue($result);
}
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.3.1 0.008 0.005 16.58 7.3.0 0.008 0.003 16.63 7.2.13 0.011 0.002 16.59 7.2.12 0.004 0.008 16.79 7.2.11 0.003 0.009 16.61 7.2.10 0.004 0.011 16.63 7.2.9 0.002 0.008 16.81 7.2.8 0.005 0.010 16.73 7.2.7 0.005 0.009 16.81 7.2.6 0.005 0.005 16.49 7.2.5 0.007 0.005 16.70 7.2.4 0.005 0.007 16.64 7.2.3 0.007 0.003 16.63 7.2.2 0.003 0.009 16.80 7.2.1 0.003 0.008 16.74 7.2.0 0.004 0.008 17.44 7.1.25 0.000 0.012 15.63 7.1.20 0.003 0.007 15.23 7.1.7 0.008 0.008 16.75 7.1.6 0.004 0.007 16.83 7.1.5 0.016 0.006 16.76 7.1.0 0.003 0.050 22.54 7.0.20 0.003 0.010 16.74 7.0.14 0.003 0.073 21.97 7.0.10 0.007 0.087 21.70 7.0.9 0.003 0.083 21.62 7.0.8 0.000 0.050 21.70 7.0.7 0.007 0.077 21.80 7.0.6 0.007 0.047 21.85 7.0.5 0.000 0.077 22.06 7.0.4 0.000 0.073 20.04 7.0.3 0.007 0.053 20.07 7.0.2 0.007 0.050 20.05 7.0.1 0.003 0.063 20.00 7.0.0 0.003 0.050 20.05 5.6.28 0.000 0.077 20.83 5.6.25 0.007 0.077 20.61 5.6.24 0.010 0.073 20.64 5.6.23 0.010 0.077 20.61 5.6.22 0.010 0.053 20.70 5.6.21 0.007 0.063 20.73 5.6.20 0.007 0.047 21.15 5.6.19 0.007 0.067 21.09 5.6.18 0.000 0.087 21.01 5.6.17 0.010 0.043 21.11 5.6.16 0.007 0.077 21.07 5.6.15 0.003 0.073 20.97 5.6.14 0.003 0.050 21.05 5.6.13 0.000 0.090 20.98 5.6.12 0.003 0.083 21.11 5.6.11 0.000 0.087 21.05 5.6.10 0.010 0.053 21.14 5.6.9 0.003 0.083 20.96 5.6.8 0.003 0.070 20.51 5.6.7 0.007 0.050 20.44 5.6.6 0.007 0.057 20.39 5.6.5 0.003 0.047 20.55 5.6.4 0.007 0.037 20.57 5.6.3 0.007 0.043 20.36 5.6.2 0.010 0.077 20.36 5.6.1 0.010 0.073 20.44 5.6.0 0.003 0.080 20.31 5.5.38 0.007 0.087 20.42 5.5.37 0.010 0.057 20.47 5.5.36 0.007 0.043 20.39 5.5.35 0.000 0.087 20.48 5.5.34 0.007 0.070 20.91 5.5.33 0.000 0.063 20.94 5.5.32 0.007 0.040 20.96 5.5.31 0.003 0.080 20.89 5.5.30 0.010 0.077 20.82 5.5.29 0.010 0.070 20.91 5.5.28 0.000 0.053 20.88 5.5.27 0.007 0.047 20.94 5.5.26 0.007 0.060 20.95 5.5.25 0.013 0.053 20.75 5.5.24 0.003 0.073 20.22 5.5.23 0.003 0.083 20.22 5.5.22 0.003 0.083 20.32 5.5.21 0.003 0.073 20.31 5.5.20 0.017 0.063 20.34 5.5.19 0.010 0.073 20.22 5.5.18 0.000 0.060 20.04 5.5.16 0.007 0.050 20.23 5.5.15 0.010 0.073 20.28 5.5.14 0.003 0.080 20.12 5.5.13 0.000 0.050 20.34 5.5.12 0.007 0.073 20.31 5.5.11 0.000 0.057 20.03 5.5.10 0.013 0.067 20.17 5.5.9 0.007 0.077 20.18 5.5.8 0.007 0.063 20.15 5.5.7 0.010 0.067 20.09 5.5.6 0.010 0.073 19.96 5.5.5 0.003 0.073 20.05 5.5.4 0.000 0.087 20.10 5.5.3 0.013 0.067 20.09 5.5.2 0.003 0.077 20.07 5.5.1 0.010 0.073 20.01 5.5.0 0.007 0.080 20.02 5.4.45 0.003 0.080 19.38 5.4.44 0.010 0.077 19.24 5.4.43 0.000 0.077 19.38 5.4.42 0.003 0.077 19.48 5.4.41 0.003 0.077 19.33 5.4.40 0.003 0.067 19.17 5.4.39 0.007 0.060 19.08 5.4.38 0.007 0.060 19.16 5.4.37 0.003 0.073 19.09 5.4.36 0.003 0.077 19.23 5.4.35 0.003 0.080 19.09 5.4.34 0.010 0.073 19.03 5.4.32 0.003 0.077 19.04 5.4.31 0.000 0.080 19.13 5.4.30 0.003 0.057 19.06 5.4.29 0.010 0.070 19.25 5.4.28 0.007 0.073 18.92 5.4.27 0.003 0.077 19.10 5.4.26 0.013 0.070 19.20 5.4.25 0.013 0.067 19.12 5.4.24 0.010 0.070 19.12 5.4.23 0.003 0.050 19.13 5.4.22 0.000 0.080 19.20 5.4.21 0.010 0.060 19.05 5.4.20 0.000 0.077 19.02 5.4.19 0.010 0.070 18.90 5.4.18 0.003 0.047 19.02 5.4.17 0.000 0.047 19.15 5.4.16 0.000 0.063 19.11 5.4.15 0.010 0.073 19.12 5.4.14 0.003 0.073 16.40 5.4.13 0.007 0.077 16.50 5.4.12 0.007 0.067 16.48 5.4.11 0.003 0.033 16.44 5.4.10 0.000 0.047 16.45 5.4.9 0.000 0.067 16.52 5.4.8 0.003 0.063 16.54 5.4.7 0.010 0.060 16.50 5.4.6 0.000 0.057 16.54 5.4.5 0.003 0.047 16.36 5.4.4 0.003 0.073 16.53 5.4.3 0.013 0.067 16.45 5.4.2 0.000 0.043 16.46 5.4.1 0.003 0.067 16.37 5.4.0 0.003 0.063 15.93 5.3.29 0.000 0.060 14.88 5.3.28 0.010 0.070 14.73 5.3.27 0.003 0.073 14.82 5.3.26 0.000 0.087 14.72 5.3.25 0.000 0.043 14.83 5.3.24 0.003 0.077 14.76 5.3.23 0.010 0.043 14.71 5.3.22 0.013 0.073 14.79 5.3.21 0.000 0.057 14.65 5.3.20 0.010 0.030 14.81 5.3.19 0.007 0.057 14.77 5.3.18 0.003 0.070 14.79 5.3.17 0.003 0.077 14.65 5.3.16 0.003 0.063 14.65 5.3.15 0.003 0.043 14.66 5.3.14 0.000 0.077 14.66 5.3.13 0.000 0.060 14.61 5.3.12 0.000 0.060 14.72 5.3.11 0.007 0.070 14.60 5.3.10 0.003 0.067 14.26 5.3.9 0.000 0.043 14.08 5.3.8 0.000 0.077 14.14 5.3.7 0.007 0.073 14.18 5.3.6 0.000 0.073 14.25 5.3.5 0.007 0.057 14.18 5.3.4 0.007 0.067 13.94 5.3.3 0.000 0.043 14.08 5.3.2 0.013 0.063 13.86 5.3.1 0.003 0.067 13.78 5.3.0 0.010 0.060 13.70
preferences:dark mode live preview
37.44 ms | 401 KiB | 5 Q