Пример #1
0
    $cPoem = new CPoem($db, $_SESSION);
    if ($type == 'newest') {
        $poems = $cPoem->getNewestPoems(10);
        create_rss($poems, 'Uusimmat runot', 'http://www.runosydan.net/rss.php?special=newest');
    }
}
require 'general_functions.php';
// We must get poet ID OR special-action, so we have something to show.
if (!isset($_GET['poet_id']) && !isset($_GET['special'])) {
    header('Location: index.php');
}
// In special feeds (newest poems) call function which will create
// correct RSS-feed for this.
if (isset($_GET['special'])) {
    create_special_feed($db, $_GET['special']);
} else {
    // Get poet username
    $cUsers = new CUsers($db);
    $poet_username = $cUsers->getUsername($_GET['poet_id']);
    if ($poet_username == '') {
        header('Location: index.php');
    }
    // Get poet poems on first page
    require 'CPoem.php';
    $cPoems = new CPoem($db, $_SESSION);
    $poems = $cPoems->getPoems($_GET['poet_id'], 1, false);
    // Feed title
    $RSS_feed_title = 'Runoilijan ' . $poet_username . ' uusimmat runot';
    $RSS_feed_url = 'http://www.runosydan.net/rss.php?poet_id=' . $_GET['poet_id'];
    create_rss($poems, $RSS_feed_title, $url);
}
Пример #2
0
function show_poems($id)
{
    global $db;
    require_once 'CPoem.php';
    $cPoem = new CPoem($db, $_SESSION);
    // Poems are splitted in multiple pages if there is too
    // many poems. If we do not have page number in URL, then
    // we want to show first page.
    if (isset($_GET['page'])) {
        $page = $_GET['page'];
    } else {
        $page = 1;
    }
    // Get poems. Note! This does NOT return all the poems
    // at the time. This automatically split results if there
    // is too many poems in one page.
    if ($_SESSION['id'] == $id) {
        $poems = $cPoem->getPoems($id, $page, true);
    } else {
        $poems = $cPoem->getPoems($id, $page, false);
    }
    $poemsPerPage = $cPoem->getPoemsPerPage();
    $last = $poemsPerPage * $page;
    // Count number of poems.
    if ($_SESSION['id'] == $id) {
        $numPoems = $cPoem->numPoems($id, true);
    } else {
        $numPoems = $cPoem->numPoems($id, false);
    }
    // Was there any poems in database?
    if (!is_null($poems)) {
        foreach ($poems as $cur) {
            // Create unique named DIV so we can create
            // a href what will jump directly here.
            echo '<div id="poem_' . $cur['id'] . '">';
            $cur['added'] = date('d.m.Y H:i', strtotime($cur['added']));
            $cur['poem'] = nl2br($cur['poem']);
            // If poem title is empty string, then
            // show "Nimetön runo" as a title.
            $title = stripslashes($cur['title']);
            if ($title == '') {
                $title = '<i>(Nimetön runo)</i>';
            }
            if ($cur['visible'] == '0') {
                echo '<p class="poem_header_hidden">';
            } else {
                echo '<p class="poem_header">';
            }
            echo $title;
            echo '</p>';
            if ($cur['visible'] == '0') {
                echo '<p class="poem_hidden">';
            } else {
                echo '<p class="poem">';
            }
            $cur['poem'] = str_replace('<br />', '<br>', $cur['poem']);
            echo stripslashes($cur['poem']);
            echo '<p class="poem_added">';
            echo $cur['added'];
            echo '</p>';
            // Get comments for this poem.
            $comments = $cPoem->getComments($cur['id']);
            $num = count($comments);
            // If we are browsing our own poems, then we should
            // add also links where we can remove and
            // modify those poems.
            if (isset($_SESSION['id']) && $_SESSION['id'] == $id) {
                echo '<p class="poem_actions">';
                echo '<a href="edit_poem.php?id=' . $cur['id'] . '">Muokkaa</a>';
                echo ' / ';
                echo '<a href="remove_poem.php?id=' . $cur['id'] . '">Poista</a> / ';
                echo '<a href="hide_poem.php?id=' . $cur['id'] . '&page=' . $_GET['page'] . '">';
                if ($cur['visible'] == '1') {
                    echo 'Piilota</a> / ';
                } else {
                    echo 'Näytä</a> / ';
                }
                echo '<a href="#" id="comment' . $cur['id'] . '" class="showComments" onClick="return false;">' . 'Näytä kommentit (' . $num . ')</a>';
                echo '</p>';
            } else {
                echo '<p class="poem_actions">';
                if (isset($_SESSION['username'])) {
                    echo '<a href="add_comment.php?id=' . $cur['id'] . '&amp;page=' . $page . '">Jätä kommentti</a> / ';
                }
                echo '<a href="#" id="comment' . $cur['id'] . '" class="showComments" onClick="return false;">' . 'Näytä kommentit (' . $num . ')</a>';
                echo '</p>';
            }
            // Generate unique ID so we can toggle comments
            // to visible and hidden by this unique ID.
            echo '<div class="poem_comment" id="poem_comment' . $cur['id'] . '">';
            for ($i = 0; $i < $num; $i++) {
                echo '<p>';
                echo $comments[$i]['comment'];
                echo '<br>';
                echo 'Kommentoija: <a href="poet.php?id=' . $comments[$i]['commenter_id'] . '">' . $comments[$i]['username'] . '</a><br>';
                echo $comments[$i]['date_added'];
            }
            echo '</div>';
            echo '</div>';
        }
        echo '<hr>';
        echo '<div class="change_page">';
        // Count number of poem pages.
        $numPages = ceil($numPoems / $poemsPerPage);
        echo 'Sivu ' . $page . ' / ' . $numPages . '<br>';
        // Get the correct URL where user should be forwareded
        // if he/she press "Seuraava" or "Edellinen" link.
        if (isset($_SESSION['id']) && $_SESSION['id'] == $id) {
            $url = 'ownpage.php';
        } else {
            $url = 'poet.php';
        }
        // Is "Seuraava sivu" shown?
        $prevShown = false;
        // Show link to previous poem page?
        if ($page > 1) {
            $prevPage = $page - 1;
            // Link to prev poem page
            echo '<a href="' . $url . '?page=' . $prevPage . '&amp;id=' . $id . '">' . 'Edellinen sivu</a>';
            $prevShown = true;
        }
        // Show link to next poem page?
        if ($numPoems > $last) {
            if ($prevShown) {
                echo ' / ';
            }
            $nextPage = $page + 1;
            // Link to next poem page
            echo '<a href="' . $url . '?page=' . $nextPage . '&amp;id=' . $id . '">' . 'Seuraava sivu</a>';
        }
    } else {
        echo '<p class="poem">';
        echo 'Yhtään runoa ei löytynyt.';
        echo '</p>';
    }
    echo '<br><br>';
    echo '</div>';
}