// Global objects $host = $app->request->getUrl(); $domain = $app->request->getHost(); $config = new Config(); $helper = new Helper(); $render = function ($subtemplate = "form.php", $code = 200) use($app, $host, $config, $domain, $helper) { // Decide on the type of answer, depending on the request $req = $app->request->headers()->get('ACCEPT'); if ($req == 'application/javascript' || $req == 'text/xml') { // API call http_response_code($code); echo $subtemplate; $app->stop(); } else { // Normal browser $app->render('root.php', array('host' => $host, 'domain' => $domain, 'brand_name' => $config->getBrandName(), 'brand_url' => $config->getBrandUrl(), 'cortito_version' => '2.1', 'subtemplate' => $subtemplate, 'helper' => $helper)); } }; $render_with_url = function ($original, $shortened) use($app, $host, $config, $domain, $helper) { $short_url = "{$host}/{$shortened}"; $short_url_sanitized = urlencode($short_url); $newline = "%0D%0A"; $app->render('root.php', array('host' => $host, 'domain' => $domain, 'brand_name' => $config->getBrandName(), 'brand_url' => $config->getBrandUrl(), 'cortito_version' => '2.1', 'subtemplate' => 'show.php', 'helper' => $helper, 'shortened' => $shortened, 'short_url' => $short_url, 'original' => $original, 'twitter_web_url' => "http://twitter.com/home?status={$short_url_sanitized}", 'email_url' => "mailto:?subject=Check%20out%20this%20URL" . "&body={$short_url_sanitized}{$newline}{$newline}" . "Shortened%20by%20cortito%20{$host}/{$newline}", 'echofon_url' => "echofon:{$short_url_sanitized}", 'twitterrific_url' => "twitterrific:///post?message={$short_url_sanitized}", 'twitter_app_url' => "twitter://post?message={$short_url_sanitized}", 'twittelator_url' => "twit:///post?message={$short_url_sanitized}", 'tweetbot_url' => "tweetbot:///post?text={$short_url_sanitized}")); }; $is_valid = function ($url) use($config, $host, $helper) { $max_length = $config->getMaxShortLength(); // Let's make sure the length of the input URL is bigger than zero if (strlen($url) == 0) { return false; } // Let's hope the user is not shortening URLs with wrong protocols