Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#16 2008-12-01 05:35:05
- azw
- Member
- Registered: 2007-01-29
- Posts: 279
Re: jmd_csv: Batch-import articles from a CSV
Thanks for getting back to me, Jon!
jm wrote:
…. I’ll see about doing some trimming of fields and the CSV file too, so you don’t have to re-save an Excel file.
I think the Excel problem is fixed. I’m uploaded directly with an Excel csv now! It’s easy.
Fixing the “Leave text untouched” / “Use Textile” issue and trimming excess white space from the front and end of fields would be a great help!
You’re right that I didn’t need to worry about using a tab-delimited file. Excel’s csv conversion adds quotes around any field with a comma in it.
Last edited by azw (2008-12-01 05:36:13)
Offline
#17 2009-03-06 07:45:59
- azw
- Member
- Registered: 2007-01-29
- Posts: 279
Re: jmd_csv: Batch-import articles from a CSV
Jon, have you thought about having this added to the plugin directory over at http://textpattern.org/plugins? It’s worth doing!
Offline
Re: jmd_csv: Batch-import articles from a CSV
azw wrote:
have you thought about having this added to the plugin directory over at http://textpattern.org/plugins? It’s worth doing!
I have, but I was kinda hoping something would happen with .org (slow and not really useful). I guess I’ll bite the bullet and add a slew of plugins from last summer.
Last edited by jm (2009-03-10 04:22:18)
Offline
#19 2009-10-21 18:32:44
- woof
- Member

- Registered: 2004-08-01
- Posts: 128
Re: jmd_csv: Batch-import articles from a CSV
Hi Jon-Michael
I’m trying to import a lot of articles that need different timestamps. Is there any way I can specify my own “Posted” values in the imported csv? It seems the default is to timestamp the imported articles with the current time and when I include a “Posted” column in my csv with my desired timestamp data I get the following error
Warning: Column ‘Posted’ specified twice insert into…[etc]
Is there a way around this? It would be a huge help with the task in hand, thanks
Offline
Re: jmd_csv: Batch-import articles from a CSV
woof wrote:
Is there a way around this? It would be a huge help with the task in hand, thanks
Try deleting this line (~L210):
Posted=now(),
Offline
#21 2009-10-21 20:41:02
- woof
- Member

- Registered: 2004-08-01
- Posts: 128
Re: jmd_csv: Batch-import articles from a CSV
jm wrote:
Try deleting this line (~L210):
Perfect — Thanks Jon-Michael!
Offline
Re: jmd_csv: Batch-import articles from a CSV
Hi Jon-Michael
I used the plugin to import a bunch of article, the problem occured with line ending, even if i tryed to modify the file with notepad++ the problem still happen.
Then i decided to watch phpmyadmin to see what is trored in db, then i found that body_html column of textpattern table is the same a body column, in a regular article the body_html is the html version of the body, and watching at the code i see that you dont insert html version, you only copy the body column to body_html column.
Hope that help.
Offline
Re: jmd_csv: Batch-import articles from a CSV
Hi Jon, me again,
I think it s not a bug because you set textile_body=0 and textile_excerpt=0 to import like a text.
I need to import the articles like html, then i make a modification to your plugin to do that and here is it:
public function import($handle, $status)
{
global $prefs, $txp_user;
include txpath.'/lib/classTextile.php';
$htm = new Textile;
$row = 1;
while (($csv = fgetcsv($handle, 0, ',')) !== FALSE)
{
$fields = count($csv);
if ($row === 1)
{
for ($i = 0; $i < $fields; $i++)
{
$header[$i] = $csv[$i];
}
}
else
{
$insert = '';
foreach ($header as $key => $value)
{
// escape all fields
// $csv[$key] = doSlash($csv[$key]);
if ($value === 'Title')
{
$url_title = stripSpace($csv[$key], 1);
}
if ($value === 'Body' || $value === 'Excerpt')
{
$insert .= "{$value}_html='{$htm->TextileThis($csv[$key])}',";
}
$csv[$key] = doSlash($csv[$key]);
$insert .= "{$value}='{$csv[$key]}',";
}
$uid = md5(uniqid(rand(),true));
$insert .= <<<EOD
AuthorID='{$txp_user}',
LastModID='{$txp_user}',
AnnotateInvite='{$prefs['comments_default_invite']}',
url_title='{$url_title}',
uid='{$uid}',
feed_time=now(),
Posted=now(),
LastMod=now(),
Status={$status},
textile_body=1,
textile_excerpt=1
EOD;
safe_insert('textpattern', $insert);
}
$row++;
}
}
Hope that help.
Offline
Re: jmd_csv: Batch-import articles from a CSV
Aargh, been trying to make this plugin work for over two hours now, but I can’t seem to get it working..
This is what I’m doing:
1. Installed and activated the plugin
2. Made the “jmd_csv” category under the files
3. Upload a .csv file, give it “jmd_csv” category.
4. Import the .csv file in the Extensions tab
5. I get the “CSV imported successfully” message
But now, when I go to my articles I can’t see any of the imported articles…
In my .csv file I have a Title, Body, Excerpt and Section.
The articles in the Section row is the real name of a section on my site.
This is how my .csv file looks.

Can somebody please tell me what I’m doing wrong?
This plugin could save me 10 hours a month..
THANKS!
Offline
Re: jmd_csv: Batch-import articles from a CSV
Hi Karl
In the image there is title, body,excerpt, section;
I use Title, Excerpt,.. The first letter must be uppercase (i think), try if it works!
Cheers
Offline
Re: jmd_csv: Batch-import articles from a CSV
works like a charm! thank you very much for your great import script!
Offline
Re: jmd_csv: Batch-import articles from a CSV
i have a question. what will happen if there are two or more duplicated articles in .csv?
Offline
Offline
Re: jmd_csv: Batch-import articles from a CSV
When we add new article manually in txp! we will get this message Article posted. The same URL-only title is used by 2 different articles. when we try to add another article with the same URL-only title
so i wonder if there is a way to prevent duplicated articles with URL-only title?!
Offline
Re: jmd_csv: Batch-import articles from a CSV
function check_url_title($url_title)
{
// Check for blank or previously used identical url-titles
if (strlen($url_title) === 0)
{
return gTxt('url_title_is_blank');
}
else
{
$url_title_count = safe_count('textpattern', "url_title = '$url_title'");
if ($url_title_count > 1)
{
return gTxt('url_title_is_multiple', array('{count}' => $url_title_count));
}
}
return '';
}
finally, i found the one i need in txp_article.php
i’ll try to modify the script to fit my need! _
Last edited by HAC (2009-12-16 10:19:57)
Offline