Пример #1
0
        /// <summary>
        /// Return the url title and description
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string GetURLInfo(string url)
        {
            //First thing first, check if the link is exist in the system yet
            //Strip the # part of the url
            if (url.IndexOf("#") > 0)
            {
                url = url.Remove(url.IndexOf("#"));
            }

            //Return if link exist in the system
            VL.ORM.Link newLink = new VL.ORM.Link("Url", url);
            if (newLink.LinkID > 0)
            {
                return "1§" + string.Format(@"Link đã được gửi vào hệ thống trước đây. <br />
                               Bạn có thể xem link ở đây:<a href='{0}'>{1}</a><br/>
                               Bạn không thể gửi thêm lần nữa. Sorry!",
                    newLink.RewriteLink, newLink.Title);
            }

            try
            {
                //Load the URL
                WebRequest wReq = WebRequest.Create(url);
                StreamReader reqStream = new StreamReader(wReq.GetResponse().GetResponseStream());
                string HTMLCode = reqStream.ReadToEnd();
                reqStream.Close();
                //Get the title only
                //Need to replace to avoid duplicate
                string Result = Regex.Match(HTMLCode, @"(?<=<title>)[\w|\W]*(?=</title>)",
                    RegexOptions.IgnoreCase | RegexOptions.Multiline).Value.Trim().Replace("§", " ");
                //Avoid sql injection warning
                Result = Regex.Replace(Result, @"&#\d*;", "");
                //Add the description in as well
                string descriptionText = Regex.Match(HTMLCode, @"(<meta[\W]*name[\W]*=[\W]*""description[\W]+content=""[^""]*)",
                    RegexOptions.IgnoreCase | RegexOptions.Multiline).Value.Replace("§", " ");
                descriptionText = Regex.Replace(descriptionText, "<[\\w\\W]*\"", "").Trim();
                Result += "§" + descriptionText;
                //Check if the content of the link is in vietnamese :
                if (Regex.IsMatch(HTMLCode, "ư") || Regex.IsMatch(url, @"\.vn"))
                    Result += "§" + "1";
                else
                    Result += "§" + "0";

                return Result;
            }
            catch
            {
                return "";
            }
        }
Пример #2
0
 /// <summary>
 /// Initialize the control and set all the label and links
 /// </summary>
 /// <param name="inLinkList"></param>
 public override void initControl(params object[] inLinkList)
 {
     _isInLinkList = (bool)inLinkList[1];
     _thisLink = (VL.ORM.VLinkList)inLinkList[0];
     _currentLink = VL.ORM.Link.Get(_thisLink.LinkID);
     lblPoint.Text = _thisLink.TotalPoint.ToString();
     //Get description if there is
     if (_thisLink.Description.Length > 0)
     {
         if (_thisLink.Description.Length > 200 && _isInLinkList)
         {
             lblDescription.InnerHtml = _thisLink.Description.Substring(0, 200);
         }
         else
         {
             lblDescription.InnerHtml = _thisLink.Description;
         }
         if (_isInLinkList)
         {
             lblDescription.InnerHtml += string.Format("...<a href='{0}' class='lCol2'>More</a><br/>",
                     VL.ORM.Link.GetRewriteLink(_thisLink.URLRewrite));
         }
     }
     //Get user info
     _postedUser = VL.ORM.User.Get(_thisLink.Poster);
     //Check if user vote for this yet? If they did, then change the button
     if (VL.Current.User!=null)
     {
         int VotedCount = new VL.ORM.VoteCollection().Where("LinkID", _thisLink.LinkID).Where("UserID", VL.Current.User.UserID).Load().Count;
         if (VotedCount > 0)
         {
             _voted = true;
             btnVoteUp.ImageUrl = "/assets/images/fireOn.gif";
         }
     }
 }
Пример #3
0
 public override void initControl(params object[] inObj)
 {
     _thisLink = (VL.ORM.Link)inObj[0];
 }