public function link($text, $url = null, $attr = array(), $full = false) { if (is_null($url)) { $url = $text; } $attr['href'] = Mapper::url($url, $full); return $this->tag('a', $text, $attr); }
public function create($action = null, $options = array()) { $options += array('method' => 'post', 'action' => Mapper::url($action)); if ($options['method'] == 'file') { $options['method'] = 'post'; $options['enctype'] = 'multipart/form-data'; } return $this->html->openTag('form', $options); }
public function asset($url, $name, $extension = null) { if (!Mapper::isExternal($url)) { if (!is_null($extension)) { $url = $this->extension($url, $extension); } $url = Mapper::url($url, false, self::$assets[$name]); } return $url; }
public function asset($url, $type, $extension = null) { if (!$this->external($url)) { if (!is_null($extension)) { $url = $this->extension($url, $extension); } $url = Mapper::url(self::$assets[$type] . $url); } return $url; }
/** * Cria um botão de envio dos dados do formulário. * * @param string $submit Nome do botão de envio * @param array $attributes Atributos e opções da tag * @return string Botão de envio do formulário */ public function submit($text, $attributes = array()) { $attributes = array_merge(array("type" => "submit", "tag" => "button"), $attributes); switch (array_unset($attributes, "tag")) { case "image": $attributes["alt"] = $text; $attributes["type"] = "image"; if (!$this->external($attributes["src"])) { $attributes["src"] = Mapper::url("/images/" . $attributes["src"]); } case "input": $attributes["value"] = $text; $button = $this->tag("input", null, $attributes, false); break; default: $button = $this->tag("button", $text, $attributes); } return $this->output($button); }
public function menu($array = array()) { $html = '<ul>' . PHP_EOL; foreach ($array as $label => $link) { $class = trim(Mapper::here(), '/') == trim($link, '/') ? ' class="selected" ' : ''; $class = Mapper::match($link) ? ' class="selected" ' : ''; $listclass = $this->applyClassOn == 'list' ? $class : ''; $html .= '<li' . $listclass . '>'; if (is_array($link)) { $html .= $label; $html .= $this->menu($link); } else { $linkclass = $this->applyClassOn == 'link' ? $class : ''; $html .= '<a href="' . Mapper::url($link) . $linkclass . '" >' . $label . '</a>'; } $html .= '</li>' . PHP_EOL; } $html .= '</ul>' . PHP_EOL; return $html; }
/** * @param string $blogURL The URL of your blog. * @param string $wordPressAPIKey WordPress API key. */ public function __construct() { $this->blogURL = Mapper::url("", true); //$this->wordPressAPIKey = $wordPressAPIKey; // Set some default values $this->apiPort = 80; $this->akismetServer = 'rest.akismet.com'; $this->akismetVersion = '1.1'; // Start to populate the comment data $this->comment['blog'] = $blogURL; $this->comment['user_agent'] = $_SERVER['HTTP_USER_AGENT']; if (isset($_SERVER['HTTP_REFERER'])) { $this->comment['referrer'] = $_SERVER['HTTP_REFERER']; } /* * This is necessary if the server PHP5 is running on has been set up to run PHP4 and * PHP5 concurently and is actually running through a separate proxy al a these instructions: * http://www.schlitt.info/applications/blog/archives/83_How_to_run_PHP4_and_PHP_5_parallel.html * and http://wiki.coggeshall.org/37.html * Otherwise the user_ip appears as the IP address of the PHP4 server passing the requests to the * PHP5 one... */ $this->comment['user_ip'] = $_SERVER['REMOTE_ADDR'] != getenv('SERVER_ADDR') ? $_SERVER['REMOTE_ADDR'] : getenv('HTTP_X_FORWARDED_FOR'); }
/** * Centraliza o envio das requisições http * * @param string $url A url que receberá a requisição * @param string $method O tipo de requisição. Ex.: POST, GET, etc * @return mixed O resultado da requisição */ public static function request($url, $method) { $self = self::instance(); //Tipos de requisições e seus correspondentes no cURL $methods = array('GET' => CURLOPT_HTTPGET, 'POST' => CURLOPT_POST); //Existe no array $methods if (array_key_exists($method, $methods)) { $self->curlOptions[$methods[$method]] = true; //Não existe, envia uma requisição customizada } else { $self->curlOptions[CURLOPT_CUSTOMREQUEST] = $method; } //Inicia a sessão curl $ch = curl_init(Mapper::url($url, true)); //Traz o resultado como string, ao invés de jogá-lo diretamente na saída $self->curlOptions[CURLOPT_RETURNTRANSFER] = true; //Coloca os arrays como opções do curl curl_setopt_array($ch, $self->curlOptions); //Executa $self->result = curl_exec($ch); //Pega o código de cabeçalho retornado $self->statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); //Tipo do conteúdo retornado. $self->contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); //info $self->info = curl_getinfo($ch); //Fecha a sessão curl curl_close($ch); //Retorna return $self->result; }
/** * Adiciona a action tratada com o Mapper::url() * $fluent->form()->action('/formularios') * * @return $this */ public function action($url) { $this->attr('action', Mapper::url($url)); return $this; }
public function redirect($url, $status = null, $exit = true) { $this->render = false; $codes = array(100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out'); if (!is_null($status) && isset($codes[$status])) { header('HTTP/1.1 ' . $status . ' ' . $codes[$status]); } header('Location: ' . Mapper::url($url, true)); if ($exit) { $this->stop(); } }
public function internalUrl($path = "", $url = "", $full = false) { if (preg_match("/^[a-z]+:/", $url)) { return $url; } else { return Mapper::url("{$path}/{$url}", $full); } }
public function testUrlWithFullReturn() { $results = Mapper::url("controller/action", true); $expected = "/^http:\\/\\/(.*)\\/controller\\/action\$/"; $this->assertPattern($expected, $results); }
public function aa($text) { $pattern = '/(?<patten>\\[(?<function>img|url)(?:="(?<url>.*?)")?(?<attrs>.*?)\\](?<value>.*?)\\[\\/(?<retrovisor>(\\2))\\])/'; preg_match($pattern, $text, $output); pr($output); pr($output['function']); if ($output['function'] == 'img') { $url = Mapper::url($output['value']); $replace = '<img src="' . $url . '" ' . $output['attrs'] . ' />'; } elseif ($output['function'] == 'url') { $url = Mapper::url($output['url']); if (empty($output['value'])) { $output['value'] = $url; } $replace = '<a href="' . $url . '" ' . $output['attrs'] . '>' . $output['value'] . '</a>'; } else { return $text; } return $this->aa(preg_replace($pattern, $replace, $text)); }
private function mapSmiles($key, $smile) { return "<img src='" . Mapper::url($this->emoticons_path) . "/" . $smile . "' alt='" . $key . "'>"; }
/** * Cria um elemento de script para ser usado no HTML. * * @param string $src Caminho do script a ser inseido no HTML * @param array $attr Atributos da tag * @param boolean $inline Verdadeiro para imprimir o script inline * @param boolean $full Verdadeiro para gerar uma URL completa * @return string Elemento de script a ser utilizado */ public function script($src = "", $attr = array(), $inline = true, $full = false) { if (is_array($src)) { $output = ""; foreach ($src as $tag) { $output .= $this->script($tag, $attr, true, $full) . PHP_EOL; } } else { if (!$this->external($src)) { $src = Mapper::url("/scripts/" . $this->extension($src, "js"), $full); } $attr = array_merge(array("src" => $src, "type" => "text/javascript"), $attr); $output = $this->output($this->tag("script", null, $attr)); } if ($inline) { return $output; } else { $this->view->scriptsForLayout .= $output; return true; } }
/** * Formata os campos para a saída. Ex.: Pega um pubDate e transforma * para o padrão, retira o html dos campos title, etc. * * @version 0.1 17/05/2010 * @param $text O texto a ser normalizado * @param string $type O tipo do campo, por exemplo, pubDate, Description, etc. * Cada um desses tipos de campos devem receber um tipo de valor * @return string o Tipo de valor para o campo */ public function format($text, $type) { switch ($type) { //Formato padrão para as datas case 'pubDate': return date('r', strtotime($text)); //Os títulos não podem ter html. //Os títulos não podem ter html. case 'title': return strip_tags($text); //Os links precisam ser escritos por completo //Os links precisam ser escritos por completo case 'link': case 'guid': return Mapper::url($text, true); //Conservo as quebras de linhas no texto //Conservo as quebras de linhas no texto case 'description': if ($this->useBBCode) { return nl2br($this->BBCode->parse($text)); } else { return nl2br($text); } //Demais campos //Demais campos default: return $text; } }
public function create($action = null, $options = array()) { $attr = array_merge(array("method" => "post", "action" => Mapper::url($action)), $options); $form = $this->openTag("form", $attr); return $this->output($form); }
/** * Gera 0 html dos breadcrumbs * * @version 0.1 02/11/2010 * - Initial * 0.2 04/11/2010 * - Caminhos adicionados posteriormente são exibidos na * ordem de inclusão * @param array $params Parâmetros para gerar o html * @return string Html gerado */ protected function htmlBreadcrumbs($attrs) { $attrs = array_merge(array('element' => 'li', 'separator' => '»', 'currentClass' => 'current'), $attrs); $output = ''; $this->breadcrumbs = array_merge($this->breadcrumbs, array_reverse($this->newBreadcrumbs)); $count = count($this->breadcrumbs); if ($count > 1) { for ($i = $count - 1; $i > 0; $i--) { $current = $this->breadcrumbs[$i]; $output .= '<' . $attrs['element'] . '>' . '<a href="' . Mapper::url($current['href']) . '">' . $current['label'] . '</a>' . '</' . $attrs['element'] . '>' . ' ' . $attrs['separator'] . ' '; } } $current = reset($this->breadcrumbs); $output .= '<' . $attrs['element'] . ' class="' . $attrs['currentClass'] . '">' . $current['label'] . '</' . $attrs['element'] . '>'; return $output; }
/** * Faz um redirecionamento enviando um cabeçalho HTTP com o código de status. * * @param string $url URL para redirecionamento * @param integer $status Código do status * @param boolean $exit Verdadeiro para encerrar o script após o redirecionamento * @return void */ public function redirect($url = "", $status = null, $exit = true) { $this->autoRender = false; $codes = array(100 => "Continue", 101 => "Switching Protocols", 200 => "OK", 201 => "Created", 202 => "Accepted", 203 => "Non-Authoritative Information", 204 => "No Content", 205 => "Reset Content", 206 => "Partial Content", 300 => "Multiple Choices", 301 => "Moved Permanently", 302 => "Found", 303 => "See Other", 304 => "Not Modified", 305 => "Use Proxy", 307 => "Temporary Redirect", 400 => "Bad Request", 401 => "Unauthorized", 402 => "Payment Required", 403 => "Forbidden", 404 => "Not Found", 405 => "Method Not Allowed", 406 => "Not Acceptable", 407 => "Proxy Authentication Required", 408 => "Request Time-out", 409 => "Conflict", 410 => "Gone", 411 => "Length Required", 412 => "Precondition Failed", 413 => "Request Entity Too Large", 414 => "Request-URI Too Large", 415 => "Unsupported Media Type", 416 => "Requested range not satisfiable", 417 => "Expectation Failed", 500 => "Internal Server Error", 501 => "Not Implemented", 502 => "Bad Gateway", 503 => "Service Unavailable", 504 => "Gateway Time-out"); if (!is_null($status) && isset($codes[$status])) { header("HTTP/1.1 {$status} {$codes[$status]}"); } header("Location: " . Mapper::url($url, true)); if ($exit) { $this->stop(); } }
function fLink($m) { list(, $pre, $atts, $text, $title, $url, $slash, $post) = $m; $url = $this->checkRefs($url); $atts = $this->pba($atts); $atts .= $title != '' ? ' title="' . $this->encode_html($title) . '"' : ''; if (!$this->noimage) { $text = $this->image($text); } $text = $this->span($text); $text = $this->glyphs($text); $url = $this->relURL($url); $out = '<a href="' . Mapper::url($this->encode_html($url . $slash)) . '"' . $atts . $this->rel . '>' . $text . '</a>' . $post; // $this->dump($out); return $this->shelve($out); }
/** * Cria um índice de sitemaps. * O formato para um índice de sitemaps é o modelo abaixo * * <?xml version="1.0" encoding="UTF-8"?> * <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> * <sitemap> * <loc>http://www.example.com/sitemap1.xml.gz</loc> * <lastmod>2004-10-01T18:23:17+00:00</lastmod> * </sitemap> * <sitemap> * <loc>http://www.example.com/sitemap2.xml.gz</loc> * <lastmod>2005-01-01</lastmod> * </sitemap> * </sitemapindex> * * @version * 0.1 24/05-2010 * Inicial * 0.2 02/11/2010 * Modificado para usar SimpleXml * Adicionado suporte a urls relativas * * @param array $list Array com a lista dos sitemaps */ public function parseIndex() { $siteindex = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></sitemapindex>'); foreach ($this->listIndex as $sitemap) { $sitemapItem = $siteindex->addChild('sitemap'); $sitemapItem->addChild('loc', Mapper::url($sitemap, true)); $sitemapItem->addChild('lastmod', date('c')); } return $siteindex->asXML(); }