Skip to content

Instantly share code, notes, and snippets.

@callumacrae
Created February 26, 2011 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callumacrae/845473 to your computer and use it in GitHub Desktop.
Save callumacrae/845473 to your computer and use it in GitHub Desktop.
The plugin
<?php
namespace lynx\Plugins;
class Auth extends Plugin
{
public function login($user, $pass, $remember)
{
$user = $this->db->select(array(
'FROM' => $this->config['table'],
'WHERE' => array(
'user' => $user,
'pass' => $this->hash->pbkdf2($pass, $user),
),
));
$result = $user->fetchObject();
if (is_object($result))
{
if ($result->active !== 1)
{
echo 'Error: account not active';
}
$this->set_session($result, $remember, true);
return true;
}
else
{
$this->failed = true;
$this->logout();
return false;
}
}
}
<?php
class Controller
{
public function load($module)
{
$path = PATH_INDEX . '/lynx/plugins/' . $module . '/';
if (!is_dir($path))
{
trigger_error('Could not find module: directory ' . $path . ' not found', E_USER_ERROR);
return false;
}
$path .= $module . '.php';
if (!is_readable($path))
{
trigger_error('Could not load module: file ' . $path . ' not found', E_USER_ERROR);
return false;
}
require($path);
$module = '\\lynx\\plugins\\' . $module;
$this->$module = new $module($module);
$this->hooks->modules[$module] = true;
if ($plugin)
{
$module =& $this->$module;
return $module;
}
return true;
}
<?php
class HomeController extends Controller
{
function index()
{
$this->load('auth');
$this->auth->login('callum', 'test', true)
require($this->view('home_body'));
}
}
<?php
//include includes
//include controller
$controller = new HomeController;
$controller->index();
<?php
namespace lynx\Plugins;
abstract class Plugin
{
public $config = array();
public function __construct($module)
{
$path = PATH_INDEX . '/lynx/plugins/' . $module . '/config.php';
if (!is_readable($path))
{
return false;
}
include($path);
$this->config = new Config($config, $module);
if (method_exists($this, 'lynx_construct'))
{
$this->lynx_construct();
}
return 1;
}
public function get_plugin($plugin)
{
$controller =& $GLOBALS['controller'];
return $controller->load($plugin);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment