Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 8a9772e099
Fetching contributors…

Cannot retrieve contributors at this time

file 252 lines (242 sloc) 8.462 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
<?php
/**
* Modifies the CakePHP FormHelper to support blueprintCSS
*
* @author Jose Diaz-Gonzalez
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @link http://josediazgonzalez/code/blueprinthelper/
* @package app
* @subpackage app.views.helpers
* @version .7
*/
class BlueprintHelper extends AppHelper {
/**
* Array of helpers in use by the BlueprintHelper
*
* @var string
**/
var $helpers = array('Form', 'Html');
/**
* The value of the class attribute assigned to the wrapper div for every label
* in the format elementType => class
*
* @var array
*/
var $_labelClass = array();

/**
* The value of the class attribute assigned to the wrapper div for most elements
*
* @var string
*/
var $_inputClass = array();

/**
* The value of the class assigned outside the input element if necessary
*
* @var string
**/
var $_specialClass = array();

/**
* Sets up Blueprint for inclusion in the header
*
* @param array $options Additional options to be set if the plugin settings need to be configured
* @return string
* @access public
* @author Jose Diaz-Gonzalez
**/
function setup($options = array()) {
$options = array_merge(array('screen' => 'blueprint/screen','print' => 'blueprint/print'), $options);
$head = $this->Html->css($options['screen'], 'stylesheet', array('media' => 'screen, projection'));
$head .= $this->Html->css($options['print'], 'stylesheet', array('media' => 'print'));
return $head;
}

/**
* Sets up the IE stylesheet for the header
*
* @param array $options Additional options to be set if the plugin settings need to be configured
* @return string
* @access public
* @author Jose Diaz-Gonzalez
**/
function ie($options = array()) {
$options = array_merge(array('ie' => 'blueprint/ie'), $options);
$head = "<!--[if IE]>";
$head .= $this->Html->css($options['ie'], 'stylesheet', array('media' => 'screen'));
$head .= "<![endif]-->";
return $head;
}
/**
* Wrapper for Html Helper that includes a plugin(s) in the header
*
* @param string $path This is the path within the blueprint plugins folder to the plugin(s)
* containing the plugin. Do not include "screen.css" or the trailing slash
* @param array $options Additional options to be set if the plugin settings need to be configured
* @return string
* @access public
* @author Jose Diaz-Gonzalez
**/
function plugins($path = NULL, $options = array()) {
$styles = '';
if (!empty($path)) :
$options = array_merge(array('blueprint' => 'blueprint/plugins','file' => 'screen', 'media' => 'screen, projection'), $options);
if (is_array($path)) :
foreach ($path as $plugin) :
$styles .= $this->Html->css($options['blueprint'] . "//$plugin//" . $options['file'], 'stylesheet', array('media' => $options['media']));
endforeach;
else :
$styles = $this->Html->css($options['blueprint'] . "//$path//" . $options['file'], 'stylesheet', array('media' => $options['media']));
endif;
endif;
return $styles;
}

/**
* Caches the blueprintCSS markup needed for labels and form elements
*
* @param string $label The value assigned to the class attribute of the div wrapper
* @param string $input
* @access public
* @author Dave Mahon
*/
function configure($elements, $label = '', $input = '', $special = '') {
if (is_array($elements)) {
foreach ($elements as $element){
$this->_labelClass[$element] = $label;
$this->_inputClass[$element] = $input;
if (!empty($special)) $this->_specialClass[$element] = $special;
}
} else {
$this->_labelClass[$elements] = $label;
$this->_inputClass[$elements] = $input;
if (!empty($special)) $this->_specialClass[$elements] = $special;
}
}

/**
* Wrapper for FormHelper->input that adds blueprintCSS markup
*
* @param string $fieldName This should be "Modelname.fieldname", "Modelname/fieldname" is deprecated
* @param array $options
* @param boolean $tagging if true
* @return string
* @access public
* @author Dave Mahon
*/
function input($fieldName, $options = array(), $tagging = false) {
if (!isset($options['type'])) $options['type'] = 'text';

if (!empty($this->_specialClass[$options['type']])){
$options = array_merge(array(
'before' => '<div class="' . $this->_labelClass[$options['type']] . '">',
'between' => '</div><div class="' . $this->_specialClass[$options['type']] . '"><div class="' . $this->_inputClass[$options['type']] . '">',
'after' => '</div></div>'
), $options);
} else {
$options = array_merge(array(
'before' => '<div class="' . $this->_labelClass[$options['type']] . '">',
'between' => '</div><div class="' . $this->_inputClass[$options['type']] . '">',
'after' => '</div>'
), $options);
}
if ($tagging) :
App::import('Helper', 'Tagging.Tagging');
return $this->Tagging->input($fieldName, $options);
endif;
return $this->Form->input($fieldName, $options);
}

/**
* Wrapper for FormHelper->end that adds blueprintCSS markup
*
* If $options is set a form submit button will be created.
*
* @param mixed $options as a string will use $options as the value of button,
* array usage:
* array('label' => 'save'); value="save"
* array('label' => 'save', 'name' => 'Whatever'); value="save" name="Whatever"
* array('name' => 'Whatever'); value="Submit" name="Whatever"
* array('label' => 'save', 'name' => 'Whatever', 'div' => 'good') <div class="good"> value="save" name="Whatever"
* array('label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good')); <div class="good"> value="save" name="Whatever"
*
* @return string a closing FORM tag optional submit button.
* @access public
* @author Dave Mahon
*/
function end($options = null) {
if ($options !== null) :
if (is_string($options)) $options = array('label'=>$options);
if (isset($options['div'])) :
$options['div'] = $this->addClass($options['div'], 'clear');
else :
$options['div'] = array('class'=>'clear');
endif;
endif;
return $this->Form->end($options);
}

/**
* Wrapper for HtmlHelper->div that adds blueprintCSS markup for class clear
*
* @param string $fieldName This should be "Modelname.fieldname", "Modelname/fieldname" is deprecated
* @param string $class CSS class name of the div element.
* @param string $text String content that will appear inside the div element.
* If null, only a start tag will be printed
* @param array $attributes Additional HTML attributes of the DIV tag
* @param boolean $escape If true, $text will be HTML-escaped
* @return string The formatted DIV element
* @access public
* @author Dave Mahon
*/
function clear($class = null, $text = null, $attributes = array(), $escape = false) {
if (strlen($class) > 0) :
$class .= ' clear';
else :
$class = 'clear';
endif;
return $this->Html->div($class, $text, $attributes, $escape);
}

/**
* Automatically wraps text(s) with classes/ids
*
* @param boolean $wrapAll whether or not to wrap each text with the same class. true by default
* @param string/array $texts string or array of text that should be wrapped
* @param string/array $classes string or array of classes to wrap the texts
* @param string/array $ids string or array of ids to wrap the texts
* @return void
* @author Jose Diaz-Gonzalez
**/
function span($wrapAll = true, $texts = NULL, $classes = NULL, $ids = null) {
$finalText = '';
if (is_array($texts)) :
if ($wrapAll) :
foreach ($texts as $text) :
$finalText .= "<div";
if (isset($ids)) :
$finalText .= " id=\"$ids\"";
endif;
if (isset($classes)) :
$finalText .= " class=\"$classes\"";
endif;
$finalText .= ">$text</div>";
endforeach;
else :
$i = 0;
foreach($texts as $text) :
$finalText .= "<div";
if (isset($ids)) :
$finalText .= " id=\"" . $ids[$i] . "\"";
endif;
if (isset($classes)) :
$finalText .= " class=\"" . $classes[$i] . "\"";
endif;
$finalText .= ">$text</div>";
endforeach;
endif;
else :
$finalText .= "<div";
if (isset($ids)) :
$finalText .= " id=\"" . $ids[$i] . "\"";
endif;
if (isset($classes)) :
$finalText .= " class=\"" . $classes[$i] . "\"";
endif;
$finalText .= ">$text</div>";
endif;
return $finalText;
}
}
?>
Something went wrong with that request. Please try again.