Permalink
Browse files

Merge changes from the 1.7 branche

Update copyright notice and version
  • Loading branch information...
JustCarmen committed Sep 26, 2018
1 parent 9b2e451 commit e41596464cbec59c5857f6fb697e4a3c01a42d38
Showing with 220 additions and 227 deletions.
  1. +123 −124 app/JustBlackThemeOptionsClass.php
  2. +13 −14 app/Schema/Migration0.php
  3. +16 −17 app/Schema/Migration1.php
  4. +13 −14 app/Schema/Migration2.php
  5. +24 −25 app/Template/AdminTemplate.php
  6. +1 −2 css/admin.css
  7. +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,108 +13,108 @@
* 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\JustBlack;
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\JustBlack;
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 JustBlack Theme Options
*/
class JustBlackThemeOptionsClass extends JustBlackThemeOptionsModule {
// Get module options
public function options($key) {
if ($key === 'css') {
return $this->directory . '/css/style.css';
} elseif ($key === 'mediafolders') {
return $this->listMediaFolders();
} else {
public function options($key) {
if ($key === 'css') {
return $this->directory . '/css/style.css';
} elseif ($key === 'mediafolders') {
return $this->listMediaFolders();
} else {
$JB_OPTIONS = unserialize($this->getPreference('JB_OPTIONS'));
$key = strtoupper($key);
if (empty($JB_OPTIONS) || (is_array($JB_OPTIONS) && !array_key_exists($key, $JB_OPTIONS))) {
return $key === 'MENU' ? $this->getDefaultMenu() : $this->setDefault($key);
} else {
return $key === 'MENU' ? $this->menuJustBlack($JB_OPTIONS['MENU']) : $JB_OPTIONS[$key];
}
}
if (empty($JB_OPTIONS) || (is_array($JB_OPTIONS) && !array_key_exists($key, $JB_OPTIONS))) {
return $key === 'MENU' ? $this->getDefaultMenu() : $this->setDefault($key);
} else {
return $key === 'MENU' ? $this->menuJustBlack($JB_OPTIONS['MENU']) : $JB_OPTIONS[$key];
}
}
}
protected function saveOptions() {
protected function saveOptions() {
$NEW_JB_OPTIONS = Filter::postArray('NEW_JB_OPTIONS');
$NEW_JB_OPTIONS['MENU'] = $this->sortArray(Filter::postArray('NEW_JB_MENU'), 'sort');
$NEW_JB_OPTIONS['IMAGE'] = Filter::post('JB_IMAGE');
$error = false;
if ($NEW_JB_OPTIONS['HEADER'] == 1) {
if ($NEW_JB_OPTIONS['HEADER'] == 1) {
$image = $_FILES['NEW_JB_IMAGE'];
$filename = 'jb_' . $image['name'];
$serverFileName = WT_DATA_DIR . $filename;
if (!empty($image['name'])) {
if ($this->upload($image, $serverFileName)) {
$NEW_JB_OPTIONS['IMAGE'] = $filename;
} else {
if (!empty($image['name'])) {
if ($this->upload($image, $serverFileName)) {
$NEW_JB_OPTIONS['IMAGE'] = $filename;
} else {
FlashMessages::addMessage(I18N::translate('Error: The image you have uploaded is not a valid image! Your settings are not saved.'), 'warning');
$error = true;
}
$error = true;
}
}
if (Filter::postBool('resize') == true) {
if (Filter::postBool('resize') == true) {
$file = WT_DATA_DIR . $this->options('image');
if ($this->options('image') && file_exists($file)) {
if ($this->options('image') && file_exists($file)) {
$image = getimagesize($file);
$this->resize($file, $image['mime'], '800', '150');
}
}
$this->resize($file, $image['mime'], '800', '150');
}
}
}
if (!$error) {
if (!$error) {
$this->setPreference('JB_OPTIONS', serialize($NEW_JB_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 menuJustBlack($menulist) {
protected function menuJustBlack($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 listMenuJustBlack($menulist) {
protected function listMenuJustBlack($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_JB_MENU[' . $label . '][' . $key . ']" value="' . $val . '"/>';
foreach ($menu as $key => $val) {
$html .= '<input type="hidden" name="NEW_JB_MENU[' . $label . '][' . $key . ']" value="' . $val . '"/>';
}
$html .= $menu['title'] . '</li>';
$html .= $menu['title'] . '</li>';
}
return $html;
return $html;
}
/**
@@ -126,22 +125,22 @@ protected function listMenuJustBlack($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) {
$JB_DEFAULT = [
'TREETITLE' => '1',
'TITLEPOS' => [
@@ -160,10 +159,10 @@ private function setDefault($key) {
'SHOW_SUBFOLDERS' => '1',
'SQUARE_THUMBS' => '1'
];
return $JB_DEFAULT[$key];
return $JB_DEFAULT[$key];
}
private function getDefaultMenu() {
private function getDefaultMenu() {
$menulist = [
'compact' => [
'title' => I18N::translate('View'),
@@ -214,97 +213,97 @@ private function getDefaultMenu() {
'function' => 'menuSearch'
],
];
return $this->menuJustBlack($menulist);
return $this->menuJustBlack($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 (Filter::postBool('resize') == true) {
$this->resize($image['tmp_name'], $image['type'], '800', '150');
if (!empty($image['name']) && preg_match('/^image\/(png|gif|jpeg)/', $image['type'])) {
if (Filter::postBool('resize') == true) {
$this->resize($image['tmp_name'], $image['type'], '800', '150');
}
if ($this->options('image')) {
$this->deleteImage(); // delete the old image from the server.
if ($this->options('image')) {
$this->deleteImage(); // delete the old image from the server.
}
move_uploaded_file($image['tmp_name'], $serverFileName);
return true;
} else {
return false;
}
return true;
} else {
return false;
}
}
private function resize($imgSrc, $type, $thumbwidth, $thumbheight) {
private function resize($imgSrc, $type, $thumbwidth, $thumbheight) {
//getting the image dimensions
list($width_orig, $height_orig) = getimagesize($imgSrc);
$ratio_orig = $width_orig / $height_orig;
if (($width_orig > $height_orig && $width_orig < $thumbwidth) || ($height_orig > $width_orig && $height_orig < $thumbheight)) {
return false;
if (($width_orig > $height_orig && $width_orig < $thumbwidth) || ($height_orig > $width_orig && $height_orig < $thumbheight)) {
return false;
}
if ($thumbwidth / $thumbheight > $ratio_orig) {
if ($thumbwidth / $thumbheight > $ratio_orig) {
$new_height = $thumbwidth / $ratio_orig;
$new_width = $thumbwidth;
} else {
$new_width = $thumbwidth;
} else {
$new_width = $thumbheight * $ratio_orig;
$new_height = $thumbheight;
$new_height = $thumbheight;
}
$y_mid = $new_height / 2;
@@ -339,13 +338,13 @@ private function resize($imgSrc, $type, $thumbwidth, $thumbheight) {
imagedestroy($image);
return imagepng($thumb, $imgSrc, 0);
}
}
}
protected function deleteImage() {
protected function deleteImage() {
$filename = $this->options('image');
if ($filename && file_exists(WT_DATA_DIR . $filename)) {
unlink(WT_DATA_DIR . $filename);
}
}
}
if ($filename && file_exists(WT_DATA_DIR . $filename)) {
unlink(WT_DATA_DIR . $filename);
}
}
}
Oops, something went wrong.

0 comments on commit e415964

Please sign in to comment.