<commit_before><?php

namespace Controllers;

use Knob\Controllers\BaseController as KnobBaseController;
use Knob\Models\Archive;
use Knob\Models\Post;
use Knob\Models\Term;
use Knob\Models\User;
use Knob\Libs\Template;
use Knob\Libs\WalkerNavMenu;
use Knob\Libs\Utils;

/**
 *
 * @author <NAME>
 */
abstract class BaseController extends KnobBaseController {

	/*
	 * Members
	 */
	protected $widgets = [ ];
	protected $menus = [ ];

	/**
	 * Constructor
	 */
	public function __construct() {
		parent::__construct();

		/*
		 * Widgets.
		 */
		foreach ( Template::getDinamicSidebarActive() as $s ) {
			ob_start();
			dynamic_sidebar($s);
			$this->widgets[$s] = ob_get_clean();
		}

		/*
		 * Menus.
		 */
		foreach ( Template::getMenusActive() as $s ) {
			$this->menus[$s] = wp_nav_menu(
					[
						'echo' => false,
						'theme_location' => $s,
						'menu_class' => 'nav navbar-nav menu ' . str_replace('_', '-', $s),
						'walker' => new WalkerNavMenu()
					]);
		}
	}

	/**
	 * Add the global variables for all controllers
	 *
	 * @param array $templateVars
	 */
	public function getGlobalVariables() {
		$globalVars = [ ];

		/*
		 * Sidebar items
		 */
		$active = ($u = User::getCurrent()) ? $u->isWithSidebar() : User::WITH_SIDEBAR_DEFAULT;
		$globalVars['widgets'] = [
			'right' => [
				'active' => $active,
				'content' => $this->widgets[Template::WIDGETS_RIGHT]
			],
			'footer' => [
				'active' => $active,
				'content' => $this->widgets[Template::WIDGETS_FOOTER]
			]
		];

		/*
		 * Menus
		 */
		$globalVars['menu'] = [
			'header' => [
				'active' => has_nav_menu(Template::MENU_HEADER),
				'content' => $this->menus[Template::MENU_HEADER]
			],
			'footer' => [
				'active' => has_nav_menu(Template::MENU_FOOTER),
				'content' => $this->menus[Template::MENU_FOOTER]
			]
		];

		return array_merge(parent::getGlobalVariables(), $globalVars);
	}
}<commit_msg>Remove KnobBaseController. Implement the render method into BaseController<commit_after><?php

namespace Controllers;

use Knob\Models\Archive;
use Knob\Models\Post;
use Knob\Models\Term;
use Knob\Models\User;
use Knob\Libs\Template;
use Knob\Libs\WalkerNavMenu;
use Knob\Libs\Utils;

/**
 *
 * @author <NAME>
 */
abstract class BaseController {

	/*
	 * Members
	 */
	protected $configParams = [ ];
	protected $currentUser = null;
	protected $template = null;
	protected $widgets = [ ];
	protected $menus = [ ];

	/**
	 * Constructor
	 */
	public function __construct() {
		/**
		 *
		 * @var array
		 */
		$this->configParams = Utils::getMustacheParams();

		/**
		 *
		 * @var User
		 */
		$this->currentUser = User::getCurrent();

		/**
		 *
		 * @var Template
		 */
		$this->template = Template::getInstance();

		// Widgets
		foreach ( Template::getDinamicSidebarActive() as $s ) {
			ob_start();
			dynamic_sidebar($s);
			$this->widgets[$s] = ob_get_clean();
		}

		// Menus
		foreach ( Template::getMenusActive() as $s ) {
			$this->menus[$s] = wp_nav_menu(
					[
						'echo' => false,
						'theme_location' => $s,
						'menu_class' => 'nav navbar-nav menu ' . str_replace('_', '-', $s),
						'walker' => new WalkerNavMenu()
					]);
		}
	}

	/**
	 * Add the global variables for all controllers
	 *
	 * @param array $templateVars
	 */
	public function getGlobalVariables() {
		$globalVars = [ ];

		// Sidebar items
		$active = ($u = User::getCurrent()) ? $u->isWithSidebar() : User::WITH_SIDEBAR_DEFAULT;
		$globalVars['widgets'] = [
			'right' => [
				'active' => $active,
				'content' => $this->widgets[Template::WIDGETS_RIGHT]
			],
			'footer' => [
				'active' => $active,
				'content' => $this->widgets[Template::WIDGETS_FOOTER]
			]
		];

		// Menus
		$globalVars['menu'] = [
			'header' => [
				'active' => has_nav_menu(Template::MENU_HEADER),
				'content' => $this->menus[Template::MENU_HEADER]
			],
			'footer' => [
				'active' => has_nav_menu(Template::MENU_FOOTER),
				'content' => $this->menus[Template::MENU_FOOTER]
			]
		];

		return ($this->configParams + $globalVars);
	}

	/**
	 * Render a partial
	 *
	 * @param string $templateName
	 * @param array $templateVars
	 */
	public function render($templateName, $templateVars = [], $addGlobalVariables = true) {
		if ($addGlobalVariables) {
			$templateVars = array_merge($templateVars, $this->getGlobalVariables());
		}
		return $this->template->getRenderEngine()->render($templateName, $templateVars);
	}

	/**
	 * Print head + template + footer
	 *
	 * @param string $templateName
	 *        	Template name to print
	 * @param array $templateVars
	 *        	Parameters to template
	 */
	public function renderPage($templateName, $templateVars = []) {
		$templateVars = array_merge($templateVars, $this->getGlobalVariables());
		$addGlobalVariablesToVars = false; // cause we already did it.
		echo $this->render('head', $templateVars, $addGlobalVariablesToVars);
		wp_head();
		echo '</head>';
		echo $this->render($templateName, $templateVars, $addGlobalVariablesToVars);
		wp_footer();
		echo $this->render('footer', $templateVars, $addGlobalVariablesToVars);
	}
}
{'fraction_non_alphanumeric': 0.1733280569845667, 'fraction_numerical': 0.0, 'mean_word_length': 3.438103599648815, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1765725', 'n_tokens_mistral': 2003, 'n_tokens_neox': 1732, 'n_words': 318}