コード例 #1
0
ファイル: contents.php プロジェクト: redaxmedia/redaxscript
/**
 * 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);
    }
}