|  |  | 
|  | <?php
 | 
|  | 
 | 
|  | if (!function_exists('file_get_html')) {
 | 
|  |     function file_get_html($url) {
 | 
|  |         $ch = curl_init();
 | 
|  |         curl_setopt($ch, CURLOPT_URL, $url);
 | 
|  |         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 | 
|  |         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 | 
|  |         $output = curl_exec($ch);
 | 
|  |         curl_close($ch);
 | 
|  |         return str_get_html($output);
 | 
|  |     }
 | 
|  | }
 | 
|  | 
 | 
|  | 
 | 
|  | function nsb_news_feed_display() {
 | 
|  |     
 | 
|  |     $news = nsb_fetch_news();
 | 
|  |     $events = nsb_fetch_events();
 | 
|  | 
 | 
|  |     
 | 
|  |     $output = '<h2>See What’s Happening</h2>';
 | 
|  |     $output .= $news;
 | 
|  |     
 | 
|  |     $output .= '<h2>Upcoming Events</h2>';
 | 
|  |     $output .= $events;
 | 
|  | 
 | 
|  |     return $output;
 | 
|  | }
 | 
|  | 
 | 
|  | 
 | 
|  | function nsb_fetch_news() {
 | 
|  |     $url = 'https://www.cityofnsb.com/';
 | 
|  |     $html = file_get_html($url);
 | 
|  | 
 | 
|  |     if (!$html) {
 | 
|  |         return '<p>Error fetching news from the City of NSB website.</p>';
 | 
|  |     }
 | 
|  | 
 | 
|  |     
 | 
|  |     $newsSection = $html->find('div#whats-happening', 0);
 | 
|  |     $spotlightSection = $html->find('div#spotlight', 0);
 | 
|  | 
 | 
|  |     if (!$newsSection || !$spotlightSection) {
 | 
|  |         return '<p>No news available at the moment.</p>';
 | 
|  |     }
 | 
|  | 
 | 
|  |     
 | 
|  |     $news = $newsSection->innertext;
 | 
|  |     $spotlight = $spotlightSection->innertext;
 | 
|  | 
 | 
|  |     return $news . '<br>' . $spotlight;
 | 
|  | }
 | 
|  | 
 | 
|  | 
 | 
|  | function nsb_fetch_events() {
 | 
|  |     $url = 'https://cityofnsb.granicus.com/ViewPublisher.php?view_id=1';
 | 
|  |     $html = file_get_html($url);
 | 
|  | 
 | 
|  |     if (!$html) {
 | 
|  |         return '<p>Error fetching events from the Granicus website.</p>';
 | 
|  |     }
 | 
|  | 
 | 
|  |     
 | 
|  |     $eventsToLookFor = [
 | 
|  |         "Planning & Zoning Board",
 | 
|  |         "City Commission Regular Meeting",
 | 
|  |         "Historic Preservation Commission",
 | 
|  |         "Housing Authority",
 | 
|  |         "Code Compliance Board",
 | 
|  |         "Community Development Block Grant Advisory Board",
 | 
|  |         "Economic Development Task Force",
 | 
|  |         "Special Magistrate"
 | 
|  |     ];
 | 
|  | 
 | 
|  |     $events = '';
 | 
|  |     foreach ($html->find('table#upcoming-events tr') as $row) {
 | 
|  |         $title = $row->find('td.title', 0)->plaintext;
 | 
|  |         $date = $row->find('td.date', 0)->plaintext;
 | 
|  | 
 | 
|  |         
 | 
|  |         foreach ($eventsToLookFor as $eventTopic) {
 | 
|  |             if (stripos($title, $eventTopic) !== false) {
 | 
|  |                 $events .= '<p>' . $date . ' - ' . $title . '</p>';
 | 
|  |                 break;
 | 
|  |             }
 | 
|  |         }
 | 
|  |     }
 | 
|  | 
 | 
|  |     if (empty($events)) {
 | 
|  |         return '<p>No upcoming events found for the specified topics.</p>';
 | 
|  |     }
 | 
|  | 
 | 
|  |     return $events;
 | 
|  | }
 | 
|  | 
 | 
|  | 
 | 
|  | add_shortcode('nsb_news_feed', 'nsb_news_feed_display');
 | 
|  | 
 | 
|  |  | 
|  |  | 
Comments