Example #1
0
        public string InsertSql(Term term)
        {
            var converterFunctions = new ConverterFunctions();

            return string.Format(
                "INSERT INTO wp_terms(name, slug, term_group) VALUES" +
                "('{0}','{1}',0);" +
                "SET @l=LAST_INSERT_ID();" +
                "INSERT INTO wp_term_taxonomy(term_id, taxonomy, description, parent, count) VALUES (@l,'category','{2}',0,0);" +
                "SELECT @l;",
                term.Name.EscapeSql(),
                converterFunctions.SeoUrl(term.Name).EscapeSql(),
                term.Description.EscapeSql());
        }
Example #2
0
        public int GetRelevance(Item item, string keyword)
        {
            var titleContainsKeywordScore = _programOptions.TitleContainsKeywordScore;
            var titleStartsWithKeywordScore = _programOptions.TitleStartsWithKeywordScore;
            var contentContainsKeywordScore = _programOptions.ContentContainsKeywordScore;
            var contentFirst100ContainsKeywordScore = _programOptions.ContentFirst100ContainsKeywordScore;
            var keywordRatioScore = _programOptions.KeywordRatioScore;

            var score = 0;
            if (Regex.IsMatch(item.Title, keyword, RegexOptions.IgnoreCase))
            {
                score += titleContainsKeywordScore;
            }
            if (item.Title.StartsWith(keyword, true, CultureInfo.InvariantCulture))
            {
                score += titleStartsWithKeywordScore;
            }

            if (!string.IsNullOrEmpty(item.Content) && Regex.IsMatch(item.Content, keyword, RegexOptions.IgnoreCase))
            {
                score += contentContainsKeywordScore;
            }
            if (!string.IsNullOrEmpty(item.Content) && item.Content.Length > 100 && Regex.IsMatch(item.Content.Substring(0, 100), keyword, RegexOptions.IgnoreCase))
            {
                score += contentFirst100ContainsKeywordScore;
            }
            if (KeywordRatio(item, keyword) >= 1)
            {
                score += keywordRatioScore;
            }

            score += GetRelevanceForNonExactMatch(item, keyword);

            if (item.Site == "Bonanza")
            {
                var imageCount = item.Content.ToLower()
                    .Split(new string[] { "<img " }, StringSplitOptions.RemoveEmptyEntries);
                var cf = new ConverterFunctions();
                var stripped = cf.StripTags(item.Content, new List<string>() { "font", "p", "span", "div", "h2", "h3", "h4", "tr", "td" });
                int rate = (int)((stripped.Length / (double)item.Content.Length) * 100);
                rate -= imageCount.Length * 5;
                if (rate < 10) score = -1;
            }

            return score;
        }
Example #3
0
        public int InsertUser(string displayname, string blogName="mysite.com", string userName = "", string email = "", string userUrl = "", string passEncoded = "$P$BYvykzVw6vXRlA4jyW85HZxrCoJoE40")
        {
            if (string.IsNullOrEmpty(userName))
            {
                var converterFunctions = new ConverterFunctions();
                userName = converterFunctions.SeoUrl(displayname);
            }
            if (string.IsNullOrEmpty(email))
            {
                email = userName + "@" + blogName;
            }
            if (string.IsNullOrEmpty(userUrl))
            {
                userUrl = "http:\\www." + userName.Replace("-", "") + ".com";
            }

            //duplicate check
            var userDataSet = _dal.GetData(string.Format("Select ID from wp_users Where user_login='{0}'", userName));
            if (userDataSet.Tables.Count > 0 && userDataSet.Tables[0].Rows.Count > 0 &&
                userDataSet.Tables[0].Rows[0].ItemArray.Length > 0)
            {
                return 0;
            }

            var userInsertDataSet = _dal.GetData(string.Format(
                "INSERT INTO wp_users(user_login, user_pass, user_nicename, user_email, user_url, user_registered, user_activation_key, user_status, display_name)" +
                " VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}');SELECT LAST_INSERT_ID();",
                userName,
                passEncoded,
                userName,
                email,
                userUrl,
                DateTime.Now.ToLongDateString(),
                passEncoded,
                0,
                displayname));
            if (userInsertDataSet.Tables.Count == 0) { return -1; }
            if (userInsertDataSet.Tables[0].Rows.Count == 0) { return -1; }
            if (userInsertDataSet.Tables[0].Rows[0].ItemArray.Length == 0) { return -1; }

            return int.Parse(userInsertDataSet.Tables[0].Rows[0][0].ToString());
        }
Example #4
0
        public virtual string PostBody(int thumbnailSize, bool includePriceAndSource = true, bool tagsAsText = true)
        {
            var programOptionsFactory = new ProgramOptionsFactory();
            var programOptions = programOptionsFactory.Get();
            var converterFunctions = new ConverterFunctions();
            var content = new StringBuilder("");
            if (ItemImages.Count > 0)
            {
                content.Append(string.Format("<div style=\"width: {0}px; margin-right: 10px;\">", (2 * thumbnailSize + 30)));
                foreach (var itemImage in ItemImages)
                {
                    content.Append(string.Format(
                        "<div style=\"width: {3}px; height: {3}px; float: left; margin-right: 15px; margin-bottom: 3px;\"><a href=\"{0}\"><img src=\"{1}\" alt=\"{2}\" title=\"{2}\" /></a></div>",
                        itemImage.Link, itemImage.NewSource, Title, thumbnailSize));

                }
                content.Append("</div>");

            }

            if (((int)(Price * 100)) > 0 && includePriceAndSource)
            {
                content.Append(string.Format("<h4>Price:{1}{0}</h4>", Price, programOptions.PriceSign));
            }
            content.Append(string.Format("<h2>{0}</h2>", Title));
            content.Append(converterFunctions.ArrangeContent(Content));
            if (!string.IsNullOrEmpty(Url) && includePriceAndSource)
            {
                content.Append(SourceStatement());
            }

            if (Tags != null && Tags.Count > 0 && tagsAsText && includePriceAndSource)
            {
                content.Append("<br/>Tags: ");
                content.Append(string.Join(", ", Tags));
            }
            return content.ToString();
        }
Example #5
0
        public virtual Item.Item GetItem(string title, string url, string extraInfo)
        {
            var item = new Item.Item()
                           {
                               Tags = new List<string>(),
                               ItemImages = new List<ItemImage>(),
                               Url = url//,
                               //Keyword = keyword
                           };

            string itemHtml = "";
            var maxTry = 3;
            var tryCount = 0;
            while (tryCount < maxTry)
            {
                if (_options.UseProxy)
                {
                    itemHtml = WebHelper.CurlSimple(url, "text/html",
                        new WebProxy(_options.ProxyAddress + ":" + _options.ProxyPort));
                }
                else
                {
                    itemHtml = WebHelper.CurlSimple(url);
                }
                if (!string.IsNullOrEmpty(itemHtml))
                {
                    break;
                }
                Thread.Sleep(TimeSpan.FromSeconds(3));
                tryCount++;
            }

            if (itemHtml == null) return null;
            var htmlDoc = new HtmlDocument();
            htmlDoc.LoadHtml(itemHtml);

            var metaDescription = htmlDoc.DocumentNode.SelectSingleNode(MetaDescriptionXPath);
            if (metaDescription != null)
            {
                item.MetaDescription = metaDescription.Attributes["content"].Value;
            }

            var tags = htmlDoc.DocumentNode.SelectNodes(TagsXPath);
            if (tags != null)
            {
                foreach (var tag in tags)
                {
                    item.Tags.Add(tag.InnerText);
                }
            }

            var images = htmlDoc.DocumentNode.SelectNodes(ImagesXPath);
            if (images != null)
            {
                foreach (var image in images)
                {

                    var imageUrl = image.Attributes[ImagesAttribute] == null ? "" : image.Attributes[ImagesAttribute].Value;
                    if (string.IsNullOrEmpty(imageUrl))
                    {
                        imageUrl = image.Attributes[AlternativeImagesAttribute] == null ? "" : image.Attributes[AlternativeImagesAttribute].Value;
                        if (string.IsNullOrEmpty(imageUrl))
                        {
                            continue;
                        }
                    }
                    if (!imageUrl.StartsWith("http://") && !imageUrl.StartsWith("https://"))
                    {
                        imageUrl = "http:" + (imageUrl.StartsWith("//") ? "" : "//") + imageUrl;
                    }
                    item.ItemImages.Add(new ItemImage() { OriginalSource = imageUrl, Primary = true });
                }
            }

            var metaPrice = htmlDoc.DocumentNode.SelectSingleNode(PriceXPath);
            if (metaPrice != null)
            {
                item.Price = GetPriceValue(metaPrice);
            }

            var content = htmlDoc.DocumentNode.SelectSingleNode(DescriptionXPath);
            if (content != null)
            {
                item.Content = Regex.Replace(content.InnerHtml, "<a.*>.*</a>", "");
                item.Content = RefineContent(item.Content);
                var converterFunctions = new ConverterFunctions();
                item.WordCount = converterFunctions.StripTags(content.InnerHtml, new List<string>()).WordCount();

            }
            item.Title = title;
            var regex = new Regex(IdRegex);
            var match = regex.Match(url);
            if (match.Success)
            {
                item.Id = Int32.Parse(match.Groups[1].Value);
            }
            item.Site = Name;
            SetCreatedDate(htmlDoc, item);
            return item;
        }
Example #6
0
        public void PublishPost(Post post)
        {
            var catDal = new CategoryDal(_dal);
            var postCategories = catDal.GetCategories(post.Id);
            var defaultCategoryId = catDal.GetInsertDefaultCategoryId();
            var categorySet = postCategories.Contains(defaultCategoryId);
            var uncategorizedSet = postCategories.Contains(1);

            var converterFunctions = new ConverterFunctions();
            var postName = converterFunctions.SeoPostUrl(post.Title);
            var sql = string.Format(
                "Update wp_posts set post_status='publish',post_date=NOW(),post_date_gmt=NOW(),post_modified=NOW(),post_modified_gmt=NOW(),post_name='{1}' where ID={0};",
                post.Id,
                postName.EscapeSql()
                );

            if (!uncategorizedSet)
            {
                sql += string.Format("Insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values({0}, {1},0);", post.Id, 1);
            }
            if (!categorySet)
            {
                sql += string.Format("Insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values({0}, {1},0);", post.Id, defaultCategoryId);
            }
            _dal.ExecuteNonQuery(sql);
        }
Example #7
0
        public int InsertPost(Post post)
        {
            var customFieldSql = new StringBuilder();
            foreach (var customField in post.CustomFields)
            {
                customFieldSql.Append(
                    string.Format("INSERT INTO wp_postmeta( post_id, meta_key, meta_value) VALUES (@l,'{0}','{1}');",
                        customField.Key.EscapeSql(), customField.Value.EscapeSql()));

            }

            var tagsSql = new StringBuilder();
            if (post.Terms != null)
            {
                foreach (var term in post.Terms)
                {
                    tagsSql.Append(
                        string.Format(
                            "INSERT INTO wp_term_relationships(object_id, term_taxonomy_id, term_order) VALUES (@l,{0},0);",
                            term.Id));

                }
            }

            var imagesSql = new StringBuilder();
            foreach (var imageId in post.ImageIds)
            {
                imagesSql.Append(
                    string.Format("Update wp_posts set [email protected] where Id={0};", imageId));

            }

            var converterFunctions = new ConverterFunctions();
            var postName = converterFunctions.SeoUrl(post.Title);
            postName = "";

            var sql = string.Format(
                "INSERT INTO wp_posts(post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, " +
                "ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, " +
                "menu_order, post_type, post_mime_type, comment_count) VALUES " +
                "('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}');" +
                "SET @l=LAST_INSERT_ID();" +
                "Update wp_posts set guid=concat('{22}?p=',@l) where [email protected];" +
                "{23}{24}{25}SELECT @l;",
                post.Author, post.PublishDateTime.ToString("yyyy-MM-dd HH':'mm':'ss"), post.PublishDateTime.ToString("yyyy-MM-dd HH':'mm':'ss"), post.Content.EscapeSql(), post.Title.EscapeSql(), "", post.Status,
                post.CommentStatus, "open",
                "", postName.EscapeSql(), "", "", DateTime.Now.ToString("yyyy-MM-dd HH':'mm':'ss"), DateTime.Now.ToString("yyyy-MM-dd HH':'mm':'ss"), "", 0, "", 0,
                post.PostType, "", 0, post.BlogUrl.EscapeSql(), customFieldSql.ToString(), tagsSql.ToString(), imagesSql.ToString());

            var postInsertDataSet = _dal.GetData(sql);

            if (postInsertDataSet.Tables.Count == 0) { return -1; }
            if (postInsertDataSet.Tables[0].Rows.Count == 0) { return -1; }
            if (postInsertDataSet.Tables[0].Rows[0].ItemArray.Length == 0) { return -1; }

            var id = postInsertDataSet.Tables[0].Rows[0][0].ToString();
            return int.Parse(id);
        }