Permalink
Browse files

Merge changes from the 1.7 branche

Update copyright notice and version
  • Loading branch information...
JustCarmen committed Sep 27, 2018
1 parent 456b751 commit b12c09c8fae0459c8e8d090bb05813117d86bd33
Showing with 189 additions and 195 deletions.
  1. +105 −106 app/JustLightThemeOptionsClass.php
  2. +16 −17 app/Schema/Migration0.php
  3. +13 −14 app/Schema/Migration1.php
  4. +24 −25 app/Template/AdminTemplate.php
  5. +1 −2 css/admin.css
  6. +30 −31 module.php
@@ -1,8 +1,7 @@
<?php
/*
* webtrees: online genealogy
* Copyright (C) 2017 webtrees development team
* Copyright (C) 2017 JustCarmen
* Copyright (C) 2018 JustCarmen (http://justcarmen.nl)
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -14,37 +13,37 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace JustCarmen\WebtreesAddOns\JustLight;
use Fisharebest\Webtrees\Filter;
use Fisharebest\Webtrees\FlashMessages;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Log;
use Fisharebest\Webtrees\Module;
use Fisharebest\Webtrees\Query\QueryMedia;
use Fisharebest\Webtrees\Tree;
namespace JustCarmen\WebtreesAddOns\JustLight;
use Fisharebest\Webtrees\Filter;
use Fisharebest\Webtrees\FlashMessages;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Log;
use Fisharebest\Webtrees\Module;
use Fisharebest\Webtrees\Query\QueryMedia;
use Fisharebest\Webtrees\Tree;
/**
* Class JustLight Theme Options
*/
class JustLightThemeOptionsClass extends JustLightThemeOptionsModule {
// Get module options
public function options($key) {
if ($key === 'mediafolders') {
return $this->listMediaFolders();
} else {
public function options($key) {
if ($key === 'mediafolders') {
return $this->listMediaFolders();
} else {
$JL_OPTIONS = unserialize($this->getPreference('JL_OPTIONS'));
$key = strtoupper($key);
if (empty($JL_OPTIONS) || (is_array($JL_OPTIONS) && !array_key_exists($key, $JL_OPTIONS))) {
return $key === 'MENU' ? $this->getDefaultMenu() : $this->setDefault($key);
} else {
return $key === 'MENU' ? $this->menuJustLight($JL_OPTIONS['MENU']) : $JL_OPTIONS[$key];
}
}
if (empty($JL_OPTIONS) || (is_array($JL_OPTIONS) && !array_key_exists($key, $JL_OPTIONS))) {
return $key === 'MENU' ? $this->getDefaultMenu() : $this->setDefault($key);
} else {
return $key === 'MENU' ? $this->menuJustLight($JL_OPTIONS['MENU']) : $JL_OPTIONS[$key];
}
}
}
protected function saveOptions() {
protected function saveOptions() {
$NEW_JL_OPTIONS = Filter::postArray('NEW_JL_OPTIONS');
$NEW_JL_OPTIONS['MENU'] = $this->sortArray(Filter::postArray('NEW_JL_MENU'), 'sort');
$NEW_JL_OPTIONS['LOGO'] = Filter::post('JL_LOGO');
@@ -54,59 +53,59 @@ protected function saveOptions() {
$filename = 'jl_' . $image['name'];
$serverFileName = WT_DATA_DIR . $filename;
if (!empty($image['name'])) {
if ($this->upload($image, $serverFileName)) {
$NEW_JL_OPTIONS['LOGO'] = $filename;
} else {
if (!empty($image['name'])) {
if ($this->upload($image, $serverFileName)) {
$NEW_JL_OPTIONS['LOGO'] = $filename;
} else {
FlashMessages::addMessage(I18N::translate('Error: The logo you have uploaded is not a valid image! Your settings are not saved.'), 'warning');
$error = true;
}
$error = true;
}
}
if (!$error) {
if (!$error) {
$this->setPreference('JL_OPTIONS', serialize($NEW_JL_OPTIONS));
FlashMessages::addMessage(I18N::translate('Your settings are successfully saved.'), 'success');
Log::addConfigurationLog($this->getTitle() . ' config updated');
}
Log::addConfigurationLog($this->getTitle() . ' config updated');
}
}
protected function menuJustLight($menulist) {
protected function menuJustLight($menulist) {
$modules = [];
foreach (Tree::getAll() as $tree) {
$modules = array_merge(Module::getActiveMenus($tree), $modules);
foreach (Tree::getAll() as $tree) {
$modules = array_merge(Module::getActiveMenus($tree), $modules);
}
// add newly activated modules to the menu
$sort = count($menulist) + 1;
foreach ($modules as $label => $module) {
if (!array_key_exists($label, $menulist)) {
foreach ($modules as $label => $module) {
if (!array_key_exists($label, $menulist)) {
$menulist[$label] = [
'title' => $module->getTitle(),
'label' => $label,
'sort' => $sort++,
'function' => 'menuModule'
];
}
];
}
}
// delete deactivated modules from the menu
foreach ($menulist as $label => $menu) {
if ($menu['function'] === 'menuModule' && !array_key_exists($label, $modules)) {
unset($menulist[$label]);
}
foreach ($menulist as $label => $menu) {
if ($menu['function'] === 'menuModule' && !array_key_exists($label, $modules)) {
unset($menulist[$label]);
}
}
return $menulist;
return $menulist;
}
protected function listMenuJustLight($menulist) {
protected function listMenuJustLight($menulist) {
$html = '';
foreach ($menulist as $label => $menu) {
foreach ($menulist as $label => $menu) {
$html .= '<li class="list-group-item' . $this->getStatus($label) . '">';
foreach ($menu as $key => $val) {
$html .= '<input type="hidden" name="NEW_JL_MENU[' . $label . '][' . $key . ']" value="' . $val . '"/>';
foreach ($menu as $key => $val) {
$html .= '<input type="hidden" name="NEW_JL_MENU[' . $label . '][' . $key . ']" value="' . $val . '"/>';
}
$html .= $menu['title'] . '</li>';
$html .= $menu['title'] . '</li>';
}
return $html;
return $html;
}
/**
@@ -117,22 +116,22 @@ protected function listMenuJustLight($menulist) {
* @param type $label
* @return boolean *
*/
public function isMenu($label) {
public function isMenu($label) {
global $WT_TREE;
$module = Module::getModuleByName($label);
if (in_array($module, Module::getActiveMenus($WT_TREE))) {
if ($module->getMenu()) {
return true;
} else {
return false;
}
} else {
return true;
}
if (in_array($module, Module::getActiveMenus($WT_TREE))) {
if ($module->getMenu()) {
return true;
} else {
return false;
}
} else {
return true;
}
}
// Set default module options
private function setDefault($key) {
private function setDefault($key) {
$JL_DEFAULT = [
'LOGO' => '',
'TITLESIZE' => '32',
@@ -142,10 +141,10 @@ private function setDefault($key) {
'MEDIA_LINK' => '',
'SHOW_SUBFOLDERS' => '1'
];
return $JL_DEFAULT[$key];
return $JL_DEFAULT[$key];
}
private function getDefaultMenu() {
private function getDefaultMenu() {
$menulist = [
'compact' => [
'title' => I18N::translate('View'),
@@ -196,82 +195,82 @@ private function getDefaultMenu() {
'function' => 'menuSearch'
],
];
return $this->menuJustLight($menulist);
return $this->menuJustLight($menulist);
}
private function listMediaFolders() {
private function listMediaFolders() {
global $WT_TREE;
$MEDIA_DIRECTORY = $WT_TREE->getPreference('MEDIA_DIRECTORY');
$folders = QueryMedia::folderList();
array_shift($folders);
$folderlist[$MEDIA_DIRECTORY] = strtoupper(I18N::translate(substr($MEDIA_DIRECTORY, 0, -1)));
foreach ($folders as $key => $value) {
if (count(glob(WT_DATA_DIR . $MEDIA_DIRECTORY . $value . '*')) > 0) {
foreach ($folders as $key => $value) {
if (count(glob(WT_DATA_DIR . $MEDIA_DIRECTORY . $value . '*')) > 0) {
$folder = array_filter(explode("/", $value));
// only list first level folders
if (count($folder) > 0 && !array_search($folder[0], $folderlist)) {
$folderlist[$folder[0] . '/'] = I18N::translate($folder[0]);
}
}
if (count($folder) > 0 && !array_search($folder[0], $folderlist)) {
$folderlist[$folder[0] . '/'] = I18N::translate($folder[0]);
}
}
}
return $folderlist;
return $folderlist;
}
// Sort the array according to the $key['SORT'] input.
private function sortArray($array, $sort_by) {
foreach ($array as $pos => $val) {
$tmp_array[$pos] = $val[$sort_by];
private function sortArray($array, $sort_by) {
foreach ($array as $pos => $val) {
$tmp_array[$pos] = $val[$sort_by];
}
asort($tmp_array);
$return_array = [];
foreach ($tmp_array as $pos => $val) {
foreach ($tmp_array as $pos => $val) {
$return_array[$pos]['title'] = $array[$pos]['title'];
$return_array[$pos]['label'] = $array[$pos]['label'];
$return_array[$pos]['sort'] = $array[$pos]['sort'];
$return_array[$pos]['function'] = $array[$pos]['function'];
$return_array[$pos]['function'] = $array[$pos]['function'];
}
return $return_array;
return $return_array;
}
// set an extra class for some menuitems
private function getStatus($label) {
if ($label == 'homepage') {
$status = ' disabled';
} elseif ($label == 'charts' || $label == 'lists' || $label == 'calendar') {
$status = ' menu-extended';
} elseif ($label == 'reports') {
$status = ' menu-extended menu-reports';
} elseif ($label == 'compact') {
$status = ' menu-compact';
} elseif ($label == 'media') {
$status = ' menu-media';
} else {
$status = '';
private function getStatus($label) {
if ($label == 'homepage') {
$status = ' disabled';
} elseif ($label == 'charts' || $label == 'lists' || $label == 'calendar') {
$status = ' menu-extended';
} elseif ($label == 'reports') {
$status = ' menu-extended menu-reports';
} elseif ($label == 'compact') {
$status = ' menu-compact';
} elseif ($label == 'media') {
$status = ' menu-media';
} else {
$status = '';
}
return $status;
return $status;
}
private function upload($image, $serverFileName) {
private function upload($image, $serverFileName) {
// Check if we are dealing with a valid image
if (!empty($image['name']) && preg_match('/^image\/(png|gif|jpeg)/', $image['type'])) {
if ($this->options('logo')) {
$this->deleteLogo(); // delete the old logo from the server.
if (!empty($image['name']) && preg_match('/^image\/(png|gif|jpeg)/', $image['type'])) {
if ($this->options('logo')) {
$this->deleteLogo(); // delete the old logo from the server.
}
move_uploaded_file($image['tmp_name'], $serverFileName);
return true;
} else {
return false;
}
return true;
} else {
return false;
}
}
protected function deleteLogo() {
protected function deleteLogo() {
$filename = $this->options('logo');
if (file_exists(WT_DATA_DIR . $filename)) {
unlink(WT_DATA_DIR . $filename);
}
}
}
if (file_exists(WT_DATA_DIR . $filename)) {
unlink(WT_DATA_DIR . $filename);
}
}
}
@@ -1,8 +1,7 @@
<?php
/**
* webtrees: online genealogy
* Copyright (C) 2017 webtrees development team
* Copyright (C) 2017 JustCarmen
* Copyright (C) 2018 JustCarmen (http://justcarmen.nl)
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -14,18 +13,18 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace JustCarmen\WebtreesAddOns\JustLight\Schema;
use Fisharebest\Webtrees\Database;
use Fisharebest\Webtrees\Schema\MigrationInterface;
namespace JustCarmen\WebtreesAddOns\JustLight\Schema;
use Fisharebest\Webtrees\Database;
use Fisharebest\Webtrees\Schema\MigrationInterface;
/**
* Upgrade the database schema from version 0 to version 1.
*/
class Migration0 implements MigrationInterface {
/** {@inheritDoc} */
public function upgrade() {
public function upgrade() {
// add menu function for modulemenus
$module_options = 'JL_OPTIONS';
$jl_options = Database::prepare(
@@ -34,17 +33,17 @@ public function upgrade() {
$options = unserialize($jl_options);
if (!empty($options) && array_key_exists('MENU', $options)) {
if (!empty($options) && array_key_exists('MENU', $options)) {
$menulist = $options['MENU'];
foreach ($menulist as $label => $menu) {
if ($menu['function'] === 'menuModules') {
$options['MENU'][$label]['function'] = 'menuModule';
}
}
foreach ($menulist as $label => $menu) {
if ($menu['function'] === 'menuModules') {
$options['MENU'][$label]['function'] = 'menuModule';
}
}
}
Database::prepare(
"UPDATE `##module_setting` SET setting_value=? WHERE setting_name=?"
)->execute([serialize($options), $module_options]);
}
}
)->execute([serialize($options), $module_options]);
}
}
Oops, something went wrong.

0 comments on commit b12c09c

Please sign in to comment.