public function post_install($theme_slug) { if (empty($theme_slug)) { $this->data['message'] = __('themes::lang.Theme slug is empty Verify theme info file')->get(ADM_LANG); $this->data['message_type'] = 'error'; if (Request::ajax()) { $data = array('flash_message' => array('message_type' => $this->data['message_type'], 'messages' => array($this->data['message']))); return json_encode($data); } return Redirect::to(ADM_URI . '/themes')->with($this->data); } $theme_path = path('public') . 'themes' . DS . $theme_slug . DS; $theme_info = null; if (file_exists($path = $theme_path . 'theme.info.json')) { $theme_info = json_decode(File::get($path)); } else { $this->data['message'] = __('themes::lang.Cannot find info file', array('theme_slug' => $theme_slug))->get(ADM_LANG); $this->data['message_type'] = 'error'; if (Request::ajax()) { $data = array('flash_message' => array('message_type' => $this->data['message_type'], 'messages' => array($this->data['message']))); return json_encode($data); } return Redirect::to(ADM_URI . '/themes')->with($this->data); } if (is_null($theme_info)) { $this->data['message'] = __('themes::lang.Cannot load information from theme info file', array('theme_slug' => $theme_slug))->get(ADM_LANG); $this->data['message_type'] = 'error'; if (Request::ajax()) { $data = array('flash_message' => array('message_type' => $this->data['message_type'], 'messages' => array($this->data['message']))); return json_encode($data); } return Redirect::to(ADM_URI . '/themes')->with($this->data); } if (!isset($theme_info->name) or empty($theme_info->name)) { $this->data['message'] = __('themes::lang.Missing theme slug', array('theme_slug' => $theme_slug))->get(ADM_LANG); $this->data['message_type'] = 'error'; if (Request::ajax()) { $data = array('flash_message' => array('message_type' => $this->data['message_type'], 'messages' => array($this->data['message']))); return json_encode($data); } return Redirect::to(ADM_URI . '/themes')->with($this->data); } if (!isset($theme_info->layer) or empty($theme_info->layer)) { $this->data['message'] = __('themes::lang.The theme layer is required in the theme info file')->get(ADM_LANG); $this->data['message_type'] = 'error'; if (Request::ajax()) { $data = array('flash_message' => array('message_type' => $this->data['message_type'], 'messages' => array($this->data['message']))); return json_encode($data); } return Redirect::to(ADM_URI . '/themes')->with($this->data); } if (!isset($theme_info->layout) or empty($theme_info->layout)) { $theme_info->layout = $theme_info->layer == 'backend' ? 'admin' : 'application'; } //Check for layout $layout_data = ''; // Full path to our layout file $layout_path = $theme_path . 'layouts' . DS; $layout_data = ''; // Check for normal php extention // themes/layouts/layoutfile.php if (file_exists($path = $layout_path . $theme_info->layout . EXT)) { $layout_data = File::get($path); } elseif (file_exists($path = $layout_path . $theme_info->layout . BLADE_EXT)) { $layout_data = File::get($path); } //themes/layouts/[layer]/layoutfile.php $layout_path = $theme_path . 'layouts' . DS . $theme_info->layer . DS; if (file_exists($path = $layout_path . $theme_info->layout . EXT)) { $layout_data = File::get($path); } elseif (file_exists($path = $layout_path . $theme_info->layout . BLADE_EXT)) { $layout_data = File::get($path); } if (empty($layout_data)) { $this->data['message'] = __('themes::lang.Layout file is empty or not found')->get(ADM_LANG); $this->data['message_type'] = 'error'; if (Request::ajax()) { $data = array('flash_message' => array('message_type' => $this->data['message_type'], 'messages' => array($this->data['message']))); return json_encode($data); } return Redirect::to(ADM_URI . '/themes')->with($this->data); } $new_theme = Themes\Model\Theme::where('slug', '=', $theme_info->slug)->first(); if (!is_null($new_theme)) { $this->data['message'] = __('themes::lang.Other theme with this same name is already installed')->get(ADM_LANG); $this->data['message_type'] = 'error'; if (Request::ajax()) { $data = array('flash_message' => array('message_type' => $this->data['message_type'], 'messages' => array($this->data['message']))); return json_encode($data); } return Redirect::to(ADM_URI . '/themes')->with($this->data); } $new_theme = new \Themes\Model\Theme(); $new_theme->name = (isset($theme_info->name) and !empty($theme_info->name)) ? $theme_info->name : 'No name provided'; $new_theme->slug = $theme_info->slug; $new_theme->description = (isset($theme_info->description) and !empty($theme_info->description)) ? $theme_info->description : 'No description provided'; $new_theme->layout = $theme_info->layout; $new_theme->layout_default = $layout_data; $new_theme->layout_content = $layout_data; $new_theme->author = (isset($theme_info->author) and !empty($theme_info->author)) ? $theme_info->author : 'Unknown'; $new_theme->version = (isset($theme_info->version) and !empty($theme_info->version)) ? $theme_info->version : '0.0'; $new_theme->layer = $theme_info->layer; $new_theme->is_core = !isset($theme_info->is_core) ? 0 : $theme_info->is_core; $new_theme->installed = 1; $new_theme->save(); $this->data['message'] = __('themes::lang.Theme was successfully installed', array('theme_slug' => $theme_slug))->get(ADM_LANG); $this->data['message_type'] = 'success'; $theme_page = $theme_info->layer == 'frontend' ? '' : '/backend'; return Redirect::back()->with($this->data); }