public function getLinkToAction($actionName, $params, $pk_link = false) { $options = isset($params['params']) && !is_array($params['params']) ? sfToolkit::stringToArray($params['params']) : array(); // default values if ($actionName[0] == '_') { $actionName = substr($actionName, 1); $name = $actionName; //$icon = sfConfig::get('sf_admin_web_dir').'/images/'.$actionName.'_icon.png'; $action = $actionName; if ($actionName == 'delete') { $options['post'] = true; if (!isset($options['confirm'])) { $options['confirm'] = 'Are you sure?'; } } } else { $name = isset($params['name']) ? $params['name'] : $actionName; //$icon = isset($params['icon']) ? sfToolkit::replaceConstants($params['icon']) : sfConfig::get('sf_admin_web_dir').'/images/default_icon.png'; $action = isset($params['action']) ? $params['action'] : 'List' . sfInflector::camelize($actionName); } $url_params = $pk_link ? '?' . $this->getPrimaryKeyUrlParams() : '\''; $phpOptions = var_export($options, true); // little hack $phpOptions = preg_replace("/'confirm' => '(.+?)(?<!\\\\)'/", '\'confirm\' => __(\'$1\')', $phpOptions); return '<li class="sf_admin_action_' . sfInflector::underscore($name) . '">[?php echo link_to(__(\'' . $params['label'] . '\'), \'' . $this->getModuleName() . '/' . $action . $url_params . ($options ? ', ' . $phpOptions : '') . ') ?]</li>' . "\n"; }
/** * Returns HTML code for an action option in a select tag. * * @param string The action name * @param array The parameters * * @return string HTML code */ public function getOptionToAction($actionName, $params) { $options = isset($params['params']) ? sfToolkit::stringToArray($params['params']) : array(); // default values if ($actionName[0] == '_') { $actionName = substr($actionName, 1); if ($actionName == 'deleteSelected') { $params['name'] = 'Delete Selected'; } } $name = isset($params['name']) ? $params['name'] : $actionName; $options['value'] = $actionName; $phpOptions = var_export($options, true); return '[?php echo content_tag(\'option\', __(\'' . $name . '\')' . ($options ? ', ' . $phpOptions : '') . ') ?]'; }
public function getColumnEditTag($column, $params = array()) { // user defined parameters $user_params = $this->getParameterValue('edit.fields.' . $column->getName() . '.params'); $user_params = is_array($user_params) ? $user_params : sfToolkit::stringToArray($user_params); $params = $user_params ? array_merge($params, $user_params) : $params; if ($column->isComponent()) { return "get_component('" . $this->getModuleName() . "', '" . $column->getName() . "', array('type' => 'edit', '{$this->getSingularName()}' => \${$this->getSingularName()}))"; } else { if ($column->isPartial()) { return "get_partial('" . $column->getName() . "', array('type' => 'edit', '{$this->getSingularName()}' => \${$this->getSingularName()}))"; } } if ($this->getParameterValue('edit.fields.' . $column->getName() . '.type') == "plain") { return "'<div class=\"sf_admin_plain_field\">'.\${$this->getSingularName()}->get" . sfInflector::camelize($column->getName()) . "().'</div>'"; } else { return '$form["' . $column->getName() . '"]->render(' . $this->getObjectTagParams($params) . ')'; } }
'foo=bar' => array('foo' => 'bar'), 'foo1=bar1 foo=bar ' => array('foo1' => 'bar1', 'foo' => 'bar'), 'foo1="bar1 foo1"' => array('foo1' => 'bar1 foo1'), 'foo1="bar1 foo1" foo=bar' => array('foo1' => 'bar1 foo1', 'foo' => 'bar'), 'foo1 = "bar1=foo1" foo=bar' => array('foo1' => 'bar1=foo1', 'foo' => 'bar'), 'foo1= \'bar1 foo1\' foo = bar' => array('foo1' => 'bar1 foo1', 'foo' => 'bar'), 'foo1=\'bar1=foo1\' foo = bar' => array('foo1' => 'bar1=foo1', 'foo' => 'bar'), 'foo1= bar1 foo1 foo=bar' => array('foo1' => 'bar1 foo1', 'foo' => 'bar'), 'foo1="l\'autre" foo=bar' => array('foo1' => 'l\'autre', 'foo' => 'bar'), 'foo1="l"autre" foo=bar' => array('foo1' => 'l"autre', 'foo' => 'bar'), 'foo_1=bar_1' => array('foo_1' => 'bar_1'), ); foreach ($tests as $string => $attributes) { $t->is(sfToolkit::stringToArray($string), $attributes, '->stringToArray()'); } // ::isUTF8() $t->diag('::isUTF8()'); $t->is('été', true, '::isUTF8() returns true if the parameter is an UTF-8 encoded string'); $t->is(sfToolkit::isUTF8('AZERTYazerty1234-_'), true, '::isUTF8() returns true if the parameter is an UTF-8 encoded string'); $t->is(sfToolkit::isUTF8('AZERTYazerty1234-_'.chr(254)), false, '::isUTF8() returns false if the parameter is not an UTF-8 encoded string'); // check a very long string $string = str_repeat('Here is an UTF8 string avec du français.', 1000); $t->is(sfToolkit::isUTF8($string), true, '::isUTF8() can operate on very large strings'); // ::literalize() $t->diag('::literalize()'); foreach (array('true', 'on', '+', 'yes') as $param) {
function _parse_attributes($string) { return is_array($string) ? $string : sfToolkit::stringToArray($string); }
echo $this->getSingularName(); ?> ->save(); <?php foreach ($this->getColumnCategories('edit.display') as $category) { foreach ($this->getColumns('edit.display', $category) as $name => $column) { $type = $column->getCreoleType(); $name = $column->getName(); if ($column->isPrimaryKey()) { continue; } $credentials = $this->getParameterValue('edit.fields.' . $column->getName() . '.credentials'); $input_type = $this->getParameterValue('edit.fields.' . $column->getName() . '.type'); $user_params = $this->getParameterValue('edit.fields.' . $column->getName() . '.params'); $user_params = is_array($user_params) ? $user_params : sfToolkit::stringToArray($user_params); $through_class = isset($user_params['through_class']) ? $user_params['through_class'] : ''; if ($through_class) { $class = $this->getClassName(); $related_class = sfPropelManyToMany::getRelatedClass($class, $through_class); $related_table = constant($related_class . 'Peer::TABLE_NAME'); $middle_table = constant($through_class . 'Peer::TABLE_NAME'); $this_table = constant($class . 'Peer::TABLE_NAME'); $related_column = sfPropelManyToMany::getRelatedColumn($class, $through_class); $column = sfPropelManyToMany::getColumn($class, $through_class); if ($input_type == 'admin_double_list' || $input_type == 'admin_check_list' || $input_type == 'admin_select_list') { if ($credentials) { $credentials = str_replace("\n", ' ', var_export($credentials, true)); ?> if ($this->getUser()->hasCredential(<?php echo $credentials;
/** * Parse attributes * * @param string $string Attributes in string * @return array Attributes */ protected static function parseAttr($string) { return is_array($string) ? $string : sfToolkit::stringToArray($string); }
public function getOptionsArray() { return sfToolkit::stringToArray($this->getWidgetOptions()); }
public static function retrieveOptFromString(&$string, &$opt) { if (empty($string)) { return null; } $opt = array_merge($opt, sfToolkit::stringToArray($string)); $string = ''; }
/** * Converts the data from getMenuHierarchy into a form usable for import * by ioMenuItem. * * This is roughly opposite to the transformations done when persisting * data in persistFromMenuArray() and _convertMenuData * * @param array $data The tree array data from getMenuHierarchy() * @return array */ protected static function _convertHierarchyToMenuArray($data) { unset($data['level'], $data['id']); if (isset($data['Permissions'])) { $credentials = array(); foreach ($data['Permissions'] as $permission) { $credentials[] = $permission['name']; } $data['credentials'] = $credentials; unset($data['Permissions']); } // handle i18n if (isset($data['Translation'])) { // we have i18n, so create an array of i18n labels $i18nLabels = array(); foreach ($data['Translation'] as $culture => $i18nData) { if ($i18nData['label']) { $i18nLabels[$culture] = $i18nData['label']; } } $data['i18n_labels'] = $i18nLabels; unset($data['Translation']); // try to set the default label from the default culture $defaultCulture = sfConfig::get('sf_default_culture'); if (isset($i18nLabels[$defaultCulture])) { $data['label'] = $i18nLabels[$defaultCulture]; } } // convert the attributes back into an array $data['attributes'] = sfToolkit::stringToArray($data['attributes']); // handle the children data if (isset($data['__children'])) { $childrenData = array(); foreach ($data['__children'] as $childData) { // recurse the children data onto this method $childrenData[$childData['name']] = self::_convertHierarchyToMenuArray($childData); } $data['children'] = $childrenData; unset($data['__children']); } return $data; }
/** * Returns the CSS classes to apply as a string * * @param string $params * @return string * @static */ public static function getClasses($params) { $table = sfToolkit::stringToArray($params); return $table['class']; }
public function getParamsArray() { return $this->get('params') ? sfToolkit::stringToArray($this->get('params')) : array(); }
/** * Returns HTML code for a column in list mode. * * @param string The column name * @param array The parameters * * @return string HTML code */ public function getColumnListTag($column, $params = array()) { $user_params = $this->getParameterValue('list.fields.' . $column->getName() . '.params'); $user_params = is_array($user_params) ? $user_params : sfToolkit::stringToArray($user_params); $params = $user_params ? array_merge($params, $user_params) : $params; $type = $column->getType(); $columnGetter = $this->getColumnGetter($column, true); if ($column->isComponent()) { return "get_component('" . $this->getModuleName() . "', '" . $column->getName() . "', array('type' => 'list', '{$this->getSingularName()}' => \${$this->getSingularName()}))"; } else { if ($column->isPartial()) { return "get_partial('" . $column->getName() . "', array('type' => 'list', '{$this->getSingularName()}' => \${$this->getSingularName()}))"; } else { if ($type == PropelColumnTypes::DATE || $type == PropelColumnTypes::TIMESTAMP) { $format = isset($params['date_format']) ? $params['date_format'] : ($type == PropelColumnTypes::DATE ? 'D' : 'f'); return "({$columnGetter} !== null && {$columnGetter} !== '') ? format_date({$columnGetter}, \"{$format}\") : ''"; } elseif ($type == PropelColumnTypes::BOOLEAN) { return "{$columnGetter} ? image_tag(sfConfig::get('sf_admin_web_dir').'/images/tick.png') : ' '"; } else { return "{$columnGetter}"; } } } }
/** * Apply common options to a value. * * @param mixed $value * @param mixed $options * * @return bool whether to continue execution */ protected function prepare(&$value, &$options = array()) { if (is_string($options)) { $options = sfToolkit::stringToArray($options); } if (isset($options['use_flash']) && $options['use_flash']) { unset($options['use_flash']); $trace = debug_backtrace(); $caller = $trace[1]; $this->plant($caller['function'], array($value, $options)); return false; } else { if (is_string($value) && isset($options['is_route']) && $options['is_route']) { $value = $this->context->getController()->genUrl($value); unset($options['is_route']); } return true; } }
/** * Returns HTML code for a column in filter mode. * * @param string The column name * @param array The parameters * * @return string HTML code */ public function getColumnFilterTag($column, $params = array()) { $user_params = $this->getParameterValue('list.fields.' . $column->getColumnName() . '.params'); $user_params = is_array($user_params) ? $user_params : sfToolkit::stringToArray($user_params); $params = $user_params ? array_merge($params, $user_params) : $params; # if ($column->isComponent()) # { # return "get_component('".$this->getModuleName()."', '".$column->getName()."', array('type' => 'list'))"; # } # else if ($column->isPartial()) # { # return "get_partial('".$column->getName()."', array('type' => 'filter', 'filters' => \$filters))"; # } $type = $column->getCreoleType(); $default_value = "isset(\$filters['" . $column->getColumnName() . "']) ? \$filters['" . $column->getColumnName() . "'] : null"; $unquotedName = 'filters[' . $column->getColumnName() . ']'; $name = "'{$unquotedName}'"; if ($column->isForeignKey()) { $params = $this->getObjectTagParams($params, array('include_blank' => true, 'related_class' => $this->getRelatedClassName($column), 'text_method' => '__toString', 'control_name' => $unquotedName)); return "object_select_tag({$default_value}, null, {$params})"; } else { if ($type == CreoleTypes::DATE) { // rich=false not yet implemented $params = $this->getObjectTagParams($params, array('middle' => '<br>', 'rich' => true, 'calendar_button_img' => sfConfig::get('sf_admin_web_dir') . '/images/calendar.gif')); return "input_date_range_tag({$name}, {$default_value}, {$params})"; } else { if ($type == CreoleTypes::TIMESTAMP) { // rich=false not yet implemented $params = $this->getObjectTagParams($params, array('middle' => '<br>', 'rich' => true, 'withtime' => true, 'calendar_button_img' => sfConfig::get('sf_admin_web_dir') . '/images/calendar.gif')); return "input_date_range_tag({$name}, {$default_value}, {$params})"; } else { if ($type == CreoleTypes::BOOLEAN) { $defaultIncludeCustom = '__("yes or no")'; $option_params = $this->getObjectTagParams($params, array('include_custom' => $defaultIncludeCustom)); $params = $this->getObjectTagParams($params); // little hack $option_params = preg_replace("/'" . preg_quote($defaultIncludeCustom) . "'/", $defaultIncludeCustom, $option_params); $options = "options_for_select(array(1 => __('yes'), 0 => __('no')), {$default_value}, {$option_params})"; return "select_tag({$name}, {$options}, {$params})"; } else { if ($type == CreoleTypes::CHAR || $type == CreoleTypes::VARCHAR || $type == CreoleTypes::TEXT || $type == CreoleTypes::LONGVARCHAR) { $size = $column->getSize() < 15 ? $column->getSize() : 15; $params = $this->getObjectTagParams($params, array('size' => $size)); return "input_tag({$name}, {$default_value}, {$params})"; } else { if ($type == CreoleTypes::INTEGER || $type == CreoleTypes::TINYINT || $type == CreoleTypes::SMALLINT || $type == CreoleTypes::BIGINT) { $params = $this->getObjectTagParams($params, array('size' => 7)); return "input_tag({$name}, {$default_value}, {$params})"; } else { if ($type == CreoleTypes::FLOAT || $type == CreoleTypes::DOUBLE || $type == CreoleTypes::DECIMAL || $type == CreoleTypes::NUMERIC || $type == CreoleTypes::REAL) { $params = $this->getObjectTagParams($params, array('size' => 7)); return "input_tag({$name}, {$default_value}, {$params})"; } else { $params = $this->getObjectTagParams($params, array('disabled' => true)); return "input_tag({$name}, {$default_value}, {$params})"; } } } } } } } }
public function tag($tagName, $opt = array(), $content = false, $openAndClose = true) { if (!($tagName = trim($tagName))) { return ''; } $tagOpt = array(); // separate tag name from attribues in $tagName if ($firstSpacePos = strpos($tagName, ' ')) { $tagNameOpt = substr($tagName, $firstSpacePos + 1); $tagName = substr($tagName, 0, $firstSpacePos); // DMS STYLE - string opt in name dmString::retrieveOptFromString($tagNameOpt, $tagOpt); } // JQUERY STYLE - css expression dmString::retrieveCssFromString($tagName, $tagOpt); // ARRAY STYLE - array opt if (is_array($opt) && !empty($opt)) { if (isset($opt['json'])) { $tagOpt['class'][] = json_encode($opt['json']); unset($opt['json']); } if (isset($opt['class'])) { $tagOpt['class'][] = is_array($opt['class']) ? implode(' ', $opt['class']) : $opt['class']; unset($opt['class']); } $tagOpt = array_merge($tagOpt, $opt); } elseif (is_string($opt) && $content) { $opt = sfToolkit::stringToArray($opt); if (isset($opt['class'])) { $tagOpt['class'][] = explode(' ', $opt['class']); unset($opt['class']); } $tagOpt = array_merge($tagOpt, $opt); } if (!$content) { if (!is_array($opt)) { $content = $opt; } else { $content = null; } } $class = isset($tagOpt['class']) ? $tagOpt['class'] : array(); if ($this->options['use_beaf'] && (in_array('beafh', $class) || in_array('beafv', $class))) { $isBeaf = true; $tagOpt['class'][] = 'clearfix'; $beafTag = in_array($tagName, array('span', 'a', 'p')) ? 'span' : 'div'; } else { $isBeaf = false; } if (isset($tagOpt['lang'])) { if ($tagOpt['lang'] === $this->context->getUser()->getCulture()) { unset($tagOpt['lang']); } } if (isset($tagOpt['class']) && is_array($tagOpt['class'])) { $tagOpt['class'] = implode(' ', array_unique($tagOpt['class'])); } $optHtml = ''; foreach ($tagOpt as $key => $val) { $optHtml .= ' ' . $key . '="' . htmlentities($val, ENT_COMPAT, 'UTF-8') . '"'; } if (in_array($tagName, $this->options['empty_elements'])) { $tag = '<' . $tagName . $optHtml . ' />'; } elseif ($openAndClose) { if ($isBeaf) { $tag = '<' . $tagName . $optHtml . '><' . $beafTag . ' class="beafore"></' . $beafTag . '><' . $beafTag . ' class="beafin">' . $content . '</' . $beafTag . '><' . $beafTag . ' class="beafter"></' . $beafTag . '></' . $tagName . '>'; } else { $tag = '<' . $tagName . $optHtml . '>' . $content . '</' . $tagName . '>'; } } else { if ($isBeaf) { $tag = '<' . $tagName . $optHtml . '><' . $beafTag . ' class="beafore"></' . $beafTag . '><' . $beafTag . ' class="beafin">'; } else { $tag = '<' . $tagName . $optHtml . '>'; } } return $tag; }
/** * @param $column * @param $params * @param $action * @return array */ private function getParams( $column, $params, $action ) { $user_params = $this->getParameterValue( $action . '.fields.' . $column->getName() . '.params' ); $user_params = is_array( $user_params ) ? $user_params : sfToolkit::stringToArray( $user_params ); $params = $user_params ? array_merge( $params, $user_params ) : $params; return $params; }