📄 rdf.class.php
字号:
* @access private * @author Stefan Saasen <s@fase4.com> * @param string $data RDF File XML Data * @see _clear_Items() */ function _parse_xRDF( $data ) { $this->_clear_Items(); $xml_parser = xml_parser_create(); xml_set_object($xml_parser,$this); xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0); xml_set_element_handler($xml_parser, "_startElement", "_endElement"); xml_set_character_data_handler($xml_parser, "_parseData"); if (!xml_parse($xml_parser, trim($data))) { $this->_throw_exception(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))."<br /><br />Exception in function parse_RDF()."); } xml_parser_free($xml_parser); } /** * This Methods allows you to set the Refresh Time * * @access public * @author Stefan Saasen <s@fase4.com> * @param int $seconds time files will be cached (in seconds). * @return boolean * @see _refresh */ function set_refresh( $seconds ) { $this->_refresh = (time() - $seconds); return true; } /** * This Methods allows you to set the No. of <item>s to display * * @access public * @param int $int No of max <item>s * @author Stefan Saasen <s@fase4.com> * @return boolean * @see _max_count, _endElement() */ function set_max_item( $int ) { $this->_max_count = $int; return true; } /** * This Methods allows you to set the Cache Directory * * @access public * @author Stefan Saasen <s@fase4.com> * @param string $dir Path to Directory. * @return boolean * @see _cache_dir */ function set_CacheDir( $dir ) { if(substr($dir, -1) != "/") { $dir = $dir."/"; } $this->_cache_dir = $dir; } /** * This Method displays Error Messages and terminates the Execution of the Script * * @access private * @param string $msg Message to display on failure * @author Stefan Saasen <s@fase4.com> */ function _throw_exception( $msg ) { echo "<div style=\"font-family: verdana, helvetica, arial, sans-serif;font-size:11px; color: #6699cc;margin-top:10px;margin-bottom:10px;\" align=\"center\">fase4 RDF Error: ".$msg."</div>"; return true; } /** * This Method clears the Array containig the Items. * * @access private * @param array $array Itemarray * @author Stefan Saasen <s@fase4.com> * @see _item */ function _clear_Items( $array = "") { $this->_item = array ("title"=>"", "link"=>"", "description"=>"", "url"=>"" ); } /** * This Method clears the Array containig the Channel Items. * * @access private * @param array $array Array containing the Channel Items * @author Stefan Saasen <s@fase4.com> * @see _item */ function _clear_cItems( $array = "") { $this->_citem = array ("title"=>"", "link"=>"", "description"=>"", "url"=>"" ); } /** * XML Parser Start Element Handler * * @access private * @author Stefan Saasen <s@fase4.com> * @param mixed $parser a reference to the XML parser calling the handler. * @param string $name contains the name of the element for which this handler is called. * @param string $attrs contains an associative array with the element's attributes (if any). * @see _get_ChannelData(), _clear_Items(), _type, _parse_mode, _depth, _tags, _cdepth, _ctags */ function _startElement($parser, $name, $attrs) { // We have to determine, which type of xml data we have to parse if($name == "rss") { $this->_type = "rss"; } elseif($name == "rdf:RDF" OR $name == "rdf") { $this->_type = "rdf"; } if ( $name == "channel" AND $this->_type != "rdf" ) { $this->_parse_mode = "channel"; } elseif ( ($name=="item") ||($name=="image") ||($name=="textinput") ||(($name=="channel") && ($this->_type != "rss")) ) { if($this->_parse_mode=="channel") { $this->_get_ChannelData( $parser ); } $this->_parse_mode = "all"; } $this->_depth[$parser]++; array_push($this->_tags, $name); $this->_cdepth[$parser]++; array_push($this->_ctags, $name); } // END _startElement() /** * Retrives the Channel Data in <rss> File * * @access private * @author Stefan Saasen <s@fase4.com> * @param mixed $parser a reference to the XML parser calling the handler. * @see _output, _display_opt, _citem */ function _get_ChannelData( $parser ) { if( empty($this->_display_opt["channel"]) OR $this->_display_opt["channel"] != "hidden") { $this->_output .= "<tr><td>\n"; $this->_output .= '<table border="0" width="100%" class="fase4_rdf_meta" cellspacing="5" cellpadding="2">'."\n"; $this->_output .= "<tr><td class=\"fase4_rdf\"><div class=\"fase4_rdf_title\">".htmlspecialchars($this->_citem["title"])."</div></td></tr>\n"; $this->_output .= "<tr><td class=\"fase4_rdf\">".strip_tags($this->_citem["description"], "<a>, <img>")."</td></tr>\n"; $this->_output .= "<tr><td> </td></tr>\n"; $this->_output .= "<tr><td class=\"fase4_rdf\">\n"; if($this->_display_opt["build"] != "hidden") { if($this->_citem["lastBuildDate"]){$this->_output .= "build: ". $this->_citem["lastBuildDate"]."<br />";} } if($this->_display_opt["cache_update"] != "hidden" && ( $_update = $this->get_cache_update_time()) ) { $this->_output .= "cache update: ".$_update."<br />\n"; } $this->_output .= "<a href=\"".$this->_citem["link"]."\" "; if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } $this->_output .= ">".$this->_cut_string($this->_citem["link"])."</a>"; $this->_output .= "</td></tr>\n"; $this->_output .= "</table></td></tr>"; } $this->_array_channel = array( "title"=>$this->_citem["title"], "link"=>$this->_citem["link"], "description"=>$this->_citem["description"], "lastBuildDate"=>$this->_citem["lastBuildDate"]); } /** * XML Parser End Element Handler * * @access private * @author Stefan Saasen <s@fase4.com> * @param mixed $parser a reference to the XML parser calling the handler. * @param string $name contains the name of the element for which this handler is called. * @see _clear_Items(), _type, _parse_mode, _depth, _tags, _cdepth, _ctags, _item, _output, _display_opt */ function _endElement($parser, $name) { array_pop($this->_tags); $this->_depth[$parser]--; array_pop($this->_ctags); $this->_cdepth[$parser]--; switch ($name) { case "item": if(empty($this->_max_count) OR $this->_item_count < $this->_max_count) { if($this->_item["title"] != $this->_item["description"] AND $this->_item["description"]) { // the title link $this->_output .= "<tr><td class=\"fase4_rdf\"><a class=\"url\" href=\"".$this->_item["link"]."\" "; if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } $this->_output .= ">".strip_tags($this->_item["title"], "<a>, <img>")."</a></td></tr>\n"; // the text body $this->_output .= "<tr><td class=\"fase4_rdf\">".strip_tags($this->_item["description"], "<a>, <img>")."</td></tr>\n"; // we just display the <hr> if there is a description // <hr style=\"border-style: dotted\" noshade=\"noshade\" size=\"1\" /> $this->_output .= "<tr><td style=\"border-top: 1px dotted #999;\"> </td></tr>\n"; } else { $this->_output .= "<tr><td class=\"fase4_rdf\">\n"; $this->_output .= "<a class=\"url\" href=\"".$this->_item["link"]."\" "; if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } $this->_output .= ">".$this->_item["title"]."</a></td></tr>\n"; } $this->_array_item[] = array( "title"=>$this->_item["title"], "link"=>$this->_item["link"], "description"=>$this->_item["description"]); ++$this->_item_count; } $this->_clear_Items(); break; case "image": if($this->_display_opt["image"] != "hidden" && $this->_item["url"]) { $this->_output .= "<tr><td class=\"fase4_rdf\">\n"; $this->_output .= "<a href=\"".$this->_item["link"]."\" "; if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } $this->_output .= "><img src=\"".$this->_item["url"]."\""; if($this->_item["width"] && $this->_item["height"]) { $this->_output .= " width=\"".$this->_item["width"]."\" height=\"".$this->_item["height"]."\""; } $this->_output .= " alt=\"".$this->_item["title"]."\" border=\"0\" /></a></td></tr>\n"; $this->_array_image[] = array( "url"=>$this->_item["url"], "link"=>$this->_item["link"], "width"=>$this->_item["width"], "height"=>$this->_item["height"]); $this->_clear_Items(); } elseif( $this->_display_opt["image"] == "hidden" ) { $this->_clear_Items(); } break; case "channel": if($this->_display_opt["channel"] != "hidden" AND $this->_item["title"] != "") { $this->_output .= "<tr><td>\n"; $this->_output .= '<table border="0" width="100%" class="fase4_rdf_meta" cellspacing="5" cellpadding="2">'."\n"; $this->_output .= "<tr><td class=\"fase4_rdf\"><div class=\"fase4_rdf_title\">".htmlspecialchars($this->_item["title"])."</div></td></tr>\n"; $this->_output .= "<tr><td class=\"fase4_rdf\">".strip_tags($this->_item["description"], "<a>, <img>")."</td></tr>\n"; $this->_output .= "<tr><td> </td></tr>\n"; $this->_output .= "<tr><td class=\"fase4_rdf\">\n"; if($this->_display_opt["build"] != "hidden") { if($this->_item["lastBuildDate"]){$this->_output .= "build: ". $this->_item["lastBuildDate"]."<br />";} } if($this->_display_opt["cache_update"] != "hidden" && ( $_update = $this->get_cache_update_time()) ) { $this->_output .= "cache update: ".$_update."<br />\n"; } $this->_output .= "<a href=\"".$this->_item["link"]."\" "; if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } $this->_output .= ">".$this->_cut_string($this->_item["link"])."</a>\n"; $this->_output .= "</td></tr>\n"; $this->_output .= "</table></td></tr>\n"; } $this->_array_channel = array( "title"=>$this->_item["title"], "link"=>$this->_item["link"], "description"=>$this->_item["description"], "lastBuildDate"=>$this->_item["lastBuildDate"]); $this->_clear_Items(); $this->_clear_cItems(); break; case "textinput": if($this->_display_opt["textinput"] != "hidden" && $this->_item["name"] && $this->_item["link"]) { $this->_output .= "<tr><td class=\"fase4_rdf\">\n"; $this->_output .= "<form action=\"".$this->_item["link"]."\" "; if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } $this->_output .= "method=\"get\">\n"; $this->_output .= "<div class=\"fase4_rdf_title\">".$this->_item["title"]."</div>"; $this->_output .= strip_tags($this->_item["description"], "<a>, <img>")."<br><br>\n"; $this->_output .= "<input class=\"fase4_rdf_input\" type=\"text\" name=\"".$this->_item["name"]."\"> \n"; $this->_output .= "<input class=\"fase4_rdf_input\" type=\"submit\" value=\"go\">"; $this->_output .= "</form>\n"; $this->_output .= "</td></tr>\n"; $this->_array_textinput = array( "title"=>$this->_item["title"], "name"=>$this->_item["name"], "link"=>$this->_item["link"], "description"=>$this->_item["description"]); $this->_clear_Items(); } elseif( $this->_display_opt["textinput"] == "hidden" ) { $this->_clear_Items(); } break; } } /** * This Method returns the data from the <channel /> paragraph. * * @access public * @author Stefan Saasen <s@fase4.com> * @return array * @see _array_channel */ function get_array_channel( ) { return $this->_array_channel; } /** * This Method returns the data from each <item /> paragraph. * * @access public * @author Stefan Saasen <s@fase4.com> * @return array * @see _array_item */ function get_array_item( ) { return $this->_array_item; } /** * This Method returns the data from <textinput />. * * @access public * @author Stefan Saasen <s@fase4.com> * @return array * @see _array_textinput */ function get_array_textinput( ) { return $this->_array_textinput; } /** * This Method returns the data from <image />. * * @access public * @author Stefan Saasen <s@fase4.com> * @return array * @see _array_image */ function get_array_image( ) { return $this->_array_image; } /** * XML Parser Data Handler * * @access private * @author Stefan Saasen <s@fase4.com> * @param mixed $parser a reference to the XML parser calling the handler. * @param string $text contains the character data as a string. * @see _parse_mode, _item, _tags, _depth, _citem, _ctags, _cdepth */ function _parseData($parser, $text) { $clean = preg_replace("/\s/", "", $text); if ($clean) { $text = preg_replace("/^\s+/", "", $text); if($this->_parse_mode == "all") { if ( $this->_item[$this->_tags[$this->_depth[$parser]]] ) { $this->_item[$this->_tags[$this->_depth[$parser]]] .= $text; } else { $this->_item[$this->_tags[$this->_depth[$parser]]] = $text; } } elseif ($this->_parse_mode == "channel") { if ( $this->_citem[$this->_ctags[$this->_cdepth[$parser]]] ) { $this->_citem[$this->_ctags[$this->_cdepth[$parser]]] .= $text; } else { $this->_citem[$this->_ctags[$this->_cdepth[$parser]]] = $text; } } } } /** * This Method allows you to choose if specific Parameters are displayed or not. These are: * image, channel, textinput, build and cache_update. If set to "hidden" those elements won't be displayed. * * @access public * @author Stefan Saasen <s@fase4.com> * @param array $options * @see _display_opt */ function set_Options( $options = "" ) { if(is_array( $options )) { $this->_display_opt = $options; return true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -