Ejemplo n.º 1
0
 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);
     }
 }
Ejemplo n.º 2
0
 /**
  * Static method for listing available style templates
  */
 public static function list_styles($up = 0, $prefix = '/', $spacer = '')
 {
     static $style_array = array();
     $style_array[''] = midcom::get('i18n')->get_string('default', 'midcom.admin.folder');
     // Give an option for creating a new layout template
     $style_array['__create'] = midcom::get('i18n')->get_string('new layout template', 'midcom.admin.folder');
     if ($GLOBALS['midcom_config']['styleengine_relative_paths'] && $up == 0) {
         // Relative paths in use, start seeking from under the style used for the Midgard host
         $up = midcom_connection::get('style');
     }
     $qb = midcom_db_style::new_query_builder();
     $qb->add_constraint('up', '=', $up);
     $styles = $qb->execute();
     foreach ($styles as $style) {
         $style_string = "{$prefix}{$style->name}";
         // Hide common unwanted material with heuristics
         if (preg_match('/(asgard|empty)/i', $style_string)) {
             continue;
         }
         $style_array[$style_string] = "{$spacer}{$style->name}";
         self::list_styles($style->id, $style_string . '/', $spacer . '  ');
     }
     return $style_array;
 }
Ejemplo n.º 3
0
 private function delete_missing_folders($foldernames, $style_id)
 {
     if (!$this->delete_missing) {
         return;
     }
     $qb = midcom_db_style::new_query_builder();
     $qb->add_constraint('up', '=', $style_id);
     if (!empty($foldernames)) {
         $qb->add_constraint('name', 'NOT IN', $foldernames);
     }
     $folders = $qb->execute();
     foreach ($folders as $folder) {
         $folder->delete();
     }
 }