예제 #1
0
/**
 * router
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Center
 * @author Henry Ruhs
 */
function router()
{
    $firstParameter = Redaxscript\Registry::get('firstParameter');
    $secondParameter = Redaxscript\Registry::get('secondParameter');
    $thirdParameter = Redaxscript\Registry::get('thirdParameter');
    $thirdSubParameter = Redaxscript\Registry::get('thirdSubParameter');
    $config = Redaxscript\Config::getInstance();
    Redaxscript\Hook::trigger('routerStart');
    if (Redaxscript\Registry::get('routerBreak')) {
        return;
    }
    /* check token */
    $messenger = new Redaxscript\Messenger(Redaxscript\Registry::getInstance());
    if ($_POST && $_POST['token'] != Redaxscript\Registry::get('token')) {
        echo $messenger->setRoute(Redaxscript\Language::get('home'), Redaxscript\Registry::get('root'))->error(Redaxscript\Language::get('token_incorrect'), Redaxscript\Language::get('error_occurred'));
        return;
    }
    /* install routing */
    if (Redaxscript\Registry::get('file') === 'install.php' && $config->get('env') !== 'production') {
        if (Redaxscript\Request::getPost('Redaxscript\\View\\InstallForm')) {
            $installController = new Redaxscript\Controller\Install(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance(), Redaxscript\Request::getInstance(), Redaxscript\Config::getInstance());
            echo $installController->process();
            return;
        } else {
            $systemStatus = new Redaxscript\View\SystemStatus(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance());
            $installForm = new Redaxscript\View\InstallForm(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance());
            echo $systemStatus->render() . $installForm->render();
            return;
        }
    }
    /* general routing */
    $post_list = ['Redaxscript\\View\\LoginForm' => 'Redaxscript\\Controller\\Login', 'Redaxscript\\View\\RegisterForm' => 'Redaxscript\\Controller\\Register', 'Redaxscript\\View\\ResetForm' => 'Redaxscript\\Controller\\Reset', 'Redaxscript\\View\\RecoverForm' => 'Redaxscript\\Controller\\Recover', 'Redaxscript\\View\\CommentForm' => 'Redaxscript\\Controller\\Comment'];
    foreach ($post_list as $key => $value) {
        if (Redaxscript\Request::getPost($key)) {
            if (class_exists($value)) {
                $controller = new $value(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance(), Redaxscript\Request::getInstance());
                echo $controller->process();
            }
            return;
        }
    }
    /* search routing */
    if (Redaxscript\Request::getPost('Redaxscript\\View\\SearchForm')) {
        $messenger = new Redaxscript\Messenger(Redaxscript\Registry::getInstance());
        $table = Redaxscript\Request::getPost('table');
        if ($table) {
            $table = '/' . $table;
        }
        echo $messenger->setRoute(Redaxscript\Language::get('continue'), 'search' . $table . '/' . Redaxscript\Request::getPost('search'))->doRedirect(0)->success(Redaxscript\Language::get('search'));
    }
    /* parameter routing */
    switch ($firstParameter) {
        case 'admin':
            if (Redaxscript\Registry::get('loggedIn') == Redaxscript\Registry::get('token')) {
                admin_router();
            } else {
                echo $messenger->setRoute(Language::get('login'), 'login')->error(Language::get('access_no'), Language::get('error_occurred'));
            }
            return;
        case 'login':
            switch ($secondParameter) {
                case 'recover':
                    if (Redaxscript\Db::getSetting('recovery') == 1) {
                        $recoverForm = new Redaxscript\View\RecoverForm(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance());
                        echo $recoverForm->render();
                        return;
                    }
                case 'reset':
                    if (Redaxscript\Db::getSetting('recovery') == 1 && $thirdParameter && $thirdSubParameter) {
                        $resetForm = new Redaxscript\View\ResetForm(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance());
                        echo $resetForm->render();
                        return;
                    }
                    /* show error */
                    echo $messenger->setRoute(Language::get('login'), 'login')->error(Language::get('access_no'), Language::get('error_occurred'));
                    return;
                default:
                    $loginForm = new Redaxscript\View\LoginForm(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance());
                    echo $loginForm->render();
                    return;
            }
        case 'logout':
            if (Redaxscript\Registry::get('loggedIn') == Redaxscript\Registry::get('token')) {
                $logoutController = new Redaxscript\Controller\Logout(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance(), Redaxscript\Request::getInstance());
                echo $logoutController->process();
                return;
            }
            /* show error */
            echo $messenger->setRoute(Language::get('login'), 'login')->error(Language::get('access_no'), Language::get('error_occurred'));
            return;
        case 'register':
            if (Redaxscript\Db::getSetting('registration')) {
                $registerForm = new Redaxscript\View\RegisterForm(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance());
                echo $registerForm->render();
                return;
            }
            /* show error */
            echo $messenger->setRoute(Language::get('home'), Redaxscript\Registry::get('root'))->error(Language::get('access_no'), Language::get('error_occurred'));
            return;
        case 'search':
            $searchController = new Redaxscript\Controller\Search(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance(), Redaxscript\Request::getInstance());
            echo $searchController->process();
            return;
        default:
            contents();
            return;
    }
    Redaxscript\Hook::trigger('routerEnd');
}
예제 #2
0
/**
 * contents
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Contents
 * @author Henry Ruhs
 */
function contents()
{
    $output = Redaxscript\Hook::trigger('contentStart');
    $aliasValidator = new Redaxscript\Validator\Alias();
    $lastId = Redaxscript\Registry::get('lastId');
    $lastTable = Redaxscript\Registry::get('lastTable');
    $categoryId = Redaxscript\Registry::get('categoryId');
    $articleId = Redaxscript\Registry::get('articleId');
    $firstParameter = Redaxscript\Registry::get('firstParameter');
    /* query articles */
    $articles = Redaxscript\Db::forTablePrefix('articles')->where('status', 1);
    $articles->whereLanguageIs(Redaxscript\Registry::get('language'));
    /* handle sibling */
    if ($lastId) {
        $sibling = Redaxscript\Db::forTablePrefix($lastTable)->where('id', $lastId)->findOne()->sibling;
        /* query sibling collection */
        $sibling_array = Redaxscript\Db::forTablePrefix($lastTable)->whereIn('sibling', [$lastId, $sibling > 0 ? $sibling : null])->where('language', Redaxscript\Registry::get('language'))->select('id')->findFlatArray();
        /* process sibling array */
        foreach ($sibling_array as $value) {
            $id_array[] = $value;
        }
    }
    /* handle article */
    if ($articleId) {
        $id_array[] = $sibling;
        $id_array[] = $articleId;
        $articles->whereIn('id', $id_array);
    } else {
        if ($categoryId) {
            if (!$id_array) {
                if ($sibling > 0) {
                    $id_array[] = $sibling;
                } else {
                    $id_array[] = $categoryId;
                }
            }
            $articles->whereIn('category', $id_array)->orderGlobal('rank');
            /* handle sub parameter */
            $result = $articles->findArray();
            if ($result) {
                $num_rows = count($result);
                $sub_maximum = ceil($num_rows / Redaxscript\Db::getSetting('limit'));
                $sub_active = Redaxscript\Registry::get('lastSubParameter');
                /* sub parameter */
                if (Redaxscript\Registry::get('lastSubParameter') > $sub_maximum || !Redaxscript\Registry::get('lastSubParameter')) {
                    $sub_active = 1;
                } else {
                    $offset_string = ($sub_active - 1) * Redaxscript\Db::getSetting('limit') . ', ';
                }
            }
            $articles->limit($offset_string . Redaxscript\Db::getSetting('limit'));
        } else {
            $articles->limit(0);
        }
    }
    /* query result */
    $result = $articles->findArray();
    $num_rows_active = count($result);
    /* handle error */
    if ($categoryId && !$num_rows) {
        $error = Redaxscript\Language::get('article_no');
    } else {
        if (!$result || !$num_rows_active || Redaxscript\Registry::get('contentError')) {
            $error = Redaxscript\Language::get('content_not_found');
        } else {
            if ($result) {
                $accessValidator = new Redaxscript\Validator\Access();
                foreach ($result as $r) {
                    $access = $r['access'];
                    /* access granted */
                    if ($accessValidator->validate($access, Redaxscript\Registry::get('myGroups')) === Redaxscript\Validator\ValidatorInterface::PASSED) {
                        if ($r) {
                            foreach ($r as $key => $value) {
                                ${$key} = $value;
                            }
                        }
                        if ($lastTable == 'categories' || !Redaxscript\Registry::get('fullRoute') || $aliasValidator->validate($firstParameter, Redaxscript\Validator\Alias::MODE_DEFAULT) == Redaxscript\Validator\ValidatorInterface::PASSED) {
                            $route = build_route('articles', $id);
                        }
                        /* parser */
                        $parser = new Redaxscript\Parser(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance());
                        $parser->init($text, ['route' => $route]);
                        /* collect headline output */
                        $output .= Redaxscript\Hook::trigger('contentFragmentStart', $r);
                        if ($headline == 1) {
                            $output .= '<h2 class="rs-title-content" id="article-' . $alias . '">';
                            if ($lastTable == 'categories' || !Redaxscript\Registry::get('fullRoute') || $aliasValidator->validate($firstParameter, Redaxscript\Validator\Alias::MODE_DEFAULT) == Redaxscript\Validator\ValidatorInterface::PASSED) {
                                $output .= '<a href="' . Redaxscript\Registry::get('parameterRoute') . $route . '">' . $title . '</a>';
                            } else {
                                $output .= $title;
                            }
                            $output .= '</h2>';
                        }
                        /* collect box output */
                        $output .= '<div class="rs-box-content">' . $parser->getOutput() . '</div>';
                        if ($byline == 1) {
                            $output .= byline('articles', $id, $author, $date);
                        }
                        $output .= Redaxscript\Hook::trigger('contentFragmentEnd', $r);
                        /* admin dock */
                        if (Redaxscript\Registry::get('loggedIn') == Redaxscript\Registry::get('token') && $firstParameter != 'logout') {
                            $output .= admin_dock('articles', $id);
                        }
                    } else {
                        $counter++;
                    }
                }
                /* handle access */
                if ($lastTable == 'categories') {
                    if ($num_rows_active == $counter) {
                        $error = Language::get('access_no');
                    }
                } else {
                    if ($lastTable == 'articles' && $counter == 1) {
                        $error = Redaxscript\Language::get('access_no');
                    }
                }
            }
        }
    }
    /* handle error */
    if ($error) {
        /* show error */
        $messenger = new Redaxscript\Messenger(Redaxscript\Registry::getInstance());
        echo $messenger->error($error, Redaxscript\Language::get('something_wrong'));
    } else {
        $output .= Redaxscript\Hook::trigger('contentEnd');
        echo $output;
        /* call comments as needed */
        if ($articleId) {
            /* comments replace */
            if ($comments == 1 && Redaxscript\Registry::get('commentReplace')) {
                Redaxscript\Hook::trigger('commentReplace');
            } else {
                if ($comments > 0) {
                    $route = build_route('articles', $articleId);
                    comments($articleId, $route);
                    /* comment form */
                    if ($comments == 1 || Redaxscript\Registry::get('commentNew') && $comments == 3) {
                        $commentForm = new Redaxscript\View\CommentForm(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance());
                        echo $commentForm->render($articleId);
                    }
                }
            }
        }
    }
    /* call pagination as needed */
    if ($sub_maximum > 1 && Redaxscript\Db::getSetting('pagination') == 1) {
        $route = build_route('categories', $categoryId);
        pagination($sub_active, $sub_maximum, $route);
    }
}