PDA

View Full Version : Download Manager - Filename and category in page title


hamesh
12-16-2006, 03:56 AM
I've been posting to SD.com and was suggested I post here instead. So...

I seem to be on an SEO mission with SD. So wanted to share a little hack to show the filename and category in the page title for the Download Manager.

First you'll need a good text editor. Notepad sucks but will get you by. For hard core Un*x folks with shell access, use vim or jed or similar on the command line. To get syntax highlighting and row numbers, there's also the free Microsoft Visual Web Developer 2005 Express Edition (http://msdn.microsoft.com/vstudio/express/vwd/) or PSPad (http://www.pspad.com/).

I digress.

Open your SD ~/index.php in text editor of choice. Around line 117 in SD 2.40, find:

// ####################### ALTER TITLE AND META SETTINGS #######################

if(isset($_GET['p2_articleid']) AND ereg("^[0-9]+$", $_GET['p2_articleid']))
{
if($article = $DB->query_first("SELECT title, metakeywords, metadescription FROM " . TABLE_PREFIX . "p2_news WHERE articleid = '" . $_GET['p2_articleid'] . "'"))
{
$mainsettings['websitetitle'] .= ' - ' . $article['title'];
$mainsettings['metadescription'] .= ', ' . $article['metadescription'];
$mainsettings['metakeywords'] .= ', ' . $article['metakeywords'];
}
}


Below this, paste:

// ################### JAMES HACK TO GET FILENAME AND CATEGORY IN DM PAGE TITLE #######################

$downloadurl = explode('/', $_SERVER['REQUEST_URI']);

if(isset($_GET['p13_sectionid']) AND ereg("^[0-9]+$", $_GET['p13_sectionid']))
{
{
$sectionname = $DB->query_first("SELECT name FROM " . TABLE_PREFIX . "p13_sections WHERE sectionid = '$downloadurl[3]'");
}
if(isset($_GET['p13_fileid']) AND ereg("^[0-9]+$", $_GET['p13_fileid']))
{
{
$filetitle = $DB->query_first("SELECT title FROM " . TABLE_PREFIX . "p13_files WHERE fileid = '$downloadurl[5]'");
}
$mainsettings['websitetitle'] .= ' - ' . $filetitle['title'];
}

$mainsettings['websitetitle'] .= ' - ' . $sectionname['name'];
}

Boom. Filename and categoryin Download Manager page titles. See http://www.belchfire.net/themes/p13_sectionid/3 (category) and http://www.belchfire.net/themes/p13_sectionid/3/p13_fileid/13 (file) for examples.

Notes. This assumes you are using Friendly URLs. Can work without Fancy URLs enabled but would require changes to $fileurl (QUERY_STRING and likely '=' as array separator). And you're not using a cloned DM but easily adapted.

Similar method could be used to enable filename and categories in title for other modules, such as Image Gallery. Obviously not ideal, but that's why it's a hack ;)

No reason couldn't use same method to update meta keywords and description also. Stay tuned.

Tobias
12-16-2006, 08:12 AM
Hello Hamesh,
thanks for putting your tips and code examples here on SD.org, too. Nice ideas.

If you don't mind I restructured your code a little for better SELECT checking (same requirements apply, like p13 etc.):

if($mainsettings['modrewrite'] && isset($_GET['p13_sectionid']) && ereg("^[0-9]+$", $_GET['p13_sectionid']))
{
$downloadurl = explode('/', $_SERVER['REQUEST_URI']);
if($sectionname = $DB->query_first("SELECT name FROM " . TABLE_PREFIX . "p13_sections WHERE sectionid = '$downloadurl[3]'"))
{
$mainsettings['websitetitle'] .= ' - ' . $sectionname['name'];
}

if(isset($_GET['p13_fileid']) AND ereg("^[0-9]+$", $_GET['p13_fileid']))
{
if($filetitle = $DB->query_first("SELECT title FROM " . TABLE_PREFIX . "p13_files WHERE fileid = '$downloadurl[5]'"))
{
$mainsettings['websitetitle'] .= ' - ' . $filetitle['title'];
}
}
}


Edit: removed "else" keyword

hamesh
12-16-2006, 09:41 AM
Not at all. I see what you're doing. Doesn't quite work though. In your code the first check is to see if modrewrite is enabled. Good. If is, look for p13_sectionid in 4th position in array; if true return category from DB. But because p13_sectionid appears in every download link (cat or file), your else statement never triggers. Result is only the category is ever returned. Not the filename when viewing an individual file. URLs:

~/downloads/p13_sectionid/4 (category)
~/downloads/p13_sectionid/4/p13_fileid/19 (file)

See what I mean? Also, in your code the category and filename would never both be returned. In mine, cat is returned for cat view, cat + filename is returned for file view. I think you'd need to nest the filename lookup within the cat lookup in order for both to be returned, not an if/else flow, no?

Tobias
12-16-2006, 11:28 AM
Hi,
yes, thanks for pointing that out. However, I think I only needed to remove the "ELSE" keyword (edited my post) to achieve to either show only the category name and/or the filename.
To my mind the "IF"s are bit nicer to avoid internal PHP "Notice" messages if no rows were found.

Brent
12-16-2006, 02:03 PM
Trying to understand you guys is like looking at the 1's and 0's of the matrix. hehe. Great work guys.

VioAdmin
10-31-2007, 11:52 PM
Can someone please, update this code for the gallery and download manager?

I'll pay if I have to!

thomas
11-01-2007, 01:26 AM
Can someone please, update this code for the gallery and download manager?

I'll pay if I have to!

This is a very old thread.

It might be worth considering to wait until SD updates the plugins/sd or post the suggestion on subdreamer.com's forum suggestions

falc
11-01-2007, 11:06 AM
Can someone please, update this code for the gallery and download manager?

I'll pay if I have to!

i'll pay too if someone can do something with this hack for the picture gallery