/** * Creates a <a> link tag of the given name using a routed URL * based on the module/action passed as argument and the routing configuration. * * If null is passed as a name, the link itself will become the name. * * Examples: * echo link_to('Homepage', 'default/index') * => <a href="/">Homepage</a> * * echo link_to('News 2008/11', 'news/index?year=2008&month=11') * => <a href="/news/2008/11">News 2008/11</a> * * echo link_to('News 2008/11 [absolute url]', 'news/index?year=2008&month=11', array('absolute'=>true)) * => <a href="http://myapp.example.com/news/2008/11">News 2008/11 [absolute url]</a> * * echo link_to('Absolute url', 'http://www.google.com') * => <a href="http://www.google.com">Absolute url</a> * * echo link_to('Link with attributes', 'default/index', array('id'=>'my_link', 'class'=>'green-arrow')) * => <a id="my_link" class="green-arrow" href="/">Link with attributes</a> * * echo link_to('<img src="x.gif" width="150" height="100" alt="[link with image]" />', 'default/index' ) * => <a href="/"><img src="x.gif" width="150" height="100" alt="[link with image]" /></a> * * * Options: * 'absolute' - if set to true, the helper outputs an absolute URL * 'query_string' - to append a query string (starting by ?) to the routed url * 'anchor' - to append an anchor (starting by #) to the routed url * * @param string text appearing between the <a> tags * @param string 'module/action' or '@rule' of the action, or an absolute url * @param array additional HTML compliant <a> tag parameters * @return string XHTML compliant <a href> tag * @see url_for */ function link_to($name = '', $internal_uri = '', $options = array()) { $html_options = _parse_attributes($options); $absolute = false; if (isset($html_options['absolute'])) { $absolute = (bool) $html_options['absolute']; unset($html_options['absolute']); } // Fabrice: FIXME (genUrl() doesnt like '#anchor' ?) => ignore empty string $html_options['href'] = $internal_uri !== '' ? url_for($internal_uri, $absolute) : ''; // anchor if (isset($html_options['anchor'])) { $html_options['href'] .= '#' . $html_options['anchor']; unset($html_options['anchor']); } if (isset($html_options['query_string'])) { $html_options['href'] .= '?' . $html_options['query_string']; unset($html_options['query_string']); } if (is_object($name)) { if (method_exists($name, '__toString')) { $name = $name->__toString(); } else { DBG::error(sprintf('Object of class "%s" cannot be converted to string (Please create a __toString() method).', get_class($name))); } } if (!strlen($name)) { $name = $html_options['href']; } return content_tag('a', $name, $html_options); }
/** * Return the HTML code for an unordered list showing opinions that can be voted (no AJAX) * If the user has already voted, then a message appears * * @param BaseObject $object Propel object instance to vote * @param string $message a message string to be displayed in the voting-message block * @param array $options Array of HTML options to apply on the HTML list * @return string **/ function depp_omnibus_selector($object, $message = '', $options = array()) { if (is_null($object)) { sfLogger::getInstance()->debug('A NULL object cannot be flagged as Omnibus'); return ''; } $user_id = sfContext::getInstance()->getUser()->getId(); try { $options = _parse_attributes($options); if (!isset($options['id'])) { $options = array_merge($options, array('id' => 'omnibus-flag')); } $object_is_omnibus = $object->getIsOmnibus(); $object_will_be_omnibus = !$object_is_omnibus; $selector = ''; if ($object_is_omnibus) { $status = "Questo atto è Omnibus"; $label = "Marcalo come non-Omnibus"; } else { $status = "Questo atto non è Omnibus"; $label = "Marcalo come Omnibus"; } $selector .= link_to($label, sprintf('atto/setOmnibusStatus?id=%d&status=%d', $object->getId(), $object_will_be_omnibus), array('post' => true)); return content_tag('div', $status) . content_tag('div', $selector, $options); } catch (Exception $e) { sfLogger::getInstance()->err('Exception catched from deppOmnibus helper: ' . $e->getMessage()); } }
function lang_anchor($controller = '', $method = FALSE, $params = FALSE, $title = FALSE, $attributes = FALSE) { $title = (string) $title; $CI =& get_instance(); $lng = $CI->config->item('language'); $base_url = $CI->config->item('base_url') . "/"; $site_url = $base_url; if ($controller) { $trans_controller = get_class_name_controller_from_translation($controller, $lng); $site_url .= $trans_controller . "/"; } if ($method) { $trans_method = get_method_name_from_translation($trans_controller, $method, $lng); $site_url .= $trans_method . "/"; } if ($params) { $site_url .= $params . "/"; } if ($title == '') { $title = $site_url; } if ($attributes != '') { $attributes = _parse_attributes($attributes); } return '<a href="' . $site_url . '"' . $attributes . '>' . $title . '</a>'; }
function form_error($param, $options = array(), $catalogue = 'messages') { $param_for_sf = str_replace(array('[', ']'), array('{', '}'), $param); $param = str_replace(array('{', '}'), array('[', ']'), $param); $options = _parse_attributes($options); $request = sfContext::getInstance()->getRequest(); $style = $request->hasError($param_for_sf) ? '' : 'display:none;'; $options['style'] = $style . (isset($options['style']) ? $options['style'] : ''); if (!isset($options['class'])) { $options['class'] = sfConfig::get('sf_validation_error_class', 'form_error'); } if (!isset($options['id'])) { $options['id'] = sfConfig::get('sf_validation_error_id_prefix', 'error_for_') . get_id_from_name($param); } $prefix = sfConfig::get('sf_validation_error_prefix', ''); if (isset($options['prefix'])) { $prefix = $options['prefix']; unset($options['prefix']); } $suffix = sfConfig::get('sf_validation_error_suffix', ''); if (isset($options['suffix'])) { $suffix = $options['suffix']; unset($options['suffix']); } $error = $request->getError($param_for_sf, $catalogue); return content_tag('div', $prefix . $error . $suffix, $options) . "\n"; }
function image_tag($source, $options = array()) { if (!$source) { return ''; } $options = _parse_attributes($options); $absolute = false; if (isset($options['absolute'])) { unset($options['absolute']); $absolute = true; } $options['src'] = system_url($source); if (!isset($options['alt'])) { $path_pos = strrpos($source, '/'); $dot_pos = strrpos($source, '.'); $begin = $path_pos ? $path_pos + 1 : 0; $nb_str = ($dot_pos ? $dot_pos : strlen($source)) - $begin; $options['alt'] = ucfirst(substr($source, $begin, $nb_str)); } if (isset($options['size'])) { list($options['width'], $options['height']) = split('x', $options['size'], 2); unset($options['size']); } return tag('img', $options); }
/** * Return the HTML code for an unordered list showing opinions that can be voted (no AJAX) * If the user has already voted, then a message appears * * @param BaseObject $object Propel object instance to vote * @param string $message a message string to be displayed in the voting-message block * @param array $options Array of HTML options to apply on the HTML list * @return string **/ function depp_prioritiser($object, $message = '', $options = array()) { if (is_null($object)) { sfLogger::getInstance()->debug('A NULL object cannot be prioritised'); return ''; } $user_id = sfContext::getInstance()->getUser()->getId(); try { $options = _parse_attributes($options); if (!isset($options['id'])) { $options = array_merge($options, array('id' => 'prioritising-items')); } $object_id = $object->getPrioritisableReferenceKey(); $list_content = ''; $object_priority = is_null($object->getPriorityValue()) ? 1 : $object->getPriorityValue(); for ($i = $object->allowsNullPriority() ? 0 : 1; $i <= $object->getMaxPriority(); $i++) { if ($object_priority == $i) { if ($object->getPriorityLastUser() != 0) { $label = sprintf('Priorità impostata da user_id:%d il %s alle %s', $object->getPriorityLastUser(), $object->getPriorityLastUpdate('d/m/Y'), $object->getPriorityLastUpdate('h:i')); } else { $label = 'Priorità di default'; } $list_content .= content_tag('li', content_tag('span', $i, array('title' => $label)), array('class' => 'current')); } else { $label = sprintf(__('Set priority to %d'), $i); $list_content .= content_tag('li', link_to($i, sprintf('deppPrioritising/prioritise?object_id=%d&object_model=%s&priority=%d', $object->getId(), get_class($object), $i), array('title' => $label, 'post' => true))); } } return content_tag('ul', $list_content, $options) . content_tag('div', $message, array('id' => 'priority-message')); } catch (Exception $e) { sfLogger::getInstance()->err('Exception catched from deppPrioritising helper: ' . $e->getMessage()); } }
/** * Returns a link with a gBox widget attached * * @param string $content content to show inside the a tag * @param string $href url (inline/ajax) to show in the gbox * @param array $options Options of the link * * @author Gerald Estadieu <*****@*****.**> * @since 15 Apr 2007 * */ function gbox($content, $href = '', $options = array()) { _loadRessources(); $html_options = _parse_attributes($options); $html_options['class'] = isset($options['class']) ? $options['class'] . ' gbox' : 'gbox'; return link_to($content, $href, $html_options); }
/** * Override of the standard options_for_select, that allows the usage of the 'include_zero_custom' option * to insert a custom field returning the 0 value on top of the options * * @return String * @author Guglielmo Celata **/ function adv_options_for_select($options = array(), $selected = '', $html_options = array()) { $html_options = _parse_attributes($html_options); if (is_array($selected)) { $selected = array_map('strval', array_values($selected)); } $html = ''; if ($value = _get_option($html_options, 'include_zero_custom')) { $html .= content_tag('option', $value, array('value' => '0')) . "\n"; } else { if ($value = _get_option($html_options, 'include_custom')) { $html .= content_tag('option', $value, array('value' => '')) . "\n"; } else { if (_get_option($html_options, 'include_blank')) { $html .= content_tag('option', '', array('value' => '')) . "\n"; } } } foreach ($options as $key => $value) { if (is_array($value)) { $html .= content_tag('optgroup', options_for_select($value, $selected, $html_options), array('label' => $key)) . "\n"; } else { $option_options = array('value' => $key); if (is_array($selected) && in_array(strval($key), $selected, true) || strval($key) == strval($selected)) { $option_options['selected'] = 'selected'; } $html .= content_tag('option', $value, $option_options) . "\n"; } } return $html; }
/** * two multiline select tags with associated and unassociated items * * @return string * @param object object * @param string method of object * @param array options * @param array html options of select tags **/ function double_list($object, $method, $options = array(), $html_options = array()) { $options = _parse_attributes($options); // get the lists of objects list($all_objects, $objects_associated, $associated_ids) = _get_object_list($object, $method, _get_option($options, 'through_class'), _get_option($options, 'peer_method')); // options $html_options['multiple'] = _get_option($html_options, 'multiple', true); $html_options['size'] = _get_option($html_options, 'size', 5); $html_options['class'] = 'double_list'; $label_assoc = _get_option($options, 'associated_label', 'Zugeh�rige Gruppen'); $label_all = _get_option($options, 'unassociated_label', 'Gruppenliste'); $name1 = _get_option($options, 'associated', 'isSelected'); $name2 = _get_option($options, 'unassociated', 'unSelected'); $form = _get_option($options, 'form_id', 'editForm'); // unassociated objects $objects_unassociated = array(); foreach ($all_objects as $object) { if (!in_array($object->getPrimaryKey(), $associated_ids)) { $objects_unassociated[] = $object; } } // select tags $select1 = select_tag($name1, options_for_select(_get_options_from_objects($objects_associated), '', $options), $html_options); unset($html_options['class']); $select2 = select_tag($name2, options_for_select(_get_options_from_objects($objects_unassociated), '', $options), $html_options); // output skeloton $html = "\n<table><tr>\n\t<td class='first'><div class='first' style='padding-bottom:0px;padding-left:15px;'>{$label_assoc}</div>%s</td>\n\t<td class='first'><div class='first' style='padding-bottom:0px;padding-left:15px;'> </div>%s<br/>%s</td>\n\t<td class='first'><div class='first' style='padding-bottom:0px;padding-left:15px;'>{$label_all}</div>%s</td>\n</tr></table>\n"; // include js library $response = sfContext::getInstance()->getResponse(); $response->addJavascript('/js/double_list.js', 'last'); return sprintf($html, $select1, link_to_function(image_tag('resultset_previous'), "double_list_move(\$('{$name2}'), \$('{$name1}'))"), link_to_function(image_tag('resultset_next'), "double_list_move(\$('{$name1}'), \$('{$name2}'))", 'style=display:block'), $select2, $form); }
function anchor($uri = '', $title = '', $attributes = '') { $title = (string) $title; $id = ''; if (strpos($uri, '#')) { $uri_part = explode('#', $uri); $uri = $uri_part[0]; $id = '#' . $uri_part[1]; } if ($uri == '/') { $site_url = base_url(); } elseif (!is_array($uri)) { $site_url = !preg_match('!^\\w+://! i', $uri) ? site_url($uri) : $uri; } else { $site_url = site_url($uri); } if (!isset($attributes['title'])) { $attributes['title'] = strip_tags($title); } if ($title == '') { $title = $site_url; } if ($attributes != '') { $attributes = _parse_attributes($attributes); } return '<a href="' . $site_url . $id . '"' . $attributes . '>' . $title . '</a>'; }
function anchor($uri = '', $title = '', $attributes = '', $ssl = FALSE) { $title = (string) $title; if (!is_array($uri)) { if ($ssl) { $site_url = !preg_match('!^\\w+://!i', $uri) ? site_url($uri, TRUE) : $uri; } else { $site_url = !preg_match('!^\\w+://!i', $uri) ? site_url($uri) : $uri; } } else { if ($ssl) { $site_url = site_url($uri, TRUE); } else { $site_url = site_url($uri); } } if ($title == '') { $title = $site_url; } if ($attributes == '') { $attributes = ' title="' . $title . '"'; } else { $attributes = _parse_attributes($attributes); } return '<a href="' . $site_url . '"' . $attributes . '>' . $title . '</a>'; }
/** * Searches through the content and extracts out any matches. The return * value is a formatted array of what needs to be replaced * * Returned syntax will look like this: * array( * 'link' => array( * 3 => array('options' => array(), 'replace' => '[link:3]'), * 5 => array('options' => array('option' => 'value'), 'replace' => '[link:5 option=value]'), * ), asset => array( * 10 => array('options' => array(), 'replace' => '[asset:10]'), * ), * ) * * @return array */ private function _parseSyntaxes($content) { // create the replacement string (e.g. link|asset|myObject) $replacementString = implode('|', array_keys(sfSympalConfig::get('content_syntax_types'))); preg_match_all("/\\[({$replacementString}):(.*?)\\]/", $content, $matches); if (isset($matches[0]) && $matches[0]) { $replacements = array(); $types = $matches[1]; $bodies = $matches[2]; foreach ($types as $type) { $replacements[$type] = array(); } /* * body matches (e.g. "3" or "5 option=value") */ foreach ($bodies as $key => $body) { // use the key to find the corresponding type $typeKey = $types[$key]; $e = explode(' ', $body); $slug = $e[0]; $replacements[$typeKey][$slug] = array('options' => _parse_attributes(substr($body, strlen($e[0]))), 'replace' => $matches[0][$key]); } return $replacements; } else { return false; } }
function link_to_star($object, $options = array()) { $user = sfContext::getInstance()->getUser(); if ($user->isAuthenticated()) { $response = sfContext::getInstance()->getResponse(); $has_jquery = sfConfig::get('app_sfPropelActAsStarredBehaviorPlugin_has_jquery'); if (!$has_jquery) { $response->addJavascript('/sfPropelActAsStarredBehaviorPlugin/js/jquery-1.2.2.pack'); } $response->addJavascript('/sfPropelActAsStarredBehaviorPlugin/js/sf_star'); $is_starred = $object->isStarred() ? 'sf_star_on' : 'sf_star_off'; $options = _parse_attributes($options); if (isset($options['class'])) { $options['class'] .= ' sf_star ' . $is_starred; } else { $options['class'] = 'sf_star ' . $is_starred; } $type = sfConfig::get('app_sfPropelActAsStarredBehaviorPlugin_content_type', null); if (!$type || $type == 'image') { $content = $object->isStarred() ? image_tag(sfConfig::get('app_sfPropelActAsStarredBehaviorPlugin_image_on', '/sfPropelActAsStarredBehaviorPlugin/images/star_on.gif')) : image_tag(sfConfig::get('app_sfPropelActAsStarredBehaviorPlugin_image_off', '/sfPropelActAsStarredBehaviorPlugin/images/star_off.gif')); } elseif (isset($options['txt_on']) && isset($options['txt_off'])) { $content = $object->isStarred() ? $options['txt_off'] : $options['txt_on']; } else { $content = $object->isStarred() ? sfConfig::get('app_sfPropelActAsStarredBehaviorPlugin_content_on') : sfConfig::get('app_sfPropelActAsStarredBehaviorPlugin_content_off'); } $model = get_class($object); $id = $object->getPrimaryKey(); return link_to($content, 'sfStar/starit?model=' . $model . '&id=' . $id, $options); // return content_tag('span',link_to($image,'sfStar/starit?model='.$model.'&id='.$id,'class=sf_star')); } else { return content_tag('span', ''); } }
function object_input_sf_asset_tag($object, $method, $options = array()) { $options = _parse_attributes($options); $name = _convert_method_to_name($method, $options); $value = _get_object_value($object, $method); return input_sf_asset_tag($name, $value, $options); }
/** * Return the HTML code for the launch/remove link * plus the list of launched object for the namespace * * @param BaseObject $object Propel object instance to launch * @param string $namespace The namespace where the object is *launched* * @param array $options Array of HTML options to apply on the HTML list * @return string **/ function depp_launcher($object, $namespace, $options = array()) { if (is_null($object)) { sfLogger::getInstance()->debug('A NULL object cannot be launched'); return ''; } if (is_null($namespace)) { sfLogger::getInstance()->debug('A namespace must be given'); return ''; } try { $options = _parse_attributes($options); if (!isset($options['id'])) { $options = array_merge($options, array('id' => 'launching-items')); } if (!isset($options['class'])) { $options = array_merge($options, array('class' => 'vote-administration')); } $object_model = get_class($object); $object_id = $object->getPrimaryKey(); // build launch/remove link if (in_array($namespace, $object->hasBeenLaunched())) { $action_link = link_to(__('Take the launch back'), sprintf('deppLaunching/remove?item_model=%s&item_pk=%s&namespace=%s', $object_model, $object_id, $namespace)); } else { $action_link = link_to(__('Launch the object'), sprintf('deppLaunching/launch?item_model=%s&item_pk=%s&namespace=%s', $object_model, $object_id, $namespace)); } $action = content_tag('div', $action_link); $list_content = ''; $launches = sfLaunchingPeer::getAllByNamespace($namespace); foreach ($launches as $i => $l) { $l_obj_model = $l->getObjectModel(); $l_obj_id = $l->getObjectId(); $l_obj = deppPropelActAsLaunchableToolkit::retrieveLaunchableObject($l_obj_model, $l_obj_id); $l_obj_short_string = $l_obj->getShortTitle(); $l_obj_remove_action = sprintf('deppLaunching/remove?item_model=%s&item_pk=%s&namespace=%s', $l_obj_model, $l_obj_id, $namespace); $l_obj_priority_up_action = sprintf('deppLaunching/priorityUp?item_model=%s&item_pk=%s&namespace=%s', $l_obj_model, $l_obj_id, $namespace); $l_obj_priority_dn_action = sprintf('deppLaunching/priorityDn?item_model=%s&item_pk=%s&namespace=%s', $l_obj_model, $l_obj_id, $namespace); $l_obj_remove_link = link_to('<img src="/images/ico-remove_alert.png" alt="X" title="Rimuovi" />', $l_obj_remove_action, array('title' => __('Take the launch back'), 'class' => 'remove-vote')); $l_obj_priority_up_link = link_to('<img src="/images/ico-thumb-up.png" alt="+" title="Aumenta priorità" />', $l_obj_priority_up_action, array('title' => __('Increase the priority'), 'class' => 'moveup-vote')); $l_obj_priority_dn_link = link_to('<img src="/images/ico-thumb-down.png" alt="-" title="Diminuisci priorità" />', $l_obj_priority_dn_action, array('title' => __('Decrease the priority'), 'class' => 'movedown-vote')); $l_obj_actions = ""; /*if ($i > 0)*/ $l_obj_actions .= " {$l_obj_priority_up_link} "; /*if ($i < count($launches) - 1 )*/ $l_obj_actions .= " {$l_obj_priority_dn_link} "; $l_obj_actions .= " {$l_obj_remove_link} "; /*$list_content .= content_tag('tr', content_tag('td', '<input type="text" value="'. $l->getPriority().'" name="priority['. $l_obj_id.']" size="3">'. $l_obj_short_string) . content_tag('td', $l_obj_actions, array('style' => 'text-align:right; width:36px;display:inline-block;')));*/ $list_content .= content_tag('li', content_tag('span', $l_obj_actions, array('style' => 'text-align:right; width:36px;display:inline-block;float:right;')) . $l_obj_short_string, array('style' => 'cursor:move; border-bottom: 1px dotted #CCC;')); } $list = content_tag('ul', $list_content, $options); // adding javascript for drag and drop //use_javascript('/js/jquery-ui-1.8.16.sortable.min.js'); return $action . $list; } catch (Exception $e) { sfLogger::getInstance()->err('Exception catched from deppLaunching helper: ' . $e->getMessage()); } }
/** * Returns a button that will trigger a javascript function using the * onclick handler and return false after the fact. * * Examples: * <?php echo button_to_function('Greeting', "alert('Hello world!')") ?> */ function button_to_function($name, $function, $html_options = array()) { $html_options = _parse_attributes($html_options); $html_options['onclick'] = $function . '; return false;'; $html_options['type'] = 'button'; $html_options['value'] = $name; return tag('input', $html_options); }
/** * Returns a link that will trigger a javascript function using the * onclick handler and return TRUE OR FALSE after the fact * depending on the $html_options['return'] parameter. * This attribute is removed before we use the default content_tag helper. * * Examples: * <?php echo link_to_function('Greeting', "alert('Hello world!')", array('return'=>true)) ?> * <?php echo link_to_function(image_tag('delete'), "if confirm('Really?'){ do_delete(); }") ?> */ function ls_link_to_function($name, $function, $html_options = array()) { $html_options = _parse_attributes($html_options); $html_options['href'] = isset($html_options['href']) ? $html_options['href'] : '#'; $html_options['onclick'] = $function . '; return '; $html_options['onclick'] .= isset($html_options['return']) && $html_options['return'] == true ? 'true;' : 'false;'; unset($html_options['return']); return content_tag('a', $name, $html_options); }
function _tag_options($options = array()) { $options = _parse_attributes($options); $html = ''; foreach ($options as $key => $value) { $html .= ' ' . $key . '="' . escape_once($value) . '"'; } return $html; }
function antispam_email_tag($emailaddress, $content = null, $options = array()) { $options = _parse_attributes($options); $options['href'] = 'mailto:' . $emailaddress; if ($content === null) { $content = $emailaddress; } return antispam_js_encrypt(content_tag('a', $content, $options), rand(-8, 5)); }
function gButton_to_function($text, $javascript = null, $html_options = null, $button_options = array()) { $html_options = _parse_attributes($html_options); if (array_key_exists('confirm', $html_options)) { $txt = $html_options['confirm']; $javascript = sprintf("if(confirm('{$txt}')){ %s; }", $javascript ? $javascript : "return true"); } $html_options['onclick'] = $javascript . ";return false;"; return gButton($text, $html_options, $button_options); }
function form_remote_tag($options = array(), $options_html = array()) { $options = _parse_attributes($options); $options_html = _parse_attributes($options_html); $options['form'] = true; $options_html['onsubmit'] = remote_function($options) . '; return false;'; $options_html['action'] = isset($options_html['action']) ? $options_html['action'] : system_url($options['url']); $options_html['method'] = isset($options_html['method']) ? $options_html['method'] : 'post'; return tag('form', $options_html, true); }
/** * Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular * reloading POST arrangement. Even though it's using JavaScript to serialize the form elements, the form submission * will work just like a regular submission as viewed by the receiving side (all elements available in 'params'). * The options for specifying the target with 'url' and defining callbacks are the same as 'link_to_remote()'. * * A "fall-through" target for browsers that don't do JavaScript can be specified * with the 'action'/'method' options on '$options_html' * * Example: * <?php echo form_remote_tag(array( * 'url' => '@tag_add', * 'update' => 'question_tags', * 'loading' => "Element.show('indicator'); \$('tag').value = ''", * 'complete' => "Element.hide('indicator');".visual_effect('highlight', 'question_tags'), * )) ?> * * The hash passed as a second argument is equivalent to the options (2nd) argument in the form_tag() helper. * * By default the fall-through action is the same as the one specified in the 'url' * (and the default method is 'post'). * * Modified to have parameters with the url */ function scss_form_remote_tag($options = array(), $options_html = array()) { $options = _parse_attributes($options); $options_html = _parse_attributes($options_html); $options['form'] = true; $options_html['onsubmit'] = dd_remote_function($options) . '; return false;'; $options_html['action'] = isset($options_html['action']) ? $options_html['action'] : (isset($options['url_params']) ? url_for($options['url'], $options['url_params']) : url_for($options['url'])); $options_html['method'] = isset($options_html['method']) ? $options_html['method'] : 'post'; return tag('form', $options_html, true); }
function anchor2($url, $titulo, $atrib = '') { $titulo = (string) $titulo; if (is_array($url)) { $url = implode('/', $url); } if ($atrib != '') { $atrib = _parse_attributes($atrib); } $url = relative_root($url); return '<a href="' . $url . '"' . $atrib . '>' . $titulo . '</a>'; }
function favicon_byslug_tag($pSlug, array $pParams = array()) { $lOptions = _parse_attributes($pParams); if (!isset($lOptions['alt'])) { $lOptions['alt'] = $pSlug; } if (!isset($lOptions['class'])) { $lOptions['class'] = 'favicon'; } else { $lOptions['class'] = $lOptions['class'] . ' favicon'; } return image_tag('/uploads/favicons/' . $pSlug . '.png', $lOptions); }
function grafico($uri = null, $options = array()) { $options = _parse_attributes($options); $options['width'] = isset($options['width']) ? $options['width'] : '300'; $options['height'] = isset($options['height']) ? $options['height'] : '200'; $ruta = sfContext::getInstance()->getUser()->getAttribute('ruta', null); $direccion = $ruta . "/index.php/" . $uri; $value = null; try { $value = open_flash_chart_object_str($options['width'], $options['height'], $direccion, true, $ruta . "/"); return $value ? $value : null; } catch (Exception $e) { return null; } }
public static function mp3PlayerTag($options = array(), $options_html = array()) { $player = sfConfig::get('app_mp3player_defaultplayer', 'worldpress'); switch ($player) { case 'flash-mp3-player': $options = _parse_attributes($options); $options_html = _parse_attributes($options_html); $trackURI = urlencode(isset($options['trackURI']) ? $options['trackURI'] : ''); $trackURInotencoded = isset($options['trackURI']) ? $options['trackURI'] : ''; $flashplayerid = isset($options['flashplayerid']) ? $options['flashplayerid'] : ''; $customSkin = isset($options['customSkin']) ? $options['customSkin'] : ''; $playerConfig = sfConfig::get('app_mp3player_flash-mp3-player'); $autoplay = isset($playerConfig['autoplay']) ? $playerConfig['autoplay'] : '1'; $width = isset($playerConfig['width']) ? $playerConfig['width'] : '200'; $img = isset($playerConfig['img']) ? image_path($playerConfig['img']) : 'nopreview.defined'; $imgmouseover = isset($playerConfig['imgmouseover']) ? image_path($playerConfig['imgmouseover']) : 'nopreview.defined'; $options_html['onClick'] = "javascript: swfobject.createSWF(\n { data:'" . public_path("/mp3player/player_mp3_maxi.swf") . "', width:'{$width}', height:'15' }, \n { flashvars:'mp3={$trackURI}&showslider=1&width={$width}&height=15&autoplay={$autoplay}'}, \n '{$flashplayerid}'); \n return false;"; $options_html['href'] = "#"; $options_html['onmouseover'] = "this.src='{$imgmouseover}'"; $options_html['onmouseout'] = "this.src='{$img}'"; $options_html['alt'] = "no preview defined?"; return image_tag($img, $options_html); break; case 'worldpress': $options = _parse_attributes($options); $options_html = _parse_attributes($options_html); $trackURI = urlencode(isset($options['trackURI']) ? $options['trackURI'] : ''); $trackURInotencoded = isset($options['trackURI']) ? $options['trackURI'] : ''; $flashplayerid = isset($options['flashplayerid']) ? $options['flashplayerid'] : ''; $customSkin = isset($options['customSkin']) ? $options['customSkin'] : ''; $playerConfig = sfConfig::get('app_mp3player_worldpress'); $img = isset($playerConfig['img']) ? image_path($playerConfig['img']) : 'nopreview.defined'; $imgmouseover = isset($playerConfig['imgmouseover']) ? image_path($playerConfig['imgmouseover']) : 'nopreview.defined'; $img = isset($options['customSkinImage']) ? image_path($options['customSkinImage']) : $img; $imgmouseover = isset($options['customSkinImageMouseover']) ? image_path($options['customSkinImageMouseover']) : $imgmouseover; $options_html['onClick'] = "javascript: if( isiPhone() ) document.getElementById('{$flashplayerid}').innerHTML='<audio controls=\"true\" autoplay=\"true\" width=\"150px\" height=\"24px\"> <source src=\"{$trackURInotencoded}\" type=\"audio/mp3\"> </audio>'; else AudioPlayer.embed('{$flashplayerid}', {soundFile: '{$trackURI}', {$customSkin}}); return false;"; $options_html['href'] = "#"; $options_html['onmouseover'] = "this.src='{$imgmouseover}'"; $options_html['onmouseout'] = "this.src='{$img}'"; $options_html['alt'] = "no preview defined?"; return image_tag($img, $options_html); break; case 'smintplayer': default: return "todo"; break; } }
function g_anchor($uri = '', $title = '', $attributes = '') { $title = (string) $title; if (!is_array($uri)) { $site_url = !preg_match('!^\\w+://! i', $uri) ? base_url() . $uri : $uri; } else { $site_url = base_url() . $uri; } if ($title == '') { $title = $site_url; } if ($attributes != '') { $attributes = _parse_attributes($attributes); } return '<a href="' . $site_url . '">' . $title . '</a>'; }
/** * Return the HTML code for an unordered list showing opinions that can be voted * If the user has already voted, then a message appears * * @param BaseObject $object Propel object instance to vote * @param string $domid unique css identifier for the block (div) containing the voter tool * @param string $message a message string to be displayed in the voting-message block * @param array $options Array of HTML options to apply on the HTML list * @return string **/ function depp_voter($object, $domid = 'depp-voter-block', $message = '', $options = array()) { if (is_null($object)) { sfLogger::getInstance()->debug('A NULL object cannot be voted'); return ''; } $user_id = deppPropelActAsVotableBehaviorToolkit::getUserId(); // anonymous votes if ((is_null($user_id) || $user_id == '') && !$object->allowsAnonymousVoting()) { return __('Anonymous voting is not allowed') . ", " . __('please') . " " . link_to('login', '/login'); } try { $voting_range = $object->getVotingRange(); $options = _parse_attributes($options); if (!isset($options['id'])) { $options = array_merge($options, array('id' => 'voting-items')); } if ($object instanceof sfOutputEscaperObjectDecorator) { $object_class = get_class($object->getRawValue()); } else { $object_class = get_class($object); } $object_id = $object->getReferenceKey(); $token = deppPropelActAsVotableBehaviorToolkit::addTokenToSession($object_class, $object_id); // already voted if ($object->hasBeenVotedByUser($user_id)) { $message .= " " . link_to_remote(__('Take your vote back'), array('url' => sprintf('deppVoting/unvote?domid=%s&token=%s', $domid, $token), 'update' => $domid, 'script' => true, 'complete' => visual_effect('appear', $domid) . visual_effect('highlight', $domid))); } $list_content = ''; for ($i = -1 * $voting_range; $i <= $voting_range; $i++) { if ($i == 0 && !$object->allowsNeutralPosition()) { continue; } $text = sprintf("[%d]", $i); $label = sprintf(__('Vote %d!'), $i); if ($object->hasBeenVotedByUser($user_id) && $object->getUserVoting($user_id) == $i) { $list_content .= content_tag('li', $text); } else { $list_content .= ' <li>' . link_to_remote($text, array('url' => sprintf('deppVoting/vote?domid=%s&token=%s&voting=%d', $domid, $token, $i), 'update' => $domid, 'script' => true, 'complete' => visual_effect('appear', $domid) . visual_effect('highlight', $domid)), array('title' => $label)) . '</li>'; } } $results = get_component('deppVoting', 'votingDetails', array('object' => $object)); return content_tag('ul', $list_content, $options) . content_tag('div', $message, array('id' => 'voting-message')) . content_tag('div', $results, array('id' => 'voting-results')); } catch (Exception $e) { sfLogger::getInstance()->err('Exception catched from sf_rater helper: ' . $e->getMessage()); } }
/** * Return the HTML code for a unordered list showing rating stars * * @param BaseObject $object Propel object instance * @param array $options Array of HTML options to apply on the HTML list * @throws sfPropelActAsRatableException * @return string **/ function sf_rater($object, $options = array()) { if (is_null($object)) { sfLogger::getInstance()->debug('A NULL object cannot be rated'); } if (!isset($options['star-width'])) { $star_width = sfConfig::get('app_rating_star_width', 25); } else { $star_width = $options['star-width']; unset($options['star-width']); } try { $max_rating = $object->getMaxRating(); $actual_rating = $object->getRating(); $bar_width = $actual_rating * $star_width; $options = _parse_attributes($options); if (!isset($options['class'])) { $options = array_merge($options, array('class' => 'star-rating')); } if (!isset($options['style']) or !preg_match('/width:/i', $options['style'])) { $full_bar_width = $max_rating * $star_width; $options = array_merge($options, array('style' => 'width:' . $full_bar_width . 'px')); } if ($object instanceof sfOutputEscaperObjectDecorator) { $object_class = get_class($object->getRawValue()); } else { $object_class = get_class($object); } $object_id = $object->getReferenceKey(); $token = sfPropelActAsRatableBehaviorToolkit::addTokenToSession($object_class, $object_id); $msg_domid = sprintf('rating_message_%s', $token); $bar_domid = sprintf('current_rating_%s', $token); $list_content = ' <li class="current-rating" id="' . $bar_domid . '" style="width:' . $bar_width . 'px;">'; $list_content .= sprintf(__('Currently rated %d star(s) on %d'), $object->getRating(), $max_rating); $list_content .= ' </li>'; for ($i = 1; $i <= $max_rating; $i++) { $label = sprintf(__('Rate it %d stars'), $i); $list_content .= ' <li>' . link_to_remote($label, array('url' => sprintf('sfRating/rate?token=%s&rating=%d&star_width=%d', $token, $i, $star_width), 'update' => $msg_domid, 'script' => true, 'complete' => visual_effect('appear', $msg_domid) . visual_effect('highlight', $msg_domid)), array('class' => 'r' . $i . 'stars', 'title' => $label)) . '</li>'; } return content_tag('ul', $list_content, $options) . content_tag('div', null, array('id' => $msg_domid)); } catch (Exception $e) { sfLogger::getInstance()->err('Exception catched from sf_rater helper: ' . $e->getMessage()); } }
protected function _prepareMenuItem($menuItem) { if ($menuItem instanceof sfSympalMenuItem) { $array = $menuItem->toArray(false); $array['item_route'] = $menuItem->getItemRoute(); $array['requires_auth'] = $menuItem->getRequiresAuth(); $array['requires_no_auth'] = $menuItem->getRequiresNoAuth(); $array['all_permissions'] = $menuItem->getAllPermissions(); $array['level'] = $menuItem->getLevel(); $array['date_published'] = $menuItem->getDatePublished(); $array['html_attributes'] = _parse_attributes($menuItem->getHtmlAttributes()); unset($array['__children']); if (sfSympalConfig::isI18nEnabled('sfSympalMenuItem')) { $array['Translation'] = $menuItem->Translation->toArray(false); } return $array; } return $menuItem; }