This repository has been archived by the owner on Jan 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCallerMarkup.php
103 lines (103 loc) · 2.97 KB
/
CallerMarkup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace RedCat\Templix;
abstract class CallerMarkup extends Markup{
protected $hiddenWrap = true;
protected $callback;
function callback(){
$this->remapAttr('selector');
if($this->__isset('compile')){
$this->__set('selector',$this->evalue($this->__get('compile')));
$this->__unset('compile');
}
if(!isset($this->callback))
$this->callback = lcfirst(ltrim(substr($c=get_class($this),(strrpos($c,'\\')+1)),'_'));
if($this->selector===null){
if(count($this->attributes)===1&&isset($this->metaAttribution[0])&&($k=$this->metaAttribution[0])&&$this->attributes[$k]==$k){
$this->selector = $k;
}
else if(!empty($this->attributes)){
$this->selector = '*';
foreach(array_keys($this->attributes) as $k)
if($k!='selector')
$this->selector .= '['.$k.'="'.str_replace('"','\"',$this->attributes[$k]).'"]';
}
}
$this->selector = str_replace("'",'"',$this->selector);
return $this->callback;
}
function load(){
//if(!$this->templix)
//return;
$this->callback();
}
function selectorCodeTHIS($__this){
$str = $this->selectorCodeTHAT($__this,"$this");
return $str===null?$this:$str;
}
private function __evePlus($eve,$prefix='',$sufix='',$__this=null){
$plus = 0;
while(strpos($eve,'+')===0){
$eve = substr($eve,1);
$plus++;
}
$eve = $this->evalue($prefix.$eve.$sufix,['__this'=>$__this]);
if($plus){
for($i=0;$i<$plus;$i++){
if(strpos($eve,'<?')===false)
break;
$eve = $this->evalue($eve,['__this'=>$__this]);
}
}
return $eve;
}
function selectorCodeTHAT($__this,$str){
$pos = 0;
if(preg_match_all('/\\{\\{this:([^\\}\\}]+)/',$str, $matches)){
foreach($matches[1] as $i=>$eve){
$eve = $this->__evePlus($eve,'<?php echo $__this->',';',$__this);
$str = substr($str,0,$pos=strpos($str,$matches[0][$i],$pos)).$eve.substr($str,$pos+strlen($matches[0][$i])+2);
}
}
$pos = 0;
if(preg_match_all('/\\{\\{compile:([^\\}\\}]+)/',$str, $matches)){
foreach($matches[1] as $i=>$eve){
$eve = $this->__evePlus($eve,'<?php echo ',';');
$str = substr($str,0,$pos=strpos($str,$matches[0][$i],$pos)).$eve.substr($str,$pos+strlen($matches[0][$i])+2);
}
}
return $str;
}
function extendLoad(){
$c = $this->callback();
if(is_array($c)){
call_user_func($c);
}
elseif($extend = $this->closest('extend')){
if($this->selector){
foreach($extend->children($this->selector) as $i=>$tg){
if($i)
$append = clone $this;
else
$append = $this;
$append->parent = $tg;
$tg->$c($append);
}
}
else{
$extend->closest()->$c($this);
}
}
}
function applyLoad($apply = null){
$c = $this->callback();
if(is_array($c)){
call_user_func($c);
}
elseif($apply || (($apply = $this->closest('apply'))) && ($apply = $apply->selfClosed?$this->closest():$apply->_extended))
if($this->selector)
foreach($apply->children($this->selector) as $select)
$select->$c($this->selectorCodeTHIS($select));
else
$apply->closest()->$c($this);
}
}