Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file TSourceCode.php

Documentation is available at TSourceCode.php

  1. <?php
  2. namespace Adianti\Widget\Util;
  3.  
  4. use Adianti\Widget\Base\TElement;
  5. use Adianti\Util\AdiantiStringConversion;
  6.  
  7. /**
  8.  * SourceCode View
  9.  *
  10.  * @version    7.4
  11.  * @package    widget
  12.  * @subpackage util
  13.  * @author     Pablo Dall'Oglio
  14.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  15.  * @license    http://www.adianti.com.br/framework-license
  16.  */
  17. {
  18.     private $content;
  19.     private $row_numbers;
  20.     
  21.     /**
  22.      * Load a PHP file
  23.      * @param $file Path to the PHP file
  24.      */
  25.     public function loadFile($file)
  26.     {
  27.         if (!file_exists($file))
  28.         {
  29.             return FALSE;
  30.         }
  31.         
  32.         $this->content AdiantiStringConversion::assureUnicode(file_get_contents($file));
  33.         
  34.         return TRUE;
  35.     }
  36.     
  37.     /**
  38.      * Load from string
  39.      */
  40.     public function loadString($content)
  41.     {
  42.         $this->content AdiantiStringConversion::assureUnicode($content);
  43.     }
  44.     
  45.     /**
  46.      * Generate row numbers
  47.      */
  48.     public function generateRowNumbers()
  49.     {
  50.         $this->row_numbers true;
  51.     }
  52.     
  53.     /**
  54.      * Insert row numbers
  55.      */
  56.     public function insertRowNumbers($highlighted_string)
  57.     {
  58.         $color ini_get('highlight.html');
  59.         $highlighted_string str_replace('<code><span style="color: '.$color.'">''<code><span style="color: #000000"><ol class="linenums"><li>'$highlighted_string);
  60.         $highlighted_string str_replace("</span>\n</code>""</li></ol></span>\n</code>"$highlighted_string);
  61.         $first TRUE;
  62.         $content preg_split ('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/'trim($highlighted_string)-1PREG_SPLIT_DELIM_CAPTURE PREG_SPLIT_NO_EMPTY);
  63.         
  64.         $return '';
  65.         foreach ($content as $line)
  66.         {
  67.             if (substr(trim($line)020== '<span style="color: ')
  68.             {
  69.                 $color substr(trim($line)207);
  70.                 $is_opened TRUE;
  71.             }
  72.             
  73.             if (substr(trim($line)07== '</span>')
  74.             {
  75.                 $is_opened FALSE;
  76.             }
  77.             
  78.             if ($line == '<br />')
  79.             {
  80.                 if ($is_opened)
  81.                 {
  82.                     $return .= '</span>';
  83.                 }
  84.                 $return .=  '</li>';
  85.                 
  86.                 $return .=  '<li>';
  87.                 if ($is_opened)
  88.                 {
  89.                     $return .= '<span style="color: '.$color.'">';
  90.                 }
  91.             }
  92.             else
  93.             {
  94.                 $return .= $line;
  95.             }
  96.         }
  97.         
  98.         return $return;
  99.     }
  100.     
  101.     /**
  102.      * Show the highlighted source code
  103.      */
  104.     public function show()
  105.     {
  106.         $span new TElement('span');
  107.         $span->{'style''font-size:10pt';
  108.         $span->{'class''tsourcecode';
  109.         
  110.         if ($this->row_numbers)
  111.         {
  112.             $span->add($this->insertRowNumbers(highlight_string($this->contentTRUE)));
  113.         }
  114.         else
  115.         {
  116.             $span->add(highlight_string($this->contentTRUE));
  117.         }
  118.         $span->show();
  119.     }
  120. }