/// Execute main logic for DoRedirectSource action public override void Execute() { var errorMessage = (String)null; var linkToRedirect = (String)null; if (!this.context.Request.Contains("source")) { errorMessage = "Source name is required!"; } else { var sourceName = this.context.Request["source"]; if (!TRequest.IsDomainName(sourceName)) { errorMessage = "Incorrect source name!"; } else { var doSource = new DOSource(this.context.Connection); THashtable[] oSource = { new THashtable() }; if (!doSource.CheckSourceName(sourceName, oSource)) { errorMessage = "No such source name!"; } else { linkToRedirect = STR(oSource[0]["s_External"]); } } } this.ExecuteRedirect(linkToRedirect, errorMessage); }
/// <summary> /// Main logic. /// </summary> /// <param name="from">Addition to feed URL (for testing purposes)</param> public void FetchFromSources(String from) { this.oLogger.Output(CAT("Start logging<br/>", EOL)); //TODO -- Purge old items //doItem = new DOItem(this.context.Connection); //doItem.PurgeOldItems(10); var doSource = new DOSource(this.context.Connection); var dsSources = doSource.EnumFetchedSources(); var totalCounter = 0; this.oLogger.Output(CAT("<br/>", EOL, "Checking ", dsSources.GetSize(), " sources...")); // Loop through sources for (int n = 0; n < dsSources.GetSize(); n++) { var oSource = dsSources.GetRow(n); Object[] itemsArray = this.FetchFromSource(oSource, from); if (itemsArray == null) { continue; } // Fetch done for this source //this.oLogger.Output(" fetched "); var itemsCounter = 0; // Loop through fetched items and parse their data for (int i = SIZE(itemsArray) - 1; i >= 0; i--) { var hash = (THashtable)itemsArray[i]; if (BLANK(hash["link"])) { continue; } var itemid = this.ParseItemData(oSource, hash); if (itemid > 0) { itemsCounter++; totalCounter++; } } this.oLogger.Output(CAT("<br/>", EOL, "... fetched (", itemsCounter, " items) end")); } // Re-count categories this.RecountCategories(); this.oLogger.Output(CAT("<br/>", EOL, "<hr/>Total items added - ", totalCounter, "<br/>", EOL)); if (Config.CACHE_PAGES && totalCounter > 0) { var doCleanCache = new DoCleanCache(this.context); doCleanCache.CleanCache(this.oLogger); } }
/// Execute main logic for FilterItems block. public override void Execute() { var doSource = new DOSource(this.context.Connection); var source = (String)null; if (this.context.Request.Contains("source")) { source = this.context.Request["source"]; } var prepare = new THashtable(); if (this.context.FineUrls) { prepare["[#Fine_Urls]"] = 1; } prepare["[#Selected]"] = BLANK(source) ? " selected=\"selected\" " : ""; var dsSources = (DataSet)null; //TODO -- This can be too long on big databases... Switch off counters for now. var useCounters = true; if (useCounters) { dsSources = doSource.EnumSourcesWithCounters(); } else { dsSources = doSource.EnumSources(); } var options = new TArrayList(); for (int n = 0; n < dsSources.GetSize(); n++) { var oSource = dsSources.GetRow(n); var option = new THashtable(); option["[#Selected]"] = (oSource["s_SourceName"].Equals(source) ? "selected=\"selected\"" : " "); option["[#Id]"] = STR(oSource["s_SourceName"]); option["[#Name]"] = STR(oSource["s_SourceName"]); if (useCounters) { option["[#Counter]"] = oSource["cntpro"]; } options.Add(option); } prepare["[#Options]"] = options; this.Write("Pages/filter_items", prepare); }
/// <summary> /// Execute main logic for generating RSS-feeds. /// </summary> public override void Execute() { //this.context.Request.Initialize(); this.context.Request.ExtractAllVars(); var errorMessage = ""; // Check source var source = this.context.Request["source"]; if (!NUL(source)) { if (BLANK(source)) { errorMessage += "Empty source!"; } else { var doSource = new DOSource(this.context.Connection); THashtable[] oSource = { new THashtable() }; if (!doSource.CheckSourceName(source, oSource)) { errorMessage += CAT("Incorrect source '", source, "'!"); } } } var anyFilter = false; if (this.context.Request.Contains("code")) { if (EQ(this.context.Request["code"], Config.SECURITY_CODE)) { anyFilter = true; } } // Check filter var filter = (String)null; var filterName = (String)null; var categoryName = (String)null; var doCategory = new DOCategory(this.context.Connection); var dsCategories = doCategory.EnumCategories(); if (dsCategories.GetSize() > 0) { filterName = this.context.Request["filter"]; if (!NUL(filterName)) { if (BLANK(filterName)) { if (errorMessage.Length > 0) { errorMessage += " "; } errorMessage += "Empty filter!"; } else { THashtable[] oCategory = { new THashtable() }; if (doCategory.CheckFilterName(filterName, oCategory)) { categoryName = STR(oCategory[0]["s_Name"]); filter = STR(oCategory[0]["s_Filter"]); } else { if (anyFilter) { filter = filterName; } else { if (errorMessage.Length > 0) { errorMessage += " "; } errorMessage += CAT("Incorrect filter '", filterName, "'!"); } } } } } // Check that parameters contain only 'source' or/and 'filter' var keys = this.context.Request.GetKeys(); while (keys.MoveNext()) { var key = (String)keys.GetCurrent(); if (EQ(key, "source") || EQ(key, "filter") || EQ(key, "code") || EQ(key, "count")) { //OK } else { //Not OK if (errorMessage.Length > 0) { errorMessage += " "; } errorMessage += CAT("Incorrect parameter '", key, "'!"); } } if (errorMessage.Length > 0) { this.WriteErrorMessage(errorMessage); return; } var fullTitle = false; if (this.context.Request.Contains("title") && STR(this.context.Request["title"]) == "full") { fullTitle = true; } var count = Config.MAX_RSS_ITEMS; var countSet = false; if (this.context.Request.Contains("count")) { if (INT(this.context.Request["count"]) > 0) { count = INT(this.context.Request["count"]); if (count < Config.MIN_RSS_ITEMS) { count = Config.MIN_RSS_ITEMS; } if (count > Config.MAX_RSS_ITEMS) { count = Config.MAX_RSS_ITEMS; } countSet = true; } } // Get content from cache (if enabled and cache data exists) var cachedFile = ""; if (Config.CACHE_RSS && !countSet) { cachedFile = Strings.Concat( this.context.RssFolder, "/rss", (BLANK(source) ? null : CAT("-s=", source)), (BLANK(filterName) ? null : CAT("-f=", filterName)), (fullTitle ? "-full" : null), ".xml"); if (Helper.FileExists(cachedFile)) { this.context.Response.WriteHeader("Content-type", "text/xml; charset=UTF-8"); var tempContent = Helper.ReadAllText(cachedFile); //this.context.Response.Write(tempContent.Substring(3)); //TODO -- BOM? this.context.Response.Write(tempContent); //TODO -- BOM? return; } } var doItem = new DOItem(this.context.Connection); // 0 - item url // 1 - item title // 2 - marketplace url // 3 - marketplace name // 4 - date // 5 - description // 6 - category var pubDate = DateTimes.Format(DateTimes.XML_DTS); var nowDate = DateTimes.Format(DateTimes.SQL_DTS); var nowTime = DateTimes.GetTime(nowDate); var fromDate = DateTimes.GmtFormat(DateTimes.SQL_DTS, nowTime - 6 * 60 * 60); //String search = DOItem.BuildSqlByFilter(filter); var search = DOItem.BuildSqlByCategory(categoryName); var dsItems = doItem.EnumItemsFromSource(fromDate, source, search, count); var current = 0; var contentToCache = ""; if (dsItems.GetSize() == 0) { contentToCache = this.WriteStart(source, categoryName, pubDate); } for (int n = 0; n < dsItems.GetSize(); n++) { var oItem = dsItems.GetRow(n); var date = STR(oItem["d_Date"]); if (DateTimes.GetTime(date) > nowTime) { continue; } if (current == 0) { // Get puDate from the first item and write starting block pubDate = DateTimes.Format(DateTimes.XML_DTS, DateTimes.GetTime(date)); contentToCache = this.WriteStart(source, categoryName, pubDate); } var category = this.context.Contains("Name_Category") ? STR(oItem["s_Category"]) : null; var creator = this.context.Contains("Name_Creator") ? STR(oItem["s_Creator"]) : null; String custom1 = this.context.Contains("Name_Custom1") ? STR(oItem["s_Custom1"]) : null; String custom2 = this.context.Contains("Name_Custom2") ? STR(oItem["s_Custom2"]) : null; var sourceName = STR(oItem["s_SourceName"]); var description = STR(oItem["t_Description"]); if (!BLANK(description)) { description = Regex.Replace(description, "<br/>", " ", RegexOptions.IgnoreCase); description = Regex.Replace(description, " ", " "); description = Regex.Replace(description, "[ \r\n\t]+", " "); if (description.Length > 512) { description = description.Substring(0, 511); var lastSpaceIndex = description.LastIndexOf(" "); description = Strings.Concat(description.Substring(0, lastSpaceIndex), " ..."); } //Boolean utfIsValid = Mb_check_encoding(description, "UTF-8"); //if (utfIsValid == false) // description = ""; //TODO } var itemTitle = CAT( (fullTitle == true && !BLANK(custom2) ? CAT(custom2, " | ") : null), Strings.RemoveTags(Strings.StripSlashes(STR(oItem["s_Title"]))), (fullTitle == true ? CAT(" [", sourceName, "]") : null) ); var link = (String)null; if (this.context.ImmediateRedirect) { link = STR(oItem["s_Link"]); } else { var url = STR(oItem["s_Url"]); var idField = doItem.GetIdField(); link = this.GetAbsoluteLink(Config.INDEX_PAGE, "?p=view_item&id=", "item/", oItem[idField]); if (!BLANK(url)) { link = this.AppendLink(link, "&title=", "/", url); } } Object[] args = ARR(7); args[0] = link; args[1] = itemTitle; args[2] = this.GetAbsoluteLink(Config.ACTION_PAGE, "?p=do_redirect_source&source=", "redirect/source/", sourceName); args[3] = sourceName; args[4] = DateTimes.Format(DateTimes.XML_DTS, DateTimes.GetTime(date)); var additional = (String)null; if (!BLANK(creator)) { if (additional != null) { additional = CAT(additional, "<br/>"); } additional = CAT(additional, this.context["Name_Creator"], ": ", creator); } if (!BLANK(category)) { if (additional != null) { additional = CAT(additional, "<br/>"); } additional = CAT(additional, this.context["Name_Categories"], ": ", category); } if (!BLANK(custom2)) { if (additional != null) { additional = CAT(additional, "<br/>"); } additional = CAT(additional, this.context["Name_Custom2"], ": ", custom2); } if (!BLANK(custom1)) { if (additional != null) { additional = CAT(additional, "<br/>"); } additional = CAT(additional, this.context["Name_Custom1"], ": ", custom1); } var extendedDescription = (String)null; if (!BLANK(description)) { if (BLANK(additional)) { extendedDescription = description; } else { extendedDescription = CAT(description, "<br/><br/>", additional); } } else if (!BLANK(additional)) { extendedDescription = additional; } args[5] = extendedDescription; args[6] = category; var itemContent = this.WriteItem(args); if (!BLANK(itemContent)) { contentToCache += itemContent; } current++; } var endContent = this.WriteEnd(); if (!BLANK(endContent)) { contentToCache += endContent; } // Save content to cache (if applicable) if (Config.CACHE_RSS && !countSet) { Helper.TestFileFolder(cachedFile); //Helper.WriteText(cachedFile, Strings.Concat("\xEF\xBB\xBF", xmlContent)); Helper.WriteText(cachedFile, contentToCache); } this.context.Response.WriteHeader("Content-type", "text/xml; charset=UTF-8"); this.context.Response.Write(contentToCache); //TODO -- BOM? }
/// Execute main logic for Items block. public override void Execute() { var pars = this.Check(); if (pars == null) { return; } var list = (String)pars["list"]; var listNumber = list == null ? 1 : INT(list); var sourceName = (String)pars["source_name"]; var filterName = (String)pars["filter_name"]; var errorMessage = ""; var filter = (String)null; var category = (String)null; if (!NUL(filterName)) { var doCategory = new DOCategory(this.context.Connection); THashtable[] oCategory = { new THashtable() }; if (!doCategory.CheckFilterName(filterName, oCategory)) { errorMessage += "Non-existing filter name!"; } else { category = STR(oCategory[0]["s_Name"]); filter = STR(oCategory[0]["s_Filter"]); } } var sourceId = -1; if (!NUL(sourceName)) { var doSource = new DOSource(this.context.Connection); THashtable[] oSource = { new THashtable() }; if (!doSource.CheckSourceName(sourceName, oSource)) { if (errorMessage.Length > 0) { errorMessage += "<br/>"; } errorMessage += "Non-existing source name!"; } else { sourceId = INT(oSource[0]["i_SourceId"]); } } var engine = this.context.GetEngine(); var prepare = new THashtable(); if (errorMessage.Length > 0) { prepare["[#ErrMessage]"] = errorMessage; this.Write("error", prepare); return; } if (Config.SHOW_IMAGES) { prepare["[#Show_Images]"] = 1; } prepare["[#ColSpan]"] = Config.SHOW_IMAGES ? 4 : 3; // Uncomment to enable filtering by source and/or category prepare["[#FilterItems]"] = engine.IncludeTemplate("Pages/FilterItems"); var s_Title = CAT( "Browse ", Config.NAME_ITEMS, (this.context.IsMobile ? "<br/>" : null), (!BLANK(sourceName) ? CAT(" ... from '", sourceName, "'") : null), (!BLANK(filter) ? CAT(" ... for '", category, "'") : null) ); prepare["[#Title]"] = s_Title; var maxRows = Config.DB_ITEMS_ROWS; var doItem = new DOItem(this.context.Connection); //String realFilter = DOItem.BuildSqlByFilter(filter); var realFilter = DOItem.BuildSqlByCategory(category); var dsItems = doItem.EnumItems(sourceName, realFilter, listNumber, maxRows); var listTotal = dsItems.GetTotalPages(); if (listNumber > listTotal) { if (listTotal > 0) { prepare["[#ErrMessage]"] = "List number is too large!"; this.Write("error", prepare); return; } else { prepare["[#ErrMessage]"] = "Empty list!"; this.Write("error", prepare); return; } } if (listTotal > 1) { prepare["[#List_Total]"] = listTotal; prepare["[#List]"] = listNumber; } var count = 1; var rows = new TArrayList(); for (int n = 0; n < dsItems.GetSize(); n++) { var oItem = dsItems.GetRow(n); var row = FillItemRow(oItem, doItem.GetIdField(), count); count++; rows.Add(row); } prepare["[#Rows]"] = rows; if (listTotal > 1) { var chunk = 2; var before = false; var after = false; var pages = new TArrayList(); for (int n = 1; n <= listTotal; n++) { var page = new THashtable(); if (n < listNumber - chunk) { if (!before) { before = true; page["[#Text]"] = "1"; page["[#Link]"] = GetPageLink(1); pages.Add(page); page = new THashtable(); page["[#Text]"] = " ... "; //row.Remove("[#Link]"); pages.Add(page); } continue; } if (n > listNumber + chunk) { if (!after) { after = true; page["[#Text]"] = " ... "; pages.Add(page); page = new THashtable(); page["[#Text]"] = listTotal; page["[#Link]"] = GetPageLink(listTotal); pages.Add(page); } continue; } if (listNumber == n) { page["[#Text]"] = CAT("=", n, "="); pages.Add(page); } else { if (n == 1) { page["[#Link]"] = GetPageLink(1); page["[#Text]"] = 1; } else { page["[#Link]"] = GetPageLink(n); page["[#Text]"] = n; } pages.Add(page); } } prepare["[#Pages]"] = pages; } this.Write("Pages/items", prepare); }