PriEco is a new search engine powered by Google, Bing and Mojeek. It is focused on Privacy, Security and Ecology. https://search.jojoyou.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
PriEco/index.php

217 lines
6.1 KiB

<!-- SPDX-FileCopyrightText: 2022, 2022-2022 Roman Láncoš <jojoyou@jojoyou.org> -->
<!-- -->
<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
<?php
//Development mode (Get search results from json files in ./Controller/dev folder)
$dev = true;
//Variable, controls reloading on settings change
$reload = false;
//Function to get string between characters
include 'Controller/functions/getsearch.php';
include 'Model/header.php';
//Prepare for search request with search engine APIs
include './Controller/database.php';
//Bangs
if (strpos($purl, '!') !== false) {
$bangData = file_get_contents('Controller/value/bangs.json');
$bangObj = json_decode($bangData, true);
$bangsSplit = explode(' ', $purl);
foreach ($bangsSplit as $bgS) {
if (strpos($bgS, '!') !== false) {
$bgS = str_replace('!', '', $bgS);
$i = 0;
foreach ($bangObj['bangs'] as $name => $value) {
if ($name == $bgS) {
$j = 0;
foreach ($bangObj['bangs'] as $pBang) {
if ($j == $i) {
$Rurl = str_replace('!' . $name . ' ', '', $purl);
header('Location: ' . $pBang . $Rurl);
exit();
} else {
$j++;
}
}
}
$i++;
}
}
}
}
//Get style.css file and post custom settings for light and dark mode
include 'Model/style.php';
if ($purl != null or $purl != '') {
//Check for img search and for empty query
$urlSet = explode('&', $urlSet);
for ($i = 1; $i < count($urlSet); $i++) {
if ($urlSet[$i] == 'image') {
$type = 'image';
}
if ($urlSet[$i] == 'video') {
$type = 'video';
}
if ($urlSet[$i] == 'news') {
$type = 'news';
}
if (strpos($urlSet[$i], 'imgsize=') !== false) {
$imgsize = str_replace('imgsize=', '', $urlSet[$i]);
}
if (strpos($urlSet[$i], 'imgcolor=') !== false) {
$imgcolor = str_replace('imgcolor=', '', $urlSet[$i]);
}
if (strpos($urlSet[$i], 'imgtype=') !== false) {
$imgtype = str_replace('imgtype=', '', $urlSet[$i]);
}
if (strpos($urlSet[$i], 'imgtime=') !== false) {
$imgtime = str_replace('imgtime=', '', $urlSet[$i]);
}
if (strpos($urlSet[$i], 'imglicence=') !== false) {
$imgright = str_replace('imglicence=', '', $urlSet[$i]);
}
if (strpos($urlSet[$i], 'pixabay') !== false) {
$pixabay = true;
}
}
if ($_POST['q'] != null) {
if ($_POST['q'] != $purl) {
header('Location: ./?' . $type . '&q=' . $_POST['q']);
exit();
}
}
//Set parameters for search request
if ($lang != $_COOKIE['Language'] && $_COOKIE['Language'] != null) {
$lang = $_COOKIE['Language'];
}
if ($local != $_COOKIE['Location'] && $_COOKIE['Location'] != null) {
$loc = $_COOKIE['Location'];
}
if ($loc == null) {
$user_ip = getenv('REMOTE_ADDR');
$geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip"));
$loc = strtolower($geo['geoplugin_countryCode']);
setcookie('Location', $loc, time() + (86400 * 360), '/');
}
$safe = $_COOKIE['safe'];
$time = $_COOKIE['time'];
$new = $_COOKIE['new'];
$mode = $_COOKIE['mode'];
$theme = $_COOKIE['theme'];
$dSug = $_COOKIE['DisSugges'];
$providers = $_COOKIE['providers'];
if ($safe == null) {
$safe = 'off';
}
if ($new == null) {
$new = 'off';
}
if ($imgsize == null) {
$imgsize = 'all';
}
if ($imgcolor == null) {
$imgcolor = 'all';
}
if ($imgtime == null) {
$imgtime = 'all';
}
if ($imgtype == null) {
$imgtype = 'all';
}
if ($imgright == null) {
$imgright = 'all';
}
switch ($time):
case 'day':
$date = 'd1';
break;
case 'week':
$date = 'w1';
break;
case 'month':
$date = 'm1';
break;
case 'year':
$date = 'y1';
break;
endswitch;
include 'Controller/retrieve.php';
//Get data from $PromoFile
$promodata = file_get_contents($PromoURL);
$promoobj = json_decode($promodata, true);
//indexLogic is here for saving settings
include 'Controller/functions/indexLogic.php';
//Get user from cookie and compare it with database
if ($_COOKIE['auth'] != null and $_COOKIE['auth'] != '') {
ini_set('session.cookie_domain', '.jojoyou.org');
session_start();
$auth = '▛' . $auth;
$possibleUsr = strstr($auth, '▛');
$possibleUsr = strstr($auth, ' ', true);
$possibleUsr = substr($possibleUsr, 3);
$authName = str_replace('▛' . $possibleUsr . ' ', '', $auth);
$sql = "SELECT * FROM JYS WHERE Username='$possibleUsr'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$authDB = explode(',', $row['Auth']);
foreach ($authDB as $a) {
if ($a == $authName) {
$usr = $row['Username'];
$usrSearches = $row['Searches'];
$_SESSION['usr'] = $usr;
continue;
}
}
}
$usr = $row['Username'];
$select_user = "SELECT * FROM JYS WHERE Username='$usr'";
$run_qry = mysqli_query($conn, $select_user);
if (mysqli_num_rows($run_qry) > 0) {
if ($row = mysqli_fetch_assoc($run_qry)) {
$usrSearches = $row['Searches'];
$usrSearches++;
$update_user = "UPDATE JYS SET Searches='$usrSearches' WHERE Username='$_SESSION[usr]'";
$run_qry = mysqli_query($conn, $update_user);
}
}
//Increase the number of total searches, file is located at ./searches.txt, if not it will be created
$file = 'searches.txt';
$counter = 1;
if (file_exists($file)) {
$counter += file_get_contents($file);
}
file_put_contents($file, $counter);
}
if($usr == null){
$usr = 'Guest';
}
//Create inputbox with settings
include 'Model/searchbox.php';
//Print output
include 'Controller/functions/output.php';
//Print share icons
include 'View/html/share.html';
//Print footer, contains JS for Ads
include 'Model/footer.php';
} else {
//Print mainpage
include 'Model/mainpage.php';
//Print footer, contains JS for Ads
include 'Model/footer.php';
}
?>