first import
This commit is contained in:
16
sites/all/modules/shortcode/CHANGELOG.txt
Normal file
16
sites/all/modules/shortcode/CHANGELOG.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
Shortcode 7.x-2.x, xxxx-xx-xx
|
||||
------------------------------
|
||||
|
||||
|
||||
Shortcode 7.x-2.x, 2012-03-10
|
||||
------------------------------
|
||||
|
||||
by Denes.Szabo: Updated the code tips, now all translateable.
|
||||
by Denes.Szabo: Updated to use new attr handling method to help code editors.
|
||||
by Denes.Szabo: Lots of fixes and cleanups
|
||||
by Denes.szabo: Fixed multi text format handling in one content.
|
||||
#1469108 by Nick Cash: Fixed a missing object creation.
|
||||
#1469132 by Nick Cash: Removed theme alter.
|
||||
by Denes.szabo: Added documentation to the functions.
|
||||
by Denes.szabo: Renamed the shortcode_embed_content module.
|
||||
|
||||
339
sites/all/modules/shortcode/LICENSE.txt
Normal file
339
sites/all/modules/shortcode/LICENSE.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
5
sites/all/modules/shortcode/README.txt
Normal file
5
sites/all/modules/shortcode/README.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
Provides a shortcode API and basic shortcodes through Drupal filters.
|
||||
|
||||
Initial works based on the Wordpress Shortcode API but I rewrote it for Drupal and solved the nested tag problem. Now you can nest tags (same tags too) no need special recursion handling.
|
||||
|
||||
All tags are themeable and new tags can be provided by other modules.
|
||||
42
sites/all/modules/shortcode/shortcode.api.php
Normal file
42
sites/all/modules/shortcode/shortcode.api.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Shortcode API documentation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* hook_shortcode_info()
|
||||
* Declare shortcodes
|
||||
*
|
||||
* @return
|
||||
* An associative array of shortcodes, whose keys are internal shortcode names,
|
||||
* which should be unique..
|
||||
* Each value is an associative array describing the shortcode, with the
|
||||
* following elements (all are optional except as noted):
|
||||
* - title: (required) An administrative summary of what the shortcode does.
|
||||
* - description: Additional administrative information about the shortcode's
|
||||
* behavior, if needed for clarification.
|
||||
* - settings callback: The name of a function that returns configuration form
|
||||
* elements for the shortcode. TODO
|
||||
* - default settings: An associative array containing default settings for
|
||||
* the shortcode, to be applied when the shortcode has not been configured yet.
|
||||
* - process callback: (required) The name the function that performs the
|
||||
* actual shortcodeing.
|
||||
* - tips callback: The name of a function that returns end-user-facing shortcode
|
||||
* usage guidelines for the shortcode.
|
||||
*
|
||||
*/
|
||||
function hook_shortcode_info() {
|
||||
// Quote shortcode example
|
||||
$shortcodes['quote'] = array(
|
||||
'title' => t('Quote'),
|
||||
'description' => t('Replace a given text formatted like a quote.'),
|
||||
'process callback' => 'shortcode_basic_tags_shortcode_quote',
|
||||
//'settings callback' => '_shortcode_settings_form', TODO
|
||||
'tips callback' => 'shortcode_basic_tags_shortcode_quote_tip',
|
||||
'default settings' => array(),
|
||||
);
|
||||
|
||||
return $shortcodes;
|
||||
}
|
||||
12
sites/all/modules/shortcode/shortcode.info
Normal file
12
sites/all/modules/shortcode/shortcode.info
Normal file
@@ -0,0 +1,12 @@
|
||||
name = Shortcode
|
||||
description = Provides shortcodes filter framework and API (like WP shortcodes)
|
||||
package = Shortcode
|
||||
core = 7.x
|
||||
dependencies[] = filter
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-03-10
|
||||
version = "7.x-2.0-alpha1"
|
||||
core = "7.x"
|
||||
project = "shortcode"
|
||||
datestamp = "1331420143"
|
||||
|
||||
502
sites/all/modules/shortcode/shortcode.module
Normal file
502
sites/all/modules/shortcode/shortcode.module
Normal file
@@ -0,0 +1,502 @@
|
||||
<?php
|
||||
/*
|
||||
* TODO
|
||||
*
|
||||
* strip_shortcodes - remove all shortcodes from the processed text
|
||||
*
|
||||
* correct element cascading
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Build a list of all shortcodes (for filter).
|
||||
* Calls the shortcode hook with the list parameter on all module
|
||||
*/
|
||||
function shortcode_list_all($reset = FALSE) {
|
||||
$shortcodes = &drupal_static(__FUNCTION__);
|
||||
if(!isset($shortcodes) || $reset) {
|
||||
$shortcodes = array();
|
||||
$shortcodes += module_invoke_all('shortcode_info');
|
||||
}
|
||||
|
||||
return $shortcodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns only enabled shortcodes for a format
|
||||
*/
|
||||
function shortcode_list_all_enabled($format, $reset = FALSE) {
|
||||
if (is_string($format)) {
|
||||
$format = filter_format_load($format);
|
||||
}
|
||||
|
||||
$shortcodes_enabled = &drupal_static(__FUNCTION__, array());
|
||||
|
||||
if (isset($shortcodes_enabled[$format->format]) && !$reset) {
|
||||
return $shortcodes_enabled[$format->format];
|
||||
}
|
||||
$shortcodes_enabled[$format->format] = array();
|
||||
|
||||
$shortcodes = shortcode_list_all($reset);
|
||||
$filters = filter_list_format($format->format);
|
||||
|
||||
if (empty($filters['shortcode'])) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach($filters['shortcode']->settings as $name => $enabled) { // Run through all shortcodes
|
||||
if ($enabled) {
|
||||
$shortcodes_enabled[$format->format][$name] = $shortcodes[$name];
|
||||
}
|
||||
}
|
||||
|
||||
return $shortcodes_enabled[$format->format];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_filter_info().
|
||||
*/
|
||||
function shortcode_filter_info() {
|
||||
$filters['shortcode'] = array(
|
||||
'title' => t('Shortcodes'),
|
||||
'description' => t('Provides WP like shortcodes to this text format.'),
|
||||
'process callback' => '_shortcode_process',
|
||||
'settings callback' => '_shortcode_settings_form',
|
||||
'tips callback' => '_shortcode_filter_tips',
|
||||
);
|
||||
$filters['shortcode_text_corrector'] = array(
|
||||
'title' => t('Shortcodes - html corrector'),
|
||||
'description' => t('Trying to correct the html around shortcodes. Enable only if you using wysiwyg editor.'),
|
||||
'process callback' => '_shortcode_postprocess_text',
|
||||
);
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter tips callback
|
||||
*/
|
||||
function _shortcode_filter_tips($filter, $format, $long = FALSE) {
|
||||
$shortcodes = shortcode_list_all_enabled($format);
|
||||
$tips = array();
|
||||
$args = func_get_args();
|
||||
foreach($filter->settings as $name => $enabled) { // Run through all shortcodes
|
||||
if($enabled && !empty($shortcodes[$name]['tips callback']) && function_exists($shortcodes[$name]['tips callback'])) {
|
||||
$tips[] = call_user_func_array($shortcodes[$name]['tips callback'], array($format, $long));
|
||||
}
|
||||
}
|
||||
return theme('item_list',
|
||||
array(
|
||||
'title' => t('Shortcodes usage'),
|
||||
'items' => $tips,
|
||||
'type' => 'ol',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form
|
||||
*/
|
||||
function _shortcode_settings_form($form, &$form_state, $filter, $format, $defaults) {
|
||||
$settings = array();
|
||||
$filter->settings += $defaults;
|
||||
$shortcodes = shortcode_list_all();
|
||||
foreach ($shortcodes as $key => $shortcode) {
|
||||
$settings[$key] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable %name shortcode', array('%name' => $shortcode['title'])),
|
||||
'#default_value' => array(),
|
||||
'#description' => 'Enable or disable this shortcode in this input format',
|
||||
);
|
||||
|
||||
if (!empty($filter->settings[$key])) {
|
||||
$settings[$key]['#default_value'] = $filter->settings[$key];
|
||||
}
|
||||
elseif( !empty($defaults[$key])) {
|
||||
$settings[$key]['#default_value'] = $defaults[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tags cache
|
||||
* @param $tags
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _shortcode_tags($tags = NULL) {
|
||||
$shortcodes = &drupal_static(__FUNCTION__, array());
|
||||
if ($tags) {
|
||||
$shortcodes = $tags;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return $shortcodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the shortcodes according to the text and the text format.
|
||||
*/
|
||||
function _shortcode_process($text, $filter) {
|
||||
// TODO: need cache for list_all for the given filter!
|
||||
$shortcodes = shortcode_list_all();
|
||||
$shortcodes_enabled = array();
|
||||
|
||||
foreach($filter->settings as $name => $value) { // run through all shortcodes
|
||||
if($value && $shortcodes[$name]['process callback']) {
|
||||
$shortcodes_enabled[$name] = array(
|
||||
'function' => $shortcodes[$name]['process callback'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($shortcodes_enabled)) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
// save the shortcodes
|
||||
_shortcode_tags($shortcodes_enabled);
|
||||
|
||||
// improved version - recursive processing - embed tags within other tags is supported!
|
||||
$chunks = preg_split('!(\[.*?\])!', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
|
||||
|
||||
//dpr($chunks);
|
||||
$heap = array();
|
||||
$heap_index = array();
|
||||
|
||||
foreach ($chunks as $c) {
|
||||
if (!$c) {
|
||||
continue;
|
||||
}
|
||||
// shortcode or not
|
||||
if (($c[0] == '[') && (substr($c, -1, 1) == ']')) {
|
||||
// $c contains shortcode
|
||||
|
||||
// self-closing tag or not
|
||||
$c = substr($c, 1, -1);
|
||||
//dpr('process: ' . $c);
|
||||
|
||||
if (substr($c, -1, 1) == '/') {
|
||||
// process a self closing tag - it has / at the end!
|
||||
//dpr('self closing: ' . $c);
|
||||
/*
|
||||
* 0 - the full tag text?
|
||||
* 1/5 - An extra [ or ] to allow for escaping shortcodes with double [[]]
|
||||
* 2 - The shortcode name
|
||||
* 3 - The shortcode argument list
|
||||
* 4 - The content of a shortcode when it wraps some content.
|
||||
* */
|
||||
$ts = explode(' ', trim($c));
|
||||
$tag = array_shift($ts);
|
||||
|
||||
$m = array(
|
||||
$c,
|
||||
'',
|
||||
$tag,
|
||||
implode(' ', $ts),
|
||||
NULL,
|
||||
''
|
||||
);
|
||||
array_unshift($heap_index, '_string_');
|
||||
array_unshift($heap, _shortcode_process_tag($m));
|
||||
}
|
||||
elseif ($c[0] == '/') {
|
||||
// closing tag - process the heap
|
||||
$closing_tag = substr($c, 1);
|
||||
//dpr('closing tag: ' . $closing_tag );
|
||||
|
||||
$process_heap = array();
|
||||
$process_heap_index = array();
|
||||
$found = FALSE;
|
||||
|
||||
// get elements from heap and process
|
||||
do {
|
||||
$tag = array_shift($heap_index);
|
||||
$heap_text = array_shift($heap);
|
||||
|
||||
if($closing_tag == $tag) {
|
||||
// process the whole tag
|
||||
$m = array(
|
||||
$tag . ' ' . $heap_text,
|
||||
'',
|
||||
$tag,
|
||||
$heap_text,
|
||||
implode('', $process_heap),
|
||||
''
|
||||
);
|
||||
$str = _shortcode_process_tag($m);
|
||||
array_unshift($heap_index, '_string_');
|
||||
array_unshift($heap, $str);
|
||||
$found = TRUE;
|
||||
}
|
||||
else {
|
||||
array_unshift($process_heap, $heap_text);
|
||||
array_unshift($process_heap_index, $tag);
|
||||
}
|
||||
} while(!$found && $heap);
|
||||
|
||||
if(!$found) {
|
||||
|
||||
foreach($process_heap as $val) {
|
||||
array_unshift($heap, $val);
|
||||
}
|
||||
foreach($process_heap_index as $val) {
|
||||
array_unshift($heap_index, $val);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
// starting tag. put to the heap
|
||||
//dpr('tag pattern: ' . $c);
|
||||
$ts = explode(' ', trim($c));
|
||||
$tag = array_shift($ts);
|
||||
|
||||
// dpr('start tag: ' . $tag);
|
||||
array_unshift($heap_index, $tag);
|
||||
array_unshift($heap, implode(' ', $ts));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// not found a pair?
|
||||
array_unshift($heap_index, '_string_');
|
||||
array_unshift($heap, $c);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return(implode('', array_reverse($heap)));
|
||||
}
|
||||
|
||||
/*
|
||||
* Html corrector for wysiwyg editors
|
||||
*
|
||||
* Correcting p elements around the divs. No div are allowed in p so remove them.
|
||||
*
|
||||
*/
|
||||
function _shortcode_postprocess_text($text, $filter) {
|
||||
$patterns = array(
|
||||
'|#!#|is',
|
||||
'!<p>( |\s)*(<\/*div>)!is',
|
||||
'!<p>( |\s)*(<div)!is',
|
||||
'!(<\/div.*?>)\s*</p>!is',
|
||||
'!(<div.*?>)\s*</p>!is',
|
||||
);
|
||||
|
||||
//$replacements = array('!!\\2', '###\\2', '@@@\\1');
|
||||
$replacements = array('', '\\2', '\\2', '\\1', '\\1');
|
||||
return preg_replace($patterns, $replacements, $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Regular Expression callable for do_shortcode() for calling shortcode hook.
|
||||
* @see get_shortcode_regex for details of the match array contents.
|
||||
*
|
||||
* @since 2.5
|
||||
* @access private
|
||||
* @uses $shortcode_tags
|
||||
*
|
||||
* @param array $m Regular expression match array
|
||||
* @return mixed False on failure.
|
||||
*/
|
||||
function _shortcode_process_tag($m) {
|
||||
// get tags from static cache
|
||||
$shortcodes = _shortcode_tags();
|
||||
|
||||
// allow [[foo]] syntax for escaping a tag
|
||||
if ($m[1] == '[' && $m[5] == ']') {
|
||||
return substr($m[0], 1, -1);
|
||||
}
|
||||
|
||||
$tag = $m[2];
|
||||
|
||||
if (!empty($shortcodes[$tag])) {
|
||||
// tag exists (enabled)
|
||||
$attr = _shortcode_parse_attrs($m[3]);
|
||||
/*
|
||||
* 0 - the full tag text?
|
||||
* 1/5 - An extra [ or ] to allow for escaping shortcodes with double [[]]
|
||||
* 2 - The shortcode name
|
||||
* 3 - The shortcode argument list
|
||||
* 4 - The content of a shortcode when it wraps some content.
|
||||
* */
|
||||
|
||||
if (! is_null($m[4]) ) {
|
||||
// enclosing tag - extra parameter
|
||||
return $m[1] . call_user_func($shortcodes[$tag]['function'], $attr, $m[4], $m[2]) . $m[5];
|
||||
}
|
||||
else {
|
||||
// self-closing tag
|
||||
//dpr('fv self closing: ' . $shortcodes[$tag]->function);
|
||||
return $m[1] . call_user_func($shortcodes[$tag]['function'], $attr, NULL, $m[2]) . $m[5];
|
||||
}
|
||||
}
|
||||
elseif(is_null($m[4])) {
|
||||
return $m[4];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all attributes from the shortcodes tag.
|
||||
*
|
||||
* The attributes list has the attribute name as the key and the value of the
|
||||
* attribute as the value in the key/value pair. This allows for easier
|
||||
* retrieval of the attributes, since all attributes have to be known.
|
||||
*
|
||||
* @since 2.5
|
||||
*
|
||||
* @param string $text
|
||||
* @return array List of attributes and their value.
|
||||
*/
|
||||
function _shortcode_parse_attrs($text) {
|
||||
$atts = array();
|
||||
$pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
|
||||
$text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
|
||||
if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) {
|
||||
foreach ($match as $m) {
|
||||
if (!empty($m[1]))
|
||||
$atts[strtolower($m[1])] = stripcslashes($m[2]);
|
||||
elseif (!empty($m[3]))
|
||||
$atts[strtolower($m[3])] = stripcslashes($m[4]);
|
||||
elseif (!empty($m[5]))
|
||||
$atts[strtolower($m[5])] = stripcslashes($m[6]);
|
||||
elseif (isset($m[7]) and strlen($m[7]))
|
||||
$atts[] = stripcslashes($m[7]);
|
||||
elseif (isset($m[8]))
|
||||
$atts[] = stripcslashes($m[8]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$atts = ltrim($text);
|
||||
}
|
||||
return $atts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the shortcode regular expression for searching.
|
||||
*
|
||||
* The regular expression combines the shortcode tags in the regular expression
|
||||
* in a regex class.
|
||||
*
|
||||
* The regular expresion contains 6 different sub matches to help with parsing.
|
||||
*
|
||||
* 1/6 - An extra [ or ] to allow for escaping shortcodes with double [[]]
|
||||
* 2 - The shortcode name
|
||||
* 3 - The shortcode argument list
|
||||
* 4 - The self closing /
|
||||
* 5 - The content of a shortcode when it wraps some content.
|
||||
*
|
||||
* @return string The shortcode search regular expression
|
||||
*/
|
||||
function _shortcode_get_shortcode_regex($names) {
|
||||
$tagregexp = join( '|', array_map('preg_quote', $names) );
|
||||
|
||||
// WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcodes()
|
||||
return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Combine user attributes with known attributes and fill in defaults when needed.
|
||||
*
|
||||
* The pairs should be considered to be all of the attributes which are
|
||||
* supported by the caller and given as a list. The returned attributes will
|
||||
* only contain the attributes in the $pairs list.
|
||||
*
|
||||
* If the $atts list has unsupported attributes, then they will be ignored and
|
||||
* removed from the final returned list.
|
||||
*
|
||||
* @since 2.5
|
||||
*
|
||||
* @param array $pairs Entire list of supported attributes and their defaults.
|
||||
* @param array $atts User defined attributes in shortcode tag.
|
||||
* @return array Combined and filtered attribute list.
|
||||
*/
|
||||
function shortcode_attrs($pairs, $attrs) {
|
||||
$attrs = (array)$attrs;
|
||||
$out = array();
|
||||
foreach ($pairs as $name => $default) {
|
||||
if (array_key_exists($name, $attrs)) {
|
||||
$out[$name] = $attrs[$name];
|
||||
}
|
||||
else {
|
||||
$out[$name] = $default;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to decide the given param is a bool value
|
||||
* @param mixed $var
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function shortcode_bool($var) {
|
||||
switch (strtolower($var)) {
|
||||
case false:
|
||||
case 'false':
|
||||
case 'no':
|
||||
case '0':
|
||||
$res = FALSE;
|
||||
break;
|
||||
default:
|
||||
$res = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class parameter helper function
|
||||
* @param $class
|
||||
* @param $default
|
||||
*/
|
||||
function shortcode_add_class($class='', $default='') {
|
||||
if ($class) {
|
||||
if (! is_array($class)) {
|
||||
$class = explode(' ', $class);
|
||||
}
|
||||
array_unshift($class, $default);
|
||||
$class = array_unique($class);
|
||||
}
|
||||
else {
|
||||
$class[] = $default;
|
||||
}
|
||||
return implode(' ', $class);
|
||||
} //shortcode_add_class
|
||||
|
||||
|
||||
// shortcode implementations
|
||||
|
||||
/**
|
||||
* Generates a random code
|
||||
*
|
||||
* Calling
|
||||
* [random length=X /]
|
||||
*
|
||||
* Where X is the length of the random text.
|
||||
* If the length empty or invalid, between 1-99, the length will be 8
|
||||
*
|
||||
*/
|
||||
function shortcode_shortcode_random($attrs, $text) {
|
||||
extract( shortcode_attrs( array(
|
||||
'length' => 8,
|
||||
), $attrs ));
|
||||
|
||||
$length = intval($length);
|
||||
if (($length < 0) || ($length > 99)) {
|
||||
$length = 8;
|
||||
}
|
||||
|
||||
$text = '';
|
||||
for ($i=0; $i < $length; ++$i) {
|
||||
$text .= chr(rand(32, 126));
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
name = Shortcode Basic Tags
|
||||
description = Provides basic shortcode tags like highlight, dropcap, etc.
|
||||
package = Shortcode
|
||||
core = 7.x
|
||||
dependencies[] = filter
|
||||
dependencies[] = shortcode
|
||||
; Information added by drupal.org packaging script on 2012-03-10
|
||||
version = "7.x-2.0-alpha1"
|
||||
core = "7.x"
|
||||
project = "shortcode"
|
||||
datestamp = "1331420143"
|
||||
|
||||
@@ -0,0 +1,469 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of hook_shortcode_info().
|
||||
* Using same formatting as hook_filter_info()
|
||||
*/
|
||||
function shortcode_basic_tags_shortcode_info() {
|
||||
$shortcodes['quote'] = array(
|
||||
'title' => t('Quote'),
|
||||
'description' => t('Replace a given text formatted like a quote.'),
|
||||
'process callback' => 'shortcode_basic_tags_shortcode_quote',
|
||||
//'settings callback' => '_shortcode_settings_form', TODO
|
||||
'attributes callback' => "shortcode_basic_tags_quote_attributes",
|
||||
'tips callback' => 'shortcode_basic_tags_shortcode_quote_tip',
|
||||
);
|
||||
$shortcodes['img'] = array(
|
||||
'title' => t('Image'),
|
||||
'description' => t('Show a image.'),
|
||||
'process callback' => 'shortcode_basic_tags_shortcode_img',
|
||||
//'settings callback' => '_shortcode_settings_form', TODO
|
||||
'tips callback' => 'shortcode_basic_tags_shortcode_img_tip',
|
||||
);
|
||||
$shortcodes['highlight'] = array(
|
||||
'title' => t('Highlight'),
|
||||
'description' => t('Insert a span around the text with highlight css class.'),
|
||||
'process callback' => 'shortcode_basic_tags_shortcode_highlight',
|
||||
//'settings callback' => '_shortcode_settings_form', TODO
|
||||
'tips callback' => 'shortcode_basic_tags_shortcode_highlight_tip',
|
||||
);
|
||||
$shortcodes['button'] = array(
|
||||
'title' => t('Button'),
|
||||
'description' => t('Insert a link formatted like a button.'),
|
||||
'process callback' => 'shortcode_basic_tags_shortcode_button',
|
||||
//'settings callback' => '_shortcode_settings_form', TODO
|
||||
'tips callback' => 'shortcode_basic_tags_shortcode_button_tip',
|
||||
);
|
||||
$shortcodes['dropcap'] = array(
|
||||
'title' => t('Dropcap'),
|
||||
'description' => t('Replace a given text formatted like a dropcap.'),
|
||||
'process callback' => 'shortcode_basic_tags_shortcode_dropcap',
|
||||
//'settings callback' => '_shortcode_settings_form', TODO
|
||||
'tips callback' => 'shortcode_basic_tags_shortcode_dropcap_tip',
|
||||
);
|
||||
$shortcodes['item'] = array(
|
||||
'title' => t('Item'),
|
||||
'description' => t('Insert div or span around the text with some css classes.'),
|
||||
'process callback' => 'shortcode_basic_tags_shortcode_item',
|
||||
//'settings callback' => '_shortcode_settings_form', TODO
|
||||
'tips callback' => 'shortcode_basic_tags_shortcode_item_tip',
|
||||
);
|
||||
$shortcodes['clear'] = array(
|
||||
'title' => t('Clear'),
|
||||
'description' => t('Insert a clearer div for a proper layout.'),
|
||||
'process callback' => 'shortcode_basic_tags_shortcode_clear',
|
||||
//'settings callback' => '_shortcode_settings_form', TODO
|
||||
'tips callback' => 'shortcode_basic_tags_shortcode_clear_tip',
|
||||
);
|
||||
$shortcodes['link'] = array(
|
||||
'title' => t('Link'),
|
||||
'description' => t('Makes an aliased link to the given path.'),
|
||||
'process callback' => 'shortcode_basic_tags_shortcode_link',
|
||||
//'settings callback' => '_shortcode_settings_form', TODO
|
||||
'tips callback' => 'shortcode_basic_tags_shortcode_link_tip',
|
||||
);
|
||||
|
||||
return $shortcodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_theme().
|
||||
*/
|
||||
function shortcode_basic_tags_theme() {
|
||||
return array(
|
||||
'shortcode_button' => array(
|
||||
'variables' => array('link' => '#', 'text' => '', 'class' => 'button'),
|
||||
),
|
||||
'shortcode_quote' => array(
|
||||
'variables' => array('text' => '', 'author' => FALSE, 'class' => 'quote'),
|
||||
),
|
||||
'shortcode_img' => array(
|
||||
'variables' => array('src' => '', 'alt' => '', 'class' => 'img'),
|
||||
),
|
||||
'shortcode_dropcap' => array(
|
||||
'variables' => array('text' => '', 'class' => 'dropcap'),
|
||||
),
|
||||
'shortcode_item' => array(
|
||||
'variables' => array('text' => '', 'id' => '', 'class' => '', 'type' => 'div'),
|
||||
),
|
||||
'shortcode_clear' => array(
|
||||
'variables' => array('text' => '', 'id' => '', 'class' => '', 'type' => 'div'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a span around the text with highlight css class
|
||||
*
|
||||
* Calling
|
||||
* [highlight]text[/highlight]
|
||||
*
|
||||
*
|
||||
* If the length empty or invalid, between 1-99, the length will be 8
|
||||
*
|
||||
*/
|
||||
function shortcode_basic_tags_shortcode_highlight($attrs, $text) {
|
||||
$attrs = shortcode_attrs(array(
|
||||
'class' => '',
|
||||
),
|
||||
$attrs
|
||||
);
|
||||
|
||||
$class = shortcode_add_class($attrs['class'], 'highlight');
|
||||
return '<span class="' . $class . '">' . $text . '</span>';
|
||||
}
|
||||
|
||||
function shortcode_basic_tags_shortcode_highlight_tip($format, $long) {
|
||||
$output = array();
|
||||
$output[] = '<p><strong>' . t('[highlight (class="additional class")]text[/highlight]') . '</strong> ';
|
||||
if ($long) {
|
||||
$output[] = t('Inserts span.highlight around the text.') . '</p>';
|
||||
$output[] = '<p>' . t('Sample css:') . '</p>';
|
||||
$output[] = '
|
||||
<code>
|
||||
span.highlight{
|
||||
background-color:red;
|
||||
}
|
||||
span.highlight2{
|
||||
background-color:cyan;
|
||||
}
|
||||
</code><p> </p>';
|
||||
}
|
||||
else {
|
||||
$output[] = t('Inserts span.highlight around the text. Additional class names can be added by the <em>class</em> parameter.') . '</p>';
|
||||
}
|
||||
|
||||
return implode(' ', $output);
|
||||
}
|
||||
|
||||
function shortcode_basic_tags_shortcode_button($attrs, $text) {
|
||||
$attrs = shortcode_attrs(array(
|
||||
'title' => 'title default',
|
||||
'class' => 'button',
|
||||
'url' => '',
|
||||
'path' => '<front>',
|
||||
),
|
||||
$attrs
|
||||
);
|
||||
|
||||
$class = shortcode_add_class($attrs['class'], 'button');
|
||||
if ($attrs['url']) {
|
||||
$attrs['path'] = $attrs['url'];
|
||||
}
|
||||
$path = url($attrs['path']);
|
||||
return theme('shortcode_button', array('path' => $path, 'text' => $text, 'class' => $class));
|
||||
}
|
||||
|
||||
function shortcode_basic_tags_shortcode_button_tip($format, $long) {
|
||||
$output = array();
|
||||
$output[] = '<p><strong>' . t('[button path="path" (class="additional class")]text[/button]') . '</strong> ';
|
||||
if ($long) {
|
||||
$output[] = t('Inserts a link formatted like a button. Use url parameter for the link.'). '</p>';
|
||||
}
|
||||
else {
|
||||
$output[] = t('Inserts a link formatted like a button. The <em>path</em> parameter provides the link target (default is the front page).
|
||||
The <em>title</em> will be formatted as a link title (small tooltip over the link - helps for SEO).
|
||||
Additional class names can be added by the <em>class</em> parameter.') . '</p>';
|
||||
}
|
||||
|
||||
return implode(' ', $output);
|
||||
}
|
||||
|
||||
function theme_shortcode_button($vars) {
|
||||
return '<a href="' . $vars['path'] . '" class="' . $vars['class'] . '"><span>' . $vars['text'] . '</span></a>';
|
||||
}
|
||||
|
||||
|
||||
function shortcode_basic_tags_shortcode_dropcap($attrs, $text) {
|
||||
$attrs = shortcode_attrs( array(
|
||||
'class' => 'dropcap',
|
||||
),
|
||||
$attrs
|
||||
);
|
||||
|
||||
$class = shortcode_add_class($attrs['class'], 'dropcap');
|
||||
return theme('shortcode_dropcap', array('text' => $text, 'class' => $class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme hook for dropcap
|
||||
* @param $text
|
||||
* @param $class
|
||||
*/
|
||||
function theme_shortcode_dropcap($vars) {
|
||||
return '<span class="' . $vars['class'] . '">' . $vars['text'] . '</span>';
|
||||
}
|
||||
|
||||
function shortcode_basic_tags_shortcode_dropcap_tip($format, $long) {
|
||||
$output = array();
|
||||
$output[] = '<p><strong>' . t('[dropcap (class="additional class")]text[/dropcap]') . '</strong> ';
|
||||
if ($long) {
|
||||
$output[] = t('Makes dropcap from the text.') . '</p>';
|
||||
$output[] = '<p>' . t('Sample css:') . '</p>';
|
||||
$output[] = '<code>
|
||||
.dropcap {
|
||||
display:block;
|
||||
float:left;
|
||||
font-size:38px;
|
||||
line-height:38px;
|
||||
vertical-align:baseline;
|
||||
padding-right:5px;
|
||||
}
|
||||
</code><p> </p>';
|
||||
|
||||
}
|
||||
else {
|
||||
$output[] = t('Makes dropcap from the text. Additional class names can be added by the <em>class</em> parameter.') . '</p>';
|
||||
}
|
||||
|
||||
return implode(' ', $output);
|
||||
}
|
||||
|
||||
// FIXME: what for these funcs?
|
||||
//function shortcode_basic_tags_quote_attributes($form, &$form_state) {
|
||||
// $form['class'] = array(
|
||||
// '#title' => t('class'),
|
||||
// '#type' => 'textfield',
|
||||
// );
|
||||
//
|
||||
// return $form;
|
||||
//}
|
||||
//
|
||||
//function shortcode_basic_tags_quote_options_submit($form, &$form_state) {
|
||||
//}
|
||||
|
||||
/**
|
||||
*
|
||||
* Replace a given text formatted like a quote.
|
||||
* @param $attrs
|
||||
* @param $text
|
||||
*/
|
||||
function shortcode_basic_tags_shortcode_quote($attrs, $text) {
|
||||
$attrs = shortcode_attrs(array(
|
||||
'class' => 'quote',
|
||||
'author' => '',
|
||||
),
|
||||
$attrs
|
||||
);
|
||||
|
||||
$class = shortcode_add_class($attrs['class'], 'quote');
|
||||
return theme('shortcode_quote', array('text' => $text, 'author' => $attrs['author'], 'class' => $class));
|
||||
}
|
||||
|
||||
function theme_shortcode_quote($vars) {
|
||||
$output = '';
|
||||
|
||||
if(!empty($vars['author'])) {
|
||||
// Add author
|
||||
$output = '<span class="quote-author">'. t('%name wrote:', array('%name' => $vars['author'])) .'</span>';
|
||||
}
|
||||
$output .= $vars['text'];
|
||||
|
||||
return '<span class="' . $vars['class'] . '">' . $output . '</span>';
|
||||
}
|
||||
|
||||
function shortcode_basic_tags_shortcode_quote_tip($format, $long) {
|
||||
$output = array();
|
||||
$output[] = '<p><strong>' . t('[quote (class="additional class" | author="author name")]text[/quote]') . '</strong> ';
|
||||
if ($long) {
|
||||
$output[] = t('Formats the text like a quote.') . '</p>';
|
||||
$output[] = '<p>' . t('Sample css:') . '</p>';
|
||||
$output[] = '<code>
|
||||
.quote {
|
||||
display:block;
|
||||
float:left;
|
||||
width:30%;
|
||||
margin:20px;
|
||||
margin-left:0;
|
||||
padding:5px 0 5px 20px;
|
||||
font-style:italic;
|
||||
border-left:3px solid #E8E8E8;
|
||||
line-heigh:1.5em;
|
||||
font-size:14px;
|
||||
letter-spacing: 1px;
|
||||
word-spacing: 2px;
|
||||
}
|
||||
|
||||
.quote.right{
|
||||
float:right;
|
||||
margin-right:0;
|
||||
margin-left:20px;
|
||||
}
|
||||
</code><p> </p>';
|
||||
}
|
||||
else {
|
||||
$output[] = t('Formats the text like a quote. Additional class names can be added by the <em>class</em> parameter.') . '</p>';
|
||||
}
|
||||
|
||||
return implode(' ', $output);
|
||||
}
|
||||
|
||||
function shortcode_basic_tags_shortcode_img($attrs, $text) {
|
||||
$attrs = shortcode_attrs(array(
|
||||
'class' => 'img',
|
||||
'alt' => '',
|
||||
),
|
||||
$attrs
|
||||
);
|
||||
|
||||
$class = shortcode_add_class($attrs['class'], 'img');
|
||||
|
||||
return theme('shortcode_img', array('src' => $text, 'alt' => $attrs['alt'], 'class' => $class));
|
||||
}
|
||||
|
||||
function theme_shortcode_img($vars) {
|
||||
return '<img src="'. url($vars['src']) .'" class="' . $vars['class'] . '" alt="' . $vars['alt'] . '"/>';
|
||||
}
|
||||
|
||||
function shortcode_basic_tags_shortcode_img_tip($format, $long) {
|
||||
$output = array();
|
||||
$output[] = '<p><strong>' . t('[img (class="additional class"|alt="alt text")]image url[/img]') . '</strong> ';
|
||||
$output[] = t('Inserts a image based on the given image url.') . '</p>';
|
||||
|
||||
return implode(' ', $output);
|
||||
}
|
||||
|
||||
function shortcode_basic_tags_shortcode_item($attrs, $text) {
|
||||
$attrs = shortcode_attrs( array(
|
||||
'class' => '',
|
||||
'style' => '',
|
||||
'id' => '',
|
||||
'type' => 'div',
|
||||
// ...etc
|
||||
),
|
||||
$attrs
|
||||
);
|
||||
|
||||
switch ($attrs['type']) {
|
||||
case 's':
|
||||
case 'span':
|
||||
$type = 'span';
|
||||
break;
|
||||
|
||||
default:
|
||||
$type = 'div';
|
||||
break;
|
||||
}
|
||||
|
||||
return theme('shortcode_item', array('text' => $text, 'id' => $attrs['id'], 'class' => $attrs['class'], 'type' => $type, 'style' => $attrs['style']));
|
||||
}
|
||||
|
||||
function shortcode_basic_tags_shortcode_item_tip($format, $long) {
|
||||
$output = array();
|
||||
$output[] = '<p><strong>' . t('[item (class="additional class"|id=item id|type=div,d,span,s)]text[/item]') . '</strong> ';
|
||||
if ($long) {
|
||||
$output[] = t('Inserts a html item (type parameter = div or span) around the given text.') . '</p>';
|
||||
$output[] = '<p>' . t('Additional class names can be added by the <em>class</em> parameter. Id parameter gives the html an unique css id.') . '</p>';
|
||||
$output[] = '<p> </p>';
|
||||
}
|
||||
else {
|
||||
$output[] = t('Inserts a html item (div or span) around the given text.') . '</p>';
|
||||
}
|
||||
|
||||
return implode(' ', $output);
|
||||
}
|
||||
|
||||
function theme_shortcode_item($vars) {
|
||||
$id = empty($vars['id']) ? '' : ' id="' . $vars['id'] . '"';
|
||||
$class = empty($vars['class']) ? '' : ' class="' . $vars['class'] . '"';
|
||||
$style = empty($vars['style']) ? '' : ' style="' . $vars['style'] . '"';
|
||||
|
||||
return '<' . $vars['type'] . $id . $class . $style . '>' . $vars['text'] . '</' . $vars['type'] . '>';
|
||||
}
|
||||
|
||||
function shortcode_basic_tags_shortcode_clear($attrs, $text) {
|
||||
$attrs = shortcode_attrs( array(
|
||||
'class' => '',
|
||||
'style' => '',
|
||||
'id' => '',
|
||||
'type' => 'div',
|
||||
// ...etc
|
||||
),
|
||||
$attrs
|
||||
);
|
||||
|
||||
$class = shortcode_add_class($attrs['class'], 'clearfix');
|
||||
|
||||
switch ($attrs['type']) {
|
||||
case 's':
|
||||
case 'span':
|
||||
$type = 'span';
|
||||
break;
|
||||
|
||||
default:
|
||||
$type = 'div';
|
||||
break;
|
||||
}
|
||||
|
||||
return theme('shortcode_clear', array('text' => $text, 'id' => $attrs['id'], 'class' => $class, 'type' => $attrs['type'], 'style' => $attrs['style']));
|
||||
}
|
||||
|
||||
function shortcode_basic_tags_shortcode_clear_tip($format, $long) {
|
||||
$output = array();
|
||||
$output[] = '<p><strong>' . t('[clear (class="additional class"|id=item id|type=div,d,span,s)]text[/clear]') . '</strong>';
|
||||
if ($long) {
|
||||
$output[] = t('Inserts a float clearer html item (type parameter = div or span) around the given text. Use the simple [clear /].') . '</p>';
|
||||
$output[] = '<p>' . t('Additional class names can be added by the <em>class</em> parameter. Id parameter gives the html an unique css id.') . '</p>';
|
||||
$output[] = '<p> </p>';
|
||||
}
|
||||
else {
|
||||
$output[] = t('Inserts a float clearer html item (div or span) around the given text. Use the simple [clear /].') . '</p>';
|
||||
}
|
||||
|
||||
return implode(' ', $output);
|
||||
}
|
||||
|
||||
function theme_shortcode_clear($vars) {
|
||||
$id = empty($vars['id']) ? '' : ' id="' . $vars['id'] . '"';
|
||||
$class = empty($vars['class']) ? '' : ' class="' . $vars['class'] . '"';
|
||||
$style = empty($vars['style']) ? '' : ' style="' . $vars['style'] . '"';
|
||||
|
||||
return '<' . $vars['type'] . $id . $class . $style . '>' . $vars['text'] . '</' . $vars['type'] . '>';
|
||||
}
|
||||
|
||||
/*
|
||||
* Create aliased link
|
||||
*
|
||||
* param $text = the linked text
|
||||
* attr[path] = the path we need aliaded
|
||||
*
|
||||
*/
|
||||
function shortcode_basic_tags_shortcode_link($attrs, $text) {
|
||||
$attrs = shortcode_attrs( array(
|
||||
'path' => '<front>',
|
||||
'title' => '',
|
||||
// ...etc
|
||||
), $attrs
|
||||
);
|
||||
|
||||
$path = url($attrs['path']);
|
||||
if ($text) {
|
||||
$class = empty($class) ? '' : ' class="' . $class . '"';
|
||||
$style = empty($style) ? '' : ' style="' . $style . '"';
|
||||
$id = empty($id) ? '' : ' id="' . $id . '"';
|
||||
if ($attrs['title'] == '<none>') {
|
||||
$title = '';
|
||||
}
|
||||
else {
|
||||
$title = empty($attrs['title']) ? check_plain($text) : check_plain($attrs['title']);
|
||||
$title = ' title="' . $title . '"';
|
||||
}
|
||||
return '<a href="' . $path . '"' . $id . $class . $style . $title . '>' . $text . '</a>';
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
function shortcode_basic_tags_shortcode_link_tip($format, $long) {
|
||||
$output = array();
|
||||
$output[] = '<p><strong>' . t('[link path="the drupal path" (title="link title"|class="additional class"|id=item id|style=css style rules)]text[/link]') . '</strong>';
|
||||
if ($long) {
|
||||
$output[] = t('Inserts an aliased drupal path around the text. You can omit the text and the closing [/link], you gives back the url only.') . '</p>';
|
||||
$output[] = '<p>' . t('Additional class names can be added by the <em>class</em> parameter. Id parameter gives the html an unique css id. In the <em>style</em> parameter you can use your own css definition.') . '</p>';
|
||||
$output[] = '<p> </p>';
|
||||
}
|
||||
else {
|
||||
$output[] = t('Inserts an aliased drupal path around the text. You can omit the text and the closing [/link], you gives back the url only.') . '</p>';
|
||||
}
|
||||
|
||||
return implode(' ', $output);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
name = Shortcode Embed Content Tag
|
||||
description = "Provides a shortcode tag for embedding a node content into text."
|
||||
package = Shortcode
|
||||
core = 7.x
|
||||
dependencies[] = filter
|
||||
dependencies[] = shortcode
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-03-10
|
||||
version = "7.x-2.0-alpha1"
|
||||
core = "7.x"
|
||||
project = "shortcode"
|
||||
datestamp = "1331420143"
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/*
|
||||
* FIXME: Need implement dynamic embedding: make embedding when the content shows
|
||||
*/
|
||||
/**
|
||||
* Implements hook_shortcode_info()
|
||||
*
|
||||
* @return array - The shortcode definition array
|
||||
*
|
||||
*/
|
||||
function shortcode_embed_content_shortcode_info() {
|
||||
$shortcodes['embed_content'] = array(
|
||||
'title' => t('Embed content'),
|
||||
'description' => t('Embed node content into the text.'),
|
||||
'process callback' => 'shortcode_embed_content_shortcode_node',
|
||||
//'settings callback' => '_shortcode_settings_form', TODO
|
||||
'tips callback' => 'shortcode_embed_content_node_tip',
|
||||
'default settings' => array(),
|
||||
);
|
||||
|
||||
return $shortcodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Embed a node content into the text
|
||||
*
|
||||
* Calling
|
||||
* [embed_content nid=X /]
|
||||
*
|
||||
* Other shortcode parameters
|
||||
*
|
||||
* class - additional class to the node
|
||||
*
|
||||
* If no nid given the result will be empty
|
||||
*
|
||||
* TODO: implement view_mode - other than teaser or full!
|
||||
*/
|
||||
function shortcode_embed_content_shortcode_node($attrs, $text) {
|
||||
extract( shortcode_attrs( array(
|
||||
'nid' => 0,
|
||||
'class' => '',
|
||||
'view_mode' => 'full',
|
||||
'show_title' => FALSE,
|
||||
'show_submitted' => FALSE,
|
||||
'show_meta' => FALSE,
|
||||
'show_terms' => FALSE,
|
||||
'show_links' => FALSE,
|
||||
), $attrs ));
|
||||
|
||||
|
||||
if (is_numeric($nid) && $nid) {
|
||||
$node = node_load($nid);
|
||||
// add embedded flag to the node
|
||||
$node->shortcode_embedded = TRUE;
|
||||
if (!$node->status || !node_access('view', $node)) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
|
||||
$params = new stdClass();
|
||||
$params->embedded = TRUE;
|
||||
// fixme: what view modes supported
|
||||
$params->view_mode = $view_mode;
|
||||
$params->show_title = shortcode_bool($show_title);
|
||||
$params->show_meta = shortcode_bool($show_meta);
|
||||
$params->show_submitted = shortcode_bool($show_submitted);
|
||||
$params->show_terms = shortcode_bool($show_terms);
|
||||
$params->show_links = shortcode_bool($show_links);
|
||||
// insert the original attributes to the params
|
||||
$params->attrs = $attrs;
|
||||
$node->shortcode = $params;
|
||||
//$content = node_view($node, $params->view_mode);
|
||||
$content = node_view($node, 'teaser');
|
||||
return render($content);
|
||||
} // shortcode_embed_content_shortcode_node()
|
||||
|
||||
|
||||
function shortcode_embed_content_node_tip($format, $long) {
|
||||
$output = '';
|
||||
$output = '<p><strong>[embed_content nid=nodeid (class="additional class")/]</strong> ';
|
||||
if ($long) {
|
||||
$output .= 'Embed a node by nid into the text. Additional class names can be added by the <em>class</em> parameter.</p>';
|
||||
}
|
||||
else {
|
||||
$output .= 'Embed a node by nid into the text. Additional class names can be added by the <em>class</em> parameter.</p>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
} // shortcode_embed_content_node_tip()
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of hook_preprocess_node()
|
||||
* TODO: implement dynamic embedding!
|
||||
*/
|
||||
function shortcode_embed_content_preprocess_node(&$vars) {
|
||||
if (isset($vars['shortcode']) && $vars['shortcode']->embedded) {
|
||||
$vars['template_files'][] = "node-shortcode--default";
|
||||
$vars['template_files'][] = 'node-shortcode--' . $vars['type'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file node.tpl.php
|
||||
*
|
||||
* Theme implementation to display a node.
|
||||
*
|
||||
* Available variables:
|
||||
* - $title: the (sanitized) title of the node.
|
||||
* - $content: Node body or teaser depending on $teaser flag.
|
||||
* - $picture: The authors picture of the node output from
|
||||
* theme_user_picture().
|
||||
* - $date: Formatted creation date (use $created to reformat with
|
||||
* format_date()).
|
||||
* - $links: Themed links like "Read more", "Add new comment", etc. output
|
||||
* from theme_links().
|
||||
* - $name: Themed username of node author output from theme_username().
|
||||
* - $node_url: Direct url of the current node.
|
||||
* - $terms: the themed list of taxonomy term links output from theme_links().
|
||||
* - $submitted: themed submission information output from
|
||||
* theme_node_submitted().
|
||||
*
|
||||
* Other variables:
|
||||
* - $node: Full node object. Contains data that may not be safe.
|
||||
* - $type: Node type, i.e. story, page, blog, etc.
|
||||
* - $comment_count: Number of comments attached to the node.
|
||||
* - $uid: User ID of the node author.
|
||||
* - $created: Time the node was published formatted in Unix timestamp.
|
||||
* - $zebra: Outputs either "even" or "odd". Useful for zebra striping in
|
||||
* teaser listings.
|
||||
* - $id: Position of the node. Increments each time it's output.
|
||||
*
|
||||
* Node status variables:
|
||||
* - $teaser: Flag for the teaser state.
|
||||
* - $page: Flag for the full page state.
|
||||
* - $promote: Flag for front page promotion state.
|
||||
* - $sticky: Flags for sticky post setting.
|
||||
* - $status: Flag for published status.
|
||||
* - $comment: State of comment settings for the node.
|
||||
* - $readmore: Flags true if the teaser content of the node cannot hold the
|
||||
* main body content.
|
||||
* - $is_front: Flags true when presented in the front page.
|
||||
* - $logged_in: Flags true when the current user is a logged-in member.
|
||||
* - $is_admin: Flags true when the current user is an administrator.
|
||||
*
|
||||
* @see template_preprocess()
|
||||
* @see template_preprocess_node()
|
||||
*/
|
||||
?>
|
||||
<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?> clear-block">
|
||||
|
||||
<?php print $picture ?>
|
||||
|
||||
<?php if (!$page): ?>
|
||||
<h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="meta">
|
||||
<?php if ($submitted): ?>
|
||||
<span class="submitted"><?php print $submitted ?></span>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($terms): ?>
|
||||
<div class="terms terms-inline"><?php print $terms ?></div>
|
||||
<?php endif;?>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<?php print $content ?>
|
||||
</div>
|
||||
|
||||
<?php print $links; ?>
|
||||
</div>
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file node.tpl.php
|
||||
*
|
||||
* Theme implementation to display a node.
|
||||
*
|
||||
* Available variables:
|
||||
* - $title: the (sanitized) title of the node.
|
||||
* - $content: Node body or teaser depending on $teaser flag.
|
||||
* - $picture: The authors picture of the node output from
|
||||
* theme_user_picture().
|
||||
* - $date: Formatted creation date (use $created to reformat with
|
||||
* format_date()).
|
||||
* - $links: Themed links like "Read more", "Add new comment", etc. output
|
||||
* from theme_links().
|
||||
* - $name: Themed username of node author output from theme_username().
|
||||
* - $node_url: Direct url of the current node.
|
||||
* - $terms: the themed list of taxonomy term links output from theme_links().
|
||||
* - $submitted: themed submission information output from
|
||||
* theme_node_submitted().
|
||||
*
|
||||
* Other variables:
|
||||
* - $node: Full node object. Contains data that may not be safe.
|
||||
* - $type: Node type, i.e. story, page, blog, etc.
|
||||
* - $comment_count: Number of comments attached to the node.
|
||||
* - $uid: User ID of the node author.
|
||||
* - $created: Time the node was published formatted in Unix timestamp.
|
||||
* - $zebra: Outputs either "even" or "odd". Useful for zebra striping in
|
||||
* teaser listings.
|
||||
* - $id: Position of the node. Increments each time it's output.
|
||||
*
|
||||
* Node status variables:
|
||||
* - $teaser: Flag for the teaser state.
|
||||
* - $page: Flag for the full page state.
|
||||
* - $promote: Flag for front page promotion state.
|
||||
* - $sticky: Flags for sticky post setting.
|
||||
* - $status: Flag for published status.
|
||||
* - $comment: State of comment settings for the node.
|
||||
* - $readmore: Flags true if the teaser content of the node cannot hold the
|
||||
* main body content.
|
||||
* - $is_front: Flags true when presented in the front page.
|
||||
* - $logged_in: Flags true when the current user is a logged-in member.
|
||||
* - $is_admin: Flags true when the current user is an administrator.
|
||||
*
|
||||
* @see template_preprocess()
|
||||
* @see template_preprocess_node()
|
||||
*/
|
||||
?>
|
||||
<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?> clear-block">
|
||||
|
||||
<?php print $picture ?>
|
||||
<?php if (!$page): ?>
|
||||
<h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="meta">
|
||||
<?php if ($submitted): ?>
|
||||
<span class="submitted"><?php print $submitted ?></span>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($terms): ?>
|
||||
<div class="terms terms-inline"><?php print $terms ?></div>
|
||||
<?php endif;?>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<?php print $content ?>
|
||||
</div>
|
||||
|
||||
<?php print $links; ?>
|
||||
</div>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Wysiwyg API integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_wysiwyg_plugin().
|
||||
*/
|
||||
function shortcode_wysiwyg_shortcode_wysiwyg_plugin() {
|
||||
$plugins['shortcode_wysiwyg'] = array(
|
||||
'title' => t('Shortcode'),
|
||||
'vendor url' => 'http://drupal.org/project/shortcode',
|
||||
'icon file' => 'insert.png',
|
||||
'icon title' => t('Insert a shortcode'),
|
||||
'settings' => array(),
|
||||
);
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 711 B |
@@ -0,0 +1,152 @@
|
||||
(function ($) {
|
||||
/**
|
||||
* Wysiwyg plugin button implementation for shortcode plugin.
|
||||
*/
|
||||
Drupal.wysiwyg.plugins.shortcode_wysiwyg = {
|
||||
/**
|
||||
* Return whether the passed node belongs to this plugin.
|
||||
*
|
||||
* @param node
|
||||
* The currently focused DOM element in the editor content.
|
||||
*/
|
||||
isNode: function(node) {
|
||||
return ($(node).is('img.shortcode_wysiwyg-shortcode_wysiwyg'));
|
||||
},
|
||||
|
||||
/**
|
||||
* Execute the button.
|
||||
*
|
||||
* @param data
|
||||
* An object containing data about the current selection:
|
||||
* - format: 'html' when the passed data is HTML content, 'text' when the
|
||||
* passed data is plain-text content.
|
||||
* - node: When 'format' is 'html', the focused DOM element in the editor.
|
||||
* - content: The textual representation of the focused/selected editor
|
||||
* content.
|
||||
* @param settings
|
||||
* The plugin settings, as provided in the plugin's PHP include file.
|
||||
* @param instanceId
|
||||
* The ID of the current editor instance.
|
||||
*/
|
||||
invoke: function(data, settings, instanceId) {
|
||||
/*
|
||||
if (data.format == 'html') {
|
||||
var content = this._getPlaceholder(settings);
|
||||
}
|
||||
else {
|
||||
var content = '<!--shortcode_wysiwyg-->';
|
||||
}
|
||||
*/
|
||||
Drupal.wysiwyg.plugins.shortcode_wysiwyg.insert_form(data, settings, instanceId);
|
||||
},
|
||||
|
||||
|
||||
insert_form: function (data, settings, instanceId) {
|
||||
form_id = Drupal.settings.shortcode_wysiwyg.current_form;
|
||||
// Location, where to fetch the dialog.
|
||||
var aurl = Drupal.settings.basePath + 'index.php?q=shortcode_wysiwyg/'+ Drupal.wysiwyg.instances[instanceId].format +'/' + form_id;
|
||||
dialogdiv = jQuery('<div id="shortcode-insert-dialog"></div>');
|
||||
dialogdiv.load(aurl + " .content #shortcode-wysiwyg-form", function(){
|
||||
var dialogClose = function () {
|
||||
try {
|
||||
dialogdiv.dialog('destroy').remove();
|
||||
} catch (e) {};
|
||||
};
|
||||
btns = {};
|
||||
btns[Drupal.t('Insert shortcode')] = function () {
|
||||
|
||||
var shortcode = dialogdiv.contents().find('#edit-shortcode option:selected').val();
|
||||
var editor_id = instanceId;
|
||||
|
||||
var options = [];
|
||||
dialogdiv.contents().find('input,select')
|
||||
.not('#edit-shortcode,[type="hidden"]')
|
||||
.each(function () {
|
||||
var name = $(this).attr('name'), val = $(this).val();
|
||||
if (val.length) {
|
||||
options.push(name + '=' + val);
|
||||
}
|
||||
});
|
||||
|
||||
shortcode = '[' + shortcode + (options.length ? ' ' + options.join(' ') : '') + ']'+ data.content +'[/' + shortcode + ']';
|
||||
|
||||
Drupal.wysiwyg.plugins.shortcode_wysiwyg.insertIntoEditor(shortcode, editor_id);
|
||||
jQuery(this).dialog("close");
|
||||
|
||||
};
|
||||
|
||||
btns[Drupal.t('Cancel')] = function () {
|
||||
jQuery(this).dialog("close");
|
||||
};
|
||||
|
||||
dialogdiv.dialog({
|
||||
modal: true,
|
||||
autoOpen: false,
|
||||
closeOnEscape: true,
|
||||
resizable: false,
|
||||
draggable: false,
|
||||
autoresize: true,
|
||||
namespace: 'jquery_ui_dialog_default_ns',
|
||||
dialogClass: 'jquery_ui_dialog-dialog',
|
||||
title: Drupal.t('Insert shortcode'),
|
||||
buttons: btns,
|
||||
width: 700,
|
||||
close: dialogClose
|
||||
});
|
||||
dialogdiv.dialog("open");
|
||||
});
|
||||
},
|
||||
|
||||
insertIntoEditor: function (shortcode, editor_id) {
|
||||
Drupal.wysiwyg.instances[editor_id].insert(shortcode);
|
||||
},
|
||||
|
||||
/**
|
||||
* Prepare all plain-text contents of this plugin with HTML representations.
|
||||
*
|
||||
* Optional; only required for "inline macro tag-processing" plugins.
|
||||
*
|
||||
* @param content
|
||||
* The plain-text contents of a textarea.
|
||||
* @param settings
|
||||
* The plugin settings, as provided in the plugin's PHP include file.
|
||||
* @param instanceId
|
||||
* The ID of the current editor instance.
|
||||
*/
|
||||
attach: function(content, settings, instanceId) {
|
||||
content = content.replace(/<!--shortcode_wysiwyg-->/g, this._getPlaceholder(settings));
|
||||
return content;
|
||||
},
|
||||
|
||||
/**
|
||||
* Process all HTML placeholders of this plugin with plain-text contents.
|
||||
*
|
||||
* Optional; only required for "inline macro tag-processing" plugins.
|
||||
*
|
||||
* @param content
|
||||
* The HTML content string of the editor.
|
||||
* @param settings
|
||||
* The plugin settings, as provided in the plugin's PHP include file.
|
||||
* @param instanceId
|
||||
* The ID of the current editor instance.
|
||||
*/
|
||||
detach: function(content, settings, instanceId) {
|
||||
var $content = $('<div>' + content + '</div>');
|
||||
$.each($('img.shortcode_wysiwyg-shortcode_wysiwyg', $content), function (i, elem) {
|
||||
//...
|
||||
});
|
||||
return $content.html();
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper function to return a HTML placeholder.
|
||||
*
|
||||
* The 'drupal-content' CSS class is required for HTML elements in the editor
|
||||
* content that shall not trigger any editor's native buttons (such as the
|
||||
* image button for this example placeholder markup).
|
||||
*/
|
||||
_getPlaceholder: function (settings) {
|
||||
return '<img src="' + settings.path + '/images/spacer.gif" alt="<--shortcode_wysiwyg->" title="<--shortcode_wysiwyg-->" class="shortcode_wysiwyg-shortcode_wysiwyg drupal-content" />';
|
||||
}
|
||||
};
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,11 @@
|
||||
name = Shortcode wysiwyg EXPERIMENTAL
|
||||
description = "Shortcode wysiwyg integration"
|
||||
core = 7.x
|
||||
package = Shortcode
|
||||
dependencies[] = shortcode
|
||||
; Information added by drupal.org packaging script on 2012-03-10
|
||||
version = "7.x-2.0-alpha1"
|
||||
core = "7.x"
|
||||
project = "shortcode"
|
||||
datestamp = "1331420143"
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This module provides wysiwyg support for shortcodes.
|
||||
*/
|
||||
function shortcode_wysiwyg_wysiwyg_include_directory($type) {
|
||||
switch ($type) {
|
||||
case 'plugins':
|
||||
return $type;
|
||||
}
|
||||
}
|
||||
|
||||
function shortcode_wysiwyg_form_alter(&$form, $form_state, $form_id) {
|
||||
if (strpos($form_id, 'node_form') !== FALSE || strpos($form_id, 'comment') !== FALSE) {
|
||||
drupal_add_library('system', 'ui.dialog');
|
||||
drupal_add_library('system', 'ui.draggable');
|
||||
drupal_add_js(array('shortcode_wysiwyg' => array('current_form' => $form['form_build_id']['#value'])), 'setting');
|
||||
}
|
||||
}
|
||||
|
||||
function shortcode_wysiwyg_menu() {
|
||||
$items = array();
|
||||
$items['shortcode_wysiwyg/%/%'] = array(
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('shortcode_wysiwyg_form', 1, 2),
|
||||
'access callback' => TRUE,
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
function shortcode_wysiwyg_form($form, &$form_state, $format_id) {
|
||||
$options = $form = array();
|
||||
module_load_include('inc', 'shortcode', 'shortcode');
|
||||
drupal_set_title(t('Shortcode'));
|
||||
|
||||
$format_id = str_replace("format", "", $format_id); /// euhj...wtf...
|
||||
$shortcodes = shortcode_list_all_enabled($format_id);
|
||||
|
||||
foreach($shortcodes as $name => $shortcode) {
|
||||
$options[$name] = $shortcode['title'];
|
||||
}
|
||||
|
||||
$form['shortcode'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Choose the shortcode you want to insert.'),
|
||||
'#options' => $options,
|
||||
'#description' => t('This shortcode will be inserted in your textfield')
|
||||
);
|
||||
|
||||
foreach($shortcodes as $name => $shortcode) {
|
||||
if ($shortcode['attributes callback']) {
|
||||
$form[$name] = call_user_func_array($shortcode['attributes callback'], array(array(), $form_state));
|
||||
}
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
Reference in New Issue
Block a user