Example #1
0
 function layout()
 {
     $template = $this->tag['template'];
     $icount = min($this->temparr['limits'], count($this->items));
     list($rowblock, $colblock) = $this->fetch_block($template);
     $colcount = empty($colblock) ? 1 : (empty($this->tag['cols']) ? 1 : $this->tag['cols']);
     $rowcount = ceil($icount / $colcount);
     $newrows = $newcols = $newrow = '';
     for ($i = 0; $i < $colcount * $rowcount; $i++) {
         //如果是空集以下的操作跳过
         $filled = isset($this->items[$i]);
         $this->item = $filled ? $this->items[$i] : array();
         $this->item['sn_cell'] = $i + 1;
         //在列表中以原始数据来解析当前的单元序号
         $filled ? $this->deal_incell() : $this->fill_blank();
         if ($colblock) {
             $this->item['sn_row'] = ceil(($i + 1) / $colcount);
             //在列表中以原始数据来解析当前的行序号
             if ($filled || $this->cell_fill) {
                 $newcol = $colblock;
                 nreplace($newcol, 'up', $this->item);
                 !$this->no_ctag && nreplace($newcol, 'c', $this->midarr);
                 //单元内的c标识
                 nreplace($newcol, 'u', $this->item);
                 nreplace($newcol, 'b', $this->item);
             } else {
                 $newcol = '';
             }
             $newcols .= $newcol;
             if (!(($i + 1) % $colcount)) {
                 $newrow = $this->block_replace('col', $newcols, $rowblock);
                 nreplace($newrow, 'up', $this->item);
                 !$this->no_ctag && nreplace($newrow, 'c', $this->midarr);
                 //单元外的c标识
                 nreplace($newrow, 'u', $this->item);
                 nreplace($newrow, 'b', $this->item);
                 $newrows .= $newrow;
                 $newcols = $newrow = '';
             }
         } else {
             $this->item['sn_row'] = $i + 1;
             //在列表中以原始数据来解析当前的行序号
             $newrow = $rowblock;
             nreplace($newrow, 'up', $this->item);
             !$this->no_ctag && nreplace($newrow, 'c', $this->midarr);
             //单元内的c标识
             nreplace($newrow, 'u', $this->item);
             nreplace($newrow, 'b', $this->item);
             $newrows .= $newrow;
             $newrow = '';
         }
     }
     $template = $this->block_replace('row', $newrows, $template);
     nreplace($template, 'up', $this->temparr);
     !$this->no_ctag && nreplace($template, 'c', $this->temparr);
     nreplace($template, 'u', $this->temparr);
     nreplace($template, 'b', $this->temparr);
     return $template;
 }
Example #2
0
function arr_row_block($str)
{
    $narr = array(1 => '', 2 => $str, 3 => '');
    if (preg_match_all("/\\{(c|u)\\\$(.+?)(\\}|\\s+(.*?)\\{\\/\\1\\\$\\2\\})/is", $str, $matches)) {
        $_reps = $_order = array();
        foreach ($matches[0] as $k => $v) {
            $_reps[$k] = $v;
            $_order[$k] = $matches[1][$k] == 'c' ? 0 : 1;
        }
        if ($_reps) {
            array_multisort($_order, SORT_ASC, $_reps);
            foreach ($_reps as $k => $v) {
                $str = str_replace($v, '[[[' . $k . ']]]', $str);
            }
        }
        unset($matches, $_order, $k, $v);
    }
    if (preg_match("/^(.*?)\\[row\\](.*)\\[\\/row\\](.*?)\$/is", $str, $matches)) {
        unset($matches[0]);
        foreach ($matches as $x => $y) {
            if (!empty($_reps)) {
                foreach ($_reps as $k => $v) {
                    $y = str_replace('[[[' . $k . ']]]', $v, $y);
                }
            }
            if ($x != 2) {
                nreplace($y, 'c');
                nreplace($y, 'u');
            }
            $narr[$x] = $y;
        }
    } elseif (!empty($_reps)) {
        foreach ($_reps as $k => $v) {
            $narr[2] = str_replace('[[[' . $k . ']]]', $v, $narr[2]);
        }
    }
    unset($matches, $reps, $k, $v);
    return $narr;
}