Example #1
0
 public function index()
 {
     $site_id = 1;
     $theme_id = 2;
     $server = Storage_server::instance();
     $filename = $this->input->get('filename');
     $theme_views = $server->get_site_themes($site_id, $theme_id, 'views');
     $theme_js = $server->get_site_themes($site_id, $theme_id, 'js');
     $theme_css = $server->get_site_themes($site_id, $theme_id, 'css');
     if (in_array($filename, $theme_views)) {
         $type = 'views';
     } else {
         if (in_array($filename, $theme_js)) {
             $type = 'js';
         } else {
             if (in_array($filename, $theme_css)) {
                 $type = 'css';
             } else {
                 $type = 'views';
                 $filename = 'index.php';
             }
         }
     }
     if ($_POST) {
         $file = $_POST['file'];
         $server->cache_site_theme($site_id, $theme_id, $type, $filename, $file);
         remind::set('add ' . $_POST['file'], url::current(TRUE));
     }
     $code = $server->get_site_theme($site_id, $theme_id, $type, $filename);
     $this->template->content = new View("site/theme_edit");
     $this->template->content->theme_files = array_merge($theme_views, $theme_js, $theme_css);
     $this->template->content->data = $code;
     $this->template->content->filename = $filename;
 }
Example #2
0
 /**
  * 清理指定主题的资源信息
  * @param int $theme_id 主题ID
  */
 public function clear_theme($theme_id = 0)
 {
     $img_id = $this->img_dir_name . $theme_id;
     $this->clear_theme_img($img_id);
     return true;
     $server = Storage_server::instance();
     // views
     $theme_views = $server->get_themes($theme_id, 'views');
     if ($theme_views) {
         foreach ($theme_views as $item) {
             $server->delete_theme($theme_id, 'views', $item);
         }
     }
     // js
     $theme_js = $server->get_themes($theme_id, 'js');
     if ($theme_js) {
         foreach ($theme_js as $item) {
             $server->delete_theme($theme_id, 'js', $item);
         }
     }
     // css
     $theme_css = $server->get_themes($theme_id, 'css');
     if ($theme_css) {
         foreach ($theme_css as $item) {
             $server->delete_theme($theme_id, 'css', $item);
         }
     }
     // images
     $theme_images = $server->get_themes($theme_id, 'images');
     if ($theme_images) {
         foreach ($theme_images as $item) {
             $server->delete_theme($theme_id, 'images', $item);
         }
     }
     return true;
 }
Example #3
0
 /**
  * 单体配置站点的全局配置
  */
 public function theme_single_config()
 {
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented');
     $key = $this->input->get('key');
     if (empty($key)) {
         $return_struct['code'] = 400;
         $return_struct['msg'] = Kohana::lang('o_global.bad_request');
         exit(json_encode($return_struct));
     }
     //站点信息
     $site = Mysite::instance($this->site_id)->get();
     if (!$site['id']) {
         $return_struct['code'] = 400;
         $return_struct['msg'] = Kohana::lang('o_global.access_denied');
         exit(json_encode($return_struct));
     }
     //站点详细信息
     $site_detail = Mysite::instance($this->site_id)->detail();
     //模板详情
     $theme = Mytheme::instance($site['theme_id'])->get();
     //模板配置
     $theme_configs = empty($theme['config']) ? array() : unserialize($theme['config']);
     //站点模板配置
     $site_theme_configs = empty($site_detail['theme_config']) ? array() : unserialize($site_detail['theme_config']);
     //得到站点模板标签的配置情况,如果站点中无配置则使用全局模板的配置
     $configs = empty($site_theme_configs) ? $theme_configs : tool::multimerge($theme_configs, $site_theme_configs);
     if (!count($configs)) {
         $return_struct['code'] = 400;
         $return_struct['msg'] = Kohana::lang('o_global.access_denied');
         exit(json_encode($return_struct));
     }
     //判断请求,处理业务逻辑
     if (request::is_ajax()) {
         $return_template = $this->template = new View('template_blank');
         //KEY对应的配置信息
         $data = array();
         $data['name'] = '';
         $data['val'] = '';
         $data['type'] = '';
         $data['key'] = '';
         if (isset($configs['name'][$key])) {
             $data['name'] = $configs['name'][$key];
             $data['val'] = htmlentities($configs['val'][$key]);
             $data['type'] = $configs['type'][$key];
             $data['description'] = $configs['desc'][$key];
             $data['key'] = $key;
         } else {
             $return_struct['code'] = 400;
             $return_struct['msg'] = Kohana::lang('o_global.bad_request');
             exit(json_encode($return_struct));
         }
         $this->template->content = new View('site/theme_single_config');
         $this->template->content->key = $key;
         $this->template->content->data = $data;
         $return_str = $return_template->render();
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['msg'] = 'Success';
         $return_struct['content'] = $return_str;
         exit(json_encode($return_struct));
     } else {
         if ($_POST) {
             //资源名称
             $name = $this->input->post('config_name');
             //图片链接
             $url = $this->input->post('img_url');
             //图片链接
             $alt = $this->input->post('img_alt');
             //资源类型
             $config_type = $this->input->post('config_type_value');
             //资源文件最大大小(default:1M)
             $file_max_size = kohana::config('theme.file_max_size');
             $file_max_size = $file_max_size > 0 ? $file_max_size : 1048576;
             //根据类型来选取相应的内容
             switch ($config_type) {
                 case 2:
                     if ($val = $_FILES['img_val']['name']) {
                         $file_type = kohana::config('theme.image_file_type');
                         $type = count($file_type) > 0 ? $file_type : array('jpg');
                         //判断文件类型
                         if (!in_array(strtolower(tool::fileext($_FILES['img_val']['name'])), $type)) {
                             remind::set(Kohana::lang('o_site.pic_type_incorrect'), '/manage/theme/config_edit/' . $id . '?key=' . $key);
                         }
                         $val = $_FILES['img_val']['name'];
                         $file_size = filesize($_FILES['img_val']['tmp_name']);
                         if ($file_size > $file_max_size) {
                             remind::set(Kohana::lang('o_site.pic_size_out_range'), '/manage/theme/config_edit/' . $id . '?key=' . $key);
                         }
                     }
                     break;
                 default:
                     $val = $this->input->post('config_val');
                     break;
             }
             //如果修改的是图片,则覆盖站点配置原有的图片
             if (!empty($val) && $config_type == 2) {
                 //文件名的存放用 键值+文件名
                 $filename = $key . '_' . $configs['val'][$key];
                 $file = file_get_contents($_FILES['img_val']["tmp_name"]);
                 //把图片存入站点图片资源
                 Storage_server::instance()->cache_site_theme($site['id'], $site['theme_id'], 'images', $filename, $file);
             } elseif ($config_type == 2) {
                 if (!isset($site_theme_configs['val'][$key])) {
                     $filename = $key . '_' . $configs['val'][$key];
                     $file = Storage_server::instance()->get_theme($site['theme_id'], 'images', $filename);
                     Storage_server::instance()->cache_site_theme($site['id'], $site['theme_id'], 'images', $filename, $file);
                 }
             }
             //内容可以不更改,如果为空则使用原有内容
             $site_theme_configs['val'][$key] = $configs['val'][$key] = $config_type == 2 ? $configs['val'][$key] : $val;
             $site_theme_configs['val'][$key] = stripslashes($site_theme_configs['val'][$key]);
             $site_theme_configs['val'][$key] = strip_tags($site_theme_configs['val'][$key], '<br><p><span><div>');
             $alt = htmlentities($alt);
             $site_theme_configs['name'][$key] = $configs['name'][$key] = $name;
             $site_theme_configs['type'][$key] = $configs['type'][$key] = $config_type;
             $site_theme_configs['desc'][$key] = $configs['desc'][$key] = array('url' => $url, 'alt' => $alt);
             //var_dump($site_theme_configs);exit;
             $data['theme_config'] = serialize($site_theme_configs);
             if (Mysite_detail::instance()->update_by_site_id($this->site_id, $data)) {
                 remind::set(Kohana::lang('o_global.update_success'), 'site/config/theme', 'success');
             } else {
                 remind::set(Kohana::lang('o_global.update_error'), 'site/config');
             }
         } else {
             die(Kohana::lang('o_global.access_denied'));
         }
     }
 }
Example #4
0
 public function do_edit()
 {
     //收集请求
     $request = $this->input->post();
     $id = $request['id'];
     // 验证 - 数据有效性
     $category = Mycategory::instance($id)->get();
     if (!$category['id'] || $category['virtual'] != 1) {
         remind::set(Kohana::lang('o_global.access_denied'), request::referrer(), 'error');
     }
     // 权限检测
     $site_id_list = role::check('product_virtual_category', 0, 0);
     // 权限验证
     if (!in_array($category['site_id'], $site_id_list)) {
         remind::set(Kohana::lang('o_global.access_denied'), request::referrer(), 'error');
     }
     // 修整 输入数据
     if (isset($request['date_add'])) {
         unset($request['date_add']);
     }
     if (isset($request['position'])) {
         unset($request['position']);
     }
     $request['date_upd'] = date('Y-m-d H:i:s');
     $request['site_id'] = $category['site_id'];
     if (Mycategory::instance($id)->virtual_edit($request)) {
         if ($_FILES['imagefile']['name']) {
             if ($_FILES["imagefile"]["error"] == 0) {
                 $image_data = array();
                 $image_data['image'] = 'category_' . $id . '.jpg';
                 $file = file_get_contents($_FILES["imagefile"]["tmp_name"]);
                 $type = 'images';
                 Storage_server::instance()->cache_category($category['site_id'], $type, $image_data['image'], $file);
                 //更新图片名
                 Mycategory::instance($id)->edit($image_data);
             }
         }
         remind::set(Kohana::lang('o_global.update_success'), 'product/virtualcategory', 'success');
     } else {
         remind::set(Kohana::lang('o_global.update_error'), request::referrer(), 'error');
     }
 }