Example #1
0
 public function install($id)
 {
     $dir = FROG_ROOT . '/public/themes/' . $id . '/';
     $files = $this->scan_directory_recursively($dir, 'php');
     $data = array();
     $data['name'] = $id;
     // Layouts
     $layouts = array();
     $l = array();
     // Snippets
     $snippets = array();
     $s = array();
     foreach ($files as $file) {
         switch ($file['name']) {
             case 'layouts':
                 foreach ($file['content'] as $layout) {
                     $layouts[] = $layout['name'];
                     $l['name'] = Themr::theme_name($layout['name']);
                     $l['content_type'] = 'text/html';
                     $l['content'] = file_get_contents($layout['path']);
                     $layout = new Layout($l);
                     if (!$layout->save()) {
                         Flash::set('error', __('Layout has not been added. Name must be unique!'));
                     }
                 }
                 break;
             case 'snippets':
                 foreach ($file['content'] as $snippet) {
                     $snippets[] = $snippet['name'];
                     $s['name'] = $snippet['name'];
                     $s['filter_id'] = '';
                     $s['content'] = file_get_contents($snippet['path']);
                     $snippet = new Snippet($s);
                     if (!$snippet->save()) {
                         Flash::set('error', __('Snippet has not been added. Name must be unique!'));
                     }
                 }
                 break;
         }
     }
     // Serialize Layout and Snippet names
     $data['layout'] = serialize($layouts);
     $data['snippet'] = serialize($snippets);
     // Get Current Theme Info
     $theme_info = Themr::findTheme($id);
     // Save into Themr database table
     $theme = new Themr($data);
     if (!$theme->save()) {
         Flash::set('error', __('Theme has not been added. Name must be unique!'));
         redirect(get_url('plugin/themr'));
     } else {
         Flash::set('success', __('Theme <b>:name</b> has been added!', array(':name' => $theme_info['name'])));
         redirect(get_url('plugin/themr'));
     }
 }