<?php

/* ========================================================================
 * $Id: page.php 1671 2017-12-02 12:05:37Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onezphp.com
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
class onezphp_page extends onezphp{
  var $pagetype='list';
  var $items=array();
  function __construct(){
  }
  function init(){
    return $this;
  }
  function add($cname,&$obj){
    $cFile=dirname(__FILE__).'/classes/'.$cname.'.class.php';
    if(file_exists($cFile)){
      include_once($cFile);
      $classname='onezphp_page_item_'.$cname;
      if(class_exists($classname)){
        $obj=new $classname();
        $obj->page=$this;
        $this->items[]=$obj;
      }
    }else{
      $obj=onez('page.item.'.$cname,-1);
      $obj->page=$this;
      $this->items[]=$obj;
    }
    return $this;
  }
  function href($href, $inplugin = 0){
    $_onez=onez()->gp('_onez');
    $mod=onez()->gp('mod');
    $get=$_GET;
    parse_str($href,$info);
    unset($get['mod']);
    $get=array_merge($get,$info);
    $url=onez()->href($mod.'?'.http_build_query($get));
    return $url;
  }
  function show(){
    global $G;
    $_onez=onez()->gp('_onez');
    $mod=onez()->gp('mod');
    $cururl=$this->get('cururl');
    if(!$cururl){
      if($_onez){
        list($ptoken,$mod)=explode('|',$_onez);
        list($mod)=explode('?',$mod);
        $cururl=onez($ptoken)->href($mod);
      }else{
        $cururl=$mod;
      }
    }
    define('CUR_URL',$cururl);
    $G['title']=$this->get('title');
    foreach($this->items as $item){
      if(method_exists($item,'header')){
        $item->header();
      }
    }
    $data_before=ob_get_contents();
    ob_clean();
    onez('admin')->header();
    include(dirname(__FILE__).'/php/show.php');
    onez('admin')->footer();
  }
  function index(){
    include(dirname(__FILE__).'/php/index.php');
  }
}