Browse Source

Merge remote branch 'etenil/master'

pull/5/head
Jaussoin Timothée 15 years ago
parent
commit
6d758c5a21
  1. 39
      js/movim.js
  2. 40
      lib/Ajaxer.php
  3. 2
      themes/movim/page.tpl

39
js/movim.js

@ -6,6 +6,8 @@ var APPEND = 2;
var FILL = 3;
var PREPEND = 4;
var movimPollHandlers = new Array();
function makeXMLHttpRequest()
{
if (window.XMLHttpRequest) {// code for real browsers
@ -46,6 +48,43 @@ function movimPack(data)
return outBuffer;
}
/**
* Attach a callback function to an event.
*/
function movimRegisterPollHandler(type, func)
{
if(!(type in movimPollHandlers)) {
movimPollHandlers[type] = new Array();
}
movimPollHandlers[type].push(func);
}
/**
* Polls the server.
*/
function movim_poll()
{
poller = makeXMLHttpRequest();
poller.open('GET', 'jajax.php?do=poll', true);
poller.onreadystatechange = function()
{
if(poller.readyState == 4)
{
if(poller.status == 200) {
// Handling poll return.
document.getElementById('testzone').innerHTML
= "<p>Poll succeeded: " + poller.responseText + "</p>"
+ document.getElementById('testzone').innerHTML;
}
// Restarting polling.
movim_poll();
}
};
poller.send();
}
/**
* Sends data to the movim server through ajax.
*

40
lib/Ajaxer.php

@ -79,26 +79,36 @@ class Ajaxer extends Controller
*/
public function handle()
{
$request = simplexml_load_string(file_get_contents('php://input'));
if(isset($_GET['do']) && $_GET['do'] == 'poll') {
if(rand(0,1) == 0) {
// We let it time out.
sleep(30);
} else {
sleep(2);
echo "tagada!!!!";
}
} else {
$request = simplexml_load_string(file_get_contents('php://input'));
// Loading the widget.
$widget_name = (string)$request['widget'];
$widget_path = LIB_PATH . 'widgets/' . $widget_name . '.php';
// Loading the widget.
$widget_name = (string)$request['widget'];
$widget_path = LIB_PATH . 'widgets/' . $widget_name . '.php';
if(file_exists($widget_path)) {
require($widget_path);
// Preparing the parameters and calling the function.
$params = array();
foreach($request->children() as $child) {
if($child->getName() == 'param') {
$params[] = (string)$child['value'];
if(file_exists($widget_path)) {
require($widget_path);
// Preparing the parameters and calling the function.
$params = array();
foreach($request->children() as $child) {
if($child->getName() == 'param') {
$params[] = (string)$child['value'];
}
}
}
$user = new User();
$widget = new $widget_name(false, $user);
$user = new User();
$widget = new $widget_name(false, $user);
call_user_func(array($widget, (string)$request['name']), $params);
call_user_func(array($widget, (string)$request['name']), $params);
}
}
}
}

2
themes/movim/page.tpl

@ -9,7 +9,7 @@
<?php $this->addCss('css/login_form.css');?>
<?php $this->scripts();?>
</head>
<body>
<body onload="movim_poll();">
<div id="nav">
<?php $this->menu();?>
</div>

Loading…
Cancel
Save