diff --git a/build b/build index afed81c..1623d55 160000 --- a/build +++ b/build @@ -1 +1 @@ -Subproject commit afed81c36d88c37e5d53bea219a871781d50c525 +Subproject commit 1623d55bd130a1ddd2e0318bc5a2dca24463fc51 diff --git a/build.properties b/build.properties index c12f035..edd25f1 100644 --- a/build.properties +++ b/build.properties @@ -5,47 +5,10 @@ phing.project.name = drupal-jenkins-demo drupal.version = 7 # The install profile to use drupal.profile = standard -# The database url to use for site installs -drupal.db.url = sqlite:${project.drupal.dir}/database.sqlite - -# Options to build the project using drush_make -# The make file for the project -# drupal.make.file = name-of-project.make -# Whether to include core or not -# drupal.make.nocore = 1 -# The directory to make the site in relative to the project root directory -# drupal.make.dir = site # The directory containing the modules and themes for the project relative to the drupal root directory project.code.dir = sites/all # A common prefix for modules developed for the site e.g. your_prefix_your_module -project.code.prefix = your_prefix +project.code.prefix = token # The names of other modules and themes developed for the site seperated by whitespace -project.code.custom = colorbox - -# The repository to clone for Phing PHPLoc task -phing.phploc.repository = https://github.com/raphaelstolt/phploc-phing.git - -# The repository to clone for Phing Drush task -phing.drush.repository = http://git.drupal.org/sandbox/mongolito404/1157574.git - -# The repository to clone for PHP CodeSniffer coding standards task -# NB: This is only required if using the phpcs target / PHP_Codesniffer -phpcs.drupalcs.repository = https://github.com/ericduran/drupalcs.git - -# The url to the jslint4java to use -jslint4java.url = http://jslint4java.googlecode.com/files/jslint4java-2.0.0-dist.zip - -# The version of jslint to use -jslint.repository = https://github.com/mikewest/JSLint.git -# The file within the repository containing jslint -jslint.file = fulljslint.js - -# The version of csslint to use -csslint.repository = https://github.com/stubbornella/csslint.git -# The csslint rules to use -# The current selection is based on discussion here: http://mattwilcox.net/archive/entry/id/1054/ -csslint.rules = empty-rules,display-property-grouping,zero-units,vendor-prefix,gradients,box-model,import,important,compatible-vendor-prefixes,duplicate-properties - -# The url from where to download rhino -rhino.url = http://ftp.mozilla.org/pub/mozilla.org/js/rhino1_7R3.zip +project.code.custom = token \ No newline at end of file diff --git a/sites/all/modules/colorbox/LICENSE.txt b/sites/all/modules/colorbox/LICENSE.txt deleted file mode 100644 index 2c095c8..0000000 --- a/sites/all/modules/colorbox/LICENSE.txt +++ /dev/null @@ -1,274 +0,0 @@ -GNU GENERAL PUBLIC LICENSE - - Version 2, June 1991 - -Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, -Cambridge, MA 02139, 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 Library 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 diff --git a/sites/all/modules/colorbox/README.txt b/sites/all/modules/colorbox/README.txt deleted file mode 100644 index 0a972a2..0000000 --- a/sites/all/modules/colorbox/README.txt +++ /dev/null @@ -1,160 +0,0 @@ -Drupal colorbox module: ------------------------- -Maintainers: - Fredrik Jonsson (http://drupal.org/user/5546) - Joe Wheaton (http://drupal.org/user/298179) -Requires - Drupal 7 -License - GPL (see LICENSE) - - -Overview: --------- -Colorbox is a lightweight customizable lightbox plugin for jQuery -1.3 and 1.4. This module allows for integration of Colorbox into Drupal. -The jQuery library is a part of Drupal since version 5+. - -Images, forms, iframed or inline content etc. can be displayed in a -overlay above the current page. - -* jQuery - http://jquery.com/ -* Colorbox - http://colorpowered.com/colorbox/ - - -Features: ---------- - -The Colorbox module: - -* Excellent integration with Image field and Image styles -* Choose between a default style and 5 example styles that are included. -* Style the Colorbox with a custom colorbox.css file in your theme. -* Option to open a login form by clicking on any login link -* Simple API to open any form in a Colorbox -* Drush command to download and install the Colorbox plugin in - sites/all/libraries - -The Colorbox plugin: - -* Supports images, image groups, slideshow, ajax, inline, and - iframed content. -* Appearance is controlled through CSS so users can restyle the box. -* Preloads background images and can preload upcoming images in a - photo group. -* Generates W3C valid XHTML and adds no JS global variables and - passes JSLint. -* Tested in Firefox 2 & 3, Safari 3 & 4, Opera 9, Chrome, - Internet Explorer 6, 7, 8. -* Released under the MIT License. - - -Installation: ------------- -1. Download and unpack the Colorbox plugin in "sites/all/libraries". - Link: http://colorpowered.com/colorbox/colorbox.zip - Drush users can use the command "drush colorbox-plugin". -2. Download and unpack the Colorbox module directory in your modules folder - (this will usually be "sites/all/modules/"). -3. Go to "Administer" -> "Modules" and enable the module. - -If you want to use Colorbox with the Embedded Media Field module -please check "Enable Colorbox load" in the settings. - - -Configuration: -------------- -Go to "Configuration" -> "Media" -> "Colorbox" to find -all the configuration options. - - -Use the Views Colorbox Trigger field: ------------------------------------- -TODO - - -Add a custom Colorbox style to your theme: ----------------------------------------- -The easiest is to start with either the default style or one of the -example styles from the Colorbox plugin. Simply copy the whole -style folder to the theme and rename it and the files to -something logical. - -Add entries in the themes info file for the Colorbox CSS/JS files. - -In the Colorbox settings select "None" as style. This will leave the -styling of Colorbox up to your theme. - - -Load content in a Colorbox: ----------------------------------- -Check the "Enable Colorbox load" option in Colorbox settings. - -This enables custom links that can open content in a Colorbox. Add the class "colorbox-load" to the link and build the url like this "[path]?width=500&height=500&iframe=true" or "[path]?width=500&height=500" if you don't want an iframe. - -Other modules may activate this for easy Colorbox integration. - - -Load inline content in a Colorbox: ----------------------------------- -Check the "Enable Colorbox inline" option in Colorbox settings. - -This enables custom links that can open inline content in a Colorbox. Inline in this context means some part/tag of the current page, e.g. a div. Replace "id-of-content" with the id of the tag you want to open. - -Add the class "colorbox-inline" to the link and build the url like this "?width=500&height=500&inline=true#id-of-content". - -Other modules may activate this for easy Colorbox integration. - - -Load a selection of forms in a Colorbox: ----------------------------------------- -Check the "Enable Colorbox load" option in Colorbox settings. - -The following form_id can be used: -* contact_site_form -* user_login -* user_login_block -* user_register -* user_pass - -The links to open a form needs the class "colorbox-load". The URL should look like this. - -"/colorbox/form/[form_id]?destination=[path_to_send_user_to_after_submit]&width=[with_in_pixel]&height=[height_in_pixel]". - -Here is an example where the user register form is opened in an -500 by 250 pixel Colorbox. - -Create new account - - -Drush: ------- -A Drush command is provides for easy installation of the Colorbox -plugin itself. - -% drush colorbox-plugin - -The command will download the plugin and unpack it in "sites/all/libraries". -It is possible to add another path as an option to the command, but not -recommended unless you know what you are doing. - - -Example styles borders do not display in Internet Explorer: ----------------------------------------------------------- -If you use one of the example styles and have problems with the border -images not loading in Internet Explorer please read -http://colorpowered.com/colorbox/#help_paths. - -The default style in Colorbox module does not have this problem. - - -Contributions: -------------- -* Porting all features from the Thickbox module, - by Fredrik Jonsson (http://drupal.org/user/5546). -* Image module integration improvements by recrit - (http://drupal.org/user/452914). -* Help with testing and many good suggestions by Shane - (http://drupal.org/user/262473). - - -Last updated: ------------- diff --git a/sites/all/modules/colorbox/colorbox-insert-image.tpl.php b/sites/all/modules/colorbox/colorbox-insert-image.tpl.php deleted file mode 100644 index 396c6e4..0000000 --- a/sites/all/modules/colorbox/colorbox-insert-image.tpl.php +++ /dev/null @@ -1,24 +0,0 @@ - tag. - * - __title__: The Title text, intended for use in the tag. - * - __description__: A description of the image, sometimes used as a caption. - */ -?> -__alt__ \ No newline at end of file diff --git a/sites/all/modules/colorbox/colorbox.admin.inc b/sites/all/modules/colorbox/colorbox.admin.inc deleted file mode 100644 index 2aefb2a..0000000 --- a/sites/all/modules/colorbox/colorbox.admin.inc +++ /dev/null @@ -1,369 +0,0 @@ - FALSE)); - - $colorbox_path = colorbox_get_path(); - - $form['colorbox_plugin_settings'] = array( - '#type' => 'fieldset', - '#title' => t('Colorbox plugin settings'), - '#collapsible' => TRUE, - '#collapsed' => TRUE - ); - $form['colorbox_plugin_settings']['colorbox_path'] = array( - '#type' => 'textfield', - '#title' => t('Path'), - '#default_value' => $colorbox_path, - '#description' => t('The location where Colorbox plugin is installed. Relative paths are from the Drupal root directory.'), - '#after_build' => array('_colorbox_admin_settings_check_plugin_path'), - ); - $form['colorbox_plugin_settings']['colorbox_compression_type'] = array( - '#type' => 'radios', - '#title' => t('Choose Colorbox compression level'), - '#options' => array( - 'min' => t('Production (Minified)'), - 'none' => t('Development (Uncompressed Code)'), - ), - '#default_value' => variable_get('colorbox_compression_type', 'min'), - ); - - if (module_exists('image')) { - $form['colorbox_imagefield'] = array( - '#type' => 'fieldset', - '#title' => t('Image field options (CCK)') - ); - $form['colorbox_imagefield']['colorbox_imagefield_gallery'] = array( - '#type' => 'radios', - '#title' => t('Image field gallery'), - '#default_value' => variable_get('colorbox_imagefield_gallery', 1), - '#options' => array(0 => t('Per page gallery'), 1 => t('Per post gallery'), 2 => t('Per field gallery'), 3 => t('No gallery')), - '#description' => t('Should the gallery be images within a single field, a single post (default) or all images on the page. The last option disables galleries.'), - ); - } - - if (module_exists('image_old')) { - $form['colorbox_image_module'] = array( - '#type' => 'fieldset', - '#title' => t('Image module settings'), - ); - $form['colorbox_image_module']['colorbox_auto_image_nodes'] = array( - '#type' => 'radios', - '#title' => t('Image module integration'), - '#options' => array(0 => t('Disabled'), 1 => t('Enabled')), - '#default_value' => variable_get('colorbox_auto_image_nodes', 0), - '#description' => t('Select if Colorbox should be activated for the Image module.'), - ); - $derivative_options = array(); - $sizes = image_get_sizes(); - foreach ($sizes as $label => $size) { - $derivative_options[$label] = $size['label']; - } - $form['colorbox_image_module']['colorbox_image_derivative'] = array( - '#type' => 'select', - '#title' => t('Image derivative'), - '#options' => $derivative_options, - '#default_value' => variable_get('colorbox_image_derivative', 'preview'), - '#description' => t('Select which image derivative to load in the Colorbox.'), - ); - } - - if (module_exists('insert')) { - $form['colorbox_insert_module'] = array( - '#type' => 'fieldset', - '#title' => t('Insert module settings'), - ); - $image_styles = image_style_options(FALSE); - $form['colorbox_insert_module']['colorbox_image_style'] = array( - '#type' => 'select', - '#title' => t('Image style'), - '#empty_option' => t('None (original image)'), - '#options' => $image_styles, - '#default_value' => variable_get('colorbox_image_style', ''), - '#description' => t('Select which image style to use for viewing images in the colorbox.'), - ); - $form['colorbox_insert_module']['colorbox_insert_gallery'] = array( - '#type' => 'radios', - '#title' => t('Insert image gallery'), - '#default_value' => variable_get('colorbox_insert_gallery', 0), - '#options' => array(0 => t('Per page gallery'), 3 => t('No gallery')), - '#description' => t('Should the gallery be all images on the page (default) or disabled.'), - ); - } - - $form['colorbox_login_settings'] = array( - '#type' => 'fieldset', - '#title' => t('Login links settings') - ); - $form['colorbox_login_settings']['colorbox_login'] = array( - '#type' => 'checkbox', - '#title' => t('Enable for login links'), - '#default_value' => variable_get('colorbox_login', 0), - '#description' => t('Automatically activate Colorbox for links to user/login.'), - ); - $form['colorbox_login_settings']['colorbox_login_links'] = array( - '#type' => 'radios', - '#title' => t('Display links'), - '#options' => array(0 => t('No links'), 1 => t('Show links'), 2 => t('Show links and open them in a Colorbox')), - '#default_value' => variable_get('colorbox_login_links', 0), - '#description' => t('Display the "Create new account" (if allowed) and "Request new password" links below the login form.'), - '#after_build' => array('_colorbox_admin_settings_login_links_load'), - '#states' => array( - 'visible' => array( - ':input[name="colorbox_login"]' => array('checked' => TRUE), - ), - ), - ); - - $form['colorbox_extra_settings'] = array( - '#type' => 'fieldset', - '#title' => t('Extra settings'), - ); - $form['colorbox_extra_settings']['colorbox_load'] = array( - '#type' => 'checkbox', - '#title' => t('Enable Colorbox load'), - '#default_value' => variable_get('colorbox_load', 0), - '#description' => t('This enables custom links that can open forms and paths in a Colorbox. Add the class "colorbox-load" to the link and build the url like this for forms "/colorbox/form/[form_id]?destination=some_path&width=500&height=500" and like this for paths "[path]?width=500&height=500&iframe=true" or "[path]?width=500&height=500" if you don\'t want an iframe. Other modules may activate this for easy Colorbox integration.'), - ); - $form['colorbox_extra_settings']['colorbox_inline'] = array( - '#type' => 'checkbox', - '#title' => t('Enable Colorbox inline'), - '#default_value' => variable_get('colorbox_inline', 0), - '#description' => t('This enables custom links that can open inline content in a Colorbox. Add the class "colorbox-inline" to the link and build the url like this "?width=500&height=500&inline=true#id-of-content". Other modules may activate this for easy Colorbox integration.'), - ); - - $form['colorbox_custom_settings'] = array( - '#type' => 'fieldset', - '#title' => t('Styles and options'), - ); - $colorbox_styles = array( - 'default' => t('Default'), - 'stockholmsyndrome' => t('Stockholm Syndrome'), - $colorbox_path . '/example1' => t('Example 1'), - $colorbox_path . '/example2' => t('Example 2'), - $colorbox_path . '/example3' => t('Example 3'), - $colorbox_path . '/example4' => t('Example 4'), - $colorbox_path . '/example5' => t('Example 5'), - 'none' => t('None'), - ); - $form['colorbox_custom_settings']['colorbox_style'] = array( - '#type' => 'select', - '#title' => t('Style'), - '#options' => $colorbox_styles, - '#default_value' => variable_get('colorbox_style', 'default'), - '#description' => t('Select the style to use for the Colorbox. The example styles are the ones that come with the Colorbox plugin. Select "None" if you have added Colorbox styles to your theme.'), - ); - $form['colorbox_custom_settings']['colorbox_custom_settings_activate'] = array( - '#type' => 'radios', - '#title' => t('Options'), - '#options' => array(0 => t('Default'), 1 => t('Custom')), - '#default_value' => variable_get('colorbox_custom_settings_activate', 0), - '#description' => t('Use the default or custom options for Colorbox.'), - '#prefix' => '
', - '#suffix' => '
', - ); - - $js_hide = variable_get('colorbox_custom_settings_activate', 0) ? '' : ' js-hide'; - $form['colorbox_custom_settings']['wrapper_start'] = array( - '#markup' => '
', - ); - - $form['colorbox_custom_settings']['colorbox_transition_type'] = array( - '#type' => 'radios', - '#title' => t('Transition type'), - '#options' => array('elastic' => t('Elastic'), 'fade' => t('Fade'), 'none' => t('None')), - '#default_value' => variable_get('colorbox_transition_type', 'elastic'), - '#description' => t('The transition type.'), - ); - $form['colorbox_custom_settings']['colorbox_transition_speed'] = array( - '#type' => 'select', - '#title' => t('Transition speed'), - '#options' => drupal_map_assoc(array(100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600)), - '#default_value' => variable_get('colorbox_transition_speed', 350), - '#description' => t('Sets the speed of the fade and elastic transitions, in milliseconds.'), - ); - $form['colorbox_custom_settings']['colorbox_opacity'] = array( - '#type' => 'select', - '#title' => t('Opacity'), - '#options' => drupal_map_assoc(array('0', '0.10', '0.15', '0.20', '0.25', '0.30', '0.35', '0.40', '0.45', '0.50', '0.55', '0.60', '0.65', '0.70', '0.75', '0.80', '0.85', '0.90', '0.95', '1')), - '#default_value' => variable_get('colorbox_opacity', '0.85'), - '#description' => t('The overlay opacity level. Range: 0 to 1.'), - ); - $form['colorbox_custom_settings']['colorbox_text_current'] = array( - '#type' => 'textfield', - '#title' => t('Current'), - '#default_value' => variable_get('colorbox_text_current', '{current} of {total}'), - '#size' => 30, - '#description' => t('Text format for the content group / gallery count. {current} and {total} are detected and replaced with actual numbers while Colorbox runs.'), - ); - $form['colorbox_custom_settings']['colorbox_text_previous'] = array( - '#type' => 'textfield', - '#title' => t('Previous'), - '#default_value' => variable_get('colorbox_text_previous', '« Prev'), - '#size' => 30, - '#description' => t('Text for the previous button in a shared relation group.'), - ); - $form['colorbox_custom_settings']['colorbox_text_next'] = array( - '#type' => 'textfield', - '#title' => t('Next'), - '#default_value' => variable_get('colorbox_text_next', 'Next »'), - '#size' => 30, - '#description' => t('Text for the next button in a shared relation group.'), - ); - $form['colorbox_custom_settings']['colorbox_text_close'] = array( - '#type' => 'textfield', - '#title' => t('Close'), - '#default_value' => variable_get('colorbox_text_close', 'Close'), - '#size' => 30, - '#description' => t('Text for the close button. The "Esc" key will also close Colorbox.'), - ); - $form['colorbox_custom_settings']['colorbox_overlayclose'] = array( - '#type' => 'checkbox', - '#title' => t('Overlay close'), - '#default_value' => variable_get('colorbox_overlayclose', 1), - '#description' => t('Enable closing ColorBox by clicking on the background overlay.'), - ); - $form['colorbox_custom_settings']['colorbox_maxwidth'] = array( - '#type' => 'textfield', - '#title' => t('Max width'), - '#default_value' => variable_get('colorbox_maxwidth', '100%'), - '#size' => 30, - '#description' => t('Set a maximum width for loaded content. Example: "100%", 500, "500px".'), - ); - $form['colorbox_custom_settings']['colorbox_maxheight'] = array( - '#type' => 'textfield', - '#title' => t('Max height'), - '#default_value' => variable_get('colorbox_maxheight', '100%'), - '#size' => 30, - '#description' => t('Set a maximum height for loaded content. Example: "100%", 500, "500px".'), - ); - - $form['colorbox_custom_settings']['colorbox_slideshow_settings'] = array( - '#type' => 'fieldset', - '#title' => t('Slideshow settings'), - '#collapsible' => TRUE, - '#collapsed' => TRUE - ); - $form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_slideshow'] = array( - '#type' => 'radios', - '#title' => t('Slideshow'), - '#options' => array(0 => t('Off'), 1 => t('On')), - '#default_value' => variable_get('colorbox_slideshow', 0), - '#description' => t('An automatic slideshow to a content group / gallery.'), - '#prefix' => '
', - '#suffix' => '
', - ); - - $js_hide = variable_get('colorbox_slideshow', 0) ? '' : ' js-hide'; - $form['colorbox_custom_settings']['colorbox_slideshow_settings']['wrapper_start'] = array( - '#markup' => '
', - ); - - $form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_slideshowauto'] = array( - '#type' => 'checkbox', - '#title' => t('Slideshow autostart'), - '#default_value' => variable_get('colorbox_slideshowauto', 1), - '#description' => t('If the slideshow should automatically start to play.'), - ); - $form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_slideshowspeed'] = array( - '#type' => 'select', - '#title' => t('Slideshow speed'), - '#options' => drupal_map_assoc(array(1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000)), - '#default_value' => variable_get('colorbox_slideshowspeed', 2500), - '#description' => t('Sets the speed of the slideshow, in milliseconds.'), - ); - $form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_text_start'] = array( - '#type' => 'textfield', - '#title' => t('Start slideshow'), - '#default_value' => variable_get('colorbox_text_start', 'start slideshow'), - '#size' => 30, - '#description' => t('Text for the slideshow start button.'), - ); - $form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_text_stop'] = array( - '#type' => 'textfield', - '#title' => t('Stop slideshow'), - '#default_value' => variable_get('colorbox_text_stop', 'stop slideshow'), - '#size' => 30, - '#description' => t('Text for the slideshow stop button.'), - ); - - $form['colorbox_custom_settings']['colorbox_slideshow_settings']['wrapper_stop'] = array( - '#markup' => '
', - ); - - $form['colorbox_custom_settings']['wrapper_stop'] = array( - '#markup' => '
', - ); - - $form['colorbox_advanced_settings'] = array( - '#type' => 'fieldset', - '#title' => t('Advanced settings'), - '#collapsible' => TRUE, - '#collapsed' => TRUE - ); - $form['colorbox_advanced_settings']['colorbox_title_trim'] = array( - '#type' => 'radios', - '#title' => t('Title shortening'), - '#options' => array(0 => t('Default'), 1 => t('Yes')), - '#default_value' => variable_get('colorbox_title_trim', 0), - '#description' => t('If the title should be made shorter in the Colorbox to avoid layout problems. The default is to shorten for the example styles, they need it, but not for other styles.'), - '#prefix' => '
', - '#suffix' => '
', - ); - $js_hide = variable_get('colorbox_title_trim', 0) ? '' : ' js-hide'; - $form['colorbox_advanced_settings']['colorbox_title_trim_length'] = array( - '#type' => 'select', - '#title' => t('Title max length'), - '#options' => drupal_map_assoc(array(40, 45, 50, 55, 60, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120)), - '#default_value' => variable_get('colorbox_title_trim_length', 75), - '#prefix' => '
', - '#suffix' => '
', - ); - $form['colorbox_advanced_settings']['colorbox_pages'] = array( - '#type' => 'textarea', - '#title' => t('Deactivate Colorbox on specific pages'), - '#default_value' => variable_get('colorbox_pages', "admin*\nimg_assist*\nimce*\nnode/add/*\nnode/*/edit"), - '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')), - ); - - return system_settings_form($form); -} - -/** - * Checks if the directory in $form_element exists and contains a file named - * 'jquery.colorbox.js'. If validation fails, the form element is flagged - * with an error from within the file_check_directory function. - * - * @param $form_element - * The form element containing the name of the directory to check. - */ -function _colorbox_admin_settings_check_plugin_path($form_element) { - $library_path = $form_element['#value']; - if (!is_dir($library_path) || !(file_exists($library_path . '/colorbox/jquery.colorbox.js') && file_exists($library_path . '/colorbox/jquery.colorbox-min.js'))) { - form_set_error($form_element['#parents'][0], t('You need to download the !colorbox and extract the entire contents of the archive into the %path folder of your server.', array('!colorbox' => l(t('Colorbox plugin'), 'http://colorpowered.com/colorbox/'), '%path' => $library_path))); - } - - return $form_element; -} - -/** - * Enable the Colorbox load feature of the links are set to open in a - * Colorbox. - */ -function _colorbox_admin_settings_links_load($form_element) { - $links = $form_element['#value']; - if ($links == 2) { - db_query("DELETE FROM {variable} WHERE name LIKE 'colorbox_load_$links'"); - variable_set('colorbox_load_'.$links, 1); - } - - return $form_element; -} diff --git a/sites/all/modules/colorbox/colorbox.api.php b/sites/all/modules/colorbox/colorbox.api.php deleted file mode 100644 index 37f11ad..0000000 --- a/sites/all/modules/colorbox/colorbox.api.php +++ /dev/null @@ -1,47 +0,0 @@ -=')) { - $requirements['colorbox_plugin'] = array( - 'title' => $t('Colorbox plugin'), - 'severity' => REQUIREMENT_OK, - 'value' => $colorbox_version, - ); - } - else { - $requirements['colorbox_plugin'] = array( - 'title' => $t('Colorbox plugin'), - 'value' => $t('At least @a', array('@a' => COLORBOX_MIN_PLUGIN_VERSION)), - 'severity' => REQUIREMENT_ERROR, - 'description' => $t('You need to download the !colorbox and extract the entire contents of the archive into the %path folder of your server.', array('!colorbox' => l(t('Colorbox plugin'), 'http://colorpowered.com/colorbox/'), '%path' => $library_path)), - ); - } - } - - return $requirements; -} - -/** - * Implements hook_uninstall(). - */ -function colorbox_uninstall() { - db_query("DELETE FROM {variable} WHERE name LIKE 'colorbox_%'"); -} - -/** - * Delete the unused colorbox_login_form variabel. - */ -function colorbox_update_7001() { - $ret = array(); - variable_del('colorbox_login_form'); - - return $ret; -} diff --git a/sites/all/modules/colorbox/colorbox.make.example b/sites/all/modules/colorbox/colorbox.make.example deleted file mode 100644 index 1aa9e93..0000000 --- a/sites/all/modules/colorbox/colorbox.make.example +++ /dev/null @@ -1,9 +0,0 @@ -; $Id$ - -core = 7.x -api = 2 - -libraries[colorbox][download][type] = "get" -libraries[colorbox][download][url] = "http://colorpowered.com/colorbox/colorbox.zip" -libraries[colorbox][directory_name] = "colorbox" -libraries[colorbox][destination] = "libraries" diff --git a/sites/all/modules/colorbox/colorbox.module b/sites/all/modules/colorbox/colorbox.module deleted file mode 100644 index 8414150..0000000 --- a/sites/all/modules/colorbox/colorbox.module +++ /dev/null @@ -1,511 +0,0 @@ - array( - 'variables' => array( - 'image' => array(), - 'path' => NULL, - 'title' => NULL, - 'gid' => NULL, - ), - 'file' => 'colorbox.theme.inc', - ), - - 'colorbox_insert_image' => array( - 'variables' => array( - 'item' => NULL, - 'widget' => NULL, - ), - 'template' => 'colorbox-insert-image', - 'file' => 'colorbox.theme.inc', - ), - - 'colorbox_image_formatter' => array( - 'variables' => array( - 'item' => NULL, - 'node' => NULL, - 'field' => array(), - 'colorbox_node_style' => NULL, - 'colorbox_image_style' => NULL, - ), - 'file' => 'colorbox.theme.inc', - ), - ); -} - -/** - * Implements hook_init(). - */ -function colorbox_init() { - // Do not load colorbox during the Drupal installation process, e.g. if part - // of installation profiles. - if (!drupal_installation_attempted()) { - _colorbox_doheader(); - } -} - -/** - * Implements hook_views_api(). - */ -function colorbox_views_api() { - return array( - 'api' => 2, - 'path' => drupal_get_path('module', 'colorbox') . '/views', - ); -} - -/** - * Implements hook_menu(). - */ -function colorbox_menu() { - $items = array(); - - $items['admin/config/media/colorbox'] = array( - 'title' => 'Colorbox', - 'description' => 'Adjust Colorbox settings.', - 'file' => 'colorbox.admin.inc', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('colorbox_admin_settings'), - 'access arguments' => array('administer site configuration'), - ); - $items['user/login/colorbox'] = array( - 'title' => 'Login', - 'page callback' => 'colorbox_login', - 'access callback' => 'user_is_anonymous', - 'type' => MENU_CALLBACK, - 'file' => 'colorbox.pages.inc', - ); - $items['colorbox/form'] = array( - 'title' => 'Form', - 'page callback' => 'colorbox_form_page', - 'page arguments' => array(2), - 'access callback' => '_colorbox_form_page_access', - 'access arguments' => array(2), - 'type' => MENU_CALLBACK, - 'file' => 'colorbox.pages.inc', - ); - - return $items; -} - -/** - * Colorbox menu access check. - */ -function _colorbox_form_page_access($form_id) { - $access = FALSE; - - // First check if this is one of the forms Colorbox support out of the box. - switch ($form_id) { - case 'contact_site_form': - $access = user_access('access site-wide contact form'); - break; - case 'user_register_form': - $access = user_register_access(); - break; - case 'user_pass': - case 'user_login': - case 'user_login_block': - $access = user_is_anonymous(); - break; - } - - // Invoke hook_colorbox_form_access for all modules. - if (!$access) { - foreach (module_implements('colorbox_form_access') as $module) { - if ($access = module_invoke($module, 'colorbox_form_access', $form_id)) { - return $access; - } - } - } - - return $access; -} - -/** - * Check if Colorbox should be active for the current URL. - * - * @return - * TRUE if Colorbox should be active for the current page. - */ -function _colorbox_active() { - // Code from the block_list funtion in block.module. - $path = drupal_get_path_alias($_GET['q']); - $colorbox_pages = variable_get('colorbox_pages', "admin*\nimg_assist*\nimce*\nnode/add/*\nnode/*/edit"); - // Compare with the internal and path alias (if any). - $page_match = drupal_match_path($path, $colorbox_pages); - if ($path != $_GET['q']) { - $page_match = $page_match || drupal_match_path($_GET['q'], $colorbox_pages); - } - - return !$page_match; -} - -/** - * Loads the various js and css files. - */ -function _colorbox_doheader() { - static $already_added = FALSE; - if ($already_added) { - return; // Don't add the JavaScript and CSS multiple times. - } - if (!_colorbox_active()) { - return; // Don't add the JavaScript and CSS on specified paths. - } - - // Insert options and translated strings as javascript settings. - if (variable_get('colorbox_custom_settings_activate', 0)) { - $js_settings = array( - 'transition' => variable_get('colorbox_transition_type', 'elastic'), - 'speed' => variable_get('colorbox_transition_speed', 350), - 'opacity' => variable_get('colorbox_opacity', '0.85'), - 'slideshow' => variable_get('colorbox_slideshow', 0) ? TRUE : FALSE, - 'slideshowAuto' => variable_get('colorbox_slideshowauto', 1) ? TRUE : FALSE, - 'slideshowSpeed' => variable_get('colorbox_slideshowspeed', 2500), - 'slideshowStart' => variable_get('colorbox_text_start', 'start slideshow'), - 'slideshowStop' => variable_get('colorbox_text_stop', 'stop slideshow'), - 'current' => variable_get('colorbox_text_current', '{current} of {total}'), - 'previous' => variable_get('colorbox_text_previous', '« Prev'), - 'next' => variable_get('colorbox_text_next', 'Next »'), - 'close' => variable_get('colorbox_text_close', 'Close'), - 'overlayClose' => variable_get('colorbox_overlayclose', 1) ? TRUE : FALSE, - 'maxWidth' => variable_get('colorbox_maxwidth', '100%'), - 'maxHeight' => variable_get('colorbox_maxheight', '100%'), - ); - } - else { - $js_settings = array( - 'opacity' => '0.85', - 'current' => t('{current} of {total}'), - 'previous' => t('« Prev'), - 'next' => t('Next »'), - 'close' => t('Close'), - 'maxWidth' => '100%', - 'maxHeight' => '100%', - ); - } - - $path = drupal_get_path('module', 'colorbox'); - $style = variable_get('colorbox_style', 'default'); - - // Give other modules the possibility to override Colorbox settings and style. - $data = &$js_settings; - $data['__drupal_alter_by_ref'] = array(&$style); - drupal_alter('colorbox_settings', $data); - - drupal_add_js(array('colorbox' => $js_settings), array('type' => 'setting', 'scope' => JS_DEFAULT)); - - if (module_exists('image') && variable_get('colorbox_auto_image_nodes', 0)) { - $image_derivative = variable_get('colorbox_image_derivative', 'preview'); - // If the image derivative is set to IMAGE_ORIGINAL check if the - // user has access before activating Colorbox. - if (!($image_derivative == IMAGE_ORIGINAL && !user_access('view original images'))) { - drupal_add_js(array('colorbox' => array('image_derivative' => $image_derivative)), array('type' => 'setting', 'scope' => JS_DEFAULT)); - drupal_add_js($path . '/js/colorbox_image_module.js'); - } - } - - // Add and initialise the Colorbox plugin. - drupal_add_js(colorbox_get_js()); - drupal_add_js($path . '/js/colorbox.js'); - - // Add JS and CSS based on selected style. - switch ($style) { - case 'none': - break; - case 'default': - drupal_add_css($path . '/styles/default/colorbox_default_style.css'); - drupal_add_js($path . '/styles/default/colorbox_default_style.js'); - break; - case 'stockholmsyndrome': - drupal_add_css($path . '/styles/stockholmsyndrome/colorbox_stockholmsyndrome.css'); - drupal_add_js($path . '/styles/stockholmsyndrome/colorbox_stockholmsyndrome.js'); - break; - default: - drupal_add_css($style . '/colorbox.css'); - } - - if (variable_get('colorbox_load', 0)) { - drupal_add_js($path . '/js/colorbox_load.js'); - } - - if (variable_get('colorbox_inline', 0)) { - drupal_add_js($path . '/js/colorbox_inline.js'); - } - - if ($GLOBALS['user']->uid == 0 && variable_get('colorbox_login', 0)) { - drupal_add_js($path . '/js/colorbox_login.js'); - } - - $already_added = TRUE; -} - -/** - * Return the version of Colorbox plugin that is installed. - * - * This can be used by other modules' hook_requirements() to ensure that the - * proper version of Colorbox plugin is installed. - * - * @see version_compare() - */ -function colorbox_get_version($colorbox_js = NULL) { - $version = 0; - $pattern = '#ColorBox v([0-9\.a-z]+)#'; - - // No file is passed in so use the default location. - if (is_null($colorbox_js)) { - $colorbox_js = colorbox_get_js(); - } - - // Return the version of Colorbox plugin, it it exists. - if (file_exists($colorbox_js)) { - $colorbox_plugin = file_get_contents($colorbox_js, NULL, NULL, 0, 32); - if (preg_match($pattern, $colorbox_plugin, $matches)) { - $version = $matches[1]; - } - } - - return $version; -} - -/** - * Return the JS filename for Colorbox plugin. - * - * @return - * Boolean indicating if the JS is located. - */ -function colorbox_get_js() { - $library_path = colorbox_get_path(); - - if (file_exists($library_path . '/colorbox/jquery.colorbox.js') && file_exists($library_path . '/colorbox/jquery.colorbox-min.js')) { - $colorbox_js_map = array('none' => 'jquery.colorbox.js', 'min' => 'jquery.colorbox-min.js'); - $colorbox_js = $colorbox_js_map[variable_get('colorbox_compression_type', 'min')]; - return $library_path . '/colorbox/' . $colorbox_js; - } -// else { -// drupal_set_message(t('You need to download the !colorbox and extract the entire contents of the archive into the %path folder of your server.', array('!colorbox' => l(t('Colorbox plugin'), 'http://colorpowered.com/colorbox/'), '%path' => $library_path)), 'error', FALSE); -// return FALSE; -// } -} - -/** - * Return the path to the Colorbox plugin. - */ -function colorbox_get_path() { - static $library_path = NULL; - - // Try to locate the library path in any possible setup. - if ($library_path == NULL) { - // First check the default location. - $path = variable_get('colorbox_path', COLORBOX_PATH); - if (is_dir($path . '/colorbox')) { - $library_path = $path; - } - // Ask the libraries module as a fallback. - elseif ($library_path == NULL && module_exists('libraries')) { - if ($path = libraries_get_path('colorbox')) { - $library_path = $path; - variable_set('colorbox_path', $library_path); - } - } - // HACK: If libraries api module is not installed but available, load it. - elseif ($library_path == NULL && file_exists(dirname(__FILE__) . '/../libraries/libraries.module')) { - require_once(dirname(__FILE__) . '/../libraries/libraries.module'); - if ($path = libraries_get_path('colorbox')) { - $library_path = $path; - variable_set('colorbox_path', $library_path); - } - } - // If no path is found suggest the default one. - elseif ($library_path == NULL) { - $library_path = COLORBOX_PATH; - } - } - - return $library_path; -} - -/** - * Implements hook_form_alter(). - * Reformat the login form. - */ -function colorbox_form_alter(&$form, &$form_state, $form_id) { - switch ($form_id) { - case 'user_login': - if (arg(0) == 'user' && arg(1) == 'login' && arg(2) == 'colorbox') { - $form['name']['#size'] = 25; - $form['pass']['#size'] = 25; - - // Add links as needed. - if (variable_get('colorbox_login_links', 0)) { - $items = array(); - // Add standard links. - if (variable_get('colorbox_login_links', 0) == 1) { - if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) { - $items[] = l(t('Create new account'), 'user/register', array('attributes' => array('title' => t('Create a new user account.')))); - } - $items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.')))); - } - // Add links that opens in a Colorbox. - if (variable_get('colorbox_login_links', 0) == 2) { - if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) { - $items[] = l(t('Create new account'), 'colorbox/form/user_register_form', array('query' => array('width' => '300', 'height' => 'auto'), 'attributes' => array('title' => t('Create a new user account.'), 'class' => 'colorbox-load'))); - } - $items[] = l(t('Request new password'), 'colorbox/form/user_pass', array('query' => array('width' => '300', 'height' => '150'), 'attributes' => array('title' => t('Request new password via e-mail.'), 'class' => 'colorbox-load'))); - } - $form['links'] = array('#markup' => theme('item_list', array('items' => $items))); - } - } - break; - case 'user_register_form': - if (arg(0) == 'colorbox' && arg(1) == 'form') { - $form['account']['name']['#size'] = 30; - $form['account']['mail']['#size'] = 30; - } - break; - case 'user_pass': - if (arg(0) == 'colorbox' && arg(1) == 'form') { - $form['name']['#size'] = 30; - } - break; - } -} - -/** - * Implements hook_link_alter(). - */ -function colorbox_link_alter(&$links, $node) { - if ($node->type == 'image' && is_array($node->images) && variable_get('colorbox_auto_image_nodes', 0)) { - // Add a colorbox class to the image link sizes on the image node. - foreach ($node->images as $size => $path) { - $links['image_size_' . $size]['attributes']['class'] = "image image-{$size} colorbox"; - $links['image_size_' . $size]['href'] = $path; - unset($links['image_size_' . $size]['query']); - } - } -} - -/** - * Implements hook_field_formatter_info(). - */ -function colorbox_field_formatter_info() { - return array( - 'colorbox' => array( - 'label' => t('Colorbox'), - 'field types' => array('image'), - 'settings' => array('colorbox_node_style' => '', 'colorbox_image_style' => ''), - ), - ); -} - -/** - * Implements hook_field_formatter_settings_form(). - */ -function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { - $display = $instance['display'][$view_mode]; - $settings = $display['settings']; - - $image_styles = image_style_options(FALSE); - $element['colorbox_node_style'] = array( - '#title' => t('Node image style'), - '#type' => 'select', - '#default_value' => $settings['colorbox_node_style'], - '#empty_option' => t('None (original image)'), - '#options' => $image_styles, - ); - $element['colorbox_image_style'] = array( - '#title' => t('Colorbox image style'), - '#type' => 'select', - '#default_value' => $settings['colorbox_image_style'], - '#empty_option' => t('None (original image)'), - '#options' => $image_styles, - ); - - return $element; -} - -/** - * Implements hook_field_formatter_settings_summary(). - */ -function colorbox_field_formatter_settings_summary($field, $instance, $view_mode) { - $display = $instance['display'][$view_mode]; - $settings = $display['settings']; - - $summary = array(); - - $image_styles = image_style_options(FALSE); - // Unset possible 'No defined styles' option. - unset($image_styles['']); - // Styles could be lost because of enabled/disabled modules that defines - // their styles in code. - if (isset($image_styles[$settings['colorbox_node_style']])) { - $summary[] = t('Node image style: @style', array('@style' => $image_styles[$settings['colorbox_node_style']])); - } - else { - $summary[] = t('Node image style: Original image'); - } - - if (isset($image_styles[$settings['colorbox_image_style']])) { - $summary[] = t('Colorbox image style: @style', array('@style' => $image_styles[$settings['colorbox_image_style']])); - } - else { - $summary[] = t('Colorbox image style: Original image'); - } - - return implode('
', $summary); -} - -/** - * Implements hook_field_formatter_view(). - */ -function colorbox_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { - $element = array(); - - foreach ($items as $delta => $item) { - $element[$delta] = array( - '#theme' => 'colorbox_image_formatter', - '#item' => $item, - '#node' => $entity, - '#field' => $field, - '#colorbox_node_style' => $display['settings']['colorbox_node_style'], - '#colorbox_image_style' => $display['settings']['colorbox_image_style'], - ); - } - - return $element; -} - -/** - * Implements hook_insert_styles(). - */ -function colorbox_insert_styles() { - $insert_styles = array(); - foreach (image_styles() as $key => $style) { - $insert_styles['colorbox__' . $key] = array('label' => 'Colorbox ' . $style['name']); - } - - return $insert_styles; -} - -/** - * Implements hook_insert_content(). - */ -function colorbox_insert_content($item, $style, $widget) { - list($item['module_name'], $item['style_name']) = explode('__', $style['name'], 2); - return theme('colorbox_insert_image', array('item' => $item, 'widget' => $widget)); -} diff --git a/sites/all/modules/colorbox/colorbox.pages.inc b/sites/all/modules/colorbox/colorbox.pages.inc deleted file mode 100644 index 1e0dc9e..0000000 --- a/sites/all/modules/colorbox/colorbox.pages.inc +++ /dev/null @@ -1,39 +0,0 @@ - $item['uri'], - 'alt' => $item['alt'], - 'title' => $item['title'], - 'style_name' => $variables['colorbox_node_style'], - ); - - // If the title is empty use alt or the node title in that order. - if (empty($image['title'])) { - if (!empty($image['alt'])) { - $image['title'] = $image['alt']; - } - elseif (!empty($node->title)) { - $image['title'] = $node->title; - } - } - - // Shorten the title for the example styles or when title shortening is active. - $colorbox_style = variable_get('colorbox_style', 'default'); - $trim_length = variable_get('colorbox_title_trim_length', 75); - if (((strpos($colorbox_style, 'colorbox/example') !== FALSE) || variable_get('colorbox_title_trim', 0)) && (drupal_strlen($item['title']) > $trim_length)) { - $image['title'] = drupal_substr($item['title'], 0, $trim_length - 5) . '...'; - } - - // Build the gallery id. - $nid = !empty($node->nid) ? $node->nid : 'nid'; - switch (variable_get('colorbox_imagefield_gallery', 1)) { - case 0: - $gallery_id = 'gallery-all'; - break; - case 1: - $gallery_id = 'gallery-' . $nid; - break; - case 2: - $gallery_id = 'gallery-' . $nid . '-' . $field['field_name']; - break; - case 3: - $gallery_id = ''; - break; - } - - if ($style_name = $variables['colorbox_image_style']) { - $path = image_style_url($style_name, $image['path']); - } - else { - $path = file_create_url($image['path']); - } - - return theme('colorbox_imagefield', array('image' => $image, 'path' => $path, 'title' => $image['title'], 'gid' => $gallery_id)); -} - -/** - * Returns HTML for an image using a specific Colorbox image style. - * - * @param $variables - * An associative array containing: - * - style_name: The name of the style to be used to alter the original image. - * - path: The path of the image file relative to the Drupal files directory. - * This function does not work with images outside the files directory nor - * with remotely hosted images. - * - alt: The alternative text for text-based browsers. - * - title: The title text is displayed when the image is hovered in some - * popular browsers. - * - gid: Gallery id. - * - attributes: Associative array of attributes to be placed in the img tag. - * - getsize: If set to TRUE, the image's dimension are fetched and added as - * width/height attributes. - * - * @ingroup themeable - */ -function theme_colorbox_imagefield($variables) { - if (!empty($variables['image']['style_name'])) { - $image = theme('image_style', $variables['image']); - } - else { - $image = theme('image', $variables['image']); - } - - $options = array( - 'html' => TRUE, - 'attributes' => array( - 'title' => $variables['title'], - 'class' => 'colorbox imagefield imagefield-imagelink', - 'rel' => $variables['gid'], - ) - ); - - return l($image, $variables['path'], $options); -} - -/** - * Preprocess variables for the colorbox-insert-image.tpl.php file. - */ -function template_preprocess_colorbox_insert_image(&$variables) { - $file = file_load($variables['item']['fid']); - - $variables['image_path'] = image_style_url($variables['item']['style_name'], $file->uri); - - if ($style_name = variable_get('colorbox_image_style', '')) { - $variables['link_path'] = image_style_url($style_name, $file->uri); - } - else { - $variables['link_path'] = file_create_url($file->uri); - } - - $variables['class'] = $variables['widget']['settings']['insert_class']; - - $variables['gallery_id'] = ''; - switch (variable_get('colorbox_insert_gallery', 0)) { - case 0: - case 1: - case 2: - $variables['gallery_id'] = 'gallery-all'; - break; - case 3: - $variables['gallery_id'] = ''; - break; - } -} diff --git a/sites/all/modules/colorbox/drush/colorbox.drush.inc b/sites/all/modules/colorbox/drush/colorbox.drush.inc deleted file mode 100644 index f2a5422..0000000 --- a/sites/all/modules/colorbox/drush/colorbox.drush.inc +++ /dev/null @@ -1,133 +0,0 @@ - 'drush_colorbox_plugin', - 'description' => dt("Downloads the Colorbox plugin."), - 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap. - 'arguments' => array( - 'path' => dt('Optional. A path where to install the Colorbox plugin. If omitted Drush will use the default location.'), - ), - 'aliases' => array('colorboxplugin'), - ); - - return $items; -} - -/** - * Implementation of hook_drush_help(). - * - * This function is called whenever a drush user calls - * 'drush help ' - * - * @param - * A string with the help section (prepend with 'drush:') - * - * @return - * A string with the help text for your command. - */ -function colorbox_drush_help($section) { - switch ($section) { - case 'drush:colorbox-plugin': - return dt("Downloads the Colorbox plugin from colorpowered.com, default location is sites/all/libraries."); - } -} - -/** - * Implements drush_MODULE_post_pm_enable(). - */ -// function drush_colorbox_post_pm_enable() { -// $modules = func_get_args(); -// if (in_array('colorbox', $modules)) { -// drush_colorbox_plugin(); -// } -// } - -/** - * Command to download the Colorbox plugin. - */ -function drush_colorbox_plugin() { - if (!drush_shell_exec('type unzip')) { - return drush_set_error(dt('Missing dependency: unzip. Install it before using this command.')); - } - - $args = func_get_args(); - if (!empty($args[0])) { - $path = $args[0]; - } - else { - $path = 'sites/all/libraries'; - } - - // Create the path if it does not exist. - if (!is_dir($path)) { - drush_op('mkdir', $path); - drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice'); - } - - // Set the directory to the download location. - $olddir = getcwd(); - chdir($path); - - $filename = basename(COLORBOX_DOWNLOAD_URI); - $dirname = basename(COLORBOX_DOWNLOAD_URI, '.zip'); - - // Remove any existing Colorbox plugin directory - if (is_dir($dirname)) { - drush_log(dt('A existing Colorbox plugin was overwritten at @path', array('@path' => $path)), 'notice'); - } - // Remove any existing Colorbox plugin zip archive - if (is_file($filename)) { - drush_op('unlink', $filename); - } - - // Download the zip archive - if (!drush_shell_exec('wget ' . COLORBOX_DOWNLOAD_URI)) { - drush_shell_exec('curl -O ' . COLORBOX_DOWNLOAD_URI); - } - - if (is_file($filename)) { - // Decompress the zip archive - drush_shell_exec('unzip -qq -o ' . $filename); - // Remove the zip archive - drush_op('unlink', $filename); - } - - // Set working directory back to the previous working directory. - chdir($olddir); - - if (is_dir($path . '/' . $dirname)) { - drush_log(dt('Colorbox plugin has been downloaded to @path', array('@path' => $path)), 'success'); - } - else { - drush_log(dt('Drush was unable to download the Colorbox plugin to @path', array('@path' => $path)), 'error'); - } -} diff --git a/sites/all/modules/colorbox/images/controls.png b/sites/all/modules/colorbox/images/controls.png deleted file mode 100644 index 2238972..0000000 Binary files a/sites/all/modules/colorbox/images/controls.png and /dev/null differ diff --git a/sites/all/modules/colorbox/images/loading_animation.gif b/sites/all/modules/colorbox/images/loading_animation.gif deleted file mode 100644 index f864d5f..0000000 Binary files a/sites/all/modules/colorbox/images/loading_animation.gif and /dev/null differ diff --git a/sites/all/modules/colorbox/images/loading_background.png b/sites/all/modules/colorbox/images/loading_background.png deleted file mode 100644 index 9de11f4..0000000 Binary files a/sites/all/modules/colorbox/images/loading_background.png and /dev/null differ diff --git a/sites/all/modules/colorbox/js/colorbox.js b/sites/all/modules/colorbox/js/colorbox.js deleted file mode 100644 index 144fc4c..0000000 --- a/sites/all/modules/colorbox/js/colorbox.js +++ /dev/null @@ -1,21 +0,0 @@ -(function ($) { - -Drupal.behaviors.initColorbox = { - attach: function (context, settings) { - if (!$.isFunction($.colorbox)) { - return; - } - $('a, area, input', context) - .filter('.colorbox') - .once('init-colorbox-processed') - .colorbox(settings.colorbox); - } -}; - -{ - $(document).bind('cbox_complete', function () { - Drupal.attachBehaviors('#cboxLoadedContent'); - }); -} - -})(jQuery); diff --git a/sites/all/modules/colorbox/js/colorbox_admin_settings.js b/sites/all/modules/colorbox/js/colorbox_admin_settings.js deleted file mode 100644 index 46608f8..0000000 --- a/sites/all/modules/colorbox/js/colorbox_admin_settings.js +++ /dev/null @@ -1,32 +0,0 @@ -(function ($) { - -Drupal.behaviors.initColorboxAdminSettings = { - attach: function (context, settings) { - $('div.colorbox-custom-settings-activate input.form-radio', context).click(function () { - if (this.value == 1) { - $('div.colorbox-custom-settings', context).show(); - } - else { - $('div.colorbox-custom-settings', context).hide(); - } - }); - $('div.colorbox-slideshow-settings-activate input.form-radio', context).click(function () { - if (this.value == 1) { - $('div.colorbox-slideshow-settings', context).show(); - } - else { - $('div.colorbox-slideshow-settings', context).hide(); - } - }); - $('div.colorbox-title-trim-settings-activate input.form-radio', context).click(function () { - if (this.value == 1) { - $('div.colorbox-title-trim-settings', context).show(); - } - else { - $('div.colorbox-title-trim-settings', context).hide(); - } - }); - } -}; - -})(jQuery); diff --git a/sites/all/modules/colorbox/js/colorbox_image_module.js b/sites/all/modules/colorbox/js/colorbox_image_module.js deleted file mode 100644 index 983bd70..0000000 --- a/sites/all/modules/colorbox/js/colorbox_image_module.js +++ /dev/null @@ -1,36 +0,0 @@ -(function ($) { - -Drupal.behaviors.initColorboxImageModule = { - attach: function (context, settings) { - // Image Attach Functionality - $('div.image-attach-body > a, ul.images a', context).once('init-colorbox-image-module-processed', function () { - var $img = $('.image', this); - if ($img.length === 0) { - return true; - } - - // Find derivative - var class = $img.attr('class'); - var matches = class.match(/image\-(\w+)/); - if (matches === null) { - return true; - } - var derivative = matches[1]; - - // Create link path - var path_replacement = settings.colorbox.image_derivative == '_original' ? '' : '.' + settings.colorbox.image_derivative; - var href = $img.attr('src').replace('.' + derivative, path_replacement); - - // Modify link to image - this.href = href; - // Add rel tag to group - this.rel = 'image-gallery'; - // Add image link title - this.title = $img.attr('title'); - // Colorbox it - $(this).addClass('colorbox'); - }); - } -}; - -})(jQuery); diff --git a/sites/all/modules/colorbox/js/colorbox_inline.js b/sites/all/modules/colorbox/js/colorbox_inline.js deleted file mode 100644 index 1ea52f7..0000000 --- a/sites/all/modules/colorbox/js/colorbox_inline.js +++ /dev/null @@ -1,56 +0,0 @@ -(function ($) { - -Drupal.behaviors.initColorboxInline = { - attach: function (context, settings) { - if (!$.isFunction($.colorbox)) { - return; - } - $.urlParam = function(name, url){ - if (name == 'fragment') { - var results = new RegExp('(#[^&#]*)').exec(url); - } - else { - var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(url); - } - if (!results) { return ''; } - return results[1] || ''; - }; - $('a, area, input', context).filter('.colorbox-inline').once('init-colorbox-inline-processed').colorbox({ - transition:settings.colorbox.transition, - speed:settings.colorbox.speed, - opacity:settings.colorbox.opacity, - slideshow:settings.colorbox.slideshow, - slideshowAuto:settings.colorbox.slideshowAuto, - slideshowSpeed:settings.colorbox.slideshowSpeed, - slideshowStart:settings.colorbox.slideshowStart, - slideshowStop:settings.colorbox.slideshowStop, - current:settings.colorbox.current, - previous:settings.colorbox.previous, - next:settings.colorbox.next, - close:settings.colorbox.close, - overlayClose:settings.colorbox.overlayClose, - maxWidth:settings.colorbox.maxWidth, - maxHeight:settings.colorbox.maxHeight, - innerWidth:function(){ - return $.urlParam('width', $(this).attr('href')); - }, - innerHeight:function(){ - return $.urlParam('height', $(this).attr('href')); - }, - title:function(){ - return decodeURIComponent($.urlParam('title', $(this).attr('href'))); - }, - iframe:function(){ - return $.urlParam('iframe', $(this).attr('href')); - }, - inline:function(){ - return $.urlParam('inline', $(this).attr('href')); - }, - href:function(){ - return $.urlParam('fragment', $(this).attr('href')); - } - }); - } -}; - -})(jQuery); diff --git a/sites/all/modules/colorbox/js/colorbox_load.js b/sites/all/modules/colorbox/js/colorbox_load.js deleted file mode 100644 index dc70c1b..0000000 --- a/sites/all/modules/colorbox/js/colorbox_load.js +++ /dev/null @@ -1,43 +0,0 @@ -(function ($) { - -Drupal.behaviors.initColorboxLoad = { - attach: function (context, settings) { - if (!$.isFunction($.colorbox)) { - return; - } - $.urlParams = function (url) { - var p = {}, - e, - a = /\+/g, // Regex for replacing addition symbol with a space - r = /([^&=]+)=?([^&]*)/g, - d = function (s) { return decodeURIComponent(s.replace(a, ' ')); }, - q = url.split('?'); - while (e = r.exec(q[1])) { - e[1] = d(e[1]); - e[2] = d(e[2]); - switch (e[2].toLowerCase()) { - case 'true': - case 'yes': - e[2] = true; - break; - case 'false': - case 'no': - e[2] = false; - break; - } - if (e[1] == 'width') { e[1] = 'innerWidth'; } - if (e[1] == 'height') { e[1] = 'innerHeight'; } - p[e[1]] = e[2]; - } - return p; - }; - $('a, area, input', context) - .filter('.colorbox-load') - .once('init-colorbox-load-processed', function () { - var params = $.urlParams($(this).attr('href')); - $(this).colorbox($.extend({}, settings.colorbox, params)); - }); - } -}; - -})(jQuery); diff --git a/sites/all/modules/colorbox/js/colorbox_login.js b/sites/all/modules/colorbox/js/colorbox_login.js deleted file mode 100644 index 1dfcf7d..0000000 --- a/sites/all/modules/colorbox/js/colorbox_login.js +++ /dev/null @@ -1,31 +0,0 @@ -(function ($) { - -Drupal.behaviors.initColorboxLogin = { - attach: function (context, settings) { - if (!$.isFunction($.colorbox)) { - return; - } - $("a[href*='/user/login'], a[href*='?q=user/login']", context).once('init-colorbox-login-processed', function () { - var path = this.href; - var new_path = path.replace(/user\/login/,'user/login/colorbox') - var addquery = (path.indexOf('?') !=-1) ? '&' : '?'; - var dest = window.location.pathname.replace(Drupal.settings.basePath, ''); - - // If no destination, add one to the current page. - if (path.indexOf('destination') != -1 || dest == '') { - this.href = new_path; - } - else { - this.href = new_path + addquery + 'destination=' + dest; - } - }).colorbox({ - initialWidth:200, - initialHeight:200, - onComplete:function(){ - $('#edit-name').focus(); - } - }); - } -}; - -})(jQuery); diff --git a/sites/all/modules/colorbox/styles/default/colorbox_default_style.css b/sites/all/modules/colorbox/styles/default/colorbox_default_style.css deleted file mode 100644 index f302949..0000000 --- a/sites/all/modules/colorbox/styles/default/colorbox_default_style.css +++ /dev/null @@ -1,192 +0,0 @@ -/** - * ColorBox Core Style: - * The following CSS is consistent between example themes and should not be altered. - */ -#colorbox, #cboxOverlay, #cboxWrapper { - position: absolute; - top: 0; - left: 0; - z-index: 9999; - overflow: hidden; -} -#cboxOverlay { - position: fixed; - width: 100%; - height: 100%; -} -#cboxMiddleLeft, #cboxBottomLeft { - clear: left; -} -#cboxContent { - position: relative; -} -#cboxLoadedContent { - overflow: auto; -} -#cboxTitle { - margin: 0; -} -#cboxLoadingOverlay, #cboxLoadingGraphic { - position: absolute; - top: 0; - left: 0; - width: 100%; -} -#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow { - cursor: pointer; -} -.cboxPhoto { - float: left; - margin: auto; - border: 0; - display: block; -} -.cboxIframe { - width: 100%; - height: 100%; - display: block; - border: 0; -} - -/** - * Colorbox module default style: - * The styles are ordered & tabbed in a way that represents - * the nesting of the generated HTML. - */ -#cboxOverlay { - background: #000; -} - -#colorBox {} - #cboxWrapper { - background: #fff; - border-radius: 5px; - -moz-border-radius: 5px; - -webkit-border-radius: 5px; - } - #cboxTopLeft { - width: 15px; - height: 15px; - } - #cboxTopCenter { - height: 15px; - } - #cboxTopRight { - width: 15px; - height: 15px; - } - #cboxBottomLeft { - width: 15px; - height: 10px; - } - #cboxBottomCenter { - height: 10px; - } - #cboxBottomRight { - width: 15px; - height: 10px; - } - #cboxMiddleLeft { - width: 15px; - } - #cboxMiddleRight { - width: 15px; - } - #cboxContent { - background: #fff; - overflow: hidden; - font: 12px "Lucida Grande", Verdana, Arial, sans-serif; - } - #cboxError { - padding: 50px; - border: 1px solid #ccc; - } - #cboxLoadedContent { - margin-bottom: 28px; - } - #cboxTitle { - position: absolute; - background: rgba(255, 255, 255, 0.7); - bottom: 28px; - left: 0; - color: #535353; - width: 100%; - padding: 4px; - } - #cboxCurrent { - position: absolute; - bottom: 4px; - left: 60px; - color: #949494; - } - .cboxSlideshow_on #cboxSlideshow { - position: absolute; - bottom: 0px; - right: 30px; - background: url(images/controls.png) -75px -50px no-repeat; - width: 25px; - height: 25px; - text-indent: -9999px; - } - .cboxSlideshow_on #cboxSlideshow.hover { - background-position: -101px -50px; - } - .cboxSlideshow_off #cboxSlideshow { - position: absolute; - bottom: 0px; - right: 30px; - background: url(images/controls.png) -49px -50px no-repeat; - width: 25px; - height: 25px; - text-indent: -9999px; - } - .cboxSlideshow_off #cboxSlideshow.hover { - background-position: -25px -50px; - } - #cboxPrevious { - position: absolute; - bottom: 0; - left: 0; - background: url(images/controls.png) -75px 0px no-repeat; - width: 25px; - height: 25px; - text-indent: -9999px; - } - #cboxPrevious.hover { - background-position: -75px -25px; - } - #cboxNext { - position: absolute; - bottom: 0; - left: 27px; - background: url(images/controls.png) -50px 0px no-repeat; - width: 25px; - height: 25px; - text-indent: -9999px; - } - #cboxNext.hover { - background-position: -50px -25px; - } - #cboxLoadingOverlay { - background: #fff; - } - #cboxLoadingGraphic { - background: url(images/loading_animation.gif) center center no-repeat; - } - #cboxClose { - position: absolute; - bottom: 0; - right: 0; - background: url(images/controls.png) -25px 0px no-repeat; - width: 25px; - height: 25px; - text-indent: -9999px; - } - #cboxClose.hover { - background-position: -25px -25px; - } - -/* The following are fixes for IE. */ -.cboxIE6 #cboxTitle { - background: #fff; -} diff --git a/sites/all/modules/colorbox/styles/default/colorbox_default_style.js b/sites/all/modules/colorbox/styles/default/colorbox_default_style.js deleted file mode 100644 index 8b77b09..0000000 --- a/sites/all/modules/colorbox/styles/default/colorbox_default_style.js +++ /dev/null @@ -1,23 +0,0 @@ -(function ($) { - -Drupal.behaviors.initColorboxDefaultStyle = { - attach: function (context, settings) { - $(document).bind('cbox_complete', function () { - // Only run if there is a title. - if ($('#cboxTitle:empty', context).length == false) { - setTimeout(function () { $('#cboxTitle', context).slideUp() }, 1500); - $('#cboxLoadedContent img', context).bind('mouseover', function () { - $('#cboxTitle', context).slideDown(); - }); - $('#cboxOverlay', context).bind('mouseover', function () { - $('#cboxTitle', context).slideUp(); - }); - } - else { - $('#cboxTitle', context).hide(); - } - }); - } -}; - -})(jQuery); diff --git a/sites/all/modules/colorbox/styles/default/images/controls.png b/sites/all/modules/colorbox/styles/default/images/controls.png deleted file mode 100644 index 2238972..0000000 Binary files a/sites/all/modules/colorbox/styles/default/images/controls.png and /dev/null differ diff --git a/sites/all/modules/colorbox/styles/default/images/loading_animation.gif b/sites/all/modules/colorbox/styles/default/images/loading_animation.gif deleted file mode 100644 index f864d5f..0000000 Binary files a/sites/all/modules/colorbox/styles/default/images/loading_animation.gif and /dev/null differ diff --git a/sites/all/modules/colorbox/styles/default/images/loading_background.png b/sites/all/modules/colorbox/styles/default/images/loading_background.png deleted file mode 100644 index 9de11f4..0000000 Binary files a/sites/all/modules/colorbox/styles/default/images/loading_background.png and /dev/null differ diff --git a/sites/all/modules/colorbox/styles/stockholmsyndrome/colorbox_stockholmsyndrome.css b/sites/all/modules/colorbox/styles/stockholmsyndrome/colorbox_stockholmsyndrome.css deleted file mode 100644 index 0d1a5d0..0000000 --- a/sites/all/modules/colorbox/styles/stockholmsyndrome/colorbox_stockholmsyndrome.css +++ /dev/null @@ -1,198 +0,0 @@ -/** - * ColorBox Core Style: - * The following CSS is consistent between example themes and should not be altered. - */ -#colorbox, #cboxOverlay, #cboxWrapper { - position: absolute; - top: 0; - left: 0; - z-index: 9999; - overflow: hidden; -} -#cboxOverlay { - position: fixed; - width: 100%; - height: 100%; -} -#cboxMiddleLeft, #cboxBottomLeft { - clear: left; -} -#cboxContent { - position: relative; -} -#cboxLoadedContent { - overflow: auto; -} -#cboxTitle { - margin: 0; -} -#cboxLoadingOverlay, #cboxLoadingGraphic { - position: absolute; - top: 0; - left: 0; - width: 100%; -} -#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow { - cursor: pointer; -} -.cboxPhoto { - float: left; - margin: auto; - border: 0; - display: block; -} -.cboxIframe { - width: 100%; - height: 100%; - display: block; - border: 0; -} - -/** - * Colorbox module Stockholm syndrome style: - * The styles are ordered & tabbed in a way that represents - * the nesting of the generated HTML. - */ -#cboxOverlay { - background: #000; - opacity: 0.4 !important; -} - -#colorbox { - background: #fff url(images/bg_tab.png) center bottom repeat-x; - box-shadow: 3px 3px 16px #333; - -moz-box-shadow: 3px 3px 16px #333; - -webkit-box-shadow: 3px 3px 16px #333; - border-bottom-left-radius: 9px; - border-bottom-right-radius: 9px; - -moz-border-radius-bottomleft: 9px; - -moz-border-radius-bottomright: 9px; - -webkit-border-bottom-left-radius: 9px; - -webkit-border-bottom-right-radius: 9px; -} -#colorbox, #colorbox div { - overflow: visible; /* Required by the close button. */ -} - #cboxWrapper { - border-bottom-left-radius: 9px; - border-bottom-right-radius: 9px; - -moz-border-radius-bottomleft: 9px; - -moz-border-radius-bottomright: 9px; - -webkit-border-bottom-left-radius: 9px; - -webkit-border-bottom-right-radius: 9px; - } - #cboxTopLeft { - width: 0; - height: 0; - } - #cboxTopCenter { - height: 0; - } - #cboxTopRight { - width: 0; - height: 0; - } - #cboxBottomLeft { - width: 15px; - height: 10px; - } - #cboxBottomCenter { - height: 10px; - } - #cboxBottomRight { - width: 15px; - height: 10px; - } - #cboxMiddleLeft { - width: 0; - } - #cboxMiddleRight { - width: 0; - } - #cboxContent { - background: #fff; - overflow: hidden; - font: 11px Arial, sans-serif; - margin-bottom: 28px; - } - #cboxError { - padding: 50px; - border: 1px solid #ccc; - } - #cboxLoadedContent { - } - #cboxTitle { - left: 0; - height: 38px; - color: #313131; - padding: 0 140px 0 15px; - display: table-cell; - vertical-align: middle; - } - #cboxCurrent { - position: absolute; - bottom: -26px; - right: 80px; - color: #313131; - border-left: 1px solid #313131; - padding: 0 0 0 15px; - } - /* Slideshow not implemented. */ - .cboxSlideshow_on #cboxSlideshow { - display: none; - } - .cboxSlideshow_on #cboxSlideshow.hover { - } - .cboxSlideshow_off #cboxSlideshow { - display: none; - } - .cboxSlideshow_off #cboxSlideshow.hover { - } - #cboxPrevious { - position: absolute; - bottom: -26px; - right: 45px; - background: url(images/controls.png) 0 -48px no-repeat; - width: 21px; - height: 15px; - text-indent: -9999px; - } - #cboxPrevious.hover { - background-position: 0 -111px; - } - #cboxNext { - position: absolute; - bottom: -26px; - right: 15px; - background: url(images/controls.png) 0 -29px no-repeat; - width: 21px; - height: 15px; - text-indent: -9999px; - } - #cboxNext.hover { - background-position: 0 -92px; - } - #cboxLoadingOverlay { - background: #e6e6e6; - } - #cboxLoadingGraphic { - background: url(images/loading_animation.gif) center center no-repeat; - } - #cboxClose { - position: absolute; - top: -10px; - right: -10px; - background: url(images/controls.png) 0px 0px no-repeat; - width: 25px; - height: 25px; - text-indent: -9999px; - opacity: 0; - } - #cboxClose.hover { - background-position: 0 -63px; - } - -/* The following are fixes for IE. */ -.cboxIE6 #cboxTitle { - background: #fff; -} diff --git a/sites/all/modules/colorbox/styles/stockholmsyndrome/colorbox_stockholmsyndrome.js b/sites/all/modules/colorbox/styles/stockholmsyndrome/colorbox_stockholmsyndrome.js deleted file mode 100644 index afe2c0f..0000000 --- a/sites/all/modules/colorbox/styles/stockholmsyndrome/colorbox_stockholmsyndrome.js +++ /dev/null @@ -1,20 +0,0 @@ -(function ($) { - -Drupal.behaviors.initColorboxStockholmsyndromeStyle = { - attach: function (context, settings) { - $(document).bind('cbox_open', function () { - // Hide close button initially. - $('#cboxClose', context).css('opacity', 0); - }); - $(document).bind('cbox_load', function () { - // Hide close button. (It doesn't handle the load animation well.) - $('#cboxClose', context).css('opacity', 0); - }); - $(document).bind('cbox_complete', function () { - // Show close button with a delay. - $('#cboxClose', context).fadeTo('fast', 0, function () {$(this).css('opacity', 1)}); - }); - } -}; - -})(jQuery); diff --git a/sites/all/modules/colorbox/styles/stockholmsyndrome/colorbox_stockholmsyndrome_screen.png b/sites/all/modules/colorbox/styles/stockholmsyndrome/colorbox_stockholmsyndrome_screen.png deleted file mode 100644 index 079e347..0000000 Binary files a/sites/all/modules/colorbox/styles/stockholmsyndrome/colorbox_stockholmsyndrome_screen.png and /dev/null differ diff --git a/sites/all/modules/colorbox/styles/stockholmsyndrome/images/bg_tab.png b/sites/all/modules/colorbox/styles/stockholmsyndrome/images/bg_tab.png deleted file mode 100644 index 03064d9..0000000 Binary files a/sites/all/modules/colorbox/styles/stockholmsyndrome/images/bg_tab.png and /dev/null differ diff --git a/sites/all/modules/colorbox/styles/stockholmsyndrome/images/controls.png b/sites/all/modules/colorbox/styles/stockholmsyndrome/images/controls.png deleted file mode 100644 index 6745faa..0000000 Binary files a/sites/all/modules/colorbox/styles/stockholmsyndrome/images/controls.png and /dev/null differ diff --git a/sites/all/modules/colorbox/styles/stockholmsyndrome/images/loading_animation.gif b/sites/all/modules/colorbox/styles/stockholmsyndrome/images/loading_animation.gif deleted file mode 100644 index f864d5f..0000000 Binary files a/sites/all/modules/colorbox/styles/stockholmsyndrome/images/loading_animation.gif and /dev/null differ diff --git a/sites/all/modules/colorbox/views/colorbox.views.inc b/sites/all/modules/colorbox/views/colorbox.views.inc deleted file mode 100644 index 40f90a5..0000000 --- a/sites/all/modules/colorbox/views/colorbox.views.inc +++ /dev/null @@ -1,28 +0,0 @@ - array(), - ); - - $data['colorbox']['colorbox'] = array( - 'title' => t('Colorbox trigger'), - 'help' => t('Provide custom text or link.'), - 'field' => array( - 'handler' => 'colorbox_handler_field_colorbox', - ), - ); - - return $data; -} diff --git a/sites/all/modules/colorbox/views/colorbox_handler_field_colorbox.inc b/sites/all/modules/colorbox/views/colorbox_handler_field_colorbox.inc deleted file mode 100644 index c5051de..0000000 --- a/sites/all/modules/colorbox/views/colorbox_handler_field_colorbox.inc +++ /dev/null @@ -1,157 +0,0 @@ - ''); - $options['popup'] = array('default' => ''); - $options['caption'] = array('default' => ''); - $options['gid'] = array('default' => TRUE); - $options['custom_gid'] = array('default' => ''); - $options['width'] = array('default' => '600px'); - $options['height'] = array('default' => '400px'); - - return $options; - } - - function options_form(&$form, &$form_state) { - parent::options_form($form, $form_state); - - // Get a list of the available fields and arguments for token replacement. - $options = array(); - $fields = array('trigger_field' => t('')); - foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) { - $options[t('Fields')]["[$field]"] = $handler->ui_name(); - // We only use fields up to (and including) this one. - if ($field == $this->options['id']) { - break; - } - - $fields[$field] = $handler->definition['title']; - } - - $form['trigger_field'] = array( - '#type' => 'select', - '#title' => t('Trigger field'), - '#description' => t('Select the field that should be turned into the trigger for the Colorbox. Only fields that appear before this one in the field list may be used.'), - '#options' => $fields, - '#default_value' => $this->options['trigger_field'], - '#weight' => -12, - ); - - $form['popup'] = array( - '#type' => 'textarea', - '#title' => t('Popup'), - '#description' => t('The Colorbox popup content. You may include HTML. You may enter data from this view as per the "Replacement patterns" below.'), - '#default_value' => $this->options['popup'], - '#weight' => -11, - ); - - $form['caption'] = array( - '#type' => 'textfield', - '#title' => t('Caption'), - '#description' => t('The Colorbox Caption. You may include HTML. You may enter data from this view as per the "Replacement patterns" below.'), - '#default_value' => $this->options['caption'], - '#weight' => -10, - ); - - $form['gid'] = array( - '#type' => 'checkbox', - '#title' => t('Automatic generated Colorbox gallery'), - '#description' => t('Enable Colorbox gallery using a generated gallery id for this view.'), - '#default_value' => $this->options['gid'], - '#weight' => -9, - ); - - $form['custom_gid'] = array( - '#type' => 'textfield', - '#title' => t('Custom Colorbox gallery'), - '#description' => t('Enable Colorbox gallery with a given string as gallery. Overrides the automatically generated gallery id above.'), - '#default_value' => $this->options['custom_gid'], - '#weight' => -8, - ); - - $form['height'] = array( - '#type' => 'textfield', - '#title' => t('Height'), - '#description' => t('Specify the height of the Colorbox popup window. Because the content is dynamic, we cannot detect this value automatically. Example: "100%", 500, "500px".'), - '#default_value' => $this->options['height'], - '#weight' => -7, - ); - - $form['width'] = array( - '#type' => 'textfield', - '#title' => t('Width'), - '#description' => t('Specify the width of the Colorbox popup window. Because the content is dynamic, we cannot detect this value automatically. Example: "100%", 500, "500px".'), - '#default_value' => $this->options['width'], - '#weight' => -6, - ); - } - - /** - * Render the trigger field and its linked popup information. - */ - function render($values) { - // Load the necessary js file for Colorbox activation. - if (_colorbox_active() && !variable_get('colorbox_inline', 0)) { - drupal_add_js(drupal_get_path('module', 'colorbox') . '/js/colorbox_inline.js'); - } - - // We need to have multiple unique IDs, one for each record. - static $i = 0; - $i++; - - // Return nothing if no trigger filed is selected. - if (empty($this->options['trigger_field'])) { - return; - } - - // Get the token information and generate the value for the popup and the - // caption. - $tokens = $this->get_render_tokens($this->options['alter']); - $popup = filter_xss_admin($this->options['popup']); - $caption = filter_xss_admin($this->options['caption']); - $popup = strtr($popup, $tokens); - $caption = strtr($caption, $tokens); - - $width = $this->options['width'] ? $this->options['width'] : '600px'; - $height = $this->options['height'] ? $this->options['height'] : '400px'; - $gallery_id = !empty($this->options['custom_gid']) ? $this->options['custom_gid'] : ($this->options['gid'] ? 'gallery-' . $this->view->name : ''); - $link_text = $tokens["[{$this->options['trigger_field']}]"]; - $link_options = array( - 'html' => TRUE, - 'fragment' => 'colorbox-inline-' . $i, - 'query' => array( - 'width' => $width, - 'height' => $height, - 'title' => $caption, - 'inline' => 'true' - ), - 'attributes' => array( - 'class' => 'colorbox-inline', - 'rel' => $gallery_id - ) - ); - - $link_tag = l($link_text, '', $link_options); - - // The outside div is there to hide all of the divs because if the specific Colorbox - // div is hidden it won't show up as a Colorbox. - return $link_tag . '
' . $popup . '
'; - } -} diff --git a/sites/all/modules/token/LICENSE.txt b/sites/all/modules/token/LICENSE.txt new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/sites/all/modules/token/LICENSE.txt @@ -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. + + + Copyright (C) + + 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. + + , 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. diff --git a/sites/all/modules/token/README.txt b/sites/all/modules/token/README.txt new file mode 100644 index 0000000..230774e --- /dev/null +++ b/sites/all/modules/token/README.txt @@ -0,0 +1,2 @@ + +Provides common and resuable token UI elements and missing core tokens. diff --git a/sites/all/modules/token/arrow-down.png b/sites/all/modules/token/arrow-down.png new file mode 100644 index 0000000..2edbb17 Binary files /dev/null and b/sites/all/modules/token/arrow-down.png differ diff --git a/sites/all/modules/token/arrow-right.png b/sites/all/modules/token/arrow-right.png new file mode 100644 index 0000000..6f2f482 Binary files /dev/null and b/sites/all/modules/token/arrow-right.png differ diff --git a/sites/all/modules/token/jquery.treeTable.css b/sites/all/modules/token/jquery.treeTable.css new file mode 100644 index 0000000..bec225a --- /dev/null +++ b/sites/all/modules/token/jquery.treeTable.css @@ -0,0 +1,44 @@ + +/* jQuery TreeTable Core 2.0 stylesheet + * + * This file contains styles that are used to display the tree table. Each tree + * table is assigned the +treeTable+ class. + * ========================================================================= */ + +/* jquery.treeTable.collapsible + * ------------------------------------------------------------------------- */ +.treeTable tr td .expander { + background-position: left center; + background-repeat: no-repeat; + cursor: pointer; + padding: 0; + zoom: 1; /* IE7 Hack */ +} + +.treeTable tr.collapsed td .expander { + background-image: url(arrow-right.png); +} + +.treeTable tr.expanded td .expander { + background-image: url(arrow-down.png); +} + +/* jquery.treeTable.sortable + * ------------------------------------------------------------------------- */ +.treeTable tr.selected, .treeTable tr.accept { + background-color: #3875d7; + color: #fff; +} + +.treeTable tr.collapsed.selected td .expander, .treeTable tr.collapsed.accept td .expander { + background-image: url(../images/toggle-expand-light.png); +} + +.treeTable tr.expanded.selected td .expander, .treeTable tr.expanded.accept td .expander { + background-image: url(../images/toggle-collapse-light.png); +} + +.treeTable .ui-draggable-dragging { + color: #000; + z-index: 1; +} diff --git a/sites/all/modules/token/jquery.treeTable.js b/sites/all/modules/token/jquery.treeTable.js new file mode 100644 index 0000000..847b8f3 --- /dev/null +++ b/sites/all/modules/token/jquery.treeTable.js @@ -0,0 +1,220 @@ + +/* + * jQuery treeTable Plugin 2.3.0 + * http://ludo.cubicphuse.nl/jquery-plugins/treeTable/ + * + * Copyright 2010, Ludo van den Boom + * Dual licensed under the MIT or GPL Version 2 licenses. + */ +(function($) { + // Helps to make options available to all functions + // TODO: This gives problems when there are both expandable and non-expandable + // trees on a page. The options shouldn't be global to all these instances! + var options; + var defaultPaddingLeft; + + $.fn.treeTable = function(opts) { + options = $.extend({}, $.fn.treeTable.defaults, opts); + + return this.each(function() { + $(this).addClass("treeTable").find("tbody tr").each(function() { + // Initialize root nodes only if possible + if(!options.expandable || $(this)[0].className.search(options.childPrefix) == -1) { + // To optimize performance of indentation, I retrieve the padding-left + // value of the first root node. This way I only have to call +css+ + // once. + if (isNaN(defaultPaddingLeft)) { + defaultPaddingLeft = parseInt($($(this).children("td")[options.treeColumn]).css('padding-left'), 10); + } + + initialize($(this)); + } else if(options.initialState == "collapsed") { + this.style.display = "none"; // Performance! $(this).hide() is slow... + } + }); + }); + }; + + $.fn.treeTable.defaults = { + childPrefix: "child-of-", + clickableNodeNames: false, + expandable: true, + indent: 19, + initialState: "collapsed", + treeColumn: 0 + }; + + // Recursively hide all node's children in a tree + $.fn.collapse = function() { + $(this).addClass("collapsed"); + + childrenOf($(this)).each(function() { + if(!$(this).hasClass("collapsed")) { + $(this).collapse(); + } + + this.style.display = "none"; // Performance! $(this).hide() is slow... + }); + + return this; + }; + + // Recursively show all node's children in a tree + $.fn.expand = function() { + $(this).removeClass("collapsed").addClass("expanded"); + + childrenOf($(this)).each(function() { + initialize($(this)); + + if($(this).is(".expanded.parent")) { + $(this).expand(); + } + + // this.style.display = "table-row"; // Unfortunately this is not possible with IE :-( + $(this).show(); + }); + + return this; + }; + + // Reveal a node by expanding all ancestors + $.fn.reveal = function() { + $(ancestorsOf($(this)).reverse()).each(function() { + initialize($(this)); + $(this).expand().show(); + }); + + return this; + }; + + // Add an entire branch to +destination+ + $.fn.appendBranchTo = function(destination) { + var node = $(this); + var parent = parentOf(node); + + var ancestorNames = $.map(ancestorsOf($(destination)), function(a) { return a.id; }); + + // Conditions: + // 1: +node+ should not be inserted in a location in a branch if this would + // result in +node+ being an ancestor of itself. + // 2: +node+ should not have a parent OR the destination should not be the + // same as +node+'s current parent (this last condition prevents +node+ + // from being moved to the same location where it already is). + // 3: +node+ should not be inserted as a child of +node+ itself. + if($.inArray(node[0].id, ancestorNames) == -1 && (!parent || (destination.id != parent[0].id)) && destination.id != node[0].id) { + indent(node, ancestorsOf(node).length * options.indent * -1); // Remove indentation + + if(parent) { node.removeClass(options.childPrefix + parent[0].id); } + + node.addClass(options.childPrefix + destination.id); + move(node, destination); // Recursively move nodes to new location + indent(node, ancestorsOf(node).length * options.indent); + } + + return this; + }; + + // Add reverse() function from JS Arrays + $.fn.reverse = function() { + return this.pushStack(this.get().reverse(), arguments); + }; + + // Toggle an entire branch + $.fn.toggleBranch = function() { + if($(this).hasClass("collapsed")) { + $(this).expand(); + } else { + $(this).removeClass("expanded").collapse(); + } + + return this; + }; + + // === Private functions + + function ancestorsOf(node) { + var ancestors = []; + while(node = parentOf(node)) { + ancestors[ancestors.length] = node[0]; + } + return ancestors; + }; + + function childrenOf(node) { + return $(node).siblings("tr." + options.childPrefix + node[0].id); + }; + + function getPaddingLeft(node) { + var paddingLeft = parseInt(node[0].style.paddingLeft, 10); + return (isNaN(paddingLeft)) ? defaultPaddingLeft : paddingLeft; + } + + function indent(node, value) { + var cell = $(node.children("td")[options.treeColumn]); + cell[0].style.paddingLeft = getPaddingLeft(cell) + value + "px"; + + childrenOf(node).each(function() { + indent($(this), value); + }); + }; + + function initialize(node) { + if(!node.hasClass("initialized")) { + node.addClass("initialized"); + + var childNodes = childrenOf(node); + + if(!node.hasClass("parent") && childNodes.length > 0) { + node.addClass("parent"); + } + + if(node.hasClass("parent")) { + var cell = $(node.children("td")[options.treeColumn]); + var padding = getPaddingLeft(cell) + options.indent; + + childNodes.each(function() { + $(this).children("td")[options.treeColumn].style.paddingLeft = padding + "px"; + }); + + if(options.expandable) { + cell.prepend(''); + $(cell[0].firstChild).click(function() { node.toggleBranch(); }); + + if(options.clickableNodeNames) { + cell[0].style.cursor = "pointer"; + $(cell).click(function(e) { + // Don't double-toggle if the click is on the existing expander icon + if (e.target.className != 'expander') { + node.toggleBranch(); + } + }); + } + + // Check for a class set explicitly by the user, otherwise set the default class + if(!(node.hasClass("expanded") || node.hasClass("collapsed"))) { + node.addClass(options.initialState); + } + + if(node.hasClass("expanded")) { + node.expand(); + } + } + } + } + }; + + function move(node, destination) { + node.insertAfter(destination); + childrenOf(node).reverse().each(function() { move($(this), node[0]); }); + }; + + function parentOf(node) { + var classNames = node[0].className.split(' '); + + for(key in classNames) { + if(classNames[key].match(options.childPrefix)) { + return $(node).siblings("#" + classNames[key].substring(options.childPrefix.length)); + } + } + }; +})(jQuery); diff --git a/sites/all/modules/token/tests/token_test.info b/sites/all/modules/token/tests/token_test.info new file mode 100644 index 0000000..d3b6920 --- /dev/null +++ b/sites/all/modules/token/tests/token_test.info @@ -0,0 +1,13 @@ +name = Token Test +description = Testing module for token functionality. +package = Testing +core = 7.x +files[] = token_test.module +hidden = TRUE + +; Information added by drupal.org packaging script on 2011-10-28 +version = "7.x-1.0-beta7" +core = "7.x" +project = "token" +datestamp = "1319825735" + diff --git a/sites/all/modules/token/tests/token_test.module b/sites/all/modules/token/tests/token_test.module new file mode 100644 index 0000000..5c8bab0 --- /dev/null +++ b/sites/all/modules/token/tests/token_test.module @@ -0,0 +1,28 @@ + array(), 'data' => array(), 'options' => array()); + foreach (array_keys($debug['tokens']) as $token) { + $debug['values'][$token] = token_replace($token, $debug['data'], $debug['options']); + } + variable_set('token_page_tokens', $debug); + } +} + +/** + * Implements hook_date_format_types(). + * + * @todo Remove when http://drupal.org/node/1173706 is fixed. + */ +function token_test_date_format_types() { + $info['token_test'] = t('Token test date format'); + + // Explicitly set the variable here as well. + variable_set('date_format_token_test', 'Y'); + + return $info; +} diff --git a/sites/all/modules/token/token.css b/sites/all/modules/token/token.css new file mode 100644 index 0000000..5c3b3ba --- /dev/null +++ b/sites/all/modules/token/token.css @@ -0,0 +1,23 @@ + +.token-tree { + font-size: 0.85em; + margin-left: 19px; +} + +.token-tree td, .token-tree th { + padding-top: 0; + padding-bottom: 0; +} + +.token-group { + font-weight: bold; +} + +.js .token-group { + font-weight: normal; +} + +/* Prevent the token columns from being wrapped. */ +.token-tree td.token-key { + white-space: nowrap; +} diff --git a/sites/all/modules/token/token.info b/sites/all/modules/token/token.info new file mode 100644 index 0000000..0abcc87 --- /dev/null +++ b/sites/all/modules/token/token.info @@ -0,0 +1,15 @@ +name = Token +description = Provides a user interface for the Token API and some missing core tokens. +core = 7.x +files[] = token.module +files[] = token.install +files[] = token.tokens.inc +files[] = token.pages.inc +files[] = token.test + +; Information added by drupal.org packaging script on 2011-10-28 +version = "7.x-1.0-beta7" +core = "7.x" +project = "token" +datestamp = "1319825735" + diff --git a/sites/all/modules/token/token.install b/sites/all/modules/token/token.install new file mode 100644 index 0000000..e4a9d74 --- /dev/null +++ b/sites/all/modules/token/token.install @@ -0,0 +1,325 @@ + $problem) { + if (!empty($problem['problems'])) { + $problems = array_unique($problem['problems']); + $problems = array_map('check_plain', $problems); + $token_problems[$problem_key] = $problem['label'] . theme('item_list', array('items' => $problems)); + } + else { + unset($token_problems[$problem_key]); + } + } + if (!empty($token_problems)) { + $requirements['token_problems'] = array( + 'title' => $t('Tokens'), + 'value' => $t('Problems detected'), + 'severity' => REQUIREMENT_WARNING, + 'description' => '

' . implode('

', $token_problems) . '

', //theme('item_list', array('items' => $token_problems)), + ); + } + } + + return $requirements; +} + +/** + * Implements hook_schema(). + */ +function token_schema() { + $schema['cache_token'] = drupal_get_schema_unprocessed('system', 'cache'); + $schema['cache_token']['description'] = 'Cache table for token information.'; + return $schema; +} + +/** + * Add the cache_token table. + */ +function token_update_7000() { + $schema['cache_token'] = drupal_get_schema_unprocessed('system', 'cache'); + $schema['cache_token']['description'] = 'Cache table for token information.'; + db_create_table('cache_token', $schema['cache_token']); +} + +/** + * Deprecate and disable the token_actions module. + */ +function token_update_7001() { + module_disable(array('token_actions')); + return 'The Token actions module has been deprecated by the updated system module actions that support tokens.'; +} + +/** + * Migrate old token_actions module actions to system actions. + */ +//function token_update_700X() { +// $actions = db_query("SELECT aid, type, callback, parameters, label FROM {actions} WHERE type = 'system' AND callback IN ('token_actions_message_action', 'token_actions_send_email_action', 'token_actions_goto_action')")->fetchAll(); +// foreach ($actions as $action) { +// $action->parameters = unserialize($action->parameters); +// foreach ($action->parameters as $key => $value) { +// if (is_string($value)) { +// $action->parameters[$key] = token_update_token_text($value); +// } +// } +// $action->callback = str_replace('token_actions_', '', $action->callback); +// actions_save($action->callback, $action->type, $action->parameters, $action->label, $action->aid); +// } +// return 'Token actions module actions migrated to system module actions. You may still want to verify that the actions were upgraded correctly.'; +//} + +/** + * Build a list of Drupal 6 tokens and their Drupal 7 token names. + */ +function _token_upgrade_token_list() { + $tokens = array( + // Global tokens + 'user-name' => 'current-user:name', + 'user-id' => 'current-user:id', + 'user-mail' => 'current-user:mail', + 'site-url' => 'site:url', + 'site-name' => 'site:name', + 'site-slogan' => 'site:slogan', + 'site-mission' => 'site:mission', + 'site-mail' => 'site:mail', + 'site-date' => 'date:short', + //'site-date-' => '', // Date tokens expanded below + 'current-page-path' => 'current-page:path', + 'current-page-url' => 'current-page:url', + 'page-number' => 'current-page:page-number', + + // Comment tokens + 'comment-cid' => 'comment:cid', + 'comment-nid' => 'comment:node:nid', + 'comment-title' => 'comment:title', + 'comment-body' => 'comment:body', + 'comment-author-name' => 'comment:author:name', + 'comment-author-mail' => 'comment:author:mail', + //'comment-body-format' => '', + //'comment-' => '', // Date tokens expanded below + 'comment-node-title' => 'comment:node', + + // Node tokens + 'nid' => 'node:nid', + 'type' => 'node:type', + 'type-name' => 'node:type-name', + 'language' => 'node:language', + 'title' => 'node:title', + 'author-uid' => 'node:author:uid', + 'author-name' => 'node:author:name', + 'author-mail' => 'node:author:mail', + 'node_comment_count' => 'node:comment-count', + 'unread_comment_count' => 'node:comment-count-new', + 'log' => 'node:log', + //'' => '', // Date tokens expanded below + //'mod-' => '', // Date tokens expanded below + 'menupath' => 'node:menu-link:parent:path][node:menu-link', + 'menu' => 'node:menu-link:menu-name', + 'menu-link-title' => 'node:menu-link', + 'menu-link-mlid' => 'node:menu-link:mlid', + 'menu-link-plid' => 'node:menu-link:parent:mlid', + //'term' => 'node:term', + //'term-id' => 'node:term:tid', + //'vocab' => 'node:term:vocabulary', + //'vocab-id' => 'node:term:vocabulary:vid', + + // Book tokens + //'book' => 'node:book', + //'book_id' => 'node:book:bid', + //'bookpath' => 'node:book:path', + + // Taxonomy tokens + 'tid' => 'term:tid', + 'cat' => 'term:name', + 'cat-description' => 'term:description', + 'vid' => 'term:vocabulary:vid', + 'vocab' => 'term:vocabulary', + 'vocab-description' => 'term:vocabulary:description', + + // User tokens + 'user' => 'user:name', + 'uid' => 'user:uid', + 'mail' => 'user:mail', + 'reg-date' => 'user:created', + 'reg-since' => 'user:created:since', + //'user-created' => '', // Date tokens expanded below + 'log-date' => 'user:last-login', + 'log-since' => 'user:last-login:since', + //'user-last-login' => '', // Date tokens expanded below + //'date-in-tz' => '', + 'account-url' => 'user:url', + 'account-edit' => 'user:edit-url', + ); + + // Account for date tokens which need to be expanded. + $tokens += _token_upgrade_token_date_list('site-', 'site:date'); + $tokens += _token_upgrade_token_date_list('', 'node:created'); + $tokens += _token_upgrade_token_date_list('mod-', 'node:changed'); + //$tokens += _token_upgrade_token_date_list('node-revision-', 'node:changed'); + $tokens += _token_upgrade_token_date_list('comment-', 'comment:created'); + $tokens += _token_upgrade_token_date_list('user-register-', 'user:created'); + $tokens += _token_upgrade_token_date_list('user-last-login-', 'user:last-login'); + + return $tokens; +} + +/** + * Build a list of Drupal 6 date tokens and their Drupal 7 token names. + */ +function _token_upgrade_token_date_list($old_token, $new_token) { + $tokens = array(); + $formats = array( + 'yyyy' => 'Y', + 'yy' => 'y', + 'month' => 'F', + 'mon' => 'M', + 'mm' => 'm', + 'm' => 'n', + 'ww' => 'W', + 'date' => 'N', + 'day' => 'l', + 'ddd' => 'D', + 'dd' => 'd', + 'd' => 'j', + ); + foreach ($formats as $token_format => $date_format) { + $tokens[$old_token . $token_format] = "$new_token:custom:$date_format"; + } + $tokens[$old_token . 'raw'] = "$new_token:raw"; + $tokens[$old_token . 'since'] = "$new_token:since"; + return $tokens; +} + +/** + * Update a string containing Drupal 6 style tokens to Drupal 7 style tokens. + * + * @param $text + * A string containing tokens. + * @param $updates + * An optional array of Drupal 7 tokens keyed by their Drupal 6 token name. + * The default tokens will be merged into this array. Note neither the old + * or new token names should include the surrounding bracket ([ and ]) + * characters. + * @return + * A string with the tokens upgraded + * + * @see _token_upgrade_token_list(); + */ +function token_update_token_text($text, $updates = array(), $leading = '[', $trailing = ']') { + $updates += _token_upgrade_token_list(); + $regex = '/' . preg_quote($leading, '/') . '([^\s]*)' . preg_quote($trailing, '/') . ']/'; + preg_match_all($regex, $text, $matches); + + foreach ($matches[1] as $index => $old_token) { + if (isset($updates[$old_token])) { + $new_token = $updates[$old_token]; + $text = str_replace("{$leading}{$old_token}{$trailing}", "[$new_token]", $text); + // Also replace any tokens that have a -raw suffix. + $text = str_replace("{$leading}{$old_token}-raw{$trailing}", "[$new_token]", $text); + } + } + + return $text; +} + +/** + * Get token problems. + */ +function token_get_token_problems() { + // @todo Improve the duplicate checking to report which modules are the offenders. + //$token_info = array(); + //foreach (module_implements('token_info') as $module) { + // $module_token_info = module_invoke($module, 'token_info'); + // if (in_array($module, _token_core_supported_modules())) { + // $module .= '/token'; + // } + // if (isset($module_token_info['types'])) { + // if (is_array($module_token_info['types'])) { + // foreach (array_keys($module_token_info['types']) as $type) { + // if (is_array($module_token_info['types'][$type])) { + // $module_token_info['types'][$type] += array('module' => $module); + // } + // } + // } + // } + // if (isset($module_token_info['tokens'])) { + // if (is_array($module_token_info['tokens'])) { + // + // } + // } + // if (is_array($module_token_info)) { + // $token_info = array_merge_recursive($token_info, $module_token_info); + // } + //} + + $token_info = token_info(); + $token_problems = array( + 'not-array' => array( + 'label' => t('The following tokens or token types are not defined as arrays:'), + ), + 'missing-info' => array( + 'label' => t('The following tokens or token types are missing required name and description information:'), + ), + 'type-no-tokens' => array( + 'label' => t('The following token types do not have any tokens defined:'), + ), + 'tokens-no-type' => array( + 'label' => t('The following token types are not defined but have tokens:'), + ), + 'duplicate' => array( + 'label' => t('The following token or token types are defined by multiple modules:') + ), + ); + + // Check token types for problems. + foreach ($token_info['types'] as $type => $type_info) { + $real_type = !empty($type_info['type']) ? $type_info['type'] : $type; + if (!is_array($type_info)) { + $token_problems['not-array']['problems'][] = "\$info['types']['$type']"; + continue; + } + elseif (!isset($type_info['name']) || !isset($type_info['description'])) { + $token_problems['missing-info']['problems'][] = "\$info['types']['$type']"; + } + elseif (empty($token_info['tokens'][$real_type])) { + $token_problems['type-no-tokens']['problems'][] = "\$info['tokens']['$real_type']"; + } + } + + // Check tokens for problems. + foreach ($token_info['tokens'] as $type => $tokens) { + if (!is_array($tokens)) { + $token_problems['not-array']['problems'][] = "\$info['tokens']['$type']"; + continue; + } + else { + foreach (array_keys($tokens) as $token) { + if (!is_array($tokens[$token])) { + $token_problems['not-array']['problems'][] = "\$info['tokens']['$type']['$token']"; + continue; + } + elseif (!isset($tokens[$token]['name']) || !isset($tokens[$token]['description'])) { + $token_problems['missing-info']['problems'][] = "\$info['tokens']['$type']['$token']"; + } + elseif (is_array($tokens[$token]['name']) || is_array($tokens[$token]['description'])) { + $token_problems['duplicate']['problems'][] = "\$info['tokens']['$type']['$token']"; + } + } + } + if (!isset($token_info['types'][$type])) { + $token_problems['tokens-no-type']['problems'][] = "\$info['types']['$type']"; + } + } + + return $token_problems; +} diff --git a/sites/all/modules/token/token.js b/sites/all/modules/token/token.js new file mode 100644 index 0000000..59715f4 --- /dev/null +++ b/sites/all/modules/token/token.js @@ -0,0 +1,55 @@ + +(function ($) { + +Drupal.behaviors.tokenTree = { + attach: function (context, settings) { + $('table.token-tree', context).once('token-tree', function () { + $(this).treeTable(); + }); + } +}; + +Drupal.behaviors.tokenInsert = { + attach: function (context, settings) { + // Keep track of which textfield was last selected/focused. + $('textarea, input[type="text"]', context).focus(function() { + Drupal.settings.tokenFocusedField = this; + }); + + $('.token-click-insert .token-key', context).once('token-click-insert', function() { + var newThis = $('' + $(this).html() + '').click(function(){ + if (typeof Drupal.settings.tokenFocusedField == 'undefined') { + alert(Drupal.t('First click a text field to insert your tokens into.')); + } + else { + var myField = Drupal.settings.tokenFocusedField; + var myValue = $(this).text(); + + //IE support + if (document.selection) { + myField.focus(); + sel = document.selection.createRange(); + sel.text = myValue; + } + + //MOZILLA/NETSCAPE support + else if (myField.selectionStart || myField.selectionStart == '0') { + var startPos = myField.selectionStart; + var endPos = myField.selectionEnd; + myField.value = myField.value.substring(0, startPos) + + myValue + + myField.value.substring(endPos, myField.value.length); + } else { + myField.value += myValue; + } + + $('html,body').animate({scrollTop: $(myField).offset().top}, 500); + } + return false; + }); + $(this).html(newThis); + }); + } +}; + +})(jQuery); diff --git a/sites/all/modules/token/token.module b/sites/all/modules/token/token.module new file mode 100644 index 0000000..65f952d --- /dev/null +++ b/sites/all/modules/token/token.module @@ -0,0 +1,1086 @@ +'; + $output .= '
' . t('List of the currently available tokens on this site') . '
'; + $output .= '
' . theme('token_tree', array('token_types' => 'all', 'click_insert' => FALSE, 'show_restricted' => TRUE)) . '
'; + $output .= ''; + return $output; + } +} + +/** + * Implements hook_system_info_alter(). + * + * Prevent the token_actions module from being enabled since updates may have + * left the old module files still in the directory. + */ +function token_system_info_alter(&$info, $file, $type) { + if ($type == 'module' && $file->name == 'token_actions') { + $info['hidden'] = TRUE; + } +} + +/** + * Return an array of the core modules supported by token.module. + */ +function _token_core_supported_modules() { + return array('book', 'field', 'menu', 'profile'); +} + +/** + * Implements hook_menu(). + */ +function token_menu() { + /*$items['token/autocomplete/all/%menu_tail'] = array( + 'page callback' => 'token_autocomplete', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + 'file' => 'token.pages.inc', + );*/ + $items['token/autocomplete/%token_type'] = array( + 'page callback' => 'token_autocomplete_token', + 'page arguments' => array(2), + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + 'file' => 'token.pages.inc', + ); + /*$items['token/autocomplete/%token_type/%menu_tail'] = array( + 'page callback' => 'token_autocomplete_token', + 'page arguments' => array(2, 3), + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + 'file' => 'token.pages.inc', + );*/ + + // Devel token pages. + if (module_exists('devel')) { + $items['node/%node/devel/token'] = array( + 'title' => 'Tokens', + 'page callback' => 'token_devel_token_object', + 'page arguments' => array('node', 1), + 'access arguments' => array('access devel information'), + 'type' => MENU_LOCAL_TASK, + 'file' => 'token.pages.inc', + 'weight' => 5, + ); + $items['comment/%comment/devel/token'] = array( + 'title' => 'Tokens', + 'page callback' => 'token_devel_token_object', + 'page arguments' => array('comment', 1), + 'access arguments' => array('access devel information'), + 'type' => MENU_LOCAL_TASK, + 'file' => 'token.pages.inc', + 'weight' => 5, + ); + $items['taxonomy/term/%taxonomy_term/devel/token'] = array( + 'title' => 'Tokens', + 'page callback' => 'token_devel_token_object', + 'page arguments' => array('taxonomy_term', 2), + 'access arguments' => array('access devel information'), + 'type' => MENU_LOCAL_TASK, + 'file' => 'token.pages.inc', + 'weight' => 5, + ); + $items['user/%user/devel/token'] = array( + 'title' => 'Tokens', + 'page callback' => 'token_devel_token_object', + 'page arguments' => array('user', 1), + 'access arguments' => array('access devel information'), + 'type' => MENU_LOCAL_TASK, + 'file' => 'token.pages.inc', + 'weight' => 5, + ); + } + + // Admin menu callback to clear token caches. + $items['token/flush-cache'] = array( + 'page callback' => 'token_flush_cache_callback', + 'access arguments' => array('flush caches'), + 'type' => MENU_CALLBACK, + 'file' => 'token.pages.inc', + ); + + return $items; +} + +/** + * Implements hook_admin_menu_output_alter(). + */ +function token_admin_menu_output_alter(&$content) { + $content['icon']['icon']['flush-cache']['token'] = array( + '#title' => t('Token registry'), + '#href' => 'token/flush-cache', + '#options' => array( + 'query' => drupal_get_destination() + array('token' => drupal_get_token('token/flush-cache')), + ), + ); +} + +function token_type_load($token_type) { + $info = token_get_info(); + return isset($info['types'][$token_type]) ? $info['types'][$token_type] : FALSE; +} + +/** + * Implements hook_theme(). + */ +function token_theme() { + return array( + 'tree_table' => array( + 'variables' => array('header' => array(), 'rows' => array(), 'attributes' => array(), 'empty' => '', 'caption' => ''), + 'file' => 'token.pages.inc', + ), + 'token_tree' => array( + 'variables' => array('token_types' => array(), 'global_types' => TRUE, 'click_insert' => TRUE, 'show_restricted' => FALSE, 'recursion_limit' => 3), + 'file' => 'token.pages.inc', + ), + ); +} + +/** + * Implements hook_library(). + */ +function token_library() { + // jQuery treeTable plugin. + $libraries['treeTable'] = array( + 'title' => 'jQuery treeTable', + 'website' => 'http://plugins.jquery.com/project/treetable', + 'version' => '2.3.0', + 'js' => array( + drupal_get_path('module', 'token') . '/jquery.treeTable.js' => array(), + ), + 'css' => array( + drupal_get_path('module', 'token') . '/jquery.treeTable.css' => array(), + ), + ); + + return $libraries; +} + +/** + * Implements hook_form_alter(). + * + * Adds a submit handler to forms which could affect the tokens available on + * the site. + */ +function token_form_alter(&$form, $form_state, $form_id) { + switch ($form_id) { + // Profile field forms. + case 'profile_field_form': + case 'profile_field_delete': + // User picture form. + case 'user_admin_settings': + // System date type form. + // @todo Remove when http://drupal.org/node/1173706 is fixed. + case 'system_add_date_format_type_form': + case 'system_delete_date_format_type_form': + $form += array('#submit' => array()); + array_unshift($form['#submit'], 'token_clear_cache'); + break; + } +} + +/** + * Implements hook_field_info_alter(). + */ +function token_field_info_alter(&$info) { + $defaults = array( + 'taxonomy_term_reference' => 'taxonomy_term_reference_plain', + 'number_integer' => 'number_unformatted', + 'number_decimal' => 'number_unformatted', + 'number_float' => 'number_unformatted', + 'file' => 'file_url_plain', + 'image' => 'file_url_plain', + 'text' => 'text_default', + 'text_long' => 'text_default', + 'text_with_summary' => 'text_default', + ); + foreach ($defaults as $field_type => $default_token_formatter) { + if (isset($info[$field_type])) { + $info[$field_type] += array('default_token_formatter' => $default_token_formatter); + } + } +} + +/** + * Implements hook_field_display_alter(). + */ +function token_field_display_alter(&$display, $context) { + if ($context['view_mode'] == 'token') { + $view_mode_settings = field_view_mode_settings($context['instance']['entity_type'], $context['instance']['bundle']); + // If the token view mode fell back to the 'default' view mode, then + // use the default token formatter. + if (empty($view_mode_settings[$context['view_mode']]['custom_settings'])) { + $field_type_info = field_info_field_types($context['field']['type']); + if (!empty($field_type_info['default_token_formatter'])) { + $display['type'] = $field_type_info['default_token_formatter']; + + $formatter_info = field_info_formatter_types($display['type']); + $display['settings'] = isset($formatter_info['settings']) ? $formatter_info['settings'] : array(); + $display['settings']['label'] = 'hidden'; + $display['module'] = $formatter_info['module']; + } + } + } +} + +/** + * Implements hook_field_create_instance(). + */ +function token_field_create_instance($instance) { + token_clear_cache(); +} + +/** + * Implements hook_field_update_instance(). + */ +function token_field_update_instance($instance) { + token_clear_cache(); +} + +/** + * Implements hook_field_delete_instance(). + */ +function token_field_delete_instance($instance) { + token_clear_cache(); +} + +/** + * Clear token caches and static variables. + */ +function token_clear_cache() { + cache_clear_all('*', 'cache_token', TRUE); + drupal_static_reset('token_get_info'); + drupal_static_reset('token_get_global_token_types'); + drupal_static_reset('token_get_entity_mapping'); + drupal_static_reset('token_build_tree'); + drupal_static_reset('_token_profile_fields'); + drupal_static_reset('token_menu_link_load'); + drupal_static_reset('token_book_link_load'); + drupal_static_reset('_token_field_info'); +} + +/** + * Return an array of entity type to token type mappings. + * + * Why do we need this? Because when the token API was moved to core we did not + * re-use the entity type as the base name for taxonomy terms and vocabulary + * tokens. + * + * @see token_entity_info_alter() + * @see http://drupal.org/node/737726 + */ +function token_get_entity_mapping($value_type = 'token', $value = NULL) { + $mapping = &drupal_static(__FUNCTION__, array()); + + if (empty($mapping)) { + foreach (entity_get_info() as $entity_type => $info) { + $mapping[$entity_type] = !empty($info['token type']) ? $info['token type'] : $entity_type; + } + } + + if (!isset($value)) { + return $mapping; + } + elseif ($value_type == 'token') { + return array_search($value, $mapping); + } + elseif ($value_type == 'entity') { + return isset($mapping[$value]) ? $mapping[$value] : FALSE; + } +} + +/** + * Implements hook_entity_info_alter(). + * + * Because some token types to do not match their entity type names, we have to + * map them to the proper type. This is purely for other modules' benefit. + * + * @see token_get_entity_mapping() + * @see http://drupal.org/node/737726 + */ +function token_entity_info_alter(&$info) { + foreach (array_keys($info) as $entity_type) { + // Add a token view mode if it does not already exist. + if (!empty($info[$entity_type]['view modes']) && !isset($info[$entity_type]['view modes']['token'])) { + $info[$entity_type]['view modes']['token'] = array( + 'label' => t('Tokens'), + 'custom settings' => FALSE, + ); + } + + if (!empty($info[$entity_type]['token type'])) { + // If the entity's token type is already defined, great! + continue; + } + + // Fill in default token types for entities. + switch ($entity_type) { + case 'taxonomy_term': + case 'taxonomy_vocabulary': + // Stupid taxonomy token types... + $info[$entity_type]['token type'] = str_replace('taxonomy_', '', $entity_type); + break; + default: + // By default the token type is the same as the entity type. + $info[$entity_type]['token type'] = $entity_type; + break; + } + } +} + +/** + * Implements hook_module_implements_alter(). + * + * Adds missing token support for core modules. + */ +function token_module_implements_alter(&$implementations, $hook) { + if ($hook == 'tokens' || $hook == 'token_info') { + foreach (_token_core_supported_modules() as $module) { + if (module_exists($module)) { + $implementations[$module] = TRUE; + } + } + // Move token.module to get included first since it is responsible for + // other modules. + unset($implementations['token']); + $implementations = array_merge(array('token' => 'tokens'), $implementations); + } +} + +/** + * Implements hook_flush_caches(). + */ +function token_flush_caches() { + return array('cache_token'); +} + +/** + * Retrieve, sort, store token info from the cache. + * + * @param $token_type + * The optional token type that if specified will return + * $info['types'][$token_type]. + * @param $token + * The optional token name if specified will return + * $info['tokens'][$token_type][$token]. + * + * @return + * An array of all token information from hook_token_info(), or the array + * of a token type or specific token. + * + * @see hook_token_info() + * @see hook_token_info_alter() + */ +function token_get_info($token_type = NULL, $token = NULL) { + global $language; + + // Use the advanced drupal_static() pattern, since this is called very often. + static $drupal_static_fast; + if (!isset($drupal_static_fast)) { + $drupal_static_fast['token_info'] = &drupal_static(__FUNCTION__); + } + $token_info = &$drupal_static_fast['token_info']; + + if (empty($token_info)) { + $cid = "info:{$language->language}"; + + if ($cache = cache_get($cid, 'cache_token')) { + $token_info = $cache->data; + } + else { + $token_info = token_info(); + + foreach (array_keys($token_info['types']) as $type_key) { + if (isset($token_info['types'][$type_key]['type'])) { + $base_type = $token_info['types'][$type_key]['type']; + // If this token type extends another token type, then merge in + // the base token type's tokens. + if (isset($token_info['tokens'][$base_type])) { + $token_info['tokens'] += array($type_key => array()); + $token_info['tokens'][$type_key] += $token_info['tokens'][$base_type]; + } + } + else { + // Add a 'type' value to each token type so we can properly use + // token_type_load(). + $token_info['types'][$type_key]['type'] = $type_key; + } + } + + // Pre-sort tokens. + uasort($token_info['types'], 'token_asort_tokens'); + foreach (array_keys($token_info['tokens']) as $type) { + uasort($token_info['tokens'][$type], 'token_asort_tokens'); + } + + // Store info in cache for future use. + cache_set($cid, $token_info, 'cache_token'); + } + } + + if (isset($token_type) && isset($token)) { + return isset($token_info['tokens'][$token_type][$token]) ? $token_info['tokens'][$token_type][$token] : NULL; + } + elseif (isset($token_type)) { + return isset($token_info['types'][$token_type]) ? $token_info['types'][$token_type] : NULL; + } + else { + return $token_info; + } +} + +/** + * Return the module responsible for a token if defined in + * $info['tokens']['type']['module']. + */ +function _token_module($type, $name) { + $token_info = token_get_info($type, $name); + return isset($token_info['module']) ? $token_info['module'] : NULL; +} + +/** + * uasort() callback to sort tokens by the 'name' property. + */ +function token_asort_tokens($token_a, $token_b) { + return strnatcmp($token_a['name'], $token_b['name']); +} + +/** + * Get a list of token types that can be used without any context (global). + * + * @return + * An array of global token types. + */ +function token_get_global_token_types() { + $global_types = &drupal_static(__FUNCTION__, array()); + + if (empty($global_types)) { + $token_info = token_get_info(); + foreach ($token_info['types'] as $type => $type_info) { + // If the token types has not specified that 'needs-data' => TRUE, then + // it is a global token type that will always be replaced in any context. + if (empty($type_info['needs-data'])) { + $global_types[] = $type; + } + } + } + + return $global_types; +} + +/** + * Validate an tokens in raw text based on possible contexts. + * + * @param $value + * A string with the raw text containing the raw tokens, or an array of + * tokens from token_scan(). + * @param $tokens + * An array of token types that will be used when token replacement is + * performed. + * @return + * An array with the invalid tokens in their original raw forms. + */ +function token_get_invalid_tokens_by_context($value, $valid_types = array()) { + if (in_array('all', $valid_types)) { + $info = token_get_info(); + $valid_types = array_keys($info['types']); + } + else { + // Add the token types that are always valid in global context. + $valid_types = array_merge($valid_types, token_get_global_token_types()); + } + + $invalid_tokens = array(); + $value_tokens = is_string($value) ? token_scan($value) : $value; + + foreach ($value_tokens as $type => $tokens) { + if (!in_array($type, $valid_types)) { + // If the token type is not a valid context, its tokens are invalid. + $invalid_tokens = array_merge($invalid_tokens, array_values($tokens)); + } + else { + // Check each individual token for validity. + $invalid_tokens = array_merge($invalid_tokens, token_get_invalid_tokens($type, $tokens)); + } + } + + array_unique($invalid_tokens); + return $invalid_tokens; +} + +/** + * Validate an array of tokens based on their token type. + * + * @param $type + * The type of tokens to validate (e.g. 'node', etc.) + * @param $tokens + * A keyed array of tokens, and their original raw form in the source text. + * @return + * An array with the invalid tokens in their original raw forms. + */ +function token_get_invalid_tokens($type, $tokens) { + $token_info = token_get_info(); + $invalid_tokens = array(); + + foreach ($tokens as $token => $full_token) { + // Split token up if it has chains. + $parts = explode(':', $token, 2); + + if (!isset($token_info['tokens'][$type][$parts[0]])) { + // This is an invalid token (not defined). + $invalid_tokens[] = $full_token; + } + elseif (count($parts) == 2) { + $sub_token_info = $token_info['tokens'][$type][$parts[0]]; + if (!empty($sub_token_info['dynamic'])) { + // If this token has been flagged as a dynamic token, skip it. + continue; + } + elseif (empty($sub_token_info['type'])) { + // If the token has chains, but does not support it, it is invalid. + $invalid_tokens[] = $full_token; + } + else { + // Resursively check the chained tokens. + $sub_tokens = token_find_with_prefix(array($token => $full_token), $parts[0]); + $invalid_tokens = array_merge($invalid_tokens, token_get_invalid_tokens($sub_token_info['type'], $sub_tokens)); + } + } + } + + return $invalid_tokens; +} + +/** + * Validate a form element that should have tokens in it. + * + * Form elements that want to add this validation should have the #token_types + * parameter defined. + * + * For example: + * @code + * $form['my_node_text_element'] = array( + * '#type' => 'textfield', + * '#title' => t('Some text to token-ize that has a node context.'), + * '#default_value' => 'The title of this node is [node:title].', + * '#element_validate' => array('token_element_validate'), + * '#token_types' => array('node'), + * '#min_tokens' => 1, + * '#max_tokens' => 10, + * ); + * @endcode + */ +function token_element_validate(&$element, &$form_state) { + $value = isset($element['#value']) ? $element['#value'] : $element['#default_value']; + + if (!drupal_strlen($value)) { + // Empty value needs no further validation since the element should depend + // on using the '#required' FAPI property. + return $element; + } + + $tokens = token_scan($value); + $title = empty($element['#title']) ? $element['#parents'][0] : $element['#title']; + // @todo Find old Drupal 6 style tokens and add them to invalid tokens. + + // Validate if an element must have a minimum number of tokens. + if (isset($element['#min_tokens']) && count($tokens) < $element['#min_tokens']) { + // @todo Change this error message to include the minimum number. + $error = format_plural($element['#min_tokens'], 'The %element-title cannot contain fewer than one token.', 'The %element-title must contain at least @count tokens.', array('%element-title' => $title)); + form_error($element, $error); + } + + // Validate if an element must have a maximum number of tokens. + if (isset($element['#max_tokens']) && count($tokens) > $element['#max_tokens']) { + // @todo Change this error message to include the maximum number. + $error = format_plural($element['#max_tokens'], 'The %element-title must contain as most one token.', 'The %element-title must contain at most @count tokens.', array('%element-title' => $title)); + form_error($element, $error); + } + + // Check if the field defines specific token types. + if (!empty($element['#token_types'])) { + $invalid_tokens = token_get_invalid_tokens_by_context($tokens, $element['#token_types']); + if ($invalid_tokens) { + form_error($element, t('The %element-title is using the following invalid tokens: @invalid-tokens.', array('%element-title' => $title, '@invalid-tokens' => implode(', ', $invalid_tokens)))); + } + } + + return $element; +} + +/** + * Deprecated. Use token_element_validate() instead. + */ +function token_element_validate_token_context(&$element, &$form_state) { + return token_element_validate($element, $form_state); +} + +/** + * Implements hook_form_FORM_ID_alter(). + */ +function token_form_field_ui_field_edit_form_alter(&$form, $form_state) { + if (($form['#field']['type'] == 'file' || $form['#field']['type'] == 'image') && isset($form['instance']['settings']['file_directory']) && !module_exists('filefield_paths')) { + // GAH! We can only support global tokens in the upload file directory path. + $form['instance']['settings']['file_directory']['#element_validate'][] = 'token_element_validate'; + $form['instance']['settings']['file_directory']['#token_types'] = array(); + $form['instance']['settings']['token_tree'] = array( + '#theme' => 'token_tree', + '#token_types' => array(), + '#weight' => $form['instance']['settings']['file_directory']['#weight'] + 0.5, + ); + } +} + +/** + * Implements hook_form_FORM_ID_alter(). + * + * Alters the configure action form to add token context validation and + * adds the token tree for a better token UI and selection. + */ +function token_form_system_actions_configure_alter(&$form, $form_state) { + $action = actions_function_lookup($form['actions_action']['#value']); + + switch ($action) { + case 'system_message_action': + case 'system_send_email_action': + case 'system_goto_action': + $form['token_tree'] = array( + '#theme' => 'token_tree', + '#token_types' => 'all', + '#weight' => 100, + ); + // @todo Add token validation to the action fields that can use tokens. + break; + } +} + +/** + * Implements hook_form_FORM_ID_alter(). + * + * Alters the user e-mail fields to add token context validation and + * adds the token tree for a better token UI and selection. + */ +function token_form_user_admin_settings_alter(&$form, &$form_state) { + $email_token_help = t('Available variables are: [site:name], [site:url], [user:name], [user:mail], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url].'); + + foreach (element_children($form) as $key) { + $element = &$form[$key]; + + // Remove the crummy default token help text. + if (!empty($element['#description'])) { + $element['#description'] = trim(str_replace($email_token_help, t('The list of available tokens that can be used in e-mails is provided below.'), $element['#description'])); + } + + switch ($key) { + case 'email_admin_created': + case 'email_pending_approval': + case 'email_no_approval_required': + case 'email_password_reset': + case 'email_cancel_confirm': + // Do nothing, but allow execution to continue. + break; + case 'email_activated': + case 'email_blocked': + case 'email_canceled': + // These fieldsets have their e-mail elements inside a 'settings' + // sub-element, so switch to that element instead. + $element = &$form[$key]['settings']; + break; + default: + continue 2; + } + + foreach (element_children($element) as $sub_key) { + if (!isset($element[$sub_key]['#type'])) { + continue; + } + elseif ($element[$sub_key]['#type'] == 'textfield' && substr($sub_key, -8) === '_subject') { + // Add validation to subject textfields. + $element[$sub_key]['#element_validate'][] = 'token_element_validate'; + $element[$sub_key] += array('#token_types' => array('user')); + } + elseif ($element[$sub_key]['#type'] == 'textarea' && substr($sub_key, -5) === '_body') { + // Add validation to body textareas. + $element[$sub_key]['#element_validate'][] = 'token_element_validate'; + $element[$sub_key] += array('#token_types' => array('user')); + } + } + } + + // Add the token tree UI. + $form['token_tree'] = array( + '#theme' => 'token_tree', + '#token_types' => array('user'), + '#show_restricted' => TRUE, + '#weight' => 90, + ); +} + +/** + * Build a tree array of tokens used for themeing or information. + * + * @param $token_type + * The token type. + * @param $flat_tree + * A boolean if TRUE will only make a flat array of tokens, otherwise + * child tokens will be inside the 'children' parameter of a token. + * @param $show_restricted + * A boolean if TRUE will show restricted tokens. Otherwise they will be + * hidden. Default is FALSE. + * @param $recursion_limit + * An integer with the maximum number of token levels to recurse. + * @param $parents + * An optional array with the current parents of the tokens. + */ +function token_build_tree($token_type, array $options = array()) { + global $language; + + // Static cache of already built token trees. + $trees = &drupal_static(__FUNCTION__, array()); + + $options += array( + 'restricted' => FALSE, + 'depth' => 4, + 'data' => array(), + 'values' => FALSE, + 'flat' => FALSE, + ); + + // Do not allow past the maximum token information depth. + $options['depth'] = min($options['depth'], TOKEN_MAX_DEPTH); + + // If $token_type is an entity, make sure we are using the actual token type. + if ($entity_token_type = token_get_entity_mapping('entity', $token_type)) { + $token_type = $entity_token_type; + } + + $tree_cid = "tree:{$token_type}:{$language->language}:{$options['depth']}"; + + // If we do not have this base tree in the static cache, check {cache_token} + // otherwise generate and store it in the cache. + if (!isset($trees[$tree_cid])) { + if ($cache = cache_get($tree_cid, 'cache_token')) { + $trees[$tree_cid] = $cache->data; + } + else { + $options['parents'] = array(); + $trees[$tree_cid] = _token_build_tree($token_type, $options); + cache_set($tree_cid, $trees[$tree_cid], 'cache_token'); + } + } + + $tree = $trees[$tree_cid]; + + // If the user has requested a flat tree, convert it. + if (!empty($options['flat'])) { + $tree = token_flatten_tree($tree); + } + + // Fill in token values. + if (!empty($options['values'])) { + $token_values = array(); + foreach ($tree as $token => $token_info) { + if (!empty($token_info['dynamic']) || !empty($token_info['restricted'])) { + continue; + } + elseif (!isset($token_info['value'])) { + $token_values[$token_info['token']] = $token; + } + } + if (!empty($token_values)) { + $token_values = token_generate($token_type, $token_values, $options['data']); + foreach ($token_values as $token => $replacement) { + $tree[$token]['value'] = $replacement; + } + } + } + + return $tree; +} + +/** + * Flatten a token tree. + */ +function token_flatten_tree($tree) { + $result = array(); + foreach ($tree as $token => $token_info) { + $result[$token] = $token_info; + if (isset($token_info['children']) && is_array($token_info['children'])) { + $result += token_flatten_tree($token_info['children']); + //unset($result[$token]['children']); + } + } + return $result; +} + +/** + * Generate a token tree. + */ +function _token_build_tree($token_type, array $options) { + $options += array( + 'parents' => array(), + ); + + $info = token_get_info(); + if ($options['depth'] <= 0 || !isset($info['types'][$token_type]) || !isset($info['tokens'][$token_type])) { + return array(); + } + + $tree = array(); + foreach ($info['tokens'][$token_type] as $token => $token_info) { + // Build the raw token string. + $token_parents = $options['parents']; + if (empty($token_parents)) { + // If the parents array is currently empty, assume the token type is its + // parent. + $token_parents[] = $token_type; + } + elseif (in_array($token, array_slice($token_parents, 1))) { + // Prevent duplicate recursive tokens. For example, this will prevent + // the tree from generating the following tokens or deeper: + // [comment:parent:parent] + // [comment:parent:root:parent] + continue; + } + + $token_parents[] = $token; + if (!empty($token_info['dynamic'])) { + $token_parents[] = '?'; + } + $raw_token = '[' . implode(':', $token_parents) . ']'; + $tree[$raw_token] = $token_info; + $tree[$raw_token]['raw token'] = $raw_token; + + // Add the token's real name (leave out the base token type). + $tree[$raw_token]['token'] = implode(':', array_slice($token_parents, 1)); + + // Add the token's parent as its raw token value. + if (!empty($options['parents'])) { + $tree[$raw_token]['parent'] = '[' . implode(':', $options['parents']) . ']'; + } + + // Fetch the child tokens. + if (!empty($token_info['type'])) { + $child_options = $options; + $child_options['depth']--; + $child_options['parents'] = $token_parents; + $tree[$raw_token]['children'] = _token_build_tree($token_info['type'], $child_options); + } + } + + return $tree; +} + +/** + * Get a translated menu link by its mlid, without access checking. + * + * This function is a copy of menu_link_load() but with its own cache and a + * simpler query to load the link. This also skips normal menu link access + * checking by using _token_menu_link_translate(). + * + * @param $mlid + * The mlid of the menu item. + * + * @return + * A menu link translated for rendering. + * + * @see menu_link_load() + * @see _token_menu_link_translate() + */ +function token_menu_link_load($mlid) { + $cache = &drupal_static(__FUNCTION__, array()); + + if (!is_numeric($mlid)) { + return FALSE; + } + + if (!isset($cache[$mlid])) { + $item = db_query("SELECT * FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path WHERE ml.mlid = :mlid", array(':mlid' => $mlid))->fetchAssoc(); + if (!empty($item)) { + _token_menu_link_translate($item); + } + $cache[$mlid] = $item; + } + + return $cache[$mlid]; +} + +/** + * Get a translated book menu link by its mlid, without access checking. + * + * This function is a copy of book_link_load() but with its own cache and a + * simpler query to load the link. This also skips normal menu link access + * checking by using _token_menu_link_translate(). + * + * @param $mlid + * The mlid of the book menu item. + * + * @return + * A book menu link translated for rendering. + * + * @see book_link_load() + * @see _token_menu_link_translate() + */ +function token_book_link_load($mlid) { + $cache = &drupal_static(__FUNCTION__, array()); + + if (!is_numeric($mlid)) { + return FALSE; + } + + if (!isset($cache[$mlid])) { + $item = db_query("SELECT * FROM {menu_links} ml INNER JOIN {book} b ON b.mlid = ml.mlid LEFT JOIN {menu_router} m ON m.path = ml.router_path WHERE ml.mlid = :mlid", array(':mlid' => $mlid))->fetchAssoc(); + if (!empty($item)) { + _token_menu_link_translate($item); + } + $cache[$mlid] = $item; + } + + return $cache[$mlid]; +} + +function _token_menu_link_translate(&$item) { + $map = array(); + + if (!is_array($item['options'])) { + $item['options'] = unserialize($item['options']); + } + + if ($item['external']) { + $item['access'] = 1; + $item['href'] = $item['link_path']; + $item['title'] = $item['link_title']; + $item['localized_options'] = $item['options']; + } + else { + // Complete the path of the menu link with elements from the current path, + // if it contains dynamic placeholders (%). + $map = explode('/', $item['link_path']); + if (strpos($item['link_path'], '%') !== FALSE) { + // Invoke registered to_arg callbacks. + if (!empty($item['to_arg_functions'])) { + _menu_link_map_translate($map, $item['to_arg_functions']); + } + } + $item['href'] = implode('/', $map); + + // Skip links containing untranslated arguments. + if (strpos($item['href'], '%') !== FALSE) { + $item['access'] = FALSE; + return FALSE; + } + + $item['access'] = TRUE; + _menu_item_localize($item, $map, TRUE); + } + + // Allow other customizations - e.g. adding a page-specific query string to the + // options array. For performance reasons we only invoke this hook if the link + // has the 'alter' flag set in the options array. + if (!empty($item['options']['alter'])) { + drupal_alter('translated_menu_link', $item, $map); + } + + return $map; +} + +/** + * Prepare a string for use as a valid token name. + * + * @param $name + * The token name to clean. + * @return + * The cleaned token name. + */ +function token_clean_token_name($name) { + static $names = array(); + + if (!isset($names[$name])) { + $cleaned_name = strtr($name, array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => '')); + $cleaned_name = preg_replace('/[^\w\-]/i', '', $cleaned_name); + $cleaned_name = trim($cleaned_name, '-'); + $names[$name] = $cleaned_name; + } + + return $names[$name]; +} + +/** + * Do not use this function yet. Its API has not been finalized. + */ +function token_render_array(array $array, array $options = array()) { + $rendered = array(); + foreach (element_children($array) as $key) { + $value = $array[$key]; + $rendered[] = is_array($value) ? render($value) : (string) $value; + } + if (!empty($options['sanitize'])) { + $rendered = array_map('check_plain', $rendered); + } + $join = isset($options['join']) ? $options['join'] : ', '; + return implode($join, $rendered); +} + +/** + * Do not use this function yet. Its API has not been finalized. + */ +function token_render_array_value($value, array $options = array()) { + $rendered = is_array($value) ? render($value) : (string) $value; + if (!empty($options['sanitize'])) { + $rendered = check_plain($rendered); + } + return $rendered; +} + +/** + * Copy of drupal_render_cache_get() that does not care about request method. + */ +function token_render_cache_get($elements) { + if (!$cid = drupal_render_cid_create($elements)) { + return FALSE; + } + $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache'; + + if (!empty($cid) && $cache = cache_get($cid, $bin)) { + // Add additional libraries, JavaScript, CSS and other data attached + // to this element. + if (isset($cache->data['#attached'])) { + drupal_process_attached($cache->data); + } + // Return the rendered output. + return $cache->data['#markup']; + } + return FALSE; +} + +/** + * Coyp of drupal_render_cache_set() that does not care about request method. + */ +function token_render_cache_set(&$markup, $elements) { + // This should only run of drupal_render_cache_set() did not. + if (in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD'))) { + return FALSE; + } + + $original_method = $_SERVER['REQUEST_METHOD']; + $_SERVER['REQUEST_METHOD'] = 'GET'; + drupal_render_cache_set($markup, $elements); + $_SERVER['REQUEST_METHOD'] = $original_method; +} diff --git a/sites/all/modules/token/token.pages.inc b/sites/all/modules/token/token.pages.inc new file mode 100644 index 0000000..cf4c2d1 --- /dev/null +++ b/sites/all/modules/token/token.pages.inc @@ -0,0 +1,300 @@ + array()); + if (!empty($row['parent'])) { + $row['class'][] = 'child-of-' . $row['parent']; + unset($row['parent']); + } + } + + if (!empty($variables['rows'])) { + drupal_add_library('token', 'treeTable'); + } + + return theme('table', $variables); +} + +/** + * Provide a 'tree' display of nested tokens. + * + * @ingroup themeable + */ +function theme_token_tree($variables) { + $token_types = $variables['token_types']; + $info = token_get_info(); + + if ($token_types == 'all') { + $token_types = array_keys($info['types']); + } + elseif ($variables['global_types']) { + $token_types = array_merge($token_types, token_get_global_token_types()); + } + + $element = array( + '#cache' => array( + 'cid' => 'tree-rendered:' . hash('sha256', serialize(array('token_types' => $token_types, 'global_types' => NULL) + $variables)), + 'bin' => 'cache_token', + ), + ); + if ($cached_output = token_render_cache_get($element)) { + return $cached_output; + } + + $options = array( + 'flat' => TRUE, + 'restricted' => $variables['show_restricted'], + 'depth' => $variables['recursion_limit'], + ); + $multiple_token_types = (count($token_types) > 1); + $rows = array(); + + foreach ($info['types'] as $type => $type_info) { + if (!in_array($type, $token_types)) { + continue; + } + + if ($multiple_token_types) { + $row = _token_token_tree_format_row($type, $type_info, TRUE); + unset($row['data']['value']); + $rows[] = $row; + } + + $tree = token_build_tree($type, $options); + foreach ($tree as $token => $token_info) { + if (!empty($token_info['restricted']) && empty($variables['show_restricted'])) { + continue; + } + if ($multiple_token_types && !isset($token_info['parent'])) { + $token_info['parent'] = $type; + } + $row = _token_token_tree_format_row($token, $token_info); + unset($row['data']['value']); + $rows[] = $row; + } + } + + $element += array( + '#theme' => 'tree_table', + '#header' => array( + t('Name'), + t('Token'), + t('Description'), + ), + '#rows' => $rows, + '#attributes' => array('class' => array('token-tree')), + '#empty' => t('No tokens available'), + '#attached' => array( + 'js' => array(drupal_get_path('module', 'token') . '/token.js'), + 'css' => array(drupal_get_path('module', 'token') . '/token.css'), + 'library' => array(array('token', 'treeTable')), + ), + ); + + if ($variables['click_insert']) { + $element['#caption'] = t('Click a token to insert it into the field you\'ve last clicked.'); + $element['#attributes']['class'][] = 'token-click-insert'; + } + + $output = drupal_render($element); + token_render_cache_set($output, $element); + return $output; +} + +/** + * Build a row in the token tree. + */ +function _token_token_tree_format_row($token, array $token_info, $is_group = FALSE) { + // Build a statically cached array of default values. This is around four + // times as efficient as building the base array from scratch each time this + // function is called. + static $defaults = array( + 'id' => '', + 'class' => array(), + 'data' => array( + 'name' => '', + 'token' => '', + 'value' => '', + 'description' => '', + ), + ); + + $row = $defaults; + $row['id'] = _token_clean_css_identifier($token); + $row['data']['name'] = $token_info['name']; + $row['data']['description'] = $token_info['description']; + + if ($is_group) { + // This is a token type/group. + $row['class'][] = 'token-group'; + } + else { + // This is a token. + $row['data']['token']['data'] = $token; + $row['data']['token']['class'][] = 'token-key'; + if (isset($token_info['value'])) { + $row['data']['value'] = $token_info['value']; + } + if (!empty($token_info['parent'])) { + $row['parent'] = _token_clean_css_identifier($token_info['parent']); + } + } + + return $row; +} + +/** + * Wrapper function for drupal_clean_css_identifier() for use with tokens. + * + * This trims any brackets from the token and also cleans the colon character + * to a hyphen. + * + * @see drupal_clean_css_identifier() + */ +function _token_clean_css_identifier($id) { + static $replacements = array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => '', ':' => '--', '?' => ''); + return 'token-' . rtrim(strtr(trim($id, '[]'), $replacements), '-'); +} + +/** + * Menu callback; prints the available tokens and values for an object. + */ +function token_devel_token_object($entity_type, $entity) { + $header = array( + t('Token'), + t('Value'), + ); + $rows = array(); + + $options = array( + 'flat' => TRUE, + 'values' => TRUE, + 'data' => array($entity_type => $entity), + ); + $tree = token_build_tree($entity_type, $options); + foreach ($tree as $token => $token_info) { + if (!empty($token_info['restricted'])) { + continue; + } + if (!isset($token_info['value']) && !empty($token_info['parent']) && !isset($tree[$token_info['parent']]['value'])) { + continue; + } + $row = _token_token_tree_format_row($token, $token_info); + unset($row['data']['description']); + unset($row['data']['name']); + $rows[] = $row; + } + + $build['tokens'] = array( + '#theme' => 'tree_table', + '#header' => $header, + '#rows' => $rows, + '#attributes' => array('class' => array('token-tree')), + '#empty' => t('No tokens available.'), + '#attached' => array( + 'js' => array(drupal_get_path('module', 'token') . '/token.js'), + 'css' => array(drupal_get_path('module', 'token') . '/token.css'), + ), + ); + + return $build; +} + +/** + * Page callback to clear the token registry caches. + */ +function token_flush_cache_callback() { + if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], current_path())) { + return MENU_NOT_FOUND; + } + + token_clear_cache(); + drupal_set_message(t('Token registry caches cleared.')); + drupal_goto(); +} + +function token_autocomplete() { + $args = func_get_args(); + $string = implode('/', $args); + + $token_info = token_info(); + + preg_match_all('/\[([^\s\]:]*):?([^\s\]]*)?\]?/', $string, $matches); + $types = $matches[1]; + $tokens = $matches[2]; + + foreach ($types as $index => $type) { + if (!empty($tokens[$index]) || isset($token_info['types'][$type])) { + token_autocomplete_token($type, $tokens[$index]); + } + else { + token_autocomplete_type($type); + } + } + +} + +function token_autocomplete_type($string = '') { + $token_info = token_info(); + $types = $token_info['types']; + $matches = array(); + + foreach ($types as $type => $info) { + if (!$string || strpos($type, $string) === 0) { + $type_key = "[{$type}:"; + $matches[$type_key] = levenshtein($type, $string); + } + } + + if ($string) { + asort($matches); + } + else { + ksort($matches); + } + + $matches = drupal_map_assoc(array_keys($matches)); + drupal_json_output($matches); +} + +function token_autocomplete_token($token_type) { + $args = func_get_args(); + array_shift($args); + $string = trim(implode('/', $args)); + $string = substr($string, strrpos($string, '[')); + + $token_type = $token_type['type']; + $matches = array(); + + if (!drupal_strlen($string)) { + $matches["[{$token_type}:"] = 0; + } + else { + $depth = max(1, substr_count($string, ':')); + $tree = token_build_tree($token_type, array('flat' => TRUE, 'depth' => $depth)); + foreach (array_keys($tree) as $token) { + if (strpos($token, $string) === 0) { + $matches[$token] = levenshtein($token, $string); + if (isset($tree[$token]['children'])) { + $token = rtrim($token, ':]') . ':'; + $matches[$token] = levenshtein($token, $string); + } + } + } + } + + asort($matches); + $matches = drupal_map_assoc(array_keys($matches)); + drupal_json_output($matches); +} diff --git a/sites/all/modules/token/token.test b/sites/all/modules/token/token.test new file mode 100644 index 0000000..59ecb92 --- /dev/null +++ b/sites/all/modules/token/token.test @@ -0,0 +1,949 @@ +assertTokens($type, $data, array($token => $expected), $options); + } + + function assertTokens($type, array $data, array $tokens, array $options = array()) { + $input = $this->mapTokenNames($type, array_keys($tokens)); + $replacements = token_generate($type, $input, $data, $options); + foreach ($tokens as $name => $expected) { + $token = $input[$name]; + if (!isset($expected)) { + $this->assertTrue(!isset($values[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token))); + } + elseif (!isset($replacements[$token])) { + $this->fail(t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token))); + } + elseif (!empty($options['regex'])) { + $this->assertTrue(preg_match('/^' . $expected . '$/', $replacements[$token]), t("Token value for @token was '@actual', matching regular expression pattern '@expected'.", array('@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected))); + } + else { + $this->assertIdentical($replacements[$token], $expected, t("Token value for @token was '@actual', expected value '@expected'.", array('@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected))); + } + } + + return $replacements; + } + + function mapTokenNames($type, array $tokens = array()) { + $return = array(); + foreach ($tokens as $token) { + $return[$token] = "[$type:$token]"; + } + return $return; + } + + function assertNoTokens($type, array $data, array $tokens, array $options = array()) { + $input = $this->mapTokenNames($type, $tokens); + $replacements = token_generate($type, $input, $data, $options); + foreach ($tokens as $name) { + $token = $input[$name]; + $this->assertTrue(!isset($replacements[$token]), t("Token value for @token was not generated.", array('@type' => $type, '@token' => $token))); + } + return $values; + } + + function saveAlias($source, $alias, $language = LANGUAGE_NONE) { + $alias = array( + 'source' => $source, + 'alias' => $alias, + 'language' => $language, + ); + path_save($alias); + return $alias; + } + + function saveEntityAlias($entity_type, $entity, $alias, $language = LANGUAGE_NONE) { + $uri = entity_uri($entity_type, $entity); + return $this->saveAlias($uri['path'], $alias, $language); + } + + /** + * Make a page request and test for token generation. + */ + function assertPageTokens($url, array $tokens, array $data = array(), array $options = array()) { + if (empty($tokens)) { + return TRUE; + } + + $token_page_tokens = array( + 'tokens' => $tokens, + 'data' => $data, + 'options' => $options, + ); + variable_set('token_page_tokens', $token_page_tokens); + + $options += array('url_options' => array()); + $this->drupalGet($url, $options['url_options']); + $this->refreshVariables(); + $result = variable_get('token_page_tokens', array()); + + if (!isset($result['values']) || !is_array($result['values'])) { + return $this->fail('Failed to generate tokens.'); + } + + foreach ($tokens as $token => $expected) { + if (!isset($expected)) { + $this->assertTrue(!isset($result['values'][$token]) || $result['values'][$token] === $token, t("Token value for @token was not generated.", array('@token' => $token))); + } + elseif (!isset($result['values'][$token])) { + $this->fail(t('Failed to generate token @token.', array('@token' => $token))); + } + else { + $this->assertIdentical($result['values'][$token], (string) $expected, t("Token value for @token was '@actual', expected value '@expected'.", array('@token' => $token, '@actual' => $result['values'][$token], '@expected' => $expected))); + } + } + } +} + +class TokenUnitTestCase extends TokenTestHelper { + public static function getInfo() { + return array( + 'name' => 'Token unit tests', + 'description' => 'Test basic, low-level token functions.', + 'group' => 'Token', + ); + } + + /** + * Test token_get_invalid_tokens() and token_get_invalid_tokens_by_context(). + */ + public function testGetInvalidTokens() { + $tests = array(); + $tests[] = array( + 'valid tokens' => array( + '[node:title]', + '[node:created:short]', + '[node:created:custom:invalid]', + '[node:created:custom:mm-YYYY]', + '[site:name]', + '[site:slogan]', + '[current-date:short]', + '[current-user:uid]', + '[current-user:ip-address]', + ), + 'invalid tokens' => array( + '[node:title:invalid]', + '[node:created:invalid]', + '[node:created:short:invalid]', + '[invalid:title]', + '[site:invalid]', + '[user:ip-address]', + '[user:uid]', + '[comment:cid]', + // Deprecated tokens + '[node:tnid]', + '[node:type]', + '[node:type-name]', + '[date:short]', + ), + 'types' => array('node'), + ); + $tests[] = array( + 'valid tokens' => array( + '[node:title]', + '[node:created:short]', + '[node:created:custom:invalid]', + '[node:created:custom:mm-YYYY]', + '[site:name]', + '[site:slogan]', + '[user:uid]', + '[comment:cid]', + '[current-date:short]', + '[current-user:uid]', + ), + 'invalid tokens' => array( + '[node:title:invalid]', + '[node:created:invalid]', + '[node:created:short:invalid]', + '[invalid:title]', + '[site:invalid]', + '[user:ip-address]', + // Deprecated tokens + '[node:tnid]', + '[node:type]', + '[node:type-name]', + ), + 'types' => array('all'), + ); + + foreach ($tests as $test) { + $tokens = array_merge($test['valid tokens'], $test['invalid tokens']); + shuffle($tokens); + + $invalid_tokens = token_get_invalid_tokens_by_context(implode(' ', $tokens), $test['types']); + + sort($invalid_tokens); + sort($test['invalid tokens']); + $this->assertEqual($invalid_tokens, $test['invalid tokens'], 'Invalid tokens detected properly: ' . implode(', ', $invalid_tokens)); + } + } +} + +class TokenURLTestCase extends TokenTestHelper { + public static function getInfo() { + return array( + 'name' => 'URL token tests', + 'description' => 'Test the URL tokens.', + 'group' => 'Token', + ); + } + + function setUp($modules = array()) { + parent::setUp($modules); + $this->saveAlias('node/1', 'first-node'); + variable_set('clean_url', 1); + } + + function testURLTokens() { + $tokens = array( + 'absolute' => 'http://example.com/first-node', + 'relative' => base_path() . 'first-node', + 'path' => 'first-node', + 'brief' => 'example.com/first-node', + 'args:value:0' => 'first-node', + 'args:value:1' => NULL, + 'args:value:N' => NULL, + 'unaliased' => 'http://example.com/node/1', + 'unaliased:relative' => base_path() . 'node/1', + 'unaliased:path' => 'node/1', + 'unaliased:brief' => 'example.com/node/1', + 'unaliased:args:value:0' => 'node', + 'unaliased:args:value:1' => '1', + 'unaliased:args:value:2' => NULL, + // Deprecated tokens. + 'alias' => 'first-node', + ); + $this->assertTokens('url', array('path' => 'node/1', 'options' => array('base_url' => 'http://example.com')), $tokens); + } +} + +class TokenCommentTestCase extends TokenTestHelper { + public static function getInfo() { + return array( + 'name' => 'Comment token tests', + 'description' => 'Test the comment tokens.', + 'group' => 'Token', + ); + } + + function testCommentTokens() { + $node = $this->drupalCreateNode(array('comment' => COMMENT_NODE_OPEN)); + + $parent_comment = new stdClass; + $parent_comment->nid = $node->nid; + $parent_comment->pid = 0; + $parent_comment->cid = NULL; + $parent_comment->uid = 0; + $parent_comment->name = 'anonymous user'; + $parent_comment->mail = 'anonymous@example.com'; + $parent_comment->subject = $this->randomName(); + $parent_comment->timestamp = mt_rand($node->created, REQUEST_TIME); + $parent_comment->language = LANGUAGE_NONE; + $parent_comment->body[LANGUAGE_NONE][0] = $this->randomName(); + comment_save($parent_comment); + + $tokens = array( + 'url' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)), + 'url:absolute' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)), + 'url:relative' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => FALSE)), + 'url:path' => 'comment/' . $parent_comment->cid, + 'parent:url:absolute' => NULL, + ); + $this->assertTokens('comment', array('comment' => $parent_comment), $tokens); + + $comment = new stdClass(); + $comment->nid = $node->nid; + $comment->pid = $parent_comment->cid; + $comment->cid = NULL; + $comment->uid = 1; + $comment->subject = $this->randomName(); + $comment->timestamp = mt_rand($parent_comment->created, REQUEST_TIME); + $comment->language = LANGUAGE_NONE; + $comment->body[LANGUAGE_NONE][0] = $this->randomName(); + comment_save($comment); + + $tokens = array( + 'url' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => TRUE)), + 'url:absolute' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => TRUE)), + 'url:relative' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => FALSE)), + 'url:path' => 'comment/' . $comment->cid, + 'parent:url:absolute' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)), + ); + $this->assertTokens('comment', array('comment' => $comment), $tokens); + } +} + +class TokenNodeTestCase extends TokenTestHelper { + public static function getInfo() { + return array( + 'name' => 'Node and content type token tests', + 'description' => 'Test the node and content type tokens.', + 'group' => 'Token', + ); + } + + function testNodeTokens() { + $source_node = $this->drupalCreateNode(array('log' => $this->randomName(), 'path' => array('alias' => 'content/source-node'))); + $tokens = array( + 'source' => NULL, + 'source:nid' => NULL, + 'log' => $source_node->log, + 'url:path' => 'content/source-node', + 'url:absolute' => url("node/{$source_node->nid}", array('absolute' => TRUE)), + 'url:relative' => url("node/{$source_node->nid}", array('absolute' => FALSE)), + 'url:unaliased:path' => "node/{$source_node->nid}", + 'content-type' => 'Basic page', + 'content-type:name' => 'Basic page', + 'content-type:machine-name' => 'page', + 'content-type:description' => "Use basic pages for your static content, such as an 'About us' page.", + 'content-type:node-count' => 1, + 'content-type:edit-url' => url('admin/structure/types/manage/page', array('absolute' => TRUE)), + // Deprecated tokens. + 'tnid' => 0, + 'type' => 'page', + 'type-name' => 'Basic page', + 'url:alias' => 'content/source-node', + ); + $this->assertTokens('node', array('node' => $source_node), $tokens); + + $translated_node = $this->drupalCreateNode(array('tnid' => $source_node->nid, 'type' => 'article')); + $tokens = array( + 'source' => $source_node->title, + 'source:nid' => $source_node->nid, + 'log' => '', + 'url:path' => "node/{$translated_node->nid}", + 'url:absolute' => url("node/{$translated_node->nid}", array('absolute' => TRUE)), + 'url:relative' => url("node/{$translated_node->nid}", array('absolute' => FALSE)), + 'url:unaliased:path' => "node/{$translated_node->nid}", + 'content-type' => 'Article', + 'content-type:name' => 'Article', + 'content-type:machine-name' => 'article', + 'content-type:description' => "Use articles for time-sensitive content like news, press releases or blog posts.", + 'content-type:node-count' => 1, + 'content-type:edit-url' => url('admin/structure/types/manage/article', array('absolute' => TRUE)), + // Deprecated tokens. + 'type' => 'article', + 'type-name' => 'Article', + 'tnid' => $source_node->nid, + 'url:alias' => "node/{$translated_node->nid}", + ); + $this->assertTokens('node', array('node' => $translated_node), $tokens); + } +} + +class TokenMenuTestCase extends TokenTestHelper { + public static function getInfo() { + return array( + 'name' => 'Menu link and menu token tests', + 'description' => 'Test the menu tokens.', + 'group' => 'Token', + ); + } + + function setUp($modules = array()) { + $modules[] = 'menu'; + parent::setUp($modules); + } + + function testMenuTokens() { + // Add a root link. + $root_link = array( + 'link_path' => 'root', + 'link_title' => 'Root link', + 'menu_name' => 'main-menu', + ); + menu_link_save($root_link); + + // Add another link with the root link as the parent + $parent_link = array( + 'link_path' => 'root/parent', + 'link_title' => 'Parent link', + 'menu_name' => 'main-menu', + 'plid' => $root_link['mlid'], + ); + menu_link_save($parent_link); + + // Test menu link tokens. + $tokens = array( + 'mlid' => $parent_link['mlid'], + 'title' => 'Parent link', + 'menu' => 'Main menu', + 'menu:name' => 'Main menu', + 'menu:machine-name' => 'main-menu', + 'menu:description' => 'The Main menu is used on many sites to show the major sections of the site, often in a top navigation bar.', + 'menu:menu-link-count' => 3, // Standard install creates one link. + 'menu:edit-url' => url("admin/structure/menu/manage/main-menu", array('absolute' => TRUE)), + 'url' => url('root/parent', array('absolute' => TRUE)), + 'url:absolute' => url('root/parent', array('absolute' => TRUE)), + 'url:relative' => url('root/parent', array('absolute' => FALSE)), + 'url:path' => 'root/parent', + 'url:alias' => 'root/parent', + 'edit-url' => url("admin/structure/menu/item/{$parent_link['mlid']}/edit", array('absolute' => TRUE)), + 'parent' => 'Root link', + 'parent:mlid' => $root_link['mlid'], + 'parent:title' => 'Root link', + 'parent:menu' => 'Main menu', + 'parent:parent' => NULL, + 'root' => 'Root link', + 'root:mlid' => $root_link['mlid'], + 'root:parent' => NULL, + 'root:root' => NULL, + ); + $this->assertTokens('menu-link', array('menu-link' => $parent_link), $tokens); + + // Add a node menu link + $node_link = array( + 'enabled' => TRUE, + 'link_title' => 'Node link', + 'plid' => $parent_link['mlid'], + 'customized' => 0, + 'description' => '', + ); + $node = $this->drupalCreateNode(array('menu' => $node_link)); + + // Test [node:menu] tokens. + $tokens = array( + 'menu-link' => 'Node link', + 'menu-link:mlid' => $node->menu['mlid'], + 'menu-link:title' => 'Node link', + 'menu-link:menu' => 'Main menu', + 'menu-link:url' => url('node/' . $node->nid, array('absolute' => TRUE)), + 'menu-link:url:path' => 'node/' . $node->nid, + 'menu-link:edit-url' => url("admin/structure/menu/item/{$node->menu['mlid']}/edit", array('absolute' => TRUE)), + 'menu-link:parent' => 'Parent link', + 'menu-link:parent:mlid' => $node->menu['plid'], + 'menu-link:parent:mlid' => $parent_link['mlid'], + 'menu-link:root' => 'Root link', + 'menu-link:root:mlid' => $root_link['mlid'], + ); + $this->assertTokens('node', array('node' => $node), $tokens); + + // Reload the node which will not have $node->menu defined and re-test. + $loaded_node = node_load($node->nid); + $this->assertTokens('node', array('node' => $loaded_node), $tokens); + + // Regression test for http://drupal.org/node/1317926 to ensure the + // original node object is not changed when calling menu_node_prepare(). + $this->assertTrue(!isset($loaded_node->menu), t('The $node->menu property was not modified during token replacement.'), 'Regression'); + } +} + +class TokenTaxonomyTestCase extends TokenTestHelper { + protected $vocab; + + public static function getInfo() { + return array( + 'name' => 'Taxonomy and vocabulary token tests', + 'description' => 'Test the taxonomy tokens.', + 'group' => 'Token', + ); + } + + function setUp($modules = array()) { + $modules[] = 'taxonomy'; + parent::setUp($modules); + // Use the default 'Tags' taxonomy included with the standard install profile. + $this->vocab = taxonomy_vocabulary_machine_name_load('tags'); + } + + /** + * Test the additional taxonomy term tokens. + */ + function testTaxonomyTokens() { + $parent_term = $this->addTerm($this->vocab, array('path' => array('alias' => 'parent-term'))); + $parent_term_tokens = array( + 'url' => url("taxonomy/term/{$parent_term->tid}", array('absolute' => TRUE)), + 'url:absolute' => url("taxonomy/term/{$parent_term->tid}", array('absolute' => TRUE)), + 'url:relative' => url("taxonomy/term/{$parent_term->tid}", array('absolute' => FALSE)), + 'url:path' => 'parent-term', + 'url:unaliased:path' => "taxonomy/term/{$parent_term->tid}", + 'edit-url' => url("taxonomy/term/{$parent_term->tid}/edit", array('absolute' => TRUE)), + 'root' => NULL, + // Deprecated tokens + 'url:alias' => 'parent-term', + ); + $this->assertTokens('term', array('term' => $parent_term), $parent_term_tokens); + + $child_term = $this->addTerm($this->vocab, array('parent' => $parent_term->tid)); + $child_term_tokens = array( + 'url' => url("taxonomy/term/{$child_term->tid}", array('absolute' => TRUE)), + 'url:absolute' => url("taxonomy/term/{$child_term->tid}", array('absolute' => TRUE)), + 'url:relative' => url("taxonomy/term/{$child_term->tid}", array('absolute' => FALSE)), + 'url:path' => "taxonomy/term/{$child_term->tid}", + 'url:unaliased:path' => "taxonomy/term/{$child_term->tid}", + 'edit-url' => url("taxonomy/term/{$child_term->tid}/edit", array('absolute' => TRUE)), + 'root' => check_plain($parent_term->name), + 'root:tid' => $parent_term->tid, + // Deprecated tokens + 'url:alias' => "taxonomy/term/{$child_term->tid}", + ); + $this->assertTokens('term', array('term' => $child_term), $child_term_tokens); + } + + /** + * Test the additional vocabulary tokens. + */ + function testVocabularyTokens() { + $vocabulary = $this->vocab; + $tokens = array( + 'machine-name' => 'tags', + 'edit-url' => url("admin/structure/taxonomy/{$vocabulary->machine_name}/edit", array('absolute' => TRUE)), + ); + $this->assertTokens('vocabulary', array('vocabulary' => $vocabulary), $tokens); + } + + function addVocabulary(array $vocabulary = array()) { + $vocabulary += array( + 'name' => drupal_strtolower($this->randomName(5)), + 'nodes' => array('article' => 'article'), + ); + $vocabulary = (object) $vocabulary; + taxonomy_vocabulary_save($vocabulary); + return $vocabulary; + } + + function addTerm(stdClass $vocabulary, array $term = array()) { + $term += array( + 'name' => drupal_strtolower($this->randomName(5)), + 'vid' => $vocabulary->vid, + ); + $term = (object) $term; + taxonomy_term_save($term); + return $term; + } +} + +class TokenUserTestCase extends TokenTestHelper { + protected $account = NULL; + + public static function getInfo() { + return array( + 'name' => 'User token tests', + 'description' => 'Test the user tokens.', + 'group' => 'Token', + ); + } + + function setUp($modules = array()) { + parent::setUp($modules); + + // Enable user pictures. + variable_set('user_pictures', 1); + variable_set('user_picture_file_size', 0); + + // Set up the pictures directory. + $picture_path = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures'); + if (!file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY)) { + $this->fail('Could not create directory ' . $picture_path . '.'); + } + + $this->account = $this->drupalCreateUser(array('administer users')); + $this->drupalLogin($this->account); + } + + function testUserTokens() { + // Add a user picture to the account. + $image = current($this->drupalGetTestFiles('image')); + $edit = array('files[picture_upload]' => drupal_realpath($image->uri)); + $this->drupalPost('user/' . $this->account->uid . '/edit', $edit, t('Save')); + + // Load actual user data from database. + $this->account = user_load($this->account->uid, TRUE); + $this->assertTrue(!empty($this->account->picture->fid), 'User picture uploaded.'); + + $user_tokens = array( + 'picture' => theme('user_picture', array('account' => $this->account)), + 'picture:fid' => $this->account->picture->fid, + 'picture:size-raw' => 125, + 'ip-address' => NULL, + 'roles' => implode(', ', $this->account->roles), + 'roles:keys' => implode(', ', array_keys($this->account->roles)), + ); + $this->assertTokens('user', array('user' => $this->account), $user_tokens); + + $edit = array('user_pictures' => FALSE); + $this->drupalPost('admin/config/people/accounts', $edit, 'Save configuration'); + $this->assertText('The configuration options have been saved.'); + + // Remove the simpletest-created user role. + user_role_delete(end($this->account->roles)); + $this->account = user_load($this->account->uid, TRUE); + + $user_tokens = array( + 'picture' => NULL, + 'picture:fid' => NULL, + 'ip-address' => NULL, + 'roles' => 'authenticated user', + 'roles:keys' => (string) DRUPAL_AUTHENTICATED_RID, + ); + $this->assertTokens('user', array('user' => $this->account), $user_tokens); + + // The ip address token should work for the current user token type. + $tokens = array( + 'ip-address' => ip_address(), + ); + $this->assertTokens('current-user', array(), $tokens); + + $anonymous = drupal_anonymous_user(); + // Mess with the role array to ensure we still get consistent output. + $anonymous->roles[DRUPAL_ANONYMOUS_RID] = DRUPAL_ANONYMOUS_RID; + $tokens = array( + 'roles' => 'anonymous user', + 'roles:keys' => (string) DRUPAL_ANONYMOUS_RID, + ); + $this->assertTokens('user', array('user' => $anonymous), $tokens); + } +} + +class TokenEntityTestCase extends TokenTestHelper { + public static function getInfo() { + return array( + 'name' => 'Entity token tests', + 'description' => 'Test the entity tokens.', + 'group' => 'Token', + ); + } + + function setUp($modules = array()) { + $modules[] = 'taxonomy'; + parent::setUp($modules); + } + + function testEntityMapping() { + $this->assertIdentical(token_get_entity_mapping('token', 'node'), 'node'); + $this->assertIdentical(token_get_entity_mapping('token', 'term'), 'taxonomy_term'); + $this->assertIdentical(token_get_entity_mapping('token', 'vocabulary'), 'taxonomy_vocabulary'); + $this->assertIdentical(token_get_entity_mapping('token', 'invalid'), FALSE); + $this->assertIdentical(token_get_entity_mapping('entity', 'node'), 'node'); + $this->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_term'), 'term'); + $this->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_vocabulary'), 'vocabulary'); + $this->assertIdentical(token_get_entity_mapping('entity', 'invalid'), FALSE); + + // Test that when we send the mis-matched entity type into token_replace() + // that we still get the tokens replaced. + $vocabulary = taxonomy_vocabulary_machine_name_load('tags'); + $term = $this->addTerm($vocabulary); + $this->assertIdentical(token_replace('[vocabulary:name]', array('taxonomy_vocabulary' => $vocabulary)), $vocabulary->name); + $this->assertIdentical(token_replace('[term:name][term:vocabulary:name]', array('taxonomy_term' => $term)), $term->name . $vocabulary->name); + } + + function addTerm(stdClass $vocabulary, array $term = array()) { + $term += array( + 'name' => drupal_strtolower($this->randomName(5)), + 'vid' => $vocabulary->vid, + ); + $term = (object) $term; + taxonomy_term_save($term); + return $term; + } +} + +/** + * Test the profile tokens. + */ +class TokenProfileTestCase extends TokenTestHelper { + private $account; + + public static function getInfo() { + return array( + 'name' => 'Profile token tests', + 'description' => 'Test the profile tokens.', + 'group' => 'Token', + ); + } + + function setUp($modules = array()) { + $modules[] = 'profile'; + parent::setUp($modules); + $this->account = $this->drupalCreateUser(array('administer users')); + $this->drupalLogin($this->account); + } + + /** + * Test the profile tokens. + */ + function testProfileTokens() { + $field_types = _profile_field_types(); + foreach (array_keys($field_types) as $field_type) { + $field = array(); + switch ($field_type) { + case 'checkbox': + $field['title'] = 'This is a checkbox'; + break; + case 'selection': + $field['options'] = implode("\n", array('Red', 'Blue', 'Green')); + break; + } + $this->addProfileField($field_type, $field); + } + + // Submit the profile fields for the user. + $edit = array( + 'profile_textfield' => 'This is a text field', + 'profile_textarea' => "First paragraph.\n\nSecond paragraph.", + 'profile_checkbox' => TRUE, + 'profile_selection' => 'Red', + 'profile_list' => ' Drupal , Joomla ', + 'profile_url' => 'http://www.example.com/', + 'profile_date[month]' => 5, + 'profile_date[day]' => 20, + 'profile_date[year]' => 1984, + ); + $this->drupalPost("user/{$this->account->uid}/edit/SimpleTest", $edit, 'Save'); + $account = user_load($this->account->uid, TRUE); + + // Test the profile token values. + $tokens = array( + 'profile-textfield' => 'This is a text field', + 'profile-textarea' => "

First paragraph.

\n

Second paragraph.

\n", + 'profile-checkbox' => 'This is a checkbox', + 'profile-selection' => 'Red', + 'profile-list' => 'Drupal, Joomla', + 'profile-url' => 'http://www.example.com/', + 'profile-date' => format_date(453859200, 'medium', '', NULL), + 'profile-date:raw' => '453859200', + 'profile-date:custom:Y' => '1984', + ); + $this->assertTokens('user', array('user' => $account), $tokens); + + // 'Un-select' the checkbox and select profile fields. + $edit = array( + 'profile_checkbox' => FALSE, + 'profile_selection' => '0', + ); + $this->drupalPost("user/{$this->account->uid}/edit/SimpleTest", $edit, 'Save'); + $account = user_load($this->account->uid, TRUE); + + // The checkbox and select profile tokens should no longer return a value. + $tokens = array( + 'profile-checkbox' => NULL, + 'profile-selection' => NULL, + ); + $this->assertTokens('user', array('user' => $account), $tokens); + } + + /** + * Add a profile field. + * + * @param $type + * The profile field type. + * @param $field + * (optional) An array of the profile field properties. + * + * @return + * The saved profile field record object. + * + * @see drupal_form_submit() + */ + function addProfileField($type, array $field = array()) { + $field += array( + 'type' => $type, + 'category' => 'SimpleTest', + 'title' => $this->randomName(8), + 'name' => 'profile_' . $type, + 'explanation' => $this->randomName(50), + 'autocomplete' => 0, + 'required' => 0, + 'register' => 0, + ); + + // Submit the profile field using drupal_form_submit(). + $form_state = array(); + $form_state['values'] = $field; + $form_state['values']['op'] = 'Save field'; + $form_state['build_info']['args'] = array($type); + drupal_form_submit('profile_field_form', $form_state); + + // Verify the profile field was created successfully. + $saved_field = db_query("SELECT * FROM {profile_field} WHERE type = :type AND name = :name", array(':type' => $type, ':name' => $field['name']))->fetchObject(); + $this->assertTrue($saved_field, t('Profile field @name created.', array('@name' => $saved_field->name))); + + // Why in the hell these fields get saved with not the explict values + // for autocomplete, register and required that we tell it, I have no idea. + // So we need to manually save it again. Stupid profile module... + $saved_field->autocomplete = $field['autocomplete']; + $saved_field->required = $field['required']; + $saved_field->register = $field['register']; + drupal_write_record('profile_field', $saved_field, array('fid')); + + return $saved_field; + } +} + +/** + * Test the current page tokens. + */ +class TokenCurrentPageTestCase extends TokenTestHelper { + public static function getInfo() { + return array( + 'name' => 'Current page token tests', + 'description' => 'Test the [current-page:*] tokens.', + 'group' => 'Token', + ); + } + + function testCurrentPageTokens() { + $tokens = array( + '[current-page:title]' => t('Welcome to @site-name', array('@site-name' => variable_get('site_name', 'Drupal'))), + '[current-page:url]' => url('node', array('absolute' => TRUE)), + '[current-page:url:absolute]' => url('node', array('absolute' => TRUE)), + '[current-page:url:relative]' => url('node', array('absolute' => FALSE)), + '[current-page:url:path]' => 'node', + '[current-page:url:args:value:0]' => 'node', + '[current-page:url:args:value:1]' => NULL, + '[current-page:url:unaliased]' => url('node', array('absolute' => TRUE, 'alias' => TRUE)), + '[current-page:page-number]' => 1, + '[current-page:query:foo]' => NULL, + '[current-page:query:bar]' => NULL, + '[current-page:query:q]' => 'node', + // Deprecated tokens + '[current-page:arg:0]' => 'node', + '[current-page:arg:1]' => NULL, + ); + $this->assertPageTokens('', $tokens); + + $node = $this->drupalCreateNode(array('title' => 'Node title', 'path' => array('alias' => 'node-alias'))); + $tokens = array( + '[current-page:title]' => 'Node title', + '[current-page:url]' => url("node/{$node->nid}", array('absolute' => TRUE)), + '[current-page:url:absolute]' => url("node/{$node->nid}", array('absolute' => TRUE)), + '[current-page:url:relative]' => url("node/{$node->nid}", array('absolute' => FALSE)), + '[current-page:url:alias]' => 'node-alias', + '[current-page:url:args:value:0]' => 'node-alias', + '[current-page:url:args:value:1]' => NULL, + '[current-page:url:unaliased]' => url("node/{$node->nid}", array('absolute' => TRUE, 'alias' => TRUE)), + '[current-page:url:unaliased:args:value:0]' => 'node', + '[current-page:url:unaliased:args:value:1]' => $node->nid, + '[current-page:url:unaliased:args:value:2]' => NULL, + '[current-page:page-number]' => 1, + '[current-page:query:foo]' => 'bar', + '[current-page:query:bar]' => NULL, + '[current-page:query:q]' => 'node/1', + // Deprecated tokens + '[current-page:arg:0]' => 'node', + '[current-page:arg:1]' => 1, + '[current-page:arg:2]' => NULL, + ); + $this->assertPageTokens("node/{$node->nid}", $tokens, array(), array('url_options' => array('query' => array('foo' => 'bar')))); + } +} + +class TokenArrayTestCase extends TokenTestHelper { + public static function getInfo() { + return array( + 'name' => 'Array token tests', + 'description' => 'Test the array tokens.', + 'group' => 'Token', + ); + } + + function testArrayTokens() { + // Test a simple array. + $array = array(0 => 'a', 1 => 'b', 2 => 'c', 4 => 'd'); + $tokens = array( + 'first' => 'a', + 'last' => 'd', + 'value:0' => 'a', + 'value:2' => 'c', + 'count' => 4, + 'keys' => '0, 1, 2, 4', + 'keys:value:3' => '4', + 'keys:join' => '0124', + 'reversed' => 'd, c, b, a', + 'reversed:keys' => '4, 2, 1, 0', + 'join:/' => 'a/b/c/d', + 'join' => 'abcd', + 'join:, ' => 'a, b, c, d', + 'join: ' => 'a b c d', + ); + $this->assertTokens('array', array('array' => $array), $tokens); + + // Test a mixed simple and render array. + // 2 => c, 0 => a, 4 => d, 1 => b + $array = array( + '#property' => 'value', + 0 => 'a', + 1 => array('#markup' => 'b', '#weight' => 0.01), + 2 => array('#markup' => 'c', '#weight' => -10), + 4 => array('#markup' => 'd', '#weight' => 0), + ); + $tokens = array( + 'first' => 'c', + 'last' => 'b', + 'value:0' => 'a', + 'value:2' => 'c', + 'count' => 4, + 'keys' => '2, 0, 4, 1', + 'keys:value:3' => '1', + 'keys:join' => '2041', + 'reversed' => 'b, d, a, c', + 'reversed:keys' => '1, 4, 0, 2', + 'join:/' => 'c/a/d/b', + 'join' => 'cadb', + 'join:, ' => 'c, a, d, b', + 'join: ' => 'c a d b', + ); + $this->assertTokens('array', array('array' => $array), $tokens); + } +} + +class TokenRandomTestCase extends TokenTestHelper { + public static function getInfo() { + return array( + 'name' => 'Random token tests', + 'description' => 'Test the random tokens.', + 'group' => 'Token', + ); + } + + function testRandomTokens() { + $tokens = array( + 'number' => '[0-9]{1,}', + 'hash:md5' => '[0-9a-f]{32}', + 'hash:sha1' => '[0-9a-f]{40}', + 'hash:sha256' => '[0-9a-f]{64}', + 'hash:invalid-algo' => NULL, + ); + + $first_set = $this->assertTokens('random', array(), $tokens, array('regex' => TRUE)); + $second_set = $this->assertTokens('random', array(), $tokens, array('regex' => TRUE)); + foreach ($first_set as $token => $value) { + $this->assertNotIdentical($first_set[$token], $second_set[$token]); + } + } +} + +/** + * @todo Remove when http://drupal.org/node/1173706 is fixed. + */ +class TokenDateTestCase extends TokenTestHelper { + public static function getInfo() { + return array( + 'name' => 'Date token tests', + 'description' => 'Test the date tokens.', + 'group' => 'Token', + ); + } + + function testDateTokens() { + $tokens = array( + 'token_test' => '1984', + 'invalid_format' => NULL, + ); + + $this->assertTokens('date', array('date' => 453859200), $tokens); + } +} diff --git a/sites/all/modules/token/token.tokens.inc b/sites/all/modules/token/token.tokens.inc new file mode 100644 index 0000000..a80a4e9 --- /dev/null +++ b/sites/all/modules/token/token.tokens.inc @@ -0,0 +1,1405 @@ + t('Current date'), + 'description' => t('Tokens related to the current date and time.'), + 'type' => 'date', + ); + + // Add a 'dynamic' key to any tokens that have chained but dynamic tokens. + $info['tokens']['date']['custom']['dynamic'] = TRUE; + + // The [file:size] may not always return in kilobytes. + // @todo Remove when http://drupal.org/node/1193044 is fixed. + $info['tokens']['file']['size']['description'] = t('The size of the file.'); + + // Remove deprecated tokens from being listed. + unset($info['tokens']['node']['tnid']); + unset($info['tokens']['node']['type']); + unset($info['tokens']['node']['type-name']); + + // Support 'url' type tokens for core tokens. + if (isset($info['tokens']['comment']['url']) && module_exists('comment')) { + $info['tokens']['comment']['url']['type'] = 'url'; + } + $info['tokens']['node']['url']['type'] = 'url'; + if (isset($info['tokens']['term']['url']) && module_exists('taxonomy')) { + $info['tokens']['term']['url']['type'] = 'url'; + } + $info['tokens']['user']['url']['type'] = 'url'; + + // Add [token:url] tokens for any URI-able entities. + $entities = entity_get_info(); + foreach ($entities as $entity => $entity_info) { + if (!isset($entity_info['token type'])) { + continue; + } + + $token_type = $entity_info['token type']; + if (!isset($info['types'][$token_type]) || !isset($info['tokens'][$token_type])) { + continue; + } + + // Add [entity:url] tokens if they do not already exist. + // @todo Support entity:label + if (!isset($info['tokens'][$token_type]['url']) && !empty($entity_info['uri callback'])) { + $info['tokens'][$token_type]['url'] = array( + 'name' => t('URL'), + 'description' => t('The URL of the @entity.', array('@entity' => drupal_strtolower($entity_info['label']))), + 'module' => 'token', + 'type' => 'url', + ); + } + } + + // Add support for custom date formats. + // @todo Remove when http://drupal.org/node/1173706 is fixed. + $date_format_types = system_get_date_types(); + foreach ($date_format_types as $date_format_type => $date_format_type_info) { + if (!isset($info['tokens']['date'][$date_format_type])) { + $info['tokens']['date'][$date_format_type] = array( + 'name' => $date_format_type_info['title'], + 'description' => t("A date in '@type' format. (%date)", array('@type' => $date_format_type, '%date' => format_date(REQUEST_TIME, $date_format_type))), + 'module' => 'token', + ); + } + } +} + +/** + * Implements hook_token_info(). + */ +function token_token_info() { + // Node tokens. + $info['tokens']['node']['source'] = array( + 'name' => t('Translation source node'), + 'description' => t("The source node for this current node's translation set."), + 'type' => 'node', + ); + $info['tokens']['node']['log'] = array( + 'name' => t('Revision log message'), + 'description' => t('The explanation of the most recent changes made to the node.'), + ); + $info['tokens']['node']['content-type'] = array( + 'name' => t('Content type'), + 'description' => t('The content type of the node.'), + 'type' => 'content-type', + ); + + // Content type tokens. + $info['types']['content-type'] = array( + 'name' => t('Content types'), + 'description' => t('Tokens related to content types.'), + 'needs-data' => 'node_type', + ); + $info['tokens']['content-type']['name'] = array( + 'name' => t('Name'), + 'description' => t('The name of the content type.'), + ); + $info['tokens']['content-type']['machine-name'] = array( + 'name' => t('Machine-readable name'), + 'description' => t('The unique machine-readable name of the content type.'), + ); + $info['tokens']['content-type']['description'] = array( + 'name' => t('Description'), + 'description' => t('The optional description of the content type.'), + ); + $info['tokens']['content-type']['node-count'] = array( + 'name' => t('Node count'), + 'description' => t('The number of nodes belonging to the content type.'), + ); + $info['tokens']['content-type']['edit-url'] = array( + 'name' => t('Edit URL'), + 'description' => t("The URL of the content type's edit page."), + //'type' => 'url', + ); + + // Taxonomy term and vocabulary tokens. + if (module_exists('taxonomy')) { + $info['tokens']['term']['edit-url'] = array( + 'name' => t('Edit URL'), + 'description' => t("The URL of the taxonomy term's edit page."), + //'type' => 'url', + ); + $info['tokens']['term']['root'] = array( + 'name' => t('Root term'), + 'description' => t("The root term of the taxonomy term."), + 'type' => 'term', + ); + + $info['tokens']['vocabulary']['machine-name'] = array( + 'name' => t('Machine-readable name'), + 'description' => t('The unique machine-readable name of the vocabulary.'), + ); + $info['tokens']['vocabulary']['edit-url'] = array( + 'name' => t('Edit URL'), + 'description' => t("The URL of the vocabulary's edit page."), + //'type' => 'url', + ); + } + + // File tokens. + $info['tokens']['file']['extension'] = array( + 'name' => t('Extension'), + 'description' => t('The extension of the file.'), + ); + $info['tokens']['file']['size-raw'] = array( + 'name' => t('File byte size'), + 'description' => t('The size of the file, in bytes.'), + ); + + // User tokens. + // Add information on the restricted user tokens. + $info['tokens']['user']['cancel-url'] = array( + 'name' => t('Account cancellation URL'), + 'description' => t('The URL of the confirm delete page for the user account.'), + 'restricted' => TRUE, + //'type' => 'url', + ); + $info['tokens']['user']['one-time-login-url'] = array( + 'name' => t('One-time login URL'), + 'description' => t('The URL of the one-time login page for the user account.'), + 'restricted' => TRUE, + //'type' => 'url', + ); + if (variable_get('user_pictures', 0)) { + $info['tokens']['user']['picture'] = array( + 'name' => t('Picture'), + 'description' => t('The picture of the user.'), + 'type' => 'file', + ); + } + $info['tokens']['user']['roles'] = array( + 'name' => t('Roles'), + 'description' => t('The user roles associated with the user account.'), + 'type' => 'array', + ); + + // Current user tokens. + $info['tokens']['current-user']['ip-address'] = array( + 'name' => t('IP address'), + 'description' => 'The IP address of the current user.', + ); + + // Menu link tokens (work regardless if menu module is enabled or not). + $info['types']['menu-link'] = array( + 'name' => t('Menu links'), + 'description' => t('Tokens related to menu links.'), + 'needs-data' => 'menu-link', + ); + $info['tokens']['menu-link']['mlid'] = array( + 'name' => t('Link ID'), + 'description' => t('The unique ID of the menu link.'), + ); + $info['tokens']['menu-link']['title'] = array( + 'name' => t('Title'), + 'description' => t('The title of the menu link.'), + ); + $info['tokens']['menu-link']['url'] = array( + 'name' => t('URL'), + 'description' => t('The URL of the menu link.'), + 'type' => 'url', + ); + $info['tokens']['menu-link']['parent'] = array( + 'name' => t('Parent'), + 'description' => t("The menu link's parent."), + 'type' => 'menu-link', + ); + $info['tokens']['menu-link']['root'] = array( + 'name' => t('Root'), + 'description' => t("The menu link's root."), + 'type' => 'menu-link', + ); + + // Current page tokens. + $info['types']['current-page'] = array( + 'name' => t('Current page'), + 'description' => t('Tokens related to the current page request.'), + ); + $info['tokens']['current-page']['title'] = array( + 'name' => t('Title'), + 'description' => t('The title of the current page.'), + ); + $info['tokens']['current-page']['url'] = array( + 'name' => t('URL'), + 'description' => t('The URL of the current page.'), + 'type' => 'url', + ); + $info['tokens']['current-page']['page-number'] = array( + 'name' => t('Page number'), + 'description' => t('The page number of the current page when viewing paged lists.'), + ); + $info['tokens']['current-page']['query'] = array( + 'name' => t('Query string value'), + 'description' => t('The value of a specific query string field of the current page.'), + 'dynamic' => TRUE, + ); + + // URL tokens. + $info['types']['url'] = array( + 'name' => t('URL'), + 'description' => t('Tokens related to URLs.'), + 'needs-data' => 'path', + ); + $info['tokens']['url']['path'] = array( + 'name' => t('Path'), + 'description' => t('The path component of the URL.'), + ); + $info['tokens']['url']['relative'] = array( + 'name' => t('Relative URL'), + 'description' => t('The relative URL.'), + ); + $info['tokens']['url']['absolute'] = array( + 'name' => t('Absolute URL'), + 'description' => t('The absolute URL.'), + ); + $info['tokens']['url']['brief'] = array( + 'name' => t('Brief URL'), + 'description' => t('The URL without the protocol and trailing backslash.'), + ); + $info['tokens']['url']['unaliased'] = array( + 'name' => t('Unaliased URL'), + 'description' => t('The unaliased URL.'), + 'type' => 'url', + ); + $info['tokens']['url']['args'] = array( + 'name' => t('Arguments'), + 'description' => t("The specific argument of the current page (e.g. 'arg:1' on the page 'node/1' returns '1')."), + 'type' => 'array', + ); + + // Array tokens. + $info['types']['array'] = array( + 'name' => t('Array'), + 'description' => t('Tokens related to arrays of strings.'), + 'needs-data' => 'array', + ); + $info['tokens']['array']['first'] = array( + 'name' => t('First'), + 'description' => t('The first element of the array.'), + ); + $info['tokens']['array']['last'] = array( + 'name' => t('Last'), + 'description' => t('The last element of the array.'), + ); + $info['tokens']['array']['count'] = array( + 'name' => t('Count'), + 'description' => t('The number of elements in the array.'), + ); + $info['tokens']['array']['reversed'] = array( + 'name' => t('Reversed'), + 'description' => t('The array reversed.'), + 'type' => 'array', + ); + $info['tokens']['array']['keys'] = array( + 'name' => t('Keys'), + 'description' => t('The array of keys of the array.'), + 'type' => 'array', + ); + $info['tokens']['array']['join'] = array( + 'name' => t('Imploded'), + 'description' => t('The values of the array joined together with a custom string in-between each value.'), + 'dynamic' => TRUE, + ); + $info['tokens']['array']['value'] = array( + 'name' => t('Value'), + 'description' => t('The specific value of the array.'), + 'dynamic' => TRUE, + ); + + // Random tokens. + $info['types']['random'] = array( + 'name' => t('Random'), + 'description' => ('Tokens related to random data.'), + ); + $info['tokens']['random']['number'] = array( + 'name' => t('Number'), + 'description' => t('A random number from 0 to @max.', array('@max' => mt_getrandmax())), + ); + $info['tokens']['random']['hash'] = array( + 'name' => t('Hash'), + 'description' => t('A random hash. The possible hashing algorithms are: @hash-algos.', array('@hash-algos' => implode(', ', hash_algos()))), + 'dynamic' => TRUE, + ); + + return $info; +} + +/** + * Implements hook_tokens(). + */ +function token_tokens($type, $tokens, array $data = array(), array $options = array()) { + $replacements = array(); + + $url_options = array('absolute' => TRUE); + if (isset($options['language'])) { + $url_options['language'] = $options['language']; + $language_code = $options['language']->language; + } + else { + $language_code = NULL; + } + + $sanitize = !empty($options['sanitize']); + + // Date tokens. + if ($type == 'date') { + $date = !empty($data['date']) ? $data['date'] : REQUEST_TIME; + + // @todo Remove when http://drupal.org/node/1173706 is fixed. + $date_format_types = system_get_date_types(); + foreach ($tokens as $name => $original) { + if (isset($date_format_types[$name]) && _token_module('date', $name) == 'token') { + $replacements[$original] = format_date($date, $name, '', NULL, $language_code); + } + } + } + + // Current date tokens. + // @todo Remove when http://drupal.org/node/943028 is fixed. + if ($type == 'current-date') { + $replacements += token_generate('date', $tokens, array('date' => REQUEST_TIME), $options); + } + + // Comment tokens. + if ($type == 'comment' && !empty($data['comment'])) { + $comment = $data['comment']; + + // Chained token relationships. + if (($url_tokens = token_find_with_prefix($tokens, 'url'))) { + $replacements += token_generate('url', $url_tokens, entity_uri('comment', $comment), $options); + } + } + + // Node tokens. + if ($type == 'node' && !empty($data['node'])) { + $node = $data['node']; + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'source': + if (!empty($node->tnid) && $source_node = node_load($node->tnid)) { + $title = $source_node->title; + $replacements[$original] = $sanitize ? filter_xss($title) : $title; + } + break; + case 'log': + $replacements[$original] = $sanitize ? filter_xss($node->log) : $node->log; + break; + case 'content-type': + $type_name = node_type_get_name($node); + $replacements[$original] = $sanitize ? check_plain($type_name) : $type_name; + break; + } + } + + // Chained token relationships. + if (!empty($node->tnid) && ($source_tokens = token_find_with_prefix($tokens, 'source')) && $source_node = node_load($node->tnid)) { + $replacements += token_generate('node', $source_tokens, array('node' => $source_node), $options); + } + if (($node_type_tokens = token_find_with_prefix($tokens, 'content-type')) && $node_type = node_type_load($node->type)) { + $replacements += token_generate('content-type', $node_type_tokens, array('node_type' => $node_type), $options); + } + if (($url_tokens = token_find_with_prefix($tokens, 'url'))) { + $replacements += token_generate('url', $url_tokens, entity_uri('node', $node), $options); + } + } + + // Content type tokens. + if ($type == 'content-type' && !empty($data['node_type'])) { + $node_type = $data['node_type']; + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'name': + $replacements[$original] = $sanitize ? check_plain($node_type->name) : $node_type->name; + break; + case 'machine-name': + // This is a machine name so does not ever need to be sanitized. + $replacements[$original] = $node_type->type; + break; + case 'description': + $replacements[$original] = $sanitize ? filter_xss($node_type->description) : $node_type->description; + break; + case 'node-count': + $query = db_select('node'); + $query->condition('type', $node_type->type); + $query->addTag('node_type_node_count'); + $count = $query->countQuery()->execute()->fetchField(); + $replacements[$original] = (int) $count; + break; + case 'edit-url': + $replacements[$original] = url("admin/structure/types/manage/{$node_type->type}", $url_options); + break; + } + } + } + + // Taxonomy term tokens. + if ($type == 'term' && !empty($data['term'])) { + $term = $data['term']; + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'edit-url': + $replacements[$original] = url("taxonomy/term/{$term->tid}/edit", $url_options); + break; + + case 'root': + $parents = taxonomy_get_parents_all($term->tid); + $root_term = end($parents); + if ($root_term->tid != $term->tid) { + $replacements[$original] = $sanitize ? check_plain($root_term->name) : $root_term->name; + } + break; + } + } + + // Chained token relationships. + if (($url_tokens = token_find_with_prefix($tokens, 'url'))) { + $replacements += token_generate('url', $url_tokens, entity_uri('taxonomy_term', $term), $options); + } + if ($root_tokens = token_find_with_prefix($tokens, 'root')) { + $parents = taxonomy_get_parents_all($term->tid); + $root_term = end($parents); + if ($root_term->tid != $term->tid) { + $replacements += token_generate('term', $root_tokens, array('term' => $root_term), $options); + } + } + } + + // Vocabulary tokens. + if ($type == 'vocabulary' && !empty($data['vocabulary'])) { + $vocabulary = $data['vocabulary']; + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'machine-name': + // This is a machine name so does not ever need to be sanitized. + $replacements[$original] = $vocabulary->machine_name; + break; + case 'edit-url': + $replacements[$original] = url("admin/structure/taxonomy/{$vocabulary->machine_name}/edit", $url_options); + break; + } + } + } + + // File tokens. + if ($type == 'file' && !empty($data['file'])) { + $file = $data['file']; + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'extension': + $extension = pathinfo($file->filename, PATHINFO_EXTENSION); + $replacements[$original] = $sanitize ? check_plain($extension) : $extension; + break; + case 'size-raw': + $replacements[$original] = (int) $file->filesize; + break; + } + } + } + + // User tokens. + if ($type == 'user' && !empty($data['user'])) { + $account = $data['user']; + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'picture': + if (variable_get('user_pictures', 0)) { + $replacements[$original] = theme('user_picture', array('account' => $account)); + } + break; + case 'roles': + // The roles array may be set from checkbox values so ensure it always + // has 'proper' data with the role names. + $roles = array_intersect_key(user_roles(), $account->roles); + $replacements[$original] = token_render_array($roles, $options); + break; + } + } + + // Chained token relationships. + if (variable_get('user_pictures', 0) && !empty($account->picture) && ($picture_tokens = token_find_with_prefix($tokens, 'picture'))) { + // @todo Remove when core bug http://drupal.org/node/978028 is fixed. + $account->picture->description = ''; + $replacements += token_generate('file', $picture_tokens, array('file' => $account->picture), $options); + } + if ($url_tokens = token_find_with_prefix($tokens, 'url')) { + $replacements += token_generate('url', $url_tokens, entity_uri('user', $account), $options); + } + if ($role_tokens = token_find_with_prefix($tokens, 'roles')) { + // The roles array may be set from checkbox values so ensure it always + // has 'proper' data with the role names. + $roles = array_intersect_key(user_roles(), $account->roles); + $replacements += token_generate('array', $role_tokens, array('array' => $roles), $options); + } + } + + // Current user tokens. + if ($type == 'current-user') { + foreach ($tokens as $name => $original) { + switch ($name) { + case 'ip-address': + $ip = ip_address(); + $replacements[$original] = $sanitize ? check_plain($ip) : $ip; + break; + } + } + } + + // Menu link tokens. + if ($type == 'menu-link' && !empty($data['menu-link'])) { + $link = (array) $data['menu-link']; + + if (!isset($link['title'])) { + // Re-load the link if it was not loaded via token_menu_link_load(). + $link = token_menu_link_load($link['mlid']); + } + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'mlid': + $replacements[$original] = $link['mlid']; + break; + case 'title': + $replacements[$original] = $sanitize ? check_plain($link['title']) : $link['title']; + break; + case 'url': + $replacements[$original] = url($link['href'], $url_options); + break; + case 'parent': + if (!empty($link['plid']) && $parent = token_menu_link_load($link['plid'])) { + $replacements[$original] = $sanitize ? check_plain($parent['title']) : $parent['title']; + } + break; + case 'root'; + if (!empty($link['p1']) && $link['p1'] != $link['mlid'] && $root = token_menu_link_load($link['p1'])) { + $replacements[$original] = $sanitize ? check_plain($root['title']) : $root['title']; + } + break; + } + } + + // Chained token relationships. + if (!empty($link['plid']) && ($source_tokens = token_find_with_prefix($tokens, 'parent')) && $parent = token_menu_link_load($link['plid'])) { + $replacements += token_generate('menu-link', $source_tokens, array('menu-link' => $parent), $options); + } + if (!empty($link['p1']) && $link['p1'] != $link['mlid'] && ($root_tokens = token_find_with_prefix($tokens, 'root')) && $root = token_menu_link_load($link['p1'])) { + $replacements += token_generate('menu-link', $root_tokens, array('menu-link' => $root), $options); + } + if ($url_tokens = token_find_with_prefix($tokens, 'url')) { + $replacements += token_generate('url', $url_tokens, array('path' => $link['href']), $options); + } + } + + // Current page tokens. + if ($type == 'current-page') { + $current_path = current_path(); + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'title': + $title = drupal_get_title(); + $replacements[$original] = $sanitize ? $title : decode_entities($title); + break; + case 'url': + $replacements[$original] = url($current_path, $url_options); + break; + case 'page-number': + if ($page = filter_input(INPUT_GET, 'page')) { + // @see PagerDefault::execute() + $pager_page_array = explode(',', $page); + $page = $pager_page_array[0]; + } + $replacements[$original] = (int) $page + 1; + break; + } + } + + // @deprecated + // [current-page:arg] dynamic tokens. + if ($arg_tokens = token_find_with_prefix($tokens, 'arg')) { + foreach ($arg_tokens as $name => $original) { + if (is_numeric($name) && ($arg = arg($name)) && isset($arg)) { + $replacements[$original] = $sanitize ? check_plain($arg) : $arg; + } + } + } + + // [current-page:query] dynamic tokens. + if ($query_tokens = token_find_with_prefix($tokens, 'query')) { + foreach ($query_tokens as $name => $original) { + // @todo Should this use filter_input()? + if (isset($_GET[$name])) { + $replacements[$original] = $sanitize ? check_plain($_GET[$name]) : $_GET[$name]; + } + } + } + + // Chained token relationships. + if ($url_tokens = token_find_with_prefix($tokens, 'url')) { + $replacements += token_generate('url', $url_tokens, array('path' => $current_path), $options); + } + } + + // URL tokens. + if ($type == 'url' && !empty($data['path'])) { + $path = $data['path']; + + if (isset($data['options'])) { + // Merge in the URL options if available. + $url_options = $data['options'] + $url_options; + } + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'path': + $value = empty($url_options['alias']) ? drupal_get_path_alias($path, $language_code) : $path; + $replacements[$original] = $sanitize ? check_plain($value) : $value; + break; + case 'alias': + // @deprecated + $alias = drupal_get_path_alias($path, $language_code); + $replacements[$original] = $sanitize ? check_plain($alias) : $alias; + break; + case 'absolute': + $replacements[$original] = url($path, $url_options); + break; + case 'relative': + $replacements[$original] = url($path, array('absolute' => FALSE) + $url_options); + break; + case 'brief': + $replacements[$original] = preg_replace(array('!^https?://!', '!/$!'), '', url($path, $url_options)); + break; + case 'unaliased': + $replacements[$original] = url($path, array('alias' => TRUE) + $url_options); + break; + case 'args': + $value = empty($url_options['alias']) ? drupal_get_path_alias($path, $language_code) : $path; + $replacements[$original] = token_render_array(arg(NULL, $value), $options); + break; + } + } + + // [url:arg:*] chained tokens. + if ($arg_tokens = token_find_with_prefix($tokens, 'args')) { + $value = empty($url_options['alias']) ? drupal_get_path_alias($path, $language_code) : $path; + $replacements += token_generate('array', $arg_tokens, array('array' => arg(NULL, $value)), $options); + } + + // [url:unaliased:*] chained tokens. + if ($unaliased_tokens = token_find_with_prefix($tokens, 'unaliased')) { + $unaliased_token_data['path'] = $path; + $unaliased_token_data['options'] = isset($data['options']) ? $data['options'] : array(); + $unaliased_token_data['options']['alias'] = TRUE; + $replacements += token_generate('url', $unaliased_tokens, $unaliased_token_data, $options); + } + } + + // Entity tokens. + if (!empty($data[$type]) && $entity_type = token_get_entity_mapping('token', $type)) { + $entity = $data[$type]; + + // Sometimes taxonomy terms are not properly loaded. + // @see http://drupal.org/node/870528 + if ($entity_type == 'taxonomy_term' && !isset($entity->vocabulary_machine_name)) { + $entity->vocabulary_machine_name = db_query("SELECT machine_name FROM {taxonomy_vocabulary} WHERE vid = :vid", array(':vid' => $entity->vid))->fetchField(); + } + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'url': + if (_token_module($type, 'url') == 'token' && $uri = entity_uri($entity_type, $entity)) { + $replacements[$original] = url($uri['path'], $uri['options']); + } + break; + } + } + + // Chained token relationships. + if (($url_tokens = token_find_with_prefix($tokens, 'url')) && _token_module($type, 'url') == 'token') { + $replacements += token_generate('url', $url_tokens, entity_uri($entity_type, $entity), $options); + } + + // Pass through to an generic 'entity' token type generation. + $entity_data = array( + 'entity_type' => $entity_type, + 'entity' => $entity, + 'token_type' => $type, + ); + // @todo Investigate passing through more data like everything from entity_extract_ids(). + $replacements += token_generate('entity', $tokens, $entity_data, $options); + } + + // Array tokens. + if ($type == 'array' && !empty($data['array']) && is_array($data['array'])) { + $array = $data['array']; + + $sort = isset($options['array sort']) ? $options['array sort'] : TRUE; + $keys = element_children($array, $sort); + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'first': + $value = $array[$keys[0]]; + $value = is_array($value) ? render($value) : (string) $value; + $replacements[$original] = $sanitize ? check_plain($value) : $value; + break; + case 'last': + $value = $array[$keys[count($keys) - 1]]; + $value = is_array($value) ? render($value) : (string) $value; + $replacements[$original] = $sanitize ? check_plain($value) : $value; + break; + case 'count': + $replacements[$original] = count($keys); + break; + case 'keys': + $replacements[$original] = token_render_array($keys, $options); + break; + case 'reversed': + $reversed = array_reverse($array, TRUE); + $replacements[$original] = token_render_array($reversed, $options); + break; + case 'join': + $replacements[$original] = token_render_array($array, array('join' => '') + $options); + break; + } + } + + // [array:value:*] dynamic tokens. + if ($value_tokens = token_find_with_prefix($tokens, 'value')) { + foreach ($value_tokens as $key => $original) { + if ($key[0] !== '#' && isset($array[$key])) { + $replacements[$original] = token_render_array_value($array[$key], $options); + } + } + } + + // [array:join:*] dynamic tokens. + if ($join_tokens = token_find_with_prefix($tokens, 'join')) { + foreach ($join_tokens as $join => $original) { + $replacements[$original] = token_render_array($array, array('join' => $join) + $options); + } + } + + // [array:keys:*] chained tokens. + if ($key_tokens = token_find_with_prefix($tokens, 'keys')) { + $replacements += token_generate('array', $key_tokens, array('array' => $keys), $options); + } + + // [array:reversed:*] chained tokens. + if ($reversed_tokens = token_find_with_prefix($tokens, 'reversed')) { + $replacements += token_generate('array', $reversed_tokens, array('array' => array_reverse($array, TRUE)), array('array sort' => FALSE) + $options); + } + + // @todo Handle if the array values are not strings and could be chained. + } + + // Random tokens. + if ($type == 'random') { + foreach ($tokens as $name => $original) { + switch ($name) { + case 'number': + $replacements[$original] = mt_rand(); + break; + } + } + + // [custom:hash:*] dynamic token. + if ($hash_tokens = token_find_with_prefix($tokens, 'hash')) { + $algos = hash_algos(); + foreach ($hash_tokens as $name => $original) { + if (in_array($name, $algos)) { + $replacements[$original] = hash($name, drupal_random_bytes(55)); + } + } + } + } + + // If $type is a token type, $data[$type] is empty but $data[$entity_type] is + // not, re-run token replacements. + if (empty($data[$type]) && ($entity_type = token_get_entity_mapping('token', $type)) && $entity_type != $type && !empty($data[$entity_type]) && empty($options['recursive'])) { + $data[$type] = $data[$entity_type]; + $options['recursive'] = TRUE; + $replacements += module_invoke_all('tokens', $type, $tokens, $data, $options); + } + + // If the token type specifics a 'needs-data' value, and the value is not + // present in $data, then throw an error. + if (!empty($GLOBALS['drupal_test_info']['test_run_id'])) { + // Only check when tests are running. + $type_info = token_get_info($type); + if (!empty($type_info['needs-data']) && !isset($data[$type_info['needs-data']])) { + trigger_error(t('Attempting to perform token replacement for token type %type without required data', array('%type' => $type)), E_USER_WARNING); + } + } + + return $replacements; +} + +/** + * Implements hook_tokens_alter(). + * + * Fix existing core tokens that do not work correctly. + */ +function token_tokens_alter(array &$replacements, array $context) { + $options = $context['options']; + + if (isset($options['language'])) { + $url_options['language'] = $options['language']; + $language_code = $options['language']->language; + } + else { + $language_code = NULL; + } + $sanitize = !empty($options['sanitize']); + + // Comment token fixes. + if ($context['type'] == 'comment' && !empty($context['data']['comment'])) { + $comment = $context['data']['comment']; + + foreach ($context['tokens'] as $name => $original) { + switch ($name) { + case 'name': + case 'author': + // @todo Remove when http://drupal.org/node/920056 is fixed. + if (!empty($comment->uid)) { + $account = user_load($comment->uid); + } + else { + $account = drupal_anonymous_user(); + $account->name = $comment->name; + } + $name = format_username($account); + $replacements[$original] = $sanitize ? check_plain($name) : $name; + break; + } + } + } + + // Node token fixes. + if ($context['type'] == 'node' && !empty($context['data']['node'])) { + $node = $context['data']['node']; + + foreach ($context['tokens'] as $name => $original) { + switch ($name) { + case 'author': + // @todo Remove when http://drupal.org/node/1185842 is fixed. + $account = user_load($node->uid); + $name = format_username($account); + $replacements[$original] = $sanitize ? check_plain($name) : $name; + break; + } + } + } + + // File token fixes. + if ($context['type'] == 'file' && !empty($context['data']['file'])) { + $file = $context['data']['file']; + + foreach ($context['tokens'] as $name => $original) { + switch ($name) { + case 'owner': + // @todo Remove when http://drupal.org/node/978028 is fixed. + $account = user_load($file->uid); + $name = format_username($account); + $replacements[$original] = $sanitize ? check_plain($name) : $name; + break; + } + } + } +} + +/** + * Implements hook_token_info() on behalf of book.module. + */ +function book_token_info() { + $info['tokens']['node']['book'] = array( + 'name' => t('Book'), + 'description' => t('The book page associated with the node.'), + 'type' => 'menu-link', + ); + return $info; +} + +/** + * Implements hook_tokens() on behalf of book.module. + */ +function book_tokens($type, $tokens, array $data = array(), array $options = array()) { + $replacements = array(); + $sanitize = !empty($options['sanitize']); + + // Node tokens. + if ($type == 'node' && !empty($data['node'])) { + $node = $data['node']; + + if (!empty($node->book['mlid'])) { + $link = token_book_link_load($node->book['mlid']); + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'book': + $replacements[$original] = $sanitize ? check_plain($link['title']) : $link['title']; + break; + } + } + + // Chained token relationships. + if ($book_tokens = token_find_with_prefix($tokens, 'book')) { + $replacements += token_generate('menu-link', $book_tokens, array('menu-link' => $link), $options); + } + } + } + + return $replacements; +} + +/** + * Implements hook_token_info() on behalf of menu.module. + */ +function menu_token_info() { + // Menu tokens. + $info['types']['menu'] = array( + 'name' => t('Menus'), + 'description' => t('Tokens related to menus.'), + 'needs-data' => 'menu', + ); + $info['tokens']['menu']['name'] = array( + 'name' => t('Name'), + 'description' => t("The name of the menu."), + ); + $info['tokens']['menu']['machine-name'] = array( + 'name' => t('Machine-readable name'), + 'description' => t("The unique machine-readable name of the menu."), + ); + $info['tokens']['menu']['description'] = array( + 'name' => t('Description'), + 'description' => t('The optional description of the menu.'), + ); + $info['tokens']['menu']['menu-link-count'] = array( + 'name' => t('Menu link count'), + 'description' => t('The number of menu links belonging to the menu.'), + ); + $info['tokens']['menu']['edit-url'] = array( + 'name' => t('Edit URL'), + 'description' => t("The URL of the menu's edit page."), + ); + + $info['tokens']['menu-link']['menu'] = array( + 'name' => t('Menu'), + 'description' => t('The menu of the menu link.'), + 'type' => 'menu', + ); + $info['tokens']['menu-link']['edit-url'] = array( + 'name' => t('Edit URL'), + 'description' => t("The URL of the menu link's edit page."), + ); + $info['tokens']['node']['menu-link'] = array( + 'name' => t('Menu link'), + 'description' => t("The menu link for this node."), + 'type' => 'menu-link', + ); + + return $info; +} + +/** + * Implements hook_tokens() on behalf of menu.module. + */ +function menu_tokens($type, $tokens, array $data = array(), array $options = array()) { + $replacements = array(); + + $url_options = array('absolute' => TRUE); + if (isset($options['language'])) { + $url_options['language'] = $options['language']; + $language_code = $options['language']->language; + } + else { + $language_code = NULL; + } + + $sanitize = !empty($options['sanitize']); + + // Node tokens. + if ($type == 'node' && !empty($data['node'])) { + // We need to clone the node as menu_node_prepare() may cause data loss. + // @see http://drupal.org/node/1317926 + $node = clone $data['node']; + + if (!isset($node->menu)) { + // Nodes do not have their menu links loaded via menu_node_load(). + menu_node_prepare($node); + } + + if (!empty($node->menu['mlid'])) { + $link = token_menu_link_load($node->menu['mlid']); + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'menu-link': + $replacements[$original] = $sanitize ? check_plain($link['title']) : $link['title']; + break; + } + } + + // Chained token relationships. + if ($menu_tokens = token_find_with_prefix($tokens, 'menu-link')) { + $replacements += token_generate('menu-link', $menu_tokens, array('menu-link' => $link), $options); + } + } + } + + // Menu link tokens. + if ($type == 'menu-link' && !empty($data['menu-link'])) { + $link = (array) $data['menu-link']; + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'menu': + if ($menu = menu_load($link['menu_name'])) { + $replacements[$original] = $sanitize ? check_plain($menu['title']) : $menu['title']; + } + break; + case 'edit-url': + $replacements[$original] = url("admin/structure/menu/item/{$link['mlid']}/edit", $url_options); + break; + } + } + + // Chained token relationships. + if (($menu_tokens = token_find_with_prefix($tokens, 'menu')) && $menu = menu_load($link['menu_name'])) { + $replacements += token_generate('menu', $menu_tokens, array('menu' => $menu), $options); + } + } + + // Menu tokens. + if ($type == 'menu' && !empty($data['menu'])) { + $menu = (array) $data['menu']; + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'name': + $replacements[$original] = $sanitize ? check_plain($menu['title']) : $menu['title']; + break; + case 'machine-name': + // This is a machine name so does not ever need to be sanitized. + $replacements[$original] = $menu['menu_name']; + break; + case 'description': + $replacements[$original] = $sanitize ? filter_xss($menu['description']) : $menu['description']; + break; + case 'menu-link-count': + $query = db_select('menu_links'); + $query->condition('menu_name', $menu['menu_name']); + $query->addTag('menu_menu_link_count'); + $count = $query->countQuery()->execute()->fetchField(); + $replacements[$original] = (int) $count; + break; + case 'edit-url': + $replacements[$original] = url("admin/structure/menu/manage/" . $menu['menu_name'], $url_options); + break; + } + } + } + + return $replacements; +} + +/** + * Implements hook_token_info() on behalf of profile.module. + */ +function profile_token_info() { + $info = array(); + + foreach (_token_profile_fields() as $field) { + $info['tokens']['user'][$field->token_name] = array( + 'name' => check_plain($field->title), + 'description' => t('@category @type field.', array('@category' => drupal_ucfirst($field->category), '@type' => $field->type)), + ); + + switch ($field->type) { + case 'date': + $info['tokens']['user'][$field->token_name]['type'] = 'date'; + break; + } + } + + return $info; +} + +/** + * Implements hook_tokens() on behalf of profile.module. + */ +function profile_tokens($type, $tokens, array $data = array(), array $options = array()) { + $replacements = array(); + $sanitize = !empty($options['sanitize']); + $language_code = isset($options['language']) ? $options['language']->language : NULL; + + if ($type == 'user' && !empty($data['user'])) { + $account = $data['user']; + + // Load profile fields if this is the global user account. + // @see http://drupal.org/node/361471 + // @see http://drupal.org/node/967330 + if ($account->uid == $GLOBALS['user']->uid && isset($account->timestamp)) { + $profile_users = array($account->uid => $account); + profile_user_load($profile_users); + $account = $profile_users[$account->uid]; + } + + $profile_fields = _token_profile_fields(); + foreach ($tokens as $name => $original) { + if (isset($profile_fields[$name]) && !empty($account->{$profile_fields[$name]->name})) { + $value = $account->{$profile_fields[$name]->name}; + switch ($profile_fields[$name]->type) { + case 'textarea': + $replacements[$original] = $sanitize ? check_markup($value, filter_default_format($account), '', TRUE) : $value; + break; + case 'date': + $timestamp = gmmktime(0, 0, 0, $value['month'], $value['day'], $value['year']); + $replacements[$original] = format_date($timestamp, 'medium', '', NULL, $language_code); + break; + case 'url': + $replacements[$original] = $sanitize ? check_url($value) : $value; + break; + case 'checkbox': + // Checkbox field if checked should return the text. + $replacements[$original] = $sanitize ? check_plain($profile_fields[$name]->title) : $profile_fields[$name]->title; + break; + case 'list': + $value = preg_split("/[,\n\r]/", $value); + $value = array_map('trim', $value); + $value = implode(', ', $value); + // Intentionally fall through to the default condition. + default: + $replacements[$original] = $sanitize ? check_plain($value) : $value; + break; + } + } + } + + // Chained token relationships. + foreach ($profile_fields as $field) { + if ($field->type == 'date' && isset($account->{$field->name}) && $field_tokens = token_find_with_prefix($tokens, $field->token_name)) { + $date = $account->{$field->name}; + $replacements += token_generate('date', $field_tokens, array('date' => gmmktime(0, 0, 0, $date['month'], $date['day'], $date['year'])), $options); + } + } + } + + return $replacements; +} + +/** + * Fetch an array of profile field objects, keyed by token name. + */ +function _token_profile_fields() { + $fields = &drupal_static(__FUNCTION__); + + if (!isset($fields)) { + $fields = array(); + $results = db_query("SELECT name, title, category, type FROM {profile_field}"); + foreach ($results as $field) { + $field->token_name = token_clean_token_name($field->name); + $fields[$field->token_name] = $field; + } + } + + return $fields; +} + +/** + * Fetch an array of field data used for tokens. + */ +function _token_field_info($field_name = NULL) { + $info = &drupal_static(__FUNCTION__); + + if (!isset($fields)) { + if ($cached = cache_get('field:info', 'cache_token')) { + $info = $cached->data; + } + else { + $info = array(); + + $fields = field_info_fields(); + $instances = field_info_instances(); + $type_info = field_info_field_types(); + $entity_info = entity_get_info(); + + foreach ($fields as $field) { + $key = $field['field_name']; + if (!empty($field['bundles'])) { + foreach (array_keys($field['bundles']) as $entity) { + // Make sure a token type exists for this entity. + $token_type = token_get_entity_mapping('entity', $entity); + if (empty($token_type)) { + continue; + } + + $info[$key]['token types'][] = $token_type; + $info[$key] += array('labels' => array(), 'bundles' => array()); + + // Find which label is most commonly used. + foreach ($field['bundles'][$entity] as $bundle) { + // Field information will included fields attached to disabled + // bundles, so check that the bundle exists before provided a + // token for it. + // @see http://drupal.org/node/1252566 + if (!isset($entity_info[$entity]['bundles'][$bundle])) { + continue; + } + + $info[$key]['labels'][] = $instances[$entity][$bundle][$key]['label']; + $info[$key]['bundles'][$token_type][$bundle] = $entity_info[$entity]['bundles'][$bundle]['label']; + } + } + } + + if (isset($info[$key])) { + $labels = array_count_values($info[$key]['labels']); + arsort($labels); + $info[$key]['label'] = key($labels); + + // Generate a description for the token. + $info[$key]['description'] = t('@type field.', array('@type' => $type_info[$field['type']]['label'])); + if ($also_known_as = array_unique(array_diff($info[$key]['labels'], array($info[$key]['label'])))) { + $info[$key]['description'] .= ' ' . t('Also known as %labels.', array('%labels' => implode(', ', $also_known_as))); + } + } + } + + drupal_alter('token_field_info', $info); + cache_set('field:info', $info, 'cache_token'); + } + } + + if (isset($field_name)) { + return isset($info[$field_name]) ? $info[$field_name] : FALSE; + } + + return $info; +} + +/** + * Implements hook_token_info_alter() on behalf of field.module. + * + * We use hook_token_info_alter() rather than hook_token_info() as other + * modules may already have defined some field tokens. + */ +function field_token_info_alter(&$info) { + $fields = _token_field_info(); + + // Attach field tokens to their respecitve entity tokens. + foreach ($fields as $field_name => $field) { + foreach (array_keys($field['bundles']) as $token_type) { + // If a token already exists for this field, then don't add it. + if (isset($info['tokens'][$token_type][$field_name])) { + continue; + } + + // Ensure the tokens exist. + if (!isset($info['types'][$token_type]) || !isset($info['tokens'][$token_type])) { + continue; + } + + if ($token_type == 'comment' && $field_name == 'comment_body') { + // Core provides the comment field as [comment:body]. + continue; + } + + $info['tokens'][$token_type][$field_name] = array( + 'name' => $field['label'], + 'description' => $field['description'], + 'module' => 'token', + ); + } + } +} + +/** + * Implements hook_tokens() on behalf of field.module. + */ +function field_tokens($type, $tokens, array $data = array(), array $options = array()) { + $replacements = array(); + $sanitize = !empty($options['sanitize']); + $langcode = isset($options['language']) ? $options['language']->language : NULL; + + // Entity tokens. + if ($type == 'entity' && !empty($data['entity_type']) && !empty($data['entity']) && !empty($data['token_type'])) { + $entity_type = $data['entity_type']; + // The field API does weird stuff to the entity, so let's clone it. + $entity = clone $data['entity']; + + list(, , $bundle) = entity_extract_ids($entity_type, $entity); + $fields = field_info_instances($entity_type, $bundle); + + foreach (array_keys($fields) as $field_name) { + // Do not continue if the field is empty. + if (empty($entity->{$field_name})) { + continue; + } + + // Replace the [entity:field-name] token. + if (isset($tokens[$field_name])) { + $original = $tokens[$field_name]; + + // Assert that this field was added by token.module. + $token_info = token_get_info($data['token_type'], $field_name); + if (!isset($token_info['module']) || $token_info['module'] != 'token') { + continue; + } + + $field_output = field_view_field($entity_type, $entity, $field_name, 'token', $langcode); + $field_output['#token_options'] = $options; + $field_output['#pre_render'][] = 'token_pre_render_field_token'; + $replacements[$original] = drupal_render($field_output); + } + } + + // Remove the cloned object from memory. + unset($entity); + } + + return $replacements; +} + +/** + * Pre-render callback for field output used with tokens. + */ +function token_pre_render_field_token(&$elements) { + // Remove the field theme hook, attachments, and JavaScript states. + unset($elements['#theme']); + unset($elements['#states']); + unset($elements['#attached']); + + // Prevent multi-value fields from appearing smooshed together by appending + // a join suffix to all but the last value. + $deltas = element_get_visible_children($elements); + $count = count($deltas); + if ($count > 1) { + $join = isset($elements['#token_options']['join']) ? $elements['#token_options']['join'] : ", "; + foreach ($deltas as $index => $delta) { + // Do not add a suffix to the last item. + if ($index < ($count - 1)) { + $elements[$delta] += array('#suffix' => $join); + } + } + } + return $elements; +}