Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenvanvliet committed Mar 14, 2008
1 parent ee0a4d7 commit 7ed4da7
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 11 deletions.
12 changes: 12 additions & 0 deletions formation/libraries/Event_Form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
class Event_Form_Core extends Model_Formation{

// protected $exclude=array('id','modified','created','user_id');
protected $form_fields=array();

protected $exclude=array('id','user_id');

protected $_model='Event_Model';


}
8 changes: 7 additions & 1 deletion formation/libraries/Formation.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,14 @@ public function add_element($type,$name=null)
if ($name==null)
throw new Kohana_Exception('formation.invalid_rule', get_class($rule));

$args=null;
if(count($args=func_get_args())>2)
{
$args=array_slice($args,2);
}

$type='Element_'.ucfirst(strtolower($type));
$this[$name]=new $type($name);
$this[$name]=new $type($name,$args);
}
return $this[$name];
}
Expand Down
2 changes: 2 additions & 0 deletions formation/libraries/Model_Formation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Model_Formation_Core extends Formation{
//Which fields to include
protected $form_fields=array();

protected $not_editable=array();

public function __construct($model=false,$guess_fields=true)
{
parent::__construct();
Expand Down
35 changes: 35 additions & 0 deletions formation/libraries/elements/Element_Csrf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php defined('SYSPATH') or die('No direct script access.');

class Element_Csrf_Core extends Element_Hidden {


public function __construct($name,$salt='lkjaslh')
{

parent::__construct($name);
if(is_array($salt))
{
$salt=$salt[0];
}
$no_csrf='no_csrf';

$session=Session::instance();

$hash=sha1(uniqid().$salt);

if($session->get($no_csrf,false)==false)
{
$session->set($no_csrf,$hash);
}
else
{
$hash=$session->get($no_csrf);
}

$this->set_value($hash);
$this->add_rule('Rule_Required');
$this->add_rule('Rule_Csrf',$hash);
}


} // End F
18 changes: 18 additions & 0 deletions formation/libraries/rules/Rule_Csrf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

class Rule_Csrf_Core extends Rule{

public function __construct($hash)
{

$this->hash=$hash;
}


public function is_valid($value)
{
$this->value=$value;
return ($this->value==$this->hash);
}

}
22 changes: 12 additions & 10 deletions formation/views/formation_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
?> </li>
<?php
else:
if ($label = $input->label()):
?> <li><?php echo $input->label();
endif;
echo $input->render();

if(($error_message=$input->error_message()) !== false):

?><label class="error" for="<?=$input->name?>"><?=$error_message ?></label><?php
endif; ?></li>
<?php
if(!($input instanceof Element_Hidden)):

if ($label = $input->label()):
?> <li><?php echo $input->label();
endif;
echo $input->render();

if(($error_message=$input->error_message()) !== false):

?><label class="error" for="<?=$input->name?>"><?=$error_message ?></label><?php
endif; ?></li>
<?php endif;
endif;

endforeach; ?>
Expand Down
File renamed without changes.
173 changes: 173 additions & 0 deletions test/head_.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php

class Head_Core extends ArrayObject{
// Head singleton
private static $instance;
/**
* Head instance of Head.
*/
public static function instance()
{
// Create the instance if it does not exist
empty(self::$instance) and new Head;

return self::$instance;
}

public function __construct()
{
$this['title'] =new Head_Title;
$this['base'] =new Head_Base;
$this['javascript'] =new Head_Javascript;
//$this['meta'] =new Head_Partial;
$this['css'] =new Head_Css;
$this['link'] =new Head_Link;

$this->setFlags(ArrayObject::ARRAY_AS_PROPS );
// Singleton instance
self::$instance = $this;
}
public function __tostring()
{
return (string) $this->render();
}
public function render()
{
$html='';
foreach($this as $field)
{
$html.=$field->render();
}
return $html;
}
public function append_script_file($file)
{
$this['javascript']['files'][]=$file;
}
public function append_script_src($script)
{
$this['javascript']['scripts'][]=$script;
}
public function append_css_file($file,$type='screen')
{
$this['css']['files'][]=array($file,$type);
return $this;
}
public function append_css_style($script)
{
$this['css']['styles'][]=$script;
return $this;
}
public function append_link($link,$rel='alternate',$type='application/rss+xml')
{
$this['link'][]=array($link,$rel,$type);
}
}

class Head_Partial extends Head_Core{

public function __construct()
{
$this->setFlags(ArrayObject::ARRAY_AS_PROPS);
}


}
class Head_Title extends Head_Partial{
public function set($title)
{
$this['title']=$title;
}
public function render()
{
return (string) '<title>'.$this['title'].'</title>'."\n\r";
}
}
class Head_Base extends Head_Partial{
public function set($base_href)
{
$this['base_href']=$base_href;
}
public function render()
{
return (string) '<base href="'.$this['base_href'].'" />'."\n\r";
}
}
class Head_Javascript extends Head_Partial{

public function __construct()
{
$this->setFlags(ArrayObject::ARRAY_AS_PROPS);
$this['files']=array();
$this['scripts']=array();
}
public function render()
{
$html='';
foreach($this as $type)
{
if($type=='files')
{
foreach($this['files'] as $field)
{
$html.=html::script($field);
}
}
else
{
foreach($this as $script)
{
$html.='<script type="text/javascript">'.$script.'</script>'."\r\n";
}
}
}
return $html;
}
}
class Head_Css extends Head_Partial{

public function __construct()
{
$this->setFlags(ArrayObject::ARRAY_AS_PROPS);
$this['files']=array();
$this['styles']=array();
}
public function render()
{
$html='';
foreach($this as $type)
{
if($type=='files')
{
foreach($this['files'] as $field)
{
$html.=html::stylesheet($field[0],$field[1]);
}
}
else
{
foreach($this['styles'] as $script)
{
$html.='<style type="text/css">'.$script.'</style>'."\r\n";
}

}
}

return $html;
}
}
class Head_Link extends Head_Partial
{
public function render()
{
$html='';
foreach($this as $link)
{
$html.=html::link($link[0],$link[1],$link[2]);
}
return $html;

}

}

0 comments on commit 7ed4da7

Please sign in to comment.