Dotclear


Ignore:
Timestamp:
12/10/13 12:26:54 (12 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Parents:
2608:3365c9df16a6 (diff), 2594:e10cf5fd3749 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge 2.6.2 commits into default branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/public/class.dc.template.php

    r2590 r2610  
    235235     } 
    236236 
    237      protected function compileFile($file) 
    238      { 
    239           $fc = file_get_contents($file); 
    240  
    241           $this->compile_stack[] = $file; 
    242  
    243           # Remove every PHP tags 
    244           if ($this->remove_php) 
    245           { 
    246                $fc = preg_replace('/<\?(?=php|=|\s).*?\?>/ms','',$fc); 
    247           } 
    248  
    249           # Transform what could be considered as PHP short tags 
    250           $fc = preg_replace('/(<\?(?!php|=|\s))(.*?)(\?>)/ms', 
    251           '<?php echo "$1"; ?>$2<?php echo "$3"; ?>',$fc); 
    252  
    253           # Remove template comments <!-- #... --> 
    254           $fc = preg_replace('/(^\s*)?<!-- #(.*?)-->/ms','',$fc); 
    255  
    256           # Lexer part : split file into small pieces 
    257           # each array entry will be either a tag or plain text 
    258           $blocks = preg_split( 
    259                '#(<tpl:\w+[^>]*>)|(</tpl:\w+>)|({{tpl:\w+[^}]*}})#msu',$fc,-1, 
    260                PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); 
    261  
    262           # Next : build semantic tree from tokens. 
    263           $rootNode = new tplNode(); 
    264           $node = $rootNode; 
    265           $errors = array(); 
    266           foreach ($blocks as $id => $block) { 
    267                $isblock = preg_match('#<tpl:(\w+)(?:(\s+.*?)>|>)|</tpl:(\w+)>|{{tpl:(\w+)(\s(.*?))?}}#ms',$block,$match); 
    268                if ($isblock == 1) { 
    269                     if (substr($match[0],1,1) == '/') { 
    270                          // Closing tag, check if it matches current opened node 
    271                          $tag = $match[3]; 
    272                          if (($node instanceof tplNodeBlock) && $node->getTag() == $tag) { 
    273                               $node->setClosing(); 
    274                               $node = $node->getParent(); 
    275                          } else { 
    276                               // Closing tag does not match opening tag 
    277                               // Search if it closes a parent tag 
    278                               $search = $node; 
    279                               while($search->getTag() != 'ROOT' && $search->getTag() != $tag) { 
    280                                    $search = $search->getParent(); 
    281                               } 
    282                               if ($search->getTag() == $tag) { 
    283                                    $errors[] = sprintf( 
    284                                         __('Did not find closing tag for block <tpl:%s>. Content has been ignored.'), 
    285                                         html::escapeHTML($node->getTag())); 
    286                                    $search->setClosing(); 
    287                                    $node = $search->getParent(); 
    288                               } else { 
    289                                    $errors[]=sprintf( 
    290                                         __('Unexpected closing tag </tpl:%s> found.'), 
    291                                         $tag);; 
    292                               } 
    293                          } 
    294                     } elseif (substr($match[0],0,1) == '{') { 
    295                          // Value tag 
    296                          $tag = $match[4]; 
    297                          $str_attr = ''; 
    298                          $attr = array(); 
    299                          if (isset($match[6])) { 
    300                               $str_attr = $match[6]; 
    301                               $attr = $this->getAttrs($match[6]); 
    302                          } 
    303                          $node->addChild(new tplNodeValue($tag,$attr,$str_attr)); 
    304                     } else { 
    305                          // Opening tag, create new node and dive into it 
    306                          $tag = $match[1]; 
    307                          $newnode = new tplNodeBlock($tag,isset($match[2])?$this->getAttrs($match[2]):array()); 
    308                          $node->addChild($newnode); 
    309                          $node = $newnode; 
    310                     } 
    311                } else { 
    312                     // Simple text 
    313                     $node->addChild(new tplNodeText($block)); 
    314                } 
    315           } 
    316  
    317           if (($node instanceof tplNodeBlock) && !$node->isClosed()) { 
    318                $errors[] = sprintf( 
    319                     __('Did not find closing tag for block <tpl:%s>. Content has been ignored.'), 
    320                     html::escapeHTML($node->getTag())); 
    321           } 
    322  
    323           $err = ""; 
    324           if (count($errors) > 0) { 
    325                $err = "\n\n<!-- \n". 
    326                     __('WARNING: the following errors have been found while parsing template file :'). 
    327                     "\n * ". 
    328                     join("\n * ",$errors). 
    329                     "\n -->\n"; 
    330           } 
    331  
    332           return $rootNode->compile($this).$err; 
    333      } 
    334  
    335237     public function compileBlockNode($tag,$attr,$content) 
    336238     { 
     
    343245          $this->core->callBehavior('templateInsideBlock',$this->core,$this->current_tag,$attr,array(&$content)); 
    344246 
    345           if (isset($this->blocks[$this->current_tag])) { 
    346                $res .= call_user_func($this->blocks[$this->current_tag],$attr,$content); 
    347           } elseif ($this->unknown_block_handler != null) { 
    348                $res .= call_user_func($this->unknown_block_handler,$this->current_tag,$attr,$content); 
    349           } 
     247          $res .= parent::compileBlockNode($this->current_tag,$attr,$content); 
    350248 
    351249          # --BEHAVIOR-- templateAfterBlock 
     
    363261          $res = $this->core->callBehavior('templateBeforeValue',$this->core,$this->current_tag,$attr); 
    364262 
    365           if (isset($this->values[$this->current_tag])) { 
    366                $res .= call_user_func($this->values[$this->current_tag],$attr,ltrim($str_attr)); 
    367           } elseif ($this->unknown_value_handler != null) { 
    368                $res .= call_user_func($this->unknown_value_handler,$this->current_tag,$attr,$str_attr); 
    369           } 
     263          $res .= parent::compileValueNode($this->current_tag,$attr,$str_attr); 
    370264 
    371265          # --BEHAVIOR-- templateAfterValue 
     
    373267 
    374268          return $res; 
    375      } 
    376  
    377      public function setUnknownValueHandler($callback) 
    378      { 
    379           if (is_callable($callback)) { 
    380                $this->unknown_value_handler = $callback; 
    381           } 
    382      } 
    383  
    384      public function setUnknownBlockHandler($callback) 
    385      { 
    386           if (is_callable($callback)) { 
    387                $this->unknown_block_handler = $callback; 
    388           } 
    389269     } 
    390270 
     
    11731053 
    11741054          if ($lastn != 0) { 
     1055               // Set limit (aka nb of entries needed) 
    11751056               if ($lastn > 0) { 
     1057                    // nb of entries per page specified in template -> regular pagination 
    11761058                    $p .= "\$params['limit'] = ".$lastn.";\n"; 
    11771059               } else { 
    1178                     $p .= "\$params['limit'] = \$_ctx->nb_entry_per_page;\n"; 
     1060                    // nb of entries per page not specified -> use ctx settings 
     1061                    $p .= "\$params['limit'] = (\$_page_number == 1 ? \$_ctx->nb_entry_first_page : \$_ctx->nb_entry_per_page);\n"; 
    11791062               } 
    1180  
     1063               // Set offset (aka index of first entry) 
    11811064               if (!isset($attr['ignore_pagination']) || $attr['ignore_pagination'] == "0") { 
    1182                     $p .= "\$params['limit'] = array(((\$_page_number-1)*\$params['limit']),\$params['limit']);\n"; 
     1065                    // standard pagination, set offset 
     1066                    $p .= "\$params['limit'] = array((\$_page_number == 1 ? 0 : (\$_page_number - 2) * \$_ctx->nb_entry_per_page + \$_ctx->nb_entry_first_page),\$params['limit']);\n"; 
    11831067               } else { 
     1068                    // no pagination, get all posts from 0 to limit 
    11841069                    $p .= "\$params['limit'] = array(0, \$params['limit']);\n"; 
    11851070               } 
Note: See TracChangeset for help on using the changeset viewer.

Sites map