/** * 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(); }
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'))); } }
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); }
/** * 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); }
/** * 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); } } }
/** * 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; }
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');
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->pass('The escaped object is read only (unset)'); } try { $escaped[0] = 12; $t->fail('The escaped object is read only (set)'); } catch (sfException $e) { $t->pass('The escaped object is read only (set)'); } // Iterator interface $t->diag('Iterator interface'); foreach ($escaped as $key => $value) { switch ($key) { case 0: $t->is($value, '<strong>escaped!</strong>', 'The escaped object behaves like an array'); break; case 1: $t->is($value, 1, 'The escaped object behaves like an array'); break; case 2: $t->is($value, null, 'The escaped object behaves like an array'); break; case 3: break; default: $t->fail('The escaped object behaves like an array'); } } // ->valid() $t->diag('->valid()'); $escaped = sfOutputEscaper::escape('esc_entities', array(1, 2, 3)); $t->is($escaped->valid(), true, '->valid() returns true if called before iteration');
/** * Creates a <a> link tag for the member nickname * * @value mixed $value (string or Member object) * @param string $options * @param string $routeName * @param bool $isCheckPrivate * @return string */ function op_link_to_member($value, $options = array(), $routeName = '@obj_member_profile', $isCheckPrivate = false) { $member = null; if ($value instanceof sfOutputEscaper || $value instanceof Member) { $member = $value; } elseif ($value) { $member = Doctrine::getTable('Member')->find($value); } if ($member && $member->id) { if ($isCheckPrivate && sfContext::hasInstance()) { $user = sfContext::getInstance()->getUser(); if (!$user->isSNSMember() && ProfileTable::PUBLIC_FLAG_WEB !== (int) $member->getConfig('profile_page_public_flag')) { return isset($options['private_text']) ? $options['private_text'] : __('Private<br />Member'); } } if (!$member instanceof sfOutputEscaper) { $member = sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), $member); } $link_target = $member->name; if (isset($options['link_target'])) { $link_target = $options['link_target']; unset($options['link_target']); } return link_to($link_target, sprintf('%s?id=%d', $routeName, $member->id), $options); } return sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), opConfig::get('nickname_of_member_who_does_not_have_credentials', '-')); }
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');
$t->diag('::unescape() unescapes strings'); $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');
*/ require_once dirname(__FILE__) . '/../../../../lib/vendor/lime/lime.php'; 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'; class sfException extends Exception { } sfConfig::set('sf_charset', 'UTF-8'); $t = new lime_test(10, new lime_output_color()); $a = array('<strong>escaped!</strong>', 1, null, array(2, '<strong>escaped!</strong>')); $escaped = sfOutputEscaper::escape('esc_entities', $a); // ->getRaw() $t->diag('->getRaw()'); $t->is($escaped->getRaw(0), '<strong>escaped!</strong>', '->getRaw() returns the raw value'); // ArrayAccess interface $t->diag('ArrayAccess interface'); $t->is($escaped[0], '<strong>escaped!</strong>', 'The escaped object behaves like an array'); $t->is($escaped[2], null, 'The escaped object behaves like an array'); $t->is($escaped[3][1], '<strong>escaped!</strong>', 'The escaped object behaves like an array'); $t->ok(isset($escaped[1]), 'The escaped object behaves like an array (isset)'); $t->diag('ArrayAccess interface is read only'); try { unset($escaped[0]); $t->fail('The escaped object is read only (unset)'); } catch (sfException $e) { $t->pass('The escaped object is read only (unset)');
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'); 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');
public function executeListMention(sfWebRequest $request) { sfContext::getInstance()->getConfiguration()->loadHelpers(array('Helper', 'Date', 'sfImage', 'opUtil', 'Escaping')); $baseUrl = sfConfig::get('op_base_url'); $memberId = $this->getUser()->getMember()->getId(); $mines = Doctrine::getTable('ActivityData')->findByMemberId($memberId); $replyId = array(); foreach ($mines as $mine) { $replyId[] = $mine->getId(); } $activityData = Doctrine_Query::create()->from('ActivityData ad')->where('ad.template = ?', 'mention_member_id')->andWhere('ad.template_param LIKE ?', '%|' . $memberId . '|%')->execute(); foreach ($activityData as $activity) { $id = $activity->getId(); $memberId = $activity->getMemberId(); $member = Doctrine::getTable('Member')->find($memberId); if (!$member->getImageFileName()) { $memberImage = $baseUrl . '/images/no_image.gif'; } else { $memberImageFile = $member->getImageFileName(); $memberImage = sf_image_path($memberImageFile, array('size' => '48x48')); } $memberName = $member->getName(); $memberScreenName = $this->getScreenName($memberId) ? $this->getScreenName($memberId) : $memberName; $body = sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), opTimelinePluginUtil::screenNameReplace($activity->getBody(), $baseUrl)); $uri = $activity->getUri(); $source = $activity->getSource(); $sourceUri = $activity->getSourceUri(); $createdAt = $activity->getCreatedAt(); if ($memberId == $this->getUser()->getMember()->getId()) { $deleteLink = 'show'; } else { $deleteLink = 'none'; } $ac[] = array('id' => $id, 'memberId' => $memberId, 'memberImage' => $memberImage, 'memberScreenName' => $memberScreenName, 'memberName' => $memberName, 'body' => $body, 'deleteLink' => $deleteLink, 'uri' => $uri, 'source' => $source, 'sourceUri' => $sourceUri, 'createdAt' => op_format_activity_time(strtotime($createdAt)), 'baseUrl' => sfConfig::get('op_base_url')); } $json = array('status' => 'success', 'data' => $ac); return $this->renderText(json_encode($json)); }
$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'));
public function executeGet(sfWebRequest $request) { $this->getResponse()->setContentType('application/json'); sfContext::getInstance()->getConfiguration()->loadHelpers(array('Helper', 'Date', 'I18N', 'sfImage', 'Url', 'Tag', 'opUtil', 'Escaping', 'opTimeline')); $ac = array(); $activityIds = array(); $mode = $request->getParameter('mode'); $list = $request->getParameter('list'); $memberId = (int) $request->getParameter('memberId'); $lastId = (int) $request->getParameter('lastId'); $moreId = (int) $request->getParameter('moreId'); $limit = (int) $request->getParameter('limit', 20); $communityId = (int) $request->getParameter('communityId'); $activityData = Doctrine_Query::create()->from('ActivityData ad'); switch ($list) { case 'all': $activityData = $activityData->where('ad.in_reply_to_activity_id IS NULL'); break; case 'more': if (!is_numeric($moreId)) { $this->status = 'error'; $this->message = 'Request parameter "moreId" must be numeric.'; return sfView::ERROR; } $activityData = $activityData->where('ad.id < ?', $moreId)->andWhere('ad.in_reply_to_activity_id IS NULL'); break; case 'check': if (!is_numeric($lastId)) { $this->status = 'error'; $this->message = 'Request parameter "lastId" must be numeric.'; return sfView::ERROR; } $activityData = $activityData->where('ad.in_reply_to_activity_id IS NULL')->andWhere('ad.id > ?', $lastId); break; default: $activityData = $activityData->where('ad.in_reply_to_activity_id IS NULL'); } switch ($mode) { case 'member': if (!is_numeric($memberId)) { $this->status = 'error'; $this->message = 'Request parameter "memberId" must be numeric.'; return sfView::ERROR; } $activityData = $activityData->andWhere('ad.member_id = ?', $memberId)->andWhere('ad.foreign_table IS NULL')->andWhere('ad.foreign_id IS NULL')->andWhere('ad.public_flag = ?', 1)->orderBy('ad.id DESC'); break; case 'community': if (!is_numeric($communityId)) { $this->status = 'error'; $this->message = 'Request parameter "communityId" must be numeric.'; return sfView::ERROR; } $activityData = $activityData->andWhere('ad.foreign_table = ?', 'community')->andWhere('ad.foreign_id = ?', $communityId)->orderBy('ad.id DESC'); break; default: $activityData = $activityData->andWhere('ad.foreign_table IS NULL')->andWhere('ad.foreign_id IS NULL')->andWhere('ad.public_flag = ?', 1); $activityData = $activityData->orderBy('ad.id DESC'); } $activityData = $activityData->limit($limit); $activityData = $activityData->execute(); foreach ($activityData as $activity) { $id = $activity->getId(); $memberId = $activity->getMemberId(); $member = Doctrine::getTable('Member')->find($memberId); if (!$member->getImageFileName()) { $memberImage = url_for('@homepage') . '/images/no_image.gif'; } else { $memberImageFile = $member->getImageFileName(); $memberImage = sf_image_path($memberImageFile, array('size' => '48x48')); } $memberName = $member->getName(); $memberScreenName = $this->getScreenName($memberId) ? $this->getScreenName($memberId) : $memberName; $body = sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), opTimelinePluginUtil::screenNameReplace($activity->getBody(), url_for('@homepage'))); $body = op_timeline_plugin_body_filter($activity, $body); $uri = $activity->getUri(); $source = $activity->getSource(); $sourceUri = $activity->getSourceUri(); $createdAt = $activity->getCreatedAt(); if ($memberId == $this->getMember()->getId()) { $deleteLink = 'inline'; } else { $deleteLink = 'none'; } $ac[] = array('id' => $id, 'memberId' => $memberId, 'memberImage' => $memberImage, 'memberScreenName' => $memberScreenName, 'memberName' => $memberName, 'body' => $body, 'deleteLink' => $deleteLink, 'uri' => $uri, 'source' => $source, 'sourceUri' => $sourceUri, 'createdAt' => op_format_activity_time(strtotime($createdAt)), 'baseUrl' => sfConfig::get('op_base_url')); $activityIds[] = $id; } $count = count($ac); $i = 0; $commentData = Doctrine_Query::create()->from('ActivityData ad')->whereIn('ad.in_reply_to_activity_id', $activityIds)->andWhere('ad.foreign_table IS NULL')->andWhere('ad.foreign_id IS NULL')->andWhere('ad.public_flag = ?', 1)->execute(); foreach ($commentData as $activity) { $inReplyToActivityId = $activity->getInReplyToActivityId(); for ($j = 0; $j < $count; $j++) { if ($ac[$j]['id'] == $inReplyToActivityId) { $member = Doctrine::getTable('Member')->find($activity->getMemberId()); $cm = array(); $cm['id'] = $activity->getId(); $cm['memberId'] = $member->getId(); $cm['memberName'] = $member->getName(); if (!$member->getImageFileName()) { $cm['memberImage'] = $baseUrl . '/images/no_image.gif'; } else { $memberImageFile = $member->getImageFileName(); $cm['memberImage'] = sf_image_path($memberImageFile, array('size' => '48x48')); } $cm['memberScreenName'] = $this->getScreenName($cm['memberId']) ? $this->getScreenName($cm['memberId']) : $cm['memberName']; $cm['body'] = opTimelinePluginUtil::screenNameReplace(sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), $activity->getBody()), $baseUrl); if ($cm['memberId'] == $this->getMember()->getId()) { $cm['deleteLink'] = 'inline'; } else { $cm['deleteLink'] = 'none'; } $cm['uri'] = $activity->getUri(); $cm['source'] = $activity->getSource(); $cm['sourceUri'] = $activity->getSourceUri(); $cm['createdAt'] = op_format_activity_time(strtotime($activity->getCreatedAt())); $cm['baseUrl'] = sfConfig::get('op_base_url'); $ac[$j]['reply'][] = $cm; } } $i++; } $this->status = 'success'; $this->data = $ac; return sfView::SUCCESS; }
/** * Returns value at given offset * * @see ArrayAccess::offsetGet() */ public function offsetGet($offset) { return sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), self::get($offset)); }
$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->diag('::escape() escapes arrays'); $input = array('foo' => '<strong>escaped!</strong>', 'bar' => array('foo' => '<strong>escaped!</strong>')); $output = sfOutputEscaper::escape('esc_entities', $input); $t->isa_ok($output, 'sfOutputEscaperArrayDecorator', '::escape() returns a sfOutputEscaperArrayDecorator object if the value to escape is an array'); $t->is($output['foo'], '<strong>escaped!</strong>', '::escape() escapes all elements of the original array'); $t->is($output['bar']['foo'], '<strong>escaped!</strong>', '::escape() is recursive'); $t->is($output->getRawValue(), $input, '->getRawValue() returns the unescaped value'); $t->diag('::escape() escapes objects'); $input = new OutputEscaperTestClass(); $output = sfOutputEscaper::escape('esc_entities', $input); $t->isa_ok($output, 'sfOutputEscaperObjectDecorator', '::escape() returns a sfOutputEscaperObjectDecorator object if the value to escape is an object'); $t->is($output->getTitle(), '<strong>escaped!</strong>', '::escape() escapes all methods of the original object'); $t->is($output->title, '<strong>escaped!</strong>', '::escape() escapes all properties of the original object'); $t->is($output->getTitleTitle(), '<strong>escaped!</strong>', '::escape() is recursive'); $t->is($output->getRawValue(), $input, '->getRawValue() returns the unescaped value'); $t->is(sfOutputEscaper::escape('esc_entities', $output)->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'); $t->diag('::escape() does not escape object marked as being safe'); $t->isa_ok(sfOutputEscaper::escape('esc_entities', new sfOutputEscaperSafe(new OutputEscaperTestClass())), 'OutputEscaperTestClass', '::escape() returns the original value if it is marked as being safe'); sfOutputEscaper::markClassAsSafe('OutputEscaperTestClass'); $t->isa_ok(sfOutputEscaper::escape('esc_entities', new OutputEscaperTestClass()), 'OutputEscaperTestClass', '::escape() returns the original value if the object class is marked as being safe'); $t->isa_ok(sfOutputEscaper::escape('esc_entities', new OutputEscaperTestClassChild()), 'OutputEscaperTestClassChild', '::escape() returns the original value if one of the object parent class is marked as being safe'); $t->diag('::escape() cannot escape resources'); $fh = fopen(__FILE__, 'r'); try { sfOutputEscaper::escape('esc_entities', $fh); $t->fail('::escape() throws an InvalidArgumentException if the value cannot be escaped'); } catch (InvalidArgumentException $e) { $t->pass('::escape() throws an InvalidArgumentException if the value cannot be escaped'); }
/** * 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]); }
/** * Creates a <a> link tag for the member nickname * * @value mixed $value (string or Member object) * @param string $options * @param string $routeName * @return string */ function op_link_to_member($value, $options = array(), $routeName = '@obj_member_profile') { $member = null; if ($value instanceof sfOutputEscaper || $value instanceof Member) { $member = $value; } elseif ($value) { $member = Doctrine::getTable('Member')->find($value); } if ($member && $member->id) { if (!$member instanceof sfOutputEscaper) { $member = sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), $member); } $link_target = $member->name; if (isset($options['link_target'])) { $link_target = $options['link_target']; unset($options['link_target']); } return link_to($link_target, sprintf('%s?id=%d', $routeName, $member->id), $options); } return sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), opConfig::get('nickname_of_member_who_does_not_have_credentials', '-')); }
public static function getEscapedTestData($namespace, $name) { return sfOutputEscaper::escape(ESC_SPECIALCHARS, self::getRawTestData($namespace, $name)); }
/** * Escapes smarty stored vars for sfData * * @param sfSmartyView $view * @param integer $escaping * @return sfOutputEscaper */ private function getSfData($view, $escaping = ESC_RAW) { $current_sf_data = self::$smarty->get_template_vars('sf_data'); if (!empty($current_sf_data) && $view->getAttribute('sf_type') == 'partial') { if (isset($current_sf_data['sf_content'])) { $view->getAttributeHolder()->set('sf_content', $current_sf_data['sf_content']); } } return sfOutputEscaper::escape($escaping, $view->getAttributeHolder()->getAll()); }