Ivan Vučica avatar Ivan Vučica committed 63be3eb

Added missing file

Comments (0)

Files changed (1)

+<?php
+$zxp = "zxmpp/"; // zxp == zxmpp path
+
+// header:
+function zxmpp_headers()
+{
+    global $zxp;
+
+    include $zxp . '/scriptlist.php';
+    $x = "";
+    foreach(zxmppGetStylesheets() as $fn)
+    {
+        $x .= '<link href="' . $zxp . $fn . '" rel="stylesheet" type="text/css" />' . "\n";
+    }
+    
+    foreach(zxmppGetAllScripts() as $fn)
+    {
+        $x .= '<script type="text/javascript" src="' . $zxp . $fn . '"></script>' . "\n";
+    }
+    
+    
+    if(false) //!usrIsAdmin($account))
+    {
+        $x .= '<style>';
+        $x .= '/* zxmpp gui hider */';
+        if(!$config['zxmpp']['show_bar'])
+            $x .= '.zxmpp_bar { display: none; }';
+        if(!$config['zxmpp']['show_roster'])
+            $x .= '#zxmpp_window__roster { display: none; }';
+        $x .= '</style>';
+    }
+    
+    echo $x;
+}
+
+// actual code
+function zxmpp_body($account, $password, $isLoggingOut /* isset($_GET['logout']) */, $useZXMPPUI)
+{
+	if(!usrCheckLogon($account, $password) && !$isLoggingOut)
+	{
+		// not logged in and not in process of logging out?
+		// delete local storage
+		?>
+		<script>
+		if(window.sessionStorage)
+		{
+			if(window.sessionStorage["zxmpp"])
+			{
+				window.sessionStorage["zxmpp"] = undefined;
+				delete window.sessionStorage["zxmpp"];
+			}
+		}
+		</script>
+		<?
+		return false;
+	}
+	if(sysIsRobotBrowser())
+		return false;
+
+	?>
+
+	<script type="text/javascript">
+	var zxmpp;
+	var zxmppui;
+
+	function zxmppZ_createZXMPP()
+	{
+		var cfg = {
+			"bind-url": "<?=$zxp?>http-bind/",
+			"route": "xmpp:" + window.location.hostname + ":5222",
+			"domain": window.location.hostname
+		};
+
+		zxmpp = new zxmppClass();
+		zxmpp.onConnectionTerminate.push(zxmppZ_onConnectionTerminate);
+		zxmpp.onPresenceUpdate.push(zxmppZ_onPresenceUpdate);
+		zxmpp.onRosterUpdate.push(zxmppZ_onRosterUpdate);
+		zxmpp.onMessage.push(zxmppZ_onMessage);
+
+		<? if ($useZXMPPUI) { ?>
+			zxmppui = new zxmpp.ui;
+			zxmppui.backend = zxmpp;
+			zxmppui.inject("body");
+		<? } ?>
+
+	<?
+		if(isset($_GET['logout'])) 
+		{
+	?>
+		zxmppui.bar.each(function(){this.style.display = 'none';});
+	<?
+		}
+
+		if($useZXMPPUI)
+		{
+			/* // no config support
+			if(isset($config['zxmpp']['roster_heading']))
+			{
+			?>
+				zxmppui.setRosterHeading("<?=addslashes(htmlspecialchars($config['zxmpp']['roster_heading']))?>");
+			<?
+			}
+			*/
+		}
+	?>
+		return cfg;
+	}
+
+	function zxmppZ_startFromScratch()
+	{
+		var cfg = zxmppZ_createZXMPP();
+
+		// update presence to current page title
+		setTimeout('zxmpp.setOwnPresence("avail", document.title, 1);', 4000); // give it 4 seconds to connect. we need full jid to be able to set own presence...
+		
+		zxmpp.main(cfg, "<?=$account?>", "<?=$this->oneshotauth?>");
+	}
+	function zxmppZ_onLoad()
+	{
+		setTimeout(zxmppZ_onLoad_delayed, 100);
+	}
+	function zxmppZ_onLoad_delayed()
+	{
+		if(window.sessionStorage)
+		{
+			if(window.sessionStorage["zxmpp"] && window.sessionStorage["zxmpp"]!="undefined")
+			{
+				zxmppZ_createZXMPP();
+				zxmpp.deserialize(window.sessionStorage["zxmpp"]);
+
+	<?
+				if(!isset($_GET['logout']))
+				{
+					// update presence to current page title
+					zxmpp.setOwnPresence("avail", document.title, 1);
+				}
+				else
+				{
+	?>
+					zxmpp.setOwnPresence("unavailable", "Logging out", 1);
+					console.warn("Logoff");
+					zxmpp.stream.logoff();
+	<?
+				}
+	?>
+				return;
+			}
+			// did not restore? start from scratch.
+			// give some time to mysql to flush auth data. FIXME can we avoid this?
+			setTimeout("zxmppZ_startFromScratch();", 1000);
+
+
+		}
+		else
+		{
+			// user does not support session storage?
+			// too bad. we don't want to show UI then and have that user
+			// continuously appear and disappear...
+		}
+	}
+	function zxmppZ_onUnload()
+	{
+		if(window.sessionStorage)
+		{
+			if(zxmpp && zxmpp.stream && zxmpp.stream.hasFullConnection)
+			{
+				window.sessionStorage["zxmpp"] = zxmpp.serialized();
+			}
+			else
+			{
+				window.sessionStorage["zxmpp"] = undefined;
+				delete window.sessionStorage["zxmpp"];
+			}
+		}
+	}
+
+	function zxmppZ_onConnectionTerminate(sender, code, humanreadable)
+	{
+		// FIXME should have a disappearing "toaster" popup...
+
+		var fakeMessage = new Object();
+		fakeMessage.from = "Problem"; // sender.cfg["domain"];
+		fakeMessage.body = "Veza prekinuta.<br><br>Razlog: " + humanreadable + "<br><br>Kod: " + code;
+		zxmppZ_onMessage(sender, fakeMessage);
+
+		zxmpp = undefined;
+				
+	}
+	function zxmppZ_onPresenceUpdate(sender, presence)
+	{
+		console.log("zxmppZ_onPresenceUpdate: " + sender.fullJid + " , " + presence.show);
+	<?
+		if(false) // no filtering //if(!usrGetValue($account, "isadmin") && !usrGetValue($account, "contestscribe") && isset($config['zxmpp']['roster_filter']) && $config['zxmpp']['roster_filter'])
+		{
+	?>
+
+			var allowed = false;
+	<?
+			foreach($config['zxmpp']['roster_filter'] as $allowed)
+			{
+	?>
+				if(presence.bareJid == "<?=htmlspecialchars($allowed)?>")
+				{
+					console.log("- Permitting " + presence.bareJid);
+					allowed = true;
+				}
+	<?
+			}
+	?>
+
+			if(!allowed)
+			{
+				console.warn("not updating " + presence.bareJid + " because it's not an allowed value");
+				return;
+			}
+	<?
+		}
+	?>
+
+		// instead of displaying status of the presence that
+		// was updated, instead we should display the
+		// status of the top presence (that might be the same
+		// presence, but not necessarily).
+		var topPresence = sender.getTopPresenceForBareJid(presence.bareJid);
+		if(topPresence)
+		{
+			console.log(" - Updating " + topPresence.bareJid + " with " + topPresence.show + " and " + topPresence.status);
+			<? if ($useZXMPPUI) { ?>
+				zxmppui.presenceUpdate(topPresence.bareJid, topPresence.show, false, topPresence.status);
+			<? } ?>
+		}
+		else
+		{
+			console.warn("no top presence for " + presence.bareJid);
+		}
+	}
+
+	function zxmppZ_onRosterUpdate(sender, item)
+	{
+		var presence = sender.getTopPresenceForBareJid(item.bareJid);
+
+		if(item.subscription != "removed" && item.subscription != "none")
+		{
+
+
+	<?
+			if(false) // no filtering //if(!usrGetValue($account, "isadmin") && !usrGetValue($account, "contestscribe") && isset($config['zxmpp']['roster_filter']) && $config['zxmpp']['roster_filter'])
+			{
+	?>
+				var allowed = false;
+	<?
+				foreach($config['zxmpp']['roster_filter'] as $allowed)
+				{
+	?>
+					if(item.bareJid == "<?=htmlspecialchars($allowed)?>")
+					{
+						allowed = true;
+						//console.log("Allowing addition of " + item.bareJid + " to roster");
+					}
+					else
+					{
+						//console.log("Our " + item.bareJid + " != <?=htmlspecialchars($allowed)?>");
+					}
+	<?
+				}
+			}
+			else
+			{
+	?>
+				var allowed = true;
+	<?
+			}
+	?>	
+
+			if(allowed)
+			{
+				var presenceShow = presence ? presence.show : "unavailable";
+				var display = item.name ? item.name : item.bareJid.split('@')[0];
+				var presenceStatus = presence ? presence.status : "";
+				
+				var vcard = sender.vCards[item.bareJid];
+				if(vcard && vcard.fn)
+					display = vcard.fn;
+				
+				<? if($useZXMPPUI) { ?>
+					zxmppui.rosterAdded(item.bareJid, presenceShow, display, presenceStatus);
+				<? } ?>
+			}
+
+
+		}
+		else
+		{
+			<? if ($useZXMPPUI) { ?>
+				zxmppui.rosterRemoved(item.bareJid);
+			<? } ?>
+		}
+	}
+
+	function zxmppZ_onMessage(sender, messageStanza)
+	{
+		if(messageStanza.body)
+		{
+			var text = messageStanza.body;
+
+			if(messageStanza.type == "error")
+			{
+				text = "ERROR with message: " + text;
+			}
+
+			zxmppZ_showNotification(undefined, messageStanza.from, text);
+		}
+
+		<? if ($useZXMPPUI) { ?>
+			zxmppui.messageStanzaReceived(messageStanza);
+		<? } ?>
+
+		var xml = messageStanza.messageNode;
+		
+		if(xml && xml.childNodes) 
+		{
+			for(var i in xml.childNodes)
+			{
+				if(!xml || !xml.childNodes)
+				{
+					console.log("Wtf?");
+					break;
+				}
+				var child = xml.childNodes[i];
+				if(!child.nodeName) continue;
+
+				this.zxmpp.util.easierAttrs(child);
+
+				switch(child.extendedNodeName)
+				{
+					case "http://zatemas.zrs.hr/evaluator/+submissionstatus":
+						var subdata = {};
+						for(var j in child.childNodes)
+						{
+							var subChild = child.childNodes[j];
+							if(!subChild.nodeName) continue;
+							if(subChild.firstChild && subChild.firstChild.nodeValue)
+								subdata[subChild.nodeName] = subChild.firstChild.nodeValue;
+						}
+
+						var fakeMessage = new Object();
+						fakeMessage.from = "Evaluator"; //messageStanza.from.split("@")[0]";
+						fakeMessage.body = "<br>Evaluacija zadatka " + subdata["problemname"] + " dovršena! Imate " + subdata["points"] + " bodova. <a target=\"_blank\" href=\"printablerun.php?app=evaluator&evlshw=log&user=<?=$account?>&file=" + subdata["problemname"] + "\">Log</a>";
+						zxmppZ_onMessage(sender, fakeMessage);
+						break;
+				}
+			}
+		}
+	}
+
+	function zxmppZ_showNotification(icon, title, msg)
+	{
+		if(!window.webkitNotifications)
+			return;
+		if (window.webkitNotifications.checkPermission() == 0) // 0 is PERMISSION_ALLOWED
+		{
+			// all is well
+		}
+		else
+		{
+			// user must enable notifications by clicking a button
+			// (otherwise notification permission request won't work)
+			// it might be a good idea to display htem a dialog; here we won't :)
+
+			// zxmppZ currently doesnt have a button...
+			//document.getElementById('notificationsbtn').style.display = 'inherit';
+			// but that button would have to call
+			//window.webkitNotifications.requestPermission();
+			return;
+		}
+
+		if(!icon)
+			icon = 'images/z.png';
+
+		var popup = window.webkitNotifications.createNotification(icon, title, msg);
+		popup.show();
+		setTimeout(function(popup)
+			{
+				popup.cancel(); 
+			}, 2000, popup);
+
+	}
+
+	</script>
+	<?
+
+
+}
+
+
+?>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.