11
kaotik
Re: Xajax+Xoops Smarty Templates
  • 2006/10/31 12:19

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


I've just been rereading this post and see that Mithrandir had already pointed me in the right direction..... I really should have investigated further.... Thanks Mithrandir!

12
Mithrandir
Re: Xajax+Xoops Smarty Templates

I did wonder, whether there was any difference from what I had said

Any time.
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

13
culex
Re: Xajax+Xoops Smarty Templates
  • 2009/7/19 11:18

  • culex

  • Module Developer

  • Posts: 711

  • Since: 2004/9/23


I have a related problem so why not place in this thread.

I would like to refresh the block using javascript / ajax. I have in the onair module a value that get updated every time a new song starts in winamp, but you have to surf the pages / or F5 to see the value changing.

simple_block.php checks the data base and writes all info into an array $messages that get placed in a scroller
and next upcomming event $messagenext into scroller


I simply cannot get the xajax or javascript to process it all.

I had written a javascript loadXMLDoc that would run a phpfile, and place in divs. But this also doesnt work.

Guess I just cant make my head understand this. Any help would be apreciated.

My module can be downloaded here
http://www.culex.dk/modules/PDdownloads/visit.php?cid=2&lid=3
Programming is like sex:
One mistake and you have to support it for the rest of your life.

14
frankblack
Re: Xajax+Xoops Smarty Templates
  • 2009/7/19 22:44

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


Erm, downloaded the module, looked at the code, but where is the connection to XAJAX? Did not found any function that is associated with XAJAX.

If you like, I give you a working example for a block. Just to be sure: XOOPS-Debug is turned off? And XAJAX-Debug is turned on (if there is any xajax)?

OK, give you the code anyway. What does the xajax do is simple: query the database for radiostations, display it in a pulldown and depending on the kind of stream a button will be displayed.

Code for block:
function debaser_showradio() {

        require_once 
DEBASER_ROOT.'/include/functions.php';
        require_once 
DEBASER_ROOT.'/xajax/xajax_core/xajax.inc.php';

        
$xajaxb = new xajax();

        if(isset(
$xajaxb)) $radio = &$xajaxb->register(XAJAX_FUNCTION'xajaxradio');
        
// Uncomment the next line for debugging purposes
        //$xajaxb->setFlag('debug', true);
    // this check for defines is because processRequest is not allowed
    // to be started anywhere else at the same time, but this is only
    // important if other modules or parts of the current module is
    // using XAJAX
        
if (defined('_XDEBSINGLEFILE') || defined('_XDEBGENRE') || defined('_XDEBTV')) {
            
// do nothing here
        
} else {
            
$xajaxb->processRequest();
        }

        
$Xjavapath DEBASER_URL.'/xajax/';
        
$xajaxjavaradio $xajaxb->getJavascript($Xjavapath);

    global 
$xoopsDB;

        
$myts =& MyTextSanitizer::getInstance();
        
$block = array();
$block['xajax'] = $xajaxjavaradio;
        
$result $xoopsDB->query("SELECT radio_id, radio_name, canplay FROM ".$xoopsDB->prefix('debaserradio')." ORDER BY radio_name ASC");

    
$radiolist = array();

    
$seloptions '';

    while (list(
$radio_id$radio_name$canplay) = $xoopsDB->fetchRow($result)) {
        
$seloptions .= '.$radio_id.'">'.$radio_name.'';
    }
    
$radiolist['options'] = $seloptions;

    
$block['radiolist'][] = $radiolist;


    return 
$block;
}


The XAJAX-function:
function xajaxradio($arg) {
        global 
$xoopsDB;

    
$radioselect $arg['radioselect'];

    
$result1 $xoopsDB->query("SELECT radio_id, radio_stream, canplay FROM ".$xoopsDB->prefix('debaserradio')." WHERE radio_id = ".intval($radioselect)."");
    list(
$radio_id$radio_stream$canplay) = $xoopsDB->fetchRow($result1);
    
$canplayarray explode(' '$canplay);

    
$result2 $xoopsDB->query("SELECT xpid, name, html_code, playericon FROM ".$xoopsDB->prefix('debaser_player')." WHERE xpid IN (".implode(', 'array_map('intval'$canplayarray)).")");

    
$imagerow '';

        while(
$fetch $xoopsDB->fetchArray($result2)) {
    if (
$fetch['html_code'] == 'external') {
        
$imagerow .= '.$radio_stream.'" target="_blank">.DEBASER_IMG.'/playericons/'.$fetch['playericon'].'" alt="'.$fetch['name'].'" title="'.$fetch['name'].'" />';
    } else {
    
$imagerow .= '.$fetch['xpid'].'" id="button'.$fetch['xpid'].'" value="'.$fetch['xpid'].'" onclick="javascript:openWithSelfMain(''.DEBASER_URL.'/radiopopup.php?radio='+document.radiolist.radioselect.options[document.radiolist.radioselect.selectedIndex].value+'&player='.$fetch['xpid'].'','player',10,10)" />.DEBASER_IMG.'/playericons/'.$fetch['playericon'].'" width="20" height="20" alt="'.$fetch['name'].'" title="'.$fetch['name'].'" /> ';
    }
        }

    
$content $imagerow;
    
$objResponse = new xajaxResponse();
    
$objResponse->assign("radiolistresponse","innerHTML"$content);
    return 
$objResponse;
    }


The HTML for the block:
<{$block.xajax}>
<
form style="margin:0px; padding:2px;" name="radiolist" id="radiolist" method="post" action="radio_block.php">
<
select id="radioselect" name="radioselect" onchange="xajax_xajaxradio(this.options[this.selectedIndex].value)">
<
option>-<{$smarty.const._MB_DEBASERRAD_CHO}>-option>
<{foreach 
item=radiolist from=$block.radiolist}>    
<{
$radiolist.options}>
<{/foreach}>
select>
form>
<
div id="radiolistresponse">div>


HTH



15
culex
Re: Xajax+Xoops Smarty Templates
  • 2009/7/20 8:45

  • culex

  • Module Developer

  • Posts: 711

  • Since: 2004/9/23


ah yeah sorry, I didnt put any connection on the module in my website only in the testing server, but had mayor problems getting the block to update properly. I was working with a custom javascript at first that call a php file to put content into the block, but it's more nice to use the templates, smarty.

Excellent thread this, but just needed the last kick to make this Xajax be clear for me. I see from your example I was not too far from getting it.

Only difference realy is that I need this to update based on date() forinstance every 1 min insted of $arg being a selection, and I need 2 ajax functions to fill the containers, but this indeed looks very promising using your help :)

P.S If your exp. makes it all come together I will be sure to credit you in Caps in the functions ;)
Programming is like sex:
One mistake and you have to support it for the rest of your life.

16
culex
Re: Xajax+Xoops Smarty Templates
  • 2009/7/20 16:32

  • culex

  • Module Developer

  • Posts: 711

  • Since: 2004/9/23


Hmmm I still am missing something or maybe not quite understanding how to do it.

I succesfully included xajax, but still I cant get it to run how I want, so backed up to original again.

What I am looking for is actually just a block-refresh.

To automaticly every 1 min to run a update block (php-template).
Programming is like sex:
One mistake and you have to support it for the rest of your life.

17
frankblack
Re: Xajax+Xoops Smarty Templates
  • 2009/7/21 12:09

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13



18
culex
Re: Xajax+Xoops Smarty Templates
  • 2009/7/21 22:08

  • culex

  • Module Developer

  • Posts: 711

  • Since: 2004/9/23


yeah something like this. I was doodling with this a little but for some reason got an xajax error from debug telling "url/xajax/ect etc/" couldn't be reached. The url the debug showed was correct though :oS. I'll look into this tomorrow.
Programming is like sex:
One mistake and you have to support it for the rest of your life.

19
culex
Re: Xajax+Xoops Smarty Templates
  • 2009/7/26 14:37

  • culex

  • Module Developer

  • Posts: 711

  • Since: 2004/9/23


And so I did, however I managede to ¤4# up my website totally and had to restore from backup hehe... (rule nr one, if you are not sure what your doing don't do it on your website use a local test server) :) well being that more clever I managed to make the thing go using both a simple small ajax rutine and jquery (looks better)..

Now my problem is that, eventhough it runs, updates, it doesnt change the divs but seem to be using cached values. This is what I got so far.

1) The block main function runs using template 1.
2) block function 1 doesnt really do anything except set the block template 1.
2.1) this template 1 has ajax that calls block function #2 + block template 2 and run the function to fill template2 used in filling the divs in visible block 1.
3) this rutine is being run every 10 seconds.

(confused? I understand! Its a mess but I'm picking up a small notes as I go along hopefully).

here are the functions
Block function 1
Quote:
/**
* Onair Module
*
* Use this to show details, picture and schedule of timed events in a block.
*
* LICENSE
*
* 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.
*
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @author Michael Albertsen (culex) <http://www.culex.dk>
* @version $Id:simple_now.php 2009-06-19 13:29 culex $
* @since File available since Release 1.0.0
*/

/**
* Create data for block
*
* @param Place $Block getting data
* @param integer $repeat 1
* @return Status
*/
function b_Onair_Show() {
include_once XOOPS_ROOT_PATH.'/modules/onair/include/functions.php';
global $xoopsDB,$xoopsModuleConfig, $XoopsConfig;
$oa_lng = onair_GetModuleOption('language');
if ( file_exists(XOOPS_ROOT_PATH.'/modules/onair/language/'.$oa_lng.'/blocks.php') ) {
include(XOOPS_ROOT_PATH.'/modules/onair/language/'.$oa_lng.'/blocks.php');
}
else {
include(XOOPS_ROOT_PATH.'/modules/onair/language/english/blocks.php');
}
// Get data now
$nowday=date('w');
// Set absolute maximum time of the day
$nextstop="23:59:59";
// Get dir, hight, width, and timetype from config
$oa_imagedir = onair_GetModuleOption('imagedir');
$oa_shothigh = onair_GetModuleOption('shotheight');
$oa_shotwide = onair_GetModuleOption('shotwidth');
$timetype = onair_GetModuleOption('timetype');

// IF timetype = American (12 hour am/pm)
if ($timetype=='1')
{ $nowtime =date('h:i:s a'); }
// IF european time (24 hour)
else if ($timetype=='0'){$nowtime =date('H:i:s');}
$block = array();
$myts =& MyTextSanitizer::getInstance();

// Get data according to current time
$sql = "SELECT * FROM ".$xoopsDB->prefix("oa_program")." WHERE ('$nowtime' BETWEEN oa_start AND oa_stop) AND '$nowday' = oa_day ORDER BY oa_day,oa_start LIMIT 1";
$result=$xoopsDB->queryF($sql);
if ($xoopsDB->getRowsNum($result)>'1') {
$dayoffset='1';
} else {
$dayoffset='0';
}
while($myrow=$xoopsDB->fetchArray($result))
{
$limiter = $myrow['oa_stop'];
$message = array();
$oa_pluginname = $myrow['oa_plugin'];
include XOOPS_ROOT_PATH.'/modules/onair/plugins/plugins.php';
$message['id'] = $myrow['oa_id'];
$message['day'] = onair_Numbers2DaysBlock($myrow['oa_day']);
if ($timetype=='1'){
$message['start'] = date('h:i:s a', strtotime($myrow['oa_start']));
$message['stop'] = date('h:i:s a', strtotime($myrow['oa_stop']));
$nextstop = date('h:i:s a', strtotime($myrow['oa_stop']));
} else if ($timetype=='0'){
$message['start'] = date('H:i:s', strtotime($myrow['oa_start']));
$message['stop'] = date('H:i:s', strtotime($myrow['oa_stop']));
$nextstop = date('H:i:s', strtotime($myrow['oa_stop']));
}
$title = $myts->stripSlashesGPC($myrow["oa_title"]);
$message['title'] = $title;
$station = $myts->stripSlashesGPC($myrow["oa_station"]);
$message['station'] = $station;
$name = $myts->stripSlashesGPC($myrow["oa_name"]);
$message['name'] = $name;
$description = $myts->stripSlashesGPC($myrow["oa_description"]);
$message['description'] = $description;
$image = $myrow["oa_image"];
$message['image'] = ""._VISITWEBSITE."";
$message['host'] = _MB_ONAIR_HOST;
$block['onair'][] = $message;
}
if ($nowday =='6'|$dayoffset>'0'){
$nowday2 = '0';
} else {
$nowday2 = $nowday + $dayoffset;
}
// Get data according to upcomming event
$sqlnext = "SELECT * FROM ".$xoopsDB->prefix("oa_program")." WHERE '$nextstop' <= oa_start AND '$nowday2' = oa_day order by oa_start, oa_stop LIMIT 1";
$resultnext=$xoopsDB->queryF($sqlnext);
if ( $resultnext ){

while($myrownext=$xoopsDB->fetchArray($resultnext))
{
$messagenext = array();
$messagenext['id'] = $myrownext['oa_id'];
$messagenext['day'] = onair_Numbers2DaysBlock($myrownext['oa_day']);
if ($timetype=='1'){
$messagenext['start'] = date('h:i:s a', strtotime($myrownext['oa_start']));
$messagenext['stop'] = date('h:i:s a', strtotime($myrownext['oa_stop']));
} else {
$messagenext['start'] = date('H:i:s', strtotime($myrownext['oa_start']));
$messagenext['stop'] = date('H:i:s', strtotime($myrownext['oa_stop']));
}
$titlenext = $myts->stripSlashesGPC($myrownext["oa_title"]);
$messagenext['title'] = $titlenext;
$stationnext = $myts->stripSlashesGPC($myrownext["oa_station"]);
$messagenext['station'] = $stationnext;
$namenext = $myts->stripSlashesGPC($myrownext["oa_name"]);
$messagenext['name'] = $namenext;
$descriptionnext = $myts->stripSlashesGPC($myrownext["oa_description"]);
$messagenext['description'] = $descriptionnext;

$imagenext = $myts->stripSlashesGPC($myrownext["oa_image"]);
$messagenext['image'] = ""._VISITWEBSITE."";
$messagenext['comup'] = _MB_ONAIR_COMINGUP;
$block['onair2'][] = $messagenext;

}
}else{
echo mysql_error();
return false;
}
return $block;
}


?>


Block Template 1
Quote:









The file called by ajax is this, showing the dummy template filled again with data from block function 1.

Quote:
include '../../mainfile.php';
include_once (XOOPS_ROOT_PATH.'/class/template.php');
include_once(XOOPS_ROOT_PATH.'/modules/onair/blocks/simple_now.php');
$tpl = new XoopsTpl();
$result = b_Onair_Show();
$tpl->assign('block', $result);
$tpl->display('db:onair_ajax.html');

?>


And finaly the dummy module block template #2 called back by ajax to split and fill the divs in block template #1
Quote:
<{foreach item=message from=$block.onair}>
<{$message.station}>


<{$message.title}>


<{$message.image}>


<{$message.host}><{$message.name}>



<{$message.pluginshow}>


<{$message.day}>

<{$message.start}> - <{$message.stop}>


,,,,
<{foreach item=messagenext from=$block.onair2}>
<{$messagenext.comup}>


<{$messagenext.station}>

<{$messagenext.title}>

<{$messagenext.image}>


<{$messagenext.host}><{$messagenext.name}>



<{$messagenext.day}>

<{$messagenext.start}> - <{$messagenext.stop}>


<{/foreach}>
<{/foreach}>



I tried every thing setting
$tpl->xoops_setCaching(0);
$tpl->xoops_setCacheTime(0);

Using etc etc but nothing.. Hope I am just missing something very simple :-S, or I'' just make meta http-equiv="refresh" content="60"> in block template but this is not optimal I think, but simple and will definitatly work
Programming is like sex:
One mistake and you have to support it for the rest of your life.

20
trabis
Re: Xajax+Xoops Smarty Templates
  • 2009/7/26 15:34

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Instead of loading template from database you can get it directly from file:

$tpl->display(XOOPS_ROOT_PATH .'/path/to/onair_ajax.html');

Login

Who's Online

421 user(s) are online (292 user(s) are browsing Support Forums)


Members: 0


Guests: 421


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