Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - AlejandroPrz

#1
PHP / de smarty a php.
25 Febrero 2014, 22:16 PM
Buenas amigos, quisiera que me ayudaran en una duda que tengo, ya que tengo esta variable en smarty

{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.

<?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'] > : -1$this->_sections['dias']['loop'] + $this->_sections['dias']['start']);
else
    
$this->_sections['dias']['start'] = min($this->_sections['dias']['start'], $this->_sections['dias']['step'] > $this->_sections['dias']['loop'] : $this->_sections['dias']['loop']-1);
if (
$this->_sections['dias']['show']) {
    
$this->_sections['dias']['total'] = min(ceil(($this->_sections['dias']['step'] > $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
Scripting / Ayuda expresiones regulares.
11 Febrero 2014, 00:53 AM
Hola amigo quisiera que me ayuden con el siguiente codigo.


    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
Scripting / Re: ayuda con python
8 Febrero 2014, 20:07 PM
gracias por comentar amigo, intentare a ver.
#4
Scripting / ayuda con python
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
"<div>Usuario: {$usuario}<span> años: {$user.year}</span></div>"

necesito que las reemplace por estas

"<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 (python) [Seleccionar]
def parse(self, linea):
       txt = self._var(linea)
       txt = self._arrayVar(linea)
       return txt

   def _var(self, linea):
       txt = linea

       re1='.*?' # Non-greedy match on filler
       re2='(\\{' # Any Single Character 1
       re3='\\$' # Any Single Character 2
       re4='((?:[a-z][a-z0-9_]*))' # Variable Name 1
       re5='\\})' # Any Single Character 3

       rg = re.compile(re1+re2+re3+re4+re5,re.IGNORECASE|re.DOTALL)
       m = rg.search(txt)
       if m:
           print m.group(1) + ' -var simple'          
           var = m.group(2)
           txt = re.sub(r'' + re1+re2+re3+re4+re5, r'\1<?php echo \3;?>', txt)
           return txt
       else:
           return linea

   def _arrayVar(self, linea):
       txt = linea

       re1='.*?' # Non-greedy match on filler
       re2='(\\{' # Any Single Character 1
       re3='\\$' # Any Single Character 2
       re4='((?:[a-z][a-z0-9_]*))' # Variable Name 1
       re5='\\.' # Any Single Character 3
       re6='((?:[a-z][a-z0-9_]*))' # Variable Name 2
       re7='\\})' # Any Single Character 4

       rg = re.compile(re1+re2+re3+re4+re5+re6+re7,re.IGNORECASE|re.DOTALL)
       
       m = rg.search(txt)
       if m:
           print m.group(1) + ' -var double'
           var = m.group(2)
           array = m.group(3)
           txt = re.sub(r'' + re1+re2+re3+re4+re5+re6+re7, r'<?php echo ' + var + '[\'' + array + '\']; ?>' , txt)
           return txt
       else:
           return linea


necesito de sus ayudas. En verdad GRACIAS.