1
xsell
adding Function to Block
  • 2009/8/28 20:43

  • xsell

  • Quite a regular

  • Posts: 245

  • Since: 2008/9/2 1


Hello

I have A module with one Block , this Module For ShoutBox ,
the block Shows the Messages , Has One Option to set How many Message the ShoutBox Shows up ..

I intergated to the Block Badword filter .. to enable or disable the Bad word filter i use .
$Badwordfilter 0;
0 for Off 1 for on

I need to make this Option Done from the Blocks on the Control Module , when click Edit block and there be able set it to 0 or 1 instaed editing the File from ftp .

this the block after i edited it..

<?php
include("../../../mainfile.php");
include_once 
XOOPS_ROOT_PATH."/modules/message/send.textsanitizer.php";
function 
b_send_blocks_show($options) {

    global 
$xoopsUser$xoopsConfig$xoopsDB$xoopsModule$xoopsTheme;
    
$block = array();
    
$myts =& sendTextSanitizer::getInstance();
 
$sql=$xoopsDB->query("select count(xid) from ".$xoopsDB->prefix("send"));
 include_once 
XOOPS_ROOT_PATH."/include/xoopscodes.php";
list(
$numrows) = $xoopsDB->fetchRow($sql);
$result $xoopsDB->query("SELECT name, message, submitter, ip, date FROM ".$xoopsDB->prefix("message")." order by xid desc limit ".$options[1]."");

    while(
$myrow $xoopsDB->fetchArray($result)){
    
$message= array();
    
    
$Badwordfilter 0;  // on or off
        
$message['name'] = $myts->htmlSpecialChars($myrow['name']);
             
$message['comment'] = $myts->makeTareaData4Show(SmartCensor($myrow['comment'], $Badwordfilter),0);
        
$message['date'] = formatTimestamp($myrow['date'],'m');
            
$block['lang_name'] = _MB_MESSAGENAME;
        
$block['lang_mesage'] = _MB_MESSAGE_COMMENT;
        
$block['lang_date'] = _MB_MESSAGEDATE;
        
$block['lang_submit'] = _MB_MESSAGESUBMIT;
        
$block['lang_guestuser'] = _MB_MESSAGEGUESTUSER;
        
$block['message'][] = $message;
    }
      return 
$block;
}
function 
b_message_blocks_edit($options) {
    
$form ""._MB_MESSAGE_DISP."&nbsp;";
    
$form .= "<input type='hidden' name='options[]' value='";
    
$form .= "date'";
    
$form .= " />";
    
$form .= "<input type='text' name='options[]' value='".$options[1]."' />&nbsp;"._MB_MESSAGE_NUM."";
    return 
$form;
}

?>


this the part for the block in xoops_version.php

// Blocks
$modversion['blocks'][1]['file'] = "message_blocks.php";
$modversion['blocks'][1]['name'] = _MI_MESSAGE_TITLE;
$modvertion['blocks'][1]['description'] = "MESSAGE";
$modversion['blocks'][1]['show_func'] = "b_message_blocks_show";
$modversion['blocks'][1]['edit_func'] = "b_message_blocks_edit";
$modversion['blocks'][1]['can_clone'] = true ;
$modversion['blocks'][1]['options'] = "date|10|19";
$modversion['blocks'][1]['template'] = 'message_blocks.html';

2
trabis
Re: adding Function to Block
  • 2009/8/29 7:06

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


<?php
include("../../../mainfile.php");
include_once 
XOOPS_ROOT_PATH."/modules/message/send.textsanitizer.php";
function 
b_send_blocks_show($options) {

    global 
$xoopsUser$xoopsConfig$xoopsDB$xoopsModule$xoopsTheme;
    
$block = array();
    
$myts =& sendTextSanitizer::getInstance();
 
$sql=$xoopsDB->query("select count(xid) from ".$xoopsDB->prefix("send"));
 include_once 
XOOPS_ROOT_PATH."/include/xoopscodes.php";
list(
$numrows) = $xoopsDB->fetchRow($sql);
$result $xoopsDB->query("SELECT name, message, submitter, ip, date FROM ".$xoopsDB->prefix("message")." order by xid desc limit ".$options[1]."");

    while(
$myrow $xoopsDB->fetchArray($result)){
    
$message= array();
    
    
$Badwordfilter $options[0];  // on or off
        
$message['name'] = $myts->htmlSpecialChars($myrow['name']);
             
$message['comment'] = $myts->makeTareaData4Show(SmartCensor($myrow['comment'], $Badwordfilter),0);
        
$message['date'] = formatTimestamp($myrow['date'],'m');
            
$block['lang_name'] = _MB_MESSAGENAME;
        
$block['lang_mesage'] = _MB_MESSAGE_COMMENT;
        
$block['lang_date'] = _MB_MESSAGEDATE;
        
$block['lang_submit'] = _MB_MESSAGESUBMIT;
        
$block['lang_guestuser'] = _MB_MESSAGEGUESTUSER;
        
$block['message'][] = $message;
    }
      return 
$block;
}
function 
b_message_blocks_edit($options) {
    
$form ""._MB_MESSAGE_DISP."&nbsp;";
    
$form .= "<input type='hidden' name='options[0]' value='";
    
$form .= "date'";
    
$form .= " />";
    
$form .= "<input type='text' name='options[0]' value='".$options[0]."' />&nbsp;"._MB_MESSAGE_NUM."";
    return 
$form;
}

?>


Try this.
I noticed you are using $option[1] in your query and it is not present on your form. You may need to add that also.

3
xsell
Re: adding Function to Block
  • 2009/8/29 18:06

  • xsell

  • Quite a regular

  • Posts: 245

  • Since: 2008/9/2 1


Thx Man ,

But it did not work , when edited like u Did , i get The Same thing in the Block Option but the Fild Box filled already with word 'date' .

the code i send first has errors , this is the Working Code , the Module Has only this block .
<?php
include("../../../mainfile.php");
include_once 
XOOPS_ROOT_PATH."/modules/message/message.textsanitizer.php";
function 
b_message_blocks_show($options) {
    global 
$xoopsUser$xoopsConfig$xoopsDB$xoopsModule$xoopsTheme;
    
$block = array();
    
$myts =& messageTextSanitizer::getInstance();
 
$sql=$xoopsDB->query("select count(xid) from ".$xoopsDB->prefix("message"));
 include_once 
XOOPS_ROOT_PATH."/include/xoopscodes.php";
list(
$numrows) = $xoopsDB->fetchRow($sql);
$result $xoopsDB->query("SELECT name, comment, submitter, ip, date FROM ".$xoopsDB->prefix("message")." order by xid desc limit ".$options[1]."");
include 
XOOPS_ROOT_PATH."/modules/message/badwords.php";
    while(
$myrow $xoopsDB->fetchArray($result)){
    
$message= array();
    
$Badwordfilter $xoopsModuleConfig['message'];  //
        
$message['name'] = $myts->htmlSpecialChars($myrow['name']);
             
$message['comment'] = $myts->makeTareaData4Show(SmartCensor($myrow['comment'], $Badwordfilter),0);
        
$message['date'] = formatTimestamp($myrow['date'],'m');
            
$block['lang_xname'] = _MB_MESSAGENAME;
        
$block['lang_xcomment'] = _MB_MESSAGE_COMMENT;
        
$block['lang_xdate'] = _MB_MESSAGEDATE;
        
$block['lang_xsubmit'] = _MB_MESSAGESUBMIT;
        
$block['lang_guestuser'] = _MB_MESSAGEGUESTUSER;
        
$block['message'][] = $message;
    }
      return 
$block;
}
function 
b_message_blocks_edit($options) {
    
$form ""._MB_MESSAGE_DISP."&nbsp;";
    
$form .= "<input type='hidden' name='options[]' value='";
    
$form .= "date'";
    
$form .= " />";
    
$form .= "<input type='text' name='options[]' value='".$options[1]."' />&nbsp;"._MB_MESSAGE_NUM."";
    return 
$form;
}

?>


2- i tried to do this .
edited xoops_version.php to look like
$modversion['config'][1]['name'] = 'message';
$modversion['config'][1]['title'] = '_MI_MESAAGE';
$modversion['config'][1]['description'] = '';
$modversion['config'][1]['formtype'] = 'textbox';
$modversion['config'][1]['valuetype'] = 'int';


in the block i edited it to
$Badwordfilter $xoopsModuleConfig['message'];


that did not work .. Look stupid .. i'm not any of php Guy .. just learning lol

4
optikool
Re: adding Function to Block
  • 2009/9/18 16:14

  • optikool

  • Not too shy to talk

  • Posts: 154

  • Since: 2007/3/26


Hi xsell,

Your code should look similar to this... If after you make the changes date still appears in the box, just change it to a number or uninstall and reinstall your module so the database is refreshed. Also in b_message_blocks_show you should make sure you are getting an integer by using is_number($options[1]) and/or (int) $options[1] so that your query string is limited by an integer and not a string.

Your Block File message_blocks.php... Looks like you were missing the 1 in options[] for message number input under b_message_blocks_edit.
<?php
include ("../../../mainfile.php");
include_once 
XOOPS_ROOT_PATH."/modules/message/message.textsanitizer.php";
function 
b_message_blocks_show($options)
{
    global 
$xoopsUser$xoopsConfig$xoopsDB$xoopsModule$xoopsTheme;
    
$block = array ();
    
$myOption = (int) $options[1];
    
$myts = & messageTextSanitizer::getInstance();
    
$sql $xoopsDB->query("select count(xid) from ".$xoopsDB->prefix("message"));
    include_once 
XOOPS_ROOT_PATH."/include/xoopscodes.php";
    list (
$numrows) = $xoopsDB->fetchRow($sql);
    
$result $xoopsDB->query("SELECT name, comment, submitter, ip, date FROM ".$xoopsDB->prefix("message")." order by xid desc limit ".$myOption."");
    include 
XOOPS_ROOT_PATH."/modules/message/badwords.php";
    while (
$myrow $xoopsDB->fetchArray($result))
    {
        
$message = array ();
        
$Badwordfilter $xoopsModuleConfig['message']; //
        
$message['name'] = $myts->htmlSpecialChars($myrow['name']);
        
$message['comment'] = $myts->makeTareaData4Show(SmartCensor($myrow['comment'], $Badwordfilter), 0);
        
$message['date'] = formatTimestamp($myrow['date'], 'm');
        
$block['lang_xname'] = _MB_MESSAGENAME;
        
$block['lang_xcomment'] = _MB_MESSAGE_COMMENT;
        
$block['lang_xdate'] = _MB_MESSAGEDATE;
        
$block['lang_xsubmit'] = _MB_MESSAGESUBMIT;
        
$block['lang_guestuser'] = _MB_MESSAGEGUESTUSER;
        
$block['message'][] = $message;
    }
    return 
$block;
}
function 
b_message_blocks_edit($options)
{
    
$form ""._MB_MESSAGE_DISP."&nbsp;";
    
$form .= "<input type='hidden' name='options[]' value='";
    
$form .= "date'";
    
$form .= " />";
    
$form .= "<input type='text' name='options[1]' value='".$options[1]."' />&nbsp;"._MB_MESSAGE_NUM."";
    return 
$form;
}

?>


Your Block Config section in xoops_version.php. Take not of the formtype and default.
<?php
$x 
0;
$modversion['config'][$x]['name'] = 'message';
$modversion['config'][$x]['title'] = '_MI_MESAAGE';
$modversion['config'][$x]['description'] = '';
$modversion['config'][$x]['formtype'] = 'yesno';
$modversion['config'][$x]['valuetype'] = 'int';
$modversion['config'][$x]['default'] = 0;
?>


Your Blocks section in xoops_version.php
<?php
// Blocks
$modversion['blocks'][1]['file'] = "message_blocks.php";
$modversion['blocks'][1]['name'] = _MI_MESSAGE_TITLE;
$modvertion['blocks'][1]['description'] = "MESSAGE";
$modversion['blocks'][1]['show_func'] = "b_message_blocks_show";
$modversion['blocks'][1]['edit_func'] = "b_message_blocks_edit";
$modversion['blocks'][1]['can_clone'] = true ;
$modversion['blocks'][1]['options'] = "date|10|19";
$modversion['blocks'][1]['template'] = 'message_blocks.html';
?>


Hope this helps...
Optikool

Login

Who's Online

152 user(s) are online (103 user(s) are browsing Support Forums)


Members: 0


Guests: 152


more...

Donat-O-Meter

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

Latest GitHub Commits