<?php namespace Tussendoor\Reloadify\Controllers;

use Tussendoor\Reloadify\Plugin;

abstract class Controller
{
    /**
     * Helper method for returning the desired template
     *
     * @param  string $path
     * @param  array $variables
     * @param  string $extension
     * @return void
     */
    public function template(string $path, array $variables = [], string $extension = 'php')
    {
        $file = Plugin::config('plugin.viewpath') . $path . '.' . $extension;

        if (! file_exists($file)) return '';

        extract($variables);

        ob_start();
        require $file;
        echo ob_get_clean();
    }

    /**
     * Return the current language
     *
     * @since 1.1.4 added param $wpmlOnly with a default true value
     *
     * @param  int $user_id
     * @return string
     */
    public function getCurrentLocale(int $user_id = 0)
    {
	    if(!function_exists('pll_current_language')) {
		    return apply_filters('wpml_current_language', '');
	    }

	    // Polylang support
	    return pll_current_language();


//	    if ($user_id != 0) {
//		    return substr(get_user_locale($user_id), 0, 2);
//	    }

    }
}
