Ejemplo n.º 1
0
        /// <summary>
        /// Normalize list of categories.
        /// </summary>
        public void NormalizeCategories()
        {
            if (BLANK(this.category))
            {
                return;
            }

            String[] categories = Strings.Split(", ", this.category);
            var      size       = SIZE(categories);

            if (size == 1)
            {
                return;
            }

            var categoryTags = new TArrayList();

            for (int n1 = 0; n1 < size; n1++)
            {
                String category1 = categories[n1];
                if (!categoryTags.Contains(category1))
                {
                    categoryTags.Add(category1);
                }
            }

            this.category = Strings.Join(", ", (String[])categoryTags.ToArray(
                                             typeof(String)
                                             ));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Call method of given class using provided arguments.
        /// </summary>
        /// <param name="class_name">Class name</param>
        /// <param name="args0">Constructor args</param>
        /// <param name="method_name">Method name</param>
        /// <param name="args">List of arguments</param>
        /// <returns>Result of method execution</returns>
        public static Object CallMethod(String class_name, TArrayList args0, String method_name, TArrayList args)
        {
            Type type = Type.GetType(class_name.Replace('/', '.'));

            Type[] types0 = GetTypes(args0);
            System.Reflection.ConstructorInfo constructorInfo = type.GetConstructor(types0);
            Object doObject = constructorInfo.Invoke(args0.ToArray());

            Type[] types = GetTypes(args);
            System.Reflection.MethodInfo methodInfo = type.GetMethod(method_name, types);
            if (methodInfo != null)
            {
                if (args != null && args.Size() > 0)
                {
                    return(methodInfo.Invoke(doObject, args.ToArray()));
                }
                else
                {
                    return(methodInfo.Invoke(doObject, null));
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// Execute main logic for required action.
        public override void Execute()
        {
            if (actionsArray == null)
            {
                Initialize();
            }

            var actionInfo = this.context.Request.TestPage(actionsArray);

            // Test action name
            if (!actionInfo.ContainsKey("page"))
            {
                this.context.Response.End("Error in parameters -- no page");
                return;
            }

            // Test action context
            if (INT(actionInfo["post_required"]) == 1 && INT(actionInfo["from_post"]) == 0)
            {
                this.context.Response.End("Error in parameters -- inconsistent pars");
                return;
            }

            //this.context.Request.Initialize();
            if (INT(actionInfo["post_required"]) == 1)
            {
                this.context.Request.ExtractPostVars();
            }
            else
            {
                this.context.Request.ExtractAllVars();
            }

            //TODO!!!
            //if (!this.context.Request.CheckReferer(Config.Site))
            //    err404();

            if (INT(actionInfo["code_required"]) == 1)
            {
                if (!this.context.Request.Contains("code") || !EQ(this.context.Request["code"], Config.SECURITY_CODE))   //TODO -- hardcoded!!!
                {
                    this.context.Response.End("No access.");
                    return;
                }
            }

            var        actionClass = CAT("Bula/Fetcher/Controller/Actions/", actionInfo["class"]);
            TArrayList args0       = new TArrayList(); args0.Add(this.context);

            Internal.CallMethod(actionClass, args0, "Execute", null);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Get template as the list of lines.
 /// </summary>
 /// <param name="filename">File name.</param>
 /// <returns>Resulting array with lines.</returns>
 private TArrayList GetTemplate(String filename)
 {
     if (Helper.FileExists(CAT(this.context.LocalRoot, filename)))
     {
         Object[] lines = Helper.ReadAllLines(CAT(this.context.LocalRoot, filename));
         return(TArrayList.CreateFrom(lines));
     }
     else
     {
         var temp = new TArrayList();
         temp.Add(CAT("File not found -- '", filename, "'<hr/>"));
         return(temp);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Call static method of given class using provided arguments.
        /// </summary>
        /// <param name="class_name">Class name</param>
        /// <param name="method_name">Method name</param>
        /// <param name="args">List of arguments</param>
        /// <returns>Result of method execution</returns>
        public static Object CallStaticMethod(String class_name, String method_name, TArrayList args)
        {
            Type type = Type.GetType(class_name.Replace('/', '.'));

            System.Reflection.MethodInfo methodInfo = type.GetMethod(method_name);
            if (args != null && args.Size() > 0)
            {
                return(methodInfo.Invoke(null, args.ToArray()));
            }
            else
            {
                return(methodInfo.Invoke(null, null));
            }
        }
Ejemplo n.º 6
0
        /// 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);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Push engine.
        /// </summary>
        /// <param name="printFlag">Whether to print content immediately (true) or save it for further processing (false).</param>
        /// <returns>New Engine instance.</returns>
        public Engine PushEngine(Boolean printFlag)
        {
            var engine = new Engine(this);

            engine.SetPrintFlag(printFlag);
            this.EngineIndex++;
            if (this.EngineInstances == null)
            {
                this.EngineInstances = new TArrayList();
            }
            if (this.EngineInstances.Size() <= this.EngineIndex)
            {
                this.EngineInstances.Add(engine);
            }
            else
            {
                this.EngineInstances[this.EngineIndex] = engine;
            }
            return(engine);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Pre-process category.
        /// </summary>
        /// <param name="categoryItem">Input category.</param>
        /// <returns>Pre-processed category.</returns>
        private String PreProcessCategory(String categoryItem)
        {
            // Pre-process category from item["category"]

            // This is just sample - implement your own logic
            if (EQ(this.source, "something.com"))
            {
                // Fix categories from something.com
            }

            if (categoryItem.Length == 0)
            {
                return(null);
            }

            var category = (String)null;

            String[] categoriesArr = Strings.Split(",", categoryItem);
            var      categoriesNew = new TArrayList();

            for (int c = 0; c < SIZE(categoriesArr); c++)
            {
                var temp = categoriesArr[c];
                temp = Strings.Trim(temp);
                if (BLANK(temp))
                {
                    continue;
                }
                temp = Strings.FirstCharToUpper(temp);
                if (category == null)
                {
                    category = temp;
                }
                else
                {
                    category = category += CAT(", ", temp);
                }
            }

            return(category);
        }
Ejemplo n.º 9
0
 private static Type[] GetTypes(TArrayList args)
 {
     Type[] types = args != null && args.Size() > 0 ? new Type[args.Size()] : new Type[0];
     if (types.Length > 0)
     {
         for (int n = 0; n < args.Size(); n++)
         {
             types[n] = args[n].GetType();
             if (args[n] is String)
             {
                 int result;
                 if (int.TryParse((String)args[n], out result))
                 {
                     types[n] = typeof(int);
                     args[n]  = result;
                 }
             }
         }
     }
     return(types);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Include file with class and generate content by calling method.
        /// </summary>
        /// <param name="className">Class name to include.</param>
        /// <param name="defaultMethod">Default method to call.</param>
        /// <returns>Resulting content.</returns>
        public String IncludeTemplate(String className, String defaultMethod)
        {
            var engine   = this.context.PushEngine(false);
            var prefix   = CAT(Config.FILE_PREFIX, "Bula/Fetcher/Controller/");
            var fileName =
                CAT(prefix, className, ".cs");

            var content = (String)null;

            if (Helper.FileExists(CAT(this.context.LocalRoot, fileName)))
            {
                TArrayList args0 = new TArrayList(); args0.Add(this.context);
                Internal.CallMethod(CAT(prefix, className), args0, defaultMethod, null);
                content = engine.GetPrintString();
            }
            else
            {
                content = CAT("No such file: ", fileName);
            }
            this.context.PopEngine();
            return(content);
        }
Ejemplo n.º 11
0
        /// Execute main logic for Home block.
        public override void Execute()
        {
            var pars = this.Check();

            if (pars == null)
            {
                return;
            }

            var prepare = new THashtable();

            var doItem = new DOItem(this.context.Connection);

            prepare["[#BrowseItemsLink]"] = this.GetLink(Config.INDEX_PAGE, "?p=", null, "items");
            if (Config.SHOW_IMAGES)
            {
                prepare["[#Show_Images]"] = 1;
            }

            var source   = (String)null;
            var search   = (String)null;
            var maxRows  = Config.DB_HOME_ROWS;
            var dsItems  = doItem.EnumItems(source, search, 1, maxRows);
            var rowCount = 1;
            var items    = new TArrayList();

            for (int n = 0; n < dsItems.GetSize(); n++)
            {
                var oItem = dsItems.GetRow(n);
                var row   = FillItemRow(oItem, doItem.GetIdField(), rowCount);
                items.Add(row);
                rowCount++;
            }
            prepare["[#Items]"] = items;

            this.Write("Pages/home", prepare);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Add standard categories (from DB) to current item.
        /// </summary>
        /// <param name="dsCategories">DataSet with categories (pre-loaded from DB).</param>
        /// <param name="lang">Input language.</param>
        /// <returns>Number of added categories.</returns>
        public int AddStandardCategories(DataSet dsCategories, String lang)
        {
            //if (BLANK(this.description))
            //    return;

            var categoryTags = new TArrayList();

            if (!BLANK(this.category))
            {
                categoryTags.AddAll(Strings.Split(", ", this.category));
            }
            for (int n1 = 0; n1 < dsCategories.GetSize(); n1++)
            {
                var oCategory     = dsCategories.GetRow(n1);
                var rssAllowedKey = STR(oCategory["s_CatId"]);
                var name          = STR(oCategory["s_Name"]);

                var      filterValue   = STR(oCategory["s_Filter"]);
                String[] filterChunks  = Strings.Split("~", filterValue);
                String[] includeChunks = SIZE(filterChunks) > 0 ?
                                         Strings.Split("\\|", filterChunks[0]) : Strings.EmptyArray();
                String[] excludeChunks = SIZE(filterChunks) > 1 ?
                                         Strings.Split("\\|", filterChunks[1]) : Strings.EmptyArray();

                var includeFlag = false;
                for (int n2 = 0; n2 < SIZE(includeChunks); n2++)
                {
                    var includeChunk = includeChunks[n2]; //Regex.Escape(includeChunks[n2]);
                    if (Regex.IsMatch(this.title, includeChunk, RegexOptions.IgnoreCase))
                    {
                        includeFlag |= true;
                        break;
                    }
                    if (!BLANK(this.description) && Regex.IsMatch(this.description, includeChunk, RegexOptions.IgnoreCase))
                    {
                        includeFlag |= true;
                        break;
                    }
                }
                for (int n3 = 0; n3 < SIZE(excludeChunks); n3++)
                {
                    var excludeChunk = excludeChunks[n3]; //Regex.Escape(excludeChunks[n3]);
                    if (Regex.IsMatch(this.title, excludeChunk, RegexOptions.IgnoreCase))
                    {
                        includeFlag &= false;
                        break;
                    }
                    if (!BLANK(this.description) && Regex.IsMatch(this.description, excludeChunk, RegexOptions.IgnoreCase))
                    {
                        includeFlag &= false;
                        break;
                    }
                }
                if (includeFlag)
                {
                    categoryTags.Add(name);
                }
            }
            if (categoryTags.Size() == 0)
            {
                return(0);
            }

            //TODO
            //TArrayList uniqueCategories = this.NormalizeList(categoryTags, lang);
            //category = String.Join(", ", uniqueCategories);

            this.category = Strings.Join(", ", (String[])categoryTags.ToArray(
                                             typeof(String)
                                             ));

            return(categoryTags.Size());
        }
Ejemplo n.º 13
0
        /// Execute main logic for Menu block
        public override void Execute()
        {
            var publicPages = new TArrayList();

            var bookmark = (String)null;

            if (this.context.Contains("Name_Category"))
            {
                bookmark = CAT("#", Config.NAME_ITEMS, "_by_", this.context["Name_Category"]);
            }
            publicPages.Add("Home");
            publicPages.Add("home");
            if (this.context.IsMobile)
            {
                publicPages.Add(Config.NAME_ITEMS); publicPages.Add("items");
                if (Config.SHOW_BOTTOM && this.context.Contains("Name_Category"))
                {
                    publicPages.Add(CAT("By ", this.context["Name_Category"]));
                    publicPages.Add(bookmark);
                    //publicPages.Add("RSS Feeds");
                    //publicPages.Add("#read_rss_feeds");
                }
                publicPages.Add("Sources");
                publicPages.Add("sources");
            }
            else
            {
                publicPages.Add(CAT("Browse ", Config.NAME_ITEMS));
                publicPages.Add("items");
                if (Config.SHOW_BOTTOM && this.context.Contains("Name_Category"))
                {
                    publicPages.Add(CAT(Config.NAME_ITEMS, " by ", this.context["Name_Category"]));
                    publicPages.Add(bookmark);

                    publicPages.Add("Read RSS Feeds");
                    publicPages.Add("#Read_RSS_Feeds");
                }
                publicPages.Add("Sources");
                publicPages.Add("sources");
            }

            var menuItems = new TArrayList();

            for (int n = 0; n < publicPages.Size(); n += 2)
            {
                var row   = new THashtable();
                var title = STR(publicPages[n + 0]);
                var page  = STR(publicPages[n + 1]);
                var href  = (String)null;
                if (EQ(page, "home"))
                {
                    href = Config.TOP_DIR;
                }
                else
                {
                    if (EQ(page.Substring(0, 1), "#"))
                    {
                        href = page;
                    }
                    else
                    {
                        href = this.GetLink(Config.INDEX_PAGE, "?p=", null, page);
                    }
                }
                row["[#Link]"]     = href;
                row["[#LinkText]"] = title;
                row["[#Prefix]"]   = n != 0 ? " &bull; " : " ";
                menuItems.Add(row);
            }

            var prepare = new THashtable();

            prepare["[#MenuItems]"] = menuItems;
            this.Write("menu", prepare);
        }
Ejemplo n.º 14
0
        /// 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);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Fetch info from RSS-feed.
        /// </summary>
        /// <param name="url">Feed url</param>
        /// <returns>Resulting array of items</returns>
        public static Object[] FetchRss(String url)
        {
            var items = new TArrayList();

            XmlDocument rssXmlDoc = new XmlDocument();

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(rssXmlDoc.NameTable);

            nsmgr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");

            // Load the RSS file from the RSS URL
            try {
                rssXmlDoc.Load(url);
            }
            catch (Exception ex1) {
                var matchCollection = Regex.Matches(ex1.Message, "'([^']+)' is an undeclared prefix. Line [0-9]+, position [0-9]+.");
                if (matchCollection.Count > 0)
                {
                    var prefix = matchCollection[0].Groups[1].Value;
                    try
                    {
                        var    client  = new System.Net.WebClient();
                        var    content = (new System.Net.WebClient()).DownloadString(url);
                        byte[] bytes   = Encoding.Default.GetBytes(content);
                        content = Encoding.UTF8.GetString(bytes);
                        //content = System.Text.Encoding.UTF8.GetBytes(content).ToString();
                        var pattern = CAT("<", prefix, ":[^>]+>[^<]+</", prefix, ":[^>]+>");
                        content = Regex.Replace(content, pattern, "");
                        rssXmlDoc.LoadXml(content);
                    }
                    catch (Exception ex2) {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }

            // Parse the Items in the RSS file
            XmlNodeList rssNodes = rssXmlDoc.SelectNodes("rss/channel/item");

            // Iterate through the items in the RSS file
            foreach (XmlNode rssNode in rssNodes)
            {
                var item = new THashtable();

                XmlNodeList itemNodes = rssNode.SelectNodes("*");
                foreach (XmlNode itemNode in itemNodes)
                {
                    String name = itemNode.Name;
                    String text = itemNode.InnerXml;
                    if (text.StartsWith("<![CDATA["))
                    {
                        text = text.Replace("<![CDATA[", "").Replace("]]>", "");
                    }

                    if (name == "category")
                    {
                        if (item[name] == null)
                        {
                            item[name] = text;
                        }
                        else
                        {
                            item[name] += ", " + text;
                        }
                    }
                    else if (name == "dc:creator")
                    {
                        THashtable dc = item.ContainsKey("dc") ? (THashtable)item["dc"] : new THashtable();
                        dc["creator"] = text;
                        item["dc"]    = dc;
                    }
                    else if (name == "dc:date")
                    {
                        THashtable dc = item.ContainsKey("dc") ? (THashtable)item["dc"] : new THashtable();
                        dc["date"] = text;
                        item["dc"] = dc;
                    }
                    else
                    {
                        item[name] = text;
                    }
                }
                items.Add(item);
            }
            return(items.ToArray());
        }
Ejemplo n.º 16
0
        /// Execute main logic for Bottom block
        public override void Execute()
        {
            var prepare = new THashtable();

            prepare.Put("[#Items_By_Category]",
                        CAT(Config.NAME_ITEMS, "_by_", this.context["Name_Category"]));

            var doCategory = new DOCategory(this.context.Connection);
            var dsCategory = doCategory.EnumAll(Config.SHOW_EMPTY ? null : "_this.i_Counter <> 0",
                                                Config.SORT_CATEGORIES == null ? null : CAT("_this.", Config.SORT_CATEGORIES));
            var size  = dsCategory.GetSize();
            int size3 = size % 3;
            int n1    = INT(size / 3) + (size3 == 0 ? 0 : 1);
            int n2    = n1 * 2;

            Object[] nn           = ARR(0, n1, n2, size);
            var      filterBlocks = new TArrayList();

            for (int td = 0; td < 3; td++)
            {
                var filterBlock = new THashtable();
                var rows        = new TArrayList();
                for (int n = INT(nn[td]); n < INT(nn[td + 1]); n++)
                {
                    var oCategory = dsCategory.GetRow(n);
                    if (NUL(oCategory))
                    {
                        continue;
                    }
                    var counter = INT(oCategory["i_Counter"]);
                    if (Config.SHOW_EMPTY == false && INT(counter) == 0)
                    {
                        continue;
                    }
                    var key  = STR(oCategory["s_CatId"]);
                    var name = STR(oCategory["s_Name"]);
                    var row  = new THashtable();
                    row["[#Link]"]     = this.GetLink(Config.INDEX_PAGE, "?p=items&filter=", "items/filter/", key);
                    row["[#LinkText]"] = name;
                    //if (counter > 0)
                    row["[#Counter]"] = counter;
                    rows.Add(row);
                }
                filterBlock["[#Rows]"] = rows;
                filterBlocks.Add(filterBlock);
            }
            prepare["[#FilterBlocks]"] = filterBlocks;

            if (!this.context.IsMobile)
            {
                //dsCategory = doCategory.EnumAll(null, Config.SORT_CATEGORIES == null ? null : CAT("_this.", Config.SORT_CATEGORIES));
                size  = dsCategory.GetSize();                 //50
                size3 = size % 3;                             //2
                n1    = INT(size / 3) + (size3 == 0 ? 0 : 1); //17.3
                n2    = n1 * 2;                               //34.6
                nn    = ARR(0, n1, n2, size);
                var rssBlocks = new TArrayList();
                for (int td = 0; td < 3; td++)
                {
                    var rssBlock = new THashtable();
                    var rows     = new TArrayList();
                    for (int n = INT(nn[td]); n < INT(nn[td + 1]); n++)
                    {
                        var oCategory = dsCategory.GetRow(n);
                        if (NUL(oCategory))
                        {
                            continue;
                        }
                        var key  = STR(oCategory["s_CatId"]);
                        var name = STR(oCategory["s_Name"]);
                        //counter = INT(oCategory["i_Counter"]);
                        var row = new THashtable();
                        row["[#Link]"]     = this.GetLink(Config.RSS_PAGE, "?filter=", "rss/", CAT(key, (this.context.FineUrls ? ".xml" : null)));
                        row["[#LinkText]"] = name;
                        rows.Add(row);
                    }
                    rssBlock["[#Rows]"] = rows;
                    rssBlocks.Add(rssBlock);
                }
                prepare["[#RssBlocks]"] = rssBlocks;
            }
            this.Write("bottom", prepare);
        }
Ejemplo n.º 17
0
        /// Execute method using parameters from request.
        public override void Execute()
        {
            //this.context.Request.Initialize();
            this.context.Request.ExtractAllVars();

            this.context.Response.WriteHeader("Content-type", "text/html; charset=UTF-8");

            // Check security code
            if (!this.context.Request.Contains("code"))
            {
                this.context.Response.End("Code is required!");
                return;
            }
            var code = this.context.Request["code"];

            if (!EQ(code, Config.SECURITY_CODE))
            {
                this.context.Response.End("Incorrect code!");
                return;
            }

            // Check package
            if (!this.context.Request.Contains("package"))
            {
                this.context.Response.End("Package is required!");
                return;
            }
            var package = this.context.Request["package"];

            if (BLANK(package))
            {
                this.context.Response.End("Empty package!");
                return;
            }
            String[] packageChunks = Strings.Split("-", package);
            for (int n = 0; n < SIZE(packageChunks); n++)
            {
                packageChunks[n] = Strings.FirstCharToUpper(packageChunks[n]);
            }
            package = Strings.Join("/", packageChunks);

            // Check class
            if (!this.context.Request.Contains("class"))
            {
                this.context.Response.End("Class is required!");
                return;
            }
            var className = this.context.Request["class"];

            if (BLANK(className))
            {
                this.context.Response.End("Empty class!");
                return;
            }

            // Check method
            if (!this.context.Request.Contains("method"))
            {
                this.context.Response.End("Method is required!");
                return;
            }
            var method = this.context.Request["method"];

            if (BLANK(method))
            {
                this.context.Response.End("Empty method!");
                return;
            }

            // Fill array with parameters
            var count = 0;
            var pars  = new TArrayList();

            for (int n = 1; n <= 6; n++)
            {
                var parName = CAT("par", n);
                if (!this.context.Request.Contains(parName))
                {
                    break;
                }
                var parValue = this.context.Request[parName];
                if (EQ(parValue, "_"))
                {
                    parValue = "";
                }
                //parsArray[] = parValue;
                pars.Add(parValue);
                count++;
            }

            var buffer = (String)null;
            var result = (Object)null;

            var fullClass = CAT(package, "/", className);

            fullClass = Strings.Replace("/", ".", fullClass);
            method    = Strings.FirstCharToUpper(method);
            TArrayList pars0 = new TArrayList(new Object[] { this.context.Connection });

            result = Bula.Internal.CallMethod(fullClass, pars0, method, pars);

            if (result == null)
            {
                buffer = "NULL";
            }
            else if (result is DataSet)
            {
                buffer = ((DataSet)result).ToXml(EOL);
            }
            else
            {
                buffer = STR(result);
            }
            this.context.Response.Write(buffer);
            this.context.Response.End();
        }
 /// Default public constructor
 public PreparedStatement()
 {
     this.pars = new TArrayList();
     this.pars.Add("dummy"); // Parameter number will start from 1.
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Execute template processing.
        /// </summary>
        /// <param name="template">Template in form of the list of lines.</param>
        /// <param name="hash">Data for merging with template.</param>
        /// <returns>Resulting content.</returns>
        private String ProcessTemplate(TArrayList template, THashtable hash)
        {
            if (this.context.IsMobile)
            {
                if (hash == null)
                {
                    hash = new THashtable();
                }
                hash["[#Is_Mobile]"] = 1;
            }
            var trimLine   = true;
            var trimEnd    = EOL;
            var ifMode     = 0;
            var repeatMode = 0;
            var ifBuf      = new TArrayList();
            var repeatBuf  = new TArrayList();
            var ifWhat     = "";
            var repeatWhat = "";
            var content    = "";

            for (int n = 0; n < template.Size(); n++)
            {
                var line           = (String)template[n];
                var lineNoComments = TrimComments(line); //, BLANK(this.context.Api)); //TODO
                if (ifMode > 0)
                {
                    if (lineNoComments.IndexOf("#if") == 0)
                    {
                        ifMode++;
                    }
                    if (lineNoComments.IndexOf("#end if") == 0)
                    {
                        if (ifMode == 1)
                        {
                            var not         = (ifWhat.IndexOf("!") == 0);
                            var eq          = (ifWhat.IndexOf("==") != -1);
                            var neq         = (ifWhat.IndexOf("!=") != -1);
                            var processFlag = false;
                            if (not == true)
                            {
                                if (!hash.ContainsKey(ifWhat.Substring(1))) //TODO
                                {
                                    processFlag = true;
                                }
                            }
                            else
                            {
                                if (eq)
                                {
                                    String[] ifWhatArray = Strings.Split("==", ifWhat);
                                    String   ifWhat1     = ifWhatArray[0];
                                    String   ifWhat2     = ifWhatArray[1];
                                    if (hash.ContainsKey(ifWhat1) && EQ(hash[ifWhat1], ifWhat2))
                                    {
                                        processFlag = true;
                                    }
                                }
                                else if (neq)
                                {
                                    String[] ifWhatArray = Strings.Split("!=", ifWhat);
                                    String   ifWhat1     = ifWhatArray[0];
                                    String   ifWhat2     = ifWhatArray[1];
                                    if (hash.ContainsKey(ifWhat1) && !EQ(hash[ifWhat1], ifWhat2))
                                    {
                                        processFlag = true;
                                    }
                                }
                                else if (hash.ContainsKey(ifWhat))
                                {
                                    processFlag = true;
                                }
                            }

                            if (processFlag)
                            {
                                content += ProcessTemplate(ifBuf, hash);
                            }
                            ifBuf = new TArrayList();
                        }
                        else
                        {
                            ifBuf.Add(line);
                        }
                        ifMode--;
                    }
                    else
                    {
                        ifBuf.Add(line);
                    }
                }
                else if (repeatMode > 0)
                {
                    if (lineNoComments.IndexOf("#repeat") == 0)
                    {
                        repeatMode++;
                    }
                    if (lineNoComments.IndexOf("#end repeat") == 0)
                    {
                        if (repeatMode == 1)
                        {
                            if (hash.ContainsKey(repeatWhat))
                            {
                                var rows = (TArrayList)hash[repeatWhat];
                                for (int r = 0; r < rows.Size(); r++)
                                {
                                    content += ProcessTemplate(repeatBuf, (THashtable)rows[r]);
                                }
                                hash.Remove(repeatWhat);
                            }
                            repeatBuf = new TArrayList();
                        }
                        else
                        {
                            repeatBuf.Add(line);
                        }
                        repeatMode--;
                    }
                    else
                    {
                        repeatBuf.Add(line);
                    }
                }
                else
                {
                    if (lineNoComments.IndexOf("#if") == 0)
                    {
                        ifMode = repeatMode > 0 ? 2 : 1;
                        ifWhat = lineNoComments.Substring(4).Trim();
                    }
                    else if (lineNoComments.IndexOf("#repeat") == 0)
                    {
                        repeatMode++;
                        repeatWhat = lineNoComments.Substring(8).Trim();
                        repeatBuf  = new TArrayList();
                    }
                    else
                    {
                        if (trimLine)
                        {
                            line  = line.Trim();
                            line += trimEnd;
                        }
                        content += line;
                    }
                }
            }
            var result = FormatTemplate(content, hash);

            return(result);
        }
Ejemplo n.º 20
0
 /// Default public constructor
 public DataSet()
 {
     this.rows       = new TArrayList();
     this.pageSize   = 10;
     this.totalPages = 0;
 }