Last active
December 20, 2015 06:29
-
-
Save kopepasah/6085956 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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|← Back to Exchange Theme Templates Page]]"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment