/** * Méthode permettant d'afficher l'arbre à partir de celui passé en paramètre. * * @param ITree $tree * @param array $options * @param $key * * @return mixed|string */ public function render(ITree $tree, array $options, $key) { $this->defaults($tree, $tree->getRoot()); if ($key != null && !isset($options["baseId"])) { $options["id"] = $this->options["id"] . "_" . $key; $options["baseId"] = $this->options["id"]; } elseif ($key != null && isset($options["baseId"])) { $options["id"] = $options["baseId"] . "_" . $key; } if ($key != null && isset($options["selected"])) { $options["selected"] = isset($options["selected"][$key]) ? $options["selected"][$key] : ""; } $options = array_merge($this->options, $options); $build = function ($tree) use(&$build, &$options, $key) { $output = is_string($options['rootOpen']) ? $options['rootOpen'] : $options['rootOpen']($tree); $nodes = $tree instanceof ITreeViewerItem && $tree->isRoot() ? array($tree) : $tree; /** @var ITreeViewerItem $node */ foreach ($nodes as $node) { $output .= is_string($options['childOpen']) ? $options['childOpen'] : $options['childOpen']($node, $node->getType(), $key); $output .= $options['nodeDecorator']($node); if (count($node->getChildren()) > 0) { $output .= $build($node->getChildren()); } $output .= is_string($options['childClose']) ? $options['childClose'] : $options['childClose']($node); } return $output . (is_string($options['rootClose']) ? $options['rootClose'] : $options['rootClose']($tree)); }; return html_entity_decode(sfOutputEscaper::unescape(get_component("eitreeviewer", "displaySelectMode", array("root" => $tree, "html" => $build($tree->getRoot()), "options" => $options, "key" => $key, "tree" => $this))), ENT_QUOTES, "UTF-8"); }
/** * SetUp */ public function setup() { $this->initPlugins(); // Escaper sfOutputEscaper::markClassesAsSafe(array('sfFeed')); $this->enablePlugins('sfDoctrineGuardPlugin'); }
/** * Returns the escaped value associated with the key supplied. * * Typically (using this implementation) the raw value is obtained using the * {@link getRaw()} method, escaped and the result returned. * * @param string $key The key to retieve * @param string $escapingMethod The escaping method (a PHP function) to use * * @return mixed The escaped value */ public function get($key, $escapingMethod = null) { if (!$escapingMethod) { $escapingMethod = $this->escapingMethod; } return sfOutputEscaper::escape($escapingMethod, $this->getRaw($key)); }
/** * Renders the presentation. * * @param string Filename * * @return string File content */ protected function renderFile($_sfFile) { if (sfConfig::get('sf_logging_enabled')) { $this->getContext()->getLogger()->info('{sfView} render "' . $_sfFile . '"'); } $this->loadCoreAndStandardHelpers(); $_escaping = $this->getEscaping(); if ($_escaping === false || $_escaping === 'bc') { $vars = $this->attributeHolder->getAll(); extract($vars); } if ($_escaping !== false) { $sf_data = sfOutputEscaper::escape($this->getEscapingMethod(), $this->attributeHolder->getAll()); if ($_escaping === 'both') { foreach ($sf_data as $_key => $_value) { ${$_key} = $_value; } } } // render ob_start(); ob_implicit_flush(0); require $_sfFile; return ob_get_clean(); }
public function configure() { sfConfig::set('dm_front_dir', realpath(dirname(__FILE__) . "/..")); sfConfig::set('dm_context_type', 'front'); sfOutputEscaper::markClassesAsSafe(array('dmFrontPageBaseHelper', 'dmFrontLayoutHelper', 'dmHelper', 'dmHtmlTag', 'dmFrontToolBarView', 'dmMenu')); require_once sfConfig::get('dm_core_dir') . '/lib/config/dmFactoryConfigHandler.php'; require_once sfConfig::get('dm_front_dir') . '/lib/config/dmFrontRoutingConfigHandler.php'; }
function op_api_force_escape($text) { if (!sfConfig::get('sf_escaping_strategy')) { // escape body even if escaping method is disabled. $text = sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), $text); } return $text; }
public function executeSmtMemberTimelineBy1(sfWebRequest $request) { $this->memberId = $request->getParameter('id'); $this->activityData = Doctrine_Query::create()->from('ActivityData ad')->where('ad.in_reply_to_activity_id IS NULL')->andWhere('ad.member_id = ?', $this->memberId)->andWhere('ad.foreign_table IS NULL')->andWhere('ad.foreign_id IS NULL')->andWhere('ad.public_flag = ?', 1)->orderBy('ad.id DESC')->limit(1)->execute(); if ($this->activityData) { $this->createdAt = $this->activityData[0]->getCreatedAt(); $this->body = sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), opTimelinePluginUtil::screenNameReplace($this->activityData[0]->getBody(), sfConfig::get('op_base_url'))); } }
/** * Evaluates and returns a partial. * The syntax is similar to the one of include_partial * * <b>Example:</b> * <code> * echo get_partial('mypartial', array('myvar' => 12345)); * </code> * * @param string $templateName partial name * @param array $vars variables to be made accessible to the partial * * @return string result of the partial execution * @see include_partial */ function get_theme_partial($templateName, $vars = array()) { $context = sfContext::getInstance(); $actionName = '_' . $templateName; $class = 'sfThemePartialView'; $current_theme = $context->getConfiguration()->getPluginConfiguration('sfThemePlugin')->getThemeManager()->getCurrentTheme(); $view = new $class($context, $current_theme, $actionName, ''); $view->setPartialVars(true === sfConfig::get('sf_escaping_strategy') ? sfOutputEscaper::unescape($vars) : $vars); return $view->render(); }
public static function get($name, $default = '#000000', $app = null) { if (is_null($app)) { $app = sfConfig::get('sf_app'); } $configName = 'op_' . $app . '_color_config_' . $name; $result = sfConfig::get($configName, $default); sfContext::getInstance()->getConfiguration()->loadHelpers('Escaping'); return sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), $result); }
/** * Construct method * @param string $class Doctrine class name * @param integer $maxPerPage Number of row per page * @param array $options array of options */ public function __construct($class, $maxPerPage = 10, $options = array()) { $this->widgetSchema = new sfWidgetPagerSchema(); $this->widgetSchema->setPager($this); $this->options = $options; $this->setup(); $this->validateRequiredOptions(); sfOutputEscaper::markClassesAsSafe(array('sfExtraDoctrinePager')); parent::__construct($class, $maxPerPage); }
/** * Retrieves a config parameter. * * @param string $name A config parameter name * @param mixed $default A default config parameter value * * @return mixed A config parameter value */ public static function get($name, $default = null) { $setting = self::getConfigurationSetting(); $result = null; if (isset($setting[$name])) { $result = Doctrine::getTable('SnsConfig')->get($name, $default); if (is_null($result)) { $result = self::getDefaultValue($name); } } sfContext::getInstance()->getConfiguration()->loadHelpers('Escaping'); return sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), $result); }
/** * SetUp */ public function setup() { $this->initPlugins(); // Escaper sfOutputEscaper::markClassesAsSafe(array('DateTime')); // г-но, но без этого Zend_Mail_Message raw письма по русски не читает // @see http://framework.zend.com/issues/browse/ZF-3591 @ini_set('iconv.internal_encoding', 'UTF-8'); // Событие на получение "из контекста" обменника валют // @see sfContext::__call $this->dispatcher->connect('context.method_not_found', array(__CLASS__, 'getMyCurrencyExchange')); // Обработка события "конфигурация подключения" $this->dispatcher->connect('doctrine.configure_connection', array(__CLASS__, 'doctrineConnectionConfigurationEvent')); }
/** * Trim comment to 30 characters * * @param string $comment * @return string */ protected function trimComment($comment) { if (strlen($comment) > 30) { $escape = sfConfig::get('sf_escaping_strategy'); if ($escape) { $comment = sfOutputEscaper::unescape($comment); } $comment = substr($comment, 0, 30) . '...'; if ($escape) { $comment = sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), $comment); } } return $comment; }
public function getListJson($controller, $contents) { sfContext::getInstance()->getConfiguration()->loadHelpers(array('Helper', 'Tag', 'Escaping', 'opUtil')); $result = array(); foreach ($contents as $content) { $data = array('number' => $content->number, 'member_url' => $controller->genUrl('@obj_member_profile?id=' . $content->member_id), 'member_name' => $content->Member->name, 'command' => $content->command, 'body' => $content->body, 'created_at' => $content->created_at); foreach ($data as &$d) { $d = sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), $d); } $data['body'] = op_auto_link_text($data['body']); $result[] = $data; } return json_encode($result); }
/** * Magic PHP method that intercepts method calls, calls them on the objects * that is being escaped and escapes the result. * * The calling of the method is changed slightly to accommodate passing a * specific escaping strategy. An additional parameter is appended to the * argument list which is the escaping strategy. The decorator will remove * and use this parameter as the escaping strategy if it begins with 'esc_' * (the prefix all escaping helper functions have). * * For example if an object, $o, implements methods a() and b($arg): * * $o->a() // Escapes the return value of a() * $o->a(ESC_RAW) // Uses the escaping method ESC_RAW with a() * $o->b('a') // Escapes the return value of b('a') * $o->b('a', ESC_RAW); // Uses the escaping method ESC_RAW with b('a') * * @param string $method The method on the object to be called * @param array $args An array of arguments to be passed to the method * * @return mixed The escaped value returned by the method */ public function __call($method, $args) { if (count($args) > 0) { $escapingMethod = $args[count($args) - 1]; if (is_string($escapingMethod) && substr($escapingMethod, 0, 4) === 'esc_') { array_pop($args); } else { $escapingMethod = $this->escapingMethod; } } else { $escapingMethod = $this->escapingMethod; } $value = call_user_func_array(array($this->value, $method), $args); return sfOutputEscaper::escape($escapingMethod, $value); }
protected function setConfigWidget() { sfContext::getInstance()->getConfiguration()->loadHelpers(array('Escaping')); $application = $this->memberApplication->getApplication(); $settings = $application->getSettings(); foreach ($settings as $key => $setting) { $param = array(); $choices = array(); $validatorBool = new sfValidatorBoolean(); $param['IsRequired'] = $validatorBool->clean($setting['required']); $param['Caption'] = sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), $setting['displayName']); if (empty($setting['datatype']) || $setting['datatype'] == 'HIDDEN') { continue; } switch ($setting['datatype']) { case 'BOOL': $param['FormType'] = 'radio'; $choices = array('1' => 'Yes', '0' => 'No'); break; case 'ENUM': $param['FormType'] = 'select'; $enumValues = array(); if (!is_array($setting['enumValues'])) { continue; } foreach ($setting['enumValues'] as $value) { $enumValues[$value['value']] = $value['displayValue']; } $choices = $enumValues; break; default: $param['FormType'] = 'input'; $param['ValueType'] = ''; } $this->widgetSchema[$key] = opFormItemGenerator::generateWidget($param, $choices); $this->validatorSchema[$key] = opFormItemGenerator::generateValidator($param, array_keys($choices)); if ($setting['defaultValue']) { $this->setDefault($key, $setting['defaultValue']); } } $userSettings = $this->memberApplication->getUserSettings(); foreach ($userSettings as $name => $value) { if (!empty($value)) { $this->setDefault($name, $value); } } }
public function initialize() { if ($this->configuration instanceof sfApplicationConfiguration) { if (sfNestedCommentConfig::isRoutesRegister()) { if (in_array('sfNestedComment', sfConfig::get('sf_enabled_modules', array()))) { $this->dispatcher->connect('routing.load_configuration', array('sfNestedCommentRouting', 'listenToRoutingLoadConfigurationEvent')); } if (in_array('sfNestedCommentAdmin', sfConfig::get('sf_enabled_modules', array()))) { $this->dispatcher->connect('routing.load_configuration', array('sfNestedCommentRouting', 'addRouteForNestedCommentAdmin')); } } sfOutputEscaper::markClassAsSafe('sfNestedCommentsRenderer'); if (sfNestedCommentConfig::isUsePluginPurifier()) { self::registerHTMLPurifier(); } } }
/** * Returns an array representation of the view parameters. * * @return array An array of view parameters * * @throws InvalidArgumentException */ public function toArray() { $event = $this->dispatcher->filter(new sfEvent($this, 'template.filter_parameters'), $this->getAll()); $parameters = $event->getReturnValue(); $attributes = array(); if ($this->isEscaped()) { $attributes['sf_data'] = sfOutputEscaper::escape($this->getEscapingMethod(), $parameters); foreach ($attributes['sf_data'] as $key => $value) { $attributes[$key] = $value; } } else { if (in_array($this->getEscaping(), array('off', false), true)) { $attributes = $parameters; $attributes['sf_data'] = sfOutputEscaper::escape(ESC_RAW, $parameters); } else { throw new InvalidArgumentException(sprintf('Unknown strategy "%s".', $this->getEscaping())); } } return $attributes; }
/** * Includes a navigation for paginated list * * @param sfPager $pager * @param string $internal_uri * @param array $options */ function op_include_pager_navigation($pager, $internal_uri, $options = array()) { $uri = url_for($internal_uri); if (isset($options['use_current_query_string']) && $options['use_current_query_string']) { $options['query_string'] = sfContext::getInstance()->getRequest()->getCurrentQueryString(); $pageFieldName = isset($options['page_field_name']) ? $options['page_field_name'] : 'page'; $options['query_string'] = preg_replace('/' . $pageFieldName . '=\\d\\&*/', '', $options['query_string']); unset($options['page_field_name']); unset($options['use_current_query_string']); } if (isset($options['query_string'])) { $options['link_options']['query_string'] = $options['query_string']; unset($options['query_string']); } $params = array('pager' => $pager, 'internalUri' => $internal_uri, 'options' => new opPartsOptionHolder($options)); $pager = sfOutputEscaper::unescape($pager); if ($pager instanceof sfReversibleDoctrinePager) { include_partial('global/pagerReversibleNavigation', $params); } else { include_partial('global/pagerNavigation', $params); } }
/** * Returns the element associated with the offset supplied (as required by the ArrayAccess interface). * * @param string $offset The offset of the value to get * * @return mixed The escaped value */ public function offsetGet($offset) { return sfOutputEscaper::escape($this->escapingMethod, $this->value[$offset]); }
/** * Initializes this view. * * @param sfContext $context The current application context * @param string $moduleName The module name for this view * @param string $actionName The action name for this view * @param string $viewName The view name * * @return bool true, if initialization completes successfully, otherwise false */ public function initialize($context, $moduleName, $actionName, $viewName) { $this->moduleName = $moduleName; $this->actionName = $actionName; $this->viewName = $viewName; $this->context = $context; $this->dispatcher = $context->getEventDispatcher(); sfOutputEscaper::markClassesAsSafe(array('sfForm', 'sfModelGeneratorHelper')); $this->attributeHolder = $this->initializeAttributeHolder(); $this->parameterHolder = new sfParameterHolder(); $this->parameterHolder->add(sfConfig::get('mod_' . strtolower($moduleName) . '_view_param', array())); $request = $context->getRequest(); $format = $request->getRequestFormat(); if (null !== $format) { if ('html' != $format) { $this->setExtension('.' . $format . $this->getExtension()); } if ($mimeType = $request->getMimeType($format)) { $this->context->getResponse()->setContentType($mimeType); if ('html' != $format) { $this->setDecorator(false); } } } $this->dispatcher->notify(new sfEvent($this, 'view.configure_format', array('format' => $format, 'response' => $context->getResponse(), 'request' => $context->getRequest()))); // include view configuration $this->configure(); return true; }
if (class_exists('SimpleXMLElement')) { $element = new SimpleXMLElement('<foo>bar</foo>'); $escaped = sfOutputEscaper::escape('esc_entities', $element); $t->is((string) $escaped, (string) $element, '->__toString() is compatible with SimpleXMLElement'); } else { $t->skip('->__toString() is compatible with SimpleXMLElement'); } class Foo { } class FooCountable implements Countable { public function count() { return 2; } } // implements Countable $t->diag('implements Countable'); $foo = sfOutputEscaper::escape('esc_entities', new Foo()); $fooc = sfOutputEscaper::escape('esc_entities', new FooCountable()); $t->is(count($foo), 1, '->count() returns 1 if the embedded object does not implement the Countable interface'); $t->is(count($fooc), 2, '->count() returns the count() for the embedded object'); // ->__isset() $t->diag('->__isset()'); $raw = new stdClass(); $raw->foo = 'bar'; $esc = sfOutputEscaper::escape('esc_entities', $raw); $t->ok(isset($esc->foo), '->__isset() asks the wrapped object whether a property is set'); unset($raw->foo); $t->ok(!isset($esc->foo), '->__isset() asks the wrapped object whether a property is set');
/** * Returns value at given offset * * @see ArrayAccess::offsetGet() */ public function offsetGet($offset) { return sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), self::get($offset)); }
echo __('Widget'); ?> </th> </tr> <?php foreach ($widget as $category => $list) { ?> <tr> <td><?php echo $category; ?> </td> <td><ul> <?php foreach ($list as $name) { ?> <li><?php echo sfOutputEscaper::unescape($name); ?> </li> <?php } ?> </ul></td> </tr> <?php } ?> </tbdoy> </table>
$t = new lime_test(88, new lime_output_color()); $context = sfContext::getInstance(); $context->controller = new myController(); $context->user = new myUser(); $context->request = new myRequest(); $context->response = new myResponse(); // options_for_select() $t->diag('options_for_select()'); $t->is(options_for_select(array('item1', 'item2', 'item3')), "<option value=\"0\">item1</option>\n<option value=\"1\">item2</option>\n<option value=\"2\">item3</option>\n", 'options_for_select() takes an array of options as its first argument'); $t->is(options_for_select(array(1 => 'item1', 2 => 'item2', 'foo' => 'item3')), "<option value=\"1\">item1</option>\n<option value=\"2\">item2</option>\n<option value=\"foo\">item3</option>\n", 'options_for_select() takes an array of options as its first argument'); $t->is(options_for_select(array('item1', 'item2', 'item3'), '0'), "<option value=\"0\" selected=\"selected\">item1</option>\n<option value=\"1\">item2</option>\n<option value=\"2\">item3</option>\n", 'options_for_select() takes the selected index as its second argument'); $t->is(options_for_select(array('item1', 'item2', 'item3'), '2'), "<option value=\"0\">item1</option>\n<option value=\"1\">item2</option>\n<option value=\"2\" selected=\"selected\">item3</option>\n", 'options_for_select() takes the selected index as its second argument'); $t->is(options_for_select(array('item1', 'item2', 'item3'), array('1', '2')), "<option value=\"0\">item1</option>\n<option value=\"1\" selected=\"selected\">item2</option>\n<option value=\"2\" selected=\"selected\">item3</option>\n", 'options_for_select() takes the selected index as its second argument'); $t->is(options_for_select(array('group1' => array('item1', 'item2'), 'bar' => 'item3')), "<optgroup label=\"group1\"><option value=\"0\">item1</option>\n<option value=\"1\">item2</option>\n</optgroup>\n<option value=\"bar\">item3</option>\n", 'options_for_select() can deal with optgroups'); // unit testing for #3923 $escaped = sfOutputEscaper::escape('htmlspecialchars', array('group1' => array('item1', 'item2'), 'bar' => 'item3')); $t->is(options_for_select($escaped), "<optgroup label=\"group1\"><option value=\"0\">item1</option>\n<option value=\"1\">item2</option>\n</optgroup>\n<option value=\"bar\">item3</option>\n", 'options_for_select() can deal with optgroups of escaped arrays'); // options $t->is(options_for_select(array('item1'), '', array('include_custom' => 'test')), "<option value=\"\">test</option>\n<option value=\"0\">item1</option>\n", 'options_for_select() can take an "include_custom" option'); $t->is(options_for_select(array('item1'), '', array('include_blank' => true)), "<option value=\"\"></option>\n<option value=\"0\">item1</option>\n", 'options_for_select() can take an "include_blank" option'); // form_tag() $t->diag('form_tag()'); $t->is(form_tag(), '<form method="post" action="module/action">', 'form_tag() creates a form tag'); // options $t->is(form_tag('', array('class' => 'foo')), '<form class="foo" method="post" action="module/action">', 'form_tag() takes an array of attribute options'); $t->is(form_tag('', array('method' => 'get')), '<form method="get" action="module/action">', 'form_tag() takes a "method" as an option'); $t->is(form_tag('', array('multipart' => true)), '<form method="post" enctype="multipart/form-data" action="module/action">', 'form_tag() takes a "multipart" boolean option'); // select_tag() $t->diag('select_tag()'); $t->is(select_tag('name'), '<select name="name" id="name"></select>', 'select_tag() takes a name as its first argument'); $option_for_select = options_for_select(array('item1'));
<?php foreach ($list_notices as $name => $fonctions) { ?> <tr> <th colspan="2"><h2 class="img_function_name"><?php echo $name; ?> </h2></th> </tr> <?php foreach ($fonctions as $id_fonction => $noticeVersion) { ?> <?php if (sfOutputEscaper::unescape($noticeVersion) != null) { ?> <tr> <td class="desc_img_notice"> <!-- Traitement des paramètres variables dans la notice --> <?php echo html_entity_decode(MyFunction::parseDescImg($noticeVersion['description'], $id_fonction, $profileParams)); ?> </td> </tr> <?php } else { ?> <tr> <td class="desc_img_notice"> <h6>No Notice Version define for this environment and language</h6>
require_once dirname(__FILE__) . '/../../../../lib/view/escaper/sfOutputEscaper.class.php'; require_once dirname(__FILE__) . '/../../../../lib/view/escaper/sfOutputEscaperGetterDecorator.class.php'; require_once dirname(__FILE__) . '/../../../../lib/view/escaper/sfOutputEscaperArrayDecorator.class.php'; require_once dirname(__FILE__) . '/../../../../lib/view/escaper/sfOutputEscaperObjectDecorator.class.php'; require_once dirname(__FILE__) . '/../../../../lib/view/escaper/sfOutputEscaperIteratorDecorator.class.php'; require_once dirname(__FILE__) . '/../../../../lib/helper/EscapingHelper.php'; require_once dirname(__FILE__) . '/../../../../lib/config/sfConfig.class.php'; sfConfig::set('sf_charset', 'UTF-8'); $t = new lime_test(10, new lime_output_color()); // ::escape() $t->diag('::escape()'); $t->is(sfOutputEscaper::escape('esc_entities', null), null, '::escape() returns null if the value to escape is null'); $t->is(sfOutputEscaper::escape('esc_entities', false), false, '::escape() returns false if the value to escape is false'); $t->is(sfOutputEscaper::escape('esc_entities', true), true, '::escape() returns true if the value to escape is true'); $t->is(sfOutputEscaper::escape('esc_raw', '<strong>escaped!</strong>'), '<strong>escaped!</strong>', '::escape() takes an escaping strategy function name as its first argument'); $t->is(sfOutputEscaper::escape('esc_entities', '<strong>escaped!</strong>'), '<strong>escaped!</strong>', '::escape() returns an escaped string if the value to escape is a string'); $t->is(sfOutputEscaper::escape('esc_entities', '<strong>échappé</strong>'), '<strong>échappé</strong>', '::escape() returns an escaped string if the value to escape is a string'); $t->isa_ok(sfOutputEscaper::escape('esc_entities', array(1, 2)), 'sfOutputEscaperArrayDecorator', '::escape() returns a sfOutputEscaperArrayDecorator object if the value to escape is an array'); $t->isa_ok(sfOutputEscaper::escape('esc_entities', new stdClass()), 'sfOutputEscaperObjectDecorator', '::escape() returns a sfOutputEscaperObjectDecorator object if the value to escape is an object'); class OutputEscaperTestClass { public function getTitle() { return '<strong>escaped!</strong>'; } } $object = new OutputEscaperTestClass(); $escaped_object = sfOutputEscaper::escape('esc_entities', $object); $t->is(sfOutputEscaper::escape('esc_entities', $escaped_object)->getTitle(), '<strong>escaped!</strong>', '::escape() does not double escape an object'); $t->isa_ok(sfOutputEscaper::escape('esc_entities', new DirectoryIterator('.')), 'sfOutputEscaperIteratorDecorator', '::escape() returns a sfOutputEscaperIteratorDecorator object if the value to escape is an object that implements the ArrayAccess interface');
/** * Set the op_mobile_header slot * * @param string $title * @param string $subtitle */ function op_mobile_page_title($title, $subtitle = '') { $params = array('title' => sfOutputEscaper::unescape($title), 'subtitle' => sfOutputEscaper::unescape($subtitle)); slot('op_mobile_header', get_partial('global/partsPageTitle', $params)); }
require_once dirname(__FILE__) . '/../../../../lib/view/escaper/sfOutputEscaperIteratorDecorator.class.php'; require_once dirname(__FILE__) . '/../../../../lib/helper/EscapingHelper.php'; require_once dirname(__FILE__) . '/../../../../lib/config/sfConfig.class.php'; class sfException extends Exception { } sfConfig::set('sf_charset', 'UTF-8'); $t = new lime_test(3, new lime_output_color()); class OutputEscaperTest { public function __toString() { return $this->getTitle(); } public function getTitle() { return '<strong>escaped!</strong>'; } public function getTitles() { return array(1, 2, '<strong>escaped!</strong>'); } } $object = new OutputEscaperTest(); $escaped = sfOutputEscaper::escape('esc_entities', $object); $t->is($escaped->getTitle(), '<strong>escaped!</strong>', 'The escaped object behaves like the real object'); $array = $escaped->getTitles(); $t->is($array[2], '<strong>escaped!</strong>', 'The escaped object behaves like the real object'); // __toString() $t->diag('__toString()'); $t->is($escaped->__toString(), '<strong>escaped!</strong>', 'The escaped object behaves like the real object');
$t->is(sfOutputEscaper::unescape('<strong>escaped!</strong>'), '<strong>escaped!</strong>', '::unescape() returns an unescaped string if the value to unescape is a string'); $t->is(sfOutputEscaper::unescape('<strong>échappé</strong>'), '<strong>échappé</strong>', '::unescape() returns an unescaped string if the value to unescape is a string'); $t->diag('::unescape() unescapes arrays'); $input = sfOutputEscaper::escape('esc_entities', array('foo' => '<strong>escaped!</strong>', 'bar' => array('foo' => '<strong>escaped!</strong>'))); $output = sfOutputEscaper::unescape($input); $t->ok(is_array($output), '::unescape() returns an array if the input is a sfOutputEscaperArrayDecorator object'); $t->is($output['foo'], '<strong>escaped!</strong>', '::unescape() unescapes all elements of the original array'); $t->is($output['bar']['foo'], '<strong>escaped!</strong>', '::unescape() is recursive'); $t->diag('::unescape() unescapes objects'); $object = new OutputEscaperTestClass(); $input = sfOutputEscaper::escape('esc_entities', $object); $output = sfOutputEscaper::unescape($input); $t->isa_ok($output, 'OutputEscaperTestClass', '::unescape() returns the original object when a sfOutputEscaperObjectDecorator object is passed'); $t->is($output->getTitle(), '<strong>escaped!</strong>', '::unescape() unescapes all methods of the original object'); $t->is($output->title, '<strong>escaped!</strong>', '::unescape() unescapes all properties of the original object'); $t->is($output->getTitleTitle(), '<strong>escaped!</strong>', '::unescape() is recursive'); $t->isa_ok(sfOutputEscaperIteratorDecorator::unescape(sfOutputEscaper::escape('esc_entities', new DirectoryIterator('.'))), 'DirectoryIterator', '::unescape() unescapes sfOutputEscaperIteratorDecorator objects'); $t->diag('::unescape() does not unescape object marked as being safe'); $t->isa_ok(sfOutputEscaper::unescape(sfOutputEscaper::escape('esc_entities', new sfOutputEscaperSafe(new OutputEscaperTestClass()))), 'OutputEscaperTestClass', '::unescape() returns the original value if it is marked as being safe'); sfOutputEscaper::markClassAsSafe('OutputEscaperTestClass'); $t->isa_ok(sfOutputEscaper::unescape(sfOutputEscaper::escape('esc_entities', new OutputEscaperTestClass())), 'OutputEscaperTestClass', '::unescape() returns the original value if the object class is marked as being safe'); $t->isa_ok(sfOutputEscaper::unescape(sfOutputEscaper::escape('esc_entities', new OutputEscaperTestClassChild())), 'OutputEscaperTestClassChild', '::unescape() returns the original value if one of the object parent class is marked as being safe'); $t->diag('::unescape() do nothing to resources'); $fh = fopen(__FILE__, 'r'); $t->is(sfOutputEscaper::unescape($fh), $fh, '::unescape() do nothing to resources'); $t->diag('::unescape() unescapes mixed arrays'); $object = new OutputEscaperTestClass(); $input = array('foo' => 'bar', 'bar' => sfOutputEscaper::escape('esc_entities', '<strong>bar</strong>'), 'foobar' => sfOutputEscaper::escape('esc_entities', $object)); $output = array('foo' => 'bar', 'bar' => '<strong>bar</strong>', 'foobar' => $object); $t->is(sfOutputEscaper::unescape($input), $output, '::unescape() unescapes values with some escaped and unescaped values');