Skip to content

Commit

Permalink
Merge pull request #26 from F3Community/2016
Browse files Browse the repository at this point in the history
2016 update!
  • Loading branch information
sn0opy authored Nov 23, 2016
2 parents 35925ff + 842ffac commit e8fed1b
Show file tree
Hide file tree
Showing 25 changed files with 1,156 additions and 1,905 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ F3com
fatfreeframework.com Wiki

##Installation
The project consists of two different repositories. One with the code, another
The project consists of two different repositories. One with the code, another
with the data. To clone both use the following command

`git clone --recursive [email protected]:F3Community/F3com.git`
Expand Down
29 changes: 18 additions & 11 deletions app/layout/model.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<?php
/*
This file is part of F3::WIKI
namespace Layout;

class Model extends \DB\Jig\Mapper {
The contents of this file are subject to the terms of the GNU General
Public License Version 3.0. You may not use this file except in
compliance with the license. Any of the license terms and conditions
can be waived if you get permission from the copyright holder.
*/

/** @var \Base */
protected $f3;
namespace Layout;

public function __construct()
{
$this->f3 = \Base::instance();
parent::__construct($this->f3->get('DB'), 'layout.json');
}
class Model extends \DB\Jig\Mapper
{
/** @var \Base */
protected $f3;

}
public function __construct()
{
$this->f3 = \Base::instance();
parent::__construct($this->f3->get('DB'), 'layout.json');
}
}
75 changes: 41 additions & 34 deletions app/navigation/model.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
<?php
/**
Navigation Model
**/
/*
This file is part of F3::WIKI
namespace Navigation;
The contents of this file are subject to the terms of the GNU General
Public License Version 3.0. You may not use this file except in
compliance with the license. Any of the license terms and conditions
can be waived if you get permission from the copyright holder.
*/

class Model extends \DB\Jig\Mapper {
namespace Navigation;

/** @var \Base */
protected $f3;
class Model extends \DB\Jig\Mapper
{
/** @var \Base */
protected $f3;

public function __construct() {
$this->f3 = \Base::instance();
parent::__construct($this->f3->get('DB'),'navigation.json');
}
public function __construct()
{
$this->f3 = \Base::instance();
parent::__construct($this->f3->get('DB'),'navigation.json');
}

/**
* return a set of pages that belongs to a given menu
* @param $menu
* @return array
*/
public function getPages($menu) {
$this->load(array('@name = ?', $menu));
if(!$this->dry()) {
$page = new \Page\Model();
$pages = array();
foreach ($this->pages as $item) {
// $page->load(array('@_id = ? AND ( isset(@deleted) && @deleted = 0)', $item));
$page->load(array('@_id = ?', $item));
if (!$page->dry())
$pages[] = array('title' => $page->title, 'slug' => $page->slug);
$page->reset();
}
} else {
trigger_error('menu not found');
}
$this->reset();
return $pages;
}
/**
* return a set of pages that belongs to a given menu
* @param $menu
* @return array
*/
public function getPages($menu)
{
$this->load(array('@name = ?', $menu));
if(!$this->dry()) {
$page = new \Page\Model();
$pages = array();
foreach ($this->pages as $item) {
// $page->load(array('@_id = ? AND ( isset(@deleted) && @deleted = 0)', $item));
$page->load(array('@_id = ?', $item));
if (!$page->dry())
$pages[] = array('title' => $page->title, 'slug' => $page->slug);
$page->reset();
}
} else {
trigger_error('menu not found');
}
$this->reset();
return $pages;
}
}
125 changes: 68 additions & 57 deletions app/navigation/view.php
Original file line number Diff line number Diff line change
@@ -1,66 +1,77 @@
<?php
/**
Navigation Menu Builder
**/
/*
This file is part of F3::WIKI
The contents of this file are subject to the terms of the GNU General
Public License Version 3.0. You may not use this file except in
compliance with the license. Any of the license terms and conditions
can be waived if you get permission from the copyright holder.
*/

namespace Navigation;

class View {
class View
{

static public function render($menu,$tmpl = 'navigation_main.html')
{
$f3 = \Base::instance();
$nav = new Model();
$current_page = $f3->get('PARAMS.page');
$pages = $nav->getPages($menu);
$activePageFound = false;

foreach($pages as &$page)
if($current_page == $page['slug']) {
$page['active'] = true;
$activePageFound = true;
} else {
$page['active'] = false;
}

static public function render($menu,$tmpl = 'navigation_main.html') {
$f3 = \Base::instance();
$nav = new Model();
$current_page = $f3->get('PARAMS.page');
$pages = $nav->getPages($menu);
$activePageFound = false;
foreach($pages as &$page)
if($current_page == $page['slug']) {
$page['active'] = true;
$activePageFound = true;
} else
$page['active'] = false;
if(!$activePageFound)
$pages = self::resolveParentActivePage($current_page,$pages);
$f3->set('menu', $pages);
$content = \Template::instance()->render($f3->get('TMPL').$tmpl);
$f3->clear('menu');
return $content;
}
if(!$activePageFound)
$pages = self::resolveParentActivePage($current_page,$pages);

static private function resolveParentActivePage($current_page,$pages)
{
// get parent page id
$pageModel = new \Page\Model();
$pageModel->load(array('@slug = ?', $current_page));
if (!$pageModel->dry() && !empty($pageModel->pid)) {
// load parent page
$pageModel->load(array('@_id = ? ', $pageModel->pid));
if (!$pageModel->dry()) {
$parent_page = $pageModel->cast();
// see, if parent page is in the set of menu pages
foreach ($pages as &$page)
if ($page['slug'] == $parent_page['slug']) {
$page['active'] = true;
return $pages;
}
return self::resolveParentActivePage($parent_page['slug'],$pages);
}
}
return $pages;
}
$f3->set('menu', $pages);
$content = \Template::instance()->render($f3->get('TMPL').$tmpl);
$f3->clear('menu');

static public function renderTag($args)
{
$attr = $args['@attrib'];
$tmp = \Template::instance();
foreach ($attr as &$att)
$att = $tmp->token($att);
if (array_key_exists('menu', $attr)) {
$nav_code = '\Navigation\View::render(\''.$attr['menu'].'\');';
if (array_key_exists('tmpl', $attr))
$nav_code = "\Navigation\View::render('".$attr['menu']."','".$attr['tmpl']."');";
return '<?php echo '.$nav_code.' ?>';
}
}
return $content;
}

static private function resolveParentActivePage($current_page,$pages)
{
// get parent page id
$pageModel = new \Page\Model();
$pageModel->load(array('@slug = ?', $current_page));
if (!$pageModel->dry() && !empty($pageModel->pid)) {
// load parent page
$pageModel->load(array('@_id = ? ', $pageModel->pid));
if (!$pageModel->dry()) {
$parent_page = $pageModel->cast();
// see, if parent page is in the set of menu pages
foreach ($pages as &$page)
if ($page['slug'] == $parent_page['slug']) {
$page['active'] = true;
return $pages;
}
return self::resolveParentActivePage($parent_page['slug'],$pages);
}
}
return $pages;
}

static public function renderTag($args)
{
$attr = $args['@attrib'];
$tmp = \Template::instance();
foreach ($attr as &$att)
$att = $tmp->token($att);
if (array_key_exists('menu', $attr)) {
$nav_code = '\Navigation\View::render(\''.$attr['menu'].'\');';
if (array_key_exists('tmpl', $attr))
$nav_code = "\Navigation\View::render('".$attr['menu']."','".$attr['tmpl']."');";
return '<?php echo '.$nav_code.' ?>';
}
}
}
Loading

0 comments on commit e8fed1b

Please sign in to comment.