first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View 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.

View File

@@ -0,0 +1,5 @@
Media: Vimeo
Creates a Vimeo PHP Stream Wrapper for Resource and implements the various
formatter and file listing hooks in the Media module.

View File

@@ -0,0 +1,21 @@
.media-vimeo-preview-wrapper {
max-width: 100%;
min-height: 50px;
position: relative;
}
.media-vimeo-preview-wrapper object,
.media-vimeo-preview-wrapper iframe {
max-width: 100%;
position: relative;
}
.media-vimeo-preview-wrapper .js-fallback {
left: 0;
margin-top: -0.5em;
position: absolute;
right: 0;
text-align: center;
top: 50%;
}

View File

@@ -0,0 +1,30 @@
/**
* @file
* Overlay for Vimeo thumbnails in the media library browser.
*/
#media-browser .styles-container-media_vimeo {
/* Relative wrapper for the overlay. */
position: relative;
}
#media-browser .styles-container-media_vimeo span {
/* Here's the overlay image. */
background: url(images/stream-vimeo.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_vimeo span:hover {
/* The */
background-position: 0px -22px;
}
#media-browser .styles-container-media_vimeo img {
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 951 B

View File

@@ -0,0 +1,98 @@
<?php
/**
* Implementation of MediaInternetBaseHandler.
*
* @see hook_media_internet_providers().
*/
class MediaInternetVimeoHandler extends MediaInternetBaseHandler {
public function parse($embedCode) {
// Vimeo has a few URL formats:
// http://vimeo.com/*
// http://vimeo.com/video/*
// http://vimeo.com/groups/*/videos/*
// http://vimeo.com/channels/*#$ID
$patterns = array(
'@vimeo\.com/(\d+)@i',
'@vimeo\.com/video/(\d+)@i',
'@vimeo\.com/groups/.+/videos/(\d+)@i',
'@vimeo\.com/channels/.+#(\d+)@i',
);
foreach ($patterns as $pattern) {
preg_match($pattern, $embedCode, $matches);
if (isset($matches[1])) {
return file_stream_wrapper_uri_normalize('vimeo://v/' . $matches[1]);
}
}
}
public function claim($embedCode) {
if ($this->parse($embedCode)) {
return TRUE;
}
}
public function save() {
$file = $this->getFileObject();
file_save($file);
return $file;
}
public function getFileObject() {
$uri = $this->parse($this->embedCode);
//@todo: this is terribly broken in some ways because the function is really
// made for local files which are 'real'
$file = file_uri_to_object($uri, TRUE);
// Try to default the file name to the video's title.
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.vimeo.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/ and https://vimeo.com/api/docs/oembed
*
* @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://vimeo.com/api/oembed.json', array(
'query' => array('url' => $external_url))
);
$response = drupal_http_request($oembed_url);
if (!isset($response->error)) {
return drupal_json_decode($response->data);
}
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* @file
* Create a Vimeo Stream Wrapper class for the Media/Resource module.
*/
/**
* Create an instance like this:
* $vimeo = new ResourceVimeoStreamWrapper('vimeo://v/[video-code]');
*/
class MediaVimeoStreamWrapper extends MediaReadOnlyStreamWrapper {
static function getMimeType($uri, $mapping = NULL) {
return 'video/vimeo';
}
/**
* Call the Vimeo Simple API and fetch the video information.
*
* See http://vimeo.com/api/docs/simple-api
*
* @return
* Array of properties.
*/
static function getVideoProperties($video_id) {
// The .php format returns a serialized array.
$response = drupal_http_request('http://vimeo.com/api/v2/video/'. $video_id .'.php');
return unserialize($response->data);
}
function getTarget($f) {
return FALSE;
}
function interpolateUrl() {
return 'http://vimeo.com/' . intval($this->parameters['v']);
}
function getOriginalThumbnailPath() {
$video_properties = self::getVideoProperties($this->parameters['v']);
return $video_properties[0]['thumbnail_large'];
}
function getLocalThumbnailPath() {
$local_path = 'public://media-vimeo/' . intval($this->parameters['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;
}
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* @file
* Styles class implementation for Media: Vimeo.
*/
class MediaVimeoStyles 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_vimeo_video', $variables));
}
}

View File

@@ -0,0 +1,167 @@
<?php
/**
* @file
*/
/**
* Implements hook_file_formatter_info().
*/
function media_vimeo_file_formatter_info() {
$formatters['media_vimeo_video'] = array(
'label' => t('Vimeo Video'),
'file types' => array('video'),
'default settings' => array(
'width' => media_vimeo_variable_get('width'),
'height' => media_vimeo_variable_get('height'),
'autoplay' => media_vimeo_variable_get('autoplay'),
),
'view callback' => 'media_vimeo_file_formatter_video_view',
'settings callback' => 'media_vimeo_file_formatter_video_settings',
);
$formatters['media_vimeo_image'] = array(
'label' => t('Vimeo Preview Image'),
'file types' => array('video'),
'default settings' => array(
'image_style' => '',
),
'view callback' => 'media_vimeo_file_formatter_image_view',
'settings callback' => 'media_vimeo_file_formatter_image_settings',
);
return $formatters;
}
/**
* Implements hook_file_formatter_FORMATTER_view().
*/
function media_vimeo_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 == 'vimeo' && empty($file->override['wysiwyg'])) {
$element = array(
'#theme' => 'media_vimeo_video',
'#uri' => $file->uri,
);
foreach (array('width', 'height', 'autoplay') as $setting) {
$element['#' . $setting] = isset($file->override[$setting]) ? $file->override[$setting] : $display['settings'][$setting];
}
return $element;
}
}
/**
* Implements hook_file_formatter_FORMATTER_settings().
*/
function media_vimeo_file_formatter_video_settings($form, &$form_state, $settings) {
$element = array();
$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['autoplay'] = array(
'#title' => t('Autoplay'),
'#type' => 'checkbox',
'#default_value' => $settings['autoplay'],
);
return $element;
}
/**
* Implements hook_file_formatter_FORMATTER_view().
*/
function media_vimeo_file_formatter_image_view($file, $display, $langcode) {
$scheme = file_uri_scheme($file->uri);
if ($scheme == 'vimeo') {
$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_vimeo_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_vimeo_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_vimeo_variable_get('autoplay'),
),
);
foreach ($default_video_settings as $view_mode => $settings) {
$display_name = 'video__' . $view_mode . '__media_vimeo_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_vimeo_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;
}

View File

@@ -0,0 +1,265 @@
<?php
/**
* @file media_vimeo/includes/media_vimeo.styles.inc
* Styles definitions for Media: Vimeo.
*/
/**
* Implementation of Styles module hook_styles_register().
*/
function media_vimeo_styles_register() {
return array(
'MediaVimeoStyles' => array(
'field_types' => 'file',
'name' => t('MediaVimeo'),
'description' => t('Media Vimeo styles.'),
'path' => drupal_get_path('module', 'media_vimeo') .'/includes',
'file' => 'media_vimeo.styles.inc',
),
);
}
/**
* Implements hook_styles_containers(). (Deprecated in version 2)
*/
function media_vimeo_styles_containers() {
return array(
'file' => array(
'containers' => array(
'media_vimeo' => array(
'label' => t('Vimeo Styles'),
'data' => array(
'streams' => array(
'vimeo',
),
'mimetypes' => array(
'video/vimeo',
),
),
'weight' => 0,
'filter callback' => 'media_vimeo_formatter_filter',
'themes' => array(
'field_formatter_styles' => 'media_vimeo_field_formatter_styles',
'styles' => 'media_vimeo_styles',
'preview' => 'media_vimeo_preview_style',
),
'description' => t('Vimeo Styles will display embedded Vimeo videos and thumbnails to your choosing, such as by resizing, setting colors, and autoplay. You can !manage.', array('!manage' => l(t('manage your Vimeo styles here'), 'admin/config/media/media-vimeo-styles'))),
),
),
),
);
}
function media_vimeo_formatter_filter($variables) {
if (isset($variables['object'])) {
$object = isset($variables['object']->file) ? $variables['object']->file : $variables['object'];
return (file_uri_scheme($object->uri) == 'vimeo') && ($object->filemime == 'video/vimeo');
}
}
/**
* Implementation of the File Styles module's hook_file_styles_filter().
*/
function media_vimeo_file_styles_filter($object) {
$file = isset($object->file) ? $object->file : $object;
if ((file_uri_scheme($file->uri) == 'vimeo') && ($file->filemime == 'video/vimeo')) {
return 'media_vimeo';
}
}
/**
* Implements hook_styles_styles().
*/
function media_vimeo_styles_styles() {
$styles = array(
'file' => array(
'containers' => array(
'media_vimeo' => array(
'styles' => array(
'vimeo_thumbnail' => array(
'name' => 'vimeo_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)),
),
),
'vimeo_preview' => array(
'name' => 'vimeo_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)),
),
),
'vimeo_full' => array(
'name' => 'vimeo_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_vimeo']['styles']['vimeo_thumbnail_' . $style_name] = array(
'name' => 'vimeo_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_vimeo_styles_presets() {
$presets = array(
'file' => array(
'square_thumbnail' => array(
'media_vimeo' => array(
'vimeo_thumbnail_square_thumbnail',
),
),
'thumbnail' => array(
'media_vimeo' => array(
'vimeo_thumbnail',
),
),
'small' => array(
'media_vimeo' => array(
'vimeo_preview',
),
),
'large' => array(
'media_vimeo' => array(
'vimeo_full',
),
),
'original' => array(
'media_vimeo' => array(
'vimeo_full',
),
),
),
);
return $presets;
}
/**
* Implementation of Styles module hook_styles_default_containers().
*/
function media_vimeo_styles_default_containers() {
// We append Vimeo to the file containers.
return array(
'file' => array(
'containers' => array(
'media_vimeo' => array(
'class' => 'MediaVimeoStyles',
'name' => 'media_vimeo',
'label' => t('Vimeo'),
'preview' => 'media_vimeo_preview_style',
),
),
),
);
}
/**
* Implementation of Styles module hook_styles_default_presets().
*/
function media_vimeo_styles_default_presets() {
$presets = array(
'file' => array(
'containers' => array(
'media_vimeo' => 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_vimeo']['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_vimeo']['presets']['unlinked_' . $style_name] = $presets['file']['containers']['media_vimeo']['presets']['linked_' . $style_name];
array_shift($presets['file']['containers']['media_vimeo']['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_vimeo']['presets']['video_' . $style_name] = array(
array(
'name' => 'resize',
'settings' => $effect['data'],
),
array(
'name' => 'video',
'settings' => array(),
),
);
}
}
}
return $presets;
}

View File

@@ -0,0 +1,132 @@
<?php
/**
* @file media_vimeo/includes/media_vimeo.variables.inc
* Variable defaults for Media: Vimeo.
*/
/**
* Define our constants.
*/
/**
* This is the variable namespace, automatically prepended to module variables.
*/
define('MEDIA_VIMEO_NAMESPACE', 'media_vimeo__');
/**
* Wrapper for variable_get() using the Media: Vimeo variable registry.
*
* @param string $name
* The variable name to retrieve. Note that it will be namespaced by
* pre-pending MEDIA_VIMEO_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_vimeo_variable_default() function.
* @return unknown
* Returns the stored variable or its default.
*
* @see media_vimeo_variable_set()
* @see media_vimeo_variable_del()
* @see media_vimeo_variable_default()
*/
function media_vimeo_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_vimeo_variable_default($name);
}
// Namespace all variables.
$variable_name = MEDIA_VIMEO_NAMESPACE . $name;
return variable_get($variable_name, $default);
}
/**
* Wrapper for variable_set() using the Media: Vimeo variable registry.
*
* @param string $name
* The variable name to set. Note that it will be namespaced by
* pre-pending MEDIA_VIMEO_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_vimeo_variable_get()
* @see media_vimeo_variable_del()
* @see media_vimeo_variable_default()
*/
function media_vimeo_variable_set($name, $value) {
$variable_name = MEDIA_VIMEO_NAMESPACE . $name;
return variable_set($variable_name, $value);
}
/**
* Wrapper for variable_del() using the Media: Vimeo variable registry.
*
* @param string $name
* The variable name to delete. Note that it will be namespaced by
* pre-pending MEDIA_VIMEO_NAMESPACE, as to avoid variable collisions with
* other modules.
*
* @see media_vimeo_variable_get()
* @see media_vimeo_variable_set()
* @see media_vimeo_variable_default()
*/
function media_vimeo_variable_del($name) {
$variable_name = MEDIA_VIMEO_NAMESPACE . $name;
variable_del($variable_name);
}
/**
* The default variables within the Media: Vimeo namespace.
*
* @param string $name
* Optional variable name to retrieve the default. Note that it has not yet
* been pre-pended with the MEDIA_VIMEO_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_vimeo_variable_get()
* @see media_vimeo_variable_set()
* @see media_vimeo_variable_del()
*/
function media_vimeo_variable_default($name = NULL) {
static $defaults;
if (!isset($defaults)) {
$defaults = array(
'width' => 560,
'height' =>340,
'autoplay' => FALSE,
'fullscreen' => TRUE,
'preview_uri' => 'vimeo://v/21869117',
);
}
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_VIMEO_NAMESPACE.
*/
function media_vimeo_variable_name($name) {
return MEDIA_VIMEO_NAMESPACE . $name;
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* @file media_vimeo/includes/themes/media-vimeo-video.tpl.php
*
* Template file for theme('media_vimeo_video').
*
* Variables available:
* $uri - The uri to the Vimeo video, such as vimeo://v/xsy7x8c9.
* $video_id - The unique identifier of the Vimeo 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-vimeo-outer-wrapper" id="media-vimeo-<?php print $id; ?>" style="width: <?php print $width; ?>px; height: <?php print $height; ?>px;">
<div class="media-vimeo-preview-wrapper" id="<?php print $wrapper_id; ?>">
<?php print $output; ?>
</div>
</div>

View File

@@ -0,0 +1,179 @@
<?php
/**
* @file media_vimeo/includes/themes/media_vimeo.theme.inc
*
* Theme and preprocess functions for Media: Vimeo.
*/
/**
* Preprocess function for theme('media_vimeo_video').
*/
function media_vimeo_preprocess_media_vimeo_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['width'] = isset($variables['width']) ? $variables['width'] : media_vimeo_variable_get('width');
$variables['height'] = isset($variables['height']) ? $variables['height'] : media_vimeo_variable_get('height');
$variables['autoplay'] = isset($variables['autoplay']) ? $variables['autoplay'] : media_vimeo_variable_get('autoplay');
$variables['fullscreen'] = isset($variables['fullscreen']) ? $variables['fullscreen'] : media_vimeo_variable_get('fullscreen');
$variables['autoplay'] = $variables['autoplay'] ? 1 : 0;
$variables['fullscreen'] = $variables['fullscreen'] ? 'true' : 'false';
$variables['wrapper_id'] = 'media_vimeo_' . $variables['video_id'] . '_' . $variables['id'];
// 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="http://vimeo.com/moogaloop.swf?clip_id={$variables['video_id']}">
<param name="allowFullScreen" value="{$variables['fullscreen']}"></param>
<param name="wmode" value="transparent" />
<embed src="http://vimeo.com/moogaloop.swf?clip_id={$variables['video_id']}" type="application/x-shockwave-flash" width="{$variables['width']}" height="{$variables['height']}" allowfullscreen="{$variables['fullscreen']}"></embed>
</object>
OUTPUT;
// Pass the settings to replace the object tag with an iframe.
$settings = array(
'media_vimeo' => array(
$variables['wrapper_id'] => array(
'width' => $variables['width'],
'height' => $variables['height'],
'video_id' => $variables['video_id'],
'fullscreen' => $variables['fullscreen'],
'id' => $variables['wrapper_id'] .'_iframe',
),
),
);
if ($variables['autoplay']) {
$settings['media_vimeo'][$variables['wrapper_id']]['options'] = array(
'autoplay' => $variables['autoplay'],
);
}
drupal_add_js($settings, 'setting');
drupal_add_js(drupal_get_path('module', 'media_vimeo') . '/js/media_vimeo.js');
drupal_add_css(drupal_get_path('module', 'media_vimeo') . '/css/media_vimeo.css');
drupal_add_js(drupal_get_path('module', 'media_vimeo') . '/js/flash_detect_min.js');
}
function theme_media_vimeo_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_vimeo_embed', $variables);
}
/**
* Preview for Styles UI.
*/
function theme_media_vimeo_preview_style($variables) {
$variables['uri'] = media_vimeo_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_vimeo_styles($variables) {
$style = $variables['style'];
$variables['file'] = $variables['object'];
$variables['uri'] = $variables['object']->uri;
$variables['style_name'] = $style['name'];
return theme('media_vimeo_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_vimeo_embed($variables) {
$preset_name = $variables['preset_name'];
$preset = styles_containers_available_styles('file', 'media_vimeo', $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_vimeo_variable_get('width');
$height = isset($height) ? $height : media_vimeo_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 'Vimeo' to media library browser thumbnails.
$output .= '<span />';
}
}
else {
$output = theme('media_vimeo_video', array('uri' => $uri, 'width' => $width, 'height' => $height, 'autoplay' => ($autoplay == 'true' ? TRUE : NULL), 'fullscreen' => ($fullscreen_value == 'true' ? TRUE : NULL)));
}
}
return $output;
}

View 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";

View File

@@ -0,0 +1,127 @@
/**
* @file
* Create the 'Vimeo' tab for the WYSIWYG plugins.
*/
// (function ($) {
// namespace('Drupal.media.browser.plugin');
//
// Drupal.media.browser.plugin.media_vimeo = function(mediaBrowser, options) {
// return {
// init: function() {
// tabset = mediaBrowser.getTabset();
// tabset.tabs('add', '#media_vimeo', 'Vimeo');
// mediaBrowser.listen('tabs.show', function (e, id) {
// if (id == 'media_vimeo') {
// // We only need to set this once.
// // We probably could set it upon load.
// if (mediaBrowser.getActivePanel().html() == '') {
// mediaBrowser.getActivePanel().html(options.media_vimeo);
// }
// }
// });
// }
// }
// };
//
// // 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_vimeo', Drupal.media.browser.plugin.media_vimeo, {});
// })(jQuery);
(function ($) {
namespace('media.browser.plugin');
Drupal.media.browser.plugin.vimeo_library = function(mediaBrowser, options) {
return {
mediaFiles: [],
init: function() {
tabset = mediaBrowser.getTabset();
tabset.tabs('add', '#vimeo_library', 'Vimeo');
var that = this;
mediaBrowser.listen('tabs.show', function (e, id) {
if (id == 'vimeo_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 ['vimeo://'];
},
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('vimeo_library', Drupal.media.browser.plugin.vimeo_library);
})(jQuery);

View File

@@ -0,0 +1,106 @@
/**
* @file media_vimeo/js/media_vimeo.js
*/
(function ($) {
Drupal.media_vimeo = {};
Drupal.behaviors.media_vimeo = {
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-vimeo-preview-wrapper').each(Drupal.media_vimeo.needFlash);
}
// Replace all object tags with iframes.
if (Drupal.settings && Drupal.settings.media_vimeo) {
for (video in Drupal.settings.media_vimeo) {
Drupal.media_vimeo.insertEmbed(video);
}
}
}
};
Drupal.media_vimeo.needFlash = function () {
var id = $(this).attr('id');
var wrapper = $('.media-vimeo-preview-wrapper');
var hw = Drupal.settings.media_vimeo[id].height / Drupal.settings.media_vimeo[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_vimeo.insertEmbed = function (embed_id) {
var videoWrapper = $('#' + embed_id + '.media-vimeo-preview-wrapper');
var settings = Drupal.settings.media_vimeo[embed_id];
// Calculate the ratio of the dimensions of the embed.
settings.hw = settings.height / settings.width;
// Replace the object embed with Vimeo's iframe. This isn't done by the
// theme function because Vimeo doesn't have a no-JS or no-Flash fallback.
var video = $('<iframe class="vimeo-player" type="text/html" frameborder="0"></iframe>');
var src = 'http://player.vimeo.com/video/' + settings.video_id;
// Allow other modules to modify the video settings.
settings.options = settings.options || {};
$(window).trigger('media_vimeo_load', settings);
// Merge Vimeo 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_vimeo.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_vimeo.resizeEmbeds, 1);
}
};
Drupal.media_vimeo.resizeEmbeds = function () {
$('.media-vimeo-preview-wrapper').each(Drupal.media_vimeo.resizeEmbed);
};
Drupal.media_vimeo.resizeEmbed = function () {
var context = $(this).parent();
var video = $(this).children(':first-child');
var hw = Drupal.settings.media_vimeo[$(this).attr('id')].hw;
// Change the height of the wrapper that was given a fixed height by the
// Vimeo 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);

View File

@@ -0,0 +1,21 @@
name = Media: Vimeo
description = Provides Vimeo support to the Media module.
package = "Media"
core = 7.x
files[] = media_vimeo.module
files[] = includes/MediaInternetVimeoHandler.inc
files[] = includes/MediaVimeoStreamWrapper.inc
files[] = includes/MediaVimeoStyles.inc
files[] = includes/media_vimeo.formatters.inc
files[] = includes/media_vimeo.styles.inc
files[] = includes/media_vimeo.variables.inc
dependencies[] = media_internet
; Information added by drupal.org packaging script on 2012-03-26
version = "7.x-1.0-beta5"
core = "7.x"
project = "media_vimeo"
datestamp = "1332792648"

View File

@@ -0,0 +1,25 @@
<?php
/**
* @file
* Install, update and uninstall functions for the Media: Vimeo module.
*/
/**
* Implement hook_install().
*/
function media_vimeo_install() {
return array();
}
/**
* Implement hook_uninstall().
*/
function media_vimeo_uninstall() {
drupal_load('module', 'media_vimeo');
foreach (media_vimeo_variable_default() as $variable => $value) {
media_vimeo_variable_del($variable);
}
return array(array('success' => TRUE, 'query' => "Deleted all variables in the Media: Vimeo namespace."));
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* @file media_vimeo/media_vimeo.module
*
* Media: Vimeo provides a stream wrapper and formatters for videos provided
* by Vimeo, available at http://vimeo.com/.
*
* @TODO:
* Tie in Vimeo API.
* Allow editors to search for videos to display on the browser.
* Allow editors to put in a vimeo username to display on the browser.
* Allow editors to log in w/ their credentials.
* Allow editors to upload videos to Vimeo.
*/
// A registry of variable_get defaults.
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_vimeo') . '/includes/media_vimeo.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_vimeo') . '/includes/media_vimeo.styles.inc';
// Hooks and callbacks for integrating with File Entity module for display.
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_vimeo') . '/includes/media_vimeo.formatters.inc';
/**
* Implements hook_media_internet_providers().
*/
function media_vimeo_media_internet_providers() {
$path = drupal_get_path('module', 'media_vimeo');
return array(
'MediaInternetVimeoHandler' => array(
'title' => 'vimeo',
'image' => $path . '/images/stream-vimeo.png'
),
);
}
/**
* Implements hook_stream_wrappers().
*/
function media_vimeo_stream_wrappers() {
return array(
'vimeo' => array(
'name' => t('Vimeo videos'),
'class' => 'MediaVimeoStreamWrapper',
'description' => t('Videos provided by Vimeo.'),
'type' => STREAM_WRAPPERS_READ_VISIBLE,
),
);
}
/**
* Implements hook_theme().
*/
function media_vimeo_theme($existing, $type, $theme, $path) {
return array(
'media_vimeo_preview_style' => array(
'variables' => array('style_name' => NULL),
'file' => 'media_vimeo.theme.inc',
'path' => $path . '/includes/themes',
),
'media_vimeo_field_formatter_styles' => array(
'variables' => array('element' => NULL, 'style' => NULL),
'file' => 'media_vimeo.theme.inc',
'path' => $path . '/includes/themes',
),
'media_vimeo_video' => array(
'variables' => array('uri' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL, 'fullscreen' => NULL),
'file' => 'media_vimeo.theme.inc',
'path' => $path . '/includes/themes',
'template' => 'media-vimeo-video',
),
'media_vimeo_embed' => array(
'variables' => array('style_name' => NULL, 'uri' => NULL, 'alt' => NULL, 'title' => NULL),
'file' => 'media_vimeo.theme.inc',
'path' => $path . '/includes/themes',
),
'media_vimeo_styles' => array(
'variables' => array('element' => NULL, 'style' => NULL),
'file' => 'media_vimeo.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_vimeo_media_parse($embed_code) {
$handler = new MediaInternetVimeoHandler($embed_code);
return $handler->parse($embed_code);
}
/**
* Implements hook_media_format_form_prepare_alter().
*/
function media_vimeo_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_vimeo_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]);
}
}