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
2b2aaeca
Commit
2b2aaeca
authored
15 years ago
by
Alex Barth
Browse files
Options
Downloads
Patches
Plain Diff
#686462: Move FeedsEnclosure class to FeedsParser.inc.
parent
69cee071
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
feeds.plugins.inc
+1
-1
1 addition, 1 deletion
feeds.plugins.inc
plugins/FeedsParser.inc
+61
-0
61 additions, 0 deletions
plugins/FeedsParser.inc
plugins/FeedsSyndicationParser.inc
+0
-61
0 additions, 61 deletions
plugins/FeedsSyndicationParser.inc
with
62 additions
and
62 deletions
feeds.plugins.inc
+
1
−
1
View file @
2b2aaeca
...
...
@@ -113,7 +113,7 @@ function _feeds_feeds_plugins() {
'description'
=>
'Parse RSS and Atom feeds.'
,
'help'
=>
'Use <a href="http://simplepie.org">SimplePie</a> to parse XML feeds in RSS 1, RSS 2 and Atom format.'
,
'handler'
=>
array
(
'parent'
=>
'Feeds
Syndication
Parser'
,
'parent'
=>
'FeedsParser'
,
'class'
=>
'FeedsSimplePieParser'
,
'file'
=>
'FeedsSimplePieParser.inc'
,
'path'
=>
$path
,
...
...
This diff is collapsed.
Click to expand it.
plugins/FeedsParser.inc
+
61
−
0
View file @
2b2aaeca
...
...
@@ -97,6 +97,67 @@ class FeedsElement {
}
}
/**
* Enclosure element, can be part of the result array.
*/
class
FeedsEnclosure
extends
FeedsElement
{
protected
$mime_type
;
protected
$file
;
/**
* Constructor, requires MIME type.
*/
public
function
__construct
(
$value
,
$mime_type
)
{
parent
::
__construct
(
$value
);
$this
->
mime_type
=
$mime_type
;
}
/**
* @return
* MIME type of return value of getValue().
*/
public
function
getMIMEType
()
{
return
$this
->
mime_type
;
}
/**
* @return
* The content of the referenced resource.
*/
public
function
getContent
()
{
feeds_include_library
(
'http_request.inc'
,
'http_request'
);
$result
=
http_request_get
(
$this
->
getValue
());
if
(
$result
->
code
!=
200
)
{
throw
new
Exception
(
t
(
'Download of @url failed with code !code.'
,
array
(
'@url'
=>
$this
->
getValue
(),
'!code'
=>
$result
->
code
)));
}
return
$result
->
data
;
}
/**
* @return
* The file path to the downloaded resource referenced by the enclosure.
* Downloads resource if not downloaded yet.
*
* @todo Get file extension from mime_type.
* @todo This is not concurrency safe.
*/
public
function
getFile
()
{
if
(
!
isset
(
$this
->
file
))
{
$dest
=
file_destination
(
file_directory_temp
()
.
'/'
.
get_class
(
$this
)
.
'-'
.
basename
(
$this
->
getValue
()),
FILE_EXISTS_RENAME
);
if
(
ini_get
(
'allow_url_fopen'
))
{
$this
->
file
=
copy
(
$this
->
getValue
(),
$dest
)
?
$dest
:
0
;
}
else
{
$this
->
file
=
file_save_data
(
$this
->
getContent
(),
$dest
);
}
if
(
$this
->
file
===
0
)
{
throw
new
Exception
(
t
(
'Cannot write content to %dest'
,
array
(
'%dest'
=>
$dest
)));
}
}
return
$this
->
file
;
}
}
/**
* Defines a date element of a parsed result (including ranges, repeat).
*/
...
...
This diff is collapsed.
Click to expand it.
plugins/FeedsSyndicationParser.inc
+
0
−
61
View file @
2b2aaeca
<?php
// $Id$
/**
* Enclosure element, can be part of the result array.
*/
class
FeedsEnclosure
extends
FeedsElement
{
protected
$mime_type
;
protected
$file
;
/**
* Constructor, requires MIME type.
*/
public
function
__construct
(
$value
,
$mime_type
)
{
parent
::
__construct
(
$value
);
$this
->
mime_type
=
$mime_type
;
}
/**
* @return
* MIME type of return value of getValue().
*/
public
function
getMIMEType
()
{
return
$this
->
mime_type
;
}
/**
* @return
* The content of the referenced resource.
*/
public
function
getContent
()
{
feeds_include_library
(
'http_request.inc'
,
'http_request'
);
$result
=
http_request_get
(
$this
->
getValue
());
if
(
$result
->
code
!=
200
)
{
throw
new
Exception
(
t
(
'Download of @url failed with code !code.'
,
array
(
'@url'
=>
$this
->
getValue
(),
'!code'
=>
$result
->
code
)));
}
return
$result
->
data
;
}
/**
* @return
* The file path to the downloaded resource referenced by the enclosure.
* Downloads resource if not downloaded yet.
*
* @todo Get file extension from mime_type.
* @todo This is not concurrency safe.
*/
public
function
getFile
()
{
if
(
!
isset
(
$this
->
file
))
{
$dest
=
file_destination
(
file_directory_temp
()
.
'/'
.
get_class
(
$this
)
.
'-'
.
basename
(
$this
->
getValue
()),
FILE_EXISTS_RENAME
);
if
(
ini_get
(
'allow_url_fopen'
))
{
$this
->
file
=
copy
(
$this
->
getValue
(),
$dest
)
?
$dest
:
0
;
}
else
{
$this
->
file
=
file_save_data
(
$this
->
getContent
(),
$dest
);
}
if
(
$this
->
file
===
0
)
{
throw
new
Exception
(
t
(
'Cannot write content to %dest'
,
array
(
'%dest'
=>
$dest
)));
}
}
return
$this
->
file
;
}
}
/**
* Class definition for Common Syndication Parser.
*
...
...
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