Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
noblogs-wp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
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
ai
noblogs-wp
Commits
0cdccdb1
Commit
0cdccdb1
authored
11 years ago
by
lucha
Committed by
lechuck
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Oembed Provider 2.0.0
parent
569bef3b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
wp-content/plugins/oembed-provider/oembed-provider.php
+163
-89
163 additions, 89 deletions
wp-content/plugins/oembed-provider/oembed-provider.php
wp-content/plugins/oembed-provider/readme.txt
+6
-7
6 additions, 7 deletions
wp-content/plugins/oembed-provider/readme.txt
with
169 additions
and
96 deletions
wp-content/plugins/oembed-provider/oembed-provider.php
+
163
−
89
View file @
0cdccdb1
...
@@ -3,104 +3,178 @@
...
@@ -3,104 +3,178 @@
Plugin Name: oEmbed Provider
Plugin Name: oEmbed Provider
Plugin URI: http://wordpress.org/extend/plugins/oembed-provider/
Plugin URI: http://wordpress.org/extend/plugins/oembed-provider/
Description: An oEmbed provider for Wordpress
Description: An oEmbed provider for Wordpress
Version:
1.1
Version:
2.0.0
Author:
Craig Andrews <candrews@integralblue.com>
Author:
pfefferle, candrews
Author URI: http://
candrews.integralblue.com
Author URI: http
s
://
github.com/pfefferle/oEmbedProvider/
*/
*/
/*
/**
Copyright 2009 Craig Andrews (candrews@integralblue.com)
* oEmbed Provider for WordPress
*
This program is free software; you can redistribute it and/or modify
* @author Matthias Pfefferle
it under the terms of the GNU General Public License as published by
* @author Craig Andrews
the Free Software Foundation; either version 2 of the License, or
*/
(at your option) any later version.
class
OembedProvider
{
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
/**
along with this program; if not, write to the Free Software
* auto discovery links
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
function
add_oembed_links
(){
if
(
is_singular
()){
echo
'<link rel="alternate" type="application/json+oembed" href="'
.
site_url
(
'/?oembed=true&format=json&url='
.
urlencode
(
get_permalink
()))
.
'" />'
.
"
\n
"
;
echo
'<link rel="alternate" type="text/xml+oembed" href="'
.
site_url
(
'/?oembed=true&format=xml&url='
.
urlencode
(
get_permalink
()))
.
'" />'
.
"
\n
"
;
}
}
if
(
function_exists
(
'add_action'
)){
/**
// Running inside of Wordpress
* adds query vars
add_action
(
'wp_head'
,
'add_oembed_links'
);
*/
function
query_vars
(
$query_vars
)
{
$query_vars
[]
=
'oembed'
;
$query_vars
[]
=
'format'
;
$query_vars
[]
=
'url'
;
$query_vars
[]
=
'callback'
;
function
add_oembed_links
(){
return
$query_vars
;
if
(
is_single
()
||
is_page
()
||
is_attachment
()){
print
'<link rel="alternate" type="application/json+oembed" href="'
.
plugins_url
(
'oembed-provider/oembed-provider.php'
)
.
'?format=json&url='
.
urlencode
(
get_permalink
())
.
'" />'
;
print
'<link rel="alternate" type="application/xml+oembed" href="'
.
plugins_url
(
'oembed-provider/oembed-provider.php'
)
.
'?format=xml&url='
.
urlencode
(
get_permalink
())
.
'" />'
;
}
}
/**
* handles request
*/
function
parse_query
(
$wp
)
{
if
(
!
array_key_exists
(
'oembed'
,
$wp
->
query_vars
)
||
!
array_key_exists
(
'url'
,
$wp
->
query_vars
))
{
return
;
}
}
}
else
{
//Directly called (not by Wordpress)
require
(
'../../../wp-load.php'
);
$url
=
$_GET
[
'url'
];
$post_ID
=
url_to_postid
(
$wp
->
query_vars
[
'url'
]);
$post_ID
=
url_to_postid
(
$url
);
$post
=
get_post
(
$post_ID
);
$post
=
get_post
(
$post_ID
);
if
(
empty
(
$post
)){
if
(
!
$post
)
{
header
(
'Status: 404'
);
header
(
'Status: 404'
);
die
(
"Not found"
);
die
(
"Not found"
);
}
else
{
}
$post_type
=
get_post_type
(
$post
);
// add support for alternate output formats
$oembed_provider_formats
=
apply_filters
(
"oembed_provider_formats"
,
array
(
'json'
,
'xml'
));
// check output format
$format
=
"json"
;
if
(
array_key_exists
(
'format'
,
$wp
->
query_vars
)
&&
in_array
(
strtolower
(
$wp
->
query_vars
[
'format'
]),
$oembed_provider_formats
))
{
$format
=
$wp
->
query_vars
[
'format'
];
}
// content filter
$oembed_provider_data
=
apply_filters
(
"oembed_provider_data"
,
array
(),
$post_type
,
$post
);
$oembed_provider_data
=
apply_filters
(
"oembed_provider_data_
{
$post_type
}
"
,
$oembed_provider_data
,
$post
);
do_action
(
"oembed_provider_render"
,
$oembed_provider_data
,
$wp
->
query_vars
);
do_action
(
"oembed_provider_render_
{
$format
}
"
,
$oembed_provider_data
,
$wp
->
query_vars
);
}
/**
* adds default content
*
* @param array $oembed_provider_data
* @param string $post_type
* @param Object $post
*/
function
generate_default_content
(
$oembed_provider_data
,
$post_type
,
$post
)
{
$author
=
get_userdata
(
$post
->
post_author
);
$author
=
get_userdata
(
$post
->
post_author
);
$oembed
=
array
();
$oembed
[
'version'
]
=
'1.0'
;
$oembed_provider_data
[
'version'
]
=
'1.0'
;
$oembed
[
'provider_name'
]
=
get_option
(
'blogname'
);
$oembed_provider_data
[
'provider_name'
]
=
get_bloginfo
(
'name'
);
$oembed
[
'provider_url'
]
=
get_option
(
'home'
);
$oembed_provider_data
[
'provider_url'
]
=
home_url
();
$oembed
[
'author_name'
]
=
$author
->
display_name
;
$oembed_provider_data
[
'author_name'
]
=
$author
->
display_name
;
$oembed
[
'author_url'
]
=
get_author_posts_url
(
$author
->
ID
,
$author
->
nicename
);
$oembed_provider_data
[
'author_url'
]
=
get_author_posts_url
(
$author
->
ID
,
$author
->
nicename
);
$oembed
[
'title'
]
=
$post
->
post_title
;
$oembed_provider_data
[
'title'
]
=
$post
->
post_title
;
switch
(
get_post_type
(
$post
)){
case
'attachment'
:
return
$oembed_provider_data
;
}
/**
* adds attachement specific content
*
* @param array $oembed_provider_data
* @param Object $post
*/
function
generate_attachement_content
(
$oembed_provider_data
,
$post
)
{
if
(
substr
(
$post
->
post_mime_type
,
0
,
strlen
(
'image/'
))
==
'image/'
)
{
if
(
substr
(
$post
->
post_mime_type
,
0
,
strlen
(
'image/'
))
==
'image/'
)
{
$oembed
[
'type'
]
=
'photo'
;
$oembed_provider_data
[
'type'
]
=
'photo'
;
}
else
{
}
else
{
$oembed
[
'type'
]
=
'link'
;
$oembed_provider_data
[
'type'
]
=
'link'
;
}
}
$oembed
[
'url'
]
=
wp_get_attachment_url
(
$post
->
ID
);
$oembed_provider_data
[
'url'
]
=
wp_get_attachment_url
(
$post
->
ID
);
break
;
case
'post'
:
return
$oembed_provider_data
;
case
'page'
:
}
$oembed
[
'type'
]
=
'link'
;
$oembed
[
'html'
]
=
empty
(
$post
->
post_excerpt
)
?
$post
->
post_content
:
$post
->
post_excerpt
;
/**
break
;
* adds post/page specific content
default
:
*
header
(
'Status: 501'
);
* @param array $oembed_provider_data
die
(
'oEmbed not supported for posts of type \''
.
$post
->
type
.
'\''
);
* @param Object $post
break
;
*/
}
function
generate_post_content
(
$oembed_provider_data
,
$post
)
{
if
(
function_exists
(
'has_post_thumbnail'
)
&&
has_post_thumbnail
(
$post
->
ID
))
{
$format
=
$_GET
[
'format'
];
$image
=
wp_get_attachment_image_src
(
get_post_thumbnail_id
(
$post
->
ID
));
switch
(
$format
){
$oembed_provider_data
[
'thumbnail_url'
]
=
$image
[
0
];
case
'json'
:
$oembed_provider_data
[
'thumbnail_width'
]
=
$image
[
1
];
header
(
'Content-Type: application/json; charset='
.
get_option
(
'blog_charset'
),
true
);
$oembed_provider_data
[
'thumbnail_height'
]
=
$image
[
2
];
$callback
=
$_GET
[
'callback'
];
}
if
(
$callback
){
$oembed_provider_data
[
'type'
]
=
'rich'
;
print
$callback
.
'('
;
$oembed_provider_data
[
'html'
]
=
empty
(
$post
->
post_excerpt
)
?
$post
->
post_content
:
$post
->
post_excerpt
;
}
print
(
json_encode
(
$oembed
));
return
$oembed_provider_data
;
if
(
$callback
){
}
print
')'
;
}
/**
break
;
* render json output
case
'xml'
:
*
header
(
'Content-Type: text/xml; charset='
.
get_option
(
'blog_charset'
),
true
);
* @param array $oembed_provider_data
print
'<?xml version="1.0" encoding="'
.
get_option
(
'blog_charset'
)
.
'" standalone="yes"?>'
;
*/
print
'<oembed>'
;
function
render_json
(
$oembed_provider_data
,
$wp_query
)
{
foreach
(
array_keys
(
$oembed
)
as
$element
){
header
(
'Content-Type: application/json; charset='
.
get_bloginfo
(
'charset'
),
true
);
print
'<'
.
$element
.
'><![CDATA['
.
$oembed
[
$element
]
.
']]></'
.
$element
.
'>'
;
}
// render json output
print
'</oembed>'
;
$json
=
json_encode
(
$oembed_provider_data
);
break
;
default
:
// add callback if available
header
(
'Status: 501'
);
if
(
array_key_exists
(
'callback'
,
$wp_query
))
{
die
(
'Format \''
.
$format
.
'\' not supported'
);
$json
=
$wp_query
[
'callback'
]
.
"(
$json
);"
;
}
}
}
}
echo
$json
;
?>
exit
;
}
/**
* render xml output
*
* @param array $oembed_provider_data
*/
function
render_xml
(
$oembed_provider_data
)
{
header
(
'Content-Type: text/xml; charset='
.
get_bloginfo
(
'charset'
),
true
);
// render xml-output
echo
'<?xml version="1.0" encoding="'
.
get_bloginfo
(
'charset'
)
.
'" ?>'
;
echo
'<oembed>'
;
foreach
(
array_keys
(
$oembed_provider_data
)
as
$element
){
echo
'<'
.
$element
.
'>'
.
htmlspecialchars
(
$oembed_provider_data
[
$element
])
.
'</'
.
$element
.
'>'
;
}
echo
'</oembed>'
;
exit
;
}
}
add_action
(
'wp_head'
,
array
(
'OembedProvider'
,
'add_oembed_links'
));
add_action
(
'parse_query'
,
array
(
'OembedProvider'
,
'parse_query'
));
add_filter
(
'query_vars'
,
array
(
'OembedProvider'
,
'query_vars'
));
add_filter
(
'oembed_provider_data'
,
array
(
'OembedProvider'
,
'generate_default_content'
),
90
,
3
);
add_filter
(
'oembed_provider_data_attachement'
,
array
(
'OembedProvider'
,
'generate_attachement_content'
),
91
,
2
);
add_filter
(
'oembed_provider_data_post'
,
array
(
'OembedProvider'
,
'generate_post_content'
),
91
,
2
);
add_filter
(
'oembed_provider_data_page'
,
array
(
'OembedProvider'
,
'generate_post_content'
),
91
,
2
);
add_action
(
'oembed_provider_render_json'
,
array
(
'OembedProvider'
,
'render_json'
),
99
,
2
);
add_action
(
'oembed_provider_render_xml'
,
array
(
'OembedProvider'
,
'render_xml'
),
99
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
wp-content/plugins/oembed-provider/readme.txt
+
6
−
7
View file @
0cdccdb1
=== oEmbed Provider ===
=== oEmbed Provider ===
Contributors: candrews
Contributors: pfefferle, candrews
Donate link: http://candrews.integralblue.com/
Tags: oembed, links
Tags: oembed, links
Requires at least:
2.8
.0
Requires at least:
3
.0
Tested up to:
2.8.2
Tested up to:
3.5.1
Stable tag:
1.1
Stable tag:
2.0.0
An oEmbed provider for Wordpress.
An oEmbed provider for Wordpress.
...
@@ -28,8 +27,8 @@ Yes!
...
@@ -28,8 +27,8 @@ Yes!
== Changelog ==
== Changelog ==
=
1.1
=
=
2.0.0
=
*
Added callback parameter for JSON-P
*
complete refactoring
= 1.0 =
= 1.0 =
* Initial release
* Initial release
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