Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
Added own class to loop through apps
Browse files Browse the repository at this point in the history
Added App-Support for aliases, domains and own CSS (Documentation coming soon)
  • Loading branch information
kolaente committed Sep 28, 2016
1 parent 419bce0 commit b6a4ecb
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 94 deletions.
2 changes: 2 additions & 0 deletions apps/Files/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
$_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'];
6 changes: 3 additions & 3 deletions apps/SimplePages/backend/dashboard.php
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
2 changes: 1 addition & 1 deletion apps/SimplePages/lang/lang.de.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$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
Expand Down
2 changes: 1 addition & 1 deletion apps/SimplePages/lang/lang.en.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$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';
Expand Down
9 changes: 9 additions & 0 deletions apps/testing/config.php
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions apps/testing/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
$page->setResponseCode(200);
$page->setContent('Hallo Welr');
$page->setTitle('tset');
2 changes: 1 addition & 1 deletion content/template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{$menu}
<div class="seite">
{$sidebar}
{$inhalt}
{$content}
{$test}
{$test2}
</div>
Expand Down
52 changes: 52 additions & 0 deletions inc/apps.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 4 additions & 0 deletions inc/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
$lang->setLangFolder( $path.'lang/');
}

//init Apps
require_once $path.'../../inc/apps.php';
$apps = new apps();

//Require appsConfig
require_once $path.'config.php';

Expand Down
4 changes: 4 additions & 0 deletions inc/autoload_adm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
//$lang = new lang();
$lang->setLangFolder('lang/');

//init Apps
require_once '../inc/apps.php';
$apps = new apps();

require_once '../inc/libs/functions.php';
107 changes: 52 additions & 55 deletions inc/libs/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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())
Expand Down Expand Up @@ -295,62 +345,9 @@ class="fa fa-group"></i>
</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
Expand Down Expand Up @@ -528,7 +525,7 @@ function hasPerm($permkey, $scope = '')

if ($scope == 'System') $scopeUri .= '../admin/';

//echo $moduluri;
//echo $appuri;

if (file_exists($scopeUri . 'permissions.json'))
{
Expand Down
7 changes: 7 additions & 0 deletions inc/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class page extends Smarty
private $title;
private $tplAssign = [];
private $templateFile;
private $domain;

//url fkt
public function setUrl($url)
Expand Down Expand Up @@ -115,4 +116,10 @@ function page_key($key)

echo preg_replace_callback('/{[A-Za-z0-9_:,\-\|]+}/', 'page_key', $tplFile);
}

public function getDomain()
{
$this->domain = $_SERVER['HTTP_HOST'];
return $this->domain;
}
}
Loading

0 comments on commit b6a4ecb

Please sign in to comment.