Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
feeds_xpathparser
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
feeds_xpathparser
Commits
c541f102
Commit
c541f102
authored
14 years ago
by
Chris Leppanen
Browse files
Options
Downloads
Patches
Plain Diff
Fixed mappings issues. Roll back to old method.
parent
b03ad59d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
FeedsXPathParser.inc
+55
-3
55 additions, 3 deletions
FeedsXPathParser.inc
feeds_xpathparser.module
+0
-32
0 additions, 32 deletions
feeds_xpathparser.module
with
55 additions
and
35 deletions
FeedsXPathParser.inc
+
55
−
3
View file @
c541f102
...
...
@@ -43,6 +43,7 @@ class FeedsXPathParserBase extends FeedsParser {
*
* @param $xml
* A SimpleXMLElement object.
*
* @return array
* Returns a structured array suitable for adding to a batch object with
* $batch->setItems().
...
...
@@ -61,7 +62,7 @@ class FeedsXPathParserBase extends FeedsParser {
$query
=
strtr
(
$query
,
$variables
);
$result
=
$this
->
parseSourceElement
(
$item
,
$query
,
$source
);
if
(
!
is_array
(
$result
))
{
$variables
[
'$'
.
$this
->
mappings
[
$source
]]
=
"'
$result
'"
;
$variables
[
'$'
.
$this
->
mappings
[
$source
]]
=
$result
;
}
$parsed_item
[
$source
]
=
$result
;
}
...
...
@@ -75,8 +76,10 @@ class FeedsXPathParserBase extends FeedsParser {
*
* @param $xml
* The XML element to execute the query on.
*
* @param $query
* An XPath query.
*
* @return array
* An array containing the results of the query.
*/
...
...
@@ -136,7 +139,6 @@ class FeedsXPathParserBase extends FeedsParser {
/**
* Normalizes XPath queries, adding the default namespace.
*
*/
private
function
addDefaultNamespace
(
$query
)
{
$parser
=
new
FeedsXPathQueryParser
(
$query
);
...
...
@@ -148,10 +150,13 @@ class FeedsXPathParserBase extends FeedsParser {
*
* @param $item
* A SimpleXMLElement from the context array.
*
* @param $query
* An XPath query.
*
* @param $source
* The name of the source for this query.
*
* @return array
* An array containing the results of the query.
*/
...
...
@@ -198,7 +203,6 @@ class FeedsXPathParserBase extends FeedsParser {
$mappings_
=
feeds_importer
(
$this
->
id
)
->
processor
->
config
[
'mappings'
];
$uniques
=
$mappings
=
array
();
foreach
(
$mappings_
as
$mapping
)
{
if
(
strpos
(
$mapping
[
'source'
],
'xpathparser:'
)
===
0
)
{
$mappings
[
$mapping
[
'source'
]]
=
$mapping
[
'target'
];
...
...
@@ -236,6 +240,7 @@ class FeedsXPathParserBase extends FeedsParser {
);
$form
[
'sources'
][
'help'
][
'#value'
]
=
'<div class="help">'
.
theme
(
'item_list'
,
$items
)
.
'</div>'
;
}
$variables
=
array
();
foreach
(
$mappings
as
$source
=>
$target
)
{
$form
[
'sources'
][
$source
]
=
array
(
...
...
@@ -365,6 +370,26 @@ class FeedsXPathParserBase extends FeedsParser {
libxml_use_internal_errors
(
$use_errors
);
return
array
(
$results
,
$error
);
}
/**
* Override parent::getMappingSources().
*/
public
function
getMappingSources
()
{
$xpath_source
=
array
(
'xpathparser:0'
=>
array
(
'name'
=>
t
(
'XPath Expression'
),
'description'
=>
t
(
'Allows you to configure an XPath expression that will populate this field.'
),
),
);
$sources
=
parent
::
getMappingSources
();
// Older versions of Feeds return FALSE here.
if
(
is_array
(
$sources
))
{
return
$sources
+
$xpath_source
;
}
return
$xpath_source
;
}
}
class
FeedsXPathParserHTML
extends
FeedsXPathParserBase
{
...
...
@@ -442,6 +467,33 @@ class FeedsXPathParserXML extends FeedsXPathParserBase {
}
}
/**
* Implementation of hook_form_feeds_ui_mapping_form_alter().
*
* This is an interesting bit of work. Each source name has to be unique,
* but we have no idea how many to create with getMappingSources() because we
* don't know how many targets there are going to be.
*
* The solution is to keep track in the form how many have been added.
*/
function
feeds_xpathparser_form_feeds_ui_mapping_form_alter
(
&
$form
,
&
$form_state
)
{
$newest_xpath_mapping
=
array
();
foreach
(
$form
[
'#mappings'
]
as
$mapping
)
{
if
(
strpos
(
$mapping
[
'source'
],
'xpathparser:'
)
===
0
)
{
$newest_xpath_mapping
=
$mapping
;
}
}
if
(
!
empty
(
$newest_xpath_mapping
))
{
list
(
$a
,
$count
)
=
explode
(
':'
,
$newest_xpath_mapping
[
'source'
]);
$default_source
=
$a
.
':'
.
'0'
;
$label
=
$form
[
'source'
][
'#options'
][
$default_source
];
unset
(
$form
[
'source'
][
'#options'
][
$default_source
]);
$form
[
'source'
][
'#options'
][
$a
.
':'
.
++
$count
]
=
$label
;
}
}
/**
* Pseudo-parser of XPath queries. When an XML document has a default
* namespace this gets called so that adding the __default__ namepace where
...
...
This diff is collapsed.
Click to expand it.
feeds_xpathparser.module
+
0
−
32
View file @
c541f102
...
...
@@ -41,35 +41,3 @@ function feeds_xpathparser_feeds_plugins() {
function
feeds_xpathparser_enable
()
{
cache_clear_all
(
'plugins:feeds:plugins'
,
'cache'
);
}
/**
* Implementation of hook_feeds_parser_sources_alter().
*
* Clear Feed's plugin cache so that this plugin shows up.
*/
function
feeds_xpathparser_feeds_parser_sources_alter
(
&
$sources
,
$content_type
)
{
$importer_id
=
feeds_get_importer_id
(
$content_type
);
$mappings
=
feeds_importer
(
$importer_id
)
->
processor
->
config
[
'mappings'
];
$description
=
t
(
'Allows you to configure an XPath expression that will populate this field.'
);
$name
=
t
(
'XPath expression'
);
$newest_xpath_mapping
=
array
();
foreach
(
$mappings
as
$mapping
)
{
if
(
strpos
(
$mapping
[
'source'
],
'xpathparser:'
)
===
0
)
{
$newest_xpath_mapping
=
$mapping
;
}
}
if
(
!
empty
(
$newest_xpath_mapping
))
{
list
(
$a
,
$count
)
=
explode
(
':'
,
$newest_xpath_mapping
[
'source'
]);
$sources
[
$a
.
':'
.
++
$count
]
=
array
(
'name'
=>
$name
,
'description'
=>
$description
,
);
}
else
{
$sources
[
'xpathparser:0'
]
=
array
(
'name'
=>
$name
,
'description'
=>
$description
,
);
}
}
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