예제 #1
0
파일: quadbraces.php 프로젝트: vgrish/xblib
 public function extensions($value, $ext = '')
 {
     $RET = '' . trim($value);
     if (empty($ext)) {
         return '' . $value;
     }
     if ($_ = preg_match_all('|\\:([\\w\\-\\.]+)((\\=`([^`]*)`)?)|si', $ext, $ms, PREG_SET_ORDER)) {
         for ($c = 0; $c < count($ms); $c++) {
             $a = $ms[$c][1];
             $v = isset($ms[$c][4]) ? $ms[$c][4] : '';
             if (xbParser::isLogic($a)) {
                 $cond = xbParser::condition($a, $value, $v);
                 $cthen = xbParser::isLogicFunction($a) ? $v : $RET;
                 if (isset($ms[$c + 1])) {
                     if ($ms[$c + 1][1] == 'then') {
                         $c++;
                         $cthen = $ms[$c][4];
                     }
                 }
                 $celse = $RET;
                 if (isset($ms[$c + 1])) {
                     if ($ms[$c + 1][1] == 'else') {
                         $c++;
                         $celse = $ms[$c][4];
                     }
                 }
                 $RET = $cond ? $cthen : $celse;
                 if (preg_match($this->_tags['local'], $RET)) {
                     $RET = preg_replace_callback($this->_tags['local'], array($this, "parse_local"), $RET);
                 }
             } elseif (in_array($a, array('import', 'css-link', 'js-link'))) {
                 $RET = xbParserLibQB::jscss($a, $RET);
             } elseif (in_array($a, array('link', 'link-external'))) {
                 $RET = xbParserLibQB::link($a, $RET, $v);
             } else {
                 switch ($a) {
                     case 'links':
                         $RET = xbParser::autoLinks($RET, $v);
                         break;
                     case 'include':
                         if (!empty($v)) {
                             $_ = xbParser::path("{$RET}/{$v}");
                             $RET = is_file($_) ? include $_ : '';
                         }
                         break;
                     case 'ul':
                     case 'ol':
                         $RET = xbParser::autoList($RET, $v, $a);
                         break;
                     case 'for':
                         $v = intval($v);
                         $start = 1;
                         if ($ms[$c + 1][1] == 'start') {
                             $c++;
                             $start = intval($ms[$c][4]);
                         }
                         $splt = '';
                         if ($ms[$c + 1][1] == 'splitter') {
                             $c++;
                             $splt = $ms[$c][4];
                         }
                         $_R = array();
                         for ($pos = $start; $pos <= $v - $start; $pos++) {
                             $tpls = array(array("#\\[\\+(iterator\\.index)((:?\\:([\\w\\-\\.]+)((=`([^`]*)`))?)*)\\+\\]#si", $pos));
                             $_R[] = $this->iteration($tpls, $RET);
                         }
                         $RET = implode($splt, $_R);
                         break;
                     case 'foreach':
                         $v = explode(',', $v);
                         $splt = '';
                         if ($ms[$c + 1][1] == 'splitter') {
                             $c++;
                             $splt = $ms[$c][4];
                         }
                         $_R = array();
                         foreach ($v as $pos => $key) {
                             $tpls = array(array("#\\[\\+(iterator\\.index)((:?\\:([\\w\\-\\.]+)((=`([^`]*)`))?)*)\\+\\]#si", $pos), array("#\\[\\+(iterator|iterator\\.key)((:?\\:([\\w\\-\\.]+)((=`([^`]*)`))?)*)\\+\\]#si", $key));
                             $_R[] = $this->iteration($tpls, $RET);
                         }
                         $RET = implode($splt, $_R);
                         break;
                     default:
                         if ($_ = $this->execute($a, $v, $RET)) {
                             $RET = $_;
                         }
                 }
             }
         }
     }
     return $RET;
 }
예제 #2
0
파일: datae.php 프로젝트: vgrish/xblib
 public function parse($m)
 {
     $key = $this->owner->parseStart($m);
     $args = $this->owner->arguments[$this->owner->level];
     $value = $this->owner->variable($key);
     if ($value === false) {
         if (in_array('datae', $this->owner->notice)) {
             return "<!-- not found: datae/{$key} -->";
         }
         $value = '';
     }
     if (is_array($value)) {
         $tplt = 'chunk';
         if (isset($args['chunkType'])) {
             if (in_array($args['chunkType'], array('chunk', 'string', 'lib'))) {
                 $tplt = $args['chunkType'];
             }
         }
         $tpli = '<li><span class="key">[+key+]</span><span class="value">[+value+]</span></li>';
         if (isset($args['chunk'])) {
             if ($fn = $this->owner->search('chunk', $args['chunk'])) {
                 switch ($tplt) {
                     case 'string':
                         $tpli = '{(' . $args['chunk'] . ' [+arguments+])}';
                         break;
                     case 'lib':
                         $tpli = '{<' . $args['chunk'] . ' [+arguments+]>}';
                         break;
                     default:
                         $tpli = '{{' . $args['chunk'] . ' [+arguments+]}}';
                         break;
                 }
             }
         }
         $LK = false;
         if (isset($args['langKeys'])) {
             $LK = xbParser::bool($args['langKeys']);
         }
         $LP = '';
         if (isset($args['langPrefix'])) {
             $LP = $args['langPrefix'];
         }
         $v = '';
         foreach ($value as $dataKey => $dataVal) {
             $DK = $LK ? "[%" . (!empty($LP) ? $LP . "." : "") . "{$dataKey}%]" : $dataKey;
             if (is_array($dataVal)) {
                 $_ = array();
                 foreach ($dataVal as $dvKey => $dvVal) {
                     $_[] = "&" . $dvKey . "=`{$dvVal}`";
                 }
                 $_[] = '&' . $key . ".datakey=`{$DK}`";
                 $v .= str_replace(array('[+key+]', '[+value+]', '[+arguments+]'), array($DK, strval($dataVal), implode(' ', $_)), $tpli);
             } else {
                 $_ = strval($dataVal);
                 $v .= str_replace(array('[+key+]', '[+value+]', '[+arguments+]'), array($DK, $_, "&key=`{$DK}` &value=`{$_}`"), $tpli);
             }
         }
     } else {
         $v = strval($value);
     }
     return $this->owner->parseFinish($m, 'datae', $key, $v);
 }
예제 #3
0
파일: table.php 프로젝트: vgrish/xblib
 public function parse($m)
 {
     $key = $this->owner->parseStart($m);
     $args = $this->owner->arguments[$this->owner->level];
     $value = $this->owner->variable($key);
     if ($value === false) {
         if (in_array('table', $this->owner->notice)) {
             return "<!-- not found: table/{$key} -->";
         }
         $value = '';
     }
     if (is_array($value)) {
         $v = '';
         // Параметры обработки
         $LK = false;
         $LP = '';
         $FL = array();
         if (isset($args['langKeys'])) {
             $LK = xbParser::bool($args['langKeys']);
         }
         if (isset($args['langPrefix'])) {
             $LP = $args['langPrefix'];
         }
         if (!isset($args['fields'])) {
             foreach ($value as $dataRow) {
                 if (is_array($dataRow)) {
                     foreach ($dataRow as $fKey => $fVal) {
                         if (!in_array($fKey, $FL)) {
                             $FL[] = $fKey;
                         }
                     }
                 }
             }
         } else {
             $FL = explode(',', $args['fields']);
         }
         $tpls = $this->owner->getTemplates($args, array('table' => '<table cellpadding="0" cellspacing="0"' . ' border="0">[+content+]</table>', 'heap' => '<theap>[+rows+]</theap>', 'heaprow' => '<tr>[+cells+]</tr>', 'heapcell' => '<th class="field-[+key+]">[+value+]</th>', 'body' => '<tbody>[+rows+]</tbody>', 'bodyrow' => '<tr data-id="[+id+]">[+cells+]</tr>', 'bodycell' => '<td class="field-[+key+]">[+value+]</td>', 'foot' => '', 'footrow' => '<tr>[+cells+]</tr>', 'footcell' => '<th class="field-[+key+]">[+value+]</th>'));
         $tplsC = array(array("#\\[\\+(key)((:?\\:([\\w\\-\\.]+)((=`([^`]*)`))?)*)\\+\\]#si", ''), array("#\\[\\+(value)((:?\\:([\\w\\-\\.]+)((=`([^`]*)`))?)*)\\+\\]#si", ''));
         $tplsR = array(array("#\\[\\+(id)((:?\\:([\\w\\-\\.]+)((=`([^`]*)`))?)*)\\+\\]#si", ''));
         // Шапка
         if (!empty($tpls['heap'])) {
             $row = array();
             foreach ($FL as $fKey) {
                 $tplsC[0][1] = $fKey;
                 $tplsC[1][1] = $LK ? "[%" . (!empty($LP) ? $LP . "." : "") . "{$fKey}%]" : $fKey;
                 $row[] = $this->owner->iteration($tplsC, $tpls['heapcell']);
             }
             $row = implode('', $row);
             $row = str_replace('[+cells+]', $row, $tpls['heaprow']);
             $v .= str_replace('[+rows+]', $row, $tpls['heap']);
         }
         // Значения
         $rows = array();
         foreach ($value as $dataID => $dataRow) {
             if (is_array($dataRow)) {
                 $tplsR[0][1] = $dataID;
                 $row = array();
                 foreach ($FL as $fKey) {
                     $tplsC[0][1] = $fKey;
                     $tplsC[1][1] = isset($dataRow[$fKey]) ? $dataRow[$fKey] : '';
                     $row[] = $this->owner->iteration($tplsC, $tpls['bodycell']);
                 }
                 $row = implode('', $row);
                 $row = str_replace('[+cells+]', $row, $tpls['bodyrow']);
                 $row = $this->owner->iteration($tplsR, $row);
                 $rows[] = $row;
             }
         }
         $v .= str_replace('[+rows+]', implode('', $rows), $tpls['body']);
         // Подвал
         if (!empty($tpls['foot'])) {
             $row = array();
             foreach ($FL as $fKey) {
                 $tplsC[0][1] = $fKey;
                 $tplsC[1][1] = $LK ? "[%" . (!empty($LP) ? $LP . "." : "") . "{$fKey}%]" : $fKey;
                 $row[] = $this->owner->iteration($tplsC, $tpls['footcell']);
             }
             $row = implode('', $row);
             $row = str_replace('[+cells+]', $row, $tpls['footrow']);
             $v .= str_replace('[+rows+]', $row, $tpls['foot']);
         }
         // Итог
         $v = str_replace('[+content+]', $v, $tpls['table']);
     } else {
         $v = strval($value);
     }
     return $this->owner->parseFinish($m, 'table', $key, $v);
 }
예제 #4
0
파일: prototype.php 프로젝트: vgrish/xblib
 public function word($key)
 {
     $P = 'caption';
     $K = xbParser::languageKey($key, $P);
     if (isset($this->_dictionary[$K][$P])) {
         return $this->_dictionary[$K][$P];
     }
     return ucfirst(str_replace(array('.', '_', '-'), ' ', $key));
 }