/** * Creates a <a> link tag for the pager link * * @param string $name * @param string $internal_uri * @param integer $page_no * @param options $options * @return string */ function op_link_to_for_pager($name, $internal_uri, $page_no, $options) { $html_options = _parse_attributes($options); $html_options = _convert_options_to_javascript($html_options); $absolute = false; if (isset($html_options['absolute_url'])) { $absolute = (bool) $html_options['absolute']; unset($html_options['absolute_url']); } $internal_uri = sprintf($internal_uri, $page_no); $html_options['href'] = url_for($internal_uri, $absolute); if (isset($html_options['query_string'])) { if (strpos($html_options['href'], '?') !== false) { $html_options['href'] .= '&' . $html_options['query_string']; } else { $html_options['href'] .= '?' . $html_options['query_string']; } unset($html_options['query_string']); } if (!strlen($name)) { $name = $html_options['href']; } return content_tag('a', $name, $html_options); }
/** * Creates a <a> link tag to the given email (with href="mailto:..."). * If null is passed as a name, the email itself will become the name. * * <b>Options:</b> * - 'encode' - if set to true, the email address appears with various random encoding for each letter. * The mail link still works when encoded, but the address doesn't appear in clear * in the source. Use it to prevent spam (efficiency not guaranteed). * * <b>Examples:</b> * <code> * echo mail_to('*****@*****.**'); * => <a href="mailto:webmaster@example.com">webmaster@example.com</a> * echo mail_to('*****@*****.**', 'send us an email'); * => <a href="mailto:webmaster@example.com">send us an email</a> * echo mail_to('*****@*****.**', 'send us an email', array('encode' => true)); * => <a href=" mailto:webmaster @example.com ">send us an email</a> * </code> * * @param string $email target email * @param string $name name of the link, i.e. string to appear between the <a> tags * @param array $options additional HTML compliant <a> tag parameters * @param array $default_value * @return string XHTML compliant <a href> tag * @see link_to */ function mail_to($email, $name = '', $options = array(), $default_value = array()) { $html_options = _parse_attributes($options); $html_options = _convert_options_to_javascript($html_options); $default_tmp = _parse_attributes($default_value); $default = array(); foreach ($default_tmp as $key => $value) { $default[] = urlencode($key) . '=' . urlencode($value); } $options = count($default) ? '?' . implode('&', $default) : ''; if (isset($html_options['encode']) && $html_options['encode']) { unset($html_options['encode']); $html_options['href'] = _encodeText('mailto:' . $email . $options); if (!$name) { $name = _encodeText($email); } } else { $html_options['href'] = 'mailto:' . $email . $options; if (!$name) { $name = $email; } } return content_tag('a', $name, $html_options); }
/** * Returns an XHTML compliant <input> tag with type="image". * * The submit_image_tag is very similar to the submit_tag, the only difference being that it uses an image * for the submit button instead of the browser-generated default button. The image is defined by the * <i>$source</i> parameter and must be a valid image, either local or remote (URL). By default, this * helper creates a submit tag with a name of <em>commit</em> to avoid conflicts with other parts of the * framework. It is recommended that you do not use the name "submit" for submit tags unless absolutely necessary. * * <b>Examples:</b> * <code> * // Assuming your image is in the /web/images/ directory * echo submit_image_tag('my_submit_button.gif'); * </code> * * <code> * echo submit_image_tag('http://mydomain.com/my_submit_button.gif'); * </code> * * @param string path to image file * @param array additional HTML compliant <input> tag parameters * @return string XHTML compliant <input> tag with type="image" */ function submit_image_tag($source, $options = array()) { 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)); } return tag('input', array_merge(array('type' => 'image', 'name' => 'commit', 'src' => image_path($source)), _convert_options_to_javascript(_convert_options($options)))); }
/** * Returns an XHTML compliant <input> tag with type="submit". * * By default, this helper creates a submit tag with a name of <em>commit</em> to avoid * conflicts with other parts of the framework. It is recommended that you do not use the name * "submit" for submit tags unless absolutely necessary. Also, the default <i>$value</i> parameter * (title of the button) is set to "Save changes", which can be easily overwritten by passing a * <i>$value</i> parameter. * * <b>Examples:</b> * <code> * echo submit_tag(); * </code> * * <code> * echo submit_tag('Update Record'); * </code> * * @param string $name field value (title of submit button) * @param array $options additional HTML compliant <input> tag parameters * * @return string XHTML compliant <input> tag with type="submit" */ function submit_tag($value = 'Save changes', $options = array()) { return tag('input', array_merge(array('type' => 'submit', 'name' => 'commit', 'value' => $value), _convert_options_to_javascript(_convert_options($options)))); }
/** * Converts specific <i>$options</i> to their correct HTML format * * @param array options * @return array returns properly formatted options */ function _convert_options($options) { $options = _parse_attributes($options); foreach (array('disabled', 'readonly', 'multiple') as $attribute) { $options = _boolean_attribute($options, $attribute); } // Parse any javascript options $options = _convert_options_to_javascript($options); return $options; }
/** * convert a link into an absolute link, to be used inside the emails * * @param string $name * @param string $internal_uri * @param string $options * @return string * @author Guglielmo Celata */ function link_to_in_mail($name = '', $internal_uri = '', $options = array()) { $html_options = _parse_attributes($options); $html_options = _convert_options_to_javascript($html_options); $site_url = sfConfig::get('sf_site_url', 'op_openparlamento.openpolis.it'); if (isset($html_options['site_url'])) { $site_url = $html_options['site_url']; } $url = url_for($internal_uri, true); $url_in_mail = preg_replace('/.*\\/symfony\\/(.*)/i', 'http://' . $site_url . '/$1', $url); return "<a href=\"{$url_in_mail}\">{$name}</a>"; }
/** * Creates an <input> button tag of the given name pointing to a routed URL * based on the module/action passed as argument and the routing configuration. * The syntax is similar to the one of link_to. * * <b>Options:</b> * - '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 * - 'confirm' - displays a javascript confirmation alert when the button is clicked * - 'popup' - if set to true, the button opens a new browser window * - 'post' - if set to true, the button submits a POST request instead of GET (caution: do not use inside a form) * * <b>Examples:</b> * <code> * echo button_to('Delete this page', 'my_module/my_action'); * => <input value="Delete this page" type="button" onclick="document.location.href='/path/to/my/action';" /> * </code> * * @param string $name name of the button * @param string $internal_uri 'module/action' or '@rule' of the action * @param array $options additional HTML compliant <input> tag parameters * @return string XHTML compliant <input> tag * @see url_for, link_to */ function bs_button_to($name, $icon, $internal_uri, $options = array()) { $html_options = _parse_attributes($options); $content = bs_icon($icon).$name; if (!isset($html_options['class'])) $html_options['class'] = ''; $html_options['class'] .= ' btn'; if (isset($html_options['post']) && $html_options['post']) { if (isset($html_options['popup'])) { throw new sfConfigurationException('You can\'t use "popup" and "post" together.'); } $html_options['type'] = 'submit'; unset($html_options['post']); $html_options = _convert_options_to_javascript($html_options); return form_tag($internal_uri, array('method' => 'post', 'class' => 'button_to')).content_tag('div', tag('input', $html_options)).'</form>'; } $url = url_for($internal_uri); if (isset($html_options['query_string'])) { $url = $url.'?'.$html_options['query_string']; unset($html_options['query_string']); } if (isset($html_options['anchor'])) { $url = $url.'#'.$html_options['anchor']; unset($html_options['anchor']); } $url = "'".$url."'"; $html_options['type'] = 'button'; if (isset($html_options['popup'])) { $html_options = _convert_options_to_javascript($html_options, $url); unset($html_options['popup']); } else { $html_options['onclick'] = "document.location.href=".$url.";"; $html_options = _convert_options_to_javascript($html_options); } return content_tag('button', $content, $html_options); }
function c2c_submit_tag($value = 'Submit', $options = array()) { return c2c_button($value, array_merge(array('type' => 'submit', 'name' => 'commit'), _convert_options_to_javascript(_convert_options($options)))); }