1
pinchecl
Random links
  • 2005/9/5 16:29

  • pinchecl

  • Friend of XOOPS

  • Posts: 193

  • Since: 2005/4/22


I have searched for a module that can present random links in a block. Not just the text link but including the 88x31 image. So far no luck. Does anybody know of such a module or hack? I'm using mylinks

2
tedsmith
Re: Random links
  • 2005/9/13 20:15

  • tedsmith

  • Home away from home

  • Posts: 1151

  • Since: 2004/6/2 1


I have been asked if I could randomise my links pages too (especially the 'Recent Links' section). Would be useful to do rather than being forced to display them in date order (i.e. date of submission).

3
mjoel
Re: Random links
  • 2007/10/12 18:41

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


sorry to bump this old thread...

does anyone know how to make a block to display random link from the mylinks module ??

4
McDonald
Re: Random links
  • 2007/10/12 19:09

  • McDonald

  • Home away from home

  • Posts: 1072

  • Since: 2005/8/15


I am not familiar with mylinks, but recently I added a random block to XoopsTube which is actually based on WF-Links.
This the code used in blocks/xoopstube_top.php:
/**
 * $Id: xoopstube_top.php
 * Module: XoopsTube
 */


/**
 * checkXTubeBlockGroups()
 * 
 * @param integer $cid
 * @param string $permType
 * @param boolean $redirect
 * @return 
 **/
function checkXTubeBlockgroups$cid 0$permType 'XTubeCatPerm'$redirect false )
{
    global 
$xoopsUser;

    
$groups is_object$xoopsUser ) ? $xoopsUser -> getGroups() : XOOPS_GROUP_ANONYMOUS;
    
$gperm_handler = &xoops_gethandler'groupperm' );

    
$module_handler = &xoops_gethandler'module' );
    
$module = &$module_handler -> getByDirname'xoopstube' );

    if ( !
$gperm_handler -> checkRight$permType$cid$groups$module -> getVar'mid' ) ) )
    {
        if ( 
$redirect == false )
        {
            return 
false;
        } 
        else
        {
            
redirect_header'index.php'3_NOPERM );
            exit();
        } 
    } 
    unset( 
$module );
    return 
true;


/**
 * Function: b_xoopstube_top_show
 * Input   : $options[0] = date for the most recent videos
 *                hits for the most popular videos
 *           $block['content'] = The optional above content
 *           $options[1] = How many videos are displayes
 * Output  : Returns the most recent or most popular links
 */
function b_xoopstube_top_show$options )
{
    global 
$xoopsDB$xoopsModuleConfig;

    
$block = array();
    
$modhandler = &xoops_gethandler'module' );
    
$xtubeModule = &$modhandler -> getByDirname'xoopstube' );
    
$config_handler = &xoops_gethandler'config' );
    
$xtubeModuleConfig = &$config_handler -> getConfigsByCat0$xtubeModule -> getVar'mid' ) );

    
$xtubemyts = &MyTextSanitizer :: getInstance();

    
$result $xoopsDB -> query"SELECT lid, cid, title, url, date, hits FROM " $xoopsDB -> prefix'xoopstube_videos' ) . " WHERE published > 0 AND published <= " time() . " AND (expired = 0 OR expired > " time() . ") AND offline = 0 ORDER BY " $options[0] . " DESC"$options[1], );
    while ( 
$myrow $xoopsDB -> fetchArray$result ) )
    {
        if ( 
false == checkXTubeBlockGroups$myrow['cid'] ) || $myrow['cid'] == )
        {
            continue;
        } 
        
$videoload = array();
        
$title $xtubemyts -> htmlSpecialChars$xtubemyts ->stripSlashesGPC($myrow["title"]) );
        
$title2 $xtubemyts -> htmlSpecialChars$xtubemyts ->stripSlashesGPC($myrow["title"]) );

        if ( !
XOOPS_USE_MULTIBYTES )
        {
            if ( 
strlen$myrow['title'] ) >= $options[2] )
            {
                
$title substr$myrow['title'], 0, ( $options[2] -) ) . "...";
            } 
        } 
        
$videoload['id'] = intval($myrow['lid']);
        
$videoload['cid'] = intval($myrow['cid']);
        
$videoload['title'] = $title;
        
$videoload['title2'] = $title2;
        
$videoload['url'] = $myrow['url'];
        if ( 
$options[0] == "date" )
        {
            
$videoload['date'] = formatTimestamp$myrow['date'], $xtubeModuleConfig['dateformat'] );
        } 
            elseif ( 
$options[0] == "hits" )
        {
            
$videoload['hits'] = $myrow['hits'];
        }
        
$videoload['dirname'] = $xtubeModule -> getVar'dirname' );
        
$videoload['shotwidth'] = $xtubeModuleConfig['shotwidth'];
        
$videoload['shotheight'] = $xtubeModuleConfig['shotheight'];
        
$videoload['balloon'] = $videoload['title2'] . " (" $videoload['date']. ")";
        
$block['videos'][] = $videoload;
    } 
    unset( 
$_block_check_array );
    return 
$block;


/**
 * Function: b_xoopstube_random
 * Input   : $options[0] = date for the most recent videos
 *                hits for the most popular videos
 *           $block['content'] = The optional above content
 *           $options[1] = How many videos are displayes
 * Output  : Returns random video
 */
function b_xoopstube_random$options )
{
    global 
$xoopsDB$xoopsModuleConfig;

    
$block = array();
    
$modhandler = &xoops_gethandler'module' );
    
$xtubeModule = &$modhandler -> getByDirname'xoopstube' );
    
$config_handler = &xoops_gethandler'config' );
    
$xtubeModuleConfig = &$config_handler -> getConfigsByCat0$xtubeModule -> getVar'mid' ) );

    
$result2 $xoopsDB -> query"SELECT lid, cid, title, url, date FROM " $xoopsDB -> prefix'xoopstube_videos' ) . " WHERE published > 0 AND published <= " time() . " AND (expired = 0 OR expired > " time() . ") AND offline = 0 ORDER BY RAND() LIMIT 1 ");
    list(
$lid$cid$title$url$date) = $xoopsDB -> fetchRow($result2);

        
$block['balloon'] = $title;
        if ( !
XOOPS_USE_MULTIBYTES )
        {
            if ( 
strlen$title ) >= $options[2] )
            {
                
$title substr$title0, ( $options[2] -) ) . "...";
            } 
        }
        
$block['id'] = intval($lid);
        
$block['cid'] = intval($cid);
        
$block['title'] = $title;
        
$block['url'] = $url;
        
$block['date'] = formatTimestamp$date$xtubeModuleConfig['dateformat'] );
        
$block['dirname'] = $xtubeModule -> getVar'dirname' );
        
$block['shotwidth'] = $xtubeModuleConfig['shotwidth'];
        
$block['shotheight'] = $xtubeModuleConfig['shotheight'];

    unset( 
$_block_check_array );
    return 
$block;
}

/**
 * b_xoopstube_top_edit()
 * 
 * @param $options
 * @return 
 **/
function b_xoopstube_top_edit$options )
{
    
$form "" _MB_XTUBE_DISP " ";
    
$form .= ";
    if ( 
$options[0] == "date" )
    {
        
$form .= "date'";
    } 
    else
    {
        
$form .= "hits'";
    } 
    
$form .= " />";
    
$form .= "$options[1] . "' /> " _MB_XTUBE_FILES "";
    
$form .= _MB_XTUBE_CHARS $options[2] . "' /> " _MB_XTUBE_LENGTH "";
    return 
$form;
}

/**
 * b_xoopstube_random_edit()
 * 
 * @param $options
 * @return 
 **/
function b_xoopstube_random_edit$options )
{
    
$form "" _MB_XTUBE_CHARS " ";
    
$form .= "$options[2] . "' /> " _MB_XTUBE_LENGTH "";
    return 
$form;
}

?>


Other files to hack are:
- xoops_version.php
- languages/english/modinfo.php
You also have to create a new template for this block.

5
riceking
Re: Random links
  • 2007/10/13 1:39

  • riceking

  • Just popping in

  • Posts: 16

  • Since: 2007/9/21


At first, I think there is not the existing block which meets your need, for your need is someting special.

The only way is to hack the Mylinks module.
1)To get random link, you could use the MySQL sql.
for example, to get 5 random link from table 'linktable' in database, the sql could be:
select * from linktable order by rand() limit 0,5;

2)To get image with text, just modify block template. And it's very easy to be done if you konw about HTML.

Good luck!

6
McDonald
Re: Random links
  • 2007/10/13 9:34

  • McDonald

  • Home away from home

  • Posts: 1072

  • Since: 2005/8/15


Hereby a guide.

First add these lines to mylinks/xoops_version.php
$modversion['blocks'][3]['file'] = "mylinks_top.php";
$modversion['blocks'][3]['name'] = _MI_MYLINKS_BNAME3;
$modversion['blocks'][3]['description'] = "Shows random web links";
$modversion['blocks'][3]['show_func'] = "b_mylinks_random";
$modversion['blocks'][3]['edit_func'] = "b_mylinks_random_edit";
$modversion['blocks'][3]['options'] = "random|1|19";
$modversion['blocks'][3]['template'] = 'mylinks_block_random.html';

after
$modversion['blocks'][2]['file'] = "mylinks_top.php";
$modversion['blocks'][2]['name'] = _MI_MYLINKS_BNAME2;
$modversion['blocks'][2]['description'] = "Shows most visited web links";
$modversion['blocks'][2]['show_func'] = "b_mylinks_top_show";
$modversion['blocks'][2]['edit_func'] = "b_mylinks_top_edit";
$modversion['blocks'][2]['options'] = "hits|10|25";
$modversion['blocks'][2]['template'] = 'mylinks_block_top.html';


Add the following to mylinks/languages/english/modinfo.php
define("_MI_MYLINKS_BNAME3","Random Link");


Replace the file mylinks/blocks/mylinks_top.php with this one:
// $Id: mylinks_top.php,v 1.11 2004/12/26 19:11:56 Onokazu Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                                                    //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
/******************************************************************************
 * Function: b_mylinks_top_show
 * Input   : $options[0] = date for the most recent links
 *                    hits for the most popular links
 *           $block['content'] = The optional above content
 *           $options[1]   = How many reviews are displayes
 * Output  : Returns the desired most recent or most popular links
 ******************************************************************************/
function b_mylinks_top_show($options) {
    global 
$xoopsDB;
    
$block = array();
    
$myts =& MyTextSanitizer::getInstance();
    
$result $xoopsDB->query("SELECT lid, cid, title, date, hits FROM ".$xoopsDB->prefix('mylinks_links')." WHERE status>0 ORDER BY ".$options[0]." DESC",$options[1],0);
    while(
$myrow $xoopsDB->fetchArray($result)){
        
$link = array();
        
$title $myts->makeTboxData4Show($myrow["title"]);
        if ( !
XOOPS_USE_MULTIBYTES ) {
            if (
strlen($myrow['title']) >= $options[2]) {
                
$title $myts->makeTboxData4Show(substr($myrow['title'],0,($options[2] -1)))."...";
            }
        }
        
$link['id'] = $myrow['lid'];
        
$link['cid'] = $myrow['cid'];
        
$link['title'] = $title;
        if(
$options[0] == "date"){
            
$link['date'] = formatTimestamp($myrow['date'],'s');
        }elseif(
$options[0] == "hits"){
            
$link['hits'] = $myrow['hits'];
        }
        
$block['links'][] = $link;
    }
    return 
$block;
}

function 
b_mylinks_random$options )
{
global 
$xoopsDB$xoopsModuleConfig;
    
$block = array();
    
$myts =& MyTextSanitizer::getInstance();
    
$result $xoopsDB->query("SELECT lid, cid, title, url, date, logourl FROM ".$xoopsDB->prefix('mylinks_links')." WHERE status>0 ORDER BY RAND() LIMIT 1 ");
    while(
$myrow $xoopsDB->fetchArray($result)){

        
$title $myts->makeTboxData4Show($myrow["title"]);
        if ( !
XOOPS_USE_MULTIBYTES )
                 {
                    if ( 
strlen$title ) >= $options[2] )
                    {
                      
$title substr$title0, ( $options[2] -) ) . "...";
                    } 
                 }
        
$block['id'] = $myrow['lid'];
        
$block['cid'] = $myrow['cid'];
        
$block['title'] = $title;
        
$block['url'] = $url;
        
$block['logourl'] = $myrow['logourl'];
        
$block['date'] = formatTimestamp($myrow['date'],'s');
        
//$block['random'][] = $random;
    
}
    return 
$block;
}

function 
b_mylinks_top_edit($options) {
    
$form ""._MB_MYLINKS_DISP." ";
    
$form .= ";
    if(
$options[0] == "date"){
        
$form .= "date'";
    }else {
        
$form .= "hits'";
    }
    
$form .= " />";
    
$form .= ".$options[1]."' /> "._MB_MYLINKS_LINKS."";
    
$form .= 
"
._MB_MYLINKS_CHARS..$options[2]."' /> "._MB_MYLINKS_LENGTH."";

    return 
$form;
}

function 
b_mylinks_random_edit$options )
{
    
$form "" _MB_MYLINKS_CHARS " ";
    
$form .= "$options[2] . "' /> " _MB_MYLINKS_LENGTH "";
    return 
$form;
}
?>


Create a file called mylinks_block_random.html in the folder mylinks/templates/blocks. This is the code for this file:
<div align="center">

<
a href="<{$xoops_url}>/modules/mylinks/visit.php?cid=<{$block.cid}>&lid=<{$block.id}>"><{$block.title}>a>

<
br />

<{
$block.date}>

<
br />
            
<
a href="<{$xoops_url}>/modules/mylinks/visit.php?cid=<{$block.cid}>&lid=<{$block.id}>" target="_blank"> <img src="<{$xoops_url}>/modules/mylinks/images/shots/<{$block.logourl}>" width="88" height="31" alt=""/>a
      
div>


Good luck!!!

7
mjoel
Re: Random links
  • 2007/10/13 12:31

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


thanks brother

just one more question....
it is possible to include the the option to choose how many random links to be display just like the recent and top links block....

8
McDonald
Re: Random links
  • 2007/10/13 13:07

  • McDonald

  • Home away from home

  • Posts: 1072

  • Since: 2005/8/15


Quote:

mjoel wrote:

just one more question....
it is possible to include the the option to choose how many random links to be display just like the recent and top links block....


I am working on that for XoopsTube already.
Creating the option is not the problem, but making it work is...

9
mjoel
Re: Random links
  • 2007/10/13 18:25

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


thanks Mc you have been a great help

i will try to modify it myself on the number of random links to be display..if i'm successful i will post it here


10
McDonald
Re: Random links
  • 2007/10/13 19:04

  • McDonald

  • Home away from home

  • Posts: 1072

  • Since: 2005/8/15


There are some typos in mylinks/blocks/mylinks_top.php
Replacing it with this one should fix it:
// $Id: mylinks_top.php,v 1.11 2004/12/26 19:11:56 Onokazu Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                                                    //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
/******************************************************************************
 * Function: b_mylinks_top_show
 * Input   : $options[0] = date for the most recent links
 *                    hits for the most popular links
 *           $block['content'] = The optional above content
 *           $options[1]   = How many reviews are displayes
 * Output  : Returns the desired most recent or most popular links
 ******************************************************************************/
function b_mylinks_top_show($options) {
    global 
$xoopsDB;
    
$block = array();
    
$myts =& MyTextSanitizer::getInstance();
    
$result $xoopsDB->query("SELECT lid, cid, title, date, hits FROM ".$xoopsDB->prefix('mylinks_links')." WHERE status>0 ORDER BY ".$options[0]." DESC",$options[1],0);
    while(
$myrow $xoopsDB->fetchArray($result)){
        
$link = array();
        
$title $myts->makeTboxData4Show($myrow["title"]);
        if ( !
XOOPS_USE_MULTIBYTES ) {
            if (
strlen($myrow['title']) >= $options[2]) {
                
$title $myts->makeTboxData4Show(substr($myrow['title'],0,($options[2] -1)))."...";
            }
        }
        
$link['id'] = $myrow['lid'];
        
$link['cid'] = $myrow['cid'];
        
$link['title'] = $title;
        if(
$options[0] == "date"){
            
$link['date'] = formatTimestamp($myrow['date'],'s');
        }elseif(
$options[0] == "hits"){
            
$link['hits'] = $myrow['hits'];
        }
        
$block['links'][] = $link;
    }
    return 
$block;
}

function 
b_mylinks_random$options )
{
         global 
$xoopsDB;
     
$block = array();
     
$myts =& MyTextSanitizer::getInstance();
     
$result $xoopsDB -> query("SELECT lid, cid, title, url, logourl, date FROM " $xoopsDB -> prefix('mylinks_links') . " WHERE status>0 ORDER BY RAND() LIMIT 1 ");
     while(
$myrow $xoopsDB->fetchArray($result)){
                
$link = array();
        
$title $myts->makeTboxData4Show($myrow["title"]);
        if ( !
XOOPS_USE_MULTIBYTES ) {
            if (
strlen($myrow['title']) >= $options[2]) {
                
$title $myts->makeTboxData4Show(substr($myrow['title'],0,($options[2] -1)))."...";
            }
        }
        
$link['id'] = $myrow['lid'];
        
$link['cid'] = $myrow['cid'];
        
$link['title'] = $title;
        
$link['url'] = $myrow['url'];
        
$link['logourl'] = $myrow['logourl'];
        
$link['date'] = formatTimestamp($myrow['date'],'s');
        
$block['links'][] = $link;
    }
    return 
$block;
}

function 
b_mylinks_top_edit($options) {
    
$form ""._MB_MYLINKS_DISP." ";
    
$form .= ";
    if(
$options[0] == "date"){
        
$form .= "date'";
    }else {
        
$form .= "hits'";
    }
    
$form .= " />";
    
$form .= ".$options[1]."' /> "._MB_MYLINKS_LINKS."";
    
$form .= 
"
._MB_MYLINKS_CHARS..$options[2]."' /> "._MB_MYLINKS_LENGTH."";

    return 
$form;
}

function 
b_mylinks_random_edit$options )
{
    
$form =  "" _MB_MYLINKS_DISP " ";
    
$form .= ";
    
$form .= "random'";
    
$form .= " />";
    
$form .= "$options[1] . "' /> " _MB_MYLINKS_LINKS "";
    
$form .= _MB_MYLINKS_CHARS $options[2] . "' /> " _MB_MYLINKS_LENGTH "";
    return 
$form;
}
?>


And change the content of mylinks_block_random.html to:
<{foreach item=link from=$block.links}>
<
div align="center">

<
a href="<{$xoops_url}>/modules/mylinks/visit.php?cid=<{$link.cid}>&lid=<{$link.id}>"><{$link.title}>a>

<
br />

<{
$link.date}>

<
br />
            
<
a href="<{$xoops_url}>/modules/mylinks/visit.php?cid=<{$link.cid}>&lid=<{$link.id}>" target="_blank"> <img src="<{$xoops_url}>/modules/mylinks/images/shots/<{$link.logourl}>" width="88" height="31" alt=""/>a>
      
div>
<{/foreach}>


Now you also have the option to set the amount of random links displayed in the block, but the setting isn't used...yet.

Login

Who's Online

169 user(s) are online (80 user(s) are browsing Support Forums)


Members: 0


Guests: 169


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits