⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rss.php

📁 通达OA2007SE源代码 非常好的
💻 PHP
字号:
<?
  class myoa_rss
  {
    var $file = null;
    var $data = null;
    var $rss_channel = array ();
    var $currently_writing = '';
    var $main = '';
    var $item_counter = 0;
    function startelement ($parser, $name, $attrs)
    {
      switch ($name)
      {
        case 'RSS':
        {
        }
        case 'RDF:RDF':
        {
        }
        case 'ITEMS':
        {
          $this->currently_writing = '';
          break;
        }
        case 'CHANNEL':
        {
          $this->main = 'CHANNEL';
          break;
        }
        case 'IMAGE':
        {
          $this->main = 'IMAGE';
          $this->rss_channel['IMAGE'] = array ();
          break;
        }
        case 'ITEM':
        {
          $this->main = 'ITEMS';
          break;
        }
        default:
        {
          $this->currently_writing = $name;
          break;
        }
      }
    }
    function endelement ($parser, $name)
    {
      if (($name == 'IMAGE'))
      {
        $this->main = 'CHANNEL';
      }
      $this->currently_writing = '';
      if (($name == 'ITEM'))
      {
        ++$this->item_counter;
      }
    }
    function characterdata ($parser, $data)
    {
      $data = iconv ('UTF-8', 'GB18030', $data);
      if (($this->currently_writing != ''))
      {
        switch ($this->main)
        {
          case 'CHANNEL':
          {
            if (isset ($this->rss_channel[$this->currently_writing]))
            {
              $this->rss_channel[$this->currently_writing] = $data;
              break;
            }
            else
            {
              $this->rss_channel[$this->currently_writing] = $data;
              break;
            }
            break;
          }
          case 'IMAGE':
          {
            if (isset ($this->rss_channel[$this->main][$this->currently_writing]))
            {
              ($this->rss_channel[$this->main][$this->currently_writing] .= $data);
              break;
            }
            else
            {
              $this->rss_channel[$this->main][$this->currently_writing] = $data;
              break;
            }
            break;
          }
          case 'ITEMS':
          {
            if (isset ($this->rss_channel[$this->main][$this->item_counter][$this->currently_writing]))
            {
              ($this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] .= $data);
              break;
            }
            else
            {
              $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] = $data;
              break;
            }
            break;
          }
        }
      }
    }
    function myoa_rss ($file = '')
    {
      $this->file = $file;
      $this->data = '';
      if (($file != ''))
      {
        $fp = fopen ($file, 'rb');
        while (!feof ($fp))
        {
          ($this->data .= fread ($fp, 4096));
        }
        fclose ($fp);
      }
    }
    function parse ($data = '')
    {
      $this->xml_parser = xml_parser_create ();
      xml_set_object ($this->xml_parser, &$this);
      xml_set_element_handler ($this->xml_parser, 'startElement', 'endElement');
      xml_set_character_data_handler ($this->xml_parser, 'characterData');
      if (($data == ''))
      {
        $data = $this->data;
      }
      if ((substr ($data, 0, 1) != '<'))
      {
        $this->data = substr ($data, strpos ($data, '<'));
      }
      if (!xml_parse ($this->xml_parser, $data))
      {
      }
      xml_parser_free ($this->xml_parser);
    }
    function gettitle ()
    {
      return $this->rss_channel['TITLE'];
    }
    function getcontent ($rows_count = 10)
    {
      if ((isset ($this->rss_channel['ITEMS']) AND (0 < count ($this->rss_channel['ITEMS']))))
      {
        for ($i = 0; ($i < count ($this->rss_channel['ITEMS'])); ++$i)
        {
          if ((($rows_count != 0) AND ($rows_count <= $i)))
          {
            break;
          }
          $itemTitle = strip_tags ($this->rss_channel['ITEMS'][$i]['TITLE']);
          $itemLink = $this->rss_channel['ITEMS'][$i]['LINK'];
          if (($this->rss_channel['ITEMS'][$i]['PUBDATE'] != ''))
          {
            $TimeStamp = strtotime ($this->rss_channel['ITEMS'][$i]['PUBDATE']);
            if (($TimeStamp != -1))
            {
              $itemPubDate = ((' ('.date ('m-d H:i', $TimeStamp)).')');
            }
          }
          ($OUTPUT_HTML .= (('·<a href="'.$itemLink).'" target="_blank"'));
          if ((($rows_count != 0) AND (64 < strlen ($itemTitle))))
          {
            ($OUTPUT_HTML .= ((((' title="'.$itemTitle).'">').csubstr ($itemTitle, 0, 60)).'...'));
          }
          else
          {
            ($OUTPUT_HTML .= ('>'.$itemTitle));
          }
          ($OUTPUT_HTML .= (('</a>'.$itemPubDate).'<br>'));
        }
      }
      return $OUTPUT_HTML;
    }
  }
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -