Retrieve live results from your database. It automatically fetches and sorts as you type, with search string preview. Created this for a new feature we're rolling out soon.
Open themes/header.php and add:
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
Create as gallery.php
Create as ajax_gallery.php - Again, fit it into a stock TTv3 file and strip the HTML. Works as is. No need for the dinosaur block functions.
What it looks like on my end:
[ATTACH type="full" width="595px" alt="spotlight1.png"]5427[/ATTACH]
[ATTACH type="full" width="595px" alt="spotlight2.png"]5428[/ATTACH]
*** Remove ALL statements of "cover1" in code, it is custom to my table.
*** Wrap ALL PHP code in gallery.php in begin_frame() - end_frame() if needed. I don't use it.
Open themes/header.php and add:
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
Create as gallery.php
<?
require_once("backend/functions.php");
dbconn();
stdhead(T_("SPOTLIGHT"));
begin_frame("");
?>
<h1 itemprop="name">
<i class="material-icons">star</i> Spotlight
</h1>
<script type="text/javascript">
$(document).ready(function() {
$("#cd-name").keyup(function() {
var a = $(this).val().trim();
if ("" != a) {
$("#uname_response").show();
$.ajax({
url: "https://WEBSITE.com/ajax_gallery.php",
type: "post",
data: {
username: a
},
success: function(a) {
$("#uname_response").html(a);
$(".comments").hide();
}
});
} else $("#uname_response").hide();
$(".comments").show();
});
});
</script>
<div style="padding-left:40px">
<form class="cd-form floating-labels">
<fieldset>
<div class="icon">
<label class="cd-label" for="cd-name">History (beta)</label>
<input class="user" type="text" name="username" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" id="cd-name" placeholder="Search Spotlight History">
</div>
</fieldset>
</form>
</div>
<!-- AJAX Search/Response -->
<center>
<div id="uname_response"></div>
</center>
<br />
<br />
<!-- Spotlight Section -->
<div class="card-action ng-scope" ng-if="item.comment_count">
<!-- interactionCount -->
<span itemprop="interactionCount" class="comments">
<h1 itemprop="name" style="text-align:center;padding-bottom:23px">
Last 50
</h1>
<center>
<?
// Include database
$dsn = 'mysql:dbname=database;host=localhost;charset=utf8';
$user = 'username;
$password = 'password';
try {
$db = new PDO($dsn, $user, $password);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // Prevent advanced injection by disabling emulated prepared statements
$resultlimit = 50;
$query = $db->prepare("SELECT * FROM torrents ORDER BY id DESC LIMIT :resultlimit");
$query->bindParam(":resultlimit", $limit, PDO::PARAM_INT);
if ($query->execute()) {
while ($row = $query->fetch()) {
echo "<a href='$site_config[SITEURL]/torrents-details.php?id=$row[id]'/><img src='$site_config[SITEURL]/images/covers/$row[image1]' style='width:107px;height:176px;margin-right:6px' /></a>";
}
}
die();
}
catch (PDOException $e) {
echo "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
</center>
</span>
</div>
<? end_frame(); stdfoot(); ?>Create as ajax_gallery.php - Again, fit it into a stock TTv3 file and strip the HTML. Works as is. No need for the dinosaur block functions.
<?
// Include database
$dsn = 'mysql:dbname=database;host=localhost;charset=utf8';
$user = 'username;
$password = 'password';
// Gallery search - April 7, 2020
try {
$db = new PDO($dsn, $user, $password);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // Prevent advanced injection by disabling emulated prepared statements
if (!empty($_POST['username'])) {
$resultlimit = 50;
$searchTerm = $_POST["username"];
$query = $db->prepare("SELECT * FROM torrents WHERE name LIKE :searchword LIMIT :resultlimit");
$query->bindValue(':searchword', '%' . $searchTerm . '%');
$query->bindParam(":resultlimit", $limit, PDO::PARAM_INT);
$result = $query->fetchAll(PDO::FETCH_ASSOC);
if ($query->execute()) {
echo "<div style='margin-top:-44px;padding-bottom:20px'>Gallery results for <span style='font-weight:600'>$_POST[username]</span>...</div>";
while ($row = $query->fetch()) {
echo '<a href="/details/' . $row['id'] . '"/><img src="https://WEBSITE.com/uploads/images/' . $row['image1'] . '" style="width:107px;height:176px;margin-right:6px" /></a>';
}
}
echo json_encode($result);
die();
}
}
catch (PDOException $e) {
echo "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>What it looks like on my end:
[ATTACH type="full" width="595px" alt="spotlight1.png"]5427[/ATTACH]
[ATTACH type="full" width="595px" alt="spotlight2.png"]5428[/ATTACH]
*** Remove ALL statements of "cover1" in code, it is custom to my table.
*** Wrap ALL PHP code in gallery.php in begin_frame() - end_frame() if needed. I don't use it.
