Skip to content

Commit

Permalink
Merge branch 'master' into ClassNames
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannon authored Nov 15, 2023
2 parents 3456100 + 58790b5 commit 5b67de1
Show file tree
Hide file tree
Showing 60 changed files with 3,045 additions and 2,618 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ docs/WebCalendar-UserManual.html
includes/settings.php
java
Makefile
sqlite-data
release-files
tests
TODO
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub/
__pycache__
*.save
*.sha
sqlite-data
tests/.phpunit.result.cache
vendor/
wc-icons/
wc-icons/
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ $(PHPMAILER_DIR)/SMTP.php: $(PHPMAILER_VENDOR_DIR)/SMTP.php
_ICONS: \
$(BOOTSTRAP_ICON_DIR)/printer.svg \
$(BOOTSTRAP_ICON_DIR)/search.svg \
$(BOOTSTRAP_ICON_DIR)/arrow-left.svg \
$(BOOTSTRAP_ICON_DIR)/arrow-right-circle.svg \
$(BOOTSTRAP_ICON_DIR)/arrow-left-circle.svg \
$(BOOTSTRAP_ICON_DIR)/arrow-up-short.svg \
Expand All @@ -61,7 +62,8 @@ _ICONS: \
$(BOOTSTRAP_ICON_DIR)/check-circle.svg \
$(BOOTSTRAP_ICON_DIR)/trash.svg \
$(BOOTSTRAP_ICON_DIR)/key-fill.svg \
$(BOOTSTRAP_ICON_DIR)/info-circle-fill.svg
$(BOOTSTRAP_ICON_DIR)/info-circle-fill.svg \
$(BOOTSTRAP_ICON_DIR)/circle.svg

$(BOOTSTRAP_ICON_DIR)/printer.svg: $(BOOTSTRAP_ICON_VENDOR_DIR)/printer.svg
cp $< $@
Expand All @@ -72,6 +74,9 @@ $(BOOTSTRAP_ICON_DIR)/search.svg: $(BOOTSTRAP_ICON_VENDOR_DIR)/search.svg
$(BOOTSTRAP_ICON_DIR)/arrow-right-circle.svg: $(BOOTSTRAP_ICON_VENDOR_DIR)/arrow-right-circle.svg
cp $< $@

$(BOOTSTRAP_ICON_DIR)/arrow-left.svg: $(BOOTSTRAP_ICON_VENDOR_DIR)/arrow-left.svg
cp $< $@

$(BOOTSTRAP_ICON_DIR)/arrow-left-circle.svg: $(BOOTSTRAP_ICON_VENDOR_DIR)/arrow-left-circle.svg
cp $< $@

Expand Down Expand Up @@ -114,6 +119,9 @@ $(BOOTSTRAP_ICON_DIR)/key-fill.svg: $(BOOTSTRAP_ICON_VENDOR_DIR)/key-fill.svg
$(BOOTSTRAP_ICON_DIR)/info-circle-fill.svg: $(BOOTSTRAP_ICON_VENDOR_DIR)/info-circle-fill.svg
cp $< $@

$(BOOTSTRAP_ICON_DIR)/circle.svg: $(BOOTSTRAP_ICON_VENDOR_DIR)/circle.svg
cp $< $@

includes/load_assets.php: \
pub/bootstrap.min.css \
pub/bootstrap.min.css.sha \
Expand Down
2 changes: 1 addition & 1 deletion UPGRADING.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h1>WebCalendar Upgrading Notes</h1>
<table>
<tr>
<th>WebCalendar Version:</th>
<td>1.9.10</td>
<td>1.9.12</td>
</tr>
</table>
<p><span class="note">Important News:</span> A major improvement beginning with Version 1.1 is the addition of an automated installation script. This script will guide you through the installation process and help identify any problem areas that might prevent successful installation or operation of WebCalendar.
Expand Down
4 changes: 1 addition & 3 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,7 @@ function save_pref ( $prefs, $src ) {
. print_radio ( 'CATEGORIES_ENABLED' ) . '</div>
<div class="form-inline mt-1 mb-2"><label title="' . tooltip ( 'icon_upload-enabled-help' ) . '">'
. translate ( 'Category Icon Upload enabled' ) . ':</label>'
. print_radio ( 'ENABLE_ICON_UPLOADS' ) . '' . ( ! is_dir ( 'wc-icons/' )
? str_replace ( 'XXX', 'wc-icons',
translate ( '(Requires XXX folder to exist.)' ) ) : '' ) . '</div>
. print_radio ( 'ENABLE_ICON_UPLOADS' ) . '</div>
<!-- DISPLAY TASK PREFERENCES -->
<div class="form-inline mt-1 mb-2"><label title="' . tooltip ( 'display-tasks-help' ) . '">'
Expand Down
48 changes: 9 additions & 39 deletions category.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,30 @@
exit;
}

// Verify that permissions allow writing to the "wc-icons" directory.
$canWrite = false;
$permError = false;
if ($ENABLE_ICON_UPLOADS == 'Y' || $is_admin) {
$testFile = "wc-icons/testWrite.txt";
$testFd = @fopen($testFile, "w+b", false);
if ($testFd !== false) {
fclose($testFd);
}
$canWrite = file_exists($testFile);
if (!$canWrite) {
$permError = true;
} else {
@unlink($testFile);
}
}

$catIcon = $catname = $error = $idStr = '';
$catIconStr = translate('Category Icon');
$globalStr = translate('Global');
$icon_path = 'wc-icons/';
// If editing, make sure they are editing their own (or they are an admin user).
if (!empty($id)) {
if (empty($categories[$id]))
$error =
str_replace('XXX', $id, translate('Invalid entry id XXX.'));

$catcolor = $categories[$id]['cat_color'];
$catname = $categories[$id]['cat_name'];
$catowner = $categories[$id]['cat_owner'];
$catIcon = $icon_path . 'cat-' . $id . '.gif';
// Try PNG if GIF not found
if (!file_exists($catIcon))
$catIcon = $icon_path . 'cat-' . $id . '.png';
$catmime = $categories[$id]['cat_icon_mime'];
$catIcon = empty($catmime) ? '' : 'getIcon.php?cat_id=' . $id;
$idStr = '<input name="id" type="hidden" value="' . $id . '">';
} else
$catcolor = '#000000';

$showIconStyle = (!empty($catIcon) && file_exists($catIcon)
? '' : 'display: none;');
$showIconStyle = (!empty($catmime) ? '' : 'display: none;');

print_header(['js/visible.php']);
echo '
<h2>' . translate('Categories') . '</h2>
' . display_admin_link(false);

// Display permission error if found above.
if ($permError && $is_admin) {
print_error_box(
translate('The permissions for the icons directory are set to read-only')
);
}

$add = getGetValue('add');
if (empty($add))
$add = 0;
Expand Down Expand Up @@ -95,8 +66,7 @@
<input type="checkbox" name="delIcon" value="Y"></div>
<div class="form-inline">
<label class="col-sm-3 col-form-label" for="FileName">'
. (is_dir($icon_path) &&
(($ENABLE_ICON_UPLOADS == 'Y' || $is_admin) && $canWrite)
. (($ENABLE_ICON_UPLOADS == 'Y' || $is_admin)
? translate('Add Icon to Category') . ':</label>
<input class="form-control" type="file" name="FileName" id="fileupload" size="45" '
. 'maxlength="50" value="">
Expand Down Expand Up @@ -132,9 +102,6 @@
foreach ($categories as $K => $V) {
if ($K < 1)
continue;
$catIcon = $icon_path . 'cat-' . $K . '.gif';
if (!file_exists($catIcon))
$catIcon = $icon_path . 'cat-' . $K . '.png';
$catStr = '<span style="color: '
. (!empty($V['cat_color']) ? $V['cat_color'] : '#000000')
. ';">' . htmlentities($V['cat_name']) . '</span>';
Expand All @@ -147,8 +114,11 @@
$global_found = true;
}

echo (file_exists($catIcon) ? '<img src="' . $catIcon . '" alt="'
. $catIconStr . '" title="' . $catIconStr . '">' : '') . '</li>';
if (!empty($V['cat_icon_mime'])) {
echo '<img src="getIcon.php?cat_id=' . $K . '" alt="'
. $catIconStr . '" title="' . $catIconStr . '">';
}
echo '</li>';
}
echo '
</ul>';
Expand Down
85 changes: 37 additions & 48 deletions category_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
$icon_max_size = '6000';
$icon_path = 'wc-icons/';

/**
* Rename any icons associated with this cat_id.
*/
function renameIcon($id)
{
global $icon_path;
$bakIcon = $catIcon = $icon_path . 'cat-';
$bakIcon .= date('YmdHis') . '.gif';
$catIcon .= $id . '.gif';
if (!file_exists($catIcon))
$catIcon = $icon_path . '/cat-' . $id . '.png';
if (file_exists($catIcon))
rename($catIcon, $bakIcon);

function updateIconBlob($catId, $iconData, $iconMimeType) {
// Update the icon binary data in the database.
dbi_update_blob(
'webcal_categories',
'cat_icon_blob',
"cat_id = $catId",
$iconData
);

// Update the MIME type of the icon in the database.
dbi_execute(
'UPDATE webcal_categories SET cat_icon_mime = ? WHERE cat_id = ?',
[$iconMimeType, $catId]
);
}

// Does the category belong to the user?
Expand Down Expand Up @@ -74,8 +76,6 @@ function renameIcon($id)
)) {
$error = db_error();
}
// Rename any icons associated with this cat_id.
renameIcon($id);
} else if (empty($error) && empty($catname)) {
$error = translate('Category name is required');
} else if (empty($error)) {
Expand All @@ -87,9 +87,6 @@ function renameIcon($id)
[$catname, $catcolor, $id]
))
$error = db_error();

if (!empty($delIcon) && $delIcon == 'Y')
renameIcon($id);
} else {
// Add new category.
// Get new id.
Expand All @@ -109,42 +106,34 @@ function renameIcon($id)
} else
$error = db_error();
}
if (empty($delIcon) && is_dir($icon_path) && (!empty($ENABLE_ICON_UPLOADS) && $ENABLE_ICON_UPLOADS == 'Y' ||
$is_admin)) {
if (empty($delIcon) && (!empty($ENABLE_ICON_UPLOADS) && $ENABLE_ICON_UPLOADS == 'Y' || $is_admin)) {
// Save icon if uploaded.
if (!empty($file['tmp_name'])) {
if (($file['type'] == 'image/gif' || $file['type'] == 'image/png')
&& $file['size'] <= $icon_max_size
) {
// $icon_props = getimagesize( $file['tmp_name'] );
// print_r ($icon_props );
$path_parts = pathinfo($_SERVER['SCRIPT_FILENAME']);
$fullIcon = $path_parts['dirname'] . '/'
. $icon_path . 'cat-' . $id;
if ($file['type'] == 'image/gif')
$fullIcon .= '.gif';
else
$fullIcon .= '.png';
renameIcon($id);
$file_result = move_uploaded_file($file['tmp_name'], $fullIcon);
// echo "Upload Result:" . $file_result;
} else if ($file['size'] > $icon_max_size) {
$error = translate('File size exceeds maximum.');
} else if (
$file['type'] != 'image/gif' &&
$file['type'] != 'image/png'
) {
$error = translate('File is not a GIF or PNG image') . ': '
. $file['type'];
}
if (($file['type'] == 'image/gif' || $file['type'] == 'image/png')
&& $file['size'] <= $icon_max_size) {
// Get binary data of the icon.
$iconData = file_get_contents($file['tmp_name']);
// Update the icon data and MIME type in the database.
updateIconBlob($id, $iconData, $file['type']);
} else if ($file['size'] > $icon_max_size) {
$error = translate('File size exceeds maximum.');
} else if (
$file['type'] != 'image/gif' &&
$file['type'] != 'image/png'
) {
$error = translate('File is not a GIF or PNG image') . ': '
. $file['type'];
}
}
// Copy icon if local file specified.
$urlname = getPostvalue('urlname');
if (!empty($urlname) && file_exists($icon_path . $urlname)) {
if (preg_match('/.(gif|GIF)$/', $urlname))
copy($icon_path . $urlname, $icon_path . 'cat-' . $id . '.gif');
else
copy($icon_path . $urlname, $icon_path . 'cat-' . $id . '.png');
// Get binary data of the icon.
$iconData = file_get_contents($icon_path . $urlname);
// Determine the MIME type based on the file extension.
$iconMimeType = (preg_match('/.(gif|GIF)$/', $urlname)) ? 'image/gif' : 'image/png';
// Update the icon data and MIME type in the database.
updateIconBlob($id, $iconData, $iconMimeType);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "k5n/webcalendar",
"type": "project",
"description": "Multi-user web-based calendar app",
"version": "1.9.10",
"version": "1.9.12",
"homepage": "https://www.k5n.us/webcalendar/",
"authors": [
{
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions getIcon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
require_once 'includes/init.php';

$cat_id = isset($_GET['cat_id']) ? intval($_GET['cat_id']) : 0;

// Query to get the icon blob data from the database
$query = "SELECT cat_icon_blob, cat_icon_mime FROM webcal_categories WHERE cat_id = ?";
$res = dbi_execute($query, [$cat_id]);

if ($res) {
$row = dbi_fetch_row($res);
if ($row && !empty($row[0])) {
// Output the MIME type header
header("Content-Type: " . $row[1]);
// Output the image
echo $row[0];
} else {
// Handle error, e.g., display default image
}
dbi_free_result($res);
} else {
// Handle error, e.g., display default image
}
3 changes: 3 additions & 0 deletions images/bootstrap-icons/arrow-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/bootstrap-icons/circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5b67de1

Please sign in to comment.