/** * Get Page Children - returns multi fields * * Return an Array of pages that are children of the requested page/slug with optional fields. * * @since 3.1 * @param $page - slug of the page to retrieve content * @param options - array of optional fields to return * * @returns - Array of slug names and optional fields. * */ function getChildrenMulti($page, $options = array()) { $pagesArray = getPagesXmlValues(); $count = 0; $returnArray = array(); foreach ($pagesArray as $key => $value) { if ($pagesArray[$key]['parent'] == $page) { $returnArray[$count] = array(); $returnArray[$count]['url'] = $key; foreach ($options as $option) { $returnArray[$count][$option] = returnPageField($key, $option); } $count++; } } return $returnArray; }
/** * Get Cached Pages XML Values * * Loads the Cached XML data into the Array $pagesArray * If the file does not exist it is created the first time. * * @since 3.1 * */ function getPagesXmlValues($chkcount = false) { global $pagesArray; // debugLog(__FUNCTION__.": chkcount - " .(int)$chkcount); // if page cache not load load it if (!$pagesArray) { $pagesArray = array(); $file = GSDATAOTHERPATH . "pages.xml"; if (file_exists($file)) { // load the xml file and setup the array. // debugLog(__FUNCTION__.": load pages.xml"); $thisfile = file_get_contents($file); $data = simplexml_load_string($thisfile); $pages = $data->item; foreach ($pages as $page) { $key = $page->url; $pagesArray[(string) $key] = array(); foreach ($page->children() as $opt => $val) { $pagesArray[(string) $key][(string) $opt] = (string) $val; } } } else { // no page cache, regen and then load it // debugLog(__FUNCTION__.": pages.xml not exist"); if (create_pagesxml(true)) { getPagesXmlValues(false); } return; } } // if checking cache sync, regen cache if pages differ. if ($chkcount == true) { $path = GSDATAPAGESPATH; $dir_handle = @opendir($path) or die("getPageXmlValues: Unable to open {$path}"); $filenames = array(); while ($filename = readdir($dir_handle)) { $ext = substr($filename, strrpos($filename, '.') + 1); if ($ext == "xml") { $filenames[] = $filename; } } if (count($pagesArray) != count($filenames)) { // debugLog(__FUNCTION__.": count differs regen pages.xml"); if (create_pagesxml(true)) { getPagesXmlValues(false); } } } }
$newxml->title = $newxml->title . ' [' . i18n_r('COPY') . ']'; $newxml->pubDate = date('r'); $status = XMLsave($newxml, $path . $newurl . '.xml'); if ($status) { create_pagesxml('true'); header('Location: pages.php?upd=clone-success&id=' . $newurl); } else { $error = sprintf(i18n_r('CLONE_ERROR'), $_GET['id']); header('Location: pages.php?error=' . $error); } } else { $error = sprintf(i18n_r('CLONE_ERROR'), $_GET['id']); header('Location: pages.php?error=' . $error); } } getPagesXmlValues(); $count = 0; foreach ($pagesArray as $page) { if ($page['parent'] != '') { $parentdata = getXML(GSDATAPAGESPATH . $page['parent'] . '.xml'); $parentTitle = $parentdata->title; $sort = $parentTitle . ' ' . $page['title']; } else { $sort = $page['title']; } $page = array_merge($page, array('sort' => $sort)); $pagesArray_tmp[$count] = $page; $count++; } $pagesArray = $pagesArray_tmp; $pagesSorted = subval_sort($pagesArray, 'sort');
/** * Get Cached Pages XML Values * * Loads the Cached XML data into the Array $pagesArray * If the file does not exist it is created the first time. * * @since 3.1 * */ function getPagesXmlValues($chkcount = true) { global $pagesArray; $pagesArray = array(); $file = GSDATAOTHERPATH . "pages.xml"; if (file_exists($file)) { // load the xml file and setup the array. $thisfile = file_get_contents($file); $data = simplexml_load_string($thisfile); $pages = $data->item; foreach ($pages as $page) { $key = $page->url; $pagesArray[(string) $key] = array(); foreach ($page->children() as $opt => $val) { $pagesArray[(string) $key][(string) $opt] = (string) $val; } } $path = GSDATAPAGESPATH; $dir_handle = @opendir($path) or die("Unable to open {$path}"); $filenames = array(); while ($filename = readdir($dir_handle)) { $ext = substr($filename, strrpos($filename, '.') + 1); if ($ext == "xml") { $filenames[] = $filename; } } if ($chkcount == true) { if (count($pagesArray) != count($filenames)) { create_pagesxml('true'); getPagesXmlValues(false); } } } else { create_pagesxml(true); getPagesXmlValues(false); } }
$newxml->title = $newxml->title . ' [' . i18n_r('COPY') . ']'; $newxml->pubDate = date('r'); $status = XMLsave($newxml, $path . $newurl . '.xml'); if ($status) { create_pagesxml('true'); header('Location: pages.php?upd=clone-success&id=' . $newurl); } else { $error = sprintf(i18n_r('CLONE_ERROR'), $_GET['id']); header('Location: pages.php?error=' . $error); } } else { $error = sprintf(i18n_r('CLONE_ERROR'), $_GET['id']); header('Location: pages.php?error=' . $error); } } getPagesXmlValues(true); $count = 0; foreach ($pagesArray as $page) { if ($page['parent'] != '') { $parentTitle = returnPageField($page['parent'], "title"); $sort = $parentTitle . ' ' . $page['title']; $sort = $parentTitle . ' ' . $page['title']; } else { $sort = $page['title']; } $page = array_merge($page, array('sort' => $sort)); $pagesArray_tmp[$count] = $page; $count++; } // $pagesArray = $pagesArray_tmp; $pagesSorted = subval_sort($pagesArray_tmp, 'sort');
/** * Creates Sitemap * * Creates GSSITEMAPFILE (sitemap.xml) in the site's root. */ function generate_sitemap() { if (getDef('GSNOSITEMAP', true)) { return; } global $pagesArray; // Variable settings $SITEURL = getSiteURL(true); $path = GSDATAPAGESPATH; getPagesXmlValues(false); $pagesSorted = subval_sort($pagesArray, 'menuStatus'); if (count($pagesSorted) > 0) { $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset></urlset>'); $xml->addAttribute('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd', 'http://www.w3.org/2001/XMLSchema-instance'); $xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); foreach ($pagesSorted as $page) { if ($page['url'] != '404') { if ($page['private'] != 'Y') { // set <loc> $pageLoc = find_url($page['url'], $page['parent'], 'full'); // set <lastmod> $tmpDate = date("Y-m-d H:i:s", strtotime($page['pubDate'])); $pageLastMod = makeIso8601TimeStamp($tmpDate); // set <changefreq> $pageChangeFreq = 'weekly'; // set <priority> if ($page['menuStatus'] == 'Y') { $pagePriority = '1.0'; } else { $pagePriority = '0.5'; } //add to sitemap $url_item = $xml->addChild('url'); $url_item->addChild('loc', $pageLoc); $url_item->addChild('lastmod', $pageLastMod); $url_item->addChild('changefreq', $pageChangeFreq); $url_item->addChild('priority', $pagePriority); } } } //create xml file $file = GSROOTPATH . GSSITEMAPFILE; $xml = exec_filter('sitemap', $xml); // @filter sitemap (obj) filter the sitemap $xml obj $status = XMLsave($xml, $file); exec_action('sitemap-aftersave'); // @hook sitemap-aftersave after a sitemap data file was saved #sitemap successfully created return $status; } else { return true; } }
private function dropdown_pages() { getPagesXmlValues(); global $pagesArray; $pages = $pagesArray; ?> <select class="text" <?php echo $this->properties; ?> > <?php foreach ($pages as $slug => $properties) { ?> <option value="<?php echo $slug; ?> " <?php if ($slug == $this->value) { echo 'selected="selected"'; } ?> ><?php echo $properties['title']; ?> </option> <?php } ?> </select> <?php }
/** * Creates Sitemap * * Creates sitemap.xml in the site's root. */ function generate_sitemap() { if (getDef('GSNOSITEMAP', true)) { return; } // Variable settings global $SITEURL; $path = GSDATAPAGESPATH; global $pagesArray; getPagesXmlValues(false); $pagesSorted = subval_sort($pagesArray, 'menuStatus'); if (count($pagesSorted) != 0) { $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset></urlset>'); $xml->addAttribute('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd', 'http://www.w3.org/2001/XMLSchema-instance'); $xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); foreach ($pagesSorted as $page) { if ($page['url'] != '404') { if ($page['private'] != 'Y') { // set <loc> $pageLoc = find_url($page['url'], $page['parent']); // set <lastmod> $tmpDate = date("Y-m-d H:i:s", strtotime($page['pubDate'])); $pageLastMod = makeIso8601TimeStamp($tmpDate); // set <changefreq> $pageChangeFreq = 'weekly'; // set <priority> if ($page['menuStatus'] == 'Y') { $pagePriority = '1.0'; } else { $pagePriority = '0.5'; } //add to sitemap $url_item = $xml->addChild('url'); $url_item->addChild('loc', $pageLoc); $url_item->addChild('lastmod', $pageLastMod); $url_item->addChild('changefreq', $pageChangeFreq); $url_item->addChild('priority', $pagePriority); } } } //create xml file $file = GSROOTPATH . 'sitemap.xml'; $xml = exec_filter('sitemap', $xml); XMLsave($xml, $file); exec_action('sitemap-aftersave'); } if (!defined('GSDONOTPING')) { if (file_exists(GSROOTPATH . 'sitemap.xml')) { if (200 === ($status = pingGoogleSitemaps($SITEURL . 'sitemap.xml'))) { #sitemap successfully created & pinged return true; } else { error_log(i18n_r('SITEMAP_ERRORPING')); return i18n_r('SITEMAP_ERRORPING'); } } else { error_log(i18n_r('SITEMAP_ERROR')); return i18n_r('SITEMAP_ERROR'); } } else { #sitemap successfully created - did not ping return true; } }