Added own class to loop through apps

Added App-Support for aliases, domains and own CSS (Documentation coming soon)
This commit is contained in:
kolaente 2016-09-28 17:49:00 +02:00
parent 419bce04d2
commit b6a4ecbe1e
13 changed files with 194 additions and 98 deletions

View File

@ -7,3 +7,5 @@ $_CONF['mod_desc'] = 'Ein Modul zum Anzeigen & Uploaden von Dateien';
$_CONF['menu_top'] = '<i class="fa fa-folder"></i> '.$GLOBALS['lang']->get('files_title');
$_CONF['menu'] = ['menu_top' => 'index.php'];
$_CONF['type'] = 'none';
$_CONF['css'] = ['css/files.css'];

View File

@ -1,11 +1,11 @@
<?php
if (hasPerm('view_dashboard'))
{
$lang->set('Seiten zum Freischalten', 'sp_pages_confirm', 'de');
$lang->set('Seiten zum Freischalten', 'sp_edit_pages_to_confirm', 'de');
$lang->set('Seiten, die Sie editieren d&uuml;rfen', 'sp_edit_pages_to_edit', 'de');
$lang->set('Seiten zum Freischalten', 'sp_pages_confirm', 'en');
$lang->set('Seiten, die Sie editieren d&uuml;rfen', 'sp_edit_pages_to_edit', 'en');
$lang->set('Pages pending confirmation', 'sp_edit_pages_to_confirm', 'en');
$lang->set('Pages you can edit', 'sp_edit_pages_to_edit', 'en');
//If pages are available for confirmation, show them
$config = parse_ini_file('../apps/SimplePages/backend/confirm.ini');

View File

@ -18,7 +18,7 @@ $lang['sp_manage_permissions'] = 'Berechtigungen verwalten';
$lang['sp_create_new'] = 'Neue Seite erstellen';
$lang['sp_confirm'] = 'Änderungen Freischalten';
$lang['sp_edit_pages_to_edit'] = 'Seiten, die Sie editieren d&uuml;rfen';
$lang['sp_edit_pages_to_edit'] = 'Pages you can edit';
$lang['sp_edit_pages_to_confirm'] = 'Seiten zum Freischalten';
//Manage Pages

View File

@ -19,7 +19,7 @@ $lang['sp_create_new'] = 'Create New Page';
$lang['sp_confirm'] = 'Confirm Changes';
$lang['sp_edit_pages_to_edit'] = 'Pages you can edit';
$lang['sp_edit_pages_to_confirm'] = 'Pages to confirm';
$lang['sp_edit_pages_to_confirm'] = 'Pages pending confirmation';
//Manage Pages
$lang['sp_page'] = 'Page';

9
apps/testing/config.php Normal file
View File

@ -0,0 +1,9 @@
<?php
$_CONF['mod_name'] = 'Appname';
$_CONF['mod_desc'] = 'Appbeschreibung';
//$_CONF['base_url'] = 'demoapp/';
$_CONF['base_file'] = 'test.php';
$_CONF['alias'] = ['test' => 'test.php', 'watr-andres' => 'test.php'];
$_CONF['domain'] = 'sub.mowie';

4
apps/testing/test.php Normal file
View File

@ -0,0 +1,4 @@
<?php
$page->setResponseCode(200);
$page->setContent('Hallo Welr');
$page->setTitle('tset');

View File

@ -13,7 +13,7 @@
{$menu}
<div class="seite">
{$sidebar}
{$inhalt}
{$content}
{$test}
{$test2}
</div>

52
inc/apps.php Normal file
View File

@ -0,0 +1,52 @@
<?php
/*
* Find all apps and put them in an array.
* Has it's own class because of performance reasons - you would need to include Smarty every time you want the apps
*/
class apps
{
private $apps;
public function __construct()
{
//Find the app directory
$appdir = 'apps/';
$rel = explode('/', str_replace($GLOBALS['MCONF']['home_uri'], '', $_SERVER['SCRIPT_NAME']));
$count = count($rel);
//if (strpos($_SERVER['REQUEST_URI'], '/apps/') !== false && $count !== 1) $count = $count - 1; $appdir = '';
$i = 1;
while ($i < $count)
{
$appdir = '../'.$appdir;
$i++;
}
//Loop through the apps
if ($handle = opendir($appdir))
{
while (false !== ($app = readdir($handle)))
{
if ($app != "." && $app != ".." && !is_file($appdir . $app))
{
$appUri = $appdir.$app;
if (file_exists($appUri.'/config.php'))
{
require $appUri.'/config.php';
$this->apps[$app] = $_CONF;
//print_r($_CONF);
$_CONF = [];
}
}
}
closedir($handle);
}
}
public function getApps()
{
return $this->apps;
}
}

View File

@ -26,6 +26,10 @@ if(file_exists($path.'lang/') && is_dir($path.'lang/'))
$lang->setLangFolder( $path.'lang/');
}
//init Apps
require_once $path.'../../inc/apps.php';
$apps = new apps();
//Require appsConfig
require_once $path.'config.php';

View File

@ -7,4 +7,8 @@ require_once '../inc/config.php';
//$lang = new lang();
$lang->setLangFolder('lang/');
//init Apps
require_once '../inc/apps.php';
$apps = new apps();
require_once '../inc/libs/functions.php';

View File

@ -207,6 +207,43 @@ function printHeader($title)
}
} else
{
//Get Apps, build app-menu (We're building the menu here and output it later because we want the name of the current app to use ist for App-CSS)
$appmenu = '';
$apps = $GLOBALS['apps']->getApps();
$appCurr = '';
foreach ($apps as $app => $appconf)
{
if (isset($appconf['menu_top']) && $appconf['menu_top'] !== '')
{
$now = '';
if (strpos($_SERVER['REQUEST_URI'], $app) !== false)
{
$now = ' class="active"';
$appCurr = $app;
}
if (array_key_exists('menu_top', $appconf['menu']))
{
$appmenu .= "\n" . '<li' . $now . ' id="mw-menu-apps-' . $app . '-top"><a href="' . $GLOBALS['MCONF']['home_uri'] . 'apps/' . $app . '/' . $appconf['menu']['menu_top'] . '">' . $appconf['menu_top'] . '</a>' . "\n";
} else
{
$first_itm = array_keys($appconf['menu']);
$appmenu .= "\n" . '<li' . $now . ' id="mw-menu-apps-' . $app . '-top"><a href="' . $GLOBALS['MCONF']['home_uri'] . 'apps/' . $app . '/' . $appconf['menu'][$first_itm[0]] . '">' . $appconf['menu_top'] . '<i class="fa fa-chevron-right sub_menu"></i></a>' . "\n" . '<ul>';
foreach ($appconf['menu'] as $app_name => $app_name_url)
{
$now = '';
if (strpos($_SERVER['REQUEST_URI'], $app_name_url) !== false && strpos($_SERVER['REQUEST_URI'], $app) !== false)
{
$now = ' class="active"';
}
$appmenu .= '<li' . $now . ' id="mw-menu-apps-' . $app . '-' . str_replace(['.php', '?', '&'], '', str_replace('/', '-', $app_name_url)) . '"><a href="' . $GLOBALS['MCONF']['home_uri'] . 'apps/' . $app . '/' . $app_name_url . '">' . $app_name . '</a></li>' . "\n";
}
$appmenu .= '</ul></li>' . "\n";
}
$appconf['menu_top'] = '';
}
}
//<link rel="stylesheet prefetch" href="' . $GLOBALS['MCONF']['web_uri'] . 'css/video-js.css" type="text/css"/>
echo '<!DOCTYPE html>
<html lang="de">
@ -224,6 +261,19 @@ function printHeader($title)
<script>
page.base(\'' . $GLOBALS['MCONF']['home_uri'] . '\');
</script>
';
//Get App-CSS and output it
if(isset($apps[$appCurr]['css']))
{
foreach ($apps[$appCurr]['css'] as $style)
{
echo ' <link rel="stylesheet" href="' . $GLOBALS['MCONF']['web_uri'] . 'apps/'.$appCurr.'/'.$style.'" type="text/css"/>';
}
}
echo '
</head>
<body>';
if (is_loggedin())
@ -295,62 +345,9 @@ function printHeader($title)
</li>
<?php
}
$moduluri = '../apps/';
$pos = strpos($_SERVER['REQUEST_URI'], '/apps/');
if ($pos !== false)
{
$moduluri = '../';
$rel = explode('/', str_replace($GLOBALS['MCONF']['home_uri'] . 'apps/', '', $_SERVER['REQUEST_URI']));
$count = count($rel);
$count = $count - 1;
$i = 1;
while ($i < $count)
{
$moduluri .= '../';
$i++;
}
}
echo $appmenu;
if ($handle = opendir($moduluri))
{
while (false !== ($mod = readdir($handle)))
{
if ($mod != "." && $mod != ".." && is_dir($moduluri . $mod))
{
require $moduluri . $mod . '/config.php';
if ($_CONF['menu_top'] !== '')
{
$now = '';
if (strpos($_SERVER['REQUEST_URI'], $mod) !== false)
{
$now = ' class="active"';
}
if (array_key_exists('menu_top', $_CONF['menu']))
{
echo "\n" . '<li' . $now . ' id="mw-menu-apps-' . $mod . '-top"><a href="' . $GLOBALS['MCONF']['home_uri'] . 'apps/' . $mod . '/' . $_CONF['menu']['menu_top'] . '">' . $_CONF['menu_top'] . '</a>' . "\n";
} else
{
$first_itm = array_keys($_CONF['menu']);
echo "\n" . '<li' . $now . ' id="mw-menu-apps-' . $mod . '-top"><a href="' . $GLOBALS['MCONF']['home_uri'] . 'apps/' . $mod . '/' . $_CONF['menu'][$first_itm[0]] . '">' . $_CONF['menu_top'] . '<i class="fa fa-chevron-right sub_menu"></i></a>' . "\n" . '<ul>';
foreach ($_CONF['menu'] as $mod_name_anz => $mod_name_url)
{
$now = '';
if (strpos($_SERVER['REQUEST_URI'], $mod_name_url) !== false && strpos($_SERVER['REQUEST_URI'], $mod) !== false)
{
$now = ' class="active"';
}
echo '<li' . $now . ' id="mw-menu-apps-' . $mod . '-' . str_replace(['.php', '?', '&'], '', str_replace('/', '-', $mod_name_url)) . '"><a href="' . $GLOBALS['MCONF']['home_uri'] . 'apps/' . $mod . '/' . $mod_name_url . '">' . $mod_name_anz . '</a></li>' . "\n";
}
echo '</ul></li>' . "\n";
}
$_CONF['menu_top'] = '';
}
}
}
closedir($handle);
}
echo '</ul>
<div class="copy"> © 2016 <a href="http://mowie.cc">Mowie</a></div><div class="langselect"><a id="langselectbtn"><i class="fa fa-globe"></i> </a><div class="langs">';
//Lang
@ -528,7 +525,7 @@ function hasPerm($permkey, $scope = '')
if ($scope == 'System') $scopeUri .= '../admin/';
//echo $moduluri;
//echo $appuri;
if (file_exists($scopeUri . 'permissions.json'))
{

View File

@ -9,6 +9,7 @@ class page extends Smarty
private $title;
private $tplAssign = [];
private $templateFile;
private $domain;
//url fkt
public function setUrl($url)
@ -115,4 +116,10 @@ class page extends Smarty
echo preg_replace_callback('/{[A-Za-z0-9_:,\-\|]+}/', 'page_key', $tplFile);
}
public function getDomain()
{
$this->domain = $_SERVER['HTTP_HOST'];
return $this->domain;
}
}

View File

@ -1,4 +1,5 @@
<?php
//Check if installed
if (file_exists('inc/config.yml'))
{
@ -6,7 +7,8 @@ if (file_exists('inc/config.yml'))
require_once 'inc/libs/Smarty/Smarty.class.php';
require_once 'inc/config.php';
require_once 'inc/libs/functions.php';
require_once 'inc/page.php';
require_once 'inc/page.php';
require_once 'inc/apps.php';
//Under Construction?
if (file_exists('inc/System/construction.txt'))
@ -30,47 +32,62 @@ if (file_exists('inc/config.yml'))
}
$page->setResponseCode(404);
$apps = new apps();
//Search apps and execute them if necessary
$appdir = 'apps/';
if ($handle = opendir($appdir))
foreach ($apps->getApps() as $app => $appconf)
{
while (false !== ($app = readdir($handle)))
$appUri = 'apps/'.$app.'/';
//If the App should run from one domain only
if((isset($appconf['domain']) && $page->getDomain() == $appconf['domain']) || !isset($appconf['domain']) || (isset($appconf['domain']) && $appconf['domain'] === ''))
{
if ($app != "." && $app != ".." && !is_file($appdir . $app))
//If we have an alias which equals the current url, execute it
if(isset($appconf['alias']))
{
if(array_key_exists($page->getUrl(), $appconf['alias']))
{
$appUri = $appdir.$app;
if (file_exists($appUri.'/config.php'))
{
require $appUri.'/config.php';
if(isset($_CONF['type']))//typ vorhanden?
{
if($_CONF['type'] == 'page')//Seite, die inhalte ausgibt
{
if(isset($_CONF['base_url_file']))
{
if($_CONF['base_url'] == $page->getUrl())
{
require $appUri.'/' . $_CONF['base_url_file'];
}
}
if(isset($_CONF['base_url']) && file_exists($appUri.'/' . $_CONF['base_file']))
{
if($_CONF['base_url'] == $page->getBaseUrl())
{
require $appUri.'/' . $_CONF['base_file'];
}
}
}
if($_CONF['type'] == 'static' && isset($_CONF['base_file']) && file_exists($appUri.'/'.$_CONF['base_file']))
{
require $appUri.'/'.$_CONF['base_file'];
}
}
$_CONF = [];
}
require $appUri. $appconf['alias'][$page->getUrl()];
}
}
closedir($handle);
//If we have a type
if(isset($appconf['type']))
{
//Page for (more or less) dynamic content
if($appconf['type'] == 'page')
{
//If we have a base_url_file and the current url equals base_url, execute base_url_file
if(isset($appconf['base_url_file']))
{
if($appconf['base_url'] == $page->getUrl())
{
require $appUri . $appconf['base_url_file'];
}
}
//if we have a base_url and a base_file which exists and the current baseUrl equals base_url, execute base_file
if(isset($appconf['base_url']) && file_exists($appUri.'/' . $appconf['base_file']))
{
if($appconf['base_url'] == $page->getBaseUrl())
{
require $appUri. $appconf['base_file'];
}
}
}
//Static
if($appconf['type'] == 'static' && isset($appconf['base_file']) && file_exists($appUri.'/'.$appconf['base_file']))
{
require $appUri.$appconf['base_file'];
}
}
//If the App should run from one domain only
/*if(isset($appconf['domain']) && $page->getDomain() == $appconf['domain'])
{
echo 'ff';*/
}
$appconf = [];
}
if($page->getResponseCode() == 404)
@ -89,7 +106,7 @@ if (file_exists('inc/config.yml'))
$page->assign('copyright', $copy);
// dat ganze ausgeben
http_response_code($page->getresponseCode());
http_response_code($page->getResponseCode());
$page->assign($MCONF['tpl_title'], $page->getTitle(). ' | ' . $MCONF['title']);
$page->assign($MCONF['tpl_content'], $page->getContent());
$page->assign($MCONF['tpl_webUri'], $MCONF['web_uri']);