Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Last active January 15, 2024 14:29
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save stevewithington/4742829 to your computer and use it in GitHub Desktop.
Save stevewithington/4742829 to your computer and use it in GitHub Desktop.
Mura CMS: Example of how to import content into Mura CMS from an RSS feed. Place the file under your Mura root. For example: http://yourdomain.com/temp/import/index.cfm. Also see https://gist.github.com/stevewithington/5051646 to importUsersViaCSV
<cfscript>
param name='form.rssurl' default='http://www.npr.org/rss/rss.php?id=1014';
param name='form.parentfilename' default='blog';
param name='form.isSubmitted' default='false';
param name='form.istest' default='true';
param name='form.siteid' default='default';
$ = application.serviceFactory.getBean('$').init(form.siteid);
if ( !$.currentUser().isSuperUser() && !$.currentUser().isInGroup('admin') ) {
WriteOutput('<h3>You should not be here.</h3>');
abort;
}
utility = $.getBean('contentUtility');
parent = $.getBean('content').loadBy(filename=form.parentfilename);
parentid = parent.getContentID();
rsSites = $.getBean('settingsManager').getList();
</cfscript>
<cfoutput>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<cfheader name="expires" value="#dateformat(now(), 'ddd, dd mmm yyyy')# #timeformat(now(), 'HH:mm:ss tt')#">
<cfheader name="pragma" value="no-cache">
<cfheader name="cache-control" value="no-cache, no-store">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Expires" content="#dateformat(now(), 'ddd, dd mmm yyyy')# #timeformat(now(), 'HH:mm:ss tt')#">
<title>Mura CMS: Import Content From RSS Feed</title>
<cfif IsValid('url', form.rssurl)>
<cffeed source="#form.rssurl#" action="read" name="theFeed" />
</cfif>
<style type="text/css">
.wrap {
clear:both;
display:block;
padding:1em;
margin:1em;
border:1px dashed grey;
font-family:Arial, Helvetica, sans-serif;
font-size:0.8em;
}
.wrap label, .wrap input {
clear:both;
display:block;
}
.wrap label {
padding:1em 0 0 0;
}
</style>
</head>
<body>
<div class="wrap">
<h2>Import Content Into Mura CMS Via RSS</h2>
<cfif form.isSubmitted and IsDefined('theFeed')>
<cfscript>
items = theFeed.item;
errors = [];
</cfscript>
<cfif parent.getIsNew()>
<h3>ERROR! Parent filename does not exist.</h3>
<p><a href="#CGI.script_name##CGI.query_string#">Return to form &gt;</a></p>
<cfabort />
</cfif>
<cfif form.istest>
<h3>Test Results <a href="#CGI.script_name##CGI.query_string#">Return to form &gt;</a></h3>
</cfif>
<cfloop array="#items#" index="i">
<!--- <cfdump var="#i#" abort="true" /> --->
<cfscript>
// content = $.getBean('content').loadBy(filename = '#form.parentfilename#/' & utility.formatFilename(i.title));
content = $.getBean('content').loadBy(remoteid = i.link);
content.setTitle(i.title);
content.setMenuTitle('');
content.setURLTitle('');
content.setHTMLTitle('');
content.setApproved(1);
content.setIsNav(0);
content.setParentID(parentid);
content.setRemoteID(i.link);
if ( StructKeyExists(i.description, 'value') ) {
content.setBody(i.description.value);
}
if ( StructKeyExists(i, 'pubDate') ) {
content.setReleaseDate(i.pubDate);
}
//content.delete();
if ( !form.istest ) {
content.save();
if ( !StructIsEmpty(content.getErrors()) ) {
ArrayAppend(errors, content.getErrors());
}
}
</cfscript>
<cfif form.istest>
<h4>#HTMLEditFormat(content.getValue('title'))#</h4>
<cfdump var="#i#" label="feed values" />
<cfdump var="#content.getAllValues()#" label="content" />
</cfif>
</cfloop>
<h3>Completed! <a href="#CGI.script_name##CGI.query_string#">Return to form &gt;</a></h3>
<cfif ArrayLen(errors)>
<h4>ERRORS</h4>
<cfdump var="#errors#" label="ERRORS" />
</cfif>
<cfelse>
<form name="frmSessions" method="post">
<label for="rssurl">RSS URL:</label>
<input type="text" name="rssurl" id="rssurl" value="#form.rssurl#" size="80" />
<label for="siteid">Site ID:</label>
<select name="siteid">
<cfloop query="rsSites">
<option value="#siteid#"<cfif form.siteid eq siteid> selected="selected"</cfif>>#HTMLEditFormat(site)#</option>
</cfloop>
</select>
<label for="parentfilename">Parent Filename:</label>
<input type="text" name="parentfilename" id="parentfilename" value="#form.parentfilename#" size="80" />
<label for="istest">Test?</label>
<select name="istest">
<option value="true"<cfif form.istest> selected="selected"</cfif>>Yes</option>
<option value="false"<cfif !form.istest> selected="selected"</cfif>>No</option>
</select>
<input type="hidden" name="isSubmitted" value="true" />
<p><input type="submit" value="Submit" /></p>
</form>
</cfif>
</div>
</body>
</html>
</cfoutput>
@manking109
Copy link

I get a No matching property [PERM] found in [string] at railo.runtime.reflection.Reflector.getGetter(Reflector.java:779): and maximal dump level reached when I use this. I use

[mura]$.dspInclude('site_custom/muraImportContentFromRSS.cfm')[/mura]

to put the file in a page expecting a form but just the error. Can you recommend something??

@stevewithington
Copy link
Author

@manking109,

Don't include this file into any content! This file is meant to be an example of how you could import content into Mura. You could take the file, create an actual directory in your file system called something like 'temp' or 'import' and then place this file in there as 'index.cfm' or something like that.

Then you should be able to navigate directly to that file such as http://yourdomain.com/import/index.cfm

Make sense?

@manking109
Copy link

Thanks that worked great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment