Subject: Blogroll update for Geeklog 1.5.1

Posted on: 16/01/09 12:52pm
By: ::Ben

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;
}
 

Re: Blogroll update for Geeklog 1.5.1

Posted on: 20/01/09 05:46am
By: 1000ideen

Would be great if the blogroll became part of the links plugin, this is actually where it belongs to.

Re: Blogroll update for Geeklog 1.5.1

Posted on: 20/01/09 07:57am
By: ::Ben

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;
}

Re: Blogroll update for Geeklog 1.5.1

Posted on: 18/01/11 03:54pm
By: ::Ben

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

Re: Blogroll update for Geeklog 1.5.1

Posted on: 19/01/11 12:43pm
By: Roccivic

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;
}

Re: Blogroll update for Geeklog 1.5.1

Posted on: 20/01/11 06:39am
By: ::Ben

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

Geeklog - Forum
https://www.geeklog.net/forum/viewtopic.php?showtopic=86015