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,57 @@
Insert is a utility that makes inserting images and links to files into text
areas or WYSIWYGs much easier. It adds a simple JavaScript-based button to
File and Image fields. Images may be inserted into text areas with a specific
Image style.
Insert was written by Nate Haug.
This Module Made by Robots: http://www.lullabot.com
Dependencies
------------
Insert module does not have any dependencies, but it won't do anything unless
you have at least one File or Image field configured on your site. Both of
these fields are provided by Drupal core.
Recommended
-----------
* WYSIWYG module
Install
-------
1) Copy the insert folder to the modules folder in your installation. Usually
this is sites/all/modules.
2) In your Drupal site, enable the module under Administer -> Modules
(/admin/modules).
3) Add or configure a File or Image field under Administer -> Structure ->
Content types -> [type] -> Manage Fields
(admin/structure/types/manage/[type]/fields). Once configuring a field,
there is a new section in the Field options for "Insert". You can then
configure the field to include an Insert button and what templates you would
like to have.
4) Create a piece of content with the configured field. After uploading a file,
an "Insert" button will appear. Click this button to send the file or image
into the Body field.
Insert should work on multiple fields (the last field that was active will
receive the file), and with most popular WYSIWYG editors.
Theming
-------
Insert can be configured to work with non-HTML filters like BBCode or Markdown.
To do this, copy the template file you would like to change from the "templates"
directory to your active theme's directory. Then empty your Drupal caches at
admin/config/development/performance.
The Image templates may also be used per Image style. You can copy the
image-insert-image.tpl.php file to your theme directory and then rename it to
image-insert-image--[style-name].tpl.php, where [style-name] is the name of the
Image style. Change underscores to hyphens in the style name.

View File

@@ -0,0 +1,21 @@
<?php
/**
* @file
* Insert support for File module.
*/
/**
* Implementation of hook_insert_widgets().
*/
function file_insert_widgets() {
return array(
'file_generic' => array(
'element_type' => 'managed_file',
'wrapper' => '.file-widget',
'fields' => array(
'description' => 'input[name$="[description]"]',
),
),
);
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* @file
* Insert support for ImageField module.
*/
/**
* Implementation of hook_insert_widgets().
*/
function image_insert_widgets() {
return array(
'image_image' => array(
'element_type' => 'managed_file',
'wrapper' => '.image-widget',
'fields' => array(
'alt' => 'input[name$="[alt]"], textarea[name$="[alt]"]',
'title' => 'input[name$="[title]"], textarea[name$="[title]"]',
'description' => 'input[name$="[description]"], textarea[name$="[description]"]',
),
),
);
}
/**
* Implementation of hook_insert_styles().
*/
function image_insert_styles() {
$image_styles = image_styles();
$insert_styles = array();
foreach ($image_styles as $style) {
$insert_styles['image_' . $style['name']] = array(
'label' => t($style['name']),
);
}
return $insert_styles;
}
/**
* Implementation of hook_insert_content().
*/
function image_insert_content($item, $style, $widget) {
$style_name = preg_replace('/^image_/', '', $style['name']);
return theme(array('image_insert_image__' . str_replace('-', '_', $style_name), 'image_insert_image'), array('item' => $item, 'widget' => $widget, 'style_name' => $style_name));
}
/**
* Theme the content that will be inserted for Image styles.
*/
function template_preprocess_image_insert_image(&$vars) {
$vars['file'] = file_load($vars['item']['fid']);
// Determine dimensions of the image after the image style transformations.
$image_info = @image_get_info($vars['file']->uri);
$vars['width'] = isset($image_info['width']) ? $image_info['width'] : NULL;
$vars['height'] = isset($image_info['height']) ? $image_info['height'] : NULL;
image_style_transform_dimensions($vars['style_name'], $vars);
$vars['uri'] = image_style_path($vars['style_name'], $vars['file']->uri);
$absolute = isset($vars['widget']['settings']['insert_absolute']) ? $vars['widget']['settings']['insert_absolute'] : NULL;
$vars['url'] = insert_create_url($vars['uri'], $absolute, variable_get('clean_url'));
// http://drupal.org/node/1923336
if (function_exists('image_style_path_token')) {
$token_query = array(IMAGE_DERIVATIVE_TOKEN => image_style_path_token($vars['style_name'], $vars['file']->uri));
$vars['url'] .= (strpos($vars['url'], '?') !== FALSE ? '&' : '?') . drupal_http_build_query($token_query);
}
$vars['class'] = !empty($vars['widget']['settings']['insert_class']) ? $vars['widget']['settings']['insert_class'] : '';
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* @file
* Insert support for generic files.
*/
/**
* Implementation of hook_insert_styles().
*/
function insert_insert_styles() {
$insert_styles = array();
$insert_styles['auto'] = array('label' => t('Automatic'), 'weight' => -20);
$insert_styles['link'] = array('label' => t('Link to file'), 'weight' => -12);
$insert_styles['icon_link'] = array('label' => t('Link to file (with icon)'), 'weight' => -11);
$insert_styles['image'] = array('label' => t('Original image'), 'weight' => -10);
return $insert_styles;
}
/**
* Implementation of hook_insert_content().
*/
function insert_insert_content($item, $style, $widget) {
$style_name = $style['name'];
if (empty($item['fid'])) {
return '';
}
if ($style_name == 'auto') {
$file = file_load($item['fid']);
$info = @pathinfo($file->uri);
if (in_array(strtolower($info['extension']), array('png', 'jpg', 'jpeg', 'gif'))) {
$style_name = 'image';
}
}
if ($style_name == 'image') {
return theme('insert_image', array('item' => $item, 'widget' => $widget));
}
if ($style_name == 'icon_link') {
return theme('insert_icon_link', array('item' => $item, 'widget' => $widget));
}
else {
return theme('insert_link', array('item' => $item, 'widget' => $widget));
}
}
/**
* Preprocess variables for the insert-image.tpl.php file.
*/
function template_preprocess_insert_image(&$vars) {
$vars['file'] = file_load($vars['item']['fid']);
$absolute = isset($vars['widget']['settings']['insert_absolute']) ? $vars['widget']['settings']['insert_absolute'] : NULL;
$vars['url'] = insert_create_url($vars['file']->uri, $absolute);
$vars['class'] = !empty($vars['widget']['settings']['insert_class']) ? $vars['widget']['settings']['insert_class'] : '';
$image_info = @image_get_info($vars['file']->uri);
$vars['width'] = isset($image_info['width']) ? $image_info['width'] : '';
$vars['height'] = isset($image_info['height']) ? $image_info['height'] : '';
}
/**
* Preprocess variables for the insert-link.tpl.php file.
*/
function template_preprocess_insert_link(&$vars) {
$vars['file'] = file_load($vars['item']['fid']);
$absolute = isset($vars['widget']['settings']['insert_absolute']) ? $vars['widget']['settings']['insert_absolute'] : NULL;
$vars['url'] = insert_create_url($vars['file']->uri, $absolute);
$vars['class'] = !empty($vars['widget']['settings']['insert_class']) ? $vars['widget']['settings']['insert_class'] : '';
$vars['name'] = $vars['file']->filename;
}
/**
* Preprocess variables for the insert-icon-link.tpl.php file.
*/
function template_preprocess_insert_icon_link(&$vars) {
$vars['file'] = file_load($vars['item']['fid']);
$absolute = isset($vars['widget']['settings']['insert_absolute']) ? $vars['widget']['settings']['insert_absolute'] : NULL;
$vars['url'] = insert_create_url($vars['file']->uri, $absolute);
$vars['class'] = !empty($vars['widget']['settings']['insert_class']) ? $vars['widget']['settings']['insert_class'] : '';
$vars['name'] = $vars['file']->filename;
$vars['type'] = $vars['file']->filemime .'; length='. $vars['file']->filesize;
$vars['icon'] = theme('file_icon', array('file' => $vars['file']));
}

View File

@@ -0,0 +1,10 @@
name = Insert
description = Assists in inserting files, images, or other media into the body field or other text areas.
core = 7.x
; Information added by drupal.org packaging script on 2013-02-23
version = "7.x-1.3"
core = "7.x"
project = "insert"
datestamp = "1361661838"

View File

@@ -0,0 +1,14 @@
<?php
/**
* @file
* Update and install functions for Insert.
*/
/**
* Implementation of hook_install().
*/
function insert_install() {
// Insert needs to load after both ImageField and FileField.
db_query("UPDATE {system} SET weight = 15 WHERE type = 'module' AND name = 'insert'");
}

View File

@@ -0,0 +1,261 @@
/**
* @file
* JavaScript to activate "Insert" buttons on file and image fields.
*/
(function ($) {
/**
* Behavior to add "Insert" buttons.
*/
Drupal.behaviors.insert = {};
Drupal.behaviors.insert.attach = function(context) {
if (typeof(insertTextarea) == 'undefined') {
insertTextarea = $('#edit-body textarea.text-full').get(0) || false;
}
// Keep track of the last active textarea (if not using WYSIWYG).
$('textarea:not([name$="[data][title]"]):not(.insert-processed)', context).addClass('insert-processed').focus(insertSetActive).blur(insertRemoveActive);
// Add the click handler to the insert button.
$('.insert-button:not(.insert-processed)', context).addClass('insert-processed').click(insert);
function insertSetActive() {
insertTextarea = this;
this.insertHasFocus = true;
}
function insertRemoveActive() {
if (insertTextarea == this) {
var thisTextarea = this;
setTimeout(function() {
thisTextarea.insertHasFocus = false;
}, 1000);
}
}
function insert() {
var widgetType = $(this).attr('rel');
var settings = Drupal.settings.insert.widgets[widgetType];
var wrapper = $(this).parents(settings.wrapper).filter(':first').get(0);
var style = $('.insert-style', wrapper).val();
var content = $('input.insert-template[name$="[' + style + ']"]', wrapper).val();
var filename = $('input.insert-filename', wrapper).val();
var options = {
widgetType: widgetType,
filename: filename,
style: style,
fields: {}
};
// Update replacements.
for (var fieldName in settings.fields) {
var fieldValue = $(settings.fields[fieldName], wrapper).val();
if (fieldValue) {
fieldValue = fieldValue
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
options['fields'][fieldName] = fieldValue;
if (fieldValue) {
var fieldRegExp = new RegExp('__' + fieldName + '(_or_filename)?__', 'g');
content = content.replace(fieldRegExp, fieldValue);
}
else {
var fieldRegExp = new RegExp('__' + fieldName + '_or_filename__', 'g');
content = content.replace(fieldRegExp, filename);
}
}
// File name replacement.
var fieldRegExp = new RegExp('__filename__', 'g');
content = content.replace(fieldRegExp, filename);
// Check for a maximum dimension and scale down the width if necessary.
// This is intended for use with Image Resize Filter.
var widthMatches = content.match(/width[ ]*=[ ]*"(\d*)"/i);
var heightMatches = content.match(/height[ ]*=[ ]*"(\d*)"/i);
if (settings.maxWidth && widthMatches && parseInt(widthMatches[1]) > settings.maxWidth) {
var insertRatio = settings.maxWidth / widthMatches[1];
var width = settings.maxWidth;
content = content.replace(/width[ ]*=[ ]*"?(\d*)"?/i, 'width="' + width + '"');
if (heightMatches) {
var height = Math.round(heightMatches[1] * insertRatio);
content = content.replace(/height[ ]*=[ ]*"?(\d*)"?/i, 'height="' + height + '"');
}
}
// Allow other modules to perform replacements.
options['content'] = content;
$.event.trigger('insertIntoActiveEditor', [options]);
content = options['content'];
// Cleanup unused replacements.
content = content.replace(/"__([a-z0-9_]+)__"/g, '""');
// Cleanup empty attributes (other than alt).
content = content.replace(/([a-z]+)[ ]*=[ ]*""/g, function(match, tagName) {
return (tagName === 'alt') ? match : '';
});
// Insert the text.
Drupal.insert.insertIntoActiveEditor(content);
}
};
// General Insert API functions.
Drupal.insert = {
/**
* Insert content into the current (or last active) editor on the page. This
* should work with most WYSIWYGs as well as plain textareas.
*
* @param content
*/
insertIntoActiveEditor: function(content) {
var editorElement;
// Always work in normal text areas that currently have focus.
if (insertTextarea && insertTextarea.insertHasFocus) {
editorElement = insertTextarea;
Drupal.insert.insertAtCursor(insertTextarea, content);
}
// Direct tinyMCE support.
else if (typeof(tinyMCE) != 'undefined' && tinyMCE.activeEditor) {
editorElement = document.getElementById(tinyMCE.activeEditor.editorId);
Drupal.insert.activateTabPane(editorElement);
tinyMCE.activeEditor.execCommand('mceInsertContent', false, content);
}
// WYSIWYG support, should work in all editors if available.
else if (Drupal.wysiwyg && Drupal.wysiwyg.activeId) {
editorElement = document.getElementById(Drupal.wysiwyg.activeId);
Drupal.insert.activateTabPane(editorElement);
Drupal.wysiwyg.instances[Drupal.wysiwyg.activeId].insert(content)
}
// FCKeditor module support.
else if (typeof(FCKeditorAPI) != 'undefined' && typeof(fckActiveId) != 'undefined') {
editorElement = document.getElementById(fckActiveId);
Drupal.insert.activateTabPane(editorElement);
FCKeditorAPI.Instances[fckActiveId].InsertHtml(content);
}
// Direct FCKeditor support (only body field supported).
else if (typeof(FCKeditorAPI) != 'undefined') {
// Try inserting into the body.
if (FCKeditorAPI.Instances[insertTextarea.id]) {
editorElement = insertTextarea;
Drupal.insert.activateTabPane(editorElement);
FCKeditorAPI.Instances[insertTextarea.id].InsertHtml(content);
}
// Try inserting into the first instance we find (may occur with very
// old versions of FCKeditor).
else {
for (var n in FCKeditorAPI.Instances) {
editorElement = document.getElementById(n);
Drupal.insert.activateTabPane(editorElement);
FCKeditorAPI.Instances[n].InsertHtml(content);
break;
}
}
}
// CKeditor module support.
else if (typeof(CKEDITOR) != 'undefined' && typeof(Drupal.ckeditorActiveId) != 'undefined') {
editorElement = document.getElementById(Drupal.ckeditorActiveId);
Drupal.insert.activateTabPane(editorElement);
CKEDITOR.instances[Drupal.ckeditorActiveId].insertHtml(content);
}
// Direct CKeditor support (only body field supported).
else if (typeof(CKEDITOR) != 'undefined' && CKEDITOR.instances[insertTextarea.id]) {
editorElement = insertTextarea;
Drupal.insert.activateTabPane(editorElement);
CKEDITOR.instances[insertTextarea.id].insertHtml(content);
}
else if (insertTextarea) {
editorElement = insertTextarea;
Drupal.insert.activateTabPane(editorElement);
Drupal.insert.insertAtCursor(insertTextarea, content);
}
if (editorElement) {
Drupal.insert.contentWarning(editorElement, content);
}
return false;
},
/**
* Check for vertical tabs and activate the pane containing the editor.
*
* @param editor
* The DOM object of the editor that will be checked.
*/
activateTabPane: function(editor) {
var $pane = $(editor).parents('.vertical-tabs-pane:first');
var $panes = $pane.parent('.vertical-tabs-panes');
var $tabs = $panes.parents('.vertical-tabs:first').find('ul.vertical-tabs-list:first li a');
if ($pane.size() && $pane.is(':hidden') && $panes.size() && $tabs.size()) {
var index = $panes.children().index($pane);
$tabs.eq(index).click();
}
},
/**
* Warn users when attempting to insert an image into an unsupported field.
*
* This function is only a 90% use-case, as it doesn't support when the filter
* tip are hidden, themed, or when only one format is available. However it
* should fail silently in these situations.
*/
contentWarning: function(editorElement, content) {
if (!content.match(/<img /)) return;
var $wrapper = $(editorElement).parents('div.text-format-wrapper:first');
if (!$wrapper.length) return;
$wrapper.find('.filter-guidelines-item:visible li').each(function(index, element) {
var expression = new RegExp(Drupal.t('Allowed HTML tags'));
if (expression.exec(element.textContent) && !element.textContent.match(/<img>/)) {
alert(Drupal.t("The selected text format will not allow it to display images. The text format will need to be changed for this image to display properly when saved."));
}
});
},
/**
* Insert content into a textarea at the current cursor position.
*
* @param editor
* The DOM object of the textarea that will receive the text.
* @param content
* The string to be inserted.
*/
insertAtCursor: function(editor, content) {
// Record the current scroll position.
var scroll = editor.scrollTop;
// IE support.
if (document.selection) {
editor.focus();
sel = document.selection.createRange();
sel.text = content;
}
// Mozilla/Firefox/Netscape 7+ support.
else if (editor.selectionStart || editor.selectionStart == '0') {
var startPos = editor.selectionStart;
var endPos = editor.selectionEnd;
editor.value = editor.value.substring(0, startPos) + content + editor.value.substring(endPos, editor.value.length);
}
// Fallback, just add to the end of the content.
else {
editor.value += content;
}
// Ensure the textarea does not unexpectedly scroll.
editor.scrollTop = scroll;
}
};
})(jQuery);

View File

@@ -0,0 +1,424 @@
<?php
/**
* @file
* Allows insertion of files, images, and other media directly into the body
* field by using an "Insert" button next to the uploaded file.
*/
// Load default implementations of insert hooks for core modules.
require dirname(__FILE__) . '/includes/file.inc';
require dirname(__FILE__) . '/includes/image.inc';
require dirname(__FILE__) . '/includes/insert.inc';
/**
* Implements hook_element_info().
*/
function insert_element_info() {
$extra = array('#after_build' => array('insert_element_process'));
$elements = array();
foreach (insert_widgets() as $widget_type => $widget) {
$element_type = isset($widget['element_type']) ? $widget['element_type'] : $widget_type;
$elements[$element_type] = $extra;
}
return $elements;
}
/**
* Implements hook_theme().
*/
function insert_theme() {
return array(
'insert_widget' => array(
'render element' => 'element',
'template' => 'templates/insert-widget',
),
'insert_field_widget_settings_styles' => array(
'render element' => 'element',
),
// Theme functions in includes/insert.inc.
'insert_image' => array(
'variables' => array('item' => NULL, 'widget' => NULL),
'template' => 'templates/insert-image',
'file' => 'includes/insert.inc',
),
'insert_link' => array(
'variables' => array('item' => NULL, 'widget' => NULL),
'template' => 'templates/insert-link',
'file' => 'includes/insert.inc',
),
'insert_icon_link' => array(
'variables' => array('item' => NULL, 'widget' => NULL),
'template' => 'templates/insert-icon-link',
'file' => 'includes/insert.inc',
),
// Theme functions in includes/image.inc.
'image_insert_image' => array(
'variables' => array('item' => NULL, 'widget' => NULL, 'style_name' => NULL),
'template' => 'templates/image-insert-image',
'pattern' => 'image_insert_image__[a-z0-9_]+',
'file' => 'includes/image.inc',
),
);
}
/**
* Get a list of all supported image styles.
*/
function insert_styles($reset = FALSE) {
static $styles;
if (!isset($styles) || $reset) {
$styles = array();
foreach (module_implements('insert_styles') as $module) {
$module_styles = module_invoke($module, 'insert_styles');
foreach ($module_styles as $name => $style) {
$module_styles[$name]['name'] = $name;
$module_styles[$name]['module'] = $module;
}
$styles = array_merge($styles, $module_styles);
}
drupal_alter('insert_styles', $styles);
uasort($styles, '_insert_style_sort');
}
return $styles;
}
/**
* Sort the styles.
*/
function _insert_style_sort($a, $b) {
$a = (array)$a + array('weight' => 0, 'label' => '');
$b = (array)$b + array('weight' => 0, 'label' => '');
return $a['weight'] < $b['weight'] ? -1 : ($a['weight'] > $b['weight'] ? 1 : strnatcasecmp($a['label'], $b['label']));
}
/**
* Load an individual insert style.
*/
function insert_style_load($style_name) {
$styles = insert_styles();
return isset($styles[$style_name]) ? $styles[$style_name] : FALSE;
}
/**
* Get a list of styles suitable for an #options array.
*/
function insert_styles_list() {
$list = array();
foreach (insert_styles() as $name => $style) {
$list[$name] = $style['label'];
}
return $list;
}
/**
* Get a list of all supported field widgets.
*/
function insert_widgets($reset = FALSE) {
static $widgets;
if (!isset($widgets) || $reset) {
$widgets = array();
foreach (module_implements('insert_widgets') as $module) {
$module_widgets = module_invoke($module, 'insert_widgets');
foreach ($module_widgets as $type => $widget) {
$module_widgets[$type]['type'] = $type;
$module_widgets[$type]['module'] = $module;
}
$widgets = array_merge($widgets, $module_widgets);
}
drupal_alter('insert_widgets', $widgets);
}
return $widgets;
}
/**
* Load a single insert field widget info.
*/
function insert_widget_load($widget_type) {
$widgets = insert_widgets();
return isset($widgets[$widget_type]) ? $widgets[$widget_type] : FALSE;
}
/**
* Given an item and an insert style, return the output.
*/
function insert_content($item, $style, $widget) {
return module_invoke($style['module'], 'insert_content', $item, $style, $widget);
}
/**
* Process function for insert-enabled fields.
*/
function insert_element_process($element) {
static $js_added;
// Bail out early if the needed properties aren't available. This happens
// most frequently when editing a field configuration.
if (!isset($element['#entity_type'])) {
return $element;
}
$item = $element['#value'];
$field = field_info_field($element['#field_name']);
$instance = field_info_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']);
$widget_settings = $instance['widget']['settings'];
$widget_type = $instance['widget']['type'];
// Bail out of Insert is not enabled on this field.
if (empty($widget_settings['insert'])) {
return $element;
}
// Add base settings only once.
if (!isset($js_added)) {
$js_added = array();
$settings = array('fileDirectoryPath' => file_default_scheme());
drupal_add_js(array('insert' => $settings), 'setting');
drupal_add_js(drupal_get_path('module', 'insert') . '/insert.js');
}
// Add settings for this widget only once.
if (!isset($js_added[$widget_type])) {
$js_added[$widget_type] = TRUE;
$insert_widget = insert_widget_load($widget_type);
$insert_settings = array(
'maxWidth' => $widget_settings['insert_width'],
'wrapper' => $insert_widget['wrapper'],
'fields' => $insert_widget['fields'],
);
drupal_add_js(array('insert' => array('widgets' => array($widget_type => $insert_settings))), 'setting');
}
// Load the file if it's not entirely loaded.
if ($element['fid']['#value'] && !isset($item['filename'])) {
if ($loaded_file = file_load($element['fid']['#value'])) {
$item = array_merge((array) $loaded_file, $item);
}
}
if (isset($item['filename'])) {
$insert_styles = !empty($widget_settings['insert_styles']['<all>']) ? drupal_map_assoc(array_keys(insert_styles())) : array_filter((array) $widget_settings['insert_styles']);
$default = !empty($instance['widget']['settings']['insert_default']) ? $widget_settings['insert_default'] : 'auto';
if (!isset($insert_styles[$default])) {
$insert_styles[$default] = $default;
}
foreach ($insert_styles as $style_name => $enabled) {
if ($enabled && ($style = insert_style_load($style_name))) {
$element['insert_templates'][$style_name] = array(
'#type' => 'hidden',
'#value' => insert_content($item, $style, $instance['widget']),
'#id' => $element['#id'] . '-insert-template-' . str_replace('_', '-', $style_name),
'#name' => $element['#name'] . '[insert_template][' . $style_name . ']',
'#attributes' => array('class' => array('insert-template')),
);
$style_options[$style_name] = $style['label'];
}
// Always provide a file name property.
$element['insert_filename'] = array(
'#type' => 'hidden',
'#value' => $item['filename'],
'#id' => $element['#id'] . '-insert-filename',
'#name' => $element['#name'] . '[insert_filename]',
'#attributes' => array('class' => array('insert-filename')),
);
}
$element['insert'] = array(
'#theme' => 'insert_widget',
'#type' => 'markup',
'#options' => $style_options,
'#widget' => $instance['widget'],
'#weight' => -3,
'#default_value' => $default,
);
}
return $element;
}
/**
* Implements hook_form_alter().
*/
function insert_form_field_ui_field_edit_form_alter(&$form, $form_state) {
$instance = $form['#instance'];
if (array_key_exists($instance['widget']['type'], insert_widgets())) {
$field = $form['#field'];
if (empty($form['instance']['settings'])) {
$form['instance']['settings'] = array();
}
$form['instance']['settings'] += insert_field_widget_settings_form($field, $instance);
}
}
/**
* Implements hook_field_widget_info_alter().
*
* A list of settings needed by Insert module on widgets.
*/
function insert_field_widget_info_alter(&$info) {
$settings = array(
'insert' => 0,
'insert_absolute' => variable_get('insert_absolute_paths', FALSE),
'insert_styles' => array('auto'),
'insert_default' => array('auto'),
'insert_class' => '',
'insert_width' => '',
);
foreach (insert_widgets() as $widget_type => $widget) {
if (isset($info[$widget_type]['settings'])) {
$info[$widget_type]['settings'] += $settings;
}
}
}
/**
* Configuration form for editing insert settings for a field instance.
*/
function insert_field_widget_settings_form($field, $instance) {
$widget = $instance['widget'];
$settings = $widget['settings'];
$form['insert'] = array(
'#type' => 'fieldset',
'#title' => t('Insert'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => t('These options allow the user to easily insert an HTML tags into text areas or WYSIWYG editors after uploading a file or image. The "Automatic" style will insert a &lt;img&gt; tag for images and a &lt;a&gt; tag for other files. Other styles may insert tags that may not match the file type.'),
'#weight' => 20,
'#parents' => array('instance', 'widget', 'settings'),
);
$form['insert']['insert'] = array(
'#type' => 'checkbox',
'#title' => t('Enable insert button'),
'#default_value' => $settings['insert'],
'#description' => t('Enable the insert button and options for this widget.'),
'#weight' => -10,
);
$form['insert']['insert_absolute'] = array(
'#type' => 'checkbox',
'#title' => t('Use absolute paths'),
'#default_value' => isset($settings['insert_absolute']) ? $settings['insert_absolute'] : variable_get('insert_absolute_paths', FALSE),
'#description' => t('Includes the full URL prefix "@base_url" in all links and image tags.', array('@base_url' => $GLOBALS['base_url'])),
'#weight' => -9,
);
$form['insert']['insert_styles'] = array(
'#title' => t('Enabled insert styles'),
'#type' => 'checkboxes',
'#options' => insert_styles_list(),
'#default_value' => !empty($settings['insert_styles']['<all>']) ? array_keys(insert_styles_list()) : $settings['insert_styles'],
'#description' => t('Select which styles should be available when sending items to text areas. If no styles are selected, the option to use a style is not displayed. If all styles are selected, new styles will be enabled by default.'),
'#element_validate' => array('insert_field_widget_settings_styles_validate'),
'#theme' => 'insert_field_widget_settings_styles',
'#weight' => 0,
);
$form['insert']['insert_default'] = array(
'#title' => t('Default insert style'),
'#type' => 'select',
'#options' => insert_styles_list(),
'#default_value' => $settings['insert_default'],
'#description' => t('Select the default style which will be selected by default or used if no specific styles above are enabled.'),
'#weight' => 1,
);
$form['insert']['insert_class'] = array(
'#title' => t('Additional CSS classes'),
'#type' => 'textfield',
'#default_value' => $settings['insert_class'],
'#description' => t('Add any classes that should be added to the item on output.'),
'#weight' => 5,
);
$form['insert']['insert_width'] = array(
'#title' => t('Maximum image insert width'),
'#type' => 'textfield',
'#size' => 10,
'#field_suffix' => ' '. t('pixels'),
'#default_value' => $settings['insert_width'],
'#description' => t('When inserting images, the height and width of images may be scaled down to fit within the specified width. Note that this does not resize the image, it only affects the HTML output. To resize images it is recommended to install the <a href="http://drupal.org/project/image_resize_filter">Image Resize Filter</a> module.'),
'#weight' => 10,
);
return $form;
}
/**
* An #element_validate function for the styles list on the settings form.
*/
function insert_field_widget_settings_styles_validate($element, &$form_state) {
if (array_values($element['#value']) == array_keys($element['#options'])) {
form_set_value($element, array('<all>' => '<all>'), $form_state);
}
}
/**
* Theme the output of the styles list on the settings form.
*/
function theme_insert_field_widget_settings_styles($variables) {
$element = $variables['element'];
drupal_add_js('misc/tableselect.js');
$header = array(
array('class' => array('select-all'), 'data' => ' ' . t('Select all')),
);
$rows = array();
foreach ($element['#options'] as $key => $label) {
$row = array();
$row[] = drupal_render($element[$key]);
$rows[] = $row;
}
return theme('table', array('header' => $header, 'rows' => $rows));
}
/**
* Utility function to create a URL for Insert.
*
* This is modeled after file_create_url(), but with the modification that it
* will consistently use absolute or relative URLs, depending on the Insert
* setting.
*/
function insert_create_url($uri, $absolute = NULL, $clean_urls = TRUE) {
$absolute = isset($absolute) ? $absolute : variable_get('insert_absolute_paths', FALSE);
// If not using clean URLs, the image derivative callback is only available
// with the query string. Always use the non-clean URL in the event that the
// image cache is flushed and needs to be regenerated. See image_style_url().
if (!$clean_urls && file_uri_scheme($uri) == 'public') {
$directory_path = file_stream_wrapper_get_instance_by_uri($uri)->getDirectoryPath();
$url = url($directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE));
}
else {
$url = file_create_url($uri);
}
if (!$absolute && strpos($url, $GLOBALS['base_url']) === 0) {
$url = base_path() . ltrim(str_replace($GLOBALS['base_url'], '', $url), '/');
}
return $url;
}
/**
* Preprocess variables for the insert-widget.tpl.php file.
*/
function template_preprocess_insert_widget(&$vars) {
$element = $vars['element'];
$vars['insert_styles'] = $element['#options'];
$vars['default_style'] = $element['#default_value'];
$vars['widget_type'] = $element['#widget']['type'];
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* @file
* Template file for Image module content inserted via the Insert module.
*
* Available variables:
* - $item: The complete item being inserted.
* - $url: The URL to the image.
* - $class: A set of classes assigned to this image (if any).
* - $width: The width of the image (if known).
* - $height: The height of the image (if known).
* - $style_name: The Image style being used.
*
* Note that ALT and Title fields should not be filled in here, instead they
* should use placeholders that will be updated through JavaScript when the
* image is inserted.
*
* Available placeholders:
* - __alt__: The ALT text, intended for use in the <img> tag.
* - __title__: The Title text, intended for use in the <img> tag.
* - __description__: A description of the image, sometimes used as a caption.
* - __filename__: The file name.
* - __[token]_or_filename__: Any of the above tokens if available, otherwise
* use the file's name. i.e. __title_or_filename__.
*/
?>
<img src="<?php print $url ?>" <?php if ($width && $height): ?>width="<?php print $width; ?>" height="<?php print $height; ?>" <?php endif; ?>alt="__alt__" title="__title__" class="image-<?php print $style_name ?><?php print $class ? ' ' . $class : '' ?>" />

View File

@@ -0,0 +1,24 @@
<?php
/**
* @file
* Template file for generic links inserted via the Insert module.
*
* Available variables:
* - $item: The complete item being inserted.
* - $url: The URL to the item.
* - $class: A set of classes assigned to this item (if any).
* - $name: The file name of the item being inserted.
*
* Modules may provide placeholders that will be replaced by user-entered values
* when the item is inserted into a textarea. Generic links only support one
* placeholder.
*
* Available placeholders:
* - __description__: A description of the item.
* - __filename__: The file name.
* - __description_or_filename__: A description of the item if available,
* otherwise use the file name.
*/
?>
<span class="file"><?php print $icon; ?> <a href="<?php print $url ?>"<?php print $class ? ' class="' . $class . '"' : '' ?> title="__description__">__description_or_filename__</a></span>

View File

@@ -0,0 +1,27 @@
<?php
/**
* @file
* Template file for generic images inserted via the Insert module.
*
* Available variables:
* - $item: The complete item being inserted.
* - $url: The URL to the image.
* - $class: A set of classes assigned to this image (if any).
* - $width: The width of the image.
* - $height: The height of the image.
*
* Note that ALT and Title fields should not be filled in here, instead they
* should use placeholders that will be updated through JavaScript when the
* image is inserted.
*
* Available placeholders:
* - __alt__: The ALT text, intended for use in the <img> tag.
* - __title__: The Title text, intended for use in the <img> tag.
* - __description__: A description of the image, sometimes used as a caption.
* - __filename__: The file name.
* - __[token]_or_filename__: Any of the above tokens if available, otherwise
* use the file's name. i.e. __title_or_filename__.
*/
?>
<img src="<?php print $url ?>" width="<?php print $width ?>" height="<?php print $height ?>" alt="__alt__" title="__title__" <?php print $class ? 'class="' . $class . '" ' : '' ?>/>

View File

@@ -0,0 +1,24 @@
<?php
/**
* @file
* Template file for generic links inserted via the Insert module.
*
* Available variables:
* - $item: The complete item being inserted.
* - $url: The URL to the item.
* - $class: A set of classes assigned to this item (if any).
* - $name: The file name of the item being inserted.
*
* Modules may provide placeholders that will be replaced by user-entered values
* when the item is inserted into a textarea. Generic links only support one
* placeholder.
*
* Available placeholders:
* - __description__: A description of the item.
* - __filename__: The file name.
* - __description_or_filename__: A description of the item if available,
* otherwise use the file name.
*/
?>
<a href="<?php print $url ?>"<?php print $class ? ' class="' . $class . '"' : '' ?> title="__description__">__description_or_filename__</a>

View File

@@ -0,0 +1,30 @@
<?php
/**
* @file
* Template file for the insert button.
*
* This button can have any appearance you like or even be a link, but must
* include the class "insert-button", to which the insert JavaScript will be
* attached.
*/
?>
<?php if (count($insert_styles) > 1): ?>
<div class="insert form-item container-inline inline">
<div class="insert-style-select">
<label><?php print t('Style') ?>:</label>
<select class="insert-style">
<?php foreach ($insert_styles as $value => $style): ?>
<option value="<?php print $value ?>"<?php print ($value == $default_style) ? 'selected="selected"' : '' ?>><?php print $style ?></option>
<?php endforeach; ?>
</select>
</div>
<?php else: ?>
<input type="hidden" class="insert-style" value="<?php print $default_style ?>" />
<?php endif; ?>
<input type="submit" rel="<?php print $widget_type ?>" class="form-submit insert-button" onclick="return false;" value="<?php print t('Insert'); ?>" />
<?php if (count($insert_styles) > 1): ?>
</div>
<?php endif; ?>