elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Los 10 CVE más críticos (peligrosos) de 2020


  Mostrar Mensajes
Páginas: [1]
1  Programación / PHP / de smarty a php. en: 25 Febrero 2014, 22:16 pm
Buenas amigos, quisiera que me ayudaran en una duda que tengo, ya que tengo esta variable en smarty

Código:
{section name=year start=$tsEndY loop=$tsEndY step=-1 max=$tsMax}
                 <option value="{$smarty.section.year.index}">{$smarty.section.year.index}</option>
            {/section}

y quisiera pasarla a puro codigo php, pero no se como se haría esto en php,
yo se que hace con un for, por no se como.

quisiera que por favor me ayudaran.

Esta es la que arroja el php del cache del smarty, como veran es mucho codigo basura, quisiera simplificarlo ya que actualmente estoy haciendo un convertidor de plantillas smarty a solamente php con python.

Código:
 <?php unset($this->_sections['dias']);
$this->_sections['dias']['name'] = 'dias';
$this->_sections['dias']['start'] = (int)1;
$this->_sections['dias']['loop'] = is_array($_loop=32) ? count($_loop) : max(0, (int)$_loop); unset($_loop);
$this->_sections['dias']['show'] = true;
$this->_sections['dias']['max'] = $this->_sections['dias']['loop'];
$this->_sections['dias']['step'] = 1;
if ($this->_sections['dias']['start'] < 0)
    $this->_sections['dias']['start'] = max($this->_sections['dias']['step'] > 0 ? 0 : -1, $this->_sections['dias']['loop'] + $this->_sections['dias']['start']);
else
    $this->_sections['dias']['start'] = min($this->_sections['dias']['start'], $this->_sections['dias']['step'] > 0 ? $this->_sections['dias']['loop'] : $this->_sections['dias']['loop']-1);
if ($this->_sections['dias']['show']) {
    $this->_sections['dias']['total'] = min(ceil(($this->_sections['dias']['step'] > 0 ? $this->_sections['dias']['loop'] - $this->_sections['dias']['start'] : $this->_sections['dias']['start']+1)/abs($this->_sections['dias']['step'])), $this->_sections['dias']['max']);
    if ($this->_sections['dias']['total'] == 0)
        $this->_sections['dias']['show'] = false;
} else
    $this->_sections['dias']['total'] = 0;
if ($this->_sections['dias']['show']):

            for ($this->_sections['dias']['index'] = $this->_sections['dias']['start'], $this->_sections['dias']['iteration'] = 1;
                 $this->_sections['dias']['iteration'] <= $this->_sections['dias']['total'];
                 $this->_sections['dias']['index'] += $this->_sections['dias']['step'], $this->_sections['dias']['iteration']++):
$this->_sections['dias']['rownum'] = $this->_sections['dias']['iteration'];
$this->_sections['dias']['index_prev'] = $this->_sections['dias']['index'] - $this->_sections['dias']['step'];
$this->_sections['dias']['index_next'] = $this->_sections['dias']['index'] + $this->_sections['dias']['step'];
$this->_sections['dias']['first']      = ($this->_sections['dias']['iteration'] == 1);
$this->_sections['dias']['last']       = ($this->_sections['dias']['iteration'] == $this->_sections['dias']['total']);
?>
                <option value="<?php echo $this->_sections['dias']['index']; ?>
"><?php echo $this->_sections['dias']['index']; ?>
</option>
            <?php endfor; endif; ?>

GRACIAS.
2  Programación / Scripting / Ayuda expresiones regulares. en: 11 Febrero 2014, 00:53 am
Hola amigo quisiera que me ayuden con el siguiente codigo.

Código:
    def _var(self, linea):
        regex = '(\\{(\\$(?:[a-z][a-z0-9_]*))\\})'
        rg = re.compile(regex ,re.IGNORECASE | re.DOTALL)
        m = rg.search(linea)
        if m:     
            txt = re.sub(regex ,r'<?php echo \g<2>; ?>', linea)
            print txt
            return txt
        else:
            return linea

El objetivo del siguiente codigo es que busque en una linea de texto que se lo paso como parametro y busque todas las expresiones que coincidan con {$variable}.
y la retorne como <?php echo $variable; ?>
el problema es que no lo hace.
y según tengo el codigo no veo error.

desde ya gracias de antemano.
3  Programación / Scripting / Re: ayuda con python en: 8 Febrero 2014, 20:07 pm
gracias por comentar amigo, intentare a ver.
4  Programación / Scripting / ayuda con python en: 8 Febrero 2014, 10:10 am
Buenas amigos hacker's. ¿como les va? espero bien.

Tengo una pequeña duda, y es que como puedo hacer para leer todas las coincidencias en una linea con expresiones regulares, ya que estoy haciendo
un software en python para pasar las plantillas de smarty a puro php.
y entonces cuando lee una plantilla y busca una coincidencia, agarra solamente la primera, de la linea, y las otras se quedan sin editarse.

necesito mas o menos hacer esto:


de una linea supongamos esta
Código:
 "<div>Usuario: {$usuario}<span> años: {$user.year}</span></div>"

necesito que las reemplace por estas

Código:
"<div>usuario <?php echo $usuario; ?><span><?php echo $user['year']; ?></span> 

claro todo eso con expresiones regulares ya que pueden cambiar pero no consigo como hacerlo


este es mi codigo:

Código
  1. def parse(self, linea):
  2.        txt = self._var(linea)
  3.        txt = self._arrayVar(linea)
  4.        return txt
  5.  
  6.    def _var(self, linea):
  7.        txt = linea
  8.  
  9.        re1='.*?' # Non-greedy match on filler
  10.        re2='(\\{' # Any Single Character 1
  11.        re3='\\$' # Any Single Character 2
  12.        re4='((?:[a-z][a-z0-9_]*))' # Variable Name 1
  13.        re5='\\})' # Any Single Character 3
  14.  
  15.        rg = re.compile(re1+re2+re3+re4+re5,re.IGNORECASE|re.DOTALL)
  16.        m = rg.search(txt)
  17.        if m:
  18.            print m.group(1) + ' -var simple'          
  19.            var = m.group(2)
  20.            txt = re.sub(r'' + re1+re2+re3+re4+re5, r'\1<?php echo \3;?>', txt)
  21.            return txt
  22.        else:
  23.            return linea
  24.  
  25.    def _arrayVar(self, linea):
  26.        txt = linea
  27.  
  28.        re1='.*?' # Non-greedy match on filler
  29.        re2='(\\{' # Any Single Character 1
  30.        re3='\\$' # Any Single Character 2
  31.        re4='((?:[a-z][a-z0-9_]*))' # Variable Name 1
  32.        re5='\\.' # Any Single Character 3
  33.        re6='((?:[a-z][a-z0-9_]*))' # Variable Name 2
  34.        re7='\\})' # Any Single Character 4
  35.  
  36.        rg = re.compile(re1+re2+re3+re4+re5+re6+re7,re.IGNORECASE|re.DOTALL)
  37.  
  38.        m = rg.search(txt)
  39.        if m:
  40.            print m.group(1) + ' -var double'
  41.            var = m.group(2)
  42.            array = m.group(3)
  43.            txt = re.sub(r'' + re1+re2+re3+re4+re5+re6+re7, r'<?php echo ' + var + '[\'' + array + '\']; ?>' , txt)
  44.            return txt
  45.        else:
  46.            return linea

necesito de sus ayudas. En verdad GRACIAS.
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines