Permalink
Browse files

Added James's changes.

  • Loading branch information...
mattwkelly committed Jun 1, 2012
2 parents 21e5e67 + e0cbdb4 commit 0935723f77f1f445081bc87e981150b1e8325974
Showing with 836 additions and 1 deletion.
  1. +2 −1 .gitignore
  2. +6 −0 .gitignore.orig
  3. +94 −0 social-plugins/pom/pom.php
  4. +734 −0 social-plugins/pom/src/plugins.json
View
@@ -1,2 +1,3 @@
.DS_Store
-fb_for_wp.kpf
+fb_for_wp.kpf
+social-plugins/pom/build/
View
@@ -0,0 +1,6 @@
+.DS_Store
+<<<<<<< HEAD
+fb_for_wp.kpf
+=======
+social-plugins/pom/build/
+>>>>>>> jpearce/master
View
@@ -0,0 +1,94 @@
+<?php
+
+ define(TWEAK, true);
+ define(CLEAN, true);
+ define(INPUT_FILE, 'src/plugins.json');
+ define(OUTPUT_DIR, 'build');
+
+ array_shift($argv); //pom.php
+ if (!($input_file = array_shift($argv))) {
+ $input_file = INPUT_FILE;
+ }
+ if (!($output_dir = array_shift($argv)) || !is_dir($output_dir)) {
+ $output_dir = OUTPUT_DIR;
+ }
+
+ print "\nCompiling POM from $input_file to $output_dir\n\n";
+
+ try {
+ $input = json_decode(file_get_contents($input_file), true);
+ $plugins = $input['plugins'];
+ } catch (Exception $e) {
+ print "Could not read or parse $input_file as a JSON list of plugins";
+ exit();
+ }
+
+ if (TWEAK) {
+ tweak($plugins);
+ }
+
+ if (CLEAN) {
+ @rmdir($output_dir);
+ }
+ @mkdir($output_dir);
+
+ foreach(compilePhp($plugins) as $filename=>$php) {
+ $filename = $output_dir . DIRECTORY_SEPARATOR . $filename;
+ file_put_contents($filename, $php);
+ include_once($filename);
+ print "Wrote & tested $filename\n";
+ }
+
+ exit();
+
+ // -----------
+
+ function tweak($plugins) {
+ foreach($plugins as $index=>$plugin) {
+ $params = $plugin['params'];
+ foreach($params as $param=>$config) {
+ foreach($config as $field=>$value) {
+ switch ($field) {
+ case 'description':
+ if (substr($value, -1) != '.') {
+ $plugins[$index] .= ".";
+ }
+ break;
+ default:
+ break;
+ }
+ $config[$field] = $value;
+ }
+ $params[$param] = $config;
+ }
+ $plugins[$index] = $plugin;
+ }
+ }
+
+ function compilePhp($plugins) {
+ $compiled = array(
+ 'base.php' =>
+ array(
+ 'class FBP_Base {',
+ '}'
+ )
+ );
+ foreach($plugins as $index=>$plugin) {
+ $filename = str_replace(' ', '', strtolower($plugin['name'])) . '.php';
+ $php = array("// Autogenerated at " . gmdate('Y-m-d H:i:s') . " GMT");
+
+ $class = str_replace(' ', '_', ucwords($plugin['name']));
+ $php[] = "include_once('base.php');";
+ $php[] = "class FBP_$class extends FBP_Base {";
+ $php[] = "}";
+ $compiled[$filename] = $php;
+ }
+ foreach($compiled as $filename=>$php) {
+ array_unshift($php, '<?php');
+ array_push($php, '?>');
+ $compiled[$filename] = implode("\n", $php);
+ }
+ return $compiled;
+ }
+
+?>
Oops, something went wrong.

0 comments on commit 0935723

Please sign in to comment.