Created
February 26, 2011 18:31
-
-
Save callumacrae/845473 to your computer and use it in GitHub Desktop.
The plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class HomeController extends Controller | |
{ | |
function index() | |
{ | |
$this->load('auth'); | |
$this->auth->login('callum', 'test', true) | |
require($this->view('home_body')); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//include includes | |
//include controller | |
$controller = new HomeController; | |
$controller->index(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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