$val) $tmp .= $key.': '.export_to_json($val).', '; if (sizeof($php_val) > 0) $tmp = substr($tmp, 0, -2); return $tmp.'}'; } else if (is_array($php_val)) { $tmp = '['; foreach ($php_val as $val) $tmp .= export_to_json($val).', '; if (sizeof($php_val) > 0) $tmp = substr($tmp, 0, -2); return $tmp.']'; } else return "'".stripslashes($php_val)."'"; } # # ACTIONS # function action_push() { global $CHANNEL_SESSION_FOLDER; if (!isset($_GET['client']) || !isset($_GET['message'])) return; $file = realpath($CHANNEL_SESSION_FOLDER.'/'.$_GET['client']); if (!is_file($file)) return; $current_session = $_SESSION; $_SESSION = array(); session_decode(file_get_contents($file)); if (isset($_SERVER['HTTP_REFERRER'])) $_SESSION['client_queue'][$_SERVER['HTTP_REFERRER']][] = $_GET['message']; else $_SESSION['client_queue']['_'][] = $_GET['message']; $fd = fopen($file, 'w'); if (flock($fd, LOCK_EX)) { fputs($fd, session_encode()); flock($fd, LOCK_UN); } fclose($fd); $_SESSION = $current_session; } function action_pull() { $php_val = ''; if (isset($_SERVER['HTTP_REFERRER']) && sizeof($_SESSION['client_queue'][$_SERVER['HTTP_REFERRER']]) > 0) $php_val = array_shift($_SESSION['client_queue'][$_SERVER['HTTP_REFERRER']]); else if (sizeof($_SESSION['client_queue']['_']) > 0) $php_val = array_shift($_SESSION['client_queue']['_']); if (isset($_GET['callback'])) echo $_GET['callback'].'('.export_to_json($php_val).');'; else echo stripslashes($php_val); } function action_list() { global $CHANNEL_SESSION_FOLDER; $sessions = array(); foreach (glob($CHANNEL_SESSION_FOLDER.'/*') as $file) { $session_id = substr($file, strlen($CHANNEL_SESSION_FOLDER) + 1); if (!stristr($session_id, session_id())) $sessions[] = $session_id; } if (sizeof($sessions) == 0) return; if (isset($_GET['callback'])) echo $_GET['callback'].'('.export_to_json($sessions).');'; else echo 'list('.export_to_json($sessions).');'; } function action_view() { global $CHANNEL_SESSION_FOLDER; if (!isset($_GET['client'])) return; $file = realpath($CHANNEL_SESSION_FOLDER.'/'.$_GET['client']); if (!is_file($file)) return; $current_session = $_SESSION; $_SESSION = array(); session_decode(file_get_contents($file)); if (isset($_GET['callback'])) echo $_GET['callback'].'('.export_to_json($_SESSION).');'; else echo 'view('.export_to_json($_SESSION).');'; $_SESSION = $current_session; } function action_self() { global $CHANNEL_SESSION_FOLDER; foreach (glob($CHANNEL_SESSION_FOLDER.'/*') as $file) { $session_id = substr($file, strlen($CHANNEL_SESSION_FOLDER) + 1); if (stristr($session_id, session_id())) break; } if (isset($_GET['callback'])) echo $_GET['callback']."('$session_id');"; else echo "self('$session_id');"; } ?>