namespace Friendica\Core;
use Friendica\App;
+use Friendica\BaseObject;
use Friendica\Database\DBA;
-use Friendica\Database\DBM;
require_once 'include/dba.php';
/**
* Some functions to handle addons
*/
-class Addon
+class Addon extends BaseObject
{
+ /**
+ * @brief Synchronise addons:
+ *
+ * system.addon contains a comma-separated list of names
+ * of 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 addon that isn't installed,
+ * call the install procedure and add it to the database.
+ *
+ */
+ public static function check()
+ {
+ $a = self::getApp();
+
+ $r = DBA::select('addon', [], ['installed' => 1]);
+ if (DBA::isResult($r)) {
+ $installed = DBA::toArray($r);
+ } else {
+ $installed = [];
+ }
+
+ $addons = Config::get('system', 'addon');
+ $addons_arr = [];
+
+ if ($addons) {
+ $addons_arr = explode(',', str_replace(' ', '', $addons));
+ }
+
+ $a->addons = $addons_arr;
+
+ $installed_arr = [];
+
+ if (count($installed)) {
+ foreach ($installed as $i) {
+ if (!in_array($i['name'], $addons_arr)) {
+ self::uninstall($i['name']);
+ } else {
+ $installed_arr[] = $i['name'];
+ }
+ }
+ }
+
+ if (count($addons_arr)) {
+ foreach ($addons_arr as $p) {
+ if (!in_array($p, $installed_arr)) {
+ self::install($p);
+ }
+ }
+ }
+
+ self::loadHooks();
+
+ return;
+ }
+
/**
* @brief uninstalls an addon.
*
$addons = Config::get('system', 'addon');
if (strlen($addons)) {
$r = DBA::select('addon', [], ['installed' => 1]);
- if (DBM::is_result($r)) {
+ if (DBA::isResult($r)) {
$installed = DBA::toArray($r);
} else {
$installed = [];
*/
public static function registerHook($hook, $file, $function, $priority = 0)
{
+ $file = str_replace(self::getApp()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
+
$condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
$exists = DBA::exists('hook', $condition);
if ($exists) {
*/
public static function unregisterHook($hook, $file, $function)
{
+ $relative_file = str_replace(self::getApp()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
+
+ // This here is only needed for fixing a problem that existed on the develop branch
$condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
+ DBA::delete('hook', $condition);
+
+ $condition = ['hook' => $hook, 'file' => $relative_file, 'function' => $function];
$r = DBA::delete('hook', $condition);
return $r;
}
*/
public static function loadHooks()
{
- $a = get_app();
+ $a = self::getApp();
$a->hooks = [];
$r = DBA::select('hook', ['hook', 'file', 'function'], [], ['order' => ['priority' => 'desc', 'file']]);
*/
public static function forkHooks($priority, $name, $data = null)
{
- $a = get_app();
+ $a = self::getApp();
if (is_array($a->hooks) && array_key_exists($name, $a->hooks)) {
foreach ($a->hooks[$name] as $hook) {
*/
public static function callHooks($name, &$data = null)
{
- $a = get_app();
+ $a = self::getApp();
if (is_array($a->hooks) && array_key_exists($name, $a->hooks)) {
foreach ($a->hooks[$name] as $hook) {
*/
public static function isApp($name)
{
- $a = get_app();
+ $a = self::getApp();
if (is_array($a->hooks) && (array_key_exists('app_menu', $a->hooks))) {
foreach ($a->hooks['app_menu'] as $hook) {
*/
public static function getInfo($addon)
{
- $a = get_app();
+ $a = self::getApp();
$info = [
'name' => $addon,
$stamp1 = microtime(true);
$f = file_get_contents("addon/$addon/$addon.php");
- $a->save_timestamp($stamp1, "file");
+ $a->saveTimestamp($stamp1, "file");
$r = preg_match("|/\*.*\*/|msU", $f, $m);
foreach ($ll as $l) {
$l = trim($l, "\t\n\r */");
if ($l != "") {
- list($type, $v) = array_map("trim", explode(":", $l, 2));
+ $addon_info = array_map("trim", explode(":", $l, 2));
+ if (count($addon_info) < 2) {
+ continue;
+ }
+
+ list($type, $v) = $addon_info;
$type = strtolower($type);
if ($type == "author" || $type == "maintainer") {
$r = preg_match("|([^<]+)<([^>]+)>|", $v, $m);