3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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); } } }
Output for 7.0.0 - 7.1.0
Fatal error: Class 'BasePresenter' not found in /in/0PHr6 on line 6
Process exited with code 255.
Output for hhvm-3.12.0
Fatal error: Uncaught Error: unknown class BasePresenter in /in/0PHr6:6 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.10.0
Fatal error: unknown class BasePresenter in /in/0PHr6 on line 6
Process exited with code 255.
Output for 5.3.0 - 5.6.28
Fatal error: Class 'BasePresenter' not found in /in/0PHr6 on line 7
Process exited with code 255.