/** * Creates a link tag for starting an email to the specified <tt>email_address</tt>, which is also used as the name of the * link unless +name+ is specified. Additional HTML options, such as class or id, can be passed in the * <tt>html_options</tt> array. * * You can also make it difficult for spiders to harvest email address by obfuscating them. * Examples: * $url->mail_to('*****@*****.**', 'My email', array('encode' => 'javascript')) => * <script type="text/javascript" language="javascript">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script> * * $url->mail_to('*****@*****.**', 'My email', array('encode' => 'hex')) => * <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a> * * You can also specify the cc address, bcc address, subject, and body parts of the message header to create a complex e-mail * using the corresponding +cc+, +bcc+, +subject+, and +body+ <tt>html_options</tt> keys. Each of these options are URI escaped * and then appended to the <tt>email_address</tt> before being output. <b>Be aware that javascript keywords will not be * escaped and may break this feature when encoding with javascript.</b> * * Examples: * mail_to "*****@*****.**", "My email", :cc => "*****@*****.**", :bcc => "*****@*****.**", :subject => "This is an example email", :body => "This is the body of the message." # => * <a href="mailto:me@domain.com?cc="*****@*****.**"&bcc="*****@*****.**"&body="This%20is%20the%20body%20of%20the%20message."&subject="This%20is%20an%20example%20email">My email</a> */ function mail_to($email_address, $name = null, $html_options = array()) { $name = empty($name) ? $email_address : $name; $default_options = array('cc' => null, 'bcc' => null, 'subject' => null, 'body' => null, 'encode' => ''); $options = array_merge($default_options, $html_options); $encode = $options['encode']; $string = ''; $extras = ''; $extras .= !empty($options['cc']) ? "cc=" . urlencode(trim($options['cc'])) . '&' : ''; $extras .= !empty($options['bcc']) ? "bcc=" . urlencode(trim($options['bcc'])) . '&' : ''; $extras .= !empty($options['body']) ? "body=" . urlencode(trim($options['body'])) . '&' : ''; $extras .= !empty($options['subject']) ? "subject=" . urlencode(trim($options['subject'])) . '&' : ''; $extras = empty($extras) ? '' : '?' . str_replace('+', '%20', rtrim($extras, '&')); $html_options = Ak::delete($html_options, 'cc', 'bcc', 'subject', 'body', 'encode'); if ($encode == 'javascript') { $tmp = "document.write('" . TagHelper::content_tag('a', $name, array_merge($html_options, array('href' => 'mailto:' . $email_address . $extras))) . "');"; for ($i = 0; $i < strlen($tmp); $i++) { $string .= '%' . dechex(ord($tmp[$i])); } return "<script type=\"text/javascript\">eval(unescape('{$string}'))</script>"; } elseif ($encode == 'hex') { $encoded_email_address = ''; $encoded_email_for_name = ''; for ($i = 0; $i < strlen($email_address); $i++) { if (preg_match('/\\w/', $email_address[$i])) { $encoded_email_address .= sprintf('%%%x', ord($email_address[$i])); } else { if ($email_address[$i] == '@') { $encoded_email_address .= '%40'; } elseif ($email_address[$i] == '.') { $encoded_email_address .= '%2e'; } else { $encoded_email_address .= $email_address[$i]; } } $encoded_email_for_name .= rand(1, 2) % 2 ? '&#' . ord($email_address[$i]) . ';' : '&#x' . dechex(ord($email_address[$i])) . ';'; } $name = str_replace($email_address, $encoded_email_for_name, $name); return TagHelper::content_tag('a', $name, array_merge($html_options, array('href' => 'mailto:' . $encoded_email_address . $extras))); } else { return TagHelper::content_tag('a', $name, array_merge($html_options, array('href' => 'mailto:' . $email_address . $extras))); } }
/** * Creates named routes for implementing verb-oriented controllers for a * singleton resource. A singleton resource is global to its current context. * For unnested singleton resources, the resource is global to the current user * visiting the application, such as a user's <tt>/account</tt> profile. * For nested singleton resources, the resource is global to its parent resource, * such as a <tt>projects</tt> resource that <tt>has_one 'project_manager'</tt>. * The <tt>project_manager</tt> should be mapped as a singleton resource * under <tt>projects</tt>: * * $Project = $Map->resources('projects'); * $Project->resource('project_manager'); * * See +resources+ for general conventions. These are the main differences: * * * A singular name is given to <tt>$Map->resource</tt>. The default controller * name is still taken from the plural name. * * To specify a custom plural name, use the <tt>'plural'</tt> option. There is * no <tt>'singular'</tt> option. * * No default index route is created for the singleton resource controller. * * When nesting singleton resources, only the singular name is used as the path * prefix (example: 'account/messages/1') * * For example: * * $Map->resource('account'); * * maps these actions in the Accounts controller: * * class AccountsController extends ActionController{ * // GET add_account_url * public function add() { * // return an HTML form for describing the new account * } * * // POST account_url * public function create() { * // create an account * } * * // GET account_url * public function show() { * // find and return the account * } * * // GET edit_account_url * public function edit() { * // return an HTML form for editing the account * } * * // PUT account_url * public function update() { * // find and update the account * } * * // DELETE account_url * public function destroy() { * // delete the account * } * } * * Along with the routes themselves, +resource+ generates named routes for * use in controllers and views. <tt>$Map->resource('account')</tt> produces * these named routes and helpers: * * Named Route Helpers * ============ ============================================= * account account_url, array_for_account_url, * account_path, array_for_account_path * * add_account add_account_url, array_for_add_account_url, * add_account_path, array_for_add_account_path * * edit_account edit_account_url, array_for_edit_account_url, * edit_account_path, array_for_edit_account_path */ public function resource($entities, $options = array()) { $entities = Ak::toArray($entities); if (!empty($this->Router->options)) { $options = array_merge(Ak::delete($this->Router->options, array('has_one')), $options); } foreach ($entities as $entity) { $Map = $this->mapSingletonResource($entity, $options); } return $Map; }
/** * Return select and option tags for the given object and column_name, using * #time_zone_options_for_select to generate the list of option tags. * * In addition to the <tt>include_blank</tt> option documented above, * this method also supports a <tt>model</tt> option, which defaults * to TimeZone. This may be used by users to specify a different time * zone model object. (See #time_zone_options_for_select for more * information.) */ function time_zone_select($object_name, $column_name, $priority_zones = array(), $options = array(), $html_options = array()) { $InstanceTag = new AkFormHelperOptionsInstanceTag($object_name, $column_name, $this, null, $this->_object[$object_name]); return $InstanceTag->to_time_zone_select_tag($priority_zones, Ak::delete($options, 'object'), $html_options); }
/** * Given a path and options, returns a rewritten URL string */ function _rewriteUrl($path, $options) { $rewritten_url = ''; if (empty($options['only_path'])) { $rewritten_url .= !empty($options['protocol']) ? $options['protocol'] : $this->Request->getProtocol(); $rewritten_url .= empty($rewritten_url) || strpos($rewritten_url, '://') ? '' : '://'; $rewritten_url .= $this->_rewriteAuthentication($options); $rewritten_url .= !empty($options['host']) ? $options['host'] : $this->Request->getHostWithPort(); $options = Ak::delete($options, array('user', 'password', 'host', 'protocol')); } $rewritten_url .= empty($options['skip_relative_url_root']) ? $this->Request->getRelativeUrlRoot() : ''; if (empty($options['skip_url_locale'])) { $locale = $this->Request->getLocaleFromUrl(); if (empty($options['lang'])) { $rewritten_url .= (empty($locale) ? '' : '/') . $locale; } } $rewritten_url .= substr($rewritten_url, -1) == '/' ? '' : (AK_URL_REWRITE_ENABLED ? '' : (!empty($path[0]) && $path[0] != '/' ? '/' : '')); $rewritten_url .= $path; $rewritten_url .= empty($options['trailing_slash']) ? '' : '/'; $rewritten_url .= empty($options['anchor']) ? '' : '#' . $options['anchor']; return $rewritten_url; }
function to_select_tag($choices, $options=array(), $html_options = array()) { $this->add_default_name_and_id($html_options); $selected_value = !empty($options['selected']) ? $options['selected'] : $this->getValue(); if (empty($selected_value) && isset($options['default'])){ $selected_value = $options['default']; } unset($options['selected']); return TagHelper::content_tag('select', $this->_addOptions($this->_template_object->options_for_select($choices, $selected_value, $options), $html_options, $this->getValue()), Ak::delete($html_options,'prompt','include_blank')); }
protected function _logRequestParams($log_params) { if (!empty($this->filter_parameter_logging)) { array_walk_recursive($log_params, array($this, '_filterRequestParamsForLogging')); } $this->_log('Parameters', array_diff(Ak::delete($log_params, $this->skip_parameter_logging), array(''))); }
private function fillInLastParameters(&$params) { $actual_parameters = $this->getParametersFromActualRequest($params); $actual_parameters = Ak::delete($actual_parameters, array('action', 'id')); if (!empty($actual_parameters)) { $this->handleLocale($params, $actual_parameters); $old_params = array(); foreach ($actual_parameters as $k => $v) { if (array_key_exists($k, $params)) { if (is_null($params[$k])) { unset($params[$k]); } break; } $old_params[$k] = $v; } $params = array_filter(array_merge($old_params, $params), array($this, '_isNull')); } }