Topic: Web Links Main Index format fix
nate_02631
avatar
Professional
Professional
Posts: 3055

Posted:
4.Feb 2004 - 00:15

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) . "\">&nbsp;&nbsp;"
                ."<a class=\"pn-title\" href=\"".$GLOBALS['modurl']."&amp;req=viewlink&amp;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=\"\">&nbsp;"
                    ."<img src=\"modules/".$GLOBALS['name']."/images/folder.gif\" alt=\"".pnVarPrepForDisplay($stitle)."\">&nbsp;&nbsp;"
                    ."<a class=\"pn-normal\" href=\"".$GLOBALS['modurl']."&amp;req=viewlink&amp;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 = "&nbsp;";
    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 = "&nbsp;";
    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."\">&nbsp;";
            }
            if ($count<=3 && $count>1) {
                $catnewlink .= "<img src=\"modules/".$GLOBALS['name']."/images/newgreen.gif\" alt=\""._NEWLAST3DAYS."\">&nbsp;";
            }
            if ($count<=7 && $count>3) {
                $catnewlink .= "<img src=\"modules/".$GLOBALS['name']."/images/newblue.gif\" alt=\""._NEWTHISWEEK."\">&nbsp;";
            }
        }
        $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 =  "&nbsp;";
    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."\">&nbsp;";
    }
            if ($count<=3 && $count>1) {
        $subcatnewlink .= "<img src=\"modules/".$GLOBALS['name']."/images/newgreen.gif\" alt=\""._CATLAST3DAYS."\">&nbsp;";
    }
            if ($count<=7 && $count>3) {
        $subcatnewlink .= "<img src=\"modules/".$GLOBALS['name']."/images/newblue.gif\" alt=\""._CATTHISWEEK."\">&nbsp;";
    }
}
        $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

echo newlinkgraphic($datetime, $time);

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...
Duster
avatar
Professional
Professional
Posts: 807

Posted:
5.Feb 2004 - 19:06

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
nate_02631
avatar
Professional
Professional
Posts: 3055

Posted:
5.Feb 2004 - 19:23

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...
Duster
avatar
Professional
Professional
Posts: 807

Posted:
6.Feb 2004 - 01:07

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

Quote

I'm not sure what you mean by "increased from 1", as the above mod will show all subcats available.
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.

--
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
nate_02631
avatar
Professional
Professional
Posts: 3055

Posted:
6.Feb 2004 - 01:26

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


Quote

I'm not sure what you mean by "increased from 1", as the above mod will show all subcats available.
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.

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...
Duster
avatar
Professional
Professional
Posts: 807

Posted:
7.Feb 2004 - 19:25

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
joedunn
avatar
Helper
Helper
Posts: 429

Posted:
22.Feb 2004 - 19:47

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
nate_02631
avatar
Professional
Professional
Posts: 3055

Posted:
22.Feb 2004 - 20:10

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...
joedunn
avatar
Helper
Helper
Posts: 429

Posted:
24.Feb 2004 - 19:20

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
nate_02631
avatar
Professional
Professional
Posts: 3055

Posted:
24.Feb 2004 - 19:47

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...
joedunn
avatar
Helper
Helper
Posts: 429

Posted:
24.Feb 2004 - 19:58

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
nate_02631
avatar
Professional
Professional
Posts: 3055

Posted:
24.Feb 2004 - 20:05

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's not perfect, as you can see in this page but slightly better. You could try "balancing off" the cats subcat list... Perhaps breaking up the Law enforment into regions of the country - either as "main" categories or subcats of the main category (West, Midwest, etc...) and have the states an extra cat level down...

--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

Cape Cod Travel Info...
kjhatch
avatar
Helper
Helper
Posts: 192

Posted:
30.Mar 2004 - 07:53

Duster

What exactly does props mean? I know the intent of the word, just not what the word stands for.


Props is a shortening of "proper respect" --that's why the usage is always "giving props" etc. :)

--Kevin
Duster
avatar
Professional
Professional
Posts: 807

Posted:
30.Mar 2004 - 09:07

Thanks, Kevin. I just found that out recently on another forum. I knew what it meant from context but the etymology was perplexing. I appreciate the information

--
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
Slugger
avatar
Professional
Professional
Posts: 1185

Posted:
31.Mar 2004 - 01:14

Finally tried your hack Nate. I like it. Much better than before.

Slugger
fenia
avatar
Softmore
Softmore
Posts: 50

Posted:
10.Mar 2005 - 13:17

Hello!

I've tried to apply the hack to the newest .760 release, but it did not work, as it gave me the following error:

Fatal error: Call to undefined function: buildsimplequery() in /home/portal/public_html/pn-NEWPORTAL/PostNuke/html/modules/Web_Links/wl-util.php on line 330

are there any thoughts about how this could be solved in this release?

Thanks a lot in advance!
nate_02631
avatar
Professional
Professional
Posts: 3055

Posted:
10.Mar 2005 - 19:05

This hack was for .726 and not .760.... I haven't had a look at the new source of .760's weblinks, but the error message pretty much says it all... There is no longer a "buildsimplequery" function in the Web_Links module.

It has probably been replaced with one of the standard API calls for querying the DB... I'd check the corresponding source code of the original .760 link's wl-util.php and swap out the "buildsimplequery" with those...

--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

Cape Cod Travel Info...
jonblaze3
avatar
Freshman
Freshman
Posts: 13

Posted:
4.May 2005 - 03:27

Nate, I used your hack when you first did it last year and it was the greatest hack of all time! But now that I upgraded to .750 I can no longer use the hack=( and my site looks very ugly. I hope you come up with a new one when you have the time! I will be the first one to use it!
jeanloui
avatar
Helper
Helper
Posts: 109

Posted:
9.Jun 2005 - 17:12

Hi nate,

I'm hacking wl-categories.php

Do you know what the "MoveNext" function do (line 53)?
And where is it defined?

Thanks!
haryana
avatar
Freshman
Freshman
Posts: 4

Posted:
16.Sep 2005 - 19:37

wakeup nate found someting ?
haryana
avatar
Freshman
Freshman
Posts: 4

Posted:
16.Sep 2005 - 19:58

aa found the solution ;) goto admin >> settings >> Enable support for legacy modules puff error gone.......good luck