HEX
Server: Apache
System: Linux www3.pit.tblive.com 5.14.0-687.38.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Aug 12 17:19:12 EDT 2026 x86_64
User: awaldron (1020)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/awaldron/_domains/pennhillscdc.org/wp-content/themes/phcdc/functions.php
<?php
/**
 * Understrap functions and definitions
 *
 * @package understrap
 */

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;




function first_paragraph( $content ) {
    $stop = strpos($content, '</p>');
    $content = substr($content, 0, $stop);
    return strip_tags($content);
}


$understrap_includes = array(
	'/theme-settings.php',                  // Initialize theme default settings.
	'/setup.php',                           // Theme setup and custom theme supports.
	'/widgets.php',                         // Register widget area.
	'/enqueue.php',                         // Enqueue scripts and styles.
	'/template-tags.php',                   // Custom template tags for this theme.
	'/pagination.php',                      // Custom pagination for this theme.
	'/hooks.php',                           // Custom hooks.
	'/extras.php',                          // Custom functions that act independently of the theme templates.
	'/customizer.php',                      // Customizer additions.
	'/custom-comments.php',                 // Custom Comments file.
	'/jetpack.php',                         // Load Jetpack compatibility file.
	'/class-wp-bootstrap-navwalker.php',    // Load custom WordPress nav walker.
	'/woocommerce.php',                     // Load WooCommerce functions.
	'/editor.php',                          // Load Editor functions.
	'/deprecated.php',                      // Load deprecated functions.
);

foreach ( $understrap_includes as $file ) {
	$filepath = locate_template( 'inc' . $file );
	if ( ! $filepath ) {
		trigger_error( sprintf( 'Error locating /inc%s for inclusion', $file ), E_USER_ERROR );
	}
	require_once $filepath;
}

/**
 * Load Custom Admin Screens
 */
require_once get_template_directory() . '/admin/admin.php';

function no_breaks( $content ) {
    $content = str_replace(">","> ", $content);
    $content = strip_tags($content,'<a>');
    return $content;
}

function phlib_calendar($m, $y, $events) {
    $ecal = array();
    for ($i=0; $i < count($events); $i++) {
        $date = date('Ymd',strtotime($events[$i]['start']));
        $ecal[$date][] = $events[$i];
    }
    $first_of_month = mktime(12,0,0,$m,1,$y);
    $days_in_month = date('t',$first_of_month);
    $start_day_of_week = date('w',$first_of_month);
    $last_of_month = mktime(12,0,0,$m,$days_in_month,$y);
    $end_day_of_week = date('w',$last_of_month);
    $month_name = date('F',$first_of_month);
    $top_blank = $bot_blank = 0;
    $week_ctr = $start_day_of_week;
    $start_of_today = mktime(0,0,0,date('n'),date('j'),date('Y'));

    //echo '<pre>',print_r($ecal),'</pre>';

    $out = '<div class="events-calendar">';
    $out .= '<table border="0" cellpadding="4" cellspacing="0" class="calendar">';
    $out .= '<tbody><tr><th colspan="7">'.$month_name.'&nbsp;'.$y.'</th></tr>';
    $out .= '<tr><td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td></tr>';
    $out .= '<tr>';
    while ($top_blank < $start_day_of_week) { $out .= '<td></td>'; $top_blank++; }
    for ($i=1; $i <= $days_in_month; $i++) {
        $today_time = mktime(12,0,0,$m,$i,$y);
        $today_date = date('Ymd',$today_time);
        $today = (date('Ymd') == $today_date);
        $id = ($today_time > $start_of_today ? 'date-'.$i : '');
        $faded = ($today_time < $start_of_today ? 'faded' : '');
        $click = ($today_time > $start_of_today ? 'clickdate' : '');
        $out .= '<td id="'.$id.'" class="'.$click.' '.($today?'today':'').' '.$faded.'" rel="'.date('Ymd',$today_time).'"><span>'.$i.'</span><div>';
        $cats_used = array();
        foreach ($ecal[$today_date] as $d) {
            if (!in_array($d['cat_title'], $cats_used)) {
                $out .= '<i class="fas fa-circle '.strtolower($d['cat_title']).'"></i>';
                $cats_used[] = $d['cat_title'];
            }
        }
        $out .= '</div></td>';
        if (($i+$start_day_of_week)%7 == 0) { $out .= '</tr><tr>'; }
    }
    while ($end_day_of_week < 6) { $out .= '<td></td>'; $end_day_of_week++; }
    $out .= '<tr>';
    $out .= ' </tbody></table></div>';
    return $out;
}



function generateRandomString($length = 32) {
    $characters = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}


function send_event_reg_email( $event, $data, $dates ) {
    $date = array();
    foreach( $dates as $d ) {
        if ($d['event_date_id'] == $data['event_date_id']) $date = $d;
    }

    $to = $data['reg_email'];
    $subject = 'Event Registration - Penn Hills Library';
    $headers = "From: phlibrary@einetwork.net" . "\r\n" .
        "Reply-To: phlibrary@einetwork.net" . "\r\n" .
        "Cc: phlibrary@einetwork.net" . "\r\n" .
        "X-Mailer: PHP/" . phpversion();

    $msg = "Penn Hills Library - Event Registration"."\n\n";
    $msg .= "Thank you for registering for this Penn Hills event. Your registration details are as follows:"."\n\n";
    $msg .= "Event: ".$event['title']."\n";
    $msg .= "Date/Time: ".date('F j, Y - g:i a',strtotime($date['start']))."\n";
    $msg .= "Location: ".$event['location']."\n";
    $msg .= "Address: ".$event['address']."\n";
    $msg .= "RSVP: ".$data['reg_adults']." Adults and ".$data['reg_kids']." Children"."\n\n";
    $msg .= "Full event details are available at:"."\n";
    $msg .= "http://pennhillslibrary.org/event/".$event['event_id']."\n\n";
    $msg .= "Should you need to cancel your registration, follow this URL:"."\n";
    $msg .= "http://pennhillslibrary.org/event_cancel/".$data['del_code']."\n\n\n";
    $msg .= "We look forward to seeing you there!"."\n";
    $msg .= "Penn Hills Library"."\n\n\n";

    wp_mail( $to, $subject, $msg, $headers );

}


function event_rewrite_rule() {
    add_rewrite_rule(
	    '^event/([^/]*)/?', 
	    'index.php?page_id=36&event_id=$matches[2]', 
	    'top'
    );
}
add_action('init', 'event_rewrite_rule');

function get_event_params($vars){
    $vars[] = 'event_id';
    return $vars;
}
add_filter('query_vars', 'get_event_params');