News

db = new PDODB('protect'); $this->config('debug', true); $this->get('/releases', array($this, 'releases')); $this->get('/newsticker', array($this, 'newsticker')); $this->get('/feed', array($this, 'feed')); $this->run(); } // *** GETS **************************************************************** public function releases() { echo $this->getResults(); } public function newsticker() { echo $this->getFeed('ticker'); } public function feed() { echo $this->getFeed(); } public function getResults() { global $ROOT_URL; $builder = new IUCommFormBuilder(); $campuses = $this->getCampuses(); $topics = array_merge(array(''=>'Topic'), $this->getDropDownByType('topics')); $audience = array_merge(array(''=>'Audience'), $this->getDropDownByType('audiences')); $params['campus'] = filter_var($_GET['campus'], FILTER_SANITIZE_STRING); $params['topic'] = filter_var($_GET['topic'], FILTER_SANITIZE_STRING); $params['audience'] = filter_var($_GET['audience'], FILTER_SANITIZE_STRING); $html = ''; $html .= $builder->open()->attribute('action', $ROOT_URL .'news/index.html') ->attribute('method','GET'); $html .= '
'; $html .= $builder->select('','campus',$campuses,array('id'=>'display_name'), $params['campus']); $html .= $builder->select('','topic',$topics,array('id'=>'display_name'), $params['topic']); $html .= $builder->select('','audience',$audience,array('id'=>'display_name'), $params['audience']); $html .= $builder->formWrapperClose(); $html .= $builder->submit('Go'); $html .= $builder->close(); $html .= $this->releaseSorterItems(); $html .= '
'; return $html; } private function releaseSorterItems() { global $ROOT_URL; $builder = new IUCommFormBuilder($_SERVER['QUERY_STRING']); $params = array(); $whereClause = array(); $page = (isset($_GET['page']) && $_GET['page'] !='') ? filter_var($_GET['page'], FILTER_VALIDATE_INT) : '1'; $perPage = '10'; $start = ($page - 1) * $perPage; if(isset($_GET['campus']) && $_GET['campus'] !='' && $_GET['campus'] !='IU Wide') { $params['campus'] = filter_var($_GET['campus'], FILTER_SANITIZE_STRING); $whereClause[] = 'campus = :campus'; } if(isset($_GET['topic']) && $_GET['topic'] !='') { $topic = filter_var($_GET['topic'], FILTER_SANITIZE_STRING); $topicTag = $this->convertName($topic); $params['topic'] = '%%<'.$topicTag.'>Yes%%'; $whereClause[] = 'content LIKE :topic'; } if(isset($_GET['audience']) && $_GET['audience'] !='') { $audience = filter_var($_GET['audience'], FILTER_SANITIZE_STRING); $audienceTag = $this->convertName($audience); $params['audience'] = '%%<'.$audienceTag.'>Yes%%'; $whereClause[] = 'content LIKE :audience'; } $sql = "SELECT SQL_CALC_FOUND_ROWS *, path, content FROM page WHERE type='news'"; if(!empty($whereClause)) $sql .= 'AND '.implode(' AND ', $whereClause); $sql .= ' ORDER BY CONVERT(release_date, UNSIGNED INTEGER) DESC'; $sql .= ' LIMIT '.$start.', '. $perPage; $this->db->query($sql, $params); $results = $this->db->to_assoc(); $this->db->query('SELECT FOUND_ROWS()'); $totalRows = $this->db->to_assoc(); $total = $totalRows[0]['FOUND_ROWS()']; $html = ''; $html .= $builder->selectionWrapper($total)->addClass('border-bottom'); $html .= '
'; foreach($results as $r) { $content = $this->convert_smart_quotes($r['content']); $xml = simplexml_load_string($content); $release = $xml->release->release; $html .= $this->outputReleases($release, $r['path']); } $html .= $builder->pagination(array('total' => $total, 'include_mobile'=> true)); //$html .= '
'; return $html; } public function getFeed($mode='') { global $ROOT_URL; $whereClause = array(); if(isset($_GET['topic']) && $_GET['topic'] !='') { $topic = filter_var($_GET['topic'], FILTER_SANITIZE_STRING); $topicTag = $this->convertName($topic); $params['topic'] = '%%<'.$topicTag.'>Yes%%'; $whereClause[] = 'content LIKE :topic'; } $sql = "SELECT path, content, type FROM page WHERE type='news'"; if(!empty($whereClause)) $sql .= 'AND '.implode(' AND ', $whereClause); $sql .= " ORDER BY CONVERT(release_date, UNSIGNED INTEGER) DESC LIMIT 5"; $this->db->query($sql, $params); $results = $this->db->to_assoc(); $divClass = ($mode=='ticker') ? 'news ticker' : 'feed'; $newsFeed = ''; $newsFeed .= '
'; foreach($results as $r) { $content = $r['content']; $xml = simplexml_load_string(utf8_encode($content)); $release = $xml->release->release; $newsFeed .= $this->outputReleases($release, $r['path'], '0'); } $newsFeed .= '
'; $topClass = ($mode=='ticker')? ' top': ''; $newsFeed .= 'View more news ยป'; return $newsFeed; } private function outputReleases($release, $path, $showDate='1') { global $ROOT_URL; $link = ($release->type=='Internal') ? $ROOT_URL.$path.'.html' : $release->{'external-url'}; $date = $release->date/1000; $photo = ($xml->release->photo->image->path !='/') ? $xml->release->photo->image->path : ''; $content = $release->teaser; $html .= '
'; if($photo!='') { $html .= '
'; $html .= ''; $html .= '
'; } $html .= '
'; $html .= '

'.$release->headline.'

'; if($showDate=='1') { $html .= ''; } $html .= '

'; if($content->saveXML()!='') $html .= $content->saveXML(); $html .= '

'; $html .= '
'; $html .= '
'; return $html; } private function getCampuses() { $array = array(); $xml = simplexml_load_file('../../news/campus-news-order-xml.xml'); foreach($xml->block->content->{system-index-block}->{system-folder} as $folder) { foreach($folder as $f) { $metadata = $f->xpath("dynamic-metadata[name='type']"); if($metadata{0}->value=='campus-news') { $displayName = $f->{'display-name'}; $array["$displayName"] = $displayName; } } return $array; } } private function getDropDownByType($type) { $allowed_types = array('topics', 'audiences'); if(!in_array($type, $allowed_types)) return; $this->db->query("SELECT content FROM page WHERE type='news' LIMIT 1"); $results = $this->db->to_assoc(); $xml = simplexml_load_string(utf8_encode($results[0]['content'])); foreach($xml->release->release->$type as $t) { foreach($t as $k=>$v) { $name = str_replace('_c_',', ',$k); $name = str_replace('_',' ',$name); $array[$name] = $name; } } return $array; } private function convertName($name) { $name = str_replace(', ', '_c_', $name); $name = str_replace(' ', '_', $name); return $name; } private function convert_smart_quotes($string) { $search = array(chr(145), chr(146), chr(147), chr(148), chr(151)); $replace = array("'", "'", '"', '"', '-'); return str_replace($search, $replace, $string); } } new API; >

How can you stay safe in life and online?

Run Hide Fight

Have you watched the new video?

This short video explains the Run Hide Fight concept for surviving an active shooter or aggressor scenario. The strategies can be used in a variety of settings.

Learn more

IU Police Academy

Unity in diversity

The 42 students who graduated from the Indiana University Police Academy brought diverse backgrounds and interests and then graduated as one family. Meet some of them in this video.

Watch

Cybersecurity while traveling

Tools for staff and students

Whether you're traveling across the state or around the world, follow these steps before, during and after your trip to prevent cyber attacks.

Learn more

Safety-minded?

We've got you covered

IU employees can obtain a Campus Emergency Preparedness Certificate by learning skills that can help them at home and at work.

Learn more