private function append_nodes(\DomNode $node, $parent) { if ($node->localName != 'node') { return; } $name = ""; foreach ($node->attributes as $element) { /* The name of each JCR node or property becomes the value of the sv:name */ if ($element->name != 'name') { continue; } $name = $element->value; } /* The hierarchy of the content repository nodes and properties is reflected in * the hierarchy of the corresponding XML elements. */ $mvc_node = new midgardmvc_core_node(); $mvc_node->name = $name; $mvc_node->up = $parent->id; $mvc_node->create(); /* If there's duplicate, get it and reuse */ if (midgard_connection::get_instance()->get_error() == MGD_ERR_DUPLICATE) { $q = new \midgard_query_select(new \midgard_query_storage('midgardmvc_core_node')); $group = new midgard_query_constraint_group('AND'); $group->add_constraint(new \midgard_query_constraint(new \midgard_query_property('up'), '=', new \midgard_query_value($parent->id))); $group->add_constraint(new \midgard_query_constraint(new \midgard_query_property('name'), '=', new \midgard_query_value($name))); $q->set_constraint($group); $q->execute(); $mvc_node = current($q->list_objects()); } foreach ($node->childNodes as $snode) { $this->append_nodes($snode, $mvc_node); } }
private function get_node($node_id) { static $nodes = array(); if (!isset($nodes[$node_id])) { $node = new midgardmvc_core_node(); $node->get_by_id($node_id); $nodes[$node_id] = midgardmvc_core_providers_hierarchy_node_midgard2::get_instance($node); } return $nodes[$node_id]; }
/** * Read the request configuration and parse the URL */ public function __construct() { if (!extension_loaded('midgard2')) { throw new Exception('Midgard 2.x is required for this Midgard MVC setup.'); } $this->midgardmvc = midgardmvc_core::get_instance(); try { $this->_root_page = new midgardmvc_core_node($this->midgardmvc->configuration->midgardmvc_root_page); } catch (midgard_error_exception $e) { $this->_root_page = new midgardmvc_core_node(); $this->_root_page->get_by_path('/midgardmvc_root'); } }
private function get_node_children(midgardmvc_core_node $node) { // Load children for PROPFIND purposes $children = array(); $mc = midgardmvc_core_node::new_collector('up', $node->id); $mc->set_key_property('name'); $mc->add_value_property('title'); $mc->execute(); $pages = $mc->list_keys(); foreach ($pages as $name => $array) { if (empty($name)) { continue; } $children[] = array('uri' => "{midgardmvc_core::get_instance()->context->prefix}{$name}/", 'title' => $mc->get_subkey($name, 'title'), 'mimetype' => 'httpd/unix-directory', 'resource' => 'collection'); } if (midgardmvc_core::get_instance()->context->page->id == midgardmvc_core::get_instance()->context->root_page->id) { // Additional "special" URLs $children[] = array('uri' => "{midgardmvc_core::get_instance()->context->prefix}mgd:snippets/", 'title' => 'Code Snippets', 'mimetype' => 'httpd/unix-directory', 'resource' => 'collection'); $children[] = array('uri' => "{midgardmvc_core::get_instance()->context->prefix}mgd:styles/", 'title' => 'Style Templates', 'mimetype' => 'httpd/unix-directory', 'resource' => 'collection'); } return $children; }
private function get_element_page($page_id, $element) { switch ($element) { case 'title': case 'content': $mc = midgardmvc_core_node::new_collector('id', $page_id); $mc->set_key_property($element); $mc->execute(); $keys = $mc->list_keys(); if (count($keys) == 0) { return null; } foreach ($keys as $value => $array) { return $value; } default: $mc = midgardmvc_core_node_template::new_collector('node', $page_id); $mc->add_constraint('name', '=', $element); $mc->set_key_property('content'); $mc->add_value_property('guid'); $mc->execute(); $keys = $mc->list_keys(); if (count($keys) == 0) { return null; } foreach ($keys as $value => $array) { // Register element to template cache $this->midgardmvc->cache->template->register($this->get_cache_identifier(), array($mc->get_subkey($value, 'guid'))); return $value; } } }
private static function prepare_node(midgardmvc_core_node $node, array $node_data, $destructive) { $node->title = $node_data['title']; $node->component = $node_data['component']; if ($destructive || !$node->content) { $node->content = $node_data['content']; } if ($node->guid) { $node->update(); } else { if (isset($node_data['guid'])) { $node->set_guid($node_data['guid']); } $node->create(); } if (isset($node_data['configuration'])) { $node->set_parameter('midgardmvc_core', 'configuration', midgardmvc_core::write_yaml($node_data['configuration'])); } self::prepare_node_children($node, $node_data, $destructive); }
private function get_page_prefix() { $context = $this->midgardmvc->context; if (!$context->page) { throw new Exception("No page set for the manual dispatcher"); } static $prefixes = array(); if (isset($prefixes[$context->page->id])) { return $prefixes[$context->page->id]; } $prefix = '/'; $root_id = 0; if (isset($context->host)) { $host_mc = midgard_host::new_collector('id', $context->host->id); $host_mc->set_key_property('root'); $host_mc->add_value_property('prefix'); $host_mc->execute(); $roots = $host_mc->list_keys(); if (!$roots) { throw new Exception("Failed to load root page data for host {$context->host->id}"); } $root_id = null; foreach ($roots as $root => $array) { $root_id = $root; $prefix = $host_mc->get_subkey($root, 'prefix') . '/'; break; } } $root_id = $this->midgardmvc->context->root_page->id; if ($context->page->id == $root_id) { // We're requesting prefix for the root page $prefixes[$context->page->id] = $prefix; return $prefix; } $page_path = ''; $page_id = $context->page->id; while ($page_id && $page_id != $root_id) { $parent_mc = midgardmvc_core_node::new_collector('id', $page_id); $parent_mc->set_key_property('up'); $parent_mc->add_value_property('name'); $parent_mc->execute(); $parents = $parent_mc->list_keys(); foreach ($parents as $parent => $array) { $page_id = $parent; $page_path = $parent_mc->get_subkey($parent, 'name') . "/{$page_path}"; } } $prefixes[$context->page->id] = $prefix . $page_path; return $prefix . $page_path; }
echo "Database initialized, preparing storage for MgdSchema classes:\n"; $re = new ReflectionExtension('midgard2'); $classes = $re->getClasses(); foreach ($classes as $refclass) { $parent_class = $refclass->getParentClass(); if (!$parent_class) { continue; } if ($parent_class->getName() != 'midgard_object') { continue; } $type = $refclass->getName(); midgard_storage::create_class_storage($type); echo " Created storage for {$type}\n"; } $page = new midgardmvc_core_node(); $page->name = 'midgardmvc_root'; $page->title = 'Midgard MVC root page'; $page->content = 'Welcome to Midgard MVC!'; $page->component = 'midgardmvc_core'; if (!$page->create()) { die("Failed to create Midgard MVC root node: " . $midgard->get_error_string() . "\n"); } echo "Created Midgard MVC root page {$page->guid}\n"; $person = new midgard_person(); $person->set_guid('f6b665f1984503790ed91f39b11b5392'); $person->firstname = 'Midgard'; $person->lastname = 'Administrator'; $person->email = '*****@*****.**'; $person->homepage = 'http://www.midgard-project.org/'; $person->birthdate = new midgard_datetime('1999-05-08');