implemented a plugin loader so i can add things like
authorpaulr <me@pjr.cc>
Fri, 4 Nov 2011 05:54:18 +0000 (16:54 +1100)
committerpaulr <me@pjr.cc>
Fri, 4 Nov 2011 05:54:18 +0000 (16:54 +1100)
http://www.phpcaptcha.org/ without having to carry their code in my
repo. hopefully should be quite simple

gwvplib/gwvplib.php
gwvplib/gwvppluginloader.php [new file with mode: 0644]
gwvplib/plugins/test_plugin.php [new file with mode: 0644]
www/index.php

index e0654bc..d24ec5c 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 
+
 require_once("gwvpweb.php");
 require_once("gwvpgitbackend.php");
 require_once("gwvpuseradmin.php");
@@ -8,6 +9,7 @@ require_once("gwvpauth.php");
 require_once("gwvpsetup.php");
 require_once("gwvpdatabase.php");
 require_once("gwvpconfig.php");
+require_once("gwvppluginloader.php");
 
 // only enable this if you need it:
 require_once("gwvpdebug.php");
diff --git a/gwvplib/gwvppluginloader.php b/gwvplib/gwvppluginloader.php
new file mode 100644 (file)
index 0000000..dcc7e0e
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+function gwvp_PluginLoader($path="")
+{
+       if($path !=  "") {
+               // try and find it
+               error_log("attempting to load plugins from $path");
+               $dh = opendir("$path");
+               if($dh) {
+                       while(($file = readdir($dh))!==false) {
+                               $mt = preg_match("/.*.php$/", $file);
+                               if($mt > 0) {
+                                       error_log("loading plugin $file");
+                                       require_once("$path/$file");
+                                       //echo "required $basedir/$file\n";
+                               }
+                       }
+               }                       
+       }
+}
+
+// we assume the config is loaded, but this is where it works:
+error_log("begin plugin load");
+if(isset($plugin_path)) {
+       error_log("path set");
+       if(is_dir($plugin_path)) {
+               error_log("is dir, beginning load");
+               gwvp_PluginLoader($plugin_path);
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/gwvplib/plugins/test_plugin.php b/gwvplib/plugins/test_plugin.php
new file mode 100644 (file)
index 0000000..8257f04
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+
+if(function_exists("gwvp_DebugEnabled")) {
+       error_log("hello, test plugin loaded");
+}
+
+?>
\ No newline at end of file
index 1bc6bc7..792b52a 100644 (file)
@@ -30,8 +30,10 @@ require_once("gwvplib.php");
 gwvp_goWebBegin();
 //goWebGitBackEnd();
 
+
 if(function_exists("gwvp_DebugEnabled")) {
        gwvp_DebugEnabled();
 }
 
+
 ?>