![]() |
- Developper API
2.0.5
|
00001 <?php 00011 class WEObject 00012 { 00013 private $title; 00014 private $url; 00015 private $text; 00016 private $category; 00017 private $date; 00018 00019 private static $xmlNodesName = array( 00020 "title", 00021 "url", 00022 "text", 00023 "category", 00024 "date" 00025 ); 00026 00036 public function __construct($title,$url,$text,$category,$date) 00037 { 00038 $this->title = $title; 00039 $this->url = $url; 00040 $this->text = $text; 00041 $this->category = $category; 00042 $this->date = $date; 00043 } 00044 00049 public final function getTitle() 00050 { 00051 return (!empty($this->title)) ? $this->title : false; 00052 } 00053 00058 public final function getURL() 00059 { 00060 return (!empty($this->url)) ? $this->url : false; 00061 } 00062 00067 public final function getText() 00068 { 00069 return (!empty($this->text)) ? $this->text : false; 00070 } 00071 00076 public final function getCategory() 00077 { 00078 return (!empty($this->category)) ? $this->category : false; 00079 } 00080 00085 public final function getDate() 00086 { 00087 return (!empty($this->date)) ? $this->date : false; 00088 } 00089 00095 public final static function getWEObjectFromSXMLElement($node) 00096 { 00097 if(!WEObject::isSXMLNodeProperty($node)) 00098 { 00099 error("WEObject Property creation failed for element: ".$node->getName()); 00100 return false; 00101 } 00102 00103 $title = $node->xpath("title"); 00104 if(count($title) > 0) 00105 $title = (string) $title[0]; 00106 else 00107 $title = ""; 00108 00109 $url = $node->xpath("url"); 00110 if(count($url) > 0) 00111 $url = (string) $url[0]; 00112 else 00113 $url = ""; 00114 00115 $text = $node->xpath("text"); 00116 if(count($text) > 0) 00117 $text = (string) $text[0]; 00118 else 00119 $text = ""; 00120 00121 $category = $node->xpath("category"); 00122 if(count($category) > 0) 00123 $category = (string) $category[0]; 00124 else 00125 $category = ""; 00126 00127 $date = $node->xpath("date"); 00128 if(count($date) > 0) 00129 $date = (string) $date[0]; 00130 else 00131 $date = ""; 00132 00133 $property = new WEObject($title,$url,$text,$category,$date); 00134 return $property; 00135 } 00136 00142 public final static function isSXMLNodeProperty($node) 00143 { 00144 if(!hasChildren($node)) 00145 return false; 00146 else 00147 { 00148 foreach($node->children() as $child) 00149 { 00150 $name = $child->getName(); 00151 00152 if( ! in_array($name,WEObject::$xmlNodesName) ) 00153 return false; 00154 } 00155 00156 return true; 00157 } 00158 } 00159 } 00160 ?>