Advertisement
wandrake

Untitled

Mar 4th, 2012
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.94 KB | None | 0 0
  1. <?php
  2.     class Element {
  3.         protected $_id;
  4.         protected $_classes = array();
  5.         protected $_style = array();
  6.        
  7.         protected $_elements = array();
  8.         protected $_idx = 0;
  9.        
  10.         public function addClass($class) {
  11.             $this->_classes[] = $class;
  12.         }
  13.        
  14.         public function setId($id) {
  15.             $this->_id = $id;
  16.         }
  17.        
  18.         protected function hasClassAttr() {
  19.             $ret = false;
  20.        
  21.             if ($this->getClassAttr() != "") $ret = true;
  22.        
  23.             return $ret;
  24.         }
  25.        
  26.         protected function getClassAttr() {
  27.             $class_attr = "";
  28.            
  29.             if (count($this->_classes)) {
  30.                 $class_attr = 'class="';
  31.                
  32.                 foreach ($this->_classes as $class) {
  33.                     $class_attr .= "$class ";
  34.                 }
  35.                
  36.                 $class_attr  = rtrim($class_attr);
  37.                 $class_attr .= '"';
  38.             }
  39.            
  40.             /*if ($class_attr == "") return false;
  41.             else return $class_attr;*/
  42.             return $class_attr;
  43.        
  44.         }
  45.        
  46.         protected function hasIdAttr() {
  47.             $ret = false;
  48.        
  49.             if ($this->getIdAttr() != "") $ret = true;
  50.            
  51.             return $ret;
  52.         }
  53.        
  54.         protected function getIdAttr() {
  55.             $id_attr = "";
  56.            
  57.             if ($this->_id != "") {
  58.                 $id_attr = sprintf('id="%s"', $this->_id);
  59.             }
  60.            
  61.             /* if ($id_attr == "") return false;
  62.             else return $id_attr; */
  63.             return $id_attr;
  64.         }
  65.        
  66.         protected function hasStyleAttr() {
  67.             $ret = false;
  68.        
  69.             if ($this->getStyleAttr() != "") $ret = true;
  70.        
  71.             return $ret;
  72.         }
  73.        
  74.         protected function getStyleAttr() {
  75.             $style_attr = "";
  76.            
  77.             if (count($this->_style)) {
  78.                 $style_attr = 'style="';
  79.                
  80.                 foreach ($this->_style as $key => $value) {
  81.                     $style_attr .= "$key: $value; ";
  82.                 }
  83.                
  84.                 $style_attr  = rtrim($style_attr);
  85.                 $style_attr .= '"';
  86.             }
  87.            
  88.             /*if ($class_attr == "") return false;
  89.             else return $class_attr;*/
  90.             return $style_attr;
  91.         }
  92.        
  93.        
  94.         public function addStyle($attr, $value) {
  95.             $this->_style[$attr] = $value;
  96.         }
  97.        
  98.         public function html() {
  99.             return "";
  100.         }
  101.        
  102.         public function show() {
  103.             echo $this->html();
  104.         }
  105.        
  106.         public function add($element) {
  107.             $this->_elements[$this->_idx] = $element;
  108.             $this->_idx++;
  109.         }
  110.     }
  111. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement