Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Streda, 19. január 2022

Súbor: [Platon] / Metafox / rewrite.php (stiahnutie)

Revízia 1.2, Thu May 17 08:57:16 2012 UTC (9 years, 8 months ago) by igor

Zmeny od 1.1: +12 -0 [lines]

added case 'notfound' for rewrite

<?php

/*
 * Metafox - enterprise content management system
 *
 * rewrite.php - controller for mod_rewrite
 * ____________________________________________________________
 *
 * Developed by Igor Mino <igor@platon.sk>
 * Copyright (c) 2001-2012 Platon Group, http://platon.sk/
 * All rights reserved.
 *
 * See README file for more information about this software.
 * See COPYING file for license information.
 *
 * Download the latest version from
 * http://opensource.platon.sk/projects/Metafox/
 */

/*
 * Logical schema:
 * ----------------
 *
 * if (actual_url == first_type_url) { // index.php?ezin_section_id=name
 *      if (actual_type_url != config_type_url) {
 *           redirect to_config_type_url
 *      } else {
 *           continue actual_url
 *      }
 * }
 *
 * repeat this for second (section.php?name) and third (name/) type of URL
 *
 * Debug levels:
 * --------------
 *
 * 0  - auto redirect according actual configuration for Link redirect
 * 1  - temporary auto redirect (without 301, 302 or similar)
 * >1 - show only link (no redirect)
 *
 */

$link = $_GET['link'];
require_once 'cfgldr.inc.php';

$link_file_type = -1;

// type 0
if ($link == 'index.php'
    || strlen($link) <= 0)
{
    $link_file_type = 0;
    $setvars = array_keys($_GET);
    if ( $ezin_cfg['link_file_type'] != 0
        && $ezin_cfg['link_redirect'] > 0
        && (in_array('ezin_section_key', $setvars)
            || in_array('ezin_section_id', $setvars)
            || in_array('ezin_article_key', $setvars)
            || in_array('ezin_article_id', $setvars)
            || in_array('ezin_author_key', $setvars)
            || in_array('ezin_author_id', $setvars)
            || in_array('ezin_print', $setvars)
            || in_array('ezin_print', $setvars))
        )
    { // redirect
        ezin_cgi_parse();

        // section
        if (in_array('ezin_section_key', $setvars)) {
            ezin_redirect_section($_GET['ezin_section_key']);
        }
        if (in_array('ezin_section_id', $setvars)) {
            ezin_redirect_section($_GET['ezin_section_id']);
        }
        
        // article
        if (in_array('ezin_article_key', $setvars)
            && !in_array('ezin_print', $setvars))
        {
            ezin_redirect_article($_GET['ezin_article_key']);
        }
        if (in_array('ezin_article_id', $setvars)
            && !in_array('ezin_print', $setvars))
        {
            ezin_redirect_article($_GET['ezin_article_id']);
        }
        
        // author
        if (in_array('ezin_author_key', $setvars)) {
            ezin_redirect_author($_GET['ezin_author_key']);
        }
        if (in_array('ezin_author_id', $setvars)) {
            ezin_redirect_author($_GET['ezin_author_id']);
        }

        // print
        if (in_array('ezin_print', $setvars)) {
            if (isset($_GET['ezin_article_key'])) {
                ezin_redirect_print($_GET['ezin_article_key']);
            } else {
                ezin_redirect_print($_GET['ezin_article_id']);
            }
        }


    } else { // normal
        if (strlen($link) == 0) {
            $link = 'index.php';
        }
        require_once $link;
    }
}

// type 1
if (in_array($link, array('section.php', 'article.php', 'author.php', 'print.php'))) {
    $link_file_type = 1;
    if ( $ezin_cfg['link_file_type'] != 1
        && $ezin_cfg['link_redirect'] > 0)
    { // redirect
        ezin_cgi_parse();
        switch ($link) {
            case 'section.php':
                $section_id = Platon::parse_id_param();
                ezin_redirect_section($section_id);
                break;
            case 'article.php':
                $article_id = Platon::parse_id_param();
                ezin_redirect_article($article_id);
                break;
            case 'author.php':
                $author_id = Platon::parse_id_param();
                ezin_redirect_author($author_id);
                break;
            case 'print.php':
                $article_id = Platon::parse_id_param();
                ezin_redirect_print($article_id);
                break;

        }

    } else { // normal
        require_once $link;
    }
}

// type 2
if (strlen($link) > 0
    && strtolower(substr($link, -4)) != '.php')
{
    $link_file_type = 2;
    $args = explode('/', $link);
    //print_r($args);

    if ( $ezin_cfg['link_file_type'] != 2
        && $ezin_cfg['link_redirect'] > 0)
    { // redirect

        // section
        if (count($args) == 1
            && strlen($args[0]) > 0)
        {
            ezin_redirect_section($args[0]);
        }

        // others, default: article
        if (count($args) > 1
            && strlen($args[0]) > 0)
        {

            $showed = false;
            if (ezin_get_rewrite_key($args[0]) == 'author') {
                ezin_redirect_author($args[1]);
                $showed = true;
            }
            if (ezin_get_rewrite_key($args[0]) == 'print') {
                ezin_redirect_print($args[1]);
                $showed = true;
            }
            if (!$showed) {
                ezin_redirect_article($args[1]);
            }

        }
    
    } else { // normal

        // homepage
        if (count($args) <= 0
            || (count($args) == 1 && strlen($args[0]) == 0))
        {
            require_once 'index.php';
        }

        // section
        if (count($args) == 1
            && strlen($args[0]) > 0)
        {
            require_once 'cfgldr.inc.php';
            $ezin_cgi['query_string'][] = $args[0];
            $ezin_cgi['input'] = 'section';
            require_once 'index.php';
        }

        // others, default: article
        if (count($args) > 1
            && strlen($args[0]) > 0)
        {
            require_once 'cfgldr.inc.php';

            $showed = false;
            if (ezin_get_rewrite_key($args[0]) == 'author') {
                $ezin_cgi['query_string'][] = $args[1];
                $ezin_cgi['input'] = 'author';
                $showed = true;
            }
            if (ezin_get_rewrite_key($args[0]) == 'print') {
                $ezin_cgi['query_string'][] = $args[1];
                $ezin_cgi['input'] = 'print';
                $showed = true;
            }
            if (!$showed) {
                $ezin_cgi['query_string'][] = $args[1];
                $ezin_cgi['input'] = 'article';
            }

            require_once 'index.php';
        }
    }
    
}

// notfound
if ($link_file_type == -1) {
    require_once 'cfgldr.inc.php';
    $ezin_cgi['input'] = 'notfound';
    require_once 'index.php';
}

?>

Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok