function index() { $model = new Blog_Model(); $this->view->categories = $model->getAllCategories(array("name")); $this->view->posts = $model->getRecentPosts(); $this->view->render('blog/index'); }
/** * * @return Blog_Model */ public static function &instance() { if (!is_object(Blog_Model::$instances)) { // Create a new instance Blog_Model::$instances = new Blog_Model(); } return Blog_Model::$instances; }
public function createObjectFromData($row) { //Create a new user_model object $blog = new Blog_Model(); //Set the ID on the user model $blog->setId($row->id); //Set the username on the user model $blog->setTitle($row->title); //Set the password on the user model $blog->setContent($row->content); //set the author on the blog model $blog->setAuthor($row->author); //Return the new user object return $blog; }
function index_action() { $this->pageTitle = 'Lista komentarzy'; $comments = $this->model->comments(); // if no comments if (!$comments->exists) { echo '<p>Brak komentarzy</p>'; return; } // table configuration $table = new ACPTable(); $table->isPagination = false; $table->header = array('Komentarz', 'Napisany', 'Autor'); $table->selectedActions[] = array('Usuń', 'comments/delete/'); $table->selectedActions[] = array('Zatwierdź', 'comments/approve/'); $table->selectedActions[] = array('Odrzuć', 'comments/reject/'); // users, posts, pages $posts = array(); // in all two arrays data about certain post/page is stored, with [id] key $pages = array(); // adding comments foreach ($comments as $comment) { $id = $comment->id; //-- $content = strip_tags($comment->content); if (mb_strlen($content) > 500) { $content = mb_substr($content, 0, 500) . ' (...)'; } $content = nl2br($content); //-- $actions = ''; // previewing if ($comment->type == 'blogpost') { // fetching data if (!isset($posts[$comment->record])) { $posts[$comment->record] = Blog_Model::postData_id($comment->record); } $post =& $posts[$comment->record]; //-- $actions .= '<a href="#/' . date('Y/m', $post->published) . '/' . $post->name . '#comment-' . $id . '" title="Obejrzyj komentarz na stronie">Zobacz</a> | '; } elseif ($comment->type = 'page') { // fetching data if (!isset($pages[$comment->record])) { $pages[$comment->record] = Pages_Model::pageData_id($comment->record); } $page =& $pages[$comment->record]; //-- $actions .= '<a href="#/' . $page->name . '#comment-' . $id . '" title="Obejrzyj komentarz na stronie">Zobacz</a> | '; } $actions .= '<a href="$/comments/edit/' . $id . '" title="Edytuj komentarz">Edytuj</a> | '; $actions .= '<a href="$/comments/delete/' . $id . '" title="Usuń komentarz">Usuń</a>'; // approve/reject (only if comment wasn't written by admin) if ($comment->authorID === null) { if ($comment->approved) { $actions .= ' | <a href="$/comments/reject/' . $id . '" title="Oznacz komentarz jako oczekujący na moderację">Odrzuć</a>'; } else { $actions .= ' | <a href="$/comments/approve/' . $id . '" title="Oznacz komentarz jako sprawdzony">Zatwierdź</a>'; } } //-- $commentInfo = ''; if (!$comment->approved) { $commentInfo .= '[<strong>Niesprawdzony!</strong>] '; } $commentInfo .= $content; $commentInfo .= '<div class="acp-actions">' . $actions . '</div>'; //-- $created = HumanDate($comment->created); //-- if ($comment->authorID !== null) { $user = Users::userData(1); //-- $author = htmlspecialchars($user->nick) . ' (admin)'; } else { $author = htmlspecialchars($comment->authorName); if ($comment->authorWebsite !== null) { $author = '<a href="' . htmlspecialchars($comment->authorWebsite) . '" target="_blank">' . $author . '</a>'; } $author .= '<br>' . htmlspecialchars($comment->authorEmail); } //-- $rowAttributes = array(); if (!$comment->approved) { $rowAttributes = array('style' => 'background-color:#F5E8D9'); } $cells = array($commentInfo, $created, $author); $table->addRow($id, $cells, $rowAttributes); } // displaying echo $table->generate(); }
public function install2() { $this->plainOutput = true; // data $fields = array('dbname', 'dbuser', 'dbpass', 'dbprefix', 'dbhost', 'login', 'pass', 'pass2', 'sitename'); foreach ($fields as $key) { ${$key} = $_POST[$key]; } if (empty($sitename)) { $sitename = 'Mój blog'; } // URL-s $mod_rewrite = $_POST['mod_rewrite'] == 'on'; if ($mod_rewrite) { $siteURL = BaseURL; } else { $siteURL = BaseURL . 'index.php/'; } // connecting with database try { DB::connect($dbhost, $dbname, $dbuser, $dbpass, $dbprefix); } catch (WMException $e) { // creating database if necessary if ($e->getCode() == 'DB:selectError') { DB::query('CREATE DATABASE ' . $dbname); DB::connect($dbhost, $dbname, $dbuser, $dbpass, $dbprefix); } else { throw $e; } } // installing tables in database $tablesSql = file_get_contents(BundlesPath . 'installer/data/structure.sql'); foreach (explode(';', $tablesSql) as $query) { $query = trim($query); if (empty($query)) { continue; } // substituting tables prefix $query = str_replace('`wm_', '`' . $dbprefix, $query); DB::pureQuery($query); } // installing Watermelon's configuration // generating Atom ID for website $atomID = SiteURL . time() . mt_rand(); $atomID = sha1($atomID); // modules $w->modulesList = Watermelon::indexModules(false); $w->defaultController = 'blog'; // other $w->siteURL = $siteURL; $w->systemURL = SystemURL; $w->skin = 'light'; $w->atomID = $atomID; // frontend $textMenus = array(array(array('Blog', '', true, null))); $w->siteName = $sitename; $w->footer = '<small><a href="$/admin">Logowanie</a></small><br>' . 'powered by <strong><a href="https://github.com/radex/Watermelon">Watermelon</a></strong>'; $w->textMenus = $textMenus; $w->headTags = ''; $w->tailTags = ''; // setting config Config::set('wmelon.wmelon', $w); Watermelon::$config = $w; // adding admin's account $salt = substr(sha1(mt_rand()), 0, 16); $adminData = (object) array('login' => strtolower($login), 'salt' => $salt, 'pass' => sha1($pass . $salt), 'nick' => $login); Config::set('wmelon.admin', $adminData); // logging in $_SESSION['wmelon.users.login'] = strtolower($login); $_SESSION['wmelon.users.pass'] = $adminData->pass; // creating cache dirs @mkdir(CachePath . 'textile/'); // warnings supressed so that installation don't fail if cache dirs already exist @mkdir(CachePath . 'textile_restricted/'); // adding sample blog post $postContent = file_get_contents(BundlesPath . 'installer/data/samplePost.txt'); Blog_Model::postPost(true, 'Dzięki za wybranie Watermelona!', $postContent); // saving config.php $configFile = file_get_contents(BundlesPath . 'installer/data/config.php'); $configFile = str_replace('{host}', addslashes($dbhost), $configFile); $configFile = str_replace('{user}', addslashes($dbuser), $configFile); $configFile = str_replace('{pass}', addslashes($dbpass), $configFile); $configFile = str_replace('{name}', addslashes($dbname), $configFile); $configFile = str_replace('{prefix}', addslashes($dbprefix), $configFile); file_put_contents(SystemPath . 'config.php', $configFile); }