Results 11 to 20 of 270

Thread: Объектно-ориентированный PHP5 рулит!

Threaded View

  1. #1
    подниматель пингвинов crazy-mike's Avatar
    Join Date
    Nov 2006
    Location
    L'viv
    Posts
    179,963

    Default Объектно-ориентированный PHP5 рулит!

    <?
    //
    // CopyLeft by Me
    //
    abstract class xhtmlObj {
    abstract public function is(); abstract public function add(xhtmlObj $v);
    }


    class javaScript extends xhtmlObj {
    private $p;
    public function __construct($v="") { $this->p='<script type="text/javascript" language="Javascript">'; $this->p.="\n"; $this->p.="// <![CDATA[\n"; $this->p.=$v;
    }

    final public function cat($v)
    { $this->p.="\n".$v;
    }

    final public function add(xhtmlObj $v)
    { $this->p.=$v->is();
    }

    final public function is()
    { $q=$this->p;
    $q.="\n";
    $q.="// ]]>\n";
    $q.='</script>'; return $q;
    }
    }

    class xhtmlHead extends xhtmlObj {
    private $p;

    public function __construct($tit) {
    $this->p='<head>';
    $this->p='<meta http-equiv="Content-Type" content="text/html; ';
    $this->p.=' charset=koi8-u; lang=uk">';
    $this->p.='<title>'.$tit.'</title>';
    }

    final public function add(xhtmlObj $v)
    { $this->p.=$v->is();
    }

    final public function is()
    { $q=$this->p.'</head>'; return $q;
    }

    }

    class xhtmlBody extends xhtmlObj {
    private $p;

    public function __construct($zclass="",$style="",$onload="")
    { $this->p='<body ';
    if($zclass!='') $this->p.='class="'.$zclass.'" ';
    if($style!='') $this->p.='style="'.$style.'" ';
    if($onload!='') $this->p.='onload="'.$onload.'" ';
    $this->p.='>';
    }

    final public function cat($v)
    { $this->p.=$v;
    }

    final public function add(xhtmlObj $v)
    { $this->p.=$v->is();
    }

    final public function is()
    { $q=$this->p.'</body>'; return $q;
    }
    }

    class xhtmlTag extends xhtmlObj {
    private $p;
    private $ztag;
    private $attr;
    private $addon;

    function __construct($v,$qv=NULL)
    { $this->ztag=$v; $this->attr=array();
    $this->p=''; if($qv!=NULL) $this->p=$qv;
    $this->addon='';
    }

    final public function setA($name,$val)
    { $this->attr[$name]=$val;
    }

    final public function setC($val)
    { $this->addon.=' '.$val;
    }

    final public function cat($v)
    { $this->p.=$v;
    }


    final public function add(xhtmlObj $v)
    { $this->p.=$v->is();
    }

    final public function is()
    { $au=array_keys($this->attr);
    $n=count($au);
    $i=0; $d2='</'.$this->ztag.'>';
    $d1='<'.$this->ztag;
    while($i<$n) { $k=$au[$i]; $v=$this->attr[$k];
    $d1.=' '.$k.'="'.$v.'"'; $i++;
    };
    $d1.=$this->addon;
    if($this->p=='') { $d1.=' />'; $q=$d1; }
    else {
    $d1.=" >"; $q=$d1.$this->p.$d2;
    };
    return $q;
    }

    }

    class xhtml extends xhtmlObj {
    private $p;

    public function __construct($v)
    { $this->p=$v;
    }

    final public function add(xhtmlObj $v)
    { $this->p.=$v->is();
    }

    final public function is()
    { $q=$this->p; return $q;
    }
    }

    class xhtmlPage extends xhtmlObj {
    public $p;

    private function prologue() {
    $this->p='<?xml version="1.0" encoding="koi8-u" ?>';
    $this->p.='<!DOCTYPE HTML PUBLIC ';
    $this->p.='"-//W3C/DTD XHTML 1.0 Transitional//EN" ';
    $this->p.='"http://www.w3.org/TR/xhtmml1/DTD/xhtml1-transitional.dtd">';
    $this->p.='<html xmlns=http://www.w3.org/1999/xhtml xml:lang="uk" lang="uk">';
    }

    public function __construct(xhtmlHead $a=NULL,xhtmlBody $b=NULL)
    { $this->prologue();
    if($a!=NULL) $this->add($a);
    if($b!=NULL) $this->add($b);
    }

    public function is()
    { $q = $this->p.'</html>';
    return $q;
    }

    final public function add(xhtmlObj $v)
    { $this->p.=$v->is();
    }

    final public function see()
    { echo $this->is();
    }
    }

    class xhtmlStyle extends xhtmlTag {
    public function __construct($v) {
    xhtmlTag::__construct('style');
    $this->setA('type','text/css');
    $this->setA('media','all');
    $this->cat($v);
    }
    }

    class xhtmlImg extends xhtmlTag {
    public function __construct($fn)
    { xhtmlTag::__construct('img');
    $this->setA('src',$fn);
    }
    }

    class xhtmlA extends xhtmlTag {
    public function __construct($href,$txt='')
    { xhtmlTag::__construct('a',$txt);
    $this->setA('href',$href);
    }
    }

    ?>

    Можно вообще спрятать html !!!!!
    ;)
    Например вот так:
    <?
    require "../../xobj/myhtml.php";
    $p=new xhtmlPage();
    $p->add(new xhtmlHead("Hello!"));
    $b=new xhtmlBody("","background :yellow;","");
    $b->add(new xhtmlTag("b","Hello,world!"));
    $p->add($b); $p->see();
    ?>
    Last edited by crazy-mike; 09-27-2007 at 03:31 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Russian America Top. Рейтинг ресурсов Русской Америки. Terms of Service | Privacy Policy Рейтинг@Mail.ru