Version Description
- Use a different validation rule for file fields that also allows domains without TLD.
- Fix a CRED issue with added validation rules.
- Handle several issues related to using "0" as a default field value and saving it to the database.
- Fix an edge-case bug when loading field groups on the Edit Post page.
Download this release
Release Info
Developer | zaantar |
Plugin | Toolset Types – Custom Post Types, Custom Fields and Taxonomies |
Version | 2.2.5 |
Comparing to | |
See all releases |
Code changes from version 2.2.4 to 2.2.5
- application/models/field/group/factory.php +1 -1
- application/models/wpml/field/group/string.php +192 -192
- application/models/wpml/field/group/string/description.php +14 -14
- application/models/wpml/field/group/string/name.php +15 -15
- application/models/wpml/field_group.php +89 -89
- application/models/wpml/interface.php +5 -5
- disabled_autoload_classmap.php +0 -151
- examples/author.php +87 -87
- examples/content-book.php +101 -101
- examples/content-consultant.php +82 -82
- examples/content-house.php +130 -130
- examples/content-writer.php +88 -88
- examples/single-consultant.php +129 -129
- library/otgs/installer/changelog.txt +150 -150
- library/otgs/installer/includes/class-installer-dependencies.php +278 -278
- library/otgs/installer/includes/class-installer-theme.php +978 -978
- library/otgs/installer/includes/installer-api.php +115 -115
- library/otgs/installer/includes/installer-upgrader-skins.php +36 -36
- library/otgs/installer/includes/installer.class.php +2672 -2672
- library/otgs/installer/includes/translation-service-info.class.php +39 -39
- library/otgs/installer/installer.php +21 -21
- library/otgs/installer/loader.php +150 -150
- library/otgs/installer/locale/orig/installer.po +230 -230
- library/otgs/installer/repositories.xml +13 -13
- library/otgs/installer/res/css/admin.css +200 -200
- library/otgs/installer/res/js/admin.js +416 -416
- library/otgs/installer/res/js/iframeResizer.min.js +10 -10
- library/otgs/installer/res/js/installer_theme_install.js +96 -96
- library/otgs/installer/templates/downloads-list-compact.php +80 -80
- library/otgs/installer/templates/downloads-list.php +85 -85
- library/otgs/installer/templates/products-compact.php +147 -147
- library/otgs/installer/templates/repository-listing.php +196 -196
- library/toolset/onthego-resources/loader.php +2 -1
- library/toolset/onthego-resources/onthego-styles/onthego-buttons.css +2 -1
- library/toolset/onthego-resources/onthego-styles/onthego-colors.css +31 -3
- library/toolset/toolset-common/bootstrap.php +221 -78
- library/toolset/toolset-common/changelog.md +127 -115
- library/toolset/toolset-common/changelog.txt +0 -122
- library/toolset/toolset-common/loader.php +3 -3
- library/toolset/toolset-common/toolset-common-loader.php +2 -2
- library/toolset/toolset-common/toolset-forms/classes/class.eforms.php +9 -2
- library/toolset/toolset-common/toolset-forms/classes/class.field_factory.php +32 -11
- library/toolset/toolset-common/toolset-forms/classes/class.taxonomy.php +9 -1
- library/toolset/toolset-common/toolset-forms/classes/class.types.php +6 -2
- library/toolset/toolset-common/toolset-forms/js/validation.js +2 -2
- library/toolset/toolset-common/toolset-forms/lib/CakePHP-Validation.php +44 -21
- library/toolset/toolset-common/utility/autoloader.php +119 -0
- library/toolset/toolset-common/utility/utils.php +14 -0
- library/toolset/toolset-common/visual-editor/res/js/codemirror/.gitattributes +0 -8
- library/toolset/toolset-common/visual-editor/res/js/codemirror/.npmignore +0 -9
- library/toolset/toolset-common/visual-editor/res/js/codemirror/.travis.yml +0 -4
- library/toolset/types/.travis.yml +0 -29
- library/toolset/types/bin/install-wp-tests.sh +0 -118
- library/toolset/types/disabled_autoload_classmap.php +0 -101
- library/toolset/types/embedded/frontend.php +136 -140
- library/toolset/types/embedded/functions.php +37 -26
- library/toolset/types/embedded/includes/fields-post.php +211 -427
- library/toolset/types/embedded/includes/fields.php +63 -42
- library/toolset/types/embedded/includes/post-relationship.php +5 -2
- library/toolset/types/includes/classes/class.types.admin.edit.fields.php +34 -26
- library/toolset/types/phpunit.xml.dist +0 -14
- library/twig/twig/.editorconfig +0 -18
- library/twig/twig/.travis.yml +0 -44
- library/twig/twig/doc/advanced.rst +0 -957
- library/twig/twig/doc/advanced_legacy.rst +0 -885
- library/twig/twig/doc/api.rst +0 -590
- library/twig/twig/doc/coding_standards.rst +0 -101
- library/twig/twig/doc/deprecated.rst +0 -210
- library/twig/twig/doc/filters/abs.rst +0 -18
- library/twig/twig/doc/filters/batch.rst +0 -51
- library/twig/twig/doc/filters/capitalize.rst +0 -11
- library/twig/twig/doc/filters/convert_encoding.rst +0 -28
- library/twig/twig/doc/filters/date.rst +0 -100
- library/twig/twig/doc/filters/date_modify.rst +0 -23
- library/twig/twig/doc/filters/default.rst +0 -33
- library/twig/twig/doc/filters/escape.rst +0 -119
- library/twig/twig/doc/filters/first.rst +0 -25
- library/twig/twig/doc/filters/format.rst +0 -16
- library/twig/twig/doc/filters/index.rst +0 -37
- library/twig/twig/doc/filters/join.rst +0 -23
- library/twig/twig/doc/filters/json_encode.rst +0 -21
- library/twig/twig/doc/filters/keys.rst +0 -11
- library/twig/twig/doc/filters/last.rst +0 -25
- library/twig/twig/doc/filters/length.rst +0 -11
- library/twig/twig/doc/filters/lower.rst +0 -10
- library/twig/twig/doc/filters/merge.rst +0 -48
- library/twig/twig/doc/filters/nl2br.rst +0 -22
- library/twig/twig/doc/filters/number_format.rst +0 -48
- library/twig/twig/doc/filters/raw.rst +0 -36
- library/twig/twig/doc/filters/replace.rst +0 -19
- library/twig/twig/doc/filters/reverse.rst +0 -47
- library/twig/twig/doc/filters/round.rst +0 -37
- library/twig/twig/doc/filters/slice.rst +0 -71
- library/twig/twig/doc/filters/sort.rst +0 -18
- library/twig/twig/doc/filters/split.rst +0 -53
- library/twig/twig/doc/filters/striptags.rst +0 -15
- library/twig/twig/doc/filters/title.rst +0 -11
- library/twig/twig/doc/filters/trim.rst +0 -29
- library/twig/twig/doc/filters/upper.rst +0 -10
- library/twig/twig/doc/filters/url_encode.rst +0 -34
- library/twig/twig/doc/functions/attribute.rst +0 -26
- library/twig/twig/doc/functions/block.rst +0 -41
- library/twig/twig/doc/functions/constant.rst +0 -29
- library/twig/twig/doc/functions/cycle.rst +0 -28
- library/twig/twig/doc/functions/date.rst +0 -55
- library/twig/twig/doc/functions/dump.rst +0 -69
- library/twig/twig/doc/functions/include.rst +0 -84
- library/twig/twig/doc/functions/index.rst +0 -20
- library/twig/twig/doc/functions/max.rst +0 -20
- library/twig/twig/doc/functions/min.rst +0 -20
- library/twig/twig/doc/functions/parent.rst +0 -20
- library/twig/twig/doc/functions/random.rst +0 -29
- library/twig/twig/doc/functions/range.rst +0 -45
- library/twig/twig/doc/functions/source.rst +0 -32
- library/twig/twig/doc/functions/template_from_string.rst +0 -32
- library/twig/twig/doc/index.rst +0 -19
- library/twig/twig/doc/installation.rst +0 -116
- library/twig/twig/doc/internals.rst +0 -142
- library/twig/twig/doc/intro.rst +0 -85
- library/twig/twig/doc/recipes.rst +0 -568
- library/twig/twig/doc/tags/autoescape.rst +0 -81
- library/twig/twig/doc/tags/block.rst +0 -11
- library/twig/twig/doc/tags/do.rst +0 -12
- library/twig/twig/doc/tags/embed.rst +0 -178
- library/twig/twig/doc/tags/extends.rst +0 -272
- library/twig/twig/doc/tags/filter.rst +0 -21
- library/twig/twig/doc/tags/flush.rst +0 -17
- library/twig/twig/doc/tags/for.rst +0 -172
- library/twig/twig/doc/tags/from.rst +0 -8
- library/twig/twig/doc/tags/if.rst +0 -76
- library/twig/twig/doc/tags/import.rst +0 -57
- library/twig/twig/doc/tags/include.rst +0 -90
- library/twig/twig/doc/tags/index.rst +0 -25
- library/twig/twig/doc/tags/macro.rst +0 -103
- library/twig/twig/doc/tags/sandbox.rst +0 -30
- library/twig/twig/doc/tags/set.rst +0 -78
- library/twig/twig/doc/tags/spaceless.rst +0 -37
- library/twig/twig/doc/tags/use.rst +0 -124
- library/twig/twig/doc/tags/verbatim.rst +0 -24
- library/twig/twig/doc/tags/with.rst +0 -44
- library/twig/twig/doc/templates.rst +0 -908
- library/twig/twig/doc/tests/constant.rst +0 -22
- library/twig/twig/doc/tests/defined.rst +0 -30
- library/twig/twig/doc/tests/divisibleby.rst +0 -14
- library/twig/twig/doc/tests/empty.rst +0 -11
- library/twig/twig/doc/tests/even.rst +0 -10
- library/twig/twig/doc/tests/index.rst +0 -15
- library/twig/twig/doc/tests/iterable.rst +0 -19
- library/twig/twig/doc/tests/null.rst +0 -12
- library/twig/twig/doc/tests/odd.rst +0 -10
- library/twig/twig/doc/tests/sameas.rst +0 -14
- library/twig/twig/ext/twig/config.m4 +0 -8
- library/twig/twig/ext/twig/config.w32 +0 -8
- library/twig/twig/ext/twig/php_twig.h +0 -35
- library/twig/twig/ext/twig/twig.c +0 -1127
- library/twig/twig/phpunit.xml.dist +0 -33
- library/twig/twig/test/Twig/Tests/AutoloaderTest.php +0 -24
- library/twig/twig/test/Twig/Tests/Cache/FilesystemTest.php +0 -193
- library/twig/twig/test/Twig/Tests/CompilerTest.php +0 -33
- library/twig/twig/test/Twig/Tests/EnvironmentTest.php +0 -652
- library/twig/twig/test/Twig/Tests/ErrorTest.php +0 -144
- library/twig/twig/test/Twig/Tests/ExpressionParserTest.php +0 -373
- library/twig/twig/test/Twig/Tests/Extension/CoreTest.php +0 -112
application/models/field/group/factory.php
CHANGED
@@ -83,7 +83,7 @@ abstract class Types_Field_Group_Factory {
|
|
83 |
$fg_post = null;
|
84 |
|
85 |
// http://stackoverflow.com/questions/2559923/shortest-way-to-check-if-a-variable-contains-positive-integer-using-php
|
86 |
-
if (
|
87 |
$fg_post = WP_Post::get_instance( $field_group );
|
88 |
} else if ( is_string( $field_group ) ) {
|
89 |
$query = new WP_Query( array( 'post_type' => $this->get_post_type(), 'name' => $field_group, 'posts_per_page' => 1 ) );
|
83 |
$fg_post = null;
|
84 |
|
85 |
// http://stackoverflow.com/questions/2559923/shortest-way-to-check-if-a-variable-contains-positive-integer-using-php
|
86 |
+
if ( is_numeric( $field_group ) && ( $field_group == (int) $field_group ) && ( (int) $field_group > 0 ) ) {
|
87 |
$fg_post = WP_Post::get_instance( $field_group );
|
88 |
} else if ( is_string( $field_group ) ) {
|
89 |
$query = new WP_Query( array( 'post_type' => $this->get_post_type(), 'name' => $field_group, 'posts_per_page' => 1 ) );
|
application/models/wpml/field/group/string.php
CHANGED
@@ -1,193 +1,193 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
abstract class Types_Wpml_Field_Group_String implements Types_Wpml_Interface {
|
4 |
-
|
5 |
-
const CONTEXT = 'plugin Types';
|
6 |
-
const TRANSLATE_FILTER = 'wpml_translate_single_string';
|
7 |
-
|
8 |
-
/**
|
9 |
-
* @var Types_Field_Group
|
10 |
-
*/
|
11 |
-
protected $group;
|
12 |
-
|
13 |
-
/**
|
14 |
-
* String to translate
|
15 |
-
* @var string
|
16 |
-
*/
|
17 |
-
protected $string_to_translate;
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Types_Wpml_Field_Group_String constructor.
|
21 |
-
*
|
22 |
-
* @param Types_Field_Group $group
|
23 |
-
*/
|
24 |
-
public function __construct( Types_Field_Group $group ) {
|
25 |
-
$this->group = $group;
|
26 |
-
}
|
27 |
-
|
28 |
-
/**
|
29 |
-
* The pattern of the string name in icl_strings
|
30 |
-
* - [name]: group %s name
|
31 |
-
* - [description]: group %s description
|
32 |
-
*
|
33 |
-
* @return string
|
34 |
-
*/
|
35 |
-
abstract protected function get_db_pattern();
|
36 |
-
|
37 |
-
|
38 |
-
/**
|
39 |
-
* Returns the string which should be translated
|
40 |
-
*
|
41 |
-
* @return string
|
42 |
-
*/
|
43 |
-
protected function get_string_to_translate() {
|
44 |
-
return $this->string_to_translate;
|
45 |
-
}
|
46 |
-
|
47 |
-
|
48 |
-
/**
|
49 |
-
* Get the db identifier (uses slug of group)
|
50 |
-
*
|
51 |
-
* @return string
|
52 |
-
*/
|
53 |
-
protected function get_db_identifier() {
|
54 |
-
return sprintf( $this->get_db_pattern(), $this->group->get_slug() );
|
55 |
-
}
|
56 |
-
|
57 |
-
/**
|
58 |
-
* Get the db identifier (uses id of group)
|
59 |
-
*
|
60 |
-
* @return string
|
61 |
-
*/
|
62 |
-
protected function get_db_identifier_legacy() {
|
63 |
-
return sprintf( $this->get_db_pattern(), $this->group->get_id() );
|
64 |
-
}
|
65 |
-
|
66 |
-
|
67 |
-
/**
|
68 |
-
* Translate name of the group
|
69 |
-
*
|
70 |
-
* @return string
|
71 |
-
*/
|
72 |
-
public function translate() {
|
73 |
-
if ( empty( $this->string_to_translate ) || ! is_string( $this->string_to_translate ) ) {
|
74 |
-
return $this->string_to_translate;
|
75 |
-
}
|
76 |
-
|
77 |
-
// trying the new pattern, which uses the GROUP NAME
|
78 |
-
$translated_string = $this->get_translation(
|
79 |
-
$this->string_to_translate,
|
80 |
-
$this->get_db_identifier()
|
81 |
-
);
|
82 |
-
|
83 |
-
if( $translated_string && $translated_string != $this->string_to_translate )
|
84 |
-
return $translated_string;
|
85 |
-
|
86 |
-
// nothing found yet, try the old pattern for group storage
|
87 |
-
return $this->translate_legacy();
|
88 |
-
}
|
89 |
-
|
90 |
-
/**
|
91 |
-
* Returning the legacy pattern which is using the GROUP ID
|
92 |
-
*
|
93 |
-
* @return mixed|void
|
94 |
-
*/
|
95 |
-
private function translate_legacy() {
|
96 |
-
$translated_string = $this->get_translation(
|
97 |
-
$this->string_to_translate,
|
98 |
-
$this->get_db_identifier_legacy()
|
99 |
-
);
|
100 |
-
|
101 |
-
// no translation found
|
102 |
-
if( ! $translated_string )
|
103 |
-
return $this->string_to_translate;
|
104 |
-
|
105 |
-
// update pattern of name field in "icl_strings" table
|
106 |
-
// to use name of group instead of id
|
107 |
-
$this->update_db_identifier();
|
108 |
-
|
109 |
-
// return translated string
|
110 |
-
return $translated_string;
|
111 |
-
}
|
112 |
-
|
113 |
-
/**
|
114 |
-
* Get translation of string
|
115 |
-
*
|
116 |
-
* @param $string
|
117 |
-
* @param $field_id
|
118 |
-
*
|
119 |
-
* @return string|false
|
120 |
-
*/
|
121 |
-
private function get_translation( $string, $field_id ) {
|
122 |
-
|
123 |
-
// check if translation exists
|
124 |
-
$is_registered = apply_filters(
|
125 |
-
'wpml_string_id',
|
126 |
-
null,
|
127 |
-
array(
|
128 |
-
'context' => self::CONTEXT,
|
129 |
-
'name' => $field_id
|
130 |
-
)
|
131 |
-
);
|
132 |
-
|
133 |
-
if( $is_registered === null )
|
134 |
-
return false;
|
135 |
-
|
136 |
-
// string is registered, return translation
|
137 |
-
return apply_filters(
|
138 |
-
self::TRANSLATE_FILTER,
|
139 |
-
$string,
|
140 |
-
self::CONTEXT,
|
141 |
-
$field_id
|
142 |
-
);
|
143 |
-
}
|
144 |
-
|
145 |
-
/**
|
146 |
-
* Update the identifier on db table "{prefix}_icl_strings" to use the "name" of a group instead of the "id"
|
147 |
-
*/
|
148 |
-
private function update_db_identifier() {
|
149 |
-
global $wpdb;
|
150 |
-
|
151 |
-
$wpdb->query(
|
152 |
-
$wpdb->prepare(
|
153 |
-
"UPDATE {$wpdb->prefix}icl_strings
|
154 |
-
SET name = %s,
|
155 |
-
domain_name_context_md5 = md5( CONCAT( context, name, gettext_context ) )
|
156 |
-
WHERE name = %s",
|
157 |
-
$this->get_db_identifier(),
|
158 |
-
$this->get_db_identifier_legacy()
|
159 |
-
)
|
160 |
-
);
|
161 |
-
}
|
162 |
-
|
163 |
-
/**
|
164 |
-
* Say Hello to WPML
|
165 |
-
*/
|
166 |
-
public function register( $slug_update = false ) {
|
167 |
-
// abort if needed function not exists
|
168 |
-
if( ! function_exists( 'icl_register_string' ) )
|
169 |
-
return;
|
170 |
-
|
171 |
-
// update string identifier
|
172 |
-
if( $slug_update ) {
|
173 |
-
global $wpdb;
|
174 |
-
|
175 |
-
$wpdb->query(
|
176 |
-
$wpdb->prepare(
|
177 |
-
"UPDATE {$wpdb->prefix}icl_strings
|
178 |
-
SET name = %s
|
179 |
-
WHERE name = %s",
|
180 |
-
$this->get_db_identifier(),
|
181 |
-
sprintf( $this->get_db_pattern(), $slug_update )
|
182 |
-
)
|
183 |
-
);
|
184 |
-
}
|
185 |
-
|
186 |
-
// register/update string
|
187 |
-
icl_register_string(
|
188 |
-
self::CONTEXT,
|
189 |
-
$this->get_db_identifier(),
|
190 |
-
$this->get_string_to_translate()
|
191 |
-
);
|
192 |
-
}
|
193 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
abstract class Types_Wpml_Field_Group_String implements Types_Wpml_Interface {
|
4 |
+
|
5 |
+
const CONTEXT = 'plugin Types';
|
6 |
+
const TRANSLATE_FILTER = 'wpml_translate_single_string';
|
7 |
+
|
8 |
+
/**
|
9 |
+
* @var Types_Field_Group
|
10 |
+
*/
|
11 |
+
protected $group;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* String to translate
|
15 |
+
* @var string
|
16 |
+
*/
|
17 |
+
protected $string_to_translate;
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Types_Wpml_Field_Group_String constructor.
|
21 |
+
*
|
22 |
+
* @param Types_Field_Group $group
|
23 |
+
*/
|
24 |
+
public function __construct( Types_Field_Group $group ) {
|
25 |
+
$this->group = $group;
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* The pattern of the string name in icl_strings
|
30 |
+
* - [name]: group %s name
|
31 |
+
* - [description]: group %s description
|
32 |
+
*
|
33 |
+
* @return string
|
34 |
+
*/
|
35 |
+
abstract protected function get_db_pattern();
|
36 |
+
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Returns the string which should be translated
|
40 |
+
*
|
41 |
+
* @return string
|
42 |
+
*/
|
43 |
+
protected function get_string_to_translate() {
|
44 |
+
return $this->string_to_translate;
|
45 |
+
}
|
46 |
+
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Get the db identifier (uses slug of group)
|
50 |
+
*
|
51 |
+
* @return string
|
52 |
+
*/
|
53 |
+
protected function get_db_identifier() {
|
54 |
+
return sprintf( $this->get_db_pattern(), $this->group->get_slug() );
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Get the db identifier (uses id of group)
|
59 |
+
*
|
60 |
+
* @return string
|
61 |
+
*/
|
62 |
+
protected function get_db_identifier_legacy() {
|
63 |
+
return sprintf( $this->get_db_pattern(), $this->group->get_id() );
|
64 |
+
}
|
65 |
+
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Translate name of the group
|
69 |
+
*
|
70 |
+
* @return string
|
71 |
+
*/
|
72 |
+
public function translate() {
|
73 |
+
if ( empty( $this->string_to_translate ) || ! is_string( $this->string_to_translate ) ) {
|
74 |
+
return $this->string_to_translate;
|
75 |
+
}
|
76 |
+
|
77 |
+
// trying the new pattern, which uses the GROUP NAME
|
78 |
+
$translated_string = $this->get_translation(
|
79 |
+
$this->string_to_translate,
|
80 |
+
$this->get_db_identifier()
|
81 |
+
);
|
82 |
+
|
83 |
+
if( $translated_string && $translated_string != $this->string_to_translate )
|
84 |
+
return $translated_string;
|
85 |
+
|
86 |
+
// nothing found yet, try the old pattern for group storage
|
87 |
+
return $this->translate_legacy();
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Returning the legacy pattern which is using the GROUP ID
|
92 |
+
*
|
93 |
+
* @return mixed|void
|
94 |
+
*/
|
95 |
+
private function translate_legacy() {
|
96 |
+
$translated_string = $this->get_translation(
|
97 |
+
$this->string_to_translate,
|
98 |
+
$this->get_db_identifier_legacy()
|
99 |
+
);
|
100 |
+
|
101 |
+
// no translation found
|
102 |
+
if( ! $translated_string )
|
103 |
+
return $this->string_to_translate;
|
104 |
+
|
105 |
+
// update pattern of name field in "icl_strings" table
|
106 |
+
// to use name of group instead of id
|
107 |
+
$this->update_db_identifier();
|
108 |
+
|
109 |
+
// return translated string
|
110 |
+
return $translated_string;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Get translation of string
|
115 |
+
*
|
116 |
+
* @param $string
|
117 |
+
* @param $field_id
|
118 |
+
*
|
119 |
+
* @return string|false
|
120 |
+
*/
|
121 |
+
private function get_translation( $string, $field_id ) {
|
122 |
+
|
123 |
+
// check if translation exists
|
124 |
+
$is_registered = apply_filters(
|
125 |
+
'wpml_string_id',
|
126 |
+
null,
|
127 |
+
array(
|
128 |
+
'context' => self::CONTEXT,
|
129 |
+
'name' => $field_id
|
130 |
+
)
|
131 |
+
);
|
132 |
+
|
133 |
+
if( $is_registered === null )
|
134 |
+
return false;
|
135 |
+
|
136 |
+
// string is registered, return translation
|
137 |
+
return apply_filters(
|
138 |
+
self::TRANSLATE_FILTER,
|
139 |
+
$string,
|
140 |
+
self::CONTEXT,
|
141 |
+
$field_id
|
142 |
+
);
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Update the identifier on db table "{prefix}_icl_strings" to use the "name" of a group instead of the "id"
|
147 |
+
*/
|
148 |
+
private function update_db_identifier() {
|
149 |
+
global $wpdb;
|
150 |
+
|
151 |
+
$wpdb->query(
|
152 |
+
$wpdb->prepare(
|
153 |
+
"UPDATE {$wpdb->prefix}icl_strings
|
154 |
+
SET name = %s,
|
155 |
+
domain_name_context_md5 = md5( CONCAT( context, name, gettext_context ) )
|
156 |
+
WHERE name = %s",
|
157 |
+
$this->get_db_identifier(),
|
158 |
+
$this->get_db_identifier_legacy()
|
159 |
+
)
|
160 |
+
);
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Say Hello to WPML
|
165 |
+
*/
|
166 |
+
public function register( $slug_update = false ) {
|
167 |
+
// abort if needed function not exists
|
168 |
+
if( ! function_exists( 'icl_register_string' ) )
|
169 |
+
return;
|
170 |
+
|
171 |
+
// update string identifier
|
172 |
+
if( $slug_update ) {
|
173 |
+
global $wpdb;
|
174 |
+
|
175 |
+
$wpdb->query(
|
176 |
+
$wpdb->prepare(
|
177 |
+
"UPDATE {$wpdb->prefix}icl_strings
|
178 |
+
SET name = %s
|
179 |
+
WHERE name = %s",
|
180 |
+
$this->get_db_identifier(),
|
181 |
+
sprintf( $this->get_db_pattern(), $slug_update )
|
182 |
+
)
|
183 |
+
);
|
184 |
+
}
|
185 |
+
|
186 |
+
// register/update string
|
187 |
+
icl_register_string(
|
188 |
+
self::CONTEXT,
|
189 |
+
$this->get_db_identifier(),
|
190 |
+
$this->get_string_to_translate()
|
191 |
+
);
|
192 |
+
}
|
193 |
}
|
application/models/wpml/field/group/string/description.php
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
class Types_Wpml_Field_Group_String_Description extends Types_Wpml_Field_Group_String {
|
5 |
-
const DB_NAME_PATTERN = 'group %s description';
|
6 |
-
|
7 |
-
public function __construct( Types_Field_Group $group ) {
|
8 |
-
parent::__construct( $group );
|
9 |
-
$this->string_to_translate = stripslashes( $this->group->get_description() );
|
10 |
-
}
|
11 |
-
|
12 |
-
protected function get_db_pattern() {
|
13 |
-
return self::DB_NAME_PATTERN;
|
14 |
-
}
|
15 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
class Types_Wpml_Field_Group_String_Description extends Types_Wpml_Field_Group_String {
|
5 |
+
const DB_NAME_PATTERN = 'group %s description';
|
6 |
+
|
7 |
+
public function __construct( Types_Field_Group $group ) {
|
8 |
+
parent::__construct( $group );
|
9 |
+
$this->string_to_translate = stripslashes( $this->group->get_description() );
|
10 |
+
}
|
11 |
+
|
12 |
+
protected function get_db_pattern() {
|
13 |
+
return self::DB_NAME_PATTERN;
|
14 |
+
}
|
15 |
}
|
application/models/wpml/field/group/string/name.php
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
class Types_Wpml_Field_Group_String_Name extends Types_Wpml_Field_Group_String {
|
5 |
-
|
6 |
-
const DB_NAME_PATTERN = 'group %s name';
|
7 |
-
|
8 |
-
public function __construct( Types_Field_Group $group ) {
|
9 |
-
parent::__construct( $group );
|
10 |
-
$this->string_to_translate = stripslashes( $this->group->get_name() );
|
11 |
-
}
|
12 |
-
|
13 |
-
protected function get_db_pattern() {
|
14 |
-
return self::DB_NAME_PATTERN;
|
15 |
-
}
|
16 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
class Types_Wpml_Field_Group_String_Name extends Types_Wpml_Field_Group_String {
|
5 |
+
|
6 |
+
const DB_NAME_PATTERN = 'group %s name';
|
7 |
+
|
8 |
+
public function __construct( Types_Field_Group $group ) {
|
9 |
+
parent::__construct( $group );
|
10 |
+
$this->string_to_translate = stripslashes( $this->group->get_name() );
|
11 |
+
}
|
12 |
+
|
13 |
+
protected function get_db_pattern() {
|
14 |
+
return self::DB_NAME_PATTERN;
|
15 |
+
}
|
16 |
}
|
application/models/wpml/field_group.php
CHANGED
@@ -1,90 +1,90 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Class Types_Wpml_Field_Group
|
5 |
-
*
|
6 |
-
* @fixme this is missing documentation
|
7 |
-
*
|
8 |
-
* @since 2.3
|
9 |
-
*/
|
10 |
-
class Types_Wpml_Field_Group implements Types_Wpml_Interface {
|
11 |
-
|
12 |
-
const STRING_NAME = 'name';
|
13 |
-
const STRING_DESCRIPTION = 'description';
|
14 |
-
|
15 |
-
/**
|
16 |
-
* @var Types_Field_Group
|
17 |
-
*/
|
18 |
-
private $group;
|
19 |
-
|
20 |
-
/**
|
21 |
-
* @var Types_Wpml_Interface
|
22 |
-
*/
|
23 |
-
private $name;
|
24 |
-
|
25 |
-
/**
|
26 |
-
* @var Types_Wpml_Interface
|
27 |
-
*/
|
28 |
-
private $description;
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Types_Wpml_Field_Group constructor.
|
32 |
-
*
|
33 |
-
* @param Types_Field_Group $group
|
34 |
-
*/
|
35 |
-
public function __construct( Types_Field_Group $group ) {
|
36 |
-
$this->group = $group;
|
37 |
-
|
38 |
-
// todo get rid of these hard dependencies
|
39 |
-
$this->name = new Types_Wpml_Field_Group_String_Name( $this->group );
|
40 |
-
$this->description = new Types_Wpml_Field_Group_String_Description( $this->group );
|
41 |
-
}
|
42 |
-
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Translate name or description of group
|
46 |
-
*
|
47 |
-
* @param string $part
|
48 |
-
*
|
49 |
-
* @return string
|
50 |
-
*/
|
51 |
-
public function translate( $part = self::STRING_NAME ) {
|
52 |
-
switch( $part ) {
|
53 |
-
case self::STRING_NAME:
|
54 |
-
return $this->translate_name();
|
55 |
-
break;
|
56 |
-
case self::STRING_DESCRIPTION:
|
57 |
-
return $this->translate_description();
|
58 |
-
break;
|
59 |
-
default:
|
60 |
-
return '';
|
61 |
-
}
|
62 |
-
}
|
63 |
-
|
64 |
-
/**
|
65 |
-
* Translate name of the group
|
66 |
-
*
|
67 |
-
* @return string
|
68 |
-
*/
|
69 |
-
public function translate_name() {
|
70 |
-
return $this->name->translate();
|
71 |
-
}
|
72 |
-
|
73 |
-
/**
|
74 |
-
* Translate description of group
|
75 |
-
*
|
76 |
-
* @return string
|
77 |
-
*/
|
78 |
-
public function translate_description() {
|
79 |
-
return $this->description->translate();
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* Registration of name and description strings
|
84 |
-
* @param bool|string $slug_update
|
85 |
-
*/
|
86 |
-
public function register( $slug_update = false ) {
|
87 |
-
$this->name->register( $slug_update );
|
88 |
-
$this->description->register( $slug_update );
|
89 |
-
}
|
90 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Types_Wpml_Field_Group
|
5 |
+
*
|
6 |
+
* @fixme this is missing documentation
|
7 |
+
*
|
8 |
+
* @since 2.3
|
9 |
+
*/
|
10 |
+
class Types_Wpml_Field_Group implements Types_Wpml_Interface {
|
11 |
+
|
12 |
+
const STRING_NAME = 'name';
|
13 |
+
const STRING_DESCRIPTION = 'description';
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @var Types_Field_Group
|
17 |
+
*/
|
18 |
+
private $group;
|
19 |
+
|
20 |
+
/**
|
21 |
+
* @var Types_Wpml_Interface
|
22 |
+
*/
|
23 |
+
private $name;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* @var Types_Wpml_Interface
|
27 |
+
*/
|
28 |
+
private $description;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Types_Wpml_Field_Group constructor.
|
32 |
+
*
|
33 |
+
* @param Types_Field_Group $group
|
34 |
+
*/
|
35 |
+
public function __construct( Types_Field_Group $group ) {
|
36 |
+
$this->group = $group;
|
37 |
+
|
38 |
+
// todo get rid of these hard dependencies
|
39 |
+
$this->name = new Types_Wpml_Field_Group_String_Name( $this->group );
|
40 |
+
$this->description = new Types_Wpml_Field_Group_String_Description( $this->group );
|
41 |
+
}
|
42 |
+
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Translate name or description of group
|
46 |
+
*
|
47 |
+
* @param string $part
|
48 |
+
*
|
49 |
+
* @return string
|
50 |
+
*/
|
51 |
+
public function translate( $part = self::STRING_NAME ) {
|
52 |
+
switch( $part ) {
|
53 |
+
case self::STRING_NAME:
|
54 |
+
return $this->translate_name();
|
55 |
+
break;
|
56 |
+
case self::STRING_DESCRIPTION:
|
57 |
+
return $this->translate_description();
|
58 |
+
break;
|
59 |
+
default:
|
60 |
+
return '';
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Translate name of the group
|
66 |
+
*
|
67 |
+
* @return string
|
68 |
+
*/
|
69 |
+
public function translate_name() {
|
70 |
+
return $this->name->translate();
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Translate description of group
|
75 |
+
*
|
76 |
+
* @return string
|
77 |
+
*/
|
78 |
+
public function translate_description() {
|
79 |
+
return $this->description->translate();
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Registration of name and description strings
|
84 |
+
* @param bool|string $slug_update
|
85 |
+
*/
|
86 |
+
public function register( $slug_update = false ) {
|
87 |
+
$this->name->register( $slug_update );
|
88 |
+
$this->description->register( $slug_update );
|
89 |
+
}
|
90 |
}
|
application/models/wpml/interface.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
interface Types_Wpml_Interface {
|
4 |
-
public function translate();
|
5 |
-
public function register( $slug_update = false );
|
6 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
interface Types_Wpml_Interface {
|
4 |
+
public function translate();
|
5 |
+
public function register( $slug_update = false );
|
6 |
}
|
disabled_autoload_classmap.php
DELETED
@@ -1,151 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
// Generated by ZF2's ./bin/classmap_generator.php
|
3 |
-
return array(
|
4 |
-
'Types_Api' => TYPES_ABSPATH . '/application/api.php',
|
5 |
-
'Types_Admin' => TYPES_ABSPATH . '/application/controllers/admin.php',
|
6 |
-
'Types_Admin_Menu' => TYPES_ABSPATH . '/application/controllers/admin_menu.php',
|
7 |
-
'Types_Ajax_Handler_Abstract' => TYPES_ABSPATH . '/application/controllers/ajax/handler/abstract.php',
|
8 |
-
'Types_Ajax_Handler_Check_Slug_Conflicts' => TYPES_ABSPATH . '/application/controllers/ajax/handler/check_slug_conflicts.php',
|
9 |
-
'Types_Ajax_Handler_Field_Control_Action' => TYPES_ABSPATH . '/application/controllers/ajax/handler/field_control_action.php',
|
10 |
-
'Types_Ajax_Handler_Settings_Action' => TYPES_ABSPATH . '/application/controllers/ajax/handler/settings_action.php',
|
11 |
-
'Types_Ajax_Handler_Interface' => TYPES_ABSPATH . '/application/controllers/ajax/handler_interface.php',
|
12 |
-
'Types_Ajax' => TYPES_ABSPATH . '/application/controllers/ajax.php',
|
13 |
-
'Types_Asset_Help_Tab_Loader' => TYPES_ABSPATH . '/application/controllers/asset/help_tab_loader.php',
|
14 |
-
'Types_Asset_Manager' => TYPES_ABSPATH . '/application/controllers/asset/manager.php',
|
15 |
-
'Types_Assets' => TYPES_ABSPATH . '/application/controllers/assets.php',
|
16 |
-
'Types_Dialog_Box' => TYPES_ABSPATH . '/application/controllers/dialog_box.php',
|
17 |
-
'Types_Embedded' => TYPES_ABSPATH . '/application/controllers/embedded.php',
|
18 |
-
'Types_Field_Type_Converter' => TYPES_ABSPATH . '/application/controllers/field/type_converter.php',
|
19 |
-
'Types_Field_Utils' => TYPES_ABSPATH . '/application/controllers/field/utils.php',
|
20 |
-
'Types_Frontend' => TYPES_ABSPATH . '/application/controllers/frontend.php',
|
21 |
-
'Types_Import_Export' => TYPES_ABSPATH . '/application/controllers/import_export.php',
|
22 |
-
'Types_Information_Controller' => TYPES_ABSPATH . '/application/controllers/information/controller.php',
|
23 |
-
'Types_Main' => TYPES_ABSPATH . '/application/controllers/main.php',
|
24 |
-
'Types_Page_Abstract' => TYPES_ABSPATH . '/application/controllers/page/abstract.php',
|
25 |
-
'Types_Page_Dashboard' => TYPES_ABSPATH . '/application/controllers/page/dashboard.php',
|
26 |
-
'Types_Page_Extension_Edit_Post' => TYPES_ABSPATH . '/application/controllers/page/extension/edit_post.php',
|
27 |
-
'Types_Page_Extension_Edit_Post_Fields' => TYPES_ABSPATH . '/application/controllers/page/extension/edit_post_fields.php',
|
28 |
-
'Types_Page_Extension_Edit_Post_Type' => TYPES_ABSPATH . '/application/controllers/page/extension/edit_post_type.php',
|
29 |
-
'Types_Page_Extension_Settings' => TYPES_ABSPATH . '/application/controllers/page/extension/settings.php',
|
30 |
-
'Types_Page_Field_Control' => TYPES_ABSPATH . '/application/controllers/page/field_control.php',
|
31 |
-
'Types_Page_Hidden_Helper' => TYPES_ABSPATH . '/application/controllers/page/hidden/helper.php',
|
32 |
-
'Types_Twig_Autoloader' => TYPES_ABSPATH . '/application/controllers/twig_autoloader.php',
|
33 |
-
'Types_Upgrade' => TYPES_ABSPATH . '/application/controllers/upgrade.php',
|
34 |
-
'Types_Utils' => TYPES_ABSPATH . '/application/controllers/utils.php',
|
35 |
-
'Types_Api_Helper' => TYPES_ABSPATH . '/application/models/api/helper.php',
|
36 |
-
'Types_Field_Group_Factory' => TYPES_ABSPATH . '/application/models/field/group/factory.php',
|
37 |
-
'Types_Field_Group_Post' => TYPES_ABSPATH . '/application/models/field/group/post.php',
|
38 |
-
'Types_Field_Group_Post_Factory' => TYPES_ABSPATH . '/application/models/field/group/post_factory.php',
|
39 |
-
'Types_Field_Group_Term' => TYPES_ABSPATH . '/application/models/field/group/term.php',
|
40 |
-
'Types_Field_Group_Term_Factory' => TYPES_ABSPATH . '/application/models/field/group/term_factory.php',
|
41 |
-
'Types_Field_Group_User' => TYPES_ABSPATH . '/application/models/field/group/user.php',
|
42 |
-
'Types_Field_Group_User_Factory' => TYPES_ABSPATH . '/application/models/field/group/user_factory.php',
|
43 |
-
'Types_Field_Group' => TYPES_ABSPATH . '/application/models/field/group.php',
|
44 |
-
'Types_Field_Type_Definition_Checkbox' => TYPES_ABSPATH . '/application/models/field/type/definition/checkbox.php',
|
45 |
-
'Types_Field_Type_Definition_Checkboxes' => TYPES_ABSPATH . '/application/models/field/type/definition/checkboxes.php',
|
46 |
-
'Types_Field_Type_Definition_Date' => TYPES_ABSPATH . '/application/models/field/type/definition/date.php',
|
47 |
-
'Types_Field_Type_Definition_Numeric' => TYPES_ABSPATH . '/application/models/field/type/definition/numeric.php',
|
48 |
-
'Types_Field_Type_Definition_Radio' => TYPES_ABSPATH . '/application/models/field/type/definition/radio.php',
|
49 |
-
'Types_Field_Type_Definition_Select' => TYPES_ABSPATH . '/application/models/field/type/definition/select.php',
|
50 |
-
'Types_Field_Type_Definition_Singular' => TYPES_ABSPATH . '/application/models/field/type/definition/singular.php',
|
51 |
-
'Types_Field_Type_Definition' => TYPES_ABSPATH . '/application/models/field/type/definition.php',
|
52 |
-
'Types_Field_Type_Definition_Factory' => TYPES_ABSPATH . '/application/models/field/type/definition_factory.php',
|
53 |
-
'Types_Helper_Condition_Archive_Exists' => TYPES_ABSPATH . '/application/models/helper/condition/archive/exists.php',
|
54 |
-
'Types_Helper_Condition_Archive_Has_Fields' => TYPES_ABSPATH . '/application/models/helper/condition/archive/has_fields.php',
|
55 |
-
'Types_Helper_Condition_Archive_Missing' => TYPES_ABSPATH . '/application/models/helper/condition/archive/missing.php',
|
56 |
-
'Types_Helper_Condition_Archive_No_Fields' => TYPES_ABSPATH . '/application/models/helper/condition/archive/no_fields.php',
|
57 |
-
'Types_Helper_Condition_Archive_No_Support' => TYPES_ABSPATH . '/application/models/helper/condition/archive/no_support.php',
|
58 |
-
'Types_Helper_Condition_Archive_Support' => TYPES_ABSPATH . '/application/models/helper/condition/archive/support.php',
|
59 |
-
'Types_Helper_Condition_Cred_Active' => TYPES_ABSPATH . '/application/models/helper/condition/cred/active.php',
|
60 |
-
'Types_Helper_Condition_Cred_Forms_Exist' => TYPES_ABSPATH . '/application/models/helper/condition/cred/forms_exist.php',
|
61 |
-
'Types_Helper_Condition_Cred_Forms_Missing' => TYPES_ABSPATH . '/application/models/helper/condition/cred/forms_missing.php',
|
62 |
-
'Types_Helper_Condition_Cred_Missing' => TYPES_ABSPATH . '/application/models/helper/condition/cred/missing.php',
|
63 |
-
'Types_Helper_Condition_Layouts_Active' => TYPES_ABSPATH . '/application/models/helper/condition/layouts/active.php',
|
64 |
-
'Types_Helper_Condition_Layouts_Archive_Exists' => TYPES_ABSPATH . '/application/models/helper/condition/layouts/archive_exists.php',
|
65 |
-
'Types_Helper_Condition_Layouts_Archive_Missing' => TYPES_ABSPATH . '/application/models/helper/condition/layouts/archive_missing.php',
|
66 |
-
'Types_Helper_Condition_Layouts_Compatible' => TYPES_ABSPATH . '/application/models/helper/condition/layouts/compatible.php',
|
67 |
-
'Types_Helper_Condition_Layouts_Missing' => TYPES_ABSPATH . '/application/models/helper/condition/layouts/missing.php',
|
68 |
-
'Types_Helper_Condition_Layouts_Template_Exists' => TYPES_ABSPATH . '/application/models/helper/condition/layouts/template_exists.php',
|
69 |
-
'Types_Helper_Condition_Layouts_Template_Missing' => TYPES_ABSPATH . '/application/models/helper/condition/layouts/template_missing.php',
|
70 |
-
'Types_Helper_Condition_Screen' => TYPES_ABSPATH . '/application/models/helper/condition/screen.php',
|
71 |
-
'Types_Helper_Condition_Single_Exists' => TYPES_ABSPATH . '/application/models/helper/condition/single/exists.php',
|
72 |
-
'Types_Helper_Condition_Single_Has_Fields' => TYPES_ABSPATH . '/application/models/helper/condition/single/has_fields.php',
|
73 |
-
'Types_Helper_Condition_Single_Missing' => TYPES_ABSPATH . '/application/models/helper/condition/single/missing.php',
|
74 |
-
'Types_Helper_Condition_Single_No_Fields' => TYPES_ABSPATH . '/application/models/helper/condition/single/no_fields.php',
|
75 |
-
'Types_Helper_Condition_Template' => TYPES_ABSPATH . '/application/models/helper/condition/template.php',
|
76 |
-
'Types_Helper_Condition_Type_Fields_Assigned' => TYPES_ABSPATH . '/application/models/helper/condition/type/fields_assigned.php',
|
77 |
-
'Types_Helper_Condition_Views_Active' => TYPES_ABSPATH . '/application/models/helper/condition/views/active.php',
|
78 |
-
'Types_Helper_Condition_Views_Archive_Exists' => TYPES_ABSPATH . '/application/models/helper/condition/views/archive_exists.php',
|
79 |
-
'Types_Helper_Condition_Views_Archive_Missing' => TYPES_ABSPATH . '/application/models/helper/condition/views/archive_missing.php',
|
80 |
-
'Types_Helper_Condition_Views_Missing' => TYPES_ABSPATH . '/application/models/helper/condition/views/missing.php',
|
81 |
-
'Types_Helper_Condition_Views_Template_Exists' => TYPES_ABSPATH . '/application/models/helper/condition/views/template_exists.php',
|
82 |
-
'Types_Helper_Condition_Views_Template_Missing' => TYPES_ABSPATH . '/application/models/helper/condition/views/template_missing.php',
|
83 |
-
'Types_Helper_Condition_Views_Views_Exist' => TYPES_ABSPATH . '/application/models/helper/condition/views/views_exist.php',
|
84 |
-
'Types_Helper_Condition_Views_Views_Missing' => TYPES_ABSPATH . '/application/models/helper/condition/views/views_missing.php',
|
85 |
-
'Types_Helper_Condition' => TYPES_ABSPATH . '/application/models/helper/condition.php',
|
86 |
-
'Types_Helper_Create_Content_Template' => TYPES_ABSPATH . '/application/models/helper/create/content_template.php',
|
87 |
-
'Types_Helper_Create_Form' => TYPES_ABSPATH . '/application/models/helper/create/form.php',
|
88 |
-
'Types_Helper_Create_Layout' => TYPES_ABSPATH . '/application/models/helper/create/layout.php',
|
89 |
-
'Types_Helper_Create_View' => TYPES_ABSPATH . '/application/models/helper/create/view.php',
|
90 |
-
'Types_Helper_Create_Wordpress_Archive' => TYPES_ABSPATH . '/application/models/helper/create/wordpress_archive.php',
|
91 |
-
'Types_Helper_Output_Interface' => TYPES_ABSPATH . '/application/models/helper/output/interface.php',
|
92 |
-
'Types_Helper_Output_Meta_Box' => TYPES_ABSPATH . '/application/models/helper/output/meta_box.php',
|
93 |
-
'Types_Helper_Placeholder' => TYPES_ABSPATH . '/application/models/helper/placeholder.php',
|
94 |
-
'Types_Helper_Twig' => TYPES_ABSPATH . '/application/models/helper/twig.php',
|
95 |
-
'Types_Helper_Url' => TYPES_ABSPATH . '/application/models/helper/url.php',
|
96 |
-
'Types_Information_Container' => TYPES_ABSPATH . '/application/models/information/container.php',
|
97 |
-
'Types_Information_Message_Post_Type' => TYPES_ABSPATH . '/application/models/information/message/post_type.php',
|
98 |
-
'Types_Information_Message' => TYPES_ABSPATH . '/application/models/information/message.php',
|
99 |
-
'Types_Information_Table' => TYPES_ABSPATH . '/application/models/information/table.php',
|
100 |
-
'Types_Post_Type' => TYPES_ABSPATH . '/application/models/post_type.php',
|
101 |
-
'Types_Setting_Boolean' => TYPES_ABSPATH . '/application/models/setting/boolean.php',
|
102 |
-
'Types_Setting_Interface' => TYPES_ABSPATH . '/application/models/setting/interface.php',
|
103 |
-
'Types_Setting_Option_Interface' => TYPES_ABSPATH . '/application/models/setting/option/interface.php',
|
104 |
-
'Types_Setting_Option' => TYPES_ABSPATH . '/application/models/setting/option.php',
|
105 |
-
'Types_Setting_Preset_Information_Table' => TYPES_ABSPATH . '/application/models/setting/preset/information_table.php',
|
106 |
-
'Types_Setting' => TYPES_ABSPATH . '/application/models/setting.php',
|
107 |
-
'Types_Taxonomy' => TYPES_ABSPATH . '/application/models/taxonomy.php',
|
108 |
-
'Toolset_Autoloader' => TYPES_ABSPATH . '/library/toolset/autoloader/autoloader.php',
|
109 |
-
'Toolset_Filesystem_Directory' => TYPES_ABSPATH . '/library/toolset/filesystem/directory.php',
|
110 |
-
'Toolset_Filesystem_Exception' => TYPES_ABSPATH . '/library/toolset/filesystem/exception.php',
|
111 |
-
'Toolset_Filesystem_File' => TYPES_ABSPATH . '/library/toolset/filesystem/file.php',
|
112 |
-
'WPToolset_Forms_Bootstrap' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/bootstrap.php',
|
113 |
-
'WPToolset_Field_Audio' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.audio.php',
|
114 |
-
'WPToolset_Field_Button' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.button.php',
|
115 |
-
'WPToolset_Field_Checkbox' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.checkbox.php',
|
116 |
-
'WPToolset_Field_Checkboxes' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.checkboxes.php',
|
117 |
-
'WPToolset_Field_Colorpicker' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.colorpicker.php',
|
118 |
-
'WPToolset_Forms_Conditional' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.conditional.php',
|
119 |
-
'WPToolset_Cred' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.cred.php',
|
120 |
-
'WPToolset_Field_Credaudio' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.credaudio.php',
|
121 |
-
'WPToolset_Field_Credfile' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.credfile.php',
|
122 |
-
'WPToolset_Field_Credimage' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.credimage.php',
|
123 |
-
'WPToolset_Field_Credvideo' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.credvideo.php',
|
124 |
-
'WPToolset_Field_Date' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.date.php',
|
125 |
-
'WPToolset_Field_Date_Scripts' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.date.scripts.php',
|
126 |
-
'WPToolset_Field_Email' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.email.php',
|
127 |
-
'WPToolset_Field_Embed' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.embed.php',
|
128 |
-
'WPToolset_Field_File' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.file.php',
|
129 |
-
'WPToolset_Field_Hidden' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.hidden.php',
|
130 |
-
'WPToolset_Field_Image' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.image.php',
|
131 |
-
'WPToolset_Field_Integer' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.integer.php',
|
132 |
-
'WPToolset_Field_Numeric' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.numeric.php',
|
133 |
-
'WPToolset_Field_Password' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.password.php',
|
134 |
-
'WPToolset_Field_Phone' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.phone.php',
|
135 |
-
'WPToolset_Field_Radios' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.radios.php',
|
136 |
-
'WPToolset_Field_Recaptcha' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.recaptcha.php',
|
137 |
-
'WPToolset_Forms_Repetitive' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.repetitive.php',
|
138 |
-
'WPToolset_Field_Select' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.select.php',
|
139 |
-
'WPToolset_Field_Skype' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.skype.php',
|
140 |
-
'WPToolset_Field_Submit' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.submit.php',
|
141 |
-
'WPToolset_Field_Taxonomy' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.taxonomy.php',
|
142 |
-
'WPToolset_Field_Taxonomyhierarchical' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.taxonomyhierarchical.php',
|
143 |
-
'WPToolset_Field_Textarea' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.textarea.php',
|
144 |
-
'WPToolset_Field_Textfield' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.textfield.php',
|
145 |
-
'WPToolset_Types' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.types.php',
|
146 |
-
'WPToolset_Field_Url' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.url.php',
|
147 |
-
'WPToolset_Forms_Validation' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.validation.php',
|
148 |
-
'WPToolset_Field_Video' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.video.php',
|
149 |
-
'WPToolset_Field_Wysiwyg' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/classes/class.wysiwyg.php',
|
150 |
-
'WPToolset_Cake_Validation' => TYPES_ABSPATH . '/library/toolset/toolset-common/toolset-forms/lib/CakePHP-Validation.php',
|
151 |
-
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
examples/author.php
CHANGED
@@ -1,87 +1,87 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* This example file is a part of the Types plugin online documentation found at: https://wp-types.com/documentation/customizing-sites-using-php/
|
4 |
-
* It is based on the original Twenty Sixteen theme's archive.php file.
|
5 |
-
* It features additional code to render custom user fields created with the Types plugin.
|
6 |
-
*
|
7 |
-
* Please note that the names of the custom fields are for example purposes only and will not work in your site as-is. You need to edit this example according to the documentation mentioned above.
|
8 |
-
*
|
9 |
-
* The template for displaying custom author archive pages
|
10 |
-
*
|
11 |
-
*
|
12 |
-
* @package WordPress
|
13 |
-
* @subpackage Twenty_Sixteen
|
14 |
-
* @since Twenty Sixteen 1.0
|
15 |
-
*/
|
16 |
-
|
17 |
-
get_header(); ?>
|
18 |
-
|
19 |
-
<div id="primary" class="content-area">
|
20 |
-
<main id="main" class="site-main" role="main">
|
21 |
-
|
22 |
-
<?php if ( have_posts() ) : ?>
|
23 |
-
|
24 |
-
<header class="page-header">
|
25 |
-
<!-- TYPES TIP: using get_the_author_meta function to output author name as the archive's title -->
|
26 |
-
<?php
|
27 |
-
echo '<h1 class="page-title">Author: ' . get_the_author_meta( 'first_name' ) . ' ' . get_the_author_meta( 'last_name' ) . '</h1>';
|
28 |
-
?>
|
29 |
-
|
30 |
-
<!-- TYPES TIP: using get_avatar function to output author's avatar image -->
|
31 |
-
<div class="user-avatar"><?php echo get_avatar( get_the_author_meta( 'user_email' ), '150' ); ?></div>
|
32 |
-
|
33 |
-
<!-- TYPES TIP: using Types function to custom user fields -->
|
34 |
-
<p><strong>Specialty topics:</strong> <?php echo types_render_usermeta( "specialty-topics" ); ?><br />
|
35 |
-
<strong>Staff role:</strong> <?php echo types_render_usermeta( "staff-role" ); ?></p>
|
36 |
-
|
37 |
-
<!-- TYPES TIP: using the the_author_meta function to output the description of the user -->
|
38 |
-
<p><b>About:</b> <?php the_author_meta( 'description' ); ?></p>
|
39 |
-
|
40 |
-
</header><!-- .page-header -->
|
41 |
-
|
42 |
-
<hr />
|
43 |
-
|
44 |
-
|
45 |
-
<!-- TYPES TIP: Creating a custom query for our author/user to display posts belonging to the "Post" and "Book" post types -->
|
46 |
-
<?php
|
47 |
-
// Add Custom Post Type to author archive
|
48 |
-
$args = array(
|
49 |
-
'post_type' => array('post', 'book') ,
|
50 |
-
'author' => get_queried_object_id(), // this will be the author ID on the author page
|
51 |
-
'showposts' => 10
|
52 |
-
);
|
53 |
-
$custom_posts = new WP_Query( $args );
|
54 |
-
|
55 |
-
// Start the Loop.
|
56 |
-
while ( $custom_posts->have_posts() ) : $custom_posts->the_post();
|
57 |
-
|
58 |
-
/*
|
59 |
-
* Include the Post-Format-specific template for the content.
|
60 |
-
* If you want to override this in a child theme, then include a file
|
61 |
-
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
|
62 |
-
*/
|
63 |
-
|
64 |
-
get_template_part( 'template-parts/content', get_post_type() );
|
65 |
-
|
66 |
-
// End the loop.
|
67 |
-
endwhile;
|
68 |
-
|
69 |
-
// Previous/next page navigation.
|
70 |
-
the_posts_pagination( array(
|
71 |
-
'prev_text' => __( 'Previous page', 'twentysixteen' ),
|
72 |
-
'next_text' => __( 'Next page', 'twentysixteen' ),
|
73 |
-
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>',
|
74 |
-
) );
|
75 |
-
|
76 |
-
// If no content, include the "No posts found" template.
|
77 |
-
else :
|
78 |
-
|
79 |
-
|
80 |
-
endif;
|
81 |
-
?>
|
82 |
-
|
83 |
-
</main><!-- .site-main -->
|
84 |
-
</div><!-- .content-area -->
|
85 |
-
|
86 |
-
<?php get_sidebar(); ?>
|
87 |
-
<?php get_footer(); ?>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* This example file is a part of the Types plugin online documentation found at: https://wp-types.com/documentation/customizing-sites-using-php/
|
4 |
+
* It is based on the original Twenty Sixteen theme's archive.php file.
|
5 |
+
* It features additional code to render custom user fields created with the Types plugin.
|
6 |
+
*
|
7 |
+
* Please note that the names of the custom fields are for example purposes only and will not work in your site as-is. You need to edit this example according to the documentation mentioned above.
|
8 |
+
*
|
9 |
+
* The template for displaying custom author archive pages
|
10 |
+
*
|
11 |
+
*
|
12 |
+
* @package WordPress
|
13 |
+
* @subpackage Twenty_Sixteen
|
14 |
+
* @since Twenty Sixteen 1.0
|
15 |
+
*/
|
16 |
+
|
17 |
+
get_header(); ?>
|
18 |
+
|
19 |
+
<div id="primary" class="content-area">
|
20 |
+
<main id="main" class="site-main" role="main">
|
21 |
+
|
22 |
+
<?php if ( have_posts() ) : ?>
|
23 |
+
|
24 |
+
<header class="page-header">
|
25 |
+
<!-- TYPES TIP: using get_the_author_meta function to output author name as the archive's title -->
|
26 |
+
<?php
|
27 |
+
echo '<h1 class="page-title">Author: ' . get_the_author_meta( 'first_name' ) . ' ' . get_the_author_meta( 'last_name' ) . '</h1>';
|
28 |
+
?>
|
29 |
+
|
30 |
+
<!-- TYPES TIP: using get_avatar function to output author's avatar image -->
|
31 |
+
<div class="user-avatar"><?php echo get_avatar( get_the_author_meta( 'user_email' ), '150' ); ?></div>
|
32 |
+
|
33 |
+
<!-- TYPES TIP: using Types function to custom user fields -->
|
34 |
+
<p><strong>Specialty topics:</strong> <?php echo types_render_usermeta( "specialty-topics" ); ?><br />
|
35 |
+
<strong>Staff role:</strong> <?php echo types_render_usermeta( "staff-role" ); ?></p>
|
36 |
+
|
37 |
+
<!-- TYPES TIP: using the the_author_meta function to output the description of the user -->
|
38 |
+
<p><b>About:</b> <?php the_author_meta( 'description' ); ?></p>
|
39 |
+
|
40 |
+
</header><!-- .page-header -->
|
41 |
+
|
42 |
+
<hr />
|
43 |
+
|
44 |
+
|
45 |
+
<!-- TYPES TIP: Creating a custom query for our author/user to display posts belonging to the "Post" and "Book" post types -->
|
46 |
+
<?php
|
47 |
+
// Add Custom Post Type to author archive
|
48 |
+
$args = array(
|
49 |
+
'post_type' => array('post', 'book') ,
|
50 |
+
'author' => get_queried_object_id(), // this will be the author ID on the author page
|
51 |
+
'showposts' => 10
|
52 |
+
);
|
53 |
+
$custom_posts = new WP_Query( $args );
|
54 |
+
|
55 |
+
// Start the Loop.
|
56 |
+
while ( $custom_posts->have_posts() ) : $custom_posts->the_post();
|
57 |
+
|
58 |
+
/*
|
59 |
+
* Include the Post-Format-specific template for the content.
|
60 |
+
* If you want to override this in a child theme, then include a file
|
61 |
+
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
|
62 |
+
*/
|
63 |
+
|
64 |
+
get_template_part( 'template-parts/content', get_post_type() );
|
65 |
+
|
66 |
+
// End the loop.
|
67 |
+
endwhile;
|
68 |
+
|
69 |
+
// Previous/next page navigation.
|
70 |
+
the_posts_pagination( array(
|
71 |
+
'prev_text' => __( 'Previous page', 'twentysixteen' ),
|
72 |
+
'next_text' => __( 'Next page', 'twentysixteen' ),
|
73 |
+
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>',
|
74 |
+
) );
|
75 |
+
|
76 |
+
// If no content, include the "No posts found" template.
|
77 |
+
else :
|
78 |
+
|
79 |
+
|
80 |
+
endif;
|
81 |
+
?>
|
82 |
+
|
83 |
+
</main><!-- .site-main -->
|
84 |
+
</div><!-- .content-area -->
|
85 |
+
|
86 |
+
<?php get_sidebar(); ?>
|
87 |
+
<?php get_footer(); ?>
|
examples/content-book.php
CHANGED
@@ -1,101 +1,101 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* This example file is a part of the Types plugin online documentation found at: https://wp-types.com/documentation/customizing-sites-using-php/
|
4 |
-
* It is based on the original Twenty Sixteen theme's template part file for displaying single items.
|
5 |
-
* It features additional code to render custom fields created with the Types plugin and some parent post contents.
|
6 |
-
*
|
7 |
-
* Please note that the names of the custom fields are for example purposes only and will not work in your site as-is. You need to edit this example according to the documentation mentioned above.
|
8 |
-
*
|
9 |
-
* The template part for displaying Book post content
|
10 |
-
*
|
11 |
-
* @package WordPress
|
12 |
-
* @subpackage Twenty_Sixteen
|
13 |
-
* @since Twenty Sixteen 1.0
|
14 |
-
*/
|
15 |
-
?>
|
16 |
-
|
17 |
-
<!-- Standard Twenty Sixteen article header output -->
|
18 |
-
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
19 |
-
<header class="entry-header">
|
20 |
-
<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
|
21 |
-
<span class="sticky-post"><?php _e( 'Featured', 'twentysixteen' ); ?></span>
|
22 |
-
<?php endif; ?>
|
23 |
-
|
24 |
-
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
|
25 |
-
</header><!-- .entry-header -->
|
26 |
-
|
27 |
-
<?php twentysixteen_excerpt(); ?>
|
28 |
-
|
29 |
-
|
30 |
-
<!-- TYPES TIP: Custom call to Types function to render a custom image field "Book Cover" -->
|
31 |
-
<?php echo types_render_field( "book-cover", array( "size" => "thumbnail" ) ); ?>
|
32 |
-
|
33 |
-
<div class="entry-content">
|
34 |
-
<?php
|
35 |
-
/* translators: %s: Name of current post */
|
36 |
-
the_content( sprintf(
|
37 |
-
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
38 |
-
get_the_title()
|
39 |
-
) );
|
40 |
-
|
41 |
-
wp_link_pages( array(
|
42 |
-
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>',
|
43 |
-
'after' => '</div>',
|
44 |
-
'link_before' => '<span>',
|
45 |
-
'link_after' => '</span>',
|
46 |
-
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%',
|
47 |
-
'separator' => '<span class="screen-reader-text">, </span>',
|
48 |
-
) );
|
49 |
-
?>
|
50 |
-
|
51 |
-
|
52 |
-
<!-- TYPES TIP: Custom call to Types function to render a custom field "Number of pages" -->
|
53 |
-
<p><strong>Number of pages:</strong> <?php echo types_render_field( "number-of-pages"); ?></p>
|
54 |
-
|
55 |
-
|
56 |
-
<!-- TYPES TIP: Custom code to load and display contents of the parent ("Writer") post -->
|
57 |
-
<?php
|
58 |
-
// Get the ID of the parent post, which belongs to the "Writer" post type
|
59 |
-
$writer_id = wpcf_pr_post_get_belongs( get_the_ID(), 'writer' );
|
60 |
-
|
61 |
-
// Get all the parent (writer) post data
|
62 |
-
$writer_post = get_post( $writer_id );
|
63 |
-
|
64 |
-
// Get the title of the parent (writer) post
|
65 |
-
$writer_name = $writer_post->post_title;
|
66 |
-
|
67 |
-
// Get the contents of the parent (writer) post
|
68 |
-
$writer_content = $writer_post->post_content;
|
69 |
-
?>
|
70 |
-
<!-- After loading the data of the parent post we display it using our custom HTML structure -->
|
71 |
-
<div class="writer">
|
72 |
-
<h5>Author: <?php echo $writer_name; ?></h5>
|
73 |
-
<div class="writer-description"><?php echo $writer_content; ?></div>
|
74 |
-
|
75 |
-
<!-- We can use the "post_id" argument with the types_render_field function to get a custom field of any post -->
|
76 |
-
<div class="writer-photo"><?php echo types_render_field( 'author-image', array( 'post_id' => $writer_id, 'size' => 'thumbnail' ) );
|
77 |
-
?></div>
|
78 |
-
|
79 |
-
<br class="clear">
|
80 |
-
</div>
|
81 |
-
|
82 |
-
|
83 |
-
</div><!-- .entry-content -->
|
84 |
-
|
85 |
-
<!-- Standard Twenty Sixteen content footer output -->
|
86 |
-
<footer class="entry-footer">
|
87 |
-
<?php twentysixteen_entry_meta(); ?>
|
88 |
-
<?php
|
89 |
-
edit_post_link(
|
90 |
-
sprintf(
|
91 |
-
/* translators: %s: Name of current post */
|
92 |
-
__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
93 |
-
get_the_title()
|
94 |
-
),
|
95 |
-
'<span class="edit-link">',
|
96 |
-
'</span>'
|
97 |
-
);
|
98 |
-
?>
|
99 |
-
</footer><!-- .entry-footer -->
|
100 |
-
</article><!-- #post-## -->
|
101 |
-
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* This example file is a part of the Types plugin online documentation found at: https://wp-types.com/documentation/customizing-sites-using-php/
|
4 |
+
* It is based on the original Twenty Sixteen theme's template part file for displaying single items.
|
5 |
+
* It features additional code to render custom fields created with the Types plugin and some parent post contents.
|
6 |
+
*
|
7 |
+
* Please note that the names of the custom fields are for example purposes only and will not work in your site as-is. You need to edit this example according to the documentation mentioned above.
|
8 |
+
*
|
9 |
+
* The template part for displaying Book post content
|
10 |
+
*
|
11 |
+
* @package WordPress
|
12 |
+
* @subpackage Twenty_Sixteen
|
13 |
+
* @since Twenty Sixteen 1.0
|
14 |
+
*/
|
15 |
+
?>
|
16 |
+
|
17 |
+
<!-- Standard Twenty Sixteen article header output -->
|
18 |
+
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
19 |
+
<header class="entry-header">
|
20 |
+
<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
|
21 |
+
<span class="sticky-post"><?php _e( 'Featured', 'twentysixteen' ); ?></span>
|
22 |
+
<?php endif; ?>
|
23 |
+
|
24 |
+
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
|
25 |
+
</header><!-- .entry-header -->
|
26 |
+
|
27 |
+
<?php twentysixteen_excerpt(); ?>
|
28 |
+
|
29 |
+
|
30 |
+
<!-- TYPES TIP: Custom call to Types function to render a custom image field "Book Cover" -->
|
31 |
+
<?php echo types_render_field( "book-cover", array( "size" => "thumbnail" ) ); ?>
|
32 |
+
|
33 |
+
<div class="entry-content">
|
34 |
+
<?php
|
35 |
+
/* translators: %s: Name of current post */
|
36 |
+
the_content( sprintf(
|
37 |
+
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
38 |
+
get_the_title()
|
39 |
+
) );
|
40 |
+
|
41 |
+
wp_link_pages( array(
|
42 |
+
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>',
|
43 |
+
'after' => '</div>',
|
44 |
+
'link_before' => '<span>',
|
45 |
+
'link_after' => '</span>',
|
46 |
+
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%',
|
47 |
+
'separator' => '<span class="screen-reader-text">, </span>',
|
48 |
+
) );
|
49 |
+
?>
|
50 |
+
|
51 |
+
|
52 |
+
<!-- TYPES TIP: Custom call to Types function to render a custom field "Number of pages" -->
|
53 |
+
<p><strong>Number of pages:</strong> <?php echo types_render_field( "number-of-pages"); ?></p>
|
54 |
+
|
55 |
+
|
56 |
+
<!-- TYPES TIP: Custom code to load and display contents of the parent ("Writer") post -->
|
57 |
+
<?php
|
58 |
+
// Get the ID of the parent post, which belongs to the "Writer" post type
|
59 |
+
$writer_id = wpcf_pr_post_get_belongs( get_the_ID(), 'writer' );
|
60 |
+
|
61 |
+
// Get all the parent (writer) post data
|
62 |
+
$writer_post = get_post( $writer_id );
|
63 |
+
|
64 |
+
// Get the title of the parent (writer) post
|
65 |
+
$writer_name = $writer_post->post_title;
|
66 |
+
|
67 |
+
// Get the contents of the parent (writer) post
|
68 |
+
$writer_content = $writer_post->post_content;
|
69 |
+
?>
|
70 |
+
<!-- After loading the data of the parent post we display it using our custom HTML structure -->
|
71 |
+
<div class="writer">
|
72 |
+
<h5>Author: <?php echo $writer_name; ?></h5>
|
73 |
+
<div class="writer-description"><?php echo $writer_content; ?></div>
|
74 |
+
|
75 |
+
<!-- We can use the "post_id" argument with the types_render_field function to get a custom field of any post -->
|
76 |
+
<div class="writer-photo"><?php echo types_render_field( 'author-image', array( 'post_id' => $writer_id, 'size' => 'thumbnail' ) );
|
77 |
+
?></div>
|
78 |
+
|
79 |
+
<br class="clear">
|
80 |
+
</div>
|
81 |
+
|
82 |
+
|
83 |
+
</div><!-- .entry-content -->
|
84 |
+
|
85 |
+
<!-- Standard Twenty Sixteen content footer output -->
|
86 |
+
<footer class="entry-footer">
|
87 |
+
<?php twentysixteen_entry_meta(); ?>
|
88 |
+
<?php
|
89 |
+
edit_post_link(
|
90 |
+
sprintf(
|
91 |
+
/* translators: %s: Name of current post */
|
92 |
+
__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
93 |
+
get_the_title()
|
94 |
+
),
|
95 |
+
'<span class="edit-link">',
|
96 |
+
'</span>'
|
97 |
+
);
|
98 |
+
?>
|
99 |
+
</footer><!-- .entry-footer -->
|
100 |
+
</article><!-- #post-## -->
|
101 |
+
|
examples/content-consultant.php
CHANGED
@@ -1,83 +1,83 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* This example file is a part of the Types plugin online documentation found at: https://wp-types.com/documentation/customizing-sites-using-php/
|
4 |
-
* It is based on the original Twenty Sixteen theme's template part file for displaying single items.
|
5 |
-
* It features additional code to render custom fields created with the Types plugin.
|
6 |
-
*
|
7 |
-
* Please note that the names of the custom fields are for example purposes only and will not work in your site as-is. You need to edit this example according to the documentation mentioned above.
|
8 |
-
*
|
9 |
-
* The template part for displaying Consultant post content
|
10 |
-
*
|
11 |
-
* @package WordPress
|
12 |
-
* @subpackage Twenty_Sixteen
|
13 |
-
* @since Twenty Sixteen 1.0
|
14 |
-
*/
|
15 |
-
?>
|
16 |
-
|
17 |
-
<!-- Standard Twenty Sixteen article header output -->
|
18 |
-
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
19 |
-
<header class="entry-header">
|
20 |
-
<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
|
21 |
-
<span class="sticky-post"><?php _e( 'Featured', 'twentysixteen' ); ?></span>
|
22 |
-
<?php endif; ?>
|
23 |
-
|
24 |
-
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
|
25 |
-
</header><!-- .entry-header -->
|
26 |
-
|
27 |
-
<?php twentysixteen_excerpt(); ?>
|
28 |
-
|
29 |
-
|
30 |
-
<!-- TYPES TIP: Custom call to Types function to render a custom field "Consultant Photo" -->
|
31 |
-
<?php echo types_render_field( "consultant-photo", array( "size" => "thumbnail" )); ?>
|
32 |
-
|
33 |
-
|
34 |
-
<div class="entry-content">
|
35 |
-
|
36 |
-
<!-- TYPES TIP: Custom call to get_the_term_list function to display a list of taxonomy terms that the current "Consultant" post belongs to -->
|
37 |
-
<?php echo get_the_term_list( $post->ID, 'spoken-language', '<p><strong>Spoken languages: </strong>', ', ', '</p>'); ?>
|
38 |
-
|
39 |
-
|
40 |
-
<!-- TYPES TIP: Custom call to Types function to render a custom field "Consultant Roles" -->
|
41 |
-
<p><strong>Role: <?php echo types_render_field( "consultant-roles" ); // Call to Types function for rendering a custom field "Consultant Roles" ?></strong></p>
|
42 |
-
|
43 |
-
|
44 |
-
<!-- Standard Twenty Sixteen content output -->
|
45 |
-
<?php
|
46 |
-
/* translators: %s: Name of current post */
|
47 |
-
the_content( sprintf(
|
48 |
-
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
49 |
-
get_the_title()
|
50 |
-
) );
|
51 |
-
|
52 |
-
wp_link_pages( array(
|
53 |
-
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>',
|
54 |
-
'after' => '</div>',
|
55 |
-
'link_before' => '<span>',
|
56 |
-
'link_after' => '</span>',
|
57 |
-
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%',
|
58 |
-
'separator' => '<span class="screen-reader-text">, </span>',
|
59 |
-
) );
|
60 |
-
?>
|
61 |
-
|
62 |
-
|
63 |
-
<!-- TYPES TIP: Custom call to Types function to render a custom field "Consultant Contact Phone" -->
|
64 |
-
<p><strong>Contact Phone: <?php echo types_render_field( "consultant-phone-number"); ?></strong></p>
|
65 |
-
</div><!-- .entry-content -->
|
66 |
-
|
67 |
-
|
68 |
-
<!-- Standard Twenty Sixteen content footer output -->
|
69 |
-
<footer class="entry-footer">
|
70 |
-
<?php twentysixteen_entry_meta(); ?>
|
71 |
-
<?php
|
72 |
-
edit_post_link(
|
73 |
-
sprintf(
|
74 |
-
/* translators: %s: Name of current post */
|
75 |
-
__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
76 |
-
get_the_title()
|
77 |
-
),
|
78 |
-
'<span class="edit-link">',
|
79 |
-
'</span>'
|
80 |
-
);
|
81 |
-
?>
|
82 |
-
</footer><!-- .entry-footer -->
|
83 |
</article><!-- #post-## -->
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* This example file is a part of the Types plugin online documentation found at: https://wp-types.com/documentation/customizing-sites-using-php/
|
4 |
+
* It is based on the original Twenty Sixteen theme's template part file for displaying single items.
|
5 |
+
* It features additional code to render custom fields created with the Types plugin.
|
6 |
+
*
|
7 |
+
* Please note that the names of the custom fields are for example purposes only and will not work in your site as-is. You need to edit this example according to the documentation mentioned above.
|
8 |
+
*
|
9 |
+
* The template part for displaying Consultant post content
|
10 |
+
*
|
11 |
+
* @package WordPress
|
12 |
+
* @subpackage Twenty_Sixteen
|
13 |
+
* @since Twenty Sixteen 1.0
|
14 |
+
*/
|
15 |
+
?>
|
16 |
+
|
17 |
+
<!-- Standard Twenty Sixteen article header output -->
|
18 |
+
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
19 |
+
<header class="entry-header">
|
20 |
+
<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
|
21 |
+
<span class="sticky-post"><?php _e( 'Featured', 'twentysixteen' ); ?></span>
|
22 |
+
<?php endif; ?>
|
23 |
+
|
24 |
+
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
|
25 |
+
</header><!-- .entry-header -->
|
26 |
+
|
27 |
+
<?php twentysixteen_excerpt(); ?>
|
28 |
+
|
29 |
+
|
30 |
+
<!-- TYPES TIP: Custom call to Types function to render a custom field "Consultant Photo" -->
|
31 |
+
<?php echo types_render_field( "consultant-photo", array( "size" => "thumbnail" )); ?>
|
32 |
+
|
33 |
+
|
34 |
+
<div class="entry-content">
|
35 |
+
|
36 |
+
<!-- TYPES TIP: Custom call to get_the_term_list function to display a list of taxonomy terms that the current "Consultant" post belongs to -->
|
37 |
+
<?php echo get_the_term_list( $post->ID, 'spoken-language', '<p><strong>Spoken languages: </strong>', ', ', '</p>'); ?>
|
38 |
+
|
39 |
+
|
40 |
+
<!-- TYPES TIP: Custom call to Types function to render a custom field "Consultant Roles" -->
|
41 |
+
<p><strong>Role: <?php echo types_render_field( "consultant-roles" ); // Call to Types function for rendering a custom field "Consultant Roles" ?></strong></p>
|
42 |
+
|
43 |
+
|
44 |
+
<!-- Standard Twenty Sixteen content output -->
|
45 |
+
<?php
|
46 |
+
/* translators: %s: Name of current post */
|
47 |
+
the_content( sprintf(
|
48 |
+
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
49 |
+
get_the_title()
|
50 |
+
) );
|
51 |
+
|
52 |
+
wp_link_pages( array(
|
53 |
+
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>',
|
54 |
+
'after' => '</div>',
|
55 |
+
'link_before' => '<span>',
|
56 |
+
'link_after' => '</span>',
|
57 |
+
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%',
|
58 |
+
'separator' => '<span class="screen-reader-text">, </span>',
|
59 |
+
) );
|
60 |
+
?>
|
61 |
+
|
62 |
+
|
63 |
+
<!-- TYPES TIP: Custom call to Types function to render a custom field "Consultant Contact Phone" -->
|
64 |
+
<p><strong>Contact Phone: <?php echo types_render_field( "consultant-phone-number"); ?></strong></p>
|
65 |
+
</div><!-- .entry-content -->
|
66 |
+
|
67 |
+
|
68 |
+
<!-- Standard Twenty Sixteen content footer output -->
|
69 |
+
<footer class="entry-footer">
|
70 |
+
<?php twentysixteen_entry_meta(); ?>
|
71 |
+
<?php
|
72 |
+
edit_post_link(
|
73 |
+
sprintf(
|
74 |
+
/* translators: %s: Name of current post */
|
75 |
+
__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
76 |
+
get_the_title()
|
77 |
+
),
|
78 |
+
'<span class="edit-link">',
|
79 |
+
'</span>'
|
80 |
+
);
|
81 |
+
?>
|
82 |
+
</footer><!-- .entry-footer -->
|
83 |
</article><!-- #post-## -->
|
examples/content-house.php
CHANGED
@@ -1,131 +1,131 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* This example file is a part of the Types plugin online documentation found at: https://wp-types.com/documentation/customizing-sites-using-php/
|
4 |
-
* It is based on the original Twenty Sixteen theme's template part file for displaying single items.
|
5 |
-
* It features additional code to render custom fields created with the Types plugin, including an image gallery created with images from the repeating image field.
|
6 |
-
*
|
7 |
-
* Please note that the names of the custom fields are for example purposes only and will not work in your site as-is. You need to edit this example according to the documentation mentioned above.
|
8 |
-
*
|
9 |
-
* The template part for displaying single House posts
|
10 |
-
*
|
11 |
-
* @package WordPress
|
12 |
-
* @subpackage Twenty_Sixteen
|
13 |
-
* @since Twenty Sixteen 1.0
|
14 |
-
*/
|
15 |
-
?>
|
16 |
-
|
17 |
-
<!-- Standard Twenty Sixteen article header output -->
|
18 |
-
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
19 |
-
<header class="entry-header">
|
20 |
-
<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
|
21 |
-
<span class="sticky-post"><?php _e( 'Featured', 'twentysixteen' ); ?></span>
|
22 |
-
<?php endif; ?>
|
23 |
-
|
24 |
-
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
|
25 |
-
</header><!-- .entry-header -->
|
26 |
-
|
27 |
-
<?php twentysixteen_excerpt(); ?>
|
28 |
-
|
29 |
-
|
30 |
-
<!-- TYPES TIP: Custom call to Types function to render a custom image field "House Photos". We used the "index" attribute to display only the first, representative photo of a house. -->
|
31 |
-
<?php echo types_render_field( "house-photos", array( "size"=>"thumbnail", "index" => "0" ) ); ?>
|
32 |
-
|
33 |
-
|
34 |
-
<div class="entry-content">
|
35 |
-
|
36 |
-
<!-- Standard Twenty Sixteen content output -->
|
37 |
-
<?php
|
38 |
-
/* translators: %s: Name of current post */
|
39 |
-
the_content( sprintf(
|
40 |
-
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
41 |
-
get_the_title()
|
42 |
-
) );
|
43 |
-
|
44 |
-
wp_link_pages( array(
|
45 |
-
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>',
|
46 |
-
'after' => '</div>',
|
47 |
-
'link_before' => '<span>',
|
48 |
-
'link_after' => '</span>',
|
49 |
-
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%',
|
50 |
-
'separator' => '<span class="screen-reader-text">, </span>',
|
51 |
-
) );
|
52 |
-
?>
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
<!-- TYPES TIP: Custom call to Types function to render a custom field "Size" belonging to a "Houses" post type -->
|
57 |
-
<p><strong>Size:</strong> <?php echo types_render_field( "size" ); ?></p>
|
58 |
-
|
59 |
-
<!-- TYPES TIP: Custom call to Types function to render a custom field "Area" belonging to a "Houses" post type -->
|
60 |
-
<p><strong>Area:</strong> <?php echo types_render_field( "area" ); ?></p>
|
61 |
-
|
62 |
-
<!-- TYPES TIP: Custom code to load Types function and render a REPEATING custom field "House Photos" but with each output thumbnail image also linking to the full-size image file (for lightbox effect, for example). -->
|
63 |
-
<p><strong>Property Photos</strong></p>
|
64 |
-
|
65 |
-
<?php
|
66 |
-
// Do nothing if we don't have Types.
|
67 |
-
if( apply_filters( 'types_is_active', false ) ) {
|
68 |
-
|
69 |
-
$output = '';
|
70 |
-
|
71 |
-
// ID of the current post
|
72 |
-
$post_id = get_the_ID();
|
73 |
-
|
74 |
-
// Slug of a Types repeating image field, without the "wpcf-" prefix.
|
75 |
-
$field_slug = 'house-photos'; // TODO set the field slug you want to display
|
76 |
-
|
77 |
-
// Parameters that define the field
|
78 |
-
$field_definition = wpcf_fields_get_field_by_slug( $field_slug );
|
79 |
-
if( ! empty( $field_definition ) ) {
|
80 |
-
|
81 |
-
// Get the raw field data.
|
82 |
-
$images = get_post_meta( $post_id, "wpcf-{$field_slug}" );
|
83 |
-
|
84 |
-
foreach( $images as $image_index => $image ) {
|
85 |
-
|
86 |
-
// Parameters for the Types field rendering mechanism.
|
87 |
-
$image_parameters = array(
|
88 |
-
'proportional' => 'true',
|
89 |
-
'url' => 'true',
|
90 |
-
'field_value' => $image
|
91 |
-
);
|
92 |
-
|
93 |
-
// Get an image of specific (maximum) proportions.
|
94 |
-
// NOTE: Update image size to your needs
|
95 |
-
$thumbnail_parameters = array_merge( $image_parameters, array( 'width' => '200', 'height' => '200' ) );
|
96 |
-
$thumbnail_url = types_render_field_single( $field_definition, $thumbnail_parameters, null, '', $image_index );
|
97 |
-
|
98 |
-
// Get the image in full size.
|
99 |
-
$fullsize_parameters = array_merge( $image_parameters, array( 'size' => 'full' ) );
|
100 |
-
$fullsize_url = types_render_field_single( $field_definition, $fullsize_parameters, null, '', $image_index );
|
101 |
-
|
102 |
-
// Append the markup (a thumbnail linking to the full image) to existing content.
|
103 |
-
// NOTE: Customize the output to your needs
|
104 |
-
$output .= sprintf(
|
105 |
-
'<div class="img"><a href=" '. $fullsize_url .' "><img src=" '. $thumbnail_url .' "></a></div>'
|
106 |
-
);
|
107 |
-
}
|
108 |
-
}
|
109 |
-
|
110 |
-
echo $output;
|
111 |
-
}
|
112 |
-
?>
|
113 |
-
|
114 |
-
</div><!-- .entry-content -->
|
115 |
-
|
116 |
-
<!-- Continue the standard Twenty Sixteen content footer output -->
|
117 |
-
<footer class="entry-footer">
|
118 |
-
<?php twentysixteen_entry_meta(); ?>
|
119 |
-
<?php
|
120 |
-
edit_post_link(
|
121 |
-
sprintf(
|
122 |
-
/* translators: %s: Name of current post */
|
123 |
-
__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
124 |
-
get_the_title()
|
125 |
-
),
|
126 |
-
'<span class="edit-link">',
|
127 |
-
'</span>'
|
128 |
-
);
|
129 |
-
?>
|
130 |
-
</footer><!-- .entry-footer -->
|
131 |
</article><!-- #post-## -->
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* This example file is a part of the Types plugin online documentation found at: https://wp-types.com/documentation/customizing-sites-using-php/
|
4 |
+
* It is based on the original Twenty Sixteen theme's template part file for displaying single items.
|
5 |
+
* It features additional code to render custom fields created with the Types plugin, including an image gallery created with images from the repeating image field.
|
6 |
+
*
|
7 |
+
* Please note that the names of the custom fields are for example purposes only and will not work in your site as-is. You need to edit this example according to the documentation mentioned above.
|
8 |
+
*
|
9 |
+
* The template part for displaying single House posts
|
10 |
+
*
|
11 |
+
* @package WordPress
|
12 |
+
* @subpackage Twenty_Sixteen
|
13 |
+
* @since Twenty Sixteen 1.0
|
14 |
+
*/
|
15 |
+
?>
|
16 |
+
|
17 |
+
<!-- Standard Twenty Sixteen article header output -->
|
18 |
+
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
19 |
+
<header class="entry-header">
|
20 |
+
<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
|
21 |
+
<span class="sticky-post"><?php _e( 'Featured', 'twentysixteen' ); ?></span>
|
22 |
+
<?php endif; ?>
|
23 |
+
|
24 |
+
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
|
25 |
+
</header><!-- .entry-header -->
|
26 |
+
|
27 |
+
<?php twentysixteen_excerpt(); ?>
|
28 |
+
|
29 |
+
|
30 |
+
<!-- TYPES TIP: Custom call to Types function to render a custom image field "House Photos". We used the "index" attribute to display only the first, representative photo of a house. -->
|
31 |
+
<?php echo types_render_field( "house-photos", array( "size"=>"thumbnail", "index" => "0" ) ); ?>
|
32 |
+
|
33 |
+
|
34 |
+
<div class="entry-content">
|
35 |
+
|
36 |
+
<!-- Standard Twenty Sixteen content output -->
|
37 |
+
<?php
|
38 |
+
/* translators: %s: Name of current post */
|
39 |
+
the_content( sprintf(
|
40 |
+
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
41 |
+
get_the_title()
|
42 |
+
) );
|
43 |
+
|
44 |
+
wp_link_pages( array(
|
45 |
+
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>',
|
46 |
+
'after' => '</div>',
|
47 |
+
'link_before' => '<span>',
|
48 |
+
'link_after' => '</span>',
|
49 |
+
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%',
|
50 |
+
'separator' => '<span class="screen-reader-text">, </span>',
|
51 |
+
) );
|
52 |
+
?>
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
<!-- TYPES TIP: Custom call to Types function to render a custom field "Size" belonging to a "Houses" post type -->
|
57 |
+
<p><strong>Size:</strong> <?php echo types_render_field( "size" ); ?></p>
|
58 |
+
|
59 |
+
<!-- TYPES TIP: Custom call to Types function to render a custom field "Area" belonging to a "Houses" post type -->
|
60 |
+
<p><strong>Area:</strong> <?php echo types_render_field( "area" ); ?></p>
|
61 |
+
|
62 |
+
<!-- TYPES TIP: Custom code to load Types function and render a REPEATING custom field "House Photos" but with each output thumbnail image also linking to the full-size image file (for lightbox effect, for example). -->
|
63 |
+
<p><strong>Property Photos</strong></p>
|
64 |
+
|
65 |
+
<?php
|
66 |
+
// Do nothing if we don't have Types.
|
67 |
+
if( apply_filters( 'types_is_active', false ) ) {
|
68 |
+
|
69 |
+
$output = '';
|
70 |
+
|
71 |
+
// ID of the current post
|
72 |
+
$post_id = get_the_ID();
|
73 |
+
|
74 |
+
// Slug of a Types repeating image field, without the "wpcf-" prefix.
|
75 |
+
$field_slug = 'house-photos'; // TODO set the field slug you want to display
|
76 |
+
|
77 |
+
// Parameters that define the field
|
78 |
+
$field_definition = wpcf_fields_get_field_by_slug( $field_slug );
|
79 |
+
if( ! empty( $field_definition ) ) {
|
80 |
+
|
81 |
+
// Get the raw field data.
|
82 |
+
$images = get_post_meta( $post_id, "wpcf-{$field_slug}" );
|
83 |
+
|
84 |
+
foreach( $images as $image_index => $image ) {
|
85 |
+
|
86 |
+
// Parameters for the Types field rendering mechanism.
|
87 |
+
$image_parameters = array(
|
88 |
+
'proportional' => 'true',
|
89 |
+
'url' => 'true',
|
90 |
+
'field_value' => $image
|
91 |
+
);
|
92 |
+
|
93 |
+
// Get an image of specific (maximum) proportions.
|
94 |
+
// NOTE: Update image size to your needs
|
95 |
+
$thumbnail_parameters = array_merge( $image_parameters, array( 'width' => '200', 'height' => '200' ) );
|
96 |
+
$thumbnail_url = types_render_field_single( $field_definition, $thumbnail_parameters, null, '', $image_index );
|
97 |
+
|
98 |
+
// Get the image in full size.
|
99 |
+
$fullsize_parameters = array_merge( $image_parameters, array( 'size' => 'full' ) );
|
100 |
+
$fullsize_url = types_render_field_single( $field_definition, $fullsize_parameters, null, '', $image_index );
|
101 |
+
|
102 |
+
// Append the markup (a thumbnail linking to the full image) to existing content.
|
103 |
+
// NOTE: Customize the output to your needs
|
104 |
+
$output .= sprintf(
|
105 |
+
'<div class="img"><a href=" '. $fullsize_url .' "><img src=" '. $thumbnail_url .' "></a></div>'
|
106 |
+
);
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
110 |
+
echo $output;
|
111 |
+
}
|
112 |
+
?>
|
113 |
+
|
114 |
+
</div><!-- .entry-content -->
|
115 |
+
|
116 |
+
<!-- Continue the standard Twenty Sixteen content footer output -->
|
117 |
+
<footer class="entry-footer">
|
118 |
+
<?php twentysixteen_entry_meta(); ?>
|
119 |
+
<?php
|
120 |
+
edit_post_link(
|
121 |
+
sprintf(
|
122 |
+
/* translators: %s: Name of current post */
|
123 |
+
__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
124 |
+
get_the_title()
|
125 |
+
),
|
126 |
+
'<span class="edit-link">',
|
127 |
+
'</span>'
|
128 |
+
);
|
129 |
+
?>
|
130 |
+
</footer><!-- .entry-footer -->
|
131 |
</article><!-- #post-## -->
|
examples/content-writer.php
CHANGED
@@ -1,88 +1,88 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* This example file is a part of the Types plugin online documentation found at: https://wp-types.com/documentation/customizing-sites-using-php/
|
4 |
-
* It is based on the original Twenty Sixteen theme's template part file for displaying single items.
|
5 |
-
* It features additional code to render custom fields created with the Types plugin and display contents of child posts.
|
6 |
-
*
|
7 |
-
* The template part for displaying Author (Writer) post content
|
8 |
-
*
|
9 |
-
* @package WordPress
|
10 |
-
* @subpackage Twenty_Sixteen
|
11 |
-
* @since Twenty Sixteen 1.0
|
12 |
-
*/
|
13 |
-
?>
|
14 |
-
|
15 |
-
<!-- Standard Twenty Sixteen article header output -->
|
16 |
-
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
17 |
-
<header class="entry-header">
|
18 |
-
<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
|
19 |
-
<span class="sticky-post"><?php _e( 'Featured', 'twentysixteen' ); ?></span>
|
20 |
-
<?php endif; ?>
|
21 |
-
|
22 |
-
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
|
23 |
-
</header><!-- .entry-header -->
|
24 |
-
|
25 |
-
<?php twentysixteen_excerpt(); ?>
|
26 |
-
|
27 |
-
|
28 |
-
<!-- TYPES TIP: Custom call to Types function to render a custom field "Author Image" -->
|
29 |
-
<?php echo types_render_field( "author-image", array( "size" => "thumbnail" )); ?>
|
30 |
-
|
31 |
-
|
32 |
-
<div class="entry-content">
|
33 |
-
|
34 |
-
<!-- Standard Twenty Sixteen content output -->
|
35 |
-
<?php
|
36 |
-
/* translators: %s: Name of current post */
|
37 |
-
the_content( sprintf(
|
38 |
-
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
39 |
-
get_the_title()
|
40 |
-
) );
|
41 |
-
?>
|
42 |
-
|
43 |
-
|
44 |
-
<!-- TYPES TIP: Custom section to display a list of child posts ("Books"), belonging to the currently displayed parent post ("Author") -->
|
45 |
-
<h4>Books from this author</h4>
|
46 |
-
|
47 |
-
<?php
|
48 |
-
// Using the Types function to load the contents of child posts and then starting a custom loop to output them
|
49 |
-
$child_posts = types_child_posts("book"); // Load the contents of related posts in the array
|
50 |
-
foreach ($child_posts as $child_post) { // Loop through each of the child post in the array
|
51 |
-
?>
|
52 |
-
|
53 |
-
<div class="book-listing">
|
54 |
-
<h5><?php echo $child_post->post_title; // Display the post title of a current child post ?></h5>
|
55 |
-
<?php echo types_render_field( "book-cover", array( "id"=> "$child_post->ID", "size" => "thumbnail" )); // Display the image coming from a custom field of the current child post ?>
|
56 |
-
</div>
|
57 |
-
|
58 |
-
|
59 |
-
<!-- Continuation of the standard Twenty Sixteen content output -->
|
60 |
-
<?php }
|
61 |
-
wp_link_pages( array(
|
62 |
-
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>',
|
63 |
-
'after' => '</div>',
|
64 |
-
'link_before' => '<span>',
|
65 |
-
'link_after' => '</span>',
|
66 |
-
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%',
|
67 |
-
'separator' => '<span class="screen-reader-text">, </span>',
|
68 |
-
) );
|
69 |
-
?>
|
70 |
-
|
71 |
-
</div><!-- .entry-content -->
|
72 |
-
|
73 |
-
<footer class="entry-footer">
|
74 |
-
<?php twentysixteen_entry_meta(); ?>
|
75 |
-
<?php
|
76 |
-
edit_post_link(
|
77 |
-
sprintf(
|
78 |
-
/* translators: %s: Name of current post */
|
79 |
-
__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
80 |
-
get_the_title()
|
81 |
-
),
|
82 |
-
'<span class="edit-link">',
|
83 |
-
'</span>'
|
84 |
-
);
|
85 |
-
?>
|
86 |
-
</footer><!-- .entry-footer -->
|
87 |
-
</article><!-- #post-## -->
|
88 |
-
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* This example file is a part of the Types plugin online documentation found at: https://wp-types.com/documentation/customizing-sites-using-php/
|
4 |
+
* It is based on the original Twenty Sixteen theme's template part file for displaying single items.
|
5 |
+
* It features additional code to render custom fields created with the Types plugin and display contents of child posts.
|
6 |
+
*
|
7 |
+
* The template part for displaying Author (Writer) post content
|
8 |
+
*
|
9 |
+
* @package WordPress
|
10 |
+
* @subpackage Twenty_Sixteen
|
11 |
+
* @since Twenty Sixteen 1.0
|
12 |
+
*/
|
13 |
+
?>
|
14 |
+
|
15 |
+
<!-- Standard Twenty Sixteen article header output -->
|
16 |
+
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
17 |
+
<header class="entry-header">
|
18 |
+
<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
|
19 |
+
<span class="sticky-post"><?php _e( 'Featured', 'twentysixteen' ); ?></span>
|
20 |
+
<?php endif; ?>
|
21 |
+
|
22 |
+
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
|
23 |
+
</header><!-- .entry-header -->
|
24 |
+
|
25 |
+
<?php twentysixteen_excerpt(); ?>
|
26 |
+
|
27 |
+
|
28 |
+
<!-- TYPES TIP: Custom call to Types function to render a custom field "Author Image" -->
|
29 |
+
<?php echo types_render_field( "author-image", array( "size" => "thumbnail" )); ?>
|
30 |
+
|
31 |
+
|
32 |
+
<div class="entry-content">
|
33 |
+
|
34 |
+
<!-- Standard Twenty Sixteen content output -->
|
35 |
+
<?php
|
36 |
+
/* translators: %s: Name of current post */
|
37 |
+
the_content( sprintf(
|
38 |
+
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
39 |
+
get_the_title()
|
40 |
+
) );
|
41 |
+
?>
|
42 |
+
|
43 |
+
|
44 |
+
<!-- TYPES TIP: Custom section to display a list of child posts ("Books"), belonging to the currently displayed parent post ("Author") -->
|
45 |
+
<h4>Books from this author</h4>
|
46 |
+
|
47 |
+
<?php
|
48 |
+
// Using the Types function to load the contents of child posts and then starting a custom loop to output them
|
49 |
+
$child_posts = types_child_posts("book"); // Load the contents of related posts in the array
|
50 |
+
foreach ($child_posts as $child_post) { // Loop through each of the child post in the array
|
51 |
+
?>
|
52 |
+
|
53 |
+
<div class="book-listing">
|
54 |
+
<h5><?php echo $child_post->post_title; // Display the post title of a current child post ?></h5>
|
55 |
+
<?php echo types_render_field( "book-cover", array( "id"=> "$child_post->ID", "size" => "thumbnail" )); // Display the image coming from a custom field of the current child post ?>
|
56 |
+
</div>
|
57 |
+
|
58 |
+
|
59 |
+
<!-- Continuation of the standard Twenty Sixteen content output -->
|
60 |
+
<?php }
|
61 |
+
wp_link_pages( array(
|
62 |
+
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>',
|
63 |
+
'after' => '</div>',
|
64 |
+
'link_before' => '<span>',
|
65 |
+
'link_after' => '</span>',
|
66 |
+
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%',
|
67 |
+
'separator' => '<span class="screen-reader-text">, </span>',
|
68 |
+
) );
|
69 |
+
?>
|
70 |
+
|
71 |
+
</div><!-- .entry-content -->
|
72 |
+
|
73 |
+
<footer class="entry-footer">
|
74 |
+
<?php twentysixteen_entry_meta(); ?>
|
75 |
+
<?php
|
76 |
+
edit_post_link(
|
77 |
+
sprintf(
|
78 |
+
/* translators: %s: Name of current post */
|
79 |
+
__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
80 |
+
get_the_title()
|
81 |
+
),
|
82 |
+
'<span class="edit-link">',
|
83 |
+
'</span>'
|
84 |
+
);
|
85 |
+
?>
|
86 |
+
</footer><!-- .entry-footer -->
|
87 |
+
</article><!-- #post-## -->
|
88 |
+
|
examples/single-consultant.php
CHANGED
@@ -1,129 +1,129 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* This example file is a part of the Types plugin online documentation found at: https://wp-types.com/documentation/customizing-sites-using-php/
|
4 |
-
* It is based on the original Twenty Sixteen theme's single.php file.
|
5 |
-
* It does not use template parts, but loads the post contents directly.
|
6 |
-
* It also features additional code to render custom fields created with the Types plugin.
|
7 |
-
*
|
8 |
-
* Please note that the names of the custom fields are for example purposes only and will not work in your site as-is. You need to edit this example according to the documentation mentioned above.
|
9 |
-
*
|
10 |
-
* The template for displaying single "Consultant" posts
|
11 |
-
*
|
12 |
-
* @package WordPress
|
13 |
-
* @subpackage Twenty_Sixteen
|
14 |
-
* @since Twenty Sixteen 1.0
|
15 |
-
*/
|
16 |
-
|
17 |
-
get_header(); ?>
|
18 |
-
|
19 |
-
<div id="primary" class="content-area">
|
20 |
-
<main id="main" class="site-main" role="main">
|
21 |
-
<?php
|
22 |
-
// Start the loop.
|
23 |
-
while ( have_posts() ) : the_post();
|
24 |
-
?>
|
25 |
-
|
26 |
-
<!-- Standard Twenty Sixteen article header output -->
|
27 |
-
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
28 |
-
<header class="entry-header">
|
29 |
-
<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
|
30 |
-
<span class="sticky-post"><?php _e( 'Featured', 'twentysixteen' ); ?></span>
|
31 |
-
<?php endif; ?>
|
32 |
-
|
33 |
-
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
|
34 |
-
</header><!-- .entry-header -->
|
35 |
-
|
36 |
-
<?php twentysixteen_excerpt(); ?>
|
37 |
-
|
38 |
-
|
39 |
-
<!-- TYPES TIP: Custom call to Types function to render a custom field "Consultant Photo" -->
|
40 |
-
<?php echo types_render_field( "consultant-photo", array( "size" => "thumbnail" )); ?>
|
41 |
-
|
42 |
-
|
43 |
-
<div class="entry-content">
|
44 |
-
|
45 |
-
|
46 |
-
<!-- TYPES TIP: Custom call to get_the_term_list function to display a list of taxonomy terms that the current "Consultant" post belongs to -->
|
47 |
-
<?php echo get_the_term_list( $post->ID, 'spoken-language', '<p><strong>Spoken languages: </strong>', ', ', '</p>'); ?>
|
48 |
-
|
49 |
-
<!-- TYPES TIP: Custom call to Types function to render a custom field "Consultant Roles" -->
|
50 |
-
<p><strong>Role: <?php echo types_render_field( "consultant-roles" ); // Call to Types function for rendering a custom field "Consultant Roles" ?></strong></p>
|
51 |
-
|
52 |
-
|
53 |
-
<!-- Standard Twenty Sixteen content output -->
|
54 |
-
<?php
|
55 |
-
/* translators: %s: Name of current post */
|
56 |
-
the_content( sprintf(
|
57 |
-
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
58 |
-
get_the_title()
|
59 |
-
) );
|
60 |
-
|
61 |
-
wp_link_pages( array(
|
62 |
-
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>',
|
63 |
-
'after' => '</div>',
|
64 |
-
'link_before' => '<span>',
|
65 |
-
'link_after' => '</span>',
|
66 |
-
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%',
|
67 |
-
'separator' => '<span class="screen-reader-text">, </span>',
|
68 |
-
) );
|
69 |
-
?>
|
70 |
-
|
71 |
-
<!-- TYPES TIP: Custom call to Types function to render a custom field "Consultant Contact Phone" -->
|
72 |
-
<p><strong>Contact Phone: <?php echo types_render_field( "consultant-phone-number"); ?></strong></p>
|
73 |
-
</div><!-- .entry-content -->
|
74 |
-
|
75 |
-
<!-- Standard Twenty Sixteen content footer output -->
|
76 |
-
<footer class="entry-footer">
|
77 |
-
<?php twentysixteen_entry_meta(); ?>
|
78 |
-
<?php
|
79 |
-
edit_post_link(
|
80 |
-
sprintf(
|
81 |
-
/* translators: %s: Name of current post */
|
82 |
-
__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
83 |
-
get_the_title()
|
84 |
-
),
|
85 |
-
'<span class="edit-link">',
|
86 |
-
'</span>'
|
87 |
-
);
|
88 |
-
?>
|
89 |
-
</footer><!-- .entry-footer -->
|
90 |
-
</article><!-- #post-## -->
|
91 |
-
|
92 |
-
|
93 |
-
<?php
|
94 |
-
// TYPES TIP: all of the lines below this point are the standard part of a single.php of the Twenty Sixteen theme.
|
95 |
-
|
96 |
-
// If comments are open or we have at least one comment, load up the comment template.
|
97 |
-
if ( comments_open() || get_comments_number() ) {
|
98 |
-
comments_template();
|
99 |
-
}
|
100 |
-
|
101 |
-
if ( is_singular( 'attachment' ) ) {
|
102 |
-
// Parent post navigation.
|
103 |
-
the_post_navigation( array(
|
104 |
-
'prev_text' => _x( '<span class="meta-nav">Published in</span><span class="post-title">%title</span>', 'Parent post link', 'twentysixteen' ),
|
105 |
-
) );
|
106 |
-
} elseif ( is_singular( 'post' ) ) {
|
107 |
-
// Previous/next post navigation.
|
108 |
-
the_post_navigation( array(
|
109 |
-
'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentysixteen' ) . '</span> ' .
|
110 |
-
'<span class="screen-reader-text">' . __( 'Next post:', 'twentysixteen' ) . '</span> ' .
|
111 |
-
'<span class="post-title">%title</span>',
|
112 |
-
'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentysixteen' ) . '</span> ' .
|
113 |
-
'<span class="screen-reader-text">' . __( 'Previous post:', 'twentysixteen' ) . '</span> ' .
|
114 |
-
'<span class="post-title">%title</span>',
|
115 |
-
) );
|
116 |
-
}
|
117 |
-
|
118 |
-
// End of the loop.
|
119 |
-
endwhile;
|
120 |
-
?>
|
121 |
-
|
122 |
-
</main><!-- .site-main -->
|
123 |
-
|
124 |
-
<?php get_sidebar( 'content-bottom' ); ?>
|
125 |
-
|
126 |
-
</div><!-- .content-area -->
|
127 |
-
|
128 |
-
<?php get_sidebar(); ?>
|
129 |
-
<?php get_footer(); ?>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* This example file is a part of the Types plugin online documentation found at: https://wp-types.com/documentation/customizing-sites-using-php/
|
4 |
+
* It is based on the original Twenty Sixteen theme's single.php file.
|
5 |
+
* It does not use template parts, but loads the post contents directly.
|
6 |
+
* It also features additional code to render custom fields created with the Types plugin.
|
7 |
+
*
|
8 |
+
* Please note that the names of the custom fields are for example purposes only and will not work in your site as-is. You need to edit this example according to the documentation mentioned above.
|
9 |
+
*
|
10 |
+
* The template for displaying single "Consultant" posts
|
11 |
+
*
|
12 |
+
* @package WordPress
|
13 |
+
* @subpackage Twenty_Sixteen
|
14 |
+
* @since Twenty Sixteen 1.0
|
15 |
+
*/
|
16 |
+
|
17 |
+
get_header(); ?>
|
18 |
+
|
19 |
+
<div id="primary" class="content-area">
|
20 |
+
<main id="main" class="site-main" role="main">
|
21 |
+
<?php
|
22 |
+
// Start the loop.
|
23 |
+
while ( have_posts() ) : the_post();
|
24 |
+
?>
|
25 |
+
|
26 |
+
<!-- Standard Twenty Sixteen article header output -->
|
27 |
+
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
28 |
+
<header class="entry-header">
|
29 |
+
<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
|
30 |
+
<span class="sticky-post"><?php _e( 'Featured', 'twentysixteen' ); ?></span>
|
31 |
+
<?php endif; ?>
|
32 |
+
|
33 |
+
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
|
34 |
+
</header><!-- .entry-header -->
|
35 |
+
|
36 |
+
<?php twentysixteen_excerpt(); ?>
|
37 |
+
|
38 |
+
|
39 |
+
<!-- TYPES TIP: Custom call to Types function to render a custom field "Consultant Photo" -->
|
40 |
+
<?php echo types_render_field( "consultant-photo", array( "size" => "thumbnail" )); ?>
|
41 |
+
|
42 |
+
|
43 |
+
<div class="entry-content">
|
44 |
+
|
45 |
+
|
46 |
+
<!-- TYPES TIP: Custom call to get_the_term_list function to display a list of taxonomy terms that the current "Consultant" post belongs to -->
|
47 |
+
<?php echo get_the_term_list( $post->ID, 'spoken-language', '<p><strong>Spoken languages: </strong>', ', ', '</p>'); ?>
|
48 |
+
|
49 |
+
<!-- TYPES TIP: Custom call to Types function to render a custom field "Consultant Roles" -->
|
50 |
+
<p><strong>Role: <?php echo types_render_field( "consultant-roles" ); // Call to Types function for rendering a custom field "Consultant Roles" ?></strong></p>
|
51 |
+
|
52 |
+
|
53 |
+
<!-- Standard Twenty Sixteen content output -->
|
54 |
+
<?php
|
55 |
+
/* translators: %s: Name of current post */
|
56 |
+
the_content( sprintf(
|
57 |
+
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
58 |
+
get_the_title()
|
59 |
+
) );
|
60 |
+
|
61 |
+
wp_link_pages( array(
|
62 |
+
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>',
|
63 |
+
'after' => '</div>',
|
64 |
+
'link_before' => '<span>',
|
65 |
+
'link_after' => '</span>',
|
66 |
+
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%',
|
67 |
+
'separator' => '<span class="screen-reader-text">, </span>',
|
68 |
+
) );
|
69 |
+
?>
|
70 |
+
|
71 |
+
<!-- TYPES TIP: Custom call to Types function to render a custom field "Consultant Contact Phone" -->
|
72 |
+
<p><strong>Contact Phone: <?php echo types_render_field( "consultant-phone-number"); ?></strong></p>
|
73 |
+
</div><!-- .entry-content -->
|
74 |
+
|
75 |
+
<!-- Standard Twenty Sixteen content footer output -->
|
76 |
+
<footer class="entry-footer">
|
77 |
+
<?php twentysixteen_entry_meta(); ?>
|
78 |
+
<?php
|
79 |
+
edit_post_link(
|
80 |
+
sprintf(
|
81 |
+
/* translators: %s: Name of current post */
|
82 |
+
__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
|
83 |
+
get_the_title()
|
84 |
+
),
|
85 |
+
'<span class="edit-link">',
|
86 |
+
'</span>'
|
87 |
+
);
|
88 |
+
?>
|
89 |
+
</footer><!-- .entry-footer -->
|
90 |
+
</article><!-- #post-## -->
|
91 |
+
|
92 |
+
|
93 |
+
<?php
|
94 |
+
// TYPES TIP: all of the lines below this point are the standard part of a single.php of the Twenty Sixteen theme.
|
95 |
+
|
96 |
+
// If comments are open or we have at least one comment, load up the comment template.
|
97 |
+
if ( comments_open() || get_comments_number() ) {
|
98 |
+
comments_template();
|
99 |
+
}
|
100 |
+
|
101 |
+
if ( is_singular( 'attachment' ) ) {
|
102 |
+
// Parent post navigation.
|
103 |
+
the_post_navigation( array(
|
104 |
+
'prev_text' => _x( '<span class="meta-nav">Published in</span><span class="post-title">%title</span>', 'Parent post link', 'twentysixteen' ),
|
105 |
+
) );
|
106 |
+
} elseif ( is_singular( 'post' ) ) {
|
107 |
+
// Previous/next post navigation.
|
108 |
+
the_post_navigation( array(
|
109 |
+
'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentysixteen' ) . '</span> ' .
|
110 |
+
'<span class="screen-reader-text">' . __( 'Next post:', 'twentysixteen' ) . '</span> ' .
|
111 |
+
'<span class="post-title">%title</span>',
|
112 |
+
'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentysixteen' ) . '</span> ' .
|
113 |
+
'<span class="screen-reader-text">' . __( 'Previous post:', 'twentysixteen' ) . '</span> ' .
|
114 |
+
'<span class="post-title">%title</span>',
|
115 |
+
) );
|
116 |
+
}
|
117 |
+
|
118 |
+
// End of the loop.
|
119 |
+
endwhile;
|
120 |
+
?>
|
121 |
+
|
122 |
+
</main><!-- .site-main -->
|
123 |
+
|
124 |
+
<?php get_sidebar( 'content-bottom' ); ?>
|
125 |
+
|
126 |
+
</div><!-- .content-area -->
|
127 |
+
|
128 |
+
<?php get_sidebar(); ?>
|
129 |
+
<?php get_footer(); ?>
|
library/otgs/installer/changelog.txt
CHANGED
@@ -1,150 +1,150 @@
|
|
1 |
-
= 1.7.13 =
|
2 |
-
* Added sanitization for some inputs
|
3 |
-
* Fixed PHP notice being logged when installing a plugin from the WP plugins directory
|
4 |
-
|
5 |
-
= 1.7.12 =
|
6 |
-
* Allow to set the site keys in PHP (as constants)
|
7 |
-
* Fixed an issue with unregistered sites gets wrong info (or error) when clicking "View version x.y.x details" link
|
8 |
-
|
9 |
-
= 1.7.11 =
|
10 |
-
* Fixed styling for 'must-register' warnings on the plugins page
|
11 |
-
|
12 |
-
= 1.7.10 =
|
13 |
-
* Fixed a notice that was appearing when the site key registration failed
|
14 |
-
|
15 |
-
= 1.7.9 =
|
16 |
-
* Save the client_id value from the site_key_validation API call response and make it available via WP_Installer_API::get_ts_client_id API call
|
17 |
-
|
18 |
-
= 1.7.8 =
|
19 |
-
* Small fix for hiding the WPML registration notice
|
20 |
-
|
21 |
-
= 1.7.7 =
|
22 |
-
* Fixed js error showing up during registration
|
23 |
-
* Styles update for unified WPML messages
|
24 |
-
|
25 |
-
= 1.7.6 =
|
26 |
-
* Updated error messages when validating site keys and stopped removing site keys in case of communication errors
|
27 |
-
* Added a note for users who renewed or purchased new subscriptions and who need to revalidate their subscription from their websites
|
28 |
-
* Fixed a problem with the registrations for multi-site setups when WordPress was installed in a separate folder
|
29 |
-
|
30 |
-
= 1.7.5 =
|
31 |
-
* Fixed a bug causing registration to not be recognized for the entire network in the multi-site mode
|
32 |
-
|
33 |
-
= 1.7.4 =
|
34 |
-
* Use https for wp-types API
|
35 |
-
|
36 |
-
= 1.7.3 =
|
37 |
-
* Added a dependencies class and check for the windows paths length exception
|
38 |
-
* Bug fix: all downloads showed up twice on the plugins list whe upgrading from WPML 3.3
|
39 |
-
|
40 |
-
= 1.7.2 =
|
41 |
-
* Added an exception to handle the case when Types embedded is installer from Toolset Installer and its included Installer version overrides the one running the Toolset setup wizard
|
42 |
-
|
43 |
-
= 1.7.1 =
|
44 |
-
* Added an exception for the case of Types 1.8.9 (Installer 1.7.0) together with older WPML (older Installer)
|
45 |
-
|
46 |
-
= 1.7.0 =
|
47 |
-
* New format for the products data file.
|
48 |
-
* Other fixes
|
49 |
-
|
50 |
-
= 1.6.8 =
|
51 |
-
* Sanitized an input that was a potential security issue
|
52 |
-
|
53 |
-
= 1.6.7 =
|
54 |
-
* Fixed a bug causing repeated calls to the Toolset api to validate the user subscription
|
55 |
-
* Use https for API urls
|
56 |
-
|
57 |
-
= 1.6.6 =
|
58 |
-
* Fixed the 'Call to undefined function get_plugins()' issue
|
59 |
-
|
60 |
-
= 1.6.5 =
|
61 |
-
* Added configuration file for composer
|
62 |
-
* Updated how free plugins are shown on the plugins list (commercial tab)
|
63 |
-
* API calls for manipulating translation service preferences
|
64 |
-
* Support for hosting custom Installer packages on wpml.org
|
65 |
-
* Fixed a warning that was showing when using the OTGS_DISABLE_AUTO_UPDATES constant before any product data was downloaded
|
66 |
-
* Changed the frequency with which product updates are checked automatically (24 hours)
|
67 |
-
* Improved reporting for version numbers
|
68 |
-
|
69 |
-
= 1.6.4 =
|
70 |
-
* Enabled the OTGS_DISABLE_AUTO_UPDATES constant for theme update checks
|
71 |
-
* Fixed a bug that was causing Register links to show for all installed plugins
|
72 |
-
|
73 |
-
= 1.6.3 =
|
74 |
-
* Fixed performance issue related to themes upgrade logic
|
75 |
-
|
76 |
-
= 1.6 =
|
77 |
-
* Improved the way plugins are matched: not just by the folder name (slug) but also by name
|
78 |
-
* Added support for installing and upgrading themes from repositories (currently: Toolset themes)
|
79 |
-
* Added support for 'alias' plugins on the toolset and wpml repositories (currently: Types)
|
80 |
-
* Enhanced the progress animation during plugins downloading
|
81 |
-
|
82 |
-
= 1.5.6 =
|
83 |
-
* Updated the translations
|
84 |
-
* Fix for WPML 3.2 conditional upgrade logic
|
85 |
-
|
86 |
-
= 1.5.5 =
|
87 |
-
* Fixed the logic for the high_priority parameter
|
88 |
-
* Fixed js bug causing a conflict with NextGen
|
89 |
-
* Fixed bug preventing users to install and upgrade Types when they didn't have a Toolset subscription
|
90 |
-
* Fixed bug preventing users to upgrade from the embedded Types to the full version
|
91 |
-
|
92 |
-
= 1.5.4 =
|
93 |
-
* Option to disable auto-updates
|
94 |
-
* Escaped urls generated with add_query_arg
|
95 |
-
|
96 |
-
= 1.5.3 =
|
97 |
-
* Fixed bug in WP_Installer::custom_plugins_api_call (filter for plugins_api) causing conflicts with other filters for plugins_api
|
98 |
-
|
99 |
-
= 1.5.2 =
|
100 |
-
* More meaningful errors when plugin downloads fail
|
101 |
-
* WordPress 4.2 compatibility
|
102 |
-
* Performance improvements (will not load in places where it's not needed and not make unnecessary requests to the CDN)
|
103 |
-
* Support putting deps.xml config file in the theme folder (root)
|
104 |
-
* Included code for importing data for toolset plugins
|
105 |
-
* Use CloudFront urls for products list files
|
106 |
-
|
107 |
-
= 1.5.1 =
|
108 |
-
* Fix for allowing embedded plugins to be updated
|
109 |
-
* Logic for the migration from embedded plugins to full plugins
|
110 |
-
|
111 |
-
= 1.5 =
|
112 |
-
* Support for embedded plugins
|
113 |
-
* Bug fix: When user registers site key with trailing slash, downloads might not work
|
114 |
-
* Tweak: Set a higher timeout limit for the http requests to CDN and API
|
115 |
-
* API function: link to specific repository
|
116 |
-
* API function: get product price
|
117 |
-
* New method for defining affiliate info (with backwards compatibility)
|
118 |
-
|
119 |
-
= 1.4 =
|
120 |
-
* Show explicit error in case of connectivity issues while validating a key.
|
121 |
-
* Bug fix: Downloading plugins in bulk was broken by plugin that had a redirect after activation
|
122 |
-
* Display friendly error message when WordPress does not have permissions to write to the plugins folder
|
123 |
-
* Added support for configuration files to auto-download required plugins and theme keys
|
124 |
-
* Changed the "Update this info" button to "Check for updates" (it refreshes the subscription info and checks for updates)
|
125 |
-
* Support for high_priority parameter that allows setting priority for an Installer instance when more with the same version number exist.
|
126 |
-
* Config files from different instances are combined (define repositories in different instances)
|
127 |
-
* Updated support for conditional updates display for ICL users
|
128 |
-
* More friendly error reporting and handling when using an invalid site key or the plugins archives are not valid.
|
129 |
-
|
130 |
-
|
131 |
-
= 1.3.1 =
|
132 |
-
* Support for conditional release notification (ICanLocalize)
|
133 |
-
|
134 |
-
= 1.3 =
|
135 |
-
* Added a new repository: Toolset
|
136 |
-
* The product packages can be displayed hierarchically and ordered
|
137 |
-
* The link to automatically create site keys will follow through login on the account site (e.g. wpml.org, wp-types.com)
|
138 |
-
* Fixed animation issues (not showing in most browsers) when downloading plugins.
|
139 |
-
* Created an admin screen on the repository end (icl-mpp) to sho registration stats (site keys, site keys usage, components usage etc..).
|
140 |
-
* Bug fix: Renew and Upgrade buttons were not entirely clickable
|
141 |
-
* Bug fix: Action buttons (buy, renew, upgrade) were not displayed correctly when WPML was not active (Installer embedded in theme)
|
142 |
-
* Support for site-wide registration. Products can be registered on the network instead of on each site separately.
|
143 |
-
* Users are able to add either http or https version for any site urls. There will be one site key that will work with both http and https versions.
|
144 |
-
|
145 |
-
= 1.2 =
|
146 |
-
* Added pagination for site keys list of Account -> My Sites
|
147 |
-
* Reversed the order in which the site keys are displayed.
|
148 |
-
* Fixed problem with WPML registration information (site key) not being saved when the option_value field in the wp_options table used a different charset than the default WordPress charset defined in wp-config.php
|
149 |
-
* Allow registering new sites by clicking a link in the WordPress admin instead of copying and pasting the site url in the Account -> My Sites section
|
150 |
-
* Display more detailed debug information related to connectivity issues with the WPML repository
|
1 |
+
= 1.7.13 =
|
2 |
+
* Added sanitization for some inputs
|
3 |
+
* Fixed PHP notice being logged when installing a plugin from the WP plugins directory
|
4 |
+
|
5 |
+
= 1.7.12 =
|
6 |
+
* Allow to set the site keys in PHP (as constants)
|
7 |
+
* Fixed an issue with unregistered sites gets wrong info (or error) when clicking "View version x.y.x details" link
|
8 |
+
|
9 |
+
= 1.7.11 =
|
10 |
+
* Fixed styling for 'must-register' warnings on the plugins page
|
11 |
+
|
12 |
+
= 1.7.10 =
|
13 |
+
* Fixed a notice that was appearing when the site key registration failed
|
14 |
+
|
15 |
+
= 1.7.9 =
|
16 |
+
* Save the client_id value from the site_key_validation API call response and make it available via WP_Installer_API::get_ts_client_id API call
|
17 |
+
|
18 |
+
= 1.7.8 =
|
19 |
+
* Small fix for hiding the WPML registration notice
|
20 |
+
|
21 |
+
= 1.7.7 =
|
22 |
+
* Fixed js error showing up during registration
|
23 |
+
* Styles update for unified WPML messages
|
24 |
+
|
25 |
+
= 1.7.6 =
|
26 |
+
* Updated error messages when validating site keys and stopped removing site keys in case of communication errors
|
27 |
+
* Added a note for users who renewed or purchased new subscriptions and who need to revalidate their subscription from their websites
|
28 |
+
* Fixed a problem with the registrations for multi-site setups when WordPress was installed in a separate folder
|
29 |
+
|
30 |
+
= 1.7.5 =
|
31 |
+
* Fixed a bug causing registration to not be recognized for the entire network in the multi-site mode
|
32 |
+
|
33 |
+
= 1.7.4 =
|
34 |
+
* Use https for wp-types API
|
35 |
+
|
36 |
+
= 1.7.3 =
|
37 |
+
* Added a dependencies class and check for the windows paths length exception
|
38 |
+
* Bug fix: all downloads showed up twice on the plugins list whe upgrading from WPML 3.3
|
39 |
+
|
40 |
+
= 1.7.2 =
|
41 |
+
* Added an exception to handle the case when Types embedded is installer from Toolset Installer and its included Installer version overrides the one running the Toolset setup wizard
|
42 |
+
|
43 |
+
= 1.7.1 =
|
44 |
+
* Added an exception for the case of Types 1.8.9 (Installer 1.7.0) together with older WPML (older Installer)
|
45 |
+
|
46 |
+
= 1.7.0 =
|
47 |
+
* New format for the products data file.
|
48 |
+
* Other fixes
|
49 |
+
|
50 |
+
= 1.6.8 =
|
51 |
+
* Sanitized an input that was a potential security issue
|
52 |
+
|
53 |
+
= 1.6.7 =
|
54 |
+
* Fixed a bug causing repeated calls to the Toolset api to validate the user subscription
|
55 |
+
* Use https for API urls
|
56 |
+
|
57 |
+
= 1.6.6 =
|
58 |
+
* Fixed the 'Call to undefined function get_plugins()' issue
|
59 |
+
|
60 |
+
= 1.6.5 =
|
61 |
+
* Added configuration file for composer
|
62 |
+
* Updated how free plugins are shown on the plugins list (commercial tab)
|
63 |
+
* API calls for manipulating translation service preferences
|
64 |
+
* Support for hosting custom Installer packages on wpml.org
|
65 |
+
* Fixed a warning that was showing when using the OTGS_DISABLE_AUTO_UPDATES constant before any product data was downloaded
|
66 |
+
* Changed the frequency with which product updates are checked automatically (24 hours)
|
67 |
+
* Improved reporting for version numbers
|
68 |
+
|
69 |
+
= 1.6.4 =
|
70 |
+
* Enabled the OTGS_DISABLE_AUTO_UPDATES constant for theme update checks
|
71 |
+
* Fixed a bug that was causing Register links to show for all installed plugins
|
72 |
+
|
73 |
+
= 1.6.3 =
|
74 |
+
* Fixed performance issue related to themes upgrade logic
|
75 |
+
|
76 |
+
= 1.6 =
|
77 |
+
* Improved the way plugins are matched: not just by the folder name (slug) but also by name
|
78 |
+
* Added support for installing and upgrading themes from repositories (currently: Toolset themes)
|
79 |
+
* Added support for 'alias' plugins on the toolset and wpml repositories (currently: Types)
|
80 |
+
* Enhanced the progress animation during plugins downloading
|
81 |
+
|
82 |
+
= 1.5.6 =
|
83 |
+
* Updated the translations
|
84 |
+
* Fix for WPML 3.2 conditional upgrade logic
|
85 |
+
|
86 |
+
= 1.5.5 =
|
87 |
+
* Fixed the logic for the high_priority parameter
|
88 |
+
* Fixed js bug causing a conflict with NextGen
|
89 |
+
* Fixed bug preventing users to install and upgrade Types when they didn't have a Toolset subscription
|
90 |
+
* Fixed bug preventing users to upgrade from the embedded Types to the full version
|
91 |
+
|
92 |
+
= 1.5.4 =
|
93 |
+
* Option to disable auto-updates
|
94 |
+
* Escaped urls generated with add_query_arg
|
95 |
+
|
96 |
+
= 1.5.3 =
|
97 |
+
* Fixed bug in WP_Installer::custom_plugins_api_call (filter for plugins_api) causing conflicts with other filters for plugins_api
|
98 |
+
|
99 |
+
= 1.5.2 =
|
100 |
+
* More meaningful errors when plugin downloads fail
|
101 |
+
* WordPress 4.2 compatibility
|
102 |
+
* Performance improvements (will not load in places where it's not needed and not make unnecessary requests to the CDN)
|
103 |
+
* Support putting deps.xml config file in the theme folder (root)
|
104 |
+
* Included code for importing data for toolset plugins
|
105 |
+
* Use CloudFront urls for products list files
|
106 |
+
|
107 |
+
= 1.5.1 =
|
108 |
+
* Fix for allowing embedded plugins to be updated
|
109 |
+
* Logic for the migration from embedded plugins to full plugins
|
110 |
+
|
111 |
+
= 1.5 =
|
112 |
+
* Support for embedded plugins
|
113 |
+
* Bug fix: When user registers site key with trailing slash, downloads might not work
|
114 |
+
* Tweak: Set a higher timeout limit for the http requests to CDN and API
|
115 |
+
* API function: link to specific repository
|
116 |
+
* API function: get product price
|
117 |
+
* New method for defining affiliate info (with backwards compatibility)
|
118 |
+
|
119 |
+
= 1.4 =
|
120 |
+
* Show explicit error in case of connectivity issues while validating a key.
|
121 |
+
* Bug fix: Downloading plugins in bulk was broken by plugin that had a redirect after activation
|
122 |
+
* Display friendly error message when WordPress does not have permissions to write to the plugins folder
|
123 |
+
* Added support for configuration files to auto-download required plugins and theme keys
|
124 |
+
* Changed the "Update this info" button to "Check for updates" (it refreshes the subscription info and checks for updates)
|
125 |
+
* Support for high_priority parameter that allows setting priority for an Installer instance when more with the same version number exist.
|
126 |
+
* Config files from different instances are combined (define repositories in different instances)
|
127 |
+
* Updated support for conditional updates display for ICL users
|
128 |
+
* More friendly error reporting and handling when using an invalid site key or the plugins archives are not valid.
|
129 |
+
|
130 |
+
|
131 |
+
= 1.3.1 =
|
132 |
+
* Support for conditional release notification (ICanLocalize)
|
133 |
+
|
134 |
+
= 1.3 =
|
135 |
+
* Added a new repository: Toolset
|
136 |
+
* The product packages can be displayed hierarchically and ordered
|
137 |
+
* The link to automatically create site keys will follow through login on the account site (e.g. wpml.org, wp-types.com)
|
138 |
+
* Fixed animation issues (not showing in most browsers) when downloading plugins.
|
139 |
+
* Created an admin screen on the repository end (icl-mpp) to sho registration stats (site keys, site keys usage, components usage etc..).
|
140 |
+
* Bug fix: Renew and Upgrade buttons were not entirely clickable
|
141 |
+
* Bug fix: Action buttons (buy, renew, upgrade) were not displayed correctly when WPML was not active (Installer embedded in theme)
|
142 |
+
* Support for site-wide registration. Products can be registered on the network instead of on each site separately.
|
143 |
+
* Users are able to add either http or https version for any site urls. There will be one site key that will work with both http and https versions.
|
144 |
+
|
145 |
+
= 1.2 =
|
146 |
+
* Added pagination for site keys list of Account -> My Sites
|
147 |
+
* Reversed the order in which the site keys are displayed.
|
148 |
+
* Fixed problem with WPML registration information (site key) not being saved when the option_value field in the wp_options table used a different charset than the default WordPress charset defined in wp-config.php
|
149 |
+
* Allow registering new sites by clicking a link in the WordPress admin instead of copying and pasting the site url in the Account -> My Sites section
|
150 |
+
* Display more detailed debug information related to connectivity issues with the WPML repository
|
library/otgs/installer/includes/class-installer-dependencies.php
CHANGED
@@ -1,278 +1,278 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Installer_Dependencies{
|
4 |
-
|
5 |
-
private $uploading_allowed = null;
|
6 |
-
private $is_win_paths_exception = array();
|
7 |
-
|
8 |
-
|
9 |
-
function __construct(){
|
10 |
-
|
11 |
-
add_action( 'admin_init', array( $this, 'prevent_plugins_update_on_plugins_page' ), 100);
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
global $pagenow;
|
16 |
-
if($pagenow == 'update.php'){
|
17 |
-
if(isset($_GET['action']) && $_GET['action'] == 'update-selected'){
|
18 |
-
add_action('admin_head', array($this, 'prevent_plugins_update_on_updates_screen')); //iframe/bulk
|
19 |
-
}else{
|
20 |
-
add_action('all_admin_notices', array($this, 'prevent_plugins_update_on_updates_screen')); //regular/singular
|
21 |
-
}
|
22 |
-
}
|
23 |
-
add_action('wp_ajax_update-plugin', array($this, 'prevent_plugins_update_on_updates_screen'), 0); // high priority, before WP
|
24 |
-
|
25 |
-
}
|
26 |
-
|
27 |
-
public function is_win_paths_exception($repository_id){
|
28 |
-
|
29 |
-
if(!isset($this->is_win_paths_exception[$repository_id])) {
|
30 |
-
|
31 |
-
$this->is_win_paths_exception[$repository_id] = false;
|
32 |
-
|
33 |
-
if ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) {
|
34 |
-
|
35 |
-
$windows_max_path_length = 256;
|
36 |
-
$longest_path['wpml'] = 109;
|
37 |
-
$longest_path['toolset'] = 99;
|
38 |
-
|
39 |
-
$margin = 15;
|
40 |
-
|
41 |
-
$upgrade_path_length = strlen( WP_CONTENT_DIR . '/upgrade' );
|
42 |
-
|
43 |
-
$installer_settings = WP_Installer()->settings;
|
44 |
-
|
45 |
-
if ( is_array( $installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'] ) ) {
|
46 |
-
$a_plugin = current( $installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'] );
|
47 |
-
$url = WP_Installer()->append_site_key_to_download_url( $a_plugin['url'], 'xxxxxx', $repository_id );
|
48 |
-
$tmpfname = wp_tempnam( $url );
|
49 |
-
|
50 |
-
$tmpname_length = strlen( basename( $tmpfname ) ) - 4; // -.tmp
|
51 |
-
|
52 |
-
if ( $upgrade_path_length + $tmpname_length + $longest_path[$repository_id] + $margin > $windows_max_path_length ) {
|
53 |
-
|
54 |
-
$this->is_win_paths_exception[$repository_id] = true;
|
55 |
-
|
56 |
-
}
|
57 |
-
|
58 |
-
}
|
59 |
-
|
60 |
-
|
61 |
-
}
|
62 |
-
|
63 |
-
}
|
64 |
-
|
65 |
-
return $this->is_win_paths_exception[$repository_id];
|
66 |
-
|
67 |
-
}
|
68 |
-
|
69 |
-
public function is_uploading_allowed(){
|
70 |
-
|
71 |
-
if(!isset($this->uploading_allowed)){
|
72 |
-
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
73 |
-
require_once WP_Installer()->plugin_path() . '/includes/installer-upgrader-skins.php';
|
74 |
-
|
75 |
-
$upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin
|
76 |
-
$upgrader = new Plugin_Upgrader($upgrader_skins);
|
77 |
-
|
78 |
-
ob_start();
|
79 |
-
$res = $upgrader->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) );
|
80 |
-
ob_end_clean();
|
81 |
-
|
82 |
-
if ( ! $res || is_wp_error( $res ) ) {
|
83 |
-
$this->uploading_allowed = false;
|
84 |
-
}else{
|
85 |
-
$this->uploading_allowed = true;
|
86 |
-
}
|
87 |
-
}
|
88 |
-
|
89 |
-
return $this->uploading_allowed;
|
90 |
-
|
91 |
-
}
|
92 |
-
|
93 |
-
public function cant_download($repository_id){
|
94 |
-
|
95 |
-
return !$this->is_uploading_allowed() || $this->is_win_paths_exception($repository_id);
|
96 |
-
|
97 |
-
}
|
98 |
-
|
99 |
-
public function win_paths_exception_message(){
|
100 |
-
return __('Downloading is not possible. WordPress cannot create required folders because of the
|
101 |
-
256 characters limitation of the current Windows environment.', 'installer');
|
102 |
-
}
|
103 |
-
|
104 |
-
public function prevent_plugins_update_on_plugins_page(){
|
105 |
-
|
106 |
-
$plugins = get_site_transient( 'update_plugins' );
|
107 |
-
if ( isset($plugins->response) && is_array($plugins->response) ) {
|
108 |
-
$plugins_with_updates = array_keys( $plugins->response );
|
109 |
-
}
|
110 |
-
|
111 |
-
if( !empty($plugins_with_updates) ) {
|
112 |
-
|
113 |
-
$plugins = get_plugins();
|
114 |
-
|
115 |
-
$installer_settings = WP_Installer()->settings;
|
116 |
-
foreach ($installer_settings['repositories'] as $repository_id => $repository) {
|
117 |
-
|
118 |
-
if ($this->is_win_paths_exception($repository_id)) {
|
119 |
-
|
120 |
-
$repositories_plugins = array();
|
121 |
-
foreach ($repository['data']['packages'] as $package) {
|
122 |
-
foreach ($package['products'] as $product) {
|
123 |
-
foreach ($product['plugins'] as $plugin_slug) {
|
124 |
-
$download = $installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
125 |
-
if ( empty($download['free-on-wporg']) ) {
|
126 |
-
$repositories_plugins[$download['slug']] = $download['name'];
|
127 |
-
}
|
128 |
-
}
|
129 |
-
}
|
130 |
-
}
|
131 |
-
|
132 |
-
foreach ($plugins as $plugin_id => $plugin) {
|
133 |
-
|
134 |
-
if( in_array( $plugin_id, $plugins_with_updates ) ) {
|
135 |
-
|
136 |
-
$wp_plugin_slug = dirname($plugin_id);
|
137 |
-
if (empty($wp_plugin_slug)) {
|
138 |
-
$wp_plugin_slug = basename($plugin_id, '.php');
|
139 |
-
}
|
140 |
-
|
141 |
-
foreach ($repositories_plugins as $slug => $name) {
|
142 |
-
if ($wp_plugin_slug == $slug || $name == $plugin['Name'] || $name == $plugin['Title']) { //match order: slug, name, title
|
143 |
-
|
144 |
-
remove_action("after_plugin_row_$plugin_id", 'wp_plugin_update_row', 10, 2);
|
145 |
-
add_action("after_plugin_row_$plugin_id", array($this, 'wp_plugin_update_row_win_exception'), 10, 2);
|
146 |
-
|
147 |
-
}
|
148 |
-
}
|
149 |
-
|
150 |
-
}
|
151 |
-
|
152 |
-
}
|
153 |
-
|
154 |
-
}
|
155 |
-
|
156 |
-
|
157 |
-
}
|
158 |
-
|
159 |
-
}
|
160 |
-
|
161 |
-
}
|
162 |
-
|
163 |
-
public function wp_plugin_update_row_win_exception(){
|
164 |
-
$wp_list_table = _get_list_table('WP_Plugins_List_Table');
|
165 |
-
echo '<tr class="plugin-update-tr">';
|
166 |
-
echo '<td class="plugin-update colspanchange" colspan="' . esc_attr( $wp_list_table->get_column_count() ) .
|
167 |
-
'"><div class="update-message">' . $this->win_paths_exception_message() . '</div></td>';
|
168 |
-
echo '</tr>';
|
169 |
-
}
|
170 |
-
|
171 |
-
public function prevent_plugins_update_on_updates_screen(){
|
172 |
-
|
173 |
-
if ( isset($_REQUEST['action']) ) {
|
174 |
-
|
175 |
-
$action = isset($_REQUEST['action']) ? sanitize_text_field ( $_REQUEST['action'] ) : '';
|
176 |
-
|
177 |
-
$installer_settings = WP_Installer()->settings;
|
178 |
-
|
179 |
-
//bulk mode
|
180 |
-
if('update-selected' == $action) {
|
181 |
-
|
182 |
-
global $plugins;
|
183 |
-
|
184 |
-
if(isset($plugins) && is_array($plugins)) {
|
185 |
-
|
186 |
-
foreach ($plugins as $k => $plugin) {
|
187 |
-
|
188 |
-
$wp_plugin_slug = dirname($plugin);
|
189 |
-
|
190 |
-
foreach ($installer_settings['repositories'] as $repository_id => $repository) {
|
191 |
-
|
192 |
-
if( $this->is_win_paths_exception($repository_id) ){
|
193 |
-
|
194 |
-
foreach ($repository['data']['packages'] as $package) {
|
195 |
-
|
196 |
-
foreach ($package['products'] as $product) {
|
197 |
-
|
198 |
-
foreach ($product['plugins'] as $plugin_slug) {
|
199 |
-
|
200 |
-
$download = $installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
201 |
-
|
202 |
-
if ($download['slug'] == $wp_plugin_slug && empty($download['free-on-wporg']) ) {
|
203 |
-
|
204 |
-
echo '<div class="updated error"><p>' . $this->win_paths_exception_message() .
|
205 |
-
' <strong>(' . $download['name'] . ')</strong>' . '</p></div>';
|
206 |
-
unset($plugins[$k]);
|
207 |
-
|
208 |
-
break(3);
|
209 |
-
|
210 |
-
}
|
211 |
-
|
212 |
-
}
|
213 |
-
|
214 |
-
}
|
215 |
-
|
216 |
-
}
|
217 |
-
|
218 |
-
|
219 |
-
}
|
220 |
-
|
221 |
-
}
|
222 |
-
|
223 |
-
}
|
224 |
-
|
225 |
-
}
|
226 |
-
|
227 |
-
}
|
228 |
-
|
229 |
-
|
230 |
-
if( 'upgrade-plugin' == $action || 'update-plugin' == $action ) {
|
231 |
-
|
232 |
-
$plugin = isset($_REQUEST['plugin']) ? trim( sanitize_text_field ( $_REQUEST['plugin'] ) ) : '';
|
233 |
-
|
234 |
-
$wp_plugin_slug = dirname($plugin);
|
235 |
-
|
236 |
-
foreach($installer_settings['repositories'] as $repository_id => $repository){
|
237 |
-
|
238 |
-
if( $this->is_win_paths_exception( $repository_id ) ) {
|
239 |
-
foreach ($repository['data']['packages'] as $package) {
|
240 |
-
|
241 |
-
foreach($package['products'] as $product) {
|
242 |
-
|
243 |
-
foreach($product['plugins'] as $plugin_slug) {
|
244 |
-
$download = $installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
245 |
-
|
246 |
-
//match by folder, will change to match by name and folder
|
247 |
-
if ( $download['slug'] == $wp_plugin_slug && empty ($download['free-on-wporg'] ) ) {
|
248 |
-
|
249 |
-
echo '<div class="updated error"><p>' . $this->win_paths_exception_message() . '</p></div>';
|
250 |
-
|
251 |
-
echo '<div class="wrap">';
|
252 |
-
echo '<h2>' . __('Update Plugin') . '</h2>';
|
253 |
-
echo '<a href="' . admin_url('update-core.php') . '">' . __('Return to the updates page', 'installer') . '</a>';
|
254 |
-
echo '</div>';
|
255 |
-
require_once(ABSPATH . 'wp-admin/admin-footer.php');
|
256 |
-
exit;
|
257 |
-
|
258 |
-
}
|
259 |
-
|
260 |
-
}
|
261 |
-
|
262 |
-
}
|
263 |
-
|
264 |
-
}
|
265 |
-
}
|
266 |
-
|
267 |
-
}
|
268 |
-
|
269 |
-
}
|
270 |
-
}
|
271 |
-
|
272 |
-
}
|
273 |
-
|
274 |
-
|
275 |
-
}
|
276 |
-
|
277 |
-
|
278 |
-
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Installer_Dependencies{
|
4 |
+
|
5 |
+
private $uploading_allowed = null;
|
6 |
+
private $is_win_paths_exception = array();
|
7 |
+
|
8 |
+
|
9 |
+
function __construct(){
|
10 |
+
|
11 |
+
add_action( 'admin_init', array( $this, 'prevent_plugins_update_on_plugins_page' ), 100);
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
global $pagenow;
|
16 |
+
if($pagenow == 'update.php'){
|
17 |
+
if(isset($_GET['action']) && $_GET['action'] == 'update-selected'){
|
18 |
+
add_action('admin_head', array($this, 'prevent_plugins_update_on_updates_screen')); //iframe/bulk
|
19 |
+
}else{
|
20 |
+
add_action('all_admin_notices', array($this, 'prevent_plugins_update_on_updates_screen')); //regular/singular
|
21 |
+
}
|
22 |
+
}
|
23 |
+
add_action('wp_ajax_update-plugin', array($this, 'prevent_plugins_update_on_updates_screen'), 0); // high priority, before WP
|
24 |
+
|
25 |
+
}
|
26 |
+
|
27 |
+
public function is_win_paths_exception($repository_id){
|
28 |
+
|
29 |
+
if(!isset($this->is_win_paths_exception[$repository_id])) {
|
30 |
+
|
31 |
+
$this->is_win_paths_exception[$repository_id] = false;
|
32 |
+
|
33 |
+
if ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) {
|
34 |
+
|
35 |
+
$windows_max_path_length = 256;
|
36 |
+
$longest_path['wpml'] = 109;
|
37 |
+
$longest_path['toolset'] = 99;
|
38 |
+
|
39 |
+
$margin = 15;
|
40 |
+
|
41 |
+
$upgrade_path_length = strlen( WP_CONTENT_DIR . '/upgrade' );
|
42 |
+
|
43 |
+
$installer_settings = WP_Installer()->settings;
|
44 |
+
|
45 |
+
if ( is_array( $installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'] ) ) {
|
46 |
+
$a_plugin = current( $installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'] );
|
47 |
+
$url = WP_Installer()->append_site_key_to_download_url( $a_plugin['url'], 'xxxxxx', $repository_id );
|
48 |
+
$tmpfname = wp_tempnam( $url );
|
49 |
+
|
50 |
+
$tmpname_length = strlen( basename( $tmpfname ) ) - 4; // -.tmp
|
51 |
+
|
52 |
+
if ( $upgrade_path_length + $tmpname_length + $longest_path[$repository_id] + $margin > $windows_max_path_length ) {
|
53 |
+
|
54 |
+
$this->is_win_paths_exception[$repository_id] = true;
|
55 |
+
|
56 |
+
}
|
57 |
+
|
58 |
+
}
|
59 |
+
|
60 |
+
|
61 |
+
}
|
62 |
+
|
63 |
+
}
|
64 |
+
|
65 |
+
return $this->is_win_paths_exception[$repository_id];
|
66 |
+
|
67 |
+
}
|
68 |
+
|
69 |
+
public function is_uploading_allowed(){
|
70 |
+
|
71 |
+
if(!isset($this->uploading_allowed)){
|
72 |
+
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
73 |
+
require_once WP_Installer()->plugin_path() . '/includes/installer-upgrader-skins.php';
|
74 |
+
|
75 |
+
$upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin
|
76 |
+
$upgrader = new Plugin_Upgrader($upgrader_skins);
|
77 |
+
|
78 |
+
ob_start();
|
79 |
+
$res = $upgrader->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) );
|
80 |
+
ob_end_clean();
|
81 |
+
|
82 |
+
if ( ! $res || is_wp_error( $res ) ) {
|
83 |
+
$this->uploading_allowed = false;
|
84 |
+
}else{
|
85 |
+
$this->uploading_allowed = true;
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
return $this->uploading_allowed;
|
90 |
+
|
91 |
+
}
|
92 |
+
|
93 |
+
public function cant_download($repository_id){
|
94 |
+
|
95 |
+
return !$this->is_uploading_allowed() || $this->is_win_paths_exception($repository_id);
|
96 |
+
|
97 |
+
}
|
98 |
+
|
99 |
+
public function win_paths_exception_message(){
|
100 |
+
return __('Downloading is not possible. WordPress cannot create required folders because of the
|
101 |
+
256 characters limitation of the current Windows environment.', 'installer');
|
102 |
+
}
|
103 |
+
|
104 |
+
public function prevent_plugins_update_on_plugins_page(){
|
105 |
+
|
106 |
+
$plugins = get_site_transient( 'update_plugins' );
|
107 |
+
if ( isset($plugins->response) && is_array($plugins->response) ) {
|
108 |
+
$plugins_with_updates = array_keys( $plugins->response );
|
109 |
+
}
|
110 |
+
|
111 |
+
if( !empty($plugins_with_updates) ) {
|
112 |
+
|
113 |
+
$plugins = get_plugins();
|
114 |
+
|
115 |
+
$installer_settings = WP_Installer()->settings;
|
116 |
+
foreach ($installer_settings['repositories'] as $repository_id => $repository) {
|
117 |
+
|
118 |
+
if ($this->is_win_paths_exception($repository_id)) {
|
119 |
+
|
120 |
+
$repositories_plugins = array();
|
121 |
+
foreach ($repository['data']['packages'] as $package) {
|
122 |
+
foreach ($package['products'] as $product) {
|
123 |
+
foreach ($product['plugins'] as $plugin_slug) {
|
124 |
+
$download = $installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
125 |
+
if ( empty($download['free-on-wporg']) ) {
|
126 |
+
$repositories_plugins[$download['slug']] = $download['name'];
|
127 |
+
}
|
128 |
+
}
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
foreach ($plugins as $plugin_id => $plugin) {
|
133 |
+
|
134 |
+
if( in_array( $plugin_id, $plugins_with_updates ) ) {
|
135 |
+
|
136 |
+
$wp_plugin_slug = dirname($plugin_id);
|
137 |
+
if (empty($wp_plugin_slug)) {
|
138 |
+
$wp_plugin_slug = basename($plugin_id, '.php');
|
139 |
+
}
|
140 |
+
|
141 |
+
foreach ($repositories_plugins as $slug => $name) {
|
142 |
+
if ($wp_plugin_slug == $slug || $name == $plugin['Name'] || $name == $plugin['Title']) { //match order: slug, name, title
|
143 |
+
|
144 |
+
remove_action("after_plugin_row_$plugin_id", 'wp_plugin_update_row', 10, 2);
|
145 |
+
add_action("after_plugin_row_$plugin_id", array($this, 'wp_plugin_update_row_win_exception'), 10, 2);
|
146 |
+
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
}
|
151 |
+
|
152 |
+
}
|
153 |
+
|
154 |
+
}
|
155 |
+
|
156 |
+
|
157 |
+
}
|
158 |
+
|
159 |
+
}
|
160 |
+
|
161 |
+
}
|
162 |
+
|
163 |
+
public function wp_plugin_update_row_win_exception(){
|
164 |
+
$wp_list_table = _get_list_table('WP_Plugins_List_Table');
|
165 |
+
echo '<tr class="plugin-update-tr">';
|
166 |
+
echo '<td class="plugin-update colspanchange" colspan="' . esc_attr( $wp_list_table->get_column_count() ) .
|
167 |
+
'"><div class="update-message">' . $this->win_paths_exception_message() . '</div></td>';
|
168 |
+
echo '</tr>';
|
169 |
+
}
|
170 |
+
|
171 |
+
public function prevent_plugins_update_on_updates_screen(){
|
172 |
+
|
173 |
+
if ( isset($_REQUEST['action']) ) {
|
174 |
+
|
175 |
+
$action = isset($_REQUEST['action']) ? sanitize_text_field ( $_REQUEST['action'] ) : '';
|
176 |
+
|
177 |
+
$installer_settings = WP_Installer()->settings;
|
178 |
+
|
179 |
+
//bulk mode
|
180 |
+
if('update-selected' == $action) {
|
181 |
+
|
182 |
+
global $plugins;
|
183 |
+
|
184 |
+
if(isset($plugins) && is_array($plugins)) {
|
185 |
+
|
186 |
+
foreach ($plugins as $k => $plugin) {
|
187 |
+
|
188 |
+
$wp_plugin_slug = dirname($plugin);
|
189 |
+
|
190 |
+
foreach ($installer_settings['repositories'] as $repository_id => $repository) {
|
191 |
+
|
192 |
+
if( $this->is_win_paths_exception($repository_id) ){
|
193 |
+
|
194 |
+
foreach ($repository['data']['packages'] as $package) {
|
195 |
+
|
196 |
+
foreach ($package['products'] as $product) {
|
197 |
+
|
198 |
+
foreach ($product['plugins'] as $plugin_slug) {
|
199 |
+
|
200 |
+
$download = $installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
201 |
+
|
202 |
+
if ($download['slug'] == $wp_plugin_slug && empty($download['free-on-wporg']) ) {
|
203 |
+
|
204 |
+
echo '<div class="updated error"><p>' . $this->win_paths_exception_message() .
|
205 |
+
' <strong>(' . $download['name'] . ')</strong>' . '</p></div>';
|
206 |
+
unset($plugins[$k]);
|
207 |
+
|
208 |
+
break(3);
|
209 |
+
|
210 |
+
}
|
211 |
+
|
212 |
+
}
|
213 |
+
|
214 |
+
}
|
215 |
+
|
216 |
+
}
|
217 |
+
|
218 |
+
|
219 |
+
}
|
220 |
+
|
221 |
+
}
|
222 |
+
|
223 |
+
}
|
224 |
+
|
225 |
+
}
|
226 |
+
|
227 |
+
}
|
228 |
+
|
229 |
+
|
230 |
+
if( 'upgrade-plugin' == $action || 'update-plugin' == $action ) {
|
231 |
+
|
232 |
+
$plugin = isset($_REQUEST['plugin']) ? trim( sanitize_text_field ( $_REQUEST['plugin'] ) ) : '';
|
233 |
+
|
234 |
+
$wp_plugin_slug = dirname($plugin);
|
235 |
+
|
236 |
+
foreach($installer_settings['repositories'] as $repository_id => $repository){
|
237 |
+
|
238 |
+
if( $this->is_win_paths_exception( $repository_id ) ) {
|
239 |
+
foreach ($repository['data']['packages'] as $package) {
|
240 |
+
|
241 |
+
foreach($package['products'] as $product) {
|
242 |
+
|
243 |
+
foreach($product['plugins'] as $plugin_slug) {
|
244 |
+
$download = $installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
245 |
+
|
246 |
+
//match by folder, will change to match by name and folder
|
247 |
+
if ( $download['slug'] == $wp_plugin_slug && empty ($download['free-on-wporg'] ) ) {
|
248 |
+
|
249 |
+
echo '<div class="updated error"><p>' . $this->win_paths_exception_message() . '</p></div>';
|
250 |
+
|
251 |
+
echo '<div class="wrap">';
|
252 |
+
echo '<h2>' . __('Update Plugin') . '</h2>';
|
253 |
+
echo '<a href="' . admin_url('update-core.php') . '">' . __('Return to the updates page', 'installer') . '</a>';
|
254 |
+
echo '</div>';
|
255 |
+
require_once(ABSPATH . 'wp-admin/admin-footer.php');
|
256 |
+
exit;
|
257 |
+
|
258 |
+
}
|
259 |
+
|
260 |
+
}
|
261 |
+
|
262 |
+
}
|
263 |
+
|
264 |
+
}
|
265 |
+
}
|
266 |
+
|
267 |
+
}
|
268 |
+
|
269 |
+
}
|
270 |
+
}
|
271 |
+
|
272 |
+
}
|
273 |
+
|
274 |
+
|
275 |
+
}
|
276 |
+
|
277 |
+
|
278 |
+
|
library/otgs/installer/includes/class-installer-theme.php
CHANGED
@@ -1,979 +1,979 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Installer Class for Theme Support
|
4 |
-
*
|
5 |
-
* Supports automatic updates and installation of Toolset/WPML Themes
|
6 |
-
*
|
7 |
-
* @class Installer_Theme_Class
|
8 |
-
* @version 1.6
|
9 |
-
* @category Class
|
10 |
-
* @author OnTheGoSystems
|
11 |
-
*/
|
12 |
-
|
13 |
-
if ( !defined( 'ABSPATH' ) ) {
|
14 |
-
exit;
|
15 |
-
}
|
16 |
-
|
17 |
-
/**
|
18 |
-
* Installer_Theme_Class
|
19 |
-
*/
|
20 |
-
class Installer_Theme_Class {
|
21 |
-
|
22 |
-
/** Theme Repository */
|
23 |
-
private $theme_repo;
|
24 |
-
|
25 |
-
/** Repository API */
|
26 |
-
private $repository_api;
|
27 |
-
|
28 |
-
/** Repository Theme Products */
|
29 |
-
private $repository_theme_products;
|
30 |
-
|
31 |
-
/** Site URL */
|
32 |
-
private $installer_site_url;
|
33 |
-
|
34 |
-
/** Site Key */
|
35 |
-
private $installer_site_key;
|
36 |
-
|
37 |
-
/** The Themes Option */
|
38 |
-
protected $installer_themes_option;
|
39 |
-
|
40 |
-
/** Update settings */
|
41 |
-
protected $installer_themes_available_updates;
|
42 |
-
|
43 |
-
/** The Themes */
|
44 |
-
protected $installer_themes = array();
|
45 |
-
|
46 |
-
/** Repository with themes */
|
47 |
-
protected $installer_repo_with_themes;
|
48 |
-
|
49 |
-
/** Active tab */
|
50 |
-
protected $installer_theme_active_tab;
|
51 |
-
|
52 |
-
/** Theme user registration */
|
53 |
-
protected $theme_user_registration;
|
54 |
-
|
55 |
-
/** Client active subscription */
|
56 |
-
protected $installer_theme_subscription_type;
|
57 |
-
|
58 |
-
public function __construct() {
|
59 |
-
|
60 |
-
/** Properties */
|
61 |
-
|
62 |
-
//Get installer repositories
|
63 |
-
$installer_repositories = WP_Installer()->get_repositories();
|
64 |
-
|
65 |
-
//Get repos with themes
|
66 |
-
$repos_with_themes = $this->installer_theme_reposities_that_has_themes( $installer_repositories );
|
67 |
-
|
68 |
-
if ( is_array( $repos_with_themes ) ) {
|
69 |
-
//Assign to property
|
70 |
-
$this->installer_repo_with_themes = $repos_with_themes;
|
71 |
-
|
72 |
-
//Let's looped through repos with themes
|
73 |
-
foreach ( $repos_with_themes as $k => $repo ) {
|
74 |
-
|
75 |
-
//$repo could be 'toolset' or 'wpml'
|
76 |
-
//Assign each repo with theme to property
|
77 |
-
$this->theme_repo[] = $repo;
|
78 |
-
|
79 |
-
if ( (isset($installer_repositories[$repo]['api-url'])) && (isset($installer_repositories[$repo]['products'])) ) {
|
80 |
-
|
81 |
-
//Define the rest of the properties based on the given repo
|
82 |
-
$this->repository_api[$repo] = $installer_repositories[$repo]['api-url'];
|
83 |
-
$this->repository_theme_products[$repo] = $installer_repositories[$repo]['products'];
|
84 |
-
$this->installer_site_url[$repo] = WP_Installer()->get_installer_site_url( $repo );
|
85 |
-
$this->installer_site_key[$repo] = WP_Installer()->get_site_key( $repo );
|
86 |
-
$this->theme_user_registration[$repo] = false;
|
87 |
-
|
88 |
-
if ( WP_Installer()->repository_has_valid_subscription( $repo ) ) {
|
89 |
-
|
90 |
-
$this->installer_theme_subscription_type = WP_Installer()->get_subscription_type_for_repository( $repo );
|
91 |
-
$this->installer_themes_option[$repo] = 'wp_installer_' . $repo . '_themes';
|
92 |
-
$this->installer_themes_available_updates[$repo] = 'wp_installer_' . $repo . '_updated_themes';
|
93 |
-
$this->installer_theme_active_tab = '';
|
94 |
-
|
95 |
-
//We only set themes available to this validated subscription
|
96 |
-
$this->installer_theme_available( $repo, $this->installer_theme_subscription_type );
|
97 |
-
|
98 |
-
add_action( 'installer_themes_support_set_up', array($this, 'installer_theme_sets_active_tab_on_init'), 10 );
|
99 |
-
$this->theme_user_registration[$repo] = true;
|
100 |
-
}
|
101 |
-
|
102 |
-
/** We are ready.. let's initialize .... */
|
103 |
-
$this->init();
|
104 |
-
}
|
105 |
-
}
|
106 |
-
add_action( 'installer_themes_support_set_up', array($this, 'installer_theme_loaded_hooks') );
|
107 |
-
}
|
108 |
-
}
|
109 |
-
|
110 |
-
/** Init */
|
111 |
-
public function init() {
|
112 |
-
add_action( 'admin_enqueue_scripts', array($this, 'installer_theme_enqueue_scripts') );
|
113 |
-
add_filter( 'themes_api', array($this, 'installer_theme_api_override'), 10, 3 );
|
114 |
-
add_filter( 'themes_api_result', array($this, 'installer_theme_api_override_response'), 10, 3 );
|
115 |
-
add_filter( 'site_transient_update_themes', array($this, 'installer_theme_upgrade_check'), 10, 1 );
|
116 |
-
add_action( 'http_api_debug', array($this, 'installer_theme_sync_native_wp_api'), 10, 5 );
|
117 |
-
add_filter( 'installer_theme_hook_response_theme', array($this, 'installer_theme_add_num_ratings'), 10, 1 );
|
118 |
-
add_filter( 'themes_update_check_locales', array($this, 'installer_theme_sync_call_wp_theme_api'), 10, 1 );
|
119 |
-
add_filter( 'admin_url', array($this, 'installer_theme_add_query_arg_tab'), 10, 3 );
|
120 |
-
add_filter( 'network_admin_url', array($this, 'installer_theme_add_query_arg_tab'), 10, 2 );
|
121 |
-
add_action( 'wp_ajax_installer_theme_frontend_selected_tab', array($this, 'installer_theme_frontend_selected_tab'), 0 );
|
122 |
-
add_action( 'wp_loaded', array($this, 'installer_themes_support_set_up_func') );
|
123 |
-
}
|
124 |
-
|
125 |
-
/** Enqueue scripts */
|
126 |
-
public function installer_theme_enqueue_scripts() {
|
127 |
-
$current_screen = $this->installer_theme_current_screen();
|
128 |
-
$commercial_plugin_screen = $this->installer_theme_is_commercial_plugin_screen( $current_screen );
|
129 |
-
if ( ('theme-install' == $current_screen) || ($commercial_plugin_screen) || ('theme-install-network' == $current_screen) ) {
|
130 |
-
$repo_with_themes = $this->installer_repo_with_themes;
|
131 |
-
$js_array = array();
|
132 |
-
if ( is_array( $repo_with_themes ) ) {
|
133 |
-
foreach ( $repo_with_themes as $k => $v ) {
|
134 |
-
|
135 |
-
//Hyperlink text
|
136 |
-
$theme_repo_name = $this->installer_theme_get_repo_product_name( $v );
|
137 |
-
$the_hyperlink_text = esc_js( $theme_repo_name );
|
138 |
-
|
139 |
-
if ( is_multisite() ) {
|
140 |
-
$admin_url_passed = network_admin_url();
|
141 |
-
} else {
|
142 |
-
$admin_url_passed = admin_url();
|
143 |
-
}
|
144 |
-
|
145 |
-
//Define
|
146 |
-
$js_array[$v] = array(
|
147 |
-
'the_hyperlink_text' => $the_hyperlink_text,
|
148 |
-
'registration_status' => $this->theme_user_registration[$v],
|
149 |
-
'is_commercial_plugin_tab' => $commercial_plugin_screen,
|
150 |
-
'registration_url' => $admin_url_passed . 'plugin-install.php?tab=commercial#installer_repo_' . $v
|
151 |
-
);
|
152 |
-
|
153 |
-
}
|
154 |
-
}
|
155 |
-
|
156 |
-
if ( !(empty($js_array)) ) {
|
157 |
-
wp_enqueue_script( 'installer-theme-install', WP_Installer()->res_url() . '/res/js/installer_theme_install.js', array('jquery', 'installer-admin'), WP_Installer()->version() );
|
158 |
-
$installer_ajax_url = admin_url( 'admin-ajax.php' );
|
159 |
-
|
160 |
-
if ( is_ssl() ) {
|
161 |
-
$installer_ajax_url = str_replace( 'http://', 'https://', $installer_ajax_url );
|
162 |
-
} else {
|
163 |
-
$installer_ajax_url = str_replace( 'https://', 'http://', $installer_ajax_url );
|
164 |
-
}
|
165 |
-
|
166 |
-
//Case where user is subscribed to a subscription that does not have themes
|
167 |
-
$subscription_js_check = $this->installer_theme_subscription_does_not_have_theme( $js_array );
|
168 |
-
|
169 |
-
wp_localize_script( 'installer-theme-install', 'installer_theme_install_localize',
|
170 |
-
array(
|
171 |
-
'js_array_installer' => $js_array,
|
172 |
-
'ajaxurl' => $installer_ajax_url,
|
173 |
-
'no_associated_themes' => $subscription_js_check,
|
174 |
-
'installer_theme_frontend_selected_tab_nonce' => wp_create_nonce( 'installer_theme_frontend_selected_tab' )
|
175 |
-
)
|
176 |
-
);
|
177 |
-
}
|
178 |
-
}
|
179 |
-
}
|
180 |
-
|
181 |
-
/** Case where user is subscribed to a subscription that does not have themes */
|
182 |
-
protected function installer_theme_subscription_does_not_have_theme( $js_array ) {
|
183 |
-
|
184 |
-
$any_subscription_has_theme = array();
|
185 |
-
$number_of_registrations = array();
|
186 |
-
|
187 |
-
//Step1, we looped through JS array
|
188 |
-
foreach ( $js_array as $repo_slug => $js_details ) {
|
189 |
-
|
190 |
-
//Step2, checked if user is registered
|
191 |
-
if ( isset($this->theme_user_registration[$repo_slug]) ) {
|
192 |
-
$registration_status = $this->theme_user_registration[$repo_slug];
|
193 |
-
if ( $registration_status ) {
|
194 |
-
|
195 |
-
//Registered
|
196 |
-
$number_of_registrations[] = $repo_slug;
|
197 |
-
|
198 |
-
//Step3, we checked if the $repo_slug has available theme
|
199 |
-
$themes_available = false;
|
200 |
-
if ( isset($this->installer_themes[$repo_slug]) ) {
|
201 |
-
$themes_available = $this->installer_themes[$repo_slug];
|
202 |
-
if ( !(empty($themes_available)) ) {
|
203 |
-
//This subscription has theme
|
204 |
-
$themes_available = true;
|
205 |
-
}
|
206 |
-
}
|
207 |
-
|
208 |
-
if ( $themes_available ) {
|
209 |
-
$any_subscription_has_theme[] = $repo_slug;
|
210 |
-
}
|
211 |
-
}
|
212 |
-
}
|
213 |
-
|
214 |
-
}
|
215 |
-
|
216 |
-
//Step4, we are done looping, check if there are any repos that have themes
|
217 |
-
if ( empty($registration_status) ) {
|
218 |
-
|
219 |
-
//No registration on any repos
|
220 |
-
return FALSE;
|
221 |
-
|
222 |
-
} elseif ( !(empty($registration_status)) ) {
|
223 |
-
|
224 |
-
//Has some registration on some repos
|
225 |
-
//We then checked if this user has any active subscriptions
|
226 |
-
if ( empty($any_subscription_has_theme) ) {
|
227 |
-
//No subscription
|
228 |
-
return TRUE;
|
229 |
-
} else {
|
230 |
-
//Has subscription found
|
231 |
-
return FALSE;
|
232 |
-
}
|
233 |
-
}
|
234 |
-
}
|
235 |
-
|
236 |
-
/** Check if its the commercial plugin screen */
|
237 |
-
private function installer_theme_is_commercial_plugin_screen( $current_screen ) {
|
238 |
-
$commercial = false;
|
239 |
-
if ( ('plugin-install' == $current_screen) || ('plugin-install-network' == $current_screen) ) {
|
240 |
-
if ( isset($_GET['tab']) ) {
|
241 |
-
$tab = sanitize_text_field( $_GET['tab'] );
|
242 |
-
if ( 'commercial' == $tab ) {
|
243 |
-
$commercial = true;
|
244 |
-
}
|
245 |
-
}
|
246 |
-
}
|
247 |
-
return $commercial;
|
248 |
-
}
|
249 |
-
|
250 |
-
/** Current screen */
|
251 |
-
private function installer_theme_current_screen() {
|
252 |
-
|
253 |
-
$current_screen_loaded = false;
|
254 |
-
|
255 |
-
if ( function_exists( 'get_current_screen' ) ) {
|
256 |
-
|
257 |
-
$screen_output = get_current_screen();
|
258 |
-
$current_screen_loaded = $screen_output->id;
|
259 |
-
|
260 |
-
}
|
261 |
-
|
262 |
-
return $current_screen_loaded;
|
263 |
-
|
264 |
-
}
|
265 |
-
|
266 |
-
/** Override WordPress Themes API */
|
267 |
-
public function installer_theme_api_override( $api_boolean, $action, $args ) {
|
268 |
-
|
269 |
-
//Let's checked if user is browsing our themes
|
270 |
-
if ( isset($args->browse) ) {
|
271 |
-
$browse = $args->browse;
|
272 |
-
if ( in_array( $browse, $this->theme_repo ) ) {
|
273 |
-
//Uniquely validated for our Themes
|
274 |
-
if ( 'query_themes' == $action ) {
|
275 |
-
//User is querying or asking information about our themes, let's override
|
276 |
-
$api_boolean = true;
|
277 |
-
}
|
278 |
-
}
|
279 |
-
} elseif ( isset($args->slug) ) {
|
280 |
-
//We are installing our themes
|
281 |
-
$theme_to_install = $args->slug;
|
282 |
-
|
283 |
-
//Lets uniquely validate if this belongs to us
|
284 |
-
//Check if this is OTGS theme
|
285 |
-
$validate_check = $this->installer_themes_belong_to_us( $theme_to_install );
|
286 |
-
if ( $validate_check ) {
|
287 |
-
//Belongs to us
|
288 |
-
if ( !(empty($theme_to_install)) ) {
|
289 |
-
$api_boolean = true;
|
290 |
-
}
|
291 |
-
}
|
292 |
-
}
|
293 |
-
|
294 |
-
return $api_boolean;
|
295 |
-
}
|
296 |
-
|
297 |
-
/** Override WordPress Themes API response with our own themes API*/
|
298 |
-
public function installer_theme_api_override_response( $res, $action, $args ) {
|
299 |
-
|
300 |
-
if ( true === $res ) {
|
301 |
-
if ( isset($args->browse) ) {
|
302 |
-
$browse = $args->browse;
|
303 |
-
if ( in_array( $browse, $this->theme_repo ) ) {
|
304 |
-
//Uniquely validated for our themes
|
305 |
-
if ( 'query_themes' == $action ) {
|
306 |
-
//Client querying OTGS themes
|
307 |
-
//Check for registration status
|
308 |
-
if ( isset($this->theme_user_registration[$browse]) ) {
|
309 |
-
//Set
|
310 |
-
if ( !($this->theme_user_registration[$browse]) ) {
|
311 |
-
//Not registered yet
|
312 |
-
$res = new stdClass();
|
313 |
-
$res->info = array();
|
314 |
-
$res->themes = array();
|
315 |
-
return $res;
|
316 |
-
} else {
|
317 |
-
//Registered
|
318 |
-
$themes = $this->installer_theme_get_themes( '', $browse );
|
319 |
-
$res = $this->installer_theme_format_response( $themes, $action );
|
320 |
-
}
|
321 |
-
}
|
322 |
-
}
|
323 |
-
}
|
324 |
-
} elseif ( isset($args->slug) ) {
|
325 |
-
//We are installing theme
|
326 |
-
//Lets uniquely validate if this belongs to our theme
|
327 |
-
$theme_to_install = $args->slug;
|
328 |
-
|
329 |
-
//Lets uniquely validate if this belongs to us
|
330 |
-
//Check if this is OTGS theme
|
331 |
-
$validate_check = $this->installer_themes_belong_to_us( $theme_to_install );
|
332 |
-
if ( $validate_check ) {
|
333 |
-
//Belongs to us
|
334 |
-
if ( ($res) && ('theme_information' == $action) ) {
|
335 |
-
$themes = $this->installer_theme_get_themes( '', $this->installer_theme_active_tab );
|
336 |
-
$res = $this->installer_theme_format_response( $themes, $action, $args->slug );
|
337 |
-
}
|
338 |
-
}
|
339 |
-
}
|
340 |
-
return $res;
|
341 |
-
} else {
|
342 |
-
//Default WP Themes here
|
343 |
-
$client_side_active_tab = get_option( 'wp_installer_clientside_active_tab' );
|
344 |
-
if ( $client_side_active_tab ) {
|
345 |
-
if ( !(in_array( $client_side_active_tab, $this->theme_repo )) ) {
|
346 |
-
//Not OTGS tab
|
347 |
-
return $res;
|
348 |
-
}
|
349 |
-
}
|
350 |
-
|
351 |
-
}
|
352 |
-
}
|
353 |
-
|
354 |
-
/** Get Themes */
|
355 |
-
private function installer_theme_get_themes( $product_url = '', $repo_source = '' ) {
|
356 |
-
|
357 |
-
//Query API
|
358 |
-
if ( empty($product_url) ) {
|
359 |
-
//Not set
|
360 |
-
if ( isset($this->repository_theme_products[$this->installer_theme_active_tab]) ) {
|
361 |
-
$query_remote_url = $this->repository_theme_products[$this->installer_theme_active_tab];
|
362 |
-
}
|
363 |
-
|
364 |
-
} else {
|
365 |
-
$query_remote_url = $product_url;
|
366 |
-
}
|
367 |
-
|
368 |
-
//Let's retrieved current installer settings so we won't be querying all the time
|
369 |
-
$current_installer_settings = WP_Installer()->get_settings();
|
370 |
-
|
371 |
-
//Set $themes to FALSE by default
|
372 |
-
$themes = false;
|
373 |
-
|
374 |
-
if ( (is_array( $current_installer_settings )) && (!(empty($current_installer_settings))) ) {
|
375 |
-
|
376 |
-
//Set and already defined, retrieved $products
|
377 |
-
if ( isset($current_installer_settings['repositories'][$repo_source]['data']) ) {
|
378 |
-
$products = $current_installer_settings['repositories'][$repo_source]['data'];
|
379 |
-
if ( isset($products['downloads']['themes']) ) {
|
380 |
-
$themes = $products['downloads']['themes'];
|
381 |
-
}
|
382 |
-
}
|
383 |
-
|
384 |
-
} else {
|
385 |
-
|
386 |
-
//Call API
|
387 |
-
$response = wp_remote_get( $query_remote_url );
|
388 |
-
|
389 |
-
if ( is_wp_error( $response ) ) {
|
390 |
-
//Error detected: http fallback
|
391 |
-
$query_remote_url = preg_replace( "@^https://@", 'http://', $query_remote_url );
|
392 |
-
$response = wp_remote_get( $query_remote_url );
|
393 |
-
}
|
394 |
-
|
395 |
-
if ( !(is_wp_error( $response )) ) {
|
396 |
-
//Not WP error
|
397 |
-
//Evaluate response
|
398 |
-
if ( $response && isset($response['response']['code']) && $response['response']['code'] == 200 ) {
|
399 |
-
//In this case, response is set and defined, proceed...
|
400 |
-
$body = wp_remote_retrieve_body( $response );
|
401 |
-
if ( $body ) {
|
402 |
-
$products = json_decode( $body, true );
|
403 |
-
if ( isset($products['downloads']['themes']) ) {
|
404 |
-
$themes = $products['downloads']['themes'];
|
405 |
-
}
|
406 |
-
}
|
407 |
-
|
408 |
-
}
|
409 |
-
}
|
410 |
-
}
|
411 |
-
|
412 |
-
//Return themes, can be filtered by user subscription type
|
413 |
-
return apply_filters( 'installer_theme_get_themes', $themes, $this->installer_theme_active_tab );
|
414 |
-
}
|
415 |
-
|
416 |
-
/** Format response in compatibility with WordPress Theme API response */
|
417 |
-
private function installer_theme_format_response( $themes, $action, $slug = '' ) {
|
418 |
-
|
419 |
-
//Let's append download link only when retrieving theme information for installation
|
420 |
-
if ( ('theme_information' == $action) && (!(empty($slug))) ) {
|
421 |
-
|
422 |
-
//Only return one result -> the theme to be installed
|
423 |
-
foreach ( $themes as $k => $theme ) {
|
424 |
-
if ( $slug == $theme['basename'] ) {
|
425 |
-
$theme['download_link'] = WP_Installer()->append_site_key_to_download_url( $theme['url'], $this->installer_site_key[$this->installer_theme_active_tab], $this->installer_theme_active_tab );
|
426 |
-
$theme = json_decode( json_encode( $theme ), FALSE );
|
427 |
-
return $theme;
|
428 |
-
}
|
429 |
-
}
|
430 |
-
|
431 |
-
} else {
|
432 |
-
|
433 |
-
$res = new stdClass();
|
434 |
-
$res->info = array();
|
435 |
-
$res->themes = array();
|
436 |
-
|
437 |
-
//Define info
|
438 |
-
$res->info['page'] = 1;
|
439 |
-
$res->info['pages'] = 10;
|
440 |
-
|
441 |
-
//Let's count available themes ;
|
442 |
-
$res->info['results'] = count( $themes );
|
443 |
-
|
444 |
-
//Let's saved themes for easy access later on
|
445 |
-
$this->installer_theme_savethemes_by_slug( $themes );
|
446 |
-
|
447 |
-
//Let's defined available themes
|
448 |
-
if ( isset($this->installer_theme_subscription_type) ) {
|
449 |
-
//Has subscription type defined, let's saved what is associated with this subscription
|
450 |
-
$this->installer_theme_available( $this->installer_theme_active_tab, $this->installer_theme_subscription_type );
|
451 |
-
} else {
|
452 |
-
$this->installer_theme_available( $this->installer_theme_active_tab );
|
453 |
-
}
|
454 |
-
|
455 |
-
//Let's add themes to the overriden WordPress API Theme response
|
456 |
-
/** Installer 1.7.6: Update to compatible data format response from WP Theme API */
|
457 |
-
$theme_compatible_array=array();
|
458 |
-
if ((is_array($themes))) {
|
459 |
-
foreach ($themes as $k=>$v) {
|
460 |
-
$theme_compatible_array[]=(object)($v);
|
461 |
-
}
|
462 |
-
}
|
463 |
-
$res->themes = $theme_compatible_array;
|
464 |
-
$res->themes = apply_filters( 'installer_theme_hook_response_theme', $res->themes );
|
465 |
-
return $res;
|
466 |
-
}
|
467 |
-
}
|
468 |
-
|
469 |
-
/** Let's save all available themes by its slug after any latest API query */
|
470 |
-
private function installer_theme_savethemes_by_slug( $themes, $doing_query = false ) {
|
471 |
-
|
472 |
-
if ( !($doing_query) ) {
|
473 |
-
$this->installer_themes[$this->installer_theme_active_tab] = array();
|
474 |
-
}
|
475 |
-
|
476 |
-
if ( !(empty($themes)) ) {
|
477 |
-
$themes_for_saving = array();
|
478 |
-
foreach ( $themes as $k => $theme ) {
|
479 |
-
if ( !($doing_query) ) {
|
480 |
-
if ( isset($theme['slug']) ) {
|
481 |
-
$theme_slug = $theme['slug'];
|
482 |
-
if ( !(empty($theme_slug)) ) {
|
483 |
-
$themes_for_saving[] = $theme_slug;
|
484 |
-
}
|
485 |
-
}
|
486 |
-
} else {
|
487 |
-
|
488 |
-
if ( ((isset($theme['slug'])) && (isset($theme['version'])) &&
|
489 |
-
(isset($theme['theme_page_url']))) && (isset($theme['url']))
|
490 |
-
) {
|
491 |
-
$theme_slug = $theme['slug'];
|
492 |
-
$theme_version = $theme['version'];
|
493 |
-
$theme_page_url = $theme['theme_page_url'];
|
494 |
-
$theme_url = $theme['url'];
|
495 |
-
if ( (!(empty($theme_slug))) && (!(empty($theme_version))) &&
|
496 |
-
(!(empty($theme_page_url))) && (!(empty($theme_url)))
|
497 |
-
) {
|
498 |
-
//$theme_slug is unique for every theme
|
499 |
-
$themes_for_saving[$theme_slug] = array(
|
500 |
-
'version' => $theme_version,
|
501 |
-
'theme_page_url' => $theme_page_url,
|
502 |
-
'url' => $theme_url
|
503 |
-
);
|
504 |
-
|
505 |
-
}
|
506 |
-
}
|
507 |
-
}
|
508 |
-
|
509 |
-
}
|
510 |
-
|
511 |
-
if ( !(empty($themes_for_saving)) ) {
|
512 |
-
//Has themes for saving
|
513 |
-
if ( !($doing_query) ) {
|
514 |
-
//Not doing query
|
515 |
-
$existing_themes = get_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
|
516 |
-
if ( !($existing_themes) ) {
|
517 |
-
//Does not yet exists
|
518 |
-
delete_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
|
519 |
-
update_option( $this->installer_themes_option[$this->installer_theme_active_tab], $themes_for_saving );
|
520 |
-
} else {
|
521 |
-
//exists, check if we need to update
|
522 |
-
if ( $existing_themes == $themes_for_saving ) {
|
523 |
-
//Equal, no need to update here
|
524 |
-
} else {
|
525 |
-
//Update
|
526 |
-
delete_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
|
527 |
-
update_option( $this->installer_themes_option[$this->installer_theme_active_tab], $themes_for_saving );
|
528 |
-
}
|
529 |
-
}
|
530 |
-
} else {
|
531 |
-
//Used for query purposes only, don't save anything
|
532 |
-
return $themes_for_saving;
|
533 |
-
}
|
534 |
-
}
|
535 |
-
}
|
536 |
-
}
|
537 |
-
|
538 |
-
/** Available themes */
|
539 |
-
private function installer_theme_available( $repo, $subscription_type = '' ) {
|
540 |
-
|
541 |
-
$subscription_type = intval( $subscription_type );
|
542 |
-
if ( $subscription_type > 0 ) {
|
543 |
-
|
544 |
-
//Here we have a case of validated subscription
|
545 |
-
//We need to set themes that is available to this subscription
|
546 |
-
$themes_associated_with_subscription = $this->installer_themes[$repo] = $this->installer_theme_get_themes_by_subscription( $subscription_type, $repo );
|
547 |
-
if ( !(empty($themes_associated_with_subscription)) ) {
|
548 |
-
//Has themes
|
549 |
-
$this->installer_themes[$repo] = $themes_associated_with_subscription;
|
550 |
-
}
|
551 |
-
} else {
|
552 |
-
|
553 |
-
//Get themes
|
554 |
-
$this->installer_themes[$repo] = get_option( $this->installer_themes_option[$repo] );
|
555 |
-
}
|
556 |
-
}
|
557 |
-
|
558 |
-
/** Theme upgrade check */
|
559 |
-
public function installer_theme_upgrade_check( $the_value ) {
|
560 |
-
|
561 |
-
//Step1: Let's looped through repos with themes and check if we have updates available for them.
|
562 |
-
if ( (is_array( $this->installer_repo_with_themes )) && (!(empty($this->installer_repo_with_themes))) ) {
|
563 |
-
foreach ( $this->installer_repo_with_themes as $k => $repo_slug ) {
|
564 |
-
//Step2: Let's checked if we have update for this theme
|
565 |
-
$update_available = get_option( $this->installer_themes_available_updates[$repo_slug] );
|
566 |
-
if ( $update_available ) {
|
567 |
-
if ( (is_array( $update_available )) && (!(empty($update_available))) ) {
|
568 |
-
//Has updates available coming from this specific theme repo
|
569 |
-
//Let's loop through the themes that needs update
|
570 |
-
foreach ( $update_available as $theme_slug => $v ) {
|
571 |
-
//Add to response API
|
572 |
-
$the_value->response [$theme_slug] = array(
|
573 |
-
'theme' => $theme_slug,
|
574 |
-
'new_version' => $v['new_version'],
|
575 |
-
'url' => $v['url'],
|
576 |
-
'package' => $v['package']
|
577 |
-
);
|
578 |
-
}
|
579 |
-
}
|
580 |
-
}
|
581 |
-
}
|
582 |
-
}
|
583 |
-
//Return
|
584 |
-
return $the_value;
|
585 |
-
}
|
586 |
-
|
587 |
-
/** Return repositories that has themes */
|
588 |
-
private function installer_theme_reposities_that_has_themes( $repositories, $ret_value = true, $doing_api_query = false ) {
|
589 |
-
|
590 |
-
$repositories_with_themes = array();
|
591 |
-
|
592 |
-
if ( (is_array( $repositories )) && (!(empty($repositories))) ) {
|
593 |
-
|
594 |
-
//Let's checked if we have something before
|
595 |
-
$themes = get_option( 'installer_repositories_with_theme' );
|
596 |
-
|
597 |
-
if ( (!($themes)) || ($doing_api_query) ) {
|
598 |
-
//Not yet defined
|
599 |
-
//Loop through each repositories and check whether they have themes
|
600 |
-
foreach ( $repositories as $k => $v ) {
|
601 |
-
if ( isset($v['products']) ) {
|
602 |
-
$products_url = $v['products'];
|
603 |
-
$themes = $this->installer_theme_get_themes( $products_url, $k );
|
604 |
-
if ( (is_array( $themes )) && (!(empty($themes))) ) {
|
605 |
-
//Repo has themes
|
606 |
-
$repositories_with_themes[] = $k;
|
607 |
-
}
|
608 |
-
}
|
609 |
-
}
|
610 |
-
} else {
|
611 |
-
//Already set
|
612 |
-
$repositories_with_themes = $themes;
|
613 |
-
}
|
614 |
-
|
615 |
-
if ( (((is_array( $repositories_with_themes )) && (!(empty($repositories_with_themes)))) && (!($themes))) || ($doing_api_query) ) {
|
616 |
-
//Save to db
|
617 |
-
update_option( 'installer_repositories_with_theme', $repositories_with_themes );
|
618 |
-
}
|
619 |
-
}
|
620 |
-
|
621 |
-
if ( $ret_value ) {
|
622 |
-
return $repositories_with_themes;
|
623 |
-
}
|
624 |
-
|
625 |
-
}
|
626 |
-
|
627 |
-
/** When WordPress queries its own Themes API, we sync with our own */
|
628 |
-
public function installer_theme_sync_native_wp_api( $response, $responsetext, $class, $args, $url ) {
|
629 |
-
|
630 |
-
$api_native_string = 'api.wordpress.org/themes/';
|
631 |
-
if ( (strpos( $url, $api_native_string ) !== false) ) {
|
632 |
-
//WordPress is querying its own themes API
|
633 |
-
$installer_repositories = WP_Installer()->get_repositories();
|
634 |
-
|
635 |
-
//Query our own API and update repository values too
|
636 |
-
$this->installer_theme_reposities_that_has_themes( $installer_repositories, false, true );
|
637 |
-
}
|
638 |
-
}
|
639 |
-
|
640 |
-
/** Returns product name by theme repo slug */
|
641 |
-
private function installer_theme_get_repo_product_name( $theme_repo ) {
|
642 |
-
|
643 |
-
$theme_repo_name = false;
|
644 |
-
|
645 |
-
if ( isset(WP_Installer()->settings['repositories'][$theme_repo]['data']['product-name']) ) {
|
646 |
-
//Set
|
647 |
-
$prod_name = WP_Installer()->settings['repositories'][$theme_repo]['data']['product-name'];
|
648 |
-
if ( !(empty($prod_name)) ) {
|
649 |
-
$theme_repo_name = $prod_name;
|
650 |
-
}
|
651 |
-
} else {
|
652 |
-
//Not yet
|
653 |
-
if ( $theme_repo == $this->theme_repo ) {
|
654 |
-
$result = $this->installer_theme_general_api_query();
|
655 |
-
if ( isset($result['product-name']) ) {
|
656 |
-
$product_name = $result['product-name'];
|
657 |
-
if ( !(empty($product_name)) ) {
|
658 |
-
$theme_repo_name = $product_name;
|
659 |
-
}
|
660 |
-
}
|
661 |
-
}
|
662 |
-
}
|
663 |
-
|
664 |
-
return $theme_repo_name;
|
665 |
-
}
|
666 |
-
|
667 |
-
/** General query API method, returns $products */
|
668 |
-
private function installer_theme_general_api_query() {
|
669 |
-
$products = false;
|
670 |
-
$response = wp_remote_get( $this->repository_theme_products );
|
671 |
-
if ( !(is_wp_error( $response )) ) {
|
672 |
-
//Not WP error
|
673 |
-
//Evaluate response
|
674 |
-
if ( $response && isset($response['response']['code']) && $response['response']['code'] == 200 ) {
|
675 |
-
//In this case, response is set and defined, proceed...
|
676 |
-
$body = wp_remote_retrieve_body( $response );
|
677 |
-
if ( $body ) {
|
678 |
-
$result = json_decode( $body, true );
|
679 |
-
if ( (is_array( $result )) && (!(empty($result))) ) {
|
680 |
-
$products = $result;
|
681 |
-
}
|
682 |
-
}
|
683 |
-
|
684 |
-
}
|
685 |
-
}
|
686 |
-
|
687 |
-
return $products;
|
688 |
-
}
|
689 |
-
|
690 |
-
/** General method to check if themes are OTGS themes based on its slug*/
|
691 |
-
private function installer_themes_belong_to_us( $theme_slug ) {
|
692 |
-
|
693 |
-
$found = false;
|
694 |
-
$theme_slug = trim( $theme_slug );
|
695 |
-
|
696 |
-
foreach ( $this->installer_themes as $repo_with_theme => $themes ) {
|
697 |
-
foreach ( $themes as $k => $otgs_theme_slug ) {
|
698 |
-
if ( $theme_slug == $otgs_theme_slug ) {
|
699 |
-
//match found! Theme belongs to otgs
|
700 |
-
return true;
|
701 |
-
}
|
702 |
-
}
|
703 |
-
}
|
704 |
-
return $found;
|
705 |
-
|
706 |
-
}
|
707 |
-
|
708 |
-
/** Sets active tab on init */
|
709 |
-
public function installer_theme_sets_active_tab_on_init() {
|
710 |
-
|
711 |
-
if ( isset ($_SERVER ['REQUEST_URI']) ) {
|
712 |
-
$request_uri = $_SERVER ['REQUEST_URI'];
|
713 |
-
if ( isset ($_GET ['browse']) ) {
|
714 |
-
$active_tab = sanitize_text_field( $_GET['browse'] );
|
715 |
-
$this->installer_theme_active_tab = $active_tab;
|
716 |
-
} elseif ( isset ($_POST ['request'] ['browse']) ) {
|
717 |
-
$active_tab = sanitize_text_field ( $_POST['request']['browse'] );
|
718 |
-
$this->installer_theme_active_tab = $active_tab;
|
719 |
-
} elseif ( (isset ($_GET ['theme_repo'])) && (isset ($_GET ['action'])) ) {
|
720 |
-
$theme_repo = sanitize_text_field( $_GET['theme_repo'] );
|
721 |
-
$the_action = sanitize_text_field( $_GET['action'] );
|
722 |
-
if ( ('install-theme' == $the_action) && (!(empty($theme_repo))) ) {
|
723 |
-
$this->installer_theme_active_tab = $theme_repo;
|
724 |
-
}
|
725 |
-
} elseif ( wp_get_referer() ) {
|
726 |
-
$referer = wp_get_referer();
|
727 |
-
$parts = parse_url( $referer );
|
728 |
-
if ( isset($parts['query']) ) {
|
729 |
-
parse_str( $parts['query'], $query );
|
730 |
-
if ( isset($query['browse']) ) {
|
731 |
-
$this->installer_theme_active_tab = $query['browse'];
|
732 |
-
}
|
733 |
-
}
|
734 |
-
}
|
735 |
-
}
|
736 |
-
}
|
737 |
-
|
738 |
-
/** WP Theme API compatibility- added num ratings */
|
739 |
-
/** Installer 1.7.6+ Added updated 'rating' field */
|
740 |
-
public function installer_theme_add_num_ratings( $themes ) {
|
741 |
-
|
742 |
-
if ( (is_array( $themes )) && (!(empty($themes))) ) {
|
743 |
-
foreach ( $themes as $k => $v ) {
|
744 |
-
if ( !(isset($v->num_ratings)) ) {
|
745 |
-
$themes[$k]->num_ratings = 100;
|
746 |
-
}
|
747 |
-
if ( !(isset($v->rating)) ) {
|
748 |
-
$themes[$k]->rating = 100;
|
749 |
-
}
|
750 |
-
}
|
751 |
-
}
|
752 |
-
|
753 |
-
return $themes;
|
754 |
-
}
|
755 |
-
|
756 |
-
/** When WordPress.org makes a call to its repository, let's run our own upgrade checks too */
|
757 |
-
public function installer_theme_sync_call_wp_theme_api( $locales ) {
|
758 |
-
|
759 |
-
$this->installer_theme_upgrade_theme_check();
|
760 |
-
|
761 |
-
return $locales;
|
762 |
-
}
|
763 |
-
|
764 |
-
/** Upgrade theme check */
|
765 |
-
private function installer_theme_upgrade_theme_check() {
|
766 |
-
|
767 |
-
// Step1-> we get all installed themes in clients local themes directory
|
768 |
-
$installed_themes = wp_get_themes();
|
769 |
-
|
770 |
-
// Step2: We need to loop through each repository with themes
|
771 |
-
foreach ( $this->installer_repo_with_themes as $k => $repo_slug ) {
|
772 |
-
|
773 |
-
// We then need to retrieved the products URL for each of this repo
|
774 |
-
$products_url = $this->repository_theme_products [$repo_slug];
|
775 |
-
|
776 |
-
// Step3-> we get all available themes in our repository via API based on this URL
|
777 |
-
$available_themes = $this->installer_theme_get_themes( $products_url, $repo_slug );
|
778 |
-
|
779 |
-
if ( !($available_themes) ) {
|
780 |
-
|
781 |
-
// API is not available as of the moment, return..
|
782 |
-
return;
|
783 |
-
} else {
|
784 |
-
|
785 |
-
// We have available themes here...
|
786 |
-
// Step4->let's simplify available themes data by slugs
|
787 |
-
$simplified_available_themes = $this->installer_theme_savethemes_by_slug( $available_themes, true );
|
788 |
-
|
789 |
-
// Step5->Let's loop through installed themes
|
790 |
-
if ( (is_array( $installed_themes )) && (!(empty ($installed_themes))) ) {
|
791 |
-
$otgs_theme_updates_available = array();
|
792 |
-
foreach ( $installed_themes as $theme_slug => $theme_object ) {
|
793 |
-
if ( array_key_exists( $theme_slug, $simplified_available_themes ) ) {
|
794 |
-
|
795 |
-
// This is our theme
|
796 |
-
// Step6->Let's get version of the local theme installed
|
797 |
-
$local_version = $theme_object->get( 'Version' );
|
798 |
-
|
799 |
-
// Step7->Let's get the latest version of this theme, page URL and download URL from our repository
|
800 |
-
$repository_version = $simplified_available_themes [$theme_slug] ['version'];
|
801 |
-
$theme_page_url = $simplified_available_themes [$theme_slug] ['theme_page_url'];
|
802 |
-
$theme_download_url = $simplified_available_themes [$theme_slug] ['url'];
|
803 |
-
|
804 |
-
// Step8->Let's compare the version
|
805 |
-
if ( version_compare( $repository_version, $local_version, '>' ) ) {
|
806 |
-
|
807 |
-
// Update available for this theme
|
808 |
-
// Step9-> Define download URL with site key
|
809 |
-
$package_url = WP_Installer()->append_site_key_to_download_url( $theme_download_url, $this->installer_site_key [$repo_slug], $repo_slug );
|
810 |
-
|
811 |
-
//Step10-> Assign to updates array for later accessing.
|
812 |
-
$otgs_theme_updates_available[$theme_slug] = array(
|
813 |
-
'theme' => $theme_slug,
|
814 |
-
'new_version' => $repository_version,
|
815 |
-
'url' => $theme_page_url,
|
816 |
-
'package' => $package_url
|
817 |
-
);
|
818 |
-
}
|
819 |
-
}
|
820 |
-
}
|
821 |
-
//Exited the upgrade loop for this specific theme repository
|
822 |
-
if ( !(empty($otgs_theme_updates_available)) ) {
|
823 |
-
//Has updates
|
824 |
-
update_option( $this->installer_themes_available_updates[$repo_slug], $otgs_theme_updates_available );
|
825 |
-
} else {
|
826 |
-
//No updates
|
827 |
-
delete_option( $this->installer_themes_available_updates[$repo_slug] );
|
828 |
-
}
|
829 |
-
|
830 |
-
}
|
831 |
-
}
|
832 |
-
}
|
833 |
-
}
|
834 |
-
|
835 |
-
/** When the user is on Themes install page OTG themes repository, let's the currently selected tab */
|
836 |
-
public function installer_theme_add_query_arg_tab( $url, $path, $blog_id = null ) {
|
837 |
-
|
838 |
-
$wp_install_string = 'update.php?action=install-theme';
|
839 |
-
if ( $path == $wp_install_string ) {
|
840 |
-
if ( isset($this->installer_theme_active_tab) ) {
|
841 |
-
if ( !(empty($this->installer_theme_active_tab)) ) {
|
842 |
-
$url = add_query_arg( array(
|
843 |
-
'theme_repo' => $this->installer_theme_active_tab
|
844 |
-
), $url );
|
845 |
-
}
|
846 |
-
}
|
847 |
-
}
|
848 |
-
return $url;
|
849 |
-
}
|
850 |
-
|
851 |
-
/** Save frontend theme tab selected */
|
852 |
-
public function installer_theme_frontend_selected_tab() {
|
853 |
-
if ( isset($_POST["frontend_tab_selected"]) ) {
|
854 |
-
check_ajax_referer( 'installer_theme_frontend_selected_tab', 'installer_theme_frontend_selected_tab_nonce' );
|
855 |
-
|
856 |
-
//Client_side_active_tab
|
857 |
-
$frontend_tab_selected = sanitize_text_field( $_POST['frontend_tab_selected'] );
|
858 |
-
if ( !(empty($frontend_tab_selected)) ) {
|
859 |
-
//Front end tab selected
|
860 |
-
update_option( 'wp_installer_clientside_active_tab', $frontend_tab_selected, false );
|
861 |
-
|
862 |
-
//Check for registration status
|
863 |
-
if ( isset($this->theme_user_registration[$frontend_tab_selected]) ) {
|
864 |
-
//Set
|
865 |
-
if ( !($this->theme_user_registration[$frontend_tab_selected]) ) {
|
866 |
-
//Not registered yet
|
867 |
-
|
868 |
-
if ( is_multisite() ) {
|
869 |
-
$admin_url_passed = network_admin_url();
|
870 |
-
} else {
|
871 |
-
$admin_url_passed = admin_url();
|
872 |
-
}
|
873 |
-
|
874 |
-
$registration_url = $admin_url_passed . 'plugin-install.php?tab=commercial#installer_repo_' . $frontend_tab_selected;
|
875 |
-
|
876 |
-
//Message and link
|
877 |
-
$theme_repo_name = $this->installer_theme_get_repo_product_name( $frontend_tab_selected );;
|
878 |
-
$response['unregistered_messages'] = sprintf( __( 'To install and update %s, please %sregister%s %s for this site.', 'installer' ),
|
879 |
-
$theme_repo_name, '<a href="' . $registration_url . '">', '</a>', $theme_repo_name );
|
880 |
-
|
881 |
-
}
|
882 |
-
}
|
883 |
-
|
884 |
-
$response['output'] = $frontend_tab_selected;
|
885 |
-
echo json_encode( $response );
|
886 |
-
}
|
887 |
-
die();
|
888 |
-
}
|
889 |
-
die();
|
890 |
-
}
|
891 |
-
|
892 |
-
/** Installer loaded aux hooks */
|
893 |
-
public function installer_theme_loaded_hooks() {
|
894 |
-
|
895 |
-
if ( isset($this->installer_theme_subscription_type) ) {
|
896 |
-
$subscription_type = intval( $this->installer_theme_subscription_type );
|
897 |
-
if ( $subscription_type > 0 ) {
|
898 |
-
//Client is subscribed
|
899 |
-
add_filter( 'installer_theme_get_themes', array($this, 'installer_theme_filter_themes_by_subscription'), 10, 2 );
|
900 |
-
}
|
901 |
-
}
|
902 |
-
|
903 |
-
}
|
904 |
-
|
905 |
-
/** Get themes by subscription type */
|
906 |
-
protected function installer_theme_get_themes_by_subscription( $subscription_type, $repo ) {
|
907 |
-
|
908 |
-
$themes_associated_with_subscription = array();
|
909 |
-
if ( isset(WP_Installer()->settings['repositories'][$repo]['data']['packages']) ) {
|
910 |
-
//Set
|
911 |
-
$packages = WP_Installer()->settings['repositories'][$repo]['data']['packages'];
|
912 |
-
$available_themes_subscription = array();
|
913 |
-
foreach ( $packages as $package_id => $package_details ) {
|
914 |
-
if ( isset($package_details['products']) ) {
|
915 |
-
$the_products = $package_details['products'];
|
916 |
-
foreach ( $the_products as $product_slug => $product_details ) {
|
917 |
-
if ( isset($product_details['subscription_type']) ) {
|
918 |
-
$subscription_type_from_settings = intval( $product_details['subscription_type'] );
|
919 |
-
if ( $subscription_type_from_settings == $subscription_type ) {
|
920 |
-
//We found the subscription
|
921 |
-
if ( isset($product_details['themes']) ) {
|
922 |
-
$themes_associated_with_subscription = $product_details['themes'];
|
923 |
-
return $themes_associated_with_subscription;
|
924 |
-
}
|
925 |
-
}
|
926 |
-
}
|
927 |
-
|
928 |
-
}
|
929 |
-
}
|
930 |
-
}
|
931 |
-
}
|
932 |
-
return $themes_associated_with_subscription;
|
933 |
-
}
|
934 |
-
|
935 |
-
/** Filter API theme response according to user subscription */
|
936 |
-
public function installer_theme_filter_themes_by_subscription( $themes, $active_tab ) {
|
937 |
-
|
938 |
-
//Step1, we only filter OTGS themes
|
939 |
-
$orig = count( $themes );
|
940 |
-
if ( in_array( $active_tab, $this->theme_repo ) ) {
|
941 |
-
//OTGS Theme
|
942 |
-
//Step2, we retrieved the available themes based on client subscription
|
943 |
-
if ( isset($this->installer_themes[$active_tab]) ) {
|
944 |
-
$available_themes = $this->installer_themes[$active_tab];
|
945 |
-
//Step3, we filter $themes based on this info
|
946 |
-
if ( (is_array( $themes )) && (!(empty($themes))) ) {
|
947 |
-
foreach ( $themes as $k => $theme ) {
|
948 |
-
//Step4, get theme slug
|
949 |
-
if ( isset($theme['slug']) ) {
|
950 |
-
$theme_slug = $theme['slug'];
|
951 |
-
if ( !(empty($theme_slug)) ) {
|
952 |
-
if ( !(in_array( $theme_slug, $available_themes )) ) {
|
953 |
-
//This theme is not in available themes
|
954 |
-
unset($themes[$k]);
|
955 |
-
}
|
956 |
-
}
|
957 |
-
}
|
958 |
-
}
|
959 |
-
}
|
960 |
-
}
|
961 |
-
}
|
962 |
-
$new = count( $themes );
|
963 |
-
if ( $orig != $new ) {
|
964 |
-
//It is filtered
|
965 |
-
$themes = array_values( $themes );
|
966 |
-
}
|
967 |
-
|
968 |
-
return $themes;
|
969 |
-
}
|
970 |
-
|
971 |
-
/** Hook to wp_loaded, fires when all Installer theme class is ready */
|
972 |
-
public function installer_themes_support_set_up_func() {
|
973 |
-
do_action( 'installer_themes_support_set_up' );
|
974 |
-
}
|
975 |
-
|
976 |
-
}
|
977 |
-
|
978 |
-
/** Instantiate Installer Theme Class */
|
979 |
new Installer_Theme_Class;
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Installer Class for Theme Support
|
4 |
+
*
|
5 |
+
* Supports automatic updates and installation of Toolset/WPML Themes
|
6 |
+
*
|
7 |
+
* @class Installer_Theme_Class
|
8 |
+
* @version 1.6
|
9 |
+
* @category Class
|
10 |
+
* @author OnTheGoSystems
|
11 |
+
*/
|
12 |
+
|
13 |
+
if ( !defined( 'ABSPATH' ) ) {
|
14 |
+
exit;
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Installer_Theme_Class
|
19 |
+
*/
|
20 |
+
class Installer_Theme_Class {
|
21 |
+
|
22 |
+
/** Theme Repository */
|
23 |
+
private $theme_repo;
|
24 |
+
|
25 |
+
/** Repository API */
|
26 |
+
private $repository_api;
|
27 |
+
|
28 |
+
/** Repository Theme Products */
|
29 |
+
private $repository_theme_products;
|
30 |
+
|
31 |
+
/** Site URL */
|
32 |
+
private $installer_site_url;
|
33 |
+
|
34 |
+
/** Site Key */
|
35 |
+
private $installer_site_key;
|
36 |
+
|
37 |
+
/** The Themes Option */
|
38 |
+
protected $installer_themes_option;
|
39 |
+
|
40 |
+
/** Update settings */
|
41 |
+
protected $installer_themes_available_updates;
|
42 |
+
|
43 |
+
/** The Themes */
|
44 |
+
protected $installer_themes = array();
|
45 |
+
|
46 |
+
/** Repository with themes */
|
47 |
+
protected $installer_repo_with_themes;
|
48 |
+
|
49 |
+
/** Active tab */
|
50 |
+
protected $installer_theme_active_tab;
|
51 |
+
|
52 |
+
/** Theme user registration */
|
53 |
+
protected $theme_user_registration;
|
54 |
+
|
55 |
+
/** Client active subscription */
|
56 |
+
protected $installer_theme_subscription_type;
|
57 |
+
|
58 |
+
public function __construct() {
|
59 |
+
|
60 |
+
/** Properties */
|
61 |
+
|
62 |
+
//Get installer repositories
|
63 |
+
$installer_repositories = WP_Installer()->get_repositories();
|
64 |
+
|
65 |
+
//Get repos with themes
|
66 |
+
$repos_with_themes = $this->installer_theme_reposities_that_has_themes( $installer_repositories );
|
67 |
+
|
68 |
+
if ( is_array( $repos_with_themes ) ) {
|
69 |
+
//Assign to property
|
70 |
+
$this->installer_repo_with_themes = $repos_with_themes;
|
71 |
+
|
72 |
+
//Let's looped through repos with themes
|
73 |
+
foreach ( $repos_with_themes as $k => $repo ) {
|
74 |
+
|
75 |
+
//$repo could be 'toolset' or 'wpml'
|
76 |
+
//Assign each repo with theme to property
|
77 |
+
$this->theme_repo[] = $repo;
|
78 |
+
|
79 |
+
if ( (isset($installer_repositories[$repo]['api-url'])) && (isset($installer_repositories[$repo]['products'])) ) {
|
80 |
+
|
81 |
+
//Define the rest of the properties based on the given repo
|
82 |
+
$this->repository_api[$repo] = $installer_repositories[$repo]['api-url'];
|
83 |
+
$this->repository_theme_products[$repo] = $installer_repositories[$repo]['products'];
|
84 |
+
$this->installer_site_url[$repo] = WP_Installer()->get_installer_site_url( $repo );
|
85 |
+
$this->installer_site_key[$repo] = WP_Installer()->get_site_key( $repo );
|
86 |
+
$this->theme_user_registration[$repo] = false;
|
87 |
+
|
88 |
+
if ( WP_Installer()->repository_has_valid_subscription( $repo ) ) {
|
89 |
+
|
90 |
+
$this->installer_theme_subscription_type = WP_Installer()->get_subscription_type_for_repository( $repo );
|
91 |
+
$this->installer_themes_option[$repo] = 'wp_installer_' . $repo . '_themes';
|
92 |
+
$this->installer_themes_available_updates[$repo] = 'wp_installer_' . $repo . '_updated_themes';
|
93 |
+
$this->installer_theme_active_tab = '';
|
94 |
+
|
95 |
+
//We only set themes available to this validated subscription
|
96 |
+
$this->installer_theme_available( $repo, $this->installer_theme_subscription_type );
|
97 |
+
|
98 |
+
add_action( 'installer_themes_support_set_up', array($this, 'installer_theme_sets_active_tab_on_init'), 10 );
|
99 |
+
$this->theme_user_registration[$repo] = true;
|
100 |
+
}
|
101 |
+
|
102 |
+
/** We are ready.. let's initialize .... */
|
103 |
+
$this->init();
|
104 |
+
}
|
105 |
+
}
|
106 |
+
add_action( 'installer_themes_support_set_up', array($this, 'installer_theme_loaded_hooks') );
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
110 |
+
/** Init */
|
111 |
+
public function init() {
|
112 |
+
add_action( 'admin_enqueue_scripts', array($this, 'installer_theme_enqueue_scripts') );
|
113 |
+
add_filter( 'themes_api', array($this, 'installer_theme_api_override'), 10, 3 );
|
114 |
+
add_filter( 'themes_api_result', array($this, 'installer_theme_api_override_response'), 10, 3 );
|
115 |
+
add_filter( 'site_transient_update_themes', array($this, 'installer_theme_upgrade_check'), 10, 1 );
|
116 |
+
add_action( 'http_api_debug', array($this, 'installer_theme_sync_native_wp_api'), 10, 5 );
|
117 |
+
add_filter( 'installer_theme_hook_response_theme', array($this, 'installer_theme_add_num_ratings'), 10, 1 );
|
118 |
+
add_filter( 'themes_update_check_locales', array($this, 'installer_theme_sync_call_wp_theme_api'), 10, 1 );
|
119 |
+
add_filter( 'admin_url', array($this, 'installer_theme_add_query_arg_tab'), 10, 3 );
|
120 |
+
add_filter( 'network_admin_url', array($this, 'installer_theme_add_query_arg_tab'), 10, 2 );
|
121 |
+
add_action( 'wp_ajax_installer_theme_frontend_selected_tab', array($this, 'installer_theme_frontend_selected_tab'), 0 );
|
122 |
+
add_action( 'wp_loaded', array($this, 'installer_themes_support_set_up_func') );
|
123 |
+
}
|
124 |
+
|
125 |
+
/** Enqueue scripts */
|
126 |
+
public function installer_theme_enqueue_scripts() {
|
127 |
+
$current_screen = $this->installer_theme_current_screen();
|
128 |
+
$commercial_plugin_screen = $this->installer_theme_is_commercial_plugin_screen( $current_screen );
|
129 |
+
if ( ('theme-install' == $current_screen) || ($commercial_plugin_screen) || ('theme-install-network' == $current_screen) ) {
|
130 |
+
$repo_with_themes = $this->installer_repo_with_themes;
|
131 |
+
$js_array = array();
|
132 |
+
if ( is_array( $repo_with_themes ) ) {
|
133 |
+
foreach ( $repo_with_themes as $k => $v ) {
|
134 |
+
|
135 |
+
//Hyperlink text
|
136 |
+
$theme_repo_name = $this->installer_theme_get_repo_product_name( $v );
|
137 |
+
$the_hyperlink_text = esc_js( $theme_repo_name );
|
138 |
+
|
139 |
+
if ( is_multisite() ) {
|
140 |
+
$admin_url_passed = network_admin_url();
|
141 |
+
} else {
|
142 |
+
$admin_url_passed = admin_url();
|
143 |
+
}
|
144 |
+
|
145 |
+
//Define
|
146 |
+
$js_array[$v] = array(
|
147 |
+
'the_hyperlink_text' => $the_hyperlink_text,
|
148 |
+
'registration_status' => $this->theme_user_registration[$v],
|
149 |
+
'is_commercial_plugin_tab' => $commercial_plugin_screen,
|
150 |
+
'registration_url' => $admin_url_passed . 'plugin-install.php?tab=commercial#installer_repo_' . $v
|
151 |
+
);
|
152 |
+
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
if ( !(empty($js_array)) ) {
|
157 |
+
wp_enqueue_script( 'installer-theme-install', WP_Installer()->res_url() . '/res/js/installer_theme_install.js', array('jquery', 'installer-admin'), WP_Installer()->version() );
|
158 |
+
$installer_ajax_url = admin_url( 'admin-ajax.php' );
|
159 |
+
|
160 |
+
if ( is_ssl() ) {
|
161 |
+
$installer_ajax_url = str_replace( 'http://', 'https://', $installer_ajax_url );
|
162 |
+
} else {
|
163 |
+
$installer_ajax_url = str_replace( 'https://', 'http://', $installer_ajax_url );
|
164 |
+
}
|
165 |
+
|
166 |
+
//Case where user is subscribed to a subscription that does not have themes
|
167 |
+
$subscription_js_check = $this->installer_theme_subscription_does_not_have_theme( $js_array );
|
168 |
+
|
169 |
+
wp_localize_script( 'installer-theme-install', 'installer_theme_install_localize',
|
170 |
+
array(
|
171 |
+
'js_array_installer' => $js_array,
|
172 |
+
'ajaxurl' => $installer_ajax_url,
|
173 |
+
'no_associated_themes' => $subscription_js_check,
|
174 |
+
'installer_theme_frontend_selected_tab_nonce' => wp_create_nonce( 'installer_theme_frontend_selected_tab' )
|
175 |
+
)
|
176 |
+
);
|
177 |
+
}
|
178 |
+
}
|
179 |
+
}
|
180 |
+
|
181 |
+
/** Case where user is subscribed to a subscription that does not have themes */
|
182 |
+
protected function installer_theme_subscription_does_not_have_theme( $js_array ) {
|
183 |
+
|
184 |
+
$any_subscription_has_theme = array();
|
185 |
+
$number_of_registrations = array();
|
186 |
+
|
187 |
+
//Step1, we looped through JS array
|
188 |
+
foreach ( $js_array as $repo_slug => $js_details ) {
|
189 |
+
|
190 |
+
//Step2, checked if user is registered
|
191 |
+
if ( isset($this->theme_user_registration[$repo_slug]) ) {
|
192 |
+
$registration_status = $this->theme_user_registration[$repo_slug];
|
193 |
+
if ( $registration_status ) {
|
194 |
+
|
195 |
+
//Registered
|
196 |
+
$number_of_registrations[] = $repo_slug;
|
197 |
+
|
198 |
+
//Step3, we checked if the $repo_slug has available theme
|
199 |
+
$themes_available = false;
|
200 |
+
if ( isset($this->installer_themes[$repo_slug]) ) {
|
201 |
+
$themes_available = $this->installer_themes[$repo_slug];
|
202 |
+
if ( !(empty($themes_available)) ) {
|
203 |
+
//This subscription has theme
|
204 |
+
$themes_available = true;
|
205 |
+
}
|
206 |
+
}
|
207 |
+
|
208 |
+
if ( $themes_available ) {
|
209 |
+
$any_subscription_has_theme[] = $repo_slug;
|
210 |
+
}
|
211 |
+
}
|
212 |
+
}
|
213 |
+
|
214 |
+
}
|
215 |
+
|
216 |
+
//Step4, we are done looping, check if there are any repos that have themes
|
217 |
+
if ( empty($registration_status) ) {
|
218 |
+
|
219 |
+
//No registration on any repos
|
220 |
+
return FALSE;
|
221 |
+
|
222 |
+
} elseif ( !(empty($registration_status)) ) {
|
223 |
+
|
224 |
+
//Has some registration on some repos
|
225 |
+
//We then checked if this user has any active subscriptions
|
226 |
+
if ( empty($any_subscription_has_theme) ) {
|
227 |
+
//No subscription
|
228 |
+
return TRUE;
|
229 |
+
} else {
|
230 |
+
//Has subscription found
|
231 |
+
return FALSE;
|
232 |
+
}
|
233 |
+
}
|
234 |
+
}
|
235 |
+
|
236 |
+
/** Check if its the commercial plugin screen */
|
237 |
+
private function installer_theme_is_commercial_plugin_screen( $current_screen ) {
|
238 |
+
$commercial = false;
|
239 |
+
if ( ('plugin-install' == $current_screen) || ('plugin-install-network' == $current_screen) ) {
|
240 |
+
if ( isset($_GET['tab']) ) {
|
241 |
+
$tab = sanitize_text_field( $_GET['tab'] );
|
242 |
+
if ( 'commercial' == $tab ) {
|
243 |
+
$commercial = true;
|
244 |
+
}
|
245 |
+
}
|
246 |
+
}
|
247 |
+
return $commercial;
|
248 |
+
}
|
249 |
+
|
250 |
+
/** Current screen */
|
251 |
+
private function installer_theme_current_screen() {
|
252 |
+
|
253 |
+
$current_screen_loaded = false;
|
254 |
+
|
255 |
+
if ( function_exists( 'get_current_screen' ) ) {
|
256 |
+
|
257 |
+
$screen_output = get_current_screen();
|
258 |
+
$current_screen_loaded = $screen_output->id;
|
259 |
+
|
260 |
+
}
|
261 |
+
|
262 |
+
return $current_screen_loaded;
|
263 |
+
|
264 |
+
}
|
265 |
+
|
266 |
+
/** Override WordPress Themes API */
|
267 |
+
public function installer_theme_api_override( $api_boolean, $action, $args ) {
|
268 |
+
|
269 |
+
//Let's checked if user is browsing our themes
|
270 |
+
if ( isset($args->browse) ) {
|
271 |
+
$browse = $args->browse;
|
272 |
+
if ( in_array( $browse, $this->theme_repo ) ) {
|
273 |
+
//Uniquely validated for our Themes
|
274 |
+
if ( 'query_themes' == $action ) {
|
275 |
+
//User is querying or asking information about our themes, let's override
|
276 |
+
$api_boolean = true;
|
277 |
+
}
|
278 |
+
}
|
279 |
+
} elseif ( isset($args->slug) ) {
|
280 |
+
//We are installing our themes
|
281 |
+
$theme_to_install = $args->slug;
|
282 |
+
|
283 |
+
//Lets uniquely validate if this belongs to us
|
284 |
+
//Check if this is OTGS theme
|
285 |
+
$validate_check = $this->installer_themes_belong_to_us( $theme_to_install );
|
286 |
+
if ( $validate_check ) {
|
287 |
+
//Belongs to us
|
288 |
+
if ( !(empty($theme_to_install)) ) {
|
289 |
+
$api_boolean = true;
|
290 |
+
}
|
291 |
+
}
|
292 |
+
}
|
293 |
+
|
294 |
+
return $api_boolean;
|
295 |
+
}
|
296 |
+
|
297 |
+
/** Override WordPress Themes API response with our own themes API*/
|
298 |
+
public function installer_theme_api_override_response( $res, $action, $args ) {
|
299 |
+
|
300 |
+
if ( true === $res ) {
|
301 |
+
if ( isset($args->browse) ) {
|
302 |
+
$browse = $args->browse;
|
303 |
+
if ( in_array( $browse, $this->theme_repo ) ) {
|
304 |
+
//Uniquely validated for our themes
|
305 |
+
if ( 'query_themes' == $action ) {
|
306 |
+
//Client querying OTGS themes
|
307 |
+
//Check for registration status
|
308 |
+
if ( isset($this->theme_user_registration[$browse]) ) {
|
309 |
+
//Set
|
310 |
+
if ( !($this->theme_user_registration[$browse]) ) {
|
311 |
+
//Not registered yet
|
312 |
+
$res = new stdClass();
|
313 |
+
$res->info = array();
|
314 |
+
$res->themes = array();
|
315 |
+
return $res;
|
316 |
+
} else {
|
317 |
+
//Registered
|
318 |
+
$themes = $this->installer_theme_get_themes( '', $browse );
|
319 |
+
$res = $this->installer_theme_format_response( $themes, $action );
|
320 |
+
}
|
321 |
+
}
|
322 |
+
}
|
323 |
+
}
|
324 |
+
} elseif ( isset($args->slug) ) {
|
325 |
+
//We are installing theme
|
326 |
+
//Lets uniquely validate if this belongs to our theme
|
327 |
+
$theme_to_install = $args->slug;
|
328 |
+
|
329 |
+
//Lets uniquely validate if this belongs to us
|
330 |
+
//Check if this is OTGS theme
|
331 |
+
$validate_check = $this->installer_themes_belong_to_us( $theme_to_install );
|
332 |
+
if ( $validate_check ) {
|
333 |
+
//Belongs to us
|
334 |
+
if ( ($res) && ('theme_information' == $action) ) {
|
335 |
+
$themes = $this->installer_theme_get_themes( '', $this->installer_theme_active_tab );
|
336 |
+
$res = $this->installer_theme_format_response( $themes, $action, $args->slug );
|
337 |
+
}
|
338 |
+
}
|
339 |
+
}
|
340 |
+
return $res;
|
341 |
+
} else {
|
342 |
+
//Default WP Themes here
|
343 |
+
$client_side_active_tab = get_option( 'wp_installer_clientside_active_tab' );
|
344 |
+
if ( $client_side_active_tab ) {
|
345 |
+
if ( !(in_array( $client_side_active_tab, $this->theme_repo )) ) {
|
346 |
+
//Not OTGS tab
|
347 |
+
return $res;
|
348 |
+
}
|
349 |
+
}
|
350 |
+
|
351 |
+
}
|
352 |
+
}
|
353 |
+
|
354 |
+
/** Get Themes */
|
355 |
+
private function installer_theme_get_themes( $product_url = '', $repo_source = '' ) {
|
356 |
+
|
357 |
+
//Query API
|
358 |
+
if ( empty($product_url) ) {
|
359 |
+
//Not set
|
360 |
+
if ( isset($this->repository_theme_products[$this->installer_theme_active_tab]) ) {
|
361 |
+
$query_remote_url = $this->repository_theme_products[$this->installer_theme_active_tab];
|
362 |
+
}
|
363 |
+
|
364 |
+
} else {
|
365 |
+
$query_remote_url = $product_url;
|
366 |
+
}
|
367 |
+
|
368 |
+
//Let's retrieved current installer settings so we won't be querying all the time
|
369 |
+
$current_installer_settings = WP_Installer()->get_settings();
|
370 |
+
|
371 |
+
//Set $themes to FALSE by default
|
372 |
+
$themes = false;
|
373 |
+
|
374 |
+
if ( (is_array( $current_installer_settings )) && (!(empty($current_installer_settings))) ) {
|
375 |
+
|
376 |
+
//Set and already defined, retrieved $products
|
377 |
+
if ( isset($current_installer_settings['repositories'][$repo_source]['data']) ) {
|
378 |
+
$products = $current_installer_settings['repositories'][$repo_source]['data'];
|
379 |
+
if ( isset($products['downloads']['themes']) ) {
|
380 |
+
$themes = $products['downloads']['themes'];
|
381 |
+
}
|
382 |
+
}
|
383 |
+
|
384 |
+
} else {
|
385 |
+
|
386 |
+
//Call API
|
387 |
+
$response = wp_remote_get( $query_remote_url );
|
388 |
+
|
389 |
+
if ( is_wp_error( $response ) ) {
|
390 |
+
//Error detected: http fallback
|
391 |
+
$query_remote_url = preg_replace( "@^https://@", 'http://', $query_remote_url );
|
392 |
+
$response = wp_remote_get( $query_remote_url );
|
393 |
+
}
|
394 |
+
|
395 |
+
if ( !(is_wp_error( $response )) ) {
|
396 |
+
//Not WP error
|
397 |
+
//Evaluate response
|
398 |
+
if ( $response && isset($response['response']['code']) && $response['response']['code'] == 200 ) {
|
399 |
+
//In this case, response is set and defined, proceed...
|
400 |
+
$body = wp_remote_retrieve_body( $response );
|
401 |
+
if ( $body ) {
|
402 |
+
$products = json_decode( $body, true );
|
403 |
+
if ( isset($products['downloads']['themes']) ) {
|
404 |
+
$themes = $products['downloads']['themes'];
|
405 |
+
}
|
406 |
+
}
|
407 |
+
|
408 |
+
}
|
409 |
+
}
|
410 |
+
}
|
411 |
+
|
412 |
+
//Return themes, can be filtered by user subscription type
|
413 |
+
return apply_filters( 'installer_theme_get_themes', $themes, $this->installer_theme_active_tab );
|
414 |
+
}
|
415 |
+
|
416 |
+
/** Format response in compatibility with WordPress Theme API response */
|
417 |
+
private function installer_theme_format_response( $themes, $action, $slug = '' ) {
|
418 |
+
|
419 |
+
//Let's append download link only when retrieving theme information for installation
|
420 |
+
if ( ('theme_information' == $action) && (!(empty($slug))) ) {
|
421 |
+
|
422 |
+
//Only return one result -> the theme to be installed
|
423 |
+
foreach ( $themes as $k => $theme ) {
|
424 |
+
if ( $slug == $theme['basename'] ) {
|
425 |
+
$theme['download_link'] = WP_Installer()->append_site_key_to_download_url( $theme['url'], $this->installer_site_key[$this->installer_theme_active_tab], $this->installer_theme_active_tab );
|
426 |
+
$theme = json_decode( json_encode( $theme ), FALSE );
|
427 |
+
return $theme;
|
428 |
+
}
|
429 |
+
}
|
430 |
+
|
431 |
+
} else {
|
432 |
+
|
433 |
+
$res = new stdClass();
|
434 |
+
$res->info = array();
|
435 |
+
$res->themes = array();
|
436 |
+
|
437 |
+
//Define info
|
438 |
+
$res->info['page'] = 1;
|
439 |
+
$res->info['pages'] = 10;
|
440 |
+
|
441 |
+
//Let's count available themes ;
|
442 |
+
$res->info['results'] = count( $themes );
|
443 |
+
|
444 |
+
//Let's saved themes for easy access later on
|
445 |
+
$this->installer_theme_savethemes_by_slug( $themes );
|
446 |
+
|
447 |
+
//Let's defined available themes
|
448 |
+
if ( isset($this->installer_theme_subscription_type) ) {
|
449 |
+
//Has subscription type defined, let's saved what is associated with this subscription
|
450 |
+
$this->installer_theme_available( $this->installer_theme_active_tab, $this->installer_theme_subscription_type );
|
451 |
+
} else {
|
452 |
+
$this->installer_theme_available( $this->installer_theme_active_tab );
|
453 |
+
}
|
454 |
+
|
455 |
+
//Let's add themes to the overriden WordPress API Theme response
|
456 |
+
/** Installer 1.7.6: Update to compatible data format response from WP Theme API */
|
457 |
+
$theme_compatible_array=array();
|
458 |
+
if ((is_array($themes))) {
|
459 |
+
foreach ($themes as $k=>$v) {
|
460 |
+
$theme_compatible_array[]=(object)($v);
|
461 |
+
}
|
462 |
+
}
|
463 |
+
$res->themes = $theme_compatible_array;
|
464 |
+
$res->themes = apply_filters( 'installer_theme_hook_response_theme', $res->themes );
|
465 |
+
return $res;
|
466 |
+
}
|
467 |
+
}
|
468 |
+
|
469 |
+
/** Let's save all available themes by its slug after any latest API query */
|
470 |
+
private function installer_theme_savethemes_by_slug( $themes, $doing_query = false ) {
|
471 |
+
|
472 |
+
if ( !($doing_query) ) {
|
473 |
+
$this->installer_themes[$this->installer_theme_active_tab] = array();
|
474 |
+
}
|
475 |
+
|
476 |
+
if ( !(empty($themes)) ) {
|
477 |
+
$themes_for_saving = array();
|
478 |
+
foreach ( $themes as $k => $theme ) {
|
479 |
+
if ( !($doing_query) ) {
|
480 |
+
if ( isset($theme['slug']) ) {
|
481 |
+
$theme_slug = $theme['slug'];
|
482 |
+
if ( !(empty($theme_slug)) ) {
|
483 |
+
$themes_for_saving[] = $theme_slug;
|
484 |
+
}
|
485 |
+
}
|
486 |
+
} else {
|
487 |
+
|
488 |
+
if ( ((isset($theme['slug'])) && (isset($theme['version'])) &&
|
489 |
+
(isset($theme['theme_page_url']))) && (isset($theme['url']))
|
490 |
+
) {
|
491 |
+
$theme_slug = $theme['slug'];
|
492 |
+
$theme_version = $theme['version'];
|
493 |
+
$theme_page_url = $theme['theme_page_url'];
|
494 |
+
$theme_url = $theme['url'];
|
495 |
+
if ( (!(empty($theme_slug))) && (!(empty($theme_version))) &&
|
496 |
+
(!(empty($theme_page_url))) && (!(empty($theme_url)))
|
497 |
+
) {
|
498 |
+
//$theme_slug is unique for every theme
|
499 |
+
$themes_for_saving[$theme_slug] = array(
|
500 |
+
'version' => $theme_version,
|
501 |
+
'theme_page_url' => $theme_page_url,
|
502 |
+
'url' => $theme_url
|
503 |
+
);
|
504 |
+
|
505 |
+
}
|
506 |
+
}
|
507 |
+
}
|
508 |
+
|
509 |
+
}
|
510 |
+
|
511 |
+
if ( !(empty($themes_for_saving)) ) {
|
512 |
+
//Has themes for saving
|
513 |
+
if ( !($doing_query) ) {
|
514 |
+
//Not doing query
|
515 |
+
$existing_themes = get_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
|
516 |
+
if ( !($existing_themes) ) {
|
517 |
+
//Does not yet exists
|
518 |
+
delete_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
|
519 |
+
update_option( $this->installer_themes_option[$this->installer_theme_active_tab], $themes_for_saving );
|
520 |
+
} else {
|
521 |
+
//exists, check if we need to update
|
522 |
+
if ( $existing_themes == $themes_for_saving ) {
|
523 |
+
//Equal, no need to update here
|
524 |
+
} else {
|
525 |
+
//Update
|
526 |
+
delete_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
|
527 |
+
update_option( $this->installer_themes_option[$this->installer_theme_active_tab], $themes_for_saving );
|
528 |
+
}
|
529 |
+
}
|
530 |
+
} else {
|
531 |
+
//Used for query purposes only, don't save anything
|
532 |
+
return $themes_for_saving;
|
533 |
+
}
|
534 |
+
}
|
535 |
+
}
|
536 |
+
}
|
537 |
+
|
538 |
+
/** Available themes */
|
539 |
+
private function installer_theme_available( $repo, $subscription_type = '' ) {
|
540 |
+
|
541 |
+
$subscription_type = intval( $subscription_type );
|
542 |
+
if ( $subscription_type > 0 ) {
|
543 |
+
|
544 |
+
//Here we have a case of validated subscription
|
545 |
+
//We need to set themes that is available to this subscription
|
546 |
+
$themes_associated_with_subscription = $this->installer_themes[$repo] = $this->installer_theme_get_themes_by_subscription( $subscription_type, $repo );
|
547 |
+
if ( !(empty($themes_associated_with_subscription)) ) {
|
548 |
+
//Has themes
|
549 |
+
$this->installer_themes[$repo] = $themes_associated_with_subscription;
|
550 |
+
}
|
551 |
+
} else {
|
552 |
+
|
553 |
+
//Get themes
|
554 |
+
$this->installer_themes[$repo] = get_option( $this->installer_themes_option[$repo] );
|
555 |
+
}
|
556 |
+
}
|
557 |
+
|
558 |
+
/** Theme upgrade check */
|
559 |
+
public function installer_theme_upgrade_check( $the_value ) {
|
560 |
+
|
561 |
+
//Step1: Let's looped through repos with themes and check if we have updates available for them.
|
562 |
+
if ( (is_array( $this->installer_repo_with_themes )) && (!(empty($this->installer_repo_with_themes))) ) {
|
563 |
+
foreach ( $this->installer_repo_with_themes as $k => $repo_slug ) {
|
564 |
+
//Step2: Let's checked if we have update for this theme
|
565 |
+
$update_available = get_option( $this->installer_themes_available_updates[$repo_slug] );
|
566 |
+
if ( $update_available ) {
|
567 |
+
if ( (is_array( $update_available )) && (!(empty($update_available))) ) {
|
568 |
+
//Has updates available coming from this specific theme repo
|
569 |
+
//Let's loop through the themes that needs update
|
570 |
+
foreach ( $update_available as $theme_slug => $v ) {
|
571 |
+
//Add to response API
|
572 |
+
$the_value->response [$theme_slug] = array(
|
573 |
+
'theme' => $theme_slug,
|
574 |
+
'new_version' => $v['new_version'],
|
575 |
+
'url' => $v['url'],
|
576 |
+
'package' => $v['package']
|
577 |
+
);
|
578 |
+
}
|
579 |
+
}
|
580 |
+
}
|
581 |
+
}
|
582 |
+
}
|
583 |
+
//Return
|
584 |
+
return $the_value;
|
585 |
+
}
|
586 |
+
|
587 |
+
/** Return repositories that has themes */
|
588 |
+
private function installer_theme_reposities_that_has_themes( $repositories, $ret_value = true, $doing_api_query = false ) {
|
589 |
+
|
590 |
+
$repositories_with_themes = array();
|
591 |
+
|
592 |
+
if ( (is_array( $repositories )) && (!(empty($repositories))) ) {
|
593 |
+
|
594 |
+
//Let's checked if we have something before
|
595 |
+
$themes = get_option( 'installer_repositories_with_theme' );
|
596 |
+
|
597 |
+
if ( (!($themes)) || ($doing_api_query) ) {
|
598 |
+
//Not yet defined
|
599 |
+
//Loop through each repositories and check whether they have themes
|
600 |
+
foreach ( $repositories as $k => $v ) {
|
601 |
+
if ( isset($v['products']) ) {
|
602 |
+
$products_url = $v['products'];
|
603 |
+
$themes = $this->installer_theme_get_themes( $products_url, $k );
|
604 |
+
if ( (is_array( $themes )) && (!(empty($themes))) ) {
|
605 |
+
//Repo has themes
|
606 |
+
$repositories_with_themes[] = $k;
|
607 |
+
}
|
608 |
+
}
|
609 |
+
}
|
610 |
+
} else {
|
611 |
+
//Already set
|
612 |
+
$repositories_with_themes = $themes;
|
613 |
+
}
|
614 |
+
|
615 |
+
if ( (((is_array( $repositories_with_themes )) && (!(empty($repositories_with_themes)))) && (!($themes))) || ($doing_api_query) ) {
|
616 |
+
//Save to db
|
617 |
+
update_option( 'installer_repositories_with_theme', $repositories_with_themes );
|
618 |
+
}
|
619 |
+
}
|
620 |
+
|
621 |
+
if ( $ret_value ) {
|
622 |
+
return $repositories_with_themes;
|
623 |
+
}
|
624 |
+
|
625 |
+
}
|
626 |
+
|
627 |
+
/** When WordPress queries its own Themes API, we sync with our own */
|
628 |
+
public function installer_theme_sync_native_wp_api( $response, $responsetext, $class, $args, $url ) {
|
629 |
+
|
630 |
+
$api_native_string = 'api.wordpress.org/themes/';
|
631 |
+
if ( (strpos( $url, $api_native_string ) !== false) ) {
|
632 |
+
//WordPress is querying its own themes API
|
633 |
+
$installer_repositories = WP_Installer()->get_repositories();
|
634 |
+
|
635 |
+
//Query our own API and update repository values too
|
636 |
+
$this->installer_theme_reposities_that_has_themes( $installer_repositories, false, true );
|
637 |
+
}
|
638 |
+
}
|
639 |
+
|
640 |
+
/** Returns product name by theme repo slug */
|
641 |
+
private function installer_theme_get_repo_product_name( $theme_repo ) {
|
642 |
+
|
643 |
+
$theme_repo_name = false;
|
644 |
+
|
645 |
+
if ( isset(WP_Installer()->settings['repositories'][$theme_repo]['data']['product-name']) ) {
|
646 |
+
//Set
|
647 |
+
$prod_name = WP_Installer()->settings['repositories'][$theme_repo]['data']['product-name'];
|
648 |
+
if ( !(empty($prod_name)) ) {
|
649 |
+
$theme_repo_name = $prod_name;
|
650 |
+
}
|
651 |
+
} else {
|
652 |
+
//Not yet
|
653 |
+
if ( $theme_repo == $this->theme_repo ) {
|
654 |
+
$result = $this->installer_theme_general_api_query();
|
655 |
+
if ( isset($result['product-name']) ) {
|
656 |
+
$product_name = $result['product-name'];
|
657 |
+
if ( !(empty($product_name)) ) {
|
658 |
+
$theme_repo_name = $product_name;
|
659 |
+
}
|
660 |
+
}
|
661 |
+
}
|
662 |
+
}
|
663 |
+
|
664 |
+
return $theme_repo_name;
|
665 |
+
}
|
666 |
+
|
667 |
+
/** General query API method, returns $products */
|
668 |
+
private function installer_theme_general_api_query() {
|
669 |
+
$products = false;
|
670 |
+
$response = wp_remote_get( $this->repository_theme_products );
|
671 |
+
if ( !(is_wp_error( $response )) ) {
|
672 |
+
//Not WP error
|
673 |
+
//Evaluate response
|
674 |
+
if ( $response && isset($response['response']['code']) && $response['response']['code'] == 200 ) {
|
675 |
+
//In this case, response is set and defined, proceed...
|
676 |
+
$body = wp_remote_retrieve_body( $response );
|
677 |
+
if ( $body ) {
|
678 |
+
$result = json_decode( $body, true );
|
679 |
+
if ( (is_array( $result )) && (!(empty($result))) ) {
|
680 |
+
$products = $result;
|
681 |
+
}
|
682 |
+
}
|
683 |
+
|
684 |
+
}
|
685 |
+
}
|
686 |
+
|
687 |
+
return $products;
|
688 |
+
}
|
689 |
+
|
690 |
+
/** General method to check if themes are OTGS themes based on its slug*/
|
691 |
+
private function installer_themes_belong_to_us( $theme_slug ) {
|
692 |
+
|
693 |
+
$found = false;
|
694 |
+
$theme_slug = trim( $theme_slug );
|
695 |
+
|
696 |
+
foreach ( $this->installer_themes as $repo_with_theme => $themes ) {
|
697 |
+
foreach ( $themes as $k => $otgs_theme_slug ) {
|
698 |
+
if ( $theme_slug == $otgs_theme_slug ) {
|
699 |
+
//match found! Theme belongs to otgs
|
700 |
+
return true;
|
701 |
+
}
|
702 |
+
}
|
703 |
+
}
|
704 |
+
return $found;
|
705 |
+
|
706 |
+
}
|
707 |
+
|
708 |
+
/** Sets active tab on init */
|
709 |
+
public function installer_theme_sets_active_tab_on_init() {
|
710 |
+
|
711 |
+
if ( isset ($_SERVER ['REQUEST_URI']) ) {
|
712 |
+
$request_uri = $_SERVER ['REQUEST_URI'];
|
713 |
+
if ( isset ($_GET ['browse']) ) {
|
714 |
+
$active_tab = sanitize_text_field( $_GET['browse'] );
|
715 |
+
$this->installer_theme_active_tab = $active_tab;
|
716 |
+
} elseif ( isset ($_POST ['request'] ['browse']) ) {
|
717 |
+
$active_tab = sanitize_text_field ( $_POST['request']['browse'] );
|
718 |
+
$this->installer_theme_active_tab = $active_tab;
|
719 |
+
} elseif ( (isset ($_GET ['theme_repo'])) && (isset ($_GET ['action'])) ) {
|
720 |
+
$theme_repo = sanitize_text_field( $_GET['theme_repo'] );
|
721 |
+
$the_action = sanitize_text_field( $_GET['action'] );
|
722 |
+
if ( ('install-theme' == $the_action) && (!(empty($theme_repo))) ) {
|
723 |
+
$this->installer_theme_active_tab = $theme_repo;
|
724 |
+
}
|
725 |
+
} elseif ( wp_get_referer() ) {
|
726 |
+
$referer = wp_get_referer();
|
727 |
+
$parts = parse_url( $referer );
|
728 |
+
if ( isset($parts['query']) ) {
|
729 |
+
parse_str( $parts['query'], $query );
|
730 |
+
if ( isset($query['browse']) ) {
|
731 |
+
$this->installer_theme_active_tab = $query['browse'];
|
732 |
+
}
|
733 |
+
}
|
734 |
+
}
|
735 |
+
}
|
736 |
+
}
|
737 |
+
|
738 |
+
/** WP Theme API compatibility- added num ratings */
|
739 |
+
/** Installer 1.7.6+ Added updated 'rating' field */
|
740 |
+
public function installer_theme_add_num_ratings( $themes ) {
|
741 |
+
|
742 |
+
if ( (is_array( $themes )) && (!(empty($themes))) ) {
|
743 |
+
foreach ( $themes as $k => $v ) {
|
744 |
+
if ( !(isset($v->num_ratings)) ) {
|
745 |
+
$themes[$k]->num_ratings = 100;
|
746 |
+
}
|
747 |
+
if ( !(isset($v->rating)) ) {
|
748 |
+
$themes[$k]->rating = 100;
|
749 |
+
}
|
750 |
+
}
|
751 |
+
}
|
752 |
+
|
753 |
+
return $themes;
|
754 |
+
}
|
755 |
+
|
756 |
+
/** When WordPress.org makes a call to its repository, let's run our own upgrade checks too */
|
757 |
+
public function installer_theme_sync_call_wp_theme_api( $locales ) {
|
758 |
+
|
759 |
+
$this->installer_theme_upgrade_theme_check();
|
760 |
+
|
761 |
+
return $locales;
|
762 |
+
}
|
763 |
+
|
764 |
+
/** Upgrade theme check */
|
765 |
+
private function installer_theme_upgrade_theme_check() {
|
766 |
+
|
767 |
+
// Step1-> we get all installed themes in clients local themes directory
|
768 |
+
$installed_themes = wp_get_themes();
|
769 |
+
|
770 |
+
// Step2: We need to loop through each repository with themes
|
771 |
+
foreach ( $this->installer_repo_with_themes as $k => $repo_slug ) {
|
772 |
+
|
773 |
+
// We then need to retrieved the products URL for each of this repo
|
774 |
+
$products_url = $this->repository_theme_products [$repo_slug];
|
775 |
+
|
776 |
+
// Step3-> we get all available themes in our repository via API based on this URL
|
777 |
+
$available_themes = $this->installer_theme_get_themes( $products_url, $repo_slug );
|
778 |
+
|
779 |
+
if ( !($available_themes) ) {
|
780 |
+
|
781 |
+
// API is not available as of the moment, return..
|
782 |
+
return;
|
783 |
+
} else {
|
784 |
+
|
785 |
+
// We have available themes here...
|
786 |
+
// Step4->let's simplify available themes data by slugs
|
787 |
+
$simplified_available_themes = $this->installer_theme_savethemes_by_slug( $available_themes, true );
|
788 |
+
|
789 |
+
// Step5->Let's loop through installed themes
|
790 |
+
if ( (is_array( $installed_themes )) && (!(empty ($installed_themes))) ) {
|
791 |
+
$otgs_theme_updates_available = array();
|
792 |
+
foreach ( $installed_themes as $theme_slug => $theme_object ) {
|
793 |
+
if ( array_key_exists( $theme_slug, $simplified_available_themes ) ) {
|
794 |
+
|
795 |
+
// This is our theme
|
796 |
+
// Step6->Let's get version of the local theme installed
|
797 |
+
$local_version = $theme_object->get( 'Version' );
|
798 |
+
|
799 |
+
// Step7->Let's get the latest version of this theme, page URL and download URL from our repository
|
800 |
+
$repository_version = $simplified_available_themes [$theme_slug] ['version'];
|
801 |
+
$theme_page_url = $simplified_available_themes [$theme_slug] ['theme_page_url'];
|
802 |
+
$theme_download_url = $simplified_available_themes [$theme_slug] ['url'];
|
803 |
+
|
804 |
+
// Step8->Let's compare the version
|
805 |
+
if ( version_compare( $repository_version, $local_version, '>' ) ) {
|
806 |
+
|
807 |
+
// Update available for this theme
|
808 |
+
// Step9-> Define download URL with site key
|
809 |
+
$package_url = WP_Installer()->append_site_key_to_download_url( $theme_download_url, $this->installer_site_key [$repo_slug], $repo_slug );
|
810 |
+
|
811 |
+
//Step10-> Assign to updates array for later accessing.
|
812 |
+
$otgs_theme_updates_available[$theme_slug] = array(
|
813 |
+
'theme' => $theme_slug,
|
814 |
+
'new_version' => $repository_version,
|
815 |
+
'url' => $theme_page_url,
|
816 |
+
'package' => $package_url
|
817 |
+
);
|
818 |
+
}
|
819 |
+
}
|
820 |
+
}
|
821 |
+
//Exited the upgrade loop for this specific theme repository
|
822 |
+
if ( !(empty($otgs_theme_updates_available)) ) {
|
823 |
+
//Has updates
|
824 |
+
update_option( $this->installer_themes_available_updates[$repo_slug], $otgs_theme_updates_available );
|
825 |
+
} else {
|
826 |
+
//No updates
|
827 |
+
delete_option( $this->installer_themes_available_updates[$repo_slug] );
|
828 |
+
}
|
829 |
+
|
830 |
+
}
|
831 |
+
}
|
832 |
+
}
|
833 |
+
}
|
834 |
+
|
835 |
+
/** When the user is on Themes install page OTG themes repository, let's the currently selected tab */
|
836 |
+
public function installer_theme_add_query_arg_tab( $url, $path, $blog_id = null ) {
|
837 |
+
|
838 |
+
$wp_install_string = 'update.php?action=install-theme';
|
839 |
+
if ( $path == $wp_install_string ) {
|
840 |
+
if ( isset($this->installer_theme_active_tab) ) {
|
841 |
+
if ( !(empty($this->installer_theme_active_tab)) ) {
|
842 |
+
$url = add_query_arg( array(
|
843 |
+
'theme_repo' => $this->installer_theme_active_tab
|
844 |
+
), $url );
|
845 |
+
}
|
846 |
+
}
|
847 |
+
}
|
848 |
+
return $url;
|
849 |
+
}
|
850 |
+
|
851 |
+
/** Save frontend theme tab selected */
|
852 |
+
public function installer_theme_frontend_selected_tab() {
|
853 |
+
if ( isset($_POST["frontend_tab_selected"]) ) {
|
854 |
+
check_ajax_referer( 'installer_theme_frontend_selected_tab', 'installer_theme_frontend_selected_tab_nonce' );
|
855 |
+
|
856 |
+
//Client_side_active_tab
|
857 |
+
$frontend_tab_selected = sanitize_text_field( $_POST['frontend_tab_selected'] );
|
858 |
+
if ( !(empty($frontend_tab_selected)) ) {
|
859 |
+
//Front end tab selected
|
860 |
+
update_option( 'wp_installer_clientside_active_tab', $frontend_tab_selected, false );
|
861 |
+
|
862 |
+
//Check for registration status
|
863 |
+
if ( isset($this->theme_user_registration[$frontend_tab_selected]) ) {
|
864 |
+
//Set
|
865 |
+
if ( !($this->theme_user_registration[$frontend_tab_selected]) ) {
|
866 |
+
//Not registered yet
|
867 |
+
|
868 |
+
if ( is_multisite() ) {
|
869 |
+
$admin_url_passed = network_admin_url();
|
870 |
+
} else {
|
871 |
+
$admin_url_passed = admin_url();
|
872 |
+
}
|
873 |
+
|
874 |
+
$registration_url = $admin_url_passed . 'plugin-install.php?tab=commercial#installer_repo_' . $frontend_tab_selected;
|
875 |
+
|
876 |
+
//Message and link
|
877 |
+
$theme_repo_name = $this->installer_theme_get_repo_product_name( $frontend_tab_selected );;
|
878 |
+
$response['unregistered_messages'] = sprintf( __( 'To install and update %s, please %sregister%s %s for this site.', 'installer' ),
|
879 |
+
$theme_repo_name, '<a href="' . $registration_url . '">', '</a>', $theme_repo_name );
|
880 |
+
|
881 |
+
}
|
882 |
+
}
|
883 |
+
|
884 |
+
$response['output'] = $frontend_tab_selected;
|
885 |
+
echo json_encode( $response );
|
886 |
+
}
|
887 |
+
die();
|
888 |
+
}
|
889 |
+
die();
|
890 |
+
}
|
891 |
+
|
892 |
+
/** Installer loaded aux hooks */
|
893 |
+
public function installer_theme_loaded_hooks() {
|
894 |
+
|
895 |
+
if ( isset($this->installer_theme_subscription_type) ) {
|
896 |
+
$subscription_type = intval( $this->installer_theme_subscription_type );
|
897 |
+
if ( $subscription_type > 0 ) {
|
898 |
+
//Client is subscribed
|
899 |
+
add_filter( 'installer_theme_get_themes', array($this, 'installer_theme_filter_themes_by_subscription'), 10, 2 );
|
900 |
+
}
|
901 |
+
}
|
902 |
+
|
903 |
+
}
|
904 |
+
|
905 |
+
/** Get themes by subscription type */
|
906 |
+
protected function installer_theme_get_themes_by_subscription( $subscription_type, $repo ) {
|
907 |
+
|
908 |
+
$themes_associated_with_subscription = array();
|
909 |
+
if ( isset(WP_Installer()->settings['repositories'][$repo]['data']['packages']) ) {
|
910 |
+
//Set
|
911 |
+
$packages = WP_Installer()->settings['repositories'][$repo]['data']['packages'];
|
912 |
+
$available_themes_subscription = array();
|
913 |
+
foreach ( $packages as $package_id => $package_details ) {
|
914 |
+
if ( isset($package_details['products']) ) {
|
915 |
+
$the_products = $package_details['products'];
|
916 |
+
foreach ( $the_products as $product_slug => $product_details ) {
|
917 |
+
if ( isset($product_details['subscription_type']) ) {
|
918 |
+
$subscription_type_from_settings = intval( $product_details['subscription_type'] );
|
919 |
+
if ( $subscription_type_from_settings == $subscription_type ) {
|
920 |
+
//We found the subscription
|
921 |
+
if ( isset($product_details['themes']) ) {
|
922 |
+
$themes_associated_with_subscription = $product_details['themes'];
|
923 |
+
return $themes_associated_with_subscription;
|
924 |
+
}
|
925 |
+
}
|
926 |
+
}
|
927 |
+
|
928 |
+
}
|
929 |
+
}
|
930 |
+
}
|
931 |
+
}
|
932 |
+
return $themes_associated_with_subscription;
|
933 |
+
}
|
934 |
+
|
935 |
+
/** Filter API theme response according to user subscription */
|
936 |
+
public function installer_theme_filter_themes_by_subscription( $themes, $active_tab ) {
|
937 |
+
|
938 |
+
//Step1, we only filter OTGS themes
|
939 |
+
$orig = count( $themes );
|
940 |
+
if ( in_array( $active_tab, $this->theme_repo ) ) {
|
941 |
+
//OTGS Theme
|
942 |
+
//Step2, we retrieved the available themes based on client subscription
|
943 |
+
if ( isset($this->installer_themes[$active_tab]) ) {
|
944 |
+
$available_themes = $this->installer_themes[$active_tab];
|
945 |
+
//Step3, we filter $themes based on this info
|
946 |
+
if ( (is_array( $themes )) && (!(empty($themes))) ) {
|
947 |
+
foreach ( $themes as $k => $theme ) {
|
948 |
+
//Step4, get theme slug
|
949 |
+
if ( isset($theme['slug']) ) {
|
950 |
+
$theme_slug = $theme['slug'];
|
951 |
+
if ( !(empty($theme_slug)) ) {
|
952 |
+
if ( !(in_array( $theme_slug, $available_themes )) ) {
|
953 |
+
//This theme is not in available themes
|
954 |
+
unset($themes[$k]);
|
955 |
+
}
|
956 |
+
}
|
957 |
+
}
|
958 |
+
}
|
959 |
+
}
|
960 |
+
}
|
961 |
+
}
|
962 |
+
$new = count( $themes );
|
963 |
+
if ( $orig != $new ) {
|
964 |
+
//It is filtered
|
965 |
+
$themes = array_values( $themes );
|
966 |
+
}
|
967 |
+
|
968 |
+
return $themes;
|
969 |
+
}
|
970 |
+
|
971 |
+
/** Hook to wp_loaded, fires when all Installer theme class is ready */
|
972 |
+
public function installer_themes_support_set_up_func() {
|
973 |
+
do_action( 'installer_themes_support_set_up' );
|
974 |
+
}
|
975 |
+
|
976 |
+
}
|
977 |
+
|
978 |
+
/** Instantiate Installer Theme Class */
|
979 |
new Installer_Theme_Class;
|
library/otgs/installer/includes/installer-api.php
CHANGED
@@ -1,116 +1,116 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WP_Installer_API{
|
4 |
-
|
5 |
-
public static function get_product_installer_link($repository_id, $package_id = false){
|
6 |
-
|
7 |
-
$menu_url = WP_Installer()->menu_url();
|
8 |
-
|
9 |
-
$url = $menu_url . '#' . $repository_id;
|
10 |
-
if($package_id){
|
11 |
-
$url .= '/' . $package_id;
|
12 |
-
}
|
13 |
-
|
14 |
-
return $url;
|
15 |
-
|
16 |
-
}
|
17 |
-
|
18 |
-
public static function get_product_price($repository_id, $package_id, $product_id, $incl_discount = false){
|
19 |
-
|
20 |
-
$price = WP_Installer()->get_product_price($repository_id, $package_id, $product_id, $incl_discount);
|
21 |
-
|
22 |
-
return $price;
|
23 |
-
}
|
24 |
-
|
25 |
-
/**
|
26 |
-
* Retrieve the preferred translation service.
|
27 |
-
*
|
28 |
-
* @since 1.6.5
|
29 |
-
*
|
30 |
-
* @param string The repository id (e.g. wpml)
|
31 |
-
* @return string The translation service id
|
32 |
-
*/
|
33 |
-
public static function get_preferred_ts($repository_id = 'wpml'){
|
34 |
-
|
35 |
-
if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'])){
|
36 |
-
return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'];
|
37 |
-
}
|
38 |
-
|
39 |
-
return false;
|
40 |
-
|
41 |
-
}
|
42 |
-
|
43 |
-
/**
|
44 |
-
* Set the preferred translation service.
|
45 |
-
*
|
46 |
-
* @since 1.6.5
|
47 |
-
*
|
48 |
-
* @param string The translation service id
|
49 |
-
* @param string The repository id (e.g. wpml)
|
50 |
-
*/
|
51 |
-
public static function set_preferred_ts( $value, $repository_id = 'wpml' ){
|
52 |
-
|
53 |
-
if( isset( WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'] ) ){
|
54 |
-
|
55 |
-
WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'] = $value;
|
56 |
-
|
57 |
-
WP_Installer()->save_settings();
|
58 |
-
|
59 |
-
}
|
60 |
-
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Retrieve the referring translation service (if any)
|
65 |
-
*
|
66 |
-
* @since 1.6.5
|
67 |
-
*
|
68 |
-
* @param string The repository id (e.g. wpml)
|
69 |
-
* @return string The translation service id or false
|
70 |
-
*/
|
71 |
-
public static function get_ts_referal($repository_id = 'wpml'){
|
72 |
-
|
73 |
-
if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['referal'])){
|
74 |
-
return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['referal'];
|
75 |
-
}
|
76 |
-
|
77 |
-
return false;
|
78 |
-
|
79 |
-
}
|
80 |
-
|
81 |
-
/**
|
82 |
-
* Retrieve the translation services client id for a specific repository (if any)
|
83 |
-
*
|
84 |
-
* @since 1.7.9
|
85 |
-
*
|
86 |
-
* @param string The repository id (e.g. wpml)
|
87 |
-
* @return string The client id or false
|
88 |
-
*/
|
89 |
-
public static function get_ts_client_id( $repository_id = 'wpml' ){
|
90 |
-
|
91 |
-
if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['client_id'])){
|
92 |
-
return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['client_id'];
|
93 |
-
}
|
94 |
-
|
95 |
-
return false;
|
96 |
-
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* Retrieve the site key corresponding to a repository.
|
101 |
-
* This is a wrapper of WP_Installer::get_site_key()
|
102 |
-
* @see WP_Installer::get_site_key()
|
103 |
-
*
|
104 |
-
* @since 1.7.9
|
105 |
-
*
|
106 |
-
* @param string The repository id (e.g. wpml)
|
107 |
-
* @return string The site key (or false)
|
108 |
-
*/
|
109 |
-
public static function get_site_key( $repository_id = 'wpml' ){
|
110 |
-
|
111 |
-
return WP_Installer()->get_site_key( $repository_id );
|
112 |
-
|
113 |
-
}
|
114 |
-
|
115 |
-
|
116 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WP_Installer_API{
|
4 |
+
|
5 |
+
public static function get_product_installer_link($repository_id, $package_id = false){
|
6 |
+
|
7 |
+
$menu_url = WP_Installer()->menu_url();
|
8 |
+
|
9 |
+
$url = $menu_url . '#' . $repository_id;
|
10 |
+
if($package_id){
|
11 |
+
$url .= '/' . $package_id;
|
12 |
+
}
|
13 |
+
|
14 |
+
return $url;
|
15 |
+
|
16 |
+
}
|
17 |
+
|
18 |
+
public static function get_product_price($repository_id, $package_id, $product_id, $incl_discount = false){
|
19 |
+
|
20 |
+
$price = WP_Installer()->get_product_price($repository_id, $package_id, $product_id, $incl_discount);
|
21 |
+
|
22 |
+
return $price;
|
23 |
+
}
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Retrieve the preferred translation service.
|
27 |
+
*
|
28 |
+
* @since 1.6.5
|
29 |
+
*
|
30 |
+
* @param string The repository id (e.g. wpml)
|
31 |
+
* @return string The translation service id
|
32 |
+
*/
|
33 |
+
public static function get_preferred_ts($repository_id = 'wpml'){
|
34 |
+
|
35 |
+
if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'])){
|
36 |
+
return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'];
|
37 |
+
}
|
38 |
+
|
39 |
+
return false;
|
40 |
+
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Set the preferred translation service.
|
45 |
+
*
|
46 |
+
* @since 1.6.5
|
47 |
+
*
|
48 |
+
* @param string The translation service id
|
49 |
+
* @param string The repository id (e.g. wpml)
|
50 |
+
*/
|
51 |
+
public static function set_preferred_ts( $value, $repository_id = 'wpml' ){
|
52 |
+
|
53 |
+
if( isset( WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'] ) ){
|
54 |
+
|
55 |
+
WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'] = $value;
|
56 |
+
|
57 |
+
WP_Installer()->save_settings();
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Retrieve the referring translation service (if any)
|
65 |
+
*
|
66 |
+
* @since 1.6.5
|
67 |
+
*
|
68 |
+
* @param string The repository id (e.g. wpml)
|
69 |
+
* @return string The translation service id or false
|
70 |
+
*/
|
71 |
+
public static function get_ts_referal($repository_id = 'wpml'){
|
72 |
+
|
73 |
+
if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['referal'])){
|
74 |
+
return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['referal'];
|
75 |
+
}
|
76 |
+
|
77 |
+
return false;
|
78 |
+
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Retrieve the translation services client id for a specific repository (if any)
|
83 |
+
*
|
84 |
+
* @since 1.7.9
|
85 |
+
*
|
86 |
+
* @param string The repository id (e.g. wpml)
|
87 |
+
* @return string The client id or false
|
88 |
+
*/
|
89 |
+
public static function get_ts_client_id( $repository_id = 'wpml' ){
|
90 |
+
|
91 |
+
if(isset(WP_Installer()->settings['repositories'][$repository_id]['ts_info']['client_id'])){
|
92 |
+
return WP_Installer()->settings['repositories'][$repository_id]['ts_info']['client_id'];
|
93 |
+
}
|
94 |
+
|
95 |
+
return false;
|
96 |
+
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Retrieve the site key corresponding to a repository.
|
101 |
+
* This is a wrapper of WP_Installer::get_site_key()
|
102 |
+
* @see WP_Installer::get_site_key()
|
103 |
+
*
|
104 |
+
* @since 1.7.9
|
105 |
+
*
|
106 |
+
* @param string The repository id (e.g. wpml)
|
107 |
+
* @return string The site key (or false)
|
108 |
+
*/
|
109 |
+
public static function get_site_key( $repository_id = 'wpml' ){
|
110 |
+
|
111 |
+
return WP_Installer()->get_site_key( $repository_id );
|
112 |
+
|
113 |
+
}
|
114 |
+
|
115 |
+
|
116 |
}
|
library/otgs/installer/includes/installer-upgrader-skins.php
CHANGED
@@ -1,37 +1,37 @@
|
|
1 |
-
<?php
|
2 |
-
class Installer_Upgrader_Skins extends WP_Upgrader_Skin{
|
3 |
-
|
4 |
-
function __construct($args = array()){
|
5 |
-
$defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
|
6 |
-
$this->options = wp_parse_args($args, $defaults);
|
7 |
-
}
|
8 |
-
|
9 |
-
function header(){
|
10 |
-
|
11 |
-
}
|
12 |
-
|
13 |
-
function footer(){
|
14 |
-
|
15 |
-
}
|
16 |
-
|
17 |
-
function error($error){
|
18 |
-
$this->installer_error = $error;
|
19 |
-
}
|
20 |
-
|
21 |
-
function add_strings(){
|
22 |
-
|
23 |
-
}
|
24 |
-
|
25 |
-
function feedback($string){
|
26 |
-
|
27 |
-
}
|
28 |
-
|
29 |
-
function before(){
|
30 |
-
|
31 |
-
}
|
32 |
-
|
33 |
-
function after(){
|
34 |
-
|
35 |
-
}
|
36 |
-
|
37 |
}
|
1 |
+
<?php
|
2 |
+
class Installer_Upgrader_Skins extends WP_Upgrader_Skin{
|
3 |
+
|
4 |
+
function __construct($args = array()){
|
5 |
+
$defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
|
6 |
+
$this->options = wp_parse_args($args, $defaults);
|
7 |
+
}
|
8 |
+
|
9 |
+
function header(){
|
10 |
+
|
11 |
+
}
|
12 |
+
|
13 |
+
function footer(){
|
14 |
+
|
15 |
+
}
|
16 |
+
|
17 |
+
function error($error){
|
18 |
+
$this->installer_error = $error;
|
19 |
+
}
|
20 |
+
|
21 |
+
function add_strings(){
|
22 |
+
|
23 |
+
}
|
24 |
+
|
25 |
+
function feedback($string){
|
26 |
+
|
27 |
+
}
|
28 |
+
|
29 |
+
function before(){
|
30 |
+
|
31 |
+
}
|
32 |
+
|
33 |
+
function after(){
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
}
|
library/otgs/installer/includes/installer.class.php
CHANGED
@@ -1,2672 +1,2672 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
final class WP_Installer{
|
4 |
-
protected static $_instance = null;
|
5 |
-
|
6 |
-
public $settings = array();
|
7 |
-
|
8 |
-
private $repositories = array();
|
9 |
-
|
10 |
-
protected $api_debug = '';
|
11 |
-
|
12 |
-
private $config = array();
|
13 |
-
|
14 |
-
protected $_plugins_renew_warnings = array();
|
15 |
-
|
16 |
-
protected $_gz_on = false;
|
17 |
-
|
18 |
-
private $admin_messages = array();
|
19 |
-
|
20 |
-
private $_using_icl = false;
|
21 |
-
private $_wpml_version = false;
|
22 |
-
|
23 |
-
private $package_source = array();
|
24 |
-
|
25 |
-
const SITE_KEY_VALIDATION_SOURCE_OTHER = 0;
|
26 |
-
const SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_SPECIFIC = 1;
|
27 |
-
const SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_REPORT = 2;
|
28 |
-
const SITE_KEY_VALIDATION_SOURCE_REGISTRATION = 3;
|
29 |
-
const SITE_KEY_VALIDATION_SOURCE_REVALIDATION = 4;
|
30 |
-
const SITE_KEY_VALIDATION_SOURCE_UPDATES_CHECK = 5;
|
31 |
-
|
32 |
-
public $dependencies;
|
33 |
-
|
34 |
-
public static function instance() {
|
35 |
-
|
36 |
-
if ( is_null( self::$_instance ) ) {
|
37 |
-
self::$_instance = new self();
|
38 |
-
}
|
39 |
-
|
40 |
-
return self::$_instance;
|
41 |
-
}
|
42 |
-
|
43 |
-
public function __construct(){
|
44 |
-
|
45 |
-
if(!is_admin() || !is_user_logged_in()) return; //Only for admin
|
46 |
-
|
47 |
-
$this->_gz_on = function_exists('gzuncompress') && function_exists('gzcompress');
|
48 |
-
$this->settings = $this->get_settings();
|
49 |
-
|
50 |
-
add_action('admin_notices', array($this, 'show_site_key_nags'));
|
51 |
-
|
52 |
-
add_action('admin_notices', array($this, 'show_admin_messages'));
|
53 |
-
|
54 |
-
add_action('admin_init', array($this, 'load_embedded_plugins'), 0);
|
55 |
-
|
56 |
-
add_action('admin_menu', array($this, 'menu_setup'));
|
57 |
-
add_action('network_admin_menu', array($this, 'menu_setup'));
|
58 |
-
|
59 |
-
if(defined('DOING_AJAX') && isset($_POST['action']) && $_POST['action'] == 'installer_download_plugin'){
|
60 |
-
add_filter( 'site_transient_update_plugins', array( $this, 'plugins_upgrade_check') );
|
61 |
-
}
|
62 |
-
add_filter('plugins_api', array( $this, 'custom_plugins_api_call'), 10, 3);
|
63 |
-
add_filter('pre_set_site_transient_update_plugins', array( $this, 'plugins_upgrade_check'));
|
64 |
-
|
65 |
-
// register repositories
|
66 |
-
$this->load_repositories_list();
|
67 |
-
|
68 |
-
if( empty($this->settings['last_repositories_update']) || time() - $this->settings['last_repositories_update'] > 86400
|
69 |
-
|| ( isset($_GET['force-check']) && $_GET['force-check'] == 1 ) ){
|
70 |
-
$this->refresh_repositories_data();
|
71 |
-
}
|
72 |
-
|
73 |
-
// default config
|
74 |
-
$this->config['plugins_install_tab'] = false;
|
75 |
-
|
76 |
-
add_action('init', array($this, 'init'));
|
77 |
-
|
78 |
-
//add_filter('wp_installer_buy_url', array($this, 'append_parameters_to_buy_url'));
|
79 |
-
|
80 |
-
add_action('init', array($this,'load_locale'));
|
81 |
-
|
82 |
-
}
|
83 |
-
|
84 |
-
public function get_repositories() {
|
85 |
-
|
86 |
-
return $this->repositories;
|
87 |
-
|
88 |
-
}
|
89 |
-
|
90 |
-
public function set_config($key, $value){
|
91 |
-
|
92 |
-
$this->config[$key] = $value;
|
93 |
-
|
94 |
-
}
|
95 |
-
|
96 |
-
public function init(){
|
97 |
-
global $pagenow;
|
98 |
-
|
99 |
-
$this->dependencies = new Installer_Dependencies;
|
100 |
-
|
101 |
-
if(empty($this->settings['_pre_1_0_clean_up'])) {
|
102 |
-
$this->_pre_1_0_clean_up();
|
103 |
-
}
|
104 |
-
|
105 |
-
$this->settings = $this->_old_products_format_backwards_compatibility($this->settings);
|
106 |
-
|
107 |
-
if ( !function_exists( 'get_plugins' ) ) {
|
108 |
-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
109 |
-
}
|
110 |
-
|
111 |
-
$this->_using_icl = function_exists('wpml_site_uses_icl') && wpml_site_uses_icl();
|
112 |
-
$this->_wpml_version = defined('ICL_SITEPRESS_VERSION') ? ICL_SITEPRESS_VERSION : '';
|
113 |
-
|
114 |
-
wp_enqueue_script('installer-admin', $this->res_url() . '/res/js/admin.js', array('jquery'), $this->version());
|
115 |
-
wp_enqueue_style('installer-admin', $this->res_url() . '/res/css/admin.css', array(), $this->version());
|
116 |
-
|
117 |
-
$translation_array = array(
|
118 |
-
'installing' => __( 'Installing %s', 'installer' ),
|
119 |
-
'updating' => __( 'Updating %s', 'installer' ),
|
120 |
-
'activating' => __( 'Activating %s', 'installer' )
|
121 |
-
);
|
122 |
-
|
123 |
-
wp_localize_script( 'installer-admin', 'installer_strings', $translation_array );
|
124 |
-
|
125 |
-
if($pagenow == 'plugins.php'){
|
126 |
-
add_action('admin_notices', array($this, 'setup_plugins_page_notices'));
|
127 |
-
add_action('admin_notices', array($this, 'setup_plugins_renew_warnings'), 10);
|
128 |
-
add_action('admin_notices', array($this, 'queue_plugins_renew_warnings'), 20);
|
129 |
-
|
130 |
-
add_action('admin_init', array($this, 'setup_plugins_action_links'));
|
131 |
-
|
132 |
-
}
|
133 |
-
|
134 |
-
if($this->is_repositories_page()){
|
135 |
-
add_action('admin_init', array($this, 'validate_repository_subscription'));
|
136 |
-
}
|
137 |
-
|
138 |
-
if(defined('DOING_AJAX')){
|
139 |
-
add_action('wp_ajax_save_site_key', array($this, 'save_site_key'));
|
140 |
-
add_action('wp_ajax_remove_site_key', array($this, 'remove_site_key_ajax'));
|
141 |
-
add_action('wp_ajax_update_site_key', array($this, 'update_site_key'));
|
142 |
-
|
143 |
-
add_action('wp_ajax_installer_download_plugin', array($this, 'download_plugin_ajax_handler'));
|
144 |
-
add_action('wp_ajax_installer_activate_plugin', array($this, 'activate_plugin'));
|
145 |
-
|
146 |
-
add_action('wp_ajax_installer_dismiss_nag', array($this, 'dismiss_nag'));
|
147 |
-
}
|
148 |
-
|
149 |
-
if($pagenow == 'update.php'){
|
150 |
-
if(isset($_GET['action']) && $_GET['action'] == 'update-selected'){
|
151 |
-
add_action('admin_head', array($this, 'plugin_upgrade_custom_errors')); //iframe/bulk
|
152 |
-
}else{
|
153 |
-
add_action('all_admin_notices', array($this, 'plugin_upgrade_custom_errors')); //regular/singular
|
154 |
-
}
|
155 |
-
}
|
156 |
-
|
157 |
-
// WP 4.2
|
158 |
-
if(defined('DOING_AJAX')){
|
159 |
-
add_action('wp_ajax_update-plugin', array($this, 'plugin_upgrade_custom_errors'), 0); // high priority, before WP
|
160 |
-
}
|
161 |
-
|
162 |
-
//Include theme support
|
163 |
-
include_once $this->plugin_path() . '/includes/class-installer-theme.php';
|
164 |
-
|
165 |
-
// Extra information about the source of Installer
|
166 |
-
$package_source_file = $this->plugin_path() . '/installer-source.json';
|
167 |
-
if( file_exists( $package_source_file ) ){
|
168 |
-
$this->package_source = json_decode( file_get_contents( $package_source_file ) );
|
169 |
-
}
|
170 |
-
}
|
171 |
-
|
172 |
-
protected function log($message){
|
173 |
-
if( defined('WPML_INSTALLER_LOGGING') && WPML_INSTALLER_LOGGING ){
|
174 |
-
if($fh = @fopen( $this->plugin_path() . '/installer.log', 'a' )){
|
175 |
-
fwrite($fh, current_time( 'mysql' ) . "\t" . $message . "\n");
|
176 |
-
}
|
177 |
-
}
|
178 |
-
}
|
179 |
-
|
180 |
-
public function register_admin_message($text, $type = 'updated'){
|
181 |
-
$this->admin_messages[] = array('text' => $text, 'type' => $type);
|
182 |
-
}
|
183 |
-
|
184 |
-
public function show_admin_messages(){
|
185 |
-
if(!empty($this->admin_messages)){
|
186 |
-
$types = array( 'error', 'updated', 'notice' );
|
187 |
-
foreach($this->admin_messages as $message){
|
188 |
-
$class = in_array( $message['type'], $types ) ? $message['type'] : 'updated';
|
189 |
-
?>
|
190 |
-
<div class="<?php echo $class ?>">
|
191 |
-
<p>
|
192 |
-
<?php echo $message['text'] ?>
|
193 |
-
</p>
|
194 |
-
</div>
|
195 |
-
<?php
|
196 |
-
}
|
197 |
-
}
|
198 |
-
}
|
199 |
-
|
200 |
-
public function load_locale(){
|
201 |
-
$locale = get_locale();
|
202 |
-
$locale = apply_filters( 'plugin_locale', $locale, 'installer' );
|
203 |
-
$mo_file = $this->plugin_path() . '/locale/installer-' . $locale . '.mo';
|
204 |
-
if(file_exists($mo_file)){
|
205 |
-
load_textdomain( 'installer', $mo_file );
|
206 |
-
}
|
207 |
-
}
|
208 |
-
|
209 |
-
public function load_embedded_plugins(){
|
210 |
-
if(file_exists($this->plugin_path() . '/embedded-plugins' )) {
|
211 |
-
include_once $this->plugin_path() . '/embedded-plugins/embedded-plugins.class.php';
|
212 |
-
$this->installer_embedded_plugins = new Installer_Embedded_Plugins();
|
213 |
-
}
|
214 |
-
}
|
215 |
-
|
216 |
-
public function menu_setup(){
|
217 |
-
global $pagenow;
|
218 |
-
|
219 |
-
if(is_multisite() && !is_network_admin()){
|
220 |
-
$this->menu_multisite_redirect();
|
221 |
-
add_options_page(__('Installer', 'installer'), __('Installer', 'installer'), 'manage_options', 'installer', array($this, 'show_products')) ;
|
222 |
-
}else{
|
223 |
-
if($this->config['plugins_install_tab'] && is_admin() && $pagenow == 'plugin-install.php'){
|
224 |
-
// Default GUI, under Plugins -> Install
|
225 |
-
add_filter('install_plugins_tabs', array($this, 'add_install_plugins_tab'));
|
226 |
-
add_action('install_plugins_commercial', array($this, 'show_products'));
|
227 |
-
}
|
228 |
-
}
|
229 |
-
|
230 |
-
}
|
231 |
-
|
232 |
-
public function menu_url(){
|
233 |
-
if(is_multisite()){
|
234 |
-
if(is_network_admin()){
|
235 |
-
$url = network_admin_url('plugin-install.php?tab=commercial');
|
236 |
-
}else{
|
237 |
-
$url = admin_url('options-general.php?page=installer');
|
238 |
-
}
|
239 |
-
}else{
|
240 |
-
$url = admin_url('plugin-install.php?tab=commercial');
|
241 |
-
}
|
242 |
-
return $url;
|
243 |
-
}
|
244 |
-
|
245 |
-
private function menu_multisite_redirect(){
|
246 |
-
global $pagenow;
|
247 |
-
|
248 |
-
if($pagenow == 'plugin-install.php' && isset($_GET['tab']) && $_GET['tab'] == 'commercial'){
|
249 |
-
wp_redirect($this->menu_url());
|
250 |
-
exit;
|
251 |
-
}
|
252 |
-
|
253 |
-
}
|
254 |
-
|
255 |
-
private function _pre_1_0_clean_up(){
|
256 |
-
global $wpdb;
|
257 |
-
|
258 |
-
if(!defined('WPRC_VERSION')){
|
259 |
-
$old_tables = array(
|
260 |
-
$wpdb->prefix . 'wprc_cached_requests',
|
261 |
-
$wpdb->prefix . 'wprc_extension_types',
|
262 |
-
$wpdb->prefix . 'wprc_extensions',
|
263 |
-
$wpdb->prefix . 'wprc_repositories',
|
264 |
-
$wpdb->prefix . 'wprc_repositories_relationships',
|
265 |
-
);
|
266 |
-
|
267 |
-
foreach($old_tables as $table){
|
268 |
-
$wpdb->query(sprintf("DROP TABLE IF EXISTS %s", $table));
|
269 |
-
}
|
270 |
-
|
271 |
-
}
|
272 |
-
|
273 |
-
$this->settings['_pre_1_0_clean_up'] = true;
|
274 |
-
$this->save_settings();
|
275 |
-
}
|
276 |
-
|
277 |
-
public function setup_plugins_action_links(){
|
278 |
-
|
279 |
-
$plugins = get_plugins();
|
280 |
-
|
281 |
-
$repositories_plugins = array();
|
282 |
-
|
283 |
-
if( !empty($this->settings['repositories']) ) {
|
284 |
-
|
285 |
-
foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
|
286 |
-
|
287 |
-
foreach ( $repository['data']['packages'] as $package ) {
|
288 |
-
|
289 |
-
foreach ( $package['products'] as $product ) {
|
290 |
-
|
291 |
-
foreach ( $product['plugins'] as $plugin_slug ) {
|
292 |
-
|
293 |
-
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
294 |
-
|
295 |
-
if ( !isset($repositories_plugins[$repository_id][$download['slug']]) ) {
|
296 |
-
$repositories_plugins[$repository_id][$download['slug']] = array(
|
297 |
-
'name' => $download['name'],
|
298 |
-
'registered' => $this->plugin_is_registered( $repository_id, $download['slug'] ) ? 1 : 0
|
299 |
-
);
|
300 |
-
}
|
301 |
-
|
302 |
-
}
|
303 |
-
|
304 |
-
}
|
305 |
-
|
306 |
-
}
|
307 |
-
|
308 |
-
foreach ( $plugins as $plugin_id => $plugin ) {
|
309 |
-
|
310 |
-
$wp_plugin_slug = dirname( $plugin_id );
|
311 |
-
if ( empty($wp_plugin_slug) ) {
|
312 |
-
$wp_plugin_slug = basename( $plugin_id, '.php' );
|
313 |
-
}
|
314 |
-
|
315 |
-
foreach ( $repositories_plugins as $repository_id => $r_plugins ) {
|
316 |
-
|
317 |
-
foreach ( $r_plugins as $slug => $r_plugin ) {
|
318 |
-
|
319 |
-
if ( $wp_plugin_slug == $slug || $r_plugin['name'] == $plugin['Name'] || $r_plugin['name'] == $plugin['Title'] ) { //match order: slug, name, title
|
320 |
-
|
321 |
-
if ( $r_plugin['registered'] ) {
|
322 |
-
add_filter( 'plugin_action_links_' . $plugin_id, array($this, 'plugins_action_links_registered') );
|
323 |
-
} else {
|
324 |
-
add_filter( 'plugin_action_links_' . $plugin_id, array($this, 'plugins_action_links_not_registered') );
|
325 |
-
}
|
326 |
-
|
327 |
-
}
|
328 |
-
|
329 |
-
}
|
330 |
-
|
331 |
-
}
|
332 |
-
|
333 |
-
|
334 |
-
}
|
335 |
-
|
336 |
-
}
|
337 |
-
}
|
338 |
-
|
339 |
-
}
|
340 |
-
|
341 |
-
public function plugins_action_links_registered($links){
|
342 |
-
$links[] = '<a href="' . $this->menu_url() . '">' . __('Registered', 'installer') . '</a>';
|
343 |
-
return $links;
|
344 |
-
}
|
345 |
-
|
346 |
-
public function plugins_action_links_not_registered($links){
|
347 |
-
$links[] = '<a href="' . $this->menu_url() . '">' . __('Register', 'installer') . '</a>';
|
348 |
-
return $links;
|
349 |
-
}
|
350 |
-
|
351 |
-
public function plugin_is_registered($repository_id, $slug){
|
352 |
-
|
353 |
-
$registered = false;
|
354 |
-
|
355 |
-
if( $this->repository_has_valid_subscription($repository_id) ){
|
356 |
-
|
357 |
-
$subscription_type = $this->get_subscription_type_for_repository($repository_id);
|
358 |
-
$r_plugins = array();
|
359 |
-
|
360 |
-
foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package){
|
361 |
-
|
362 |
-
foreach($package['products'] as $product){
|
363 |
-
|
364 |
-
if( $product['subscription_type'] == $subscription_type || $this->have_superior_subscription($subscription_type, $product) ) {
|
365 |
-
|
366 |
-
foreach ($product['plugins'] as $plugin_slug) {
|
367 |
-
|
368 |
-
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
369 |
-
|
370 |
-
if (!isset($rep_plugins[$download['slug']])) {
|
371 |
-
$r_plugins[$download['slug']] = $download['slug'];
|
372 |
-
}
|
373 |
-
|
374 |
-
}
|
375 |
-
|
376 |
-
}
|
377 |
-
|
378 |
-
}
|
379 |
-
|
380 |
-
}
|
381 |
-
|
382 |
-
$registered = isset($r_plugins[$slug]);
|
383 |
-
|
384 |
-
}
|
385 |
-
|
386 |
-
|
387 |
-
return $registered;
|
388 |
-
|
389 |
-
}
|
390 |
-
|
391 |
-
public function version(){
|
392 |
-
return WP_INSTALLER_VERSION;
|
393 |
-
}
|
394 |
-
|
395 |
-
public function plugin_path() {
|
396 |
-
return untrailingslashit( plugin_dir_path( dirname(__FILE__) ) );
|
397 |
-
}
|
398 |
-
|
399 |
-
public function plugin_url() {
|
400 |
-
if(isset($this->config['in_theme_folder']) && !empty($this->config['in_theme_folder'])){
|
401 |
-
$url = untrailingslashit(get_template_directory_uri() . '/' . $this->config['in_theme_folder']);
|
402 |
-
}else{
|
403 |
-
$url = untrailingslashit( plugins_url( '/', dirname(__FILE__) ) );
|
404 |
-
}
|
405 |
-
|
406 |
-
return $url;
|
407 |
-
}
|
408 |
-
|
409 |
-
public function is_repositories_page(){
|
410 |
-
global $pagenow;
|
411 |
-
|
412 |
-
return $pagenow == 'plugin-install.php' && isset($_GET['tab']) && $_GET['tab'] == 'commercial';
|
413 |
-
}
|
414 |
-
|
415 |
-
public function res_url(){
|
416 |
-
if(isset($this->config['in_theme_folder']) && !empty($this->config['in_theme_folder'])){
|
417 |
-
$url = untrailingslashit(get_template_directory_uri() . '/' . $this->config['in_theme_folder']);
|
418 |
-
}else{
|
419 |
-
$url = $this->plugin_url();
|
420 |
-
}
|
421 |
-
return $url;
|
422 |
-
}
|
423 |
-
|
424 |
-
public function save_settings(){
|
425 |
-
|
426 |
-
$_settings = serialize($this->settings);
|
427 |
-
if($this->_gz_on){
|
428 |
-
$_settings = gzcompress($_settings);
|
429 |
-
}
|
430 |
-
$_settings = base64_encode($_settings);
|
431 |
-
|
432 |
-
update_option( 'wp_installer_settings', $_settings );
|
433 |
-
|
434 |
-
if( is_multisite() && is_main_site() && isset($this->settings['repositories']) ){
|
435 |
-
$network_settings = array();
|
436 |
-
|
437 |
-
foreach( $this->settings['repositories'] as $rep_id => $repository ){
|
438 |
-
if( isset($repository['subscription']) )
|
439 |
-
$network_settings[$rep_id] = $repository['subscription'];
|
440 |
-
}
|
441 |
-
|
442 |
-
update_site_option( 'wp_installer_network', $network_settings );
|
443 |
-
|
444 |
-
|
445 |
-
}
|
446 |
-
|
447 |
-
}
|
448 |
-
|
449 |
-
public function get_settings($refresh = false){
|
450 |
-
|
451 |
-
if($refresh || empty($this->settings)){
|
452 |
-
|
453 |
-
$_settings = get_option('wp_installer_settings');
|
454 |
-
|
455 |
-
|
456 |
-
if (is_array($_settings) || empty($_settings)) { //backward compatibility 1.1
|
457 |
-
$this->settings = $_settings;
|
458 |
-
|
459 |
-
} else {
|
460 |
-
$_settings = base64_decode($_settings);
|
461 |
-
if ($this->_gz_on) {
|
462 |
-
$_settings = gzuncompress($_settings);
|
463 |
-
}
|
464 |
-
$this->settings = unserialize($_settings);
|
465 |
-
}
|
466 |
-
|
467 |
-
if (is_multisite() && isset($this->settings['repositories'])) {
|
468 |
-
$network_settings = maybe_unserialize(get_site_option('wp_installer_network'));
|
469 |
-
if ($network_settings) {
|
470 |
-
foreach ($this->settings['repositories'] as $rep_id => $repository) {
|
471 |
-
if (isset($network_settings[$rep_id])) {
|
472 |
-
$this->settings['repositories'][$rep_id]['subscription'] = $network_settings[$rep_id];
|
473 |
-
}
|
474 |
-
}
|
475 |
-
}
|
476 |
-
}
|
477 |
-
|
478 |
-
$this->load_hardcoded_site_keys();
|
479 |
-
|
480 |
-
$this->settings = $this->_pre_1_6_backwards_compatibility($this->settings);
|
481 |
-
|
482 |
-
$this->settings = $this->_old_products_format_backwards_compatibility($this->settings);
|
483 |
-
|
484 |
-
}
|
485 |
-
|
486 |
-
return $this->settings;
|
487 |
-
}
|
488 |
-
|
489 |
-
private function load_hardcoded_site_keys(){
|
490 |
-
|
491 |
-
if( !empty( $this->settings['repositories'] ) ) {
|
492 |
-
foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
|
493 |
-
|
494 |
-
if ( $site_key = self::get_repository_hardcoded_site_key( $repository_id ) ) {
|
495 |
-
|
496 |
-
$site_key_missing = empty($this->settings['repositories'][$repository_id]['subscription']['data']);
|
497 |
-
$site_key_changed = !$site_key_missing &&
|
498 |
-
$this->settings['repositories'][$repository_id]['subscription']['key'] != $site_key;
|
499 |
-
|
500 |
-
if ( $site_key_missing || $site_key_changed ) {
|
501 |
-
|
502 |
-
if ( !function_exists( 'get_plugins' ) ) {
|
503 |
-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
504 |
-
}
|
505 |
-
$this->load_repositories_list();
|
506 |
-
$response = $this->save_site_key(
|
507 |
-
array(
|
508 |
-
'repository_id' => $repository_id,
|
509 |
-
'site_key' => $site_key,
|
510 |
-
'return' => true,
|
511 |
-
'nonce' => wp_create_nonce( 'save_site_key_' . $repository_id )
|
512 |
-
)
|
513 |
-
);
|
514 |
-
|
515 |
-
if ( !empty($response['error']) ) {
|
516 |
-
$this->remove_site_key( $repository_id );
|
517 |
-
|
518 |
-
$this->admin_messages[] = array(
|
519 |
-
'type' => 'error',
|
520 |
-
'text' => sprintf( __( 'You are using an invalid site key defined as the constant %s (most likely in wp-config.php).
|
521 |
-
Please remove it or use the correct value in order to be able to register correctly.', 'installer' ), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper( $repository_id ) )
|
522 |
-
);
|
523 |
-
|
524 |
-
}
|
525 |
-
|
526 |
-
}
|
527 |
-
|
528 |
-
}
|
529 |
-
|
530 |
-
}
|
531 |
-
}
|
532 |
-
|
533 |
-
}
|
534 |
-
|
535 |
-
public static function get_repository_hardcoded_site_key( $repository_id ){
|
536 |
-
|
537 |
-
$site_key = false;
|
538 |
-
|
539 |
-
$site_key_constant = 'OTGS_INSTALLER_SITE_KEY_' . strtoupper( $repository_id );
|
540 |
-
if( defined( $site_key_constant ) ){
|
541 |
-
$site_key = constant( $site_key_constant );
|
542 |
-
}
|
543 |
-
|
544 |
-
return $site_key;
|
545 |
-
}
|
546 |
-
|
547 |
-
//backward compatibility, will remove 'basename' in version 1.8
|
548 |
-
private function _pre_1_6_backwards_compatibility($settings){
|
549 |
-
|
550 |
-
if( version_compare($this->version(), '1.8', '<') && !empty($settings['repositories']) ){
|
551 |
-
|
552 |
-
foreach ($settings['repositories'] as $repository_id => $repository) {
|
553 |
-
|
554 |
-
foreach ($repository['data']['downloads']['plugins'] as $slug => $download) {
|
555 |
-
|
556 |
-
$settings['repositories'][$repository_id]['data']['downloads']['plugins'][$slug]['slug'] = $download['basename'];
|
557 |
-
|
558 |
-
}
|
559 |
-
}
|
560 |
-
|
561 |
-
}
|
562 |
-
|
563 |
-
return $settings;
|
564 |
-
|
565 |
-
}
|
566 |
-
|
567 |
-
//backward compatibility - support old products list format (downloads under products instead of global downloads list)
|
568 |
-
private function _old_products_format_backwards_compatibility($settings){
|
569 |
-
|
570 |
-
if( version_compare($this->version(), '1.8', '<') && !empty($settings['repositories']) && empty($this->_old_products_format_backwards_compatibility) ) {
|
571 |
-
|
572 |
-
foreach ($settings['repositories'] as $repository_id => $repository) {
|
573 |
-
|
574 |
-
$populate_downloads = false;
|
575 |
-
|
576 |
-
foreach ($repository['data']['packages'] as $package_id => $package) {
|
577 |
-
|
578 |
-
foreach ($package['products'] as $product_id => $product) {
|
579 |
-
|
580 |
-
if (!isset($product['plugins'])) {
|
581 |
-
|
582 |
-
$populate_downloads = true;
|
583 |
-
|
584 |
-
foreach ($product['downloads'] as $download_id => $download) {
|
585 |
-
|
586 |
-
$settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['plugins'][] = $download['slug'];
|
587 |
-
|
588 |
-
}
|
589 |
-
|
590 |
-
}
|
591 |
-
|
592 |
-
}
|
593 |
-
|
594 |
-
}
|
595 |
-
|
596 |
-
if ($populate_downloads) {
|
597 |
-
|
598 |
-
// Add downloads branch
|
599 |
-
foreach ($repository['data']['packages'] as $package_id => $package) {
|
600 |
-
|
601 |
-
foreach ($package['products'] as $product_id => $product) {
|
602 |
-
|
603 |
-
foreach ($product['downloads'] as $download_id => $download) {
|
604 |
-
|
605 |
-
if (!isset($settings['repositories'][$repository_id]['data']['downloads']['plugins'][$download['slug']])) {
|
606 |
-
$settings['repositories'][$repository_id]['data']['downloads']['plugins'][$download['slug']] = $download;
|
607 |
-
}
|
608 |
-
|
609 |
-
$settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['plugins'][] = $download['slug'];
|
610 |
-
}
|
611 |
-
|
612 |
-
unset($settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['downloads']);
|
613 |
-
|
614 |
-
}
|
615 |
-
|
616 |
-
}
|
617 |
-
|
618 |
-
}
|
619 |
-
|
620 |
-
}
|
621 |
-
|
622 |
-
$this->_old_products_format_backwards_compatibility = true;
|
623 |
-
|
624 |
-
}
|
625 |
-
|
626 |
-
return $settings;
|
627 |
-
|
628 |
-
}
|
629 |
-
|
630 |
-
public function get_installer_site_url( $repository_id = false ){
|
631 |
-
global $current_site;
|
632 |
-
|
633 |
-
$site_url = get_site_url();
|
634 |
-
|
635 |
-
if( $repository_id && is_multisite() && isset( $this->settings['repositories'] ) ){
|
636 |
-
$network_settings = maybe_unserialize( get_site_option('wp_installer_network') );
|
637 |
-
|
638 |
-
if ( isset( $network_settings[$repository_id] ) ) {
|
639 |
-
$site_url = get_site_url( $current_site->blog_id );
|
640 |
-
}
|
641 |
-
|
642 |
-
}
|
643 |
-
|
644 |
-
return $site_url;
|
645 |
-
}
|
646 |
-
|
647 |
-
public function show_site_key_nags(){
|
648 |
-
$screen = get_current_screen();
|
649 |
-
|
650 |
-
if($screen->base == 'settings_page_installer' || ($screen->base == 'plugin-install' && isset($_GET['tab']) && $_GET['tab'] == 'commercial')){
|
651 |
-
return;
|
652 |
-
}
|
653 |
-
|
654 |
-
if(!empty($this->config['site_key_nags'])){
|
655 |
-
|
656 |
-
foreach($this->config['site_key_nags'] as $nag){
|
657 |
-
|
658 |
-
if(!$this->repository_has_subscription($nag['repository_id'] )){
|
659 |
-
$show = true;
|
660 |
-
if(!empty($nag['condition_cb'])){
|
661 |
-
$show = call_user_func($nag['condition_cb']);
|
662 |
-
}
|
663 |
-
|
664 |
-
if(empty($this->settings['dismissed_nags'][$nag['repository_id']]) && $show){
|
665 |
-
echo '<div class="updated error otgs-is-dismissible"><p>';
|
666 |
-
printf(__("To get automatic updates, you need to register %s for this site. %sRegister %s%s", 'sitepress'),
|
667 |
-
$nag['product_name'], '<a class="button-primary" href="' . $this->menu_url() . '">', $nag['product_name'], '</a>');
|
668 |
-
|
669 |
-
echo '</p>';
|
670 |
-
echo '<span class="installer-dismiss-nag notice-dismiss" data-repository="' . $nag['repository_id'] . '"><span class="screen-reader-text">' . __('Dismiss', 'sitepress') . '</span></span>';
|
671 |
-
echo '</div>';
|
672 |
-
}
|
673 |
-
}
|
674 |
-
|
675 |
-
}
|
676 |
-
|
677 |
-
}
|
678 |
-
|
679 |
-
}
|
680 |
-
|
681 |
-
public function dismiss_nag(){
|
682 |
-
$this->settings['dismissed_nags'][$_POST['repository']] = 1;
|
683 |
-
|
684 |
-
$this->save_settings();
|
685 |
-
|
686 |
-
echo json_encode(array());
|
687 |
-
exit;
|
688 |
-
}
|
689 |
-
|
690 |
-
public function add_install_plugins_tab($tabs){
|
691 |
-
|
692 |
-
$tabs['commercial'] = __('Commercial', 'installer');
|
693 |
-
|
694 |
-
return $tabs;
|
695 |
-
}
|
696 |
-
|
697 |
-
public function load_repositories_list(){
|
698 |
-
global $wp_installer_instances;
|
699 |
-
|
700 |
-
foreach ($wp_installer_instances as $instance) {
|
701 |
-
|
702 |
-
if (file_exists(dirname($instance['bootfile']) . '/repositories.xml')) {
|
703 |
-
$config_file = dirname($instance['bootfile']) . '/repositories.xml';
|
704 |
-
|
705 |
-
if (file_exists(dirname($instance['bootfile']) . '/repositories.sandbox.xml')) {
|
706 |
-
$config_file = dirname($instance['bootfile']) . '/repositories.sandbox.xml';
|
707 |
-
add_filter('https_ssl_verify', '__return_false');
|
708 |
-
}
|
709 |
-
|
710 |
-
$repos = simplexml_load_file($config_file);
|
711 |
-
|
712 |
-
if($repos) {
|
713 |
-
foreach ($repos as $repo) {
|
714 |
-
$id = strval($repo->id);
|
715 |
-
|
716 |
-
$data['api-url'] = strval($repo->apiurl);
|
717 |
-
$data['products'] = strval($repo->products);
|
718 |
-
|
719 |
-
// excludes rule;
|
720 |
-
if (isset($this->config['repositories_exclude']) && in_array($id, $this->config['repositories_exclude'])) {
|
721 |
-
continue;
|
722 |
-
}
|
723 |
-
|
724 |
-
// includes rule;
|
725 |
-
if (isset($this->config['repositories_include']) && !in_array($id, $this->config['repositories_include'])) {
|
726 |
-
continue;
|
727 |
-
}
|
728 |
-
|
729 |
-
$this->repositories[$id] = $data;
|
730 |
-
|
731 |
-
}
|
732 |
-
}
|
733 |
-
|
734 |
-
}
|
735 |
-
}
|
736 |
-
|
737 |
-
}
|
738 |
-
|
739 |
-
public function filter_repositories_list(){
|
740 |
-
|
741 |
-
if(!empty($this->settings['repositories'])) {
|
742 |
-
foreach ($this->settings['repositories'] as $id => $repo_data) {
|
743 |
-
|
744 |
-
// excludes rule;
|
745 |
-
if (isset($this->config['repositories_exclude']) && in_array($id, $this->config['repositories_exclude'])) {
|
746 |
-
unset($this->settings['repositories'][$id]);
|
747 |
-
}
|
748 |
-
|
749 |
-
// includes rule;
|
750 |
-
if (isset($this->config['repositories_include']) && !in_array($id, $this->config['repositories_include'])) {
|
751 |
-
unset($this->settings['repositories'][$id]);
|
752 |
-
}
|
753 |
-
|
754 |
-
|
755 |
-
}
|
756 |
-
}
|
757 |
-
|
758 |
-
|
759 |
-
}
|
760 |
-
|
761 |
-
public function refresh_repositories_data(){
|
762 |
-
static $checked = false;
|
763 |
-
|
764 |
-
if( defined('OTGS_DISABLE_AUTO_UPDATES') && OTGS_DISABLE_AUTO_UPDATES && empty($_GET['force-check']) || $checked ){
|
765 |
-
|
766 |
-
if(empty($this->settings['repositories']) && $this->is_repositories_page()){
|
767 |
-
|
768 |
-
foreach($this->repositories as $id => $data) {
|
769 |
-
$repository_names[] = $id;
|
770 |
-
|
771 |
-
}
|
772 |
-
|
773 |
-
$error = sprintf(__("Installer cannot display the products information because the automatic updating for %s was explicitly disabled with the configuration below (usually in wp-config.php):", 'installer'), strtoupper( join(', ', $repository_names) ));
|
774 |
-
$error .= '<br /><br /><code>define("OTGS_DISABLE_AUTO_UPDATES", true);</code><br /><br />';
|
775 |
-
$error .= sprintf(__("In order to see the products information, please run the %smanual updates check%s to initialize the products list or (temporarily) remove the above code.", 'installer'), '<a href="' . admin_url('update-core.php') . '">', '</a>');
|
776 |
-
|
777 |
-
$this->register_admin_message($error, 'error');
|
778 |
-
|
779 |
-
|
780 |
-
}
|
781 |
-
|
782 |
-
return;
|
783 |
-
}
|
784 |
-
|
785 |
-
$checked = true;
|
786 |
-
|
787 |
-
foreach($this->repositories as $id => $data){
|
788 |
-
|
789 |
-
$response = wp_remote_get($data['products']);
|
790 |
-
|
791 |
-
if(is_wp_error($response)){
|
792 |
-
// http fallback
|
793 |
-
$data['products'] = preg_replace("@^https://@", 'http://', $data['products']);
|
794 |
-
$response = wp_remote_get($data['products']);
|
795 |
-
}
|
796 |
-
|
797 |
-
if(is_wp_error($response)){
|
798 |
-
|
799 |
-
$error = sprintf(__("Installer cannot contact our updates server to get information about the available products and check for new versions. If you are seeing this message for the first time, you can ignore it, as it may be a temporary communication problem. If the problem persists and your WordPress admin is slowing down, you can disable automated version checks. Add the following line to your wp-config.php file:", 'installer'), strtoupper($id));
|
800 |
-
$error .= '<br /><br /><code>define("OTGS_DISABLE_AUTO_UPDATES", true);</code>';
|
801 |
-
|
802 |
-
$this->register_admin_message($error, 'error');
|
803 |
-
|
804 |
-
continue;
|
805 |
-
}
|
806 |
-
|
807 |
-
if($response && isset($response['response']['code']) && $response['response']['code'] == 200){
|
808 |
-
$body = wp_remote_retrieve_body($response);
|
809 |
-
if($body){
|
810 |
-
$products = json_decode($body, true);
|
811 |
-
|
812 |
-
if(is_array($products)){
|
813 |
-
$this->settings['repositories'][$id]['data'] = $products;
|
814 |
-
$this->settings = $this->_pre_1_6_backwards_compatibility($this->settings);
|
815 |
-
}
|
816 |
-
}
|
817 |
-
|
818 |
-
}
|
819 |
-
|
820 |
-
$this->log( sprintf("Checked for %s updates: %s", $id, $data['products']) );
|
821 |
-
|
822 |
-
|
823 |
-
}
|
824 |
-
|
825 |
-
// cleanup
|
826 |
-
if(empty($this->settings['repositories'])){
|
827 |
-
$this->settings['repositories'] = array();
|
828 |
-
}
|
829 |
-
foreach($this->settings['repositories'] as $id => $data){
|
830 |
-
if(!in_array($id, array_keys($this->repositories))){
|
831 |
-
unset($this->settings['repositories'][$id]);
|
832 |
-
}
|
833 |
-
}
|
834 |
-
|
835 |
-
$this->settings['last_repositories_update']= time();
|
836 |
-
|
837 |
-
$this->save_settings();
|
838 |
-
|
839 |
-
}
|
840 |
-
|
841 |
-
public function show_products($args = array()){
|
842 |
-
|
843 |
-
$screen = get_current_screen();
|
844 |
-
|
845 |
-
if($screen->base == 'settings_page_installer'){ // settings page
|
846 |
-
echo '<div class="wrap">';
|
847 |
-
echo '<h2>' . __('Installer', 'installer') . '</h2>';
|
848 |
-
echo '<br />';
|
849 |
-
}
|
850 |
-
|
851 |
-
if(!is_array($args)) $args = array();
|
852 |
-
if(empty($args['template'])) $args['template'] = 'default';
|
853 |
-
|
854 |
-
$this->filter_repositories_list();
|
855 |
-
|
856 |
-
if(!empty($this->settings['repositories'])){
|
857 |
-
|
858 |
-
$this->localize_strings();
|
859 |
-
$this->set_filtered_prices($args);
|
860 |
-
$this->set_hierarchy_and_order();
|
861 |
-
|
862 |
-
foreach($this->settings['repositories'] as $repository_id => $repository){
|
863 |
-
|
864 |
-
if($args['template'] == 'compact'){
|
865 |
-
|
866 |
-
if(isset($args['repository']) && $args['repository'] == $repository_id){
|
867 |
-
include $this->plugin_path() . '/templates/products-compact.php';
|
868 |
-
}
|
869 |
-
|
870 |
-
}else{
|
871 |
-
|
872 |
-
include $this->plugin_path() . '/templates/repository-listing.php';
|
873 |
-
|
874 |
-
}
|
875 |
-
|
876 |
-
unset($site_key, $subscription_type, $expired, $upgrade_options, $products_avaliable);
|
877 |
-
|
878 |
-
}
|
879 |
-
|
880 |
-
}else{
|
881 |
-
|
882 |
-
echo '<center>' . __('No repositories defined.', 'installer') . '</center>';
|
883 |
-
|
884 |
-
}
|
885 |
-
|
886 |
-
if($screen->base == 'settings_page_installer'){ // settings page
|
887 |
-
echo '</div>';
|
888 |
-
}
|
889 |
-
|
890 |
-
|
891 |
-
}
|
892 |
-
|
893 |
-
public function get_product_price($repository_id, $package_id, $product_id, $incl_discount = false){
|
894 |
-
|
895 |
-
$price = false;
|
896 |
-
|
897 |
-
foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package ){
|
898 |
-
|
899 |
-
if($package['id'] == $package_id){
|
900 |
-
if(isset($package['products'][$product_id])){
|
901 |
-
if($incl_discount && isset($package['products'][$product_id]['price_disc'])){
|
902 |
-
$price = $package['products'][$product_id]['price_disc'];
|
903 |
-
}elseif(isset($package['products'][$product_id]['price'])){
|
904 |
-
$price = $package['products'][$product_id]['price'];
|
905 |
-
}
|
906 |
-
}
|
907 |
-
break;
|
908 |
-
}
|
909 |
-
}
|
910 |
-
|
911 |
-
return $price;
|
912 |
-
}
|
913 |
-
|
914 |
-
private function _render_product_packages($packages, $subscription_type, $expired, $upgrade_options, $repository_id){
|
915 |
-
|
916 |
-
$data = array();
|
917 |
-
|
918 |
-
foreach($packages as $package_id => $package){
|
919 |
-
|
920 |
-
$row = array('products' => array(), 'downloads' => array());
|
921 |
-
foreach($package['products'] as $product){
|
922 |
-
|
923 |
-
// filter out free subscriptions from being displayed as buying options
|
924 |
-
if( empty($product['price']) && (empty($subscription_type) || $expired) ){
|
925 |
-
continue;
|
926 |
-
}
|
927 |
-
|
928 |
-
// buy base
|
929 |
-
if(empty($subscription_type) || $expired) {
|
930 |
-
|
931 |
-
$p['url'] = $this->append_parameters_to_buy_url($product['url'], $repository_id);
|
932 |
-
if (!empty($product['price_disc'])) {
|
933 |
-
$p['label'] = $product['call2action'] . ' - ' . sprintf('$%s %s$%d%s (USD)', $product['price_disc'], ' <del>', $product['price'], '</del>');
|
934 |
-
} else {
|
935 |
-
$p['label'] = $product['call2action'] . ' - ' . sprintf('$%d (USD)', $product['price']);
|
936 |
-
}
|
937 |
-
$row['products'][] = $p;
|
938 |
-
|
939 |
-
// renew
|
940 |
-
} elseif(isset($subscription_type) && $product['subscription_type'] == $subscription_type){
|
941 |
-
|
942 |
-
if($product['renewals']) {
|
943 |
-
foreach ($product['renewals'] as $renewal) {
|
944 |
-
$p['url'] = $this->append_parameters_to_buy_url($renewal['url'], $repository_id);
|
945 |
-
$p['label'] = $renewal['call2action'] . ' - ' . sprintf('$%d (USD)', $renewal['price']);
|
946 |
-
}
|
947 |
-
|
948 |
-
$row['products'][] = $p;
|
949 |
-
}
|
950 |
-
|
951 |
-
}
|
952 |
-
|
953 |
-
// upgrades
|
954 |
-
if(!empty($upgrade_options[$product['subscription_type']])){
|
955 |
-
|
956 |
-
foreach($upgrade_options[$product['subscription_type']] as $stype => $upgrade){
|
957 |
-
if($stype != $subscription_type) continue;
|
958 |
-
|
959 |
-
$p['url'] = $this->append_parameters_to_buy_url($upgrade['url'], $repository_id);
|
960 |
-
if (!empty($upgrade['price_disc'])) {
|
961 |
-
$p['label'] = $upgrade['call2action'] . ' - ' . sprintf('$%s %s$%d%s (USD)', $upgrade['price_disc'], ' <del>', $upgrade['price'], '</del>');
|
962 |
-
} else {
|
963 |
-
$p['label'] = $upgrade['call2action'] . ' - ' . sprintf('$%d (USD)', $upgrade['price']);
|
964 |
-
}
|
965 |
-
$row['products'][] = $p;
|
966 |
-
|
967 |
-
}
|
968 |
-
|
969 |
-
}
|
970 |
-
|
971 |
-
// downloads
|
972 |
-
if(isset($subscription_type) && !$expired && $product['subscription_type'] == $subscription_type){
|
973 |
-
foreach($product['plugins'] as $plugin_slug){
|
974 |
-
|
975 |
-
$row['downloads'][] = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
976 |
-
|
977 |
-
}
|
978 |
-
|
979 |
-
}
|
980 |
-
|
981 |
-
//subpackages
|
982 |
-
if(!empty($package['sub-packages'])){
|
983 |
-
$row['sub-packages'] = $package['sub-packages'];
|
984 |
-
}
|
985 |
-
|
986 |
-
}
|
987 |
-
|
988 |
-
$row['id'] = $package['id'];
|
989 |
-
$row['image_url'] = $package['image_url'];
|
990 |
-
$row['name'] = $package['name'];
|
991 |
-
$row['description'] = $package['description'];
|
992 |
-
|
993 |
-
if(!empty($row['products']) || !empty($row['downloads']) || !empty($row['sub-packages'])){
|
994 |
-
$data[] = $row;
|
995 |
-
}
|
996 |
-
|
997 |
-
|
998 |
-
}
|
999 |
-
|
1000 |
-
return $data;
|
1001 |
-
|
1002 |
-
}
|
1003 |
-
|
1004 |
-
public function get_extra_url_parameters(){
|
1005 |
-
|
1006 |
-
$parameters = array();
|
1007 |
-
|
1008 |
-
if(!empty($this->package_source)){
|
1009 |
-
foreach($this->package_source as $key => $val){
|
1010 |
-
$parameters[$key] = $val;
|
1011 |
-
}
|
1012 |
-
}
|
1013 |
-
|
1014 |
-
$parameters['installer_version'] = WP_INSTALLER_VERSION;
|
1015 |
-
$parameters['theme'] = wp_get_theme()->get( 'Name' );
|
1016 |
-
$parameters['site_name'] = get_bloginfo( 'name' );
|
1017 |
-
|
1018 |
-
return $parameters;
|
1019 |
-
}
|
1020 |
-
|
1021 |
-
public function append_parameters_to_buy_url($url, $repository_id, $args = array()){
|
1022 |
-
|
1023 |
-
$url = add_query_arg( array('icl_site_url' => $this->get_installer_site_url( $repository_id ) ), $url );
|
1024 |
-
|
1025 |
-
$affiliate_id = false;
|
1026 |
-
$affiliate_key = false;
|
1027 |
-
|
1028 |
-
// Add extra parameters for custom Installer packages
|
1029 |
-
if( !empty($this->package_source) ){
|
1030 |
-
$extra = $this->get_extra_url_parameters();
|
1031 |
-
|
1032 |
-
if( !empty($extra['repository']) && $extra['repository'] == $repository_id ) {
|
1033 |
-
|
1034 |
-
if( !empty($extra['affiliate_key']) && !empty($extra['user_id']) ){
|
1035 |
-
$this->config['affiliate_id:' . $repository_id] = $extra['user_id'];
|
1036 |
-
$this->config['affiliate_key:' . $repository_id] = $extra['affiliate_key'];
|
1037 |
-
unset($extra['affiliate_key'], $extra['user_id'], $extra['repository']); // no need to include these ones
|
1038 |
-
}
|
1039 |
-
|
1040 |
-
$url = add_query_arg($extra, $url);
|
1041 |
-
}
|
1042 |
-
|
1043 |
-
}
|
1044 |
-
|
1045 |
-
if(isset($this->config['affiliate_id:' . $repository_id]) && isset($this->config['affiliate_key:' . $repository_id])){
|
1046 |
-
|
1047 |
-
$affiliate_id = $this->config['affiliate_id:' . $repository_id];
|
1048 |
-
$affiliate_key = $this->config['affiliate_key:' . $repository_id];
|
1049 |
-
|
1050 |
-
}elseif(isset($args['affiliate_id:' . $repository_id]) && isset($args['affiliate_key:' . $repository_id])){
|
1051 |
-
|
1052 |
-
$affiliate_id = $args['affiliate_id:' . $repository_id];
|
1053 |
-
$affiliate_key = $args['affiliate_key:' . $repository_id];
|
1054 |
-
|
1055 |
-
}elseif(defined('ICL_AFFILIATE_ID') && defined('ICL_AFFILIATE_KEY')){ //support for 1 repo
|
1056 |
-
|
1057 |
-
$affiliate_id = ICL_AFFILIATE_ID;
|
1058 |
-
$affiliate_key = ICL_AFFILIATE_KEY;
|
1059 |
-
|
1060 |
-
}elseif(isset($this->config['affiliate_id']) && isset($this->config['affiliate_key'])) {
|
1061 |
-
// BACKWARDS COMPATIBILITY
|
1062 |
-
$affiliate_id = $this->config['affiliate_id'];
|
1063 |
-
$affiliate_key = $this->config['affiliate_key'];
|
1064 |
-
}
|
1065 |
-
|
1066 |
-
if($affiliate_id && $affiliate_key){
|
1067 |
-
$url = add_query_arg(array('aid' => $affiliate_id, 'affiliate_key' => $affiliate_key), $url);
|
1068 |
-
}
|
1069 |
-
|
1070 |
-
if($repository_id == 'wpml'){
|
1071 |
-
$url = add_query_arg(array('using_icl' => $this->_using_icl, 'wpml_version' => $this->_wpml_version), $url);
|
1072 |
-
}
|
1073 |
-
|
1074 |
-
$url = apply_filters('wp_installer_buy_url', $url);
|
1075 |
-
|
1076 |
-
$url = esc_url($url);
|
1077 |
-
|
1078 |
-
return $url;
|
1079 |
-
|
1080 |
-
}
|
1081 |
-
|
1082 |
-
public function save_site_key($args = array()){
|
1083 |
-
|
1084 |
-
$error = '';
|
1085 |
-
|
1086 |
-
if( isset( $args['repository_id'] ) ){
|
1087 |
-
$repository_id = $args['repository_id'];
|
1088 |
-
}elseif( isset( $_POST['repository_id'] ) ){
|
1089 |
-
$repository_id = sanitize_text_field( $_POST['repository_id'] );
|
1090 |
-
}else{
|
1091 |
-
$repository_id = false;
|
1092 |
-
}
|
1093 |
-
|
1094 |
-
if( isset( $args['nonce'] ) ){
|
1095 |
-
$nonce = $args['nonce'];
|
1096 |
-
}elseif( isset($_POST['nonce'] ) ){
|
1097 |
-
$nonce = sanitize_text_field( $_POST['nonce'] );
|
1098 |
-
}else{
|
1099 |
-
$nonce = '';
|
1100 |
-
}
|
1101 |
-
|
1102 |
-
if( isset( $args['site_key'] ) ){
|
1103 |
-
$site_key = $args['site_key'];
|
1104 |
-
} else {
|
1105 |
-
$site_key = sanitize_text_field( $_POST[ 'site_key_' . $repository_id] );
|
1106 |
-
}
|
1107 |
-
$site_key = preg_replace("/[^A-Za-z0-9]/", '', $site_key);
|
1108 |
-
|
1109 |
-
if($repository_id && $nonce && wp_create_nonce('save_site_key_' . $repository_id) == $nonce){
|
1110 |
-
|
1111 |
-
try {
|
1112 |
-
$subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REGISTRATION );
|
1113 |
-
|
1114 |
-
if ( $subscription_data ) {
|
1115 |
-
$this->settings['repositories'][$repository_id]['subscription'] = array('key' => $site_key, 'data' => $subscription_data);
|
1116 |
-
$this->save_settings();
|
1117 |
-
} else {
|
1118 |
-
$error = __( 'Invalid site key for the current site.', 'installer' )
|
1119 |
-
. '<br /><div class="installer-footnote">' . __('Please note that the site key is case sensitive.', 'installer') . '</div>';
|
1120 |
-
}
|
1121 |
-
|
1122 |
-
} catch (Exception $e ){
|
1123 |
-
$error = $e->getMessage();
|
1124 |
-
if( preg_match('#Could not resolve host: (.*)#', $error, $matches) || preg_match('#Couldn\'t resolve host \'(.*)\'#', $error, $matches) ){
|
1125 |
-
$error = sprintf(__("%s cannot access %s to register. Try again to see if it's a temporary problem. If the problem continues, make sure that this site has access to the Internet. You can still use the plugin without registration, but you will not receive automated updates.", 'installer'),
|
1126 |
-
'<strong><i>' . $this->get_generic_product_name($repository_id) . '</i></strong>',
|
1127 |
-
'<strong><i>' . $matches[1]. '</i></strong>'
|
1128 |
-
) ;
|
1129 |
-
}
|
1130 |
-
}
|
1131 |
-
|
1132 |
-
}
|
1133 |
-
|
1134 |
-
$return = array('error' => $error);
|
1135 |
-
|
1136 |
-
if($this->api_debug){
|
1137 |
-
$return['debug'] = $this->api_debug;
|
1138 |
-
}
|
1139 |
-
|
1140 |
-
if(!empty($args['return'])){
|
1141 |
-
return $return;
|
1142 |
-
}else{
|
1143 |
-
echo json_encode($return);
|
1144 |
-
exit;
|
1145 |
-
}
|
1146 |
-
|
1147 |
-
}
|
1148 |
-
|
1149 |
-
/**
|
1150 |
-
* Alias for WP_Installer::get_repository_site_key
|
1151 |
-
* @see WP_Installer::get_repository_site_key()
|
1152 |
-
*
|
1153 |
-
* @param string $repository_id
|
1154 |
-
* @return string (site key) or bool
|
1155 |
-
*/
|
1156 |
-
public function get_site_key($repository_id){
|
1157 |
-
return WP_Installer::get_repository_site_key( $repository_id );
|
1158 |
-
}
|
1159 |
-
|
1160 |
-
public function remove_site_key( $repository_id ){
|
1161 |
-
if( isset( $this->settings['repositories'][$repository_id] ) ){
|
1162 |
-
unset($this->settings['repositories'][$repository_id]['subscription']);
|
1163 |
-
$this->save_settings();
|
1164 |
-
$this->refresh_repositories_data();
|
1165 |
-
}
|
1166 |
-
}
|
1167 |
-
|
1168 |
-
public function remove_site_key_ajax(){
|
1169 |
-
if($_POST['nonce'] == wp_create_nonce('remove_site_key_' . $_POST['repository_id'])){
|
1170 |
-
$this->remove_site_key( $_POST['repository_id'] );
|
1171 |
-
}
|
1172 |
-
exit;
|
1173 |
-
}
|
1174 |
-
|
1175 |
-
public function validate_repository_subscription(){
|
1176 |
-
$repository_id = isset($_GET['validate_repository']) ? sanitize_text_field( $_GET['validate_repository'] ) : false;
|
1177 |
-
if($repository_id){
|
1178 |
-
|
1179 |
-
$site_key = $this->get_site_key($repository_id);
|
1180 |
-
if($site_key) {
|
1181 |
-
$subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION);
|
1182 |
-
if(empty($subscription_data)){
|
1183 |
-
unset($this->settings['repositories'][$repository_id]['subscription']);
|
1184 |
-
delete_site_transient('update_plugins');
|
1185 |
-
$this->save_settings();
|
1186 |
-
}
|
1187 |
-
}
|
1188 |
-
|
1189 |
-
wp_redirect($this->menu_url() . '#repository-' . $repository_id);
|
1190 |
-
exit;
|
1191 |
-
|
1192 |
-
}
|
1193 |
-
|
1194 |
-
}
|
1195 |
-
|
1196 |
-
public function update_site_key(){
|
1197 |
-
|
1198 |
-
$error = '';
|
1199 |
-
|
1200 |
-
$repository_id = sanitize_text_field ( $_POST['repository_id'] );
|
1201 |
-
if($_POST['nonce'] == wp_create_nonce('update_site_key_' . $repository_id )){
|
1202 |
-
|
1203 |
-
$site_key = $this->get_site_key($_POST['repository_id']);
|
1204 |
-
|
1205 |
-
if($site_key){
|
1206 |
-
try {
|
1207 |
-
$subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_UPDATES_CHECK );
|
1208 |
-
|
1209 |
-
if ( $subscription_data ) {
|
1210 |
-
$this->settings['repositories'][$repository_id]['subscription'] = array('key' => $site_key, 'data' => $subscription_data);
|
1211 |
-
|
1212 |
-
//also refresh products information
|
1213 |
-
$this->refresh_repositories_data();
|
1214 |
-
|
1215 |
-
$this->save_settings();
|
1216 |
-
|
1217 |
-
} else {
|
1218 |
-
unset($this->settings['repositories'][$repository_id]['subscription']);
|
1219 |
-
$error = __( 'Invalid site key for the current site. If the error persists, try to unregister first and then register again with the same site key.', 'installer' );
|
1220 |
-
}
|
1221 |
-
|
1222 |
-
|
1223 |
-
} catch (Exception $e ){
|
1224 |
-
$error = $e->getMessage();
|
1225 |
-
if( preg_match('#Could not resolve host: (.*)#', $error, $matches) || preg_match('#Couldn\'t resolve host \'(.*)\'#', $error, $matches) ){
|
1226 |
-
$error = sprintf(__("%s cannot access %s to register. Try again to see if it's a temporary problem. If the problem continues, make sure that this site has access to the Internet. You can still use the plugin without registration, but you will not receive automated updates.", 'installer'),
|
1227 |
-
'<strong><i>' . $this->get_generic_product_name($repository_id) . '</i></strong>',
|
1228 |
-
'<strong><i>' . $matches[1]. '</i></strong>'
|
1229 |
-
) ;
|
1230 |
-
}
|
1231 |
-
}
|
1232 |
-
|
1233 |
-
}
|
1234 |
-
|
1235 |
-
}
|
1236 |
-
|
1237 |
-
echo json_encode(array('error' => $error));
|
1238 |
-
|
1239 |
-
exit;
|
1240 |
-
}
|
1241 |
-
|
1242 |
-
public function api_debug_log($text){
|
1243 |
-
|
1244 |
-
if(defined('WPML_DEBUG_INSTALLER') && WPML_DEBUG_INSTALLER){
|
1245 |
-
|
1246 |
-
if(!is_scalar($text)){
|
1247 |
-
$text = print_r($text, 1);
|
1248 |
-
}
|
1249 |
-
|
1250 |
-
$this->api_debug .= $text . "\n";
|
1251 |
-
|
1252 |
-
}
|
1253 |
-
|
1254 |
-
}
|
1255 |
-
|
1256 |
-
public function fetch_subscription_data( $repository_id, $site_key, $source = self::SITE_KEY_VALIDATION_SOURCE_OTHER ){
|
1257 |
-
|
1258 |
-
$subscription_data = false;
|
1259 |
-
|
1260 |
-
$args['body'] = array(
|
1261 |
-
'action' => 'site_key_validation',
|
1262 |
-
'site_key' => $site_key,
|
1263 |
-
'site_url' => $this->get_installer_site_url( $repository_id ),
|
1264 |
-
'source' => $source
|
1265 |
-
);
|
1266 |
-
|
1267 |
-
if($repository_id == 'wpml'){
|
1268 |
-
$args['body']['using_icl'] = $this->_using_icl;
|
1269 |
-
$args['body']['wpml_version'] = $this->_wpml_version;
|
1270 |
-
}
|
1271 |
-
|
1272 |
-
$args['body']['installer_version'] = WP_INSTALLER_VERSION;
|
1273 |
-
$args['body']['theme'] = wp_get_theme()->get( 'Name' );
|
1274 |
-
$args['body']['site_name'] = get_bloginfo( 'name' );
|
1275 |
-
|
1276 |
-
$args['body']['versions'] = $this->get_local_product_versions( $repository_id );
|
1277 |
-
|
1278 |
-
$args['timeout'] = 45;
|
1279 |
-
|
1280 |
-
// Add extra parameters for custom Installer packages
|
1281 |
-
if( !empty($this->package_source) ){
|
1282 |
-
$extra = $this->get_extra_url_parameters();
|
1283 |
-
if( !empty($extra['repository']) && $extra['repository'] == $repository_id ) {
|
1284 |
-
unset($extra['repository']);
|
1285 |
-
foreach($extra as $key => $val){
|
1286 |
-
$args['body'][$key] = $val;
|
1287 |
-
}
|
1288 |
-
}
|
1289 |
-
}
|
1290 |
-
|
1291 |
-
$response = wp_remote_post($this->repositories[$repository_id]['api-url'], $args);
|
1292 |
-
|
1293 |
-
$this->api_debug_log("POST {$this->repositories[$repository_id]['api-url']}");
|
1294 |
-
$this->api_debug_log($args);
|
1295 |
-
|
1296 |
-
$this->log("POST {$this->repositories[$repository_id]['api-url']} - fetch subscription data");
|
1297 |
-
|
1298 |
-
if( !is_wp_error($response) ){
|
1299 |
-
$datas = wp_remote_retrieve_body($response);
|
1300 |
-
|
1301 |
-
if(is_serialized($datas)){
|
1302 |
-
$data = unserialize($datas);
|
1303 |
-
$this->api_debug_log($data);
|
1304 |
-
|
1305 |
-
if( !empty( $data->subscription_data ) ){
|
1306 |
-
$subscription_data = $data->subscription_data;
|
1307 |
-
}
|
1308 |
-
|
1309 |
-
do_action( 'installer_fetched_subscription_data', $data, $repository_id);
|
1310 |
-
|
1311 |
-
}else{
|
1312 |
-
$this->api_debug_log($datas);
|
1313 |
-
}
|
1314 |
-
|
1315 |
-
}else{
|
1316 |
-
|
1317 |
-
$this->api_debug_log($response);
|
1318 |
-
throw new Exception( $response->get_error_message() );
|
1319 |
-
}
|
1320 |
-
|
1321 |
-
return $subscription_data;
|
1322 |
-
|
1323 |
-
}
|
1324 |
-
|
1325 |
-
function get_local_product_versions( $repository_id ){
|
1326 |
-
|
1327 |
-
$versions = array();
|
1328 |
-
|
1329 |
-
foreach( $this->settings['repositories'][$repository_id]['data']['packages'] as $package_id => $package ){
|
1330 |
-
|
1331 |
-
foreach( $package['products'] as $product_id => $product ){
|
1332 |
-
|
1333 |
-
foreach( $product['plugins'] as $plugin_slug ){
|
1334 |
-
|
1335 |
-
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
1336 |
-
|
1337 |
-
if( empty( $versions[$download['slug']] ) ) {
|
1338 |
-
$v = $this->get_plugin_installed_version($download['name'], $download['slug']);
|
1339 |
-
if($v){
|
1340 |
-
$versions[$download['slug']] = $v;
|
1341 |
-
}
|
1342 |
-
}
|
1343 |
-
|
1344 |
-
}
|
1345 |
-
|
1346 |
-
}
|
1347 |
-
|
1348 |
-
}
|
1349 |
-
|
1350 |
-
return $versions;
|
1351 |
-
}
|
1352 |
-
|
1353 |
-
public function get_repository_site_key($repository_id){
|
1354 |
-
$site_key = false;
|
1355 |
-
|
1356 |
-
if(!empty($this->settings['repositories'][$repository_id]['subscription']['key'])){
|
1357 |
-
$site_key = $this->settings['repositories'][$repository_id]['subscription']['key'];
|
1358 |
-
}
|
1359 |
-
|
1360 |
-
return $site_key;
|
1361 |
-
}
|
1362 |
-
|
1363 |
-
public function repository_has_valid_subscription($repository_id){
|
1364 |
-
|
1365 |
-
$valid = false;
|
1366 |
-
|
1367 |
-
if(!empty($this->settings['repositories'][$repository_id]['subscription'])){
|
1368 |
-
|
1369 |
-
$subscription = $this->settings['repositories'][$repository_id]['subscription']['data'];
|
1370 |
-
$valid = ( $subscription->status == 1 && (strtotime($subscription->expires) > time() || empty($subscription->expires)) ) || $subscription->status == 4;
|
1371 |
-
|
1372 |
-
}
|
1373 |
-
return $valid;
|
1374 |
-
|
1375 |
-
}
|
1376 |
-
|
1377 |
-
public function repository_has_subscription($repository_id){
|
1378 |
-
$key = false;
|
1379 |
-
if(!empty($this->settings['repositories'][$repository_id]['subscription']['key'])){
|
1380 |
-
$key = $this->settings['repositories'][$repository_id]['subscription']['key'];
|
1381 |
-
}
|
1382 |
-
|
1383 |
-
return $key;
|
1384 |
-
|
1385 |
-
}
|
1386 |
-
|
1387 |
-
public function repository_has_expired_subscription($repository_id){
|
1388 |
-
|
1389 |
-
return $this->repository_has_subscription($repository_id) && !$this->repository_has_valid_subscription($repository_id);
|
1390 |
-
|
1391 |
-
}
|
1392 |
-
|
1393 |
-
public function get_generic_product_name($repository_id){
|
1394 |
-
|
1395 |
-
return $this->settings['repositories'][$repository_id]['data']['product-name'];
|
1396 |
-
|
1397 |
-
}
|
1398 |
-
|
1399 |
-
public function show_subscription_renew_warning($repository_id, $subscription_id){
|
1400 |
-
|
1401 |
-
$show = false;
|
1402 |
-
|
1403 |
-
$data = $this->settings['repositories'][$repository_id]['data'];
|
1404 |
-
if(!empty($data['subscriptions_meta'])){
|
1405 |
-
if(isset($data['subscriptions_meta']['expiration'])){
|
1406 |
-
|
1407 |
-
if(!empty($data['subscriptions_meta']['expiration'][$subscription_id])){
|
1408 |
-
|
1409 |
-
$days = $data['subscriptions_meta']['expiration'][$subscription_id]['days_warning'];
|
1410 |
-
$message = $data['subscriptions_meta']['expiration'][$subscription_id]['warning_message'];
|
1411 |
-
|
1412 |
-
}else{
|
1413 |
-
|
1414 |
-
//defaults
|
1415 |
-
$days = 30;
|
1416 |
-
$message = __('You will have to renew your subscription in order to continue getting the updates and support.', 'installer');
|
1417 |
-
|
1418 |
-
}
|
1419 |
-
|
1420 |
-
if(!empty($this->settings['repositories'][$repository_id]['subscription'])){
|
1421 |
-
$subscription = $this->settings['repositories'][$repository_id]['subscription'];
|
1422 |
-
|
1423 |
-
if($subscription['data']->subscription_type == $subscription_id && !empty($subscription['data']->expires)){
|
1424 |
-
|
1425 |
-
if(strtotime($subscription['data']->expires) < strtotime(sprintf("+%d day", $days))){
|
1426 |
-
|
1427 |
-
$days_to_expiration = ceil((strtotime($subscription['data']->expires) - time()) / 86400);
|
1428 |
-
|
1429 |
-
echo '<div><p class="installer-warn-box">' .
|
1430 |
-
sprintf(_n('Your subscription expires in %d day.', 'Your subscription expires in %d days.', $days_to_expiration, 'installer'), $days_to_expiration) .
|
1431 |
-
'<br />' . $message .
|
1432 |
-
'</p></div>';
|
1433 |
-
|
1434 |
-
$show = true;
|
1435 |
-
|
1436 |
-
}
|
1437 |
-
|
1438 |
-
}
|
1439 |
-
|
1440 |
-
}
|
1441 |
-
|
1442 |
-
|
1443 |
-
}
|
1444 |
-
}
|
1445 |
-
|
1446 |
-
|
1447 |
-
return $show;
|
1448 |
-
|
1449 |
-
}
|
1450 |
-
|
1451 |
-
public function setup_plugins_renew_warnings(){
|
1452 |
-
|
1453 |
-
$plugins = get_plugins();
|
1454 |
-
|
1455 |
-
$subscriptions_with_warnings = array();
|
1456 |
-
foreach($this->settings['repositories'] as $repository_id => $repository){
|
1457 |
-
|
1458 |
-
if($this->repository_has_valid_subscription($repository_id)){
|
1459 |
-
$subscription_type = $this->settings['repositories'][$repository_id]['subscription']['data']->subscription_type;
|
1460 |
-
$expires = $this->settings['repositories'][$repository_id]['subscription']['data']->expires;
|
1461 |
-
|
1462 |
-
$never_expires = isset($this->settings['repositories'][$repository_id]['subscription'])
|
1463 |
-
&& empty($this->settings['repositories'][$repository_id]['subscription']['data']->expires)
|
1464 |
-
&& (
|
1465 |
-
$this->settings['repositories'][$repository_id]['subscription']['data']->status == 4 ||
|
1466 |
-
$this->settings['repositories'][$repository_id]['subscription']['data']->status == 1
|
1467 |
-
);
|
1468 |
-
|
1469 |
-
if(!$never_expires){
|
1470 |
-
if(isset($this->settings['repositories'][$repository_id]['data']['subscriptions_meta']['expiration'][$subscription_type])){
|
1471 |
-
|
1472 |
-
$days_warning = $this->settings['repositories'][$repository_id]['data']['subscriptions_meta']['expiration'][$subscription_type]['days_warning'];
|
1473 |
-
$custom_message = $this->settings['repositories'][$repository_id]['data']['subscriptions_meta']['expiration'][$subscription_type]['warning_message'];
|
1474 |
-
|
1475 |
-
}else{
|
1476 |
-
//defaults
|
1477 |
-
$days_warning = 30;
|
1478 |
-
$custom_message = __('You will have to renew your subscription in order to continue getting the updates and support.', 'installer');
|
1479 |
-
}
|
1480 |
-
|
1481 |
-
if(strtotime($expires) < strtotime(sprintf('+%d day', $days_warning)) ){
|
1482 |
-
|
1483 |
-
$days_to_expiration = ceil((strtotime($expires) - time()) / 86400);
|
1484 |
-
|
1485 |
-
$message = sprintf(_n('Your subscription expires in %d day.', 'Your subscription expires in %d days.', $days_to_expiration, 'installer'), $days_to_expiration);
|
1486 |
-
$subscriptions_with_warnings[$subscription_type] = $message . ' ' . $custom_message;
|
1487 |
-
|
1488 |
-
}
|
1489 |
-
}
|
1490 |
-
|
1491 |
-
}
|
1492 |
-
|
1493 |
-
}
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
foreach($plugins as $plugin_id => $plugin){
|
1498 |
-
|
1499 |
-
$slug = dirname($plugin_id);
|
1500 |
-
if(empty($slug)) continue;
|
1501 |
-
|
1502 |
-
foreach($this->settings['repositories'] as $repository_id => $repository){
|
1503 |
-
|
1504 |
-
if($this->repository_has_valid_subscription($repository_id)){
|
1505 |
-
|
1506 |
-
foreach($repository['data']['packages'] as $package){
|
1507 |
-
|
1508 |
-
foreach($package['products'] as $product){
|
1509 |
-
|
1510 |
-
foreach($product['plugins'] as $plugin_slug){
|
1511 |
-
|
1512 |
-
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
1513 |
-
|
1514 |
-
if($download['slug'] == $slug || $download['name'] == $plugin['Name'] || $download['name'] == $plugin['Title']){ //match order: slug, name, title
|
1515 |
-
|
1516 |
-
if(isset($subscriptions_with_warnings[$product['subscription_type']])){
|
1517 |
-
|
1518 |
-
$this->_plugins_renew_warnings[$plugin_id] = $subscriptions_with_warnings[$product['subscription_type']];
|
1519 |
-
|
1520 |
-
}
|
1521 |
-
|
1522 |
-
}
|
1523 |
-
|
1524 |
-
}
|
1525 |
-
|
1526 |
-
}
|
1527 |
-
|
1528 |
-
}
|
1529 |
-
|
1530 |
-
}
|
1531 |
-
|
1532 |
-
}
|
1533 |
-
|
1534 |
-
}
|
1535 |
-
|
1536 |
-
}
|
1537 |
-
|
1538 |
-
public function queue_plugins_renew_warnings() {
|
1539 |
-
|
1540 |
-
if(!empty($this->_plugins_renew_warnings)){
|
1541 |
-
|
1542 |
-
foreach($this->_plugins_renew_warnings as $plugin_id => $message){
|
1543 |
-
|
1544 |
-
add_action( "after_plugin_row_" . $plugin_id, array($this, 'plugins_renew_warning'), 10, 3 );
|
1545 |
-
}
|
1546 |
-
|
1547 |
-
}
|
1548 |
-
|
1549 |
-
}
|
1550 |
-
|
1551 |
-
public function plugins_renew_warning($plugin_file, $plugin_data, $status){
|
1552 |
-
|
1553 |
-
if(empty($this->_plugins_renew_warnings[$plugin_file])) return;
|
1554 |
-
|
1555 |
-
$wp_list_table = _get_list_table('WP_Plugins_List_Table');
|
1556 |
-
?>
|
1557 |
-
|
1558 |
-
<tr class="plugin-update-tr"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
|
1559 |
-
<div class="update-message">
|
1560 |
-
<?php
|
1561 |
-
echo $this->_plugins_renew_warnings[$plugin_file]. ' ';
|
1562 |
-
printf(__('%sRenew here%s.', 'installer'),
|
1563 |
-
'<a href="' . $this->menu_url() . '">', '</a>');
|
1564 |
-
?>
|
1565 |
-
</div>
|
1566 |
-
</tr>
|
1567 |
-
|
1568 |
-
<?php
|
1569 |
-
|
1570 |
-
}
|
1571 |
-
|
1572 |
-
public function get_subscription_type_for_repository($repository_id){
|
1573 |
-
|
1574 |
-
$subscription_type = false;
|
1575 |
-
|
1576 |
-
if(!empty($this->settings['repositories'][$repository_id]['subscription'])){
|
1577 |
-
$subscription_type = $this->settings['repositories'][$repository_id]['subscription']['data']->subscription_type;
|
1578 |
-
}
|
1579 |
-
|
1580 |
-
return $subscription_type;
|
1581 |
-
|
1582 |
-
}
|
1583 |
-
|
1584 |
-
public function have_superior_subscription($subscription_type, $product){
|
1585 |
-
|
1586 |
-
$have = false;
|
1587 |
-
|
1588 |
-
if(is_array($product['upgrades'])){
|
1589 |
-
foreach($product['upgrades'] as $u){
|
1590 |
-
if($u['subscription_type'] == $subscription_type){
|
1591 |
-
$have = true;
|
1592 |
-
break;
|
1593 |
-
}
|
1594 |
-
}
|
1595 |
-
}
|
1596 |
-
|
1597 |
-
return $have;
|
1598 |
-
}
|
1599 |
-
|
1600 |
-
public function is_product_available_for_download($product_name, $repository_id){
|
1601 |
-
|
1602 |
-
$available = false;
|
1603 |
-
|
1604 |
-
$subscription_type = $this->get_subscription_type_for_repository($repository_id);
|
1605 |
-
$expired = $this->repository_has_expired_subscription($repository_id);
|
1606 |
-
|
1607 |
-
if($this->repository_has_subscription($repository_id) && !$expired){
|
1608 |
-
|
1609 |
-
$this->set_hierarchy_and_order();
|
1610 |
-
|
1611 |
-
foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package_id => $package){
|
1612 |
-
|
1613 |
-
$has_top_package = false;
|
1614 |
-
|
1615 |
-
foreach($package['products'] as $product){
|
1616 |
-
|
1617 |
-
if($subscription_type == $product['subscription_type']){
|
1618 |
-
$has_top_package = true;
|
1619 |
-
if($product['name'] == $product_name){
|
1620 |
-
return $available = true;
|
1621 |
-
}
|
1622 |
-
}
|
1623 |
-
|
1624 |
-
}
|
1625 |
-
|
1626 |
-
if(!empty($package['sub-packages'])){
|
1627 |
-
foreach($package['sub-packages'] as $sub_package){
|
1628 |
-
foreach($sub_package['products'] as $product){
|
1629 |
-
if($product['name'] == $product_name && ($subscription_type == $product['subscription_type'] || $has_top_package)){
|
1630 |
-
return $available = true;
|
1631 |
-
}
|
1632 |
-
}
|
1633 |
-
}
|
1634 |
-
}
|
1635 |
-
|
1636 |
-
}
|
1637 |
-
}
|
1638 |
-
|
1639 |
-
return $available;
|
1640 |
-
|
1641 |
-
}
|
1642 |
-
|
1643 |
-
public function get_upgrade_options($repository_id){
|
1644 |
-
$all_upgrades = array();
|
1645 |
-
|
1646 |
-
|
1647 |
-
//get all products: packages and subpackages
|
1648 |
-
$all_products = array();
|
1649 |
-
foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package){
|
1650 |
-
foreach($package['products'] as $product) {
|
1651 |
-
$all_products[] = $product;
|
1652 |
-
}
|
1653 |
-
if(!empty($package['sub-packages'])){
|
1654 |
-
foreach($package['sub-packages'] as $subpackage){
|
1655 |
-
foreach($subpackage['products'] as $product) {
|
1656 |
-
$all_products[] = $product;
|
1657 |
-
}
|
1658 |
-
|
1659 |
-
}
|
1660 |
-
|
1661 |
-
}
|
1662 |
-
|
1663 |
-
}
|
1664 |
-
|
1665 |
-
foreach( $all_products as $product ) {
|
1666 |
-
if ($product['upgrades']) {
|
1667 |
-
foreach ($product['upgrades'] as $upgrade) {
|
1668 |
-
if ($this->repository_has_valid_subscription($repository_id) || ($this->repository_has_subscription($repository_id) && $upgrade['including_expired'])) {
|
1669 |
-
$all_upgrades[$upgrade['subscription_type']][$product['subscription_type']] = $upgrade;
|
1670 |
-
}
|
1671 |
-
}
|
1672 |
-
}
|
1673 |
-
}
|
1674 |
-
|
1675 |
-
return $all_upgrades;
|
1676 |
-
|
1677 |
-
}
|
1678 |
-
|
1679 |
-
public function append_site_key_to_download_url($url, $key, $repository_id){
|
1680 |
-
|
1681 |
-
$url_params['site_key'] = $key;
|
1682 |
-
$url_params['site_url'] = $this->get_installer_site_url( $repository_id );
|
1683 |
-
|
1684 |
-
|
1685 |
-
// Add extra parameters for custom Installer packages
|
1686 |
-
if( !empty($this->package_source) ){
|
1687 |
-
$extra = $this->get_extra_url_parameters();
|
1688 |
-
if( !empty($extra['repository']) && $extra['repository'] == $repository_id ) {
|
1689 |
-
unset($extra['repository']);
|
1690 |
-
foreach($extra as $key => $val){
|
1691 |
-
$url_params[$key] = $val;
|
1692 |
-
}
|
1693 |
-
}
|
1694 |
-
}
|
1695 |
-
|
1696 |
-
$url = add_query_arg($url_params, $url);
|
1697 |
-
|
1698 |
-
if($repository_id == 'wpml'){
|
1699 |
-
$url = add_query_arg(array('using_icl' => $this->_using_icl, 'wpml_version' => $this->_wpml_version), $url);
|
1700 |
-
}
|
1701 |
-
|
1702 |
-
return $url;
|
1703 |
-
|
1704 |
-
}
|
1705 |
-
|
1706 |
-
public function plugin_is_installed($name, $slug, $version = null){
|
1707 |
-
|
1708 |
-
$is = false;
|
1709 |
-
|
1710 |
-
$plugins = get_plugins();
|
1711 |
-
|
1712 |
-
foreach($plugins as $plugin_id => $plugin){
|
1713 |
-
|
1714 |
-
$wp_plugin_slug = dirname($plugin_id);
|
1715 |
-
|
1716 |
-
// Exception: embedded plugins
|
1717 |
-
if( $wp_plugin_slug == $slug || $plugin['Name'] == $name || $plugin['Title'] == $name || ( $wp_plugin_slug == $slug . '-embedded' || $plugin['Name'] == $name . ' Embedded' ) ){
|
1718 |
-
if($version){
|
1719 |
-
if(version_compare($plugin['Version'], $version, '>=')){
|
1720 |
-
$is = $plugin['Version'];
|
1721 |
-
}
|
1722 |
-
}else{
|
1723 |
-
$is = $plugin['Version'];
|
1724 |
-
}
|
1725 |
-
|
1726 |
-
break;
|
1727 |
-
}
|
1728 |
-
|
1729 |
-
}
|
1730 |
-
|
1731 |
-
//exception: Types name difference
|
1732 |
-
if(!$is && $name == 'Types'){
|
1733 |
-
return $this->plugin_is_installed('Types - Complete Solution for Custom Fields and Types', $slug, $version);
|
1734 |
-
}
|
1735 |
-
|
1736 |
-
return $is;
|
1737 |
-
}
|
1738 |
-
|
1739 |
-
public function plugin_is_embedded_version($name, $slug){
|
1740 |
-
$is = false;
|
1741 |
-
|
1742 |
-
$plugins = get_plugins();
|
1743 |
-
|
1744 |
-
//false if teh full version is also installed
|
1745 |
-
$is_full_installed = false;
|
1746 |
-
foreach($plugins as $plugin_id => $plugin){
|
1747 |
-
|
1748 |
-
if(($plugin['Name'] == $name && !preg_match("#-embedded$#", $slug)) ){
|
1749 |
-
$is_full_installed = true;
|
1750 |
-
break;
|
1751 |
-
}
|
1752 |
-
|
1753 |
-
}
|
1754 |
-
|
1755 |
-
if($is_full_installed){
|
1756 |
-
return false;
|
1757 |
-
}
|
1758 |
-
|
1759 |
-
foreach($plugins as $plugin_id => $plugin){
|
1760 |
-
|
1761 |
-
// TBD
|
1762 |
-
$wp_plugin_slug = dirname($plugin_id);
|
1763 |
-
if( $wp_plugin_slug == $slug . '-embedded' && $plugin['Name'] == $name . ' Embedded'){
|
1764 |
-
$is = true;
|
1765 |
-
break;
|
1766 |
-
}
|
1767 |
-
|
1768 |
-
}
|
1769 |
-
|
1770 |
-
return $is;
|
1771 |
-
|
1772 |
-
}
|
1773 |
-
|
1774 |
-
//Alias for plugin_is_installed
|
1775 |
-
public function get_plugin_installed_version($name, $slug){
|
1776 |
-
|
1777 |
-
return $this->plugin_is_installed($name, $slug);
|
1778 |
-
|
1779 |
-
}
|
1780 |
-
|
1781 |
-
public function get_plugin_repository_version($repository_id, $slug){
|
1782 |
-
$version = false;
|
1783 |
-
|
1784 |
-
if(!empty($this->settings['repositories'][$repository_id]['data']['packages'])){
|
1785 |
-
foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package){
|
1786 |
-
foreach($package['products'] as $product) {
|
1787 |
-
|
1788 |
-
foreach($product['plugins'] as $plugin_slug){
|
1789 |
-
|
1790 |
-
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
1791 |
-
|
1792 |
-
if($download['slug'] == $slug){
|
1793 |
-
$version = $download['version'];
|
1794 |
-
break (3);
|
1795 |
-
}
|
1796 |
-
|
1797 |
-
}
|
1798 |
-
|
1799 |
-
}
|
1800 |
-
}
|
1801 |
-
}
|
1802 |
-
|
1803 |
-
return $version;
|
1804 |
-
}
|
1805 |
-
|
1806 |
-
public function is_uploading_allowed(){
|
1807 |
-
|
1808 |
-
//_deprecated_function ( __FUNCTION__, '1.7.3', 'Installer_Dependencies::' . __FUNCTION__ );
|
1809 |
-
return $this->dependencies->is_uploading_allowed();
|
1810 |
-
|
1811 |
-
}
|
1812 |
-
|
1813 |
-
public function download_plugin_ajax_handler(){
|
1814 |
-
|
1815 |
-
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
1816 |
-
require_once $this->plugin_path() . '/includes/installer-upgrader-skins.php';
|
1817 |
-
|
1818 |
-
$data = json_decode( base64_decode( sanitize_text_field ( $_POST['data'] ) ), true );
|
1819 |
-
|
1820 |
-
$ret = false;
|
1821 |
-
$plugin_id = false;
|
1822 |
-
$message = '';
|
1823 |
-
|
1824 |
-
//validate subscription
|
1825 |
-
$site_key = $this->get_repository_site_key($data['repository_id']);
|
1826 |
-
$subscription_data = $this->fetch_subscription_data( $data['repository_id'], $site_key , self::SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_REPORT);
|
1827 |
-
|
1828 |
-
if($subscription_data && !is_wp_error($subscription_data) && $this->repository_has_valid_subscription($data['repository_id'])){
|
1829 |
-
|
1830 |
-
if($data['nonce'] == wp_create_nonce('install_plugin_' . $data['url'])){
|
1831 |
-
|
1832 |
-
$upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin
|
1833 |
-
$upgrader = new Plugin_Upgrader($upgrader_skins);
|
1834 |
-
|
1835 |
-
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
|
1836 |
-
|
1837 |
-
$plugins = get_plugins();
|
1838 |
-
|
1839 |
-
//upgrade or install?
|
1840 |
-
foreach($plugins as $id => $plugin){
|
1841 |
-
$wp_plugin_slug = dirname($id);
|
1842 |
-
$is_embedded = $this->plugin_is_embedded_version(preg_replace('/ Embedded$/', '', $plugin['Name']), preg_replace('/-embedded$/', '', $wp_plugin_slug));
|
1843 |
-
|
1844 |
-
if($wp_plugin_slug == $data['slug'] || $is_embedded && preg_replace('/-embedded$/', '', $wp_plugin_slug) == $data['slug']){
|
1845 |
-
$plugin_id = $id;
|
1846 |
-
break;
|
1847 |
-
}
|
1848 |
-
}
|
1849 |
-
|
1850 |
-
if($plugin_id && empty($is_embedded)){ //upgrade
|
1851 |
-
$response['upgrade'] = 1;
|
1852 |
-
|
1853 |
-
$plugin_is_active = is_plugin_active($plugin_id);
|
1854 |
-
|
1855 |
-
$ret = $upgrader->upgrade($plugin_id);
|
1856 |
-
|
1857 |
-
if(!$ret && !empty($upgrader->skin->installer_error)){
|
1858 |
-
if(is_wp_error($upgrader->skin->installer_error)){
|
1859 |
-
$message = $upgrader->skin->installer_error->get_error_message() .
|
1860 |
-
' (' . $upgrader->skin->installer_error->get_error_data() . ')';
|
1861 |
-
}
|
1862 |
-
}
|
1863 |
-
|
1864 |
-
if($plugin_is_active){
|
1865 |
-
//prevent redirects
|
1866 |
-
add_filter('wp_redirect', '__return_false');
|
1867 |
-
activate_plugin($plugin_id);
|
1868 |
-
}
|
1869 |
-
|
1870 |
-
}else{ //install
|
1871 |
-
|
1872 |
-
if($is_embedded){
|
1873 |
-
delete_plugins(array($plugin_id));
|
1874 |
-
}
|
1875 |
-
|
1876 |
-
$response['install'] = 1;
|
1877 |
-
$ret = $upgrader->install($data['url']);
|
1878 |
-
if(!$ret && !empty($upgrader->skin->installer_error)){
|
1879 |
-
if(is_wp_error($upgrader->skin->installer_error)){
|
1880 |
-
$message = $upgrader->skin->installer_error->get_error_message() .
|
1881 |
-
' (' . $upgrader->skin->installer_error->get_error_data() . ')';
|
1882 |
-
}
|
1883 |
-
}
|
1884 |
-
}
|
1885 |
-
|
1886 |
-
$plugins = get_plugins(); //read again
|
1887 |
-
|
1888 |
-
if($ret && !empty($_POST['activate'])){
|
1889 |
-
foreach($plugins as $id => $plugin){
|
1890 |
-
$wp_plugin_slug = dirname($id);
|
1891 |
-
if($wp_plugin_slug == $data['slug']){
|
1892 |
-
$plugin_version = $plugin['Version'];
|
1893 |
-
$plugin_id = $id;
|
1894 |
-
break;
|
1895 |
-
}
|
1896 |
-
}
|
1897 |
-
|
1898 |
-
}
|
1899 |
-
|
1900 |
-
}
|
1901 |
-
|
1902 |
-
} else { //subscription not valid
|
1903 |
-
|
1904 |
-
$ret = false;
|
1905 |
-
$message = __('Your subscription appears to no longer be valid. Please try to register again using a valid site key.', 'installer');
|
1906 |
-
}
|
1907 |
-
|
1908 |
-
$response['version'] = isset($plugin_version) ? $plugin_version : 0;
|
1909 |
-
$response['plugin_id'] = $plugin_id;
|
1910 |
-
$response['nonce'] = wp_create_nonce('activate_' . $plugin_id);
|
1911 |
-
$response['success'] = $ret;
|
1912 |
-
$response['message'] = $message;
|
1913 |
-
|
1914 |
-
echo json_encode( $response );
|
1915 |
-
exit;
|
1916 |
-
|
1917 |
-
}
|
1918 |
-
|
1919 |
-
public function download_plugin($slug, $url){
|
1920 |
-
|
1921 |
-
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
1922 |
-
require_once $this->plugin_path() . '/includes/installer-upgrader-skins.php';
|
1923 |
-
|
1924 |
-
$upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin
|
1925 |
-
$upgrader = new Plugin_Upgrader($upgrader_skins);
|
1926 |
-
|
1927 |
-
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
|
1928 |
-
|
1929 |
-
$plugins = get_plugins();
|
1930 |
-
|
1931 |
-
$plugin_id = false;
|
1932 |
-
|
1933 |
-
//upgrade or install?
|
1934 |
-
foreach($plugins as $id => $plugin){
|
1935 |
-
$wp_plugin_slug = dirname($id);
|
1936 |
-
if($wp_plugin_slug == $slug){
|
1937 |
-
$plugin_id = $id;
|
1938 |
-
break;
|
1939 |
-
}
|
1940 |
-
}
|
1941 |
-
|
1942 |
-
if($plugin_id){ //upgrade
|
1943 |
-
|
1944 |
-
$plugin_is_active = is_plugin_active($plugin_id);
|
1945 |
-
|
1946 |
-
$ret = $upgrader->upgrade($plugin_id);
|
1947 |
-
|
1948 |
-
if($plugin_is_active){
|
1949 |
-
activate_plugin($plugin_id);
|
1950 |
-
}
|
1951 |
-
|
1952 |
-
}else{ //install
|
1953 |
-
$ret = $upgrader->install($url);
|
1954 |
-
}
|
1955 |
-
|
1956 |
-
return $ret;
|
1957 |
-
|
1958 |
-
}
|
1959 |
-
|
1960 |
-
public function activate_plugin(){
|
1961 |
-
|
1962 |
-
$error = '';
|
1963 |
-
|
1964 |
-
$plugin_id = sanitize_text_field ( $_POST['plugin_id'] );
|
1965 |
-
if(isset($_POST['nonce']) && $plugin_id && $_POST['nonce'] == wp_create_nonce('activate_' . $plugin_id )){
|
1966 |
-
|
1967 |
-
// Deactivate any embedded version
|
1968 |
-
$plugin_slug = dirname($plugin_id);
|
1969 |
-
$active_plugins = get_option('active_plugins');
|
1970 |
-
foreach($active_plugins as $plugin){
|
1971 |
-
$wp_plugin_slug = dirname($plugin);
|
1972 |
-
if($wp_plugin_slug == $plugin_slug . '-embedded'){
|
1973 |
-
deactivate_plugins(array($plugin));
|
1974 |
-
break;
|
1975 |
-
}
|
1976 |
-
}
|
1977 |
-
|
1978 |
-
//prevent redirects
|
1979 |
-
add_filter('wp_redirect', '__return_false', 10000);
|
1980 |
-
|
1981 |
-
$return = activate_plugin($plugin_id);
|
1982 |
-
|
1983 |
-
if(is_wp_error($return)){
|
1984 |
-
$error = $return->get_error_message();
|
1985 |
-
}
|
1986 |
-
|
1987 |
-
}else{
|
1988 |
-
$error = 'error';
|
1989 |
-
}
|
1990 |
-
|
1991 |
-
$ret = array('error' => $error);
|
1992 |
-
|
1993 |
-
echo json_encode($ret);
|
1994 |
-
exit;
|
1995 |
-
|
1996 |
-
}
|
1997 |
-
|
1998 |
-
public function custom_plugins_api_call($false, $action, $args){
|
1999 |
-
|
2000 |
-
if($action == 'plugin_information'){
|
2001 |
-
|
2002 |
-
$plugins = get_plugins();
|
2003 |
-
$plugin_names = array();
|
2004 |
-
foreach( $plugins as $plugin_id => $plugin ) {
|
2005 |
-
// plugins by WP slug which (plugin folder) which can be different
|
2006 |
-
// will use this to compare by title
|
2007 |
-
$plugin_names[ dirname( $plugin_id ) ] = array(
|
2008 |
-
'name' => $plugin['Name'],
|
2009 |
-
'title' => $plugin['Title'],
|
2010 |
-
);
|
2011 |
-
}
|
2012 |
-
|
2013 |
-
$slug = $args->slug;
|
2014 |
-
|
2015 |
-
foreach($this->settings['repositories'] as $repository_id => $repository){
|
2016 |
-
|
2017 |
-
if(!$this->repository_has_valid_subscription($repository_id)){
|
2018 |
-
$site_key = false;
|
2019 |
-
}else{
|
2020 |
-
$site_key = $repository['subscription']['key'];
|
2021 |
-
}
|
2022 |
-
|
2023 |
-
foreach($repository['data']['packages'] as $package){
|
2024 |
-
|
2025 |
-
foreach($package['products'] as $product){
|
2026 |
-
|
2027 |
-
foreach($product['plugins'] as $plugin_slug){
|
2028 |
-
|
2029 |
-
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
2030 |
-
|
2031 |
-
if( $download['slug'] == $slug ||
|
2032 |
-
isset( $plugin_names[$slug] ) && (
|
2033 |
-
$plugin_names[$slug]['name'] == $download['name'] ||
|
2034 |
-
$plugin_names[$slug]['title'] == $download['name']
|
2035 |
-
)
|
2036 |
-
){
|
2037 |
-
|
2038 |
-
if( !empty( $download['free-on-wporg'] ) ){
|
2039 |
-
return false; // use data from wordpress.org
|
2040 |
-
}
|
2041 |
-
|
2042 |
-
$res = new stdClass();
|
2043 |
-
$res->external = true;
|
2044 |
-
|
2045 |
-
$res->name = $download['name'];
|
2046 |
-
$res->slug = $slug;
|
2047 |
-
$res->version = $download['version'];
|
2048 |
-
$res->author = '';
|
2049 |
-
$res->author_profile = '';
|
2050 |
-
$res->last_updated = $download['date'];
|
2051 |
-
|
2052 |
-
if($site_key){
|
2053 |
-
$res->download_link = $this->append_site_key_to_download_url($download['url'], $site_key, $repository_id);
|
2054 |
-
}
|
2055 |
-
|
2056 |
-
$res->homepage = $repository['data']['url'];
|
2057 |
-
$res->sections = array('Description' => $download['description'], 'Changelog' => $download['changelog']);
|
2058 |
-
|
2059 |
-
return $res;
|
2060 |
-
|
2061 |
-
}
|
2062 |
-
|
2063 |
-
}
|
2064 |
-
|
2065 |
-
}
|
2066 |
-
|
2067 |
-
}
|
2068 |
-
|
2069 |
-
}
|
2070 |
-
|
2071 |
-
}
|
2072 |
-
|
2073 |
-
return $false;
|
2074 |
-
|
2075 |
-
}
|
2076 |
-
|
2077 |
-
public function plugins_upgrade_check($update_plugins){
|
2078 |
-
|
2079 |
-
if(!empty($this->settings['repositories'])){
|
2080 |
-
|
2081 |
-
$plugins = get_plugins();
|
2082 |
-
|
2083 |
-
foreach($plugins as $plugin_id => $plugin){
|
2084 |
-
|
2085 |
-
$slug = dirname($plugin_id);
|
2086 |
-
if(empty($slug)) continue;
|
2087 |
-
|
2088 |
-
$version = $plugin['Version'];
|
2089 |
-
$name = $plugin['Name'];
|
2090 |
-
|
2091 |
-
foreach($this->settings['repositories'] as $repository_id => $repository){
|
2092 |
-
|
2093 |
-
|
2094 |
-
if(!$this->repository_has_valid_subscription($repository_id)){
|
2095 |
-
$site_key = false;
|
2096 |
-
}else{
|
2097 |
-
$site_key = $repository['subscription']['key'];
|
2098 |
-
//$subscription_type = $this->get_subscription_type_for_repository($repository_id);
|
2099 |
-
}
|
2100 |
-
|
2101 |
-
foreach($repository['data']['packages'] as $package){
|
2102 |
-
|
2103 |
-
foreach($package['products'] as $product){
|
2104 |
-
|
2105 |
-
foreach($product['plugins'] as $plugin_slug){
|
2106 |
-
|
2107 |
-
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
2108 |
-
|
2109 |
-
if(!empty($download['free-on-wporg'])) {
|
2110 |
-
continue;
|
2111 |
-
}
|
2112 |
-
|
2113 |
-
if(empty($update_plugins->response[$plugin_id]) && ($download['slug'] == $slug || $download['name'] == $name ) && version_compare($download['version'], $version, '>')){
|
2114 |
-
|
2115 |
-
$response = new stdClass();
|
2116 |
-
$response->id = 0;
|
2117 |
-
$response->slug = $slug;
|
2118 |
-
$response->plugin = $plugin_id;
|
2119 |
-
$response->new_version = $download['version'];
|
2120 |
-
$response->upgrade_notice = '';
|
2121 |
-
$response->url = $download['url'];
|
2122 |
-
if($site_key){
|
2123 |
-
$response->package = $this->append_site_key_to_download_url($download['url'], $site_key, $repository_id);
|
2124 |
-
}
|
2125 |
-
$update_plugins->checked[$plugin_id] = $version;
|
2126 |
-
$update_plugins->response[$plugin_id] = $response;
|
2127 |
-
|
2128 |
-
}
|
2129 |
-
|
2130 |
-
}
|
2131 |
-
|
2132 |
-
}
|
2133 |
-
|
2134 |
-
}
|
2135 |
-
|
2136 |
-
}
|
2137 |
-
|
2138 |
-
}
|
2139 |
-
|
2140 |
-
}
|
2141 |
-
|
2142 |
-
return $update_plugins;
|
2143 |
-
|
2144 |
-
}
|
2145 |
-
|
2146 |
-
public function setup_plugins_page_notices(){
|
2147 |
-
|
2148 |
-
$plugins = get_plugins();
|
2149 |
-
|
2150 |
-
foreach($plugins as $plugin_id => $plugin){
|
2151 |
-
|
2152 |
-
$slug = dirname($plugin_id);
|
2153 |
-
if(empty($slug)) continue;
|
2154 |
-
|
2155 |
-
$name = $plugin['Name'];
|
2156 |
-
|
2157 |
-
foreach($this->settings['repositories'] as $repository_id => $repository){
|
2158 |
-
|
2159 |
-
if(!$this->repository_has_valid_subscription($repository_id)){
|
2160 |
-
$site_key = false;
|
2161 |
-
}else{
|
2162 |
-
$site_key = $repository['subscription']['key'];
|
2163 |
-
}
|
2164 |
-
|
2165 |
-
foreach($repository['data']['packages'] as $package){
|
2166 |
-
|
2167 |
-
foreach($package['products'] as $product){
|
2168 |
-
|
2169 |
-
foreach($product['plugins'] as $plugin_slug){
|
2170 |
-
|
2171 |
-
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
2172 |
-
|
2173 |
-
if(!empty($download['free-on-wporg'])) {
|
2174 |
-
continue;
|
2175 |
-
}
|
2176 |
-
|
2177 |
-
if( $download['slug'] == $slug || $download['name'] == $name ){
|
2178 |
-
|
2179 |
-
if( !$site_key || !$this->plugin_is_registered($repository_id, $download['slug']) ){
|
2180 |
-
add_action( "after_plugin_row_" . $plugin_id, array($this, 'show_purchase_notice_under_plugin'), 10, 3 );
|
2181 |
-
}
|
2182 |
-
|
2183 |
-
}
|
2184 |
-
|
2185 |
-
}
|
2186 |
-
|
2187 |
-
}
|
2188 |
-
|
2189 |
-
}
|
2190 |
-
|
2191 |
-
}
|
2192 |
-
|
2193 |
-
}
|
2194 |
-
|
2195 |
-
}
|
2196 |
-
|
2197 |
-
public function show_purchase_notice_under_plugin($plugin_file, $plugin_data, $status){
|
2198 |
-
|
2199 |
-
$wp_list_table = _get_list_table('WP_Plugins_List_Table');
|
2200 |
-
$wp_version = preg_replace( '/-(.+)$/', '', $GLOBALS['wp_version'] );
|
2201 |
-
|
2202 |
-
if( version_compare( $wp_version, '4.6', '>=' ) ){
|
2203 |
-
|
2204 |
-
?>
|
2205 |
-
<tr class="plugin-update-tr installer-plugin-update-tr">
|
2206 |
-
<td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
|
2207 |
-
<div class="notice inline notice-warning notice-alt">
|
2208 |
-
<p class="installer-q-icon">
|
2209 |
-
<?php printf( __('You must have a valid subscription in order to get upgrades or support for this plugin. %sPurchase a subscription or enter an existing site key%s.', 'installer'),
|
2210 |
-
'<a href="' . $this->menu_url() . '">', '</a>'); ?>
|
2211 |
-
</p>
|
2212 |
-
</div>
|
2213 |
-
</td>
|
2214 |
-
</tr>
|
2215 |
-
<?php
|
2216 |
-
|
2217 |
-
} else {
|
2218 |
-
|
2219 |
-
?>
|
2220 |
-
<tr class="plugin-update-tr">
|
2221 |
-
<td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
|
2222 |
-
<div class="update-message installer-q-icon">
|
2223 |
-
<?php printf( __('You must have a valid subscription in order to get upgrades or support for this plugin. %sPurchase a subscription or enter an existing site key%s.', 'installer'),
|
2224 |
-
'<a href="' . $this->menu_url() . '">', '</a>'); ?>
|
2225 |
-
</div>
|
2226 |
-
</td>
|
2227 |
-
</tr>
|
2228 |
-
<?php
|
2229 |
-
|
2230 |
-
}
|
2231 |
-
|
2232 |
-
}
|
2233 |
-
|
2234 |
-
public function localize_strings(){
|
2235 |
-
|
2236 |
-
if(!empty($this->settings['repositories'])){
|
2237 |
-
foreach($this->settings['repositories'] as $repository_id => $repository){
|
2238 |
-
//set name as call2action when don't have any
|
2239 |
-
//products
|
2240 |
-
foreach($repository['data']['packages'] as $package_id => $package){
|
2241 |
-
foreach($package['products'] as $product_id => $product){
|
2242 |
-
if(empty($product['call2action'])){
|
2243 |
-
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['call2action'] = $product['name'];
|
2244 |
-
}
|
2245 |
-
|
2246 |
-
foreach($product['upgrades'] as $idx => $upg){
|
2247 |
-
if(empty($upg['call2action'])){
|
2248 |
-
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['upgrades'][$idx]['call2action'] = $upg['name'];
|
2249 |
-
}
|
2250 |
-
}
|
2251 |
-
|
2252 |
-
foreach($product['renewals'] as $idx => $rnw){
|
2253 |
-
if(empty($rnw['call2action'])){
|
2254 |
-
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['renewals'][$idx]['call2action'] = $rnw['name'];
|
2255 |
-
}
|
2256 |
-
|
2257 |
-
}
|
2258 |
-
|
2259 |
-
}
|
2260 |
-
}
|
2261 |
-
}
|
2262 |
-
}
|
2263 |
-
|
2264 |
-
global $sitepress;
|
2265 |
-
if(is_null($sitepress)){
|
2266 |
-
return;
|
2267 |
-
}
|
2268 |
-
|
2269 |
-
// default strings are always in English
|
2270 |
-
$user_admin_language = $sitepress->get_admin_language();
|
2271 |
-
|
2272 |
-
if($user_admin_language != 'en'){
|
2273 |
-
foreach($this->settings['repositories'] as $repository_id => $repository){
|
2274 |
-
|
2275 |
-
$localization = $repository['data']['localization'];
|
2276 |
-
|
2277 |
-
//packages
|
2278 |
-
foreach($repository['data']['packages'] as $package_id => $package){
|
2279 |
-
|
2280 |
-
if( isset($localization['packages'][$package_id]['name'][$user_admin_language]) ){
|
2281 |
-
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['name'] = $localization['packages'][$package_id]['name'][$user_admin_language];
|
2282 |
-
}
|
2283 |
-
if( isset($localization['packages'][$package_id]['description'][$user_admin_language]) ){
|
2284 |
-
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['description'] = $localization['packages'][$package_id]['description'][$user_admin_language];
|
2285 |
-
}
|
2286 |
-
|
2287 |
-
}
|
2288 |
-
|
2289 |
-
//products
|
2290 |
-
foreach($repository['data']['packages'] as $package_id => $package){
|
2291 |
-
foreach($package['products'] as $product_id => $product){
|
2292 |
-
|
2293 |
-
if( isset($localization['products'][$product_id]['name'][$user_admin_language]) ){
|
2294 |
-
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['name']
|
2295 |
-
= $localization['products'][$product_id]['name'][$user_admin_language];
|
2296 |
-
}
|
2297 |
-
if( isset($localization['products'][$product_id]['description'][$user_admin_language]) ){
|
2298 |
-
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['description']
|
2299 |
-
= $localization['products'][$product_id]['description'][$user_admin_language];
|
2300 |
-
}
|
2301 |
-
if( isset($localization['products'][$product_id]['call2action'][$user_admin_language]) ){
|
2302 |
-
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['name']
|
2303 |
-
= $localization['products'][$product_id]['call2action'][$user_admin_language];
|
2304 |
-
}
|
2305 |
-
|
2306 |
-
|
2307 |
-
}
|
2308 |
-
}
|
2309 |
-
|
2310 |
-
//subscription info
|
2311 |
-
if(isset($repository['data']['subscriptions_meta']['expiration'])){
|
2312 |
-
foreach($repository['data']['subscriptions_meta']['expiration'] as $subscription_id => $note){
|
2313 |
-
if(isset($localization['subscriptions-notes'][$subscription_id]['expiration-warning'][$user_admin_language])){
|
2314 |
-
$this->settings['repositories'][$repository_id]['data']['subscriptions_meta']['expiration'][$subscription_id]['warning_message']
|
2315 |
-
= $localization['subscriptions-notes'][$subscription_id]['expiration-warning'][$user_admin_language];
|
2316 |
-
}
|
2317 |
-
}
|
2318 |
-
}
|
2319 |
-
|
2320 |
-
}
|
2321 |
-
}
|
2322 |
-
|
2323 |
-
}
|
2324 |
-
|
2325 |
-
public function get_matching_cp($repository, $args = array()){
|
2326 |
-
$match = false;
|
2327 |
-
|
2328 |
-
|
2329 |
-
$cp_name = $cp_author = false;
|
2330 |
-
|
2331 |
-
if(isset($this->config['src_name']) && isset($this->config['src_author'])){
|
2332 |
-
|
2333 |
-
$cp_name = $this->config['src_name'];
|
2334 |
-
$cp_author = $this->config['src_author'];
|
2335 |
-
|
2336 |
-
}elseif(isset($args['src_name']) && isset($args['src_author'])){
|
2337 |
-
|
2338 |
-
$cp_name = $args['src_name'];
|
2339 |
-
$cp_author = $args['src_author'];
|
2340 |
-
|
2341 |
-
}
|
2342 |
-
|
2343 |
-
if(isset($repository['data']['marketing_cp'])){
|
2344 |
-
|
2345 |
-
foreach($repository['data']['marketing_cp'] as $cp){
|
2346 |
-
|
2347 |
-
if(!empty($cp['exp']) && time() > $cp['exp']){
|
2348 |
-
continue;
|
2349 |
-
}
|
2350 |
-
|
2351 |
-
//Use theme_name for plugins too
|
2352 |
-
if(!empty($cp['theme_name'])){
|
2353 |
-
if($cp['author_name'] == $cp_author && $cp['theme_name'] == $cp_name){
|
2354 |
-
$match = $cp;
|
2355 |
-
continue;
|
2356 |
-
}
|
2357 |
-
}else{
|
2358 |
-
if($cp['author_name'] == $cp_author){
|
2359 |
-
$match = $cp;
|
2360 |
-
continue;
|
2361 |
-
}
|
2362 |
-
}
|
2363 |
-
|
2364 |
-
}
|
2365 |
-
|
2366 |
-
}
|
2367 |
-
|
2368 |
-
return $match;
|
2369 |
-
}
|
2370 |
-
|
2371 |
-
public function set_filtered_prices($args = array()){
|
2372 |
-
|
2373 |
-
foreach($this->settings['repositories'] as $repository_id => $repository){
|
2374 |
-
|
2375 |
-
$match = $this->get_matching_cp($repository, $args);
|
2376 |
-
|
2377 |
-
if(empty($match)) continue;
|
2378 |
-
|
2379 |
-
foreach($repository['data']['packages'] as $package_id => $package){
|
2380 |
-
|
2381 |
-
foreach($package['products'] as $product_id => $product){
|
2382 |
-
|
2383 |
-
if($match['dtp'] == '%'){
|
2384 |
-
$fprice = round( $product['price'] * (1 - $match['amt']/100), 2 );
|
2385 |
-
$fprice = $fprice != round($fprice) ? sprintf('%.2f', $fprice) : round($fprice, 0);
|
2386 |
-
}elseif($match['dtp'] == '-'){
|
2387 |
-
$fprice = $product['price'] - $match['amt'];
|
2388 |
-
}else{
|
2389 |
-
$fprice = $product['price'];
|
2390 |
-
}
|
2391 |
-
|
2392 |
-
if($fprice){
|
2393 |
-
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['price_disc'] = $fprice;
|
2394 |
-
|
2395 |
-
$url_glue = false !== strpos($this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['url'], '?') ? '&' : '?';
|
2396 |
-
$cpndata = base64_encode(json_encode(array('theme_author' => $match['author_name'], 'theme_name' => $match['theme_name'], 'vlc' => $match['vlc'])));
|
2397 |
-
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['url'] .= $url_glue . 'cpn=' . $cpndata;
|
2398 |
-
|
2399 |
-
foreach($product['upgrades'] as $upgrade_id => $upgrade){
|
2400 |
-
|
2401 |
-
$fprice = false;
|
2402 |
-
if($match['dtp'] == '%'){
|
2403 |
-
$fprice = round( $upgrade['price'] * (1 - $match['amt']/100), 2 );
|
2404 |
-
$fprice = $fprice != round($fprice) ? sprintf('%.2f', $fprice) : round($fprice, 0);
|
2405 |
-
}elseif($match['dtp'] == '-'){
|
2406 |
-
$fprice = $upgrade['price'] - $match['amt'];
|
2407 |
-
}
|
2408 |
-
if($fprice){
|
2409 |
-
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['upgrades'][$upgrade_id]['price_disc'] = $fprice;
|
2410 |
-
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['upgrades'][$upgrade_id]['url'] .= $url_glue . 'cpn=' . $cpndata;
|
2411 |
-
}
|
2412 |
-
|
2413 |
-
|
2414 |
-
}
|
2415 |
-
|
2416 |
-
}
|
2417 |
-
|
2418 |
-
}
|
2419 |
-
|
2420 |
-
}
|
2421 |
-
|
2422 |
-
}
|
2423 |
-
|
2424 |
-
}
|
2425 |
-
|
2426 |
-
public function set_hierarchy_and_order(){
|
2427 |
-
|
2428 |
-
//2 levels
|
2429 |
-
if(!empty($this->settings['repositories'])) {
|
2430 |
-
foreach ($this->settings['repositories'] as $repository_id => $repository) {
|
2431 |
-
|
2432 |
-
if( empty( $repository['data']['packages'] ) ) continue;
|
2433 |
-
|
2434 |
-
$all_packages = $repository['data']['packages'];
|
2435 |
-
$ordered_packages = array();
|
2436 |
-
|
2437 |
-
//backward compatibility - 'order'
|
2438 |
-
foreach($all_packages as $k => $v){
|
2439 |
-
if(!isset($v['order'])){
|
2440 |
-
$all_packages[$k]['order'] = 0;
|
2441 |
-
}
|
2442 |
-
}
|
2443 |
-
|
2444 |
-
//select parents
|
2445 |
-
foreach ($all_packages as $package_id => $package) {
|
2446 |
-
if(empty($package['parent'])){
|
2447 |
-
$ordered_packages[$package_id] = $package;
|
2448 |
-
}
|
2449 |
-
}
|
2450 |
-
|
2451 |
-
//add sub-packages
|
2452 |
-
foreach($all_packages as $package_id => $package){
|
2453 |
-
if(!empty($package['parent'])) {
|
2454 |
-
if(isset($ordered_packages[$package['parent']])){
|
2455 |
-
$ordered_packages[$package['parent']]['sub-packages'][$package_id] = $package;
|
2456 |
-
}
|
2457 |
-
}
|
2458 |
-
}
|
2459 |
-
|
2460 |
-
// order parents
|
2461 |
-
usort($ordered_packages, array($this, '_order_packages_callback'));
|
2462 |
-
//order sub-packages
|
2463 |
-
foreach($ordered_packages as $package_id => $package){
|
2464 |
-
if(!empty($package['sub-packages'])) {
|
2465 |
-
usort($ordered_packages[$package_id]['sub-packages'], create_function('$a, $b', 'return $a[\'order\'] > $b[\'order\'];'));
|
2466 |
-
}
|
2467 |
-
}
|
2468 |
-
|
2469 |
-
$this->settings['repositories'][$repository_id]['data']['packages'] = $ordered_packages;
|
2470 |
-
|
2471 |
-
|
2472 |
-
}
|
2473 |
-
}
|
2474 |
-
|
2475 |
-
|
2476 |
-
}
|
2477 |
-
|
2478 |
-
public function _order_packages_callback($a, $b){
|
2479 |
-
return $a['order'] > $b['order'];
|
2480 |
-
}
|
2481 |
-
|
2482 |
-
public function get_support_tag_by_name( $name, $repository ){
|
2483 |
-
|
2484 |
-
if( is_array($this->settings['repositories'][$repository]['data']['support_tags'] )){
|
2485 |
-
foreach( $this->settings['repositories'][$repository]['data']['support_tags'] as $support_tag){
|
2486 |
-
if( $support_tag['name'] == $name ){
|
2487 |
-
return $support_tag['url'];
|
2488 |
-
}
|
2489 |
-
}
|
2490 |
-
}
|
2491 |
-
|
2492 |
-
return false;
|
2493 |
-
}
|
2494 |
-
|
2495 |
-
public function plugin_upgrade_custom_errors(){
|
2496 |
-
|
2497 |
-
if ( isset($_REQUEST['action']) ) {
|
2498 |
-
|
2499 |
-
$action = isset($_REQUEST['action']) ? sanitize_text_field ( $_REQUEST['action'] ) : '';
|
2500 |
-
|
2501 |
-
//bulk mode
|
2502 |
-
if('update-selected' == $action) {
|
2503 |
-
|
2504 |
-
global $plugins;
|
2505 |
-
|
2506 |
-
if(isset($plugins) && is_array($plugins)) {
|
2507 |
-
|
2508 |
-
foreach ($plugins as $k => $plugin) {
|
2509 |
-
$plugin_repository = false;
|
2510 |
-
|
2511 |
-
$wp_plugin_slug = dirname($plugin);
|
2512 |
-
|
2513 |
-
foreach ($this->settings['repositories'] as $repository_id => $repository) {
|
2514 |
-
|
2515 |
-
foreach ($repository['data']['packages'] as $package) {
|
2516 |
-
|
2517 |
-
foreach ($package['products'] as $product) {
|
2518 |
-
|
2519 |
-
foreach ($product['plugins'] as $plugin_slug) {
|
2520 |
-
|
2521 |
-
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
2522 |
-
|
2523 |
-
if ($download['slug'] == $wp_plugin_slug) {
|
2524 |
-
$plugin_repository = $repository_id;
|
2525 |
-
$product_name = $repository['data']['product-name'];
|
2526 |
-
$plugin_name = $download['name'];
|
2527 |
-
$free_on_wporg = !empty($download['free-on-wporg']);
|
2528 |
-
break;
|
2529 |
-
}
|
2530 |
-
|
2531 |
-
}
|
2532 |
-
|
2533 |
-
}
|
2534 |
-
|
2535 |
-
}
|
2536 |
-
|
2537 |
-
}
|
2538 |
-
|
2539 |
-
if ($plugin_repository) {
|
2540 |
-
|
2541 |
-
//validate subscription
|
2542 |
-
static $sub_cache = array();
|
2543 |
-
|
2544 |
-
if(empty($sub_cache[$plugin_repository])){
|
2545 |
-
$site_key = $this->get_repository_site_key($plugin_repository);
|
2546 |
-
if ($site_key) {
|
2547 |
-
$subscription_data = $this->fetch_subscription_data( $plugin_repository, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION );
|
2548 |
-
}
|
2549 |
-
|
2550 |
-
$sub_cache[$plugin_repository]['site_key'] = $site_key;
|
2551 |
-
$sub_cache[$plugin_repository]['subscription_data'] = isset($subscription_data) ? $subscription_data : false;
|
2552 |
-
}else{
|
2553 |
-
|
2554 |
-
$site_key = $sub_cache[$plugin_repository]['site_key'];
|
2555 |
-
$subscription_data = $sub_cache[$plugin_repository]['subscription_data'];
|
2556 |
-
|
2557 |
-
}
|
2558 |
-
|
2559 |
-
if(!$site_key && !empty($free_on_wporg)){ // allow the download from wp.org
|
2560 |
-
continue;
|
2561 |
-
}
|
2562 |
-
|
2563 |
-
if (empty($site_key) || empty($subscription_data)) {
|
2564 |
-
|
2565 |
-
|
2566 |
-
$error_message = sprintf(__("%s cannot update because your site's registration is not valid. Please %sregister %s%s again for this site first.", 'installer'),
|
2567 |
-
'<strong>' . $plugin_name . '</strong>', '<a target="_top" href="' . $this->menu_url() . '&validate_repository=' . $plugin_repository .
|
2568 |
-
'#repository-' . $plugin_repository . '">', $product_name, '</a>');
|
2569 |
-
|
2570 |
-
echo '<div class="updated error"><p>' . $error_message . '</p></div>';
|
2571 |
-
|
2572 |
-
unset($plugins[$k]);
|
2573 |
-
|
2574 |
-
|
2575 |
-
}
|
2576 |
-
|
2577 |
-
}
|
2578 |
-
|
2579 |
-
}
|
2580 |
-
|
2581 |
-
}
|
2582 |
-
|
2583 |
-
}
|
2584 |
-
|
2585 |
-
|
2586 |
-
if( 'upgrade-plugin' == $action || 'update-plugin' == $action ) {
|
2587 |
-
|
2588 |
-
$plugin = isset($_REQUEST['plugin']) ? trim( sanitize_text_field ( $_REQUEST['plugin'] ) ) : '';
|
2589 |
-
|
2590 |
-
$wp_plugin_slug = dirname($plugin);
|
2591 |
-
|
2592 |
-
$plugin_repository = false;
|
2593 |
-
|
2594 |
-
foreach($this->settings['repositories'] as $repository_id => $repository){
|
2595 |
-
|
2596 |
-
foreach($repository['data']['packages'] as $package){
|
2597 |
-
|
2598 |
-
foreach($package['products'] as $product){
|
2599 |
-
|
2600 |
-
foreach($product['plugins'] as $plugin_slug){
|
2601 |
-
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
2602 |
-
|
2603 |
-
//match by folder, will change to match by name and folder
|
2604 |
-
if($download['slug'] == $wp_plugin_slug) {
|
2605 |
-
$plugin_repository = $repository_id;
|
2606 |
-
$product_name = $repository['data']['product-name'];
|
2607 |
-
$plugin_name = $download['name'];
|
2608 |
-
$free_on_wporg = !empty($download['free-on-wporg']);
|
2609 |
-
break;
|
2610 |
-
}
|
2611 |
-
|
2612 |
-
}
|
2613 |
-
|
2614 |
-
}
|
2615 |
-
|
2616 |
-
}
|
2617 |
-
|
2618 |
-
}
|
2619 |
-
|
2620 |
-
if($plugin_repository) {
|
2621 |
-
|
2622 |
-
//validate subscription
|
2623 |
-
$site_key = $this->get_repository_site_key($plugin_repository);
|
2624 |
-
if ($site_key) {
|
2625 |
-
$subscription_data = $this->fetch_subscription_data( $plugin_repository, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION );
|
2626 |
-
}
|
2627 |
-
|
2628 |
-
if ( (empty($site_key) || empty($subscription_data)) && empty($free_on_wporg)) {
|
2629 |
-
|
2630 |
-
$error_message = sprintf(__("%s cannot update because your site's registration is not valid. Please %sregister %s%s again for this site first.", 'installer'),
|
2631 |
-
'<strong>'.$plugin_name . '</strong>', '<a href="' . $this->menu_url() . '&validate_repository=' . $plugin_repository .
|
2632 |
-
'#repository-' . $plugin_repository . '">', $product_name, '</a>');
|
2633 |
-
|
2634 |
-
if(defined('DOING_AJAX')){ //WP 4.2
|
2635 |
-
|
2636 |
-
$status = array(
|
2637 |
-
'update' => 'plugin',
|
2638 |
-
'plugin' => $plugin,
|
2639 |
-
'slug' => sanitize_key( $_POST['slug'] ),
|
2640 |
-
'oldVersion' => '',
|
2641 |
-
'newVersion' => '',
|
2642 |
-
);
|
2643 |
-
|
2644 |
-
$status['errorCode'] = 'wp_installer_invalid_subscription';
|
2645 |
-
$status['error'] = $error_message;
|
2646 |
-
|
2647 |
-
wp_send_json_error( $status );
|
2648 |
-
|
2649 |
-
} else { // WP 4.1.1
|
2650 |
-
echo '<div class="updated error"><p>' . $error_message . '</p></div>';
|
2651 |
-
|
2652 |
-
|
2653 |
-
echo '<div class="wrap">';
|
2654 |
-
echo '<h2>' . __('Update Plugin') . '</h2>';
|
2655 |
-
echo '<a href="' . admin_url('plugins.php') . '">' . __('Return to the plugins page') . '</a>';
|
2656 |
-
echo '</div>';
|
2657 |
-
require_once(ABSPATH . 'wp-admin/admin-footer.php');
|
2658 |
-
exit;
|
2659 |
-
|
2660 |
-
}
|
2661 |
-
|
2662 |
-
}
|
2663 |
-
|
2664 |
-
|
2665 |
-
}
|
2666 |
-
|
2667 |
-
}
|
2668 |
-
}
|
2669 |
-
|
2670 |
-
}
|
2671 |
-
|
2672 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
final class WP_Installer{
|
4 |
+
protected static $_instance = null;
|
5 |
+
|
6 |
+
public $settings = array();
|
7 |
+
|
8 |
+
private $repositories = array();
|
9 |
+
|
10 |
+
protected $api_debug = '';
|
11 |
+
|
12 |
+
private $config = array();
|
13 |
+
|
14 |
+
protected $_plugins_renew_warnings = array();
|
15 |
+
|
16 |
+
protected $_gz_on = false;
|
17 |
+
|
18 |
+
private $admin_messages = array();
|
19 |
+
|
20 |
+
private $_using_icl = false;
|
21 |
+
private $_wpml_version = false;
|
22 |
+
|
23 |
+
private $package_source = array();
|
24 |
+
|
25 |
+
const SITE_KEY_VALIDATION_SOURCE_OTHER = 0;
|
26 |
+
const SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_SPECIFIC = 1;
|
27 |
+
const SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_REPORT = 2;
|
28 |
+
const SITE_KEY_VALIDATION_SOURCE_REGISTRATION = 3;
|
29 |
+
const SITE_KEY_VALIDATION_SOURCE_REVALIDATION = 4;
|
30 |
+
const SITE_KEY_VALIDATION_SOURCE_UPDATES_CHECK = 5;
|
31 |
+
|
32 |
+
public $dependencies;
|
33 |
+
|
34 |
+
public static function instance() {
|
35 |
+
|
36 |
+
if ( is_null( self::$_instance ) ) {
|
37 |
+
self::$_instance = new self();
|
38 |
+
}
|
39 |
+
|
40 |
+
return self::$_instance;
|
41 |
+
}
|
42 |
+
|
43 |
+
public function __construct(){
|
44 |
+
|
45 |
+
if(!is_admin() || !is_user_logged_in()) return; //Only for admin
|
46 |
+
|
47 |
+
$this->_gz_on = function_exists('gzuncompress') && function_exists('gzcompress');
|
48 |
+
$this->settings = $this->get_settings();
|
49 |
+
|
50 |
+
add_action('admin_notices', array($this, 'show_site_key_nags'));
|
51 |
+
|
52 |
+
add_action('admin_notices', array($this, 'show_admin_messages'));
|
53 |
+
|
54 |
+
add_action('admin_init', array($this, 'load_embedded_plugins'), 0);
|
55 |
+
|
56 |
+
add_action('admin_menu', array($this, 'menu_setup'));
|
57 |
+
add_action('network_admin_menu', array($this, 'menu_setup'));
|
58 |
+
|
59 |
+
if(defined('DOING_AJAX') && isset($_POST['action']) && $_POST['action'] == 'installer_download_plugin'){
|
60 |
+
add_filter( 'site_transient_update_plugins', array( $this, 'plugins_upgrade_check') );
|
61 |
+
}
|
62 |
+
add_filter('plugins_api', array( $this, 'custom_plugins_api_call'), 10, 3);
|
63 |
+
add_filter('pre_set_site_transient_update_plugins', array( $this, 'plugins_upgrade_check'));
|
64 |
+
|
65 |
+
// register repositories
|
66 |
+
$this->load_repositories_list();
|
67 |
+
|
68 |
+
if( empty($this->settings['last_repositories_update']) || time() - $this->settings['last_repositories_update'] > 86400
|
69 |
+
|| ( isset($_GET['force-check']) && $_GET['force-check'] == 1 ) ){
|
70 |
+
$this->refresh_repositories_data();
|
71 |
+
}
|
72 |
+
|
73 |
+
// default config
|
74 |
+
$this->config['plugins_install_tab'] = false;
|
75 |
+
|
76 |
+
add_action('init', array($this, 'init'));
|
77 |
+
|
78 |
+
//add_filter('wp_installer_buy_url', array($this, 'append_parameters_to_buy_url'));
|
79 |
+
|
80 |
+
add_action('init', array($this,'load_locale'));
|
81 |
+
|
82 |
+
}
|
83 |
+
|
84 |
+
public function get_repositories() {
|
85 |
+
|
86 |
+
return $this->repositories;
|
87 |
+
|
88 |
+
}
|
89 |
+
|
90 |
+
public function set_config($key, $value){
|
91 |
+
|
92 |
+
$this->config[$key] = $value;
|
93 |
+
|
94 |
+
}
|
95 |
+
|
96 |
+
public function init(){
|
97 |
+
global $pagenow;
|
98 |
+
|
99 |
+
$this->dependencies = new Installer_Dependencies;
|
100 |
+
|
101 |
+
if(empty($this->settings['_pre_1_0_clean_up'])) {
|
102 |
+
$this->_pre_1_0_clean_up();
|
103 |
+
}
|
104 |
+
|
105 |
+
$this->settings = $this->_old_products_format_backwards_compatibility($this->settings);
|
106 |
+
|
107 |
+
if ( !function_exists( 'get_plugins' ) ) {
|
108 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
109 |
+
}
|
110 |
+
|
111 |
+
$this->_using_icl = function_exists('wpml_site_uses_icl') && wpml_site_uses_icl();
|
112 |
+
$this->_wpml_version = defined('ICL_SITEPRESS_VERSION') ? ICL_SITEPRESS_VERSION : '';
|
113 |
+
|
114 |
+
wp_enqueue_script('installer-admin', $this->res_url() . '/res/js/admin.js', array('jquery'), $this->version());
|
115 |
+
wp_enqueue_style('installer-admin', $this->res_url() . '/res/css/admin.css', array(), $this->version());
|
116 |
+
|
117 |
+
$translation_array = array(
|
118 |
+
'installing' => __( 'Installing %s', 'installer' ),
|
119 |
+
'updating' => __( 'Updating %s', 'installer' ),
|
120 |
+
'activating' => __( 'Activating %s', 'installer' )
|
121 |
+
);
|
122 |
+
|
123 |
+
wp_localize_script( 'installer-admin', 'installer_strings', $translation_array );
|
124 |
+
|
125 |
+
if($pagenow == 'plugins.php'){
|
126 |
+
add_action('admin_notices', array($this, 'setup_plugins_page_notices'));
|
127 |
+
add_action('admin_notices', array($this, 'setup_plugins_renew_warnings'), 10);
|
128 |
+
add_action('admin_notices', array($this, 'queue_plugins_renew_warnings'), 20);
|
129 |
+
|
130 |
+
add_action('admin_init', array($this, 'setup_plugins_action_links'));
|
131 |
+
|
132 |
+
}
|
133 |
+
|
134 |
+
if($this->is_repositories_page()){
|
135 |
+
add_action('admin_init', array($this, 'validate_repository_subscription'));
|
136 |
+
}
|
137 |
+
|
138 |
+
if(defined('DOING_AJAX')){
|
139 |
+
add_action('wp_ajax_save_site_key', array($this, 'save_site_key'));
|
140 |
+
add_action('wp_ajax_remove_site_key', array($this, 'remove_site_key_ajax'));
|
141 |
+
add_action('wp_ajax_update_site_key', array($this, 'update_site_key'));
|
142 |
+
|
143 |
+
add_action('wp_ajax_installer_download_plugin', array($this, 'download_plugin_ajax_handler'));
|
144 |
+
add_action('wp_ajax_installer_activate_plugin', array($this, 'activate_plugin'));
|
145 |
+
|
146 |
+
add_action('wp_ajax_installer_dismiss_nag', array($this, 'dismiss_nag'));
|
147 |
+
}
|
148 |
+
|
149 |
+
if($pagenow == 'update.php'){
|
150 |
+
if(isset($_GET['action']) && $_GET['action'] == 'update-selected'){
|
151 |
+
add_action('admin_head', array($this, 'plugin_upgrade_custom_errors')); //iframe/bulk
|
152 |
+
}else{
|
153 |
+
add_action('all_admin_notices', array($this, 'plugin_upgrade_custom_errors')); //regular/singular
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
// WP 4.2
|
158 |
+
if(defined('DOING_AJAX')){
|
159 |
+
add_action('wp_ajax_update-plugin', array($this, 'plugin_upgrade_custom_errors'), 0); // high priority, before WP
|
160 |
+
}
|
161 |
+
|
162 |
+
//Include theme support
|
163 |
+
include_once $this->plugin_path() . '/includes/class-installer-theme.php';
|
164 |
+
|
165 |
+
// Extra information about the source of Installer
|
166 |
+
$package_source_file = $this->plugin_path() . '/installer-source.json';
|
167 |
+
if( file_exists( $package_source_file ) ){
|
168 |
+
$this->package_source = json_decode( file_get_contents( $package_source_file ) );
|
169 |
+
}
|
170 |
+
}
|
171 |
+
|
172 |
+
protected function log($message){
|
173 |
+
if( defined('WPML_INSTALLER_LOGGING') && WPML_INSTALLER_LOGGING ){
|
174 |
+
if($fh = @fopen( $this->plugin_path() . '/installer.log', 'a' )){
|
175 |
+
fwrite($fh, current_time( 'mysql' ) . "\t" . $message . "\n");
|
176 |
+
}
|
177 |
+
}
|
178 |
+
}
|
179 |
+
|
180 |
+
public function register_admin_message($text, $type = 'updated'){
|
181 |
+
$this->admin_messages[] = array('text' => $text, 'type' => $type);
|
182 |
+
}
|
183 |
+
|
184 |
+
public function show_admin_messages(){
|
185 |
+
if(!empty($this->admin_messages)){
|
186 |
+
$types = array( 'error', 'updated', 'notice' );
|
187 |
+
foreach($this->admin_messages as $message){
|
188 |
+
$class = in_array( $message['type'], $types ) ? $message['type'] : 'updated';
|
189 |
+
?>
|
190 |
+
<div class="<?php echo $class ?>">
|
191 |
+
<p>
|
192 |
+
<?php echo $message['text'] ?>
|
193 |
+
</p>
|
194 |
+
</div>
|
195 |
+
<?php
|
196 |
+
}
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
public function load_locale(){
|
201 |
+
$locale = get_locale();
|
202 |
+
$locale = apply_filters( 'plugin_locale', $locale, 'installer' );
|
203 |
+
$mo_file = $this->plugin_path() . '/locale/installer-' . $locale . '.mo';
|
204 |
+
if(file_exists($mo_file)){
|
205 |
+
load_textdomain( 'installer', $mo_file );
|
206 |
+
}
|
207 |
+
}
|
208 |
+
|
209 |
+
public function load_embedded_plugins(){
|
210 |
+
if(file_exists($this->plugin_path() . '/embedded-plugins' )) {
|
211 |
+
include_once $this->plugin_path() . '/embedded-plugins/embedded-plugins.class.php';
|
212 |
+
$this->installer_embedded_plugins = new Installer_Embedded_Plugins();
|
213 |
+
}
|
214 |
+
}
|
215 |
+
|
216 |
+
public function menu_setup(){
|
217 |
+
global $pagenow;
|
218 |
+
|
219 |
+
if(is_multisite() && !is_network_admin()){
|
220 |
+
$this->menu_multisite_redirect();
|
221 |
+
add_options_page(__('Installer', 'installer'), __('Installer', 'installer'), 'manage_options', 'installer', array($this, 'show_products')) ;
|
222 |
+
}else{
|
223 |
+
if($this->config['plugins_install_tab'] && is_admin() && $pagenow == 'plugin-install.php'){
|
224 |
+
// Default GUI, under Plugins -> Install
|
225 |
+
add_filter('install_plugins_tabs', array($this, 'add_install_plugins_tab'));
|
226 |
+
add_action('install_plugins_commercial', array($this, 'show_products'));
|
227 |
+
}
|
228 |
+
}
|
229 |
+
|
230 |
+
}
|
231 |
+
|
232 |
+
public function menu_url(){
|
233 |
+
if(is_multisite()){
|
234 |
+
if(is_network_admin()){
|
235 |
+
$url = network_admin_url('plugin-install.php?tab=commercial');
|
236 |
+
}else{
|
237 |
+
$url = admin_url('options-general.php?page=installer');
|
238 |
+
}
|
239 |
+
}else{
|
240 |
+
$url = admin_url('plugin-install.php?tab=commercial');
|
241 |
+
}
|
242 |
+
return $url;
|
243 |
+
}
|
244 |
+
|
245 |
+
private function menu_multisite_redirect(){
|
246 |
+
global $pagenow;
|
247 |
+
|
248 |
+
if($pagenow == 'plugin-install.php' && isset($_GET['tab']) && $_GET['tab'] == 'commercial'){
|
249 |
+
wp_redirect($this->menu_url());
|
250 |
+
exit;
|
251 |
+
}
|
252 |
+
|
253 |
+
}
|
254 |
+
|
255 |
+
private function _pre_1_0_clean_up(){
|
256 |
+
global $wpdb;
|
257 |
+
|
258 |
+
if(!defined('WPRC_VERSION')){
|
259 |
+
$old_tables = array(
|
260 |
+
$wpdb->prefix . 'wprc_cached_requests',
|
261 |
+
$wpdb->prefix . 'wprc_extension_types',
|
262 |
+
$wpdb->prefix . 'wprc_extensions',
|
263 |
+
$wpdb->prefix . 'wprc_repositories',
|
264 |
+
$wpdb->prefix . 'wprc_repositories_relationships',
|
265 |
+
);
|
266 |
+
|
267 |
+
foreach($old_tables as $table){
|
268 |
+
$wpdb->query(sprintf("DROP TABLE IF EXISTS %s", $table));
|
269 |
+
}
|
270 |
+
|
271 |
+
}
|
272 |
+
|
273 |
+
$this->settings['_pre_1_0_clean_up'] = true;
|
274 |
+
$this->save_settings();
|
275 |
+
}
|
276 |
+
|
277 |
+
public function setup_plugins_action_links(){
|
278 |
+
|
279 |
+
$plugins = get_plugins();
|
280 |
+
|
281 |
+
$repositories_plugins = array();
|
282 |
+
|
283 |
+
if( !empty($this->settings['repositories']) ) {
|
284 |
+
|
285 |
+
foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
|
286 |
+
|
287 |
+
foreach ( $repository['data']['packages'] as $package ) {
|
288 |
+
|
289 |
+
foreach ( $package['products'] as $product ) {
|
290 |
+
|
291 |
+
foreach ( $product['plugins'] as $plugin_slug ) {
|
292 |
+
|
293 |
+
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
294 |
+
|
295 |
+
if ( !isset($repositories_plugins[$repository_id][$download['slug']]) ) {
|
296 |
+
$repositories_plugins[$repository_id][$download['slug']] = array(
|
297 |
+
'name' => $download['name'],
|
298 |
+
'registered' => $this->plugin_is_registered( $repository_id, $download['slug'] ) ? 1 : 0
|
299 |
+
);
|
300 |
+
}
|
301 |
+
|
302 |
+
}
|
303 |
+
|
304 |
+
}
|
305 |
+
|
306 |
+
}
|
307 |
+
|
308 |
+
foreach ( $plugins as $plugin_id => $plugin ) {
|
309 |
+
|
310 |
+
$wp_plugin_slug = dirname( $plugin_id );
|
311 |
+
if ( empty($wp_plugin_slug) ) {
|
312 |
+
$wp_plugin_slug = basename( $plugin_id, '.php' );
|
313 |
+
}
|
314 |
+
|
315 |
+
foreach ( $repositories_plugins as $repository_id => $r_plugins ) {
|
316 |
+
|
317 |
+
foreach ( $r_plugins as $slug => $r_plugin ) {
|
318 |
+
|
319 |
+
if ( $wp_plugin_slug == $slug || $r_plugin['name'] == $plugin['Name'] || $r_plugin['name'] == $plugin['Title'] ) { //match order: slug, name, title
|
320 |
+
|
321 |
+
if ( $r_plugin['registered'] ) {
|
322 |
+
add_filter( 'plugin_action_links_' . $plugin_id, array($this, 'plugins_action_links_registered') );
|
323 |
+
} else {
|
324 |
+
add_filter( 'plugin_action_links_' . $plugin_id, array($this, 'plugins_action_links_not_registered') );
|
325 |
+
}
|
326 |
+
|
327 |
+
}
|
328 |
+
|
329 |
+
}
|
330 |
+
|
331 |
+
}
|
332 |
+
|
333 |
+
|
334 |
+
}
|
335 |
+
|
336 |
+
}
|
337 |
+
}
|
338 |
+
|
339 |
+
}
|
340 |
+
|
341 |
+
public function plugins_action_links_registered($links){
|
342 |
+
$links[] = '<a href="' . $this->menu_url() . '">' . __('Registered', 'installer') . '</a>';
|
343 |
+
return $links;
|
344 |
+
}
|
345 |
+
|
346 |
+
public function plugins_action_links_not_registered($links){
|
347 |
+
$links[] = '<a href="' . $this->menu_url() . '">' . __('Register', 'installer') . '</a>';
|
348 |
+
return $links;
|
349 |
+
}
|
350 |
+
|
351 |
+
public function plugin_is_registered($repository_id, $slug){
|
352 |
+
|
353 |
+
$registered = false;
|
354 |
+
|
355 |
+
if( $this->repository_has_valid_subscription($repository_id) ){
|
356 |
+
|
357 |
+
$subscription_type = $this->get_subscription_type_for_repository($repository_id);
|
358 |
+
$r_plugins = array();
|
359 |
+
|
360 |
+
foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package){
|
361 |
+
|
362 |
+
foreach($package['products'] as $product){
|
363 |
+
|
364 |
+
if( $product['subscription_type'] == $subscription_type || $this->have_superior_subscription($subscription_type, $product) ) {
|
365 |
+
|
366 |
+
foreach ($product['plugins'] as $plugin_slug) {
|
367 |
+
|
368 |
+
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
369 |
+
|
370 |
+
if (!isset($rep_plugins[$download['slug']])) {
|
371 |
+
$r_plugins[$download['slug']] = $download['slug'];
|
372 |
+
}
|
373 |
+
|
374 |
+
}
|
375 |
+
|
376 |
+
}
|
377 |
+
|
378 |
+
}
|
379 |
+
|
380 |
+
}
|
381 |
+
|
382 |
+
$registered = isset($r_plugins[$slug]);
|
383 |
+
|
384 |
+
}
|
385 |
+
|
386 |
+
|
387 |
+
return $registered;
|
388 |
+
|
389 |
+
}
|
390 |
+
|
391 |
+
public function version(){
|
392 |
+
return WP_INSTALLER_VERSION;
|
393 |
+
}
|
394 |
+
|
395 |
+
public function plugin_path() {
|
396 |
+
return untrailingslashit( plugin_dir_path( dirname(__FILE__) ) );
|
397 |
+
}
|
398 |
+
|
399 |
+
public function plugin_url() {
|
400 |
+
if(isset($this->config['in_theme_folder']) && !empty($this->config['in_theme_folder'])){
|
401 |
+
$url = untrailingslashit(get_template_directory_uri() . '/' . $this->config['in_theme_folder']);
|
402 |
+
}else{
|
403 |
+
$url = untrailingslashit( plugins_url( '/', dirname(__FILE__) ) );
|
404 |
+
}
|
405 |
+
|
406 |
+
return $url;
|
407 |
+
}
|
408 |
+
|
409 |
+
public function is_repositories_page(){
|
410 |
+
global $pagenow;
|
411 |
+
|
412 |
+
return $pagenow == 'plugin-install.php' && isset($_GET['tab']) && $_GET['tab'] == 'commercial';
|
413 |
+
}
|
414 |
+
|
415 |
+
public function res_url(){
|
416 |
+
if(isset($this->config['in_theme_folder']) && !empty($this->config['in_theme_folder'])){
|
417 |
+
$url = untrailingslashit(get_template_directory_uri() . '/' . $this->config['in_theme_folder']);
|
418 |
+
}else{
|
419 |
+
$url = $this->plugin_url();
|
420 |
+
}
|
421 |
+
return $url;
|
422 |
+
}
|
423 |
+
|
424 |
+
public function save_settings(){
|
425 |
+
|
426 |
+
$_settings = serialize($this->settings);
|
427 |
+
if($this->_gz_on){
|
428 |
+
$_settings = gzcompress($_settings);
|
429 |
+
}
|
430 |
+
$_settings = base64_encode($_settings);
|
431 |
+
|
432 |
+
update_option( 'wp_installer_settings', $_settings );
|
433 |
+
|
434 |
+
if( is_multisite() && is_main_site() && isset($this->settings['repositories']) ){
|
435 |
+
$network_settings = array();
|
436 |
+
|
437 |
+
foreach( $this->settings['repositories'] as $rep_id => $repository ){
|
438 |
+
if( isset($repository['subscription']) )
|
439 |
+
$network_settings[$rep_id] = $repository['subscription'];
|
440 |
+
}
|
441 |
+
|
442 |
+
update_site_option( 'wp_installer_network', $network_settings );
|
443 |
+
|
444 |
+
|
445 |
+
}
|
446 |
+
|
447 |
+
}
|
448 |
+
|
449 |
+
public function get_settings($refresh = false){
|
450 |
+
|
451 |
+
if($refresh || empty($this->settings)){
|
452 |
+
|
453 |
+
$_settings = get_option('wp_installer_settings');
|
454 |
+
|
455 |
+
|
456 |
+
if (is_array($_settings) || empty($_settings)) { //backward compatibility 1.1
|
457 |
+
$this->settings = $_settings;
|
458 |
+
|
459 |
+
} else {
|
460 |
+
$_settings = base64_decode($_settings);
|
461 |
+
if ($this->_gz_on) {
|
462 |
+
$_settings = gzuncompress($_settings);
|
463 |
+
}
|
464 |
+
$this->settings = unserialize($_settings);
|
465 |
+
}
|
466 |
+
|
467 |
+
if (is_multisite() && isset($this->settings['repositories'])) {
|
468 |
+
$network_settings = maybe_unserialize(get_site_option('wp_installer_network'));
|
469 |
+
if ($network_settings) {
|
470 |
+
foreach ($this->settings['repositories'] as $rep_id => $repository) {
|
471 |
+
if (isset($network_settings[$rep_id])) {
|
472 |
+
$this->settings['repositories'][$rep_id]['subscription'] = $network_settings[$rep_id];
|
473 |
+
}
|
474 |
+
}
|
475 |
+
}
|
476 |
+
}
|
477 |
+
|
478 |
+
$this->load_hardcoded_site_keys();
|
479 |
+
|
480 |
+
$this->settings = $this->_pre_1_6_backwards_compatibility($this->settings);
|
481 |
+
|
482 |
+
$this->settings = $this->_old_products_format_backwards_compatibility($this->settings);
|
483 |
+
|
484 |
+
}
|
485 |
+
|
486 |
+
return $this->settings;
|
487 |
+
}
|
488 |
+
|
489 |
+
private function load_hardcoded_site_keys(){
|
490 |
+
|
491 |
+
if( !empty( $this->settings['repositories'] ) ) {
|
492 |
+
foreach ( $this->settings['repositories'] as $repository_id => $repository ) {
|
493 |
+
|
494 |
+
if ( $site_key = self::get_repository_hardcoded_site_key( $repository_id ) ) {
|
495 |
+
|
496 |
+
$site_key_missing = empty($this->settings['repositories'][$repository_id]['subscription']['data']);
|
497 |
+
$site_key_changed = !$site_key_missing &&
|
498 |
+
$this->settings['repositories'][$repository_id]['subscription']['key'] != $site_key;
|
499 |
+
|
500 |
+
if ( $site_key_missing || $site_key_changed ) {
|
501 |
+
|
502 |
+
if ( !function_exists( 'get_plugins' ) ) {
|
503 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
504 |
+
}
|
505 |
+
$this->load_repositories_list();
|
506 |
+
$response = $this->save_site_key(
|
507 |
+
array(
|
508 |
+
'repository_id' => $repository_id,
|
509 |
+
'site_key' => $site_key,
|
510 |
+
'return' => true,
|
511 |
+
'nonce' => wp_create_nonce( 'save_site_key_' . $repository_id )
|
512 |
+
)
|
513 |
+
);
|
514 |
+
|
515 |
+
if ( !empty($response['error']) ) {
|
516 |
+
$this->remove_site_key( $repository_id );
|
517 |
+
|
518 |
+
$this->admin_messages[] = array(
|
519 |
+
'type' => 'error',
|
520 |
+
'text' => sprintf( __( 'You are using an invalid site key defined as the constant %s (most likely in wp-config.php).
|
521 |
+
Please remove it or use the correct value in order to be able to register correctly.', 'installer' ), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper( $repository_id ) )
|
522 |
+
);
|
523 |
+
|
524 |
+
}
|
525 |
+
|
526 |
+
}
|
527 |
+
|
528 |
+
}
|
529 |
+
|
530 |
+
}
|
531 |
+
}
|
532 |
+
|
533 |
+
}
|
534 |
+
|
535 |
+
public static function get_repository_hardcoded_site_key( $repository_id ){
|
536 |
+
|
537 |
+
$site_key = false;
|
538 |
+
|
539 |
+
$site_key_constant = 'OTGS_INSTALLER_SITE_KEY_' . strtoupper( $repository_id );
|
540 |
+
if( defined( $site_key_constant ) ){
|
541 |
+
$site_key = constant( $site_key_constant );
|
542 |
+
}
|
543 |
+
|
544 |
+
return $site_key;
|
545 |
+
}
|
546 |
+
|
547 |
+
//backward compatibility, will remove 'basename' in version 1.8
|
548 |
+
private function _pre_1_6_backwards_compatibility($settings){
|
549 |
+
|
550 |
+
if( version_compare($this->version(), '1.8', '<') && !empty($settings['repositories']) ){
|
551 |
+
|
552 |
+
foreach ($settings['repositories'] as $repository_id => $repository) {
|
553 |
+
|
554 |
+
foreach ($repository['data']['downloads']['plugins'] as $slug => $download) {
|
555 |
+
|
556 |
+
$settings['repositories'][$repository_id]['data']['downloads']['plugins'][$slug]['slug'] = $download['basename'];
|
557 |
+
|
558 |
+
}
|
559 |
+
}
|
560 |
+
|
561 |
+
}
|
562 |
+
|
563 |
+
return $settings;
|
564 |
+
|
565 |
+
}
|
566 |
+
|
567 |
+
//backward compatibility - support old products list format (downloads under products instead of global downloads list)
|
568 |
+
private function _old_products_format_backwards_compatibility($settings){
|
569 |
+
|
570 |
+
if( version_compare($this->version(), '1.8', '<') && !empty($settings['repositories']) && empty($this->_old_products_format_backwards_compatibility) ) {
|
571 |
+
|
572 |
+
foreach ($settings['repositories'] as $repository_id => $repository) {
|
573 |
+
|
574 |
+
$populate_downloads = false;
|
575 |
+
|
576 |
+
foreach ($repository['data']['packages'] as $package_id => $package) {
|
577 |
+
|
578 |
+
foreach ($package['products'] as $product_id => $product) {
|
579 |
+
|
580 |
+
if (!isset($product['plugins'])) {
|
581 |
+
|
582 |
+
$populate_downloads = true;
|
583 |
+
|
584 |
+
foreach ($product['downloads'] as $download_id => $download) {
|
585 |
+
|
586 |
+
$settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['plugins'][] = $download['slug'];
|
587 |
+
|
588 |
+
}
|
589 |
+
|
590 |
+
}
|
591 |
+
|
592 |
+
}
|
593 |
+
|
594 |
+
}
|
595 |
+
|
596 |
+
if ($populate_downloads) {
|
597 |
+
|
598 |
+
// Add downloads branch
|
599 |
+
foreach ($repository['data']['packages'] as $package_id => $package) {
|
600 |
+
|
601 |
+
foreach ($package['products'] as $product_id => $product) {
|
602 |
+
|
603 |
+
foreach ($product['downloads'] as $download_id => $download) {
|
604 |
+
|
605 |
+
if (!isset($settings['repositories'][$repository_id]['data']['downloads']['plugins'][$download['slug']])) {
|
606 |
+
$settings['repositories'][$repository_id]['data']['downloads']['plugins'][$download['slug']] = $download;
|
607 |
+
}
|
608 |
+
|
609 |
+
$settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['plugins'][] = $download['slug'];
|
610 |
+
}
|
611 |
+
|
612 |
+
unset($settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['downloads']);
|
613 |
+
|
614 |
+
}
|
615 |
+
|
616 |
+
}
|
617 |
+
|
618 |
+
}
|
619 |
+
|
620 |
+
}
|
621 |
+
|
622 |
+
$this->_old_products_format_backwards_compatibility = true;
|
623 |
+
|
624 |
+
}
|
625 |
+
|
626 |
+
return $settings;
|
627 |
+
|
628 |
+
}
|
629 |
+
|
630 |
+
public function get_installer_site_url( $repository_id = false ){
|
631 |
+
global $current_site;
|
632 |
+
|
633 |
+
$site_url = get_site_url();
|
634 |
+
|
635 |
+
if( $repository_id && is_multisite() && isset( $this->settings['repositories'] ) ){
|
636 |
+
$network_settings = maybe_unserialize( get_site_option('wp_installer_network') );
|
637 |
+
|
638 |
+
if ( isset( $network_settings[$repository_id] ) ) {
|
639 |
+
$site_url = get_site_url( $current_site->blog_id );
|
640 |
+
}
|
641 |
+
|
642 |
+
}
|
643 |
+
|
644 |
+
return $site_url;
|
645 |
+
}
|
646 |
+
|
647 |
+
public function show_site_key_nags(){
|
648 |
+
$screen = get_current_screen();
|
649 |
+
|
650 |
+
if($screen->base == 'settings_page_installer' || ($screen->base == 'plugin-install' && isset($_GET['tab']) && $_GET['tab'] == 'commercial')){
|
651 |
+
return;
|
652 |
+
}
|
653 |
+
|
654 |
+
if(!empty($this->config['site_key_nags'])){
|
655 |
+
|
656 |
+
foreach($this->config['site_key_nags'] as $nag){
|
657 |
+
|
658 |
+
if(!$this->repository_has_subscription($nag['repository_id'] )){
|
659 |
+
$show = true;
|
660 |
+
if(!empty($nag['condition_cb'])){
|
661 |
+
$show = call_user_func($nag['condition_cb']);
|
662 |
+
}
|
663 |
+
|
664 |
+
if(empty($this->settings['dismissed_nags'][$nag['repository_id']]) && $show){
|
665 |
+
echo '<div class="updated error otgs-is-dismissible"><p>';
|
666 |
+
printf(__("To get automatic updates, you need to register %s for this site. %sRegister %s%s", 'sitepress'),
|
667 |
+
$nag['product_name'], '<a class="button-primary" href="' . $this->menu_url() . '">', $nag['product_name'], '</a>');
|
668 |
+
|
669 |
+
echo '</p>';
|
670 |
+
echo '<span class="installer-dismiss-nag notice-dismiss" data-repository="' . $nag['repository_id'] . '"><span class="screen-reader-text">' . __('Dismiss', 'sitepress') . '</span></span>';
|
671 |
+
echo '</div>';
|
672 |
+
}
|
673 |
+
}
|
674 |
+
|
675 |
+
}
|
676 |
+
|
677 |
+
}
|
678 |
+
|
679 |
+
}
|
680 |
+
|
681 |
+
public function dismiss_nag(){
|
682 |
+
$this->settings['dismissed_nags'][$_POST['repository']] = 1;
|
683 |
+
|
684 |
+
$this->save_settings();
|
685 |
+
|
686 |
+
echo json_encode(array());
|
687 |
+
exit;
|
688 |
+
}
|
689 |
+
|
690 |
+
public function add_install_plugins_tab($tabs){
|
691 |
+
|
692 |
+
$tabs['commercial'] = __('Commercial', 'installer');
|
693 |
+
|
694 |
+
return $tabs;
|
695 |
+
}
|
696 |
+
|
697 |
+
public function load_repositories_list(){
|
698 |
+
global $wp_installer_instances;
|
699 |
+
|
700 |
+
foreach ($wp_installer_instances as $instance) {
|
701 |
+
|
702 |
+
if (file_exists(dirname($instance['bootfile']) . '/repositories.xml')) {
|
703 |
+
$config_file = dirname($instance['bootfile']) . '/repositories.xml';
|
704 |
+
|
705 |
+
if (file_exists(dirname($instance['bootfile']) . '/repositories.sandbox.xml')) {
|
706 |
+
$config_file = dirname($instance['bootfile']) . '/repositories.sandbox.xml';
|
707 |
+
add_filter('https_ssl_verify', '__return_false');
|
708 |
+
}
|
709 |
+
|
710 |
+
$repos = simplexml_load_file($config_file);
|
711 |
+
|
712 |
+
if($repos) {
|
713 |
+
foreach ($repos as $repo) {
|
714 |
+
$id = strval($repo->id);
|
715 |
+
|
716 |
+
$data['api-url'] = strval($repo->apiurl);
|
717 |
+
$data['products'] = strval($repo->products);
|
718 |
+
|
719 |
+
// excludes rule;
|
720 |
+
if (isset($this->config['repositories_exclude']) && in_array($id, $this->config['repositories_exclude'])) {
|
721 |
+
continue;
|
722 |
+
}
|
723 |
+
|
724 |
+
// includes rule;
|
725 |
+
if (isset($this->config['repositories_include']) && !in_array($id, $this->config['repositories_include'])) {
|
726 |
+
continue;
|
727 |
+
}
|
728 |
+
|
729 |
+
$this->repositories[$id] = $data;
|
730 |
+
|
731 |
+
}
|
732 |
+
}
|
733 |
+
|
734 |
+
}
|
735 |
+
}
|
736 |
+
|
737 |
+
}
|
738 |
+
|
739 |
+
public function filter_repositories_list(){
|
740 |
+
|
741 |
+
if(!empty($this->settings['repositories'])) {
|
742 |
+
foreach ($this->settings['repositories'] as $id => $repo_data) {
|
743 |
+
|
744 |
+
// excludes rule;
|
745 |
+
if (isset($this->config['repositories_exclude']) && in_array($id, $this->config['repositories_exclude'])) {
|
746 |
+
unset($this->settings['repositories'][$id]);
|
747 |
+
}
|
748 |
+
|
749 |
+
// includes rule;
|
750 |
+
if (isset($this->config['repositories_include']) && !in_array($id, $this->config['repositories_include'])) {
|
751 |
+
unset($this->settings['repositories'][$id]);
|
752 |
+
}
|
753 |
+
|
754 |
+
|
755 |
+
}
|
756 |
+
}
|
757 |
+
|
758 |
+
|
759 |
+
}
|
760 |
+
|
761 |
+
public function refresh_repositories_data(){
|
762 |
+
static $checked = false;
|
763 |
+
|
764 |
+
if( defined('OTGS_DISABLE_AUTO_UPDATES') && OTGS_DISABLE_AUTO_UPDATES && empty($_GET['force-check']) || $checked ){
|
765 |
+
|
766 |
+
if(empty($this->settings['repositories']) && $this->is_repositories_page()){
|
767 |
+
|
768 |
+
foreach($this->repositories as $id => $data) {
|
769 |
+
$repository_names[] = $id;
|
770 |
+
|
771 |
+
}
|
772 |
+
|
773 |
+
$error = sprintf(__("Installer cannot display the products information because the automatic updating for %s was explicitly disabled with the configuration below (usually in wp-config.php):", 'installer'), strtoupper( join(', ', $repository_names) ));
|
774 |
+
$error .= '<br /><br /><code>define("OTGS_DISABLE_AUTO_UPDATES", true);</code><br /><br />';
|
775 |
+
$error .= sprintf(__("In order to see the products information, please run the %smanual updates check%s to initialize the products list or (temporarily) remove the above code.", 'installer'), '<a href="' . admin_url('update-core.php') . '">', '</a>');
|
776 |
+
|
777 |
+
$this->register_admin_message($error, 'error');
|
778 |
+
|
779 |
+
|
780 |
+
}
|
781 |
+
|
782 |
+
return;
|
783 |
+
}
|
784 |
+
|
785 |
+
$checked = true;
|
786 |
+
|
787 |
+
foreach($this->repositories as $id => $data){
|
788 |
+
|
789 |
+
$response = wp_remote_get($data['products']);
|
790 |
+
|
791 |
+
if(is_wp_error($response)){
|
792 |
+
// http fallback
|
793 |
+
$data['products'] = preg_replace("@^https://@", 'http://', $data['products']);
|
794 |
+
$response = wp_remote_get($data['products']);
|
795 |
+
}
|
796 |
+
|
797 |
+
if(is_wp_error($response)){
|
798 |
+
|
799 |
+
$error = sprintf(__("Installer cannot contact our updates server to get information about the available products and check for new versions. If you are seeing this message for the first time, you can ignore it, as it may be a temporary communication problem. If the problem persists and your WordPress admin is slowing down, you can disable automated version checks. Add the following line to your wp-config.php file:", 'installer'), strtoupper($id));
|
800 |
+
$error .= '<br /><br /><code>define("OTGS_DISABLE_AUTO_UPDATES", true);</code>';
|
801 |
+
|
802 |
+
$this->register_admin_message($error, 'error');
|
803 |
+
|
804 |
+
continue;
|
805 |
+
}
|
806 |
+
|
807 |
+
if($response && isset($response['response']['code']) && $response['response']['code'] == 200){
|
808 |
+
$body = wp_remote_retrieve_body($response);
|
809 |
+
if($body){
|
810 |
+
$products = json_decode($body, true);
|
811 |
+
|
812 |
+
if(is_array($products)){
|
813 |
+
$this->settings['repositories'][$id]['data'] = $products;
|
814 |
+
$this->settings = $this->_pre_1_6_backwards_compatibility($this->settings);
|
815 |
+
}
|
816 |
+
}
|
817 |
+
|
818 |
+
}
|
819 |
+
|
820 |
+
$this->log( sprintf("Checked for %s updates: %s", $id, $data['products']) );
|
821 |
+
|
822 |
+
|
823 |
+
}
|
824 |
+
|
825 |
+
// cleanup
|
826 |
+
if(empty($this->settings['repositories'])){
|
827 |
+
$this->settings['repositories'] = array();
|
828 |
+
}
|
829 |
+
foreach($this->settings['repositories'] as $id => $data){
|
830 |
+
if(!in_array($id, array_keys($this->repositories))){
|
831 |
+
unset($this->settings['repositories'][$id]);
|
832 |
+
}
|
833 |
+
}
|
834 |
+
|
835 |
+
$this->settings['last_repositories_update']= time();
|
836 |
+
|
837 |
+
$this->save_settings();
|
838 |
+
|
839 |
+
}
|
840 |
+
|
841 |
+
public function show_products($args = array()){
|
842 |
+
|
843 |
+
$screen = get_current_screen();
|
844 |
+
|
845 |
+
if($screen->base == 'settings_page_installer'){ // settings page
|
846 |
+
echo '<div class="wrap">';
|
847 |
+
echo '<h2>' . __('Installer', 'installer') . '</h2>';
|
848 |
+
echo '<br />';
|
849 |
+
}
|
850 |
+
|
851 |
+
if(!is_array($args)) $args = array();
|
852 |
+
if(empty($args['template'])) $args['template'] = 'default';
|
853 |
+
|
854 |
+
$this->filter_repositories_list();
|
855 |
+
|
856 |
+
if(!empty($this->settings['repositories'])){
|
857 |
+
|
858 |
+
$this->localize_strings();
|
859 |
+
$this->set_filtered_prices($args);
|
860 |
+
$this->set_hierarchy_and_order();
|
861 |
+
|
862 |
+
foreach($this->settings['repositories'] as $repository_id => $repository){
|
863 |
+
|
864 |
+
if($args['template'] == 'compact'){
|
865 |
+
|
866 |
+
if(isset($args['repository']) && $args['repository'] == $repository_id){
|
867 |
+
include $this->plugin_path() . '/templates/products-compact.php';
|
868 |
+
}
|
869 |
+
|
870 |
+
}else{
|
871 |
+
|
872 |
+
include $this->plugin_path() . '/templates/repository-listing.php';
|
873 |
+
|
874 |
+
}
|
875 |
+
|
876 |
+
unset($site_key, $subscription_type, $expired, $upgrade_options, $products_avaliable);
|
877 |
+
|
878 |
+
}
|
879 |
+
|
880 |
+
}else{
|
881 |
+
|
882 |
+
echo '<center>' . __('No repositories defined.', 'installer') . '</center>';
|
883 |
+
|
884 |
+
}
|
885 |
+
|
886 |
+
if($screen->base == 'settings_page_installer'){ // settings page
|
887 |
+
echo '</div>';
|
888 |
+
}
|
889 |
+
|
890 |
+
|
891 |
+
}
|
892 |
+
|
893 |
+
public function get_product_price($repository_id, $package_id, $product_id, $incl_discount = false){
|
894 |
+
|
895 |
+
$price = false;
|
896 |
+
|
897 |
+
foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package ){
|
898 |
+
|
899 |
+
if($package['id'] == $package_id){
|
900 |
+
if(isset($package['products'][$product_id])){
|
901 |
+
if($incl_discount && isset($package['products'][$product_id]['price_disc'])){
|
902 |
+
$price = $package['products'][$product_id]['price_disc'];
|
903 |
+
}elseif(isset($package['products'][$product_id]['price'])){
|
904 |
+
$price = $package['products'][$product_id]['price'];
|
905 |
+
}
|
906 |
+
}
|
907 |
+
break;
|
908 |
+
}
|
909 |
+
}
|
910 |
+
|
911 |
+
return $price;
|
912 |
+
}
|
913 |
+
|
914 |
+
private function _render_product_packages($packages, $subscription_type, $expired, $upgrade_options, $repository_id){
|
915 |
+
|
916 |
+
$data = array();
|
917 |
+
|
918 |
+
foreach($packages as $package_id => $package){
|
919 |
+
|
920 |
+
$row = array('products' => array(), 'downloads' => array());
|
921 |
+
foreach($package['products'] as $product){
|
922 |
+
|
923 |
+
// filter out free subscriptions from being displayed as buying options
|
924 |
+
if( empty($product['price']) && (empty($subscription_type) || $expired) ){
|
925 |
+
continue;
|
926 |
+
}
|
927 |
+
|
928 |
+
// buy base
|
929 |
+
if(empty($subscription_type) || $expired) {
|
930 |
+
|
931 |
+
$p['url'] = $this->append_parameters_to_buy_url($product['url'], $repository_id);
|
932 |
+
if (!empty($product['price_disc'])) {
|
933 |
+
$p['label'] = $product['call2action'] . ' - ' . sprintf('$%s %s$%d%s (USD)', $product['price_disc'], ' <del>', $product['price'], '</del>');
|
934 |
+
} else {
|
935 |
+
$p['label'] = $product['call2action'] . ' - ' . sprintf('$%d (USD)', $product['price']);
|
936 |
+
}
|
937 |
+
$row['products'][] = $p;
|
938 |
+
|
939 |
+
// renew
|
940 |
+
} elseif(isset($subscription_type) && $product['subscription_type'] == $subscription_type){
|
941 |
+
|
942 |
+
if($product['renewals']) {
|
943 |
+
foreach ($product['renewals'] as $renewal) {
|
944 |
+
$p['url'] = $this->append_parameters_to_buy_url($renewal['url'], $repository_id);
|
945 |
+
$p['label'] = $renewal['call2action'] . ' - ' . sprintf('$%d (USD)', $renewal['price']);
|
946 |
+
}
|
947 |
+
|
948 |
+
$row['products'][] = $p;
|
949 |
+
}
|
950 |
+
|
951 |
+
}
|
952 |
+
|
953 |
+
// upgrades
|
954 |
+
if(!empty($upgrade_options[$product['subscription_type']])){
|
955 |
+
|
956 |
+
foreach($upgrade_options[$product['subscription_type']] as $stype => $upgrade){
|
957 |
+
if($stype != $subscription_type) continue;
|
958 |
+
|
959 |
+
$p['url'] = $this->append_parameters_to_buy_url($upgrade['url'], $repository_id);
|
960 |
+
if (!empty($upgrade['price_disc'])) {
|
961 |
+
$p['label'] = $upgrade['call2action'] . ' - ' . sprintf('$%s %s$%d%s (USD)', $upgrade['price_disc'], ' <del>', $upgrade['price'], '</del>');
|
962 |
+
} else {
|
963 |
+
$p['label'] = $upgrade['call2action'] . ' - ' . sprintf('$%d (USD)', $upgrade['price']);
|
964 |
+
}
|
965 |
+
$row['products'][] = $p;
|
966 |
+
|
967 |
+
}
|
968 |
+
|
969 |
+
}
|
970 |
+
|
971 |
+
// downloads
|
972 |
+
if(isset($subscription_type) && !$expired && $product['subscription_type'] == $subscription_type){
|
973 |
+
foreach($product['plugins'] as $plugin_slug){
|
974 |
+
|
975 |
+
$row['downloads'][] = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
976 |
+
|
977 |
+
}
|
978 |
+
|
979 |
+
}
|
980 |
+
|
981 |
+
//subpackages
|
982 |
+
if(!empty($package['sub-packages'])){
|
983 |
+
$row['sub-packages'] = $package['sub-packages'];
|
984 |
+
}
|
985 |
+
|
986 |
+
}
|
987 |
+
|
988 |
+
$row['id'] = $package['id'];
|
989 |
+
$row['image_url'] = $package['image_url'];
|
990 |
+
$row['name'] = $package['name'];
|
991 |
+
$row['description'] = $package['description'];
|
992 |
+
|
993 |
+
if(!empty($row['products']) || !empty($row['downloads']) || !empty($row['sub-packages'])){
|
994 |
+
$data[] = $row;
|
995 |
+
}
|
996 |
+
|
997 |
+
|
998 |
+
}
|
999 |
+
|
1000 |
+
return $data;
|
1001 |
+
|
1002 |
+
}
|
1003 |
+
|
1004 |
+
public function get_extra_url_parameters(){
|
1005 |
+
|
1006 |
+
$parameters = array();
|
1007 |
+
|
1008 |
+
if(!empty($this->package_source)){
|
1009 |
+
foreach($this->package_source as $key => $val){
|
1010 |
+
$parameters[$key] = $val;
|
1011 |
+
}
|
1012 |
+
}
|
1013 |
+
|
1014 |
+
$parameters['installer_version'] = WP_INSTALLER_VERSION;
|
1015 |
+
$parameters['theme'] = wp_get_theme()->get( 'Name' );
|
1016 |
+
$parameters['site_name'] = get_bloginfo( 'name' );
|
1017 |
+
|
1018 |
+
return $parameters;
|
1019 |
+
}
|
1020 |
+
|
1021 |
+
public function append_parameters_to_buy_url($url, $repository_id, $args = array()){
|
1022 |
+
|
1023 |
+
$url = add_query_arg( array('icl_site_url' => $this->get_installer_site_url( $repository_id ) ), $url );
|
1024 |
+
|
1025 |
+
$affiliate_id = false;
|
1026 |
+
$affiliate_key = false;
|
1027 |
+
|
1028 |
+
// Add extra parameters for custom Installer packages
|
1029 |
+
if( !empty($this->package_source) ){
|
1030 |
+
$extra = $this->get_extra_url_parameters();
|
1031 |
+
|
1032 |
+
if( !empty($extra['repository']) && $extra['repository'] == $repository_id ) {
|
1033 |
+
|
1034 |
+
if( !empty($extra['affiliate_key']) && !empty($extra['user_id']) ){
|
1035 |
+
$this->config['affiliate_id:' . $repository_id] = $extra['user_id'];
|
1036 |
+
$this->config['affiliate_key:' . $repository_id] = $extra['affiliate_key'];
|
1037 |
+
unset($extra['affiliate_key'], $extra['user_id'], $extra['repository']); // no need to include these ones
|
1038 |
+
}
|
1039 |
+
|
1040 |
+
$url = add_query_arg($extra, $url);
|
1041 |
+
}
|
1042 |
+
|
1043 |
+
}
|
1044 |
+
|
1045 |
+
if(isset($this->config['affiliate_id:' . $repository_id]) && isset($this->config['affiliate_key:' . $repository_id])){
|
1046 |
+
|
1047 |
+
$affiliate_id = $this->config['affiliate_id:' . $repository_id];
|
1048 |
+
$affiliate_key = $this->config['affiliate_key:' . $repository_id];
|
1049 |
+
|
1050 |
+
}elseif(isset($args['affiliate_id:' . $repository_id]) && isset($args['affiliate_key:' . $repository_id])){
|
1051 |
+
|
1052 |
+
$affiliate_id = $args['affiliate_id:' . $repository_id];
|
1053 |
+
$affiliate_key = $args['affiliate_key:' . $repository_id];
|
1054 |
+
|
1055 |
+
}elseif(defined('ICL_AFFILIATE_ID') && defined('ICL_AFFILIATE_KEY')){ //support for 1 repo
|
1056 |
+
|
1057 |
+
$affiliate_id = ICL_AFFILIATE_ID;
|
1058 |
+
$affiliate_key = ICL_AFFILIATE_KEY;
|
1059 |
+
|
1060 |
+
}elseif(isset($this->config['affiliate_id']) && isset($this->config['affiliate_key'])) {
|
1061 |
+
// BACKWARDS COMPATIBILITY
|
1062 |
+
$affiliate_id = $this->config['affiliate_id'];
|
1063 |
+
$affiliate_key = $this->config['affiliate_key'];
|
1064 |
+
}
|
1065 |
+
|
1066 |
+
if($affiliate_id && $affiliate_key){
|
1067 |
+
$url = add_query_arg(array('aid' => $affiliate_id, 'affiliate_key' => $affiliate_key), $url);
|
1068 |
+
}
|
1069 |
+
|
1070 |
+
if($repository_id == 'wpml'){
|
1071 |
+
$url = add_query_arg(array('using_icl' => $this->_using_icl, 'wpml_version' => $this->_wpml_version), $url);
|
1072 |
+
}
|
1073 |
+
|
1074 |
+
$url = apply_filters('wp_installer_buy_url', $url);
|
1075 |
+
|
1076 |
+
$url = esc_url($url);
|
1077 |
+
|
1078 |
+
return $url;
|
1079 |
+
|
1080 |
+
}
|
1081 |
+
|
1082 |
+
public function save_site_key($args = array()){
|
1083 |
+
|
1084 |
+
$error = '';
|
1085 |
+
|
1086 |
+
if( isset( $args['repository_id'] ) ){
|
1087 |
+
$repository_id = $args['repository_id'];
|
1088 |
+
}elseif( isset( $_POST['repository_id'] ) ){
|
1089 |
+
$repository_id = sanitize_text_field( $_POST['repository_id'] );
|
1090 |
+
}else{
|
1091 |
+
$repository_id = false;
|
1092 |
+
}
|
1093 |
+
|
1094 |
+
if( isset( $args['nonce'] ) ){
|
1095 |
+
$nonce = $args['nonce'];
|
1096 |
+
}elseif( isset($_POST['nonce'] ) ){
|
1097 |
+
$nonce = sanitize_text_field( $_POST['nonce'] );
|
1098 |
+
}else{
|
1099 |
+
$nonce = '';
|
1100 |
+
}
|
1101 |
+
|
1102 |
+
if( isset( $args['site_key'] ) ){
|
1103 |
+
$site_key = $args['site_key'];
|
1104 |
+
} else {
|
1105 |
+
$site_key = sanitize_text_field( $_POST[ 'site_key_' . $repository_id] );
|
1106 |
+
}
|
1107 |
+
$site_key = preg_replace("/[^A-Za-z0-9]/", '', $site_key);
|
1108 |
+
|
1109 |
+
if($repository_id && $nonce && wp_create_nonce('save_site_key_' . $repository_id) == $nonce){
|
1110 |
+
|
1111 |
+
try {
|
1112 |
+
$subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REGISTRATION );
|
1113 |
+
|
1114 |
+
if ( $subscription_data ) {
|
1115 |
+
$this->settings['repositories'][$repository_id]['subscription'] = array('key' => $site_key, 'data' => $subscription_data);
|
1116 |
+
$this->save_settings();
|
1117 |
+
} else {
|
1118 |
+
$error = __( 'Invalid site key for the current site.', 'installer' )
|
1119 |
+
. '<br /><div class="installer-footnote">' . __('Please note that the site key is case sensitive.', 'installer') . '</div>';
|
1120 |
+
}
|
1121 |
+
|
1122 |
+
} catch (Exception $e ){
|
1123 |
+
$error = $e->getMessage();
|
1124 |
+
if( preg_match('#Could not resolve host: (.*)#', $error, $matches) || preg_match('#Couldn\'t resolve host \'(.*)\'#', $error, $matches) ){
|
1125 |
+
$error = sprintf(__("%s cannot access %s to register. Try again to see if it's a temporary problem. If the problem continues, make sure that this site has access to the Internet. You can still use the plugin without registration, but you will not receive automated updates.", 'installer'),
|
1126 |
+
'<strong><i>' . $this->get_generic_product_name($repository_id) . '</i></strong>',
|
1127 |
+
'<strong><i>' . $matches[1]. '</i></strong>'
|
1128 |
+
) ;
|
1129 |
+
}
|
1130 |
+
}
|
1131 |
+
|
1132 |
+
}
|
1133 |
+
|
1134 |
+
$return = array('error' => $error);
|
1135 |
+
|
1136 |
+
if($this->api_debug){
|
1137 |
+
$return['debug'] = $this->api_debug;
|
1138 |
+
}
|
1139 |
+
|
1140 |
+
if(!empty($args['return'])){
|
1141 |
+
return $return;
|
1142 |
+
}else{
|
1143 |
+
echo json_encode($return);
|
1144 |
+
exit;
|
1145 |
+
}
|
1146 |
+
|
1147 |
+
}
|
1148 |
+
|
1149 |
+
/**
|
1150 |
+
* Alias for WP_Installer::get_repository_site_key
|
1151 |
+
* @see WP_Installer::get_repository_site_key()
|
1152 |
+
*
|
1153 |
+
* @param string $repository_id
|
1154 |
+
* @return string (site key) or bool
|
1155 |
+
*/
|
1156 |
+
public function get_site_key($repository_id){
|
1157 |
+
return WP_Installer::get_repository_site_key( $repository_id );
|
1158 |
+
}
|
1159 |
+
|
1160 |
+
public function remove_site_key( $repository_id ){
|
1161 |
+
if( isset( $this->settings['repositories'][$repository_id] ) ){
|
1162 |
+
unset($this->settings['repositories'][$repository_id]['subscription']);
|
1163 |
+
$this->save_settings();
|
1164 |
+
$this->refresh_repositories_data();
|
1165 |
+
}
|
1166 |
+
}
|
1167 |
+
|
1168 |
+
public function remove_site_key_ajax(){
|
1169 |
+
if($_POST['nonce'] == wp_create_nonce('remove_site_key_' . $_POST['repository_id'])){
|
1170 |
+
$this->remove_site_key( $_POST['repository_id'] );
|
1171 |
+
}
|
1172 |
+
exit;
|
1173 |
+
}
|
1174 |
+
|
1175 |
+
public function validate_repository_subscription(){
|
1176 |
+
$repository_id = isset($_GET['validate_repository']) ? sanitize_text_field( $_GET['validate_repository'] ) : false;
|
1177 |
+
if($repository_id){
|
1178 |
+
|
1179 |
+
$site_key = $this->get_site_key($repository_id);
|
1180 |
+
if($site_key) {
|
1181 |
+
$subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION);
|
1182 |
+
if(empty($subscription_data)){
|
1183 |
+
unset($this->settings['repositories'][$repository_id]['subscription']);
|
1184 |
+
delete_site_transient('update_plugins');
|
1185 |
+
$this->save_settings();
|
1186 |
+
}
|
1187 |
+
}
|
1188 |
+
|
1189 |
+
wp_redirect($this->menu_url() . '#repository-' . $repository_id);
|
1190 |
+
exit;
|
1191 |
+
|
1192 |
+
}
|
1193 |
+
|
1194 |
+
}
|
1195 |
+
|
1196 |
+
public function update_site_key(){
|
1197 |
+
|
1198 |
+
$error = '';
|
1199 |
+
|
1200 |
+
$repository_id = sanitize_text_field ( $_POST['repository_id'] );
|
1201 |
+
if($_POST['nonce'] == wp_create_nonce('update_site_key_' . $repository_id )){
|
1202 |
+
|
1203 |
+
$site_key = $this->get_site_key($_POST['repository_id']);
|
1204 |
+
|
1205 |
+
if($site_key){
|
1206 |
+
try {
|
1207 |
+
$subscription_data = $this->fetch_subscription_data( $repository_id, $site_key, self::SITE_KEY_VALIDATION_SOURCE_UPDATES_CHECK );
|
1208 |
+
|
1209 |
+
if ( $subscription_data ) {
|
1210 |
+
$this->settings['repositories'][$repository_id]['subscription'] = array('key' => $site_key, 'data' => $subscription_data);
|
1211 |
+
|
1212 |
+
//also refresh products information
|
1213 |
+
$this->refresh_repositories_data();
|
1214 |
+
|
1215 |
+
$this->save_settings();
|
1216 |
+
|
1217 |
+
} else {
|
1218 |
+
unset($this->settings['repositories'][$repository_id]['subscription']);
|
1219 |
+
$error = __( 'Invalid site key for the current site. If the error persists, try to unregister first and then register again with the same site key.', 'installer' );
|
1220 |
+
}
|
1221 |
+
|
1222 |
+
|
1223 |
+
} catch (Exception $e ){
|
1224 |
+
$error = $e->getMessage();
|
1225 |
+
if( preg_match('#Could not resolve host: (.*)#', $error, $matches) || preg_match('#Couldn\'t resolve host \'(.*)\'#', $error, $matches) ){
|
1226 |
+
$error = sprintf(__("%s cannot access %s to register. Try again to see if it's a temporary problem. If the problem continues, make sure that this site has access to the Internet. You can still use the plugin without registration, but you will not receive automated updates.", 'installer'),
|
1227 |
+
'<strong><i>' . $this->get_generic_product_name($repository_id) . '</i></strong>',
|
1228 |
+
'<strong><i>' . $matches[1]. '</i></strong>'
|
1229 |
+
) ;
|
1230 |
+
}
|
1231 |
+
}
|
1232 |
+
|
1233 |
+
}
|
1234 |
+
|
1235 |
+
}
|
1236 |
+
|
1237 |
+
echo json_encode(array('error' => $error));
|
1238 |
+
|
1239 |
+
exit;
|
1240 |
+
}
|
1241 |
+
|
1242 |
+
public function api_debug_log($text){
|
1243 |
+
|
1244 |
+
if(defined('WPML_DEBUG_INSTALLER') && WPML_DEBUG_INSTALLER){
|
1245 |
+
|
1246 |
+
if(!is_scalar($text)){
|
1247 |
+
$text = print_r($text, 1);
|
1248 |
+
}
|
1249 |
+
|
1250 |
+
$this->api_debug .= $text . "\n";
|
1251 |
+
|
1252 |
+
}
|
1253 |
+
|
1254 |
+
}
|
1255 |
+
|
1256 |
+
public function fetch_subscription_data( $repository_id, $site_key, $source = self::SITE_KEY_VALIDATION_SOURCE_OTHER ){
|
1257 |
+
|
1258 |
+
$subscription_data = false;
|
1259 |
+
|
1260 |
+
$args['body'] = array(
|
1261 |
+
'action' => 'site_key_validation',
|
1262 |
+
'site_key' => $site_key,
|
1263 |
+
'site_url' => $this->get_installer_site_url( $repository_id ),
|
1264 |
+
'source' => $source
|
1265 |
+
);
|
1266 |
+
|
1267 |
+
if($repository_id == 'wpml'){
|
1268 |
+
$args['body']['using_icl'] = $this->_using_icl;
|
1269 |
+
$args['body']['wpml_version'] = $this->_wpml_version;
|
1270 |
+
}
|
1271 |
+
|
1272 |
+
$args['body']['installer_version'] = WP_INSTALLER_VERSION;
|
1273 |
+
$args['body']['theme'] = wp_get_theme()->get( 'Name' );
|
1274 |
+
$args['body']['site_name'] = get_bloginfo( 'name' );
|
1275 |
+
|
1276 |
+
$args['body']['versions'] = $this->get_local_product_versions( $repository_id );
|
1277 |
+
|
1278 |
+
$args['timeout'] = 45;
|
1279 |
+
|
1280 |
+
// Add extra parameters for custom Installer packages
|
1281 |
+
if( !empty($this->package_source) ){
|
1282 |
+
$extra = $this->get_extra_url_parameters();
|
1283 |
+
if( !empty($extra['repository']) && $extra['repository'] == $repository_id ) {
|
1284 |
+
unset($extra['repository']);
|
1285 |
+
foreach($extra as $key => $val){
|
1286 |
+
$args['body'][$key] = $val;
|
1287 |
+
}
|
1288 |
+
}
|
1289 |
+
}
|
1290 |
+
|
1291 |
+
$response = wp_remote_post($this->repositories[$repository_id]['api-url'], $args);
|
1292 |
+
|
1293 |
+
$this->api_debug_log("POST {$this->repositories[$repository_id]['api-url']}");
|
1294 |
+
$this->api_debug_log($args);
|
1295 |
+
|
1296 |
+
$this->log("POST {$this->repositories[$repository_id]['api-url']} - fetch subscription data");
|
1297 |
+
|
1298 |
+
if( !is_wp_error($response) ){
|
1299 |
+
$datas = wp_remote_retrieve_body($response);
|
1300 |
+
|
1301 |
+
if(is_serialized($datas)){
|
1302 |
+
$data = unserialize($datas);
|
1303 |
+
$this->api_debug_log($data);
|
1304 |
+
|
1305 |
+
if( !empty( $data->subscription_data ) ){
|
1306 |
+
$subscription_data = $data->subscription_data;
|
1307 |
+
}
|
1308 |
+
|
1309 |
+
do_action( 'installer_fetched_subscription_data', $data, $repository_id);
|
1310 |
+
|
1311 |
+
}else{
|
1312 |
+
$this->api_debug_log($datas);
|
1313 |
+
}
|
1314 |
+
|
1315 |
+
}else{
|
1316 |
+
|
1317 |
+
$this->api_debug_log($response);
|
1318 |
+
throw new Exception( $response->get_error_message() );
|
1319 |
+
}
|
1320 |
+
|
1321 |
+
return $subscription_data;
|
1322 |
+
|
1323 |
+
}
|
1324 |
+
|
1325 |
+
function get_local_product_versions( $repository_id ){
|
1326 |
+
|
1327 |
+
$versions = array();
|
1328 |
+
|
1329 |
+
foreach( $this->settings['repositories'][$repository_id]['data']['packages'] as $package_id => $package ){
|
1330 |
+
|
1331 |
+
foreach( $package['products'] as $product_id => $product ){
|
1332 |
+
|
1333 |
+
foreach( $product['plugins'] as $plugin_slug ){
|
1334 |
+
|
1335 |
+
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
1336 |
+
|
1337 |
+
if( empty( $versions[$download['slug']] ) ) {
|
1338 |
+
$v = $this->get_plugin_installed_version($download['name'], $download['slug']);
|
1339 |
+
if($v){
|
1340 |
+
$versions[$download['slug']] = $v;
|
1341 |
+
}
|
1342 |
+
}
|
1343 |
+
|
1344 |
+
}
|
1345 |
+
|
1346 |
+
}
|
1347 |
+
|
1348 |
+
}
|
1349 |
+
|
1350 |
+
return $versions;
|
1351 |
+
}
|
1352 |
+
|
1353 |
+
public function get_repository_site_key($repository_id){
|
1354 |
+
$site_key = false;
|
1355 |
+
|
1356 |
+
if(!empty($this->settings['repositories'][$repository_id]['subscription']['key'])){
|
1357 |
+
$site_key = $this->settings['repositories'][$repository_id]['subscription']['key'];
|
1358 |
+
}
|
1359 |
+
|
1360 |
+
return $site_key;
|
1361 |
+
}
|
1362 |
+
|
1363 |
+
public function repository_has_valid_subscription($repository_id){
|
1364 |
+
|
1365 |
+
$valid = false;
|
1366 |
+
|
1367 |
+
if(!empty($this->settings['repositories'][$repository_id]['subscription'])){
|
1368 |
+
|
1369 |
+
$subscription = $this->settings['repositories'][$repository_id]['subscription']['data'];
|
1370 |
+
$valid = ( $subscription->status == 1 && (strtotime($subscription->expires) > time() || empty($subscription->expires)) ) || $subscription->status == 4;
|
1371 |
+
|
1372 |
+
}
|
1373 |
+
return $valid;
|
1374 |
+
|
1375 |
+
}
|
1376 |
+
|
1377 |
+
public function repository_has_subscription($repository_id){
|
1378 |
+
$key = false;
|
1379 |
+
if(!empty($this->settings['repositories'][$repository_id]['subscription']['key'])){
|
1380 |
+
$key = $this->settings['repositories'][$repository_id]['subscription']['key'];
|
1381 |
+
}
|
1382 |
+
|
1383 |
+
return $key;
|
1384 |
+
|
1385 |
+
}
|
1386 |
+
|
1387 |
+
public function repository_has_expired_subscription($repository_id){
|
1388 |
+
|
1389 |
+
return $this->repository_has_subscription($repository_id) && !$this->repository_has_valid_subscription($repository_id);
|
1390 |
+
|
1391 |
+
}
|
1392 |
+
|
1393 |
+
public function get_generic_product_name($repository_id){
|
1394 |
+
|
1395 |
+
return $this->settings['repositories'][$repository_id]['data']['product-name'];
|
1396 |
+
|
1397 |
+
}
|
1398 |
+
|
1399 |
+
public function show_subscription_renew_warning($repository_id, $subscription_id){
|
1400 |
+
|
1401 |
+
$show = false;
|
1402 |
+
|
1403 |
+
$data = $this->settings['repositories'][$repository_id]['data'];
|
1404 |
+
if(!empty($data['subscriptions_meta'])){
|
1405 |
+
if(isset($data['subscriptions_meta']['expiration'])){
|
1406 |
+
|
1407 |
+
if(!empty($data['subscriptions_meta']['expiration'][$subscription_id])){
|
1408 |
+
|
1409 |
+
$days = $data['subscriptions_meta']['expiration'][$subscription_id]['days_warning'];
|
1410 |
+
$message = $data['subscriptions_meta']['expiration'][$subscription_id]['warning_message'];
|
1411 |
+
|
1412 |
+
}else{
|
1413 |
+
|
1414 |
+
//defaults
|
1415 |
+
$days = 30;
|
1416 |
+
$message = __('You will have to renew your subscription in order to continue getting the updates and support.', 'installer');
|
1417 |
+
|
1418 |
+
}
|
1419 |
+
|
1420 |
+
if(!empty($this->settings['repositories'][$repository_id]['subscription'])){
|
1421 |
+
$subscription = $this->settings['repositories'][$repository_id]['subscription'];
|
1422 |
+
|
1423 |
+
if($subscription['data']->subscription_type == $subscription_id && !empty($subscription['data']->expires)){
|
1424 |
+
|
1425 |
+
if(strtotime($subscription['data']->expires) < strtotime(sprintf("+%d day", $days))){
|
1426 |
+
|
1427 |
+
$days_to_expiration = ceil((strtotime($subscription['data']->expires) - time()) / 86400);
|
1428 |
+
|
1429 |
+
echo '<div><p class="installer-warn-box">' .
|
1430 |
+
sprintf(_n('Your subscription expires in %d day.', 'Your subscription expires in %d days.', $days_to_expiration, 'installer'), $days_to_expiration) .
|
1431 |
+
'<br />' . $message .
|
1432 |
+
'</p></div>';
|
1433 |
+
|
1434 |
+
$show = true;
|
1435 |
+
|
1436 |
+
}
|
1437 |
+
|
1438 |
+
}
|
1439 |
+
|
1440 |
+
}
|
1441 |
+
|
1442 |
+
|
1443 |
+
}
|
1444 |
+
}
|
1445 |
+
|
1446 |
+
|
1447 |
+
return $show;
|
1448 |
+
|
1449 |
+
}
|
1450 |
+
|
1451 |
+
public function setup_plugins_renew_warnings(){
|
1452 |
+
|
1453 |
+
$plugins = get_plugins();
|
1454 |
+
|
1455 |
+
$subscriptions_with_warnings = array();
|
1456 |
+
foreach($this->settings['repositories'] as $repository_id => $repository){
|
1457 |
+
|
1458 |
+
if($this->repository_has_valid_subscription($repository_id)){
|
1459 |
+
$subscription_type = $this->settings['repositories'][$repository_id]['subscription']['data']->subscription_type;
|
1460 |
+
$expires = $this->settings['repositories'][$repository_id]['subscription']['data']->expires;
|
1461 |
+
|
1462 |
+
$never_expires = isset($this->settings['repositories'][$repository_id]['subscription'])
|
1463 |
+
&& empty($this->settings['repositories'][$repository_id]['subscription']['data']->expires)
|
1464 |
+
&& (
|
1465 |
+
$this->settings['repositories'][$repository_id]['subscription']['data']->status == 4 ||
|
1466 |
+
$this->settings['repositories'][$repository_id]['subscription']['data']->status == 1
|
1467 |
+
);
|
1468 |
+
|
1469 |
+
if(!$never_expires){
|
1470 |
+
if(isset($this->settings['repositories'][$repository_id]['data']['subscriptions_meta']['expiration'][$subscription_type])){
|
1471 |
+
|
1472 |
+
$days_warning = $this->settings['repositories'][$repository_id]['data']['subscriptions_meta']['expiration'][$subscription_type]['days_warning'];
|
1473 |
+
$custom_message = $this->settings['repositories'][$repository_id]['data']['subscriptions_meta']['expiration'][$subscription_type]['warning_message'];
|
1474 |
+
|
1475 |
+
}else{
|
1476 |
+
//defaults
|
1477 |
+
$days_warning = 30;
|
1478 |
+
$custom_message = __('You will have to renew your subscription in order to continue getting the updates and support.', 'installer');
|
1479 |
+
}
|
1480 |
+
|
1481 |
+
if(strtotime($expires) < strtotime(sprintf('+%d day', $days_warning)) ){
|
1482 |
+
|
1483 |
+
$days_to_expiration = ceil((strtotime($expires) - time()) / 86400);
|
1484 |
+
|
1485 |
+
$message = sprintf(_n('Your subscription expires in %d day.', 'Your subscription expires in %d days.', $days_to_expiration, 'installer'), $days_to_expiration);
|
1486 |
+
$subscriptions_with_warnings[$subscription_type] = $message . ' ' . $custom_message;
|
1487 |
+
|
1488 |
+
}
|
1489 |
+
}
|
1490 |
+
|
1491 |
+
}
|
1492 |
+
|
1493 |
+
}
|
1494 |
+
|
1495 |
+
|
1496 |
+
|
1497 |
+
foreach($plugins as $plugin_id => $plugin){
|
1498 |
+
|
1499 |
+
$slug = dirname($plugin_id);
|
1500 |
+
if(empty($slug)) continue;
|
1501 |
+
|
1502 |
+
foreach($this->settings['repositories'] as $repository_id => $repository){
|
1503 |
+
|
1504 |
+
if($this->repository_has_valid_subscription($repository_id)){
|
1505 |
+
|
1506 |
+
foreach($repository['data']['packages'] as $package){
|
1507 |
+
|
1508 |
+
foreach($package['products'] as $product){
|
1509 |
+
|
1510 |
+
foreach($product['plugins'] as $plugin_slug){
|
1511 |
+
|
1512 |
+
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
1513 |
+
|
1514 |
+
if($download['slug'] == $slug || $download['name'] == $plugin['Name'] || $download['name'] == $plugin['Title']){ //match order: slug, name, title
|
1515 |
+
|
1516 |
+
if(isset($subscriptions_with_warnings[$product['subscription_type']])){
|
1517 |
+
|
1518 |
+
$this->_plugins_renew_warnings[$plugin_id] = $subscriptions_with_warnings[$product['subscription_type']];
|
1519 |
+
|
1520 |
+
}
|
1521 |
+
|
1522 |
+
}
|
1523 |
+
|
1524 |
+
}
|
1525 |
+
|
1526 |
+
}
|
1527 |
+
|
1528 |
+
}
|
1529 |
+
|
1530 |
+
}
|
1531 |
+
|
1532 |
+
}
|
1533 |
+
|
1534 |
+
}
|
1535 |
+
|
1536 |
+
}
|
1537 |
+
|
1538 |
+
public function queue_plugins_renew_warnings() {
|
1539 |
+
|
1540 |
+
if(!empty($this->_plugins_renew_warnings)){
|
1541 |
+
|
1542 |
+
foreach($this->_plugins_renew_warnings as $plugin_id => $message){
|
1543 |
+
|
1544 |
+
add_action( "after_plugin_row_" . $plugin_id, array($this, 'plugins_renew_warning'), 10, 3 );
|
1545 |
+
}
|
1546 |
+
|
1547 |
+
}
|
1548 |
+
|
1549 |
+
}
|
1550 |
+
|
1551 |
+
public function plugins_renew_warning($plugin_file, $plugin_data, $status){
|
1552 |
+
|
1553 |
+
if(empty($this->_plugins_renew_warnings[$plugin_file])) return;
|
1554 |
+
|
1555 |
+
$wp_list_table = _get_list_table('WP_Plugins_List_Table');
|
1556 |
+
?>
|
1557 |
+
|
1558 |
+
<tr class="plugin-update-tr"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
|
1559 |
+
<div class="update-message">
|
1560 |
+
<?php
|
1561 |
+
echo $this->_plugins_renew_warnings[$plugin_file]. ' ';
|
1562 |
+
printf(__('%sRenew here%s.', 'installer'),
|
1563 |
+
'<a href="' . $this->menu_url() . '">', '</a>');
|
1564 |
+
?>
|
1565 |
+
</div>
|
1566 |
+
</tr>
|
1567 |
+
|
1568 |
+
<?php
|
1569 |
+
|
1570 |
+
}
|
1571 |
+
|
1572 |
+
public function get_subscription_type_for_repository($repository_id){
|
1573 |
+
|
1574 |
+
$subscription_type = false;
|
1575 |
+
|
1576 |
+
if(!empty($this->settings['repositories'][$repository_id]['subscription'])){
|
1577 |
+
$subscription_type = $this->settings['repositories'][$repository_id]['subscription']['data']->subscription_type;
|
1578 |
+
}
|
1579 |
+
|
1580 |
+
return $subscription_type;
|
1581 |
+
|
1582 |
+
}
|
1583 |
+
|
1584 |
+
public function have_superior_subscription($subscription_type, $product){
|
1585 |
+
|
1586 |
+
$have = false;
|
1587 |
+
|
1588 |
+
if(is_array($product['upgrades'])){
|
1589 |
+
foreach($product['upgrades'] as $u){
|
1590 |
+
if($u['subscription_type'] == $subscription_type){
|
1591 |
+
$have = true;
|
1592 |
+
break;
|
1593 |
+
}
|
1594 |
+
}
|
1595 |
+
}
|
1596 |
+
|
1597 |
+
return $have;
|
1598 |
+
}
|
1599 |
+
|
1600 |
+
public function is_product_available_for_download($product_name, $repository_id){
|
1601 |
+
|
1602 |
+
$available = false;
|
1603 |
+
|
1604 |
+
$subscription_type = $this->get_subscription_type_for_repository($repository_id);
|
1605 |
+
$expired = $this->repository_has_expired_subscription($repository_id);
|
1606 |
+
|
1607 |
+
if($this->repository_has_subscription($repository_id) && !$expired){
|
1608 |
+
|
1609 |
+
$this->set_hierarchy_and_order();
|
1610 |
+
|
1611 |
+
foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package_id => $package){
|
1612 |
+
|
1613 |
+
$has_top_package = false;
|
1614 |
+
|
1615 |
+
foreach($package['products'] as $product){
|
1616 |
+
|
1617 |
+
if($subscription_type == $product['subscription_type']){
|
1618 |
+
$has_top_package = true;
|
1619 |
+
if($product['name'] == $product_name){
|
1620 |
+
return $available = true;
|
1621 |
+
}
|
1622 |
+
}
|
1623 |
+
|
1624 |
+
}
|
1625 |
+
|
1626 |
+
if(!empty($package['sub-packages'])){
|
1627 |
+
foreach($package['sub-packages'] as $sub_package){
|
1628 |
+
foreach($sub_package['products'] as $product){
|
1629 |
+
if($product['name'] == $product_name && ($subscription_type == $product['subscription_type'] || $has_top_package)){
|
1630 |
+
return $available = true;
|
1631 |
+
}
|
1632 |
+
}
|
1633 |
+
}
|
1634 |
+
}
|
1635 |
+
|
1636 |
+
}
|
1637 |
+
}
|
1638 |
+
|
1639 |
+
return $available;
|
1640 |
+
|
1641 |
+
}
|
1642 |
+
|
1643 |
+
public function get_upgrade_options($repository_id){
|
1644 |
+
$all_upgrades = array();
|
1645 |
+
|
1646 |
+
|
1647 |
+
//get all products: packages and subpackages
|
1648 |
+
$all_products = array();
|
1649 |
+
foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package){
|
1650 |
+
foreach($package['products'] as $product) {
|
1651 |
+
$all_products[] = $product;
|
1652 |
+
}
|
1653 |
+
if(!empty($package['sub-packages'])){
|
1654 |
+
foreach($package['sub-packages'] as $subpackage){
|
1655 |
+
foreach($subpackage['products'] as $product) {
|
1656 |
+
$all_products[] = $product;
|
1657 |
+
}
|
1658 |
+
|
1659 |
+
}
|
1660 |
+
|
1661 |
+
}
|
1662 |
+
|
1663 |
+
}
|
1664 |
+
|
1665 |
+
foreach( $all_products as $product ) {
|
1666 |
+
if ($product['upgrades']) {
|
1667 |
+
foreach ($product['upgrades'] as $upgrade) {
|
1668 |
+
if ($this->repository_has_valid_subscription($repository_id) || ($this->repository_has_subscription($repository_id) && $upgrade['including_expired'])) {
|
1669 |
+
$all_upgrades[$upgrade['subscription_type']][$product['subscription_type']] = $upgrade;
|
1670 |
+
}
|
1671 |
+
}
|
1672 |
+
}
|
1673 |
+
}
|
1674 |
+
|
1675 |
+
return $all_upgrades;
|
1676 |
+
|
1677 |
+
}
|
1678 |
+
|
1679 |
+
public function append_site_key_to_download_url($url, $key, $repository_id){
|
1680 |
+
|
1681 |
+
$url_params['site_key'] = $key;
|
1682 |
+
$url_params['site_url'] = $this->get_installer_site_url( $repository_id );
|
1683 |
+
|
1684 |
+
|
1685 |
+
// Add extra parameters for custom Installer packages
|
1686 |
+
if( !empty($this->package_source) ){
|
1687 |
+
$extra = $this->get_extra_url_parameters();
|
1688 |
+
if( !empty($extra['repository']) && $extra['repository'] == $repository_id ) {
|
1689 |
+
unset($extra['repository']);
|
1690 |
+
foreach($extra as $key => $val){
|
1691 |
+
$url_params[$key] = $val;
|
1692 |
+
}
|
1693 |
+
}
|
1694 |
+
}
|
1695 |
+
|
1696 |
+
$url = add_query_arg($url_params, $url);
|
1697 |
+
|
1698 |
+
if($repository_id == 'wpml'){
|
1699 |
+
$url = add_query_arg(array('using_icl' => $this->_using_icl, 'wpml_version' => $this->_wpml_version), $url);
|
1700 |
+
}
|
1701 |
+
|
1702 |
+
return $url;
|
1703 |
+
|
1704 |
+
}
|
1705 |
+
|
1706 |
+
public function plugin_is_installed($name, $slug, $version = null){
|
1707 |
+
|
1708 |
+
$is = false;
|
1709 |
+
|
1710 |
+
$plugins = get_plugins();
|
1711 |
+
|
1712 |
+
foreach($plugins as $plugin_id => $plugin){
|
1713 |
+
|
1714 |
+
$wp_plugin_slug = dirname($plugin_id);
|
1715 |
+
|
1716 |
+
// Exception: embedded plugins
|
1717 |
+
if( $wp_plugin_slug == $slug || $plugin['Name'] == $name || $plugin['Title'] == $name || ( $wp_plugin_slug == $slug . '-embedded' || $plugin['Name'] == $name . ' Embedded' ) ){
|
1718 |
+
if($version){
|
1719 |
+
if(version_compare($plugin['Version'], $version, '>=')){
|
1720 |
+
$is = $plugin['Version'];
|
1721 |
+
}
|
1722 |
+
}else{
|
1723 |
+
$is = $plugin['Version'];
|
1724 |
+
}
|
1725 |
+
|
1726 |
+
break;
|
1727 |
+
}
|
1728 |
+
|
1729 |
+
}
|
1730 |
+
|
1731 |
+
//exception: Types name difference
|
1732 |
+
if(!$is && $name == 'Types'){
|
1733 |
+
return $this->plugin_is_installed('Types - Complete Solution for Custom Fields and Types', $slug, $version);
|
1734 |
+
}
|
1735 |
+
|
1736 |
+
return $is;
|
1737 |
+
}
|
1738 |
+
|
1739 |
+
public function plugin_is_embedded_version($name, $slug){
|
1740 |
+
$is = false;
|
1741 |
+
|
1742 |
+
$plugins = get_plugins();
|
1743 |
+
|
1744 |
+
//false if teh full version is also installed
|
1745 |
+
$is_full_installed = false;
|
1746 |
+
foreach($plugins as $plugin_id => $plugin){
|
1747 |
+
|
1748 |
+
if(($plugin['Name'] == $name && !preg_match("#-embedded$#", $slug)) ){
|
1749 |
+
$is_full_installed = true;
|
1750 |
+
break;
|
1751 |
+
}
|
1752 |
+
|
1753 |
+
}
|
1754 |
+
|
1755 |
+
if($is_full_installed){
|
1756 |
+
return false;
|
1757 |
+
}
|
1758 |
+
|
1759 |
+
foreach($plugins as $plugin_id => $plugin){
|
1760 |
+
|
1761 |
+
// TBD
|
1762 |
+
$wp_plugin_slug = dirname($plugin_id);
|
1763 |
+
if( $wp_plugin_slug == $slug . '-embedded' && $plugin['Name'] == $name . ' Embedded'){
|
1764 |
+
$is = true;
|
1765 |
+
break;
|
1766 |
+
}
|
1767 |
+
|
1768 |
+
}
|
1769 |
+
|
1770 |
+
return $is;
|
1771 |
+
|
1772 |
+
}
|
1773 |
+
|
1774 |
+
//Alias for plugin_is_installed
|
1775 |
+
public function get_plugin_installed_version($name, $slug){
|
1776 |
+
|
1777 |
+
return $this->plugin_is_installed($name, $slug);
|
1778 |
+
|
1779 |
+
}
|
1780 |
+
|
1781 |
+
public function get_plugin_repository_version($repository_id, $slug){
|
1782 |
+
$version = false;
|
1783 |
+
|
1784 |
+
if(!empty($this->settings['repositories'][$repository_id]['data']['packages'])){
|
1785 |
+
foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package){
|
1786 |
+
foreach($package['products'] as $product) {
|
1787 |
+
|
1788 |
+
foreach($product['plugins'] as $plugin_slug){
|
1789 |
+
|
1790 |
+
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
1791 |
+
|
1792 |
+
if($download['slug'] == $slug){
|
1793 |
+
$version = $download['version'];
|
1794 |
+
break (3);
|
1795 |
+
}
|
1796 |
+
|
1797 |
+
}
|
1798 |
+
|
1799 |
+
}
|
1800 |
+
}
|
1801 |
+
}
|
1802 |
+
|
1803 |
+
return $version;
|
1804 |
+
}
|
1805 |
+
|
1806 |
+
public function is_uploading_allowed(){
|
1807 |
+
|
1808 |
+
//_deprecated_function ( __FUNCTION__, '1.7.3', 'Installer_Dependencies::' . __FUNCTION__ );
|
1809 |
+
return $this->dependencies->is_uploading_allowed();
|
1810 |
+
|
1811 |
+
}
|
1812 |
+
|
1813 |
+
public function download_plugin_ajax_handler(){
|
1814 |
+
|
1815 |
+
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
1816 |
+
require_once $this->plugin_path() . '/includes/installer-upgrader-skins.php';
|
1817 |
+
|
1818 |
+
$data = json_decode( base64_decode( sanitize_text_field ( $_POST['data'] ) ), true );
|
1819 |
+
|
1820 |
+
$ret = false;
|
1821 |
+
$plugin_id = false;
|
1822 |
+
$message = '';
|
1823 |
+
|
1824 |
+
//validate subscription
|
1825 |
+
$site_key = $this->get_repository_site_key($data['repository_id']);
|
1826 |
+
$subscription_data = $this->fetch_subscription_data( $data['repository_id'], $site_key , self::SITE_KEY_VALIDATION_SOURCE_DOWNLOAD_REPORT);
|
1827 |
+
|
1828 |
+
if($subscription_data && !is_wp_error($subscription_data) && $this->repository_has_valid_subscription($data['repository_id'])){
|
1829 |
+
|
1830 |
+
if($data['nonce'] == wp_create_nonce('install_plugin_' . $data['url'])){
|
1831 |
+
|
1832 |
+
$upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin
|
1833 |
+
$upgrader = new Plugin_Upgrader($upgrader_skins);
|
1834 |
+
|
1835 |
+
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
|
1836 |
+
|
1837 |
+
$plugins = get_plugins();
|
1838 |
+
|
1839 |
+
//upgrade or install?
|
1840 |
+
foreach($plugins as $id => $plugin){
|
1841 |
+
$wp_plugin_slug = dirname($id);
|
1842 |
+
$is_embedded = $this->plugin_is_embedded_version(preg_replace('/ Embedded$/', '', $plugin['Name']), preg_replace('/-embedded$/', '', $wp_plugin_slug));
|
1843 |
+
|
1844 |
+
if($wp_plugin_slug == $data['slug'] || $is_embedded && preg_replace('/-embedded$/', '', $wp_plugin_slug) == $data['slug']){
|
1845 |
+
$plugin_id = $id;
|
1846 |
+
break;
|
1847 |
+
}
|
1848 |
+
}
|
1849 |
+
|
1850 |
+
if($plugin_id && empty($is_embedded)){ //upgrade
|
1851 |
+
$response['upgrade'] = 1;
|
1852 |
+
|
1853 |
+
$plugin_is_active = is_plugin_active($plugin_id);
|
1854 |
+
|
1855 |
+
$ret = $upgrader->upgrade($plugin_id);
|
1856 |
+
|
1857 |
+
if(!$ret && !empty($upgrader->skin->installer_error)){
|
1858 |
+
if(is_wp_error($upgrader->skin->installer_error)){
|
1859 |
+
$message = $upgrader->skin->installer_error->get_error_message() .
|
1860 |
+
' (' . $upgrader->skin->installer_error->get_error_data() . ')';
|
1861 |
+
}
|
1862 |
+
}
|
1863 |
+
|
1864 |
+
if($plugin_is_active){
|
1865 |
+
//prevent redirects
|
1866 |
+
add_filter('wp_redirect', '__return_false');
|
1867 |
+
activate_plugin($plugin_id);
|
1868 |
+
}
|
1869 |
+
|
1870 |
+
}else{ //install
|
1871 |
+
|
1872 |
+
if($is_embedded){
|
1873 |
+
delete_plugins(array($plugin_id));
|
1874 |
+
}
|
1875 |
+
|
1876 |
+
$response['install'] = 1;
|
1877 |
+
$ret = $upgrader->install($data['url']);
|
1878 |
+
if(!$ret && !empty($upgrader->skin->installer_error)){
|
1879 |
+
if(is_wp_error($upgrader->skin->installer_error)){
|
1880 |
+
$message = $upgrader->skin->installer_error->get_error_message() .
|
1881 |
+
' (' . $upgrader->skin->installer_error->get_error_data() . ')';
|
1882 |
+
}
|
1883 |
+
}
|
1884 |
+
}
|
1885 |
+
|
1886 |
+
$plugins = get_plugins(); //read again
|
1887 |
+
|
1888 |
+
if($ret && !empty($_POST['activate'])){
|
1889 |
+
foreach($plugins as $id => $plugin){
|
1890 |
+
$wp_plugin_slug = dirname($id);
|
1891 |
+
if($wp_plugin_slug == $data['slug']){
|
1892 |
+
$plugin_version = $plugin['Version'];
|
1893 |
+
$plugin_id = $id;
|
1894 |
+
break;
|
1895 |
+
}
|
1896 |
+
}
|
1897 |
+
|
1898 |
+
}
|
1899 |
+
|
1900 |
+
}
|
1901 |
+
|
1902 |
+
} else { //subscription not valid
|
1903 |
+
|
1904 |
+
$ret = false;
|
1905 |
+
$message = __('Your subscription appears to no longer be valid. Please try to register again using a valid site key.', 'installer');
|
1906 |
+
}
|
1907 |
+
|
1908 |
+
$response['version'] = isset($plugin_version) ? $plugin_version : 0;
|
1909 |
+
$response['plugin_id'] = $plugin_id;
|
1910 |
+
$response['nonce'] = wp_create_nonce('activate_' . $plugin_id);
|
1911 |
+
$response['success'] = $ret;
|
1912 |
+
$response['message'] = $message;
|
1913 |
+
|
1914 |
+
echo json_encode( $response );
|
1915 |
+
exit;
|
1916 |
+
|
1917 |
+
}
|
1918 |
+
|
1919 |
+
public function download_plugin($slug, $url){
|
1920 |
+
|
1921 |
+
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
1922 |
+
require_once $this->plugin_path() . '/includes/installer-upgrader-skins.php';
|
1923 |
+
|
1924 |
+
$upgrader_skins = new Installer_Upgrader_Skins(); //use our custom (mute) Skin
|
1925 |
+
$upgrader = new Plugin_Upgrader($upgrader_skins);
|
1926 |
+
|
1927 |
+
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
|
1928 |
+
|
1929 |
+
$plugins = get_plugins();
|
1930 |
+
|
1931 |
+
$plugin_id = false;
|
1932 |
+
|
1933 |
+
//upgrade or install?
|
1934 |
+
foreach($plugins as $id => $plugin){
|
1935 |
+
$wp_plugin_slug = dirname($id);
|
1936 |
+
if($wp_plugin_slug == $slug){
|
1937 |
+
$plugin_id = $id;
|
1938 |
+
break;
|
1939 |
+
}
|
1940 |
+
}
|
1941 |
+
|
1942 |
+
if($plugin_id){ //upgrade
|
1943 |
+
|
1944 |
+
$plugin_is_active = is_plugin_active($plugin_id);
|
1945 |
+
|
1946 |
+
$ret = $upgrader->upgrade($plugin_id);
|
1947 |
+
|
1948 |
+
if($plugin_is_active){
|
1949 |
+
activate_plugin($plugin_id);
|
1950 |
+
}
|
1951 |
+
|
1952 |
+
}else{ //install
|
1953 |
+
$ret = $upgrader->install($url);
|
1954 |
+
}
|
1955 |
+
|
1956 |
+
return $ret;
|
1957 |
+
|
1958 |
+
}
|
1959 |
+
|
1960 |
+
public function activate_plugin(){
|
1961 |
+
|
1962 |
+
$error = '';
|
1963 |
+
|
1964 |
+
$plugin_id = sanitize_text_field ( $_POST['plugin_id'] );
|
1965 |
+
if(isset($_POST['nonce']) && $plugin_id && $_POST['nonce'] == wp_create_nonce('activate_' . $plugin_id )){
|
1966 |
+
|
1967 |
+
// Deactivate any embedded version
|
1968 |
+
$plugin_slug = dirname($plugin_id);
|
1969 |
+
$active_plugins = get_option('active_plugins');
|
1970 |
+
foreach($active_plugins as $plugin){
|
1971 |
+
$wp_plugin_slug = dirname($plugin);
|
1972 |
+
if($wp_plugin_slug == $plugin_slug . '-embedded'){
|
1973 |
+
deactivate_plugins(array($plugin));
|
1974 |
+
break;
|
1975 |
+
}
|
1976 |
+
}
|
1977 |
+
|
1978 |
+
//prevent redirects
|
1979 |
+
add_filter('wp_redirect', '__return_false', 10000);
|
1980 |
+
|
1981 |
+
$return = activate_plugin($plugin_id);
|
1982 |
+
|
1983 |
+
if(is_wp_error($return)){
|
1984 |
+
$error = $return->get_error_message();
|
1985 |
+
}
|
1986 |
+
|
1987 |
+
}else{
|
1988 |
+
$error = 'error';
|
1989 |
+
}
|
1990 |
+
|
1991 |
+
$ret = array('error' => $error);
|
1992 |
+
|
1993 |
+
echo json_encode($ret);
|
1994 |
+
exit;
|
1995 |
+
|
1996 |
+
}
|
1997 |
+
|
1998 |
+
public function custom_plugins_api_call($false, $action, $args){
|
1999 |
+
|
2000 |
+
if($action == 'plugin_information'){
|
2001 |
+
|
2002 |
+
$plugins = get_plugins();
|
2003 |
+
$plugin_names = array();
|
2004 |
+
foreach( $plugins as $plugin_id => $plugin ) {
|
2005 |
+
// plugins by WP slug which (plugin folder) which can be different
|
2006 |
+
// will use this to compare by title
|
2007 |
+
$plugin_names[ dirname( $plugin_id ) ] = array(
|
2008 |
+
'name' => $plugin['Name'],
|
2009 |
+
'title' => $plugin['Title'],
|
2010 |
+
);
|
2011 |
+
}
|
2012 |
+
|
2013 |
+
$slug = $args->slug;
|
2014 |
+
|
2015 |
+
foreach($this->settings['repositories'] as $repository_id => $repository){
|
2016 |
+
|
2017 |
+
if(!$this->repository_has_valid_subscription($repository_id)){
|
2018 |
+
$site_key = false;
|
2019 |
+
}else{
|
2020 |
+
$site_key = $repository['subscription']['key'];
|
2021 |
+
}
|
2022 |
+
|
2023 |
+
foreach($repository['data']['packages'] as $package){
|
2024 |
+
|
2025 |
+
foreach($package['products'] as $product){
|
2026 |
+
|
2027 |
+
foreach($product['plugins'] as $plugin_slug){
|
2028 |
+
|
2029 |
+
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
2030 |
+
|
2031 |
+
if( $download['slug'] == $slug ||
|
2032 |
+
isset( $plugin_names[$slug] ) && (
|
2033 |
+
$plugin_names[$slug]['name'] == $download['name'] ||
|
2034 |
+
$plugin_names[$slug]['title'] == $download['name']
|
2035 |
+
)
|
2036 |
+
){
|
2037 |
+
|
2038 |
+
if( !empty( $download['free-on-wporg'] ) ){
|
2039 |
+
return false; // use data from wordpress.org
|
2040 |
+
}
|
2041 |
+
|
2042 |
+
$res = new stdClass();
|
2043 |
+
$res->external = true;
|
2044 |
+
|
2045 |
+
$res->name = $download['name'];
|
2046 |
+
$res->slug = $slug;
|
2047 |
+
$res->version = $download['version'];
|
2048 |
+
$res->author = '';
|
2049 |
+
$res->author_profile = '';
|
2050 |
+
$res->last_updated = $download['date'];
|
2051 |
+
|
2052 |
+
if($site_key){
|
2053 |
+
$res->download_link = $this->append_site_key_to_download_url($download['url'], $site_key, $repository_id);
|
2054 |
+
}
|
2055 |
+
|
2056 |
+
$res->homepage = $repository['data']['url'];
|
2057 |
+
$res->sections = array('Description' => $download['description'], 'Changelog' => $download['changelog']);
|
2058 |
+
|
2059 |
+
return $res;
|
2060 |
+
|
2061 |
+
}
|
2062 |
+
|
2063 |
+
}
|
2064 |
+
|
2065 |
+
}
|
2066 |
+
|
2067 |
+
}
|
2068 |
+
|
2069 |
+
}
|
2070 |
+
|
2071 |
+
}
|
2072 |
+
|
2073 |
+
return $false;
|
2074 |
+
|
2075 |
+
}
|
2076 |
+
|
2077 |
+
public function plugins_upgrade_check($update_plugins){
|
2078 |
+
|
2079 |
+
if(!empty($this->settings['repositories'])){
|
2080 |
+
|
2081 |
+
$plugins = get_plugins();
|
2082 |
+
|
2083 |
+
foreach($plugins as $plugin_id => $plugin){
|
2084 |
+
|
2085 |
+
$slug = dirname($plugin_id);
|
2086 |
+
if(empty($slug)) continue;
|
2087 |
+
|
2088 |
+
$version = $plugin['Version'];
|
2089 |
+
$name = $plugin['Name'];
|
2090 |
+
|
2091 |
+
foreach($this->settings['repositories'] as $repository_id => $repository){
|
2092 |
+
|
2093 |
+
|
2094 |
+
if(!$this->repository_has_valid_subscription($repository_id)){
|
2095 |
+
$site_key = false;
|
2096 |
+
}else{
|
2097 |
+
$site_key = $repository['subscription']['key'];
|
2098 |
+
//$subscription_type = $this->get_subscription_type_for_repository($repository_id);
|
2099 |
+
}
|
2100 |
+
|
2101 |
+
foreach($repository['data']['packages'] as $package){
|
2102 |
+
|
2103 |
+
foreach($package['products'] as $product){
|
2104 |
+
|
2105 |
+
foreach($product['plugins'] as $plugin_slug){
|
2106 |
+
|
2107 |
+
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
2108 |
+
|
2109 |
+
if(!empty($download['free-on-wporg'])) {
|
2110 |
+
continue;
|
2111 |
+
}
|
2112 |
+
|
2113 |
+
if(empty($update_plugins->response[$plugin_id]) && ($download['slug'] == $slug || $download['name'] == $name ) && version_compare($download['version'], $version, '>')){
|
2114 |
+
|
2115 |
+
$response = new stdClass();
|
2116 |
+
$response->id = 0;
|
2117 |
+
$response->slug = $slug;
|
2118 |
+
$response->plugin = $plugin_id;
|
2119 |
+
$response->new_version = $download['version'];
|
2120 |
+
$response->upgrade_notice = '';
|
2121 |
+
$response->url = $download['url'];
|
2122 |
+
if($site_key){
|
2123 |
+
$response->package = $this->append_site_key_to_download_url($download['url'], $site_key, $repository_id);
|
2124 |
+
}
|
2125 |
+
$update_plugins->checked[$plugin_id] = $version;
|
2126 |
+
$update_plugins->response[$plugin_id] = $response;
|
2127 |
+
|
2128 |
+
}
|
2129 |
+
|
2130 |
+
}
|
2131 |
+
|
2132 |
+
}
|
2133 |
+
|
2134 |
+
}
|
2135 |
+
|
2136 |
+
}
|
2137 |
+
|
2138 |
+
}
|
2139 |
+
|
2140 |
+
}
|
2141 |
+
|
2142 |
+
return $update_plugins;
|
2143 |
+
|
2144 |
+
}
|
2145 |
+
|
2146 |
+
public function setup_plugins_page_notices(){
|
2147 |
+
|
2148 |
+
$plugins = get_plugins();
|
2149 |
+
|
2150 |
+
foreach($plugins as $plugin_id => $plugin){
|
2151 |
+
|
2152 |
+
$slug = dirname($plugin_id);
|
2153 |
+
if(empty($slug)) continue;
|
2154 |
+
|
2155 |
+
$name = $plugin['Name'];
|
2156 |
+
|
2157 |
+
foreach($this->settings['repositories'] as $repository_id => $repository){
|
2158 |
+
|
2159 |
+
if(!$this->repository_has_valid_subscription($repository_id)){
|
2160 |
+
$site_key = false;
|
2161 |
+
}else{
|
2162 |
+
$site_key = $repository['subscription']['key'];
|
2163 |
+
}
|
2164 |
+
|
2165 |
+
foreach($repository['data']['packages'] as $package){
|
2166 |
+
|
2167 |
+
foreach($package['products'] as $product){
|
2168 |
+
|
2169 |
+
foreach($product['plugins'] as $plugin_slug){
|
2170 |
+
|
2171 |
+
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
2172 |
+
|
2173 |
+
if(!empty($download['free-on-wporg'])) {
|
2174 |
+
continue;
|
2175 |
+
}
|
2176 |
+
|
2177 |
+
if( $download['slug'] == $slug || $download['name'] == $name ){
|
2178 |
+
|
2179 |
+
if( !$site_key || !$this->plugin_is_registered($repository_id, $download['slug']) ){
|
2180 |
+
add_action( "after_plugin_row_" . $plugin_id, array($this, 'show_purchase_notice_under_plugin'), 10, 3 );
|
2181 |
+
}
|
2182 |
+
|
2183 |
+
}
|
2184 |
+
|
2185 |
+
}
|
2186 |
+
|
2187 |
+
}
|
2188 |
+
|
2189 |
+
}
|
2190 |
+
|
2191 |
+
}
|
2192 |
+
|
2193 |
+
}
|
2194 |
+
|
2195 |
+
}
|
2196 |
+
|
2197 |
+
public function show_purchase_notice_under_plugin($plugin_file, $plugin_data, $status){
|
2198 |
+
|
2199 |
+
$wp_list_table = _get_list_table('WP_Plugins_List_Table');
|
2200 |
+
$wp_version = preg_replace( '/-(.+)$/', '', $GLOBALS['wp_version'] );
|
2201 |
+
|
2202 |
+
if( version_compare( $wp_version, '4.6', '>=' ) ){
|
2203 |
+
|
2204 |
+
?>
|
2205 |
+
<tr class="plugin-update-tr installer-plugin-update-tr">
|
2206 |
+
<td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
|
2207 |
+
<div class="notice inline notice-warning notice-alt">
|
2208 |
+
<p class="installer-q-icon">
|
2209 |
+
<?php printf( __('You must have a valid subscription in order to get upgrades or support for this plugin. %sPurchase a subscription or enter an existing site key%s.', 'installer'),
|
2210 |
+
'<a href="' . $this->menu_url() . '">', '</a>'); ?>
|
2211 |
+
</p>
|
2212 |
+
</div>
|
2213 |
+
</td>
|
2214 |
+
</tr>
|
2215 |
+
<?php
|
2216 |
+
|
2217 |
+
} else {
|
2218 |
+
|
2219 |
+
?>
|
2220 |
+
<tr class="plugin-update-tr">
|
2221 |
+
<td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
|
2222 |
+
<div class="update-message installer-q-icon">
|
2223 |
+
<?php printf( __('You must have a valid subscription in order to get upgrades or support for this plugin. %sPurchase a subscription or enter an existing site key%s.', 'installer'),
|
2224 |
+
'<a href="' . $this->menu_url() . '">', '</a>'); ?>
|
2225 |
+
</div>
|
2226 |
+
</td>
|
2227 |
+
</tr>
|
2228 |
+
<?php
|
2229 |
+
|
2230 |
+
}
|
2231 |
+
|
2232 |
+
}
|
2233 |
+
|
2234 |
+
public function localize_strings(){
|
2235 |
+
|
2236 |
+
if(!empty($this->settings['repositories'])){
|
2237 |
+
foreach($this->settings['repositories'] as $repository_id => $repository){
|
2238 |
+
//set name as call2action when don't have any
|
2239 |
+
//products
|
2240 |
+
foreach($repository['data']['packages'] as $package_id => $package){
|
2241 |
+
foreach($package['products'] as $product_id => $product){
|
2242 |
+
if(empty($product['call2action'])){
|
2243 |
+
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['call2action'] = $product['name'];
|
2244 |
+
}
|
2245 |
+
|
2246 |
+
foreach($product['upgrades'] as $idx => $upg){
|
2247 |
+
if(empty($upg['call2action'])){
|
2248 |
+
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['upgrades'][$idx]['call2action'] = $upg['name'];
|
2249 |
+
}
|
2250 |
+
}
|
2251 |
+
|
2252 |
+
foreach($product['renewals'] as $idx => $rnw){
|
2253 |
+
if(empty($rnw['call2action'])){
|
2254 |
+
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['renewals'][$idx]['call2action'] = $rnw['name'];
|
2255 |
+
}
|
2256 |
+
|
2257 |
+
}
|
2258 |
+
|
2259 |
+
}
|
2260 |
+
}
|
2261 |
+
}
|
2262 |
+
}
|
2263 |
+
|
2264 |
+
global $sitepress;
|
2265 |
+
if(is_null($sitepress)){
|
2266 |
+
return;
|
2267 |
+
}
|
2268 |
+
|
2269 |
+
// default strings are always in English
|
2270 |
+
$user_admin_language = $sitepress->get_admin_language();
|
2271 |
+
|
2272 |
+
if($user_admin_language != 'en'){
|
2273 |
+
foreach($this->settings['repositories'] as $repository_id => $repository){
|
2274 |
+
|
2275 |
+
$localization = $repository['data']['localization'];
|
2276 |
+
|
2277 |
+
//packages
|
2278 |
+
foreach($repository['data']['packages'] as $package_id => $package){
|
2279 |
+
|
2280 |
+
if( isset($localization['packages'][$package_id]['name'][$user_admin_language]) ){
|
2281 |
+
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['name'] = $localization['packages'][$package_id]['name'][$user_admin_language];
|
2282 |
+
}
|
2283 |
+
if( isset($localization['packages'][$package_id]['description'][$user_admin_language]) ){
|
2284 |
+
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['description'] = $localization['packages'][$package_id]['description'][$user_admin_language];
|
2285 |
+
}
|
2286 |
+
|
2287 |
+
}
|
2288 |
+
|
2289 |
+
//products
|
2290 |
+
foreach($repository['data']['packages'] as $package_id => $package){
|
2291 |
+
foreach($package['products'] as $product_id => $product){
|
2292 |
+
|
2293 |
+
if( isset($localization['products'][$product_id]['name'][$user_admin_language]) ){
|
2294 |
+
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['name']
|
2295 |
+
= $localization['products'][$product_id]['name'][$user_admin_language];
|
2296 |
+
}
|
2297 |
+
if( isset($localization['products'][$product_id]['description'][$user_admin_language]) ){
|
2298 |
+
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['description']
|
2299 |
+
= $localization['products'][$product_id]['description'][$user_admin_language];
|
2300 |
+
}
|
2301 |
+
if( isset($localization['products'][$product_id]['call2action'][$user_admin_language]) ){
|
2302 |
+
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['name']
|
2303 |
+
= $localization['products'][$product_id]['call2action'][$user_admin_language];
|
2304 |
+
}
|
2305 |
+
|
2306 |
+
|
2307 |
+
}
|
2308 |
+
}
|
2309 |
+
|
2310 |
+
//subscription info
|
2311 |
+
if(isset($repository['data']['subscriptions_meta']['expiration'])){
|
2312 |
+
foreach($repository['data']['subscriptions_meta']['expiration'] as $subscription_id => $note){
|
2313 |
+
if(isset($localization['subscriptions-notes'][$subscription_id]['expiration-warning'][$user_admin_language])){
|
2314 |
+
$this->settings['repositories'][$repository_id]['data']['subscriptions_meta']['expiration'][$subscription_id]['warning_message']
|
2315 |
+
= $localization['subscriptions-notes'][$subscription_id]['expiration-warning'][$user_admin_language];
|
2316 |
+
}
|
2317 |
+
}
|
2318 |
+
}
|
2319 |
+
|
2320 |
+
}
|
2321 |
+
}
|
2322 |
+
|
2323 |
+
}
|
2324 |
+
|
2325 |
+
public function get_matching_cp($repository, $args = array()){
|
2326 |
+
$match = false;
|
2327 |
+
|
2328 |
+
|
2329 |
+
$cp_name = $cp_author = false;
|
2330 |
+
|
2331 |
+
if(isset($this->config['src_name']) && isset($this->config['src_author'])){
|
2332 |
+
|
2333 |
+
$cp_name = $this->config['src_name'];
|
2334 |
+
$cp_author = $this->config['src_author'];
|
2335 |
+
|
2336 |
+
}elseif(isset($args['src_name']) && isset($args['src_author'])){
|
2337 |
+
|
2338 |
+
$cp_name = $args['src_name'];
|
2339 |
+
$cp_author = $args['src_author'];
|
2340 |
+
|
2341 |
+
}
|
2342 |
+
|
2343 |
+
if(isset($repository['data']['marketing_cp'])){
|
2344 |
+
|
2345 |
+
foreach($repository['data']['marketing_cp'] as $cp){
|
2346 |
+
|
2347 |
+
if(!empty($cp['exp']) && time() > $cp['exp']){
|
2348 |
+
continue;
|
2349 |
+
}
|
2350 |
+
|
2351 |
+
//Use theme_name for plugins too
|
2352 |
+
if(!empty($cp['theme_name'])){
|
2353 |
+
if($cp['author_name'] == $cp_author && $cp['theme_name'] == $cp_name){
|
2354 |
+
$match = $cp;
|
2355 |
+
continue;
|
2356 |
+
}
|
2357 |
+
}else{
|
2358 |
+
if($cp['author_name'] == $cp_author){
|
2359 |
+
$match = $cp;
|
2360 |
+
continue;
|
2361 |
+
}
|
2362 |
+
}
|
2363 |
+
|
2364 |
+
}
|
2365 |
+
|
2366 |
+
}
|
2367 |
+
|
2368 |
+
return $match;
|
2369 |
+
}
|
2370 |
+
|
2371 |
+
public function set_filtered_prices($args = array()){
|
2372 |
+
|
2373 |
+
foreach($this->settings['repositories'] as $repository_id => $repository){
|
2374 |
+
|
2375 |
+
$match = $this->get_matching_cp($repository, $args);
|
2376 |
+
|
2377 |
+
if(empty($match)) continue;
|
2378 |
+
|
2379 |
+
foreach($repository['data']['packages'] as $package_id => $package){
|
2380 |
+
|
2381 |
+
foreach($package['products'] as $product_id => $product){
|
2382 |
+
|
2383 |
+
if($match['dtp'] == '%'){
|
2384 |
+
$fprice = round( $product['price'] * (1 - $match['amt']/100), 2 );
|
2385 |
+
$fprice = $fprice != round($fprice) ? sprintf('%.2f', $fprice) : round($fprice, 0);
|
2386 |
+
}elseif($match['dtp'] == '-'){
|
2387 |
+
$fprice = $product['price'] - $match['amt'];
|
2388 |
+
}else{
|
2389 |
+
$fprice = $product['price'];
|
2390 |
+
}
|
2391 |
+
|
2392 |
+
if($fprice){
|
2393 |
+
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['price_disc'] = $fprice;
|
2394 |
+
|
2395 |
+
$url_glue = false !== strpos($this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['url'], '?') ? '&' : '?';
|
2396 |
+
$cpndata = base64_encode(json_encode(array('theme_author' => $match['author_name'], 'theme_name' => $match['theme_name'], 'vlc' => $match['vlc'])));
|
2397 |
+
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['url'] .= $url_glue . 'cpn=' . $cpndata;
|
2398 |
+
|
2399 |
+
foreach($product['upgrades'] as $upgrade_id => $upgrade){
|
2400 |
+
|
2401 |
+
$fprice = false;
|
2402 |
+
if($match['dtp'] == '%'){
|
2403 |
+
$fprice = round( $upgrade['price'] * (1 - $match['amt']/100), 2 );
|
2404 |
+
$fprice = $fprice != round($fprice) ? sprintf('%.2f', $fprice) : round($fprice, 0);
|
2405 |
+
}elseif($match['dtp'] == '-'){
|
2406 |
+
$fprice = $upgrade['price'] - $match['amt'];
|
2407 |
+
}
|
2408 |
+
if($fprice){
|
2409 |
+
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['upgrades'][$upgrade_id]['price_disc'] = $fprice;
|
2410 |
+
$this->settings['repositories'][$repository_id]['data']['packages'][$package_id]['products'][$product_id]['upgrades'][$upgrade_id]['url'] .= $url_glue . 'cpn=' . $cpndata;
|
2411 |
+
}
|
2412 |
+
|
2413 |
+
|
2414 |
+
}
|
2415 |
+
|
2416 |
+
}
|
2417 |
+
|
2418 |
+
}
|
2419 |
+
|
2420 |
+
}
|
2421 |
+
|
2422 |
+
}
|
2423 |
+
|
2424 |
+
}
|
2425 |
+
|
2426 |
+
public function set_hierarchy_and_order(){
|
2427 |
+
|
2428 |
+
//2 levels
|
2429 |
+
if(!empty($this->settings['repositories'])) {
|
2430 |
+
foreach ($this->settings['repositories'] as $repository_id => $repository) {
|
2431 |
+
|
2432 |
+
if( empty( $repository['data']['packages'] ) ) continue;
|
2433 |
+
|
2434 |
+
$all_packages = $repository['data']['packages'];
|
2435 |
+
$ordered_packages = array();
|
2436 |
+
|
2437 |
+
//backward compatibility - 'order'
|
2438 |
+
foreach($all_packages as $k => $v){
|
2439 |
+
if(!isset($v['order'])){
|
2440 |
+
$all_packages[$k]['order'] = 0;
|
2441 |
+
}
|
2442 |
+
}
|
2443 |
+
|
2444 |
+
//select parents
|
2445 |
+
foreach ($all_packages as $package_id => $package) {
|
2446 |
+
if(empty($package['parent'])){
|
2447 |
+
$ordered_packages[$package_id] = $package;
|
2448 |
+
}
|
2449 |
+
}
|
2450 |
+
|
2451 |
+
//add sub-packages
|
2452 |
+
foreach($all_packages as $package_id => $package){
|
2453 |
+
if(!empty($package['parent'])) {
|
2454 |
+
if(isset($ordered_packages[$package['parent']])){
|
2455 |
+
$ordered_packages[$package['parent']]['sub-packages'][$package_id] = $package;
|
2456 |
+
}
|
2457 |
+
}
|
2458 |
+
}
|
2459 |
+
|
2460 |
+
// order parents
|
2461 |
+
usort($ordered_packages, array($this, '_order_packages_callback'));
|
2462 |
+
//order sub-packages
|
2463 |
+
foreach($ordered_packages as $package_id => $package){
|
2464 |
+
if(!empty($package['sub-packages'])) {
|
2465 |
+
usort($ordered_packages[$package_id]['sub-packages'], create_function('$a, $b', 'return $a[\'order\'] > $b[\'order\'];'));
|
2466 |
+
}
|
2467 |
+
}
|
2468 |
+
|
2469 |
+
$this->settings['repositories'][$repository_id]['data']['packages'] = $ordered_packages;
|
2470 |
+
|
2471 |
+
|
2472 |
+
}
|
2473 |
+
}
|
2474 |
+
|
2475 |
+
|
2476 |
+
}
|
2477 |
+
|
2478 |
+
public function _order_packages_callback($a, $b){
|
2479 |
+
return $a['order'] > $b['order'];
|
2480 |
+
}
|
2481 |
+
|
2482 |
+
public function get_support_tag_by_name( $name, $repository ){
|
2483 |
+
|
2484 |
+
if( is_array($this->settings['repositories'][$repository]['data']['support_tags'] )){
|
2485 |
+
foreach( $this->settings['repositories'][$repository]['data']['support_tags'] as $support_tag){
|
2486 |
+
if( $support_tag['name'] == $name ){
|
2487 |
+
return $support_tag['url'];
|
2488 |
+
}
|
2489 |
+
}
|
2490 |
+
}
|
2491 |
+
|
2492 |
+
return false;
|
2493 |
+
}
|
2494 |
+
|
2495 |
+
public function plugin_upgrade_custom_errors(){
|
2496 |
+
|
2497 |
+
if ( isset($_REQUEST['action']) ) {
|
2498 |
+
|
2499 |
+
$action = isset($_REQUEST['action']) ? sanitize_text_field ( $_REQUEST['action'] ) : '';
|
2500 |
+
|
2501 |
+
//bulk mode
|
2502 |
+
if('update-selected' == $action) {
|
2503 |
+
|
2504 |
+
global $plugins;
|
2505 |
+
|
2506 |
+
if(isset($plugins) && is_array($plugins)) {
|
2507 |
+
|
2508 |
+
foreach ($plugins as $k => $plugin) {
|
2509 |
+
$plugin_repository = false;
|
2510 |
+
|
2511 |
+
$wp_plugin_slug = dirname($plugin);
|
2512 |
+
|
2513 |
+
foreach ($this->settings['repositories'] as $repository_id => $repository) {
|
2514 |
+
|
2515 |
+
foreach ($repository['data']['packages'] as $package) {
|
2516 |
+
|
2517 |
+
foreach ($package['products'] as $product) {
|
2518 |
+
|
2519 |
+
foreach ($product['plugins'] as $plugin_slug) {
|
2520 |
+
|
2521 |
+
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
2522 |
+
|
2523 |
+
if ($download['slug'] == $wp_plugin_slug) {
|
2524 |
+
$plugin_repository = $repository_id;
|
2525 |
+
$product_name = $repository['data']['product-name'];
|
2526 |
+
$plugin_name = $download['name'];
|
2527 |
+
$free_on_wporg = !empty($download['free-on-wporg']);
|
2528 |
+
break;
|
2529 |
+
}
|
2530 |
+
|
2531 |
+
}
|
2532 |
+
|
2533 |
+
}
|
2534 |
+
|
2535 |
+
}
|
2536 |
+
|
2537 |
+
}
|
2538 |
+
|
2539 |
+
if ($plugin_repository) {
|
2540 |
+
|
2541 |
+
//validate subscription
|
2542 |
+
static $sub_cache = array();
|
2543 |
+
|
2544 |
+
if(empty($sub_cache[$plugin_repository])){
|
2545 |
+
$site_key = $this->get_repository_site_key($plugin_repository);
|
2546 |
+
if ($site_key) {
|
2547 |
+
$subscription_data = $this->fetch_subscription_data( $plugin_repository, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION );
|
2548 |
+
}
|
2549 |
+
|
2550 |
+
$sub_cache[$plugin_repository]['site_key'] = $site_key;
|
2551 |
+
$sub_cache[$plugin_repository]['subscription_data'] = isset($subscription_data) ? $subscription_data : false;
|
2552 |
+
}else{
|
2553 |
+
|
2554 |
+
$site_key = $sub_cache[$plugin_repository]['site_key'];
|
2555 |
+
$subscription_data = $sub_cache[$plugin_repository]['subscription_data'];
|
2556 |
+
|
2557 |
+
}
|
2558 |
+
|
2559 |
+
if(!$site_key && !empty($free_on_wporg)){ // allow the download from wp.org
|
2560 |
+
continue;
|
2561 |
+
}
|
2562 |
+
|
2563 |
+
if (empty($site_key) || empty($subscription_data)) {
|
2564 |
+
|
2565 |
+
|
2566 |
+
$error_message = sprintf(__("%s cannot update because your site's registration is not valid. Please %sregister %s%s again for this site first.", 'installer'),
|
2567 |
+
'<strong>' . $plugin_name . '</strong>', '<a target="_top" href="' . $this->menu_url() . '&validate_repository=' . $plugin_repository .
|
2568 |
+
'#repository-' . $plugin_repository . '">', $product_name, '</a>');
|
2569 |
+
|
2570 |
+
echo '<div class="updated error"><p>' . $error_message . '</p></div>';
|
2571 |
+
|
2572 |
+
unset($plugins[$k]);
|
2573 |
+
|
2574 |
+
|
2575 |
+
}
|
2576 |
+
|
2577 |
+
}
|
2578 |
+
|
2579 |
+
}
|
2580 |
+
|
2581 |
+
}
|
2582 |
+
|
2583 |
+
}
|
2584 |
+
|
2585 |
+
|
2586 |
+
if( 'upgrade-plugin' == $action || 'update-plugin' == $action ) {
|
2587 |
+
|
2588 |
+
$plugin = isset($_REQUEST['plugin']) ? trim( sanitize_text_field ( $_REQUEST['plugin'] ) ) : '';
|
2589 |
+
|
2590 |
+
$wp_plugin_slug = dirname($plugin);
|
2591 |
+
|
2592 |
+
$plugin_repository = false;
|
2593 |
+
|
2594 |
+
foreach($this->settings['repositories'] as $repository_id => $repository){
|
2595 |
+
|
2596 |
+
foreach($repository['data']['packages'] as $package){
|
2597 |
+
|
2598 |
+
foreach($package['products'] as $product){
|
2599 |
+
|
2600 |
+
foreach($product['plugins'] as $plugin_slug){
|
2601 |
+
$download = $this->settings['repositories'][$repository_id]['data']['downloads']['plugins'][$plugin_slug];
|
2602 |
+
|
2603 |
+
//match by folder, will change to match by name and folder
|
2604 |
+
if($download['slug'] == $wp_plugin_slug) {
|
2605 |
+
$plugin_repository = $repository_id;
|
2606 |
+
$product_name = $repository['data']['product-name'];
|
2607 |
+
$plugin_name = $download['name'];
|
2608 |
+
$free_on_wporg = !empty($download['free-on-wporg']);
|
2609 |
+
break;
|
2610 |
+
}
|
2611 |
+
|
2612 |
+
}
|
2613 |
+
|
2614 |
+
}
|
2615 |
+
|
2616 |
+
}
|
2617 |
+
|
2618 |
+
}
|
2619 |
+
|
2620 |
+
if($plugin_repository) {
|
2621 |
+
|
2622 |
+
//validate subscription
|
2623 |
+
$site_key = $this->get_repository_site_key($plugin_repository);
|
2624 |
+
if ($site_key) {
|
2625 |
+
$subscription_data = $this->fetch_subscription_data( $plugin_repository, $site_key, self::SITE_KEY_VALIDATION_SOURCE_REVALIDATION );
|
2626 |
+
}
|
2627 |
+
|
2628 |
+
if ( (empty($site_key) || empty($subscription_data)) && empty($free_on_wporg)) {
|
2629 |
+
|
2630 |
+
$error_message = sprintf(__("%s cannot update because your site's registration is not valid. Please %sregister %s%s again for this site first.", 'installer'),
|
2631 |
+
'<strong>'.$plugin_name . '</strong>', '<a href="' . $this->menu_url() . '&validate_repository=' . $plugin_repository .
|
2632 |
+
'#repository-' . $plugin_repository . '">', $product_name, '</a>');
|
2633 |
+
|
2634 |
+
if(defined('DOING_AJAX')){ //WP 4.2
|
2635 |
+
|
2636 |
+
$status = array(
|
2637 |
+
'update' => 'plugin',
|
2638 |
+
'plugin' => $plugin,
|
2639 |
+
'slug' => sanitize_key( $_POST['slug'] ),
|
2640 |
+
'oldVersion' => '',
|
2641 |
+
'newVersion' => '',
|
2642 |
+
);
|
2643 |
+
|
2644 |
+
$status['errorCode'] = 'wp_installer_invalid_subscription';
|
2645 |
+
$status['error'] = $error_message;
|
2646 |
+
|
2647 |
+
wp_send_json_error( $status );
|
2648 |
+
|
2649 |
+
} else { // WP 4.1.1
|
2650 |
+
echo '<div class="updated error"><p>' . $error_message . '</p></div>';
|
2651 |
+
|
2652 |
+
|
2653 |
+
echo '<div class="wrap">';
|
2654 |
+
echo '<h2>' . __('Update Plugin') . '</h2>';
|
2655 |
+
echo '<a href="' . admin_url('plugins.php') . '">' . __('Return to the plugins page') . '</a>';
|
2656 |
+
echo '</div>';
|
2657 |
+
require_once(ABSPATH . 'wp-admin/admin-footer.php');
|
2658 |
+
exit;
|
2659 |
+
|
2660 |
+
}
|
2661 |
+
|
2662 |
+
}
|
2663 |
+
|
2664 |
+
|
2665 |
+
}
|
2666 |
+
|
2667 |
+
}
|
2668 |
+
}
|
2669 |
+
|
2670 |
+
}
|
2671 |
+
|
2672 |
+
}
|
library/otgs/installer/includes/translation-service-info.class.php
CHANGED
@@ -1,40 +1,40 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class TranslationServiceInfo{
|
4 |
-
|
5 |
-
function __construct(){
|
6 |
-
|
7 |
-
add_action('installer_fetched_subscription_data',array($this, 'save_info'), 10, 2);
|
8 |
-
|
9 |
-
}
|
10 |
-
|
11 |
-
function save_info($data, $repository_id) {
|
12 |
-
|
13 |
-
$ts_info = isset( WP_Installer()->settings['repositories'][$repository_id]['ts_info'] ) ?
|
14 |
-
WP_Installer()->settings['repositories'][$repository_id]['ts_info'] : false;
|
15 |
-
|
16 |
-
$save_settings = false;
|
17 |
-
if(isset($data->ts_info['preferred']) && empty($ts_info['preferred'])){
|
18 |
-
WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'] = $data->ts_info['preferred'];
|
19 |
-
$save_settings = true;
|
20 |
-
}
|
21 |
-
|
22 |
-
if(isset($data->ts_info['referal']) && empty($ts_info['referal'])){
|
23 |
-
WP_Installer()->settings['repositories'][$repository_id]['ts_info']['referal'] = $data->ts_info['referal'];
|
24 |
-
$save_settings = true;
|
25 |
-
}
|
26 |
-
|
27 |
-
if ( !empty( $data->ts_info['client_id'] ) ) { // can be updated
|
28 |
-
WP_Installer()->settings['repositories'][$repository_id]['ts_info']['client_id'] = $data->ts_info['client_id'];
|
29 |
-
$save_settings = true;
|
30 |
-
}
|
31 |
-
|
32 |
-
if($save_settings){
|
33 |
-
WP_Installer()->save_settings();
|
34 |
-
}
|
35 |
-
|
36 |
-
}
|
37 |
-
|
38 |
-
}
|
39 |
-
|
40 |
new TranslationServiceInfo();
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class TranslationServiceInfo{
|
4 |
+
|
5 |
+
function __construct(){
|
6 |
+
|
7 |
+
add_action('installer_fetched_subscription_data',array($this, 'save_info'), 10, 2);
|
8 |
+
|
9 |
+
}
|
10 |
+
|
11 |
+
function save_info($data, $repository_id) {
|
12 |
+
|
13 |
+
$ts_info = isset( WP_Installer()->settings['repositories'][$repository_id]['ts_info'] ) ?
|
14 |
+
WP_Installer()->settings['repositories'][$repository_id]['ts_info'] : false;
|
15 |
+
|
16 |
+
$save_settings = false;
|
17 |
+
if(isset($data->ts_info['preferred']) && empty($ts_info['preferred'])){
|
18 |
+
WP_Installer()->settings['repositories'][$repository_id]['ts_info']['preferred'] = $data->ts_info['preferred'];
|
19 |
+
$save_settings = true;
|
20 |
+
}
|
21 |
+
|
22 |
+
if(isset($data->ts_info['referal']) && empty($ts_info['referal'])){
|
23 |
+
WP_Installer()->settings['repositories'][$repository_id]['ts_info']['referal'] = $data->ts_info['referal'];
|
24 |
+
$save_settings = true;
|
25 |
+
}
|
26 |
+
|
27 |
+
if ( !empty( $data->ts_info['client_id'] ) ) { // can be updated
|
28 |
+
WP_Installer()->settings['repositories'][$repository_id]['ts_info']['client_id'] = $data->ts_info['client_id'];
|
29 |
+
$save_settings = true;
|
30 |
+
}
|
31 |
+
|
32 |
+
if($save_settings){
|
33 |
+
WP_Installer()->save_settings();
|
34 |
+
}
|
35 |
+
|
36 |
+
}
|
37 |
+
|
38 |
+
}
|
39 |
+
|
40 |
new TranslationServiceInfo();
|
library/otgs/installer/installer.php
CHANGED
@@ -1,22 +1,22 @@
|
|
1 |
-
<?php
|
2 |
-
define('WP_INSTALLER_VERSION', '1.7.13');
|
3 |
-
|
4 |
-
include_once dirname(__FILE__) . '/includes/installer.class.php';
|
5 |
-
|
6 |
-
function WP_Installer() {
|
7 |
-
return WP_Installer::instance();
|
8 |
-
}
|
9 |
-
|
10 |
-
|
11 |
-
WP_Installer();
|
12 |
-
|
13 |
-
include_once WP_Installer()->plugin_path() . '/includes/installer-api.php';
|
14 |
-
include_once WP_Installer()->plugin_path() . '/includes/translation-service-info.class.php';
|
15 |
-
include_once WP_Installer()->plugin_path() . '/includes/class-installer-dependencies.php';
|
16 |
-
|
17 |
-
// Ext function
|
18 |
-
function WP_Installer_Show_Products($args = array()){
|
19 |
-
|
20 |
-
WP_Installer()->show_products($args);
|
21 |
-
|
22 |
}
|
1 |
+
<?php
|
2 |
+
define('WP_INSTALLER_VERSION', '1.7.13');
|
3 |
+
|
4 |
+
include_once dirname(__FILE__) . '/includes/installer.class.php';
|
5 |
+
|
6 |
+
function WP_Installer() {
|
7 |
+
return WP_Installer::instance();
|
8 |
+
}
|
9 |
+
|
10 |
+
|
11 |
+
WP_Installer();
|
12 |
+
|
13 |
+
include_once WP_Installer()->plugin_path() . '/includes/installer-api.php';
|
14 |
+
include_once WP_Installer()->plugin_path() . '/includes/translation-service-info.class.php';
|
15 |
+
include_once WP_Installer()->plugin_path() . '/includes/class-installer-dependencies.php';
|
16 |
+
|
17 |
+
// Ext function
|
18 |
+
function WP_Installer_Show_Products($args = array()){
|
19 |
+
|
20 |
+
WP_Installer()->show_products($args);
|
21 |
+
|
22 |
}
|
library/otgs/installer/loader.php
CHANGED
@@ -1,151 +1,151 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
4 |
-
exit; // Exit if accessed directly
|
5 |
-
}
|
6 |
-
|
7 |
-
//It should only be loaded on the admin side
|
8 |
-
if( !is_admin() ){
|
9 |
-
if(!function_exists('WP_Installer_Setup')){ function WP_Installer_Setup(){} }
|
10 |
-
$wp_installer_instance = null;
|
11 |
-
return;
|
12 |
-
}
|
13 |
-
|
14 |
-
|
15 |
-
$wp_installer_instance = dirname(__FILE__) . '/installer.php';
|
16 |
-
|
17 |
-
|
18 |
-
// Global stack of instances
|
19 |
-
global $wp_installer_instances;
|
20 |
-
$wp_installer_instances[$wp_installer_instance] = array(
|
21 |
-
'bootfile' => $wp_installer_instance,
|
22 |
-
'version' => '1.7.13'
|
23 |
-
);
|
24 |
-
|
25 |
-
|
26 |
-
/* EXCEPTIONS ********************************************************************************************/
|
27 |
-
// Exception: When WPML prior 3.2 is used, that instance must be used regardless of another newer instance
|
28 |
-
// Case 1: WPML loaded before Types - eliminate other instances
|
29 |
-
if( defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.2', '<') ) {
|
30 |
-
foreach($wp_installer_instances as $key => $instance) {
|
31 |
-
if(isset($instance['args']['site_key_nags'])){
|
32 |
-
$wp_installer_instances[$key]['version'] = '9.9';
|
33 |
-
}else{
|
34 |
-
$wp_installer_instances[$key]['version'] = '0';
|
35 |
-
}
|
36 |
-
}
|
37 |
-
}
|
38 |
-
|
39 |
-
// Exception: Types 1.8.9 (Installer 1.7.0) with WPML before 3.3 (Installer before 1.7.0)
|
40 |
-
// New products file http://d2salfytceyqoe.cloudfront.net/wpml-products33.json overrides the old one
|
41 |
-
// while the WPML's instance is being used
|
42 |
-
// => Force using the new Installer Instance
|
43 |
-
if( defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.3.1', '<') ) {
|
44 |
-
|
45 |
-
// if Installer 1.7.0+ is present, unregister Installer from old WPML
|
46 |
-
// Force Installer 1.7.0+ being used over older Installer versions
|
47 |
-
$installer_171_plus_on = false;
|
48 |
-
foreach($wp_installer_instances as $key => $instance) {
|
49 |
-
if( version_compare( $instance['version'], '1.7.1', '>=' ) ){
|
50 |
-
$installer_171_plus_on = true;
|
51 |
-
break;
|
52 |
-
}
|
53 |
-
}
|
54 |
-
|
55 |
-
if( $installer_171_plus_on ){
|
56 |
-
foreach($wp_installer_instances as $key => $instance) {
|
57 |
-
|
58 |
-
if( version_compare( $instance['version'], '1.7.0', '<' ) ){
|
59 |
-
unset( $wp_installer_instances[$key] );
|
60 |
-
}
|
61 |
-
|
62 |
-
}
|
63 |
-
}
|
64 |
-
|
65 |
-
}
|
66 |
-
|
67 |
-
// Exception: When using the embedded plugins module allow the set up to run completely with the
|
68 |
-
// Installer instance that triggers it
|
69 |
-
if( isset( $_POST['installer_instance'] ) && isset( $wp_installer_instances[$_POST['installer_instance']] ) ){
|
70 |
-
$wp_installer_instances[$_POST['installer_instance']]['version'] = '999';
|
71 |
-
}
|
72 |
-
/* EXCEPTIONS ********************************************************************************************/
|
73 |
-
|
74 |
-
|
75 |
-
// Only one of these in the end
|
76 |
-
remove_action('after_setup_theme', 'wpml_installer_instance_delegator', 1);
|
77 |
-
add_action('after_setup_theme', 'wpml_installer_instance_delegator', 1);
|
78 |
-
|
79 |
-
// When all plugins load pick the newest version
|
80 |
-
if(!function_exists('wpml_installer_instance_delegator')){
|
81 |
-
function wpml_installer_instance_delegator(){
|
82 |
-
global $wp_installer_instances;
|
83 |
-
|
84 |
-
// version based election
|
85 |
-
foreach($wp_installer_instances as $instance){
|
86 |
-
|
87 |
-
if(!isset($delegate)){
|
88 |
-
$delegate = $instance;
|
89 |
-
continue;
|
90 |
-
}
|
91 |
-
|
92 |
-
if(version_compare($instance['version'], $delegate['version'], '>')){
|
93 |
-
$delegate = $instance;
|
94 |
-
}
|
95 |
-
}
|
96 |
-
|
97 |
-
// priority based election
|
98 |
-
$highest_priority = null;
|
99 |
-
foreach($wp_installer_instances as $instance) {
|
100 |
-
if(isset($instance['args']['high_priority'])){
|
101 |
-
if(is_null($highest_priority) || $instance['args']['high_priority'] <= $highest_priority){
|
102 |
-
$highest_priority = $instance['args']['high_priority'];
|
103 |
-
$delegate = $instance;
|
104 |
-
}
|
105 |
-
}
|
106 |
-
}
|
107 |
-
|
108 |
-
// Exception: When WPML prior 3.2 is used, that instance must be used regardless of another newer instance
|
109 |
-
// Case 2: WPML loaded after Types
|
110 |
-
if( defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.2', '<') ) {
|
111 |
-
foreach($wp_installer_instances as $key => $instance) {
|
112 |
-
if(isset($instance['args']['site_key_nags'])){
|
113 |
-
$delegate = $instance;
|
114 |
-
$wp_installer_instances = array($key => $delegate); //Eliminate other instances
|
115 |
-
break;
|
116 |
-
}
|
117 |
-
}
|
118 |
-
}
|
119 |
-
|
120 |
-
include_once $delegate['bootfile'];
|
121 |
-
|
122 |
-
// set configuration
|
123 |
-
if(strpos(realpath($delegate['bootfile']), realpath(TEMPLATEPATH)) === 0){
|
124 |
-
$delegate['args']['in_theme_folder'] = dirname(ltrim(str_replace(realpath(TEMPLATEPATH), '', realpath($delegate['bootfile'])), '\\/'));
|
125 |
-
}
|
126 |
-
if(isset($delegate['args']) && is_array($delegate['args'])){
|
127 |
-
foreach($delegate['args'] as $key => $value){
|
128 |
-
WP_Installer()->set_config($key, $value);
|
129 |
-
}
|
130 |
-
}
|
131 |
-
|
132 |
-
}
|
133 |
-
}
|
134 |
-
|
135 |
-
if(!function_exists('WP_Installer_Setup')){
|
136 |
-
|
137 |
-
// $args:
|
138 |
-
// plugins_install_tab = true|false (default: true)
|
139 |
-
// repositories_include = array() (default: all)
|
140 |
-
// repositories_exclude = array() (default: none)
|
141 |
-
// template = name (default: default)
|
142 |
-
//
|
143 |
-
// Ext function
|
144 |
-
function WP_Installer_Setup($wp_installer_instance, $args = array()){
|
145 |
-
global $wp_installer_instances;
|
146 |
-
|
147 |
-
$wp_installer_instances[$wp_installer_instance]['args'] = $args;
|
148 |
-
|
149 |
-
}
|
150 |
-
|
151 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
4 |
+
exit; // Exit if accessed directly
|
5 |
+
}
|
6 |
+
|
7 |
+
//It should only be loaded on the admin side
|
8 |
+
if( !is_admin() ){
|
9 |
+
if(!function_exists('WP_Installer_Setup')){ function WP_Installer_Setup(){} }
|
10 |
+
$wp_installer_instance = null;
|
11 |
+
return;
|
12 |
+
}
|
13 |
+
|
14 |
+
|
15 |
+
$wp_installer_instance = dirname(__FILE__) . '/installer.php';
|
16 |
+
|
17 |
+
|
18 |
+
// Global stack of instances
|
19 |
+
global $wp_installer_instances;
|
20 |
+
$wp_installer_instances[$wp_installer_instance] = array(
|
21 |
+
'bootfile' => $wp_installer_instance,
|
22 |
+
'version' => '1.7.13'
|
23 |
+
);
|
24 |
+
|
25 |
+
|
26 |
+
/* EXCEPTIONS ********************************************************************************************/
|
27 |
+
// Exception: When WPML prior 3.2 is used, that instance must be used regardless of another newer instance
|
28 |
+
// Case 1: WPML loaded before Types - eliminate other instances
|
29 |
+
if( defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.2', '<') ) {
|
30 |
+
foreach($wp_installer_instances as $key => $instance) {
|
31 |
+
if(isset($instance['args']['site_key_nags'])){
|
32 |
+
$wp_installer_instances[$key]['version'] = '9.9';
|
33 |
+
}else{
|
34 |
+
$wp_installer_instances[$key]['version'] = '0';
|
35 |
+
}
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
// Exception: Types 1.8.9 (Installer 1.7.0) with WPML before 3.3 (Installer before 1.7.0)
|
40 |
+
// New products file http://d2salfytceyqoe.cloudfront.net/wpml-products33.json overrides the old one
|
41 |
+
// while the WPML's instance is being used
|
42 |
+
// => Force using the new Installer Instance
|
43 |
+
if( defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.3.1', '<') ) {
|
44 |
+
|
45 |
+
// if Installer 1.7.0+ is present, unregister Installer from old WPML
|
46 |
+
// Force Installer 1.7.0+ being used over older Installer versions
|
47 |
+
$installer_171_plus_on = false;
|
48 |
+
foreach($wp_installer_instances as $key => $instance) {
|
49 |
+
if( version_compare( $instance['version'], '1.7.1', '>=' ) ){
|
50 |
+
$installer_171_plus_on = true;
|
51 |
+
break;
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
if( $installer_171_plus_on ){
|
56 |
+
foreach($wp_installer_instances as $key => $instance) {
|
57 |
+
|
58 |
+
if( version_compare( $instance['version'], '1.7.0', '<' ) ){
|
59 |
+
unset( $wp_installer_instances[$key] );
|
60 |
+
}
|
61 |
+
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
}
|
66 |
+
|
67 |
+
// Exception: When using the embedded plugins module allow the set up to run completely with the
|
68 |
+
// Installer instance that triggers it
|
69 |
+
if( isset( $_POST['installer_instance'] ) && isset( $wp_installer_instances[$_POST['installer_instance']] ) ){
|
70 |
+
$wp_installer_instances[$_POST['installer_instance']]['version'] = '999';
|
71 |
+
}
|
72 |
+
/* EXCEPTIONS ********************************************************************************************/
|
73 |
+
|
74 |
+
|
75 |
+
// Only one of these in the end
|
76 |
+
remove_action('after_setup_theme', 'wpml_installer_instance_delegator', 1);
|
77 |
+
add_action('after_setup_theme', 'wpml_installer_instance_delegator', 1);
|
78 |
+
|
79 |
+
// When all plugins load pick the newest version
|
80 |
+
if(!function_exists('wpml_installer_instance_delegator')){
|
81 |
+
function wpml_installer_instance_delegator(){
|
82 |
+
global $wp_installer_instances;
|
83 |
+
|
84 |
+
// version based election
|
85 |
+
foreach($wp_installer_instances as $instance){
|
86 |
+
|
87 |
+
if(!isset($delegate)){
|
88 |
+
$delegate = $instance;
|
89 |
+
continue;
|
90 |
+
}
|
91 |
+
|
92 |
+
if(version_compare($instance['version'], $delegate['version'], '>')){
|
93 |
+
$delegate = $instance;
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
// priority based election
|
98 |
+
$highest_priority = null;
|
99 |
+
foreach($wp_installer_instances as $instance) {
|
100 |
+
if(isset($instance['args']['high_priority'])){
|
101 |
+
if(is_null($highest_priority) || $instance['args']['high_priority'] <= $highest_priority){
|
102 |
+
$highest_priority = $instance['args']['high_priority'];
|
103 |
+
$delegate = $instance;
|
104 |
+
}
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
// Exception: When WPML prior 3.2 is used, that instance must be used regardless of another newer instance
|
109 |
+
// Case 2: WPML loaded after Types
|
110 |
+
if( defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.2', '<') ) {
|
111 |
+
foreach($wp_installer_instances as $key => $instance) {
|
112 |
+
if(isset($instance['args']['site_key_nags'])){
|
113 |
+
$delegate = $instance;
|
114 |
+
$wp_installer_instances = array($key => $delegate); //Eliminate other instances
|
115 |
+
break;
|
116 |
+
}
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
120 |
+
include_once $delegate['bootfile'];
|
121 |
+
|
122 |
+
// set configuration
|
123 |
+
if(strpos(realpath($delegate['bootfile']), realpath(TEMPLATEPATH)) === 0){
|
124 |
+
$delegate['args']['in_theme_folder'] = dirname(ltrim(str_replace(realpath(TEMPLATEPATH), '', realpath($delegate['bootfile'])), '\\/'));
|
125 |
+
}
|
126 |
+
if(isset($delegate['args']) && is_array($delegate['args'])){
|
127 |
+
foreach($delegate['args'] as $key => $value){
|
128 |
+
WP_Installer()->set_config($key, $value);
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
if(!function_exists('WP_Installer_Setup')){
|
136 |
+
|
137 |
+
// $args:
|
138 |
+
// plugins_install_tab = true|false (default: true)
|
139 |
+
// repositories_include = array() (default: all)
|
140 |
+
// repositories_exclude = array() (default: none)
|
141 |
+
// template = name (default: default)
|
142 |
+
//
|
143 |
+
// Ext function
|
144 |
+
function WP_Installer_Setup($wp_installer_instance, $args = array()){
|
145 |
+
global $wp_installer_instances;
|
146 |
+
|
147 |
+
$wp_installer_instances[$wp_installer_instance]['args'] = $args;
|
148 |
+
|
149 |
+
}
|
150 |
+
|
151 |
}
|
library/otgs/installer/locale/orig/installer.po
CHANGED
@@ -1,230 +1,230 @@
|
|
1 |
-
# This file was generated by WPML
|
2 |
-
# WPML is a WordPress plugin that can turn any WordPress site into a full featured multilingual content management system.
|
3 |
-
# https://wpml.org
|
4 |
-
msgid ""
|
5 |
-
msgstr ""
|
6 |
-
"Content-Type: text/plain; charset=utf-8\n"
|
7 |
-
"Content-Transfer-Encoding: 8bit\n"
|
8 |
-
"Project-Id-Version:WPML_EXPORT\n"
|
9 |
-
"POT-Creation-Date: \n"
|
10 |
-
"PO-Revision-Date: \n"
|
11 |
-
"Last-Translator: \n"
|
12 |
-
"Language-Team: \n"
|
13 |
-
"Language:en\n"
|
14 |
-
"MIME-Version: 1.0\n"
|
15 |
-
|
16 |
-
msgid "Installer"
|
17 |
-
msgstr ""
|
18 |
-
|
19 |
-
msgid "Registered"
|
20 |
-
msgstr ""
|
21 |
-
|
22 |
-
msgid "Register"
|
23 |
-
msgstr ""
|
24 |
-
|
25 |
-
msgid "To get automatic updates, you need to register %s for this site. %sRegister %s%s"
|
26 |
-
msgstr ""
|
27 |
-
|
28 |
-
msgid "Dismiss"
|
29 |
-
msgstr ""
|
30 |
-
|
31 |
-
msgid "Commercial"
|
32 |
-
msgstr ""
|
33 |
-
|
34 |
-
msgid "Installer cannot contact our updates server to get information about the available products and check for new versions. If you are seeing this message for the first time, you can ignore it, as it may be a temporary communication problem. If the problem persists and your WordPress admin is slowing down, you can disable automated version checks. Add the following line to your wp-config.php file:"
|
35 |
-
msgstr ""
|
36 |
-
|
37 |
-
msgid "No repositories defined."
|
38 |
-
msgstr ""
|
39 |
-
|
40 |
-
msgid "%s cannot access %s to register. Try again to see if it's a temporary problem. If the problem continues, make sure that this site has access to the Internet. You can still use the plugin without registration, but you will not receive automated updates."
|
41 |
-
msgstr ""
|
42 |
-
|
43 |
-
msgid "Invalid site key for the current site."
|
44 |
-
msgstr ""
|
45 |
-
|
46 |
-
msgid "You will have to renew your subscription in order to continue getting the updates and support."
|
47 |
-
msgstr ""
|
48 |
-
|
49 |
-
msgid "%sRenew here%s."
|
50 |
-
msgstr ""
|
51 |
-
|
52 |
-
msgid "Your subscription appears to no longer be valid. Please try to register again using a valid site key."
|
53 |
-
msgstr ""
|
54 |
-
|
55 |
-
msgid "You need to have a valid subscription in order to get upgrades or support for this plugin. %sPurchase a subscription or enter an existing site key%s."
|
56 |
-
msgstr ""
|
57 |
-
|
58 |
-
msgid "%s cannot update because your site's registration is not valid. Please %sregister %s%s again for this site first."
|
59 |
-
msgstr ""
|
60 |
-
|
61 |
-
msgid "Update Plugin"
|
62 |
-
msgstr ""
|
63 |
-
|
64 |
-
msgid "Return to the plugins page"
|
65 |
-
msgstr ""
|
66 |
-
|
67 |
-
msgid "Your subscription expires in %d day."
|
68 |
-
msgstr ""
|
69 |
-
|
70 |
-
msgid "Your subscription expires in %d days."
|
71 |
-
msgstr ""
|
72 |
-
|
73 |
-
msgid "Downloading is not possible because WordPress cannot write into the plugins folder. %sHow to fix%s."
|
74 |
-
msgstr ""
|
75 |
-
|
76 |
-
msgid "Plugin"
|
77 |
-
msgstr ""
|
78 |
-
|
79 |
-
msgid "downloading..."
|
80 |
-
msgstr ""
|
81 |
-
|
82 |
-
msgid "failed!"
|
83 |
-
msgstr ""
|
84 |
-
|
85 |
-
msgid "downloaded"
|
86 |
-
msgstr ""
|
87 |
-
|
88 |
-
msgid "activating"
|
89 |
-
msgstr ""
|
90 |
-
|
91 |
-
msgid "activated"
|
92 |
-
msgstr ""
|
93 |
-
|
94 |
-
msgid "Activate after download"
|
95 |
-
msgstr ""
|
96 |
-
|
97 |
-
msgid "Operation complete!"
|
98 |
-
msgstr ""
|
99 |
-
|
100 |
-
msgid "Download failed!\n\nClick OK to revalidate your subscription or CANCEL to try again."
|
101 |
-
msgstr ""
|
102 |
-
|
103 |
-
msgid "Available"
|
104 |
-
msgstr ""
|
105 |
-
|
106 |
-
msgid "Installed"
|
107 |
-
msgstr ""
|
108 |
-
|
109 |
-
msgid "Downloading"
|
110 |
-
msgstr ""
|
111 |
-
|
112 |
-
msgid "Activate"
|
113 |
-
msgstr ""
|
114 |
-
|
115 |
-
msgid "Download"
|
116 |
-
msgstr ""
|
117 |
-
|
118 |
-
msgid "Downloads:"
|
119 |
-
msgstr ""
|
120 |
-
|
121 |
-
msgid "Current version"
|
122 |
-
msgstr ""
|
123 |
-
|
124 |
-
msgid "Released"
|
125 |
-
msgstr ""
|
126 |
-
|
127 |
-
msgid "Installed version"
|
128 |
-
msgstr ""
|
129 |
-
|
130 |
-
msgid "(embedded)"
|
131 |
-
msgstr ""
|
132 |
-
|
133 |
-
msgid "installing..."
|
134 |
-
msgstr ""
|
135 |
-
|
136 |
-
msgid "updating..."
|
137 |
-
msgstr ""
|
138 |
-
|
139 |
-
msgid "installed"
|
140 |
-
msgstr ""
|
141 |
-
|
142 |
-
msgid "updated"
|
143 |
-
msgstr ""
|
144 |
-
|
145 |
-
msgid "Download failed!\n\nPlease refresh the page and try again."
|
146 |
-
msgstr ""
|
147 |
-
|
148 |
-
msgid "Incorrect setup"
|
149 |
-
msgstr ""
|
150 |
-
|
151 |
-
msgid "Invalid product"
|
152 |
-
msgstr ""
|
153 |
-
|
154 |
-
msgid "Unknown repository"
|
155 |
-
msgstr ""
|
156 |
-
|
157 |
-
msgid " Your current site key (%s) does not match the selected product (%s)."
|
158 |
-
msgstr ""
|
159 |
-
|
160 |
-
msgid "Buy %s"
|
161 |
-
msgstr ""
|
162 |
-
|
163 |
-
msgid "Already bought %s?"
|
164 |
-
msgstr ""
|
165 |
-
|
166 |
-
msgid "Renew %s"
|
167 |
-
msgstr ""
|
168 |
-
|
169 |
-
msgid "Remove current site key (%s)"
|
170 |
-
msgstr ""
|
171 |
-
|
172 |
-
msgid "%s support on wpml.org"
|
173 |
-
msgstr ""
|
174 |
-
|
175 |
-
msgid "Enter site key"
|
176 |
-
msgstr ""
|
177 |
-
|
178 |
-
msgid "Subscription is expired."
|
179 |
-
msgstr ""
|
180 |
-
|
181 |
-
msgid "Add"
|
182 |
-
msgstr ""
|
183 |
-
|
184 |
-
msgid "Are you sure you want to remove this site key?"
|
185 |
-
msgstr ""
|
186 |
-
|
187 |
-
msgid "Register %s"
|
188 |
-
msgstr ""
|
189 |
-
|
190 |
-
msgid "1. Go to your %s%s account%s and add this site URL: %s"
|
191 |
-
msgstr ""
|
192 |
-
|
193 |
-
msgid "Unregister %s from this site"
|
194 |
-
msgstr ""
|
195 |
-
|
196 |
-
msgid "%s is registered on this site. You will receive automatic updates until %s"
|
197 |
-
msgstr ""
|
198 |
-
|
199 |
-
msgid "%s is registered on this site. Your Lifetime account gives you updates for life."
|
200 |
-
msgstr ""
|
201 |
-
|
202 |
-
msgid "This page lets you install plugins and update existing plugins. To remove any of these plugins, go to the %splugins%s page and if you have the permission to remove plugins you should be able to do this."
|
203 |
-
msgstr ""
|
204 |
-
|
205 |
-
msgid "Already bought?"
|
206 |
-
msgstr ""
|
207 |
-
|
208 |
-
msgid "2. Enter your site key"
|
209 |
-
msgstr ""
|
210 |
-
|
211 |
-
msgid "Subscription is expired. You need to either purchase a new subscription or upgrade if available."
|
212 |
-
msgstr ""
|
213 |
-
|
214 |
-
msgid "Check for updates"
|
215 |
-
msgstr ""
|
216 |
-
|
217 |
-
msgid "Individual components"
|
218 |
-
msgstr ""
|
219 |
-
|
220 |
-
msgid "OK"
|
221 |
-
msgstr ""
|
222 |
-
|
223 |
-
msgid "Cancel"
|
224 |
-
msgstr ""
|
225 |
-
|
226 |
-
msgid "Are you sure you want to unregister?"
|
227 |
-
msgstr ""
|
228 |
-
|
229 |
-
msgid "Click to see individual components options."
|
230 |
-
msgstr ""
|
1 |
+
# This file was generated by WPML
|
2 |
+
# WPML is a WordPress plugin that can turn any WordPress site into a full featured multilingual content management system.
|
3 |
+
# https://wpml.org
|
4 |
+
msgid ""
|
5 |
+
msgstr ""
|
6 |
+
"Content-Type: text/plain; charset=utf-8\n"
|
7 |
+
"Content-Transfer-Encoding: 8bit\n"
|
8 |
+
"Project-Id-Version:WPML_EXPORT\n"
|
9 |
+
"POT-Creation-Date: \n"
|
10 |
+
"PO-Revision-Date: \n"
|
11 |
+
"Last-Translator: \n"
|
12 |
+
"Language-Team: \n"
|
13 |
+
"Language:en\n"
|
14 |
+
"MIME-Version: 1.0\n"
|
15 |
+
|
16 |
+
msgid "Installer"
|
17 |
+
msgstr ""
|
18 |
+
|
19 |
+
msgid "Registered"
|
20 |
+
msgstr ""
|
21 |
+
|
22 |
+
msgid "Register"
|
23 |
+
msgstr ""
|
24 |
+
|
25 |
+
msgid "To get automatic updates, you need to register %s for this site. %sRegister %s%s"
|
26 |
+
msgstr ""
|
27 |
+
|
28 |
+
msgid "Dismiss"
|
29 |
+
msgstr ""
|
30 |
+
|
31 |
+
msgid "Commercial"
|
32 |
+
msgstr ""
|
33 |
+
|
34 |
+
msgid "Installer cannot contact our updates server to get information about the available products and check for new versions. If you are seeing this message for the first time, you can ignore it, as it may be a temporary communication problem. If the problem persists and your WordPress admin is slowing down, you can disable automated version checks. Add the following line to your wp-config.php file:"
|
35 |
+
msgstr ""
|
36 |
+
|
37 |
+
msgid "No repositories defined."
|
38 |
+
msgstr ""
|
39 |
+
|
40 |
+
msgid "%s cannot access %s to register. Try again to see if it's a temporary problem. If the problem continues, make sure that this site has access to the Internet. You can still use the plugin without registration, but you will not receive automated updates."
|
41 |
+
msgstr ""
|
42 |
+
|
43 |
+
msgid "Invalid site key for the current site."
|
44 |
+
msgstr ""
|
45 |
+
|
46 |
+
msgid "You will have to renew your subscription in order to continue getting the updates and support."
|
47 |
+
msgstr ""
|
48 |
+
|
49 |
+
msgid "%sRenew here%s."
|
50 |
+
msgstr ""
|
51 |
+
|
52 |
+
msgid "Your subscription appears to no longer be valid. Please try to register again using a valid site key."
|
53 |
+
msgstr ""
|
54 |
+
|
55 |
+
msgid "You need to have a valid subscription in order to get upgrades or support for this plugin. %sPurchase a subscription or enter an existing site key%s."
|
56 |
+
msgstr ""
|
57 |
+
|
58 |
+
msgid "%s cannot update because your site's registration is not valid. Please %sregister %s%s again for this site first."
|
59 |
+
msgstr ""
|
60 |
+
|
61 |
+
msgid "Update Plugin"
|
62 |
+
msgstr ""
|
63 |
+
|
64 |
+
msgid "Return to the plugins page"
|
65 |
+
msgstr ""
|
66 |
+
|
67 |
+
msgid "Your subscription expires in %d day."
|
68 |
+
msgstr ""
|
69 |
+
|
70 |
+
msgid "Your subscription expires in %d days."
|
71 |
+
msgstr ""
|
72 |
+
|
73 |
+
msgid "Downloading is not possible because WordPress cannot write into the plugins folder. %sHow to fix%s."
|
74 |
+
msgstr ""
|
75 |
+
|
76 |
+
msgid "Plugin"
|
77 |
+
msgstr ""
|
78 |
+
|
79 |
+
msgid "downloading..."
|
80 |
+
msgstr ""
|
81 |
+
|
82 |
+
msgid "failed!"
|
83 |
+
msgstr ""
|
84 |
+
|
85 |
+
msgid "downloaded"
|
86 |
+
msgstr ""
|
87 |
+
|
88 |
+
msgid "activating"
|
89 |
+
msgstr ""
|
90 |
+
|
91 |
+
msgid "activated"
|
92 |
+
msgstr ""
|
93 |
+
|
94 |
+
msgid "Activate after download"
|
95 |
+
msgstr ""
|
96 |
+
|
97 |
+
msgid "Operation complete!"
|
98 |
+
msgstr ""
|
99 |
+
|
100 |
+
msgid "Download failed!\n\nClick OK to revalidate your subscription or CANCEL to try again."
|
101 |
+
msgstr ""
|
102 |
+
|
103 |
+
msgid "Available"
|
104 |
+
msgstr ""
|
105 |
+
|
106 |
+
msgid "Installed"
|
107 |
+
msgstr ""
|
108 |
+
|
109 |
+
msgid "Downloading"
|
110 |
+
msgstr ""
|
111 |
+
|
112 |
+
msgid "Activate"
|
113 |
+
msgstr ""
|
114 |
+
|
115 |
+
msgid "Download"
|
116 |
+
msgstr ""
|
117 |
+
|
118 |
+
msgid "Downloads:"
|
119 |
+
msgstr ""
|
120 |
+
|
121 |
+
msgid "Current version"
|
122 |
+
msgstr ""
|
123 |
+
|
124 |
+
msgid "Released"
|
125 |
+
msgstr ""
|
126 |
+
|
127 |
+
msgid "Installed version"
|
128 |
+
msgstr ""
|
129 |
+
|
130 |
+
msgid "(embedded)"
|
131 |
+
msgstr ""
|
132 |
+
|
133 |
+
msgid "installing..."
|
134 |
+
msgstr ""
|
135 |
+
|
136 |
+
msgid "updating..."
|
137 |
+
msgstr ""
|
138 |
+
|
139 |
+
msgid "installed"
|
140 |
+
msgstr ""
|
141 |
+
|
142 |
+
msgid "updated"
|
143 |
+
msgstr ""
|
144 |
+
|
145 |
+
msgid "Download failed!\n\nPlease refresh the page and try again."
|
146 |
+
msgstr ""
|
147 |
+
|
148 |
+
msgid "Incorrect setup"
|
149 |
+
msgstr ""
|
150 |
+
|
151 |
+
msgid "Invalid product"
|
152 |
+
msgstr ""
|
153 |
+
|
154 |
+
msgid "Unknown repository"
|
155 |
+
msgstr ""
|
156 |
+
|
157 |
+
msgid " Your current site key (%s) does not match the selected product (%s)."
|
158 |
+
msgstr ""
|
159 |
+
|
160 |
+
msgid "Buy %s"
|
161 |
+
msgstr ""
|
162 |
+
|
163 |
+
msgid "Already bought %s?"
|
164 |
+
msgstr ""
|
165 |
+
|
166 |
+
msgid "Renew %s"
|
167 |
+
msgstr ""
|
168 |
+
|
169 |
+
msgid "Remove current site key (%s)"
|
170 |
+
msgstr ""
|
171 |
+
|
172 |
+
msgid "%s support on wpml.org"
|
173 |
+
msgstr ""
|
174 |
+
|
175 |
+
msgid "Enter site key"
|
176 |
+
msgstr ""
|
177 |
+
|
178 |
+
msgid "Subscription is expired."
|
179 |
+
msgstr ""
|
180 |
+
|
181 |
+
msgid "Add"
|
182 |
+
msgstr ""
|
183 |
+
|
184 |
+
msgid "Are you sure you want to remove this site key?"
|
185 |
+
msgstr ""
|
186 |
+
|
187 |
+
msgid "Register %s"
|
188 |
+
msgstr ""
|
189 |
+
|
190 |
+
msgid "1. Go to your %s%s account%s and add this site URL: %s"
|
191 |
+
msgstr ""
|
192 |
+
|
193 |
+
msgid "Unregister %s from this site"
|
194 |
+
msgstr ""
|
195 |
+
|
196 |
+
msgid "%s is registered on this site. You will receive automatic updates until %s"
|
197 |
+
msgstr ""
|
198 |
+
|
199 |
+
msgid "%s is registered on this site. Your Lifetime account gives you updates for life."
|
200 |
+
msgstr ""
|
201 |
+
|
202 |
+
msgid "This page lets you install plugins and update existing plugins. To remove any of these plugins, go to the %splugins%s page and if you have the permission to remove plugins you should be able to do this."
|
203 |
+
msgstr ""
|
204 |
+
|
205 |
+
msgid "Already bought?"
|
206 |
+
msgstr ""
|
207 |
+
|
208 |
+
msgid "2. Enter your site key"
|
209 |
+
msgstr ""
|
210 |
+
|
211 |
+
msgid "Subscription is expired. You need to either purchase a new subscription or upgrade if available."
|
212 |
+
msgstr ""
|
213 |
+
|
214 |
+
msgid "Check for updates"
|
215 |
+
msgstr ""
|
216 |
+
|
217 |
+
msgid "Individual components"
|
218 |
+
msgstr ""
|
219 |
+
|
220 |
+
msgid "OK"
|
221 |
+
msgstr ""
|
222 |
+
|
223 |
+
msgid "Cancel"
|
224 |
+
msgstr ""
|
225 |
+
|
226 |
+
msgid "Are you sure you want to unregister?"
|
227 |
+
msgstr ""
|
228 |
+
|
229 |
+
msgid "Click to see individual components options."
|
230 |
+
msgstr ""
|
library/otgs/installer/repositories.xml
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
-
<?xml version="1.0" encoding="utf-8"?>
|
2 |
-
<repositories>
|
3 |
-
<repository>
|
4 |
-
<id>wpml</id>
|
5 |
-
<apiurl>https://api.wpml.org/</apiurl>
|
6 |
-
<products>http://d2salfytceyqoe.cloudfront.net/wpml33-products.json</products>
|
7 |
-
</repository>
|
8 |
-
<repository>
|
9 |
-
<id>toolset</id>
|
10 |
-
<apiurl>https://api.wp-types.com/</apiurl>
|
11 |
-
<products>http://d7j863fr5jhrr.cloudfront.net/toolset33-products.json</products>
|
12 |
-
</repository>
|
13 |
-
</repositories>
|
1 |
+
<?xml version="1.0" encoding="utf-8"?>
|
2 |
+
<repositories>
|
3 |
+
<repository>
|
4 |
+
<id>wpml</id>
|
5 |
+
<apiurl>https://api.wpml.org/</apiurl>
|
6 |
+
<products>http://d2salfytceyqoe.cloudfront.net/wpml33-products.json</products>
|
7 |
+
</repository>
|
8 |
+
<repository>
|
9 |
+
<id>toolset</id>
|
10 |
+
<apiurl>https://api.wp-types.com/</apiurl>
|
11 |
+
<products>http://d7j863fr5jhrr.cloudfront.net/toolset33-products.json</products>
|
12 |
+
</repository>
|
13 |
+
</repositories>
|
library/otgs/installer/res/css/admin.css
CHANGED
@@ -1,201 +1,201 @@
|
|
1 |
-
.otgsi_site_key_form{
|
2 |
-
display:none;
|
3 |
-
/*display:inline;*/
|
4 |
-
}
|
5 |
-
|
6 |
-
.installer-status-installing, .installer-status-installed, .installer-status-updating, .installer-status-updated, .installer-status-activating, .installer-status-activated, .installer-status-success{
|
7 |
-
display: none;
|
8 |
-
}
|
9 |
-
.installer-status-installing{color: #FF9900; }
|
10 |
-
.installer-status-installed{color: #003300; font-weight: bold; }
|
11 |
-
.installer-status-updating{color: #FF9900; }
|
12 |
-
.installer-status-updated{color: #003300; font-weight: bold; }
|
13 |
-
|
14 |
-
.installer-status-activating{color: #996666 }
|
15 |
-
.installer-status-activated{color: #333366; font-weight: bold; }
|
16 |
-
|
17 |
-
.js-status-success p{
|
18 |
-
color: #FF9900;
|
19 |
-
padding: 4px;
|
20 |
-
}
|
21 |
-
|
22 |
-
.installer-green-text{
|
23 |
-
color:#006600;
|
24 |
-
font-weight:bold;
|
25 |
-
}
|
26 |
-
|
27 |
-
.installer-red-text{
|
28 |
-
color:#b22121;
|
29 |
-
font-weight:bold;
|
30 |
-
}
|
31 |
-
|
32 |
-
.installer-footnote{
|
33 |
-
color:#3d5e69;
|
34 |
-
display:block;
|
35 |
-
float: left;
|
36 |
-
font-style: italic;
|
37 |
-
font-size: 90%;
|
38 |
-
}
|
39 |
-
|
40 |
-
.installer-products-list li{
|
41 |
-
display: inline;
|
42 |
-
margin-right: 20px;
|
43 |
-
}
|
44 |
-
|
45 |
-
.otgs_wp_installer_table a.disabled{
|
46 |
-
color:#888;
|
47 |
-
}
|
48 |
-
|
49 |
-
.otgs_wp_installer_subtable{
|
50 |
-
clear: both;
|
51 |
-
margin-left:-20px;
|
52 |
-
}
|
53 |
-
.otgs_wp_installer_subtable td p{
|
54 |
-
font-size: 92%;
|
55 |
-
}
|
56 |
-
|
57 |
-
.installer-status-error{
|
58 |
-
color: #f00;
|
59 |
-
}
|
60 |
-
|
61 |
-
.installer-status-note{
|
62 |
-
color: #6F6E6D;
|
63 |
-
font-style: italic;
|
64 |
-
}
|
65 |
-
|
66 |
-
.installer-warn-box{
|
67 |
-
-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;border:1px solid #962722;background-color:#F5C8C6;
|
68 |
-
color: #333;
|
69 |
-
padding: 5px;
|
70 |
-
}
|
71 |
-
.installer-warn-box span.details{
|
72 |
-
font-style: italic;
|
73 |
-
color:#777;
|
74 |
-
}
|
75 |
-
|
76 |
-
.installer-error-box{
|
77 |
-
color:#962722;
|
78 |
-
margin-top: 10px;
|
79 |
-
}
|
80 |
-
.installer-error-box p{
|
81 |
-
margin: 10px 0 10px 0;
|
82 |
-
-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;border:1px solid #962722;background-color:#F5C8C6;
|
83 |
-
color: #333;
|
84 |
-
padding: 5px;
|
85 |
-
text-align: center;
|
86 |
-
}
|
87 |
-
|
88 |
-
.spinner-inline{
|
89 |
-
float: none;
|
90 |
-
display: inline-block;
|
91 |
-
visibility: visible;
|
92 |
-
}
|
93 |
-
|
94 |
-
.installer-q-icon:before{
|
95 |
-
content: '\f223' !important;
|
96 |
-
font-family: dashicons !important;
|
97 |
-
color: #f56e28;
|
98 |
-
font: 20px/1 "dashicons";
|
99 |
-
}
|
100 |
-
|
101 |
-
.installer-plugin-update-tr td{
|
102 |
-
padding-left:3px !important;
|
103 |
-
}
|
104 |
-
|
105 |
-
.otgsi_yellow_bg{
|
106 |
-
background-color: #f2f46b;
|
107 |
-
}
|
108 |
-
|
109 |
-
.otgs_wp_installer_table_compact{
|
110 |
-
width:480px;
|
111 |
-
border: solid 1px #999;
|
112 |
-
padding:10px;
|
113 |
-
border-radius: 5px;
|
114 |
-
}
|
115 |
-
|
116 |
-
.installer-plugins-list-compact{
|
117 |
-
background-color: #fff;
|
118 |
-
border-collapse: collapse;
|
119 |
-
border:solid 1px #C1DAD7;
|
120 |
-
width:100%;
|
121 |
-
}
|
122 |
-
|
123 |
-
.installer-plugins-list-compact tr th{
|
124 |
-
padding-top:3px;
|
125 |
-
background-color: #ccc;
|
126 |
-
}
|
127 |
-
|
128 |
-
.installer-plugins-list-compact tr{
|
129 |
-
background-color: #ddd;
|
130 |
-
}
|
131 |
-
|
132 |
-
.installer-plugins-list-compact tr.even{
|
133 |
-
background-color: #eee;
|
134 |
-
}
|
135 |
-
|
136 |
-
.installer-plugins-list-compact td{
|
137 |
-
padding:2px 5px 2px 5px;
|
138 |
-
border-right: 1px solid #C1DAD7;
|
139 |
-
border-bottom: 1px solid #C1DAD7;
|
140 |
-
}
|
141 |
-
|
142 |
-
.installer-plugins-list-compact td.twelve{
|
143 |
-
width:16px;
|
144 |
-
}
|
145 |
-
|
146 |
-
.otgs_wp_installer_table_compact .installer-status-downloading,
|
147 |
-
.otgs_wp_installer_table_compact .installer-status-downloaded,
|
148 |
-
.otgs_wp_installer_table_compact .installer-status-activating,
|
149 |
-
.otgs_wp_installer_table_compact .installer-status-activated{
|
150 |
-
display: none;
|
151 |
-
color:transparent; width: 12px; padding:2px;
|
152 |
-
}
|
153 |
-
|
154 |
-
.otgs_wp_installer_table_compact .installer-status-success,
|
155 |
-
.otgs_wp_installer_table_compact .installer-status-fail{
|
156 |
-
display: none;
|
157 |
-
}
|
158 |
-
|
159 |
-
.installer-status-success{
|
160 |
-
float: right;
|
161 |
-
color: #006600;
|
162 |
-
}
|
163 |
-
|
164 |
-
.otgs_wp_installer_table_compact .installer-status-downloading{background: url(../img/dn.gif) no-repeat center; }
|
165 |
-
.otgs_wp_installer_table_compact .installer-status-downloaded{background: url(../img/complete.png) no-repeat center;}
|
166 |
-
.otgs_wp_installer_table_compact .installer-status-activating{background: url(../img/dn.gif) no-repeat center; }
|
167 |
-
.otgs_wp_installer_table_compact .installer-status-activated{background: url(../img/complete.png) no-repeat center; }
|
168 |
-
.otgs_wp_installer_table_compact .installer-status-error{background: url(../img/icon_error.gif) no-repeat center; }
|
169 |
-
|
170 |
-
.installer_highlight{
|
171 |
-
color:#c5510b;
|
172 |
-
}
|
173 |
-
|
174 |
-
.installer_highlight_package{
|
175 |
-
background-color: #fff9c0;
|
176 |
-
}
|
177 |
-
|
178 |
-
.plugin_progress{
|
179 |
-
font-style: italic;
|
180 |
-
color: #777
|
181 |
-
}
|
182 |
-
|
183 |
-
.installer-download-progress-status{
|
184 |
-
display: none;
|
185 |
-
float:right;
|
186 |
-
color: #006600;
|
187 |
-
font-style: italic;
|
188 |
-
background: url('../img/spinner.gif') no-repeat;
|
189 |
-
padding-left:24px;
|
190 |
-
}
|
191 |
-
|
192 |
-
.otgs-is-dismissible {
|
193 |
-
position: relative;
|
194 |
-
padding-right: 38px;
|
195 |
-
}
|
196 |
-
.otgs-is-dismissible .notice-dismiss {
|
197 |
-
text-decoration: none;
|
198 |
-
}
|
199 |
-
.otgs-is-dismissible p [class*="button-"] {
|
200 |
-
margin: -5px 5px;
|
201 |
}
|
1 |
+
.otgsi_site_key_form{
|
2 |
+
display:none;
|
3 |
+
/*display:inline;*/
|
4 |
+
}
|
5 |
+
|
6 |
+
.installer-status-installing, .installer-status-installed, .installer-status-updating, .installer-status-updated, .installer-status-activating, .installer-status-activated, .installer-status-success{
|
7 |
+
display: none;
|
8 |
+
}
|
9 |
+
.installer-status-installing{color: #FF9900; }
|
10 |
+
.installer-status-installed{color: #003300; font-weight: bold; }
|
11 |
+
.installer-status-updating{color: #FF9900; }
|
12 |
+
.installer-status-updated{color: #003300; font-weight: bold; }
|
13 |
+
|
14 |
+
.installer-status-activating{color: #996666 }
|
15 |
+
.installer-status-activated{color: #333366; font-weight: bold; }
|
16 |
+
|
17 |
+
.js-status-success p{
|
18 |
+
color: #FF9900;
|
19 |
+
padding: 4px;
|
20 |
+
}
|
21 |
+
|
22 |
+
.installer-green-text{
|
23 |
+
color:#006600;
|
24 |
+
font-weight:bold;
|
25 |
+
}
|
26 |
+
|
27 |
+
.installer-red-text{
|
28 |
+
color:#b22121;
|
29 |
+
font-weight:bold;
|
30 |
+
}
|
31 |
+
|
32 |
+
.installer-footnote{
|
33 |
+
color:#3d5e69;
|
34 |
+
display:block;
|
35 |
+
float: left;
|
36 |
+
font-style: italic;
|
37 |
+
font-size: 90%;
|
38 |
+
}
|
39 |
+
|
40 |
+
.installer-products-list li{
|
41 |
+
display: inline;
|
42 |
+
margin-right: 20px;
|
43 |
+
}
|
44 |
+
|
45 |
+
.otgs_wp_installer_table a.disabled{
|
46 |
+
color:#888;
|
47 |
+
}
|
48 |
+
|
49 |
+
.otgs_wp_installer_subtable{
|
50 |
+
clear: both;
|
51 |
+
margin-left:-20px;
|
52 |
+
}
|
53 |
+
.otgs_wp_installer_subtable td p{
|
54 |
+
font-size: 92%;
|
55 |
+
}
|
56 |
+
|
57 |
+
.installer-status-error{
|
58 |
+
color: #f00;
|
59 |
+
}
|
60 |
+
|
61 |
+
.installer-status-note{
|
62 |
+
color: #6F6E6D;
|
63 |
+
font-style: italic;
|
64 |
+
}
|
65 |
+
|
66 |
+
.installer-warn-box{
|
67 |
+
-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;border:1px solid #962722;background-color:#F5C8C6;
|
68 |
+
color: #333;
|
69 |
+
padding: 5px;
|
70 |
+
}
|
71 |
+
.installer-warn-box span.details{
|
72 |
+
font-style: italic;
|
73 |
+
color:#777;
|
74 |
+
}
|
75 |
+
|
76 |
+
.installer-error-box{
|
77 |
+
color:#962722;
|
78 |
+
margin-top: 10px;
|
79 |
+
}
|
80 |
+
.installer-error-box p{
|
81 |
+
margin: 10px 0 10px 0;
|
82 |
+
-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;border:1px solid #962722;background-color:#F5C8C6;
|
83 |
+
color: #333;
|
84 |
+
padding: 5px;
|
85 |
+
text-align: center;
|
86 |
+
}
|
87 |
+
|
88 |
+
.spinner-inline{
|
89 |
+
float: none;
|
90 |
+
display: inline-block;
|
91 |
+
visibility: visible;
|
92 |
+
}
|
93 |
+
|
94 |
+
.installer-q-icon:before{
|
95 |
+
content: '\f223' !important;
|
96 |
+
font-family: dashicons !important;
|
97 |
+
color: #f56e28;
|
98 |
+
font: 20px/1 "dashicons";
|
99 |
+
}
|
100 |
+
|
101 |
+
.installer-plugin-update-tr td{
|
102 |
+
padding-left:3px !important;
|
103 |
+
}
|
104 |
+
|
105 |
+
.otgsi_yellow_bg{
|
106 |
+
background-color: #f2f46b;
|
107 |
+
}
|
108 |
+
|
109 |
+
.otgs_wp_installer_table_compact{
|
110 |
+
width:480px;
|
111 |
+
border: solid 1px #999;
|
112 |
+
padding:10px;
|
113 |
+
border-radius: 5px;
|
114 |
+
}
|
115 |
+
|
116 |
+
.installer-plugins-list-compact{
|
117 |
+
background-color: #fff;
|
118 |
+
border-collapse: collapse;
|
119 |
+
border:solid 1px #C1DAD7;
|
120 |
+
width:100%;
|
121 |
+
}
|
122 |
+
|
123 |
+
.installer-plugins-list-compact tr th{
|
124 |
+
padding-top:3px;
|
125 |
+
background-color: #ccc;
|
126 |
+
}
|
127 |
+
|
128 |
+
.installer-plugins-list-compact tr{
|
129 |
+
background-color: #ddd;
|
130 |
+
}
|
131 |
+
|
132 |
+
.installer-plugins-list-compact tr.even{
|
133 |
+
background-color: #eee;
|
134 |
+
}
|
135 |
+
|
136 |
+
.installer-plugins-list-compact td{
|
137 |
+
padding:2px 5px 2px 5px;
|
138 |
+
border-right: 1px solid #C1DAD7;
|
139 |
+
border-bottom: 1px solid #C1DAD7;
|
140 |
+
}
|
141 |
+
|
142 |
+
.installer-plugins-list-compact td.twelve{
|
143 |
+
width:16px;
|
144 |
+
}
|
145 |
+
|
146 |
+
.otgs_wp_installer_table_compact .installer-status-downloading,
|
147 |
+
.otgs_wp_installer_table_compact .installer-status-downloaded,
|
148 |
+
.otgs_wp_installer_table_compact .installer-status-activating,
|
149 |
+
.otgs_wp_installer_table_compact .installer-status-activated{
|
150 |
+
display: none;
|
151 |
+
color:transparent; width: 12px; padding:2px;
|
152 |
+
}
|
153 |
+
|
154 |
+
.otgs_wp_installer_table_compact .installer-status-success,
|
155 |
+
.otgs_wp_installer_table_compact .installer-status-fail{
|
156 |
+
display: none;
|
157 |
+
}
|
158 |
+
|
159 |
+
.installer-status-success{
|
160 |
+
float: right;
|
161 |
+
color: #006600;
|
162 |
+
}
|
163 |
+
|
164 |
+
.otgs_wp_installer_table_compact .installer-status-downloading{background: url(../img/dn.gif) no-repeat center; }
|
165 |
+
.otgs_wp_installer_table_compact .installer-status-downloaded{background: url(../img/complete.png) no-repeat center;}
|
166 |
+
.otgs_wp_installer_table_compact .installer-status-activating{background: url(../img/dn.gif) no-repeat center; }
|
167 |
+
.otgs_wp_installer_table_compact .installer-status-activated{background: url(../img/complete.png) no-repeat center; }
|
168 |
+
.otgs_wp_installer_table_compact .installer-status-error{background: url(../img/icon_error.gif) no-repeat center; }
|
169 |
+
|
170 |
+
.installer_highlight{
|
171 |
+
color:#c5510b;
|
172 |
+
}
|
173 |
+
|
174 |
+
.installer_highlight_package{
|
175 |
+
background-color: #fff9c0;
|
176 |
+
}
|
177 |
+
|
178 |
+
.plugin_progress{
|
179 |
+
font-style: italic;
|
180 |
+
color: #777
|
181 |
+
}
|
182 |
+
|
183 |
+
.installer-download-progress-status{
|
184 |
+
display: none;
|
185 |
+
float:right;
|
186 |
+
color: #006600;
|
187 |
+
font-style: italic;
|
188 |
+
background: url('../img/spinner.gif') no-repeat;
|
189 |
+
padding-left:24px;
|
190 |
+
}
|
191 |
+
|
192 |
+
.otgs-is-dismissible {
|
193 |
+
position: relative;
|
194 |
+
padding-right: 38px;
|
195 |
+
}
|
196 |
+
.otgs-is-dismissible .notice-dismiss {
|
197 |
+
text-decoration: none;
|
198 |
+
}
|
199 |
+
.otgs-is-dismissible p [class*="button-"] {
|
200 |
+
margin: -5px 5px;
|
201 |
}
|
library/otgs/installer/res/js/admin.js
CHANGED
@@ -1,417 +1,417 @@
|
|
1 |
-
var otgs_wp_installer = {
|
2 |
-
|
3 |
-
init: function(){
|
4 |
-
|
5 |
-
jQuery('.otgs_wp_installer_table').on('click', '.enter_site_key_js', otgs_wp_installer.show_site_key_form);
|
6 |
-
jQuery('.otgs_wp_installer_table').on('click', '.cancel_site_key_js', otgs_wp_installer.hide_site_key_form);
|
7 |
-
|
8 |
-
jQuery('.otgs_wp_installer_table').on('click', '.remove_site_key_js', otgs_wp_installer.remove_site_key);
|
9 |
-
jQuery('.otgs_wp_installer_table').on('click', '.update_site_key_js', otgs_wp_installer.update_site_key);
|
10 |
-
|
11 |
-
jQuery('.otgs_wp_installer_table').on('submit', '.otgsi_site_key_form', otgs_wp_installer.save_site_key);
|
12 |
-
jQuery('.otgs_wp_installer_table').on('submit', '.otgsi_downloads_form', otgs_wp_installer.download_downloads);
|
13 |
-
jQuery('.otgs_wp_installer_table').on('change', '.otgsi_downloads_form :checkbox[name="downloads[]"]', otgs_wp_installer.update_downloads_form);
|
14 |
-
|
15 |
-
jQuery('.installer-dismiss-nag').click(otgs_wp_installer.dismiss_nag);
|
16 |
-
|
17 |
-
jQuery('.otgs_wp_installer_table').on('click', '.installer_expand_button', otgs_wp_installer.toggle_subpackages);
|
18 |
-
|
19 |
-
otgs_wp_installer.scroll_to_repository();
|
20 |
-
|
21 |
-
if( typeof pagenow != 'undefined' && pagenow == 'plugins'){
|
22 |
-
|
23 |
-
jQuery(document).ajaxSuccess(function(event, xhr, settings) {
|
24 |
-
var data = otgs_wp_installer.getQueryParameters(settings.data);
|
25 |
-
if(typeof data.action != 'undefined' && data.action == 'update-plugin'){
|
26 |
-
response = xhr.responseJSON.data;
|
27 |
-
if(typeof response.error != 'undefined'){
|
28 |
-
var default_error = jQuery('#' + response.slug + '-update .update-message').html();
|
29 |
-
jQuery('#' + response.slug + '-update .update-message').html(default_error + ' »<span class="installer-red-text"> ' + response.error + '</span>');
|
30 |
-
}
|
31 |
-
}
|
32 |
-
return false;
|
33 |
-
});
|
34 |
-
|
35 |
-
}
|
36 |
-
|
37 |
-
},
|
38 |
-
|
39 |
-
getQueryParameters : function(str) {
|
40 |
-
return (str || document.location.search).replace(/(^\?)/,'').split("&").map(function(n){return n = n.split("="),this[n[0]] = n[1],this}.bind({}))[0];
|
41 |
-
},
|
42 |
-
|
43 |
-
reset_errors: function(){
|
44 |
-
jQuery('.installer-error-box').html('').hide();
|
45 |
-
},
|
46 |
-
|
47 |
-
show_error: function(repo, text){
|
48 |
-
jQuery('#installer_repo_' + repo).find('.installer-error-box').html(text).show();
|
49 |
-
},
|
50 |
-
|
51 |
-
show_site_key_form: function(){
|
52 |
-
|
53 |
-
if( jQuery(this).hasClass('disabled') ) {
|
54 |
-
alert( jQuery(this).attr('title') );
|
55 |
-
return false;
|
56 |
-
}
|
57 |
-
|
58 |
-
otgs_wp_installer.reset_errors();
|
59 |
-
|
60 |
-
var form = jQuery(this).parent().find('form.otgsi_site_key_form');
|
61 |
-
jQuery(this).prev().hide();
|
62 |
-
jQuery(this).hide();
|
63 |
-
form.css('display', 'inline');
|
64 |
-
form.find('input[name^=site_key_]').focus().val('');
|
65 |
-
form.find('input').removeAttr('disabled');
|
66 |
-
|
67 |
-
form.closest('.otgsi_register_product_wrap').addClass('otgsi_yellow_bg');
|
68 |
-
|
69 |
-
return false;
|
70 |
-
},
|
71 |
-
|
72 |
-
hide_site_key_form: function(){
|
73 |
-
var form = jQuery(this).closest('form');
|
74 |
-
form.hide();
|
75 |
-
form.parent().find('.enter_site_key_js').show();
|
76 |
-
form.parent().find('.enter_site_key_js').prev().show();
|
77 |
-
|
78 |
-
form.closest('.otgsi_register_product_wrap').removeClass('otgsi_yellow_bg');
|
79 |
-
otgs_wp_installer.reset_errors();
|
80 |
-
return false;
|
81 |
-
},
|
82 |
-
|
83 |
-
save_site_key: function(){
|
84 |
-
|
85 |
-
var thisf = jQuery(this);
|
86 |
-
var data = jQuery(this).serialize();
|
87 |
-
jQuery(this).find('input').attr('disabled', 'disabled');
|
88 |
-
|
89 |
-
var spinner = jQuery('<span class="spinner"></span>');
|
90 |
-
spinner.css({display: 'inline-block', float: 'none'}).prependTo(jQuery(this));
|
91 |
-
|
92 |
-
otgs_wp_installer.reset_errors();
|
93 |
-
|
94 |
-
jQuery.ajax({url: ajaxurl, type: 'POST', dataType:'json', data: data, success:
|
95 |
-
function(ret){
|
96 |
-
if(!ret.error){
|
97 |
-
otgs_wp_installer.saved_site_key();
|
98 |
-
}else{
|
99 |
-
otgs_wp_installer.show_error(thisf.find('[name=repository_id]').val(), ret.error);
|
100 |
-
thisf.find('input').removeAttr('disabled');
|
101 |
-
}
|
102 |
-
|
103 |
-
if(typeof ret.debug != 'undefined'){
|
104 |
-
thisf.append('<textarea style="width:100%" rows="20">' + ret.debug + '</textarea>');
|
105 |
-
}
|
106 |
-
|
107 |
-
spinner.remove();
|
108 |
-
}
|
109 |
-
});
|
110 |
-
|
111 |
-
return false;
|
112 |
-
|
113 |
-
},
|
114 |
-
|
115 |
-
saved_site_key: function(){
|
116 |
-
location.reload();
|
117 |
-
},
|
118 |
-
|
119 |
-
remove_site_key: function(){
|
120 |
-
|
121 |
-
if( jQuery(this).attr('disabled') == 'disabled' ){
|
122 |
-
|
123 |
-
alert( jQuery(this).attr('title') );
|
124 |
-
return false;
|
125 |
-
|
126 |
-
} else {
|
127 |
-
|
128 |
-
if(confirm(jQuery(this).data('confirmation'))){
|
129 |
-
|
130 |
-
jQuery('<span class="spinner"></span>').css({visibility: 'visible', float: 'none'}).prependTo(jQuery(this).parent());
|
131 |
-
data = {action: 'remove_site_key', repository_id: jQuery(this).data('repository'), nonce: jQuery(this).data('nonce')}
|
132 |
-
jQuery.ajax({url: ajaxurl, type: 'POST', data: data, success: otgs_wp_installer.removed_site_key});
|
133 |
-
}
|
134 |
-
|
135 |
-
}
|
136 |
-
|
137 |
-
return false;
|
138 |
-
},
|
139 |
-
|
140 |
-
removed_site_key: function(){
|
141 |
-
location.reload();
|
142 |
-
},
|
143 |
-
|
144 |
-
update_site_key: function(){
|
145 |
-
var error_wrap = jQuery(this).closest('.otgsi_register_product_wrap').find('.installer-error-box');
|
146 |
-
error_wrap.html('');
|
147 |
-
|
148 |
-
var spinner = jQuery('<span class="spinner"></span>');
|
149 |
-
|
150 |
-
spinner.css({visibility: 'visible', float: 'none'}).prependTo(jQuery(this).parent());
|
151 |
-
data = {action: 'update_site_key', repository_id: jQuery(this).data('repository'), nonce: jQuery(this).data('nonce')}
|
152 |
-
jQuery.ajax({
|
153 |
-
url: ajaxurl,
|
154 |
-
type: 'POST',
|
155 |
-
data: data,
|
156 |
-
dataType: 'json',
|
157 |
-
complete: function( event, xhr, settings ){
|
158 |
-
var error = '';
|
159 |
-
if(xhr == 'success') {
|
160 |
-
var ret = event.responseJSON;
|
161 |
-
if(ret.error){
|
162 |
-
error = ret.error;
|
163 |
-
}else{
|
164 |
-
otgs_wp_installer.updated_site_key(ret);
|
165 |
-
}
|
166 |
-
}else{
|
167 |
-
error = 'Error processing request (' + xhr + '). Please try again!';
|
168 |
-
}
|
169 |
-
|
170 |
-
if( error ){
|
171 |
-
error_wrap.html('<p>' + error + '</p>').show();
|
172 |
-
spinner.remove();
|
173 |
-
}
|
174 |
-
|
175 |
-
}
|
176 |
-
});
|
177 |
-
|
178 |
-
return false;
|
179 |
-
|
180 |
-
},
|
181 |
-
|
182 |
-
updated_site_key: function(ret){
|
183 |
-
location.reload();
|
184 |
-
},
|
185 |
-
|
186 |
-
update_downloads_form: function(){
|
187 |
-
|
188 |
-
var checked = jQuery('.otgsi_downloads_form :checkbox:checked[name="downloads[]"]').length;
|
189 |
-
|
190 |
-
if(checked){
|
191 |
-
jQuery(this).closest('form').find(':submit, :checkbox[name=activate]').removeAttr('disabled');
|
192 |
-
}else{
|
193 |
-
jQuery(this).closest('form').find(':submit, :checkbox[name=activate]').attr('disabled', 'disabled');
|
194 |
-
}
|
195 |
-
|
196 |
-
|
197 |
-
},
|
198 |
-
|
199 |
-
download_downloads: function(){
|
200 |
-
|
201 |
-
var activate = jQuery(this).find(":checkbox:checked[name=activate]").val(),
|
202 |
-
action_button = jQuery(this).find('input[type="submit"]');
|
203 |
-
downloads_form = jQuery(this),
|
204 |
-
idx = 0,
|
205 |
-
checkboxes = [];
|
206 |
-
|
207 |
-
jQuery(this).find(':checkbox:checked[name="downloads[]"]').each(function(){
|
208 |
-
if(jQuery(this).attr('disabled')) return;
|
209 |
-
checkboxes[idx] = jQuery(this);
|
210 |
-
idx++;
|
211 |
-
jQuery(this).attr('disabled', 'disabled');
|
212 |
-
});
|
213 |
-
|
214 |
-
idx = 0;
|
215 |
-
|
216 |
-
if( typeof checkboxes[idx] != 'undefined' ){
|
217 |
-
download_and_activate( checkboxes[idx] );
|
218 |
-
action_button.attr('disabled', 'disabled');
|
219 |
-
}
|
220 |
-
|
221 |
-
function download_and_activate( elem ){
|
222 |
-
|
223 |
-
var this_tr = elem.closest('tr');
|
224 |
-
var is_update = this_tr.find('.installer-red-text').length;
|
225 |
-
if(is_update){
|
226 |
-
var installing = this_tr.find('.installer-status-updating');
|
227 |
-
var installed = this_tr.find('.installer-status-updated');
|
228 |
-
}else{
|
229 |
-
var installing = this_tr.find('.installer-status-installing');
|
230 |
-
var installed = this_tr.find('.installer-status-installed');
|
231 |
-
|
232 |
-
}
|
233 |
-
if(activate){
|
234 |
-
var activating = this_tr.find('.installer-status-activating');
|
235 |
-
var activated = this_tr.find('.installer-status-activated');
|
236 |
-
}
|
237 |
-
|
238 |
-
if( this_tr.find('.for_spinner_js .spinner').length > 0 ){
|
239 |
-
var spinner = this_tr.find('.for_spinner_js .spinner');
|
240 |
-
}else{
|
241 |
-
var spinner = this_tr.find('.installer-status-downloading');
|
242 |
-
}
|
243 |
-
|
244 |
-
otgs_wp_installer.reset_errors();
|
245 |
-
downloads_form.find('div.installer-status-success').hide();
|
246 |
-
spinner.css('visibility', 'visible');
|
247 |
-
installing.show();
|
248 |
-
|
249 |
-
var plugin_name = this_tr.find('.installer_plugin_name').html();
|
250 |
-
if(is_update){
|
251 |
-
otgs_wp_installer.show_download_progress_status(downloads_form, installer_strings.updating.replace('%s', plugin_name));
|
252 |
-
}else{
|
253 |
-
otgs_wp_installer.show_download_progress_status(downloads_form, installer_strings.installing.replace('%s', plugin_name));
|
254 |
-
}
|
255 |
-
|
256 |
-
|
257 |
-
data = {action: 'installer_download_plugin', data: elem.val(), activate: activate}
|
258 |
-
|
259 |
-
jQuery.ajax({
|
260 |
-
url: ajaxurl,
|
261 |
-
type: 'POST',
|
262 |
-
dataType: 'json',
|
263 |
-
data: data,
|
264 |
-
success: function(ret){
|
265 |
-
installing.hide();
|
266 |
-
|
267 |
-
if(!ret.success){
|
268 |
-
installed.addClass('installer-status-error');
|
269 |
-
installed.html(installed.data('fail'));
|
270 |
-
|
271 |
-
if(ret.message){
|
272 |
-
installed.closest('.otgs_wp_installer_table').find('.installer-error-box').html('<p>' + ret.message + '</p>').show();
|
273 |
-
}else{
|
274 |
-
installed.closest('.otgs_wp_installer_table').find('.installer-error-box').html('<p>' + downloads_form.find('.installer-revalidate-message').html() + '</p>').show();
|
275 |
-
}
|
276 |
-
|
277 |
-
|
278 |
-
}
|
279 |
-
|
280 |
-
installed.show();
|
281 |
-
spinner.fadeOut();
|
282 |
-
|
283 |
-
if(ret.version){
|
284 |
-
this_tr.find('.installer_version_installed').html('<span class="installer-green-text">' + ret.version + '</span>');
|
285 |
-
}
|
286 |
-
|
287 |
-
if(ret.success && activate){
|
288 |
-
|
289 |
-
otgs_wp_installer.show_download_progress_status(downloads_form, installer_strings.activating.replace('%s', plugin_name));
|
290 |
-
activating.show();
|
291 |
-
spinner.show();
|
292 |
-
this_tr.find('.installer-red-text').removeClass('installer-red-text').addClass('installer-green-text').html(ret.version);
|
293 |
-
|
294 |
-
jQuery.ajax({
|
295 |
-
url: ajaxurl,
|
296 |
-
type: 'POST',
|
297 |
-
dataType: 'json',
|
298 |
-
data: {action: 'installer_activate_plugin', plugin_id: ret.plugin_id, nonce: ret.nonce},
|
299 |
-
success: function(ret){
|
300 |
-
activating.hide();
|
301 |
-
if(!ret.error ){
|
302 |
-
activated.show();
|
303 |
-
}
|
304 |
-
|
305 |
-
spinner.fadeOut();
|
306 |
-
|
307 |
-
idx++;
|
308 |
-
if( typeof checkboxes[idx] != 'undefined' ){
|
309 |
-
download_and_activate( checkboxes[idx] );
|
310 |
-
}else{
|
311 |
-
otgs_wp_installer.hide_download_progress_status(downloads_form);
|
312 |
-
downloads_form.find('div.installer-status-success').show();
|
313 |
-
action_button.removeAttr('disabled');
|
314 |
-
}
|
315 |
-
}
|
316 |
-
});
|
317 |
-
}else{
|
318 |
-
idx++;
|
319 |
-
if( typeof checkboxes[idx] != 'undefined' ){
|
320 |
-
download_and_activate( checkboxes[idx] );
|
321 |
-
}else{
|
322 |
-
otgs_wp_installer.hide_download_progress_status(downloads_form);
|
323 |
-
downloads_form.find('div.installer-status-success').show();
|
324 |
-
action_button.removeAttr('disabled');
|
325 |
-
}
|
326 |
-
}
|
327 |
-
}
|
328 |
-
|
329 |
-
});
|
330 |
-
|
331 |
-
};
|
332 |
-
|
333 |
-
return false;
|
334 |
-
},
|
335 |
-
|
336 |
-
|
337 |
-
show_download_progress_status: function(downloads_form, text){
|
338 |
-
|
339 |
-
downloads_form.find('.installer-download-progress-status').html(text).fadeIn();
|
340 |
-
|
341 |
-
},
|
342 |
-
|
343 |
-
hide_download_progress_status: function(downloads_form){
|
344 |
-
|
345 |
-
downloads_form.find('.installer-download-progress-status').html('').fadeOut();
|
346 |
-
|
347 |
-
},
|
348 |
-
|
349 |
-
dismiss_nag: function(){
|
350 |
-
|
351 |
-
var thisa = jQuery(this);
|
352 |
-
|
353 |
-
data = {action: 'installer_dismiss_nag', repository: jQuery(this).data('repository')}
|
354 |
-
|
355 |
-
jQuery.ajax({url: ajaxurl, type: 'POST', dataType:'json', data: data, success:
|
356 |
-
function(ret){
|
357 |
-
thisa.closest('.otgs-is-dismissible').remove();
|
358 |
-
}
|
359 |
-
});
|
360 |
-
|
361 |
-
return false;
|
362 |
-
},
|
363 |
-
|
364 |
-
toggle_subpackages: function(){
|
365 |
-
var list = jQuery(this).closest('td').find('.otgs_wp_installer_subtable');
|
366 |
-
|
367 |
-
if(list.is(':visible')){
|
368 |
-
list.slideUp('fast');
|
369 |
-
}else{
|
370 |
-
list.slideDown('fast');
|
371 |
-
}
|
372 |
-
|
373 |
-
|
374 |
-
return false;
|
375 |
-
|
376 |
-
},
|
377 |
-
|
378 |
-
scroll_to_repository: function(){
|
379 |
-
|
380 |
-
var ref = window.location.hash.replace('#', '');
|
381 |
-
|
382 |
-
if(ref) {
|
383 |
-
var split = ref.split('/');
|
384 |
-
var repo = split[0];
|
385 |
-
|
386 |
-
if(typeof split[1] != 'undefined'){
|
387 |
-
var package = split[1];
|
388 |
-
var repo_element = jQuery('#repository-' + repo);
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
if(repo_element.length){
|
393 |
-
|
394 |
-
jQuery('html, body').animate({
|
395 |
-
scrollTop: repo_element.offset().top
|
396 |
-
}, 1000);
|
397 |
-
|
398 |
-
var package_element = jQuery('#repository-' + repo +'_' + package);
|
399 |
-
|
400 |
-
if(package_element.length && !package_element.is(':visible')){
|
401 |
-
package_element.parents('.otgs_wp_installer_subtable').slideDown();
|
402 |
-
package_element.addClass('installer_highlight_package');
|
403 |
-
}
|
404 |
-
|
405 |
-
package_element.find('.button-secondary').removeClass('button-secondary').addClass('button-primary');
|
406 |
-
}
|
407 |
-
}
|
408 |
-
|
409 |
-
}
|
410 |
-
|
411 |
-
}
|
412 |
-
|
413 |
-
|
414 |
-
}
|
415 |
-
|
416 |
-
|
417 |
jQuery(document).ready(otgs_wp_installer.init);
|
1 |
+
var otgs_wp_installer = {
|
2 |
+
|
3 |
+
init: function(){
|
4 |
+
|
5 |
+
jQuery('.otgs_wp_installer_table').on('click', '.enter_site_key_js', otgs_wp_installer.show_site_key_form);
|
6 |
+
jQuery('.otgs_wp_installer_table').on('click', '.cancel_site_key_js', otgs_wp_installer.hide_site_key_form);
|
7 |
+
|
8 |
+
jQuery('.otgs_wp_installer_table').on('click', '.remove_site_key_js', otgs_wp_installer.remove_site_key);
|
9 |
+
jQuery('.otgs_wp_installer_table').on('click', '.update_site_key_js', otgs_wp_installer.update_site_key);
|
10 |
+
|
11 |
+
jQuery('.otgs_wp_installer_table').on('submit', '.otgsi_site_key_form', otgs_wp_installer.save_site_key);
|
12 |
+
jQuery('.otgs_wp_installer_table').on('submit', '.otgsi_downloads_form', otgs_wp_installer.download_downloads);
|
13 |
+
jQuery('.otgs_wp_installer_table').on('change', '.otgsi_downloads_form :checkbox[name="downloads[]"]', otgs_wp_installer.update_downloads_form);
|
14 |
+
|
15 |
+
jQuery('.installer-dismiss-nag').click(otgs_wp_installer.dismiss_nag);
|
16 |
+
|
17 |
+
jQuery('.otgs_wp_installer_table').on('click', '.installer_expand_button', otgs_wp_installer.toggle_subpackages);
|
18 |
+
|
19 |
+
otgs_wp_installer.scroll_to_repository();
|
20 |
+
|
21 |
+
if( typeof pagenow != 'undefined' && pagenow == 'plugins'){
|
22 |
+
|
23 |
+
jQuery(document).ajaxSuccess(function(event, xhr, settings) {
|
24 |
+
var data = otgs_wp_installer.getQueryParameters(settings.data);
|
25 |
+
if(typeof data.action != 'undefined' && data.action == 'update-plugin'){
|
26 |
+
response = xhr.responseJSON.data;
|
27 |
+
if(typeof response.error != 'undefined'){
|
28 |
+
var default_error = jQuery('#' + response.slug + '-update .update-message').html();
|
29 |
+
jQuery('#' + response.slug + '-update .update-message').html(default_error + ' »<span class="installer-red-text"> ' + response.error + '</span>');
|
30 |
+
}
|
31 |
+
}
|
32 |
+
return false;
|
33 |
+
});
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
+
},
|
38 |
+
|
39 |
+
getQueryParameters : function(str) {
|
40 |
+
return (str || document.location.search).replace(/(^\?)/,'').split("&").map(function(n){return n = n.split("="),this[n[0]] = n[1],this}.bind({}))[0];
|
41 |
+
},
|
42 |
+
|
43 |
+
reset_errors: function(){
|
44 |
+
jQuery('.installer-error-box').html('').hide();
|
45 |
+
},
|
46 |
+
|
47 |
+
show_error: function(repo, text){
|
48 |
+
jQuery('#installer_repo_' + repo).find('.installer-error-box').html(text).show();
|
49 |
+
},
|
50 |
+
|
51 |
+
show_site_key_form: function(){
|
52 |
+
|
53 |
+
if( jQuery(this).hasClass('disabled') ) {
|
54 |
+
alert( jQuery(this).attr('title') );
|
55 |
+
return false;
|
56 |
+
}
|
57 |
+
|
58 |
+
otgs_wp_installer.reset_errors();
|
59 |
+
|
60 |
+
var form = jQuery(this).parent().find('form.otgsi_site_key_form');
|
61 |
+
jQuery(this).prev().hide();
|
62 |
+
jQuery(this).hide();
|
63 |
+
form.css('display', 'inline');
|
64 |
+
form.find('input[name^=site_key_]').focus().val('');
|
65 |
+
form.find('input').removeAttr('disabled');
|
66 |
+
|
67 |
+
form.closest('.otgsi_register_product_wrap').addClass('otgsi_yellow_bg');
|
68 |
+
|
69 |
+
return false;
|
70 |
+
},
|
71 |
+
|
72 |
+
hide_site_key_form: function(){
|
73 |
+
var form = jQuery(this).closest('form');
|
74 |
+
form.hide();
|
75 |
+
form.parent().find('.enter_site_key_js').show();
|
76 |
+
form.parent().find('.enter_site_key_js').prev().show();
|
77 |
+
|
78 |
+
form.closest('.otgsi_register_product_wrap').removeClass('otgsi_yellow_bg');
|
79 |
+
otgs_wp_installer.reset_errors();
|
80 |
+
return false;
|
81 |
+
},
|
82 |
+
|
83 |
+
save_site_key: function(){
|
84 |
+
|
85 |
+
var thisf = jQuery(this);
|
86 |
+
var data = jQuery(this).serialize();
|
87 |
+
jQuery(this).find('input').attr('disabled', 'disabled');
|
88 |
+
|
89 |
+
var spinner = jQuery('<span class="spinner"></span>');
|
90 |
+
spinner.css({display: 'inline-block', float: 'none'}).prependTo(jQuery(this));
|
91 |
+
|
92 |
+
otgs_wp_installer.reset_errors();
|
93 |
+
|
94 |
+
jQuery.ajax({url: ajaxurl, type: 'POST', dataType:'json', data: data, success:
|
95 |
+
function(ret){
|
96 |
+
if(!ret.error){
|
97 |
+
otgs_wp_installer.saved_site_key();
|
98 |
+
}else{
|
99 |
+
otgs_wp_installer.show_error(thisf.find('[name=repository_id]').val(), ret.error);
|
100 |
+
thisf.find('input').removeAttr('disabled');
|
101 |
+
}
|
102 |
+
|
103 |
+
if(typeof ret.debug != 'undefined'){
|
104 |
+
thisf.append('<textarea style="width:100%" rows="20">' + ret.debug + '</textarea>');
|
105 |
+
}
|
106 |
+
|
107 |
+
spinner.remove();
|
108 |
+
}
|
109 |
+
});
|
110 |
+
|
111 |
+
return false;
|
112 |
+
|
113 |
+
},
|
114 |
+
|
115 |
+
saved_site_key: function(){
|
116 |
+
location.reload();
|
117 |
+
},
|
118 |
+
|
119 |
+
remove_site_key: function(){
|
120 |
+
|
121 |
+
if( jQuery(this).attr('disabled') == 'disabled' ){
|
122 |
+
|
123 |
+
alert( jQuery(this).attr('title') );
|
124 |
+
return false;
|
125 |
+
|
126 |
+
} else {
|
127 |
+
|
128 |
+
if(confirm(jQuery(this).data('confirmation'))){
|
129 |
+
|
130 |
+
jQuery('<span class="spinner"></span>').css({visibility: 'visible', float: 'none'}).prependTo(jQuery(this).parent());
|
131 |
+
data = {action: 'remove_site_key', repository_id: jQuery(this).data('repository'), nonce: jQuery(this).data('nonce')}
|
132 |
+
jQuery.ajax({url: ajaxurl, type: 'POST', data: data, success: otgs_wp_installer.removed_site_key});
|
133 |
+
}
|
134 |
+
|
135 |
+
}
|
136 |
+
|
137 |
+
return false;
|
138 |
+
},
|
139 |
+
|
140 |
+
removed_site_key: function(){
|
141 |
+
location.reload();
|
142 |
+
},
|
143 |
+
|
144 |
+
update_site_key: function(){
|
145 |
+
var error_wrap = jQuery(this).closest('.otgsi_register_product_wrap').find('.installer-error-box');
|
146 |
+
error_wrap.html('');
|
147 |
+
|
148 |
+
var spinner = jQuery('<span class="spinner"></span>');
|
149 |
+
|
150 |
+
spinner.css({visibility: 'visible', float: 'none'}).prependTo(jQuery(this).parent());
|
151 |
+
data = {action: 'update_site_key', repository_id: jQuery(this).data('repository'), nonce: jQuery(this).data('nonce')}
|
152 |
+
jQuery.ajax({
|
153 |
+
url: ajaxurl,
|
154 |
+
type: 'POST',
|
155 |
+
data: data,
|
156 |
+
dataType: 'json',
|
157 |
+
complete: function( event, xhr, settings ){
|
158 |
+
var error = '';
|
159 |
+
if(xhr == 'success') {
|
160 |
+
var ret = event.responseJSON;
|
161 |
+
if(ret.error){
|
162 |
+
error = ret.error;
|
163 |
+
}else{
|
164 |
+
otgs_wp_installer.updated_site_key(ret);
|
165 |
+
}
|
166 |
+
}else{
|
167 |
+
error = 'Error processing request (' + xhr + '). Please try again!';
|
168 |
+
}
|
169 |
+
|
170 |
+
if( error ){
|
171 |
+
error_wrap.html('<p>' + error + '</p>').show();
|
172 |
+
spinner.remove();
|
173 |
+
}
|
174 |
+
|
175 |
+
}
|
176 |
+
});
|
177 |
+
|
178 |
+
return false;
|
179 |
+
|
180 |
+
},
|
181 |
+
|
182 |
+
updated_site_key: function(ret){
|
183 |
+
location.reload();
|
184 |
+
},
|
185 |
+
|
186 |
+
update_downloads_form: function(){
|
187 |
+
|
188 |
+
var checked = jQuery('.otgsi_downloads_form :checkbox:checked[name="downloads[]"]').length;
|
189 |
+
|
190 |
+
if(checked){
|
191 |
+
jQuery(this).closest('form').find(':submit, :checkbox[name=activate]').removeAttr('disabled');
|
192 |
+
}else{
|
193 |
+
jQuery(this).closest('form').find(':submit, :checkbox[name=activate]').attr('disabled', 'disabled');
|
194 |
+
}
|
195 |
+
|
196 |
+
|
197 |
+
},
|
198 |
+
|
199 |
+
download_downloads: function(){
|
200 |
+
|
201 |
+
var activate = jQuery(this).find(":checkbox:checked[name=activate]").val(),
|
202 |
+
action_button = jQuery(this).find('input[type="submit"]');
|
203 |
+
downloads_form = jQuery(this),
|
204 |
+
idx = 0,
|
205 |
+
checkboxes = [];
|
206 |
+
|
207 |
+
jQuery(this).find(':checkbox:checked[name="downloads[]"]').each(function(){
|
208 |
+
if(jQuery(this).attr('disabled')) return;
|
209 |
+
checkboxes[idx] = jQuery(this);
|
210 |
+
idx++;
|
211 |
+
jQuery(this).attr('disabled', 'disabled');
|
212 |
+
});
|
213 |
+
|
214 |
+
idx = 0;
|
215 |
+
|
216 |
+
if( typeof checkboxes[idx] != 'undefined' ){
|
217 |
+
download_and_activate( checkboxes[idx] );
|
218 |
+
action_button.attr('disabled', 'disabled');
|
219 |
+
}
|
220 |
+
|
221 |
+
function download_and_activate( elem ){
|
222 |
+
|
223 |
+
var this_tr = elem.closest('tr');
|
224 |
+
var is_update = this_tr.find('.installer-red-text').length;
|
225 |
+
if(is_update){
|
226 |
+
var installing = this_tr.find('.installer-status-updating');
|
227 |
+
var installed = this_tr.find('.installer-status-updated');
|
228 |
+
}else{
|
229 |
+
var installing = this_tr.find('.installer-status-installing');
|
230 |
+
var installed = this_tr.find('.installer-status-installed');
|
231 |
+
|
232 |
+
}
|
233 |
+
if(activate){
|
234 |
+
var activating = this_tr.find('.installer-status-activating');
|
235 |
+
var activated = this_tr.find('.installer-status-activated');
|
236 |
+
}
|
237 |
+
|
238 |
+
if( this_tr.find('.for_spinner_js .spinner').length > 0 ){
|
239 |
+
var spinner = this_tr.find('.for_spinner_js .spinner');
|
240 |
+
}else{
|
241 |
+
var spinner = this_tr.find('.installer-status-downloading');
|
242 |
+
}
|
243 |
+
|
244 |
+
otgs_wp_installer.reset_errors();
|
245 |
+
downloads_form.find('div.installer-status-success').hide();
|
246 |
+
spinner.css('visibility', 'visible');
|
247 |
+
installing.show();
|
248 |
+
|
249 |
+
var plugin_name = this_tr.find('.installer_plugin_name').html();
|
250 |
+
if(is_update){
|
251 |
+
otgs_wp_installer.show_download_progress_status(downloads_form, installer_strings.updating.replace('%s', plugin_name));
|
252 |
+
}else{
|
253 |
+
otgs_wp_installer.show_download_progress_status(downloads_form, installer_strings.installing.replace('%s', plugin_name));
|
254 |
+
}
|
255 |
+
|
256 |
+
|
257 |
+
data = {action: 'installer_download_plugin', data: elem.val(), activate: activate}
|
258 |
+
|
259 |
+
jQuery.ajax({
|
260 |
+
url: ajaxurl,
|
261 |
+
type: 'POST',
|
262 |
+
dataType: 'json',
|
263 |
+
data: data,
|
264 |
+
success: function(ret){
|
265 |
+
installing.hide();
|
266 |
+
|
267 |
+
if(!ret.success){
|
268 |
+
installed.addClass('installer-status-error');
|
269 |
+
installed.html(installed.data('fail'));
|
270 |
+
|
271 |
+
if(ret.message){
|
272 |
+
installed.closest('.otgs_wp_installer_table').find('.installer-error-box').html('<p>' + ret.message + '</p>').show();
|
273 |
+
}else{
|
274 |
+
installed.closest('.otgs_wp_installer_table').find('.installer-error-box').html('<p>' + downloads_form.find('.installer-revalidate-message').html() + '</p>').show();
|
275 |
+
}
|
276 |
+
|
277 |
+
|
278 |
+
}
|
279 |
+
|
280 |
+
installed.show();
|
281 |
+
spinner.fadeOut();
|
282 |
+
|
283 |
+
if(ret.version){
|
284 |
+
this_tr.find('.installer_version_installed').html('<span class="installer-green-text">' + ret.version + '</span>');
|
285 |
+
}
|
286 |
+
|
287 |
+
if(ret.success && activate){
|
288 |
+
|
289 |
+
otgs_wp_installer.show_download_progress_status(downloads_form, installer_strings.activating.replace('%s', plugin_name));
|
290 |
+
activating.show();
|
291 |
+
spinner.show();
|
292 |
+
this_tr.find('.installer-red-text').removeClass('installer-red-text').addClass('installer-green-text').html(ret.version);
|
293 |
+
|
294 |
+
jQuery.ajax({
|
295 |
+
url: ajaxurl,
|
296 |
+
type: 'POST',
|
297 |
+
dataType: 'json',
|
298 |
+
data: {action: 'installer_activate_plugin', plugin_id: ret.plugin_id, nonce: ret.nonce},
|
299 |
+
success: function(ret){
|
300 |
+
activating.hide();
|
301 |
+
if(!ret.error ){
|
302 |
+
activated.show();
|
303 |
+
}
|
304 |
+
|
305 |
+
spinner.fadeOut();
|
306 |
+
|
307 |
+
idx++;
|
308 |
+
if( typeof checkboxes[idx] != 'undefined' ){
|
309 |
+
download_and_activate( checkboxes[idx] );
|
310 |
+
}else{
|
311 |
+
otgs_wp_installer.hide_download_progress_status(downloads_form);
|
312 |
+
downloads_form.find('div.installer-status-success').show();
|
313 |
+
action_button.removeAttr('disabled');
|
314 |
+
}
|
315 |
+
}
|
316 |
+
});
|
317 |
+
}else{
|
318 |
+
idx++;
|
319 |
+
if( typeof checkboxes[idx] != 'undefined' ){
|
320 |
+
download_and_activate( checkboxes[idx] );
|
321 |
+
}else{
|
322 |
+
otgs_wp_installer.hide_download_progress_status(downloads_form);
|
323 |
+
downloads_form.find('div.installer-status-success').show();
|
324 |
+
action_button.removeAttr('disabled');
|
325 |
+
}
|
326 |
+
}
|
327 |
+
}
|
328 |
+
|
329 |
+
});
|
330 |
+
|
331 |
+
};
|
332 |
+
|
333 |
+
return false;
|
334 |
+
},
|
335 |
+
|
336 |
+
|
337 |
+
show_download_progress_status: function(downloads_form, text){
|
338 |
+
|
339 |
+
downloads_form.find('.installer-download-progress-status').html(text).fadeIn();
|
340 |
+
|
341 |
+
},
|
342 |
+
|
343 |
+
hide_download_progress_status: function(downloads_form){
|
344 |
+
|
345 |
+
downloads_form.find('.installer-download-progress-status').html('').fadeOut();
|
346 |
+
|
347 |
+
},
|
348 |
+
|
349 |
+
dismiss_nag: function(){
|
350 |
+
|
351 |
+
var thisa = jQuery(this);
|
352 |
+
|
353 |
+
data = {action: 'installer_dismiss_nag', repository: jQuery(this).data('repository')}
|
354 |
+
|
355 |
+
jQuery.ajax({url: ajaxurl, type: 'POST', dataType:'json', data: data, success:
|
356 |
+
function(ret){
|
357 |
+
thisa.closest('.otgs-is-dismissible').remove();
|
358 |
+
}
|
359 |
+
});
|
360 |
+
|
361 |
+
return false;
|
362 |
+
},
|
363 |
+
|
364 |
+
toggle_subpackages: function(){
|
365 |
+
var list = jQuery(this).closest('td').find('.otgs_wp_installer_subtable');
|
366 |
+
|
367 |
+
if(list.is(':visible')){
|
368 |
+
list.slideUp('fast');
|
369 |
+
}else{
|
370 |
+
list.slideDown('fast');
|
371 |
+
}
|
372 |
+
|
373 |
+
|
374 |
+
return false;
|
375 |
+
|
376 |
+
},
|
377 |
+
|
378 |
+
scroll_to_repository: function(){
|
379 |
+
|
380 |
+
var ref = window.location.hash.replace('#', '');
|
381 |
+
|
382 |
+
if(ref) {
|
383 |
+
var split = ref.split('/');
|
384 |
+
var repo = split[0];
|
385 |
+
|
386 |
+
if(typeof split[1] != 'undefined'){
|
387 |
+
var package = split[1];
|
388 |
+
var repo_element = jQuery('#repository-' + repo);
|
389 |
+
|
390 |
+
|
391 |
+
|
392 |
+
if(repo_element.length){
|
393 |
+
|
394 |
+
jQuery('html, body').animate({
|
395 |
+
scrollTop: repo_element.offset().top
|
396 |
+
}, 1000);
|
397 |
+
|
398 |
+
var package_element = jQuery('#repository-' + repo +'_' + package);
|
399 |
+
|
400 |
+
if(package_element.length && !package_element.is(':visible')){
|
401 |
+
package_element.parents('.otgs_wp_installer_subtable').slideDown();
|
402 |
+
package_element.addClass('installer_highlight_package');
|
403 |
+
}
|
404 |
+
|
405 |
+
package_element.find('.button-secondary').removeClass('button-secondary').addClass('button-primary');
|
406 |
+
}
|
407 |
+
}
|
408 |
+
|
409 |
+
}
|
410 |
+
|
411 |
+
}
|
412 |
+
|
413 |
+
|
414 |
+
}
|
415 |
+
|
416 |
+
|
417 |
jQuery(document).ready(otgs_wp_installer.init);
|
library/otgs/installer/res/js/iframeResizer.min.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
-
/*! iFrame Resizer (iframeSizer.min.js ) - v2.6.1 - 2014-09-03
|
2 |
-
* Desc: Force cross domain iframes to size to content.
|
3 |
-
* Requires: iframeResizer.contentWindow.min.js to be loaded into the target frame.
|
4 |
-
* Copyright: (c) 2014 David J. Bradshaw - dave@bradshaw.net
|
5 |
-
* License: MIT
|
6 |
-
*/
|
7 |
-
|
8 |
-
!function(){"use strict";function a(a,b,c){"addEventListener"in window?a.addEventListener(b,c,!1):"attachEvent"in window&&a.attachEvent("on"+b,c)}function b(){var a,b=["moz","webkit","o","ms"];for(a=0;a<b.length&&!w;a+=1)w=window[b[a]+"RequestAnimationFrame"];w||c(" RequestAnimationFrame not supported")}function c(a){y.log&&"object"==typeof console&&console.log(s+"[Host page"+u+"]"+a)}function d(a){function b(){function a(){h(z),f(),y.resizedCallback(z)}i(a,z,"resetPage")}function d(a){var b=a.id;c(" Removing iFrame: "+b),a.parentNode.removeChild(a),y.closedCallback(b),c(" --")}function e(){var a=x.substr(t).split(":");return{iframe:document.getElementById(a[0]),id:a[0],height:a[1],width:a[2],type:a[3]}}function j(a){var b=Number(y["max"+a]),d=Number(y["min"+a]),e=a.toLowerCase(),f=Number(z[e]);if(d>b)throw new Error("Value for min"+a+" can not be greater than max"+a);c(" Checking "+e+" is in range "+d+"-"+b),d>f&&(f=d,c(" Set "+e+" to min value")),f>b&&(f=b,c(" Set "+e+" to max value")),z[e]=""+f}function k(){var b=a.origin,d=z.iframe.src.split("/").slice(0,3).join("/");if(y.checkOrigin&&(c(" Checking connection is from: "+d),""+b!="null"&&b!==d))throw new Error("Unexpected message received from: "+b+" for "+z.iframe.id+". Message was: "+a.data+". This error can be disabled by adding the checkOrigin: false option.");return!0}function l(){return s===(""+x).substr(0,t)}function m(){var a=z.type in{"true":1,"false":1};return a&&c(" Ignoring init message from meta parent page"),a}function n(){var a=x.substr(x.indexOf(":")+r+6);c(" MessageCallback passed: {iframe: "+z.iframe.id+", message: "+a+"}"),y.messageCallback({iframe:z.iframe,message:a}),c(" --")}function o(){if(null===z.iframe)throw new Error("iFrame ("+z.id+") does not exist on "+u);return!0}function q(){c(" Reposition requested from iFrame"),v={x:z.width,y:z.height},f()}function w(){switch(z.type){case"close":d(z.iframe),y.resizedCallback(z);break;case"message":n();break;case"scrollTo":q();break;case"reset":g(z);break;case"init":b(),y.initCallback(z.iframe);break;default:b()}}var x=a.data,z={};l()&&(c(" Received: "+x),z=e(),j("Height"),j("Width"),!m()&&o()&&k()&&(w(),p=!1))}function e(){null===v&&(v={x:void 0!==window.pageXOffset?window.pageXOffset:document.documentElement.scrollLeft,y:void 0!==window.pageYOffset?window.pageYOffset:document.documentElement.scrollTop},c(" Get position: "+v.x+","+v.y))}function f(){null!==v&&(window.scrollTo(v.x,v.y),c(" Set position: "+v.x+","+v.y),v=null)}function g(a){function b(){h(a),j("reset","reset",a.iframe)}c(" Size reset requested by "+("init"===a.type?"host page":"iFrame")),e(),i(b,a,"init")}function h(a){function b(b){a.iframe.style[b]=a[b]+"px",c(" IFrame ("+a.iframe.id+") "+b+" set to "+a[b]+"px")}y.sizeHeight&&b("height"),y.sizeWidth&&b("width")}function i(a,b,d){d!==b.type&&w?(c(" Requesting animation frame"),w(a)):a()}function j(a,b,d){c("["+a+"] Sending msg to iframe ("+b+")"),d.contentWindow.postMessage(s+b,"*")}function k(){function b(){function a(a){1/0!==y[a]&&0!==y[a]&&(k.style[a]=y[a]+"px",c(" Set "+a+" = "+y[a]+"px"))}a("maxHeight"),a("minHeight"),a("maxWidth"),a("minWidth")}function d(a){return""===a&&(k.id=a="iFrameResizer"+o++,c(" Added missing iframe ID: "+a+" ("+k.src+")")),a}function e(){c(" IFrame scrolling "+(y.scrolling?"enabled":"disabled")+" for "+l),k.style.overflow=!1===y.scrolling?"hidden":"auto",k.scrolling=!1===y.scrolling?"no":"yes"}function f(){("number"==typeof y.bodyMargin||"0"===y.bodyMargin)&&(y.bodyMarginV1=y.bodyMargin,y.bodyMargin=""+y.bodyMargin+"px")}function h(){return l+":"+y.bodyMarginV1+":"+y.sizeWidth+":"+y.log+":"+y.interval+":"+y.enablePublicMethods+":"+y.autoResize+":"+y.bodyMargin+":"+y.heightCalculationMethod+":"+y.bodyBackground+":"+y.bodyPadding+":"+y.tolerance}function i(b){a(k,"load",function(){var a=p;j("iFrame.onload",b,k),!a&&y.heightCalculationMethod in x&&g({iframe:k,height:0,width:0,type:"init"})}),j("init",b,k)}var k=this,l=d(k.id);e(),b(),f(),i(h())}function l(a){if("object"!=typeof a)throw new TypeError("Options is not an object.")}function m(){function a(a){if("IFRAME"!==a.tagName.toUpperCase())throw new TypeError("Expected <IFRAME> tag, found <"+a.tagName+">.");k.call(a)}function b(a){a=a||{},l(a);for(var b in z)z.hasOwnProperty(b)&&(y[b]=a.hasOwnProperty(b)?a[b]:z[b])}return function(c,d){b(c),Array.prototype.forEach.call(document.querySelectorAll(d||"iframe"),a)}}function n(a){a.fn.iFrameResize=function(b){return b=b||{},l(b),y=a.extend({},z,b),this.filter("iframe").each(k).end()}}var o=0,p=!0,q="message",r=q.length,s="[iFrameSizer]",t=s.length,u="",v=null,w=window.requestAnimationFrame,x={max:1,scroll:1,bodyScroll:1,documentElementScroll:1},y={},z={autoResize:!0,bodyBackground:null,bodyMargin:null,bodyMarginV1:8,bodyPadding:null,checkOrigin:!0,enablePublicMethods:!1,heightCalculationMethod:"offset",interval:32,log:!1,maxHeight:1/0,maxWidth:1/0,minHeight:0,minWidth:0,scrolling:!1,sizeHeight:!0,sizeWidth:!1,tolerance:0,closedCallback:function(){},initCallback:function(){},messageCallback:function(){},resizedCallback:function(){}};b(),a(window,"message",d),"jQuery"in window&&n(jQuery),"function"==typeof define&&define.amd?define(function(){return m()}):window.iFrameResize=m()}();
|
9 |
-
//# sourceMappingURL=../src/iframeResizer.map
|
10 |
-
|
1 |
+
/*! iFrame Resizer (iframeSizer.min.js ) - v2.6.1 - 2014-09-03
|
2 |
+
* Desc: Force cross domain iframes to size to content.
|
3 |
+
* Requires: iframeResizer.contentWindow.min.js to be loaded into the target frame.
|
4 |
+
* Copyright: (c) 2014 David J. Bradshaw - dave@bradshaw.net
|
5 |
+
* License: MIT
|
6 |
+
*/
|
7 |
+
|
8 |
+
!function(){"use strict";function a(a,b,c){"addEventListener"in window?a.addEventListener(b,c,!1):"attachEvent"in window&&a.attachEvent("on"+b,c)}function b(){var a,b=["moz","webkit","o","ms"];for(a=0;a<b.length&&!w;a+=1)w=window[b[a]+"RequestAnimationFrame"];w||c(" RequestAnimationFrame not supported")}function c(a){y.log&&"object"==typeof console&&console.log(s+"[Host page"+u+"]"+a)}function d(a){function b(){function a(){h(z),f(),y.resizedCallback(z)}i(a,z,"resetPage")}function d(a){var b=a.id;c(" Removing iFrame: "+b),a.parentNode.removeChild(a),y.closedCallback(b),c(" --")}function e(){var a=x.substr(t).split(":");return{iframe:document.getElementById(a[0]),id:a[0],height:a[1],width:a[2],type:a[3]}}function j(a){var b=Number(y["max"+a]),d=Number(y["min"+a]),e=a.toLowerCase(),f=Number(z[e]);if(d>b)throw new Error("Value for min"+a+" can not be greater than max"+a);c(" Checking "+e+" is in range "+d+"-"+b),d>f&&(f=d,c(" Set "+e+" to min value")),f>b&&(f=b,c(" Set "+e+" to max value")),z[e]=""+f}function k(){var b=a.origin,d=z.iframe.src.split("/").slice(0,3).join("/");if(y.checkOrigin&&(c(" Checking connection is from: "+d),""+b!="null"&&b!==d))throw new Error("Unexpected message received from: "+b+" for "+z.iframe.id+". Message was: "+a.data+". This error can be disabled by adding the checkOrigin: false option.");return!0}function l(){return s===(""+x).substr(0,t)}function m(){var a=z.type in{"true":1,"false":1};return a&&c(" Ignoring init message from meta parent page"),a}function n(){var a=x.substr(x.indexOf(":")+r+6);c(" MessageCallback passed: {iframe: "+z.iframe.id+", message: "+a+"}"),y.messageCallback({iframe:z.iframe,message:a}),c(" --")}function o(){if(null===z.iframe)throw new Error("iFrame ("+z.id+") does not exist on "+u);return!0}function q(){c(" Reposition requested from iFrame"),v={x:z.width,y:z.height},f()}function w(){switch(z.type){case"close":d(z.iframe),y.resizedCallback(z);break;case"message":n();break;case"scrollTo":q();break;case"reset":g(z);break;case"init":b(),y.initCallback(z.iframe);break;default:b()}}var x=a.data,z={};l()&&(c(" Received: "+x),z=e(),j("Height"),j("Width"),!m()&&o()&&k()&&(w(),p=!1))}function e(){null===v&&(v={x:void 0!==window.pageXOffset?window.pageXOffset:document.documentElement.scrollLeft,y:void 0!==window.pageYOffset?window.pageYOffset:document.documentElement.scrollTop},c(" Get position: "+v.x+","+v.y))}function f(){null!==v&&(window.scrollTo(v.x,v.y),c(" Set position: "+v.x+","+v.y),v=null)}function g(a){function b(){h(a),j("reset","reset",a.iframe)}c(" Size reset requested by "+("init"===a.type?"host page":"iFrame")),e(),i(b,a,"init")}function h(a){function b(b){a.iframe.style[b]=a[b]+"px",c(" IFrame ("+a.iframe.id+") "+b+" set to "+a[b]+"px")}y.sizeHeight&&b("height"),y.sizeWidth&&b("width")}function i(a,b,d){d!==b.type&&w?(c(" Requesting animation frame"),w(a)):a()}function j(a,b,d){c("["+a+"] Sending msg to iframe ("+b+")"),d.contentWindow.postMessage(s+b,"*")}function k(){function b(){function a(a){1/0!==y[a]&&0!==y[a]&&(k.style[a]=y[a]+"px",c(" Set "+a+" = "+y[a]+"px"))}a("maxHeight"),a("minHeight"),a("maxWidth"),a("minWidth")}function d(a){return""===a&&(k.id=a="iFrameResizer"+o++,c(" Added missing iframe ID: "+a+" ("+k.src+")")),a}function e(){c(" IFrame scrolling "+(y.scrolling?"enabled":"disabled")+" for "+l),k.style.overflow=!1===y.scrolling?"hidden":"auto",k.scrolling=!1===y.scrolling?"no":"yes"}function f(){("number"==typeof y.bodyMargin||"0"===y.bodyMargin)&&(y.bodyMarginV1=y.bodyMargin,y.bodyMargin=""+y.bodyMargin+"px")}function h(){return l+":"+y.bodyMarginV1+":"+y.sizeWidth+":"+y.log+":"+y.interval+":"+y.enablePublicMethods+":"+y.autoResize+":"+y.bodyMargin+":"+y.heightCalculationMethod+":"+y.bodyBackground+":"+y.bodyPadding+":"+y.tolerance}function i(b){a(k,"load",function(){var a=p;j("iFrame.onload",b,k),!a&&y.heightCalculationMethod in x&&g({iframe:k,height:0,width:0,type:"init"})}),j("init",b,k)}var k=this,l=d(k.id);e(),b(),f(),i(h())}function l(a){if("object"!=typeof a)throw new TypeError("Options is not an object.")}function m(){function a(a){if("IFRAME"!==a.tagName.toUpperCase())throw new TypeError("Expected <IFRAME> tag, found <"+a.tagName+">.");k.call(a)}function b(a){a=a||{},l(a);for(var b in z)z.hasOwnProperty(b)&&(y[b]=a.hasOwnProperty(b)?a[b]:z[b])}return function(c,d){b(c),Array.prototype.forEach.call(document.querySelectorAll(d||"iframe"),a)}}function n(a){a.fn.iFrameResize=function(b){return b=b||{},l(b),y=a.extend({},z,b),this.filter("iframe").each(k).end()}}var o=0,p=!0,q="message",r=q.length,s="[iFrameSizer]",t=s.length,u="",v=null,w=window.requestAnimationFrame,x={max:1,scroll:1,bodyScroll:1,documentElementScroll:1},y={},z={autoResize:!0,bodyBackground:null,bodyMargin:null,bodyMarginV1:8,bodyPadding:null,checkOrigin:!0,enablePublicMethods:!1,heightCalculationMethod:"offset",interval:32,log:!1,maxHeight:1/0,maxWidth:1/0,minHeight:0,minWidth:0,scrolling:!1,sizeHeight:!0,sizeWidth:!1,tolerance:0,closedCallback:function(){},initCallback:function(){},messageCallback:function(){},resizedCallback:function(){}};b(),a(window,"message",d),"jQuery"in window&&n(jQuery),"function"==typeof define&&define.amd?define(function(){return m()}):window.iFrameResize=m()}();
|
9 |
+
//# sourceMappingURL=../src/iframeResizer.map
|
10 |
+
|
library/otgs/installer/res/js/installer_theme_install.js
CHANGED
@@ -1,97 +1,97 @@
|
|
1 |
-
jQuery( document ).ready( function( $ ) {
|
2 |
-
|
3 |
-
/** Append OTGS Theme tab */
|
4 |
-
var js_array= installer_theme_install_localize.js_array_installer;
|
5 |
-
|
6 |
-
if (!($.isEmptyObject(js_array))) {
|
7 |
-
//Unempty
|
8 |
-
for(var key in js_array) {
|
9 |
-
//Dont append if we are on commercial plugins tab page and if there are no themes
|
10 |
-
if ((!(js_array[key]['is_commercial_plugin_tab'])) && (!(installer_theme_install_localize.no_associated_themes))) {
|
11 |
-
$('div.wp-filter ul.filter-links').append('<li><a data-sort="'+key+'" href="#">'+ js_array[key]['the_hyperlink_text'] +'</a></li>');
|
12 |
-
}
|
13 |
-
}
|
14 |
-
}
|
15 |
-
|
16 |
-
/** Page load event tab selected identifier */
|
17 |
-
var loaded_browsing_tab=installer_theme_extended_object.getParameterByName('browse');
|
18 |
-
if (loaded_browsing_tab.length > 0) {
|
19 |
-
|
20 |
-
var frontend_tab_selected_tab = loaded_browsing_tab;
|
21 |
-
|
22 |
-
} else if (0 == loaded_browsing_tab.length){
|
23 |
-
|
24 |
-
//WordPress defaults to 'Featured' when theme install is loaded without the browse parameter
|
25 |
-
var frontend_tab_selected_tab = 'featured';
|
26 |
-
}
|
27 |
-
|
28 |
-
/** Prepare data on page load event for AJAX */
|
29 |
-
var data = {
|
30 |
-
action: 'installer_theme_frontend_selected_tab',
|
31 |
-
installer_theme_frontend_selected_tab_nonce: installer_theme_install_localize.installer_theme_frontend_selected_tab_nonce,
|
32 |
-
frontend_tab_selected :frontend_tab_selected_tab
|
33 |
-
};
|
34 |
-
|
35 |
-
//Call AJAX
|
36 |
-
installer_theme_extended_object.doAJAX(data,frontend_tab_selected_tab,js_array);
|
37 |
-
|
38 |
-
/** When user clicks on any tab */
|
39 |
-
$(document).on('click','.filter-links li > a',function () {
|
40 |
-
|
41 |
-
//Get data_sort
|
42 |
-
var data_sort =$(this).attr('data-sort');
|
43 |
-
|
44 |
-
if (data_sort) {
|
45 |
-
//data_sort is set, prepare data
|
46 |
-
var data = {
|
47 |
-
action: 'installer_theme_frontend_selected_tab',
|
48 |
-
installer_theme_frontend_selected_tab_nonce: installer_theme_install_localize.installer_theme_frontend_selected_tab_nonce,
|
49 |
-
frontend_tab_selected : data_sort
|
50 |
-
};
|
51 |
-
|
52 |
-
//Call AJAX
|
53 |
-
installer_theme_extended_object.doAJAX(data,data_sort,js_array);
|
54 |
-
|
55 |
-
}
|
56 |
-
});
|
57 |
-
|
58 |
-
var fullhash = window.location.hash;
|
59 |
-
if (fullhash.length > 0) {
|
60 |
-
var product_selector=fullhash+' '+'.enter_site_key_js';
|
61 |
-
if ($(product_selector).length ) {
|
62 |
-
$(product_selector).click();
|
63 |
-
}
|
64 |
-
}
|
65 |
-
});
|
66 |
-
|
67 |
-
//Installer theme extended JS object for methods
|
68 |
-
var installer_theme_extended_object = {
|
69 |
-
|
70 |
-
getParameterByName: function(name) {
|
71 |
-
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
72 |
-
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
|
73 |
-
results = regex.exec(location.search);
|
74 |
-
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
|
75 |
-
},
|
76 |
-
|
77 |
-
doAJAX: function(data,data_sort,js_array) {
|
78 |
-
|
79 |
-
//We only want to post to AJAX if its an OTGS tab
|
80 |
-
jQuery.post(installer_theme_install_localize.ajaxurl, data, function(response) {
|
81 |
-
//AJAX response
|
82 |
-
var myObject = jQuery.parseJSON(response);
|
83 |
-
if (typeof myObject != "undefined") {
|
84 |
-
if(myObject.hasOwnProperty("output")){
|
85 |
-
var tab_selected= myObject.output;
|
86 |
-
if (data_sort in js_array) {
|
87 |
-
if (!(installer_theme_install_localize.js_array_installer[tab_selected]['registration_status'])) {
|
88 |
-
//Not registered, no theme response
|
89 |
-
var unregistered_message= myObject.unregistered_messages;
|
90 |
-
jQuery('.no-themes').html(unregistered_message);
|
91 |
-
}
|
92 |
-
}
|
93 |
-
}
|
94 |
-
}
|
95 |
-
});
|
96 |
-
}
|
97 |
};
|
1 |
+
jQuery( document ).ready( function( $ ) {
|
2 |
+
|
3 |
+
/** Append OTGS Theme tab */
|
4 |
+
var js_array= installer_theme_install_localize.js_array_installer;
|
5 |
+
|
6 |
+
if (!($.isEmptyObject(js_array))) {
|
7 |
+
//Unempty
|
8 |
+
for(var key in js_array) {
|
9 |
+
//Dont append if we are on commercial plugins tab page and if there are no themes
|
10 |
+
if ((!(js_array[key]['is_commercial_plugin_tab'])) && (!(installer_theme_install_localize.no_associated_themes))) {
|
11 |
+
$('div.wp-filter ul.filter-links').append('<li><a data-sort="'+key+'" href="#">'+ js_array[key]['the_hyperlink_text'] +'</a></li>');
|
12 |
+
}
|
13 |
+
}
|
14 |
+
}
|
15 |
+
|
16 |
+
/** Page load event tab selected identifier */
|
17 |
+
var loaded_browsing_tab=installer_theme_extended_object.getParameterByName('browse');
|
18 |
+
if (loaded_browsing_tab.length > 0) {
|
19 |
+
|
20 |
+
var frontend_tab_selected_tab = loaded_browsing_tab;
|
21 |
+
|
22 |
+
} else if (0 == loaded_browsing_tab.length){
|
23 |
+
|
24 |
+
//WordPress defaults to 'Featured' when theme install is loaded without the browse parameter
|
25 |
+
var frontend_tab_selected_tab = 'featured';
|
26 |
+
}
|
27 |
+
|
28 |
+
/** Prepare data on page load event for AJAX */
|
29 |
+
var data = {
|
30 |
+
action: 'installer_theme_frontend_selected_tab',
|
31 |
+
installer_theme_frontend_selected_tab_nonce: installer_theme_install_localize.installer_theme_frontend_selected_tab_nonce,
|
32 |
+
frontend_tab_selected :frontend_tab_selected_tab
|
33 |
+
};
|
34 |
+
|
35 |
+
//Call AJAX
|
36 |
+
installer_theme_extended_object.doAJAX(data,frontend_tab_selected_tab,js_array);
|
37 |
+
|
38 |
+
/** When user clicks on any tab */
|
39 |
+
$(document).on('click','.filter-links li > a',function () {
|
40 |
+
|
41 |
+
//Get data_sort
|
42 |
+
var data_sort =$(this).attr('data-sort');
|
43 |
+
|
44 |
+
if (data_sort) {
|
45 |
+
//data_sort is set, prepare data
|
46 |
+
var data = {
|
47 |
+
action: 'installer_theme_frontend_selected_tab',
|
48 |
+
installer_theme_frontend_selected_tab_nonce: installer_theme_install_localize.installer_theme_frontend_selected_tab_nonce,
|
49 |
+
frontend_tab_selected : data_sort
|
50 |
+
};
|
51 |
+
|
52 |
+
//Call AJAX
|
53 |
+
installer_theme_extended_object.doAJAX(data,data_sort,js_array);
|
54 |
+
|
55 |
+
}
|
56 |
+
});
|
57 |
+
|
58 |
+
var fullhash = window.location.hash;
|
59 |
+
if (fullhash.length > 0) {
|
60 |
+
var product_selector=fullhash+' '+'.enter_site_key_js';
|
61 |
+
if ($(product_selector).length ) {
|
62 |
+
$(product_selector).click();
|
63 |
+
}
|
64 |
+
}
|
65 |
+
});
|
66 |
+
|
67 |
+
//Installer theme extended JS object for methods
|
68 |
+
var installer_theme_extended_object = {
|
69 |
+
|
70 |
+
getParameterByName: function(name) {
|
71 |
+
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
72 |
+
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
|
73 |
+
results = regex.exec(location.search);
|
74 |
+
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
|
75 |
+
},
|
76 |
+
|
77 |
+
doAJAX: function(data,data_sort,js_array) {
|
78 |
+
|
79 |
+
//We only want to post to AJAX if its an OTGS tab
|
80 |
+
jQuery.post(installer_theme_install_localize.ajaxurl, data, function(response) {
|
81 |
+
//AJAX response
|
82 |
+
var myObject = jQuery.parseJSON(response);
|
83 |
+
if (typeof myObject != "undefined") {
|
84 |
+
if(myObject.hasOwnProperty("output")){
|
85 |
+
var tab_selected= myObject.output;
|
86 |
+
if (data_sort in js_array) {
|
87 |
+
if (!(installer_theme_install_localize.js_array_installer[tab_selected]['registration_status'])) {
|
88 |
+
//Not registered, no theme response
|
89 |
+
var unregistered_message= myObject.unregistered_messages;
|
90 |
+
jQuery('.no-themes').html(unregistered_message);
|
91 |
+
}
|
92 |
+
}
|
93 |
+
}
|
94 |
+
}
|
95 |
+
});
|
96 |
+
}
|
97 |
};
|
library/otgs/installer/templates/downloads-list-compact.php
CHANGED
@@ -1,80 +1,80 @@
|
|
1 |
-
|
2 |
-
<form method="post" class="otgsi_downloads_form">
|
3 |
-
|
4 |
-
<table class="installer-plugins-list-compact">
|
5 |
-
<thead>
|
6 |
-
<tr>
|
7 |
-
<th> </th>
|
8 |
-
<th><?php _e('Plugin', 'installer') ?></th>
|
9 |
-
<th><img src="<?php echo $this->plugin_url() ?>/res/img/globe.png" alt="<?php esc_attr_e('Available', 'installer') ?>" width="16" height="16"></th>
|
10 |
-
<th><img src="<?php echo $this->plugin_url() ?>/res/img/computer.png" alt="<?php esc_attr_e('Installed', 'installer') ?>" width="16" height="16"></th>
|
11 |
-
<th><img src="<?php echo $this->plugin_url() ?>/res/img/dn2.gif" alt="<?php esc_attr_e('Downloading', 'installer') ?>" width="16" height="16"></th>
|
12 |
-
<th><img src="<?php echo $this->plugin_url() ?>/res/img/on.png" alt="<?php esc_attr_e('Activate', 'installer') ?>" width="16" height="16"></th>
|
13 |
-
</tr>
|
14 |
-
</thead>
|
15 |
-
<tbody>
|
16 |
-
<?php foreach($product['downloads'] as $download): ?>
|
17 |
-
<?php if(empty($tr_oddeven) || $tr_oddeven == 'even') $tr_oddeven = 'odd'; else $tr_oddeven = 'even'; ?>
|
18 |
-
<tr class="<?php echo $tr_oddeven ?>">
|
19 |
-
<td>
|
20 |
-
<label>
|
21 |
-
<?php
|
22 |
-
$url = $this->append_site_key_to_download_url($download['url'], $site_key, $repository_id );
|
23 |
-
|
24 |
-
$download_data = array(
|
25 |
-
'url' => $url,
|
26 |
-
'slug' => $download['slug'],
|
27 |
-
'nonce' => wp_create_nonce('install_plugin_' . $url),
|
28 |
-
'repository_id' => $repository_id
|
29 |
-
);
|
30 |
-
|
31 |
-
$disabled = $expired ||
|
32 |
-
(
|
33 |
-
$this->plugin_is_installed($download['name'], $download['slug'], $download['version']) &&
|
34 |
-
!$this->plugin_is_embedded_version($download['name'], $download['slug'])
|
35 |
-
) || WP_Installer()->dependencies->cant_download( $repository_id );
|
36 |
-
|
37 |
-
?>
|
38 |
-
<input type="checkbox" name="downloads[]" value="<?php echo base64_encode(json_encode($download_data)); ?>" <?php
|
39 |
-
if($disabled): ?>disabled="disabled"<?php endif; ?> />
|
40 |
-
|
41 |
-
</label>
|
42 |
-
</td>
|
43 |
-
<td class="installer_plugin_name"><?php echo $download['name'] ?></td>
|
44 |
-
<td><?php echo $download['version'] ?></td>
|
45 |
-
<td class="installer_version_installed">
|
46 |
-
<?php if($v = $this->plugin_is_installed($download['name'], $download['slug'])):
|
47 |
-
$class = version_compare($v, $download['version'], '>=') ? 'installer-green-text' : 'installer-red-text'; ?>
|
48 |
-
<span class="<?php echo $class ?>"><?php echo $v; ?></span>
|
49 |
-
<?php endif; ?>
|
50 |
-
</td>
|
51 |
-
<td class="twelve">
|
52 |
-
<div class="installer-status-downloading"><?php _e('downloading...', 'installer') ?></div>
|
53 |
-
<div class="installer-status-downloaded" data-fail="<?php _e('failed!', 'installer') ?>"><?php _e('downloaded', 'installer') ?></div>
|
54 |
-
</td>
|
55 |
-
<td class="twelve">
|
56 |
-
<div class="installer-status-activating"><?php _e('activating', 'installer') ?></div>
|
57 |
-
<div class="installer-status-activated"><?php _e('activated', 'installer') ?></div>
|
58 |
-
</td>
|
59 |
-
</tr>
|
60 |
-
<?php endforeach; ?>
|
61 |
-
</tbody>
|
62 |
-
</table>
|
63 |
-
|
64 |
-
<?php if( !WP_Installer()->dependencies->is_uploading_allowed() ): ?>
|
65 |
-
<p class="installer-error-box"><?php printf(__('Downloading is not possible because WordPress cannot write into the plugins folder. %sHow to fix%s.', 'installer'),
|
66 |
-
'<a href="http://codex.wordpress.org/Changing_File_Permissions">', '</a>') ?></p>
|
67 |
-
<?php elseif( WP_Installer()->dependencies->is_win_paths_exception($repository_id) ): ?>
|
68 |
-
<p><?php echo WP_Installer()->dependencies->win_paths_exception_message() ?></p>
|
69 |
-
<?php endif;?>
|
70 |
-
|
71 |
-
<br />
|
72 |
-
<input type="submit" class="button-secondary" value="<?php esc_attr_e('Download', 'installer') ?>" disabled="disabled" />
|
73 |
-
|
74 |
-
<label><input name="activate" type="checkbox" value="1" disabled="disabled" /> <?php _e('Activate after download', 'installer') ?></label>
|
75 |
-
|
76 |
-
<div class="installer-download-progress-status"></div>
|
77 |
-
<div class="installer-status-success"><?php _e('Operation complete!', 'installer') ?></div>
|
78 |
-
|
79 |
-
<span class="installer-revalidate-message hidden"><?php _e("Download failed!\n\nClick OK to revalidate your subscription or CANCEL to try again.", 'installer') ?></span>
|
80 |
-
</form>
|
1 |
+
|
2 |
+
<form method="post" class="otgsi_downloads_form">
|
3 |
+
|
4 |
+
<table class="installer-plugins-list-compact">
|
5 |
+
<thead>
|
6 |
+
<tr>
|
7 |
+
<th> </th>
|
8 |
+
<th><?php _e('Plugin', 'installer') ?></th>
|
9 |
+
<th><img src="<?php echo $this->plugin_url() ?>/res/img/globe.png" alt="<?php esc_attr_e('Available', 'installer') ?>" width="16" height="16"></th>
|
10 |
+
<th><img src="<?php echo $this->plugin_url() ?>/res/img/computer.png" alt="<?php esc_attr_e('Installed', 'installer') ?>" width="16" height="16"></th>
|
11 |
+
<th><img src="<?php echo $this->plugin_url() ?>/res/img/dn2.gif" alt="<?php esc_attr_e('Downloading', 'installer') ?>" width="16" height="16"></th>
|
12 |
+
<th><img src="<?php echo $this->plugin_url() ?>/res/img/on.png" alt="<?php esc_attr_e('Activate', 'installer') ?>" width="16" height="16"></th>
|
13 |
+
</tr>
|
14 |
+
</thead>
|
15 |
+
<tbody>
|
16 |
+
<?php foreach($product['downloads'] as $download): ?>
|
17 |
+
<?php if(empty($tr_oddeven) || $tr_oddeven == 'even') $tr_oddeven = 'odd'; else $tr_oddeven = 'even'; ?>
|
18 |
+
<tr class="<?php echo $tr_oddeven ?>">
|
19 |
+
<td>
|
20 |
+
<label>
|
21 |
+
<?php
|
22 |
+
$url = $this->append_site_key_to_download_url($download['url'], $site_key, $repository_id );
|
23 |
+
|
24 |
+
$download_data = array(
|
25 |
+
'url' => $url,
|
26 |
+
'slug' => $download['slug'],
|
27 |
+
'nonce' => wp_create_nonce('install_plugin_' . $url),
|
28 |
+
'repository_id' => $repository_id
|
29 |
+
);
|
30 |
+
|
31 |
+
$disabled = $expired ||
|
32 |
+
(
|
33 |
+
$this->plugin_is_installed($download['name'], $download['slug'], $download['version']) &&
|
34 |
+
!$this->plugin_is_embedded_version($download['name'], $download['slug'])
|
35 |
+
) || WP_Installer()->dependencies->cant_download( $repository_id );
|
36 |
+
|
37 |
+
?>
|
38 |
+
<input type="checkbox" name="downloads[]" value="<?php echo base64_encode(json_encode($download_data)); ?>" <?php
|
39 |
+
if($disabled): ?>disabled="disabled"<?php endif; ?> />
|
40 |
+
|
41 |
+
</label>
|
42 |
+
</td>
|
43 |
+
<td class="installer_plugin_name"><?php echo $download['name'] ?></td>
|
44 |
+
<td><?php echo $download['version'] ?></td>
|
45 |
+
<td class="installer_version_installed">
|
46 |
+
<?php if($v = $this->plugin_is_installed($download['name'], $download['slug'])):
|
47 |
+
$class = version_compare($v, $download['version'], '>=') ? 'installer-green-text' : 'installer-red-text'; ?>
|
48 |
+
<span class="<?php echo $class ?>"><?php echo $v; ?></span>
|
49 |
+
<?php endif; ?>
|
50 |
+
</td>
|
51 |
+
<td class="twelve">
|
52 |
+
<div class="installer-status-downloading"><?php _e('downloading...', 'installer') ?></div>
|
53 |
+
<div class="installer-status-downloaded" data-fail="<?php _e('failed!', 'installer') ?>"><?php _e('downloaded', 'installer') ?></div>
|
54 |
+
</td>
|
55 |
+
<td class="twelve">
|
56 |
+
<div class="installer-status-activating"><?php _e('activating', 'installer') ?></div>
|
57 |
+
<div class="installer-status-activated"><?php _e('activated', 'installer') ?></div>
|
58 |
+
</td>
|
59 |
+
</tr>
|
60 |
+
<?php endforeach; ?>
|
61 |
+
</tbody>
|
62 |
+
</table>
|
63 |
+
|
64 |
+
<?php if( !WP_Installer()->dependencies->is_uploading_allowed() ): ?>
|
65 |
+
<p class="installer-error-box"><?php printf(__('Downloading is not possible because WordPress cannot write into the plugins folder. %sHow to fix%s.', 'installer'),
|
66 |
+
'<a href="http://codex.wordpress.org/Changing_File_Permissions">', '</a>') ?></p>
|
67 |
+
<?php elseif( WP_Installer()->dependencies->is_win_paths_exception($repository_id) ): ?>
|
68 |
+
<p><?php echo WP_Installer()->dependencies->win_paths_exception_message() ?></p>
|
69 |
+
<?php endif;?>
|
70 |
+
|
71 |
+
<br />
|
72 |
+
<input type="submit" class="button-secondary" value="<?php esc_attr_e('Download', 'installer') ?>" disabled="disabled" />
|
73 |
+
|
74 |
+
<label><input name="activate" type="checkbox" value="1" disabled="disabled" /> <?php _e('Activate after download', 'installer') ?></label>
|
75 |
+
|
76 |
+
<div class="installer-download-progress-status"></div>
|
77 |
+
<div class="installer-status-success"><?php _e('Operation complete!', 'installer') ?></div>
|
78 |
+
|
79 |
+
<span class="installer-revalidate-message hidden"><?php _e("Download failed!\n\nClick OK to revalidate your subscription or CANCEL to try again.", 'installer') ?></span>
|
80 |
+
</form>
|
library/otgs/installer/templates/downloads-list.php
CHANGED
@@ -1,85 +1,85 @@
|
|
1 |
-
<br clear="all" /><br />
|
2 |
-
<strong><?php _e('Downloads:', 'installer') ?></strong>
|
3 |
-
|
4 |
-
<form method="post" class="otgsi_downloads_form">
|
5 |
-
|
6 |
-
<table class="widefat">
|
7 |
-
<thead>
|
8 |
-
<tr>
|
9 |
-
<th> </th>
|
10 |
-
<th><?php _e('Plugin', 'installer') ?></th>
|
11 |
-
<th><?php _e('Current version', 'installer') ?></th>
|
12 |
-
<th><?php _e('Released', 'installer') ?></th>
|
13 |
-
<th><?php _e('Installed version', 'installer') ?></th>
|
14 |
-
<th> </th>
|
15 |
-
<th> </th>
|
16 |
-
<th> </th>
|
17 |
-
</tr>
|
18 |
-
</thead>
|
19 |
-
<tbody>
|
20 |
-
<?php
|
21 |
-
foreach($package['downloads'] as $download): ?>
|
22 |
-
<tr>
|
23 |
-
<td>
|
24 |
-
<label>
|
25 |
-
<?php
|
26 |
-
$url = $this->append_site_key_to_download_url($download['url'], $site_key, $repository_id);
|
27 |
-
|
28 |
-
$download_data = array(
|
29 |
-
'url' => $url,
|
30 |
-
'slug' => $download['slug'],
|
31 |
-
'nonce' => wp_create_nonce('install_plugin_' . $url),
|
32 |
-
'repository_id' => $repository_id
|
33 |
-
);
|
34 |
-
?>
|
35 |
-
<input type="checkbox" name="downloads[]" value="<?php echo base64_encode(json_encode($download_data)); ?>" <?php
|
36 |
-
if($this->plugin_is_installed($download['name'], $download['slug'], $download['version']) && !$this->plugin_is_embedded_version($download['name'], $download['slug']) || WP_Installer()->dependencies->cant_download($repository_id) ): ?>disabled="disabled"<?php endif; ?> />
|
37 |
-
|
38 |
-
</label>
|
39 |
-
</td>
|
40 |
-
<td class="installer_plugin_name"><?php echo $download['name'] ?></td>
|
41 |
-
<td><?php echo $download['version'] ?></td>
|
42 |
-
<td><?php echo date_i18n('F j, Y', strtotime($download['date'])) ?></td>
|
43 |
-
<td class="installer_version_installed">
|
44 |
-
<?php if($v = $this->plugin_is_installed($download['name'], $download['slug'])): $class = version_compare($v, $download['version'], '>=') ? 'installer-green-text' : 'installer-red-text'; ?>
|
45 |
-
<span class="<?php echo $class ?>"><?php echo $v; ?></span>
|
46 |
-
<?php if($this->plugin_is_embedded_version($download['name'], $download['slug'])): ?> <?php _e('(embedded)', 'installer'); ?><?php endif; ?>
|
47 |
-
<?php endif; ?>
|
48 |
-
</td>
|
49 |
-
<td>
|
50 |
-
<span class="installer-status-installing"><?php _e('installing...', 'installer') ?></span>
|
51 |
-
<span class="installer-status-updating"><?php _e('updating...', 'installer') ?></span>
|
52 |
-
<span class="installer-status-installed" data-fail="<?php _e('failed!', 'installer') ?>"><?php _e('installed', 'installer') ?></span>
|
53 |
-
<span class="installer-status-updated" data-fail="<?php _e('failed!', 'installer') ?>"><?php _e('updated', 'installer') ?></span>
|
54 |
-
</td>
|
55 |
-
<td>
|
56 |
-
<span class="installer-status-activating"><?php _e('activating', 'installer') ?></span>
|
57 |
-
<span class="installer-status-activated"><?php _e('activated', 'installer') ?></span>
|
58 |
-
</td>
|
59 |
-
<td class="for_spinner_js"><span class="spinner"></span></td>
|
60 |
-
</tr>
|
61 |
-
<?php endforeach; ?>
|
62 |
-
</tbody>
|
63 |
-
</table>
|
64 |
-
|
65 |
-
<br />
|
66 |
-
|
67 |
-
<div class="installer-error-box">
|
68 |
-
<?php if( !WP_Installer()->dependencies->is_uploading_allowed() ): ?>
|
69 |
-
<p><?php printf(__('Downloading is not possible because WordPress cannot write into the plugins folder. %sHow to fix%s.', 'installer'),
|
70 |
-
'<a href="http://codex.wordpress.org/Changing_File_Permissions">', '</a>') ?></p>
|
71 |
-
<?php elseif( WP_Installer()->dependencies->is_win_paths_exception($repository_id) ): ?>
|
72 |
-
<p><?php echo WP_Installer()->dependencies->win_paths_exception_message() ?></p>
|
73 |
-
<?php endif; ?>
|
74 |
-
</div>
|
75 |
-
|
76 |
-
<input type="submit" class="button-secondary" value="<?php esc_attr_e('Download', 'installer') ?>" disabled="disabled" />
|
77 |
-
|
78 |
-
<label><input name="activate" type="checkbox" value="1" disabled="disabled" /> <?php _e('Activate after download', 'installer') ?></label>
|
79 |
-
|
80 |
-
<div class="installer-download-progress-status"></div>
|
81 |
-
|
82 |
-
<div class="installer-status-success"><?php _e('Operation complete!', 'installer') ?></div>
|
83 |
-
|
84 |
-
<span class="installer-revalidate-message hidden"><?php _e("Download failed!\n\nPlease refresh the page and try again.", 'installer') ?></span>
|
85 |
-
</form>
|
1 |
+
<br clear="all" /><br />
|
2 |
+
<strong><?php _e('Downloads:', 'installer') ?></strong>
|
3 |
+
|
4 |
+
<form method="post" class="otgsi_downloads_form">
|
5 |
+
|
6 |
+
<table class="widefat">
|
7 |
+
<thead>
|
8 |
+
<tr>
|
9 |
+
<th> </th>
|
10 |
+
<th><?php _e('Plugin', 'installer') ?></th>
|
11 |
+
<th><?php _e('Current version', 'installer') ?></th>
|
12 |
+
<th><?php _e('Released', 'installer') ?></th>
|
13 |
+
<th><?php _e('Installed version', 'installer') ?></th>
|
14 |
+
<th> </th>
|
15 |
+
<th> </th>
|
16 |
+
<th> </th>
|
17 |
+
</tr>
|
18 |
+
</thead>
|
19 |
+
<tbody>
|
20 |
+
<?php
|
21 |
+
foreach($package['downloads'] as $download): ?>
|
22 |
+
<tr>
|
23 |
+
<td>
|
24 |
+
<label>
|
25 |
+
<?php
|
26 |
+
$url = $this->append_site_key_to_download_url($download['url'], $site_key, $repository_id);
|
27 |
+
|
28 |
+
$download_data = array(
|
29 |
+
'url' => $url,
|
30 |
+
'slug' => $download['slug'],
|
31 |
+
'nonce' => wp_create_nonce('install_plugin_' . $url),
|
32 |
+
'repository_id' => $repository_id
|
33 |
+
);
|
34 |
+
?>
|
35 |
+
<input type="checkbox" name="downloads[]" value="<?php echo base64_encode(json_encode($download_data)); ?>" <?php
|
36 |
+
if($this->plugin_is_installed($download['name'], $download['slug'], $download['version']) && !$this->plugin_is_embedded_version($download['name'], $download['slug']) || WP_Installer()->dependencies->cant_download($repository_id) ): ?>disabled="disabled"<?php endif; ?> />
|
37 |
+
|
38 |
+
</label>
|
39 |
+
</td>
|
40 |
+
<td class="installer_plugin_name"><?php echo $download['name'] ?></td>
|
41 |
+
<td><?php echo $download['version'] ?></td>
|
42 |
+
<td><?php echo date_i18n('F j, Y', strtotime($download['date'])) ?></td>
|
43 |
+
<td class="installer_version_installed">
|
44 |
+
<?php if($v = $this->plugin_is_installed($download['name'], $download['slug'])): $class = version_compare($v, $download['version'], '>=') ? 'installer-green-text' : 'installer-red-text'; ?>
|
45 |
+
<span class="<?php echo $class ?>"><?php echo $v; ?></span>
|
46 |
+
<?php if($this->plugin_is_embedded_version($download['name'], $download['slug'])): ?> <?php _e('(embedded)', 'installer'); ?><?php endif; ?>
|
47 |
+
<?php endif; ?>
|
48 |
+
</td>
|
49 |
+
<td>
|
50 |
+
<span class="installer-status-installing"><?php _e('installing...', 'installer') ?></span>
|
51 |
+
<span class="installer-status-updating"><?php _e('updating...', 'installer') ?></span>
|
52 |
+
<span class="installer-status-installed" data-fail="<?php _e('failed!', 'installer') ?>"><?php _e('installed', 'installer') ?></span>
|
53 |
+
<span class="installer-status-updated" data-fail="<?php _e('failed!', 'installer') ?>"><?php _e('updated', 'installer') ?></span>
|
54 |
+
</td>
|
55 |
+
<td>
|
56 |
+
<span class="installer-status-activating"><?php _e('activating', 'installer') ?></span>
|
57 |
+
<span class="installer-status-activated"><?php _e('activated', 'installer') ?></span>
|
58 |
+
</td>
|
59 |
+
<td class="for_spinner_js"><span class="spinner"></span></td>
|
60 |
+
</tr>
|
61 |
+
<?php endforeach; ?>
|
62 |
+
</tbody>
|
63 |
+
</table>
|
64 |
+
|
65 |
+
<br />
|
66 |
+
|
67 |
+
<div class="installer-error-box">
|
68 |
+
<?php if( !WP_Installer()->dependencies->is_uploading_allowed() ): ?>
|
69 |
+
<p><?php printf(__('Downloading is not possible because WordPress cannot write into the plugins folder. %sHow to fix%s.', 'installer'),
|
70 |
+
'<a href="http://codex.wordpress.org/Changing_File_Permissions">', '</a>') ?></p>
|
71 |
+
<?php elseif( WP_Installer()->dependencies->is_win_paths_exception($repository_id) ): ?>
|
72 |
+
<p><?php echo WP_Installer()->dependencies->win_paths_exception_message() ?></p>
|
73 |
+
<?php endif; ?>
|
74 |
+
</div>
|
75 |
+
|
76 |
+
<input type="submit" class="button-secondary" value="<?php esc_attr_e('Download', 'installer') ?>" disabled="disabled" />
|
77 |
+
|
78 |
+
<label><input name="activate" type="checkbox" value="1" disabled="disabled" /> <?php _e('Activate after download', 'installer') ?></label>
|
79 |
+
|
80 |
+
<div class="installer-download-progress-status"></div>
|
81 |
+
|
82 |
+
<div class="installer-status-success"><?php _e('Operation complete!', 'installer') ?></div>
|
83 |
+
|
84 |
+
<span class="installer-revalidate-message hidden"><?php _e("Download failed!\n\nPlease refresh the page and try again.", 'installer') ?></span>
|
85 |
+
</form>
|
library/otgs/installer/templates/products-compact.php
CHANGED
@@ -1,147 +1,147 @@
|
|
1 |
-
<h3><?php echo $args['box_title'] ?></h3>
|
2 |
-
|
3 |
-
<?php
|
4 |
-
if(empty($args['repository']) || empty($args['package']) || empty($args['product'])){
|
5 |
-
echo __('Incorrect setup', 'installer');
|
6 |
-
return;
|
7 |
-
}
|
8 |
-
|
9 |
-
$product = false;
|
10 |
-
foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package_idx => $package){
|
11 |
-
|
12 |
-
//pre 1.3 backwardds compatibility
|
13 |
-
if(!isset($package['id'])){
|
14 |
-
$package['id'] = sanitize_title_with_dashes($package['name']);
|
15 |
-
}
|
16 |
-
|
17 |
-
if($package['id'] == $args['package']){
|
18 |
-
$product = $this->settings['repositories'][$repository_id]['data']['packages'][$package_idx]['products'][$args['product']];
|
19 |
-
break;
|
20 |
-
}
|
21 |
-
}
|
22 |
-
|
23 |
-
|
24 |
-
if(!$product){
|
25 |
-
echo __('Invalid product', 'installer');
|
26 |
-
return;
|
27 |
-
}
|
28 |
-
|
29 |
-
if(isset($this->settings['repositories'][$repository_id])){
|
30 |
-
if(isset($this->settings['repositories'][$repository_id]['subscription']['key'])){
|
31 |
-
$site_key = $this->settings['repositories'][$repository_id]['subscription']['key'];
|
32 |
-
}else{
|
33 |
-
$site_key = false;
|
34 |
-
}
|
35 |
-
}else{
|
36 |
-
echo __('Unknown repository', 'installer');
|
37 |
-
return;
|
38 |
-
}
|
39 |
-
|
40 |
-
$subscription_type = $this->get_subscription_type_for_repository($repository_id);
|
41 |
-
$expired = false;
|
42 |
-
|
43 |
-
if($subscription_type != $product['subscription_type'] && !$this->have_superior_subscription($subscription_type, $product) && $site_key){
|
44 |
-
$subscription_no_match = sprintf(__(' Your current site key (%s) does not match the selected product (%s).', 'installer'), $site_key, $product['name']);
|
45 |
-
}
|
46 |
-
|
47 |
-
if(!isset($args['product_name'])) $args['product_name'] = $product['name'];
|
48 |
-
|
49 |
-
?>
|
50 |
-
|
51 |
-
<div class="otgs_wp_installer_table otgs_wp_installer_table_compact">
|
52 |
-
|
53 |
-
<p><?php echo $args['box_description'] ?></p>
|
54 |
-
|
55 |
-
|
56 |
-
<?php if(!$this->repository_has_subscription($repository_id) || !empty($subscription_no_match)): ?>
|
57 |
-
|
58 |
-
<?php if(!empty($subscription_no_match)): ?>
|
59 |
-
<div class="installer-warn-box">
|
60 |
-
<?php echo $subscription_no_match; ?>
|
61 |
-
</div>
|
62 |
-
<br />
|
63 |
-
<?php endif; ?>
|
64 |
-
|
65 |
-
<a class="button-primary" href="<?php echo $this->append_parameters_to_buy_url($product['url'], $repository_id, $args) ?>"><?php printf(__('Buy %s', 'installer'), $args['product_name']) ?></a>
|
66 |
-
|
67 |
-
<div>
|
68 |
-
<br />
|
69 |
-
<?php printf(__('Already bought %s?', 'installer'), $args['product_name']) ?>
|
70 |
-
<a class="enter_site_key_js<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?> disabled<?php endif ?>" href="#"
|
71 |
-
<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
|
72 |
-
style="cursor: help"
|
73 |
-
disabled="disabled"
|
74 |
-
title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to register.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
|
75 |
-
<?php endif; ?>
|
76 |
-
>
|
77 |
-
<?php _e('Enter site key', 'installer') ?>
|
78 |
-
</a>
|
79 |
-
|
80 |
-
<form class="otgsi_site_key_form" method="post">
|
81 |
-
<input type="hidden" name="action" value="save_site_key" />
|
82 |
-
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce('save_site_key_' . $repository_id) ?>" />
|
83 |
-
<input type="hidden" name="repository_id" value="<?php echo $repository_id ?>">
|
84 |
-
<input type="text" size="10" name="site_key_<?php echo $repository_id ?>" />
|
85 |
-
<input class="button-secondary" type="submit" value="<?php esc_attr_e('Add', 'installer') ?>" />
|
86 |
-
</form>
|
87 |
-
<div class="installer-error-box hidden" style="margin-top:10px;"></div>
|
88 |
-
</div>
|
89 |
-
|
90 |
-
<?php else: ?>
|
91 |
-
|
92 |
-
<?php if($this->repository_has_expired_subscription($repository_id)): $expired = true; ?>
|
93 |
-
|
94 |
-
<div><p class="installer-warn-box"><?php _e('Subscription is expired.', 'installer') ?></p></div>
|
95 |
-
|
96 |
-
<?php else: ?>
|
97 |
-
|
98 |
-
<?php if($this->show_subscription_renew_warning($repository_id, $subscription_type)): ?>
|
99 |
-
|
100 |
-
<ul class="installer-products-list">
|
101 |
-
<?php foreach($product['renewals'] as $renewal): ?>
|
102 |
-
<li>
|
103 |
-
<a href="<?php echo $this->append_parameters_to_buy_url($renewal['url'], $repository_id, $args) ?>"><?php printf(__('Renew %s', 'installer'), $args['product_name']) ?></a>
|
104 |
-
</li>
|
105 |
-
<?php endforeach; ?>
|
106 |
-
</ul>
|
107 |
-
|
108 |
-
<?php endif; ?>
|
109 |
-
|
110 |
-
<?php endif; ?>
|
111 |
-
|
112 |
-
<center>
|
113 |
-
<a class="remove_site_key_js" href="#" data-repository=<?php echo $repository_id ?>
|
114 |
-
data-confirmation="<?php esc_attr_e('Are you sure you want to remove this site key?', 'installer') ?>"
|
115 |
-
data-nonce="<?php echo wp_create_nonce('remove_site_key_' . $repository_id) ?>"
|
116 |
-
<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
|
117 |
-
style="cursor: help;color:#999999"
|
118 |
-
disabled="disabled"
|
119 |
-
title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to unregister.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
|
120 |
-
<?php endif; ?>
|
121 |
-
>
|
122 |
-
<?php printf(__("Remove current site key (%s)", 'installer'), $site_key) ?>
|
123 |
-
</a>
|
124 |
-
</center>
|
125 |
-
<br />
|
126 |
-
|
127 |
-
<?php include $this->plugin_path() . '/templates/downloads-list-compact.php'; ?>
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
<?php endif; ?>
|
132 |
-
|
133 |
-
<?php
|
134 |
-
if( isset( $args[ 'name' ] ) ):
|
135 |
-
$support_link = $this->get_support_tag_by_name($args['name'], $args['repository']); ?>
|
136 |
-
|
137 |
-
<?php if($support_link): ?>
|
138 |
-
<p><a href="<?php echo $support_link ?>" target="_blank"><?php printf(__('%s support on wpml.org', 'installer'), $args['name'] ) ?></a></p>
|
139 |
-
|
140 |
-
<?php endif; ?>
|
141 |
-
<?php
|
142 |
-
// compatibility for installer 1.1
|
143 |
-
elseif( isset( $args[ 'support_link' ] ) ): ?>
|
144 |
-
<p><?php echo $args[ 'support_link' ]; ?></p>
|
145 |
-
<?php endif; ?>
|
146 |
-
|
147 |
-
</div>
|
1 |
+
<h3><?php echo $args['box_title'] ?></h3>
|
2 |
+
|
3 |
+
<?php
|
4 |
+
if(empty($args['repository']) || empty($args['package']) || empty($args['product'])){
|
5 |
+
echo __('Incorrect setup', 'installer');
|
6 |
+
return;
|
7 |
+
}
|
8 |
+
|
9 |
+
$product = false;
|
10 |
+
foreach($this->settings['repositories'][$repository_id]['data']['packages'] as $package_idx => $package){
|
11 |
+
|
12 |
+
//pre 1.3 backwardds compatibility
|
13 |
+
if(!isset($package['id'])){
|
14 |
+
$package['id'] = sanitize_title_with_dashes($package['name']);
|
15 |
+
}
|
16 |
+
|
17 |
+
if($package['id'] == $args['package']){
|
18 |
+
$product = $this->settings['repositories'][$repository_id]['data']['packages'][$package_idx]['products'][$args['product']];
|
19 |
+
break;
|
20 |
+
}
|
21 |
+
}
|
22 |
+
|
23 |
+
|
24 |
+
if(!$product){
|
25 |
+
echo __('Invalid product', 'installer');
|
26 |
+
return;
|
27 |
+
}
|
28 |
+
|
29 |
+
if(isset($this->settings['repositories'][$repository_id])){
|
30 |
+
if(isset($this->settings['repositories'][$repository_id]['subscription']['key'])){
|
31 |
+
$site_key = $this->settings['repositories'][$repository_id]['subscription']['key'];
|
32 |
+
}else{
|
33 |
+
$site_key = false;
|
34 |
+
}
|
35 |
+
}else{
|
36 |
+
echo __('Unknown repository', 'installer');
|
37 |
+
return;
|
38 |
+
}
|
39 |
+
|
40 |
+
$subscription_type = $this->get_subscription_type_for_repository($repository_id);
|
41 |
+
$expired = false;
|
42 |
+
|
43 |
+
if($subscription_type != $product['subscription_type'] && !$this->have_superior_subscription($subscription_type, $product) && $site_key){
|
44 |
+
$subscription_no_match = sprintf(__(' Your current site key (%s) does not match the selected product (%s).', 'installer'), $site_key, $product['name']);
|
45 |
+
}
|
46 |
+
|
47 |
+
if(!isset($args['product_name'])) $args['product_name'] = $product['name'];
|
48 |
+
|
49 |
+
?>
|
50 |
+
|
51 |
+
<div class="otgs_wp_installer_table otgs_wp_installer_table_compact">
|
52 |
+
|
53 |
+
<p><?php echo $args['box_description'] ?></p>
|
54 |
+
|
55 |
+
|
56 |
+
<?php if(!$this->repository_has_subscription($repository_id) || !empty($subscription_no_match)): ?>
|
57 |
+
|
58 |
+
<?php if(!empty($subscription_no_match)): ?>
|
59 |
+
<div class="installer-warn-box">
|
60 |
+
<?php echo $subscription_no_match; ?>
|
61 |
+
</div>
|
62 |
+
<br />
|
63 |
+
<?php endif; ?>
|
64 |
+
|
65 |
+
<a class="button-primary" href="<?php echo $this->append_parameters_to_buy_url($product['url'], $repository_id, $args) ?>"><?php printf(__('Buy %s', 'installer'), $args['product_name']) ?></a>
|
66 |
+
|
67 |
+
<div>
|
68 |
+
<br />
|
69 |
+
<?php printf(__('Already bought %s?', 'installer'), $args['product_name']) ?>
|
70 |
+
<a class="enter_site_key_js<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?> disabled<?php endif ?>" href="#"
|
71 |
+
<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
|
72 |
+
style="cursor: help"
|
73 |
+
disabled="disabled"
|
74 |
+
title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to register.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
|
75 |
+
<?php endif; ?>
|
76 |
+
>
|
77 |
+
<?php _e('Enter site key', 'installer') ?>
|
78 |
+
</a>
|
79 |
+
|
80 |
+
<form class="otgsi_site_key_form" method="post">
|
81 |
+
<input type="hidden" name="action" value="save_site_key" />
|
82 |
+
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce('save_site_key_' . $repository_id) ?>" />
|
83 |
+
<input type="hidden" name="repository_id" value="<?php echo $repository_id ?>">
|
84 |
+
<input type="text" size="10" name="site_key_<?php echo $repository_id ?>" />
|
85 |
+
<input class="button-secondary" type="submit" value="<?php esc_attr_e('Add', 'installer') ?>" />
|
86 |
+
</form>
|
87 |
+
<div class="installer-error-box hidden" style="margin-top:10px;"></div>
|
88 |
+
</div>
|
89 |
+
|
90 |
+
<?php else: ?>
|
91 |
+
|
92 |
+
<?php if($this->repository_has_expired_subscription($repository_id)): $expired = true; ?>
|
93 |
+
|
94 |
+
<div><p class="installer-warn-box"><?php _e('Subscription is expired.', 'installer') ?></p></div>
|
95 |
+
|
96 |
+
<?php else: ?>
|
97 |
+
|
98 |
+
<?php if($this->show_subscription_renew_warning($repository_id, $subscription_type)): ?>
|
99 |
+
|
100 |
+
<ul class="installer-products-list">
|
101 |
+
<?php foreach($product['renewals'] as $renewal): ?>
|
102 |
+
<li>
|
103 |
+
<a href="<?php echo $this->append_parameters_to_buy_url($renewal['url'], $repository_id, $args) ?>"><?php printf(__('Renew %s', 'installer'), $args['product_name']) ?></a>
|
104 |
+
</li>
|
105 |
+
<?php endforeach; ?>
|
106 |
+
</ul>
|
107 |
+
|
108 |
+
<?php endif; ?>
|
109 |
+
|
110 |
+
<?php endif; ?>
|
111 |
+
|
112 |
+
<center>
|
113 |
+
<a class="remove_site_key_js" href="#" data-repository=<?php echo $repository_id ?>
|
114 |
+
data-confirmation="<?php esc_attr_e('Are you sure you want to remove this site key?', 'installer') ?>"
|
115 |
+
data-nonce="<?php echo wp_create_nonce('remove_site_key_' . $repository_id) ?>"
|
116 |
+
<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
|
117 |
+
style="cursor: help;color:#999999"
|
118 |
+
disabled="disabled"
|
119 |
+
title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to unregister.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
|
120 |
+
<?php endif; ?>
|
121 |
+
>
|
122 |
+
<?php printf(__("Remove current site key (%s)", 'installer'), $site_key) ?>
|
123 |
+
</a>
|
124 |
+
</center>
|
125 |
+
<br />
|
126 |
+
|
127 |
+
<?php include $this->plugin_path() . '/templates/downloads-list-compact.php'; ?>
|
128 |
+
|
129 |
+
|
130 |
+
|
131 |
+
<?php endif; ?>
|
132 |
+
|
133 |
+
<?php
|
134 |
+
if( isset( $args[ 'name' ] ) ):
|
135 |
+
$support_link = $this->get_support_tag_by_name($args['name'], $args['repository']); ?>
|
136 |
+
|
137 |
+
<?php if($support_link): ?>
|
138 |
+
<p><a href="<?php echo $support_link ?>" target="_blank"><?php printf(__('%s support on wpml.org', 'installer'), $args['name'] ) ?></a></p>
|
139 |
+
|
140 |
+
<?php endif; ?>
|
141 |
+
<?php
|
142 |
+
// compatibility for installer 1.1
|
143 |
+
elseif( isset( $args[ 'support_link' ] ) ): ?>
|
144 |
+
<p><?php echo $args[ 'support_link' ]; ?></p>
|
145 |
+
<?php endif; ?>
|
146 |
+
|
147 |
+
</div>
|
library/otgs/installer/templates/repository-listing.php
CHANGED
@@ -1,196 +1,196 @@
|
|
1 |
-
<?php if((!$this->repository_has_subscription($repository_id) && $match = $this->get_matching_cp($repository)) && $match['exp']): ?>
|
2 |
-
<p class="alignright installer_highlight"><strong><?php printf('Price offers available until %s', date_i18n(get_option( 'date_format' ), $match['exp'])) ?></strong></p>
|
3 |
-
<?php endif; ?>
|
4 |
-
|
5 |
-
<h3 id="repository-<?php echo $repository_id ?>"><?php echo $repository['data']['name'] ?></h3>
|
6 |
-
<?php
|
7 |
-
$generic_product_name = $this->settings['repositories'][$repository_id]['data']['product-name'];
|
8 |
-
?>
|
9 |
-
<table class="widefat otgs_wp_installer_table" id="installer_repo_<?php echo $repository_id ?>">
|
10 |
-
|
11 |
-
<tr>
|
12 |
-
<td> </td>
|
13 |
-
<td class="otgsi_register_product_wrap" align="center" valign="top">
|
14 |
-
<?php // IF NO SUBSCRIPTION ?>
|
15 |
-
<?php if(!$this->repository_has_subscription($repository_id)): ?>
|
16 |
-
|
17 |
-
<div style="text-align: right;">
|
18 |
-
<span><?php _e('Already bought?', 'installer'); ?> </span>
|
19 |
-
<a class="enter_site_key_js button-primary<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?> disabled<?php endif ?>" href="#"
|
20 |
-
<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
|
21 |
-
style="cursor: help"
|
22 |
-
disabled="disabled"
|
23 |
-
title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to register.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
|
24 |
-
<?php endif; ?>
|
25 |
-
>
|
26 |
-
<?php printf(__('Register %s', 'installer'), $generic_product_name); ?>
|
27 |
-
</a>
|
28 |
-
<form class="otgsi_site_key_form" method="post">
|
29 |
-
<input type="hidden" name="action" value="save_site_key" />
|
30 |
-
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce('save_site_key_' . $repository_id) ?>" />
|
31 |
-
<input type="hidden" name="repository_id" value="<?php echo $repository_id ?>">
|
32 |
-
<?php _e('2. Enter your site key', 'installer'); ?>
|
33 |
-
<input type="text" size="10" name="site_key_<?php echo $repository_id ?>" placeholder="<?php echo esc_attr('site key') ?>" />
|
34 |
-
<input class="button-primary" type="submit" value="<?php esc_attr_e('OK', 'installer') ?>" />
|
35 |
-
<input class="button-secondary cancel_site_key_js" type="button" value="<?php esc_attr_e('Cancel', 'installer') ?>" />
|
36 |
-
|
37 |
-
<div class="alignleft" style="margin-top:6px;"><?php printf(__('1. Go to your %s%s account%s and add this site URL: %s', 'installer'),
|
38 |
-
'<a href="' . $this->settings['repositories'][$repository_id]['data']['site_keys_management_url'] . '?add='.urlencode($this->get_installer_site_url( $repository_id )).'">',
|
39 |
-
$generic_product_name, '</a>', $this->get_installer_site_url( $repository_id )); ?></div>
|
40 |
-
</form>
|
41 |
-
|
42 |
-
|
43 |
-
</div>
|
44 |
-
|
45 |
-
<?php
|
46 |
-
$site_key = false;
|
47 |
-
|
48 |
-
// IF SUBSCRIPTION
|
49 |
-
else:
|
50 |
-
|
51 |
-
$site_key = $this->settings['repositories'][$repository_id]['subscription']['key'];
|
52 |
-
$subscription_type = $this->get_subscription_type_for_repository($repository_id);
|
53 |
-
$upgrade_options = $this->get_upgrade_options($repository_id);
|
54 |
-
$expired = false;
|
55 |
-
|
56 |
-
?>
|
57 |
-
|
58 |
-
<?php if($this->repository_has_expired_subscription($repository_id)): $expired = true; ?>
|
59 |
-
<div>
|
60 |
-
<p class="installer-warn-box">
|
61 |
-
<?php _e('Subscription expired. You need to either purchase a new subscription or upgrade if available.', 'installer') ?>
|
62 |
-
<span class="alignright">
|
63 |
-
<a class="update_site_key_js button-secondary" href="#" data-repository=<?php echo $repository_id ?> data-nonce="<?php echo wp_create_nonce('update_site_key_' . $repository_id) ?>">
|
64 |
-
<?php _e('Revalidate subscription', 'installer'); ?>
|
65 |
-
</a>
|
66 |
-
</span>
|
67 |
-
<br />
|
68 |
-
<span class="details"><?php _e("If you have already purchased or renewed your subscription and you can still see this message, please revalidate your subscription", 'installer') ?></span>
|
69 |
-
</p>
|
70 |
-
</div>
|
71 |
-
<?php else: ?>
|
72 |
-
<?php $this->show_subscription_renew_warning($repository_id, $subscription_type); ?>
|
73 |
-
<?php endif; ?>
|
74 |
-
|
75 |
-
<div class="alignright">
|
76 |
-
<a class="remove_site_key_js button-secondary" href="#" data-repository=<?php echo $repository_id ?>
|
77 |
-
data-confirmation="<?php esc_attr_e('Are you sure you want to unregister?', 'installer') ?>"
|
78 |
-
data-nonce="<?php echo wp_create_nonce('remove_site_key_' . $repository_id) ?>"
|
79 |
-
<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
|
80 |
-
style="cursor: help"
|
81 |
-
disabled="disabled"
|
82 |
-
title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to unregister.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
|
83 |
-
<?php endif; ?>
|
84 |
-
>
|
85 |
-
<?php printf(__("Unregister %s from this site", 'installer'), $generic_product_name) ?></a>
|
86 |
-
<a class="update_site_key_js button-secondary" href="#" data-repository=<?php echo $repository_id ?>
|
87 |
-
data-nonce="<?php echo wp_create_nonce('update_site_key_' . $repository_id) ?>">
|
88 |
-
<?php _e('Check for updates', 'installer'); ?>
|
89 |
-
</a>
|
90 |
-
</div>
|
91 |
-
|
92 |
-
<?php if(empty($expired)): ?>
|
93 |
-
<div class="alignleft">
|
94 |
-
<?php if($expires = $this->settings['repositories'][$repository_id]['subscription']['data']->expires): ?>
|
95 |
-
<?php printf(__('%s is registered on this site. You will receive automatic updates until %s', 'installer'), $generic_product_name, date_i18n('F j, Y', strtotime($expires))); ?>
|
96 |
-
<?php else: ?>
|
97 |
-
<?php printf(__('%s is registered on this site. Your Lifetime account gives you updates for life.', 'installer'), $generic_product_name); ?>
|
98 |
-
<?php endif; ?>
|
99 |
-
</div>
|
100 |
-
<?php endif; //if(empty($expired)) ?>
|
101 |
-
|
102 |
-
<?php endif; // if(!repository_has_subscription) ?>
|
103 |
-
<br clear="all" />
|
104 |
-
<div class="installer-error-box hidden"></div>
|
105 |
-
|
106 |
-
</td>
|
107 |
-
</tr>
|
108 |
-
|
109 |
-
<?php
|
110 |
-
|
111 |
-
$subscription_type = isset($subscription_type) ? $subscription_type : null;
|
112 |
-
$expired = isset($expired) ? $expired : null;
|
113 |
-
$upgrade_options = isset($upgrade_options) ? $upgrade_options : null;
|
114 |
-
$packages = $this->_render_product_packages($repository['data']['packages'], $subscription_type, $expired, $upgrade_options, $repository_id);
|
115 |
-
if(empty($subscription_type) || $expired){
|
116 |
-
$subpackages_expandable = true;
|
117 |
-
}else{
|
118 |
-
$subpackages_expandable = false;
|
119 |
-
}
|
120 |
-
|
121 |
-
?>
|
122 |
-
|
123 |
-
<?php foreach($packages as $package): ?>
|
124 |
-
<tr id="repository-<?php echo $repository_id ?>_<?php echo $package['id'] ?>">
|
125 |
-
<td><img width="140" height="140" src="<?php echo $package['image_url'] ?>" /></td>
|
126 |
-
<td>
|
127 |
-
<p><strong><?php echo $package['name'] ?></strong></p>
|
128 |
-
<p><?php echo $package['description'] ?></p>
|
129 |
-
|
130 |
-
<?php if($package['products']): ?>
|
131 |
-
<?php foreach($package['products'] as $product): ?>
|
132 |
-
<ul class="installer-products-list" style="display:inline">
|
133 |
-
<li>
|
134 |
-
<a class="button-secondary" href="<?php echo $product['url'] ?>"><?php echo $product['label'] ?></a>
|
135 |
-
</li>
|
136 |
-
</ul>
|
137 |
-
<?php endforeach; ?>
|
138 |
-
<?php endif; ?>
|
139 |
-
|
140 |
-
<?php if($package['downloads']): ?>
|
141 |
-
<?php include $this->plugin_path() . '/templates/downloads-list.php'; ?>
|
142 |
-
<?php endif; ?>
|
143 |
-
|
144 |
-
<?php if(!empty($package['sub-packages'])): ?>
|
145 |
-
|
146 |
-
<?php $subpackages = $this->_render_product_packages($package['sub-packages'], $subscription_type, $expired, $upgrade_options, $repository_id); ?>
|
147 |
-
|
148 |
-
<?php if($subpackages): ?>
|
149 |
-
|
150 |
-
<?php if($subpackages_expandable): ?>
|
151 |
-
<h5><a class="installer_expand_button" href="#" title="<?php esc_attr_e('Click to see individual components options.', 'installer') ?>"><?php _e('Individual components', 'installer') ?></a></h5>
|
152 |
-
<?php endif; ?>
|
153 |
-
|
154 |
-
<table class="otgs_wp_installer_subtable" style="<?php if($subpackages_expandable) echo 'display:none' ?>">
|
155 |
-
<?php foreach($subpackages as $package): ?>
|
156 |
-
<tr id="repository-<?php echo $repository_id ?>_<?php echo $package['id'] ?>">
|
157 |
-
<td><img width="70" height="70" src="<?php echo $package['image_url'] ?>" /></td>
|
158 |
-
<td>
|
159 |
-
<p><strong><?php echo $package['name'] ?></strong></p>
|
160 |
-
<p><?php echo $package['description'] ?></p>
|
161 |
-
|
162 |
-
<?php if($package['products']): ?>
|
163 |
-
<?php foreach($package['products'] as $product): ?>
|
164 |
-
<ul class="installer-products-list" style="display:inline">
|
165 |
-
<li>
|
166 |
-
<a class="button-secondary" href="<?php echo $product['url'] ?>"><?php echo $product['label'] ?></a>
|
167 |
-
</li>
|
168 |
-
</ul>
|
169 |
-
<?php endforeach; ?>
|
170 |
-
<?php endif; ?>
|
171 |
-
|
172 |
-
<?php if($package['downloads']): ?>
|
173 |
-
<?php include $this->plugin_path() . '/templates/downloads-list.php'; ?>
|
174 |
-
<?php endif; ?>
|
175 |
-
</td>
|
176 |
-
</tr>
|
177 |
-
<?php endforeach; ?>
|
178 |
-
</table>
|
179 |
-
<?php endif; ?>
|
180 |
-
|
181 |
-
<?php endif; ?>
|
182 |
-
|
183 |
-
|
184 |
-
</td>
|
185 |
-
</tr>
|
186 |
-
|
187 |
-
<?php endforeach; ?>
|
188 |
-
|
189 |
-
</table>
|
190 |
-
|
191 |
-
|
192 |
-
<p><i><?php printf(__('This page lets you install plugins and update existing plugins. To remove any of these plugins, go to the %splugins%s page and if you have the permission to remove plugins you should be able to do this.', 'installer'), '<a href="' . admin_url('plugins.php') . '">' , '</a>'); ?></i></p>
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
<br />
|
1 |
+
<?php if((!$this->repository_has_subscription($repository_id) && $match = $this->get_matching_cp($repository)) && $match['exp']): ?>
|
2 |
+
<p class="alignright installer_highlight"><strong><?php printf('Price offers available until %s', date_i18n(get_option( 'date_format' ), $match['exp'])) ?></strong></p>
|
3 |
+
<?php endif; ?>
|
4 |
+
|
5 |
+
<h3 id="repository-<?php echo $repository_id ?>"><?php echo $repository['data']['name'] ?></h3>
|
6 |
+
<?php
|
7 |
+
$generic_product_name = $this->settings['repositories'][$repository_id]['data']['product-name'];
|
8 |
+
?>
|
9 |
+
<table class="widefat otgs_wp_installer_table" id="installer_repo_<?php echo $repository_id ?>">
|
10 |
+
|
11 |
+
<tr>
|
12 |
+
<td> </td>
|
13 |
+
<td class="otgsi_register_product_wrap" align="center" valign="top">
|
14 |
+
<?php // IF NO SUBSCRIPTION ?>
|
15 |
+
<?php if(!$this->repository_has_subscription($repository_id)): ?>
|
16 |
+
|
17 |
+
<div style="text-align: right;">
|
18 |
+
<span><?php _e('Already bought?', 'installer'); ?> </span>
|
19 |
+
<a class="enter_site_key_js button-primary<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?> disabled<?php endif ?>" href="#"
|
20 |
+
<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
|
21 |
+
style="cursor: help"
|
22 |
+
disabled="disabled"
|
23 |
+
title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to register.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
|
24 |
+
<?php endif; ?>
|
25 |
+
>
|
26 |
+
<?php printf(__('Register %s', 'installer'), $generic_product_name); ?>
|
27 |
+
</a>
|
28 |
+
<form class="otgsi_site_key_form" method="post">
|
29 |
+
<input type="hidden" name="action" value="save_site_key" />
|
30 |
+
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce('save_site_key_' . $repository_id) ?>" />
|
31 |
+
<input type="hidden" name="repository_id" value="<?php echo $repository_id ?>">
|
32 |
+
<?php _e('2. Enter your site key', 'installer'); ?>
|
33 |
+
<input type="text" size="10" name="site_key_<?php echo $repository_id ?>" placeholder="<?php echo esc_attr('site key') ?>" />
|
34 |
+
<input class="button-primary" type="submit" value="<?php esc_attr_e('OK', 'installer') ?>" />
|
35 |
+
<input class="button-secondary cancel_site_key_js" type="button" value="<?php esc_attr_e('Cancel', 'installer') ?>" />
|
36 |
+
|
37 |
+
<div class="alignleft" style="margin-top:6px;"><?php printf(__('1. Go to your %s%s account%s and add this site URL: %s', 'installer'),
|
38 |
+
'<a href="' . $this->settings['repositories'][$repository_id]['data']['site_keys_management_url'] . '?add='.urlencode($this->get_installer_site_url( $repository_id )).'">',
|
39 |
+
$generic_product_name, '</a>', $this->get_installer_site_url( $repository_id )); ?></div>
|
40 |
+
</form>
|
41 |
+
|
42 |
+
|
43 |
+
</div>
|
44 |
+
|
45 |
+
<?php
|
46 |
+
$site_key = false;
|
47 |
+
|
48 |
+
// IF SUBSCRIPTION
|
49 |
+
else:
|
50 |
+
|
51 |
+
$site_key = $this->settings['repositories'][$repository_id]['subscription']['key'];
|
52 |
+
$subscription_type = $this->get_subscription_type_for_repository($repository_id);
|
53 |
+
$upgrade_options = $this->get_upgrade_options($repository_id);
|
54 |
+
$expired = false;
|
55 |
+
|
56 |
+
?>
|
57 |
+
|
58 |
+
<?php if($this->repository_has_expired_subscription($repository_id)): $expired = true; ?>
|
59 |
+
<div>
|
60 |
+
<p class="installer-warn-box">
|
61 |
+
<?php _e('Subscription expired. You need to either purchase a new subscription or upgrade if available.', 'installer') ?>
|
62 |
+
<span class="alignright">
|
63 |
+
<a class="update_site_key_js button-secondary" href="#" data-repository=<?php echo $repository_id ?> data-nonce="<?php echo wp_create_nonce('update_site_key_' . $repository_id) ?>">
|
64 |
+
<?php _e('Revalidate subscription', 'installer'); ?>
|
65 |
+
</a>
|
66 |
+
</span>
|
67 |
+
<br />
|
68 |
+
<span class="details"><?php _e("If you have already purchased or renewed your subscription and you can still see this message, please revalidate your subscription", 'installer') ?></span>
|
69 |
+
</p>
|
70 |
+
</div>
|
71 |
+
<?php else: ?>
|
72 |
+
<?php $this->show_subscription_renew_warning($repository_id, $subscription_type); ?>
|
73 |
+
<?php endif; ?>
|
74 |
+
|
75 |
+
<div class="alignright">
|
76 |
+
<a class="remove_site_key_js button-secondary" href="#" data-repository=<?php echo $repository_id ?>
|
77 |
+
data-confirmation="<?php esc_attr_e('Are you sure you want to unregister?', 'installer') ?>"
|
78 |
+
data-nonce="<?php echo wp_create_nonce('remove_site_key_' . $repository_id) ?>"
|
79 |
+
<?php if( WP_Installer::get_repository_hardcoded_site_key( $repository_id ) ): ?>
|
80 |
+
style="cursor: help"
|
81 |
+
disabled="disabled"
|
82 |
+
title="<?php printf( esc_attr__("Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to unregister.", 'installer'), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper($repository_id) ) ?>"
|
83 |
+
<?php endif; ?>
|
84 |
+
>
|
85 |
+
<?php printf(__("Unregister %s from this site", 'installer'), $generic_product_name) ?></a>
|
86 |
+
<a class="update_site_key_js button-secondary" href="#" data-repository=<?php echo $repository_id ?>
|
87 |
+
data-nonce="<?php echo wp_create_nonce('update_site_key_' . $repository_id) ?>">
|
88 |
+
<?php _e('Check for updates', 'installer'); ?>
|
89 |
+
</a>
|
90 |
+
</div>
|
91 |
+
|
92 |
+
<?php if(empty($expired)): ?>
|
93 |
+
<div class="alignleft">
|
94 |
+
<?php if($expires = $this->settings['repositories'][$repository_id]['subscription']['data']->expires): ?>
|
95 |
+
<?php printf(__('%s is registered on this site. You will receive automatic updates until %s', 'installer'), $generic_product_name, date_i18n('F j, Y', strtotime($expires))); ?>
|
96 |
+
<?php else: ?>
|
97 |
+
<?php printf(__('%s is registered on this site. Your Lifetime account gives you updates for life.', 'installer'), $generic_product_name); ?>
|
98 |
+
<?php endif; ?>
|
99 |
+
</div>
|
100 |
+
<?php endif; //if(empty($expired)) ?>
|
101 |
+
|
102 |
+
<?php endif; // if(!repository_has_subscription) ?>
|
103 |
+
<br clear="all" />
|
104 |
+
<div class="installer-error-box hidden"></div>
|
105 |
+
|
106 |
+
</td>
|
107 |
+
</tr>
|
108 |
+
|
109 |
+
<?php
|
110 |
+
|
111 |
+
$subscription_type = isset($subscription_type) ? $subscription_type : null;
|
112 |
+
$expired = isset($expired) ? $expired : null;
|
113 |
+
$upgrade_options = isset($upgrade_options) ? $upgrade_options : null;
|
114 |
+
$packages = $this->_render_product_packages($repository['data']['packages'], $subscription_type, $expired, $upgrade_options, $repository_id);
|
115 |
+
if(empty($subscription_type) || $expired){
|
116 |
+
$subpackages_expandable = true;
|
117 |
+
}else{
|
118 |
+
$subpackages_expandable = false;
|
119 |
+
}
|
120 |
+
|
121 |
+
?>
|
122 |
+
|
123 |
+
<?php foreach($packages as $package): ?>
|
124 |
+
<tr id="repository-<?php echo $repository_id ?>_<?php echo $package['id'] ?>">
|
125 |
+
<td><img width="140" height="140" src="<?php echo $package['image_url'] ?>" /></td>
|
126 |
+
<td>
|
127 |
+
<p><strong><?php echo $package['name'] ?></strong></p>
|
128 |
+
<p><?php echo $package['description'] ?></p>
|
129 |
+
|
130 |
+
<?php if($package['products']): ?>
|
131 |
+
<?php foreach($package['products'] as $product): ?>
|
132 |
+
<ul class="installer-products-list" style="display:inline">
|
133 |
+
<li>
|
134 |
+
<a class="button-secondary" href="<?php echo $product['url'] ?>"><?php echo $product['label'] ?></a>
|
135 |
+
</li>
|
136 |
+
</ul>
|
137 |
+
<?php endforeach; ?>
|
138 |
+
<?php endif; ?>
|
139 |
+
|
140 |
+
<?php if($package['downloads']): ?>
|
141 |
+
<?php include $this->plugin_path() . '/templates/downloads-list.php'; ?>
|
142 |
+
<?php endif; ?>
|
143 |
+
|
144 |
+
<?php if(!empty($package['sub-packages'])): ?>
|
145 |
+
|
146 |
+
<?php $subpackages = $this->_render_product_packages($package['sub-packages'], $subscription_type, $expired, $upgrade_options, $repository_id); ?>
|
147 |
+
|
148 |
+
<?php if($subpackages): ?>
|
149 |
+
|
150 |
+
<?php if($subpackages_expandable): ?>
|
151 |
+
<h5><a class="installer_expand_button" href="#" title="<?php esc_attr_e('Click to see individual components options.', 'installer') ?>"><?php _e('Individual components', 'installer') ?></a></h5>
|
152 |
+
<?php endif; ?>
|
153 |
+
|
154 |
+
<table class="otgs_wp_installer_subtable" style="<?php if($subpackages_expandable) echo 'display:none' ?>">
|
155 |
+
<?php foreach($subpackages as $package): ?>
|
156 |
+
<tr id="repository-<?php echo $repository_id ?>_<?php echo $package['id'] ?>">
|
157 |
+
<td><img width="70" height="70" src="<?php echo $package['image_url'] ?>" /></td>
|
158 |
+
<td>
|
159 |
+
<p><strong><?php echo $package['name'] ?></strong></p>
|
160 |
+
<p><?php echo $package['description'] ?></p>
|
161 |
+
|
162 |
+
<?php if($package['products']): ?>
|
163 |
+
<?php foreach($package['products'] as $product): ?>
|
164 |
+
<ul class="installer-products-list" style="display:inline">
|
165 |
+
<li>
|
166 |
+
<a class="button-secondary" href="<?php echo $product['url'] ?>"><?php echo $product['label'] ?></a>
|
167 |
+
</li>
|
168 |
+
</ul>
|
169 |
+
<?php endforeach; ?>
|
170 |
+
<?php endif; ?>
|
171 |
+
|
172 |
+
<?php if($package['downloads']): ?>
|
173 |
+
<?php include $this->plugin_path() . '/templates/downloads-list.php'; ?>
|
174 |
+
<?php endif; ?>
|
175 |
+
</td>
|
176 |
+
</tr>
|
177 |
+
<?php endforeach; ?>
|
178 |
+
</table>
|
179 |
+
<?php endif; ?>
|
180 |
+
|
181 |
+
<?php endif; ?>
|
182 |
+
|
183 |
+
|
184 |
+
</td>
|
185 |
+
</tr>
|
186 |
+
|
187 |
+
<?php endforeach; ?>
|
188 |
+
|
189 |
+
</table>
|
190 |
+
|
191 |
+
|
192 |
+
<p><i><?php printf(__('This page lets you install plugins and update existing plugins. To remove any of these plugins, go to the %splugins%s page and if you have the permission to remove plugins you should be able to do this.', 'installer'), '<a href="' . admin_url('plugins.php') . '">' , '</a>'); ?></i></p>
|
193 |
+
|
194 |
+
|
195 |
+
|
196 |
+
<br />
|
library/toolset/onthego-resources/loader.php
CHANGED
@@ -16,7 +16,8 @@
|
|
16 |
// is made to the onthego-resources code.
|
17 |
// The version number will then be used to work out which plugin has the latest
|
18 |
// version of the code.
|
19 |
-
$onthegosystems_branding_version =
|
|
|
20 |
|
21 |
// ----------------------------------------------------------------------//
|
22 |
// WARNING * WARNING *WARNING
|
16 |
// is made to the onthego-resources code.
|
17 |
// The version number will then be used to work out which plugin has the latest
|
18 |
// version of the code.
|
19 |
+
$onthegosystems_branding_version = 20;
|
20 |
+
|
21 |
|
22 |
// ----------------------------------------------------------------------//
|
23 |
// WARNING * WARNING *WARNING
|
library/toolset/onthego-resources/onthego-styles/onthego-buttons.css
CHANGED
@@ -694,4 +694,5 @@ input[type="button"].ont-btn-block {
|
|
694 |
.navbar-form .checkbox label {
|
695 |
padding-left: 0!important;
|
696 |
}
|
697 |
-
label.ont-btn{width:auto!important;min-width:60px!important;}
|
|
694 |
.navbar-form .checkbox label {
|
695 |
padding-left: 0!important;
|
696 |
}
|
697 |
+
label.ont-btn{width:auto!important;min-width:60px!important;}
|
698 |
+
.ont-btn-xxs{padding:0!important;border:none!important;}
|
library/toolset/onthego-resources/onthego-styles/onthego-colors.css
CHANGED
@@ -4,15 +4,17 @@ This file is a collection of generic colors used in our styles
|
|
4 |
.ont-color-default {
|
5 |
color: #444444!important; }
|
6 |
|
7 |
-
.ont-color-orange {
|
8 |
color: #f05a28!important; }
|
9 |
|
10 |
.ont-color-gray {
|
11 |
color: #888!important; }
|
12 |
|
13 |
-
.ont-color-white {
|
14 |
color: white!important; }
|
15 |
|
|
|
|
|
16 |
.ont-color-menu {
|
17 |
color: #999999!important; }
|
18 |
|
@@ -23,4 +25,30 @@ This file is a collection of generic colors used in our styles
|
|
23 |
color: #2ea2cc!important; }
|
24 |
|
25 |
.ont-color-link:hover {
|
26 |
-
color: #0074a2!important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
.ont-color-default {
|
5 |
color: #444444!important; }
|
6 |
|
7 |
+
.ont-color-orange, .ont-color-orange:hover {
|
8 |
color: #f05a28!important; }
|
9 |
|
10 |
.ont-color-gray {
|
11 |
color: #888!important; }
|
12 |
|
13 |
+
.ont-color-white, .ont-color-white:hover {
|
14 |
color: white!important; }
|
15 |
|
16 |
+
.ont-color-white > *:hover{color: white!important;}
|
17 |
+
|
18 |
.ont-color-menu {
|
19 |
color: #999999!important; }
|
20 |
|
25 |
color: #2ea2cc!important; }
|
26 |
|
27 |
.ont-color-link:hover {
|
28 |
+
color: #0074a2!important; }
|
29 |
+
|
30 |
+
.ont-background-default {
|
31 |
+
background: #444444!important; }
|
32 |
+
|
33 |
+
.ont-background-orange, .ont-background-orange:hover {
|
34 |
+
background: #f05a28!important; }
|
35 |
+
|
36 |
+
.ont-background-orange > *:hover{background: #f05a28!important;}
|
37 |
+
|
38 |
+
.ont-background-gray {
|
39 |
+
background: #888!important; }
|
40 |
+
|
41 |
+
.ont-background-white {
|
42 |
+
background: white!important; }
|
43 |
+
|
44 |
+
.ont-background-menu {
|
45 |
+
background: #999999!important; }
|
46 |
+
|
47 |
+
.ont-background-link {
|
48 |
+
background: #0074a2!important; }
|
49 |
+
|
50 |
+
.ont-background-menu:hover {
|
51 |
+
background: #2ea2cc!important; }
|
52 |
+
|
53 |
+
.ont-background-link:hover {
|
54 |
+
background: #0074a2!important; }
|
library/toolset/toolset-common/bootstrap.php
CHANGED
@@ -41,10 +41,40 @@ class Toolset_Common_Bootstrap {
|
|
41 |
public $settings;
|
42 |
public $promotion;
|
43 |
public $wpml_compatibility;
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
private function __construct() {
|
46 |
self::$sections_loaded = array();
|
47 |
-
|
|
|
48 |
$this->register_utils();
|
49 |
$this->register_res();
|
50 |
$this->register_libs();
|
@@ -53,72 +83,132 @@ class Toolset_Common_Bootstrap {
|
|
53 |
add_filter( 'toolset_is_toolset_common_available', '__return_true' );
|
54 |
|
55 |
add_action( 'switch_blog', array( $this, 'clear_settings_instance' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
}
|
57 |
-
|
|
|
|
|
|
|
|
|
58 |
public static function getInstance() {
|
59 |
-
|
60 |
-
self::$instance = new Toolset_Common_Bootstrap();
|
61 |
-
}
|
62 |
-
return self::$instance;
|
63 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
/**
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
public function load_sections( $load = array() ) {
|
74 |
-
|
75 |
// Load toolset_debug on demand
|
76 |
-
if (
|
77 |
-
empty( $load )
|
78 |
-
|| in_array( 'toolset_debug', $load )
|
79 |
-
) {
|
80 |
$this->register_debug();
|
81 |
}
|
82 |
-
|
83 |
// Maybe register forms
|
84 |
-
if (
|
85 |
-
empty( $load )
|
86 |
-
|| in_array( 'toolset_forms', $load )
|
87 |
-
) {
|
88 |
$this->register_toolset_forms();
|
89 |
}
|
90 |
-
|
91 |
// Maybe register the editor addon
|
92 |
-
if (
|
93 |
-
empty( $load )
|
94 |
-
|| in_array( 'toolset_visual_editor', $load )
|
95 |
-
) {
|
96 |
$this->register_visual_editor();
|
97 |
}
|
98 |
-
|
99 |
-
if (
|
100 |
-
empty( $load )
|
101 |
-
|| in_array( 'toolset_parser', $load )
|
102 |
-
) {
|
103 |
$this->register_parser();
|
104 |
}
|
|
|
105 |
}
|
106 |
|
107 |
public function register_res() {
|
108 |
-
|
109 |
-
if ( !
|
110 |
-
$
|
111 |
// Use the class provided by Ric
|
112 |
require_once( TOOLSET_COMMON_PATH . '/inc/toolset.assets.manager.class.php' );
|
113 |
$this->assets_manager = Toolset_Assets_Manager::getInstance();
|
114 |
-
|
115 |
}
|
116 |
}
|
117 |
|
118 |
public function register_libs() {
|
119 |
-
|
120 |
-
if ( !
|
121 |
-
|
|
|
|
|
122 |
if ( ! class_exists( 'ICL_Array2XML' ) ) {
|
123 |
require_once( TOOLSET_COMMON_PATH . '/lib/array2xml.php' );
|
124 |
}
|
@@ -137,14 +227,17 @@ class Toolset_Common_Bootstrap {
|
|
137 |
if ( ! class_exists( 'Toolset_Enlimbo_Forms' ) ) {
|
138 |
require_once( TOOLSET_COMMON_PATH . '/lib/enlimbo.forms.class.php' );
|
139 |
}
|
140 |
-
|
|
|
141 |
}
|
142 |
}
|
143 |
|
144 |
public function register_inc() {
|
145 |
-
|
146 |
-
if ( !
|
147 |
-
|
|
|
|
|
148 |
if ( ! class_exists( 'Toolset_Settings' ) ) {
|
149 |
require_once( TOOLSET_COMMON_PATH . '/inc/toolset.settings.class.php' );
|
150 |
$this->settings = Toolset_Settings::get_instance();
|
@@ -193,82 +286,132 @@ class Toolset_Common_Bootstrap {
|
|
193 |
require_once( TOOLSET_COMMON_PATH . '/inc/toolset.relevanssi.compatibility.class.php' );
|
194 |
$this->relevanssi_compatibility = new Toolset_Relevanssi_Compatibility();
|
195 |
}
|
196 |
-
|
197 |
if ( ! class_exists( 'Toolset_CssComponent' ) ) {
|
198 |
require_once( TOOLSET_COMMON_PATH . '/inc/toolset.css.component.class.php' );
|
199 |
$toolset_bs_component = Toolset_CssComponent::getInstance();
|
200 |
}
|
201 |
-
|
202 |
require_once( TOOLSET_COMMON_PATH . '/inc/toolset.compatibility.php' );
|
203 |
require_once( TOOLSET_COMMON_PATH . '/inc/toolset.function.helpers.php' );
|
204 |
require_once( TOOLSET_COMMON_PATH . '/deprecated.php' );
|
205 |
|
206 |
-
|
207 |
}
|
208 |
}
|
209 |
|
210 |
public function register_utils() {
|
211 |
-
|
212 |
-
$
|
213 |
-
|
214 |
-
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
}
|
217 |
-
|
218 |
-
|
219 |
-
|
|
|
|
|
220 |
}
|
221 |
-
|
222 |
-
|
223 |
-
|
|
|
224 |
}
|
225 |
-
|
|
|
226 |
}
|
227 |
-
|
|
|
228 |
public function register_debug() {
|
229 |
-
|
230 |
-
if ( !
|
231 |
-
$
|
232 |
require_once( TOOLSET_COMMON_PATH . '/debug/debug-information.php' );
|
233 |
-
|
|
|
234 |
}
|
235 |
}
|
236 |
|
237 |
public function register_toolset_forms() {
|
238 |
-
|
239 |
-
if ( !
|
240 |
-
$
|
241 |
if ( ! class_exists( 'WPToolset_Forms_Bootstrap' ) ) {
|
242 |
require_once TOOLSET_COMMON_PATH . '/toolset-forms/bootstrap.php';
|
243 |
}
|
244 |
-
|
245 |
}
|
246 |
}
|
247 |
|
248 |
public function register_visual_editor() {
|
249 |
-
|
250 |
-
if ( !
|
251 |
-
$
|
252 |
require_once( TOOLSET_COMMON_PATH . '/visual-editor/editor-addon-generic.class.php' );
|
253 |
require_once( TOOLSET_COMMON_PATH . '/visual-editor/editor-addon.class.php' );
|
254 |
require_once( TOOLSET_COMMON_PATH . '/visual-editor/views-editor-addon.class.php' );
|
255 |
-
|
256 |
}
|
257 |
}
|
258 |
|
259 |
public function register_parser() {
|
260 |
-
|
261 |
-
if ( !
|
262 |
-
$
|
263 |
if ( ! class_exists( 'Toolset_Regex' ) ) {
|
264 |
require_once( TOOLSET_COMMON_PATH . '/expression-parser/parser.php' );
|
265 |
}
|
266 |
-
|
267 |
}
|
268 |
}
|
269 |
-
|
270 |
public function clear_settings_instance() {
|
271 |
Toolset_Settings::clear_instance();
|
272 |
}
|
273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
};
|
41 |
public $settings;
|
42 |
public $promotion;
|
43 |
public $wpml_compatibility;
|
44 |
+
|
45 |
+
// Names of various sections/modules of the common library that can be loaded.
|
46 |
+
const TOOLSET_AUTOLOADER = 'toolset_autoloader';
|
47 |
+
const TOOLSET_DEBUG = 'toolset_debug';
|
48 |
+
const TOOLSET_FORMS = 'toolset_forms';
|
49 |
+
const TOOLSET_VISUAL_EDITOR = 'toolset_visual_editor';
|
50 |
+
const TOOLSET_PARSER = 'toolset_parser';
|
51 |
+
const TOOLSET_RESOURCES = 'toolset_res';
|
52 |
+
const TOOLSET_LIBRARIES = 'toolset_lib';
|
53 |
+
const TOOLSET_INCLUDES = 'toolset_inc';
|
54 |
+
const TOOLSET_UTILS = 'toolset_utils';
|
55 |
+
const TOOLSET_DIALOGS = 'toolset_dialogs';
|
56 |
+
const TOOLSET_HELP_VIDEOS = 'toolset_help_videos';
|
57 |
+
const TOOLSET_GUI_BASE = 'toolset_gui_base';
|
58 |
+
const TOOLSET_RELATIONSHIPS = 'toolset_relationships';
|
59 |
+
|
60 |
+
|
61 |
+
// Request mode
|
62 |
+
const MODE_UNDEFINED = '';
|
63 |
+
const MODE_AJAX = 'ajax';
|
64 |
+
const MODE_ADMIN = 'admin';
|
65 |
+
const MODE_FRONTEND = 'frontend';
|
66 |
+
|
67 |
+
|
68 |
+
/**
|
69 |
+
* @var string One of the MODE_* constants.
|
70 |
+
*/
|
71 |
+
private $mode = self::MODE_UNDEFINED;
|
72 |
+
|
73 |
+
|
74 |
private function __construct() {
|
75 |
self::$sections_loaded = array();
|
76 |
+
|
77 |
+
// Register assets, utils, settings, localization, promotion, debug, admin bar and WPML compatibility
|
78 |
$this->register_utils();
|
79 |
$this->register_res();
|
80 |
$this->register_libs();
|
83 |
add_filter( 'toolset_is_toolset_common_available', '__return_true' );
|
84 |
|
85 |
add_action( 'switch_blog', array( $this, 'clear_settings_instance' ) );
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Action when the Toolset Common Library is completely loaded.
|
89 |
+
*
|
90 |
+
* @since m2m
|
91 |
+
*/
|
92 |
+
do_action( 'toolset_common_loaded' );
|
93 |
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* @return Toolset_Common_Bootstrap
|
97 |
+
* @deprecated Use get_instance() instead.
|
98 |
+
*/
|
99 |
public static function getInstance() {
|
100 |
+
return self::get_instance();
|
|
|
|
|
|
|
101 |
}
|
102 |
+
|
103 |
+
|
104 |
+
/**
|
105 |
+
* @return Toolset_Common_Bootstrap
|
106 |
+
* @since 2.1
|
107 |
+
*/
|
108 |
+
public static function get_instance() {
|
109 |
+
if ( ! self::$instance ) {
|
110 |
+
self::$instance = new Toolset_Common_Bootstrap();
|
111 |
+
}
|
112 |
+
return self::$instance;
|
113 |
+
}
|
114 |
+
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Determine if a given section is already loaded.
|
118 |
+
*
|
119 |
+
* @param string $section_name
|
120 |
+
* @return bool
|
121 |
+
* @since 2.1
|
122 |
+
*/
|
123 |
+
private function is_section_loaded( $section_name ) {
|
124 |
+
return in_array( $section_name, self::$sections_loaded );
|
125 |
+
}
|
126 |
+
|
127 |
|
128 |
/**
|
129 |
+
* Add a section name to the list of the loaded ones.
|
130 |
+
*
|
131 |
+
* @param string $section_name
|
132 |
+
* @since 2.1
|
133 |
+
*/
|
134 |
+
private function add_section_loaded( $section_name ) {
|
135 |
+
self::$sections_loaded[] = $section_name;
|
136 |
+
}
|
137 |
+
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Decide whether a particular section needs to be loaded.
|
141 |
+
*
|
142 |
+
* @param string[] $sections_to_load Array of sections that should be loaded, or empty array to load all of them.
|
143 |
+
* @param string $section_name Name of a section.
|
144 |
+
* @return bool
|
145 |
+
* @since 2.1
|
146 |
+
*/
|
147 |
+
private function should_load_section( $sections_to_load, $section_name ) {
|
148 |
+
return ( empty( $sections_to_load ) || in_array( $section_name, $sections_to_load ) );
|
149 |
+
}
|
150 |
+
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Apply a filter on the array of names loaded sections.
|
154 |
+
*
|
155 |
+
* @param string $filter_name Name of the filter.
|
156 |
+
* @since 2.1
|
157 |
+
*/
|
158 |
+
private function apply_filters_on_sections_loaded( $filter_name ) {
|
159 |
+
self::$sections_loaded = apply_filters( $filter_name, self::$sections_loaded );
|
160 |
+
}
|
161 |
+
|
162 |
|
163 |
+
/**
|
164 |
+
* Load sections on demand
|
165 |
+
*
|
166 |
+
* This needs to be called after after_setup_theme:10 because this file is not loaded before that
|
167 |
+
*
|
168 |
+
* @since 1.9
|
169 |
+
*
|
170 |
+
* @param string[] $load Names of sections to load or an empty array to load everything.
|
171 |
+
*/
|
172 |
public function load_sections( $load = array() ) {
|
173 |
+
|
174 |
// Load toolset_debug on demand
|
175 |
+
if ( $this->should_load_section( $load, self::TOOLSET_DEBUG ) ) {
|
|
|
|
|
|
|
176 |
$this->register_debug();
|
177 |
}
|
178 |
+
|
179 |
// Maybe register forms
|
180 |
+
if ( $this->should_load_section( $load, self::TOOLSET_FORMS ) ) {
|
|
|
|
|
|
|
181 |
$this->register_toolset_forms();
|
182 |
}
|
183 |
+
|
184 |
// Maybe register the editor addon
|
185 |
+
if ( $this->should_load_section( $load, self::TOOLSET_VISUAL_EDITOR ) ) {
|
|
|
|
|
|
|
186 |
$this->register_visual_editor();
|
187 |
}
|
188 |
+
|
189 |
+
if ( $this->should_load_section( $load, self::TOOLSET_PARSER ) ) {
|
|
|
|
|
|
|
190 |
$this->register_parser();
|
191 |
}
|
192 |
+
|
193 |
}
|
194 |
|
195 |
public function register_res() {
|
196 |
+
|
197 |
+
if ( ! $this->is_section_loaded( self::TOOLSET_RESOURCES ) ) {
|
198 |
+
$this->add_section_loaded( self::TOOLSET_RESOURCES );
|
199 |
// Use the class provided by Ric
|
200 |
require_once( TOOLSET_COMMON_PATH . '/inc/toolset.assets.manager.class.php' );
|
201 |
$this->assets_manager = Toolset_Assets_Manager::getInstance();
|
202 |
+
$this->apply_filters_on_sections_loaded( 'toolset_register_assets_section' );
|
203 |
}
|
204 |
}
|
205 |
|
206 |
public function register_libs() {
|
207 |
+
|
208 |
+
if ( ! $this->is_section_loaded( self::TOOLSET_LIBRARIES ) ) {
|
209 |
+
|
210 |
+
$this->add_section_loaded( self::TOOLSET_LIBRARIES );
|
211 |
+
|
212 |
if ( ! class_exists( 'ICL_Array2XML' ) ) {
|
213 |
require_once( TOOLSET_COMMON_PATH . '/lib/array2xml.php' );
|
214 |
}
|
227 |
if ( ! class_exists( 'Toolset_Enlimbo_Forms' ) ) {
|
228 |
require_once( TOOLSET_COMMON_PATH . '/lib/enlimbo.forms.class.php' );
|
229 |
}
|
230 |
+
|
231 |
+
$this->apply_filters_on_sections_loaded( 'toolset_register_library_section' );
|
232 |
}
|
233 |
}
|
234 |
|
235 |
public function register_inc() {
|
236 |
+
|
237 |
+
if ( ! $this->is_section_loaded( self::TOOLSET_INCLUDES ) ) {
|
238 |
+
|
239 |
+
$this->add_section_loaded( self::TOOLSET_INCLUDES );
|
240 |
+
|
241 |
if ( ! class_exists( 'Toolset_Settings' ) ) {
|
242 |
require_once( TOOLSET_COMMON_PATH . '/inc/toolset.settings.class.php' );
|
243 |
$this->settings = Toolset_Settings::get_instance();
|
286 |
require_once( TOOLSET_COMMON_PATH . '/inc/toolset.relevanssi.compatibility.class.php' );
|
287 |
$this->relevanssi_compatibility = new Toolset_Relevanssi_Compatibility();
|
288 |
}
|
289 |
+
|
290 |
if ( ! class_exists( 'Toolset_CssComponent' ) ) {
|
291 |
require_once( TOOLSET_COMMON_PATH . '/inc/toolset.css.component.class.php' );
|
292 |
$toolset_bs_component = Toolset_CssComponent::getInstance();
|
293 |
}
|
294 |
+
|
295 |
require_once( TOOLSET_COMMON_PATH . '/inc/toolset.compatibility.php' );
|
296 |
require_once( TOOLSET_COMMON_PATH . '/inc/toolset.function.helpers.php' );
|
297 |
require_once( TOOLSET_COMMON_PATH . '/deprecated.php' );
|
298 |
|
299 |
+
$this->apply_filters_on_sections_loaded( 'toolset_register_include_section' );
|
300 |
}
|
301 |
}
|
302 |
|
303 |
public function register_utils() {
|
304 |
+
|
305 |
+
if( ! $this->is_section_loaded( self::TOOLSET_AUTOLOADER ) ) {
|
306 |
+
// This needs to happen very very early
|
307 |
+
require_once TOOLSET_COMMON_PATH . '/utility/autoloader.php';
|
308 |
+
Toolset_Common_Autoloader::initialize();
|
309 |
+
$this->add_section_loaded( self::TOOLSET_AUTOLOADER );
|
310 |
+
}
|
311 |
+
|
312 |
+
if ( ! $this->is_section_loaded( self::TOOLSET_UTILS ) ) {
|
313 |
+
$this->add_section_loaded( self::TOOLSET_UTILS );
|
314 |
+
require_once TOOLSET_COMMON_PATH . '/utility/utils.php';
|
315 |
}
|
316 |
+
|
317 |
+
// Although this is full of DDL prefixes, we need to actually port before using it.
|
318 |
+
if ( ! $this->is_section_loaded( self::TOOLSET_DIALOGS ) ) {
|
319 |
+
$this->add_section_loaded( self::TOOLSET_DIALOGS );
|
320 |
+
require_once TOOLSET_COMMON_PATH . '/utility/dialogs/toolset.dialog-boxes.class.php' ;
|
321 |
}
|
322 |
+
|
323 |
+
if( ! $this->is_section_loaded( self::TOOLSET_HELP_VIDEOS ) ) {
|
324 |
+
$this->add_section_loaded( self::TOOLSET_HELP_VIDEOS );
|
325 |
+
require_once TOOLSET_COMMON_PATH . '/utility/help-videos/toolset-help-videos.php';
|
326 |
}
|
327 |
+
|
328 |
+
$this->apply_filters_on_sections_loaded( 'toolset_register_utility_section' );
|
329 |
}
|
330 |
+
|
331 |
+
|
332 |
public function register_debug() {
|
333 |
+
|
334 |
+
if ( ! $this->is_section_loaded( self::TOOLSET_DEBUG ) ) {
|
335 |
+
$this->add_section_loaded( self::TOOLSET_DEBUG );
|
336 |
require_once( TOOLSET_COMMON_PATH . '/debug/debug-information.php' );
|
337 |
+
|
338 |
+
$this->apply_filters_on_sections_loaded( 'toolset_register_debug_section' );
|
339 |
}
|
340 |
}
|
341 |
|
342 |
public function register_toolset_forms() {
|
343 |
+
|
344 |
+
if ( ! $this->is_section_loaded( self::TOOLSET_FORMS ) ) {
|
345 |
+
$this->add_section_loaded( self::TOOLSET_FORMS );
|
346 |
if ( ! class_exists( 'WPToolset_Forms_Bootstrap' ) ) {
|
347 |
require_once TOOLSET_COMMON_PATH . '/toolset-forms/bootstrap.php';
|
348 |
}
|
349 |
+
$this->apply_filters_on_sections_loaded( 'toolset_register_forms_section' );
|
350 |
}
|
351 |
}
|
352 |
|
353 |
public function register_visual_editor() {
|
354 |
+
|
355 |
+
if ( ! $this->is_section_loaded( self::TOOLSET_VISUAL_EDITOR ) ) {
|
356 |
+
$this->add_section_loaded( self::TOOLSET_VISUAL_EDITOR );
|
357 |
require_once( TOOLSET_COMMON_PATH . '/visual-editor/editor-addon-generic.class.php' );
|
358 |
require_once( TOOLSET_COMMON_PATH . '/visual-editor/editor-addon.class.php' );
|
359 |
require_once( TOOLSET_COMMON_PATH . '/visual-editor/views-editor-addon.class.php' );
|
360 |
+
$this->apply_filters_on_sections_loaded( 'toolset_register_visual_editor_section' );
|
361 |
}
|
362 |
}
|
363 |
|
364 |
public function register_parser() {
|
365 |
+
|
366 |
+
if ( ! $this->is_section_loaded( self::TOOLSET_PARSER ) ) {
|
367 |
+
$this->add_section_loaded( self::TOOLSET_PARSER );
|
368 |
if ( ! class_exists( 'Toolset_Regex' ) ) {
|
369 |
require_once( TOOLSET_COMMON_PATH . '/expression-parser/parser.php' );
|
370 |
}
|
371 |
+
$this->apply_filters_on_sections_loaded( 'toolset_register_parsers_section' );
|
372 |
}
|
373 |
}
|
374 |
+
|
375 |
public function clear_settings_instance() {
|
376 |
Toolset_Settings::clear_instance();
|
377 |
}
|
378 |
+
|
379 |
+
|
380 |
+
/**
|
381 |
+
* See get_request_mode().
|
382 |
+
*
|
383 |
+
* @since 2.3
|
384 |
+
*/
|
385 |
+
private function determine_request_mode() {
|
386 |
+
if( is_admin() ) {
|
387 |
+
if( defined( 'DOING_AJAX' ) ) {
|
388 |
+
$this->mode = self::MODE_AJAX;
|
389 |
+
} else {
|
390 |
+
$this->mode = self::MODE_ADMIN;
|
391 |
+
}
|
392 |
+
} else {
|
393 |
+
$this->mode = self::MODE_FRONTEND;
|
394 |
+
}
|
395 |
+
}
|
396 |
+
|
397 |
+
|
398 |
+
/**
|
399 |
+
* Get current request mode.
|
400 |
+
*
|
401 |
+
* Possible values are:
|
402 |
+
* - MODE_UNDEFINED before the main controller initialization is completed
|
403 |
+
* - MODE_AJAX when doing an AJAX request
|
404 |
+
* - MODE_ADMIN when showing a WP admin page
|
405 |
+
* - MODE_FRONTEND when rendering a frontend page
|
406 |
+
*
|
407 |
+
* @return string
|
408 |
+
* @since 2.3
|
409 |
+
*/
|
410 |
+
public function get_request_mode() {
|
411 |
+
if( self::MODE_UNDEFINED == $this->mode ) {
|
412 |
+
$this->determine_request_mode();
|
413 |
+
}
|
414 |
+
return $this->mode;
|
415 |
+
}
|
416 |
+
|
417 |
};
|
library/toolset/toolset-common/changelog.md
CHANGED
@@ -1,122 +1,134 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
- Fixed select2 edge cases when methods are called on non-select2 initialised element
|
11 |
-
- Refined special handling of old inputs by making sure target is only a select and not the hidden relative element
|
12 |
|
13 |
-
|
14 |
|
15 |
-
|
16 |
-
- Updated the bundled select2 script to version 4.0.3
|
17 |
-
- Fixed a problem with some assets URLs lacking a backslash
|
18 |
-
- Improved management of CRED file fields uploads
|
19 |
-
- Improved the frontend markup for CRED taxonomy fields
|
20 |
-
- Added an internal Toolset compatibility class
|
21 |
|
22 |
-
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
Common 1.3 (Dec 15 2014)
|
122 |
-
- Tagged for Views 1.7 beta1 and Layouts 1.0 beta1
|
1 |
+
# Toolset Common Library
|
2 |
+
|
3 |
+
## 2.3.0
|
4 |
+
|
5 |
+
- Extend the post objects relationships management with two actions to gather data on demand.
|
6 |
+
- Only include the jQuery datepicker stylesheet on demand when the current page contains a datepicker from Toolset.
|
7 |
+
- Include the user editors in the common bootstrap class.
|
8 |
+
|
9 |
+
## 2.2.6
|
10 |
+
|
11 |
+
- Fix a CRED issue with added validation rules (types-988).
|
12 |
+
- Handle several issues related to using "0" as a default field value and saving it to the database (toolsetcommon-106).
|
13 |
+
- Minor compatibility fixes for the upcoming CRED 1.8.4 release.
|
14 |
|
15 |
+
## 2.2.5 (November 5, 2016)
|
16 |
+
|
17 |
+
- Thorough check for security vulnerabilities.
|
18 |
|
19 |
+
## 2.2.4 (November 2, 2016)
|
|
|
|
|
20 |
|
21 |
+
- Fixed a problem with some assets management by definind better rules on constant definitions.
|
22 |
|
23 |
+
## 2.2.3 (October 10, 2016)
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
- Fixed select2 edge cases when methods are called on non-select2 initialised element
|
26 |
+
- Refined special handling of old inputs by making sure target is only a select and not the hidden relative element
|
27 |
+
- Extended the valid date formats that Types and CRED supports for the Date field.
|
28 |
|
29 |
+
## 2.2.2 (September 26, 2016)
|
30 |
+
|
31 |
+
- Updated the bundled select2 script to version 4.0.3
|
32 |
+
- Fixed a problem with some assets URLs lacking a backslash
|
33 |
+
- Improved management of CRED file fields uploads
|
34 |
+
- Improved the frontend markup for CRED taxonomy fields
|
35 |
+
- Added an internal Toolset compatibility class
|
36 |
+
|
37 |
+
## 2.2.1 (August 25, 2016)
|
38 |
+
|
39 |
+
- Avoid translating the Toolset top level admin menu label
|
40 |
|
41 |
+
## 2.2 (August 24, 2016)
|
42 |
+
|
43 |
+
- Added compatibility classes for Relevanssi and Beaver Builder
|
44 |
+
- Added a CSS components class
|
45 |
+
- Improved the Toolset Common assets management
|
46 |
+
- Added the Glyphicons library
|
47 |
+
|
48 |
+
## 2.1 (June 13, 2016)
|
49 |
+
|
50 |
+
- Refactored event-manager library to toolset-event manager to namespace it and avoid conficts with ACF Plugin
|
51 |
+
- Added a new class for promotional and help videos management
|
52 |
+
- Improved compatibility with PHP 5.2
|
53 |
+
- Improved compatibility with WPML, including admin language switchers and loading times
|
54 |
+
- Improved compatibility for CRED file uploads and bundled scripts
|
55 |
+
- Fixed double slashes on assets URLs
|
56 |
+
|
57 |
+
## 2.0 (April 7, 2016)
|
58 |
+
|
59 |
+
- Created new loader to load resources for all plugins when plugin loads
|
60 |
+
- Refactored in a more organised way files and resources to be compatible with the new loader
|
61 |
+
- Added scripts and styles manager class to register and enqueue static resources with a unified system
|
62 |
+
- Added Toolset Dialog Boxes to provide a unified way to create and render dialogs
|
63 |
+
- Fixed various bugs
|
64 |
+
|
65 |
+
## 1.9.2 (March 17, 2016)
|
66 |
+
|
67 |
+
- Fixed issue in validation messages on Amazon S3
|
68 |
+
|
69 |
+
## 1.9.1 (March 15, 2016)
|
70 |
+
|
71 |
+
- Added control to filter array to prevent exceptions
|
72 |
+
- Prevented error when object does not have property or key is not set in array filter callback
|
73 |
+
- Fixed glitch in validation library
|
74 |
+
- Absolute path to include toolset-forms/api.php
|
75 |
+
- Fixed search terms with language translation
|
76 |
+
|
77 |
+
## 1.9 (February 15, 2016)
|
78 |
+
|
79 |
+
- Tagged for Types 1.9, Views 1.12, CRED 1.5, Layouts 1.5 and Access 1.2.8
|
80 |
+
- Updated parser.php constructors for PHP7 compatibility.
|
81 |
+
- Updated the adodb time library for PHP7 compatibility.
|
82 |
+
- Introduced the Shortcode Generator class.
|
83 |
+
- New utils.
|
84 |
+
|
85 |
+
## 1.8 (November 10, 2015)
|
86 |
+
|
87 |
+
- Tagged for Views 1.11.1, Types 1.8.9 and CRED 1.4.2
|
88 |
+
- Improved the media manager script.
|
89 |
+
- Added helper functions for dealing with $_GET, $_POST and arrays.
|
90 |
+
- Improved CRED file uploads.
|
91 |
+
- Improved taxonomy management in CRED forms.
|
92 |
+
- Improved usermeta fields management in CRED forms.
|
93 |
+
|
94 |
+
## 1.7 (October 30, 2015)
|
95 |
+
|
96 |
+
- Tagged for Views 1.11 and Layouts 1.4
|
97 |
+
|
98 |
+
## 1.6.2 (September 25, 2015)
|
99 |
+
|
100 |
+
- Tagged for CRED 1.4, Types 1.8.2
|
101 |
+
|
102 |
+
## 1.6.1 (August 17, 2015)
|
103 |
+
|
104 |
+
- Tagged for Composer Types 1.8, Views 1.10, CRED 1.4 and Layouts 1.3
|
105 |
+
|
106 |
+
## 1.6 (June 11, 2015)
|
107 |
+
|
108 |
+
- Tagged for Types 1.7, Views 1.9 and Layouts 1.2
|
109 |
+
|
110 |
+
## 1.5 (Apr 1, 2015)
|
111 |
+
|
112 |
+
- Tagged for Types 1.6.6, Views 1.8, CRED 1.3.6 and Layouts 1.1.
|
113 |
+
- Fixed issue when there is more than one CRED form on a page with the same taxonomy.
|
114 |
+
- Fixed a little problem with edit skype button modal window - was too narrow.
|
115 |
+
- Fixed empty title problem for filter "wpt_field_options" on user edit/add screen.
|
116 |
+
https://wp-types.com/forums/topic/populate-select-field-in-wpcf-um-group/
|
117 |
+
- Added filter "toolset_editor_add_form_buttons" to disable Toolset buttons on the post editor.
|
118 |
+
- Added placeholder attributes to fields.
|
119 |
+
- Updated CakePHP validation URL method to allow new TLD's.
|
120 |
+
|
121 |
+
## 1.4 (Feb 2 2015)
|
122 |
+
|
123 |
+
- Tagged for Views 1.7, Types 1.6.5, CRED 1.3.5 and Layouts 1.0 beta1
|
124 |
+
- Updated Installer to 1.5
|
125 |
+
|
126 |
+
## 1.3.1 (Dec 16 2014)
|
127 |
+
|
128 |
+
- Tagged for Views 1.7 beta1 and Layouts 1.0 beta1
|
129 |
+
- Fixed issue about Editor addon and ACF compatibility
|
130 |
+
- Fixed issue about branding loader
|
131 |
+
|
132 |
+
## 1.3 (Dec 15 2014)
|
133 |
+
|
134 |
+
- Tagged for Views 1.7 beta1 and Layouts 1.0 beta1
|
|
|
|
library/toolset/toolset-common/changelog.txt
DELETED
@@ -1,122 +0,0 @@
|
|
1 |
-
Common 2.2.5 (November 5, 2016)
|
2 |
-
- Thorough check for security vulnerabilities.
|
3 |
-
|
4 |
-
Common 2.2.4 (November 2, 2016)
|
5 |
-
- Fixed a problem with some assets management by definind better rules on constant definitions.
|
6 |
-
|
7 |
-
-------------------------------------------------------------------------------------------------------------------
|
8 |
-
|
9 |
-
Common 2.2.3 (October 10, 2016)
|
10 |
-
- Fixed select2 edge cases when methods are called on non-select2 initialised element
|
11 |
-
- Refined special handling of old inputs by making sure target is only a select and not the hidden relative element
|
12 |
-
|
13 |
-
-------------------------------------------------------------------------------------------------------------------
|
14 |
-
|
15 |
-
Common 2.2.2 (September 26, 2016)
|
16 |
-
- Updated the bundled select2 script to version 4.0.3
|
17 |
-
- Fixed a problem with some assets URLs lacking a backslash
|
18 |
-
- Improved management of CRED file fields uploads
|
19 |
-
- Improved the frontend markup for CRED taxonomy fields
|
20 |
-
- Added an internal Toolset compatibility class
|
21 |
-
|
22 |
-
-------------------------------------------------------------------------------------------------------------------
|
23 |
-
|
24 |
-
Common 2.2.1 (August 25, 2016)
|
25 |
-
- Avoid translating the Toolset top level admin menu label
|
26 |
-
|
27 |
-
-------------------------------------------------------------------------------------------------------------------
|
28 |
-
|
29 |
-
Common 2.2 (August 24, 2016)
|
30 |
-
- Added compatibility classes for Relevanssi and Beaver Builder
|
31 |
-
- Added a CSS components class
|
32 |
-
- Improved the Toolset Common assets management
|
33 |
-
- Added the Glyphicons library
|
34 |
-
|
35 |
-
-------------------------------------------------------------------------------------------------------------------
|
36 |
-
|
37 |
-
Common 2.1 (June 13, 2016)
|
38 |
-
- Refactored event-manager library to toolset-event manager to namespace it and avoid conficts with ACF Plugin
|
39 |
-
- Added a new class for promotional and help videos management
|
40 |
-
- Improved compatibility with PHP 5.2
|
41 |
-
- Improved compatibility with WPML, including admin language switchers and loading times
|
42 |
-
- Improved compatibility for CRED file uploads and bundled scripts
|
43 |
-
- Fixed double slashes on assets URLs
|
44 |
-
|
45 |
-
-------------------------------------------------------------------------------------------------------------------
|
46 |
-
|
47 |
-
Common 2.0 (April 7, 2016)
|
48 |
-
- Created new loader to load resources for all plugins when plugin loads
|
49 |
-
- Refactored in a more organised way files and resources to be compatible with the new loader
|
50 |
-
- Added scripts and styles manager class to register and enqueue static resources with a unified system
|
51 |
-
- Added Toolset Dialog Boxes to provide a unified way to create and render dialogs
|
52 |
-
- Fixed various bugs
|
53 |
-
|
54 |
-
-------------------------------------------------------------------------------------------------------------------
|
55 |
-
|
56 |
-
Common 1.9.2 (March 17, 2016)
|
57 |
-
- Fixed issue in validation messages on Amazon S3
|
58 |
-
|
59 |
-
-------------------------------------------------------------------------------------------------------------------
|
60 |
-
Common 1.9.1 (March 15, 2016)
|
61 |
-
- Added control to filter array to prevent exceptions
|
62 |
-
- Prevented error when object does not have property or key is not set in array filter callback
|
63 |
-
- Fixed glitch in validation library
|
64 |
-
- Absolute path to include toolset-forms/api.php
|
65 |
-
- Fixed search terms with language translation
|
66 |
-
|
67 |
-
-------------------------------------------------------------------------------------------------------------------
|
68 |
-
Common 1.9 (February 15, 2016)
|
69 |
-
- Tagged for Types 1.9, Views 1.12, CRED 1.5, Layouts 1.5 and Access 1.2.8
|
70 |
-
- Updated parser.php constructors for PHP7 compatibility.
|
71 |
-
- Updated the adodb time library for PHP7 compatibility.
|
72 |
-
- Introduced the Shortcode Generator class.
|
73 |
-
- New utils.
|
74 |
-
|
75 |
-
-------------------------------------------------------------------------------------------------------------------
|
76 |
-
Common 1.8 (November 10, 2015)
|
77 |
-
- Tagged for Views 1.11.1, Types 1.8.9 and CRED 1.4.2
|
78 |
-
- Improved the media manager script.
|
79 |
-
- Added helper functions for dealing with $_GET, $_POST and arrays.
|
80 |
-
- Improved CRED file uploads.
|
81 |
-
- Improved taxonomy management in CRED forms.
|
82 |
-
- Improved usermeta fields management in CRED forms.
|
83 |
-
|
84 |
-
-------------------------------------------------------------------------------------------------------------------
|
85 |
-
Common 1.7 (October 30, 2015)
|
86 |
-
- Tagged for Views 1.11 and Layouts 1.4
|
87 |
-
|
88 |
-
-------------------------------------------------------------------------------------------------------------------
|
89 |
-
Common 1.6.2 (September 25, 2015)
|
90 |
-
- Tagged for CRED 1.4, Types 1.8.2
|
91 |
-
|
92 |
-
Common 1.6.1 (August 17, 2015)
|
93 |
-
- Tagged for Composer Types 1.8, Views 1.10, CRED 1.4 and Layouts 1.3
|
94 |
-
|
95 |
-
Common 1.6 (June 11, 2015)
|
96 |
-
- Tagged for Types 1.7, Views 1.9 and Layouts 1.2
|
97 |
-
|
98 |
-
-------------------------------------------------------------------------------------------------------------------
|
99 |
-
Common 1.5 (Apr 1, 2015)
|
100 |
-
- Tagged for Types 1.6.6, Views 1.8, CRED 1.3.6 and Layouts 1.1.
|
101 |
-
- Fixed issue when there is more than one CRED form on a page with the same taxonomy.
|
102 |
-
- Fixed a little problem with edit skype button modal window - was too narrow.
|
103 |
-
- Fixed empty title problem for filter "wpt_field_options" on user edit/add screen.
|
104 |
-
https://wp-types.com/forums/topic/populate-select-field-in-wpcf-um-group/
|
105 |
-
- Added filter "toolset_editor_add_form_buttons" to disable Toolset buttons on the post editor.
|
106 |
-
- Added placeholder attributes to fields.
|
107 |
-
- Updated CakePHP validation URL method to allow new TLD's.
|
108 |
-
|
109 |
-
-------------------------------------------------------------------------------------------------------------------
|
110 |
-
Common 1.4 (Feb 2 2015)
|
111 |
-
- Tagged for Views 1.7, Types 1.6.5, CRED 1.3.5 and Layouts 1.0 beta1
|
112 |
-
- Updated Installer to 1.5
|
113 |
-
|
114 |
-
-------------------------------------------------------------------------------------------------------------------
|
115 |
-
Common 1.3.1 (Dec 16 2014)
|
116 |
-
- Tagged for Views 1.7 beta1 and Layouts 1.0 beta1
|
117 |
-
- Fixed issue about Editor addon and ACF compatibility
|
118 |
-
- Fixed issue about branding loader
|
119 |
-
|
120 |
-
-------------------------------------------------------------------------------------------------------------------
|
121 |
-
Common 1.3 (Dec 15 2014)
|
122 |
-
- Tagged for Views 1.7 beta1 and Layouts 1.0 beta1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/toolset/toolset-common/loader.php
CHANGED
@@ -8,7 +8,7 @@
|
|
8 |
* plugin loader and then call the toolset_common_initialize function.
|
9 |
* The toolset_common_initialize should be passed the file path to the directory
|
10 |
* where this file is located and also the url to this directory.
|
11 |
-
* Note that both the path and URL will be normalized with untrailingslashit
|
12 |
* so they do not pack any trailing slash.
|
13 |
*
|
14 |
*
|
@@ -30,7 +30,7 @@
|
|
30 |
* Now that we have a unique version for all plugins
|
31 |
* we define the version here
|
32 |
*/
|
33 |
-
$toolset_common_version =
|
34 |
|
35 |
|
36 |
// ----------------------------------------------------------------------//
|
@@ -76,7 +76,7 @@ if ( ! function_exists( 'toolset_common_initialize' ) ) {
|
|
76 |
global $toolset_common_paths;
|
77 |
|
78 |
$path = str_replace( '\\', '/', $path );
|
79 |
-
|
80 |
$path = untrailingslashit( $path );
|
81 |
$url = untrailingslashit( $url );
|
82 |
|
8 |
* plugin loader and then call the toolset_common_initialize function.
|
9 |
* The toolset_common_initialize should be passed the file path to the directory
|
10 |
* where this file is located and also the url to this directory.
|
11 |
+
* Note that both the path and URL will be normalized with untrailingslashit
|
12 |
* so they do not pack any trailing slash.
|
13 |
*
|
14 |
*
|
30 |
* Now that we have a unique version for all plugins
|
31 |
* we define the version here
|
32 |
*/
|
33 |
+
$toolset_common_version = 226000;
|
34 |
|
35 |
|
36 |
// ----------------------------------------------------------------------//
|
76 |
global $toolset_common_paths;
|
77 |
|
78 |
$path = str_replace( '\\', '/', $path );
|
79 |
+
|
80 |
$path = untrailingslashit( $path );
|
81 |
$url = untrailingslashit( $url );
|
82 |
|
library/toolset/toolset-common/toolset-common-loader.php
CHANGED
@@ -5,11 +5,11 @@ if ( class_exists( 'Toolset_Common_Bootstrap' ) ) {
|
|
5 |
};
|
6 |
|
7 |
if( !defined('TOOLSET_VERSION') ){
|
8 |
-
define('TOOLSET_VERSION', '2.2.
|
9 |
}
|
10 |
|
11 |
if ( ! defined('TOOLSET_COMMON_VERSION' ) ) {
|
12 |
-
define( 'TOOLSET_COMMON_VERSION', '2.2.
|
13 |
}
|
14 |
|
15 |
if ( ! defined('TOOLSET_COMMON_PATH' ) ) {
|
5 |
};
|
6 |
|
7 |
if( !defined('TOOLSET_VERSION') ){
|
8 |
+
define('TOOLSET_VERSION', '2.2.6');
|
9 |
}
|
10 |
|
11 |
if ( ! defined('TOOLSET_COMMON_VERSION' ) ) {
|
12 |
+
define( 'TOOLSET_COMMON_VERSION', '2.2.6' );
|
13 |
}
|
14 |
|
15 |
if ( ! defined('TOOLSET_COMMON_PATH' ) ) {
|
library/toolset/toolset-common/toolset-forms/classes/class.eforms.php
CHANGED
@@ -711,7 +711,7 @@ class Enlimbo_Forms {
|
|
711 |
$element['_render']['element'] .= sprintf(' data-wpt-type="%s"', __FUNCTION__);
|
712 |
$element['_render']['element'] .= $this->_getDataWptId($element);
|
713 |
|
714 |
-
|
715 |
* Add html attribute value=""
|
716 |
*
|
717 |
* We have key #value and we also have #default-value key
|
@@ -725,9 +725,16 @@ class Enlimbo_Forms {
|
|
725 |
*
|
726 |
* To get things right we flip the usage of Types fields to handle it the same way as CRED does
|
727 |
*
|
|
|
|
|
728 |
* START Todo: Types should deliver the correct values instead of flipping it here
|
729 |
*/
|
730 |
-
|
|
|
|
|
|
|
|
|
|
|
731 |
$tmp_value = $element['#value'];
|
732 |
|
733 |
$element['#value'] = array_key_exists( '#default_value', $element )
|
711 |
$element['_render']['element'] .= sprintf(' data-wpt-type="%s"', __FUNCTION__);
|
712 |
$element['_render']['element'] .= $this->_getDataWptId($element);
|
713 |
|
714 |
+
/*
|
715 |
* Add html attribute value=""
|
716 |
*
|
717 |
* We have key #value and we also have #default-value key
|
725 |
*
|
726 |
* To get things right we flip the usage of Types fields to handle it the same way as CRED does
|
727 |
*
|
728 |
+
* The fact that a field comes from Types is determined from its name (sic!). This is very fragile.
|
729 |
+
*
|
730 |
* START Todo: Types should deliver the correct values instead of flipping it here
|
731 |
*/
|
732 |
+
$is_types_field = (
|
733 |
+
( strpos( $element['#name'], 'wpcf[' ) === 0 )
|
734 |
+
|| ( strpos( $element['#name'], 'wpcf_post_relationship[' ) === 0 )
|
735 |
+
);
|
736 |
+
|
737 |
+
if( $is_types_field ) {
|
738 |
$tmp_value = $element['#value'];
|
739 |
|
740 |
$element['#value'] = array_key_exists( '#default_value', $element )
|
library/toolset/toolset-common/toolset-forms/classes/class.field_factory.php
CHANGED
@@ -81,17 +81,9 @@ abstract class FieldFactory extends FieldAbstract
|
|
81 |
{
|
82 |
global $post;
|
83 |
$value = $this->_value;
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
if (
|
88 |
-
empty( $value )
|
89 |
-
&& ! is_numeric( $value )
|
90 |
-
&& array_key_exists('user_default_value', $this->_data)
|
91 |
-
&& ! empty( $this->_data['user_default_value'] )
|
92 |
-
) {
|
93 |
-
$value = stripcslashes( $this->_data['user_default_value'] );
|
94 |
-
}
|
95 |
$value = apply_filters( 'wpcf_fields_value_get', $value, $post );
|
96 |
if ( array_key_exists('slug', $this->_data ) ) {
|
97 |
$value = apply_filters( 'wpcf_fields_slug_' . $this->_data['slug'] . '_value_get', $value, $post );
|
@@ -100,6 +92,35 @@ abstract class FieldFactory extends FieldAbstract
|
|
100 |
return $value;
|
101 |
}
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
public function getTitle($_title = false)
|
104 |
{
|
105 |
if ( $_title && empty($this->_data['title']) && isset($this->_data['_title']) ) {
|
81 |
{
|
82 |
global $post;
|
83 |
$value = $this->_value;
|
84 |
+
|
85 |
+
$value = $this->maybe_apply_default_value( $value );
|
86 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
$value = apply_filters( 'wpcf_fields_value_get', $value, $post );
|
88 |
if ( array_key_exists('slug', $this->_data ) ) {
|
89 |
$value = apply_filters( 'wpcf_fields_slug_' . $this->_data['slug'] . '_value_get', $value, $post );
|
92 |
return $value;
|
93 |
}
|
94 |
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Determine whether the actual field value needs to be replaced by a default one.
|
98 |
+
*
|
99 |
+
* @param mixed $actual_value
|
100 |
+
* @return string|mixed The actual value or the default one if the actual one is empty.
|
101 |
+
* @since 2.2.3
|
102 |
+
*/
|
103 |
+
private function maybe_apply_default_value( $actual_value ) {
|
104 |
+
|
105 |
+
// empty( "0" ) == true but we don't want that
|
106 |
+
$is_default_value_needed = ( empty( $actual_value ) && ! is_numeric( $actual_value ) );
|
107 |
+
|
108 |
+
if( $is_default_value_needed ) {
|
109 |
+
|
110 |
+
$default_value = toolset_getarr( $this->_data, 'user_default_value', null );
|
111 |
+
|
112 |
+
// Again, handle "0".
|
113 |
+
$is_default_value_defined = ( ( ! empty( $default_value ) ) || is_numeric( $default_value ) );
|
114 |
+
|
115 |
+
if( $is_default_value_defined ) {
|
116 |
+
return stripcslashes( $default_value );
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
120 |
+
return $actual_value;
|
121 |
+
}
|
122 |
+
|
123 |
+
|
124 |
public function getTitle($_title = false)
|
125 |
{
|
126 |
if ( $_title && empty($this->_data['title']) && isset($this->_data['_title']) ) {
|
library/toolset/toolset-common/toolset-forms/classes/class.taxonomy.php
CHANGED
@@ -13,7 +13,15 @@ class WPToolset_Field_Taxonomy extends WPToolset_Field_Textfield {
|
|
13 |
public function init() {
|
14 |
$this->objValues = array();
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
$i = 0;
|
18 |
foreach ($terms as $n => $term) {
|
19 |
$this->values .= ($i == 0) ? $term->name : "," . $term->name;
|
13 |
public function init() {
|
14 |
$this->objValues = array();
|
15 |
|
16 |
+
// Compatibility with CRED 1.8.4 and above
|
17 |
+
if( class_exists( 'CRED_Form_Rendering' ) ) {
|
18 |
+
$current_post_id = CRED_Form_Rendering::$current_postid;
|
19 |
+
} else {
|
20 |
+
// CRED <= 1.8.3
|
21 |
+
$current_post_id = CredForm::$current_postid;
|
22 |
+
}
|
23 |
+
|
24 |
+
$terms = apply_filters('toolset_filter_taxonomy_terms', wp_get_post_terms( $current_post_id, $this->getName(), array("fields" => "all")));
|
25 |
$i = 0;
|
26 |
foreach ($terms as $n => $term) {
|
27 |
$this->values .= ($i == 0) ? $term->name : "," . $term->name;
|
library/toolset/toolset-common/toolset-forms/classes/class.types.php
CHANGED
@@ -150,13 +150,17 @@ class WPToolset_Types
|
|
150 |
* Loop over validation settings and create array of validation rules.
|
151 |
* array( $rule => array( 'args' => array, 'message' => string ), ... )
|
152 |
*
|
153 |
-
* @param array|string $
|
154 |
* @return array array( $rule => array( 'args' => array, 'message' => string ), ... )
|
155 |
*/
|
156 |
-
public static function filterValidation($config)
|
157 |
{
|
158 |
$config = self::getConfig( $config );
|
159 |
if ( is_null( $config ) ) return array();
|
|
|
|
|
|
|
|
|
160 |
/* Placeholder for field value '$value'.
|
161 |
*
|
162 |
* Used for validation settings.
|
150 |
* Loop over validation settings and create array of validation rules.
|
151 |
* array( $rule => array( 'args' => array, 'message' => string ), ... )
|
152 |
*
|
153 |
+
* @param array|string $config settings array (as stored in DB) or field ID
|
154 |
* @return array array( $rule => array( 'args' => array, 'message' => string ), ... )
|
155 |
*/
|
156 |
+
public static function filterValidation( $config )
|
157 |
{
|
158 |
$config = self::getConfig( $config );
|
159 |
if ( is_null( $config ) ) return array();
|
160 |
+
|
161 |
+
// Handle surplus url/url2 validation rules for CRED fields through this
|
162 |
+
$config = apply_filters( 'toolset_filter_field_definition_array', $config, 'filter_validation' );
|
163 |
+
|
164 |
/* Placeholder for field value '$value'.
|
165 |
*
|
166 |
* Used for validation settings.
|
library/toolset/toolset-common/toolset-forms/js/validation.js
CHANGED
@@ -59,8 +59,8 @@ var wptValidation = (function ($) {
|
|
59 |
if (jQuery(element).hasClass("wpt-form-radio")) {
|
60 |
var val = jQuery('input[name="' + _name + '"]:checked').val();
|
61 |
if (wptValidationDebug)
|
62 |
-
console.log("radio " + (
|
63 |
-
return
|
64 |
}
|
65 |
|
66 |
//Fixing YT cred-104
|
59 |
if (jQuery(element).hasClass("wpt-form-radio")) {
|
60 |
var val = jQuery('input[name="' + _name + '"]:checked').val();
|
61 |
if (wptValidationDebug)
|
62 |
+
console.log("radio " + (typeof val != 'undefined' && val && $.trim(val).length > 0));
|
63 |
+
return typeof val != 'undefined' && val && $.trim(val).length > 0;
|
64 |
}
|
65 |
|
66 |
//Fixing YT cred-104
|
library/toolset/toolset-common/toolset-forms/lib/CakePHP-Validation.php
CHANGED
@@ -55,7 +55,8 @@ class WPToolset_Cake_Validation {
|
|
55 |
* @access private
|
56 |
*/
|
57 |
var $__pattern = array(
|
58 |
-
'hostname' => '(?:[_\p{L}0-9][-_\p{L}0-9]*\.)*(?:[\p{L}0-9][-\p{L}0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,})'
|
|
|
59 |
);
|
60 |
|
61 |
/**
|
@@ -928,37 +929,59 @@ class WPToolset_Cake_Validation {
|
|
928 |
return $_this->_check();
|
929 |
}
|
930 |
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
|
|
950 |
$_this = &WPToolset_Cake_Validation::getInstance();
|
951 |
$_this->__populateIp();
|
952 |
$_this->check = $check;
|
953 |
$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~[]') . '\/0-9\p{L}\p{N}]|(%[0-9a-f]{2}))';
|
|
|
|
|
|
|
954 |
$_this->regex = '/^(?:(?:https?|ftps?|sftp|file|news|gopher):\/\/)' . (!empty($strict) ? '' : '?') .
|
955 |
-
'(?:' . $_this->__pattern['IPv4'] . '|\[' . $_this->__pattern['IPv6'] . '\]|' . $
|
956 |
'(?:\/?|\/' . $validChars . '*)?' .
|
957 |
'(?:\?' . $validChars . '*)?' .
|
958 |
'(?:#' . $validChars . '*)?$/iu';
|
959 |
return $_this->_check();
|
960 |
}
|
961 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
962 |
/**
|
963 |
* Checks if a value is in a given list.
|
964 |
*
|
55 |
* @access private
|
56 |
*/
|
57 |
var $__pattern = array(
|
58 |
+
'hostname' => '(?:[_\p{L}0-9][-_\p{L}0-9]*\.)*(?:[\p{L}0-9][-\p{L}0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,})',
|
59 |
+
'hostname_without_tld' => '(?:[_\p{L}0-9][-_\p{L}0-9]*\.)*(?:[\p{L}0-9][-\p{L}0-9]{0,62})(?:\.(?:(?:[a-z]{2}\.)?[a-z]{2,}))?'
|
60 |
);
|
61 |
|
62 |
/**
|
929 |
return $_this->_check();
|
930 |
}
|
931 |
|
932 |
+
/**
|
933 |
+
* Checks that a value is a valid URL according to http://www.w3.org/Addressing/URL/url-spec.txt
|
934 |
+
*
|
935 |
+
* The regex checks for the following component parts:
|
936 |
+
*
|
937 |
+
* - a valid, optional, scheme
|
938 |
+
* - a valid ip address OR
|
939 |
+
* a valid domain name as defined by section 2.3.1 of http://www.ietf.org/rfc/rfc1035.txt
|
940 |
+
* with an optional port number
|
941 |
+
* - an optional valid path
|
942 |
+
* - an optional query string (get parameters)
|
943 |
+
* - an optional fragment (anchor tag)
|
944 |
+
*
|
945 |
+
* @param string $check Value to check
|
946 |
+
* @param boolean $strict Require URL to be prefixed by a valid scheme (one of http(s)/ftp(s)/file/news/gopher)
|
947 |
+
* @param bool $require_tld Require the hostname to contain TLD. True by default.
|
948 |
+
*
|
949 |
+
* @return bool Success
|
950 |
+
*/
|
951 |
+
function url( $check, $strict = false, $require_tld = true ) {
|
952 |
$_this = &WPToolset_Cake_Validation::getInstance();
|
953 |
$_this->__populateIp();
|
954 |
$_this->check = $check;
|
955 |
$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~[]') . '\/0-9\p{L}\p{N}]|(%[0-9a-f]{2}))';
|
956 |
+
|
957 |
+
$hostname_pattern = $_this->__pattern[ ( $require_tld ? 'hostname' : 'hostname_without_tld' ) ];
|
958 |
+
|
959 |
$_this->regex = '/^(?:(?:https?|ftps?|sftp|file|news|gopher):\/\/)' . (!empty($strict) ? '' : '?') .
|
960 |
+
'(?:' . $_this->__pattern['IPv4'] . '|\[' . $_this->__pattern['IPv6'] . '\]|' . $hostname_pattern . ')(?::[1-9][0-9]{0,4})?' .
|
961 |
'(?:\/?|\/' . $validChars . '*)?' .
|
962 |
'(?:\?' . $validChars . '*)?' .
|
963 |
'(?:#' . $validChars . '*)?$/iu';
|
964 |
return $_this->_check();
|
965 |
}
|
966 |
|
967 |
+
|
968 |
+
/**
|
969 |
+
* Alternative URL validation that (more or less) corresponds to the url2 validation method in jQuery UI.
|
970 |
+
*
|
971 |
+
* It is less strict than the standard 'url' because it doesn't require the TLD to be present in the hostname.
|
972 |
+
* Parameters are directly passed to self::url().
|
973 |
+
*
|
974 |
+
* @param string $check Value to check.
|
975 |
+
* @param bool $strict
|
976 |
+
*
|
977 |
+
* @return bool Validation result.
|
978 |
+
* @since 2.2.6
|
979 |
+
*/
|
980 |
+
function url2( $check, $strict = false ) {
|
981 |
+
return $this->url( $check, $strict, false );
|
982 |
+
}
|
983 |
+
|
984 |
+
|
985 |
/**
|
986 |
* Checks if a value is in a given list.
|
987 |
*
|
library/toolset/toolset-common/utility/autoloader.php
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Toolset autoloader class.
|
5 |
+
*
|
6 |
+
* Based on classmaps, so each plugin or TCL section that uses this needs to register a classmap
|
7 |
+
* either directly or via the toolset_register_classmap action hook.
|
8 |
+
*
|
9 |
+
* @since m2m
|
10 |
+
*/
|
11 |
+
final class Toolset_Common_Autoloader {
|
12 |
+
|
13 |
+
private static $instance;
|
14 |
+
|
15 |
+
public static function get_instance() {
|
16 |
+
if( self::$instance === null ) {
|
17 |
+
self::$instance = new self;
|
18 |
+
}
|
19 |
+
|
20 |
+
return self::$instance;
|
21 |
+
}
|
22 |
+
|
23 |
+
|
24 |
+
private function __construct() { }
|
25 |
+
|
26 |
+
private function __clone() { }
|
27 |
+
|
28 |
+
|
29 |
+
private static $is_initialized = false;
|
30 |
+
|
31 |
+
|
32 |
+
/**
|
33 |
+
* This needs to be called before any other autoloader features are used.
|
34 |
+
*
|
35 |
+
* @since m2m
|
36 |
+
*/
|
37 |
+
public static function initialize() {
|
38 |
+
|
39 |
+
if( self::$is_initialized ) {
|
40 |
+
return;
|
41 |
+
}
|
42 |
+
|
43 |
+
$instance = self::get_instance();
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Action hook for registering a classmap.
|
47 |
+
*
|
48 |
+
* The one who is adding mappings is responsible for existence of the files.
|
49 |
+
*
|
50 |
+
* @param string[string] $classmap class name => absolute path to a file where this class is defined
|
51 |
+
* @throws InvalidArgumentException
|
52 |
+
* @since m2m
|
53 |
+
*/
|
54 |
+
add_action( 'toolset_register_classmap', array( $instance, 'register_classmap' ) );
|
55 |
+
|
56 |
+
// Actually register the autoloader.
|
57 |
+
//
|
58 |
+
// If available (PHP >= 5.3.0), we're setting $prepend = true because this implementation is significantly
|
59 |
+
// faster than other (legacy) Toolset autoloaders, especially when they don't find the class we're looking for.
|
60 |
+
// This will (statistically) save a lot of execution time.
|
61 |
+
if ( PHP_VERSION_ID < 50300 ) {
|
62 |
+
spl_autoload_register( array( $instance, 'autoload' ), true );
|
63 |
+
} else {
|
64 |
+
spl_autoload_register( array( $instance, 'autoload' ), true, true );
|
65 |
+
}
|
66 |
+
|
67 |
+
self::$is_initialized = true;
|
68 |
+
}
|
69 |
+
|
70 |
+
|
71 |
+
private $classmap = array();
|
72 |
+
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Register a classmap.
|
76 |
+
*
|
77 |
+
* Merges given classmap with the existing one.
|
78 |
+
*
|
79 |
+
* The one who is adding mappings is responsible for existence of the files.
|
80 |
+
*
|
81 |
+
* @param string[string] $classmap class name => absolute path to a file where this class is defined
|
82 |
+
* @throws InvalidArgumentException
|
83 |
+
* @since m2m
|
84 |
+
*/
|
85 |
+
public function register_classmap( $classmap ) {
|
86 |
+
|
87 |
+
if( ! is_array( $classmap ) ) {
|
88 |
+
throw new InvalidArgumentException( 'The classmap must be an array.' );
|
89 |
+
}
|
90 |
+
|
91 |
+
$this->classmap = array_merge( $this->classmap, $classmap );
|
92 |
+
|
93 |
+
}
|
94 |
+
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Try to autoload a class if it's in the classmap.
|
98 |
+
*
|
99 |
+
* @param string $class_name
|
100 |
+
* @return bool True if the file specified by the classmap was loaded, false otherwise.
|
101 |
+
* @since m2m
|
102 |
+
*/
|
103 |
+
public function autoload( $class_name ) {
|
104 |
+
|
105 |
+
if( array_key_exists( $class_name, $this->classmap ) ) {
|
106 |
+
$file_name = $this->classmap[ $class_name ];
|
107 |
+
|
108 |
+
// If this causes an error, blame the one who filled the $classmap.
|
109 |
+
require_once $file_name;
|
110 |
+
|
111 |
+
return true;
|
112 |
+
}
|
113 |
+
|
114 |
+
return false;
|
115 |
+
}
|
116 |
+
|
117 |
+
|
118 |
+
|
119 |
+
}
|
library/toolset/toolset-common/utility/utils.php
CHANGED
@@ -101,6 +101,20 @@ if (!class_exists('Toolset_Utils')) {
|
|
101 |
return $sizes;
|
102 |
}
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
105 |
|
106 |
}
|
101 |
return $sizes;
|
102 |
}
|
103 |
|
104 |
+
/**
|
105 |
+
* Check for a custom field value's "emptiness".
|
106 |
+
*
|
107 |
+
* "0" is also a valid value that we need to take into account.
|
108 |
+
*
|
109 |
+
* @param $field_value
|
110 |
+
* @return bool
|
111 |
+
* @since 2.2.3
|
112 |
+
*/
|
113 |
+
public static function is_field_value_truly_empty( $field_value ) {
|
114 |
+
$is_truly_empty = ( empty( $field_value ) && ! is_numeric( $field_value ) );
|
115 |
+
return $is_truly_empty;
|
116 |
+
}
|
117 |
+
|
118 |
}
|
119 |
|
120 |
}
|
library/toolset/toolset-common/visual-editor/res/js/codemirror/.gitattributes
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
*.txt text
|
2 |
-
*.js text
|
3 |
-
*.html text
|
4 |
-
*.md text
|
5 |
-
*.json text
|
6 |
-
*.yml text
|
7 |
-
*.css text
|
8 |
-
*.svg text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/toolset/toolset-common/visual-editor/res/js/codemirror/.npmignore
DELETED
@@ -1,9 +0,0 @@
|
|
1 |
-
/node_modules
|
2 |
-
/demo
|
3 |
-
/doc
|
4 |
-
/test
|
5 |
-
/index.html
|
6 |
-
/mode/*/*test.js
|
7 |
-
/mode/*/*.html
|
8 |
-
/mode/index.html
|
9 |
-
.*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/toolset/toolset-common/visual-editor/res/js/codemirror/.travis.yml
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
language: node_js
|
2 |
-
node_js:
|
3 |
-
- stable
|
4 |
-
sudo: false
|
|
|
|
|
|
|
|
library/toolset/types/.travis.yml
DELETED
@@ -1,29 +0,0 @@
|
|
1 |
-
language: php
|
2 |
-
|
3 |
-
notifications:
|
4 |
-
email:
|
5 |
-
on_success: never
|
6 |
-
on_failure: change
|
7 |
-
|
8 |
-
branches:
|
9 |
-
only:
|
10 |
-
- master
|
11 |
-
|
12 |
-
php:
|
13 |
-
- 5.3
|
14 |
-
- 5.6
|
15 |
-
|
16 |
-
env:
|
17 |
-
- WP_VERSION=latest WP_MULTISITE=0
|
18 |
-
- WP_VERSION=3.7 WP_MULTISITE=0
|
19 |
-
- WP_VERSION=4.4.1 WP_MULTISITE=0
|
20 |
-
|
21 |
-
matrix:
|
22 |
-
include:
|
23 |
-
- php: 5.3
|
24 |
-
env: WP_VERSION=latest WP_MULTISITE=1
|
25 |
-
|
26 |
-
before_script:
|
27 |
-
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
|
28 |
-
|
29 |
-
script: phpunit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/toolset/types/bin/install-wp-tests.sh
DELETED
@@ -1,118 +0,0 @@
|
|
1 |
-
#!/usr/bin/env bash
|
2 |
-
|
3 |
-
if [ $# -lt 3 ]; then
|
4 |
-
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
|
5 |
-
exit 1
|
6 |
-
fi
|
7 |
-
|
8 |
-
DB_NAME=$1
|
9 |
-
DB_USER=$2
|
10 |
-
DB_PASS=$3
|
11 |
-
DB_HOST=${4-localhost}
|
12 |
-
WP_VERSION=${5-latest}
|
13 |
-
|
14 |
-
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
|
15 |
-
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
|
16 |
-
|
17 |
-
download() {
|
18 |
-
if [ `which curl` ]; then
|
19 |
-
curl -s "$1" > "$2";
|
20 |
-
elif [ `which wget` ]; then
|
21 |
-
wget -nv -O "$2" "$1"
|
22 |
-
fi
|
23 |
-
}
|
24 |
-
|
25 |
-
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
|
26 |
-
WP_TESTS_TAG="tags/$WP_VERSION"
|
27 |
-
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
|
28 |
-
WP_TESTS_TAG="trunk"
|
29 |
-
else
|
30 |
-
# http serves a single offer, whereas https serves multiple. we only want one
|
31 |
-
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
|
32 |
-
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
|
33 |
-
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
|
34 |
-
if [[ -z "$LATEST_VERSION" ]]; then
|
35 |
-
echo "Latest WordPress version could not be found"
|
36 |
-
exit 1
|
37 |
-
fi
|
38 |
-
WP_TESTS_TAG="tags/$LATEST_VERSION"
|
39 |
-
fi
|
40 |
-
|
41 |
-
set -ex
|
42 |
-
|
43 |
-
install_wp() {
|
44 |
-
|
45 |
-
if [ -d $WP_CORE_DIR ]; then
|
46 |
-
return;
|
47 |
-
fi
|
48 |
-
|
49 |
-
mkdir -p $WP_CORE_DIR
|
50 |
-
|
51 |
-
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
|
52 |
-
mkdir -p /tmp/wordpress-nightly
|
53 |
-
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
|
54 |
-
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
|
55 |
-
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
|
56 |
-
else
|
57 |
-
if [ $WP_VERSION == 'latest' ]; then
|
58 |
-
local ARCHIVE_NAME='latest'
|
59 |
-
else
|
60 |
-
local ARCHIVE_NAME="wordpress-$WP_VERSION"
|
61 |
-
fi
|
62 |
-
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
|
63 |
-
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
|
64 |
-
fi
|
65 |
-
|
66 |
-
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
|
67 |
-
}
|
68 |
-
|
69 |
-
install_test_suite() {
|
70 |
-
# portable in-place argument for both GNU sed and Mac OSX sed
|
71 |
-
if [[ $(uname -s) == 'Darwin' ]]; then
|
72 |
-
local ioption='-i .bak'
|
73 |
-
else
|
74 |
-
local ioption='-i'
|
75 |
-
fi
|
76 |
-
|
77 |
-
# set up testing suite if it doesn't yet exist
|
78 |
-
if [ ! -d $WP_TESTS_DIR ]; then
|
79 |
-
# set up testing suite
|
80 |
-
mkdir -p $WP_TESTS_DIR
|
81 |
-
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
|
82 |
-
fi
|
83 |
-
|
84 |
-
if [ ! -f wp-tests-config.php ]; then
|
85 |
-
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
|
86 |
-
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
|
87 |
-
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
|
88 |
-
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
|
89 |
-
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
|
90 |
-
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
|
91 |
-
fi
|
92 |
-
|
93 |
-
}
|
94 |
-
|
95 |
-
install_db() {
|
96 |
-
# parse DB_HOST for port or socket references
|
97 |
-
local PARTS=(${DB_HOST//\:/ })
|
98 |
-
local DB_HOSTNAME=${PARTS[0]};
|
99 |
-
local DB_SOCK_OR_PORT=${PARTS[1]};
|
100 |
-
local EXTRA=""
|
101 |
-
|
102 |
-
if ! [ -z $DB_HOSTNAME ] ; then
|
103 |
-
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
|
104 |
-
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
|
105 |
-
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
|
106 |
-
EXTRA=" --socket=$DB_SOCK_OR_PORT"
|
107 |
-
elif ! [ -z $DB_HOSTNAME ] ; then
|
108 |
-
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
|
109 |
-
fi
|
110 |
-
fi
|
111 |
-
|
112 |
-
# create database
|
113 |
-
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
|
114 |
-
}
|
115 |
-
|
116 |
-
install_wp
|
117 |
-
install_test_suite
|
118 |
-
install_db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/toolset/types/disabled_autoload_classmap.php
DELETED
@@ -1,101 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
// Generated by ZF2's ./bin/classmap_generator.php
|
3 |
-
return array(
|
4 |
-
'WPCF_Import_Export' => WPCF_ABSPATH . '/embedded/classes/class.wpcf-import-export.php',
|
5 |
-
'WPCF_Post_Types' => WPCF_ABSPATH . '/embedded/classes/class.wpcf-post-types.php',
|
6 |
-
'WPCF_Conditional' => WPCF_ABSPATH . '/embedded/classes/conditional.php',
|
7 |
-
'WPCF_Editor' => WPCF_ABSPATH . '/embedded/classes/editor.php',
|
8 |
-
'WPCF_Evaluate' => WPCF_ABSPATH . '/embedded/classes/evaluate.php',
|
9 |
-
'WPCF_Field_Accessor_Abstract' => WPCF_ABSPATH . '/embedded/classes/field/accessor/abstract.php',
|
10 |
-
'WPCF_Field_Accessor_Dummy' => WPCF_ABSPATH . '/embedded/classes/field/accessor/dummy.php',
|
11 |
-
'WPCF_Field_Accessor_Termmeta' => WPCF_ABSPATH . '/embedded/classes/field/accessor/termmeta.php',
|
12 |
-
'WPCF_Field_Accessor_Termmeta_Field' => WPCF_ABSPATH . '/embedded/classes/field/accessor/termmeta_field.php',
|
13 |
-
'WPCF_Field_Data_Saver' => WPCF_ABSPATH . '/embedded/classes/field/data_saver.php',
|
14 |
-
'WPCF_Field_DataMapper_Abstract' => WPCF_ABSPATH . '/embedded/classes/field/datamapper/abstract.php',
|
15 |
-
'WPCF_Field_DataMapper_Checkbox' => WPCF_ABSPATH . '/embedded/classes/field/datamapper/checkbox.php',
|
16 |
-
'WPCF_Field_DataMapper_Checkboxes' => WPCF_ABSPATH . '/embedded/classes/field/datamapper/checkboxes.php',
|
17 |
-
'WPCF_Field_DataMapper_Identity' => WPCF_ABSPATH . '/embedded/classes/field/datamapper/identity.php',
|
18 |
-
'WPCF_Field_Definition' => WPCF_ABSPATH . '/embedded/classes/field/definition.php',
|
19 |
-
'WPCF_Field_Definition_Abstract' => WPCF_ABSPATH . '/embedded/classes/field/definition_abstract.php',
|
20 |
-
'WPCF_Field_Definition_Factory' => WPCF_ABSPATH . '/embedded/classes/field/definition_factory.php',
|
21 |
-
'WPCF_Field_Definition_Factory_Post' => WPCF_ABSPATH . '/embedded/classes/field/definition_factory_post.php',
|
22 |
-
'WPCF_Field_Definition_Factory_Term' => WPCF_ABSPATH . '/embedded/classes/field/definition_factory_term.php',
|
23 |
-
'WPCF_Field_Definition_Factory_User' => WPCF_ABSPATH . '/embedded/classes/field/definition_factory_user.php',
|
24 |
-
'WPCF_Field_Definition_Generic' => WPCF_ABSPATH . '/embedded/classes/field/definition_generic.php',
|
25 |
-
'WPCF_Field_Definition_Post' => WPCF_ABSPATH . '/embedded/classes/field/definition_post.php',
|
26 |
-
'WPCF_Field_Definition_Term' => WPCF_ABSPATH . '/embedded/classes/field/definition_term.php',
|
27 |
-
'WPCF_Field_Definition_User' => WPCF_ABSPATH . '/embedded/classes/field/definition_user.php',
|
28 |
-
'WPCF_Field_Hooks_API' => WPCF_ABSPATH . '/embedded/classes/field/hooks_api.php',
|
29 |
-
'WPCF_Field_Instance' => WPCF_ABSPATH . '/embedded/classes/field/instance.php',
|
30 |
-
'WPCF_Field_Instance_Abstract' => WPCF_ABSPATH . '/embedded/classes/field/instance_abstract.php',
|
31 |
-
'WPCF_Field_Instance_Term' => WPCF_ABSPATH . '/embedded/classes/field/instance_term.php',
|
32 |
-
'WPCF_Field_Instance_Unsaved' => WPCF_ABSPATH . '/embedded/classes/field/instance_unsaved.php',
|
33 |
-
'WPCF_Field_Option_Checkboxes' => WPCF_ABSPATH . '/embedded/classes/field/option_checkboxes.php',
|
34 |
-
'WPCF_Field_Option_Radio' => WPCF_ABSPATH . '/embedded/classes/field/option_radio.php',
|
35 |
-
'WPCF_Field_Option_Select' => WPCF_ABSPATH . '/embedded/classes/field/option_select.php',
|
36 |
-
'WPCF_Field_Renderer_Abstract' => WPCF_ABSPATH . '/embedded/classes/field/renderer/abstract.php',
|
37 |
-
'WPCF_Field_Renderer_Factory' => WPCF_ABSPATH . '/embedded/classes/field/renderer/factory.php',
|
38 |
-
'WPCF_Field_Renderer_Preview_Address' => WPCF_ABSPATH . '/embedded/classes/field/renderer/preview/address.php',
|
39 |
-
'WPCF_Field_Renderer_Preview_Base' => WPCF_ABSPATH . '/embedded/classes/field/renderer/preview/base.php',
|
40 |
-
'WPCF_Field_Renderer_Preview_Checkbox' => WPCF_ABSPATH . '/embedded/classes/field/renderer/preview/checkbox.php',
|
41 |
-
'WPCF_Field_Renderer_Preview_Checkboxes' => WPCF_ABSPATH . '/embedded/classes/field/renderer/preview/checkboxes.php',
|
42 |
-
'WPCF_Field_Renderer_Preview_Colorpicker' => WPCF_ABSPATH . '/embedded/classes/field/renderer/preview/colorpicker.php',
|
43 |
-
'WPCF_Field_Renderer_Preview_Date' => WPCF_ABSPATH . '/embedded/classes/field/renderer/preview/date.php',
|
44 |
-
'WPCF_Field_Renderer_Preview_File' => WPCF_ABSPATH . '/embedded/classes/field/renderer/preview/file.php',
|
45 |
-
'WPCF_Field_Renderer_Preview_Image' => WPCF_ABSPATH . '/embedded/classes/field/renderer/preview/image.php',
|
46 |
-
'WPCF_Field_Renderer_Preview_Radio' => WPCF_ABSPATH . '/embedded/classes/field/renderer/preview/radio.php',
|
47 |
-
'WPCF_Field_Renderer_Preview_Skype' => WPCF_ABSPATH . '/embedded/classes/field/renderer/preview/skype.php',
|
48 |
-
'WPCF_Field_Renderer_Preview_Textfield' => WPCF_ABSPATH . '/embedded/classes/field/renderer/preview/textfield.php',
|
49 |
-
'WPCF_Field_Renderer_Preview_URL' => WPCF_ABSPATH . '/embedded/classes/field/renderer/preview/url.php',
|
50 |
-
'WPCF_Field_Renderer_Toolset_Forms' => WPCF_ABSPATH . '/embedded/classes/field/renderer/toolset_forms.php',
|
51 |
-
'WPCF_Field' => WPCF_ABSPATH . '/embedded/classes/field.php',
|
52 |
-
'WPCF_Termmeta_Field' => WPCF_ABSPATH . '/embedded/classes/field.php',
|
53 |
-
'WPCF_Fields' => WPCF_ABSPATH . '/embedded/classes/fields.php',
|
54 |
-
'WPCF_GUI_Term_Field_Editing' => WPCF_ABSPATH . '/embedded/classes/gui/term_field_editing.php',
|
55 |
-
'WPCF_Helper_Ajax' => WPCF_ABSPATH . '/embedded/classes/helper.ajax.php',
|
56 |
-
'WPCF_Loader' => WPCF_ABSPATH . '/embedded/classes/loader.php',
|
57 |
-
'WPCF_Path' => WPCF_ABSPATH . '/embedded/classes/path.php',
|
58 |
-
'WPCF_Relationship_Child_Form' => WPCF_ABSPATH . '/embedded/classes/relationship/form-child.php',
|
59 |
-
'WPCF_Relationship' => WPCF_ABSPATH . '/embedded/classes/relationship.php',
|
60 |
-
'WPCF_Repeater' => WPCF_ABSPATH . '/embedded/classes/repeater.php',
|
61 |
-
'WPCF_Termmeta_Repeater' => WPCF_ABSPATH . '/embedded/classes/repeater.php',
|
62 |
-
'WPCF_Usermeta_Field' => WPCF_ABSPATH . '/embedded/classes/usermeta_field.php',
|
63 |
-
'WPCF_Usermeta_Repeater' => WPCF_ABSPATH . '/embedded/classes/usermeta_repeater.php',
|
64 |
-
'Wpcf_Cake_Validation' => WPCF_ABSPATH . '/embedded/classes/validation-cakephp.php',
|
65 |
-
'WPCF_Validation' => WPCF_ABSPATH . '/embedded/classes/validation.php',
|
66 |
-
'WPCF_WPViews' => WPCF_ABSPATH . '/embedded/classes/wpviews.php',
|
67 |
-
'WPCF_Autoloader' => WPCF_ABSPATH . '/embedded/includes/autoloader.php',
|
68 |
-
'Types_Data_Installer' => WPCF_ABSPATH . '/embedded/includes/classes/class.types.data.installer.php',
|
69 |
-
'WPCF_WP_filter_state' => WPCF_ABSPATH . '/embedded/includes/fields/wysiwyg.php',
|
70 |
-
'WPCF_Relationship_Model' => WPCF_ABSPATH . '/embedded/models/relationship.php',
|
71 |
-
'Types_Image_View' => WPCF_ABSPATH . '/embedded/views/image.php',
|
72 |
-
'Types_Image_Utils' => WPCF_ABSPATH . '/embedded/views/image.php',
|
73 |
-
'Types_Image_Model' => WPCF_ABSPATH . '/embedded/views/image.php',
|
74 |
-
'Types_Cache' => WPCF_ABSPATH . '/embedded/views/image.php',
|
75 |
-
'Types_Error' => WPCF_ABSPATH . '/embedded/views/image.php',
|
76 |
-
'Types_Admin_Edit_Custom_Fields_Group' => WPCF_ABSPATH . '/includes/classes/class.types.admin.edit.custom.fields.group.php',
|
77 |
-
'Types_Admin_Edit_Fields' => WPCF_ABSPATH . '/includes/classes/class.types.admin.edit.fields.php',
|
78 |
-
'Types_Admin_Edit_Meta_Fields_Group' => WPCF_ABSPATH . '/includes/classes/class.types.admin.edit.meta.fields.group.php',
|
79 |
-
'Types_Admin_Edit_Post_Type' => WPCF_ABSPATH . '/includes/classes/class.types.admin.edit.post.type.php',
|
80 |
-
'Types_Admin_Edit_Taxonomy' => WPCF_ABSPATH . '/includes/classes/class.types.admin.edit.taxonomy.php',
|
81 |
-
'Types_Admin_Fields' => WPCF_ABSPATH . '/includes/classes/class.types.admin.fields.php',
|
82 |
-
'Types_Admin_Page' => WPCF_ABSPATH . '/includes/classes/class.types.admin.page.php',
|
83 |
-
'Types_Admin_Post_Type' => WPCF_ABSPATH . '/includes/classes/class.types.admin.post-type.php',
|
84 |
-
'Types_Admin_Post_Types_List_Table' => WPCF_ABSPATH . '/includes/classes/class.types.admin.post.types.list.table.php',
|
85 |
-
'Types_Admin_Taxonomies_List_Table' => WPCF_ABSPATH . '/includes/classes/class.types.admin.taxonomies.list.table.php',
|
86 |
-
'Types_Admin_Taxonomies' => WPCF_ABSPATH . '/includes/classes/class.types.admin.taxonomies.php',
|
87 |
-
'Types_Admin_Usermeta_Groups_List_Table' => WPCF_ABSPATH . '/includes/classes/class.types.admin.usermeta.groups.list.table.php',
|
88 |
-
'Types_Admin_Usermeta_Control_Table' => WPCF_ABSPATH . '/includes/classes/class.types.admin.usermeta.table.php',
|
89 |
-
'Types_Fields_Conditional' => WPCF_ABSPATH . '/includes/classes/class.types.fields.conditional.php',
|
90 |
-
'WPCF_Custom_Fields_List_Table' => WPCF_ABSPATH . '/includes/classes/class.wpcf.custom.fields.list.table.php',
|
91 |
-
'WPCF_Types_Marketing_Messages' => WPCF_ABSPATH . '/includes/classes/class.wpcf.marketing.messages.php',
|
92 |
-
'WPCF_Types_Marketing' => WPCF_ABSPATH . '/includes/classes/class.wpcf.marketing.php',
|
93 |
-
'WPCF_Roles' => WPCF_ABSPATH . '/includes/classes/class.wpcf.roles.php',
|
94 |
-
'WPCF_Page_Abstract' => WPCF_ABSPATH . '/includes/classes/page/abstract.php',
|
95 |
-
'WPCF_Page_Edit_Termmeta' => WPCF_ABSPATH . '/includes/classes/page/edit/termmeta.php',
|
96 |
-
'WPCF_Page_Edit_Termmeta_Form' => WPCF_ABSPATH . '/includes/classes/page/edit/termmeta_form.php',
|
97 |
-
'WPCF_Page_Listing_Abstract' => WPCF_ABSPATH . '/includes/classes/page/listing/abstract.php',
|
98 |
-
'WPCF_Page_Listing_Table' => WPCF_ABSPATH . '/includes/classes/page/listing/table.php',
|
99 |
-
'WPCF_Page_Listing_Termmeta' => WPCF_ABSPATH . '/includes/classes/page/listing/termmeta.php',
|
100 |
-
'WPCF_Page_Listing_Termmeta_Table' => WPCF_ABSPATH . '/includes/classes/page/listing/termmeta_table.php',
|
101 |
-
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/toolset/types/embedded/frontend.php
CHANGED
@@ -91,147 +91,154 @@ function wpcf_shortcode( $atts, $content = null, $code = '' ) {
|
|
91 |
*
|
92 |
* @return string
|
93 |
*/
|
94 |
-
function types_render_field( $field_id = null, $params = array(), $content = null, $code = '', $allow_parent = true )
|
95 |
-
{
|
96 |
-
|
97 |
-
|
98 |
-
}
|
99 |
|
100 |
-
|
101 |
|
102 |
-
|
103 |
-
|
104 |
|
105 |
-
|
106 |
-
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
}
|
129 |
-
$post_id = $current_post->post_parent;
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
}
|
135 |
-
}
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
}
|
140 |
|
141 |
-
|
142 |
-
|
|
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
}
|
147 |
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
// If field not found return empty string
|
152 |
-
if ( empty( $field ) ) {
|
153 |
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
|
161 |
-
|
162 |
-
|
163 |
|
164 |
-
|
165 |
-
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
|
186 |
-
|
187 |
-
|
188 |
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
if ( !empty( $output ) && isset( $params['separator'] )
|
199 |
-
&& $params['separator'] !== '' ) {
|
200 |
-
$output = implode( html_entity_decode( $params['separator'] ),
|
201 |
-
$output );
|
202 |
-
} else if ( !empty( $output ) ) {
|
203 |
-
$output = implode( ' ', $output );
|
204 |
-
} else {
|
205 |
-
return '';
|
206 |
-
}
|
207 |
-
} else {
|
208 |
-
// Make sure indexed right
|
209 |
-
$_index = 0;
|
210 |
-
foreach ( $meta as $temp_key => $temp_value ) {
|
211 |
-
if ( $_index == $index ) {
|
212 |
-
$params['field_value'] = $temp_value;
|
213 |
-
return types_render_field_single( $field, $params, $content, $code, $temp_key );
|
214 |
-
}
|
215 |
-
$_index++;
|
216 |
-
}
|
217 |
-
// If missed index
|
218 |
-
return '';
|
219 |
-
}
|
220 |
-
$html = $output;
|
221 |
-
} else {
|
222 |
-
return '';
|
223 |
-
}
|
224 |
-
} else {
|
225 |
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
}
|
236 |
|
237 |
function types_render_termmeta( $field_id, $params, $content = null, $code = '' ) {
|
@@ -250,18 +257,11 @@ function types_render_termmeta( $field_id, $params, $content = null, $code = ''
|
|
250 |
|
251 |
if (
|
252 |
! isset( $params['term_id'] )
|
253 |
-
&& (
|
254 |
-
is_tax()
|
255 |
-
|| is_category()
|
256 |
-
|| is_tag()
|
257 |
-
)
|
258 |
) {
|
259 |
global $wp_query;
|
260 |
$term = $wp_query->get_queried_object();
|
261 |
-
if (
|
262 |
-
$term
|
263 |
-
&& isset( $term->term_id )
|
264 |
-
) {
|
265 |
$params['term_id'] = $term->term_id;
|
266 |
}
|
267 |
}
|
@@ -310,8 +310,7 @@ function types_render_termmeta( $field_id, $params, $content = null, $code = ''
|
|
310 |
return '';
|
311 |
} else {
|
312 |
$params['field_value'] = $_temp;
|
313 |
-
return types_render_field_single( $field, $params, $content,
|
314 |
-
$code, $meta_id );
|
315 |
}
|
316 |
} else if ( !empty( $meta ) ) {
|
317 |
$output = '';
|
@@ -331,13 +330,12 @@ function types_render_termmeta( $field_id, $params, $content = null, $code = ''
|
|
331 |
$params['field_value'] = $temp_value;
|
332 |
$temp_output = types_render_field_single( $field, $params,
|
333 |
$content, $code, $temp_key );
|
334 |
-
if ( !
|
335 |
$output[] = $temp_output;
|
336 |
}
|
337 |
}
|
338 |
if ( !empty( $output ) && isset( $params['separator'] ) ) {
|
339 |
-
$output = implode( html_entity_decode( $params['separator'] ),
|
340 |
-
$output );
|
341 |
} else if ( !empty( $output ) ) {
|
342 |
$output = implode( '', $output );
|
343 |
} else {
|
@@ -349,8 +347,7 @@ function types_render_termmeta( $field_id, $params, $content = null, $code = ''
|
|
349 |
foreach ( $meta as $temp_key => $temp_value ) {
|
350 |
if ( $_index == $index ) {
|
351 |
$params['field_value'] = $temp_value;
|
352 |
-
$output = types_render_field_single( $field, $params,
|
353 |
-
$content, $code, $temp_key );
|
354 |
}
|
355 |
$_index++;
|
356 |
}
|
@@ -481,7 +478,7 @@ function types_render_usermeta( $field_id, $params, $content = null, $code = ''
|
|
481 |
$params['field_value'] = $temp_value;
|
482 |
$temp_output = types_render_field_single( $field, $params,
|
483 |
$content, $code, $temp_key );
|
484 |
-
if ( !
|
485 |
$output[] = $temp_output;
|
486 |
}
|
487 |
}
|
@@ -598,8 +595,7 @@ function types_render_field_single( $field, $params, $content = null, $code = ''
|
|
598 |
$output = strval( call_user_func( $_view_func, $params ) );
|
599 |
}
|
600 |
|
601 |
-
|
602 |
-
if ( empty( $output ) && isset( $params['field_value'] )
|
603 |
&& $params['field_value'] !== "" ) {
|
604 |
$output = $params['field_value'];
|
605 |
} else if ( $output == '__wpcf_skip_empty' ) {
|
@@ -610,7 +606,7 @@ function types_render_field_single( $field, $params, $content = null, $code = ''
|
|
610 |
$output = wpcf_frontend_compat_html_output( $output, $field, $content, $params );
|
611 |
} else {
|
612 |
// Prepend name if needed
|
613 |
-
if ( !
|
614 |
&& $params['show_name'] == 'true' ) {
|
615 |
$output = $params['field']['name'] . ': ' . $output;
|
616 |
}
|
91 |
*
|
92 |
* @return string
|
93 |
*/
|
94 |
+
function types_render_field( $field_id = null, $params = array(), $content = null, $code = '', $allow_parent = true ) {
|
95 |
+
if ( empty( $field_id ) ) {
|
96 |
+
return '';
|
97 |
+
}
|
|
|
98 |
|
99 |
+
global $wpcf;
|
100 |
|
101 |
+
// HTML var holds actual output
|
102 |
+
$html = '';
|
103 |
|
104 |
+
// Set post ID to global
|
105 |
+
$post_id = get_the_ID();
|
106 |
|
107 |
+
// check if "$parent" for "id" is allowed
|
108 |
+
// OR if "id" does not contain a "$parent" selection
|
109 |
+
$parent_check = isset( $params['id'] ) && ( $allow_parent || substr( $params['id'], 0, 1 ) !== '$' );
|
110 |
|
111 |
+
// support also 'id' like our shortcode [types] does
|
112 |
+
// @since 2.1
|
113 |
+
if ( ! isset( $params['post_id'] ) && isset( $params['id'] ) && $parent_check ) {
|
114 |
+
$params['post_id'] = $params['id'];
|
115 |
+
}
|
116 |
|
117 |
+
// Check if other post required
|
118 |
+
if ( isset( $params['post_id'] ) ) {
|
119 |
+
// If numeric value
|
120 |
+
if ( is_numeric( $params['post_id'] ) ) {
|
121 |
+
$post_id = intval( $params['post_id'] );
|
122 |
+
|
123 |
+
// WP parent
|
124 |
+
} else if ( $params['post_id'] == '$parent' ) {
|
125 |
+
$current_post = get_post( $post_id );
|
126 |
+
if ( empty( $current_post->post_parent ) ) {
|
127 |
+
return '';
|
128 |
+
}
|
129 |
+
$post_id = $current_post->post_parent;
|
130 |
|
131 |
+
// Types parent
|
132 |
+
} else if ( strpos( $params['post_id'], '$' ) === 0 ) {
|
133 |
+
$post_id = intval( WPCF_Relationship::get_parent( $post_id, trim( $params['post_id'], '$' ) ) );
|
134 |
+
}
|
135 |
+
}
|
|
|
|
|
136 |
|
137 |
+
if ( empty( $post_id ) ) {
|
138 |
+
return '';
|
139 |
+
}
|
|
|
|
|
140 |
|
141 |
+
// Set post
|
142 |
+
$post = get_post( $post_id );
|
|
|
143 |
|
144 |
+
if ( empty( $post ) ) {
|
145 |
+
return '';
|
146 |
+
}
|
147 |
|
148 |
+
// Get field
|
149 |
+
$field = types_get_field( $field_id );
|
|
|
150 |
|
151 |
+
// If field not found return empty string
|
152 |
+
if ( empty( $field ) ) {
|
|
|
|
|
|
|
153 |
|
154 |
+
// Log
|
155 |
+
if ( ! function_exists( 'wplogger' ) ) {
|
156 |
+
require_once WPCF_EMBEDDED_TOOLSET_ABSPATH . '/toolset-common/wplogger.php';
|
157 |
+
}
|
158 |
+
global $wplogger;
|
159 |
+
$wplogger->log( 'types_render_field call for missing field \'' . $field_id . '\'', WPLOG_DEBUG );
|
160 |
|
161 |
+
return '';
|
162 |
+
}
|
163 |
|
164 |
+
// Set field
|
165 |
+
$wpcf->field->set( $post, $field );
|
166 |
|
167 |
+
// See if repetitive
|
168 |
+
if ( types_is_repetitive( $field ) ) {
|
169 |
+
$wpcf->repeater->set( $post_id, $field );
|
170 |
+
$_meta = $wpcf->repeater->_get_meta();
|
171 |
+
$meta = $_meta['custom_order'];
|
172 |
|
173 |
+
// Sometimes if meta is empty - array(0 => '') is returned
|
174 |
+
if ( count( $meta ) == 1 && reset( $meta ) == '' ) {
|
175 |
+
return '';
|
176 |
+
}
|
177 |
+
if ( ! empty( $meta ) ) {
|
178 |
+
$output = '';
|
179 |
|
180 |
+
if ( isset( $params['index'] ) ) {
|
181 |
+
$index = $params['index'];
|
182 |
+
} else {
|
183 |
+
$index = '';
|
184 |
+
}
|
185 |
|
186 |
+
// Allow wpv-for-each shortcode to set the index
|
187 |
+
$index = apply_filters( 'wpv-for-each-index', $index );
|
188 |
|
189 |
+
if ( $index === '' ) {
|
190 |
+
$output = array();
|
191 |
+
foreach ( $meta as $temp_key => $temp_value ) {
|
192 |
+
$params['field_value'] = $temp_value;
|
193 |
+
$temp_output = types_render_field_single( $field, $params, $content, $code, $temp_key );
|
194 |
+
if ( ! Toolset_Utils::is_field_value_truly_empty( $temp_output ) ) {
|
195 |
+
$output[] = $temp_output;
|
196 |
+
}
|
197 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
+
if ( ! empty( $output ) && isset( $params['separator'] )
|
200 |
+
&& $params['separator'] !== ''
|
201 |
+
) {
|
202 |
+
$output = implode( html_entity_decode( $params['separator'] ), $output );
|
203 |
+
} else if ( ! empty( $output ) ) {
|
204 |
+
$output = implode( ' ', $output );
|
205 |
+
} else {
|
206 |
+
return '';
|
207 |
+
}
|
208 |
+
|
209 |
+
} else {
|
210 |
+
// Make sure indexed right
|
211 |
+
$_index = 0;
|
212 |
+
foreach ( $meta as $temp_key => $temp_value ) {
|
213 |
+
if ( $_index == $index ) {
|
214 |
+
$params['field_value'] = $temp_value;
|
215 |
+
|
216 |
+
return types_render_field_single( $field, $params, $content, $code, $temp_key );
|
217 |
+
}
|
218 |
+
$_index ++;
|
219 |
+
}
|
220 |
+
|
221 |
+
// If missed index
|
222 |
+
return '';
|
223 |
+
}
|
224 |
+
$html = $output;
|
225 |
+
} else {
|
226 |
+
return '';
|
227 |
+
}
|
228 |
+
} else {
|
229 |
+
|
230 |
+
// Non-repetitive field
|
231 |
+
$meta_key = wpcf_types_get_meta_prefix( $field ) . $field['slug'];
|
232 |
+
$params['field_value'] = wpcf_get_post_meta( $post_id, $meta_key, true );
|
233 |
+
|
234 |
+
if ( $params['field_value'] == '' && $field['type'] != 'checkbox' ) {
|
235 |
+
return '';
|
236 |
+
}
|
237 |
+
|
238 |
+
$html = types_render_field_single( $field, $params, $content, $code, $wpcf->field->meta_object->meta_id );
|
239 |
+
}
|
240 |
+
|
241 |
+
return $wpcf->field->html( $html, $params );
|
242 |
}
|
243 |
|
244 |
function types_render_termmeta( $field_id, $params, $content = null, $code = '' ) {
|
257 |
|
258 |
if (
|
259 |
! isset( $params['term_id'] )
|
260 |
+
&& ( is_tax() || is_category() || is_tag() )
|
|
|
|
|
|
|
|
|
261 |
) {
|
262 |
global $wp_query;
|
263 |
$term = $wp_query->get_queried_object();
|
264 |
+
if ( $term && isset( $term->term_id ) ) {
|
|
|
|
|
|
|
265 |
$params['term_id'] = $term->term_id;
|
266 |
}
|
267 |
}
|
310 |
return '';
|
311 |
} else {
|
312 |
$params['field_value'] = $_temp;
|
313 |
+
return types_render_field_single( $field, $params, $content, $code, $meta_id );
|
|
|
314 |
}
|
315 |
} else if ( !empty( $meta ) ) {
|
316 |
$output = '';
|
330 |
$params['field_value'] = $temp_value;
|
331 |
$temp_output = types_render_field_single( $field, $params,
|
332 |
$content, $code, $temp_key );
|
333 |
+
if ( ! Toolset_Utils::is_field_value_truly_empty( $temp_output ) ) {
|
334 |
$output[] = $temp_output;
|
335 |
}
|
336 |
}
|
337 |
if ( !empty( $output ) && isset( $params['separator'] ) ) {
|
338 |
+
$output = implode( html_entity_decode( $params['separator'] ), $output );
|
|
|
339 |
} else if ( !empty( $output ) ) {
|
340 |
$output = implode( '', $output );
|
341 |
} else {
|
347 |
foreach ( $meta as $temp_key => $temp_value ) {
|
348 |
if ( $_index == $index ) {
|
349 |
$params['field_value'] = $temp_value;
|
350 |
+
$output = types_render_field_single( $field, $params, $content, $code, $temp_key );
|
|
|
351 |
}
|
352 |
$_index++;
|
353 |
}
|
478 |
$params['field_value'] = $temp_value;
|
479 |
$temp_output = types_render_field_single( $field, $params,
|
480 |
$content, $code, $temp_key );
|
481 |
+
if ( ! Toolset_Utils::is_field_value_truly_empty( $temp_output ) ) {
|
482 |
$output[] = $temp_output;
|
483 |
}
|
484 |
}
|
595 |
$output = strval( call_user_func( $_view_func, $params ) );
|
596 |
}
|
597 |
|
598 |
+
if ( Toolset_Utils::is_field_value_truly_empty( $output ) && isset( $params['field_value'] )
|
|
|
599 |
&& $params['field_value'] !== "" ) {
|
600 |
$output = $params['field_value'];
|
601 |
} else if ( $output == '__wpcf_skip_empty' ) {
|
606 |
$output = wpcf_frontend_compat_html_output( $output, $field, $content, $params );
|
607 |
} else {
|
608 |
// Prepend name if needed
|
609 |
+
if ( ! Toolset_Utils::is_field_value_truly_empty( $output ) && isset( $params['show_name'] )
|
610 |
&& $params['show_name'] == 'true' ) {
|
611 |
$output = $params['field']['name'] . ': ' . $output;
|
612 |
}
|
library/toolset/types/embedded/functions.php
CHANGED
@@ -10,21 +10,24 @@
|
|
10 |
* Returns the post meta or empty string if not available
|
11 |
* Since 2.3 the function no longer has its own caching.
|
12 |
*
|
13 |
-
* @param
|
14 |
-
* @param
|
15 |
-
* @param
|
16 |
-
*
|
|
|
|
|
|
|
17 |
*/
|
18 |
-
function wpcf_get_post_meta($post_id, $meta_key, $
|
19 |
|
20 |
-
$post_meta = get_post_meta( $post_id, $meta_key, $
|
21 |
|
22 |
-
if(
|
23 |
-
|
|
|
24 |
}
|
25 |
|
26 |
-
|
27 |
-
return '';
|
28 |
}
|
29 |
|
30 |
/**
|
@@ -397,8 +400,8 @@ function wpcf_save_settings($settings)
|
|
397 |
|
398 |
/**
|
399 |
* Check if it can be repetitive
|
400 |
-
* @param type
|
401 |
-
* @return
|
402 |
*/
|
403 |
function wpcf_admin_can_be_repetitive($type)
|
404 |
{
|
@@ -407,17 +410,17 @@ function wpcf_admin_can_be_repetitive($type)
|
|
407 |
}
|
408 |
|
409 |
/**
|
410 |
-
* Check if field is repetitive
|
411 |
-
*
|
412 |
-
* @
|
|
|
|
|
413 |
*/
|
414 |
-
function wpcf_admin_is_repetitive($field)
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
$check = intval( $field['data']['repetitive'] );
|
420 |
-
return !empty( $check ) && wpcf_admin_can_be_repetitive( $field['type'] );
|
421 |
}
|
422 |
|
423 |
/**
|
@@ -589,16 +592,24 @@ function wpcf_enqueue_scripts()
|
|
589 |
$select2_version
|
590 |
);
|
591 |
}
|
592 |
-
if ( !wp_style_is('select2', 'registered') ) {
|
593 |
wp_register_style(
|
594 |
-
'select2',
|
595 |
WPCF_EMBEDDED_TOOLSET_RELPATH. '/toolset-common/res/lib/select2/select2.css',
|
596 |
array(),
|
597 |
$select2_version
|
598 |
);
|
599 |
}
|
600 |
-
|
601 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
602 |
}
|
603 |
|
604 |
// Add JS settings
|
10 |
* Returns the post meta or empty string if not available
|
11 |
* Since 2.3 the function no longer has its own caching.
|
12 |
*
|
13 |
+
* @param $post_id
|
14 |
+
* @param $meta_key
|
15 |
+
* @param $is_single
|
16 |
+
*
|
17 |
+
* @return mixed
|
18 |
+
* @deprecated This is no longer needed. For accessing custom fields, use the Toolset_Field* API. For accessing
|
19 |
+
* other postmeta, use get_post_meta() directly.
|
20 |
*/
|
21 |
+
function wpcf_get_post_meta($post_id, $meta_key, $is_single) {
|
22 |
|
23 |
+
$post_meta = get_post_meta( $post_id, $meta_key, $is_single );
|
24 |
|
25 |
+
if( Toolset_Utils::is_field_value_truly_empty( $post_meta ) ) {
|
26 |
+
// no meta data
|
27 |
+
return '';
|
28 |
}
|
29 |
|
30 |
+
return maybe_unserialize( $post_meta );
|
|
|
31 |
}
|
32 |
|
33 |
/**
|
400 |
|
401 |
/**
|
402 |
* Check if it can be repetitive
|
403 |
+
* @param $type
|
404 |
+
* @return bool
|
405 |
*/
|
406 |
function wpcf_admin_can_be_repetitive($type)
|
407 |
{
|
410 |
}
|
411 |
|
412 |
/**
|
413 |
+
* Check if field is repetitive.
|
414 |
+
*
|
415 |
+
* @deprecated Use types_is_repetitive instead.
|
416 |
+
* @param array $field Field definition array.
|
417 |
+
* @return bool
|
418 |
*/
|
419 |
+
function wpcf_admin_is_repetitive( $field ) {
|
420 |
+
$field_type = wpcf_getarr( $field, 'type', '' );
|
421 |
+
$is_repetitive = (int) wpcf_getnest( $field, array( 'data', 'repetitive' ), 0 );
|
422 |
+
|
423 |
+
return ( $is_repetitive && ! empty( $field_type ) && wpcf_admin_can_be_repetitive( $field_type ) );
|
|
|
|
|
424 |
}
|
425 |
|
426 |
/**
|
592 |
$select2_version
|
593 |
);
|
594 |
}
|
595 |
+
if ( !wp_style_is('toolset-select2-css', 'registered') ) {
|
596 |
wp_register_style(
|
597 |
+
'toolset-select2-css',
|
598 |
WPCF_EMBEDDED_TOOLSET_RELPATH. '/toolset-common/res/lib/select2/select2.css',
|
599 |
array(),
|
600 |
$select2_version
|
601 |
);
|
602 |
}
|
603 |
+
if ( !wp_style_is('toolset-select2-overrides-css', 'registered') ) {
|
604 |
+
wp_register_style(
|
605 |
+
'toolset-select2-css',
|
606 |
+
WPCF_EMBEDDED_TOOLSET_RELPATH. '/toolset-common/res/lib/select2/select2-overrides.css',
|
607 |
+
array('toolset-select2-css'),
|
608 |
+
$select2_version
|
609 |
+
);
|
610 |
+
}
|
611 |
+
if ( !wp_style_is('toolset-select2-overrides-css') ) {
|
612 |
+
wp_enqueue_style('toolset-select2-overrides-css');
|
613 |
}
|
614 |
|
615 |
// Add JS settings
|
library/toolset/types/embedded/includes/fields-post.php
CHANGED
@@ -217,20 +217,27 @@ function wpcf_add_meta_boxes( $post_type, $post )
|
|
217 |
|
218 |
// Check if hidden
|
219 |
if ( !isset( $group['__show_meta_box'] ) || $group['__show_meta_box'] != false ) {
|
220 |
-
|
221 |
-
$
|
222 |
-
|
223 |
-
//
|
224 |
-
if
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
}
|
235 |
}
|
236 |
}
|
@@ -397,19 +404,19 @@ function wpcf_admin_post_meta_box_preview( $post, $group, $echo = '' ){
|
|
397 |
/**
|
398 |
* Renders meta box content.
|
399 |
*
|
400 |
-
*
|
401 |
-
*
|
402 |
-
*
|
403 |
-
* @
|
404 |
*
|
405 |
-
* @
|
406 |
-
* @param type $group
|
407 |
-
* @param type $echo
|
408 |
-
* @param type boolean $open_style_editor if true use code for open style editor when edit group
|
409 |
*/
|
410 |
function wpcf_admin_post_meta_box( $post, $group, $echo = '', $open_style_editor = false )
|
411 |
{
|
412 |
-
|
|
|
|
|
|
|
413 |
|
414 |
if (
|
415 |
false === $open_style_editor
|
@@ -578,416 +585,193 @@ function wpcf_admin_post_meta_box( $post, $group, $echo = '', $open_style_editor
|
|
578 |
}
|
579 |
|
580 |
/**
|
581 |
-
*
|
582 |
-
*
|
583 |
-
* Core function. Works and stable. Do not move or change.
|
584 |
-
* If required, add hooks only.
|
585 |
*
|
586 |
* @param int $post_ID
|
587 |
* @param WP_Post $post
|
588 |
-
*
|
589 |
-
* @return bool
|
590 |
*/
|
591 |
-
function wpcf_admin_post_save_post_hook( $post_ID, $post )
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
return;
|
770 |
-
}
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
// OLD
|
775 |
-
|
776 |
-
global $wpcf;
|
777 |
-
|
778 |
-
// Basic cheks
|
779 |
-
/*
|
780 |
-
* Allow this hook to be triggered only if Types form is submitted
|
781 |
-
*/
|
782 |
-
// if ( !isset( $_POST['_wpcf_post_wpnonce'] ) || !wp_verify_nonce( $_POST['_wpcf_post_wpnonce'],
|
783 |
-
// 'update-' . $post->post_type . '_' . $post_ID ) ) {
|
784 |
-
// return false;
|
785 |
-
// }
|
786 |
-
/*
|
787 |
-
* Do not save post if is type of:
|
788 |
-
* revision
|
789 |
-
* attachment
|
790 |
-
* wp-types-group
|
791 |
-
* view
|
792 |
-
* view-template
|
793 |
-
* cred-form
|
794 |
-
*/
|
795 |
-
if ( in_array( $post->post_type, $wpcf->excluded_post_types ) ) {
|
796 |
-
return false;
|
797 |
-
}
|
798 |
-
|
799 |
-
/*
|
800 |
-
*
|
801 |
-
*
|
802 |
-
* Get all groups connected to this $post
|
803 |
-
*/
|
804 |
-
$groups = wpcf_admin_post_get_post_groups_fields( $post );
|
805 |
-
if ( empty( $groups ) ) {
|
806 |
-
return false;
|
807 |
-
}
|
808 |
-
$all_fields = array();
|
809 |
-
$_not_valid = array();
|
810 |
-
$_error = false;
|
811 |
-
|
812 |
-
/*
|
813 |
-
*
|
814 |
-
*
|
815 |
-
* Loop over each group
|
816 |
-
*
|
817 |
-
* TODO Document this
|
818 |
-
* Connect 'wpcf-invalid-fields' with all fields
|
819 |
-
*/
|
820 |
-
foreach ( $groups as $group ) {
|
821 |
-
if ( isset( $group['fields'] ) ) {
|
822 |
-
// Process fields
|
823 |
-
$fields = wpcf_admin_post_process_fields( $post, $group['fields'],
|
824 |
-
true, false, 'validation' );
|
825 |
-
// Validate fields
|
826 |
-
$form = wpcf_form_simple_validate( $fields );
|
827 |
-
$all_fields = $all_fields + $fields;
|
828 |
-
// Collect all not valid fields
|
829 |
-
if ( $form->isError() ) {
|
830 |
-
$_error = true; // Set error only to true
|
831 |
-
$_not_valid = array_merge( $_not_valid,
|
832 |
-
(array) $form->get_not_valid() );
|
833 |
-
}
|
834 |
-
}
|
835 |
-
}
|
836 |
-
// Set fields
|
837 |
-
foreach ( $all_fields as $k => $v ) {
|
838 |
-
// only Types field
|
839 |
-
if ( empty( $v['wpcf-id'] ) ) {
|
840 |
-
continue;
|
841 |
-
}
|
842 |
-
$_temp = new WPCF_Field();
|
843 |
-
$_temp->set( $wpcf->post, $v['wpcf-id'] );
|
844 |
-
$all_fields[$k]['_field'] = $_temp;
|
845 |
-
}
|
846 |
-
foreach ( $_not_valid as $k => $v ) {
|
847 |
-
// only Types field
|
848 |
-
if ( empty( $v['wpcf-id'] ) ) {
|
849 |
-
continue;
|
850 |
-
}
|
851 |
-
$_temp = new WPCF_Field();
|
852 |
-
$_temp->set( $wpcf->post, $v['wpcf-id'] );
|
853 |
-
$_not_valid[$k]['_field'] = $_temp;
|
854 |
-
}
|
855 |
-
|
856 |
-
/*
|
857 |
-
*
|
858 |
-
* Allow interaction here.
|
859 |
-
* Conditional will set $error to false if field is conditional
|
860 |
-
* and not submitted.
|
861 |
-
*/
|
862 |
-
$error = apply_filters( 'wpcf_post_form_error', $_error, $_not_valid, $all_fields );
|
863 |
-
$not_valid = apply_filters( 'wpcf_post_form_not_valid', $_not_valid, $_error, $all_fields );
|
864 |
-
|
865 |
-
// Notify user about error
|
866 |
-
if ( $error ) {
|
867 |
-
wpcf_admin_message_store(
|
868 |
-
__( 'Please check your input data', 'wpcf' ), 'error' );
|
869 |
-
}
|
870 |
-
|
871 |
-
/*
|
872 |
-
* Save invalid elements so user can be informed after redirect.
|
873 |
-
*/
|
874 |
-
if ( !empty( $not_valid ) ) {
|
875 |
-
update_post_meta( $post_ID, 'wpcf-invalid-fields', $not_valid );
|
876 |
-
}
|
877 |
-
|
878 |
-
/*
|
879 |
-
*
|
880 |
-
*
|
881 |
-
*
|
882 |
-
*
|
883 |
-
* Save meta fields
|
884 |
-
*/
|
885 |
-
if ( !empty( $_POST['wpcf'] ) ) {
|
886 |
-
foreach ( $_POST['wpcf'] as $field_slug => $field_value ) {
|
887 |
-
|
888 |
-
// Get field by slug
|
889 |
-
$field = wpcf_fields_get_field_by_slug( $field_slug );
|
890 |
-
if ( empty( $field ) ) {
|
891 |
-
continue;
|
892 |
-
}
|
893 |
-
|
894 |
-
// Set field
|
895 |
-
$wpcf->field->set( $post_ID, $field );
|
896 |
-
|
897 |
-
// Skip copied fields
|
898 |
-
// CHECKPOINT
|
899 |
-
if ( isset( $_POST['wpcf_repetitive_copy'][$field['slug']] ) ) {
|
900 |
-
continue;
|
901 |
-
}
|
902 |
-
|
903 |
-
// Don't save invalid
|
904 |
-
// CHECKPOINT
|
905 |
-
if ( isset( $not_valid[$field['slug']] ) ) {
|
906 |
-
continue;
|
907 |
-
}
|
908 |
-
|
909 |
-
|
910 |
-
/*
|
911 |
-
*
|
912 |
-
*
|
913 |
-
* Saving fields
|
914 |
-
* @since 1.2
|
915 |
-
*
|
916 |
-
* We changed way repetitive fields are saved.
|
917 |
-
* On each save fields are rewritten and order is saved in
|
918 |
-
* '_$slug-sort-order' meta field.
|
919 |
-
*/
|
920 |
-
|
921 |
-
/*
|
922 |
-
*
|
923 |
-
* We marked fields as repetitive in POST['__wpcf_repetitive']
|
924 |
-
* Without this check we won't save any.
|
925 |
-
* @see WPCF_Repeater::get_fields_form()
|
926 |
-
*/
|
927 |
-
if ( isset( $_POST['__wpcf_repetitive'][$wpcf->field->slug] ) ) {
|
928 |
-
/*
|
929 |
-
* Use here WPCF_Repeater class.
|
930 |
-
* WPCF_Repeater::set() - switches to current post
|
931 |
-
* WPCF_Repeater::save() - saves repetitive field
|
932 |
-
*/
|
933 |
-
$wpcf->repeater->set( $post_ID, $field );
|
934 |
-
$wpcf->repeater->save();
|
935 |
-
} else {
|
936 |
-
/*
|
937 |
-
* Use WPCF_Field::save()
|
938 |
-
*/
|
939 |
-
$wpcf->field->save();
|
940 |
-
}
|
941 |
-
|
942 |
-
do_action( 'wpcf_post_field_saved', $post_ID, $field );
|
943 |
-
}
|
944 |
-
}
|
945 |
-
|
946 |
-
/*
|
947 |
-
* Process checkboxes
|
948 |
-
*
|
949 |
-
* TODO Revise and remove
|
950 |
-
* Since Types 1.1.5 we moved this check to embedded/includes/checkbox.php
|
951 |
-
* checkbox.php added permanently to bootstrap.
|
952 |
-
*/
|
953 |
-
foreach ( $all_fields as $field ) {
|
954 |
-
if ( !isset( $field['#type'] ) ) {
|
955 |
-
continue;
|
956 |
-
}
|
957 |
-
// if ( $field['#type'] == 'checkbox'
|
958 |
-
// && !isset( $_POST['wpcf'][$field['wpcf-slug']] ) ) {
|
959 |
-
// $field_data = wpcf_admin_fields_get_field( $field['wpcf-id'] );
|
960 |
-
// if ( isset( $field_data['data']['save_empty'] )
|
961 |
-
// && $field_data['data']['save_empty'] == 'yes' ) {
|
962 |
-
// update_post_meta( $post_ID,
|
963 |
-
// wpcf_types_get_meta_prefix( $field ) . $field['wpcf-slug'],
|
964 |
-
// 0 );
|
965 |
-
// } else {
|
966 |
-
// delete_post_meta( $post_ID,
|
967 |
-
// wpcf_types_get_meta_prefix( $field ) . $field['wpcf-slug'] );
|
968 |
-
// }
|
969 |
-
// }
|
970 |
-
if ( $field['#type'] == 'checkboxes' ) {
|
971 |
-
$field_data = wpcf_admin_fields_get_field( $field['wpcf-id'] );
|
972 |
-
if ( !empty( $field_data['data']['options'] ) ) {
|
973 |
-
$update_data = array();
|
974 |
-
foreach ( $field_data['data']['options'] as $option_id => $option_data ) {
|
975 |
-
if ( !isset( $_POST['wpcf'][$field['wpcf-slug']][$option_id] ) ) {
|
976 |
-
if ( isset( $field_data['data']['save_empty'] ) && $field_data['data']['save_empty'] == 'yes' ) {
|
977 |
-
$update_data[$option_id] = 0;
|
978 |
-
}
|
979 |
-
} else {
|
980 |
-
$update_data[$option_id] = $_POST['wpcf'][$field['wpcf-slug']][$option_id];
|
981 |
-
}
|
982 |
-
}
|
983 |
-
update_post_meta( $post_ID, wpcf_types_get_meta_prefix( $field ) . $field['wpcf-slug'], $update_data );
|
984 |
-
}
|
985 |
-
}
|
986 |
-
}
|
987 |
-
|
988 |
-
do_action( 'wpcf_post_saved', $post_ID );
|
989 |
}
|
990 |
|
|
|
991 |
/**
|
992 |
*
|
993 |
* Only for attachments, only default checkboxes!
|
217 |
|
218 |
// Check if hidden
|
219 |
if ( !isset( $group['__show_meta_box'] ) || $group['__show_meta_box'] != false ) {
|
220 |
+
|
221 |
+
$field_group = Types_Field_Group_Post_Factory::load( $group['slug'] );
|
222 |
+
|
223 |
+
// Skip field groups that can't be loaded
|
224 |
+
if( null !== $field_group ) {
|
225 |
+
|
226 |
+
$group_wpml = new Types_Wpml_Field_Group( $field_group );
|
227 |
+
|
228 |
+
// Add meta boxes
|
229 |
+
if ( empty( $only_preview ) ) {
|
230 |
+
add_meta_box( "wpcf-group-{$group['slug']}",
|
231 |
+
$group_wpml->translate_name(),
|
232 |
+
'wpcf_admin_post_meta_box',
|
233 |
+
$post_type, $group['meta_box_context'], 'high', $group );
|
234 |
+
} else {
|
235 |
+
add_meta_box( "wpcf-group-{$group['slug']}",
|
236 |
+
$group_wpml->translate_name(),
|
237 |
+
'wpcf_admin_post_meta_box_preview', $post_type,
|
238 |
+
$group['meta_box_context'], 'high', $group );
|
239 |
+
}
|
240 |
+
|
241 |
}
|
242 |
}
|
243 |
}
|
404 |
/**
|
405 |
* Renders meta box content.
|
406 |
*
|
407 |
+
* @param $post
|
408 |
+
* @param array $group
|
409 |
+
* @param string $echo
|
410 |
+
* @param bool $open_style_editor if true use code for open style editor when edit group
|
411 |
*
|
412 |
+
* @return string
|
|
|
|
|
|
|
413 |
*/
|
414 |
function wpcf_admin_post_meta_box( $post, $group, $echo = '', $open_style_editor = false )
|
415 |
{
|
416 |
+
|
417 |
+
$field_group = Types_Field_Group_Post_Factory::load( $group['args']['slug'] );
|
418 |
+
// todo Handle null $field_group.
|
419 |
+
$group_wpml = new Types_Wpml_Field_Group( $field_group );
|
420 |
|
421 |
if (
|
422 |
false === $open_style_editor
|
585 |
}
|
586 |
|
587 |
/**
|
588 |
+
* The save_post hook.
|
|
|
|
|
|
|
589 |
*
|
590 |
* @param int $post_ID
|
591 |
* @param WP_Post $post
|
592 |
+
* @since unknown
|
|
|
593 |
*/
|
594 |
+
function wpcf_admin_post_save_post_hook( $post_ID, $post ) {
|
595 |
+
|
596 |
+
// Apparently, some things are *slightly* different when saving a child post in the Post relationships metabox.
|
597 |
+
// Ugly hack that will go away with m2m.
|
598 |
+
//
|
599 |
+
// Note: The types_updating_child_post filter is needed for a situation when user clicks on the Update button
|
600 |
+
// for the parent post. In that case we don't get enough information to determine if a child post is being updated.
|
601 |
+
$is_child_post_update = (
|
602 |
+
( 'wpcf_ajax' == wpcf_getget( 'action' ) && 'pr_save_child_post' == wpcf_getget( 'wpcf_action' ) )
|
603 |
+
|| apply_filters( 'types_updating_child_post', false )
|
604 |
+
);
|
605 |
+
|
606 |
+
global $wpcf;
|
607 |
+
$errors = false;
|
608 |
+
|
609 |
+
// Do not save post if is type of
|
610 |
+
if ( in_array( $post->post_type,
|
611 |
+
array(
|
612 |
+
'revision',
|
613 |
+
'view',
|
614 |
+
'view-template',
|
615 |
+
'cred-form',
|
616 |
+
'cred-user-form',
|
617 |
+
'nav_menu_item',
|
618 |
+
'mediapage'
|
619 |
+
) ) )
|
620 |
+
{
|
621 |
+
return;
|
622 |
+
}
|
623 |
+
|
624 |
+
$_post_wpcf = array();
|
625 |
+
if ( ! empty( $_POST['wpcf'] ) ) {
|
626 |
+
$_post_wpcf = $_POST['wpcf'];
|
627 |
+
}
|
628 |
+
|
629 |
+
// handle checkbox
|
630 |
+
if ( array_key_exists( '_wptoolset_checkbox', $_POST ) && is_array( $_POST['_wptoolset_checkbox'] ) ) {
|
631 |
+
foreach ( $_POST['_wptoolset_checkbox'] as $key => $field_value ) {
|
632 |
+
$field_slug = preg_replace( '/^wpcf\-/', '', $key );
|
633 |
+
if ( array_key_exists( $field_slug, $_post_wpcf ) ) {
|
634 |
+
continue;
|
635 |
+
}
|
636 |
+
$_post_wpcf[ $field_slug ] = false;
|
637 |
+
}
|
638 |
+
}
|
639 |
+
|
640 |
+
// handle radios
|
641 |
+
if ( array_key_exists( '_wptoolset_radios', $_POST ) && is_array( $_POST['_wptoolset_radios'] ) ) {
|
642 |
+
foreach ( $_POST['_wptoolset_radios'] as $key => $field_value ) {
|
643 |
+
$field_slug = preg_replace( '/^wpcf\-/', '', $key );
|
644 |
+
if ( array_key_exists( $field_slug, $_post_wpcf ) ) {
|
645 |
+
continue;
|
646 |
+
}
|
647 |
+
$_post_wpcf[ $field_slug ] = false;
|
648 |
+
}
|
649 |
+
}
|
650 |
+
|
651 |
+
|
652 |
+
if ( count( $_post_wpcf ) ) {
|
653 |
+
$add_error_message = true;
|
654 |
+
if ( isset( $_POST['post_id'] ) && $_POST['post_id'] != $post_ID ) {
|
655 |
+
$add_error_message = false;
|
656 |
+
}
|
657 |
+
|
658 |
+
// check some attachment to delete
|
659 |
+
$delete_attachments = apply_filters( 'wpcf_delete_attachments', true );
|
660 |
+
$images_to_delete = array();
|
661 |
+
if ( $delete_attachments && isset( $_POST['wpcf'] ) && array_key_exists( 'delete-image', $_POST['wpcf'] ) && is_array( $_POST['wpcf']['delete-image'] ) ) {
|
662 |
+
foreach ( $_POST['wpcf']['delete-image'] as $image ) {
|
663 |
+
$images_to_delete[ $image ] = 1;
|
664 |
+
}
|
665 |
+
}
|
666 |
+
foreach ( $_post_wpcf as $field_slug => $field_value ) {
|
667 |
+
// Get field by slug
|
668 |
+
$field = wpcf_fields_get_field_by_slug( $field_slug );
|
669 |
+
if ( empty( $field ) ) {
|
670 |
+
continue;
|
671 |
+
}
|
672 |
+
// Skip copied fields
|
673 |
+
if ( isset( $_POST['wpcf_repetitive_copy'][ $field['slug'] ] ) ) {
|
674 |
+
continue;
|
675 |
+
}
|
676 |
+
|
677 |
+
// This is (apparently) expected for repetitive fields...
|
678 |
+
if ( $is_child_post_update && types_is_repetitive( $field ) ) {
|
679 |
+
$field_value = array( $field_value );
|
680 |
+
}
|
681 |
+
|
682 |
+
$_field_value = ! types_is_repetitive( $field ) ? array( $field_value ) : $field_value;
|
683 |
+
|
684 |
+
// Set config
|
685 |
+
$config = wptoolset_form_filter_types_field( $field, $post_ID, $_post_wpcf );
|
686 |
+
|
687 |
+
// remove from images_to_delete if user add again
|
688 |
+
if ( $delete_attachments && 'image' == $config['type'] ) {
|
689 |
+
$images = $_field_value;
|
690 |
+
if ( ! is_array( $images ) ) {
|
691 |
+
$images = array( $images );
|
692 |
+
}
|
693 |
+
foreach ( $images as $image ) {
|
694 |
+
if ( array_key_exists( $image, $images_to_delete ) ) {
|
695 |
+
unset( $images_to_delete[ $image ] );
|
696 |
+
}
|
697 |
+
}
|
698 |
+
}
|
699 |
+
|
700 |
+
// add filter to remove field name from error message
|
701 |
+
// This filter is toolset-common/toolset-forms/classes/class.validation.php
|
702 |
+
add_filter( 'toolset_common_validation_add_field_name_to_error', '__return_false', 1234, 1 );
|
703 |
+
foreach ( $_field_value as $_k => $_val ) {
|
704 |
+
// Check if valid
|
705 |
+
$validation = wptoolset_form_validate_field( 'post', $config, $_val );
|
706 |
+
$conditional = wptoolset_form_conditional_check( $config );
|
707 |
+
$not_valid = is_wp_error( $validation ) || ! $conditional;
|
708 |
+
if ( $add_error_message && is_wp_error( $validation ) ) {
|
709 |
+
$errors = true;
|
710 |
+
$_errors = $validation->get_error_data();
|
711 |
+
$_msg = sprintf( __( 'Field "%s" not updated:', 'wpcf' ), $field['name'] );
|
712 |
+
wpcf_admin_message_store( $_msg . ' ' . implode( ', ', $_errors ), 'error' );
|
713 |
+
}
|
714 |
+
if ( $not_valid ) {
|
715 |
+
if ( types_is_repetitive( $field ) ) {
|
716 |
+
unset( $field_value[ $_k ] );
|
717 |
+
} else {
|
718 |
+
break;
|
719 |
+
}
|
720 |
+
}
|
721 |
+
}
|
722 |
+
remove_filter( 'toolset_common_validation_add_field_name_to_error', '__return_false', 1234, 1 );
|
723 |
+
// Save field
|
724 |
+
if ( types_is_repetitive( $field ) ) {
|
725 |
+
$wpcf->repeater->set( $post_ID, $field );
|
726 |
+
$wpcf->repeater->save( $field_value );
|
727 |
+
} else if ( ! $not_valid ) {
|
728 |
+
$wpcf->field->set( $post_ID, $field );
|
729 |
+
$wpcf->field->save( $field_value );
|
730 |
+
}
|
731 |
+
do_action( 'wpcf_post_field_saved', $post_ID, $field );
|
732 |
+
// TODO Move to checkboxes
|
733 |
+
if ( $field['type'] == 'checkboxes' ) {
|
734 |
+
if ( ! empty( $field['data']['options'] ) ) {
|
735 |
+
$update_data = array();
|
736 |
+
foreach ( $field['data']['options'] as $option_id => $option_data ) {
|
737 |
+
if ( ! isset( $_POST['wpcf'][ $field['id'] ][ $option_id ] ) ) {
|
738 |
+
if ( isset( $field['data']['save_empty'] ) && $field['data']['save_empty'] == 'yes' ) {
|
739 |
+
$update_data[ $option_id ] = 0;
|
740 |
+
}
|
741 |
+
} else {
|
742 |
+
$update_data[ $option_id ] = $_POST['wpcf'][ $field['id'] ][ $option_id ];
|
743 |
+
}
|
744 |
+
}
|
745 |
+
update_post_meta( $post_ID, $field['meta_key'], $update_data );
|
746 |
+
}
|
747 |
+
}
|
748 |
+
}
|
749 |
+
|
750 |
+
// delete images
|
751 |
+
if ( $delete_attachments && ! empty( $images_to_delete ) ) {
|
752 |
+
$args = array(
|
753 |
+
'post_parent' => $post_ID,
|
754 |
+
'posts_per_page' => - 1,
|
755 |
+
);
|
756 |
+
$children_array = get_children( $args );
|
757 |
+
foreach ( $children_array as $child ) {
|
758 |
+
if ( ! array_key_exists( $child->guid, $images_to_delete ) ) {
|
759 |
+
continue;
|
760 |
+
}
|
761 |
+
wp_delete_attachment( $child->ID );
|
762 |
+
}
|
763 |
+
}
|
764 |
+
|
765 |
+
}
|
766 |
+
if ( $errors ) {
|
767 |
+
update_post_meta( $post_ID, '__wpcf-invalid-fields', true );
|
768 |
+
}
|
769 |
+
do_action( 'wpcf_post_saved', $post_ID );
|
770 |
+
|
771 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
772 |
}
|
773 |
|
774 |
+
|
775 |
/**
|
776 |
*
|
777 |
* Only for attachments, only default checkboxes!
|
library/toolset/types/embedded/includes/fields.php
CHANGED
@@ -248,65 +248,86 @@ function wpcf_admin_fields_get_fields( $only_active = false,
|
|
248 |
|
249 |
$v['meta_type'] = $option_name_to_meta_type[ $option_name ];
|
250 |
$fields[$k] = wpcf_sanitize_field( $v );
|
|
|
|
|
251 |
}
|
252 |
$cache[$cache_key] = apply_filters( 'types_fields', $fields );
|
253 |
return $cache[$cache_key];
|
254 |
}
|
255 |
|
256 |
|
257 |
-
add_filter( '
|
258 |
|
259 |
|
260 |
/**
|
261 |
-
* Modify field
|
262 |
*
|
263 |
-
* Hooked into
|
264 |
*
|
265 |
* Add mandatory validation rules that have not been stored in the database but are needed by Types and toolset-forms
|
266 |
-
* to work properly. Namely it's the URL validation for file fields.
|
267 |
-
*
|
268 |
*
|
269 |
-
* @param array $
|
270 |
* @return array
|
271 |
* @since 2.2.4
|
272 |
*/
|
273 |
-
function
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
|
309 |
-
|
310 |
}
|
311 |
|
312 |
|
248 |
|
249 |
$v['meta_type'] = $option_name_to_meta_type[ $option_name ];
|
250 |
$fields[$k] = wpcf_sanitize_field( $v );
|
251 |
+
|
252 |
+
$fields[ $k ] = apply_filters( 'toolset_filter_field_definition_array', $v, 'types_fields' );
|
253 |
}
|
254 |
$cache[$cache_key] = apply_filters( 'types_fields', $fields );
|
255 |
return $cache[$cache_key];
|
256 |
}
|
257 |
|
258 |
|
259 |
+
add_filter( 'toolset_filter_field_definition_array', 'wpcf_update_mandatory_validation_rules', 10, 2 );
|
260 |
|
261 |
|
262 |
/**
|
263 |
+
* Modify field validation rules.
|
264 |
*
|
265 |
+
* Hooked into toolset_filter_field_definition_array. Not to be used elsewhere.
|
266 |
*
|
267 |
* Add mandatory validation rules that have not been stored in the database but are needed by Types and toolset-forms
|
268 |
+
* to work properly. Namely it's the URL validation for file fields. On the contrary CRED needs these validation rules
|
269 |
+
* removed.
|
270 |
*
|
271 |
+
* @param array $field_definition A field definition array.
|
272 |
* @return array
|
273 |
* @since 2.2.4
|
274 |
*/
|
275 |
+
function wpcf_update_mandatory_validation_rules( $field_definition, $ignored ) {
|
276 |
+
|
277 |
+
// Add URL validation to file fields (containing URLs).
|
278 |
+
//
|
279 |
+
// This doesn't include embed files because they are more variable and the URL validation can be
|
280 |
+
// configured on the Edit Field Group page.
|
281 |
+
$file_fields = array( 'file', 'image', 'audio', 'video' );
|
282 |
+
|
283 |
+
$field_type = toolset_getarr( $field_definition, 'type' );
|
284 |
+
$is_file_field = in_array( $field_type, $file_fields );
|
285 |
+
$validation_rules = wpcf_ensarr( wpcf_getnest( $field_definition, array( 'data', 'validate' ) ) );
|
286 |
+
$has_url2_validation = array_key_exists( 'url2', $validation_rules );
|
287 |
+
|
288 |
+
if ( $is_file_field ) {
|
289 |
+
|
290 |
+
unset( $validation_rules['url'] );
|
291 |
+
|
292 |
+
if ( ! $has_url2_validation ) {
|
293 |
+
|
294 |
+
$default_validation_error_message = __( 'Please enter a valid URL address pointing to the file.', 'wpcf' );
|
295 |
+
$validation_error_messages = array(
|
296 |
+
'file' => $default_validation_error_message,
|
297 |
+
'audio' => __( 'Please enter a valid URL address pointing to the audio file.', 'wpcf' ),
|
298 |
+
'image' => __( 'Please enter a valid URL address pointing to the image file.', 'wpcf' ),
|
299 |
+
'video' => __( 'Please enter a valid URL address pointing to the video file.', 'wpcf' )
|
300 |
+
);
|
301 |
+
|
302 |
+
// The url2 validation doesn't require the TLD part of the URL.
|
303 |
+
$validation_rules['url2'] = array(
|
304 |
+
'active' => '1',
|
305 |
+
'message' => toolset_getarr( $validation_error_messages, $field_type, $default_validation_error_message ),
|
306 |
+
'suppress_for_cred' => true
|
307 |
+
);
|
308 |
+
}
|
309 |
+
|
310 |
+
$field_definition['data']['validate'] = $validation_rules;
|
311 |
+
}
|
312 |
+
|
313 |
+
|
314 |
+
// On the contrary, CRED file fileds MUST NOT use this validation otherwise it won't be possible to
|
315 |
+
// submit not changed fields on the edit form. Thus we're making sure that no such rule goes through.
|
316 |
+
//
|
317 |
+
// These field types come via WPToolset_Types::filterValidation().
|
318 |
+
$cred_file_fields = array( 'credfile', 'credimage', 'credaudio', 'credvideo' );
|
319 |
+
$is_cred_field = in_array( $field_type, $cred_file_fields );
|
320 |
+
|
321 |
+
if( $is_cred_field ) {
|
322 |
+
|
323 |
+
unset( $validation_rules['url'] );
|
324 |
+
unset( $validation_rules['url2'] );
|
325 |
+
|
326 |
+
$field_definition['data']['validate'] = $validation_rules;
|
327 |
+
}
|
328 |
+
|
329 |
|
330 |
+
return $field_definition;
|
331 |
}
|
332 |
|
333 |
|
library/toolset/types/embedded/includes/post-relationship.php
CHANGED
@@ -261,11 +261,14 @@ function wpcf_admin_notice_post_locked_no_parent() {
|
|
261 |
</div>
|
262 |
<?php
|
263 |
}
|
|
|
264 |
/**
|
265 |
* Meta boxes contents output.
|
266 |
*
|
267 |
-
* @param
|
268 |
-
* @param
|
|
|
|
|
269 |
*/
|
270 |
function wpcf_pr_admin_post_meta_box_output( $post, $args )
|
271 |
{
|
261 |
</div>
|
262 |
<?php
|
263 |
}
|
264 |
+
|
265 |
/**
|
266 |
* Meta boxes contents output.
|
267 |
*
|
268 |
+
* @param WP_Post $post
|
269 |
+
* @param array $args
|
270 |
+
*
|
271 |
+
* @return string
|
272 |
*/
|
273 |
function wpcf_pr_admin_post_meta_box_output( $post, $args )
|
274 |
{
|
library/toolset/types/includes/classes/class.types.admin.edit.fields.php
CHANGED
@@ -154,9 +154,7 @@ abstract class Types_Admin_Edit_Fields extends Types_Admin_Page
|
|
154 |
$required = (isset($form_data['data']['validate']['required']['active']) && $form_data['data']['validate']['required']['active'] === "1") ? __('- required','wpcf') : '';
|
155 |
$form_data['id'] = $id;
|
156 |
|
157 |
-
|
158 |
-
* Set title
|
159 |
-
*/
|
160 |
$title = !empty( $form_data['name'] ) ? $form_data['name'] : __( 'Untitled', 'wpcf' );
|
161 |
$title = sprintf(
|
162 |
'<span class="wpcf-legend-update">%s</span> <span class="description">(%s)</span> <span class="wpcf_required_data">%s</span>',
|
@@ -176,10 +174,7 @@ abstract class Types_Admin_Edit_Fields extends Types_Admin_Page
|
|
176 |
|
177 |
$form_field = array();
|
178 |
|
179 |
-
|
180 |
-
* Font Awesome Icon
|
181 |
-
*/
|
182 |
-
$icon = '';
|
183 |
$icon = $this->render_field_icon( $field_init_data );
|
184 |
|
185 |
/**
|
@@ -203,9 +198,7 @@ abstract class Types_Admin_Edit_Fields extends Types_Admin_Page
|
|
203 |
}
|
204 |
*/
|
205 |
|
206 |
-
|
207 |
-
* box title
|
208 |
-
*/
|
209 |
$form_field['box-open'] = array(
|
210 |
'#type' => 'markup',
|
211 |
'#markup' => sprintf(
|
@@ -395,22 +388,37 @@ abstract class Types_Admin_Edit_Fields extends Types_Admin_Page
|
|
395 |
);
|
396 |
break;
|
397 |
}
|
398 |
-
|
399 |
-
{
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
414 |
}
|
415 |
|
416 |
if ( wpcf_admin_can_be_repetitive( $type ) ) {
|
154 |
$required = (isset($form_data['data']['validate']['required']['active']) && $form_data['data']['validate']['required']['active'] === "1") ? __('- required','wpcf') : '';
|
155 |
$form_data['id'] = $id;
|
156 |
|
157 |
+
// Set title
|
|
|
|
|
158 |
$title = !empty( $form_data['name'] ) ? $form_data['name'] : __( 'Untitled', 'wpcf' );
|
159 |
$title = sprintf(
|
160 |
'<span class="wpcf-legend-update">%s</span> <span class="description">(%s)</span> <span class="wpcf_required_data">%s</span>',
|
174 |
|
175 |
$form_field = array();
|
176 |
|
177 |
+
// Font Awesome Icon
|
|
|
|
|
|
|
178 |
$icon = $this->render_field_icon( $field_init_data );
|
179 |
|
180 |
/**
|
198 |
}
|
199 |
*/
|
200 |
|
201 |
+
// box title
|
|
|
|
|
202 |
$form_field['box-open'] = array(
|
203 |
'#type' => 'markup',
|
204 |
'#markup' => sprintf(
|
388 |
);
|
389 |
break;
|
390 |
}
|
391 |
+
|
392 |
+
switch( $type ) {
|
393 |
+
case 'audio':
|
394 |
+
case 'file':
|
395 |
+
case 'image':
|
396 |
+
case 'video':
|
397 |
+
$form_field['user_default_value']['#validate'] = array(
|
398 |
+
'url2' => array(
|
399 |
+
'active' => 1,
|
400 |
+
'message' => __( 'Please enter a valid URL address.', 'wpcf' )
|
401 |
+
)
|
402 |
+
);
|
403 |
+
break;
|
404 |
+
|
405 |
+
case 'embed':
|
406 |
+
case 'url':
|
407 |
+
$form_field['user_default_value']['#validate'] = array(
|
408 |
+
'url' => array(
|
409 |
+
'active' => 1,
|
410 |
+
'message' => __( 'Please enter a valid URL address.', 'wpcf' )
|
411 |
+
)
|
412 |
+
);
|
413 |
+
break;
|
414 |
+
|
415 |
+
case 'email':
|
416 |
+
$form_field['user_default_value']['#validate'] = array( 'email' => array() );
|
417 |
+
break;
|
418 |
+
|
419 |
+
case 'numeric':
|
420 |
+
$form_field['user_default_value']['#validate'] = array( 'number' => array() );
|
421 |
+
break;
|
422 |
}
|
423 |
|
424 |
if ( wpcf_admin_can_be_repetitive( $type ) ) {
|
library/toolset/types/phpunit.xml.dist
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
<phpunit
|
2 |
-
bootstrap="tests/bootstrap.php"
|
3 |
-
backupGlobals="false"
|
4 |
-
colors="true"
|
5 |
-
convertErrorsToExceptions="true"
|
6 |
-
convertNoticesToExceptions="true"
|
7 |
-
convertWarningsToExceptions="true"
|
8 |
-
>
|
9 |
-
<testsuites>
|
10 |
-
<testsuite>
|
11 |
-
<directory prefix="test-" suffix=".php">./tests/</directory>
|
12 |
-
</testsuite>
|
13 |
-
</testsuites>
|
14 |
-
</phpunit>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/.editorconfig
DELETED
@@ -1,18 +0,0 @@
|
|
1 |
-
; top-most EditorConfig file
|
2 |
-
root = true
|
3 |
-
|
4 |
-
; Unix-style newlines
|
5 |
-
[*]
|
6 |
-
end_of_line = LF
|
7 |
-
|
8 |
-
[*.php]
|
9 |
-
indent_style = space
|
10 |
-
indent_size = 4
|
11 |
-
|
12 |
-
[*.test]
|
13 |
-
indent_style = space
|
14 |
-
indent_size = 4
|
15 |
-
|
16 |
-
[*.rst]
|
17 |
-
indent_style = space
|
18 |
-
indent_size = 4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/.travis.yml
DELETED
@@ -1,44 +0,0 @@
|
|
1 |
-
language: php
|
2 |
-
|
3 |
-
sudo: false
|
4 |
-
|
5 |
-
cache:
|
6 |
-
directories:
|
7 |
-
- vendor
|
8 |
-
- $HOME/.composer/cache/files
|
9 |
-
|
10 |
-
php:
|
11 |
-
- 5.2
|
12 |
-
- 5.3
|
13 |
-
- 5.4
|
14 |
-
- 5.5
|
15 |
-
- 5.6
|
16 |
-
- 7.0
|
17 |
-
- 7.1
|
18 |
-
- hhvm
|
19 |
-
|
20 |
-
env:
|
21 |
-
- TWIG_EXT=no
|
22 |
-
- TWIG_EXT=yes
|
23 |
-
|
24 |
-
before_install:
|
25 |
-
- if [[ ! $TRAVIS_PHP_VERSION = hhvm* ]]; then phpenv config-rm xdebug.ini || echo "xdebug not available"; fi
|
26 |
-
|
27 |
-
install:
|
28 |
-
# Composer is not available on PHP 5.2
|
29 |
-
- if [ ${TRAVIS_PHP_VERSION:0:3} != "5.2" ]; then travis_retry composer install; fi
|
30 |
-
|
31 |
-
before_script:
|
32 |
-
- if [ "$TWIG_EXT" == "yes" ]; then sh -c "cd ext/twig && phpize && ./configure --enable-twig && make && make install"; fi
|
33 |
-
- if [ "$TWIG_EXT" == "yes" ]; then echo "extension=twig.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`; fi
|
34 |
-
- if [ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]; then sed -i.bak "s|vendor/autoload.php|test/bootstrap.php|" phpunit.xml.dist; fi
|
35 |
-
|
36 |
-
matrix:
|
37 |
-
fast_finish: true
|
38 |
-
exclude:
|
39 |
-
- php: hhvm
|
40 |
-
env: TWIG_EXT=yes
|
41 |
-
- php: 7.0
|
42 |
-
env: TWIG_EXT=yes
|
43 |
-
- php: 7.1
|
44 |
-
env: TWIG_EXT=yes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/advanced.rst
DELETED
@@ -1,957 +0,0 @@
|
|
1 |
-
Extending Twig
|
2 |
-
==============
|
3 |
-
|
4 |
-
.. caution::
|
5 |
-
|
6 |
-
This section describes how to extend Twig as of **Twig 1.12**. If you are
|
7 |
-
using an older version, read the :doc:`legacy<advanced_legacy>` chapter
|
8 |
-
instead.
|
9 |
-
|
10 |
-
Twig can be extended in many ways; you can add extra tags, filters, tests,
|
11 |
-
operators, global variables, and functions. You can even extend the parser
|
12 |
-
itself with node visitors.
|
13 |
-
|
14 |
-
.. note::
|
15 |
-
|
16 |
-
The first section of this chapter describes how to extend Twig easily. If
|
17 |
-
you want to reuse your changes in different projects or if you want to
|
18 |
-
share them with others, you should then create an extension as described
|
19 |
-
in the following section.
|
20 |
-
|
21 |
-
.. caution::
|
22 |
-
|
23 |
-
When extending Twig without creating an extension, Twig won't be able to
|
24 |
-
recompile your templates when the PHP code is updated. To see your changes
|
25 |
-
in real-time, either disable template caching or package your code into an
|
26 |
-
extension (see the next section of this chapter).
|
27 |
-
|
28 |
-
Before extending Twig, you must understand the differences between all the
|
29 |
-
different possible extension points and when to use them.
|
30 |
-
|
31 |
-
First, remember that Twig has two main language constructs:
|
32 |
-
|
33 |
-
* ``{{ }}``: used to print the result of an expression evaluation;
|
34 |
-
|
35 |
-
* ``{% %}``: used to execute statements.
|
36 |
-
|
37 |
-
To understand why Twig exposes so many extension points, let's see how to
|
38 |
-
implement a *Lorem ipsum* generator (it needs to know the number of words to
|
39 |
-
generate).
|
40 |
-
|
41 |
-
You can use a ``lipsum`` *tag*:
|
42 |
-
|
43 |
-
.. code-block:: jinja
|
44 |
-
|
45 |
-
{% lipsum 40 %}
|
46 |
-
|
47 |
-
That works, but using a tag for ``lipsum`` is not a good idea for at least
|
48 |
-
three main reasons:
|
49 |
-
|
50 |
-
* ``lipsum`` is not a language construct;
|
51 |
-
* The tag outputs something;
|
52 |
-
* The tag is not flexible as you cannot use it in an expression:
|
53 |
-
|
54 |
-
.. code-block:: jinja
|
55 |
-
|
56 |
-
{{ 'some text' ~ {% lipsum 40 %} ~ 'some more text' }}
|
57 |
-
|
58 |
-
In fact, you rarely need to create tags; and that's good news because tags are
|
59 |
-
the most complex extension point of Twig.
|
60 |
-
|
61 |
-
Now, let's use a ``lipsum`` *filter*:
|
62 |
-
|
63 |
-
.. code-block:: jinja
|
64 |
-
|
65 |
-
{{ 40|lipsum }}
|
66 |
-
|
67 |
-
Again, it works, but it looks weird. A filter transforms the passed value to
|
68 |
-
something else but here we use the value to indicate the number of words to
|
69 |
-
generate (so, ``40`` is an argument of the filter, not the value we want to
|
70 |
-
transform).
|
71 |
-
|
72 |
-
Next, let's use a ``lipsum`` *function*:
|
73 |
-
|
74 |
-
.. code-block:: jinja
|
75 |
-
|
76 |
-
{{ lipsum(40) }}
|
77 |
-
|
78 |
-
Here we go. For this specific example, the creation of a function is the
|
79 |
-
extension point to use. And you can use it anywhere an expression is accepted:
|
80 |
-
|
81 |
-
.. code-block:: jinja
|
82 |
-
|
83 |
-
{{ 'some text' ~ lipsum(40) ~ 'some more text' }}
|
84 |
-
|
85 |
-
{% set lipsum = lipsum(40) %}
|
86 |
-
|
87 |
-
Last but not the least, you can also use a *global* object with a method able
|
88 |
-
to generate lorem ipsum text:
|
89 |
-
|
90 |
-
.. code-block:: jinja
|
91 |
-
|
92 |
-
{{ text.lipsum(40) }}
|
93 |
-
|
94 |
-
As a rule of thumb, use functions for frequently used features and global
|
95 |
-
objects for everything else.
|
96 |
-
|
97 |
-
Keep in mind the following when you want to extend Twig:
|
98 |
-
|
99 |
-
========== ========================== ========== =========================
|
100 |
-
What? Implementation difficulty? How often? When?
|
101 |
-
========== ========================== ========== =========================
|
102 |
-
*macro* trivial frequent Content generation
|
103 |
-
*global* trivial frequent Helper object
|
104 |
-
*function* trivial frequent Content generation
|
105 |
-
*filter* trivial frequent Value transformation
|
106 |
-
*tag* complex rare DSL language construct
|
107 |
-
*test* trivial rare Boolean decision
|
108 |
-
*operator* trivial rare Values transformation
|
109 |
-
========== ========================== ========== =========================
|
110 |
-
|
111 |
-
Globals
|
112 |
-
-------
|
113 |
-
|
114 |
-
A global variable is like any other template variable, except that it's
|
115 |
-
available in all templates and macros::
|
116 |
-
|
117 |
-
$twig = new Twig_Environment($loader);
|
118 |
-
$twig->addGlobal('text', new Text());
|
119 |
-
|
120 |
-
You can then use the ``text`` variable anywhere in a template:
|
121 |
-
|
122 |
-
.. code-block:: jinja
|
123 |
-
|
124 |
-
{{ text.lipsum(40) }}
|
125 |
-
|
126 |
-
Filters
|
127 |
-
-------
|
128 |
-
|
129 |
-
Creating a filter is as simple as associating a name with a PHP callable::
|
130 |
-
|
131 |
-
// an anonymous function
|
132 |
-
$filter = new Twig_SimpleFilter('rot13', function ($string) {
|
133 |
-
return str_rot13($string);
|
134 |
-
});
|
135 |
-
|
136 |
-
// or a simple PHP function
|
137 |
-
$filter = new Twig_SimpleFilter('rot13', 'str_rot13');
|
138 |
-
|
139 |
-
// or a class static method
|
140 |
-
$filter = new Twig_SimpleFilter('rot13', array('SomeClass', 'rot13Filter'));
|
141 |
-
$filter = new Twig_SimpleFilter('rot13', 'SomeClass::rot13Filter');
|
142 |
-
|
143 |
-
// or a class method
|
144 |
-
$filter = new Twig_SimpleFilter('rot13', array($this, 'rot13Filter'));
|
145 |
-
// the one below needs a runtime implementation (see below for more information)
|
146 |
-
$filter = new Twig_SimpleFilter('rot13', array('SomeClass', 'rot13Filter'));
|
147 |
-
|
148 |
-
The first argument passed to the ``Twig_SimpleFilter`` constructor is the name
|
149 |
-
of the filter you will use in templates and the second one is the PHP callable
|
150 |
-
to associate with it.
|
151 |
-
|
152 |
-
Then, add the filter to your Twig environment::
|
153 |
-
|
154 |
-
$twig = new Twig_Environment($loader);
|
155 |
-
$twig->addFilter($filter);
|
156 |
-
|
157 |
-
And here is how to use it in a template:
|
158 |
-
|
159 |
-
.. code-block:: jinja
|
160 |
-
|
161 |
-
{{ 'Twig'|rot13 }}
|
162 |
-
|
163 |
-
{# will output Gjvt #}
|
164 |
-
|
165 |
-
When called by Twig, the PHP callable receives the left side of the filter
|
166 |
-
(before the pipe ``|``) as the first argument and the extra arguments passed
|
167 |
-
to the filter (within parentheses ``()``) as extra arguments.
|
168 |
-
|
169 |
-
For instance, the following code:
|
170 |
-
|
171 |
-
.. code-block:: jinja
|
172 |
-
|
173 |
-
{{ 'TWIG'|lower }}
|
174 |
-
{{ now|date('d/m/Y') }}
|
175 |
-
|
176 |
-
is compiled to something like the following::
|
177 |
-
|
178 |
-
<?php echo strtolower('TWIG') ?>
|
179 |
-
<?php echo twig_date_format_filter($now, 'd/m/Y') ?>
|
180 |
-
|
181 |
-
The ``Twig_SimpleFilter`` class takes an array of options as its last
|
182 |
-
argument::
|
183 |
-
|
184 |
-
$filter = new Twig_SimpleFilter('rot13', 'str_rot13', $options);
|
185 |
-
|
186 |
-
Environment-aware Filters
|
187 |
-
~~~~~~~~~~~~~~~~~~~~~~~~~
|
188 |
-
|
189 |
-
If you want to access the current environment instance in your filter, set the
|
190 |
-
``needs_environment`` option to ``true``; Twig will pass the current
|
191 |
-
environment as the first argument to the filter call::
|
192 |
-
|
193 |
-
$filter = new Twig_SimpleFilter('rot13', function (Twig_Environment $env, $string) {
|
194 |
-
// get the current charset for instance
|
195 |
-
$charset = $env->getCharset();
|
196 |
-
|
197 |
-
return str_rot13($string);
|
198 |
-
}, array('needs_environment' => true));
|
199 |
-
|
200 |
-
Context-aware Filters
|
201 |
-
~~~~~~~~~~~~~~~~~~~~~
|
202 |
-
|
203 |
-
If you want to access the current context in your filter, set the
|
204 |
-
``needs_context`` option to ``true``; Twig will pass the current context as
|
205 |
-
the first argument to the filter call (or the second one if
|
206 |
-
``needs_environment`` is also set to ``true``)::
|
207 |
-
|
208 |
-
$filter = new Twig_SimpleFilter('rot13', function ($context, $string) {
|
209 |
-
// ...
|
210 |
-
}, array('needs_context' => true));
|
211 |
-
|
212 |
-
$filter = new Twig_SimpleFilter('rot13', function (Twig_Environment $env, $context, $string) {
|
213 |
-
// ...
|
214 |
-
}, array('needs_context' => true, 'needs_environment' => true));
|
215 |
-
|
216 |
-
Automatic Escaping
|
217 |
-
~~~~~~~~~~~~~~~~~~
|
218 |
-
|
219 |
-
If automatic escaping is enabled, the output of the filter may be escaped
|
220 |
-
before printing. If your filter acts as an escaper (or explicitly outputs HTML
|
221 |
-
or JavaScript code), you will want the raw output to be printed. In such a
|
222 |
-
case, set the ``is_safe`` option::
|
223 |
-
|
224 |
-
$filter = new Twig_SimpleFilter('nl2br', 'nl2br', array('is_safe' => array('html')));
|
225 |
-
|
226 |
-
Some filters may need to work on input that is already escaped or safe, for
|
227 |
-
example when adding (safe) HTML tags to originally unsafe output. In such a
|
228 |
-
case, set the ``pre_escape`` option to escape the input data before it is run
|
229 |
-
through your filter::
|
230 |
-
|
231 |
-
$filter = new Twig_SimpleFilter('somefilter', 'somefilter', array('pre_escape' => 'html', 'is_safe' => array('html')));
|
232 |
-
|
233 |
-
Variadic Filters
|
234 |
-
~~~~~~~~~~~~~~~~
|
235 |
-
|
236 |
-
.. versionadded:: 1.19
|
237 |
-
Support for variadic filters was added in Twig 1.19.
|
238 |
-
|
239 |
-
When a filter should accept an arbitrary number of arguments, set the
|
240 |
-
``is_variadic`` option to ``true``; Twig will pass the extra arguments as the
|
241 |
-
last argument to the filter call as an array::
|
242 |
-
|
243 |
-
$filter = new Twig_SimpleFilter('thumbnail', function ($file, array $options = array()) {
|
244 |
-
// ...
|
245 |
-
}, array('is_variadic' => true));
|
246 |
-
|
247 |
-
Be warned that named arguments passed to a variadic filter cannot be checked
|
248 |
-
for validity as they will automatically end up in the option array.
|
249 |
-
|
250 |
-
Dynamic Filters
|
251 |
-
~~~~~~~~~~~~~~~
|
252 |
-
|
253 |
-
A filter name containing the special ``*`` character is a dynamic filter as
|
254 |
-
the ``*`` can be any string::
|
255 |
-
|
256 |
-
$filter = new Twig_SimpleFilter('*_path', function ($name, $arguments) {
|
257 |
-
// ...
|
258 |
-
});
|
259 |
-
|
260 |
-
The following filters will be matched by the above defined dynamic filter:
|
261 |
-
|
262 |
-
* ``product_path``
|
263 |
-
* ``category_path``
|
264 |
-
|
265 |
-
A dynamic filter can define more than one dynamic parts::
|
266 |
-
|
267 |
-
$filter = new Twig_SimpleFilter('*_path_*', function ($name, $suffix, $arguments) {
|
268 |
-
// ...
|
269 |
-
});
|
270 |
-
|
271 |
-
The filter will receive all dynamic part values before the normal filter
|
272 |
-
arguments, but after the environment and the context. For instance, a call to
|
273 |
-
``'foo'|a_path_b()`` will result in the following arguments to be passed to
|
274 |
-
the filter: ``('a', 'b', 'foo')``.
|
275 |
-
|
276 |
-
Deprecated Filters
|
277 |
-
~~~~~~~~~~~~~~~~~~
|
278 |
-
|
279 |
-
.. versionadded:: 1.21
|
280 |
-
Support for deprecated filters was added in Twig 1.21.
|
281 |
-
|
282 |
-
You can mark a filter as being deprecated by setting the ``deprecated`` option
|
283 |
-
to ``true``. You can also give an alternative filter that replaces the
|
284 |
-
deprecated one when that makes sense::
|
285 |
-
|
286 |
-
$filter = new Twig_SimpleFilter('obsolete', function () {
|
287 |
-
// ...
|
288 |
-
}, array('deprecated' => true, 'alternative' => 'new_one'));
|
289 |
-
|
290 |
-
When a filter is deprecated, Twig emits a deprecation notice when compiling a
|
291 |
-
template using it. See :ref:`deprecation-notices` for more information.
|
292 |
-
|
293 |
-
Functions
|
294 |
-
---------
|
295 |
-
|
296 |
-
Functions are defined in the exact same way as filters, but you need to create
|
297 |
-
an instance of ``Twig_SimpleFunction``::
|
298 |
-
|
299 |
-
$twig = new Twig_Environment($loader);
|
300 |
-
$function = new Twig_SimpleFunction('function_name', function () {
|
301 |
-
// ...
|
302 |
-
});
|
303 |
-
$twig->addFunction($function);
|
304 |
-
|
305 |
-
Functions support the same features as filters, except for the ``pre_escape``
|
306 |
-
and ``preserves_safety`` options.
|
307 |
-
|
308 |
-
Tests
|
309 |
-
-----
|
310 |
-
|
311 |
-
Tests are defined in the exact same way as filters and functions, but you need
|
312 |
-
to create an instance of ``Twig_SimpleTest``::
|
313 |
-
|
314 |
-
$twig = new Twig_Environment($loader);
|
315 |
-
$test = new Twig_SimpleTest('test_name', function () {
|
316 |
-
// ...
|
317 |
-
});
|
318 |
-
$twig->addTest($test);
|
319 |
-
|
320 |
-
Tests allow you to create custom application specific logic for evaluating
|
321 |
-
boolean conditions. As a simple example, let's create a Twig test that checks if
|
322 |
-
objects are 'red'::
|
323 |
-
|
324 |
-
$twig = new Twig_Environment($loader);
|
325 |
-
$test = new Twig_SimpleTest('red', function ($value) {
|
326 |
-
if (isset($value->color) && $value->color == 'red') {
|
327 |
-
return true;
|
328 |
-
}
|
329 |
-
if (isset($value->paint) && $value->paint == 'red') {
|
330 |
-
return true;
|
331 |
-
}
|
332 |
-
return false;
|
333 |
-
});
|
334 |
-
$twig->addTest($test);
|
335 |
-
|
336 |
-
Test functions should always return true/false.
|
337 |
-
|
338 |
-
When creating tests you can use the ``node_class`` option to provide custom test
|
339 |
-
compilation. This is useful if your test can be compiled into PHP primitives.
|
340 |
-
This is used by many of the tests built into Twig::
|
341 |
-
|
342 |
-
$twig = new Twig_Environment($loader);
|
343 |
-
$test = new Twig_SimpleTest(
|
344 |
-
'odd',
|
345 |
-
null,
|
346 |
-
array('node_class' => 'Twig_Node_Expression_Test_Odd'));
|
347 |
-
$twig->addTest($test);
|
348 |
-
|
349 |
-
class Twig_Node_Expression_Test_Odd extends Twig_Node_Expression_Test
|
350 |
-
{
|
351 |
-
public function compile(Twig_Compiler $compiler)
|
352 |
-
{
|
353 |
-
$compiler
|
354 |
-
->raw('(')
|
355 |
-
->subcompile($this->getNode('node'))
|
356 |
-
->raw(' % 2 == 1')
|
357 |
-
->raw(')')
|
358 |
-
;
|
359 |
-
}
|
360 |
-
}
|
361 |
-
|
362 |
-
The above example shows how you can create tests that use a node class. The
|
363 |
-
node class has access to one sub-node called 'node'. This sub-node contains the
|
364 |
-
value that is being tested. When the ``odd`` filter is used in code such as:
|
365 |
-
|
366 |
-
.. code-block:: jinja
|
367 |
-
|
368 |
-
{% if my_value is odd %}
|
369 |
-
|
370 |
-
The ``node`` sub-node will contain an expression of ``my_value``. Node-based
|
371 |
-
tests also have access to the ``arguments`` node. This node will contain the
|
372 |
-
various other arguments that have been provided to your test.
|
373 |
-
|
374 |
-
If you want to pass a variable number of positional or named arguments to the
|
375 |
-
test, set the ``is_variadic`` option to ``true``. Tests also support dynamic
|
376 |
-
name feature as filters and functions.
|
377 |
-
|
378 |
-
Tags
|
379 |
-
----
|
380 |
-
|
381 |
-
One of the most exciting features of a template engine like Twig is the
|
382 |
-
possibility to define new language constructs. This is also the most complex
|
383 |
-
feature as you need to understand how Twig's internals work.
|
384 |
-
|
385 |
-
Let's create a simple ``set`` tag that allows the definition of simple
|
386 |
-
variables from within a template. The tag can be used like follows:
|
387 |
-
|
388 |
-
.. code-block:: jinja
|
389 |
-
|
390 |
-
{% set name = "value" %}
|
391 |
-
|
392 |
-
{{ name }}
|
393 |
-
|
394 |
-
{# should output value #}
|
395 |
-
|
396 |
-
.. note::
|
397 |
-
|
398 |
-
The ``set`` tag is part of the Core extension and as such is always
|
399 |
-
available. The built-in version is slightly more powerful and supports
|
400 |
-
multiple assignments by default (cf. the template designers chapter for
|
401 |
-
more information).
|
402 |
-
|
403 |
-
Three steps are needed to define a new tag:
|
404 |
-
|
405 |
-
* Defining a Token Parser class (responsible for parsing the template code);
|
406 |
-
|
407 |
-
* Defining a Node class (responsible for converting the parsed code to PHP);
|
408 |
-
|
409 |
-
* Registering the tag.
|
410 |
-
|
411 |
-
Registering a new tag
|
412 |
-
~~~~~~~~~~~~~~~~~~~~~
|
413 |
-
|
414 |
-
Adding a tag is as simple as calling the ``addTokenParser`` method on the
|
415 |
-
``Twig_Environment`` instance::
|
416 |
-
|
417 |
-
$twig = new Twig_Environment($loader);
|
418 |
-
$twig->addTokenParser(new Project_Set_TokenParser());
|
419 |
-
|
420 |
-
Defining a Token Parser
|
421 |
-
~~~~~~~~~~~~~~~~~~~~~~~
|
422 |
-
|
423 |
-
Now, let's see the actual code of this class::
|
424 |
-
|
425 |
-
class Project_Set_TokenParser extends Twig_TokenParser
|
426 |
-
{
|
427 |
-
public function parse(Twig_Token $token)
|
428 |
-
{
|
429 |
-
$parser = $this->parser;
|
430 |
-
$stream = $parser->getStream();
|
431 |
-
|
432 |
-
$name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
|
433 |
-
$stream->expect(Twig_Token::OPERATOR_TYPE, '=');
|
434 |
-
$value = $parser->getExpressionParser()->parseExpression();
|
435 |
-
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
436 |
-
|
437 |
-
return new Project_Set_Node($name, $value, $token->getLine(), $this->getTag());
|
438 |
-
}
|
439 |
-
|
440 |
-
public function getTag()
|
441 |
-
{
|
442 |
-
return 'set';
|
443 |
-
}
|
444 |
-
}
|
445 |
-
|
446 |
-
The ``getTag()`` method must return the tag we want to parse, here ``set``.
|
447 |
-
|
448 |
-
The ``parse()`` method is invoked whenever the parser encounters a ``set``
|
449 |
-
tag. It should return a ``Twig_Node`` instance that represents the node (the
|
450 |
-
``Project_Set_Node`` calls creating is explained in the next section).
|
451 |
-
|
452 |
-
The parsing process is simplified thanks to a bunch of methods you can call
|
453 |
-
from the token stream (``$this->parser->getStream()``):
|
454 |
-
|
455 |
-
* ``getCurrent()``: Gets the current token in the stream.
|
456 |
-
|
457 |
-
* ``next()``: Moves to the next token in the stream, *but returns the old one*.
|
458 |
-
|
459 |
-
* ``test($type)``, ``test($value)`` or ``test($type, $value)``: Determines whether
|
460 |
-
the current token is of a particular type or value (or both). The value may be an
|
461 |
-
array of several possible values.
|
462 |
-
|
463 |
-
* ``expect($type[, $value[, $message]])``: If the current token isn't of the given
|
464 |
-
type/value a syntax error is thrown. Otherwise, if the type and value are correct,
|
465 |
-
the token is returned and the stream moves to the next token.
|
466 |
-
|
467 |
-
* ``look()``: Looks a the next token without consuming it.
|
468 |
-
|
469 |
-
Parsing expressions is done by calling the ``parseExpression()`` like we did for
|
470 |
-
the ``set`` tag.
|
471 |
-
|
472 |
-
.. tip::
|
473 |
-
|
474 |
-
Reading the existing ``TokenParser`` classes is the best way to learn all
|
475 |
-
the nitty-gritty details of the parsing process.
|
476 |
-
|
477 |
-
Defining a Node
|
478 |
-
~~~~~~~~~~~~~~~
|
479 |
-
|
480 |
-
The ``Project_Set_Node`` class itself is rather simple::
|
481 |
-
|
482 |
-
class Project_Set_Node extends Twig_Node
|
483 |
-
{
|
484 |
-
public function __construct($name, Twig_Node_Expression $value, $line, $tag = null)
|
485 |
-
{
|
486 |
-
parent::__construct(array('value' => $value), array('name' => $name), $line, $tag);
|
487 |
-
}
|
488 |
-
|
489 |
-
public function compile(Twig_Compiler $compiler)
|
490 |
-
{
|
491 |
-
$compiler
|
492 |
-
->addDebugInfo($this)
|
493 |
-
->write('$context[\''.$this->getAttribute('name').'\'] = ')
|
494 |
-
->subcompile($this->getNode('value'))
|
495 |
-
->raw(";\n")
|
496 |
-
;
|
497 |
-
}
|
498 |
-
}
|
499 |
-
|
500 |
-
The compiler implements a fluid interface and provides methods that helps the
|
501 |
-
developer generate beautiful and readable PHP code:
|
502 |
-
|
503 |
-
* ``subcompile()``: Compiles a node.
|
504 |
-
|
505 |
-
* ``raw()``: Writes the given string as is.
|
506 |
-
|
507 |
-
* ``write()``: Writes the given string by adding indentation at the beginning
|
508 |
-
of each line.
|
509 |
-
|
510 |
-
* ``string()``: Writes a quoted string.
|
511 |
-
|
512 |
-
* ``repr()``: Writes a PHP representation of a given value (see
|
513 |
-
``Twig_Node_For`` for a usage example).
|
514 |
-
|
515 |
-
* ``addDebugInfo()``: Adds the line of the original template file related to
|
516 |
-
the current node as a comment.
|
517 |
-
|
518 |
-
* ``indent()``: Indents the generated code (see ``Twig_Node_Block`` for a
|
519 |
-
usage example).
|
520 |
-
|
521 |
-
* ``outdent()``: Outdents the generated code (see ``Twig_Node_Block`` for a
|
522 |
-
usage example).
|
523 |
-
|
524 |
-
.. _creating_extensions:
|
525 |
-
|
526 |
-
Creating an Extension
|
527 |
-
---------------------
|
528 |
-
|
529 |
-
The main motivation for writing an extension is to move often used code into a
|
530 |
-
reusable class like adding support for internationalization. An extension can
|
531 |
-
define tags, filters, tests, operators, global variables, functions, and node
|
532 |
-
visitors.
|
533 |
-
|
534 |
-
Most of the time, it is useful to create a single extension for your project,
|
535 |
-
to host all the specific tags and filters you want to add to Twig.
|
536 |
-
|
537 |
-
.. tip::
|
538 |
-
|
539 |
-
When packaging your code into an extension, Twig is smart enough to
|
540 |
-
recompile your templates whenever you make a change to it (when
|
541 |
-
``auto_reload`` is enabled).
|
542 |
-
|
543 |
-
.. note::
|
544 |
-
|
545 |
-
Before writing your own extensions, have a look at the Twig official
|
546 |
-
extension repository: http://github.com/twigphp/Twig-extensions.
|
547 |
-
|
548 |
-
An extension is a class that implements the following interface::
|
549 |
-
|
550 |
-
interface Twig_ExtensionInterface
|
551 |
-
{
|
552 |
-
/**
|
553 |
-
* Initializes the runtime environment.
|
554 |
-
*
|
555 |
-
* This is where you can load some file that contains filter functions for instance.
|
556 |
-
*
|
557 |
-
* @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_InitRuntimeInterface instead
|
558 |
-
*/
|
559 |
-
function initRuntime(Twig_Environment $environment);
|
560 |
-
|
561 |
-
/**
|
562 |
-
* Returns the token parser instances to add to the existing list.
|
563 |
-
*
|
564 |
-
* @return (Twig_TokenParserInterface|Twig_TokenParserBrokerInterface)[]
|
565 |
-
*/
|
566 |
-
function getTokenParsers();
|
567 |
-
|
568 |
-
/**
|
569 |
-
* Returns the node visitor instances to add to the existing list.
|
570 |
-
*
|
571 |
-
* @return Twig_NodeVisitorInterface[]
|
572 |
-
*/
|
573 |
-
function getNodeVisitors();
|
574 |
-
|
575 |
-
/**
|
576 |
-
* Returns a list of filters to add to the existing list.
|
577 |
-
*
|
578 |
-
* @return Twig_SimpleFilter[]
|
579 |
-
*/
|
580 |
-
function getFilters();
|
581 |
-
|
582 |
-
/**
|
583 |
-
* Returns a list of tests to add to the existing list.
|
584 |
-
*
|
585 |
-
* @return Twig_SimpleTest[]
|
586 |
-
*/
|
587 |
-
function getTests();
|
588 |
-
|
589 |
-
/**
|
590 |
-
* Returns a list of functions to add to the existing list.
|
591 |
-
*
|
592 |
-
* @return Twig_SimpleFunction[]
|
593 |
-
*/
|
594 |
-
function getFunctions();
|
595 |
-
|
596 |
-
/**
|
597 |
-
* Returns a list of operators to add to the existing list.
|
598 |
-
*
|
599 |
-
* @return array An array of operators
|
600 |
-
*/
|
601 |
-
function getOperators();
|
602 |
-
|
603 |
-
/**
|
604 |
-
* Returns a list of global variables to add to the existing list.
|
605 |
-
*
|
606 |
-
* @return array An array of global variables
|
607 |
-
*
|
608 |
-
* @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_GlobalsInterface instead
|
609 |
-
*/
|
610 |
-
function getGlobals();
|
611 |
-
|
612 |
-
/**
|
613 |
-
* Returns the name of the extension.
|
614 |
-
*
|
615 |
-
* @return string The extension name
|
616 |
-
*
|
617 |
-
* @deprecated since 1.26 (to be removed in 2.0), not used anymore internally
|
618 |
-
*/
|
619 |
-
function getName();
|
620 |
-
}
|
621 |
-
|
622 |
-
To keep your extension class clean and lean, inherit from the built-in
|
623 |
-
``Twig_Extension`` class instead of implementing the interface as it provides
|
624 |
-
empty implementations for all methods:
|
625 |
-
|
626 |
-
class Project_Twig_Extension extends Twig_Extension
|
627 |
-
{
|
628 |
-
}
|
629 |
-
|
630 |
-
Of course, this extension does nothing for now. We will customize it in the
|
631 |
-
next sections.
|
632 |
-
|
633 |
-
.. note::
|
634 |
-
|
635 |
-
Prior to Twig 1.26, you must implement the ``getName()`` method which must
|
636 |
-
return a unique identifier for the extension.
|
637 |
-
|
638 |
-
Twig does not care where you save your extension on the filesystem, as all
|
639 |
-
extensions must be registered explicitly to be available in your templates.
|
640 |
-
|
641 |
-
You can register an extension by using the ``addExtension()`` method on your
|
642 |
-
main ``Environment`` object::
|
643 |
-
|
644 |
-
$twig = new Twig_Environment($loader);
|
645 |
-
$twig->addExtension(new Project_Twig_Extension());
|
646 |
-
|
647 |
-
.. tip::
|
648 |
-
|
649 |
-
The Twig core extensions are great examples of how extensions work.
|
650 |
-
|
651 |
-
Globals
|
652 |
-
~~~~~~~
|
653 |
-
|
654 |
-
Global variables can be registered in an extension via the ``getGlobals()``
|
655 |
-
method::
|
656 |
-
|
657 |
-
class Project_Twig_Extension extends Twig_Extension implements Twig_Extension_GlobalsInterface
|
658 |
-
{
|
659 |
-
public function getGlobals()
|
660 |
-
{
|
661 |
-
return array(
|
662 |
-
'text' => new Text(),
|
663 |
-
);
|
664 |
-
}
|
665 |
-
|
666 |
-
// ...
|
667 |
-
}
|
668 |
-
|
669 |
-
Functions
|
670 |
-
~~~~~~~~~
|
671 |
-
|
672 |
-
Functions can be registered in an extension via the ``getFunctions()``
|
673 |
-
method::
|
674 |
-
|
675 |
-
class Project_Twig_Extension extends Twig_Extension
|
676 |
-
{
|
677 |
-
public function getFunctions()
|
678 |
-
{
|
679 |
-
return array(
|
680 |
-
new Twig_SimpleFunction('lipsum', 'generate_lipsum'),
|
681 |
-
);
|
682 |
-
}
|
683 |
-
|
684 |
-
// ...
|
685 |
-
}
|
686 |
-
|
687 |
-
Filters
|
688 |
-
~~~~~~~
|
689 |
-
|
690 |
-
To add a filter to an extension, you need to override the ``getFilters()``
|
691 |
-
method. This method must return an array of filters to add to the Twig
|
692 |
-
environment::
|
693 |
-
|
694 |
-
class Project_Twig_Extension extends Twig_Extension
|
695 |
-
{
|
696 |
-
public function getFilters()
|
697 |
-
{
|
698 |
-
return array(
|
699 |
-
new Twig_SimpleFilter('rot13', 'str_rot13'),
|
700 |
-
);
|
701 |
-
}
|
702 |
-
|
703 |
-
// ...
|
704 |
-
}
|
705 |
-
|
706 |
-
Tags
|
707 |
-
~~~~
|
708 |
-
|
709 |
-
Adding a tag in an extension can be done by overriding the
|
710 |
-
``getTokenParsers()`` method. This method must return an array of tags to add
|
711 |
-
to the Twig environment::
|
712 |
-
|
713 |
-
class Project_Twig_Extension extends Twig_Extension
|
714 |
-
{
|
715 |
-
public function getTokenParsers()
|
716 |
-
{
|
717 |
-
return array(new Project_Set_TokenParser());
|
718 |
-
}
|
719 |
-
|
720 |
-
// ...
|
721 |
-
}
|
722 |
-
|
723 |
-
In the above code, we have added a single new tag, defined by the
|
724 |
-
``Project_Set_TokenParser`` class. The ``Project_Set_TokenParser`` class is
|
725 |
-
responsible for parsing the tag and compiling it to PHP.
|
726 |
-
|
727 |
-
Operators
|
728 |
-
~~~~~~~~~
|
729 |
-
|
730 |
-
The ``getOperators()`` methods lets you add new operators. Here is how to add
|
731 |
-
``!``, ``||``, and ``&&`` operators::
|
732 |
-
|
733 |
-
class Project_Twig_Extension extends Twig_Extension
|
734 |
-
{
|
735 |
-
public function getOperators()
|
736 |
-
{
|
737 |
-
return array(
|
738 |
-
array(
|
739 |
-
'!' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'),
|
740 |
-
),
|
741 |
-
array(
|
742 |
-
'||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
743 |
-
'&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
744 |
-
),
|
745 |
-
);
|
746 |
-
}
|
747 |
-
|
748 |
-
// ...
|
749 |
-
}
|
750 |
-
|
751 |
-
Tests
|
752 |
-
~~~~~
|
753 |
-
|
754 |
-
The ``getTests()`` method lets you add new test functions::
|
755 |
-
|
756 |
-
class Project_Twig_Extension extends Twig_Extension
|
757 |
-
{
|
758 |
-
public function getTests()
|
759 |
-
{
|
760 |
-
return array(
|
761 |
-
new Twig_SimpleTest('even', 'twig_test_even'),
|
762 |
-
);
|
763 |
-
}
|
764 |
-
|
765 |
-
// ...
|
766 |
-
}
|
767 |
-
|
768 |
-
Definition vs Runtime
|
769 |
-
~~~~~~~~~~~~~~~~~~~~~
|
770 |
-
|
771 |
-
Twig filters, functions, and tests runtime implementations can be defined as
|
772 |
-
any valid PHP callable:
|
773 |
-
|
774 |
-
* **functions/static methods**: Simple to implement and fast (used by all Twig
|
775 |
-
core extensions); but it is hard for the runtime to depend on external
|
776 |
-
objects;
|
777 |
-
|
778 |
-
* **closures**: Simple to implement;
|
779 |
-
|
780 |
-
* **object methods**: More flexible and required if your runtime code depends
|
781 |
-
on external objects.
|
782 |
-
|
783 |
-
The simplest way to use methods is to define them on the extension itself::
|
784 |
-
|
785 |
-
class Project_Twig_Extension extends Twig_Extension
|
786 |
-
{
|
787 |
-
private $rot13Provider;
|
788 |
-
|
789 |
-
public function __construct($rot13Provider)
|
790 |
-
{
|
791 |
-
$this->rot13Provider = $rot13Provider;
|
792 |
-
}
|
793 |
-
|
794 |
-
public function getFunctions()
|
795 |
-
{
|
796 |
-
return array(
|
797 |
-
new Twig_SimpleFunction('rot13', array($this, 'rot13')),
|
798 |
-
);
|
799 |
-
}
|
800 |
-
|
801 |
-
public function rot13($value)
|
802 |
-
{
|
803 |
-
return $rot13Provider->rot13($value);
|
804 |
-
}
|
805 |
-
}
|
806 |
-
|
807 |
-
This is very convenient but not recommended as it makes template compilation
|
808 |
-
depend on runtime dependencies even if they are not needed (think for instance
|
809 |
-
as a dependency that connects to a database engine).
|
810 |
-
|
811 |
-
As of Twig 1.26, you can easily decouple the extension definitions from their
|
812 |
-
runtime implementations by registering a ``Twig_RuntimeLoaderInterface``
|
813 |
-
instance on the environment that knows how to instantiate such runtime classes
|
814 |
-
(runtime classes must be autoload-able)::
|
815 |
-
|
816 |
-
class RuntimeLoader implements Twig_RuntimeLoaderInterface
|
817 |
-
{
|
818 |
-
public function load($class)
|
819 |
-
{
|
820 |
-
// implement the logic to create an instance of $class
|
821 |
-
// and inject its dependencies
|
822 |
-
// most of the time, it means using your dependency injection container
|
823 |
-
if ('Project_Twig_RuntimeExtension' === $class) {
|
824 |
-
return new $class(new Rot13Provider());
|
825 |
-
} else {
|
826 |
-
// ...
|
827 |
-
}
|
828 |
-
}
|
829 |
-
}
|
830 |
-
|
831 |
-
$twig->addRuntimeLoader(new RuntimeLoader());
|
832 |
-
|
833 |
-
It is now possible to move the runtime logic to a new
|
834 |
-
``Project_Twig_RuntimeExtension`` class and use it directly in the extension::
|
835 |
-
|
836 |
-
class Project_Twig_RuntimeExtension extends Twig_Extension
|
837 |
-
{
|
838 |
-
private $rot13Provider;
|
839 |
-
|
840 |
-
public function __construct($rot13Provider)
|
841 |
-
{
|
842 |
-
$this->rot13Provider = $rot13Provider;
|
843 |
-
}
|
844 |
-
|
845 |
-
public function rot13($value)
|
846 |
-
{
|
847 |
-
return $rot13Provider->rot13($value);
|
848 |
-
}
|
849 |
-
}
|
850 |
-
|
851 |
-
class Project_Twig_Extension extends Twig_Extension
|
852 |
-
{
|
853 |
-
public function getFunctions()
|
854 |
-
{
|
855 |
-
return array(
|
856 |
-
new Twig_SimpleFunction('rot13', array('Project_Twig_RuntimeExtension', 'rot13')),
|
857 |
-
// or
|
858 |
-
new Twig_SimpleFunction('rot13', 'Project_Twig_RuntimeExtension::rot13'),
|
859 |
-
);
|
860 |
-
}
|
861 |
-
}
|
862 |
-
|
863 |
-
Overloading
|
864 |
-
-----------
|
865 |
-
|
866 |
-
To overload an already defined filter, test, operator, global variable, or
|
867 |
-
function, re-define it in an extension and register it **as late as
|
868 |
-
possible** (order matters)::
|
869 |
-
|
870 |
-
class MyCoreExtension extends Twig_Extension
|
871 |
-
{
|
872 |
-
public function getFilters()
|
873 |
-
{
|
874 |
-
return array(
|
875 |
-
new Twig_SimpleFilter('date', array($this, 'dateFilter')),
|
876 |
-
);
|
877 |
-
}
|
878 |
-
|
879 |
-
public function dateFilter($timestamp, $format = 'F j, Y H:i')
|
880 |
-
{
|
881 |
-
// do something different from the built-in date filter
|
882 |
-
}
|
883 |
-
}
|
884 |
-
|
885 |
-
$twig = new Twig_Environment($loader);
|
886 |
-
$twig->addExtension(new MyCoreExtension());
|
887 |
-
|
888 |
-
Here, we have overloaded the built-in ``date`` filter with a custom one.
|
889 |
-
|
890 |
-
If you do the same on the ``Twig_Environment`` itself, beware that it takes
|
891 |
-
precedence over any other registered extensions::
|
892 |
-
|
893 |
-
$twig = new Twig_Environment($loader);
|
894 |
-
$twig->addFilter(new Twig_SimpleFilter('date', function ($timestamp, $format = 'F j, Y H:i') {
|
895 |
-
// do something different from the built-in date filter
|
896 |
-
}));
|
897 |
-
// the date filter will come from the above registration, not
|
898 |
-
// from the registered extension below
|
899 |
-
$twig->addExtension(new MyCoreExtension());
|
900 |
-
|
901 |
-
.. caution::
|
902 |
-
|
903 |
-
Note that overloading the built-in Twig elements is not recommended as it
|
904 |
-
might be confusing.
|
905 |
-
|
906 |
-
Testing an Extension
|
907 |
-
--------------------
|
908 |
-
|
909 |
-
Functional Tests
|
910 |
-
~~~~~~~~~~~~~~~~
|
911 |
-
|
912 |
-
You can create functional tests for extensions simply by creating the
|
913 |
-
following file structure in your test directory::
|
914 |
-
|
915 |
-
Fixtures/
|
916 |
-
filters/
|
917 |
-
foo.test
|
918 |
-
bar.test
|
919 |
-
functions/
|
920 |
-
foo.test
|
921 |
-
bar.test
|
922 |
-
tags/
|
923 |
-
foo.test
|
924 |
-
bar.test
|
925 |
-
IntegrationTest.php
|
926 |
-
|
927 |
-
The ``IntegrationTest.php`` file should look like this::
|
928 |
-
|
929 |
-
class Project_Tests_IntegrationTest extends Twig_Test_IntegrationTestCase
|
930 |
-
{
|
931 |
-
public function getExtensions()
|
932 |
-
{
|
933 |
-
return array(
|
934 |
-
new Project_Twig_Extension1(),
|
935 |
-
new Project_Twig_Extension2(),
|
936 |
-
);
|
937 |
-
}
|
938 |
-
|
939 |
-
public function getFixturesDir()
|
940 |
-
{
|
941 |
-
return dirname(__FILE__).'/Fixtures/';
|
942 |
-
}
|
943 |
-
}
|
944 |
-
|
945 |
-
Fixtures examples can be found within the Twig repository
|
946 |
-
`tests/Twig/Fixtures`_ directory.
|
947 |
-
|
948 |
-
Node Tests
|
949 |
-
~~~~~~~~~~
|
950 |
-
|
951 |
-
Testing the node visitors can be complex, so extend your test cases from
|
952 |
-
``Twig_Test_NodeTestCase``. Examples can be found in the Twig repository
|
953 |
-
`tests/Twig/Node`_ directory.
|
954 |
-
|
955 |
-
.. _`rot13`: http://www.php.net/manual/en/function.str-rot13.php
|
956 |
-
.. _`tests/Twig/Fixtures`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Fixtures
|
957 |
-
.. _`tests/Twig/Node`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Node
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/advanced_legacy.rst
DELETED
@@ -1,885 +0,0 @@
|
|
1 |
-
Extending Twig
|
2 |
-
==============
|
3 |
-
|
4 |
-
.. caution::
|
5 |
-
|
6 |
-
This section describes how to extends Twig for versions **older than
|
7 |
-
1.12**. If you are using a newer version, read the :doc:`newer<advanced>`
|
8 |
-
chapter instead.
|
9 |
-
|
10 |
-
Twig can be extended in many ways; you can add extra tags, filters, tests,
|
11 |
-
operators, global variables, and functions. You can even extend the parser
|
12 |
-
itself with node visitors.
|
13 |
-
|
14 |
-
.. note::
|
15 |
-
|
16 |
-
The first section of this chapter describes how to extend Twig easily. If
|
17 |
-
you want to reuse your changes in different projects or if you want to
|
18 |
-
share them with others, you should then create an extension as described
|
19 |
-
in the following section.
|
20 |
-
|
21 |
-
.. caution::
|
22 |
-
|
23 |
-
When extending Twig by calling methods on the Twig environment instance,
|
24 |
-
Twig won't be able to recompile your templates when the PHP code is
|
25 |
-
updated. To see your changes in real-time, either disable template caching
|
26 |
-
or package your code into an extension (see the next section of this
|
27 |
-
chapter).
|
28 |
-
|
29 |
-
Before extending Twig, you must understand the differences between all the
|
30 |
-
different possible extension points and when to use them.
|
31 |
-
|
32 |
-
First, remember that Twig has two main language constructs:
|
33 |
-
|
34 |
-
* ``{{ }}``: used to print the result of an expression evaluation;
|
35 |
-
|
36 |
-
* ``{% %}``: used to execute statements.
|
37 |
-
|
38 |
-
To understand why Twig exposes so many extension points, let's see how to
|
39 |
-
implement a *Lorem ipsum* generator (it needs to know the number of words to
|
40 |
-
generate).
|
41 |
-
|
42 |
-
You can use a ``lipsum`` *tag*:
|
43 |
-
|
44 |
-
.. code-block:: jinja
|
45 |
-
|
46 |
-
{% lipsum 40 %}
|
47 |
-
|
48 |
-
That works, but using a tag for ``lipsum`` is not a good idea for at least
|
49 |
-
three main reasons:
|
50 |
-
|
51 |
-
* ``lipsum`` is not a language construct;
|
52 |
-
* The tag outputs something;
|
53 |
-
* The tag is not flexible as you cannot use it in an expression:
|
54 |
-
|
55 |
-
.. code-block:: jinja
|
56 |
-
|
57 |
-
{{ 'some text' ~ {% lipsum 40 %} ~ 'some more text' }}
|
58 |
-
|
59 |
-
In fact, you rarely need to create tags; and that's good news because tags are
|
60 |
-
the most complex extension point of Twig.
|
61 |
-
|
62 |
-
Now, let's use a ``lipsum`` *filter*:
|
63 |
-
|
64 |
-
.. code-block:: jinja
|
65 |
-
|
66 |
-
{{ 40|lipsum }}
|
67 |
-
|
68 |
-
Again, it works, but it looks weird. A filter transforms the passed value to
|
69 |
-
something else but here we use the value to indicate the number of words to
|
70 |
-
generate (so, ``40`` is an argument of the filter, not the value we want to
|
71 |
-
transform).
|
72 |
-
|
73 |
-
Next, let's use a ``lipsum`` *function*:
|
74 |
-
|
75 |
-
.. code-block:: jinja
|
76 |
-
|
77 |
-
{{ lipsum(40) }}
|
78 |
-
|
79 |
-
Here we go. For this specific example, the creation of a function is the
|
80 |
-
extension point to use. And you can use it anywhere an expression is accepted:
|
81 |
-
|
82 |
-
.. code-block:: jinja
|
83 |
-
|
84 |
-
{{ 'some text' ~ ipsum(40) ~ 'some more text' }}
|
85 |
-
|
86 |
-
{% set ipsum = ipsum(40) %}
|
87 |
-
|
88 |
-
Last but not the least, you can also use a *global* object with a method able
|
89 |
-
to generate lorem ipsum text:
|
90 |
-
|
91 |
-
.. code-block:: jinja
|
92 |
-
|
93 |
-
{{ text.lipsum(40) }}
|
94 |
-
|
95 |
-
As a rule of thumb, use functions for frequently used features and global
|
96 |
-
objects for everything else.
|
97 |
-
|
98 |
-
Keep in mind the following when you want to extend Twig:
|
99 |
-
|
100 |
-
========== ========================== ========== =========================
|
101 |
-
What? Implementation difficulty? How often? When?
|
102 |
-
========== ========================== ========== =========================
|
103 |
-
*macro* trivial frequent Content generation
|
104 |
-
*global* trivial frequent Helper object
|
105 |
-
*function* trivial frequent Content generation
|
106 |
-
*filter* trivial frequent Value transformation
|
107 |
-
*tag* complex rare DSL language construct
|
108 |
-
*test* trivial rare Boolean decision
|
109 |
-
*operator* trivial rare Values transformation
|
110 |
-
========== ========================== ========== =========================
|
111 |
-
|
112 |
-
Globals
|
113 |
-
-------
|
114 |
-
|
115 |
-
A global variable is like any other template variable, except that it's
|
116 |
-
available in all templates and macros::
|
117 |
-
|
118 |
-
$twig = new Twig_Environment($loader);
|
119 |
-
$twig->addGlobal('text', new Text());
|
120 |
-
|
121 |
-
You can then use the ``text`` variable anywhere in a template:
|
122 |
-
|
123 |
-
.. code-block:: jinja
|
124 |
-
|
125 |
-
{{ text.lipsum(40) }}
|
126 |
-
|
127 |
-
Filters
|
128 |
-
-------
|
129 |
-
|
130 |
-
A filter is a regular PHP function or an object method that takes the left
|
131 |
-
side of the filter (before the pipe ``|``) as first argument and the extra
|
132 |
-
arguments passed to the filter (within parentheses ``()``) as extra arguments.
|
133 |
-
|
134 |
-
Defining a filter is as easy as associating the filter name with a PHP
|
135 |
-
callable. For instance, let's say you have the following code in a template:
|
136 |
-
|
137 |
-
.. code-block:: jinja
|
138 |
-
|
139 |
-
{{ 'TWIG'|lower }}
|
140 |
-
|
141 |
-
When compiling this template to PHP, Twig looks for the PHP callable
|
142 |
-
associated with the ``lower`` filter. The ``lower`` filter is a built-in Twig
|
143 |
-
filter, and it is simply mapped to the PHP ``strtolower()`` function. After
|
144 |
-
compilation, the generated PHP code is roughly equivalent to:
|
145 |
-
|
146 |
-
.. code-block:: html+php
|
147 |
-
|
148 |
-
<?php echo strtolower('TWIG') ?>
|
149 |
-
|
150 |
-
As you can see, the ``'TWIG'`` string is passed as a first argument to the PHP
|
151 |
-
function.
|
152 |
-
|
153 |
-
A filter can also take extra arguments like in the following example:
|
154 |
-
|
155 |
-
.. code-block:: jinja
|
156 |
-
|
157 |
-
{{ now|date('d/m/Y') }}
|
158 |
-
|
159 |
-
In this case, the extra arguments are passed to the function after the main
|
160 |
-
argument, and the compiled code is equivalent to:
|
161 |
-
|
162 |
-
.. code-block:: html+php
|
163 |
-
|
164 |
-
<?php echo twig_date_format_filter($now, 'd/m/Y') ?>
|
165 |
-
|
166 |
-
Let's see how to create a new filter.
|
167 |
-
|
168 |
-
In this section, we will create a ``rot13`` filter, which should return the
|
169 |
-
`rot13`_ transformation of a string. Here is an example of its usage and the
|
170 |
-
expected output:
|
171 |
-
|
172 |
-
.. code-block:: jinja
|
173 |
-
|
174 |
-
{{ "Twig"|rot13 }}
|
175 |
-
|
176 |
-
{# should displays Gjvt #}
|
177 |
-
|
178 |
-
Adding a filter is as simple as calling the ``addFilter()`` method on the
|
179 |
-
``Twig_Environment`` instance::
|
180 |
-
|
181 |
-
$twig = new Twig_Environment($loader);
|
182 |
-
$twig->addFilter('rot13', new Twig_Filter_Function('str_rot13'));
|
183 |
-
|
184 |
-
The second argument of ``addFilter()`` is an instance of ``Twig_Filter``.
|
185 |
-
Here, we use ``Twig_Filter_Function`` as the filter is a PHP function. The
|
186 |
-
first argument passed to the ``Twig_Filter_Function`` constructor is the name
|
187 |
-
of the PHP function to call, here ``str_rot13``, a native PHP function.
|
188 |
-
|
189 |
-
Let's say I now want to be able to add a prefix before the converted string:
|
190 |
-
|
191 |
-
.. code-block:: jinja
|
192 |
-
|
193 |
-
{{ "Twig"|rot13('prefix_') }}
|
194 |
-
|
195 |
-
{# should displays prefix_Gjvt #}
|
196 |
-
|
197 |
-
As the PHP ``str_rot13()`` function does not support this requirement, let's
|
198 |
-
create a new PHP function::
|
199 |
-
|
200 |
-
function project_compute_rot13($string, $prefix = '')
|
201 |
-
{
|
202 |
-
return $prefix.str_rot13($string);
|
203 |
-
}
|
204 |
-
|
205 |
-
As you can see, the ``prefix`` argument of the filter is passed as an extra
|
206 |
-
argument to the ``project_compute_rot13()`` function.
|
207 |
-
|
208 |
-
Adding this filter is as easy as before::
|
209 |
-
|
210 |
-
$twig->addFilter('rot13', new Twig_Filter_Function('project_compute_rot13'));
|
211 |
-
|
212 |
-
For better encapsulation, a filter can also be defined as a static method of a
|
213 |
-
class. The ``Twig_Filter_Function`` class can also be used to register such
|
214 |
-
static methods as filters::
|
215 |
-
|
216 |
-
$twig->addFilter('rot13', new Twig_Filter_Function('SomeClass::rot13Filter'));
|
217 |
-
|
218 |
-
.. tip::
|
219 |
-
|
220 |
-
In an extension, you can also define a filter as a static method of the
|
221 |
-
extension class.
|
222 |
-
|
223 |
-
Environment aware Filters
|
224 |
-
~~~~~~~~~~~~~~~~~~~~~~~~~
|
225 |
-
|
226 |
-
The ``Twig_Filter`` classes take options as their last argument. For instance,
|
227 |
-
if you want access to the current environment instance in your filter, set the
|
228 |
-
``needs_environment`` option to ``true``::
|
229 |
-
|
230 |
-
$filter = new Twig_Filter_Function('str_rot13', array('needs_environment' => true));
|
231 |
-
|
232 |
-
Twig will then pass the current environment as the first argument to the
|
233 |
-
filter call::
|
234 |
-
|
235 |
-
function twig_compute_rot13(Twig_Environment $env, $string)
|
236 |
-
{
|
237 |
-
// get the current charset for instance
|
238 |
-
$charset = $env->getCharset();
|
239 |
-
|
240 |
-
return str_rot13($string);
|
241 |
-
}
|
242 |
-
|
243 |
-
Automatic Escaping
|
244 |
-
~~~~~~~~~~~~~~~~~~
|
245 |
-
|
246 |
-
If automatic escaping is enabled, the output of the filter may be escaped
|
247 |
-
before printing. If your filter acts as an escaper (or explicitly outputs HTML
|
248 |
-
or JavaScript code), you will want the raw output to be printed. In such a
|
249 |
-
case, set the ``is_safe`` option::
|
250 |
-
|
251 |
-
$filter = new Twig_Filter_Function('nl2br', array('is_safe' => array('html')));
|
252 |
-
|
253 |
-
Some filters may need to work on input that is already escaped or safe, for
|
254 |
-
example when adding (safe) HTML tags to originally unsafe output. In such a
|
255 |
-
case, set the ``pre_escape`` option to escape the input data before it is run
|
256 |
-
through your filter::
|
257 |
-
|
258 |
-
$filter = new Twig_Filter_Function('somefilter', array('pre_escape' => 'html', 'is_safe' => array('html')));
|
259 |
-
|
260 |
-
Dynamic Filters
|
261 |
-
~~~~~~~~~~~~~~~
|
262 |
-
|
263 |
-
.. versionadded:: 1.5
|
264 |
-
Dynamic filters support was added in Twig 1.5.
|
265 |
-
|
266 |
-
A filter name containing the special ``*`` character is a dynamic filter as
|
267 |
-
the ``*`` can be any string::
|
268 |
-
|
269 |
-
$twig->addFilter('*_path_*', new Twig_Filter_Function('twig_path'));
|
270 |
-
|
271 |
-
function twig_path($name, $arguments)
|
272 |
-
{
|
273 |
-
// ...
|
274 |
-
}
|
275 |
-
|
276 |
-
The following filters will be matched by the above defined dynamic filter:
|
277 |
-
|
278 |
-
* ``product_path``
|
279 |
-
* ``category_path``
|
280 |
-
|
281 |
-
A dynamic filter can define more than one dynamic parts::
|
282 |
-
|
283 |
-
$twig->addFilter('*_path_*', new Twig_Filter_Function('twig_path'));
|
284 |
-
|
285 |
-
function twig_path($name, $suffix, $arguments)
|
286 |
-
{
|
287 |
-
// ...
|
288 |
-
}
|
289 |
-
|
290 |
-
The filter will receive all dynamic part values before the normal filters
|
291 |
-
arguments. For instance, a call to ``'foo'|a_path_b()`` will result in the
|
292 |
-
following PHP call: ``twig_path('a', 'b', 'foo')``.
|
293 |
-
|
294 |
-
Functions
|
295 |
-
---------
|
296 |
-
|
297 |
-
A function is a regular PHP function or an object method that can be called from
|
298 |
-
templates.
|
299 |
-
|
300 |
-
.. code-block:: jinja
|
301 |
-
|
302 |
-
{{ constant("DATE_W3C") }}
|
303 |
-
|
304 |
-
When compiling this template to PHP, Twig looks for the PHP callable
|
305 |
-
associated with the ``constant`` function. The ``constant`` function is a built-in Twig
|
306 |
-
function, and it is simply mapped to the PHP ``constant()`` function. After
|
307 |
-
compilation, the generated PHP code is roughly equivalent to:
|
308 |
-
|
309 |
-
.. code-block:: html+php
|
310 |
-
|
311 |
-
<?php echo constant('DATE_W3C') ?>
|
312 |
-
|
313 |
-
Adding a function is similar to adding a filter. This can be done by calling the
|
314 |
-
``addFunction()`` method on the ``Twig_Environment`` instance::
|
315 |
-
|
316 |
-
$twig = new Twig_Environment($loader);
|
317 |
-
$twig->addFunction('functionName', new Twig_Function_Function('someFunction'));
|
318 |
-
|
319 |
-
You can also expose extension methods as functions in your templates::
|
320 |
-
|
321 |
-
// $this is an object that implements Twig_ExtensionInterface.
|
322 |
-
$twig = new Twig_Environment($loader);
|
323 |
-
$twig->addFunction('otherFunction', new Twig_Function_Method($this, 'someMethod'));
|
324 |
-
|
325 |
-
Functions also support ``needs_environment`` and ``is_safe`` parameters.
|
326 |
-
|
327 |
-
Dynamic Functions
|
328 |
-
~~~~~~~~~~~~~~~~~
|
329 |
-
|
330 |
-
.. versionadded:: 1.5
|
331 |
-
Dynamic functions support was added in Twig 1.5.
|
332 |
-
|
333 |
-
A function name containing the special ``*`` character is a dynamic function
|
334 |
-
as the ``*`` can be any string::
|
335 |
-
|
336 |
-
$twig->addFunction('*_path', new Twig_Function_Function('twig_path'));
|
337 |
-
|
338 |
-
function twig_path($name, $arguments)
|
339 |
-
{
|
340 |
-
// ...
|
341 |
-
}
|
342 |
-
|
343 |
-
The following functions will be matched by the above defined dynamic function:
|
344 |
-
|
345 |
-
* ``product_path``
|
346 |
-
* ``category_path``
|
347 |
-
|
348 |
-
A dynamic function can define more than one dynamic parts::
|
349 |
-
|
350 |
-
$twig->addFilter('*_path_*', new Twig_Filter_Function('twig_path'));
|
351 |
-
|
352 |
-
function twig_path($name, $suffix, $arguments)
|
353 |
-
{
|
354 |
-
// ...
|
355 |
-
}
|
356 |
-
|
357 |
-
The function will receive all dynamic part values before the normal functions
|
358 |
-
arguments. For instance, a call to ``a_path_b('foo')`` will result in the
|
359 |
-
following PHP call: ``twig_path('a', 'b', 'foo')``.
|
360 |
-
|
361 |
-
Tags
|
362 |
-
----
|
363 |
-
|
364 |
-
One of the most exciting feature of a template engine like Twig is the
|
365 |
-
possibility to define new language constructs. This is also the most complex
|
366 |
-
feature as you need to understand how Twig's internals work.
|
367 |
-
|
368 |
-
Let's create a simple ``set`` tag that allows the definition of simple
|
369 |
-
variables from within a template. The tag can be used like follows:
|
370 |
-
|
371 |
-
.. code-block:: jinja
|
372 |
-
|
373 |
-
{% set name = "value" %}
|
374 |
-
|
375 |
-
{{ name }}
|
376 |
-
|
377 |
-
{# should output value #}
|
378 |
-
|
379 |
-
.. note::
|
380 |
-
|
381 |
-
The ``set`` tag is part of the Core extension and as such is always
|
382 |
-
available. The built-in version is slightly more powerful and supports
|
383 |
-
multiple assignments by default (cf. the template designers chapter for
|
384 |
-
more information).
|
385 |
-
|
386 |
-
Three steps are needed to define a new tag:
|
387 |
-
|
388 |
-
* Defining a Token Parser class (responsible for parsing the template code);
|
389 |
-
|
390 |
-
* Defining a Node class (responsible for converting the parsed code to PHP);
|
391 |
-
|
392 |
-
* Registering the tag.
|
393 |
-
|
394 |
-
Registering a new tag
|
395 |
-
~~~~~~~~~~~~~~~~~~~~~
|
396 |
-
|
397 |
-
Adding a tag is as simple as calling the ``addTokenParser`` method on the
|
398 |
-
``Twig_Environment`` instance::
|
399 |
-
|
400 |
-
$twig = new Twig_Environment($loader);
|
401 |
-
$twig->addTokenParser(new Project_Set_TokenParser());
|
402 |
-
|
403 |
-
Defining a Token Parser
|
404 |
-
~~~~~~~~~~~~~~~~~~~~~~~
|
405 |
-
|
406 |
-
Now, let's see the actual code of this class::
|
407 |
-
|
408 |
-
class Project_Set_TokenParser extends Twig_TokenParser
|
409 |
-
{
|
410 |
-
public function parse(Twig_Token $token)
|
411 |
-
{
|
412 |
-
$lineno = $token->getLine();
|
413 |
-
$name = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue();
|
414 |
-
$this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, '=');
|
415 |
-
$value = $this->parser->getExpressionParser()->parseExpression();
|
416 |
-
|
417 |
-
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
418 |
-
|
419 |
-
return new Project_Set_Node($name, $value, $lineno, $this->getTag());
|
420 |
-
}
|
421 |
-
|
422 |
-
public function getTag()
|
423 |
-
{
|
424 |
-
return 'set';
|
425 |
-
}
|
426 |
-
}
|
427 |
-
|
428 |
-
The ``getTag()`` method must return the tag we want to parse, here ``set``.
|
429 |
-
|
430 |
-
The ``parse()`` method is invoked whenever the parser encounters a ``set``
|
431 |
-
tag. It should return a ``Twig_Node`` instance that represents the node (the
|
432 |
-
``Project_Set_Node`` calls creating is explained in the next section).
|
433 |
-
|
434 |
-
The parsing process is simplified thanks to a bunch of methods you can call
|
435 |
-
from the token stream (``$this->parser->getStream()``):
|
436 |
-
|
437 |
-
* ``getCurrent()``: Gets the current token in the stream.
|
438 |
-
|
439 |
-
* ``next()``: Moves to the next token in the stream, *but returns the old one*.
|
440 |
-
|
441 |
-
* ``test($type)``, ``test($value)`` or ``test($type, $value)``: Determines whether
|
442 |
-
the current token is of a particular type or value (or both). The value may be an
|
443 |
-
array of several possible values.
|
444 |
-
|
445 |
-
* ``expect($type[, $value[, $message]])``: If the current token isn't of the given
|
446 |
-
type/value a syntax error is thrown. Otherwise, if the type and value are correct,
|
447 |
-
the token is returned and the stream moves to the next token.
|
448 |
-
|
449 |
-
* ``look()``: Looks a the next token without consuming it.
|
450 |
-
|
451 |
-
Parsing expressions is done by calling the ``parseExpression()`` like we did for
|
452 |
-
the ``set`` tag.
|
453 |
-
|
454 |
-
.. tip::
|
455 |
-
|
456 |
-
Reading the existing ``TokenParser`` classes is the best way to learn all
|
457 |
-
the nitty-gritty details of the parsing process.
|
458 |
-
|
459 |
-
Defining a Node
|
460 |
-
~~~~~~~~~~~~~~~
|
461 |
-
|
462 |
-
The ``Project_Set_Node`` class itself is rather simple::
|
463 |
-
|
464 |
-
class Project_Set_Node extends Twig_Node
|
465 |
-
{
|
466 |
-
public function __construct($name, Twig_Node_Expression $value, $lineno, $tag = null)
|
467 |
-
{
|
468 |
-
parent::__construct(array('value' => $value), array('name' => $name), $lineno, $tag);
|
469 |
-
}
|
470 |
-
|
471 |
-
public function compile(Twig_Compiler $compiler)
|
472 |
-
{
|
473 |
-
$compiler
|
474 |
-
->addDebugInfo($this)
|
475 |
-
->write('$context[\''.$this->getAttribute('name').'\'] = ')
|
476 |
-
->subcompile($this->getNode('value'))
|
477 |
-
->raw(";\n")
|
478 |
-
;
|
479 |
-
}
|
480 |
-
}
|
481 |
-
|
482 |
-
The compiler implements a fluid interface and provides methods that helps the
|
483 |
-
developer generate beautiful and readable PHP code:
|
484 |
-
|
485 |
-
* ``subcompile()``: Compiles a node.
|
486 |
-
|
487 |
-
* ``raw()``: Writes the given string as is.
|
488 |
-
|
489 |
-
* ``write()``: Writes the given string by adding indentation at the beginning
|
490 |
-
of each line.
|
491 |
-
|
492 |
-
* ``string()``: Writes a quoted string.
|
493 |
-
|
494 |
-
* ``repr()``: Writes a PHP representation of a given value (see
|
495 |
-
``Twig_Node_For`` for a usage example).
|
496 |
-
|
497 |
-
* ``addDebugInfo()``: Adds the line of the original template file related to
|
498 |
-
the current node as a comment.
|
499 |
-
|
500 |
-
* ``indent()``: Indents the generated code (see ``Twig_Node_Block`` for a
|
501 |
-
usage example).
|
502 |
-
|
503 |
-
* ``outdent()``: Outdents the generated code (see ``Twig_Node_Block`` for a
|
504 |
-
usage example).
|
505 |
-
|
506 |
-
.. _creating_extensions:
|
507 |
-
|
508 |
-
Creating an Extension
|
509 |
-
---------------------
|
510 |
-
|
511 |
-
The main motivation for writing an extension is to move often used code into a
|
512 |
-
reusable class like adding support for internationalization. An extension can
|
513 |
-
define tags, filters, tests, operators, global variables, functions, and node
|
514 |
-
visitors.
|
515 |
-
|
516 |
-
Creating an extension also makes for a better separation of code that is
|
517 |
-
executed at compilation time and code needed at runtime. As such, it makes
|
518 |
-
your code faster.
|
519 |
-
|
520 |
-
Most of the time, it is useful to create a single extension for your project,
|
521 |
-
to host all the specific tags and filters you want to add to Twig.
|
522 |
-
|
523 |
-
.. tip::
|
524 |
-
|
525 |
-
When packaging your code into an extension, Twig is smart enough to
|
526 |
-
recompile your templates whenever you make a change to it (when the
|
527 |
-
``auto_reload`` is enabled).
|
528 |
-
|
529 |
-
.. note::
|
530 |
-
|
531 |
-
Before writing your own extensions, have a look at the Twig official
|
532 |
-
extension repository: http://github.com/twigphp/Twig-extensions.
|
533 |
-
|
534 |
-
An extension is a class that implements the following interface::
|
535 |
-
|
536 |
-
interface Twig_ExtensionInterface
|
537 |
-
{
|
538 |
-
/**
|
539 |
-
* Initializes the runtime environment.
|
540 |
-
*
|
541 |
-
* This is where you can load some file that contains filter functions for instance.
|
542 |
-
*/
|
543 |
-
function initRuntime(Twig_Environment $environment);
|
544 |
-
|
545 |
-
/**
|
546 |
-
* Returns the token parser instances to add to the existing list.
|
547 |
-
*
|
548 |
-
* @return (Twig_TokenParserInterface|Twig_TokenParserBrokerInterface)[]
|
549 |
-
*/
|
550 |
-
function getTokenParsers();
|
551 |
-
|
552 |
-
/**
|
553 |
-
* Returns the node visitor instances to add to the existing list.
|
554 |
-
*
|
555 |
-
* @return Twig_NodeVisitorInterface[]
|
556 |
-
*/
|
557 |
-
function getNodeVisitors();
|
558 |
-
|
559 |
-
/**
|
560 |
-
* Returns a list of filters to add to the existing list.
|
561 |
-
*
|
562 |
-
* @return Twig_SimpleFilter[]
|
563 |
-
*/
|
564 |
-
function getFilters();
|
565 |
-
|
566 |
-
/**
|
567 |
-
* Returns a list of tests to add to the existing list.
|
568 |
-
*
|
569 |
-
* @return Twig_SimpleTest[]
|
570 |
-
*/
|
571 |
-
function getTests();
|
572 |
-
|
573 |
-
/**
|
574 |
-
* Returns a list of functions to add to the existing list.
|
575 |
-
*
|
576 |
-
* @return Twig_SimpleFunction[]
|
577 |
-
*/
|
578 |
-
function getFunctions();
|
579 |
-
|
580 |
-
/**
|
581 |
-
* Returns a list of operators to add to the existing list.
|
582 |
-
*
|
583 |
-
* @return array An array of operators
|
584 |
-
*/
|
585 |
-
function getOperators();
|
586 |
-
|
587 |
-
/**
|
588 |
-
* Returns a list of global variables to add to the existing list.
|
589 |
-
*
|
590 |
-
* @return array An array of global variables
|
591 |
-
*/
|
592 |
-
function getGlobals();
|
593 |
-
|
594 |
-
/**
|
595 |
-
* Returns the name of the extension.
|
596 |
-
*
|
597 |
-
* @return string The extension name
|
598 |
-
*/
|
599 |
-
function getName();
|
600 |
-
}
|
601 |
-
|
602 |
-
To keep your extension class clean and lean, it can inherit from the built-in
|
603 |
-
``Twig_Extension`` class instead of implementing the whole interface. That
|
604 |
-
way, you just need to implement the ``getName()`` method as the
|
605 |
-
``Twig_Extension`` provides empty implementations for all other methods.
|
606 |
-
|
607 |
-
The ``getName()`` method must return a unique identifier for your extension.
|
608 |
-
|
609 |
-
Now, with this information in mind, let's create the most basic extension
|
610 |
-
possible::
|
611 |
-
|
612 |
-
class Project_Twig_Extension extends Twig_Extension
|
613 |
-
{
|
614 |
-
public function getName()
|
615 |
-
{
|
616 |
-
return 'project';
|
617 |
-
}
|
618 |
-
}
|
619 |
-
|
620 |
-
.. note::
|
621 |
-
|
622 |
-
Of course, this extension does nothing for now. We will customize it in
|
623 |
-
the next sections.
|
624 |
-
|
625 |
-
Twig does not care where you save your extension on the filesystem, as all
|
626 |
-
extensions must be registered explicitly to be available in your templates.
|
627 |
-
|
628 |
-
You can register an extension by using the ``addExtension()`` method on your
|
629 |
-
main ``Environment`` object::
|
630 |
-
|
631 |
-
$twig = new Twig_Environment($loader);
|
632 |
-
$twig->addExtension(new Project_Twig_Extension());
|
633 |
-
|
634 |
-
Of course, you need to first load the extension file by either using
|
635 |
-
``require_once()`` or by using an autoloader (see `spl_autoload_register()`_).
|
636 |
-
|
637 |
-
.. tip::
|
638 |
-
|
639 |
-
The bundled extensions are great examples of how extensions work.
|
640 |
-
|
641 |
-
Globals
|
642 |
-
~~~~~~~
|
643 |
-
|
644 |
-
Global variables can be registered in an extension via the ``getGlobals()``
|
645 |
-
method::
|
646 |
-
|
647 |
-
class Project_Twig_Extension extends Twig_Extension
|
648 |
-
{
|
649 |
-
public function getGlobals()
|
650 |
-
{
|
651 |
-
return array(
|
652 |
-
'text' => new Text(),
|
653 |
-
);
|
654 |
-
}
|
655 |
-
|
656 |
-
// ...
|
657 |
-
}
|
658 |
-
|
659 |
-
Functions
|
660 |
-
~~~~~~~~~
|
661 |
-
|
662 |
-
Functions can be registered in an extension via the ``getFunctions()``
|
663 |
-
method::
|
664 |
-
|
665 |
-
class Project_Twig_Extension extends Twig_Extension
|
666 |
-
{
|
667 |
-
public function getFunctions()
|
668 |
-
{
|
669 |
-
return array(
|
670 |
-
'lipsum' => new Twig_Function_Function('generate_lipsum'),
|
671 |
-
);
|
672 |
-
}
|
673 |
-
|
674 |
-
// ...
|
675 |
-
}
|
676 |
-
|
677 |
-
Filters
|
678 |
-
~~~~~~~
|
679 |
-
|
680 |
-
To add a filter to an extension, you need to override the ``getFilters()``
|
681 |
-
method. This method must return an array of filters to add to the Twig
|
682 |
-
environment::
|
683 |
-
|
684 |
-
class Project_Twig_Extension extends Twig_Extension
|
685 |
-
{
|
686 |
-
public function getFilters()
|
687 |
-
{
|
688 |
-
return array(
|
689 |
-
'rot13' => new Twig_Filter_Function('str_rot13'),
|
690 |
-
);
|
691 |
-
}
|
692 |
-
|
693 |
-
// ...
|
694 |
-
}
|
695 |
-
|
696 |
-
As you can see in the above code, the ``getFilters()`` method returns an array
|
697 |
-
where keys are the name of the filters (``rot13``) and the values the
|
698 |
-
definition of the filter (``new Twig_Filter_Function('str_rot13')``).
|
699 |
-
|
700 |
-
As seen in the previous chapter, you can also define filters as static methods
|
701 |
-
on the extension class::
|
702 |
-
|
703 |
-
$twig->addFilter('rot13', new Twig_Filter_Function('Project_Twig_Extension::rot13Filter'));
|
704 |
-
|
705 |
-
You can also use ``Twig_Filter_Method`` instead of ``Twig_Filter_Function``
|
706 |
-
when defining a filter to use a method::
|
707 |
-
|
708 |
-
class Project_Twig_Extension extends Twig_Extension
|
709 |
-
{
|
710 |
-
public function getFilters()
|
711 |
-
{
|
712 |
-
return array(
|
713 |
-
'rot13' => new Twig_Filter_Method($this, 'rot13Filter'),
|
714 |
-
);
|
715 |
-
}
|
716 |
-
|
717 |
-
public function rot13Filter($string)
|
718 |
-
{
|
719 |
-
return str_rot13($string);
|
720 |
-
}
|
721 |
-
|
722 |
-
// ...
|
723 |
-
}
|
724 |
-
|
725 |
-
The first argument of the ``Twig_Filter_Method`` constructor is always
|
726 |
-
``$this``, the current extension object. The second one is the name of the
|
727 |
-
method to call.
|
728 |
-
|
729 |
-
Using methods for filters is a great way to package your filter without
|
730 |
-
polluting the global namespace. This also gives the developer more flexibility
|
731 |
-
at the cost of a small overhead.
|
732 |
-
|
733 |
-
Overriding default Filters
|
734 |
-
..........................
|
735 |
-
|
736 |
-
If some default core filters do not suit your needs, you can easily override
|
737 |
-
them by creating your own extension. Just use the same names as the one you
|
738 |
-
want to override::
|
739 |
-
|
740 |
-
class MyCoreExtension extends Twig_Extension
|
741 |
-
{
|
742 |
-
public function getFilters()
|
743 |
-
{
|
744 |
-
return array(
|
745 |
-
'date' => new Twig_Filter_Method($this, 'dateFilter'),
|
746 |
-
// ...
|
747 |
-
);
|
748 |
-
}
|
749 |
-
|
750 |
-
public function dateFilter($timestamp, $format = 'F j, Y H:i')
|
751 |
-
{
|
752 |
-
return '...'.twig_date_format_filter($timestamp, $format);
|
753 |
-
}
|
754 |
-
|
755 |
-
public function getName()
|
756 |
-
{
|
757 |
-
return 'project';
|
758 |
-
}
|
759 |
-
}
|
760 |
-
|
761 |
-
Here, we override the ``date`` filter with a custom one. Using this extension
|
762 |
-
is as simple as registering the ``MyCoreExtension`` extension by calling the
|
763 |
-
``addExtension()`` method on the environment instance::
|
764 |
-
|
765 |
-
$twig = new Twig_Environment($loader);
|
766 |
-
$twig->addExtension(new MyCoreExtension());
|
767 |
-
|
768 |
-
Tags
|
769 |
-
~~~~
|
770 |
-
|
771 |
-
Adding a tag in an extension can be done by overriding the
|
772 |
-
``getTokenParsers()`` method. This method must return an array of tags to add
|
773 |
-
to the Twig environment::
|
774 |
-
|
775 |
-
class Project_Twig_Extension extends Twig_Extension
|
776 |
-
{
|
777 |
-
public function getTokenParsers()
|
778 |
-
{
|
779 |
-
return array(new Project_Set_TokenParser());
|
780 |
-
}
|
781 |
-
|
782 |
-
// ...
|
783 |
-
}
|
784 |
-
|
785 |
-
In the above code, we have added a single new tag, defined by the
|
786 |
-
``Project_Set_TokenParser`` class. The ``Project_Set_TokenParser`` class is
|
787 |
-
responsible for parsing the tag and compiling it to PHP.
|
788 |
-
|
789 |
-
Operators
|
790 |
-
~~~~~~~~~
|
791 |
-
|
792 |
-
The ``getOperators()`` methods allows to add new operators. Here is how to add
|
793 |
-
``!``, ``||``, and ``&&`` operators::
|
794 |
-
|
795 |
-
class Project_Twig_Extension extends Twig_Extension
|
796 |
-
{
|
797 |
-
public function getOperators()
|
798 |
-
{
|
799 |
-
return array(
|
800 |
-
array(
|
801 |
-
'!' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'),
|
802 |
-
),
|
803 |
-
array(
|
804 |
-
'||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
805 |
-
'&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
806 |
-
),
|
807 |
-
);
|
808 |
-
}
|
809 |
-
|
810 |
-
// ...
|
811 |
-
}
|
812 |
-
|
813 |
-
Tests
|
814 |
-
~~~~~
|
815 |
-
|
816 |
-
The ``getTests()`` methods allows to add new test functions::
|
817 |
-
|
818 |
-
class Project_Twig_Extension extends Twig_Extension
|
819 |
-
{
|
820 |
-
public function getTests()
|
821 |
-
{
|
822 |
-
return array(
|
823 |
-
'even' => new Twig_Test_Function('twig_test_even'),
|
824 |
-
);
|
825 |
-
}
|
826 |
-
|
827 |
-
// ...
|
828 |
-
}
|
829 |
-
|
830 |
-
Testing an Extension
|
831 |
-
--------------------
|
832 |
-
|
833 |
-
.. versionadded:: 1.10
|
834 |
-
Support for functional tests was added in Twig 1.10.
|
835 |
-
|
836 |
-
Functional Tests
|
837 |
-
~~~~~~~~~~~~~~~~
|
838 |
-
|
839 |
-
You can create functional tests for extensions simply by creating the
|
840 |
-
following file structure in your test directory::
|
841 |
-
|
842 |
-
Fixtures/
|
843 |
-
filters/
|
844 |
-
foo.test
|
845 |
-
bar.test
|
846 |
-
functions/
|
847 |
-
foo.test
|
848 |
-
bar.test
|
849 |
-
tags/
|
850 |
-
foo.test
|
851 |
-
bar.test
|
852 |
-
IntegrationTest.php
|
853 |
-
|
854 |
-
The ``IntegrationTest.php`` file should look like this::
|
855 |
-
|
856 |
-
class Project_Tests_IntegrationTest extends Twig_Test_IntegrationTestCase
|
857 |
-
{
|
858 |
-
public function getExtensions()
|
859 |
-
{
|
860 |
-
return array(
|
861 |
-
new Project_Twig_Extension1(),
|
862 |
-
new Project_Twig_Extension2(),
|
863 |
-
);
|
864 |
-
}
|
865 |
-
|
866 |
-
public function getFixturesDir()
|
867 |
-
{
|
868 |
-
return dirname(__FILE__).'/Fixtures/';
|
869 |
-
}
|
870 |
-
}
|
871 |
-
|
872 |
-
Fixtures examples can be found within the Twig repository
|
873 |
-
`tests/Twig/Fixtures`_ directory.
|
874 |
-
|
875 |
-
Node Tests
|
876 |
-
~~~~~~~~~~
|
877 |
-
|
878 |
-
Testing the node visitors can be complex, so extend your test cases from
|
879 |
-
``Twig_Test_NodeTestCase``. Examples can be found in the Twig repository
|
880 |
-
`tests/Twig/Node`_ directory.
|
881 |
-
|
882 |
-
.. _`spl_autoload_register()`: http://www.php.net/spl_autoload_register
|
883 |
-
.. _`rot13`: http://www.php.net/manual/en/function.str-rot13.php
|
884 |
-
.. _`tests/Twig/Fixtures`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Fixtures
|
885 |
-
.. _`tests/Twig/Node`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Node
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/api.rst
DELETED
@@ -1,590 +0,0 @@
|
|
1 |
-
Twig for Developers
|
2 |
-
===================
|
3 |
-
|
4 |
-
This chapter describes the API to Twig and not the template language. It will
|
5 |
-
be most useful as reference to those implementing the template interface to
|
6 |
-
the application and not those who are creating Twig templates.
|
7 |
-
|
8 |
-
Basics
|
9 |
-
------
|
10 |
-
|
11 |
-
Twig uses a central object called the **environment** (of class
|
12 |
-
``Twig_Environment``). Instances of this class are used to store the
|
13 |
-
configuration and extensions, and are used to load templates from the file
|
14 |
-
system or other locations.
|
15 |
-
|
16 |
-
Most applications will create one ``Twig_Environment`` object on application
|
17 |
-
initialization and use that to load templates. In some cases it's however
|
18 |
-
useful to have multiple environments side by side, if different configurations
|
19 |
-
are in use.
|
20 |
-
|
21 |
-
The simplest way to configure Twig to load templates for your application
|
22 |
-
looks roughly like this::
|
23 |
-
|
24 |
-
require_once '/path/to/lib/Twig/Autoloader.php';
|
25 |
-
Twig_Autoloader::register();
|
26 |
-
|
27 |
-
$loader = new Twig_Loader_Filesystem('/path/to/templates');
|
28 |
-
$twig = new Twig_Environment($loader, array(
|
29 |
-
'cache' => '/path/to/compilation_cache',
|
30 |
-
));
|
31 |
-
|
32 |
-
This will create a template environment with the default settings and a loader
|
33 |
-
that looks up the templates in the ``/path/to/templates/`` folder. Different
|
34 |
-
loaders are available and you can also write your own if you want to load
|
35 |
-
templates from a database or other resources.
|
36 |
-
|
37 |
-
.. note::
|
38 |
-
|
39 |
-
Notice that the second argument of the environment is an array of options.
|
40 |
-
The ``cache`` option is a compilation cache directory, where Twig caches
|
41 |
-
the compiled templates to avoid the parsing phase for sub-sequent
|
42 |
-
requests. It is very different from the cache you might want to add for
|
43 |
-
the evaluated templates. For such a need, you can use any available PHP
|
44 |
-
cache library.
|
45 |
-
|
46 |
-
Rendering Templates
|
47 |
-
-------------------
|
48 |
-
|
49 |
-
To load a template from a Twig environment, call the ``load()`` method which
|
50 |
-
returns a ``Twig_TemplateWrapper`` instance::
|
51 |
-
|
52 |
-
$template = $twig->load('index.html');
|
53 |
-
|
54 |
-
.. note::
|
55 |
-
|
56 |
-
Before Twig 1.28, you should use ``loadTemplate()`` instead which returns a
|
57 |
-
``Twig_Template`` instance.
|
58 |
-
|
59 |
-
To render the template with some variables, call the ``render()`` method::
|
60 |
-
|
61 |
-
echo $template->render(array('the' => 'variables', 'go' => 'here'));
|
62 |
-
|
63 |
-
.. note::
|
64 |
-
|
65 |
-
The ``display()`` method is a shortcut to output the template directly.
|
66 |
-
|
67 |
-
You can also load and render the template in one fell swoop::
|
68 |
-
|
69 |
-
echo $twig->render('index.html', array('the' => 'variables', 'go' => 'here'));
|
70 |
-
|
71 |
-
.. versionadded:: 1.28
|
72 |
-
The possibility to render blocks from the API was added in Twig 1.28.
|
73 |
-
|
74 |
-
If a template defines blocks, they can be rendered individually via the
|
75 |
-
``renderBlock()`` call::
|
76 |
-
|
77 |
-
echo $template->renderBlock('block_name', array('the' => 'variables', 'go' => 'here'));
|
78 |
-
|
79 |
-
.. _environment_options:
|
80 |
-
|
81 |
-
Environment Options
|
82 |
-
-------------------
|
83 |
-
|
84 |
-
When creating a new ``Twig_Environment`` instance, you can pass an array of
|
85 |
-
options as the constructor second argument::
|
86 |
-
|
87 |
-
$twig = new Twig_Environment($loader, array('debug' => true));
|
88 |
-
|
89 |
-
The following options are available:
|
90 |
-
|
91 |
-
* ``debug`` *boolean*
|
92 |
-
|
93 |
-
When set to ``true``, the generated templates have a
|
94 |
-
``__toString()`` method that you can use to display the generated nodes
|
95 |
-
(default to ``false``).
|
96 |
-
|
97 |
-
* ``charset`` *string* (defaults to ``utf-8``)
|
98 |
-
|
99 |
-
The charset used by the templates.
|
100 |
-
|
101 |
-
* ``base_template_class`` *string* (defaults to ``Twig_Template``)
|
102 |
-
|
103 |
-
The base template class to use for generated
|
104 |
-
templates.
|
105 |
-
|
106 |
-
* ``cache`` *string* or ``false``
|
107 |
-
|
108 |
-
An absolute path where to store the compiled templates, or
|
109 |
-
``false`` to disable caching (which is the default).
|
110 |
-
|
111 |
-
* ``auto_reload`` *boolean*
|
112 |
-
|
113 |
-
When developing with Twig, it's useful to recompile the
|
114 |
-
template whenever the source code changes. If you don't provide a value for
|
115 |
-
the ``auto_reload`` option, it will be determined automatically based on the
|
116 |
-
``debug`` value.
|
117 |
-
|
118 |
-
* ``strict_variables`` *boolean*
|
119 |
-
|
120 |
-
If set to ``false``, Twig will silently ignore invalid
|
121 |
-
variables (variables and or attributes/methods that do not exist) and
|
122 |
-
replace them with a ``null`` value. When set to ``true``, Twig throws an
|
123 |
-
exception instead (default to ``false``).
|
124 |
-
|
125 |
-
* ``autoescape`` *string* or *boolean*
|
126 |
-
|
127 |
-
If set to ``true``, HTML auto-escaping will be enabled by
|
128 |
-
default for all templates (default to ``true``).
|
129 |
-
|
130 |
-
As of Twig 1.8, you can set the escaping strategy to use (``html``, ``js``,
|
131 |
-
``false`` to disable).
|
132 |
-
|
133 |
-
As of Twig 1.9, you can set the escaping strategy to use (``css``, ``url``,
|
134 |
-
``html_attr``, or a PHP callback that takes the template name and must
|
135 |
-
return the escaping strategy to use -- the callback cannot be a function name
|
136 |
-
to avoid collision with built-in escaping strategies).
|
137 |
-
|
138 |
-
As of Twig 1.17, the ``filename`` escaping strategy (renamed to ``name`` as
|
139 |
-
of Twig 1.27) determines the escaping strategy to use for a template based on
|
140 |
-
the template filename extension (this strategy does not incur any overhead at
|
141 |
-
runtime as auto-escaping is done at compilation time.)
|
142 |
-
|
143 |
-
* ``optimizations`` *integer*
|
144 |
-
|
145 |
-
A flag that indicates which optimizations to apply
|
146 |
-
(default to ``-1`` -- all optimizations are enabled; set it to ``0`` to
|
147 |
-
disable).
|
148 |
-
|
149 |
-
Loaders
|
150 |
-
-------
|
151 |
-
|
152 |
-
Loaders are responsible for loading templates from a resource such as the file
|
153 |
-
system.
|
154 |
-
|
155 |
-
Compilation Cache
|
156 |
-
~~~~~~~~~~~~~~~~~
|
157 |
-
|
158 |
-
All template loaders can cache the compiled templates on the filesystem for
|
159 |
-
future reuse. It speeds up Twig a lot as templates are only compiled once; and
|
160 |
-
the performance boost is even larger if you use a PHP accelerator such as APC.
|
161 |
-
See the ``cache`` and ``auto_reload`` options of ``Twig_Environment`` above
|
162 |
-
for more information.
|
163 |
-
|
164 |
-
Built-in Loaders
|
165 |
-
~~~~~~~~~~~~~~~~
|
166 |
-
|
167 |
-
Here is a list of the built-in loaders Twig provides:
|
168 |
-
|
169 |
-
``Twig_Loader_Filesystem``
|
170 |
-
..........................
|
171 |
-
|
172 |
-
.. versionadded:: 1.10
|
173 |
-
The ``prependPath()`` and support for namespaces were added in Twig 1.10.
|
174 |
-
|
175 |
-
.. versionadded:: 1.27
|
176 |
-
Relative paths support was added in Twig 1.27.
|
177 |
-
|
178 |
-
``Twig_Loader_Filesystem`` loads templates from the file system. This loader
|
179 |
-
can find templates in folders on the file system and is the preferred way to
|
180 |
-
load them::
|
181 |
-
|
182 |
-
$loader = new Twig_Loader_Filesystem($templateDir);
|
183 |
-
|
184 |
-
It can also look for templates in an array of directories::
|
185 |
-
|
186 |
-
$loader = new Twig_Loader_Filesystem(array($templateDir1, $templateDir2));
|
187 |
-
|
188 |
-
With such a configuration, Twig will first look for templates in
|
189 |
-
``$templateDir1`` and if they do not exist, it will fallback to look for them
|
190 |
-
in the ``$templateDir2``.
|
191 |
-
|
192 |
-
You can add or prepend paths via the ``addPath()`` and ``prependPath()``
|
193 |
-
methods::
|
194 |
-
|
195 |
-
$loader->addPath($templateDir3);
|
196 |
-
$loader->prependPath($templateDir4);
|
197 |
-
|
198 |
-
The filesystem loader also supports namespaced templates. This allows to group
|
199 |
-
your templates under different namespaces which have their own template paths.
|
200 |
-
|
201 |
-
When using the ``setPaths()``, ``addPath()``, and ``prependPath()`` methods,
|
202 |
-
specify the namespace as the second argument (when not specified, these
|
203 |
-
methods act on the "main" namespace)::
|
204 |
-
|
205 |
-
$loader->addPath($templateDir, 'admin');
|
206 |
-
|
207 |
-
Namespaced templates can be accessed via the special
|
208 |
-
``@namespace_name/template_path`` notation::
|
209 |
-
|
210 |
-
$twig->render('@admin/index.html', array());
|
211 |
-
|
212 |
-
``Twig_Loader_Filesystem`` support absolute and relative paths. Using relative
|
213 |
-
paths is preferred as it makes the cache keys independent of the project root
|
214 |
-
directory (for instance, it allows warming the cache from a build server where
|
215 |
-
the directory might be different from the one used on production servers)::
|
216 |
-
|
217 |
-
$loader = new Twig_Loader_Filesystem('templates', getcwd().'/..');
|
218 |
-
|
219 |
-
.. note::
|
220 |
-
|
221 |
-
When not passing the root path as a second argument, Twig uses ``getcwd()``
|
222 |
-
for relative paths.
|
223 |
-
|
224 |
-
``Twig_Loader_Array``
|
225 |
-
.....................
|
226 |
-
|
227 |
-
``Twig_Loader_Array`` loads a template from a PHP array. It's passed an array
|
228 |
-
of strings bound to template names::
|
229 |
-
|
230 |
-
$loader = new Twig_Loader_Array(array(
|
231 |
-
'index.html' => 'Hello {{ name }}!',
|
232 |
-
));
|
233 |
-
$twig = new Twig_Environment($loader);
|
234 |
-
|
235 |
-
echo $twig->render('index.html', array('name' => 'Fabien'));
|
236 |
-
|
237 |
-
This loader is very useful for unit testing. It can also be used for small
|
238 |
-
projects where storing all templates in a single PHP file might make sense.
|
239 |
-
|
240 |
-
.. tip::
|
241 |
-
|
242 |
-
When using the ``Array`` or ``String`` loaders with a cache mechanism, you
|
243 |
-
should know that a new cache key is generated each time a template content
|
244 |
-
"changes" (the cache key being the source code of the template). If you
|
245 |
-
don't want to see your cache grows out of control, you need to take care
|
246 |
-
of clearing the old cache file by yourself.
|
247 |
-
|
248 |
-
``Twig_Loader_Chain``
|
249 |
-
.....................
|
250 |
-
|
251 |
-
``Twig_Loader_Chain`` delegates the loading of templates to other loaders::
|
252 |
-
|
253 |
-
$loader1 = new Twig_Loader_Array(array(
|
254 |
-
'base.html' => '{% block content %}{% endblock %}',
|
255 |
-
));
|
256 |
-
$loader2 = new Twig_Loader_Array(array(
|
257 |
-
'index.html' => '{% extends "base.html" %}{% block content %}Hello {{ name }}{% endblock %}',
|
258 |
-
'base.html' => 'Will never be loaded',
|
259 |
-
));
|
260 |
-
|
261 |
-
$loader = new Twig_Loader_Chain(array($loader1, $loader2));
|
262 |
-
|
263 |
-
$twig = new Twig_Environment($loader);
|
264 |
-
|
265 |
-
When looking for a template, Twig will try each loader in turn and it will
|
266 |
-
return as soon as the template is found. When rendering the ``index.html``
|
267 |
-
template from the above example, Twig will load it with ``$loader2`` but the
|
268 |
-
``base.html`` template will be loaded from ``$loader1``.
|
269 |
-
|
270 |
-
``Twig_Loader_Chain`` accepts any loader that implements
|
271 |
-
``Twig_LoaderInterface``.
|
272 |
-
|
273 |
-
.. note::
|
274 |
-
|
275 |
-
You can also add loaders via the ``addLoader()`` method.
|
276 |
-
|
277 |
-
Create your own Loader
|
278 |
-
~~~~~~~~~~~~~~~~~~~~~~
|
279 |
-
|
280 |
-
All loaders implement the ``Twig_LoaderInterface``::
|
281 |
-
|
282 |
-
interface Twig_LoaderInterface
|
283 |
-
{
|
284 |
-
/**
|
285 |
-
* Gets the source code of a template, given its name.
|
286 |
-
*
|
287 |
-
* @param string $name string The name of the template to load
|
288 |
-
*
|
289 |
-
* @return string The template source code
|
290 |
-
*
|
291 |
-
* @deprecated since 1.27 (to be removed in 2.0), implement Twig_SourceContextLoaderInterface
|
292 |
-
*/
|
293 |
-
function getSource($name);
|
294 |
-
|
295 |
-
/**
|
296 |
-
* Gets the cache key to use for the cache for a given template name.
|
297 |
-
*
|
298 |
-
* @param string $name string The name of the template to load
|
299 |
-
*
|
300 |
-
* @return string The cache key
|
301 |
-
*/
|
302 |
-
function getCacheKey($name);
|
303 |
-
|
304 |
-
/**
|
305 |
-
* Returns true if the template is still fresh.
|
306 |
-
*
|
307 |
-
* @param string $name The template name
|
308 |
-
* @param timestamp $time The last modification time of the cached template
|
309 |
-
*/
|
310 |
-
function isFresh($name, $time);
|
311 |
-
}
|
312 |
-
|
313 |
-
The ``isFresh()`` method must return ``true`` if the current cached template
|
314 |
-
is still fresh, given the last modification time, or ``false`` otherwise.
|
315 |
-
|
316 |
-
.. note::
|
317 |
-
|
318 |
-
As of Twig 1.27, you should also implement
|
319 |
-
``Twig_SourceContextLoaderInterface`` to avoid deprecation notices.
|
320 |
-
|
321 |
-
.. tip::
|
322 |
-
|
323 |
-
As of Twig 1.11.0, you can also implement ``Twig_ExistsLoaderInterface``
|
324 |
-
to make your loader faster when used with the chain loader.
|
325 |
-
|
326 |
-
Using Extensions
|
327 |
-
----------------
|
328 |
-
|
329 |
-
Twig extensions are packages that add new features to Twig. Using an
|
330 |
-
extension is as simple as using the ``addExtension()`` method::
|
331 |
-
|
332 |
-
$twig->addExtension(new Twig_Extension_Sandbox());
|
333 |
-
|
334 |
-
Twig comes bundled with the following extensions:
|
335 |
-
|
336 |
-
* *Twig_Extension_Core*: Defines all the core features of Twig.
|
337 |
-
|
338 |
-
* *Twig_Extension_Escaper*: Adds automatic output-escaping and the possibility
|
339 |
-
to escape/unescape blocks of code.
|
340 |
-
|
341 |
-
* *Twig_Extension_Sandbox*: Adds a sandbox mode to the default Twig
|
342 |
-
environment, making it safe to evaluate untrusted code.
|
343 |
-
|
344 |
-
* *Twig_Extension_Profiler*: Enabled the built-in Twig profiler (as of Twig
|
345 |
-
1.18).
|
346 |
-
|
347 |
-
* *Twig_Extension_Optimizer*: Optimizes the node tree before compilation.
|
348 |
-
|
349 |
-
The core, escaper, and optimizer extensions do not need to be added to the
|
350 |
-
Twig environment, as they are registered by default.
|
351 |
-
|
352 |
-
Built-in Extensions
|
353 |
-
-------------------
|
354 |
-
|
355 |
-
This section describes the features added by the built-in extensions.
|
356 |
-
|
357 |
-
.. tip::
|
358 |
-
|
359 |
-
Read the chapter about extending Twig to learn how to create your own
|
360 |
-
extensions.
|
361 |
-
|
362 |
-
Core Extension
|
363 |
-
~~~~~~~~~~~~~~
|
364 |
-
|
365 |
-
The ``core`` extension defines all the core features of Twig:
|
366 |
-
|
367 |
-
* :doc:`Tags <tags/index>`;
|
368 |
-
* :doc:`Filters <filters/index>`;
|
369 |
-
* :doc:`Functions <functions/index>`;
|
370 |
-
* :doc:`Tests <tests/index>`.
|
371 |
-
|
372 |
-
Escaper Extension
|
373 |
-
~~~~~~~~~~~~~~~~~
|
374 |
-
|
375 |
-
The ``escaper`` extension adds automatic output escaping to Twig. It defines a
|
376 |
-
tag, ``autoescape``, and a filter, ``raw``.
|
377 |
-
|
378 |
-
When creating the escaper extension, you can switch on or off the global
|
379 |
-
output escaping strategy::
|
380 |
-
|
381 |
-
$escaper = new Twig_Extension_Escaper('html');
|
382 |
-
$twig->addExtension($escaper);
|
383 |
-
|
384 |
-
If set to ``html``, all variables in templates are escaped (using the ``html``
|
385 |
-
escaping strategy), except those using the ``raw`` filter:
|
386 |
-
|
387 |
-
.. code-block:: jinja
|
388 |
-
|
389 |
-
{{ article.to_html|raw }}
|
390 |
-
|
391 |
-
You can also change the escaping mode locally by using the ``autoescape`` tag
|
392 |
-
(see the :doc:`autoescape<tags/autoescape>` doc for the syntax used before
|
393 |
-
Twig 1.8):
|
394 |
-
|
395 |
-
.. code-block:: jinja
|
396 |
-
|
397 |
-
{% autoescape 'html' %}
|
398 |
-
{{ var }}
|
399 |
-
{{ var|raw }} {# var won't be escaped #}
|
400 |
-
{{ var|escape }} {# var won't be double-escaped #}
|
401 |
-
{% endautoescape %}
|
402 |
-
|
403 |
-
.. warning::
|
404 |
-
|
405 |
-
The ``autoescape`` tag has no effect on included files.
|
406 |
-
|
407 |
-
The escaping rules are implemented as follows:
|
408 |
-
|
409 |
-
* Literals (integers, booleans, arrays, ...) used in the template directly as
|
410 |
-
variables or filter arguments are never automatically escaped:
|
411 |
-
|
412 |
-
.. code-block:: jinja
|
413 |
-
|
414 |
-
{{ "Twig<br />" }} {# won't be escaped #}
|
415 |
-
|
416 |
-
{% set text = "Twig<br />" %}
|
417 |
-
{{ text }} {# will be escaped #}
|
418 |
-
|
419 |
-
* Expressions which the result is always a literal or a variable marked safe
|
420 |
-
are never automatically escaped:
|
421 |
-
|
422 |
-
.. code-block:: jinja
|
423 |
-
|
424 |
-
{{ foo ? "Twig<br />" : "<br />Twig" }} {# won't be escaped #}
|
425 |
-
|
426 |
-
{% set text = "Twig<br />" %}
|
427 |
-
{{ foo ? text : "<br />Twig" }} {# will be escaped #}
|
428 |
-
|
429 |
-
{% set text = "Twig<br />" %}
|
430 |
-
{{ foo ? text|raw : "<br />Twig" }} {# won't be escaped #}
|
431 |
-
|
432 |
-
{% set text = "Twig<br />" %}
|
433 |
-
{{ foo ? text|escape : "<br />Twig" }} {# the result of the expression won't be escaped #}
|
434 |
-
|
435 |
-
* Escaping is applied before printing, after any other filter is applied:
|
436 |
-
|
437 |
-
.. code-block:: jinja
|
438 |
-
|
439 |
-
{{ var|upper }} {# is equivalent to {{ var|upper|escape }} #}
|
440 |
-
|
441 |
-
* The `raw` filter should only be used at the end of the filter chain:
|
442 |
-
|
443 |
-
.. code-block:: jinja
|
444 |
-
|
445 |
-
{{ var|raw|upper }} {# will be escaped #}
|
446 |
-
|
447 |
-
{{ var|upper|raw }} {# won't be escaped #}
|
448 |
-
|
449 |
-
* Automatic escaping is not applied if the last filter in the chain is marked
|
450 |
-
safe for the current context (e.g. ``html`` or ``js``). ``escape`` and
|
451 |
-
``escape('html')`` are marked safe for HTML, ``escape('js')`` is marked
|
452 |
-
safe for JavaScript, ``raw`` is marked safe for everything.
|
453 |
-
|
454 |
-
.. code-block:: jinja
|
455 |
-
|
456 |
-
{% autoescape 'js' %}
|
457 |
-
{{ var|escape('html') }} {# will be escaped for HTML and JavaScript #}
|
458 |
-
{{ var }} {# will be escaped for JavaScript #}
|
459 |
-
{{ var|escape('js') }} {# won't be double-escaped #}
|
460 |
-
{% endautoescape %}
|
461 |
-
|
462 |
-
.. note::
|
463 |
-
|
464 |
-
Note that autoescaping has some limitations as escaping is applied on
|
465 |
-
expressions after evaluation. For instance, when working with
|
466 |
-
concatenation, ``{{ foo|raw ~ bar }}`` won't give the expected result as
|
467 |
-
escaping is applied on the result of the concatenation, not on the
|
468 |
-
individual variables (so, the ``raw`` filter won't have any effect here).
|
469 |
-
|
470 |
-
Sandbox Extension
|
471 |
-
~~~~~~~~~~~~~~~~~
|
472 |
-
|
473 |
-
The ``sandbox`` extension can be used to evaluate untrusted code. Access to
|
474 |
-
unsafe attributes and methods is prohibited. The sandbox security is managed
|
475 |
-
by a policy instance. By default, Twig comes with one policy class:
|
476 |
-
``Twig_Sandbox_SecurityPolicy``. This class allows you to white-list some
|
477 |
-
tags, filters, properties, and methods::
|
478 |
-
|
479 |
-
$tags = array('if');
|
480 |
-
$filters = array('upper');
|
481 |
-
$methods = array(
|
482 |
-
'Article' => array('getTitle', 'getBody'),
|
483 |
-
);
|
484 |
-
$properties = array(
|
485 |
-
'Article' => array('title', 'body'),
|
486 |
-
);
|
487 |
-
$functions = array('range');
|
488 |
-
$policy = new Twig_Sandbox_SecurityPolicy($tags, $filters, $methods, $properties, $functions);
|
489 |
-
|
490 |
-
With the previous configuration, the security policy will only allow usage of
|
491 |
-
the ``if`` tag, and the ``upper`` filter. Moreover, the templates will only be
|
492 |
-
able to call the ``getTitle()`` and ``getBody()`` methods on ``Article``
|
493 |
-
objects, and the ``title`` and ``body`` public properties. Everything else
|
494 |
-
won't be allowed and will generate a ``Twig_Sandbox_SecurityError`` exception.
|
495 |
-
|
496 |
-
The policy object is the first argument of the sandbox constructor::
|
497 |
-
|
498 |
-
$sandbox = new Twig_Extension_Sandbox($policy);
|
499 |
-
$twig->addExtension($sandbox);
|
500 |
-
|
501 |
-
By default, the sandbox mode is disabled and should be enabled when including
|
502 |
-
untrusted template code by using the ``sandbox`` tag:
|
503 |
-
|
504 |
-
.. code-block:: jinja
|
505 |
-
|
506 |
-
{% sandbox %}
|
507 |
-
{% include 'user.html' %}
|
508 |
-
{% endsandbox %}
|
509 |
-
|
510 |
-
You can sandbox all templates by passing ``true`` as the second argument of
|
511 |
-
the extension constructor::
|
512 |
-
|
513 |
-
$sandbox = new Twig_Extension_Sandbox($policy, true);
|
514 |
-
|
515 |
-
Profiler Extension
|
516 |
-
~~~~~~~~~~~~~~~~~~
|
517 |
-
|
518 |
-
.. versionadded:: 1.18
|
519 |
-
The Profile extension was added in Twig 1.18.
|
520 |
-
|
521 |
-
The ``profiler`` extension enables a profiler for Twig templates; it should
|
522 |
-
only be used on your development machines as it adds some overhead::
|
523 |
-
|
524 |
-
$profile = new Twig_Profiler_Profile();
|
525 |
-
$twig->addExtension(new Twig_Extension_Profiler($profile));
|
526 |
-
|
527 |
-
$dumper = new Twig_Profiler_Dumper_Text();
|
528 |
-
echo $dumper->dump($profile);
|
529 |
-
|
530 |
-
A profile contains information about time and memory consumption for template,
|
531 |
-
block, and macro executions.
|
532 |
-
|
533 |
-
You can also dump the data in a `Blackfire.io <https://blackfire.io/>`_
|
534 |
-
compatible format::
|
535 |
-
|
536 |
-
$dumper = new Twig_Profiler_Dumper_Blackfire();
|
537 |
-
file_put_contents('/path/to/profile.prof', $dumper->dump($profile));
|
538 |
-
|
539 |
-
Upload the profile to visualize it (create a `free account
|
540 |
-
<https://blackfire.io/signup>`_ first):
|
541 |
-
|
542 |
-
.. code-block:: sh
|
543 |
-
|
544 |
-
blackfire --slot=7 upload /path/to/profile.prof
|
545 |
-
|
546 |
-
Optimizer Extension
|
547 |
-
~~~~~~~~~~~~~~~~~~~
|
548 |
-
|
549 |
-
The ``optimizer`` extension optimizes the node tree before compilation::
|
550 |
-
|
551 |
-
$twig->addExtension(new Twig_Extension_Optimizer());
|
552 |
-
|
553 |
-
By default, all optimizations are turned on. You can select the ones you want
|
554 |
-
to enable by passing them to the constructor::
|
555 |
-
|
556 |
-
$optimizer = new Twig_Extension_Optimizer(Twig_NodeVisitor_Optimizer::OPTIMIZE_FOR);
|
557 |
-
|
558 |
-
$twig->addExtension($optimizer);
|
559 |
-
|
560 |
-
Twig supports the following optimizations:
|
561 |
-
|
562 |
-
* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_ALL``, enables all optimizations
|
563 |
-
(this is the default value).
|
564 |
-
* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_NONE``, disables all optimizations.
|
565 |
-
This reduces the compilation time, but it can increase the execution time
|
566 |
-
and the consumed memory.
|
567 |
-
* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_FOR``, optimizes the ``for`` tag by
|
568 |
-
removing the ``loop`` variable creation whenever possible.
|
569 |
-
* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_RAW_FILTER``, removes the ``raw``
|
570 |
-
filter whenever possible.
|
571 |
-
* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_VAR_ACCESS``, simplifies the creation
|
572 |
-
and access of variables in the compiled templates whenever possible.
|
573 |
-
|
574 |
-
Exceptions
|
575 |
-
----------
|
576 |
-
|
577 |
-
Twig can throw exceptions:
|
578 |
-
|
579 |
-
* ``Twig_Error``: The base exception for all errors.
|
580 |
-
|
581 |
-
* ``Twig_Error_Syntax``: Thrown to tell the user that there is a problem with
|
582 |
-
the template syntax.
|
583 |
-
|
584 |
-
* ``Twig_Error_Runtime``: Thrown when an error occurs at runtime (when a filter
|
585 |
-
does not exist for instance).
|
586 |
-
|
587 |
-
* ``Twig_Error_Loader``: Thrown when an error occurs during template loading.
|
588 |
-
|
589 |
-
* ``Twig_Sandbox_SecurityError``: Thrown when an unallowed tag, filter, or
|
590 |
-
method is called in a sandboxed template.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/coding_standards.rst
DELETED
@@ -1,101 +0,0 @@
|
|
1 |
-
Coding Standards
|
2 |
-
================
|
3 |
-
|
4 |
-
When writing Twig templates, we recommend you to follow these official coding
|
5 |
-
standards:
|
6 |
-
|
7 |
-
* Put one (and only one) space after the start of a delimiter (``{{``, ``{%``,
|
8 |
-
and ``{#``) and before the end of a delimiter (``}}``, ``%}``, and ``#}``):
|
9 |
-
|
10 |
-
.. code-block:: jinja
|
11 |
-
|
12 |
-
{{ foo }}
|
13 |
-
{# comment #}
|
14 |
-
{% if foo %}{% endif %}
|
15 |
-
|
16 |
-
When using the whitespace control character, do not put any spaces between
|
17 |
-
it and the delimiter:
|
18 |
-
|
19 |
-
.. code-block:: jinja
|
20 |
-
|
21 |
-
{{- foo -}}
|
22 |
-
{#- comment -#}
|
23 |
-
{%- if foo -%}{%- endif -%}
|
24 |
-
|
25 |
-
* Put one (and only one) space before and after the following operators:
|
26 |
-
comparison operators (``==``, ``!=``, ``<``, ``>``, ``>=``, ``<=``), math
|
27 |
-
operators (``+``, ``-``, ``/``, ``*``, ``%``, ``//``, ``**``), logic
|
28 |
-
operators (``not``, ``and``, ``or``), ``~``, ``is``, ``in``, and the ternary
|
29 |
-
operator (``?:``):
|
30 |
-
|
31 |
-
.. code-block:: jinja
|
32 |
-
|
33 |
-
{{ 1 + 2 }}
|
34 |
-
{{ foo ~ bar }}
|
35 |
-
{{ true ? true : false }}
|
36 |
-
|
37 |
-
* Put one (and only one) space after the ``:`` sign in hashes and ``,`` in
|
38 |
-
arrays and hashes:
|
39 |
-
|
40 |
-
.. code-block:: jinja
|
41 |
-
|
42 |
-
{{ [1, 2, 3] }}
|
43 |
-
{{ {'foo': 'bar'} }}
|
44 |
-
|
45 |
-
* Do not put any spaces after an opening parenthesis and before a closing
|
46 |
-
parenthesis in expressions:
|
47 |
-
|
48 |
-
.. code-block:: jinja
|
49 |
-
|
50 |
-
{{ 1 + (2 * 3) }}
|
51 |
-
|
52 |
-
* Do not put any spaces before and after string delimiters:
|
53 |
-
|
54 |
-
.. code-block:: jinja
|
55 |
-
|
56 |
-
{{ 'foo' }}
|
57 |
-
{{ "foo" }}
|
58 |
-
|
59 |
-
* Do not put any spaces before and after the following operators: ``|``,
|
60 |
-
``.``, ``..``, ``[]``:
|
61 |
-
|
62 |
-
.. code-block:: jinja
|
63 |
-
|
64 |
-
{{ foo|upper|lower }}
|
65 |
-
{{ user.name }}
|
66 |
-
{{ user[name] }}
|
67 |
-
{% for i in 1..12 %}{% endfor %}
|
68 |
-
|
69 |
-
* Do not put any spaces before and after the parenthesis used for filter and
|
70 |
-
function calls:
|
71 |
-
|
72 |
-
.. code-block:: jinja
|
73 |
-
|
74 |
-
{{ foo|default('foo') }}
|
75 |
-
{{ range(1..10) }}
|
76 |
-
|
77 |
-
* Do not put any spaces before and after the opening and the closing of arrays
|
78 |
-
and hashes:
|
79 |
-
|
80 |
-
.. code-block:: jinja
|
81 |
-
|
82 |
-
{{ [1, 2, 3] }}
|
83 |
-
{{ {'foo': 'bar'} }}
|
84 |
-
|
85 |
-
* Use lower cased and underscored variable names:
|
86 |
-
|
87 |
-
.. code-block:: jinja
|
88 |
-
|
89 |
-
{% set foo = 'foo' %}
|
90 |
-
{% set foo_bar = 'foo' %}
|
91 |
-
|
92 |
-
* Indent your code inside tags (use the same indentation as the one used for
|
93 |
-
the target language of the rendered template):
|
94 |
-
|
95 |
-
.. code-block:: jinja
|
96 |
-
|
97 |
-
{% block foo %}
|
98 |
-
{% if true %}
|
99 |
-
true
|
100 |
-
{% endif %}
|
101 |
-
{% endblock %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/deprecated.rst
DELETED
@@ -1,210 +0,0 @@
|
|
1 |
-
Deprecated Features
|
2 |
-
===================
|
3 |
-
|
4 |
-
This document lists all deprecated features in Twig. Deprecated features are
|
5 |
-
kept for backward compatibility and removed in the next major release (a
|
6 |
-
feature that was deprecated in Twig 1.x is removed in Twig 2.0).
|
7 |
-
|
8 |
-
Deprecation Notices
|
9 |
-
-------------------
|
10 |
-
|
11 |
-
As of Twig 1.21, Twig generates deprecation notices when a template uses
|
12 |
-
deprecated features. See :ref:`deprecation-notices` for more information.
|
13 |
-
|
14 |
-
Token Parsers
|
15 |
-
-------------
|
16 |
-
|
17 |
-
* As of Twig 1.x, the token parser broker sub-system is deprecated. The
|
18 |
-
following class and interface will be removed in 2.0:
|
19 |
-
|
20 |
-
* ``Twig_TokenParserBrokerInterface``
|
21 |
-
* ``Twig_TokenParserBroker``
|
22 |
-
|
23 |
-
* As of Twig 1.27, ``Twig_Parser::getFilename()`` is deprecated. From a token
|
24 |
-
parser, use ``$this->parser->getStream()->getSourceContext()->getPath()`` instead.
|
25 |
-
|
26 |
-
* As of Twig 1.27, ``Twig_Parser::getEnvironment()`` is deprecated.
|
27 |
-
|
28 |
-
Extensions
|
29 |
-
----------
|
30 |
-
|
31 |
-
* As of Twig 1.x, the ability to remove an extension is deprecated and the
|
32 |
-
``Twig_Environment::removeExtension()`` method will be removed in 2.0.
|
33 |
-
|
34 |
-
* As of Twig 1.23, the ``Twig_ExtensionInterface::initRuntime()`` method is
|
35 |
-
deprecated. You have two options to avoid the deprecation notice: if you
|
36 |
-
implement this method to store the environment for your custom filters,
|
37 |
-
functions, or tests, use the ``needs_environment`` option instead; if you
|
38 |
-
have more complex needs, explicitly implement
|
39 |
-
``Twig_Extension_InitRuntimeInterface`` (not recommended).
|
40 |
-
|
41 |
-
* As of Twig 1.23, the ``Twig_ExtensionInterface::getGlobals()`` method is
|
42 |
-
deprecated. Implement ``Twig_Extension_GlobalsInterface`` to avoid
|
43 |
-
deprecation notices.
|
44 |
-
|
45 |
-
* As of Twig 1.26, the ``Twig_ExtensionInterface::getName()`` method is
|
46 |
-
deprecated and it is not used internally anymore.
|
47 |
-
|
48 |
-
PEAR
|
49 |
-
----
|
50 |
-
|
51 |
-
PEAR support has been discontinued in Twig 1.15.1, and no PEAR packages are
|
52 |
-
provided anymore. Use Composer instead.
|
53 |
-
|
54 |
-
Filters
|
55 |
-
-------
|
56 |
-
|
57 |
-
* As of Twig 1.x, use ``Twig_SimpleFilter`` to add a filter. The following
|
58 |
-
classes and interfaces will be removed in 2.0:
|
59 |
-
|
60 |
-
* ``Twig_FilterInterface``
|
61 |
-
* ``Twig_FilterCallableInterface``
|
62 |
-
* ``Twig_Filter``
|
63 |
-
* ``Twig_Filter_Function``
|
64 |
-
* ``Twig_Filter_Method``
|
65 |
-
* ``Twig_Filter_Node``
|
66 |
-
|
67 |
-
* As of Twig 2.x, the ``Twig_SimpleFilter`` class is deprecated and will be
|
68 |
-
removed in Twig 3.x (use ``Twig_Filter`` instead). In Twig 2.x,
|
69 |
-
``Twig_SimpleFilter`` is just an alias for ``Twig_Filter``.
|
70 |
-
|
71 |
-
Functions
|
72 |
-
---------
|
73 |
-
|
74 |
-
* As of Twig 1.x, use ``Twig_SimpleFunction`` to add a function. The following
|
75 |
-
classes and interfaces will be removed in 2.0:
|
76 |
-
|
77 |
-
* ``Twig_FunctionInterface``
|
78 |
-
* ``Twig_FunctionCallableInterface``
|
79 |
-
* ``Twig_Function``
|
80 |
-
* ``Twig_Function_Function``
|
81 |
-
* ``Twig_Function_Method``
|
82 |
-
* ``Twig_Function_Node``
|
83 |
-
|
84 |
-
* As of Twig 2.x, the ``Twig_SimpleFunction`` class is deprecated and will be
|
85 |
-
removed in Twig 3.x (use ``Twig_Function`` instead). In Twig 2.x,
|
86 |
-
``Twig_SimpleFunction`` is just an alias for ``Twig_Function``.
|
87 |
-
|
88 |
-
Tests
|
89 |
-
-----
|
90 |
-
|
91 |
-
* As of Twig 1.x, use ``Twig_SimpleTest`` to add a test. The following classes
|
92 |
-
and interfaces will be removed in 2.0:
|
93 |
-
|
94 |
-
* ``Twig_TestInterface``
|
95 |
-
* ``Twig_TestCallableInterface``
|
96 |
-
* ``Twig_Test``
|
97 |
-
* ``Twig_Test_Function``
|
98 |
-
* ``Twig_Test_Method``
|
99 |
-
* ``Twig_Test_Node``
|
100 |
-
|
101 |
-
* As of Twig 2.x, the ``Twig_SimpleTest`` class is deprecated and will be
|
102 |
-
removed in Twig 3.x (use ``Twig_Test`` instead). In Twig 2.x,
|
103 |
-
``Twig_SimpleTest`` is just an alias for ``Twig_Test``.
|
104 |
-
|
105 |
-
* The ``sameas`` and ``divisibleby`` tests are deprecated in favor of ``same
|
106 |
-
as`` and ``divisible by`` respectively.
|
107 |
-
|
108 |
-
Tags
|
109 |
-
----
|
110 |
-
|
111 |
-
* As of Twig 1.x, the ``raw`` tag is deprecated. You should use ``verbatim``
|
112 |
-
instead.
|
113 |
-
|
114 |
-
Nodes
|
115 |
-
-----
|
116 |
-
|
117 |
-
* As of Twig 1.x, ``Node::toXml()`` is deprecated and will be removed in Twig
|
118 |
-
2.0.
|
119 |
-
|
120 |
-
* As of Twig 1.26, ``Node::$nodes`` should only contains ``Twig_Node``
|
121 |
-
instances, storing a ``null`` value is deprecated and won't be possible in
|
122 |
-
Twig 2.x.
|
123 |
-
|
124 |
-
* As of Twig 1.27, the ``filename`` attribute on ``Twig_Node_Module`` is
|
125 |
-
deprecated. Use ``getName()`` instead.
|
126 |
-
|
127 |
-
* As of Twig 1.27, the ``Twig_Node::getFilename()/Twig_Node::getLine()``
|
128 |
-
methods are deprecated, use
|
129 |
-
``Twig_Node::getTemplateName()/Twig_Node::getTemplateLine()`` instead.
|
130 |
-
|
131 |
-
Interfaces
|
132 |
-
----------
|
133 |
-
|
134 |
-
* As of Twig 2.x, the following interfaces are deprecated and empty (they will
|
135 |
-
be removed in Twig 3.0):
|
136 |
-
|
137 |
-
* ``Twig_CompilerInterface`` (use ``Twig_Compiler`` instead)
|
138 |
-
* ``Twig_LexerInterface`` (use ``Twig_Lexer`` instead)
|
139 |
-
* ``Twig_NodeInterface`` (use ``Twig_Node`` instead)
|
140 |
-
* ``Twig_ParserInterface`` (use ``Twig_Parser`` instead)
|
141 |
-
* ``Twig_ExistsLoaderInterface`` (merged with ``Twig_LoaderInterface``)
|
142 |
-
* ``Twig_SourceContextLoaderInterface`` (merged with ``Twig_LoaderInterface``)
|
143 |
-
* ``Twig_TemplateInterface`` (use ``Twig_Template`` instead, and use
|
144 |
-
those constants Twig_Template::ANY_CALL, Twig_Template::ARRAY_CALL,
|
145 |
-
Twig_Template::METHOD_CALL)
|
146 |
-
|
147 |
-
Compiler
|
148 |
-
--------
|
149 |
-
|
150 |
-
* As of Twig 1.26, the ``Twig_Compiler::getFilename()`` has been deprecated.
|
151 |
-
You should not use it anyway as its values is not reliable.
|
152 |
-
|
153 |
-
* As of Twig 1.27, the ``Twig_Compiler::addIndentation()`` has been deprecated.
|
154 |
-
Use ``Twig_Compiler::write('')`` instead.
|
155 |
-
|
156 |
-
Loaders
|
157 |
-
-------
|
158 |
-
|
159 |
-
* As of Twig 1.x, ``Twig_Loader_String`` is deprecated and will be removed in
|
160 |
-
2.0. You can render a string via ``Twig_Environment::createTemplate()``.
|
161 |
-
|
162 |
-
* As of Twig 1.27, ``Twig_LoaderInterface::getSource()`` is deprecated.
|
163 |
-
Implement ``Twig_SourceContextLoaderInterface`` instead and use
|
164 |
-
``getSourceContext()``.
|
165 |
-
|
166 |
-
Node Visitors
|
167 |
-
-------------
|
168 |
-
|
169 |
-
* Because of the removal of ``Twig_NodeInterface`` in 2.0, you need to extend
|
170 |
-
``Twig_BaseNodeVisitor`` instead of implementing ``Twig_NodeVisitorInterface``
|
171 |
-
directly to make your node visitors compatible with both Twig 1.x and 2.x.
|
172 |
-
|
173 |
-
Globals
|
174 |
-
-------
|
175 |
-
|
176 |
-
* As of Twig 2.x, the ability to register a global variable after the runtime
|
177 |
-
or the extensions have been initialized is not possible anymore (but
|
178 |
-
changing the value of an already registered global is possible).
|
179 |
-
|
180 |
-
* As of Twig 1.x, using the ``_self`` global variable to get access to the
|
181 |
-
current ``Twig_Template`` instance is deprecated; most usages only need the
|
182 |
-
current template name, which will continue to work in Twig 2.0. In Twig 2.0,
|
183 |
-
``_self`` returns the current template name instead of the current
|
184 |
-
``Twig_Template`` instance.
|
185 |
-
|
186 |
-
Miscellaneous
|
187 |
-
-------------
|
188 |
-
|
189 |
-
* As of Twig 1.x, ``Twig_Environment::clearTemplateCache()``,
|
190 |
-
``Twig_Environment::writeCacheFile()``,
|
191 |
-
``Twig_Environment::clearCacheFiles()``,
|
192 |
-
``Twig_Environment::getCacheFilename()``,
|
193 |
-
``Twig_Environment::getTemplateClassPrefix()``,
|
194 |
-
``Twig_Environment::getLexer()``, ``Twig_Environment::getParser()``, and
|
195 |
-
``Twig_Environment::getCompiler()`` are deprecated and will be removed in 2.0.
|
196 |
-
|
197 |
-
* As of Twig 1.x, ``Twig_Template::getEnvironment()`` and
|
198 |
-
``Twig_TemplateInterface::getEnvironment()`` are deprecated and will be
|
199 |
-
removed in 2.0.
|
200 |
-
|
201 |
-
* As of Twig 1.27, ``Twig_Error::getTemplateFile()`` and
|
202 |
-
``Twig_Error::setTemplateFile()`` are deprecated. Use
|
203 |
-
``Twig_Error::getTemplateName()`` and ``Twig_Error::setTemplateName()``
|
204 |
-
instead.
|
205 |
-
|
206 |
-
* As of Twig 1.27, ``Twig_Template::getSource()`` is deprecated. Use
|
207 |
-
``Twig_Template::getSourceContext()`` instead.
|
208 |
-
|
209 |
-
* As of Twig 1.27, ``Twig_Parser::addHandler()`` and
|
210 |
-
``Twig_Parser::addNodeVisitor()`` are deprecated and will be removed in 2.0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/abs.rst
DELETED
@@ -1,18 +0,0 @@
|
|
1 |
-
``abs``
|
2 |
-
=======
|
3 |
-
|
4 |
-
The ``abs`` filter returns the absolute value.
|
5 |
-
|
6 |
-
.. code-block:: jinja
|
7 |
-
|
8 |
-
{# number = -5 #}
|
9 |
-
|
10 |
-
{{ number|abs }}
|
11 |
-
|
12 |
-
{# outputs 5 #}
|
13 |
-
|
14 |
-
.. note::
|
15 |
-
|
16 |
-
Internally, Twig uses the PHP `abs`_ function.
|
17 |
-
|
18 |
-
.. _`abs`: http://php.net/abs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/batch.rst
DELETED
@@ -1,51 +0,0 @@
|
|
1 |
-
``batch``
|
2 |
-
=========
|
3 |
-
|
4 |
-
.. versionadded:: 1.12.3
|
5 |
-
The ``batch`` filter was added in Twig 1.12.3.
|
6 |
-
|
7 |
-
The ``batch`` filter "batches" items by returning a list of lists with the
|
8 |
-
given number of items. A second parameter can be provided and used to fill in
|
9 |
-
missing items:
|
10 |
-
|
11 |
-
.. code-block:: jinja
|
12 |
-
|
13 |
-
{% set items = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] %}
|
14 |
-
|
15 |
-
<table>
|
16 |
-
{% for row in items|batch(3, 'No item') %}
|
17 |
-
<tr>
|
18 |
-
{% for column in row %}
|
19 |
-
<td>{{ column }}</td>
|
20 |
-
{% endfor %}
|
21 |
-
</tr>
|
22 |
-
{% endfor %}
|
23 |
-
</table>
|
24 |
-
|
25 |
-
The above example will be rendered as:
|
26 |
-
|
27 |
-
.. code-block:: jinja
|
28 |
-
|
29 |
-
<table>
|
30 |
-
<tr>
|
31 |
-
<td>a</td>
|
32 |
-
<td>b</td>
|
33 |
-
<td>c</td>
|
34 |
-
</tr>
|
35 |
-
<tr>
|
36 |
-
<td>d</td>
|
37 |
-
<td>e</td>
|
38 |
-
<td>f</td>
|
39 |
-
</tr>
|
40 |
-
<tr>
|
41 |
-
<td>g</td>
|
42 |
-
<td>No item</td>
|
43 |
-
<td>No item</td>
|
44 |
-
</tr>
|
45 |
-
</table>
|
46 |
-
|
47 |
-
Arguments
|
48 |
-
---------
|
49 |
-
|
50 |
-
* ``size``: The size of the batch; fractional numbers will be rounded up
|
51 |
-
* ``fill``: Used to fill in missing items
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/capitalize.rst
DELETED
@@ -1,11 +0,0 @@
|
|
1 |
-
``capitalize``
|
2 |
-
==============
|
3 |
-
|
4 |
-
The ``capitalize`` filter capitalizes a value. The first character will be
|
5 |
-
uppercase, all others lowercase:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{{ 'my first car'|capitalize }}
|
10 |
-
|
11 |
-
{# outputs 'My first car' #}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/convert_encoding.rst
DELETED
@@ -1,28 +0,0 @@
|
|
1 |
-
``convert_encoding``
|
2 |
-
====================
|
3 |
-
|
4 |
-
.. versionadded:: 1.4
|
5 |
-
The ``convert_encoding`` filter was added in Twig 1.4.
|
6 |
-
|
7 |
-
The ``convert_encoding`` filter converts a string from one encoding to
|
8 |
-
another. The first argument is the expected output charset and the second one
|
9 |
-
is the input charset:
|
10 |
-
|
11 |
-
.. code-block:: jinja
|
12 |
-
|
13 |
-
{{ data|convert_encoding('UTF-8', 'iso-2022-jp') }}
|
14 |
-
|
15 |
-
.. note::
|
16 |
-
|
17 |
-
This filter relies on the `iconv`_ or `mbstring`_ extension, so one of
|
18 |
-
them must be installed. In case both are installed, `mbstring`_ is used by
|
19 |
-
default (Twig before 1.8.1 uses `iconv`_ by default).
|
20 |
-
|
21 |
-
Arguments
|
22 |
-
---------
|
23 |
-
|
24 |
-
* ``to``: The output charset
|
25 |
-
* ``from``: The input charset
|
26 |
-
|
27 |
-
.. _`iconv`: http://php.net/iconv
|
28 |
-
.. _`mbstring`: http://php.net/mbstring
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/date.rst
DELETED
@@ -1,100 +0,0 @@
|
|
1 |
-
``date``
|
2 |
-
========
|
3 |
-
|
4 |
-
.. versionadded:: 1.1
|
5 |
-
The timezone support has been added in Twig 1.1.
|
6 |
-
|
7 |
-
.. versionadded:: 1.5
|
8 |
-
The default date format support has been added in Twig 1.5.
|
9 |
-
|
10 |
-
.. versionadded:: 1.6.1
|
11 |
-
The default timezone support has been added in Twig 1.6.1.
|
12 |
-
|
13 |
-
.. versionadded:: 1.11.0
|
14 |
-
The introduction of the false value for the timezone was introduced in Twig 1.11.0
|
15 |
-
|
16 |
-
The ``date`` filter formats a date to a given format:
|
17 |
-
|
18 |
-
.. code-block:: jinja
|
19 |
-
|
20 |
-
{{ post.published_at|date("m/d/Y") }}
|
21 |
-
|
22 |
-
The format specifier is the same as supported by `date`_,
|
23 |
-
except when the filtered data is of type `DateInterval`_, when the format must conform to
|
24 |
-
`DateInterval::format`_ instead.
|
25 |
-
|
26 |
-
The ``date`` filter accepts strings (it must be in a format supported by the
|
27 |
-
`strtotime`_ function), `DateTime`_ instances, or `DateInterval`_ instances. For
|
28 |
-
instance, to display the current date, filter the word "now":
|
29 |
-
|
30 |
-
.. code-block:: jinja
|
31 |
-
|
32 |
-
{{ "now"|date("m/d/Y") }}
|
33 |
-
|
34 |
-
To escape words and characters in the date format use ``\\`` in front of each
|
35 |
-
character:
|
36 |
-
|
37 |
-
.. code-block:: jinja
|
38 |
-
|
39 |
-
{{ post.published_at|date("F jS \\a\\t g:ia") }}
|
40 |
-
|
41 |
-
If the value passed to the ``date`` filter is ``null``, it will return the
|
42 |
-
current date by default. If an empty string is desired instead of the current
|
43 |
-
date, use a ternary operator:
|
44 |
-
|
45 |
-
.. code-block:: jinja
|
46 |
-
|
47 |
-
{{ post.published_at is empty ? "" : post.published_at|date("m/d/Y") }}
|
48 |
-
|
49 |
-
If no format is provided, Twig will use the default one: ``F j, Y H:i``. This
|
50 |
-
default can be easily changed by calling the ``setDateFormat()`` method on the
|
51 |
-
``core`` extension instance. The first argument is the default format for
|
52 |
-
dates and the second one is the default format for date intervals:
|
53 |
-
|
54 |
-
.. code-block:: php
|
55 |
-
|
56 |
-
$twig = new Twig_Environment($loader);
|
57 |
-
$twig->getExtension('Twig_Extension_Core')->setDateFormat('d/m/Y', '%d days');
|
58 |
-
|
59 |
-
// before Twig 1.26
|
60 |
-
$twig->getExtension('core')->setDateFormat('d/m/Y', '%d days');
|
61 |
-
|
62 |
-
Timezone
|
63 |
-
--------
|
64 |
-
|
65 |
-
By default, the date is displayed by applying the default timezone (the one
|
66 |
-
specified in php.ini or declared in Twig -- see below), but you can override
|
67 |
-
it by explicitly specifying a timezone:
|
68 |
-
|
69 |
-
.. code-block:: jinja
|
70 |
-
|
71 |
-
{{ post.published_at|date("m/d/Y", "Europe/Paris") }}
|
72 |
-
|
73 |
-
If the date is already a DateTime object, and if you want to keep its current
|
74 |
-
timezone, pass ``false`` as the timezone value:
|
75 |
-
|
76 |
-
.. code-block:: jinja
|
77 |
-
|
78 |
-
{{ post.published_at|date("m/d/Y", false) }}
|
79 |
-
|
80 |
-
The default timezone can also be set globally by calling ``setTimezone()``:
|
81 |
-
|
82 |
-
.. code-block:: php
|
83 |
-
|
84 |
-
$twig = new Twig_Environment($loader);
|
85 |
-
$twig->getExtension('Twig_Extension_Core')->setTimezone('Europe/Paris');
|
86 |
-
|
87 |
-
// before Twig 1.26
|
88 |
-
$twig->getExtension('core')->setTimezone('Europe/Paris');
|
89 |
-
|
90 |
-
Arguments
|
91 |
-
---------
|
92 |
-
|
93 |
-
* ``format``: The date format
|
94 |
-
* ``timezone``: The date timezone
|
95 |
-
|
96 |
-
.. _`strtotime`: http://www.php.net/strtotime
|
97 |
-
.. _`DateTime`: http://www.php.net/DateTime
|
98 |
-
.. _`DateInterval`: http://www.php.net/DateInterval
|
99 |
-
.. _`date`: http://www.php.net/date
|
100 |
-
.. _`DateInterval::format`: http://www.php.net/DateInterval.format
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/date_modify.rst
DELETED
@@ -1,23 +0,0 @@
|
|
1 |
-
``date_modify``
|
2 |
-
===============
|
3 |
-
|
4 |
-
.. versionadded:: 1.9.0
|
5 |
-
The date_modify filter has been added in Twig 1.9.0.
|
6 |
-
|
7 |
-
The ``date_modify`` filter modifies a date with a given modifier string:
|
8 |
-
|
9 |
-
.. code-block:: jinja
|
10 |
-
|
11 |
-
{{ post.published_at|date_modify("+1 day")|date("m/d/Y") }}
|
12 |
-
|
13 |
-
The ``date_modify`` filter accepts strings (it must be in a format supported
|
14 |
-
by the `strtotime`_ function) or `DateTime`_ instances. You can easily combine
|
15 |
-
it with the :doc:`date<date>` filter for formatting.
|
16 |
-
|
17 |
-
Arguments
|
18 |
-
---------
|
19 |
-
|
20 |
-
* ``modifier``: The modifier
|
21 |
-
|
22 |
-
.. _`strtotime`: http://www.php.net/strtotime
|
23 |
-
.. _`DateTime`: http://www.php.net/DateTime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/default.rst
DELETED
@@ -1,33 +0,0 @@
|
|
1 |
-
``default``
|
2 |
-
===========
|
3 |
-
|
4 |
-
The ``default`` filter returns the passed default value if the value is
|
5 |
-
undefined or empty, otherwise the value of the variable:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{{ var|default('var is not defined') }}
|
10 |
-
|
11 |
-
{{ var.foo|default('foo item on var is not defined') }}
|
12 |
-
|
13 |
-
{{ var['foo']|default('foo item on var is not defined') }}
|
14 |
-
|
15 |
-
{{ ''|default('passed var is empty') }}
|
16 |
-
|
17 |
-
When using the ``default`` filter on an expression that uses variables in some
|
18 |
-
method calls, be sure to use the ``default`` filter whenever a variable can be
|
19 |
-
undefined:
|
20 |
-
|
21 |
-
.. code-block:: jinja
|
22 |
-
|
23 |
-
{{ var.method(foo|default('foo'))|default('foo') }}
|
24 |
-
|
25 |
-
.. note::
|
26 |
-
|
27 |
-
Read the documentation for the :doc:`defined<../tests/defined>` and
|
28 |
-
:doc:`empty<../tests/empty>` tests to learn more about their semantics.
|
29 |
-
|
30 |
-
Arguments
|
31 |
-
---------
|
32 |
-
|
33 |
-
* ``default``: The default value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/escape.rst
DELETED
@@ -1,119 +0,0 @@
|
|
1 |
-
``escape``
|
2 |
-
==========
|
3 |
-
|
4 |
-
.. versionadded:: 1.9.0
|
5 |
-
The ``css``, ``url``, and ``html_attr`` strategies were added in Twig
|
6 |
-
1.9.0.
|
7 |
-
|
8 |
-
.. versionadded:: 1.14.0
|
9 |
-
The ability to define custom escapers was added in Twig 1.14.0.
|
10 |
-
|
11 |
-
The ``escape`` filter escapes a string for safe insertion into the final
|
12 |
-
output. It supports different escaping strategies depending on the template
|
13 |
-
context.
|
14 |
-
|
15 |
-
By default, it uses the HTML escaping strategy:
|
16 |
-
|
17 |
-
.. code-block:: jinja
|
18 |
-
|
19 |
-
{{ user.username|escape }}
|
20 |
-
|
21 |
-
For convenience, the ``e`` filter is defined as an alias:
|
22 |
-
|
23 |
-
.. code-block:: jinja
|
24 |
-
|
25 |
-
{{ user.username|e }}
|
26 |
-
|
27 |
-
The ``escape`` filter can also be used in other contexts than HTML thanks to
|
28 |
-
an optional argument which defines the escaping strategy to use:
|
29 |
-
|
30 |
-
.. code-block:: jinja
|
31 |
-
|
32 |
-
{{ user.username|e }}
|
33 |
-
{# is equivalent to #}
|
34 |
-
{{ user.username|e('html') }}
|
35 |
-
|
36 |
-
And here is how to escape variables included in JavaScript code:
|
37 |
-
|
38 |
-
.. code-block:: jinja
|
39 |
-
|
40 |
-
{{ user.username|escape('js') }}
|
41 |
-
{{ user.username|e('js') }}
|
42 |
-
|
43 |
-
The ``escape`` filter supports the following escaping strategies:
|
44 |
-
|
45 |
-
* ``html``: escapes a string for the **HTML body** context.
|
46 |
-
|
47 |
-
* ``js``: escapes a string for the **JavaScript context**.
|
48 |
-
|
49 |
-
* ``css``: escapes a string for the **CSS context**. CSS escaping can be
|
50 |
-
applied to any string being inserted into CSS and escapes everything except
|
51 |
-
alphanumerics.
|
52 |
-
|
53 |
-
* ``url``: escapes a string for the **URI or parameter contexts**. This should
|
54 |
-
not be used to escape an entire URI; only a subcomponent being inserted.
|
55 |
-
|
56 |
-
* ``html_attr``: escapes a string for the **HTML attribute** context.
|
57 |
-
|
58 |
-
.. note::
|
59 |
-
|
60 |
-
Internally, ``escape`` uses the PHP native `htmlspecialchars`_ function
|
61 |
-
for the HTML escaping strategy.
|
62 |
-
|
63 |
-
.. caution::
|
64 |
-
|
65 |
-
When using automatic escaping, Twig tries to not double-escape a variable
|
66 |
-
when the automatic escaping strategy is the same as the one applied by the
|
67 |
-
escape filter; but that does not work when using a variable as the
|
68 |
-
escaping strategy:
|
69 |
-
|
70 |
-
.. code-block:: jinja
|
71 |
-
|
72 |
-
{% set strategy = 'html' %}
|
73 |
-
|
74 |
-
{% autoescape 'html' %}
|
75 |
-
{{ var|escape('html') }} {# won't be double-escaped #}
|
76 |
-
{{ var|escape(strategy) }} {# will be double-escaped #}
|
77 |
-
{% endautoescape %}
|
78 |
-
|
79 |
-
When using a variable as the escaping strategy, you should disable
|
80 |
-
automatic escaping:
|
81 |
-
|
82 |
-
.. code-block:: jinja
|
83 |
-
|
84 |
-
{% set strategy = 'html' %}
|
85 |
-
|
86 |
-
{% autoescape 'html' %}
|
87 |
-
{{ var|escape(strategy)|raw }} {# won't be double-escaped #}
|
88 |
-
{% endautoescape %}
|
89 |
-
|
90 |
-
Custom Escapers
|
91 |
-
---------------
|
92 |
-
|
93 |
-
You can define custom escapers by calling the ``setEscaper()`` method on the
|
94 |
-
``core`` extension instance. The first argument is the escaper name (to be
|
95 |
-
used in the ``escape`` call) and the second one must be a valid PHP callable:
|
96 |
-
|
97 |
-
.. code-block:: php
|
98 |
-
|
99 |
-
$twig = new Twig_Environment($loader);
|
100 |
-
$twig->getExtension('Twig_Extension_Core')->setEscaper('csv', 'csv_escaper');
|
101 |
-
|
102 |
-
// before Twig 1.26
|
103 |
-
$twig->getExtension('core')->setEscaper('csv', 'csv_escaper');
|
104 |
-
|
105 |
-
When called by Twig, the callable receives the Twig environment instance, the
|
106 |
-
string to escape, and the charset.
|
107 |
-
|
108 |
-
.. note::
|
109 |
-
|
110 |
-
Built-in escapers cannot be overridden mainly they should be considered as
|
111 |
-
the final implementation and also for better performance.
|
112 |
-
|
113 |
-
Arguments
|
114 |
-
---------
|
115 |
-
|
116 |
-
* ``strategy``: The escaping strategy
|
117 |
-
* ``charset``: The string charset
|
118 |
-
|
119 |
-
.. _`htmlspecialchars`: http://php.net/htmlspecialchars
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/first.rst
DELETED
@@ -1,25 +0,0 @@
|
|
1 |
-
``first``
|
2 |
-
=========
|
3 |
-
|
4 |
-
.. versionadded:: 1.12.2
|
5 |
-
The ``first`` filter was added in Twig 1.12.2.
|
6 |
-
|
7 |
-
The ``first`` filter returns the first "element" of a sequence, a mapping, or
|
8 |
-
a string:
|
9 |
-
|
10 |
-
.. code-block:: jinja
|
11 |
-
|
12 |
-
{{ [1, 2, 3, 4]|first }}
|
13 |
-
{# outputs 1 #}
|
14 |
-
|
15 |
-
{{ { a: 1, b: 2, c: 3, d: 4 }|first }}
|
16 |
-
{# outputs 1 #}
|
17 |
-
|
18 |
-
{{ '1234'|first }}
|
19 |
-
{# outputs 1 #}
|
20 |
-
|
21 |
-
.. note::
|
22 |
-
|
23 |
-
It also works with objects implementing the `Traversable`_ interface.
|
24 |
-
|
25 |
-
.. _`Traversable`: http://php.net/manual/en/class.traversable.php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/format.rst
DELETED
@@ -1,16 +0,0 @@
|
|
1 |
-
``format``
|
2 |
-
==========
|
3 |
-
|
4 |
-
The ``format`` filter formats a given string by replacing the placeholders
|
5 |
-
(placeholders follows the `sprintf`_ notation):
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{{ "I like %s and %s."|format(foo, "bar") }}
|
10 |
-
|
11 |
-
{# outputs I like foo and bar
|
12 |
-
if the foo parameter equals to the foo string. #}
|
13 |
-
|
14 |
-
.. _`sprintf`: http://www.php.net/sprintf
|
15 |
-
|
16 |
-
.. seealso:: :doc:`replace<replace>`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/index.rst
DELETED
@@ -1,37 +0,0 @@
|
|
1 |
-
Filters
|
2 |
-
=======
|
3 |
-
|
4 |
-
.. toctree::
|
5 |
-
:maxdepth: 1
|
6 |
-
|
7 |
-
abs
|
8 |
-
batch
|
9 |
-
capitalize
|
10 |
-
convert_encoding
|
11 |
-
date
|
12 |
-
date_modify
|
13 |
-
default
|
14 |
-
escape
|
15 |
-
first
|
16 |
-
format
|
17 |
-
join
|
18 |
-
json_encode
|
19 |
-
keys
|
20 |
-
last
|
21 |
-
length
|
22 |
-
lower
|
23 |
-
merge
|
24 |
-
nl2br
|
25 |
-
number_format
|
26 |
-
raw
|
27 |
-
replace
|
28 |
-
reverse
|
29 |
-
round
|
30 |
-
slice
|
31 |
-
sort
|
32 |
-
split
|
33 |
-
striptags
|
34 |
-
title
|
35 |
-
trim
|
36 |
-
upper
|
37 |
-
url_encode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/join.rst
DELETED
@@ -1,23 +0,0 @@
|
|
1 |
-
``join``
|
2 |
-
========
|
3 |
-
|
4 |
-
The ``join`` filter returns a string which is the concatenation of the items
|
5 |
-
of a sequence:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{{ [1, 2, 3]|join }}
|
10 |
-
{# returns 123 #}
|
11 |
-
|
12 |
-
The separator between elements is an empty string per default, but you can
|
13 |
-
define it with the optional first parameter:
|
14 |
-
|
15 |
-
.. code-block:: jinja
|
16 |
-
|
17 |
-
{{ [1, 2, 3]|join('|') }}
|
18 |
-
{# outputs 1|2|3 #}
|
19 |
-
|
20 |
-
Arguments
|
21 |
-
---------
|
22 |
-
|
23 |
-
* ``glue``: The separator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/json_encode.rst
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
``json_encode``
|
2 |
-
===============
|
3 |
-
|
4 |
-
The ``json_encode`` filter returns the JSON representation of a value:
|
5 |
-
|
6 |
-
.. code-block:: jinja
|
7 |
-
|
8 |
-
{{ data|json_encode() }}
|
9 |
-
|
10 |
-
.. note::
|
11 |
-
|
12 |
-
Internally, Twig uses the PHP `json_encode`_ function.
|
13 |
-
|
14 |
-
Arguments
|
15 |
-
---------
|
16 |
-
|
17 |
-
* ``options``: A bitmask of `json_encode options`_ (``{{
|
18 |
-
data|json_encode(constant('JSON_PRETTY_PRINT')) }}``)
|
19 |
-
|
20 |
-
.. _`json_encode`: http://php.net/json_encode
|
21 |
-
.. _`json_encode options`: http://www.php.net/manual/en/json.constants.php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/keys.rst
DELETED
@@ -1,11 +0,0 @@
|
|
1 |
-
``keys``
|
2 |
-
========
|
3 |
-
|
4 |
-
The ``keys`` filter returns the keys of an array. It is useful when you want to
|
5 |
-
iterate over the keys of an array:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{% for key in array|keys %}
|
10 |
-
...
|
11 |
-
{% endfor %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/last.rst
DELETED
@@ -1,25 +0,0 @@
|
|
1 |
-
``last``
|
2 |
-
========
|
3 |
-
|
4 |
-
.. versionadded:: 1.12.2
|
5 |
-
The ``last`` filter was added in Twig 1.12.2.
|
6 |
-
|
7 |
-
The ``last`` filter returns the last "element" of a sequence, a mapping, or
|
8 |
-
a string:
|
9 |
-
|
10 |
-
.. code-block:: jinja
|
11 |
-
|
12 |
-
{{ [1, 2, 3, 4]|last }}
|
13 |
-
{# outputs 4 #}
|
14 |
-
|
15 |
-
{{ { a: 1, b: 2, c: 3, d: 4 }|last }}
|
16 |
-
{# outputs 4 #}
|
17 |
-
|
18 |
-
{{ '1234'|last }}
|
19 |
-
{# outputs 4 #}
|
20 |
-
|
21 |
-
.. note::
|
22 |
-
|
23 |
-
It also works with objects implementing the `Traversable`_ interface.
|
24 |
-
|
25 |
-
.. _`Traversable`: http://php.net/manual/en/class.traversable.php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/length.rst
DELETED
@@ -1,11 +0,0 @@
|
|
1 |
-
``length``
|
2 |
-
==========
|
3 |
-
|
4 |
-
The ``length`` filter returns the number of items of a sequence or mapping, or
|
5 |
-
the length of a string:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{% if users|length > 10 %}
|
10 |
-
...
|
11 |
-
{% endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/lower.rst
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
``lower``
|
2 |
-
=========
|
3 |
-
|
4 |
-
The ``lower`` filter converts a value to lowercase:
|
5 |
-
|
6 |
-
.. code-block:: jinja
|
7 |
-
|
8 |
-
{{ 'WELCOME'|lower }}
|
9 |
-
|
10 |
-
{# outputs 'welcome' #}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/merge.rst
DELETED
@@ -1,48 +0,0 @@
|
|
1 |
-
``merge``
|
2 |
-
=========
|
3 |
-
|
4 |
-
The ``merge`` filter merges an array with another array:
|
5 |
-
|
6 |
-
.. code-block:: jinja
|
7 |
-
|
8 |
-
{% set values = [1, 2] %}
|
9 |
-
|
10 |
-
{% set values = values|merge(['apple', 'orange']) %}
|
11 |
-
|
12 |
-
{# values now contains [1, 2, 'apple', 'orange'] #}
|
13 |
-
|
14 |
-
New values are added at the end of the existing ones.
|
15 |
-
|
16 |
-
The ``merge`` filter also works on hashes:
|
17 |
-
|
18 |
-
.. code-block:: jinja
|
19 |
-
|
20 |
-
{% set items = { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'unknown' } %}
|
21 |
-
|
22 |
-
{% set items = items|merge({ 'peugeot': 'car', 'renault': 'car' }) %}
|
23 |
-
|
24 |
-
{# items now contains { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car', 'renault': 'car' } #}
|
25 |
-
|
26 |
-
For hashes, the merging process occurs on the keys: if the key does not
|
27 |
-
already exist, it is added but if the key already exists, its value is
|
28 |
-
overridden.
|
29 |
-
|
30 |
-
.. tip::
|
31 |
-
|
32 |
-
If you want to ensure that some values are defined in an array (by given
|
33 |
-
default values), reverse the two elements in the call:
|
34 |
-
|
35 |
-
.. code-block:: jinja
|
36 |
-
|
37 |
-
{% set items = { 'apple': 'fruit', 'orange': 'fruit' } %}
|
38 |
-
|
39 |
-
{% set items = { 'apple': 'unknown' }|merge(items) %}
|
40 |
-
|
41 |
-
{# items now contains { 'apple': 'fruit', 'orange': 'fruit' } #}
|
42 |
-
|
43 |
-
.. note::
|
44 |
-
|
45 |
-
Internally, Twig uses the PHP `array_merge`_ function. It supports
|
46 |
-
Traversable objects by transforming those to arrays.
|
47 |
-
|
48 |
-
.. _`array_merge`: http://php.net/array_merge
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/nl2br.rst
DELETED
@@ -1,22 +0,0 @@
|
|
1 |
-
``nl2br``
|
2 |
-
=========
|
3 |
-
|
4 |
-
.. versionadded:: 1.5
|
5 |
-
The ``nl2br`` filter was added in Twig 1.5.
|
6 |
-
|
7 |
-
The ``nl2br`` filter inserts HTML line breaks before all newlines in a string:
|
8 |
-
|
9 |
-
.. code-block:: jinja
|
10 |
-
|
11 |
-
{{ "I like Twig.\nYou will like it too."|nl2br }}
|
12 |
-
{# outputs
|
13 |
-
|
14 |
-
I like Twig.<br />
|
15 |
-
You will like it too.
|
16 |
-
|
17 |
-
#}
|
18 |
-
|
19 |
-
.. note::
|
20 |
-
|
21 |
-
The ``nl2br`` filter pre-escapes the input before applying the
|
22 |
-
transformation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/number_format.rst
DELETED
@@ -1,48 +0,0 @@
|
|
1 |
-
``number_format``
|
2 |
-
=================
|
3 |
-
|
4 |
-
.. versionadded:: 1.5
|
5 |
-
The ``number_format`` filter was added in Twig 1.5
|
6 |
-
|
7 |
-
The ``number_format`` filter formats numbers. It is a wrapper around PHP's
|
8 |
-
`number_format`_ function:
|
9 |
-
|
10 |
-
.. code-block:: jinja
|
11 |
-
|
12 |
-
{{ 200.35|number_format }}
|
13 |
-
|
14 |
-
You can control the number of decimal places, decimal point, and thousands
|
15 |
-
separator using the additional arguments:
|
16 |
-
|
17 |
-
.. code-block:: jinja
|
18 |
-
|
19 |
-
{{ 9800.333|number_format(2, '.', ',') }}
|
20 |
-
|
21 |
-
If no formatting options are provided then Twig will use the default formatting
|
22 |
-
options of:
|
23 |
-
|
24 |
-
* 0 decimal places.
|
25 |
-
* ``.`` as the decimal point.
|
26 |
-
* ``,`` as the thousands separator.
|
27 |
-
|
28 |
-
These defaults can be easily changed through the core extension:
|
29 |
-
|
30 |
-
.. code-block:: php
|
31 |
-
|
32 |
-
$twig = new Twig_Environment($loader);
|
33 |
-
$twig->getExtension('Twig_Extension_Core')->setNumberFormat(3, '.', ',');
|
34 |
-
|
35 |
-
// before Twig 1.26
|
36 |
-
$twig->getExtension('core')->setNumberFormat(3, '.', ',');
|
37 |
-
|
38 |
-
The defaults set for ``number_format`` can be over-ridden upon each call using the
|
39 |
-
additional parameters.
|
40 |
-
|
41 |
-
Arguments
|
42 |
-
---------
|
43 |
-
|
44 |
-
* ``decimal``: The number of decimal points to display
|
45 |
-
* ``decimal_point``: The character(s) to use for the decimal point
|
46 |
-
* ``thousand_sep``: The character(s) to use for the thousands separator
|
47 |
-
|
48 |
-
.. _`number_format`: http://php.net/number_format
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/raw.rst
DELETED
@@ -1,36 +0,0 @@
|
|
1 |
-
``raw``
|
2 |
-
=======
|
3 |
-
|
4 |
-
The ``raw`` filter marks the value as being "safe", which means that in an
|
5 |
-
environment with automatic escaping enabled this variable will not be escaped
|
6 |
-
if ``raw`` is the last filter applied to it:
|
7 |
-
|
8 |
-
.. code-block:: jinja
|
9 |
-
|
10 |
-
{% autoescape %}
|
11 |
-
{{ var|raw }} {# var won't be escaped #}
|
12 |
-
{% endautoescape %}
|
13 |
-
|
14 |
-
.. note::
|
15 |
-
|
16 |
-
Be careful when using the ``raw`` filter inside expressions:
|
17 |
-
|
18 |
-
.. code-block:: jinja
|
19 |
-
|
20 |
-
{% autoescape %}
|
21 |
-
{% set hello = '<strong>Hello</strong>' %}
|
22 |
-
{% set hola = '<strong>Hola</strong>' %}
|
23 |
-
|
24 |
-
{{ false ? '<strong>Hola</strong>' : hello|raw }}
|
25 |
-
does not render the same as
|
26 |
-
{{ false ? hola : hello|raw }}
|
27 |
-
but renders the same as
|
28 |
-
{{ (false ? hola : hello)|raw }}
|
29 |
-
{% endautoescape %}
|
30 |
-
|
31 |
-
The first ternary statement is not escaped: ``hello`` is marked as being
|
32 |
-
safe and Twig does not escape static values (see
|
33 |
-
:doc:`escape<../tags/autoescape>`). In the second ternary statement, even
|
34 |
-
if ``hello`` is marked as safe, ``hola`` remains unsafe and so is the whole
|
35 |
-
expression. The third ternary statement is marked as safe and the result is
|
36 |
-
not escaped.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/replace.rst
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
``replace``
|
2 |
-
===========
|
3 |
-
|
4 |
-
The ``replace`` filter formats a given string by replacing the placeholders
|
5 |
-
(placeholders are free-form):
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{{ "I like %this% and %that%."|replace({'%this%': foo, '%that%': "bar"}) }}
|
10 |
-
|
11 |
-
{# outputs I like foo and bar
|
12 |
-
if the foo parameter equals to the foo string. #}
|
13 |
-
|
14 |
-
Arguments
|
15 |
-
---------
|
16 |
-
|
17 |
-
* ``replace_pairs``: The placeholder values
|
18 |
-
|
19 |
-
.. seealso:: :doc:`format<format>`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/reverse.rst
DELETED
@@ -1,47 +0,0 @@
|
|
1 |
-
``reverse``
|
2 |
-
===========
|
3 |
-
|
4 |
-
.. versionadded:: 1.6
|
5 |
-
Support for strings has been added in Twig 1.6.
|
6 |
-
|
7 |
-
The ``reverse`` filter reverses a sequence, a mapping, or a string:
|
8 |
-
|
9 |
-
.. code-block:: jinja
|
10 |
-
|
11 |
-
{% for user in users|reverse %}
|
12 |
-
...
|
13 |
-
{% endfor %}
|
14 |
-
|
15 |
-
{{ '1234'|reverse }}
|
16 |
-
|
17 |
-
{# outputs 4321 #}
|
18 |
-
|
19 |
-
.. tip::
|
20 |
-
|
21 |
-
For sequences and mappings, numeric keys are not preserved. To reverse
|
22 |
-
them as well, pass ``true`` as an argument to the ``reverse`` filter:
|
23 |
-
|
24 |
-
.. code-block:: jinja
|
25 |
-
|
26 |
-
{% for key, value in {1: "a", 2: "b", 3: "c"}|reverse %}
|
27 |
-
{{ key }}: {{ value }}
|
28 |
-
{%- endfor %}
|
29 |
-
|
30 |
-
{# output: 0: c 1: b 2: a #}
|
31 |
-
|
32 |
-
{% for key, value in {1: "a", 2: "b", 3: "c"}|reverse(true) %}
|
33 |
-
{{ key }}: {{ value }}
|
34 |
-
{%- endfor %}
|
35 |
-
|
36 |
-
{# output: 3: c 2: b 1: a #}
|
37 |
-
|
38 |
-
.. note::
|
39 |
-
|
40 |
-
It also works with objects implementing the `Traversable`_ interface.
|
41 |
-
|
42 |
-
Arguments
|
43 |
-
---------
|
44 |
-
|
45 |
-
* ``preserve_keys``: Preserve keys when reversing a mapping or a sequence.
|
46 |
-
|
47 |
-
.. _`Traversable`: http://php.net/Traversable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/round.rst
DELETED
@@ -1,37 +0,0 @@
|
|
1 |
-
``round``
|
2 |
-
=========
|
3 |
-
|
4 |
-
.. versionadded:: 1.15.0
|
5 |
-
The ``round`` filter was added in Twig 1.15.0.
|
6 |
-
|
7 |
-
The ``round`` filter rounds a number to a given precision:
|
8 |
-
|
9 |
-
.. code-block:: jinja
|
10 |
-
|
11 |
-
{{ 42.55|round }}
|
12 |
-
{# outputs 43 #}
|
13 |
-
|
14 |
-
{{ 42.55|round(1, 'floor') }}
|
15 |
-
{# outputs 42.5 #}
|
16 |
-
|
17 |
-
The ``round`` filter takes two optional arguments; the first one specifies the
|
18 |
-
precision (default is ``0``) and the second the rounding method (default is
|
19 |
-
``common``):
|
20 |
-
|
21 |
-
* ``common`` rounds either up or down (rounds the value up to precision decimal
|
22 |
-
places away from zero, when it is half way there -- making 1.5 into 2 and
|
23 |
-
-1.5 into -2);
|
24 |
-
|
25 |
-
* ``ceil`` always rounds up;
|
26 |
-
|
27 |
-
* ``floor`` always rounds down.
|
28 |
-
|
29 |
-
.. note::
|
30 |
-
|
31 |
-
The ``//`` operator is equivalent to ``|round(0, 'floor')``.
|
32 |
-
|
33 |
-
Arguments
|
34 |
-
---------
|
35 |
-
|
36 |
-
* ``precision``: The rounding precision
|
37 |
-
* ``method``: The rounding method
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/slice.rst
DELETED
@@ -1,71 +0,0 @@
|
|
1 |
-
``slice``
|
2 |
-
===========
|
3 |
-
|
4 |
-
.. versionadded:: 1.6
|
5 |
-
The ``slice`` filter was added in Twig 1.6.
|
6 |
-
|
7 |
-
The ``slice`` filter extracts a slice of a sequence, a mapping, or a string:
|
8 |
-
|
9 |
-
.. code-block:: jinja
|
10 |
-
|
11 |
-
{% for i in [1, 2, 3, 4, 5]|slice(1, 2) %}
|
12 |
-
{# will iterate over 2 and 3 #}
|
13 |
-
{% endfor %}
|
14 |
-
|
15 |
-
{{ '12345'|slice(1, 2) }}
|
16 |
-
|
17 |
-
{# outputs 23 #}
|
18 |
-
|
19 |
-
You can use any valid expression for both the start and the length:
|
20 |
-
|
21 |
-
.. code-block:: jinja
|
22 |
-
|
23 |
-
{% for i in [1, 2, 3, 4, 5]|slice(start, length) %}
|
24 |
-
{# ... #}
|
25 |
-
{% endfor %}
|
26 |
-
|
27 |
-
As syntactic sugar, you can also use the ``[]`` notation:
|
28 |
-
|
29 |
-
.. code-block:: jinja
|
30 |
-
|
31 |
-
{% for i in [1, 2, 3, 4, 5][start:length] %}
|
32 |
-
{# ... #}
|
33 |
-
{% endfor %}
|
34 |
-
|
35 |
-
{{ '12345'[1:2] }} {# will display "23" #}
|
36 |
-
|
37 |
-
{# you can omit the first argument -- which is the same as 0 #}
|
38 |
-
{{ '12345'[:2] }} {# will display "12" #}
|
39 |
-
|
40 |
-
{# you can omit the last argument -- which will select everything till the end #}
|
41 |
-
{{ '12345'[2:] }} {# will display "345" #}
|
42 |
-
|
43 |
-
The ``slice`` filter works as the `array_slice`_ PHP function for arrays and
|
44 |
-
`mb_substr`_ for strings with a fallback to `substr`_.
|
45 |
-
|
46 |
-
If the start is non-negative, the sequence will start at that start in the
|
47 |
-
variable. If start is negative, the sequence will start that far from the end
|
48 |
-
of the variable.
|
49 |
-
|
50 |
-
If length is given and is positive, then the sequence will have up to that
|
51 |
-
many elements in it. If the variable is shorter than the length, then only the
|
52 |
-
available variable elements will be present. If length is given and is
|
53 |
-
negative then the sequence will stop that many elements from the end of the
|
54 |
-
variable. If it is omitted, then the sequence will have everything from offset
|
55 |
-
up until the end of the variable.
|
56 |
-
|
57 |
-
.. note::
|
58 |
-
|
59 |
-
It also works with objects implementing the `Traversable`_ interface.
|
60 |
-
|
61 |
-
Arguments
|
62 |
-
---------
|
63 |
-
|
64 |
-
* ``start``: The start of the slice
|
65 |
-
* ``length``: The size of the slice
|
66 |
-
* ``preserve_keys``: Whether to preserve key or not (when the input is an array)
|
67 |
-
|
68 |
-
.. _`Traversable`: http://php.net/manual/en/class.traversable.php
|
69 |
-
.. _`array_slice`: http://php.net/array_slice
|
70 |
-
.. _`mb_substr` : http://php.net/mb-substr
|
71 |
-
.. _`substr`: http://php.net/substr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/sort.rst
DELETED
@@ -1,18 +0,0 @@
|
|
1 |
-
``sort``
|
2 |
-
========
|
3 |
-
|
4 |
-
The ``sort`` filter sorts an array:
|
5 |
-
|
6 |
-
.. code-block:: jinja
|
7 |
-
|
8 |
-
{% for user in users|sort %}
|
9 |
-
...
|
10 |
-
{% endfor %}
|
11 |
-
|
12 |
-
.. note::
|
13 |
-
|
14 |
-
Internally, Twig uses the PHP `asort`_ function to maintain index
|
15 |
-
association. It supports Traversable objects by transforming
|
16 |
-
those to arrays.
|
17 |
-
|
18 |
-
.. _`asort`: http://php.net/asort
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/split.rst
DELETED
@@ -1,53 +0,0 @@
|
|
1 |
-
``split``
|
2 |
-
=========
|
3 |
-
|
4 |
-
.. versionadded:: 1.10.3
|
5 |
-
The ``split`` filter was added in Twig 1.10.3.
|
6 |
-
|
7 |
-
The ``split`` filter splits a string by the given delimiter and returns a list
|
8 |
-
of strings:
|
9 |
-
|
10 |
-
.. code-block:: jinja
|
11 |
-
|
12 |
-
{% set foo = "one,two,three"|split(',') %}
|
13 |
-
{# foo contains ['one', 'two', 'three'] #}
|
14 |
-
|
15 |
-
You can also pass a ``limit`` argument:
|
16 |
-
|
17 |
-
* If ``limit`` is positive, the returned array will contain a maximum of
|
18 |
-
limit elements with the last element containing the rest of string;
|
19 |
-
|
20 |
-
* If ``limit`` is negative, all components except the last -limit are
|
21 |
-
returned;
|
22 |
-
|
23 |
-
* If ``limit`` is zero, then this is treated as 1.
|
24 |
-
|
25 |
-
.. code-block:: jinja
|
26 |
-
|
27 |
-
{% set foo = "one,two,three,four,five"|split(',', 3) %}
|
28 |
-
{# foo contains ['one', 'two', 'three,four,five'] #}
|
29 |
-
|
30 |
-
If the ``delimiter`` is an empty string, then value will be split by equal
|
31 |
-
chunks. Length is set by the ``limit`` argument (one character by default).
|
32 |
-
|
33 |
-
.. code-block:: jinja
|
34 |
-
|
35 |
-
{% set foo = "123"|split('') %}
|
36 |
-
{# foo contains ['1', '2', '3'] #}
|
37 |
-
|
38 |
-
{% set bar = "aabbcc"|split('', 2) %}
|
39 |
-
{# bar contains ['aa', 'bb', 'cc'] #}
|
40 |
-
|
41 |
-
.. note::
|
42 |
-
|
43 |
-
Internally, Twig uses the PHP `explode`_ or `str_split`_ (if delimiter is
|
44 |
-
empty) functions for string splitting.
|
45 |
-
|
46 |
-
Arguments
|
47 |
-
---------
|
48 |
-
|
49 |
-
* ``delimiter``: The delimiter
|
50 |
-
* ``limit``: The limit argument
|
51 |
-
|
52 |
-
.. _`explode`: http://php.net/explode
|
53 |
-
.. _`str_split`: http://php.net/str_split
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/striptags.rst
DELETED
@@ -1,15 +0,0 @@
|
|
1 |
-
``striptags``
|
2 |
-
=============
|
3 |
-
|
4 |
-
The ``striptags`` filter strips SGML/XML tags and replace adjacent whitespace
|
5 |
-
by one space:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{{ some_html|striptags }}
|
10 |
-
|
11 |
-
.. note::
|
12 |
-
|
13 |
-
Internally, Twig uses the PHP `strip_tags`_ function.
|
14 |
-
|
15 |
-
.. _`strip_tags`: http://php.net/strip_tags
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/title.rst
DELETED
@@ -1,11 +0,0 @@
|
|
1 |
-
``title``
|
2 |
-
=========
|
3 |
-
|
4 |
-
The ``title`` filter returns a titlecased version of the value. Words will
|
5 |
-
start with uppercase letters, all remaining characters are lowercase:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{{ 'my first car'|title }}
|
10 |
-
|
11 |
-
{# outputs 'My First Car' #}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/trim.rst
DELETED
@@ -1,29 +0,0 @@
|
|
1 |
-
``trim``
|
2 |
-
========
|
3 |
-
|
4 |
-
.. versionadded:: 1.6.2
|
5 |
-
The ``trim`` filter was added in Twig 1.6.2.
|
6 |
-
|
7 |
-
The ``trim`` filter strips whitespace (or other characters) from the beginning
|
8 |
-
and end of a string:
|
9 |
-
|
10 |
-
.. code-block:: jinja
|
11 |
-
|
12 |
-
{{ ' I like Twig. '|trim }}
|
13 |
-
|
14 |
-
{# outputs 'I like Twig.' #}
|
15 |
-
|
16 |
-
{{ ' I like Twig.'|trim('.') }}
|
17 |
-
|
18 |
-
{# outputs ' I like Twig' #}
|
19 |
-
|
20 |
-
.. note::
|
21 |
-
|
22 |
-
Internally, Twig uses the PHP `trim`_ function.
|
23 |
-
|
24 |
-
Arguments
|
25 |
-
---------
|
26 |
-
|
27 |
-
* ``character_mask``: The characters to strip
|
28 |
-
|
29 |
-
.. _`trim`: http://php.net/trim
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/upper.rst
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
``upper``
|
2 |
-
=========
|
3 |
-
|
4 |
-
The ``upper`` filter converts a value to uppercase:
|
5 |
-
|
6 |
-
.. code-block:: jinja
|
7 |
-
|
8 |
-
{{ 'welcome'|upper }}
|
9 |
-
|
10 |
-
{# outputs 'WELCOME' #}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/filters/url_encode.rst
DELETED
@@ -1,34 +0,0 @@
|
|
1 |
-
``url_encode``
|
2 |
-
==============
|
3 |
-
|
4 |
-
.. versionadded:: 1.12.3
|
5 |
-
Support for encoding an array as query string was added in Twig 1.12.3.
|
6 |
-
|
7 |
-
.. versionadded:: 1.16.0
|
8 |
-
The ``raw`` argument was removed in Twig 1.16.0. Twig now always encodes
|
9 |
-
according to RFC 3986.
|
10 |
-
|
11 |
-
The ``url_encode`` filter percent encodes a given string as URL segment
|
12 |
-
or an array as query string:
|
13 |
-
|
14 |
-
.. code-block:: jinja
|
15 |
-
|
16 |
-
{{ "path-seg*ment"|url_encode }}
|
17 |
-
{# outputs "path-seg%2Ament" #}
|
18 |
-
|
19 |
-
{{ "string with spaces"|url_encode }}
|
20 |
-
{# outputs "string%20with%20spaces" #}
|
21 |
-
|
22 |
-
{{ {'param': 'value', 'foo': 'bar'}|url_encode }}
|
23 |
-
{# outputs "param=value&foo=bar" #}
|
24 |
-
|
25 |
-
.. note::
|
26 |
-
|
27 |
-
Internally, Twig uses the PHP `urlencode`_ (or `rawurlencode`_ if you pass
|
28 |
-
``true`` as the first parameter) or the `http_build_query`_ function. Note
|
29 |
-
that as of Twig 1.16.0, ``urlencode`` **always** uses ``rawurlencode`` (the
|
30 |
-
``raw`` argument was removed.)
|
31 |
-
|
32 |
-
.. _`urlencode`: http://php.net/urlencode
|
33 |
-
.. _`rawurlencode`: http://php.net/rawurlencode
|
34 |
-
.. _`http_build_query`: http://php.net/http_build_query
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/attribute.rst
DELETED
@@ -1,26 +0,0 @@
|
|
1 |
-
``attribute``
|
2 |
-
=============
|
3 |
-
|
4 |
-
.. versionadded:: 1.2
|
5 |
-
The ``attribute`` function was added in Twig 1.2.
|
6 |
-
|
7 |
-
The ``attribute`` function can be used to access a "dynamic" attribute of a
|
8 |
-
variable:
|
9 |
-
|
10 |
-
.. code-block:: jinja
|
11 |
-
|
12 |
-
{{ attribute(object, method) }}
|
13 |
-
{{ attribute(object, method, arguments) }}
|
14 |
-
{{ attribute(array, item) }}
|
15 |
-
|
16 |
-
In addition, the ``defined`` test can check for the existence of a dynamic
|
17 |
-
attribute:
|
18 |
-
|
19 |
-
.. code-block:: jinja
|
20 |
-
|
21 |
-
{{ attribute(object, method) is defined ? 'Method exists' : 'Method does not exist' }}
|
22 |
-
|
23 |
-
.. note::
|
24 |
-
|
25 |
-
The resolution algorithm is the same as the one used for the ``.``
|
26 |
-
notation, except that the item can be any valid expression.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/block.rst
DELETED
@@ -1,41 +0,0 @@
|
|
1 |
-
``block``
|
2 |
-
=========
|
3 |
-
|
4 |
-
.. versionadded: 1.28
|
5 |
-
Using ``block`` with the ``defined`` test was added in Twig 1.28.
|
6 |
-
|
7 |
-
.. versionadded: 1.28
|
8 |
-
Support for the template argument was added in Twig 1.28.
|
9 |
-
|
10 |
-
When a template uses inheritance and if you want to print a block multiple
|
11 |
-
times, use the ``block`` function:
|
12 |
-
|
13 |
-
.. code-block:: jinja
|
14 |
-
|
15 |
-
<title>{% block title %}{% endblock %}</title>
|
16 |
-
|
17 |
-
<h1>{{ block('title') }}</h1>
|
18 |
-
|
19 |
-
{% block body %}{% endblock %}
|
20 |
-
|
21 |
-
The ``block`` function can also be used to display one block of another
|
22 |
-
template:
|
23 |
-
|
24 |
-
.. code-block:: jinja
|
25 |
-
|
26 |
-
{{ block("title", "common_blocks.twig") }}
|
27 |
-
|
28 |
-
Use the ``defined`` test to check if a block exists in the context of the
|
29 |
-
current template:
|
30 |
-
|
31 |
-
.. code-block:: jinja
|
32 |
-
|
33 |
-
{% if block("footer") is defined %}
|
34 |
-
...
|
35 |
-
{% endif %}
|
36 |
-
|
37 |
-
{% if block("footer", "common_blocks.twig") is defined %}
|
38 |
-
...
|
39 |
-
{% endif %}
|
40 |
-
|
41 |
-
.. seealso:: :doc:`extends<../tags/extends>`, :doc:`parent<../functions/parent>`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/constant.rst
DELETED
@@ -1,29 +0,0 @@
|
|
1 |
-
``constant``
|
2 |
-
============
|
3 |
-
|
4 |
-
.. versionadded: 1.12.1
|
5 |
-
constant now accepts object instances as the second argument.
|
6 |
-
|
7 |
-
.. versionadded: 1.28
|
8 |
-
Using ``constant`` with the ``defined`` test was added in Twig 1.28.
|
9 |
-
|
10 |
-
``constant`` returns the constant value for a given string:
|
11 |
-
|
12 |
-
.. code-block:: jinja
|
13 |
-
|
14 |
-
{{ some_date|date(constant('DATE_W3C')) }}
|
15 |
-
{{ constant('Namespace\\Classname::CONSTANT_NAME') }}
|
16 |
-
|
17 |
-
As of 1.12.1 you can read constants from object instances as well:
|
18 |
-
|
19 |
-
.. code-block:: jinja
|
20 |
-
|
21 |
-
{{ constant('RSS', date) }}
|
22 |
-
|
23 |
-
Use the ``defined`` test to check if a constant is defined:
|
24 |
-
|
25 |
-
.. code-block:: jinja
|
26 |
-
|
27 |
-
{% if constant('SOME_CONST') is defined %}
|
28 |
-
...
|
29 |
-
{% endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/cycle.rst
DELETED
@@ -1,28 +0,0 @@
|
|
1 |
-
``cycle``
|
2 |
-
=========
|
3 |
-
|
4 |
-
The ``cycle`` function cycles on an array of values:
|
5 |
-
|
6 |
-
.. code-block:: jinja
|
7 |
-
|
8 |
-
{% set start_year = date() | date('Y') %}
|
9 |
-
{% set end_year = start_year + 5 %}
|
10 |
-
|
11 |
-
{% for year in start_year..end_year %}
|
12 |
-
{{ cycle(['odd', 'even'], loop.index0) }}
|
13 |
-
{% endfor %}
|
14 |
-
|
15 |
-
The array can contain any number of values:
|
16 |
-
|
17 |
-
.. code-block:: jinja
|
18 |
-
|
19 |
-
{% set fruits = ['apple', 'orange', 'citrus'] %}
|
20 |
-
|
21 |
-
{% for i in 0..10 %}
|
22 |
-
{{ cycle(fruits, i) }}
|
23 |
-
{% endfor %}
|
24 |
-
|
25 |
-
Arguments
|
26 |
-
---------
|
27 |
-
|
28 |
-
* ``position``: The cycle position
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/date.rst
DELETED
@@ -1,55 +0,0 @@
|
|
1 |
-
``date``
|
2 |
-
========
|
3 |
-
|
4 |
-
.. versionadded:: 1.6
|
5 |
-
The date function has been added in Twig 1.6.
|
6 |
-
|
7 |
-
.. versionadded:: 1.6.1
|
8 |
-
The default timezone support has been added in Twig 1.6.1.
|
9 |
-
|
10 |
-
Converts an argument to a date to allow date comparison:
|
11 |
-
|
12 |
-
.. code-block:: jinja
|
13 |
-
|
14 |
-
{% if date(user.created_at) < date('-2days') %}
|
15 |
-
{# do something #}
|
16 |
-
{% endif %}
|
17 |
-
|
18 |
-
The argument must be in one of PHP’s supported `date and time formats`_.
|
19 |
-
|
20 |
-
You can pass a timezone as the second argument:
|
21 |
-
|
22 |
-
.. code-block:: jinja
|
23 |
-
|
24 |
-
{% if date(user.created_at) < date('-2days', 'Europe/Paris') %}
|
25 |
-
{# do something #}
|
26 |
-
{% endif %}
|
27 |
-
|
28 |
-
If no argument is passed, the function returns the current date:
|
29 |
-
|
30 |
-
.. code-block:: jinja
|
31 |
-
|
32 |
-
{% if date(user.created_at) < date() %}
|
33 |
-
{# always! #}
|
34 |
-
{% endif %}
|
35 |
-
|
36 |
-
.. note::
|
37 |
-
|
38 |
-
You can set the default timezone globally by calling ``setTimezone()`` on
|
39 |
-
the ``core`` extension instance:
|
40 |
-
|
41 |
-
.. code-block:: php
|
42 |
-
|
43 |
-
$twig = new Twig_Environment($loader);
|
44 |
-
$twig->getExtension('Twig_Extension_Core')->setTimezone('Europe/Paris');
|
45 |
-
|
46 |
-
// before Twig 1.26
|
47 |
-
$twig->getExtension('core')->setTimezone('Europe/Paris');
|
48 |
-
|
49 |
-
Arguments
|
50 |
-
---------
|
51 |
-
|
52 |
-
* ``date``: The date
|
53 |
-
* ``timezone``: The timezone
|
54 |
-
|
55 |
-
.. _`date and time formats`: http://php.net/manual/en/datetime.formats.php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/dump.rst
DELETED
@@ -1,69 +0,0 @@
|
|
1 |
-
``dump``
|
2 |
-
========
|
3 |
-
|
4 |
-
.. versionadded:: 1.5
|
5 |
-
The ``dump`` function was added in Twig 1.5.
|
6 |
-
|
7 |
-
The ``dump`` function dumps information about a template variable. This is
|
8 |
-
mostly useful to debug a template that does not behave as expected by
|
9 |
-
introspecting its variables:
|
10 |
-
|
11 |
-
.. code-block:: jinja
|
12 |
-
|
13 |
-
{{ dump(user) }}
|
14 |
-
|
15 |
-
.. note::
|
16 |
-
|
17 |
-
The ``dump`` function is not available by default. You must add the
|
18 |
-
``Twig_Extension_Debug`` extension explicitly when creating your Twig
|
19 |
-
environment::
|
20 |
-
|
21 |
-
$twig = new Twig_Environment($loader, array(
|
22 |
-
'debug' => true,
|
23 |
-
// ...
|
24 |
-
));
|
25 |
-
$twig->addExtension(new Twig_Extension_Debug());
|
26 |
-
|
27 |
-
Even when enabled, the ``dump`` function won't display anything if the
|
28 |
-
``debug`` option on the environment is not enabled (to avoid leaking debug
|
29 |
-
information on a production server).
|
30 |
-
|
31 |
-
In an HTML context, wrap the output with a ``pre`` tag to make it easier to
|
32 |
-
read:
|
33 |
-
|
34 |
-
.. code-block:: jinja
|
35 |
-
|
36 |
-
<pre>
|
37 |
-
{{ dump(user) }}
|
38 |
-
</pre>
|
39 |
-
|
40 |
-
.. tip::
|
41 |
-
|
42 |
-
Using a ``pre`` tag is not needed when `XDebug`_ is enabled and
|
43 |
-
``html_errors`` is ``on``; as a bonus, the output is also nicer with
|
44 |
-
XDebug enabled.
|
45 |
-
|
46 |
-
You can debug several variables by passing them as additional arguments:
|
47 |
-
|
48 |
-
.. code-block:: jinja
|
49 |
-
|
50 |
-
{{ dump(user, categories) }}
|
51 |
-
|
52 |
-
If you don't pass any value, all variables from the current context are
|
53 |
-
dumped:
|
54 |
-
|
55 |
-
.. code-block:: jinja
|
56 |
-
|
57 |
-
{{ dump() }}
|
58 |
-
|
59 |
-
.. note::
|
60 |
-
|
61 |
-
Internally, Twig uses the PHP `var_dump`_ function.
|
62 |
-
|
63 |
-
Arguments
|
64 |
-
---------
|
65 |
-
|
66 |
-
* ``context``: The context to dump
|
67 |
-
|
68 |
-
.. _`XDebug`: http://xdebug.org/docs/display
|
69 |
-
.. _`var_dump`: http://php.net/var_dump
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/include.rst
DELETED
@@ -1,84 +0,0 @@
|
|
1 |
-
``include``
|
2 |
-
===========
|
3 |
-
|
4 |
-
.. versionadded:: 1.12
|
5 |
-
The ``include`` function was added in Twig 1.12.
|
6 |
-
|
7 |
-
The ``include`` function returns the rendered content of a template:
|
8 |
-
|
9 |
-
.. code-block:: jinja
|
10 |
-
|
11 |
-
{{ include('template.html') }}
|
12 |
-
{{ include(some_var) }}
|
13 |
-
|
14 |
-
Included templates have access to the variables of the active context.
|
15 |
-
|
16 |
-
If you are using the filesystem loader, the templates are looked for in the
|
17 |
-
paths defined by it.
|
18 |
-
|
19 |
-
The context is passed by default to the template but you can also pass
|
20 |
-
additional variables:
|
21 |
-
|
22 |
-
.. code-block:: jinja
|
23 |
-
|
24 |
-
{# template.html will have access to the variables from the current context and the additional ones provided #}
|
25 |
-
{{ include('template.html', {foo: 'bar'}) }}
|
26 |
-
|
27 |
-
You can disable access to the context by setting ``with_context`` to
|
28 |
-
``false``:
|
29 |
-
|
30 |
-
.. code-block:: jinja
|
31 |
-
|
32 |
-
{# only the foo variable will be accessible #}
|
33 |
-
{{ include('template.html', {foo: 'bar'}, with_context = false) }}
|
34 |
-
|
35 |
-
.. code-block:: jinja
|
36 |
-
|
37 |
-
{# no variables will be accessible #}
|
38 |
-
{{ include('template.html', with_context = false) }}
|
39 |
-
|
40 |
-
And if the expression evaluates to a ``Twig_Template`` or a
|
41 |
-
``Twig_TemplateWrapper`` instance, Twig will use it directly::
|
42 |
-
|
43 |
-
// {{ include(template) }}
|
44 |
-
|
45 |
-
// deprecated as of Twig 1.28
|
46 |
-
$template = $twig->loadTemplate('some_template.twig');
|
47 |
-
|
48 |
-
// as of Twig 1.28
|
49 |
-
$template = $twig->load('some_template.twig');
|
50 |
-
|
51 |
-
$twig->display('template.twig', array('template' => $template));
|
52 |
-
|
53 |
-
When you set the ``ignore_missing`` flag, Twig will return an empty string if
|
54 |
-
the template does not exist:
|
55 |
-
|
56 |
-
.. code-block:: jinja
|
57 |
-
|
58 |
-
{{ include('sidebar.html', ignore_missing = true) }}
|
59 |
-
|
60 |
-
You can also provide a list of templates that are checked for existence before
|
61 |
-
inclusion. The first template that exists will be rendered:
|
62 |
-
|
63 |
-
.. code-block:: jinja
|
64 |
-
|
65 |
-
{{ include(['page_detailed.html', 'page.html']) }}
|
66 |
-
|
67 |
-
If ``ignore_missing`` is set, it will fall back to rendering nothing if none
|
68 |
-
of the templates exist, otherwise it will throw an exception.
|
69 |
-
|
70 |
-
When including a template created by an end user, you should consider
|
71 |
-
sandboxing it:
|
72 |
-
|
73 |
-
.. code-block:: jinja
|
74 |
-
|
75 |
-
{{ include('page.html', sandboxed = true) }}
|
76 |
-
|
77 |
-
Arguments
|
78 |
-
---------
|
79 |
-
|
80 |
-
* ``template``: The template to render
|
81 |
-
* ``variables``: The variables to pass to the template
|
82 |
-
* ``with_context``: Whether to pass the current context variables or not
|
83 |
-
* ``ignore_missing``: Whether to ignore missing templates or not
|
84 |
-
* ``sandboxed``: Whether to sandbox the template or not
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/index.rst
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
Functions
|
2 |
-
=========
|
3 |
-
|
4 |
-
.. toctree::
|
5 |
-
:maxdepth: 1
|
6 |
-
|
7 |
-
attribute
|
8 |
-
block
|
9 |
-
constant
|
10 |
-
cycle
|
11 |
-
date
|
12 |
-
dump
|
13 |
-
include
|
14 |
-
max
|
15 |
-
min
|
16 |
-
parent
|
17 |
-
random
|
18 |
-
range
|
19 |
-
source
|
20 |
-
template_from_string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/max.rst
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
``max``
|
2 |
-
=======
|
3 |
-
|
4 |
-
.. versionadded:: 1.15
|
5 |
-
The ``max`` function was added in Twig 1.15.
|
6 |
-
|
7 |
-
``max`` returns the biggest value of a sequence or a set of values:
|
8 |
-
|
9 |
-
.. code-block:: jinja
|
10 |
-
|
11 |
-
{{ max(1, 3, 2) }}
|
12 |
-
{{ max([1, 3, 2]) }}
|
13 |
-
|
14 |
-
When called with a mapping, max ignores keys and only compares values:
|
15 |
-
|
16 |
-
.. code-block:: jinja
|
17 |
-
|
18 |
-
{{ max({2: "e", 1: "a", 3: "b", 5: "d", 4: "c"}) }}
|
19 |
-
{# returns "e" #}
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/min.rst
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
``min``
|
2 |
-
=======
|
3 |
-
|
4 |
-
.. versionadded:: 1.15
|
5 |
-
The ``min`` function was added in Twig 1.15.
|
6 |
-
|
7 |
-
``min`` returns the lowest value of a sequence or a set of values:
|
8 |
-
|
9 |
-
.. code-block:: jinja
|
10 |
-
|
11 |
-
{{ min(1, 3, 2) }}
|
12 |
-
{{ min([1, 3, 2]) }}
|
13 |
-
|
14 |
-
When called with a mapping, min ignores keys and only compares values:
|
15 |
-
|
16 |
-
.. code-block:: jinja
|
17 |
-
|
18 |
-
{{ min({2: "e", 3: "a", 1: "b", 5: "d", 4: "c"}) }}
|
19 |
-
{# returns "a" #}
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/parent.rst
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
``parent``
|
2 |
-
==========
|
3 |
-
|
4 |
-
When a template uses inheritance, it's possible to render the contents of the
|
5 |
-
parent block when overriding a block by using the ``parent`` function:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{% extends "base.html" %}
|
10 |
-
|
11 |
-
{% block sidebar %}
|
12 |
-
<h3>Table Of Contents</h3>
|
13 |
-
...
|
14 |
-
{{ parent() }}
|
15 |
-
{% endblock %}
|
16 |
-
|
17 |
-
The ``parent()`` call will return the content of the ``sidebar`` block as
|
18 |
-
defined in the ``base.html`` template.
|
19 |
-
|
20 |
-
.. seealso:: :doc:`extends<../tags/extends>`, :doc:`block<../functions/block>`, :doc:`block<../tags/block>`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/random.rst
DELETED
@@ -1,29 +0,0 @@
|
|
1 |
-
``random``
|
2 |
-
==========
|
3 |
-
|
4 |
-
.. versionadded:: 1.5
|
5 |
-
The ``random`` function was added in Twig 1.5.
|
6 |
-
|
7 |
-
.. versionadded:: 1.6
|
8 |
-
String and integer handling was added in Twig 1.6.
|
9 |
-
|
10 |
-
The ``random`` function returns a random value depending on the supplied
|
11 |
-
parameter type:
|
12 |
-
|
13 |
-
* a random item from a sequence;
|
14 |
-
* a random character from a string;
|
15 |
-
* a random integer between 0 and the integer parameter (inclusive).
|
16 |
-
|
17 |
-
.. code-block:: jinja
|
18 |
-
|
19 |
-
{{ random(['apple', 'orange', 'citrus']) }} {# example output: orange #}
|
20 |
-
{{ random('ABC') }} {# example output: C #}
|
21 |
-
{{ random() }} {# example output: 15386094 (works as the native PHP mt_rand function) #}
|
22 |
-
{{ random(5) }} {# example output: 3 #}
|
23 |
-
|
24 |
-
Arguments
|
25 |
-
---------
|
26 |
-
|
27 |
-
* ``values``: The values
|
28 |
-
|
29 |
-
.. _`mt_rand`: http://php.net/mt_rand
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/range.rst
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
``range``
|
2 |
-
=========
|
3 |
-
|
4 |
-
Returns a list containing an arithmetic progression of integers:
|
5 |
-
|
6 |
-
.. code-block:: jinja
|
7 |
-
|
8 |
-
{% for i in range(0, 3) %}
|
9 |
-
{{ i }},
|
10 |
-
{% endfor %}
|
11 |
-
|
12 |
-
{# outputs 0, 1, 2, 3, #}
|
13 |
-
|
14 |
-
When step is given (as the third parameter), it specifies the increment (or
|
15 |
-
decrement):
|
16 |
-
|
17 |
-
.. code-block:: jinja
|
18 |
-
|
19 |
-
{% for i in range(0, 6, 2) %}
|
20 |
-
{{ i }},
|
21 |
-
{% endfor %}
|
22 |
-
|
23 |
-
{# outputs 0, 2, 4, 6, #}
|
24 |
-
|
25 |
-
The Twig built-in ``..`` operator is just syntactic sugar for the ``range``
|
26 |
-
function (with a step of 1):
|
27 |
-
|
28 |
-
.. code-block:: jinja
|
29 |
-
|
30 |
-
{% for i in 0..3 %}
|
31 |
-
{{ i }},
|
32 |
-
{% endfor %}
|
33 |
-
|
34 |
-
.. tip::
|
35 |
-
|
36 |
-
The ``range`` function works as the native PHP `range`_ function.
|
37 |
-
|
38 |
-
Arguments
|
39 |
-
---------
|
40 |
-
|
41 |
-
* ``low``: The first value of the sequence.
|
42 |
-
* ``high``: The highest possible value of the sequence.
|
43 |
-
* ``step``: The increment between elements of the sequence.
|
44 |
-
|
45 |
-
.. _`range`: http://php.net/range
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/source.rst
DELETED
@@ -1,32 +0,0 @@
|
|
1 |
-
``source``
|
2 |
-
==========
|
3 |
-
|
4 |
-
.. versionadded:: 1.15
|
5 |
-
The ``source`` function was added in Twig 1.15.
|
6 |
-
|
7 |
-
.. versionadded:: 1.18.3
|
8 |
-
The ``ignore_missing`` flag was added in Twig 1.18.3.
|
9 |
-
|
10 |
-
The ``source`` function returns the content of a template without rendering it:
|
11 |
-
|
12 |
-
.. code-block:: jinja
|
13 |
-
|
14 |
-
{{ source('template.html') }}
|
15 |
-
{{ source(some_var) }}
|
16 |
-
|
17 |
-
When you set the ``ignore_missing`` flag, Twig will return an empty string if
|
18 |
-
the template does not exist:
|
19 |
-
|
20 |
-
.. code-block:: jinja
|
21 |
-
|
22 |
-
{{ source('template.html', ignore_missing = true) }}
|
23 |
-
|
24 |
-
The function uses the same template loaders as the ones used to include
|
25 |
-
templates. So, if you are using the filesystem loader, the templates are looked
|
26 |
-
for in the paths defined by it.
|
27 |
-
|
28 |
-
Arguments
|
29 |
-
---------
|
30 |
-
|
31 |
-
* ``name``: The name of the template to read
|
32 |
-
* ``ignore_missing``: Whether to ignore missing templates or not
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/functions/template_from_string.rst
DELETED
@@ -1,32 +0,0 @@
|
|
1 |
-
``template_from_string``
|
2 |
-
========================
|
3 |
-
|
4 |
-
.. versionadded:: 1.11
|
5 |
-
The ``template_from_string`` function was added in Twig 1.11.
|
6 |
-
|
7 |
-
The ``template_from_string`` function loads a template from a string:
|
8 |
-
|
9 |
-
.. code-block:: jinja
|
10 |
-
|
11 |
-
{{ include(template_from_string("Hello {{ name }}")) }}
|
12 |
-
{{ include(template_from_string(page.template)) }}
|
13 |
-
|
14 |
-
.. note::
|
15 |
-
|
16 |
-
The ``template_from_string`` function is not available by default. You
|
17 |
-
must add the ``Twig_Extension_StringLoader`` extension explicitly when
|
18 |
-
creating your Twig environment::
|
19 |
-
|
20 |
-
$twig = new Twig_Environment(...);
|
21 |
-
$twig->addExtension(new Twig_Extension_StringLoader());
|
22 |
-
|
23 |
-
.. note::
|
24 |
-
|
25 |
-
Even if you will probably always use the ``template_from_string`` function
|
26 |
-
with the ``include`` function, you can use it with any tag or function that
|
27 |
-
takes a template as an argument (like the ``embed`` or ``extends`` tags).
|
28 |
-
|
29 |
-
Arguments
|
30 |
-
---------
|
31 |
-
|
32 |
-
* ``template``: The template
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/index.rst
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
Twig
|
2 |
-
====
|
3 |
-
|
4 |
-
.. toctree::
|
5 |
-
:maxdepth: 2
|
6 |
-
|
7 |
-
intro
|
8 |
-
installation
|
9 |
-
templates
|
10 |
-
api
|
11 |
-
advanced
|
12 |
-
internals
|
13 |
-
deprecated
|
14 |
-
recipes
|
15 |
-
coding_standards
|
16 |
-
tags/index
|
17 |
-
filters/index
|
18 |
-
functions/index
|
19 |
-
tests/index
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/installation.rst
DELETED
@@ -1,116 +0,0 @@
|
|
1 |
-
Installation
|
2 |
-
============
|
3 |
-
|
4 |
-
You have multiple ways to install Twig.
|
5 |
-
|
6 |
-
Installing the Twig PHP package
|
7 |
-
-------------------------------
|
8 |
-
|
9 |
-
Installing via Composer (recommended)
|
10 |
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
11 |
-
|
12 |
-
Install `Composer`_ and run the following command to get the latest version:
|
13 |
-
|
14 |
-
.. code-block:: bash
|
15 |
-
|
16 |
-
composer require twig/twig:~1.0
|
17 |
-
|
18 |
-
Installing from the tarball release
|
19 |
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
20 |
-
|
21 |
-
1. Download the most recent tarball from the `download page`_
|
22 |
-
2. Verify the integrity of the tarball http://fabien.potencier.org/article/73/signing-project-releases
|
23 |
-
3. Unpack the tarball
|
24 |
-
4. Move the files somewhere in your project
|
25 |
-
|
26 |
-
Installing the development version
|
27 |
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
28 |
-
|
29 |
-
.. code-block:: bash
|
30 |
-
|
31 |
-
git clone git://github.com/twigphp/Twig.git
|
32 |
-
|
33 |
-
Installing the PEAR package
|
34 |
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
35 |
-
|
36 |
-
.. note::
|
37 |
-
|
38 |
-
Using PEAR for installing Twig is deprecated and Twig 1.15.1 was the last
|
39 |
-
version published on the PEAR channel; use Composer instead.
|
40 |
-
|
41 |
-
.. code-block:: bash
|
42 |
-
|
43 |
-
pear channel-discover pear.twig-project.org
|
44 |
-
pear install twig/Twig
|
45 |
-
|
46 |
-
Installing the C extension
|
47 |
-
--------------------------
|
48 |
-
|
49 |
-
.. versionadded:: 1.4
|
50 |
-
The C extension was added in Twig 1.4.
|
51 |
-
|
52 |
-
.. note::
|
53 |
-
|
54 |
-
The C extension is **optional** but it brings some nice performance
|
55 |
-
improvements. Note that the extension is not a replacement for the PHP
|
56 |
-
code; it only implements a small part of the PHP code to improve the
|
57 |
-
performance at runtime; you must still install the regular PHP code.
|
58 |
-
|
59 |
-
Twig comes with a C extension that enhances the performance of the Twig
|
60 |
-
runtime engine; install it like any other PHP extensions:
|
61 |
-
|
62 |
-
.. code-block:: bash
|
63 |
-
|
64 |
-
cd ext/twig
|
65 |
-
phpize
|
66 |
-
./configure
|
67 |
-
make
|
68 |
-
make install
|
69 |
-
|
70 |
-
.. note::
|
71 |
-
|
72 |
-
You can also install the C extension via PEAR (note that this method is
|
73 |
-
deprecated and newer versions of Twig are not available on the PEAR
|
74 |
-
channel):
|
75 |
-
|
76 |
-
.. code-block:: bash
|
77 |
-
|
78 |
-
pear channel-discover pear.twig-project.org
|
79 |
-
pear install twig/CTwig
|
80 |
-
|
81 |
-
For Windows:
|
82 |
-
|
83 |
-
1. Setup the build environment following the `PHP documentation`_
|
84 |
-
2. Put Twig's C extension source code into ``C:\php-sdk\phpdev\vcXX\x86\php-source-directory\ext\twig``
|
85 |
-
3. Use the ``configure --disable-all --enable-cli --enable-twig=shared`` command instead of step 14
|
86 |
-
4. ``nmake``
|
87 |
-
5. Copy the ``C:\php-sdk\phpdev\vcXX\x86\php-source-directory\Release_TS\php_twig.dll`` file to your PHP setup.
|
88 |
-
|
89 |
-
.. tip::
|
90 |
-
|
91 |
-
For Windows ZendServer, ZTS is not enabled as mentioned in `Zend Server
|
92 |
-
FAQ`_.
|
93 |
-
|
94 |
-
You have to use ``configure --disable-all --disable-zts --enable-cli
|
95 |
-
--enable-twig=shared`` to be able to build the twig C extension for
|
96 |
-
ZendServer.
|
97 |
-
|
98 |
-
The built DLL will be available in
|
99 |
-
``C:\\php-sdk\\phpdev\\vcXX\\x86\\php-source-directory\\Release``
|
100 |
-
|
101 |
-
Finally, enable the extension in your ``php.ini`` configuration file:
|
102 |
-
|
103 |
-
.. code-block:: ini
|
104 |
-
|
105 |
-
extension=twig.so #For Unix systems
|
106 |
-
extension=php_twig.dll #For Windows systems
|
107 |
-
|
108 |
-
And from now on, Twig will automatically compile your templates to take
|
109 |
-
advantage of the C extension. Note that this extension does not replace the
|
110 |
-
PHP code but only provides an optimized version of the
|
111 |
-
``Twig_Template::getAttribute()`` method.
|
112 |
-
|
113 |
-
.. _`download page`: https://github.com/twigphp/Twig/tags
|
114 |
-
.. _`Composer`: https://getcomposer.org/download/
|
115 |
-
.. _`PHP documentation`: https://wiki.php.net/internals/windows/stepbystepbuild
|
116 |
-
.. _`Zend Server FAQ`: http://www.zend.com/en/products/server/faq#faqD6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/internals.rst
DELETED
@@ -1,142 +0,0 @@
|
|
1 |
-
Twig Internals
|
2 |
-
==============
|
3 |
-
|
4 |
-
Twig is very extensible and you can easily hack it. Keep in mind that you
|
5 |
-
should probably try to create an extension before hacking the core, as most
|
6 |
-
features and enhancements can be handled with extensions. This chapter is also
|
7 |
-
useful for people who want to understand how Twig works under the hood.
|
8 |
-
|
9 |
-
How does Twig work?
|
10 |
-
-------------------
|
11 |
-
|
12 |
-
The rendering of a Twig template can be summarized into four key steps:
|
13 |
-
|
14 |
-
* **Load** the template: If the template is already compiled, load it and go
|
15 |
-
to the *evaluation* step, otherwise:
|
16 |
-
|
17 |
-
* First, the **lexer** tokenizes the template source code into small pieces
|
18 |
-
for easier processing;
|
19 |
-
* Then, the **parser** converts the token stream into a meaningful tree
|
20 |
-
of nodes (the Abstract Syntax Tree);
|
21 |
-
* Eventually, the *compiler* transforms the AST into PHP code.
|
22 |
-
|
23 |
-
* **Evaluate** the template: It basically means calling the ``display()``
|
24 |
-
method of the compiled template and passing it the context.
|
25 |
-
|
26 |
-
The Lexer
|
27 |
-
---------
|
28 |
-
|
29 |
-
The lexer tokenizes a template source code into a token stream (each token is
|
30 |
-
an instance of ``Twig_Token``, and the stream is an instance of
|
31 |
-
``Twig_TokenStream``). The default lexer recognizes 13 different token types:
|
32 |
-
|
33 |
-
* ``Twig_Token::BLOCK_START_TYPE``, ``Twig_Token::BLOCK_END_TYPE``: Delimiters for blocks (``{% %}``)
|
34 |
-
* ``Twig_Token::VAR_START_TYPE``, ``Twig_Token::VAR_END_TYPE``: Delimiters for variables (``{{ }}``)
|
35 |
-
* ``Twig_Token::TEXT_TYPE``: A text outside an expression;
|
36 |
-
* ``Twig_Token::NAME_TYPE``: A name in an expression;
|
37 |
-
* ``Twig_Token::NUMBER_TYPE``: A number in an expression;
|
38 |
-
* ``Twig_Token::STRING_TYPE``: A string in an expression;
|
39 |
-
* ``Twig_Token::OPERATOR_TYPE``: An operator;
|
40 |
-
* ``Twig_Token::PUNCTUATION_TYPE``: A punctuation sign;
|
41 |
-
* ``Twig_Token::INTERPOLATION_START_TYPE``, ``Twig_Token::INTERPOLATION_END_TYPE`` (as of Twig 1.5): Delimiters for string interpolation;
|
42 |
-
* ``Twig_Token::EOF_TYPE``: Ends of template.
|
43 |
-
|
44 |
-
You can manually convert a source code into a token stream by calling the
|
45 |
-
``tokenize()`` method of an environment::
|
46 |
-
|
47 |
-
$stream = $twig->tokenize(new Twig_Source($source, $identifier));
|
48 |
-
|
49 |
-
.. versionadded:: 1.27
|
50 |
-
``Twig_Source`` was introduced in version 1.27, pass the source and the
|
51 |
-
identifier directly on previous versions.
|
52 |
-
|
53 |
-
As the stream has a ``__toString()`` method, you can have a textual
|
54 |
-
representation of it by echoing the object::
|
55 |
-
|
56 |
-
echo $stream."\n";
|
57 |
-
|
58 |
-
Here is the output for the ``Hello {{ name }}`` template:
|
59 |
-
|
60 |
-
.. code-block:: text
|
61 |
-
|
62 |
-
TEXT_TYPE(Hello )
|
63 |
-
VAR_START_TYPE()
|
64 |
-
NAME_TYPE(name)
|
65 |
-
VAR_END_TYPE()
|
66 |
-
EOF_TYPE()
|
67 |
-
|
68 |
-
.. note::
|
69 |
-
|
70 |
-
The default lexer (``Twig_Lexer``) can be changed by calling
|
71 |
-
the ``setLexer()`` method::
|
72 |
-
|
73 |
-
$twig->setLexer($lexer);
|
74 |
-
|
75 |
-
The Parser
|
76 |
-
----------
|
77 |
-
|
78 |
-
The parser converts the token stream into an AST (Abstract Syntax Tree), or a
|
79 |
-
node tree (an instance of ``Twig_Node_Module``). The core extension defines
|
80 |
-
the basic nodes like: ``for``, ``if``, ... and the expression nodes.
|
81 |
-
|
82 |
-
You can manually convert a token stream into a node tree by calling the
|
83 |
-
``parse()`` method of an environment::
|
84 |
-
|
85 |
-
$nodes = $twig->parse($stream);
|
86 |
-
|
87 |
-
Echoing the node object gives you a nice representation of the tree::
|
88 |
-
|
89 |
-
echo $nodes."\n";
|
90 |
-
|
91 |
-
Here is the output for the ``Hello {{ name }}`` template:
|
92 |
-
|
93 |
-
.. code-block:: text
|
94 |
-
|
95 |
-
Twig_Node_Module(
|
96 |
-
Twig_Node_Text(Hello )
|
97 |
-
Twig_Node_Print(
|
98 |
-
Twig_Node_Expression_Name(name)
|
99 |
-
)
|
100 |
-
)
|
101 |
-
|
102 |
-
.. note::
|
103 |
-
|
104 |
-
The default parser (``Twig_TokenParser``) can be changed by calling the
|
105 |
-
``setParser()`` method::
|
106 |
-
|
107 |
-
$twig->setParser($parser);
|
108 |
-
|
109 |
-
The Compiler
|
110 |
-
------------
|
111 |
-
|
112 |
-
The last step is done by the compiler. It takes a node tree as an input and
|
113 |
-
generates PHP code usable for runtime execution of the template.
|
114 |
-
|
115 |
-
You can manually compile a node tree to PHP code with the ``compile()`` method
|
116 |
-
of an environment::
|
117 |
-
|
118 |
-
$php = $twig->compile($nodes);
|
119 |
-
|
120 |
-
The generated template for a ``Hello {{ name }}`` template reads as follows
|
121 |
-
(the actual output can differ depending on the version of Twig you are
|
122 |
-
using)::
|
123 |
-
|
124 |
-
/* Hello {{ name }} */
|
125 |
-
class __TwigTemplate_1121b6f109fe93ebe8c6e22e3712bceb extends Twig_Template
|
126 |
-
{
|
127 |
-
protected function doDisplay(array $context, array $blocks = array())
|
128 |
-
{
|
129 |
-
// line 1
|
130 |
-
echo "Hello ";
|
131 |
-
echo twig_escape_filter($this->env, isset($context["name"]) ? $context["name"] : null), "html", null, true);
|
132 |
-
}
|
133 |
-
|
134 |
-
// some more code
|
135 |
-
}
|
136 |
-
|
137 |
-
.. note::
|
138 |
-
|
139 |
-
The default compiler (``Twig_Compiler``) can be changed by calling the
|
140 |
-
``setCompiler()`` method::
|
141 |
-
|
142 |
-
$twig->setCompiler($compiler);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/intro.rst
DELETED
@@ -1,85 +0,0 @@
|
|
1 |
-
Introduction
|
2 |
-
============
|
3 |
-
|
4 |
-
This is the documentation for Twig, the flexible, fast, and secure template
|
5 |
-
engine for PHP.
|
6 |
-
|
7 |
-
If you have any exposure to other text-based template languages, such as
|
8 |
-
Smarty, Django, or Jinja, you should feel right at home with Twig. It's both
|
9 |
-
designer and developer friendly by sticking to PHP's principles and adding
|
10 |
-
functionality useful for templating environments.
|
11 |
-
|
12 |
-
The key-features are...
|
13 |
-
|
14 |
-
* *Fast*: Twig compiles templates down to plain optimized PHP code. The
|
15 |
-
overhead compared to regular PHP code was reduced to the very minimum.
|
16 |
-
|
17 |
-
* *Secure*: Twig has a sandbox mode to evaluate untrusted template code. This
|
18 |
-
allows Twig to be used as a template language for applications where users
|
19 |
-
may modify the template design.
|
20 |
-
|
21 |
-
* *Flexible*: Twig is powered by a flexible lexer and parser. This allows the
|
22 |
-
developer to define their own custom tags and filters, and to create their own DSL.
|
23 |
-
|
24 |
-
Twig is used by many Open-Source projects like Symfony, Drupal8, eZPublish,
|
25 |
-
phpBB, Piwik, OroCRM; and many frameworks have support for it as well like
|
26 |
-
Slim, Yii, Laravel, Codeigniter and Kohana — just to name a few.
|
27 |
-
|
28 |
-
Prerequisites
|
29 |
-
-------------
|
30 |
-
|
31 |
-
Twig needs at least **PHP 5.2.7** to run.
|
32 |
-
|
33 |
-
Installation
|
34 |
-
------------
|
35 |
-
|
36 |
-
The recommended way to install Twig is via Composer:
|
37 |
-
|
38 |
-
.. code-block:: bash
|
39 |
-
|
40 |
-
composer require "twig/twig:~1.0"
|
41 |
-
|
42 |
-
.. note::
|
43 |
-
|
44 |
-
To learn more about the other installation methods, read the
|
45 |
-
:doc:`installation<installation>` chapter; it also explains how to install
|
46 |
-
the Twig C extension.
|
47 |
-
|
48 |
-
Basic API Usage
|
49 |
-
---------------
|
50 |
-
|
51 |
-
This section gives you a brief introduction to the PHP API for Twig.
|
52 |
-
|
53 |
-
.. code-block:: php
|
54 |
-
|
55 |
-
require_once '/path/to/vendor/autoload.php';
|
56 |
-
|
57 |
-
$loader = new Twig_Loader_Array(array(
|
58 |
-
'index' => 'Hello {{ name }}!',
|
59 |
-
));
|
60 |
-
$twig = new Twig_Environment($loader);
|
61 |
-
|
62 |
-
echo $twig->render('index', array('name' => 'Fabien'));
|
63 |
-
|
64 |
-
Twig uses a loader (``Twig_Loader_Array``) to locate templates, and an
|
65 |
-
environment (``Twig_Environment``) to store the configuration.
|
66 |
-
|
67 |
-
The ``render()`` method loads the template passed as a first argument and
|
68 |
-
renders it with the variables passed as a second argument.
|
69 |
-
|
70 |
-
As templates are generally stored on the filesystem, Twig also comes with a
|
71 |
-
filesystem loader::
|
72 |
-
|
73 |
-
$loader = new Twig_Loader_Filesystem('/path/to/templates');
|
74 |
-
$twig = new Twig_Environment($loader, array(
|
75 |
-
'cache' => '/path/to/compilation_cache',
|
76 |
-
));
|
77 |
-
|
78 |
-
echo $twig->render('index.html', array('name' => 'Fabien'));
|
79 |
-
|
80 |
-
.. tip::
|
81 |
-
|
82 |
-
If you are not using Composer, use the Twig built-in autoloader::
|
83 |
-
|
84 |
-
require_once '/path/to/lib/Twig/Autoloader.php';
|
85 |
-
Twig_Autoloader::register();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/recipes.rst
DELETED
@@ -1,568 +0,0 @@
|
|
1 |
-
Recipes
|
2 |
-
=======
|
3 |
-
|
4 |
-
.. _deprecation-notices:
|
5 |
-
|
6 |
-
Displaying Deprecation Notices
|
7 |
-
------------------------------
|
8 |
-
|
9 |
-
.. versionadded:: 1.21
|
10 |
-
This works as of Twig 1.21.
|
11 |
-
|
12 |
-
Deprecated features generate deprecation notices (via a call to the
|
13 |
-
``trigger_error()`` PHP function). By default, they are silenced and never
|
14 |
-
displayed nor logged.
|
15 |
-
|
16 |
-
To easily remove all deprecated feature usages from your templates, write and
|
17 |
-
run a script along the lines of the following::
|
18 |
-
|
19 |
-
require_once __DIR__.'/vendor/autoload.php';
|
20 |
-
|
21 |
-
$twig = create_your_twig_env();
|
22 |
-
|
23 |
-
$deprecations = new Twig_Util_DeprecationCollector($twig);
|
24 |
-
|
25 |
-
print_r($deprecations->collectDir(__DIR__.'/templates'));
|
26 |
-
|
27 |
-
The ``collectDir()`` method compiles all templates found in a directory,
|
28 |
-
catches deprecation notices, and return them.
|
29 |
-
|
30 |
-
.. tip::
|
31 |
-
|
32 |
-
If your templates are not stored on the filesystem, use the ``collect()``
|
33 |
-
method instead which takes an ``Iterator``; the iterator must return
|
34 |
-
template names as keys and template contents as values (as done by
|
35 |
-
``Twig_Util_TemplateDirIterator``).
|
36 |
-
|
37 |
-
However, this code won't find all deprecations (like using deprecated some Twig
|
38 |
-
classes). To catch all notices, register a custom error handler like the one
|
39 |
-
below::
|
40 |
-
|
41 |
-
$deprecations = array();
|
42 |
-
set_error_handler(function ($type, $msg) use (&$deprecations) {
|
43 |
-
if (E_USER_DEPRECATED === $type) {
|
44 |
-
$deprecations[] = $msg;
|
45 |
-
}
|
46 |
-
});
|
47 |
-
|
48 |
-
// run your application
|
49 |
-
|
50 |
-
print_r($deprecations);
|
51 |
-
|
52 |
-
Note that most deprecation notices are triggered during **compilation**, so
|
53 |
-
they won't be generated when templates are already cached.
|
54 |
-
|
55 |
-
.. tip::
|
56 |
-
|
57 |
-
If you want to manage the deprecation notices from your PHPUnit tests, have
|
58 |
-
a look at the `symfony/phpunit-bridge
|
59 |
-
<https://github.com/symfony/phpunit-bridge>`_ package, which eases the
|
60 |
-
process a lot.
|
61 |
-
|
62 |
-
Making a Layout conditional
|
63 |
-
---------------------------
|
64 |
-
|
65 |
-
Working with Ajax means that the same content is sometimes displayed as is,
|
66 |
-
and sometimes decorated with a layout. As Twig layout template names can be
|
67 |
-
any valid expression, you can pass a variable that evaluates to ``true`` when
|
68 |
-
the request is made via Ajax and choose the layout accordingly:
|
69 |
-
|
70 |
-
.. code-block:: jinja
|
71 |
-
|
72 |
-
{% extends request.ajax ? "base_ajax.html" : "base.html" %}
|
73 |
-
|
74 |
-
{% block content %}
|
75 |
-
This is the content to be displayed.
|
76 |
-
{% endblock %}
|
77 |
-
|
78 |
-
Making an Include dynamic
|
79 |
-
-------------------------
|
80 |
-
|
81 |
-
When including a template, its name does not need to be a string. For
|
82 |
-
instance, the name can depend on the value of a variable:
|
83 |
-
|
84 |
-
.. code-block:: jinja
|
85 |
-
|
86 |
-
{% include var ~ '_foo.html' %}
|
87 |
-
|
88 |
-
If ``var`` evaluates to ``index``, the ``index_foo.html`` template will be
|
89 |
-
rendered.
|
90 |
-
|
91 |
-
As a matter of fact, the template name can be any valid expression, such as
|
92 |
-
the following:
|
93 |
-
|
94 |
-
.. code-block:: jinja
|
95 |
-
|
96 |
-
{% include var|default('index') ~ '_foo.html' %}
|
97 |
-
|
98 |
-
Overriding a Template that also extends itself
|
99 |
-
----------------------------------------------
|
100 |
-
|
101 |
-
A template can be customized in two different ways:
|
102 |
-
|
103 |
-
* *Inheritance*: A template *extends* a parent template and overrides some
|
104 |
-
blocks;
|
105 |
-
|
106 |
-
* *Replacement*: If you use the filesystem loader, Twig loads the first
|
107 |
-
template it finds in a list of configured directories; a template found in a
|
108 |
-
directory *replaces* another one from a directory further in the list.
|
109 |
-
|
110 |
-
But how do you combine both: *replace* a template that also extends itself
|
111 |
-
(aka a template in a directory further in the list)?
|
112 |
-
|
113 |
-
Let's say that your templates are loaded from both ``.../templates/mysite``
|
114 |
-
and ``.../templates/default`` in this order. The ``page.twig`` template,
|
115 |
-
stored in ``.../templates/default`` reads as follows:
|
116 |
-
|
117 |
-
.. code-block:: jinja
|
118 |
-
|
119 |
-
{# page.twig #}
|
120 |
-
{% extends "layout.twig" %}
|
121 |
-
|
122 |
-
{% block content %}
|
123 |
-
{% endblock %}
|
124 |
-
|
125 |
-
You can replace this template by putting a file with the same name in
|
126 |
-
``.../templates/mysite``. And if you want to extend the original template, you
|
127 |
-
might be tempted to write the following:
|
128 |
-
|
129 |
-
.. code-block:: jinja
|
130 |
-
|
131 |
-
{# page.twig in .../templates/mysite #}
|
132 |
-
{% extends "page.twig" %} {# from .../templates/default #}
|
133 |
-
|
134 |
-
Of course, this will not work as Twig will always load the template from
|
135 |
-
``.../templates/mysite``.
|
136 |
-
|
137 |
-
It turns out it is possible to get this to work, by adding a directory right
|
138 |
-
at the end of your template directories, which is the parent of all of the
|
139 |
-
other directories: ``.../templates`` in our case. This has the effect of
|
140 |
-
making every template file within our system uniquely addressable. Most of the
|
141 |
-
time you will use the "normal" paths, but in the special case of wanting to
|
142 |
-
extend a template with an overriding version of itself we can reference its
|
143 |
-
parent's full, unambiguous template path in the extends tag:
|
144 |
-
|
145 |
-
.. code-block:: jinja
|
146 |
-
|
147 |
-
{# page.twig in .../templates/mysite #}
|
148 |
-
{% extends "default/page.twig" %} {# from .../templates #}
|
149 |
-
|
150 |
-
.. note::
|
151 |
-
|
152 |
-
This recipe was inspired by the following Django wiki page:
|
153 |
-
http://code.djangoproject.com/wiki/ExtendingTemplates
|
154 |
-
|
155 |
-
Customizing the Syntax
|
156 |
-
----------------------
|
157 |
-
|
158 |
-
Twig allows some syntax customization for the block delimiters. It's not
|
159 |
-
recommended to use this feature as templates will be tied with your custom
|
160 |
-
syntax. But for specific projects, it can make sense to change the defaults.
|
161 |
-
|
162 |
-
To change the block delimiters, you need to create your own lexer object::
|
163 |
-
|
164 |
-
$twig = new Twig_Environment();
|
165 |
-
|
166 |
-
$lexer = new Twig_Lexer($twig, array(
|
167 |
-
'tag_comment' => array('{#', '#}'),
|
168 |
-
'tag_block' => array('{%', '%}'),
|
169 |
-
'tag_variable' => array('{{', '}}'),
|
170 |
-
'interpolation' => array('#{', '}'),
|
171 |
-
));
|
172 |
-
$twig->setLexer($lexer);
|
173 |
-
|
174 |
-
Here are some configuration example that simulates some other template engines
|
175 |
-
syntax::
|
176 |
-
|
177 |
-
// Ruby erb syntax
|
178 |
-
$lexer = new Twig_Lexer($twig, array(
|
179 |
-
'tag_comment' => array('<%#', '%>'),
|
180 |
-
'tag_block' => array('<%', '%>'),
|
181 |
-
'tag_variable' => array('<%=', '%>'),
|
182 |
-
));
|
183 |
-
|
184 |
-
// SGML Comment Syntax
|
185 |
-
$lexer = new Twig_Lexer($twig, array(
|
186 |
-
'tag_comment' => array('<!--#', '-->'),
|
187 |
-
'tag_block' => array('<!--', '-->'),
|
188 |
-
'tag_variable' => array('${', '}'),
|
189 |
-
));
|
190 |
-
|
191 |
-
// Smarty like
|
192 |
-
$lexer = new Twig_Lexer($twig, array(
|
193 |
-
'tag_comment' => array('{*', '*}'),
|
194 |
-
'tag_block' => array('{', '}'),
|
195 |
-
'tag_variable' => array('{$', '}'),
|
196 |
-
));
|
197 |
-
|
198 |
-
Using dynamic Object Properties
|
199 |
-
-------------------------------
|
200 |
-
|
201 |
-
When Twig encounters a variable like ``article.title``, it tries to find a
|
202 |
-
``title`` public property in the ``article`` object.
|
203 |
-
|
204 |
-
It also works if the property does not exist but is rather defined dynamically
|
205 |
-
thanks to the magic ``__get()`` method; you just need to also implement the
|
206 |
-
``__isset()`` magic method like shown in the following snippet of code::
|
207 |
-
|
208 |
-
class Article
|
209 |
-
{
|
210 |
-
public function __get($name)
|
211 |
-
{
|
212 |
-
if ('title' == $name) {
|
213 |
-
return 'The title';
|
214 |
-
}
|
215 |
-
|
216 |
-
// throw some kind of error
|
217 |
-
}
|
218 |
-
|
219 |
-
public function __isset($name)
|
220 |
-
{
|
221 |
-
if ('title' == $name) {
|
222 |
-
return true;
|
223 |
-
}
|
224 |
-
|
225 |
-
return false;
|
226 |
-
}
|
227 |
-
}
|
228 |
-
|
229 |
-
Accessing the parent Context in Nested Loops
|
230 |
-
--------------------------------------------
|
231 |
-
|
232 |
-
Sometimes, when using nested loops, you need to access the parent context. The
|
233 |
-
parent context is always accessible via the ``loop.parent`` variable. For
|
234 |
-
instance, if you have the following template data::
|
235 |
-
|
236 |
-
$data = array(
|
237 |
-
'topics' => array(
|
238 |
-
'topic1' => array('Message 1 of topic 1', 'Message 2 of topic 1'),
|
239 |
-
'topic2' => array('Message 1 of topic 2', 'Message 2 of topic 2'),
|
240 |
-
),
|
241 |
-
);
|
242 |
-
|
243 |
-
And the following template to display all messages in all topics:
|
244 |
-
|
245 |
-
.. code-block:: jinja
|
246 |
-
|
247 |
-
{% for topic, messages in topics %}
|
248 |
-
* {{ loop.index }}: {{ topic }}
|
249 |
-
{% for message in messages %}
|
250 |
-
- {{ loop.parent.loop.index }}.{{ loop.index }}: {{ message }}
|
251 |
-
{% endfor %}
|
252 |
-
{% endfor %}
|
253 |
-
|
254 |
-
The output will be similar to:
|
255 |
-
|
256 |
-
.. code-block:: text
|
257 |
-
|
258 |
-
* 1: topic1
|
259 |
-
- 1.1: The message 1 of topic 1
|
260 |
-
- 1.2: The message 2 of topic 1
|
261 |
-
* 2: topic2
|
262 |
-
- 2.1: The message 1 of topic 2
|
263 |
-
- 2.2: The message 2 of topic 2
|
264 |
-
|
265 |
-
In the inner loop, the ``loop.parent`` variable is used to access the outer
|
266 |
-
context. So, the index of the current ``topic`` defined in the outer for loop
|
267 |
-
is accessible via the ``loop.parent.loop.index`` variable.
|
268 |
-
|
269 |
-
Defining undefined Functions and Filters on the Fly
|
270 |
-
---------------------------------------------------
|
271 |
-
|
272 |
-
When a function (or a filter) is not defined, Twig defaults to throw a
|
273 |
-
``Twig_Error_Syntax`` exception. However, it can also call a `callback`_ (any
|
274 |
-
valid PHP callable) which should return a function (or a filter).
|
275 |
-
|
276 |
-
For filters, register callbacks with ``registerUndefinedFilterCallback()``.
|
277 |
-
For functions, use ``registerUndefinedFunctionCallback()``::
|
278 |
-
|
279 |
-
// auto-register all native PHP functions as Twig functions
|
280 |
-
// don't try this at home as it's not secure at all!
|
281 |
-
$twig->registerUndefinedFunctionCallback(function ($name) {
|
282 |
-
if (function_exists($name)) {
|
283 |
-
return new Twig_SimpleFunction($name, $name);
|
284 |
-
}
|
285 |
-
|
286 |
-
return false;
|
287 |
-
});
|
288 |
-
|
289 |
-
If the callable is not able to return a valid function (or filter), it must
|
290 |
-
return ``false``.
|
291 |
-
|
292 |
-
If you register more than one callback, Twig will call them in turn until one
|
293 |
-
does not return ``false``.
|
294 |
-
|
295 |
-
.. tip::
|
296 |
-
|
297 |
-
As the resolution of functions and filters is done during compilation,
|
298 |
-
there is no overhead when registering these callbacks.
|
299 |
-
|
300 |
-
Validating the Template Syntax
|
301 |
-
------------------------------
|
302 |
-
|
303 |
-
When template code is provided by a third-party (through a web interface for
|
304 |
-
instance), it might be interesting to validate the template syntax before
|
305 |
-
saving it. If the template code is stored in a `$template` variable, here is
|
306 |
-
how you can do it::
|
307 |
-
|
308 |
-
try {
|
309 |
-
$twig->parse($twig->tokenize(new Twig_Source($template)));
|
310 |
-
|
311 |
-
// the $template is valid
|
312 |
-
} catch (Twig_Error_Syntax $e) {
|
313 |
-
// $template contains one or more syntax errors
|
314 |
-
}
|
315 |
-
|
316 |
-
If you iterate over a set of files, you can pass the filename to the
|
317 |
-
``tokenize()`` method to get the filename in the exception message::
|
318 |
-
|
319 |
-
foreach ($files as $file) {
|
320 |
-
try {
|
321 |
-
$twig->parse($twig->tokenize(new Twig_Source($template, $file->getFilename(), $file)));
|
322 |
-
|
323 |
-
// the $template is valid
|
324 |
-
} catch (Twig_Error_Syntax $e) {
|
325 |
-
// $template contains one or more syntax errors
|
326 |
-
}
|
327 |
-
}
|
328 |
-
|
329 |
-
.. versionadded:: 1.27
|
330 |
-
``Twig_Source`` was introduced in version 1.27, pass the source and the
|
331 |
-
identifier directly on previous versions.
|
332 |
-
|
333 |
-
.. note::
|
334 |
-
|
335 |
-
This method won't catch any sandbox policy violations because the policy
|
336 |
-
is enforced during template rendering (as Twig needs the context for some
|
337 |
-
checks like allowed methods on objects).
|
338 |
-
|
339 |
-
Refreshing modified Templates when OPcache or APC is enabled
|
340 |
-
------------------------------------------------------------
|
341 |
-
|
342 |
-
When using OPcache with ``opcache.validate_timestamps`` set to ``0`` or APC
|
343 |
-
with ``apc.stat`` set to ``0`` and Twig cache enabled, clearing the template
|
344 |
-
cache won't update the cache.
|
345 |
-
|
346 |
-
To get around this, force Twig to invalidate the bytecode cache::
|
347 |
-
|
348 |
-
$twig = new Twig_Environment($loader, array(
|
349 |
-
'cache' => new Twig_Cache_Filesystem('/some/cache/path', Twig_Cache_Filesystem::FORCE_BYTECODE_INVALIDATION),
|
350 |
-
// ...
|
351 |
-
));
|
352 |
-
|
353 |
-
.. note::
|
354 |
-
|
355 |
-
Before Twig 1.22, you should extend ``Twig_Environment`` instead::
|
356 |
-
|
357 |
-
class OpCacheAwareTwigEnvironment extends Twig_Environment
|
358 |
-
{
|
359 |
-
protected function writeCacheFile($file, $content)
|
360 |
-
{
|
361 |
-
parent::writeCacheFile($file, $content);
|
362 |
-
|
363 |
-
// Compile cached file into bytecode cache
|
364 |
-
if (function_exists('opcache_invalidate')) {
|
365 |
-
opcache_invalidate($file, true);
|
366 |
-
} elseif (function_exists('apc_compile_file')) {
|
367 |
-
apc_compile_file($file);
|
368 |
-
}
|
369 |
-
}
|
370 |
-
}
|
371 |
-
|
372 |
-
Reusing a stateful Node Visitor
|
373 |
-
-------------------------------
|
374 |
-
|
375 |
-
When attaching a visitor to a ``Twig_Environment`` instance, Twig uses it to
|
376 |
-
visit *all* templates it compiles. If you need to keep some state information
|
377 |
-
around, you probably want to reset it when visiting a new template.
|
378 |
-
|
379 |
-
This can be easily achieved with the following code::
|
380 |
-
|
381 |
-
protected $someTemplateState = array();
|
382 |
-
|
383 |
-
public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
|
384 |
-
{
|
385 |
-
if ($node instanceof Twig_Node_Module) {
|
386 |
-
// reset the state as we are entering a new template
|
387 |
-
$this->someTemplateState = array();
|
388 |
-
}
|
389 |
-
|
390 |
-
// ...
|
391 |
-
|
392 |
-
return $node;
|
393 |
-
}
|
394 |
-
|
395 |
-
Using a Database to store Templates
|
396 |
-
-----------------------------------
|
397 |
-
|
398 |
-
If you are developing a CMS, templates are usually stored in a database. This
|
399 |
-
recipe gives you a simple PDO template loader you can use as a starting point
|
400 |
-
for your own.
|
401 |
-
|
402 |
-
First, let's create a temporary in-memory SQLite3 database to work with::
|
403 |
-
|
404 |
-
$dbh = new PDO('sqlite::memory:');
|
405 |
-
$dbh->exec('CREATE TABLE templates (name STRING, source STRING, last_modified INTEGER)');
|
406 |
-
$base = '{% block content %}{% endblock %}';
|
407 |
-
$index = '
|
408 |
-
{% extends "base.twig" %}
|
409 |
-
{% block content %}Hello {{ name }}{% endblock %}
|
410 |
-
';
|
411 |
-
$now = time();
|
412 |
-
$dbh->exec("INSERT INTO templates (name, source, last_modified) VALUES ('base.twig', '$base', $now)");
|
413 |
-
$dbh->exec("INSERT INTO templates (name, source, last_modified) VALUES ('index.twig', '$index', $now)");
|
414 |
-
|
415 |
-
We have created a simple ``templates`` table that hosts two templates:
|
416 |
-
``base.twig`` and ``index.twig``.
|
417 |
-
|
418 |
-
Now, let's define a loader able to use this database::
|
419 |
-
|
420 |
-
class DatabaseTwigLoader implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
|
421 |
-
{
|
422 |
-
protected $dbh;
|
423 |
-
|
424 |
-
public function __construct(PDO $dbh)
|
425 |
-
{
|
426 |
-
$this->dbh = $dbh;
|
427 |
-
}
|
428 |
-
|
429 |
-
public function getSource($name)
|
430 |
-
{
|
431 |
-
if (false === $source = $this->getValue('source', $name)) {
|
432 |
-
throw new Twig_Error_Loader(sprintf('Template "%s" does not exist.', $name));
|
433 |
-
}
|
434 |
-
|
435 |
-
return $source;
|
436 |
-
}
|
437 |
-
|
438 |
-
// Twig_SourceContextLoaderInterface as of Twig 1.27
|
439 |
-
public function getSourceContext($name)
|
440 |
-
{
|
441 |
-
if (false === $source = $this->getValue('source', $name)) {
|
442 |
-
throw new Twig_Error_Loader(sprintf('Template "%s" does not exist.', $name));
|
443 |
-
}
|
444 |
-
|
445 |
-
return new Twig_Source($source, $name);
|
446 |
-
}
|
447 |
-
|
448 |
-
// Twig_ExistsLoaderInterface as of Twig 1.11
|
449 |
-
public function exists($name)
|
450 |
-
{
|
451 |
-
return $name === $this->getValue('name', $name);
|
452 |
-
}
|
453 |
-
|
454 |
-
public function getCacheKey($name)
|
455 |
-
{
|
456 |
-
return $name;
|
457 |
-
}
|
458 |
-
|
459 |
-
public function isFresh($name, $time)
|
460 |
-
{
|
461 |
-
if (false === $lastModified = $this->getValue('last_modified', $name)) {
|
462 |
-
return false;
|
463 |
-
}
|
464 |
-
|
465 |
-
return $lastModified <= $time;
|
466 |
-
}
|
467 |
-
|
468 |
-
protected function getValue($column, $name)
|
469 |
-
{
|
470 |
-
$sth = $this->dbh->prepare('SELECT '.$column.' FROM templates WHERE name = :name');
|
471 |
-
$sth->execute(array(':name' => (string) $name));
|
472 |
-
|
473 |
-
return $sth->fetchColumn();
|
474 |
-
}
|
475 |
-
}
|
476 |
-
|
477 |
-
Finally, here is an example on how you can use it::
|
478 |
-
|
479 |
-
$loader = new DatabaseTwigLoader($dbh);
|
480 |
-
$twig = new Twig_Environment($loader);
|
481 |
-
|
482 |
-
echo $twig->render('index.twig', array('name' => 'Fabien'));
|
483 |
-
|
484 |
-
Using different Template Sources
|
485 |
-
--------------------------------
|
486 |
-
|
487 |
-
This recipe is the continuation of the previous one. Even if you store the
|
488 |
-
contributed templates in a database, you might want to keep the original/base
|
489 |
-
templates on the filesystem. When templates can be loaded from different
|
490 |
-
sources, you need to use the ``Twig_Loader_Chain`` loader.
|
491 |
-
|
492 |
-
As you can see in the previous recipe, we reference the template in the exact
|
493 |
-
same way as we would have done it with a regular filesystem loader. This is
|
494 |
-
the key to be able to mix and match templates coming from the database, the
|
495 |
-
filesystem, or any other loader for that matter: the template name should be a
|
496 |
-
logical name, and not the path from the filesystem::
|
497 |
-
|
498 |
-
$loader1 = new DatabaseTwigLoader($dbh);
|
499 |
-
$loader2 = new Twig_Loader_Array(array(
|
500 |
-
'base.twig' => '{% block content %}{% endblock %}',
|
501 |
-
));
|
502 |
-
$loader = new Twig_Loader_Chain(array($loader1, $loader2));
|
503 |
-
|
504 |
-
$twig = new Twig_Environment($loader);
|
505 |
-
|
506 |
-
echo $twig->render('index.twig', array('name' => 'Fabien'));
|
507 |
-
|
508 |
-
Now that the ``base.twig`` templates is defined in an array loader, you can
|
509 |
-
remove it from the database, and everything else will still work as before.
|
510 |
-
|
511 |
-
Loading a Template from a String
|
512 |
-
--------------------------------
|
513 |
-
|
514 |
-
From a template, you can easily load a template stored in a string via the
|
515 |
-
``template_from_string`` function (available as of Twig 1.11 via the
|
516 |
-
``Twig_Extension_StringLoader`` extension):
|
517 |
-
|
518 |
-
.. code-block:: jinja
|
519 |
-
|
520 |
-
{{ include(template_from_string("Hello {{ name }}")) }}
|
521 |
-
|
522 |
-
From PHP, it's also possible to load a template stored in a string via
|
523 |
-
``Twig_Environment::createTemplate()`` (available as of Twig 1.18)::
|
524 |
-
|
525 |
-
$template = $twig->createTemplate('hello {{ name }}');
|
526 |
-
echo $template->render(array('name' => 'Fabien'));
|
527 |
-
|
528 |
-
.. note::
|
529 |
-
|
530 |
-
Never use the ``Twig_Loader_String`` loader, which has severe limitations.
|
531 |
-
|
532 |
-
Using Twig and AngularJS in the same Templates
|
533 |
-
----------------------------------------------
|
534 |
-
|
535 |
-
Mixing different template syntaxes in the same file is not a recommended
|
536 |
-
practice as both AngularJS and Twig use the same delimiters in their syntax:
|
537 |
-
``{{`` and ``}}``.
|
538 |
-
|
539 |
-
Still, if you want to use AngularJS and Twig in the same template, there are
|
540 |
-
two ways to make it work depending on the amount of AngularJS you need to
|
541 |
-
include in your templates:
|
542 |
-
|
543 |
-
* Escaping the AngularJS delimiters by wrapping AngularJS sections with the
|
544 |
-
``{% verbatim %}`` tag or by escaping each delimiter via ``{{ '{{' }}`` and
|
545 |
-
``{{ '}}' }}``;
|
546 |
-
|
547 |
-
* Changing the delimiters of one of the template engines (depending on which
|
548 |
-
engine you introduced last):
|
549 |
-
|
550 |
-
* For AngularJS, change the interpolation tags using the
|
551 |
-
``interpolateProvider`` service, for instance at the module initialization
|
552 |
-
time:
|
553 |
-
|
554 |
-
..code-block:: javascript
|
555 |
-
|
556 |
-
angular.module('myApp', []).config(function($interpolateProvider) {
|
557 |
-
$interpolateProvider.startSymbol('{[').endSymbol(']}');
|
558 |
-
});
|
559 |
-
|
560 |
-
* For Twig, change the delimiters via the ``tag_variable`` Lexer option:
|
561 |
-
|
562 |
-
..code-block:: php
|
563 |
-
|
564 |
-
$env->setLexer(new Twig_Lexer($env, array(
|
565 |
-
'tag_variable' => array('{[', ']}'),
|
566 |
-
)));
|
567 |
-
|
568 |
-
.. _callback: http://www.php.net/manual/en/function.is-callable.php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/autoescape.rst
DELETED
@@ -1,81 +0,0 @@
|
|
1 |
-
``autoescape``
|
2 |
-
==============
|
3 |
-
|
4 |
-
Whether automatic escaping is enabled or not, you can mark a section of a
|
5 |
-
template to be escaped or not by using the ``autoescape`` tag:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{% autoescape %}
|
10 |
-
Everything will be automatically escaped in this block
|
11 |
-
using the HTML strategy
|
12 |
-
{% endautoescape %}
|
13 |
-
|
14 |
-
{% autoescape 'html' %}
|
15 |
-
Everything will be automatically escaped in this block
|
16 |
-
using the HTML strategy
|
17 |
-
{% endautoescape %}
|
18 |
-
|
19 |
-
{% autoescape 'js' %}
|
20 |
-
Everything will be automatically escaped in this block
|
21 |
-
using the js escaping strategy
|
22 |
-
{% endautoescape %}
|
23 |
-
|
24 |
-
{% autoescape false %}
|
25 |
-
Everything will be outputted as is in this block
|
26 |
-
{% endautoescape %}
|
27 |
-
|
28 |
-
.. note::
|
29 |
-
|
30 |
-
Before Twig 1.8, the syntax was different:
|
31 |
-
|
32 |
-
.. code-block:: jinja
|
33 |
-
|
34 |
-
{% autoescape true %}
|
35 |
-
Everything will be automatically escaped in this block
|
36 |
-
using the HTML strategy
|
37 |
-
{% endautoescape %}
|
38 |
-
|
39 |
-
{% autoescape false %}
|
40 |
-
Everything will be outputted as is in this block
|
41 |
-
{% endautoescape %}
|
42 |
-
|
43 |
-
{% autoescape true js %}
|
44 |
-
Everything will be automatically escaped in this block
|
45 |
-
using the js escaping strategy
|
46 |
-
{% endautoescape %}
|
47 |
-
|
48 |
-
When automatic escaping is enabled everything is escaped by default except for
|
49 |
-
values explicitly marked as safe. Those can be marked in the template by using
|
50 |
-
the :doc:`raw<../filters/raw>` filter:
|
51 |
-
|
52 |
-
.. code-block:: jinja
|
53 |
-
|
54 |
-
{% autoescape %}
|
55 |
-
{{ safe_value|raw }}
|
56 |
-
{% endautoescape %}
|
57 |
-
|
58 |
-
Functions returning template data (like :doc:`macros<macro>` and
|
59 |
-
:doc:`parent<../functions/parent>`) always return safe markup.
|
60 |
-
|
61 |
-
.. note::
|
62 |
-
|
63 |
-
Twig is smart enough to not escape an already escaped value by the
|
64 |
-
:doc:`escape<../filters/escape>` filter.
|
65 |
-
|
66 |
-
.. note::
|
67 |
-
|
68 |
-
Twig does not escape static expressions:
|
69 |
-
|
70 |
-
.. code-block:: jinja
|
71 |
-
|
72 |
-
{% set hello = "<strong>Hello</strong>" %}
|
73 |
-
{{ hello }}
|
74 |
-
{{ "<strong>world</strong>" }}
|
75 |
-
|
76 |
-
Will be rendered "<strong>Hello</strong> **world**".
|
77 |
-
|
78 |
-
.. note::
|
79 |
-
|
80 |
-
The chapter :doc:`Twig for Developers<../api>` gives more information
|
81 |
-
about when and how automatic escaping is applied.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/block.rst
DELETED
@@ -1,11 +0,0 @@
|
|
1 |
-
``block``
|
2 |
-
=========
|
3 |
-
|
4 |
-
Blocks are used for inheritance and act as placeholders and replacements at
|
5 |
-
the same time. They are documented in detail in the documentation for the
|
6 |
-
:doc:`extends<../tags/extends>` tag.
|
7 |
-
|
8 |
-
Block names should consist of alphanumeric characters, and underscores. Dashes
|
9 |
-
are not permitted.
|
10 |
-
|
11 |
-
.. seealso:: :doc:`block<../functions/block>`, :doc:`parent<../functions/parent>`, :doc:`use<../tags/use>`, :doc:`extends<../tags/extends>`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/do.rst
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
``do``
|
2 |
-
======
|
3 |
-
|
4 |
-
.. versionadded:: 1.5
|
5 |
-
The ``do`` tag was added in Twig 1.5.
|
6 |
-
|
7 |
-
The ``do`` tag works exactly like the regular variable expression (``{{ ...
|
8 |
-
}}``) just that it doesn't print anything:
|
9 |
-
|
10 |
-
.. code-block:: jinja
|
11 |
-
|
12 |
-
{% do 1 + 2 %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/embed.rst
DELETED
@@ -1,178 +0,0 @@
|
|
1 |
-
``embed``
|
2 |
-
=========
|
3 |
-
|
4 |
-
.. versionadded:: 1.8
|
5 |
-
The ``embed`` tag was added in Twig 1.8.
|
6 |
-
|
7 |
-
The ``embed`` tag combines the behaviour of :doc:`include<include>` and
|
8 |
-
:doc:`extends<extends>`.
|
9 |
-
It allows you to include another template's contents, just like ``include``
|
10 |
-
does. But it also allows you to override any block defined inside the
|
11 |
-
included template, like when extending a template.
|
12 |
-
|
13 |
-
Think of an embedded template as a "micro layout skeleton".
|
14 |
-
|
15 |
-
.. code-block:: jinja
|
16 |
-
|
17 |
-
{% embed "teasers_skeleton.twig" %}
|
18 |
-
{# These blocks are defined in "teasers_skeleton.twig" #}
|
19 |
-
{# and we override them right here: #}
|
20 |
-
{% block left_teaser %}
|
21 |
-
Some content for the left teaser box
|
22 |
-
{% endblock %}
|
23 |
-
{% block right_teaser %}
|
24 |
-
Some content for the right teaser box
|
25 |
-
{% endblock %}
|
26 |
-
{% endembed %}
|
27 |
-
|
28 |
-
The ``embed`` tag takes the idea of template inheritance to the level of
|
29 |
-
content fragments. While template inheritance allows for "document skeletons",
|
30 |
-
which are filled with life by child templates, the ``embed`` tag allows you to
|
31 |
-
create "skeletons" for smaller units of content and re-use and fill them
|
32 |
-
anywhere you like.
|
33 |
-
|
34 |
-
Since the use case may not be obvious, let's look at a simplified example.
|
35 |
-
Imagine a base template shared by multiple HTML pages, defining a single block
|
36 |
-
named "content":
|
37 |
-
|
38 |
-
.. code-block:: text
|
39 |
-
|
40 |
-
┌─── page layout ─────────────────────┐
|
41 |
-
│ │
|
42 |
-
│ ┌── block "content" ──┐ │
|
43 |
-
│ │ │ │
|
44 |
-
│ │ │ │
|
45 |
-
│ │ (child template to │ │
|
46 |
-
│ │ put content here) │ │
|
47 |
-
│ │ │ │
|
48 |
-
│ │ │ │
|
49 |
-
│ └─────────────────────┘ │
|
50 |
-
│ │
|
51 |
-
└─────────────────────────────────────┘
|
52 |
-
|
53 |
-
Some pages ("foo" and "bar") share the same content structure -
|
54 |
-
two vertically stacked boxes:
|
55 |
-
|
56 |
-
.. code-block:: text
|
57 |
-
|
58 |
-
┌─── page layout ─────────────────────┐
|
59 |
-
│ │
|
60 |
-
│ ┌── block "content" ──┐ │
|
61 |
-
│ │ ┌─ block "top" ───┐ │ │
|
62 |
-
│ │ │ │ │ │
|
63 |
-
│ │ └─────────────────┘ │ │
|
64 |
-
│ │ ┌─ block "bottom" ┐ │ │
|
65 |
-
│ │ │ │ │ │
|
66 |
-
│ │ └─────────────────┘ │ │
|
67 |
-
│ └─────────────────────┘ │
|
68 |
-
│ │
|
69 |
-
└─────────────────────────────────────┘
|
70 |
-
|
71 |
-
While other pages ("boom" and "baz") share a different content structure -
|
72 |
-
two boxes side by side:
|
73 |
-
|
74 |
-
.. code-block:: text
|
75 |
-
|
76 |
-
┌─── page layout ─────────────────────┐
|
77 |
-
│ │
|
78 |
-
│ ┌── block "content" ──┐ │
|
79 |
-
│ │ │ │
|
80 |
-
│ │ ┌ block ┐ ┌ block ┐ │ │
|
81 |
-
│ │ │"left" │ │"right"│ │ │
|
82 |
-
│ │ │ │ │ │ │ │
|
83 |
-
│ │ │ │ │ │ │ │
|
84 |
-
│ │ └───────┘ └───────┘ │ │
|
85 |
-
│ └─────────────────────┘ │
|
86 |
-
│ │
|
87 |
-
└─────────────────────────────────────┘
|
88 |
-
|
89 |
-
Without the ``embed`` tag, you have two ways to design your templates:
|
90 |
-
|
91 |
-
* Create two "intermediate" base templates that extend the master layout
|
92 |
-
template: one with vertically stacked boxes to be used by the "foo" and
|
93 |
-
"bar" pages and another one with side-by-side boxes for the "boom" and
|
94 |
-
"baz" pages.
|
95 |
-
|
96 |
-
* Embed the markup for the top/bottom and left/right boxes into each page
|
97 |
-
template directly.
|
98 |
-
|
99 |
-
These two solutions do not scale well because they each have a major drawback:
|
100 |
-
|
101 |
-
* The first solution may indeed work for this simplified example. But imagine
|
102 |
-
we add a sidebar, which may again contain different, recurring structures
|
103 |
-
of content. Now we would need to create intermediate base templates for
|
104 |
-
all occurring combinations of content structure and sidebar structure...
|
105 |
-
and so on.
|
106 |
-
|
107 |
-
* The second solution involves duplication of common code with all its negative
|
108 |
-
consequences: any change involves finding and editing all affected copies
|
109 |
-
of the structure, correctness has to be verified for each copy, copies may
|
110 |
-
go out of sync by careless modifications etc.
|
111 |
-
|
112 |
-
In such a situation, the ``embed`` tag comes in handy. The common layout
|
113 |
-
code can live in a single base template, and the two different content structures,
|
114 |
-
let's call them "micro layouts" go into separate templates which are embedded
|
115 |
-
as necessary:
|
116 |
-
|
117 |
-
Page template ``foo.twig``:
|
118 |
-
|
119 |
-
.. code-block:: jinja
|
120 |
-
|
121 |
-
{% extends "layout_skeleton.twig" %}
|
122 |
-
|
123 |
-
{% block content %}
|
124 |
-
{% embed "vertical_boxes_skeleton.twig" %}
|
125 |
-
{% block top %}
|
126 |
-
Some content for the top box
|
127 |
-
{% endblock %}
|
128 |
-
|
129 |
-
{% block bottom %}
|
130 |
-
Some content for the bottom box
|
131 |
-
{% endblock %}
|
132 |
-
{% endembed %}
|
133 |
-
{% endblock %}
|
134 |
-
|
135 |
-
And here is the code for ``vertical_boxes_skeleton.twig``:
|
136 |
-
|
137 |
-
.. code-block:: html+jinja
|
138 |
-
|
139 |
-
<div class="top_box">
|
140 |
-
{% block top %}
|
141 |
-
Top box default content
|
142 |
-
{% endblock %}
|
143 |
-
</div>
|
144 |
-
|
145 |
-
<div class="bottom_box">
|
146 |
-
{% block bottom %}
|
147 |
-
Bottom box default content
|
148 |
-
{% endblock %}
|
149 |
-
</div>
|
150 |
-
|
151 |
-
The goal of the ``vertical_boxes_skeleton.twig`` template being to factor
|
152 |
-
out the HTML markup for the boxes.
|
153 |
-
|
154 |
-
The ``embed`` tag takes the exact same arguments as the ``include`` tag:
|
155 |
-
|
156 |
-
.. code-block:: jinja
|
157 |
-
|
158 |
-
{% embed "base" with {'foo': 'bar'} %}
|
159 |
-
...
|
160 |
-
{% endembed %}
|
161 |
-
|
162 |
-
{% embed "base" with {'foo': 'bar'} only %}
|
163 |
-
...
|
164 |
-
{% endembed %}
|
165 |
-
|
166 |
-
{% embed "base" ignore missing %}
|
167 |
-
...
|
168 |
-
{% endembed %}
|
169 |
-
|
170 |
-
.. warning::
|
171 |
-
|
172 |
-
As embedded templates do not have "names", auto-escaping strategies based
|
173 |
-
on the template name won't work as expected if you change the context (for
|
174 |
-
instance, if you embed a CSS/JavaScript template into an HTML one). In that
|
175 |
-
case, explicitly set the default auto-escaping strategy with the
|
176 |
-
``autoescape`` tag.
|
177 |
-
|
178 |
-
.. seealso:: :doc:`include<../tags/include>`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/extends.rst
DELETED
@@ -1,272 +0,0 @@
|
|
1 |
-
``extends``
|
2 |
-
===========
|
3 |
-
|
4 |
-
The ``extends`` tag can be used to extend a template from another one.
|
5 |
-
|
6 |
-
.. note::
|
7 |
-
|
8 |
-
Like PHP, Twig does not support multiple inheritance. So you can only have
|
9 |
-
one extends tag called per rendering. However, Twig supports horizontal
|
10 |
-
:doc:`reuse<use>`.
|
11 |
-
|
12 |
-
Let's define a base template, ``base.html``, which defines a simple HTML
|
13 |
-
skeleton document:
|
14 |
-
|
15 |
-
.. code-block:: html+jinja
|
16 |
-
|
17 |
-
<!DOCTYPE html>
|
18 |
-
<html>
|
19 |
-
<head>
|
20 |
-
{% block head %}
|
21 |
-
<link rel="stylesheet" href="style.css" />
|
22 |
-
<title>{% block title %}{% endblock %} - My Webpage</title>
|
23 |
-
{% endblock %}
|
24 |
-
</head>
|
25 |
-
<body>
|
26 |
-
<div id="content">{% block content %}{% endblock %}</div>
|
27 |
-
<div id="footer">
|
28 |
-
{% block footer %}
|
29 |
-
© Copyright 2011 by <a href="http://domain.invalid/">you</a>.
|
30 |
-
{% endblock %}
|
31 |
-
</div>
|
32 |
-
</body>
|
33 |
-
</html>
|
34 |
-
|
35 |
-
In this example, the :doc:`block<block>` tags define four blocks that child
|
36 |
-
templates can fill in.
|
37 |
-
|
38 |
-
All the ``block`` tag does is to tell the template engine that a child
|
39 |
-
template may override those portions of the template.
|
40 |
-
|
41 |
-
Child Template
|
42 |
-
--------------
|
43 |
-
|
44 |
-
A child template might look like this:
|
45 |
-
|
46 |
-
.. code-block:: jinja
|
47 |
-
|
48 |
-
{% extends "base.html" %}
|
49 |
-
|
50 |
-
{% block title %}Index{% endblock %}
|
51 |
-
{% block head %}
|
52 |
-
{{ parent() }}
|
53 |
-
<style type="text/css">
|
54 |
-
.important { color: #336699; }
|
55 |
-
</style>
|
56 |
-
{% endblock %}
|
57 |
-
{% block content %}
|
58 |
-
<h1>Index</h1>
|
59 |
-
<p class="important">
|
60 |
-
Welcome on my awesome homepage.
|
61 |
-
</p>
|
62 |
-
{% endblock %}
|
63 |
-
|
64 |
-
The ``extends`` tag is the key here. It tells the template engine that this
|
65 |
-
template "extends" another template. When the template system evaluates this
|
66 |
-
template, first it locates the parent. The extends tag should be the first tag
|
67 |
-
in the template.
|
68 |
-
|
69 |
-
Note that since the child template doesn't define the ``footer`` block, the
|
70 |
-
value from the parent template is used instead.
|
71 |
-
|
72 |
-
You can't define multiple ``block`` tags with the same name in the same
|
73 |
-
template. This limitation exists because a block tag works in "both"
|
74 |
-
directions. That is, a block tag doesn't just provide a hole to fill - it also
|
75 |
-
defines the content that fills the hole in the *parent*. If there were two
|
76 |
-
similarly-named ``block`` tags in a template, that template's parent wouldn't
|
77 |
-
know which one of the blocks' content to use.
|
78 |
-
|
79 |
-
If you want to print a block multiple times you can however use the
|
80 |
-
``block`` function:
|
81 |
-
|
82 |
-
.. code-block:: jinja
|
83 |
-
|
84 |
-
<title>{% block title %}{% endblock %}</title>
|
85 |
-
<h1>{{ block('title') }}</h1>
|
86 |
-
{% block body %}{% endblock %}
|
87 |
-
|
88 |
-
Parent Blocks
|
89 |
-
-------------
|
90 |
-
|
91 |
-
It's possible to render the contents of the parent block by using the
|
92 |
-
:doc:`parent<../functions/parent>` function. This gives back the results of
|
93 |
-
the parent block:
|
94 |
-
|
95 |
-
.. code-block:: jinja
|
96 |
-
|
97 |
-
{% block sidebar %}
|
98 |
-
<h3>Table Of Contents</h3>
|
99 |
-
...
|
100 |
-
{{ parent() }}
|
101 |
-
{% endblock %}
|
102 |
-
|
103 |
-
Named Block End-Tags
|
104 |
-
--------------------
|
105 |
-
|
106 |
-
Twig allows you to put the name of the block after the end tag for better
|
107 |
-
readability:
|
108 |
-
|
109 |
-
.. code-block:: jinja
|
110 |
-
|
111 |
-
{% block sidebar %}
|
112 |
-
{% block inner_sidebar %}
|
113 |
-
...
|
114 |
-
{% endblock inner_sidebar %}
|
115 |
-
{% endblock sidebar %}
|
116 |
-
|
117 |
-
Of course, the name after the ``endblock`` word must match the block name.
|
118 |
-
|
119 |
-
Block Nesting and Scope
|
120 |
-
-----------------------
|
121 |
-
|
122 |
-
Blocks can be nested for more complex layouts. Per default, blocks have access
|
123 |
-
to variables from outer scopes:
|
124 |
-
|
125 |
-
.. code-block:: jinja
|
126 |
-
|
127 |
-
{% for item in seq %}
|
128 |
-
<li>{% block loop_item %}{{ item }}{% endblock %}</li>
|
129 |
-
{% endfor %}
|
130 |
-
|
131 |
-
Block Shortcuts
|
132 |
-
---------------
|
133 |
-
|
134 |
-
For blocks with little content, it's possible to use a shortcut syntax. The
|
135 |
-
following constructs do the same thing:
|
136 |
-
|
137 |
-
.. code-block:: jinja
|
138 |
-
|
139 |
-
{% block title %}
|
140 |
-
{{ page_title|title }}
|
141 |
-
{% endblock %}
|
142 |
-
|
143 |
-
.. code-block:: jinja
|
144 |
-
|
145 |
-
{% block title page_title|title %}
|
146 |
-
|
147 |
-
Dynamic Inheritance
|
148 |
-
-------------------
|
149 |
-
|
150 |
-
Twig supports dynamic inheritance by using a variable as the base template:
|
151 |
-
|
152 |
-
.. code-block:: jinja
|
153 |
-
|
154 |
-
{% extends some_var %}
|
155 |
-
|
156 |
-
If the variable evaluates to a ``Twig_Template`` or a ``Twig_TemplateWraper``
|
157 |
-
instance, Twig will use it as the parent template::
|
158 |
-
|
159 |
-
// {% extends layout %}
|
160 |
-
|
161 |
-
// deprecated as of Twig 1.28
|
162 |
-
$layout = $twig->loadTemplate('some_layout_template.twig');
|
163 |
-
|
164 |
-
// as of Twig 1.28
|
165 |
-
$layout = $twig->load('some_layout_template.twig');
|
166 |
-
|
167 |
-
$twig->display('template.twig', array('layout' => $layout));
|
168 |
-
|
169 |
-
.. versionadded:: 1.2
|
170 |
-
The possibility to pass an array of templates has been added in Twig 1.2.
|
171 |
-
|
172 |
-
You can also provide a list of templates that are checked for existence. The
|
173 |
-
first template that exists will be used as a parent:
|
174 |
-
|
175 |
-
.. code-block:: jinja
|
176 |
-
|
177 |
-
{% extends ['layout.html', 'base_layout.html'] %}
|
178 |
-
|
179 |
-
Conditional Inheritance
|
180 |
-
-----------------------
|
181 |
-
|
182 |
-
As the template name for the parent can be any valid Twig expression, it's
|
183 |
-
possible to make the inheritance mechanism conditional:
|
184 |
-
|
185 |
-
.. code-block:: jinja
|
186 |
-
|
187 |
-
{% extends standalone ? "minimum.html" : "base.html" %}
|
188 |
-
|
189 |
-
In this example, the template will extend the "minimum.html" layout template
|
190 |
-
if the ``standalone`` variable evaluates to ``true``, and "base.html"
|
191 |
-
otherwise.
|
192 |
-
|
193 |
-
How do blocks work?
|
194 |
-
-------------------
|
195 |
-
|
196 |
-
A block provides a way to change how a certain part of a template is rendered
|
197 |
-
but it does not interfere in any way with the logic around it.
|
198 |
-
|
199 |
-
Let's take the following example to illustrate how a block works and more
|
200 |
-
importantly, how it does not work:
|
201 |
-
|
202 |
-
.. code-block:: jinja
|
203 |
-
|
204 |
-
{# base.twig #}
|
205 |
-
|
206 |
-
{% for post in posts %}
|
207 |
-
{% block post %}
|
208 |
-
<h1>{{ post.title }}</h1>
|
209 |
-
<p>{{ post.body }}</p>
|
210 |
-
{% endblock %}
|
211 |
-
{% endfor %}
|
212 |
-
|
213 |
-
If you render this template, the result would be exactly the same with or
|
214 |
-
without the ``block`` tag. The ``block`` inside the ``for`` loop is just a way
|
215 |
-
to make it overridable by a child template:
|
216 |
-
|
217 |
-
.. code-block:: jinja
|
218 |
-
|
219 |
-
{# child.twig #}
|
220 |
-
|
221 |
-
{% extends "base.twig" %}
|
222 |
-
|
223 |
-
{% block post %}
|
224 |
-
<article>
|
225 |
-
<header>{{ post.title }}</header>
|
226 |
-
<section>{{ post.text }}</section>
|
227 |
-
</article>
|
228 |
-
{% endblock %}
|
229 |
-
|
230 |
-
Now, when rendering the child template, the loop is going to use the block
|
231 |
-
defined in the child template instead of the one defined in the base one; the
|
232 |
-
executed template is then equivalent to the following one:
|
233 |
-
|
234 |
-
.. code-block:: jinja
|
235 |
-
|
236 |
-
{% for post in posts %}
|
237 |
-
<article>
|
238 |
-
<header>{{ post.title }}</header>
|
239 |
-
<section>{{ post.text }}</section>
|
240 |
-
</article>
|
241 |
-
{% endfor %}
|
242 |
-
|
243 |
-
Let's take another example: a block included within an ``if`` statement:
|
244 |
-
|
245 |
-
.. code-block:: jinja
|
246 |
-
|
247 |
-
{% if posts is empty %}
|
248 |
-
{% block head %}
|
249 |
-
{{ parent() }}
|
250 |
-
|
251 |
-
<meta name="robots" content="noindex, follow">
|
252 |
-
{% endblock head %}
|
253 |
-
{% endif %}
|
254 |
-
|
255 |
-
Contrary to what you might think, this template does not define a block
|
256 |
-
conditionally; it just makes overridable by a child template the output of
|
257 |
-
what will be rendered when the condition is ``true``.
|
258 |
-
|
259 |
-
If you want the output to be displayed conditionally, use the following
|
260 |
-
instead:
|
261 |
-
|
262 |
-
.. code-block:: jinja
|
263 |
-
|
264 |
-
{% block head %}
|
265 |
-
{{ parent() }}
|
266 |
-
|
267 |
-
{% if posts is empty %}
|
268 |
-
<meta name="robots" content="noindex, follow">
|
269 |
-
{% endif %}
|
270 |
-
{% endblock head %}
|
271 |
-
|
272 |
-
.. seealso:: :doc:`block<../functions/block>`, :doc:`block<../tags/block>`, :doc:`parent<../functions/parent>`, :doc:`use<../tags/use>`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/filter.rst
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
``filter``
|
2 |
-
==========
|
3 |
-
|
4 |
-
Filter sections allow you to apply regular Twig filters on a block of template
|
5 |
-
data. Just wrap the code in the special ``filter`` section:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{% filter upper %}
|
10 |
-
This text becomes uppercase
|
11 |
-
{% endfilter %}
|
12 |
-
|
13 |
-
You can also chain filters:
|
14 |
-
|
15 |
-
.. code-block:: jinja
|
16 |
-
|
17 |
-
{% filter lower|escape %}
|
18 |
-
<strong>SOME TEXT</strong>
|
19 |
-
{% endfilter %}
|
20 |
-
|
21 |
-
{# outputs "<strong>some text</strong>" #}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/flush.rst
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
``flush``
|
2 |
-
=========
|
3 |
-
|
4 |
-
.. versionadded:: 1.5
|
5 |
-
The flush tag was added in Twig 1.5.
|
6 |
-
|
7 |
-
The ``flush`` tag tells Twig to flush the output buffer:
|
8 |
-
|
9 |
-
.. code-block:: jinja
|
10 |
-
|
11 |
-
{% flush %}
|
12 |
-
|
13 |
-
.. note::
|
14 |
-
|
15 |
-
Internally, Twig uses the PHP `flush`_ function.
|
16 |
-
|
17 |
-
.. _`flush`: http://php.net/flush
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/for.rst
DELETED
@@ -1,172 +0,0 @@
|
|
1 |
-
``for``
|
2 |
-
=======
|
3 |
-
|
4 |
-
Loop over each item in a sequence. For example, to display a list of users
|
5 |
-
provided in a variable called ``users``:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
<h1>Members</h1>
|
10 |
-
<ul>
|
11 |
-
{% for user in users %}
|
12 |
-
<li>{{ user.username|e }}</li>
|
13 |
-
{% endfor %}
|
14 |
-
</ul>
|
15 |
-
|
16 |
-
.. note::
|
17 |
-
|
18 |
-
A sequence can be either an array or an object implementing the
|
19 |
-
``Traversable`` interface.
|
20 |
-
|
21 |
-
If you do need to iterate over a sequence of numbers, you can use the ``..``
|
22 |
-
operator:
|
23 |
-
|
24 |
-
.. code-block:: jinja
|
25 |
-
|
26 |
-
{% for i in 0..10 %}
|
27 |
-
* {{ i }}
|
28 |
-
{% endfor %}
|
29 |
-
|
30 |
-
The above snippet of code would print all numbers from 0 to 10.
|
31 |
-
|
32 |
-
It can be also useful with letters:
|
33 |
-
|
34 |
-
.. code-block:: jinja
|
35 |
-
|
36 |
-
{% for letter in 'a'..'z' %}
|
37 |
-
* {{ letter }}
|
38 |
-
{% endfor %}
|
39 |
-
|
40 |
-
The ``..`` operator can take any expression at both sides:
|
41 |
-
|
42 |
-
.. code-block:: jinja
|
43 |
-
|
44 |
-
{% for letter in 'a'|upper..'z'|upper %}
|
45 |
-
* {{ letter }}
|
46 |
-
{% endfor %}
|
47 |
-
|
48 |
-
.. tip:
|
49 |
-
|
50 |
-
If you need a step different from 1, you can use the ``range`` function
|
51 |
-
instead.
|
52 |
-
|
53 |
-
The `loop` variable
|
54 |
-
-------------------
|
55 |
-
|
56 |
-
Inside of a ``for`` loop block you can access some special variables:
|
57 |
-
|
58 |
-
===================== =============================================================
|
59 |
-
Variable Description
|
60 |
-
===================== =============================================================
|
61 |
-
``loop.index`` The current iteration of the loop. (1 indexed)
|
62 |
-
``loop.index0`` The current iteration of the loop. (0 indexed)
|
63 |
-
``loop.revindex`` The number of iterations from the end of the loop (1 indexed)
|
64 |
-
``loop.revindex0`` The number of iterations from the end of the loop (0 indexed)
|
65 |
-
``loop.first`` True if first iteration
|
66 |
-
``loop.last`` True if last iteration
|
67 |
-
``loop.length`` The number of items in the sequence
|
68 |
-
``loop.parent`` The parent context
|
69 |
-
===================== =============================================================
|
70 |
-
|
71 |
-
.. code-block:: jinja
|
72 |
-
|
73 |
-
{% for user in users %}
|
74 |
-
{{ loop.index }} - {{ user.username }}
|
75 |
-
{% endfor %}
|
76 |
-
|
77 |
-
.. note::
|
78 |
-
|
79 |
-
The ``loop.length``, ``loop.revindex``, ``loop.revindex0``, and
|
80 |
-
``loop.last`` variables are only available for PHP arrays, or objects that
|
81 |
-
implement the ``Countable`` interface. They are also not available when
|
82 |
-
looping with a condition.
|
83 |
-
|
84 |
-
.. versionadded:: 1.2
|
85 |
-
The ``if`` modifier support has been added in Twig 1.2.
|
86 |
-
|
87 |
-
Adding a condition
|
88 |
-
------------------
|
89 |
-
|
90 |
-
Unlike in PHP, it's not possible to ``break`` or ``continue`` in a loop. You
|
91 |
-
can however filter the sequence during iteration which allows you to skip
|
92 |
-
items. The following example skips all the users which are not active:
|
93 |
-
|
94 |
-
.. code-block:: jinja
|
95 |
-
|
96 |
-
<ul>
|
97 |
-
{% for user in users if user.active %}
|
98 |
-
<li>{{ user.username|e }}</li>
|
99 |
-
{% endfor %}
|
100 |
-
</ul>
|
101 |
-
|
102 |
-
The advantage is that the special loop variable will count correctly thus not
|
103 |
-
counting the users not iterated over. Keep in mind that properties like
|
104 |
-
``loop.last`` will not be defined when using loop conditions.
|
105 |
-
|
106 |
-
.. note::
|
107 |
-
|
108 |
-
Using the ``loop`` variable within the condition is not recommended as it
|
109 |
-
will probably not be doing what you expect it to. For instance, adding a
|
110 |
-
condition like ``loop.index > 4`` won't work as the index is only
|
111 |
-
incremented when the condition is true (so the condition will never
|
112 |
-
match).
|
113 |
-
|
114 |
-
The `else` Clause
|
115 |
-
-----------------
|
116 |
-
|
117 |
-
If no iteration took place because the sequence was empty, you can render a
|
118 |
-
replacement block by using ``else``:
|
119 |
-
|
120 |
-
.. code-block:: jinja
|
121 |
-
|
122 |
-
<ul>
|
123 |
-
{% for user in users %}
|
124 |
-
<li>{{ user.username|e }}</li>
|
125 |
-
{% else %}
|
126 |
-
<li><em>no user found</em></li>
|
127 |
-
{% endfor %}
|
128 |
-
</ul>
|
129 |
-
|
130 |
-
Iterating over Keys
|
131 |
-
-------------------
|
132 |
-
|
133 |
-
By default, a loop iterates over the values of the sequence. You can iterate
|
134 |
-
on keys by using the ``keys`` filter:
|
135 |
-
|
136 |
-
.. code-block:: jinja
|
137 |
-
|
138 |
-
<h1>Members</h1>
|
139 |
-
<ul>
|
140 |
-
{% for key in users|keys %}
|
141 |
-
<li>{{ key }}</li>
|
142 |
-
{% endfor %}
|
143 |
-
</ul>
|
144 |
-
|
145 |
-
Iterating over Keys and Values
|
146 |
-
------------------------------
|
147 |
-
|
148 |
-
You can also access both keys and values:
|
149 |
-
|
150 |
-
.. code-block:: jinja
|
151 |
-
|
152 |
-
<h1>Members</h1>
|
153 |
-
<ul>
|
154 |
-
{% for key, user in users %}
|
155 |
-
<li>{{ key }}: {{ user.username|e }}</li>
|
156 |
-
{% endfor %}
|
157 |
-
</ul>
|
158 |
-
|
159 |
-
Iterating over a Subset
|
160 |
-
-----------------------
|
161 |
-
|
162 |
-
You might want to iterate over a subset of values. This can be achieved using
|
163 |
-
the :doc:`slice <../filters/slice>` filter:
|
164 |
-
|
165 |
-
.. code-block:: jinja
|
166 |
-
|
167 |
-
<h1>Top Ten Members</h1>
|
168 |
-
<ul>
|
169 |
-
{% for user in users|slice(0, 10) %}
|
170 |
-
<li>{{ user.username|e }}</li>
|
171 |
-
{% endfor %}
|
172 |
-
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/from.rst
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
``from``
|
2 |
-
========
|
3 |
-
|
4 |
-
The ``from`` tag imports :doc:`macro<../tags/macro>` names into the current
|
5 |
-
namespace. The tag is documented in detail in the documentation for the
|
6 |
-
:doc:`import<../tags/import>` tag.
|
7 |
-
|
8 |
-
.. seealso:: :doc:`macro<../tags/macro>`, :doc:`import<../tags/import>`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/if.rst
DELETED
@@ -1,76 +0,0 @@
|
|
1 |
-
``if``
|
2 |
-
======
|
3 |
-
|
4 |
-
The ``if`` statement in Twig is comparable with the if statements of PHP.
|
5 |
-
|
6 |
-
In the simplest form you can use it to test if an expression evaluates to
|
7 |
-
``true``:
|
8 |
-
|
9 |
-
.. code-block:: jinja
|
10 |
-
|
11 |
-
{% if online == false %}
|
12 |
-
<p>Our website is in maintenance mode. Please, come back later.</p>
|
13 |
-
{% endif %}
|
14 |
-
|
15 |
-
You can also test if an array is not empty:
|
16 |
-
|
17 |
-
.. code-block:: jinja
|
18 |
-
|
19 |
-
{% if users %}
|
20 |
-
<ul>
|
21 |
-
{% for user in users %}
|
22 |
-
<li>{{ user.username|e }}</li>
|
23 |
-
{% endfor %}
|
24 |
-
</ul>
|
25 |
-
{% endif %}
|
26 |
-
|
27 |
-
.. note::
|
28 |
-
|
29 |
-
If you want to test if the variable is defined, use ``if users is
|
30 |
-
defined`` instead.
|
31 |
-
|
32 |
-
You can also use ``not`` to check for values that evaluate to ``false``:
|
33 |
-
|
34 |
-
.. code-block:: jinja
|
35 |
-
|
36 |
-
{% if not user.subscribed %}
|
37 |
-
<p>You are not subscribed to our mailing list.</p>
|
38 |
-
{% endif %}
|
39 |
-
|
40 |
-
For multiple conditions, ``and`` and ``or`` can be used:
|
41 |
-
|
42 |
-
.. code-block:: jinja
|
43 |
-
|
44 |
-
{% if temperature > 18 and temperature < 27 %}
|
45 |
-
<p>It's a nice day for a walk in the park.</p>
|
46 |
-
{% endif %}
|
47 |
-
|
48 |
-
For multiple branches ``elseif`` and ``else`` can be used like in PHP. You can
|
49 |
-
use more complex ``expressions`` there too:
|
50 |
-
|
51 |
-
.. code-block:: jinja
|
52 |
-
|
53 |
-
{% if kenny.sick %}
|
54 |
-
Kenny is sick.
|
55 |
-
{% elseif kenny.dead %}
|
56 |
-
You killed Kenny! You bastard!!!
|
57 |
-
{% else %}
|
58 |
-
Kenny looks okay --- so far
|
59 |
-
{% endif %}
|
60 |
-
|
61 |
-
.. note::
|
62 |
-
|
63 |
-
The rules to determine if an expression is ``true`` or ``false`` are the
|
64 |
-
same as in PHP; here are the edge cases rules:
|
65 |
-
|
66 |
-
====================== ====================
|
67 |
-
Value Boolean evaluation
|
68 |
-
====================== ====================
|
69 |
-
empty string false
|
70 |
-
numeric zero false
|
71 |
-
whitespace-only string true
|
72 |
-
empty array false
|
73 |
-
null false
|
74 |
-
non-empty array true
|
75 |
-
object true
|
76 |
-
====================== ====================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/import.rst
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
``import``
|
2 |
-
==========
|
3 |
-
|
4 |
-
Twig supports putting often used code into :doc:`macros<../tags/macro>`. These
|
5 |
-
macros can go into different templates and get imported from there.
|
6 |
-
|
7 |
-
There are two ways to import templates. You can import the complete template
|
8 |
-
into a variable or request specific macros from it.
|
9 |
-
|
10 |
-
Imagine we have a helper module that renders forms (called ``forms.html``):
|
11 |
-
|
12 |
-
.. code-block:: jinja
|
13 |
-
|
14 |
-
{% macro input(name, value, type, size) %}
|
15 |
-
<input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
|
16 |
-
{% endmacro %}
|
17 |
-
|
18 |
-
{% macro textarea(name, value, rows, cols) %}
|
19 |
-
<textarea name="{{ name }}" rows="{{ rows|default(10) }}" cols="{{ cols|default(40) }}">{{ value|e }}</textarea>
|
20 |
-
{% endmacro %}
|
21 |
-
|
22 |
-
The easiest and most flexible is importing the whole module into a variable.
|
23 |
-
That way you can access the attributes:
|
24 |
-
|
25 |
-
.. code-block:: jinja
|
26 |
-
|
27 |
-
{% import 'forms.html' as forms %}
|
28 |
-
|
29 |
-
<dl>
|
30 |
-
<dt>Username</dt>
|
31 |
-
<dd>{{ forms.input('username') }}</dd>
|
32 |
-
<dt>Password</dt>
|
33 |
-
<dd>{{ forms.input('password', null, 'password') }}</dd>
|
34 |
-
</dl>
|
35 |
-
<p>{{ forms.textarea('comment') }}</p>
|
36 |
-
|
37 |
-
Alternatively you can import names from the template into the current
|
38 |
-
namespace:
|
39 |
-
|
40 |
-
.. code-block:: jinja
|
41 |
-
|
42 |
-
{% from 'forms.html' import input as input_field, textarea %}
|
43 |
-
|
44 |
-
<dl>
|
45 |
-
<dt>Username</dt>
|
46 |
-
<dd>{{ input_field('username') }}</dd>
|
47 |
-
<dt>Password</dt>
|
48 |
-
<dd>{{ input_field('password', '', 'password') }}</dd>
|
49 |
-
</dl>
|
50 |
-
<p>{{ textarea('comment') }}</p>
|
51 |
-
|
52 |
-
.. tip::
|
53 |
-
|
54 |
-
To import macros from the current file, use the special ``_self`` variable
|
55 |
-
for the source.
|
56 |
-
|
57 |
-
.. seealso:: :doc:`macro<../tags/macro>`, :doc:`from<../tags/from>`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/include.rst
DELETED
@@ -1,90 +0,0 @@
|
|
1 |
-
``include``
|
2 |
-
===========
|
3 |
-
|
4 |
-
The ``include`` statement includes a template and returns the rendered content
|
5 |
-
of that file into the current namespace:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{% include 'header.html' %}
|
10 |
-
Body
|
11 |
-
{% include 'footer.html' %}
|
12 |
-
|
13 |
-
Included templates have access to the variables of the active context.
|
14 |
-
|
15 |
-
If you are using the filesystem loader, the templates are looked for in the
|
16 |
-
paths defined by it.
|
17 |
-
|
18 |
-
You can add additional variables by passing them after the ``with`` keyword:
|
19 |
-
|
20 |
-
.. code-block:: jinja
|
21 |
-
|
22 |
-
{# template.html will have access to the variables from the current context and the additional ones provided #}
|
23 |
-
{% include 'template.html' with {'foo': 'bar'} %}
|
24 |
-
|
25 |
-
{% set vars = {'foo': 'bar'} %}
|
26 |
-
{% include 'template.html' with vars %}
|
27 |
-
|
28 |
-
You can disable access to the context by appending the ``only`` keyword:
|
29 |
-
|
30 |
-
.. code-block:: jinja
|
31 |
-
|
32 |
-
{# only the foo variable will be accessible #}
|
33 |
-
{% include 'template.html' with {'foo': 'bar'} only %}
|
34 |
-
|
35 |
-
.. code-block:: jinja
|
36 |
-
|
37 |
-
{# no variables will be accessible #}
|
38 |
-
{% include 'template.html' only %}
|
39 |
-
|
40 |
-
.. tip::
|
41 |
-
|
42 |
-
When including a template created by an end user, you should consider
|
43 |
-
sandboxing it. More information in the :doc:`Twig for Developers<../api>`
|
44 |
-
chapter and in the :doc:`sandbox<../tags/sandbox>` tag documentation.
|
45 |
-
|
46 |
-
The template name can be any valid Twig expression:
|
47 |
-
|
48 |
-
.. code-block:: jinja
|
49 |
-
|
50 |
-
{% include some_var %}
|
51 |
-
{% include ajax ? 'ajax.html' : 'not_ajax.html' %}
|
52 |
-
|
53 |
-
And if the expression evaluates to a ``Twig_Template`` or a
|
54 |
-
``Twig_TemplateWrapper`` instance, Twig will use it directly::
|
55 |
-
|
56 |
-
// {% include template %}
|
57 |
-
|
58 |
-
// deprecated as of Twig 1.28
|
59 |
-
$template = $twig->loadTemplate('some_template.twig');
|
60 |
-
|
61 |
-
// as of Twig 1.28
|
62 |
-
$template = $twig->load('some_template.twig');
|
63 |
-
|
64 |
-
$twig->display('template.twig', array('template' => $template));
|
65 |
-
|
66 |
-
.. versionadded:: 1.2
|
67 |
-
The ``ignore missing`` feature has been added in Twig 1.2.
|
68 |
-
|
69 |
-
You can mark an include with ``ignore missing`` in which case Twig will ignore
|
70 |
-
the statement if the template to be included does not exist. It has to be
|
71 |
-
placed just after the template name. Here some valid examples:
|
72 |
-
|
73 |
-
.. code-block:: jinja
|
74 |
-
|
75 |
-
{% include 'sidebar.html' ignore missing %}
|
76 |
-
{% include 'sidebar.html' ignore missing with {'foo': 'bar'} %}
|
77 |
-
{% include 'sidebar.html' ignore missing only %}
|
78 |
-
|
79 |
-
.. versionadded:: 1.2
|
80 |
-
The possibility to pass an array of templates has been added in Twig 1.2.
|
81 |
-
|
82 |
-
You can also provide a list of templates that are checked for existence before
|
83 |
-
inclusion. The first template that exists will be included:
|
84 |
-
|
85 |
-
.. code-block:: jinja
|
86 |
-
|
87 |
-
{% include ['page_detailed.html', 'page.html'] %}
|
88 |
-
|
89 |
-
If ``ignore missing`` is given, it will fall back to rendering nothing if none
|
90 |
-
of the templates exist, otherwise it will throw an exception.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/index.rst
DELETED
@@ -1,25 +0,0 @@
|
|
1 |
-
Tags
|
2 |
-
====
|
3 |
-
|
4 |
-
.. toctree::
|
5 |
-
:maxdepth: 1
|
6 |
-
|
7 |
-
autoescape
|
8 |
-
block
|
9 |
-
do
|
10 |
-
embed
|
11 |
-
extends
|
12 |
-
filter
|
13 |
-
flush
|
14 |
-
for
|
15 |
-
from
|
16 |
-
if
|
17 |
-
import
|
18 |
-
include
|
19 |
-
macro
|
20 |
-
sandbox
|
21 |
-
set
|
22 |
-
spaceless
|
23 |
-
use
|
24 |
-
verbatim
|
25 |
-
with
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/macro.rst
DELETED
@@ -1,103 +0,0 @@
|
|
1 |
-
``macro``
|
2 |
-
=========
|
3 |
-
|
4 |
-
Macros are comparable with functions in regular programming languages. They
|
5 |
-
are useful to put often used HTML idioms into reusable elements to not repeat
|
6 |
-
yourself.
|
7 |
-
|
8 |
-
Here is a small example of a macro that renders a form element:
|
9 |
-
|
10 |
-
.. code-block:: jinja
|
11 |
-
|
12 |
-
{% macro input(name, value, type, size) %}
|
13 |
-
<input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
|
14 |
-
{% endmacro %}
|
15 |
-
|
16 |
-
Macros differ from native PHP functions in a few ways:
|
17 |
-
|
18 |
-
* Default argument values are defined by using the ``default`` filter in the
|
19 |
-
macro body;
|
20 |
-
|
21 |
-
* Arguments of a macro are always optional.
|
22 |
-
|
23 |
-
* If extra positional arguments are passed to a macro, they end up in the
|
24 |
-
special ``varargs`` variable as a list of values.
|
25 |
-
|
26 |
-
But as with PHP functions, macros don't have access to the current template
|
27 |
-
variables.
|
28 |
-
|
29 |
-
.. tip::
|
30 |
-
|
31 |
-
You can pass the whole context as an argument by using the special
|
32 |
-
``_context`` variable.
|
33 |
-
|
34 |
-
Import
|
35 |
-
------
|
36 |
-
|
37 |
-
Macros can be defined in any template, and need to be "imported" before being
|
38 |
-
used (see the documentation for the :doc:`import<../tags/import>` tag for more
|
39 |
-
information):
|
40 |
-
|
41 |
-
.. code-block:: jinja
|
42 |
-
|
43 |
-
{% import "forms.html" as forms %}
|
44 |
-
|
45 |
-
The above ``import`` call imports the "forms.html" file (which can contain only
|
46 |
-
macros, or a template and some macros), and import the functions as items of
|
47 |
-
the ``forms`` variable.
|
48 |
-
|
49 |
-
The macro can then be called at will:
|
50 |
-
|
51 |
-
.. code-block:: jinja
|
52 |
-
|
53 |
-
<p>{{ forms.input('username') }}</p>
|
54 |
-
<p>{{ forms.input('password', null, 'password') }}</p>
|
55 |
-
|
56 |
-
If macros are defined and used in the same template, you can use the
|
57 |
-
special ``_self`` variable to import them:
|
58 |
-
|
59 |
-
.. code-block:: jinja
|
60 |
-
|
61 |
-
{% import _self as forms %}
|
62 |
-
|
63 |
-
<p>{{ forms.input('username') }}</p>
|
64 |
-
|
65 |
-
.. warning::
|
66 |
-
|
67 |
-
When you define a macro in the template where you are going to use it, you
|
68 |
-
might be tempted to call the macro directly via ``_self.input()`` instead
|
69 |
-
of importing it; even if seems to work, this is just a side-effect of the
|
70 |
-
current implementation and it won't work anymore in Twig 2.x.
|
71 |
-
|
72 |
-
When you want to use a macro in another macro from the same file, you need to
|
73 |
-
import it locally:
|
74 |
-
|
75 |
-
.. code-block:: jinja
|
76 |
-
|
77 |
-
{% macro input(name, value, type, size) %}
|
78 |
-
<input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
|
79 |
-
{% endmacro %}
|
80 |
-
|
81 |
-
{% macro wrapped_input(name, value, type, size) %}
|
82 |
-
{% import _self as forms %}
|
83 |
-
|
84 |
-
<div class="field">
|
85 |
-
{{ forms.input(name, value, type, size) }}
|
86 |
-
</div>
|
87 |
-
{% endmacro %}
|
88 |
-
|
89 |
-
Named Macro End-Tags
|
90 |
-
--------------------
|
91 |
-
|
92 |
-
Twig allows you to put the name of the macro after the end tag for better
|
93 |
-
readability:
|
94 |
-
|
95 |
-
.. code-block:: jinja
|
96 |
-
|
97 |
-
{% macro input() %}
|
98 |
-
...
|
99 |
-
{% endmacro input %}
|
100 |
-
|
101 |
-
Of course, the name after the ``endmacro`` word must match the macro name.
|
102 |
-
|
103 |
-
.. seealso:: :doc:`from<../tags/from>`, :doc:`import<../tags/import>`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/sandbox.rst
DELETED
@@ -1,30 +0,0 @@
|
|
1 |
-
``sandbox``
|
2 |
-
===========
|
3 |
-
|
4 |
-
The ``sandbox`` tag can be used to enable the sandboxing mode for an included
|
5 |
-
template, when sandboxing is not enabled globally for the Twig environment:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{% sandbox %}
|
10 |
-
{% include 'user.html' %}
|
11 |
-
{% endsandbox %}
|
12 |
-
|
13 |
-
.. warning::
|
14 |
-
|
15 |
-
The ``sandbox`` tag is only available when the sandbox extension is
|
16 |
-
enabled (see the :doc:`Twig for Developers<../api>` chapter).
|
17 |
-
|
18 |
-
.. note::
|
19 |
-
|
20 |
-
The ``sandbox`` tag can only be used to sandbox an include tag and it
|
21 |
-
cannot be used to sandbox a section of a template. The following example
|
22 |
-
won't work:
|
23 |
-
|
24 |
-
.. code-block:: jinja
|
25 |
-
|
26 |
-
{% sandbox %}
|
27 |
-
{% for i in 1..2 %}
|
28 |
-
{{ i }}
|
29 |
-
{% endfor %}
|
30 |
-
{% endsandbox %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/set.rst
DELETED
@@ -1,78 +0,0 @@
|
|
1 |
-
``set``
|
2 |
-
=======
|
3 |
-
|
4 |
-
Inside code blocks you can also assign values to variables. Assignments use
|
5 |
-
the ``set`` tag and can have multiple targets.
|
6 |
-
|
7 |
-
Here is how you can assign the ``bar`` value to the ``foo`` variable:
|
8 |
-
|
9 |
-
.. code-block:: jinja
|
10 |
-
|
11 |
-
{% set foo = 'bar' %}
|
12 |
-
|
13 |
-
After the ``set`` call, the ``foo`` variable is available in the template like
|
14 |
-
any other ones:
|
15 |
-
|
16 |
-
.. code-block:: jinja
|
17 |
-
|
18 |
-
{# displays bar #}
|
19 |
-
{{ foo }}
|
20 |
-
|
21 |
-
The assigned value can be any valid :ref:`Twig expressions
|
22 |
-
<twig-expressions>`:
|
23 |
-
|
24 |
-
.. code-block:: jinja
|
25 |
-
|
26 |
-
{% set foo = [1, 2] %}
|
27 |
-
{% set foo = {'foo': 'bar'} %}
|
28 |
-
{% set foo = 'foo' ~ 'bar' %}
|
29 |
-
|
30 |
-
Several variables can be assigned in one block:
|
31 |
-
|
32 |
-
.. code-block:: jinja
|
33 |
-
|
34 |
-
{% set foo, bar = 'foo', 'bar' %}
|
35 |
-
|
36 |
-
{# is equivalent to #}
|
37 |
-
|
38 |
-
{% set foo = 'foo' %}
|
39 |
-
{% set bar = 'bar' %}
|
40 |
-
|
41 |
-
The ``set`` tag can also be used to 'capture' chunks of text:
|
42 |
-
|
43 |
-
.. code-block:: jinja
|
44 |
-
|
45 |
-
{% set foo %}
|
46 |
-
<div id="pagination">
|
47 |
-
...
|
48 |
-
</div>
|
49 |
-
{% endset %}
|
50 |
-
|
51 |
-
.. caution::
|
52 |
-
|
53 |
-
If you enable automatic output escaping, Twig will only consider the
|
54 |
-
content to be safe when capturing chunks of text.
|
55 |
-
|
56 |
-
.. note::
|
57 |
-
|
58 |
-
Note that loops are scoped in Twig; therefore a variable declared inside a
|
59 |
-
``for`` loop is not accessible outside the loop itself:
|
60 |
-
|
61 |
-
.. code-block:: jinja
|
62 |
-
|
63 |
-
{% for item in list %}
|
64 |
-
{% set foo = item %}
|
65 |
-
{% endfor %}
|
66 |
-
|
67 |
-
{# foo is NOT available #}
|
68 |
-
|
69 |
-
If you want to access the variable, just declare it before the loop:
|
70 |
-
|
71 |
-
.. code-block:: jinja
|
72 |
-
|
73 |
-
{% set foo = "" %}
|
74 |
-
{% for item in list %}
|
75 |
-
{% set foo = item %}
|
76 |
-
{% endfor %}
|
77 |
-
|
78 |
-
{# foo is available #}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/spaceless.rst
DELETED
@@ -1,37 +0,0 @@
|
|
1 |
-
``spaceless``
|
2 |
-
=============
|
3 |
-
|
4 |
-
Use the ``spaceless`` tag to remove whitespace *between HTML tags*, not
|
5 |
-
whitespace within HTML tags or whitespace in plain text:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{% spaceless %}
|
10 |
-
<div>
|
11 |
-
<strong>foo</strong>
|
12 |
-
</div>
|
13 |
-
{% endspaceless %}
|
14 |
-
|
15 |
-
{# output will be <div><strong>foo</strong></div> #}
|
16 |
-
|
17 |
-
This tag is not meant to "optimize" the size of the generated HTML content but
|
18 |
-
merely to avoid extra whitespace between HTML tags to avoid browser rendering
|
19 |
-
quirks under some circumstances.
|
20 |
-
|
21 |
-
.. tip::
|
22 |
-
|
23 |
-
If you want to optimize the size of the generated HTML content, gzip
|
24 |
-
compress the output instead.
|
25 |
-
|
26 |
-
.. tip::
|
27 |
-
|
28 |
-
If you want to create a tag that actually removes all extra whitespace in
|
29 |
-
an HTML string, be warned that this is not as easy as it seems to be
|
30 |
-
(think of ``textarea`` or ``pre`` tags for instance). Using a third-party
|
31 |
-
library like Tidy is probably a better idea.
|
32 |
-
|
33 |
-
.. tip::
|
34 |
-
|
35 |
-
For more information on whitespace control, read the
|
36 |
-
:ref:`dedicated section <templates-whitespace-control>` of the documentation and learn how
|
37 |
-
you can also use the whitespace control modifier on your tags.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/use.rst
DELETED
@@ -1,124 +0,0 @@
|
|
1 |
-
``use``
|
2 |
-
=======
|
3 |
-
|
4 |
-
.. versionadded:: 1.1
|
5 |
-
Horizontal reuse was added in Twig 1.1.
|
6 |
-
|
7 |
-
.. note::
|
8 |
-
|
9 |
-
Horizontal reuse is an advanced Twig feature that is hardly ever needed in
|
10 |
-
regular templates. It is mainly used by projects that need to make
|
11 |
-
template blocks reusable without using inheritance.
|
12 |
-
|
13 |
-
Template inheritance is one of the most powerful features of Twig but it is
|
14 |
-
limited to single inheritance; a template can only extend one other template.
|
15 |
-
This limitation makes template inheritance simple to understand and easy to
|
16 |
-
debug:
|
17 |
-
|
18 |
-
.. code-block:: jinja
|
19 |
-
|
20 |
-
{% extends "base.html" %}
|
21 |
-
|
22 |
-
{% block title %}{% endblock %}
|
23 |
-
{% block content %}{% endblock %}
|
24 |
-
|
25 |
-
Horizontal reuse is a way to achieve the same goal as multiple inheritance,
|
26 |
-
but without the associated complexity:
|
27 |
-
|
28 |
-
.. code-block:: jinja
|
29 |
-
|
30 |
-
{% extends "base.html" %}
|
31 |
-
|
32 |
-
{% use "blocks.html" %}
|
33 |
-
|
34 |
-
{% block title %}{% endblock %}
|
35 |
-
{% block content %}{% endblock %}
|
36 |
-
|
37 |
-
The ``use`` statement tells Twig to import the blocks defined in
|
38 |
-
``blocks.html`` into the current template (it's like macros, but for blocks):
|
39 |
-
|
40 |
-
.. code-block:: jinja
|
41 |
-
|
42 |
-
{# blocks.html #}
|
43 |
-
|
44 |
-
{% block sidebar %}{% endblock %}
|
45 |
-
|
46 |
-
In this example, the ``use`` statement imports the ``sidebar`` block into the
|
47 |
-
main template. The code is mostly equivalent to the following one (the
|
48 |
-
imported blocks are not outputted automatically):
|
49 |
-
|
50 |
-
.. code-block:: jinja
|
51 |
-
|
52 |
-
{% extends "base.html" %}
|
53 |
-
|
54 |
-
{% block sidebar %}{% endblock %}
|
55 |
-
{% block title %}{% endblock %}
|
56 |
-
{% block content %}{% endblock %}
|
57 |
-
|
58 |
-
.. note::
|
59 |
-
|
60 |
-
The ``use`` tag only imports a template if it does not extend another
|
61 |
-
template, if it does not define macros, and if the body is empty. But it
|
62 |
-
can *use* other templates.
|
63 |
-
|
64 |
-
.. note::
|
65 |
-
|
66 |
-
Because ``use`` statements are resolved independently of the context
|
67 |
-
passed to the template, the template reference cannot be an expression.
|
68 |
-
|
69 |
-
The main template can also override any imported block. If the template
|
70 |
-
already defines the ``sidebar`` block, then the one defined in ``blocks.html``
|
71 |
-
is ignored. To avoid name conflicts, you can rename imported blocks:
|
72 |
-
|
73 |
-
.. code-block:: jinja
|
74 |
-
|
75 |
-
{% extends "base.html" %}
|
76 |
-
|
77 |
-
{% use "blocks.html" with sidebar as base_sidebar, title as base_title %}
|
78 |
-
|
79 |
-
{% block sidebar %}{% endblock %}
|
80 |
-
{% block title %}{% endblock %}
|
81 |
-
{% block content %}{% endblock %}
|
82 |
-
|
83 |
-
.. versionadded:: 1.3
|
84 |
-
The ``parent()`` support was added in Twig 1.3.
|
85 |
-
|
86 |
-
The ``parent()`` function automatically determines the correct inheritance
|
87 |
-
tree, so it can be used when overriding a block defined in an imported
|
88 |
-
template:
|
89 |
-
|
90 |
-
.. code-block:: jinja
|
91 |
-
|
92 |
-
{% extends "base.html" %}
|
93 |
-
|
94 |
-
{% use "blocks.html" %}
|
95 |
-
|
96 |
-
{% block sidebar %}
|
97 |
-
{{ parent() }}
|
98 |
-
{% endblock %}
|
99 |
-
|
100 |
-
{% block title %}{% endblock %}
|
101 |
-
{% block content %}{% endblock %}
|
102 |
-
|
103 |
-
In this example, ``parent()`` will correctly call the ``sidebar`` block from
|
104 |
-
the ``blocks.html`` template.
|
105 |
-
|
106 |
-
.. tip::
|
107 |
-
|
108 |
-
In Twig 1.2, renaming allows you to simulate inheritance by calling the
|
109 |
-
"parent" block:
|
110 |
-
|
111 |
-
.. code-block:: jinja
|
112 |
-
|
113 |
-
{% extends "base.html" %}
|
114 |
-
|
115 |
-
{% use "blocks.html" with sidebar as parent_sidebar %}
|
116 |
-
|
117 |
-
{% block sidebar %}
|
118 |
-
{{ block('parent_sidebar') }}
|
119 |
-
{% endblock %}
|
120 |
-
|
121 |
-
.. note::
|
122 |
-
|
123 |
-
You can use as many ``use`` statements as you want in any given template.
|
124 |
-
If two imported templates define the same block, the latest one wins.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/verbatim.rst
DELETED
@@ -1,24 +0,0 @@
|
|
1 |
-
``verbatim``
|
2 |
-
============
|
3 |
-
|
4 |
-
.. versionadded:: 1.12
|
5 |
-
The ``verbatim`` tag was added in Twig 1.12 (it was named ``raw`` before).
|
6 |
-
|
7 |
-
The ``verbatim`` tag marks sections as being raw text that should not be
|
8 |
-
parsed. For example to put Twig syntax as example into a template you can use
|
9 |
-
this snippet:
|
10 |
-
|
11 |
-
.. code-block:: jinja
|
12 |
-
|
13 |
-
{% verbatim %}
|
14 |
-
<ul>
|
15 |
-
{% for item in seq %}
|
16 |
-
<li>{{ item }}</li>
|
17 |
-
{% endfor %}
|
18 |
-
</ul>
|
19 |
-
{% endverbatim %}
|
20 |
-
|
21 |
-
.. note::
|
22 |
-
|
23 |
-
The ``verbatim`` tag works in the exact same way as the old ``raw`` tag,
|
24 |
-
but was renamed to avoid confusion with the ``raw`` filter.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tags/with.rst
DELETED
@@ -1,44 +0,0 @@
|
|
1 |
-
``with``
|
2 |
-
========
|
3 |
-
|
4 |
-
.. versionadded:: 1.28
|
5 |
-
The ``with`` tag was added in Twig 1.28.
|
6 |
-
|
7 |
-
Use the ``with`` tag to create a new inner scope. Variables set within this
|
8 |
-
scope are not visible outside of the scope:
|
9 |
-
|
10 |
-
.. code-block:: jinja
|
11 |
-
|
12 |
-
{% with %}
|
13 |
-
{% set foo = 42 %}
|
14 |
-
{{ foo }} foo is 42 here
|
15 |
-
{% endwith %}
|
16 |
-
foo is not visible here any longer
|
17 |
-
|
18 |
-
Instead of defining variables at the beginning of the scope, you can pass a
|
19 |
-
hash of variables you want to define in the ``with`` tag; the previous example
|
20 |
-
is equivalent to the following one:
|
21 |
-
|
22 |
-
.. code-block:: jinja
|
23 |
-
|
24 |
-
{% with { foo: 42 } %}
|
25 |
-
{{ foo }} foo is 42 here
|
26 |
-
{% endwith %}
|
27 |
-
foo is not visible here any longer
|
28 |
-
|
29 |
-
{# it works with any expression that resolves to a hash #}
|
30 |
-
{% set vars = { foo: 42 } %}
|
31 |
-
{% with vars %}
|
32 |
-
...
|
33 |
-
{% endwith %}
|
34 |
-
|
35 |
-
By default, the inner scope has access to the outer scope context; you can
|
36 |
-
disable this behavior by appending the ``only`` keyword:
|
37 |
-
|
38 |
-
.. code-block:: jinja
|
39 |
-
|
40 |
-
{% set bar = 'bar' %}
|
41 |
-
{% with { foo: 42 } only %}
|
42 |
-
{# only foo is defined #}
|
43 |
-
{# bar is not defined #}
|
44 |
-
{% endwith %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/templates.rst
DELETED
@@ -1,908 +0,0 @@
|
|
1 |
-
Twig for Template Designers
|
2 |
-
===========================
|
3 |
-
|
4 |
-
This document describes the syntax and semantics of the template engine and
|
5 |
-
will be most useful as reference to those creating Twig templates.
|
6 |
-
|
7 |
-
Synopsis
|
8 |
-
--------
|
9 |
-
|
10 |
-
A template is simply a text file. It can generate any text-based format (HTML,
|
11 |
-
XML, CSV, LaTeX, etc.). It doesn't have a specific extension, ``.html`` or
|
12 |
-
``.xml`` are just fine.
|
13 |
-
|
14 |
-
A template contains **variables** or **expressions**, which get replaced with
|
15 |
-
values when the template is evaluated, and **tags**, which control the logic
|
16 |
-
of the template.
|
17 |
-
|
18 |
-
Below is a minimal template that illustrates a few basics. We will cover further
|
19 |
-
details later on:
|
20 |
-
|
21 |
-
.. code-block:: html+jinja
|
22 |
-
|
23 |
-
<!DOCTYPE html>
|
24 |
-
<html>
|
25 |
-
<head>
|
26 |
-
<title>My Webpage</title>
|
27 |
-
</head>
|
28 |
-
<body>
|
29 |
-
<ul id="navigation">
|
30 |
-
{% for item in navigation %}
|
31 |
-
<li><a href="{{ item.href }}">{{ item.caption }}</a></li>
|
32 |
-
{% endfor %}
|
33 |
-
</ul>
|
34 |
-
|
35 |
-
<h1>My Webpage</h1>
|
36 |
-
{{ a_variable }}
|
37 |
-
</body>
|
38 |
-
</html>
|
39 |
-
|
40 |
-
There are two kinds of delimiters: ``{% ... %}`` and ``{{ ... }}``. The first
|
41 |
-
one is used to execute statements such as for-loops, the latter prints the
|
42 |
-
result of an expression to the template.
|
43 |
-
|
44 |
-
IDEs Integration
|
45 |
-
----------------
|
46 |
-
|
47 |
-
Many IDEs support syntax highlighting and auto-completion for Twig:
|
48 |
-
|
49 |
-
* *Textmate* via the `Twig bundle`_
|
50 |
-
* *Vim* via the `Jinja syntax plugin`_ or the `vim-twig plugin`_
|
51 |
-
* *Netbeans* via the `Twig syntax plugin`_ (until 7.1, native as of 7.2)
|
52 |
-
* *PhpStorm* (native as of 2.1)
|
53 |
-
* *Eclipse* via the `Twig plugin`_
|
54 |
-
* *Sublime Text* via the `Twig bundle`_
|
55 |
-
* *GtkSourceView* via the `Twig language definition`_ (used by gedit and other projects)
|
56 |
-
* *Coda* and *SubEthaEdit* via the `Twig syntax mode`_
|
57 |
-
* *Coda 2* via the `other Twig syntax mode`_
|
58 |
-
* *Komodo* and *Komodo Edit* via the Twig highlight/syntax check mode
|
59 |
-
* *Notepad++* via the `Notepad++ Twig Highlighter`_
|
60 |
-
* *Emacs* via `web-mode.el`_
|
61 |
-
* *Atom* via the `PHP-twig for atom`_
|
62 |
-
* *Visual Studio Code* via the `Twig pack`_
|
63 |
-
|
64 |
-
Also, `TwigFiddle`_ is an online service that allows you to execute Twig templates
|
65 |
-
from a browser; it supports all versions of Twig.
|
66 |
-
|
67 |
-
Variables
|
68 |
-
---------
|
69 |
-
|
70 |
-
The application passes variables to the templates for manipulation in the
|
71 |
-
template. Variables may have attributes or elements you can access,
|
72 |
-
too. The visual representation of a variable depends heavily on the application providing
|
73 |
-
it.
|
74 |
-
|
75 |
-
You can use a dot (``.``) to access attributes of a variable (methods or
|
76 |
-
properties of a PHP object, or items of a PHP array), or the so-called
|
77 |
-
"subscript" syntax (``[]``):
|
78 |
-
|
79 |
-
.. code-block:: jinja
|
80 |
-
|
81 |
-
{{ foo.bar }}
|
82 |
-
{{ foo['bar'] }}
|
83 |
-
|
84 |
-
When the attribute contains special characters (like ``-`` that would be
|
85 |
-
interpreted as the minus operator), use the ``attribute`` function instead to
|
86 |
-
access the variable attribute:
|
87 |
-
|
88 |
-
.. code-block:: jinja
|
89 |
-
|
90 |
-
{# equivalent to the non-working foo.data-foo #}
|
91 |
-
{{ attribute(foo, 'data-foo') }}
|
92 |
-
|
93 |
-
.. note::
|
94 |
-
|
95 |
-
It's important to know that the curly braces are *not* part of the
|
96 |
-
variable but the print statement. When accessing variables inside tags,
|
97 |
-
don't put the braces around them.
|
98 |
-
|
99 |
-
If a variable or attribute does not exist, you will receive a ``null`` value
|
100 |
-
when the ``strict_variables`` option is set to ``false``; alternatively, if ``strict_variables``
|
101 |
-
is set, Twig will throw an error (see :ref:`environment options<environment_options>`).
|
102 |
-
|
103 |
-
.. sidebar:: Implementation
|
104 |
-
|
105 |
-
For convenience's sake ``foo.bar`` does the following things on the PHP
|
106 |
-
layer:
|
107 |
-
|
108 |
-
* check if ``foo`` is an array and ``bar`` a valid element;
|
109 |
-
* if not, and if ``foo`` is an object, check that ``bar`` is a valid property;
|
110 |
-
* if not, and if ``foo`` is an object, check that ``bar`` is a valid method
|
111 |
-
(even if ``bar`` is the constructor - use ``__construct()`` instead);
|
112 |
-
* if not, and if ``foo`` is an object, check that ``getBar`` is a valid method;
|
113 |
-
* if not, and if ``foo`` is an object, check that ``isBar`` is a valid method;
|
114 |
-
* if not, return a ``null`` value.
|
115 |
-
|
116 |
-
``foo['bar']`` on the other hand only works with PHP arrays:
|
117 |
-
|
118 |
-
* check if ``foo`` is an array and ``bar`` a valid element;
|
119 |
-
* if not, return a ``null`` value.
|
120 |
-
|
121 |
-
.. note::
|
122 |
-
|
123 |
-
If you want to access a dynamic attribute of a variable, use the
|
124 |
-
:doc:`attribute<functions/attribute>` function instead.
|
125 |
-
|
126 |
-
Global Variables
|
127 |
-
~~~~~~~~~~~~~~~~
|
128 |
-
|
129 |
-
The following variables are always available in templates:
|
130 |
-
|
131 |
-
* ``_self``: references the current template;
|
132 |
-
* ``_context``: references the current context;
|
133 |
-
* ``_charset``: references the current charset.
|
134 |
-
|
135 |
-
Setting Variables
|
136 |
-
~~~~~~~~~~~~~~~~~
|
137 |
-
|
138 |
-
You can assign values to variables inside code blocks. Assignments use the
|
139 |
-
:doc:`set<tags/set>` tag:
|
140 |
-
|
141 |
-
.. code-block:: jinja
|
142 |
-
|
143 |
-
{% set foo = 'foo' %}
|
144 |
-
{% set foo = [1, 2] %}
|
145 |
-
{% set foo = {'foo': 'bar'} %}
|
146 |
-
|
147 |
-
Filters
|
148 |
-
-------
|
149 |
-
|
150 |
-
Variables can be modified by **filters**. Filters are separated from the
|
151 |
-
variable by a pipe symbol (``|``) and may have optional arguments in
|
152 |
-
parentheses. Multiple filters can be chained. The output of one filter is
|
153 |
-
applied to the next.
|
154 |
-
|
155 |
-
The following example removes all HTML tags from the ``name`` and title-cases
|
156 |
-
it:
|
157 |
-
|
158 |
-
.. code-block:: jinja
|
159 |
-
|
160 |
-
{{ name|striptags|title }}
|
161 |
-
|
162 |
-
Filters that accept arguments have parentheses around the arguments. This
|
163 |
-
example will join a list by commas:
|
164 |
-
|
165 |
-
.. code-block:: jinja
|
166 |
-
|
167 |
-
{{ list|join(', ') }}
|
168 |
-
|
169 |
-
To apply a filter on a section of code, wrap it in the
|
170 |
-
:doc:`filter<tags/filter>` tag:
|
171 |
-
|
172 |
-
.. code-block:: jinja
|
173 |
-
|
174 |
-
{% filter upper %}
|
175 |
-
This text becomes uppercase
|
176 |
-
{% endfilter %}
|
177 |
-
|
178 |
-
Go to the :doc:`filters<filters/index>` page to learn more about built-in
|
179 |
-
filters.
|
180 |
-
|
181 |
-
Functions
|
182 |
-
---------
|
183 |
-
|
184 |
-
Functions can be called to generate content. Functions are called by their
|
185 |
-
name followed by parentheses (``()``) and may have arguments.
|
186 |
-
|
187 |
-
For instance, the ``range`` function returns a list containing an arithmetic
|
188 |
-
progression of integers:
|
189 |
-
|
190 |
-
.. code-block:: jinja
|
191 |
-
|
192 |
-
{% for i in range(0, 3) %}
|
193 |
-
{{ i }},
|
194 |
-
{% endfor %}
|
195 |
-
|
196 |
-
Go to the :doc:`functions<functions/index>` page to learn more about the
|
197 |
-
built-in functions.
|
198 |
-
|
199 |
-
Named Arguments
|
200 |
-
---------------
|
201 |
-
|
202 |
-
.. versionadded:: 1.12
|
203 |
-
Support for named arguments was added in Twig 1.12.
|
204 |
-
|
205 |
-
.. code-block:: jinja
|
206 |
-
|
207 |
-
{% for i in range(low=1, high=10, step=2) %}
|
208 |
-
{{ i }},
|
209 |
-
{% endfor %}
|
210 |
-
|
211 |
-
Using named arguments makes your templates more explicit about the meaning of
|
212 |
-
the values you pass as arguments:
|
213 |
-
|
214 |
-
.. code-block:: jinja
|
215 |
-
|
216 |
-
{{ data|convert_encoding('UTF-8', 'iso-2022-jp') }}
|
217 |
-
|
218 |
-
{# versus #}
|
219 |
-
|
220 |
-
{{ data|convert_encoding(from='iso-2022-jp', to='UTF-8') }}
|
221 |
-
|
222 |
-
Named arguments also allow you to skip some arguments for which you don't want
|
223 |
-
to change the default value:
|
224 |
-
|
225 |
-
.. code-block:: jinja
|
226 |
-
|
227 |
-
{# the first argument is the date format, which defaults to the global date format if null is passed #}
|
228 |
-
{{ "now"|date(null, "Europe/Paris") }}
|
229 |
-
|
230 |
-
{# or skip the format value by using a named argument for the time zone #}
|
231 |
-
{{ "now"|date(timezone="Europe/Paris") }}
|
232 |
-
|
233 |
-
You can also use both positional and named arguments in one call, in which
|
234 |
-
case positional arguments must always come before named arguments:
|
235 |
-
|
236 |
-
.. code-block:: jinja
|
237 |
-
|
238 |
-
{{ "now"|date('d/m/Y H:i', timezone="Europe/Paris") }}
|
239 |
-
|
240 |
-
.. tip::
|
241 |
-
|
242 |
-
Each function and filter documentation page has a section where the names
|
243 |
-
of all arguments are listed when supported.
|
244 |
-
|
245 |
-
Control Structure
|
246 |
-
-----------------
|
247 |
-
|
248 |
-
A control structure refers to all those things that control the flow of a
|
249 |
-
program - conditionals (i.e. ``if``/``elseif``/``else``), ``for``-loops, as
|
250 |
-
well as things like blocks. Control structures appear inside ``{% ... %}``
|
251 |
-
blocks.
|
252 |
-
|
253 |
-
For example, to display a list of users provided in a variable called
|
254 |
-
``users``, use the :doc:`for<tags/for>` tag:
|
255 |
-
|
256 |
-
.. code-block:: jinja
|
257 |
-
|
258 |
-
<h1>Members</h1>
|
259 |
-
<ul>
|
260 |
-
{% for user in users %}
|
261 |
-
<li>{{ user.username|e }}</li>
|
262 |
-
{% endfor %}
|
263 |
-
</ul>
|
264 |
-
|
265 |
-
The :doc:`if<tags/if>` tag can be used to test an expression:
|
266 |
-
|
267 |
-
.. code-block:: jinja
|
268 |
-
|
269 |
-
{% if users|length > 0 %}
|
270 |
-
<ul>
|
271 |
-
{% for user in users %}
|
272 |
-
<li>{{ user.username|e }}</li>
|
273 |
-
{% endfor %}
|
274 |
-
</ul>
|
275 |
-
{% endif %}
|
276 |
-
|
277 |
-
Go to the :doc:`tags<tags/index>` page to learn more about the built-in tags.
|
278 |
-
|
279 |
-
Comments
|
280 |
-
--------
|
281 |
-
|
282 |
-
To comment-out part of a line in a template, use the comment syntax ``{# ...
|
283 |
-
#}``. This is useful for debugging or to add information for other template
|
284 |
-
designers or yourself:
|
285 |
-
|
286 |
-
.. code-block:: jinja
|
287 |
-
|
288 |
-
{# note: disabled template because we no longer use this
|
289 |
-
{% for user in users %}
|
290 |
-
...
|
291 |
-
{% endfor %}
|
292 |
-
#}
|
293 |
-
|
294 |
-
Including other Templates
|
295 |
-
-------------------------
|
296 |
-
|
297 |
-
The :doc:`include<functions/include>` function is useful to include a template
|
298 |
-
and return the rendered content of that template into the current one:
|
299 |
-
|
300 |
-
.. code-block:: jinja
|
301 |
-
|
302 |
-
{{ include('sidebar.html') }}
|
303 |
-
|
304 |
-
By default, included templates have access to the same context as the template
|
305 |
-
which includes them. This means that any variable defined in the main template
|
306 |
-
will be available in the included template too:
|
307 |
-
|
308 |
-
.. code-block:: jinja
|
309 |
-
|
310 |
-
{% for box in boxes %}
|
311 |
-
{{ include('render_box.html') }}
|
312 |
-
{% endfor %}
|
313 |
-
|
314 |
-
The included template ``render_box.html`` is able to access the ``box`` variable.
|
315 |
-
|
316 |
-
The filename of the template depends on the template loader. For instance, the
|
317 |
-
``Twig_Loader_Filesystem`` allows you to access other templates by giving the
|
318 |
-
filename. You can access templates in subdirectories with a slash:
|
319 |
-
|
320 |
-
.. code-block:: jinja
|
321 |
-
|
322 |
-
{{ include('sections/articles/sidebar.html') }}
|
323 |
-
|
324 |
-
This behavior depends on the application embedding Twig.
|
325 |
-
|
326 |
-
Template Inheritance
|
327 |
-
--------------------
|
328 |
-
|
329 |
-
The most powerful part of Twig is template inheritance. Template inheritance
|
330 |
-
allows you to build a base "skeleton" template that contains all the common
|
331 |
-
elements of your site and defines **blocks** that child templates can
|
332 |
-
override.
|
333 |
-
|
334 |
-
Sounds complicated but it is very basic. It's easier to understand it by
|
335 |
-
starting with an example.
|
336 |
-
|
337 |
-
Let's define a base template, ``base.html``, which defines a simple HTML
|
338 |
-
skeleton document that you might use for a simple two-column page:
|
339 |
-
|
340 |
-
.. code-block:: html+jinja
|
341 |
-
|
342 |
-
<!DOCTYPE html>
|
343 |
-
<html>
|
344 |
-
<head>
|
345 |
-
{% block head %}
|
346 |
-
<link rel="stylesheet" href="style.css" />
|
347 |
-
<title>{% block title %}{% endblock %} - My Webpage</title>
|
348 |
-
{% endblock %}
|
349 |
-
</head>
|
350 |
-
<body>
|
351 |
-
<div id="content">{% block content %}{% endblock %}</div>
|
352 |
-
<div id="footer">
|
353 |
-
{% block footer %}
|
354 |
-
© Copyright 2011 by <a href="http://domain.invalid/">you</a>.
|
355 |
-
{% endblock %}
|
356 |
-
</div>
|
357 |
-
</body>
|
358 |
-
</html>
|
359 |
-
|
360 |
-
In this example, the :doc:`block<tags/block>` tags define four blocks that
|
361 |
-
child templates can fill in. All the ``block`` tag does is to tell the
|
362 |
-
template engine that a child template may override those portions of the
|
363 |
-
template.
|
364 |
-
|
365 |
-
A child template might look like this:
|
366 |
-
|
367 |
-
.. code-block:: jinja
|
368 |
-
|
369 |
-
{% extends "base.html" %}
|
370 |
-
|
371 |
-
{% block title %}Index{% endblock %}
|
372 |
-
{% block head %}
|
373 |
-
{{ parent() }}
|
374 |
-
<style type="text/css">
|
375 |
-
.important { color: #336699; }
|
376 |
-
</style>
|
377 |
-
{% endblock %}
|
378 |
-
{% block content %}
|
379 |
-
<h1>Index</h1>
|
380 |
-
<p class="important">
|
381 |
-
Welcome to my awesome homepage.
|
382 |
-
</p>
|
383 |
-
{% endblock %}
|
384 |
-
|
385 |
-
The :doc:`extends<tags/extends>` tag is the key here. It tells the template
|
386 |
-
engine that this template "extends" another template. When the template system
|
387 |
-
evaluates this template, first it locates the parent. The extends tag should
|
388 |
-
be the first tag in the template.
|
389 |
-
|
390 |
-
Note that since the child template doesn't define the ``footer`` block, the
|
391 |
-
value from the parent template is used instead.
|
392 |
-
|
393 |
-
It's possible to render the contents of the parent block by using the
|
394 |
-
:doc:`parent<functions/parent>` function. This gives back the results of the
|
395 |
-
parent block:
|
396 |
-
|
397 |
-
.. code-block:: jinja
|
398 |
-
|
399 |
-
{% block sidebar %}
|
400 |
-
<h3>Table Of Contents</h3>
|
401 |
-
...
|
402 |
-
{{ parent() }}
|
403 |
-
{% endblock %}
|
404 |
-
|
405 |
-
.. tip::
|
406 |
-
|
407 |
-
The documentation page for the :doc:`extends<tags/extends>` tag describes
|
408 |
-
more advanced features like block nesting, scope, dynamic inheritance, and
|
409 |
-
conditional inheritance.
|
410 |
-
|
411 |
-
.. note::
|
412 |
-
|
413 |
-
Twig also supports multiple inheritance with the so called horizontal reuse
|
414 |
-
with the help of the :doc:`use<tags/use>` tag. This is an advanced feature
|
415 |
-
hardly ever needed in regular templates.
|
416 |
-
|
417 |
-
HTML Escaping
|
418 |
-
-------------
|
419 |
-
|
420 |
-
When generating HTML from templates, there's always a risk that a variable
|
421 |
-
will include characters that affect the resulting HTML. There are two
|
422 |
-
approaches: manually escaping each variable or automatically escaping
|
423 |
-
everything by default.
|
424 |
-
|
425 |
-
Twig supports both, automatic escaping is enabled by default.
|
426 |
-
|
427 |
-
The automatic escaping strategy can be configured via the
|
428 |
-
:ref:`autoescape<environment_options>` option and defaults to ``html``.
|
429 |
-
|
430 |
-
Working with Manual Escaping
|
431 |
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
432 |
-
|
433 |
-
If manual escaping is enabled, it is **your** responsibility to escape
|
434 |
-
variables if needed. What to escape? Any variable you don't trust.
|
435 |
-
|
436 |
-
Escaping works by piping the variable through the
|
437 |
-
:doc:`escape<filters/escape>` or ``e`` filter:
|
438 |
-
|
439 |
-
.. code-block:: jinja
|
440 |
-
|
441 |
-
{{ user.username|e }}
|
442 |
-
|
443 |
-
By default, the ``escape`` filter uses the ``html`` strategy, but depending on
|
444 |
-
the escaping context, you might want to explicitly use any other available
|
445 |
-
strategies:
|
446 |
-
|
447 |
-
.. code-block:: jinja
|
448 |
-
|
449 |
-
{{ user.username|e('js') }}
|
450 |
-
{{ user.username|e('css') }}
|
451 |
-
{{ user.username|e('url') }}
|
452 |
-
{{ user.username|e('html_attr') }}
|
453 |
-
|
454 |
-
Working with Automatic Escaping
|
455 |
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
456 |
-
|
457 |
-
Whether automatic escaping is enabled or not, you can mark a section of a
|
458 |
-
template to be escaped or not by using the :doc:`autoescape<tags/autoescape>`
|
459 |
-
tag:
|
460 |
-
|
461 |
-
.. code-block:: jinja
|
462 |
-
|
463 |
-
{% autoescape %}
|
464 |
-
Everything will be automatically escaped in this block (using the HTML strategy)
|
465 |
-
{% endautoescape %}
|
466 |
-
|
467 |
-
By default, auto-escaping uses the ``html`` escaping strategy. If you output
|
468 |
-
variables in other contexts, you need to explicitly escape them with the
|
469 |
-
appropriate escaping strategy:
|
470 |
-
|
471 |
-
.. code-block:: jinja
|
472 |
-
|
473 |
-
{% autoescape 'js' %}
|
474 |
-
Everything will be automatically escaped in this block (using the JS strategy)
|
475 |
-
{% endautoescape %}
|
476 |
-
|
477 |
-
Escaping
|
478 |
-
--------
|
479 |
-
|
480 |
-
It is sometimes desirable or even necessary to have Twig ignore parts it would
|
481 |
-
otherwise handle as variables or blocks. For example if the default syntax is
|
482 |
-
used and you want to use ``{{`` as raw string in the template and not start a
|
483 |
-
variable you have to use a trick.
|
484 |
-
|
485 |
-
The easiest way is to output the variable delimiter (``{{``) by using a variable
|
486 |
-
expression:
|
487 |
-
|
488 |
-
.. code-block:: jinja
|
489 |
-
|
490 |
-
{{ '{{' }}
|
491 |
-
|
492 |
-
For bigger sections it makes sense to mark a block
|
493 |
-
:doc:`verbatim<tags/verbatim>`.
|
494 |
-
|
495 |
-
Macros
|
496 |
-
------
|
497 |
-
|
498 |
-
.. versionadded:: 1.12
|
499 |
-
Support for default argument values was added in Twig 1.12.
|
500 |
-
|
501 |
-
Macros are comparable with functions in regular programming languages. They
|
502 |
-
are useful to reuse often used HTML fragments to not repeat yourself.
|
503 |
-
|
504 |
-
A macro is defined via the :doc:`macro<tags/macro>` tag. Here is a small example
|
505 |
-
(subsequently called ``forms.html``) of a macro that renders a form element:
|
506 |
-
|
507 |
-
.. code-block:: jinja
|
508 |
-
|
509 |
-
{% macro input(name, value, type, size) %}
|
510 |
-
<input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
|
511 |
-
{% endmacro %}
|
512 |
-
|
513 |
-
Macros can be defined in any template, and need to be "imported" via the
|
514 |
-
:doc:`import<tags/import>` tag before being used:
|
515 |
-
|
516 |
-
.. code-block:: jinja
|
517 |
-
|
518 |
-
{% import "forms.html" as forms %}
|
519 |
-
|
520 |
-
<p>{{ forms.input('username') }}</p>
|
521 |
-
|
522 |
-
Alternatively, you can import individual macro names from a template into the
|
523 |
-
current namespace via the :doc:`from<tags/from>` tag and optionally alias them:
|
524 |
-
|
525 |
-
.. code-block:: jinja
|
526 |
-
|
527 |
-
{% from 'forms.html' import input as input_field %}
|
528 |
-
|
529 |
-
<dl>
|
530 |
-
<dt>Username</dt>
|
531 |
-
<dd>{{ input_field('username') }}</dd>
|
532 |
-
<dt>Password</dt>
|
533 |
-
<dd>{{ input_field('password', '', 'password') }}</dd>
|
534 |
-
</dl>
|
535 |
-
|
536 |
-
A default value can also be defined for macro arguments when not provided in a
|
537 |
-
macro call:
|
538 |
-
|
539 |
-
.. code-block:: jinja
|
540 |
-
|
541 |
-
{% macro input(name, value = "", type = "text", size = 20) %}
|
542 |
-
<input type="{{ type }}" name="{{ name }}" value="{{ value|e }}" size="{{ size }}" />
|
543 |
-
{% endmacro %}
|
544 |
-
|
545 |
-
If extra positional arguments are passed to a macro call, they end up in the
|
546 |
-
special ``varargs`` variable as a list of values.
|
547 |
-
|
548 |
-
.. _twig-expressions:
|
549 |
-
|
550 |
-
Expressions
|
551 |
-
-----------
|
552 |
-
|
553 |
-
Twig allows expressions everywhere. These work very similar to regular PHP and
|
554 |
-
even if you're not working with PHP you should feel comfortable with it.
|
555 |
-
|
556 |
-
.. note::
|
557 |
-
|
558 |
-
The operator precedence is as follows, with the lowest-precedence
|
559 |
-
operators listed first: ``b-and``, ``b-xor``, ``b-or``, ``or``, ``and``,
|
560 |
-
``==``, ``!=``, ``<``, ``>``, ``>=``, ``<=``, ``in``, ``matches``,
|
561 |
-
``starts with``, ``ends with``, ``..``, ``+``, ``-``, ``~``, ``*``, ``/``,
|
562 |
-
``//``, ``%``, ``is``, ``**``, ``|``, ``[]``, and ``.``:
|
563 |
-
|
564 |
-
.. code-block:: jinja
|
565 |
-
|
566 |
-
{% set greeting = 'Hello ' %}
|
567 |
-
{% set name = 'Fabien' %}
|
568 |
-
|
569 |
-
{{ greeting ~ name|lower }} {# Hello fabien #}
|
570 |
-
|
571 |
-
{# use parenthesis to change precedence #}
|
572 |
-
{{ (greeting ~ name)|lower }} {# hello fabien #}
|
573 |
-
|
574 |
-
Literals
|
575 |
-
~~~~~~~~
|
576 |
-
|
577 |
-
.. versionadded:: 1.5
|
578 |
-
Support for hash keys as names and expressions was added in Twig 1.5.
|
579 |
-
|
580 |
-
The simplest form of expressions are literals. Literals are representations
|
581 |
-
for PHP types such as strings, numbers, and arrays. The following literals
|
582 |
-
exist:
|
583 |
-
|
584 |
-
* ``"Hello World"``: Everything between two double or single quotes is a
|
585 |
-
string. They are useful whenever you need a string in the template (for
|
586 |
-
example as arguments to function calls, filters or just to extend or include
|
587 |
-
a template). A string can contain a delimiter if it is preceded by a
|
588 |
-
backslash (``\``) -- like in ``'It\'s good'``. If the string contains a
|
589 |
-
backslash (e.g. ``'c:\Program Files'``) escape it by doubling it
|
590 |
-
(e.g. ``'c:\\Program Files'``).
|
591 |
-
|
592 |
-
* ``42`` / ``42.23``: Integers and floating point numbers are created by just
|
593 |
-
writing the number down. If a dot is present the number is a float,
|
594 |
-
otherwise an integer.
|
595 |
-
|
596 |
-
* ``["foo", "bar"]``: Arrays are defined by a sequence of expressions
|
597 |
-
separated by a comma (``,``) and wrapped with squared brackets (``[]``).
|
598 |
-
|
599 |
-
* ``{"foo": "bar"}``: Hashes are defined by a list of keys and values
|
600 |
-
separated by a comma (``,``) and wrapped with curly braces (``{}``):
|
601 |
-
|
602 |
-
.. code-block:: jinja
|
603 |
-
|
604 |
-
{# keys as string #}
|
605 |
-
{ 'foo': 'foo', 'bar': 'bar' }
|
606 |
-
|
607 |
-
{# keys as names (equivalent to the previous hash) -- as of Twig 1.5 #}
|
608 |
-
{ foo: 'foo', bar: 'bar' }
|
609 |
-
|
610 |
-
{# keys as integer #}
|
611 |
-
{ 2: 'foo', 4: 'bar' }
|
612 |
-
|
613 |
-
{# keys as expressions (the expression must be enclosed into parentheses) -- as of Twig 1.5 #}
|
614 |
-
{ (1 + 1): 'foo', (a ~ 'b'): 'bar' }
|
615 |
-
|
616 |
-
* ``true`` / ``false``: ``true`` represents the true value, ``false``
|
617 |
-
represents the false value.
|
618 |
-
|
619 |
-
* ``null``: ``null`` represents no specific value. This is the value returned
|
620 |
-
when a variable does not exist. ``none`` is an alias for ``null``.
|
621 |
-
|
622 |
-
Arrays and hashes can be nested:
|
623 |
-
|
624 |
-
.. code-block:: jinja
|
625 |
-
|
626 |
-
{% set foo = [1, {"foo": "bar"}] %}
|
627 |
-
|
628 |
-
.. tip::
|
629 |
-
|
630 |
-
Using double-quoted or single-quoted strings has no impact on performance
|
631 |
-
but string interpolation is only supported in double-quoted strings.
|
632 |
-
|
633 |
-
Math
|
634 |
-
~~~~
|
635 |
-
|
636 |
-
Twig allows you to calculate with values. This is rarely useful in templates
|
637 |
-
but exists for completeness' sake. The following operators are supported:
|
638 |
-
|
639 |
-
* ``+``: Adds two objects together (the operands are casted to numbers). ``{{
|
640 |
-
1 + 1 }}`` is ``2``.
|
641 |
-
|
642 |
-
* ``-``: Subtracts the second number from the first one. ``{{ 3 - 2 }}`` is
|
643 |
-
``1``.
|
644 |
-
|
645 |
-
* ``/``: Divides two numbers. The returned value will be a floating point
|
646 |
-
number. ``{{ 1 / 2 }}`` is ``{{ 0.5 }}``.
|
647 |
-
|
648 |
-
* ``%``: Calculates the remainder of an integer division. ``{{ 11 % 7 }}`` is
|
649 |
-
``4``.
|
650 |
-
|
651 |
-
* ``//``: Divides two numbers and returns the floored integer result. ``{{ 20
|
652 |
-
// 7 }}`` is ``2``, ``{{ -20 // 7 }}`` is ``-3`` (this is just syntactic
|
653 |
-
sugar for the :doc:`round<filters/round>` filter).
|
654 |
-
|
655 |
-
* ``*``: Multiplies the left operand with the right one. ``{{ 2 * 2 }}`` would
|
656 |
-
return ``4``.
|
657 |
-
|
658 |
-
* ``**``: Raises the left operand to the power of the right operand. ``{{ 2 **
|
659 |
-
3 }}`` would return ``8``.
|
660 |
-
|
661 |
-
Logic
|
662 |
-
~~~~~
|
663 |
-
|
664 |
-
You can combine multiple expressions with the following operators:
|
665 |
-
|
666 |
-
* ``and``: Returns true if the left and the right operands are both true.
|
667 |
-
|
668 |
-
* ``or``: Returns true if the left or the right operand is true.
|
669 |
-
|
670 |
-
* ``not``: Negates a statement.
|
671 |
-
|
672 |
-
* ``(expr)``: Groups an expression.
|
673 |
-
|
674 |
-
.. note::
|
675 |
-
|
676 |
-
Twig also support bitwise operators (``b-and``, ``b-xor``, and ``b-or``).
|
677 |
-
|
678 |
-
.. note::
|
679 |
-
|
680 |
-
Operators are case sensitive.
|
681 |
-
|
682 |
-
Comparisons
|
683 |
-
~~~~~~~~~~~
|
684 |
-
|
685 |
-
The following comparison operators are supported in any expression: ``==``,
|
686 |
-
``!=``, ``<``, ``>``, ``>=``, and ``<=``.
|
687 |
-
|
688 |
-
You can also check if a string ``starts with`` or ``ends with`` another
|
689 |
-
string:
|
690 |
-
|
691 |
-
.. code-block:: jinja
|
692 |
-
|
693 |
-
{% if 'Fabien' starts with 'F' %}
|
694 |
-
{% endif %}
|
695 |
-
|
696 |
-
{% if 'Fabien' ends with 'n' %}
|
697 |
-
{% endif %}
|
698 |
-
|
699 |
-
.. note::
|
700 |
-
|
701 |
-
For complex string comparisons, the ``matches`` operator allows you to use
|
702 |
-
`regular expressions`_:
|
703 |
-
|
704 |
-
.. code-block:: jinja
|
705 |
-
|
706 |
-
{% if phone matches '/^[\\d\\.]+$/' %}
|
707 |
-
{% endif %}
|
708 |
-
|
709 |
-
Containment Operator
|
710 |
-
~~~~~~~~~~~~~~~~~~~~
|
711 |
-
|
712 |
-
The ``in`` operator performs containment test.
|
713 |
-
|
714 |
-
It returns ``true`` if the left operand is contained in the right:
|
715 |
-
|
716 |
-
.. code-block:: jinja
|
717 |
-
|
718 |
-
{# returns true #}
|
719 |
-
|
720 |
-
{{ 1 in [1, 2, 3] }}
|
721 |
-
|
722 |
-
{{ 'cd' in 'abcde' }}
|
723 |
-
|
724 |
-
.. tip::
|
725 |
-
|
726 |
-
You can use this filter to perform a containment test on strings, arrays,
|
727 |
-
or objects implementing the ``Traversable`` interface.
|
728 |
-
|
729 |
-
To perform a negative test, use the ``not in`` operator:
|
730 |
-
|
731 |
-
.. code-block:: jinja
|
732 |
-
|
733 |
-
{% if 1 not in [1, 2, 3] %}
|
734 |
-
|
735 |
-
{# is equivalent to #}
|
736 |
-
{% if not (1 in [1, 2, 3]) %}
|
737 |
-
|
738 |
-
Test Operator
|
739 |
-
~~~~~~~~~~~~~
|
740 |
-
|
741 |
-
The ``is`` operator performs tests. Tests can be used to test a variable against
|
742 |
-
a common expression. The right operand is name of the test:
|
743 |
-
|
744 |
-
.. code-block:: jinja
|
745 |
-
|
746 |
-
{# find out if a variable is odd #}
|
747 |
-
|
748 |
-
{{ name is odd }}
|
749 |
-
|
750 |
-
Tests can accept arguments too:
|
751 |
-
|
752 |
-
.. code-block:: jinja
|
753 |
-
|
754 |
-
{% if post.status is constant('Post::PUBLISHED') %}
|
755 |
-
|
756 |
-
Tests can be negated by using the ``is not`` operator:
|
757 |
-
|
758 |
-
.. code-block:: jinja
|
759 |
-
|
760 |
-
{% if post.status is not constant('Post::PUBLISHED') %}
|
761 |
-
|
762 |
-
{# is equivalent to #}
|
763 |
-
{% if not (post.status is constant('Post::PUBLISHED')) %}
|
764 |
-
|
765 |
-
Go to the :doc:`tests<tests/index>` page to learn more about the built-in
|
766 |
-
tests.
|
767 |
-
|
768 |
-
Other Operators
|
769 |
-
~~~~~~~~~~~~~~~
|
770 |
-
|
771 |
-
.. versionadded:: 1.12.0
|
772 |
-
Support for the extended ternary operator was added in Twig 1.12.0.
|
773 |
-
|
774 |
-
The following operators don't fit into any of the other categories:
|
775 |
-
|
776 |
-
* ``|``: Applies a filter.
|
777 |
-
|
778 |
-
* ``..``: Creates a sequence based on the operand before and after the operator
|
779 |
-
(this is just syntactic sugar for the :doc:`range<functions/range>` function):
|
780 |
-
|
781 |
-
.. code-block:: jinja
|
782 |
-
|
783 |
-
{{ 1..5 }}
|
784 |
-
|
785 |
-
{# equivalent to #}
|
786 |
-
{{ range(1, 5) }}
|
787 |
-
|
788 |
-
Note that you must use parentheses when combining it with the filter operator
|
789 |
-
due to the :ref:`operator precedence rules <twig-expressions>`:
|
790 |
-
|
791 |
-
.. code-block:: jinja
|
792 |
-
|
793 |
-
(1..5)|join(', ')
|
794 |
-
|
795 |
-
* ``~``: Converts all operands into strings and concatenates them. ``{{ "Hello
|
796 |
-
" ~ name ~ "!" }}`` would return (assuming ``name`` is ``'John'``) ``Hello
|
797 |
-
John!``.
|
798 |
-
|
799 |
-
* ``.``, ``[]``: Gets an attribute of an object.
|
800 |
-
|
801 |
-
* ``?:``: The ternary operator:
|
802 |
-
|
803 |
-
.. code-block:: jinja
|
804 |
-
|
805 |
-
{{ foo ? 'yes' : 'no' }}
|
806 |
-
|
807 |
-
{# as of Twig 1.12.0 #}
|
808 |
-
{{ foo ?: 'no' }} is the same as {{ foo ? foo : 'no' }}
|
809 |
-
{{ foo ? 'yes' }} is the same as {{ foo ? 'yes' : '' }}
|
810 |
-
|
811 |
-
* ``??``: The null-coalescing operator:
|
812 |
-
|
813 |
-
.. code-block:: jinja
|
814 |
-
|
815 |
-
{# returns the value of foo if it is defined and not null, 'no' otherwise #}
|
816 |
-
{{ foo ?? 'no' }}
|
817 |
-
|
818 |
-
String Interpolation
|
819 |
-
~~~~~~~~~~~~~~~~~~~~
|
820 |
-
|
821 |
-
.. versionadded:: 1.5
|
822 |
-
String interpolation was added in Twig 1.5.
|
823 |
-
|
824 |
-
String interpolation (``#{expression}``) allows any valid expression to appear
|
825 |
-
within a *double-quoted string*. The result of evaluating that expression is
|
826 |
-
inserted into the string:
|
827 |
-
|
828 |
-
.. code-block:: jinja
|
829 |
-
|
830 |
-
{{ "foo #{bar} baz" }}
|
831 |
-
{{ "foo #{1 + 2} baz" }}
|
832 |
-
|
833 |
-
.. _templates-whitespace-control:
|
834 |
-
|
835 |
-
Whitespace Control
|
836 |
-
------------------
|
837 |
-
|
838 |
-
.. versionadded:: 1.1
|
839 |
-
Tag level whitespace control was added in Twig 1.1.
|
840 |
-
|
841 |
-
The first newline after a template tag is removed automatically (like in PHP.)
|
842 |
-
Whitespace is not further modified by the template engine, so each whitespace
|
843 |
-
(spaces, tabs, newlines etc.) is returned unchanged.
|
844 |
-
|
845 |
-
Use the ``spaceless`` tag to remove whitespace *between HTML tags*:
|
846 |
-
|
847 |
-
.. code-block:: jinja
|
848 |
-
|
849 |
-
{% spaceless %}
|
850 |
-
<div>
|
851 |
-
<strong>foo bar</strong>
|
852 |
-
</div>
|
853 |
-
{% endspaceless %}
|
854 |
-
|
855 |
-
{# output will be <div><strong>foo bar</strong></div> #}
|
856 |
-
|
857 |
-
In addition to the spaceless tag you can also control whitespace on a per tag
|
858 |
-
level. By using the whitespace control modifier on your tags, you can trim
|
859 |
-
leading and or trailing whitespace:
|
860 |
-
|
861 |
-
.. code-block:: jinja
|
862 |
-
|
863 |
-
{% set value = 'no spaces' %}
|
864 |
-
{#- No leading/trailing whitespace -#}
|
865 |
-
{%- if true -%}
|
866 |
-
{{- value -}}
|
867 |
-
{%- endif -%}
|
868 |
-
|
869 |
-
{# output 'no spaces' #}
|
870 |
-
|
871 |
-
The above sample shows the default whitespace control modifier, and how you can
|
872 |
-
use it to remove whitespace around tags. Trimming space will consume all whitespace
|
873 |
-
for that side of the tag. It is possible to use whitespace trimming on one side
|
874 |
-
of a tag:
|
875 |
-
|
876 |
-
.. code-block:: jinja
|
877 |
-
|
878 |
-
{% set value = 'no spaces' %}
|
879 |
-
<li> {{- value }} </li>
|
880 |
-
|
881 |
-
{# outputs '<li>no spaces </li>' #}
|
882 |
-
|
883 |
-
Extensions
|
884 |
-
----------
|
885 |
-
|
886 |
-
Twig can be easily extended.
|
887 |
-
|
888 |
-
If you are looking for new tags, filters, or functions, have a look at the Twig official
|
889 |
-
`extension repository`_.
|
890 |
-
|
891 |
-
If you want to create your own, read the :ref:`Creating an
|
892 |
-
Extension<creating_extensions>` chapter.
|
893 |
-
|
894 |
-
.. _`Twig bundle`: https://github.com/Anomareh/PHP-Twig.tmbundle
|
895 |
-
.. _`Jinja syntax plugin`: http://jinja.pocoo.org/docs/integration/#vim
|
896 |
-
.. _`vim-twig plugin`: https://github.com/evidens/vim-twig
|
897 |
-
.. _`Twig syntax plugin`: http://plugins.netbeans.org/plugin/37069/php-twig
|
898 |
-
.. _`Twig plugin`: https://github.com/pulse00/Twig-Eclipse-Plugin
|
899 |
-
.. _`Twig language definition`: https://github.com/gabrielcorpse/gedit-twig-template-language
|
900 |
-
.. _`extension repository`: http://github.com/twigphp/Twig-extensions
|
901 |
-
.. _`Twig syntax mode`: https://github.com/bobthecow/Twig-HTML.mode
|
902 |
-
.. _`other Twig syntax mode`: https://github.com/muxx/Twig-HTML.mode
|
903 |
-
.. _`Notepad++ Twig Highlighter`: https://github.com/Banane9/notepadplusplus-twig
|
904 |
-
.. _`web-mode.el`: http://web-mode.org/
|
905 |
-
.. _`regular expressions`: http://php.net/manual/en/pcre.pattern.php
|
906 |
-
.. _`PHP-twig for atom`: https://github.com/reesef/php-twig
|
907 |
-
.. _`TwigFiddle`: http://twigfiddle.com/
|
908 |
-
.. _`Twig pack`: https://marketplace.visualstudio.com/items?itemName=bajdzis.vscode-twig-pack
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tests/constant.rst
DELETED
@@ -1,22 +0,0 @@
|
|
1 |
-
``constant``
|
2 |
-
============
|
3 |
-
|
4 |
-
.. versionadded: 1.13.1
|
5 |
-
constant now accepts object instances as the second argument.
|
6 |
-
|
7 |
-
``constant`` checks if a variable has the exact same value as a constant. You
|
8 |
-
can use either global constants or class constants:
|
9 |
-
|
10 |
-
.. code-block:: jinja
|
11 |
-
|
12 |
-
{% if post.status is constant('Post::PUBLISHED') %}
|
13 |
-
the status attribute is exactly the same as Post::PUBLISHED
|
14 |
-
{% endif %}
|
15 |
-
|
16 |
-
You can test constants from object instances as well:
|
17 |
-
|
18 |
-
.. code-block:: jinja
|
19 |
-
|
20 |
-
{% if post.status is constant('PUBLISHED', post) %}
|
21 |
-
the status attribute is exactly the same as Post::PUBLISHED
|
22 |
-
{% endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tests/defined.rst
DELETED
@@ -1,30 +0,0 @@
|
|
1 |
-
``defined``
|
2 |
-
===========
|
3 |
-
|
4 |
-
``defined`` checks if a variable is defined in the current context. This is very
|
5 |
-
useful if you use the ``strict_variables`` option:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{# defined works with variable names #}
|
10 |
-
{% if foo is defined %}
|
11 |
-
...
|
12 |
-
{% endif %}
|
13 |
-
|
14 |
-
{# and attributes on variables names #}
|
15 |
-
{% if foo.bar is defined %}
|
16 |
-
...
|
17 |
-
{% endif %}
|
18 |
-
|
19 |
-
{% if foo['bar'] is defined %}
|
20 |
-
...
|
21 |
-
{% endif %}
|
22 |
-
|
23 |
-
When using the ``defined`` test on an expression that uses variables in some
|
24 |
-
method calls, be sure that they are all defined first:
|
25 |
-
|
26 |
-
.. code-block:: jinja
|
27 |
-
|
28 |
-
{% if var is defined and foo.method(var) is defined %}
|
29 |
-
...
|
30 |
-
{% endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tests/divisibleby.rst
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
``divisible by``
|
2 |
-
================
|
3 |
-
|
4 |
-
.. versionadded:: 1.14.2
|
5 |
-
The ``divisible by`` test was added in Twig 1.14.2 as an alias for
|
6 |
-
``divisibleby``.
|
7 |
-
|
8 |
-
``divisible by`` checks if a variable is divisible by a number:
|
9 |
-
|
10 |
-
.. code-block:: jinja
|
11 |
-
|
12 |
-
{% if loop.index is divisible by(3) %}
|
13 |
-
...
|
14 |
-
{% endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tests/empty.rst
DELETED
@@ -1,11 +0,0 @@
|
|
1 |
-
``empty``
|
2 |
-
=========
|
3 |
-
|
4 |
-
``empty`` checks if a variable is an empty string, an empty array, an empty
|
5 |
-
hash, exactly ``false``, or exactly ``null``:
|
6 |
-
|
7 |
-
.. code-block:: jinja
|
8 |
-
|
9 |
-
{% if foo is empty %}
|
10 |
-
...
|
11 |
-
{% endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tests/even.rst
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
``even``
|
2 |
-
========
|
3 |
-
|
4 |
-
``even`` returns ``true`` if the given number is even:
|
5 |
-
|
6 |
-
.. code-block:: jinja
|
7 |
-
|
8 |
-
{{ var is even }}
|
9 |
-
|
10 |
-
.. seealso:: :doc:`odd<../tests/odd>`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tests/index.rst
DELETED
@@ -1,15 +0,0 @@
|
|
1 |
-
Tests
|
2 |
-
=====
|
3 |
-
|
4 |
-
.. toctree::
|
5 |
-
:maxdepth: 1
|
6 |
-
|
7 |
-
constant
|
8 |
-
defined
|
9 |
-
divisibleby
|
10 |
-
empty
|
11 |
-
even
|
12 |
-
iterable
|
13 |
-
null
|
14 |
-
odd
|
15 |
-
sameas
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tests/iterable.rst
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
``iterable``
|
2 |
-
============
|
3 |
-
|
4 |
-
.. versionadded:: 1.7
|
5 |
-
The iterable test was added in Twig 1.7.
|
6 |
-
|
7 |
-
``iterable`` checks if a variable is an array or a traversable object:
|
8 |
-
|
9 |
-
.. code-block:: jinja
|
10 |
-
|
11 |
-
{# evaluates to true if the foo variable is iterable #}
|
12 |
-
{% if users is iterable %}
|
13 |
-
{% for user in users %}
|
14 |
-
Hello {{ user }}!
|
15 |
-
{% endfor %}
|
16 |
-
{% else %}
|
17 |
-
{# users is probably a string #}
|
18 |
-
Hello {{ users }}!
|
19 |
-
{% endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tests/null.rst
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
``null``
|
2 |
-
========
|
3 |
-
|
4 |
-
``null`` returns ``true`` if the variable is ``null``:
|
5 |
-
|
6 |
-
.. code-block:: jinja
|
7 |
-
|
8 |
-
{{ var is null }}
|
9 |
-
|
10 |
-
.. note::
|
11 |
-
|
12 |
-
``none`` is an alias for ``null``.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tests/odd.rst
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
``odd``
|
2 |
-
=======
|
3 |
-
|
4 |
-
``odd`` returns ``true`` if the given number is odd:
|
5 |
-
|
6 |
-
.. code-block:: jinja
|
7 |
-
|
8 |
-
{{ var is odd }}
|
9 |
-
|
10 |
-
.. seealso:: :doc:`even<../tests/even>`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/doc/tests/sameas.rst
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
``same as``
|
2 |
-
===========
|
3 |
-
|
4 |
-
.. versionadded:: 1.14.2
|
5 |
-
The ``same as`` test was added in Twig 1.14.2 as an alias for ``sameas``.
|
6 |
-
|
7 |
-
``same as`` checks if a variable is the same as another variable.
|
8 |
-
This is the equivalent to ``===`` in PHP:
|
9 |
-
|
10 |
-
.. code-block:: jinja
|
11 |
-
|
12 |
-
{% if foo.attribute is same as(false) %}
|
13 |
-
the foo attribute really is the 'false' PHP value
|
14 |
-
{% endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/ext/twig/config.m4
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
dnl config.m4 for extension twig
|
2 |
-
|
3 |
-
PHP_ARG_ENABLE(twig, whether to enable twig support,
|
4 |
-
[ --enable-twig Enable twig support])
|
5 |
-
|
6 |
-
if test "$PHP_TWIG" != "no"; then
|
7 |
-
PHP_NEW_EXTENSION(twig, twig.c, $ext_shared)
|
8 |
-
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/ext/twig/config.w32
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
// vim:ft=javascript
|
2 |
-
|
3 |
-
ARG_ENABLE("twig", "Twig support", "no");
|
4 |
-
|
5 |
-
if (PHP_TWIG != "no") {
|
6 |
-
AC_DEFINE('HAVE_TWIG', 1);
|
7 |
-
EXTENSION('twig', 'twig.c');
|
8 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/ext/twig/php_twig.h
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
/*
|
2 |
-
+----------------------------------------------------------------------+
|
3 |
-
| Twig Extension |
|
4 |
-
+----------------------------------------------------------------------+
|
5 |
-
| Copyright (c) 2011 Derick Rethans |
|
6 |
-
+----------------------------------------------------------------------+
|
7 |
-
| Redistribution and use in source and binary forms, with or without |
|
8 |
-
| modification, are permitted provided that the conditions mentioned |
|
9 |
-
| in the accompanying LICENSE file are met (BSD-3-Clause). |
|
10 |
-
+----------------------------------------------------------------------+
|
11 |
-
| Author: Derick Rethans <derick@derickrethans.nl> |
|
12 |
-
+----------------------------------------------------------------------+
|
13 |
-
*/
|
14 |
-
|
15 |
-
#ifndef PHP_TWIG_H
|
16 |
-
#define PHP_TWIG_H
|
17 |
-
|
18 |
-
#define PHP_TWIG_VERSION "1.28.2"
|
19 |
-
|
20 |
-
#include "php.h"
|
21 |
-
|
22 |
-
extern zend_module_entry twig_module_entry;
|
23 |
-
#define phpext_twig_ptr &twig_module_entry
|
24 |
-
#ifndef PHP_WIN32
|
25 |
-
zend_module_entry *get_module(void);
|
26 |
-
#endif
|
27 |
-
|
28 |
-
#ifdef ZTS
|
29 |
-
#include "TSRM.h"
|
30 |
-
#endif
|
31 |
-
|
32 |
-
PHP_FUNCTION(twig_template_get_attributes);
|
33 |
-
PHP_RSHUTDOWN_FUNCTION(twig);
|
34 |
-
|
35 |
-
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/ext/twig/twig.c
DELETED
@@ -1,1127 +0,0 @@
|
|
1 |
-
/*
|
2 |
-
+----------------------------------------------------------------------+
|
3 |
-
| Twig Extension |
|
4 |
-
+----------------------------------------------------------------------+
|
5 |
-
| Copyright (c) 2011 Derick Rethans |
|
6 |
-
+----------------------------------------------------------------------+
|
7 |
-
| Redistribution and use in source and binary forms, with or without |
|
8 |
-
| modification, are permitted provided that the conditions mentioned |
|
9 |
-
| in the accompanying LICENSE file are met (BSD-3-Clause). |
|
10 |
-
+----------------------------------------------------------------------+
|
11 |
-
| Author: Derick Rethans <derick@derickrethans.nl> |
|
12 |
-
+----------------------------------------------------------------------+
|
13 |
-
*/
|
14 |
-
|
15 |
-
#ifdef HAVE_CONFIG_H
|
16 |
-
#include "config.h"
|
17 |
-
#endif
|
18 |
-
|
19 |
-
#include "php.h"
|
20 |
-
#include "php_twig.h"
|
21 |
-
#include "ext/standard/php_var.h"
|
22 |
-
#include "ext/standard/php_string.h"
|
23 |
-
#include "ext/standard/php_smart_str.h"
|
24 |
-
#include "ext/spl/spl_exceptions.h"
|
25 |
-
|
26 |
-
#include "Zend/zend_object_handlers.h"
|
27 |
-
#include "Zend/zend_interfaces.h"
|
28 |
-
#include "Zend/zend_exceptions.h"
|
29 |
-
|
30 |
-
#ifndef Z_ADDREF_P
|
31 |
-
#define Z_ADDREF_P(pz) (pz)->refcount++
|
32 |
-
#endif
|
33 |
-
|
34 |
-
#define FREE_DTOR(z) \
|
35 |
-
zval_dtor(z); \
|
36 |
-
efree(z);
|
37 |
-
|
38 |
-
#if PHP_VERSION_ID >= 50300
|
39 |
-
#define APPLY_TSRMLS_DC TSRMLS_DC
|
40 |
-
#define APPLY_TSRMLS_CC TSRMLS_CC
|
41 |
-
#define APPLY_TSRMLS_FETCH()
|
42 |
-
#else
|
43 |
-
#define APPLY_TSRMLS_DC
|
44 |
-
#define APPLY_TSRMLS_CC
|
45 |
-
#define APPLY_TSRMLS_FETCH() TSRMLS_FETCH()
|
46 |
-
#endif
|
47 |
-
|
48 |
-
ZEND_BEGIN_ARG_INFO_EX(twig_template_get_attribute_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 6)
|
49 |
-
ZEND_ARG_INFO(0, template)
|
50 |
-
ZEND_ARG_INFO(0, object)
|
51 |
-
ZEND_ARG_INFO(0, item)
|
52 |
-
ZEND_ARG_INFO(0, arguments)
|
53 |
-
ZEND_ARG_INFO(0, type)
|
54 |
-
ZEND_ARG_INFO(0, isDefinedTest)
|
55 |
-
ZEND_END_ARG_INFO()
|
56 |
-
|
57 |
-
#ifndef PHP_FE_END
|
58 |
-
#define PHP_FE_END { NULL, NULL, NULL}
|
59 |
-
#endif
|
60 |
-
|
61 |
-
static const zend_function_entry twig_functions[] = {
|
62 |
-
PHP_FE(twig_template_get_attributes, twig_template_get_attribute_args)
|
63 |
-
PHP_FE_END
|
64 |
-
};
|
65 |
-
|
66 |
-
PHP_RSHUTDOWN_FUNCTION(twig)
|
67 |
-
{
|
68 |
-
#if ZEND_DEBUG
|
69 |
-
CG(unclean_shutdown) = 0; /* get rid of PHPUnit's exit() and report memleaks */
|
70 |
-
#endif
|
71 |
-
return SUCCESS;
|
72 |
-
}
|
73 |
-
|
74 |
-
zend_module_entry twig_module_entry = {
|
75 |
-
STANDARD_MODULE_HEADER,
|
76 |
-
"twig",
|
77 |
-
twig_functions,
|
78 |
-
NULL,
|
79 |
-
NULL,
|
80 |
-
NULL,
|
81 |
-
PHP_RSHUTDOWN(twig),
|
82 |
-
NULL,
|
83 |
-
PHP_TWIG_VERSION,
|
84 |
-
STANDARD_MODULE_PROPERTIES
|
85 |
-
};
|
86 |
-
|
87 |
-
|
88 |
-
#ifdef COMPILE_DL_TWIG
|
89 |
-
ZEND_GET_MODULE(twig)
|
90 |
-
#endif
|
91 |
-
|
92 |
-
static int TWIG_ARRAY_KEY_EXISTS(zval *array, zval *key)
|
93 |
-
{
|
94 |
-
if (Z_TYPE_P(array) != IS_ARRAY) {
|
95 |
-
return 0;
|
96 |
-
}
|
97 |
-
|
98 |
-
switch (Z_TYPE_P(key)) {
|
99 |
-
case IS_NULL:
|
100 |
-
return zend_hash_exists(Z_ARRVAL_P(array), "", 1);
|
101 |
-
|
102 |
-
case IS_BOOL:
|
103 |
-
case IS_DOUBLE:
|
104 |
-
convert_to_long(key);
|
105 |
-
case IS_LONG:
|
106 |
-
return zend_hash_index_exists(Z_ARRVAL_P(array), Z_LVAL_P(key));
|
107 |
-
|
108 |
-
default:
|
109 |
-
convert_to_string(key);
|
110 |
-
return zend_symtable_exists(Z_ARRVAL_P(array), Z_STRVAL_P(key), Z_STRLEN_P(key) + 1);
|
111 |
-
}
|
112 |
-
}
|
113 |
-
|
114 |
-
static int TWIG_INSTANCE_OF(zval *object, zend_class_entry *interface TSRMLS_DC)
|
115 |
-
{
|
116 |
-
if (Z_TYPE_P(object) != IS_OBJECT) {
|
117 |
-
return 0;
|
118 |
-
}
|
119 |
-
return instanceof_function(Z_OBJCE_P(object), interface TSRMLS_CC);
|
120 |
-
}
|
121 |
-
|
122 |
-
static int TWIG_INSTANCE_OF_USERLAND(zval *object, char *interface TSRMLS_DC)
|
123 |
-
{
|
124 |
-
zend_class_entry **pce;
|
125 |
-
if (Z_TYPE_P(object) != IS_OBJECT) {
|
126 |
-
return 0;
|
127 |
-
}
|
128 |
-
if (zend_lookup_class(interface, strlen(interface), &pce TSRMLS_CC) == FAILURE) {
|
129 |
-
return 0;
|
130 |
-
}
|
131 |
-
return instanceof_function(Z_OBJCE_P(object), *pce TSRMLS_CC);
|
132 |
-
}
|
133 |
-
|
134 |
-
static zval *TWIG_GET_ARRAYOBJECT_ELEMENT(zval *object, zval *offset TSRMLS_DC)
|
135 |
-
{
|
136 |
-
zend_class_entry *ce = Z_OBJCE_P(object);
|
137 |
-
zval *retval;
|
138 |
-
|
139 |
-
if (Z_TYPE_P(object) == IS_OBJECT) {
|
140 |
-
SEPARATE_ARG_IF_REF(offset);
|
141 |
-
zend_call_method_with_1_params(&object, ce, NULL, "offsetget", &retval, offset);
|
142 |
-
|
143 |
-
zval_ptr_dtor(&offset);
|
144 |
-
|
145 |
-
if (!retval) {
|
146 |
-
if (!EG(exception)) {
|
147 |
-
zend_error(E_ERROR, "Undefined offset for object of type %s used as array.", ce->name);
|
148 |
-
}
|
149 |
-
return NULL;
|
150 |
-
}
|
151 |
-
|
152 |
-
return retval;
|
153 |
-
}
|
154 |
-
return NULL;
|
155 |
-
}
|
156 |
-
|
157 |
-
static int TWIG_ISSET_ARRAYOBJECT_ELEMENT(zval *object, zval *offset TSRMLS_DC)
|
158 |
-
{
|
159 |
-
zend_class_entry *ce = Z_OBJCE_P(object);
|
160 |
-
zval *retval;
|
161 |
-
|
162 |
-
if (Z_TYPE_P(object) == IS_OBJECT) {
|
163 |
-
SEPARATE_ARG_IF_REF(offset);
|
164 |
-
zend_call_method_with_1_params(&object, ce, NULL, "offsetexists", &retval, offset);
|
165 |
-
|
166 |
-
zval_ptr_dtor(&offset);
|
167 |
-
|
168 |
-
if (!retval) {
|
169 |
-
if (!EG(exception)) {
|
170 |
-
zend_error(E_ERROR, "Undefined offset for object of type %s used as array.", ce->name);
|
171 |
-
}
|
172 |
-
return 0;
|
173 |
-
}
|
174 |
-
|
175 |
-
return (retval && Z_TYPE_P(retval) == IS_BOOL && Z_LVAL_P(retval));
|
176 |
-
}
|
177 |
-
return 0;
|
178 |
-
}
|
179 |
-
|
180 |
-
static char *TWIG_STRTOLOWER(const char *str, int str_len)
|
181 |
-
{
|
182 |
-
char *item_dup;
|
183 |
-
|
184 |
-
item_dup = estrndup(str, str_len);
|
185 |
-
php_strtolower(item_dup, str_len);
|
186 |
-
return item_dup;
|
187 |
-
}
|
188 |
-
|
189 |
-
static zval *TWIG_CALL_USER_FUNC_ARRAY(zval *object, char *function, zval *arguments TSRMLS_DC)
|
190 |
-
{
|
191 |
-
zend_fcall_info fci;
|
192 |
-
zval ***args = NULL;
|
193 |
-
int arg_count = 0;
|
194 |
-
HashTable *table;
|
195 |
-
HashPosition pos;
|
196 |
-
int i = 0;
|
197 |
-
zval *retval_ptr;
|
198 |
-
zval *zfunction;
|
199 |
-
|
200 |
-
if (arguments) {
|
201 |
-
table = HASH_OF(arguments);
|
202 |
-
args = safe_emalloc(sizeof(zval **), table->nNumOfElements, 0);
|
203 |
-
|
204 |
-
zend_hash_internal_pointer_reset_ex(table, &pos);
|
205 |
-
|
206 |
-
while (zend_hash_get_current_data_ex(table, (void **)&args[i], &pos) == SUCCESS) {
|
207 |
-
i++;
|
208 |
-
zend_hash_move_forward_ex(table, &pos);
|
209 |
-
}
|
210 |
-
arg_count = table->nNumOfElements;
|
211 |
-
}
|
212 |
-
|
213 |
-
MAKE_STD_ZVAL(zfunction);
|
214 |
-
ZVAL_STRING(zfunction, function, 1);
|
215 |
-
fci.size = sizeof(fci);
|
216 |
-
fci.function_table = EG(function_table);
|
217 |
-
fci.function_name = zfunction;
|
218 |
-
fci.symbol_table = NULL;
|
219 |
-
#if PHP_VERSION_ID >= 50300
|
220 |
-
fci.object_ptr = object;
|
221 |
-
#else
|
222 |
-
fci.object_pp = &object;
|
223 |
-
#endif
|
224 |
-
fci.retval_ptr_ptr = &retval_ptr;
|
225 |
-
fci.param_count = arg_count;
|
226 |
-
fci.params = args;
|
227 |
-
fci.no_separation = 0;
|
228 |
-
|
229 |
-
if (zend_call_function(&fci, NULL TSRMLS_CC) == FAILURE) {
|
230 |
-
ALLOC_INIT_ZVAL(retval_ptr);
|
231 |
-
ZVAL_BOOL(retval_ptr, 0);
|
232 |
-
}
|
233 |
-
|
234 |
-
if (args) {
|
235 |
-
efree(fci.params);
|
236 |
-
}
|
237 |
-
FREE_DTOR(zfunction);
|
238 |
-
return retval_ptr;
|
239 |
-
}
|
240 |
-
|
241 |
-
static int TWIG_CALL_BOOLEAN(zval *object, char *functionName TSRMLS_DC)
|
242 |
-
{
|
243 |
-
zval *ret;
|
244 |
-
int res;
|
245 |
-
|
246 |
-
ret = TWIG_CALL_USER_FUNC_ARRAY(object, functionName, NULL TSRMLS_CC);
|
247 |
-
res = Z_LVAL_P(ret);
|
248 |
-
zval_ptr_dtor(&ret);
|
249 |
-
return res;
|
250 |
-
}
|
251 |
-
|
252 |
-
static zval *TWIG_GET_STATIC_PROPERTY(zval *class, char *prop_name TSRMLS_DC)
|
253 |
-
{
|
254 |
-
zval **tmp_zval;
|
255 |
-
zend_class_entry *ce;
|
256 |
-
|
257 |
-
if (class == NULL || Z_TYPE_P(class) != IS_OBJECT) {
|
258 |
-
return NULL;
|
259 |
-
}
|
260 |
-
|
261 |
-
ce = zend_get_class_entry(class TSRMLS_CC);
|
262 |
-
#if PHP_VERSION_ID >= 50400
|
263 |
-
tmp_zval = zend_std_get_static_property(ce, prop_name, strlen(prop_name), 0, NULL TSRMLS_CC);
|
264 |
-
#else
|
265 |
-
tmp_zval = zend_std_get_static_property(ce, prop_name, strlen(prop_name), 0 TSRMLS_CC);
|
266 |
-
#endif
|
267 |
-
return *tmp_zval;
|
268 |
-
}
|
269 |
-
|
270 |
-
static zval *TWIG_GET_ARRAY_ELEMENT_ZVAL(zval *class, zval *prop_name TSRMLS_DC)
|
271 |
-
{
|
272 |
-
zval **tmp_zval;
|
273 |
-
|
274 |
-
if (class == NULL || Z_TYPE_P(class) != IS_ARRAY) {
|
275 |
-
if (class != NULL && Z_TYPE_P(class) == IS_OBJECT && TWIG_INSTANCE_OF(class, zend_ce_arrayaccess TSRMLS_CC)) {
|
276 |
-
// array access object
|
277 |
-
return TWIG_GET_ARRAYOBJECT_ELEMENT(class, prop_name TSRMLS_CC);
|
278 |
-
}
|
279 |
-
return NULL;
|
280 |
-
}
|
281 |
-
|
282 |
-
switch(Z_TYPE_P(prop_name)) {
|
283 |
-
case IS_NULL:
|
284 |
-
zend_hash_find(HASH_OF(class), "", 1, (void**) &tmp_zval);
|
285 |
-
return *tmp_zval;
|
286 |
-
|
287 |
-
case IS_BOOL:
|
288 |
-
case IS_DOUBLE:
|
289 |
-
convert_to_long(prop_name);
|
290 |
-
case IS_LONG:
|
291 |
-
zend_hash_index_find(HASH_OF(class), Z_LVAL_P(prop_name), (void **) &tmp_zval);
|
292 |
-
return *tmp_zval;
|
293 |
-
|
294 |
-
case IS_STRING:
|
295 |
-
zend_symtable_find(HASH_OF(class), Z_STRVAL_P(prop_name), Z_STRLEN_P(prop_name) + 1, (void**) &tmp_zval);
|
296 |
-
return *tmp_zval;
|
297 |
-
}
|
298 |
-
|
299 |
-
return NULL;
|
300 |
-
}
|
301 |
-
|
302 |
-
static zval *TWIG_GET_ARRAY_ELEMENT(zval *class, char *prop_name, int prop_name_length TSRMLS_DC)
|
303 |
-
{
|
304 |
-
zval **tmp_zval;
|
305 |
-
|
306 |
-
if (class == NULL/* || Z_TYPE_P(class) != IS_ARRAY*/) {
|
307 |
-
return NULL;
|
308 |
-
}
|
309 |
-
|
310 |
-
if (class != NULL && Z_TYPE_P(class) == IS_OBJECT && TWIG_INSTANCE_OF(class, zend_ce_arrayaccess TSRMLS_CC)) {
|
311 |
-
// array access object
|
312 |
-
zval *tmp_name_zval;
|
313 |
-
zval *tmp_ret_zval;
|
314 |
-
|
315 |
-
ALLOC_INIT_ZVAL(tmp_name_zval);
|
316 |
-
ZVAL_STRING(tmp_name_zval, prop_name, 1);
|
317 |
-
tmp_ret_zval = TWIG_GET_ARRAYOBJECT_ELEMENT(class, tmp_name_zval TSRMLS_CC);
|
318 |
-
FREE_DTOR(tmp_name_zval);
|
319 |
-
return tmp_ret_zval;
|
320 |
-
}
|
321 |
-
|
322 |
-
if (zend_symtable_find(HASH_OF(class), prop_name, prop_name_length+1, (void**)&tmp_zval) == SUCCESS) {
|
323 |
-
return *tmp_zval;
|
324 |
-
}
|
325 |
-
return NULL;
|
326 |
-
}
|
327 |
-
|
328 |
-
static zval *TWIG_PROPERTY(zval *object, zval *propname TSRMLS_DC)
|
329 |
-
{
|
330 |
-
zval *tmp = NULL;
|
331 |
-
|
332 |
-
if (Z_OBJ_HT_P(object)->read_property) {
|
333 |
-
#if PHP_VERSION_ID >= 50400
|
334 |
-
tmp = Z_OBJ_HT_P(object)->read_property(object, propname, BP_VAR_IS, NULL TSRMLS_CC);
|
335 |
-
#else
|
336 |
-
tmp = Z_OBJ_HT_P(object)->read_property(object, propname, BP_VAR_IS TSRMLS_CC);
|
337 |
-
#endif
|
338 |
-
if (tmp == EG(uninitialized_zval_ptr)) {
|
339 |
-
ZVAL_NULL(tmp);
|
340 |
-
}
|
341 |
-
}
|
342 |
-
return tmp;
|
343 |
-
}
|
344 |
-
|
345 |
-
static int TWIG_HAS_PROPERTY(zval *object, zval *propname TSRMLS_DC)
|
346 |
-
{
|
347 |
-
if (Z_OBJ_HT_P(object)->has_property) {
|
348 |
-
#if PHP_VERSION_ID >= 50400
|
349 |
-
return Z_OBJ_HT_P(object)->has_property(object, propname, 0, NULL TSRMLS_CC);
|
350 |
-
#else
|
351 |
-
return Z_OBJ_HT_P(object)->has_property(object, propname, 0 TSRMLS_CC);
|
352 |
-
#endif
|
353 |
-
}
|
354 |
-
return 0;
|
355 |
-
}
|
356 |
-
|
357 |
-
static int TWIG_HAS_DYNAMIC_PROPERTY(zval *object, char *prop, int prop_len TSRMLS_DC)
|
358 |
-
{
|
359 |
-
if (Z_OBJ_HT_P(object)->get_properties) {
|
360 |
-
return zend_hash_quick_exists(
|
361 |
-
Z_OBJ_HT_P(object)->get_properties(object TSRMLS_CC), // the properties hash
|
362 |
-
prop, // property name
|
363 |
-
prop_len + 1, // property length
|
364 |
-
zend_get_hash_value(prop, prop_len + 1) // hash value
|
365 |
-
);
|
366 |
-
}
|
367 |
-
return 0;
|
368 |
-
}
|
369 |
-
|
370 |
-
static zval *TWIG_PROPERTY_CHAR(zval *object, char *propname TSRMLS_DC)
|
371 |
-
{
|
372 |
-
zval *tmp_name_zval, *tmp;
|
373 |
-
|
374 |
-
ALLOC_INIT_ZVAL(tmp_name_zval);
|
375 |
-
ZVAL_STRING(tmp_name_zval, propname, 1);
|
376 |
-
tmp = TWIG_PROPERTY(object, tmp_name_zval TSRMLS_CC);
|
377 |
-
FREE_DTOR(tmp_name_zval);
|
378 |
-
return tmp;
|
379 |
-
}
|
380 |
-
|
381 |
-
static zval *TWIG_CALL_S(zval *object, char *method, char *arg0 TSRMLS_DC)
|
382 |
-
{
|
383 |
-
zend_fcall_info fci;
|
384 |
-
zval **args[1];
|
385 |
-
zval *argument;
|
386 |
-
zval *zfunction;
|
387 |
-
zval *retval_ptr;
|
388 |
-
|
389 |
-
MAKE_STD_ZVAL(argument);
|
390 |
-
ZVAL_STRING(argument, arg0, 1);
|
391 |
-
args[0] = &argument;
|
392 |
-
|
393 |
-
MAKE_STD_ZVAL(zfunction);
|
394 |
-
ZVAL_STRING(zfunction, method, 1);
|
395 |
-
fci.size = sizeof(fci);
|
396 |
-
fci.function_table = EG(function_table);
|
397 |
-
fci.function_name = zfunction;
|
398 |
-
fci.symbol_table = NULL;
|
399 |
-
#if PHP_VERSION_ID >= 50300
|
400 |
-
fci.object_ptr = object;
|
401 |
-
#else
|
402 |
-
fci.object_pp = &object;
|
403 |
-
#endif
|
404 |
-
fci.retval_ptr_ptr = &retval_ptr;
|
405 |
-
fci.param_count = 1;
|
406 |
-
fci.params = args;
|
407 |
-
fci.no_separation = 0;
|
408 |
-
|
409 |
-
if (zend_call_function(&fci, NULL TSRMLS_CC) == FAILURE) {
|
410 |
-
FREE_DTOR(zfunction);
|
411 |
-
zval_ptr_dtor(&argument);
|
412 |
-
return 0;
|
413 |
-
}
|
414 |
-
FREE_DTOR(zfunction);
|
415 |
-
zval_ptr_dtor(&argument);
|
416 |
-
return retval_ptr;
|
417 |
-
}
|
418 |
-
|
419 |
-
static int TWIG_CALL_SB(zval *object, char *method, char *arg0 TSRMLS_DC)
|
420 |
-
{
|
421 |
-
zval *retval_ptr;
|
422 |
-
int success;
|
423 |
-
|
424 |
-
retval_ptr = TWIG_CALL_S(object, method, arg0 TSRMLS_CC);
|
425 |
-
success = (retval_ptr && (Z_TYPE_P(retval_ptr) == IS_BOOL) && Z_LVAL_P(retval_ptr));
|
426 |
-
|
427 |
-
if (retval_ptr) {
|
428 |
-
zval_ptr_dtor(&retval_ptr);
|
429 |
-
}
|
430 |
-
|
431 |
-
return success;
|
432 |
-
}
|
433 |
-
|
434 |
-
static int TWIG_CALL_ZZ(zval *object, char *method, zval *arg1, zval *arg2 TSRMLS_DC)
|
435 |
-
{
|
436 |
-
zend_fcall_info fci;
|
437 |
-
zval **args[2];
|
438 |
-
zval *zfunction;
|
439 |
-
zval *retval_ptr;
|
440 |
-
int success;
|
441 |
-
|
442 |
-
args[0] = &arg1;
|
443 |
-
args[1] = &arg2;
|
444 |
-
|
445 |
-
MAKE_STD_ZVAL(zfunction);
|
446 |
-
ZVAL_STRING(zfunction, method, 1);
|
447 |
-
fci.size = sizeof(fci);
|
448 |
-
fci.function_table = EG(function_table);
|
449 |
-
fci.function_name = zfunction;
|
450 |
-
fci.symbol_table = NULL;
|
451 |
-
#if PHP_VERSION_ID >= 50300
|
452 |
-
fci.object_ptr = object;
|
453 |
-
#else
|
454 |
-
fci.object_pp = &object;
|
455 |
-
#endif
|
456 |
-
fci.retval_ptr_ptr = &retval_ptr;
|
457 |
-
fci.param_count = 2;
|
458 |
-
fci.params = args;
|
459 |
-
fci.no_separation = 0;
|
460 |
-
|
461 |
-
if (zend_call_function(&fci, NULL TSRMLS_CC) == FAILURE) {
|
462 |
-
FREE_DTOR(zfunction);
|
463 |
-
return 0;
|
464 |
-
}
|
465 |
-
|
466 |
-
FREE_DTOR(zfunction);
|
467 |
-
|
468 |
-
success = (retval_ptr && (Z_TYPE_P(retval_ptr) == IS_BOOL) && Z_LVAL_P(retval_ptr));
|
469 |
-
if (retval_ptr) {
|
470 |
-
zval_ptr_dtor(&retval_ptr);
|
471 |
-
}
|
472 |
-
|
473 |
-
return success;
|
474 |
-
}
|
475 |
-
|
476 |
-
#ifndef Z_SET_REFCOUNT_P
|
477 |
-
# define Z_SET_REFCOUNT_P(pz, rc) pz->refcount = rc
|
478 |
-
# define Z_UNSET_ISREF_P(pz) pz->is_ref = 0
|
479 |
-
#endif
|
480 |
-
|
481 |
-
static void TWIG_NEW(zval *object, char *class, zval *arg0, zval *arg1 TSRMLS_DC)
|
482 |
-
{
|
483 |
-
zend_class_entry **pce;
|
484 |
-
|
485 |
-
if (zend_lookup_class(class, strlen(class), &pce TSRMLS_CC) == FAILURE) {
|
486 |
-
return;
|
487 |
-
}
|
488 |
-
|
489 |
-
Z_TYPE_P(object) = IS_OBJECT;
|
490 |
-
object_init_ex(object, *pce);
|
491 |
-
Z_SET_REFCOUNT_P(object, 1);
|
492 |
-
Z_UNSET_ISREF_P(object);
|
493 |
-
|
494 |
-
TWIG_CALL_ZZ(object, "__construct", arg0, arg1 TSRMLS_CC);
|
495 |
-
}
|
496 |
-
|
497 |
-
static int twig_add_array_key_to_string(void *pDest APPLY_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
|
498 |
-
{
|
499 |
-
smart_str *buf;
|
500 |
-
char *joiner;
|
501 |
-
APPLY_TSRMLS_FETCH();
|
502 |
-
|
503 |
-
buf = va_arg(args, smart_str*);
|
504 |
-
joiner = va_arg(args, char*);
|
505 |
-
|
506 |
-
if (buf->len != 0) {
|
507 |
-
smart_str_appends(buf, joiner);
|
508 |
-
}
|
509 |
-
|
510 |
-
if (hash_key->nKeyLength == 0) {
|
511 |
-
smart_str_append_long(buf, (long) hash_key->h);
|
512 |
-
} else {
|
513 |
-
char *key, *tmp_str;
|
514 |
-
int key_len, tmp_len;
|
515 |
-
key = php_addcslashes(hash_key->arKey, hash_key->nKeyLength - 1, &key_len, 0, "'\\", 2 TSRMLS_CC);
|
516 |
-
tmp_str = php_str_to_str_ex(key, key_len, "\0", 1, "' . \"\\0\" . '", 12, &tmp_len, 0, NULL);
|
517 |
-
|
518 |
-
smart_str_appendl(buf, tmp_str, tmp_len);
|
519 |
-
efree(key);
|
520 |
-
efree(tmp_str);
|
521 |
-
}
|
522 |
-
|
523 |
-
return 0;
|
524 |
-
}
|
525 |
-
|
526 |
-
static char *TWIG_IMPLODE_ARRAY_KEYS(char *joiner, zval *array TSRMLS_DC)
|
527 |
-
{
|
528 |
-
smart_str collector = { 0, 0, 0 };
|
529 |
-
|
530 |
-
smart_str_appendl(&collector, "", 0);
|
531 |
-
zend_hash_apply_with_arguments(HASH_OF(array) APPLY_TSRMLS_CC, twig_add_array_key_to_string, 2, &collector, joiner);
|
532 |
-
smart_str_0(&collector);
|
533 |
-
|
534 |
-
return collector.c;
|
535 |
-
}
|
536 |
-
|
537 |
-
static void TWIG_RUNTIME_ERROR(zval *template TSRMLS_DC, char *message, ...)
|
538 |
-
{
|
539 |
-
char *buffer;
|
540 |
-
va_list args;
|
541 |
-
zend_class_entry **pce;
|
542 |
-
zval *ex;
|
543 |
-
zval *constructor;
|
544 |
-
zval *zmessage;
|
545 |
-
zval *lineno;
|
546 |
-
zval *filename_func;
|
547 |
-
zval *filename;
|
548 |
-
zval *constructor_args[3];
|
549 |
-
zval *constructor_retval;
|
550 |
-
|
551 |
-
if (zend_lookup_class("Twig_Error_Runtime", strlen("Twig_Error_Runtime"), &pce TSRMLS_CC) == FAILURE) {
|
552 |
-
return;
|
553 |
-
}
|
554 |
-
|
555 |
-
va_start(args, message);
|
556 |
-
vspprintf(&buffer, 0, message, args);
|
557 |
-
va_end(args);
|
558 |
-
|
559 |
-
MAKE_STD_ZVAL(ex);
|
560 |
-
object_init_ex(ex, *pce);
|
561 |
-
|
562 |
-
// Call Twig_Error constructor
|
563 |
-
MAKE_STD_ZVAL(constructor);
|
564 |
-
MAKE_STD_ZVAL(zmessage);
|
565 |
-
MAKE_STD_ZVAL(lineno);
|
566 |
-
MAKE_STD_ZVAL(filename);
|
567 |
-
MAKE_STD_ZVAL(filename_func);
|
568 |
-
MAKE_STD_ZVAL(constructor_retval);
|
569 |
-
|
570 |
-
ZVAL_STRINGL(constructor, "__construct", sizeof("__construct")-1, 1);
|
571 |
-
ZVAL_STRING(zmessage, buffer, 1);
|
572 |
-
ZVAL_LONG(lineno, -1);
|
573 |
-
|
574 |
-
// Get template filename
|
575 |
-
ZVAL_STRINGL(filename_func, "getTemplateName", sizeof("getTemplateName")-1, 1);
|
576 |
-
call_user_function(EG(function_table), &template, filename_func, filename, 0, 0 TSRMLS_CC);
|
577 |
-
|
578 |
-
constructor_args[0] = zmessage;
|
579 |
-
constructor_args[1] = lineno;
|
580 |
-
constructor_args[2] = filename;
|
581 |
-
call_user_function(EG(function_table), &ex, constructor, constructor_retval, 3, constructor_args TSRMLS_CC);
|
582 |
-
|
583 |
-
zval_ptr_dtor(&constructor_retval);
|
584 |
-
zval_ptr_dtor(&zmessage);
|
585 |
-
zval_ptr_dtor(&lineno);
|
586 |
-
zval_ptr_dtor(&filename);
|
587 |
-
FREE_DTOR(constructor);
|
588 |
-
FREE_DTOR(filename_func);
|
589 |
-
efree(buffer);
|
590 |
-
|
591 |
-
zend_throw_exception_object(ex TSRMLS_CC);
|
592 |
-
}
|
593 |
-
|
594 |
-
static char *TWIG_GET_CLASS_NAME(zval *object TSRMLS_DC)
|
595 |
-
{
|
596 |
-
char *class_name;
|
597 |
-
zend_uint class_name_len;
|
598 |
-
|
599 |
-
if (Z_TYPE_P(object) != IS_OBJECT) {
|
600 |
-
return "";
|
601 |
-
}
|
602 |
-
#if PHP_API_VERSION >= 20100412
|
603 |
-
zend_get_object_classname(object, (const char **) &class_name, &class_name_len TSRMLS_CC);
|
604 |
-
#else
|
605 |
-
zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC);
|
606 |
-
#endif
|
607 |
-
return class_name;
|
608 |
-
}
|
609 |
-
|
610 |
-
static int twig_add_method_to_class(void *pDest APPLY_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
|
611 |
-
{
|
612 |
-
zend_class_entry *ce;
|
613 |
-
zval *retval;
|
614 |
-
char *item;
|
615 |
-
size_t item_len;
|
616 |
-
zend_function *mptr = (zend_function *) pDest;
|
617 |
-
APPLY_TSRMLS_FETCH();
|
618 |
-
|
619 |
-
if (!(mptr->common.fn_flags & ZEND_ACC_PUBLIC)) {
|
620 |
-
return 0;
|
621 |
-
}
|
622 |
-
|
623 |
-
ce = *va_arg(args, zend_class_entry**);
|
624 |
-
retval = va_arg(args, zval*);
|
625 |
-
|
626 |
-
item_len = strlen(mptr->common.function_name);
|
627 |
-
item = estrndup(mptr->common.function_name, item_len);
|
628 |
-
php_strtolower(item, item_len);
|
629 |
-
|
630 |
-
if (strcmp("getenvironment", item) == 0) {
|
631 |
-
zend_class_entry **twig_template_ce;
|
632 |
-
if (zend_lookup_class("Twig_Template", strlen("Twig_Template"), &twig_template_ce TSRMLS_CC) == FAILURE) {
|
633 |
-
return 0;
|
634 |
-
}
|
635 |
-
if (instanceof_function(ce, *twig_template_ce TSRMLS_CC)) {
|
636 |
-
return 0;
|
637 |
-
}
|
638 |
-
}
|
639 |
-
|
640 |
-
add_assoc_stringl_ex(retval, item, item_len+1, item, item_len, 0);
|
641 |
-
|
642 |
-
return 0;
|
643 |
-
}
|
644 |
-
|
645 |
-
static int twig_add_property_to_class(void *pDest APPLY_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
|
646 |
-
{
|
647 |
-
zend_class_entry *ce;
|
648 |
-
zval *retval;
|
649 |
-
char *class_name, *prop_name;
|
650 |
-
zend_property_info *pptr = (zend_property_info *) pDest;
|
651 |
-
APPLY_TSRMLS_FETCH();
|
652 |
-
|
653 |
-
if (!(pptr->flags & ZEND_ACC_PUBLIC) || (pptr->flags & ZEND_ACC_STATIC)) {
|
654 |
-
return 0;
|
655 |
-
}
|
656 |
-
|
657 |
-
ce = *va_arg(args, zend_class_entry**);
|
658 |
-
retval = va_arg(args, zval*);
|
659 |
-
|
660 |
-
#if PHP_API_VERSION >= 20100412
|
661 |
-
zend_unmangle_property_name(pptr->name, pptr->name_length, (const char **) &class_name, (const char **) &prop_name);
|
662 |
-
#else
|
663 |
-
zend_unmangle_property_name(pptr->name, pptr->name_length, &class_name, &prop_name);
|
664 |
-
#endif
|
665 |
-
|
666 |
-
add_assoc_string(retval, prop_name, prop_name, 1);
|
667 |
-
|
668 |
-
return 0;
|
669 |
-
}
|
670 |
-
|
671 |
-
static void twig_add_class_to_cache(zval *cache, zval *object, char *class_name TSRMLS_DC)
|
672 |
-
{
|
673 |
-
zval *class_info, *class_methods, *class_properties;
|
674 |
-
zend_class_entry *class_ce;
|
675 |
-
|
676 |
-
class_ce = zend_get_class_entry(object TSRMLS_CC);
|
677 |
-
|
678 |
-
ALLOC_INIT_ZVAL(class_info);
|
679 |
-
ALLOC_INIT_ZVAL(class_methods);
|
680 |
-
ALLOC_INIT_ZVAL(class_properties);
|
681 |
-
array_init(class_info);
|
682 |
-
array_init(class_methods);
|
683 |
-
array_init(class_properties);
|
684 |
-
// add all methods to self::cache[$class]['methods']
|
685 |
-
zend_hash_apply_with_arguments(&class_ce->function_table APPLY_TSRMLS_CC, twig_add_method_to_class, 2, &class_ce, class_methods);
|
686 |
-
zend_hash_apply_with_arguments(&class_ce->properties_info APPLY_TSRMLS_CC, twig_add_property_to_class, 2, &class_ce, class_properties);
|
687 |
-
|
688 |
-
add_assoc_zval(class_info, "methods", class_methods);
|
689 |
-
add_assoc_zval(class_info, "properties", class_properties);
|
690 |
-
add_assoc_zval(cache, class_name, class_info);
|
691 |
-
}
|
692 |
-
|
693 |
-
/* {{{ proto mixed twig_template_get_attributes(TwigTemplate template, mixed object, mixed item, array arguments, string type, boolean isDefinedTest, boolean ignoreStrictCheck)
|
694 |
-
A C implementation of TwigTemplate::getAttribute() */
|
695 |
-
PHP_FUNCTION(twig_template_get_attributes)
|
696 |
-
{
|
697 |
-
zval *template;
|
698 |
-
zval *object;
|
699 |
-
char *item;
|
700 |
-
int item_len;
|
701 |
-
zval *zitem, ztmpitem;
|
702 |
-
zval *arguments = NULL;
|
703 |
-
zval *ret = NULL;
|
704 |
-
char *type = NULL;
|
705 |
-
int type_len = 0;
|
706 |
-
zend_bool isDefinedTest = 0;
|
707 |
-
zend_bool ignoreStrictCheck = 0;
|
708 |
-
int free_ret = 0;
|
709 |
-
zval *tmp_self_cache;
|
710 |
-
char *class_name = NULL;
|
711 |
-
zval *tmp_class;
|
712 |
-
char *type_name;
|
713 |
-
|
714 |
-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ozz|asbb", &template, &object, &zitem, &arguments, &type, &type_len, &isDefinedTest, &ignoreStrictCheck) == FAILURE) {
|
715 |
-
return;
|
716 |
-
}
|
717 |
-
|
718 |
-
// convert the item to a string
|
719 |
-
ztmpitem = *zitem;
|
720 |
-
zval_copy_ctor(&ztmpitem);
|
721 |
-
convert_to_string(&ztmpitem);
|
722 |
-
item_len = Z_STRLEN(ztmpitem);
|
723 |
-
item = estrndup(Z_STRVAL(ztmpitem), item_len);
|
724 |
-
zval_dtor(&ztmpitem);
|
725 |
-
|
726 |
-
if (!type) {
|
727 |
-
type = "any";
|
728 |
-
}
|
729 |
-
|
730 |
-
/*
|
731 |
-
// array
|
732 |
-
if (Twig_Template::METHOD_CALL !== $type) {
|
733 |
-
$arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item;
|
734 |
-
|
735 |
-
if ((is_array($object) && array_key_exists($arrayItem, $object))
|
736 |
-
|| ($object instanceof ArrayAccess && isset($object[$arrayItem]))
|
737 |
-
) {
|
738 |
-
if ($isDefinedTest) {
|
739 |
-
return true;
|
740 |
-
}
|
741 |
-
|
742 |
-
return $object[$arrayItem];
|
743 |
-
}
|
744 |
-
*/
|
745 |
-
|
746 |
-
|
747 |
-
if (strcmp("method", type) != 0) {
|
748 |
-
if ((TWIG_ARRAY_KEY_EXISTS(object, zitem))
|
749 |
-
|| (TWIG_INSTANCE_OF(object, zend_ce_arrayaccess TSRMLS_CC) && TWIG_ISSET_ARRAYOBJECT_ELEMENT(object, zitem TSRMLS_CC))
|
750 |
-
) {
|
751 |
-
|
752 |
-
if (isDefinedTest) {
|
753 |
-
efree(item);
|
754 |
-
RETURN_TRUE;
|
755 |
-
}
|
756 |
-
|
757 |
-
ret = TWIG_GET_ARRAY_ELEMENT_ZVAL(object, zitem TSRMLS_CC);
|
758 |
-
|
759 |
-
if (!ret) {
|
760 |
-
ret = &EG(uninitialized_zval);
|
761 |
-
}
|
762 |
-
RETVAL_ZVAL(ret, 1, 0);
|
763 |
-
if (free_ret) {
|
764 |
-
zval_ptr_dtor(&ret);
|
765 |
-
}
|
766 |
-
efree(item);
|
767 |
-
return;
|
768 |
-
}
|
769 |
-
/*
|
770 |
-
if (Twig_Template::ARRAY_CALL === $type) {
|
771 |
-
if ($isDefinedTest) {
|
772 |
-
return false;
|
773 |
-
}
|
774 |
-
if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
|
775 |
-
return null;
|
776 |
-
}
|
777 |
-
*/
|
778 |
-
if (strcmp("array", type) == 0 || Z_TYPE_P(object) != IS_OBJECT) {
|
779 |
-
if (isDefinedTest) {
|
780 |
-
efree(item);
|
781 |
-
RETURN_FALSE;
|
782 |
-
}
|
783 |
-
if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) {
|
784 |
-
efree(item);
|
785 |
-
return;
|
786 |
-
}
|
787 |
-
/*
|
788 |
-
if ($object instanceof ArrayAccess) {
|
789 |
-
$message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist', $arrayItem, get_class($object));
|
790 |
-
} elseif (is_object($object)) {
|
791 |
-
$message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface', $item, get_class($object));
|
792 |
-
} elseif (is_array($object)) {
|
793 |
-
if (empty($object)) {
|
794 |
-
$message = sprintf('Key "%s" does not exist as the array is empty', $arrayItem);
|
795 |
-
} else {
|
796 |
-
$message = sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object)));
|
797 |
-
}
|
798 |
-
} elseif (Twig_Template::ARRAY_CALL === $type) {
|
799 |
-
if (null === $object) {
|
800 |
-
$message = sprintf('Impossible to access a key ("%s") on a null variable', $item);
|
801 |
-
} else {
|
802 |
-
$message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object);
|
803 |
-
}
|
804 |
-
} elseif (null === $object) {
|
805 |
-
$message = sprintf('Impossible to access an attribute ("%s") on a null variable', $item);
|
806 |
-
} else {
|
807 |
-
$message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s")', $item, gettype($object), $object);
|
808 |
-
}
|
809 |
-
throw new Twig_Error_Runtime($message, -1, $this->getTemplateName());
|
810 |
-
}
|
811 |
-
}
|
812 |
-
*/
|
813 |
-
if (TWIG_INSTANCE_OF(object, zend_ce_arrayaccess TSRMLS_CC)) {
|
814 |
-
TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" in object with ArrayAccess of class \"%s\" does not exist.", item, TWIG_GET_CLASS_NAME(object TSRMLS_CC));
|
815 |
-
} else if (Z_TYPE_P(object) == IS_OBJECT) {
|
816 |
-
TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to access a key \"%s\" on an object of class \"%s\" that does not implement ArrayAccess interface.", item, TWIG_GET_CLASS_NAME(object TSRMLS_CC));
|
817 |
-
} else if (Z_TYPE_P(object) == IS_ARRAY) {
|
818 |
-
if (0 == zend_hash_num_elements(Z_ARRVAL_P(object))) {
|
819 |
-
TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" does not exist as the array is empty.", item);
|
820 |
-
} else {
|
821 |
-
char *array_keys = TWIG_IMPLODE_ARRAY_KEYS(", ", object TSRMLS_CC);
|
822 |
-
TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" for array with keys \"%s\" does not exist.", item, array_keys);
|
823 |
-
efree(array_keys);
|
824 |
-
}
|
825 |
-
} else {
|
826 |
-
char *type_name = zend_zval_type_name(object);
|
827 |
-
Z_ADDREF_P(object);
|
828 |
-
if (Z_TYPE_P(object) == IS_NULL) {
|
829 |
-
convert_to_string(object);
|
830 |
-
TWIG_RUNTIME_ERROR(template TSRMLS_CC,
|
831 |
-
(strcmp("array", type) == 0)
|
832 |
-
? "Impossible to access a key (\"%s\") on a %s variable."
|
833 |
-
: "Impossible to access an attribute (\"%s\") on a %s variable.",
|
834 |
-
item, type_name);
|
835 |
-
} else {
|
836 |
-
convert_to_string(object);
|
837 |
-
TWIG_RUNTIME_ERROR(template TSRMLS_CC,
|
838 |
-
(strcmp("array", type) == 0)
|
839 |
-
? "Impossible to access a key (\"%s\") on a %s variable (\"%s\")."
|
840 |
-
: "Impossible to access an attribute (\"%s\") on a %s variable (\"%s\").",
|
841 |
-
item, type_name, Z_STRVAL_P(object));
|
842 |
-
}
|
843 |
-
zval_ptr_dtor(&object);
|
844 |
-
}
|
845 |
-
efree(item);
|
846 |
-
return;
|
847 |
-
}
|
848 |
-
}
|
849 |
-
|
850 |
-
/*
|
851 |
-
if (!is_object($object)) {
|
852 |
-
if ($isDefinedTest) {
|
853 |
-
return false;
|
854 |
-
}
|
855 |
-
*/
|
856 |
-
|
857 |
-
if (Z_TYPE_P(object) != IS_OBJECT) {
|
858 |
-
if (isDefinedTest) {
|
859 |
-
efree(item);
|
860 |
-
RETURN_FALSE;
|
861 |
-
}
|
862 |
-
/*
|
863 |
-
if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
|
864 |
-
return null;
|
865 |
-
}
|
866 |
-
|
867 |
-
if (null === $object) {
|
868 |
-
$message = sprintf('Impossible to invoke a method ("%s") on a null variable', $item);
|
869 |
-
} else {
|
870 |
-
$message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s")', $item, gettype($object), $object);
|
871 |
-
}
|
872 |
-
|
873 |
-
throw new Twig_Error_Runtime($message, -1, $this->getTemplateName());
|
874 |
-
}
|
875 |
-
*/
|
876 |
-
if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) {
|
877 |
-
efree(item);
|
878 |
-
return;
|
879 |
-
}
|
880 |
-
|
881 |
-
type_name = zend_zval_type_name(object);
|
882 |
-
Z_ADDREF_P(object);
|
883 |
-
if (Z_TYPE_P(object) == IS_NULL) {
|
884 |
-
convert_to_string_ex(&object);
|
885 |
-
|
886 |
-
TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to invoke a method (\"%s\") on a %s variable.", item, type_name);
|
887 |
-
} else {
|
888 |
-
convert_to_string_ex(&object);
|
889 |
-
|
890 |
-
TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to invoke a method (\"%s\") on a %s variable (\"%s\").", item, type_name, Z_STRVAL_P(object));
|
891 |
-
}
|
892 |
-
|
893 |
-
zval_ptr_dtor(&object);
|
894 |
-
efree(item);
|
895 |
-
return;
|
896 |
-
}
|
897 |
-
/*
|
898 |
-
$class = get_class($object);
|
899 |
-
*/
|
900 |
-
|
901 |
-
class_name = TWIG_GET_CLASS_NAME(object TSRMLS_CC);
|
902 |
-
tmp_self_cache = TWIG_GET_STATIC_PROPERTY(template, "cache" TSRMLS_CC);
|
903 |
-
tmp_class = TWIG_GET_ARRAY_ELEMENT(tmp_self_cache, class_name, strlen(class_name) TSRMLS_CC);
|
904 |
-
|
905 |
-
if (!tmp_class) {
|
906 |
-
twig_add_class_to_cache(tmp_self_cache, object, class_name TSRMLS_CC);
|
907 |
-
tmp_class = TWIG_GET_ARRAY_ELEMENT(tmp_self_cache, class_name, strlen(class_name) TSRMLS_CC);
|
908 |
-
}
|
909 |
-
efree(class_name);
|
910 |
-
|
911 |
-
/*
|
912 |
-
// object property
|
913 |
-
if (Twig_Template::METHOD_CALL !== $type && !$object instanceof Twig_Template) {
|
914 |
-
if (isset($object->$item) || array_key_exists((string) $item, $object)) {
|
915 |
-
if ($isDefinedTest) {
|
916 |
-
return true;
|
917 |
-
}
|
918 |
-
|
919 |
-
if ($this->env->hasExtension('Twig_Extension_Sandbox')) {
|
920 |
-
$this->env->getExtension('Twig_Extension_Sandbox')->checkPropertyAllowed($object, $item);
|
921 |
-
}
|
922 |
-
|
923 |
-
return $object->$item;
|
924 |
-
}
|
925 |
-
}
|
926 |
-
*/
|
927 |
-
if (strcmp("method", type) != 0 && !TWIG_INSTANCE_OF_USERLAND(object, "Twig_Template" TSRMLS_CC)) {
|
928 |
-
zval *tmp_properties, *tmp_item;
|
929 |
-
|
930 |
-
tmp_properties = TWIG_GET_ARRAY_ELEMENT(tmp_class, "properties", strlen("properties") TSRMLS_CC);
|
931 |
-
tmp_item = TWIG_GET_ARRAY_ELEMENT(tmp_properties, item, item_len TSRMLS_CC);
|
932 |
-
|
933 |
-
if (tmp_item || TWIG_HAS_PROPERTY(object, zitem TSRMLS_CC) || TWIG_HAS_DYNAMIC_PROPERTY(object, item, item_len TSRMLS_CC)) {
|
934 |
-
if (isDefinedTest) {
|
935 |
-
efree(item);
|
936 |
-
RETURN_TRUE;
|
937 |
-
}
|
938 |
-
if (TWIG_CALL_SB(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "hasExtension", "Twig_Extension_Sandbox" TSRMLS_CC)) {
|
939 |
-
TWIG_CALL_ZZ(TWIG_CALL_S(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "getExtension", "Twig_Extension_Sandbox" TSRMLS_CC), "checkPropertyAllowed", object, zitem TSRMLS_CC);
|
940 |
-
}
|
941 |
-
if (EG(exception)) {
|
942 |
-
efree(item);
|
943 |
-
return;
|
944 |
-
}
|
945 |
-
|
946 |
-
ret = TWIG_PROPERTY(object, zitem TSRMLS_CC);
|
947 |
-
efree(item);
|
948 |
-
RETURN_ZVAL(ret, 1, 0);
|
949 |
-
}
|
950 |
-
}
|
951 |
-
/*
|
952 |
-
// object method
|
953 |
-
if (!isset(self::$cache[$class]['methods'])) {
|
954 |
-
if ($object instanceof self) {
|
955 |
-
$ref = new ReflectionClass($class);
|
956 |
-
$methods = array();
|
957 |
-
|
958 |
-
foreach ($ref->getMethods(ReflectionMethod::IS_PUBLIC) as $refMethod) {
|
959 |
-
$methodName = strtolower($refMethod->name);
|
960 |
-
|
961 |
-
// Accessing the environment from templates is forbidden to prevent untrusted changes to the environment
|
962 |
-
if ('getenvironment' !== $methodName) {
|
963 |
-
$methods[$methodName] = true;
|
964 |
-
}
|
965 |
-
}
|
966 |
-
|
967 |
-
self::$cache[$class]['methods'] = $methods;
|
968 |
-
} else {
|
969 |
-
self::$cache[$class]['methods'] = array_change_key_case(array_flip(get_class_methods($object)));
|
970 |
-
}
|
971 |
-
}
|
972 |
-
|
973 |
-
$call = false;
|
974 |
-
$lcItem = strtolower($item);
|
975 |
-
if (isset(self::$cache[$class]['methods'][$lcItem])) {
|
976 |
-
$method = (string) $item;
|
977 |
-
} elseif (isset(self::$cache[$class]['methods']['get'.$lcItem])) {
|
978 |
-
$method = 'get'.$item;
|
979 |
-
} elseif (isset(self::$cache[$class]['methods']['is'.$lcItem])) {
|
980 |
-
$method = 'is'.$item;
|
981 |
-
} elseif (isset(self::$cache[$class]['methods']['__call'])) {
|
982 |
-
$method = (string) $item;
|
983 |
-
$call = true;
|
984 |
-
*/
|
985 |
-
{
|
986 |
-
int call = 0;
|
987 |
-
char *lcItem = TWIG_STRTOLOWER(item, item_len);
|
988 |
-
int lcItem_length;
|
989 |
-
char *method = NULL;
|
990 |
-
char *tmp_method_name_get;
|
991 |
-
char *tmp_method_name_is;
|
992 |
-
zval *zmethod;
|
993 |
-
zval *tmp_methods;
|
994 |
-
|
995 |
-
lcItem_length = strlen(lcItem);
|
996 |
-
tmp_method_name_get = emalloc(4 + lcItem_length);
|
997 |
-
tmp_method_name_is = emalloc(3 + lcItem_length);
|
998 |
-
|
999 |
-
sprintf(tmp_method_name_get, "get%s", lcItem);
|
1000 |
-
sprintf(tmp_method_name_is, "is%s", lcItem);
|
1001 |
-
|
1002 |
-
tmp_methods = TWIG_GET_ARRAY_ELEMENT(tmp_class, "methods", strlen("methods") TSRMLS_CC);
|
1003 |
-
|
1004 |
-
if (TWIG_GET_ARRAY_ELEMENT(tmp_methods, lcItem, lcItem_length TSRMLS_CC)) {
|
1005 |
-
method = item;
|
1006 |
-
} else if (TWIG_GET_ARRAY_ELEMENT(tmp_methods, tmp_method_name_get, lcItem_length + 3 TSRMLS_CC)) {
|
1007 |
-
method = tmp_method_name_get;
|
1008 |
-
} else if (TWIG_GET_ARRAY_ELEMENT(tmp_methods, tmp_method_name_is, lcItem_length + 2 TSRMLS_CC)) {
|
1009 |
-
method = tmp_method_name_is;
|
1010 |
-
} else if (TWIG_GET_ARRAY_ELEMENT(tmp_methods, "__call", 6 TSRMLS_CC)) {
|
1011 |
-
method = item;
|
1012 |
-
call = 1;
|
1013 |
-
/*
|
1014 |
-
} else {
|
1015 |
-
if ($isDefinedTest) {
|
1016 |
-
return false;
|
1017 |
-
}
|
1018 |
-
|
1019 |
-
if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
|
1020 |
-
return null;
|
1021 |
-
}
|
1022 |
-
|
1023 |
-
throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist.', $item, get_class($object)), -1, $this->getTemplateName());
|
1024 |
-
}
|
1025 |
-
|
1026 |
-
if ($isDefinedTest) {
|
1027 |
-
return true;
|
1028 |
-
}
|
1029 |
-
*/
|
1030 |
-
} else {
|
1031 |
-
efree(tmp_method_name_get);
|
1032 |
-
efree(tmp_method_name_is);
|
1033 |
-
efree(lcItem);
|
1034 |
-
|
1035 |
-
if (isDefinedTest) {
|
1036 |
-
efree(item);
|
1037 |
-
RETURN_FALSE;
|
1038 |
-
}
|
1039 |
-
if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) {
|
1040 |
-
efree(item);
|
1041 |
-
return;
|
1042 |
-
}
|
1043 |
-
TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Neither the property \"%s\" nor one of the methods \"%s()\", \"get%s()\"/\"is%s()\" or \"__call()\" exist and have public access in class \"%s\".", item, item, item, item, TWIG_GET_CLASS_NAME(object TSRMLS_CC));
|
1044 |
-
efree(item);
|
1045 |
-
return;
|
1046 |
-
}
|
1047 |
-
|
1048 |
-
if (isDefinedTest) {
|
1049 |
-
efree(tmp_method_name_get);
|
1050 |
-
efree(tmp_method_name_is);
|
1051 |
-
efree(lcItem);efree(item);
|
1052 |
-
RETURN_TRUE;
|
1053 |
-
}
|
1054 |
-
/*
|
1055 |
-
if ($this->env->hasExtension('Twig_Extension_Sandbox')) {
|
1056 |
-
$this->env->getExtension('Twig_Extension_Sandbox')->checkMethodAllowed($object, $method);
|
1057 |
-
}
|
1058 |
-
*/
|
1059 |
-
MAKE_STD_ZVAL(zmethod);
|
1060 |
-
ZVAL_STRING(zmethod, method, 1);
|
1061 |
-
if (TWIG_CALL_SB(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "hasExtension", "Twig_Extension_Sandbox" TSRMLS_CC)) {
|
1062 |
-
TWIG_CALL_ZZ(TWIG_CALL_S(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "getExtension", "Twig_Extension_Sandbox" TSRMLS_CC), "checkMethodAllowed", object, zmethod TSRMLS_CC);
|
1063 |
-
}
|
1064 |
-
zval_ptr_dtor(&zmethod);
|
1065 |
-
if (EG(exception)) {
|
1066 |
-
efree(tmp_method_name_get);
|
1067 |
-
efree(tmp_method_name_is);
|
1068 |
-
efree(lcItem);efree(item);
|
1069 |
-
return;
|
1070 |
-
}
|
1071 |
-
/*
|
1072 |
-
// Some objects throw exceptions when they have __call, and the method we try
|
1073 |
-
// to call is not supported. If ignoreStrictCheck is true, we should return null.
|
1074 |
-
try {
|
1075 |
-
$ret = call_user_func_array(array($object, $method), $arguments);
|
1076 |
-
} catch (BadMethodCallException $e) {
|
1077 |
-
if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) {
|
1078 |
-
return null;
|
1079 |
-
}
|
1080 |
-
throw $e;
|
1081 |
-
}
|
1082 |
-
*/
|
1083 |
-
ret = TWIG_CALL_USER_FUNC_ARRAY(object, method, arguments TSRMLS_CC);
|
1084 |
-
if (EG(exception) && TWIG_INSTANCE_OF(EG(exception), spl_ce_BadMethodCallException TSRMLS_CC)) {
|
1085 |
-
if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) {
|
1086 |
-
efree(tmp_method_name_get);
|
1087 |
-
efree(tmp_method_name_is);
|
1088 |
-
efree(lcItem);efree(item);
|
1089 |
-
zend_clear_exception(TSRMLS_C);
|
1090 |
-
return;
|
1091 |
-
}
|
1092 |
-
}
|
1093 |
-
free_ret = 1;
|
1094 |
-
efree(tmp_method_name_get);
|
1095 |
-
efree(tmp_method_name_is);
|
1096 |
-
efree(lcItem);
|
1097 |
-
}
|
1098 |
-
/*
|
1099 |
-
// useful when calling a template method from a template
|
1100 |
-
// this is not supported but unfortunately heavily used in the Symfony profiler
|
1101 |
-
if ($object instanceof Twig_TemplateInterface) {
|
1102 |
-
return $ret === '' ? '' : new Twig_Markup($ret, $this->env->getCharset());
|
1103 |
-
}
|
1104 |
-
|
1105 |
-
return $ret;
|
1106 |
-
*/
|
1107 |
-
efree(item);
|
1108 |
-
// ret can be null, if e.g. the called method throws an exception
|
1109 |
-
if (ret) {
|
1110 |
-
if (TWIG_INSTANCE_OF_USERLAND(object, "Twig_TemplateInterface" TSRMLS_CC)) {
|
1111 |
-
if (Z_STRLEN_P(ret) != 0) {
|
1112 |
-
zval *charset = TWIG_CALL_USER_FUNC_ARRAY(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "getCharset", NULL TSRMLS_CC);
|
1113 |
-
TWIG_NEW(return_value, "Twig_Markup", ret, charset TSRMLS_CC);
|
1114 |
-
zval_ptr_dtor(&charset);
|
1115 |
-
if (ret) {
|
1116 |
-
zval_ptr_dtor(&ret);
|
1117 |
-
}
|
1118 |
-
return;
|
1119 |
-
}
|
1120 |
-
}
|
1121 |
-
|
1122 |
-
RETVAL_ZVAL(ret, 1, 0);
|
1123 |
-
if (free_ret) {
|
1124 |
-
zval_ptr_dtor(&ret);
|
1125 |
-
}
|
1126 |
-
}
|
1127 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/phpunit.xml.dist
DELETED
@@ -1,33 +0,0 @@
|
|
1 |
-
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
-
|
3 |
-
<phpunit backupGlobals="false"
|
4 |
-
backupStaticAttributes="false"
|
5 |
-
colors="true"
|
6 |
-
convertErrorsToExceptions="true"
|
7 |
-
convertNoticesToExceptions="true"
|
8 |
-
convertWarningsToExceptions="true"
|
9 |
-
processIsolation="false"
|
10 |
-
stopOnFailure="false"
|
11 |
-
syntaxCheck="false"
|
12 |
-
bootstrap="vendor/autoload.php"
|
13 |
-
>
|
14 |
-
<testsuites>
|
15 |
-
<testsuite name="Twig Test Suite">
|
16 |
-
<directory>./test/Twig/</directory>
|
17 |
-
</testsuite>
|
18 |
-
</testsuites>
|
19 |
-
|
20 |
-
<php>
|
21 |
-
<ini name="error_reporting" value="-1" />
|
22 |
-
</php>
|
23 |
-
|
24 |
-
<listeners>
|
25 |
-
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
|
26 |
-
</listeners>
|
27 |
-
|
28 |
-
<filter>
|
29 |
-
<whitelist>
|
30 |
-
<directory suffix=".php">./lib/Twig/</directory>
|
31 |
-
</whitelist>
|
32 |
-
</filter>
|
33 |
-
</phpunit>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/test/Twig/Tests/AutoloaderTest.php
DELETED
@@ -1,24 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* This file is part of Twig.
|
5 |
-
*
|
6 |
-
* (c) Fabien Potencier
|
7 |
-
*
|
8 |
-
* For the full copyright and license information, please view the LICENSE
|
9 |
-
* file that was distributed with this source code.
|
10 |
-
*/
|
11 |
-
|
12 |
-
class Twig_Tests_AutoloaderTest extends PHPUnit_Framework_TestCase
|
13 |
-
{
|
14 |
-
/**
|
15 |
-
* @group legacy
|
16 |
-
*/
|
17 |
-
public function testAutoload()
|
18 |
-
{
|
19 |
-
$this->assertFalse(class_exists('FooBarFoo'), '->autoload() does not try to load classes that does not begin with Twig');
|
20 |
-
|
21 |
-
$autoloader = new Twig_Autoloader();
|
22 |
-
$this->assertNull($autoloader->autoload('Foo'), '->autoload() returns false if it is not able to load a class');
|
23 |
-
}
|
24 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/test/Twig/Tests/Cache/FilesystemTest.php
DELETED
@@ -1,193 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* This file is part of Twig.
|
5 |
-
*
|
6 |
-
* (c) Fabien Potencier
|
7 |
-
*
|
8 |
-
* For the full copyright and license information, please view the LICENSE
|
9 |
-
* file that was distributed with this source code.
|
10 |
-
*/
|
11 |
-
|
12 |
-
require_once dirname(dirname(__FILE__)).'/FilesystemHelper.php';
|
13 |
-
|
14 |
-
class Twig_Tests_Cache_FilesystemTest extends PHPUnit_Framework_TestCase
|
15 |
-
{
|
16 |
-
private $classname;
|
17 |
-
private $directory;
|
18 |
-
private $cache;
|
19 |
-
|
20 |
-
protected function setUp()
|
21 |
-
{
|
22 |
-
$nonce = hash('sha256', uniqid(mt_rand(), true));
|
23 |
-
$this->classname = '__Twig_Tests_Cache_FilesystemTest_Template_'.$nonce;
|
24 |
-
$this->directory = sys_get_temp_dir().'/twig-test';
|
25 |
-
$this->cache = new Twig_Cache_Filesystem($this->directory);
|
26 |
-
}
|
27 |
-
|
28 |
-
protected function tearDown()
|
29 |
-
{
|
30 |
-
if (file_exists($this->directory)) {
|
31 |
-
Twig_Tests_FilesystemHelper::removeDir($this->directory);
|
32 |
-
}
|
33 |
-
}
|
34 |
-
|
35 |
-
public function testLoad()
|
36 |
-
{
|
37 |
-
$key = $this->directory.'/cache/cachefile.php';
|
38 |
-
|
39 |
-
$dir = dirname($key);
|
40 |
-
@mkdir($dir, 0777, true);
|
41 |
-
$this->assertTrue(is_dir($dir));
|
42 |
-
$this->assertFalse(class_exists($this->classname, false));
|
43 |
-
|
44 |
-
$content = $this->generateSource();
|
45 |
-
file_put_contents($key, $content);
|
46 |
-
|
47 |
-
$this->cache->load($key);
|
48 |
-
|
49 |
-
$this->assertTrue(class_exists($this->classname, false));
|
50 |
-
}
|
51 |
-
|
52 |
-
public function testLoadMissing()
|
53 |
-
{
|
54 |
-
$key = $this->directory.'/cache/cachefile.php';
|
55 |
-
|
56 |
-
$this->assertFalse(class_exists($this->classname, false));
|
57 |
-
|
58 |
-
$this->cache->load($key);
|
59 |
-
|
60 |
-
$this->assertFalse(class_exists($this->classname, false));
|
61 |
-
}
|
62 |
-
|
63 |
-
public function testWrite()
|
64 |
-
{
|
65 |
-
$key = $this->directory.'/cache/cachefile.php';
|
66 |
-
$content = $this->generateSource();
|
67 |
-
|
68 |
-
$this->assertFalse(file_exists($key));
|
69 |
-
$this->assertFalse(file_exists($this->directory));
|
70 |
-
|
71 |
-
$this->cache->write($key, $content);
|
72 |
-
|
73 |
-
$this->assertTrue(file_exists($this->directory));
|
74 |
-
$this->assertTrue(file_exists($key));
|
75 |
-
$this->assertSame(file_get_contents($key), $content);
|
76 |
-
}
|
77 |
-
|
78 |
-
/**
|
79 |
-
* @expectedException RuntimeException
|
80 |
-
* @expectedExceptionMessage Unable to create the cache directory
|
81 |
-
*/
|
82 |
-
public function testWriteFailMkdir()
|
83 |
-
{
|
84 |
-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
85 |
-
$this->markTestSkipped('Read-only directories not possible on Windows.');
|
86 |
-
}
|
87 |
-
|
88 |
-
$key = $this->directory.'/cache/cachefile.php';
|
89 |
-
$content = $this->generateSource();
|
90 |
-
|
91 |
-
$this->assertFalse(file_exists($key));
|
92 |
-
|
93 |
-
// Create read-only root directory.
|
94 |
-
@mkdir($this->directory, 0555, true);
|
95 |
-
$this->assertTrue(is_dir($this->directory));
|
96 |
-
|
97 |
-
$this->cache->write($key, $content);
|
98 |
-
}
|
99 |
-
|
100 |
-
/**
|
101 |
-
* @expectedException RuntimeException
|
102 |
-
* @expectedExceptionMessage Unable to write in the cache directory
|
103 |
-
*/
|
104 |
-
public function testWriteFailDirWritable()
|
105 |
-
{
|
106 |
-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
107 |
-
$this->markTestSkipped('Read-only directories not possible on Windows.');
|
108 |
-
}
|
109 |
-
|
110 |
-
$key = $this->directory.'/cache/cachefile.php';
|
111 |
-
$content = $this->generateSource();
|
112 |
-
|
113 |
-
$this->assertFalse(file_exists($key));
|
114 |
-
|
115 |
-
// Create root directory.
|
116 |
-
@mkdir($this->directory, 0777, true);
|
117 |
-
// Create read-only subdirectory.
|
118 |
-
@mkdir($this->directory.'/cache', 0555);
|
119 |
-
$this->assertTrue(is_dir($this->directory.'/cache'));
|
120 |
-
|
121 |
-
$this->cache->write($key, $content);
|
122 |
-
}
|
123 |
-
|
124 |
-
/**
|
125 |
-
* @expectedException RuntimeException
|
126 |
-
* @expectedExceptionMessage Failed to write cache file
|
127 |
-
*/
|
128 |
-
public function testWriteFailWriteFile()
|
129 |
-
{
|
130 |
-
$key = $this->directory.'/cache/cachefile.php';
|
131 |
-
$content = $this->generateSource();
|
132 |
-
|
133 |
-
$this->assertFalse(file_exists($key));
|
134 |
-
|
135 |
-
// Create a directory in the place of the cache file.
|
136 |
-
@mkdir($key, 0777, true);
|
137 |
-
$this->assertTrue(is_dir($key));
|
138 |
-
|
139 |
-
$this->cache->write($key, $content);
|
140 |
-
}
|
141 |
-
|
142 |
-
public function testGetTimestamp()
|
143 |
-
{
|
144 |
-
$key = $this->directory.'/cache/cachefile.php';
|
145 |
-
|
146 |
-
$dir = dirname($key);
|
147 |
-
@mkdir($dir, 0777, true);
|
148 |
-
$this->assertTrue(is_dir($dir));
|
149 |
-
|
150 |
-
// Create the file with a specific modification time.
|
151 |
-
touch($key, 1234567890);
|
152 |
-
|
153 |
-
$this->assertSame(1234567890, $this->cache->getTimestamp($key));
|
154 |
-
}
|
155 |
-
|
156 |
-
public function testGetTimestampMissingFile()
|
157 |
-
{
|
158 |
-
$key = $this->directory.'/cache/cachefile.php';
|
159 |
-
$this->assertSame(0, $this->cache->getTimestamp($key));
|
160 |
-
}
|
161 |
-
|
162 |
-
/**
|
163 |
-
* Test file cache is tolerant towards trailing (back)slashes on the configured cache directory.
|
164 |
-
*
|
165 |
-
* @dataProvider provideDirectories
|
166 |
-
*/
|
167 |
-
public function testGenerateKey($expected, $input)
|
168 |
-
{
|
169 |
-
$cache = new Twig_Cache_Filesystem($input);
|
170 |
-
$this->assertRegExp($expected, $cache->generateKey('_test_', get_class($this)));
|
171 |
-
}
|
172 |
-
|
173 |
-
public function provideDirectories()
|
174 |
-
{
|
175 |
-
$pattern = '#a/b/[a-zA-Z0-9]+/[a-zA-Z0-9]+.php$#';
|
176 |
-
|
177 |
-
return array(
|
178 |
-
array($pattern, 'a/b'),
|
179 |
-
array($pattern, 'a/b/'),
|
180 |
-
array($pattern, 'a/b\\'),
|
181 |
-
array($pattern, 'a/b\\/'),
|
182 |
-
array($pattern, 'a/b\\//'),
|
183 |
-
array('#/'.substr($pattern, 1), '/a/b'),
|
184 |
-
);
|
185 |
-
}
|
186 |
-
|
187 |
-
private function generateSource()
|
188 |
-
{
|
189 |
-
return strtr('<?php class {{classname}} {}', array(
|
190 |
-
'{{classname}}' => $this->classname,
|
191 |
-
));
|
192 |
-
}
|
193 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/test/Twig/Tests/CompilerTest.php
DELETED
@@ -1,33 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* This file is part of Twig.
|
5 |
-
*
|
6 |
-
* (c) Fabien Potencier
|
7 |
-
*
|
8 |
-
* For the full copyright and license information, please view the LICENSE
|
9 |
-
* file that was distributed with this source code.
|
10 |
-
*/
|
11 |
-
|
12 |
-
class Twig_Tests_CompilerTest extends PHPUnit_Framework_TestCase
|
13 |
-
{
|
14 |
-
public function testReprNumericValueWithLocale()
|
15 |
-
{
|
16 |
-
$compiler = new Twig_Compiler(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
|
17 |
-
|
18 |
-
$locale = setlocale(LC_NUMERIC, 0);
|
19 |
-
if (false === $locale) {
|
20 |
-
$this->markTestSkipped('Your platform does not support locales.');
|
21 |
-
}
|
22 |
-
|
23 |
-
$required_locales = array('fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8', 'French_France.1252');
|
24 |
-
if (false === setlocale(LC_NUMERIC, $required_locales)) {
|
25 |
-
$this->markTestSkipped('Could not set any of required locales: '.implode(', ', $required_locales));
|
26 |
-
}
|
27 |
-
|
28 |
-
$this->assertEquals('1.2', $compiler->repr(1.2)->getSource());
|
29 |
-
$this->assertContains('fr', strtolower(setlocale(LC_NUMERIC, 0)));
|
30 |
-
|
31 |
-
setlocale(LC_NUMERIC, $locale);
|
32 |
-
}
|
33 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/test/Twig/Tests/EnvironmentTest.php
DELETED
@@ -1,652 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* This file is part of Twig.
|
5 |
-
*
|
6 |
-
* (c) Fabien Potencier
|
7 |
-
*
|
8 |
-
* For the full copyright and license information, please view the LICENSE
|
9 |
-
* file that was distributed with this source code.
|
10 |
-
*/
|
11 |
-
|
12 |
-
require_once dirname(__FILE__).'/FilesystemHelper.php';
|
13 |
-
|
14 |
-
class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
|
15 |
-
{
|
16 |
-
private $deprecations = array();
|
17 |
-
|
18 |
-
/**
|
19 |
-
* @group legacy
|
20 |
-
*/
|
21 |
-
public function testLegacyTokenizeSignature()
|
22 |
-
{
|
23 |
-
$env = new Twig_Environment();
|
24 |
-
$stream = $env->tokenize('{{ foo }}', 'foo');
|
25 |
-
$this->assertEquals('{{ foo }}', $stream->getSource());
|
26 |
-
$this->assertEquals('foo', $stream->getFilename());
|
27 |
-
}
|
28 |
-
|
29 |
-
/**
|
30 |
-
* @group legacy
|
31 |
-
*/
|
32 |
-
public function testLegacyCompileSourceSignature()
|
33 |
-
{
|
34 |
-
$loader = new Twig_Loader_Array(array('foo' => '{{ foo }}'));
|
35 |
-
$env = new Twig_Environment($loader);
|
36 |
-
$this->assertContains('getTemplateName', $env->compileSource('{{ foo }}', 'foo'));
|
37 |
-
}
|
38 |
-
|
39 |
-
/**
|
40 |
-
* @expectedException LogicException
|
41 |
-
* @expectedExceptionMessage You must set a loader first.
|
42 |
-
* @group legacy
|
43 |
-
*/
|
44 |
-
public function testRenderNoLoader()
|
45 |
-
{
|
46 |
-
$env = new Twig_Environment();
|
47 |
-
$env->render('test');
|
48 |
-
}
|
49 |
-
|
50 |
-
public function testAutoescapeOption()
|
51 |
-
{
|
52 |
-
$loader = new Twig_Loader_Array(array(
|
53 |
-
'html' => '{{ foo }} {{ foo }}',
|
54 |
-
'js' => '{{ bar }} {{ bar }}',
|
55 |
-
));
|
56 |
-
|
57 |
-
$twig = new Twig_Environment($loader, array(
|
58 |
-
'debug' => true,
|
59 |
-
'cache' => false,
|
60 |
-
'autoescape' => array($this, 'escapingStrategyCallback'),
|
61 |
-
));
|
62 |
-
|
63 |
-
$this->assertEquals('foo<br/ > foo<br/ >', $twig->render('html', array('foo' => 'foo<br/ >')));
|
64 |
-
$this->assertEquals('foo\x3Cbr\x2F\x20\x3E foo\x3Cbr\x2F\x20\x3E', $twig->render('js', array('bar' => 'foo<br/ >')));
|
65 |
-
}
|
66 |
-
|
67 |
-
public function escapingStrategyCallback($name)
|
68 |
-
{
|
69 |
-
return $name;
|
70 |
-
}
|
71 |
-
|
72 |
-
public function testGlobals()
|
73 |
-
{
|
74 |
-
// to be removed in 2.0
|
75 |
-
$loader = $this->getMockBuilder('Twig_EnvironmentTestLoaderInterface')->getMock();
|
76 |
-
//$loader = $this->getMockBuilder(array('Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface'))->getMock();
|
77 |
-
$loader->expects($this->any())->method('getSourceContext')->will($this->returnValue(new Twig_Source('', '')));
|
78 |
-
|
79 |
-
// globals can be added after calling getGlobals
|
80 |
-
|
81 |
-
$twig = new Twig_Environment($loader);
|
82 |
-
$twig->addGlobal('foo', 'foo');
|
83 |
-
$twig->getGlobals();
|
84 |
-
$twig->addGlobal('foo', 'bar');
|
85 |
-
$globals = $twig->getGlobals();
|
86 |
-
$this->assertEquals('bar', $globals['foo']);
|
87 |
-
|
88 |
-
// globals can be modified after a template has been loaded
|
89 |
-
$twig = new Twig_Environment($loader);
|
90 |
-
$twig->addGlobal('foo', 'foo');
|
91 |
-
$twig->getGlobals();
|
92 |
-
$twig->loadTemplate('index');
|
93 |
-
$twig->addGlobal('foo', 'bar');
|
94 |
-
$globals = $twig->getGlobals();
|
95 |
-
$this->assertEquals('bar', $globals['foo']);
|
96 |
-
|
97 |
-
// globals can be modified after extensions init
|
98 |
-
$twig = new Twig_Environment($loader);
|
99 |
-
$twig->addGlobal('foo', 'foo');
|
100 |
-
$twig->getGlobals();
|
101 |
-
$twig->getFunctions();
|
102 |
-
$twig->addGlobal('foo', 'bar');
|
103 |
-
$globals = $twig->getGlobals();
|
104 |
-
$this->assertEquals('bar', $globals['foo']);
|
105 |
-
|
106 |
-
// globals can be modified after extensions and a template has been loaded
|
107 |
-
$arrayLoader = new Twig_Loader_Array(array('index' => '{{foo}}'));
|
108 |
-
$twig = new Twig_Environment($arrayLoader);
|
109 |
-
$twig->addGlobal('foo', 'foo');
|
110 |
-
$twig->getGlobals();
|
111 |
-
$twig->getFunctions();
|
112 |
-
$twig->loadTemplate('index');
|
113 |
-
$twig->addGlobal('foo', 'bar');
|
114 |
-
$globals = $twig->getGlobals();
|
115 |
-
$this->assertEquals('bar', $globals['foo']);
|
116 |
-
|
117 |
-
$twig = new Twig_Environment($arrayLoader);
|
118 |
-
$twig->getGlobals();
|
119 |
-
$twig->addGlobal('foo', 'bar');
|
120 |
-
$template = $twig->loadTemplate('index');
|
121 |
-
$this->assertEquals('bar', $template->render(array()));
|
122 |
-
|
123 |
-
/* to be uncomment in Twig 2.0
|
124 |
-
// globals cannot be added after a template has been loaded
|
125 |
-
$twig = new Twig_Environment($loader);
|
126 |
-
$twig->addGlobal('foo', 'foo');
|
127 |
-
$twig->getGlobals();
|
128 |
-
$twig->loadTemplate('index');
|
129 |
-
try {
|
130 |
-
$twig->addGlobal('bar', 'bar');
|
131 |
-
$this->fail();
|
132 |
-
} catch (LogicException $e) {
|
133 |
-
$this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
|
134 |
-
}
|
135 |
-
|
136 |
-
// globals cannot be added after extensions init
|
137 |
-
$twig = new Twig_Environment($loader);
|
138 |
-
$twig->addGlobal('foo', 'foo');
|
139 |
-
$twig->getGlobals();
|
140 |
-
$twig->getFunctions();
|
141 |
-
try {
|
142 |
-
$twig->addGlobal('bar', 'bar');
|
143 |
-
$this->fail();
|
144 |
-
} catch (LogicException $e) {
|
145 |
-
$this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
|
146 |
-
}
|
147 |
-
|
148 |
-
// globals cannot be added after extensions and a template has been loaded
|
149 |
-
$twig = new Twig_Environment($loader);
|
150 |
-
$twig->addGlobal('foo', 'foo');
|
151 |
-
$twig->getGlobals();
|
152 |
-
$twig->getFunctions();
|
153 |
-
$twig->loadTemplate('index');
|
154 |
-
try {
|
155 |
-
$twig->addGlobal('bar', 'bar');
|
156 |
-
$this->fail();
|
157 |
-
} catch (LogicException $e) {
|
158 |
-
$this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
|
159 |
-
}
|
160 |
-
|
161 |
-
// test adding globals after a template has been loaded without call to getGlobals
|
162 |
-
$twig = new Twig_Environment($loader);
|
163 |
-
$twig->loadTemplate('index');
|
164 |
-
try {
|
165 |
-
$twig->addGlobal('bar', 'bar');
|
166 |
-
$this->fail();
|
167 |
-
} catch (LogicException $e) {
|
168 |
-
$this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
|
169 |
-
}
|
170 |
-
*/
|
171 |
-
}
|
172 |
-
|
173 |
-
public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate()
|
174 |
-
{
|
175 |
-
$cache = new Twig_Cache_Filesystem($dir = sys_get_temp_dir().'/twig');
|
176 |
-
$options = array('cache' => $cache, 'auto_reload' => false, 'debug' => false);
|
177 |
-
|
178 |
-
// force compilation
|
179 |
-
$twig = new Twig_Environment($loader = new Twig_Loader_Array(array('index' => '{{ foo }}')), $options);
|
180 |
-
|
181 |
-
$key = $cache->generateKey('index', $twig->getTemplateClass('index'));
|
182 |
-
$cache->write($key, $twig->compileSource(new Twig_Source('{{ foo }}', 'index')));
|
183 |
-
|
184 |
-
// check that extensions won't be initialized when rendering a template that is already in the cache
|
185 |
-
$twig = $this
|
186 |
-
->getMockBuilder('Twig_Environment')
|
187 |
-
->setConstructorArgs(array($loader, $options))
|
188 |
-
->setMethods(array('initExtensions'))
|
189 |
-
->getMock()
|
190 |
-
;
|
191 |
-
|
192 |
-
$twig->expects($this->never())->method('initExtensions');
|
193 |
-
|
194 |
-
// render template
|
195 |
-
$output = $twig->render('index', array('foo' => 'bar'));
|
196 |
-
$this->assertEquals('bar', $output);
|
197 |
-
|
198 |
-
Twig_Tests_FilesystemHelper::removeDir($dir);
|
199 |
-
}
|
200 |
-
|
201 |
-
public function testAutoReloadCacheMiss()
|
202 |
-
{
|
203 |
-
$templateName = __FUNCTION__;
|
204 |
-
$templateContent = __FUNCTION__;
|
205 |
-
|
206 |
-
$cache = $this->getMockBuilder('Twig_CacheInterface')->getMock();
|
207 |
-
$loader = $this->getMockLoader($templateName, $templateContent);
|
208 |
-
$twig = new Twig_Environment($loader, array('cache' => $cache, 'auto_reload' => true, 'debug' => false));
|
209 |
-
|
210 |
-
// Cache miss: getTimestamp returns 0 and as a result the load() is
|
211 |
-
// skipped.
|
212 |
-
$cache->expects($this->once())
|
213 |
-
->method('generateKey')
|
214 |
-
->will($this->returnValue('key'));
|
215 |
-
$cache->expects($this->once())
|
216 |
-
->method('getTimestamp')
|
217 |
-
->will($this->returnValue(0));
|
218 |
-
$loader->expects($this->never())
|
219 |
-
->method('isFresh');
|
220 |
-
$cache->expects($this->once())
|
221 |
-
->method('write');
|
222 |
-
$cache->expects($this->once())
|
223 |
-
->method('load');
|
224 |
-
|
225 |
-
$twig->loadTemplate($templateName);
|
226 |
-
}
|
227 |
-
|
228 |
-
public function testAutoReloadCacheHit()
|
229 |
-
{
|
230 |
-
$templateName = __FUNCTION__;
|
231 |
-
$templateContent = __FUNCTION__;
|
232 |
-
|
233 |
-
$cache = $this->getMockBuilder('Twig_CacheInterface')->getMock();
|
234 |
-
$loader = $this->getMockLoader($templateName, $templateContent);
|
235 |
-
$twig = new Twig_Environment($loader, array('cache' => $cache, 'auto_reload' => true, 'debug' => false));
|
236 |
-
|
237 |
-
$now = time();
|
238 |
-
|
239 |
-
// Cache hit: getTimestamp returns something > extension timestamps and
|
240 |
-
// the loader returns true for isFresh().
|
241 |
-
$cache->expects($this->once())
|
242 |
-
->method('generateKey')
|
243 |
-
->will($this->returnValue('key'));
|
244 |
-
$cache->expects($this->once())
|
245 |
-
->method('getTimestamp')
|
246 |
-
->will($this->returnValue($now));
|
247 |
-
$loader->expects($this->once())
|
248 |
-
->method('isFresh')
|
249 |
-
->will($this->returnValue(true));
|
250 |
-
$cache->expects($this->atLeastOnce())
|
251 |
-
->method('load');
|
252 |
-
|
253 |
-
$twig->loadTemplate($templateName);
|
254 |
-
}
|
255 |
-
|
256 |
-
public function testAutoReloadOutdatedCacheHit()
|
257 |
-
{
|
258 |
-
$templateName = __FUNCTION__;
|
259 |
-
$templateContent = __FUNCTION__;
|
260 |
-
|
261 |
-
$cache = $this->getMockBuilder('Twig_CacheInterface')->getMock();
|
262 |
-
$loader = $this->getMockLoader($templateName, $templateContent);
|
263 |
-
$twig = new Twig_Environment($loader, array('cache' => $cache, 'auto_reload' => true, 'debug' => false));
|
264 |
-
|
265 |
-
$now = time();
|
266 |
-
|
267 |
-
$cache->expects($this->once())
|
268 |
-
->method('generateKey')
|
269 |
-
->will($this->returnValue('key'));
|
270 |
-
$cache->expects($this->once())
|
271 |
-
->method('getTimestamp')
|
272 |
-
->will($this->returnValue($now));
|
273 |
-
$loader->expects($this->once())
|
274 |
-
->method('isFresh')
|
275 |
-
->will($this->returnValue(false));
|
276 |
-
$cache->expects($this->once())
|
277 |
-
->method('write');
|
278 |
-
$cache->expects($this->once())
|
279 |
-
->method('load');
|
280 |
-
|
281 |
-
$twig->loadTemplate($templateName);
|
282 |
-
}
|
283 |
-
|
284 |
-
/**
|
285 |
-
* @group legacy
|
286 |
-
*/
|
287 |
-
public function testHasGetExtensionWithDynamicName()
|
288 |
-
{
|
289 |
-
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
290 |
-
|
291 |
-
$ext1 = new Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName('ext1');
|
292 |
-
$ext2 = new Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName('ext2');
|
293 |
-
$twig->addExtension($ext1);
|
294 |
-
$twig->addExtension($ext2);
|
295 |
-
|
296 |
-
$this->assertTrue($twig->hasExtension('ext1'));
|
297 |
-
$this->assertTrue($twig->hasExtension('ext2'));
|
298 |
-
|
299 |
-
$this->assertTrue($twig->hasExtension('Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName'));
|
300 |
-
|
301 |
-
$this->assertSame($ext1, $twig->getExtension('ext1'));
|
302 |
-
$this->assertSame($ext2, $twig->getExtension('ext2'));
|
303 |
-
}
|
304 |
-
|
305 |
-
public function testHasGetExtensionByClassName()
|
306 |
-
{
|
307 |
-
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
308 |
-
$twig->addExtension($ext = new Twig_Tests_EnvironmentTest_Extension());
|
309 |
-
$this->assertTrue($twig->hasExtension('Twig_Tests_EnvironmentTest_Extension'));
|
310 |
-
$this->assertTrue($twig->hasExtension('\Twig_Tests_EnvironmentTest_Extension'));
|
311 |
-
|
312 |
-
$this->assertSame($ext, $twig->getExtension('Twig_Tests_EnvironmentTest_Extension'));
|
313 |
-
$this->assertSame($ext, $twig->getExtension('\Twig_Tests_EnvironmentTest_Extension'));
|
314 |
-
}
|
315 |
-
|
316 |
-
public function testAddExtension()
|
317 |
-
{
|
318 |
-
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
319 |
-
$twig->addExtension(new Twig_Tests_EnvironmentTest_Extension());
|
320 |
-
|
321 |
-
$this->assertArrayHasKey('test', $twig->getTags());
|
322 |
-
$this->assertArrayHasKey('foo_filter', $twig->getFilters());
|
323 |
-
$this->assertArrayHasKey('foo_function', $twig->getFunctions());
|
324 |
-
$this->assertArrayHasKey('foo_test', $twig->getTests());
|
325 |
-
$this->assertArrayHasKey('foo_unary', $twig->getUnaryOperators());
|
326 |
-
$this->assertArrayHasKey('foo_binary', $twig->getBinaryOperators());
|
327 |
-
$this->assertArrayHasKey('foo_global', $twig->getGlobals());
|
328 |
-
$visitors = $twig->getNodeVisitors();
|
329 |
-
$found = false;
|
330 |
-
foreach ($visitors as $visitor) {
|
331 |
-
if ($visitor instanceof Twig_Tests_EnvironmentTest_NodeVisitor) {
|
332 |
-
$found = true;
|
333 |
-
}
|
334 |
-
}
|
335 |
-
$this->assertTrue($found);
|
336 |
-
}
|
337 |
-
|
338 |
-
/**
|
339 |
-
* @requires PHP 5.3
|
340 |
-
*/
|
341 |
-
public function testAddExtensionWithDeprecatedGetGlobals()
|
342 |
-
{
|
343 |
-
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
344 |
-
$twig->addExtension(new Twig_Tests_EnvironmentTest_Extension_WithGlobals());
|
345 |
-
|
346 |
-
$this->deprecations = array();
|
347 |
-
set_error_handler(array($this, 'handleError'));
|
348 |
-
|
349 |
-
$this->assertArrayHasKey('foo_global', $twig->getGlobals());
|
350 |
-
|
351 |
-
$this->assertCount(1, $this->deprecations);
|
352 |
-
$this->assertContains('Defining the getGlobals() method in the "Twig_Tests_EnvironmentTest_Extension_WithGlobals" extension ', $this->deprecations[0]);
|
353 |
-
|
354 |
-
restore_error_handler();
|
355 |
-
}
|
356 |
-
|
357 |
-
/**
|
358 |
-
* @group legacy
|
359 |
-
*/
|
360 |
-
public function testRemoveExtension()
|
361 |
-
{
|
362 |
-
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
363 |
-
$twig->addExtension(new Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName());
|
364 |
-
$twig->removeExtension('environment_test');
|
365 |
-
|
366 |
-
$this->assertFalse(array_key_exists('test', $twig->getTags()));
|
367 |
-
$this->assertFalse(array_key_exists('foo_filter', $twig->getFilters()));
|
368 |
-
$this->assertFalse(array_key_exists('foo_function', $twig->getFunctions()));
|
369 |
-
$this->assertFalse(array_key_exists('foo_test', $twig->getTests()));
|
370 |
-
$this->assertFalse(array_key_exists('foo_unary', $twig->getUnaryOperators()));
|
371 |
-
$this->assertFalse(array_key_exists('foo_binary', $twig->getBinaryOperators()));
|
372 |
-
$this->assertFalse(array_key_exists('foo_global', $twig->getGlobals()));
|
373 |
-
$this->assertCount(2, $twig->getNodeVisitors());
|
374 |
-
}
|
375 |
-
|
376 |
-
public function testAddMockExtension()
|
377 |
-
{
|
378 |
-
// should be replaced by the following in 2.0 (this current code is just to avoid a dep notice)
|
379 |
-
// $extension = $this->getMockBuilder('Twig_Extension')->getMock();
|
380 |
-
$extension = eval(<<<EOF
|
381 |
-
class Twig_Tests_EnvironmentTest_ExtensionInEval extends Twig_Extension
|
382 |
-
{
|
383 |
-
}
|
384 |
-
EOF
|
385 |
-
);
|
386 |
-
$extension = new Twig_Tests_EnvironmentTest_ExtensionInEval();
|
387 |
-
|
388 |
-
$loader = new Twig_Loader_Array(array('page' => 'hey'));
|
389 |
-
|
390 |
-
$twig = new Twig_Environment($loader);
|
391 |
-
$twig->addExtension($extension);
|
392 |
-
|
393 |
-
$this->assertInstanceOf('Twig_ExtensionInterface', $twig->getExtension(get_class($extension)));
|
394 |
-
$this->assertTrue($twig->isTemplateFresh('page', time()));
|
395 |
-
}
|
396 |
-
|
397 |
-
public function testInitRuntimeWithAnExtensionUsingInitRuntimeNoDeprecation()
|
398 |
-
{
|
399 |
-
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
400 |
-
$twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime());
|
401 |
-
|
402 |
-
$twig->initRuntime();
|
403 |
-
}
|
404 |
-
|
405 |
-
/**
|
406 |
-
* @requires PHP 5.3
|
407 |
-
*/
|
408 |
-
public function testInitRuntimeWithAnExtensionUsingInitRuntimeDeprecation()
|
409 |
-
{
|
410 |
-
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
411 |
-
$twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime());
|
412 |
-
|
413 |
-
$this->deprecations = array();
|
414 |
-
set_error_handler(array($this, 'handleError'));
|
415 |
-
|
416 |
-
$twig->initRuntime();
|
417 |
-
|
418 |
-
$this->assertCount(1, $this->deprecations);
|
419 |
-
$this->assertContains('Defining the initRuntime() method in the "Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime" extension is deprecated since version 1.23.', $this->deprecations[0]);
|
420 |
-
|
421 |
-
restore_error_handler();
|
422 |
-
}
|
423 |
-
|
424 |
-
public function handleError($type, $msg)
|
425 |
-
{
|
426 |
-
if (E_USER_DEPRECATED === $type) {
|
427 |
-
$this->deprecations[] = $msg;
|
428 |
-
}
|
429 |
-
}
|
430 |
-
|
431 |
-
/**
|
432 |
-
* @requires PHP 5.3
|
433 |
-
*/
|
434 |
-
public function testOverrideExtension()
|
435 |
-
{
|
436 |
-
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
437 |
-
$twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime());
|
438 |
-
|
439 |
-
$this->deprecations = array();
|
440 |
-
set_error_handler(array($this, 'handleError'));
|
441 |
-
|
442 |
-
$twig->addExtension(new Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName());
|
443 |
-
$twig->addExtension(new Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName());
|
444 |
-
|
445 |
-
$this->assertCount(1, $this->deprecations);
|
446 |
-
$this->assertContains('The possibility to register the same extension twice', $this->deprecations[0]);
|
447 |
-
|
448 |
-
restore_error_handler();
|
449 |
-
}
|
450 |
-
|
451 |
-
public function testAddRuntimeLoader()
|
452 |
-
{
|
453 |
-
$runtimeLoader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock();
|
454 |
-
$runtimeLoader->expects($this->any())->method('load')->will($this->returnValue(new Twig_Tests_EnvironmentTest_Runtime()));
|
455 |
-
|
456 |
-
$loader = new Twig_Loader_Array(array(
|
457 |
-
'func_array' => '{{ from_runtime_array("foo") }}',
|
458 |
-
'func_array_default' => '{{ from_runtime_array() }}',
|
459 |
-
'func_array_named_args' => '{{ from_runtime_array(name="foo") }}',
|
460 |
-
'func_string' => '{{ from_runtime_string("foo") }}',
|
461 |
-
'func_string_default' => '{{ from_runtime_string() }}',
|
462 |
-
'func_string_named_args' => '{{ from_runtime_string(name="foo") }}',
|
463 |
-
));
|
464 |
-
|
465 |
-
$twig = new Twig_Environment($loader);
|
466 |
-
$twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutRuntime());
|
467 |
-
$twig->addRuntimeLoader($runtimeLoader);
|
468 |
-
|
469 |
-
$this->assertEquals('foo', $twig->render('func_array'));
|
470 |
-
$this->assertEquals('bar', $twig->render('func_array_default'));
|
471 |
-
$this->assertEquals('foo', $twig->render('func_array_named_args'));
|
472 |
-
$this->assertEquals('foo', $twig->render('func_string'));
|
473 |
-
$this->assertEquals('bar', $twig->render('func_string_default'));
|
474 |
-
$this->assertEquals('foo', $twig->render('func_string_named_args'));
|
475 |
-
}
|
476 |
-
|
477 |
-
protected function getMockLoader($templateName, $templateContent)
|
478 |
-
{
|
479 |
-
// to be removed in 2.0
|
480 |
-
$loader = $this->getMockBuilder('Twig_EnvironmentTestLoaderInterface')->getMock();
|
481 |
-
//$loader = $this->getMockBuilder(array('Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface'))->getMock();
|
482 |
-
$loader->expects($this->any())
|
483 |
-
->method('getSourceContext')
|
484 |
-
->with($templateName)
|
485 |
-
->will($this->returnValue(new Twig_Source($templateContent, $templateName)));
|
486 |
-
$loader->expects($this->any())
|
487 |
-
->method('getCacheKey')
|
488 |
-
->with($templateName)
|
489 |
-
->will($this->returnValue($templateName));
|
490 |
-
|
491 |
-
return $loader;
|
492 |
-
}
|
493 |
-
}
|
494 |
-
|
495 |
-
class Twig_Tests_EnvironmentTest_Extension_WithGlobals extends Twig_Extension
|
496 |
-
{
|
497 |
-
public function getGlobals()
|
498 |
-
{
|
499 |
-
return array(
|
500 |
-
'foo_global' => 'foo_global',
|
501 |
-
);
|
502 |
-
}
|
503 |
-
}
|
504 |
-
|
505 |
-
class Twig_Tests_EnvironmentTest_Extension extends Twig_Extension implements Twig_Extension_GlobalsInterface
|
506 |
-
{
|
507 |
-
public function getTokenParsers()
|
508 |
-
{
|
509 |
-
return array(
|
510 |
-
new Twig_Tests_EnvironmentTest_TokenParser(),
|
511 |
-
);
|
512 |
-
}
|
513 |
-
|
514 |
-
public function getNodeVisitors()
|
515 |
-
{
|
516 |
-
return array(
|
517 |
-
new Twig_Tests_EnvironmentTest_NodeVisitor(),
|
518 |
-
);
|
519 |
-
}
|
520 |
-
|
521 |
-
public function getFilters()
|
522 |
-
{
|
523 |
-
return array(
|
524 |
-
new Twig_SimpleFilter('foo_filter', 'foo_filter'),
|
525 |
-
);
|
526 |
-
}
|
527 |
-
|
528 |
-
public function getTests()
|
529 |
-
{
|
530 |
-
return array(
|
531 |
-
new Twig_SimpleTest('foo_test', 'foo_test'),
|
532 |
-
);
|
533 |
-
}
|
534 |
-
|
535 |
-
public function getFunctions()
|
536 |
-
{
|
537 |
-
return array(
|
538 |
-
new Twig_SimpleFunction('foo_function', 'foo_function'),
|
539 |
-
);
|
540 |
-
}
|
541 |
-
|
542 |
-
public function getOperators()
|
543 |
-
{
|
544 |
-
return array(
|
545 |
-
array('foo_unary' => array()),
|
546 |
-
array('foo_binary' => array()),
|
547 |
-
);
|
548 |
-
}
|
549 |
-
|
550 |
-
public function getGlobals()
|
551 |
-
{
|
552 |
-
return array(
|
553 |
-
'foo_global' => 'foo_global',
|
554 |
-
);
|
555 |
-
}
|
556 |
-
}
|
557 |
-
|
558 |
-
class Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName extends Twig_Extension
|
559 |
-
{
|
560 |
-
public function getName()
|
561 |
-
{
|
562 |
-
return 'environment_test';
|
563 |
-
}
|
564 |
-
}
|
565 |
-
|
566 |
-
class Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName extends Twig_Extension
|
567 |
-
{
|
568 |
-
private $name;
|
569 |
-
|
570 |
-
public function __construct($name)
|
571 |
-
{
|
572 |
-
$this->name = $name;
|
573 |
-
}
|
574 |
-
|
575 |
-
public function getName()
|
576 |
-
{
|
577 |
-
return $this->name;
|
578 |
-
}
|
579 |
-
}
|
580 |
-
|
581 |
-
class Twig_Tests_EnvironmentTest_TokenParser extends Twig_TokenParser
|
582 |
-
{
|
583 |
-
public function parse(Twig_Token $token)
|
584 |
-
{
|
585 |
-
}
|
586 |
-
|
587 |
-
public function getTag()
|
588 |
-
{
|
589 |
-
return 'test';
|
590 |
-
}
|
591 |
-
}
|
592 |
-
|
593 |
-
class Twig_Tests_EnvironmentTest_NodeVisitor implements Twig_NodeVisitorInterface
|
594 |
-
{
|
595 |
-
public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
|
596 |
-
{
|
597 |
-
return $node;
|
598 |
-
}
|
599 |
-
|
600 |
-
public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
|
601 |
-
{
|
602 |
-
return $node;
|
603 |
-
}
|
604 |
-
|
605 |
-
public function getPriority()
|
606 |
-
{
|
607 |
-
return 0;
|
608 |
-
}
|
609 |
-
}
|
610 |
-
|
611 |
-
class Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime extends Twig_Extension
|
612 |
-
{
|
613 |
-
public function initRuntime(Twig_Environment $env)
|
614 |
-
{
|
615 |
-
}
|
616 |
-
}
|
617 |
-
|
618 |
-
class Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime extends Twig_Extension implements Twig_Extension_InitRuntimeInterface
|
619 |
-
{
|
620 |
-
public function initRuntime(Twig_Environment $env)
|
621 |
-
{
|
622 |
-
}
|
623 |
-
}
|
624 |
-
|
625 |
-
class Twig_Tests_EnvironmentTest_ExtensionWithoutRuntime extends Twig_Extension
|
626 |
-
{
|
627 |
-
public function getFunctions()
|
628 |
-
{
|
629 |
-
return array(
|
630 |
-
new Twig_SimpleFunction('from_runtime_array', array('Twig_Tests_EnvironmentTest_Runtime', 'fromRuntime')),
|
631 |
-
new Twig_SimpleFunction('from_runtime_string', 'Twig_Tests_EnvironmentTest_Runtime::fromRuntime'),
|
632 |
-
);
|
633 |
-
}
|
634 |
-
|
635 |
-
public function getName()
|
636 |
-
{
|
637 |
-
return 'from_runtime';
|
638 |
-
}
|
639 |
-
}
|
640 |
-
|
641 |
-
class Twig_Tests_EnvironmentTest_Runtime
|
642 |
-
{
|
643 |
-
public function fromRuntime($name = 'bar')
|
644 |
-
{
|
645 |
-
return $name;
|
646 |
-
}
|
647 |
-
}
|
648 |
-
|
649 |
-
// to be removed in 2.0
|
650 |
-
interface Twig_EnvironmentTestLoaderInterface extends Twig_LoaderInterface, Twig_SourceContextLoaderInterface
|
651 |
-
{
|
652 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/test/Twig/Tests/ErrorTest.php
DELETED
@@ -1,144 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* This file is part of Twig.
|
5 |
-
*
|
6 |
-
* (c) Fabien Potencier
|
7 |
-
*
|
8 |
-
* For the full copyright and license information, please view the LICENSE
|
9 |
-
* file that was distributed with this source code.
|
10 |
-
*/
|
11 |
-
|
12 |
-
class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase
|
13 |
-
{
|
14 |
-
public function testErrorWithObjectFilename()
|
15 |
-
{
|
16 |
-
$error = new Twig_Error('foo');
|
17 |
-
$error->setTemplateName(new SplFileInfo(__FILE__));
|
18 |
-
|
19 |
-
$this->assertContains('test'.DIRECTORY_SEPARATOR.'Twig'.DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR.'ErrorTest.php', $error->getMessage());
|
20 |
-
}
|
21 |
-
|
22 |
-
public function testErrorWithArrayFilename()
|
23 |
-
{
|
24 |
-
$error = new Twig_Error('foo');
|
25 |
-
$error->setTemplateName(array('foo' => 'bar'));
|
26 |
-
|
27 |
-
$this->assertEquals('foo in {"foo":"bar"}', $error->getMessage());
|
28 |
-
}
|
29 |
-
|
30 |
-
public function testTwigExceptionAddsFileAndLineWhenMissingWithInheritanceOnDisk()
|
31 |
-
{
|
32 |
-
$loader = new Twig_Loader_Filesystem(dirname(__FILE__).'/Fixtures/errors');
|
33 |
-
$twig = new Twig_Environment($loader, array('strict_variables' => true, 'debug' => true, 'cache' => false));
|
34 |
-
|
35 |
-
$template = $twig->loadTemplate('index.html');
|
36 |
-
try {
|
37 |
-
$template->render(array());
|
38 |
-
|
39 |
-
$this->fail();
|
40 |
-
} catch (Twig_Error_Runtime $e) {
|
41 |
-
$this->assertEquals('Variable "foo" does not exist in "index.html" at line 3.', $e->getMessage());
|
42 |
-
$this->assertEquals(3, $e->getTemplateLine());
|
43 |
-
$this->assertEquals('index.html', $e->getTemplateName());
|
44 |
-
}
|
45 |
-
|
46 |
-
try {
|
47 |
-
$template->render(array('foo' => new Twig_Tests_ErrorTest_Foo()));
|
48 |
-
|
49 |
-
$this->fail();
|
50 |
-
} catch (Twig_Error_Runtime $e) {
|
51 |
-
$this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...") in "index.html" at line 3.', $e->getMessage());
|
52 |
-
$this->assertEquals(3, $e->getTemplateLine());
|
53 |
-
$this->assertEquals('index.html', $e->getTemplateName());
|
54 |
-
}
|
55 |
-
}
|
56 |
-
|
57 |
-
/**
|
58 |
-
* @dataProvider getErroredTemplates
|
59 |
-
*/
|
60 |
-
public function testTwigExceptionAddsFileAndLine($templates, $name, $line)
|
61 |
-
{
|
62 |
-
$loader = new Twig_Loader_Array($templates);
|
63 |
-
$twig = new Twig_Environment($loader, array('strict_variables' => true, 'debug' => true, 'cache' => false));
|
64 |
-
|
65 |
-
$template = $twig->loadTemplate('index');
|
66 |
-
|
67 |
-
try {
|
68 |
-
$template->render(array());
|
69 |
-
|
70 |
-
$this->fail();
|
71 |
-
} catch (Twig_Error_Runtime $e) {
|
72 |
-
$this->assertEquals(sprintf('Variable "foo" does not exist in "%s" at line %d.', $name, $line), $e->getMessage());
|
73 |
-
$this->assertEquals($line, $e->getTemplateLine());
|
74 |
-
$this->assertEquals($name, $e->getTemplateName());
|
75 |
-
}
|
76 |
-
|
77 |
-
try {
|
78 |
-
$template->render(array('foo' => new Twig_Tests_ErrorTest_Foo()));
|
79 |
-
|
80 |
-
$this->fail();
|
81 |
-
} catch (Twig_Error_Runtime $e) {
|
82 |
-
$this->assertEquals(sprintf('An exception has been thrown during the rendering of a template ("Runtime error...") in "%s" at line %d.', $name, $line), $e->getMessage());
|
83 |
-
$this->assertEquals($line, $e->getTemplateLine());
|
84 |
-
$this->assertEquals($name, $e->getTemplateName());
|
85 |
-
}
|
86 |
-
}
|
87 |
-
|
88 |
-
public function getErroredTemplates()
|
89 |
-
{
|
90 |
-
return array(
|
91 |
-
// error occurs in a template
|
92 |
-
array(
|
93 |
-
array(
|
94 |
-
'index' => "\n\n{{ foo.bar }}\n\n\n{{ 'foo' }}",
|
95 |
-
),
|
96 |
-
'index', 3,
|
97 |
-
),
|
98 |
-
|
99 |
-
// error occurs in an included template
|
100 |
-
array(
|
101 |
-
array(
|
102 |
-
'index' => "{% include 'partial' %}",
|
103 |
-
'partial' => '{{ foo.bar }}',
|
104 |
-
),
|
105 |
-
'partial', 1,
|
106 |
-
),
|
107 |
-
|
108 |
-
// error occurs in a parent block when called via parent()
|
109 |
-
array(
|
110 |
-
array(
|
111 |
-
'index' => "{% extends 'base' %}
|
112 |
-
{% block content %}
|
113 |
-
{{ parent() }}
|
114 |
-
{% endblock %}",
|
115 |
-
'base' => '{% block content %}{{ foo.bar }}{% endblock %}',
|
116 |
-
),
|
117 |
-
'base', 1,
|
118 |
-
),
|
119 |
-
|
120 |
-
// error occurs in a block from the child
|
121 |
-
array(
|
122 |
-
array(
|
123 |
-
'index' => "{% extends 'base' %}
|
124 |
-
{% block content %}
|
125 |
-
{{ foo.bar }}
|
126 |
-
{% endblock %}
|
127 |
-
{% block foo %}
|
128 |
-
{{ foo.bar }}
|
129 |
-
{% endblock %}",
|
130 |
-
'base' => '{% block content %}{% endblock %}',
|
131 |
-
),
|
132 |
-
'index', 3,
|
133 |
-
),
|
134 |
-
);
|
135 |
-
}
|
136 |
-
}
|
137 |
-
|
138 |
-
class Twig_Tests_ErrorTest_Foo
|
139 |
-
{
|
140 |
-
public function bar()
|
141 |
-
{
|
142 |
-
throw new Exception('Runtime error...');
|
143 |
-
}
|
144 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/test/Twig/Tests/ExpressionParserTest.php
DELETED
@@ -1,373 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* This file is part of Twig.
|
5 |
-
*
|
6 |
-
* (c) Fabien Potencier
|
7 |
-
*
|
8 |
-
* For the full copyright and license information, please view the LICENSE
|
9 |
-
* file that was distributed with this source code.
|
10 |
-
*/
|
11 |
-
|
12 |
-
class Twig_Tests_ExpressionParserTest extends PHPUnit_Framework_TestCase
|
13 |
-
{
|
14 |
-
/**
|
15 |
-
* @expectedException Twig_Error_Syntax
|
16 |
-
* @dataProvider getFailingTestsForAssignment
|
17 |
-
*/
|
18 |
-
public function testCanOnlyAssignToNames($template)
|
19 |
-
{
|
20 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
21 |
-
$parser = new Twig_Parser($env);
|
22 |
-
|
23 |
-
$parser->parse($env->tokenize(new Twig_Source($template, 'index')));
|
24 |
-
}
|
25 |
-
|
26 |
-
public function getFailingTestsForAssignment()
|
27 |
-
{
|
28 |
-
return array(
|
29 |
-
array('{% set false = "foo" %}'),
|
30 |
-
array('{% set FALSE = "foo" %}'),
|
31 |
-
array('{% set true = "foo" %}'),
|
32 |
-
array('{% set TRUE = "foo" %}'),
|
33 |
-
array('{% set none = "foo" %}'),
|
34 |
-
array('{% set NONE = "foo" %}'),
|
35 |
-
array('{% set null = "foo" %}'),
|
36 |
-
array('{% set NULL = "foo" %}'),
|
37 |
-
array('{% set 3 = "foo" %}'),
|
38 |
-
array('{% set 1 + 2 = "foo" %}'),
|
39 |
-
array('{% set "bar" = "foo" %}'),
|
40 |
-
array('{% set %}{% endset %}'),
|
41 |
-
);
|
42 |
-
}
|
43 |
-
|
44 |
-
/**
|
45 |
-
* @dataProvider getTestsForArray
|
46 |
-
*/
|
47 |
-
public function testArrayExpression($template, $expected)
|
48 |
-
{
|
49 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
50 |
-
$stream = $env->tokenize(new Twig_Source($template, ''));
|
51 |
-
$parser = new Twig_Parser($env);
|
52 |
-
|
53 |
-
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr'));
|
54 |
-
}
|
55 |
-
|
56 |
-
/**
|
57 |
-
* @expectedException Twig_Error_Syntax
|
58 |
-
* @dataProvider getFailingTestsForArray
|
59 |
-
*/
|
60 |
-
public function testArraySyntaxError($template)
|
61 |
-
{
|
62 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
63 |
-
$parser = new Twig_Parser($env);
|
64 |
-
|
65 |
-
$parser->parse($env->tokenize(new Twig_Source($template, 'index')));
|
66 |
-
}
|
67 |
-
|
68 |
-
public function getFailingTestsForArray()
|
69 |
-
{
|
70 |
-
return array(
|
71 |
-
array('{{ [1, "a": "b"] }}'),
|
72 |
-
array('{{ {"a": "b", 2} }}'),
|
73 |
-
);
|
74 |
-
}
|
75 |
-
|
76 |
-
public function getTestsForArray()
|
77 |
-
{
|
78 |
-
return array(
|
79 |
-
// simple array
|
80 |
-
array('{{ [1, 2] }}', new Twig_Node_Expression_Array(array(
|
81 |
-
new Twig_Node_Expression_Constant(0, 1),
|
82 |
-
new Twig_Node_Expression_Constant(1, 1),
|
83 |
-
|
84 |
-
new Twig_Node_Expression_Constant(1, 1),
|
85 |
-
new Twig_Node_Expression_Constant(2, 1),
|
86 |
-
), 1),
|
87 |
-
),
|
88 |
-
|
89 |
-
// array with trailing ,
|
90 |
-
array('{{ [1, 2, ] }}', new Twig_Node_Expression_Array(array(
|
91 |
-
new Twig_Node_Expression_Constant(0, 1),
|
92 |
-
new Twig_Node_Expression_Constant(1, 1),
|
93 |
-
|
94 |
-
new Twig_Node_Expression_Constant(1, 1),
|
95 |
-
new Twig_Node_Expression_Constant(2, 1),
|
96 |
-
), 1),
|
97 |
-
),
|
98 |
-
|
99 |
-
// simple hash
|
100 |
-
array('{{ {"a": "b", "b": "c"} }}', new Twig_Node_Expression_Array(array(
|
101 |
-
new Twig_Node_Expression_Constant('a', 1),
|
102 |
-
new Twig_Node_Expression_Constant('b', 1),
|
103 |
-
|
104 |
-
new Twig_Node_Expression_Constant('b', 1),
|
105 |
-
new Twig_Node_Expression_Constant('c', 1),
|
106 |
-
), 1),
|
107 |
-
),
|
108 |
-
|
109 |
-
// hash with trailing ,
|
110 |
-
array('{{ {"a": "b", "b": "c", } }}', new Twig_Node_Expression_Array(array(
|
111 |
-
new Twig_Node_Expression_Constant('a', 1),
|
112 |
-
new Twig_Node_Expression_Constant('b', 1),
|
113 |
-
|
114 |
-
new Twig_Node_Expression_Constant('b', 1),
|
115 |
-
new Twig_Node_Expression_Constant('c', 1),
|
116 |
-
), 1),
|
117 |
-
),
|
118 |
-
|
119 |
-
// hash in an array
|
120 |
-
array('{{ [1, {"a": "b", "b": "c"}] }}', new Twig_Node_Expression_Array(array(
|
121 |
-
new Twig_Node_Expression_Constant(0, 1),
|
122 |
-
new Twig_Node_Expression_Constant(1, 1),
|
123 |
-
|
124 |
-
new Twig_Node_Expression_Constant(1, 1),
|
125 |
-
new Twig_Node_Expression_Array(array(
|
126 |
-
new Twig_Node_Expression_Constant('a', 1),
|
127 |
-
new Twig_Node_Expression_Constant('b', 1),
|
128 |
-
|
129 |
-
new Twig_Node_Expression_Constant('b', 1),
|
130 |
-
new Twig_Node_Expression_Constant('c', 1),
|
131 |
-
), 1),
|
132 |
-
), 1),
|
133 |
-
),
|
134 |
-
|
135 |
-
// array in a hash
|
136 |
-
array('{{ {"a": [1, 2], "b": "c"} }}', new Twig_Node_Expression_Array(array(
|
137 |
-
new Twig_Node_Expression_Constant('a', 1),
|
138 |
-
new Twig_Node_Expression_Array(array(
|
139 |
-
new Twig_Node_Expression_Constant(0, 1),
|
140 |
-
new Twig_Node_Expression_Constant(1, 1),
|
141 |
-
|
142 |
-
new Twig_Node_Expression_Constant(1, 1),
|
143 |
-
new Twig_Node_Expression_Constant(2, 1),
|
144 |
-
), 1),
|
145 |
-
new Twig_Node_Expression_Constant('b', 1),
|
146 |
-
new Twig_Node_Expression_Constant('c', 1),
|
147 |
-
), 1),
|
148 |
-
),
|
149 |
-
);
|
150 |
-
}
|
151 |
-
|
152 |
-
/**
|
153 |
-
* @expectedException Twig_Error_Syntax
|
154 |
-
*/
|
155 |
-
public function testStringExpressionDoesNotConcatenateTwoConsecutiveStrings()
|
156 |
-
{
|
157 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
|
158 |
-
$stream = $env->tokenize(new Twig_Source('{{ "a" "b" }}', 'index'));
|
159 |
-
$parser = new Twig_Parser($env);
|
160 |
-
|
161 |
-
$parser->parse($stream);
|
162 |
-
}
|
163 |
-
|
164 |
-
/**
|
165 |
-
* @dataProvider getTestsForString
|
166 |
-
*/
|
167 |
-
public function testStringExpression($template, $expected)
|
168 |
-
{
|
169 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
|
170 |
-
$stream = $env->tokenize(new Twig_Source($template, ''));
|
171 |
-
$parser = new Twig_Parser($env);
|
172 |
-
|
173 |
-
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr'));
|
174 |
-
}
|
175 |
-
|
176 |
-
public function getTestsForString()
|
177 |
-
{
|
178 |
-
return array(
|
179 |
-
array(
|
180 |
-
'{{ "foo" }}', new Twig_Node_Expression_Constant('foo', 1),
|
181 |
-
),
|
182 |
-
array(
|
183 |
-
'{{ "foo #{bar}" }}', new Twig_Node_Expression_Binary_Concat(
|
184 |
-
new Twig_Node_Expression_Constant('foo ', 1),
|
185 |
-
new Twig_Node_Expression_Name('bar', 1),
|
186 |
-
1
|
187 |
-
),
|
188 |
-
),
|
189 |
-
array(
|
190 |
-
'{{ "foo #{bar} baz" }}', new Twig_Node_Expression_Binary_Concat(
|
191 |
-
new Twig_Node_Expression_Binary_Concat(
|
192 |
-
new Twig_Node_Expression_Constant('foo ', 1),
|
193 |
-
new Twig_Node_Expression_Name('bar', 1),
|
194 |
-
1
|
195 |
-
),
|
196 |
-
new Twig_Node_Expression_Constant(' baz', 1),
|
197 |
-
1
|
198 |
-
),
|
199 |
-
),
|
200 |
-
|
201 |
-
array(
|
202 |
-
'{{ "foo #{"foo #{bar} baz"} baz" }}', new Twig_Node_Expression_Binary_Concat(
|
203 |
-
new Twig_Node_Expression_Binary_Concat(
|
204 |
-
new Twig_Node_Expression_Constant('foo ', 1),
|
205 |
-
new Twig_Node_Expression_Binary_Concat(
|
206 |
-
new Twig_Node_Expression_Binary_Concat(
|
207 |
-
new Twig_Node_Expression_Constant('foo ', 1),
|
208 |
-
new Twig_Node_Expression_Name('bar', 1),
|
209 |
-
1
|
210 |
-
),
|
211 |
-
new Twig_Node_Expression_Constant(' baz', 1),
|
212 |
-
1
|
213 |
-
),
|
214 |
-
1
|
215 |
-
),
|
216 |
-
new Twig_Node_Expression_Constant(' baz', 1),
|
217 |
-
1
|
218 |
-
),
|
219 |
-
),
|
220 |
-
);
|
221 |
-
}
|
222 |
-
|
223 |
-
/**
|
224 |
-
* @expectedException Twig_Error_Syntax
|
225 |
-
*/
|
226 |
-
public function testAttributeCallDoesNotSupportNamedArguments()
|
227 |
-
{
|
228 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
229 |
-
$parser = new Twig_Parser($env);
|
230 |
-
|
231 |
-
$parser->parse($env->tokenize(new Twig_Source('{{ foo.bar(name="Foo") }}', 'index')));
|
232 |
-
}
|
233 |
-
|
234 |
-
/**
|
235 |
-
* @expectedException Twig_Error_Syntax
|
236 |
-
*/
|
237 |
-
public function testMacroCallDoesNotSupportNamedArguments()
|
238 |
-
{
|
239 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
240 |
-
$parser = new Twig_Parser($env);
|
241 |
-
|
242 |
-
$parser->parse($env->tokenize(new Twig_Source('{% from _self import foo %}{% macro foo() %}{% endmacro %}{{ foo(name="Foo") }}', 'index')));
|
243 |
-
}
|
244 |
-
|
245 |
-
/**
|
246 |
-
* @expectedException Twig_Error_Syntax
|
247 |
-
* @expectedExceptionMessage An argument must be a name. Unexpected token "string" of value "a" ("name" expected) in "index" at line 1.
|
248 |
-
*/
|
249 |
-
public function testMacroDefinitionDoesNotSupportNonNameVariableName()
|
250 |
-
{
|
251 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
252 |
-
$parser = new Twig_Parser($env);
|
253 |
-
|
254 |
-
$parser->parse($env->tokenize(new Twig_Source('{% macro foo("a") %}{% endmacro %}', 'index')));
|
255 |
-
}
|
256 |
-
|
257 |
-
/**
|
258 |
-
* @expectedException Twig_Error_Syntax
|
259 |
-
* @expectedExceptionMessage A default value for an argument must be a constant (a boolean, a string, a number, or an array) in "index" at line 1
|
260 |
-
* @dataProvider getMacroDefinitionDoesNotSupportNonConstantDefaultValues
|
261 |
-
*/
|
262 |
-
public function testMacroDefinitionDoesNotSupportNonConstantDefaultValues($template)
|
263 |
-
{
|
264 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
265 |
-
$parser = new Twig_Parser($env);
|
266 |
-
|
267 |
-
$parser->parse($env->tokenize(new Twig_Source($template, 'index')));
|
268 |
-
}
|
269 |
-
|
270 |
-
public function getMacroDefinitionDoesNotSupportNonConstantDefaultValues()
|
271 |
-
{
|
272 |
-
return array(
|
273 |
-
array('{% macro foo(name = "a #{foo} a") %}{% endmacro %}'),
|
274 |
-
array('{% macro foo(name = [["b", "a #{foo} a"]]) %}{% endmacro %}'),
|
275 |
-
);
|
276 |
-
}
|
277 |
-
|
278 |
-
/**
|
279 |
-
* @dataProvider getMacroDefinitionSupportsConstantDefaultValues
|
280 |
-
*/
|
281 |
-
public function testMacroDefinitionSupportsConstantDefaultValues($template)
|
282 |
-
{
|
283 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
284 |
-
$parser = new Twig_Parser($env);
|
285 |
-
|
286 |
-
$parser->parse($env->tokenize(new Twig_Source($template, 'index')));
|
287 |
-
}
|
288 |
-
|
289 |
-
public function getMacroDefinitionSupportsConstantDefaultValues()
|
290 |
-
{
|
291 |
-
return array(
|
292 |
-
array('{% macro foo(name = "aa") %}{% endmacro %}'),
|
293 |
-
array('{% macro foo(name = 12) %}{% endmacro %}'),
|
294 |
-
array('{% macro foo(name = true) %}{% endmacro %}'),
|
295 |
-
array('{% macro foo(name = ["a"]) %}{% endmacro %}'),
|
296 |
-
array('{% macro foo(name = [["a"]]) %}{% endmacro %}'),
|
297 |
-
array('{% macro foo(name = {a: "a"}) %}{% endmacro %}'),
|
298 |
-
array('{% macro foo(name = {a: {b: "a"}}) %}{% endmacro %}'),
|
299 |
-
);
|
300 |
-
}
|
301 |
-
|
302 |
-
/**
|
303 |
-
* @expectedException Twig_Error_Syntax
|
304 |
-
* @expectedExceptionMessage Unknown "cycl" function. Did you mean "cycle" in "index" at line 1?
|
305 |
-
*/
|
306 |
-
public function testUnknownFunction()
|
307 |
-
{
|
308 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
309 |
-
$parser = new Twig_Parser($env);
|
310 |
-
|
311 |
-
$parser->parse($env->tokenize(new Twig_Source('{{ cycl() }}', 'index')));
|
312 |
-
}
|
313 |
-
|
314 |
-
/**
|
315 |
-
* @expectedException Twig_Error_Syntax
|
316 |
-
* @expectedExceptionMessage Unknown "foobar" function in "index" at line 1.
|
317 |
-
*/
|
318 |
-
public function testUnknownFunctionWithoutSuggestions()
|
319 |
-
{
|
320 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
321 |
-
$parser = new Twig_Parser($env);
|
322 |
-
|
323 |
-
$parser->parse($env->tokenize(new Twig_Source('{{ foobar() }}', 'index')));
|
324 |
-
}
|
325 |
-
|
326 |
-
/**
|
327 |
-
* @expectedException Twig_Error_Syntax
|
328 |
-
* @expectedExceptionMessage Unknown "lowe" filter. Did you mean "lower" in "index" at line 1?
|
329 |
-
*/
|
330 |
-
public function testUnknownFilter()
|
331 |
-
{
|
332 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
333 |
-
$parser = new Twig_Parser($env);
|
334 |
-
|
335 |
-
$parser->parse($env->tokenize(new Twig_Source('{{ 1|lowe }}', 'index')));
|
336 |
-
}
|
337 |
-
|
338 |
-
/**
|
339 |
-
* @expectedException Twig_Error_Syntax
|
340 |
-
* @expectedExceptionMessage Unknown "foobar" filter in "index" at line 1.
|
341 |
-
*/
|
342 |
-
public function testUnknownFilterWithoutSuggestions()
|
343 |
-
{
|
344 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
345 |
-
$parser = new Twig_Parser($env);
|
346 |
-
|
347 |
-
$parser->parse($env->tokenize(new Twig_Source('{{ 1|foobar }}', 'index')));
|
348 |
-
}
|
349 |
-
|
350 |
-
/**
|
351 |
-
* @expectedException Twig_Error_Syntax
|
352 |
-
* @expectedExceptionMessage Unknown "nul" test. Did you mean "null" in "index" at line 1
|
353 |
-
*/
|
354 |
-
public function testUnknownTest()
|
355 |
-
{
|
356 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
357 |
-
$parser = new Twig_Parser($env);
|
358 |
-
$stream = $env->tokenize(new Twig_Source('{{ 1 is nul }}', 'index'));
|
359 |
-
$parser->parse($stream);
|
360 |
-
}
|
361 |
-
|
362 |
-
/**
|
363 |
-
* @expectedException Twig_Error_Syntax
|
364 |
-
* @expectedExceptionMessage Unknown "foobar" test in "index" at line 1.
|
365 |
-
*/
|
366 |
-
public function testUnknownTestWithoutSuggestions()
|
367 |
-
{
|
368 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
369 |
-
$parser = new Twig_Parser($env);
|
370 |
-
|
371 |
-
$parser->parse($env->tokenize(new Twig_Source('{{ 1 is foobar }}', 'index')));
|
372 |
-
}
|
373 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/twig/twig/test/Twig/Tests/Extension/CoreTest.php
DELETED
@@ -1,158 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* This file is part of Twig.
|
5 |
-
*
|
6 |
-
* (c) Fabien Potencier
|
7 |
-
*
|
8 |
-
* For the full copyright and license information, please view the LICENSE
|
9 |
-
* file that was distributed with this source code.
|
10 |
-
*/
|
11 |
-
|
12 |
-
class Twig_Tests_Extension_CoreTest extends PHPUnit_Framework_TestCase
|
13 |
-
{
|
14 |
-
/**
|
15 |
-
* @dataProvider getRandomFunctionTestData
|
16 |
-
*/
|
17 |
-
public function testRandomFunction($value, $expectedInArray)
|
18 |
-
{
|
19 |
-
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
20 |
-
|
21 |
-
for ($i = 0; $i < 100; ++$i) {
|
22 |
-
$this->assertTrue(in_array(twig_random($env, $value), $expectedInArray, true)); // assertContains() would not consider the type
|
23 |
-
}
|
24 |
-
}
|
25 |
-
|
26 |
-
public function getRandomFunctionTestData()
|
27 |
-
{
|
28 |
-
return array(
|
29 |
-
array(// array
|
30 |
-
array('apple', 'orange', 'citrus'),
|
31 |
-
array('apple', 'orange', 'citrus'),
|
32 |
-
),
|
33 |
-
array(// Traversable
|
34 |
-
new ArrayObject(array('apple', 'orange', 'citrus')),
|
35 |
-
array('apple', 'orange', 'citrus'),
|
36 |
-
),
|
37 |
-
array(// unicode string
|
38 |
-
'Ä€é',
|
39 |
-
array('Ä', '€', 'é'),
|
40 |
-
),
|
41 |
-
array(// numeric but string
|
42 |
-
'123',
|
43 |
-
array('1', '2', '3'),
|
44 |
-
),
|
45 |
-
array(// integer
|
46 |
-
5,
|
47 |
-
range(0, 5, 1),
|
48 |
-
),
|
49 |
-
array(// float
|
50 |
-
5.9,
|
51 |
-
range(0, 5, 1),
|
52 |
-
),
|
53 |
-
array(// negative
|
54 |
-
-2,
|
55 |
-
array(0, -1, -2),
|
56 |
-
),
|
57 |
-
);
|
58 |
-
}
|
59 |
-
|
60 |
-
public function testRandomFunctionWithoutParameter()
|
61 |
-
{
|
62 |
-
$max = mt_getrandmax();
|
63 |
-
|
64 |
-
for ($i = 0; $i < 100; ++$i) {
|
65 |
-
$val = twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
|
66 |
-
$this->assertTrue(is_int($val) && $val >= 0 && $val <= $max);
|
67 |
-
}
|
68 |
-
}
|
69 |
-
|
70 |
-
public function testRandomFunctionReturnsAsIs()
|
71 |
-
{
|
72 |
-
$this->assertSame('', twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), ''));
|
73 |
-
$this->assertSame('', twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('charset' => null)), ''));
|
74 |
-
|
75 |
-
$instance = new stdClass();
|
76 |
-
$this->assertSame($instance, twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), $instance));
|
77 |
-
}
|
78 |
-
|
79 |
-
/**
|
80 |
-
* @expectedException Twig_Error_Runtime
|
81 |
-
*/
|
82 |
-
public function testRandomFunctionOfEmptyArrayThrowsException()
|
83 |
-
{
|
84 |
-
twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), array());
|
85 |
-
}
|
86 |
-
|
87 |
-
public function testRandomFunctionOnNonUTF8String()
|
88 |
-
{
|
89 |
-
if (!function_exists('iconv') && !function_exists('mb_convert_encoding')) {
|
90 |
-
$this->markTestSkipped('needs iconv or mbstring');
|
91 |
-
}
|
92 |
-
|
93 |
-
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
94 |
-
$twig->setCharset('ISO-8859-1');
|
95 |
-
|
96 |
-
$text = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8');
|
97 |
-
for ($i = 0; $i < 30; ++$i) {
|
98 |
-
$rand = twig_random($twig, $text);
|
99 |
-
$this->assertTrue(in_array(twig_convert_encoding($rand, 'UTF-8', 'ISO-8859-1'), array('Ä', 'é'), true));
|
100 |
-
}
|
101 |
-
}
|
102 |
-
|
103 |
-
public function testReverseFilterOnNonUTF8String()
|
104 |
-
{
|
105 |
-
if (!function_exists('iconv') && !function_exists('mb_convert_encoding')) {
|
106 |
-
$this->markTestSkipped('needs iconv or mbstring');
|
107 |
-
}
|
108 |
-
|
109 |
-
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
110 |
-
$twig->setCharset('ISO-8859-1');
|
111 |
-
|
112 |
-
$input = t
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|