| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
function link_to2($name, $routeName, $params, $options = array()) |
|---|
| 24 |
{ |
|---|
| 25 |
$params = array_merge(array('sf_route' => $routeName), is_object($params) ? array('sf_subject' => $params) : $params); |
|---|
| 26 |
|
|---|
| 27 |
return link_to1($name, $params, $options); |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
function link_to1($name, $internal_uri, $options = array()) |
|---|
| 34 |
{ |
|---|
| 35 |
$html_options = _parse_attributes($options); |
|---|
| 36 |
|
|---|
| 37 |
$html_options = _convert_options_to_javascript($html_options); |
|---|
| 38 |
|
|---|
| 39 |
$absolute = false; |
|---|
| 40 |
if (isset($html_options['absolute_url'])) |
|---|
| 41 |
{ |
|---|
| 42 |
$html_options['absolute'] = $html_options['absolute_url']; |
|---|
| 43 |
unset($html_options['absolute_url']); |
|---|
| 44 |
} |
|---|
| 45 |
if (isset($html_options['absolute'])) |
|---|
| 46 |
{ |
|---|
| 47 |
$absolute = (boolean) $html_options['absolute']; |
|---|
| 48 |
unset($html_options['absolute']); |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
$html_options['href'] = url_for($internal_uri, $absolute); |
|---|
| 52 |
|
|---|
| 53 |
if (isset($html_options['query_string'])) |
|---|
| 54 |
{ |
|---|
| 55 |
$html_options['href'] .= '?'.$html_options['query_string']; |
|---|
| 56 |
unset($html_options['query_string']); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
if (isset($html_options['anchor'])) |
|---|
| 60 |
{ |
|---|
| 61 |
$html_options['href'] .= '#'.$html_options['anchor']; |
|---|
| 62 |
unset($html_options['anchor']); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
if (is_object($name)) |
|---|
| 66 |
{ |
|---|
| 67 |
if (method_exists($name, '__toString')) |
|---|
| 68 |
{ |
|---|
| 69 |
$name = $name->__toString(); |
|---|
| 70 |
} |
|---|
| 71 |
else |
|---|
| 72 |
{ |
|---|
| 73 |
throw new sfException(sprintf('Object of class "%s" cannot be converted to string (Please create a __toString() method).', get_class($name))); |
|---|
| 74 |
} |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
if (!strlen($name)) |
|---|
| 78 |
{ |
|---|
| 79 |
$name = $html_options['href']; |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
return content_tag('a', $name, $html_options); |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
function url_for2($routeName, $params = array(), $absolute = false) |
|---|
| 89 |
{ |
|---|
| 90 |
$params = array_merge(array('sf_route' => $routeName), is_object($params) ? array('sf_subject' => $params) : $params); |
|---|
| 91 |
|
|---|
| 92 |
return url_for1($params, $absolute); |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
function url_for1($internal_uri, $absolute = false) |
|---|
| 99 |
{ |
|---|
| 100 |
return sfContext::getInstance()->getController()->genUrl($internal_uri, $absolute); |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
function url_for() |
|---|
| 122 |
{ |
|---|
| 123 |
|
|---|
| 124 |
$arguments = func_get_args(); |
|---|
| 125 |
if (is_array($arguments[0]) || '@' == substr($arguments[0], 0, 1) || false !== strpos($arguments[0], '/')) |
|---|
| 126 |
{ |
|---|
| 127 |
return call_user_func_array('url_for1', $arguments); |
|---|
| 128 |
} |
|---|
| 129 |
else |
|---|
| 130 |
{ |
|---|
| 131 |
return call_user_func_array('url_for2', $arguments); |
|---|
| 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 |
function link_to() |
|---|
| 175 |
{ |
|---|
| 176 |
|
|---|
| 177 |
$arguments = func_get_args(); |
|---|
| 178 |
if (empty($arguments[1]) || is_array($arguments[1]) || '@' == substr($arguments[1], 0, 1) || false !== strpos($arguments[1], '/')) |
|---|
| 179 |
{ |
|---|
| 180 |
return call_user_func_array('link_to1', $arguments); |
|---|
| 181 |
} |
|---|
| 182 |
else |
|---|
| 183 |
{ |
|---|
| 184 |
if (!array_key_exists(2, $arguments)) |
|---|
| 185 |
{ |
|---|
| 186 |
$arguments[2] = array(); |
|---|
| 187 |
} |
|---|
| 188 |
return call_user_func_array('link_to2', $arguments); |
|---|
| 189 |
} |
|---|
| 190 |
} |
|---|
| 191 |
|
|---|
| 192 |
function url_for_form(sfFormObject $form, $routePrefix) |
|---|
| 193 |
{ |
|---|
| 194 |
$format = '%s/%s'; |
|---|
| 195 |
if ('@' == $routePrefix[0]) |
|---|
| 196 |
{ |
|---|
| 197 |
$format = '%s_%s'; |
|---|
| 198 |
$routePrefix = substr($routePrefix, 1); |
|---|
| 199 |
} |
|---|
| 200 |
|
|---|
| 201 |
$uri = sprintf($format, $routePrefix, $form->getObject()->isNew() ? 'create' : 'update'); |
|---|
| 202 |
|
|---|
| 203 |
return url_for($uri, $form->getObject()); |
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
function form_tag_for(sfForm $form, $routePrefix, $attributes = array()) |
|---|
| 207 |
{ |
|---|
| 208 |
return $form->renderFormTag(url_for_form($form, $routePrefix), $attributes); |
|---|
| 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 |
function link_to_if() |
|---|
| 244 |
{ |
|---|
| 245 |
$arguments = func_get_args(); |
|---|
| 246 |
if (empty($arguments[2]) || '@' == substr($arguments[2], 0, 1) || false !== strpos($arguments[2], '/')) |
|---|
| 247 |
{ |
|---|
| 248 |
list($condition, $name, $params, $options) = array_pad($arguments, 4, null); |
|---|
| 249 |
} |
|---|
| 250 |
else |
|---|
| 251 |
{ |
|---|
| 252 |
list($condition, $name, $routeName, $params, $options) = array_pad($arguments, 5, null); |
|---|
| 253 |
$params = array_merge(array('sf_route' => $routeName), is_object($params) ? array('sf_subject' => $params) : (array) $params); |
|---|
| 254 |
} |
|---|
| 255 |
|
|---|
| 256 |
$html_options = _parse_attributes($options); |
|---|
| 257 |
if ($condition) |
|---|
| 258 |
{ |
|---|
| 259 |
unset($html_options['tag']); |
|---|
| 260 |
return link_to1($name, $params, $html_options); |
|---|
| 261 |
} |
|---|
| 262 |
else |
|---|
| 263 |
{ |
|---|
| 264 |
unset($html_options['query_string']); |
|---|
| 265 |
unset($html_options['absolute_url']); |
|---|
| 266 |
unset($html_options['absolute']); |
|---|
| 267 |
|
|---|
| 268 |
$tag = _get_option($html_options, 'tag', 'span'); |
|---|
| 269 |
|
|---|
| 270 |
return content_tag($tag, $name, $html_options); |
|---|
| 271 |
} |
|---|
| 272 |
} |
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
function link_to_unless() |
|---|
| 307 |
{ |
|---|
| 308 |
$arguments = func_get_args(); |
|---|
| 309 |
$arguments[0] = !$arguments[0]; |
|---|
| 310 |
return call_user_func_array('link_to_if', $arguments); |
|---|
| 311 |
} |
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
function public_path($path, $absolute = false) |
|---|
| 321 |
{ |
|---|
| 322 |
$request = sfContext::getInstance()->getRequest(); |
|---|
| 323 |
$root = $request->getRelativeUrlRoot(); |
|---|
| 324 |
|
|---|
| 325 |
if ($absolute) |
|---|
| 326 |
{ |
|---|
| 327 |
$source = 'http'; |
|---|
| 328 |
if ($request->isSecure()) |
|---|
| 329 |
{ |
|---|
| 330 |
$source .= 's'; |
|---|
| 331 |
} |
|---|
| 332 |
$source .='://'.$request->getHost().$root; |
|---|
| 333 |
} |
|---|
| 334 |
else |
|---|
| 335 |
{ |
|---|
| 336 |
$source = $root; |
|---|
| 337 |
} |
|---|
| 338 |
|
|---|
| 339 |
if (substr($path, 0, 1) != '/') |
|---|
| 340 |
{ |
|---|
| 341 |
$path = '/'.$path; |
|---|
| 342 |
} |
|---|
| 343 |
|
|---|
| 344 |
return $source.$path; |
|---|
| 345 |
} |
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
function button_to($name, $internal_uri, $options = array()) |
|---|
| 373 |
{ |
|---|
| 374 |
$html_options = _parse_attributes($options); |
|---|
| 375 |
$html_options['value'] = $name; |
|---|
| 376 |
|
|---|
| 377 |
if (isset($html_options['post']) && $html_options['post']) |
|---|
| 378 |
{ |
|---|
| 379 |
if (isset($html_options['popup'])) |
|---|
| 380 |
{ |
|---|
| 381 |
throw new sfConfigurationException('You can\'t use "popup" and "post" together.'); |
|---|
| 382 |
} |
|---|
| 383 |
$html_options['type'] = 'submit'; |
|---|
| 384 |
unset($html_options['post']); |
|---|
| 385 |
$html_options = _convert_options_to_javascript($html_options); |
|---|
| 386 |
|
|---|
| 387 |
return form_tag($internal_uri, array('method' => 'post', 'class' => 'button_to')).content_tag('div', tag('input', $html_options)).'</form>'; |
|---|
| 388 |
} |
|---|
| 389 |
|
|---|
| 390 |
$url = url_for($internal_uri); |
|---|
| 391 |
if (isset($html_options['query_string'])) |
|---|
| 392 |
{ |
|---|
| 393 |
$url = $url.'?'.$html_options['query_string']; |
|---|
| 394 |
unset($html_options['query_string']); |
|---|
| 395 |
} |
|---|
| 396 |
if (isset($html_options['anchor'])) |
|---|
| 397 |
{ |
|---|
| 398 |
$url = $url.'#'.$html_options['anchor']; |
|---|
| 399 |
unset($html_options['anchor']); |
|---|
| 400 |
} |
|---|
| 401 |
$url = "'".$url."'"; |
|---|
| 402 |
$html_options['type'] = 'button'; |
|---|
| 403 |
|
|---|
| 404 |
if (isset($html_options['popup'])) |
|---|
| 405 |
{ |
|---|
| 406 |
$html_options = _convert_options_to_javascript($html_options, $url); |
|---|
| 407 |
unset($html_options['popup']); |
|---|
| 408 |
} |
|---|
| 409 |
else |
|---|
| 410 |
{ |
|---|
| 411 |
$html_options['onclick'] = "document.location.href=".$url.";"; |
|---|
| 412 |
$html_options = _convert_options_to_javascript($html_options); |
|---|
| 413 |
} |
|---|
| 414 |
|
|---|
| 415 |
return tag('input', $html_options); |
|---|
| 416 |
} |
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 |
|
|---|
| 437 |
function form_tag($url_for_options = '', $options = array()) |
|---|
| 438 |
{ |
|---|
| 439 |
$options = _parse_attributes($options); |
|---|
| 440 |
|
|---|
| 441 |
$html_options = $options; |
|---|
| 442 |
|
|---|
| 443 |
$html_options['method'] = isset($html_options['method']) ? strtolower($html_options['method']) : 'post'; |
|---|
| 444 |
|
|---|
| 445 |
if (_get_option($html_options, 'multipart')) |
|---|
| 446 |
{ |
|---|
| 447 |
$html_options['enctype'] = 'multipart/form-data'; |
|---|
| 448 |
} |
|---|
| 449 |
|
|---|
| 450 |
$html_options['action'] = url_for($url_for_options); |
|---|
| 451 |
|
|---|
| 452 |
$html = ''; |
|---|
| 453 |
if (!in_array($html_options['method'], array('get', 'post'))) |
|---|
| 454 |
{ |
|---|
| 455 |
$html = tag('input', array('type' => 'hidden', 'name' => 'sf_method', 'value' => $html_options['method'])); |
|---|
| 456 |
$html_options['method'] = 'post'; |
|---|
| 457 |
} |
|---|
| 458 |
|
|---|
| 459 |
return tag('form', $html_options, true).$html; |
|---|
| 460 |
} |
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
|
|---|
| 464 |
|
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
|
|---|
| 473 |
|
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
function mail_to($email, $name = '', $options = array(), $default_value = array()) |
|---|
| 492 |
{ |
|---|
| 493 |
$html_options = _parse_attributes($options); |
|---|
| 494 |
|
|---|
| 495 |
$html_options = _convert_options_to_javascript($html_options); |
|---|
| 496 |
|
|---|
| 497 |
$default_tmp = _parse_attributes($default_value); |
|---|
| 498 |
$default = array(); |
|---|
| 499 |
foreach ($default_tmp as $key => $value) |
|---|
| 500 |
{ |
|---|
| 501 |
$default[] = urlencode($key).'='.urlencode($value); |
|---|
| 502 |
} |
|---|
| 503 |
$options = count($default) ? '?'.implode('&', $default) : ''; |
|---|
| 504 |
|
|---|
| 505 |
if (isset($html_options['encode']) && $html_options['encode']) |
|---|
| 506 |
{ |
|---|
| 507 |
unset($html_options['encode']); |
|---|
| 508 |
$html_options['href'] = _encodeText('mailto:'.$email.$options); |
|---|
| 509 |
if (!$name) |
|---|
| 510 |
{ |
|---|
| 511 |
$name = _encodeText($email); |
|---|
| 512 |
} |
|---|
| 513 |
} |
|---|
| 514 |
else |
|---|
| 515 |
{ |
|---|
| 516 |
$html_options['href'] = 'mailto:'.$email.$options; |
|---|
| 517 |
if (!$name) |
|---|
| 518 |
{ |
|---|
| 519 |
$name = $email; |
|---|
| 520 |
} |
|---|
| 521 |
} |
|---|
| 522 |
|
|---|
| 523 |
return content_tag('a', $name, $html_options); |
|---|
| 524 |
} |
|---|
| 525 |
|
|---|
| 526 |
function _convert_options_to_javascript($html_options, $url = 'this.href') |
|---|
| 527 |
{ |
|---|
| 528 |
|
|---|
| 529 |
$confirm = isset($html_options['confirm']) ? $html_options['confirm'] : ''; |
|---|
| 530 |
unset($html_options['confirm']); |
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 |
$popup = isset($html_options['popup']) ? $html_options['popup'] : ''; |
|---|
| 534 |
unset($html_options['popup']); |
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
$method = isset($html_options['method']) ? $html_options['method'] : (isset($html_options['post']) && $html_options['post'] ? 'post' : false); |
|---|
| 538 |
unset($html_options['post'], $html_options['method']); |
|---|
| 539 |
|
|---|
| 540 |
$onclick = isset($html_options['onclick']) ? $html_options['onclick'] : ''; |
|---|
| 541 |
|
|---|
| 542 |
if ($popup && $method) |
|---|
| 543 |
{ |
|---|
| 544 |
throw new sfConfigurationException('You can\'t use "popup", "method" and "post" in the same link.'); |
|---|
| 545 |
} |
|---|
| 546 |
else if ($confirm && $popup) |
|---|
| 547 |
{ |
|---|
| 548 |
$html_options['onclick'] = $onclick.'if ('._confirm_javascript_function($confirm).') { '._popup_javascript_function($popup, $url).' };return false;'; |
|---|
| 549 |
} |
|---|
| 550 |
else if ($confirm && $method) |
|---|
| 551 |
{ |
|---|
| 552 |
$html_options['onclick'] = $onclick.'if ('._confirm_javascript_function($confirm).') { '._method_javascript_function($method).' };return false;'; |
|---|
| 553 |
} |
|---|
| 554 |
else if ($confirm) |
|---|
| 555 |
{ |
|---|
| 556 |
if ($onclick) |
|---|
| 557 |
{ |
|---|
| 558 |
$html_options['onclick'] = 'if ('._confirm_javascript_function($confirm).') { return '.$onclick.'} else return false;'; |
|---|
| 559 |
} |
|---|
| 560 |
else |
|---|
| 561 |
{ |
|---|
| 562 |
$html_options['onclick'] = 'return '._confirm_javascript_function($confirm).';'; |
|---|
| 563 |
} |
|---|
| 564 |
} |
|---|
| 565 |
else if ($method) |
|---|
| 566 |
{ |
|---|
| 567 |
$html_options['onclick'] = $onclick._method_javascript_function($method).'return false;'; |
|---|
| 568 |
} |
|---|
| 569 |
else if ($popup) |
|---|
| 570 |
{ |
|---|
| 571 |
$html_options['onclick'] = $onclick._popup_javascript_function($popup, $url).'return false;'; |
|---|
| 572 |
} |
|---|
| 573 |
|
|---|
| 574 |
return $html_options; |
|---|
| 575 |
} |
|---|
| 576 |
|
|---|
| 577 |
function _confirm_javascript_function($confirm) |
|---|
| 578 |
{ |
|---|
| 579 |
return "confirm('".escape_javascript($confirm)."')"; |
|---|
| 580 |
} |
|---|
| 581 |
|
|---|
| 582 |
function _popup_javascript_function($popup, $url = '') |
|---|
| 583 |
{ |
|---|
| 584 |
if (is_array($popup)) |
|---|
| 585 |
{ |
|---|
| 586 |
if (isset($popup[1])) |
|---|
| 587 |
{ |
|---|
| 588 |
return "var w=window.open(".$url.",'".$popup[0]."','".$popup[1]."');w.focus();"; |
|---|
| 589 |
} |
|---|
| 590 |
else |
|---|
| 591 |
{ |
|---|
| 592 |
return "var w=window.open(".$url.",'".$popup[0]."');w.focus();"; |
|---|
| 593 |
} |
|---|
| 594 |
} |
|---|
| 595 |
else |
|---|
| 596 |
{ |
|---|
| 597 |
return "var w=window.open(".$url.");w.focus();"; |
|---|
| 598 |
} |
|---|
| 599 |
} |
|---|
| 600 |
|
|---|
| 601 |
function _post_javascript_function() |
|---|
| 602 |
{ |
|---|
| 603 |
return _method_javascript_function('POST'); |
|---|
| 604 |
} |
|---|
| 605 |
|
|---|
| 606 |
function _method_javascript_function($method) |
|---|
| 607 |
{ |
|---|
| 608 |
$function = "var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'post'; f.action = this.href;"; |
|---|
| 609 |
|
|---|
| 610 |
if ('post' != strtolower($method)) |
|---|
| 611 |
{ |
|---|
| 612 |
$function .= "var m = document.createElement('input'); m.setAttribute('type', 'hidden'); "; |
|---|
| 613 |
$function .= sprintf("m.setAttribute('name', 'sf_method'); m.setAttribute('value', '%s'); f.appendChild(m);", strtolower($method)); |
|---|
| 614 |
} |
|---|
| 615 |
|
|---|
| 616 |
|
|---|
| 617 |
$form = new BaseForm(); |
|---|
| 618 |
if ($form->isCSRFProtected()) |
|---|
| 619 |
{ |
|---|
| 620 |
$function .= "var m = document.createElement('input'); m.setAttribute('type', 'hidden'); "; |
|---|
| 621 |
$function .= sprintf("m.setAttribute('name', '%s'); m.setAttribute('value', '%s'); f.appendChild(m);", $form->getCSRFFieldName(), $form->getCSRFToken()); |
|---|
| 622 |
} |
|---|
| 623 |
|
|---|
| 624 |
$function .= "f.submit();"; |
|---|
| 625 |
|
|---|
| 626 |
return $function; |
|---|
| 627 |
} |
|---|
| 628 |
|
|---|
| 629 |
function _encodeText($text) |
|---|
| 630 |
{ |
|---|
| 631 |
$encoded_text = ''; |
|---|
| 632 |
|
|---|
| 633 |
for ($i = 0; $i < strlen($text); $i++) |
|---|
| 634 |
{ |
|---|
| 635 |
$char = $text{$i}; |
|---|
| 636 |
$r = rand(0, 100); |
|---|
| 637 |
|
|---|
| 638 |
|
|---|
| 639 |
# '@' *must* be encoded. I insist. |
|---|
| 640 |
if ($r > 90 && $char != '@') |
|---|
| 641 |
{ |
|---|
| 642 |
$encoded_text .= $char; |
|---|
| 643 |
} |
|---|
| 644 |
else if ($r < 45) |
|---|
| 645 |
{ |
|---|
| 646 |
$encoded_text .= '&#x'.dechex(ord($char)).';'; |
|---|
| 647 |
} |
|---|
| 648 |
else |
|---|
| 649 |
{ |
|---|
| 650 |
$encoded_text .= '&#'.ord($char).';'; |
|---|
| 651 |
} |
|---|
| 652 |
} |
|---|
| 653 |
|
|---|
| 654 |
return $encoded_text; |
|---|
| 655 |
} |
|---|
| 656 |
|
|---|