FINAL suepr merge step : added all modules to this super repos

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-19 16:46:59 +02:00
7585 changed files with 1723356 additions and 18 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,29 @@
<?php
/**
* Define this Export UI plugin.
*/
$plugin = array(
'schema' => 'vef_video_styles', // As defined in hook_schema().
'access' => 'administer video styles', // Define a permission users must have to access these pages.
// Define the menu item.
'menu' => array(
'menu prefix' => 'admin/config/media',
'menu item' => 'vef_video_styles',
'menu title' => 'Configure Video Embed Styles',
'menu description' => 'Administer Video Embed Field\'s video styles.',
),
// Define user interface texts.
'title singular' => t('video style'),
'title plural' => t('video styles'),
'title singular proper' => t('Video Styles'),
'title plural proper' => t('Video Styles'),
// Define the names of the functions that provide the add/edit forms.
'form' => array(
'settings' => 'video_embed_field_video_style_form',
// 'submit' and 'validate' are also valid callbacks.
),
);

View File

@@ -0,0 +1,22 @@
<?php
/**
* @file
* Default theme implementation to display a video embed field.
*
* Variables available:
* - $url: The URL of the video to display embed code for
* - $style: The style name of the embed code to use
* - $style_settings: The style settings for the embed code
* - $handler: The name of the video handler
* - $embed_code: The embed code
* - $data: Additional video data
*
* @see template_preprocess_video_embed()
*/
?>
<div class="embedded-video">
<div class="player">
<?php print $embed_code; ?>
</div>
</div>

View File

@@ -0,0 +1,13 @@
name = "Video Embed Facebook"
description = "Provides Facebook handler for Video Embed Fields. This module also serves as an example of how to add handlers to video embed field."
core = "7.x"
package = Media
configure = admin/config/media/vef_video_styles
dependencies[] = "video_embed_field"
; Information added by drupal.org packaging script on 2012-06-21
version = "7.x-2.0-beta5"
core = "7.x"
project = "video_embed_field"
datestamp = "1340317020"

View File

@@ -0,0 +1,148 @@
<?php
/**
* @file Add a handler for facebook videos to Video Embed Field.
* @see video_embed_field.api.php for more documentation
*/
/**
* Implements hook_video_embed_handler_info().
* This function is used to tell video_embed_field which functions will be used to handle
* different operations, along with a bit of metadata.
* @return an associative array with the data
* @see video_embed_field.api.php for specific details on the data to return.
*/
function video_embed_facebook_video_embed_handler_info () {
$handlers = array();
//the key here should be unique to our handler, normally the name of the service will suffice
$handlers['facebook'] = array(
'title' => 'Facebook Video', //The title is the name to show to users
//function is a function to take the url and return the embed code
'function' => 'video_embed_facebook_handle_video',
//thumbnail_function is optional and takes the url and returns the thumbnail url
'thumbnail_function' => 'video_embed_facebook_handle_thumbnail',
//data_function is optional and returns an array of extra data for the given video url
//because facebook requires oath to get this data, we'll leave it out for now
//'data_function' => 'video_embed_facebook_handle_data',
//form is the configure form to embed into video_embed styles - this is where all settings should go
'form' => 'video_embed_facebook_form',
//domains is how video embed determines which handler to use, its an array of domains to match
//urls against. Don't include the scheme (like http://) or www.
'domains' => array(
'facebook.com',
),
//defaults are the defaults to provide to your form (as defined in your form callback)
'defaults' => array(
'width' => 640,
'height' => 360,
'allowfullscreen' => TRUE,
),
);
return $handlers;
}
/**
* Our configuration form (the callback for the form key in info)
* Provide a form to configure out video settings
* @param $defaults - default/current values for your provider, the currently saved settings
* with empty values filled with the defaults provided in info hook
* @return a form as defined by forms api
*/
function video_embed_facebook_form ($defaults) {
$form = array();
//form element for the width of the player - note we're using the default from defaults
$form['height'] = array(
'#type' => 'textfield',
'#title' => t('Player Width'),
'#description' => t('The width of the player.'),
'#default_value' => $defaults['height'],
);
//element for width
$form['width'] = array(
'#type' => 'textfield',
'#title' => t('Player Width'),
'#description' => t('The width of the player.'),
'#default_value' => $defaults['width'],
);
//allow configuration of fullscreen
$form['allowfullscreen'] = array(
'#type' => 'checkbox',
'#title' => t('Allow Fullscreen'),
'#desecription' => t('This will allow the video to be fullscreened.'),
'#default_value' => $defaults['allowfullscreen'],
);
return $form;
}
/**
* This is the video handler (the 'function' key from handler_info)
* @param $url - the full video url
* @param $settings - an associative array of this handlers settings, from the settings form
* @return - the embed code for the video
*/
function video_embed_facebook_handle_video ($url, $settings) {
$id = _video_embed_facebook_get_video_id($url);
if($id) {
//our embed code
$embed = '<object>
<param name="allowfullscreen" value="!fullscreen" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://www.facebook.com/v/!id" />
<param name="wmode" value="opaque" />
<embed src="http://www.facebook.com/v/!id" type="application/x-shockwave-flash" wmode="opaque"
allowscriptaccess="always" allowfullscreen="!fullscreen" width="!width" height="!height">
</embed>
</object>';
//use format_string to replace our placeholders with the values from the settings
$embed = format_string($embed, array(
'!id' => $id,
'!fullscreen' => $settings['allowfullscreen'] ? 'true' : 'false',
'!width' => $settings['width'],
'!height' => $settings['height'],
));
//we want to return a render array
$video = array(
'#markup' => $embed,
);
return $video;
}
// just return an empty string if there is no id, so we don't have broken embeds showing up
return '';
}
/**
* Retreive the thumbnail for the facebook video - note that based on a users permissions, this may be
* the facebook unknown thumbnail: https://s-static.ak.facebook.com/rsrc.php/v1/y0/r/XsEg9L6Ie5_.jpg
* @param $url - the url of the video as entered by the user
* @return an array with the keys:
* 'id' => an id for the video which is unique to your provider, used for naming the cached thumbnail file
* 'url' => the url to retrieve the thumbnail from
*/
function video_embed_facebook_handle_thumbnail ($url) {
$id = _video_embed_facebook_get_video_id($url);
// We're using a part of the graphs api to return the thumbnail. This only works for some videos
return array(
'id' => $id, //generally the id that the provider uses for the video
'url' => 'https://graph.facebook.com/'.$id.'/picture', //the url of the thumbnail
);
}
/**
* Helper function to take a facebook video url and return its id
* @param $url - the full facebook video url
* @return the id for the video
*/
function _video_embed_facebook_get_video_id ($url) {
//parse_url is an easy way to break a url into its components
$matches = array();
preg_match('/(.*)?v=([^&#]*)/', $url, $matches);
//if the v get parameter is set, return it
if ($matches && !empty($matches[2])) {
return $matches[2];
}
//otherwise return false.
return FALSE;
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* Form builder; Form for editing a video style.
* Used by CTools export ui
*
* @ingroup forms
* @see video_embed_field_video_style_form_submit()
*/
function video_embed_field_video_style_form(&$form, &$form_state) {
if(isset($form_state['item'])){
$style = (array) $form_state['item'];
} else {
$style = array();
}
$form_state['video_style'] = $style;
//Grab the settings off the parser form
$values = isset($style['data']) ? $style['data'] : array();
$parser_form = video_embed_field_get_form($values);
//General settings for playback - formerly in the configuration section
$form['data'] = array(
'#type' => 'vertical_tabs',
'#title' => t('Playback settings'),
'#tree' => TRUE,
) + $parser_form; //add in our extra settings
return $form;
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* API Info for video_embed_field module
*/
/**
* @function hook_video_embed_handler_info
* Can be used to add more handlers for video_embed_field
* @return an array of handlers, each handler is an array with the following keys
* 'title' : required, the untranslated title of the provider, to show to the admin user
* 'function' : required, the function used to generate the embed code
* 'thumbnail_function' : optional, the function used to provide the thumbnail for a video
* 'data_function' : optional, the function to return an array of video data.
* 'form' : required, the function that returns the settings form for your provider
* 'domains' : required, an array of domains to match against, this is used to know which provider to use
* 'defaults' : default values for each setting made configurable in your form function
*
* @see below for function definitions
*/
function hook_video_embed_handler_info() {
$handlers = array();
$handlers['ustream'] = array(
'title' => 'UStream',
'function' => 'your_module_handle_ustream',
'thumbnail_function' => 'your_module_handle_ustream_thumbnail',
'data_function' => 'your_module_handler_ustream_data',
'form' => 'your_module_handler_ustream_form',
'domains' => array(
'ustream.com',
),
'defaults' => array(
'width' => 640,
'height' => 360,
),
);
return $handlers;
}
// Example callbacks for a provider (in this case for ustream) - obviously, these functions are only for example
// purposes
/**
* Generate the embed code for a video
* @param $url - the video url as entered by the user
* @param $settings - the settings for this provider as defined in the form function,
* defaulting to your provider's defaults
* @return the embed code as a renderable array
*/
function your_module_handle_ustream($url, $settings) {
return array(
//this should be the full embed code for your provider, including each of the settings
'#markup' => '<iframe src="ustream"></iframe>',
);
}
/**
* Retrieve information about the thumbnail for a given url
* @param $url - the url of the video as entered by the user
* @return an array with the keys:
* 'id' => an id for the video which is unique to your provider, used for naming the cached thumbnail file
* 'url' => the url to retrieve the thumbnail from
*/
function your_module_handle_ustream_thumbnail ($url) {
return array(
'id' => '12332243242', //generally the id that the provider uses for the video
'url' => 'http://something/thumbnail/somthing.jpg', //the url of the thumbnail
);
}
/**
* A forms api callback, returns the settings form for the provider
* @param $defaults - default/current values for your provider, the currently saved settings
* with empty values filled with the defaults provided in info hook
* @return a form as defined by forms api
*
* @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7
*/
function your_module_handler_ustream_form($defaults) {
$form = array();
$form['width'] = array(
'#type' => 'textfield',
'#title' => t('Player Width'),
'#description' => t('The width of the player in pixels'),
'#default_value' => $defaults['width'],
);
return $form;
}
/**
* Return an array of extra data to be stored with the video, this data will be available for theming
* @return an array
*/
function your_module_handler_ustream_data($url) {
return array();
}

View File

@@ -0,0 +1,407 @@
<?php
/**
* @file
* Implement a video field.
*/
/**
* Implements of hook_field_info().
*/
function video_embed_field_field_info() {
return array(
'video_embed_field' => array(
'label' => 'Video Embed',
'description' => 'Embed videos from youtube or vimeo',
'settings' => array(),
'instance_settings' => array(
'description_field' => 0,
),
'default_widget' => 'video_embed_field_video',
'default_formatter' => 'video_embed_field',
)
);
}
/**
* Implements hook_field_instance_settings_form().
*/
function video_embed_field_field_instance_settings_form($field, $instance) {
$settings = $instance['settings'];
$form['description_field'] = array(
'#type' => 'checkbox',
'#title' => t('Enable <em>Description</em> field'),
'#default_value' => isset($settings['description_field']) ? $settings['description_field'] : '',
'#description' => t('The description field allows users to enter a description about the video.'),
'#parents' => array('instance', 'settings', 'description_field'),
'#weight' => 11,
);
return $form;
}
/**
* Implements hook_field_widget_info().
*/
function video_embed_field_field_widget_info() {
return array(
'video_embed_field_video' => array(
'label' => 'Video',
'description' => 'Provides a video embed field',
'field types' => array('video_embed_field'),
'settings' => array(),
'behaviors' => array(
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
'default value' => FIELD_BEHAVIOR_DEFAULT
),
),
);
}
/**
* Implements hook_field_widget_form().
*/
function video_embed_field_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
// Don't need to check the type right now because we're only defining one
$element += array(
'#type' => 'fieldset'
);
$element['video_url'] = array(
'#type' => 'textfield',
'#title' => t('Video URL'),
'#attributes' => array('class' => array('video_embed_url')),
'#attached' => array(
'css' => array(
drupal_get_path('module', 'video_embed_field') .'/video_embed_field.form.css'
)
),
'#default_value' => isset($items[$delta]['video_url'])?$items[$delta]['video_url']:'',
'#required' => $element['#required']
);
// Add the description field if enabled.
if (!empty($instance['settings']['description_field'])) {
$element['description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#default_value' => isset($items[$delta]['description']) ? $items[$delta]['description'] : '',
'#description' => t('The description which may be used as a label.'),
);
}
return $element;
}
/**
* Validates video URL.
*/
function video_embed_field_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
foreach ($items as $delta => $item) {
if (!empty($item['video_url'])) {
$item['video_url'] = trim($item['video_url']);
if (stristr($item['video_url'], '.') && !stristr($item['video_url'], 'http://') && !stristr($item['video_url'], 'https://')) {
$item['video_url'] = 'http://' . $item['video_url'];
}
$parts = parse_url($item['video_url']);
if (!$parts || !isset($parts['host'])) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => t('Invalid Url'),
'message' => t('Video: Invalid Video URL.', array('%name' => $instance['label'])),
);
}
else {
$host = $parts['host'];
if (stripos($host, 'www.') > -1) {
$host = substr($host, 4);
}
$domains = _video_embed_field_get_provider_domains();
if (!array_key_exists($host, $domains)) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => t('Unsupported Video Provider'),
'message' => t('%name: This video provider is not currently supported.', array('%name' => $instance['label'])),
);
}
}
}
}
}
/**
* Implementation of hook_field_prepare_view().
*
* Download and save the thumbnail if it hasn't already been stored.
* Get video data.
*/
function video_embed_field_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
foreach($items as $delta => $item){
// Try to load thumbnail URL
$info = video_embed_field_thumbnail_url($item['video_url']);
if (isset($info['url']) && $info['url']) {
$thumb_url = $info['url'];
$local_path = 'public://video_embed_field_thumbnails/' . $info['handler'] . '/' . $info['id'] . '.jpg';
$dirname = drupal_dirname($local_path);
file_prepare_directory($dirname, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
$response = drupal_http_request($thumb_url);
if (!isset($response->error)) {
file_save_data($response->data, $local_path, TRUE);
}
else{
@copy($thumb_url, $local_path);
}
$items[$delta]['thumbnail_path'] = $local_path;
} //couldn't get the thumbnail for whatever reason
else {
$items[$delta]['thumbnail_path'] = '';
}
// Try to load video data
$data = video_embed_field_get_video_data($item['video_url']);
if (is_array($data) && !empty($data)) {
$items[$delta]['video_data'] = serialize($data);
}
else {
$items[$delta]['video_data'] = NULL;
}
}
}
/**
* Implements of hook_field_is_empty().
*/
function video_embed_field_field_is_empty($item, $field){
return empty($item) || empty($item['video_url']) || $item['video_url'] === '';
}
/**
* Implements hook_field_formatter_info().
*/
function video_embed_field_field_formatter_info() {
$info = array(
'video_embed_field' => array(
'label' => t('Video Player'),
'field types' => array('video_embed_field'),
'settings' => array('video_style' => 'normal', 'description' => 1),
),
'video_embed_field_thumbnail' => array(
'label' => t('Thumbnail Preview'),
'field types' => array('video_embed_field'),
'settings' => array(
'image_style' => 'none',
'description' => 1,
'image_link' => 'none',
),
),
);
if( module_exists('colorbox') ) {
$info['video_embed_field_thumbnail_colorbox'] = array(
'label' => t('Thumbnail Preview w/Colorbox'),
'field types' => array('video_embed_field'),
'settings' => array('video_style' => 'normal', 'image_style' => 'none', 'description' => 1),
);
}
return $info;
}
/**
* Implements hook_field_formatter_settings_form().
*/
function video_embed_field_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
if ($display['type'] == 'video_embed_field' || $display['type'] == 'video_embed_field_thumbnail_colorbox') {
$video_styles = video_embed_field_video_style_options(FALSE);
$element['video_style'] = array(
'#title' => t('Video style'),
'#type' => 'select',
'#default_value' => $settings['video_style'],
'#options' => $video_styles,
);
}
if ($display['type'] == 'video_embed_field_thumbnail' || $display['type'] == 'video_embed_field_thumbnail_colorbox') {
$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)'),
);
}
if($display['type'] == 'video_embed_field_thumbnail'){
$link_types = array(
'node' => t('Node'),
'source' => t('Video Source'),
);
$element['image_link'] = array(
'#title' => t('Link thumbnail to'),
'#type' => 'select',
'#default_value' => $settings['image_link'],
'#empty_option' => t('Nothing'),
'#options' => $link_types,
);
}
if ($instance['settings']['description_field']) {
$element['description'] = array(
'#title' => t('Show description'),
'#type' => 'checkbox',
'#default_value' => $settings['description'],
);
}
return $element;
}
/**
* Implements hook_field_formatter_settings_summary().
*/
function video_embed_field_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$summary = array();
if($display['type'] == 'video_embed_field' || $display['type'] == 'video_embed_field_thumbnail_colorbox'){
$video_styles = video_embed_field_video_style_options(FALSE);
// Styles could be lost because of enabled/disabled modules that defines
// their styles in code.
if (isset($video_styles[$settings['video_style']])) {
$summary[] = t('Video style: @style', array('@style' => $video_styles[$settings['video_style']]));
}
}
if ($display['type'] == 'video_embed_field_thumbnail' || $display['type'] == 'video_embed_field_thumbnail_colorbox') {
$image_styles = image_style_options(FALSE);
if (isset($image_styles[$settings['image_style']])) {
$summary[] = t('Image style: @style', array('@style' => $image_styles[$settings['image_style']]));
} //No Image style (original image)
else {
$summary[] = t('Original Image.');
}
if(isset($settings['image_link'])){
$summary[] = t('Image link: ' . $settings['image_link']);
}
else{
$summary[] = t('Image link: none');
}
}
if ($settings['description'] && $instance['settings']['description_field']) {
$summary[] = t('Show description');
}
else if ($instance['settings']['description_field']) {
$summary[] = t('Hide description');
}
return implode('<br />', $summary);
}
/**
* Implements hook_field_formatter_view().
*/
function video_embed_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display){
$element = array();
foreach ($items as $delta => $item) {
//create the render array for the description
if (isset($item['description']) && $item['description'] && $display['settings']['description'] && $instance['settings']['description_field']) {
$description = array(
'#prefix' => '<div class="video-embed-description">',
'#markup' => $item['description'],
'#suffix' => '</div>',
);
}
else {
$description = array();
}
//Render the field
if ($display['type'] == 'video_embed_field') {
$element[$delta] = array(
array(
'#theme' => 'video_embed_field_embed_code',
'#url' => $item['video_url'],
'#style' => $display['settings']['video_style'],
'#video_data' => !empty($item['video_data']) ? unserialize($item['video_data']) : array(),
),
);
}
else if ($display['type'] == 'video_embed_field_thumbnail') {
if (isset($item['thumbnail_path'])) {
if(empty($display['settings']['image_style']) || $display['settings']['image_style'] == 'none'){
$element[$delta] = array(
array(
'#theme' => 'image',
'#path' => $item['thumbnail_path'],
),
);
}
else {
$element[$delta] = array(
array(
'#theme' => 'image_style',
'#path' => $item['thumbnail_path'],
'#style_name' => $display['settings']['image_style'],
),
);
}
if($display['settings']['image_link'] == 'source'){
$link = explode('|||', l('|||', $item['video_url']));
$element[$delta]['#prefix'] = $link[0];
$element[$delta]['#suffix'] = $link[1];
}
else if($display['settings']['image_link'] == 'node'){
$nid = $entity->nid;
$link = explode('|||', l('|||', 'node/'. $nid));
$element[$delta]['#prefix'] = $link[0];
$element[$delta]['#suffix'] = $link[1];
}
} //incase no thumbnail was downloaded / provider doesn't support thumbnails
else {
$element[$delta] = array(
);
}
}
else if ($display['type'] == 'video_embed_field_thumbnail_colorbox') {
if (isset($item['thumbnail_path'])) {
$element[$delta] = array(
array(
'#theme' => 'video_embed_field_colorbox_code',
'#image_url' => $item['thumbnail_path'],
'#image_style' => $display['settings']['image_style'],
'#video_url' => $item['video_url'],
'#video_style' => $display['settings']['video_style'],
'#video_data' => unserialize($item['video_data']),
),
);
}//incase no thumbnail was downloaded / provider doesn't support thumbnails
else {
$element[$delta] = array(
);
}
}
//Get the HTML instead of the array, because we append it to the suffix.
//This way, the thumbnail link wrapper doesn't make the description a link as well.
$description_html = drupal_render($description);
//No need to check to add, as we set it to blank above if it's set to not display.
//The if/else is so that it doesn't show an error in case there's no suffix.
if(isset($element[$delta]['#suffix'])){
$element[$delta]['#suffix'] .= $description_html;
}
else{
$element[$delta]['#suffix'] = $description_html;
}
}
return $element;
}

View File

@@ -0,0 +1,4 @@
/* Style to make sure the fields are the right way */
table input.fluid.video_embed_url {
width:100%;
}

View File

@@ -0,0 +1,515 @@
<?php
/**
* Provide some handlers for video embed field
* Other modules can implement the hook_video_embed_handler_info to provide more handlers
*/
/**
* Implementation of hook_video_embed_handler_info
*/
function video_embed_field_video_embed_handler_info() {
$handlers = array();
$handlers['youtube'] = array(
'title' => 'Youtube',
'function' => 'video_embed_field_handle_youtube',
'thumbnail_function' => 'video_embed_field_handle_youtube_thumbnail',
'data_function' => 'video_embed_field_handle_youtube_data',
'form' => 'video_embed_field_handler_youtube_form',
'domains' => array(
'youtube.com',
'youtu.be'
),
'defaults' => array(
'width' => '640px',
'height' => '360px',
'autoplay' => 0,
'hd' => 1,
'rel' => 0,
'autohide' => 2,
'showinfo' => 1,
'modestbranding' => 0,
'theme' => 'dark',
'iv_load_policy' => 1,
),
);
$handlers['vimeo'] = array(
'title' => 'Vimeo',
'function' => 'video_embed_field_handle_vimeo',
'thumbnail_function' => 'video_embed_field_handle_vimeo_thumbnail',
'data_function' => 'video_embed_field_handle_vimeo_data',
'form' => 'video_embed_field_handler_vimeo_form',
'domains' => array(
'vimeo.com'
),
'defaults' => array(
'width' => '640px',
'height' => '360px',
'color' => '00adef',
'portrait' => 1,
'title' => 1,
'byline' => 1,
'autoplay' => 0,
'loop' => 0,
),
);
return $handlers;
}
/**
* Helper function to get the youtube video's id
* Returns false if it doesn't parse for wahtever reason
*/
function _video_embed_field_get_youtube_id($url){
// Find the ID of the video they want to play from the url
if (stristr($url, 'http://')) {
$url = substr($url, 7);
}
else if (stristr($url, 'https://')) {
$url = substr($url, 8);
}
if(stristr($url, 'playlist')){
//Playlists need the appended ampersand to take the options properly.
$url = $url . '&';
$pos = strripos($url, '?list=');
if($pos!==FALSE){
$pos2 = stripos($url, '&');
$pos2++;
}
else{
return FALSE;
}
}
//Alternate playlist link
else if(stristr($url, 'view_play_list')){
$url = $url . '&';
//All playlist ID's are prepended with PL. view_play_list links allow you to not have that, though.
if(!stristr($url, '?p=PL')){
$url = substr_replace($url, 'PL', strpos($url, '?p=') + 3, 0);
}
//Replace the links format with the embed format
$url = str_ireplace('play_list?p=', 'videoseries?list=', $url);
$pos = strripos($url, 'videoseries?list=');
if($pos !== FALSE){
$pos2 = stripos($url, '&');
$pos2++;
}
else{
return FALSE;
}
}
else{
$pos = strripos($url, 'v=');
if ($pos!== FALSE) {
$pos += 2;
$pos2 = stripos($url, '&', $pos);
$pos_hash = stripos($url, '#', $pos);
$pos2 = _video_embed_get_min($pos2, $pos_hash);
}
else {
$pos = strripos($url, '/');
if ($pos !== FALSE) {
$pos++;
$pos2 = stripos($url, '?', $pos);
$pos_hash = stripos($url, '#', $pos);
$pos2 = _video_embed_get_min($pos2, $pos_hash);
}
}
}
if ($pos === FALSE) {
return FALSE;
}
else {
if ($pos2 > 0) {
$id = substr($url, $pos, $pos2 - $pos);
}
else {
$id = substr($url, $pos);
}
}
return $id;
}
/**
* Handler for Youtube videos.
*/
function video_embed_field_handle_youtube($url, $settings) {
$output = array();
//Grab the minutes and seconds, and just convert it down to seconds
preg_match('/#t=((?P<min>\d+)m)?((?P<sec>\d+)s)?/', $url, $matches);
//Give it some default data in case there is no #t=...
$matches += array(
"min" => 0,
"sec" => 0,
);
$time = ($matches["min"] * 60) + $matches["sec"];
$settings['start'] = $time;
$id = _video_embed_field_get_youtube_id($url);
if (!$id) {
// We can't decode the URL - just return the URL as a link
$output['#markup'] = l($url, $url);
return $output;
}
// Construct the embed code
$settings['wmode'] = 'opaque';
$settings_str = _video_embed_code_get_settings_str($settings);
$output['#markup'] = '<iframe width="' . $settings['width'] . '" height="' . $settings['height'] . '" src="//www.youtube.com/embed/' . $id . '?' . $settings_str . '" frameborder="0" allowfullscreen></iframe>';
return $output;
}
/**
* Get the thumbnail url for youtube videos
*/
function video_embed_field_handle_youtube_thumbnail($video_url){
$info = array();
$id = _video_embed_field_get_youtube_id($video_url);
//Playlist
if(stristr($id, '?list=')){
//Strip out all but the ID, including the PL behind the ID.
$start = strpos($id, '?list=PL') + 8;
$length = strpos($id, '&') - $start;
$id = substr($id, $start, $length);
$info['id'] = $id;
//Playlist info is stored in XML. The thumbnail is in there.
$xml = drupal_http_request('http://gdata.youtube.com/feeds/api/playlists/' . $id);
if(!isset($xml->error)){
$xml = new SimpleXMLElement($xml->data);
$media = $xml->children('http://search.yahoo.com/mrss/');
if($media->group->thumbnail && $media->group->thumbnail[0]->attributes()){
$attrs = $media->group->thumbnail[0]->attributes();
$info['url'] = (string)$attrs['url'];
}
}
}
//Regular video
else if($id) {
$info['id'] = $id;
$info['url'] = 'http://img.youtube.com/vi/'.$id.'/0.jpg';
}
return $info;
}
/**
* Get video data for a YouTube video URL
*
* @param string $url
* A YouTube video URL to get data for
*
* @return array|false $data
* An array of video data, or FALSE if unable to fetch data
*/
function video_embed_field_handle_youtube_data($url) {
$data = array();
// Get YouTube video ID from URL
$id = _video_embed_field_get_youtube_id($url);
if ($id) {
$response = drupal_http_request('http://gdata.youtube.com/feeds/api/videos/' . $id . '?v=2&alt=json');
if (!isset($response->error)) {
$data = json_decode($response->data);
$data = (array) $data->entry;
return _video_embed_field_clean_up_youtube_data($data);
}
}
return FALSE;
}
/**
* Flatten out some unnecessary nesting in the youtube data
*/
function _video_embed_field_clean_up_youtube_data($data) {
//make things a bit nicer for people trying to use the data
foreach ($data as $key => $value) {
if (is_object($value)) {
$temp = (array)$value;
if (isset($temp['$t'])) {
$data[$key] = $temp['$t'];
} else {
$data[$key] = _video_embed_field_clean_up_youtube_data($temp);
}
} else if (is_array($value)) {
$data[$key] = _video_embed_field_clean_up_youtube_data($value);
}
if($key === 'category') {
$terms = array();
foreach ($data[$key] as $value) {
if(isset($value['scheme']) && $value['scheme'] == 'http://schemas.google.com/g/2005#kind') {
continue;
}
if(isset($value['term'])) {
$terms[] = $value['term'];
}
}
$data['terms'] = $terms;
}
}
return $data;
}
/**
* Defines the form elements for the Youtube configuration form.
*/
function video_embed_field_handler_youtube_form($defaults) {
$form = array();
$form['width'] = array(
'#type' => 'textfield',
'#size' => '5',
'#title' => t('Player Width'),
'#description' => t('The width of the youtube player.'),
'#default_value' => $defaults['width'],
);
$form['height'] = array(
'#type' => 'textfield',
'#size' => '5',
'#title' => t('Player Height'),
'#description' => t('The height of the youtube player.'),
'#default_value' => $defaults['height'],
);
$form['theme'] = array(
'#type' => 'select',
'#options' => array(
'dark' => t('Dark'),
'light' => t('Light'),
),
'#title' => t('Player theme'),
'#default_value' => $defaults['theme'],
);
$form['autoplay'] = array(
'#type' => 'checkbox',
'#title' => t('Autoplay'),
'#description' => t('Play the video immediately.'),
'#default_value' => $defaults['autoplay'],
);
$form['hd'] = array(
'#type' => 'checkbox',
'#title' => t('Use HD'),
'#description' => t('Attempt to play the video in HD if available.'),
'#default_value' => $defaults['hd'],
);
$form['rel'] = array(
'#type' => 'checkbox',
'#title' => t('Show related videos'),
'#description' => t('Show related videos after the video is finished playing.'),
'#default_value' => $defaults['rel'],
);
$form['showinfo'] = array(
'#type' => 'checkbox',
'#title' => t('Show info'),
'#description' => t('Display information like the video title and rating before the video starts playing.'),
'#default_value' => $defaults['showinfo'],
);
$form['modestbranding'] = array(
'#type' => 'checkbox',
'#title' => t('Hide Youtube logo'),
'#description' => t('Hide the Youtube logo button on the player'),
'#default_value' => $defaults['modestbranding']
);
$form['iv_load_policy'] = array(
'#type' => 'radios',
'#options' => array(
1 => t('Show video annotations.'),
3 => t('Hide video annotations.'),
),
'#title' => t('Display annotations'),
'#description' => t('Controls the display of annotations over the video content. Only works when using the flash player.'),
'#default_value' => $defaults['iv_load_policy'],
);
$form['autohide'] = array(
'#type' => 'radios',
'#options' => array(
0 => t('The video progress bar and player controls will be visible throughout the video.'),
1 => t('Automatically slide the video progress bar and the player controls out of view a couple of seconds after the video starts playing. They will only reappear if the user moves her mouse over the video player or presses a keyboard key.'),
2 => t('The video progress bar will fade out but the player controls (play button, volume control, etc.) remain visible.'),
),
'#title' => t('Autohide progress bar and the player controls'),
'#description' => t('Controls the autohide behavior of the youtube player controls.'),
'#default_value' => $defaults['autohide'],
);
return $form;
}
/**
* Helper function to get the Vimeo video's ID
*
* @param string $url
* A Vimeo video URL to get the ID of
*
* @return integer|false $id
* The video ID, or FALSE if unable to get the video ID
*/
function _video_embed_field_get_vimeo_id($url){
$pos = strripos($url, '/');
if ($pos != FALSE) {
$pos += 1;
return (int) substr($url, $pos);
}
return FALSE;
}
/**
* Handler for Vimeo videos.
*/
function video_embed_field_handle_vimeo($url, $settings) {
// Get ID of video from URL
$id = _video_embed_field_get_vimeo_id($url);
if (!$id) {
return array(
'#markup' => l($url, $url),
);
}
// Construct the embed code
$settings['portrait'] = 0;
$settings_str = _video_embed_code_get_settings_str($settings);
return array(
'#markup' => '<iframe width="' . $settings['width'] . '" height="' . $settings['height'] . '" src="//player.vimeo.com/video/' . $id .
'?' . $settings_str . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>',
);
}
/**
* Get the thumbnail url for youtube videos
*/
function video_embed_field_handle_vimeo_thumbnail($url){
// Get ID of video from URL
$id = _video_embed_field_get_vimeo_id($url);
$info = array(
'id' => $id,
);
$response = drupal_http_request('http://vimeo.com/api/v2/video/' . $id . '.php');
if (!isset($response->error)) {
$response = unserialize($response->data);
$video = current($response);
$image_url = $video['thumbnail_large'];
$info['url'] = $image_url;
}
return $info;
}
/**
* Get video data for a Vimeo video URL
*
* @param string $url
* A Vimeo video URL to get data for
*
* @return array|false $data
* An array of video data, or FALSE if unable to fetch data
*/
function video_embed_field_handle_vimeo_data($url) {
// Get ID of video from URL
$id = _video_embed_field_get_vimeo_id($url);
if ($id) {
$response = drupal_http_request('http://vimeo.com/api/v2/video/' . $id . '.php');
if (!isset($response->error)) {
$response = unserialize($response->data);
return (array) current($response);
}
}
return FALSE;
}
/**
* Defines the form elements for the Vimeo configuration form.
*/
function video_embed_field_handler_vimeo_form($defaults) {
$form = array();
$form['width'] = array(
'#type' => 'textfield',
'#size' => '5',
'#title' => t('Player Width'),
'#description' => t('The width of the vimeo player.'),
'#default_value' => $defaults['width'],
);
$form['height'] = array(
'#type' => 'textfield',
'#size' => '5',
'#title' => t('Player Height'),
'#description' => t('The height of the vimeo player.'),
'#default_value' => $defaults['height'],
);
$form['color'] = array(
'#type' => 'select',
'#options' => array(
'00adef' => t('Blue'),
'ff9933' => t('Orange'),
'c9ff23' => t('Lime'),
'ff0179' => t('Fuschia'),
'ffffff' => t('White')
),
'#title' => t('Player Color'),
'#description' => t('The color to use on the vimeo player.'),
'#default_value' => $defaults['color'],
);
$form['portrait'] = array(
'#type' => 'checkbox',
'#title' => t('Overlay Author Thumbnail'),
'#description' => t('Overlay the author\'s thumbnail before the video is played.'),
'#default_value' => $defaults['portrait'],
);
$form['title'] = array(
'#type' => 'checkbox',
'#title' => t('Overlay Video\'s Title'),
'#description' => t('Overlay the video\'s title before the video is played.'),
'#default_value' => $defaults['title'],
);
$form['byline'] = array(
'#type' => 'checkbox',
'#title' => t('Overlay Video\'s Byline'),
'#description' => t('Overlay the video\'s description before the video is played.'),
'#default_value' => $defaults['byline'],
);
$form['overridable'] = array (
'#prefix' => '<p class="note"><strong>'.t('Note').': </strong><em>',
'#markup' => t('Color, portrait, title and byline can be restricted by Vimeo Plus videos.
Such videos will ignore these settings.'),
'#suffix' => '</em></p>',
);
$form['autoplay'] = array(
'#type' => 'checkbox',
'#title' => t('Autoplay'),
'#description' => t('Play the video immediately.'),
'#default_value' => $defaults['autoplay'],
);
$form['loop'] = array(
'#type' => 'checkbox',
'#title' => t('Loop'),
'#description' => t('Loop the video\'s playback'),
'#default_value' => $defaults['loop'],
);
return $form;
}
/**
* Calculate the min index for use in finding the id of a youtube video
*/
function _video_embed_get_min($pos1, $pos2) {
if(!$pos1) {
return $pos2;
} else if(!$pos2) {
return $pos1;
} else {
return min($pos1, $pos2);
}
}

View File

@@ -0,0 +1,14 @@
name = "Video Embed Field"
description = "Expose a field type for embedding videos from youtube or vimeo."
core = 7.x
package = Media
configure = admin/config/media/vef_video_styles
dependencies[] = ctools
dependencies[] = image
; Information added by drupal.org packaging script on 2012-06-21
version = "7.x-2.0-beta5"
core = "7.x"
project = "video_embed_field"
datestamp = "1340317020"

View File

@@ -0,0 +1,238 @@
<?php
/**
* Install file for video_embed_field module
* @author jcaldwell
*/
/**
* Implements hook_field_schema().
*/
function video_embed_field_field_schema($field){
switch($field['type']){
case 'video_embed_field' :
$columns = array(
'video_url' => array(
'type' => 'varchar',
'length' => 512,
'default' => '',
),
'thumbnail_path' => array(
'type' => 'varchar',
'length' => 512,
'default' => '',
),
'video_data' => array(
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
),
'embed_code' => array(
'type' => 'varchar',
'length' => 1024,
'default' => '',
),
'description' => array(
'type' => 'text',
'not null' => FALSE,
),
);
$indexes = array();
break;
}
return array(
'columns' => $columns,
'indexes' => $indexes
);
}
/**
* Implements hook_schema().
*/
function video_embed_field_schema(){
$schema['vef_video_styles'] = array(
'description' => 'Stores video embed styles.',
'export' => array(
'key' => 'name',
'primary key' => 'vsid',
'identifier' => 'video_embed_style', // Exports will be as $video_style
'default hook' => 'default_video_embed_styles', // Function hook name.
'api' => array(
'owner' => 'video_embed_field',
'api' => 'default_video_embed_styles', // Base name for api include files.
'minimum_version' => 1,
'current_version' => 1,
),
),
'fields' => array(
'vsid' => array(
'description' => 'The primary identifier for a video style.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'no export' => TRUE,
),
'name' => array(
'description' => 'The style name.',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'data' => array(
'description' => 'The configuration data for the style.',
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
),
),
'primary key' => array('vsid'),
'unique keys' => array(
'name' => array('name')
),
);
return $schema;
}
/**
* Implements hook_uninstall().
*/
function video_embed_field_uninstall(){
//do nothing right now - should eventually remove all the variables
}
/**
* Update 7000
* Add an optional description form
*/
function video_embed_field_update_7000() {
// Get the list of fields of type 'video_embed_field'.
$video_embed_fields = array();
foreach (field_info_fields() as $field_name => $field_info) {
if ($field_info['type'] == 'video_embed_field') {
$video_embed_fields[$field_name] = field_read_field($field_name);
}
}
foreach ($video_embed_fields as $field) {
if ($field['deleted']) {
$table = "field_deleted_data_{$field['id']}";
$revision_table = "field_deleted_revision_{$field['id']}";
}
else {
$table = "field_data_{$field['field_name']}";
$revision_table = "field_revision_{$field['field_name']}";
}
$column = $field['field_name'] . '_' . 'description';
db_add_field($table, $column, array('type' => 'text', 'not null' => FALSE));
db_add_field($revision_table, $column, array('type' => 'text', 'not null' => FALSE));
}
return t('Additional columns added.');
}
/**
* Update 7001
* Add video style storage table
*/
function video_embed_field_update_7001() {
if (!db_table_exists('vef_video_styles')) {
$schema = video_embed_field_schema();
db_create_table('vef_video_styles', $schema['vef_video_styles']);
}
return t('Video styles storage table created.');
}
/**
* Update 7002
* Add field for storing the path to the video thumbnail
*/
function video_embed_field_update_7002() {
// Get the list of fields of type 'video_embed_field'.
$video_embed_fields = array();
foreach (field_info_fields() as $field_name => $field_info) {
if ($field_info['type'] == 'video_embed_field') {
$video_embed_fields[$field_name] = field_read_field($field_name);
}
}
foreach ($video_embed_fields as $field) {
if ($field['deleted']) {
$table = "field_deleted_data_{$field['id']}";
$revision_table = "field_deleted_revision_{$field['id']}";
}
else {
$table = "field_data_{$field['field_name']}";
$revision_table = "field_revision_{$field['field_name']}";
}
$column = $field['field_name'] . '_' . 'thumbnail_path';
db_add_field($table, $column, array(
'type' => 'varchar',
'length' => 512,
'default' => ''
));
db_add_field($revision_table, $column, array(
'type' => 'varchar',
'length' => 512,
'default' => ''
));
}
return t('Thumbnail column added.');
}
/**
* Enable inline colorbox support if colorbox is installed [NO LONGER NEEDED - This update hook does nothing]
*/
function video_embed_field_update_7003() {
//this is no longer needed
//variable_set('colorbox_inline', 1);
}
/**
* Enable colorbox load support if colorbox is installed, we no longer need inline support
*/
function video_embed_field_update_7004() {
variable_set('colorbox_load', 1);
}
/**
* Add data column to field database.
*/
function video_embed_field_update_7005() {
// Get the list of fields of type 'video_embed_field'.
$video_embed_fields = array();
foreach (field_info_fields() as $field_name => $field_info) {
if ($field_info['type'] == 'video_embed_field') {
$video_embed_fields[$field_name] = field_read_field($field_name);
}
}
foreach ($video_embed_fields as $field) {
if ($field['deleted']) {
$table = "field_deleted_data_{$field['id']}";
$revision_table = "field_deleted_revision_{$field['id']}";
}
else {
$table = "field_data_{$field['field_name']}";
$revision_table = "field_revision_{$field['field_name']}";
}
$column = $field['field_name'] . '_' . 'video_data';
db_add_field($table, $column, array(
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE
));
db_add_field($revision_table, $column, array(
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE
));
}
return t('Data column added. Please clear cache.');
}

View File

@@ -0,0 +1,558 @@
<?php
/**
* Provides a simple field for easily embedding videos from youtube or vimeo
*
* This module is not intended to replace media or video - it does not allow for any local storage of videos, custom players or anything else
* It simply allows users to embed videos from youtube and vimeo - and provides a hook to allow other modules to provide more providers.
*
* Uses CTools Export UI to manage settings. @see ./plugins/export_ui/video_embed_field_export_ui.inc
*
* @author jec006, jdelaune
*/
// Load all Field module hooks.
module_load_include('inc', 'video_embed_field', 'video_embed_field.field');
// Load the admin forms
module_load_include('inc', 'video_embed_field', 'video_embed_field.admin');
// Load our default handlers
module_load_include('inc', 'video_embed_field', 'video_embed_field.handlers');
/**
* Implementation of hook_ctools_plugin_directory().
*/
function video_embed_field_ctools_plugin_directory($module, $type) {
// Load the export_ui plugin.
if ($type =='export_ui') {
return 'plugins/export_ui';
}
}
/**
* Implementation of hook_ctools_plugin_api().
*
* Tell CTools that we support the default_mymodule_presets API.
*/
function video_embed_field_ctools_plugin_api($owner, $api) {
if ($owner == 'video_embed_field' && $api == 'default_video_embed_styles') {
return array('version' => 1);
}
}
/**
* Implements hook_default_video_styles().
*/
function video_embed_field_default_video_embed_styles() {
$styles = array();
$handlers = video_embed_get_handlers();
//create the normal handler
$normal = new stdClass;
$normal->disabled = FALSE; /* Edit this to true to make a default video_embed_style disabled initially */
$normal->api_version = 1;
$normal->name = 'normal';
$normal->data = array();
$teaser = new stdClass;
$teaser->disabled = FALSE; /* Edit this to true to make a default video_embed_style disabled initially */
$teaser->api_version = 1;
$teaser->name = 'teaser';
$teaser->data = array();
//add in our settings for each of the handlers
foreach ($handlers as $name => $handler) {
$normal->data[$name] = $handler['defaults'];
$teaser->data[$name] = $handler['defaults'];
$teaser->data[$name]['width'] = 480;
$teaser->data[$name]['height'] = 270;
}
return array($normal, $teaser);
}
/**
* Implements hook_menu().
*/
function video_embed_field_menu() {
$items = array();
$items['vef/load/%'] = array(
'title' => 'Video Embed Field - Load Video',
'page callback' => '_video_embed_field_show_video',
'page arguments' => array(2),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Get an array of all styles and their settings.
*
* @return
* An array of styles keyed by the video style ID (vsid).
* @see video_embed_field_video_style_load()
*/
function video_embed_field_video_styles() {
$styles = &drupal_static(__FUNCTION__);
// Grab from cache or build the array.
if (!isset($styles)) {
// load the style via ctools - which will handle all the caching for us -
// however, because it does a bit more logic, lets still statically cache this function
ctools_include('export');
$styles = ctools_export_load_object('vef_video_styles');
}
return $styles;
}
/**
* Load a style by style name or ID. May be used as a loader for menu items.
*
* Note that you may also use ctools_export_load_object with the key being vef_video_styles
*
* @param $name
* The name of the style.
* @param $isid
* Optional. The numeric id of a style if the name is not known.
* @return
* An video style array containing the following keys:
* - "vsid": The unique image style ID.
* - "name": The unique image style name.
* - "data": An array of video settings within this video style.
* If the video style name or ID is not valid, an empty array is returned.
*/
function video_embed_field_video_style_load($name = NULL, $vsid = NULL) {
$styles = video_embed_field_video_styles();
// If retrieving by name.
if (isset($name) && isset($styles[$name])) {
$style = $styles[$name];
} // If retrieving by image style id.
else if (!isset($name) && isset($vsid)) {
foreach ($styles as $name => $database_style) {
if (isset($database_style['vsid']) && $database_style['vsid'] == $vsid) {
$style = $database_style;
break;
}
}
}
//if we found a style return it
if (isset($style)) {
return $style;
}
// Otherwise the style was not found.
return FALSE;
}
/**
* Implements hook_permission().
*/
function video_embed_field_permission() {
return array(
'administer video styles' => array(
'title' => t('Administer video styles'),
'description' => t('Create and modify styles for embedded videos.'),
),
);
}
/**
* Implements hook_theme().
*/
function video_embed_field_theme() {
return array(
// Theme functions in video_embed_field.admin.inc.
'video_embed_field_video_style_list' => array(
'variables' => array('styles' => NULL),
),
'video_embed_field_embed_code' => array(
'template' => 'video-embed-field-embed-code',
'variables' => array('url' => NULL, 'style' => 'normal', 'video_data' => array()),
),
'video_embed_field_colorbox_code' => array(
'variables' => array('image_url' => NULL, 'image_style' => 'normal', 'video_url' => NULL, 'video_style' => NULL, 'video_data' => array()),
),
);
}
/**
* Creates a hook that other modules can implement to get handlers - hook_video_embed_handler_info
* Can be used to add more handlers if needed - from other modules and such
* @see video_embed_field.api.php for more information
*/
function video_embed_get_handlers() {
$handlers = cache_get('video_embed_field_handlers');
if ($handlers === FALSE) {
$handlers = module_invoke_all('video_embed_handler_info');
drupal_alter('video_embed_field_handlers', $handlers);
cache_set('video_embed_field_handlers', $handlers);
}
else {
$handlers = $handlers->data;
}
return $handlers;
}
function video_embed_get_handler($url){
// Process video URL
if (!stristr($url, 'http://') && !stristr($url, 'https://')) {
$url = 'http://' . $url;
}
$parts = parse_url($url);
if (!isset($parts['host'])) {
return FALSE;
}
$host = $parts['host'];
if (stripos($host, 'www.') > -1) {
$host = substr($host, 4);
}
$domains = _video_embed_field_get_provider_domains();
$handlers = video_embed_get_handlers();
if (isset($domains[$host])) {
$handler_name = $domains[$host];
$handler = $handlers[$handler_name];
$handler['name'] = $handler_name;
return $handler;
} else {
return FALSE;
}
}
/**
* Create a form from the player configuration options
* $defaults will be passed in with the default settings for the various fields
*/
function video_embed_field_get_form($defaults) {
$form = array();
$handlers = video_embed_get_handlers();
foreach ($handlers as $name => $handler) {
if (isset($handler['form']) && function_exists($handler['form'])) {
$handler_defaults = isset($defaults[$name]) ? $defaults[$name] : array();
$handler_defaults = array_merge($handler['defaults'], $handler_defaults);
$form[$name] = call_user_func($handler['form'], $handler_defaults);
$form[$name] += array(
'#type' => 'fieldset',
'#title' => t($handler['title']),
'#tree' => TRUE,
);
}
}
return $form;
}
/**
* Get an array of image styles suitable for using as select list options.
*
* @param $include_empty
* If TRUE a <none> option will be inserted in the options array.
* @return
* Array of image styles both key and value are set to style name.
*/
function video_embed_field_video_style_options($include_empty = TRUE) {
$styles = video_embed_field_video_styles();
$options = array();
if ($include_empty && !empty($styles)) {
$options[''] = t('<none>');
}
$options = array_merge($options, drupal_map_assoc(array_keys($styles)));
if (empty($options)) {
$options[''] = t('No defined styles');
}
return $options;
}
/**
* Implements hook_filter_info().
*/
function video_embed_field_filter_info() {
$filters['video_embed_field'] = array(
'title' => t('Video Embedding'),
'description' => t('Replaces [VIDEO::http://www.youtube.com/watch?v=someVideoID::aVideoStyle] tags with embedded videos.'),
'process callback' => 'video_embed_field_filter_process',
);
return $filters;
}
/**
* Video Embed Field filter process callback.
*/
function video_embed_field_filter_process($text, $filter, $format) {
preg_match_all('/ \[VIDEO:: ( [^\[\]]+ )* \] /x', $text, $matches);
$tag_match = (array) array_unique($matches[1]);
$handlers = video_embed_get_handlers();
foreach ($tag_match as $tag) {
$parts = explode('::', $tag);
// Get video style
if (isset($parts[1])) {
$style = $parts[1];
}
else {
$style = 'normal';
}
$embed_code = theme('video_embed_field_embed_code', array('url' => $parts[0], 'style' => $style));
$text = str_replace('[VIDEO::' . $tag . ']', $embed_code, $text);
}
return $text;
}
/**
* Process variables to format a video player.
*
* $variables contains the following information:
* - $url
* - $style
* - $video_data
*
* @see video-embed.tpl.php
*/
function template_preprocess_video_embed_field_embed_code(&$variables) {
// Get the handler
$handler = video_embed_get_handler($variables['url']);
$variables['handler'] = $handler['name'];
// Load the style
$style = video_embed_field_video_style_load($variables['style']);
// If there was an issue load in the default style
if ($style == FALSE) {
$style = video_embed_field_video_style_load('normal');
}
if (isset($style->data[$variables['handler']])) {
$variables['style_settings'] = $style->data[$variables['handler']];
} //safety valve for when we add new handlers and there are styles in the database.
else {
$variables['style_settings'] = $handler['defaults'];
}
// Prepare the URL
if (!stristr($variables['url'], 'http://') && !stristr($variables['url'], 'https://')) {
$variables['url'] = 'http://' . $variables['url'];
}
// Prepare embed code
if ($handler && isset($handler['function']) && function_exists($handler['function'])) {
$variables['embed_code'] = drupal_render(call_user_func($handler['function'], $variables['url'], $variables['style_settings']));
}
else {
$variables['embed_code'] = l($variables['url'], $variables['url']);
}
// Prepare video data
$variables['data'] = $variables['video_data'];
unset($variables['video_data']);
}
/**
* Returns image style image with a link to
* an embedded video in colorbox.
*
* @param $variables
* An associative array containing:
* - image_url: The image URL.
* - image_style: The image style to use.
* - video_url: The video URL.
* - video_style: The video style to use.
* - video_data: An array of data about the video.
*
* @ingroup themeable
*/
function theme_video_embed_field_colorbox_code($variables) {
$style = video_embed_field_video_style_load($variables['video_style']);
// If there was an issue load in the default style
if ($style == FALSE) {
$style = video_embed_field_video_style_load('normal');
}
$handler = video_embed_get_handler($variables['video_url']);
$data = $style->data[$handler['name']];
//Create a unique ID for colorbox inline
$id = uniqid('video_embed_field-' . rand());
if($variables['image_style'] == 'none'){
$image = array(
array(
'#theme' => 'image',
'#path' => $variables['image_url'],
),
);
}
else {
$image = array(
'#theme' => 'image_style',
'#path' => $variables['image_url'],
'#style_name' => $variables['image_style'],
);
}
$image = drupal_render($image);
// Write values for later AJAX load
$hash = _video_embed_field_store_video($variables['video_url'], $variables['video_style']);
$output = l($image, base_path() . '?q=vef/load/' . $hash . '&width=' . ($data['width']) . '&height=' . ($data['height']+3), array('html' => true, 'external' => true, 'attributes' => array('class' => array('colorbox-load'))));
return $output;
}
/**
* Get the thumbnail url for a given video url
* @param $url - the url of the video
* @return a string representing the url of the thumbnail, or FALSE on error
*/
function video_embed_field_thumbnail_url($url){
$handler = video_embed_get_handler($url);
if ($handler && isset($handler['thumbnail_function']) && function_exists($handler['thumbnail_function'])) {
$info = call_user_func($handler['thumbnail_function'], $url);
$info['handler'] = $handler['name'];
return $info;
}
return FALSE;
}
/**
* Get a video data array for a given video url
*
* @param string $url
* A video URL of the data array you want returned
*
* @return array|false $data
* An array of video data, or FALSE on error
*/
function video_embed_field_get_video_data($url) {
$handler = video_embed_get_handler($url);
if ($handler && isset($handler['data_function']) && function_exists($handler['data_function'])) {
$data = call_user_func($handler['data_function'], $url);
$data['handler'] = $handler['name'];
return $data;
}
return FALSE;
}
/**
* Fetch all available provider domains.
*/
function _video_embed_field_get_provider_domains() {
$domains = array();
$handlers = video_embed_get_handlers();
foreach ($handlers as $name => $handler) {
if (isset($handler['function']) && function_exists($handler['function'])) {
foreach ($handler['domains'] as $domain) {
$domains[$domain] = $name;
}
}
}
return $domains;
}
/**
* Fetch settings string
*/
function _video_embed_code_get_settings_str($settings = array()) {
$values = array();
foreach ($settings as $name => $value) {
$values[] = $name . '=' . $value;
}
return implode('&amp;', $values);
}
//used to array filter in video_embed_field_requirements
function _video_embed_field_array_filter($item) {
return (isset($item['type']) && $item['type'] == 'video_embed_field');
}
/**
* Store a video to be loaded later from an _video_embed_field_load_video
*/
function _video_embed_field_store_video($video_url, $video_style) {
//create a hash key
$hash = _video_embed_field_hash($video_url, $video_style);
//check that is record doesn't already exist before saving it
if(!_video_embed_field_load_video($hash)){
$record = array(
'vhash' => $hash,
'video_url' => $video_url,
'video_style' => $video_style,
);
cache_set('vef-store-'.$hash, $record);
//add it to our static cache so we won't have to go to the database
$static_cache = &drupal_static('vef_video_store', array());
$static_cache[$hash] = $record;
}
return $hash;
}
/**
* Callback to render a video for an Ajax call
*/
function _video_embed_field_show_video($hash){
$data = _video_embed_field_load_video($hash);
$video = array(
'#theme' => 'video_embed_field_embed_code',
'#style' => $data['video_style'],
'#url' => $data['video_url'],
);
print drupal_render($video);
return NULL;
}
/**
* Loads a video from the video store given its hash
* Returns either the data - an array with hash, video_url and video_style keys
*/
function _video_embed_field_load_video($hash) {
$static_cache = &drupal_static('vef_video_store', array());
//check if we've already loaded it
if (isset($static_cache[$hash])) {
return $static_cache[$hash];
} else {
$result = cache_get('vef-store-'.$hash);
if ($result) {
//cache it before returning
$data = $result->data;
$static_cache[$hash] = $data;
return $data;
} else {
return FALSE;
}
}
}
/**
* Creates a hash for storing or looking up a video in the store table
*/
function _video_embed_field_hash($video_url, $video_style){
return md5('vef' . $video_url . $video_style);
}