Skip to content

Commit

Permalink
Merge pull request #472 from bbannon/php
Browse files Browse the repository at this point in the history
faster
  • Loading branch information
craigk5n authored Aug 31, 2024
2 parents 9ef67a2 + 1db0579 commit 62f776b
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 80 deletions.
60 changes: 15 additions & 45 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,7 @@ function save_pref ( $prefs, $src ) {
// Make sure globals values passed to styles.php are for this user.
// Makes the demo calendar and Page title accurate.
$GLOBALS['APPLICATION_NAME'] = $s['APPLICATION_NAME'];
$GLOBALS['BGCOLOR'] = $s['BGCOLOR'];
$GLOBALS['CELLBG'] = $s['CELLBG'];
$GLOBALS['FONTS'] = $s['FONTS'];
$GLOBALS['H2COLOR'] = $s['H2COLOR'];
$GLOBALS['HASEVENTSBG'] = $s['HASEVENTSBG'];
$GLOBALS['MYEVENTS'] = $s['MYEVENTS'];
$GLOBALS['OTHERMONTHBG'] = $s['OTHERMONTHBG'];
$GLOBALS['TABLEBG'] = $s['TABLEBG'];
$GLOBALS['TEXTCOLOR'] = $s['TEXTCOLOR'];
$GLOBALS['THBG'] = $s['THBG'];
$GLOBALS['THFG'] = $s['THFG'];
$GLOBALS['TODAYCELLBG'] = $s['TODAYCELLBG'];
$GLOBALS['WEEKENDBG'] = $s['WEEKENDBG'];
$GLOBALS['WEEKNUMBER'] = $s['WEEKNUMBER'];

define_languages(); // Load the language list.
reset ( $languages );
Expand Down Expand Up @@ -127,8 +114,9 @@ function save_pref ( $prefs, $src ) {

$option = '
<option value="';
$color_sets = $datestyle_md = $datestyle_my = $datestyle_tk = '';
$datestyle_ymd = $lang_list = $prefer_vu = '';

$cch = $color_sets = $datestyle_md = $datestyle_my = $datestyle_tk = '';
$datestyle_ymd = $lang_list = $prefer_vu = $rc = '';
$start_wk_on = $start_wkend_on = $tabs = $user_vu = '';
$work_hr_end = $work_hr_start = '';

Expand Down Expand Up @@ -225,10 +213,15 @@ function save_pref ( $prefs, $src ) {
'POPUP_BG' => translate('Event popup background'),
'POPUP_FG' => translate('Event popup text')
];

foreach ( $colors as $k => $v ) {
$handler = 'color_change_handler_' . $k;
$color_sets .= print_color_input_html ( $k, $v, '', '', 'p', '', $handler );
$GLOBALS[$k] = $s[$k];
// Change the color in the current page
$cch .= " function color_change_handler_$k() {\n var color = $('#admin_' + $k).val();\n\n $('body').get(0).style.setProperty('--' + $k.toLowerCase, color);\n }\n";
$color_sets .= print_color_input_html ( $k, $v, '', '', 'p', '', 'color_change_handler_' . $k );
$rc .= "\n $('#admin_' + $k).val(" . $GLOBALS[$k] . ");\n $('body').get(0).style.setProperty('--' + $k.toLowerCase, '" . $GLOBALS[$k] . "');\n";
}

$csp = ( $s['CSP'] ?: 'none' );

set_today ( date ( 'Ymd' ) );
Expand Down Expand Up @@ -852,36 +845,13 @@ function save_pref ( $prefs, $src ) {
</div>
<div style="clear:both;">
<button class="btn btn-primary" name="" type="submit">'
. $saveStr . '</button>
. $saveStr . "</button>
</div>
</form>
</div>
</div>
</div>';

echo "\n<script>\n";

// Change the color in the current page
foreach ( $colors as $k => $v ) {
echo "function color_change_handler_$k() {\n";
echo " var color = $('#admin_" . $k . "').val();\n";
echo " $('body').get(0).style.setProperty('--" . strtolower($k) . "', color);\n";
echo "}\n";
}

?>
function reset_colors() {
<?php
foreach ( $colors as $k => $v ) {
echo " $('body').get(0).style.setProperty('--" . strtolower($k) . "', '$GLOBALS[$k]');\n";
echo " $('#admin_" . $k . "').val('$GLOBALS[$k]');\n";
}
?>
}

</script>
<?php

<script>\n" . $cch . "
function reset_colors() {" . $rc . '
}
</script>';
} else {
// if $error
echo print_error ( $error, true );
Expand Down
2 changes: 1 addition & 1 deletion export.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

$datem = date ( 'm' );
$dateY = date ( 'Y' );
$yearAgo = time () - 365 * 24 * 3600;
$yearAgo = time () - 31536000; // 365 * 24 * 3600;
$dateYearAgo = date('Ymd', $yearAgo);
$selected = ' selected ';

Expand Down
2 changes: 1 addition & 1 deletion import_outlookcsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function parse_outlookcsv ( $cal_file ) {
}

function dateDifference ( $start_timestamp, $end_timestamp, $unit = 0 ) {
$days_seconds_star = ( 23 * 56 * 60 ) + 4.091; // Star Day
$days_seconds_star = 77284.091; // Star Day ( 23 * 56 * 60 ) + 4.091
$days_seconds_sun = 86400; // Sun Day
$difference_seconds = $end_timestamp - $start_timestamp;
switch ( $unit ) {
Expand Down
22 changes: 11 additions & 11 deletions includes/classes/Doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,71 +19,71 @@
*/
class Doc {
/**
* The unique id
* The unique id
* @var int
* @access private
*/
var $_blob_id;

/**
* Associated event's id (if any)
* Associated event's id (if any)
* @var int
* @access private
*/
var $_event_id;

/**
* The user login of user who created this Doc
* The user login of user who created this Doc
* @var string
* @access private
*/
var $_login;

/**
* Filename of the doc (not used for comments)
* Filename of the doc (not used for comments)
* @var string
* @access private
*/
var $_name;

/**
* The description of the doc
* The description of the doc
* @var string
* @access private
*/
var $_description;

/**
* The size of the doc (in bytes)
* The size of the doc (in bytes)
* (not used for comments)
* @var int
* @access private
*/
var $_size;

/**
* The MIME type of the doc
* The MIME type of the doc
* @var string
* @access private
*/
var $_mime_type;

/**
* Type of object (C=Comment, A=Attachment)
* Type of object (C=Comment, A=Attachment)
* @var string
* @access private
*/
var $_type;

/**
* Date last modified (in YYYYMMDD format)
* Date last modified (in YYYYMMDD format)
* @var int
* @access private
*/
var $_mod_date;

/**
* Time last modified (in HHMMSS format)
* Time last modified (in HHMMSS format)
* @var int
* @access private
*/
Expand Down Expand Up @@ -314,7 +314,7 @@ function getSummary ($target='') {
if ( $this->_size < 1024 )
$ret .= $this->_size . ' ' . translate ( 'bytes' );
else
if ( $this->_size < 1024 * 1024 )
if ( $this->_size < 1048576 ) // 1024 * 1024
$ret .= sprintf ( " %.1f", ( $this->_size / 1024 ) ) . translate ( 'kb' );
else
$ret .= sprintf ( " %.1f", ( $this->_size / 1048576 ) ) . translate ( 'Mb' );
Expand Down
12 changes: 6 additions & 6 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function add_duration ( $time, $duration ) {
$minutes =
intval ( $time / 10000 ) * 60 + ( ( $time / 100 ) % 100 ) + $duration;
// If we ran past 240000, then roll back over to 000000.
$minutes %= ( 24 * 60 );
$minutes %= 1440;

return sprintf ( "%d%02d00", $minutes / 60, $minutes % 60 );
}
Expand Down Expand Up @@ -2581,9 +2581,9 @@ function get_groups($user, $includeUserlist=false)
$res = dbi_execute($sql, [$groups[$i]['cal_group_id']]);
while ($row = dbi_fetch_row($res)) {
if (isset($users_by_name[$row[0]])){
// It is possible some users assigned to this group may not exist,
// so we skip those that don't. For example, if users are fetched
// from an external source via user-app-*.php, and one of those
// It is possible some users assigned to this group may not exist,
// so we skip those that don't. For example, if users are fetched
// from an external source via user-app-*.php, and one of those
// users is deleted externally.
$users[] = $users_by_name[$row[0]];
}
Expand Down Expand Up @@ -3426,8 +3426,8 @@ function getReminders ( $id, $display = false ) {
$d = $h = $minutes = 0;
if ( $reminder['offset'] > 0 ) {
$minutes = $reminder['offset'];
$d = intval ( $minutes / (24*60) );
$minutes -= ( $d * (24*60) );
$d = intval ( $minutes / 1440 ); // (24*&60)
$minutes -= ( $d * 1440 ); // (24*60)
$h = intval ( $minutes / 60 );
$minutes -= ( $h * 60 );
}
Expand Down
20 changes: 10 additions & 10 deletions includes/moon_phases.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ function calculateMoonPhases ( $year, $month = 1 ) {
$U = false;

$K0 = intval ( ( $year - 1900 ) * 12.3685 ) + ( $month - 1 );
$R1 = 3.14159265 / 180;
$T = ( $year - 1899.5 ) / 100;
$R1 = 0.0174532925; // [pi] 3.14159265 / 180
$T = ( $year - 1899.5 ) / 100;
$T2 = $T * $T;
$T3 = $T2 * $T;

$J0 = 2415020 + 29 * $K0;
$J0 = 29 * $K0 + 2415020;

$F0 = ( ( 0.0001178 * $T2 - 0.000000155 * $T3 ) +
( 0.75933 + 0.53058868 * $K0 ) -
( 0.53058868 * $K0 + 0.75933 ) -
( 0.000837 * $T + 0.000335 * $T2 ) );

$M0 = $K0 * 0.08084821133;
Expand All @@ -53,14 +53,14 @@ function calculateMoonPhases ( $year, $month = 1 ) {
( 0.00000239 * $T3 ) );

for ( $K9 = 0; $K9 < 7; $K9 += 0.5 ) {
$J = $J0 + 14 * $K9;
$J = 14 * $K9 + $J0;
$K = $K9 / 2;

$B6 = ( $B1 + $K * 390.67050646 ) * $R1;
$M5 = ( $M0 + $K * 29.10535608 ) * $R1;
$M6 = ( $M1 + $K * 385.81691806 ) * $R1;
$B6 = ( $K * 390.67050646 + $B1 ) * $R1;
$M5 = ( $K * 29.10535608 + $M0 ) * $R1;
$M6 = ( $K * 385.81691806 + $M1 ) * $R1;

$F = ( ( $F0 + 0.765294 * $K9 ) -
$F = ( ( 0.765294 * $K9 + $F0 ) -
( 0.4068 * sin ( $M6 ) ) +
( ( 0.1734 - 0.000393 * $T ) * sin ( $M5 ) ) +
( 0.0161 * sin ( 2 * $M6 ) ) +
Expand All @@ -73,7 +73,7 @@ function calculateMoonPhases ( $year, $month = 1 ) {

$J += intval ( $F );
$F -= intval ( $F );
//.

// Convert from JD to Calendar Date.
$julian = $J + round ( $F );
$s = ( function_exists ( 'jdtogregorian' )
Expand Down
6 changes: 2 additions & 4 deletions purge.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,9 @@ function purge_events ( $ids ) {
['webcal_entry', 'cal_id']];

//var_dump($tables);exit;
$num = [];
$cnt = count ( $tables );
for ( $i = 0; $i < $cnt; $i++ ) {
$num[$i] = 0;
}
$num = array_fill ( 0, $cnt, 0 );

foreach ( $ids as $cal_id ) {
for ( $i = 0; $i < $cnt; $i++ ) {
$clause = ( $cal_id == 'ALL' ? '' :
Expand Down
4 changes: 2 additions & 2 deletions search.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@
</td></tr>';
}
if ($show_advanced) {
$startDateYmd = date('Ymd', time() - (90 * 24 * 3600)); // 90 days ago
$endDateYmd = date('Y-m-d', time() + (90 * 24 * 3600)); // 90 days from now
$startDateYmd = date ( 'Ymd', time() - 7776000 ); // 90 days ago
$endDateYmd = date ( 'Y-m-d', time() + 7776000 ); // 90 days from now
echo '<tr id="datefilter">
<td><label for="date_filter" class="colon">' . translate('Filter by Date')
. ':</label></td>
Expand Down

0 comments on commit 62f776b

Please sign in to comment.