- Moderated by:
- Support Team
-
- rank:
-
Professional
- registered:
- September 2003
- Status:
- offline
- last visit:
- 11.04.08
- Posts:
- 3055
Don't you just hate it when, on your main Web Links directory, you have one category with many subcategories and one next to it with none (or not as many) and you get a very unbalanced page with a lot of whitespace?
Sure, you could just not have any subcategories, make sure you have a relatively even # of subcategories, or fix the main index not to show *any* subcategories, but why compromise? ;)
My solution involves keeping all the subcategories, but outputting the main links index in just a one left and one right table cell - instead of a cell for each category/subcategory set which causes the layout imbalance. (Note changes applied to PN .726 wl-navigation.php v 1.14 & wl-util.php v 1.17
Here's how you do it:
Replace the index() function in your wl-navigation.php script with:
Code
function index()
{
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
include("header.php");
$mainlink = 0;
if (!pnSecAuthAction(0, 'Web Links::', '::', ACCESS_READ)) {
echo _WEBLINKSNOAUTH;
include 'footer.php';
exit;
}
menu($mainlink);
$column = &$pntable['links_categories_column'];
$result=$dbconn->Execute("select $column[cat_id], $column[title], $column[cdescription]
from $pntable[links_categories]
WHERE $column[parent_id]=0
ORDER BY $column[title]");
$numcats = $result->PO_RecordCount();
if ($numcats == 0) {
echo "<b>"._LINKSNOCATS."</b>";
include 'footer.php';
} else {
OpenTable();
// echo "<center><font class=\"pn-title\">"._LINKSMAINCAT."</font></center><br />";
$count = 0;
while(list($cat_id, $title, $cdescription) = $result->fields)
{
$result->MoveNext();
/* Hide this web link if have no access to it */
if (!pnSecAuthAction(0, 'Web Links::Category', "$title::$cat_id", ACCESS_READ)) {
continue;
}
$count++;
$cnumrows = CountSubLinks($cat_id);
$this_cat = "<p><font class=\"pn-normal\">"
."<img src=\"modules/".$GLOBALS['name']."/images/folder.gif\" alt=\"" . pnVarPrepForDisplay($title) . "\"> "
."<a class=\"pn-title\" href=\"".$GLOBALS['modurl']."&req=viewlink&cid=$cat_id\">".pnVarPrepForDisplay($title)."</a>"
." ($cnumrows)";
$this_cat .= categorynewlinkgraphic($cat_id);
$this_cat .= "</font>";
$this_cat .= "<br />";
if ($cdescription) {
$this_cat .= "<font class=\"pn-normal\">".pnVarPrepHTMLDisplay($cdescription)."</font><br />";
}
$column = &$pntable['links_categories_column'];
$result2 = $dbconn->Execute("SELECT $column[cat_id], $column[title] FROM $pntable[links_categories] WHERE $column[parent_id]=".pnVarPrepForStore($cat_id)." ORDER BY $column[title]");
$space = 0;
while(list($scat_id, $stitle) = $result2->fields) {
$result2->MoveNext();
$this_cat .= "<font class=\"pn-normal\"><img src=\"modules/".$GLOBALS['name']."/images/tree_end.gif\" alt=\"\"> "
."<img src=\"modules/".$GLOBALS['name']."/images/folder.gif\" alt=\"".pnVarPrepForDisplay($stitle)."\"> "
."<a class=\"pn-normal\" href=\"".$GLOBALS['modurl']."&req=viewlink&cid=$scat_id\">".pnVarPrepForDisplay($stitle)."</a>"
."</font>";
$this_cat .= subcategorynewlinkgraphic($scat_id);
$this_cat .= "<BR />";
$space++;
}
if ($count%2) {
$left_column .= $this_cat.'<BR>';
} else {
$right_column .= $this_cat.'<BR>';
}
$this_cat = '';
} //While
// Output the table
echo "<table border=\"0\" cellspacing=\"10\" cellpadding=\"0\" align=\"center\" width=\"98%\"><tr valign=top>";
echo "<td width=50%>$left_column</td><td>$right_column</td>";
echo "</tr></table>";
$result=$dbconn->Execute("SELECT COUNT(*) FROM $pntable[links_links]");
list($numrows) = $result->fields;
$result=$dbconn->Execute("SELECT COUNT(*) FROM $pntable[links_categories]");
list($catnum) = $result->fields;
echo "<br /><br /><center><font class=\"pn-sub\">"._THEREARE." <b>$numrows</b> "._LINKS." "._AND." <b>$catnum</b> "._CATEGORIES." "._INDB."</font></center>";
CloseTable();
include("footer.php");
}
}
Hold on! We're not quite done... Because the functions for outputting the "new" graphics next to cats/subcats "echo" the output instead of returning it, you need to adjust these slightly too. In your wl-util.php file, replace the following three functions with:
Code
/* Link Graphics */
/**
* categorynewlinkgraphic
* @usedby index, viewlink
*/
function categorynewlinkgraphic($cat)
{
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
$column = &$pntable['links_links_column'];
$locale = pnConfigGetVar('locale');
$query = buildSimpleQuery ('links_links', array ('date'), "$column[cat_id]=$cat", "$column[date] DESC", 1);
$newresult = $dbconn->Execute($query);
list($time)=$newresult->fields;
if (!$time) return;
$catnewlink = " ";
setlocale (LC_TIME, $locale);
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
$datetime = ml_ftime(""._LINKSDATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
$datetime = ucfirst($datetime);
$startdate = time();
$count = 0;
while ($count <= 7)
{
$daysold = ml_ftime(""._LINKSDATESTRING."", $startdate);
if ("$daysold" == "$datetime") {
if ($count<=1) {
$catnewlink .= "<img src=\"modules/".$GLOBALS['name']."/images/newred.gif\" alt=\""._CATNEWTODAY."\">";
}
if ($count<=3 && $count>1) {
$catnewlink .= "<img src=\"modules/".$GLOBALS['name']."/images/newgreen.gif\" alt=\""._CATLAST3DAYS."\">";
}
if ($count<=7 && $count>3) {
$catnewlink .= "<img src=\"modules/".$GLOBALS['name']."/images/newblue.gif\" alt=\""._CATTHISWEEK."\">";
}
}
$count++;
$startdate = (time()-(86400 * $count));
}
return $catnewlink;
}
/**
* newlinkgraphic
* @usedby mostpopular, search
*/
function newlinkgraphic($datetime, $time) {
$locale = pnConfigGetVar('locale');
$catnewlink = " ";
setlocale (LC_TIME, $locale);
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
$datetime = ml_ftime(""._LINKSDATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
$datetime = ucfirst($datetime);
$startdate = time();
$count = 0;
while ($count <= 7)
{
$daysold = ml_ftime(""._LINKSDATESTRING."", $startdate);
if ("$daysold" == "$datetime") {
if ($count<=1) {
$catnewlink .= "<img src=\"modules/".$GLOBALS['name']."/images/newred.gif\" alt=\""._NEWTODAY."\"> ";
}
if ($count<=3 && $count>1) {
$catnewlink .= "<img src=\"modules/".$GLOBALS['name']."/images/newgreen.gif\" alt=\""._NEWLAST3DAYS."\"> ";
}
if ($count<=7 && $count>3) {
$catnewlink .= "<img src=\"modules/".$GLOBALS['name']."/images/newblue.gif\" alt=\""._NEWTHISWEEK."\"> ";
}
}
$count++;
$startdate = (time()-(86400 * $count));
}
return $catnewlink;
}
/**
* subcategorynewlinkgraphic
*
* Post-Nuke mod -- Create a the new function for generating the 'new' graphics for
* sub-categoires, based on the post-nuke categorynewlinkgraphic($cid)
* @usedby index, viewlink
*/
function subcategorynewlinkgraphic($sid)
{
$locale = pnConfigGetVar('locale');
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
$column = &$pntable['links_links_column'];
$query = buildSimpleQuery ('links_links', array ('date'), "$column[cat_id]=".(int)pnVarPrepForStore($sid)."", "$column[date] DESC");
$newresult = $dbconn->SelectLimit($query, 1);
list($time)=$newresult->fields;
$subcatnewlink = " ";
if (!$time) return;
setlocale (LC_TIME, $locale);
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
$datetime = ml_ftime(""._LINKSDATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
$datetime = ucfirst($datetime);
$startdate = time();
$count = 0;
while ($count <= 7) {
$daysold = ml_ftime(""._LINKSDATESTRING."", $startdate);
if ("$daysold" == "$datetime") {
if ($count<=1) {
$subcatnewlink .= "<img src=\"modules/".$GLOBALS['name']."/images/newred.gif\" alt=\""._CATNEWTODAY."\"> ";
}
if ($count<=3 && $count>1) {
$subcatnewlink .= "<img src=\"modules/".$GLOBALS['name']."/images/newgreen.gif\" alt=\""._CATLAST3DAYS."\"> ";
}
if ($count<=7 && $count>3) {
$subcatnewlink .= "<img src=\"modules/".$GLOBALS['name']."/images/newblue.gif\" alt=\""._CATTHISWEEK."\"> ";
}
}
$count++;
$startdate = (time()-(86400 * $count));
}
return $subcatnewlink;
}
We basically just replaced the "echos" in those functions to assign the output to a variable and then return it at the end of a function - I think these functions could stand a bit of optimization(!)
Lastly, you just need to change any occurances of the functions above in the Web Links modules to be echoed. So this:
Code
newlinkgraphic($datetime, $time);
becomes:
Code
You'll find instances of those functions in the wl-mostpopular, newlinks, search, toprated and viewlink files. *DON'T* make any further changes to the index() function in wl-navigation.php, though.
That's it! Of course if you don't have the *exact* same total number of categories and subcategories in the left and right columns the "bottoms" won't end at the same spot in the page, but I think it looks much better than the default.
P.S. The index() function above makes reference to a graphic "tree_end.gif" which I added to my install. It is just a 16x16 "L"-graphic that servers to connect the folders in a tree-like fashion. Feel free to make your own or remove the reference...
--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods
Cape Cod Travel Info... -
- rank:
-
Professional
- registered:
- July 2003
- Status:
- offline
- last visit:
- 20.06.04
- Posts:
- 807
I added this enhancement early this morning, replacing the previous hack I was using. I like it. It certainly helps to be able to show subcategories without the very unbalanced way of displaying them in the manner fo the unmodified core files. This hack should definitely be in PN .8 I didn't add the L graphic as I think it is uneccesary and visual clutter. Phorum uses it by default and it creates an ugly layout. I think the indentation is enough to establish the tree relationship.
I do have a couple of questions. Can the number of subcategories be changed and be set either to 0 or increased from 1? I think those changes would make it versatile for everybody.
--
Yes, I have checked the pnGuide and done a search on the forums before posting my question.
PN Guides for Beginners
How To Find Answers and Ask Questions -
- rank:
-
Professional
- registered:
- September 2003
- Status:
- offline
- last visit:
- 11.04.08
- Posts:
- 3055
Thanks for the props, Duster!
In answer to your query, you should be able to set the max number of subcats here (though I think setting it to zero sort of defeats the purpose of the mod - you could do this with the "stock" Web Links to get the same results)
Check out this line of code:
Code
$result2 = $dbconn->Execute("SELECT $column[cat_id], $column[title] FROM $pntable[links_categories] WHERE $column[parent_id]=".pnVarPrepForStore($cat_id)." ORDER BY $column[title]");
You could add a LIMIT X at the end of the query (where X is the maximum # of subcats you want to display). I'm not sure what you mean by "increased from 1", as the above mod will show all subcats available. And of course, if you were electing not to output *any* subcategories, you could just wipe out that section of code where they are queried & output altogether(!)
Another idea for subcategory presentation would be perhaps to change the above query to just get the COUNT of the subcategories, i.e.
Code
$result2 = $dbconn->Execute("SELECT COUNT(*) AS subcatcount FROM $pntable[links_categories] WHERE $column[parent_id]=".pnVarPrepForStore($cat_id));
Then, instead of outputting all the subcategory names & links, just output the count:
Code
Number of subcategories: 3
--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods
Cape Cod Travel Info... -
- rank:
-
Professional
- registered:
- July 2003
- Status:
- offline
- last visit:
- 20.06.04
- Posts:
- 807
nate_02631
Thanks for the props, Duster!
You're welcome. What exactly does props mean? I know the intent of the word, just not what the word stands for.
Quote
In answer to your query, you should be able to set the max number of subcats here (though I think setting it to zero sort of defeats the purpose of the mod - you could do this with the "stock" Web Links to get the same results)
I was thinking that if your hack was incorporated into the .8 files, it would be helpful to offer all the choices any PN admin might want to make
Not so. I have a few categories that show countries as subcategories. While the U.S. subcat has all the states listed, none of them show.Quote
I'm not sure what you mean by "increased from 1", as the above mod will show all subcats available.
--
Yes, I have checked the pnGuide and done a search on the forums before posting my question.
PN Guides for Beginners
How To Find Answers and Ask Questions -
- rank:
-
Professional
- registered:
- September 2003
- Status:
- offline
- last visit:
- 11.04.08
- Posts:
- 3055
Duster
What exactly does props mean?
Props = Kudos, Accolades
Duster
I was thinking that if your hack was incorporated into the .8 files, it would be helpful to offer all the choices any PN admin might want to make
I see. In which case if you had more subcats, a "more..." link could be generated. A vertical vs. horizontal-separated-by-commas option would be nice too! (though pnRender might make that not necessary?)
Duster
Not so. I have a few categories that show countries as subcategories. While the U.S. subcat has all the states listed, none of them show.Quote
I'm not sure what you mean by "increased from 1", as the above mod will show all subcats available.
Gotcha - you mean the number of *levels* of subcategories being shown on the Web Link "home page" - i.e. showing subcategories of subcategories... I dunno, I think that would get pretty messy real fast, don't you?
At any rate, I didn't make any changes to what info is fetched for the links index, only the way it is parsed & output. Though it probably wouldn't be hard to add a little loop in there for the subcats, it would likely requre more than a few DB queries to go through each one.
--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods
Cape Cod Travel Info... -
- rank:
-
Professional
- registered:
- July 2003
- Status:
- offline
- last visit:
- 20.06.04
- Posts:
- 807
Nate,
I just thought of a minor enhancement to your hack. If you have the subcategories use folder2.gif, it would allow an elegant visual tree relationship as opposed to the (on my copy) discarded tree_end graphic. That would make it easy to use a different color folder graphic for the subcategories. Those admins who wanted to could copy folder.gif to folder2.gif to have them both the same.
--
Yes, I have checked the pnGuide and done a search on the forums before posting my question.
PN Guides for Beginners
How To Find Answers and Ask Questions -
- rank:
-
Helper
- registered:
- April 2003
- Status:
- offline
- last visit:
- 19.10.06
- Posts:
- 429
OK, I need this. I thought I followed your instructions easily enough. When it didn't work the first time I uploaded new generic Web Link files and verified everything was back to the original method. I then followed your instructions a second time and got the exact same errors. Either I can not read OR I made the exact smae mistake two times in a row. I tried to discover my error but just do not know enough about PHP to know my error if I am looking at it. What do these errors suggest to you?
Parse error: parse error in /home/affiliat/public_html/modules/Web_Links/wl-util.php on line 360
Parse error: parse error in /home/affiliat/public_html/modules/Web_Links/wl-navigation.php on line 36
Fatal error: Call to undefined function: index() in /home/affiliat/public_html/modules/Web_Links/index.php on line 227 -
- rank:
-
Professional
- registered:
- September 2003
- Status:
- offline
- last visit:
- 11.04.08
- Posts:
- 3055
The third is caused by the first two which seem to indicate a syntax error that was made - perhaps a missing semi-colon, closing function markers "}" etc... If you have a decent text editor you can go right to these lines and check it out (though sometimes in PHP the "error" isn't on the exact line mentioned, but somewhat before or near it).
Duster, I think, has made the a download for this mod available on his web site...
--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods
Cape Cod Travel Info... -
- rank:
-
Helper
- registered:
- April 2003
- Status:
- offline
- last visit:
- 19.10.06
- Posts:
- 429
I tried it again and there are no errors. However, I don't see that any change has occured. It is still one long column on the left and a very short one on the right.
http://www.affiliate…eb_Links&file=index
Did I miss something else?
Joe Dunn -
- rank:
-
Professional
- registered:
- September 2003
- Status:
- offline
- last visit:
- 11.04.08
- Posts:
- 3055
Nope that's right... With this mod, you will always have an even number of main categories on the left and right columns, however with your setup of categories/subcats you can't see this effect clearly.
--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods
Cape Cod Travel Info... -
- rank:
-
Helper
- registered:
- April 2003
- Status:
- offline
- last visit:
- 19.10.06
- Posts:
- 429
The way you worded your response leads me to believe that you don't care for the way I have things setup. What would you do differently? I was hoping for a shorter page with sub categories in two or three columns to save space. I respect your opininion as you have helped me many times!
Joe Dunn -
- rank:
-
Professional
- registered:
- September 2003
- Status:
- offline
- last visit:
- 11.04.08
- Posts:
- 3055
No, I have no opinion about that really, but if the number of cats, subcats is way unbalanced on the left/right side, this mod can't do much about that. It simply removes the table/cell type output so their aren't big whitesplace gaps between individual categories. It
