first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
# Features
* [wpmlcf7-1] Added compatibility for Contact Form 7

View File

@@ -0,0 +1,6 @@
# Features
* [wpmlcf7-23] Fixes the duplicate button in the language metabox.
* [wpmlcf7-10] Add support for manual translation.
# Fixes
* [wpmlcf7-20] Fixes the behaviour of the admin top bar language switcher while editing a contact form.

View File

@@ -0,0 +1,12 @@
<?php
namespace WPML\CF7;
class Constants {
/**
* The CPT slug for contact forms.
*/
const POST_TYPE = 'wpcf7_contact_form';
}

View File

@@ -0,0 +1,212 @@
<?php
namespace WPML\CF7;
class Language_Metabox implements \IWPML_Backend_Action, \IWPML_DIC_Action {
/**
* Instance of Sitepress.
*
* @var \SitePress
*/
private $sitepress;
/**
* Instance of $wpml_post_translations.
*
* @var \WPML_post_translation
*/
private $wpml_post_translations;
/**
* Language_Metabox constructor.
*
* @param \SitePress $sitepress An instance of SitePress class.
* @param \WPML_post_translation $wpml_post_translations An instance of WPML_post_translation class.
*/
public function __construct( \SitePress $sitepress, \WPML_post_translation $wpml_post_translations ) {
$this->sitepress = $sitepress;
$this->wpml_post_translations = $wpml_post_translations;
}
/**
* Adds the actions and filters.
*/
public function add_hooks() {
add_action( 'admin_init', [ $this, 'maybe_setup_post_edit' ] );
add_action( 'wpcf7_admin_misc_pub_section', [ $this, 'add_language_meta_box' ] );
add_filter( 'wpml_link_to_translation', [ $this, 'link_to_translation' ], 10, 4 );
add_filter( 'wpml_admin_language_switcher_items', [ $this, 'admin_language_switcher_items' ] );
}
/**
* Call the required code for the language meta box functionality.
*
* @TODO Remove duplicated code
*/
public function maybe_setup_post_edit() {
global $post_edit_screen;
$is_wpcf7_page = $this->is_wpcf7_page();
$post = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
if ( $is_wpcf7_page && $post ) {
// Duplicated code from wpml_maybe_setup_post_edit().
$post_edit_screen = new \WPML_Post_Edit_Screen( $this->sitepress );
add_action( 'admin_head', array( $this->sitepress, 'post_edit_language_options' ) );
// Duplicated code from SitePress::js_load().
wp_register_script( 'sitepress-post-edit-tags', ICL_PLUGIN_URL . '/res/js/post-edit-terms.js', array( 'jquery' ) );
$post_edit_messages = array(
'switch_language_title' => __( 'You are about to change the language of {post_name}.', 'sitepress' ),
'switch_language_alert' => __( 'All categories and tags will be translated if possible.', 'sitepress' ),
'connection_loss_alert' => __( 'The following terms do not have a translation in the chosen language and will be disconnected from this post:', 'sitepress' ),
'loading' => __( 'Loading Language Data for {post_name}', 'sitepress' ),
'switch_language_message' => __( 'Please make sure that you\'ve saved all the changes. We will have to reload the page.', 'sitepress' ),
'switch_language_confirm' => __( 'Do you want to continue?', 'sitepress' ),
'_nonce' => wp_create_nonce( 'wpml_switch_post_lang_nonce' ),
'empty_post_title' => __( '(No title for this post yet)', 'sitepress' ),
'ok_button_label' => __( 'OK', 'sitepress' ),
'cancel_button_label' => __( 'Cancel', 'sitepress' ),
);
wp_localize_script( 'sitepress-post-edit-tags', 'icl_post_edit_messages', $post_edit_messages );
wp_enqueue_script( 'sitepress-post-edit-tags' );
// Duplicated code from WPML_Meta_Boxes_Post_Edit_Ajax::enqueue_scripts().
wp_enqueue_script( 'wpml-meta-box', ICL_PLUGIN_URL . '/dist/js/wpml-meta-box/wpml-meta-box.js' );
// Only if TM is active.
if ( class_exists( 'WPML_TM_Post_Edit_TM_Editor_Select' ) ) {
$tm_selector = new \WPML_TM_Post_Edit_TM_Editor_Select( $this->sitepress );
$tm_selector->add_hooks();
}
}
}
/**
* Add the WPML meta box when editing forms.
*
* @param int|\WP_Post $post The post ID or an instance of WP_Post.
*/
public function add_language_meta_box( $post ) {
$post = get_post( $post );
$trid = filter_input( INPUT_GET, 'trid', FILTER_SANITIZE_NUMBER_INT );
if ( $post ) {
add_filter( 'wpml_post_edit_can_translate', '__return_true' );
?>
</div>
</div>
</div>
</div>
<div class="postbox">
<h3><?php echo esc_html( __( 'Language', 'sitepress' ) ); ?></h3>
<div>
<div>
<div id="icl_div">
<div class="inside"><?php $this->sitepress->meta_box( $post ); ?></div>
<?php
} elseif ( $trid ) {
// Used by WPML for connecting new manual translations to their originals.
echo '<input type="hidden" name="icl_trid" value="' . esc_attr( $trid ) . '" />';
}
}
/**
* Filters links to translations in language metabox.
*
* @param string $link
* @param int $post_id
* @param string $lang
* @param int $trid
* @return string
*/
public function link_to_translation( $link, $post_id, $lang, $trid ) {
if ( Constants::POST_TYPE === get_post_type( $post_id ) ) {
$link = $this->get_link_to_translation( $post_id, $lang );
}
return $link;
}
/**
* Filters the top bar admin language switcher links.
*
* @param array $links
* @return array $links
*/
public function admin_language_switcher_items( $links ) {
$is_wpcf7_page = $this->is_wpcf7_page();
$post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
$trid = filter_input( INPUT_GET, 'trid', FILTER_SANITIZE_NUMBER_INT );
if ( $is_wpcf7_page && ( $trid || $post_id ) ) {
// If we are adding a post, get the post_id from the trid and source_lang.
if ( ! $post_id ) {
$source_lang = filter_input( INPUT_GET, 'source_lang', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
$post_id = $this->wpml_post_translations->get_element_id( $source_lang, $trid );
unset( $links['all'] );
// We shouldn't get here, but just in case.
if ( ! $post_id ) {
return $links;
}
}
foreach ( $links as $lang => & $link ) {
if ( 'all' !== $lang && ! $link['current'] ) {
$link['url'] = $this->get_link_to_translation( $post_id, $lang );
}
}
}
return $links;
}
/**
* Check if we are in CF7 admin page.
*
* @return int
*/
private function is_wpcf7_page() {
global $pagenow, $plugin_page;
$is_admin_page = $pagenow && ( 'admin.php' === $pagenow );
$is_wpcf7_page = $plugin_page && in_array( $plugin_page, [ 'wpcf7', 'wpcf7-new' ], true );
return $is_admin_page && $is_wpcf7_page;
}
/**
* Works out the correct link to a translation
*
* @param int $post_id The post_id being edited.
* @param string $lang The target language.
* @return string
*/
private function get_link_to_translation( $post_id, $lang ) {
$translated_post_id = $this->wpml_post_translations->element_id_in( $post_id, $lang );
if ( $translated_post_id ) {
// Rewrite link to edit contact form translation.
$args = [
'page' => 'wpcf7',
'lang' => $lang,
'post' => $translated_post_id,
'action' => 'edit',
];
} else {
// Rewrite link to create contact form translation.
$trid = $this->wpml_post_translations->get_element_trid( $post_id, Constants::POST_TYPE );
$source_language_code = $this->wpml_post_translations->get_element_lang_code( $post_id );
$args = [
'page' => 'wpcf7-new',
'lang' => $lang,
'trid' => $trid,
'source_lang' => $source_language_code,
];
}
return add_query_arg( $args, admin_url( 'admin.php' ) );
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace WPML\CF7;
class Shortcodes implements \IWPML_Frontend_Action {
public function add_hooks() {
add_filter( 'shortcode_atts_wpcf7', [ $this, 'translate_shortcode_form_id' ] );
}
/**
* Translate the `id` in the shortcode attributes on-the-fly.
*
* @param array $out Shortcode attributes to be filtered.
*
* @return array
*/
public function translate_shortcode_form_id( $out ) {
$out['id'] = apply_filters( 'wpml_object_id', $out['id'], Constants::POST_TYPE, true );
return $out;
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace WPML\CF7;
class Translations implements \IWPML_Backend_Action {
/**
* Adds the required hooks.
*/
public function add_hooks() {
add_filter( 'icl_job_elements', array( $this, 'remove_body_from_translation_job' ), 10, 2 );
add_filter( 'wpml_document_view_item_link', array( $this, 'document_view_item_link' ), 10, 5 );
add_filter( 'wpml_document_edit_item_link', array( $this, 'document_edit_item_link' ), 10, 5 );
add_action( 'save_post', array( $this, 'fix_setting_language_information' ) );
}
/**
* Don't translate the post_content of contact forms.
*
* @param array $elements Translation job elements.
* @param int $post_id The post ID.
*
* @return array
*/
public function remove_body_from_translation_job( $elements, $post_id ) {
// Bail out early if its not a CF7 form.
if ( Constants::POST_TYPE !== get_post_type( $post_id ) ) {
return $elements;
}
// Search for the body element and empty it so that it's not displayed in the TE.
$field_types = wp_list_pluck( $elements, 'field_type' );
$index = array_search( 'body', $field_types, true );
if ( false !== $index ) {
$elements[ $index ]->field_data = '';
$elements[ $index ]->field_data_translated = '';
}
return $elements;
}
/**
* Remove the 'View' link from translation jobs because Contact
* Forms don't have a link to 'View' them.
*
* @param string $link The complete link.
* @param string $text The text to link.
* @param object $job The corresponding translation job.
* @param string $prefix The prefix of the element type.
* @param string $type The element type.
*
* @return string
*/
public function document_view_item_link( $link, $text, $job, $prefix, $type ) {
if ( Constants::POST_TYPE === $type ) {
$link = '';
}
return $link;
}
/**
* Adjust the 'Edit' link from translation jobs because Contact
* Forms have a different URL for editing.
*
* @param string $link The complete link.
* @param string $text The text to link.
* @param object $current_document The document to translate.
* @param string $prefix The prefix of the element type.
* @param string $type The element type.
*
* @return string
*/
public function document_edit_item_link( $link, $text, $current_document, $prefix, $type ) {
if ( Constants::POST_TYPE === $type ) {
$url = sprintf( 'admin.php?page=wpcf7&post=%d&action=edit', $current_document->ID );
$link = sprintf( '<a href="%s">%s</a>', admin_url( $url ), $text );
}
return $link;
}
/**
* CF7 sets post_ID to -1 for new forms.
* WPML thinks we are saving a different post and doesn't save language information.
* Removing it fixes the misunderstanding.
*/
public function fix_setting_language_information() {
if ( empty( $_POST['_wpnonce'] ) || empty( $_POST['post_ID'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'wpcf7-save-contact-form_' . $_POST['post_ID'] ) ) {
return;
}
if ( -1 === (int) $_POST['post_ID'] ) {
unset( $_POST['post_ID'] );
}
}
}

View File

@@ -0,0 +1,281 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110, 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

View File

@@ -0,0 +1,35 @@
<?php
/**
* Plugin Name: Contact Form 7 Multilingual
* Plugin URI:
* Description: Make forms from Contact Form 7 translatable with WPML | <a href="https://wpml.org/documentation/plugins-compatibility/using-contact-form-7-with-wpml/">Documentation</a>
* Author: OnTheGoSystems
* Author URI: http://www.onthegosystems.com/
* Version: 1.0.2
* Plugin Slug: contact-form-7-multilingual
*
* @package wpml/cf7
*/
if ( defined( 'CF7ML_VERSION' ) ) {
return;
}
define( 'CF7ML_VERSION', '1.0.2' );
define( 'CF7ML_PLUGIN_PATH', dirname( __FILE__ ) );
require_once CF7ML_PLUGIN_PATH . '/vendor/autoload.php';
/**
* Entry point.
*/
function cf7ml_init() {
$action_loader = new \WPML_Action_Filter_Loader();
$action_loader->load( [
WPML\CF7\Translations::class,
WPML\CF7\Language_Metabox::class,
WPML\CF7\Shortcodes::class,
] );
}
add_action( 'wpml_loaded', 'cf7ml_init' );

View File

@@ -0,0 +1,7 @@
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitfc3a1e232919a7798f1f05108c48e219::getLoader();

View File

@@ -0,0 +1,445 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @see http://www.php-fig.org/psr/psr-0/
* @see http://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
private $fallbackDirsPsr4 = array();
// PSR-0
private $prefixesPsr0 = array();
private $fallbackDirsPsr0 = array();
private $useIncludePath = false;
private $classMap = array();
private $classMapAuthoritative = false;
private $missingClasses = array();
private $apcuPrefix;
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array $classMap Class to filename map
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 base directories
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}

View File

@@ -0,0 +1,21 @@
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,13 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'WPML\\CF7\\Constants' => $baseDir . '/classes/constants.php',
'WPML\\CF7\\Language_Metabox' => $baseDir . '/classes/language-metabox.php',
'WPML\\CF7\\Shortcodes' => $baseDir . '/classes/shortcodes.php',
'WPML\\CF7\\Translations' => $baseDir . '/classes/translations.php',
);

View File

@@ -0,0 +1,9 @@
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View File

@@ -0,0 +1,9 @@
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View File

@@ -0,0 +1,52 @@
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitfc3a1e232919a7798f1f05108c48e219
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitfc3a1e232919a7798f1f05108c48e219', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitfc3a1e232919a7798f1f05108c48e219', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitfc3a1e232919a7798f1f05108c48e219::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
}
$loader->register(true);
return $loader;
}
}

View File

@@ -0,0 +1,23 @@
<?php
// autoload_static.php @generated by Composer
namespace Composer\Autoload;
class ComposerStaticInitfc3a1e232919a7798f1f05108c48e219
{
public static $classMap = array (
'WPML\\CF7\\Constants' => __DIR__ . '/../..' . '/classes/constants.php',
'WPML\\CF7\\Language_Metabox' => __DIR__ . '/../..' . '/classes/language-metabox.php',
'WPML\\CF7\\Shortcodes' => __DIR__ . '/../..' . '/classes/shortcodes.php',
'WPML\\CF7\\Translations' => __DIR__ . '/../..' . '/classes/translations.php',
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->classMap = ComposerStaticInitfc3a1e232919a7798f1f05108c48e219::$classMap;
}, null, ClassLoader::class);
}
}

View File

@@ -0,0 +1,23 @@
<wpml-config>
<custom-types>
<custom-type translate="1">wpcf7_contact_form</custom-type>
</custom-types>
<custom-fields>
<custom-field action="translate">_form</custom-field>
<custom-field action="translate">_mail</custom-field>
<custom-field action="translate">_mail_2</custom-field>
<custom-field action="translate">_messages</custom-field>
<custom-field action="copy">_additional_settings</custom-field>
<custom-field action="translate">_locale</custom-field>
</custom-fields>
<custom-fields-texts>
<key name="_mail">
<key name="subject" />
<key name="body" />
</key>
<key name="_mail_2">
<key name="subject" />
<key name="body" />
</key>
</custom-fields-texts>
</wpml-config>