2014-02-13 03:10:20 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class overrides Kohana's URL
|
|
|
|
*
|
|
|
|
* @package lnApp
|
|
|
|
* @category Modifications
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2014 Deon George
|
|
|
|
* @license http://dev.leenooks.net/license.html
|
|
|
|
*/
|
2014-02-17 00:29:11 +00:00
|
|
|
abstract class lnApp_URL extends Kohana_URL {
|
2014-02-13 03:10:20 +00:00
|
|
|
// Our method paths for different functions
|
|
|
|
public static $method_directory = array(
|
|
|
|
'admin'=>'a',
|
|
|
|
'user'=>'u',
|
|
|
|
);
|
|
|
|
|
|
|
|
public static function admin_url() {
|
|
|
|
return (Request::current() AND (
|
|
|
|
(Auth::instance()->logged_in() AND ! empty(URL::$method_directory[strtolower(Request::current()->directory())]))
|
|
|
|
OR in_array(strtolower(Request::current()->controller()),array('login','oauth'))));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to reveal the real directory for a URL
|
|
|
|
*/
|
|
|
|
public static function dir($dir) {
|
|
|
|
// Quick check if we can do something here
|
|
|
|
if (! in_array(strtolower($dir),URL::$method_directory))
|
|
|
|
return $dir;
|
|
|
|
|
|
|
|
// OK, we can, find it.
|
|
|
|
foreach (URL::$method_directory as $k=>$v)
|
|
|
|
if (strtolower($dir) == $v)
|
|
|
|
return ucfirst($k);
|
|
|
|
|
|
|
|
// If we get here, we didnt have anything.
|
|
|
|
return $dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper to provide a URL::site() link based on function
|
|
|
|
*/
|
|
|
|
public static function link($dir,$src,$site=FALSE) {
|
|
|
|
if (! $dir)
|
|
|
|
return $src;
|
|
|
|
|
|
|
|
if (! array_key_exists($dir,URL::$method_directory))
|
|
|
|
throw new Kohana_Exception('Unknown directory :dir for :src',array(':dir'=>$dir,':src'=>$src));
|
|
|
|
|
|
|
|
$x = URL::$method_directory[$dir].'/'.$src;
|
|
|
|
|
|
|
|
return $site ? URL::site($x) : $x;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function navbar() {
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
foreach (array_reverse(self::$method_directory) as $k=>$v)
|
|
|
|
switch ($k) {
|
2014-09-08 13:42:05 +00:00
|
|
|
case 'admin': $result[$k] = array('name'=>'Administrator','icon'=>'fa-globe');
|
2014-02-13 03:10:20 +00:00
|
|
|
break;
|
|
|
|
|
2014-09-29 12:06:38 +00:00
|
|
|
case 'user': $result[$k] = array('name'=>(array_key_exists('auth',Kohana::modules()) AND $x=Auth::instance()->get_user()) ? $x->name() : 'Guest','icon'=>'icon-user');
|
2014-02-13 03:10:20 +00:00
|
|
|
break;
|
|
|
|
|
2014-09-08 13:42:05 +00:00
|
|
|
default: $result[$k] = array('name'=>$k,'icon'=>'fa-question-sign');
|
2014-02-13 03:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|