/// <summary> /// Format date/time according to Config settings. /// </summary> /// <param name="input">Input date/time.</param> /// <returns>Resulting date/time.</returns> public static String ShowTime(String input) { var time = DateTimes.GetTime(input); var delta = 3600 * (Config.TIME_SHIFT / 100) + 60 * (Config.TIME_SHIFT % 100); time += delta; return(CAT(DateTimes.Format(DateTimes.DTS, time), " ", Config.TIME_ZONE)); }
/// Execute main logic for DoTestItems action public override void Execute() { var insertRequired = false; var updateRequired = false; var doTime = new DOTime(this.context.Connection); var dsTimes = doTime.GetById(1); var timeShift = 240; // 4 min var currentTime = DateTimes.GetTime(); if (dsTimes.GetSize() > 0) { var oTime = dsTimes.GetRow(0); if (currentTime > DateTimes.GetTime(STR(oTime["d_Time"])) + timeShift) { updateRequired = true; } } else { insertRequired = true; } var from = (String)null; if (this.context.Request.Contains("from")) { from = this.context.Request["from"]; } this.context.Response.Write(TOP); if (updateRequired || insertRequired) { this.context.Response.Write(CAT("Fetching new items... Please wait...<br/>", EOL)); var boFetcher = new BOFetcher(this.context); boFetcher.FetchFromSources(from); doTime = new DOTime(this.context.Connection); // Need for DB reopen var fields = new THashtable(); fields["d_Time"] = DateTimes.Format(DateTimes.SQL_DTS, DateTimes.GetTime()); if (insertRequired) { fields["i_Id"] = 1; doTime.Insert(fields); } else { doTime.UpdateById(1, fields); } } else { this.context.Response.Write(CAT("<hr/>Fetch is not required<br/>", EOL)); } this.context.Response.Write(BOTTOM); }
/// <summary> /// Purge items. /// </summary> /// <param name="days">Remove items older than days.</param> /// <returns>Resulting data set.</returns> public int PurgeOldItems(int days) { var purgeDate = DateTimes.Format(DBConfig.SQL_DTS, DateTimes.GetTime(CAT("-", days, " days"))); var query = Strings.Concat("DELETE FROM ", this.tableName, " WHERE d_Date < ?"); Object[] pars = ARR("SetDate", purgeDate); return(this.UpdateInternal(query, pars, "update")); }
/// <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? }
/// <summary> /// Set DateTime parameter. /// </summary> /// <param name="n">Parameter number.</param> /// <param name="val">Parameter value.</param> public void SetDate(int n, String val) { SetValue(n, CAT("'", DateTimes.Format(DateTimes.SQL_DTS, DateTimes.GetTime(val)), "'")); }