Skip to content

Instantly share code, notes, and snippets.

@kopepasah
Last active December 20, 2015 06:29
Show Gist options
  • Save kopepasah/6085956 to your computer and use it in GitHub Desktop.
Save kopepasah/6085956 to your computer and use it in GitHub Desktop.
<?php
header('Content-Type: text/plain');
// $file = $argv[1];
$file = '';
$hook_pattern = "|" . preg_quote( '<?php do_action(', '/') . "(.*?);|";
$api_pattern = "|" . preg_quote( '<?php it_exchange(' ) . "(.*?);|";
$contents = file_get_contents( dirname( __FILE__ ) . '/' . $file );
$lines = file( dirname( __FILE__ ) . '/' . $file );
foreach ( $lines as $number => $line ) {
if ( $number > 1 && $number < 5 ) {
if ( preg_match( '|@since|', $line ) )
break;
echo str_replace( "\n", ' ', str_replace( ' * ', '', $line ) );
}
}
echo "\n\n==Theme Location==\n";
echo 'theme/exchange/' . $file;
echo "\n\n==Action Hooks==\n";
if ( preg_match_all( $hook_pattern, $contents, $matches ) ) {
$actions = str_replace( ' ', '', str_replace( '<?php do_action( \'', '', str_replace( '\' );', '', $matches[0] ) ) );
foreach ( $actions as $action )
echo '*[[Exchange_Theme_Hooks:_' . $action .'|' . $action .']]' . "\n";
} else {
echo "Currently no hooks for this file.\n";
}
echo "\n==Theme API==\n";
if ( preg_match_all( $api_pattern, $contents, $matches ) ) {
$actions = str_replace( ' ', '', str_replace( '<?php ', '', str_replace( ');', ')', $matches[0] ) ) );
foreach ( $actions as $action ) {
echo '*[[Exchange_Theme_API:_' . preg_replace( "/.*'(.*)'.*'(.*)'.*/", "$1", $action ) . '/' . preg_replace( "/.*'(.*)'.*'(.*)'.*/", "$2", $action ) . '|' . $action . ']]' . "\n";
}
} else {
echo "Currently no api calls for this file.\n";
}
echo "\n==Default Code==\n";
echo '<pre class="brush:php">' . $contents . '</pre>';
echo "\n\n[[Exchange_Theme_Templates|&larr; Back to Exchange Theme Templates Page]]";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment