Subversion Repositories cheapmusic

Rev

Rev 97 | Rev 104 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 97 Rev 99
Line 11... Line 11...
11
include_once ('php/walmart.php');
11
include_once ('php/walmart.php');
12
include_once ('php/itunes.php');
12
include_once ('php/itunes.php');
13
include_once ('php/amazon.php');
13
include_once ('php/amazon.php');
14
include_once ('php/amazon_scrape.php');
14
include_once ('php/amazon_scrape.php');
15
include_once ('php/impact.php');
15
include_once ('php/impact.php');
-
 
16
include_once ('php/sessions_db.php');
16
 
17
 
17
error_reporting(E_ALL);
18
error_reporting(E_ALL);
18
 
19
 
19
// search
20
// search
20
function performSearch() {
21
function performSearch() {
Line 33... Line 34...
33
    updatePbFile();
34
    updatePbFile();
34
 
35
 
35
    $_SESSION["currentView"] = 'All';
36
    $_SESSION["currentView"] = 'All';
36
    $_SESSION["currentLayout"] = 'TableView';
37
    $_SESSION["currentLayout"] = 'TableView';
37
    $_SESSION["resultArr"] = [];
38
    $_SESSION["resultArr"] = [];
-
 
39
    expireSearchCache();
38
    $_SESSION["resultArr"] = searchAll($_SESSION["searchTerm"]);
40
    $_SESSION["resultArr"] = searchAll($_SESSION["searchTerm"]);
39
 
41
 
40
verifyResultArr();
42
    verifyResultArr();
41
 
43
 
42
    updatePbFile();
44
    updatePbFile();
43
 
45
 
44
    $_SESSION["resultArr"] = applySearchFilter($_SESSION["resultArr"]);
46
    $_SESSION["resultArr"] = applySearchFilter($_SESSION["resultArr"]);
45
    updatePbFile();
47
    updatePbFile();
Line 1498... Line 1500...
1498
    return ($a['score'] > $b['score']);
1500
    return ($a['score'] > $b['score']);
1499
}
1501
}
1500
 
1502
 
1501
function my_error_log($msg) {
1503
function my_error_log($msg) {
1502
    error_log("[" . date("d-M-Y H:m:s") . "] " . $msg . PHP_EOL, 3, $_SERVER['DOCUMENT_ROOT'] . "/../MyFiles/logs/my_php_error.log");
1504
    error_log("[" . date("d-M-Y H:m:s") . "] " . $msg . PHP_EOL, 3, $_SERVER['DOCUMENT_ROOT'] . "/../MyFiles/logs/my_php_error.log");
-
 
1505
}
-
 
1506
 
-
 
1507
function saveSearchCache($vendor, $query, $subquery, $text) {
-
 
1508
    $conn = MySessionHandler::getDBSessionId();
-
 
1509
 
-
 
1510
    $created = mysqli_real_escape_string($conn, time());
-
 
1511
    $v = mysqli_real_escape_string($conn, $vendor);
-
 
1512
    $q = mysqli_real_escape_string($conn, $query);
-
 
1513
    $s = mysqli_real_escape_string($conn, $subquery);
-
 
1514
    $r = base64_encode(gzencode($text));
-
 
1515
 
-
 
1516
    $sql = "INSERT
-
 
1517
                INTO searchCache
-
 
1518
                (created, vendor, query, subquery, result)
-
 
1519
                VALUES ('$created', '$v', '$q', '$s', '$r')";
-
 
1520
 
-
 
1521
    if (!($result = mysqli_query($conn, $sql))) {
-
 
1522
        error_log("MySQL Write SearchCache Error: " . mysqli_error($conn) . " (" . mysqli_errno($conn) . ")");
-
 
1523
    }
-
 
1524
 
-
 
1525
    return $result;
-
 
1526
}
-
 
1527
 
-
 
1528
 
-
 
1529
function expireSearchCache() {
-
 
1530
    $conn = MySessionHandler::getDBSessionId();
-
 
1531
    $t = MySessionHandler::getDBExpirationTime();
-
 
1532
 
-
 
1533
    $expired = mysqli_real_escape_string($conn, time() - $t);
-
 
1534
 
-
 
1535
    $sql = "DELETE
-
 
1536
                FROM searchCache
-
 
1537
                WHERE created < $expired";
-
 
1538
 
-
 
1539
    if (!($result = mysqli_query($conn, $sql))) {
-
 
1540
        error_log("MySQL Delete SearchCache Error: " . mysqli_error($conn) . " (" . mysqli_errno($conn) . ")");
-
 
1541
    }
-
 
1542
}
-
 
1543
 
-
 
1544
function getSearchCache($vendor, $query, $subquery) {
-
 
1545
    $conn = MySessionHandler::getDBSessionId();
-
 
1546
 
-
 
1547
    $v = mysqli_real_escape_string($conn, $vendor);
-
 
1548
    $q = mysqli_real_escape_string($conn, $query);
-
 
1549
    $s = mysqli_real_escape_string($conn, $subquery);
-
 
1550
    $sql = "select result from searchCache where vendor = '$v' and query = '$q' and subquery = '$s'";
-
 
1551
    $conn = MySessionHandler::getDBSessionId();
-
 
1552
 
-
 
1553
    if ($result = mysqli_query($conn, $sql)) {
-
 
1554
        if (mysqli_num_rows($result) == 1) {
-
 
1555
            if ($row = mysqli_fetch_assoc($result)) {
-
 
1556
                return gzdecode(base64_decode($row["result"]));
-
 
1557
            }
-
 
1558
        }
-
 
1559
    }
-
 
1560
    else if (mysqli_errno($conn)) {
-
 
1561
        error_log("MySQL Read SearchCache SQL: " . $sql);
-
 
1562
        error_log("MySQL Read SearchCache Error: " . mysqli_error($conn) . " (" . mysqli_errno($conn) . ")");
-
 
1563
    }
-
 
1564
 
-
 
1565
    return false;
1503
}
1566
}