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 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='******'", 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 #3
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 post_parent=@l 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 Id=@l;" +
                "{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);
        }