Welcome to Geeklog, Anonymous Thursday, November 28 2024 @ 01:52 pm EST
Geeklog Forums
Blogroll update for Geeklog 1.5.1
Status: offline
::Ben
Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Just an update to the Blogroll block and a new feature (sort order).
::Ben
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
::Ben
Text 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
9
10
Quote
Status: offline
::Ben
Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Some code is missing from the post above. I try one more time.
::Ben
{
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
::Ben
Text 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
4
6
Quote
Status: offline
::Ben
Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Need a blogroll with all the links from the links plugin. Here it is:
{
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
Text 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
8
11
Quote
Status: offline
Roccivic
Forum User
Moderator
Registered: 05/19/10
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.
{
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;
}
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.
Text 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;
}
8
10
Quote
Status: offline
::Ben
Forum User
Full Member
Registered: 01/14/05
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:
$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
No it didn't know this function. Thanks.
You must also change the code above to avoid sql error. Add a WHERE statement:
Text 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
16
8
Quote
All times are EST. The time is now 01:52 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