Example #1
0
/**
 * comments
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Comments
 * @author Henry Ruhs
 *
 * @param integer $article
 * @param string $route
 */
function comments($article, $route)
{
    $output = Redaxscript\Hook::trigger('commentStart');
    /* query comments */
    $comments = Redaxscript\Db::forTablePrefix('comments')->where(['status' => 1, 'article' => $article])->whereLanguageIs(Redaxscript\Registry::get('language'))->orderGlobal('rank');
    /* query result */
    $result = $comments->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') . ', ';
        }
    }
    $comments->limit($offset_string . Redaxscript\Db::getSetting('limit'));
    /* query result */
    $result = $comments->findArray();
    $num_rows_active = count($result);
    /* handle error */
    if (!$result || !$num_rows) {
        $error = Redaxscript\Language::get('comment_no');
    } 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} = stripslashes($value);
                        }
                    }
                    /* collect headline output */
                    $output .= Redaxscript\Hook::trigger('commentFragmentStart', $r) . '<h3 id="comment-' . $id . '" class="rs-title-comment">';
                    if ($url) {
                        $output .= '<a href="' . $url . '" rel="nofollow">' . $author . '</a>';
                    } else {
                        $output .= $author;
                    }
                    $output .= '</h3>';
                    /* collect box output */
                    $output .= '<div class="rs-box-comment">' . $text . '</div>';
                    $output .= byline('comments', $id, $author, $date);
                    $output .= Redaxscript\Hook::trigger('commentFragmentEnd', $r);
                    /* admin dock */
                    if (Redaxscript\Registry::get('loggedIn') == Redaxscript\Registry::get('token') && Redaxscript\Registry::get('firstParameter') != 'logout') {
                        $output .= admin_dock('comments', $id);
                    }
                } else {
                    $counter++;
                }
            }
            /* handle access */
            if ($num_rows_active == $counter) {
                $error = Redaxscript\Language::get('access_no');
            }
        }
    }
    /* handle error */
    if ($error) {
        $output = '<div class="rs-box-comment">' . $error . Redaxscript\Language::get('point') . '</div>';
    }
    $output .= Redaxscript\Hook::trigger('commentEnd');
    echo $output;
    /* call pagination as needed */
    if ($sub_maximum > 1 && Redaxscript\Db::getSetting('pagination') == 1) {
        pagination($sub_active, $sub_maximum, $route);
    }
}
Example #2
0
    $app->views->add('me/page', ['content' => $content, 'byline' => $byline]);
});
//Router me
$app->router->add('me', function () use($app) {
    $app->theme->setTitle("Me");
    $content = $app->fileContent->get('me.md');
    $content = $app->textFilter->doFilter($content, 'shortcode, markdown');
    $byline = byline($app);
    $app->views->add('me/page', ['content' => $content, 'byline' => $byline]);
});
//Route Redovisning
$app->router->add('redovisning', function () use($app) {
    $app->theme->setTitle("Redovisning");
    $content = $app->fileContent->get('redovisning.md');
    $content = $app->textFilter->doFilter($content, 'shortcode, markdown');
    $byline = byline($app);
    $app->views->add('me/page', ['content' => $content, 'byline' => $byline]);
});
//Router Source
$app->router->add('source', function () use($app) {
    $app->theme->addStylesheet('css/source.css');
    $app->theme->setTitle("Källkod");
    $source = new \Mos\Source\CSource(['secure_dir' => '..', 'base_dir' => '..', 'add_ignore' => ['.htaccess']]);
    $app->views->add('me/source', ['content' => $source->View()]);
});
// Route to show welcome to dice
$app->router->add('dice', function () use($app) {
    $app->theme->addStylesheet('css/dice.css');
    $app->views->add('dice/index');
    $app->theme->setTitle("Kasta tärning");
});
Example #3
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);
    }
}