Source for file web_page.class.php
Documentation is available at web_page.class.php
// *** Tangra (Application Framework and Tools for PHP)
* Contains class Web_Page
require_once(TANGRA_MAIN_DIR. 'web_site/web_ctrl.class.php');
require_once('web_page_view.class.php');
require_once('just_headers_view.class.php');
require_once(TANGRA_MAIN_DIR. 'exceptions/te_web_page_view_not_exists.class.php');
require_once(TANGRA_MAIN_DIR. 'exceptions/te_web_page_view_already_exists.class.php');
* Class Web_Page represents the abstract concept of web page
* Views for this page. Array of Web_Page_View
* current URL of the page
* @param string $page_name
* @param Web_Context $context
* @param Web_Site_Config $config
public function _init(Web_Context $context, Web_Site_Config $config) {
parent::_init($context, $config);
* @param string $page_name
* @throws Tangra_Exception
* @throws Tangra_Exception
if (ereg("^[a-z]{1}[a-z0-9_/\\]{0,100}$", $page_name)) {
throw new Tangra_Exception('Invalid page name ($page_name). Must conform ^[a-z]{1}[a-z0-9_/\\]{1,100}[a-z0-9_]{1}$. Current value: '. $page_name);
* @param Web_Page_View $page_view
* @throws TE_Web_Page_View_Already_Exists
protected function add_view(Web_Page_View $page_view) {
$this->views[$page_view->get_name()] = $page_view;
throw new TE_Web_Page_View_Already_Exists($page_view->get_name());
* @param string $name Name of the view
* @throws TE_Web_Page_View_Not_Exists
protected function get_view($name = 'default') {
$ret = $this->views[$name];
throw new TE_Web_Page_View_Not_Exists($name);
* Captures current URL from context
$script_name = $context->get_from_server('SCRIPT_NAME');
$relative_docroot = $config->get_document_root_relative();
* Creates and returns Just_Headers_View with redirect (Location: ) header
* If $target starts with "http" redirect will be with absolute URL, otherwise will be relative URL.
* Please note that $params_pairs will be merged with existing (if any) transit variables.
* @param stirng $target_location target page to redirect to. Example: 'admin/index.php'
* @param array $param_pairs key => value pairs of parameters that will be added to redirect. Example: array('confirmed' => 1)
* @throws Tangra_Exception
$target_location = trim($target_location);
$redir_view->add_http_header($redir->get_location());
throw new Tangra_Exception('$target is empty or invalid.');
* Detects referer (if local) and exports it as _uni_back
* Useful for creating back links that work the same way as browser window but with _tm variable set correctly (if available).
$parsed_url = parse_url($_SERVER['HTTP_REFERER']);
if ($parsed_url['host'] == $config->get_current_host()) {
// $lang_pos = strpos($parsed_url['path'], '_lang-');
// if ($lang_pos !== false) {
// $parsed_url['path'] = substr($parsed_url['path'], 0, $lang_pos -1);
if ($parsed_url['query']) {
$tm_pos = strpos($parsed_url['query'], '&_tm=');
$tm_full = substr($parsed_url['query'], $tm_pos, 37);
$parsed_url['query'] = str_replace($tm_full, '', $parsed_url['query']);
$parsed_url['query'] = '';
$this->export('_uni_back', $parsed_url['path']. ($parsed_url['query'] ? '?'. $parsed_url['query'] : ''));
* End classes must implement this function and it must be used always for creating views (i.e. no new Some_View())
abstract public function create_view($name = 'default');
|