示例#1
0
 /**
  * Uses AkTextHelper::format to take the text and format it, indented two spaces for
  * each line, and wrapped at 72 columns.
  */
 public function block_format($text)
 {
     $formatted = '';
     $paragraphs = preg_split("/(\n|\r){2,}/", $text);
     foreach ((array) $paragraphs as $paragraph) {
         $formatted .= AkTextHelper::format($paragraph, array('columns' => 72, 'first_indent' => 2, 'body_indent' => 2));
     }
     // Make list points stand on their own line
     return preg_replace("/[ ]*([*]+) ([^*]*)/", " \$1 \$2\n", preg_replace("/[ ]*([#]+) ([^#]*)/", " \$1 \$2\n", $formatted));
 }
示例#2
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;
 }
示例#3
0
 public function highlightErrors($xhtml)
 {
     $highlighted_xhtml = array();
     if (!empty($this->_linesToHighlight)) {
         $xhtml_arr = preg_split('/\\n|\\r/', $xhtml);
         foreach ($xhtml_arr as $k => $xhtml_line) {
             $pos = $k + $this->_startLine;
             $highlighted_xhtml[$k] = $pos . "&nbsp;&nbsp;&nbsp;&nbsp;";
             $xhtml_line = htmlentities($xhtml_line);
             if (isset($this->_linesToHighlight[$pos])) {
                 foreach ($this->_linesToHighlight[$pos] as $highlight_details) {
                     $highlighted_xhtml[$k] .= AkTextHelper::highlight($xhtml_line, $highlight_details['phrase'], '<strong style="border:2px solid #' . $highlight_details['color'] . ';padding:1px; margin:1px; background: #ffc;">\\1</strong>');
                 }
             } else {
                 $highlighted_xhtml[$k] .= $xhtml_line;
             }
             $highlighted_xhtml[$k] .= "<br />\n";
         }
     }
     return empty($highlighted_xhtml) ? $xhtml : join($highlighted_xhtml);
 }
 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.'));
         }
     }
 }
示例#5
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;
    }
示例#6
0
文件: parser.php 项目: bermi/akelos
 public function extractImagesIntoInlineParts(&$Mail, $options = array())
 {
     $html =& $Mail->body;
     $images = AkTextHelper::get_image_urls_from_html($html);
     $html_images = array();
     if (!empty($images)) {
         $tmp_dir = AkConfig::getDir('tmp');
         $app_dir = AkConfig::getDir('app');
         $images = array_diff(array_unique($images), array(''));
         foreach ($images as $image) {
             $original_image_name = $image;
             if (substr($image, 0, 4) == 'cid:') {
                 continue;
             }
             $image = $this->_getImagePath($image);
             if (!empty($image)) {
                 $extenssion = substr($image, strrpos('.' . $image, '.'));
                 $image_name = Ak::uuid() . '.' . $extenssion;
                 $html_images[$original_image_name] = 'cid:' . $image_name;
                 $Mail->setAttachment('image/' . $extenssion, array('body' => AkFileSystem::file_get_contents($image, array('base_path' => strstr($image, $app_dir) ? null : $tmp_dir)), 'filename' => $image_name, 'content_disposition' => 'inline', 'content_id' => '<' . $image_name . '>'));
             }
         }
         $modified_html = str_replace(array_keys($html_images), array_values($html_images), $html);
         if ($modified_html != $html) {
             $html = $modified_html;
             $Mail->moveBodyToInlinePart();
         }
     }
 }
示例#7
0
 public function convert()
 {
     return $this->source = preg_replace("/([ \n\t]+)/", ' ', AkTextHelper::markdown($this->source));
 }
示例#8
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)));
     }
 }
示例#9
0
 static function h($html, $quote_style = ENT_COMPAT)
 {
     return AkTextHelper::html_escape($html, $quote_style);
 }
示例#10
0
文件: logger.php 项目: bermi/akelos
 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);
             }
         }
     }
 }
示例#11
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";
 }
示例#12
0
 private function _highlightNotes($textile)
 {
     if (preg_match_all('/(IMPORTANT|CAUTION|WARNING|NOTE|INFO|TIP)(?:\\.|\\:)(.*)/', $textile, $matches)) {
         foreach ($matches[1] as $k => $class) {
             $css_class = strtolower($class);
             $css_class = in_array($css_class, array('caution', 'important')) ? 'warning' : $css_class;
             $css_class = in_array($css_class, array('tip')) ? 'info' : $css_class;
             $note_caption = $this->t(ucfirst($css_class));
             $pin_note = "<notextile><p class='{$css_class}-box highlighted-box'> <img height='52' width='27' class='no-print' alt='' src='" . $this->_controller->url_helper->url_for(array('action' => 'images', 'id' => "{$css_class}-pin", 'format' => 'gif', 'controller' => 'virtual_assets')) . "'><strong class='only-print'>{$note_caption}: </strong>" . AkTextHelper::textilize_without_paragraph($this->_replacePlusPlus($matches[2][$k])) . "</p></notextile>";
             // $simple_note = "<notextile><div class='$css_class'><p>".strip_tags($matches[2][$k]).'</p></div></notextile>';
             $textile = str_replace($matches[0][$k], $pin_note, $textile);
         }
     }
     return $textile;
 }
示例#13
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));
 }
示例#14
0
    $Logger->message('Invalid test name');
    echo "Invalid test name\n";
    return false;
}
$valid_options = array('config', 'base_path', 'namespace', 'TestSuite', 'reporter' => 'TextReporter', 'files');
$controllers = array();
foreach ($options as $k => $v) {
    if (!in_array($k, $valid_options)) {
        if (!is_bool($v)) {
            $v = rtrim($v, DS);
            $options['files'][] = $options['base_path'] . DS . $v . '_controller_test.php';
            unset($options[$k]);
        }
    }
}
if (empty($options['files'])) {
    $controller_files = glob($options['base_path'] . DS . '*_controller_test.php');
    foreach ($controller_files as $k => $controller) {
        if (is_file($controller)) {
            $options['files'][] = $controller;
        }
    }
}
if (empty($options['description']) && !empty($options['files'])) {
    $description = array();
    foreach ($options['files'] as $file) {
        $description[] = trim(str_replace(array($options['base_path'], DS, '_controller_test.php'), '', $file), DS);
    }
    $options['description'] = AkTextHelper::pluralize(count($description), 'Fixture for controller ', 'Fixtures for controllers ') . '(' . join(', ', $description) . ')';
}
AkUnitTestSuite::runFunctionalFromOptions($options);
 /**
  * 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)));
 }
示例#16
0
 public function convert()
 {
     require_once AK_ACTION_PACK_DIR . DS . 'helpers' . DS . 'text_helper.php';
     return AkTextHelper::textilize($this->source);
 }