public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $this->pluginTemplate = '/news/archive.plug.html'; $data = $data->fork(); $data->setArray($this->attributes()); $articles = new Model_News_Article(); $articles->where('categoryid IN ?', $this->getAttribute('categoryid')); // TODO: Group by date $data->set('articles', $articles); parent::output($data, $stream); }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $this->pluginTemplate = '/news/feed.plug.html'; $default = array('limit' => 5, 'categoryid' => null); $settings = array_merge($default, $this->attributes()); $articles = new Model_News_Article(); if (!is_null($settings['categoryid'])) { if (!is_array($settings['categoryid'])) { $settings['categoryid'] = array($settings['categoryid']); } if (!in_array(0, $settings['categoryid'])) { $articles->where('categoryid IN ?', $settings['categoryid']); } } $articles->where('pubdate <= ?', Typeframe::Now()); $articles->where('expdate >= ? OR expdate = ? OR expdate IS NULL', Typeframe::Now(), '0000-00-00 00:00:00'); $articles->where('status = ?', 'published'); $articles->limit($settings['limit']); $data = $data->fork(); $data['header'] = $settings['header']; $data['articles'] = $articles; parent::output($data, $stream); }
* Typeframe News application * * client-side index controller */ // save typing below $typef_app_dir = Typeframe::CurrentPage()->applicationUri(); // get category id, if any //$categoryid = News::GetCategoryId(); $settings = Typeframe::CurrentPage()->settings(); // set category id in template //$pm->setVariable('categoryid', $settings['categoryid']); // get articles; limit to this category and valid publication date $articles = new Model_News_Article(); $categories = new Model_News_Category(); if (isset($settings['categoryid']) && is_array($settings['categoryid']) && count($settings['categoryid']) && !in_array(0, $settings['categoryid'])) { $articles->where('news.categoryid IN ?', $settings['categoryid']); $categories->where('categoryid IN ?', $settings['categoryid']); } $articles->where('pubdate <= ?', Typeframe::Now()); $articles->where('expdate > ? OR expdate = ? OR expdate IS NULL', Typeframe::Now(), '0000-00-00 00:00:00'); $articles->where('status = ?', 'published'); $total = $articles->count(); // set up pagination $perpage = !empty($settings['perpage']) ? $settings['perpage'] : 20; $pag = Pagination::Calculate($total, $perpage); $articles->paginate($pag['page'], $pag['perpage']); $pm->setVariable('pagination', $pag); $settings = Typeframe::CurrentPage()->settings(); // add articles, pagination to template $pm->setVariable('news', $articles); //$pm->setVariableArray(Pagination::Calculate($articles->getTotal(),
*/ // get sorting options list($sort_options, $sort, $order) = News::GetAdminSortingOptions(); // set sorting in template $pm->setVariable('sort_options', $sort_options); $pm->setVariable('sort', $sort); if (!empty($_REQUEST['pageid'])) { $page = Model_Page::Get($_REQUEST['pageid']); if (!$page->exists() || $page['application'] != 'News' && $page['application'] != 'News RSS') { Typeframe::Redirect('Invalid page specified.', Typeframe::CurrentPage()->applicationUri(), 1); return; } $pm->setVariable('currentpage', $page); } $newspages = new Model_Page(); $newspages->where('application = ?', 'News'); $pm->setVariable('newspages', $newspages); $articles = new Model_News_Article(); $total = $articles->count(); if (!empty($_REQUEST['status'])) { $articles->where('status = ?', $_REQUEST['status']); } $articles->order($order); // set up pagination $page = @$_REQUEST['page'] && ctype_digit($_REQUEST['page']) ? intval($_REQUEST['page']) : 1; $perpage = isset($settings['perpage']) ? $settings['perpage'] : 10; //$articles->setPagination($page, $perpage); $articles->paginate($page, $perpage); // add pagination, articles to template $pm->setVariable('pagination', Pagination::Calculate($total, $perpage, $page)); $pm->setVariable('news', $articles);
public function testNewsAdminCreateEditAndDeleteArticle() { /* Assertions: * New article appears in news index * Index has link to edit article * Index has link to delete article * New article has ID * Changes to article get saved * Article can be deleted */ $title = 'Integration Test ' . time(); $form = $this->first('form[action^="' . TYPEF_WEB_DIR . '/admin/news/add"]'); $form->first('input[name="title"]')->setValue($title); $form->first('input[name="author"]')->setValue('the test case'); $form->first('textarea[name="article"]')->setValue('<p>My article!</p>'); $form->submit(); $news = new Model_News_Article(); $news->where('title = ?', $title); $article = $news->getFirst(); $this->assertTrue($article->exists(), 'Posted article not found in database'); if ($article->exists()) { $this->get(TYPEF_WEB_DIR . '/admin/news'); $newsid = $article['newsid']; $links = $this->select('a[href*="newsid=' . $article['newsid'] . '"]'); $editLink = false; $deleteLink = false; foreach ($links as $link) { if ($editLink && $deleteLink) { break; } if (strpos($link['href'], TYPEF_WEB_DIR . '/admin/news/edit') !== false) { $editLink = $link['href']; } else { if (strpos($link['href'], '/admin/news/delete') !== false) { $deleteLink = true; } } } $this->assertTrue($editLink, 'No link to edit article.'); $this->assertTrue($deleteLink, 'No link to delete article.'); $this->get($editLink); $form = $this->first('form[action="' . TYPEF_WEB_DIR . '/admin/news/edit"]'); $form->first('textarea[name="article"]')->setValue('<p>My modified article!</p>'); $form->submit(); $this->get($editLink); $this->assertText('My modified article!', "Edited article was not saved."); $this->post(TYPEF_WEB_DIR . '/admin/news/delete', array('newsid' => $newsid)); $this->get(TYPEF_WEB_DIR . '/admin/news'); $this->assertNoText($title, 'Article could not be deleted.'); } /*$this->get(TYPEF_WEB_DIR . '/admin/news'); if ($this->assertText($title, 'New article missing from index')) { //$links = $this->first('td.toolbar')->select('a'); //$links = $this->select('a[href') $newsid = null; $editLink = false; $deleteLink = false; foreach ($links as $link) { if ($editLink && $deleteLink) break; if (strpos($link['href'], TYPEF_WEB_DIR . '/admin/news/edit') !== false) { $editLink = "{$link['href']}"; if (preg_match('/newsid=([0-9]*)/', "{$link['href']}", $matches)) { $newsid = $matches[1]; } } else if (strpos($link['href'], 'delete') !== false) { $deleteLink = true; } } $this->assertTrue($editLink, 'No link to edit article.'); $this->assertTrue($deleteLink, 'No link to delete article.'); $this->assertTrue($newsid, 'Article does not have an ID.'); if ($newsid) { $this->get($editLink); $form = $this->first('form[action="' . TYPEF_WEB_DIR . '/admin/news/edit"]'); $form->first('textarea[name="article"]')->setValue('<p>My modified article!</p>'); $form->submit(); $this->get($editLink); $this->assertText('My modified article!', "Edited article was not saved."); $this->post(TYPEF_WEB_DIR . '/admin/news/delete', array('newsid' => $newsid)); $this->get(TYPEF_WEB_DIR . '/admin/news'); $this->assertNoText($title, 'Article could not be deleted.'); } }*/ }
return; } // create news category object $category = Model_News_Category::Get($categoryid); // redirect if category id is invalid if (!$category->exists()) { Typeframe::Redirect('Invalid category specified.', $typef_app_dir, 1); return; } // determine if there are 0 or more than 1 categories; add flag to template if ($setcat && (in_array(0, $setcat) || count($setcat) > 1)) { $pm->setVariable('multicats', true); } // add category name, id, and object to template $pm->setVariable('categoryname', $category->get('categoryname')); $pm->setVariable('categoryid', $category->get('categoryid')); $pm->setVariable('category', $category); // create news article factory; filter by category id $articles = new Model_News_Article(); $articles->where('categoryid = ?', $category->get('categoryid')); // add articles to template $pm->setVariable('news', $articles); // get comment types //$comment_types = CommentType::DAOFactory(); //$comment_types->setOrder('name'); // add comment types to template //$pm->setVariable('comment_types', $comment_types); // add page title and header to template //$title = News::GetTitle(); //$pm->setVariable('page_title', $title); //$pm->setVariable('page_header', $title);
<?php $path = Typeframe::CurrentPage()->pathInfo(); $settings = Typeframe::CurrentPage()->settings(); $typef_app_dir = Typeframe::CurrentPage()->applicationUri(); $articles = new Model_News_Article(); $redirect = false; if ($path) { // Get the article by encoded title $articles->where('encodedtitle = ?', $path); } else { // Get the article by news ID if possible if (isset($_REQUEST['newsid'])) { $articles->where('newsid = ?', $_REQUEST['newsid']); $redirect = true; } else { Typeframe::Redirect('No news article was specified.', $typef_app_dir, 1, false); return; } } if (isset($settings['categoryid']) && is_array($settings['categoryid']) && !in_array(0, $settings['categoryid'])) { $articles->where('categoryid IN ?', $settings['categoryid']); } $articles->where('pubdate <= ?', Typeframe::Now()); $articles->where('expdate = ? OR expdate > ? OR expdate IS NULL', '0000-00-00 00:00:00', Typeframe::Now()); $articles->where('status = ?', 'published'); $article = $articles->getFirst(); if (!$article->exists()) { http_response_code(404); Typeframe::Redirect('Invalid article specified.', $typef_app_dir, 1, false); return;
<?php /** * Typeframe News application * * client-side rss controller */ // set the appropriate content type header('Content-Type: application/rss+xml'); // set the template Typeframe::SetPageTemplate('/news/rss.xml'); // add title, description, link, and lastbuild date to template $pm->setVariable('title', TYPEF_TITLE); $pm->setVariable('description', TYPEF_TITLE . ' News'); $pm->setVariable('link', 'http://' . $_SERVER['HTTP_HOST']); $pm->setVariable('lastbuild', date('D, d M Y H:i:s T')); // get articles; limit to published if non-admin $articles = new Model_News_Article(); $articles->where('pubdate <= ?', Typeframe::Now()); $articles->limit('0, 10'); // add articles to template $pm->setVariable('items', $articles);
<?php if (Typeframe::Allow(TYPEF_WEB_DIR . '/admin/news') || Typeframe::Allow(TYPEF_WEB_DIR . '/admin/pages')) { $pages = new Model_Page(); $pages->where('application IN ?', array('News', 'News RSS')); foreach ($pages->getAll() as $page) { $pm->addLoop('admin_pages', $page); } } if (Typeframe::Allow(TYPEF_WEB_DIR . '/admin/news')) { $admin_news = array(); $articles = new Model_News_Article(); $admin_news['totalarticles'] = $articles->getTotal(); $articles = new Model_News_Article(); $articles->where('status = ?', 'draft'); $admin_news['totaldrafts'] = $articles->getTotal(); $pm->setVariable('admin_news', $admin_news); $pm->addLoop('admin_panels', array('name' => 'News', 'template' => '/admin/news/panel.inc.html')); }