Skip to content

Commit 0aaead9

Browse files
Included ApiGen files
1 parent 1791075 commit 0aaead9

38 files changed

+3421
-0
lines changed

apigen.neon

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
destination: build/apidocs
2+
templateConfig: apigen/theme-woocommerce/config.neon
3+
extensions: [php]
4+
source:
5+
- source/woocommerce/woocommerce.php
6+
- source/woocommerce/includes
7+
exclude:
8+
- source/woocommerce/includes/libraries/
9+
- source/woocommerce/includes/api/legacy/
10+
- source/woocommerce/api/legacy/
11+
- source/woocommerce/libraries/
12+
charset: [UTF-8]
13+
main: WC
14+
title: WooCommerce Code Reference
15+
baseUrl: https://docs.woocommerce.com/wc-apidocs/
16+
templateTheme: default
17+
php: false
18+
sourceCode: true
19+
tree: true
20+
deprecated: true
21+
todo: true
22+
download: false

apigen/hook-docs.php

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
<?php
2+
/**
3+
* Generate documentation for hooks in WC
4+
*/
5+
class WC_HookFinder {
6+
const SOURCE_PATH = '../source/woocommerce/';
7+
8+
private static $current_file = '';
9+
private static $files_to_scan = array();
10+
private static $pattern_custom_actions = '/do_action(.*?);/i';
11+
private static $pattern_custom_filters = '/apply_filters(.*?);/i';
12+
private static $found_files = array();
13+
private static $custom_hooks_found = '';
14+
15+
private static function get_files( $pattern, $flags = 0, $path = '' ) {
16+
17+
if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) {
18+
19+
if ( '\\' == $dir || '/' == $dir ) {
20+
$dir = '';
21+
}
22+
23+
return self::get_files( basename( $pattern ), $flags, $dir . '/' );
24+
25+
} // End IF Statement
26+
27+
$paths = glob( $path . '*', GLOB_ONLYDIR | GLOB_NOSORT );
28+
$files = glob( $path . $pattern, $flags );
29+
30+
if ( is_array( $paths ) ) {
31+
foreach ( $paths as $p ) {
32+
$found_files = array();
33+
$retrieved_files = (array) self::get_files( $pattern, $flags, $p . '/' );
34+
foreach ( $retrieved_files as $file ) {
35+
if ( ! in_array( $file, self::$found_files ) ) {
36+
$found_files[] = $file;
37+
}
38+
}
39+
40+
self::$found_files = array_merge( self::$found_files, $found_files );
41+
42+
if ( is_array( $files ) && is_array( $found_files ) ) {
43+
$files = array_merge( $files, $found_files );
44+
}
45+
} // End FOREACH Loop
46+
}
47+
return $files;
48+
}
49+
50+
private static function get_hook_link( $hook, $details = array() ) {
51+
if ( ! empty( $details['class'] ) ) {
52+
$link = 'http://docs.woocommerce.com/wc-apidocs/source-class-' . $details['class'] . '.html#' . $details['line'];
53+
} elseif ( ! empty( $details['function'] ) ) {
54+
$link = 'http://docs.woocommerce.com/wc-apidocs/source-function-' . $details['function'] . '.html#' . $details['line'];
55+
} else {
56+
$link = 'https://github.com/woocommerce/woocommerce/search?utf8=%E2%9C%93&q=' . $hook;
57+
}
58+
59+
return '<a href="' . $link . '">' . $hook . '</a>';
60+
}
61+
62+
public static function process_hooks() {
63+
self::$files_to_scan = array();
64+
65+
self::$files_to_scan['Template Files'] = self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'templates/' );
66+
self::$files_to_scan['Template Functions'] = array( self::SOURCE_PATH . 'includes/wc-template-functions.php', self::SOURCE_PATH . 'includes/wc-template-hooks.php' );
67+
self::$files_to_scan['Shortcodes'] = self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/shortcodes/' );
68+
self::$files_to_scan['Widgets'] = self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/widgets/' );
69+
self::$files_to_scan['Data Stores'] = self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/data-stores' );
70+
self::$files_to_scan['Core Classes'] = array_merge(
71+
self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/' ),
72+
self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/abstracts/' ),
73+
self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/customizer/' ),
74+
self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/emails/' ),
75+
self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/export/' ),
76+
self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/gateways/' ),
77+
self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/import/' ),
78+
self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/shipping/' )
79+
);
80+
81+
self::$files_to_scan = array_filter( self::$files_to_scan );
82+
83+
$scanned = array();
84+
85+
ob_start();
86+
87+
$index = array();
88+
89+
foreach ( self::$files_to_scan as $heading => $files ) {
90+
$index[] = '<a href="#hooks-' . str_replace( ' ', '-', strtolower( $heading ) ) . '">' . $heading . '</a>';
91+
}
92+
93+
echo '<div id="content">';
94+
echo '<h1>Action and Filter Hook Reference</h1>';
95+
echo '<div class="description">
96+
<p>This is simply a list of action and filter hooks found within WooCommerce files. View the source to see supported params and usage.</p>
97+
<p>' . implode( ', ', $index ) . '</p>
98+
</div>';
99+
100+
foreach ( self::$files_to_scan as $heading => $files ) {
101+
self::$custom_hooks_found = array();
102+
103+
foreach ( $files as $f ) {
104+
self::$current_file = basename( $f );
105+
$tokens = token_get_all( file_get_contents( $f ) );
106+
$token_type = false;
107+
$current_class = '';
108+
$current_function = '';
109+
110+
if ( in_array( self::$current_file, $scanned ) ) {
111+
continue;
112+
}
113+
114+
$scanned[] = self::$current_file;
115+
116+
foreach ( $tokens as $index => $token ) {
117+
if ( is_array( $token ) ) {
118+
$trimmed_token_1 = trim( $token[1] );
119+
if ( T_CLASS == $token[0] ) {
120+
$token_type = 'class';
121+
} elseif ( T_FUNCTION == $token[0] ) {
122+
$token_type = 'function';
123+
} elseif ( 'do_action' === $token[1] ) {
124+
$token_type = 'action';
125+
} elseif ( 'apply_filters' === $token[1] ) {
126+
$token_type = 'filter';
127+
} elseif ( $token_type && ! empty( $trimmed_token_1 ) ) {
128+
switch ( $token_type ) {
129+
case 'class' :
130+
$current_class = $token[1];
131+
break;
132+
case 'function' :
133+
$current_function = $token[1];
134+
break;
135+
case 'filter' :
136+
case 'action' :
137+
$hook = trim( $token[1], "'" );
138+
$hook = str_replace( '_FUNCTION_', strtoupper( $current_function ), $hook );
139+
$hook = str_replace( '_CLASS_', strtoupper( $current_class ), $hook );
140+
$hook = str_replace( '$this', strtoupper( $current_class ), $hook );
141+
$hook = str_replace( array( '.', '{', '}', '"', "'", ' ', ')', '(' ), '', $hook );
142+
$loop = 0;
143+
144+
// Keep adding to hook until we find a comma or colon
145+
while ( 1 ) {
146+
$loop ++;
147+
$prev_hook = is_string( $tokens[ $index + $loop - 1 ] ) ? $tokens[ $index + $loop - 1 ] : $tokens[ $index + $loop - 1 ][1];
148+
$next_hook = is_string( $tokens[ $index + $loop ] ) ? $tokens[ $index + $loop ] : $tokens[ $index + $loop ][1];
149+
150+
if ( in_array( $next_hook, array( '.', '{', '}', '"', "'", ' ', ')', '(' ) ) ) {
151+
continue;
152+
}
153+
154+
if ( in_array( $next_hook, array( ',', ';' ) ) ) {
155+
break;
156+
}
157+
158+
$hook_first = substr( $next_hook, 0, 1 );
159+
$hook_last = substr( $next_hook, -1, 1 );
160+
161+
if ( '{' === $hook_first || '}' === $hook_last || '$' === $hook_first || ')' === $hook_last || '>' === substr( $prev_hook, -1, 1 ) ) {
162+
$next_hook = strtoupper( $next_hook );
163+
}
164+
165+
$next_hook = str_replace( array( '.', '{', '}', '"', "'", ' ', ')', '(' ), '', $next_hook );
166+
167+
$hook .= $next_hook;
168+
}
169+
170+
if ( isset( self::$custom_hooks_found[ $hook ] ) ) {
171+
self::$custom_hooks_found[ $hook ]['file'][] = self::$current_file;
172+
} else {
173+
self::$custom_hooks_found[ $hook ] = array(
174+
'line' => $token[2],
175+
'class' => $current_class,
176+
'function' => $current_function,
177+
'file' => array( self::$current_file ),
178+
'type' => $token_type,
179+
);
180+
}
181+
break;
182+
}
183+
$token_type = false;
184+
}
185+
}
186+
}
187+
}
188+
189+
foreach ( self::$custom_hooks_found as $hook => $details ) {
190+
if ( ! strstr( $hook, 'woocommerce' ) && ! strstr( $hook, 'product' ) && ! strstr( $hook, 'wc_' ) ) {
191+
//unset( self::$custom_hooks_found[ $hook ] );
192+
}
193+
}
194+
195+
ksort( self::$custom_hooks_found );
196+
197+
if ( ! empty( self::$custom_hooks_found ) ) {
198+
echo '<div class="panel panel-default"><div class="panel-heading"><h2 id="hooks-' . str_replace( ' ', '-', strtolower( $heading ) ) . '">' . $heading . '</h2></div>';
199+
200+
echo '<table class="summary table table-bordered table-striped"><thead><tr><th>Hook</th><th>Type</th><th>File(s)</th></tr></thead><tbody>';
201+
202+
foreach ( self::$custom_hooks_found as $hook => $details ) {
203+
echo '<tr>
204+
<td>' . self::get_hook_link( $hook, $details ) . '</td>
205+
<td>' . $details['type'] . '</td>
206+
<td>' . implode( ', ', array_unique( $details['file'] ) ) . '</td>
207+
</tr>' . "\n";
208+
}
209+
210+
echo '</tbody></table></div>';
211+
}
212+
}
213+
214+
echo '</div><div id="footer">';
215+
216+
$html = file_get_contents( '../build/apidocs/tree.html' );
217+
$header = explode( '<div id="content">', $html );
218+
$header = str_replace( '<li class="active">', '<li>', current( $header ) );
219+
$header = str_replace( '<li class="hooks">', '<li class="active">', $header );
220+
$header = str_replace( 'Tree | ', 'Hook Reference | ', $header );
221+
$footer = explode( '<div id="footer">', $html );
222+
223+
file_put_contents( '../build/apidocs/hook-docs.html', $header . ob_get_clean() . end( $footer ) );
224+
echo "Hook docs generated :)\n";
225+
}
226+
}
227+
228+
WC_HookFinder::process_hooks();

apigen/theme-woocommerce/404.latte

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{layout '@layout.latte'}
2+
{var $robots = false}
3+
4+
{block title}Page not found{/block}
5+
6+
{block content}
7+
<div id="content">
8+
<h1>{include title}</h1>
9+
<p>The requested page could not be found.</p>
10+
<p>You have probably clicked on a link that is outdated and points to a page that does not exist any more or you have made an typing error in the address.</p>
11+
<p>To continue please try to find requested page in the menu,{if $config->tree} take a look at <a href="tree.html">the tree view</a> of the whole project{/if} or use search field on the top.</p>
12+
</div>
13+
{/block}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{define elements}
2+
<tr n:foreach="$elements as $element">
3+
<td class="name"><a href="{$element|elementUrl}" n:class="$element->deprecated ? deprecated, !$element->valid ? invalid">{if $namespace}{$element->shortName}{else}{$element->name}{/if}</a></td>
4+
<td>{$element|shortDescription|noescape}</td>
5+
</tr>
6+
{/define}
7+
8+
{if $classes}
9+
<div class="panel panel-default">
10+
<div class="panel-heading"><h2>Classes summary</h2></div>
11+
<table class="summary table table-bordered table-striped" id="classes">
12+
{include elements, elements => $classes}
13+
</table>
14+
</div>
15+
{/if}
16+
17+
{if $interfaces}
18+
<div class="panel panel-default">
19+
<div class="panel-heading"><h2>Interfaces summary</h2></div>
20+
<table class="summary table table-bordered table-striped" id="interfaces">
21+
{include elements, elements => $interfaces}
22+
</table>
23+
</div>
24+
{/if}
25+
26+
{if $traits}
27+
<div class="panel panel-default">
28+
<div class="panel-heading"><h2>Traits summary</h2></div>
29+
<table class="summary table table-bordered table-striped" id="traits">
30+
{include elements, elements => $traits}
31+
</table>
32+
</div>
33+
{/if}
34+
35+
{if $exceptions}
36+
<div class="panel panel-default">
37+
<div class="panel-heading"><h2>Exceptions summary</h2></div>
38+
<table class="summary table table-bordered table-striped" id="exceptions">
39+
{include elements, elements => $exceptions}
40+
</table>
41+
</div>
42+
{/if}
43+
44+
{if $constants}
45+
<div class="panel panel-default">
46+
<div class="panel-heading"><h2>Constants summary</h2></div>
47+
<table class="summary table table-bordered table-striped" id="constants">
48+
{include elements, elements => $constants}
49+
</table>
50+
</div>
51+
{/if}
52+
53+
{if $functions}
54+
<div class="panel panel-default">
55+
<div class="panel-heading"><h2>Functions summary</h2></div>
56+
<table class="summary table table-bordered table-striped" id="functions">
57+
{include elements, elements => $functions}
58+
</table>
59+
</div>
60+
{/if}

0 commit comments

Comments
 (0)