public function read_style($style, $path) { $style_path = "{$path}{$style->name}"; if (!file_exists($style_path)) { mkdir($style_path); } $filenames = array(); $foldernames = array(); $element_qb = midcom_db_element::new_query_builder(); $element_qb->add_constraint('style', '=', $style->id); $elements = $element_qb->execute(); foreach ($elements as $element) { file_put_contents("{$style_path}/{$element->name}.php", $element->value); $filenames[] = "{$element->name}.php"; } $style_qb = midcom_db_style::new_query_builder(); $style_qb->add_constraint('up', '=', $style->id); $styles = $style_qb->execute(); foreach ($styles as $style) { $this->read_style($style, "{$style_path}/"); $foldernames[] = $style->name; } if ($this->delete_missing) { // Then delete files and folders that are in DB but not in the importing folder $this->delete_missing_folders($foldernames, $style_path); $this->delete_missing_files($filenames, $style_path); } }
function get_style_elements_and_nodes($style) { $results = array('elements' => array(), 'nodes' => array()); $style_id = $this->get_style_id_from_path($style); if (!$style_id) { return $results; } $style_nodes = midcom::get('style')->get_nodes_using_style($style); foreach ($style_nodes as $node) { if (!isset($results['nodes'][$node->component])) { $results['nodes'][$node->component] = array(); } $results['nodes'][$node->component][] = $node; } foreach ($results['nodes'] as $component => $nodes) { // Get the list of style elements for the component $results['elements'][$component] = midcom::get('style')->get_component_default_elements($component); // Arrange elements in alphabetical order ksort($results['elements'][$component]); } $results['elements']['midcom'] = array('style-init' => '', 'style-finish' => ''); if ($style_id == midcom_connection::get('style')) { // We're in site main style, append elements from there to the list of "common elements" $mc = midcom_db_element::new_collector('style', midcom_connection::get('style')); $elements = $mc->get_values('name'); foreach ($elements as $name) { $results['elements']['midcom'][$name] = ''; } if (!isset($results['elements']['midcom']['ROOT'])) { // There should always be the ROOT element available $results['elements']['midcom']['ROOT'] = ''; } } return $results; }
private function delete_missing_files($filenames, $style_id) { if (!$this->delete_missing) { return; } $qb = midcom_db_element::new_query_builder(); $qb->add_constraint('style', '=', $style_id); if (!empty($filenames)) { $qb->add_constraint('name', 'NOT IN', $filenames); } $files = $qb->execute(); foreach ($files as $file) { $file->delete(); } }