CVE-2014-125072 (PHP, published 2023-01-09T22:15Z)
Description: value: A vulnerability classified as critical has been found in CherishSin klattr. This affects an unknown part. The manipulation leads to sql injection. The patch is named f8e4ecfbb83aef577011b0b4aebe96fb6ec557f1. It is recommended to apply a patch to fix this issue. The associated identifier of this vulnerability is VDB-217719.
Severity: nan (CVSS v3 base score: 8.8)
Weakness: CWE-89 \u2014 Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
Repository: https://github.com/CherishSin/klattr
Files changed:
README.md
ToCheck.txt
nginx_configs/klattr.com
www/ht_docs/activate.php
www/ht_docs/browserconfig.xml
www/ht_docs/css/.giosaveBCFZBX
www/ht_docs/css/main.css
www/ht_docs/delete_account.php
www/ht_docs/delete_klattr.php
www/ht_docs/do_login.php
www/ht_docs/do_logout.php
www/ht_docs/do_profile_edit.php
www/ht_docs/do_profile_picture_edit.php
www/ht_docs/do_profile_text_edit.php
www/ht_docs/do_signup.php
www/ht_docs/do_subscribe.php
www/ht_docs/forgot_password.php
www/ht_docs/get_more.php
www/ht_docs/get_replies.php
www/ht_docs/in.php
www/ht_docs/index.php
www/ht_docs/js/forms.js
www/ht_docs/js/sound.js
www/ht_docs/play_sound.php
www/ht_docs/process_klattr.php
www/ht_docs/reset_password.php
www/ht_docs/search.php
www/ht_docs/send_email.php
www/ht_docs/show_jpg.php
www/ht_docs/subscribed_to.php
www/ht_docs/user.php
www/ht_docs/waveform.php
www/includes/auth
www/includes/do_scroll
www/includes/email_template
www/includes/evaluate_cookie
www/includes/evaluate_password
www/includes/evaluate_signup
www/includes/footer
www/includes/forme
www/includes/fuzzyago
www/includes/head
www/includes/header
www/includes/klattr_retrieve_queries
www/includes/legal
www/includes/logged_in
www/includes/login
www/includes/m.head
www/includes/m.header
www/includes/m.logged_in
www/includes/m.login
www/includes/m.render_klattrs
www/includes/new_klattr_email_template
www/includes/new_subscriber_email_template
www/includes/open_db
www/includes/password_email_template
www/includes/render_klattrs
www/includes/render_people
www/includes/search
www/includes/search_people
www/includes/signed_up
www/includes/signup_page
www/includes/user_page
www/includes/user_panel
www/m_ht_docs/browserconfig.xml
www/m_ht_docs/css/main.css
www/m_ht_docs/do_login.php
www/m_ht_docs/do_logout.php
www/m_ht_docs/do_profile_edit.php
www/m_ht_docs/do_profile_picture_edit.php
www/m_ht_docs/do_profile_text_edit.php
www/m_ht_docs/do_signup.php
www/m_ht_docs/do_subscribe.php
www/m_ht_docs/forgot_password.php
www/m_ht_docs/get_more.php
www/m_ht_docs/get_replies.php
www/m_ht_docs/in.php
www/m_ht_docs/index.php
www/m_ht_docs/js/forms.js
www/povs/README
Commit message: fixed and commented on some of the potential sql injection vectors


Vulnerable code:

Fixed code:
klattr
======
klattr_retrieve_queries:  $sql = "SELECT ID, Subscribed_To FROM Users WHERE Handle='$profileID'";
klattr_retrieve_queries:  $sql = "SELECT ID, Handle, Name, Profile_Text FROM Users WHERE Handle REGEXP '" . $sub_regexp . "' " . $oldest_text . "AND Activated = '1' ORDER BY ID DESC LIMIT 0, 10";
klattr_retrieve_queries:  $sql = "SELECT Povs.Recipient, Povs.Num_Replies, Povs.ID, Povs.Title, Povs.Tags, Povs.Data, Povs.Private, Povs.Time_Posted, Povs.Waveform, Users.Handle FROM Users INNER JOIN Povs ON Povs.Poster=Users.ID WHERE Povs.Parent_ID='$parentId' AND Povs.Private='0' AND Users.Activated = '1' ORDER BY ID DESC LIMIT 0, 10";
klattr_retrieve_queries:  $sql = "SELECT ID, Handle, Name, Profile_Text FROM Users WHERE (Handle REGEXP '$searchTerm' OR Name REGEXP '$searchTerm')" . $oldest_text . " AND Activated = '1' ORDER BY ID DESC LIMIT 0, " . $search_limit;
klattr_retrieve_queries:  $sql = "SELECT Povs.Recipient, Povs.Num_Replies, Povs.ID, Povs.Title, Povs.Tags, Povs.Data, Povs.Private, Povs.Time_Posted, Povs.Waveform, Users.Handle FROM Users INNER JOIN Povs ON Povs.Poster=Users.ID WHERE Povs.Poster='$profileID' AND Povs.Private='0' " . $oldest_text . " AND Users.Activated = '1' ORDER BY ID DESC LIMIT 0, 10";
klattr_retrieve_queries:  $sql = "SELECT Subscribed_To FROM Users WHERE ID='$UID'";
klattr_retrieve_queries:  $sql = "SELECT Povs.Recipient, Povs.Num_Replies, Povs.ID, Povs.Title, Povs.Tags, Povs.Data, Povs.Private, Povs.Time_Posted, Povs.Waveform, Users.Handle FROM Users INNER JOIN Povs ON Povs.Poster=Users.ID WHERE (" . $sub_regexp . "INSTR(Povs.Recipient, '$uname_plus_space') > 0 OR Povs.Poster='$UID') AND Povs.Private='0' " . $oldest_text . " AND Users.Activated = '1'ORDER BY ID DESC LIMIT 0, 10";
klattr_retrieve_queries:  $sql = "SELECT Povs.Recipient, Povs.Num_Replies, Povs.ID, Povs.Title, Povs.Tags, Povs.Data, Povs.Private, Povs.Time_Posted, Povs.Waveform, Users.Handle FROM Users INNER JOIN Povs ON Povs.Poster=Users.ID WHERE (Povs.Tags REGEXP '$searchTerm' OR Povs.Title REGEXP '$searchTerm') AND Povs.Private='0' " . $oldest_text . " AND Users.Activated = '1'ORDER BY ID DESC LIMIT 0, 10";
klattr_retrieve_queries:  $sql = "SELECT Povs.Recipient, Povs.Num_Replies, Povs.ID, Povs.Title, Povs.Tags, Povs.Data, Povs.Private, Povs.Time_Posted, Povs.Waveform, Users.Handle FROM Users INNER JOIN Povs ON Povs.Poster=Users.ID WHERE (INSTR(Povs.Recipient, '$uname_plus_space') > 0) AND Povs.Private='0' " . $oldest_text . " AND Users.Activated = '1'ORDER BY ID DESC LIMIT 0, 10";
user_page:  $sql = "SELECT Handle, Name, Profile_Text, Website_Addr, Avatar, ID FROM Users WHERE Handle='$profileUname' AND BINARY(Handle) = BINARY('$profileUname') AND Activated = '1'";
user_panel:$sql = "SELECT ID, Subscribed_To FROM Users WHERE Handle='$panelName'";
user_panel:$sql = "SELECT COUNT(*) AS Count from Povs WHERE Poster='$panelUID'";
user_panel:$sql = "SELECT COUNT(*) AS Count from Users WHERE INSTR(Subscribed_To, '$handle_plus_space') > 0";
user_panel:$sql = "SELECT Handle FROM Users WHERE INSTR(Subscribed_To, '$handle_plus_space') > 0";
user_panel:  $sql = "SELECT Handle FROM Users WHERE Handle='$uname' AND INSTR(Subscribed_To, '$handle_plus_space') > 0";
user_panel:      $sql = "SELECT Activated FROM Users WHERE Handle='$sub'";
server {
  listen         80;
  server_name    klattr.com;
  rewrite        ^ https://$server_name$request_uri? permanent;
}

server {
  listen	80;
  server_name	www.klattr.com klattr.info klattr.co.uk klattr.net www.klattr.info www.klattr.co.uk www.klattr.net klattr.org www.klattr.org;
  rewrite        ^ https://klattr.com$request_uri? permanent;
}

server {
  listen         443;
  server_name    klattr.com;
  ssl on;

  ssl_certificate      /opt/certs/pems/klattr.com.pem;
  ssl_certificate_key  /opt/certs/pems/key.pem;
  client_max_body_size 4M;

  root /data/klattr.com/www/ht_docs;

  location = / {
    #Block list
    deny 70.128.119.253;
    deny 201.161.37.93;
    deny 50.23.254.99;
    deny 189.36.199.70;
    deny 113.111.202.206;
    deny 94.102.49.37;
    deny 173.201.45.104;
    deny 117.14.148.173;
    deny 188.165.192.91;
    
    index index.php;
    try_files $uri $uri/ /index.php?q=$request_uri;
  }

  location ~ .php$ {
    fastcgi_pass   localhost:9000;  # port where FastCGI processes were spawned
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME    /data/klattr.com/www/ht_docs/$fastcgi_script_name;  # same path as above
    fastcgi_param PATH_INFO               $fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
  }

  location /in {
    fastcgi_pass   localhost:9000;  # port where FastCGI processes were spawned
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME    /data/klattr.com/www/ht_docs/$fastcgi_script_name;  # same path as above
    fastcgi_param PATH_INFO               $fastcgi_script_name;
    include /etc/nginx/fastcgi_params;

  }

  location /out {
    fastcgi_pass   localhost:9000;  # port where FastCGI processes were spawned
    fastcgi_index  index.php;
    fastcgi_param REMOTE_ADDR $http_x_real_ip;
    fastcgi_param  SCRIPT_FILENAME    /data/klattr.com/www/ht_docs/$fastcgi_script_name;  # same path as above
    fastcgi_param PATH_INFO               $fastcgi_script_name;
    include /etc/nginx/fastcgi_params;

  } 


  location ~ .css$ {
  }

  location ~ .gif$ {
  }

  location ~ .png$ {
  }

  location ~ .ico$ {
  }

  location ~ .eot$ {
  }

  location ~ .ttf$ {
  }

  location ~ .cur$ {
  }

  location ~ .js$ {
  }


  location / {
    resolver 8.8.4.4;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_pass https://klattr.com/user.php?uname=$request_uri;
  }

  location ~ .jpeg$ {
    resolver 208.67.222.222;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_pass https://klattr.com/show_jpg.php?jpeg=$request_uri;
  } 

  location ~ .ogg$ {
    resolver 208.67.222.222;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_pass https://klattr.com/play_sound.php?sound=$request_uri;
  }

  location ~ .mp3$ {
    resolver 208.67.222.222;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_pass https://klattr.com/play_sound.php?sound=$request_uri;
  } 
}
<?php
$activatePage = 1;
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
  if (isset($_GET['key'])) {
    $sql = "SELECT Activation_Key FROM Users WHERE ID='$UID'";
    $sql_result = mysqli_query($con,$sql);
    $row = mysqli_fetch_array($sql_result);

    if ($_GET['key'] === $row['Activation_Key']) {
      $sql = "UPDATE Users SET Activated='1' WHERE ID='$UID'";
      mysqli_query($con,$sql);
      header( 'Location: https://klattr.com' );
    } else {
      header( 'Location: https://klattr.com' );
    }

  } else {
?>
<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/header"; ?>

<div id="body">
  <div class="body_center">
    <div class="welcome" style="padding:10px; top:-70px;height:120px">
<h1 style="padding:0px;margin:0px;">Thank you for signing up with Klattr.</h1><br> An eMail has been sent with instructions to activate your account.<br>
If you have not recieved an eMail, please click <span class="fake-link" onclick="send_email()" >here</span> to have a new one sent out.<br><br>
The Klattr Team.
    </div>
  </div>
</div>


    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>
<?php
  }  
} else {
  header( 'Location: https://klattr.com' );
}

?>
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
  <msapplication>
    <tile>
      <square70x70logo src="/mstile-70x70.png"/>
      <square150x150logo src="/mstile-150x150.png"/>
      <square310x310logo src="/mstile-310x310.png"/>
      <wide310x150logo src="/mstile-310x150.png"/>
      <TileColor>#b91d47</TileColor>
    </tile>
  </msapplication>
</browserconfig>
@font-face {
 font-family: KlattrFontBold;
 src: url("/fonts/Serif_Bold.eot") /* EOT file for IE */
}
@font-face {
 font-family: KlattrFontBold;
 src: url("/fonts/Serif_Bold.ttf") /* TTF file for CSS3 browsers */
}

@font-face {
 font-family: KlattrFont;
 src: url("/fonts/Serif.eot") /* EOT file for IE */
}
@font-face {
 font-family: KlattrFont;
 src: url("/fonts/Serif.ttf") /* TTF file for CSS3 browsers */
} 


body
{
  color:#ffffff;
  background-color:#686A88;
  background-image:url('/gfx/darkened.gif.png');
  background-repeat:no-repeat;
  background-position:center top;
  background-attachment:fixed;
  #height:100%;
  margin:0px;
  overflow:auto;
  font-size:14px;
  font-family:  KlattrFont, Arial;
}

a{
  color:#6628a6;
  text-decoration:none;
}

.fake-link {
  color:#6628a6;
  text-decoration:none;
  cursor: pointer;
}

div.profile_link{
  position:absolute;
  bottom:3px;
  width:640px;
}

a.profile{
  position:relative;
  text-align:center;
  margin-left:auto;
  margin-right:auto;

}

a:hover{
  text-decoration:none;
}

#container {
  min-height:100%;
  position:relative;
}

#header {
  position:fixed;
  width:100%;
  z-index:50;
  background:#444;
  height:30px;
  padding:0px;
  box-shadow:0px 0px 4px #000000;
}
#body {
  position:relative;
  padding:10px;
  padding-bottom:30px;   /* Height of the footer */
  height:100%;
  #overflow:auto;
}

div.feed {
  position:relative;
  width:758px;
  /* Fallback for web browsers that doesn't support RGBa */
  background: rgb(255, 255, 255) transparent;
  /* RGBa with 0.3 opacity */
  background: rgba(255, 255, 255, 0.3);
  /* For IE 5.5 - 7*/
  filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#55ffffff, endColorstr=#55ffffff);
  /* For IE 8*/
  -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#55ffffff, endColorstr=#55ffffff)";
  left:10px;
  top:-100px;
  padding-top:50px;
  padding-bottom:10px;
  color:#000;
  height:auto;
  min-height:230px;
  -moz-border-radius: 3px;
  border-radius: 3px;
}

div.user_panel_wrapper{
  //position:relative;
  //background-color:#ff0000;
  overflow:auto;
  //top:-100px;
  width:780px;
  padding:0px;
}

div.user_panel {
  position:relative;

  //position:fixed;
  color:#000;
  float:right;
  background-color:#fff;
  width:250px;
  padding:10px;
  margin-right:10px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;

}

div.feed_inner {
  position:relative;
  color:#000;
  background-color:#fff;
  width:430px;
//  padding:10px;
  margin-left:10px;
  margin-bottom:100px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;
}

#footer {
  position:fixed;
  bottom:0;
  width:100%;
  height:30px;   /* Height of the footer */
  background:#444;
  box-shadow:0px 0px 4px #000000;
}

#header_logo {
  position:relative;
  float:left;
  top:3px;
  margin-right:25px;
  border:0px;
}

#user_text {
  position:relative;
  border-style:none;
  border:3px;
  width:640px;
  height:60px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  float:right;
}

div.header_center{
  position:relative;
  width:770px;
  margin-left:auto;
  margin-right:auto;
  padding-right:30px;
  padding-top:0px;
  top:0px;
}

div.body_center{
  position:relative;
  width:800px;
  margin-left:auto;
  margin-right:auto;
  top:100px;
}

div.login{
  position:relative;
  background-color:#ffffff;
  float:left;
  left:-10px;
  width:358px;
  height:210px;
  color:#222222;
  margin:20px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;
}

div.welcome{
  position:relative;
  background-color:#ffffff;
  background-repeat:no-repeat;
  background-image:url('/gfx/welcome_bg.png');
  float:left;
  left:-10px;
  width:758px;
  height:100px;
  color:#222222;
  margin:20px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;
}

div.user_banner{
  position:relative;
  background-color:#ffffff;
  background-repeat:no-repeat;
  background-image:url('/gfx/welcome_bg.png');
  float:left;
  left:-10px;
  //top:-90px;
  width:738px;
  height:93px;
  padding:10px;
  color:#222222;
  margin:20px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;
  text-align:center;
}


div.legal{
  position:relative;
  background-color:#ffffff;
  width:456px;
  height:200px;
  color:#555555;
  margin-left:15px;
  margin-right:15px;
  margin-top:0px;
  margin-bottom:0px;
  border-width:1px;
  border-style:solid;
  border-color:#bdbdbd;
  -moz-border-radius: 3px;
  border-radius: 3px;
  overflow:auto; 
  font-size:9px;
}

div.do_signup{
  position:relative;
  background-color:#ffffff;
  background-repeat:no-repeat;
  background-image:url('/gfx/welcome_bg.png');
  float:left;
  left:-10px;
  width:758px;
  color:#222222;
  margin:20px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;
}



div.copyright{
  position:relative;
  float:right;
  right:20px;
  top:7px;
}


h1{
  margin-left:20px;
  font-family: KlattrFontBold, Arial;
  font-weight:normal;
}

h2{
  position:relative;
  margin-left:15px;
  top:15px;
  font-size:14px;
  font-family:  KlattrFontBold, Arial;
  font-weight:normal;
  display:inline;
}

h3{
  position:relative;
  top:15px;
  font-size:14px;
  font-family:  KlattrFontBold, Arial;
  font-weight:normal;
  display:inline;
  color:#686A88;
}

h4 {
  position:relative;
  display:inline;
  font-size:32px;
  font-weight:normal;
  text-align:left;
  margin-left:auto;
  margin-right:auto;
}

h5 {
  position:relative;
  display:inline;
  font-size:20px;
}

h6 {
  display:inline;
  font-size:14px;
  font-family:  KlattrFontBold, Arial;
  color:#686A88;
  margin-top:5px;
  margin-bottom:5px;
  text-decoration:none; 
  font-weight:normal; 
}

h7 {
  position:relative;
  font-size:15px;
  font-family:  KLattrFontBold, Arial;
  font-weight:normal;
  color:#686A88;
  display:block;
  vertical-align:top;
}

div.form_text
{
  position:relative;
  top:8px;
  display:inline;
  width:250px;
}

div.form_val
{
  position:relative;
  top:8px;
  display:inline;
  width:250px;
  float:right;
  padding-left:20px;
}


div.form_line{
  overflow:auto;
  margin-left:15px;
  margin-right:15px;
  margin-top:0px;
  margin-bottom:0px;
  height:35px;
  padding:2px;
}

input.submit_login{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-left:solid 1px #55bb44;
  border-top:solid 1px #55bb44;
  border-right:solid 1px #228811;
  border-bottom:solid 1px #228811;
  background-image:url('/gfx/login_button.png');
  height:28px;
  width:80px;
  box-shadow:0px 2px 2px #666666;
}

input.cancel_login{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-left:solid 1px #bb5544;
  border-top:solid 1px #bb5544;
  border-right:solid 1px #882211;
  border-bottom:solid 1px #882211;
  background-image:url('/gfx/cancel_button.png');
  height:28px;
  width:80px;
  box-shadow:0px 2px 2px #666666;
  margin-right:5px;
}


input.button_inactive{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-left:solid 1px #cccccc;
  border-top:solid 1px #cccccc;
  border-right:solid 1px #aaaaaa;
  border-bottom:solid 1px #aaaaaa;
  height:28px;
  width:80px;
  box-shadow:0px 2px 2px #cccccc;
  color:#aaaaaa;
}


input.submit_login:hover{
  background-image:url('/gfx/login_button_dark.png');
  cursor:pointer;
}

input.cancel_login:hover{
  background-image:url('/gfx/cancel_button_dark.png');
  cursor:pointer;
}

div.file_wrapper{
  float:left;
  height:32px;
  width:100px;
  overflow:hidden;
  position:relative;
  cursor:pointer;
}

div.file_wrapper > .btn-file-input{
  display:inline-block;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-top:solid 1px #bbbb44;
  border-left:solid 1px #bbbb44;
  border-right:solid 1px #888811;
  border-bottom:solid 1px #888811;
  background-image:url('/gfx/signup_button.png');
  height:28px;
  width:100px;
  box-shadow:0px 2px 2px #666666;
  cursor:pointer;
}

div.file_wr
@font-face {
 font-family: KlattrFontBold;
 src: url("/fonts/Serif_Bold.eot") /* EOT file for IE */
}
@font-face {
 font-family: KlattrFontBold;
 src: url("/fonts/Serif_Bold.ttf") /* TTF file for CSS3 browsers */
}

@font-face {
 font-family: KlattrFont;
 src: url("/fonts/Serif.eot") /* EOT file for IE */
}
@font-face {
 font-family: KlattrFont;
 src: url("/fonts/Serif.ttf") /* TTF file for CSS3 browsers */
} 


body
{
  color:#ffffff;
  background-color:#686A88;
  background-image:url('/gfx/darkened.gif.png');
  background-repeat:no-repeat;
  background-position:center top;
  background-attachment:fixed;
  #height:100%;
  margin:0px;
  overflow:auto;
  font-size:14px;
  font-family:  KlattrFont, Arial;
}

a{
  color:#6628a6;
  text-decoration:none;
}

.fake-link {
  color:#6628a6;
  text-decoration:none;
  cursor: pointer;
}

div.profile_link{
  position:absolute;
  bottom:3px;
  width:640px;
}

a.profile{
  position:relative;
  text-align:center;
  margin-left:auto;
  margin-right:auto;

}

a:hover{
  text-decoration:none;
}

#container {
  min-height:100%;
  position:relative;
}

#header {
  position:fixed;
  width:100%;
  z-index:50;
  background:#444;
  height:30px;
  padding:0px;
  box-shadow:0px 0px 4px #000000;
}
#body {
  position:relative;
  padding:10px;
  padding-bottom:30px;   /* Height of the footer */
  height:100%;
  #overflow:auto;
}

div.feed {
  position:relative;
  width:758px;
  /* Fallback for web browsers that doesn't support RGBa */
  background: rgb(255, 255, 255) transparent;
  /* RGBa with 0.3 opacity */
  background: rgba(255, 255, 255, 0.3);
  /* For IE 5.5 - 7*/
  filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#55ffffff, endColorstr=#55ffffff);
  /* For IE 8*/
  -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#55ffffff, endColorstr=#55ffffff)";
  left:10px;
  top:-100px;
  padding-top:50px;
  padding-bottom:10px;
  color:#000;
  height:auto;
  min-height:230px;
  -moz-border-radius: 3px;
  border-radius: 3px;
}
.clear { clear: both; }

div.user_panel_wrapper{
  position:relative;
  //background-color:#ff0000;
  overflow:auto;
  //top:-100px;
  width:780px;
  padding:0px;
}

div.user_panel {
  position:relative;

  //position:fixed;
  color:#000;
  float:right;
  background-color:#fff;
  width:250px;
  padding:10px;
  margin-right:10px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;

}

div.feed_inner {
  position:relative;
  color:#000;
  background-color:#fff;
  width:450px;
//  padding:10px;
  margin-left:10px;
  margin-bottom:100px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;

  -moz-border-radius: 3px;
  border-radius: 3px;
}

#footer {
  position:fixed;
  bottom:0;
  width:100%;
  height:30px;   /* Height of the footer */
  background:#444;
  box-shadow:0px 0px 4px #000000;
}

#header_logo {
  position:relative;
  float:left;
  top:3px;
  margin-right:25px;
  border:0px;
}

#user_text {
  position:relative;
  border-style:none;
  border:3px;
  width:640px;
  height:60px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  float:right;
}

div.header_center{
  position:relative;
  width:770px;
  margin-left:auto;
  margin-right:auto;
  padding-right:30px;
  padding-top:0px;
  top:0px;
}

div.body_center{
  position:relative;
  width:800px;
  margin-left:auto;
  margin-right:auto;
  top:100px;
}

div.login{
  position:relative;
  background-color:#ffffff;
  float:left;
  left:-10px;
  width:358px;
  height:210px;
  color:#222222;
  margin:20px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;
}

div.welcome{
  position:relative;
  background-color:#ffffff;
  background-repeat:no-repeat;
  background-image:url('/gfx/welcome_bg.png');
  float:left;
  left:-10px;
  width:758px;
  height:100px;
  color:#222222;
  margin:20px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;
}

div.user_banner{
  position:relative;
  background-color:#ffffff;
  background-repeat:no-repeat;
  background-image:url('/gfx/welcome_bg.png');
  float:left;
  left:-10px;
  //top:-90px;
  width:738px;
  height:93px;
  padding:10px;
  color:#222222;
  margin:20px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;
  text-align:center;
}


div.legal{
  position:relative;
  background-color:#ffffff;
  width:456px;
  height:200px;
  color:#555555;
  margin-left:15px;
  margin-right:15px;
  margin-top:0px;
  margin-bottom:0px;
  border-width:1px;
  border-style:solid;
  border-color:#bdbdbd;
  -moz-border-radius: 3px;
  border-radius: 3px;
  overflow:auto; 
  font-size:9px;
}

div.do_signup{
  position:relative;
  background-color:#ffffff;
  background-repeat:no-repeat;
  background-image:url('/gfx/welcome_bg.png');
  float:left;
  left:-10px;
  width:758px;
  color:#222222;
  margin:20px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;
}



div.copyright{
  position:relative;
  float:right;
  right:20px;
  top:7px;
}


h1{
  margin-left:20px;
  font-family: KlattrFontBold, Arial;
  font-weight:normal;
}

h2{
  position:relative;
  margin-left:15px;
  top:15px;
  font-size:14px;
  font-family:  KlattrFontBold, Arial;
  font-weight:normal;
  display:inline;
}

h3{
  position:relative;
  top:15px;
  font-size:14px;
  font-family:  KlattrFontBold, Arial;
  font-weight:normal;
  display:inline;
  color:#686A88;
}

h4 {
  position:relative;
  display:inline;
  font-size:32px;
  font-weight:normal;
  text-align:left;
  margin-left:auto;
  margin-right:auto;
}

h5 {
  margin-left:5px;
  position:relative;
  display:inline;
  font-size:20px;
}

h6 {
  display:inline;
  font-size:14px;
  font-family:  KlattrFontBold, Arial;
  color:#686A88;
  margin-top:5px;
  margin-bottom:5px;
  text-decoration:none; 
  font-weight:normal; 
}

h7 {
  position:relative;
  font-size:15px;
  font-family:  KLattrFontBold, Arial;
  font-weight:normal;
  color:#686A88;
  display:block;
  vertical-align:top;
}

div.form_text
{
  position:relative;
  top:8px;
  display:inline;
  width:250px;
}

div.form_val
{
  position:relative;
  top:8px;
  display:inline;
  width:250px;
  float:right;
  padding-left:20px;
}


div.form_line{
  overflow:auto;
  margin-left:15px;
  margin-right:15px;
  margin-top:0px;
  margin-bottom:0px;
  height:35px;
  padding:2px;
}

input.submit_login{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-left:solid 1px #55bb44;
  border-top:solid 1px #55bb44;
  border-right:solid 1px #228811;
  border-bottom:solid 1px #228811;
  background-image:url('/gfx/login_button.png');
  height:28px;
  width:80px;
  box-shadow:0px 2px 2px #666666;
  font-family:  KlattrFont, Arial;
  font-weight:normal;
  text-decoration:none;
}

input.cancel_login{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-left:solid 1px #bb5544;
  border-top:solid 1px #bb5544;
  border-right:solid 1px #882211;
  border-bottom:solid 1px #882211;
  background-image:url('/gfx/cancel_button.png');
  height:28px;
  width:80px;
  box-shadow:0px 2px 2px #666666;
  margin-right:5px;
  font-family:  KlattrFont, Arial;
  font-weight:normal;
  text-decoration:none;
}


input.button_inactive{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-left:solid 1px #cccccc;
  border-top:solid 1px #cccccc;
  border-right:solid 1px #aaaaaa;
  border-bottom:solid 1px #aaaaaa;
  height:28px;
  width:80px;
  box-shadow:0px 2px 2px #cccccc;
  color:#aaaaaa;
}


input.submit_login:hover{
  background-image:url('/gfx/login_button_dark.png');
  cursor:pointer;
}

input.cancel_login:hover{
  background-image:url('/gfx/cancel_button_dark.png');
  cursor:pointer;
}

div.file_wrapper{
  float:left;
  height:32px;
  width:100px;
  overflow:hidden;
  position:relative;
  cursor:pointer;
}

div.file_wrapper > .btn-file-input{
  display:inline-block;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-top:solid 1px #bbbb44;
  border-left:solid 1px #bbbb44;
  border-right:solid 1px #888811;
  border-bottom:solid 1px #888811;
  background-image:url('/gfx/signup_button.png');
  height:28px;
  width:100px;
  box-shadow:0px 2px 2px #666666;
  cursor:pointer;
}

div.file_wrapper:hover > .btn-file-input{
  background-image:url('/gfx/signup_button_dark.png');
  cursor:pointer;
} 

div.file_wrapper > input{

    font-size: 200px;
    position: absolute;
    top: 0;
    right: 0;
  width:102px;
  height:32px;
  filter: alpha(opacity=0); /* internet explorer */
  -khtml-opacity: 0;      /* khtml, old safari */
  -moz-opacity: 0;       /* mozilla, netscape */
    opacity: 0;
  cursor:pointer;
}

div.file_wrapper:hover > input{
  cursor:pointer;
}

input.submit_signup{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-top:solid 1px #bbbb44;
  border-left:solid 1px #bbbb44;
  border-right:solid 1px #888811;
  border-bottom:solid 1px #888811;
  background-image:url('/gfx/signup_button.png');
  height:28px;
  width:80px;
  box-shadow:0px 2px 2px #666666;
  cursor:pointer;
  font-family:  KlattrFont, Arial;
  font-weight:normal;
  text-decoration:none;

}

input.submit_signup:hover{
  background-image:url('/gfx/signup_button_dark.png');
  cursor:pointer;
} 


input.cancel_signup{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-left:solid 1px #bb5544;
  border-top:solid 1px #bb5544;
  border-right:solid 1px #882211;
  border-bottom:solid 1px #882211;
  background-image:url('/gfx/cancel_button.png');
  height:28px;
  width:80px;
  box-shadow:0px 2px 2px #666666;
  cursor:pointer;
  font-family:  KlattrFont, Arial;
  font-weight:normal;
  text-decoration:none;
}

input.cancel_signup:hover{
  background-image:url('/gfx/cancel_button_dark.png');
  cursor:pointer;
} 

input.search_submit{
  position:relative;
  float:right;
  -webkit-border-top-right-radius: 11px;
  -webkit-border-bottom-right-radius: 11px;
  -moz-border-radius-topright: 11px;
  -moz-border-radius-bottomright: 11px;
  border-top-right-radius: 11px;
  border-bottom-right-radius: 11px;
  height:26px;
  margin-top:2px;
  border-top:solid 1px #bbbb44;
  border-left:solid 1px #bbbb44;
  border-right:solid 1px #888811;
  border-bottom:solid 1px #888811;
  background-image:url('/gfx/signup_button.png');
  left:-2px;
  padding-left:4px;
}

input.search_submit:hover{
  cursor:pointer;
  background-image:url('/gfx/signup_button_dark.png');
}

input.rec_button{
  -moz-border-radius: 30px;
  border-radius: 30px;
  box-shadow:1px 0px 3px #000;
  position:absolute;
  left:110px;
  top:45px;
  border:0px;
  height:60px;
  width:60px;
  background:transparent;
  background-image:url('/gfx/rec_dark.png');
  cursor:pointer;

}

input.stop_button{
  -moz-border-radius: 30px;
  border-radius: 30px;
  box-shadow:1px 0px 3px #000;
  position:absolute;
  left:110px;
  top:45px;
  border:0px;
  height:60px;
  width:60px;
  background:transparent;
  background-image:url('/gfx/stop_dark.png');
  cursor:pointer;

}


input.play_button{
  -moz-border-radius: 30px;
  border-radius: 30px;
  box-shadow:1px 0px 3px #000;
  position:absolute;
  left:110px;
  top:45px;
  border:0px;
  height:60px;
  width:60px;
  background:transparent;
  background-image:url('/gfx/play_dark.png');
  cursor:pointer;
}

input.stop_button:hover{
  background-image:url('/gfx/stop_light.png');
  box-shadow:1px 0px 20px #f88;
  border:0px;
}

input.stop_button:focus {
  outline:0px;
}

input.play_button:hover{
  background-image:url('/gfx/play_light.png');
  box-shadow:1px 0px 20px #f88;
  border:0px;
} 

input.play_button:focus {
  outline:0px;
} 

div.progress{
  left:10px;
  width:0px;
  background-color:#ff0000;
  background-image:url('/gfx/Anim-progress.gif');
  height:60px;
  position:relative;
  display:inline-block;
}

div.play_progress{
  left:8px;
  width:0px;
  background-color:#ff0000;
  background-image:url('/gfx/Anim-progress.gif');
  height:60px;
  position:relative;
  display:inline-block;
  filter: alpha(opacity=50); /* internet explorer */
  -khtml-opacity: 0.5;      /* khtml, old safari */
  -moz-opacity: 0.5;       /* mozilla, netscape */
  opacity: 0.5;           /* fx, safari, opera */

}


input.rec_button:hover{
  background-image:url('/gfx/rec_light.png');
  box-shadow:1px 0px 20px #f88;
  border:0px;
}

input.rec_button:focus {
  outline:0px;
}

input.gen_input{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border:solid 1px #bdbdbd;
  height:26px;
  width:200px;

}
input.gen_input_left{
  -moz-border-radius: 3px;
  border-radius: 3px;
  border:solid 1px #bdbdbd;
  height:26px;
  width:200px;

}

input.search_input{
  position:relative;
  float:right;
  -webkit-border-top-left-radius: 11px;
  -webkit-border-bottom-left-radius: 11px;
  -moz-border-radius-topleft: 11px;
  -moz-border-radius-bottomleft: 11px;
  border-top-left-radius: 11px;
  border-bottom-left-radius: 11px;
  border:solid 1px #bdbdbd;
  height:22px;
  width:150px;
  margin-top:2px;
  padding-left:10px;
  
}

input.search_input:focus{
  border:solid 1px #686A88;
  outline:0px;
  width:150px;
  box-shadow:0px 0px 2px #686a88;
}

input.gen_input:focus{
  border:solid 1px #686A88;
  outline:0px;
  width:200px;
  box-shadow:0px 0px 2px #686a88;
}

input.gen_input_left:focus{
  border:solid 1px #686A88;
  outline:0px; 
  width:200px;
  box-shadow:0px 0px 2px #686a88;
} 

textarea{
  -moz-border-radius: 3px;
  border-radius: 3px;
  border:solid 1px #bdbdbd;
}

textarea:focus{
  border:solid 1px #686A88;
  outline:0px;
  box-shadow:0px 0px 2px #686a88;
}


input.checkbox_login{
  float:right;
}

div.header_button_selected{
  float:left;
  position:relative;
  background-color:#3d3d3d;
  border-left:solid 1px #333;
  border-right:solid 1px #333;
  height:25px;
  width:100px;
  box-shadow:0px 3px 3px #686A88;
  text-align: center;
  vertical-align: middle;
  font-size:18px;
  padding-top:5px;
  font-weight:bold;
  text-shadow: 0px 0px 0.4em #fff, 1px 1px #656565, -1px -1px #222;
  cursor:pointer;
  color:#D8DAF8;
}

div.header_button{
  float:left;
  position:relative;
  height:25px;
  width:100px;
  text-align: center;
  vertical-align: middle;
  font-size:18px;
  color:#333;
  padding-top:5px;
  font-weight:bold;
  text-shadow: 0px 0px 0.4em #555, 1px 1px #666, -1px -1px #111;
  cursor:pointer;

}



div.header_logout{
  position:relative;
  float:right;
  display:inline;
  font-size:12px;
  width:100px;
  text-align:right;
  cursor:pointer;
  right:5px;
  top:1px;

}

#user_pic_main {
  position:relative;
  float:left;
  width:90px;
  height:90px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;

}

#user_pic {
  position:relative;
  float:right;
  width:50px;
  height:50px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;

}

#user_pic_small {
  position:relative;
  float:right;
  width:23px;
  height:23px;
  margin:2px;
  border-width:1px;
  border-style:solid;
  border-color:#fff;
  -moz-border-radius: 3px;
  border-radius: 3px;

}



#dim
{
  height:100%;
  width:100%;
  position:fixed;
  left:0;
  top:0;
  z-index:51 !important;
  background-color:black;
  filter: alpha(opacity=0); /* internet explorer */
  -khtml-opacity: 0;      /* khtml, old safari */
  -moz-opacity: 0;       /* mozilla, netscape */
  opacity: 0;           /* fx, safari, opera */
  visibility:hidden;
}


div.dialog_wrapper 
{
  width: 100%;
  top: 100px;
  left: 0px;
  position: absolute;
  z-index: 55;
  display: block;
  visibility:hidden;
  filter: alpha(opacity=0); /* internet explorer */
  -khtml-opacity: 0;      /* khtml, old safari */
  -moz-opacity: 0;       /* mozilla, netscape */
  opacity: 0;           /* fx, safari, opera */

}

div.dialog
{
  -moz-border-radius: 3px;
  border-radius: 3px;
  width: 500px;
  margin: 0 auto;
  padding: 7px;
  background-color: #fff;
  border: 1px solid #ccc; color: #000;
  overflow:auto;
  box-shadow:0px 2px 8px #000000;
}

div.exit_button
{
  float:right;
  border: 1px solid #ddd;
  -moz-border-radius: 3px;
  border-radius: 3px;
  font=size: 10px;
  width:16px;
  text-align:center;
}

div.image_edit{
  -moz-border-radius: 3px;
  border-radius: 3px;
  border: 1px solid #ccc; color: #000;
  width:498px;
  height:220px;
  display:block;
  padding:5px
  margin-top:10px;
  margin-bottom:10px;
  background-color:#686A88;
  box-shadow:inset 0 0 10px #000000
}

img.preview_image{
  position:relative;
  width:125px;
  height:125px;
  margin-right:175;
  margin-left:175px;;
  margin-top:40px;
  -moz-border-radius: 3px;
  border-radius: 3px; 
  border: 3px solid #fff; color: #000;
  box-shadow:0px 2px 8px #000000;
}

img.centred{
  position:relative;
  margin-left:auto;
  margin-right:auto;
  display:block;
}

img.klattr_img{
  position:relative;
  height:60px;
  width:60px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;

}

div.record_div{
  position:relative;
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border: 1px solid #ccc; 
  color: #fff;
  font-size:18px;
  width:220px;
  height:60px;
  display:block;
  padding:0px
  margin-top:20px;
  margin-bottom:0px;
  background-color:#686A88;
  box-shadow:inset 0 0 10px #000000;
  vertical-align:middle;
}

div.record_div

div.blank{
  float:right;
  font-size:18px;
  height:60px;
  display:block;
  padding:0px
  margin-top:20px;
  margin-bottom:0px;
  vertical-align:middle;
}
div.record{
  position:relative;
  float:right;
  right:20px;
  top:20px;
}



td.panel_title{
  width:70px;
  font-size:10px;
  text-align:center;
}

td.panel_content{
  font-size:20px;
  text-align:center;
  color:#686A88;
}

img.preload {
  position: absolute;
  display: block;
  top: -40000px;
  left: -400000px;
}

div.delete_klattr {
  cursor:pointer;
  float:right;
}

div.tags {
  width:230px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  padding-left:3px;
  padding-right:3px;
  margin-right:2px;
  background-color:#dcdcdc;
  font-size:10px;
  float:right;
  position:relative;

}

div.replies {
  width:57px;
  height:18px
  -moz-border-radius: 3px;
  border-radius: 3px;
  padding-left:3px;
  padding-right:3px;
  padding-top:4px;
  padding-bottom:4px;
  margin-right:2px;
  background-color:#dcdcdc;
  font-size:8px;
  float:left;
  position:relative;

}

div.tag {
  -moz-border-radius: 3px;
  border-radius: 3px;
  padding:2px;
  background-color:#ffffff;
  margin:1px;
  display:inline-block;
  position:relative;

}

div.subscriber_row {
  position:relative;
  -moz-border-radius: 3px;
  border-radius: 3px;
  padding-left:3px;
  padding-right:3px;
  margin-top:3px;
  background-color:#dcdcdc
}

div.subscriber {
  vertical-align:middle;
  line-height:30px;
}

div.klattr_div {
  margin-top:10px;
}
div.klattr_div_inner {
  position:relative;
  padding-left:10px;
  padding-right:10px;
}


div.name_block {
  margin-left:5px;
  width:100px;
  float:left;
  font-size:11px;
}

div.inLineReplies {
  padding-top:10px;
  padding-bottom:10px;
  box-shadow:inset 0  10px 10px -10px #000000,inset 0 -10px 10px -10px #000000;
  margin:0px;
}
<?php
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
  $cookie_key = $_COOKIE['session_auth'];
  $sql = "DELETE FROM Session WHERE SessionKey='$cookie_key'";
  mysqli_query($con,$sql);
  unset($_COOKIE['session_auth']);
  setcookie("session_auth", "", time()-3600, "", ".klattr.com");

  $sql = "UPDATE Users SET Password_hash='' WHERE ID='$UID'";
  mysqli_query($con,$sql);
  $sql = "UPDATE Users SET Activated='0' WHERE ID='$UID'";
  mysqli_query($con,$sql);
  $sql = "UPDATE Users SET Activation_Key='' WHERE ID='$UID'";
  mysqli_query($con,$sql);

  header( 'Location: https://klattr.com' );
} elseif ($auth == 0) {
  header( 'Location: https://klattr.com' );
}
?>
<?php
include "/data/klattr.com/www/includes/auth";

if ($auth == 1) {


  $klattr_name = $_POST['klattr'];
  $klattr_path_ogg = "/data/klattr.com/www/povs/" . $klattr_name . ".ogg";
  $klattr_path_mp3 = "/data/klattr.com/www/povs/" . $klattr_name . ".mp3";

  $sql = "SELECT Parent_ID FROM Povs WHERE Data='$klattr_name' AND Poster='$UID'";
  $sql_result = mysqli_query($con,$sql);
  $row = mysqli_fetch_array($sql_result);
  if ($row['Parent_ID'] != "") {
    $parent = $row['Parent_ID'];
    $sql = "UPDATE Povs Set Num_Replies = Num_Replies - 1 WHERE ID='$parent' ";
    mysqli_query($con,$sql);
  }

  $sql = "DELETE FROM Povs WHERE Data='$klattr_name' AND Poster='$UID'";

  mysqli_query($con,$sql);
  $error = mysqli_error();
  file_put_contents('/tmp/error', $error);
  unlink($klattr_path_ogg);
  unlink($klattr_path_mp3);
} else {
  header( 'Location: https://klattr.com' );
}
?>
<?php
if (isset($_POST["username"]) && isset($_POST["password"])) {
  $username = $_POST["username"];
  $pass = $_POST["password"];
  $sticky = $_POST["stay_signed_in"];
  $expire_time = 0;
  if ($sticky == "yes") {
    $expire_time = time()+2592000;
  }

  include "/data/klattr.com/www/includes/evaluate_password";
  include "/data/klattr.com/www/includes/open_db";
  $username = evaluate_password($username, $pass);
  if ($username != 1) {
//echo $username;
    $sql = "SELECT ID FROM Users WHERE Handle='$username'";
    $sql_result = mysqli_query($con,$sql);
    $row = mysqli_fetch_array($sql_result);
    $UID = $row['ID'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $randomData = file_get_contents('/dev/urandom', false, null, 0, 128) . uniqid(mt_rand(), true);
    $randkey = substr(str_replace(array('/','=','+'),'', base64_encode($randomData)),0,128);

    $session_date = date("Y-m-d h:i:s");
    $sql = "INSERT INTO Session (SessionKey, UserID, IP, Date) VALUES ('$randkey','$UID','$ip','$session_date')";
    mysqli_query($con,$sql);
    setcookie ("session_auth", $randkey, $expire_time, "/", ".klattr.com");

    header( 'Location: https://klattr.com' );


  } else {
    header( 'Location: https://klattr.com?up=' . evaluate_password($username, $pass));
  }
} else {
  header( 'Location: https://klattr.com' );
}
?>
<?php

if (isset($_COOKIE['session_auth'])) {
  include "/data/klattr.com/www/includes/open_db";
  $cookie_key = $_COOKIE['session_auth'];
  $sql = "DELETE FROM Session WHERE SessionKey='$cookie_key'";
  mysqli_query($con,$sql);
  unset($_COOKIE['session_auth']);
  setcookie("session_auth", "", time()-3600, "", ".klattr.com");
  header( 'Location: https://klattr.com' );
} else {
  header( 'Location: https://klattr.com' );
}


?>
<?php
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
  $profileUname = $uname; 
  $sql = "SELECT Handle, Name, Profile_Text, Website_Addr, Avatar, ID FROM Users WHERE Handle='$profileUname' AND BINARY(Handle) = BINARY('$profileUname')";
  $sql_result = mysqli_query($con,$sql);
  $row = mysqli_fetch_array($sql_result);
  $profileUname = $row['Handle'];
  $profileRname = $row['Name'];
  $profileProfile = $row['Profile_Text'];
  $profileURL = $row['Website_Addr'];
  $profileID = $row[ID];
  if ($row['Avatar'] === "" || $row['Avatar'] === NULL) {
    $profileUserPic = "/gfx/default_user.png";
  } else {
    $profileUserPic = $profileUname . ".jpeg";
  }

  $page = "edit_profile";
?>
<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body onload="validatePasswordReset(Exists)">
    <script>
      Exists = 0;
    </script>
    <?php include "/data/klattr.com/www/includes/header"; ?>
<div id="body">
  <div class="body_center" style="top:10px;">
    <div class="user_banner">
      <img id="user_pic_main" src="<?php echo $profileUserPic;  ?>" onmouseover="editstyle('user_pic_main')" onmouseout="normalstyle('user_pic_main')" onclick="showeditor('edit_profile_picture')">
  
      <h4><?php echo $profileUname; ?></h4>
      <div id="user_text" style="" onmouseover="editstyle('user_text')" onmouseout="normalstyle('user_text')" onclick="showeditor('edit_profile_text')">
<?php
  if ($profileProfile == "") { 
    echo "<div class=\"mute_text\">Click to add Profile Text.</div>";
  } else {
    echo $profileProfile;
  }
  echo "<div class=\"profile_link\"><a href=\"" . $profileURL . "\" class=\"profile\">" . $profileURL . "</a></div>";
?>
  
      </div>
    </div>
    <div class="do_signup" style="top:-30px">
      <h1>Change Password.</h1>
      <form name="SignUp" method="POST" action="/reset_password.php">
      <div>
      <div class="form_line"><div class="form_text">Password:</div>
      <div class="form_val" id="val_pass"></div>
      <input type="password" class="gen_input" name="password" onkeyup="validatePasswordReset(Exists)" onblur="validatePasswordReset(Exists)"></div>
      <div class="form_line"><div class="form_text">Retype password:</div>
      <div class="form_val" id="val_pass2"></div>
      <input type="password" class="gen_input" name="password2" onkeyup="validatePasswordReset(Exists)" onblur="validatePasswordReset(Exists)"></div>
      </div>
      <div class="form_line">
        <div id="sub_div" style="display:none"><input type="submit" class="submit_signup" style="width:200px;float:right;" value="Reset Password!"></div>
        <input type="button" class="submit_signup" style="width:200px;float:right;" value="Reset Password!" onclick="reset_password()">
      </div>
      </form>
    </div>
    <div class="do_signup" style="top:-60px">
      <h1>Close Account.</h1>
      <form name="DeleteAccount" method="POST" action="/delete_account.php">
        <div class="form_line">
          <div class="form_text">
            If for some reason you'd like to close your account with us, click here.
          </div>
          <input type="submit"  class="cancel_signup" style="width:200px;float:right;" value="Close Account!"> 
          
        </div>
      </form>
    </div>
  </div>
</div>


<div id="dim"></div>
<div class="dialog_wrapper" id="edit_profile_text">
  <div class="dialog">
    <h5>Edit Profile Text & Web Address.</h5>
    <img src="/gfx/hr.png" width="450" height="1"/>
    <Form name="EditProfile" action="/do_profile_text_edit.php" method="post">
      Profile Text:<br>
      <textarea rows="4" cols="60" name="profileText" placeholder="Describe yourself here."><?php echo $profileProfile; ?></textarea><br>
      Web Address:<br>
      <input type="text" class="gen_input_left" name="webAddress" value="<?php echo $profileURL;?>">
      <input type="hidden" name="senduname" value="<?php echo $profileUname; ?>">
      <input type="submit" class="submit_login" style="width:100px;" value="Save It">
      <input type="button" onclick="hideeditor('edit_profile_text')" class="cancel_login" style="width:100px;" value="Cancel">
    </Form>
  </div>
</div>

<div class="dialog_wrapper" id="edit_profile_picture">
  <div class="dialog">
    <h5>Edit Profile Picture</h5>
    <img src="/gfx/hr.png" width="450" height="1"/>
    <form name="EditProfilePicture" enctype="multipart/form-data" action="/do_profile_picture_edit.php" method="post">
      Choose image file:<br>
      <div class="image_edit">
        <img id="image_upload" src="<?php echo $userPic;?>" class="preview_image" /> 
      </div>
      <div class="file_wrapper">
        <button class="btn-file-input">Choose File</button>
        <input type="hidden" name="senduname" value="<?php echo $profileUname; ?>">
        <input id="imgInp" type="file" name="file" accept="image/gif, image/jpeg, image/png" />
      </div>
      <input type="submit" class="submit_login" style="width:100px;" value="Save It">
      <input type="button" onclick="hideeditor('edit_profile_picture')" class="cancel_login" style="width:100px;" value="Cancel">
    </form>
  </div>
</div>
    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>
<?php
} else {
  header( 'Location: https://klattr.com' );
}
?>
<?php
include "/data/klattr.com/www/includes/auth";

if ($auth == 1) {
//  echo print_r($_FILES);
//  echo $_FILES['file']['tmp_name'];

  $senduname = $_POST["senduname"];
  $type = $_FILES['file']['type'];
  $type = substr($type, 0, 5);
  if ($_FILES['file']['tmp_name'] != "" && $type === "image") {
    $image = new Imagick($_FILES['file']['tmp_name']);
    $image->resizeImage(150,150, imagick::FILTER_LANCZOS, 0.9, false);
    $image->setImageFormat('jpeg');
    $image = addslashes($image);
    $sql = "UPDATE Users SET Avatar='$image' WHERE ID='$UID'";
    mysqli_query($con,$sql);
  }
  header( "Location: https://klattr.com/$senduname" );

//  header('Content-type: image/jpeg');
//  echo $image;

} else {
  header( 'Location: https://klattr.com' );
}

?>
<?php
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
  $profileText = $_POST["profileText"];
  $profileURL = $_POST["webAddress"];
  $senduname = $_POST["senduname"];
  if(strpos($profileURL, 'http') !== 0) {
    $profileURL = "http://" . $profileURL;
  }
  if(!filter_var($profileURL, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) {
    $profileURL = "";
  }
/*Sanitize the vars that are going into the database*/
  $profileText = htmlspecialchars($profileText);
  $profileText = addslashes($profileText);
  $profileURL = htmlspecialchars($profileURL);
  $profileURL = addslashes($profileURL);


  $sql = "UPDATE Users SET Website_Addr='$profileURL', Profile_Text='$profileText' WHERE ID='$UID'";
  mysqli_query($con,$sql);
  header( "Location: https://klattr.com/$senduname" );
  } else {
  header( 'Location: https://klattr.com' );
}
?>
<?php

$accountLimit = 250;

if (isset($_COOKIE['session_auth'])) {
  header( 'Location: https://klattr.com' );
} else {


  include "/data/klattr.com/www/includes/open_db";
  $sql = "SELECT COUNT(*) AS Num FROM Users";
  $sql_result = mysqli_query($con,$sql);
  $row = mysqli_fetch_array($sql_result);
  if ($row['Num'] > $accountLimit) {
?>

<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/header"; ?>

<div id="body">
  <div class="body_center">
    <div class="welcome" style="padding:10px; top:-70px;height:120px">
      <h1> Sorry. This beta is limited to <?php echo $accountLimit; ?> accounts. Please try later.</h1>
    </div>
  </div>
</div>


    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>
<?php
  } else {



 
    if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["password"]) && isset($_POST["username"])) {

      $name = $_POST["name"];
      $email = $_POST["email"];
      $password = $_POST["password"];
      $username = $_POST["username"];
      $sticky = $_POST["stay_signed_in"];
      $expire_time = 0;
      if ($sticky == "yes") {
        $expire_time = time()+2592000;
      }

      include "/data/klattr.com/www/includes/evaluate_signup";

      $e_n = evaluate_name($name);
      $e_e = evaluate_email($email);
      $e_p = evaluate_pass($password);
      $e_u = evaluate_uname($username);

      if ($e_n != 0 || $e_e != 0 || $e_p != 0 || $e_u != 0) {
        $exists = $e_e + $e_u;
        include "/data/klattr.com/www/includes/signup_page";
      } else {
        $enc_password = urlencode($password);
        $password_hash = crypt($enc_password);
#      $randkey = substr(str_shuffle(md5(time())),0,128);
#      $randkey = substr(sha1(rand()), 0, 128);
        $randomData = file_get_contents('/dev/urandom', false, null, 0, 128) . uniqid(mt_rand(), true);
        $randkey = substr(str_replace(array('/','=','+'),'', base64_encode($randomData)),0,128);

        $ip = $_SERVER['REMOTE_ADDR'];
        $sql = "INSERT INTO Users (Name, Email_Addr, Password_hash, Handle) VALUES ('$name','$email','$password_hash','$username')";
        mysqli_query($con,$sql);
        $sql = "SELECT ID FROM Users WHERE Handle='$username'";
        $sql_result = mysqli_query($con,$sql);
        $row = mysqli_fetch_array($sql_result);
        $UID = $row['ID'];
        $session_date = date("Y-m-d h:i:s");
        setcookie ("session_auth", $randkey, $expire_time, "/", ".klattr.com");
/*make sure the cookie in the database matches sanitized cookie from user*/
        $randkey = htmlspecialchars($randkey);
        $randkey = addslashes($randkey);

        $sql = "INSERT INTO Session (SessionKey, UserID, IP, Date) VALUES ('$randkey','$UID','$ip','$session_date')";
        mysqli_query($con,$sql);
        $uname = $username;
        $rname = $name;
        $uEmailAddr = $email;
        $first_mail = 1;
        include "/data/klattr.com/www/ht_docs/send_email.php";
        header( 'Location: https://klattr.com' );
//      include "/data/klattr.com/www/includes/signed_up";
      }
    } else {

  $name = $_POST["name"];
  $email = $_POST["email"];
  $password = $_POST["password"];
  $username = $_POST["username"];

  include "/data/klattr.com/www/includes/signup_page";
    }
  }
}
?>
<?php

$outfile = "/tmp/output.txt";

include "/data/klattr.com/www/includes/auth";

if ($auth == 1) {
	$target = $_POST['sub_to'];

	$sql = "SELECT Subscribed_To FROM Users WHERE ID='$UID'";
	$sql_results = mysqli_query($con,$sql);
	$row = mysqli_fetch_array($sql_results);
	$sub_list = $row['Subscribed_To'];

	if (preg_match("/^[a-zA-Z0-9_]+$/",$target)) {

		$target_matcher = " " . $target . " ";

		if (strpos($sub_list, $target_matcher) !== false) {
			$sub_list = str_replace($target_matcher, " ", $sub_list);
		} else {
			$sub_list = $sub_list . $target_matcher;
			$sub_list = str_replace('  ',' ',$sub_list);
		}

		$sql = "UPDATE Users SET Subscribed_To='$sub_list' WHERE ID='$UID'";
		mysqli_query($con,$sql);
	}

	//
	// Add the current user to the list of Subscribers for the person they're subscribing to
	$sql = "SELECT Subscribers FROM Users WHERE Handle='$target'";
	$sql_results = mysqli_query($con,$sql);
	$row = mysqli_fetch_array($sql_results);
	$sub_list = $row['Subscribers'];

	if (preg_match("/^[a-zA-Z0-9_]+$/",$UID)) {

		$target_matcher = " " . $UID. " ";

		if (strpos($sub_list, $target_matcher) !== false) {
			$sub_list = str_replace($target_matcher, " ", $sub_list);
		} else {
			$sub_list = $sub_list . $target_matcher;
			$sub_list = str_replace('  ',' ',$sub_list);
            $adding = 1;
		}

		$sql = "UPDATE Users SET Subscribers='$sub_list' WHERE Handle='$target'";
		mysqli_query($con,$sql);
	}

    // send emails to the subscribee
    $sql = "SELECT Name, Email_Addr FROM Users WHERE Handle = '$target' AND Activated = '1'";
    $sql_result = mysqli_query($con,$sql);
    $row = mysqli_fetch_array($sql_result);
    if ($row['Name'] != "" && $adding == 1) {
      $emailText = file_get_contents("/data/klattr.com/www/includes/new_subscriber_email_template");
      $emailText = str_replace("FULLNAME", $row['Name'], $emailText);
      $emailText = str_replace("SENDER", $uname, $emailText);
      $headers = "From: Klattr Team <administrator@klattr.com>\r\nReply-To: No Reply\r\n";
      $headers .= "MIME-Version: 1.0\r\n";
      $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
      mail($row['Email_Addr'], "You have a new subscriber!", $emailText, $headers);
    }
    	

} else {
	header( 'Location: https://klattr.com' );
}
?>
<?php
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
  header( 'Location: https://klattr.com' );
} elseif ($auth == 0) {
  if (isset($_POST['eoru'])) {
    $eoru = addslashes($_POST['eoru']);
    $eoru = str_replace(";", "", $eoru);

    include "/data/klattr.com/www/includes/open_db";
    $sql = "SELECT Email_Addr, ID, Name FROM Users WHERE Email_Addr='$eoru' OR Handle='$eoru'";
    $sql_result = mysqli_query($con,$sql);
    $row = mysqli_fetch_array($sql_result);
    
    if ($row['Email_Addr'] != "") {
      
      $rname = $row['Name'];
      $uEmailAddr = $row['Email_Addr'];
      $UID = $row['ID'];

      $emailText = file_get_contents("/data/klattr.com/www/includes/password_email_template");
      $emailText = str_replace("FULLNAME", $rname, $emailText);
      $randomData = file_get_contents('/dev/urandom', false, null, 0, 64) . uniqid(mt_rand(), true);
      $randkey = substr(str_replace(array('/','=','+'),'', base64_encode($randomData)),0,64);
      $emailText = str_replace("UNIQUEKEY", $randkey, $emailText);
      $headers = "From: Klattr Team <administrator@klattr.com>\r\nReply-To: No Reply\r\n";
      $headers .= "MIME-Version: 1.0\r\n";
      $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
      $sql = "UPDATE Users SET Activation_Key='$randkey' WHERE ID='$UID'";
      mysqli_query($con,$sql);
      mail($uEmailAddr, "Reset Password", $emailText, $headers);

?>
<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/header"; ?>
<div id="body">
  <div class="body_center">
    <div class="welcome" style="padding:10px; top:-70px;">
      Email sent. Please check your email for instructions.
    </div>
  </div>
</div>
    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>
<?php
    }
  } elseif (isset($_GET['key'])) {
    include "/data/klattr.com/www/includes/open_db";
    $recieved_key = addslashes($_GET['key']);
    $recieved_key = str_replace(";", "", $recieved_key);    
    $sql = "SELECT ID, Name, Handle, Activation_Key FROM Users WHERE Activation_Key='$recieved_key'";
    $sql_result = mysqli_query($con,$sql);
    $row = mysqli_fetch_array($sql_result);
?>
<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body onload="validatePasswordReset(Exists)">
    <script>
      Exists = 0;
    </script>
    <?php include "/data/klattr.com/www/includes/header"; ?>
<div id="body">
  <div class="body_center">
    <div class="welcome" style="padding:10px; top:-70px; height:200px">
      <h1>Reset password for <?php echo $row['Handle']; ?>.</h1>
      <form name="SignUp" method="POST" action="/reset_password.php">
      <div>
      <div class="form_line"><div class="form_text">Password:</div>
      <div class="form_val" id="val_pass"></div>
      <input type="password" class="gen_input" name="password" onkeyup="validatePasswordReset(Exists)" onblur="validatePasswordReset(Exists)"></div>
      <div class="form_line"><div class="form_text">Retype password:</div>
      <div class="form_val" id="val_pass2"></div>
      <input type="password" class="gen_input" name="password2" onkeyup="validatePasswordReset(Exists)" onblur="validatePasswordReset(Exists)"></div>
      </div>
      <div class="form_line">
        <div class="form_val">&nbsp;</div>
        <div id="sub_div"><input type="submit" class="submit_signup" style="width:200px;" value="Reset Password!"></div>
      </div>
      <input type="hidden" name="key" value="<?php echo $recieved_key; ?>">
      </form>
    </div>
  </div>
</div>
    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>
<?php    
  } else {
?>

<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/header"; ?>
<div id="body">
  <div class="body_center">
    <div class="welcome" style="padding:10px; top:-70px;height:150px">
<h1 style="padding:0px;margin:0px;">Retrieve Password.</h1><br> Please enter your eMail address or your username below and we'll send you an eMail with further instructions for resetting your password.<br><br>
<form name="retrieve_form" method="POST" action="/forgot_password.php">
<div class="form_line">
<div class="form_text">Username/eMail Address:</div>
<input type="submit" class="submit_signup" style="width:200px;margin-left:10px;" value="Submit!">
<input type="text" class="gen_input" style="width:300px" name="eoru">

</div></form>
    </div>
  </div>
</div>
    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>
<?php
  }
}
?>
<?php
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
  if (isset($_POST['oldest'])) {
    $oldest = $_POST['oldest'];
    $page = $_POST['page'];
    if (isset($_POST['profile_id'])) {
      $profileID = $_POST['profile_id'];
    }
    $get_more = 1;
// echo $page;
    $searchTerm = $_POST['search'];
    include "/data/klattr.com/www/includes/klattr_retrieve_queries";

    if ($page == "peopleSearch" ||  $page == "subscribed_to") {
//    echo "A";
      include "/data/klattr.com/www/includes/render_people";
    } else {
//    echo "B";
      include "/data/klattr.com/www/includes/render_klattrs";
    }
  }
} else {
  header( 'Location: https://klattr.com' );
}

?>
<?php
include "/data/klattr.com/www/includes/auth";
$parentId = $_POST['parent_id'];
$nestLevel = $_POST['nest_level'];

$page = "replies";
if (is_numeric($parentId) && is_numeric($nestLevel)) {
  include "/data/klattr.com/www/includes/klattr_retrieve_queries";
  include "/data/klattr.com/www/includes/render_klattrs";
}
?>
<?php
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
$page = "Forme";
?>

<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/header"; ?>
    <?php include "/data/klattr.com/www/includes/forme"; ?>

<?php
} else {
  header( 'Location: https://klattr.com' );
}
?>
    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>

<?php
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
$page = "Feed";
?>

<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/header"; ?>
    <?php include "/data/klattr.com/www/includes/logged_in"; ?>

<?php
} elseif ($auth == 0) {
?>

<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/header"; ?>
    <?php include "/data/klattr.com/www/includes/login"; ?>

<?php
}


?>




    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>
var klattr_recipient = "";
var klattr_parent_id = "";
var oldest_klattr;
var loading_content = 0;
var profile_id;
var search_term;



  function validateEmailAddr(email) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
  }

  function validateNameString(name) {
    var re = /^[a-zA-Z]+[a-zA-Z ]+$/;
    return re.test(name);
  }

  function validateUnameString(uname) {
    var re = /^[a-zA-Z0-9_]+$/;
    return re.test(uname);
  }

  function validateForm(Exist)
  {
    a = validateName();
    b = validateEmail(Exist);
    c = validatePassword();
    d = validateUsername(Exist);
    if (a + b + c + d == 0) {
      document.getElementById("sub_div").innerHTML = "<input type=\"submit\" class=\"submit_signup\" style=\"width:200px;\" value=\"Sign Up!\">";
    } else {
      document.getElementById("sub_div").innerHTML = "<input type=\"button\" class=\"button_inactive\" style=\"width:200px;\" value=\"Form Incomplete!\">";
    }
    Exists = 0;
  }

  function validatePasswordReset(Exists)
  {
    a = validatePassword();
    b = validatePassword2();
    if (a + b == 0) {
      document.getElementById("sub_div").innerHTML = "<input type=\"submit\" class=\"submit_signup\" style=\"width:200px;\" value=\"Reset Password!\">";
    } else {
      document.getElementById("sub_div").innerHTML = "<input type=\"button\" class=\"button_inactive\" style=\"width:200px;\" value=\"Form Incomplete!\">";
    }
    Exists = 0;
  }

  function validateName()
  {
    var nameString=document.forms["SignUp"]["name"].value;
    if (nameString==null || nameString==""){
      document.getElementById("val_name").innerHTML = "<font color=\"red\"> &#8678; You'll need a name.</font>";
      return 1;
    } else {
      if (validateNameString(nameString)) {
        document.getElementById("val_name").innerHTML = "<font color=\"green\"> &#10004; That name is fine.</font>";
        return 0;
      } else {
        document.getElementById("val_name").innerHTML = "<font color=\"red\"> &#8678; Letters only please.</font>";
        return 1;
      }
    }
  }

  function validateEmail(Exist)
  {
    if (Exist == 20 || Exist == 22) {
      document.getElementById("val_email").innerHTML = "<font color=\"red\"> &#8678; That address has been used.</font>";
      return 1;
    } else {
      var emailString=document.forms["SignUp"]["email"].value;
      if (emailString==null || emailString==""){
        document.getElementById("val_email").innerHTML = "<font color=\"red\"> &#8678; You'll need an eMail address.</font>";
        return 1;
      } else {
        if (validateEmailAddr(emailString)){
          document.getElementById("val_email").innerHTML = "<font color=\"green\"> &#10004; eMail address looks good.</font>";
          return 0;
        } else {
          document.getElementById("val_email").innerHTML = "<font color=\"red\"> &#8678; Are you sure?.</font>";
          return 1;
        }
      }
    }
  }

  function validatePassword()
  {
    var passString=document.forms["SignUp"]["password"].value;
    if (passString==null || passString==""){
      document.getElementById("val_pass").innerHTML = "<font color=\"red\"> &#8678; You'll want a password.</font>";
      return 1;
    } else {
      if (passString.length < 6){
        document.getElementById("val_pass").innerHTML = "<font color=\"red\"> &#8678; Six characters or more please.</font>";
        return 1;
      } else {
        document.getElementById("val_pass").innerHTML = "<font color=\"green\"> &#10004; Password is alright.</font>";
        return 0;
      }
    }
  }

  function validatePassword2()
  {
    var pass2String=document.forms["SignUp"]["password2"].value;
    var passString=document.forms["SignUp"]["password"].value;
    if (pass2String==null || pass2String==""){
      document.getElementById("val_pass2").innerHTML = "<font color=\"red\"> &#8678; Please retype Password.</font>";
      return 1;
    } else {
      if (pass2String == passString) {
        document.getElementById("val_pass2").innerHTML = "<font color=\"green\"> &#10004; Looks good.</font>";
        return 0;
      } else {
        document.getElementById("val_pass2").innerHTML = "<font color=\"red\"> &#8678; Passwords must match.</font>";
        return 1;
      }
    }
  }

  function validateUsername(Exist)
  {
    if (Exist == 2 || Exist == 22) {
      document.getElementById("val_uname").innerHTML = "<font color=\"red\"> &#8678;That username's gone. Sorry.</font>";
      return 1;
    } else {
      var unameString=document.forms["SignUp"]["username"].value;
      if (!validateUnameString(unameString)){
        if ( unameString == "") {
          document.getElementById("val_uname").innerHTML = "<font color=\"red\"> &#8678; A username is a must.</font>";
        } else {
          document.getElementById("val_uname").innerHTML = "<font color=\"red\"> &#8678; Letters and numbers only.</font>";
        }
        return 1;
      } else {
        if (unameString.length < 3) {
          document.getElementById("val_uname").innerHTML = "<font color=\"red\"> &#8678; At least three characters.</font>";
          return 1;
        } else {
          document.getElementById("val_uname").innerHTML = "<font color=\"green\"> &#10004; Looks good!";
          return 0;
        }
      }
    }  
  }

  function editstyle(Element)
  {
    El = document.getElementById(Element);
    El.style.boxShadow = '0px 0px 1px 2px #44ff44';
    El.style.cursor = 'url(/gfx/edit_cur.cur),auto';
  }

  function normalstyle(Element)
  {
    El = document.getElementById(Element);
    El.style.boxShadow = 'none';
    El.style.cursor = 'auto';

  }

  function showeditor(EditItem)
  {
    fade_in('dim', 0, 0.7);
    fade_in(EditItem, 0, 1);
    slide_in(EditItem, 100);
    document.getElementsByTagName("body")[0].style.overflow = "hidden";
    get_mic();
    
  }

  function showAlert(EditItem)
  { 
    fade_in(EditItem, 0, 1);
    slide_in(EditItem, 20);
    
  }

  function hideeditor(EditItem)
  {
    document.getElementById('dim').style.opacity = '0';
    document.getElementById('dim').style.filter = 'alpha(opacity=0)';

    document.getElementById(EditItem).style.opacity = '0';
    document.getElementById(EditItem).style.filter = 'alpha(opacity=0)';

    document.getElementById('dim').style.visibility = 'hidden';
    document.getElementById(EditItem).style.visibility = 'hidden';
    document.getElementsByTagName("body")[0].style.overflow = "auto";
  }

  function hideAlert(EditItem)
  {
    fade_out(EditItem, 1, 0);
    //document.getElementById(EditItem).style.opacity = '0';
    //document.getElementById(EditItem).style.filter = 'alpha(opacity=0)';
    //document.getElementById(EditItem).style.visibility = 'hidden';

  }

  function readURL(input)
  {
    if (input.files && input.files[0]) {
      var reader = new FileReader();
     
      reader.onload = function (e) {
        $('#image_upload').attr('src', e.target.result);
      }
            
      reader.readAsDataURL(input.files[0]);
    }
  }
    
  $("#imgInp").change(function(){
    readURL(this);
  });

  function slide_in(element, terminus) {
    top_modifier = document.documentElement.scrollTop || document.body.scrollTop;
    etop = top_modifier -400; 
    terminus += top_modifier;
    var timer = setInterval(function() {
//      console.log(etop)
      if (etop >= terminus){
        clearInterval(timer);
      }
      document.getElementById(element).style.top = '' + etop + 'px';
//console.log(document.getElementById(element).style.top)
      etop += 16;
    }, 1);
  }

  function fade_in(element, start, end) {
    op = start;  // initial opacity
    document.getElementById(element).style.visibility = 'visible';
    var timer = setInterval(function () {
      if (op >= end ){
        clearInterval(timer);
      }
      document.getElementById(element).style.opacity = parseFloat(op);
      document.getElementById(element).style.filter = 'alpha(opacity=' + parseFloat(op * 100) + ")";
      op += 0.1;
    }, 20);
  }

  function fade_out(element, start, end) {
    op = start;  // initial opacity
    var timer = setInterval(function () {
      if (op <= end ){
        clearInterval(timer);
      }
      document.getElementById(element).style.opacity = parseFloat(op);
      document.getElementById(element).style.filter = 'alpha(opacity=' + parseFloat(op * 100) + ")";
      op -= 0.1;
    }, 20);
    document.getElementById(element).style.visibility = 'hidden';
  }


  function make_submit_form() {
    document.getElementById("Add_title").innerHTML = "<div class=\"form_line\" style=\"margin-right:0px\"><div class=\"form_text\">Add a title:</div><input type=\"text\" class=\"gen_input\" maxlength=\"20\" style=\"width:300px;\" name=\"klattr_title\"></div><div class=\"form_line\" style=\"margin-right:0px\"><div class=\"form_text\">Add recipients (Max 5):</div><input type=\"text\" class=\"gen_input\" style=\"width:300px;\" name=\"klattr_recipients\" id=\"klattr_recipients\"></div>"; 
    document.getElementById("Add_tags").innerHTML = "<div id=\"output\"></div><div class=\"form_line\" style=\"margin-right:0px\"><div class=\"form_text\">Add some tags:</div><input type=\"text\" class=\"gen_input\" style=\"width:300px;\" name=\"klattr_tags\"></div>";
    document.getElementById("button_line").innerHTML = "<input type=\"button\" class=\"submit_login\" style=\"width:100px;\" value=\"Send It\" onclick=\"save_recording()\"><input type=\"button\" onclick=\"hideeditor('record_popup');reset_recording();destroy_submit_form();\" class=\"cancel_login\" style=\"width:100px;\" value=\"Cancel\">";
    
    document.getElementById("klattr_recipients").value = klattr_recipient;
    
  }

  function destroy_submit_form() {
    document.getElementById("Add_title").innerHTML = "";
    document.getElementById("Add_tags").innerHTML = "";
    document.getElementById("button_line").innerHTML = "<input type=\"button\" onclick=\"hideeditor('record_popup');reset_recording();destroy_submit_form();\" class=\"cancel_login\" style=\"width:100px;margin-right:0px\" value=\"Cancel\">";
    document.getElementById('record_div').className = "record_div";
    document.getElementById('record_div').style.width = "470px";
    document.getElementById('record_div').innerHTML = "<div class=\"progress\" id=\"progress\"><div id=\"instructions\" style=\"position:relative;top:18px;left:30px;float:left;width:300px\"><-- Click to start recording</div></div>";
    document.getElementById('klattr_wrapper').innerHTML = "<input type=\"button\" id=\"do_record\" class=\"rec_button\" onclick=\"record(19500);toggle_recording()\" style=\"z-index:100;top:1px;left:0px;\">";
    klattr_parent_id = "";
  }

  function send_klattr_form(Kblob) {
    document.getElementById('record_div').className = "blank"
    document.getElementById('record_div').innerHTML = "<img src=\"/gfx/wait.gif\" class=\"centred\">"; 
    document.getElementById('record_div').style.width = "500px";   
    document.getElementById('klattr_wrapper').innerHTML = ""; 
    var
      oOutput = document.getElementById("output"),
      oData = new FormData(document.forms.namedItem("SubmitKlattr"));
    if (klattr_parent_id != "") {
      oData.append("parent_id", klattr_parent_id);
    }
    oData.append("klattr_audio", Kblob);

    var oReq = new XMLHttpRequest();
    oReq.open("POST", "/process_klattr.php", true);
    oReq.onload = function(oEvent) {
      hideeditor('record_popup');
      destroy_submit_form();
      reset_recording();
      if (oReq.status == 200) {
        popAlert("Uploaded!");
        location.reload();
      } else {
        popAlert("Error " + oReq.status + " occurred uploading your file.<br \/>");
      }
    };

  oReq.send(oData);
  }


  function popAlert(message) {
    document.getElementById('popAlert_message').innerHTML = message;
    showAlert('popAlert'); 
    setTimeout(function(){hideAlert('popAlert')}, 2000); 
  }

  function delete_klattr(klattr) {
    console.log("here")
    var
      oOutput = document.getElementById("output"),
      oData = new FormData(document.forms.namedItem("delete_klattr"));

    oData.append("klattr", klattr);

    var oReq = new XMLHttpRequest();
    oReq.open("POST", "/delete_klattr.php", true);
    oReq.onload = function(oEvent) {
      if (oReq.status == 200) {
//console.log("success")
        popAlert("Klattr Deleted!");
        var element = document.getElementById(klattr);
        element.parentNode.removeChild(element);
//console.log('done')
      } else {
//console.log("failure")
        popAlert("Error " + oReq.status);
      }
    };
  oReq.send(oData); 
  }

  function subscribe_to() {
    var 
      oOutput = document.getElementById("output"),
      oData = new FormData(document.forms.namedItem("Subscribe"));

    var oReq = new XMLHttpRequest();
    oReq.open("POST", "/do_subscribe.php", true);
    oReq.onload = function(oEvent) {
      if (oReq.status == 200) {
//console.log("success")
        state = document.getElementById('sub_button').value;
        if (state == "Subscribe!") {
          document.getElementById('sub_button').value = "Unsubscribe!";
          document.getElementById('sub_button').className = "cancel_signup";
          popAlert("Subscribed!");
        } else {
          document.getElementById('sub_button').value = "Subscribe!";
          document.getElementById('sub_button').className = "submit_signup";
          popAlert("Unsubscribed!");
        }

      } else {
//console.log("failure")
        popAlert("Error " + oReq.status);
      } 
    };
  oReq.send(oData);
  }

function set_recipient(recipient, parent_id) {
//console.log(recipient)
  klattr_recipient = recipient;
  klattr_parent_id = parent_id;
//console.log(klattr_recipient)
}

function set_oldest(klattr_id) {
  if (klattr_id == "no_more") {
    loading_content = 1;
  } else {
    oldest_klattr = klattr_id;
//    console.log(oldest_klattr)
  }
}

function set_profile_id(id) {
  profile_id = id;
//  console.log(profile_id)
}

function retrieve_more(page) {

  $container = $('#klattr_parent');
  
  if (loading_content == 0) {
    var
      oData = new FormData();
    var retrieved_content = "<div id=\"feed_wait\"><center><img src=\"gfx/wait.gif\"></center></div>"
//    document.getElementById('klattr_parent').innerHTML += retrieved_content;
    $container.append(retrieved_content);
    loading_content = 1;
    oData.append("oldest", oldest_klattr);
    oData.append("page", page);
    oData.append("profile_id", profile_id);
    oData.append("search", search_term);
//console.log(search_term)

    var oReq = new XMLHttpRequest();
    oReq.open("POST", "/get_more.php", true);
    oReq.onload = function(oEvent) {
      if (oReq.status == 200) {
        var element = document.getElementById("feed_wait");
        element.parentNode.removeChild(element);
        retrieved_content = oReq.responseText;
//        document.getElementById('klattr_parent').innerHTML = document.getElementById('klattr_parent').innerHTML + retrieved_content;
        $container.append(retrieved_content);
        loading_content = 0;
      } else {
        popAlert("Error" + oReq.status);
//console.log("failed to retrieve more")
      }
    };
  oReq.send(oData);
  }
}

function get_replies(parent_id, nest_level) {
  var container_id = "Parent" + parent_id + "_" + nest_level;
  var up_down = "up_down" + parent_id + "_" + nest_level;
  var devider_id = "devider" + parent_id + "_" + nest_level;

  if (document.getElementById(up_down).src == "https://klattr.com/gfx/down.png") {
    document.getElementById(up_down).src = "https://klattr.com/gfx/up.png";
        
    nest_level += 1;

    var container = $('#' + container_id);
    var oData = new FormData();
    var retrieved_content = "<div id=\"replies_wait\"><center><img src=\"gfx/wait.gif\"></center></div>";
    document.getElementById(container_id).className = "inLineReplies";
    document.getElementById(devider_id).style.visibility = "hidden";
    container.append(retrieved_content);
    oData.append("parent_id", parent_id);
    oData.append("nest_level", nest_level);

    var oReq = new XMLHttpRequest();
    oReq.open("POST", "/get_replies.php", true);
    oReq.onload = function(oEvent) {
      if (oReq.status == 200) {
        var element = document.getElementById("replies_wait");
        element.parentNode.removeChild(element);
        retrieved_content = oReq.responseText;
        container.append(retrieved_content);
      } else {
        popAlert("Error" + oReq.status);
      }
    };
    oReq.send(oData);
  } else {
     
    document.getElementById(up_down).src = "https://klattr.com/gfx/down.png";
    document.getElementById(container_id).innerHTML = "";
    document.getElementById(container_id).className = "";
    document.getElementById(devider_id).style.visibility = "visible";

  }
}

function send_email() {
  var oData = new FormData();
  var oReq = new XMLHttpRequest();
  oReq.open("POST", "/send_email.php", true);
  oReq.onload = function(oEvent) {
    if (oReq.status == 200) {
      popAlert("eMail Sent");
    } else {
      popAlert("Error" + oReq.status);
    }
  };
  oReq.send(oData);
}

function reset_password() {
  var oData = new FormData(document.forms.namedItem("SignUp"));
  var oReq = new XMLHttpRequest();
  oReq.open("POST", "/reset_password.php", true);
  oReq.onload = function(oEvent) {
    if (oReq.status == 200) {
      retrieved_content = oReq.responseText;
      popAlert(retrieved_content);
    } else {
      popAlert("Error" + oReq.status);
    }
  };
  oReq.send(oData);
}







// variables
var leftchannel = [];
var rightchannel = [];
var recorder = null;
var recording = false;
var recordingLength = 0;
var volume = null;
var audioInput = null;
var sampleRate = 44100;
var audioContext = null;
var context = null;
var outputElement = document.getElementById('output');
var outputString;
var timer;
var play_timer;
var play_length;
var progwidth;
var recorder;
var Storage = {
  AudioContext: audioContext = window.AudioContext || window.webkitAudioContext
}

function get_mic(){
// feature detection 
  if (!navigator.getUserMedia)
      navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
                    navigator.mozGetUserMedia || navigator.msGetUserMedia;

  if (navigator.getUserMedia){
      navigator.getUserMedia({audio:true}, success, function(e) {
      alert('Error capturing audio.');
      });
  } else alert('getUserMedia not supported in this browser.');
}

function record(reclength){
  recording = true;
  leftchannel.length = rightchannel.length = 0;
  recordingLength = 0;
//  console.log(reclength)
//  console.log(recording)
  document.getElementById("instructions").style.visibility = 'hidden';
  recorder = setTimeout(function(){
    stop_recording();
    clearInterval(timer);
    document.getElementById("progress").style.backgroundImage = "url('/gfx/Still-progress.gif')";
    make_submit_form();
  }, reclength); 
  progwidth = 0;
  recint = reclength/470;
//  console.log(recint)
  timer = setInterval(function(){
    document.getElementById("progress").style.width = '' + progwidth + 'px';
    progwidth += 1;  
  }, recint)
}

function toggle_recording(){
  if (recording){
    document.getElementById("do_record").className = "stop_button";
    document.getElementById("do_record").style.top = "1px";
    document.getElementById("do_record").setAttribute( "onClick", "javascript: reset_recording();toggle_recording()" )
  } else if (!recording){
    document.getElementById("do_record").className = "rec_button";
    document.getElementById("do_record").setAttribute( "onClick", "javascript: record(19500);toggle_recording()" )
  }
 
}

function stop_recording(){
  recording = false;
//  console.log("stop recording")
}

function reset_recording(){
  if(document.getElementById("progress")){
    document.getElementById("progress").style.width = '0px';
    document.getElementById("progress").style.backgroundImage = "url('/gfx/progress.gif')";
  }
  clearInterval(timer);
  stop_recording();
  clearTimeout(recorder);
  recordingLength = 0;
  leftchannel = [];
  rightchannel = [];
  recorder = null;
  volume = null;
  audioInput = null;
  sampleRate = 44100;
  audioContext = null;
  context = null;
  outputElement = document.getElementById('output');
    navigator.getUserMedia({audio:true}, success, function(e) {
    alert('Error capturing audio.');
    });

}

function save_recording(){
  var interleaved = mergeBuffers ( leftchannel, recordingLength );
//  var rightBuffer = mergeBuffers ( rightchannel, recordingLength );
//  var interleaved = interleave ( leftBuffer, rightBuffer );

  var buffer = new ArrayBuffer(44 + interleaved.length * 2);
  var view = new DataView(buffer);

  writeUTFBytes(view, 0, 'RIFF');
  view.setUint32(4, 36 + interleaved.length * 2, true);
  writeUTFBytes(view, 8, 'WAVE');
  writeUTFBytes(view, 12, 'fmt ');
  view.setUint32(16, 16, true);
  view.setUint16(20, 1, true);
  view.setUint16(22, 1, true);
  view.setUint32(24, sampleRate, true);
  view.setUint32(28, sampleRate * 2, true);
  view.setUint16(32, 2, true);
  view.setUint16(34, 16, true);
  writeUTFBytes(view, 36, 'data');
  view.setUint32(40, interleaved.length * 2, true);

// write PCM samples

  var lng = interleaved.length;
  var index = 44;
  var volume = 1;
  for (var i = 0; i < lng; i++){
    view.setInt16(index, interleaved[i] * (0x7FFF * volume), true);
    index += 2;
  }
  var blob = new Blob ( [ view ], { type : 'audio/wav' } );
  //blob = "blobby blobby blobby"
  send_klattr_form(blob);
  //download_file(blob)
}

function download_file(blob){
  var url = (window.URL || window.webkitURL).createObjectURL(blob);
  var link = window.document.createElement('a');
  link.href = url;
  link.download = 'output.wav';
  var click = document.createEvent("Event");
  click.initEvent("click", true, true);
  link.dispatchEvent(click);
}


function interleave(leftChannel, rightChannel){
  var length = leftChannel.length + rightChannel.length;
  var result = new Float32Array(length);

  var inputIndex = 0;

  for (var index = 0; index < length; ){
    result[index++] = leftChannel[inputIndex];
    result[index++] = rightChannel[inputIndex];
    inputIndex++;
  }
  return result;
}

function mergeBuffers(channelBuffer, recordingLength){
  var result = new Float32Array(recordingLength);
  var offset = 0;
  var lng = channelBuffer.length;
  for (var i = 0; i < lng; i++){
    var buffer = channelBuffer[i];
    result.set(buffer, offset);
    offset += buffer.length;
  }
  return result;
}

function writeUTFBytes(view, offset, string){ 
  var lng = string.length;
  for (var i = 0; i < lng; i++){
    view.setUint8(offset + i, string.charCodeAt(i));
  }
}

function success(e){
    // creates the audio context
    var audioContext = Storage.AudioContext;
    
    if (!Storage.AudioContextConstructor)
      Storage.AudioContextConstructor = new audioContext();

    context = Storage.AudioContextConstructor;

    // creates a gain node
    if (!Storage.VolumeGainNode)
      Storage.VolumeGainNode = context.createGain();

    volume = Storage.VolumeGainNode;

    // creates an audio node from the microphone incoming stream
    if (!Storage.AudioInput)
      Storage.AudioInput = context.createMediaStreamSource(e);

    audioInput = Storage.AudioInput;

    // connect the stream to the gain node
    audioInput.connect(volume);

    /* From the spec: This value controls how frequently the audioprocess event is 
    dispatched and how many sample-frames need to be processed each call. 
    Lower values for buffer size will result in a lower (better) latency. 
    Higher values will be necessary to avoid audio breakup and glitches */
    var bufferSize = 4096;
    //recorder = context.createJavaScriptNode(bufferSize, 2, 2);
    recorder = context.createScriptProcessor(bufferSize, 1, 1);
    
    recorder.onaudioprocess = function(e){
        if (!recording) return;
        var left = e.inputBuffer.getChannelData (0);
//        var right = e.inputBuffer.getChannelData (1);
        // we clone the samples
        leftchannel.push (new Float32Array (left));
//        rightchannel.push (new Float32Array (right));
        recordingLength += bufferSize;
    }

    // we connect the recorder
    volume.connect (recorder);
    recorder.connect (context.destination); 
}

function play_klattr(klattr) {
  stop_all_klattrs();

  var song = document.getElementById(klattr);
  var progress_element = "progress_" + klattr;
  var button_element = "button_" + klattr;
  
  document.getElementById(button_element).className = "stop_button";
//  document.getElementById(button_element).style.left = '30px';
//  document.getElementById(button_element).style.float = 'right';
//  document.getElementById(button_element).style.top = '1px';
  document.getElementById(button_element).setAttribute( "onClick", "javascript: stop_playing('" + klattr + "')" );

  song.play();
  play_length = setTimeout(function(){
    clearInterval(play_timer);
    document.getElementById(progress_element).style.backgroundImage = "url('/gfx/Still-progress.gif')";
    stop_playing(klattr);
  }, 19500);
  var progresswidth = 0;
  var playint = 19500/300;
  play_timer = setInterval(function(){
    document.getElementById(progress_element).style.width = '' + progresswidth + 'px';
    progresswidth += 1;
  }, playint)
}

function stop_playing(klattr) {
  var progress_element = "progress_" + klattr;
  var button_element = "button_" + klattr;

  document.getElementById(button_element).className = "play_button";
  document.getElementById(button_element).setAttribute( "onClick", "javascript: play_klattr('" + klattr + "')" );


  kaudio = document.getElementById(klattr);
  kaudio.pause();
  kaudio.currentTime = 0;
  kaudio.load();
  document.getElementById(progress_element).style.width = "0px";
  clearInterval(play_timer);
  clearTimeout(play_length);

}

function stop_all_klattrs() {
  var button_element;
  var audios = document.getElementsByTagName('audio'),
        i = audios.length;
  while(i--) {
    button_element = "button_" + audios[i].id;
    document.getElementById(button_element).className = "play_button";
    document.getElementById(button_element).setAttribute( "onClick", "javascript: play_klattr('" + audios[i].id + "')" );

    audios[i].pause();
    //audios[i].src = audios[i].src;
    audios[i].currentTime = 0;
    if (audios[i].currentTime != 0)
      audios[i].load();
//console.log(audios[i].currentTime)
  }


  var players = document.getElementsByClassName('play_progress'),
        i = players.length;
  while(i--) {
    players[i].style.width = "0px";
    clearInterval(play_timer);
    clearTimeout(play_length);
  }
}
<?php 
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
  
  $sound_name = $_GET["sound"];
  $sound_type = substr($sound_name, -3);
  $sound_name = substr($sound_name, 1, -4);
  $sound_path = "/data/klattr.com/www/povs/" . $sound_name . "." . $sound_type;
  $sound = file_get_contents($sound_path);
  $sound_content = "Content-type: audio/" . $sound_type;
  //echo $sound_type;
  //echo $sound_name;
  header($sound_content);
  header('Accept-Ranges: bytes');
  echo $sound;
} else {
  header( 'Location: https://klattr.com' );
}
?>
<?php
include "/data/klattr.com/www/includes/auth";

if ($auth == 1) {

  $parent = 0;
  $private = 0;
  $ttl = 0;

  $klattr_path = $_FILES['klattr_audio']['tmp_name'];

  $title = $_POST['klattr_title'];
  $recipients = $_POST['klattr_recipients'];
  $tags = $_POST['klattr_tags'];
  if (isset($_POST['parent_id'])) {
    $parent = $_POST['parent_id'];
  }

  $title = substr($title, 0, 20);
  $title = htmlspecialchars($title);
  $title = addslashes($title);

  $recipients = htmlspecialchars($recipients);
  $recipients = str_replace(";", " ", $recipients);
  $recipients = str_replace(",", " ", $recipients);
  $recipients = str_replace("  ", " ", $recipients);
  $recipient_regex = str_replace(" ", "|", $recipients);
  $recipients = " " . $recipients . " ";
  $recipients = addslashes($recipients);

  $recipient_array = explode(" ", $recipients);


  $tags = htmlspecialchars($tags);
  $tags = str_replace(";", " ", $tags);
  $tags = str_replace(",", " ", $tags);
  $tags = $tags . " ";
  $tags = addslashes($tags);

  $randomData = file_get_contents('/dev/urandom', false, null, 0, 64) . uniqid(mt_rand(), true);
  $randkey = substr(str_replace(array('/','=','+'),'', base64_encode($randomData)),0,64);
  $dateString = date("Ymdhis");
  $postDate = date("Y-m-d H:i:s");
  $nameString = str_replace(' ','',$uname);
  $uniqueName = $nameString . $randkey . $dateString;
  $wav2png = "/etc/wav2png/wav2png";
  $oggenc = "/usr/bin/oggenc";
  $lame = "/usr/bin/lame";
  $imagePath = "/tmp/" . $uniqueName . ".png";

  $wav2pngResult = `$wav2png --foreground-color=FFFFFFFF --background-color=686A88FF -w 700 -h 100 -d -o $imagePath $klattr_path  2>&1`;
  $oggencResults = `$oggenc -o /data/klattr.com/www/povs/$uniqueName.ogg $klattr_path`;
  $lameResults = `$lame $klattr_path /data/klattr.com/www/povs/$uniqueName.mp3`;

  $waveform = new Imagick($imagePath);
  $waveform->setImageFormat('png');
  $waveform = addslashes($waveform);

  //$sql = "INSERT INTO Povs (Title, Tags, Data, Poster, Recipient, Parent_ID, Time_Posted, TTL, Waveform) VALUES ('$title', '$tags', '$uniqueName', '$UID', '$recipients', '$parent', '$postDate', '$ttl', '$waveform')";  

  $sql = "INSERT INTO Povs (Title, Tags, Data, Poster, Recipient, Private, Parent_ID, Time_Posted, TTL, Waveform) VALUES ('$title', '$tags', '$uniqueName', '$UID', '$recipients', '$private', '$parent', '$postDate', '$ttl', '$waveform')";

  mysqli_query($con,$sql);
  $error = mysqli_error();
  file_put_contents('/tmp/error', $error);
  unlink($imagePath);

  if (isset($parent)) {
    $sql = "UPDATE Povs Set Num_Replies = Num_Replies + 1 WHERE ID='$parent' ";
    mysqli_query($con,$sql);
  }

	//
	// Add this item to the Feed column for recipients and subscribers
	$sql = "UPDATE Users SET Feed=CONCAT('$uniqueName ',Feed) WHERE Subscribed_To LIKE '%$uname%'";
	mysqli_query($con,$sql);

    // send emails top the klattr recipients
    $sql = "SELECT Name, Email_Addr FROM Users WHERE Handle REGEXP '$recipient_regex' AND Activated = '1'";
    $sql_result = mysqli_query($con,$sql);
    while ($row = mysqli_fetch_array($sql_result)){
      if ($row['Name'] != "") {
        $emailText = file_get_contents("/data/klattr.com/www/includes/new_klattr_email_template");
        $emailText = str_replace("FULLNAME", $row['Name'], $emailText);
        $emailText = str_replace("SENDER", $uname, $emailText);
        $headers = "From: Klattr Team <administrator@klattr.com>\r\nReply-To: No Reply\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        mail($row['Email_Addr'], "You've Received a Klattr!", $emailText, $headers);
      }
    }

} else {
  header( 'Location: https://klattr.com' );
}
?>
<?php
include "/data/klattr.com/www/includes/auth";
include "/data/klattr.com/www/includes/evaluate_signup";
if ($auth == 1) {
  if (isset($_POST['password']) && isset($_POST['password2'])) {
    if (evaluate_pass($_POST['password']) == 0) {
      if ($_POST['password'] == $_POST['password2']) {
        $password = $_POST["password"];
        $enc_password = urlencode($password);
        $password_hash = crypt($enc_password);

        $sql = "UPDATE Users SET Password_hash='$password_hash' WHERE ID='$UID'";
        mysqli_query($con,$sql);

        $randomData = file_get_contents('/dev/urandom', false, null, 0, 128) . uniqid(mt_rand(), true);
        $randkey = substr(str_replace(array('/','=','+'),'', base64_encode($randomData)),0,128);
        $ip = $_SERVER['REMOTE_ADDR'];
        $session_date = date("Y-m-d h:i:s");
        $sql = "INSERT INTO Session (SessionKey, UserID, IP, Date) VALUES ('$randkey','$UID','$ip','$session_date')";
        mysqli_query($con,$sql);
        echo "Password Reset";
      } else {
        echo "Your Passwords don't match!";
      }
    } else {
      echo "Your password isn't long enough!";
    }
  }
} elseif ($auth == 0) {
//echo $_POST['key'];
  if (isset($_POST['key']) && isset($_POST['password']) && isset($_POST['password2'])){
    if ($_POST['password'] == $_POST['password2']) {
      $password = $_POST["password"];
      $key = addslashes($_POST['key']);
      $key = str_replace(";", "", $key);
//echo $key;
      include "/data/klattr.com/www/includes/open_db";
      $enc_password = urlencode($password);
      $password_hash = crypt($enc_password);

      $sql = "SELECT ID FROM Users WHERE Activation_Key='$key'";
      $sql_result = mysqli_query($con,$sql);
      $row = mysqli_fetch_array($sql_result);
//echo $row['ID'];
      if (isset($row['ID'])) {
        $UID = $row['ID'];
//echo $UID;
        $sql = "UPDATE Users SET Password_hash='$password_hash' WHERE ID='$UID'";
        mysqli_query($con,$sql);

        $randomData = file_get_contents('/dev/urandom', false, null, 0, 128) . uniqid(mt_rand(), true);
        $randkey = substr(str_replace(array('/','=','+'),'', base64_encode($randomData)),0,128);
        $ip = $_SERVER['REMOTE_ADDR'];
        $session_date = date("Y-m-d h:i:s");
        $sql = "INSERT INTO Session (SessionKey, UserID, IP, Date) VALUES ('$randkey','$UID','$ip','$session_date')";
        mysqli_query($con,$sql);
        setcookie ("session_auth", $randkey, $expire_time, "/", ".klattr.com");
        header( 'Location: https://klattr.com' );

      } else {
        header( 'Location: https://klattr.com' );
      }
    } else {
      header( 'Location: https://klattr.com' );
    }
  } else {
    header( 'Location: https://klattr.com' );
  }
}
?>
<?php
include "/data/klattr.com/www/includes/auth";

$searchTerm = $_GET['search'];
if ($_GET['type'] == "people") {
  $page = "peopleSearch";
  $ps = 1; 
}
$searchTerm = substr($searchTerm, 0, 30);
$searchQuery = urlencode($searchTerm);
$searchTerm = str_replace(array('/','=',',',';','\\','+',' '),'|', $searchTerm);

if ($auth == 1) {
  ?>
<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body>
    <script>var search_term = "<?php echo $searchTerm?>"; </script>
    <?php include "/data/klattr.com/www/includes/header"; ?>
    <?php include "/data/klattr.com/www/includes/search"; ?>

<?php
} elseif ($auth == 2) {
  header( 'Location: https://klattr.com' );
} elseif ($auth == 0) {
  header( 'Location: https://klattr.com' );
}

?>

    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>
<?php
if ($first_mail !== 1) {
  $activatePage = 1;
  include "/data/klattr.com/www/includes/auth";
}

if ($auth == 1 || $first_mail == 1 ) {
  $emailText = file_get_contents("/data/klattr.com/www/includes/email_template");
  $emailText = str_replace("FULLNAME", $rname, $emailText);
  $randomData = file_get_contents('/dev/urandom', false, null, 0, 64) . uniqid(mt_rand(), true);
  $randkey = substr(str_replace(array('/','=','+'),'', base64_encode($randomData)),0,64);
  $emailText = str_replace("UNIQUEKEY", $randkey, $emailText);
  $headers = "From: Klattr Team <administrator@klattr.com>\r\nReply-To: No Reply\r\n";
  $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  $sql = "UPDATE Users SET Activation_Key='$randkey' WHERE ID='$UID'";
  mysqli_query($con,$sql);
  mail($uEmailAddr, "Welcome to Klattr", $emailText, $headers);
//  shell_exec("echo $emailText | mail -s \"Welcome to Klattr\" -r administrator@klattr.com $uEmailAddr");
  
} else {
  header( 'Location: https://klattr.com' );
}
?>
<?php 
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
  $jpeg_name = $_GET["jpeg"];
  $jpeg_name = substr($jpeg_name, 1, -5);
  $sql = "SELECT Avatar FROM Users WHERE Handle='$jpeg_name' AND BINARY(Handle) = BINARY('$jpeg_name')";
  $sql_result = mysqli_query($con,$sql);
  $row = mysqli_fetch_array($sql_result);
  if ($row['Avatar'] != "") {
    header('Content-type: image/jpeg');
    echo $row['Avatar'];
  } else {
    $img = file_get_contents('/data/klattr.com/www/ht_docs/gfx/default_user.png');
    header('Content-type: image/png');
    echo $img;
  }
} else {
  header( 'Location: https://klattr.com' );
}
?>
<?php
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
  $profileID = $_GET['user'];
  if ($profileID == "") {
    header( 'Location: https://klattr.com' );
  }
  $page = "subscribed_to";
  $ps = 1;
  ?>
<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/header"; ?>
  <div class="body_center">
    <div class="feed">
      <?php include "/data/klattr.com/www/includes/user_panel"; ?>
<div class="feed_inner"  id="klattr_parent" style="margin-bottom:10px;">
<h5><?php echo $profileID; ?> is subscribed to:</h5>
<?php
  include "/data/klattr.com/www/includes/klattr_retrieve_queries";
  include "/data/klattr.com/www/includes/render_people";

  if ($pcount == 0) {
?>

<div class="klattr_div">
  <center>Sorry. No results found.</center>
</div>

<?php
  } else {
    if ($ps == 1) {
      include "/data/klattr.com/www/includes/do_scroll"; 
    } else {

    }
?>
    </div>
  </div>
</div>
<?php
  }


} else {
    header( 'Location: https://klattr.com' );
}
?>

    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>
<?php
include "/data/klattr.com/www/includes/auth";
$profileUname = $_GET["uname"];
$profileUname = substr($profileUname, 1);
if ($auth == 1) {
$page = "user";
?>

<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/header"; ?>
    <?php include "/data/klattr.com/www/includes/user_page" ?>
<?php
} elseif ($auth == 2) {
  header( 'Location: https://klattr.com' );
} elseif ($auth == 0) {
  header( 'Location: https://klattr.com' );
}


?>




    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>

<?php 
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
  $png_name = $_GET["id"];
  //$png_name = substr($png_name, 1);
  $sql = "SELECT Waveform FROM Povs WHERE ID='$png_name'";
  $sql_result = mysqli_query($con,$sql);
  $row = mysqli_fetch_array($sql_result);
  header('Content-type: image/png');
  echo $row['Waveform'];
} else {
  header( 'Location: https://klattr.com' );
}
?>
<?php 
if (isset($_COOKIE['session_auth'])) {
  include "/data/klattr.com/www/includes/open_db";
  include "/data/klattr.com/www/includes/evaluate_cookie";
  $ip = $_SERVER['HTTP_X_REAL_IP'];
  if ($ip == "") {
    $ip = $_SERVER['REMOTE_ADDR'];
  }
  $cookie_key = $_COOKIE['session_auth'];
/* Sanitize $cookie_key */
  $cookie_key = htmlspecialchars($cookie_key);
  $cookie_key = addslashes($cookie_key);

  $UID = evaluate_cookie($cookie_key, $ip);
  if ($UID !== 0) {
    /*  $UID is now an SQL injection attack
        if UID is just Numeric - then so if(!ctype_digit($UID)) { return false; }
    */
    $sql = "SELECT Handle, Name, Profile_Text, Avatar, Email_Addr, Activated FROM Users WHERE ID='$UID'";
    $sql_result = mysqli_query($con,$sql);
    $row = mysqli_fetch_array($sql_result);
    $uname = $row['Handle'];
    $rname = $row['Name'];
    $uEmailAddr = $row['Email_Addr'];
    $profile = $row['Profile_Text'];
    if (empty($row['Avatar'])) {
      $userPic = "/gfx/default_user.png";
    } else {
      $userPic = $uname . ".jpeg";
    }
    if ($row['Activated'] == 1 || $activatePage == 1) {
      $auth = 1;
    } else {
      header( 'Location: https://klattr.com/activate.php' );
    }
    


  } else {
    $auth = 0;
  }
} else {
  $auth = 0;
}
<?php
if ($count > 0 || $pcount > 0) {
?>

        <script>
            $(document).ready(function() {
                $(window).scroll(function() {
                    if ($('body').height() <= ($(window).height() + $(window).scrollTop())) {
                        retrieve_more('<?php echo $page; ?>');
                    }
                });
            });    
        </script>

<?php
}
?>
<html>
<body>

<div style="width:600px;margin-right:auto;margin-left:auto;border-style:solid;border-width:1px;">
<h1 style="color:#ffffff;background-color:#686A88;padding:5px;margin:0px">Welcome to Klattr.</h1><div style="background-image:url('https://klattr.com/gfx/welcome_bg.png');background-repeat:no-repeat;padding:5px">
Dear FULLNAME.<br><br>
Thank you for signing up with Klattr. Please follow <a href="https://klattr.com/activate.php?key=UNIQUEKEY">this link</a> to activate your account or copy and paste the below into your browser address bar.<br>
https://klattr.com/activate.php?key=UNIQUEKEY<br><br>
The Klattr Team.
</div></div>

</body>
</html>
<?php
function evaluate_cookie ($e_key, $e_ip) {
  global $con;
  
  /*
    what is $e_key ? - should check it - SQL injection.  
    -It is the key from the cookie, it is sanitized before this function call.
  */
  
  $sql = "SELECT SessionKey, UserID, IP FROM Session WHERE SessionKey='$e_key'";
  $sql_result = mysqli_query($con,$sql);
  $row = mysqli_fetch_array($sql_result);
  if ($row['IP'] == $e_ip) {
    $result = $row['UserID'];
  } else {
    $result = 0;
  } 
  return $result;
}
?>
<?php

function evaluate_password ($e_uname, $e_password) {
  global $con;

/*sanitize variables before sql injection*/

  $e_uname = htmlspecialchars($e_uname);
  $e_uname = addslashes($e_uname);
  $e_password = htmlspecialchars($e_password);
  $e_password = addslashes($e_password);

  $sql = "SELECT Handle, Email_Addr, Password_Hash FROM Users WHERE Handle='$e_uname' || Email_Addr='$e_uname'";
  $sql_result = mysqli_query($con,$sql);
  $row = mysqli_fetch_array($sql_result);
//echo $row['Handle'];
  $enc_password = urlencode($e_password);
  $password_hash = crypt($enc_password);

    $result = $row['Handle'];

  if ($e_password !== null && $e_password !== "") {
    if ($row['Password_Hash'] == crypt($enc_password, $row['Password_Hash'])) {
      //$result = 0;
    } else {
      $result = 1;
    }  
  } else {
    $result = 1;
  }
  return $result;
}
?>
<?php

function evaluate_name ($e_name) {
  if (preg_match("/^[a-zA-Z]+[a-zA-Z ]+$/",$e_name)) {
    $result = 0;
  } else {
    $result = 1;
  }

  return $result;
}


function evaluate_email ($e_email) {
  global $con;
  $email_regx = "/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/";
  if (preg_match($email_regx,$e_email)) {
    $sql = "SELECT Email_Addr FROM Users WHERE Email_Addr='$e_email'";
    $sql_result = mysqli_query($con,$sql);
    $row = mysqli_fetch_array($sql_result);
    if (strcmp($e_email,$row['Email_Addr'])==0) {
      $result = 20;
    } else {
      $result = 0;
    }
  } else {
    $result = 1;
  }

  return $result;
}

function evaluate_pass ($e_pass) {
  if (strlen($e_pass) > 6) {
    $result = 0;
  } else {
    $result = 1;
  }

  return $result;
}

function evaluate_uname ($e_uname) {

// sanitize before injection
  $e_uname = htmlspecialchars($e_uname);
  $e_uname = addslashes($e_uname);

  global $con;
  if (preg_match("/^[a-zA-Z0-9_]+$/",$e_uname)) {
    $sql = "SELECT Handle FROM Users WHERE Handle='$e_uname'";
    $sql_result = mysqli_query($con,$sql);
    $row = mysqli_fetch_array($sql_result);
    if (strcmp($e_uname,$row['Handle'])==0) {
      $result = 2;
   } else {
      $result = 0;
   }
  } else {
    $result = 1;
  }

  return $result;
}

?>
<div id="footer">
<div class="copyright">&copy; 2014 Klattr</div>
</div>
<div class="dialog_wrapper" id="popAlert">
  <div class="dialog" id="popAlert_message">
  </div>
</div>

<img src="/gfx/stop_dark.png" class="preload">
<img src="/gfx/stop_light.png" class="preload">
<img src="/gfx/play_dark.png" class="preload">
<img src="/gfx/play_light.png" class="preload">
<img src="/gfx/rec_light.png" class="preload">
<img src="/gfx/signup_button_dark.png" class="preload">
<img src="/gfx/cancel_button_dark.png" class="preload">
<img src="/gfx/login_button_dark.png" class="preload">
<img src="/gfx/Still-progress.gif" class="preload">
<div id="body">
  <div class="body_center">
    <div class="feed">
      <?php include "/data/klattr.com/www/includes/user_panel"; ?>
      <div class="feed_inner" id="klattr_parent">
<?php include "/data/klattr.com/www/includes/klattr_retrieve_queries"; ?>
<?php include "/data/klattr.com/www/includes/render_klattrs"; ?>
<?php include "/data/klattr.com/www/includes/do_scroll"; ?>
      </div>
    </div>
  </div>
</div>
<?php
function fuzzyAgo($date){
    $time = strtotime($date);
    $now = time();
    $ago = $now - $time;
    if($ago < 60){
        $when = round($ago);
        $s = ($when == 1)?"second":"seconds";
        return "$when $s ago";
    }elseif($ago < 3600){
        $when = round($ago / 60);
        $m = ($when == 1)?"minute":"minutes";
        return "$when $m ago";
    }elseif($ago >= 3600 && $ago < 86400){
        $when = round($ago / 60 / 60);
        $h = ($when == 1)?"hour":"hours";
        return "$when $h ago";
    }elseif($ago >= 86400 && $ago < 2629743.83){
        $when = round($ago / 60 / 60 / 24);
        $d = ($when == 1)?"day":"days";
        return "$when $d ago";
    }elseif($ago >= 2629743.83 && $ago < 31556926){
        $when = round($ago / 60 / 60 / 24 / 30.4375);
        $m = ($when == 1)?"month":"months";
        return "$when $m ago";
    }else{
        $when = round($ago / 60 / 60 / 24 / 365);
        $y = ($when == 1)?"year":"years";
        return "$when $y ago";
    }
}
?>
<html>
    <head>
      <title>Klattr.com - Just say it!</title>
      <link rel="stylesheet" type="text/css" href="/css/main.css" media="screen" />
      <script type='text/javascript' src="//code.jquery.com/jquery-1.9.1.js"></script>
      <script src="/js/forms.js"></script>
      <link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png" />
      <link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png" />
      <link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png" />
      <link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png" />
      <link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png" />
      <link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png" />
      <link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png" />
      <link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png" />
      <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16" />
      <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32" />
      <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96" />
      <link rel="icon" type="image/png" href="/favicon-160x160.png" sizes="160x160" />
      <link rel="icon" type="image/png" href="/favicon-196x196.png" sizes="196x196" />
      <meta name="msapplication-TileColor" content="#b91d47" />
      <meta name="msapplication-TileImage" content="/mstile-144x144.png" />

      <meta charset="utf-8" />
      <meta name="viewport" content="width=device-width" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />


	<script src="/js/sound.js"></script>
      
    </head>
<img src="/gfx/klattr_big.png" class="preload">
<div id="header">
  <div class="header_center">
    <a href="https://klattr.com"><img src="/gfx/klattr_text_small.png" id="header_logo"></a>
<?php
if ($auth == 1 && $activatePage != 1) {
?>
    <div onclick="location.href='https://klattr.com'" class="header_button<?php if ($page == "Feed") {echo "_selected";}  ?>">&#9777; Feed</div>
    <div onclick="location.href='https://klattr.com/in.php'" class="header_button<?php if ($page == "Forme") {echo "_selected";}  ?>">&#62; In</div>
<!--    <div onclick="location.href='https://klattr.com/out'" class="header_button<?php if ($page == "Byme") {echo "_selected";}  ?>">&#60; Out</div> -->

    <a href="https://klattr.com/<?php echo $uname; ?>"><img id="user_pic_small" src="<?php echo $userPic; ?>"></a>


    <div onclick="location.href='https://klattr.com/do_logout.php'" class="header_logout">Logout <?php echo $uname; ?></div>

    <form name="SearchForm" action="/search.php" method="GET">
      <input type="submit" class="search_submit" value="Go"><input type="text" class="search_input" name="search" placeholder="Search!">
    </form>
<?php  


}
?>
  </div>
</div>
<?php
$uname_plus_space = " " .$uname . " ";
$oldest_text = "";
if (isset($oldest)) {
  if ($page == "peopleSearch" || $page == "subscribed_to") {
    $oldest_text = "AND ID < '" . $oldest ."' ";
    $search_limit = 10;
  } else {
    $oldest_text = "AND Povs.ID < '" . $oldest ."' ";
  }
}

if ($page == "subscribed_to") {
  $sql = "SELECT ID, Subscribed_To FROM Users WHERE Handle='$profileID'";
  $sql_result = mysqli_query($con,$sql);
  $row = mysqli_fetch_array($sql_result);
  $panelUID = $row['ID'];
  $sub_list = preg_replace('/\s\s+/', '|', $row['Subscribed_To']);
  $sub_regexp = str_replace(" ", "|", $sub_list);
  $sub_regexp = substr($sub_regexp, 1 , -1);
  $sql = "SELECT ID, Handle, Name, Profile_Text FROM Users WHERE Handle REGEXP '" . $sub_regexp . "' " . $oldest_text . "AND Activated = '1' ORDER BY ID DESC LIMIT 0, 10";

//echo $sql;

}

if ($page == "replies") {
  $sql = "SELECT Povs.Recipient, Povs.Num_Replies, Povs.ID, Povs.Title, Povs.Tags, Povs.Data, Povs.Private, Povs.Time_Posted, Povs.Waveform, Users.Handle FROM Users INNER JOIN Povs ON Povs.Poster=Users.ID WHERE Povs.Parent_ID='$parentId' AND Povs.Private='0' AND Users.Activated = '1' ORDER BY ID DESC LIMIT 0, 10";
}

//echo $page;
if ($page == "peopleSearch") {
  $sql = "SELECT ID, Handle, Name, Profile_Text FROM Users WHERE (Handle REGEXP '$searchTerm' OR Name REGEXP '$searchTerm')" . $oldest_text . " AND Activated = '1' ORDER BY ID DESC LIMIT 0, " . $search_limit;

//echo $sql;
//echo "Got here";

}


if ($page == "user") {
  $sql = "SELECT Povs.Recipient, Povs.Num_Replies, Povs.ID, Povs.Title, Povs.Tags, Povs.Data, Povs.Private, Povs.Time_Posted, Povs.Waveform, Users.Handle FROM Users INNER JOIN Povs ON Povs.Poster=Users.ID WHERE Povs.Poster='$profileID' AND Povs.Private='0' " . $oldest_text . " AND Users.Activated = '1' ORDER BY ID DESC LIMIT 0, 10";
}

if ($page == "Feed") {
  $sql = "SELECT Subscribed_To FROM Users WHERE ID='$UID'";
  $sql_results = mysqli_query($con,$sql);
  $row = mysqli_fetch_array($sql_results);
  $sub_list = $row['Subscribed_To'];
//echo "subed: " . $sub_list . $UID;
  $sub_regexp = str_replace(" ", "|", $sub_list);
  $sub_regexp = substr($sub_regexp, 1 , -1);
//echo "regexp: " . $sub_regexp;  
  if ($sub_regexp != "") {
    $sub_regexp = "Users.Handle REGEXP '" . $sub_regexp . "' OR ";
  }
  
//echo "regexp: " . $sub_regexp;
  $sql = "SELECT Povs.Recipient, Povs.Num_Replies, Povs.ID, Povs.Title, Povs.Tags, Povs.Data, Povs.Private, Povs.Time_Posted, Povs.Waveform, Users.Handle FROM Users INNER JOIN Povs ON Povs.Poster=Users.ID WHERE (" . $sub_regexp . "INSTR(Povs.Recipient, '$uname_plus_space') > 0 OR Povs.Poster='$UID') AND Povs.Private='0' " . $oldest_text . " AND Users.Activated = '1'ORDER BY ID DESC LIMIT 0, 10";

//echo "<br>" . $sql;
}

if ($page == "search") {
  $sql = "SELECT Povs.Recipient, Povs.Num_Replies, Povs.ID, Povs.Title, Povs.Tags, Povs.Data, Povs.Private, Povs.Time_Posted, Povs.Waveform, Users.Handle FROM Users INNER JOIN Povs ON Povs.Poster=Users.ID WHERE (Povs.Tags REGEXP '$searchTerm' OR Povs.Title REGEXP '$searchTerm') AND Povs.Private='0' " . $oldest_text . " AND Users.Activated = '1'ORDER BY ID DESC LIMIT 0, 10";
}

if ($page == "Forme") {
  $sql = "SELECT Povs.Recipient, Povs.Num_Replies, Povs.ID, Povs.Title, Povs.Tags, Povs.Data, Povs.Private, Povs.Time_Posted, Povs.Waveform, Users.Handle FROM Users INNER JOIN Povs ON Povs.Poster=Users.ID WHERE (INSTR(Povs.Recipient, '$uname_plus_space') > 0) AND Povs.Private='0' " . $oldest_text . " AND Users.Activated = '1'ORDER BY ID DESC LIMIT 0, 10";
}

$sql_result = mysqli_query($con,$sql);




?>
This is a beta test and as such the terms may change.<br><br>

For the duration of this test.<br><br>

What you say/record is yours both in the sense of property and in the sense that you are responsible for it.<br><br>
Klattr takes no responsibility for any anything you say or record.<br><br>

Klattr will not sell your data to any third parties.<br><br>

Klattr does use cookies.<br><br>

The Klattr Team.<br><br>
<div id="body">
  <div class="body_center">
    <div class="feed">
      <?php include "/data/klattr.com/www/includes/user_panel"; ?>
      <div class="feed_inner" id="klattr_parent">
<?php include "/data/klattr.com/www/includes/klattr_retrieve_queries"; ?>
<?php include "/data/klattr.com/www/includes/render_klattrs"; ?>
<?php include "/data/klattr.com/www/includes/do_scroll"; ?>

      </div>
    </div>
  </div>
</div>
<div id="body">
  <div class="body_center">
    <div class="welcome">
      <h1>Welcome to Klattr.</h1>
    </div>
    <div class="login">
      <h2>Login!</h2>
      <br /><br />
      <img src="/gfx/hr.png" width="350"/>
      <form name="Login" action="/do_login.php" method="post">
        <div class="form_line"><div class="form_text">Username:</div> <input type="text" class="gen_input" name="username"></div>
        <div class="form_line"><div class="form_text">Password:</div> <input type="password" class="gen_input" name="password"></div>
        <div class="form_line"><div class="form_text" style="font-size:10px; top:0px;"><a href="forgot_password.php" style="margin-right:10px;">Forgot your password?</a> Keep me signed in.</div><input type="checkbox" name="stay_signed_in" value="yes" class="checkbox_login" checked></div>
        <div class="form_line"><input type="submit" class="submit_login" value="Sign In!"></div>
      </form>
    </div>
    <div class="login">
      <h2>Don't have a Klattr Account?</h2> <h3>Sign Up!</h3>
      <br /><br />
      <img src="/gfx/hr.png" width="350" />
      <form name="SignUp" action="/do_signup.php" method="post">
        <div class="form_line"><div class="form_text">Full Name:</div> <input type="text" class="gen_input" name="name"></div>
        <div class="form_line"><div class="form_text">Email Address:</div> <input type="text" class="gen_input" name="email"></div>
        <div class="form_line"><div class="form_text">Password:</div> <input type="password" class="gen_input" name="password"></div>
        <input type="hidden" class="gen_input" name="username">
        <div class="form_line"><input type="submit" class="submit_signup" value="Sign Up!"></div>
      </form>
    </div>
  </div>
</div>
<html>
    <head>
      <title>Klattr.com - Just say it!</title>
      <link rel="stylesheet" type="text/css" href="/css/main.css" media="screen" />
      <script type='text/javascript' src="//code.jquery.com/jquery-1.9.1.js"></script>
      <script src="/js/forms.js"></script>
      <link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png" />
      <link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png" />
      <link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png" />
      <link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png" />
      <link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png" />
      <link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png" />
      <link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png" />
      <link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png" />
      <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16" />
      <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32" />
      <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96" />
      <link rel="icon" type="image/png" href="/favicon-160x160.png" sizes="160x160" />
      <link rel="icon" type="image/png" href="/favicon-196x196.png" sizes="196x196" />
      <meta name="msapplication-TileColor" content="#b91d47" />
      <meta name="msapplication-TileImage" content="/mstile-144x144.png" />

      <meta charset="utf-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/> <!--320-->


	<script src="/js/sound.js"></script>
      
    </head>
<img src="/gfx/klattr_big.png" class="preload">
<div id="header">
  <div style="width:100%;position:relative;float:right">
    <a href="https://klattr.com"><img src="/gfx/klattr_text_small.png" id="header_logo"></a>
<?php
if ($auth == 1 && $activatePage != 1) {
?>
    <a href="https://klattr.com/<?php echo $uname; ?>"><img id="user_pic_small" src="<?php echo $userPic; ?>"></a>

    <form name="SearchForm" action="/search.php" method="GET">
      <input type="submit" class="search_submit" value="Go"><input type="text" class="search_input" name="search" placeholder="Search!">
    </form>

<!--    <div onclick="location.href='https://m.klattr.com/do_logout.php'" class="header_logout">Logout <?php echo $uname; ?></div> -->
  </div>
  <div style="width:100%;position:relative;float:right;">
    <div onclick="location.href='https://m.klattr.com'" class="header_button<?php if ($page == "Feed") {echo "_selected";}  ?>">&#9777; Feed</div>
    <div onclick="location.href='https://m.klattr.com/in.php'" class="header_button<?php if ($page == "Forme") {echo "_selected";}  ?>">&#62; In</div>



<?php  


}
?>
  </div>
</div>
<div id="body">
    <div class="feed">
<!--      <?php include "/data/klattr.com/www/includes/user_panel"; ?> -->
<?php include "/data/klattr.com/www/includes/klattr_retrieve_queries"; ?>
<?php include "/data/klattr.com/www/includes/m.render_klattrs"; ?>
<?php include "/data/klattr.com/www/includes/do_scroll"; ?>

    </div>
</div>
<div id="body">
  <div class="welcome">
    <h1>Welcome to Klattr.</h1>

    <h2>Login!</h2>
    <br /><br />
    <img src="/gfx/hr.png" width="350"/>
    <form name="Login" action="/do_login.php" method="post">
      <div class="form_line"><div class="form_text">Username:</div> <input type="text" class="gen_input" name="username"></div>
      <div class="form_line"><div class="form_text">Password:</div> <input type="password" class="gen_input" name="password"></div>
      <div class="form_line"><div class="form_text" style="font-size:10px; top:0px;"><a href="forgot_password.php" style="margin-right:10px;">Forgot your password?</a> Keep me signed in.</div><input type="checkbox" name="stay_signed_in" value="yes" class="checkbox_login" checked></div>
      <div class="form_line"><input type="submit" class="submit_login" value="Sign In!"></div>
    </form>
    <h2>Don't have a Klattr Account?</h2> <h3>Sign Up!</h3>
    <br /><br />
    <img src="/gfx/hr.png" width="350" />
    <form name="SignUp" action="/do_signup.php" method="post">
      <div class="form_line"><div class="form_text">Full Name:</div> <input type="text" class="gen_input" name="name"></div>
      <div class="form_line"><div class="form_text">Email Address:</div> <input type="text" class="gen_input" name="email"></div>
      <div class="form_line"><div class="form_text">Password:</div> <input type="password" class="gen_input" name="password"></div>
      <input type="hidden" class="gen_input" name="username">
      <div class="form_line"><input type="submit" class="submit_signup" value="Sign Up!"></div>
    </form>
  <div>
</div>
<?php
include "/data/klattr.com/www/includes/fuzzyago";
$count = 0;
while ($row = mysqli_fetch_array($sql_result)){
  if ($row['Data'] != "") {
    $count ++;
    $klattr_id = $row['ID'];
  if (isset($nestLevel)) {
    $nestID = "_nest" . $nestLevel;
  }
?>
<!--#######################################################################################-->


<div class="klattr_div" id="<?php echo $row['Data'] . $nestID;?>"><div class="klattr_div_inner">
  <div style="width:100%">
    <center>
      <h6><?php echo $row['Title'];?> 
        <div style="font-family:  KlattrFont, Arial;font-size:10px; color:#535353;">(About <?php echo fuzzyAgo($row['Time_Posted']); ?>)
        </div>
      </h6>
    </center>

    <?php echo $row['Handle']; ?>

    <div style="width:100%">
<?php
    if ($row['Handle'] == $uname) {
?>

      <div class="delete_klattr" onclick="delete_klattr('<?php echo $row['Data']; ?>')">
        <form id="delete"><img src="/gfx/delete.png" height="15" style="display:inline;float:right">
        </form>
      </div>

<?php
    }
?>
      <div class="tags" style="width:230px;">
<?php
  if ($row['Recipient'] != "  ") {
    echo "        To: ";
  }

$recipient_array = explode(" ", $row['Recipient']);
foreach ($recipient_array as &$recipient){
  if ($recipient != "") {
    echo "<a href=\"/$recipient\">\n          <div class=\"tag\" style=\"height:10px;padding:1px;\">$recipient\n          </div>\n        </a> ";
  }
}
//echo $row['Recipient'];
?>

      </div>
      <div class="clear"></clear>
    </div>
  </div>
  <a href="/<?php echo $row['Handle']; ?>"><img class="klattr_img" src="/<?php echo $row['Handle']; ?>.jpeg"></a>
  <div class="record_div" style="width:245px;background-image:url('https://klattr.com/waveform.php?id=<?php echo $row['ID'];?>');background-size:245px 60px;" >
    
    <div class="play_progress" id="progress_audio_<?php echo $row['Data'] . $nestID; ?>"></div>
    <input id="button_audio_<?php echo $row['Data'] . $nestID; ?>"type="button" class="play_button" style="top:0px; left:-30px" onclick="play_klattr('audio_<?php echo $row['Data'] . $nestID; ?>')">
    
  </div>
  
  <audio class="audios" id="audio_<?php echo $row['Data'] . $nestID; ?>" preload="auto">
    <source src="/<?php echo $row['Data']; ?>.ogg" type="https://klattr.com/audio/ogg">
    <source src="/<?php echo $row['Data']; ?>.mp3" type="https://klattr.com/audio/mpeg">
    Your browser does not support this audio format.
  </audio>
  <div style="width:100%">
    <input type="button" class="submit_signup" value="Reply" style="width:68px;height:16px;font-size:10px;" onclick="showeditor('record_popup'); set_recipient('<?php echo $row['Handle']; ?>', <?php echo $row['ID']; ?>)">
    <div class="tags" style="width:195px">
<?php 
    $tags = preg_replace('/\s\s+/', ' ', $row['Tags']);
    $tag_array = explode(" ", $tags);
    foreach ($tag_array as &$tag) {
      if ($tag != "") {
        echo "<a href=\"/search.php?search=" . $tag . "\"><div class=\"tag\">" . $tag . "</div></a>";
      }
    }
?>  
    </div>
<?php
    if ($row['Num_Replies'] >= 1) {
      if (!isset($nestLevel)) {
        $nestLevel = 0;
      }
?>
    <div class="replies">
      <span class="fake-link" id="link<?php echo $row['ID'] . '_' . $nestLevel; ?>" onclick="get_replies(<?php echo $row['ID'] . ', ' . $nestLevel; ?>)"><?php echo $row['Num_Replies']; ?> Replies <img src="/gfx/down.png" width="8" id="up_down<?php echo $row['ID'] . '_' . $nestLevel; ?>"\>
      </span>
    </div>
    <div class="clear">
    </div>
  </div>
</div>
<img src="/gfx/spacer.png" width="100%" height="1">
<div id="Parent<?php echo $row['ID'] . '_' . $nestLevel; ?>"></div>
<?php
    } else {
?>
    <div class="clear">
    </div>
  </div>
</div>  
<?php
    }
?>    
  <img src="/gfx/hr.png" width="100%" height="1" id="devider<?php echo $row['ID'] . '_' . $nestLevel; ?>">
</div>
<?php
    if ($row['Num_Replies'] >= 1) {
?>
<!--<div class="inLineReplies" id="Parent<?php echo $row['ID']; ?>"></div>-->
<?php
    }
  }
}

if ($count < 1) {
  if ($get_more == 0 && $page != "search" ) {
?>
<div class="klattr_div"><center>No Klattrs Yet :(</center></div>
<?php
  } else if ($get_more == 1) {
?>
<div class="klattr_div"><center>No more Klattrs</center></div>
<?php
  }
?>
<img src="/gfx/vr.png" width="0" height="0" onload="set_oldest('no_more');this.parentNode.removeChild(this);" \>

<?php
}
if ($page !== "replies") {
?>

<img src="/gfx/vr.png" width="0" height="0" onload="set_oldest(<?php echo $klattr_id; ?>);this.parentNode.removeChild(this);" \>
<?php
}
?>

<html>
<body>
<div style="width:600px;margin-right:auto;margin-left:auto;border-style:solid;border-width:1px;">
<h1 style="color:#ffffff;background-color:#686A88;padding:5px;margin:0px">You've received a Klattr.</h1><div style="background-image:url('https://klattr.com/gfx/welcome_bg.png');background-repeat:no-repeat;padding:5px">
Dear FULLNAME.<br><br>
SENDER has just sent you a Klattr! <a href="klattr.com">Login</a> to hear what they have to say.<br><br>
The Klattr Team.
</div></div>
</body>
</html>
<html>
<body>
<div style="width:600px;margin-right:auto;margin-left:auto;border-style:solid;border-width:1px;">
<h1 style="color:#ffffff;background-color:#686A88;padding:5px;margin:0px">You have a new subscriber!</h1><div style="background-image:url('https://klattr.com/gfx/welcome_bg.png');background-repeat:no-repeat;padding:5px">
Dear FULLNAME.<br><br>
SENDER has just subscribed to your Klattr feed! Why not <a href="klattr.com/SENDER">login</a> and say 'Hi'.<br><br>
The Klattr Team.
</div></div>
</body>
</html>
<?php
    // Create connection
    global $con;
    $con=mysqli_connect("localhost","klattr","xxxxxxxxxx","live_povr");

    // Check connection
    if (mysqli_connect_errno())
    {
      echo "Failed to connect to database: " . mysqli_connect_error();
    }
?>
<html>
<body>

<div style="width:600px;margin-right:auto;margin-left:auto;border-style:solid;border-width:1px;">
<h1 style="color:#ffffff;background-color:#686A88;padding:5px;margin:0px">Klattr Password Reset.</h1><div style="background-image:url('https://klattr.com/gfx/welcome_bg.png');background-repeat:no-repeat;padding:5px">
Dear FULLNAME.<br><br>
Someone, hopefully you, has requested to have your Klattr password reset. If you did not initiate this request please ignore this email, however if you would like your password reset, please follow <a href="https://klattr.com/forgot_password.php?key=UNIQUEKEY">this link</a> or copy the below into your browser address bar.<br>https://klattr.com/forgot_password.php?key=UNIQUEKEY<br><br>
The Klattr Team.
</div></div>

</body>
</html>
<?php
include "/data/klattr.com/www/includes/fuzzyago";
$count = 0;
while ($row = mysqli_fetch_array($sql_result)){
  if ($row['Data'] != "") {
    $count ++;
    $klattr_id = $row['ID'];
  if (isset($nestLevel)) {
    $nestID = "_nest" . $nestLevel;
  }
?>
<div class="klattr_div" id="<?php echo $row['Data'] . $nestID;?>"><div class="klattr_div_inner">
  <div><center><h6><?php echo $row['Title'];?> <div style="font-family:  KlattrFont, Arial;font-size:10px; color:#535353;">(About <?php echo fuzzyAgo($row['Time_Posted']); ?>)</div></h6></center><?php echo $row['Handle']; ?>
<?php
    if ($row['Handle'] == $uname) {
?>

<div class="delete_klattr" onclick="delete_klattr('<?php echo $row['Data']; ?>')"><form id="delete"><img src="/gfx/delete.png" height="15" style="display:inline;float:right"></form></div>

<?php
    }
?>
<div class="tags" style="width:282px;">
<?php
  if ($row['Recipient'] != "  ") {
    echo "To: ";
  }

$recipient_array = explode(" ", $row['Recipient']);
foreach ($recipient_array as &$recipient){
  if ($recipient != "") {
    echo "<a href=\"/$recipient\"><div class=\"tag\" style=\"height:10px;padding:1px;\">$recipient</div></a> ";
  }
}
//echo $row['Recipient'];
?>
</div>
</div>
  <a href="/<?php echo $row['Handle']; ?>"><img class="klattr_img" src="/<?php echo $row['Handle']; ?>.jpeg"></a>
  <div class="record_div" style="width:300px;background-image:url('/waveform.php?id=<?php echo $row['ID'];?>');background-size:300px 60px;" >
    
    <div class="play_progress" id="progress_audio_<?php echo $row['Data'] . $nestID; ?>"></div>
    <input id="button_audio_<?php echo $row['Data'] . $nestID; ?>"type="button" class="play_button" style="top:0px; left:-30px" onclick="play_klattr('audio_<?php echo $row['Data'] . $nestID; ?>')">
    
  </div>
  
  <audio class="audios" id="audio_<?php echo $row['Data'] . $nestID; ?>" preload="auto">
    <source src="/<?php echo $row['Data']; ?>.ogg" type="audio/ogg">
    <source src="/<?php echo $row['Data']; ?>.mp3" type="audio/mpeg">
    Your browser does not support this audio format.
  </audio>
<input type="button" class="submit_signup" value="Reply" style="width:68px;height:16px;font-size:10px;" onclick="showeditor('record_popup'); set_recipient('<?php echo $row['Handle']; ?>', <?php echo $row['ID']; ?>)">
  <div class="tags">
<?php 
    $tags = preg_replace('/\s\s+/', ' ', $row['Tags']);
    $tag_array = explode(" ", $tags);
    foreach ($tag_array as &$tag) {
      if ($tag != "") {
        echo "<a href=\"/search.php?search=" . $tag . "\"><div class=\"tag\">" . $tag . "</div></a>";
      }
    }
?></div>
<?php
    if ($row['Num_Replies'] >= 1) {
      if (!isset($nestLevel)) {
        $nestLevel = 0;
      }
?>
  <div class="replies"><span class="fake-link" id="link<?php echo $row['ID'] . '_' . $nestLevel; ?>" onclick="get_replies(<?php echo $row['ID'] . ', ' . $nestLevel; ?>)"><?php echo $row['Num_Replies']; ?> Replies <img src="/gfx/down.png" width="8" id="up_down<?php echo $row['ID'] . '_' . $nestLevel; ?>"\></span></div></div>
<img src="/gfx/spacer.png" width="430" height="1">
<div id="Parent<?php echo $row['ID'] . '_' . $nestLevel; ?>"></div>
<?php
    } else {
?>
</div>  
<?php
    }
?>    
  <img src="/gfx/hr.png" width="430" height="1" id="devider<?php echo $row['ID'] . '_' . $nestLevel; ?>">
</div>
<?php
    if ($row['Num_Replies'] >= 1) {
?>
<!--<div class="inLineReplies" id="Parent<?php echo $row['ID']; ?>"></div>-->
<?php
    }
  }
}

if ($count < 1) {
  if ($get_more == 0 && $page != "search" ) {
?>
<div class="klattr_div"><center>No Klattrs Yet :(</center></div>
<?php
  } else if ($get_more == 1) {
?>
<div class="klattr_div"><center>No more Klattrs</center></div>
<?php
  }
?>
<img src="/gfx/vr.png" width="0" height="0" onload="set_oldest('no_more');this.parentNode.removeChild(this);" \>

<?php
}
if ($page !== "replies") {
?>

<img src="/gfx/vr.png" width="0" height="0" onload="set_oldest(<?php echo $klattr_id; ?>);this.parentNode.removeChild(this);" \>
<?php
}
?>

<?php
  while ($row = mysqli_fetch_array($sql_result)){
    if ($row['Handle'] != "") {
      $pcount ++;
      $person_id = $row['ID'];
?>

<div class="klattr_div">
  <div class="name_block">
    <a href="https://klattr.com/<?php echo $row['Handle']; ?>"><h7><?php echo $row['Handle']; ?></h7>
    (<?php echo $row['Name']; ?>)</a>
  </div>
  <a href="https://klattr.com/<?php echo $row['Handle']; ?>"><img id="user_pic" src="<?php echo $row['Handle']; ?>.jpeg"></a>
  <div style="height:30px;width:270px;position:relative;float:right;margin-right:5px;"><?php echo $row['Profile_Text']; ?></div>
    
        <br><img src="/gfx/hr.png" width="430" />
</div>

<?php
    }
  }
?>
<img src="/gfx/vr.png" width="0" height="0" onload="set_oldest(<?php echo $person_id; ?>);this.parentNode.removeChild(this);" \>
<?php
?>
<div id="body">
  <div class="body_center">
    <div class="feed">
      <?php include "/data/klattr.com/www/includes/user_panel"; ?>

        <div class="feed_inner" style="margin-bottom:10px;"><div class="klattr_div">
    <form name="SearchForm2" action="/search.php" method="GET">
      <div class="form_line"><input type="submit" class="search_submit" value="Go"><input type="text" class="search_input" name="search" <?php 
if ($page == "peopleSearch") { ?> 
placeholder="Search People!"
<?php } else { ?>
placeholder="Search!"
<?php } ?>
style="width:350px"></div>
    </form>
        </div></div>

      <div class="feed_inner" <?php if ($page == "peopleSearch") { ?> id="klattr_parent" <?php } ?> style="margin-bottom:10px;">

<h5>People.</h5>
<?php 
if ($page == "peopleSearch") {
  $search_limit = 10;
  include "/data/klattr.com/www/includes/search_people";
  ?></div><?php
} else {
  $search_limit = 3;

include "/data/klattr.com/www/includes/search_people";
$page ="search";
?>
      </div>

      <div class="feed_inner" id="klattr_parent">
<?php include "/data/klattr.com/www/includes/klattr_retrieve_queries"; ?>

<h5>Klattrs.</h5>

<?php include "/data/klattr.com/www/includes/render_klattrs"; ?>
<?php include "/data/klattr.com/www/includes/do_scroll"; ?>

<?php
if ($count == 0) {
?>

        <div class="klattr_div">
          <center>Sorry. No results found.</center>
        </div>

<?php
}
}

?>
      </div>
    </div>
  </div>
</div>
<?php
  $pcount = 0;
  $page = "peopleSearch";
  include "/data/klattr.com/www/includes/klattr_retrieve_queries";
  include "/data/klattr.com/www/includes/render_people";

  if ($pcount == 0) {
?>

<div class="klattr_div">
  <center>Sorry. No results found.</center>
</div>

<?php
  } else {
    if ($ps == 1) {
      include "/data/klattr.com/www/includes/do_scroll"; 
    } else {
?>

<div class="klattr_div">
  <a href="/search.php?search=<?php echo $searchQuery; ?>&type=people"><center>Search for more people</center></a>
</div>

<?php
    }
  }

?>
<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body onload="validateForm(Exists)">
    <?php include "/data/klattr.com/www/includes/header"; ?>
    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>

<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body onload="validateForm(Exists)">
    <script>
      Exists = 0;
      Exists = <?php echo $exists;  ?>;
    </script>
    <?php include "/data/klattr.com/www/includes/header"; ?>
    <div class="body_center">
      <div class="do_signup">
        <h1>Join Klattr Now.</h1>
        <form name="SignUp" action="/do_signup.php" method="post">
          <div class="form_line">
            <div class="form_text">Full Name:</div>
            <div class="form_val" id="val_name"></div>
            <input type="text" class="gen_input" name="name" value="<?php echo $name; ?>" onkeyup="validateForm(Exists)" onblur="validateForm(Exists)">
          </div>
          <div class="form_line">
            <div class="form_text">eMail Address:</div>
            <div class="form_val" id="val_email"></div>
            <input type="text" class="gen_input" name="email" value="<?php echo $email; ?>" onkeyup="validateForm(Exists)" onblur="validateForm(Exists)">
          </div>
          <div class="form_line">
            <div class="form_text">Password:</div>
            <div class="form_val" id="val_pass"></div>
            <input type="password" class="gen_input" name="password" value="<?php echo $password; ?>" onkeyup="validateForm(Exists)" onblur="validateForm(Exists)">
          </div>
          <div class="form_line">
            <div class="form_text">User Name:</div>
            <div class="form_val" id="val_uname"></div>
            <input type="text" class="gen_input" name="username" value="<?php echo $username; ?>" onkeyup="validateForm(Exists)" onblur="validateForm(Exists)">
          </div>

          <img src="/gfx/hr.png" width="450" height="1"/>
          <div class="form_line">
            <div class="form_text">Legal Notice:</div>
          </div>
          <div class="legal">
            <?php include "/data/klattr.com/www/includes/legal"; ?>
          </div>
          <img src="/gfx/hr.png" width="450" height="1"/>
          <div class="form_line" style="width:150px;">
            <div class="form_text" style="font-size:10px; top:0px;">Keep me signed in.</div>
            <input type="checkbox" name="stay_signed_in" value="yes" class="checkbox_login" checked>
          </div>

          <div class="form_line">
            <div class="form_val">&nbsp;</div>
            <div id="sub_div"><input type="submit" class="submit_signup" style="width:200px;" value="Sign Up!"></div>
          </div>
        </form>
      </div>
    </div>
    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>

<?php
  $sql = "SELECT Handle, Name, Profile_Text, Website_Addr, Avatar, ID FROM Users WHERE Handle='$profileUname' AND BINARY(Handle) = BINARY('$profileUname') AND Activated = '1'";
  $sql_result = mysqli_query($con,$sql);
  $row = mysqli_fetch_array($sql_result);
  $profileUname = $row['Handle'];
  $profileRname = $row['Name'];
  $profileProfile = $row['Profile_Text'];
  $profileURL = $row['Website_Addr'];
  $profileID = $row[ID];
  if ($row['Avatar'] === "" || $row['Avatar'] === NULL) {
    $profileUserPic = "/gfx/default_user.png";
  } else {
    $profileUserPic = $profileUname . ".jpeg";
  }

  if ($profileRname == "") {
?>
<div id="body">
  <div class="body_center">
    <div class="user_banner">
      <h4>Sorry! No Such User Exists!</h4> 
    </div>
  </div>
</div>

<?php
  } else {
?>
<div id="body">
  <div class="body_center" style="top:10px;">
    <div class="user_banner">
      <img id="user_pic_main" src="<?php echo $profileUserPic;  ?>" <?php
  if ($profileUname == $uname) {
    echo " onmouseover=\"editstyle('user_pic_main')\" onmouseout=\"normalstyle('user_pic_main')\"";
    echo " onclick=\"showeditor('edit_profile_picture')\"";
  }
?>> <h4>
<?php echo $profileUname; ?></h4>
      <div id="user_text" style=""<?php
  if ($profileUname == $uname) {
    echo " onmouseover=\"editstyle('user_text')\" onmouseout=\"normalstyle('user_text')\"";
    echo " onclick=\"showeditor('edit_profile_text')\"";
  }
?>>
<?php
  if ($profileUname == $uname && $profileProfile == "") { 
    echo "<div class=\"mute_text\">Click to add Profile Text.</div>";
  } else {
    echo $profileProfile;
  }
  echo "<div class=\"profile_link\"><a href=\"" . $profileURL . "\" class=\"profile\">" . $profileURL . "</a></div>";
?>
  
  </div>

    </div>
  <br><div class="user_panel_wrapper">
<?php include "/data/klattr.com/www/includes/user_panel"; ?>    
    <div class="feed_inner" style="width:450px">
      <div id="klattr_parent">
<?php include "/data/klattr.com/www/includes/klattr_retrieve_queries"; ?>
<?php include "/data/klattr.com/www/includes/render_klattrs"; ?>
<?php include "/data/klattr.com/www/includes/do_scroll"; ?>
      </div><br class="clear" />
    </div>
  </div>
  </div>

</div>
<?php
if ($profileUname == $uname) {
?>



<div id="dim"></div>
<div class="dialog_wrapper" id="edit_profile_text">
  <div class="dialog">
    <h5>Edit Profile Text & Web Address.</h5>
    <img src="/gfx/hr.png" width="450" height="1"/>
    <Form name="EditProfile" action="/do_profile_text_edit.php" method="post">
      Profile Text:<br>
      <textarea rows="4" cols="60" name="profileText" placeholder="Describe yourself here."><?php echo $profileProfile; ?></textarea><br>
      Web Address:<br>
      <input type="text" class="gen_input_left" name="webAddress" value="<?php echo $profileURL;?>">
      <input type="hidden" name="senduname" value="<?php echo $profileUname; ?>">
      <input type="submit" class="submit_login" style="width:100px;" value="Save It">
      <input type="button" onclick="hideeditor('edit_profile_text')" class="cancel_login" style="width:100px;" value="Cancel">
    </Form>
  </div>
</div>

<div class="dialog_wrapper" id="edit_profile_picture">
  <div class="dialog">
    <h5>Edit Profile Picture</h5>
    <img src="/gfx/hr.png" width="450" height="1"/>
    <form name="EditProfilePicture" enctype="multipart/form-data" action="/do_profile_picture_edit.php" method="post">
      Choose image file:<br>
      <div class="image_edit">
        <img id="image_upload" src="<?php echo $userPic;?>" class="preview_image" /> 
      </div>
      <div class="file_wrapper">
        <button class="btn-file-input">Choose File</button>
        <input type="hidden" name="senduname" value="<?php echo $profileUname; ?>">
        <input id="imgInp" type="file" name="file" accept="image/gif, image/jpeg, image/png" />
      </div>
      <input type="submit" class="submit_login" style="width:100px;" value="Save It">
      <input type="button" onclick="hideeditor('edit_profile_picture')" class="cancel_login" style="width:100px;" value="Cancel">
    </form>
  </div>
</div>
<?php
}

}
?>
<?php

if ($profileUname == $uname || $profileUname == "") {
  $panelName = $uname;
} else {
  $panelName = $profileUname;
}

$sql = "SELECT ID, Subscribed_To FROM Users WHERE Handle='$panelName'";
$sql_result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($sql_result);
$panelUID = $row['ID'];
//echo "blah" . $row['Subscribed_To'];
$sub_list = preg_replace('/\s\s+/', ' ', $row['Subscribed_To']);
$sub_list = substr($sub_list, 1, -1);
//echo "Sub List" . $sub_list;
$sub_array = explode(" ", $sub_list);
if ($sub_array[0] != "") {
  $num_subscribed_to = count($sub_array);
} else {
  $num_subscribed_to = 0;
}
$sql = "SELECT COUNT(*) AS Count from Povs WHERE Poster='$panelUID'";
$sql_result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($sql_result);
$numKlattrs = $row['Count'];

$handle_plus_space = " " . $panelName . " ";
$sql = "SELECT COUNT(*) AS Count from Users WHERE INSTR(Subscribed_To, '$handle_plus_space') > 0";
$sql_result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($sql_result);
$numSubscribers = $row['Count'];

$sql = "SELECT Handle FROM Users WHERE INSTR(Subscribed_To, '$handle_plus_space') > 0";
$sql_subscribers = mysqli_query($con,$sql);


?>

<script src="/js/sound.js"></script>
<div style="width:300px;float:right;min-height:400px;">
      <div class="user_panel">
<?php
if ($page != "user") {
?>
        <h5><?php echo $rname; ?></h5>
        <a href="https://klattr.com/<?php echo $uname; ?>"><img id="user_pic" src="<?php echo $userPic; ?>"></a>
        <img src="/gfx/hr.png" width="220" />
        
<?php
}
?>
<script>set_profile_id('<?php echo $profileID; ?>')</script>
        <table>
          <tr>
            <td class="panel_title">Klattrs</td>
            <td rowspan="2"><img src="/gfx/vr.png" height="36" width="1"></td>
            <td class="panel_title">Subscribers</td>
            <td rowspan="2"><img src="/gfx/vr.png" height="36" width="1"></td>
            <td class="panel_title">Subscribed to</td>
          </tr>
          <tr>
            <td class="panel_content"><?php echo $numKlattrs; ?></td>
            <td class="panel_content"><?php echo $numSubscribers; ?></td>
            <td class="panel_content"><?php echo $num_subscribed_to; ?></td>
          </tr>
        </table>
        
<?php
if ($page == "user" && $profileUname != $uname){

  $handle_plus_space = " " . $profileUname . " ";
  $sql = "SELECT Handle FROM Users WHERE Handle='$uname' AND INSTR(Subscribed_To, '$handle_plus_space') > 0";
  $sql_result = mysqli_query($con,$sql);
  $row = mysqli_fetch_array($sql_result);
  
  if ($row['Handle'] == "") {
?>
<form name="Subscribe" action="/do_subscribe.php" method="post">
  <input type="hidden" name="sub_to" value="<?php echo $profileUname; ?>">
  <input type="button" id="sub_button" class="submit_signup" value="Subscribe!" style="width:250px" onclick="subscribe_to()">
</form>
<?php
  } else {
?>
<form name="Subscribe" action="/do_subscribe.php" method="post">
  <input type="hidden" name="sub_to" value="<?php echo $profileUname; ?>">
  <input type="button" id="sub_button" class="cancel_signup" value="Unsubscribe!" style="width:250px" onclick="subscribe_to()">
</form>
<?php
  }
} 

if ($page =="user" && $profileUname == $uname) {
?>
<form name="Subscribe" action="/do_profile_edit.php" method="post">
  <input type="hidden" name="name" value="<?php echo $uname; ?>">
  <input type="submit" id="sub_button" class="submit_signup" value="Edit Profile/Settings" style="width:250px">
</form>
<?php
}
?>
        <br><br>
        <div class="record_div">
          <form><input type="button" class="rec_button" onclick="showeditor('record_popup')" style="left:-30px;top:0px;"><div class="record">Record a Klattr!</div></form>
        </div>
      </div>
<?php
if ($page == "user"){
  if ($sub_array[0] != "") {
?>
      <div class="user_panel" style="top:10px">Subscribed To
<?php
   } else {
?>
      <div class="user_panel" style="top:10px">Not subscribed to anyone
<?php
   }
  $i = 0;
  foreach ($sub_array as &$sub){
    if ($sub != ""){
      $sql = "SELECT Activated FROM Users WHERE Handle='$sub'";
      $sql_result = mysqli_query($con,$sql);
      $row = mysqli_fetch_array($sql_result);
      if ($row['Activated'] == 1) {
        if(++$i > 4) {
          echo "<br><center><a href=\"/subscribed_to.php?user=" . $profileUname . "\">see all</a></center>";
          break;
        }
?>

    <div class="subscriber_row"><a href="https://klattr.com/<?php echo $sub; ?>"><img id="user_pic_small" style="float:left" src="<?php echo $sub; ?>.jpeg"><div class="subscriber"><?php echo $sub;?></div></a></div>

<?php
      }
    }
  }
?>
      </div>
      <div class="user_panel" style="top:20px">
<?php
  if ($numSubscribers == 0) {
    echo "No Subscribers";
  } else {
    echo "Subscribers";
  }


  $i = 0;
  while ($row = mysqli_fetch_array($sql_subscribers)){
  $sub = $row['Handle'];
?>
    <div class="subscriber_row"><a href="https://klattr.com/<?php echo $sub; ?>"><img id="user_pic_small" style="float:left" src="<?php echo $sub; ?>.jpeg"><div class="subscriber"><?php echo $sub;?></div></a></div>

<?php
  }

?>

      </div>
<?php
}
?>
</div>

<div id="dim"></div>
<div class="dialog_wrapper" id="record_popup">
  <div class="dialog" >
    <h5>Record a Klattr!</h5>
    <img src="/gfx/hr.png" width="450" height="1"/>
    <form name="SubmitKlattr" action="/process_klattr.php" method="post" enctype="multipart/form-data"> 
      <div id="Add_title"></div>
      <div id= "record_div" class="record_div" style="width:470px;overflow:hidden;">
        <div class="progress" id="progress">
          <div id="instructions" style="position:relative;top:18px;left:30px;float:left;width:300px">
            <-- Click to start recording
          </div>

        </div>
      </div> 
      <div style="width:100%; display:block-inline;position:relative;">
        <div id="klattr_wrapper" style="height:81px">
          <input type="button" id="do_record" class="rec_button" onclick="record(19500);toggle_recording()" style="z-index:100;top:1px;left:0px;">
        </div>
      <div id="Add_tags"></div>
      <div class="form_line" style="margin-right:0px" id="button_line">
        <input type="button" onclick="hideeditor('record_popup');reset_recording();destroy_submit_form();" class="cancel_login" style="width:100px;margin-right:0px" value="Cancel">
      </div>
      </div>
    </form>
  </div>
</div>


<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
  <msapplication>
    <tile>
      <square70x70logo src="/mstile-70x70.png"/>
      <square150x150logo src="/mstile-150x150.png"/>
      <square310x310logo src="/mstile-310x310.png"/>
      <wide310x150logo src="/mstile-310x150.png"/>
      <TileColor>#b91d47</TileColor>
    </tile>
  </msapplication>
</browserconfig>
@font-face {
 font-family: KlattrFontBold;
 src: url("/fonts/Serif_Bold.eot") /* EOT file for IE */
}
@font-face {
 font-family: KlattrFontBold;
 src: url("/fonts/Serif_Bold.ttf") /* TTF file for CSS3 browsers */
}

@font-face {
 font-family: KlattrFont;
 src: url("/fonts/Serif.eot") /* EOT file for IE */
}
@font-face {
 font-family: KlattrFont;
 src: url("/fonts/Serif.ttf") /* TTF file for CSS3 browsers */
} 


body
{
  color:#ffffff;
  background-color:#686A88;
  background-image:url('/gfx/darkened.gif.png');
  background-repeat:no-repeat;
  //background-position:center top;
  background-attachment:fixed;
  background-size:contain;
  //height:100%;
  margin:0px;
  overflow:auto;
  font-size:14px;
  font-family:  KlattrFont, Arial;
}

a{
  color:#6628a6;
  text-decoration:none;
}

.fake-link {
  color:#6628a6;
  text-decoration:none;
  cursor: pointer;
}

div.profile_link{
  position:absolute;
  bottom:3px;
  width:640px;
}

a.profile{
  position:relative;
  text-align:center;
  margin-left:auto;
  margin-right:auto;

}

a:hover{
  text-decoration:none;
}

#container {
  min-height:100%;
  position:relative;
}

#header {
  position:fixed;
  width:100%;
  z-index:50;
  background:#444;
  height:60px;
  padding:0px;
  box-shadow:0px 0px 4px #000000;
}
#body {
  position:relative;
  padding-bottom:30px;   /* Height of the footer */
  //height:100%;
  width:100%;
  #overflow:auto;
}

div.feed {
  position:relative;
  width:100%;
  background: rgb(255, 255, 255);
  padding-top:60px;
  padding-bottom:10px;
  color:#000;
  height:auto;
  min-height:230px;
  -moz-border-radius: 3px;
  border-radius: 3px;
}
.clear { clear: both; }

div.user_panel_wrapper{
  position:relative;
  //background-color:#ff0000;
  overflow:auto;
  //top:-100px;
  width:780px;
  padding:0px;
}

div.user_panel {
  position:relative;

  //position:fixed;
  color:#000;
  float:right;
  background-color:#fff;
  width:250px;
  padding:10px;
  margin-right:10px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;

}

div.feed_inner {
  position:relative;
  color:#000;
  background-color:#fff;
  width:450px;
//  padding:10px;
  margin-left:10px;
  margin-bottom:100px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;

  -moz-border-radius: 3px;
  border-radius: 3px;
}

#footer {
  position:fixed;
  bottom:0;
  width:100%;
  height:30px;   /* Height of the footer */
  background:#444;
  box-shadow:0px 0px 4px #000000;
}

#header_logo {
  position:relative;
  float:left;
  top:3px;
  margin-right:25px;
  border:0px;
}

#user_text {
  position:relative;
  border-style:none;
  border:3px;
  width:640px;
  height:60px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  float:right;
}

div.header_center{
  position:relative;
  width:770px;
  margin-left:auto;
  margin-right:auto;
  padding-right:30px;
  padding-top:0px;
  top:0px;
}

div.body_center{
  position:relative;
  width:100%;
  top:100px;
}

div.login{
  position:relative;
  background-color:#ffffff;
  float:left;
  left:-10px;
  width:358px;
  height:210px;
  color:#222222;
  margin:20px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;
}

div.welcome{
  position:relative;
  background-color:#ffffff;
  background-repeat:no-repeat;
  background-image:url('/gfx/welcome_bg.png');
  width:100%;
  color:#222222;
  top:60px;
  //margin:20px;
  border-width:0px;
  border-style:solid;
  border-color:#464866;
 }

div.user_banner{
  position:relative;
  background-color:#ffffff;
  background-repeat:no-repeat;
  background-image:url('/gfx/welcome_bg.png');
  float:left;
  left:-10px;
  //top:-90px;
  width:738px;
  height:93px;
  padding:10px;
  color:#222222;
  margin:20px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;
  text-align:center;
}


div.legal{
  position:relative;
  background-color:#ffffff;
  width:456px;
  height:200px;
  color:#555555;
  margin-left:15px;
  margin-right:15px;
  margin-top:0px;
  margin-bottom:0px;
  border-width:1px;
  border-style:solid;
  border-color:#bdbdbd;
  -moz-border-radius: 3px;
  border-radius: 3px;
  overflow:auto; 
  font-size:9px;
}

div.do_signup{
  position:relative;
  background-color:#ffffff;
  background-repeat:no-repeat;
  background-image:url('/gfx/welcome_bg.png');
  float:left;
  left:-10px;
  width:758px;
  color:#222222;
  margin:20px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;
}



div.copyright{
  position:relative;
  float:right;
  right:20px;
  top:7px;
}


h1{
  margin-left:20px;
  margin-top:0px;
  font-family: KlattrFontBold, Arial;
  font-weight:normal;
}

h2{
  position:relative;
  margin-left:15px;
  top:15px;
  font-size:14px;
  font-family:  KlattrFontBold, Arial;
  font-weight:normal;
  display:inline;
}

h3{
  position:relative;
  top:15px;
  font-size:14px;
  font-family:  KlattrFontBold, Arial;
  font-weight:normal;
  display:inline;
  color:#686A88;
}

h4 {
  position:relative;
  display:inline;
  font-size:32px;
  font-weight:normal;
  text-align:left;
  margin-left:auto;
  margin-right:auto;
}

h5 {
  margin-left:5px;
  position:relative;
  display:inline;
  font-size:20px;
}

h6 {
  display:inline;
  font-size:14px;
  font-family:  KlattrFontBold, Arial;
  color:#686A88;
  margin-top:5px;
  margin-bottom:5px;
  text-decoration:none; 
  font-weight:normal; 
}

h7 {
  position:relative;
  font-size:15px;
  font-family:  KLattrFontBold, Arial;
  font-weight:normal;
  color:#686A88;
  display:block;
  vertical-align:top;
}

div.form_text
{
  position:relative;
  top:8px;
  display:inline;
  width:250px;
}

div.form_val
{
  position:relative;
  top:8px;
  display:inline;
  width:250px;
  float:right;
  padding-left:20px;
}


div.form_line{
  overflow:auto;
  margin-left:15px;
  margin-right:15px;
  margin-top:0px;
  margin-bottom:0px;
  height:35px;
  padding:2px;
}

input.submit_login{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-left:solid 1px #55bb44;
  border-top:solid 1px #55bb44;
  border-right:solid 1px #228811;
  border-bottom:solid 1px #228811;
  background-image:url('/gfx/login_button.png');
  height:28px;
  width:80px;
  box-shadow:0px 2px 2px #666666;
  font-family:  KlattrFont, Arial;
  font-weight:normal;
  text-decoration:none;
}

input.cancel_login{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-left:solid 1px #bb5544;
  border-top:solid 1px #bb5544;
  border-right:solid 1px #882211;
  border-bottom:solid 1px #882211;
  background-image:url('/gfx/cancel_button.png');
  height:28px;
  width:80px;
  box-shadow:0px 2px 2px #666666;
  margin-right:5px;
  font-family:  KlattrFont, Arial;
  font-weight:normal;
  text-decoration:none;
}


input.button_inactive{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-left:solid 1px #cccccc;
  border-top:solid 1px #cccccc;
  border-right:solid 1px #aaaaaa;
  border-bottom:solid 1px #aaaaaa;
  height:28px;
  width:80px;
  box-shadow:0px 2px 2px #cccccc;
  color:#aaaaaa;
}


input.submit_login:hover{
  background-image:url('/gfx/login_button_dark.png');
  cursor:pointer;
}

input.cancel_login:hover{
  background-image:url('/gfx/cancel_button_dark.png');
  cursor:pointer;
}

div.file_wrapper{
  float:left;
  height:32px;
  width:100px;
  overflow:hidden;
  position:relative;
  cursor:pointer;
}

div.file_wrapper > .btn-file-input{
  display:inline-block;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-top:solid 1px #bbbb44;
  border-left:solid 1px #bbbb44;
  border-right:solid 1px #888811;
  border-bottom:solid 1px #888811;
  background-image:url('/gfx/signup_button.png');
  height:28px;
  width:100px;
  box-shadow:0px 2px 2px #666666;
  cursor:pointer;
}

div.file_wrapper:hover > .btn-file-input{
  background-image:url('/gfx/signup_button_dark.png');
  cursor:pointer;
} 

div.file_wrapper > input{

    font-size: 200px;
    position: absolute;
    top: 0;
    right: 0;
  width:102px;
  height:32px;
  filter: alpha(opacity=0); /* internet explorer */
  -khtml-opacity: 0;      /* khtml, old safari */
  -moz-opacity: 0;       /* mozilla, netscape */
    opacity: 0;
  cursor:pointer;
}

div.file_wrapper:hover > input{
  cursor:pointer;
}

input.submit_signup{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-top:solid 1px #bbbb44;
  border-left:solid 1px #bbbb44;
  border-right:solid 1px #888811;
  border-bottom:solid 1px #888811;
  background-image:url('/gfx/signup_button.png');
  height:28px;
  width:80px;
  box-shadow:0px 2px 2px #666666;
  cursor:pointer;
  font-family:  KlattrFont, Arial;
  font-weight:normal;
  text-decoration:none;

}

input.submit_signup:hover{
  background-image:url('/gfx/signup_button_dark.png');
  cursor:pointer;
} 


input.cancel_signup{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border-left:solid 1px #bb5544;
  border-top:solid 1px #bb5544;
  border-right:solid 1px #882211;
  border-bottom:solid 1px #882211;
  background-image:url('/gfx/cancel_button.png');
  height:28px;
  width:80px;
  box-shadow:0px 2px 2px #666666;
  cursor:pointer;
  font-family:  KlattrFont, Arial;
  font-weight:normal;
  text-decoration:none;
}

input.cancel_signup:hover{
  background-image:url('/gfx/cancel_button_dark.png');
  cursor:pointer;
} 

input.search_submit{
  position:relative;
  float:right;
  -webkit-border-top-right-radius: 11px;
  -webkit-border-bottom-right-radius: 11px;
  -moz-border-radius-topright: 11px;
  -moz-border-radius-bottomright: 11px;
  border-top-right-radius: 11px;
  border-bottom-right-radius: 11px;
  height:26px;
  margin-top:2px;
  border-top:solid 1px #bbbb44;
  border-left:solid 1px #bbbb44;
  border-right:solid 1px #888811;
  border-bottom:solid 1px #888811;
  background-image:url('/gfx/signup_button.png');
  left:-2px;
  padding-left:4px;
}

input.search_submit:hover{
  cursor:pointer;
  background-image:url('/gfx/signup_button_dark.png');
}

input.rec_button{
  -moz-border-radius: 30px;
  border-radius: 30px;
  box-shadow:1px 0px 3px #000;
  position:absolute;
  left:110px;
  top:45px;
  border:0px;
  height:60px;
  width:60px;
  background:transparent;
  background-image:url('/gfx/rec_dark.png');
  cursor:pointer;

}

input.stop_button{
  -moz-border-radius: 30px;
  border-radius: 30px;
  box-shadow:1px 0px 3px #000;
  position:absolute;
  left:110px;
  top:45px;
  border:0px;
  height:60px;
  width:60px;
  background:transparent;
  background-image:url('/gfx/stop_dark.png');
  cursor:pointer;

}


input.play_button{
  -moz-border-radius: 30px;
  border-radius: 30px;
  box-shadow:1px 0px 3px #000;
  position:absolute;
  left:110px;
  top:45px;
  border:0px;
  height:60px;
  width:60px;
  background:transparent;
  background-image:url('/gfx/play_dark.png');
  cursor:pointer;
}

input.stop_button:hover{
  background-image:url('/gfx/stop_light.png');
  box-shadow:1px 0px 20px #f88;
  border:0px;
}

input.stop_button:focus {
  outline:0px;
}

input.play_button:hover{
  background-image:url('/gfx/play_light.png');
  box-shadow:1px 0px 20px #f88;
  border:0px;
} 

input.play_button:focus {
  outline:0px;
} 

div.progress{
  left:10px;
  width:0px;
  background-color:#ff0000;
  background-image:url('/gfx/Anim-progress.gif');
  height:60px;
  position:relative;
  display:inline-block;
}

div.play_progress{
  left:8px;
  width:0px;
  background-color:#ff0000;
  background-image:url('/gfx/Anim-progress.gif');
  height:60px;
  position:relative;
  display:inline-block;
  filter: alpha(opacity=50); /* internet explorer */
  -khtml-opacity: 0.5;      /* khtml, old safari */
  -moz-opacity: 0.5;       /* mozilla, netscape */
  opacity: 0.5;           /* fx, safari, opera */

}


input.rec_button:hover{
  background-image:url('/gfx/rec_light.png');
  box-shadow:1px 0px 20px #f88;
  border:0px;
}

input.rec_button:focus {
  outline:0px;
}

input.gen_input{
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border:solid 1px #bdbdbd;
  height:26px;
  width:200px;

}
input.gen_input_left{
  -moz-border-radius: 3px;
  border-radius: 3px;
  border:solid 1px #bdbdbd;
  height:26px;
  width:200px;

}

input.search_input{
  position:relative;
  float:right;
  -webkit-border-top-left-radius: 11px;
  -webkit-border-bottom-left-radius: 11px;
  -moz-border-radius-topleft: 11px;
  -moz-border-radius-bottomleft: 11px;
  border-top-left-radius: 11px;
  border-bottom-left-radius: 11px;
  border:solid 1px #bdbdbd;
  height:22px;
  width:150px;
  margin-top:2px;
  padding-left:10px;
  
}

input.search_input:focus{
  border:solid 1px #686A88;
  outline:0px;
  width:150px;
  box-shadow:0px 0px 2px #686a88;
}

input.gen_input:focus{
  border:solid 1px #686A88;
  outline:0px;
  width:200px;
  box-shadow:0px 0px 2px #686a88;
}

input.gen_input_left:focus{
  border:solid 1px #686A88;
  outline:0px; 
  width:200px;
  box-shadow:0px 0px 2px #686a88;
} 

textarea{
  -moz-border-radius: 3px;
  border-radius: 3px;
  border:solid 1px #bdbdbd;
}

textarea:focus{
  border:solid 1px #686A88;
  outline:0px;
  box-shadow:0px 0px 2px #686a88;
}


input.checkbox_login{
  float:right;
}

div.header_button_selected{
  float:left;
  position:relative;
  background-color:#3d3d3d;
  border-left:solid 0px #333;
  border-right:solid 0px #333;
  height:25px;
  width:50%;
  box-shadow:0px 3px 3px #686A88;
  text-align: center;
  vertical-align: middle;
  font-size:18px;
  padding-top:5px;
  font-weight:bold;
  text-shadow: 0px 0px 0.4em #fff, 1px 1px #656565, -1px -1px #222;
  cursor:pointer;
  color:#D8DAF8;
}

div.header_button{
  float:left;
  position:relative;
  height:25px;
  width:50%;
  text-align: center;
  vertical-align: middle;
  font-size:18px;
  color:#333;
  padding-top:5px;
  font-weight:bold;
  text-shadow: 0px 0px 0.4em #555, 1px 1px #666, -1px -1px #111;
  cursor:pointer;

}



div.header_logout{
  position:relative;
  float:right;
  display:inline;
  font-size:12px;
  width:100px;
  text-align:right;
  cursor:pointer;
  right:5px;
  top:1px;

}

#user_pic_main {
  position:relative;
  float:left;
  width:90px;
  height:90px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;

}

#user_pic {
  position:relative;
  float:right;
  width:50px;
  height:50px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;

}

#user_pic_small {
  position:relative;
  float:right;
  width:23px;
  height:23px;
  margin:2px;
  border-width:1px;
  border-style:solid;
  border-color:#fff;
  -moz-border-radius: 3px;
  border-radius: 3px;

}



#dim
{
  height:100%;
  width:100%;
  position:fixed;
  left:0;
  top:0;
  z-index:51 !important;
  background-color:black;
  filter: alpha(opacity=0); /* internet explorer */
  -khtml-opacity: 0;      /* khtml, old safari */
  -moz-opacity: 0;       /* mozilla, netscape */
  opacity: 0;           /* fx, safari, opera */
  visibility:hidden;
}


div.dialog_wrapper 
{
  width: 100%;
  top: 100px;
  left: 0px;
  position: absolute;
  z-index: 55;
  display: block;
  visibility:hidden;
  filter: alpha(opacity=0); /* internet explorer */
  -khtml-opacity: 0;      /* khtml, old safari */
  -moz-opacity: 0;       /* mozilla, netscape */
  opacity: 0;           /* fx, safari, opera */

}

div.dialog
{
  -moz-border-radius: 3px;
  border-radius: 3px;
  width: 500px;
  margin: 0 auto;
  padding: 7px;
  background-color: #fff;
  border: 1px solid #ccc; color: #000;
  overflow:auto;
  box-shadow:0px 2px 8px #000000;
}

div.exit_button
{
  float:right;
  border: 1px solid #ddd;
  -moz-border-radius: 3px;
  border-radius: 3px;
  font=size: 10px;
  width:16px;
  text-align:center;
}

div.image_edit{
  -moz-border-radius: 3px;
  border-radius: 3px;
  border: 1px solid #ccc; color: #000;
  width:498px;
  height:220px;
  display:block;
  padding:5px
  margin-top:10px;
  margin-bottom:10px;
  background-color:#686A88;
  box-shadow:inset 0 0 10px #000000
}

img.preview_image{
  position:relative;
  width:125px;
  height:125px;
  margin-right:175;
  margin-left:175px;;
  margin-top:40px;
  -moz-border-radius: 3px;
  border-radius: 3px; 
  border: 3px solid #fff; color: #000;
  box-shadow:0px 2px 8px #000000;
}

img.centred{
  position:relative;
  margin-left:auto;
  margin-right:auto;
  display:block;
}

img.klattr_img{
  position:relative;
  height:60px;
  width:60px;
  border-width:1px;
  border-style:solid;
  border-color:#464866;
  -moz-border-radius: 3px;
  border-radius: 3px;

}

div.record_div{
  position:relative;
  float:right;
  -moz-border-radius: 3px;
  border-radius: 3px;
  border: 1px solid #ccc; 
  color: #fff;
  font-size:18px;
  width:220px;
  height:60px;
  display:block;
  padding:0px
  margin-top:20px;
  margin-bottom:0px;
  background-color:#686A88;
  box-shadow:inset 0 0 10px #000000;
  vertical-align:middle;
}

div.record_div

div.blank{
  float:right;
  font-size:18px;
  height:60px;
  display:block;
  padding:0px
  margin-top:20px;
  margin-bottom:0px;
  vertical-align:middle;
}
div.record{
  position:relative;
  float:right;
  right:20px;
  top:20px;
}



td.panel_title{
  width:70px;
  font-size:10px;
  text-align:center;
}

td.panel_content{
  font-size:20px;
  text-align:center;
  color:#686A88;
}

img.preload {
  position: absolute;
  display: block;
  top: -40000px;
  left: -400000px;
}

div.delete_klattr {
  cursor:pointer;
  float:right;
}

div.tags {
  width:230px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  padding-left:3px;
  padding-right:3px;
  margin-right:2px;
  background-color:#dcdcdc;
  font-size:10px;
  float:right;
  position:relative;

}

div.replies {
  width:57px;
  height:18px
  -moz-border-radius: 3px;
  border-radius: 3px;
  padding-left:3px;
  padding-right:3px;
  padding-top:4px;
  padding-bottom:4px;
  margin-right:2px;
  background-color:#dcdcdc;
  font-size:8px;
  float:left;
  position:relative;

}

div.tag {
  -moz-border-radius: 3px;
  border-radius: 3px;
  padding:2px;
  background-color:#ffffff;
  margin:1px;
  display:inline-block;
  position:relative;

}

div.subscriber_row {
  position:relative;
  -moz-border-radius: 3px;
  border-radius: 3px;
  padding-left:3px;
  padding-right:3px;
  margin-top:3px;
  background-color:#dcdcdc
}

div.subscriber {
  vertical-align:middle;
  line-height:30px;
}

div.klattr_div {
  margin-top:10px;
}
div.klattr_div_inner {
  position:relative;
  padding-left:10px;
  padding-right:10px;
}


div.name_block {
  margin-left:5px;
  width:100px;
  float:left;
  font-size:11px;
}

div.inLineReplies {
  padding-top:10px;
  padding-bottom:10px;
  box-shadow:inset 0  10px 10px -10px #000000,inset 0 -10px 10px -10px #000000;
  margin:0px;
}
<?php
if (isset($_POST["username"]) && isset($_POST["password"])) {
  $username = $_POST["username"];
  $pass = $_POST["password"];
  $sticky = $_POST["stay_signed_in"];
  $expire_time = 0;
  if ($sticky == "yes") {
    $expire_time = time()+2592000;
  }

  include "/data/klattr.com/www/includes/evaluate_password";
  include "/data/klattr.com/www/includes/open_db";
  $username = evaluate_password($username, $pass);
  if ($username != 1) {
//echo $username;
    $sql = "SELECT ID FROM Users WHERE Handle='$username'";
    $sql_result = mysqli_query($con,$sql);
    $row = mysqli_fetch_array($sql_result);
    $UID = $row['ID'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $randomData = file_get_contents('/dev/urandom', false, null, 0, 128) . uniqid(mt_rand(), true);
    $randkey = substr(str_replace(array('/','=','+'),'', base64_encode($randomData)),0,128);

    $session_date = date("Y-m-d h:i:s");
    $sql = "INSERT INTO Session (SessionKey, UserID, IP, Date) VALUES ('$randkey','$UID','$ip','$session_date')";
    mysqli_query($con,$sql);
    setcookie ("session_auth", $randkey, $expire_time, "/", ".klattr.com");

    header( 'Location: https://m.klattr.com' );


  } else {
    header( 'Location: https://m.klattr.com?up=' . evaluate_password($username, $pass));
  }
} else {
  header( 'Location: https://m.klattr.com' );
}
?>
<?php

if (isset($_COOKIE['session_auth'])) {
  include "/data/klattr.com/www/includes/open_db";
  $cookie_key = $_COOKIE['session_auth'];
  $sql = "DELETE FROM Session WHERE SessionKey='$cookie_key'";
  mysqli_query($con,$sql);
  unset($_COOKIE['session_auth']);
  setcookie("session_auth", "", time()-3600, "", ".klattr.com");
  header( 'Location: https://klattr.com' );
} else {
  header( 'Location: https://klattr.com' );
}


?>
<?php
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
  $profileUname = $uname; 
  $sql = "SELECT Handle, Name, Profile_Text, Website_Addr, Avatar, ID FROM Users WHERE Handle='$profileUname' AND BINARY(Handle) = BINARY('$profileUname')";
  $sql_result = mysqli_query($con,$sql);
  $row = mysqli_fetch_array($sql_result);
  $profileUname = $row['Handle'];
  $profileRname = $row['Name'];
  $profileProfile = $row['Profile_Text'];
  $profileURL = $row['Website_Addr'];
  $profileID = $row[ID];
  if ($row['Avatar'] === "" || $row['Avatar'] === NULL) {
    $profileUserPic = "/gfx/default_user.png";
  } else {
    $profileUserPic = $profileUname . ".jpeg";
  }

  $page = "edit_profile";
?>
<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body onload="validatePasswordReset(Exists)">
    <script>
      Exists = 0;
    </script>
    <?php include "/data/klattr.com/www/includes/header"; ?>
<div id="body">
  <div class="body_center" style="top:10px;">
    <div class="user_banner">
      <img id="user_pic_main" src="<?php echo $profileUserPic;  ?>" onmouseover="editstyle('user_pic_main')" onmouseout="normalstyle('user_pic_main')" onclick="showeditor('edit_profile_picture')">
  
      <h4><?php echo $profileUname; ?></h4>
      <div id="user_text" style="" onmouseover="editstyle('user_text')" onmouseout="normalstyle('user_text')" onclick="showeditor('edit_profile_text')">
<?php
  if ($profileProfile == "") { 
    echo "<div class=\"mute_text\">Click to add Profile Text.</div>";
  } else {
    echo $profileProfile;
  }
  echo "<div class=\"profile_link\"><a href=\"" . $profileURL . "\" class=\"profile\">" . $profileURL . "</a></div>";
?>
  
      </div>
    </div>
    <div class="do_signup" style="top:-30px">
      <h1>Change Password.</h1>
      <form name="SignUp" method="POST" action="/reset_password.php">
      <div>
      <div class="form_line"><div class="form_text">Password:</div>
      <div class="form_val" id="val_pass"></div>
      <input type="password" class="gen_input" name="password" onkeyup="validatePasswordReset(Exists)" onblur="validatePasswordReset(Exists)"></div>
      <div class="form_line"><div class="form_text">Retype password:</div>
      <div class="form_val" id="val_pass2"></div>
      <input type="password" class="gen_input" name="password2" onkeyup="validatePasswordReset(Exists)" onblur="validatePasswordReset(Exists)"></div>
      </div>
      <div class="form_line">
        <div id="sub_div" style="display:none"><input type="submit" class="submit_signup" style="width:200px;float:right;" value="Reset Password!"></div>
        <input type="button" class="submit_signup" style="width:200px;float:right;" value="Reset Password!" onclick="reset_password()">
      </div>
      </form>
    </div>
    <div class="do_signup" style="top:-60px">
      <h1>Close Account.</h1>
      <form name="DeleteAccount" method="POST" action="/delete_account.php">
        <div class="form_line">
          <div class="form_text">
            If for some reason you'd like to close your account with us, click here.
          </div>
          <input type="submit"  class="cancel_signup" style="width:200px;float:right;" value="Close Account!"> 
          
        </div>
      </form>
    </div>
  </div>
</div>


<div id="dim"></div>
<div class="dialog_wrapper" id="edit_profile_text">
  <div class="dialog">
    <h5>Edit Profile Text & Web Address.</h5>
    <img src="/gfx/hr.png" width="450" height="1"/>
    <Form name="EditProfile" action="/do_profile_text_edit.php" method="post">
      Profile Text:<br>
      <textarea rows="4" cols="60" name="profileText" placeholder="Describe yourself here."><?php echo $profileProfile; ?></textarea><br>
      Web Address:<br>
      <input type="text" class="gen_input_left" name="webAddress" value="<?php echo $profileURL;?>">
      <input type="hidden" name="senduname" value="<?php echo $profileUname; ?>">
      <input type="submit" class="submit_login" style="width:100px;" value="Save It">
      <input type="button" onclick="hideeditor('edit_profile_text')" class="cancel_login" style="width:100px;" value="Cancel">
    </Form>
  </div>
</div>

<div class="dialog_wrapper" id="edit_profile_picture">
  <div class="dialog">
    <h5>Edit Profile Picture</h5>
    <img src="/gfx/hr.png" width="450" height="1"/>
    <form name="EditProfilePicture" enctype="multipart/form-data" action="/do_profile_picture_edit.php" method="post">
      Choose image file:<br>
      <div class="image_edit">
        <img id="image_upload" src="<?php echo $userPic;?>" class="preview_image" /> 
      </div>
      <div class="file_wrapper">
        <button class="btn-file-input">Choose File</button>
        <input type="hidden" name="senduname" value="<?php echo $profileUname; ?>">
        <input id="imgInp" type="file" name="file" accept="image/gif, image/jpeg, image/png" />
      </div>
      <input type="submit" class="submit_login" style="width:100px;" value="Save It">
      <input type="button" onclick="hideeditor('edit_profile_picture')" class="cancel_login" style="width:100px;" value="Cancel">
    </form>
  </div>
</div>
    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>
<?php
} else {
  header( 'Location: https://klattr.com' );
}
?>
<?php
include "/data/klattr.com/www/includes/auth";

if ($auth == 1) {
//  echo print_r($_FILES);
//  echo $_FILES['file']['tmp_name'];

  $senduname = $_POST["senduname"];
  $type = $_FILES['file']['type'];
  $type = substr($type, 0, 5);
  if ($_FILES['file']['tmp_name'] != "" && $type === "image") {
    $image = new Imagick($_FILES['file']['tmp_name']);
    $image->resizeImage(150,150, imagick::FILTER_LANCZOS, 0.9, false);
    $image->setImageFormat('jpeg');
    $image = addslashes($image);
    $sql = "UPDATE Users SET Avatar='$image' WHERE ID='$UID'";
    mysqli_query($con,$sql);
  }
  header( "Location: https://klattr.com/$senduname" );

//  header('Content-type: image/jpeg');
//  echo $image;

} else {
  header( 'Location: https://klattr.com' );
}

?>
<?php
if (isset($_COOKIE['session_auth'])) {
  include "/data/klattr.com/www/includes/open_db";
  include "/data/klattr.com/www/includes/evaluate_cookie";
  $ip = $_SERVER['HTTP_X_REAL_IP'];
  if ($ip == "") {
    $ip = $_SERVER['REMOTE_ADDR'];
  }
  $cookie_key = $_COOKIE['session_auth'];
  $UID = evaluate_cookie($cookie_key, $ip);
  if ($UID !== 0) {
    $profileText = $_POST["profileText"];
    $profileURL = $_POST["webAddress"];
    $senduname = $_POST["senduname"];
    $profileText = htmlspecialchars($profileText);
    $profileText = addslashes($profileText);
    if(strpos($profileURL, 'http') !== 0) {
      $profileURL = "http://" . $profileURL;
    }
    if(!filter_var($profileURL, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) {
      $profileURL = "";
    }
    $sql = "UPDATE Users SET Website_Addr='$profileURL', Profile_Text='$profileText' WHERE ID='$UID'";
    mysqli_query($con,$sql);
    header( "Location: https://klattr.com/$senduname" );
  }
} else {
  header( 'Location: https://klattr.com' );
}
?>
<?php

$accountLimit = 250;

if (isset($_COOKIE['session_auth'])) {
  header( 'Location: https://klattr.com' );
} else {


  include "/data/klattr.com/www/includes/open_db";
  $sql = "SELECT COUNT(*) AS Num FROM Users";
  $sql_result = mysqli_query($con,$sql);
  $row = mysqli_fetch_array($sql_result);
  if ($row['Num'] > $accountLimit) {
?>

<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/header"; ?>

<div id="body">
  <div class="body_center">
    <div class="welcome" style="padding:10px; top:-70px;height:120px">
      <h1> Sorry. This beta is limited to <?php echo $accountLimit; ?> accounts. Please try later.</h1>
    </div>
  </div>
</div>


    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>
<?php
  } else {



 
    if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["password"]) && isset($_POST["username"])) {

      $name = $_POST["name"];
      $email = $_POST["email"];
      $password = $_POST["password"];
      $username = $_POST["username"];
      $sticky = $_POST["stay_signed_in"];
      $expire_time = 0;
      if ($sticky == "yes") {
        $expire_time = time()+2592000;
      }

      include "/data/klattr.com/www/includes/evaluate_signup";

      $e_n = evaluate_name($name);
      $e_e = evaluate_email($email);
      $e_p = evaluate_pass($password);
      $e_u = evaluate_uname($username);

      if ($e_n != 0 || $e_e != 0 || $e_p != 0 || $e_u != 0) {
        $exists = $e_e + $e_u;
        include "/data/klattr.com/www/includes/signup_page";
      } else {
        $enc_password = urlencode($password);
        $password_hash = crypt($enc_password);
#      $randkey = substr(str_shuffle(md5(time())),0,128);
#      $randkey = substr(sha1(rand()), 0, 128);
        $randomData = file_get_contents('/dev/urandom', false, null, 0, 128) . uniqid(mt_rand(), true);
        $randkey = substr(str_replace(array('/','=','+'),'', base64_encode($randomData)),0,128);

        $ip = $_SERVER['REMOTE_ADDR'];
        $sql = "INSERT INTO Users (Name, Email_Addr, Password_hash, Handle) VALUES ('$name','$email','$password_hash','$username')";
        mysqli_query($con,$sql);
        $sql = "SELECT ID FROM Users WHERE Handle='$username'";
        $sql_result = mysqli_query($con,$sql);
        $row = mysqli_fetch_array($sql_result);
        $UID = $row['ID'];
        $session_date = date("Y-m-d h:i:s");
        $sql = "INSERT INTO Session (SessionKey, UserID, IP, Date) VALUES ('$randkey','$UID','$ip','$session_date')";
        mysqli_query($con,$sql);
        setcookie ("session_auth", $randkey, $expire_time, "/", ".klattr.com");
        $uname = $username;
        $rname = $name;
        $uEmailAddr = $email;
        $first_mail = 1;
        include "/data/klattr.com/www/ht_docs/send_email.php";
        header( 'Location: https://klattr.com' );
//      include "/data/klattr.com/www/includes/signed_up";
      }
    } else {

  $name = $_POST["name"];
  $email = $_POST["email"];
  $password = $_POST["password"];
  $username = $_POST["username"];

  include "/data/klattr.com/www/includes/signup_page";
    }
  }
}
?>
<?php

$outfile = "/tmp/output.txt";

include "/data/klattr.com/www/includes/auth";

if ($auth == 1) {
	$target = $_POST['sub_to'];

	$sql = "SELECT Subscribed_To FROM Users WHERE ID='$UID'";
	$sql_results = mysqli_query($con,$sql);
	$row = mysqli_fetch_array($sql_results);
	$sub_list = $row['Subscribed_To'];

	if (preg_match("/^[a-zA-Z0-9_]+$/",$target)) {

		$target_matcher = " " . $target . " ";

		if (strpos($sub_list, $target_matcher) !== false) {
			$sub_list = str_replace($target_matcher, " ", $sub_list);
		} else {
			$sub_list = $sub_list . $target_matcher;
			$sub_list = str_replace('  ',' ',$sub_list);
		}

		$sql = "UPDATE Users SET Subscribed_To='$sub_list' WHERE ID='$UID'";
		mysqli_query($con,$sql);
	}

	//
	// Add the current user to the list of Subscribers for the person they're subscribing to
	$sql = "SELECT Subscribers FROM Users WHERE Handle='$target'";
	$sql_results = mysqli_query($con,$sql);
	$row = mysqli_fetch_array($sql_results);
	$sub_list = $row['Subscribers'];

	if (preg_match("/^[a-zA-Z0-9_]+$/",$UID)) {

		$target_matcher = " " . $UID. " ";

		if (strpos($sub_list, $target_matcher) !== false) {
			$sub_list = str_replace($target_matcher, " ", $sub_list);
		} else {
			$sub_list = $sub_list . $target_matcher;
			$sub_list = str_replace('  ',' ',$sub_list);
            $adding = 1;
		}

		$sql = "UPDATE Users SET Subscribers='$sub_list' WHERE Handle='$target'";
		mysqli_query($con,$sql);
	}

    // send emails to the subscribee
    $sql = "SELECT Name, Email_Addr FROM Users WHERE Handle = '$target' AND Activated = '1'";
    $sql_result = mysqli_query($con,$sql);
    $row = mysqli_fetch_array($sql_result);
    if ($row['Name'] != "" && $adding == 1) {
      $emailText = file_get_contents("/data/klattr.com/www/includes/new_subscriber_email_template");
      $emailText = str_replace("FULLNAME", $row['Name'], $emailText);
      $emailText = str_replace("SENDER", $uname, $emailText);
      $headers = "From: Klattr Team <administrator@klattr.com>\r\nReply-To: No Reply\r\n";
      $headers .= "MIME-Version: 1.0\r\n";
      $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
      mail($row['Email_Addr'], "You have a new subscriber!", $emailText, $headers);
    }
    	

} else {
	header( 'Location: https://klattr.com' );
}
?>
<?php
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
  header( 'Location: https://klattr.com' );
} elseif ($auth == 0) {
  if (isset($_POST['eoru'])) {
    $eoru = addslashes($_POST['eoru']);
    $eoru = str_replace(";", "", $eoru);

    include "/data/klattr.com/www/includes/open_db";
    $sql = "SELECT Email_Addr, ID, Name FROM Users WHERE Email_Addr='$eoru' OR Handle='$eoru'";
    $sql_result = mysqli_query($con,$sql);
    $row = mysqli_fetch_array($sql_result);
    
    if ($row['Email_Addr'] != "") {
      
      $rname = $row['Name'];
      $uEmailAddr = $row['Email_Addr'];
      $UID = $row['ID'];

      $emailText = file_get_contents("/data/klattr.com/www/includes/password_email_template");
      $emailText = str_replace("FULLNAME", $rname, $emailText);
      $randomData = file_get_contents('/dev/urandom', false, null, 0, 64) . uniqid(mt_rand(), true);
      $randkey = substr(str_replace(array('/','=','+'),'', base64_encode($randomData)),0,64);
      $emailText = str_replace("UNIQUEKEY", $randkey, $emailText);
      $headers = "From: Klattr Team <administrator@klattr.com>\r\nReply-To: No Reply\r\n";
      $headers .= "MIME-Version: 1.0\r\n";
      $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
      $sql = "UPDATE Users SET Activation_Key='$randkey' WHERE ID='$UID'";
      mysqli_query($con,$sql);
      mail($uEmailAddr, "Reset Password", $emailText, $headers);

?>
<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/header"; ?>
<div id="body">
  <div class="body_center">
    <div class="welcome" style="padding:10px; top:-70px;">
      Email sent. Please check your email for instructions.
    </div>
  </div>
</div>
    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>
<?php
    }
  } elseif (isset($_GET['key'])) {
    include "/data/klattr.com/www/includes/open_db";
    $recieved_key = addslashes($_GET['key']);
    $recieved_key = str_replace(";", "", $recieved_key);    
    $sql = "SELECT ID, Name, Handle, Activation_Key FROM Users WHERE Activation_Key='$recieved_key'";
    $sql_result = mysqli_query($con,$sql);
    $row = mysqli_fetch_array($sql_result);
?>
<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body onload="validatePasswordReset(Exists)">
    <script>
      Exists = 0;
    </script>
    <?php include "/data/klattr.com/www/includes/header"; ?>
<div id="body">
  <div class="body_center">
    <div class="welcome" style="padding:10px; top:-70px; height:200px">
      <h1>Reset password for <?php echo $row['Handle']; ?>.</h1>
      <form name="SignUp" method="POST" action="/reset_password.php">
      <div>
      <div class="form_line"><div class="form_text">Password:</div>
      <div class="form_val" id="val_pass"></div>
      <input type="password" class="gen_input" name="password" onkeyup="validatePasswordReset(Exists)" onblur="validatePasswordReset(Exists)"></div>
      <div class="form_line"><div class="form_text">Retype password:</div>
      <div class="form_val" id="val_pass2"></div>
      <input type="password" class="gen_input" name="password2" onkeyup="validatePasswordReset(Exists)" onblur="validatePasswordReset(Exists)"></div>
      </div>
      <div class="form_line">
        <div class="form_val">&nbsp;</div>
        <div id="sub_div"><input type="submit" class="submit_signup" style="width:200px;" value="Reset Password!"></div>
      </div>
      <input type="hidden" name="key" value="<?php echo $recieved_key; ?>">
      </form>
    </div>
  </div>
</div>
    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>
<?php    
  } else {
?>

<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/header"; ?>
<div id="body">
  <div class="body_center">
    <div class="welcome" style="padding:10px; top:-70px;height:150px">
<h1 style="padding:0px;margin:0px;">Retrieve Password.</h1><br> Please enter your eMail address or your username below and we'll send you an eMail with further instructions for resetting your password.<br><br>
<form name="retrieve_form" method="POST" action="/forgot_password.php">
<div class="form_line">
<div class="form_text">Username/eMail Address:</div>
<input type="submit" class="submit_signup" style="width:200px;margin-left:10px;" value="Submit!">
<input type="text" class="gen_input" style="width:300px" name="eoru">

</div></form>
    </div>
  </div>
</div>
    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>
<?php
  }
}
?>
<?php
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
  if (isset($_POST['oldest'])) {
    $oldest = $_POST['oldest'];
    $page = $_POST['page'];
    if (isset($_POST['profile_id'])) {
      $profileID = $_POST['profile_id'];
    }
    $get_more = 1;
// echo $page;
    $searchTerm = $_POST['search'];
    include "/data/klattr.com/www/includes/klattr_retrieve_queries";

    if ($page == "peopleSearch" ||  $page == "subscribed_to") {
//    echo "A";
      include "/data/klattr.com/www/includes/render_people";
    } else {
//    echo "B";
      include "/data/klattr.com/www/includes/render_klattrs";
    }
  }
} else {
  header( 'Location: https://klattr.com' );
}

?>
<?php
include "/data/klattr.com/www/includes/auth";
$parentId = $_POST['parent_id'];
$nestLevel = $_POST['nest_level'];

$page = "replies";
if (is_numeric($parentId) && is_numeric($nestLevel)) {
  include "/data/klattr.com/www/includes/klattr_retrieve_queries";
  include "/data/klattr.com/www/includes/render_klattrs";
}
?>
<?php
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
$page = "Forme";
?>

<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/header"; ?>
    <?php include "/data/klattr.com/www/includes/forme"; ?>

<?php
} else {
  header( 'Location: https://klattr.com' );
}
?>
    <?php include "/data/klattr.com/www/includes/footer"; ?>
  </body>
</html>

<?php
include "/data/klattr.com/www/includes/auth";
if ($auth == 1) {
$page = "Feed";
?>

<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/m.head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/m.header"; ?>
    <?php include "/data/klattr.com/www/includes/m.logged_in"; ?>

<?php
} elseif ($auth == 0) {
?>

<!DOCTYPE html>
<?php include "/data/klattr.com/www/includes/m.head"; ?>
  <body>
    <?php include "/data/klattr.com/www/includes/m.header"; ?>
    <?php include "/data/klattr.com/www/includes/m.login"; ?>

<?php
}


?>




    <?php include "/data/klattr.com/www/includes/m.footer"; ?>
  </body>
</html>
var klattr_recipient = "";
var klattr_parent_id = "";
var oldest_klattr;
var loading_content = 0;
var profile_id;
var search_term;



  function validateEmailAddr(email) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
  }

  function validateNameString(name) {
    var re = /^[a-zA-Z]+[a-zA-Z ]+$/;
    return re.test(name);
  }

  function validateUnameString(uname) {
    var re = /^[a-zA-Z0-9_]+$/;
    return re.test(uname);
  }

  function validateForm(Exist)
  {
    a = validateName();
    b = validateEmail(Exist);
    c = validatePassword();
    d = validateUsername(Exist);
    if (a + b + c + d == 0) {
      document.getElementById("sub_div").innerHTML = "<input type=\"submit\" class=\"submit_signup\" style=\"width:200px;\" value=\"Sign Up!\">";
    } else {
      document.getElementById("sub_div").innerHTML = "<input type=\"button\" class=\"button_inactive\" style=\"width:200px;\" value=\"Form Incomplete!\">";
    }
    Exists = 0;
  }

  function validatePasswordReset(Exists)
  {
    a = validatePassword();
    b = validatePassword2();
    if (a + b == 0) {
      document.getElementById("sub_div").innerHTML = "<input type=\"submit\" class=\"submit_signup\" style=\"width:200px;\" value=\"Reset Password!\">";
    } else {
      document.getElementById("sub_div").innerHTML = "<input type=\"button\" class=\"button_inactive\" style=\"width:200px;\" value=\"Form Incomplete!\">";
    }
    Exists = 0;
  }

  function validateName()
  {
    var nameString=document.forms["SignUp"]["name"].value;
    if (nameString==null || nameString==""){
      document.getElementById("val_name").innerHTML = "<font color=\"red\"> &#8678; You'll need a name.</font>";
      return 1;
    } else {
      if (validateNameString(nameString)) {
        document.getElementById("val_name").innerHTML = "<font color=\"green\"> &#10004; That name is fine.</font>";
        return 0;
      } else {
        document.getElementById("val_name").innerHTML = "<font color=\"red\"> &#8678; Letters only please.</font>";
        return 1;
      }
    }
  }

  function validateEmail(Exist)
  {
    if (Exist == 20 || Exist == 22) {
      document.getElementById("val_email").innerHTML = "<font color=\"red\"> &#8678; That address has been used.</font>";
      return 1;
    } else {
      var emailString=document.forms["SignUp"]["email"].value;
      if (emailString==null || emailString==""){
        document.getElementById("val_email").innerHTML = "<font color=\"red\"> &#8678; You'll need an eMail address.</font>";
        return 1;
      } else {
        if (validateEmailAddr(emailString)){
          document.getElementById("val_email").innerHTML = "<font color=\"green\"> &#10004; eMail address looks good.</font>";
          return 0;
        } else {
          document.getElementById("val_email").innerHTML = "<font color=\"red\"> &#8678; Are you sure?.</font>";
          return 1;
        }
      }
    }
  }

  function validatePassword()
  {
    var passString=document.forms["SignUp"]["password"].value;
    if (passString==null || passString==""){
      document.getElementById("val_pass").innerHTML = "<font color=\"red\"> &#8678; You'll want a password.</font>";
      return 1;
    } else {
      if (passString.length < 6){
        document.getElementById("val_pass").innerHTML = "<font color=\"red\"> &#8678; Six characters or more please.</font>";
        return 1;
      } else {
        document.getElementById("val_pass").innerHTML = "<font color=\"green\"> &#10004; Password is alright.</font>";
        return 0;
      }
    }
  }

  function validatePassword2()
  {
    var pass2String=document.forms["SignUp"]["password2"].value;
    var passString=document.forms["SignUp"]["password"].value;
    if (pass2String==null || pass2String==""){
      document.getElementById("val_pass2").innerHTML = "<font color=\"red\"> &#8678; Please retype Password.</font>";
      return 1;
    } else {
      if (pass2String == passString) {
        document.getElementById("val_pass2").innerHTML = "<font color=\"green\"> &#10004; Looks good.</font>";
        return 0;
      } else {
        document.getElementById("val_pass2").innerHTML = "<font color=\"red\"> &#8678; Passwords must match.</font>";
        return 1;
      }
    }
  }

  function validateUsername(Exist)
  {
    if (Exist == 2 || Exist == 22) {
      document.getElementById("val_uname").innerHTML = "<font color=\"red\"> &#8678;That username's gone. Sorry.</font>";
      return 1;
    } else {
      var unameString=document.forms["SignUp"]["username"].value;
      if (!validateUnameString(unameString)){
        if ( unameString == "") {
          document.getElementById("val_uname").innerHTML = "<font color=\"red\"> &#8678; A username is a must.</font>";
        } else {
          document.getElementById("val_uname").innerHTML = "<font color=\"red\"> &#8678; Letters and numbers only.</font>";
        }
        return 1;
      } else {
        if (unameString.length < 3) {
          document.getElementById("val_uname").innerHTML = "<font color=\"red\"> &#8678; At least three characters.</font>";
          return 1;
        } else {
          document.getElementById("val_uname").innerHTML = "<font color=\"green\"> &#10004; Looks good!";
          return 0;
        }
      }
    }  
  }

  function editstyle(Element)
  {
    El = document.getElementById(Element);
    El.style.boxShadow = '0px 0px 1px 2px #44ff44';
    El.style.cursor = 'url(/gfx/edit_cur.cur),auto';
  }

  function normalstyle(Element)
  {
    El = document.getElementById(Element);
    El.style.boxShadow = 'none';
    El.style.cursor = 'auto';

  }

  function showeditor(EditItem)
  {
    fade_in('dim', 0, 0.7);
    fade_in(EditItem, 0, 1);
    slide_in(EditItem, 100);
    document.getElementsByTagName("body")[0].style.overflow = "hidden";
    get_mic();
    
  }

  function showAlert(EditItem)
  { 
    fade_in(EditItem, 0, 1);
    slide_in(EditItem, 20);
    
  }

  function hideeditor(EditItem)
  {
    document.getElementById('dim').style.opacity = '0';
    document.getElementById('dim').style.filter = 'alpha(opacity=0)';

    document.getElementById(EditItem).style.opacity = '0';
    document.getElementById(EditItem).style.filter = 'alpha(opacity=0)';

    document.getElementById('dim').style.visibility = 'hidden';
    document.getElementById(EditItem).style.visibility = 'hidden';
    document.getElementsByTagName("body")[0].style.overflow = "auto";
  }

  function hideAlert(EditItem)
  {
    fade_out(EditItem, 1, 0);
    //document.getElementById(EditItem).style.opacity = '0';
    //document.getElementById(EditItem).style.filter = 'alpha(opacity=0)';
    //document.getElementById(EditItem).style.visibility = 'hidden';

  }

  function readURL(input)
  {
    if (input.files && input.files[0]) {
      var reader = new FileReader();
     
      reader.onload = function (e) {
        $('#image_upload').attr('src', e.target.result);
      }
            
      reader.readAsDataURL(input.files[0]);
    }
  }
    
  $("#imgInp").change(function(){
    readURL(this);
  });

  function slide_in(element, terminus) {
    top_modifier = document.documentElement.scrollTop || document.body.scrollTop;
    etop = top_modifier -400; 
    terminus += top_modifier;
    var timer = setInterval(function() {
//      console.log(etop)
      if (etop >= terminus){
        clearInterval(timer);
      }
      document.getElementById(element).style.top = '' + etop + 'px';
//console.log(document.getElementById(element).style.top)
      etop += 16;
    }, 1);
  }

  function fade_in(element, start, end) {
    op = start;  // initial opacity
    document.getElementById(element).style.visibility = 'visible';
    var timer = setInterval(function () {
      if (op >= end ){
        clearInterval(timer);
      }
      document.getElementById(element).style.opacity = parseFloat(op);
      document.getElementById(element).style.filter = 'alpha(opacity=' + parseFloat(op * 100) + ")";
      op += 0.1;
    }, 20);
  }

  function fade_out(element, start, end) {
    op = start;  // initial opacity
    var timer = setInterval(function () {
      if (op <= end ){
        clearInterval(timer);
      }
      document.getElementById(element).style.opacity = parseFloat(op);
      document.getElementById(element).style.filter = 'alpha(opacity=' + parseFloat(op * 100) + ")";
      op -= 0.1;
    }, 20);
    document.getElementById(element).style.visibility = 'hidden';
  }


  function make_submit_form() {
    document.getElementById("Add_title").innerHTML = "<div class=\"form_line\" style=\"margin-right:0px\"><div class=\"form_text\">Add a title:</div><input type=\"text\" class=\"gen_input\" maxlength=\"20\" style=\"width:300px;\" name=\"klattr_title\"></div><div class=\"form_line\" style=\"margin-right:0px\"><div class=\"form_text\">Add recipients (Max 5):</div><input type=\"text\" class=\"gen_input\" style=\"width:300px;\" name=\"klattr_recipients\" id=\"klattr_recipients\"></div>"; 
    document.getElementById("Add_tags").innerHTML = "<div id=\"output\"></div><div class=\"form_line\" style=\"margin-right:0px\"><div class=\"form_text\">Add some tags:</div><input type=\"text\" class=\"gen_input\" style=\"width:300px;\" name=\"klattr_tags\"></div>";
    document.getElementById("button_line").innerHTML = "<input type=\"button\" class=\"submit_login\" style=\"width:100px;\" value=\"Send It\" onclick=\"save_recording()\"><input type=\"button\" onclick=\"hideeditor('record_popup');reset_recording();destroy_submit_form();\" class=\"cancel_login\" style=\"width:100px;\" value=\"Cancel\">";
    
    document.getElementById("klattr_recipients").value = klattr_recipient;
    
  }

  function destroy_submit_form() {
    document.getElementById("Add_title").innerHTML = "";
    document.getElementById("Add_tags").innerHTML = "";
    document.getElementById("button_line").innerHTML = "<input type=\"button\" onclick=\"hideeditor('record_popup');reset_recording();destroy_submit_form();\" class=\"cancel_login\" style=\"width:100px;margin-right:0px\" value=\"Cancel\">";
    document.getElementById('record_div').className = "record_div";
    document.getElementById('record_div').style.width = "470px";
    document.getElementById('record_div').innerHTML = "<div class=\"progress\" id=\"progress\"><div id=\"instructions\" style=\"position:relative;top:18px;left:30px;float:left;width:300px\"><-- Click to start recording</div></div>";
    document.getElementById('klattr_wrapper').innerHTML = "<input type=\"button\" id=\"do_record\" class=\"rec_button\" onclick=\"record(19500);toggle_recording()\" style=\"z-index:100;top:1px;left:0px;\">";
    klattr_parent_id = "";
  }

  function send_klattr_form(Kblob) {
    document.getElementById('record_div').className = "blank"
    document.getElementById('record_div').innerHTML = "<img src=\"/gfx/wait.gif\" class=\"centred\">"; 
    document.getElementById('record_div').style.width = "500px";   
    document.getElementById('klattr_wrapper').innerHTML = ""; 
    var
      oOutput = document.getElementById("output"),
      oData = new FormData(document.forms.namedItem("SubmitKlattr"));
    if (klattr_parent_id != "") {
      oData.append("parent_id", klattr_parent_id);
    }
    oData.append("klattr_audio", Kblob);

    var oReq = new XMLHttpRequest();
    oReq.open("POST", "/process_klattr.php", true);
    oReq.onload = function(oEvent) {
      hideeditor('record_popup');
      destroy_submit_form();
      reset_recording();
      if (oReq.status == 200) {
        popAlert("Uploaded!");
        location.reload();
      } else {
        popAlert("Error " + oReq.status + " occurred uploading your file.<br \/>");
      }
    };

  oReq.send(oData);
  }


  function popAlert(message) {
    document.getElementById('popAlert_message').innerHTML = message;
    showAlert('popAlert'); 
    setTimeout(function(){hideAlert('popAlert')}, 2000); 
  }

  function delete_klattr(klattr) {
    console.log("here")
    var
      oOutput = document.getElementById("output"),
      oData = new FormData(document.forms.namedItem("delete_klattr"));

    oData.append("klattr", klattr);

    var oReq = new XMLHttpRequest();
    oReq.open("POST", "/delete_klattr.php", true);
    oReq.onload = function(oEvent) {
      if (oReq.status == 200) {
//console.log("success")
        popAlert("Klattr Deleted!");
        var element = document.getElementById(klattr);
        element.parentNode.removeChild(element);
//console.log('done')
      } else {
//console.log("failure")
        popAlert("Error " + oReq.status);
      }
    };
  oReq.send(oData); 
  }

  function subscribe_to() {
    var 
      oOutput = document.getElementById("output"),
      oData = new FormData(document.forms.namedItem("Subscribe"));

    var oReq = new XMLHttpRequest();
    oReq.open("POST", "/do_subscribe.php", true);
    oReq.onload = function(oEvent) {
      if (oReq.status == 200) {
//console.log("success")
        state = document.getElementById('sub_button').value;
        if (state == "Subscribe!") {
          document.getElementById('sub_button').value = "Unsubscribe!";
          document.getElementById('sub_button').className = "cancel_signup";
          popAlert("Subscribed!");
        } else {
          document.getElementById('sub_button').value = "Subscribe!";
          document.getElementById('sub_button').className = "submit_signup";
          popAlert("Unsubscribed!");
        }

      } else {
//console.log("failure")
        popAlert("Error " + oReq.status);
      } 
    };
  oReq.send(oData);
  }

function set_recipient(recipient, parent_id) {
//console.log(recipient)
  klattr_recipient = recipient;
  klattr_parent_id = parent_id;
//console.log(klattr_recipient)
}

function set_oldest(klattr_id) {
  if (klattr_id == "no_more") {
    loading_content = 1;
  } else {
    oldest_klattr = klattr_id;
//    console.log(oldest_klattr)
  }
}

function set_profile_id(id) {
  profile_id = id;
//  console.log(profile_id)
}

function retrieve_more(page) {

  $container = $('#klattr_parent');
  
  if (loading_content == 0) {
    var
      oData = new FormData();
    var retrieved_content = "<div id=\"feed_wait\"><center><img src=\"gfx/wait.gif\"></center></div>"
//    document.getElementById('klattr_parent').innerHTML += retrieved_content;
    $container.append(retrieved_content);
    loading_content = 1;
    oData.append("oldest", oldest_klattr);
    oData.append("page", page);
    oData.append("profile_id", profile_id);
    oData.append("search", search_term);
//console.log(search_term)

    var oReq = new XMLHttpRequest();
    oReq.open("POST", "/get_more.php", true);
    oReq.onload = function(oEvent) {
      if (oReq.status == 200) {
        var element = document.getElementById("feed_wait");
        element.parentNode.removeChild(element);
        retrieved_content = oReq.responseText;
//        document.getElementById('klattr_parent').innerHTML = document.getElementById('klattr_parent').innerHTML + retrieved_content;
        $container.append(retrieved_content);
        loading_content = 0;
      } else {
        popAlert("Error" + oReq.status);
//console.log("failed to retrieve more")
      }
    };
  oReq.send(oData);
  }
}

function get_replies(parent_id, nest_level) {
  var container_id = "Parent" + parent_id + "_" + nest_level;
  var up_down = "up_down" + parent_id + "_" + nest_level;
  var devider_id = "devider" + parent_id + "_" + nest_level;

  if (document.getElementById(up_down).src == "https://klattr.com/gfx/down.png") {
    document.getElementById(up_down).src = "https://klattr.com/gfx/up.png";
        
    nest_level += 1;

    var container = $('#' + container_id);
    var oData = new FormData();
    var retrieved_content = "<div id=\"replies_wait\"><center><img src=\"gfx/wait.gif\"></center></div>";
    document.getElementById(container_id).className = "inLineReplies";
    document.getElementById(devider_id).style.visibility = "hidden";
    container.append(retrieved_content);
    oData.append("parent_id", parent_id);
    oData.append("nest_level", nest_level);

    var oReq = new XMLHttpRequest();
    oReq.open("POST", "/get_replies.php", true);
    oReq.onload = function(oEvent) {
      if (oReq.status == 200) {
        var element = document.getElementById("replies_wait");
        element.parentNode.removeChild(element);
        retrieved_content = oReq.responseText;
        container.append(retrieved_content);
      } else {
        popAlert("Error" + oReq.status);
      }
    };
    oReq.send(oData);
  } else {
     
    document.getElementById(up_down).src = "https://klattr.com/gfx/down.png";
    document.getElementById(container_id).innerHTML = "";
    document.getElementById(container_id).className = "";
    document.getElementById(devider_id).style.visibility = "visible";

  }
}

function send_email() {
  var oData = new FormData();
  var oReq = new XMLHttpRequest();
  oReq.open("POST", "/send_email.php", true);
  oReq.onload = function(oEvent) {
    if (oReq.status == 200) {
      popAlert("eMail Sent");
    } else {
      popAlert("Error" + oReq.status);
    }
  };
  oReq.send(oData);
}

function reset_password() {
  var oData = new FormData(document.forms.namedItem("SignUp"));
  var oReq = new XMLHttpRequest();
  oReq.open("POST", "/reset_password.php", true);
  oReq.onload = function(oEvent) {
    if (oReq.status == 200) {
      retrieved_content = oReq.responseText;
      popAlert(retrieved_content);
    } else {
      popAlert("Error" + oReq.status);
    }
  };
  oReq.send(oData);
}







Klattrs/POVs go here