Version Description
- fix incorrect storage when creating a connection from the other end
- respect 'reciprocal' => false when 'from' =
Download this release
Release Info
Developer | scribu |
Plugin | Posts 2 Posts |
Version | 0.9.2 |
Comparing to | |
See all releases |
Code changes from version 0.8 to 0.9.2
- .svnignore +0 -2
- admin/base.php +96 -0
- {ui → admin}/box.css +44 -10
- admin/box.js +232 -0
- admin/box.php +316 -0
- admin/fields.php +131 -0
- {ui → admin}/images/add.png +0 -0
- {ui → admin}/images/delete.png +0 -0
- admin/images/sort.png +0 -0
- {ui → admin}/templates/box.html +0 -0
- admin/templates/column-create.html +1 -0
- admin/templates/column-delete-all.html +1 -0
- admin/templates/column-delete.html +1 -0
- {ui → admin}/templates/column-title.html +0 -0
- {ui → admin}/templates/tab-create-post.html +0 -0
- ui/templates/tab-recent.html → admin/templates/tab-list.html +6 -2
- {ui → admin}/templates/tab-search.html +0 -0
- ui/templates/box-row.html → admin/templates/table-row.html +0 -0
- api.php +0 -331
- core/api.php +144 -0
- core/query.php +128 -0
- storage.php → core/storage.php +19 -14
- core/type.php +289 -0
- core/widget.php +94 -0
- lang/posts-to-posts-fa_IR.mo +0 -0
- lang/posts-to-posts-fa_IR.po +142 -0
- lang/posts-to-posts-hr.mo +0 -0
- lang/posts-to-posts-hr.po +73 -0
- lang/posts-to-posts-pt_BR.mo +0 -0
- lang/posts-to-posts-pt_BR.po +74 -0
- lang/posts-to-posts-ro_RO.mo +0 -0
- lang/posts-to-posts-ro_RO.po +53 -31
- lang/posts-to-posts-ru_RU.mo +0 -0
- lang/posts-to-posts-ru_RU.po +88 -0
- lang/posts-to-posts.pot +38 -22
- mustache/examples/child_context/ChildContext.php +0 -13
- mustache/examples/child_context/child_context.mustache +0 -2
- mustache/examples/child_context/child_context.txt +0 -2
- mustache/examples/comments/Comments.php +0 -7
- mustache/examples/comments/comments.mustache +0 -1
- mustache/examples/comments/comments.txt +0 -1
- mustache/examples/complex/complex.mustache +0 -16
- mustache/examples/complex/complex.php +0 -19
- mustache/examples/complex/complex.txt +0 -6
- mustache/examples/delimiters/Delimiters.php +0 -14
- mustache/examples/delimiters/delimiters.mustache +0 -8
- mustache/examples/delimiters/delimiters.txt +0 -4
- mustache/examples/dot_notation/DotNotation.php +0 -19
- mustache/examples/dot_notation/dot_notation.mustache +0 -4
- mustache/examples/dot_notation/dot_notation.txt +0 -4
- mustache/examples/double_section/DoubleSection.php +0 -9
- mustache/examples/double_section/double_section.mustache +0 -7
- mustache/examples/double_section/double_section.txt +0 -3
- mustache/examples/escaped/Escaped.php +0 -5
- mustache/examples/escaped/escaped.mustache +0 -1
- mustache/examples/escaped/escaped.txt +0 -1
- mustache/examples/grand_parent_context/GrandParentContext.php +0 -24
- mustache/examples/grand_parent_context/grand_parent_context.mustache +0 -7
- mustache/examples/grand_parent_context/grand_parent_context.txt +0 -7
- mustache/examples/implicit_iterator/ImplicitIterator.php +0 -5
- mustache/examples/implicit_iterator/implicit_iterator.mustache +0 -3
- mustache/examples/implicit_iterator/implicit_iterator.txt +0 -5
- mustache/examples/inverted_double_section/InvertedDoubleSection.php +0 -6
- mustache/examples/inverted_double_section/inverted_double_section.mustache +0 -7
- mustache/examples/inverted_double_section/inverted_double_section.txt +0 -3
- mustache/examples/inverted_section/InvertedSection.php +0 -5
- mustache/examples/inverted_section/inverted_section.mustache +0 -2
- mustache/examples/inverted_section/inverted_section.txt +0 -1
- mustache/examples/partials/Partials.php +0 -13
- mustache/examples/partials/partials.mustache +0 -2
- mustache/examples/partials/partials.txt +0 -3
- mustache/examples/partials_with_view_class/PartialsWithViewClass.php +0 -19
- mustache/examples/partials_with_view_class/partials_with_view_class.mustache +0 -2
- mustache/examples/partials_with_view_class/partials_with_view_class.txt +0 -3
- mustache/examples/pragma_unescaped/PragmaUnescaped.php +0 -5
- mustache/examples/pragma_unescaped/pragma_unescaped.mustache +0 -3
- mustache/examples/pragma_unescaped/pragma_unescaped.txt +0 -2
- mustache/examples/pragmas_in_partials/PragmasInPartials.php +0 -8
- mustache/examples/pragmas_in_partials/pragmas_in_partials.mustache +0 -3
- mustache/examples/pragmas_in_partials/pragmas_in_partials.txt +0 -2
- mustache/examples/recursive_partials/RecursivePartials.php +0 -16
- mustache/examples/recursive_partials/recursive_partials.mustache +0 -1
- mustache/examples/recursive_partials/recursive_partials.txt +0 -1
- mustache/examples/section_iterator_objects/SectionIteratorObjects.php +0 -16
- mustache/examples/section_iterator_objects/section_iterator_objects.mustache +0 -5
- mustache/examples/section_iterator_objects/section_iterator_objects.txt +0 -4
- mustache/examples/section_magic_objects/SectionMagicObjects.php +0 -26
- mustache/examples/section_magic_objects/section_magic_objects.mustache +0 -6
- mustache/examples/section_magic_objects/section_magic_objects.txt +0 -4
- mustache/examples/section_objects/SectionObjects.php +0 -16
- mustache/examples/section_objects/section_objects.mustache +0 -6
- mustache/examples/section_objects/section_objects.txt +0 -4
- mustache/examples/sections/Sections.php +0 -14
- mustache/examples/sections/sections.mustache +0 -5
- mustache/examples/sections/sections.txt +0 -4
- mustache/examples/sections_nested/SectionsNested.php +0 -33
- mustache/examples/sections_nested/sections_nested.mustache +0 -7
- mustache/examples/sections_nested/sections_nested.txt +0 -12
- mustache/examples/simple/Simple.php +0 -12
- mustache/examples/simple/simple.mustache +0 -5
- mustache/examples/simple/simple.txt +0 -3
- mustache/examples/unescaped/Unescaped.php +0 -5
- mustache/examples/unescaped/unescaped.mustache +0 -1
- mustache/examples/unescaped/unescaped.txt +0 -1
- mustache/examples/utf8/UTF8.php +0 -5
- mustache/examples/utf8/utf8.mustache +0 -1
- mustache/examples/utf8/utf8.txt +0 -1
- mustache/examples/utf8_unescaped/UTF8Unescaped.php +0 -5
- mustache/examples/utf8_unescaped/utf8_unescaped.mustache +0 -1
- mustache/examples/utf8_unescaped/utf8_unescaped.txt +0 -1
- mustache/examples/whitespace/Whitespace.php +0 -37
- mustache/examples/whitespace/whitespace.mustache +0 -10
- mustache/examples/whitespace/whitespace.txt +0 -12
- mustache/test/MustacheExceptionTest.php +0 -120
- mustache/test/MustacheObjectSectionTest.php +0 -73
- mustache/test/MustachePragmaTest.php +0 -50
- mustache/test/MustachePragmaUnescapedTest.php +0 -19
- mustache/test/MustacheSpecTest.php +0 -145
- mustache/test/MustacheTest.php +0 -464
- mustache/test/lib/yaml/LICENSE +0 -19
- mustache/test/lib/yaml/README.markdown +0 -15
- mustache/test/lib/yaml/doc/00-Introduction.markdown +0 -143
- mustache/test/lib/yaml/doc/01-Usage.markdown +0 -110
- mustache/test/lib/yaml/doc/02-YAML.markdown +0 -312
- mustache/test/lib/yaml/doc/A-License.markdown +0 -108
- mustache/test/lib/yaml/lib/sfYaml.php +0 -135
- mustache/test/lib/yaml/lib/sfYamlDumper.php +0 -60
- mustache/test/lib/yaml/lib/sfYamlInline.php +0 -442
- mustache/test/lib/yaml/lib/sfYamlParser.php +0 -622
- mustache/test/lib/yaml/package.xml +0 -102
- mustache/test/phpunit.xml +0 -10
- posts-to-posts.php +17 -40
- readme.txt +27 -5
- scb/AdminPage.php +27 -46
- scb/BoxesPage.php +1 -1
- scb/Forms.php +70 -25
- scb/Hooks.php +32 -9
- scb/Util.php +23 -13
- scb/Widget.php +11 -25
- scb/load.php +1 -1
- screenshot-2.png +0 -0
- test/debug.php +160 -0
- test/unit.php +124 -0
- tests.php +0 -275
- ui.php +0 -145
- ui/box.js +0 -280
- ui/box.php +0 -355
- ui/templates/column-create.html +0 -1
- ui/templates/column-delete-all.html +0 -1
- ui/templates/column-delete.html +0 -1
.svnignore
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
mustache/examples
|
2 |
-
mustache/test
|
|
|
|
admin/base.php
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
define( 'P2P_BOX_NONCE', 'p2p-box' );
|
4 |
+
|
5 |
+
class P2P_Box_Factory {
|
6 |
+
|
7 |
+
function init() {
|
8 |
+
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
|
9 |
+
add_action( 'save_post', array( __CLASS__, 'save_post' ), 10, 2 );
|
10 |
+
add_action( 'wp_ajax_p2p_box', array( __CLASS__, 'wp_ajax_p2p_box' ) );
|
11 |
+
}
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Add all the metaboxes.
|
15 |
+
*/
|
16 |
+
static function add_meta_boxes( $from ) {
|
17 |
+
foreach ( P2P_Connection_Type::$instances as $box_id => $args ) {
|
18 |
+
$box = self::make_box( $box_id, $from );
|
19 |
+
if ( !$box )
|
20 |
+
continue;
|
21 |
+
|
22 |
+
$box->register();
|
23 |
+
}
|
24 |
+
}
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Collect metadata from all boxes.
|
28 |
+
*/
|
29 |
+
function save_post( $post_id, $post ) {
|
30 |
+
if ( 'revision' == $post->post_type || defined( 'DOING_AJAX' ) )
|
31 |
+
return;
|
32 |
+
|
33 |
+
// Custom fields
|
34 |
+
if ( isset( $_POST['p2p_meta'] ) ) {
|
35 |
+
foreach ( $_POST['p2p_meta'] as $p2p_id => $data ) {
|
36 |
+
foreach ( $data as $key => $value ) {
|
37 |
+
p2p_update_meta( $p2p_id, $key, $value );
|
38 |
+
}
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
// Ordering
|
43 |
+
if ( isset( $_POST['p2p_order'] ) ) {
|
44 |
+
foreach ( $_POST['p2p_order'] as $key => $list ) {
|
45 |
+
foreach ( $list as $i => $p2p_id ) {
|
46 |
+
p2p_update_meta( $p2p_id, $key, $i );
|
47 |
+
}
|
48 |
+
}
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Controller for all box ajax requests.
|
54 |
+
*/
|
55 |
+
function wp_ajax_p2p_box() {
|
56 |
+
check_ajax_referer( P2P_BOX_NONCE, 'nonce' );
|
57 |
+
|
58 |
+
$box = self::make_box( $_REQUEST['box_id'], $_REQUEST['post_type'] );
|
59 |
+
if ( !$box )
|
60 |
+
die(0);
|
61 |
+
|
62 |
+
if ( !current_user_can( $box->ptype->cap->edit_posts ) )
|
63 |
+
die(-1);
|
64 |
+
|
65 |
+
$method = 'ajax_' . $_REQUEST['subaction'];
|
66 |
+
|
67 |
+
$box->$method();
|
68 |
+
}
|
69 |
+
|
70 |
+
private static function make_box( $box_id, $post_type ) {
|
71 |
+
if ( !isset( P2P_Connection_Type::$instances[ $box_id ] ) )
|
72 |
+
return false;
|
73 |
+
|
74 |
+
$ctype = P2P_Connection_Type::$instances[ $box_id ];
|
75 |
+
|
76 |
+
if ( !$ctype->show_ui )
|
77 |
+
return false;
|
78 |
+
|
79 |
+
$direction = $ctype->get_direction( $post_type );
|
80 |
+
|
81 |
+
if ( !$ctype->reciprocal ) {
|
82 |
+
if ( 'any' == $direction )
|
83 |
+
$direction = 'from';
|
84 |
+
elseif ( 'to' == $direction )
|
85 |
+
$direction = false;
|
86 |
+
}
|
87 |
+
|
88 |
+
if ( !$direction )
|
89 |
+
return false;
|
90 |
+
|
91 |
+
return new P2P_Box( $box_id, $ctype, $post_type, $direction );
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
P2P_Box_Factory::init();
|
96 |
+
|
{ui → admin}/box.css
RENAMED
@@ -33,6 +33,7 @@
|
|
33 |
border-spacing: 0;
|
34 |
border-style: solid;
|
35 |
border-width: 1px;
|
|
|
36 |
}
|
37 |
|
38 |
.p2p-search + .p2p-results,
|
@@ -64,6 +65,7 @@ td.p2p-col-create {
|
|
64 |
.p2p-col-delete img,
|
65 |
.p2p-col-create img {
|
66 |
padding: 5px 6px;
|
|
|
67 |
}
|
68 |
|
69 |
th.p2p-col-delete a {
|
@@ -74,10 +76,6 @@ th.p2p-col-delete a {
|
|
74 |
border-top: 0;
|
75 |
}
|
76 |
|
77 |
-
.p2p-connections {
|
78 |
-
width: 100%;
|
79 |
-
}
|
80 |
-
|
81 |
.p2p-connections th {
|
82 |
background-color: #F1F1F1;
|
83 |
text-align: left;
|
@@ -98,7 +96,6 @@ th.p2p-col-delete a {
|
|
98 |
height: 16px;
|
99 |
margin-top: 1px;
|
100 |
opacity: 0.5;
|
101 |
-
text-indent: -9999px;
|
102 |
width: 16px;
|
103 |
}
|
104 |
|
@@ -118,14 +115,18 @@ th.p2p-col-delete a {
|
|
118 |
background: url("images/delete.png") no-repeat scroll 50% 50% transparent;
|
119 |
}
|
120 |
|
121 |
-
.p2p-
|
|
|
|
|
|
|
|
|
|
|
122 |
margin-left: -20px;
|
123 |
opacity: 0.8;
|
124 |
vertical-align: -0.3em;
|
125 |
}
|
126 |
|
127 |
-
.p2p-tab-search input
|
128 |
-
.p2p-tab-create-post {
|
129 |
background-color: transparent;
|
130 |
padding-right: 22px;
|
131 |
margin: 0;
|
@@ -144,10 +145,12 @@ th.p2p-col-delete a {
|
|
144 |
|
145 |
.p2p-navigation {
|
146 |
clear: both;
|
|
|
147 |
overflow: hidden;
|
148 |
}
|
149 |
|
150 |
-
.p2p-navigation .button.inactive,
|
|
|
151 |
border-color: #bbb;
|
152 |
color: #aaa;
|
153 |
background: #f6f6f6;
|
@@ -155,7 +158,7 @@ th.p2p-col-delete a {
|
|
155 |
cursor: default;
|
156 |
}
|
157 |
|
158 |
-
.p2p-navigation
|
159 |
float: left;
|
160 |
line-height: 13px;
|
161 |
padding-top: 3px;
|
@@ -163,3 +166,34 @@ th.p2p-col-delete a {
|
|
163 |
margin-right: 5px;
|
164 |
}
|
165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
border-spacing: 0;
|
34 |
border-style: solid;
|
35 |
border-width: 1px;
|
36 |
+
width: 100%;
|
37 |
}
|
38 |
|
39 |
.p2p-search + .p2p-results,
|
65 |
.p2p-col-delete img,
|
66 |
.p2p-col-create img {
|
67 |
padding: 5px 6px;
|
68 |
+
vertical-align: middle;
|
69 |
}
|
70 |
|
71 |
th.p2p-col-delete a {
|
76 |
border-top: 0;
|
77 |
}
|
78 |
|
|
|
|
|
|
|
|
|
79 |
.p2p-connections th {
|
80 |
background-color: #F1F1F1;
|
81 |
text-align: left;
|
96 |
height: 16px;
|
97 |
margin-top: 1px;
|
98 |
opacity: 0.5;
|
|
|
99 |
width: 16px;
|
100 |
}
|
101 |
|
115 |
background: url("images/delete.png") no-repeat scroll 50% 50% transparent;
|
116 |
}
|
117 |
|
118 |
+
tr:hover td.p2p-col-order {
|
119 |
+
cursor: move;
|
120 |
+
background: url("images/sort.png") no-repeat scroll 50% 50% transparent;
|
121 |
+
}
|
122 |
+
|
123 |
+
.p2p-search .p2p-spinner {
|
124 |
margin-left: -20px;
|
125 |
opacity: 0.8;
|
126 |
vertical-align: -0.3em;
|
127 |
}
|
128 |
|
129 |
+
.p2p-tab-search input {
|
|
|
130 |
background-color: transparent;
|
131 |
padding-right: 22px;
|
132 |
margin: 0;
|
145 |
|
146 |
.p2p-navigation {
|
147 |
clear: both;
|
148 |
+
display: table;
|
149 |
overflow: hidden;
|
150 |
}
|
151 |
|
152 |
+
.p2p-navigation .button.inactive,
|
153 |
+
.p2p-navigation .button.inactive:hover {
|
154 |
border-color: #bbb;
|
155 |
color: #aaa;
|
156 |
background: #f6f6f6;
|
158 |
cursor: default;
|
159 |
}
|
160 |
|
161 |
+
.p2p-navigation div {
|
162 |
float: left;
|
163 |
line-height: 13px;
|
164 |
padding-top: 3px;
|
166 |
margin-right: 5px;
|
167 |
}
|
168 |
|
169 |
+
.p2p-navigation .p2p-spinner {
|
170 |
+
margin-top: 3px;
|
171 |
+
}
|
172 |
+
|
173 |
+
/* RTL support */
|
174 |
+
|
175 |
+
body.rtl .p2p-navigation div {
|
176 |
+
float: right;
|
177 |
+
}
|
178 |
+
|
179 |
+
body.rtl .p2p-search .p2p-spinner {
|
180 |
+
margin-left: 0;
|
181 |
+
margin-right: -20px;
|
182 |
+
}
|
183 |
+
|
184 |
+
body.rtl .p2p-tab-search input {
|
185 |
+
padding-left: 22px;
|
186 |
+
padding-right: 0;
|
187 |
+
}
|
188 |
+
|
189 |
+
body.rtl .p2p-col-create a:hover,
|
190 |
+
body.rtl .p2p-col-delete a:hover {
|
191 |
+
border-left: 1px solid #ddd;
|
192 |
+
border-right: 0;
|
193 |
+
}
|
194 |
+
|
195 |
+
body.rtl .p2p-navigation div {
|
196 |
+
margin-right: 0;
|
197 |
+
margin-left: 5px;
|
198 |
+
}
|
199 |
+
|
admin/box.js
ADDED
@@ -0,0 +1,232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function(){
|
2 |
+
jQuery(function(){
|
3 |
+
var setVal, clearVal;
|
4 |
+
if (!jQuery('<input placeholder="1" />')[0].placeholder) {
|
5 |
+
setVal = function(){
|
6 |
+
var $this;
|
7 |
+
$this = jQuery(this);
|
8 |
+
if (!$this.val()) {
|
9 |
+
$this.val($this.attr('placeholder'));
|
10 |
+
$this.addClass('p2p-placeholder');
|
11 |
+
}
|
12 |
+
};
|
13 |
+
clearVal = function(){
|
14 |
+
var $this;
|
15 |
+
$this = jQuery(this);
|
16 |
+
if ($this.hasClass('p2p-placeholder')) {
|
17 |
+
$this.val('');
|
18 |
+
$this.removeClass('p2p-placeholder');
|
19 |
+
}
|
20 |
+
};
|
21 |
+
jQuery('.p2p-search input[placeholder]').each(setVal).focus(clearVal).blur(setVal);
|
22 |
+
}
|
23 |
+
return jQuery('.p2p-box').each(function(){
|
24 |
+
var $metabox, $connections, $spinner, ajax_request, row_ajax_request, clear_connections, delete_connection, create_connection, switch_to_tab, PostsTab, searchTab, listTab, $searchInput, $createButton, $createInput;
|
25 |
+
$metabox = jQuery(this);
|
26 |
+
$connections = $metabox.find('.p2p-connections');
|
27 |
+
$spinner = jQuery('<img>', {
|
28 |
+
'src': P2PAdmin.spinner,
|
29 |
+
'class': 'p2p-spinner'
|
30 |
+
});
|
31 |
+
ajax_request = function(data, callback, method){
|
32 |
+
method == null && (method = 'post');
|
33 |
+
data.action = 'p2p_box';
|
34 |
+
data.nonce = P2PAdmin.nonce;
|
35 |
+
data.box_id = $metabox.data('box_id');
|
36 |
+
data.post_type = jQuery('#post_type').val();
|
37 |
+
return jQuery[method](ajaxurl, data, callback);
|
38 |
+
};
|
39 |
+
row_ajax_request = function($td, data, callback){
|
40 |
+
$td.html($spinner.show());
|
41 |
+
return ajax_request(data, callback);
|
42 |
+
};
|
43 |
+
clear_connections = function(ev){
|
44 |
+
var $self, $td, data, _this = this;
|
45 |
+
if (!confirm(P2PAdmin.deleteConfirmMessage)) {
|
46 |
+
return false;
|
47 |
+
}
|
48 |
+
$self = jQuery(ev.target);
|
49 |
+
$td = $self.closest('td');
|
50 |
+
data = {
|
51 |
+
subaction: 'clear_connections',
|
52 |
+
post_id: jQuery('#post_ID').val()
|
53 |
+
};
|
54 |
+
row_ajax_request($td, data, function(response){
|
55 |
+
$connections.hide().find('tbody').html('');
|
56 |
+
return $td.html($self);
|
57 |
+
});
|
58 |
+
return false;
|
59 |
+
};
|
60 |
+
delete_connection = function(ev){
|
61 |
+
var $self, $td, data, _this = this;
|
62 |
+
$self = jQuery(ev.target);
|
63 |
+
$td = $self.closest('td');
|
64 |
+
data = {
|
65 |
+
subaction: 'disconnect',
|
66 |
+
p2p_id: $self.data('p2p_id')
|
67 |
+
};
|
68 |
+
row_ajax_request($td, data, function(response){
|
69 |
+
$td.closest('tr').remove();
|
70 |
+
if (!$connections.find('tbody tr').length) {
|
71 |
+
return $connections.hide();
|
72 |
+
}
|
73 |
+
});
|
74 |
+
return false;
|
75 |
+
};
|
76 |
+
create_connection = function(ev){
|
77 |
+
var $self, $td, data, _this = this;
|
78 |
+
$self = jQuery(ev.target);
|
79 |
+
$td = $self.closest('td');
|
80 |
+
data = {
|
81 |
+
subaction: 'connect',
|
82 |
+
from: jQuery('#post_ID').val(),
|
83 |
+
to: $self.data('post_id')
|
84 |
+
};
|
85 |
+
row_ajax_request($td, data, function(response){
|
86 |
+
var $table;
|
87 |
+
$connections.show().find('tbody').append(response);
|
88 |
+
if ($metabox.data('prevent_duplicates')) {
|
89 |
+
$table = $td.closest('table');
|
90 |
+
if (1 == $table.find('tbody tr').length) {
|
91 |
+
return $table.remove();
|
92 |
+
} else {
|
93 |
+
return $td.closest('tr').remove();
|
94 |
+
}
|
95 |
+
} else {
|
96 |
+
return $td.html($self);
|
97 |
+
}
|
98 |
+
});
|
99 |
+
return false;
|
100 |
+
};
|
101 |
+
switch_to_tab = function(){
|
102 |
+
var $tab;
|
103 |
+
$tab = jQuery(this);
|
104 |
+
$metabox.find('.wp-tab-bar li').removeClass('wp-tab-active');
|
105 |
+
$tab.addClass('wp-tab-active');
|
106 |
+
$metabox.find('.tabs-panel').hide().end().find($tab.data('ref')).show().find(':text').focus();
|
107 |
+
return false;
|
108 |
+
};
|
109 |
+
$metabox.delegate('th.p2p-col-delete a', 'click', clear_connections).delegate('td.p2p-col-delete a', 'click', delete_connection).delegate('td.p2p-col-create a', 'click', create_connection).delegate('.wp-tab-bar li', 'click', switch_to_tab);
|
110 |
+
if ($connections.find('th.p2p-col-order').length) {
|
111 |
+
$connections.find('tbody').sortable({
|
112 |
+
handle: 'td.p2p-col-order',
|
113 |
+
helper: function(e, ui){
|
114 |
+
ui.children().each(function(){
|
115 |
+
var $this;
|
116 |
+
$this = jQuery(this);
|
117 |
+
return $this.width($this.width());
|
118 |
+
});
|
119 |
+
return ui;
|
120 |
+
}
|
121 |
+
});
|
122 |
+
}
|
123 |
+
PostsTab = (function(){
|
124 |
+
PostsTab.displayName = 'PostsTab';
|
125 |
+
var prototype = PostsTab.prototype, constructor = PostsTab;
|
126 |
+
function PostsTab(selector){
|
127 |
+
this.tab = $metabox.find(selector);
|
128 |
+
this.init_pagination_data();
|
129 |
+
this.tab.delegate('.p2p-prev, .p2p-next', 'click', __bind(this, this.change_page));
|
130 |
+
this.data = {
|
131 |
+
subaction: 'search',
|
132 |
+
post_id: jQuery('#post_ID').val(),
|
133 |
+
s: ''
|
134 |
+
};
|
135 |
+
}
|
136 |
+
prototype.init_pagination_data = function(){
|
137 |
+
this.current_page = this.tab.find('.p2p-current').data('num') || 1;
|
138 |
+
return this.total_pages = this.tab.find('.p2p-total').data('num') || 1;
|
139 |
+
};
|
140 |
+
prototype.change_page = function(ev){
|
141 |
+
var $navButton, new_page;
|
142 |
+
$navButton = jQuery(ev.target);
|
143 |
+
new_page = this.current_page;
|
144 |
+
if ($navButton.hasClass('inactive')) {
|
145 |
+
return false;
|
146 |
+
}
|
147 |
+
if ($navButton.hasClass('p2p-prev')) {
|
148 |
+
new_page--;
|
149 |
+
} else {
|
150 |
+
new_page++;
|
151 |
+
}
|
152 |
+
this.find_posts(new_page);
|
153 |
+
return false;
|
154 |
+
};
|
155 |
+
prototype.find_posts = function(new_page){
|
156 |
+
this.data.paged = new_page
|
157 |
+
? new_page > this.total_pages ? this.current_page : new_page
|
158 |
+
: this.current_page;
|
159 |
+
$spinner.appendTo(this.tab.find('.p2p-navigation'));
|
160 |
+
return ajax_request(this.data, __bind(this, this.update_rows), 'getJSON');
|
161 |
+
};
|
162 |
+
prototype.update_rows = function(response){
|
163 |
+
$spinner.remove();
|
164 |
+
this.tab.find('.p2p-results, .p2p-navigation, .p2p-notice').remove();
|
165 |
+
if (!response.rows) {
|
166 |
+
return this.tab.append(jQuery('<div class="p2p-notice">').html(response.msg));
|
167 |
+
} else {
|
168 |
+
this.tab.append(response.rows);
|
169 |
+
return this.init_pagination_data();
|
170 |
+
}
|
171 |
+
};
|
172 |
+
return PostsTab;
|
173 |
+
}());
|
174 |
+
searchTab = new PostsTab('.p2p-tab-search');
|
175 |
+
listTab = new PostsTab('.p2p-tab-list');
|
176 |
+
$searchInput = $metabox.find('.p2p-tab-search :text');
|
177 |
+
$searchInput.keypress(function(ev){
|
178 |
+
if (13 === ev.keyCode) {
|
179 |
+
return false;
|
180 |
+
}
|
181 |
+
}).keyup(function(ev){
|
182 |
+
var delayed;
|
183 |
+
if (undefined !== delayed) {
|
184 |
+
clearTimeout(delayed);
|
185 |
+
}
|
186 |
+
return delayed = setTimeout(function(){
|
187 |
+
var searchStr;
|
188 |
+
searchStr = $searchInput.val();
|
189 |
+
if ('' == searchStr || searchStr === searchTab.data.s) {
|
190 |
+
return;
|
191 |
+
}
|
192 |
+
searchTab.data.s = searchStr;
|
193 |
+
$spinner.insertAfter($searchInput).show();
|
194 |
+
return searchTab.find_posts(1);
|
195 |
+
}, 400);
|
196 |
+
});
|
197 |
+
$createButton = $metabox.find('.p2p-tab-create-post .button');
|
198 |
+
$createInput = $metabox.find('.p2p-tab-create-post :text');
|
199 |
+
$createButton.click(function(){
|
200 |
+
var $button, title, data;
|
201 |
+
$button = jQuery(this);
|
202 |
+
if ($button.hasClass('inactive')) {
|
203 |
+
return false;
|
204 |
+
}
|
205 |
+
title = $createInput.val();
|
206 |
+
if ('' === title) {
|
207 |
+
$createInput.focus();
|
208 |
+
return false;
|
209 |
+
}
|
210 |
+
$button.addClass('inactive');
|
211 |
+
data = {
|
212 |
+
subaction: 'create_post',
|
213 |
+
from: jQuery('#post_ID').val(),
|
214 |
+
post_title: title
|
215 |
+
};
|
216 |
+
ajax_request(data, function(response){
|
217 |
+
$connections.show().find('tbody').append(response);
|
218 |
+
$createInput.val('');
|
219 |
+
return $button.removeClass('inactive');
|
220 |
+
});
|
221 |
+
return false;
|
222 |
+
});
|
223 |
+
return $createInput.keypress(function(ev){
|
224 |
+
if (13 === ev.keyCode) {
|
225 |
+
$createButton.click();
|
226 |
+
return false;
|
227 |
+
}
|
228 |
+
});
|
229 |
+
});
|
230 |
+
});
|
231 |
+
function __bind(me, fn){ return function(){ return fn.apply(me, arguments) } }
|
232 |
+
}).call(this);
|
admin/box.php
ADDED
@@ -0,0 +1,316 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
interface P2P_Field {
|
4 |
+
function get_title();
|
5 |
+
function render( $key, $p2p_id, $post_id );
|
6 |
+
}
|
7 |
+
|
8 |
+
|
9 |
+
class P2P_Box {
|
10 |
+
private $box_id;
|
11 |
+
|
12 |
+
private $data;
|
13 |
+
|
14 |
+
private $current_ptype;
|
15 |
+
private $direction;
|
16 |
+
|
17 |
+
public $ptype;
|
18 |
+
|
19 |
+
private $columns;
|
20 |
+
|
21 |
+
private static $extra_qv = array(
|
22 |
+
'update_post_term_cache' => false,
|
23 |
+
'update_post_meta_cache' => false,
|
24 |
+
'post_status' => 'any',
|
25 |
+
);
|
26 |
+
|
27 |
+
function __construct( $box_id, $data, $current_ptype, $direction ) {
|
28 |
+
$this->box_id = $box_id;
|
29 |
+
$this->data = $data;
|
30 |
+
|
31 |
+
$this->direction = $direction;
|
32 |
+
|
33 |
+
$this->current_ptype = $current_ptype;
|
34 |
+
|
35 |
+
$other_ptype = $this->data->get_other_post_type( $direction );
|
36 |
+
$this->ptype = get_post_type_object( $other_ptype[0] );
|
37 |
+
|
38 |
+
if ( !class_exists( 'Mustache' ) )
|
39 |
+
require dirname(__FILE__) . '/../mustache/Mustache.php';
|
40 |
+
|
41 |
+
$this->columns = array(
|
42 |
+
'delete' => new P2P_Field_Delete,
|
43 |
+
'title' => new P2P_Field_Title( $this->ptype->labels->singular_name ),
|
44 |
+
);
|
45 |
+
|
46 |
+
foreach ( $this->data->fields as $key => $data ) {
|
47 |
+
$this->columns[ $key ] = new P2P_Field_Generic( $data );
|
48 |
+
}
|
49 |
+
|
50 |
+
if ( $this->data->sortable && 'from' == $direction ) {
|
51 |
+
$this->columns['order'] = new P2P_Field_Order( $this->data->sortable );
|
52 |
+
}
|
53 |
+
|
54 |
+
wp_enqueue_style( 'p2p-admin', plugins_url( 'box.css', __FILE__ ), array(), P2P_PLUGIN_VERSION );
|
55 |
+
wp_enqueue_script( 'p2p-admin', plugins_url( 'box.js', __FILE__ ), array( 'jquery' ), P2P_PLUGIN_VERSION, true );
|
56 |
+
wp_localize_script( 'p2p-admin', 'P2PAdmin', array(
|
57 |
+
'nonce' => wp_create_nonce( P2P_BOX_NONCE ),
|
58 |
+
'spinner' => admin_url( 'images/wpspin_light.gif' ),
|
59 |
+
'deleteConfirmMessage' => __( 'Are you sure you want to delete all connections?', P2P_TEXTDOMAIN ),
|
60 |
+
) );
|
61 |
+
|
62 |
+
add_filter( 'posts_search', array( __CLASS__, '_search_by_title' ), 10, 2 );
|
63 |
+
}
|
64 |
+
|
65 |
+
public function register() {
|
66 |
+
$title = $this->data->get_title( $this->direction );
|
67 |
+
|
68 |
+
if ( empty( $title ) ) {
|
69 |
+
$title = sprintf( __( 'Connected %s', P2P_TEXTDOMAIN ), $this->ptype->labels->name );
|
70 |
+
}
|
71 |
+
|
72 |
+
add_meta_box(
|
73 |
+
'p2p-connections-' . $this->box_id,
|
74 |
+
$title,
|
75 |
+
array( $this, 'render' ),
|
76 |
+
$this->current_ptype,
|
77 |
+
$this->data->context,
|
78 |
+
'default'
|
79 |
+
);
|
80 |
+
}
|
81 |
+
|
82 |
+
function render( $post ) {
|
83 |
+
$data = array();
|
84 |
+
|
85 |
+
$qv = self::$extra_qv;
|
86 |
+
$qv['nopaging'] = true;
|
87 |
+
|
88 |
+
$connected_posts = $this->data->get_connected( $post->ID, $qv, $this->direction )->posts;
|
89 |
+
|
90 |
+
if ( empty( $connected_posts ) )
|
91 |
+
$data['hide-connections'] = 'style="display:none"';
|
92 |
+
|
93 |
+
$tbody = '';
|
94 |
+
foreach ( $connected_posts as $connected ) {
|
95 |
+
$tbody .= $this->connection_row( $connected->p2p_id, $connected->ID );
|
96 |
+
}
|
97 |
+
$data['tbody'] = $tbody;
|
98 |
+
|
99 |
+
foreach ( $this->columns as $key => $field ) {
|
100 |
+
$data['thead'][] = array(
|
101 |
+
'column' => $key,
|
102 |
+
'title' => $field->get_title()
|
103 |
+
);
|
104 |
+
}
|
105 |
+
|
106 |
+
$data_attr = array(
|
107 |
+
'box_id' => $this->box_id,
|
108 |
+
'prevent_duplicates' => $this->data->prevent_duplicates,
|
109 |
+
);
|
110 |
+
|
111 |
+
$data_attr_str = array();
|
112 |
+
foreach ( $data_attr as $key => $value )
|
113 |
+
$data_attr_str[] = "data-$key='" . $value . "'";
|
114 |
+
$data['attributes'] = implode( ' ', $data_attr_str );
|
115 |
+
|
116 |
+
$data['create-label'] = __( 'Create connections:', P2P_TEXTDOMAIN );
|
117 |
+
|
118 |
+
// Search tab
|
119 |
+
$tab_content = _p2p_mustache_render( 'tab-search.html', array(
|
120 |
+
'placeholder' => $this->ptype->labels->search_items,
|
121 |
+
) );
|
122 |
+
|
123 |
+
$data['tabs'][] = array(
|
124 |
+
'tab-id' => 'search',
|
125 |
+
'tab-title' => __( 'Search', P2P_TEXTDOMAIN ),
|
126 |
+
'is-active' => array(true),
|
127 |
+
'tab-content' => $tab_content
|
128 |
+
);
|
129 |
+
|
130 |
+
// List tab
|
131 |
+
$data['tabs'][] = array(
|
132 |
+
'tab-id' => 'list',
|
133 |
+
'tab-title' => __( 'View All', P2P_TEXTDOMAIN ),
|
134 |
+
'tab-content' => $this->post_rows( $post->ID )
|
135 |
+
);
|
136 |
+
|
137 |
+
// Create post tab
|
138 |
+
if ( $this->data->can_create_post( $this->direction ) ) {
|
139 |
+
$tab_content = _p2p_mustache_render( 'tab-create-post.html', array(
|
140 |
+
'title' => $this->ptype->labels->add_new_item
|
141 |
+
) );
|
142 |
+
|
143 |
+
$data['tabs'][] = array(
|
144 |
+
'tab-id' => 'create-post',
|
145 |
+
'tab-title' => $this->ptype->labels->new_item,
|
146 |
+
'tab-content' => $tab_content
|
147 |
+
);
|
148 |
+
}
|
149 |
+
|
150 |
+
echo _p2p_mustache_render( 'box.html', $data );
|
151 |
+
}
|
152 |
+
|
153 |
+
protected function connection_row( $p2p_id, $post_id ) {
|
154 |
+
$data = array();
|
155 |
+
|
156 |
+
foreach ( $this->columns as $key => $field ) {
|
157 |
+
$data['columns'][] = array(
|
158 |
+
'column' => $key,
|
159 |
+
'content' => $field->render( $key, $p2p_id, $post_id )
|
160 |
+
);
|
161 |
+
}
|
162 |
+
|
163 |
+
return _p2p_mustache_render( 'table-row.html', $data );
|
164 |
+
}
|
165 |
+
|
166 |
+
protected function post_rows( $current_post_id, $page = 1, $search = '' ) {
|
167 |
+
$args = array_merge( self::$extra_qv, array(
|
168 |
+
'paged' => $page,
|
169 |
+
'posts_per_page' => 5,
|
170 |
+
) );
|
171 |
+
|
172 |
+
if ( $search ) {
|
173 |
+
$args['_p2p_box'] = true;
|
174 |
+
$args['s'] = $search;
|
175 |
+
}
|
176 |
+
|
177 |
+
$query = $this->data->get_connectable( $current_post_id, $args, $this->direction );
|
178 |
+
|
179 |
+
if ( empty( $query->posts ) )
|
180 |
+
return false;
|
181 |
+
|
182 |
+
$candidate = (object) array(
|
183 |
+
'posts' => $query->posts,
|
184 |
+
'current_page' => max( 1, $query->get('paged') ),
|
185 |
+
'total_pages' => $query->max_num_pages
|
186 |
+
);
|
187 |
+
|
188 |
+
$data = array();
|
189 |
+
|
190 |
+
$columns = array(
|
191 |
+
'create' => new P2P_Field_Create,
|
192 |
+
'title' => new P2P_Field_Title,
|
193 |
+
);
|
194 |
+
|
195 |
+
foreach ( $candidate->posts as $post ) {
|
196 |
+
$row = array();
|
197 |
+
|
198 |
+
foreach ( $columns as $key => $field ) {
|
199 |
+
$row['columns'][] = array(
|
200 |
+
'column' => $key,
|
201 |
+
'content' => $field->render( $key, 0, $post->ID )
|
202 |
+
);
|
203 |
+
}
|
204 |
+
|
205 |
+
$data['rows'][] = $row;
|
206 |
+
}
|
207 |
+
|
208 |
+
if ( $candidate->total_pages > 1 ) {
|
209 |
+
$data['navigation'] = array(
|
210 |
+
'current-page' => number_format_i18n( $candidate->current_page ),
|
211 |
+
'total-pages' => number_format_i18n( $candidate->total_pages ),
|
212 |
+
|
213 |
+
'current-page-raw' => $candidate->current_page,
|
214 |
+
'total-pages-raw' => $candidate->total_pages,
|
215 |
+
|
216 |
+
'prev-inactive' => ( 1 == $candidate->current_page ) ? 'inactive' : '',
|
217 |
+
'next-inactive' => ( $candidate->total_pages == $candidate->current_page ) ? 'inactive' : '',
|
218 |
+
|
219 |
+
'prev-label' => __( 'previous', P2P_TEXTDOMAIN ),
|
220 |
+
'next-label' => __( 'next', P2P_TEXTDOMAIN ),
|
221 |
+
'of-label' => __( 'of', P2P_TEXTDOMAIN ),
|
222 |
+
);
|
223 |
+
}
|
224 |
+
|
225 |
+
return _p2p_mustache_render( 'tab-list.html', $data, array( 'table-row' ) );
|
226 |
+
}
|
227 |
+
|
228 |
+
|
229 |
+
// Ajax handlers
|
230 |
+
|
231 |
+
public function ajax_create_post() {
|
232 |
+
$this->safe_connect( $this->create_post( $_POST['post_title'] ) );
|
233 |
+
}
|
234 |
+
|
235 |
+
private function create_post( $title ) {
|
236 |
+
$args = array(
|
237 |
+
'post_title' => $title,
|
238 |
+
'post_author' => get_current_user_id(),
|
239 |
+
'post_type' => $this->ptype->name
|
240 |
+
);
|
241 |
+
|
242 |
+
$args = apply_filters( 'p2p_new_post_args', $args, $this->data );
|
243 |
+
|
244 |
+
return wp_insert_post( $args );
|
245 |
+
}
|
246 |
+
|
247 |
+
public function ajax_connect() {
|
248 |
+
$this->safe_connect( $_POST['to'] );
|
249 |
+
}
|
250 |
+
|
251 |
+
private function safe_connect( $to ) {
|
252 |
+
$from = absint( $_POST['from'] );
|
253 |
+
$to = absint( $to );
|
254 |
+
|
255 |
+
if ( !$from || !$to )
|
256 |
+
die(-1);
|
257 |
+
|
258 |
+
$p2p_id = $this->data->connect( $from, $to, $this->direction );
|
259 |
+
|
260 |
+
die( $this->connection_row( $p2p_id, $to ) );
|
261 |
+
}
|
262 |
+
|
263 |
+
public function ajax_disconnect() {
|
264 |
+
$this->data->delete_connection( $_POST['p2p_id'] );
|
265 |
+
|
266 |
+
die(1);
|
267 |
+
}
|
268 |
+
|
269 |
+
public function ajax_clear_connections() {
|
270 |
+
$this->data->disconnect( $_POST['post_id'], $this->direction );
|
271 |
+
|
272 |
+
die(1);
|
273 |
+
}
|
274 |
+
|
275 |
+
public function ajax_search() {
|
276 |
+
$rows = $this->post_rows( $_GET['post_id'], $_GET['paged'], $_GET['s'] );
|
277 |
+
|
278 |
+
if ( $rows ) {
|
279 |
+
$results = compact( 'rows' );
|
280 |
+
} else {
|
281 |
+
$results = array(
|
282 |
+
'msg' => $this->ptype->labels->not_found,
|
283 |
+
);
|
284 |
+
}
|
285 |
+
|
286 |
+
die( json_encode( $results ) );
|
287 |
+
}
|
288 |
+
|
289 |
+
function _search_by_title( $sql, $wp_query ) {
|
290 |
+
if ( $wp_query->is_search && $wp_query->get( '_p2p_box' ) ) {
|
291 |
+
list( $sql ) = explode( ' OR ', $sql, 2 );
|
292 |
+
return $sql . '))';
|
293 |
+
}
|
294 |
+
|
295 |
+
return $sql;
|
296 |
+
}
|
297 |
+
}
|
298 |
+
|
299 |
+
|
300 |
+
// Helpers
|
301 |
+
|
302 |
+
function _p2p_mustache_render( $file, $data, $partials = array() ) {
|
303 |
+
$partial_data = array();
|
304 |
+
foreach ( $partials as $partial ) {
|
305 |
+
$partial_data[$partial] = _p2p_load_template( $partial . '.html' );
|
306 |
+
}
|
307 |
+
|
308 |
+
$m = new Mustache;
|
309 |
+
|
310 |
+
return $m->render( _p2p_load_template( $file ), $data, $partial_data );
|
311 |
+
}
|
312 |
+
|
313 |
+
function _p2p_load_template( $file ) {
|
314 |
+
return file_get_contents( dirname(__FILE__) . '/templates/' . $file );
|
315 |
+
}
|
316 |
+
|
admin/fields.php
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class P2P_Field_Create implements P2P_Field {
|
4 |
+
|
5 |
+
function get_title() {
|
6 |
+
// Not needed
|
7 |
+
return '';
|
8 |
+
}
|
9 |
+
|
10 |
+
function render( $key, $p2p_id, $post_id ) {
|
11 |
+
$data = array(
|
12 |
+
'post_id' => $post_id,
|
13 |
+
'title' => __( 'Create connection', P2P_TEXTDOMAIN )
|
14 |
+
);
|
15 |
+
|
16 |
+
return _p2p_mustache_render( 'column-create.html', $data );
|
17 |
+
}
|
18 |
+
}
|
19 |
+
|
20 |
+
|
21 |
+
class P2P_Field_Delete implements P2P_Field {
|
22 |
+
|
23 |
+
function get_title() {
|
24 |
+
$data = array(
|
25 |
+
'title' => __( 'Delete all connections', P2P_TEXTDOMAIN )
|
26 |
+
);
|
27 |
+
|
28 |
+
return _p2p_mustache_render( 'column-delete-all.html', $data );
|
29 |
+
}
|
30 |
+
|
31 |
+
function render( $key, $p2p_id, $post_id ) {
|
32 |
+
$data = array(
|
33 |
+
'p2p_id' => $p2p_id,
|
34 |
+
'title' => __( 'Delete connection', P2P_TEXTDOMAIN )
|
35 |
+
);
|
36 |
+
|
37 |
+
return _p2p_mustache_render( 'column-delete.html', $data );
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
|
42 |
+
class P2P_Field_Order implements P2P_Field {
|
43 |
+
|
44 |
+
protected $sort_key;
|
45 |
+
|
46 |
+
function __construct( $sort_key ) {
|
47 |
+
$this->sort_key = $sort_key;
|
48 |
+
}
|
49 |
+
|
50 |
+
function get_title() {
|
51 |
+
return '';
|
52 |
+
}
|
53 |
+
|
54 |
+
function render( $key, $p2p_id, $post_id ) {
|
55 |
+
return html( 'input', array(
|
56 |
+
'type' => 'hidden',
|
57 |
+
'name' => "p2p_order[$this->sort_key][]",
|
58 |
+
'value' => $p2p_id
|
59 |
+
) );
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
|
64 |
+
class P2P_Field_Title implements P2P_Field {
|
65 |
+
|
66 |
+
protected $title;
|
67 |
+
|
68 |
+
function __construct( $title = '' ) {
|
69 |
+
$this->title = $title;
|
70 |
+
}
|
71 |
+
|
72 |
+
function get_title() {
|
73 |
+
return $this->title;
|
74 |
+
}
|
75 |
+
|
76 |
+
function render( $key, $p2p_id, $post_id ) {
|
77 |
+
$data = array(
|
78 |
+
'title-attr' => get_post_type_object( get_post_type( $post_id ) )->labels->edit_item,
|
79 |
+
'title' => get_post_field( 'post_title', $post_id ),
|
80 |
+
'url' => get_edit_post_link( $post_id ),
|
81 |
+
);
|
82 |
+
|
83 |
+
$post_status = get_post_status( $post_id );
|
84 |
+
|
85 |
+
if ( 'publish' != $post_status ) {
|
86 |
+
$status_obj = get_post_status_object( $post_status );
|
87 |
+
if ( $status_obj ) {
|
88 |
+
$data['status']['text'] = $status_obj->label;
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
return _p2p_mustache_render( 'column-title.html', $data );
|
93 |
+
}
|
94 |
+
}
|
95 |
+
|
96 |
+
|
97 |
+
class P2P_Field_Generic implements P2P_Field {
|
98 |
+
|
99 |
+
protected $data;
|
100 |
+
|
101 |
+
function __construct( $data ) {
|
102 |
+
if ( !is_array( $data ) )
|
103 |
+
$data = array( 'title' => $data );
|
104 |
+
|
105 |
+
$this->data = $data;
|
106 |
+
}
|
107 |
+
|
108 |
+
function get_title() {
|
109 |
+
return $this->data['title'];
|
110 |
+
}
|
111 |
+
|
112 |
+
function render( $key, $p2p_id, $post_id ) {
|
113 |
+
$form = new scbForm(
|
114 |
+
array( $key => p2p_get_meta( $p2p_id, $key, true ) ),
|
115 |
+
array( 'p2p_meta', $p2p_id )
|
116 |
+
);
|
117 |
+
|
118 |
+
$args = array(
|
119 |
+
'type' => 'text',
|
120 |
+
'name' => $key
|
121 |
+
);
|
122 |
+
|
123 |
+
if ( isset( $this->data['values'] ) ) {
|
124 |
+
$args['type'] = 'select';
|
125 |
+
$args['value'] = $this->data['values'];
|
126 |
+
}
|
127 |
+
|
128 |
+
return $form->input( $args );
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
{ui → admin}/images/add.png
RENAMED
File without changes
|
{ui → admin}/images/delete.png
RENAMED
File without changes
|
admin/images/sort.png
ADDED
Binary file
|
{ui → admin}/templates/box.html
RENAMED
File without changes
|
admin/templates/column-create.html
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<a href="#" data-post_id="{{post_id}}" title="{{title}}"></a>
|
admin/templates/column-delete-all.html
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<a href="#" title="{{title}}"></a>
|
admin/templates/column-delete.html
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<a href="#" data-p2p_id="{{p2p_id}}" title="{{title}}"></a>
|
{ui → admin}/templates/column-title.html
RENAMED
File without changes
|
{ui → admin}/templates/tab-create-post.html
RENAMED
File without changes
|
ui/templates/tab-recent.html → admin/templates/tab-list.html
RENAMED
@@ -1,7 +1,7 @@
|
|
1 |
<table class="p2p-results">
|
2 |
<tbody>
|
3 |
{{#rows}}
|
4 |
-
{{>
|
5 |
{{/rows}}
|
6 |
</tbody>
|
7 |
</table>
|
@@ -9,7 +9,11 @@
|
|
9 |
{{#navigation}}
|
10 |
<div class="p2p-navigation">
|
11 |
<div class="p2p-prev button {{prev-inactive}}" title="{{prev-label}}">‹</div>
|
12 |
-
<div
|
|
|
|
|
|
|
|
|
13 |
<div class="p2p-next button {{next-inactive}}" title="{{next-label}}">›</div>
|
14 |
</div>
|
15 |
{{/navigation}}
|
1 |
<table class="p2p-results">
|
2 |
<tbody>
|
3 |
{{#rows}}
|
4 |
+
{{>table-row}}
|
5 |
{{/rows}}
|
6 |
</tbody>
|
7 |
</table>
|
9 |
{{#navigation}}
|
10 |
<div class="p2p-navigation">
|
11 |
<div class="p2p-prev button {{prev-inactive}}" title="{{prev-label}}">‹</div>
|
12 |
+
<div>
|
13 |
+
<span class="p2p-current" data-num="{{current-page-raw}}">{{current-page}}</span>
|
14 |
+
{{of-label}}
|
15 |
+
<span class="p2p-total" data-num="{{total-pages-raw}}">{{total-pages}}</span>
|
16 |
+
</div>
|
17 |
<div class="p2p-next button {{next-inactive}}" title="{{next-label}}">›</div>
|
18 |
</div>
|
19 |
{{/navigation}}
|
{ui → admin}/templates/tab-search.html
RENAMED
File without changes
|
ui/templates/box-row.html → admin/templates/table-row.html
RENAMED
File without changes
|
api.php
DELETED
@@ -1,331 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Register a connection between two post types.
|
5 |
-
* This creates the appropriate meta box in the admin edit screen
|
6 |
-
*
|
7 |
-
* @param array $args Can be:
|
8 |
-
* - 'from' string|array The first end of the connection.
|
9 |
-
* - 'to' string|array The second end of the connection.
|
10 |
-
* - 'fields' array Additional metadata fields (optional).
|
11 |
-
* - 'prevent_duplicates' bool Wether to disallow duplicate connections between the same two posts. Default: true.
|
12 |
-
* - 'reciprocal' bool Wether to show the box on both sides of the connection. Default: false.
|
13 |
-
* - 'title' string The box's title. Default: 'Connected {$post_type}s'
|
14 |
-
* - 'context' string Where should the box show up by default. Possible values: 'advanced' or 'side'
|
15 |
-
* - 'box' string A class that handles displaying and saving connections. Default: P2P_Box_Multiple
|
16 |
-
*/
|
17 |
-
function p2p_register_connection_type( $args ) {
|
18 |
-
$argv = func_get_args();
|
19 |
-
|
20 |
-
if ( count( $argv ) > 1 ) {
|
21 |
-
$args = array();
|
22 |
-
@list( $args['from'], $args['to'], $args['reciprocal'] ) = $argv;
|
23 |
-
}
|
24 |
-
|
25 |
-
$defaults = array(
|
26 |
-
'from' => '',
|
27 |
-
'to' => '',
|
28 |
-
'fields' => array(),
|
29 |
-
'prevent_duplicates' => true,
|
30 |
-
'reciprocal' => false,
|
31 |
-
'title' => '',
|
32 |
-
'context' => 'side',
|
33 |
-
'box' => 'P2P_Box_Multiple',
|
34 |
-
);
|
35 |
-
|
36 |
-
$args = wp_parse_args( $args, $defaults );
|
37 |
-
|
38 |
-
foreach ( (array) $args['from'] as $from ) {
|
39 |
-
foreach ( (array) $args['to'] as $to ) {
|
40 |
-
P2P_Connection_Types::register( array_merge( $args, compact( 'from', 'to' ) ) );
|
41 |
-
}
|
42 |
-
}
|
43 |
-
}
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Connect a post to one or more other posts.
|
47 |
-
*
|
48 |
-
* @param int|array $from The first end of the connection
|
49 |
-
* @param int|array $to The second end of the connection
|
50 |
-
* @param array $data additional data about the connection
|
51 |
-
*/
|
52 |
-
function p2p_connect( $from, $to, $data = array() ) {
|
53 |
-
foreach ( (array) $from as $from ) {
|
54 |
-
foreach ( (array) $to as $to ) {
|
55 |
-
P2P_Connections::connect( $from, $to, $data );
|
56 |
-
}
|
57 |
-
}
|
58 |
-
}
|
59 |
-
|
60 |
-
/**
|
61 |
-
* Disconnect a post from or more other posts.
|
62 |
-
*
|
63 |
-
* @param int|array $from The first end of the connection
|
64 |
-
* @param int|array|string $to The second end of the connection
|
65 |
-
* @param array $data additional data about the connection to filter against
|
66 |
-
*/
|
67 |
-
function p2p_disconnect( $from, $to, $data = array() ) {
|
68 |
-
foreach ( (array) $from as $from ) {
|
69 |
-
foreach ( (array) $to as $to ) {
|
70 |
-
P2P_Connections::disconnect( $from, $to, $data );
|
71 |
-
}
|
72 |
-
}
|
73 |
-
}
|
74 |
-
|
75 |
-
/**
|
76 |
-
* Get a list of connected posts.
|
77 |
-
*
|
78 |
-
* Low-level function. Use new WP_Query( array( 'connected' => $post_id ) ) instead.
|
79 |
-
*
|
80 |
-
* @param int $post_id One end of the connection
|
81 |
-
* @param string $direction The direction of the connection. Can be 'to', 'from' or 'any'
|
82 |
-
* @param array $data additional data about the connection to filter against
|
83 |
-
*
|
84 |
-
* @return array( p2p_id => post_id )
|
85 |
-
*/
|
86 |
-
function p2p_get_connected( $post_id, $direction = 'any', $data = array() ) {
|
87 |
-
return P2P_Connections::get( $post_id, $direction, $data );
|
88 |
-
}
|
89 |
-
|
90 |
-
/**
|
91 |
-
* See if a certain post is connected to another one
|
92 |
-
*
|
93 |
-
* @param int $from The first end of the connection
|
94 |
-
* @param int $to The second end of the connection
|
95 |
-
* @param array $data additional data about the connection to filter against
|
96 |
-
*
|
97 |
-
* @return bool True if the connection exists, false otherwise
|
98 |
-
*/
|
99 |
-
function p2p_is_connected( $from, $to, $data = array() ) {
|
100 |
-
$ids = p2p_get_connected( $from, $to, $data );
|
101 |
-
|
102 |
-
return !empty( $ids );
|
103 |
-
}
|
104 |
-
|
105 |
-
/**
|
106 |
-
* Delete one or more connections
|
107 |
-
*
|
108 |
-
* @param int|array $p2p_id Connection ids
|
109 |
-
*
|
110 |
-
* @return int Number of connections deleted
|
111 |
-
*/
|
112 |
-
function p2p_delete_connection( $p2p_id ) {
|
113 |
-
return P2P_Connections::delete( $p2p_id );
|
114 |
-
}
|
115 |
-
|
116 |
-
function p2p_each_connected_to( $query, $qv ) {
|
117 |
-
return _p2p_each_connected( 'to', $query, $qv );
|
118 |
-
}
|
119 |
-
|
120 |
-
function p2p_each_connected_from( $query, $qv ) {
|
121 |
-
return _p2p_each_connected( 'from', $query, $qv );
|
122 |
-
}
|
123 |
-
|
124 |
-
function p2p_each_connected( $query, $qv ) {
|
125 |
-
return _p2p_each_connected( 'any', $query, $qv );
|
126 |
-
}
|
127 |
-
|
128 |
-
/**
|
129 |
-
* Optimized inner query, after the outer query was executed.
|
130 |
-
*
|
131 |
-
* Populates each of the outer querie's $post objects with a property containing a list of connected posts
|
132 |
-
*
|
133 |
-
* @param string $direction The direction of the connection. Can be 'to', 'from' or 'any'
|
134 |
-
* @param object $query The outer query.
|
135 |
-
* @param string|array $args The query vars for the inner query.
|
136 |
-
*/
|
137 |
-
function _p2p_each_connected( $direction, $query, $search ) {
|
138 |
-
if ( empty( $query->posts ) )
|
139 |
-
return;
|
140 |
-
|
141 |
-
$prop_name = 'connected';
|
142 |
-
|
143 |
-
// re-index by ID
|
144 |
-
$posts = array();
|
145 |
-
foreach ( $query->posts as $post ) {
|
146 |
-
$post->$prop_name = array();
|
147 |
-
$posts[ $post->ID ] = $post;
|
148 |
-
}
|
149 |
-
|
150 |
-
// ignore other 'connected' query vars for the inner query
|
151 |
-
foreach ( array_keys( P2P_Query::$qv_map ) as $qv )
|
152 |
-
unset( $search[ $qv ] );
|
153 |
-
|
154 |
-
// ignore pagination
|
155 |
-
$search['nopaging'] = true;
|
156 |
-
foreach ( array( 'showposts', 'posts_per_page', 'posts_per_archive_page' ) as $disabled_qv ) {
|
157 |
-
if ( isset( $search[ $disabled_qv ] ) ) {
|
158 |
-
trigger_error( "Can't use '$disabled_qv' in an inner query", E_USER_WARNING );
|
159 |
-
}
|
160 |
-
}
|
161 |
-
|
162 |
-
$map = array(
|
163 |
-
'any' => 'connected',
|
164 |
-
'from' => 'connected_to',
|
165 |
-
'to' => 'connected_from'
|
166 |
-
);
|
167 |
-
|
168 |
-
$search[ $map[ $direction ] ] = array_keys( $posts );
|
169 |
-
$search[ 'suppress_filters' ] = false;
|
170 |
-
|
171 |
-
foreach ( get_posts( $search ) as $inner_post ) {
|
172 |
-
if ( $inner_post->ID == $inner_post->p2p_from )
|
173 |
-
$outer_post_id = $inner_post->p2p_to;
|
174 |
-
elseif ( $inner_post->ID == $inner_post->p2p_to )
|
175 |
-
$outer_post_id = $inner_post->p2p_from;
|
176 |
-
else
|
177 |
-
throw new Exception( 'Corrupted data.' );
|
178 |
-
|
179 |
-
if ( $outer_post_id == $inner_post->ID )
|
180 |
-
throw new Exception( 'Post connected to itself.' );
|
181 |
-
|
182 |
-
array_push( $posts[ $outer_post_id ]->$prop_name, $inner_post );
|
183 |
-
}
|
184 |
-
}
|
185 |
-
|
186 |
-
// Allows you to write query_posts( array( 'connected' => 123 ) ); etc.
|
187 |
-
class P2P_Query {
|
188 |
-
|
189 |
-
static $qv_map = array(
|
190 |
-
'connected' => 'any',
|
191 |
-
'connected_to' => 'to',
|
192 |
-
'connected_from' => 'from',
|
193 |
-
);
|
194 |
-
|
195 |
-
/**
|
196 |
-
* Handles connected* query vars
|
197 |
-
*/
|
198 |
-
function posts_clauses( $clauses, $wp_query ) {
|
199 |
-
global $wpdb;
|
200 |
-
|
201 |
-
$found = self::find_qv( $wp_query );
|
202 |
-
|
203 |
-
if ( !$found )
|
204 |
-
return $clauses;
|
205 |
-
|
206 |
-
list( $search, $key, $direction ) = $found;
|
207 |
-
|
208 |
-
$clauses['fields'] .= ", $wpdb->p2p.*";
|
209 |
-
|
210 |
-
$clauses['join'] .= " INNER JOIN $wpdb->p2p";
|
211 |
-
|
212 |
-
if ( 'any' == $search ) {
|
213 |
-
$search = false;
|
214 |
-
} else {
|
215 |
-
$search = implode( ',', array_map( 'absint', (array) $search ) );
|
216 |
-
}
|
217 |
-
|
218 |
-
switch ( $direction ) {
|
219 |
-
case 'from':
|
220 |
-
$clauses['where'] .= " AND $wpdb->posts.ID = $wpdb->p2p.p2p_to";
|
221 |
-
if ( $search ) {
|
222 |
-
$clauses['where'] .= " AND $wpdb->p2p.p2p_from IN ($search)";
|
223 |
-
}
|
224 |
-
break;
|
225 |
-
case 'to':
|
226 |
-
$clauses['where'] .= " AND $wpdb->posts.ID = $wpdb->p2p.p2p_from";
|
227 |
-
if ( $search ) {
|
228 |
-
$clauses['where'] .= " AND $wpdb->p2p.p2p_to IN ($search)";
|
229 |
-
}
|
230 |
-
break;
|
231 |
-
case 'any':
|
232 |
-
if ( $search ) {
|
233 |
-
$clauses['where'] .= " AND (
|
234 |
-
($wpdb->posts.ID = $wpdb->p2p.p2p_to AND $wpdb->p2p.p2p_from IN ($search) ) OR
|
235 |
-
($wpdb->posts.ID = $wpdb->p2p.p2p_from AND $wpdb->p2p.p2p_to IN ($search) )
|
236 |
-
)";
|
237 |
-
} else {
|
238 |
-
$clauses['where'] .= " AND ($wpdb->posts.ID = $wpdb->p2p.p2p_to OR $wpdb->posts.ID = $wpdb->p2p.p2p_from)";
|
239 |
-
}
|
240 |
-
break;
|
241 |
-
}
|
242 |
-
|
243 |
-
$connected_meta = $wp_query->get( 'connected_meta' );
|
244 |
-
if ( !empty( $connected_meta ) ) {
|
245 |
-
$meta_clauses = _p2p_meta_sql_helper( $connected_meta );
|
246 |
-
foreach ( $meta_clauses as $key => $value ) {
|
247 |
-
$clauses[ $key ] .= $value;
|
248 |
-
}
|
249 |
-
}
|
250 |
-
|
251 |
-
// Handle ordering
|
252 |
-
$connected_orderby = $wp_query->get( 'connected_orderby' );
|
253 |
-
if ( $connected_orderby ) {
|
254 |
-
$clauses['join'] .= $wpdb->prepare( "
|
255 |
-
LEFT JOIN $wpdb->p2pmeta ON ($wpdb->p2p.p2p_id = $wpdb->p2pmeta.p2p_id AND $wpdb->p2pmeta.meta_key = %s )
|
256 |
-
", $connected_orderby );
|
257 |
-
|
258 |
-
$connected_order = ( 'DESC' == strtoupper( $wp_query->get('connected_order') ) ) ? 'DESC' : 'ASC';
|
259 |
-
|
260 |
-
$field = 'meta_value';
|
261 |
-
|
262 |
-
if ( $wp_query->get('connected_order_num') )
|
263 |
-
$field .= '+0';
|
264 |
-
|
265 |
-
$clauses['orderby'] = "$wpdb->p2pmeta.$field $connected_order";
|
266 |
-
}
|
267 |
-
|
268 |
-
return $clauses;
|
269 |
-
}
|
270 |
-
|
271 |
-
/**
|
272 |
-
* Handles each_connected* query vars
|
273 |
-
*
|
274 |
-
* @priority 11
|
275 |
-
*/
|
276 |
-
function the_posts( $the_posts, $wp_query ) {
|
277 |
-
if ( empty( $the_posts ) )
|
278 |
-
return $the_posts;
|
279 |
-
|
280 |
-
if ( self::find_qv( $wp_query ) ) {
|
281 |
-
update_meta_cache( 'p2p', wp_list_pluck( $the_posts, 'p2p_id' ) );
|
282 |
-
}
|
283 |
-
|
284 |
-
$found = self::find_qv( $wp_query, 'each_' );
|
285 |
-
|
286 |
-
if ( !$found )
|
287 |
-
return $the_posts;
|
288 |
-
|
289 |
-
list( $search, $qv, $direction ) = $found;
|
290 |
-
|
291 |
-
_p2p_each_connected( $direction, $wp_query, $search );
|
292 |
-
|
293 |
-
return $the_posts;
|
294 |
-
}
|
295 |
-
|
296 |
-
private function find_qv( $wp_query, $prefix = '' ) {
|
297 |
-
foreach ( self::$qv_map as $qv => $direction ) {
|
298 |
-
$search = $wp_query->get( $prefix . $qv );
|
299 |
-
if ( !empty( $search ) )
|
300 |
-
break;
|
301 |
-
}
|
302 |
-
|
303 |
-
if ( empty( $search ) )
|
304 |
-
return false;
|
305 |
-
|
306 |
-
return array( $search, $qv, $direction );
|
307 |
-
}
|
308 |
-
}
|
309 |
-
scbHooks::add( 'P2P_Query' );
|
310 |
-
|
311 |
-
/**
|
312 |
-
* List some posts
|
313 |
-
*
|
314 |
-
* @param object|array A WP_Query instance, a list of post objects or a list of post ids
|
315 |
-
*/
|
316 |
-
function p2p_list_posts( $posts ) {
|
317 |
-
if ( is_object( $posts ) )
|
318 |
-
$posts = $posts->posts;
|
319 |
-
|
320 |
-
if ( empty( $posts ) )
|
321 |
-
return;
|
322 |
-
|
323 |
-
if ( is_object( $posts[0] ) )
|
324 |
-
$posts = wp_list_pluck( $posts, 'ID' );
|
325 |
-
|
326 |
-
echo '<ul>';
|
327 |
-
foreach ( $posts as $post_id ) {
|
328 |
-
echo html( 'li', html( 'a', array( 'href' => get_permalink( $post_id ) ), get_the_title( $post_id ) ) );
|
329 |
-
}
|
330 |
-
echo '</ul>';
|
331 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
core/api.php
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Register a connection between two post types.
|
5 |
+
* This creates the appropriate meta box in the admin edit screen
|
6 |
+
*
|
7 |
+
* @param array $args See https://github.com/scribu/wp-posts-to-posts/wiki/p2p_register_connection_type()
|
8 |
+
* @return bool|object False on failure, P2P_Connection_Type instance on success.
|
9 |
+
*/
|
10 |
+
function p2p_register_connection_type( $args ) {
|
11 |
+
if ( !did_action('init') ) {
|
12 |
+
trigger_error( "Connection types should not be registered before the 'init' hook.", E_USER_NOTICE );
|
13 |
+
}
|
14 |
+
|
15 |
+
$argv = func_get_args();
|
16 |
+
|
17 |
+
if ( count( $argv ) > 1 ) {
|
18 |
+
$args = array();
|
19 |
+
@list( $args['from'], $args['to'], $args['reciprocal'] ) = $argv;
|
20 |
+
}
|
21 |
+
|
22 |
+
$args = wp_parse_args( $args, array(
|
23 |
+
'show_ui' => true,
|
24 |
+
'fields' => array(),
|
25 |
+
'context' => 'side',
|
26 |
+
) );
|
27 |
+
|
28 |
+
return P2P_Connection_Type::make_instance( $args );
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Connect a post to one or more other posts.
|
33 |
+
*
|
34 |
+
* @param int|array $from The first end of the connection
|
35 |
+
* @param int|array $to The second end of the connection
|
36 |
+
* @param array $data additional data about the connection
|
37 |
+
*/
|
38 |
+
function p2p_connect( $from, $to, $data = array() ) {
|
39 |
+
foreach ( (array) $from as $from ) {
|
40 |
+
foreach ( (array) $to as $to ) {
|
41 |
+
P2P_Storage::connect( $from, $to, $data );
|
42 |
+
}
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Disconnect a post from or more other posts.
|
48 |
+
*
|
49 |
+
* @param int|array $from The first end of the connection
|
50 |
+
* @param int|array|string $to The second end of the connection
|
51 |
+
* @param array $data additional data about the connection to filter against
|
52 |
+
*/
|
53 |
+
function p2p_disconnect( $from, $to, $data = array() ) {
|
54 |
+
foreach ( (array) $from as $from ) {
|
55 |
+
foreach ( (array) $to as $to ) {
|
56 |
+
P2P_Storage::disconnect( $from, $to, $data );
|
57 |
+
}
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Get a list of connected posts.
|
63 |
+
*
|
64 |
+
* Low-level function. Use new WP_Query( array( 'connected' => $post_id ) ) instead.
|
65 |
+
*
|
66 |
+
* @param int $post_id One end of the connection
|
67 |
+
* @param string $direction The direction of the connection. Can be 'to', 'from' or 'any'
|
68 |
+
* @param array $data additional data about the connection to filter against
|
69 |
+
*
|
70 |
+
* @return array( p2p_id => post_id )
|
71 |
+
*/
|
72 |
+
function p2p_get_connected( $post_id, $direction = 'any', $data = array() ) {
|
73 |
+
return P2P_Storage::get( $post_id, $direction, $data );
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* See if a certain post is connected to another one
|
78 |
+
*
|
79 |
+
* @param int $from The first end of the connection
|
80 |
+
* @param int $to The second end of the connection
|
81 |
+
* @param array $data additional data about the connection to filter against
|
82 |
+
*
|
83 |
+
* @return bool True if the connection exists, false otherwise
|
84 |
+
*/
|
85 |
+
function p2p_is_connected( $from, $to, $data = array() ) {
|
86 |
+
$ids = p2p_get_connected( $from, $to, $data );
|
87 |
+
|
88 |
+
return !empty( $ids );
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Delete one or more connections
|
93 |
+
*
|
94 |
+
* @param int|array $p2p_id Connection ids
|
95 |
+
*
|
96 |
+
* @return int Number of connections deleted
|
97 |
+
*/
|
98 |
+
function p2p_delete_connection( $p2p_id ) {
|
99 |
+
return P2P_Storage::delete( $p2p_id );
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* List some posts.
|
104 |
+
*
|
105 |
+
* @param object|array A WP_Query instance, or a list of post objects
|
106 |
+
* @param array $args (optional)
|
107 |
+
*/
|
108 |
+
function p2p_list_posts( $posts, $args = array() ) {
|
109 |
+
if ( is_object( $posts ) )
|
110 |
+
$posts = $posts->posts;
|
111 |
+
|
112 |
+
$args = wp_parse_args( $args, array(
|
113 |
+
'before_list' => '<ul>', 'after_list' => '</ul>',
|
114 |
+
'before_item' => '<li>', 'after_item' => '</li>',
|
115 |
+
'template' => false
|
116 |
+
) );
|
117 |
+
|
118 |
+
extract( $args, EXTR_SKIP );
|
119 |
+
|
120 |
+
if ( empty( $posts ) )
|
121 |
+
return;
|
122 |
+
|
123 |
+
echo $before_list;
|
124 |
+
|
125 |
+
foreach ( $posts as $post ) {
|
126 |
+
$GLOBALS['post'] = $post;
|
127 |
+
|
128 |
+
setup_postdata( $post );
|
129 |
+
|
130 |
+
echo $before_item;
|
131 |
+
|
132 |
+
if ( $template )
|
133 |
+
locate_template( $template, true, false );
|
134 |
+
else
|
135 |
+
echo html( 'a', array( 'href' => get_permalink( $post->ID ) ), get_the_title( $post->ID ) );
|
136 |
+
|
137 |
+
echo $after_item;
|
138 |
+
}
|
139 |
+
|
140 |
+
echo $after_list;
|
141 |
+
|
142 |
+
wp_reset_postdata();
|
143 |
+
}
|
144 |
+
|
core/query.php
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Handles connected{_to|_from} query vars
|
5 |
+
*/
|
6 |
+
class P2P_Query {
|
7 |
+
|
8 |
+
function init() {
|
9 |
+
add_action( 'parse_query', array( 'P2P_Query', 'parse_legacy_qv' ) );
|
10 |
+
add_filter( 'posts_clauses', array( 'P2P_Query', 'posts_clauses' ), 10, 2 );
|
11 |
+
add_filter( 'the_posts', array( 'P2P_Query', 'the_posts' ), 11, 2 );
|
12 |
+
}
|
13 |
+
|
14 |
+
function parse_legacy_qv( $wp_query ) {
|
15 |
+
$qv_map = array(
|
16 |
+
'connected_to' => 'to',
|
17 |
+
'connected_from' => 'from',
|
18 |
+
);
|
19 |
+
|
20 |
+
foreach ( $qv_map as $key => $direction ) {
|
21 |
+
$search = $wp_query->get( $key );
|
22 |
+
if ( !empty( $search ) ) {
|
23 |
+
trigger_error( "'$key' query var is deprecated. Use 'connected' + 'connected_direction' instead.", E_USER_NOTICE );
|
24 |
+
$wp_query->set( 'connected', $search );
|
25 |
+
$wp_query->set( 'connected_direction', $direction );
|
26 |
+
|
27 |
+
$wp_query->set( $key, false );
|
28 |
+
}
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
function posts_clauses( $clauses, $wp_query ) {
|
33 |
+
global $wpdb;
|
34 |
+
|
35 |
+
$search = $wp_query->get( 'connected' );
|
36 |
+
if ( empty( $search ) )
|
37 |
+
return $clauses;
|
38 |
+
|
39 |
+
$direction = $wp_query->get( 'connected_direction' );
|
40 |
+
if ( empty( $direction ) )
|
41 |
+
$direction = 'any';
|
42 |
+
|
43 |
+
$wp_query->_p2p_cache = true;
|
44 |
+
|
45 |
+
$clauses['fields'] .= ", $wpdb->p2p.*";
|
46 |
+
|
47 |
+
$clauses['join'] .= " INNER JOIN $wpdb->p2p";
|
48 |
+
|
49 |
+
if ( 'any' == $search ) {
|
50 |
+
$search = false;
|
51 |
+
} else {
|
52 |
+
$search = implode( ',', array_map( 'absint', (array) $search ) );
|
53 |
+
}
|
54 |
+
|
55 |
+
switch ( $direction ) {
|
56 |
+
case 'from':
|
57 |
+
$clauses['where'] .= " AND $wpdb->posts.ID = $wpdb->p2p.p2p_to";
|
58 |
+
if ( $search ) {
|
59 |
+
$clauses['where'] .= " AND $wpdb->p2p.p2p_from IN ($search)";
|
60 |
+
}
|
61 |
+
break;
|
62 |
+
|
63 |
+
case 'to':
|
64 |
+
$clauses['where'] .= " AND $wpdb->posts.ID = $wpdb->p2p.p2p_from";
|
65 |
+
if ( $search ) {
|
66 |
+
$clauses['where'] .= " AND $wpdb->p2p.p2p_to IN ($search)";
|
67 |
+
}
|
68 |
+
break;
|
69 |
+
|
70 |
+
case 'any':
|
71 |
+
if ( $search ) {
|
72 |
+
$clauses['where'] .= " AND (
|
73 |
+
($wpdb->posts.ID = $wpdb->p2p.p2p_to AND $wpdb->p2p.p2p_from IN ($search)) OR
|
74 |
+
($wpdb->posts.ID = $wpdb->p2p.p2p_from AND $wpdb->p2p.p2p_to IN ($search))
|
75 |
+
)";
|
76 |
+
} else {
|
77 |
+
$clauses['where'] .= " AND ($wpdb->posts.ID = $wpdb->p2p.p2p_to OR $wpdb->posts.ID = $wpdb->p2p.p2p_from)";
|
78 |
+
}
|
79 |
+
break;
|
80 |
+
}
|
81 |
+
|
82 |
+
$connected_meta = $wp_query->get( 'connected_meta' );
|
83 |
+
if ( !empty( $connected_meta ) ) {
|
84 |
+
$meta_clauses = _p2p_meta_sql_helper( $connected_meta );
|
85 |
+
foreach ( $meta_clauses as $key => $value ) {
|
86 |
+
$clauses[ $key ] .= $value;
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
// Handle ordering
|
91 |
+
$connected_orderby = $wp_query->get( 'connected_orderby' );
|
92 |
+
if ( $connected_orderby ) {
|
93 |
+
$clauses['join'] .= $wpdb->prepare( "
|
94 |
+
LEFT JOIN $wpdb->p2pmeta AS p2pm_order ON (
|
95 |
+
$wpdb->p2p.p2p_id = p2pm_order.p2p_id AND p2pm_order.meta_key = %s
|
96 |
+
)
|
97 |
+
", $connected_orderby );
|
98 |
+
|
99 |
+
$connected_order = ( 'DESC' == strtoupper( $wp_query->get('connected_order') ) ) ? 'DESC' : 'ASC';
|
100 |
+
|
101 |
+
$field = 'meta_value';
|
102 |
+
|
103 |
+
if ( $wp_query->get('connected_order_num') )
|
104 |
+
$field .= '+0';
|
105 |
+
|
106 |
+
$clauses['orderby'] = "p2pm_order.$field $connected_order";
|
107 |
+
}
|
108 |
+
|
109 |
+
return $clauses;
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Pre-populates the p2p meta cache to decrease the number of queries.
|
114 |
+
*/
|
115 |
+
function the_posts( $the_posts, $wp_query ) {
|
116 |
+
if ( empty( $the_posts ) )
|
117 |
+
return $the_posts;
|
118 |
+
|
119 |
+
if ( isset( $wp_query->_p2p_cache ) ) {
|
120 |
+
update_meta_cache( 'p2p', wp_list_pluck( $the_posts, 'p2p_id' ) );
|
121 |
+
}
|
122 |
+
|
123 |
+
return $the_posts;
|
124 |
+
}
|
125 |
+
}
|
126 |
+
|
127 |
+
P2P_Query::init();
|
128 |
+
|
storage.php → core/storage.php
RENAMED
@@ -1,9 +1,11 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class
|
4 |
|
5 |
-
|
6 |
-
|
|
|
|
|
7 |
p2p_id bigint(20) unsigned NOT NULL auto_increment,
|
8 |
p2p_from bigint(20) unsigned NOT NULL,
|
9 |
p2p_to bigint(20) unsigned NOT NULL,
|
@@ -12,7 +14,7 @@ class P2P_Connections {
|
|
12 |
KEY p2p_to (p2p_to)
|
13 |
" );
|
14 |
|
15 |
-
$table2 = new scbTable( 'p2pmeta',
|
16 |
meta_id bigint(20) unsigned NOT NULL auto_increment,
|
17 |
p2p_id bigint(20) unsigned NOT NULL default '0',
|
18 |
meta_key varchar(255) default NULL,
|
@@ -22,9 +24,12 @@ class P2P_Connections {
|
|
22 |
KEY meta_key (meta_key)
|
23 |
" );
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
28 |
|
29 |
add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
|
30 |
}
|
@@ -49,11 +54,8 @@ class P2P_Connections {
|
|
49 |
$from = self::_get( $post_id, 'from', $data );
|
50 |
$to = self::_get( $post_id, 'to', $data );
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
}
|
55 |
-
|
56 |
-
return $from;
|
57 |
}
|
58 |
|
59 |
return self::_get( $post_id, $direction, $data );
|
@@ -72,10 +74,12 @@ class P2P_Connections {
|
|
72 |
$fields .= ', p2p_to AS post_id';
|
73 |
$where .= $wpdb->prepare( "p2p_from = %d", $from );
|
74 |
break;
|
|
|
75 |
case 'to':
|
76 |
$fields .= ', p2p_from AS post_id';
|
77 |
$where .= $wpdb->prepare( "p2p_to = %d", $from );
|
78 |
break;
|
|
|
79 |
default:
|
80 |
$where .= $wpdb->prepare( "p2p_from = %d AND p2p_to = %d", $from, $to );
|
81 |
$_return_p2p_ids = true;
|
@@ -107,11 +111,10 @@ class P2P_Connections {
|
|
107 |
* @param int $from post id
|
108 |
* @param int $to post id
|
109 |
* @param array $data additional data about the connection
|
110 |
-
* @param string $duplicates Duplicate prevention strategy: 'none', 'matching_data', 'strict'
|
111 |
*
|
112 |
* @return int|bool connection id or False on failure
|
113 |
*/
|
114 |
-
function connect( $from, $to, $data = array()
|
115 |
global $wpdb;
|
116 |
|
117 |
$from = absint( $from );
|
@@ -173,6 +176,8 @@ class P2P_Connections {
|
|
173 |
}
|
174 |
}
|
175 |
|
|
|
|
|
176 |
|
177 |
function p2p_get_meta($p2p_id, $key, $single = false) {
|
178 |
return get_metadata('p2p', $p2p_id, $key, $single);
|
1 |
<?php
|
2 |
|
3 |
+
class P2P_Storage {
|
4 |
|
5 |
+
private static $version = 3;
|
6 |
+
|
7 |
+
function init() {
|
8 |
+
$table = new scbTable( 'p2p', false, "
|
9 |
p2p_id bigint(20) unsigned NOT NULL auto_increment,
|
10 |
p2p_from bigint(20) unsigned NOT NULL,
|
11 |
p2p_to bigint(20) unsigned NOT NULL,
|
14 |
KEY p2p_to (p2p_to)
|
15 |
" );
|
16 |
|
17 |
+
$table2 = new scbTable( 'p2pmeta', false, "
|
18 |
meta_id bigint(20) unsigned NOT NULL auto_increment,
|
19 |
p2p_id bigint(20) unsigned NOT NULL default '0',
|
20 |
meta_key varchar(255) default NULL,
|
24 |
KEY meta_key (meta_key)
|
25 |
" );
|
26 |
|
27 |
+
if ( is_admin() && self::$version != get_option( 'p2p_storage' ) ) {
|
28 |
+
$table->install();
|
29 |
+
$table2->install();
|
30 |
+
|
31 |
+
update_option( 'p2p_storage', self::$version );
|
32 |
+
}
|
33 |
|
34 |
add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
|
35 |
}
|
54 |
$from = self::_get( $post_id, 'from', $data );
|
55 |
$to = self::_get( $post_id, 'to', $data );
|
56 |
|
57 |
+
// array_merge() doesn't preserve numeric keys
|
58 |
+
return $from + $to;
|
|
|
|
|
|
|
59 |
}
|
60 |
|
61 |
return self::_get( $post_id, $direction, $data );
|
74 |
$fields .= ', p2p_to AS post_id';
|
75 |
$where .= $wpdb->prepare( "p2p_from = %d", $from );
|
76 |
break;
|
77 |
+
|
78 |
case 'to':
|
79 |
$fields .= ', p2p_from AS post_id';
|
80 |
$where .= $wpdb->prepare( "p2p_to = %d", $from );
|
81 |
break;
|
82 |
+
|
83 |
default:
|
84 |
$where .= $wpdb->prepare( "p2p_from = %d AND p2p_to = %d", $from, $to );
|
85 |
$_return_p2p_ids = true;
|
111 |
* @param int $from post id
|
112 |
* @param int $to post id
|
113 |
* @param array $data additional data about the connection
|
|
|
114 |
*
|
115 |
* @return int|bool connection id or False on failure
|
116 |
*/
|
117 |
+
function connect( $from, $to, $data = array() ) {
|
118 |
global $wpdb;
|
119 |
|
120 |
$from = absint( $from );
|
176 |
}
|
177 |
}
|
178 |
|
179 |
+
P2P_Storage::init();
|
180 |
+
|
181 |
|
182 |
function p2p_get_meta($p2p_id, $key, $single = false) {
|
183 |
return get_metadata('p2p', $p2p_id, $key, $single);
|
core/type.php
ADDED
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class P2P_Connection_Type {
|
4 |
+
|
5 |
+
static $instances = array();
|
6 |
+
|
7 |
+
protected $args;
|
8 |
+
|
9 |
+
protected function __construct( $args ) {
|
10 |
+
$this->args = $args;
|
11 |
+
}
|
12 |
+
|
13 |
+
public function __get( $key ) {
|
14 |
+
return $this->args[$key];
|
15 |
+
}
|
16 |
+
|
17 |
+
public function get_instance( $hash ) {
|
18 |
+
if ( isset( self::$instances[ $hash ] ) )
|
19 |
+
return self::$instances[ $hash ];
|
20 |
+
|
21 |
+
return false;
|
22 |
+
}
|
23 |
+
|
24 |
+
public function make_instance( $args ) {
|
25 |
+
$args = wp_parse_args( $args, array(
|
26 |
+
'from' => '',
|
27 |
+
'to' => '',
|
28 |
+
'data' => array(),
|
29 |
+
'reciprocal' => null,
|
30 |
+
'sortable' => false,
|
31 |
+
'prevent_duplicates' => true,
|
32 |
+
'title' => '',
|
33 |
+
) );
|
34 |
+
|
35 |
+
foreach ( array( 'from', 'to' ) as $key ) {
|
36 |
+
$args[ $key ] = array_values( array_filter( (array) $args[ $key ], 'post_type_exists' ) );
|
37 |
+
if ( empty( $args[ $key ] ) ) {
|
38 |
+
trigger_error( "'$key' arg doesn't contain any valid post types", E_USER_WARNING );
|
39 |
+
return false;
|
40 |
+
}
|
41 |
+
sort( $args[ $key ] );
|
42 |
+
}
|
43 |
+
|
44 |
+
$common = array_intersect( $args['from'], $args['to'] );
|
45 |
+
if ( !empty( $common ) && count( $args['from'] ) + count( $args['to'] ) > 2 ) {
|
46 |
+
$args['reciprocal'] = false;
|
47 |
+
}
|
48 |
+
|
49 |
+
if ( is_null( $args['reciprocal'] ) )
|
50 |
+
$args['reciprocal'] = ( $args['from'] == $args['to'] );
|
51 |
+
|
52 |
+
$hash = md5( serialize( wp_array_slice_assoc( $args, array( 'from', 'to', 'data' ) ) ) );
|
53 |
+
|
54 |
+
if ( isset( self::$instances[ $hash ] ) ) {
|
55 |
+
trigger_error( 'Connection type is already defined.', E_USER_NOTICE );
|
56 |
+
return self::$instances[ $hash ];
|
57 |
+
}
|
58 |
+
|
59 |
+
return self::$instances[ $hash ] = new P2P_Connection_Type( $args );
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Get connection direction.
|
64 |
+
*
|
65 |
+
* @param int|string $arg A post id or a post type.
|
66 |
+
*
|
67 |
+
* @return bool|string False on failure, 'any', 'to' or 'from' on success.
|
68 |
+
*/
|
69 |
+
public function get_direction( $arg ) {
|
70 |
+
if ( $post_id = (int) $arg ) {
|
71 |
+
$post = get_post( $post_id );
|
72 |
+
if ( !$post )
|
73 |
+
return false;
|
74 |
+
$post_type = $post->post_type;
|
75 |
+
} else {
|
76 |
+
$post_type = $arg;
|
77 |
+
}
|
78 |
+
|
79 |
+
if ( in_array( $post_type, $this->from ) ) {
|
80 |
+
if ( in_array( $post_type, $this->to ) )
|
81 |
+
$direction = 'any';
|
82 |
+
else
|
83 |
+
$direction = 'from';
|
84 |
+
} elseif ( in_array( $post_type, $this->to ) ) {
|
85 |
+
$direction = 'to';
|
86 |
+
} else {
|
87 |
+
$direction = false;
|
88 |
+
}
|
89 |
+
|
90 |
+
return $direction;
|
91 |
+
}
|
92 |
+
|
93 |
+
public function get_other_post_type( $direction ) {
|
94 |
+
return 'from' == $direction ? $this->to : $this->from;
|
95 |
+
}
|
96 |
+
|
97 |
+
public function can_create_post( $direction ) {
|
98 |
+
$ptype = $this->get_other_post_type( $direction );
|
99 |
+
|
100 |
+
if ( count( $ptype ) > 1 )
|
101 |
+
return false;
|
102 |
+
|
103 |
+
return current_user_can( get_post_type_object( $ptype[0] )->cap->edit_posts );
|
104 |
+
}
|
105 |
+
|
106 |
+
public function get_title( $direction ) {
|
107 |
+
$title = $this->args['title'];
|
108 |
+
|
109 |
+
if ( is_array( $title ) ) {
|
110 |
+
$key = ( 'to' == $direction ) ? 'to' : 'from';
|
111 |
+
|
112 |
+
if ( isset( $title[ $key ] ) )
|
113 |
+
$title = $title[ $key ];
|
114 |
+
else
|
115 |
+
$title = '';
|
116 |
+
}
|
117 |
+
|
118 |
+
return $title;
|
119 |
+
}
|
120 |
+
|
121 |
+
private function get_base_args( $direction, $extra_qv ) {
|
122 |
+
return array_merge( $extra_qv, array(
|
123 |
+
'post_type' => $this->get_other_post_type( $direction ),
|
124 |
+
'suppress_filters' => false,
|
125 |
+
'ignore_sticky_posts' => true
|
126 |
+
) );
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Get a list of posts that are connected to a given post.
|
131 |
+
*
|
132 |
+
* @param int $post_id A post id.
|
133 |
+
* @param array $extra_qv Additional query variables to use.
|
134 |
+
*
|
135 |
+
* @return bool|object False on failure; A WP_Query instance on success.
|
136 |
+
*/
|
137 |
+
public function get_connected( $post_id, $extra_qv = array(), $_direction = false ) {
|
138 |
+
$direction = $_direction ? $_direction : $this->get_direction( $post_id );
|
139 |
+
if ( !$direction )
|
140 |
+
return false;
|
141 |
+
|
142 |
+
$args = $this->get_base_args( $direction, $extra_qv );
|
143 |
+
|
144 |
+
_p2p_append( $args, array(
|
145 |
+
'connected' => $post_id,
|
146 |
+
'connected_direction' => $direction,
|
147 |
+
'connected_meta' => $this->data,
|
148 |
+
) );
|
149 |
+
|
150 |
+
if ( $this->sortable && 'from' == $direction ) {
|
151 |
+
_p2p_append( $args, array(
|
152 |
+
'connected_orderby' => $this->sortable,
|
153 |
+
'connected_order' => 'ASC',
|
154 |
+
'connected_order_num' => true,
|
155 |
+
) );
|
156 |
+
}
|
157 |
+
|
158 |
+
$args = apply_filters( 'p2p_connected_args', $args, $this );
|
159 |
+
|
160 |
+
return new WP_Query( $args );
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Get a list of posts that could be connected to a given post.
|
165 |
+
*
|
166 |
+
* @param int $post_id A post id.
|
167 |
+
* @param array $extra_qv Additional query variables to use.
|
168 |
+
*
|
169 |
+
* @return bool|object False on failure; A WP_Query instance on success.
|
170 |
+
*/
|
171 |
+
public function get_connectable( $post_id, $extra_qv, $_direction = false ) {
|
172 |
+
$direction = $_direction ? $_direction : $this->get_direction( $post_id );
|
173 |
+
if ( !$direction )
|
174 |
+
return false;
|
175 |
+
|
176 |
+
$args = $this->get_base_args( $direction, $extra_qv );
|
177 |
+
|
178 |
+
if ( $this->prevent_duplicates ) {
|
179 |
+
if ( !isset( $args['post__not_in'] ) ) {
|
180 |
+
$args['post__not_in'] = array();
|
181 |
+
}
|
182 |
+
|
183 |
+
_p2p_append( $args['post__not_in'], P2P_Storage::get( $post_id, $direction, $this->data ) );
|
184 |
+
}
|
185 |
+
|
186 |
+
$args = apply_filters( 'p2p_connectable_args', $args, $this );
|
187 |
+
|
188 |
+
return new WP_Query( $args );
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* Optimized inner query, after the outer query was executed.
|
193 |
+
*
|
194 |
+
* Populates each of the outer querie's $post objects with a 'connected' property, containing a list of connected posts
|
195 |
+
*
|
196 |
+
* @param object $query WP_Query instance.
|
197 |
+
* @param string|array $extra_qv Additional query vars for the inner query.
|
198 |
+
*/
|
199 |
+
public function each_connected( $query, $extra_qv = array() ) {
|
200 |
+
if ( empty( $query->posts ) || !is_object( $query->posts[0] ) )
|
201 |
+
return;
|
202 |
+
|
203 |
+
$post_type = $query->get( 'post_type' );
|
204 |
+
if ( empty( $post_type ) )
|
205 |
+
$post_type = 'post';
|
206 |
+
|
207 |
+
$direction = $this->get_direction( $post_type );
|
208 |
+
if ( !$direction )
|
209 |
+
return;
|
210 |
+
|
211 |
+
$prop_name = 'connected';
|
212 |
+
|
213 |
+
$posts = array();
|
214 |
+
|
215 |
+
foreach ( $query->posts as $post ) {
|
216 |
+
$post->$prop_name = array();
|
217 |
+
$posts[ $post->ID ] = $post;
|
218 |
+
}
|
219 |
+
|
220 |
+
// ignore pagination
|
221 |
+
foreach ( array( 'showposts', 'posts_per_page', 'posts_per_archive_page' ) as $disabled_qv ) {
|
222 |
+
if ( isset( $extra_qv[ $disabled_qv ] ) ) {
|
223 |
+
trigger_error( "Can't use '$disabled_qv' in an inner query", E_USER_WARNING );
|
224 |
+
}
|
225 |
+
}
|
226 |
+
$extra_qv['nopaging'] = true;
|
227 |
+
|
228 |
+
$q = $this->get_connected( array_keys( $posts ), $extra_qv, $direction );
|
229 |
+
|
230 |
+
foreach ( $q->posts as $inner_post ) {
|
231 |
+
if ( $inner_post->ID == $inner_post->p2p_from )
|
232 |
+
$outer_post_id = $inner_post->p2p_to;
|
233 |
+
elseif ( $inner_post->ID == $inner_post->p2p_to )
|
234 |
+
$outer_post_id = $inner_post->p2p_from;
|
235 |
+
else {
|
236 |
+
trigger_error( "Corrupted data for post $inner_post->ID", E_USER_WARNING );
|
237 |
+
continue;
|
238 |
+
}
|
239 |
+
|
240 |
+
if ( $outer_post_id == $inner_post->ID ) {
|
241 |
+
trigger_error( 'Post connected to itself.', E_USER_WARNING );
|
242 |
+
continue;
|
243 |
+
}
|
244 |
+
|
245 |
+
array_push( $posts[ $outer_post_id ]->$prop_name, $inner_post );
|
246 |
+
}
|
247 |
+
}
|
248 |
+
|
249 |
+
public function connect( $from, $to, $_direction = false ) {
|
250 |
+
$post_from = get_post( $from );
|
251 |
+
$post_to = get_post( $to );
|
252 |
+
|
253 |
+
if ( !$post_from || !$post_to ) {
|
254 |
+
return false;
|
255 |
+
}
|
256 |
+
|
257 |
+
$direction = $_direction ? $_direction : $this->get_direction( $from );
|
258 |
+
|
259 |
+
$args = array( $from, $to );
|
260 |
+
|
261 |
+
if ( 'to' == $direction )
|
262 |
+
$args = array_reverse( $args );
|
263 |
+
|
264 |
+
$p2p_id = false;
|
265 |
+
|
266 |
+
if ( $this->prevent_duplicates ) {
|
267 |
+
$p2p_ids = P2P_Storage::get( $args[0], $args[1], $this->data );
|
268 |
+
|
269 |
+
if ( !empty( $p2p_ids ) )
|
270 |
+
$p2p_id = $p2p_ids[0];
|
271 |
+
}
|
272 |
+
|
273 |
+
if ( !$p2p_id ) {
|
274 |
+
$p2p_id = P2P_Storage::connect( $args[0], $args[1], $this->data );
|
275 |
+
}
|
276 |
+
|
277 |
+
return $p2p_id;
|
278 |
+
}
|
279 |
+
|
280 |
+
public function disconnect( $post_id, $_direction = false ) {
|
281 |
+
$direction = $_direction ? $_direction : $this->get_direction( $post_id );
|
282 |
+
P2P_Storage::disconnect( $post_id, $direction, $this->data );
|
283 |
+
}
|
284 |
+
|
285 |
+
public function delete_connection( $p2p_id ) {
|
286 |
+
return P2P_Storage::delete( $p2p_id );
|
287 |
+
}
|
288 |
+
}
|
289 |
+
|
core/widget.php
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class P2P_Widget extends scbWidget {
|
4 |
+
|
5 |
+
protected $defaults = array(
|
6 |
+
'ctype' => false,
|
7 |
+
);
|
8 |
+
|
9 |
+
static function init( $file ) {
|
10 |
+
parent::init( __CLASS__, $file, 'p2p' );
|
11 |
+
}
|
12 |
+
|
13 |
+
function __construct() {
|
14 |
+
parent::__construct( 'p2p', __( 'Posts 2 Posts', P2P_TEXTDOMAIN ), array(
|
15 |
+
'description' => __( 'A list of posts connected to the current post', P2P_TEXTDOMAIN )
|
16 |
+
) );
|
17 |
+
}
|
18 |
+
|
19 |
+
function form( $instance ) {
|
20 |
+
if ( empty( $instance ) )
|
21 |
+
$instance = $this->defaults;
|
22 |
+
|
23 |
+
$ctypes = array_map( array( __CLASS__, 'ctype_label' ), P2P_Connection_Type::$instances );
|
24 |
+
|
25 |
+
echo $this->input( array(
|
26 |
+
'type' => 'select',
|
27 |
+
'name' => 'ctype',
|
28 |
+
'values' => $ctypes,
|
29 |
+
'desc' => __( 'Connection type:', P2P_TEXTDOMAIN )
|
30 |
+
), $instance );
|
31 |
+
}
|
32 |
+
|
33 |
+
function widget( $args, $instance ) {
|
34 |
+
if ( !is_singular() )
|
35 |
+
return;
|
36 |
+
|
37 |
+
$ctype = P2P_Connection_Type::get_instance( $instance['ctype'] );
|
38 |
+
if ( !$ctype )
|
39 |
+
return;
|
40 |
+
|
41 |
+
$direction = $ctype->get_direction( get_queried_object_id(), true );
|
42 |
+
if ( !$direction )
|
43 |
+
return;
|
44 |
+
|
45 |
+
$connected = $ctype->get_connected( get_queried_object_id() );
|
46 |
+
if ( !$connected->have_posts() )
|
47 |
+
return;
|
48 |
+
|
49 |
+
$title = $ctype->get_title( $direction );
|
50 |
+
|
51 |
+
if ( empty( $title ) ) {
|
52 |
+
$ptype = get_post_type_object( $ctype->get_other_post_type( $direction ) );
|
53 |
+
$title = sprintf( __( 'Related %s', P2P_TEXTDOMAIN ), $ptype->label );
|
54 |
+
}
|
55 |
+
|
56 |
+
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
|
57 |
+
|
58 |
+
extract( $args );
|
59 |
+
|
60 |
+
echo $before_widget;
|
61 |
+
|
62 |
+
if ( ! empty( $title ) )
|
63 |
+
echo $before_title . $title . $after_title;
|
64 |
+
|
65 |
+
p2p_list_posts( $connected );
|
66 |
+
|
67 |
+
echo $after_widget;
|
68 |
+
}
|
69 |
+
|
70 |
+
private static function ctype_label( $ctype ) {
|
71 |
+
foreach ( array( 'from', 'to' ) as $key ) {
|
72 |
+
$$key = implode( ', ', array_map( array( __CLASS__, 'cpt_label' ), $ctype->$key ) );
|
73 |
+
}
|
74 |
+
|
75 |
+
if ( $ctype->reciprocal || $ctype->to == $ctype->from )
|
76 |
+
$arrow = '↔';
|
77 |
+
else
|
78 |
+
$arrow = '→';
|
79 |
+
|
80 |
+
$label = "$from $arrow $to";
|
81 |
+
|
82 |
+
$title = $ctype->get_title( 'from' );
|
83 |
+
|
84 |
+
if ( $title )
|
85 |
+
$label .= " ($title)";
|
86 |
+
|
87 |
+
return $label;
|
88 |
+
}
|
89 |
+
|
90 |
+
private static function cpt_label( $post_type ) {
|
91 |
+
return get_post_type_object( $post_type )->label;
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
lang/posts-to-posts-fa_IR.mo
ADDED
Binary file
|
lang/posts-to-posts-fa_IR.po
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: \n"
|
4 |
+
"Report-Msgid-Bugs-To: http://wordpress.org/tag/p2p\n"
|
5 |
+
"POT-Creation-Date: 2011-09-24 13:12:56+00:00\n"
|
6 |
+
"PO-Revision-Date: 2011-09-25 19:00+0330\n"
|
7 |
+
"Last-Translator: geminorum <contact@geminorum.ir>\n"
|
8 |
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
|
13 |
+
"X-Poedit-SourceCharset: utf-8\n"
|
14 |
+
"X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
|
15 |
+
"X-Textdomain-Support: yes\n"
|
16 |
+
"X-Poedit-SearchPath-0: .\n"
|
17 |
+
|
18 |
+
#@ posts-to-posts
|
19 |
+
#: scb/AdminPage.php:163
|
20 |
+
msgid "Settings <strong>saved</strong>."
|
21 |
+
msgstr "تنظیمات <strong>ذخیره</strong> شد."
|
22 |
+
|
23 |
+
#@ posts-to-posts
|
24 |
+
#: scb/AdminPage.php:176
|
25 |
+
#: scb/AdminPage.php:187
|
26 |
+
msgid "Save Changes"
|
27 |
+
msgstr "ذخیره تغییرات"
|
28 |
+
|
29 |
+
#@ posts-to-posts
|
30 |
+
#: scb/AdminPage.php:348
|
31 |
+
msgid "Settings"
|
32 |
+
msgstr "تنظیمات"
|
33 |
+
|
34 |
+
#@ posts-to-posts
|
35 |
+
#: admin/fields.php:13
|
36 |
+
msgid "Create connection"
|
37 |
+
msgstr "برقراری ارتباط"
|
38 |
+
|
39 |
+
#@ posts-to-posts
|
40 |
+
#: admin/fields.php:25
|
41 |
+
msgid "Delete all connections"
|
42 |
+
msgstr "پاککردن همه ارتباطها"
|
43 |
+
|
44 |
+
#@ posts-to-posts
|
45 |
+
#: admin/fields.php:34
|
46 |
+
msgid "Delete connection"
|
47 |
+
msgstr "پاککردن ارتباط"
|
48 |
+
|
49 |
+
#@ posts-to-posts
|
50 |
+
#: admin/box.php:59
|
51 |
+
msgid "Are you sure you want to delete all connections?"
|
52 |
+
msgstr "از پاککردن همه ارتباطها اطمینان دارید؟"
|
53 |
+
|
54 |
+
#@ posts-to-posts
|
55 |
+
#: admin/box.php:69
|
56 |
+
#, php-format
|
57 |
+
msgid "Connected %s"
|
58 |
+
msgstr "%sی مرتبط"
|
59 |
+
|
60 |
+
#@ posts-to-posts
|
61 |
+
#: admin/box.php:116
|
62 |
+
msgid "Create connections:"
|
63 |
+
msgstr "برقراری ارتباط:"
|
64 |
+
|
65 |
+
#@ posts-to-posts
|
66 |
+
#: admin/box.php:125
|
67 |
+
msgid "Search"
|
68 |
+
msgstr "جستوجو"
|
69 |
+
|
70 |
+
#@ posts-to-posts
|
71 |
+
#: admin/box.php:133
|
72 |
+
msgid "View All"
|
73 |
+
msgstr "نمایش همه"
|
74 |
+
|
75 |
+
#@ posts-to-posts
|
76 |
+
#: admin/box.php:216
|
77 |
+
msgid "previous"
|
78 |
+
msgstr "قبلی"
|
79 |
+
|
80 |
+
#@ posts-to-posts
|
81 |
+
#: admin/box.php:217
|
82 |
+
msgid "next"
|
83 |
+
msgstr "بعدی"
|
84 |
+
|
85 |
+
#@ posts-to-posts
|
86 |
+
#: admin/box.php:218
|
87 |
+
msgid "of"
|
88 |
+
msgstr "از"
|
89 |
+
|
90 |
+
#@ posts-to-posts
|
91 |
+
#. translators: plugin header field 'Name'
|
92 |
+
#: core/widget.php:14
|
93 |
+
#: posts-to-posts.php:0
|
94 |
+
msgid "Posts 2 Posts"
|
95 |
+
msgstr "نوشتهها به نوشتهها"
|
96 |
+
|
97 |
+
#@ posts-to-posts
|
98 |
+
#: core/widget.php:15
|
99 |
+
msgid "A list of posts connected to the current post"
|
100 |
+
msgstr "فهرستی از همه نوشتههای مرتبط با این نوشته"
|
101 |
+
|
102 |
+
#@ posts-to-posts
|
103 |
+
#: core/widget.php:29
|
104 |
+
msgid "Connection type:"
|
105 |
+
msgstr "نوع ارتباط:"
|
106 |
+
|
107 |
+
#@ posts-to-posts
|
108 |
+
#: core/widget.php:53
|
109 |
+
#, php-format
|
110 |
+
msgid "Related %s"
|
111 |
+
msgstr "%sی وابسته"
|
112 |
+
|
113 |
+
#@ posts-to-posts
|
114 |
+
#. translators: plugin header field 'PluginURI'
|
115 |
+
#: posts-to-posts.php:0
|
116 |
+
msgid "http://scribu.net/wordpress/posts-to-posts"
|
117 |
+
msgstr ""
|
118 |
+
|
119 |
+
#@ posts-to-posts
|
120 |
+
#. translators: plugin header field 'Description'
|
121 |
+
#: posts-to-posts.php:0
|
122 |
+
msgid "Create many-to-many relationships between all types of posts."
|
123 |
+
msgstr "ارتباطهای تو در تو بین انواع نوشتهها برقرار کنید."
|
124 |
+
|
125 |
+
#@ posts-to-posts
|
126 |
+
#. translators: plugin header field 'Author'
|
127 |
+
#: posts-to-posts.php:0
|
128 |
+
msgid "scribu"
|
129 |
+
msgstr ""
|
130 |
+
|
131 |
+
#@ posts-to-posts
|
132 |
+
#. translators: plugin header field 'AuthorURI'
|
133 |
+
#: posts-to-posts.php:0
|
134 |
+
msgid "http://scribu.net/"
|
135 |
+
msgstr ""
|
136 |
+
|
137 |
+
#@ posts-to-posts
|
138 |
+
#. translators: plugin header field 'Version'
|
139 |
+
#: posts-to-posts.php:0
|
140 |
+
msgid "0.9.1-beta"
|
141 |
+
msgstr ""
|
142 |
+
|
lang/posts-to-posts-hr.mo
ADDED
Binary file
|
lang/posts-to-posts-hr.po
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2010
|
2 |
+
# This file is distributed under the same license as the package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"Project-Id-Version: \n"
|
6 |
+
"Report-Msgid-Bugs-To: http://wordpress.org/tag/p2p\n"
|
7 |
+
"POT-Creation-Date: 2011-09-18 21:35:49+00:00\n"
|
8 |
+
"MIME-Version: 1.0\n"
|
9 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
+
"Content-Transfer-Encoding: 8bit\n"
|
11 |
+
"PO-Revision-Date: 2011-09-19 12:57+0200\n"
|
12 |
+
"Last-Translator: scribu <scribu@gmail.com>\n"
|
13 |
+
"Language-Team: \n"
|
14 |
+
"X-Poedit-Language: Croatian\n"
|
15 |
+
"X-Poedit-Country: CROATIA\n"
|
16 |
+
|
17 |
+
#: scb/AdminPage.php:163
|
18 |
+
msgid "Settings <strong>saved</strong>."
|
19 |
+
msgstr "Postavke <strong>spremljene</strong>."
|
20 |
+
|
21 |
+
#: scb/AdminPage.php:176
|
22 |
+
#: scb/AdminPage.php:187
|
23 |
+
msgid "Save Changes"
|
24 |
+
msgstr "Spremi Promjene"
|
25 |
+
|
26 |
+
#: scb/AdminPage.php:348
|
27 |
+
msgid "Settings"
|
28 |
+
msgstr "Postavke"
|
29 |
+
|
30 |
+
#: admin/fields.php:13
|
31 |
+
msgid "Create connection"
|
32 |
+
msgstr "Izradi poveznicu"
|
33 |
+
|
34 |
+
#: admin/fields.php:25
|
35 |
+
msgid "Delete all connections"
|
36 |
+
msgstr "Izbriši sve poveznice"
|
37 |
+
|
38 |
+
#: admin/fields.php:34
|
39 |
+
msgid "Delete connection"
|
40 |
+
msgstr "Obriši poveznicu"
|
41 |
+
|
42 |
+
#: admin/box.php:58
|
43 |
+
msgid "Are you sure you want to delete all connections?"
|
44 |
+
msgstr "Sigurno želiš obrisati sve poveznice"
|
45 |
+
|
46 |
+
#: admin/box.php:68
|
47 |
+
msgid "Connected %s"
|
48 |
+
msgstr "Povezano %s"
|
49 |
+
|
50 |
+
#: admin/box.php:115
|
51 |
+
msgid "Create connections:"
|
52 |
+
msgstr "Izradi poveznice:"
|
53 |
+
|
54 |
+
#: admin/box.php:124
|
55 |
+
msgid "Search"
|
56 |
+
msgstr "Pretraži"
|
57 |
+
|
58 |
+
#: admin/box.php:132
|
59 |
+
msgid "View All"
|
60 |
+
msgstr "Pregledaj Sve"
|
61 |
+
|
62 |
+
#: admin/box.php:215
|
63 |
+
msgid "previous"
|
64 |
+
msgstr "prethodna"
|
65 |
+
|
66 |
+
#: admin/box.php:216
|
67 |
+
msgid "next"
|
68 |
+
msgstr "slijedeća"
|
69 |
+
|
70 |
+
#: admin/box.php:217
|
71 |
+
msgid "of"
|
72 |
+
msgstr "od"
|
73 |
+
|
lang/posts-to-posts-pt_BR.mo
ADDED
Binary file
|
lang/posts-to-posts-pt_BR.po
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2010
|
2 |
+
# This file is distributed under the same license as the package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"Project-Id-Version: Posts 2 Posts 0.4\n"
|
6 |
+
"Report-Msgid-Bugs-To: http://wordpress.org/tag/p2p\n"
|
7 |
+
"POT-Creation-Date: 2011-07-22 13:03:03+00:00\n"
|
8 |
+
"MIME-Version: 1.0\n"
|
9 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
+
"Content-Transfer-Encoding: 8bit\n"
|
11 |
+
"PO-Revision-Date: 2011-08-31 17:26-0300\n"
|
12 |
+
"Last-Translator: Marcelo Minholi <minholi@gmail.com>\n"
|
13 |
+
"Language-Team: \n"
|
14 |
+
"X-Poedit-Language: Portuguese\n"
|
15 |
+
"X-Poedit-Country: BRAZIL\n"
|
16 |
+
"X-Poedit-SourceCharset: utf-8\n"
|
17 |
+
|
18 |
+
#: scb/AdminPage.php:161
|
19 |
+
msgid "Settings <strong>saved</strong>."
|
20 |
+
msgstr "Configurações <strong>salvas</strong>."
|
21 |
+
|
22 |
+
#: scb/AdminPage.php:174
|
23 |
+
#: scb/AdminPage.php:185
|
24 |
+
msgid "Save Changes"
|
25 |
+
msgstr "Salvar Alterações"
|
26 |
+
|
27 |
+
#: scb/AdminPage.php:367
|
28 |
+
msgid "Settings"
|
29 |
+
msgstr "Configurações"
|
30 |
+
|
31 |
+
#: ui/box.php:14
|
32 |
+
msgid "Are you sure you want to delete all connections?"
|
33 |
+
msgstr "Você tem certeza que quer apagar todas as relações?"
|
34 |
+
|
35 |
+
#: ui/box.php:33
|
36 |
+
msgid "Create connections:"
|
37 |
+
msgstr "Criar relações:"
|
38 |
+
|
39 |
+
#: ui/box.php:64
|
40 |
+
msgid "Search"
|
41 |
+
msgstr "Buscar"
|
42 |
+
|
43 |
+
#: ui/box.php:72
|
44 |
+
msgid "Recent"
|
45 |
+
msgstr "Recentes"
|
46 |
+
|
47 |
+
#: ui/box.php:148
|
48 |
+
msgid "Previous"
|
49 |
+
msgstr "Anteriores"
|
50 |
+
|
51 |
+
#: ui/box.php:149
|
52 |
+
msgid "Next"
|
53 |
+
msgstr "Próximas"
|
54 |
+
|
55 |
+
#: ui/box.php:150
|
56 |
+
msgid "of"
|
57 |
+
msgstr "de"
|
58 |
+
|
59 |
+
#: ui/box.php:182
|
60 |
+
msgid "Create connection"
|
61 |
+
msgstr "Criar relação"
|
62 |
+
|
63 |
+
#: ui/box.php:191
|
64 |
+
msgid "Delete connection"
|
65 |
+
msgstr "Apagar relação"
|
66 |
+
|
67 |
+
#: ui/box.php:199
|
68 |
+
msgid "Delete all connections"
|
69 |
+
msgstr "Apagar todas as relações"
|
70 |
+
|
71 |
+
#: ui.php:33
|
72 |
+
msgid "Connected %s"
|
73 |
+
msgstr "%s Relacionado(a)"
|
74 |
+
|
lang/posts-to-posts-ro_RO.mo
CHANGED
Binary file
|
lang/posts-to-posts-ro_RO.po
CHANGED
@@ -7,8 +7,8 @@ msgid ""
|
|
7 |
msgstr ""
|
8 |
"Project-Id-Version: Posts 2 Posts\n"
|
9 |
"Report-Msgid-Bugs-To: http://wordpress.org/tag/p2p\n"
|
10 |
-
"POT-Creation-Date: 2011-
|
11 |
-
"PO-Revision-Date: 2011-
|
12 |
"Last-Translator: scribu <scribu@gmail.com>\n"
|
13 |
"Language-Team: ROMANIAN <LL@li.org>\n"
|
14 |
"Language: \n"
|
@@ -16,62 +16,84 @@ msgstr ""
|
|
16 |
"Content-Type: text/plain; charset=UTF-8\n"
|
17 |
"Content-Transfer-Encoding: 8bit\n"
|
18 |
|
19 |
-
#: scb/AdminPage.php:
|
20 |
msgid "Settings <strong>saved</strong>."
|
21 |
msgstr "Setări <strong>salvate</strong>."
|
22 |
|
23 |
-
#: scb/AdminPage.php:
|
24 |
-
#: scb/AdminPage.php:
|
25 |
msgid "Save Changes"
|
26 |
msgstr "Salvează schimbările"
|
27 |
|
28 |
-
#: scb/AdminPage.php:
|
29 |
msgid "Settings"
|
30 |
msgstr "Setări"
|
31 |
|
32 |
-
#:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
msgid "Are you sure you want to delete all connections?"
|
34 |
msgstr "Sigur vreți să ștergeți toate conexiunile?"
|
35 |
|
36 |
-
#:
|
|
|
|
|
|
|
|
|
37 |
msgid "Create connections:"
|
38 |
msgstr "Creează conexiuni:"
|
39 |
|
40 |
-
#:
|
41 |
msgid "Search"
|
42 |
msgstr "Căutare"
|
43 |
|
44 |
-
#:
|
45 |
-
msgid "
|
46 |
-
msgstr "
|
47 |
|
48 |
-
#:
|
49 |
-
msgid "
|
50 |
-
msgstr "
|
51 |
|
52 |
-
#:
|
53 |
-
msgid "
|
54 |
-
msgstr "
|
55 |
|
56 |
-
#:
|
57 |
msgid "of"
|
58 |
msgstr "din"
|
59 |
|
60 |
-
#:
|
61 |
-
msgid "
|
62 |
-
msgstr "
|
63 |
|
64 |
-
#:
|
65 |
-
msgid "
|
66 |
-
msgstr "
|
67 |
|
68 |
-
#:
|
69 |
-
msgid "
|
70 |
-
msgstr "
|
71 |
|
72 |
-
#:
|
73 |
-
msgid "
|
74 |
-
msgstr "%s
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
#~ msgid ""
|
77 |
#~ "Start typing the title of a post you want to connect and then click on to "
|
7 |
msgstr ""
|
8 |
"Project-Id-Version: Posts 2 Posts\n"
|
9 |
"Report-Msgid-Bugs-To: http://wordpress.org/tag/p2p\n"
|
10 |
+
"POT-Creation-Date: 2011-09-24 13:12:56+00:00\n"
|
11 |
+
"PO-Revision-Date: 2011-09-24 16:15+0200\n"
|
12 |
"Last-Translator: scribu <scribu@gmail.com>\n"
|
13 |
"Language-Team: ROMANIAN <LL@li.org>\n"
|
14 |
"Language: \n"
|
16 |
"Content-Type: text/plain; charset=UTF-8\n"
|
17 |
"Content-Transfer-Encoding: 8bit\n"
|
18 |
|
19 |
+
#: scb/AdminPage.php:163
|
20 |
msgid "Settings <strong>saved</strong>."
|
21 |
msgstr "Setări <strong>salvate</strong>."
|
22 |
|
23 |
+
#: scb/AdminPage.php:176
|
24 |
+
#: scb/AdminPage.php:187
|
25 |
msgid "Save Changes"
|
26 |
msgstr "Salvează schimbările"
|
27 |
|
28 |
+
#: scb/AdminPage.php:348
|
29 |
msgid "Settings"
|
30 |
msgstr "Setări"
|
31 |
|
32 |
+
#: admin/fields.php:13
|
33 |
+
msgid "Create connection"
|
34 |
+
msgstr "Crează conexiune"
|
35 |
+
|
36 |
+
#: admin/fields.php:25
|
37 |
+
msgid "Delete all connections"
|
38 |
+
msgstr "Șterge toate conexiunile"
|
39 |
+
|
40 |
+
#: admin/fields.php:34
|
41 |
+
msgid "Delete connection"
|
42 |
+
msgstr "Șterge conexiune"
|
43 |
+
|
44 |
+
#: admin/box.php:59
|
45 |
msgid "Are you sure you want to delete all connections?"
|
46 |
msgstr "Sigur vreți să ștergeți toate conexiunile?"
|
47 |
|
48 |
+
#: admin/box.php:69
|
49 |
+
msgid "Connected %s"
|
50 |
+
msgstr "%s conectate"
|
51 |
+
|
52 |
+
#: admin/box.php:116
|
53 |
msgid "Create connections:"
|
54 |
msgstr "Creează conexiuni:"
|
55 |
|
56 |
+
#: admin/box.php:125
|
57 |
msgid "Search"
|
58 |
msgstr "Căutare"
|
59 |
|
60 |
+
#: admin/box.php:133
|
61 |
+
msgid "View All"
|
62 |
+
msgstr "Vezi toate"
|
63 |
|
64 |
+
#: admin/box.php:216
|
65 |
+
msgid "previous"
|
66 |
+
msgstr "anterioare"
|
67 |
|
68 |
+
#: admin/box.php:217
|
69 |
+
msgid "next"
|
70 |
+
msgstr "următoare"
|
71 |
|
72 |
+
#: admin/box.php:218
|
73 |
msgid "of"
|
74 |
msgstr "din"
|
75 |
|
76 |
+
#: core/widget.php:14
|
77 |
+
msgid "Posts 2 Posts"
|
78 |
+
msgstr "Posts 2 Posts"
|
79 |
|
80 |
+
#: core/widget.php:15
|
81 |
+
msgid "A list of posts connected to the current post"
|
82 |
+
msgstr "O lista de postări conectate la postarea curentă"
|
83 |
|
84 |
+
#: core/widget.php:29
|
85 |
+
msgid "Connection type:"
|
86 |
+
msgstr "Tipul conexiunii:"
|
87 |
|
88 |
+
#: core/widget.php:53
|
89 |
+
msgid "Related %s"
|
90 |
+
msgstr "%s înrudite"
|
91 |
+
|
92 |
+
#~ msgid "Recent"
|
93 |
+
#~ msgstr "Recente"
|
94 |
+
|
95 |
+
#~ msgid "Next"
|
96 |
+
#~ msgstr "Următoare"
|
97 |
|
98 |
#~ msgid ""
|
99 |
#~ "Start typing the title of a post you want to connect and then click on to "
|
lang/posts-to-posts-ru_RU.mo
ADDED
Binary file
|
lang/posts-to-posts-ru_RU.po
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: Posts-to-posts\n"
|
4 |
+
"Report-Msgid-Bugs-To: http://wordpress.org/tag/p2p\n"
|
5 |
+
"POT-Creation-Date: 2011-09-24 13:12:56+00:00\n"
|
6 |
+
"PO-Revision-Date: \n"
|
7 |
+
"Last-Translator: foralien <nordworldofann@gmail.com>\n"
|
8 |
+
"Language-Team: foalien\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
|
13 |
+
#: scb/AdminPage.php:163
|
14 |
+
msgid "Settings <strong>saved</strong>."
|
15 |
+
msgstr "Настройки <strong>сохранены</strong>."
|
16 |
+
|
17 |
+
#: scb/AdminPage.php:176
|
18 |
+
#: scb/AdminPage.php:187
|
19 |
+
msgid "Save Changes"
|
20 |
+
msgstr "Сохранить изменения"
|
21 |
+
|
22 |
+
#: scb/AdminPage.php:348
|
23 |
+
msgid "Settings"
|
24 |
+
msgstr "Настройки"
|
25 |
+
|
26 |
+
#: admin/fields.php:13
|
27 |
+
msgid "Create connection"
|
28 |
+
msgstr "Создать взаимосвязь"
|
29 |
+
|
30 |
+
#: admin/fields.php:25
|
31 |
+
msgid "Delete all connections"
|
32 |
+
msgstr "Удалить все взаимосвязи"
|
33 |
+
|
34 |
+
#: admin/fields.php:34
|
35 |
+
msgid "Delete connection"
|
36 |
+
msgstr "Удалить взаимосвязь"
|
37 |
+
|
38 |
+
#: admin/box.php:59
|
39 |
+
msgid "Are you sure you want to delete all connections?"
|
40 |
+
msgstr "Вы уверены, что хотите удалить все взаимосвязи?"
|
41 |
+
|
42 |
+
#: admin/box.php:69
|
43 |
+
msgid "Connected %s"
|
44 |
+
msgstr "Связанные %s"
|
45 |
+
|
46 |
+
#: admin/box.php:116
|
47 |
+
msgid "Create connections:"
|
48 |
+
msgstr "Создать взаимосвязи:"
|
49 |
+
|
50 |
+
#: admin/box.php:125
|
51 |
+
msgid "Search"
|
52 |
+
msgstr "Поиск"
|
53 |
+
|
54 |
+
#: admin/box.php:133
|
55 |
+
msgid "View All"
|
56 |
+
msgstr "Все"
|
57 |
+
|
58 |
+
#: admin/box.php:216
|
59 |
+
msgid "previous"
|
60 |
+
msgstr "пред."
|
61 |
+
|
62 |
+
#: admin/box.php:217
|
63 |
+
msgid "next"
|
64 |
+
msgstr "след."
|
65 |
+
|
66 |
+
#: admin/box.php:218
|
67 |
+
msgid "of"
|
68 |
+
msgstr "из"
|
69 |
+
|
70 |
+
#: core/widget.php:14
|
71 |
+
msgid "Posts 2 Posts"
|
72 |
+
msgstr "Posts 2 Posts"
|
73 |
+
|
74 |
+
#: core/widget.php:15
|
75 |
+
msgid "A list of posts connected to the current post"
|
76 |
+
msgstr "Список всех записей, связанных с текущей"
|
77 |
+
|
78 |
+
#: core/widget.php:29
|
79 |
+
msgid "Connection type:"
|
80 |
+
msgstr "Тип взаимосвязи:"
|
81 |
+
|
82 |
+
#: core/widget.php:53
|
83 |
+
msgid "Related %s"
|
84 |
+
msgstr "Связанные %s"
|
85 |
+
|
86 |
+
#~ msgid "Recent"
|
87 |
+
#~ msgstr "Недавние"
|
88 |
+
|
lang/posts-to-posts.pot
CHANGED
@@ -4,7 +4,7 @@ msgid ""
|
|
4 |
msgstr ""
|
5 |
"Project-Id-Version: \n"
|
6 |
"Report-Msgid-Bugs-To: http://wordpress.org/tag/p2p\n"
|
7 |
-
"POT-Creation-Date: 2011-
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
@@ -12,58 +12,74 @@ msgstr ""
|
|
12 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
|
15 |
-
#: scb/AdminPage.php:
|
16 |
msgid "Settings <strong>saved</strong>."
|
17 |
msgstr ""
|
18 |
|
19 |
-
#: scb/AdminPage.php:
|
20 |
msgid "Save Changes"
|
21 |
msgstr ""
|
22 |
|
23 |
-
#: scb/AdminPage.php:
|
24 |
msgid "Settings"
|
25 |
msgstr ""
|
26 |
|
27 |
-
#:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
msgid "Are you sure you want to delete all connections?"
|
29 |
msgstr ""
|
30 |
|
31 |
-
#:
|
|
|
|
|
|
|
|
|
32 |
msgid "Create connections:"
|
33 |
msgstr ""
|
34 |
|
35 |
-
#:
|
36 |
msgid "Search"
|
37 |
msgstr ""
|
38 |
|
39 |
-
#:
|
40 |
-
msgid "
|
41 |
msgstr ""
|
42 |
|
43 |
-
#:
|
44 |
-
msgid "
|
45 |
msgstr ""
|
46 |
|
47 |
-
#:
|
48 |
-
msgid "
|
49 |
msgstr ""
|
50 |
|
51 |
-
#:
|
52 |
msgid "of"
|
53 |
msgstr ""
|
54 |
|
55 |
-
#:
|
56 |
-
msgid "
|
57 |
msgstr ""
|
58 |
|
59 |
-
#:
|
60 |
-
msgid "
|
61 |
msgstr ""
|
62 |
|
63 |
-
#:
|
64 |
-
msgid "
|
65 |
msgstr ""
|
66 |
|
67 |
-
#:
|
68 |
-
msgid "
|
69 |
msgstr ""
|
4 |
msgstr ""
|
5 |
"Project-Id-Version: \n"
|
6 |
"Report-Msgid-Bugs-To: http://wordpress.org/tag/p2p\n"
|
7 |
+
"POT-Creation-Date: 2011-09-24 13:12:56+00:00\n"
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
12 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
|
15 |
+
#: scb/AdminPage.php:163
|
16 |
msgid "Settings <strong>saved</strong>."
|
17 |
msgstr ""
|
18 |
|
19 |
+
#: scb/AdminPage.php:176 scb/AdminPage.php:187
|
20 |
msgid "Save Changes"
|
21 |
msgstr ""
|
22 |
|
23 |
+
#: scb/AdminPage.php:348
|
24 |
msgid "Settings"
|
25 |
msgstr ""
|
26 |
|
27 |
+
#: admin/fields.php:13
|
28 |
+
msgid "Create connection"
|
29 |
+
msgstr ""
|
30 |
+
|
31 |
+
#: admin/fields.php:25
|
32 |
+
msgid "Delete all connections"
|
33 |
+
msgstr ""
|
34 |
+
|
35 |
+
#: admin/fields.php:34
|
36 |
+
msgid "Delete connection"
|
37 |
+
msgstr ""
|
38 |
+
|
39 |
+
#: admin/box.php:59
|
40 |
msgid "Are you sure you want to delete all connections?"
|
41 |
msgstr ""
|
42 |
|
43 |
+
#: admin/box.php:69
|
44 |
+
msgid "Connected %s"
|
45 |
+
msgstr ""
|
46 |
+
|
47 |
+
#: admin/box.php:116
|
48 |
msgid "Create connections:"
|
49 |
msgstr ""
|
50 |
|
51 |
+
#: admin/box.php:125
|
52 |
msgid "Search"
|
53 |
msgstr ""
|
54 |
|
55 |
+
#: admin/box.php:133
|
56 |
+
msgid "View All"
|
57 |
msgstr ""
|
58 |
|
59 |
+
#: admin/box.php:216
|
60 |
+
msgid "previous"
|
61 |
msgstr ""
|
62 |
|
63 |
+
#: admin/box.php:217
|
64 |
+
msgid "next"
|
65 |
msgstr ""
|
66 |
|
67 |
+
#: admin/box.php:218
|
68 |
msgid "of"
|
69 |
msgstr ""
|
70 |
|
71 |
+
#: core/widget.php:14
|
72 |
+
msgid "Posts 2 Posts"
|
73 |
msgstr ""
|
74 |
|
75 |
+
#: core/widget.php:15
|
76 |
+
msgid "A list of posts connected to the current post"
|
77 |
msgstr ""
|
78 |
|
79 |
+
#: core/widget.php:29
|
80 |
+
msgid "Connection type:"
|
81 |
msgstr ""
|
82 |
|
83 |
+
#: core/widget.php:53
|
84 |
+
msgid "Related %s"
|
85 |
msgstr ""
|
mustache/examples/child_context/ChildContext.php
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class ChildContext extends Mustache {
|
4 |
-
public $parent = array(
|
5 |
-
'child' => 'child works',
|
6 |
-
);
|
7 |
-
|
8 |
-
public $grandparent = array(
|
9 |
-
'parent' => array(
|
10 |
-
'child' => 'grandchild works',
|
11 |
-
),
|
12 |
-
);
|
13 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/child_context/child_context.mustache
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
<h1>{{#parent}}{{child}}{{/parent}}</h1>
|
2 |
-
<h2>{{#grandparent}}{{#parent}}{{child}}{{/parent}}{{/grandparent}}</h2>
|
|
|
|
mustache/examples/child_context/child_context.txt
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
<h1>child works</h1>
|
2 |
-
<h2>grandchild works</h2>
|
|
|
|
mustache/examples/comments/Comments.php
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Comments extends Mustache {
|
4 |
-
public function title() {
|
5 |
-
return 'A Comedy of Errors';
|
6 |
-
}
|
7 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/comments/comments.mustache
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<h1>{{title}}{{! just something interesting... #or ^not... }}</h1>
|
|
mustache/examples/comments/comments.txt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<h1>A Comedy of Errors</h1>
|
|
mustache/examples/complex/complex.mustache
DELETED
@@ -1,16 +0,0 @@
|
|
1 |
-
<h1>{{header}}</h1>
|
2 |
-
{{#notEmpty}}
|
3 |
-
<ul>
|
4 |
-
{{#item}}
|
5 |
-
{{#current}}
|
6 |
-
<li><strong>{{name}}</strong></li>
|
7 |
-
{{/current}}
|
8 |
-
{{^current}}
|
9 |
-
<li><a href="{{url}}">{{name}}</a></li>
|
10 |
-
{{/current}}
|
11 |
-
{{/item}}
|
12 |
-
</ul>
|
13 |
-
{{/notEmpty}}
|
14 |
-
{{#isEmpty}}
|
15 |
-
<p>The list is empty.</p>
|
16 |
-
{{/isEmpty}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/complex/complex.php
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Complex extends Mustache {
|
4 |
-
public $header = 'Colors';
|
5 |
-
|
6 |
-
public $item = array(
|
7 |
-
array('name' => 'red', 'current' => true, 'url' => '#Red'),
|
8 |
-
array('name' => 'green', 'current' => false, 'url' => '#Green'),
|
9 |
-
array('name' => 'blue', 'current' => false, 'url' => '#Blue'),
|
10 |
-
);
|
11 |
-
|
12 |
-
public function notEmpty() {
|
13 |
-
return !($this->isEmpty());
|
14 |
-
}
|
15 |
-
|
16 |
-
public function isEmpty() {
|
17 |
-
return count($this->item) === 0;
|
18 |
-
}
|
19 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/complex/complex.txt
DELETED
@@ -1,6 +0,0 @@
|
|
1 |
-
<h1>Colors</h1>
|
2 |
-
<ul>
|
3 |
-
<li><strong>red</strong></li>
|
4 |
-
<li><a href="#Green">green</a></li>
|
5 |
-
<li><a href="#Blue">blue</a></li>
|
6 |
-
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/delimiters/Delimiters.php
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Delimiters extends Mustache {
|
4 |
-
public $start = "It worked the first time.";
|
5 |
-
|
6 |
-
public function middle() {
|
7 |
-
return array(
|
8 |
-
array('item' => "And it worked the second time."),
|
9 |
-
array('item' => "As well as the third."),
|
10 |
-
);
|
11 |
-
}
|
12 |
-
|
13 |
-
public $final = "Then, surprisingly, it worked the final time.";
|
14 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/delimiters/delimiters.mustache
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
{{=<% %>=}}
|
2 |
-
* <% start %>
|
3 |
-
<%=| |=%>
|
4 |
-
|# middle |
|
5 |
-
* | item |
|
6 |
-
|/ middle |
|
7 |
-
|={{ }}=|
|
8 |
-
* {{ final }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/delimiters/delimiters.txt
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
* It worked the first time.
|
2 |
-
* And it worked the second time.
|
3 |
-
* As well as the third.
|
4 |
-
* Then, surprisingly, it worked the final time.
|
|
|
|
|
|
|
|
mustache/examples/dot_notation/DotNotation.php
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* DotNotation example class. Uses DOT_NOTATION pragma.
|
5 |
-
*
|
6 |
-
* @extends Mustache
|
7 |
-
*/
|
8 |
-
class DotNotation extends Mustache {
|
9 |
-
public $person = array(
|
10 |
-
'name' => array('first' => 'Chris', 'last' => 'Firescythe'),
|
11 |
-
'age' => 24,
|
12 |
-
'hometown' => array(
|
13 |
-
'city' => 'Cincinnati',
|
14 |
-
'state' => 'OH',
|
15 |
-
)
|
16 |
-
);
|
17 |
-
|
18 |
-
public $normal = 'Normal';
|
19 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/dot_notation/dot_notation.mustache
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
* {{person.name.first}} {{person.name.last}}
|
2 |
-
* {{person.age}}
|
3 |
-
* {{person.hometown.city}}, {{person.hometown.state}}
|
4 |
-
* {{normal}}
|
|
|
|
|
|
|
|
mustache/examples/dot_notation/dot_notation.txt
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
* Chris Firescythe
|
2 |
-
* 24
|
3 |
-
* Cincinnati, OH
|
4 |
-
* Normal
|
|
|
|
|
|
|
|
mustache/examples/double_section/DoubleSection.php
DELETED
@@ -1,9 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class DoubleSection extends Mustache {
|
4 |
-
public function t() {
|
5 |
-
return true;
|
6 |
-
}
|
7 |
-
|
8 |
-
public $two = "second";
|
9 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/double_section/double_section.mustache
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
{{#t}}
|
2 |
-
* first
|
3 |
-
{{/t}}
|
4 |
-
* {{two}}
|
5 |
-
{{#t}}
|
6 |
-
* third
|
7 |
-
{{/t}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/double_section/double_section.txt
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
* first
|
2 |
-
* second
|
3 |
-
* third
|
|
|
|
|
|
mustache/examples/escaped/Escaped.php
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Escaped extends Mustache {
|
4 |
-
public $title = '"Bear" > "Shark"';
|
5 |
-
}
|
|
|
|
|
|
|
|
|
|
mustache/examples/escaped/escaped.mustache
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<h1>{{title}}</h1>
|
|
mustache/examples/escaped/escaped.txt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<h1>"Bear" > "Shark"</h1>
|
|
mustache/examples/grand_parent_context/GrandParentContext.php
DELETED
@@ -1,24 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class GrandParentContext extends Mustache {
|
4 |
-
public $grand_parent_id = 'grand_parent1';
|
5 |
-
public $parent_contexts = array();
|
6 |
-
|
7 |
-
public function __construct() {
|
8 |
-
parent::__construct();
|
9 |
-
|
10 |
-
$this->parent_contexts[] = array('parent_id' => 'parent1', 'child_contexts' => array(
|
11 |
-
array('child_id' => 'parent1-child1'),
|
12 |
-
array('child_id' => 'parent1-child2')
|
13 |
-
));
|
14 |
-
|
15 |
-
$parent2 = new stdClass();
|
16 |
-
$parent2->parent_id = 'parent2';
|
17 |
-
$parent2->child_contexts = array(
|
18 |
-
array('child_id' => 'parent2-child1'),
|
19 |
-
array('child_id' => 'parent2-child2')
|
20 |
-
);
|
21 |
-
|
22 |
-
$this->parent_contexts[] = $parent2;
|
23 |
-
}
|
24 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/grand_parent_context/grand_parent_context.mustache
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
{{grand_parent_id}}
|
2 |
-
{{#parent_contexts}}
|
3 |
-
{{parent_id}} ({{grand_parent_id}})
|
4 |
-
{{#child_contexts}}
|
5 |
-
{{child_id}} ({{parent_id}} << {{grand_parent_id}})
|
6 |
-
{{/child_contexts}}
|
7 |
-
{{/parent_contexts}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/grand_parent_context/grand_parent_context.txt
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
grand_parent1
|
2 |
-
parent1 (grand_parent1)
|
3 |
-
parent1-child1 (parent1 << grand_parent1)
|
4 |
-
parent1-child2 (parent1 << grand_parent1)
|
5 |
-
parent2 (grand_parent1)
|
6 |
-
parent2-child1 (parent2 << grand_parent1)
|
7 |
-
parent2-child2 (parent2 << grand_parent1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/implicit_iterator/ImplicitIterator.php
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class ImplicitIterator extends Mustache {
|
4 |
-
protected $data = array('Donkey Kong', 'Luigi', 'Mario', 'Peach', 'Yoshi');
|
5 |
-
}
|
|
|
|
|
|
|
|
|
|
mustache/examples/implicit_iterator/implicit_iterator.mustache
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
{{#data}}
|
2 |
-
* {{.}}
|
3 |
-
{{/data}}
|
|
|
|
|
|
mustache/examples/implicit_iterator/implicit_iterator.txt
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
* Donkey Kong
|
2 |
-
* Luigi
|
3 |
-
* Mario
|
4 |
-
* Peach
|
5 |
-
* Yoshi
|
|
|
|
|
|
|
|
|
|
mustache/examples/inverted_double_section/InvertedDoubleSection.php
DELETED
@@ -1,6 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class InvertedDoubleSection extends Mustache {
|
4 |
-
public $t = false;
|
5 |
-
public $two = 'second';
|
6 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/inverted_double_section/inverted_double_section.mustache
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
{{^t}}
|
2 |
-
* first
|
3 |
-
{{/t}}
|
4 |
-
* {{two}}
|
5 |
-
{{^t}}
|
6 |
-
* third
|
7 |
-
{{/t}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/inverted_double_section/inverted_double_section.txt
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
* first
|
2 |
-
* second
|
3 |
-
* third
|
|
|
|
|
|
mustache/examples/inverted_section/InvertedSection.php
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class InvertedSection extends Mustache {
|
4 |
-
public $repo = array();
|
5 |
-
}
|
|
|
|
|
|
|
|
|
|
mustache/examples/inverted_section/inverted_section.mustache
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
{{#repo}}<b>{{name}}</b>{{/repo}}
|
2 |
-
{{^repo}}No repos :({{/repo}}
|
|
|
|
mustache/examples/inverted_section/inverted_section.txt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
No repos :(
|
|
mustache/examples/partials/Partials.php
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Partials extends Mustache {
|
4 |
-
public $name = 'ilmich';
|
5 |
-
public $data = array(
|
6 |
-
array('name' => 'federica', 'age' => 27, 'gender' => 'female'),
|
7 |
-
array('name' => 'marco', 'age' => 32, 'gender' => 'male'),
|
8 |
-
);
|
9 |
-
|
10 |
-
protected $_partials = array(
|
11 |
-
'children' => "{{#data}}{{name}} - {{age}} - {{gender}}\n{{/data}}",
|
12 |
-
);
|
13 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/partials/partials.mustache
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
Children of {{name}}:
|
2 |
-
{{>children}}
|
|
|
|
mustache/examples/partials/partials.txt
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
Children of ilmich:
|
2 |
-
federica - 27 - female
|
3 |
-
marco - 32 - male
|
|
|
|
|
|
mustache/examples/partials_with_view_class/PartialsWithViewClass.php
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class PartialsWithViewClass extends Mustache {
|
4 |
-
public function __construct($template = null, $view = null, $partials = null) {
|
5 |
-
// Use an object of an arbitrary class as a View for this Mustache instance:
|
6 |
-
$view = new StdClass();
|
7 |
-
$view->name = 'ilmich';
|
8 |
-
$view->data = array(
|
9 |
-
array('name' => 'federica', 'age' => 27, 'gender' => 'female'),
|
10 |
-
array('name' => 'marco', 'age' => 32, 'gender' => 'male'),
|
11 |
-
);
|
12 |
-
|
13 |
-
$partials = array(
|
14 |
-
'children' => "{{#data}}{{name}} - {{age}} - {{gender}}\n{{/data}}",
|
15 |
-
);
|
16 |
-
|
17 |
-
parent::__construct($template, $view, $partials);
|
18 |
-
}
|
19 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/partials_with_view_class/partials_with_view_class.mustache
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
Children of {{name}}:
|
2 |
-
{{>children}}
|
|
|
|
mustache/examples/partials_with_view_class/partials_with_view_class.txt
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
Children of ilmich:
|
2 |
-
federica - 27 - female
|
3 |
-
marco - 32 - male
|
|
|
|
|
|
mustache/examples/pragma_unescaped/PragmaUnescaped.php
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class PragmaUnescaped extends Mustache {
|
4 |
-
public $vs = 'Bear > Shark';
|
5 |
-
}
|
|
|
|
|
|
|
|
|
|
mustache/examples/pragma_unescaped/pragma_unescaped.mustache
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
{{%UNESCAPED}}
|
2 |
-
{{vs}}
|
3 |
-
{{{vs}}}
|
|
|
|
|
|
mustache/examples/pragma_unescaped/pragma_unescaped.txt
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
Bear > Shark
|
2 |
-
Bear > Shark
|
|
|
|
mustache/examples/pragmas_in_partials/PragmasInPartials.php
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class PragmasInPartials extends Mustache {
|
4 |
-
public $say = '< RAWR!! >';
|
5 |
-
protected $_partials = array(
|
6 |
-
'dinosaur' => '{{say}}'
|
7 |
-
);
|
8 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/pragmas_in_partials/pragmas_in_partials.mustache
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
{{%UNESCAPED}}
|
2 |
-
{{say}}
|
3 |
-
{{>dinosaur}}
|
|
|
|
|
|
mustache/examples/pragmas_in_partials/pragmas_in_partials.txt
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
< RAWR!! >
|
2 |
-
< RAWR!! >
|
|
|
|
mustache/examples/recursive_partials/RecursivePartials.php
DELETED
@@ -1,16 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class RecursivePartials extends Mustache {
|
4 |
-
protected $_partials = array(
|
5 |
-
'child' => " > {{ name }}{{#child}}{{>child}}{{/child}}",
|
6 |
-
);
|
7 |
-
|
8 |
-
public $name = 'George';
|
9 |
-
public $child = array(
|
10 |
-
'name' => 'Dan',
|
11 |
-
'child' => array(
|
12 |
-
'name' => 'Justin',
|
13 |
-
'child' => false,
|
14 |
-
)
|
15 |
-
);
|
16 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/recursive_partials/recursive_partials.mustache
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
{{name}}{{#child}}{{>child}}{{/child}}
|
|
mustache/examples/recursive_partials/recursive_partials.txt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
George > Dan > Justin
|
|
mustache/examples/section_iterator_objects/SectionIteratorObjects.php
DELETED
@@ -1,16 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class SectionIteratorObjects extends Mustache {
|
4 |
-
public $start = "It worked the first time.";
|
5 |
-
|
6 |
-
protected $_data = array(
|
7 |
-
array('item' => 'And it worked the second time.'),
|
8 |
-
array('item' => 'As well as the third.'),
|
9 |
-
);
|
10 |
-
|
11 |
-
public function middle() {
|
12 |
-
return new ArrayIterator($this->_data);
|
13 |
-
}
|
14 |
-
|
15 |
-
public $final = "Then, surprisingly, it worked the final time.";
|
16 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/section_iterator_objects/section_iterator_objects.mustache
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
* {{ start }}
|
2 |
-
{{# middle }}
|
3 |
-
* {{ item }}
|
4 |
-
{{/ middle }}
|
5 |
-
* {{ final }}
|
|
|
|
|
|
|
|
|
|
mustache/examples/section_iterator_objects/section_iterator_objects.txt
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
* It worked the first time.
|
2 |
-
* And it worked the second time.
|
3 |
-
* As well as the third.
|
4 |
-
* Then, surprisingly, it worked the final time.
|
|
|
|
|
|
|
|
mustache/examples/section_magic_objects/SectionMagicObjects.php
DELETED
@@ -1,26 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class SectionMagicObjects extends Mustache {
|
4 |
-
public $start = "It worked the first time.";
|
5 |
-
|
6 |
-
public function middle() {
|
7 |
-
return new MagicObject();
|
8 |
-
}
|
9 |
-
|
10 |
-
public $final = "Then, surprisingly, it worked the final time.";
|
11 |
-
}
|
12 |
-
|
13 |
-
class MagicObject {
|
14 |
-
protected $_data = array(
|
15 |
-
'foo' => 'And it worked the second time.',
|
16 |
-
'bar' => 'As well as the third.'
|
17 |
-
);
|
18 |
-
|
19 |
-
public function __get($key) {
|
20 |
-
return isset($this->_data[$key]) ? $this->_data[$key] : NULL;
|
21 |
-
}
|
22 |
-
|
23 |
-
public function __isset($key) {
|
24 |
-
return isset($this->_data[$key]);
|
25 |
-
}
|
26 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/section_magic_objects/section_magic_objects.mustache
DELETED
@@ -1,6 +0,0 @@
|
|
1 |
-
* {{ start }}
|
2 |
-
{{# middle }}
|
3 |
-
* {{ foo }}
|
4 |
-
* {{ bar }}
|
5 |
-
{{/ middle }}
|
6 |
-
* {{ final }}
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/section_magic_objects/section_magic_objects.txt
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
* It worked the first time.
|
2 |
-
* And it worked the second time.
|
3 |
-
* As well as the third.
|
4 |
-
* Then, surprisingly, it worked the final time.
|
|
|
|
|
|
|
|
mustache/examples/section_objects/SectionObjects.php
DELETED
@@ -1,16 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class SectionObjects extends Mustache {
|
4 |
-
public $start = "It worked the first time.";
|
5 |
-
|
6 |
-
public function middle() {
|
7 |
-
return new SectionObject;
|
8 |
-
}
|
9 |
-
|
10 |
-
public $final = "Then, surprisingly, it worked the final time.";
|
11 |
-
}
|
12 |
-
|
13 |
-
class SectionObject {
|
14 |
-
public $foo = 'And it worked the second time.';
|
15 |
-
public $bar = 'As well as the third.';
|
16 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/section_objects/section_objects.mustache
DELETED
@@ -1,6 +0,0 @@
|
|
1 |
-
* {{ start }}
|
2 |
-
{{# middle }}
|
3 |
-
* {{ foo }}
|
4 |
-
* {{ bar }}
|
5 |
-
{{/ middle }}
|
6 |
-
* {{ final }}
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/section_objects/section_objects.txt
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
* It worked the first time.
|
2 |
-
* And it worked the second time.
|
3 |
-
* As well as the third.
|
4 |
-
* Then, surprisingly, it worked the final time.
|
|
|
|
|
|
|
|
mustache/examples/sections/Sections.php
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Sections extends Mustache {
|
4 |
-
public $start = "It worked the first time.";
|
5 |
-
|
6 |
-
public function middle() {
|
7 |
-
return array(
|
8 |
-
array('item' => "And it worked the second time."),
|
9 |
-
array('item' => "As well as the third."),
|
10 |
-
);
|
11 |
-
}
|
12 |
-
|
13 |
-
public $final = "Then, surprisingly, it worked the final time.";
|
14 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/sections/sections.mustache
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
* {{ start }}
|
2 |
-
{{# middle }}
|
3 |
-
* {{ item }}
|
4 |
-
{{/ middle }}
|
5 |
-
* {{ final }}
|
|
|
|
|
|
|
|
|
|
mustache/examples/sections/sections.txt
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
* It worked the first time.
|
2 |
-
* And it worked the second time.
|
3 |
-
* As well as the third.
|
4 |
-
* Then, surprisingly, it worked the final time.
|
|
|
|
|
|
|
|
mustache/examples/sections_nested/SectionsNested.php
DELETED
@@ -1,33 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class SectionsNested extends Mustache {
|
4 |
-
public $name = 'Little Mac';
|
5 |
-
|
6 |
-
public function enemies() {
|
7 |
-
return array(
|
8 |
-
array(
|
9 |
-
'name' => 'Von Kaiser',
|
10 |
-
'enemies' => array(
|
11 |
-
array('name' => 'Super Macho Man'),
|
12 |
-
array('name' => 'Piston Honda'),
|
13 |
-
array('name' => 'Mr. Sandman'),
|
14 |
-
)
|
15 |
-
),
|
16 |
-
array(
|
17 |
-
'name' => 'Mike Tyson',
|
18 |
-
'enemies' => array(
|
19 |
-
array('name' => 'Soda Popinski'),
|
20 |
-
array('name' => 'King Hippo'),
|
21 |
-
array('name' => 'Great Tiger'),
|
22 |
-
array('name' => 'Glass Joe'),
|
23 |
-
)
|
24 |
-
),
|
25 |
-
array(
|
26 |
-
'name' => 'Don Flamenco',
|
27 |
-
'enemies' => array(
|
28 |
-
array('name' => 'Bald Bull'),
|
29 |
-
)
|
30 |
-
),
|
31 |
-
);
|
32 |
-
}
|
33 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/sections_nested/sections_nested.mustache
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
Enemies of {{ name }}:
|
2 |
-
{{# enemies }}
|
3 |
-
{{ name }} ... who also has enemies:
|
4 |
-
{{# enemies }}
|
5 |
-
--> {{ name }}
|
6 |
-
{{/ enemies }}
|
7 |
-
{{/ enemies }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/sections_nested/sections_nested.txt
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
Enemies of Little Mac:
|
2 |
-
Von Kaiser ... who also has enemies:
|
3 |
-
--> Super Macho Man
|
4 |
-
--> Piston Honda
|
5 |
-
--> Mr. Sandman
|
6 |
-
Mike Tyson ... who also has enemies:
|
7 |
-
--> Soda Popinski
|
8 |
-
--> King Hippo
|
9 |
-
--> Great Tiger
|
10 |
-
--> Glass Joe
|
11 |
-
Don Flamenco ... who also has enemies:
|
12 |
-
--> Bald Bull
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/simple/Simple.php
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Simple extends Mustache {
|
4 |
-
public $name = "Chris";
|
5 |
-
public $value = 10000;
|
6 |
-
|
7 |
-
public function taxed_value() {
|
8 |
-
return $this->value - ($this->value * 0.4);
|
9 |
-
}
|
10 |
-
|
11 |
-
public $in_ca = true;
|
12 |
-
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/simple/simple.mustache
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
Hello {{name}}
|
2 |
-
You have just won ${{value}}!
|
3 |
-
{{#in_ca}}
|
4 |
-
Well, ${{ taxed_value }}, after taxes.
|
5 |
-
{{/in_ca}}
|
|
|
|
|
|
|
|
|
|
mustache/examples/simple/simple.txt
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
Hello Chris
|
2 |
-
You have just won $10000!
|
3 |
-
Well, $6000, after taxes.
|
|
|
|
|
|
mustache/examples/unescaped/Unescaped.php
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Unescaped extends Mustache {
|
4 |
-
public $title = "Bear > Shark";
|
5 |
-
}
|
|
|
|
|
|
|
|
|
|
mustache/examples/unescaped/unescaped.mustache
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<h1>{{{title}}}</h1>
|
|
mustache/examples/unescaped/unescaped.txt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<h1>Bear > Shark</h1>
|
|
mustache/examples/utf8/UTF8.php
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class UTF8Unescaped extends Mustache {
|
4 |
-
public $test = '中文又来啦';
|
5 |
-
}
|
|
|
|
|
|
|
|
|
|
mustache/examples/utf8/utf8.mustache
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<h1>中文 {{test}}</h1>
|
|
mustache/examples/utf8/utf8.txt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<h1>中文 中文又来啦</h1>
|
|
mustache/examples/utf8_unescaped/UTF8Unescaped.php
DELETED
@@ -1,5 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class UTF8 extends Mustache {
|
4 |
-
public $test = '中文又来啦';
|
5 |
-
}
|
|
|
|
|
|
|
|
|
|
mustache/examples/utf8_unescaped/utf8_unescaped.mustache
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<h1>中文 {{{test}}}</h1>
|
|
mustache/examples/utf8_unescaped/utf8_unescaped.txt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<h1>中文 中文又来啦</h1>
|
|
mustache/examples/whitespace/Whitespace.php
DELETED
@@ -1,37 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Whitespace test for tag names.
|
5 |
-
*
|
6 |
-
* Per http://github.com/janl/mustache.js/issues/issue/34/#comment_244396
|
7 |
-
* tags should strip leading and trailing whitespace in key names.
|
8 |
-
*
|
9 |
-
* `{{> tag }}` and `{{> tag}}` and `{{>tag}}` should all be equivalent.
|
10 |
-
*
|
11 |
-
* @extends Mustache
|
12 |
-
*/
|
13 |
-
class Whitespace extends Mustache {
|
14 |
-
public $foo = 'alpha';
|
15 |
-
|
16 |
-
public $bar = 'beta';
|
17 |
-
|
18 |
-
public function baz() {
|
19 |
-
return 'gamma';
|
20 |
-
}
|
21 |
-
|
22 |
-
public function qux() {
|
23 |
-
return array(
|
24 |
-
array('key with space' => 'A'),
|
25 |
-
array('key with space' => 'B'),
|
26 |
-
array('key with space' => 'C'),
|
27 |
-
array('key with space' => 'D'),
|
28 |
-
array('key with space' => 'E'),
|
29 |
-
array('key with space' => 'F'),
|
30 |
-
array('key with space' => 'G'),
|
31 |
-
);
|
32 |
-
}
|
33 |
-
|
34 |
-
protected $_partials = array(
|
35 |
-
'alphabet' => " * {{.}}\n",
|
36 |
-
);
|
37 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/whitespace/whitespace.mustache
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
{{^ inverted section test }}
|
2 |
-
These are some things:
|
3 |
-
{{/inverted section test }}
|
4 |
-
* {{ foo }}
|
5 |
-
* {{ bar}}
|
6 |
-
* {{ baz }}
|
7 |
-
{{# qux }}
|
8 |
-
* {{ key with space }}
|
9 |
-
{{/ qux }}
|
10 |
-
{{#qux}}.{{/qux}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/examples/whitespace/whitespace.txt
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
These are some things:
|
2 |
-
* alpha
|
3 |
-
* beta
|
4 |
-
* gamma
|
5 |
-
* A
|
6 |
-
* B
|
7 |
-
* C
|
8 |
-
* D
|
9 |
-
* E
|
10 |
-
* F
|
11 |
-
* G
|
12 |
-
.......
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/MustacheExceptionTest.php
DELETED
@@ -1,120 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
require_once '../Mustache.php';
|
4 |
-
|
5 |
-
class MustacheExceptionTest extends PHPUnit_Framework_TestCase {
|
6 |
-
|
7 |
-
const TEST_CLASS = 'Mustache';
|
8 |
-
|
9 |
-
protected $pickyMustache;
|
10 |
-
protected $slackerMustache;
|
11 |
-
|
12 |
-
public function setUp() {
|
13 |
-
$this->pickyMustache = new PickyMustache();
|
14 |
-
$this->slackerMustache = new SlackerMustache();
|
15 |
-
}
|
16 |
-
|
17 |
-
/**
|
18 |
-
* @group interpolation
|
19 |
-
* @expectedException MustacheException
|
20 |
-
*/
|
21 |
-
public function testThrowsUnknownVariableException() {
|
22 |
-
$this->pickyMustache->render('{{not_a_variable}}');
|
23 |
-
}
|
24 |
-
|
25 |
-
/**
|
26 |
-
* @group sections
|
27 |
-
* @expectedException MustacheException
|
28 |
-
*/
|
29 |
-
public function testThrowsUnclosedSectionException() {
|
30 |
-
$this->pickyMustache->render('{{#unclosed}}');
|
31 |
-
}
|
32 |
-
|
33 |
-
/**
|
34 |
-
* @group sections
|
35 |
-
* @expectedException MustacheException
|
36 |
-
*/
|
37 |
-
public function testThrowsUnclosedInvertedSectionException() {
|
38 |
-
$this->pickyMustache->render('{{^unclosed}}');
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* @group sections
|
43 |
-
* @expectedException MustacheException
|
44 |
-
*/
|
45 |
-
public function testThrowsUnexpectedCloseSectionException() {
|
46 |
-
$this->pickyMustache->render('{{/unopened}}');
|
47 |
-
}
|
48 |
-
|
49 |
-
/**
|
50 |
-
* @group partials
|
51 |
-
* @expectedException MustacheException
|
52 |
-
*/
|
53 |
-
public function testThrowsUnknownPartialException() {
|
54 |
-
$this->pickyMustache->render('{{>impartial}}');
|
55 |
-
}
|
56 |
-
|
57 |
-
/**
|
58 |
-
* @group pragmas
|
59 |
-
* @expectedException MustacheException
|
60 |
-
*/
|
61 |
-
public function testThrowsUnknownPragmaException() {
|
62 |
-
$this->pickyMustache->render('{{%SWEET-MUSTACHE-BRO}}');
|
63 |
-
}
|
64 |
-
|
65 |
-
/**
|
66 |
-
* @group sections
|
67 |
-
*/
|
68 |
-
public function testDoesntThrowUnclosedSectionException() {
|
69 |
-
$this->assertEquals('', $this->slackerMustache->render('{{#unclosed}}'));
|
70 |
-
}
|
71 |
-
|
72 |
-
/**
|
73 |
-
* @group sections
|
74 |
-
*/
|
75 |
-
public function testDoesntThrowUnexpectedCloseSectionException() {
|
76 |
-
$this->assertEquals('', $this->slackerMustache->render('{{/unopened}}'));
|
77 |
-
}
|
78 |
-
|
79 |
-
/**
|
80 |
-
* @group partials
|
81 |
-
*/
|
82 |
-
public function testDoesntThrowUnknownPartialException() {
|
83 |
-
$this->assertEquals('', $this->slackerMustache->render('{{>impartial}}'));
|
84 |
-
}
|
85 |
-
|
86 |
-
/**
|
87 |
-
* @group pragmas
|
88 |
-
* @expectedException MustacheException
|
89 |
-
*/
|
90 |
-
public function testGetPragmaOptionsThrowsExceptionsIfItThinksYouHaveAPragmaButItTurnsOutYouDont() {
|
91 |
-
$mustache = new TestableMustache();
|
92 |
-
$mustache->testableGetPragmaOptions('PRAGMATIC');
|
93 |
-
}
|
94 |
-
}
|
95 |
-
|
96 |
-
class PickyMustache extends Mustache {
|
97 |
-
protected $_throwsExceptions = array(
|
98 |
-
MustacheException::UNKNOWN_VARIABLE => true,
|
99 |
-
MustacheException::UNCLOSED_SECTION => true,
|
100 |
-
MustacheException::UNEXPECTED_CLOSE_SECTION => true,
|
101 |
-
MustacheException::UNKNOWN_PARTIAL => true,
|
102 |
-
MustacheException::UNKNOWN_PRAGMA => true,
|
103 |
-
);
|
104 |
-
}
|
105 |
-
|
106 |
-
class SlackerMustache extends Mustache {
|
107 |
-
protected $_throwsExceptions = array(
|
108 |
-
MustacheException::UNKNOWN_VARIABLE => false,
|
109 |
-
MustacheException::UNCLOSED_SECTION => false,
|
110 |
-
MustacheException::UNEXPECTED_CLOSE_SECTION => false,
|
111 |
-
MustacheException::UNKNOWN_PARTIAL => false,
|
112 |
-
MustacheException::UNKNOWN_PRAGMA => false,
|
113 |
-
);
|
114 |
-
}
|
115 |
-
|
116 |
-
class TestableMustache extends Mustache {
|
117 |
-
public function testableGetPragmaOptions($pragma_name) {
|
118 |
-
return $this->_getPragmaOptions($pragma_name);
|
119 |
-
}
|
120 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/MustacheObjectSectionTest.php
DELETED
@@ -1,73 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
require_once '../Mustache.php';
|
4 |
-
|
5 |
-
/**
|
6 |
-
* @group sections
|
7 |
-
*/
|
8 |
-
class MustacheObjectSectionTest extends PHPUnit_Framework_TestCase {
|
9 |
-
public function testBasicObject() {
|
10 |
-
$alpha = new Alpha();
|
11 |
-
$this->assertEquals('Foo', $alpha->render('{{#foo}}{{name}}{{/foo}}'));
|
12 |
-
}
|
13 |
-
|
14 |
-
public function testObjectWithGet() {
|
15 |
-
$beta = new Beta();
|
16 |
-
$this->assertEquals('Foo', $beta->render('{{#foo}}{{name}}{{/foo}}'));
|
17 |
-
}
|
18 |
-
|
19 |
-
public function testSectionObjectWithGet() {
|
20 |
-
$gamma = new Gamma();
|
21 |
-
$this->assertEquals('Foo', $gamma->render('{{#bar}}{{#foo}}{{name}}{{/foo}}{{/bar}}'));
|
22 |
-
}
|
23 |
-
|
24 |
-
public function testSectionObjectWithFunction() {
|
25 |
-
$alpha = new Alpha();
|
26 |
-
$alpha->foo = new Delta();
|
27 |
-
$this->assertEquals('Foo', $alpha->render('{{#foo}}{{name}}{{/foo}}'));
|
28 |
-
}
|
29 |
-
}
|
30 |
-
|
31 |
-
class Alpha extends Mustache {
|
32 |
-
public $foo;
|
33 |
-
|
34 |
-
public function __construct() {
|
35 |
-
$this->foo = new StdClass();
|
36 |
-
$this->foo->name = 'Foo';
|
37 |
-
$this->foo->number = 1;
|
38 |
-
}
|
39 |
-
}
|
40 |
-
|
41 |
-
class Beta extends Mustache {
|
42 |
-
protected $_data = array();
|
43 |
-
|
44 |
-
public function __construct() {
|
45 |
-
$this->_data['foo'] = new StdClass();
|
46 |
-
$this->_data['foo']->name = 'Foo';
|
47 |
-
$this->_data['foo']->number = 1;
|
48 |
-
}
|
49 |
-
|
50 |
-
public function __isset($name) {
|
51 |
-
return array_key_exists($name, $this->_data);
|
52 |
-
}
|
53 |
-
|
54 |
-
public function __get($name) {
|
55 |
-
return $this->_data[$name];
|
56 |
-
}
|
57 |
-
}
|
58 |
-
|
59 |
-
class Gamma extends Mustache {
|
60 |
-
public $bar;
|
61 |
-
|
62 |
-
public function __construct() {
|
63 |
-
$this->bar = new Beta();
|
64 |
-
}
|
65 |
-
}
|
66 |
-
|
67 |
-
class Delta extends Mustache {
|
68 |
-
protected $_name = 'Foo';
|
69 |
-
|
70 |
-
public function name() {
|
71 |
-
return $this->_name;
|
72 |
-
}
|
73 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/MustachePragmaTest.php
DELETED
@@ -1,50 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
require_once '../Mustache.php';
|
4 |
-
|
5 |
-
/**
|
6 |
-
* @group pragmas
|
7 |
-
*/
|
8 |
-
class MustachePragmaTest extends PHPUnit_Framework_TestCase {
|
9 |
-
|
10 |
-
public function testUnknownPragmaException() {
|
11 |
-
$m = new Mustache();
|
12 |
-
|
13 |
-
try {
|
14 |
-
$m->render('{{%I-HAVE-THE-GREATEST-MUSTACHE}}');
|
15 |
-
} catch (MustacheException $e) {
|
16 |
-
$this->assertEquals(MustacheException::UNKNOWN_PRAGMA, $e->getCode(), 'Caught exception code was not MustacheException::UNKNOWN_PRAGMA');
|
17 |
-
return;
|
18 |
-
}
|
19 |
-
|
20 |
-
$this->fail('Mustache should have thrown an unknown pragma exception');
|
21 |
-
}
|
22 |
-
|
23 |
-
public function testPragmaReplace() {
|
24 |
-
$m = new Mustache();
|
25 |
-
$this->assertEquals('', $m->render('{{%UNESCAPED}}'), 'Pragma tag not removed');
|
26 |
-
}
|
27 |
-
|
28 |
-
public function testPragmaReplaceMultiple() {
|
29 |
-
$m = new Mustache();
|
30 |
-
|
31 |
-
$this->assertEquals('', $m->render('{{% UNESCAPED }}'), 'Pragmas should allow whitespace');
|
32 |
-
$this->assertEquals('', $m->render('{{% UNESCAPED foo=bar }}'), 'Pragmas should allow whitespace');
|
33 |
-
$this->assertEquals('', $m->render("{{%UNESCAPED}}\n{{%UNESCAPED}}"), 'Multiple pragma tags not removed');
|
34 |
-
$this->assertEquals(' ', $m->render('{{%UNESCAPED}} {{%UNESCAPED}}'), 'Multiple pragma tags not removed');
|
35 |
-
}
|
36 |
-
|
37 |
-
public function testPragmaReplaceNewline() {
|
38 |
-
$m = new Mustache();
|
39 |
-
$this->assertEquals('', $m->render("{{%UNESCAPED}}\n"), 'Trailing newline after pragma tag not removed');
|
40 |
-
$this->assertEquals("\n", $m->render("\n{{%UNESCAPED}}\n"), 'Too many newlines removed with pragma tag');
|
41 |
-
$this->assertEquals("1\n23", $m->render("1\n2{{%UNESCAPED}}\n3"), 'Wrong newline removed with pragma tag');
|
42 |
-
}
|
43 |
-
|
44 |
-
public function testPragmaReset() {
|
45 |
-
$m = new Mustache('', array('symbol' => '>>>'));
|
46 |
-
$this->assertEquals('>>>', $m->render('{{{symbol}}}'));
|
47 |
-
$this->assertEquals('>>>', $m->render('{{%UNESCAPED}}{{symbol}}'));
|
48 |
-
$this->assertEquals('>>>', $m->render('{{{symbol}}}'));
|
49 |
-
}
|
50 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/MustachePragmaUnescapedTest.php
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
require_once '../Mustache.php';
|
4 |
-
|
5 |
-
/**
|
6 |
-
* @group pragmas
|
7 |
-
*/
|
8 |
-
class MustachePragmaUnescapedTest extends PHPUnit_Framework_TestCase {
|
9 |
-
|
10 |
-
public function testPragmaUnescaped() {
|
11 |
-
$m = new Mustache(null, array('title' => 'Bear > Shark'));
|
12 |
-
|
13 |
-
$this->assertEquals('Bear > Shark', $m->render('{{%UNESCAPED}}{{title}}'));
|
14 |
-
$this->assertEquals('Bear > Shark', $m->render('{{title}}'));
|
15 |
-
$this->assertEquals('Bear > Shark', $m->render('{{%UNESCAPED}}{{{title}}}'));
|
16 |
-
$this->assertEquals('Bear > Shark', $m->render('{{{title}}}'));
|
17 |
-
}
|
18 |
-
|
19 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/MustacheSpecTest.php
DELETED
@@ -1,145 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
require_once '../Mustache.php';
|
4 |
-
require_once './lib/yaml/lib/sfYamlParser.php';
|
5 |
-
|
6 |
-
/**
|
7 |
-
* A PHPUnit test case wrapping the Mustache Spec
|
8 |
-
*
|
9 |
-
* @group mustache-spec
|
10 |
-
*/
|
11 |
-
class MustacheSpecTest extends PHPUnit_Framework_TestCase {
|
12 |
-
|
13 |
-
/**
|
14 |
-
* For some reason data providers can't mark tests skipped, so this test exists
|
15 |
-
* simply to provide a 'skipped' test if the `spec` submodule isn't initialized.
|
16 |
-
*/
|
17 |
-
public function testSpecInitialized() {
|
18 |
-
$spec_dir = dirname(__FILE__) . '/spec/specs/';
|
19 |
-
if (!file_exists($spec_dir)) {
|
20 |
-
$this->markTestSkipped('Mustache spec submodule not initialized: run "git submodule update --init"');
|
21 |
-
}
|
22 |
-
}
|
23 |
-
|
24 |
-
/**
|
25 |
-
* @group comments
|
26 |
-
* @dataProvider loadCommentSpec
|
27 |
-
*/
|
28 |
-
public function testCommentSpec($desc, $template, $data, $partials, $expected) {
|
29 |
-
$m = new Mustache($template, $data, $partials);
|
30 |
-
$this->assertEquals($expected, $m->render(), $desc);
|
31 |
-
}
|
32 |
-
|
33 |
-
/**
|
34 |
-
* @group delimiters
|
35 |
-
* @dataProvider loadDelimitersSpec
|
36 |
-
*/
|
37 |
-
public function testDelimitersSpec($desc, $template, $data, $partials, $expected) {
|
38 |
-
$m = new Mustache($template, $data, $partials);
|
39 |
-
$this->assertEquals($expected, $m->render(), $desc);
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* @group interpolation
|
44 |
-
* @dataProvider loadInterpolationSpec
|
45 |
-
*/
|
46 |
-
public function testInterpolationSpec($desc, $template, $data, $partials, $expected) {
|
47 |
-
$m = new Mustache($template, $data, $partials);
|
48 |
-
$this->assertEquals($expected, $m->render(), $desc);
|
49 |
-
}
|
50 |
-
|
51 |
-
/**
|
52 |
-
* @group inverted-sections
|
53 |
-
* @dataProvider loadInvertedSpec
|
54 |
-
*/
|
55 |
-
public function testInvertedSpec($desc, $template, $data, $partials, $expected) {
|
56 |
-
$m = new Mustache($template, $data, $partials);
|
57 |
-
$this->assertEquals($expected, $m->render(), $desc);
|
58 |
-
}
|
59 |
-
|
60 |
-
// /**
|
61 |
-
// * @group lambdas
|
62 |
-
// * @dataProvider loadLambdasSpec
|
63 |
-
// */
|
64 |
-
// public function testLambdasSpec($desc, $template, $data, $partials, $expected) {
|
65 |
-
// $this->markTestSkipped("Lambdas for PHP haven't made it into the spec yet, so we'll skip them to avoid a bajillion failed tests.");
|
66 |
-
//
|
67 |
-
// if (!version_compare(PHP_VERSION, '5.3.0', '>=')) {
|
68 |
-
// $this->markTestSkipped('Unable to test Lambdas spec with PHP < 5.3.');
|
69 |
-
// }
|
70 |
-
//
|
71 |
-
// $m = new Mustache($template, $data, $partials);
|
72 |
-
// $this->assertEquals($expected, $m->render(), $desc);
|
73 |
-
// }
|
74 |
-
|
75 |
-
/**
|
76 |
-
* @group partials
|
77 |
-
* @dataProvider loadPartialsSpec
|
78 |
-
*/
|
79 |
-
public function testPartialsSpec($desc, $template, $data, $partials, $expected) {
|
80 |
-
$m = new Mustache($template, $data, $partials);
|
81 |
-
$this->assertEquals($expected, $m->render(), $desc);
|
82 |
-
}
|
83 |
-
|
84 |
-
/**
|
85 |
-
* @group sections
|
86 |
-
* @dataProvider loadSectionsSpec
|
87 |
-
*/
|
88 |
-
public function testSectionsSpec($desc, $template, $data, $partials, $expected) {
|
89 |
-
$m = new Mustache($template, $data, $partials);
|
90 |
-
$this->assertEquals($expected, $m->render(), $desc);
|
91 |
-
}
|
92 |
-
|
93 |
-
public function loadCommentSpec() {
|
94 |
-
return $this->loadSpec('comments');
|
95 |
-
}
|
96 |
-
|
97 |
-
public function loadDelimitersSpec() {
|
98 |
-
return $this->loadSpec('delimiters');
|
99 |
-
}
|
100 |
-
|
101 |
-
public function loadInterpolationSpec() {
|
102 |
-
return $this->loadSpec('interpolation');
|
103 |
-
}
|
104 |
-
|
105 |
-
public function loadInvertedSpec() {
|
106 |
-
return $this->loadSpec('inverted');
|
107 |
-
}
|
108 |
-
|
109 |
-
// public function loadLambdasSpec() {
|
110 |
-
// return $this->loadSpec('lambdas');
|
111 |
-
// }
|
112 |
-
|
113 |
-
public function loadPartialsSpec() {
|
114 |
-
return $this->loadSpec('partials');
|
115 |
-
}
|
116 |
-
|
117 |
-
public function loadSectionsSpec() {
|
118 |
-
return $this->loadSpec('sections');
|
119 |
-
}
|
120 |
-
|
121 |
-
/**
|
122 |
-
* Data provider for the mustache spec test.
|
123 |
-
*
|
124 |
-
* Loads YAML files from the spec and converts them to PHPisms.
|
125 |
-
*
|
126 |
-
* @access public
|
127 |
-
* @return array
|
128 |
-
*/
|
129 |
-
protected function loadSpec($name) {
|
130 |
-
$filename = dirname(__FILE__) . '/spec/specs/' . $name . '.yml';
|
131 |
-
if (!file_exists($filename)) {
|
132 |
-
return array();
|
133 |
-
}
|
134 |
-
|
135 |
-
$data = array();
|
136 |
-
|
137 |
-
$yaml = new sfYamlParser();
|
138 |
-
|
139 |
-
$spec = $yaml->parse(file_get_contents($filename));
|
140 |
-
foreach ($spec['tests'] as $test) {
|
141 |
-
$data[] = array($test['name'] . ': ' . $test['desc'], $test['template'], $test['data'], isset($test['partials']) ? $test['partials'] : array(), $test['expected']);
|
142 |
-
}
|
143 |
-
return $data;
|
144 |
-
}
|
145 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/MustacheTest.php
DELETED
@@ -1,464 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
require_once '../Mustache.php';
|
4 |
-
|
5 |
-
/**
|
6 |
-
* A PHPUnit test case for Mustache.php.
|
7 |
-
*
|
8 |
-
* This is a very basic, very rudimentary unit test case. It's probably more important to have tests
|
9 |
-
* than to have elegant tests, so let's bear with it for a bit.
|
10 |
-
*
|
11 |
-
* This class assumes an example directory exists at `../examples` with the following structure:
|
12 |
-
*
|
13 |
-
* @code
|
14 |
-
* examples
|
15 |
-
* foo
|
16 |
-
* Foo.php
|
17 |
-
* foo.mustache
|
18 |
-
* foo.txt
|
19 |
-
* bar
|
20 |
-
* Bar.php
|
21 |
-
* bar.mustache
|
22 |
-
* bar.txt
|
23 |
-
* @endcode
|
24 |
-
*
|
25 |
-
* To use this test:
|
26 |
-
*
|
27 |
-
* 1. {@link http://www.phpunit.de/manual/current/en/installation.html Install PHPUnit}
|
28 |
-
* 2. run phpunit from the `test` directory:
|
29 |
-
* `phpunit MustacheTest`
|
30 |
-
* 3. Fix bugs. Lather, rinse, repeat.
|
31 |
-
*
|
32 |
-
* @extends PHPUnit_Framework_TestCase
|
33 |
-
*/
|
34 |
-
class MustacheTest extends PHPUnit_Framework_TestCase {
|
35 |
-
|
36 |
-
const TEST_CLASS = 'Mustache';
|
37 |
-
|
38 |
-
protected $knownIssues = array(
|
39 |
-
// Just the whitespace ones...
|
40 |
-
);
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Test Mustache constructor.
|
44 |
-
*
|
45 |
-
* @access public
|
46 |
-
* @return void
|
47 |
-
*/
|
48 |
-
public function test__construct() {
|
49 |
-
$template = '{{#mustaches}}{{#last}}and {{/last}}{{type}}{{^last}}, {{/last}}{{/mustaches}}';
|
50 |
-
$data = array(
|
51 |
-
'mustaches' => array(
|
52 |
-
array('type' => 'Natural'),
|
53 |
-
array('type' => 'Hungarian'),
|
54 |
-
array('type' => 'Dali'),
|
55 |
-
array('type' => 'English'),
|
56 |
-
array('type' => 'Imperial'),
|
57 |
-
array('type' => 'Freestyle', 'last' => 'true'),
|
58 |
-
)
|
59 |
-
);
|
60 |
-
$output = 'Natural, Hungarian, Dali, English, Imperial, and Freestyle';
|
61 |
-
|
62 |
-
$m1 = new Mustache();
|
63 |
-
$this->assertEquals($output, $m1->render($template, $data));
|
64 |
-
|
65 |
-
$m2 = new Mustache($template);
|
66 |
-
$this->assertEquals($output, $m2->render(null, $data));
|
67 |
-
|
68 |
-
$m3 = new Mustache($template, $data);
|
69 |
-
$this->assertEquals($output, $m3->render());
|
70 |
-
|
71 |
-
$m4 = new Mustache(null, $data);
|
72 |
-
$this->assertEquals($output, $m4->render($template));
|
73 |
-
}
|
74 |
-
|
75 |
-
/**
|
76 |
-
* @dataProvider constructorOptions
|
77 |
-
*/
|
78 |
-
public function testConstructorOptions($options, $charset, $delimiters, $pragmas) {
|
79 |
-
$mustache = new MustacheExposedOptionsStub(null, null, null, $options);
|
80 |
-
$this->assertEquals($charset, $mustache->getCharset());
|
81 |
-
$this->assertEquals($delimiters, $mustache->getDelimiters());
|
82 |
-
$this->assertEquals($pragmas, $mustache->getPragmas());
|
83 |
-
}
|
84 |
-
|
85 |
-
public function constructorOptions() {
|
86 |
-
return array(
|
87 |
-
array(
|
88 |
-
array(),
|
89 |
-
'UTF-8',
|
90 |
-
array('{{', '}}'),
|
91 |
-
array(),
|
92 |
-
),
|
93 |
-
array(
|
94 |
-
array(
|
95 |
-
'charset' => 'UTF-8',
|
96 |
-
'delimiters' => '<< >>',
|
97 |
-
'pragmas' => array(Mustache::PRAGMA_UNESCAPED)
|
98 |
-
),
|
99 |
-
'UTF-8',
|
100 |
-
array('<<', '>>'),
|
101 |
-
array(Mustache::PRAGMA_UNESCAPED),
|
102 |
-
),
|
103 |
-
array(
|
104 |
-
array(
|
105 |
-
'charset' => 'cp866',
|
106 |
-
'delimiters' => array('[[[[', ']]]]'),
|
107 |
-
'pragmas' => array(Mustache::PRAGMA_UNESCAPED)
|
108 |
-
),
|
109 |
-
'cp866',
|
110 |
-
array('[[[[', ']]]]'),
|
111 |
-
array(Mustache::PRAGMA_UNESCAPED),
|
112 |
-
),
|
113 |
-
);
|
114 |
-
}
|
115 |
-
|
116 |
-
/**
|
117 |
-
* @expectedException MustacheException
|
118 |
-
*/
|
119 |
-
public function testConstructorInvalidPragmaOptionsThrowExceptions() {
|
120 |
-
$mustache = new Mustache(null, null, null, array('pragmas' => array('banana phone')));
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
* Test __toString() function.
|
125 |
-
*
|
126 |
-
* @access public
|
127 |
-
* @return void
|
128 |
-
*/
|
129 |
-
public function test__toString() {
|
130 |
-
$m = new Mustache('{{first_name}} {{last_name}}', array('first_name' => 'Karl', 'last_name' => 'Marx'));
|
131 |
-
|
132 |
-
$this->assertEquals('Karl Marx', $m->__toString());
|
133 |
-
$this->assertEquals('Karl Marx', (string) $m);
|
134 |
-
|
135 |
-
$m2 = $this->getMock(self::TEST_CLASS, array('render'), array());
|
136 |
-
$m2->expects($this->once())
|
137 |
-
->method('render')
|
138 |
-
->will($this->returnValue('foo'));
|
139 |
-
|
140 |
-
$this->assertEquals('foo', $m2->render());
|
141 |
-
}
|
142 |
-
|
143 |
-
public function test__toStringException() {
|
144 |
-
$m = $this->getMock(self::TEST_CLASS, array('render'), array());
|
145 |
-
$m->expects($this->once())
|
146 |
-
->method('render')
|
147 |
-
->will($this->throwException(new Exception));
|
148 |
-
|
149 |
-
try {
|
150 |
-
$out = (string) $m;
|
151 |
-
} catch (Exception $e) {
|
152 |
-
$this->fail('__toString should catch all exceptions');
|
153 |
-
}
|
154 |
-
}
|
155 |
-
|
156 |
-
/**
|
157 |
-
* Test render().
|
158 |
-
*
|
159 |
-
* @access public
|
160 |
-
* @return void
|
161 |
-
*/
|
162 |
-
public function testRender() {
|
163 |
-
$m = new Mustache();
|
164 |
-
|
165 |
-
$this->assertEquals('', $m->render(''));
|
166 |
-
$this->assertEquals('foo', $m->render('foo'));
|
167 |
-
$this->assertEquals('', $m->render(null));
|
168 |
-
|
169 |
-
$m2 = new Mustache('foo');
|
170 |
-
$this->assertEquals('foo', $m2->render());
|
171 |
-
|
172 |
-
$m3 = new Mustache('');
|
173 |
-
$this->assertEquals('', $m3->render());
|
174 |
-
|
175 |
-
$m3 = new Mustache();
|
176 |
-
$this->assertEquals('', $m3->render(null));
|
177 |
-
}
|
178 |
-
|
179 |
-
/**
|
180 |
-
* Test render() with data.
|
181 |
-
*
|
182 |
-
* @group interpolation
|
183 |
-
*/
|
184 |
-
public function testRenderWithData() {
|
185 |
-
$m = new Mustache('{{first_name}} {{last_name}}');
|
186 |
-
$this->assertEquals('Charlie Chaplin', $m->render(null, array('first_name' => 'Charlie', 'last_name' => 'Chaplin')));
|
187 |
-
$this->assertEquals('Zappa, Frank', $m->render('{{last_name}}, {{first_name}}', array('first_name' => 'Frank', 'last_name' => 'Zappa')));
|
188 |
-
}
|
189 |
-
|
190 |
-
/**
|
191 |
-
* @group partials
|
192 |
-
*/
|
193 |
-
public function testRenderWithPartials() {
|
194 |
-
$m = new Mustache('{{>stache}}', null, array('stache' => '{{first_name}} {{last_name}}'));
|
195 |
-
$this->assertEquals('Charlie Chaplin', $m->render(null, array('first_name' => 'Charlie', 'last_name' => 'Chaplin')));
|
196 |
-
$this->assertEquals('Zappa, Frank', $m->render('{{last_name}}, {{first_name}}', array('first_name' => 'Frank', 'last_name' => 'Zappa')));
|
197 |
-
}
|
198 |
-
|
199 |
-
/**
|
200 |
-
* @group interpolation
|
201 |
-
* @dataProvider interpolationData
|
202 |
-
*/
|
203 |
-
public function testDoubleRenderMustacheTags($template, $context, $expected) {
|
204 |
-
$m = new Mustache($template, $context);
|
205 |
-
$this->assertEquals($expected, $m->render());
|
206 |
-
}
|
207 |
-
|
208 |
-
public function interpolationData() {
|
209 |
-
return array(
|
210 |
-
array(
|
211 |
-
'{{#a}}{{=<% %>=}}{{b}} c<%={{ }}=%>{{/a}}',
|
212 |
-
array('a' => array(array('b' => 'Do Not Render'))),
|
213 |
-
'{{b}} c'
|
214 |
-
),
|
215 |
-
array(
|
216 |
-
'{{#a}}{{b}}{{/a}}',
|
217 |
-
array('a' => array('b' => '{{c}}'), 'c' => 'FAIL'),
|
218 |
-
'{{c}}'
|
219 |
-
),
|
220 |
-
);
|
221 |
-
}
|
222 |
-
|
223 |
-
/**
|
224 |
-
* Mustache should allow newlines (and other whitespace) in comments and all other tags.
|
225 |
-
*
|
226 |
-
* @group comments
|
227 |
-
*/
|
228 |
-
public function testNewlinesInComments() {
|
229 |
-
$m = new Mustache("{{! comment \n \t still a comment... }}");
|
230 |
-
$this->assertEquals('', $m->render());
|
231 |
-
}
|
232 |
-
|
233 |
-
/**
|
234 |
-
* Mustache should return the same thing when invoked multiple times.
|
235 |
-
*/
|
236 |
-
public function testMultipleInvocations() {
|
237 |
-
$m = new Mustache('x');
|
238 |
-
$first = $m->render();
|
239 |
-
$second = $m->render();
|
240 |
-
|
241 |
-
$this->assertEquals('x', $first);
|
242 |
-
$this->assertEquals($first, $second);
|
243 |
-
}
|
244 |
-
|
245 |
-
/**
|
246 |
-
* Mustache should return the same thing when invoked multiple times.
|
247 |
-
*
|
248 |
-
* @group interpolation
|
249 |
-
*/
|
250 |
-
public function testMultipleInvocationsWithTags() {
|
251 |
-
$m = new Mustache('{{one}} {{two}}', array('one' => 'foo', 'two' => 'bar'));
|
252 |
-
$first = $m->render();
|
253 |
-
$second = $m->render();
|
254 |
-
|
255 |
-
$this->assertEquals('foo bar', $first);
|
256 |
-
$this->assertEquals($first, $second);
|
257 |
-
}
|
258 |
-
|
259 |
-
/**
|
260 |
-
* Mustache should not use templates passed to the render() method for subsequent invocations.
|
261 |
-
*/
|
262 |
-
public function testResetTemplateForMultipleInvocations() {
|
263 |
-
$m = new Mustache('Sirve.');
|
264 |
-
$this->assertEquals('No sirve.', $m->render('No sirve.'));
|
265 |
-
$this->assertEquals('Sirve.', $m->render());
|
266 |
-
|
267 |
-
$m2 = new Mustache();
|
268 |
-
$this->assertEquals('No sirve.', $m2->render('No sirve.'));
|
269 |
-
$this->assertEquals('', $m2->render());
|
270 |
-
}
|
271 |
-
|
272 |
-
/**
|
273 |
-
* Test the __clone() magic function.
|
274 |
-
*
|
275 |
-
* @group examples
|
276 |
-
* @dataProvider getExamples
|
277 |
-
*
|
278 |
-
* @param string $class
|
279 |
-
* @param string $template
|
280 |
-
* @param string $output
|
281 |
-
*/
|
282 |
-
public function test__clone($class, $template, $output) {
|
283 |
-
if (isset($this->knownIssues[$class])) {
|
284 |
-
return $this->markTestSkipped($this->knownIssues[$class]);
|
285 |
-
}
|
286 |
-
|
287 |
-
$m = new $class;
|
288 |
-
$n = clone $m;
|
289 |
-
|
290 |
-
$n_output = $n->render($template);
|
291 |
-
|
292 |
-
$o = clone $n;
|
293 |
-
|
294 |
-
$this->assertEquals($m->render($template), $n_output);
|
295 |
-
$this->assertEquals($n_output, $o->render($template));
|
296 |
-
|
297 |
-
$this->assertNotSame($m, $n);
|
298 |
-
$this->assertNotSame($n, $o);
|
299 |
-
$this->assertNotSame($m, $o);
|
300 |
-
}
|
301 |
-
|
302 |
-
/**
|
303 |
-
* Test everything in the `examples` directory.
|
304 |
-
*
|
305 |
-
* @group examples
|
306 |
-
* @dataProvider getExamples
|
307 |
-
*
|
308 |
-
* @param string $class
|
309 |
-
* @param string $template
|
310 |
-
* @param string $output
|
311 |
-
*/
|
312 |
-
public function testExamples($class, $template, $output) {
|
313 |
-
if (isset($this->knownIssues[$class])) {
|
314 |
-
return $this->markTestSkipped($this->knownIssues[$class]);
|
315 |
-
}
|
316 |
-
|
317 |
-
$m = new $class;
|
318 |
-
$this->assertEquals($output, $m->render($template));
|
319 |
-
}
|
320 |
-
|
321 |
-
/**
|
322 |
-
* Data provider for testExamples method.
|
323 |
-
*
|
324 |
-
* Assumes that an `examples` directory exists inside parent directory.
|
325 |
-
* This examples directory should contain any number of subdirectories, each of which contains
|
326 |
-
* three files: one Mustache class (.php), one Mustache template (.mustache), and one output file
|
327 |
-
* (.txt).
|
328 |
-
*
|
329 |
-
* This whole mess will be refined later to be more intuitive and less prescriptive, but it'll
|
330 |
-
* do for now. Especially since it means we can have unit tests :)
|
331 |
-
*
|
332 |
-
* @return array
|
333 |
-
*/
|
334 |
-
public function getExamples() {
|
335 |
-
$basedir = dirname(__FILE__) . '/../examples/';
|
336 |
-
|
337 |
-
$ret = array();
|
338 |
-
|
339 |
-
$files = new RecursiveDirectoryIterator($basedir);
|
340 |
-
while ($files->valid()) {
|
341 |
-
|
342 |
-
if ($files->hasChildren() && $children = $files->getChildren()) {
|
343 |
-
$example = $files->getSubPathname();
|
344 |
-
$class = null;
|
345 |
-
$template = null;
|
346 |
-
$output = null;
|
347 |
-
|
348 |
-
foreach ($children as $file) {
|
349 |
-
if (!$file->isFile()) continue;
|
350 |
-
|
351 |
-
$filename = $file->getPathname();
|
352 |
-
$info = pathinfo($filename);
|
353 |
-
|
354 |
-
if (isset($info['extension'])) {
|
355 |
-
switch($info['extension']) {
|
356 |
-
case 'php':
|
357 |
-
$class = $info['filename'];
|
358 |
-
include_once($filename);
|
359 |
-
break;
|
360 |
-
|
361 |
-
case 'mustache':
|
362 |
-
$template = file_get_contents($filename);
|
363 |
-
break;
|
364 |
-
|
365 |
-
case 'txt':
|
366 |
-
$output = file_get_contents($filename);
|
367 |
-
break;
|
368 |
-
}
|
369 |
-
}
|
370 |
-
}
|
371 |
-
|
372 |
-
if (!empty($class)) {
|
373 |
-
$ret[$example] = array($class, $template, $output);
|
374 |
-
}
|
375 |
-
}
|
376 |
-
|
377 |
-
$files->next();
|
378 |
-
}
|
379 |
-
return $ret;
|
380 |
-
}
|
381 |
-
|
382 |
-
/**
|
383 |
-
* @group delimiters
|
384 |
-
*/
|
385 |
-
public function testCrazyDelimiters() {
|
386 |
-
$m = new Mustache(null, array('result' => 'success'));
|
387 |
-
$this->assertEquals('success', $m->render('{{=[[ ]]=}}[[ result ]]'));
|
388 |
-
$this->assertEquals('success', $m->render('{{=(( ))=}}(( result ))'));
|
389 |
-
$this->assertEquals('success', $m->render('{{={$ $}=}}{$ result $}'));
|
390 |
-
$this->assertEquals('success', $m->render('{{=<.. ..>=}}<.. result ..>'));
|
391 |
-
$this->assertEquals('success', $m->render('{{=^^ ^^}}^^ result ^^'));
|
392 |
-
$this->assertEquals('success', $m->render('{{=// \\\\}}// result \\\\'));
|
393 |
-
}
|
394 |
-
|
395 |
-
/**
|
396 |
-
* @group delimiters
|
397 |
-
*/
|
398 |
-
public function testResetDelimiters() {
|
399 |
-
$m = new Mustache(null, array('result' => 'success'));
|
400 |
-
$this->assertEquals('success', $m->render('{{=[[ ]]=}}[[ result ]]'));
|
401 |
-
$this->assertEquals('success', $m->render('{{=<< >>=}}<< result >>'));
|
402 |
-
$this->assertEquals('success', $m->render('{{=<% %>=}}<% result %>'));
|
403 |
-
}
|
404 |
-
|
405 |
-
/**
|
406 |
-
* @group delimiters
|
407 |
-
*/
|
408 |
-
public function testStickyDelimiters() {
|
409 |
-
$m = new Mustache(null, array('result' => 'FAIL'));
|
410 |
-
$this->assertEquals('{{ result }}', $m->render('{{=[[ ]]=}}{{ result }}[[={{ }}=]]'));
|
411 |
-
$this->assertEquals('{{#result}}{{/result}}', $m->render('{{=[[ ]]=}}{{#result}}{{/result}}[[={{ }}=]]'));
|
412 |
-
$this->assertEquals('{{ result }}', $m->render('{{=[[ ]]=}}[[#result]]{{ result }}[[/result]][[={{ }}=]]'));
|
413 |
-
$this->assertEquals('{{ result }}', $m->render('{{#result}}{{=[[ ]]=}}{{ result }}[[/result]][[^result]][[={{ }}=]][[ result ]]{{/result}}'));
|
414 |
-
}
|
415 |
-
|
416 |
-
/**
|
417 |
-
* @group sections
|
418 |
-
* @dataProvider poorlyNestedSections
|
419 |
-
* @expectedException MustacheException
|
420 |
-
*/
|
421 |
-
public function testPoorlyNestedSections($template) {
|
422 |
-
$m = new Mustache($template);
|
423 |
-
$m->render();
|
424 |
-
}
|
425 |
-
|
426 |
-
public function poorlyNestedSections() {
|
427 |
-
return array(
|
428 |
-
array('{{#foo}}'),
|
429 |
-
array('{{#foo}}{{/bar}}'),
|
430 |
-
array('{{#foo}}{{#bar}}{{/foo}}'),
|
431 |
-
array('{{#foo}}{{#bar}}{{/foo}}{{/bar}}'),
|
432 |
-
array('{{#foo}}{{/bar}}{{/foo}}'),
|
433 |
-
);
|
434 |
-
}
|
435 |
-
|
436 |
-
/**
|
437 |
-
* Ensure that Mustache doesn't double-render sections (allowing mustache injection).
|
438 |
-
*
|
439 |
-
* @group sections
|
440 |
-
*/
|
441 |
-
public function testMustacheInjection() {
|
442 |
-
$template = '{{#foo}}{{bar}}{{/foo}}';
|
443 |
-
$view = array(
|
444 |
-
'foo' => true,
|
445 |
-
'bar' => '{{win}}',
|
446 |
-
'win' => 'FAIL',
|
447 |
-
);
|
448 |
-
|
449 |
-
$m = new Mustache($template, $view);
|
450 |
-
$this->assertEquals('{{win}}', $m->render());
|
451 |
-
}
|
452 |
-
}
|
453 |
-
|
454 |
-
class MustacheExposedOptionsStub extends Mustache {
|
455 |
-
public function getPragmas() {
|
456 |
-
return $this->_pragmas;
|
457 |
-
}
|
458 |
-
public function getCharset() {
|
459 |
-
return $this->_charset;
|
460 |
-
}
|
461 |
-
public function getDelimiters() {
|
462 |
-
return array($this->_otag, $this->_ctag);
|
463 |
-
}
|
464 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/lib/yaml/LICENSE
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
Copyright (c) 2008-2009 Fabien Potencier
|
2 |
-
|
3 |
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4 |
-
of this software and associated documentation files (the "Software"), to deal
|
5 |
-
in the Software without restriction, including without limitation the rights
|
6 |
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7 |
-
copies of the Software, and to permit persons to whom the Software is furnished
|
8 |
-
to do so, subject to the following conditions:
|
9 |
-
|
10 |
-
The above copyright notice and this permission notice shall be included in all
|
11 |
-
copies or substantial portions of the Software.
|
12 |
-
|
13 |
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14 |
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15 |
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16 |
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17 |
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18 |
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19 |
-
THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/lib/yaml/README.markdown
DELETED
@@ -1,15 +0,0 @@
|
|
1 |
-
Symfony YAML: A PHP library that speaks YAML
|
2 |
-
============================================
|
3 |
-
|
4 |
-
Symfony YAML is a PHP library that parses YAML strings and converts them to
|
5 |
-
PHP arrays. It can also converts PHP arrays to YAML strings. Its official
|
6 |
-
website is at http://components.symfony-project.org/yaml/.
|
7 |
-
|
8 |
-
The documentation is to be found in the `doc/` directory.
|
9 |
-
|
10 |
-
Symfony YAML is licensed under the MIT license (see LICENSE file).
|
11 |
-
|
12 |
-
The Symfony YAML library is developed and maintained by the
|
13 |
-
[symfony](http://www.symfony-project.org/) project team. It has been extracted
|
14 |
-
from symfony to be used as a standalone library. Symfony YAML is part of the
|
15 |
-
[symfony components project](http://components.symfony-project.org/).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/lib/yaml/doc/00-Introduction.markdown
DELETED
@@ -1,143 +0,0 @@
|
|
1 |
-
Introduction
|
2 |
-
============
|
3 |
-
|
4 |
-
This book is about *Symfony YAML*, a PHP library part of the Symfony
|
5 |
-
Components project. Its official website is at
|
6 |
-
http://components.symfony-project.org/yaml/.
|
7 |
-
|
8 |
-
>**SIDEBAR**
|
9 |
-
>About the Symfony Components
|
10 |
-
>
|
11 |
-
>[Symfony Components](http://components.symfony-project.org/) are
|
12 |
-
>standalone PHP classes that can be easily used in any
|
13 |
-
>PHP project. Most of the time, they have been developed as part of the
|
14 |
-
>[Symfony framework](http://www.symfony-project.org/), and decoupled from the
|
15 |
-
>main framework later on. You don't need to use the Symfony MVC framework to use
|
16 |
-
>the components.
|
17 |
-
|
18 |
-
What is it?
|
19 |
-
-----------
|
20 |
-
|
21 |
-
Symfony YAML is a PHP library that parses YAML strings and converts them to
|
22 |
-
PHP arrays. It can also converts PHP arrays to YAML strings.
|
23 |
-
|
24 |
-
[YAML](http://www.yaml.org/), YAML Ain't Markup Language, is a human friendly
|
25 |
-
data serialization standard for all programming languages. YAML is a great
|
26 |
-
format for your configuration files. YAML files are as expressive as XML files
|
27 |
-
and as readable as INI files.
|
28 |
-
|
29 |
-
### Easy to use
|
30 |
-
|
31 |
-
There is only one archive to download, and you are ready to go. No
|
32 |
-
configuration, No installation. Drop the files in a directory and start using
|
33 |
-
it today in your projects.
|
34 |
-
|
35 |
-
### Open-Source
|
36 |
-
|
37 |
-
Released under the MIT license, you are free to do whatever you want, even in
|
38 |
-
a commercial environment. You are also encouraged to contribute.
|
39 |
-
|
40 |
-
|
41 |
-
### Used by popular Projects
|
42 |
-
|
43 |
-
Symfony YAML was initially released as part of the symfony framework, one of
|
44 |
-
the most popular PHP web framework. It is also embedded in other popular
|
45 |
-
projects like PHPUnit or Doctrine.
|
46 |
-
|
47 |
-
### Documented
|
48 |
-
|
49 |
-
Symfony YAML is fully documented, with a dedicated online book, and of course
|
50 |
-
a full API documentation.
|
51 |
-
|
52 |
-
### Fast
|
53 |
-
|
54 |
-
One of the goal of Symfony YAML is to find the right balance between speed and
|
55 |
-
features. It supports just the needed feature to handle configuration files.
|
56 |
-
|
57 |
-
### Unit tested
|
58 |
-
|
59 |
-
The library is fully unit-tested. With more than 400 unit tests, the library
|
60 |
-
is stable and is already used in large projects.
|
61 |
-
|
62 |
-
### Real Parser
|
63 |
-
|
64 |
-
It sports a real parser and is able to parse a large subset of the YAML
|
65 |
-
specification, for all your configuration needs. It also means that the parser
|
66 |
-
is pretty robust, easy to understand, and simple enough to extend.
|
67 |
-
|
68 |
-
### Clear error messages
|
69 |
-
|
70 |
-
Whenever you have a syntax problem with your YAML files, the library outputs a
|
71 |
-
helpful message with the filename and the line number where the problem
|
72 |
-
occurred. It eases the debugging a lot.
|
73 |
-
|
74 |
-
### Dump support
|
75 |
-
|
76 |
-
It is also able to dump PHP arrays to YAML with object support, and inline
|
77 |
-
level configuration for pretty outputs.
|
78 |
-
|
79 |
-
### Types Support
|
80 |
-
|
81 |
-
It supports most of the YAML built-in types like dates, integers, octals,
|
82 |
-
booleans, and much more...
|
83 |
-
|
84 |
-
|
85 |
-
### Full merge key support
|
86 |
-
|
87 |
-
Full support for references, aliases, and full merge key. Don't repeat
|
88 |
-
yourself by referencing common configuration bits.
|
89 |
-
|
90 |
-
### PHP Embedding
|
91 |
-
|
92 |
-
YAML files are dynamic. By embedding PHP code inside a YAML file, you have
|
93 |
-
even more power for your configuration files.
|
94 |
-
|
95 |
-
Installation
|
96 |
-
------------
|
97 |
-
|
98 |
-
Symfony YAML can be installed by downloading the source code as a
|
99 |
-
[tar](http://github.com/fabpot/yaml/tarball/master) archive or a
|
100 |
-
[zip](http://github.com/fabpot/yaml/zipball/master) one.
|
101 |
-
|
102 |
-
To stay up-to-date, you can also use the official Subversion
|
103 |
-
[repository](http://svn.symfony-project.com/components/yaml/).
|
104 |
-
|
105 |
-
If you are a Git user, there is an official
|
106 |
-
[mirror](http://github.com/fabpot/yaml), which is updated every 10 minutes.
|
107 |
-
|
108 |
-
If you prefer to install the component globally on your machine, you can use
|
109 |
-
the symfony [PEAR](http://pear.symfony-project.com/) channel server.
|
110 |
-
|
111 |
-
Support
|
112 |
-
-------
|
113 |
-
|
114 |
-
Support questions and enhancements can be discussed on the
|
115 |
-
[mailing-list](http://groups.google.com/group/symfony-components).
|
116 |
-
|
117 |
-
If you find a bug, you can create a ticket at the symfony
|
118 |
-
[trac](http://trac.symfony-project.org/newticket) under the *YAML* component.
|
119 |
-
|
120 |
-
License
|
121 |
-
-------
|
122 |
-
|
123 |
-
The Symfony YAML component is licensed under the *MIT license*:
|
124 |
-
|
125 |
-
>Copyright (c) 2008-2009 Fabien Potencier
|
126 |
-
>
|
127 |
-
>Permission is hereby granted, free of charge, to any person obtaining a copy
|
128 |
-
>of this software and associated documentation files (the "Software"), to deal
|
129 |
-
>in the Software without restriction, including without limitation the rights
|
130 |
-
>to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
131 |
-
>copies of the Software, and to permit persons to whom the Software is furnished
|
132 |
-
>to do so, subject to the following conditions:
|
133 |
-
>
|
134 |
-
>The above copyright notice and this permission notice shall be included in all
|
135 |
-
>copies or substantial portions of the Software.
|
136 |
-
>
|
137 |
-
>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
138 |
-
>IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
139 |
-
>FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
140 |
-
>AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
141 |
-
>LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
142 |
-
>OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
143 |
-
>THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/lib/yaml/doc/01-Usage.markdown
DELETED
@@ -1,110 +0,0 @@
|
|
1 |
-
Using Symfony YAML
|
2 |
-
==================
|
3 |
-
|
4 |
-
The Symfony YAML library is very simple and consists of two main classes: one
|
5 |
-
to parse YAML strings (`sfYamlParser`), and the other to dump a PHP array to
|
6 |
-
a YAML string (`sfYamlDumper`).
|
7 |
-
|
8 |
-
On top of these two core classes, the main `sfYaml` class acts as a thin
|
9 |
-
wrapper and simplifies common uses.
|
10 |
-
|
11 |
-
Reading YAML Files
|
12 |
-
------------------
|
13 |
-
|
14 |
-
The `sfYamlParser::parse()` method parses a YAML string and converts it to a
|
15 |
-
PHP array:
|
16 |
-
|
17 |
-
[php]
|
18 |
-
$yaml = new sfYamlParser();
|
19 |
-
$value = $yaml->parse(file_get_contents('/path/to/file.yaml'));
|
20 |
-
|
21 |
-
If an error occurs during parsing, the parser throws an exception indicating
|
22 |
-
the error type and the line in the original YAML string where the error
|
23 |
-
occurred:
|
24 |
-
|
25 |
-
[php]
|
26 |
-
try
|
27 |
-
{
|
28 |
-
$value = $yaml->parse(file_get_contents('/path/to/file.yaml'));
|
29 |
-
}
|
30 |
-
catch (InvalidArgumentException $e)
|
31 |
-
{
|
32 |
-
// an error occurred during parsing
|
33 |
-
echo "Unable to parse the YAML string: ".$e->getMessage();
|
34 |
-
}
|
35 |
-
|
36 |
-
>**TIP**
|
37 |
-
>As the parser is reentrant, you can use the same parser object to load
|
38 |
-
>different YAML strings.
|
39 |
-
|
40 |
-
When loading a YAML file, it is sometimes better to use the `sfYaml::load()`
|
41 |
-
wrapper method:
|
42 |
-
|
43 |
-
[php]
|
44 |
-
$loader = sfYaml::load('/path/to/file.yml');
|
45 |
-
|
46 |
-
The `sfYaml::load()` static method takes a YAML string or a file containing
|
47 |
-
YAML. Internally, it calls the `sfYamlParser::parse()` method, but with some
|
48 |
-
added bonuses:
|
49 |
-
|
50 |
-
* It executes the YAML file as if it was a PHP file, so that you can embed
|
51 |
-
PHP commands in YAML files;
|
52 |
-
|
53 |
-
* When a file cannot be parsed, it automatically adds the file name to the
|
54 |
-
error message, simplifying debugging when your application is loading
|
55 |
-
several YAML files.
|
56 |
-
|
57 |
-
Writing YAML Files
|
58 |
-
------------------
|
59 |
-
|
60 |
-
The `sfYamlDumper` dumps any PHP array to its YAML representation:
|
61 |
-
|
62 |
-
[php]
|
63 |
-
$array = array('foo' => 'bar', 'bar' => array('foo' => 'bar', 'bar' => 'baz'));
|
64 |
-
|
65 |
-
$dumper = new sfYamlDumper();
|
66 |
-
$yaml = $dumper->dump($array);
|
67 |
-
file_put_contents('/path/to/file.yaml', $yaml);
|
68 |
-
|
69 |
-
>**NOTE**
|
70 |
-
>Of course, the Symfony YAML dumper is not able to dump resources. Also,
|
71 |
-
>even if the dumper is able to dump PHP objects, it is to be considered
|
72 |
-
>an alpha feature.
|
73 |
-
|
74 |
-
If you only need to dump one array, you can use the `sfYaml::dump()` static
|
75 |
-
method shortcut:
|
76 |
-
|
77 |
-
[php]
|
78 |
-
$yaml = sfYaml::dump($array, $inline);
|
79 |
-
|
80 |
-
The YAML format supports two kind of representation for arrays, the expanded
|
81 |
-
one, and the inline one. By default, the dumper uses the inline
|
82 |
-
representation:
|
83 |
-
|
84 |
-
[yml]
|
85 |
-
{ foo: bar, bar: { foo: bar, bar: baz } }
|
86 |
-
|
87 |
-
The second argument of the `dump()` method customizes the level at which the
|
88 |
-
output switches from the expanded representation to the inline one:
|
89 |
-
|
90 |
-
[php]
|
91 |
-
echo $dumper->dump($array, 1);
|
92 |
-
|
93 |
-
-
|
94 |
-
|
95 |
-
[yml]
|
96 |
-
foo: bar
|
97 |
-
bar: { foo: bar, bar: baz }
|
98 |
-
|
99 |
-
-
|
100 |
-
|
101 |
-
[php]
|
102 |
-
echo $dumper->dump($array, 2);
|
103 |
-
|
104 |
-
-
|
105 |
-
|
106 |
-
[yml]
|
107 |
-
foo: bar
|
108 |
-
bar:
|
109 |
-
foo: bar
|
110 |
-
bar: baz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/lib/yaml/doc/02-YAML.markdown
DELETED
@@ -1,312 +0,0 @@
|
|
1 |
-
The YAML Format
|
2 |
-
===============
|
3 |
-
|
4 |
-
According to the official [YAML](http://yaml.org/) website, YAML is "a human
|
5 |
-
friendly data serialization standard for all programming languages".
|
6 |
-
|
7 |
-
Even if the YAML format can describe complex nested data structure, this
|
8 |
-
chapter only describes the minimum set of features needed to use YAML as a
|
9 |
-
configuration file format.
|
10 |
-
|
11 |
-
YAML is a simple language that describes data. As PHP, it has a syntax for
|
12 |
-
simple types like strings, booleans, floats, or integers. But unlike PHP, it
|
13 |
-
makes a difference between arrays (sequences) and hashes (mappings).
|
14 |
-
|
15 |
-
Scalars
|
16 |
-
-------
|
17 |
-
|
18 |
-
The syntax for scalars is similar to the PHP syntax.
|
19 |
-
|
20 |
-
### Strings
|
21 |
-
|
22 |
-
[yml]
|
23 |
-
A string in YAML
|
24 |
-
|
25 |
-
-
|
26 |
-
|
27 |
-
[yml]
|
28 |
-
'A singled-quoted string in YAML'
|
29 |
-
|
30 |
-
>**TIP**
|
31 |
-
>In a single quoted string, a single quote `'` must be doubled:
|
32 |
-
>
|
33 |
-
> [yml]
|
34 |
-
> 'A single quote '' in a single-quoted string'
|
35 |
-
|
36 |
-
[yml]
|
37 |
-
"A double-quoted string in YAML\n"
|
38 |
-
|
39 |
-
Quoted styles are useful when a string starts or ends with one or more
|
40 |
-
relevant spaces.
|
41 |
-
|
42 |
-
>**TIP**
|
43 |
-
>The double-quoted style provides a way to express arbitrary strings, by
|
44 |
-
>using `\` escape sequences. It is very useful when you need to embed a
|
45 |
-
>`\n` or a unicode character in a string.
|
46 |
-
|
47 |
-
When a string contains line breaks, you can use the literal style, indicated
|
48 |
-
by the pipe (`|`), to indicate that the string will span several lines. In
|
49 |
-
literals, newlines are preserved:
|
50 |
-
|
51 |
-
[yml]
|
52 |
-
|
|
53 |
-
\/ /| |\/| |
|
54 |
-
/ / | | | |__
|
55 |
-
|
56 |
-
Alternatively, strings can be written with the folded style, denoted by `>`,
|
57 |
-
where each line break is replaced by a space:
|
58 |
-
|
59 |
-
[yml]
|
60 |
-
>
|
61 |
-
This is a very long sentence
|
62 |
-
that spans several lines in the YAML
|
63 |
-
but which will be rendered as a string
|
64 |
-
without carriage returns.
|
65 |
-
|
66 |
-
>**NOTE**
|
67 |
-
>Notice the two spaces before each line in the previous examples. They
|
68 |
-
>won't appear in the resulting PHP strings.
|
69 |
-
|
70 |
-
### Numbers
|
71 |
-
|
72 |
-
[yml]
|
73 |
-
# an integer
|
74 |
-
12
|
75 |
-
|
76 |
-
-
|
77 |
-
|
78 |
-
[yml]
|
79 |
-
# an octal
|
80 |
-
014
|
81 |
-
|
82 |
-
-
|
83 |
-
|
84 |
-
[yml]
|
85 |
-
# an hexadecimal
|
86 |
-
0xC
|
87 |
-
|
88 |
-
-
|
89 |
-
|
90 |
-
[yml]
|
91 |
-
# a float
|
92 |
-
13.4
|
93 |
-
|
94 |
-
-
|
95 |
-
|
96 |
-
[yml]
|
97 |
-
# an exponential number
|
98 |
-
1.2e+34
|
99 |
-
|
100 |
-
-
|
101 |
-
|
102 |
-
[yml]
|
103 |
-
# infinity
|
104 |
-
.inf
|
105 |
-
|
106 |
-
### Nulls
|
107 |
-
|
108 |
-
Nulls in YAML can be expressed with `null` or `~`.
|
109 |
-
|
110 |
-
### Booleans
|
111 |
-
|
112 |
-
Booleans in YAML are expressed with `true` and `false`.
|
113 |
-
|
114 |
-
>**NOTE**
|
115 |
-
>The symfony YAML parser also recognize `on`, `off`, `yes`, and `no` but
|
116 |
-
>it is strongly discouraged to use them as it has been removed from the
|
117 |
-
>1.2 YAML specifications.
|
118 |
-
|
119 |
-
### Dates
|
120 |
-
|
121 |
-
YAML uses the ISO-8601 standard to express dates:
|
122 |
-
|
123 |
-
[yml]
|
124 |
-
2001-12-14t21:59:43.10-05:00
|
125 |
-
|
126 |
-
-
|
127 |
-
|
128 |
-
[yml]
|
129 |
-
# simple date
|
130 |
-
2002-12-14
|
131 |
-
|
132 |
-
Collections
|
133 |
-
-----------
|
134 |
-
|
135 |
-
A YAML file is rarely used to describe a simple scalar. Most of the time, it
|
136 |
-
describes a collection. A collection can be a sequence or a mapping of
|
137 |
-
elements. Both sequences and mappings are converted to PHP arrays.
|
138 |
-
|
139 |
-
Sequences use a dash followed by a space (`- `):
|
140 |
-
|
141 |
-
[yml]
|
142 |
-
- PHP
|
143 |
-
- Perl
|
144 |
-
- Python
|
145 |
-
|
146 |
-
The previous YAML file is equivalent to the following PHP code:
|
147 |
-
|
148 |
-
[php]
|
149 |
-
array('PHP', 'Perl', 'Python');
|
150 |
-
|
151 |
-
Mappings use a colon followed by a space (`: `) to mark each key/value pair:
|
152 |
-
|
153 |
-
[yml]
|
154 |
-
PHP: 5.2
|
155 |
-
MySQL: 5.1
|
156 |
-
Apache: 2.2.20
|
157 |
-
|
158 |
-
which is equivalent to this PHP code:
|
159 |
-
|
160 |
-
[php]
|
161 |
-
array('PHP' => 5.2, 'MySQL' => 5.1, 'Apache' => '2.2.20');
|
162 |
-
|
163 |
-
>**NOTE**
|
164 |
-
>In a mapping, a key can be any valid scalar.
|
165 |
-
|
166 |
-
The number of spaces between the colon and the value does not matter:
|
167 |
-
|
168 |
-
[yml]
|
169 |
-
PHP: 5.2
|
170 |
-
MySQL: 5.1
|
171 |
-
Apache: 2.2.20
|
172 |
-
|
173 |
-
YAML uses indentation with one or more spaces to describe nested collections:
|
174 |
-
|
175 |
-
[yml]
|
176 |
-
"symfony 1.0":
|
177 |
-
PHP: 5.0
|
178 |
-
Propel: 1.2
|
179 |
-
"symfony 1.2":
|
180 |
-
PHP: 5.2
|
181 |
-
Propel: 1.3
|
182 |
-
|
183 |
-
The following YAML is equivalent to the following PHP code:
|
184 |
-
|
185 |
-
[php]
|
186 |
-
array(
|
187 |
-
'symfony 1.0' => array(
|
188 |
-
'PHP' => 5.0,
|
189 |
-
'Propel' => 1.2,
|
190 |
-
),
|
191 |
-
'symfony 1.2' => array(
|
192 |
-
'PHP' => 5.2,
|
193 |
-
'Propel' => 1.3,
|
194 |
-
),
|
195 |
-
);
|
196 |
-
|
197 |
-
There is one important thing you need to remember when using indentation in a
|
198 |
-
YAML file: *Indentation must be done with one or more spaces, but never with
|
199 |
-
tabulations*.
|
200 |
-
|
201 |
-
You can nest sequences and mappings as you like:
|
202 |
-
|
203 |
-
[yml]
|
204 |
-
'Chapter 1':
|
205 |
-
- Introduction
|
206 |
-
- Event Types
|
207 |
-
'Chapter 2':
|
208 |
-
- Introduction
|
209 |
-
- Helpers
|
210 |
-
|
211 |
-
YAML can also use flow styles for collections, using explicit indicators
|
212 |
-
rather than indentation to denote scope.
|
213 |
-
|
214 |
-
A sequence can be written as a comma separated list within square brackets
|
215 |
-
(`[]`):
|
216 |
-
|
217 |
-
[yml]
|
218 |
-
[PHP, Perl, Python]
|
219 |
-
|
220 |
-
A mapping can be written as a comma separated list of key/values within curly
|
221 |
-
braces (`{}`):
|
222 |
-
|
223 |
-
[yml]
|
224 |
-
{ PHP: 5.2, MySQL: 5.1, Apache: 2.2.20 }
|
225 |
-
|
226 |
-
You can mix and match styles to achieve a better readability:
|
227 |
-
|
228 |
-
[yml]
|
229 |
-
'Chapter 1': [Introduction, Event Types]
|
230 |
-
'Chapter 2': [Introduction, Helpers]
|
231 |
-
|
232 |
-
-
|
233 |
-
|
234 |
-
[yml]
|
235 |
-
"symfony 1.0": { PHP: 5.0, Propel: 1.2 }
|
236 |
-
"symfony 1.2": { PHP: 5.2, Propel: 1.3 }
|
237 |
-
|
238 |
-
Comments
|
239 |
-
--------
|
240 |
-
|
241 |
-
Comments can be added in YAML by prefixing them with a hash mark (`#`):
|
242 |
-
|
243 |
-
[yml]
|
244 |
-
# Comment on a line
|
245 |
-
"symfony 1.0": { PHP: 5.0, Propel: 1.2 } # Comment at the end of a line
|
246 |
-
"symfony 1.2": { PHP: 5.2, Propel: 1.3 }
|
247 |
-
|
248 |
-
>**NOTE**
|
249 |
-
>Comments are simply ignored by the YAML parser and do not need to be
|
250 |
-
>indented according to the current level of nesting in a collection.
|
251 |
-
|
252 |
-
Dynamic YAML files
|
253 |
-
------------------
|
254 |
-
|
255 |
-
In symfony, a YAML file can contain PHP code that is evaluated just before the
|
256 |
-
parsing occurs:
|
257 |
-
|
258 |
-
[php]
|
259 |
-
1.0:
|
260 |
-
version: <?php echo file_get_contents('1.0/VERSION')."\n" ?>
|
261 |
-
1.1:
|
262 |
-
version: "<?php echo file_get_contents('1.1/VERSION') ?>"
|
263 |
-
|
264 |
-
Be careful to not mess up with the indentation. Keep in mind the following
|
265 |
-
simple tips when adding PHP code to a YAML file:
|
266 |
-
|
267 |
-
* The `<?php ?>` statements must always start the line or be embedded in a
|
268 |
-
value.
|
269 |
-
|
270 |
-
* If a `<?php ?>` statement ends a line, you need to explicitly output a new
|
271 |
-
line ("\n").
|
272 |
-
|
273 |
-
<div class="pagebreak"></div>
|
274 |
-
|
275 |
-
A Full Length Example
|
276 |
-
---------------------
|
277 |
-
|
278 |
-
The following example illustrates most YAML notations explained in this
|
279 |
-
document:
|
280 |
-
|
281 |
-
[yml]
|
282 |
-
"symfony 1.0":
|
283 |
-
end_of_maintainance: 2010-01-01
|
284 |
-
is_stable: true
|
285 |
-
release_manager: "Grégoire Hubert"
|
286 |
-
description: >
|
287 |
-
This stable version is the right choice for projects
|
288 |
-
that need to be maintained for a long period of time.
|
289 |
-
latest_beta: ~
|
290 |
-
latest_minor: 1.0.20
|
291 |
-
supported_orms: [Propel]
|
292 |
-
archives: { source: [zip, tgz], sandbox: [zip, tgz] }
|
293 |
-
|
294 |
-
"symfony 1.2":
|
295 |
-
end_of_maintainance: 2008-11-01
|
296 |
-
is_stable: true
|
297 |
-
release_manager: 'Fabian Lange'
|
298 |
-
description: >
|
299 |
-
This stable version is the right choice
|
300 |
-
if you start a new project today.
|
301 |
-
latest_beta: null
|
302 |
-
latest_minor: 1.2.5
|
303 |
-
supported_orms:
|
304 |
-
- Propel
|
305 |
-
- Doctrine
|
306 |
-
archives:
|
307 |
-
source:
|
308 |
-
- zip
|
309 |
-
- tgz
|
310 |
-
sandbox:
|
311 |
-
- zip
|
312 |
-
- tgz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/lib/yaml/doc/A-License.markdown
DELETED
@@ -1,108 +0,0 @@
|
|
1 |
-
Appendix A - License
|
2 |
-
====================
|
3 |
-
|
4 |
-
Attribution-Share Alike 3.0 Unported License
|
5 |
-
--------------------------------------------
|
6 |
-
|
7 |
-
THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
|
8 |
-
|
9 |
-
BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
|
10 |
-
|
11 |
-
1. Definitions
|
12 |
-
|
13 |
-
a. **"Adaptation"** means a work based upon the Work, or upon the Work and other pre-existing works, such as a translation, adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogram or performance and includes cinematographic adaptations or any other form in which the Work may be recast, transformed, or adapted including in any form recognizably derived from the original, except that a work that constitutes a Collection will not be considered an Adaptation for the purpose of this License. For the avoidance of doubt, where the Work is a musical work, performance or phonogram, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered an Adaptation for the purpose of this License.
|
14 |
-
|
15 |
-
b. **"Collection"** means a collection of literary or artistic works, such as encyclopedias and anthologies, or performances, phonograms or broadcasts, or other works or subject matter other than works listed in Section 1(f) below, which, by reason of the selection and arrangement of their contents, constitute intellectual creations, in which the Work is included in its entirety in unmodified form along with one or more other contributions, each constituting separate and independent works in themselves, which together are assembled into a collective whole. A work that constitutes a Collection will not be considered an Adaptation (as defined below) for the purposes of this License.
|
16 |
-
|
17 |
-
c. **"Creative Commons Compatible License"** means a license that is listed at http://creativecommons.org/compatiblelicenses that has been approved by Creative Commons as being essentially equivalent to this License, including, at a minimum, because that license: (i) contains terms that have the same purpose, meaning and effect as the License Elements of this License; and, (ii) explicitly permits the relicensing of adaptations of works made available under that license under this License or a Creative Commons jurisdiction license with the same License Elements as this License.
|
18 |
-
|
19 |
-
d. **"Distribute"** means to make available to the public the original and copies of the Work or Adaptation, as appropriate, through sale or other transfer of ownership.
|
20 |
-
|
21 |
-
e. **"License Elements"** means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, ShareAlike.
|
22 |
-
|
23 |
-
f. **"Licensor"** means the individual, individuals, entity or entities that offer(s) the Work under the terms of this License.
|
24 |
-
|
25 |
-
g. **"Original Author"** means, in the case of a literary or artistic work, the individual, individuals, entity or entities who created the Work or if no individual or entity can be identified, the publisher; and in addition (i) in the case of a performance the actors, singers, musicians, dancers, and other persons who act, sing, deliver, declaim, play in, interpret or otherwise perform literary or artistic works or expressions of folklore; (ii) in the case of a phonogram the producer being the person or legal entity who first fixes the sounds of a performance or other sounds; and, (iii) in the case of broadcasts, the organization that transmits the broadcast.
|
26 |
-
|
27 |
-
h. **"Work"** means the literary and/or artistic work offered under the terms of this License including without limitation any production in the literary, scientific and artistic domain, whatever may be the mode or form of its expression including digital form, such as a book, pamphlet and other writing; a lecture, address, sermon or other work of the same nature; a dramatic or dramatico-musical work; a choreographic work or entertainment in dumb show; a musical composition with or without words; a cinematographic work to which are assimilated works expressed by a process analogous to cinematography; a work of drawing, painting, architecture, sculpture, engraving or lithography; a photographic work to which are assimilated works expressed by a process analogous to photography; a work of applied art; an illustration, map, plan, sketch or three-dimensional work relative to geography, topography, architecture or science; a performance; a broadcast; a phonogram; a compilation of data to the extent it is protected as a copyrightable work; or a work performed by a variety or circus performer to the extent it is not otherwise considered a literary or artistic work.
|
28 |
-
|
29 |
-
i. **"You"** means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
|
30 |
-
|
31 |
-
j. **"Publicly Perform"** means to perform public recitations of the Work and to communicate to the public those public recitations, by any means or process, including by wire or wireless means or public digital performances; to make available to the public Works in such a way that members of the public may access these Works from a place and at a place individually chosen by them; to perform the Work to the public by any means or process and the communication to the public of the performances of the Work, including by public digital performance; to broadcast and rebroadcast the Work by any means including signs, sounds or images.
|
32 |
-
|
33 |
-
k. **"Reproduce"** means to make copies of the Work by any means including without limitation by sound or visual recordings and the right of fixation and reproducing fixations of the Work, including storage of a protected performance or phonogram in digital form or other electronic medium.
|
34 |
-
|
35 |
-
2. Fair Dealing Rights
|
36 |
-
|
37 |
-
Nothing in this License is intended to reduce, limit, or restrict any uses free from copyright or rights arising from limitations or exceptions that are provided for in connection with the copyright protection under copyright law or other applicable laws.
|
38 |
-
|
39 |
-
3. License Grant
|
40 |
-
|
41 |
-
Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:
|
42 |
-
|
43 |
-
a. to Reproduce the Work, to incorporate the Work into one or more Collections, and to Reproduce the Work as incorporated in the Collections;
|
44 |
-
|
45 |
-
b. to create and Reproduce Adaptations provided that any such Adaptation, including any translation in any medium, takes reasonable steps to clearly label, demarcate or otherwise identify that changes were made to the original Work. For example, a translation could be marked "The original work was translated from English to Spanish," or a modification could indicate "The original work has been modified.";
|
46 |
-
|
47 |
-
c. to Distribute and Publicly Perform the Work including as incorporated in Collections; and,
|
48 |
-
|
49 |
-
d. to Distribute and Publicly Perform Adaptations.
|
50 |
-
|
51 |
-
e. For the avoidance of doubt:
|
52 |
-
|
53 |
-
i. **Non-waivable Compulsory License Schemes**. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme cannot be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License;
|
54 |
-
|
55 |
-
ii. **Waivable Compulsory License Schemes**. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme can be waived, the Licensor waives the exclusive right to collect such royalties for any exercise by You of the rights granted under this License; and,
|
56 |
-
|
57 |
-
iii. **Voluntary License Schemes**. The Licensor waives the right to collect royalties, whether individually or, in the event that the Licensor is a member of a collecting society that administers voluntary licensing schemes, via that society, from any exercise by You of the rights granted under this License.
|
58 |
-
|
59 |
-
The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. Subject to Section 8(f), all rights not expressly granted by Licensor are hereby reserved.
|
60 |
-
|
61 |
-
4. Restrictions
|
62 |
-
|
63 |
-
The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:
|
64 |
-
|
65 |
-
a. You may Distribute or Publicly Perform the Work only under the terms of this License. You must include a copy of, or the Uniform Resource Identifier (URI) for, this License with every copy of the Work You Distribute or Publicly Perform. You may not offer or impose any terms on the Work that restrict the terms of this License or the ability of the recipient of the Work to exercise the rights granted to that recipient under the terms of the License. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties with every copy of the Work You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Work, You may not impose any effective technological measures on the Work that restrict the ability of a recipient of the Work from You to exercise the rights granted to that recipient under the terms of the License. This Section 4(a) applies to the Work as incorporated in a Collection, but this does not require the Collection apart from the Work itself to be made subject to the terms of this License. If You create a Collection, upon notice from any Licensor You must, to the extent practicable, remove from the Collection any credit as required by Section 4(c), as requested. If You create an Adaptation, upon notice from any Licensor You must, to the extent practicable, remove from the Adaptation any credit as required by Section 4(c), as requested.
|
66 |
-
|
67 |
-
b. You may Distribute or Publicly Perform an Adaptation only under the terms of: (i) this License; (ii) a later version of this License with the same License Elements as this License; (iii) a Creative Commons jurisdiction license (either this or a later license version) that contains the same License Elements as this License (e.g., Attribution-ShareAlike 3.0 US)); (iv) a Creative Commons Compatible License. If you license the Adaptation under one of the licenses mentioned in (iv), you must comply with the terms of that license. If you license the Adaptation under the terms of any of the licenses mentioned in (i), (ii) or (iii) (the "Applicable License"), you must comply with the terms of the Applicable License generally and the following provisions: (I) You must include a copy of, or the URI for, the Applicable License with every copy of each Adaptation You Distribute or Publicly Perform; (II) You may not offer or impose any terms on the Adaptation that restrict the terms of the Applicable License or the ability of the recipient of the Adaptation to exercise the rights granted to that recipient under the terms of the Applicable License; (III) You must keep intact all notices that refer to the Applicable License and to the disclaimer of warranties with every copy of the Work as included in the Adaptation You Distribute or Publicly Perform; (IV) when You Distribute or Publicly Perform the Adaptation, You may not impose any effective technological measures on the Adaptation that restrict the ability of a recipient of the Adaptation from You to exercise the rights granted to that recipient under the terms of the Applicable License. This Section 4(b) applies to the Adaptation as incorporated in a Collection, but this does not require the Collection apart from the Adaptation itself to be made subject to the terms of the Applicable License.
|
68 |
-
|
69 |
-
c. If You Distribute, or Publicly Perform the Work or any Adaptations or Collections, You must, unless a request has been made pursuant to Section 4(a), keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or if the Original Author and/or Licensor designate another party or parties (e.g., a sponsor institute, publishing entity, journal) for attribution ("Attribution Parties") in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; (ii) the title of the Work if supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and (iv) , consistent with Ssection 3(b), in the case of an Adaptation, a credit identifying the use of the Work in the Adaptation (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). The credit required by this Section 4(c) may be implemented in any reasonable manner; provided, however, that in the case of a Adaptation or Collection, at a minimum such credit will appear, if a credit for all contributing authors of the Adaptation or Collection appears, then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors. For the avoidance of doubt, You may only use the credit required by this Section for the purpose of attribution in the manner set out above and, by exercising Your rights under this License, You may not implicitly or explicitly assert or imply any connection with, sponsorship or endorsement by the Original Author, Licensor and/or Attribution Parties, as appropriate, of You or Your use of the Work, without the separate, express prior written permission of the Original Author, Licensor and/or Attribution Parties.
|
70 |
-
|
71 |
-
d. Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable law, if You Reproduce, Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or Collections, You must not distort, mutilate, modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author's honor or reputation. Licensor agrees that in those jurisdictions (e.g. Japan), in which any exercise of the right granted in Section 3(b) of this License (the right to make Adaptations) would be deemed to be a distortion, mutilation, modification or other derogatory action prejudicial to the Original Author's honor and reputation, the Licensor will waive or not assert, as appropriate, this Section, to the fullest extent permitted by the applicable national law, to enable You to reasonably exercise Your right under Section 3(b) of this License (right to make Adaptations) but not otherwise.
|
72 |
-
|
73 |
-
5. Representations, Warranties and Disclaimer
|
74 |
-
|
75 |
-
UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.
|
76 |
-
|
77 |
-
6. Limitation on Liability
|
78 |
-
|
79 |
-
EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
80 |
-
|
81 |
-
7. Termination
|
82 |
-
|
83 |
-
a. This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Adaptations or Collections from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
|
84 |
-
|
85 |
-
b. Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.
|
86 |
-
|
87 |
-
8. Miscellaneous
|
88 |
-
|
89 |
-
a. Each time You Distribute or Publicly Perform the Work or a Collection, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
|
90 |
-
|
91 |
-
b. Each time You Distribute or Publicly Perform an Adaptation, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
|
92 |
-
|
93 |
-
c. If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
|
94 |
-
|
95 |
-
d. No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
|
96 |
-
|
97 |
-
e. This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.
|
98 |
-
|
99 |
-
f. The rights granted under, and the subject matter referenced, in this License were drafted utilizing the terminology of the Berne Convention for the Protection of Literary and Artistic Works (as amended on September 28, 1979), the Rome Convention of 1961, the WIPO Copyright Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and the Universal Copyright Convention (as revised on July 24, 1971). These rights and subject matter take effect in the relevant jurisdiction in which the License terms are sought to be enforced according to the corresponding provisions of the implementation of those treaty provisions in the applicable national law. If the standard suite of rights granted under applicable copyright law includes additional rights not granted under this License, such additional rights are deemed to be included in the License; this License is not intended to restrict the license of any rights under applicable law.
|
100 |
-
|
101 |
-
>**SIDEBAR**
|
102 |
-
>Creative Commons Notice
|
103 |
-
>
|
104 |
-
>Creative Commons is not a party to this License, and makes no warranty whatsoever in connection with the Work. Creative Commons will not be liable to You or any party on any legal theory for any damages whatsoever, including without limitation any general, special, incidental or consequential damages arising in connection to this license. Notwithstanding the foregoing two (2) sentences, if Creative Commons has expressly identified itself as the Licensor hereunder, it shall have all rights and obligations of Licensor.
|
105 |
-
>
|
106 |
-
>Except for the limited purpose of indicating to the public that the Work is licensed under the CCPL, Creative Commons does not authorize the use by either party of the trademark "Creative Commons" or any related trademark or logo of Creative Commons without the prior written consent of Creative Commons. Any permitted use will be in compliance with Creative Commons' then-current trademark usage guidelines, as may be published on its website or otherwise made available upon request from time to time. For the avoidance of doubt, this trademark restriction does not form part of the License.
|
107 |
-
>
|
108 |
-
>Creative Commons may be contacted at http://creativecommons.org/.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/lib/yaml/lib/sfYaml.php
DELETED
@@ -1,135 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* This file is part of the symfony package.
|
5 |
-
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
|
6 |
-
*
|
7 |
-
* For the full copyright and license information, please view the LICENSE
|
8 |
-
* file that was distributed with this source code.
|
9 |
-
*/
|
10 |
-
|
11 |
-
/**
|
12 |
-
* sfYaml offers convenience methods to load and dump YAML.
|
13 |
-
*
|
14 |
-
* @package symfony
|
15 |
-
* @subpackage yaml
|
16 |
-
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
17 |
-
* @version SVN: $Id: sfYaml.class.php 8988 2008-05-15 20:24:26Z fabien $
|
18 |
-
*/
|
19 |
-
class sfYaml
|
20 |
-
{
|
21 |
-
static protected
|
22 |
-
$spec = '1.2';
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Sets the YAML specification version to use.
|
26 |
-
*
|
27 |
-
* @param string $version The YAML specification version
|
28 |
-
*/
|
29 |
-
static public function setSpecVersion($version)
|
30 |
-
{
|
31 |
-
if (!in_array($version, array('1.1', '1.2')))
|
32 |
-
{
|
33 |
-
throw new InvalidArgumentException(sprintf('Version %s of the YAML specifications is not supported', $version));
|
34 |
-
}
|
35 |
-
|
36 |
-
self::$spec = $version;
|
37 |
-
}
|
38 |
-
|
39 |
-
/**
|
40 |
-
* Gets the YAML specification version to use.
|
41 |
-
*
|
42 |
-
* @return string The YAML specification version
|
43 |
-
*/
|
44 |
-
static public function getSpecVersion()
|
45 |
-
{
|
46 |
-
return self::$spec;
|
47 |
-
}
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Loads YAML into a PHP array.
|
51 |
-
*
|
52 |
-
* The load method, when supplied with a YAML stream (string or file),
|
53 |
-
* will do its best to convert YAML in a file into a PHP array.
|
54 |
-
*
|
55 |
-
* Usage:
|
56 |
-
* <code>
|
57 |
-
* $array = sfYaml::load('config.yml');
|
58 |
-
* print_r($array);
|
59 |
-
* </code>
|
60 |
-
*
|
61 |
-
* @param string $input Path of YAML file or string containing YAML
|
62 |
-
*
|
63 |
-
* @return array The YAML converted to a PHP array
|
64 |
-
*
|
65 |
-
* @throws InvalidArgumentException If the YAML is not valid
|
66 |
-
*/
|
67 |
-
public static function load($input)
|
68 |
-
{
|
69 |
-
$file = '';
|
70 |
-
|
71 |
-
// if input is a file, process it
|
72 |
-
if (strpos($input, "\n") === false && is_file($input))
|
73 |
-
{
|
74 |
-
$file = $input;
|
75 |
-
|
76 |
-
ob_start();
|
77 |
-
$retval = include($input);
|
78 |
-
$content = ob_get_clean();
|
79 |
-
|
80 |
-
// if an array is returned by the config file assume it's in plain php form else in YAML
|
81 |
-
$input = is_array($retval) ? $retval : $content;
|
82 |
-
}
|
83 |
-
|
84 |
-
// if an array is returned by the config file assume it's in plain php form else in YAML
|
85 |
-
if (is_array($input))
|
86 |
-
{
|
87 |
-
return $input;
|
88 |
-
}
|
89 |
-
|
90 |
-
require_once dirname(__FILE__).'/sfYamlParser.php';
|
91 |
-
|
92 |
-
$yaml = new sfYamlParser();
|
93 |
-
|
94 |
-
try
|
95 |
-
{
|
96 |
-
$ret = $yaml->parse($input);
|
97 |
-
}
|
98 |
-
catch (Exception $e)
|
99 |
-
{
|
100 |
-
throw new InvalidArgumentException(sprintf('Unable to parse %s: %s', $file ? sprintf('file "%s"', $file) : 'string', $e->getMessage()));
|
101 |
-
}
|
102 |
-
|
103 |
-
return $ret;
|
104 |
-
}
|
105 |
-
|
106 |
-
/**
|
107 |
-
* Dumps a PHP array to a YAML string.
|
108 |
-
*
|
109 |
-
* The dump method, when supplied with an array, will do its best
|
110 |
-
* to convert the array into friendly YAML.
|
111 |
-
*
|
112 |
-
* @param array $array PHP array
|
113 |
-
* @param integer $inline The level where you switch to inline YAML
|
114 |
-
*
|
115 |
-
* @return string A YAML string representing the original PHP array
|
116 |
-
*/
|
117 |
-
public static function dump($array, $inline = 2)
|
118 |
-
{
|
119 |
-
require_once dirname(__FILE__).'/sfYamlDumper.php';
|
120 |
-
|
121 |
-
$yaml = new sfYamlDumper();
|
122 |
-
|
123 |
-
return $yaml->dump($array, $inline);
|
124 |
-
}
|
125 |
-
}
|
126 |
-
|
127 |
-
/**
|
128 |
-
* Wraps echo to automatically provide a newline.
|
129 |
-
*
|
130 |
-
* @param string $string The string to echo with new line
|
131 |
-
*/
|
132 |
-
function echoln($string)
|
133 |
-
{
|
134 |
-
echo $string."\n";
|
135 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/lib/yaml/lib/sfYamlDumper.php
DELETED
@@ -1,60 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* This file is part of the symfony package.
|
5 |
-
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
6 |
-
*
|
7 |
-
* For the full copyright and license information, please view the LICENSE
|
8 |
-
* file that was distributed with this source code.
|
9 |
-
*/
|
10 |
-
|
11 |
-
require_once(dirname(__FILE__).'/sfYamlInline.php');
|
12 |
-
|
13 |
-
/**
|
14 |
-
* sfYamlDumper dumps PHP variables to YAML strings.
|
15 |
-
*
|
16 |
-
* @package symfony
|
17 |
-
* @subpackage yaml
|
18 |
-
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
19 |
-
* @version SVN: $Id: sfYamlDumper.class.php 10575 2008-08-01 13:08:42Z nicolas $
|
20 |
-
*/
|
21 |
-
class sfYamlDumper
|
22 |
-
{
|
23 |
-
/**
|
24 |
-
* Dumps a PHP value to YAML.
|
25 |
-
*
|
26 |
-
* @param mixed $input The PHP value
|
27 |
-
* @param integer $inline The level where you switch to inline YAML
|
28 |
-
* @param integer $indent The level o indentation indentation (used internally)
|
29 |
-
*
|
30 |
-
* @return string The YAML representation of the PHP value
|
31 |
-
*/
|
32 |
-
public function dump($input, $inline = 0, $indent = 0)
|
33 |
-
{
|
34 |
-
$output = '';
|
35 |
-
$prefix = $indent ? str_repeat(' ', $indent) : '';
|
36 |
-
|
37 |
-
if ($inline <= 0 || !is_array($input) || empty($input))
|
38 |
-
{
|
39 |
-
$output .= $prefix.sfYamlInline::dump($input);
|
40 |
-
}
|
41 |
-
else
|
42 |
-
{
|
43 |
-
$isAHash = array_keys($input) !== range(0, count($input) - 1);
|
44 |
-
|
45 |
-
foreach ($input as $key => $value)
|
46 |
-
{
|
47 |
-
$willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
|
48 |
-
|
49 |
-
$output .= sprintf('%s%s%s%s',
|
50 |
-
$prefix,
|
51 |
-
$isAHash ? sfYamlInline::dump($key).':' : '-',
|
52 |
-
$willBeInlined ? ' ' : "\n",
|
53 |
-
$this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + 2)
|
54 |
-
).($willBeInlined ? "\n" : '');
|
55 |
-
}
|
56 |
-
}
|
57 |
-
|
58 |
-
return $output;
|
59 |
-
}
|
60 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/lib/yaml/lib/sfYamlInline.php
DELETED
@@ -1,442 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* This file is part of the symfony package.
|
5 |
-
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
6 |
-
*
|
7 |
-
* For the full copyright and license information, please view the LICENSE
|
8 |
-
* file that was distributed with this source code.
|
9 |
-
*/
|
10 |
-
|
11 |
-
require_once dirname(__FILE__).'/sfYaml.php';
|
12 |
-
|
13 |
-
/**
|
14 |
-
* sfYamlInline implements a YAML parser/dumper for the YAML inline syntax.
|
15 |
-
*
|
16 |
-
* @package symfony
|
17 |
-
* @subpackage yaml
|
18 |
-
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
19 |
-
* @version SVN: $Id: sfYamlInline.class.php 16177 2009-03-11 08:32:48Z fabien $
|
20 |
-
*/
|
21 |
-
class sfYamlInline
|
22 |
-
{
|
23 |
-
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\']*(?:\'\'[^\']*)*)\')';
|
24 |
-
|
25 |
-
/**
|
26 |
-
* Convert a YAML string to a PHP array.
|
27 |
-
*
|
28 |
-
* @param string $value A YAML string
|
29 |
-
*
|
30 |
-
* @return array A PHP array representing the YAML string
|
31 |
-
*/
|
32 |
-
static public function load($value)
|
33 |
-
{
|
34 |
-
$value = trim($value);
|
35 |
-
|
36 |
-
if (0 == strlen($value))
|
37 |
-
{
|
38 |
-
return '';
|
39 |
-
}
|
40 |
-
|
41 |
-
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2)
|
42 |
-
{
|
43 |
-
$mbEncoding = mb_internal_encoding();
|
44 |
-
mb_internal_encoding('ASCII');
|
45 |
-
}
|
46 |
-
|
47 |
-
switch ($value[0])
|
48 |
-
{
|
49 |
-
case '[':
|
50 |
-
$result = self::parseSequence($value);
|
51 |
-
break;
|
52 |
-
case '{':
|
53 |
-
$result = self::parseMapping($value);
|
54 |
-
break;
|
55 |
-
default:
|
56 |
-
$result = self::parseScalar($value);
|
57 |
-
}
|
58 |
-
|
59 |
-
if (isset($mbEncoding))
|
60 |
-
{
|
61 |
-
mb_internal_encoding($mbEncoding);
|
62 |
-
}
|
63 |
-
|
64 |
-
return $result;
|
65 |
-
}
|
66 |
-
|
67 |
-
/**
|
68 |
-
* Dumps a given PHP variable to a YAML string.
|
69 |
-
*
|
70 |
-
* @param mixed $value The PHP variable to convert
|
71 |
-
*
|
72 |
-
* @return string The YAML string representing the PHP array
|
73 |
-
*/
|
74 |
-
static public function dump($value)
|
75 |
-
{
|
76 |
-
if ('1.1' === sfYaml::getSpecVersion())
|
77 |
-
{
|
78 |
-
$trueValues = array('true', 'on', '+', 'yes', 'y');
|
79 |
-
$falseValues = array('false', 'off', '-', 'no', 'n');
|
80 |
-
}
|
81 |
-
else
|
82 |
-
{
|
83 |
-
$trueValues = array('true');
|
84 |
-
$falseValues = array('false');
|
85 |
-
}
|
86 |
-
|
87 |
-
switch (true)
|
88 |
-
{
|
89 |
-
case is_resource($value):
|
90 |
-
throw new InvalidArgumentException('Unable to dump PHP resources in a YAML file.');
|
91 |
-
case is_object($value):
|
92 |
-
return '!!php/object:'.serialize($value);
|
93 |
-
case is_array($value):
|
94 |
-
return self::dumpArray($value);
|
95 |
-
case null === $value:
|
96 |
-
return 'null';
|
97 |
-
case true === $value:
|
98 |
-
return 'true';
|
99 |
-
case false === $value:
|
100 |
-
return 'false';
|
101 |
-
case ctype_digit($value):
|
102 |
-
return is_string($value) ? "'$value'" : (int) $value;
|
103 |
-
case is_numeric($value):
|
104 |
-
return is_infinite($value) ? str_ireplace('INF', '.Inf', strval($value)) : (is_string($value) ? "'$value'" : $value);
|
105 |
-
case false !== strpos($value, "\n") || false !== strpos($value, "\r"):
|
106 |
-
return sprintf('"%s"', str_replace(array('"', "\n", "\r"), array('\\"', '\n', '\r'), $value));
|
107 |
-
case preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ - ? | < > = ! % @ ` ]/x', $value):
|
108 |
-
return sprintf("'%s'", str_replace('\'', '\'\'', $value));
|
109 |
-
case '' == $value:
|
110 |
-
return "''";
|
111 |
-
case preg_match(self::getTimestampRegex(), $value):
|
112 |
-
return "'$value'";
|
113 |
-
case in_array(strtolower($value), $trueValues):
|
114 |
-
return "'$value'";
|
115 |
-
case in_array(strtolower($value), $falseValues):
|
116 |
-
return "'$value'";
|
117 |
-
case in_array(strtolower($value), array('null', '~')):
|
118 |
-
return "'$value'";
|
119 |
-
default:
|
120 |
-
return $value;
|
121 |
-
}
|
122 |
-
}
|
123 |
-
|
124 |
-
/**
|
125 |
-
* Dumps a PHP array to a YAML string.
|
126 |
-
*
|
127 |
-
* @param array $value The PHP array to dump
|
128 |
-
*
|
129 |
-
* @return string The YAML string representing the PHP array
|
130 |
-
*/
|
131 |
-
static protected function dumpArray($value)
|
132 |
-
{
|
133 |
-
// array
|
134 |
-
$keys = array_keys($value);
|
135 |
-
if (
|
136 |
-
(1 == count($keys) && '0' == $keys[0])
|
137 |
-
||
|
138 |
-
(count($keys) > 1 && array_reduce($keys, create_function('$v,$w', 'return (integer) $v + $w;'), 0) == count($keys) * (count($keys) - 1) / 2))
|
139 |
-
{
|
140 |
-
$output = array();
|
141 |
-
foreach ($value as $val)
|
142 |
-
{
|
143 |
-
$output[] = self::dump($val);
|
144 |
-
}
|
145 |
-
|
146 |
-
return sprintf('[%s]', implode(', ', $output));
|
147 |
-
}
|
148 |
-
|
149 |
-
// mapping
|
150 |
-
$output = array();
|
151 |
-
foreach ($value as $key => $val)
|
152 |
-
{
|
153 |
-
$output[] = sprintf('%s: %s', self::dump($key), self::dump($val));
|
154 |
-
}
|
155 |
-
|
156 |
-
return sprintf('{ %s }', implode(', ', $output));
|
157 |
-
}
|
158 |
-
|
159 |
-
/**
|
160 |
-
* Parses a scalar to a YAML string.
|
161 |
-
*
|
162 |
-
* @param scalar $scalar
|
163 |
-
* @param string $delimiters
|
164 |
-
* @param array $stringDelimiter
|
165 |
-
* @param integer $i
|
166 |
-
* @param boolean $evaluate
|
167 |
-
*
|
168 |
-
* @return string A YAML string
|
169 |
-
*/
|
170 |
-
static public function parseScalar($scalar, $delimiters = null, $stringDelimiters = array('"', "'"), &$i = 0, $evaluate = true)
|
171 |
-
{
|
172 |
-
if (in_array($scalar[$i], $stringDelimiters))
|
173 |
-
{
|
174 |
-
// quoted scalar
|
175 |
-
$output = self::parseQuotedScalar($scalar, $i);
|
176 |
-
}
|
177 |
-
else
|
178 |
-
{
|
179 |
-
// "normal" string
|
180 |
-
if (!$delimiters)
|
181 |
-
{
|
182 |
-
$output = substr($scalar, $i);
|
183 |
-
$i += strlen($output);
|
184 |
-
|
185 |
-
// remove comments
|
186 |
-
if (false !== $strpos = strpos($output, ' #'))
|
187 |
-
{
|
188 |
-
$output = rtrim(substr($output, 0, $strpos));
|
189 |
-
}
|
190 |
-
}
|
191 |
-
else if (preg_match('/^(.+?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match))
|
192 |
-
{
|
193 |
-
$output = $match[1];
|
194 |
-
$i += strlen($output);
|
195 |
-
}
|
196 |
-
else
|
197 |
-
{
|
198 |
-
throw new InvalidArgumentException(sprintf('Malformed inline YAML string (%s).', $scalar));
|
199 |
-
}
|
200 |
-
|
201 |
-
$output = $evaluate ? self::evaluateScalar($output) : $output;
|
202 |
-
}
|
203 |
-
|
204 |
-
return $output;
|
205 |
-
}
|
206 |
-
|
207 |
-
/**
|
208 |
-
* Parses a quoted scalar to YAML.
|
209 |
-
*
|
210 |
-
* @param string $scalar
|
211 |
-
* @param integer $i
|
212 |
-
*
|
213 |
-
* @return string A YAML string
|
214 |
-
*/
|
215 |
-
static protected function parseQuotedScalar($scalar, &$i)
|
216 |
-
{
|
217 |
-
if (!preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match))
|
218 |
-
{
|
219 |
-
throw new InvalidArgumentException(sprintf('Malformed inline YAML string (%s).', substr($scalar, $i)));
|
220 |
-
}
|
221 |
-
|
222 |
-
$output = substr($match[0], 1, strlen($match[0]) - 2);
|
223 |
-
|
224 |
-
if ('"' == $scalar[$i])
|
225 |
-
{
|
226 |
-
// evaluate the string
|
227 |
-
$output = str_replace(array('\\"', '\\n', '\\r'), array('"', "\n", "\r"), $output);
|
228 |
-
}
|
229 |
-
else
|
230 |
-
{
|
231 |
-
// unescape '
|
232 |
-
$output = str_replace('\'\'', '\'', $output);
|
233 |
-
}
|
234 |
-
|
235 |
-
$i += strlen($match[0]);
|
236 |
-
|
237 |
-
return $output;
|
238 |
-
}
|
239 |
-
|
240 |
-
/**
|
241 |
-
* Parses a sequence to a YAML string.
|
242 |
-
*
|
243 |
-
* @param string $sequence
|
244 |
-
* @param integer $i
|
245 |
-
*
|
246 |
-
* @return string A YAML string
|
247 |
-
*/
|
248 |
-
static protected function parseSequence($sequence, &$i = 0)
|
249 |
-
{
|
250 |
-
$output = array();
|
251 |
-
$len = strlen($sequence);
|
252 |
-
$i += 1;
|
253 |
-
|
254 |
-
// [foo, bar, ...]
|
255 |
-
while ($i < $len)
|
256 |
-
{
|
257 |
-
switch ($sequence[$i])
|
258 |
-
{
|
259 |
-
case '[':
|
260 |
-
// nested sequence
|
261 |
-
$output[] = self::parseSequence($sequence, $i);
|
262 |
-
break;
|
263 |
-
case '{':
|
264 |
-
// nested mapping
|
265 |
-
$output[] = self::parseMapping($sequence, $i);
|
266 |
-
break;
|
267 |
-
case ']':
|
268 |
-
return $output;
|
269 |
-
case ',':
|
270 |
-
case ' ':
|
271 |
-
break;
|
272 |
-
default:
|
273 |
-
$isQuoted = in_array($sequence[$i], array('"', "'"));
|
274 |
-
$value = self::parseScalar($sequence, array(',', ']'), array('"', "'"), $i);
|
275 |
-
|
276 |
-
if (!$isQuoted && false !== strpos($value, ': '))
|
277 |
-
{
|
278 |
-
// embedded mapping?
|
279 |
-
try
|
280 |
-
{
|
281 |
-
$value = self::parseMapping('{'.$value.'}');
|
282 |
-
}
|
283 |
-
catch (InvalidArgumentException $e)
|
284 |
-
{
|
285 |
-
// no, it's not
|
286 |
-
}
|
287 |
-
}
|
288 |
-
|
289 |
-
$output[] = $value;
|
290 |
-
|
291 |
-
--$i;
|
292 |
-
}
|
293 |
-
|
294 |
-
++$i;
|
295 |
-
}
|
296 |
-
|
297 |
-
throw new InvalidArgumentException(sprintf('Malformed inline YAML string %s', $sequence));
|
298 |
-
}
|
299 |
-
|
300 |
-
/**
|
301 |
-
* Parses a mapping to a YAML string.
|
302 |
-
*
|
303 |
-
* @param string $mapping
|
304 |
-
* @param integer $i
|
305 |
-
*
|
306 |
-
* @return string A YAML string
|
307 |
-
*/
|
308 |
-
static protected function parseMapping($mapping, &$i = 0)
|
309 |
-
{
|
310 |
-
$output = array();
|
311 |
-
$len = strlen($mapping);
|
312 |
-
$i += 1;
|
313 |
-
|
314 |
-
// {foo: bar, bar:foo, ...}
|
315 |
-
while ($i < $len)
|
316 |
-
{
|
317 |
-
switch ($mapping[$i])
|
318 |
-
{
|
319 |
-
case ' ':
|
320 |
-
case ',':
|
321 |
-
++$i;
|
322 |
-
continue 2;
|
323 |
-
case '}':
|
324 |
-
return $output;
|
325 |
-
}
|
326 |
-
|
327 |
-
// key
|
328 |
-
$key = self::parseScalar($mapping, array(':', ' '), array('"', "'"), $i, false);
|
329 |
-
|
330 |
-
// value
|
331 |
-
$done = false;
|
332 |
-
while ($i < $len)
|
333 |
-
{
|
334 |
-
switch ($mapping[$i])
|
335 |
-
{
|
336 |
-
case '[':
|
337 |
-
// nested sequence
|
338 |
-
$output[$key] = self::parseSequence($mapping, $i);
|
339 |
-
$done = true;
|
340 |
-
break;
|
341 |
-
case '{':
|
342 |
-
// nested mapping
|
343 |
-
$output[$key] = self::parseMapping($mapping, $i);
|
344 |
-
$done = true;
|
345 |
-
break;
|
346 |
-
case ':':
|
347 |
-
case ' ':
|
348 |
-
break;
|
349 |
-
default:
|
350 |
-
$output[$key] = self::parseScalar($mapping, array(',', '}'), array('"', "'"), $i);
|
351 |
-
$done = true;
|
352 |
-
--$i;
|
353 |
-
}
|
354 |
-
|
355 |
-
++$i;
|
356 |
-
|
357 |
-
if ($done)
|
358 |
-
{
|
359 |
-
continue 2;
|
360 |
-
}
|
361 |
-
}
|
362 |
-
}
|
363 |
-
|
364 |
-
throw new InvalidArgumentException(sprintf('Malformed inline YAML string %s', $mapping));
|
365 |
-
}
|
366 |
-
|
367 |
-
/**
|
368 |
-
* Evaluates scalars and replaces magic values.
|
369 |
-
*
|
370 |
-
* @param string $scalar
|
371 |
-
*
|
372 |
-
* @return string A YAML string
|
373 |
-
*/
|
374 |
-
static protected function evaluateScalar($scalar)
|
375 |
-
{
|
376 |
-
$scalar = trim($scalar);
|
377 |
-
|
378 |
-
if ('1.1' === sfYaml::getSpecVersion())
|
379 |
-
{
|
380 |
-
$trueValues = array('true', 'on', '+', 'yes', 'y');
|
381 |
-
$falseValues = array('false', 'off', '-', 'no', 'n');
|
382 |
-
}
|
383 |
-
else
|
384 |
-
{
|
385 |
-
$trueValues = array('true');
|
386 |
-
$falseValues = array('false');
|
387 |
-
}
|
388 |
-
|
389 |
-
switch (true)
|
390 |
-
{
|
391 |
-
case 'null' == strtolower($scalar):
|
392 |
-
case '' == $scalar:
|
393 |
-
case '~' == $scalar:
|
394 |
-
return null;
|
395 |
-
case 0 === strpos($scalar, '!str'):
|
396 |
-
return (string) substr($scalar, 5);
|
397 |
-
case 0 === strpos($scalar, '! '):
|
398 |
-
return intval(self::parseScalar(substr($scalar, 2)));
|
399 |
-
case 0 === strpos($scalar, '!!php/object:'):
|
400 |
-
return unserialize(substr($scalar, 13));
|
401 |
-
case ctype_digit($scalar):
|
402 |
-
$raw = $scalar;
|
403 |
-
$cast = intval($scalar);
|
404 |
-
return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
|
405 |
-
case in_array(strtolower($scalar), $trueValues):
|
406 |
-
return true;
|
407 |
-
case in_array(strtolower($scalar), $falseValues):
|
408 |
-
return false;
|
409 |
-
case is_numeric($scalar):
|
410 |
-
return '0x' == $scalar[0].$scalar[1] ? hexdec($scalar) : floatval($scalar);
|
411 |
-
case 0 == strcasecmp($scalar, '.inf'):
|
412 |
-
case 0 == strcasecmp($scalar, '.NaN'):
|
413 |
-
return -log(0);
|
414 |
-
case 0 == strcasecmp($scalar, '-.inf'):
|
415 |
-
return log(0);
|
416 |
-
case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $scalar):
|
417 |
-
return floatval(str_replace(',', '', $scalar));
|
418 |
-
case preg_match(self::getTimestampRegex(), $scalar):
|
419 |
-
return strtotime($scalar);
|
420 |
-
default:
|
421 |
-
return (string) $scalar;
|
422 |
-
}
|
423 |
-
}
|
424 |
-
|
425 |
-
static protected function getTimestampRegex()
|
426 |
-
{
|
427 |
-
return <<<EOF
|
428 |
-
~^
|
429 |
-
(?P<year>[0-9][0-9][0-9][0-9])
|
430 |
-
-(?P<month>[0-9][0-9]?)
|
431 |
-
-(?P<day>[0-9][0-9]?)
|
432 |
-
(?:(?:[Tt]|[ \t]+)
|
433 |
-
(?P<hour>[0-9][0-9]?)
|
434 |
-
:(?P<minute>[0-9][0-9])
|
435 |
-
:(?P<second>[0-9][0-9])
|
436 |
-
(?:\.(?P<fraction>[0-9]*))?
|
437 |
-
(?:[ \t]*(?P<tz>Z|(?P<tz_sign>[-+])(?P<tz_hour>[0-9][0-9]?)
|
438 |
-
(?::(?P<tz_minute>[0-9][0-9]))?))?)?
|
439 |
-
$~x
|
440 |
-
EOF;
|
441 |
-
}
|
442 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/lib/yaml/lib/sfYamlParser.php
DELETED
@@ -1,622 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* This file is part of the symfony package.
|
5 |
-
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
6 |
-
*
|
7 |
-
* For the full copyright and license information, please view the LICENSE
|
8 |
-
* file that was distributed with this source code.
|
9 |
-
*/
|
10 |
-
|
11 |
-
require_once(dirname(__FILE__).'/sfYamlInline.php');
|
12 |
-
|
13 |
-
if (!defined('PREG_BAD_UTF8_OFFSET_ERROR'))
|
14 |
-
{
|
15 |
-
define('PREG_BAD_UTF8_OFFSET_ERROR', 5);
|
16 |
-
}
|
17 |
-
|
18 |
-
/**
|
19 |
-
* sfYamlParser parses YAML strings to convert them to PHP arrays.
|
20 |
-
*
|
21 |
-
* @package symfony
|
22 |
-
* @subpackage yaml
|
23 |
-
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
24 |
-
* @version SVN: $Id: sfYamlParser.class.php 10832 2008-08-13 07:46:08Z fabien $
|
25 |
-
*/
|
26 |
-
class sfYamlParser
|
27 |
-
{
|
28 |
-
protected
|
29 |
-
$offset = 0,
|
30 |
-
$lines = array(),
|
31 |
-
$currentLineNb = -1,
|
32 |
-
$currentLine = '',
|
33 |
-
$refs = array();
|
34 |
-
|
35 |
-
/**
|
36 |
-
* Constructor
|
37 |
-
*
|
38 |
-
* @param integer $offset The offset of YAML document (used for line numbers in error messages)
|
39 |
-
*/
|
40 |
-
public function __construct($offset = 0)
|
41 |
-
{
|
42 |
-
$this->offset = $offset;
|
43 |
-
}
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Parses a YAML string to a PHP value.
|
47 |
-
*
|
48 |
-
* @param string $value A YAML string
|
49 |
-
*
|
50 |
-
* @return mixed A PHP value
|
51 |
-
*
|
52 |
-
* @throws InvalidArgumentException If the YAML is not valid
|
53 |
-
*/
|
54 |
-
public function parse($value)
|
55 |
-
{
|
56 |
-
$this->currentLineNb = -1;
|
57 |
-
$this->currentLine = '';
|
58 |
-
$this->lines = explode("\n", $this->cleanup($value));
|
59 |
-
|
60 |
-
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2)
|
61 |
-
{
|
62 |
-
$mbEncoding = mb_internal_encoding();
|
63 |
-
mb_internal_encoding('UTF-8');
|
64 |
-
}
|
65 |
-
|
66 |
-
$data = array();
|
67 |
-
while ($this->moveToNextLine())
|
68 |
-
{
|
69 |
-
if ($this->isCurrentLineEmpty())
|
70 |
-
{
|
71 |
-
continue;
|
72 |
-
}
|
73 |
-
|
74 |
-
// tab?
|
75 |
-
if (preg_match('#^\t+#', $this->currentLine))
|
76 |
-
{
|
77 |
-
throw new InvalidArgumentException(sprintf('A YAML file cannot contain tabs as indentation at line %d (%s).', $this->getRealCurrentLineNb() + 1, $this->currentLine));
|
78 |
-
}
|
79 |
-
|
80 |
-
$isRef = $isInPlace = $isProcessed = false;
|
81 |
-
if (preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+?))?\s*$#u', $this->currentLine, $values))
|
82 |
-
{
|
83 |
-
if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches))
|
84 |
-
{
|
85 |
-
$isRef = $matches['ref'];
|
86 |
-
$values['value'] = $matches['value'];
|
87 |
-
}
|
88 |
-
|
89 |
-
// array
|
90 |
-
if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#'))
|
91 |
-
{
|
92 |
-
$c = $this->getRealCurrentLineNb() + 1;
|
93 |
-
$parser = new sfYamlParser($c);
|
94 |
-
$parser->refs =& $this->refs;
|
95 |
-
$data[] = $parser->parse($this->getNextEmbedBlock());
|
96 |
-
}
|
97 |
-
else
|
98 |
-
{
|
99 |
-
if (isset($values['leadspaces'])
|
100 |
-
&& ' ' == $values['leadspaces']
|
101 |
-
&& preg_match('#^(?P<key>'.sfYamlInline::REGEX_QUOTED_STRING.'|[^ \'"\{].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $values['value'], $matches))
|
102 |
-
{
|
103 |
-
// this is a compact notation element, add to next block and parse
|
104 |
-
$c = $this->getRealCurrentLineNb();
|
105 |
-
$parser = new sfYamlParser($c);
|
106 |
-
$parser->refs =& $this->refs;
|
107 |
-
|
108 |
-
$block = $values['value'];
|
109 |
-
if (!$this->isNextLineIndented())
|
110 |
-
{
|
111 |
-
$block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + 2);
|
112 |
-
}
|
113 |
-
|
114 |
-
$data[] = $parser->parse($block);
|
115 |
-
}
|
116 |
-
else
|
117 |
-
{
|
118 |
-
$data[] = $this->parseValue($values['value']);
|
119 |
-
}
|
120 |
-
}
|
121 |
-
}
|
122 |
-
else if (preg_match('#^(?P<key>'.sfYamlInline::REGEX_QUOTED_STRING.'|[^ \'"].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->currentLine, $values))
|
123 |
-
{
|
124 |
-
$key = sfYamlInline::parseScalar($values['key']);
|
125 |
-
|
126 |
-
if ('<<' === $key)
|
127 |
-
{
|
128 |
-
if (isset($values['value']) && '*' === substr($values['value'], 0, 1))
|
129 |
-
{
|
130 |
-
$isInPlace = substr($values['value'], 1);
|
131 |
-
if (!array_key_exists($isInPlace, $this->refs))
|
132 |
-
{
|
133 |
-
throw new InvalidArgumentException(sprintf('Reference "%s" does not exist at line %s (%s).', $isInPlace, $this->getRealCurrentLineNb() + 1, $this->currentLine));
|
134 |
-
}
|
135 |
-
}
|
136 |
-
else
|
137 |
-
{
|
138 |
-
if (isset($values['value']) && $values['value'] !== '')
|
139 |
-
{
|
140 |
-
$value = $values['value'];
|
141 |
-
}
|
142 |
-
else
|
143 |
-
{
|
144 |
-
$value = $this->getNextEmbedBlock();
|
145 |
-
}
|
146 |
-
$c = $this->getRealCurrentLineNb() + 1;
|
147 |
-
$parser = new sfYamlParser($c);
|
148 |
-
$parser->refs =& $this->refs;
|
149 |
-
$parsed = $parser->parse($value);
|
150 |
-
|
151 |
-
$merged = array();
|
152 |
-
if (!is_array($parsed))
|
153 |
-
{
|
154 |
-
throw new InvalidArgumentException(sprintf("YAML merge keys used with a scalar value instead of an array at line %s (%s)", $this->getRealCurrentLineNb() + 1, $this->currentLine));
|
155 |
-
}
|
156 |
-
else if (isset($parsed[0]))
|
157 |
-
{
|
158 |
-
// Numeric array, merge individual elements
|
159 |
-
foreach (array_reverse($parsed) as $parsedItem)
|
160 |
-
{
|
161 |
-
if (!is_array($parsedItem))
|
162 |
-
{
|
163 |
-
throw new InvalidArgumentException(sprintf("Merge items must be arrays at line %s (%s).", $this->getRealCurrentLineNb() + 1, $parsedItem));
|
164 |
-
}
|
165 |
-
$merged = array_merge($parsedItem, $merged);
|
166 |
-
}
|
167 |
-
}
|
168 |
-
else
|
169 |
-
{
|
170 |
-
// Associative array, merge
|
171 |
-
$merged = array_merge($merge, $parsed);
|
172 |
-
}
|
173 |
-
|
174 |
-
$isProcessed = $merged;
|
175 |
-
}
|
176 |
-
}
|
177 |
-
else if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches))
|
178 |
-
{
|
179 |
-
$isRef = $matches['ref'];
|
180 |
-
$values['value'] = $matches['value'];
|
181 |
-
}
|
182 |
-
|
183 |
-
if ($isProcessed)
|
184 |
-
{
|
185 |
-
// Merge keys
|
186 |
-
$data = $isProcessed;
|
187 |
-
}
|
188 |
-
// hash
|
189 |
-
else if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#'))
|
190 |
-
{
|
191 |
-
// if next line is less indented or equal, then it means that the current value is null
|
192 |
-
if ($this->isNextLineIndented())
|
193 |
-
{
|
194 |
-
$data[$key] = null;
|
195 |
-
}
|
196 |
-
else
|
197 |
-
{
|
198 |
-
$c = $this->getRealCurrentLineNb() + 1;
|
199 |
-
$parser = new sfYamlParser($c);
|
200 |
-
$parser->refs =& $this->refs;
|
201 |
-
$data[$key] = $parser->parse($this->getNextEmbedBlock());
|
202 |
-
}
|
203 |
-
}
|
204 |
-
else
|
205 |
-
{
|
206 |
-
if ($isInPlace)
|
207 |
-
{
|
208 |
-
$data = $this->refs[$isInPlace];
|
209 |
-
}
|
210 |
-
else
|
211 |
-
{
|
212 |
-
$data[$key] = $this->parseValue($values['value']);
|
213 |
-
}
|
214 |
-
}
|
215 |
-
}
|
216 |
-
else
|
217 |
-
{
|
218 |
-
// 1-liner followed by newline
|
219 |
-
if (2 == count($this->lines) && empty($this->lines[1]))
|
220 |
-
{
|
221 |
-
$value = sfYamlInline::load($this->lines[0]);
|
222 |
-
if (is_array($value))
|
223 |
-
{
|
224 |
-
$first = reset($value);
|
225 |
-
if ('*' === substr($first, 0, 1))
|
226 |
-
{
|
227 |
-
$data = array();
|
228 |
-
foreach ($value as $alias)
|
229 |
-
{
|
230 |
-
$data[] = $this->refs[substr($alias, 1)];
|
231 |
-
}
|
232 |
-
$value = $data;
|
233 |
-
}
|
234 |
-
}
|
235 |
-
|
236 |
-
if (isset($mbEncoding))
|
237 |
-
{
|
238 |
-
mb_internal_encoding($mbEncoding);
|
239 |
-
}
|
240 |
-
|
241 |
-
return $value;
|
242 |
-
}
|
243 |
-
|
244 |
-
switch (preg_last_error())
|
245 |
-
{
|
246 |
-
case PREG_INTERNAL_ERROR:
|
247 |
-
$error = 'Internal PCRE error on line';
|
248 |
-
break;
|
249 |
-
case PREG_BACKTRACK_LIMIT_ERROR:
|
250 |
-
$error = 'pcre.backtrack_limit reached on line';
|
251 |
-
break;
|
252 |
-
case PREG_RECURSION_LIMIT_ERROR:
|
253 |
-
$error = 'pcre.recursion_limit reached on line';
|
254 |
-
break;
|
255 |
-
case PREG_BAD_UTF8_ERROR:
|
256 |
-
$error = 'Malformed UTF-8 data on line';
|
257 |
-
break;
|
258 |
-
case PREG_BAD_UTF8_OFFSET_ERROR:
|
259 |
-
$error = 'Offset doesn\'t correspond to the begin of a valid UTF-8 code point on line';
|
260 |
-
break;
|
261 |
-
default:
|
262 |
-
$error = 'Unable to parse line';
|
263 |
-
}
|
264 |
-
|
265 |
-
throw new InvalidArgumentException(sprintf('%s %d (%s).', $error, $this->getRealCurrentLineNb() + 1, $this->currentLine));
|
266 |
-
}
|
267 |
-
|
268 |
-
if ($isRef)
|
269 |
-
{
|
270 |
-
$this->refs[$isRef] = end($data);
|
271 |
-
}
|
272 |
-
}
|
273 |
-
|
274 |
-
if (isset($mbEncoding))
|
275 |
-
{
|
276 |
-
mb_internal_encoding($mbEncoding);
|
277 |
-
}
|
278 |
-
|
279 |
-
return empty($data) ? null : $data;
|
280 |
-
}
|
281 |
-
|
282 |
-
/**
|
283 |
-
* Returns the current line number (takes the offset into account).
|
284 |
-
*
|
285 |
-
* @return integer The current line number
|
286 |
-
*/
|
287 |
-
protected function getRealCurrentLineNb()
|
288 |
-
{
|
289 |
-
return $this->currentLineNb + $this->offset;
|
290 |
-
}
|
291 |
-
|
292 |
-
/**
|
293 |
-
* Returns the current line indentation.
|
294 |
-
*
|
295 |
-
* @return integer The current line indentation
|
296 |
-
*/
|
297 |
-
protected function getCurrentLineIndentation()
|
298 |
-
{
|
299 |
-
return strlen($this->currentLine) - strlen(ltrim($this->currentLine, ' '));
|
300 |
-
}
|
301 |
-
|
302 |
-
/**
|
303 |
-
* Returns the next embed block of YAML.
|
304 |
-
*
|
305 |
-
* @param integer $indentation The indent level at which the block is to be read, or null for default
|
306 |
-
*
|
307 |
-
* @return string A YAML string
|
308 |
-
*/
|
309 |
-
protected function getNextEmbedBlock($indentation = null)
|
310 |
-
{
|
311 |
-
$this->moveToNextLine();
|
312 |
-
|
313 |
-
if (null === $indentation)
|
314 |
-
{
|
315 |
-
$newIndent = $this->getCurrentLineIndentation();
|
316 |
-
|
317 |
-
if (!$this->isCurrentLineEmpty() && 0 == $newIndent)
|
318 |
-
{
|
319 |
-
throw new InvalidArgumentException(sprintf('Indentation problem at line %d (%s)', $this->getRealCurrentLineNb() + 1, $this->currentLine));
|
320 |
-
}
|
321 |
-
}
|
322 |
-
else
|
323 |
-
{
|
324 |
-
$newIndent = $indentation;
|
325 |
-
}
|
326 |
-
|
327 |
-
$data = array(substr($this->currentLine, $newIndent));
|
328 |
-
|
329 |
-
while ($this->moveToNextLine())
|
330 |
-
{
|
331 |
-
if ($this->isCurrentLineEmpty())
|
332 |
-
{
|
333 |
-
if ($this->isCurrentLineBlank())
|
334 |
-
{
|
335 |
-
$data[] = substr($this->currentLine, $newIndent);
|
336 |
-
}
|
337 |
-
|
338 |
-
continue;
|
339 |
-
}
|
340 |
-
|
341 |
-
$indent = $this->getCurrentLineIndentation();
|
342 |
-
|
343 |
-
if (preg_match('#^(?P<text> *)$#', $this->currentLine, $match))
|
344 |
-
{
|
345 |
-
// empty line
|
346 |
-
$data[] = $match['text'];
|
347 |
-
}
|
348 |
-
else if ($indent >= $newIndent)
|
349 |
-
{
|
350 |
-
$data[] = substr($this->currentLine, $newIndent);
|
351 |
-
}
|
352 |
-
else if (0 == $indent)
|
353 |
-
{
|
354 |
-
$this->moveToPreviousLine();
|
355 |
-
|
356 |
-
break;
|
357 |
-
}
|
358 |
-
else
|
359 |
-
{
|
360 |
-
throw new InvalidArgumentException(sprintf('Indentation problem at line %d (%s)', $this->getRealCurrentLineNb() + 1, $this->currentLine));
|
361 |
-
}
|
362 |
-
}
|
363 |
-
|
364 |
-
return implode("\n", $data);
|
365 |
-
}
|
366 |
-
|
367 |
-
/**
|
368 |
-
* Moves the parser to the next line.
|
369 |
-
*/
|
370 |
-
protected function moveToNextLine()
|
371 |
-
{
|
372 |
-
if ($this->currentLineNb >= count($this->lines) - 1)
|
373 |
-
{
|
374 |
-
return false;
|
375 |
-
}
|
376 |
-
|
377 |
-
$this->currentLine = $this->lines[++$this->currentLineNb];
|
378 |
-
|
379 |
-
return true;
|
380 |
-
}
|
381 |
-
|
382 |
-
/**
|
383 |
-
* Moves the parser to the previous line.
|
384 |
-
*/
|
385 |
-
protected function moveToPreviousLine()
|
386 |
-
{
|
387 |
-
$this->currentLine = $this->lines[--$this->currentLineNb];
|
388 |
-
}
|
389 |
-
|
390 |
-
/**
|
391 |
-
* Parses a YAML value.
|
392 |
-
*
|
393 |
-
* @param string $value A YAML value
|
394 |
-
*
|
395 |
-
* @return mixed A PHP value
|
396 |
-
*/
|
397 |
-
protected function parseValue($value)
|
398 |
-
{
|
399 |
-
if ('*' === substr($value, 0, 1))
|
400 |
-
{
|
401 |
-
if (false !== $pos = strpos($value, '#'))
|
402 |
-
{
|
403 |
-
$value = substr($value, 1, $pos - 2);
|
404 |
-
}
|
405 |
-
else
|
406 |
-
{
|
407 |
-
$value = substr($value, 1);
|
408 |
-
}
|
409 |
-
|
410 |
-
if (!array_key_exists($value, $this->refs))
|
411 |
-
{
|
412 |
-
throw new InvalidArgumentException(sprintf('Reference "%s" does not exist (%s).', $value, $this->currentLine));
|
413 |
-
}
|
414 |
-
return $this->refs[$value];
|
415 |
-
}
|
416 |
-
|
417 |
-
if (preg_match('/^(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?$/', $value, $matches))
|
418 |
-
{
|
419 |
-
$modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';
|
420 |
-
|
421 |
-
return $this->parseFoldedScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), intval(abs($modifiers)));
|
422 |
-
}
|
423 |
-
else
|
424 |
-
{
|
425 |
-
return sfYamlInline::load($value);
|
426 |
-
}
|
427 |
-
}
|
428 |
-
|
429 |
-
/**
|
430 |
-
* Parses a folded scalar.
|
431 |
-
*
|
432 |
-
* @param string $separator The separator that was used to begin this folded scalar (| or >)
|
433 |
-
* @param string $indicator The indicator that was used to begin this folded scalar (+ or -)
|
434 |
-
* @param integer $indentation The indentation that was used to begin this folded scalar
|
435 |
-
*
|
436 |
-
* @return string The text value
|
437 |
-
*/
|
438 |
-
protected function parseFoldedScalar($separator, $indicator = '', $indentation = 0)
|
439 |
-
{
|
440 |
-
$separator = '|' == $separator ? "\n" : ' ';
|
441 |
-
$text = '';
|
442 |
-
|
443 |
-
$notEOF = $this->moveToNextLine();
|
444 |
-
|
445 |
-
while ($notEOF && $this->isCurrentLineBlank())
|
446 |
-
{
|
447 |
-
$text .= "\n";
|
448 |
-
|
449 |
-
$notEOF = $this->moveToNextLine();
|
450 |
-
}
|
451 |
-
|
452 |
-
if (!$notEOF)
|
453 |
-
{
|
454 |
-
return '';
|
455 |
-
}
|
456 |
-
|
457 |
-
if (!preg_match('#^(?P<indent>'.($indentation ? str_repeat(' ', $indentation) : ' +').')(?P<text>.*)$#u', $this->currentLine, $matches))
|
458 |
-
{
|
459 |
-
$this->moveToPreviousLine();
|
460 |
-
|
461 |
-
return '';
|
462 |
-
}
|
463 |
-
|
464 |
-
$textIndent = $matches['indent'];
|
465 |
-
$previousIndent = 0;
|
466 |
-
|
467 |
-
$text .= $matches['text'].$separator;
|
468 |
-
while ($this->currentLineNb + 1 < count($this->lines))
|
469 |
-
{
|
470 |
-
$this->moveToNextLine();
|
471 |
-
|
472 |
-
if (preg_match('#^(?P<indent> {'.strlen($textIndent).',})(?P<text>.+)$#u', $this->currentLine, $matches))
|
473 |
-
{
|
474 |
-
if (' ' == $separator && $previousIndent != $matches['indent'])
|
475 |
-
{
|
476 |
-
$text = substr($text, 0, -1)."\n";
|
477 |
-
}
|
478 |
-
$previousIndent = $matches['indent'];
|
479 |
-
|
480 |
-
$text .= str_repeat(' ', $diff = strlen($matches['indent']) - strlen($textIndent)).$matches['text'].($diff ? "\n" : $separator);
|
481 |
-
}
|
482 |
-
else if (preg_match('#^(?P<text> *)$#', $this->currentLine, $matches))
|
483 |
-
{
|
484 |
-
$text .= preg_replace('#^ {1,'.strlen($textIndent).'}#', '', $matches['text'])."\n";
|
485 |
-
}
|
486 |
-
else
|
487 |
-
{
|
488 |
-
$this->moveToPreviousLine();
|
489 |
-
|
490 |
-
break;
|
491 |
-
}
|
492 |
-
}
|
493 |
-
|
494 |
-
if (' ' == $separator)
|
495 |
-
{
|
496 |
-
// replace last separator by a newline
|
497 |
-
$text = preg_replace('/ (\n*)$/', "\n$1", $text);
|
498 |
-
}
|
499 |
-
|
500 |
-
switch ($indicator)
|
501 |
-
{
|
502 |
-
case '':
|
503 |
-
$text = preg_replace('#\n+$#s', "\n", $text);
|
504 |
-
break;
|
505 |
-
case '+':
|
506 |
-
break;
|
507 |
-
case '-':
|
508 |
-
$text = preg_replace('#\n+$#s', '', $text);
|
509 |
-
break;
|
510 |
-
}
|
511 |
-
|
512 |
-
return $text;
|
513 |
-
}
|
514 |
-
|
515 |
-
/**
|
516 |
-
* Returns true if the next line is indented.
|
517 |
-
*
|
518 |
-
* @return Boolean Returns true if the next line is indented, false otherwise
|
519 |
-
*/
|
520 |
-
protected function isNextLineIndented()
|
521 |
-
{
|
522 |
-
$currentIndentation = $this->getCurrentLineIndentation();
|
523 |
-
$notEOF = $this->moveToNextLine();
|
524 |
-
|
525 |
-
while ($notEOF && $this->isCurrentLineEmpty())
|
526 |
-
{
|
527 |
-
$notEOF = $this->moveToNextLine();
|
528 |
-
}
|
529 |
-
|
530 |
-
if (false === $notEOF)
|
531 |
-
{
|
532 |
-
return false;
|
533 |
-
}
|
534 |
-
|
535 |
-
$ret = false;
|
536 |
-
if ($this->getCurrentLineIndentation() <= $currentIndentation)
|
537 |
-
{
|
538 |
-
$ret = true;
|
539 |
-
}
|
540 |
-
|
541 |
-
$this->moveToPreviousLine();
|
542 |
-
|
543 |
-
return $ret;
|
544 |
-
}
|
545 |
-
|
546 |
-
/**
|
547 |
-
* Returns true if the current line is blank or if it is a comment line.
|
548 |
-
*
|
549 |
-
* @return Boolean Returns true if the current line is empty or if it is a comment line, false otherwise
|
550 |
-
*/
|
551 |
-
protected function isCurrentLineEmpty()
|
552 |
-
{
|
553 |
-
return $this->isCurrentLineBlank() || $this->isCurrentLineComment();
|
554 |
-
}
|
555 |
-
|
556 |
-
/**
|
557 |
-
* Returns true if the current line is blank.
|
558 |
-
*
|
559 |
-
* @return Boolean Returns true if the current line is blank, false otherwise
|
560 |
-
*/
|
561 |
-
protected function isCurrentLineBlank()
|
562 |
-
{
|
563 |
-
return '' == trim($this->currentLine, ' ');
|
564 |
-
}
|
565 |
-
|
566 |
-
/**
|
567 |
-
* Returns true if the current line is a comment line.
|
568 |
-
*
|
569 |
-
* @return Boolean Returns true if the current line is a comment line, false otherwise
|
570 |
-
*/
|
571 |
-
protected function isCurrentLineComment()
|
572 |
-
{
|
573 |
-
//checking explicitly the first char of the trim is faster than loops or strpos
|
574 |
-
$ltrimmedLine = ltrim($this->currentLine, ' ');
|
575 |
-
return $ltrimmedLine[0] === '#';
|
576 |
-
}
|
577 |
-
|
578 |
-
/**
|
579 |
-
* Cleanups a YAML string to be parsed.
|
580 |
-
*
|
581 |
-
* @param string $value The input YAML string
|
582 |
-
*
|
583 |
-
* @return string A cleaned up YAML string
|
584 |
-
*/
|
585 |
-
protected function cleanup($value)
|
586 |
-
{
|
587 |
-
$value = str_replace(array("\r\n", "\r"), "\n", $value);
|
588 |
-
|
589 |
-
if (!preg_match("#\n$#", $value))
|
590 |
-
{
|
591 |
-
$value .= "\n";
|
592 |
-
}
|
593 |
-
|
594 |
-
// strip YAML header
|
595 |
-
$count = 0;
|
596 |
-
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#su', '', $value, -1, $count);
|
597 |
-
$this->offset += $count;
|
598 |
-
|
599 |
-
// remove leading comments
|
600 |
-
$trimmedValue = preg_replace('#^(\#.*?\n)+#s', '', $value, -1, $count);
|
601 |
-
if ($count == 1)
|
602 |
-
{
|
603 |
-
// items have been removed, update the offset
|
604 |
-
$this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
|
605 |
-
$value = $trimmedValue;
|
606 |
-
}
|
607 |
-
|
608 |
-
// remove start of the document marker (---)
|
609 |
-
$trimmedValue = preg_replace('#^\-\-\-.*?\n#s', '', $value, -1, $count);
|
610 |
-
if ($count == 1)
|
611 |
-
{
|
612 |
-
// items have been removed, update the offset
|
613 |
-
$this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
|
614 |
-
$value = $trimmedValue;
|
615 |
-
|
616 |
-
// remove end of the document marker (...)
|
617 |
-
$value = preg_replace('#\.\.\.\s*$#s', '', $value);
|
618 |
-
}
|
619 |
-
|
620 |
-
return $value;
|
621 |
-
}
|
622 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/lib/yaml/package.xml
DELETED
@@ -1,102 +0,0 @@
|
|
1 |
-
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
-
<package packagerversion="1.4.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
|
3 |
-
<name>YAML</name>
|
4 |
-
<channel>pear.symfony-project.com</channel>
|
5 |
-
<summary>The Symfony YAML Component.</summary>
|
6 |
-
<description>The Symfony YAML Component.</description>
|
7 |
-
<lead>
|
8 |
-
<name>Fabien Potencier</name>
|
9 |
-
<user>fabpot</user>
|
10 |
-
<email>fabien.potencier@symfony-project.org</email>
|
11 |
-
<active>yes</active>
|
12 |
-
</lead>
|
13 |
-
<date>2009-12-01</date>
|
14 |
-
<version>
|
15 |
-
<release>1.0.2</release>
|
16 |
-
<api>1.0.0</api>
|
17 |
-
</version>
|
18 |
-
<stability>
|
19 |
-
<release>stable</release>
|
20 |
-
<api>stable</api>
|
21 |
-
</stability>
|
22 |
-
<license uri="http://www.symfony-project.com/license">MIT license</license>
|
23 |
-
<notes>-</notes>
|
24 |
-
<contents>
|
25 |
-
<dir name="/">
|
26 |
-
<file name="README.markdown" role="doc" />
|
27 |
-
<file name="LICENSE" role="doc" />
|
28 |
-
|
29 |
-
<dir name="lib">
|
30 |
-
<file install-as="SymfonyComponents/YAML/sfYaml.php" name="sfYaml.php" role="php" />
|
31 |
-
<file install-as="SymfonyComponents/YAML/sfYamlDumper.php" name="sfYamlDumper.php" role="php" />
|
32 |
-
<file install-as="SymfonyComponents/YAML/sfYamlInline.php" name="sfYamlInline.php" role="php" />
|
33 |
-
<file install-as="SymfonyComponents/YAML/sfYamlParser.php" name="sfYamlParser.php" role="php" />
|
34 |
-
</dir>
|
35 |
-
</dir>
|
36 |
-
</contents>
|
37 |
-
|
38 |
-
<dependencies>
|
39 |
-
<required>
|
40 |
-
<php>
|
41 |
-
<min>5.2.4</min>
|
42 |
-
</php>
|
43 |
-
<pearinstaller>
|
44 |
-
<min>1.4.1</min>
|
45 |
-
</pearinstaller>
|
46 |
-
</required>
|
47 |
-
</dependencies>
|
48 |
-
|
49 |
-
<phprelease>
|
50 |
-
</phprelease>
|
51 |
-
|
52 |
-
<changelog>
|
53 |
-
<release>
|
54 |
-
<version>
|
55 |
-
<release>1.0.2</release>
|
56 |
-
<api>1.0.0</api>
|
57 |
-
</version>
|
58 |
-
<stability>
|
59 |
-
<release>stable</release>
|
60 |
-
<api>stable</api>
|
61 |
-
</stability>
|
62 |
-
<license uri="http://www.symfony-project.com/license">MIT license</license>
|
63 |
-
<date>2009-12-01</date>
|
64 |
-
<license>MIT</license>
|
65 |
-
<notes>
|
66 |
-
* fabien: fixed \ usage in quoted string
|
67 |
-
</notes>
|
68 |
-
</release>
|
69 |
-
<release>
|
70 |
-
<version>
|
71 |
-
<release>1.0.1</release>
|
72 |
-
<api>1.0.0</api>
|
73 |
-
</version>
|
74 |
-
<stability>
|
75 |
-
<release>stable</release>
|
76 |
-
<api>stable</api>
|
77 |
-
</stability>
|
78 |
-
<license uri="http://www.symfony-project.com/license">MIT license</license>
|
79 |
-
<date>2009-12-01</date>
|
80 |
-
<license>MIT</license>
|
81 |
-
<notes>
|
82 |
-
* fabien: fixed a possible loop in parsing a non-valid quoted string
|
83 |
-
</notes>
|
84 |
-
</release>
|
85 |
-
<release>
|
86 |
-
<version>
|
87 |
-
<release>1.0.0</release>
|
88 |
-
<api>1.0.0</api>
|
89 |
-
</version>
|
90 |
-
<stability>
|
91 |
-
<release>stable</release>
|
92 |
-
<api>stable</api>
|
93 |
-
</stability>
|
94 |
-
<license uri="http://www.symfony-project.com/license">MIT license</license>
|
95 |
-
<date>2009-11-30</date>
|
96 |
-
<license>MIT</license>
|
97 |
-
<notes>
|
98 |
-
* fabien: first stable release as a Symfony Component
|
99 |
-
</notes>
|
100 |
-
</release>
|
101 |
-
</changelog>
|
102 |
-
</package>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mustache/test/phpunit.xml
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
-
<phpunit colors="true">
|
3 |
-
<testsuite name="Mustache">
|
4 |
-
<directory>./</directory>
|
5 |
-
</testsuite>
|
6 |
-
<blacklist>
|
7 |
-
<directory suffix=".php">../examples</directory>
|
8 |
-
<directory suffix=".php">./</directory>
|
9 |
-
</blacklist>
|
10 |
-
</phpunit>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
posts-to-posts.php
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Posts 2 Posts
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
Author URI: http://scribu.net/
|
8 |
Plugin URI: http://scribu.net/wordpress/posts-to-posts
|
9 |
Text Domain: posts-to-posts
|
@@ -26,53 +26,30 @@ You should have received a copy of the GNU General Public License
|
|
26 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
27 |
*/
|
28 |
|
29 |
-
define( 'P2P_PLUGIN_VERSION', '0.
|
|
|
|
|
30 |
|
31 |
require dirname( __FILE__ ) . '/scb/load.php';
|
32 |
|
33 |
function _p2p_init() {
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
require_once dirname( __FILE__ ) . '/api.php';
|
38 |
|
39 |
-
|
40 |
-
|
41 |
|
42 |
-
|
43 |
|
44 |
-
|
|
|
|
|
|
|
45 |
}
|
46 |
scb_init( '_p2p_init' );
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
function init() {
|
52 |
-
add_action( 'admin_notices', array( __CLASS__, 'migrate' ) );
|
53 |
-
}
|
54 |
-
|
55 |
-
function migrate() {
|
56 |
-
if ( !isset( $_GET['migrate_p2p'] ) || !current_user_can( 'administrator' ) )
|
57 |
-
return;
|
58 |
-
|
59 |
-
$tax = 'p2p';
|
60 |
-
|
61 |
-
register_taxonomy( $tax, 'post', array( 'public' => false ) );
|
62 |
-
|
63 |
-
$count = 0;
|
64 |
-
foreach ( get_terms( $tax ) as $term ) {
|
65 |
-
$post_b = (int) substr( $term->slug, 1 );
|
66 |
-
$post_a = get_objects_in_term( $term->term_id, $tax );
|
67 |
-
|
68 |
-
p2p_connect( $post_a, $post_b );
|
69 |
-
|
70 |
-
wp_delete_term( $term->term_id, $tax );
|
71 |
-
|
72 |
-
$count += count( $post_a );
|
73 |
-
}
|
74 |
-
|
75 |
-
printf( "<div class='updated'><p>Migrated %d connections.</p></div>", $count );
|
76 |
-
}
|
77 |
}
|
78 |
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Posts 2 Posts
|
4 |
+
Description: Create many-to-many relationships between all types of posts.
|
5 |
+
Version: 0.9.2
|
6 |
+
Author: scribu
|
7 |
Author URI: http://scribu.net/
|
8 |
Plugin URI: http://scribu.net/wordpress/posts-to-posts
|
9 |
Text Domain: posts-to-posts
|
26 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
27 |
*/
|
28 |
|
29 |
+
define( 'P2P_PLUGIN_VERSION', '0.9.2' );
|
30 |
+
|
31 |
+
define( 'P2P_TEXTDOMAIN', 'posts-to-posts' );
|
32 |
|
33 |
require dirname( __FILE__ ) . '/scb/load.php';
|
34 |
|
35 |
function _p2p_init() {
|
36 |
+
$base = dirname( __FILE__ );
|
37 |
|
38 |
+
load_plugin_textdomain( P2P_TEXTDOMAIN, '', basename( $base ) . '/lang' );
|
|
|
39 |
|
40 |
+
foreach ( array( 'storage', 'query', 'type', 'api', 'widget' ) as $file )
|
41 |
+
require_once "$base/core/$file.php";
|
42 |
|
43 |
+
P2P_Widget::init( __FILE__ );
|
44 |
|
45 |
+
if ( is_admin() ) {
|
46 |
+
foreach ( array( 'base', 'box', 'fields' ) as $file )
|
47 |
+
require_once "$base/admin/$file.php";
|
48 |
+
}
|
49 |
}
|
50 |
scb_init( '_p2p_init' );
|
51 |
|
52 |
+
function _p2p_append( &$arr, $values ) {
|
53 |
+
$arr = array_merge( $arr, $values );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
}
|
55 |
|
readme.txt
CHANGED
@@ -2,19 +2,20 @@
|
|
2 |
Contributors: scribu, ciobi
|
3 |
Tags: cms, custom post types, relationships, many-to-many
|
4 |
Requires at least: 3.2
|
5 |
-
Tested up to: 3.
|
6 |
-
Stable tag: 0.
|
7 |
|
8 |
Create connections between posts
|
9 |
|
10 |
== Description ==
|
11 |
|
12 |
-
This plugin allows you to create many-to-many relationships between posts of
|
13 |
|
14 |
A few example use cases:
|
15 |
|
16 |
-
* 'review'
|
17 |
* manually curated lists of related posts
|
|
|
18 |
etc.
|
19 |
|
20 |
Links: [**Documentation**](http://github.com/scribu/wp-posts-to-posts/wiki) | [Plugin News](http://scribu.net/wordpress/posts-to-posts) | [Author's Site](http://scribu.net)
|
@@ -38,11 +39,32 @@ Make sure your host is running PHP 5. The only foolproof way to do this is to ad
|
|
38 |
|
39 |
== Screenshots ==
|
40 |
|
41 |
-
1.
|
42 |
2. Advanced connection metabox
|
43 |
|
44 |
== Changelog ==
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
= 0.8 =
|
47 |
* added ability to create draft posts from the connection box. props Oren Kolker
|
48 |
* show post status in the connection box. props [Michael Fields](http://wordpress.mfields.org/)
|
2 |
Contributors: scribu, ciobi
|
3 |
Tags: cms, custom post types, relationships, many-to-many
|
4 |
Requires at least: 3.2
|
5 |
+
Tested up to: 3.3
|
6 |
+
Stable tag: 0.9.2
|
7 |
|
8 |
Create connections between posts
|
9 |
|
10 |
== Description ==
|
11 |
|
12 |
+
This plugin allows you to create many-to-many relationships between posts of any type: post, page, custom etc.
|
13 |
|
14 |
A few example use cases:
|
15 |
|
16 |
+
* 'review' posts connected to 'product' posts
|
17 |
* manually curated lists of related posts
|
18 |
+
|
19 |
etc.
|
20 |
|
21 |
Links: [**Documentation**](http://github.com/scribu/wp-posts-to-posts/wiki) | [Plugin News](http://scribu.net/wordpress/posts-to-posts) | [Author's Site](http://scribu.net)
|
39 |
|
40 |
== Screenshots ==
|
41 |
|
42 |
+
1. Basic connection metabox
|
43 |
2. Advanced connection metabox
|
44 |
|
45 |
== Changelog ==
|
46 |
|
47 |
+
= 0.9.2 =
|
48 |
+
* fix incorrect storage when creating a connection from the other end
|
49 |
+
* respect 'reciprocal' => false when 'from' == 'to'
|
50 |
+
* pass pagination numbers through number_format_i18n()
|
51 |
+
|
52 |
+
= 0.9.1 =
|
53 |
+
* fix bug with each_connected()
|
54 |
+
* add widget
|
55 |
+
* allow 'from' and 'to' to be arrays again
|
56 |
+
* improve RTL support
|
57 |
+
|
58 |
+
= 0.9 =
|
59 |
+
* introduce dropdown connection fields
|
60 |
+
* introduce 'sortable' arg to p2p_register_connection_type()
|
61 |
+
* introduce 'data' arg to p2p_register_connection_type()
|
62 |
+
* replace 'box' arg with hooks
|
63 |
+
* replace p2p_each_connected() with P2P_Post_Type->each_connected()
|
64 |
+
* allow using 'connected_meta' and 'connected_orderby' together
|
65 |
+
* fix some translations
|
66 |
+
* [more info](http://scribu.net/wordpress/posts-to-posts/p2p-0-9.html)
|
67 |
+
|
68 |
= 0.8 =
|
69 |
* added ability to create draft posts from the connection box. props Oren Kolker
|
70 |
* show post status in the connection box. props [Michael Fields](http://wordpress.mfields.org/)
|
scb/AdminPage.php
CHANGED
@@ -4,16 +4,18 @@
|
|
4 |
|
5 |
abstract class scbAdminPage {
|
6 |
/** Page args
|
7 |
-
* $
|
8 |
-
* $
|
9 |
-
* $
|
10 |
-
* $
|
11 |
-
* $
|
12 |
-
* $
|
13 |
-
* $
|
14 |
-
* $
|
15 |
-
* $
|
16 |
-
* $
|
|
|
|
|
17 |
*/
|
18 |
protected $args;
|
19 |
|
@@ -115,7 +117,7 @@ abstract class scbAdminPage {
|
|
115 |
// A generic page header
|
116 |
function page_header() {
|
117 |
echo "<div class='wrap'>\n";
|
118 |
-
screen_icon();
|
119 |
echo "<h2>" . $this->args['page_title'] . "</h2>\n";
|
120 |
}
|
121 |
|
@@ -227,13 +229,8 @@ abstract class scbAdminPage {
|
|
227 |
return scbForms::form_wrap( $content, $this->nonce );
|
228 |
}
|
229 |
|
230 |
-
// See scbForms::form()
|
231 |
-
function form( $rows, $formdata = array() ) {
|
232 |
-
return scbForms::form( $rows, $formdata, $this->nonce );
|
233 |
-
}
|
234 |
-
|
235 |
// Generates a table wrapped in a form
|
236 |
-
function form_table( $rows, $formdata =
|
237 |
$output = '';
|
238 |
foreach ( $rows as $row )
|
239 |
$output .= $this->table_row( $row, $formdata );
|
@@ -252,7 +249,7 @@ abstract class scbAdminPage {
|
|
252 |
}
|
253 |
|
254 |
// Generates a form table
|
255 |
-
function table( $rows, $formdata =
|
256 |
$output = '';
|
257 |
foreach ( $rows as $row )
|
258 |
$output .= $this->table_row( $row, $formdata );
|
@@ -263,7 +260,7 @@ abstract class scbAdminPage {
|
|
263 |
}
|
264 |
|
265 |
// Generates a table row
|
266 |
-
function table_row( $args, $formdata =
|
267 |
return $this->row_wrap( $args['title'], $this->input( $args, $formdata ) );
|
268 |
}
|
269 |
|
@@ -281,34 +278,16 @@ abstract class scbAdminPage {
|
|
281 |
.html( 'td', $content ) );
|
282 |
}
|
283 |
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
$tree = ( array ) $args['name_tree'];
|
290 |
-
unset( $args['name_tree'] );
|
291 |
-
|
292 |
-
$value = $formdata;
|
293 |
-
$name = $this->option_name;
|
294 |
-
foreach ( $tree as $key ) {
|
295 |
-
$value = $value[$key];
|
296 |
-
$name .= '[' . $key . ']';
|
297 |
-
}
|
298 |
-
|
299 |
-
$args['name'] = $name;
|
300 |
-
unset( $args['names'] );
|
301 |
-
|
302 |
-
unset( $args['values'] );
|
303 |
|
304 |
-
|
|
|
305 |
}
|
306 |
|
307 |
-
return scbForms::input( $args, $formdata );
|
308 |
-
}
|
309 |
-
|
310 |
-
// Mimic scbForms inheritance
|
311 |
-
function __call( $method, $args ) {
|
312 |
return call_user_func_array( array( 'scbForms', $method ), $args );
|
313 |
}
|
314 |
|
@@ -334,7 +313,7 @@ abstract class scbAdminPage {
|
|
334 |
$this->pagehook = add_submenu_page( $parent, $page_title, $menu_title, $capability, $page_slug, array( $this, '_page_content_hook' ) );
|
335 |
} else {
|
336 |
$func = 'add_' . $toplevel . '_page';
|
337 |
-
$this->pagehook = $func( $page_title, $menu_title, $capability, $page_slug, array( $this, '_page_content_hook' ), $icon_url );
|
338 |
}
|
339 |
|
340 |
if ( ! $this->pagehook )
|
@@ -358,7 +337,9 @@ abstract class scbAdminPage {
|
|
358 |
|
359 |
$this->args = wp_parse_args( $this->args, array(
|
360 |
'toplevel' => '',
|
361 |
-
'
|
|
|
|
|
362 |
'parent' => 'options-general.php',
|
363 |
'capability' => 'manage_options',
|
364 |
'menu_title' => $this->args['page_title'],
|
4 |
|
5 |
abstract class scbAdminPage {
|
6 |
/** Page args
|
7 |
+
* $page_title string (mandatory)
|
8 |
+
* $parent (string) (default: options-general.php)
|
9 |
+
* $capability (string) (default: 'manage_options')
|
10 |
+
* $menu_title (string) (default: $page_title)
|
11 |
+
* $page_slug (string) (default: sanitized $page_title)
|
12 |
+
* $toplevel (string) If not empty, will create a new top level menu (for expected values see http://codex.wordpress.org/Administration_Menus#Using_add_submenu_page)
|
13 |
+
* - $icon_url (string) URL to an icon for the top level menu
|
14 |
+
* - $position (int) Position of the toplevel menu (caution!)
|
15 |
+
* $screen_icon (string) The icon type to use in the screen header
|
16 |
+
* $nonce string (default: $page_slug)
|
17 |
+
* $action_link (string|bool) Text of the action link on the Plugins page (default: 'Settings')
|
18 |
+
* $admin_action_priority int The priority that the admin_menu action should be executed at (default: 10)
|
19 |
*/
|
20 |
protected $args;
|
21 |
|
117 |
// A generic page header
|
118 |
function page_header() {
|
119 |
echo "<div class='wrap'>\n";
|
120 |
+
screen_icon( $this->args['screen_icon'] );
|
121 |
echo "<h2>" . $this->args['page_title'] . "</h2>\n";
|
122 |
}
|
123 |
|
229 |
return scbForms::form_wrap( $content, $this->nonce );
|
230 |
}
|
231 |
|
|
|
|
|
|
|
|
|
|
|
232 |
// Generates a table wrapped in a form
|
233 |
+
function form_table( $rows, $formdata = false ) {
|
234 |
$output = '';
|
235 |
foreach ( $rows as $row )
|
236 |
$output .= $this->table_row( $row, $formdata );
|
249 |
}
|
250 |
|
251 |
// Generates a form table
|
252 |
+
function table( $rows, $formdata = false ) {
|
253 |
$output = '';
|
254 |
foreach ( $rows as $row )
|
255 |
$output .= $this->table_row( $row, $formdata );
|
260 |
}
|
261 |
|
262 |
// Generates a table row
|
263 |
+
function table_row( $args, $formdata = false ) {
|
264 |
return $this->row_wrap( $args['title'], $this->input( $args, $formdata ) );
|
265 |
}
|
266 |
|
278 |
.html( 'td', $content ) );
|
279 |
}
|
280 |
|
281 |
+
// Mimic scbForms inheritance
|
282 |
+
function __call( $method, $args ) {
|
283 |
+
if ( in_array( $method, array( 'input', 'form' ) ) ) {
|
284 |
+
if ( empty( $args[1] ) && isset( $this->options ) )
|
285 |
+
$args[1] = $this->options->get();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
|
287 |
+
if ( 'form' == $method )
|
288 |
+
$args[2] = $this->nonce;
|
289 |
}
|
290 |
|
|
|
|
|
|
|
|
|
|
|
291 |
return call_user_func_array( array( 'scbForms', $method ), $args );
|
292 |
}
|
293 |
|
313 |
$this->pagehook = add_submenu_page( $parent, $page_title, $menu_title, $capability, $page_slug, array( $this, '_page_content_hook' ) );
|
314 |
} else {
|
315 |
$func = 'add_' . $toplevel . '_page';
|
316 |
+
$this->pagehook = $func( $page_title, $menu_title, $capability, $page_slug, array( $this, '_page_content_hook' ), $icon_url, $position );
|
317 |
}
|
318 |
|
319 |
if ( ! $this->pagehook )
|
337 |
|
338 |
$this->args = wp_parse_args( $this->args, array(
|
339 |
'toplevel' => '',
|
340 |
+
'position' => null,
|
341 |
+
'icon_url' => '',
|
342 |
+
'screen_icon' => '',
|
343 |
'parent' => 'options-general.php',
|
344 |
'capability' => 'manage_options',
|
345 |
'menu_title' => $this->args['page_title'],
|
scb/BoxesPage.php
CHANGED
@@ -41,7 +41,6 @@ abstract class scbBoxesPage extends scbAdminPage {
|
|
41 |
.inside {
|
42 |
clear: both;
|
43 |
overflow: hidden;
|
44 |
-
padding: 10px 10px 0 !important;
|
45 |
}
|
46 |
.inside table {
|
47 |
margin: 0 !important;
|
@@ -68,6 +67,7 @@ abstract class scbBoxesPage extends scbAdminPage {
|
|
68 |
.inside p.submit {
|
69 |
float: left !important;
|
70 |
padding: 0 !important;
|
|
|
71 |
}
|
72 |
</style>
|
73 |
<?php
|
41 |
.inside {
|
42 |
clear: both;
|
43 |
overflow: hidden;
|
|
|
44 |
}
|
45 |
.inside table {
|
46 |
margin: 0 !important;
|
67 |
.inside p.submit {
|
68 |
float: left !important;
|
69 |
padding: 0 !important;
|
70 |
+
margin-bottom: 0 !important;
|
71 |
}
|
72 |
</style>
|
73 |
<?php
|
scb/Forms.php
CHANGED
@@ -7,9 +7,9 @@ class scbForms {
|
|
7 |
const token = '%input%';
|
8 |
|
9 |
protected static $cur_name;
|
10 |
-
protected static $cur_val;
|
11 |
|
12 |
-
static function input( $args, $formdata =
|
|
|
13 |
foreach ( array( 'name', 'value' ) as $key ) {
|
14 |
$old = $key . 's';
|
15 |
|
@@ -19,31 +19,36 @@ class scbForms {
|
|
19 |
}
|
20 |
}
|
21 |
|
|
|
|
|
|
|
|
|
|
|
22 |
if ( empty( $args['name'] ) )
|
23 |
return trigger_error( 'Empty name', E_USER_WARNING );
|
24 |
|
25 |
$args = wp_parse_args( $args, array(
|
26 |
-
'value' => NULL,
|
27 |
'desc' => '',
|
28 |
'desc_pos' => '',
|
29 |
) );
|
30 |
|
|
|
|
|
31 |
if ( isset( $args['extra'] ) && !is_array( $args['extra'] ) )
|
32 |
$args['extra'] = shortcode_parse_atts( $args['extra'] );
|
33 |
|
34 |
self::$cur_name = self::get_name( $args['name'] );
|
35 |
-
self::$cur_val = self::get_value( $args['name'], $formdata );
|
36 |
|
37 |
switch ( $args['type'] ) {
|
38 |
case 'select':
|
39 |
case 'radio':
|
40 |
-
if ( !
|
41 |
return trigger_error( "'value' argument is expected to be an array", E_USER_WARNING );
|
42 |
|
43 |
return self::_single_choice( $args );
|
44 |
break;
|
45 |
case 'checkbox':
|
46 |
-
if (
|
47 |
return self::_multiple_choice( $args );
|
48 |
else
|
49 |
return self::_checkbox( $args );
|
@@ -160,7 +165,7 @@ class scbForms {
|
|
160 |
extract( $args );
|
161 |
|
162 |
if ( !is_array( $checked ) )
|
163 |
-
$checked =
|
164 |
|
165 |
$opts = '';
|
166 |
foreach ( $value as $value => $title ) {
|
@@ -198,8 +203,6 @@ class scbForms {
|
|
198 |
$selected = key( $value ); // radio buttons should always have one option selected
|
199 |
}
|
200 |
|
201 |
-
$cur_val = self::get_cur_val( $selected );
|
202 |
-
|
203 |
$opts = '';
|
204 |
foreach ( $value as $value => $title ) {
|
205 |
if ( empty( $value ) || empty( $title ) )
|
@@ -208,7 +211,7 @@ class scbForms {
|
|
208 |
$opts .= self::_checkbox( array(
|
209 |
'type' => 'radio',
|
210 |
'value' => $value,
|
211 |
-
'checked' => ( (string) $value == (string) $
|
212 |
'desc' => $title,
|
213 |
'desc_pos' => $desc_pos
|
214 |
) );
|
@@ -223,14 +226,12 @@ class scbForms {
|
|
223 |
'extra' => array()
|
224 |
) ) );
|
225 |
|
226 |
-
$cur_val = self::get_cur_val( $selected );
|
227 |
-
|
228 |
$options = array();
|
229 |
|
230 |
if ( false !== $text ) {
|
231 |
$options[] = array(
|
232 |
'value' => '',
|
233 |
-
'selected' => ( $
|
234 |
'title' => $text
|
235 |
);
|
236 |
}
|
@@ -241,7 +242,7 @@ class scbForms {
|
|
241 |
|
242 |
$options[] = array(
|
243 |
'value' => $value,
|
244 |
-
'selected' => ( (string) $value == (string) $
|
245 |
'title' => $title
|
246 |
);
|
247 |
}
|
@@ -273,7 +274,7 @@ class scbForms {
|
|
273 |
$$key = &$val;
|
274 |
unset( $val );
|
275 |
|
276 |
-
$extra['checked'] =
|
277 |
|
278 |
if ( is_null( $desc ) && !is_bool( $value ) )
|
279 |
$desc = str_replace( '[]', '', $value );
|
@@ -284,7 +285,7 @@ class scbForms {
|
|
284 |
// Handle args for text inputs
|
285 |
private static function _input( $args ) {
|
286 |
$args = wp_parse_args( $args, array(
|
287 |
-
'value' =>
|
288 |
'desc_pos' => 'after',
|
289 |
'extra' => array( 'class' => 'regular-text' ),
|
290 |
) );
|
@@ -293,9 +294,6 @@ class scbForms {
|
|
293 |
$$key = &$val;
|
294 |
unset( $val );
|
295 |
|
296 |
-
if ( is_null( $value ) )
|
297 |
-
$value = self::get_cur_val( '' );
|
298 |
-
|
299 |
if ( !isset( $extra['id'] ) && !is_array( $name ) && false === strpos( $name, '[' ) )
|
300 |
$extra['id'] = $name;
|
301 |
|
@@ -358,7 +356,7 @@ class scbForms {
|
|
358 |
*
|
359 |
* @return string
|
360 |
*/
|
361 |
-
|
362 |
$name = (array) $name;
|
363 |
|
364 |
$name_str = array_shift( $name );
|
@@ -378,7 +376,7 @@ class scbForms {
|
|
378 |
*
|
379 |
* @return mixed
|
380 |
*/
|
381 |
-
|
382 |
foreach ( (array) $name as $key ) {
|
383 |
if ( !isset( $value[ $key ] ) )
|
384 |
return null;
|
@@ -389,13 +387,60 @@ class scbForms {
|
|
389 |
return $value;
|
390 |
}
|
391 |
|
392 |
-
private static function get_cur_val( $default = null ) {
|
393 |
-
return is_null( self::$cur_val ) ? $default : self::$cur_val;
|
394 |
-
}
|
395 |
-
|
396 |
private static function is_associative( $array ) {
|
397 |
$keys = array_keys( $array );
|
398 |
return array_keys( $keys ) !== $keys;
|
399 |
}
|
400 |
}
|
401 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
const token = '%input%';
|
8 |
|
9 |
protected static $cur_name;
|
|
|
10 |
|
11 |
+
static function input( $args, $formdata = false ) {
|
12 |
+
// setle on singular keys
|
13 |
foreach ( array( 'name', 'value' ) as $key ) {
|
14 |
$old = $key . 's';
|
15 |
|
19 |
}
|
20 |
}
|
21 |
|
22 |
+
if ( !empty( $formdata ) ) {
|
23 |
+
$form = new scbForm( $formdata );
|
24 |
+
return $form->input( $args );
|
25 |
+
}
|
26 |
+
|
27 |
if ( empty( $args['name'] ) )
|
28 |
return trigger_error( 'Empty name', E_USER_WARNING );
|
29 |
|
30 |
$args = wp_parse_args( $args, array(
|
|
|
31 |
'desc' => '',
|
32 |
'desc_pos' => '',
|
33 |
) );
|
34 |
|
35 |
+
$val_is_array = isset( $args['value'] ) && is_array( $args['value'] );
|
36 |
+
|
37 |
if ( isset( $args['extra'] ) && !is_array( $args['extra'] ) )
|
38 |
$args['extra'] = shortcode_parse_atts( $args['extra'] );
|
39 |
|
40 |
self::$cur_name = self::get_name( $args['name'] );
|
|
|
41 |
|
42 |
switch ( $args['type'] ) {
|
43 |
case 'select':
|
44 |
case 'radio':
|
45 |
+
if ( ! $val_is_array )
|
46 |
return trigger_error( "'value' argument is expected to be an array", E_USER_WARNING );
|
47 |
|
48 |
return self::_single_choice( $args );
|
49 |
break;
|
50 |
case 'checkbox':
|
51 |
+
if ( $val_is_array )
|
52 |
return self::_multiple_choice( $args );
|
53 |
else
|
54 |
return self::_checkbox( $args );
|
165 |
extract( $args );
|
166 |
|
167 |
if ( !is_array( $checked ) )
|
168 |
+
$checked = array();
|
169 |
|
170 |
$opts = '';
|
171 |
foreach ( $value as $value => $title ) {
|
203 |
$selected = key( $value ); // radio buttons should always have one option selected
|
204 |
}
|
205 |
|
|
|
|
|
206 |
$opts = '';
|
207 |
foreach ( $value as $value => $title ) {
|
208 |
if ( empty( $value ) || empty( $title ) )
|
211 |
$opts .= self::_checkbox( array(
|
212 |
'type' => 'radio',
|
213 |
'value' => $value,
|
214 |
+
'checked' => ( (string) $value == (string) $selected ),
|
215 |
'desc' => $title,
|
216 |
'desc_pos' => $desc_pos
|
217 |
) );
|
226 |
'extra' => array()
|
227 |
) ) );
|
228 |
|
|
|
|
|
229 |
$options = array();
|
230 |
|
231 |
if ( false !== $text ) {
|
232 |
$options[] = array(
|
233 |
'value' => '',
|
234 |
+
'selected' => ( $selected == array( 'foo' ) ),
|
235 |
'title' => $text
|
236 |
);
|
237 |
}
|
242 |
|
243 |
$options[] = array(
|
244 |
'value' => $value,
|
245 |
+
'selected' => ( (string) $value == (string) $selected ),
|
246 |
'title' => $title
|
247 |
);
|
248 |
}
|
274 |
$$key = &$val;
|
275 |
unset( $val );
|
276 |
|
277 |
+
$extra['checked'] = $checked;
|
278 |
|
279 |
if ( is_null( $desc ) && !is_bool( $value ) )
|
280 |
$desc = str_replace( '[]', '', $value );
|
285 |
// Handle args for text inputs
|
286 |
private static function _input( $args ) {
|
287 |
$args = wp_parse_args( $args, array(
|
288 |
+
'value' => '',
|
289 |
'desc_pos' => 'after',
|
290 |
'extra' => array( 'class' => 'regular-text' ),
|
291 |
) );
|
294 |
$$key = &$val;
|
295 |
unset( $val );
|
296 |
|
|
|
|
|
|
|
297 |
if ( !isset( $extra['id'] ) && !is_array( $name ) && false === strpos( $name, '[' ) )
|
298 |
$extra['id'] = $name;
|
299 |
|
356 |
*
|
357 |
* @return string
|
358 |
*/
|
359 |
+
static function get_name( $name ) {
|
360 |
$name = (array) $name;
|
361 |
|
362 |
$name_str = array_shift( $name );
|
376 |
*
|
377 |
* @return mixed
|
378 |
*/
|
379 |
+
static function get_value( $name, $value ) {
|
380 |
foreach ( (array) $name as $key ) {
|
381 |
if ( !isset( $value[ $key ] ) )
|
382 |
return null;
|
387 |
return $value;
|
388 |
}
|
389 |
|
|
|
|
|
|
|
|
|
390 |
private static function is_associative( $array ) {
|
391 |
$keys = array_keys( $array );
|
392 |
return array_keys( $keys ) !== $keys;
|
393 |
}
|
394 |
}
|
395 |
|
396 |
+
/**
|
397 |
+
* A wrapper for scbForms, containing the formdata
|
398 |
+
*/
|
399 |
+
class scbForm {
|
400 |
+
protected $data = array();
|
401 |
+
protected $prefix = array();
|
402 |
+
|
403 |
+
function __construct( $data, $prefix = false ) {
|
404 |
+
if ( is_array( $data ) )
|
405 |
+
$this->data = $data;
|
406 |
+
|
407 |
+
if ( $prefix )
|
408 |
+
$this->prefix = (array) $prefix;
|
409 |
+
}
|
410 |
+
|
411 |
+
function traverse_to( $path ) {
|
412 |
+
$data = scbForms::get_value( $path, $this->data );
|
413 |
+
|
414 |
+
$prefix = array_merge( $this->prefix, (array) $path );
|
415 |
+
|
416 |
+
return new scbForm( $data, $prefix );
|
417 |
+
}
|
418 |
+
|
419 |
+
function input( $args ) {
|
420 |
+
$value = scbForms::get_value( $args['name'], $this->data );
|
421 |
+
|
422 |
+
if ( !is_null( $value ) ) {
|
423 |
+
switch ( $args['type'] ) {
|
424 |
+
case 'select':
|
425 |
+
case 'radio':
|
426 |
+
$args['selected'] = $value;
|
427 |
+
break;
|
428 |
+
case 'checkbox':
|
429 |
+
if ( is_array( $value ) )
|
430 |
+
$args['checked'] = $value;
|
431 |
+
else
|
432 |
+
$args['checked'] = ( $value || ( isset( $args['value'] ) && $value == $args['value'] ) );
|
433 |
+
break;
|
434 |
+
default:
|
435 |
+
$args['value'] = $value;
|
436 |
+
}
|
437 |
+
}
|
438 |
+
|
439 |
+
if ( !empty( $this->prefix ) ) {
|
440 |
+
$args['name'] = array_merge( $this->prefix, (array) $args['name'] );
|
441 |
+
}
|
442 |
+
|
443 |
+
return scbForms::input( $args );
|
444 |
+
}
|
445 |
+
}
|
446 |
+
|
scb/Hooks.php
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
<?php
|
2 |
|
3 |
class scbHooks {
|
|
|
4 |
|
5 |
public static function add( $class ) {
|
6 |
self::_do( 'add_filter', $class );
|
@@ -10,21 +11,36 @@ class scbHooks {
|
|
10 |
self::_do( 'remove_filter', $class );
|
11 |
}
|
12 |
|
13 |
-
public static function debug( $class ) {
|
|
|
|
|
14 |
echo "<pre>";
|
15 |
self::_do( array( __CLASS__, '_print' ), $class );
|
16 |
echo "</pre>";
|
17 |
}
|
18 |
|
19 |
private static function _print( $tag, $callback, $prio, $argc ) {
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
23 |
$class = "'" . $callback[0] . "'";
|
|
|
|
|
24 |
|
25 |
-
$func = "
|
26 |
|
27 |
-
echo "add_filter( '$tag', $func
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
}
|
29 |
|
30 |
private static function _do( $action, $class ) {
|
@@ -38,10 +54,17 @@ class scbHooks {
|
|
38 |
continue;
|
39 |
}
|
40 |
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
|
|
|
|
|
45 |
}
|
46 |
}
|
47 |
}
|
1 |
<?php
|
2 |
|
3 |
class scbHooks {
|
4 |
+
private static $mangle_name;
|
5 |
|
6 |
public static function add( $class ) {
|
7 |
self::_do( 'add_filter', $class );
|
11 |
self::_do( 'remove_filter', $class );
|
12 |
}
|
13 |
|
14 |
+
public static function debug( $class, $mangle_name = false ) {
|
15 |
+
self::$mangle_name = $mangle_name;
|
16 |
+
|
17 |
echo "<pre>";
|
18 |
self::_do( array( __CLASS__, '_print' ), $class );
|
19 |
echo "</pre>";
|
20 |
}
|
21 |
|
22 |
private static function _print( $tag, $callback, $prio, $argc ) {
|
23 |
+
$static = !is_object( $callback[0] );
|
24 |
+
|
25 |
+
if ( self::$mangle_name )
|
26 |
+
$class = $static ? '__CLASS__' : '$this';
|
27 |
+
else if ( $static )
|
28 |
$class = "'" . $callback[0] . "'";
|
29 |
+
else
|
30 |
+
$class = '$' . get_class( $callback[0] );
|
31 |
|
32 |
+
$func = "array( $class, '$callback[1]' )";
|
33 |
|
34 |
+
echo "add_filter( '$tag', $func";
|
35 |
+
|
36 |
+
if ( $prio != 10 || $argc > 1 ) {
|
37 |
+
echo ", $prio";
|
38 |
+
|
39 |
+
if ( $argc > 1 )
|
40 |
+
echo ", $argc";
|
41 |
+
}
|
42 |
+
|
43 |
+
echo " );\n";
|
44 |
}
|
45 |
|
46 |
private static function _do( $action, $class ) {
|
54 |
continue;
|
55 |
}
|
56 |
|
57 |
+
preg_match_all( '/@hook:?\s+([^\s]+)/', $comment, $matches ) ? $matches[1] : $method->name;
|
58 |
+
if ( empty( $matches[1] ) )
|
59 |
+
$hooks = array( $method->name );
|
60 |
+
else
|
61 |
+
$hooks = $matches[1];
|
62 |
+
|
63 |
+
$priority = preg_match( '/@priority:?\s+(\d+)/', $comment, $matches ) ? $matches[1] : 10;
|
64 |
|
65 |
+
foreach ( $hooks as $hook ) {
|
66 |
+
call_user_func( $action, $hook, array( $class, $method->name ), $priority, $method->getNumberOfParameters() );
|
67 |
+
}
|
68 |
}
|
69 |
}
|
70 |
}
|
scb/Util.php
CHANGED
@@ -25,12 +25,10 @@ class scbUtil {
|
|
25 |
|
26 |
ob_start();
|
27 |
$wp_styles->do_items( ( array ) $handles );
|
28 |
-
$content = str_replace( array( '"
|
29 |
|
30 |
echo "<script type='text/javascript'>\n";
|
31 |
-
echo "jQuery(
|
32 |
-
echo "$( 'head' ).prepend( \"$content\" );\n";
|
33 |
-
echo "} );\n";
|
34 |
echo "</script>";
|
35 |
}
|
36 |
|
@@ -67,24 +65,20 @@ class scbUtil {
|
|
67 |
|
68 |
// Extract certain $keys from $array
|
69 |
static function array_extract( $array, $keys ) {
|
70 |
-
_deprecated_function( '
|
71 |
return wp_array_slice_assoc( $array, $keys );
|
72 |
}
|
73 |
|
74 |
// Extract a certain value from a list of arrays
|
75 |
static function array_pluck( $array, $key ) {
|
76 |
-
_deprecated_function( '
|
77 |
return wp_list_pluck( $array, $key );
|
78 |
}
|
79 |
|
80 |
// Transform a list of objects into an associative array
|
81 |
static function objects_to_assoc( $objects, $key, $value ) {
|
82 |
-
|
83 |
-
|
84 |
-
foreach ( $objects as $obj )
|
85 |
-
$r[$obj->$key] = $obj->$value;
|
86 |
-
|
87 |
-
return $r;
|
88 |
}
|
89 |
|
90 |
// Prepare an array for an IN statement
|
@@ -110,6 +104,22 @@ class scbUtil {
|
|
110 |
}
|
111 |
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
//_____Minimalist HTML framework_____
|
114 |
|
115 |
/*
|
@@ -158,7 +168,7 @@ function html_link( $url, $title = '' ) {
|
|
158 |
if ( empty( $title ) )
|
159 |
$title = $url;
|
160 |
|
161 |
-
return
|
162 |
}
|
163 |
endif;
|
164 |
|
25 |
|
26 |
ob_start();
|
27 |
$wp_styles->do_items( ( array ) $handles );
|
28 |
+
$content = str_replace( array( "'", "\n" ), array( '"', '' ), ob_get_clean() );
|
29 |
|
30 |
echo "<script type='text/javascript'>\n";
|
31 |
+
echo "jQuery(function ($) { $('head').prepend('$content'); });\n";
|
|
|
|
|
32 |
echo "</script>";
|
33 |
}
|
34 |
|
65 |
|
66 |
// Extract certain $keys from $array
|
67 |
static function array_extract( $array, $keys ) {
|
68 |
+
_deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'WP 3.1', 'wp_array_slice_assoc()' );
|
69 |
return wp_array_slice_assoc( $array, $keys );
|
70 |
}
|
71 |
|
72 |
// Extract a certain value from a list of arrays
|
73 |
static function array_pluck( $array, $key ) {
|
74 |
+
_deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'WP 3.1', 'wp_list_pluck()' );
|
75 |
return wp_list_pluck( $array, $key );
|
76 |
}
|
77 |
|
78 |
// Transform a list of objects into an associative array
|
79 |
static function objects_to_assoc( $objects, $key, $value ) {
|
80 |
+
_deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'r41', 'scb_list_fold()' );
|
81 |
+
return scb_list_fold( $objects, $key, $value );
|
|
|
|
|
|
|
|
|
82 |
}
|
83 |
|
84 |
// Prepare an array for an IN statement
|
104 |
}
|
105 |
|
106 |
|
107 |
+
// Transform a list of objects into an associative array
|
108 |
+
function scb_list_fold( $list, $key, $value ) {
|
109 |
+
$r = array();
|
110 |
+
|
111 |
+
if ( is_array( reset( $list ) ) ) {
|
112 |
+
foreach ( $list as $item )
|
113 |
+
$r[ $item[ $key ] ] = $item[ $value ];
|
114 |
+
} else {
|
115 |
+
foreach ( $list as $item )
|
116 |
+
$r[ $item->$key ] = $item->$value;
|
117 |
+
}
|
118 |
+
|
119 |
+
return $r;
|
120 |
+
}
|
121 |
+
|
122 |
+
|
123 |
//_____Minimalist HTML framework_____
|
124 |
|
125 |
/*
|
168 |
if ( empty( $title ) )
|
169 |
$title = $url;
|
170 |
|
171 |
+
return html( 'a', array( 'href' => $url ), $title );
|
172 |
}
|
173 |
endif;
|
174 |
|
scb/Widget.php
CHANGED
@@ -50,40 +50,26 @@ abstract class scbWidget extends WP_Widget {
|
|
50 |
// See scbForms::input()
|
51 |
// Allows extra parameter $args['title']
|
52 |
protected function input( $args, $formdata = array() ) {
|
|
|
|
|
|
|
|
|
53 |
// Add default class
|
54 |
-
if ( !isset( $args['extra'] ) )
|
55 |
-
$args['extra'] = 'class
|
56 |
|
57 |
// Add default label position
|
58 |
if ( !in_array( $args['type'], array( 'checkbox', 'radio' ) ) && empty( $args['desc_pos'] ) )
|
59 |
$args['desc_pos'] = 'before';
|
60 |
|
61 |
-
|
62 |
-
$new_formdata = array();
|
63 |
-
foreach ( ( array ) $args['name'] as $name )
|
64 |
-
$new_formdata[$this->scb_get_field_name( $name )] = @$formdata[$name];
|
65 |
-
$new_names = array_keys( $new_formdata );
|
66 |
-
|
67 |
-
// Finally, replace the old names
|
68 |
-
if ( 1 == count( $new_names ) )
|
69 |
-
$args['name'] = $new_names[0];
|
70 |
-
else
|
71 |
-
$args['name'] = $new_names;
|
72 |
-
|
73 |
-
return scbForms::input( $args, $new_formdata );
|
74 |
-
}
|
75 |
-
|
76 |
-
|
77 |
-
//_____INTERNAL METHODS_____
|
78 |
|
|
|
|
|
79 |
|
80 |
-
|
81 |
-
if ( $split = scbUtil::split_at( '[', $name ) )
|
82 |
-
list( $basename, $extra ) = $split;
|
83 |
-
else
|
84 |
-
return $this->get_field_name( $name );
|
85 |
|
86 |
-
return
|
87 |
}
|
88 |
}
|
89 |
|
50 |
// See scbForms::input()
|
51 |
// Allows extra parameter $args['title']
|
52 |
protected function input( $args, $formdata = array() ) {
|
53 |
+
$prefix = array( 'widget-' . $this->id_base, $this->number );
|
54 |
+
|
55 |
+
$form = new scbForm( $formdata, $prefix );
|
56 |
+
|
57 |
// Add default class
|
58 |
+
if ( !isset( $args['extra'] ) && 'text' == $args['type'] )
|
59 |
+
$args['extra'] = array( 'class' => 'widefat' );
|
60 |
|
61 |
// Add default label position
|
62 |
if ( !in_array( $args['type'], array( 'checkbox', 'radio' ) ) && empty( $args['desc_pos'] ) )
|
63 |
$args['desc_pos'] = 'before';
|
64 |
|
65 |
+
$name = $args['name'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
+
if ( !is_array( $name ) && '[]' == substr( $name, -2 ) )
|
68 |
+
$name = array( substr( $name, 0, -2 ), '' );
|
69 |
|
70 |
+
$args['name'] = $name;
|
|
|
|
|
|
|
|
|
71 |
|
72 |
+
return $form->input( $args );
|
73 |
}
|
74 |
}
|
75 |
|
scb/load.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
$GLOBALS['_scb_data'] = array(
|
4 |
'scbUtil', 'scbOptions', 'scbForms', 'scbTable',
|
5 |
'scbWidget', 'scbAdminPage', 'scbBoxesPage',
|
6 |
'scbCron', 'scbHooks',
|
1 |
<?php
|
2 |
|
3 |
+
$GLOBALS['_scb_data'] = array( 41, __FILE__, array(
|
4 |
'scbUtil', 'scbOptions', 'scbForms', 'scbTable',
|
5 |
'scbWidget', 'scbAdminPage', 'scbBoxesPage',
|
6 |
'scbCron', 'scbHooks',
|
screenshot-2.png
CHANGED
Binary file
|
test/debug.php
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class P2P_Debug {
|
4 |
+
|
5 |
+
private static $ctype;
|
6 |
+
|
7 |
+
function init() {
|
8 |
+
if ( !function_exists('p2p_register_connection_type') )
|
9 |
+
return;
|
10 |
+
|
11 |
+
add_action('init', array(__CLASS__, '_init'));
|
12 |
+
add_action('load-index.php', array(__CLASS__, 'test'));
|
13 |
+
}
|
14 |
+
|
15 |
+
function _init() {
|
16 |
+
register_post_type('actor', array(
|
17 |
+
'public' => true,
|
18 |
+
'labels' => array(
|
19 |
+
'name' => 'Actors',
|
20 |
+
'singular_name' => 'Actor',
|
21 |
+
'search_items' => 'Search Actors',
|
22 |
+
'new_item' => 'New Actor',
|
23 |
+
'not_found' => 'No actors found.'
|
24 |
+
),
|
25 |
+
'has_archive' => 'actors',
|
26 |
+
'taxonomies' => array( 'category' )
|
27 |
+
));
|
28 |
+
|
29 |
+
register_post_type('movie', array(
|
30 |
+
'public' => true,
|
31 |
+
'labels' => array(
|
32 |
+
'name' => 'Movies',
|
33 |
+
'singular_name' => 'Movie',
|
34 |
+
'search_items' => 'Search movies',
|
35 |
+
'new_item' => 'New Movie',
|
36 |
+
'not_found' => 'No movies found.',
|
37 |
+
)
|
38 |
+
) );
|
39 |
+
|
40 |
+
p2p_register_connection_type( array(
|
41 |
+
'from' => 'actor',
|
42 |
+
'to' => 'movie',
|
43 |
+
'fields' => array(
|
44 |
+
'role' => 'Role',
|
45 |
+
'role_type' => array( 'title' => 'Role Type', 'values' => array( 'lead', 'secondary', 'episodic' ) ),
|
46 |
+
),
|
47 |
+
'sortable' => 'order',
|
48 |
+
'prevent_duplicates' => false,
|
49 |
+
'context' => 'advanced',
|
50 |
+
'reciprocal' => true,
|
51 |
+
'title' => array(
|
52 |
+
'from' => 'Played In',
|
53 |
+
'to' => 'Cast'
|
54 |
+
)
|
55 |
+
) );
|
56 |
+
|
57 |
+
p2p_register_connection_type( array(
|
58 |
+
'from' => 'actor',
|
59 |
+
'to' => 'actor',
|
60 |
+
'reciprocal' => true,
|
61 |
+
'title' => array( 'from' => 'Doubles', 'to' => 'Main Actor' ),
|
62 |
+
'data' => array( 'type' => 'doubles' ),
|
63 |
+
'sortable' => 'order'
|
64 |
+
) );
|
65 |
+
|
66 |
+
p2p_register_connection_type( array(
|
67 |
+
'from' => array( 'foo', 'actor' ),
|
68 |
+
'to' => 'actor',
|
69 |
+
'reciprocal' => true,
|
70 |
+
'title' => 'Friends with',
|
71 |
+
'data' => array( 'type' => 'friends' )
|
72 |
+
) );
|
73 |
+
|
74 |
+
//register_post_type('actor');
|
75 |
+
//register_post_type('movie');
|
76 |
+
|
77 |
+
//global $wpdb;
|
78 |
+
|
79 |
+
//$movie_ids = $actor_ids = array();
|
80 |
+
|
81 |
+
//for ( $i=0; $i<20; $i++ ) {
|
82 |
+
//$actor_ids[] = wp_insert_post(array(
|
83 |
+
//'post_type' => 'actor',
|
84 |
+
//'post_title' => "Actor $i",
|
85 |
+
//'post_status' => 'publish'
|
86 |
+
//));
|
87 |
+
|
88 |
+
//$movie_ids[] = wp_insert_post(array(
|
89 |
+
//'post_type' => 'movie',
|
90 |
+
//'post_title' => "Movie $i",
|
91 |
+
//'post_status' => 'publish'
|
92 |
+
//));
|
93 |
+
//}
|
94 |
+
|
95 |
+
self::$ctype = p2p_register_connection_type( array( 'actor', 'post' ), array( 'page', 'movie' ), true );
|
96 |
+
}
|
97 |
+
|
98 |
+
function test() {
|
99 |
+
self::test_each_connected();
|
100 |
+
}
|
101 |
+
|
102 |
+
function test_ordering() {
|
103 |
+
$query = new WP_Query( array(
|
104 |
+
'connected' => $actor_ids[0],
|
105 |
+
'post_type' => 'movie',
|
106 |
+
'post_status' => 'any',
|
107 |
+
'nopaging' => true,
|
108 |
+
|
109 |
+
'connected_meta' => array( 'foo' => 'bar' ),
|
110 |
+
|
111 |
+
'connected_orderby' => 'role',
|
112 |
+
'connected_order_num' => true,
|
113 |
+
'connected_order' => 'asc'
|
114 |
+
) );
|
115 |
+
|
116 |
+
self::walk( $posts );
|
117 |
+
}
|
118 |
+
|
119 |
+
function test_each_connected() {
|
120 |
+
$query = new WP_Query( array( 'post_status' => 'publish' ) );
|
121 |
+
|
122 |
+
self::$ctype->each_connected( $query );
|
123 |
+
|
124 |
+
self::walk( $query->posts );
|
125 |
+
}
|
126 |
+
|
127 |
+
private function walk( $posts, $level = 0 ) {
|
128 |
+
if ( !isset( $_GET['p2p_debug'] ) )
|
129 |
+
return;
|
130 |
+
|
131 |
+
if ( 0 == $level )
|
132 |
+
echo "<pre>\n";
|
133 |
+
|
134 |
+
foreach ( $posts as $post ) {
|
135 |
+
echo str_repeat( "\t", $level ) . "$post->ID: $post->post_title\n";
|
136 |
+
|
137 |
+
self::walk( (array) @$post->connected, $level+1 );
|
138 |
+
}
|
139 |
+
|
140 |
+
if ( 0 == $level )
|
141 |
+
echo "</pre>\n";
|
142 |
+
}
|
143 |
+
|
144 |
+
function debug() {
|
145 |
+
global $wpdb;
|
146 |
+
|
147 |
+
$rows = $wpdb->get_results("SELECT * FROM $wpdb->p2p");
|
148 |
+
|
149 |
+
foreach ( $rows as $row ) {
|
150 |
+
echo html_link( get_edit_post_link( $row->p2p_from ), $row->p2p_from ) . ' -> ';
|
151 |
+
echo html_link( get_edit_post_link( $row->p2p_to ), $row->p2p_to );
|
152 |
+
echo '<br>';
|
153 |
+
}
|
154 |
+
|
155 |
+
die;
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
add_action( 'plugins_loaded', array( 'P2P_Debug', 'init' ), 11 );
|
160 |
+
|
test/unit.php
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
#define( 'WP_ADMIN', true );
|
4 |
+
|
5 |
+
class P2P_Unit_Tests extends WP_UnitTestCase {
|
6 |
+
|
7 |
+
var $plugin_slug = 'p2p/posts-to-posts';
|
8 |
+
|
9 |
+
function test_basic_api() {
|
10 |
+
register_post_type('actor');
|
11 |
+
register_post_type('movie');
|
12 |
+
|
13 |
+
global $wpdb;
|
14 |
+
|
15 |
+
$movie_ids = $actor_ids = array();
|
16 |
+
|
17 |
+
for ( $i=0; $i<20; $i++ ) {
|
18 |
+
$actor_ids[] = wp_insert_post(array(
|
19 |
+
'post_type' => 'actor',
|
20 |
+
'post_title' => "Actor $i",
|
21 |
+
'post_status' => 'publish'
|
22 |
+
));
|
23 |
+
|
24 |
+
$movie_ids[] = wp_insert_post(array(
|
25 |
+
'post_type' => 'movie',
|
26 |
+
'post_title' => "Movie $i",
|
27 |
+
'post_status' => 'publish'
|
28 |
+
));
|
29 |
+
}
|
30 |
+
|
31 |
+
p2p_connect( array_slice( $actor_ids, 0, 5 ), array_slice( $movie_ids, 0, 3 ) );
|
32 |
+
p2p_connect( $movie_ids[0], $actor_ids[10] );
|
33 |
+
|
34 |
+
$result = array_values( p2p_get_connected( $actor_ids[0], 'from' ) );
|
35 |
+
sort( $result );
|
36 |
+
$expected = array_slice( $movie_ids, 0, 3 );
|
37 |
+
sort($expected);
|
38 |
+
$this->assertEquals( $expected, $result );
|
39 |
+
|
40 |
+
$result = array_values( p2p_get_connected( $movie_ids[0], 'any' ) );
|
41 |
+
sort( $result );
|
42 |
+
$expected = array( $actor_ids[0], $actor_ids[10] );
|
43 |
+
sort( $expected );
|
44 |
+
$this->assertEquals( $expected, $result );
|
45 |
+
|
46 |
+
$this->assertTrue( p2p_is_connected( $actor_ids[0], $movie_ids[0] ) );
|
47 |
+
$this->assertFalse( p2p_is_connected( $actor_ids[0], $movie_ids[10] ) );
|
48 |
+
|
49 |
+
// 'actor' => 'actor'
|
50 |
+
$posts = get_posts( array(
|
51 |
+
'connected' => $actor_ids[0],
|
52 |
+
'post_type' => 'actor',
|
53 |
+
'post_status' => 'any',
|
54 |
+
'suppress_filters' => false,
|
55 |
+
'fields' => 'ids',
|
56 |
+
) );
|
57 |
+
$this->assertEmpty( $posts );
|
58 |
+
|
59 |
+
// compare p2p_get_connected() to 'connected' => 123
|
60 |
+
p2p_connect( $actor_ids[2], $actor_ids[10] );
|
61 |
+
p2p_connect( $actor_ids[10], $actor_ids[2] );
|
62 |
+
|
63 |
+
$raw = p2p_get_connected($actor_ids[2], 'any');
|
64 |
+
|
65 |
+
$posts = get_posts( array(
|
66 |
+
'connected' => $actor_ids[2],
|
67 |
+
'post_type' => 'actor',
|
68 |
+
'post_status' => 'any',
|
69 |
+
'suppress_filters' => false,
|
70 |
+
'cache_results' => false,
|
71 |
+
) );
|
72 |
+
|
73 |
+
$r = scb_list_fold( $posts, 'p2p_id', 'ID' );
|
74 |
+
|
75 |
+
$this->assertEquals( array_intersect_assoc( $r, $raw ), $r );
|
76 |
+
}
|
77 |
+
|
78 |
+
function test_connection_types() {
|
79 |
+
foreach ( array( 'actor', 'movie', 'studio' ) as $ptype )
|
80 |
+
register_post_type( $ptype );
|
81 |
+
|
82 |
+
// Normal connections
|
83 |
+
$normal = p2p_register_connection_type( 'actor', 'movie' );
|
84 |
+
|
85 |
+
$this->assertInstanceOf( 'P2P_Connection_Type', $normal );
|
86 |
+
|
87 |
+
$this->assertEquals( 'from', $normal->get_direction( 'actor' ) );
|
88 |
+
$this->assertEquals( 'to', $normal->get_direction( 'movie' ) );
|
89 |
+
$this->assertFalse( $normal->get_direction( 'post' ) );
|
90 |
+
|
91 |
+
// Recursive connections
|
92 |
+
$recursive = p2p_register_connection_type( 'actor', 'actor' );
|
93 |
+
|
94 |
+
$this->assertInstanceOf( 'P2P_Connection_Type', $recursive );
|
95 |
+
|
96 |
+
$this->assertEquals( 'any', $recursive->get_direction( 'actor' ) );
|
97 |
+
$this->assertFalse( $recursive->get_direction( 'post' ) );
|
98 |
+
|
99 |
+
// 'from' array
|
100 |
+
$multiple = p2p_register_connection_type( array( 'actor', 'movie' ), 'studio' );
|
101 |
+
|
102 |
+
$this->assertInstanceOf( 'P2P_Connection_Type', $multiple );
|
103 |
+
|
104 |
+
$this->assertEquals( 'to', $multiple->get_direction( 'studio' ) );
|
105 |
+
$this->assertEquals( 'from', $multiple->get_direction( 'actor' ) );
|
106 |
+
$this->assertEquals( 'from', $multiple->get_direction( 'movie' ) );
|
107 |
+
$this->assertFalse( $multiple->get_direction( 'post' ) );
|
108 |
+
|
109 |
+
// 'to' array
|
110 |
+
$ctype = p2p_register_connection_type( 'actor', array( 'movie', 'studio', 'foo' ) );
|
111 |
+
$this->assertInstanceOf( 'P2P_Connection_Type', $ctype );
|
112 |
+
|
113 |
+
// Invalid
|
114 |
+
$ctype = @p2p_register_connection_type( 'actor', array( 'actor', 'studio' ) );
|
115 |
+
$this->assertFalse( $ctype );
|
116 |
+
|
117 |
+
$ctype = @p2p_register_connection_type( 'foo', 'actor' );
|
118 |
+
$this->assertFalse( $ctype );
|
119 |
+
|
120 |
+
$ctype = @p2p_register_connection_type( 'actor', 'foo' );
|
121 |
+
$this->assertFalse( $ctype );
|
122 |
+
}
|
123 |
+
}
|
124 |
+
|
tests.php
DELETED
@@ -1,275 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Automated testing suite for the Posts 2 Posts plugin
|
4 |
-
|
5 |
-
class P2P_Test {
|
6 |
-
|
7 |
-
function init() {
|
8 |
-
if ( !function_exists('p2p_register_connection_type') )
|
9 |
-
return;
|
10 |
-
|
11 |
-
add_action('init', array(__CLASS__, '_init'));
|
12 |
-
# add_action('admin_init', array(__CLASS__, 'setup'));
|
13 |
-
add_action('load-index.php', array(__CLASS__, 'test'));
|
14 |
-
# add_action('load-index.php', array(__CLASS__, 'debug'));
|
15 |
-
}
|
16 |
-
|
17 |
-
function _init() {
|
18 |
-
register_post_type('actor', array(
|
19 |
-
'public' => true,
|
20 |
-
'labels' => array(
|
21 |
-
'name' => 'Actors',
|
22 |
-
'singular_name' => 'Actor',
|
23 |
-
'search_items' => 'Search Actors',
|
24 |
-
'new_item' => 'New Actor',
|
25 |
-
'not_found' => 'No actors found.'
|
26 |
-
),
|
27 |
-
'has_archive' => 'actors',
|
28 |
-
'taxonomies' => array( 'category' )
|
29 |
-
));
|
30 |
-
register_post_type('movie', array(
|
31 |
-
'public' => true,
|
32 |
-
'labels' => array(
|
33 |
-
'name' => 'Movies',
|
34 |
-
'singular_name' => 'Movie',
|
35 |
-
'search_items' => 'Search movies',
|
36 |
-
'new_item' => 'New Movie',
|
37 |
-
'not_found' => 'No movies found.',
|
38 |
-
)
|
39 |
-
) );
|
40 |
-
|
41 |
-
p2p_register_connection_type( array(
|
42 |
-
'from' => 'actor',
|
43 |
-
'to' => 'movie',
|
44 |
-
'fields' => array(
|
45 |
-
'role' => 'Role',
|
46 |
-
'role_type' => 'Role Type'
|
47 |
-
),
|
48 |
-
'prevent_duplicates' => false,
|
49 |
-
'context' => 'advanced',
|
50 |
-
'reciprocal' => true,
|
51 |
-
'title' => array(
|
52 |
-
'from' => 'Played In',
|
53 |
-
'to' => 'Cast'
|
54 |
-
)
|
55 |
-
) );
|
56 |
-
|
57 |
-
p2p_register_connection_type( array(
|
58 |
-
'from' => 'actor',
|
59 |
-
'to' => 'actor',
|
60 |
-
'reciprocal' => true,
|
61 |
-
'title' => array( 'from' => 'Doubles', 'to' => 'Main Actor' )
|
62 |
-
) );
|
63 |
-
|
64 |
-
p2p_register_connection_type('actor', array('post', 'page'));
|
65 |
-
}
|
66 |
-
|
67 |
-
function setup() {
|
68 |
-
global $wpdb;
|
69 |
-
|
70 |
-
$wpdb->query("DELETE FROM $wpdb->posts WHERE post_type IN ('actor', 'movie')");
|
71 |
-
|
72 |
-
$movie_ids = $actor_ids = array();
|
73 |
-
|
74 |
-
for ( $i=0; $i<20; $i++ ) {
|
75 |
-
$actor_ids[] = wp_insert_post(array(
|
76 |
-
'post_type' => 'actor',
|
77 |
-
'post_title' => "Actor $i",
|
78 |
-
'post_status' => 'publish'
|
79 |
-
));
|
80 |
-
|
81 |
-
$movie_ids[] = wp_insert_post(array(
|
82 |
-
'post_type' => 'movie',
|
83 |
-
'post_title' => "Movie $i",
|
84 |
-
'post_status' => 'publish'
|
85 |
-
));
|
86 |
-
}
|
87 |
-
}
|
88 |
-
|
89 |
-
function test() {
|
90 |
-
global $wpdb;
|
91 |
-
|
92 |
-
$wpdb->query("TRUNCATE $wpdb->p2p");
|
93 |
-
$wpdb->query("TRUNCATE $wpdb->p2pmeta");
|
94 |
-
|
95 |
-
assert_options(ASSERT_ACTIVE, 1);
|
96 |
-
assert_options(ASSERT_WARNING, 0);
|
97 |
-
assert_options(ASSERT_QUIET_EVAL, 1);
|
98 |
-
|
99 |
-
$failed = false;
|
100 |
-
|
101 |
-
assert_options(ASSERT_CALLBACK, function ($file, $line, $code) use ( &$failed ) {
|
102 |
-
$failed = true;
|
103 |
-
|
104 |
-
echo "<hr>Assertion Failed (line $line):<br />
|
105 |
-
<code>$code</code><br /><hr />";
|
106 |
-
|
107 |
-
add_action('admin_notices', array(__CLASS__, 'debug'));
|
108 |
-
});
|
109 |
-
|
110 |
-
$actor_ids = get_posts( array(
|
111 |
-
'fields' => 'ids',
|
112 |
-
'post_type' => 'actor',
|
113 |
-
'post_status' => 'any',
|
114 |
-
'nopaging' => true
|
115 |
-
) );
|
116 |
-
|
117 |
-
$movie_ids = get_posts( array(
|
118 |
-
'fields' => 'ids',
|
119 |
-
'post_type' => 'movie',
|
120 |
-
'post_status' => 'any',
|
121 |
-
'orderby' => 'post_title',
|
122 |
-
'order' => 'asc',
|
123 |
-
'nopaging' => true
|
124 |
-
) );
|
125 |
-
|
126 |
-
// basic API correctness
|
127 |
-
p2p_connect( array_slice( $actor_ids, 0, 5 ), array_slice( $movie_ids, 0, 3 ) );
|
128 |
-
p2p_connect( $movie_ids[0], $actor_ids[10] );
|
129 |
-
|
130 |
-
$result = array_values( p2p_get_connected( $actor_ids[0], 'from' ) );
|
131 |
-
sort( $result );
|
132 |
-
$expected = array_slice( $movie_ids, 0, 3 );
|
133 |
-
sort($expected);
|
134 |
-
assert( '$expected == $result' );
|
135 |
-
|
136 |
-
$result = array_values( p2p_get_connected( $movie_ids[0], 'any' ) );
|
137 |
-
sort( $result );
|
138 |
-
$expected = array( $actor_ids[0], $actor_ids[10] );
|
139 |
-
sort( $expected );
|
140 |
-
assert( '$expected == $result' );
|
141 |
-
|
142 |
-
assert( 'true == p2p_is_connected( $actor_ids[0], $movie_ids[0] )' );
|
143 |
-
assert( 'false == p2p_is_connected( $actor_ids[0], $movie_ids[10] )' );
|
144 |
-
|
145 |
-
// 'actor' => 'actor'
|
146 |
-
$posts = get_posts( array(
|
147 |
-
'connected' => $actor_ids[0],
|
148 |
-
'post_type' => 'actor',
|
149 |
-
'post_status' => 'any',
|
150 |
-
'suppress_filters' => false,
|
151 |
-
'fields' => 'ids',
|
152 |
-
) );
|
153 |
-
assert( 'array() == $posts' );
|
154 |
-
|
155 |
-
// compare p2p_get_connected() to 'connected' => 123
|
156 |
-
p2p_connect( $actor_ids[2], $actor_ids[10] );
|
157 |
-
p2p_connect( $actor_ids[10], $actor_ids[2] );
|
158 |
-
|
159 |
-
$raw = p2p_get_connected($actor_ids[2], 'any');
|
160 |
-
|
161 |
-
$posts = get_posts( array(
|
162 |
-
'connected' => $actor_ids[2],
|
163 |
-
'post_type' => 'actor',
|
164 |
-
'post_status' => 'any',
|
165 |
-
'suppress_filters' => false,
|
166 |
-
'cache_results' => false,
|
167 |
-
) );
|
168 |
-
|
169 |
-
$r = array();
|
170 |
-
foreach ( $posts as $post ) {
|
171 |
-
$r[ $post->p2p_id ] = $post->ID;
|
172 |
-
}
|
173 |
-
|
174 |
-
assert( 'array_intersect_assoc($r, $raw) == $r' );
|
175 |
-
|
176 |
-
// test ordering
|
177 |
-
$query = new WP_Query( array(
|
178 |
-
'connected' => $actor_ids[0],
|
179 |
-
'post_type' => 'movie',
|
180 |
-
'post_status' => 'any',
|
181 |
-
'nopaging' => true,
|
182 |
-
|
183 |
-
'connected_orderby' => 'role',
|
184 |
-
'connected_order_num' => true,
|
185 |
-
'connected_order' => 'asc'
|
186 |
-
) );
|
187 |
-
|
188 |
-
// test 'each_*' query vars
|
189 |
-
$posts = get_posts( array(
|
190 |
-
'post_type' => 'actor',
|
191 |
-
'post_status' => 'any',
|
192 |
-
'nopaging' => true,
|
193 |
-
'each_connected' => array(
|
194 |
-
'post_type' => 'movie',
|
195 |
-
'post_status' => 'any',
|
196 |
-
'nopaging' => true,
|
197 |
-
),
|
198 |
-
'suppress_filters' => false
|
199 |
-
) );
|
200 |
-
|
201 |
-
# self::walk( $posts );
|
202 |
-
|
203 |
-
// test 'each_*' query vars
|
204 |
-
# $posts = get_posts( array(
|
205 |
-
# 'post_type' => 'actor',
|
206 |
-
# 'post_status' => 'any',
|
207 |
-
# 'nopaging' => true,
|
208 |
-
# 'each_connected' => array(
|
209 |
-
# 'post_type' => 'actor',
|
210 |
-
# 'post_status' => 'any',
|
211 |
-
# 'nopaging' => true,
|
212 |
-
# 'each_connected' => array(
|
213 |
-
# 'post_type' => 'actor',
|
214 |
-
# 'post_status' => 'any',
|
215 |
-
# 'nopaging' => true,
|
216 |
-
# ),
|
217 |
-
# ),
|
218 |
-
# 'suppress_filters' => false
|
219 |
-
# ) );
|
220 |
-
|
221 |
-
self::walk( $posts );
|
222 |
-
|
223 |
-
// test p2p_each_connected()
|
224 |
-
$query = new WP_Query( array(
|
225 |
-
'post_type' => 'actor',
|
226 |
-
'post_status' => 'any',
|
227 |
-
'nopaging' => true,
|
228 |
-
) );
|
229 |
-
|
230 |
-
p2p_each_connected( $query, array( 'post_type' => 'movie' ) );
|
231 |
-
|
232 |
-
self::walk( $query->posts );
|
233 |
-
|
234 |
-
if ( $failed )
|
235 |
-
self::debug();
|
236 |
-
}
|
237 |
-
|
238 |
-
private function walk( $posts, $level = 0 ) {
|
239 |
-
if ( !isset( $_GET['p2p_debug'] ) )
|
240 |
-
return;
|
241 |
-
|
242 |
-
if ( 0 == $level )
|
243 |
-
echo '<pre>';
|
244 |
-
|
245 |
-
foreach ( $posts as $post ) {
|
246 |
-
echo str_repeat( "\t", $level ) . "$post->ID: $post->post_title\n";
|
247 |
-
|
248 |
-
// Meta cache test
|
249 |
-
if ( isset( $post->p2p_id ) )
|
250 |
-
p2p_get_meta( $post->p2p_id, 'foo', true );
|
251 |
-
|
252 |
-
self::walk( (array) @$post->connected, $level+1 );
|
253 |
-
}
|
254 |
-
|
255 |
-
if ( 0 == $level )
|
256 |
-
echo '</pre>';
|
257 |
-
}
|
258 |
-
|
259 |
-
function debug() {
|
260 |
-
global $wpdb;
|
261 |
-
|
262 |
-
$rows = $wpdb->get_results("SELECT * FROM $wpdb->p2p");
|
263 |
-
|
264 |
-
foreach ( $rows as $row ) {
|
265 |
-
echo html_link( get_edit_post_link( $row->p2p_from ), $row->p2p_from ) . ' -> ';
|
266 |
-
echo html_link( get_edit_post_link( $row->p2p_to ), $row->p2p_to );
|
267 |
-
echo '<br>';
|
268 |
-
}
|
269 |
-
|
270 |
-
die;
|
271 |
-
}
|
272 |
-
}
|
273 |
-
|
274 |
-
add_action( 'plugins_loaded', array('P2P_Test', 'init'), 11 );
|
275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ui.php
DELETED
@@ -1,145 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
define( 'P2P_BOX_NONCE', 'p2p-box' );
|
4 |
-
|
5 |
-
abstract class P2P_Box {
|
6 |
-
public $box_id;
|
7 |
-
|
8 |
-
public $from;
|
9 |
-
public $to;
|
10 |
-
|
11 |
-
protected $reversed;
|
12 |
-
protected $direction;
|
13 |
-
|
14 |
-
// Enqueue scripts here
|
15 |
-
function setup() {}
|
16 |
-
|
17 |
-
// This is where the box content goes
|
18 |
-
abstract function render_box( $post_id );
|
19 |
-
|
20 |
-
function get_box_title() {
|
21 |
-
if ( is_array( $this->title ) ) {
|
22 |
-
$key = $this->reversed ? 'to' : 'from';
|
23 |
-
|
24 |
-
if ( isset( $this->title[ $key ] ) )
|
25 |
-
$title = $this->title[ $key ];
|
26 |
-
else
|
27 |
-
$title = '';
|
28 |
-
} else {
|
29 |
-
$title = $this->title;
|
30 |
-
}
|
31 |
-
|
32 |
-
if ( empty( $title ) ) {
|
33 |
-
$title = sprintf( __( 'Connected %s', 'posts-to-posts' ), get_post_type_object( $this->to )->labels->name );
|
34 |
-
}
|
35 |
-
|
36 |
-
return $title;
|
37 |
-
}
|
38 |
-
|
39 |
-
|
40 |
-
// Internal stuff
|
41 |
-
|
42 |
-
|
43 |
-
public function __construct( $args, $direction, $box_id ) {
|
44 |
-
foreach ( $args as $key => $value )
|
45 |
-
$this->$key = $value;
|
46 |
-
|
47 |
-
$this->box_id = $box_id;
|
48 |
-
|
49 |
-
$this->direction = $direction;
|
50 |
-
|
51 |
-
$this->reversed = ( 'to' == $direction );
|
52 |
-
|
53 |
-
if ( $this->reversed )
|
54 |
-
list( $this->to, $this->from ) = array( $this->from, $this->to );
|
55 |
-
|
56 |
-
$this->setup();
|
57 |
-
}
|
58 |
-
|
59 |
-
function _box( $post ) {
|
60 |
-
$this->render_box( $post->ID );
|
61 |
-
}
|
62 |
-
}
|
63 |
-
|
64 |
-
|
65 |
-
class P2P_Connection_Types {
|
66 |
-
|
67 |
-
private static $ctypes = array();
|
68 |
-
|
69 |
-
static public function register( $args ) {
|
70 |
-
self::$ctypes[] = $args;
|
71 |
-
}
|
72 |
-
|
73 |
-
static function add_meta_boxes( $from ) {
|
74 |
-
foreach ( self::$ctypes as $box_id => $args ) {
|
75 |
-
$box = self::make_box( $box_id, $from );
|
76 |
-
if ( !$box )
|
77 |
-
continue;
|
78 |
-
|
79 |
-
add_meta_box(
|
80 |
-
'p2p-connections-' . $box->box_id,
|
81 |
-
$box->get_box_title(),
|
82 |
-
array( $box, '_box' ),
|
83 |
-
$box->from,
|
84 |
-
$box->context,
|
85 |
-
'default'
|
86 |
-
);
|
87 |
-
}
|
88 |
-
}
|
89 |
-
|
90 |
-
function save_post( $post_id, $post ) {
|
91 |
-
if ( 'revision' == $post->post_type || !isset( $_POST['p2p_meta'] ) )
|
92 |
-
return;
|
93 |
-
|
94 |
-
foreach ( $_POST['p2p_meta'] as $p2p_id => $data ) {
|
95 |
-
foreach ( $data as $key => $value ) {
|
96 |
-
p2p_update_meta( $p2p_id, $key, $value );
|
97 |
-
}
|
98 |
-
}
|
99 |
-
}
|
100 |
-
|
101 |
-
function wp_ajax_p2p_box() {
|
102 |
-
check_ajax_referer( P2P_BOX_NONCE, 'nonce' );
|
103 |
-
|
104 |
-
$box = self::make_box( $_REQUEST['box_id'], $_REQUEST['post_type'] );
|
105 |
-
if ( !$box )
|
106 |
-
die(0);
|
107 |
-
|
108 |
-
$ptype_obj = get_post_type_object( $box->from );
|
109 |
-
if ( !current_user_can( $ptype_obj->cap->edit_posts ) )
|
110 |
-
die(-1);
|
111 |
-
|
112 |
-
$method = 'ajax_' . $_REQUEST['subaction'];
|
113 |
-
|
114 |
-
$box->$method();
|
115 |
-
}
|
116 |
-
|
117 |
-
private static function make_box( $box_id, $post_type ) {
|
118 |
-
if ( !isset( self::$ctypes[ $box_id ] ) )
|
119 |
-
return false;
|
120 |
-
|
121 |
-
$args = self::$ctypes[ $box_id ];
|
122 |
-
|
123 |
-
$direction = self::get_direction( $post_type, $args );
|
124 |
-
if ( !$direction )
|
125 |
-
return false;
|
126 |
-
|
127 |
-
return new $args['box']( $args, $direction, $box_id );
|
128 |
-
}
|
129 |
-
|
130 |
-
private static function get_direction( $post_type, $args ) {
|
131 |
-
$direction = false;
|
132 |
-
|
133 |
-
if ( $args['reciprocal'] && $post_type == $args['from'] && $args['from'] == $args['to'] ) {
|
134 |
-
$direction = 'any';
|
135 |
-
} elseif ( $args['reciprocal'] && $post_type == $args['to'] ) {
|
136 |
-
$direction = 'to';
|
137 |
-
} elseif ( $post_type == $args['from'] ) {
|
138 |
-
$direction = 'from';
|
139 |
-
}
|
140 |
-
|
141 |
-
return $direction;
|
142 |
-
}
|
143 |
-
}
|
144 |
-
scbHooks::add( 'P2P_Connection_Types' );
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ui/box.js
DELETED
@@ -1,280 +0,0 @@
|
|
1 |
-
jQuery(document).ready(function($) {
|
2 |
-
|
3 |
-
// Placeholder support for IE
|
4 |
-
if (!jQuery('<input placeholder="1" />')[0].placeholder) {
|
5 |
-
jQuery('.p2p-search input[placeholder]').each(function(){
|
6 |
-
var $this = $(this);
|
7 |
-
if (!$this.val()) {
|
8 |
-
$this.val($this.attr('placeholder'));
|
9 |
-
$this.addClass('p2p-placeholder');
|
10 |
-
}
|
11 |
-
}).focus(function(e){
|
12 |
-
var $this = $(this);
|
13 |
-
if ($this.hasClass('p2p-placeholder')) {
|
14 |
-
$this.val('');
|
15 |
-
$this.removeClass('p2p-placeholder');
|
16 |
-
}
|
17 |
-
}).blur(function(e){
|
18 |
-
var $this = $(this);
|
19 |
-
if (!$this.val()) {
|
20 |
-
$this.addClass('p2p-placeholder');
|
21 |
-
$this.val($this.attr('placeholder'));
|
22 |
-
}
|
23 |
-
});
|
24 |
-
}
|
25 |
-
|
26 |
-
$('.p2p-box').each(function() {
|
27 |
-
var
|
28 |
-
$metabox = $(this),
|
29 |
-
$connections = $metabox.find('.p2p-connections'),
|
30 |
-
$spinner = $('#publishing-action .ajax-loading')
|
31 |
-
.clone()
|
32 |
-
.removeAttr('id')
|
33 |
-
.removeClass('ajax-loading')
|
34 |
-
.addClass('waiting');
|
35 |
-
|
36 |
-
function get_base_data() {
|
37 |
-
return {
|
38 |
-
action: 'p2p_box',
|
39 |
-
nonce: P2PAdmin_I18n.nonce,
|
40 |
-
box_id: $metabox.attr('data-box_id'),
|
41 |
-
post_type: $('#post_type').val()
|
42 |
-
};
|
43 |
-
}
|
44 |
-
|
45 |
-
// Delete all connections
|
46 |
-
$metabox.delegate('th.p2p-col-delete a', 'click', function() {
|
47 |
-
if ( !confirm(P2PAdmin_I18n.deleteConfirmMessage) )
|
48 |
-
return false;
|
49 |
-
|
50 |
-
var
|
51 |
-
$self = $(this),
|
52 |
-
$td = $self.closest('td'),
|
53 |
-
data = $.extend( get_base_data(), {
|
54 |
-
subaction: 'clear_connections',
|
55 |
-
post_id: $('#post_ID').val()
|
56 |
-
} );
|
57 |
-
|
58 |
-
$td.html( $spinner.show() );
|
59 |
-
|
60 |
-
$.post(ajaxurl, data, function(response) {
|
61 |
-
$connections.hide()
|
62 |
-
.find('tbody').html('');
|
63 |
-
|
64 |
-
$td.html($self);
|
65 |
-
});
|
66 |
-
|
67 |
-
return false;
|
68 |
-
});
|
69 |
-
|
70 |
-
// Delete connection
|
71 |
-
$metabox.delegate('td.p2p-col-delete a', 'click', function() {
|
72 |
-
var
|
73 |
-
$self = $(this),
|
74 |
-
$td = $self.closest('td'),
|
75 |
-
data = $.extend( get_base_data(), {
|
76 |
-
subaction: 'disconnect',
|
77 |
-
p2p_id: $self.attr('data-p2p_id')
|
78 |
-
} );
|
79 |
-
|
80 |
-
$td.html( $spinner.show() );
|
81 |
-
|
82 |
-
$.post(ajaxurl, data, function(response) {
|
83 |
-
$td.closest('tr').remove();
|
84 |
-
|
85 |
-
if ( !$connections.find('tbody tr').length )
|
86 |
-
$connections.hide();
|
87 |
-
});
|
88 |
-
|
89 |
-
return false;
|
90 |
-
});
|
91 |
-
|
92 |
-
// Create connection
|
93 |
-
$metabox.delegate('td.p2p-col-create a', 'click', function() {
|
94 |
-
var
|
95 |
-
$self = $(this),
|
96 |
-
$td = $self.closest('td'),
|
97 |
-
data = $.extend( get_base_data(), {
|
98 |
-
subaction: 'connect',
|
99 |
-
from: $('#post_ID').val(),
|
100 |
-
to: $self.attr('data-post_id')
|
101 |
-
} );
|
102 |
-
|
103 |
-
$td.html( $spinner.show() );
|
104 |
-
|
105 |
-
$.post(ajaxurl, data, function(response) {
|
106 |
-
$connections.show()
|
107 |
-
.find('tbody').append(response);
|
108 |
-
|
109 |
-
if ( $metabox.attr('data-prevent_duplicates') ) {
|
110 |
-
var $table = $td.closest('table');
|
111 |
-
|
112 |
-
if ( 1 == $table.find('tbody tr').length )
|
113 |
-
$table.remove();
|
114 |
-
else
|
115 |
-
$td.closest('tr').remove();
|
116 |
-
} else {
|
117 |
-
$td.html( $self );
|
118 |
-
}
|
119 |
-
});
|
120 |
-
|
121 |
-
return false;
|
122 |
-
});
|
123 |
-
|
124 |
-
// Tabs
|
125 |
-
$metabox.delegate('.wp-tab-bar li', 'click', function() {
|
126 |
-
var $tab = $(this);
|
127 |
-
|
128 |
-
// Set active tab
|
129 |
-
$metabox.find('.wp-tab-bar li').removeClass('wp-tab-active');
|
130 |
-
$tab.addClass('wp-tab-active');
|
131 |
-
|
132 |
-
// Set active panel
|
133 |
-
$metabox.find('.tabs-panel').hide();
|
134 |
-
$metabox.find( $tab.attr('data-ref') )
|
135 |
-
.show()
|
136 |
-
.find(':text').focus();
|
137 |
-
|
138 |
-
return false;
|
139 |
-
});
|
140 |
-
|
141 |
-
function PostsTab(selector) {
|
142 |
-
this.tab = $metabox.find(selector);
|
143 |
-
|
144 |
-
this.init_pagination_data();
|
145 |
-
|
146 |
-
this.tab.delegate('.p2p-prev, .p2p-next', 'click', $.proxy(this, 'change_page'));
|
147 |
-
|
148 |
-
this.data = $.extend( get_base_data(), {
|
149 |
-
subaction: 'search',
|
150 |
-
post_id: $('#post_ID').val(),
|
151 |
-
s: ''
|
152 |
-
} );
|
153 |
-
}
|
154 |
-
|
155 |
-
$.extend(PostsTab.prototype, {
|
156 |
-
|
157 |
-
init_pagination_data: function() {
|
158 |
-
this.current_page = this.tab.find('.p2p-current').text() || 1;
|
159 |
-
this.total_pages = this.tab.find('.p2p-total').text() || 1;
|
160 |
-
},
|
161 |
-
|
162 |
-
change_page: function(ev) {
|
163 |
-
var
|
164 |
-
$navButton = $(ev.target),
|
165 |
-
new_page = this.current_page;
|
166 |
-
|
167 |
-
if ( $navButton.hasClass('inactive') )
|
168 |
-
return false;
|
169 |
-
|
170 |
-
if ( $navButton.hasClass('p2p-prev') )
|
171 |
-
new_page--;
|
172 |
-
else
|
173 |
-
new_page++;
|
174 |
-
|
175 |
-
this.find_posts(new_page);
|
176 |
-
|
177 |
-
return false;
|
178 |
-
},
|
179 |
-
|
180 |
-
find_posts: function (new_page) {
|
181 |
-
this.data.paged = new_page ? ( new_page > this.total_pages ? this.current_page : new_page ) : this.current_page;
|
182 |
-
|
183 |
-
$spinner.appendTo( this.tab.find('.p2p-navigation') );
|
184 |
-
$.getJSON(ajaxurl, this.data, $.proxy(this, 'update_rows'));
|
185 |
-
},
|
186 |
-
|
187 |
-
update_rows: function(response) {
|
188 |
-
$spinner.remove();
|
189 |
-
|
190 |
-
this.tab.find('.p2p-results, .p2p-navigation, .p2p-notice').remove();
|
191 |
-
|
192 |
-
if ( 'undefined' === typeof response.rows ) {
|
193 |
-
this.tab.append( $('<div class="p2p-notice">').html(response.msg) );
|
194 |
-
} else {
|
195 |
-
this.tab.append(response.rows);
|
196 |
-
|
197 |
-
this.init_pagination_data();
|
198 |
-
}
|
199 |
-
}
|
200 |
-
});
|
201 |
-
|
202 |
-
var searchTab = new PostsTab('.p2p-tab-search');
|
203 |
-
var recentTab = new PostsTab('.p2p-tab-recent');
|
204 |
-
|
205 |
-
// Search posts
|
206 |
-
var delayed, $searchInput = $metabox.find('.p2p-tab-search :text');
|
207 |
-
|
208 |
-
$searchInput
|
209 |
-
.keypress(function (ev) {
|
210 |
-
if ( 13 === ev.keyCode )
|
211 |
-
return false;
|
212 |
-
})
|
213 |
-
.keyup(function (ev) {
|
214 |
-
if ( undefined !== delayed ) {
|
215 |
-
clearTimeout(delayed);
|
216 |
-
}
|
217 |
-
|
218 |
-
delayed = setTimeout(function () {
|
219 |
-
var searchStr = $searchInput.val();
|
220 |
-
|
221 |
-
if ( '' == searchStr || searchStr === searchTab.data.s ) {
|
222 |
-
return;
|
223 |
-
}
|
224 |
-
|
225 |
-
searchTab.data.s = searchStr;
|
226 |
-
|
227 |
-
$spinner.insertAfter($searchInput).show();
|
228 |
-
|
229 |
-
searchTab.find_posts(1);
|
230 |
-
}, 400);
|
231 |
-
});
|
232 |
-
|
233 |
-
// Post creation
|
234 |
-
var
|
235 |
-
$createButton = $metabox.find('.p2p-tab-create-post .button'),
|
236 |
-
$createInput = $metabox.find('.p2p-tab-create-post :text');
|
237 |
-
|
238 |
-
$createButton.click(function () {
|
239 |
-
var $button = $(this);
|
240 |
-
|
241 |
-
if ( $button.hasClass('inactive') )
|
242 |
-
return false;
|
243 |
-
|
244 |
-
var title = $createInput.val();
|
245 |
-
|
246 |
-
if ( '' === title ) {
|
247 |
-
$createInput.focus();
|
248 |
-
return false;
|
249 |
-
}
|
250 |
-
|
251 |
-
$button.addClass('inactive');
|
252 |
-
|
253 |
-
var data = $.extend( get_base_data(), {
|
254 |
-
subaction: 'create_post',
|
255 |
-
from: $('#post_ID').val(),
|
256 |
-
post_title: title
|
257 |
-
});
|
258 |
-
|
259 |
-
$.post(ajaxurl, data, function (response) {
|
260 |
-
$connections.show()
|
261 |
-
.find('tbody').append(response);
|
262 |
-
|
263 |
-
$createInput.val('');
|
264 |
-
|
265 |
-
$button.removeClass('inactive');
|
266 |
-
});
|
267 |
-
|
268 |
-
return false;
|
269 |
-
});
|
270 |
-
|
271 |
-
$createInput.keypress(function (ev) {
|
272 |
-
if ( 13 === ev.keyCode ) {
|
273 |
-
$createButton.click();
|
274 |
-
|
275 |
-
return false;
|
276 |
-
}
|
277 |
-
});
|
278 |
-
});
|
279 |
-
});
|
280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ui/box.php
DELETED
@@ -1,355 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class P2P_Box_Multiple extends P2P_Box {
|
4 |
-
const POSTS_PER_PAGE = 5;
|
5 |
-
|
6 |
-
function setup() {
|
7 |
-
if ( !class_exists( 'Mustache' ) )
|
8 |
-
require dirname(__FILE__) . '/../mustache/Mustache.php';
|
9 |
-
|
10 |
-
wp_enqueue_style( 'p2p-admin', plugins_url( 'box.css', __FILE__ ), array(), P2P_PLUGIN_VERSION );
|
11 |
-
wp_enqueue_script( 'p2p-admin', plugins_url( 'box.js', __FILE__ ), array( 'jquery' ), P2P_PLUGIN_VERSION, true );
|
12 |
-
wp_localize_script( 'p2p-admin', 'P2PAdmin_I18n', array(
|
13 |
-
'nonce' => wp_create_nonce( P2P_BOX_NONCE ),
|
14 |
-
'deleteConfirmMessage' => __( 'Are you sure you want to delete all connections?', 'posts-to-posts' ),
|
15 |
-
) );
|
16 |
-
|
17 |
-
$this->columns = array_merge(
|
18 |
-
array( 'delete' => $this->column_delete_all() ),
|
19 |
-
array( 'title' => get_post_type_object( $this->to )->labels->singular_name ),
|
20 |
-
$this->fields
|
21 |
-
);
|
22 |
-
}
|
23 |
-
|
24 |
-
|
25 |
-
// Initial rendering
|
26 |
-
|
27 |
-
function render_box( $post_id ) {
|
28 |
-
$connected_ids = $this->get_connected_ids( $post_id );
|
29 |
-
|
30 |
-
$to_cpt = get_post_type_object( $this->to );
|
31 |
-
|
32 |
-
$data = array(
|
33 |
-
'create-label' => __( 'Create connections:', 'posts-to-posts' ),
|
34 |
-
);
|
35 |
-
|
36 |
-
if ( empty( $connected_ids ) )
|
37 |
-
$data['hide-connections'] = 'style="display:none"';
|
38 |
-
|
39 |
-
foreach ( $this->columns as $key => $title ) {
|
40 |
-
$data['thead'][] = array(
|
41 |
-
'column' => $key,
|
42 |
-
'title' => $title
|
43 |
-
);
|
44 |
-
}
|
45 |
-
|
46 |
-
$data_attr = array();
|
47 |
-
foreach ( array( 'box_id', 'direction', 'prevent_duplicates' ) as $key )
|
48 |
-
$data_attr[] = "data-$key='" . $this->$key . "'";
|
49 |
-
$data['attributes'] = implode( ' ', $data_attr );
|
50 |
-
|
51 |
-
$tbody = '';
|
52 |
-
foreach ( $connected_ids as $p2p_id => $post_b ) {
|
53 |
-
$tbody .= $this->connection_row( $p2p_id, $post_b );
|
54 |
-
}
|
55 |
-
$data['tbody'] = $tbody;
|
56 |
-
|
57 |
-
// Search tab
|
58 |
-
$tab_content = self::mustache_render( 'tab-search.html', array(
|
59 |
-
'placeholder' => $to_cpt->labels->search_items,
|
60 |
-
) );
|
61 |
-
|
62 |
-
$data['tabs'][] = array(
|
63 |
-
'tab-id' => 'search',
|
64 |
-
'tab-title' => __( 'Search', 'p2p-textdomain' ),
|
65 |
-
'is-active' => array(true),
|
66 |
-
'tab-content' => $tab_content
|
67 |
-
);
|
68 |
-
|
69 |
-
// Recent tab
|
70 |
-
$data['tabs'][] = array(
|
71 |
-
'tab-id' => 'recent',
|
72 |
-
'tab-title' => __( 'Recent', 'p2p-textdomain' ),
|
73 |
-
'tab-content' => $this->handle_search( $post_id )
|
74 |
-
);
|
75 |
-
|
76 |
-
// Create post tab
|
77 |
-
if ( current_user_can( $to_cpt->cap->edit_posts ) ) {
|
78 |
-
$tab_content = self::mustache_render( 'tab-create-post.html', array(
|
79 |
-
'title' => $to_cpt->labels->add_new_item
|
80 |
-
) );
|
81 |
-
|
82 |
-
$data['tabs'][] = array(
|
83 |
-
'tab-id' => 'create-post',
|
84 |
-
'tab-title' => $to_cpt->labels->new_item,
|
85 |
-
'tab-content' => $tab_content
|
86 |
-
);
|
87 |
-
}
|
88 |
-
|
89 |
-
echo self::mustache_render( 'box.html', $data );
|
90 |
-
}
|
91 |
-
|
92 |
-
protected function connection_row( $p2p_id, $post_id ) {
|
93 |
-
$data = array();
|
94 |
-
foreach ( array_keys( $this->columns ) as $key ) {
|
95 |
-
switch ( $key ) {
|
96 |
-
case 'title':
|
97 |
-
$value = $this->column_title( $post_id );
|
98 |
-
break;
|
99 |
-
|
100 |
-
case 'delete':
|
101 |
-
$value = $this->column_delete( $p2p_id );
|
102 |
-
break;
|
103 |
-
|
104 |
-
default:
|
105 |
-
$value = html( 'input', array(
|
106 |
-
'type' => 'text',
|
107 |
-
'name' => "p2p_meta[$p2p_id][$key]",
|
108 |
-
'value' => p2p_get_meta( $p2p_id, $key, true )
|
109 |
-
) );
|
110 |
-
}
|
111 |
-
|
112 |
-
$data['columns'][] = array(
|
113 |
-
'column' => $key,
|
114 |
-
'content' => $value
|
115 |
-
);
|
116 |
-
}
|
117 |
-
|
118 |
-
return self::mustache_render( 'box-row.html', $data );
|
119 |
-
}
|
120 |
-
|
121 |
-
protected function post_rows( $query ) {
|
122 |
-
$data = array();
|
123 |
-
|
124 |
-
foreach ( $query->posts as $post ) {
|
125 |
-
$row = array();
|
126 |
-
|
127 |
-
foreach ( array( 'create', 'title' ) as $key ) {
|
128 |
-
$row['columns'][] = array(
|
129 |
-
'column' => $key,
|
130 |
-
'content' => call_user_func( array( $this, "column_$key" ), $post->ID )
|
131 |
-
);
|
132 |
-
}
|
133 |
-
|
134 |
-
$data['rows'][] = $row;
|
135 |
-
}
|
136 |
-
|
137 |
-
$current_page = max( 1, $query->get('paged') );
|
138 |
-
$total_pages = $query->max_num_pages;
|
139 |
-
|
140 |
-
if ( $total_pages > 1 ) {
|
141 |
-
$data['navigation'] = array(
|
142 |
-
'current-page' => $current_page,
|
143 |
-
'total-pages' => $total_pages,
|
144 |
-
|
145 |
-
'prev-inactive' => ( 1 == $current_page ) ? 'inactive' : '',
|
146 |
-
'next-inactive' => ( $total_pages == $current_page ) ? 'inactive' : '',
|
147 |
-
|
148 |
-
'prev-label' => __( 'Previous', 'p2p-textdomain' ),
|
149 |
-
'next-label' => __( 'Next', 'p2p-textdomain' ),
|
150 |
-
'of-label' => __( 'of', 'p2p-textdomain' ),
|
151 |
-
);
|
152 |
-
}
|
153 |
-
|
154 |
-
return self::mustache_render( 'tab-recent.html', $data, array( 'box-row' ) );
|
155 |
-
}
|
156 |
-
|
157 |
-
|
158 |
-
// Column rendering
|
159 |
-
|
160 |
-
protected function column_title( $post_id ) {
|
161 |
-
$data = array(
|
162 |
-
'title-attr' => get_post_type_object( get_post_type( $post_id ) )->labels->edit_item,
|
163 |
-
'title' => get_post_field( 'post_title', $post_id ),
|
164 |
-
'url' => get_edit_post_link( $post_id ),
|
165 |
-
);
|
166 |
-
|
167 |
-
$post_status = get_post_status( $post_id );
|
168 |
-
|
169 |
-
if ( 'publish' != $post_status ) {
|
170 |
-
$status_obj = get_post_status_object( $post_status );
|
171 |
-
if ( $status_obj ) {
|
172 |
-
$data['status']['text'] = $status_obj->label;
|
173 |
-
}
|
174 |
-
}
|
175 |
-
|
176 |
-
return self::mustache_render( 'column-title.html', $data );
|
177 |
-
}
|
178 |
-
|
179 |
-
protected function column_create( $post_id ) {
|
180 |
-
$data = array(
|
181 |
-
'post_id' => $post_id,
|
182 |
-
'title' => __( 'Create connection', 'posts-to-posts' )
|
183 |
-
);
|
184 |
-
|
185 |
-
return self::mustache_render( 'column-create.html', $data );
|
186 |
-
}
|
187 |
-
|
188 |
-
protected function column_delete( $p2p_id ) {
|
189 |
-
$data = array(
|
190 |
-
'p2p_id' => $p2p_id,
|
191 |
-
'title' => __( 'Delete connection', 'posts-to-posts' )
|
192 |
-
);
|
193 |
-
|
194 |
-
return self::mustache_render( 'column-delete.html', $data );
|
195 |
-
}
|
196 |
-
|
197 |
-
protected function column_delete_all() {
|
198 |
-
$data = array(
|
199 |
-
'title' => __( 'Delete all connections', 'posts-to-posts' )
|
200 |
-
);
|
201 |
-
|
202 |
-
return self::mustache_render( 'column-delete-all.html', $data );
|
203 |
-
}
|
204 |
-
|
205 |
-
|
206 |
-
// Ajax handlers
|
207 |
-
|
208 |
-
public function ajax_create_post() {
|
209 |
-
$new_post_id = wp_insert_post( array(
|
210 |
-
'post_title' => $_POST['post_title'],
|
211 |
-
'post_author' => get_current_user_id(),
|
212 |
-
'post_type' => $this->to
|
213 |
-
) );
|
214 |
-
|
215 |
-
$this->safe_connect( absint( $_POST['from'] ), $new_post_id );
|
216 |
-
}
|
217 |
-
|
218 |
-
public function ajax_connect() {
|
219 |
-
$this->safe_connect( absint( $_POST['from'] ), absint( $_POST['to'] ) );
|
220 |
-
}
|
221 |
-
|
222 |
-
protected function safe_connect( $from, $to ) {
|
223 |
-
if ( !$from || !$to )
|
224 |
-
die(-1);
|
225 |
-
|
226 |
-
$args = array( $from, $to );
|
227 |
-
|
228 |
-
if ( $this->reversed )
|
229 |
-
$args = array_reverse( $args );
|
230 |
-
|
231 |
-
$p2p_id = false;
|
232 |
-
if ( $this->prevent_duplicates ) {
|
233 |
-
$p2p_ids = P2P_Connections::get( $args[0], $args[1] );
|
234 |
-
|
235 |
-
if ( !empty( $p2p_ids ) )
|
236 |
-
$p2p_id = $p2p_ids[0];
|
237 |
-
}
|
238 |
-
|
239 |
-
if ( !$p2p_id )
|
240 |
-
$p2p_id = P2P_Connections::connect( $args[0], $args[1] );
|
241 |
-
|
242 |
-
die( $this->connection_row( $p2p_id, $to ) );
|
243 |
-
}
|
244 |
-
|
245 |
-
public function ajax_disconnect() {
|
246 |
-
$p2p_id = absint( $_POST['p2p_id'] );
|
247 |
-
|
248 |
-
p2p_delete_connection( $p2p_id );
|
249 |
-
|
250 |
-
die(1);
|
251 |
-
}
|
252 |
-
|
253 |
-
public function ajax_clear_connections() {
|
254 |
-
$post_id = absint( $_POST['post_id'] );
|
255 |
-
|
256 |
-
p2p_disconnect( $post_id, $this->direction );
|
257 |
-
|
258 |
-
die(1);
|
259 |
-
}
|
260 |
-
|
261 |
-
public function ajax_search() {
|
262 |
-
$rows = $this->handle_search( $_GET['post_id'], $_GET['paged'], $_GET['s'] );
|
263 |
-
|
264 |
-
if ( $rows ) {
|
265 |
-
$results = compact( 'rows' );
|
266 |
-
} else {
|
267 |
-
$results = array(
|
268 |
-
'msg' => get_post_type_object( $this->to )->labels->not_found,
|
269 |
-
);
|
270 |
-
}
|
271 |
-
|
272 |
-
die( json_encode( $results ) );
|
273 |
-
}
|
274 |
-
|
275 |
-
protected function handle_search( $post_id, $page = 1, $search = '' ) {
|
276 |
-
$query = new WP_Query( $this->get_query_vars( $post_id, $page, $search ) );
|
277 |
-
|
278 |
-
if ( !$query->have_posts() )
|
279 |
-
return false;
|
280 |
-
|
281 |
-
return $this->post_rows( $query );
|
282 |
-
}
|
283 |
-
|
284 |
-
protected function get_query_vars( $post_id, $page, $search ) {
|
285 |
-
$args = array(
|
286 |
-
'paged' => $page,
|
287 |
-
'post_type' => $this->to,
|
288 |
-
'post_status' => 'any',
|
289 |
-
'posts_per_page' => self::POSTS_PER_PAGE,
|
290 |
-
'suppress_filters' => false,
|
291 |
-
'update_post_term_cache' => false,
|
292 |
-
'update_post_meta_cache' => false
|
293 |
-
);
|
294 |
-
|
295 |
-
if ( $search ) {
|
296 |
-
add_filter( 'posts_search', array( __CLASS__, '_search_by_title' ), 10, 2 );
|
297 |
-
$args['s'] = $search;
|
298 |
-
}
|
299 |
-
|
300 |
-
if ( $this->prevent_duplicates )
|
301 |
-
$args['post__not_in'] = p2p_get_connected( $post_id, $this->direction );
|
302 |
-
|
303 |
-
return $args;
|
304 |
-
}
|
305 |
-
|
306 |
-
function _search_by_title( $sql, $wp_query ) {
|
307 |
-
if ( $wp_query->is_search ) {
|
308 |
-
list( $sql ) = explode( ' OR ', $sql, 2 );
|
309 |
-
return $sql . '))';
|
310 |
-
}
|
311 |
-
|
312 |
-
return $sql;
|
313 |
-
}
|
314 |
-
|
315 |
-
|
316 |
-
// Helpers
|
317 |
-
|
318 |
-
protected function get_connected_ids( $post_id ) {
|
319 |
-
$connected_posts = p2p_get_connected( $post_id, $this->direction );
|
320 |
-
|
321 |
-
if ( empty( $connected_posts ) )
|
322 |
-
return array();
|
323 |
-
|
324 |
-
$args = array(
|
325 |
-
'post__in' => $connected_posts,
|
326 |
-
'post_type'=> $this->to,
|
327 |
-
'post_status' => 'any',
|
328 |
-
'nopaging' => true,
|
329 |
-
'update_post_meta_cache' => false,
|
330 |
-
'update_post_term_cache' => false,
|
331 |
-
'suppress_filters' => false,
|
332 |
-
);
|
333 |
-
|
334 |
-
$post_ids = wp_list_pluck( get_posts($args), 'ID' );
|
335 |
-
|
336 |
-
return array_intersect( $connected_posts, $post_ids ); // to preserve p2p_id keys
|
337 |
-
}
|
338 |
-
|
339 |
-
|
340 |
-
private static function mustache_render( $file, $data, $partials = array() ) {
|
341 |
-
$partial_data = array();
|
342 |
-
foreach ( $partials as $partial ) {
|
343 |
-
$partial_data[$partial] = self::load_template( $partial . '.html' );
|
344 |
-
}
|
345 |
-
|
346 |
-
$m = new Mustache;
|
347 |
-
|
348 |
-
return $m->render( self::load_template( $file ), $data, $partial_data );
|
349 |
-
}
|
350 |
-
|
351 |
-
private function load_template( $file ) {
|
352 |
-
return file_get_contents( dirname(__FILE__) . '/templates/' . $file );
|
353 |
-
}
|
354 |
-
}
|
355 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ui/templates/column-create.html
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<a href="#" data-post_id="{{post_id}}" title="{{title}}">{{title}}</a>
|
|
ui/templates/column-delete-all.html
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<a href="#" title="{{title}}">{{title}}</a>
|
|
ui/templates/column-delete.html
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<a href="#" data-p2p_id="{{p2p_id}}" title="{{title}}">{{title}}</a>
|
|