Setting up an RSS Feed Parser in MODX

MODX uses an add-on called getFeed to parse RSS content.

In order to use it, place this code on your page template (example uses the Faculty News Feed):


[[!getFeed?
&url=`https://sls.gmu.edu/faculty-news/feed/`
&tpl=`RSSFeedParser`
&limit=`1`
]]

The code pulls the RSSFeedParser, a custom chunk we made that pulls the most recent article title and link.

Titles are pulled using:

[[+title]]

Links are pulled using:

[[+link]]

Here is a list of other data fields that may be pulled from the RSS Feed, if available:

  • title – The title of the post.
  • link – A direct link to the post.
  • description – The description of the post.
  • pubdate – The date the post was published.
  • guid – The GUID of the post.
  • author – The name of the author of the post.
  • category – Any tags or category associations the post has.
  • summary – A short summary of the post.
  • date_timestamp – The timestamp of the post.

Like most MODx variables, wrap the data fields with double square brackets, but be sure to use the + sign prefix rather than the * symbol.

Full-Time Faculty Table

The Full Time Faculty Table implements one ditto that calls two separate chunks.

The chunks are:

ditto.people_finder.odd.tr.2018

and

ditto.people_finder.even.tr.2018

The structure of both dittos are the same, with only the row background color being different using the existing even and odd classes within the main style sheet.

When calling the ditto, filter the results using:

&parents=`5842,1794`

This sorts the list based on Faculty Type.

When adding fields use the + sign instead of the usual *, so to add the professor’s title, it would look like this:

[[+title_main]]

To integrate a link, use this format:

<a href="mailto:[[+email]]"">[[+email]] </a>

Trouble Viewing Published Material on MODx?

If you’re making an edit to an existing page that has been unpublished in the past, be sure to take an extra look at the “Hide Template Variables on Output” field.

The field is located under most page templates under Template Variables -> Templates – Default TVs:

It varies, but the field in most page templates can be found at the very bottom of the page:

 

A Template Variable or TV, is simply what MODx calls a custom field found in page creation forms. When this field is set to “Yes” and the page is published, no content will be viewable.

This field is set to “No” by default and should not be a problem when creating new content.

 

 

Events Planning Form Using Javascript

A short questionnaire to direct users to the right form using Javscript
window.onload = function() { document.getElementById('link1').style.display = 'none'; document.getElementById('link2').style.display = 'none'; }; //Clears div box

var x, y, z; //assigns variables to radio selections

function a1(answer1){ x = answer1; };
function a2(answer2){ y = answer2; };
function a3(answer3){ z = answer3; };

//if all answers are no, display link2 and hide link2; if any answers are yes, do the opposite.

function showdiv() { if (x==1 | y==1 | z==1){ document.getElementById('link1').style.display='block'; document.getElementById('link2').style.display='none'; } else { console.log("None of the questions is 1"); document.getElementById('link1').style.display='none'; document.getElementById('link2').style.display='block'; } return; }

//How to structure your HTML to code. Onlick assigns value to x,y,z variables

<input type="radio" onclick="a1(1)" name="q1">Yes
<input type="radio" onclick="a1(0)" name="q1">No

//execute code
<button onclick="showdiv()">What Form Do I Need?</button>

//hide show divs using IDs
<div id="link1">
Link 1
</div>
<div id="link2">
Link 2
</div>

Force Update of PDFs

When replacing an existing PDF, browsers don’t serve the latest version. They usually serve the cached version. To change that, we use Apache directives as below:

# Instruct browsers to always check for the latest version of your files using Apache directives
<IfModule mod_headers.c>
<FilesMatch "(?i)^.*\.(css|htm|html|gif|jpg|jpeg|js|png|pdf)$">
Header set Cache-Control "max-age=0,must-revalidate"
</FilesMatch>
</IfModule>

The instruction above includes more than just PDF.

Another solution is using ?ver=x.x in the URL. For example:

https://www.law.gmu.edu/assets/css/2015/style.css?ver=2.0

x.x could be any number.

Source: “How to force an update of cached files, images, favicon

PHP Script Swapping out GA codes

This script was used to delineate Google Analytic Tracking codes between four different sites sharing the same wordpress theme files. Originally placed in footer.php above the GA tracking code provided by Google.

<?php
$host = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if (strpos($host,'sls') !== false)
{
$gacode ="UA-792782-19";
}

elseif (strpos($host,'gai') !== false)
{
$gacode ="UA-792782-21";
}

elseif (strpos($host,'pep') !== false)
{
$gacode ="UA-792782-22";
}

elseif (strpos($host,'mvets') !== false)
{
$gacode ="UA-792782-23";
}

else
{
$gacode ="UA-792782-XX";
}
?>

The script checks the URL and replaces the $gacode variable with the correct analytics code inside the provided GA script.


<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', '<?phpecho $gacode; ?>', 'auto');
ga('send', 'pageview');

</script>

Homepage Featured Events Display Using DOM

The featured events on the Mason Law homepage is pulled from the master calendar’s RSS. To get the dates and times separated from the titles, accessing the DOM is needed. The following codes, which requires jQuery, make the magic happened:

$('.rssItemLink').each(
function(){
$this = $(this);
$this.
html('<em>' +
$this.
html().
replace(/((\d{1,2}\/){2}\d{2,4}\s*[0-9]{1,2}:[0-9]{1,2}\s*[apAP][mM]\s*to\s*[0-9]{1,2}:[0-9]{1,2}\s*[apAP][mM])/,
'</em><b>$1</b>'
)
);
}
);

Sticky Nav on Scroll

Here’s a little JavaScript function to make your site’s header or navigation stick to the top of the window when users scroll the page:

HTML:

<div id="navigation">
  <!-- your navigation code -->
</div>

CSS:

#navigation{
  position:absolute;
  top:120px;
  left:0;
}
#navigation.fixed{
  position:fixed;
  top:16px;
}

JavaScript:

// Handles the page being scrolled by ensuring the navigation is always in view.
function handleScroll(){
  // check that this is a relatively modern browser
  if (window.XMLHttpRequest){
    // determine the distance scrolled down the page
    var offset = window.pageYOffset
               ? window.pageYOffset
               : document.documentElement.scrollTop;
    // set the appropriate class on the navigation
    document.getElementById('navigation').className =
        (offset > 104 ? 'fixed' : '');
  }
}
// add the scroll event listener
if (window.addEventListener){
  window.addEventListener('scroll', handleScroll, false);
}else{
  window.attachEvent('onscroll', handleScroll);
}

Source: “Detachable navigation using JavaScript

EMS Master Calendar Modification

  1. Connect to the server via Microsoft Remote Desktop
  2. Locate: C:\inetpub\wwwroot\MasterCalendar (under My Computer, C drive)

In order to add the Mason Law logo in the master calendar of events, I had to modify the master template file (Calendar.master). Scroll down to line 105, you’ll see this:

<div id="HeaderContainer" runat="server" class="HeaderContainer show-large" >
<!--MASON LAW BY DONNY-->
<div style="background-color:#063; width:100%;"><a href="https://www.law.gmu.edu/"><img src="http://video.law.gmu.edu/logos/cal-head-logo.png" alt="Antonin Scalia Law School, George Mason University" ></a><a href="http://events.law.gmu.edu/MasterCalendar/"><img src="http://video.law.gmu.edu/logos/cal-head-text.png" alt="Calendar of Events" ></a></div>
<!--/MASON LAW BY DONNY-->

<%--<div style="margin-bottom:20px;background-image:url(Images/ems-banner-bg.png)"><div class="centered" style="width:1423px;height:205px;"><img class="centered" src="Images/ems-banner.png"/></div>
</div>--%>
<header:Header ID="Header" runat="server" />
</div>

This template needs to be update every time the EMS calendar is upgraded.