Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding 5.0 template files #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions 5.0/data-defintions/news-with-images.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<system-data-structure>
<text default="news-with-images" field-id="cc9359640aaf692c3ea1383daecf97bc" identifier="module-id" required="true" restrict-to-groups="Administrator"/>
<group identifier="news-with-images" label="Upcoming Events">
<text field-id="cc9359640aaf692c3ea1383db879724f" identifier="headline" label="Headline"/>
<text default="View All News" field-id="cc9359640aaf692c3ea1383d91088a46" identifier="view-all-label" label="View All Link Label"/>
<text default="Internal" field-id="cc9359640aaf692c3ea1383dc3102ade" identifier="internal-external" label="Internal or External Link" type="radiobutton">
<radio-item show-fields="news-with-images/view-all" value="Internal"/>
<radio-item show-fields="news-with-images/external-news-page" value="External"/>
</text>
<asset field-id="cc9359640aaf692c3ea1383dce4e86a8" help-text="Won't Display View All Link if Left Blank" identifier="view-all" label="View All Link" type="page"/>
<text field-id="cc9359640aaf692c3ea1383d7c3d991a" help-text="Won't Display View All Link if Left Blank" identifier="external-news-page" label="External News Page"/>
<text default="call-to-action" field-id="cc9359640aaf692c3ea1383d6f7d0a5d" identifier="news-type" label="Select news display type" type="radiobutton">
<radio-item label="Dedicated link text" show-fields="news-with-images/news-item, news-with-images/news-item/date, news-with-images/news-item/headline, news-with-images/news-item/link-text, news-with-images/news-item/link-type, news-with-images/news-item/image, news-with-images/news-item/img-alt" value="call-to-action"/>
<radio-item label="Headline as link text" show-fields="news-with-images/news-item, news-with-images/news-item/date, news-with-images/news-item/headline, news-with-images/news-item/link-type, news-with-images/news-item/image, news-with-images/news-item/img-alt" value="headline"/>
<radio-item label="Automated News Feed" show-fields="news-with-images/news-feed" value="feed"/>
</text>
<group identifier="news-item" label="News Item" maximum-number="3" minimum-number="3" multiple="true">
<text field-id="cc9359640aaf692c3ea1383dddaa4c3e" help-text="Date Format: July 1 or July 1 - 2" identifier="date" label="Date"/>
<text field-id="cc9359640aaf692c3ea1383dc7f212a5" identifier="headline" label="Headline"/>
<text default="Read More" field-id="cc9359640aaf692c3ea1383d17e9fa8c" identifier="link-text" label="Link Text"/>
<text default="Internal" field-id="cc9359640aaf692c3ea1383d0bb87567" identifier="link-type" label="Link Type" type="radiobutton">
<radio-item show-fields="news-with-images/news-item/internal-link" value="Internal"/>
<radio-item show-fields="news-with-images/news-item/external-link" value="External"/>
</text>
<asset field-id="cc9359640aaf692c3ea1383db1e92553" identifier="internal-link" label="Internal Link" type="page,file,symlink"/>
<text field-id="cc9359640aaf692c3ea1383d11d34579" help-text="Won't Display View All Link if Left Blank" identifier="external-link" label="External Link"/>
<asset field-id="cc9359640aaf692c3ea1383dac92dc75" identifier="image" label="Image" type="file"/>
<text field-id="cc9359640aaf692c3ea1383d2fdef0ac" help-text="For Accessibility Purposes " identifier="img-alt" label="Image Description (Alt Text)"/>
</group>
<group identifier="news-feed" label="Automated News Feed">
<text field-id="7ef02c960aaf6b9871452c626819817e" help-text="Select categories to display news items from today.ucsd.edu. Will display the three most recent articles." identifier="feed-categories" label="News Feed Categories" type="checkbox">
<checkbox-item label="Campus News" value="174"/>
<checkbox-item label="Arts and Humanities" value="75"/>
<checkbox-item label="Biological Sciences" value="79"/>
<checkbox-item label="Extension" value="82"/>
<checkbox-item label="Global Policy and Strategy" value="100"/>
<checkbox-item label="Library" value="85"/>
<checkbox-item label="Physical Sciences" value="78"/>
<checkbox-item label="Rady School of Management" value="81"/>
<checkbox-item label="School of Medicine" value="84"/>
<checkbox-item label="Social Sciences" value="77"/>
<checkbox-item label="The Herbert Wertheim School of Public Health and Human Longevity Science" value="113"/>
</text>
<text field-id="7f2bdf4f0aaf692c05c81e124b0f122f" identifier="admin-feed-categories" label="ADMIN News Feed Categories" restrict-to-groups="P--Administrator, P--University-Communications" type="checkbox">
<checkbox-item label="Books &amp; Culture" value="177"/>
<checkbox-item label="Events &amp; Happenings" value="178"/>
<checkbox-item label="Visual &amp; Performing Arts" value="179"/>
<checkbox-item label="At Work" value="172"/>
<checkbox-item label="Athletics" value="173"/>
<checkbox-item label="Giving" value="175"/>
<checkbox-item label="Student Life" value="176"/>
<checkbox-item label="Awards &amp; Accolades" value="168"/>
<checkbox-item label="In Memoriam" value="169"/>
<checkbox-item label="Milestones" value="170"/>
<checkbox-item label="Profiles" value="171"/>
<checkbox-item label="Insights &amp; Experts" value="180"/>
<checkbox-item label="Opinion" value="181"/>
<checkbox-item label="Q&amp;A" value="182"/>
<checkbox-item label="Halıcıoğlu Data Science Institute" value="112"/>
<checkbox-item label="Jacobs School of Engineering" value="76"/>
<checkbox-item label="Qualcomm Institute / Calit2" value="86"/>
<checkbox-item label="San Diego Supercomputer Center" value="87"/>
<checkbox-item label="Scripps Oceanography" value="80"/>
<checkbox-item label="Skaggs School of Pharmacy and Pharmaceutical Sciences" value="83"/>
<checkbox-item label="COVID-19" value="109"/>
<checkbox-item label="Return to Learn" value="109|110"/>
<checkbox-item label="Climate Change" value="114"/>
<checkbox-item label="Environment" value="88"/>
<checkbox-item label="Business &amp; Economics Research" value="162"/>
<checkbox-item label="Health &amp; Behavior Research" value="163"/>
<checkbox-item label="Humanities Research" value="164"/>
<checkbox-item label="Politics &amp; Society Research" value="165"/>
<checkbox-item label="Science &amp; Environment Research" value="166"/>
<checkbox-item label="Technology &amp; Engineering Research" value="167"/>
<checkbox-item label="The Arts Research" value="161"/>
<checkbox-item label="Alumni" value="187"/>
<checkbox-item label="Magazine" value="188"/>
</text>
</group>
</group>
</system-data-structure>
215 changes: 215 additions & 0 deletions 5.0/formats/news-with-images.vm
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
#macro(NewsImg)

#set ($NewsImg = $_XPathTool.selectSingleNode($node, 'default/content/system-data-structure/news-with-images'))


#set($NiAllNews = "")
#set ($NiLinkCheck = $NewsImg.getChild("internal-external").text)
#if ($NiLinkCheck == "Internal")
#set ($NiAllNews = $NewsImg.getChild("view-all").getChild("link").text)
#elseif ($NiLinkCheck == "External")
#set ($NiAllNews = $NewsImg.getChild("external-news-page").text)
#end
#set ($NiHeadline = $NewsImg.getChild("headline").text)
#set ($NiAllNewsLabel = $NewsImg.getChild("view-all-label").text)
#set ($NewsType = $NewsImg.getChild("news-type").text)
#set ($NewsItems = $_XPathTool.selectNodes($NewsImg, 'news-item'))

<section class="jumbotron jumbotron-gray jumbotron-news" aria-label="News Section">
<div class="container">
<div class="row">
<div class="col-xs-8">
#if($NiHeadline && !$NiHeadline.isEmpty())
<h2>$_EscapeTool.xml($NiHeadline)</h2>
#end
</div>

<div class="col-xs-4 view-all-link text-right">
#if($NiAllNews !="")
<a href="$_EscapeTool.xml($NiAllNews)" class="text-link">$_EscapeTool.xml($NiAllNewsLabel)</a>
#end
</div>
</div>
<div class="row">
#if ($NewsType == "feed")
#set ($NewsFeed = $_XPathTool.selectSingleNode($NewsImg, 'news-feed'))
#set ($FeedCategories = $_XPathTool.selectNodes($NewsFeed, 'feed-categories/value'))
#set ($AdminFeedCategories = $_XPathTool.selectNodes($NewsFeed, 'admin-feed-categories/value'))
#set ($categoryString = "")

#if ($FeedCategories.size() > 0)
#foreach ($category in $FeedCategories)
#set ($categoryString = $categoryString + $category.value)
#if($foreach.hasNext)
#set ($categoryString = $categoryString + "|")
#end
#end
#end

#if ($AdminFeedCategories.size() > 0)
#if(!$_PropertyTool.isEmpty($categoryString))
#set ($categoryString = $categoryString + "|")
#end
#foreach ($category in $AdminFeedCategories)
#set ($categoryString = $categoryString + $category.value)
#if($foreach.hasNext)
#set ($categoryString = $categoryString + "|")
#end
#end
#end

#generateNewsFeed($categoryString)
#else
#foreach($NewsItem in $NewsItems)

#set ($NiDate = $NewsItem.getChild("date").text)
#set ($NiHeadline = $NewsItem.getChild("headline").text)
#set ($NiLinkText = $NewsItem.getChild("link-text").text)
#set ($NiLinkCheck = $NewsItem.getChild("link-type").text)

#if ($NiLinkCheck == "Internal")
#set ($NiLink = $NewsItem.getChild("internal-link").getChild("link").text)
#else
#set ($NiLink = $NewsItem.getChild("external-link").text)
#end

#set ($NiimgAlt = $NewsItem.getChild("img-alt").text)
#set ($NiImg = $NewsItem.getChild("image").getChild("path").text)

#if ($NiImg == "/")
#set ($NiImg = "https://cdn.ucsd.edu/cms/decorator-5/img/news-388x246.png")
#end

<div class="col-sm-4">
<a href="$_EscapeTool.xml($NiLink)" class="panel panel-default" alt="link to news item">
<img class="img-responsive" src="$_EscapeTool.xml($NiImg)" alt="$_EscapeTool.xml($NiimgAlt)" />
<div class="panel-heading">
<p class="panel-news-date small">$_EscapeTool.xml($NiDate)</p>
<h3 class="panel-news-title">$_EscapeTool.xml($NiHeadline)</h3>
</div>
#if ($NewsType == "call-to-action")
<div class="panel-body">$_EscapeTool.xml($NiLinkText)</div>
#end
</a>
</div>
#end
#end
</div>
</div>
</section>

#end

#macro(generateNewsFeed $feedCategoryString)
#set($categoryStringReplace = $feedCategoryString.replace('|',''))
<div class="col-sm-4">
<a class="panel panel-default url0-${categoryStringReplace}" alt="link to news item">
<img alt="" class="img-responsive" id="img0-${categoryStringReplace}" />
<div class="panel-heading">
<p class="panel-news-date small" id="date0-${categoryStringReplace}">&#160;</p>
<h3 class="panel-news-title" id="head0-${categoryStringReplace}">&#160;</h3>
</div>
</a>
</div>

<div class="col-sm-4">
<a class="panel panel-default url1-${categoryStringReplace}" alt="link to news item">
<img alt="" class="img-responsive" id="img1-${categoryStringReplace}" />
<div class="panel-heading">
<p class="panel-news-date small" id="date1-${categoryStringReplace}">&#160;</p>
<h3 class="panel-news-title" id="head1-${categoryStringReplace}">&#160;</h3>
</div>
</a>
</div>

<div class="col-sm-4">
<a class="panel panel-default url2-${categoryStringReplace}" alt="link to news item">
<img alt="" class="img-responsive" id="img2-${categoryStringReplace}" />
<div class="panel-heading">
<p class="panel-news-date small" id="date2-${categoryStringReplace}">&#160;</p>
<h3 class="panel-news-title" id="head2-${categoryStringReplace}">&#160;</h3>
</div>
</a>
</div>

<![CDATA[#protect
<script>
var url = "https://today.ucsd.edu/news-and-features-api?category=${feedCategoryString}&limit=3";

getData(url);

function getData(theurl) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", theurl, true);
xmlhttp.onload = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
if (xmlhttp.status == 200) {
var newsData = JSON.parse(xmlhttp.responseText);

for (var index = 0; index < 3; index++) {
var headId = "head" + index + "-${categoryStringReplace}";
var imgId = "img" + index + "-${categoryStringReplace}";
var dateId = "date" + index + "-${categoryStringReplace}";
var urlId = "url" + index + "-${categoryStringReplace}";

if (newsData[index].entry_date >= 1660546800000) {
if (newsData[index].teaser_photo) {
image = newsData[index].teaser_photo;
var lastSegIndex = image.lastIndexOf('/');
var firstSeg = image.slice(0, lastSegIndex);
var lastSeg = image.slice(lastSegIndex)
var feedImage = firstSeg + '/_ucsd-feed' + lastSeg;
image = feedImage;
}
else {
image = "https://cdn.ucsd.edu/cms/decorator-5/img/news-placeholder.png";
}
} else {
if (newsData[index].feature_image) {
image = newsData[index].feature_image;
} else if (newsData[index].primary_photo) {
image = newsData[index].primary_photo;
} else {
image = "https://cdn.ucsd.edu/cms/decorator-5/img/news-placeholder.png";
}
}
document.getElementById(imgId).src = image;
document.getElementById(headId).innerText = newsData[index].title;
document.getElementById(dateId).innerText = timeConverter(newsData[index].entry_date);
var urls = document.getElementsByClassName(urlId);
var newsUrl = "https://today.ucsd.edu" + "/story/" + newsData[index].url_title;
for (var j = 0; j < urls.length; j++) {
urls[j].setAttribute("href", newsUrl);
}
if (newsData[index].pp_alt) {
document.getElementById(imgId).alt = newsData[index].pp_alt;
}
}
}
else if (xmlhttp.status == 400) {
console.log('Status: Error 400 returned');
}
else {
console.log('Status:' + xmlhttp.status);
}
}
};

xmlhttp.send();
}

function timeConverter(UNIX_timestamp){
var a = new Date(UNIX_timestamp);
var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
var year = a.getFullYear();
var month = months[a.getMonth()];
var date = a.getDate();
var hour = a.getHours();
var min = a.getMinutes();
var sec = a.getSeconds();
var time = month + ' ' + date + ', ' + year;
return time;
}
</script>
#protect]]>
#end