Navigation Menu

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

Commit

Permalink
Merge changes from the 1.7 branche
Browse files Browse the repository at this point in the history
Update copyright notice and version
  • Loading branch information
JustCarmen committed Sep 26, 2018
1 parent 9b2e451 commit e415964
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 227 deletions.
247 changes: 123 additions & 124 deletions app/JustBlackThemeOptionsClass.php
@@ -1,8 +1,7 @@
<?php <?php
/* /*
* webtrees: online genealogy * webtrees: online genealogy
* Copyright (C) 2017 webtrees development team * Copyright (C) 2018 JustCarmen (http://justcarmen.nl)
* Copyright (C) 2017 JustCarmen
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
Expand All @@ -14,108 +13,108 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace JustCarmen\WebtreesAddOns\JustBlack; namespace JustCarmen\WebtreesAddOns\JustBlack;


use Fisharebest\Webtrees\Filter; use Fisharebest\Webtrees\Filter;
use Fisharebest\Webtrees\FlashMessages; use Fisharebest\Webtrees\FlashMessages;
use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Log; use Fisharebest\Webtrees\Log;
use Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\Module;
use Fisharebest\Webtrees\Query\QueryMedia; use Fisharebest\Webtrees\Query\QueryMedia;
use Fisharebest\Webtrees\Tree; use Fisharebest\Webtrees\Tree;


/** /**
* Class JustBlack Theme Options * Class JustBlack Theme Options
*/ */
class JustBlackThemeOptionsClass extends JustBlackThemeOptionsModule { class JustBlackThemeOptionsClass extends JustBlackThemeOptionsModule {


// Get module options // Get module options
public function options($key) { public function options($key) {
if ($key === 'css') { if ($key === 'css') {
return $this->directory . '/css/style.css'; return $this->directory . '/css/style.css';
} elseif ($key === 'mediafolders') { } elseif ($key === 'mediafolders') {
return $this->listMediaFolders(); return $this->listMediaFolders();
} else { } else {
$JB_OPTIONS = unserialize($this->getPreference('JB_OPTIONS')); $JB_OPTIONS = unserialize($this->getPreference('JB_OPTIONS'));
$key = strtoupper($key); $key = strtoupper($key);
if (empty($JB_OPTIONS) || (is_array($JB_OPTIONS) && !array_key_exists($key, $JB_OPTIONS))) { if (empty($JB_OPTIONS) || (is_array($JB_OPTIONS) && !array_key_exists($key, $JB_OPTIONS))) {
return $key === 'MENU' ? $this->getDefaultMenu() : $this->setDefault($key); return $key === 'MENU' ? $this->getDefaultMenu() : $this->setDefault($key);
} else { } else {
return $key === 'MENU' ? $this->menuJustBlack($JB_OPTIONS['MENU']) : $JB_OPTIONS[$key]; 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 = Filter::postArray('NEW_JB_OPTIONS');
$NEW_JB_OPTIONS['MENU'] = $this->sortArray(Filter::postArray('NEW_JB_MENU'), 'sort'); $NEW_JB_OPTIONS['MENU'] = $this->sortArray(Filter::postArray('NEW_JB_MENU'), 'sort');
$NEW_JB_OPTIONS['IMAGE'] = Filter::post('JB_IMAGE'); $NEW_JB_OPTIONS['IMAGE'] = Filter::post('JB_IMAGE');
$error = false; $error = false;
if ($NEW_JB_OPTIONS['HEADER'] == 1) { if ($NEW_JB_OPTIONS['HEADER'] == 1) {
$image = $_FILES['NEW_JB_IMAGE']; $image = $_FILES['NEW_JB_IMAGE'];
$filename = 'jb_' . $image['name']; $filename = 'jb_' . $image['name'];
$serverFileName = WT_DATA_DIR . $filename; $serverFileName = WT_DATA_DIR . $filename;


if (!empty($image['name'])) { if (!empty($image['name'])) {
if ($this->upload($image, $serverFileName)) { if ($this->upload($image, $serverFileName)) {
$NEW_JB_OPTIONS['IMAGE'] = $filename; $NEW_JB_OPTIONS['IMAGE'] = $filename;
} else { } else {
FlashMessages::addMessage(I18N::translate('Error: The image you have uploaded is not a valid image! Your settings are not saved.'), 'warning'); 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'); $file = WT_DATA_DIR . $this->options('image');
if ($this->options('image') && file_exists($file)) { if ($this->options('image') && file_exists($file)) {
$image = getimagesize($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)); $this->setPreference('JB_OPTIONS', serialize($NEW_JB_OPTIONS));
FlashMessages::addMessage(I18N::translate('Your settings are successfully saved.'), 'success'); 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 = []; $modules = [];
foreach (Tree::getAll() as $tree) { foreach (Tree::getAll() as $tree) {
$modules = array_merge(Module::getActiveMenus($tree), $modules); $modules = array_merge(Module::getActiveMenus($tree), $modules);
} }


// add newly activated modules to the menu // add newly activated modules to the menu
$sort = count($menulist) + 1; $sort = count($menulist) + 1;
foreach ($modules as $label => $module) { foreach ($modules as $label => $module) {
if (!array_key_exists($label, $menulist)) { if (!array_key_exists($label, $menulist)) {
$menulist[$label] = [ $menulist[$label] = [
'title' => $module->getTitle(), 'title' => $module->getTitle(),
'label' => $label, 'label' => $label,
'sort' => $sort++, 'sort' => $sort++,
'function' => 'menuModule' 'function' => 'menuModule'
]; ];
} }
} }
// delete deactivated modules from the menu // delete deactivated modules from the menu
foreach ($menulist as $label => $menu) { foreach ($menulist as $label => $menu) {
if ($menu['function'] === 'menuModule' && !array_key_exists($label, $modules)) { if ($menu['function'] === 'menuModule' && !array_key_exists($label, $modules)) {
unset($menulist[$label]); unset($menulist[$label]);
} }
} }
return $menulist; return $menulist;
} }


protected function listMenuJustBlack($menulist) { protected function listMenuJustBlack($menulist) {
$html = ''; $html = '';
foreach ($menulist as $label => $menu) { foreach ($menulist as $label => $menu) {
$html .= '<li class="list-group-item' . $this->getStatus($label) . '">'; $html .= '<li class="list-group-item' . $this->getStatus($label) . '">';
foreach ($menu as $key => $val) { foreach ($menu as $key => $val) {
$html .= '<input type="hidden" name="NEW_JB_MENU[' . $label . '][' . $key . ']" value="' . $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;
} }


/** /**
Expand All @@ -126,22 +125,22 @@ protected function listMenuJustBlack($menulist) {
* @param type $label * @param type $label
* @return boolean * * @return boolean *
*/ */
public function isMenu($label) { public function isMenu($label) {
global $WT_TREE; global $WT_TREE;
$module = Module::getModuleByName($label); $module = Module::getModuleByName($label);
if (in_array($module, Module::getActiveMenus($WT_TREE))) { if (in_array($module, Module::getActiveMenus($WT_TREE))) {
if ($module->getMenu()) { if ($module->getMenu()) {
return true; return true;
} else { } else {
return false; return false;
} }
} else { } else {
return true; return true;
} }
} }


// Set default module options // Set default module options
private function setDefault($key) { private function setDefault($key) {
$JB_DEFAULT = [ $JB_DEFAULT = [
'TREETITLE' => '1', 'TREETITLE' => '1',
'TITLEPOS' => [ 'TITLEPOS' => [
Expand All @@ -160,10 +159,10 @@ private function setDefault($key) {
'SHOW_SUBFOLDERS' => '1', 'SHOW_SUBFOLDERS' => '1',
'SQUARE_THUMBS' => '1' 'SQUARE_THUMBS' => '1'
]; ];
return $JB_DEFAULT[$key]; return $JB_DEFAULT[$key];
} }


private function getDefaultMenu() { private function getDefaultMenu() {
$menulist = [ $menulist = [
'compact' => [ 'compact' => [
'title' => I18N::translate('View'), 'title' => I18N::translate('View'),
Expand Down Expand Up @@ -214,97 +213,97 @@ private function getDefaultMenu() {
'function' => 'menuSearch' 'function' => 'menuSearch'
], ],
]; ];
return $this->menuJustBlack($menulist); return $this->menuJustBlack($menulist);
} }


private function listMediaFolders() { private function listMediaFolders() {
global $WT_TREE; global $WT_TREE;


$MEDIA_DIRECTORY = $WT_TREE->getPreference('MEDIA_DIRECTORY'); $MEDIA_DIRECTORY = $WT_TREE->getPreference('MEDIA_DIRECTORY');
$folders = QueryMedia::folderList(); $folders = QueryMedia::folderList();
array_shift($folders); array_shift($folders);
$folderlist[$MEDIA_DIRECTORY] = strtoupper(I18N::translate(substr($MEDIA_DIRECTORY, 0, -1))); $folderlist[$MEDIA_DIRECTORY] = strtoupper(I18N::translate(substr($MEDIA_DIRECTORY, 0, -1)));


foreach ($folders as $key => $value) { foreach ($folders as $key => $value) {
if (count(glob(WT_DATA_DIR . $MEDIA_DIRECTORY . $value . '*')) > 0) { if (count(glob(WT_DATA_DIR . $MEDIA_DIRECTORY . $value . '*')) > 0) {
$folder = array_filter(explode("/", $value)); $folder = array_filter(explode("/", $value));
// only list first level folders // only list first level folders
if (count($folder) > 0 && !array_search($folder[0], $folderlist)) { if (count($folder) > 0 && !array_search($folder[0], $folderlist)) {
$folderlist[$folder[0] . '/'] = I18N::translate($folder[0]); $folderlist[$folder[0] . '/'] = I18N::translate($folder[0]);
} }
} }
} }
return $folderlist; return $folderlist;
} }


// Sort the array according to the $key['SORT'] input. // Sort the array according to the $key['SORT'] input.
private function sortArray($array, $sort_by) { private function sortArray($array, $sort_by) {
foreach ($array as $pos => $val) { foreach ($array as $pos => $val) {
$tmp_array[$pos] = $val[$sort_by]; $tmp_array[$pos] = $val[$sort_by];
} }
asort($tmp_array); asort($tmp_array);


$return_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]['title'] = $array[$pos]['title'];
$return_array[$pos]['label'] = $array[$pos]['label']; $return_array[$pos]['label'] = $array[$pos]['label'];
$return_array[$pos]['sort'] = $array[$pos]['sort']; $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 // set an extra class for some menuitems
private function getStatus($label) { private function getStatus($label) {
if ($label == 'homepage') { if ($label == 'homepage') {
$status = ' disabled'; $status = ' disabled';
} elseif ($label == 'charts' || $label == 'lists' || $label == 'calendar') { } elseif ($label == 'charts' || $label == 'lists' || $label == 'calendar') {
$status = ' menu-extended'; $status = ' menu-extended';
} elseif ($label == 'reports') { } elseif ($label == 'reports') {
$status = ' menu-extended menu-reports'; $status = ' menu-extended menu-reports';
} elseif ($label == 'compact') { } elseif ($label == 'compact') {
$status = ' menu-compact'; $status = ' menu-compact';
} elseif ($label == 'media') { } elseif ($label == 'media') {
$status = ' menu-media'; $status = ' menu-media';
} else { } else {
$status = ''; $status = '';
} }
return $status; return $status;
} }


private function upload($image, $serverFileName) { private function upload($image, $serverFileName) {
// Check if we are dealing with a valid image // Check if we are dealing with a valid image
if (!empty($image['name']) && preg_match('/^image\/(png|gif|jpeg)/', $image['type'])) { if (!empty($image['name']) && preg_match('/^image\/(png|gif|jpeg)/', $image['type'])) {
if (Filter::postBool('resize') == true) { if (Filter::postBool('resize') == true) {
$this->resize($image['tmp_name'], $image['type'], '800', '150'); $this->resize($image['tmp_name'], $image['type'], '800', '150');
} }


if ($this->options('image')) { if ($this->options('image')) {
$this->deleteImage(); // delete the old image from the server. $this->deleteImage(); // delete the old image from the server.
} }


move_uploaded_file($image['tmp_name'], $serverFileName); move_uploaded_file($image['tmp_name'], $serverFileName);
return true; return true;
} else { } else {
return false; return false;
} }
} }


private function resize($imgSrc, $type, $thumbwidth, $thumbheight) { private function resize($imgSrc, $type, $thumbwidth, $thumbheight) {
//getting the image dimensions //getting the image dimensions
list($width_orig, $height_orig) = getimagesize($imgSrc); list($width_orig, $height_orig) = getimagesize($imgSrc);
$ratio_orig = $width_orig / $height_orig; $ratio_orig = $width_orig / $height_orig;


if (($width_orig > $height_orig && $width_orig < $thumbwidth) || ($height_orig > $width_orig && $height_orig < $thumbheight)) { if (($width_orig > $height_orig && $width_orig < $thumbwidth) || ($height_orig > $width_orig && $height_orig < $thumbheight)) {
return false; return false;
} }


if ($thumbwidth / $thumbheight > $ratio_orig) { if ($thumbwidth / $thumbheight > $ratio_orig) {
$new_height = $thumbwidth / $ratio_orig; $new_height = $thumbwidth / $ratio_orig;
$new_width = $thumbwidth; $new_width = $thumbwidth;
} else { } else {
$new_width = $thumbheight * $ratio_orig; $new_width = $thumbheight * $ratio_orig;
$new_height = $thumbheight; $new_height = $thumbheight;
} }


$y_mid = $new_height / 2; $y_mid = $new_height / 2;
Expand Down Expand Up @@ -339,13 +338,13 @@ private function resize($imgSrc, $type, $thumbwidth, $thumbheight) {
imagedestroy($image); imagedestroy($image);


return imagepng($thumb, $imgSrc, 0); return imagepng($thumb, $imgSrc, 0);
} }
} }


protected function deleteImage() { protected function deleteImage() {
$filename = $this->options('image'); $filename = $this->options('image');
if ($filename && file_exists(WT_DATA_DIR . $filename)) { if ($filename && file_exists(WT_DATA_DIR . $filename)) {
unlink(WT_DATA_DIR . $filename); unlink(WT_DATA_DIR . $filename);
} }
} }
} }

0 comments on commit e415964

Please sign in to comment.