Core Modules & Blocks  :: 
Sections module graphic or title config
 Top

  • Hi All

    I am trying to understand the setup of the sections module and using a graphic image appears to prevent the text description from showing. The text or titles are also shown close to the centre of the page. Is there a method of controlling this so that we can set some spacing for the section titles and have both an image and the text showing ?

    I'd also like to have the articles in the sections using a left justified rather than centre justified formatting. Is there something I am missing with this ?

    TIA

    cheers
    Tony
  • Hi All

    Had no answer to my original post so I did it myself.

    Purpose: to fix the issue with titles not displaying.

    /modules/Sections is where we are working

    Scripts:

    admin.php

    contains the admin functions that are only accessed via the admin area and allows for adding and maintaining sections.

    Checked here to confirm that the DB uses a three field table for the section info with a key, the text title, and a graphic file name, note that the graphic file name only is stored, the path is hard coded to the /images/Sections directory and your graphic must be in there to work.

    index.php

    the main functions for presentation of sections.

    First issue to resolve:

    Use of images and text for titles. Currently its either/or rather than both. So that you have either an image which may be meaningless, or the text which is meaningful but austere.

    The function

    Code

    listsections()
    is the one that needs modding.

    line 41 to start the function:

    line 55 starts the DB call to return the table contents.

    Code

    $result = $dbconn->Execute("SELECT $column[secid], $column[secname], $column[image] FROM $pntable[sections] ORDER BY $column[secname]");


    From this we confirm that the

    Code

    listsections()
    function is getting all fields and therefore has the information available to use. You may also note that the sort order for display defaults to alphabetical by section title. You could make a change here to have the order by the image value, this would again be in alpha order by image file name, but if you prefixed your images with a numeric key, this would allow you to re-sequence your sections in any order you wanted. I'd suggest using a two digit leading 0 based file structure to support this, i.e. section_image.jpg becomes 01_section_image.jpg and the code would be simply changed to the ORDER BY instruction like this:

    Code

    $result = $dbconn->Execute("SELECT $column[secid], $column[secname], $column[image] FROM $pntable[sections] ORDER BY $column[image]");


    And just down the page is the offending piece of code that does not do what I need it to do.

    Lines 74 -> 77

    Code

    if ( ($image == "transparent.gif") or ($image == "") or ($image== "none") )  {
                  echo $secname;
                } else {
                  echo "<img src=\"images/".strtolower($GLOBALS[ModName])."/$image\" border=\"0\" Alt=\"$secname\">";



    The option here is that if the image name value is blank in the database or equal to the default of 'transparent.gif' then the text value is displayed. If there is an image name value then the text is only used as the Alt tag value. I suspect that the reason for this is to have simple code, whereas for what I want I will need extra table manipulation for each image to have the appropriate text appear below the image, and thats a tad more complex.

    Assuming that I do want to keep similar functionality of displaying only the text in the absence of an image then I need to maintain the if-else structure. I also noted that this is nested within an if-else that tests for a count of the sections displayed so far and that this is hard-coded to 2 which means only two sections are displayed per row.

    It was at this point I figured that there are a number of things I want to modify here and these options may be better being controlled from the admin function. So the mods that I made were done with variable values which I preset for test purposes at the beginning of the function. If it works I'll add the options to the sections admin script later.

    So I modified things within lines 64 - > 86 which was originally:

    **************************

    Code

    $count = 0;
        while(list($secid, $secname, $image) = $result->fields) {

            $result->MoveNext();
            if (pnSecAuthAction(0, 'Sections::Section', "$secname::$secid", ACCESS_READ)) {
                if ($count == 2) {
                    echo "</tr><tr>";
                    $count = 0;
                }
                echo "<td><a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=$GLOBALS[ModName]&amp;file=index&amp;req=listarticles&amp;secid=$secid\">";
                if ( ($image == "transparent.gif") or ($image == "") or ($image== "none") )  {
                  echo $secname;
                } else {
                  echo "<img src=\"images/".strtolower($GLOBALS[ModName])."/$image\" border=\"0\" Alt=\"$secname\">";
                }
                echo "</a></td>";
                $count++;
            }
        }
        $result->Close();
        echo "</tr></table>";
        CloseTable();
        include ('footer.php');




    **************************

    An issue! I want to have a second row being compiled that contains the titles for the sections. so that I have a row with the images and then a row with the text. Hmmm.... I or someone else may want to have the title above the image.

    Ok, so within the loop I need to also have a setting for above or below and be able to prepare information for the title row and the image row.

    This is what I ended up with from line 64 to the end of the function now on line 139:

    ************************

    Code

    $count = 0;

    # set the number of sections per row until admin option is created
    $sections_per_row = 3;
    # set flag for using both text and image until admin option is created
    $sections_image_with_title = true;
    # set flag for title above or below - below is default
    $section_image_above_title = true;
    # clear the text variables for the table construction
    $section_title_row = "";
    $section_image_row = "";
    # set the closing string that is used repeatedly
    $section_table_cell_end = "</a></td>";
    # set the width parameter to balance the spread of the cells in the table
    $section_table_cell_width = round(100/$sections_per_row);

    while(list($secid, $secname, $image) = $result->fields) {

       $result->MoveNext();
       if (pnSecAuthAction(0, 'Sections::Section', "$secname::$secid", ACCESS_READ)) {
          if ($count == $sections_per_row) {
             if ($sections_image_with_title) {
        if ($section_image_above_title) {   
           echo "$section_image_row</tr><tr>$section_title_row";
        } else {
                       echo "$section_title_row</tr><tr>$section_image_row";
        }
        $section_title_row = "";
        $section_image_row = "";
        }
                    echo "</tr><tr>";
                    $count = 0;
        }
        # increment count for use within the next if statement
        $count++;
        if ($sections_image_with_title) {
    # prepare the stuff for each of two rows  -- image_row and title_row
           $section_cell_start = "<td align=\"center\" width=\"$section_table_cell_width%\"><a class=\"pn-normal\"
    href=\"modules.php?op=modload&amp;name=$GLOBALS[ModName]&amp;file=index&amp;req=listarticles&amp;secid=$secid\">"
    ;
                       $section_title_row =
    $section_title_row.$section_cell_start.$secname.$section_table_cell_end;
                       $section_image_row =
    $section_image_row.$section_cell_start."<img src=\"images/".strtolower($GLOBALS[ModName])."/$image\" border=\"0\" Alt=\"$secname\">".$section_table_cell_end;
        } else {
                       echo "<td><a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=$GLOBALS[ModName]&amp;file=index&amp;req=listarticles&amp;secid=$secid\">";
           if ( ($image == "transparent.gif") or ($image == "") or
    ($image== "none") )  {
                          echo $secname;
           } else {
              echo "<img src=\"images/".strtolower($GLOBALS[ModName])."/$image\" border=\"0\" Alt=\"$secname\">";
                       }
        echo $section_table_cell_end;
        }
                  }
        }
        $result->Close();
        if ($sections_image_with_title) {
        # where the number of sections doesn't make a complete row,
        # we need to pad It out
        while($count < $sections_per_row) {
            $count++;
            $section_title_row = $section_title_row."<td></td>";
            $section_image_row = $section_image_row."<td></td>";
         }
        # render the final row of sections
        if ($section_image_above_title) {   
           echo "$section_image_row</tr><tr>$section_title_row";
        } else {
            echo "$section_title_row</tr><tr>$section_image_row";
        }
       # clean up after ourselves
       $section_title_row = "";
       $section_image_row = "";
       }
       # finish off regardless of options used
        echo "</tr><tr>";
        $count = 0;
        echo "</tr></table>";
        CloseTable();
        include ('footer.php');

    ************************

    Note : that there will be some issue with line wrapping in this post so if you decide to try this please be careful, and save the original index.php before you edit anything.

    It all works and presents a nice balanced sections layout in my Phoenix 7.2.3 setup that I did the dev work on. I'll come back to the admin fuction later.

    Hope someone else finds this useful. If you try it and it fails just post a follow up and I'll email the code to you.

    cheers
    Tony
This list is based on the users active over the last 60 minutes.