本文整理汇总了PHP中sfOutputEscaper::escape方法的典型用法代码示例。如果您正苦于以下问题:PHP sfOutputEscaper::escape方法的具体用法?PHP sfOutputEscaper::escape怎么用?PHP sfOutputEscaper::escape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfOutputEscaper
的用法示例。
在下文中一共展示了sfOutputEscaper::escape方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* 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));
}
示例2: renderFile
/**
* 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();
}
示例3: op_api_force_escape
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;
}
示例4: executeSmtMemberTimelineBy1
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')));
}
}
示例5: get
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);
}
示例6: get
/**
* 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);
}
示例7: trimComment
/**
* 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;
}
示例8: getListJson
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);
}
示例9: __call
/**
* 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);
}
示例10: setConfigWidget
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);
}
}
}
示例11: toArray
/**
* 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;
}
示例12: dirname
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');
示例13: dirname
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');
示例14: only
$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');
示例15: op_link_to_member
/**
* 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', '-'));
}