+
+ /**
+ *
+ * Synchronise plugins:
+ *
+ * $a->config['system']['addon'] contains a comma-separated list of names
+ * of plugins/addons which are used on this system.
+ * Go through the database list of already installed addons, and if we have
+ * an entry, but it isn't in the config list, call the uninstall procedure
+ * and mark it uninstalled in the database (for now we'll remove it).
+ * Then go through the config list and if we have a plugin that isn't installed,
+ * call the install procedure and add it to the database.
+ *
+ */
+
+ $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
+ if(count($r))
+ $installed = $r;
+ else
+ $installed = array();
+
+ $plugins = get_config('system','addon');
+ $plugins_arr = array();
+
+ if($plugins)
+ $plugins_arr = explode(',',str_replace(' ', '',$plugins));
+
+ $installed_arr = array();
+
+ if(count($installed)) {
+ foreach($installed as $i) {
+ if(! in_array($i['name'],$plugins_arr)) {
+ logger("Addons: uninstalling " . $i['name']);
+ q("DELETE FROM `addon` WHERE `id` = %d LIMIT 1",
+ intval($i['id'])
+ );
+
+ @include_once('addon/' . $i['name'] . '/' . $i['name'] . '.php');
+ if(function_exists($i['name'] . '_uninstall')) {
+ $func = $i['name'] . '_uninstall';
+ $func();
+ }
+ }
+ else
+ $installed_arr[] = $i['name'];
+ }
+ }
+
+ if(count($plugins_arr)) {
+ foreach($plugins_arr as $p) {
+ if(! in_array($p,$installed_arr)) {
+ logger("Addons: installing " . $p);
+ @include_once('addon/' . $p . '/' . $p . '.php');
+ if(function_exists($p . '_install')) {
+ $func = $p . '_install';
+ $func();
+ $r = q("INSERT INTO `addon` (`name`, `installed`) VALUES ( '%s', 1 ) ",
+ dbesc($p)
+ );
+ }
+ }
+ }
+ }
+