Noht /functions.php

Language PHP Lines 144
MD5 Hash 4ee3f906e5ee78192a6dad0dba48287e
Repository https://github.com/monkeymars/Noht.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?
// Global functionality
// should be included on every page

session_start();

$user = $_COOKIE['noht_user_hash'] ? $_COOKIE['noht_user_hash'] : setHashCookie();
$new_user;

$a_year = time()+(60*60*24*365);

function setHashCookie() {
	$cookie = sha1(time().str_replace(".", $_SERVER['REMOTE_ADDR']));
	setcookie("noht_user_hash", $cookie, $a_year);
	
	global $new_user;
	$new_user = true;
	
	return $cookie;
}

$title = "Noht. sharing drawings. A simple HTML5 mobile canvas drawing, social sharing, application";

function alphaID($in, $to_num = false, $pad_up = false, $passKey = null) {

  $index = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  if ($passKey !== null) {
    // Although this function's purpose is to just make the
    // ID short - and not so much secure,
    // with this patch by Simon Franz (http://blog.snaky.org/)
    // you can optionally supply a password to make it harder
    // to calculate the corresponding numeric ID
 
    for ($n = 0; $n<strlen($index); $n++) {
      $i[] = substr( $index,$n ,1);
    }
 
    $passhash = hash('sha256',$passKey);
    $passhash = (strlen($passhash) < strlen($index))
      ? hash('sha512',$passKey)
      : $passhash;
 
    for ($n=0; $n < strlen($index); $n++) {
      $p[] =  substr($passhash, $n ,1);
    }
 
    array_multisort($p,  SORT_DESC, $i);
    $index = implode($i);
  }
 
  $base  = strlen($index);
 
  if ($to_num) {
    // Digital number  <<--  alphabet letter code
    $in  = strrev($in);
    $out = 0;
    $len = strlen($in) - 1;
    for ($t = 0; $t <= $len; $t++) {
      $bcpow = bcpow($base, $len - $t);
      $out   = $out + strpos($index, substr($in, $t, 1)) * $bcpow;
    }
 
    if (is_numeric($pad_up)) {
      $pad_up--;
      if ($pad_up > 0) {
        $out -= pow($base, $pad_up);
      }
    }
    $out = sprintf('%F', $out);
    $out = substr($out, 0, strpos($out, '.'));
  } else {
    // Digital number  -->>  alphabet letter code
    if (is_numeric($pad_up)) {
      $pad_up--;
      if ($pad_up > 0) {
        $in += pow($base, $pad_up);
      }
    }
 
    $out = "";
    for ($t = floor(log($in, $base)); $t >= 0; $t--) {
      $bcp = bcpow($base, $t);
      $a   = floor($in / $bcp) % $base;
      $out = $out . substr($index, $a, 1);
      $in  = $in - ($a * $bcp);
    }
    $out = strrev($out); // reverse
  }
 
  return $out;
}

$colors = array(
	"black" 	=> array("hex" => "000", "rgb" => array("r" => 0, "g" => 0, "b" => 0)),
	"white" => array("hex" => "fff", "rgb" => array("r" => 255, "g" => 255, "b" => 255)),
	"blue" => array("hex" => "6cf", "rgb" => array("r" => 102, "g" => 204, "b" => 255)),
	"red" => array("hex" => "d6012a", "rgb" => array("r" => 214, "g" => 1, "b" => 42)),
	"orange" => array("hex" => "e36731", "rgb" => array("r" => 227, "g" => 103, "b" => 49)),
	"yellow" => array("hex" => "dbce0a", "rgb" => array("r" => 219, "g" => 206, "b" => 10)),
	"green" => array("hex" => "4a6e00", "rgb" => array("r" => 74, "g" => 110, "b" => 0)),
	"purple" => array("hex" => "503662", "rgb" => array("r" => 80, "g" => 54, "b" => 98)),
	"pink" => array("hex" => "da6aa5", "rgb" => array("r" => 218, "g" => 106, "b" => 165)),
);

function timeAgo($time) {

	$time = time() - $time; // to get the time since that moment
		
	$tokens = array (
			31536000 => 'year',
			2592000 => 'month',
			604800 => 'week',
			86400 => 'day',
			3600 => 'hour',
			60 => 'minute',
			1 => 'second'
	);

	foreach ($tokens as $unit => $text) {
		if ($time < $unit) continue;
		$numberOfUnits = floor($time / $unit);
		return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'').' ago';
	}

}

function deviceCheck() {
	
	if( stristr($_SERVER['HTTP_USER_AGENT'],'ipad') ) {
		$device = "ipad";
	} else if( stristr($_SERVER['HTTP_USER_AGENT'],'iphone') || strstr($_SERVER['HTTP_USER_AGENT'],'iphone') ) {
		$device = "iphone";
	} else if( stristr($_SERVER['HTTP_USER_AGENT'],'blackberry') ) {
		$device = "blackberry";
	} else if( stristr($_SERVER['HTTP_USER_AGENT'],'android') ) {
		$device = "android";
	}

	return ($device) ? $device : false;
}

$device = deviceCheck();

?>
Back to Top