public function send($alias, $to, $from = null, array $data = null) { if (!config('mail.enabled')) { return; } $template = $this->getTemplate($alias); if (!$template) { throw new CoreException('Cannot find template with alias/id: ' . $alias, 404); } if ($data === null) { $data = array(); } $template->setDescription($this->replaceTemplateContent($template->getDescription(), $data)); $template->setName($this->replaceTemplateContent($template->getName(), $data)); $preffix = server_url(base_url()); $content = preg_replace('#background\\: url\\((.*)\\)#', 'background: url(' . $preffix . '$1)', $template->getDescription()); $content = preg_replace('#\\<img src=\\"(.*)\\"#', '<img src="' . $preffix . '$1"', $content); $template->getDescription($content); $message = new Message(); $message->setSubject($template->getName()); if ($from) { $message->setFrom($from); } $message->addTo($to); $content = $template->getDescription(); $content = '<html><head><title>' . $template->getName() . '</title></head><body>' . $template->getDescription() . '</body></html>'; $html = new Mime\Part($content); $html->setType(Mime\Mime::TYPE_HTML); $html->setCharset('utf-8'); $mimeMessage = new Mime\Message(); $mimeMessage->addPart($html); foreach ($this->attachments as $attachment) { $mimeMessage->addPart($attachment); } $message->setBody($mimeMessage); try { $transport = new SmtpTransport(new SmtpOptions(config('mail.options'))); $transport->send($message); } catch (\Exception $e) { throw $e; } return $this; }
function showATOM() { header('Content-Type: application/atom+xml; charset=utf-8'); // $usepermalink : If true, use permalink instead of final link. // User just has to add 'permalink' in URL parameters. e.g. http://mysite.com/shaarli/?do=atom&permalinks $usepermalinks = isset($_GET['permalinks']) || !$GLOBALS['config']['ENABLE_RSS_PERMALINKS']; // Cache system $query = $_SERVER["QUERY_STRING"]; $cache = new CachedPage($GLOBALS['config']['PAGECACHE'], page_url($_SERVER), startsWith($query, 'do=atom') && !isLoggedIn()); $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; } // If cached was not found (or not usable), then read the database and build the response: // Read links from database (and filter private links if used it not logged in). $LINKSDB = new LinkDB($GLOBALS['config']['DATASTORE'], isLoggedIn(), $GLOBALS['config']['HIDE_PUBLIC_LINKS'], $GLOBALS['redirector']); // Optionally filter the results: if (!empty($_GET['searchterm'])) { $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $_GET['searchterm']); } else { if (!empty($_GET['searchtags'])) { $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TAG, trim($_GET['searchtags'])); } else { $linksToDisplay = $LINKSDB; } } $nblinksToDisplay = 50; // Number of links to display. // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. if (!empty($_GET['nb'])) { $nblinksToDisplay = $_GET['nb'] == 'all' ? count($linksToDisplay) : max(intval($_GET['nb']), 1); } $pageaddr = escape(index_url($_SERVER)); $latestDate = ''; $entries = ''; $i = 0; $keys = array(); foreach ($linksToDisplay as $key => $value) { $keys[] = $key; } // No, I can't use array_keys(). while ($i < $nblinksToDisplay && $i < count($keys)) { $link = $linksToDisplay[$keys[$i]]; $guid = $pageaddr . '?' . smallHash($link['linkdate']); $iso8601date = linkdate2iso8601($link['linkdate']); $latestDate = max($latestDate, $iso8601date); $absurl = $link['url']; if (startsWith($absurl, '?')) { $absurl = $pageaddr . $absurl; } // make permalink URL absolute $entries .= '<entry><title>' . $link['title'] . '</title>'; if ($usepermalinks === true) { $entries .= '<link href="' . $guid . '" /><id>' . $guid . '</id>'; } else { $entries .= '<link href="' . $absurl . '" /><id>' . $guid . '</id>'; } if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) { $entries .= '<updated>' . escape($iso8601date) . '</updated>'; } // Add permalink in description $descriptionlink = '(<a href="' . $guid . '">Permalink</a>)'; // If user wants permalinks first, put the final link in description if ($usepermalinks === true) { $descriptionlink = '(<a href="' . $absurl . '">Link</a>)'; } if (strlen($link['description']) > 0) { $descriptionlink = '<br>' . $descriptionlink; } $entries .= '<content type="html"><![CDATA[' . format_description($link['description'], $GLOBALS['redirector']) . $descriptionlink . "]]></content>\n"; if ($link['tags'] != '') { foreach (explode(' ', $link['tags']) as $tag) { $entries .= '<category scheme="' . $pageaddr . '" term="' . $tag . '" />' . "\n"; } } $entries .= "</entry>\n"; $i++; } $feed = '<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom">'; $feed .= '<title>' . $GLOBALS['title'] . '</title>'; if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) { $feed .= '<updated>' . escape($latestDate) . '</updated>'; } $feed .= '<link rel="self" href="' . escape(server_url($_SERVER) . $_SERVER["REQUEST_URI"]) . '" />'; if (!empty($GLOBALS['config']['PUBSUBHUB_URL'])) { $feed .= '<!-- PubSubHubbub Discovery -->'; $feed .= '<link rel="hub" href="' . escape($GLOBALS['config']['PUBSUBHUB_URL']) . '" />'; $feed .= '<!-- End Of PubSubHubbub Discovery -->'; } $feed .= '<author><name>' . $pageaddr . '</name><uri>' . $pageaddr . '</uri></author>'; $feed .= '<id>' . $pageaddr . '</id>' . "\n\n"; // Yes, I know I should use a real IRI (RFC3987), but the site URL will do. $feed .= $entries; $feed .= '</feed><!-- Cached version of ' . escape(page_url($_SERVER)) . ' -->'; echo $feed; $cache->cache(ob_get_contents()); ob_end_flush(); exit; }
/** * Returns the absolute URL of the current script, without the query * * If the resource is "index.php", then it is removed (for better-looking URLs) * * @param array $server the $_SERVER array * * @return string the absolute URL of the current script, without the query */ function index_url($server) { $scriptname = $server['SCRIPT_NAME']; if (endswith($scriptname, 'index.php')) { $scriptname = substr($scriptname, 0, -9); } return server_url($server) . $scriptname; }
/** * HTTPS server on port 443 */ public function testStandardHttpsPort() { $this->assertEquals('https://host.tld', server_url(array('HTTPS' => 'ON', 'SERVER_NAME' => 'host.tld', 'SERVER_PORT' => '443'))); }