Example #1
0
    /**
     * Constructor 
     *
     */
    public function __construct($url, $dbOptions)
    {
        $user = new CUser($dbOptions);
        $content = new CContent($dbOptions);
        $filter = new CTextFilter();
        $res = $content->getContentByUrl($url);
        if (isset($res[0])) {
            $c = $res[0];
        } else {
            die('Misslyckades: det finns inget innehåll.');
        }
        // Sanitize content before using it.
        $title = htmlentities($c->title, null, 'UTF-8');
        $data = $filter->doFilter(htmlentities($c->data, null, 'UTF-8'), $c->filter);
        // Prepare content and store it all in variables in the Anax container.
        $this->title = $title;
        $editLink = $user->isAuthenticated() ? "<a href='content_edit.php?id={$c->id}'>Uppdatera sidan</a>\n        <a href='content_delete.php?id={$c->id}'>Radera sidan</a>" : null;
        $this->main = <<<EOD
<article>
<header>
<h1>{$title}</h1>
</header>

{$data}

<footer>
<p>(Skriven av {$c->owner}. Publicerad {$c->pubdate})</p>
{$editLink}
</footer
</article>
EOD;
    }
Example #2
0
    public function getMain($limit = null)
    {
        $filter = new CTextFilter();
        // Get GET-variables
        $slug = isset($_GET['slug']) ? $_GET['slug'] : null;
        $category = isset($_GET['category']) ? $_GET['category'] : null;
        // Get blogitems
        if ($category) {
            $res = $this->content->getPostByCategory($category, $limit);
            $this->path[] = array('text' => htmlentities($category), 'url' => "?category={$category}");
        } else {
            $res = $this->content->getPostBySlug($slug, $limit);
        }
        // Prepare the blogg roll
        $main = null;
        if (isset($res[0])) {
            foreach ($res as $c) {
                // Sanitize content before using it.
                $title = htmlentities($c->title, null, 'UTF-8');
                $category = htmlentities($c->category, null, 'UTF-8');
                $data = $filter->doFilter(htmlentities($c->data, null, 'UTF-8'), $c->filter);
                if ($slug) {
                    $this->title = "{$title} | " . $this->title;
                    $this->path[] = array('text' => $category, 'url' => "?category={$category}");
                    $this->path[] = array('text' => $title, 'url' => "?id={$c->id}");
                } else {
                    $words = explode(' ', $data);
                    if (count($words) >= 30) {
                        $data = implode(' ', array_splice($words, 0, 25));
                        $data .= " ...  <a href='content_blog.php?slug={$c->slug}'>Read more</a>";
                    }
                }
                $adminLink = CUser::isAuthenticated() ? "<a href='content_edit.php?id={$c->id}'>Edit</a> <a href='content_delete.php?id={$c->id}'>Delete</a>" : null;
                $main .= <<<EOD
<article>
<header>
<h2><a href='content_blog.php?slug={$c->slug}'>{$title}</a></h2>
</header>

{$data}

<footer>
<p>
Publicerad {$c->pubdate} av {$c->owner}<br>
Kategori: <a href=content_blog.php?category{$c->category}>{$c->category}<br>
<a>{$adminLink}</p>
</footer
</article>
EOD;
            }
        } else {
            if ($slug) {
                $main = "Det fanns inte en sådan bloggpost.";
            } else {
                $main = "Det fanns inga bloggposter.";
            }
        }
        return $main;
    }
Example #3
0
 public static function getMenu()
 {
     $name = null;
     $user = null;
     if (CUser::isAuthenticated()) {
         $name = CUser::getName();
         $user = "******";
     }
     $hem = "<li>\n        <a href='index.php?p=hem'>Hem</a>\n        <ul>\n            <li><a href='login.php'>Logga in (webbredaktör)</a></li>\n        </ul>\n    </li>";
     if (CUser::isAuthenticated()) {
         $hem = "<li>\n        <a href='index.php?p=hem'>Hem</a>\n    </li>";
     }
     $html = "<nav id='menu-wrap'><ul id=\"menu\">\n        {$hem}\n        <li>\n        <a href=\"#\">Klubben</a>\n        <ul>\n            <li>\n            <a href=\"#\">Bli medlem</a>\n            <ul>\n                <li><a href='medlem.php?p=klubben'>Anmälningsformulär</a></li>\n            </ul>\n            </li>\n            <li><a href='page.php?p=2'>Styrelse</a></li>\n            <li><a href=\"#\">Information</a></li>\n            <li><a href=\"#\">Hitta till oss</a></li>\n        </ul>\n    </li>\n        <li><a href='page.php?p=1'>Kurser</a></li>\n    <li>\n        <a href=\"#\">Tävlingar</a>\n        <ul>\n            <li><a href=\"#\">Tävlingsekipage</a></li>\n            <li><a href=\"#\">Månadscupen</a></li>\n        </ul>\n    </li>\n    <li><a href='calender.php'>Kalender</a></li>\n    <li><a href='blog.php'>Blogg</a></li>\n    <li><a href='galleri.php'>Galleri</a></li>\n    {$user}\n    </ul></nav>";
     return $html;
 }
Example #4
0
    public function getTable($res, $rows)
    {
        // Get parameters
        $hits = isset($_GET['hits']) ? $_GET['hits'] : 8;
        $page = isset($_GET['page']) ? $_GET['page'] : 1;
        $id = isset($_GET['id']) ? $_GET['id'] : null;
        // Check that incoming parameters are valid
        is_numeric($hits) or die('Check: Hits must be numeric.');
        is_numeric($page) or die('Check: Page must be numeric.');
        if ($id !== null) {
            return $this->getDetails($res[0]);
            exit;
        }
        // Prepare the table, firt the header row
        $admin = CUser::isUser() ? '<th>Admin</th>' : NULL;
        $tr = "<tr>\n        <th>Id</th>\n        <th>Akronym " . CFunc::orderby('acronym') . "</th>\n        <th>Namn  " . CFunc::orderby('name') . "</th>\n        <th>Roll</th>\n        {$admin}\n        </tr>";
        // Prepare the data rows
        foreach ($res as $key => $val) {
            $admin = CUser::isCurrentUser($val->id) ? "<a href='user_regedit.php?id={$val->id}'>Edit</a> <a href='user_delete.php?id={$val->id}'>Delete</a>" : NULL;
            $admin = CUser::isUser($val->id) ? "<td>{$admin}</td>" : NULL;
            $admin = CUser::isAuthenticated() ? "<td><a href='user_edit.php?id={$val->id}'>Edit</a> <a href='user_delete.php?id={$val->id}'>Delete</a></td>" : $admin;
            // $synopsys = CTextFilter::nl2br($val->synopsys);
            $href = CFunc::getQueryString(array('id' => $val->id));
            $tr .= "<tr>\n            </a></td>\n            <td>{$val->id}</td>\n            <td><a href='{$href}'>{$val->acronym}</a></td>\n            <td>{$val->name}</td>\n            <td>{$val->role}</td>\n            {$admin}\n            </tr>";
        }
        // Prepare navigation bars and admin information
        $max = ceil($rows / $hits);
        $hitsPerPage = CFunc::getHitsPerPage(array(4, 8, 16), $hits);
        $navigatePage = CFunc::getPageNavigation($hits, $page, $max);
        $adminAnchors = CUser::isAuthenticated() ? "<p><a href='user_create.php'>Skapa ny användare</a> <a href='user_reset.php'>Återställ användardatabasen</a></p>" : null;
        // Put rows in HTML-table with navigation bars
        $htmlTable = <<<EOD
<div class='dbtable'>
  <div class='rows'>{$rows} träffar. {$hitsPerPage}</div>
  <table>
  {$tr}
  </table>
  <div class='pages'>{$navigatePage}</div>
  {$adminAnchors}
</div>
EOD;
        return $htmlTable;
    }
Example #5
0
<?php

/**
 * This is a Branax pagecontroller.
 *
 */
// Include the essential config-file which also creates the $branax variable with its defaults.
include __DIR__ . '/config.php';
$user = new CUser($branax['database']);
$user->isAuthenticated() or die('Check: You must login to edit.');
$content = new CContent($branax['database']);
// Do it and store it all in variables in the Anax container.
$branax['title'] = "Lägg till";
$branax['main'] = <<<EOD
<h1>Lägg till nytt innehåll</h1>
{$content->create($user->getAcronym())}
EOD;
// Finally, leave it all to the rendering phase of Anax.
include BRANAX_THEME_PATH;
Example #6
0
<?php

/**
 * This is a Branax pagecontroller.
 *
 */
// Include the essential config-file which also creates the $branax variable with its defaults.
include __DIR__ . '/config.php';
$user = new CUser($branax['database']);
$user->isAuthenticated() or die('Check: You must login first.');
$content = new CContent($branax['database']);
// Do it and store it all in variables in the Branax container.
$branax['title'] = "Återställ";
$branax['main'] = <<<EOD
<h1>Återställ databasen till ursprungligt skick</h1>
{$content->reset()}
EOD;
// Finally, leave it all to the rendering phase of Branax.
include BRANAX_THEME_PATH;
Example #7
0
 public function drawNews($res)
 {
     $items = null;
     if (CUser::isAuthenticated()) {
         foreach ($res as $key => $val) {
             //$first=substr($content,0,255);
             $val->published = date("| Y, M j, G:i");
             if ($val->deleted == NULL) {
                 $items .= "<div class='box'><h2>{$val->title}</h2><p>{$val->content}</p><p class='pub'>Publiserad av: {$val->name} {$val->published}</p><a class='link' href='#'>Editera</a></div>\n";
             }
         }
         return $items;
     } else {
         foreach ($res as $key => $val) {
             $val->published = date("| Y, M j, G:i");
             if ($val->deleted == NULL) {
                 $items .= "<div class='box'><h2>{$val->title}</h2><p>{$val->content}</p><p class='pub'>Publiserad av: {$val->name} {$val->published}</p></div>\n";
             }
         }
         return $items;
     }
 }
Example #8
0
<?php

/**
 * This is a Branax pagecontroller.
 *
 */
// Include the essential config-file which also creates the $branax variable with its defaults.
include __DIR__ . '/config.php';
$user = new CUser($branax['database']);
$user->isAuthenticated() or die('Check: You must login to delete.');
$content = new CContent($branax['database']);
// Do it and store it all in variables in the Branax container.
$branax['title'] = "Radera";
$branax['main'] = <<<EOD
<h1>Radera innehåll</h1>
{$content->delete()}
EOD;
// Finally, leave it all to the rendering phase of Branax.
include BRANAX_THEME_PATH;
Example #9
0
<?php

if (CUser::isAuthenticated()) {
    $get_page = new CContent();
    $id = $_GET['p'];
    $params = array($id);
    $content = $get_page->getPage($params);
}
Example #10
0
    public function getTable($res, $rows)
    {
        // Get parameters
        $genre = isset($_GET['genre']) ? htmlentities($_GET['genre']) : null;
        $hits = isset($_GET['hits']) ? $_GET['hits'] : 8;
        $page = isset($_GET['page']) ? $_GET['page'] : 1;
        $id = isset($_GET['id']) ? $_GET['id'] : null;
        if ($id !== null) {
            return $this->getDetails($res);
            exit;
        }
        if ($genre) {
            $this->path[] = array('text' => $genre, 'url' => "?genre={$genre}");
        }
        // Check that incoming parameters are valid
        is_numeric($hits) or die('Check: Hits must be numeric.');
        is_numeric($page) or die('Check: Page must be numeric.');
        // Prepare the header row
        $admin = CUser::isAuthenticated() ? '<th>Admin</th>' : NULL;
        $tr = "<tr>\n        <th>Bild</th>\n        <th>Titel " . CFunc::orderby('title') . "</th>\n        <th>Synopsis</th>\n        <th>Rating " . CFunc::orderby('rating') . "</th>\n        <th>Genre</th>\n        <th>Pris</th>\n        {$admin}\n        </tr>";
        // Prepare the data rows
        foreach ($res as $key => $val) {
            $tmp = explode(',', $val->genre);
            $genres = [];
            foreach ($tmp as $gen) {
                $genres[] = "<a href='?genre={$gen}'>{$gen}</a>";
            }
            $genres = implode('<br>', $genres);
            $admin = CUser::isAuthenticated() ? "<th><a href='movie_edit.php?id={$val->id}'>Edit</a> <a href='movie_delete.php?id={$val->id}'>Delete</a></th>" : NULL;
            $synopsys = $val->synopsys;
            $words = explode(' ', $synopsys);
            if (count($words) >= 30) {
                $synopsys = implode(' ', array_splice($words, 0, 25));
                $synopsys .= " ...  <a href='?id={$val->id}'>Read more</a>";
            }
            $tr .= "<tr>\n            <td><a href='?id={$val->id}'>\n                <img src=img.php?src=img/movie/{$val->image}&amp;width=75&amp alt='{$val->title}'/>\n            </a></td>\n            <td>{$val->title}</td>\n            <td>{$synopsys}</td>\n            <td>{$val->rating}%</td>\n            <td>{$genres}</td>\n            <td>{$val->price} SEK</td>\n             {$admin}\n            </tr>";
        }
        // Prepare navigation bars and admin information
        $max = ceil($rows / $hits);
        $hitsPerPage = CFunc::getHitsPerPage(array(4, 8, 16), $hits);
        $navigatePage = CFunc::getPageNavigation($hits, $page, $max);
        $adminAnchors = CUser::isAuthenticated() ? "<p><a href='movie_create.php'>Ny film</a> <a href='movie_reset.php'>Återställ filmdatabasen</a></p>" : null;
        // Put rows in HTML-table with navigation bars
        $htmlTable = <<<EOD
<div class='dbtable'>
  <div class='rows'>{$rows} träffar. {$hitsPerPage}</div>
  <table>
  {$tr}
  </table>
  <div class='pages'>{$navigatePage}</div>
  {$adminAnchors}
</div>
EOD;
        return $htmlTable;
    }
Example #11
0
<?php

/**
 * This is a Branax pagecontroller.
 *
 */
// Include the essential config-file which also creates the $branax variable with its defaults.
include __DIR__ . '/config.php';
// Create the user object
$user = new CUser($branax['database']);
// Check if user is authenticated.
$output = $user->isAuthenticated() ? "Du är inloggad som: {$user->getAcronym()} ({$user->getName()})" : "Du är INTE inloggad.";
// Check if user and password is okey and login the user
if (isset($_POST['login'])) {
    $user->login($_POST['acronym'], $_POST['password']);
    header('Location: user_status.php');
}
// Do it and store it all in variables in the Branax container.
$branax['title'] = "Login";
$branax['main'] = <<<EOD
<h1>{$branax['title']}</h1>

<form method=post>
  <fieldset>
  <legend>Login</legend>
  <p><label>Användare:<br/><input type='text' name='acronym' value=''/></label></p>
  <p><label>Lösenord:<br/><input type='password' name='password' value=''/></label></p>
  <p><input type='submit' name='login' value='Login'/></p>
  <p><a href='user_logout.php'>Logout</a></p>
  <p><a href='user_register.php'>Skapa ny användare</a></p>
  <output><b>{$output}</b></output>
Example #12
0
$branax['database']['driver_options'] = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'");
/**
 * The navbar
 *
 */
//$anax['navbar'] = null; // To skip the navbar
// $content = new CContent($branax['database']);
// $blogItems = $content->getBlogItems();
// $pageItems = $content->getPageItems();
// $content = null;
$userId = CUser::isUser() ? '?id=' . CUser::isUser() : null;
$blogSubMenuItems = CUser::isAuthenticated() ? array('items' => array('view' => array('text' => 'Ändra', 'url' => 'content_view.php', 'title' => 'Ändra innehåll'), 'create' => array('text' => 'Lägg till', 'url' => 'content_create.php', 'title' => 'Nytt innehåll'), 'reset' => array('text' => 'Återställ', 'url' => 'content_reset.php', 'title' => 'Återställ innehåll'))) : null;
$movieSubMenuItems = CUser::isAuthenticated() ? array('items' => array('create' => array('text' => 'Lägg till', 'url' => 'movie_create.php', 'title' => 'Nytt innehåll'), 'reset' => array('text' => 'Återställ', 'url' => 'movie_reset.php', 'title' => 'Återställ innehåll'))) : null;
$userSubMenuItems = CUser::isUser() ? array('logout' => array('text' => 'Logout', 'url' => 'user_logout.php', 'title' => 'Utloggning')) : array();
$userSubMenuItems += array('login' => array('text' => 'Login', 'url' => 'user_login.php', 'title' => 'Inloggning'), 'status' => array('text' => 'Status', 'url' => 'user_status.php', 'title' => 'Inloggningsstatus'));
$userSubMenuItems += CUser::isAuthenticated() ? array('create' => array('text' => 'Lägg till', 'url' => 'user_create.php', 'title' => 'Nytt innehåll'), 'reset' => array('text' => 'Återställ', 'url' => 'user_reset.php', 'title' => 'Återställ')) : array();
$searchForm = CMovieSearch::getTitleForm('movies.php');
$branax['navbar'] = array('class' => 'navbar', 'items' => array('hem' => array('text' => 'Hem', 'url' => 'home.php', 'title' => 'RM Rental Movies'), 'filmer' => array('text' => 'Filmer', 'url' => 'movies.php', 'title' => 'Våra filmer', 'submenu' => $movieSubMenuItems), 'nyheter' => array('text' => 'Nyheter', 'url' => 'content_blog.php', 'title' => 'Blogg', 'submenu' => $blogSubMenuItems), 'dice' => array('text' => 'Tävling', 'url' => 'dice100.php', 'title' => 'Spela och vinn en film'), 'user' => array('text' => 'Användare', 'url' => "user_view.php{$userId}", 'title' => 'Användarprofiler', 'submenu' => array('items' => $userSubMenuItems)), 'about' => array('text' => 'Om RM', 'url' => 'about.php', 'title' => 'Om företaget')), 'callback' => function ($url) {
    if (basename($_SERVER['SCRIPT_NAME']) == $url) {
        return true;
    }
    if (in_array(basename($_SERVER['SCRIPT_NAME']), ['content_edit.php', 'content_delete.php', 'content_view.php']) && in_array($url, ['content_edit.php', 'content_delete.php', 'content_view.php'])) {
        return true;
    }
    if (in_array(basename($_SERVER['SCRIPT_NAME']), ['movie_view.php', 'movie_edit.php', 'movie_delete.php']) && in_array($url, ['movies.php'])) {
        return true;
    }
    if (in_array(basename($_SERVER['SCRIPT_NAME']), ['user_view.php', 'user_register.php', 'user_regedit.php', 'user_edit.php', 'user_delete.php']) && in_array(parse_url($url, PHP_URL_PATH), ['user_view.php'])) {
        return true;
    }
});