public
Created

Pagelime Page Listing using FTP-XML

  • Download Gist
get-page-list-for-folder.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
<?php
 
function pagesForFolder($folderName) {
$pages = array();
// this is the path to the sitemap XML that Pagelime publishes
$pages_path = "/cms-assets/xml/sitemap.xml";
// if the XML file exists, keep going
if (file_exists($_SERVER["DOCUMENT_ROOT"].$pages_path)) {
// initialize an XML DOM Document
$xml = new DOMDocument;
$xml->preserveWhiteSpace = false;
// load the sitemap XML file
if ($xml->load($_SERVER["DOCUMENT_ROOT"].$pages_path)) {
// prepare an XPath navigator. we'll use this to find the right folder
$xpath = new DOMXPath($xml);
// find the page IDs for the requested folder name using XPath
$entries = $xpath->query("/Folder/Folders/Folder[Name=\"$folderName\"]/Files/Page/PageID");
// we'll use this array counter to push new pages into the return object
$count = 0;
// loop through the page IDs
foreach ($entries as $entry) {
// create a new array / page object in the return array $pages
$pages[$count] = array();
// get the $page_id from the looped elements
$page_id = $entry->textContent;
// this is the derived path of the XML for the specific page, based off the ID
$page_id_path = "/cms-assets/xml/pages/$page_id.xml";
// if it exits
if (file_exists($_SERVER["DOCUMENT_ROOT"].$page_id_path)) {
// load it
$xmlForPage = new DOMDocument;
$xmlForPage->preserveWhiteSpace = false;
if ($xmlForPage->load($_SERVER["DOCUMENT_ROOT"].$page_id_path)) {
// now do some xpath magic to find the page description and title
$xpathForPage = new DOMXPath($xmlForPage);
$description = $xpathForPage->query('/Page/MetaData/PageMetaData[@Name="description"]')->item(0)->getAttribute("Content");
$pages[$count]["description"] = $description;
$title = $xpathForPage->query('/Page/Title')->item(0)->textContent;
$pages[$count]["title"] = $title;
}
}
// increment the counter
$count++;
}
}
}
// return the pages
return $pages;
}
 
?>
index.php
PHP
1 2 3 4 5 6 7 8 9 10
<?php require("get-page-list-for-folder.php") ?>
 
<!-- so this is a piece of code that lists the title and description -->
 
<div id="news_page_list">
<?php foreach(pagesForFolder("news") as $page) { ?>
<h1><?php echo $page["title"]; ?></h1>
<p><?php echo $page["description"]; ?></p>
<?php } ?>
</div>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.