Browse Source

functions to support module and widget registration by plugins. These have identical construction to core modules and widgets and are registered just like hooks during addon load. Also additional Apps functions addon_app_installed() and system_app_installed() which will eventually replace feature_installed() for features which are converted to apps. The convention being used is that the module associated with the app calls the appropriate *_app_installed() function and if not present emits descriptive text about the app and exits. This allows one to click on an 'available' app and learn about it. Once installed, the app module behaves normally and may offer functionality or what once were addon settings on the settings/featured page. Refer to zap-addons in the zap repository for examples of how this is being used to eliminate the 'additional features' and 'addon settings' pages.

disroot_master
zotlabs 2 years ago
parent
commit
d71e70bedf
5 changed files with 174 additions and 23 deletions
  1. +48
    -0
      Zotlabs/Extend/Route.php
  2. +47
    -0
      Zotlabs/Extend/Widget.php
  3. +30
    -6
      Zotlabs/Lib/Apps.php
  4. +24
    -10
      Zotlabs/Render/Comanche.php
  5. +25
    -7
      Zotlabs/Web/Router.php

+ 48
- 0
Zotlabs/Extend/Route.php View File

@@ -0,0 +1,48 @@
<?php

namespace Zotlabs\Extend;


class Route {

static function register($file,$modname) {
$rt = self::get();
$rt[] = [ $file, $modname ];
self::set($rt);
}

static function unregister($file,$modname) {
$rt = self::get();
if($rt) {
$n = [];
foreach($rt as $r) {
if($r[0] !== $file && $r[1] !== $modname) {
$n[] = $r;
}
}
self::set($n);
}
}

static function unregister_by_file($file) {
$rt = self::get();
if($rt) {
$n = [];
foreach($rt as $r) {
if($r[0] !== $file) {
$n[] = $r;
}
}
self::set($n);
}
}

static function get() {
return get_config('system','routes',[]);
}

static function set($r) {
return set_config('system','routes',$r);
}
}


+ 47
- 0
Zotlabs/Extend/Widget.php View File

@@ -0,0 +1,47 @@
<?php

namespace Zotlabs\Extend;


class Widget {

static function register($file,$widget) {
$rt = self::get();
$rt[] = [ $file, $widget ];
self::set($rt);
}

static function unregister($file,$widget) {
$rt = self::get();
if($rt) {
$n = [];
foreach($rt as $r) {
if($r[0] !== $file && $r[1] !== $widget) {
$n[] = $r;
}
}
self::set($n);
}
}

static function unregister_by_file($file) {
$rt = self::get();
if($rt) {
$n = [];
foreach($rt as $r) {
if($r[0] !== $file) {
$n[] = $r;
}
}
self::set($n);
}
}

static function get() {
return get_config('system','widgets',[]);
}

static function set($r) {
return set_config('system','widgets',$r);
}
}

+ 30
- 6
Zotlabs/Lib/Apps.php View File

@@ -534,13 +534,15 @@ class Apps {
intval(TERM_OBJ_APP),
intval($x[0]['id'])
);
$r = q("delete from app where app_id = '%s' and app_channel = %d",
dbesc($app['guid']),
intval($uid)
);
if ($uid) {
$r = q("delete from app where app_id = '%s' and app_channel = %d",
dbesc($app['guid']),
intval($uid)
);

// we don't sync system apps - they may be completely different on the other system
build_sync_packet($uid,array('app' => $x));
// we don't sync system apps - they may be completely different on the other system
build_sync_packet($uid,array('app' => $x));
}
}
else {
self::app_undestroy($uid,$app);
@@ -605,6 +607,28 @@ class Apps {
}


static public function addon_app_installed($uid,$app) {

$r = q("select id from app where app_plugin = '%s' and app_channel = %d limit 1",
dbesc($app),
intval($uid)
);
return(($r) ? true : false);

}

static public function system_app_installed($uid,$app) {

$r = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
dbesc(hash('whirlpool',$app)),
intval($uid)
);
return(($r) ? true : false);

}



static public function app_list($uid, $deleted = false, $cats = []) {
if($deleted)
$sql_extra = "";


+ 24
- 10
Zotlabs/Render/Comanche.php View File

@@ -528,18 +528,32 @@ class Comanche {
$clsname = ucfirst($name);
$nsname = "\\Zotlabs\\Widget\\" . $clsname;

if(file_exists('Zotlabs/SiteWidget/' . $clsname . '.php'))
require_once('Zotlabs/SiteWidget/' . $clsname . '.php');
elseif(file_exists('widget/' . $clsname . '/' . $clsname . '.php'))
require_once('widget/' . $clsname . '/' . $clsname . '.php');
elseif(file_exists('Zotlabs/Widget/' . $clsname . '.php'))
require_once('Zotlabs/Widget/' . $clsname . '.php');
else {
$pth = theme_include($clsname . '.php');
if($pth) {
require_once($pth);
$found = false;
$widgets = \Zotlabs\Extend\Widget::get();
if($widgets) {
foreach($widgets as $widget) {
if(is_array($widget) && strtolower($widget[1]) === strtolower($name) && file_exists($widget[0])) {
require_once($widget[0]);
$found = true;
}
}
}

if(! $found) {
if(file_exists('Zotlabs/SiteWidget/' . $clsname . '.php'))
require_once('Zotlabs/SiteWidget/' . $clsname . '.php');
elseif(file_exists('widget/' . $clsname . '/' . $clsname . '.php'))
require_once('widget/' . $clsname . '/' . $clsname . '.php');
elseif(file_exists('Zotlabs/Widget/' . $clsname . '.php'))
require_once('Zotlabs/Widget/' . $clsname . '.php');
else {
$pth = theme_include($clsname . '.php');
if($pth) {
require_once($pth);
}
}
}

if(class_exists($nsname)) {
$x = new $nsname;
$f = 'widget';


+ 25
- 7
Zotlabs/Web/Router.php View File

@@ -2,6 +2,7 @@

namespace Zotlabs\Web;

use Zotlabs\Extend\Route;
use Exception;

/**
@@ -52,14 +53,31 @@ class Router {
* First see if we have a plugin which is masquerading as a module.
*/

if(is_array(\App::$plugins) && in_array($module,\App::$plugins) && file_exists("addon/{$module}/{$module}.php")) {
include_once("addon/{$module}/{$module}.php");
if(class_exists($modname)) {
$this->controller = new $modname;
\App::$module_loaded = true;
$routes = Route::get();
if($routes) {
foreach($routes as $route) {
if(is_array($route) && strtolower($route[1]) === $module) {
include_once($route[0]);
if(class_exists($modname)) {
$this->controller = new $modname;
\App::$module_loaded = true;
}
}
}
elseif(function_exists($module . '_module')) {
\App::$module_loaded = true;
}

// legacy plugins - this can be removed when they have all been converted

if(! (\App::$module_loaded)) {
if(is_array(\App::$plugins) && in_array($module,\App::$plugins) && file_exists("addon/{$module}/{$module}.php")) {
include_once("addon/{$module}/{$module}.php");
if(class_exists($modname)) {
$this->controller = new $modname;
\App::$module_loaded = true;
}
elseif(function_exists($module . '_module')) {
\App::$module_loaded = true;
}
}
}



Loading…
Cancel
Save