first import
This commit is contained in:
47
sites/all/modules/media_youtube/CHANGELOG.txt
Normal file
47
sites/all/modules/media_youtube/CHANGELOG.txt
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
Changelog for the Media: YouTube module.
|
||||
========================================
|
||||
|
||||
by aaron: Add overlay to media browser library thumbnails.
|
||||
by aaron: Begin framework for pager support.
|
||||
by aaron: Add an empty message.
|
||||
by aaron: Remove old tab from browser.
|
||||
by aaron: Begin work on adding 'All/My Youtubes' vertical tabs.
|
||||
by aaron: Add 'YouTube Library' tab to browser w/ all youtube videos.
|
||||
by aaron: Allow parsing of url's like youtube.com/watch#v=...
|
||||
by aaron: Fix incorrect parse to youtube from flickr.
|
||||
by aaron: Implement hook_media_parse().
|
||||
by aaron: Remove link behavior for the moment.
|
||||
by aaron: Change tab behavior to new required format.
|
||||
by aaron: Allow w/h overrides.
|
||||
by aaron: Add wysiwyg tab for youtube url.
|
||||
by aaron: Add style presets for youtube.
|
||||
by aaron: Add action link to add youtube video from media content admin.
|
||||
by aaron: Add alt/title to embed thumbnails theme.
|
||||
by aaron: Refactor styles containers to match new API.
|
||||
by aaron: Add preview on parsing new youtube.
|
||||
by aaron: Add media_youtube.js.
|
||||
by aaron: Add a weight to style containers.
|
||||
by aaron: Add JS behavior to url text field.
|
||||
by aaron: Browse user + all youtube videos.
|
||||
by aaron: New themes for styles.
|
||||
by aaron: Begin browser forms for YouTube.
|
||||
by aaron: Embed themes & style callbacks.
|
||||
by aaron: Define filter callbacks.
|
||||
by aaron: Fix return value for hook_styles_presets().
|
||||
by aaron: Implement hook_styles_presets().
|
||||
by aaron: Add variables to preview theme.
|
||||
by aaron: Integrate with Styles.
|
||||
by aaron: Add preview theme.
|
||||
by aaron: Add test default media styles.
|
||||
by aaron: Parse URL correctly.
|
||||
by aaron: Register the stream wrapper.
|
||||
by aaron: Include stream wrapper w/ module load.
|
||||
by aaron: Rename stream wrapper implementation to MediaYouTubeStreamWrapper.
|
||||
by aaron: Upgrade module to DRUPAL-7.
|
||||
|
||||
=============
|
||||
DRUPAL-7--1
|
||||
=============
|
||||
|
||||
by aaron: Create ResourceYouTubeStreamWrapper.inc.
|
339
sites/all/modules/media_youtube/LICENSE.txt
Normal file
339
sites/all/modules/media_youtube/LICENSE.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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 Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @todo Remove once usage statistics indicate that virtually everyone has
|
||||
* updated to 1.0-alpha5 or later. This is retained until then, so that
|
||||
* update.php can bootstrap.
|
||||
*/
|
||||
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_youtube') . '/includes/includes/MediaYouTubeStreamWrapper.inc';
|
5
sites/all/modules/media_youtube/README.txt
Normal file
5
sites/all/modules/media_youtube/README.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
Media: YouTube
|
||||
|
||||
Creates a YouTube PHP Stream Wrapper for Resource and implements the various
|
||||
formatter and file listing hooks in the Media module.
|
21
sites/all/modules/media_youtube/css/media_youtube.css
Normal file
21
sites/all/modules/media_youtube/css/media_youtube.css
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
.media-youtube-preview-wrapper {
|
||||
max-width: 100%;
|
||||
min-height: 50px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.media-youtube-preview-wrapper object,
|
||||
.media-youtube-preview-wrapper iframe {
|
||||
max-width: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.media-youtube-preview-wrapper .js-fallback {
|
||||
left: 0;
|
||||
margin-top: -0.5em;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
text-align: center;
|
||||
top: 50%;
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Overlay for YouTube thumbnails in the media library browser.
|
||||
*/
|
||||
#media-browser .styles-container-media_youtube {
|
||||
/* Relative wrapper for the overlay. */
|
||||
position: relative;
|
||||
}
|
||||
#media-browser .styles-container-media_youtube span {
|
||||
/* Here's the overlay image. */
|
||||
background: url(images/stream-youtube.png) no-repeat;
|
||||
|
||||
/* Absolute positioning in the relative wrapper creates the overlay. */
|
||||
position: absolute;
|
||||
|
||||
/* Size of the overlay */
|
||||
width: 69px;
|
||||
height: 22px;
|
||||
|
||||
/* Position of the overlay */
|
||||
left: 33px;
|
||||
top: 80px;
|
||||
}
|
||||
#media-browser .styles-container-media_youtube span:hover {
|
||||
/* The */
|
||||
background-position: 0px -22px;
|
||||
}
|
||||
#media-browser .styles-container-media_youtube img {
|
||||
}
|
BIN
sites/all/modules/media_youtube/images/stream-youtube.png
Normal file
BIN
sites/all/modules/media_youtube/images/stream-youtube.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of MediaInternetBaseHandler.
|
||||
*
|
||||
* @see hook_media_internet_providers().
|
||||
*/
|
||||
class MediaInternetYouTubeHandler extends MediaInternetBaseHandler {
|
||||
public function parse($embedCode) {
|
||||
$patterns = array(
|
||||
'@youtube\.com/watch[#\?].*?v=([^"\& ]+)@i',
|
||||
'@youtube\.com/embed/([^"\&\? ]+)@i',
|
||||
'@youtube\.com/v/([^"\&\? ]+)@i',
|
||||
'@youtube\.com/\?v=([^"\& ]+)@i',
|
||||
'@youtu.be/([^"\&\? ]+)@i',
|
||||
);
|
||||
foreach ($patterns as $pattern) {
|
||||
preg_match($pattern, $embedCode, $matches);
|
||||
if (isset($matches[1]) && $this->valid_id($matches[1])) {
|
||||
return file_stream_wrapper_uri_normalize('youtube://v/' . $matches[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function valid_id($id) {
|
||||
$url = 'http://gdata.youtube.com/feeds/api/videos/'. $id;
|
||||
$response = drupal_http_request($url, array('method' => 'HEAD'));
|
||||
if ($response->code != 200) {
|
||||
throw new MediaInternetValidationException(t('The YouTube video ID is invalid or the video was deleted.'));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function claim($embedCode) {
|
||||
if ($this->parse($embedCode)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
public function getFileObject() {
|
||||
$uri = $this->parse($this->embedCode);
|
||||
$file = file_uri_to_object($uri, TRUE);
|
||||
|
||||
if (empty($file->fid) && $info = $this->getOEmbed()) {
|
||||
$file->filename = truncate_utf8($info['title'], 255);
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about the media. See http://video.search.yahoo.com/mrss.
|
||||
*
|
||||
* @return
|
||||
* If ATOM+MRSS information is available, a SimpleXML element containing
|
||||
* ATOM and MRSS elements, as per those respective specifications.
|
||||
*
|
||||
* @todo Would be better for the return value to be an array rather than a
|
||||
* SimpleXML element, but media_retrieve_xml() needs to be upgraded to
|
||||
* handle namespaces first.
|
||||
*/
|
||||
public function getMRSS() {
|
||||
$uri = $this->parse($this->embedCode);
|
||||
$video_id = arg(1, file_uri_target($uri));
|
||||
$rss_url = url('http://gdata.youtube.com/feeds/api/videos/' . $video_id, array('query' => array('v' => '2')));
|
||||
// @todo Use media_retrieve_xml() once it's upgraded to include elements
|
||||
// from all namespaces, not just the document default namespace.
|
||||
$entry = simplexml_load_file($rss_url);
|
||||
return $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about the media. See http://www.oembed.com/.
|
||||
*
|
||||
* @return
|
||||
* If oEmbed information is available, an array containing 'title', 'type',
|
||||
* 'url', and other information as specified by the oEmbed standard.
|
||||
* Otherwise, NULL.
|
||||
*/
|
||||
public function getOEmbed() {
|
||||
$uri = $this->parse($this->embedCode);
|
||||
$external_url = drupal_realpath($uri);
|
||||
$oembed_url = url('http://www.youtube.com/oembed', array('query' => array('url' => $external_url, 'format' => 'json')));
|
||||
$response = drupal_http_request($oembed_url);
|
||||
if (!isset($response->error)) {
|
||||
return drupal_json_decode($response->data);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Create a YouTube Stream Wrapper class for the Media/Resource module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create an instance like this:
|
||||
* $youtube = new ResourceYouTubeStreamWrapper('youtube://?v=[video-code]');
|
||||
*/
|
||||
class MediaYouTubeStreamWrapper extends MediaReadOnlyStreamWrapper {
|
||||
protected $base_url = 'http://youtube.com/watch';
|
||||
|
||||
function getTarget($f) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static function getMimeType($uri, $mapping = NULL) {
|
||||
return 'video/youtube';
|
||||
}
|
||||
|
||||
function getOriginalThumbnailPath() {
|
||||
$parts = $this->get_parameters();
|
||||
return 'http://img.youtube.com/vi/'. check_plain($parts['v']) .'/0.jpg';
|
||||
}
|
||||
|
||||
function getLocalThumbnailPath() {
|
||||
$parts = $this->get_parameters();
|
||||
$local_path = 'public://media-youtube/' . check_plain($parts['v']) . '.jpg';
|
||||
if (!file_exists($local_path)) {
|
||||
$dirname = drupal_dirname($local_path);
|
||||
file_prepare_directory($dirname, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
|
||||
@copy($this->getOriginalThumbnailPath(), $local_path);
|
||||
}
|
||||
return $local_path;
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Styles class implementation for Media: YouTube.
|
||||
*/
|
||||
|
||||
class MediaYouTubeStyles extends FileStyles {
|
||||
public $autoplay;
|
||||
public $fullscreen;
|
||||
|
||||
function getAutoplay() {
|
||||
return $this->get('autoplay');
|
||||
}
|
||||
function setAutoplay($value) {
|
||||
return $this->set('autoplay', $value);
|
||||
}
|
||||
function getFullscreen() {
|
||||
return $this->get('fullscreen');
|
||||
}
|
||||
function setFullscreen($value) {
|
||||
return $this->set('fullscreen', $value);
|
||||
}
|
||||
|
||||
function getImageUri() {
|
||||
if ($image_uri = $this->get('imageUri')) {
|
||||
return $image_uri;
|
||||
}
|
||||
$object = $this->getObject();
|
||||
if ($object->uri) {
|
||||
$wrapper = file_stream_wrapper_get_instance_by_uri($object->uri);
|
||||
return $wrapper->getLocalThumbnailPath();
|
||||
}
|
||||
}
|
||||
function video($effect) {
|
||||
$variables = array(
|
||||
'uri' => $this->getUri(),
|
||||
'width' => $this->getWidth(),
|
||||
'height' => $this->getHeight(),
|
||||
'autoplay' => $this->getAutoplay(),
|
||||
'fullscreen' => $this->getFullscreen(),
|
||||
);
|
||||
$this->setOutput(theme('media_youtube_video', $variables));
|
||||
}
|
||||
}
|
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_file_formatter_info().
|
||||
*/
|
||||
function media_youtube_file_formatter_info() {
|
||||
$formatters['media_youtube_video'] = array(
|
||||
'label' => t('YouTube Video'),
|
||||
'file types' => array('video'),
|
||||
'default settings' => array(),
|
||||
'view callback' => 'media_youtube_file_formatter_video_view',
|
||||
'settings callback' => 'media_youtube_file_formatter_video_settings',
|
||||
);
|
||||
foreach (array('width', 'height', 'autoplay', 'related', 'hd', 'showsearch', 'modestbranding', 'showinfo', 'version', 'theme', 'fullscreen', 'wmode', 'chromeless') as $setting) {
|
||||
$formatters['media_youtube_video']['default settings'][$setting] = media_youtube_variable_get($setting);
|
||||
}
|
||||
$formatters['media_youtube_image'] = array(
|
||||
'label' => t('YouTube Preview Image'),
|
||||
'file types' => array('video'),
|
||||
'default settings' => array(
|
||||
'image_style' => '',
|
||||
),
|
||||
'view callback' => 'media_youtube_file_formatter_image_view',
|
||||
'settings callback' => 'media_youtube_file_formatter_image_settings',
|
||||
);
|
||||
return $formatters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_file_formatter_FORMATTER_view().
|
||||
*/
|
||||
function media_youtube_file_formatter_video_view($file, $display, $langcode) {
|
||||
$scheme = file_uri_scheme($file->uri);
|
||||
// WYSIWYG does not yet support video inside a running editor instance.
|
||||
if ($scheme == 'youtube' && empty($file->override['wysiwyg'])) {
|
||||
$element = array(
|
||||
'#theme' => 'media_youtube_video',
|
||||
'#uri' => $file->uri,
|
||||
'#options' => array(),
|
||||
);
|
||||
foreach (array('width', 'height', 'autoplay', 'related', 'hd', 'showsearch', 'modestbranding', 'showinfo', 'version', 'theme', 'fullscreen', 'wmode', 'chromeless') as $setting) {
|
||||
$element['#options'][$setting] = isset($file->override[$setting]) ? $file->override[$setting] : $display['settings'][$setting];
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_file_formatter_FORMATTER_settings().
|
||||
*/
|
||||
function media_youtube_file_formatter_video_settings($form, &$form_state, $settings) {
|
||||
$element = array();
|
||||
$options = array(
|
||||
0 => t('AS2'),
|
||||
3 => t('AS3'),
|
||||
);
|
||||
$element['version'] = array(
|
||||
'#title' => t('YouTube player version'),
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#default_value' => $settings['version'],
|
||||
);
|
||||
$options = array(
|
||||
'dark' => t('dark'),
|
||||
'light' => t('light'),
|
||||
);
|
||||
$element['theme'] = array(
|
||||
'#title' => t('YouTube player theme'),
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#default_value' => $settings['theme'],
|
||||
);
|
||||
|
||||
$element['width'] = array(
|
||||
'#title' => t('Width'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $settings['width'],
|
||||
);
|
||||
$element['height'] = array(
|
||||
'#title' => t('Height'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $settings['height'],
|
||||
);
|
||||
$element['fullscreen'] = array(
|
||||
'#title' => t('Allow the video to be played in full screen mode'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['fullscreen'],
|
||||
);
|
||||
$element['autoplay'] = array(
|
||||
'#title' => t('Autoplay'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['autoplay'],
|
||||
);
|
||||
$element['related'] = array(
|
||||
'#title' => t('Show suggested videos when the video finishes'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['related'],
|
||||
);
|
||||
$element['hd'] = array(
|
||||
'#title' => t('Display the high quality version of the video when available'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['hd'],
|
||||
);
|
||||
$element['showsearch'] = array(
|
||||
'#title' => t('Allow users to search from the video'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['showsearch'],
|
||||
);
|
||||
$element['modestbranding'] = array(
|
||||
'#title' => t('Use modest YouTube branding (requires AS3 version player)'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['modestbranding'],
|
||||
);
|
||||
$element['showinfo'] = array(
|
||||
'#title' => t('Display video title'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['showinfo'],
|
||||
);
|
||||
$element['chromeless'] = array(
|
||||
'#title' => t('Use chromeless player'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['chromeless'],
|
||||
);
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_file_formatter_FORMATTER_view().
|
||||
*/
|
||||
function media_youtube_file_formatter_image_view($file, $display, $langcode) {
|
||||
$scheme = file_uri_scheme($file->uri);
|
||||
if ($scheme == 'youtube') {
|
||||
$wrapper = file_stream_wrapper_get_instance_by_uri($file->uri);
|
||||
$image_style = $display['settings']['image_style'];
|
||||
$valid_image_styles = image_style_options(FALSE);
|
||||
if (empty($image_style) || !isset($valid_image_styles[$image_style])) {
|
||||
$element = array(
|
||||
'#theme' => 'image',
|
||||
'#path' => $wrapper->getOriginalThumbnailPath(),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$element = array(
|
||||
'#theme' => 'image_style',
|
||||
'#style_name' => $image_style,
|
||||
'#path' => $wrapper->getLocalThumbnailPath(),
|
||||
);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_file_formatter_FORMATTER_settings().
|
||||
*/
|
||||
function media_youtube_file_formatter_image_settings($form, &$form_state, $settings) {
|
||||
$element = array();
|
||||
$element['image_style'] = array(
|
||||
'#title' => t('Image style'),
|
||||
'#type' => 'select',
|
||||
'#options' => image_style_options(FALSE),
|
||||
'#default_value' => $settings['image_style'],
|
||||
'#empty_option' => t('None (original image)'),
|
||||
);
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_file_default_displays().
|
||||
*/
|
||||
function media_youtube_file_default_displays() {
|
||||
$default_displays = array();
|
||||
|
||||
// Default settings for displaying as a video.
|
||||
$default_video_settings = array(
|
||||
'media_large' => array(
|
||||
'width' => 480,
|
||||
'height' => 360,
|
||||
'autoplay' => FALSE,
|
||||
),
|
||||
'media_original' => array(
|
||||
'width' => 640,
|
||||
'height' => 480,
|
||||
'autoplay' => media_youtube_variable_get('autoplay'),
|
||||
),
|
||||
);
|
||||
foreach ($default_video_settings as $view_mode => $settings) {
|
||||
$display_name = 'video__' . $view_mode . '__media_youtube_video';
|
||||
$default_displays[$display_name] = (object) array(
|
||||
'api_version' => 1,
|
||||
'name' => $display_name,
|
||||
'status' => 1,
|
||||
'weight' => 1,
|
||||
'settings' => $settings,
|
||||
);
|
||||
}
|
||||
|
||||
// Default settings for displaying a video preview image. We enable preview
|
||||
// images even for view modes that also play video, for use inside a running
|
||||
// WYSIWYG editor. The higher weight ensures that the video display is used
|
||||
// where possible.
|
||||
$default_image_styles = array(
|
||||
'media_preview' => 'square_thumbnail',
|
||||
'media_large' => 'large',
|
||||
'media_original' => ''
|
||||
);
|
||||
foreach ($default_image_styles as $view_mode => $image_style) {
|
||||
$display_name = 'video__' . $view_mode . '__media_youtube_image';
|
||||
$default_displays[$display_name] = (object) array(
|
||||
'api_version' => 1,
|
||||
'name' => $display_name,
|
||||
'status' => 1,
|
||||
'weight' => 2,
|
||||
'settings' => array('image_style' => $image_style),
|
||||
);
|
||||
}
|
||||
|
||||
return $default_displays;
|
||||
}
|
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file media_youtube/includes/media_youtube.styles.inc
|
||||
* Styles definitions for Media: YouTube.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of Styles module hook_styles_register().
|
||||
*/
|
||||
function media_youtube_styles_register() {
|
||||
return array(
|
||||
'MediaYouTubeStyles' => array(
|
||||
'field_types' => 'file',
|
||||
'name' => t('MediaYouTube'),
|
||||
'description' => t('Media YouTube styles.'),
|
||||
'path' => drupal_get_path('module', 'media_youtube') .'/includes',
|
||||
'file' => 'media_youtube.styles.inc',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_styles_containers(). (Deprecated in version 2)
|
||||
*/
|
||||
function media_youtube_styles_containers() {
|
||||
return array(
|
||||
'file' => array(
|
||||
'containers' => array(
|
||||
'media_youtube' => array(
|
||||
'label' => t('YouTube Styles'),
|
||||
'data' => array(
|
||||
'streams' => array(
|
||||
'youtube',
|
||||
),
|
||||
'mimetypes' => array(
|
||||
'video/youtube',
|
||||
),
|
||||
),
|
||||
'weight' => 0,
|
||||
'filter callback' => 'media_youtube_formatter_filter',
|
||||
'themes' => array(
|
||||
'field_formatter_styles' => 'media_youtube_field_formatter_styles',
|
||||
'styles' => 'media_youtube_styles',
|
||||
'preview' => 'media_youtube_preview_style',
|
||||
),
|
||||
'description' => t('YouTube Styles will display embedded YouTube videos and thumbnails to your choosing, such as by resizing, setting colors, and autoplay. You can !manage.', array('!manage' => l(t('manage your YouTube styles here'), 'admin/config/media/media-youtube-styles'))),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function media_youtube_formatter_filter($variables) {
|
||||
if (isset($variables['object'])) {
|
||||
$object = isset($variables['object']->file) ? $variables['object']->file : $variables['object'];
|
||||
return (file_uri_scheme($object->uri) == 'youtube') && ($object->filemime == 'video/youtube');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of the File Styles module's hook_file_styles_filter().
|
||||
*/
|
||||
function media_youtube_file_styles_filter($object) {
|
||||
$file = isset($object->file) ? $object->file : $object;
|
||||
if ((file_uri_scheme($file->uri) == 'youtube') && ($file->filemime == 'video/youtube')) {
|
||||
return 'media_youtube';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_styles_styles().
|
||||
*/
|
||||
function media_youtube_styles_styles() {
|
||||
$styles = array(
|
||||
'file' => array(
|
||||
'containers' => array(
|
||||
'media_youtube' => array(
|
||||
'styles' => array(
|
||||
'youtube_thumbnail' => array(
|
||||
'name' => 'youtube_thumbnail',
|
||||
'effects' => array(
|
||||
array('label' => t('Thumbnail'), 'name' => 'thumbnail', 'data' => array('thumbnail' => 1)),
|
||||
array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 100, 'height' => 75)),
|
||||
),
|
||||
),
|
||||
'youtube_preview' => array(
|
||||
'name' => 'youtube_preview',
|
||||
'effects' => array(
|
||||
array('label' => t('Autoplay'), 'name' => 'autoplay', 'data' => array('autoplay' => 0)),
|
||||
array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 220, 'height' => 165)),
|
||||
),
|
||||
),
|
||||
'youtube_full' => array(
|
||||
'name' => 'youtube_full',
|
||||
'effects' => array(
|
||||
array('label' => t('Autoplay'), 'name' => 'autoplay', 'data' => array('autoplay' => 0)),
|
||||
array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 640, 'height' => 480)),
|
||||
array('label' => t('Full screen'), 'name' => 'fullscreen', 'data' => array('fullscreen' => 1)),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Allow any image style to be applied to the thumbnail.
|
||||
foreach (image_styles() as $style_name => $image_style) {
|
||||
$styles['file']['containers']['media_youtube']['styles']['youtube_thumbnail_' . $style_name] = array(
|
||||
'name' => 'youtube_thumbnail_' . $style_name,
|
||||
'image_style' => $style_name,
|
||||
'effects' => array(
|
||||
array('label' => t('Thumbnail'), 'name' => 'thumbnail', 'data' => array('thumbnail' => 1)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return $styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_styles_presets().
|
||||
*/
|
||||
function media_youtube_styles_presets() {
|
||||
$presets = array(
|
||||
'file' => array(
|
||||
'square_thumbnail' => array(
|
||||
'media_youtube' => array(
|
||||
'youtube_thumbnail_square_thumbnail',
|
||||
),
|
||||
),
|
||||
'thumbnail' => array(
|
||||
'media_youtube' => array(
|
||||
'youtube_thumbnail',
|
||||
),
|
||||
),
|
||||
'small' => array(
|
||||
'media_youtube' => array(
|
||||
'youtube_preview',
|
||||
),
|
||||
),
|
||||
'large' => array(
|
||||
'media_youtube' => array(
|
||||
'youtube_full',
|
||||
),
|
||||
),
|
||||
'original' => array(
|
||||
'media_youtube' => array(
|
||||
'youtube_full',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return $presets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of Styles module hook_styles_default_containers().
|
||||
*/
|
||||
function media_youtube_styles_default_containers() {
|
||||
// We append YouTube to the file containers.
|
||||
return array(
|
||||
'file' => array(
|
||||
'containers' => array(
|
||||
'media_youtube' => array(
|
||||
'class' => 'MediaYouTubeStyles',
|
||||
'name' => 'media_youtube',
|
||||
'label' => t('YouTube'),
|
||||
'preview' => 'media_youtube_preview_style',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of Styles module hook_styles_default_presets().
|
||||
*/
|
||||
function media_youtube_styles_default_presets() {
|
||||
$presets = array(
|
||||
'file' => array(
|
||||
'containers' => array(
|
||||
'media_youtube' => array(
|
||||
'default preset' => 'unlinked_thumbnail',
|
||||
'styles' => array(
|
||||
'original' => array(
|
||||
'default preset' => 'video',
|
||||
),
|
||||
'thumbnail' => array(
|
||||
'default preset' => 'linked_thumbnail',
|
||||
),
|
||||
'square_thumbnail' => array(
|
||||
'default preset' => 'linked_square_thumbnail',
|
||||
),
|
||||
'medium' => array(
|
||||
'default preset' => 'linked_medium',
|
||||
),
|
||||
'large' => array(
|
||||
'default preset' => 'large_video',
|
||||
),
|
||||
),
|
||||
'presets' => array(
|
||||
'video' => array(
|
||||
array(
|
||||
'name' => 'video',
|
||||
'settings' => array(),
|
||||
),
|
||||
),
|
||||
'large_video' => array(
|
||||
array(
|
||||
'name' => 'resize',
|
||||
'settings' => array(
|
||||
'width' => 640,
|
||||
'height' => 390,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'video',
|
||||
'settings' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
// Allow any image style to be applied to the thumbnail.
|
||||
foreach (image_styles() as $style_name => $image_style) {
|
||||
$presets['file']['containers']['media_youtube']['presets']['linked_' . $style_name] = array(
|
||||
array(
|
||||
'name' => 'linkToMedia',
|
||||
'settings' => array(),
|
||||
),
|
||||
array(
|
||||
'name' => 'imageStyle',
|
||||
'settings' => array(
|
||||
'image_style' => $style_name,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'thumbnail',
|
||||
'settings' => array(),
|
||||
),
|
||||
);
|
||||
$presets['file']['containers']['media_youtube']['presets']['unlinked_' . $style_name] = $presets['file']['containers']['media_youtube']['presets']['linked_' . $style_name];
|
||||
array_shift($presets['file']['containers']['media_youtube']['presets']['unlinked_' . $style_name]);
|
||||
foreach ($image_style['effects'] as $effect) {
|
||||
if (in_array($effect['name'], array('image_scale', 'image_scale_and_crop', 'image_resize', 'image_crop'))) {
|
||||
$presets['file']['containers']['media_youtube']['presets']['video_' . $style_name] = array(
|
||||
array(
|
||||
'name' => 'resize',
|
||||
'settings' => $effect['data'],
|
||||
),
|
||||
array(
|
||||
'name' => 'video',
|
||||
'settings' => array(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $presets;
|
||||
}
|
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file media_youtube/includes/media_youtube.variables.inc
|
||||
* Variable defaults for Media: YouTube.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define our constants.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is the variable namespace, automatically prepended to module variables.
|
||||
*/
|
||||
define('MEDIA_YOUTUBE_NAMESPACE', 'media_youtube__');
|
||||
|
||||
/**
|
||||
* Wrapper for variable_get() using the Media: YouTube variable registry.
|
||||
*
|
||||
* @param string $name
|
||||
* The variable name to retrieve. Note that it will be namespaced by
|
||||
* pre-pending MEDIA_YOUTUBE_NAMESPACE, as to avoid variable collisions
|
||||
* with other modules.
|
||||
* @param unknown $default
|
||||
* An optional default variable to return if the variable hasn't been set
|
||||
* yet. Note that within this module, all variables should already be set
|
||||
* in the media_youtube_variable_default() function.
|
||||
* @return unknown
|
||||
* Returns the stored variable or its default.
|
||||
*
|
||||
* @see media_youtube_variable_set()
|
||||
* @see media_youtube_variable_del()
|
||||
* @see media_youtube_variable_default()
|
||||
*/
|
||||
function media_youtube_variable_get($name, $default = NULL) {
|
||||
// Allow for an override of the default.
|
||||
// Useful when a variable is required (like $path), but namespacing is still
|
||||
// desired.
|
||||
if (!isset($default)) {
|
||||
$default = media_youtube_variable_default($name);
|
||||
}
|
||||
// Namespace all variables.
|
||||
$variable_name = MEDIA_YOUTUBE_NAMESPACE . $name;
|
||||
return variable_get($variable_name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for variable_set() using the Media: YouTube variable registry.
|
||||
*
|
||||
* @param string $name
|
||||
* The variable name to set. Note that it will be namespaced by
|
||||
* pre-pending MEDIA_YOUTUBE_NAMESPACE, as to avoid variable collisions with
|
||||
* other modules.
|
||||
* @param unknown $value
|
||||
* The value for which to set the variable.
|
||||
* @return unknown
|
||||
* Returns the stored variable after setting.
|
||||
*
|
||||
* @see media_youtube_variable_get()
|
||||
* @see media_youtube_variable_del()
|
||||
* @see media_youtube_variable_default()
|
||||
*/
|
||||
function media_youtube_variable_set($name, $value) {
|
||||
$variable_name = MEDIA_YOUTUBE_NAMESPACE . $name;
|
||||
return variable_set($variable_name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for variable_del() using the Media: YouTube variable registry.
|
||||
*
|
||||
* @param string $name
|
||||
* The variable name to delete. Note that it will be namespaced by
|
||||
* pre-pending MEDIA_YOUTUBE_NAMESPACE, as to avoid variable collisions with
|
||||
* other modules.
|
||||
*
|
||||
* @see media_youtube_variable_get()
|
||||
* @see media_youtube_variable_set()
|
||||
* @see media_youtube_variable_default()
|
||||
*/
|
||||
function media_youtube_variable_del($name) {
|
||||
$variable_name = MEDIA_YOUTUBE_NAMESPACE . $name;
|
||||
variable_del($variable_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* The default variables within the Media: YouTube namespace.
|
||||
*
|
||||
* @param string $name
|
||||
* Optional variable name to retrieve the default. Note that it has not yet
|
||||
* been pre-pended with the MEDIA_YOUTUBE_NAMESPACE namespace at this time.
|
||||
* @return unknown
|
||||
* The default value of this variable, if it's been set, or NULL, unless
|
||||
* $name is NULL, in which case we return an array of all default values.
|
||||
*
|
||||
* @see media_youtube_variable_get()
|
||||
* @see media_youtube_variable_set()
|
||||
* @see media_youtube_variable_del()
|
||||
*/
|
||||
function media_youtube_variable_default($name = NULL) {
|
||||
static $defaults;
|
||||
|
||||
if (!isset($defaults)) {
|
||||
$defaults = array(
|
||||
'width' => 560,
|
||||
'height' =>340,
|
||||
'autoplay' => FALSE,
|
||||
'related' => TRUE,
|
||||
'hd' => FALSE,
|
||||
'showsearch' => TRUE,
|
||||
'modestbranding' => FALSE,
|
||||
'showinfo'=> TRUE,
|
||||
'version' => 3,
|
||||
'theme' => 'dark',
|
||||
'fullscreen' => TRUE,
|
||||
'wmode' => 'transparent',
|
||||
'chromeless' => FALSE,
|
||||
'preview_uri' => 'youtube://v/-jubiv7QUco',
|
||||
);
|
||||
}
|
||||
|
||||
if (!isset($name)) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
if (isset($defaults[$name])) {
|
||||
return $defaults[$name];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the fully namespace variable name.
|
||||
*
|
||||
* @param string $name
|
||||
* The variable name to retrieve the namespaced name.
|
||||
* @return string
|
||||
* The fully namespace variable name, prepended with
|
||||
* MEDIA_YOUTUBE_NAMESPACE.
|
||||
*/
|
||||
function media_youtube_variable_name($name) {
|
||||
return MEDIA_YOUTUBE_NAMESPACE . $name;
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file media_youtube/includes/themes/media-youtube-video.tpl.php
|
||||
*
|
||||
* Template file for theme('media_youtube_video').
|
||||
*
|
||||
* Variables available:
|
||||
* $uri - The uri to the YouTube video, such as youtube://v/xsy7x8c9.
|
||||
* $video_id - The unique identifier of the YouTube video.
|
||||
* $width - The width to render.
|
||||
* $height - The height to render.
|
||||
* $autoplay - If TRUE, then start the player automatically when displaying.
|
||||
* $fullscreen - Whether to allow fullscreen playback.
|
||||
*
|
||||
* Note that we set the width & height of the outer wrapper manually so that
|
||||
* the JS will respect that when resizing later.
|
||||
*/
|
||||
?>
|
||||
<div class="media-youtube-outer-wrapper" id="media-youtube-<?php print $id; ?>" style="width: <?php print $width; ?>px; height: <?php print $height; ?>px;">
|
||||
<div class="media-youtube-preview-wrapper" id="<?php print $wrapper_id; ?>">
|
||||
<?php print $output; ?>
|
||||
</div>
|
||||
</div>
|
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file media_youtube/includes/themes/media_youtube.theme.inc
|
||||
*
|
||||
* Theme and preprocess functions for Media: YouTube.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Preprocess function for theme('media_youtube_video').
|
||||
*/
|
||||
function media_youtube_preprocess_media_youtube_video(&$variables) {
|
||||
// Build the URL for display.
|
||||
$uri = $variables['uri'];
|
||||
$wrapper = file_stream_wrapper_get_instance_by_uri($uri);
|
||||
$parts = $wrapper->get_parameters();
|
||||
$variables['video_id'] = check_plain($parts['v']);
|
||||
$variables['query'] = array();
|
||||
|
||||
// @see http://code.google.com/apis/youtube/player_parameters.html
|
||||
foreach (array('width', 'height', 'autoplay', 'related', 'hd', 'showsearch', 'modestbranding', 'showinfo', 'version', 'theme', 'fullscreen', 'wmode', 'chromeless') as $option) {
|
||||
// Set the option, either from the options array, or from the default value.
|
||||
$variables[$option] = isset($variables[$option]) ? $variables[$option] : (isset($variables['options'][$option]) ? $variables['options'][$option] : media_youtube_variable_get($option));
|
||||
}
|
||||
|
||||
// We have to set fullscreen in the url query and as a parameter to the flash.
|
||||
$variables['fs'] = $variables['fullscreen'];
|
||||
$variables['fullscreen'] = $variables['fullscreen'] ? 'true' : 'false';
|
||||
|
||||
$variables['wrapper_id'] = 'media_youtube_' . $variables['video_id'] . '_' . $variables['id'];
|
||||
|
||||
// Pass the settings to replace the object tag with an iframe.
|
||||
$settings = array(
|
||||
'media_youtube' => array(
|
||||
$variables['wrapper_id'] => array(
|
||||
'width' => $variables['width'],
|
||||
'height' => $variables['height'],
|
||||
'video_id' => $variables['video_id'],
|
||||
'fullscreen' => $variables['fullscreen'],
|
||||
'id' => $variables['wrapper_id'] .'_iframe',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Set the version of the youtube api player.
|
||||
if ($variables['version']) {
|
||||
$variables['query']['version'] = $variables['version'];
|
||||
// Note that the fs variable defaults to 1 with the AS3 player.
|
||||
if (!$variables['fs']) {
|
||||
$variables['query']['fs'] = 0;
|
||||
}
|
||||
}
|
||||
else if ($variables['fs']) {
|
||||
// Note that the fs variable defaults to 0 with the AS2 player.
|
||||
$variables['query']['fs'] = 1;
|
||||
}
|
||||
|
||||
// These options default to 0.
|
||||
foreach (array('modestbranding', 'autoplay', 'hd') as $variable) {
|
||||
if ($variables[$variable]) {
|
||||
$variables['query'][$variable] = 1;
|
||||
}
|
||||
}
|
||||
// These options default to 1.
|
||||
foreach (array('showsearch', 'showinfo') as $variable) {
|
||||
if (!$variables[$variable]) {
|
||||
$variables['query'][$variable] = 0;
|
||||
}
|
||||
}
|
||||
if (!$variables['related']) {
|
||||
$variables['query']['rel'] = 0;
|
||||
}
|
||||
if ($variables['theme'] != 'dark') {
|
||||
$variables['query']['theme'] = $variables['theme'];
|
||||
}
|
||||
|
||||
// Ensure that we pass the required query variables to the Iframe settings.
|
||||
if (!empty($variables['query'])) {
|
||||
$settings['media_youtube'][$variables['wrapper_id']]['options'] = $variables['query'];
|
||||
}
|
||||
|
||||
drupal_add_js($settings, 'setting');
|
||||
drupal_add_js(drupal_get_path('module', 'media_youtube') . '/js/media_youtube.js');
|
||||
drupal_add_css(drupal_get_path('module', 'media_youtube') . '/css/media_youtube.css');
|
||||
drupal_add_js(drupal_get_path('module', 'media_youtube') . '/js/flash_detect_min.js');
|
||||
|
||||
// The chromeless player requires a different url.
|
||||
if ($variables['chromeless']) {
|
||||
$variables['url_api'] = 'apiplayer';
|
||||
$variables['query']['video_id'] = $variables['video_id'];
|
||||
}
|
||||
else {
|
||||
$variables['url_api'] = 'v/' . $variables['video_id'];
|
||||
}
|
||||
|
||||
$variables['url'] = url('http://www.youtube.com/' . $variables['url_api'], array('query' => $variables['query'], 'external' => TRUE, 'https' => TRUE));
|
||||
|
||||
// For users with JavaScript, these object and embed tags will be replaced
|
||||
// by an iframe, so that we can support users without Flash.
|
||||
$variables['output'] = <<<OUTPUT
|
||||
<object width="{$variables['width']}" height="{$variables['height']}">
|
||||
<param name="movie" value="{$variables['url']}"></param>
|
||||
<param name="allowFullScreen" value="{$variables['fullscreen']}"></param>
|
||||
<param name="wmode" value="{$variables['wmode']}" />
|
||||
<embed src="{$variables['url']}" type="application/x-shockwave-flash" width="{$variables['width']}" height="{$variables['height']}" allowfullscreen="{$variables['fullscreen']}" wmode="{$variables['wmode']}"></embed>
|
||||
</object>
|
||||
OUTPUT;
|
||||
}
|
||||
|
||||
function theme_media_youtube_field_formatter_styles($variables) {
|
||||
$element = $variables['element'];
|
||||
$style = $variables['style'];
|
||||
$variables['file'] = $element['#item'];
|
||||
$variables['uri'] = $variables['file']['uri'];
|
||||
$variables['style_name'] = $style['name'];
|
||||
return theme('media_youtube_embed', $variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preview for Styles UI.
|
||||
*/
|
||||
function theme_media_youtube_preview_style($variables) {
|
||||
$variables['uri'] = media_youtube_variable_get('preview_uri');
|
||||
$variables['field_type'] = 'file';
|
||||
$variables['object'] = file_uri_to_object($variables['uri']);
|
||||
|
||||
return theme('styles', $variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: Deprecated with Styles version 2.
|
||||
*/
|
||||
function theme_media_youtube_styles($variables) {
|
||||
$style = $variables['style'];
|
||||
$variables['file'] = $variables['object'];
|
||||
$variables['uri'] = $variables['object']->uri;
|
||||
$variables['style_name'] = $style['name'];
|
||||
return theme('media_youtube_embed', $variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo: get this working
|
||||
*
|
||||
* This code is for embedding videos in WYSIYWG areas, not currently working.
|
||||
* NOTE: Deprecated with Styles version 2.
|
||||
*/
|
||||
function theme_media_youtube_embed($variables) {
|
||||
$preset_name = $variables['preset_name'];
|
||||
$preset = styles_containers_available_styles('file', 'media_youtube', $preset_name);
|
||||
$output = '';
|
||||
if (!empty($preset)) {
|
||||
// Build the URL for display.
|
||||
$uri = $variables['uri'];
|
||||
$wrapper = file_stream_wrapper_get_instance_by_uri($uri);
|
||||
$parts = $wrapper->get_parameters();
|
||||
|
||||
$fullscreen_value = $autoplay = 'false';
|
||||
$in_browser = $thumbnail = FALSE;
|
||||
|
||||
foreach ($preset['effects'] as $effect) {
|
||||
switch ($effect['name']) {
|
||||
case 'autoplay':
|
||||
$autoplay = $effect['data']['autoplay'] ? 'true' : 'false';
|
||||
break;
|
||||
case 'resize':
|
||||
$width = $effect['data']['width'];
|
||||
$height = $effect['data']['height'];
|
||||
break;
|
||||
case 'fullscreen':
|
||||
$fullscreen_value = $effect['data']['fullscreen'] ? 'true' : 'false';
|
||||
break;
|
||||
case 'thumbnail':
|
||||
$thumbnail = $effect['data']['thumbnail'];
|
||||
}
|
||||
}
|
||||
if (isset($variables['object']->override)) {
|
||||
$override = $variables['object']->override;
|
||||
if (isset($override['width'])) {
|
||||
$width = $override['width'];
|
||||
}
|
||||
if (isset($override['height'])) {
|
||||
$height = $override['height'];
|
||||
}
|
||||
if (isset($override['wysiwyg'])) {
|
||||
$thumbnail = TRUE;
|
||||
}
|
||||
if (isset($override['browser']) && $override['browser']) {
|
||||
$in_browser = TRUE;
|
||||
$thumbnail = TRUE;
|
||||
}
|
||||
}
|
||||
$width = isset($width) ? $width : media_youtube_variable_get('width');
|
||||
$height = isset($height) ? $height : media_youtube_variable_get('height');
|
||||
$video_id = check_plain($parts['v']);
|
||||
if ($thumbnail) {
|
||||
// @todo Clean this up.
|
||||
$image_variables = array(
|
||||
'path' => $wrapper->getOriginalThumbnailPath(),
|
||||
'alt' => $variables['alt'],
|
||||
'title' => $variables['title'],
|
||||
'getsize' => FALSE,
|
||||
);
|
||||
if (isset($preset['image_style'])) {
|
||||
$image_variables['path'] = $wrapper->getLocalThumbnailPath();
|
||||
$image_variables['style_name'] = $preset['image_style'];
|
||||
$output = theme('image_style', $image_variables);
|
||||
}
|
||||
else {
|
||||
// We need to add this style attribute here so that it doesn't get lost
|
||||
// If you resize a video in a node, save it, edit it, but don't adjust
|
||||
// the sizing of the video while editing, the size will revert to the
|
||||
// default. Adding the specific size here retains the original resizing
|
||||
$WYSIWYG = isset($variables['object']->override['style']) ? $variables['object']->override['style'] : '';
|
||||
$image_variables['attributes'] = array('width' => $width, 'height' => $height, 'style' => $WYSIWYG);
|
||||
$output = theme('image', $image_variables);
|
||||
}
|
||||
if ($in_browser) {
|
||||
// Add an overlay that says 'YouTube' to media library browser thumbnails.
|
||||
$output .= '<span />';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$output = theme('media_youtube_video', array('uri' => $uri, 'width' => $width, 'height' => $height, 'autoplay' => ($autoplay == 'true' ? TRUE : NULL), 'fullscreen' => ($fullscreen_value == 'true' ? TRUE : NULL)));
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
5
sites/all/modules/media_youtube/js/flash_detect_min.js
Normal file
5
sites/all/modules/media_youtube/js/flash_detect_min.js
Normal file
@@ -0,0 +1,5 @@
|
||||
//http://www.featureblend.com/license.txt
|
||||
var FlashDetect=new function(){var self=this;self.installed=false;self.raw="";self.major=-1;self.minor=-1;self.revision=-1;self.revisionStr="";var activeXDetectRules=[{"name":"ShockwaveFlash.ShockwaveFlash.7","version":function(obj){return getActiveXVersion(obj);}},{"name":"ShockwaveFlash.ShockwaveFlash.6","version":function(obj){var version="6,0,21";try{obj.AllowScriptAccess="always";version=getActiveXVersion(obj);}catch(err){}
|
||||
return version;}},{"name":"ShockwaveFlash.ShockwaveFlash","version":function(obj){return getActiveXVersion(obj);}}];var getActiveXVersion=function(activeXObj){var version=-1;try{version=activeXObj.GetVariable("$version");}catch(err){}
|
||||
return version;};var getActiveXObject=function(name){var obj=-1;try{obj=new ActiveXObject(name);}catch(err){obj={activeXError:true};}
|
||||
return obj;};var parseActiveXVersion=function(str){var versionArray=str.split(",");return{"raw":str,"major":parseInt(versionArray[0].split(" ")[1],10),"minor":parseInt(versionArray[1],10),"revision":parseInt(versionArray[2],10),"revisionStr":versionArray[2]};};var parseStandardVersion=function(str){var descParts=str.split(/ +/);var majorMinor=descParts[2].split(/\./);var revisionStr=descParts[3];return{"raw":str,"major":parseInt(majorMinor[0],10),"minor":parseInt(majorMinor[1],10),"revisionStr":revisionStr,"revision":parseRevisionStrToInt(revisionStr)};};var parseRevisionStrToInt=function(str){return parseInt(str.replace(/[a-zA-Z]/g,""),10)||self.revision;};self.majorAtLeast=function(version){return self.major>=version;};self.minorAtLeast=function(version){return self.minor>=version;};self.revisionAtLeast=function(version){return self.revision>=version;};self.versionAtLeast=function(major){var properties=[self.major,self.minor,self.revision];var len=Math.min(properties.length,arguments.length);for(i=0;i<len;i++){if(properties[i]>=arguments[i]){if(i+1<len&&properties[i]==arguments[i]){continue;}else{return true;}}else{return false;}}};self.FlashDetect=function(){if(navigator.plugins&&navigator.plugins.length>0){var type='application/x-shockwave-flash';var mimeTypes=navigator.mimeTypes;if(mimeTypes&&mimeTypes[type]&&mimeTypes[type].enabledPlugin&&mimeTypes[type].enabledPlugin.description){var version=mimeTypes[type].enabledPlugin.description;var versionObj=parseStandardVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revisionStr=versionObj.revisionStr;self.revision=versionObj.revision;self.installed=true;}}else if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){var version=-1;for(var i=0;i<activeXDetectRules.length&&version==-1;i++){var obj=getActiveXObject(activeXDetectRules[i].name);if(!obj.activeXError){self.installed=true;version=activeXDetectRules[i].version(obj);if(version!=-1){var versionObj=parseActiveXVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revision=versionObj.revision;self.revisionStr=versionObj.revisionStr;}}}}}();};FlashDetect.JS_RELEASE="1.0.4";
|
127
sites/all/modules/media_youtube/js/media_youtube.fromurl.js
Normal file
127
sites/all/modules/media_youtube/js/media_youtube.fromurl.js
Normal file
@@ -0,0 +1,127 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Create the 'YouTube' tab for the WYSIWYG plugins.
|
||||
*/
|
||||
|
||||
// (function ($) {
|
||||
// namespace('Drupal.media.browser.plugin');
|
||||
//
|
||||
// Drupal.media.browser.plugin.media_youtube = function(mediaBrowser, options) {
|
||||
// return {
|
||||
// init: function() {
|
||||
// tabset = mediaBrowser.getTabset();
|
||||
// tabset.tabs('add', '#media_youtube', 'YouTube');
|
||||
// mediaBrowser.listen('tabs.show', function (e, id) {
|
||||
// if (id == 'media_youtube') {
|
||||
// // We only need to set this once.
|
||||
// // We probably could set it upon load.
|
||||
// if (mediaBrowser.getActivePanel().html() == '') {
|
||||
// mediaBrowser.getActivePanel().html(options.media_youtube);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// // For now, I guess self registration makes sense.
|
||||
// // Really though, we should be doing it via drupal_add_js and some settings
|
||||
// // from the drupal variable.
|
||||
// //@todo: needs a review.
|
||||
// Drupal.media.browser.register('media_youtube', Drupal.media.browser.plugin.media_youtube, {});
|
||||
// })(jQuery);
|
||||
|
||||
(function ($) {
|
||||
namespace('media.browser.plugin');
|
||||
|
||||
Drupal.media.browser.plugin.youtube_library = function(mediaBrowser, options) {
|
||||
|
||||
return {
|
||||
mediaFiles: [],
|
||||
init: function() {
|
||||
tabset = mediaBrowser.getTabset();
|
||||
tabset.tabs('add', '#youtube_library', 'YouTube');
|
||||
var that = this;
|
||||
mediaBrowser.listen('tabs.show', function (e, id) {
|
||||
if (id == 'youtube_library') {
|
||||
// This is kinda rough, I'm not sure who should delegate what here.
|
||||
mediaBrowser.getActivePanel().addClass('throbber');
|
||||
mediaBrowser.getActivePanel().html('');
|
||||
//mediaBrowser.getActivePanel().addClass('throbber');
|
||||
|
||||
// Assumes we have to refresh everytime.
|
||||
// Remove any existing content
|
||||
mediaBrowser.getActivePanel().append('<ul></ul>');
|
||||
that.browser = $('ul', mediaBrowser.getActivePanel());
|
||||
that.browser.addClass('clearfix');
|
||||
that.getMedia();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getStreams: function () {
|
||||
return ['youtube://'];
|
||||
},
|
||||
|
||||
getConditions: function () {
|
||||
return {};
|
||||
//return this.settings.conditions;
|
||||
},
|
||||
|
||||
getMedia: function() {
|
||||
var that = this;
|
||||
var callback = mediaBrowser.getCallbackUrl('getMedia');
|
||||
var params = {
|
||||
conditions: JSON.stringify(this.getConditions()),
|
||||
streams: JSON.stringify(this.getStreams())
|
||||
};
|
||||
jQuery.get(
|
||||
callback,
|
||||
params,
|
||||
function(data, status) {
|
||||
that.mediaFiles = data.media;
|
||||
that.emptyMessage = data.empty;
|
||||
that.pager = data.pager;
|
||||
that.render();
|
||||
},
|
||||
'json'
|
||||
);
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var that = this;
|
||||
mediaBrowser.getActivePanel().removeClass('throbber');
|
||||
if (this.mediaFiles.length < 1) {
|
||||
jQuery('<div id="media-empty-message" class="media-empty-message"></div>').appendTo(this.browser)
|
||||
.html(this.emptyMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
for (var m in this.mediaFiles) {
|
||||
mediaFile = this.mediaFiles[m];
|
||||
|
||||
var listItem = jQuery('<li></li>').appendTo(this.browser)
|
||||
.attr('id', 'media-file-' + mediaFile.fid)
|
||||
.addClass('media-file');
|
||||
|
||||
var imgLink = jQuery('<a href="#"></a>').appendTo(listItem)
|
||||
.html(mediaFile.preview)
|
||||
.bind('click', mediaFile, function(e) {
|
||||
// Notify the main browser
|
||||
//this.selectedMedia = mediaFile;
|
||||
$('div.media-thumbnail img').removeClass('selected');
|
||||
$('div.media-thumbnail img', $(this)).addClass('selected');
|
||||
mediaBrowser.notify('mediaSelected', {mediaFiles: [e.data]});
|
||||
//that.settings.onSelect(mediaFile);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
jQuery('<div id="media-pager" class="media-pager"></div>').appendTo(this.browser)
|
||||
.html(this.pager);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Drupal.media.browser.register('youtube_library', Drupal.media.browser.plugin.youtube_library);
|
||||
})(jQuery);
|
107
sites/all/modules/media_youtube/js/media_youtube.js
Normal file
107
sites/all/modules/media_youtube/js/media_youtube.js
Normal file
@@ -0,0 +1,107 @@
|
||||
|
||||
/**
|
||||
* @file media_youtube/js/media_youtube.js
|
||||
*/
|
||||
|
||||
(function ($) {
|
||||
|
||||
Drupal.media_youtube = {};
|
||||
Drupal.behaviors.media_youtube = {
|
||||
attach: function (context, settings) {
|
||||
// Check the browser to see if it supports html5 video.
|
||||
var video = document.createElement('video');
|
||||
var html5 = video.canPlayType ? true : false;
|
||||
|
||||
// If it has video, does it support the correct codecs?
|
||||
if (html5) {
|
||||
html5 = false;
|
||||
if (video.canPlayType( 'video/webm; codecs="vp8, vorbis"' ) || video.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"')) {
|
||||
html5 = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Put a prompt in the video wrappers to let users know they need flash
|
||||
if (!FlashDetect.installed && !html5){
|
||||
$('.media-youtube-preview-wrapper').each(Drupal.media_youtube.needFlash);
|
||||
}
|
||||
|
||||
// Replace all object tags with iframes.
|
||||
if (Drupal.settings && Drupal.settings.media_youtube) {
|
||||
for (video in Drupal.settings.media_youtube) {
|
||||
Drupal.media_youtube.insertEmbed(video);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Drupal.media_youtube.needFlash = function () {
|
||||
var id = $(this).attr('id');
|
||||
var wrapper = $('.media-youtube-preview-wrapper');
|
||||
var hw = Drupal.settings.media_youtube[id].height / Drupal.settings.media_youtube[id].width;
|
||||
wrapper.html('<div class="js-fallback">' + Drupal.t('You need Flash to watch this video. <a href="@flash">Get Flash</a>', {'@flash':'http://get.adobe.com/flashplayer'}) + '</div>');
|
||||
wrapper.height(wrapper.width() * hw);
|
||||
};
|
||||
|
||||
Drupal.media_youtube.insertEmbed = function (embed_id) {
|
||||
var videoWrapper = $('#' + embed_id + '.media-youtube-preview-wrapper');
|
||||
var settings = Drupal.settings.media_youtube[embed_id];
|
||||
|
||||
// Calculate the ratio of the dimensions of the embed.
|
||||
settings.hw = settings.height / settings.width;
|
||||
|
||||
// Replace the object embed with YouTube's iframe. This isn't done by the
|
||||
// theme function because YouTube doesn't have a no-JS or no-Flash fallback.
|
||||
var video = $('<iframe class="youtube-player" type="text/html" frameborder="0"></iframe>');
|
||||
var src = 'http://www.youtube.com/embed/' + settings.video_id;
|
||||
|
||||
// Allow other modules to modify the video settings.
|
||||
settings.options = settings.options || {};
|
||||
settings.options.wmode = 'opaque';
|
||||
$(window).trigger('media_youtube_load', settings);
|
||||
|
||||
// Merge YouTube options (such as autoplay) into the source URL.
|
||||
var query = $.param(settings.options);
|
||||
if (query) {
|
||||
src += '?' + query;
|
||||
}
|
||||
|
||||
// Set up the iframe with its contents and add it to the page.
|
||||
video
|
||||
.attr('id', settings.id)
|
||||
.attr('width', settings.width)
|
||||
.attr('height', settings.height)
|
||||
.attr('src', src);
|
||||
videoWrapper.html(video);
|
||||
|
||||
// Bind a resize event to handle fluid layouts.
|
||||
$(window).bind('resize', Drupal.media_youtube.resizeEmbeds);
|
||||
|
||||
// For some reason Chrome does not properly size the container around the
|
||||
// embed and it will just render the embed at full size unless we set this
|
||||
// timeout.
|
||||
if (!$('.lightbox-stack').length) {
|
||||
setTimeout(Drupal.media_youtube.resizeEmbeds, 1);
|
||||
}
|
||||
};
|
||||
|
||||
Drupal.media_youtube.resizeEmbeds = function () {
|
||||
$('.media-youtube-preview-wrapper').each(Drupal.media_youtube.resizeEmbed);
|
||||
};
|
||||
|
||||
Drupal.media_youtube.resizeEmbed = function () {
|
||||
var context = $(this).parent();
|
||||
var video = $(this).children(':first-child');
|
||||
var hw = Drupal.settings.media_youtube[$(this).attr('id')].hw;
|
||||
// Change the height of the wrapper that was given a fixed height by the
|
||||
// YouTube theming function.
|
||||
$(this)
|
||||
.height(context.width() * hw)
|
||||
.width(context.width());
|
||||
|
||||
// Change the attributes on the embed to match the new size.
|
||||
video
|
||||
.height(context.width() * hw)
|
||||
.width(context.width());
|
||||
};
|
||||
|
||||
})(jQuery);
|
20
sites/all/modules/media_youtube/media_youtube.info
Normal file
20
sites/all/modules/media_youtube/media_youtube.info
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
name = Media: YouTube
|
||||
description = Provides YouTube support to the Media module.
|
||||
package = "Media"
|
||||
core = 7.x
|
||||
files[] = media_youtube.module
|
||||
files[] = includes/MediaInternetYouTubeHandler.inc
|
||||
files[] = includes/MediaYouTubeStreamWrapper.inc
|
||||
files[] = includes/MediaYouTubeStyles.inc
|
||||
files[] = includes/media_youtube.formatters.inc
|
||||
files[] = includes/media_youtube.styles.inc
|
||||
files[] = includes/media_youtube.variables.inc
|
||||
dependencies[] = media_internet
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-03-13
|
||||
version = "7.x-1.0-beta3"
|
||||
core = "7.x"
|
||||
project = "media_youtube"
|
||||
datestamp = "1331655643"
|
||||
|
109
sites/all/modules/media_youtube/media_youtube.install
Normal file
109
sites/all/modules/media_youtube/media_youtube.install
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the Media: YouTube module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implement hook_install().
|
||||
*/
|
||||
function media_youtube_install() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_uninstall().
|
||||
*/
|
||||
function media_youtube_uninstall() {
|
||||
drupal_load('module', 'media_youtube');
|
||||
|
||||
foreach (media_youtube_variable_default() as $variable => $value) {
|
||||
media_youtube_variable_del($variable);
|
||||
}
|
||||
return array(array('success' => TRUE, 'query' => "Deleted all variables in the Media: YouTube namespace."));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear style and preset caches.
|
||||
*/
|
||||
function media_youtube_update_7001() {
|
||||
// We don't do this if we're using version 1 of Styles.
|
||||
if (function_exists('styles_style_flush')) {
|
||||
styles_style_flush();
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add label to Media: YouTube file style.
|
||||
*/
|
||||
function media_youtube_update_7003() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild themes.
|
||||
*/
|
||||
function media_youtube_update_7004() {
|
||||
drupal_theme_rebuild();
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a large video preset and medium thumbnail.
|
||||
*/
|
||||
function media_youtube_update_7005() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a square thumbnail preset.
|
||||
*/
|
||||
function media_youtube_update_7006() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the registry to locate class files in new location.
|
||||
*/
|
||||
function media_youtube_update_7007() {
|
||||
registry_rebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild styles presets to use camelCase.
|
||||
*/
|
||||
function media_youtube_update_7008() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change default styles presets.
|
||||
*/
|
||||
function media_youtube_update_7009() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change default styles presets.
|
||||
*/
|
||||
function media_youtube_update_7010() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add video presets based on Image styles.
|
||||
*/
|
||||
function media_youtube_update_7011() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild theme and formatters.
|
||||
*/
|
||||
function media_youtube_update_7012() {
|
||||
return array();
|
||||
}
|
||||
|
123
sites/all/modules/media_youtube/media_youtube.module
Normal file
123
sites/all/modules/media_youtube/media_youtube.module
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file media_youtube/media_youtube.module
|
||||
*
|
||||
* Media: YouTube provides a stream wrapper and formatters for videos provided
|
||||
* by YouTube, available at http://youtube.com/.
|
||||
*
|
||||
* @TODO:
|
||||
* Tie in YouTube API.
|
||||
* Allow editors to search for videos to display on the browser.
|
||||
* Allow editors to put in a youtube username to display on the browser.
|
||||
* Allow editors to log in w/ their credentials.
|
||||
* Allow editors to upload videos to YouTube.
|
||||
*/
|
||||
|
||||
// A registry of variable_get defaults.
|
||||
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_youtube') . '/includes/media_youtube.variables.inc';
|
||||
|
||||
// Hooks and callbacks for integrating with Styles module for display.
|
||||
// @todo Can save a little overhead for people without Styles module by wrapping
|
||||
// this inside a module_exists('styles'). However, is that safe to do in
|
||||
// global context? If not, is there any down side to doing it in hook_init()?
|
||||
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_youtube') . '/includes/media_youtube.styles.inc';
|
||||
|
||||
// Hooks and callbacks for integrating with File Entity module for display.
|
||||
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_youtube') . '/includes/media_youtube.formatters.inc';
|
||||
|
||||
/**
|
||||
* Implements hook_media_internet_providers().
|
||||
*/
|
||||
function media_youtube_media_internet_providers() {
|
||||
$path = drupal_get_path('module', 'media_youtube');
|
||||
return array(
|
||||
'MediaInternetYouTubeHandler' => array(
|
||||
'title' => 'youtube',
|
||||
'image' => $path . '/images/stream-youtube.png'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_stream_wrappers().
|
||||
*/
|
||||
function media_youtube_stream_wrappers() {
|
||||
return array(
|
||||
'youtube' => array(
|
||||
'name' => t('YouTube videos'),
|
||||
'class' => 'MediaYouTubeStreamWrapper',
|
||||
'description' => t('Videos provided by YouTube.'),
|
||||
'type' => STREAM_WRAPPERS_READ_VISIBLE,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function media_youtube_theme($existing, $type, $theme, $path) {
|
||||
return array(
|
||||
'media_youtube_preview_style' => array(
|
||||
'variables' => array('style_name' => NULL),
|
||||
'file' => 'media_youtube.theme.inc',
|
||||
'path' => $path . '/includes/themes',
|
||||
),
|
||||
'media_youtube_field_formatter_styles' => array(
|
||||
'variables' => array('element' => NULL, 'style' => NULL),
|
||||
'file' => 'media_youtube.theme.inc',
|
||||
'path' => $path . '/includes/themes',
|
||||
),
|
||||
// Note that all the variables after options are now deprecated.
|
||||
'media_youtube_video' => array(
|
||||
'variables' => array('uri' => NULL, 'options' => array(), 'width' => NULL, 'height' => NULL, 'autoplay' => NULL, 'fullscreen' => NULL, 'related' => NULL),
|
||||
'file' => 'media_youtube.theme.inc',
|
||||
'path' => $path . '/includes/themes',
|
||||
'template' => 'media-youtube-video',
|
||||
),
|
||||
'media_youtube_embed' => array(
|
||||
'variables' => array('style_name' => NULL, 'uri' => NULL, 'alt' => NULL, 'title' => NULL),
|
||||
'file' => 'media_youtube.theme.inc',
|
||||
'path' => $path . '/includes/themes',
|
||||
),
|
||||
'media_youtube_styles' => array(
|
||||
'variables' => array('element' => NULL, 'style' => NULL),
|
||||
'file' => 'media_youtube.theme.inc',
|
||||
'path' => $path . '/includes/themes',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_media_parse().
|
||||
*
|
||||
* @todo This hook should be deprecated. Refactor Media module to not call it
|
||||
* any more, since media_internet should be able to automatically route to the
|
||||
* appropriate handler.
|
||||
*/
|
||||
function media_youtube_media_parse($embed_code) {
|
||||
$handler = new MediaInternetYouTubeHandler($embed_code);
|
||||
return $handler->parse($embed_code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_media_format_form_prepare_alter().
|
||||
*/
|
||||
function media_youtube_media_format_form_prepare_alter(&$form, &$form_state, $media) {
|
||||
$settings = array('autosubmit' => ($media->type == "video"));
|
||||
drupal_add_js(array('media_format_form' => $settings), 'setting');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ctools_plugin_api().
|
||||
*/
|
||||
function media_youtube_ctools_plugin_api($owner, $api) {
|
||||
static $api_versions = array(
|
||||
'file_entity' => array(
|
||||
'file_default_displays' => 1,
|
||||
),
|
||||
);
|
||||
if (isset($api_versions[$owner][$api])) {
|
||||
return array('version' => $api_versions[$owner][$api]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user