Example #1
0
 public function get_doc_page_by_site_id($site_id)
 {
     $docs = array();
     $doc_sercice = Mydoc::instance();
     $request_struct = array('where' => array('site_id' => $site_id));
     $docs = $doc_sercice->lists($request_struct);
     return $docs;
 }
Example #2
0
 /**
  * 批量删除文案
  */
 public function batch_delete()
 {
     //初始化返回数据
     $return_data = array();
     //请求结构体
     $request_data = array();
     try {
         $doc_ids = $this->input->post('doc_ids');
         if (is_array($doc_ids) && count($doc_ids) > 0) {
             /* 删除失败的 */
             $failed_doc_names = '';
             /* 执行操作 */
             foreach ($doc_ids as $doc_id) {
                 if (!Mydoc::instance($doc_id)->delete()) {
                     $failed_doc_names .= ' | ' . $doc_id;
                 }
             }
             if (empty($failed_doc_names)) {
                 throw new MyRuntimeException(Kohana::lang('o_site.delete_doc_success'), 403);
             } else {
                 /* 中转提示页面的停留时间 */
                 $return_struct['action']['time'] = 10;
                 $failed_doc_names = trim($failed_doc_names, ' | ');
                 throw new MyRuntimeException(Kohana::lang('o_site.delete_doc_error', $failed_doc_names), 403);
             }
         } else {
             throw new MyRuntimeException(Kohana::lang('o_global.data_load_error'), 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;
         }
     }
 }
Example #3
0
 /**
  * init site data
  * 
  * @param int $site_id
  * @param int $site_type_id
  * @return boolean
  */
 public static function doc_init($site_id, $site_type_id = 0)
 {
     $type = 'default';
     if ($site_type_id) {
         $type = $site_type_id;
     }
     $permalink = kohana::config("doc.{$type}.permalink");
     $name = kohana::config("doc.{$type}.name");
     foreach ($permalink as $key => $value) {
         $doc = Mydoc::instance()->get_by_permalink($value, $site_id);
         $content = kohana::config("doc.{$type}.{$value}");
         $data = array();
         $data['title'] = $name[$key];
         $data['permalink'] = $value;
         $data['content'] = $content;
         $data['site_id'] = $site_id;
         if ($doc['id']) {
             Mydoc::instance($doc['id'])->edit($data);
         } else {
             Mydoc::instance()->add($data);
         }
     }
 }
Example #4
0
 public static function parse($current_uri)
 {
     $current_uri = trim($current_uri);
     if (empty($current_uri)) {
         return FALSE;
     }
     $site_id = Mysite::instance()->id();
     // 尝试解析 doc
     $doc_uris = Mydoc::get_uris($site_id);
     if (isset($doc_uris[$current_uri])) {
         return '/doc/view/' . $current_uri;
     }
     $route_type = Myroute::instance()->type();
     $category_suffix = Myroute::instance()->get_action('category_suffix');
     $category_key = Myroute::instance()->get_action('category');
     $categorys = CategoryService::get_instance()->get_uri_name();
     // 尝试解析 category
     $arguments = explode('/', $current_uri);
     switch ($route_type) {
         case 0:
             // www.example.com/category/1.html/page/2
             if ($arguments[0] === $category_key and isset($arguments[1])) {
                 if (!empty($category_suffix)) {
                     $arguments[1] = substr($arguments[1], 0, strlen($arguments[1]) - strlen($category_suffix));
                 }
                 if (preg_match('/^\\d+$/', $arguments[1])) {
                     $result = 'category/index/' . $arguments[1];
                     for ($i = 2; isset($arguments[$i]); $i++) {
                         $result .= '/' . $arguments[$i];
                     }
                     return $result;
                 }
             }
             break;
         case 1:
             // www.example.com/category/xxxxx.html/page/2
             if ($arguments[0] === $category_key and isset($arguments[1])) {
                 if (!empty($category_suffix)) {
                     $arguments[1] = substr($arguments[1], 0, strlen($arguments[1]) - strlen($category_suffix));
                 }
                 if (isset($categorys[$arguments[1]])) {
                     $result = 'category/index/' . $arguments[1];
                     for ($i = 2; isset($arguments[$i]); $i++) {
                         $result .= '/' . $arguments[$i];
                     }
                     return $result;
                 }
             }
             break;
         case 2:
             // www.example.com/xxxxx.html/page/2
             if (count($arguments) == 1 or count($arguments) > 2) {
                 if (!empty($category_suffix)) {
                     $arguments[0] = substr($arguments[0], 0, strlen($arguments[0]) - strlen($category_suffix));
                 }
                 if (isset($categorys[$arguments[0]])) {
                     $result = 'category/index/' . $arguments[0];
                     for ($i = 1; isset($arguments[$i]); $i++) {
                         $result .= '/' . $arguments[$i];
                     }
                     return $result;
                 }
             }
             break;
         case 3:
             // www.example.com/xxxxx/ooooo.html/page/2
             for ($i = 0; isset($arguments[$i]); $i++) {
                 if (!isset($categorys[$arguments[$i]])) {
                     break;
                 }
             }
             if ($i == 0) {
                 break;
             }
             if (empty($category_suffix)) {
                 $i--;
             }
             $count = count($arguments) - $i;
             if ($count == 1 or $count > 2) {
                 if (!empty($category_suffix)) {
                     $arguments[$i] = substr($arguments[$i], 0, strlen($arguments[$i]) - strlen($category_suffix));
                 }
                 $result = 'category/index/' . $arguments[$i];
                 for ($i = $i + 1; isset($arguments[$i]); $i++) {
                     $result .= '/' . $arguments[$i];
                 }
                 return $result;
             }
             break;
         case 4:
             // www.example.com/xxxxx.html/page/2
             if (count($arguments) == 1 or count($arguments) > 2) {
                 if (!empty($category_suffix)) {
                     $arguments[0] = substr($arguments[0], 0, strlen($arguments[0]) - strlen($category_suffix));
                 }
                 if (isset($categorys[$arguments[0]])) {
                     $result = 'category/index/' . $arguments[0];
                     for ($i = 1; isset($arguments[$i]); $i++) {
                         $result .= '/' . $arguments[$i];
                     }
                     return $result;
                 }
             }
             break;
     }
     $product_suffix = Myroute::instance()->get_action('product_suffix');
     $product_key = Myroute::instance()->get_action('product');
     // 尝试解析  product
     $arguments = explode('/', $current_uri);
     switch ($route_type) {
         case 0:
             // www.example.com/product/220.html
             if ($arguments[0] === $product_key and isset($arguments[1])) {
                 if (!empty($product_suffix)) {
                     $arguments[1] = substr($arguments[1], 0, strlen($arguments[1]) - strlen($product_suffix));
                 }
                 if (preg_match('/^\\d+$/', $arguments[1])) {
                     return 'product/get/' . $arguments[1];
                 }
             }
             break;
         case 1:
             // www.example.com/product/yyyyy.html
             if ($arguments[0] === $product_key and isset($arguments[1])) {
                 if (!empty($product_suffix)) {
                     $arguments[1] = substr($arguments[1], 0, strlen($arguments[1]) - strlen($product_suffix));
                 }
                 return 'product/get/' . $arguments[1];
             }
             break;
         case 2:
             // www.example.com/xxxxx/yyyyy.html
             if (isset($categorys[$arguments[0]]) and isset($arguments[1])) {
                 if (!empty($product_suffix)) {
                     $arguments[1] = substr($arguments[1], 0, strlen($arguments[1]) - strlen($product_suffix));
                 }
                 return 'product/get/' . $arguments[1];
             }
             break;
         case 3:
             // www.example.com/xxxxx/ooooo/yyyyy.html
             for ($i = 0; isset($arguments[$i]); $i++) {
                 if (!isset($categorys[$arguments[$i]])) {
                     break;
                 }
             }
             if ($i > 0 and isset($arguments[$i])) {
                 if (!empty($product_suffix)) {
                     $arguments[$i] = substr($arguments[$i], 0, strlen($arguments[$i]) - strlen($product_suffix));
                 }
                 return 'product/get/' . $arguments[$i];
             }
             break;
         case 4:
             // www.example.com/product/yyyyy.html
             if ($arguments[0] === $product_key and isset($arguments[1])) {
                 if (!empty($product_suffix)) {
                     $arguments[1] = substr($arguments[1], 0, strlen($arguments[1]) - strlen($product_suffix));
                 }
                 return 'product/get/' . $arguments[1];
             }
             break;
     }
     return FALSE;
 }
Example #5
0
 /**
  * 编辑文案链接导航
  */
 public function doc_menu_edit($id)
 {
     $site_menu = Mysite_menu::instance($id);
     $site_menu_data = $site_menu->get();
     /* 得到导航列表并删除自身及自身的子目录 */
     $child_ids = array();
     $site_menus = Mysite_menu::instance()->site_menu_queue();
     $temp = Mysite_menu::instance()->site_menu_queue($id);
     foreach ($temp as $val) {
         $child_ids[] = $val['id'];
     }
     foreach ($site_menus as $key => $value) {
         if ($value['id'] == $id || in_array($value['id'], $child_ids)) {
             unset($site_menus[$key]);
         }
     }
     if ($_POST) {
         //标签过滤
         tool::filter_strip_tags($_POST);
         /* 获取要添加的导航的level_depth*/
         $data = $_POST;
         $parent_id = $this->input->post('parent_id');
         if ($parent_id == 0) {
             $data['level_depth'] = 1;
         } else {
             $parent_level_depth = Mysite_menu::instance($parent_id)->get('level_depth');
             $data['level_depth'] = $parent_level_depth + 1;
         }
         if (!Mysite_menu::instance()->child_level_depth_edit($id, $data['level_depth'], $temp)) {
             remind::set(Kohana::lang('o_global.update_error'), 'site/menu');
         }
         /* 获取文案的url*/
         $doc_id = $this->input->post('doc_id');
         $doc_permalink = Mydoc::instance($doc_id)->get('permalink');
         $data['url'] = $doc_permalink;
         /* 标志导航类型*/
         $data['memo'] = 'doc';
         $data['type'] = $this->MENU_TYPE_DOC;
         $data['relation_id'] = $doc_id;
         if ($site_menu->site_menu_edit($site_menu_data['id'], $data)) {
             remind::set(Kohana::lang('o_global.update_success'), 'site/menu/', 'success');
         } else {
             remind::set(Kohana::lang('o_global.update_error'), 'site/menu');
         }
     }
     $site_docs = Mydoc::instance()->site_docs();
     //$permalink = trim($site_menu_data['url'],'/');
     //$doc_now = Mydoc::instance()->get_by_permalink($permalink);
     $doc_id_now = $site_menu_data['relation_id'];
     $this->template->content = new View("site/doc_menu_edit");
     $this->template->content->site_menus = $site_menus;
     $this->template->content->site_docs = $site_docs;
     $this->template->content->site_menu_data = $site_menu_data;
     $this->template->content->doc_id_now = $doc_id_now;
 }
Example #6
0
 /**
  * init site doc default data
  */
 public function init($type = 0)
 {
     $data = array();
     $data['title'] = 'about us';
     $data['permalink'] = 'about-us';
     $data['content'] = 'about us';
     Mydoc::instance()->add($data);
 }