Gossamer Forum
Home : Products : Gossamer Links : PHP Front End :

Featured Site mod [release]

Quote Reply
Featured Site mod [release]
As mentioned in another thread...
Quote:
I've got the old v1.1x Featured mod updated to a dynamic PHP version now,
complete with templates and a Featured.inc.php file, sans error reporting.

Basically, what it does is randomly select a 'featured' site from the database and
build that into the template, with a link to a popup window containing the full list
of featured links. Pretty simple, but it adds incentive to other sites to link back to
you in return for a featured listing...

The old v1.1x version can be found here for reference:

http://run-down.com/mods/

You will want to start by adding the isFeatured column to your Links table:

Column Name: isFeatured
Type: INT
Form Length: 1
Max Length: 1
Not Null: Yes
Default: 0
Validation: 1|0

The v2.x admin area (Database > Links > Properties > Add Column) contains a lot of
other optional table fields that can probably be ignored, so long as you set the
important ones above.

In page.php's switch($do) section, add the following:

Code:
case 'featured':
include_once("$include_path/Featured.inc.php");
break;

Create a new file called Featured.inc.php and place it in the /admin/Links/PHP/ directory.
Add the following to the file:

Code:
<?php
# ==================================================================
# Links SQL - enhanced directory management system
#
# Website : http://gossamer-threads.com/
# Support : http://gossamer-threads.com/scripts/support/
# CVS Info : 087,068,082,095,085
# Revision : $Id: Featured.inc.php
#
# Copyright (c) 2001 Gossamer Threads Inc. All Rights Reserved.
# Redistribution in part or in whole strictly prohibited. Please
# see LICENSE file for full details.
# ==================================================================

# used for formatting the featured link with link.html:
require_once("$admin_root_path/Links/PHP/Utils.inc.php");

function handle() {
# ---------------------------------------------------
# Determine what to do.
#
global $CFG, $IN, $USER, $DB, $PREFIX, $HTTP_SERVER_VARS;

# $id = isset($IN['link_id']) ? intval($IN['link_id']) : '';
$action = isset($IN['action']) ? strtolower($IN['action']) : '';

# Now figure out what to do.
if ($action == 'full') {

$results = "";
$sth = $DB->query("SELECT ID, Title, URL, Description FROM ${PREFIX}Links WHERE isFeatured = 1 ORDER BY Title ASC");
while ($row = $sth->fetchrow_hash()) {
$results .= "<a href=\"". $CFG['db_php_url'] ."/page.php?do=jump&link_id=". $row['ID'] ."\" target=\"_blank\">". $row['Title'] ."</a> - ". $row['Description'] ."<br><br>\n";
}

print_page('featured_full', array('featured_full' => $results));
} else {

# build an array of featured links to randomly select one from
$featured_array = array ();

$sth = $DB->query("SELECT ID FROM ${PREFIX}Links WHERE isFeatured = 1");
while ($row = $sth->fetchrow_hash()) {
$featured_array[] = $row['ID'];
}

# select a random id from the array
srand ((float) microtime() * 10000000);
$rand_keys = array_rand($featured_array);
$featured_id = $featured_array[$rand_keys];

// use this for a more efficient query if you will be manually formatting the link output:
// $sth = $DB->query("SELECT ID, Title, URL, Description FROM ${PREFIX}Links WHERE ID = '$featured_id'");

$sth = $DB->query("SELECT * FROM ${PREFIX}Links WHERE ID = '$featured_id'");
$row = $sth->fetchrow_hash();

// use this instead of _print_link() for manually formatting the link output:
// $result = "<a href=\"". $CFG['db_php_url'] ."/page.php?do=jump&link_id=". $row['ID'] ."\" target=\"_blank\">". $row['Title'] ."</a> - ". $row['Description'] ."<br>\n";

$result = _print_link($row);
print_page('featured', array('featured' => $result));
}
}

?>

Create 2 new template files that will go into the /templates/default_php/local/
directory. The first will be called featured.html and will contain:

Code:
<html>
<head>
<title><?echo $site_title?> : Featured Sites</title>

<SCRIPT LANGUAGE="JavaScript">
<!--
function new_window() { rate =
window.open('','rate','toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=yes,height=300,width=300');
}
// -->
</SCRIPT>

...

<?echo $featured?>

...

Where "..." refers to whatever header/footer layout your templates take.

The second will be called featured_full.html and will contain:

Code:
<html>
<head>
<title><?echo $site_title?> : Featured Sites</title>

</head>
<body BGCOLOR="#ffffff">

<?echo $featured_full?>

<center><form><input type="button" value="Close" onClick="window.close();"></form></center>

</body>
</html>

Finally, you will access the featured page through:

http://www.domain.com/pages/page.php?do=featured

That should about do it. To see it in action, you can take a look at the semi-static
(updated daily) current production version it is based on:

http://run-down.com/featured.php

I'm also working on an updated version of the Priority Link Listing mod.

Dan
Quote Reply
Re: [Dan Kaplan] Featured Site mod [release] In reply to
Hi Dan,

Thank you for posting your works, my question is, it possible to have the featured sites to be list with numbers

1. site 1

2. site 2

3 site 3

ect!
Quote Reply
Re: [xpert] Featured Site mod [release] In reply to
Do you mean in the full list version? All that would require is a counter started at zero that increments by one as each link is prepared in Featured.inc.php. What would be the basis for numbering/ordering the links?

Dan
Quote Reply
Re: [Dan Kaplan] Featured Site mod [release] In reply to
increment form 1, up and in alphabet order!
Quote Reply
Re: [xpert] Featured Site mod [release] In reply to
Easy enough. That's the sort order already, so all you have to do is change the while() loop in the ($action == "full") section to:

Code:
$count = 1;
while ($row = $sth->fetchrow_hash()) {
$results .= $count .". <a href=\"". $CFG['db_php_url'] ."/page.php?do=jump&link_id=". $row['ID'] ."\" target=\"_blank\">". $row['Title'] ."</a> - ". $row['Description'] ."<br><br>\n";
$count++;
}
Dan

Last edited by:

Dan Kaplan: Jul 2, 2002, 11:51 PM