Smutty
MVC Framework
View Code: Smutty_Smarty
Browse: All · Classes · Plugins
1
<?php
2
3
/**
4
* this class provides the smarty plugin functionality for
5
* Smutty. the plugins usually just pass off their work here
6
* so that it can be centralised and unit tested.
7
*
8
*/
9
10
class Smutty_Smarty extends Smutty_Object {
11
12
/**
13
* returns a "real" field name for a "shortcut" field name
14
*
15
* eg. user.body becomes user[body]
16
*
17
* @param String $str the shortcut field name
18
* @return String the real field name
19
*
20
*/
21
23
24
$parts = explode( '.', $str );
25
26
return sizeof($parts) == 1
27
? $parts[0] : $parts[0] . '[' . $parts[1] . ']';
28
29
}
30
31
/**
32
* returns an HTML element with the specified attributes
33
*
34
* @param array $params parameters
35
* @param Smarty $smarty smarty object
36
* @return String html element string
37
*
38
*/
39
41
42
$name = strtolower( $name );
43
$singles = array( 'link', 'input', 'hr', 'br' );
44
$isSingle = false;
45
46
// is it a single element?
47
foreach ( $singles as $single )
48
if ( $single == $name ) {
49
$isSingle = true;
50
break;
51
}
52
53
// now put the element together
54
$elem = '<' . $name . self::buildAttrString($attrs,$smarty);
55
if ( $isSingle )
56
$elem .= ' />';
57
else
58
$elem .= '>';
59
60
return $elem;
61
62
}
63
64
/**
65
* builds an element attributes string from a hash
66
*
67
* @param array $attrs assoc array of attributes
68
* @param Smarty $smarty the smarty object
69
* @return String the attribute string
70
*
71
*/
72
74
75
$smarty->depend( 'modifier', 'escape' );
76
77
// build the attribute string
78
$attrString = '';
79
foreach ( $attrs as $key => $value )
80
if ( $value )
81
$attrString .= ' ' . $key . '="' . smarty_modifier_escape($value) . '"';
82
83
return $attrString;
84
85
}
86
87
}
88
89
?>
The code shown here is the code that is currently running this site. If you want to view the latest SVN version of the code then go to the Subversion repository.