Skip to content

Commit

Permalink
PHP 8.X changes; Add script to bump version.
Browse files Browse the repository at this point in the history
  • Loading branch information
craigk5n committed Aug 15, 2023
1 parent 299b02d commit 3889507
Show file tree
Hide file tree
Showing 21 changed files with 248 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
context: .
file: ./docker/Dockerfile-php8
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/webcalendar:v1.9.1-dev-php8
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/webcalendar:v1.9.2-dev-php8
2 changes: 1 addition & 1 deletion UPGRADING.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h1>WebCalendar Upgrading Notes</h1>
<table>
<tr>
<th>WebCalendar Version:</th>
<td>1.9.0 </td>
<td>1.9.2</td>
</tr>
</table>

Expand Down
139 changes: 139 additions & 0 deletions bump_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash

# Function to bump version number
bump_version() {
local version="$1"
local major minor patch
IFS='.' read -ra ADDR <<< "${version#v}"
major=${ADDR[0]}
minor=${ADDR[1]}
patch=${ADDR[2]}
patch=$((patch + 1))
echo "v$major.$minor.$patch"
}

# Function to update version in install/default_config.php
update_default_config_version() {
local new_version="$1"
sed -i -E "s/('WEBCAL_PROGRAM_VERSION' => ')[^']*(')/\1$new_version\2/" install/default_config.php
}

update_sql_version() {
local file_path="$1"
local new_version="$2"

# Get the last line of the file
local last_line=$(tail -n 1 "$file_path")

# Check if the last line contains a version string.
if [[ $last_line == *upgrade* ]]; then
# If it does, replace the version in the last line.
sed -i "$ s/.*/\/\*upgrade_${new_version}\*\//g" "$file_path"
else
# If it doesn't, append a new line with the version.
echo "/*upgrade_${new_version}*/" >> "$file_path"
fi

echo "Updated $file_path to version $new_version"
}


# SQL files to update
declare -a sql_files=(
"install/sql/upgrade-db2.sql"
"install/sql/upgrade-ibase.sql"
"install/sql/upgrade-mssql.sql"
"install/sql/upgrade-mysql.sql"
"install/sql/upgrade-oracle.sql"
"install/sql/upgrade-postgres.sql"
"install/sql/upgrade.sql"
)

# Function to update version and date in includes/config.php
update_config_php() {
local file_path="includes/config.php"
local new_version="$1"
local new_date=$(date +"%d %b %Y")

# Update version
sed -i "/^ *\$PROGRAM_VERSION\s*=\s*/s/'[^']*'/'$new_version'/" "$file_path"

# Update date
sed -i "/^ *\$PROGRAM_DATE =\s*/s/'[^']*'/'$new_date'/" "$file_path"

echo "Updated $file_path to version $new_version and date $new_date"
}



# Function to update version in .github/workflows/docker.yml
update_docker_yml() {
local file_path=".github/workflows/docker.yml"
local new_version="$1"

# Get the line number containing the version tag
local line_num=$(grep -nE 'tags: \${{ secrets.DOCKER_HUB_USERNAME }}/webcalendar:[^ ]*-dev-php8' "$file_path" | cut -d: -f1)

# If we found the line, update the version on that line
if [[ -n "$line_num" ]]; then
sed -i "${line_num}s|webcalendar:[^ ]*-dev-php8|webcalendar:${new_version}-dev-php8|" "$file_path"
fi

echo "Updated $file_path to version $new_version"
}

# Function to update version in UPGRADING.html
update_upgrading_html() {
local file_path="UPGRADING.html"
local new_version="$1"
local version_without_v="${new_version#v}" # removes 'v' prefix for versions like v1.9.1

# Get the line number containing the version
local line_num=$(grep -nE '<th>WebCalendar Version:</th>' "$file_path" | cut -d: -f1)
# Add 1 to the line number to target the next line
((line_num++))

# If we found the line, update the version on that line
if [[ -n "$line_num" ]]; then
sed -i "${line_num}s|<td>[^<]*</td>|<td>$version_without_v</td>|" "$file_path"
fi

echo "Updated $file_path to version $new_version"
}

# Function to update version in composer.json
update_composer_json() {
local file_path="composer.json"
local new_version="$1"
local version_without_v="${new_version#v}" # removes 'v' prefix for versions like v1.9.1

# Use jq to update the version key in the JSON file
jq ".version = \"$version_without_v\"" "$file_path" > "$file_path.tmp" && mv "$file_path.tmp" "$file_path"

echo "Updated $file_path to version $new_version"
}

# Main logic
if [ "$#" -eq 0 ]; then
# No arguments provided, bump the version
current_version=$(grep 'WEBCAL_PROGRAM_VERSION' install/default_config.php | sed -E "s/.*'WEBCAL_PROGRAM_VERSION' => '([^']*)'.*/\1/")
new_version=$(bump_version "$current_version")
else
# Argument provided, use it as the new version
new_version="$1"
fi

#update_default_config_version "$new_version"

#for file in "${sql_files[@]}"; do
# update_sql_version "$file" "$new_version"
# echo "Updated $file to version $new_version"
#done

update_config_php "$new_version"
update_docker_yml "$new_version"
update_upgrading_html "$new_version"
#update_composer_json "$new_version"

echo "Updated to version $new_version"

44 changes: 22 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "k5n/webcalendar",
"type": "project",
"description": "Multi-user web-based calendar app",
"version": "v1.9.1",
"homepage": "https://www.k5n.us/webcalendar/",
"authors": [
{
"name": "Craig Knudsen",
"email": "craig@k5n.us",
"homepage": "https://www.k5n.us",
"role": "Project Maintainer / Developer"
}
],
"require": {
"phpmailer/phpmailer": "6.5.4",
"components/jquery": "3.5.*",
"ckeditor/ckeditor": "4.18.*",
"twbs/bootstrap": "4.6.2",
"twbs/bootstrap-icons": "1.8.3",
"phpunit/phpunit": "9.*"
},
"license": "GPL-2.0-only"
"name": "k5n/webcalendar",
"type": "project",
"description": "Multi-user web-based calendar app",
"version": "1.9.2",
"homepage": "https://www.k5n.us/webcalendar/",
"authors": [
{
"name": "Craig Knudsen",
"email": "craig@k5n.us",
"homepage": "https://www.k5n.us",
"role": "Project Maintainer / Developer"
}
],
"require": {
"phpmailer/phpmailer": "6.5.4",
"components/jquery": "3.5.*",
"ckeditor/ckeditor": "4.18.*",
"twbs/bootstrap": "4.6.2",
"twbs/bootstrap-icons": "1.8.3",
"phpunit/phpunit": "9.*"
},
"license": "GPL-2.0-only"
}
2 changes: 1 addition & 1 deletion edit_entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function time_selection($prefix, $time = '', $trigger = false)
access_user_calendar('edit', $create_by, $login, $type, $access);

$day = $cal_date % 100;
$month = ($cal_date / 100) % 100;
$month = intval($cal_date / 100) % 100;
$year = intval($cal_date / 10000);

$time = $row[2];
Expand Down
8 changes: 4 additions & 4 deletions edit_entry_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function sort_byday( $a, $b ) {
$cat_id = getValue ( 'cat_id', '-?[0-9,\-]*', true );
$completed_hour = getPostValue( 'completed_hour' );
$completed_minute = getPostValue( 'completed_minute' );
$ymd = getPostValue('completed_YMD');
$ymd = getPostValue('completed_YMD', '');
$parsed = date_parse($ymd);
$completed_day = $parsed['day'];
$completed_month = $parsed['month'];
Expand All @@ -97,7 +97,7 @@ function sort_byday( $a, $b ) {
$due_ampm = getPostValue( 'due_ampm' );
$due_hour = getPostValue( 'due_hour' );
$due_minute = getPostValue( 'due_minute' );
$ymd = getPostValue('due__YMD');
$ymd = getPostValue('due__YMD', '');
$parsed = date_parse($ymd);
$due_day = $parsed['day'];
$due_month = $parsed['month'];
Expand Down Expand Up @@ -131,7 +131,7 @@ function sort_byday( $a, $b ) {
$reminder_hour = getPostValue( 'reminder_hour' );
$reminder_minute = getPostValue( 'reminder_minute' );
$reminder_type = getPostValue( 'reminder_type' );
$ymd = getPostValue('reminder__YMD');
$ymd = getPostValue('reminder__YMD', '');
$parsed = date_parse($ymd);
$reminder_day = $parsed['day'];
$reminder_month = $parsed['month'];
Expand All @@ -145,7 +145,7 @@ function sort_byday( $a, $b ) {
$rpt_minute = getPostValue( 'rpt_minute' );
$rpt_type = getPostValue( 'rpt_type' );
$rptmode = getPostValue( 'rptmode' );
$ymd = getPostValue('rpt__YMD');
$ymd = getPostValue('rpt__YMD', '');
$parsed = date_parse($ymd);
$rpt_day = $parsed['day'];
$rpt_month = $parsed['month'];
Expand Down
4 changes: 2 additions & 2 deletions includes/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ function do_config()
];

// When changing PROGRAM VERSION, also change it in install/default_config.php
$PROGRAM_VERSION = 'v1.9.1';
$PROGRAM_VERSION = 'v1.9.2';
// Update PROGRAM_DATE with official release data
$PROGRAM_DATE = '(08 Mar 2022)';
$PROGRAM_DATE = '15 Aug 2023';

$PROGRAM_NAME = 'WebCalendar ' . "$PROGRAM_VERSION ($PROGRAM_DATE)";
$PROGRAM_URL = 'http://k5n.us/wp/webcalendar/';
Expand Down
10 changes: 9 additions & 1 deletion includes/dbi4php.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ function dbi_connect( $host, $login, $password, $database, $lazy = true ) {
} else
return false;
} elseif( strcmp( $GLOBALS['db_type'], 'mysqli' ) == 0 ) {
#mysqli_report(MYSQLI_REPORT_ALL);
$c = new mysqli( $host, $login, $password, $database );

if( $c ) {
Expand Down Expand Up @@ -379,7 +380,14 @@ function dbi_query( $sql, $fatalOnError = true, $showError = true ) {
$res = mysql_query( $sql, $db_connection_info['connection'] );
} elseif( strcmp( $GLOBALS['db_type'], 'mysqli' ) == 0 ) {
$found_db_type = true;
$res = $GLOBALS['db_connection']->query( $sql );
try {
$res = $GLOBALS['db_connection']->query( $sql );
} catch (Exception $e) {
$res = false;
// Log error
//echo "Error: " . $e->getMessage() . "<br>";
//error_log($e->getMessage());
}
} elseif( strcmp( $GLOBALS['db_type'], 'odbc' ) == 0 ) {
return odbc_exec( $GLOBALS['odbc_connection'], $sql );
} elseif( strcmp( $GLOBALS['db_type'], 'oracle' ) == 0 ) {
Expand Down
23 changes: 13 additions & 10 deletions includes/formvars.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function preventHacking_helper($matches) {
return chr(hexdec($matches[1]));
}
function preventHacking ( $name, $instr ) {
global $PHP_SELF;
$script = basename($PHP_SELF);
$phpSelf = $_SERVER['PHP_SELF'];
$script = basename($phpSelf);

$bannedTags = [
'APPLET', 'BODY', 'EMBED', 'FORM', 'HEAD',
Expand Down Expand Up @@ -57,6 +57,8 @@ function preventHacking ( $name, $instr ) {
//print_r ( $_SERVER );
//echo "NO ERROR <br>\n"; exit;

if (empty($instr))
return;
if ( is_array ( $instr ) ) {
for ( $j = 0; $j < count ( $instr ); $j++ ) {
// First, replace any escape characters like '\x3c'
Expand Down Expand Up @@ -146,7 +148,7 @@ function getPostValue($name, $defVal = NULL, $chkXSS = false)

$cleanXSS = $chkXSS ? chkXSS($postName) : true;
preventHacking($name, $postName);
return $cleanXSS ? $postName : NULL;
return $cleanXSS ? $postName : '';
}

/**
Expand Down Expand Up @@ -250,15 +252,16 @@ function getIntValue($name, $fatal = false) {
*/
function chkXSS($name) {
global $login;
if(empty($name))
return '';
$cleanXSS = true;
//add more array elements as needed
foreach (array( 'Ajax.Request', 'onerror') as $i) {
if (preg_match("/$i/i", $name)) {
activity_log(0, $login, $login, SECURITY_VIOLATION,
'Hijack attempt:' . $i);
$cleanXSS = false;
}
//add more array elements as needed
foreach (array( 'Ajax.Request', 'onerror') as $i) {
if (preg_match("/$i/i", $name)) {
activity_log(0, $login, $login, SECURITY_VIOLATION, 'Hijack attempt:' . $i);
$cleanXSS = false;
}
}

return $cleanXSS;
}
Expand Down
25 changes: 16 additions & 9 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,9 @@ function date_to_str ( $indate, $format = '', $show_weekday = true,
$y = intval ( $indate / 10000 );
$m = intval ( $indate / 100 ) % 100;
$d = $indate % 100;
$wday = strftime ( "%w", mktime ( 0, 0, 0, $m, $d, $y ) );
$dateTime = new DateTime();
$dateTime->setDate($y, $m, $d);
$wday = $dateTime->format('w');
if ( $short_months ) {
$month = month_name ( $m - 1, 'M' );
$weekday = weekday_name ( $wday, 'D' );
Expand All @@ -886,7 +888,7 @@ function date_to_str ( $indate, $format = '', $show_weekday = true,
$ret = str_replace ( '__yy__', sprintf ( "%02d", $y % 100 ), $ret );

return ( $show_weekday
? weekday_name ( strftime ( '%w', mktime ( 0, 0, 0, $m, $d, $y ) ),
? weekday_name ( date('w', mktime(0, 0, 0, $m, $d, $y)),
( $short_months ? 'D' : '' ) ) . ', '
: '' ) . str_replace ( '__yyyy__', $y, $ret );
}
Expand Down Expand Up @@ -1549,7 +1551,7 @@ function display_time ( $time = '', $control = 0, $timestamp = '',
}
}
$hour = intval ( $time / 10000 );
$min = abs ( ( $time / 100 ) % 100 );
$min = abs ( intval( $time / 100 ) % 100 );

// Prevent goofy times like 8:00 9:30 9:00 10:30 10:00.
if ( $time < 0 && $min > 0 )
Expand Down Expand Up @@ -3954,14 +3956,19 @@ function is_weekend ( $date ) {
*
* @ignore
*/
function isLeapYear ( $year = '' ) {
if ( empty ( $year ) )
$year = strftime( '%Y', time() );
function isLeapYear(int $year = null): bool {
// If no year is provided, use the current year
if ($year === null) {
$year = (int) date('Y');
}

if ( strlen ( $year ) != 4 || preg_match ( '/\D/', $year ) )
return false;
// Check if the year is 4 characters and numeric
if (strlen((string) $year) != 4 || !is_numeric($year)) {
return false;
}

return ( ( $year % 4 == 0 && $year % 100 != 0 ) || $year % 400 == 0 );
// Leap year check
return ($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0;
}

/**
Expand Down

0 comments on commit 3889507

Please sign in to comment.