Skip to content

Instantly share code, notes, and snippets.

@bzerangue
Last active October 15, 2023 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bzerangue/8031833501b1b830870a8edc76553432 to your computer and use it in GitHub Desktop.
Save bzerangue/8031833501b1b830870a8edc76553432 to your computer and use it in GitHub Desktop.
Ministry Platform Publication Feed

Rendering Publications - Ministry Platform

From the Ministry Platform Knowledge Base...

Existing Messages may be associated with a Publication via the Messages sub-page or the Publication Messages page.

A list of available Publications can be found by appending /ministryplatformapi/publications.svc to your church's base URL (for example, https://sample.church.com/ministryplatformapi/publications.svc). To populate a feed, further append the URL with the desired Publication Name as defined on the Publication record.

Once appended (for example, https://sample.church.com/ministryplatformapi/publications.svc/samplefeed), the content of all associated Messages will appear correctly formatted in an XML file. Do not include a trailing slash after the Publication Name.


See attached PHP and XSLT code to render your MP Publications on a server that renders PHP and has access to libXSLT library (which most PHP hosts have).

Add these two files to your server as is, but replace https://sample.church.com/ministryplatformapi/publications.svc/samplefeed with your feed url.

<?php
/* Use your MinistryPlatform Publications Feed URL */
$feedUrl = 'https://sample.church.com/ministryplatformapi/publications.svc/samplefeed';
/* Set ID to value from url paramater; if parameter does not exist or is not set, give it a blank value */
$id = isset($_GET['id']) ? $_GET['id'] : '';
$xmlData = file_get_contents($feedUrl);
$xmlProc = new XsltProcessor();
$xslt = new DomDocument();
/* Load the XSLT Stylesheet */
$xslt -> load("render.xsl");
$xmlProc -> importStylesheet($xslt);
/* Set the Parameter, if no parameter is there, set a NULL value */
$xmlProc -> setParameter('', 'id', $id);
$xml = new DomDocument();
/* Load the XML document */
$xml -> loadXML($xmlData);
/* If the transform is successful then display transformation,
If NOT display the message there is a problem */
if ($html = $xmlProc -> transformToXML($xml))
{
echo $html;
}
else
{
echo "<p>There is a problem.</p>";
}
?>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="atom dc itunes date">
<xsl:output method="html" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
<xsl:param name="id"></xsl:param>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="normalize-space($id)!=''">
<xsl:apply-templates select="atom:feed/atom:entry[atom:id=$id]" mode="detail"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="atom-list"></xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="atom-list">
<xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html&gt;&#10;</xsl:text>
<html lang="en-us">
<head>
<title><xsl:value-of select="atom:feed/atom:title"/></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<style type="text/css"><xsl:call-template name="styles"/></style>
</head>
<body>
<div class="container">
<header>
<h1><xsl:value-of select="atom:feed/atom:title"/></h1>
</header>
<xsl:apply-templates select="atom:feed/atom:entry" mode="list"/>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="atom:entry" mode="list">
<xsl:param name="displayDate">
<xsl:value-of select="date:month-name(atom:updated)"/>
<xsl:text> </xsl:text>
<xsl:value-of select="date:day-in-month(atom:updated)"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="date:year(atom:updated)"/>
</xsl:param>
<div class="pb-5">
<h3>
<a href="?id={atom:id}" target="_blank" rel="noopener">
<xsl:value-of select="atom:title"/>
</a>
</h3>
<small class="meta">
<xsl:text>Published: </xsl:text>
<xsl:value-of select="$displayDate"/>
</small>
</div>
</xsl:template>
<xsl:template match="atom:entry" mode="detail">
<xsl:value-of select="atom:content" disable-output-escaping="yes"/>
</xsl:template>
<xsl:template name="styles">
* { box-sizing: border-box; }
img { max-width: 100%; }
body { --gap: 1.4em; margin: 0; font-family: system-ui; line-height: 1.4; }
h1,h2,h3 { margin-block-start: 0; margin-block-end: 0; line-height: 1.2; }
.container { display: grid; gap: var(--gap); max-width: 46rem; width: 95%; margin: 1.4em auto; }
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment