public function __construct($parent){ $this->parent=$parent; $this->db=$parent->db; $tree=$parent->record_tree2; $this->data=pull_item($tree->get($this->dataPath)); //add filter hook for relative paths $tree->addressFilters[]=function($address,$node){ //query:/:::`foo`!='' //optional paging: query:my_search_id:::/:::`foo`!='':::10,1 if(substr($address,0,6)==='query:'){ if($node->tree_queryfilter->data===false){ $node->record_tree2->insert(substr($node->tree_queryfilter->dataPath,0,strrpos($node->tree_queryfilter->dataPath,'/')+1),array(substr($node->tree_queryfilter->dataPath,strrpos($node->tree_queryfilter->dataPath,'/')+1)=>$node->tree_queryfilter->defaultData)); $node->tree_queryfilter->data=array('node:children'=>array()); } $queryDetails=explode(':::',substr($address,6)); $cacheItem=$node->tree_queryfilter->dataPath.'/'.$queryDetails[0]; $curItem=pull_item($node->record_tree2->get($cacheItem)); if($curItem===false){ if(isset($queryDetails[3])){ $paging=explode(',',$queryDetails[3]); }else{$paging=array(0,1);} $queryResults=$node->record_tree2->query($queryDetails[1],$queryDetails[2],true,false,$paging[0],$paging[1]); $cacheData=array('results'=>$queryResults, 'memUsage'=>memory_get_peak_usage(true), 'dbCount'=>$node->db->count); $node->record_tree2->insert($node->tree_queryfilter->dataPath.'/',array($queryDetails[0]=>$cacheData)); }else{ //$node->record_tree2->edit($cacheItem,$cacheData); } return $cacheItem; } return $address; }; }
public function address_matches($realAddress,$eventAddress,$item=false){ //no wildcards in real addresses if(strstr($realAddress,'/node:')!==false) return false; $realAddress=$this->filter_address($realAddress); $eventAddress=$this->filter_address($eventAddress); $special=array('node:wild', 'node:wild-recursive', 'node:wild-or-nothing', 'node:wild-recursive-or-nothing', 'node:starts-with(', 'node:ends-with(', 'node:attributes('); $realSplit=explode('/',$realAddress); $eventSplit=explode('/',$eventAddress); foreach($realSplit as $i=>$name){ if(isset($eventSplit[$i]) && $name!==''){ //static cases //print_r(array('eve'=>$eventSplit,'i'=>$i,'real'=>$realSplit)); switch($eventSplit[$i]){ case $special[0]: //wild continue; case $special[1]: //wild-recursive if(isset($eventSplit[$i+1]) && count($realSplit)<$i+1){ $curAddress=implode('/',array_slice($realSplit,0,$i+1)); $curCheck=implode('/',array_merge(array_slice($realSplit,0,$i),array_slice($eventSplit,$i+1,1))); if($this->address_matches($curAddress,$curCheck)){ array_splice($eventSplit,$i,1); } }elseif(count($realSplit)>$i+1){ array_splice($eventSplit,$i,1,array($realSplit[$i],$special[3])); } continue; case $special[2]: //wild-or-nothing if(isset($eventSplit[$i+1])){ $curAddress=implode('/',array_slice($realSplit,0,$i+1)); $curCheck=implode('/',array_merge(array_slice($eventSplit,0,$i),array_slice($eventSplit,$i+1,1))); if($this->address_matches($curAddress,$curCheck)){ array_splice($eventSplit,$i,1); } } break; case $special[3]: //wild-recursive-or-nothing if(isset($eventSplit[$i+1]) && count($realSplit)<=$i+2){ //ie do the nothing check as well as the recursive check insteadnof just one if(count($realSplit)<=$i+1){ $curAddress=implode('/',array_slice($realSplit,0,$i+1)); $curCheck=implode('/',array_merge(array_slice($realSplit,0,$i),array_slice($eventSplit,$i+1,1))); }else{ $curAddress=$realAddress; $curCheck=implode('/',array_merge(array_slice($realSplit,0,$i),array_slice($eventSplit,$i+1,count($eventSplit)))); } //echo "here we are\n"; //print_r(array('curAddrA'=>$curAddress,'checkA'=>$curCheck)); if($this->address_matches($curAddress,$curCheck)){ //echo 'foozle'; array_splice($eventSplit,$i,1); } //echo "back in da house\n"; }elseif(count($realSplit)>$i+1){ //echo 'fo-sho::'.implode('/',array_merge(array_slice($realSplit,0,$i+1),array_slice($eventSplit,$i+2,count($eventSplit))))."\n"; //TODO:DONEish need to check to see if this item matches the next item //before moving on and accepting //could go a diff path //TODO: need to check up a level as well as the undermen!!!! //echo 'shiilze::'.implode('/',array_slice($realSplit,0,$i+1)); //echo "\nfoozel::".implode('/',array_merge(array_slice($realSplit,0,$i),array_slice($eventSplit,$i+1,1))); if($this->address_matches(implode('/',array_slice($realSplit,0,$i+1)),implode('/',array_merge(array_slice($realSplit,0,$i),array_slice($eventSplit,$i+1,1)))) && $this->address_matches($realAddress,implode('/',array_merge(array_slice($realSplit,0,$i+1),array_slice($eventSplit,$i+2,count($eventSplit)))))) return true; array_splice($eventSplit,$i,0,array($realSplit[$i])); } break; } //print_r(array('eve2'=>$eventSplit,'i2'=>$i,'real2'=>$realSplit)); //dynamic special cases if(substr($eventSplit[$i],0,strlen($special[4]))===$special[4] && substr($eventSplit[$i],-1)===')'){ //starts-with(term) $term=substr($eventSplit[$i],strlen($special[4]),-1); if(substr($name,0,strlen($term))!==$term) return false; }elseif(substr($eventSplit[$i],0,strlen($special[5]))===$special[5] && substr($eventSplit[$i],-1)===')'){ //ends-with(term) $term=substr($eventSplit[$i],strlen($special[5]),-1); if(substr($name,-strlen($term))!==$term) return false; }elseif(substr($eventSplit[$i],0,strlen($special[6]))===$special[6] && substr($eventSplit[$i],-1)===')'){ //load item data if not supplied if($item===false) $item=pull_item($this->get(implode('/',array_slice($realSplit,0,$i+1)))); if($item===false) return false; //attributes(term) $term=substr($eventSplit[$i],strlen($special[6]),-1); $booleanSorted=$this->parse_attribute_query_string($term,array($item)); $curAddresses=$this->query_boolean_sort($booleanSorted); if(!count($curAddresses)) return false; }elseif(substr($eventSplit[$i],0,5)!=='node:' && $eventSplit[$i]!==$name){ return false; } }elseif(!isset($eventSplit[$i]) || $eventSplit[$i]!==$name){ return false; } } $lastEventName=$eventSplit[count($eventSplit)-1]; if(count($eventSplit)>count($realSplit) && in_array($lastEventName,$special) && strstr($lastEventName,'-or-nothing')!==false){ array_pop($eventSplit); } return count($realSplit)===count($eventSplit); }
<? function convert($size){ $unit=array('b','kb','mb','gb','tb','pb'); return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; } //useful value: path to app $p=$node->root_http_path.$node->ini['front']['appPath']; $appDir=substr($node->page['template'],0,strrpos($node->page['template'],'/')); //useful object: tree $tree=$node->record_tree2; $dataPath=$node->ini['front']['dataPath']; $dataRoot=pull_item($tree->get($dataPath,2)); if(!$dataRoot) die('Data not found!');
<? $itemAddress=$_POST['fields']['address']; if($itemAddress==='/'){ $isRoot=true; $item=array('node:mode'=>$node->record_tree2->mode('/'),'node:address'=>'/'); $item['node:modeString']=$node->record_tree2->mode_to_string($item['node:mode']); $item['node:roles']=$node->record_tree2->mode_to_roles($item['node:mode']); }else{ $isRoot=false; if(!is_array($render_params)) $error=$render_params; $item=pull_item($render_params); if(!$item) $error='Invalid item!'; } if(!isset($error)){ $permissions=$node->record_tree2->mode($itemAddress,0); }
public function rebuild_permissions($address='/',$depth=true){ $cache=array(); //find all items that have a pattern match! $patterned=$this->tree->query($address,"`pattern:match`!=''",$depth); foreach($patterned as $itemAddress=>$item){ if(array_key_exists($item['pattern:match'],$cache)){ $pattern=$cache[$item['pattern:match']]; }else{ $pattern=pull_item($this->tree->get($item['pattern:match'])); $cache[$item['pattern:match']]=$pattern; } if($pattern===false) return false; if(!isset($pattern['set-permission'])) continue; $perms=explode(',',$pattern['set-permission']); foreach($perms as $perm){ $perm=explode(':',$perm); if($this->tree->chmod($itemAddress,trim($perm[1])*1,array(trim($perm[0])*1))===false) return false; } } return true; }
foreach($inserters as $cId){ if(in_array(trim($cId)*1,$accessId)){ $childTypes[$patKey]=$patVal; } } } } } } }else{$thisItem=false;} break; case 'delete': case 'move': case 'owner': case 'rename': if(isset($_GET['address'])){ $itemData=$tree->get($_GET['address']); $thisItem=pull_item($itemData); } break; case 'permission': if(isset($_GET['address'])){ $itemData=$tree->get($_GET['address']); $thisItem=pull_item($itemData); $permissions=$node->record_tree2->mode($thisItem['node:address'],0); } break; default: $tool=false; }
//a little bit different when loading from the pattern's root $patternData=$tree->get($thisItem['pattern:children'],true); if(substr($thisItem['pattern:children'],-1)==='/'){ $patternAddr=substr($thisItem['pattern:children'],0,-1); $patternItem=pull_item($tree->get($patternAddr,true)); }else{ $patternAddr=$thisItem['pattern:children']; $patternItem=pull_item($patternData); } $patternFlat=flatten_tree($patternData); }else{$thisItem=false;} if(isset($patternItem) && is_array($patternItem) && isset($patternItem['page-read-depth'])){ //reload this content at the desired depth! $pageData=$tree->get($pageAddr,$patternItem['page-read-depth']*1); $thisItem=pull_item($pageData); } if(isset($patternItem['node:children']['section'])){ $thisChildren=organize_by_attrib('pattern:match',$thisItem['node:children']); if(isset($thisChildren[$patternAddr.'/section'])) $thisSections=$thisChildren[$patternAddr.'/section']; else $thisSections=false; }else{$thisSections=false;} function extract_modifiers($match){ $return=array(); $modifiers=array('display-as-link', 'hide-on-page', 'no-wrapper-on-page'); foreach($modifiers as $mod){ if(isset($match[$mod])){ $return[$mod]=explode(',',$match[$mod]);