Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
feeds
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
feeds
Commits
4aef5be2
Commit
4aef5be2
authored
14 years ago
by
Alex Barth
Browse files
Options
Downloads
Patches
Plain Diff
#913672 andrewlevine: Break out CSV Parser into submethods so it is more easily overridable.
parent
17d40965
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.txt
+2
-0
2 additions, 0 deletions
CHANGELOG.txt
plugins/FeedsCSVParser.inc
+34
-6
34 additions, 6 deletions
plugins/FeedsCSVParser.inc
with
36 additions
and
6 deletions
CHANGELOG.txt
+
2
−
0
View file @
4aef5be2
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
Feeds 6.x xxxxxxxxxxxxxxxxxxxxxx
Feeds 6.x xxxxxxxxxxxxxxxxxxxxxx
--------------------------------
--------------------------------
- #913672 andrewlevine: Break out CSV Parser into submethods so it is more
easily overridable
- #853974 snoldak924, alex_b: Fix XSS vulnerabilities in module.
- #853974 snoldak924, alex_b: Fix XSS vulnerabilities in module.
- #887846 ekes: Make FeedsSimplePieEnclosure (un)serialization safe.
- #887846 ekes: Make FeedsSimplePieEnclosure (un)serialization safe.
- #908582 XiaN Vizjereij, alex_b: Fix "Cannot use object of type stdClass as
- #908582 XiaN Vizjereij, alex_b: Fix "Cannot use object of type stdClass as
...
...
This diff is collapsed.
Click to expand it.
plugins/FeedsCSVParser.inc
+
34
−
6
View file @
4aef5be2
...
@@ -19,25 +19,53 @@ class FeedsCSVParser extends FeedsParser {
...
@@ -19,25 +19,53 @@ class FeedsCSVParser extends FeedsParser {
$delimiter
=
$source_config
[
'delimiter'
]
==
'TAB'
?
"
\t
"
:
$source_config
[
'delimiter'
];
$delimiter
=
$source_config
[
'delimiter'
]
==
'TAB'
?
"
\t
"
:
$source_config
[
'delimiter'
];
$parser
->
setDelimiter
(
$delimiter
);
$parser
->
setDelimiter
(
$delimiter
);
// Get first line and use it for column names, convert them to lower case.
$header
=
$this
->
parseHeader
(
$parser
,
$iterator
);
if
(
!
header
)
{
return
;
}
$parser
->
setColumnNames
(
$header
);
// Populate batch.
$batch
->
setItems
(
$this
->
parseItems
(
$parser
,
$iterator
));
}
/**
* Get first line and use it for column names, convert them to lower case.
* Be aware that the $parser and iterator objects can be modified in this
* function since they are passed in by reference
*
* @param ParserCSV $parser
* @param ParserCSVIterator $iterator
* @return
* An array of lower-cased column names to use as keys for the parsed items.
*/
protected
function
parseHeader
(
ParserCSV
$parser
,
ParserCSVIterator
$iterator
)
{
$parser
->
setLineLimit
(
1
);
$parser
->
setLineLimit
(
1
);
$rows
=
$parser
->
parse
(
$iterator
);
$rows
=
$parser
->
parse
(
$iterator
);
if
(
!
count
(
$rows
))
{
if
(
!
count
(
$rows
))
{
return
;
return
FALSE
;
}
}
$header
=
array_shift
(
$rows
);
$header
=
array_shift
(
$rows
);
foreach
(
$header
as
$i
=>
$title
)
{
foreach
(
$header
as
$i
=>
$title
)
{
$header
[
$i
]
=
trim
(
drupal_strtolower
(
$title
));
$header
[
$i
]
=
trim
(
drupal_strtolower
(
$title
));
}
}
$parser
->
setColumnNames
(
$header
);
return
$header
;
}
/**
* Parse all of the items from the CSV.
*
* @param ParserCSV $parser
* @param ParserCSVIterator $iterator
* @return
* An array of rows of the CSV keyed by the column names previously set
*/
protected
function
parseItems
(
ParserCSV
$parser
,
ParserCSVIterator
$iterator
)
{
// Set line limit to 0 and start byte to last position and parse rest.
// Set line limit to 0 and start byte to last position and parse rest.
$parser
->
setLineLimit
(
0
);
$parser
->
setLineLimit
(
0
);
$parser
->
setStartByte
(
$parser
->
lastLinePos
());
$parser
->
setStartByte
(
$parser
->
lastLinePos
());
$rows
=
$parser
->
parse
(
$iterator
);
$rows
=
$parser
->
parse
(
$iterator
);
return
$rows
;
// Populate batch.
$batch
->
setItems
(
$rows
);
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment