| 1 |
<?php |
|---|
| 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 |
function link_to_function($name, $function, $html_options = array()) |
|---|
| 37 |
{ |
|---|
| 38 |
$html_options = _parse_attributes($html_options); |
|---|
| 39 |
|
|---|
| 40 |
$html_options['href'] = isset($html_options['href']) ? $html_options['href'] : '#'; |
|---|
| 41 |
if ( isset($html_options['confirm']) ) |
|---|
| 42 |
{ |
|---|
| 43 |
$confirm = escape_javascript($html_options['confirm']); |
|---|
| 44 |
unset($html_options['confirm']); |
|---|
| 45 |
$function = "if(window.confirm('$confirm')){ $function;}"; |
|---|
| 46 |
} |
|---|
| 47 |
$html_options['onclick'] = $function.'; return false;'; |
|---|
| 48 |
|
|---|
| 49 |
return content_tag('a', $name, $html_options); |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
function button_to_function($name, $function, $html_options = array()) |
|---|
| 60 |
{ |
|---|
| 61 |
$html_options = _parse_attributes($html_options); |
|---|
| 62 |
|
|---|
| 63 |
$html_options['onclick'] = $function.'; return false;'; |
|---|
| 64 |
$html_options['type'] = 'button'; |
|---|
| 65 |
$html_options['value'] = $name; |
|---|
| 66 |
|
|---|
| 67 |
return tag('input', $html_options); |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
function javascript_tag($content = null) |
|---|
| 79 |
{ |
|---|
| 80 |
if (!is_null($content)) |
|---|
| 81 |
{ |
|---|
| 82 |
return content_tag('script', javascript_cdata_section($content), array('type' => 'text/javascript')); |
|---|
| 83 |
} |
|---|
| 84 |
else |
|---|
| 85 |
{ |
|---|
| 86 |
ob_start(); |
|---|
| 87 |
} |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
function end_javascript_tag() |
|---|
| 91 |
{ |
|---|
| 92 |
echo javascript_tag(ob_get_clean()); |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
function javascript_cdata_section($content) |
|---|
| 96 |
{ |
|---|
| 97 |
return "\n//".cdata_section("\n$content\n//")."\n"; |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
function if_javascript() |
|---|
| 105 |
{ |
|---|
| 106 |
if (!sfContext::getInstance()->getRequest()->isXmlHttpRequest()) |
|---|
| 107 |
{ |
|---|
| 108 |
ob_start(); |
|---|
| 109 |
} |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
function end_if_javascript() |
|---|
| 117 |
{ |
|---|
| 118 |
if (!sfContext::getInstance()->getRequest()->isXmlHttpRequest()) |
|---|
| 119 |
{ |
|---|
| 120 |
$content = ob_get_clean(); |
|---|
| 121 |
echo javascript_tag("document.write('" . esc_js_no_entities($content) . "');"); |
|---|
| 122 |
} |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
function array_or_string_for_javascript($option) |
|---|
| 133 |
{ |
|---|
| 134 |
if (is_array($option)) |
|---|
| 135 |
{ |
|---|
| 136 |
return "['".join('\',\'', $option)."']"; |
|---|
| 137 |
} |
|---|
| 138 |
else if (is_string($option) && $option[0] != "'") |
|---|
| 139 |
{ |
|---|
| 140 |
return "'$option'"; |
|---|
| 141 |
} |
|---|
| 142 |
return $option; |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
function options_for_javascript($options) |
|---|
| 152 |
{ |
|---|
| 153 |
$opts = array(); |
|---|
| 154 |
foreach ($options as $key => $value) |
|---|
| 155 |
{ |
|---|
| 156 |
if (is_array($value)) |
|---|
| 157 |
{ |
|---|
| 158 |
$value = options_for_javascript($value); |
|---|
| 159 |
} |
|---|
| 160 |
$opts[] = $key.":".boolean_for_javascript($value); |
|---|
| 161 |
} |
|---|
| 162 |
sort($opts); |
|---|
| 163 |
|
|---|
| 164 |
return '{'.join(', ', $opts).'}'; |
|---|
| 165 |
} |
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
function boolean_for_javascript($bool) |
|---|
| 175 |
{ |
|---|
| 176 |
if (is_bool($bool)) |
|---|
| 177 |
{ |
|---|
| 178 |
return ($bool===true ? 'true' : 'false'); |
|---|
| 179 |
} |
|---|
| 180 |
return $bool; |
|---|
| 181 |
} |
|---|
| 182 |
|
|---|