SHARE
TWEET

Untitled

a guest Apr 2nd, 2019 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. require_once('vendor/autoload.php');
  3. use \Firebase\JWT\JWT;
  4.  
  5. date_default_timezone_set('Europe/Copenhagen');
  6.  
  7. class Ssas {
  8.  
  9.     private static $mysqlServer = 'localhost';
  10.     private static $mysqlUser = 'root';
  11.     private static $mysqlPass = 'ssas';
  12.     private static $mysqlDb = 'ssas';
  13.     private static $key = "54.KO-314Q!";
  14.     private static $data;
  15.     private static $image_dir = "/var/www/html/uploads/";
  16.     private static $cooldown = 10;
  17.  
  18.     function __construct(){
  19.         $link = mysql_connect(self::$mysqlServer, self::$mysqlUser, self::$mysqlPass);
  20.         $db_selected = mysql_select_db(self::$mysqlDb, $link);
  21.     }
  22.  
  23.     // Custom implementaion of MySQL query execution in PHP.
  24.     // Someone mentioned that an "improved" version exists, but this works for now...
  25.     function execute($query_str, $split = false){
  26.         $result;
  27.         if ($split) $query_str = explode(';', $query_str);
  28.         else $query_str = str_split($query_str, strlen($query_str));
  29.         foreach ($query_str as &$query) {
  30.             if($query) $result = mysql_query($query);
  31.         }
  32.         return $result;
  33.     }
  34.  
  35.     // This function will authenticate a user based on the token cookie.
  36.     // returns true if the user is authenticated, otherwise return false
  37.     // if the token is invalid or has expired the method will call exit() and not return anything
  38.     function authenticate(){
  39.         if(isset($_COOKIE['token'])){
  40.             try{
  41.                 //Retrieves the JWT token from the cookie
  42.                 $token = $_COOKIE['token'];
  43.  
  44.                 //Decrypts the token. This call will throw an exception if the token is invalid
  45.                 $token = (array) JWT::decode($token,self::$key,array('HS512'));
  46.  
  47.                 //Extracts the user data from the token
  48.                 self::$data = (array) $token['data'];
  49.  
  50.                 //Check that the user actually exists (could have been removed)
  51.                 $uid = self::getUid();
  52.                 $uname = self::getUsername();
  53.                 if (self::verifyInput($uname)) {
  54.                     $query = "SELECT id FROM user WHERE id = ".mysql_real_escape_string($uid)." AND username = '".mysql_real_escape_string($uname)."';";
  55.                     $result = self::execute($query);
  56.  
  57.                     if (mysql_num_rows($result) > 0) return true;
  58.                 }
  59.                
  60.                 //If the query did not succeed, then there is something wrong!
  61.                 throw new Exception('Authentication failed!');
  62.  
  63.             } catch (Exception $e){
  64.  
  65.                 //This will happend if
  66.                 //  1) The token has expired
  67.                 //  2) The token is not valid
  68.                 //  3) No user matching the user data exists
  69.  
  70.                 self::logout();
  71.                 header("Location: index.php");
  72.                 exit(); //Just to be sure
  73.  
  74.             }
  75.         }
  76.        return false; //Could not authenticate
  77.     }
  78.  
  79.     // This function will destroy the token cookie if it exists
  80.     function logout(){
  81.         if(isset($_COOKIE['token'])){
  82.             unset($_COOKIE['token']);
  83.             setcookie('token', '', time() - 3600);
  84.         }
  85.     }
  86.  
  87.     // This function will check if the user is logged in
  88.     // If the user is not authenticated, the the method will try to authenticate.
  89.     // returns true if the user is logged in otherwise false
  90.     function isUserLoggedIn(){
  91.         if(!isset(self::$data) && isset($_COOKIE['token'])) self::authenticate();
  92.         return isset(self::$data);
  93.     }
  94.  
  95.     // This function will return to logged in users id (if authenticated)
  96.     function &getUid(){
  97.     if(self::isUserLoggedIn()) return self::$data['uid'];
  98.     }
  99.  
  100.     // This function will return to logged in users username (if authenticated)
  101.     function &getUsername(){
  102.     if(self::isUserLoggedIn()) return self::$data['username'];
  103.     }
  104.  
  105.     // This function will create a new user with the given username password combo
  106.     // returns true if the user was created, otherwise error message
  107.     function createUser($username, $password){
  108.  
  109.         if($username == "") return "username can't be empty";
  110.         if($password == "") return "password can't be empty";
  111.  
  112.         // Bad user input, like illegal character/byte
  113.         if (!(self::verifyInput($username) && self::verifyInput($password))) {
  114.            
  115.             return "bad character";    
  116.         }
  117.  
  118.         // Check length
  119.         if (strlen($username) > 20){
  120.             return "username too long";
  121.         } elseif (strlen($password) > 20){
  122.             return "password too long";
  123.         } elseif (strlen($password) < 6){
  124.             return "password too short";
  125.         }
  126.  
  127.         //Hash and encrypt password before inserting to database
  128.         $safePassword = password_hash(mysql_real_escape_string($password), PASSWORD_BCRYPT);
  129.  
  130.         //Inserts username and password into the database
  131.         $query = "INSERT INTO user(username,password) VALUES ('".mysql_real_escape_string($username)."','".mysql_real_escape_string($safePassword)."');";
  132.         self::execute($query, false);
  133.  
  134.         //If exactly one row was affected then we know that the user was inserted.
  135.         if (mysql_affected_rows() == 1) return true;
  136.         return "user could not be created";
  137.     }
  138.  
  139.     // This function will login with the given username password combo
  140.     // returns true if the login was successful, otherwise error message
  141.     function login($username, $password){
  142.        
  143.         $username_real = mysql_real_escape_string($username);
  144.         //Query to get the username and real password,
  145.         $query = "SELECT id,password FROM user WHERE username = '".$username_real."';";
  146.         $result = self::execute($query);
  147.  
  148.         if (mysql_num_rows($result) > 0) {
  149.             $row = mysql_fetch_assoc($result);
  150.             $uid = $row['id'];
  151.             $password_real = $row['password'];
  152.         } else {
  153.            
  154.             // Record try
  155.             $ip = self::getClientIP();
  156.             $tries = "SELECT login_tries FROM connection WHERE ip = $ip;";
  157.  
  158.             // Get now
  159.             $php_now = date_default_timezone_get();
  160.             $mysql_now = date( 'Y-m-d H:i:s', $phpdate);
  161.  
  162.             if (empty($tries)){
  163.                
  164.                 // User had not failed to login before
  165.                 // Register failed attempt
  166.                 $one = 1;
  167.                 $insert = "INSERT INTO connection (ip, login_tries, latest) VALUES ('$ip', '$one', '$mysql_now');";
  168.                 $insert_result = self::execute($insert);
  169.  
  170.             } else {
  171.  
  172.                 // User had failed to login before
  173.                 // Evaluate failed attempt count
  174.                 if ($tries >= 3){
  175.                
  176.                     // Check cooldown
  177.                     $latest_mysql = "SELECT latest FROM connection WHERE ip = $ip;";
  178.                     if (!empty($latest_mysql)){
  179.                        
  180.                         // Calculate cooldown
  181.                         $difference = strtotime($mysql_now) - strtotime($latest_mysql);
  182.                         if ($difference >= $cooldown){
  183.                        
  184.                             // Cooldown over
  185.                             $zero = 0;
  186.                             $update = "UPDATE connection SET login_tries = '$zero', latest = '$mysql_now' WHERE ip = $ip;";
  187.                             $update_result = self::execute($update);
  188.  
  189.                         } else {
  190.                             return "You're on cooldown, remaining seconds: " + $difference;
  191.                         }
  192.  
  193.                     } else {
  194.                         return "unable to process cooldown: latest trigger is missing";
  195.                     }
  196.  
  197.                 } else {
  198.  
  199.                     // Not on cooldown, simply update
  200.                     $increment = $tries + 1;
  201.                     $update = "UPDATE connection SET login_tries = '$increment', latest = '$mysql_now' WHERE ip = $ip;";
  202.                     $update_result = self::execute($update);
  203.                 }
  204.                
  205.             }
  206.            
  207.             return "username and password does not match";
  208.         }
  209.  
  210.         // If the real password matches the one given, then the login succeeds.
  211.         //if(isset($password_real) && (mysql_real_escape_string($password) === $password_real)){
  212.         if(isset($password_real) && password_verify(mysql_real_escape_string($password),$password_real)){
  213.  
  214.             // Generates random tokenid
  215.             // TODO Maybe store some of this server side... (Stateful or stateless?)
  216.             $tokenId = base64_encode(mcrypt_create_iv(32,MCRYPT_DEV_URANDOM));
  217.  
  218.             $issuedAt = time(); //time of issue
  219.             $notBefore = $issuedAt; //can be used to say that a token is not valid before a given time (not used)
  220.             $expire = $notBefore + 3600 * 24 * 90; //token expires in 90 days
  221.             $data = [
  222.                 'iat' => $issuedAt,
  223.                 'jti' => $tokenId,
  224.                 'nbf' => $notBefore,
  225.                 'exp' => $expire,
  226.                 'data' => [
  227.                     'uid' => $uid,
  228.                     'username' => $username
  229.                 ]
  230.             ];
  231.  
  232.             //Computes the encrypted token
  233.             $jwt = JWT::encode($data,self::$key,'HS512');
  234.  
  235.             //Sets to cookie to never expire as the token itself contains the expiration date (Mimimum exposure)
  236.             setcookie("token", $jwt, -1);
  237.             return true;
  238.         } else return "username and password does not match";
  239.  
  240.         return "could not login";
  241.     }
  242.  
  243.     // This function uploads the given image
  244.     // returns true if the image was successfully uploaded, otherwise error message.
  245.     function uploadImage($file, $mime){
  246.  
  247.         if(self::isUserLoggedIn()){
  248.  
  249.             // Size check carried over to ssas.php (previously on upload.php)
  250.             if (filesize($file) / 1000 < 4096 ){
  251.  
  252.                 $img = 'data:' . $mime . ';base64,' . base64_encode(file_get_contents($file));
  253.  
  254.                 $uid = self::getUid();
  255.                 $query = "INSERT INTO image(owner_id) VALUES(".$uid.");";
  256.                 $result = self::execute($query);
  257.                 if ($result) {
  258.  
  259.                     $iid = mysql_insert_id();
  260.                     self::save_image($img, $iid);
  261.                     return true;
  262.                 }
  263.  
  264.             } else {
  265.                 return "File size cannot be bigger than 4MB";
  266.             }      
  267.             return "Image could not be uploaded";
  268.         }
  269.         return "Your session timed out, please re-login";
  270.     }
  271.  
  272.     // This function will lookup a users id given the username
  273.     // returns the user id if exists, otherwise false
  274.     private function getUserId($username){
  275.  
  276.         $query = "SELECT id FROM user WHERE username = '".mysql_real_escape_string($username)."';";
  277.         $result = self::execute($query);
  278.         if (mysql_num_rows($result) > 0) {
  279.             $row = mysql_fetch_assoc($result);
  280.             return $row['id'];
  281.         }
  282.         return false;
  283.     }
  284.  
  285.     // This function will remove sharing with the given user for the given image
  286.     // returns true if the operation was successful, otherwise false
  287.     function removeShare($iid, $username){
  288.  
  289.         if(self::isUserLoggedIn() && self::isOwner($iid)){
  290.             $uid = self::getUserId($username);
  291.             if($uid == false) return false;
  292.  
  293.             // Removing sharing of image from database
  294.             $query = "DELETE FROM shared_image WHERE image_id = ".mysql_real_escape_string($iid)." AND user_id = ".mysql_real_escape_string($uid).";";
  295.             self::execute($query);
  296.  
  297.             return mysql_affected_rows() == 1;
  298.         }
  299.         return false;
  300.     }
  301.  
  302.     // This function will share the given image with the given user
  303.     // returns true if the image was shared, otherwise false
  304.     function shareImage($iid, $username)
  305.     {
  306.         // The user must be owner of the image to share it
  307.         if(self::isUserLoggedIn() && self::isOwner($iid)){
  308.  
  309.             // Getting uid from username
  310.             $uid = self::getUserId($username);
  311.  
  312.             // Inserting sharing of image into database
  313.             $query = "INSERT INTO shared_image VALUES ("$uid.",".$iid.");";
  314.             self::execute($query);
  315.  
  316.             return mysql_affected_rows() == 1;
  317.         }
  318.         return false;
  319.     }
  320.  
  321.     // This function returns a list of users whom the given image can be shared with
  322.     // returns a list of users if successful, otherwise false
  323.     function getUsersToShareWith($iid){
  324.         if(self::isUserLoggedIn()){//&& self::isOwner($iid)){
  325.             $users = array();
  326.  
  327.             // Query database for users to share with, which is everyone but the owner
  328.             // and those whom the image is already shared with.
  329.             $uid = self::getUid();
  330.             $query = "SELECT id,username FROM user WHERE id <> ".mysql_real_escape_string($uid)." AND id NOT IN (SELECT user_id FROM shared_image WHERE image_id = ".mysql_real_escape_string($iid).");";
  331.             $result = self::execute($query);
  332.  
  333.             if (mysql_num_rows($result) > 0) {
  334.                 while ($row = mysql_fetch_assoc($result)) {
  335.                     $users[] = new user($row['id'], $row['username']);
  336.                 }
  337.             } else {
  338.                 return "No users to share this with.";
  339.             }          
  340.  
  341.             return $users;
  342.         }
  343.         return false;
  344.     }
  345.  
  346.     // This function returns a list of users whom the given image is shared with.
  347.     // returns a list of users if successful, otherwise false
  348.     function sharedWith($iid){
  349.         if(self::isUserLoggedIn()) {
  350.             $users = array();
  351.            
  352.             $query = "SELECT id,username FROM user INNER JOIN shared_image ON id = user_id WHERE image_id = ".mysql_real_escape_string($iid).";";
  353.             $result = self::execute($query);
  354.  
  355.             if (mysql_num_rows($result) > 0) {
  356.                 while ($row = mysql_fetch_assoc($result)) {
  357.                     $users[] = new user($row['id'], $row['username']);
  358.                 }
  359.             }
  360.  
  361.             return $users;
  362.         }
  363.         return false;
  364.     }
  365.  
  366.     // This function saves the image to a file with the corresponding image id as the name.
  367.     // TODO: Find out how to handle the file permissions.
  368.     function save_image($img, $iid){
  369.         $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $img));
  370.         $file = self::$image_dir.$iid;
  371.         file_put_contents($file, $data);
  372.         chmod($file, 0777); // This works for now, but probably isn't necessary... right?
  373.     }
  374.  
  375.     // This function loads the image file with the corresponding image id.
  376.     // TODO: Find out how to handle the file permissions.
  377.     function loadImage($iid){
  378.         $file = self::$image_dir.$iid;
  379.         $type = pathinfo($file, PATHINFO_EXTENSION);   
  380.         $data = file_get_contents($file);
  381.         $img = 'data:image/' . $type . ';base64,' . base64_encode($data);      
  382.         return $img;
  383.     }
  384.  
  385.     // This function returns a list of all images shared with the loggedin user
  386.     // returns a list of images if successful, otherwise false
  387.     function getImages(){
  388.         if(self::isUserLoggedIn()){
  389.             $images = array();
  390.            
  391.             // The images to display should either be those owned by the user
  392.             // or those ahred with the user and should not be duplicated.
  393.             $uid = self::getUid();
  394.             $query = "SELECT DISTINCT image.id,owner_id,username,createdDate FROM image INNER JOIN user on user.id = owner_id LEFT JOIN shared_image ON image_id = image.id WHERE user_id = ".$uid." OR owner_id = ".$uid." ORDER BY createdDate DESC";
  395.             $result = self::execute($query);
  396.  
  397.             if (mysql_num_rows($result) > 0) {
  398.                 while ($row = mysql_fetch_assoc($result)) {
  399.                     $iid = $row['id'];
  400.                     $img = self::loadImage($iid);
  401.                     $images[] = new Image($iid, $row['owner_id'], $row['username'], $img, $row['createdDate']);
  402.                 }
  403.             }
  404.  
  405.             return $images;
  406.         }
  407.         return false;
  408.     }
  409.  
  410.     // This function returns the given image iff the loggedin user have access to it
  411.     // returns the image if successful, otherwise false
  412.     function getImage($iid)
  413.     {
  414.         if(self::isUserLoggedIn())
  415.         {
  416.             $uid = self::getUid();
  417.             $query = "SELECT image.id,owner_id,username,createdDate FROM image INNER JOIN user ON user.id = owner_id LEFT JOIN shared_image ON image_id = image.id WHERE (user_id = ".$uid." OR owner_id = ".$uid.") AND image.id = ".$iid.";";
  418.             $result = self::execute($query);
  419.            
  420.             if (mysql_num_rows($result) > 0) {
  421.                 $row = mysql_fetch_assoc($result);
  422.            
  423.                 $img = self::loadImage($iid);
  424.                 return new Image($iid, $row['owner_id'], $row['username'], $img, $row['createdDate']);
  425.             }
  426.             return null;
  427.         }
  428.  
  429.         return false;
  430.     }
  431.  
  432.     // This function will post given comment to given image iff the loggedin user has access to post
  433.     // returns true if successful, otherwise false
  434.     function comment($iid, $comment)
  435.     {
  436.         if(self::isUserLoggedIn() && self::verifyShare(self::getUid(), $iid))
  437.         {
  438.             $uid = self::getUid();
  439.             $query = "INSERT INTO post(text, user_id, image_id) VALUES ('".mysql_real_escape_string($comment)."',".mysql_real_escape_string($uid).",".mysql_real_escape_string($iid).")";
  440.             $result = self::execute($query);
  441.             return mysql_affected_rows() == 1;
  442.         }
  443.         return false;
  444.     }
  445.  
  446.     // This function gets all comments for the given image
  447.     // returns a list of comments if successful, otherwise false
  448.     function getComments($iid)
  449.     {
  450.         if(self::isUserLoggedIn() && self::verifyShare(self::getUid(), $iid))
  451.         {          
  452.             $comments = array();
  453.  
  454.             $query = "SELECT post.id,username,text,createdDate FROM post INNER JOIN user ON user_id = user.id WHERE image_id = ".mysql_real_escape_string($iid)." ORDER BY createdDate ASC;";
  455.             $result = self::execute($query);
  456.  
  457.             if (mysql_num_rows($result) > 0) {
  458.                 while ($row = mysql_fetch_assoc($result)) {
  459.                     // Only include verified comments
  460.                     $text = $row['text'];
  461.                     if ((self::verifyInput($text))) {
  462.                         $comments[] = new Comment($row['id'], $row['username'], $text, $row['createdDate']);
  463.                     }
  464.                 }
  465.             }
  466.  
  467.             return $comments;
  468.         }
  469.         return false;
  470.     }
  471.  
  472.     // This function checks if the loggedin user is owner of the given image
  473.     // returns true if the loggedin user is owner, otherwise false
  474.     function isOwner($iid){
  475.         $uid = self::getUid();
  476.         $query = "SELECT id FROM image WHERE owner_id = ".mysql_real_escape_string($uid)." AND id = ".mysql_real_escape_string($iid).";";
  477.         $result = self::execute($query);
  478.         return mysql_num_rows($result) > 0;
  479.     }
  480.  
  481.     // This function will verify whether the given user input is bad.
  482.     // This is to prevent malicious users from sending bad input, e.g. NULL,
  483.     // which would cause the MySQL service to crash.
  484.     // Returns true if no bad input is detected, otherwise false.
  485.     function verifyInput($input) {
  486.         $valid = !(eval('"'.$input.'"===NULL;') || eval('"'.$input.'"==="\0";'));
  487.         return $valid;
  488.     }
  489.  
  490.     // This function checks if the loggedin user is either owner or has access to the given image
  491.     // returns true if the loggedin user has access, otherwise false
  492.     function verifyShare($uid, $iid)
  493.     {
  494.         $query = "SELECT id FROM image LEFT JOIN shared_image ON image_id = id WHERE (user_id = ".mysql_real_escape_string($uid)." OR owner_id = ".mysql_real_escape_string($uid).") AND id = ".mysql_real_escape_string($iid).";";
  495.         $result = self::execute($query);
  496.         return mysql_num_rows($result) > 0;
  497.     }
  498.  
  499.     // This function retrieves the client IP
  500.     // Function to get the client ip address
  501.     function getClientIP() {
  502.         $ipaddress = '';
  503.         if ($_SERVER['HTTP_CLIENT_IP'])
  504.             $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
  505.         else if($_SERVER['HTTP_X_FORWARDED_FOR'])
  506.             $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
  507.         else if($_SERVER['HTTP_X_FORWARDED'])
  508.             $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
  509.         else if($_SERVER['HTTP_FORWARDED_FOR'])
  510.             $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
  511.         else if($_SERVER['HTTP_FORWARDED'])
  512.             $ipaddress = $_SERVER['HTTP_FORWARDED'];
  513.         else if($_SERVER['REMOTE_ADDR'])
  514.             $ipaddress = $_SERVER['REMOTE_ADDR'];
  515.         else
  516.             $ipaddress = 'UNKNOWN';
  517.  
  518.         return $ipaddress;
  519.     }
  520. }
  521.  
  522. class User{
  523.     private $_id;
  524.     private $_name;
  525.  
  526.     public function __construct($id, $name){
  527.         $this -> _id = $id;
  528.         $this -> _name = $name;
  529.     }
  530.  
  531.     public function getName(){ return $this -> _name; }
  532.     public function getId(){ return $this -> _id; }
  533. }
  534.  
  535. // This class is kind of obsolete, but still used.
  536. // Might be used in the future to, like, maybe store images in a database?
  537. class Image{
  538.  
  539.     private $_id;
  540.     private $_ownerId;
  541.     private $_image;
  542.     private $_username;
  543.     private $_datetime;
  544.  
  545.     public function __construct($id, $ownerId, $username, $image, $datetime){
  546.         $this -> _id = $id;
  547.         $this -> _ownerId = $ownerId;
  548.         $this -> _image = $image;
  549.         $this -> _username = $username;
  550.         $this -> _datetime = new DateTime($datetime);
  551.     }
  552.  
  553.     public function getId() { return $this -> _id; }
  554.     public function getOwnerId() { return $this -> _ownerId; }
  555.     public function getUser() { return $this -> _username; }
  556.     public function getImage() { return $this -> _image; }
  557.     public function getAge() {
  558.         $date = $this -> _datetime;
  559.         $currentDate = new DateTime();
  560.         $dateDiff = $date -> diff($currentDate);
  561.         $years = $dateDiff -> y;
  562.         $months = $dateDiff -> m;
  563.         $days = $dateDiff -> d;
  564.         $hours = $dateDiff -> h;
  565.         $minutes = $dateDiff -> i;
  566.         $seconds = $dateDiff -> s;
  567.  
  568.  
  569.         if($years > 1) return $years .' years';
  570.         if($years > 0) return $years .' year';
  571.         if($months > 1) return $months .' months';
  572.         if($months > 0) return $months .' month';
  573.         if($days > 1) return $days .' days';
  574.         if($days > 0) return $days .' day';
  575.         if($hours > 1) return $hours .' hours';
  576.         if($hours > 0) return $hours .' hour';
  577.         if($minutes > 1) return $minutes .' minutes';
  578.         if($minutes > 0) return $minutes .' minute';
  579.         if($seconds > 1) return $seconds .' seconds';
  580.         if($seconds >= 0) return $seconds .' second';
  581.         return "Error!";
  582.     }
  583. }
  584.  
  585. class Comment{
  586.     private $_id;
  587.     private $_userName;
  588.     private $_text;
  589.     private $_datetime;
  590.  
  591.     public function __construct($id, $userName, $text, $datetime){
  592.         $this -> _id = $id;
  593.         $this -> _userName = $userName;
  594.         $this -> _text = $text;
  595.         $this -> _datetime = new DateTime($datetime);
  596.     }
  597.  
  598.     public function getId() { return $this -> _id; }
  599.     public function getUser() { return $this -> _userName; }
  600.     public function getText() { return $this -> _text; }
  601.     public function getAge() {
  602.         $date = $this -> _datetime;
  603.         $currentDate = new DateTime();
  604.         $dateDiff = $date -> diff($currentDate);
  605.         $years = $dateDiff -> y;
  606.         $months = $dateDiff -> m;
  607.         $days = $dateDiff -> d;
  608.         $hours = $dateDiff -> h;
  609.         $minutes = $dateDiff -> i;
  610.         $seconds = $dateDiff -> s;
  611.  
  612.  
  613.         if($years > 1) return $years .' years';
  614.         if($years > 0) return $years .' year';
  615.         if($months > 1) return $months .' months';
  616.         if($months > 0) return $months .' month';
  617.         if($days > 1) return $days .' days';
  618.         if($days > 0) return $days .' day';
  619.         if($hours > 1) return $hours .' hours';
  620.         if($hours > 0) return $hours .' hour';
  621.         if($minutes > 1) return $minutes .' minutes';
  622.         if($minutes > 0) return $minutes .' minute';
  623.         if($seconds > 1) return $seconds .' seconds';
  624.         if($seconds >= 0) return $seconds .' second';
  625.         return "Error!";
  626.     }
  627. }
  628. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top