Fork me on GitHub

function datetime hack  Bottom

  • Hello,

    I want date a function datetime is refresh evrey 1 secondes to have exact time , so i hack a function datetime in system theme plugin and i put in my theme plugin.

    Function :

    Code

    function smarty_function_date($params, &$smarty)
    {
        extract($params);
        unset($params);
       var ajaxCall;
    $("runRequest").onclick = function() {
    ajaxCall = new Ajax.PeriodicalUpdater($("format"),
    "serveur/get-time.php", { method: "get", frequency: 1 });
    }
        // set some defaults
        if (!isset($format)) {
            $format = '_DATELONG';
        }
        if (strpos($format, '%') !== false) { // allow the use of conversion specifiers
            return ml_ftime($format, (GetUserTime(time())));
        }
        return ml_ftime(constant($format), (GetUserTime(time())));
    }


    and on my theme template i put this :

    Code

    <!--[date format=\@ %H:%M:%S']-->


    Time is show but it isn't update every 1 secondes. I am not so good in Ajax so if someone can help me to hack my function to works
  • IMHO, to use Ajax to update the seconds is overwhelming.
    You can have a special CSS class and find out a script to convert those items on 'dinamic' dates... javascript can do that, without server requests icon_wink

    --
    - Mateo T. -
    Mis principios... son mis fines
  • ok thanks i will do it with js this is my code of exact time

    Code

    Now the question is how to do special css class to put this js here in my template :

    [code]<div id="welcome">

        <!--[pnml name='_THEME_TODAY']-->&nbsp;<!--[date end='&nbsp;']--><!--[date format=\@ %H:%M:%S']--> put js here to see diff between php and js time

    </div>


    could some put me on road with calling this js or makinkg CSS class?
  • re, if i put this in my template

    Code

    <!--[modulejavascript modname='' script='time.js']-->

    it doesn't work because my js is in dir : theme/javascript
  • i have made a new version of function time withs js inside but it still doesn't works

    Code

    function smarty_function_time($params, &$smarty)
    {
        // variables to use
        // params
       
        unset($params);
         
      //  PageUtil::addVar('javascript', $smarty->scriptpath.'/News/liveclock.js');
     //   PageUtil::addVar('javascript', $smarty->scriptpath.'/time.js');
        // assign the respective output
        $output  = '<body onLoad="loadclock()">';
        $output  = '<span id=tick2></span>';
    $output  = '<!--
    function show2(){
    var Digital=new Date()
    var hours=Digital.getHours()
    var minutes=Digital.getMinutes()
    var seconds=Digital.getSeconds()
    if (hours<10)
    hours="0"+hours
    if (minutes<=9)
    minutes="0"+minutes
    if (seconds<=9)
    seconds="0"+seconds
    var ctime="<b>"+hours+" H "+minutes+" M "+seconds+" S</b>"
    if (!document.all)
    document.write(ctime)
    else
    tick2.innerHTML=ctime
    }
    function loadclock(){
    if (document.all)
    setInterval("show2()",1000)
    }
    if (!document.all)
    show2()
    //-->
    '
    ;
        return $output;
    }


    and i call this function in my template

    Code

    <!--[time]-->


    nothing is showing?? any help please
  • No more pb i fixed but still if i put this code it doesn't works

    Code

    <!--[modulejavascript modname=foobar script=openwindow.js modonly=1 onload="dosomething()" assign=myjs ]-->

    i must put this in head section

    Code

    /javascript/time.js" type="text/javascript">


    and i body section this

    Code

    <body onload="Heure()">
    <span id ="heure"></span>


    and it works
  • 0 users

This list is based on users active over the last 60 minutes.