<commit_before><?php
/*
 *	Lizzy - small and fast web-page rendering engine
 *
 *  SiteStructure
*/

class SiteStructure
{
	private $list = false;
	private $tree = false;
	public $currPage;
	public $prevPage = '';
	public $nextPage = '';
	public $currPageRec = false;
	public $config;
	private $noContent = false;

	//....................................................
	public function __construct($lzy, $currPage = false)
	{
	    $this->lzy = $lzy;
        $this->nextPage = '';
        $this->prevPage = '';

        $this->config = $config = $lzy->config;

		$this->site_sitemapFile = $config->site_sitemapFile;
		$this->currPage = $currPage;
		if (!$this->config->feature_sitemapFromFolders && !file_exists($this->site_sitemapFile)) {
			$this->currPageRec = array('folder' => '', 'name' => '');
			$this->list = false;
			return;
		}
		$this->site_enableCaching = $this->config->site_enableCaching;
		$this->cachePath = $this->config->cachePath; //'.#cache/';
		$this->cacheFile = $this->cachePath.'_siteStructure.dat';


		if (!$this->readCache()) {
            if ($config->feature_sitemapFromFolders) {
                $this->list = $this->getSitemapFromFolders();
            } else {
                $this->list = $this->getList();
            }
			$this->tree = $this->getTree();
            $this->propagateProperties();   // properties marked with ! -> propagate into branches, e.g. 'lang!'='fr'

			$this->writeCache();
		}

		$currNr = $this->findSiteElem($this->currPage);
		if ($currNr !== false) {
			$this->list[$currNr]['isCurrPage'] = true;
			$this->currPageRec = &$this->list[$currNr];
			$this->markParents();

		} else {    // requested page not found:
            $this->currPage = '_unknown/';
            $this->currPageRec = [
                'name' => 'Default',
                'level' => 0,
                'folder' => '_unknown/',
                'requestedFolder' => $currPage,
                'isCurrPage' => true,
                'inx' => '0',
                'urlExt' => '',
                'active' => false,
                'noContent' => false,
                'hide!' => false,
                'hasChildren' => false,
                'restricted' => false,
                'parent' => null
            ];
            return;
        }

		if ($currNr < (sizeof($this->list) - 1)) {
		    $i = 1;
		    while ($this->list[$currNr + $i]['hide!'] && (($currNr + $i) < (sizeof($this->list) - 1))) {
		        $i++;
            }
			$this->nextPage = $this->list[$currNr + $i]['folder'];
		}
		if ($currNr > 0) {
            $i = 1;
            while ($this->list[$currNr - $i]['hide!'] && (($currNr - $i) > 0)) {
                $i++;
            }
			$this->prevPage = $this->list[$currNr - $i]['folder'];
		}
	} // __construct



	//....................................................
	public function getSiteList() {
		return $this->list;
	} // getSiteList



	//....................................................
	public function getSiteTree() {
		return $this->tree;
	} // getSiteTree




    //....................................................
    private function getSitemapFromFolders() {
        $list = array();
        $i = 0;<commit_msg>bugfix: prevPage and nextPage - needs to take into account empty and hidden pages - empty foldername to be distinguished from non-existing (as in prev of home)<commit_after><?php
/*
 *	Lizzy - small and fast web-page rendering engine
 *
 *  SiteStructure
*/

class SiteStructure
{
	private $list = false;
	private $tree = false;
	public $currPage;
	public $prevPage = '';
	public $nextPage = '';
	public $currPageRec = false;
	public $config;
	private $noContent = false;

	//....................................................
	public function __construct($lzy, $currPage = false)
	{
	    $this->lzy = $lzy;
        $this->nextPage = false;
        $this->prevPage = false;

        $this->config = $config = $lzy->config;

		$this->site_sitemapFile = $config->site_sitemapFile;
		$this->currPage = $currPage;
		if (!$this->config->feature_sitemapFromFolders && !file_exists($this->site_sitemapFile)) {
			$this->currPageRec = array('folder' => '', 'name' => '');
			$this->list = false;
			return;
		}
		$this->site_enableCaching = $this->config->site_enableCaching;
		$this->cachePath = $this->config->cachePath; //'.#cache/';
		$this->cacheFile = $this->cachePath.'_siteStructure.dat';


		if (!$this->readCache()) {
            if ($config->feature_sitemapFromFolders) {
                $this->list = $this->getSitemapFromFolders();
            } else {
                $this->list = $this->getList();
            }
			$this->tree = $this->getTree();
            $this->propagateProperties();   // properties marked with ! -> propagate into branches, e.g. 'lang!'='fr'

			$this->writeCache();
		}

		$currNr = $this->findSiteElem($this->currPage);
		if ($currNr !== false) {
			$this->list[$currNr]['isCurrPage'] = true;
			$this->currPageRec = &$this->list[$currNr];
			$this->markParents();

		} else {    // requested page not found:
            $this->currPage = '_unknown/';
            $this->currPageRec = [
                'name' => 'Default',
                'level' => 0,
                'folder' => '_unknown/',
                'requestedFolder' => $currPage,
                'isCurrPage' => true,
                'inx' => '0',
                'urlExt' => '',
                'active' => false,
                'noContent' => false,
                'hide!' => false,
                'hasChildren' => false,
                'restricted' => false,
                'parent' => null
            ];
            return;
        }

		if ($currNr < (sizeof($this->list) - 1)) {
		    $i = 1;
		    while ($this->list[$currNr + $i]['hide!'] && (($currNr + $i) < (sizeof($this->list) - 1))) {
		        $i++;
            }
			$this->nextPage = $this->list[$currNr + $i]['folder'];
		}
		if ($currNr > 0) {
            $i = 1;
            $j = $currNr - $i;
            while (($j > 0) && ($this->list[$j]['hide!'] || $this->list[$j]['noContent'])) {
                $i++;
                $j = $currNr - $i;
            }
            if ($j >= 0) {
                $this->prevPage = $this->list[$j]['folder'];
            } else {
                $this->prevPage = false;
            }
		}
	} // __construct



	//....................................................
	public function getSiteList() {
		return $this->list;
	} // getSiteList



	//....................................................
	public function getSiteTree() {
		return $this->tree;
	} // getSiteTree




    //....................................................
    private function getSitemapFromFolders() {
        $list = array();
        $i = 0;
{'fraction_non_alphanumeric': 0.2359416840226123, 'fraction_numerical': 0.002826539720321333, 'mean_word_length': 1.6699761715647339, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 140, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '320928', 'n_tokens_mistral': 2226, 'n_tokens_neox': 2045, 'n_words': 395}