//--- Class Methods --- internal static AMedia New(XUri uri, XDoc config) { // check if the uri is a viddler video if (uri.Scheme.EqualsInvariantIgnoreCase("kaltura")) { if (uri.Segments.Length >= 1) { string entryID = uri.Segments[0]; string partnerID = config["kaltura/partner-id"].AsText; // check if extension is configured for kaltura integration if (!string.IsNullOrEmpty(partnerID)) { bool remix = !(uri.GetParam("edit", null) ?? uri.GetParam("remix", "no")).EqualsInvariantIgnoreCase("no"); // verify that user has permission to remix content on current page if (remix) { Plug dekiApi = GetDekiApi(config); if (dekiApi != null) { try { DekiScriptMap env = DreamContext.Current.GetState <DekiScriptMap>(); string pageid = env.GetAt("page.id").AsString(); string userid = env.GetAt("user.id").AsString(); XDoc users = dekiApi.At("pages", pageid, "allowed").With("permissions", "UPDATE").Post(new XDoc("users").Start("user").Attr("id", userid).End()).ToDocument(); remix = !users[string.Format(".//user[@id='{0}']", userid)].IsEmpty; } catch (Exception e) { _log.Error("unable to verify user permission on page", e); } } } // check if SEO links are explicitly disabled bool seo = !(config["kaltura/seo-links"].AsText ?? "enabled").EqualsInvariantIgnoreCase("disabled"); // determin which UI configuration to use based on user's permissions and embed settings for video string uiConfID = remix ? config["kaltura/uiconf/player-mix"].AsText : config["kaltura/uiconf/player-nomix"].AsText; if (!string.IsNullOrEmpty(uiConfID)) { uri = config["kaltura/server-uri"].AsUri ?? new XUri("http://www.kaltura.com"); uri = uri.At("index.php", "kwidget", "wid", "_" + partnerID, "uiconf_id", uiConfID, "entry_id", entryID); return(new KalturaVideo(uri, remix, seo)); } } } } return(null); }
public Hashtable PopularPages( [DekiExtParam("max results (default: 10)", true)] int?max, [DekiExtParam("poll interval (only for js format, default: 30)", true)] int?interval ) { int maxResults = max ?? 10; int resultCount = 0; DekiScriptMap env = DreamContext.Current.GetState <DekiScriptMap>(); DekiScriptLiteral uriLiteral = env.GetAt("site.uri"); XUri deki = new XUri(uriLiteral.NativeValue.ToString()).At("@api", "deki"); Hashtable map = new Hashtable(StringComparer.OrdinalIgnoreCase); map.Add("interval", _ttl.TotalSeconds); ArrayList pages = new ArrayList(); map.Add("pages", pages); int total = 0; Dictionary <uint, int> rankLookup = new Dictionary <uint, int>(); lock (_pageViews) { foreach (View view in _pageViews) { if (rankLookup.ContainsKey(view.PageId)) { rankLookup[view.PageId]++; } else { rankLookup[view.PageId] = 1; } total++; } } List <Tuplet <uint, int> > rank = new List <Tuplet <uint, int> >(); foreach (KeyValuePair <uint, int> kvp in rankLookup) { rank.Add(new Tuplet <uint, int>(kvp.Key, kvp.Value)); } rank.Sort(delegate(Tuplet <uint, int> a, Tuplet <uint, int> b) { return(b.Item2.CompareTo(a.Item2)); }); map.Add("total", total); foreach (Tuplet <uint, int> page in rank) { Hashtable pageMap = new Hashtable(StringComparer.OrdinalIgnoreCase); pages.Add(pageMap); // BUGBUGBUG (arnec): the AsLocalUri should not be required after bug #5964 is resolved pageMap.Add("page", DekiScriptExpression.Constant(deki.At("$page").AsLocalUri(), new[] { DekiScriptExpression.Constant(page.Item1), DekiScriptExpression.Constant(true) })); pageMap.Add("views", page.Item2); resultCount++; if (resultCount >= maxResults) { break; } } return(map); }
public T EnvAt <T>(string path) { if (path == null) { throw new ArgumentNullException("path"); } DekiScriptMap env = DreamContext.Current.GetState <DekiScriptMap>(); if (env == null) { return(default(T)); } DekiScriptLiteral value = env.GetAt(path); return(SysUtil.ChangeType <T>(value.NativeValue)); }