public function admin(Pagemill_Data $data, Pagemill_Stream $stream) { $this->adminTemplate = '/admin/news/feed.plug.html'; $data = $data->fork(); $categories = new Model_News_Category(); $categories->order('categoryname'); $data['categories'] = $categories; $pages = new Model_Page(); $pages->where('application = ?', 'News'); $data['pages'] = $pages; $data->setArray($this->attributes()); parent::admin($data, $stream); }
public function admin(Pagemill_Data $data, Pagemill_Stream $stream) { // TODO: Implement $data = $data->fork(); $data->setArray($this->attributes()); $pages = new Model_Page(); $pages->where('application = ?', 'News'); $data->set('pages', $pages); $categories = new Model_News_Category(); $categories->order('categoryname'); $data->set('categories', $categories); $this->adminTemplate = '/admin/news/archive.plug.html'; parent::admin($data, $stream); }
public function action_delete($id = null) { is_null($id) and Response::redirect('news/category'); if ($news_category = Model_News_Category::find($id)) { $news_category->delete(); Session::set_flash('success', 'Deleted news_category #' . $id); } else { Session::set_flash('error', 'Could not delete news_category #' . $id); } Response::redirect('news/category'); }
public function admin(Pagemill_Data $data, Pagemill_Stream $stream) { $this->adminTemplate = '/admin/news/newsfeed.adminplug.html'; $data = $data->fork(); $this->attributes = array_merge(array('news_page_base' => '', 'limit' => ''), $this->attributes); $data->setArray($this->attributes); // get pages; add to template $pages = new Model_Page(); $pages->where('application = ?', 'News'); $data->set('pages', $pages); // get categories; add to template //$categories = new News_Category_Factory(); $categories = new Model_News_Category(); $categories->order('categoryname'); foreach ($categories->getAll() as $category) { if (isset($this->attributes['categoryid']) && in_array($row['categoryid'], $this->attributes['categoryid'])) { $category->set('selected', true, true); } } $data->set('categories', $categories); parent::output($data, $stream); }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $this->pluginTemplate = '/news/categories.plug.html'; $data = $data->fork(); $this->settings['id'] = isset($this->settings['id']) ? $this->settings['id'] : 'newscategoryfeed-' . rand(0, 9) . rand(0, 9) . rand(0, 9); $this->settings['template'] = isset($this->settings['template']) ? $this->settings['template'] : 'newscategoryfeed.plug.html'; $data->setArray($this->settings); $categories = new Model_News_Category(); $categoryid = News::GetCategoryId(true); if (isset($this->settings['count'])) { $categories->limit($this->settings['count']); } $categories = $categories->getAll(); foreach ($categories as $index => $category) { $cid = $category->get('categoryid'); $category->set('url', TYPEF_WEB_DIR . News::GetCategoryUri($cid) . "/categories?categoryid={$cid}"); $category->set('articlesCount', News::CountArticles($category)); $categories[$index] = $category; } $data->set('categories', $categories); $this->pluginTemplate = '/news/' . $this->settings['template']; parent::output($data, $stream, $tag); }
private static function _GetCategoryBases() { static $categoryids = null; static $categoryBases = null; if (is_null($categoryBases)) { $categoryids = array(); $categoryBases = array(); $categories = new Model_News_Category(); foreach ($categories->select() as $category) { $categoryids[] = $category['id']; } $pages = new Model_Page(); $pages->where('application = ?', 'News'); foreach ($pages->select() as $page) { if (isset($page['settings']['categoryid']) && is_array($page['settings']['categoryid']) && !in_array(0, $page['settings']['categoryid'])) { foreach ($page['settings']['categoryid'] as $id) { if (!isset($categoryBases[$id])) { $categoryBases[$id] = array(); } $categoryBases[$id][] = TYPEF_WEB_DIR . $page['uri']; } } else { if (!isset($categoryBases[0])) { $categoryBases[0] = array(); } $categoryBases[0][] = TYPEF_WEB_DIR . $page['uri']; foreach ($categoryids as $id) { if (!isset($categoryBases[$id])) { $categoryBases[$id] = array(); } $categoryBases[$id][] = TYPEF_WEB_DIR . $page['uri']; } } } } return $categoryBases; }
<?php $parentid = isset($_REQUEST['parentid']) ? $_REQUEST['parentid'] : 0; $categories = new Model_News_Category(); $categories->where('parentid = ?', $parentid); $pm->setVariable('categories', $categories);
<?php $parents = new Model_News_Category(); $parents->order('categoryname'); $pm->setVariable('parents', $parents);
$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(), // $perpage, $articles->getCurrentPage())); // get categories; limit to the given parent category //$categories = new News_Category_Factory(); $categories = new Model_News_Category(); //if ($categoryid) $categories->where('parentid IN ?', $categoryid); //$categories->setParentId($categoryid); // add parent category to template /*if ($category) { $pm->addLoop('crumbs', $category); $parentid = $category->get('parentid'); while ($parentid > 0) { $parent = Model_News_Category::Get($parentid); $pm->addLoop('crumbs', $parent); $parentid = $parent->get('parentid'); } }*/ // add categories to template with download counts
<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $sortnum = array(); for ($i = 0; $i < count($_POST['categoryid']); $i++) { if (!isset($sortnum[$_POST['parentid'][$i]])) { $sortnum[$_POST['parentid'][$i]] = 0; } $category = Model_News_Category::Get($_POST['categoryid'][$i]); $category['parentid'] = $_POST['parentid'][$i]; $category['sortnum'] = $sortnum[$_POST['parentid'][$i]]; $category->save(); $sortnum[$_POST['parentid'][$i]]++; } Typeframe::Redirect('Sorted.', Typeframe::CurrentPage()->applicationUri()); }
public function testNewsAdminCreateEditAndDeleteCategory() { /* Assertions: * Create category * Edit category * Delete category */ $this->get(TYPEF_WEB_DIR . '/admin/news/categories'); $this->get(TYPEF_WEB_DIR . '/admin/news/categories/add'); $form = $this->first('form[action="' . TYPEF_WEB_DIR . '/admin/news/categories/add"]'); $categoryname = 'Integration Test ' . time(); $categorydescr = "{$categoryname} description"; $form->first('input[name="categoryname"]')->setValue($categoryname); $form->first('input[name="categorydescr"]')->setValue($categorydescr); $form->first('input[name="categorydescr"]')->setValue(TYPEF_DIR . '/tests/images/placeholders/generic/1024x768.jpg'); $form->submit(); $catmod = new Model_News_Category(); $catmod->where('categoryname = ?', $categoryname); $category = $catmod->getFirst(); $this->assertTrue($category->exists(), 'Failed to create news category'); if ($category->exists()) { $id = $category['id']; $categoryname .= ' updated'; $this->get(TYPEF_WEB_DIR . '/admin/news/categories/edit?categoryid=' . $id); $form = $this->first('form[action="' . TYPEF_WEB_DIR . '/admin/news/categories/edit"]'); $form->first('input[name="categoryname"]')->setValue($categoryname); $form->submit(); $catmod = new Model_News_Category(); $catmod->where('categoryname = ?', $categoryname); $category = $catmod->getFirst(); $this->assertTrue($category->exists(), 'Failed to edit news category'); $this->post(TYPEF_WEB_DIR . '/admin/news/categories/delete', array('categoryid' => $id)); $category = Model_News_Category::Get($id); $this->assertFalse($category->exists(), 'Failed to delete news category'); } }
<?php $category->setArray($_POST, false); $image = FileManager::GetPostedOrUploadedFile('categoryimage', TYPEF_DIR . '/files/public/news'); $category['categoryimage'] = basename($image); if (!$category->exists()) { $ordered = new Model_News_Category(); $ordered->where('parentid = 0'); $ordered->order('sortnum DESC'); $last = $ordered->getFirst(); $category['sortnum'] = $last['sortnum'] + 1; } $category->save();
<?php require_once 'options.inc.php'; $category = Model_News_Category::Create(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { require_once 'update.inc.php'; if ($category->exists() && !$category->dirty()) { Typeframe::Redirect('Category created.', Typeframe::CurrentPage()->applicationUri() . '/categories'); } }
} $settings = Typeframe::CurrentPage()->settings(); $typef_app_dir = Typeframe::CurrentPage()->applicationUri(); //var_dump($_SERVER);die; // get category id from request if not in path info if (!$categoryid) { $categoryid = @$_REQUEST['categoryid']; } // validate category id in settings $setcat = @$settings['categoryid']; if ($setcat && !in_array(0, $setcat) && !in_array($categoryid, $setcat)) { Typeframe::Redirect('Invalid category specified.', $typef_app_dir, 1); 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();
<?php $category = Model_News_Category::Get($_REQUEST['categoryid']); if (!$category->exists()) { Typeframe::Redirect('Invalid category specified.', Typeframe::CurrentPage()->applicationUri() . '/categories', -1); return; } $parentid = $category['parentid']; if ($category['articles']->getTotal() && $parentid == 0) { Typeframe::Redirect('Category has articles that cannot be recategorized.', Typeframe::CurrentPage()->applicationUri() . '/categories', -1); return; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($category['articles']->getTotal()) { foreach ($category['articles']->getAll() as $article) { $article['categoryid'] = $parentid; $article->save(); } } if ($category['children']->getTotal()) { foreach ($category['children']->getAll() as $child) { $child['parentid'] = $parentid; $child->save(); } } $category->delete(); Typeframe::Redirect('Category deleted.', Typeframe::CurrentPage()->applicationUri() . '/categories'); }
$categories = array(); $allselected = true; $pm->setVariable('settingstemplate', '/admin/news/settings.html'); if (isset($_REQUEST['pageid'])) { //$rs = $db->prepare('SELECT * FROM #__page WHERE pageid = ?'); //$rs->execute($_REQUEST['pageid']); $row = Model_Page::Get($_REQUEST['pageid']); if ($row->exists()) { $pm->setVariable('settings', $row['settings']); $categories = isset($settings['categoryid']) ? $settings['categoryid'] : array(); if (!is_array($categories)) { $categories = array(); } if (in_array(0, $categories)) { $allselected = true; } else { $allselected = false; } } } //$rs = $db->execute('SELECT * FROM #__news_category ORDER BY categoryname'); $categories = new Model_News_Category(); $categories->order('categoryname'); foreach ($categories->select() as $row) { if (!$allselected && isset($row['categoryid']) && is_array($row['categoryid']) && in_array($row['categoryid'], $categories)) { $row['selected'] = 'selected'; } else { $row['selected'] = ''; } $pm->addLoop('categories', $row); }