コード例 #1
0
 public override void Process(ref HtmlNode node, HtmlAttribute dynamicAttribute, Dictionary <string, AliasReference> classNameAlias, Dictionary <int, string> classNameAliasdepth, int depth, string websiteId, ExpressionEvaluator evaluator, KEntity entity, dynamic websiteData, Models.Pagination viewDetails, string queryString, Dictionary <string, long> functionLog, bool isDetailsView = false, bool isNFSite = false, string developerId = null)
 {
     if (Kitsune.Helper.Constants.WidgetRegulerExpression.IsMatch(dynamicAttribute.Value))
     {
         string attributeValue = evaluator.EvaluateExpression(dynamicAttribute.Value, entity, viewDetails, classNameAlias, websiteData, websiteData?._system?.kresult, queryString, out bool hasData, functionLog, isDetailsView, isNFSite, developerId).ToString();
         if (!hasData || (System.Boolean.TryParse(attributeValue, out bool attVal) && attVal))
         {
             node = HtmlCommentNode.CreateNode("<!-- skip -->");
         }
     }
 }
コード例 #2
0
        public override void Process(ref HtmlNode node, HtmlAttribute dynamicAttribute, Dictionary <string, AliasReference> classNameAlias, Dictionary <int, string> classNameAliasdepth, int depth, string websiteId, ExpressionEvaluator evaluator, KEntity entity, dynamic websiteData, Models.Pagination viewDetails, string queryString, Dictionary <string, long> functionLog, bool isDetailsView = false, bool isNFSite = false, string developerId = null)
        {
            Node result = LexerGenerator.Parse(Helper.TrimDelimiters(dynamicAttribute.Value));

            if (result.Token.Value == ACTIONS.Loop)
            {
                string referenceObject = result.Children[0].Children[0].Token.Value;
                string referenceName   = result.Children[2].Children[0].Token.Value?.ToLower();
                var    refObj          = evaluator.EvaluateExpression(referenceObject, entity, viewDetails, classNameAlias, websiteData, websiteData?._system?.kresult, queryString, out bool hasData, functionLog, isDetailsView, isNFSite);
                if (refObj.GetType() == typeof(string) && refObj == "")
                {
                    node = HtmlCommentNode.CreateNode("<!-- skip -->");
                    return;
                }
                string offsetObj = evaluator.EvaluateExpression(result.Children[6], entity, viewDetails, classNameAlias, websiteData, websiteData?._system?.kresult, queryString, out hasData, functionLog, isDetailsView, isNFSite, developerId).ToString();
                int.TryParse(offsetObj, out int offset);
                int iteration    = 0;
                int maxIteration = 0;
                if (dynamicAttribute.Value.IndexOf("offset") > 0)
                {
                    if (int.TryParse(viewDetails.currentpagenumber, out int currentPage) && currentPage > 0)
                    {
                        iteration = offset * (currentPage - 1);
                    }
                }
                else
                {
                    string iterationObj = evaluator.EvaluateExpression(result.Children[4], entity, viewDetails, classNameAlias, websiteData, websiteData?._system?.kresult, queryString, out hasData, functionLog, isDetailsView, isNFSite, developerId).ToString();
                    int.TryParse(iterationObj, out iteration);
                }
                maxIteration = iteration + offset;
                int objSize = (int)evaluator.GetObjectSize(refObj);
                maxIteration = (maxIteration < objSize) ? maxIteration : objSize;
                if (iteration > maxIteration)
                {
                    node = HtmlCommentNode.CreateNode("<!-- skip -->");
                    return;
                }
                else if (objSize == maxIteration && dynamicAttribute.Value.IndexOf("offset") > 0)
                {
                    viewDetails.nextpage.url = "#";
                    viewDetails.pagesize     = maxIteration - iteration + 1;
                }

                AliasReference aliasReference = new AliasReference
                {
                    referenceObject = null,
                    iteration       = iteration,
                    maxIteration    = maxIteration
                };
                if (!classNameAlias.ContainsKey(referenceName))
                {
                    classNameAlias.Add(referenceName, aliasReference);
                    classNameAliasdepth.Add(depth, referenceName);
                }
            }
            else if (result.Token.Value == ACTIONS.InLoop)
            {
                string referenceName   = result.Children[0].Children[0].Token.Value?.ToLower();
                string referenceObject = result.Children[2].Children[0].Token.Value;
                var    obj             = evaluator.EvaluateExpression(referenceObject, entity, viewDetails, classNameAlias, websiteData, websiteData?._system?.kresult, queryString, out bool hasData, functionLog, isDetailsView, isNFSite);
                if (obj.GetType() == typeof(string) && obj == "")
                {
                    node = HtmlCommentNode.CreateNode("<!-- skip -->");
                    return;
                }
                AliasReference aliasReference = new AliasReference();
                aliasReference.referenceObject = referenceObject;
                aliasReference.iteration       = 0;
                aliasReference.maxIteration    = (int)evaluator.GetObjectSize(obj);

                if (!classNameAlias.ContainsKey(referenceName))
                {
                    classNameAlias.Add(referenceName, aliasReference);
                    classNameAliasdepth.Add(depth, referenceName);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Process the node for k-tags and k-expressions and return the processed node.
        /// </summary>
        /// <param name="readNode"></param>
        /// <param name="classNameAlias"></param>
        /// <param name="classNameAliasDepth"></param>
        /// <param name="depth"></param>
        /// <param name="isRepeat"></param>
        /// <param name="evaluator"></param>
        /// <returns></returns>
        private HtmlNode GetProcessedNode(HtmlNode readNode, Dictionary <string, AliasReference> classNameAlias, Dictionary <int, string> classNameAliasDepth, int depth, bool isRepeat, ExpressionEvaluator evaluator, string customerId, KEntity entity, dynamic websiteData, Models.Pagination viewDetails, string queryString, Dictionary <string, long> functionLog, bool isDetailsView, bool isNFSite)
        {
            try
            {
                HtmlNode returnNode = readNode.CloneNode(false);
                if (readNode.NodeType == HtmlNodeType.Comment)
                {
                    return(returnNode);
                }
                else if (readNode.NodeType == HtmlNodeType.Text)
                {
                    returnNode = HtmlTextNode.CreateNode(ReplaceKLanguage(readNode.OuterHtml, classNameAlias, evaluator, entity, viewDetails, websiteData, websiteData?._system?.kresult, queryString, functionLog, isDetailsView, isNFSite)) ?? returnNode;
                    return(returnNode);
                }
                else if (readNode.NodeType == HtmlNodeType.Element)
                {
                    if (isRepeat && (false || readNode.Attributes.Aggregate(false, (acc, x) => acc || x.Name.ToLower().Equals("k-norepeat"))))
                    {
                        returnNode = HtmlCommentNode.CreateNode("<!-- skip -->");
                    }

                    if (returnNode.Attributes.Count() > 0)
                    {
                        foreach (HtmlAttribute attribute in returnNode.Attributes.ToList())
                        {
                            if (returnNode.NodeType == HtmlNodeType.Comment)
                            {
                                break;
                            }
                            if (!String.IsNullOrEmpty(attribute.Name) && dynamicTagDescriptors.Contains(attribute.Name.ToLower()))
                            {
                                TagProcessor processor = processorFactory.GetProcessor(attribute.Name);
                                processor.ProcessNode(ref returnNode, attribute, classNameAlias, classNameAliasDepth, depth, customerId, evaluator, entity, websiteData, viewDetails, queryString, functionLog, isDetailsView, isNFSite);
                                if (!(attribute.Name.ToLower().Equals(LanguageAttributes.KPayAmount.GetDescription()) || attribute.Name.ToLower().Equals(LanguageAttributes.KPayPurpose.GetDescription())))
                                {
                                    returnNode.Attributes[attribute.Name.ToLower()]?.Remove();
                                }
                            }
                            else if (!attribute.Name.Equals("input", StringComparison.InvariantCultureIgnoreCase) && !attribute.Name.Equals("headers", StringComparison.InvariantCultureIgnoreCase) && Kitsune.Helper.Constants.WidgetRegulerExpression.IsMatch(attribute.Value))
                            {
                                attribute.Value = ReplaceKLanguage(attribute.Value, classNameAlias, evaluator, entity, viewDetails, websiteData, websiteData?._system?.kresult, queryString, functionLog, isDetailsView, isNFSite);
                                //attribute.Value = evaluator.EvaluateExpression(attribute.Value, entity, viewDetails, classNameAlias, websiteData, websiteData?._system?.kresult, queryString, isDetailsView, isNFSite);
                                if (returnNode.Name?.ToLower() == "img" && attribute.Name?.ToLower() == "src")
                                {
                                    attribute.Value = attribute.Value?.Trim();
                                }
                            }
                        }

                        if (requestType == KitsuneRequestUrlType.PRODUCTION && returnNode.Name?.ToLower() == "img")
                        {
                            string source = returnNode.Attributes.Where(x => x.Name.ToLower() == "src")?.FirstOrDefault()?.Value;
                            if (!string.IsNullOrEmpty(source) && !source.StartsWith("/") && !source.StartsWith(".") && !source.StartsWith("data:") && source.ToLower().IndexOf("k-img") < 0)
                            {
                                source = source.Replace(" ", "%20");
                                string ext    = source.Split('?')[0].Split('.').Last().ToLower();
                                string domain = source.Replace("http://", "").Replace("https://", "").Split('/')[0].ToLower();
                                if (!BlackListKImgFileExtension.Contains(ext) && !BlackListKImgDomain.Contains(domain) && !domain.Contains("cdn") && !domain.Contains("akamai") && !domain.Contains("cloudflare"))
                                {
                                    string rootUrl = websiteData?.rootaliasurl?.url?.Value;
                                    if (!source.StartsWith(rootUrl, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        string srcSetValue = "";
                                        foreach (int resolution in KLM_Constants.IMAGE_RESOLUTIONS)
                                        {
                                            srcSetValue += String.Format(KLM_Constants.K_IMG_FORMAT_STRING, resolution, source);
                                        }
                                        if (srcSetValue != null)
                                        {
                                            returnNode.Attributes.Add("srcset", srcSetValue);
                                            //returnNode.Attributes.Remove("src");
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //if (returnNode.Name?.ToLower() == "img")
                    //{
                    //    string source = returnNode.Attributes.Where(x => x.Name.ToLower() == "src").FirstOrDefault().Value;
                    //    if (!string.IsNullOrEmpty(source))
                    //    {
                    //        string[] srcParts = source.Split('?')[0].Split('.');
                    //        if (!srcParts[srcParts.Length - 1].Equals("svg", StringComparison.InvariantCultureIgnoreCase))
                    //        {
                    //            string rootUrl = websiteData?.rootaliasurl?.url?.Value;
                    //            string path = websiteData?._system?.request?.urlpath?.Value;
                    //            string srcSetValue = GetSrcSetValue(rootUrl, path, source);
                    //            if (srcSetValue != null)
                    //            {
                    //                returnNode.Attributes.Add("srcset", srcSetValue);
                    //                //returnNode.Attributes.Remove("src");
                    //            }
                    //        }
                    //    }
                    //}

                    if (returnNode.Name?.ToLower() == LanguageAttributes.KScript.GetDescription()?.ToLower())
                    {
                        TagProcessor processor = processorFactory.GetProcessor(returnNode.Name);
                        processor.ProcessNode(ref returnNode, null, classNameAlias, classNameAliasDepth, depth, customerId, evaluator, entity, websiteData, viewDetails, queryString, functionLog, isDetailsView, isNFSite);
                    }
                }
                return(returnNode);
            }
            catch (Exception ex) { throw; }
        }