News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Inserting posts using createPost

Started by kai920, December 13, 2009, 03:29:13 AM

Previous topic - Next topic

kai920


I'm trying to convert about 400 pieces of Joomla content over to SMF. With Arantor's help I've gotten rid of some of the unwanted HTML via regex (still WIP).

While my script is mostly working, I have some questions:

1. after I insert all the topics & posts using createPost - can SMF sort by post date?  I don't want topics from 2005 to be listed before this year's posts.

2. if I click to modify a post and immediately save it, the spacing in my posts look much better. (see before vs after jpg attachments). What does modifyPost do that createPost doesn't?

3. can I mark all all posts created with createPost as read for everyone, not just the author?


Thanks for reading!

H

Quote1. after I insert all the topics & posts using createPost - can SMF sort by post date?  I don't want topics from 2005 to be listed before this year's posts.

Not by default. You can use Custom Board Sort if you're on 1.1.x

Quote3. can I mark all all posts created with createPost as read for everyone, not just the author?

I don't think so. You many need to use markread() for every single user which isn't the best idea. Hopefully someone will have a better suggestion :)

Quote2. if I click to modify a post and immediately save it, the spacing in my posts look much better. (see before vs after jpg attachments). What does modifyPost do that createPost doesn't?

Most likely something gets regexed client-side that you weren't already doing? Did you try comparing what is stored in smf_messages for the post before and after?
-H
Former Support Team Lead
                              I recommend:
Namecheap (domains)
Fastmail (e-mail)
Linode (VPS)
                             

kai920

#2
Quote from: H on December 13, 2009, 03:34:31 AM
Quote1. after I insert all the topics & posts using createPost - can SMF sort by post date?  I don't want topics from 2005 to be listed before this year's posts.

Not by default. You can use Custom Board Sort if you're on 1.1.x

Ah yes, I used that before, but I'm now on 2.0 RC2. There's also Board Sort Methods that should only need a bit of work to be working for RC2.

Quote
Quote2. if I click to modify a post and immediately save it, the spacing in my posts look much better. (see before vs after jpg attachments). What does modifyPost do that createPost doesn't?

Most likely something gets regexed client-side that you weren't already doing? Did you try comparing what is stored in smf_messages for the post before and after?



I didn't look at the table directly, but I did try observing Firebug's HTML output. Looking at smf_messages is a good idea though. It seems to have stripped some extra <br> tags and what not? (maybe empty <p></p> paragraph pairings?)

I wonder if I invoked modifyPost in my script after createPost, if that would lead to the same cosmetic changes. It should, right?




edit - took a look at the table and attached screenshot of before and after modifyPost. I think when I insert HTML directly, the line breaks are being interpreted as an extra br tag?

Arantor

I don't think Custom Board Sort would entirely help you. Just insert posts in chronological order and you're done, plus it's faster that way.

Note that every \n (not \r\n, since that's a double break in some cases) is replaced with <br />. I'd wonder if you don't already have something funky in the original content that needs to be emptied out.

kai920

Quote from: Arantor on December 13, 2009, 06:20:59 AM
Just insert posts in chronological order and you're done, plus it's faster that way.

wouldn't all my "new" posts (changed to the original creation date of 2005, 2006 etc) inserted using createPost show up before my current posts?

Arantor

Nope. They're always sorted by topic and then message id.

I wasn't clear on whether you have existing posts or not, or whether this is a fully new forum - always pays to be clear.

kai920

It's an existing forum - would custom board sort still help?

Thanks for your help, as always.

Arantor

Not sure whether that can sort strictly by date or not.

kai920

Quote from: Arantor on December 13, 2009, 09:14:14 AM
Not sure whether that can sort strictly by date or not.

Doesn't look like it - if topics have no replies it's correct, but with replies the overall sorting order is incorrect.

kai920

Quote from: Arantor on December 13, 2009, 06:20:59 AM
Note that every \n (not \r\n, since that's a double break in some cases) is replaced with <br />. I'd wonder if you don't already have something funky in the original content that needs to be emptied out.

Here's another screenshot of the text in the body column before and after modifying a post.


What is the entity & #13;?

kai920

Quote from: H on December 13, 2009, 03:34:31 AM
Quote
Quote3. can I mark all all posts created with createPost as read for everyone, not just the author?

I don't think so. You many need to use markread() for every single user which isn't the best idea. Hopefully someone will have a better suggestion :)


So the markRead() function in 2.0 says "Requires a valid ID in the query string". Is this the ID of the topic?




Arantor

Entity 13 is a carriage return, the first half of a newline character pair on Windows (Windows expects carriage return, followed by newline, a.k.a. \r\n) while SMF itself only looks for \n in reformatting a page.

markRead requires a valid session id in the querystring, that long series of characters that takes the form of abcd1234=abcd1234abcd1234abcd1234 (not necessarily those characters exactly, but will be series of characters = series of characters)

kai920

Quote from: Arantor on December 14, 2009, 02:40:09 AM
Entity 13 is a carriage return, the first half of a newline character pair on Windows (Windows expects carriage return, followed by newline, a.k.a. \r\n) while SMF itself only looks for \n in reformatting a page.


Sorry, you lost me here. Why is SMF replacing \r\n with a carriage return (entity 13)? Does \r by itself mean anything?


QuotemarkRead requires a valid session id in the querystring, that long series of characters that takes the form of abcd1234=abcd1234abcd1234abcd1234 (not necessarily those characters exactly, but will be series of characters = series of characters)


If that's the case, I can't really use markRead to mark my inserted messages as "read" for everyone, can I?

Arantor

SMF isn't doing anything of the sort directly. Somewhere along the line, \r is being entitified. Whether it's SMF or it's something else, I don't know. But I believe SMF does sanitise rogue data in posts and entitifies it.

The only direct operation it does is on \n, to <br />\n

And, no, but you *can* use the query it uses to nicely fill up your log-read tables.

kai920

Quote from: Arantor on December 14, 2009, 03:18:57 AM
SMF isn't doing anything of the sort directly. Somewhere along the line, \r is being entitified. Whether it's SMF or it's something else, I don't know. But I believe SMF does sanitise rogue data in posts and entitifies it.

Hmm, okay. Let me try doing a simple search and replace from \r\n to entity 13 before I try to insert them into SMF...

(Wow, quite a lot of \r\n 's... almost 23,000!)

Arantor

Or just replace with \n, which would be preferable - since it reduces your DB, and also means you don't get double spacing which I believe was the original issue?

kai920

#16
Quote from: Arantor on December 14, 2009, 03:47:38 AM
Or just replace with \n, which would be preferable - since it reduces your DB, and also means you don't get double spacing which I believe was the original issue?

Good idea, I'll try this and let you know the results.

edit.. didn't work. There are like 4 br tags before, and after modifying the post, they're all gone. (!?)

I should mention that my inserted posts sit between html and /html bbcode tags.

Arantor

I'd guess that the \n were also removed then.

kai920

Quote from: Arantor on December 14, 2009, 05:35:36 AM
I'd guess that the \n were also removed then.

You mean by my search and replace in the SQL, or after the post were modified?

Arantor

Don't know, but if it's not generating <br />'s, it doesn't have \n's to replace to form <br />s.

Advertisement: