public function executeShow(sfWebRequest $request)
 {
     include_once 'Text/Diff.php';
     include_once 'Text/Diff/Renderer/inline.php';
     include_once 'Text/Diff/Renderer/unified.php';
     include_once 'Text/Diff/Engine/string.php';
     $this->previous_commit = $this->file_change->findPrevious();
     $this->inline_diff = null;
     $this->unified_diff = null;
     // get the SCM adapter
     $scm = $this->file_change->getCommit()->getScm();
     $scm_adapter = $scm->getAdapter();
     // get the code of the request version
     try {
         $this->code = !sfConfig::get('app_simulate_scm', false) ? $scm_adapter->getFileContents($this->file_change->getFilePath(), $this->file_change->getCommit()->getRevision()) : file_get_contents(sfConfig::get('sf_data_dir') . '/example_final.diff');
     } catch (Exception $e) {
         $this->getUser()->setFlash('error', 'Unable to retrieve the source code from the SCM server; perhaps it is unavailable?');
         return;
     }
     // if a previous version exists, retrieve the file and diff the result
     if ($this->previous_commit) {
         try {
             $old = !sfConfig::get('app_simulate_scm', false) ? $scm_adapter->getFileContents($this->file_change->getFilePath(), $this->previous_commit->getRevision()) : file_get_contents(sfConfig::get('sf_data_dir') . '/example.diff');
         } catch (Exception $e) {
             $this->getUser()->setFlash('error', 'Unable to retrieve the source code from the SCM server; perhaps it is unavailable?');
             return;
         }
         // prepare diff
         $diff = new Text_Diff('auto', array(explode(PHP_EOL, $old), explode(PHP_EOL, $this->code)));
         $inline_renderer = new Text_Diff_Renderer_Inline();
         $unified_renderer = new Text_Diff_Renderer_Unified();
         $this->code = sfGeshi::parse_single($this->code, 'php');
         // execute and store diff
         $this->inline_diff = $inline_renderer->render($diff);
         // if the diff is empty, no changes can be found (which is unusual)
         if (!$this->inline_diff) {
             $this->inline_diff = $this->code;
         }
         $this->unified_diff = $unified_renderer->render($diff);
     }
 }
 /**
  * Transforms a given block into HTML using Geshi syntax highlighting.
  *
  * @param  $matches
  * @param string $default
  * @return mixed|string
  */
 protected function transformGeshiBlock($matches, $default = '')
 {
     if (preg_match('/^\\[(.+?)\\]\\s*(.+)$/s', $matches[1], $match)) {
         return sfGeshi::parse_single(html_entity_decode($match[2]), $match[1]);
     }
     if ($default) {
         $geshi = new sfGeshi(html_entity_decode($matches[1]), $default);
         $geshi->enable_classes();
         return $geshi->parse_code();
     }
     return "<pre><code>" . $matches[1] . '</pre></code>';
 }
Beispiel #3
0
<div class="tabs">
  <ul>
    <?php 
if ($previous_commit) {
    ?>
    <li><a href="#tabs-1">Summary</a></li>
    <?php 
}
?>
    <li><a href="#tabs-2">Full view</a></li>
  </ul>
  <?php 
if ($previous_commit) {
    ?>
  <div id="tabs-1"><pre><?php 
    echo !is_null($unified_diff) ? sfGeshi::parse_single($sf_data->getRaw('unified_diff'), 'diff') : include_partial('global/error_large', array('message' => 'There was an error while obtaining the difference.'));
    ?>
</pre></div>
  <?php 
}
?>
  <div id="tabs-2">
    <pre><?php 
if ($previous_commit) {
    echo !is_null($inline_diff) ? $sf_data->getRaw('inline_diff') : include_partial('global/error_large', array('message' => 'There was an error while obtaining the difference.'));
} else {
    echo $code;
}
?>
</pre>
  </div>
Beispiel #4
0
 public function executeShow(sfWebRequest $request)
 {
     $this->redirectUnless($request->getParameter('slug'), 'snippet/index');
     $this->snippet = SnippetTable::getBySlug($request->getParameter('slug'));
     $this->code = sfGeshi::parse_single($this->snippet->getSnippet(), $this->snippet->getLinguagem());
 }
 /**
  * Integrate Geshi highlighting into matched blocks
  *
  * @param array $matches
  * @param string $default
  * @return string
  */
 private static function geshiHighlighter($matches, $default = '')
 {
     if (preg_match('/^\\[(.+?)\\]\\s*(.+)$/s', $matches[1], $match)) {
         //$geshi = new sfGeshi(html_entity_decode($match[2]), $match[1]);
         return sfGeshi::parse_single(html_entity_decode($match[2]), $match[1]);
     }
     if (preg_match('/^\\[(.+?)\\]\\s*(.+)$/s', $matches[1], $match)) {
         $geshi = new sfGeshi(html_entity_decode($match[2]), $match[1]);
         return $geshi->parse_single();
     } else {
         if ($default) {
             $geshi = new sfGeshi(html_entity_decode($matches[1]), $default);
             $geshi->enable_classes();
             return $geshi->parse_code();
         } else {
             return "<pre><code>" . $matches[1] . '</pre></code>';
         }
     }
 }
Beispiel #6
0
 /**
  * Demo action. Displays code highlighting example.
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     $this->code_single = sfGeshi::parse_single(implode("", file(__FILE__)), 'php');
     $this->code_mixed = sfGeshi::parse_mixed("Hello, mom, this is <b>PHP</b> language!\n[php]\n<?php\n    echo \"hello GeSHi\";\n?>\n[/]\nWait, mom, the following is <b>C</b> language!\n[cpp]\nclass Symfony {\n  public:\n    Symfony() {\n    }\n};\n[/]\nBye, mom!");
 }
Beispiel #7
0
 /**
  * Internal callback function used within parse_mixed method
  * (@link sfGeshi->parse_mixed()).
  * Calls parse_single method once (and is called by parse_mixed)
  * for each code block.
  *
  * @param Array $matches - Array of matches returned for each code block.
  */
 private static function highlight($matches)
 {
     return sfGeshi::parse_single($matches[3], $matches[2]);
 }