/** * Format mobile number according to known SK and CZ specifics * @param string $mobile * @return string */ public static function mobile($mobile) { if (NStrings::startsWith($mobile, '+')) { return self::format($mobile, array(4, 3, 3, 3)); } elseif (NStrings::startsWith($mobile, '00')) { return self::format($mobile, array(5, 3, 3, 3)); } else { return self::format($mobile, array(4, 3, 3)); } }
/** * Make relative url absolute * @param string image url * @param string single or double quote * @param string absolute css file path * @param string source path * @return string */ public static function absolutizeUrl($url, $quote, $cssFile, $sourcePath) { // is already absolute if (preg_match("/^([a-z]+:\\/)?\\//", $url)) { return $url; } $docroot = realpath(WWW_DIR); $basePath = rtrim(NEnvironment::getVariable("baseUri"), '/'); // inside document root if (NStrings::startsWith($cssFile, $docroot)) { $path = $basePath . substr(dirname($cssFile), strlen($docroot)) . DIRECTORY_SEPARATOR . $url; // outside document root } else { $path = $basePath . substr($sourcePath, strlen($docroot)) . DIRECTORY_SEPARATOR . $url; } $path = self::cannonicalizePath($path); return $quote === '"' ? addslashes($path) : $path; }
/** * Generates code for {macro ...} to the output. * @param string * @param string * @param string * @param bool * @return void */ public function writeMacro($name, $args = NULL, $modifiers = NULL, $isRightmost = FALSE) { $isLeftmost = trim(substr($this->output, $leftOfs = strrpos("\n$this->output", "\n"))) === ''; if ($name[0] === '/') { // closing $node = end($this->macroNodes); if (!$node || ("/$node->name" !== $name && '/' !== $name) || $modifiers || ($args && $node->args && !NStrings::startsWith("$node->args ", "$args ")) ) { $name .= $args ? ' ' : ''; throw new NLatteException("Unexpected macro {{$name}{$args}{$modifiers}}" . ($node ? ", expecting {/$node->name}" . ($args && $node->args ? " or eventually {/$node->name $node->args}" : '') : ''), 0, $this->getLine()); } array_pop($this->macroNodes); if (!$node->args) { $node->setArgs($args); } if ($isLeftmost && $isRightmost) { $this->output = substr($this->output, 0, $leftOfs); // alone macro -> remove indentation } $code = $node->close(substr($this->output, $node->offset)); if (!$isLeftmost && $isRightmost && substr($code, -2) === '?>') { $code .= "\n"; // double newline to avoid newline eating by PHP } $this->output = substr($this->output, 0, $node->offset) . $node->content. $code; } else { // opening list($node, $code) = $this->expandMacro($name, $args, $modifiers); if (!$node->isEmpty) { $this->macroNodes[] = $node; } if ($isRightmost) { if ($isLeftmost && substr($code, 0, 11) !== '<?php echo ') { $this->output = substr($this->output, 0, $leftOfs); // alone macro without output -> remove indentation } elseif (substr($code, -2) === '?>') { $code .= "\n"; // double newline to avoid newline eating by PHP } } $this->output .= $code; $node->offset = strlen($this->output); } }
/** * Inserting a topic to a forum * * @access public * @param Nette\Application\UI\Form $form formulář * @return void * @uses ForumControlModel::getTopic() * @uses ForumControlModel::insert() * @since 1.0.0 */ public function forumFormSubmitted(UI\Form $form) { try { if ($form['insert']->isSubmittedBy()) { $values = $form->values; $this->context->httpResponse->setCookie('Nette-ForumControl-Name', $values->name, strtotime('+1 month')); if ($this->forumTopicId) { $replyTo = $this->model->getTopic($this->forumTopicId); $values->title = NStrings::startsWith($replyTo->title, 'Re: ') ? $replyTo->title : 'Re: ' . $replyTo->title; } $values->ip = $this->context->httpRequest->remoteAddress; $values->date_time = date('Y-m-d H:i:s'); $this->model->insert($values, $this->forumTopicId); $this->presenter->flashMessage('Your topic has been successfully inserted.'); } } catch (\DibiException $e) { $this->presenter->flashMessage('An error occured while adding your topic.', 'error'); } $this->presenter->redirect($this->presenter->view); }
/** * Helper for macroIncludePart * @param string $params * @return array */ private static function prepareIncludePartParams($params) { $return = array('name' => false, 'params' => 'array()'); $p = explode(',', substr($params, 6, -1)); if (count($p) >= 1 and strpos($p[0], '=>') === FALSE) { $p = is_string($p) ? trim($p) : $p; if (!empty($p)) { $return['name'] = !NStrings::startsWith($p[0], '$') ? substr($p[0], 1, -1) : $p[0]; unset($p[0]); $return['params'] = implode(',', $p); } } elseif (count($p) >= 1 and strpos($p[0], '=>') !== FALSE) { if (!empty($p)) { $return['name'] = false; $return['params'] = implode(',', $p); } } $return['params'] = 'array(' . $return['params'] . ')'; return $return; }
/** * Handles CONTEXT_TAG. */ private function contextTag() { $matches = $this->match('~ (?P<end>\ ?/?>)([ \t]*\n)?| ## end of HTML tag '.$this->macroRe.'| ## macro tag \s*(?P<attr>[^\s/>={]+)(?:\s*=\s*(?P<value>["\']|[^\s/>{]+))? ## begin of HTML attribute ~xsi'); if (!empty($matches['end'])) { // end of HTML tag /> $this->addToken(NLatteToken::HTML_TAG_END, $matches[0]); $this->setContext(!$this->xmlMode && in_array($this->lastHtmlTag, array('script', 'style')) ? self::CONTEXT_CDATA : self::CONTEXT_TEXT); } elseif (isset($matches['attr']) && $matches['attr'] !== '') { // HTML attribute $token = $this->addToken(NLatteToken::HTML_ATTRIBUTE, $matches[0]); $token->name = $matches['attr']; $token->value = isset($matches['value']) ? $matches['value'] : ''; if ($token->value === '"' || $token->value === "'") { // attribute = "' if (NStrings::startsWith($token->name, self::N_PREFIX)) { $token->value = ''; if ($m = $this->match('~(.*?)' . $matches['value'] . '~xsi')) { $token->value = $m[1]; $token->text .= $m[0]; } } else { $this->setContext(self::CONTEXT_ATTRIBUTE, $matches['value']); } } } return $matches; }
/** * Generates code for {macro ...} to the output. * @param string * @param string * @param string * @param bool * @return NMacroNode */ public function writeMacro($name, $args = NULL, $modifiers = NULL, $isRightmost = FALSE, NHtmlNode $htmlNode = NULL, $prefix = NULL) { if ($name[0] === '/') { // closing $node = end($this->macroNodes); if (!$node || ("/$node->name" !== $name && '/' !== $name) || $modifiers || ($args && $node->args && !NStrings::startsWith("$node->args ", "$args ")) ) { $name .= $args ? ' ' : ''; throw new NCompileException("Unexpected macro {{$name}{$args}{$modifiers}}" . ($node ? ", expecting {/$node->name}" . ($args && $node->args ? " or eventually {/$node->name $node->args}" : '') : '')); } array_pop($this->macroNodes); if (!$node->args) { $node->setArgs($args); } $isLeftmost = $node->content ? trim(substr($this->output, strrpos("\n$this->output", "\n"))) === '' : FALSE; $node->closing = TRUE; $node->macro->nodeClosed($node); $this->output = & $node->saved[0]; $this->writeCode($node->openingCode, $this->output, $node->saved[1]); $this->writeCode($node->closingCode, $node->content, $isRightmost, $isLeftmost); $this->output .= $node->content; } else { // opening $node = $this->expandMacro($name, $args, $modifiers, $htmlNode, $prefix); if ($node->isEmpty) { $this->writeCode($node->openingCode, $this->output, $isRightmost); } else { $this->macroNodes[] = $node; $node->saved = array(& $this->output, $isRightmost); $this->output = & $node->content; } } return $node; }