First time posting any mods, so please check results on your sites. These changes worked for me while retaining original function of version 1.0.8.
I wanted a way to see through unpublished docs like mentioned here before. I have active docs to display that weren’t. This patch adds a new paramater similar to ditto called &seeThruUnpub that will do exactly that - see through the unpublished docs for active docs. By active, I was looking for published but not deleted. I am sure there is a better way to do this, but this works. The patch updates the notes at the top but not the version number completely. I added an ’a’ to a couple of places so I could identify what I was doing or if I had my modified version in place.
Also makes a small change to not display the alias name or site_url if the doc id is the same as the site_start id. Cleans up display of homepage link.
--- sitemap.orig 2009-07-24 11:17:16.000000000 -0700
+++ sitemap.new 2009-07-24 11:46:48.000000000 -0700
@@ -20,6 +20,11 @@
MODx: 0.9.2.1, 0.9.6.1
History:
+# 1.0.8a
+- Added ability to see through unpublished docs to find active documents. Added new parameter similar to the ditto
+ call, &seeThruUnpub. Useful if you use documents as containers but don't publish the containers.
+- Added fix pointed out in comments for the home page URL. Checks the site start id and leaves off the alias portion
+ if the current document is the home page. From comment by Urban on 05-28-09
# 1.0.8
- excludeTemplates can now also be specified as a template ID instead of template name.
Useful if you change the names of your templates frequently. (ncrossland)
@@ -129,12 +134,19 @@
$excludeWeblinks = (isset($excludeWeblinks)) ? $excludeWeblinks : false;
+# $seeThruUnpub [ bool ]
+# Should we look into unpublished folders to published content?
+# You may want to include documents that are contained inside unpublished containers
+# By default, these are ignored.
+# Default: false
+$seeThruUnpub = (isset($seeThruUnpub)) ? $seeThruUnpub : false;
+
/* End parameters
----------------------------------------------- */
# get list of documents
# ---------------------------------------------
-$docs = getDocs($modx,$startid,$priority,$changefreq,$excludeTV);
+$docs = getDocs($modx,$startid,$priority,$changefreq,$excludeTV,$seeThruUnpub);
# filter out documents by template or TV
@@ -221,7 +233,7 @@
foreach ($docs as $doc) {
- $url = '[(site_url)][~'.$doc['id'].'~]';
+ $url = ( $doc['id'] == $modx->config['site_start'] ) ? '[(site_url)]' : '[(site_url)][~'.$doc['id'].'~]';
$date = $doc['editedon'];
$date = date("Y-m-d", $date);
$docPriority = ($doc[$priority]) ? $doc[$priority] : 0; // false if TV doesn't exist
@@ -270,21 +282,50 @@
}
# gets list of published documents with properties
-function getDocs($modx,$startid,$priority,$changefreq,$excludeTV)
+function getDocs($modx,$startid,$priority,$changefreq,$excludeTV,$seeThruUnpub=false)
{
+ $activeDocs = array();
// get children documents
- $docs = $modx->getActiveChildren($startid,'menuindex','asc','id,editedon,template,published,searchable,pagetitle,type');
+ if ($seeThruUnpub)
+ {
+ $docs = $modx->getAllChildren($startid,'menuindex','asc','id,editedon,template,published,searchable,pagetitle,type,deleted');
+ //We will determine if we are going to write or not later
+ $writeDoc = false;
+ } else {
+ $docs = $modx->getActiveChildren($startid,'menuindex','asc','id,editedon,template,published,searchable,pagetitle,type');
+ //Since we are only dealing with Active Docs, safe to write them all
+ $writeDoc = true;
+ }
// add sub-children to the list
foreach ($docs as $key => $doc)
{
+ if ($seeThruUnpub) {
+ //Its possible we are looking at an unpublished document
+ if ($doc['published'] && !($doc['deleted'])) {
+ // Doc is published and is not deleted, so we want to add it to array
+ $writeDoc = true;
+ } else {
+ // Doc was not published or was deleted or something else we didn't want so go to next doc
+ $writeDoc = false;
+ }
+ }
$id = $doc['id'];
- $docs[$key][$priority] = getTV($modx,$id,$priority); // add priority property
- $docs[$key][$changefreq] = getTV($modx,$id,$changefreq); // add changefreq property
- $docs[$key][$excludeTV] = getTV($modx,$id,$excludeTV); // add excludeTV property
-
- if ($modx->getActiveChildren($id))
- $docs = array_merge($docs, getDocs($modx,$id,$priority,$changefreq,$excludeTV));
+ if ($writeDoc) {
+ # If here, we have a valid active document
+ $activeDocs[$key] = $doc;
+ $activeDocs[$key][$priority] = getTV($modx,$id,$priority); // add priority property
+ $activeDocs[$key][$changefreq] = getTV($modx,$id,$changefreq); // add changefreq property
+ $activeDocs[$key][$excludeTV] = getTV($modx,$id,$excludeTV); // add excludeTV property
+ }
+ //Check to see if this Doc has any children...
+ if ($seeThruUnpub) {
+ if ($modx->getAllChildren($id))
+ $activeDocs = array_merge($activeDocs, getDocs($modx,$id,$priority,$changefreq,$excludeTV,$seeThruUnpub));
+ } else {
+ if ($modx->getActiveChildren($id))
+ $activeDocs = array_merge($activeDocs, getDocs($modx,$id,$priority,$changefreq,$excludeTV,$seeThruUnpub));
+ }
} // end foreach
- return $docs;
+ return $activeDocs;
}
?>
Added attachment of the patch as well.