projects
/
platal.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
make add(Js|Css)Link don't need the extra css/ or javascript/ link, so
[platal.git]
/
classes
/
Platal.php
diff --git
a/classes/Platal.php
b/classes/Platal.php
index
cf888cc
..
c34d34d
100644
(file)
--- a/
classes/Platal.php
+++ b/
classes/Platal.php
@@
-19,8
+19,6
@@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
-define('PL_OK', 0);
-define('PL_NEEDLOGIN', 1);
define('PL_FORBIDDEN', 403);
define('PL_NOT_FOUND', 404);
define('PL_FORBIDDEN', 403);
define('PL_NOT_FOUND', 404);
@@
-29,32
+27,40
@@
class Platal
var $__mods;
var $__hooks;
var $__mods;
var $__hooks;
+ var $ns;
var $path;
var $path;
- var $a
uth
;
+ var $a
rgv
;
function Platal()
{
function Platal()
{
- $this->path = trim(Get::_get('p', null), '/');
+ $modules = func_get_args();
+ $this->path = trim(Get::_get('n', null), '/');
$this->__mods = array();
$this->__hooks = array();
$this->__mods = array();
$this->__hooks = array();
- foreach (glob(dirname(__FILE__).'/../modules/*.php') as $module) {
- $module = basename($module, '.php');
- $m =& PLModule::factory($this, $module);
- $this->__mods[$module] =& $m;
+ array_unshift($modules, 'core');
+ foreach ($modules as $module) {
+ $this->__mods[$module] = $m = PLModule::factory($module);
$this->__hooks += $m->handlers();
}
$this->__hooks += $m->handlers();
}
-
- krsort($this->__hooks);
}
}
- function
load_class($cls
)
+ function
pl_self($n = null
)
{
{
- require_once dirname(__FILE__).'/../classes/'.$cls.'.php';
+ if (is_null($n))
+ return $this->path;
+
+ if ($n >= 0)
+ return join('/', array_slice($this->argv, 0, $n + 1));
+
+ if ($n <= -count($this->argv))
+ return $this->argv[0];
+
+ return join('/', array_slice($this->argv, 0, $n));
}
}
- function
call_hook(&$page
)
+ function
find_hook(
)
{
$p = $this->path;
{
$p = $this->path;
@@
-64,37
+70,64
@@
class Platal
$p = substr($p, 0, strrpos($p, '/'));
}
$p = substr($p, 0, strrpos($p, '/'));
}
+
if (empty($this->__hooks[$p])) {
if (empty($this->__hooks[$p])) {
- return
PL_NOT_FOUND
;
+ return
null
;
}
$hook = $this->__hooks[$p];
if (!is_callable($hook['hook'])) {
}
$hook = $this->__hooks[$p];
if (!is_callable($hook['hook'])) {
- return
PL_NOT_FOUND
;
+ return
null
;
}
}
- $args = explode('/', substr($this->path, strlen($p) + 1));
- if ($args[0] != '') {
- array_unshift($args, &$page);
- } else {
- $args = array(&$page);
+ $this->argv = explode('/', substr($this->path, strlen($p)));
+ $this->argv[0] = $p;
+
+ return $hook;
+ }
+
+ function call_hook(&$page)
+ {
+ $hook = $this->find_hook();
+
+ if (is_null($hook)) {
+ return PL_NOT_FOUND;
}
}
- if ($hook['auth'] > Session::get('auth', AUTH_PUBLIC)) {
- $_SESSION['session']->doAuth($page);
+ $args = $this->argv;
+ $args[0] = &$page;
+
+ if ($hook['auth'] > S::v('auth', AUTH_PUBLIC)) {
+ // FIXME: don't use 'session' object anymore
+ if (!$_SESSION['session']->doAuth()) {
+ $this->force_login($page);
+ }
}
}
+
return call_user_func_array($hook['hook'], $args);
}
return call_user_func_array($hook['hook'], $args);
}
+ function force_login(&$page)
+ {
+ if (S::logged() and !$new_name) {
+ $page->changeTpl('password_prompt_logged.tpl');
+ $page->addJsLink('do_challenge_response_logged.js');
+ } else {
+ $page->changeTpl('password_prompt.tpl');
+ $page->addJsLink('do_challenge_response.js');
+ }
+ $page->run();
+ }
+
function run()
{
global $page;
function run()
{
global $page;
- new_skinned_page('index.tpl'
, AUTH_PUBLIC
);
+ new_skinned_page('index.tpl');
if (empty($this->path)) {
if (empty($this->path)) {
- $
page->run()
;
+ $
this->path = 'index'
;
}
switch ($this->call_hook($page)) {
}
switch ($this->call_hook($page)) {
@@
-106,8
+139,19
@@
class Platal
$this->__mods['core']->handler_404($page);
break;
}
$this->__mods['core']->handler_404($page);
break;
}
+ $page->assign_by_ref('platal', $this);
$page->run();
}
$page->run();
}
+
+ function on_subscribe($forlife, $uid, $promo, $pass)
+ {
+ $args = func_get_args();
+ foreach ($this->__mods as $mod) {
+ if (!is_callable($mod, 'on_subscribe'))
+ continue;
+ call_user_func_array(array($mod, 'on_subscribe'), $args);
+ }
+ }
}
?>
}
?>