Permalink
Browse files

Kohana 3.1 upgrade

  • Loading branch information...
1 parent f806fd4 commit 1c0206a3680aa542e38b1b839a4b228d90addd7e Deepwinter committed Apr 22, 2011
@@ -0,0 +1,10 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Controller_Welcome extends Controller {
+
+ public function action_index()
+ {
+ $this->response->body('hello, world!');
+ }
+
+} // End Welcome
@@ -0,0 +1,16 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+return array(
+
+ 'driver' => 'file',
+ 'hash_method' => 'sha256',
+ 'hash_key' => 'aasd9asdf093as903s',
+ 'lifetime' => 1209600,
+ 'session_key' => 'auth_user',
+
+ // Username/password combinations for the Auth File driver
+ 'users' => array(
+ // 'admin' => 'b3154acf3a344170077d11bdb5fff31532f679a1919e716a02',
+ ),
+
+);
No changes.
@@ -41,15 +41,14 @@ public function __get($column){
if(in_array($column, $this->nonmappedfields)){
return parent::__get($column);
}
- //echo '<br>getting'.$column.'<br>';
-
+
//check for dbmap
$object = ORM::Factory('page', parent::__get('page_id'));
//echo 'FROM '.$object->id.'<br>';
$column = mop::dbmap( $object->template_id, $column);
//echo 'which maps to'.$column;
if(!$column){
- return null;
+ throw new Kohana_Exception('Column :column not found in content model', array(':column', $column));
}
if(strstr($column, 'object')){
@@ -5,62 +5,59 @@
*
*/
class Model_Page extends ORM {
- protected $_belongs_to = array(
- 'template'=>array()
- );
- protected $_has_one = array(
- 'template'=>array()
- );
-
- public $content = null;
-
- private $object_fields = array('loaded', 'template', 'primary_key', 'primary_val');
-
- public function __construct($id=NULL){
- parent::__construct($id);
- // $this->object_fields = array_merge($this->object_fields, array_keys($this->_column_cache) );
- }
- /**
- * * Allows a model to be loaded by username or email address.
- * */
- public function unique_key($id)
- {
- if ( ! empty($id) AND is_string($id) AND ! ctype_digit($id))
- {
- return 'slug';
- }
-
- return parent::unique_key($id);
- }
-
- /*
- * Function: __get
- * Custom getter for this model, links in appropriate content table
- * when related object 'content' is requested
- * */
- public function __get($column){
-
- if($column=='contenttable' && !isset($this->_related[$column])){
- $content = ORM::factory( inflector::singular('contents') );
- $content->setTemplateName($this->template->templatename); //set the templatename for dbmapping
- $this->_related[$column]=$content->where('page_id','=',$this->id)->find();
- if(!$this->_related[$column]->_loaded){
- throw new Kohana_User_Exception('BAD_MOP_DB', 'no content record for page '.$this->id);
- }
- return $this->_related[$column];
- } else if($column=='parent'){
- //return ORM::Factory('page', $this->parentid);
- } else {
- return parent::__get($column);
- }
- }
-
-
- /*
- Function: __set
- Custom setter, saves to appropriate contenttable
- */
+ protected $_belongs_to = array(
+ 'template' => array()
+ );
+ protected $_has_one = array(
+ 'template' => array()
+ );
+ public $content = null;
+ private $object_fields = array('loaded', 'template', 'primary_key', 'primary_val');
+
+ public function __construct($id=NULL) {
+ parent::__construct($id);
+ // $this->object_fields = array_merge($this->object_fields, array_keys($this->_column_cache) );
+ }
+
+ /**
+ * * Allows a model to be loaded by username or email address.
+ * */
+ public function unique_key($id) {
+ if (!empty($id) AND is_string($id) AND !ctype_digit($id)) {
+ return 'slug';
+ }
+
+ return parent::unique_key($id);
+ }
+
+ /*
+ * Function: __get
+ * Custom getter for this model, links in appropriate content table
+ * when related object 'content' is requested
+ * */
+
+ public function __get($column) {
+
+ if ($column == 'contenttable' && !isset($this->_related[$column])) {
+ $content = ORM::factory(inflector::singular('contents'));
+ $content->setTemplateName($this->template->templatename); //set the templatename for dbmapping
+ $this->_related[$column] = $content->where('page_id', '=', $this->id)->find();
+ if (!$this->_related[$column]->_loaded) {
+ throw new Kohana_User_Exception('BAD_MOP_DB', 'no content record for page ' . $this->id);
+ }
+ return $this->_related[$column];
+ } else if ($column == 'parent') {
+ return ORM::Factory('page', $this->parentid);
+ } else {
+ return parent::__get($column);
+ }
+ }
+
+ /*
+ Function: __set
+ Custom setter, saves to appropriate contenttable
+ */
public function __set($column, $value){
if($column=='contenttable'){
$this->_changed[$column] = $column;
@@ -140,7 +140,9 @@ public function action_savefield($id){
}
$page = ORM::Factory('page')->find($id);
- return array('value'=>$page->contenttable->$_POST['field']);
+ //echo $_POST['field'];
+ $value = $page->contenttable->$_POST['field'];
+ $this->response->data(array('value'=>$value));
}
/*
@@ -2,4 +2,7 @@
$config['navigationRequest'] = 'navigation';
+$config['layout'] = 'LayoutAdmin';
+//$config['authrole'] = 'admin';
+
return $config;
@@ -14,8 +14,6 @@
'modules/mop/MoPModules.js'
);
-$config['layout'] = 'LayoutAdmin';
-$config['authrole'] = 'admin';
$config['defaultsettings']['editable_title'] = true;
//- - if set all titles editable
@@ -27,11 +27,13 @@ public function action_data($uri)
$subRequest = Request::Factory($uri);
$data = $subRequest->execute()->data();
} catch (Exception $e) {
+ //return HTML from exception
+ $message = $e->getString() . $e->getTrace();
$ajaxResponse = array(
'returnValue' => TRUE,
+ 'response' => $message
+
);
- echo "CALL A FUNCITON HERE TO COMMUNICATION EXCEPTION TO CLIENTSIDE";
- throw $e;
return;
}
$ajaxResponse = array(
@@ -18,17 +18,69 @@ class Controller_MOP extends Controller {
public function __construct($request, $response){
parent::__construct($request, $response);
+ $this->controllerName = strtolower(substr(get_class($this), 11));
+ $this->checkAccess();
if($request->is_initial()){
self::$topController = $this;
}
//look up all matching js and css based off controller name
- $this->controllerName = strtolower(substr(get_class($this), 11));
$this->loadResources($this->controllerName);
}
+ /*
+ * Function: checkAccess()
+ * Default function for acccess checking for a controller. Can be overridden in child classes
+ * Checks logged in user against authrole array in config file for controller
+ * Parameters:nothing, except config file
+ * Returns: nothing
+ */
+ public function checkAccess(){
+ //Authentication check
+ $role = Kohana::config(strtolower($this->controllerName).'.authrole', FALSE, FALSE);
+
+ //checked if logged in
+ if($role && !Auth::instance()->logged_in()){
+ Request::current()->redirect('auth/login/'.Request::initial()->uri());
+ exit;
+ }
+
+ if(is_array($role)){
+ $accessGranted = false;
+ foreach($role as $aRole){
+ if($role=='admin'){
+ if(Kohana::config('mop.staging_enabled') && !Kohana::config('mop.staging')){
+ $redirect = 'staging/'. Router::$current_uri;
+ url::redirect($redirect);
+ }
+ }
+
+ if(moputil::checkRoleAccess($aRole)){
+ $accessGranted = true;
+ }
+ }
+ } else {
+ if($role=='admin'){
+ if(Kohana::config('mop.staging_enabled') && !Kohana::config('mop.staging')){
+ $redirect = 'staging/'. Router::$current_uri;
+ url::redirect($redirect);
+ }
+ }
+
+ $accessGranted = moputil::checkRoleAccess($role);
+ }
+
+ if(!$accessGranted){
+ $redirect = 'accessdenied';
+ url::redirect($redirect);
+ exit;
+ }
+
+ }
+
+
protected function loadResources($key){
if(is_subclass_of(self::$topController, 'Controller_MOP')){
//should add to self, then merge into topController
@@ -0,0 +1,103 @@
+<?
+
+/*
+ * Class: moputil
+ * Utility helper class
+ */
+Class moputil {
+
+ /*
+ * Function: getMicroSeconds()
+ * Returns a microseconds of current time as a 3 place float
+ * Returns: Microseconds
+ */
+ public static function getMicroSeconds(){
+ list($usec, $sec) = explode(" ", microtime());
+ return number_format((float)$usec, 3);
+ }
+
+ /*
+ * Function getMicroTimestamp()
+ * Creates a timestamp including microseconds
+ * Returns: Microsecond timestamp
+ */
+ public static function getMicroTimestamp(){
+ $timestamp = date('YmdHis') . substr(moputil::getMicroSeconds(), 1) ;
+ Kohana::log('info', 'TIMESTAMP: '.$timestamp);
+ return $timestamp;
+ }
+
+ /*
+ * Function: img($file, $prefix, $alt, $extra = null){
+ * Echos an image tag as built from a mop file object.
+ * Parameters:
+ * $file - mop file object
+ * $prefix - the prefix to output
+ * $alt - alt tag phrase
+ * $extra - extra stuff to go inside the tag attributes area
+ * Returns: if file exists, return the img src tag code, otherwise return null
+ */
+ public static function img($file, $prefix, $alt, $extra = null){
+ if(!$file->$prefix->fullpath
+ || !file_exists($file->$prefix->fullpath)){
+ return null;
+ }
+ $img = sprintf('<img src="%s" width="%s" height="%s" alt="%s" %s>',
+ $file->$prefix->fullpath,
+ $file->$prefix->width,
+ $file->$prefix->height,
+ $alt,
+ $extra);
+ return $img;
+ }
+
+ /*
+ * Function: checkRoleAccess($role)
+ * Checks whether the currently logged in user has a certain role
+ * Parameters:
+ * $role - the role to check against
+ * Returns: true or false
+ */
+ public static function checkRoleAccess($role){
+
+ if($role && !Auth::instance()->logged_in($role)){
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /*
+ * Function: decode_recurse($value)
+ */
+ private static function decode_recurse($value){
+ //handle object?
+ if(!is_array($value)){
+ return html_entity_decode($value);
+ } else {
+ for($i=0, $keys=array_keys($value), $count=count($value); $i<$count; $i++){
+ $value[$keys[$i]] = moputil::decode_recurse($value[$keys[$i]]);
+ }
+ return $value;
+ }
+ }
+
+ public static $modulos;
+ public static $modulosOptionsCount;
+ public static function modulo($identifier, $options){
+ self::$modulosOptionsCount = count( $options );
+ if(!is_array(self::$modulos)){
+ self::$modulos = array();
+ }
+ if(!isset(self::$modulos[$identifier])){
+ self::$modulos[$identifier] = 0;
+ }
+ $index = self::$modulos[$identifier];
+ self::$modulos[$identifier]++;
+ return $options[$index%self::$modulosOptionsCount];
+
+ }
+
+
+
+}
@@ -1 +0,0 @@
-This is the default public footer
@@ -1 +1 @@
-This is the default public header
+<? echo Request::Factory('mopauth')->execute()->body() ;?>
@@ -0,0 +1,12 @@
+<?
+
+class KeepAlive_Controller extends Controller {
+
+ public function index(){
+ if(Auth::instance()->logged_in()){
+ echo 'true';
+ } else {
+ echo 'false';
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 1c0206a

Please sign in to comment.