4
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:
<?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 -> getConfigsByCat( 0, $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], 0 );
while ( $myrow = $xoopsDB -> fetchArray( $result ) )
{
if ( false == checkXTubeBlockGroups( $myrow['cid'] ) || $myrow['cid'] == 0 )
{
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] -1 ) ) . "...";
}
}
$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 -> getConfigsByCat( 0, $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( $title, 0, ( $options[2] -1 ) ) . "...";
}
}
$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 .= "<input type='hidden' name='options[]' value='";
if ( $options[0] == "date" )
{
$form .= "date'";
}
else
{
$form .= "hits'";
}
$form .= " />";
$form .= "<input type='text' name='options[]' value='" . $options[1] . "' /> " . _MB_XTUBE_FILES . "";
$form .= " <br />" . _MB_XTUBE_CHARS . " <input type='text' name='options[]' value='" . $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 .= "<input type='text' name='options[]' value='" . $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.