private static function RecurseGroups($e, $xml, $skin) { $group = array(); $name = Insertable::_NameToSymbol((string) $e['name']); if ($name !== (string) $e['name']) { trigger_error("Group name '{$e['name']}' has invalid characters (should be letters, numbers, and underscores only) in template '{$template}'"); return null; } $group = array(); $group['name'] = $name; $group['label'] = (string) $e['label']; $group['subpage'] = (string) $e['subpage']; $group['members'] = array(); $members = $e->xpath('pm:member'); foreach ($members as $m) { $name = Insertable::_NameToSymbol((string) $m['name']); if ($name !== (string) $m['name']) { trigger_error("Group name '{$m['name']}' has invalid characters (should be letters, numbers, and underscores only) in template '{$template}'"); return null; } $label = (string) $m['label']; $type = (string) $m['type']; $cssid = ''; $cssclass = ''; $selector = ''; if ($type == 'html') { $thePath = '//pm:loop[@name=\'' . $group['name'] . '\']|//*[@pm:loop=\'' . $group['name'] . '\']'; $loops = $xml->xpath($thePath); foreach ($loops as $l) { if (count($l->children())) { $children = $l->xpath('//*[contains(text(), \'@{' . $name . '}@\')]'); foreach ($children as $c) { if (preg_match('/@{[\\w\\W\\s\\S]*?' . $name . '[\\w\\W\\s\\S]*?}@/', $c->asXml())) { $selector = Insertable::_InsertSelector($c, $skin); break; } } } if ($selector) { break; } } } else { if ($type == 'select') { $options = array(); foreach ($m->option as $option) { $options[] = array('label' => "{$option}", 'value' => !is_null($option['value']) ? "{$option['value']}" : "{$option}"); } } else { if ($type == 'model') { $options = array(); if (class_exists($m['model'])) { $model = (string) $m['model']; $values = new $model(); foreach ($values->getAll() as $value) { $options[] = array('label' => $value->get((string) $m['modellabel']), 'value' => $model . ':' . $value->get('id')); } } $type = 'select'; } } } $member = array('name' => $name, 'label' => $label, 'type' => $type, 'cssid' => $cssid, 'cssclass' => $cssclass, 'selector' => $selector); if ($type == 'select') { $member['options'] = $options; } $group['members'][] = $member; } $group['admin'] = (string) $e['admin']; $group['subgroups'] = array(); $subgroups = $e->xpath('pm:group'); foreach ($subgroups as $subgroup) { $group['subgroups'][] = self::RecurseGroups($subgroup, $xml, $skin); } return $group; }