Exemplo n.º 1
0
 /**
  * Returns the escaped +html+ without affecting existing escaped entities.
  *
  *  <%= escape_once "1 > 2 &amp; 3" %>
  *    # => "1 &gt; 2 &amp; 3"
  */
 function escape_once($html)
 {
     static $charset;
     if (empty($charset)) {
         $charset = Ak::locale('charset');
     }
     return TagHelper::_fix_double_escape(htmlentities($html, ENT_COMPAT, $charset));
 }
Exemplo n.º 2
0
 function _tag_options($options)
 {
     $formated_options = array();
     foreach (array_diff($options, array('')) as $key => $value) {
         if (!is_numeric($key) && !is_array($value) && !is_object($value)) {
             $formated_options[$key] = $key . '="' . htmlentities($value, ENT_COMPAT, Ak::locale('charset')) . '"';
         }
     }
     ksort($formated_options);
     return empty($formated_options) ? '' : ' ' . join(' ', $formated_options);
 }
Exemplo n.º 3
0
    /**
      * Formats a +number+ into a currency string. The +options+ array can be used to customize the format of the output.
      * The +number+ can contain a level of precision using the +precision+ key; default is 2
      * The currency type can be set using the +unit+ key; default is "$"
      * The unit separator can be set using the +separator+ key; default is "."
      * The delimiter can be set using the +delimiter+ key; default is ","
      * Examples:
      *    $number_helper->number_to_currency(1234567890.50)     => $1,234,567,890.50
      *    $number_helper->number_to_currency(1234567890.506)    => $1,234,567,890.51
      *    $number_helper->number_to_currency(1234567890.50, 
      * 	array('unit' => "&pound;", 'separator' => ",", 'delimiter' => "")) => &pound;1234567890,50
      *    $number_helper->number_to_currency(1234567890.50, 
      * 	array('unit' => " &euro;", 'separator' => ",", 'delimiter' => ".",
      * 			'unit_position' => 'right')) => 1.234.567.890,50 &euro;
      */

    function number_to_currency($number, $options = array())
    {
        $default_options = Ak::locale('currency');

        $options = array_merge($default_options, $options);

        return
        ($options['unit_position'] == 'left' ? $options['unit'] : '').
        number_format($number, $options['precision'],$options['separator'], $options['delimiter']).
        ($options['unit_position'] == 'right' ? $options['unit'] : '');

    }
Exemplo n.º 4
0
 function toString($date_format = '')
 {
     if (!empty($date_format)) {
         $format = $date_format . '_';
     } else {
         $format = '';
     }
     $format = Ak::locale($format . 'date_time_format');
     if (!$format) {
         $format = Ak::locale('date_time_format');
     }
     return date($format, $this->value);
 }
Exemplo n.º 5
0
 /**
  * Converts an ISO date to current locale format
  *
  */
 function locale_date($iso_date)
 {
     $timestamp = Ak::getTimestamp($iso_date);
     $format = Ak::locale('date_format');
     return Ak::getDate($timestamp, $format);
 }
Exemplo n.º 6
0
 function html_escape($html)
 {
     static $charset;
     if (empty($charset)) {
         $charset = Ak::locale('charset');
     }
     return htmlentities($html, ENT_COMPAT, $charset);
 }
Exemplo n.º 7
0
Arquivo: Ak.php Projeto: joeymetal/v1
 function encoding()
 {
     static $encoding;
     if (empty($encoding)) {
         // This will force system language settings
         Ak::t('Akelos');
         $encoding = Ak::locale('charset', Ak::lang());
         $encoding = empty($encoding) ? 'UTF-8' : $encoding;
     }
     return $encoding;
 }
Exemplo n.º 8
0
 public function test_today()
 {
     $Zone = $this->_createTimeZone("Test", 43200);
     $Zone->_timestamp = $this->timestamp;
     $this->assertEqual(Ak::getDate(mktime(0,0,0,7,26,2004), Ak::locale('date_format')), $Zone->today());
 }
Exemplo n.º 9
0
    /**
    * 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_helper->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_helper->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:
    *   $url_helper->mail_to("*****@*****.**", "My email", array('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', htmlentities($name, null, Ak::locale('charset')), 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)));
        }
    }
Exemplo n.º 10
0
 /**
  * Return the current time in this time zone.
  */
 function dateTime()
 {
     return Ak::getDate($this->now(), Ak::locale('date_time_format'));
 }
Exemplo n.º 11
0
 static function html_escape($html, $quote_style = ENT_COMPAT)
 {
     static $charset;
     if (empty($charset)) {
         $charset = Ak::locale('charset');
     }
     return htmlentities($html, $quote_style, $charset);
 }
Exemplo n.º 12
0
    function setOptions($options = array())
    {
        $this->year = empty($options['year']) ? Ak::getDate(null,'Y') : $options['year'];
        $this->month = empty($options['month']) ? Ak::getDate(null,'n') : $options['month'];
        $this->starts_on = CalendarCalculations::getDayOnTheWeek($this->year, $this->month, 1);
        $this->first_day_of_week = !isset($options['first_day_of_week']) ? Ak::locale('first_day_of_week') : $options['first_day_of_week'];
        $this->number_of_days = $this->getNumberOfDaysForMonth();
        $this->ends_on = CalendarCalculations::getDayOnTheWeek($this->year, $this->month, $this->number_of_days);
        $this->last_month_days = $this->starts_on;
        $this->next_month_days = 6-$this->ends_on;
        $this->number_of_weeks = abs(($this->last_month_days+$this->number_of_days+$this->next_month_days)/7);
        $this->is_current_month = Ak::getDate(null, 'n') == $this->month;

        if(!isset($options['load_days']) || $options['load_days']){
            $this->loadDays();
        }
    }
Exemplo n.º 13
0
 function _send($to)
 {
     $headers = $this->_getHeaders($to);
     if (empty($this->Mime)) {
         $body = $this->body;
         $headers['Content-Type'] = 'text/plain; charset=' . Ak::locale('charset') . '; format=flowed';
     } else {
         $body = $this->Mime->get();
         $headers = $this->Mime->headers($headers);
     }
     return $this->Connector->send(array('To' => $to), $headers, $body);
 }