Example #1
0
 private function _setCodeBlocks($textile)
 {
     if (preg_match_all('/<(yaml|shell|php|tpl|html|sql|plain)>(.*?)<\\/\\1>/ms', $textile, $matches)) {
         foreach ($matches[1] as $k => $class) {
             $css_class = strtolower($class);
             $css_class = in_array($css_class, array('shell')) ? 'html' : $css_class;
             $escaped = AkTextHelper::html_escape($matches[2][$k]);
             $textile = str_replace($matches[0][$k], $this->_tabText("<notextile><div class='code_container'><code class='{$css_class}'>{$escaped}</code></div></notextile>"), $textile);
         }
     }
     return $textile;
 }
 public function web_terminal()
 {
     $this->user = trim(AK_WIN ? `ECHO %USERNAME%` : `whoami`);
     if (defined('AK_ENABLE_TERMINAL_ON_DEV') && AK_ENABLE_TERMINAL_ON_DEV) {
         $this->enabled = true;
         $cwd = empty($_SESSION['last_working_directory']) ? AK_BASE_DIR : $_SESSION['last_working_directory'];
         if (!empty($this->params['cmd'])) {
             $result = `cd {$cwd};{$this->params['cmd']};echo "----akelos-cmd----";pwd;`;
             list($response, $last_dir) = explode('----akelos-cmd----', $result);
             $_SESSION['last_working_directory'] = trim($last_dir);
             if ($response) {
                 $this->renderText(AkTextHelper::html_escape($response));
             } else {
                 $this->renderText(AkTextHelper::html_escape($this->t('Error or empty response while running: %command', array('%command' => $this->params['cmd']))));
             }
         }
     } else {
         if (!empty($this->params['cmd'])) {
             $this->renderText($this->t('Terminal disabled.'));
         }
     }
 }
Example #3
0
    public function format_snippet($code = '', $snippet_type = '')
    {
        if ($this->_capturing_snippet) {
            $snippet_type = $this->_capturing_snippet;
            $code = $this->_controller->ak_capture_helper->end(false);
            $this->_capturing_snippet = false;
        }
        $code = trim($code);
        $lines = explode("\n", $code . "\n");
        array_pop($lines);
        $snippet_type_set = !empty($snippet_type);
        $snippet_type = empty($snippet_type) ? 'php' : $snippet_type;
        $snippet_type_uc = strtoupper($snippet_type);
        $snippet_lines = '';
        $total = count($lines);
        $line_numbers = join("<br />", range(1, $total));
        $code = str_replace(array("\n"), array('<br />'), AkTextHelper::html_escape($code));
        $copy_button_version = in_array($snippet_type, array('shell')) ? '-2' : '';
        $snippet_corner_image = $this->_controller->ak_url_helper->url_for(array('action' => "images", 'controller' => 'virtual_assets', 'module' => 'akelos_panel', 'id' => "{$snippet_type}-box-corner", 'format' => "gif"));
        $snippet_type_description = !$snippet_type_set ? '' : "<div class=\"code-snippet-title no-print\"><span class=\"snippet-title-{$snippet_type}\">{$snippet_type_uc}</span></div>";
        $snippet_template = <<<SNIPPET
      {$snippet_type_description}
      <div class="code-snippet-holder">
        <table class="snippet" width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td align="left" valign="top"><pre class="line-numbers"><code class='no-print'>{$line_numbers}</code></pre></td>
            <td class="snippet-separator code-snippet-{$snippet_type}-separator">&nbsp;</td>
            <td align="left" valign="top" class="code-snippet-{$snippet_type} snippet-cell"><div class="code_container"><pre><code class="{$snippet_type}">{$code}</pre></code></div>
            <img src="{$snippet_corner_image}" width="30" height="35" alt="" class="no-print snippet-corner" />
            </td>
          </tr>
        </table>
      </div>
SNIPPET;
        return $snippet_template;
    }
Example #4
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>
  */
 public 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') {
         $html = AkTagHelper::content_tag('a', AkTextHelper::html_escape($name, null), array_merge($html_options, array('href' => 'mailto:' . $email_address . $extras)));
         $html = AkJavascriptHelper::escape_javascript($html);
         $tmp = "document.write('{$html}');";
         $len = strlen($tmp);
         for ($i = 0; $i < $len; $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 = '';
         $length = strlen($email_address);
         for ($i = 0; $i < $length; $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 AkTagHelper::content_tag('a', $name, array_merge($html_options, array('href' => 'mailto:' . $encoded_email_address . $extras)));
     } else {
         return AkTagHelper::content_tag('a', $name, array_merge($html_options, array('href' => 'mailto:' . $email_address . $extras)));
     }
 }
Example #5
0
 static function h($html, $quote_style = ENT_COMPAT)
 {
     return AkTextHelper::html_escape($html, $quote_style);
 }
Example #6
0
 public function handleDisplayMessage($error_level, $message, $parameters = array())
 {
     if (AkConfig::getOption('logger.display_message', true)) {
         if (!empty($this->options['print'])) {
             list($file, $line, $method) = AkDebug::getLastFileAndLineAndMethod(false, 3);
             AkDebug::trace("<strong>[{$error_level}]</strong> - " . AkTextHelper::html_escape($message), $line, $file, $method, false);
             if (!empty($parameters)) {
                 AkDebug::trace($parameters, $line, $file, $method);
             }
         }
     }
 }
Example #7
0
 public function _renderTag($name_space, $tagName, $content = null, $attributes = array(), $open = '<', $close = '>', $closeTag = '/>')
 {
     $attribute_array = array();
     if (is_array($attributes) && count($attributes) > 0) {
         foreach ($attributes as $name => $value) {
             if (is_string($value)) {
                 $attribute_array[] = $name . '="' . AkTextHelper::html_escape($value) . '"';
             } else {
                 if (is_array($value)) {
                     $attr_name_space = $name;
                     foreach ($value as $name => $v) {
                         $attribute_array[] = $attr_name_space . ':' . $name . '="' . AkTextHelper::html_escape($v) . '"';
                     }
                 }
             }
         }
         $attribute_string = ' ' . implode(' ', $attribute_array);
     }
     return $open . ($name_space != false ? $name_space . ':' : '') . $tagName . (count($attribute_array) > 0 ? $attribute_string : '') . ($content != null ? $close . $content . $open . '/' . ($name_space != false ? $name_space . ':' : '') . $tagName . $close : $closeTag) . "\n";
 }
Example #8
0
 /**
  * Returns the escaped +html+ without affecting existing escaped entities.
  *
  *  <%= escape_once "1 > 2 &amp; 3" %>
  *    # => "1 &gt; 2 &amp; 3"
  */
 static function escape_once($html)
 {
     return AkTagHelper::fix_double_escape(AkTextHelper::html_escape($html));
 }
 /**
  * Use this method in your view to generate a return for the AJAX autocomplete requests.
  *
  * Example action:
  *
  *   function auto_complete_for_item_title()
  *   {
  *     $this->items = $Item->find('all', array('conditions' => array('strtolower($description).' LIKE ?', '%' . strtolower($this->_controller->Request->getRawPostData(). '%' ))))
  *     return $this->_controller->render(array('inline'=> '<?= $javascript_macros->auto_complete_result(@$items, 'description') ?>'));
  *   }
  *
  * The auto_complete_result can of course also be called from a view belonging to the 
  * auto_complete action if you need to decorate it further.
  *
  * @deprecated 
  */
 public function auto_complete_result($entries, $field, $phrase = null)
 {
     if (empty($entries)) {
         return '';
     }
     foreach ($entries as $entry) {
         $items[] = AkTagHelper::content_tag('li', !empty($phrase) ? AkTextHelper::highlight(AkTextHelper::html_escape($entry[$field]), $phrase) : AkTextHelper::html_escape(@$entry[$field]));
     }
     return AkTagHelper::content_tag('ul', join('', array_unique($items)));
 }