Location: PHPKode > scripts > Noostr > _engine/classes/Page.php
<?php defined('SYSPATH') OR die('No direct access to this file is allowed.');
/**
 * Holds all page-related information, from content to security context.
 *
 * @package Noostr
 * @subpackage Classes
 */

class Page {
	private $data = array();		// all content data
	private $current;			// current page name
	public $id;				// current page uid
	public $roleid;				// current page ACL role

	public function __construct($pagename) {
		global $db;
		$this->current = $pagename;
		$query = 'select uid, pid, tid, created, displayorder, url, title, excerpt, roleid, type, showAlways from '.PREFIX.'pages where roleid != ? order by type, pid, displayorder, title';
		$this->load($db->query($query, ''));
		$this->id = $this->get($pagename, 'uid');
		$this->roleid = $this->get($pagename, 'roleid');
	}

	public function load($array) {
		$this->data = $array;
	}
	public function get_pages($type = 'page', $pid = '') {
		$return = null;
		for ($i = 0, $c = count($this->data); $i < $c; $i++) {
			if ($this->data[$i]['type'] == $type) {
				if ($this->data[$i]['pid'] == $pid) {
					$return[$this->data[$i]['uid']] = $this->get_pages($type, $this->data[$i]['uid']);
				}
			}
		}
		if (!isset($return)) {
			$return = false;
		}
		return $return;
	}
	private function show_pages_int($pages, $type, $pre, $post, $precurrent, $postcurrent) {
		global $acl, $user;
		$return = '';
		if (!is_array($pages)) {
			$pages = array($pages);
		}
		foreach ($pages as $index => $page) {
			$bshow = false;
			if ($this->find('uid', $index, 'type') == $type) {
				// check "role" and "showAlways"!
				if ($this->find('uid', $index, 'showAlways')) {
					$bshow = true;
				} else {
					if ($acl->canSee($this->find('uid', $index, 'roleid'), $user->roleid)) {
						$bshow = true;
						if ($this->find('uid', $index, 'roleid') == $acl->anon && !$this->find('uid', $index, 'showAlways')) {
							if ($user->roleid != $acl->anon) {
								$bshow = false;
							}
						}
					}
				}
				if ($bshow) {
					if ($this->get(strtolower($this->current), 'uid') == $index) {
						$return .= $precurrent;
					} else {
						$return .= $pre;
					}
					$return .= '<a href="'.$this->find('uid', $index, 'url').'">'.$this->find('uid', $index, 'title').'</a>';
					if (is_array($page)) {
						$return .= '<ul>'.$this->show_pages_int($page, $pre, $post, $precurrent, $postcurrent).'</ul>';
					}
					if ($this->get(strtolower($this->current), 'uid') == $index) {
						$return .= $postcurrent;
					} else {
						$return .= $post;
					}
				}
			}
		}
		return $return;
	}
	public function show_pages($pre = '<li class="page-item">', $post = '</li>', $precurrent = '<li class="page-item current-page-item">', $postcurrent = '</li>') {
		echo $this->show_pages_int($this->get_pages('page'), 'page', $pre, $post, $precurrent, $postcurrent);
	}
	public function show_meta($pre = '<li class="meta-item">', $post = '</li>', $precurrent = '<li class="meta-item current-meta-item">', $postcurrent = '</li>') {
		echo $this->show_pages_int($this->get_pages('meta'), 'meta', $pre, $post, $precurrent, $postcurrent);
	}
	public function set($type, $value, $node, $set) {
		$return = '';
		if (is_array($this->data)) {
			for ($i = 0, $c = count($this->data); $i < $c; $i++) {
				if (array_key_exists($type, $this->data[$i])) {
					if ($this->data[$i][$type] == $value || $this->data[$i][$type] == '/'.$value) {
						$this->data[$i][$node] = $set;
					}
				}
			}
		}
		return $return;
	}
	public function find($type, $value, $item) {
		$return = '';
		if (is_array($this->data)) {
			for ($i = 0, $c = count($this->data); $i < $c; $i++) {
				if (array_key_exists($type, $this->data[$i])) {
					if ($this->data[$i][$type] == $value) {
						if (array_key_exists($item, $this->data[$i])) {
							$return = $this->data[$i][$item];
						}
					}
				}
			}
		}
		return $return;
	}
	public function get($url, $item) {
		$return = $this->find('url', '/'.$url, $item);
		return $return;
	}
	public function show($url, $item) {
		echo $this->get($url, $item);
	}
	public function show_content() {
		global $db;
		$t = $this->get($this->current, 'description');
		if ($t == '') {
			$content = array();
			$content = $db->query('select description from '.PREFIX.'pages where uid = ?', $this->get($this->current, 'uid'));
			if (isset($content[0]['description'])) {
				$this->set('url', $this->current, 'description', $content[0]['description']);
				$t = $content[0]['description'];
			}
		}
		$t .= "\n";
		$t = json_encode($t);
		$t = gzcompress($t, 6);
		$t = gzuncompress($t);
		$t = json_decode($t, true);
		echo $t;
	}

	public function tpl_getinfo($admin = false) {
		for ($i = 0, $c = count($this->data); $i < $c; $i++){
			if ($admin) {
				return $this->data;
			} else {
				if ($this->data[$i]['uid'] == $this->id) {
					return $this->data[$i];
				}
			}
		}
	}
}
Return current item: Noostr