function Users_after_Q_session_write($params) { Q::$state['session'] = true; if (!$params['changed']) { return; } // Q::autoload('Db'); // Q::autoload('Db_Mysql'); // Q::autoload('Db_Result'); // Q::autoload('Db_Expression'); // Q::autoload('Db_Query'); // Q::autoload('Db_Query_Mysql'); // Q::autoload('Db_Row'); // Q::autoload('Base_Users_Session'); // Q::autoload('Base_Users'); // Q::autoload('Users'); Q::autoload('Q_Utils'); Q::autoload('Q_Config'); Q::autoload('Q_Session'); $id = Q_Session::id(); if (!$id) { return; } $parts = explode('-', $id); $duration = count($parts) > 1 ? $parts[0] : 0; $content = Q::json_encode($_SESSION, JSON_FORCE_OBJECT); if (Users::$loggedOut) { Q_Utils::sendToNode(array("Q/method" => "Users/session", "sessionId" => $id, "content" => null, "duration" => $duration)); } else { if (Q_Session::id() and !empty($_SERVER['HTTP_HOST'])) { try { Q_Utils::sendToNode(array("Q/method" => "Users/session", "sessionId" => $id, "content" => $content, "duration" => $duration)); } catch (Exception $e) { // don't throw here, it would only result in a mysterious fatal error } } } }
function Users_after_Q_session_destroy($params) { Q::$state['session'] = true; // Q::autoload('Db'); // Q::autoload('Db_Mysql'); // Q::autoload('Db_Result'); // Q::autoload('Db_Expression'); // Q::autoload('Db_Query'); // Q::autoload('Db_Query_Mysql'); // Q::autoload('Db_Row'); // Q::autoload('Base_Users_Session'); // Q::autoload('Base_Users'); // Q::autoload('Users'); Q::autoload('Q_Utils'); Q::autoload('Q_Config'); Q::autoload('Q_Session'); $id = Q_Session::id(); if (!$id) { return; } $content = Q::json_encode($_SESSION, JSON_FORCE_OBJECT); Q_Utils::sendToNode(array("Q/method" => "Users/session", "sessionId" => $id, "content" => null, "updatedTime" => null, "destroyed" => true)); }
/** * Return colored text that you can output in logs or text mode * Pass an exception or * @param {string|Exception} $exception The exception or an exception message. If the later, you must pass three more arguments. * @param {string} [$file] * @param {string} [$line] * @param {string} [$trace] * @return {string} */ static function coloredString($message, $file = null, $line = null, $trace = null) { if ($message instanceof Exception) { $e = $message; $traceString = is_callable(array($e, 'getTraceAsStringEx')) ? $e->getTraceAsStringEx() : $e->getTraceAsString(); return self::coloredString($e->getMessage(), $e->getFile(), $e->getLine(), $traceString); } $colors = Q_Config::get('Q', 'exception', 'colors', array()); Q::autoload('Q_Utils'); $fields = array('message' => $message, 'fileAndLine' => "in {$file} ({$line})", 'trace' => $trace); foreach ($fields as $f => $v) { $c0 = isset($colors[$f][0]) ? $colors[$f][0] : null; $c1 = isset($colors[$f][1]) ? $colors[$f][1] : null; $fields[$f] = Q_Utils::colored($v, $c0, $c1); } $reset = Q_Utils::colored("", "", ""); return "{$fields['message']}\n\n{$fields['fileAndLine']}\n{$fields['trace']}\n"; }