summaryrefslogtreecommitdiff
path: root/linkshorter/functions.php
diff options
context:
space:
mode:
Diffstat (limited to 'linkshorter/functions.php')
-rw-r--r--linkshorter/functions.php71
1 files changed, 22 insertions, 49 deletions
diff --git a/linkshorter/functions.php b/linkshorter/functions.php
index 7fa8cff..720fb4d 100644
--- a/linkshorter/functions.php
+++ b/linkshorter/functions.php
@@ -1,59 +1,32 @@
<?php
-function do_output($reason, $httpcode, $ajax = true, $heading = NULL){
- header ($_SERVER['SERVER_PROTOCOL'] . " " . $httpcode);
- if( $ajax ){
- echo $reason;
- ob_end_flush();
- exit;
- }
-?>
-<!doctype html>
-<html>
-<head>
- <meta charset="utf-8">
- <title>Link Shorter</title>
- <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
- <!--style>html{position:relative;min-height:100%}body{margin-bottom:60px}.footer{position:absolute;bottom:0;width:100%}#copyright-text{text-decoration:underline;color:#333}</style-->
- <style>
- <?php echo file_get_contents("../tools/style.css"); ?>
- </style>
- <noscript><style>.navbar{margin-bottom:0;}</style></noscript>
- <link rel='shortcut icon' href='../tools/favicon.ico' type='image/x-icon'>
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
-</head>
- <?php require("../tools/navbar.php"); ?>
-<div class="container text-center pagination-centered">
- <div class="row">
- <?php echo $heading; ?>
- <hr>
- </div>
- <div class="text-center">
- <?php echo $reason; ?>
- </div>
-</div>
- <?php require("../tools/footer.php"); ?>
-</body>
-<?php
- ob_end_flush();
+function _do_output($heading, $reason){
+
+ require 'view/templ-output.php';
+
exit;
+
}
-function sanitize_output($buffer) {
+function getToken(){
- $search = array(
- '/\>[^\S ]+/s', // strip whitespaces after tags, except space
- '/[^\S ]+\</s', // strip whitespaces before tags, except space
- '/(\s)+/s' // shorten multiple whitespace sequences
- );
+ $db = $GLOBALS["db"];
- $replace = array(
- '>',
- '<',
- '\\1'
- );
+ do {
+ $arr = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
- $buffer = preg_replace($search, $replace, $buffer);
+ $short="";
+ for ($i=0;$i<5;$i++){
+ $r = mt_rand(0, count($arr)-1);
+ $short.=$arr[$r];
+ }
+ } while( $db->exists($short) );
- return $buffer;
+ return $short;
+}
+
+function redirect($goto){
+ header($_SERVER["SERVER_PROTOCOL"] . " 301 Moved Permanently");
+ header("Location: " . $goto);
+ exit;
}