Welcome to Geeklog Wednesday, December 13 2017 @ 11:21 pm EST


Status: offline

::Ben

Forum User
Full Member
Registered: 14/01/2005
Posts: 1569
Location:la rochelle, France
Just an update to the Blogroll block and a new feature (sort order).

::Ben

PHP Formatted Code

function phpblock_blogroll ()
{
    global $_CONF, $_TABLES;
 
    // configuration options:
 
    $cat = 'Logiciel'; // cid to take links from (e.g. If category is Geeklog Sites, cid is geeklog-sites
    $directlink = false; // Use direct links (true) or portal.php (false)
    $random = false;     // Random order (true) or sort by $sort (false)
    $sort = 'hits';     // Sort by 'date', 'title', 'url', 'hits'
    $order = 'DESC';    // Order is ASC or DESC
 
    // === you shouldn't need to change anything below this line ==============
    $retval = '';
 
    $result = DB_query ("SELECT lid,url,title,description,hits FROM   WHERE cid='$cat'" . COM_getPermSql ('AND') . " ORDER BY $sort $order");
    $numLinks = DB_numRows ($result);
 
    $links = array ();
    for ($i = 0; $i < $numLinks; $i++) {
        $A = DB_fetchArray ($result);
 
        if ($directlink) {
            $url = $A['url'];
            $link = '<a href="' . $url . '">';
 
        } else {
            $url = $_CONF['site_url']
                 . COM_buildUrl ('/links/portal.php/link/' . $A['lid']);
            $link = '<a href="' . $url . '" title="' . $A['url'] . '">';
 
        }
        $links[] = $link . stripslashes ($A['title']) . '</a>' . ' (' . ($A['hits']) . ')' . '<br><i>' . ($A['description']) . '<br><br></i>';
    }
 
    if (count ($links) > 0) {
 
        if ($random) {
            $min = 0;
            $max = count ($links) - 1;
 
            $newlist = array ();
            do {
                $r = rand ($min, $max);
 
                if (!empty ($links[$r])) {
                    $newlist[] = $links[$r];
                    unset ($links[$r]);
                }
 
                if ($r == $min) {
                    $min = $r + 1;
                } else if ($r == $max) {
                    $max = $r - 1;
                }
                if ($min == $max) {
                    if (!empty ($links[$min])) {
                        $newlist[] = $links[$min];
                    }
                    break;
                }
            }
            while ($max > $min);
 
            $retval = COM_makeList ($newlist, 'list-blogroll');
        } else {
            $retval = COM_makeList ($links, 'list-blogroll');
        }
    }
 
    return $retval;
}
 

I'm available to customise your themes or plugins for your Geeklog CMS

Status: offline

1000ideen

Forum User
Full Member
Registered: 04/08/2003
Posts: 1289
Would be great if the blogroll became part of the links plugin, this is actually where it belongs to.

Status: offline

::Ben

Forum User
Full Member
Registered: 14/01/2005
Posts: 1569
Location:la rochelle, France
Some code is missing from the post above. I try one more time.

::Ben

PHP Formatted Code
function phpblock_blogroll ()
{
    global $_CONF, $_TABLES;
 
    // configuration options:
 
    $cat = 'Logiciel'; // cid to take links from (e.g. If category is Geeklog Sites, cid is geeklog-sites
    $directlink = false; // Use direct links (true) or portal.php (false)
    $random = false;     // Random order (true) or sort by $sort (false)
    $sort = 'hits';     // Sort by 'date', 'title', 'url', 'hits'
        $order = 'DESC';    // Order is ASC or DESC
 
    // === you shouldn't need to change anything below this line ==============
    $retval = '';
 
    $result = DB_query ("SELECT lid,url,title,description,hits FROM {$_TABLES['links']}  WHERE cid='$cat'" . COM_getPermSql ('AND') . " ORDER BY $sort $order");
    $numLinks = DB_numRows ($result);
 
    $links = array ();
    for ($i = 0; $i < $numLinks; $i++) {
        $A = DB_fetchArray ($result);
 
        if ($directlink) {
            $url = $A['url'];
            $link = '<a href="' . $url . '">';
 
        } else {
            $url = $_CONF['site_url']
                 . COM_buildUrl ('/links/portal.php/link/' . $A['lid']);
            $link = '<a href="' . $url . '" title="' . $A['url'] . '">';

        }
        $links[] = $link . stripslashes ($A['title']) . '</a>' . ' (' . ($A['hits']) . ')' . '<br><i>' . ($A['description']) . '<br><br></i>';
    }
 
    if (count ($links) > 0) {
 
        if ($random) {
            $min = 0;
            $max = count ($links) - 1;
 
            $newlist = array ();
            do {
                $r = rand ($min, $max);
 
                if (!empty ($links[$r])) {
                    $newlist[] = $links[$r];
                    unset ($links[$r]);
                }
 
                if ($r == $min) {
                    $min = $r + 1;
                } else if ($r == $max) {
                    $max = $r - 1;
                }
                if ($min == $max) {
                    if (!empty ($links[$min])) {
                        $newlist[] = $links[$min];
                    }
                    break;
                }
            }
            while ($max > $min);
 
            $retval = COM_makeList ($newlist, 'list-blogroll');
        } else {
            $retval = COM_makeList ($links, 'list-blogroll');
        }
    }
 
    return $retval;
}

I'm available to customise your themes or plugins for your Geeklog CMS

Status: offline

::Ben

Forum User
Full Member
Registered: 14/01/2005
Posts: 1569
Location:la rochelle, France
Need a blogroll with all the links from the links plugin. Here it is:
PHP Formatted Code
function phpblock_blogroll_nocat ()
{
    global $_CONF, $_TABLES;
 
    // configuration options:
 
    $directlink = false; // Use direct links (true) or portal.php (false)
    $random = false;     // Random order (true) or sort by $sort (false)
    $sort = 'title';     // Sort by 'date', 'title', 'url', 'hits'
        $order = 'ASC';    // Order is ASC or DESC
 
    // === you shouldn't need to change anything below this line ==============
    $retval = '';
 
    $result = DB_query ("SELECT lid,url,title,description,hits FROM {$_TABLES['links']}  " . COM_getPermSql ('AND') . " ORDER BY $sort $order");
    $numLinks = DB_numRows ($result);
 
    $links = array ();
    for ($i = 0; $i < $numLinks; $i++) {
        $A = DB_fetchArray ($result);
 
        if ($directlink) {
            $url = $A['url'];
            $link = '<a href="' . $url . '">';
 
        } else {
            $url = $_CONF['site_url']
                 . COM_buildUrl ('/links/portal.php/link/' . $A['lid']);
            $link = '<a href="' . $url . '" title="' . $A['description'] . '">';

        }
        $links[] = $link . stripslashes ($A['title']) . '</a>';
    }
 
    if (count ($links) > 0) {
 
        if ($random) {
            $min = 0;
            $max = count ($links) - 1;
 
            $newlist = array ();
            do {
                $r = rand ($min, $max);
 
                if (!empty ($links[$r])) {
                    $newlist[] = $links[$r];
                    unset ($links[$r]);
                }
 
                if ($r == $min) {
                    $min = $r + 1;
                } else if ($r == $max) {
                    $max = $r - 1;
                }
                if ($min == $max) {
                    if (!empty ($links[$min])) {
                        $newlist[] = $links[$min];
                    }
                    break;
                }
            }
            while ($max > $min);
 
            $retval = COM_makeList ($newlist, 'list-blogroll');
        } else {
            $retval = COM_makeList ($links, 'list-blogroll');
        }
    }
 
    return $retval;
}

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS

Status: offline

Roccivic

Forum User
Moderator
Registered: 19/05/2010
Posts: 136
Hey Ben,
did you know that you can use the shuffle() function to randomise an array? It will make your code shorter, neater and easier to understand.

PHP Formatted Code
function phpblock_blogroll_nocat()
{
    global $_CONF, $_TABLES;
 
    // configuration options:
 
    $directlink = false; // Use direct links (true) or portal.php (false)
    $random = false;      // Random order (true) or sort by $sort (false)
    $sort = 'title';     // Sort by 'date', 'title', 'url', 'hits'
    $order = 'ASC';      // Order is ASC or DESC
 
    // === you shouldn't need to change anything below this line ==============
    $retval = '';
 
    $result = DB_query ("SELECT lid,url,title,description,hits FROM {$_TABLES['links']}  " . COM_getPermSql ('AND') . " ORDER BY $sort $order");
    $numLinks = DB_numRows ($result);
 
    $links = array ();
    for ($i = 0; $i < $numLinks; $i++) {
        $A = DB_fetchArray ($result);
 
        if ($directlink) {
            $url = $A['url'];
            $link = '<a href="' . $url . '">';
 
        } else {
            $url = $_CONF['site_url']
                 . COM_buildUrl ('/links/portal.php/link/' . $A['lid']);
            $link = '<a href="' . $url . '" title="' . $A['description'] . '">';

        }
        $links[] = $link . stripslashes ($A['title']) . '</a>';
    }
 
    if (count ($links) > 0) {
        if ($random) {
            shuffle($links);
        }
        $retval = COM_makeList ($links, 'list-blogroll');
    }
 
    return $retval;
}

Status: offline

::Ben

Forum User
Full Member
Registered: 14/01/2005
Posts: 1569
Location:la rochelle, France
Hey,

No it didn't know this function. Thanks.

You must also change the code above to avoid sql error. Add a WHERE statement:

PHP Formatted Code

$result = DB_query ("SELECT lid,url,title,description,hits FROM {$_TABLES['links']} WHERE 1=1 " . COM_getPermSql ('AND') . " ORDER BY $sort $order");
 


::Ben
I'm available to customise your themes or plugins for your Geeklog CMS

All times are EST. The time is now 11:21 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content