Ejemplo n.º 1
0
 /**
  * init site data
  * 
  * @param int $site_id
  * @param int $theme_id
  * @return boolean
  */
 public static function init($site_id, $theme_id = 1)
 {
     $type = 0;
     //doc default info
     //Mydoc::instance()->init($site_id);
     site::doc_init($site_id);
     //faq default info
     Myfaq::instance()->init($site_id);
     //seo default info
     Myseo::instance()->init($site_id);
     //route default info
     Myroute::instance()->init($site_id);
     //menu default info
     Mysite_menu::instance()->init($site_id);
     //theme default info
     Mytheme::instance($theme_id)->init($site_id);
     //mail default info
     Mymail::instance()->init($site_id);
     //product default info
     //Mydata_import::instance()->import($site_id);
 }
Ejemplo n.º 2
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'));
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * get site data
  *
  * @param Array $query_struct
  * @param Array $orderby
  * @param Int $limit
  * @param Int $offset
  * @return Array
  */
 private function _data($query_struct = array(), $orderby = NULL, $limit = 1000, $offset = 0)
 {
     $list = array();
     $where = array();
     $like = array();
     $in = array();
     $site = ORM::factory('site');
     //WHERE
     if (count($query_struct) > 0) {
         if (isset($query_struct['where'])) {
             foreach ($query_struct['where'] as $key => $value) {
                 $where[$key] = $value;
             }
         }
     }
     //LIKE
     if (count($query_struct) > 0) {
         if (isset($query_struct['like'])) {
             foreach ($query_struct['like'] as $key => $value) {
                 $like[$key] = $value;
             }
         }
     }
     //IN
     if (count($query_struct) > 0) {
         if (isset($query_struct['in'])) {
             foreach ($query_struct['in'] as $key => $value) {
                 $in[$key] = $value;
             }
         }
     }
     //WHERE
     if (count($where) > 0) {
         $site->where($where);
     }
     //LIKE
     if (count($like) > 0) {
         $site->like($like);
     }
     //IN
     if (count($in) > 0) {
         foreach ($in as $key => $value) {
             $site->in($key, $value);
         }
     }
     if (!empty($orderby)) {
         $site->orderby($orderby);
     }
     $orm_list = $site->find_all($limit, $offset);
     if ($this->union_query) {
         foreach ($orm_list as $item) {
             $merge_arr = array('site_type_name' => Mysite_type::instance($item->site_type_id)->get('name'), 'theme_name' => Mytheme::instance($item->theme_id)->get('name'));
             $list[] = array_merge($item->as_array(), $merge_arr);
         }
     } else {
         foreach ($orm_list as $item) {
             $list[] = $item->as_array();
         }
     }
     return $list;
 }
Ejemplo n.º 4
0
 /**
  * 删除模板
  * @param int $id
  */
 public function delete($id = 0)
 {
     // 初始化返回数据
     $return_data = array();
     //请求结构体
     $request_data = array();
     try {
         if ($id <= 0) {
             throw new MyRuntimeException(Kohana::lang('o_global.data_load_error'), 403);
         }
         $theme = Mytheme::instance($id);
         if ($theme->delete($id)) {
             throw new MyRuntimeException(Kohana::lang('o_manage.delete_theme_success'), 403);
         } else {
             throw new MyRuntimeException(Kohana::lang('o_manage.manage_theme_delete_failed_by_site'), 403);
         }
     } catch (MyRuntimeException $ex) {
         $return_struct['status'] = 0;
         $return_struct['code'] = $ex->getCode();
         $return_struct['msg'] = $ex->getMessage();
         //TODO 异常处理
         //throw $ex;
         if ($this->is_ajax_request()) {
             $this->template = new View('layout/empty_html');
             $this->template->content = $return_struct['msg'];
         } else {
             $this->template->return_struct = $return_struct;
             $content = new View('info');
             $this->template->content = $content;
             /* 请求结构数据绑定 */
             $this->template->content->request_data = $request_data;
             /* 返回结构体绑定 */
             $this->template->content->return_struct = $return_struct;
         }
     }
 }