Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.30 KB | None | 0 0
  1. <?php
  2. class Core {
  3. public $db;
  4. public $domain;
  5. public $settings;
  6. public $language_array;
  7. public function getDomain() {
  8. return $this->domain;
  9. }
  10. function __construct($db,$domain) {
  11. $this->db = $db;
  12. $this->domain = $domain;
  13. $this->getSettings();
  14. $this->db->query('SET NAMES UTF8MB4');
  15. }
  16. public function getSettings() {
  17. $settings = $this->db->query("SELECT * FROM settings");
  18. $settings = $settings->fetch_object();
  19. $this->settings = $settings;
  20. }
  21. public function getPageName() {
  22. return basename($_SERVER['PHP_SELF']);
  23. }
  24. public function getLanguage() {
  25. $path = dirname(dirname(__FILE__));
  26. $language = $path.'/languages/english/language.php';
  27. require($language);
  28. $this->language_array = $lang;
  29. }
  30. public function translate($str) {
  31. return $this->language_array[$str];
  32. }
  33. }
  34. class Database extends Core {
  35. public function paginateQuery($query,$per_page,$count) {
  36. $last_page = ceil($count/$per_page);
  37. if(isset($_GET['page'])) { $p = $_GET['page']; } else { $p = 1; }
  38. if($p < 1) { $p = 1; } elseif($p > $last_page) { $p = $last_page; }
  39. $limit = 'LIMIT ' .($p - 1) * $per_page .',' .$per_page;
  40. $query.= " $limit";
  41. return array('query' => $query, 'last_page' => $last_page);
  42. }
  43. }
  44. class Geo extends Database {
  45. public function coordsToKm($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000) {
  46. $latFrom = deg2rad($latitudeFrom);
  47. $lonFrom = deg2rad($longitudeFrom);
  48. $latTo = deg2rad($latitudeTo);
  49. $lonTo = deg2rad($longitudeTo);
  50.  
  51. $lonDelta = $lonTo - $lonFrom;
  52. $a = pow(cos($latTo) * sin($lonDelta), 2) +
  53. pow(cos($latFrom) * sin($latTo) - sin($latFrom) * cos($latTo) * cos($lonDelta), 2);
  54. $b = sin($latFrom) * sin($latTo) + cos($latFrom) * cos($latTo) * cos($lonDelta);
  55.  
  56. $angle = atan2(sqrt($a), $b);
  57. return ($angle * $earthRadius)/1000;
  58. }
  59. public function reverseGeo() {
  60. $json = file_get_contents("https://www.geoip-db.com/json");
  61. return json_decode($json);
  62. }
  63. }
  64. class TimeHelper extends Geo {
  65. public function timeAgo($lang,$ptime) {
  66. $etime = time() - $ptime;
  67. if ($etime < 1)
  68. {
  69. return $this->translate('just_now');
  70. }
  71. $a = array( 365 * 24 * 60 * 60 => $this->translate('year'),
  72. 30 * 24 * 60 * 60 => $this->translate('month'),
  73. 24 * 60 * 60 => $this->translate('day'),
  74. 60 * 60 => $this->translate('hour'),
  75. 60 => $this->translate('minute'),
  76. 1 => $this->translate('second')
  77. );
  78. $a_plural = array( 'year' => $this->translate('years'),
  79. 'month' => $this->translate('months'),
  80. 'day' => $this->translate('days'),
  81. 'hour' => $this->translate('hours'),
  82. 'minute' => $this->translate('minutes'),
  83. 'second' => $this->translate('seconds')
  84. );
  85. foreach ($a as $secs => $str)
  86. {
  87. $d = $etime / $secs;
  88. if ($d >= 1)
  89. {
  90. $r = round($d);
  91. return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str).' '.$this->translate('ago');
  92. }
  93. }
  94. }
  95. }
  96. class Notification extends TimeHelper {
  97. public function NotificationCount($notification) {
  98. if($notification == 'liked_you') {
  99. $notifications = $this->db->query("SELECT COUNT(*) as count FROM profile_likes WHERE profile_id='".$this->data->id."' AND is_seen='0'");
  100. } elseif($notification == 'visited_you') {
  101. $notifications = $this->db->query("SELECT COUNT(*) as count FROM profile_views WHERE profile_id='".$this->data->id."' AND is_seen='0'");
  102. } elseif($notification == 'unread_messages') {
  103. $notifications = $this->db->query("SELECT COUNT(*) as count FROM messages WHERE (user1='".$this->data->id."' OR user2='".$this->data->id."') AND is_seen='0'");
  104. } elseif($notification == 'favorites') {
  105. $notifications = $this->db->query("SELECT COUNT(*) as count FROM profile_favorites WHERE profile_id='".$this->data->id."' AND is_seen='0'");
  106. }
  107. $notifications = $notifications->fetch_object();
  108. $count = $notifications->count;
  109. if($count > 0) {
  110. if(strlen($count) == 1) {
  111. return '<span class="notifications animated infinite flash badge"> <p class="one-digit">'.$count.'</p> </span>';
  112. } elseif(strlen($count) == 2) {
  113. return '<span class="notifications animated infinite flash badge"> <p class="two-digit">'.$count.'</p> </span>';
  114. }
  115. }
  116. }
  117. public function markAsSeen($notification,$id) {
  118. if($notification == 'liked_you') {
  119. $this->db->query("UPDATE profile_likes SET is_seen='1' WHERE id='".$id."'");
  120. } elseif($notification == 'visited_you') {
  121. $this->db->query("UPDATE profile_views SET is_seen='1' WHERE id='".$id."'");
  122. } elseif($notification == 'favorites') {
  123. $this->db->query("UPDATE profile_favorites SET is_seen='1' WHERE id='".$id."'");
  124. }
  125. }
  126. public function checkIfSeen($notification,$id) {
  127. if($notification == 'liked_you') {
  128. $query = $this->db->query("SELECT id FROM profile_likes WHERE id='".$id."' AND is_seen='1'");
  129. if($query->num_rows >= 1) {
  130. return true;
  131. } else {
  132. return false;
  133. }
  134. } elseif($notification == 'visited_you') {
  135. $query = $this->db->query("SELECT id FROM profile_views WHERE id='".$id."' AND is_seen='1'");
  136. if($query->num_rows >= 1) {
  137. return true;
  138. } else {
  139. return false;
  140. }
  141. } elseif($notification == 'favorites') {
  142. $query = $this->db->query("SELECT id FROM profile_favorites WHERE id='".$id."' AND is_seen='1'");
  143. if($query->num_rows >= 1) {
  144. return true;
  145. } else {
  146. return false;
  147. }
  148. }
  149. }
  150. }
  151. class Verification extends Notification {
  152. public function hasVerification($type,$user_id) {
  153. $query = $this->db->query("SELECT id FROM verifications WHERE type='".$type."' AND user_id='".$user_id."'");
  154. if($query->num_rows >= 1) {
  155. return true;
  156. } else {
  157. return false;
  158. }
  159. }
  160. }
  161. class Layout extends Verification {
  162. public function loadBlock($block,$var) {
  163. require_once('layout/blocks/'.$block.'.php');
  164. $content = ob_get_contents();
  165. return $content;
  166. }
  167. public function showLikeBtn($profile_id) {
  168. $check = $this->db->query("SELECT id FROM profile_likes
  169. WHERE viewer_id='".$profile_id."' AND profile_id='".$profile_id."'");
  170. $var['check'] = $check;
  171. echo $this->loadBlock('like_btn',$var);
  172. }
  173. public function showDislikeBtn($profile_id) {
  174. $check = $this->db->query("SELECT id FROM profile_dislikes
  175. WHERE viewer_id='".$profile_id."' AND profile_id='".$profile_id."'");
  176. $var['check'] = $check;
  177. echo $this->loadBlock('dislike_btn',$var);
  178. }
  179. public function showFavoriteBtn($profile_id) {
  180. $check = $this->db->query("SELECT id FROM profile_favorites
  181. WHERE viewer_id='".$profile_id."' AND profile_id='".$profile_id."'");
  182. $var['check'] = $check;
  183. echo $this->loadBlock('favorite_btn',$var);
  184. }
  185. public function showInviteFriends() {
  186. $people = $this->db->query("SELECT * FROM users
  187. WHERE profile_picture != '' ORDER BY RAND() LIMIT 3");
  188. $var['people'] = $people;
  189. echo $this->loadBlock('invite_friends',$var);
  190. }
  191. public function showVerifications($profile_id) {
  192. $verifications = $this->db->query("SELECT * FROM verifications
  193. WHERE user_id='".$profile_id."' AND is_active='1'");
  194. while($verification = $verifications->fetch_object()) {
  195. $var['verification'] = $verification;
  196. echo $this->loadBlock('single_verification',$var);
  197. }
  198. }
  199. public function showAwards($user_id) {
  200. $owned_awards = $this->db->query("SELECT id,award_id,time FROM owned_awards
  201. WHERE user_id='".$user_id."'");
  202. while($owned_award = $owned_awards->fetch_object()) {
  203. $award = $this->db->query("SELECT * FROM awards
  204. WHERE id='".$owned_award->award_id."'");
  205. $award = $award->fetch_object();
  206. $time = $owned_award->time;
  207. $var['award'] = $award;
  208. $var['owned_award'] = $owned_award;
  209. $var['user_id'] = $user_id;
  210. $var = array('user_id' => $user_id, 'award' => $award, 'time' => $time);
  211. echo $this->loadBlock('single_award',$var);
  212. }
  213. }
  214. public function showFooterPages() {
  215. $pages = $this->db->query("SELECT * FROM pages ORDER BY id ASC");
  216. if($pages->num_rows >= 1) {
  217. while($page = $pages->fetch_object()) {
  218. echo '<li> <a href="'.$this->domain.'/page/'.$page->id.'"> '.$page->page_title.' </a> </li>';
  219. }
  220. }
  221. }
  222. }
  223. class User extends Geo {
  224. public $data;
  225. function __construct($db,$domain,$user_id) {
  226. parent::__construct($db,$domain);
  227. $this->getLanguage();
  228. $user = $this->db->query("SELECT * FROM users WHERE id='".$user_id."'");
  229. if($user->num_rows >= 1) {
  230. $user = $user->fetch_object();
  231. $this->data = $user;
  232. }
  233. }
  234. public function markActivity() {
  235. $this->db->query("UPDATE users SET last_active='".time()."' WHERE id='".$this->data->id."'");
  236. }
  237. public function isVerified() {
  238. if($this->data->is_verified == 1) {
  239. return true;
  240. } else {
  241. return false;
  242. }
  243. }
  244. public function hasSuperPowers($user_object) {
  245. if($this->data->has_superpowers == 1 || $this->data->superpowers_expiration > time()) {
  246. return true;
  247. } else {
  248. return false;
  249. }
  250. }
  251. public function getBadges() {
  252. if($this->isVerified($this->data)) {
  253. echo '<a class="btn btn-info btn-xs btn-fill btn-icon profile-badge btn-tooltip"><i class="icon icon-checkmark"></i></a>';
  254. echo '<div class="hidden"> This profile is verified </div>';
  255. }
  256. if($this->hasSuperPowers($this->data)) {
  257. echo '
  258. <div class="superman-svg profile-badge btn-tooltip">
  259. <a class="btn btn-warning btn-xs btn-icon">
  260. <object data="'.$this->domain.'/img/superman-clean.svg" type="image/svg+xml"></object>
  261. </a>
  262. </div>';
  263. echo '<div class="hidden"> Super Powered Girl! </div>';
  264. }
  265. }
  266. public function getPhotos($limit=false) {
  267. if(!is_numeric($limit)) {
  268. $limit = '';
  269. } else {
  270. $limit = 'LIMIT '.$limit;
  271. }
  272. return $this->db->query("SELECT * FROM uploaded_photos WHERE user_id='".$this->data->id."' ".$limit." ");
  273. }
  274. public function OnlineStatus() {
  275. if(time()-$this->data->last_active <= 300) {
  276. return true;
  277. } else {
  278. return false;
  279. }
  280. }
  281. public function getScore() {
  282. $user_id = $this->data->id;
  283. $likes = $this->db->query("SELECT id FROM profile_likes WHERE profile_id='".$user_id."'");
  284. $likes = $likes->num_rows;
  285. $dislikes = $this->db->query("SELECT id FROM profile_dislikes WHERE profile_id='".$user_id."'");
  286. $dislikes = $dislikes->num_rows;
  287. $total = ($likes+$dislikes);
  288. $percentage = ($likes/$total);
  289. $result = new stdClass();
  290. $result->likes = $likes;
  291. $result->dislikes = $dislikes;
  292. $result->total = $total;
  293. $result->percentage = $percentage;
  294. $display_value = number_format($percentage*10,1);
  295. if(strlen($display_value) == 2) {
  296. $result->class = 'one-digit';
  297. } elseif(strlen($display_value) == 3) {
  298. $result->class = 'two-digit';
  299. } elseif(strlen($display_value) == 4) {
  300. $result->class = 'three-digit';
  301. }
  302. $result->display_value = $display_value;
  303. if(strtolower($display_value) == 'nan') {
  304. $result->display_value = '0.0';
  305. $result->class = 'two-digit';
  306. }
  307. return $result;
  308. }
  309. public function commonInterests($user2) {
  310. $user1 = $this->data->id;
  311. $common = $this->db->query("
  312. SELECT * FROM interests AS user1
  313. JOIN interests AS user2
  314. WHERE user1.name = user2.name AND (user1.user_id='".$user1."'
  315. AND user2.user_id='".$user2."') GROUP BY user1.name");
  316. return $common->num_rows;
  317. }
  318. public function unlockText($trigger,$content,$profile_id) {
  319. if($this->data->id == $profile_id) {
  320. return $content;
  321. } else {
  322. if($trigger == 'work_and_education') {
  323. if(empty($this->data->work) || empty($this->data->education)) {
  324. return substr($content,0,6).'<span class="full-text">'.substr($content,6).'</span>
  325. <span class="show-text" data-toggle="modal" data-target="#unlock-education">Show all</span>';
  326. } else {
  327. return $content;
  328. }
  329. } else {
  330. return $content;
  331. }
  332. }
  333. }
  334. public function getGenderInterest() {
  335. if($this->data->sexuality == 'Straight' && $this->data->gender == 'Male') {
  336. return ''.$this->translate('Girls').'';
  337. } elseif($this->data->sexuality == 'Gay' && $this->data->gender == 'Male') {
  338. return ''.$this->translate('Boys').'';
  339. } elseif($this->data->sexuality == 'Straight' && $this->data->gender == 'Female') {
  340. return ''.$this->translate('Boys').'';
  341. } elseif($this->data->sexuality == 'Lesbian' && $this->data->gender == 'Female') {
  342. return ''.$this->translate('Girls').'';
  343. } else {
  344. return ''.$this->translate('People').'';
  345. }
  346. }
  347. public function randomProfilePicture() {
  348. $interest = $this->data->sexual_interest;
  349. if($interest == 1) {
  350. $users = $this->db->query("SELECT * FROM users WHERE gender='Male' ORDER BY RAND() LIMIT 1");
  351. } elseif($interest == 2) {
  352. $users = $this->db->query("SELECT * FROM users WHERE gender='Female' ORDER BY RAND() LIMIT 1");
  353. } else {
  354. $users = $this->db->query("SELECT * FROM users ORDER BY RAND() LIMIT 1");
  355. }
  356. while($user = $users->fetch_object()) {
  357. return $this->getProfilePicture($user);
  358. }
  359. }
  360. function getInterests() {
  361. return $this->db->query("SELECT * FROM interests WHERE user_id='".$this->data->id."' GROUP BY name ORDER BY id ASC");
  362. }
  363. public function convertHereTo() {
  364. $here_to = $this->data->here_to;
  365. switch ($here_to) {
  366. case 1:
  367. return ''.$this->translate('Here_Friends').'';
  368. break;
  369. case 2:
  370. return ''.$this->translate('Here_Chat').'';
  371. break;
  372. case 3:
  373. return ''.$this->translate('Here_Date').'';
  374. break;
  375. default:
  376. return ''.$this->translate('Here_Friends').'';
  377. break;
  378. }
  379. }
  380. public function convertAge() {
  381. $starttime = $this->data->birthday;
  382. $endtime = time();
  383. $age = date('Y',$endtime) - date('Y',$starttime);
  384. if(date('z',$endtime) < date('z',$starttime)) {
  385. $age--;
  386. }
  387. return $age;
  388. }
  389. public function emptyText($show, $text) {
  390. if(empty($text)) {
  391. echo $show;
  392. } else {
  393. echo $text;
  394. }
  395. }
  396. public function getDistance($user2,$format=true) {
  397. if($this->data->country == $user2->country) {
  398. $distance = $this->coordsToKm($this->data->latitude,$this->data->longitude,$user2->latitude,$user2->longitude);
  399. if($distance > 0) {
  400. if($format == true) {
  401. $distance = '~'.sprintf($this->translate('km_away'),ceil($distance)).'';
  402. } else {
  403. $distance = ceil($distance);
  404. }
  405. } else {
  406. $distance = $user2->city;
  407. }
  408. } else {
  409. $distance = $user2->city;
  410. }
  411. return $distance;
  412. }
  413. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement