Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Core {
- public $db;
- public $domain;
- public $settings;
- public $language_array;
- public function getDomain() {
- return $this->domain;
- }
- function __construct($db,$domain) {
- $this->db = $db;
- $this->domain = $domain;
- $this->getSettings();
- $this->db->query('SET NAMES UTF8MB4');
- }
- public function getSettings() {
- $settings = $this->db->query("SELECT * FROM settings");
- $settings = $settings->fetch_object();
- $this->settings = $settings;
- }
- public function getPageName() {
- return basename($_SERVER['PHP_SELF']);
- }
- public function getLanguage() {
- $path = dirname(dirname(__FILE__));
- $language = $path.'/languages/english/language.php';
- require($language);
- $this->language_array = $lang;
- }
- public function translate($str) {
- return $this->language_array[$str];
- }
- }
- class Database extends Core {
- public function paginateQuery($query,$per_page,$count) {
- $last_page = ceil($count/$per_page);
- if(isset($_GET['page'])) { $p = $_GET['page']; } else { $p = 1; }
- if($p < 1) { $p = 1; } elseif($p > $last_page) { $p = $last_page; }
- $limit = 'LIMIT ' .($p - 1) * $per_page .',' .$per_page;
- $query.= " $limit";
- return array('query' => $query, 'last_page' => $last_page);
- }
- }
- class Geo extends Database {
- public function coordsToKm($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000) {
- $latFrom = deg2rad($latitudeFrom);
- $lonFrom = deg2rad($longitudeFrom);
- $latTo = deg2rad($latitudeTo);
- $lonTo = deg2rad($longitudeTo);
- $lonDelta = $lonTo - $lonFrom;
- $a = pow(cos($latTo) * sin($lonDelta), 2) +
- pow(cos($latFrom) * sin($latTo) - sin($latFrom) * cos($latTo) * cos($lonDelta), 2);
- $b = sin($latFrom) * sin($latTo) + cos($latFrom) * cos($latTo) * cos($lonDelta);
- $angle = atan2(sqrt($a), $b);
- return ($angle * $earthRadius)/1000;
- }
- public function reverseGeo() {
- $json = file_get_contents("https://www.geoip-db.com/json");
- return json_decode($json);
- }
- }
- class TimeHelper extends Geo {
- public function timeAgo($lang,$ptime) {
- $etime = time() - $ptime;
- if ($etime < 1)
- {
- return $this->translate('just_now');
- }
- $a = array( 365 * 24 * 60 * 60 => $this->translate('year'),
- 30 * 24 * 60 * 60 => $this->translate('month'),
- 24 * 60 * 60 => $this->translate('day'),
- 60 * 60 => $this->translate('hour'),
- 60 => $this->translate('minute'),
- 1 => $this->translate('second')
- );
- $a_plural = array( 'year' => $this->translate('years'),
- 'month' => $this->translate('months'),
- 'day' => $this->translate('days'),
- 'hour' => $this->translate('hours'),
- 'minute' => $this->translate('minutes'),
- 'second' => $this->translate('seconds')
- );
- foreach ($a as $secs => $str)
- {
- $d = $etime / $secs;
- if ($d >= 1)
- {
- $r = round($d);
- return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str).' '.$this->translate('ago');
- }
- }
- }
- }
- class Notification extends TimeHelper {
- public function NotificationCount($notification) {
- if($notification == 'liked_you') {
- $notifications = $this->db->query("SELECT COUNT(*) as count FROM profile_likes WHERE profile_id='".$this->data->id."' AND is_seen='0'");
- } elseif($notification == 'visited_you') {
- $notifications = $this->db->query("SELECT COUNT(*) as count FROM profile_views WHERE profile_id='".$this->data->id."' AND is_seen='0'");
- } elseif($notification == 'unread_messages') {
- $notifications = $this->db->query("SELECT COUNT(*) as count FROM messages WHERE (user1='".$this->data->id."' OR user2='".$this->data->id."') AND is_seen='0'");
- } elseif($notification == 'favorites') {
- $notifications = $this->db->query("SELECT COUNT(*) as count FROM profile_favorites WHERE profile_id='".$this->data->id."' AND is_seen='0'");
- }
- $notifications = $notifications->fetch_object();
- $count = $notifications->count;
- if($count > 0) {
- if(strlen($count) == 1) {
- return '<span class="notifications animated infinite flash badge"> <p class="one-digit">'.$count.'</p> </span>';
- } elseif(strlen($count) == 2) {
- return '<span class="notifications animated infinite flash badge"> <p class="two-digit">'.$count.'</p> </span>';
- }
- }
- }
- public function markAsSeen($notification,$id) {
- if($notification == 'liked_you') {
- $this->db->query("UPDATE profile_likes SET is_seen='1' WHERE id='".$id."'");
- } elseif($notification == 'visited_you') {
- $this->db->query("UPDATE profile_views SET is_seen='1' WHERE id='".$id."'");
- } elseif($notification == 'favorites') {
- $this->db->query("UPDATE profile_favorites SET is_seen='1' WHERE id='".$id."'");
- }
- }
- public function checkIfSeen($notification,$id) {
- if($notification == 'liked_you') {
- $query = $this->db->query("SELECT id FROM profile_likes WHERE id='".$id."' AND is_seen='1'");
- if($query->num_rows >= 1) {
- return true;
- } else {
- return false;
- }
- } elseif($notification == 'visited_you') {
- $query = $this->db->query("SELECT id FROM profile_views WHERE id='".$id."' AND is_seen='1'");
- if($query->num_rows >= 1) {
- return true;
- } else {
- return false;
- }
- } elseif($notification == 'favorites') {
- $query = $this->db->query("SELECT id FROM profile_favorites WHERE id='".$id."' AND is_seen='1'");
- if($query->num_rows >= 1) {
- return true;
- } else {
- return false;
- }
- }
- }
- }
- class Verification extends Notification {
- public function hasVerification($type,$user_id) {
- $query = $this->db->query("SELECT id FROM verifications WHERE type='".$type."' AND user_id='".$user_id."'");
- if($query->num_rows >= 1) {
- return true;
- } else {
- return false;
- }
- }
- }
- class Layout extends Verification {
- public function loadBlock($block,$var) {
- require_once('layout/blocks/'.$block.'.php');
- $content = ob_get_contents();
- return $content;
- }
- public function showLikeBtn($profile_id) {
- $check = $this->db->query("SELECT id FROM profile_likes
- WHERE viewer_id='".$profile_id."' AND profile_id='".$profile_id."'");
- $var['check'] = $check;
- echo $this->loadBlock('like_btn',$var);
- }
- public function showDislikeBtn($profile_id) {
- $check = $this->db->query("SELECT id FROM profile_dislikes
- WHERE viewer_id='".$profile_id."' AND profile_id='".$profile_id."'");
- $var['check'] = $check;
- echo $this->loadBlock('dislike_btn',$var);
- }
- public function showFavoriteBtn($profile_id) {
- $check = $this->db->query("SELECT id FROM profile_favorites
- WHERE viewer_id='".$profile_id."' AND profile_id='".$profile_id."'");
- $var['check'] = $check;
- echo $this->loadBlock('favorite_btn',$var);
- }
- public function showInviteFriends() {
- $people = $this->db->query("SELECT * FROM users
- WHERE profile_picture != '' ORDER BY RAND() LIMIT 3");
- $var['people'] = $people;
- echo $this->loadBlock('invite_friends',$var);
- }
- public function showVerifications($profile_id) {
- $verifications = $this->db->query("SELECT * FROM verifications
- WHERE user_id='".$profile_id."' AND is_active='1'");
- while($verification = $verifications->fetch_object()) {
- $var['verification'] = $verification;
- echo $this->loadBlock('single_verification',$var);
- }
- }
- public function showAwards($user_id) {
- $owned_awards = $this->db->query("SELECT id,award_id,time FROM owned_awards
- WHERE user_id='".$user_id."'");
- while($owned_award = $owned_awards->fetch_object()) {
- $award = $this->db->query("SELECT * FROM awards
- WHERE id='".$owned_award->award_id."'");
- $award = $award->fetch_object();
- $time = $owned_award->time;
- $var['award'] = $award;
- $var['owned_award'] = $owned_award;
- $var['user_id'] = $user_id;
- $var = array('user_id' => $user_id, 'award' => $award, 'time' => $time);
- echo $this->loadBlock('single_award',$var);
- }
- }
- public function showFooterPages() {
- $pages = $this->db->query("SELECT * FROM pages ORDER BY id ASC");
- if($pages->num_rows >= 1) {
- while($page = $pages->fetch_object()) {
- echo '<li> <a href="'.$this->domain.'/page/'.$page->id.'"> '.$page->page_title.' </a> </li>';
- }
- }
- }
- }
- class User extends Geo {
- public $data;
- function __construct($db,$domain,$user_id) {
- parent::__construct($db,$domain);
- $this->getLanguage();
- $user = $this->db->query("SELECT * FROM users WHERE id='".$user_id."'");
- if($user->num_rows >= 1) {
- $user = $user->fetch_object();
- $this->data = $user;
- }
- }
- public function markActivity() {
- $this->db->query("UPDATE users SET last_active='".time()."' WHERE id='".$this->data->id."'");
- }
- public function isVerified() {
- if($this->data->is_verified == 1) {
- return true;
- } else {
- return false;
- }
- }
- public function hasSuperPowers($user_object) {
- if($this->data->has_superpowers == 1 || $this->data->superpowers_expiration > time()) {
- return true;
- } else {
- return false;
- }
- }
- public function getBadges() {
- if($this->isVerified($this->data)) {
- echo '<a class="btn btn-info btn-xs btn-fill btn-icon profile-badge btn-tooltip"><i class="icon icon-checkmark"></i></a>';
- echo '<div class="hidden"> This profile is verified </div>';
- }
- if($this->hasSuperPowers($this->data)) {
- echo '
- <div class="superman-svg profile-badge btn-tooltip">
- <a class="btn btn-warning btn-xs btn-icon">
- <object data="'.$this->domain.'/img/superman-clean.svg" type="image/svg+xml"></object>
- </a>
- </div>';
- echo '<div class="hidden"> Super Powered Girl! </div>';
- }
- }
- public function getPhotos($limit=false) {
- if(!is_numeric($limit)) {
- $limit = '';
- } else {
- $limit = 'LIMIT '.$limit;
- }
- return $this->db->query("SELECT * FROM uploaded_photos WHERE user_id='".$this->data->id."' ".$limit." ");
- }
- public function OnlineStatus() {
- if(time()-$this->data->last_active <= 300) {
- return true;
- } else {
- return false;
- }
- }
- public function getScore() {
- $user_id = $this->data->id;
- $likes = $this->db->query("SELECT id FROM profile_likes WHERE profile_id='".$user_id."'");
- $likes = $likes->num_rows;
- $dislikes = $this->db->query("SELECT id FROM profile_dislikes WHERE profile_id='".$user_id."'");
- $dislikes = $dislikes->num_rows;
- $total = ($likes+$dislikes);
- $percentage = ($likes/$total);
- $result = new stdClass();
- $result->likes = $likes;
- $result->dislikes = $dislikes;
- $result->total = $total;
- $result->percentage = $percentage;
- $display_value = number_format($percentage*10,1);
- if(strlen($display_value) == 2) {
- $result->class = 'one-digit';
- } elseif(strlen($display_value) == 3) {
- $result->class = 'two-digit';
- } elseif(strlen($display_value) == 4) {
- $result->class = 'three-digit';
- }
- $result->display_value = $display_value;
- if(strtolower($display_value) == 'nan') {
- $result->display_value = '0.0';
- $result->class = 'two-digit';
- }
- return $result;
- }
- public function commonInterests($user2) {
- $user1 = $this->data->id;
- $common = $this->db->query("
- SELECT * FROM interests AS user1
- JOIN interests AS user2
- WHERE user1.name = user2.name AND (user1.user_id='".$user1."'
- AND user2.user_id='".$user2."') GROUP BY user1.name");
- return $common->num_rows;
- }
- public function unlockText($trigger,$content,$profile_id) {
- if($this->data->id == $profile_id) {
- return $content;
- } else {
- if($trigger == 'work_and_education') {
- if(empty($this->data->work) || empty($this->data->education)) {
- return substr($content,0,6).'<span class="full-text">'.substr($content,6).'</span>
- <span class="show-text" data-toggle="modal" data-target="#unlock-education">Show all</span>';
- } else {
- return $content;
- }
- } else {
- return $content;
- }
- }
- }
- public function getGenderInterest() {
- if($this->data->sexuality == 'Straight' && $this->data->gender == 'Male') {
- return ''.$this->translate('Girls').'';
- } elseif($this->data->sexuality == 'Gay' && $this->data->gender == 'Male') {
- return ''.$this->translate('Boys').'';
- } elseif($this->data->sexuality == 'Straight' && $this->data->gender == 'Female') {
- return ''.$this->translate('Boys').'';
- } elseif($this->data->sexuality == 'Lesbian' && $this->data->gender == 'Female') {
- return ''.$this->translate('Girls').'';
- } else {
- return ''.$this->translate('People').'';
- }
- }
- public function randomProfilePicture() {
- $interest = $this->data->sexual_interest;
- if($interest == 1) {
- $users = $this->db->query("SELECT * FROM users WHERE gender='Male' ORDER BY RAND() LIMIT 1");
- } elseif($interest == 2) {
- $users = $this->db->query("SELECT * FROM users WHERE gender='Female' ORDER BY RAND() LIMIT 1");
- } else {
- $users = $this->db->query("SELECT * FROM users ORDER BY RAND() LIMIT 1");
- }
- while($user = $users->fetch_object()) {
- return $this->getProfilePicture($user);
- }
- }
- function getInterests() {
- return $this->db->query("SELECT * FROM interests WHERE user_id='".$this->data->id."' GROUP BY name ORDER BY id ASC");
- }
- public function convertHereTo() {
- $here_to = $this->data->here_to;
- switch ($here_to) {
- case 1:
- return ''.$this->translate('Here_Friends').'';
- break;
- case 2:
- return ''.$this->translate('Here_Chat').'';
- break;
- case 3:
- return ''.$this->translate('Here_Date').'';
- break;
- default:
- return ''.$this->translate('Here_Friends').'';
- break;
- }
- }
- public function convertAge() {
- $starttime = $this->data->birthday;
- $endtime = time();
- $age = date('Y',$endtime) - date('Y',$starttime);
- if(date('z',$endtime) < date('z',$starttime)) {
- $age--;
- }
- return $age;
- }
- public function emptyText($show, $text) {
- if(empty($text)) {
- echo $show;
- } else {
- echo $text;
- }
- }
- public function getDistance($user2,$format=true) {
- if($this->data->country == $user2->country) {
- $distance = $this->coordsToKm($this->data->latitude,$this->data->longitude,$user2->latitude,$user2->longitude);
- if($distance > 0) {
- if($format == true) {
- $distance = '~'.sprintf($this->translate('km_away'),ceil($distance)).'';
- } else {
- $distance = ceil($distance);
- }
- } else {
- $distance = $user2->city;
- }
- } else {
- $distance = $user2->city;
- }
- return $distance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement