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
48cfdeab
Commit
48cfdeab
authored
14 years ago
by
Alex Barth
Browse files
Options
Downloads
Patches
Plain Diff
Convert hook_nodeapi() to hook_node_X().
parent
c0426510
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
feeds.module
+125
-100
125 additions, 100 deletions
feeds.module
with
125 additions
and
100 deletions
feeds.module
+
125
−
100
View file @
48cfdeab
...
@@ -323,116 +323,141 @@ function feeds_feeds_plugins() {
...
@@ -323,116 +323,141 @@ function feeds_feeds_plugins() {
}
}
/**
/**
* Implements hook_nodeapi().
* Implements hook_node_load().
*
* @todo For Drupal 7, revisit static cache based shuttling of values between
* 'validate' and 'update'/'insert'.
*/
*/
function
feeds_nodeapi
(
&
$node
,
$op
,
$form
)
{
function
feeds_node_load
(
$node
)
{
_feeds_node_processor_node_load
(
$node
);
}
// $node looses any changes after 'validate' stage (see node_form_validate()).
/**
// Keep a copy of title and feeds array between 'validate' and subsequent
* Implements hook_node_validate().
// stages. This allows for automatically populating the title of the node form
*/
// and modifying the $form['feeds'] array on node validation just like on the
function
feeds_node_validate
(
$node
,
$form
,
&
$form_state
)
{
// standalone form.
if
(
!
$importer_id
=
feeds_get_importer_id
(
$node
->
type
))
{
static
$last_title
;
return
;
static
$node_feeds
;
}
// Keep a copy of the title for subsequent node creation stages.
// @todo: revisit whether $node still looses all of its properties
// between validate and insert stage.
$last_title
=
&
drupal_static
(
'feeds_node_last_title'
);
$last_feeds
=
&
drupal_static
(
'feeds_node_last_feeds'
);
// On validation stage we are working with a FeedsSource object that is
// not tied to a nid - when creating a new node there is no
// $node->nid at this stage.
$source
=
feeds_source
(
$importer_id
);
// Node module magically moved $form['feeds'] to $node->feeds :P
$last_feeds
=
$node
->
feeds
;
$source
->
configFormValidate
(
$last_feeds
);
// If node title is empty, try to retrieve title from feed.
if
(
trim
(
$node
->
title
)
==
''
)
{
try
{
$source
->
addConfig
(
$last_feeds
);
if
(
!
$last_title
=
$source
->
preview
()
->
getTitle
())
{
throw
new
Exception
();
}
}
catch
(
Exception
$e
)
{
drupal_set_message
(
$e
->
getMessage
(),
'error'
);
form_set_error
(
'title'
,
t
(
'Could not retrieve title from feed.'
),
'error'
);
}
}
}
// Break out node processor related nodeapi functionality.
/**
_feeds_nodeapi_node_processor
(
$node
,
$op
);
* Implements hook_node_insert().
*/
function
feeds_node_insert
(
$node
)
{
_feeds_node_processor_node_insert
(
$node
);
feeds_node_update
(
$node
);
}
/**
* Implements hook_node_update().
*/
function
feeds_node_update
(
$node
)
{
_feeds_node_processor_node_update
(
$node
);
if
(
!
$importer_id
=
feeds_get_importer_id
(
$node
->
type
))
{
return
;
}
$last_title
=
&
drupal_static
(
'feeds_node_last_title'
);
$last_feeds
=
&
drupal_static
(
'feeds_node_last_feeds'
);
// Populate title from result of validation phase.
if
(
!
empty
(
$last_title
))
{
$node
->
title
=
$last_title
;
}
$last_title
=
NULL
;
// A node may not have been validated, make sure $last_feeds is present.
if
(
empty
(
$last_feeds
))
{
$last_feeds
=
$node
->
feeds
;
}
// Add configuration to feed source and save.
$source
=
feeds_source
(
$importer_id
,
$node
->
nid
);
$source
->
addConfig
(
$last_feeds
);
$source
->
save
();
// Refresh feed if import on create is selected and suppress_import is
// not set.
if
(
$op
==
'insert'
&&
feeds_importer
(
$importer_id
)
->
config
[
'import_on_create'
]
&&
!
isset
(
$last_feeds
[
'suppress_import'
]))
{
feeds_batch_set
(
t
(
'Importing'
),
'import'
,
$importer_id
,
$node
->
nid
);
}
// Add source to schedule, make sure importer is scheduled, too.
if
(
$op
==
'insert'
)
{
$source
->
schedule
();
$source
->
importer
->
schedule
();
}
$last_feeds
=
NULL
;
}
/**
* Implements hook_node_delete().
*/
function
feeds_node_delete
(
$node
)
{
_feeds_node_processor_node_delete
(
$node
);
if
(
$importer_id
=
feeds_get_importer_id
(
$node
->
type
))
{
if
(
$importer_id
=
feeds_get_importer_id
(
$node
->
type
))
{
switch
(
$op
)
{
feeds_source
(
$importer_id
,
$node
->
nid
)
->
delete
();
case
'validate'
:
// On validation stage we are working with a FeedsSource object that is
// not tied to a nid - when creating a new node there is no
// $node->nid at this stage.
$source
=
feeds_source
(
$importer_id
);
// Node module magically moved $form['feeds'] to $node->feeds :P
$node_feeds
=
$node
->
feeds
;
$source
->
configFormValidate
(
$node_feeds
);
// If node title is empty, try to retrieve title from feed.
if
(
trim
(
$node
->
title
)
==
''
)
{
try
{
$source
->
addConfig
(
$node_feeds
);
if
(
!
$last_title
=
$source
->
preview
()
->
getTitle
())
{
throw
new
Exception
();
}
}
catch
(
Exception
$e
)
{
drupal_set_message
(
$e
->
getMessage
(),
'error'
);
form_set_error
(
'title'
,
t
(
'Could not retrieve title from feed.'
),
'error'
);
}
}
break
;
case
'presave'
:
if
(
!
empty
(
$last_title
))
{
$node
->
title
=
$last_title
;
}
$last_title
=
NULL
;
break
;
case
'insert'
:
case
'update'
:
// A node may not have been validated, make sure $node_feeds is present.
if
(
empty
(
$node_feeds
))
{
$node_feeds
=
$node
->
feeds
;
}
// Add configuration to feed source and save.
$source
=
feeds_source
(
$importer_id
,
$node
->
nid
);
$source
->
addConfig
(
$node_feeds
);
$source
->
save
();
// Refresh feed if import on create is selected and suppress_import is
// not set.
if
(
$op
==
'insert'
&&
feeds_importer
(
$importer_id
)
->
config
[
'import_on_create'
]
&&
!
isset
(
$node_feeds
[
'suppress_import'
]))
{
feeds_batch_set
(
t
(
'Importing'
),
'import'
,
$importer_id
,
$node
->
nid
);
}
// Add source to schedule, make sure importer is scheduled, too.
if
(
$op
==
'insert'
)
{
$source
->
schedule
();
$source
->
importer
->
schedule
();
}
$node_feeds
=
NULL
;
break
;
case
'delete'
:
// Remove attached source.
feeds_source
(
$importer_id
,
$node
->
nid
)
->
delete
();
break
;
}
}
}
}
}
/**
/**
*
Handles
FeedsNodeProcessor
specific nodeapi operations
.
* FeedsNodeProcessor
's hook_node_load()
.
*/
*/
function
_feeds_nodeapi_node_processor
(
$node
,
$op
)
{
function
_feeds_node_processor_node_load
(
$node
)
{
switch
(
$op
)
{
if
(
$result
=
db_query
(
"SELECT imported, guid, url, feed_nid FROM
{
feeds_node_item
}
WHERE nid = :nid"
,
array
(
':nid'
=>
$node
->
nid
))
->
fetch
())
{
case
'load'
:
$node
->
feeds_node_item
=
$result
;
if
(
$result
=
db_query
(
"SELECT imported, guid, url, feed_nid FROM
{
feeds_node_item
}
WHERE nid = :nid"
,
array
(
':nid'
=>
$node
->
nid
))
->
fetch
())
{
}
$node
->
feeds_node_item
=
$result
;
}
}
break
;
/**
case
'insert'
:
* FeedsNodeProcessor's hook_node_insert().
if
(
isset
(
$node
->
feeds_node_item
))
{
*/
$node
->
feeds_node_item
->
nid
=
$node
->
nid
;
function
_feeds_node_processor_node_insert
(
$node
)
{
drupal_write_record
(
'feeds_node_item'
,
$node
->
feeds_node_item
);
if
(
isset
(
$node
->
feeds_node_item
))
{
}
$node
->
feeds_node_item
->
nid
=
$node
->
nid
;
break
;
drupal_write_record
(
'feeds_node_item'
,
$node
->
feeds_node_item
);
case
'update'
:
}
if
(
isset
(
$node
->
feeds_node_item
))
{
}
$node
->
feeds_node_item
->
nid
=
$node
->
nid
;
drupal_write_record
(
'feeds_node_item'
,
$node
->
feeds_node_item
,
'nid'
);
/**
}
* FeedsNodeProcessor's hook_node_update().
break
;
*/
case
'delete'
:
function
_feeds_node_processor_node_update
(
$node
)
{
if
(
isset
(
$node
->
feeds_node_item
))
{
if
(
isset
(
$node
->
feeds_node_item
))
{
db_delete
(
'feeds_node_item'
)
$node
->
feeds_node_item
->
nid
=
$node
->
nid
;
->
condition
(
'nid'
,
$node
->
nid
)
drupal_write_record
(
'feeds_node_item'
,
$node
->
feeds_node_item
,
'nid'
);
->
execute
();
}
}
}
break
;
/**
* FeedsNodeProcessor's hook_node_delete().
*/
function
_feeds_node_processor_node_delete
(
$node
)
{
if
(
isset
(
$node
->
feeds_node_item
))
{
db_delete
(
'feeds_node_item'
)
->
condition
(
'nid'
,
$node
->
nid
)
->
execute
();
}
}
}
}
...
...
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