Net_NNTP
[ class tree: Net_NNTP ] [ index: Net_NNTP ] [ all elements ]

Source for file NNTP.php

Documentation is available at NNTP.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Martin Kaltoft   <martin@nitro.dk>                          |
  17. // |          Tomas V.V.Cox    <cox@idecnet.com>                          |
  18. // |          Heino H. Gehlsen <heino@gehlsen.dk>                         |
  19. // +----------------------------------------------------------------------+
  20. // $Id: NNTP.php,v 1.30.2.3 2005/01/14 20:07:49 heino Exp $
  21.  
  22. require_once 'Net/NNTP/Protocol/Client.php';
  23.  
  24. // {{{ constants
  25.  
  26. /* NNTP Authentication modes */
  27. define('NET_NNTP_AUTHORIGINAL''original');
  28. define('NET_NNTP_AUTHSIMPLE',   'simple');
  29. define('NET_NNTP_AUTHGENERIC',  'generic');
  30.  
  31. // Deprecated due to naming
  32. define('PEAR_NNTP_AUTHORIGINAL'NET_NNTP_AUTHORIGINAL);
  33. define('PEAR_NNTP_AUTHSIMPLE',   NET_NNTP_AUTHSIMPLE);
  34. define('PEAR_NNTP_AUTHGENERIC',  NET_NNTP_AUTHGENERIC);
  35.  
  36. // }}}
  37. // {{{ Net_NNTP
  38.  
  39. /**
  40.  * The Net_NNTP class is an almost 100 % backward compatible
  41.  * frontend class to the Net_NNTP_Protocol_Client class.
  42.  * 
  43.  * ATTENTION!!!
  44.  * This class should NOT be used in new projects. It is meant
  45.  * as a drop in replacement to the outdated v0.2, and uses
  46.  * excatly the same protocol implementation as the new
  47.  * Net_NNTP_Client class, but has a lot of deprecated
  48.  * methods etc.
  49.  *
  50.  * @category   Net
  51.  * @package    Net_NNTP
  52.  * @author     Martin Kaltoft   <martin@nitro.dk>
  53.  * @author     Tomas V.V.Cox    <cox@idecnet.com>
  54.  * @author     Heino H. Gehlsen <heino@gehlsen.dk>
  55.  * @version    $Id: NNTP.php,v 1.30.2.3 2005/01/14 20:07:49 heino Exp $
  56.  * @access     public
  57.  * @see        Net_NNTP_Client
  58.  * @since      Class available since Release 0.1.0
  59.  * @deprecated Class deprecated in Release 0.10.0
  60.  */
  61. {
  62.     // {{{ properties
  63.  
  64.     /**
  65.      * @var int 
  66.      * @access public
  67.      * @deprecated use last() instead
  68.      */
  69.     var $max;
  70.  
  71.     /**
  72.      * @var int 
  73.      * @access public
  74.      * @deprecated use first() instead
  75.      */
  76.     var $min;
  77.  
  78.     /**
  79.      * Used for storing information about the currently selected group
  80.      *
  81.      * @var array 
  82.      * @access private
  83.      * @since 0.3
  84.      */
  85.     var $_currentGroup = null;
  86.  
  87.     // }}}
  88.     // {{{ constructor
  89.  
  90.     /**
  91.      * Constructor
  92.      */
  93.     function Net_NNTP()
  94.     {
  95.         parent::Net_NNTP_Protocol_Client();
  96.     }
  97.  
  98.     // }}}
  99.     // {{{ connect()
  100.  
  101.     /**
  102.      * Connect to the newsserver.
  103.      *
  104.      * The function currently allows automatic authentication via the three last parameters,
  105.      * but this feature is to be considered depresated (use connectAuthenticated instead)
  106.      *
  107.      * In the future, this function will just be inherrited from the parent,
  108.      * and thus the last three parameters will no longer be used to authenticate.
  109.      *
  110.      * @param optional string $host The adress of the NNTP-server to connect to.
  111.      * @param optional int $port The port to connect to.
  112.      * @param optional string $user Deprecated!
  113.      * @param optional string $pass Deprecated!
  114.      * @param optional string $authmode Deprecated!
  115.      *
  116.      * @return mixed (bool) true on success or (object) pear_error on failure
  117.      * @access public
  118.      * @see Net_NNTP::quit()
  119.      * @see Net_NNTP::connectAuthenticated()
  120.      * @see Net_NNTP::authenticate()
  121.      */
  122.     function connect($host = NET_NNTP_PROTOCOL_CLIENT_DEFAULT_HOST,
  123.                      $port = NET_NNTP_PROTOCOL_CLIENT_DEFAULT_PORT,
  124.                      $user = null,
  125.                      $pass = null,
  126.                      $authmode = NET_NNTP_AUTHORIGINAL)
  127.     {
  128.         // Currently this function just 'forwards' to connectAuthenticated().
  129.         return $this->connectAuthenticated($user$pass$host$port$authmode);
  130.     }
  131.  
  132.  
  133.     // }}}
  134.     // {{{ connectAuthenticated()
  135.  
  136.     /**
  137.      * Connect to the newsserver, and authenticate. If no user/pass is specified, just connect.
  138.      *
  139.      * @param optional string $user The user name to authenticate with
  140.      * @param optional string $pass The password
  141.      * @param optional string $host The adress of the NNTP-server to connect to.
  142.      * @param optional int $port The port to connect to.
  143.      * @param optional string $authmode The authentication mode
  144.      *
  145.      * @return mixed (bool) true on success or (object) pear_error on failure
  146.      * @access public
  147.      * @since 0.3
  148.      * @see Net_NNTP::connect()
  149.      * @see Net_NNTP::authenticate()
  150.      * @see Net_NNTP::quit()
  151.      * @deprecated use connect() and authenticate() instead
  152.      */
  153.     function connectAuthenticated($user = null,
  154.                                   $pass = null,
  155.                                   $host = NET_NNTP_PROTOCOL_CLIENT_DEFAULT_HOST,
  156.                                   $port = NET_NNTP_PROTOCOL_CLIENT_DEFAULT_PORT,
  157.                                   $authmode = NET_NNTP_AUTHORIGINAL)
  158.     {
  159.         // Until connect() is changed, connect() is called directly from the parent...
  160.         $R = parent::connect($host$port);
  161.         if (PEAR::isError($R)) {
  162.             return $R;
  163.         }
  164.  
  165.         // Authenticate if username is given
  166.         if ($user != null{
  167.             $R $this->authenticate($user$pass$authmode);
  168.             if (PEAR::isError($R)) {
  169.                 return $R;
  170.             }
  171.         }
  172.  
  173.         return true;
  174.     }
  175.  
  176.     // }}}
  177.     // {{{ quit()
  178.  
  179.     /**
  180.      * Close connection to the newsserver
  181.      *
  182.      * @access public
  183.      * @see Net_NNTP::connect()
  184.      */
  185.     function quit()
  186.     {
  187.         return $this->cmdQuit();
  188.     }
  189.  
  190.     // }}}
  191.     // {{{ prepareConnection()
  192.  
  193.     /**
  194.      * Connect to the newsserver, and issue a GROUP command
  195.      * Once connection is prepared, we can only fetch articles from one group
  196.      * at a time, to fetch from another group, a new connection has to be made.
  197.      *
  198.      * This is to avoid the GROUP command for every article, as it is very
  199.      * ressource intensive on the newsserver especially when used for
  200.      * groups with many articles.
  201.      *
  202.      * @param string $host The adress of the NNTP-server to connect to.
  203.      * @param optional int $port the port-number to connect to, defaults to 119.
  204.      * @param string $newsgroup The name of the newsgroup to use.
  205.      * @param optional string $user The user name to authenticate with
  206.      * @param optional string $pass The password
  207.      * @param optional string $authmode The authentication mode
  208.      *
  209.      * @return mixed (bool) true on success or (object) pear_error on failure
  210.      * @access public
  211.      *
  212.      * @deprecated Use connect() or connectAuthenticated() instead
  213.      */
  214.     function prepareConnection($host,
  215.                                 $port = 119,
  216.                                 $newsgroup,
  217.                                 $user = null,
  218.                                 $pass = null,
  219.                                 $authmode = NET_NNTP_AUTHORIGINAL)
  220.     {
  221.         /* connect to the server */
  222.         $R $this->connect($host$port$user$pass$authmode);
  223.         if (PEAR::isError($R)) {
  224.             return $R;
  225.         }
  226.  
  227.         /* issue a GROUP command */
  228.         $R $this->selectGroup($newsgroup);
  229.         if (PEAR::isError($R)) {
  230.             return $R;
  231.         }
  232.  
  233.         return true;
  234.     }
  235.  
  236.     function prepare_connection($nntpserver,
  237.                                 $port = 119,
  238.                                 $newsgroup,
  239.                                 $user = null,
  240.                                 $pass = null,
  241.                                 $authmode = NET_NNTP_AUTHORIGINAL)
  242.     {
  243.         return $this->prepareConnection($nntpserver$port$newsgroup$user$pass$authmode);
  244.     }
  245.                                                                                     
  246.     // }}}
  247.     // {{{ authenticate()
  248.  
  249.     /**
  250.      * Auth process (not yet standarized but used any way)
  251.      * http://www.mibsoftware.com/userkt/nntpext/index.html
  252.      *
  253.      * @param string $user The user name
  254.      * @param optional string $pass The password if needed
  255.      * @param optional string $mode Authinfo type: original, simple, generic
  256.      *
  257.      * @return mixed (bool) true on success or (object) pear_error on failure
  258.      * @access public
  259.      * @since 0.3
  260.      * @see Net_NNTP::connect()
  261.      */
  262.     function authenticate($user$pass$mode = NET_NNTP_AUTHORIGINAL)
  263.     {
  264.         // Username is a must...
  265.         if ($user == null{
  266.             return PEAR::throwError('No username supplied'null);
  267.         }
  268.  
  269.         // Use selected authentication method
  270.         switch ($mode{
  271.             case NET_NNTP_AUTHORIGINAL:
  272.                 return $this->cmdAuthinfo($user$pass);
  273.                 break;
  274.             case NET_NNTP_AUTHSIMPLE:
  275.                 return $this->cmdAuthinfoSimple($user$pass);
  276.                 break;
  277.             case NET_NNTP_AUTHGENERIC:
  278.                 return $this->cmdAuthinfoGeneric($user$pass);
  279.                 break;
  280.             default:
  281.                 return PEAR::throwError("The auth mode: '$mode' is unknown"null);
  282.         }
  283.     }
  284.  
  285.     // }}}
  286.     // {{{ isConnected()
  287.  
  288.     /**
  289.      * Test whether we are connected or not.
  290.      *
  291.      * @return bool true or false
  292.      * @access public
  293.      * @see Net_NNTP::connect()
  294.      * @see Net_NNTP::quit()
  295.      */
  296.     function isConnected()
  297.     {
  298.         return parent::isConnected();
  299.     }
  300.     
  301.     function is_connected()
  302.     {
  303.     return $this->isConnected();
  304.     }
  305.  
  306.     // }}}
  307.     // {{{ selectGroup()
  308.  
  309.     /**
  310.      * Selects a news group (issue a GROUP command to the server)
  311.      *
  312.      * @param string $newsgroup The newsgroup name
  313.      *
  314.      * @return mixed (array) Groups info on success or (object) pear_error on failure
  315.      * @access public
  316.      * @see group()
  317.      * @see count()
  318.      * @see first()
  319.      * @see last()
  320.      */
  321.     function selectGroup($newsgroup)
  322.     {
  323.         $response_arr $this->cmdGroup($newsgroup);
  324.         if (PEAR::isError($response_arr)) {
  325.             return $response_arr;
  326.         }
  327.  
  328.         $this->_currentGroup $response_arr;
  329.  
  330.         // Deprecated / historical                      
  331.         $response_arr['min'=$response_arr['first'];
  332.         $response_arr['max'=$response_arr['last'];
  333.         $this->min =$response_arr['min'];
  334.         $this->max =$response_arr['max'];
  335.  
  336.         return $response_arr;
  337.     }
  338.  
  339.     function select_group($newsgroup)
  340.     {
  341.         return $this->selectGroup($newsgroup);
  342.     }
  343.  
  344.     // }}}
  345.     // {{{ getGroups()
  346.  
  347.     /**
  348.      * Fetches a list of all avaible newsgroups
  349.      *
  350.      * @return mixed (array) nested array with informations about existing newsgroups on success or (object) pear_error on failure
  351.      * @access public
  352.      */
  353.     function getGroups()
  354.     {
  355.         // Get groups
  356.         $groups $this->cmdList();
  357.         if (PEAR::isError($groups)) {
  358.             return $groups;
  359.         }
  360.  
  361.         // Deprecated / historical
  362.         foreach (array_keys($groupsas $k{
  363.             $groups[$k]['posting_allowed'=$groups[$k]['posting'];
  364.         }
  365.  
  366.         // Get group descriptions
  367.         $descriptions $this->cmdListNewsgroups();
  368.         if (PEAR::isError($descriptions)) {
  369.             return $descriptions;
  370.         }
  371.     
  372.         // Set known descriptions for groups
  373.         if (count($descriptions> 0{
  374.             foreach ($descriptions as $k=>$v{
  375.                 $groups[$k]['desc'$v;
  376.             }
  377.         }
  378.  
  379.         return $groups;
  380.     }
  381.  
  382.     function get_groups()
  383.     {
  384.     return $this->getGroups();
  385.     }
  386.  
  387.     // }}}
  388.     // {{{ getOverview()
  389.  
  390.     /**
  391.      * Fetch message header from message number $first to $last
  392.      *
  393.      * The format of the returned array is:
  394.      * $messages[message_id][header_name]
  395.      *
  396.      * @param integer $first first article to fetch
  397.      * @param integer $last  last article to fetch
  398.      *
  399.      * @return mixed (array) nested array of message and there headers on success or (object) pear_error on failure
  400.      * @access public
  401.      * @see Net_NNTP::getOverviewFormat()
  402.      * @see Net_NNTP::getReferencesOverview()
  403.      */
  404.     function getOverview($first$last)
  405.     {
  406.         $overview $this->cmdXOver($first.'-'.$last);
  407.         if (PEAR::isError($overview)) {
  408.             return $overview;
  409.         }
  410.  
  411.         return $overview;
  412.     }
  413.  
  414.     function get_overview($first$last)
  415.     {
  416.         $this->getOverview($first$last);
  417.     }
  418.  
  419.     // }}}
  420.     // {{{ getOverviewFormat()
  421.  
  422.     /**
  423.      * Returns a list of avaible headers which are send from newsserver to client for every news message
  424.      *
  425.      * @return mixed (array) header names on success or (object) pear_error on failure
  426.      * @access public
  427.      * @see Net_NNTP::getOverview()
  428.      */
  429.     function getOverviewFormat()
  430.     {
  431.         return $this->cmdListOverviewFMT();
  432.     }
  433.  
  434.     // }}}
  435.     // {{{ getOverviewFmt()
  436.  
  437.     /**
  438.      * Returns a list of avaible headers which are send from newsserver to client for every news message
  439.      *
  440.      * @return mixed (array) header names on success or (object) pear_error on failure
  441.      * @access public
  442.      * @deprecated use getOverviewFormat() instead
  443.      */
  444.     function getOverviewFmt()
  445.     {
  446.         return $this->getOverviewFormat();
  447.     }
  448.  
  449.     function get_overview_fmt()
  450.     {
  451.         $this->getOverviewFmt();
  452.     }
  453.     
  454.     // }}}
  455.     // {{{ getReferencesOverview()
  456.  
  457.     /**
  458.      * Fetch a list of each message's reference header.
  459.      *
  460.      * @param integer $first first article to fetch
  461.      * @param integer $last  last article to fetch
  462.      *
  463.      * @return mixed (array) nested array of references on success or (object) pear_error on failure
  464.      *
  465.      * @return mixed (array) nested array of message and there headers on success or (object) pear_error on failure
  466.      * @access public
  467.      * @see Net_NNTP::getOverview()
  468.      */
  469.     function getReferencesOverview($first$last)
  470.     {
  471.         $overview $this->cmdXROver($first.'-'.$last);
  472.         if (PEAR::isError($overview)) {
  473.             return $overview;
  474.         }
  475.     
  476.         return $overview;
  477.     }
  478.  
  479.     // }}}
  480.     // {{{ post()
  481.  
  482.     /**
  483.      * Post an article to a number of newsgroups.
  484.      *
  485.      * (Among the aditional headers you might think of adding could be:
  486.      * "NNTP-Posting-Host: <ip-of-author>", which should contain the IP-adress
  487.      * of the author of the post, so the message can be traced back to him.
  488.      * Or "Organization: <org>" which contain the name of the organization
  489.      * the post originates from)
  490.      *
  491.      * @param string $subject The subject of the post.
  492.      * @param string $newsgroup The newsgroup to post to.
  493.      * @param string $from Name + email-adress of sender.
  494.      * @param string $body The body of the post itself.
  495.      * @param optional string $aditional Aditional headers to send.
  496.      *
  497.      * @return mixed (string) server response on success or (object) pear_error on failure
  498.      * @access public
  499.      */
  500.     function post($subject$newsgroup$from$body$aditional '')
  501.     {
  502.         return $this->cmdPost($newsgroup$subject$body$from$aditional);
  503.     }
  504.  
  505.     // }}}
  506.     // {{{ getArticleRaw()
  507.  
  508.     /**
  509.      * Get an article (raw data)
  510.      *
  511.      * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  512.      * @param bool  $implode When true the result array is imploded to a string, defaults to true.
  513.      *
  514.      * @return mixed (array/string) The headers on success or (object) pear_error on failure
  515.      * @access public
  516.      * @since 0.3
  517.      * @see getHeaderRaw()
  518.      * @see getBodyRaw()
  519.      */
  520.     function getArticleRaw($article$implode = true)
  521.     {
  522.         $data $this->cmdArticle($article);
  523.         if (PEAR::isError($data)) {
  524.             return $data;
  525.         }
  526.         if ($implode == true{
  527.             $data implode("\r\n"$data);
  528.         }
  529.         return $data;
  530.     }
  531.  
  532.     // }}}
  533.     // {{{ getArticle()
  534.  
  535.     /**
  536.      * Get an article (deprecated)
  537.      *
  538.      * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  539.      *
  540.      * @return mixed (string) The headers on success or (object) pear_error on failure
  541.      * @access public
  542.      * @deprecated Use getArticleRaw() instead
  543.      */
  544.     function getArticle($article)
  545.     {
  546.         return $this->getArticleRaw($article);
  547.     }
  548.  
  549.     function get_article($article)
  550.     {
  551.         return $this->getArticle($article);
  552.     }
  553.  
  554.     // }}}
  555.     // {{{ getHeaderRaw()
  556.  
  557.     /**
  558.      * Get the headers of an article (raw data)
  559.      *
  560.      * @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
  561.      * @param bool  $implode When true the result array is imploded to a string, defaults to true.
  562.      *
  563.      * @return mixed (array/string) headers on success or (object) pear_error on failure
  564.      * @access public
  565.      * @since 0.3
  566.      * @see getArticleRaw()
  567.      * @see getBodyRaw()
  568.      */
  569.     function getHeaderRaw($article$implode = true)
  570.     {
  571.         $data $this->cmdHead($article);
  572.         if (PEAR::isError($data)) {
  573.             return $data;
  574.         }
  575.         if ($implode == true{
  576.             $data implode("\r\n"$data);
  577.         }
  578.         return $data;
  579.     }
  580.  
  581.     // }}}
  582.     // {{{ getHeaders()
  583.  
  584.     /**
  585.      * Get the headers of an article (deprecated)
  586.      *
  587.      * @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
  588.      *
  589.      * @return mixed (string) headers on success or (object) pear_error on failure
  590.      * @access public
  591.      * @deprecated Use getHeaderRaw() instead
  592.      */
  593.     function getHeaders($article)
  594.     {
  595.         return $this->getHeaderRaw($article);
  596.     }
  597.  
  598.     function get_headers($article)
  599.     {
  600.         return $this->getHeaders($article);
  601.     }
  602.  
  603.     // }}}
  604.     // {{{ getBodyRaw()
  605.  
  606.     /**
  607.      * Get the body of an article (raw data)
  608.      *
  609.      * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  610.      * @param bool  $implode When true the result array is imploded to a string, defaults to true.
  611.      *
  612.      * @return mixed (array/string) headers on success or (object) pear_error on failure
  613.      * @access public
  614.      * @since 0.3
  615.      * @see getHeaderRaw()
  616.      * @see getArticleRaw()
  617.      */
  618.     function getBodyRaw($article$implode = true)
  619.     {
  620.         $data $this->cmdBody($article);
  621.         if (PEAR::isError($data)) {
  622.             return $data;
  623.         }
  624.         if ($implode == true{
  625.             $data implode("\r\n"$data);
  626.         }
  627.         return $data;
  628.     }
  629.  
  630.     // }}}
  631.     // {{{ getBody()
  632.  
  633.     /**
  634.      * Get the body of an article (deprecated)
  635.      *
  636.      * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  637.      *
  638.      * @return mixed (string) headers on success or (object) pear_error on failure
  639.      * @access public
  640.      * @deprecated Use getBodyRaw() instead
  641.      */
  642.     function getBody($article)
  643.     {
  644.         return $this->getBodyRaw($article);
  645.     }
  646.  
  647.     function get_body($article)
  648.     {
  649.         return $this->getBody($article);
  650.     }
  651.  
  652.     // }}}
  653.     // {{{ getDate()
  654.  
  655.     /**
  656.      * Get the NNTP-server's internal date
  657.      *
  658.      * Get the date from the newsserver format of returned date:
  659.      *
  660.      * @param optional int $format
  661.      *   - 0: $date - timestamp
  662.      *   - 1: $date['y'] - year
  663.      *        $date['m'] - month
  664.      *        $date['d'] - day
  665.      *
  666.      * @return mixed (mixed) date on success or (object) pear_error on failure
  667.      * @access public
  668.      * @since 0.3
  669.      */
  670.     function getDate($format = 1)
  671.     {
  672.         $date $this->cmdDate();
  673.         if (PEAR::isError($date)) {
  674.             return $date;
  675.         }
  676.  
  677.         switch ($format{
  678.             case 1:
  679.                 return array('y' => substr($date04)'m' => substr($date42)'d' => substr($date62));
  680.                 break;
  681.  
  682.             case 0:
  683.             default:
  684.                 return $date;
  685.                 break;
  686.         }
  687.     }
  688.  
  689.     // }}}
  690.     // {{{ date()
  691.  
  692.     /**
  693.      * @return mixed (array) date on success or (object) pear_error on failure
  694.      * @access public
  695.      *
  696.      * @deprecated Use getDate() instead
  697.      */
  698.     function date()
  699.     {
  700.         return $this->getDate();
  701.     }
  702.  
  703.     // }}}
  704.     // {{{ count()
  705.  
  706.     /**
  707.      * Number of articles in currently selected group
  708.      *
  709.      * @return integer count
  710.      * @access public
  711.      * @since 0.3
  712.      * @see Net_NNTP::selectGroup()
  713.      * @see Net_NNTP::group()
  714.      * @see Net_NNTP::first()
  715.      * @see Net_NNTP::last()
  716.      */
  717.     function count()
  718.     {
  719.         return $this->_currentGroup['count'];
  720.     }
  721.  
  722.     // }}}
  723.     // {{{ last()
  724.  
  725.     /**
  726.      * Maximum article number in current group
  727.      *
  728.      * @return integer maximum
  729.      * @access public
  730.      * @since 0.3
  731.      * @see Net_NNTP::selectGroup()
  732.      * @see Net_NNTP::group()
  733.      * @see Net_NNTP::first()
  734.      * @see Net_NNTP::count()
  735.      */
  736.     function last()
  737.     {
  738.         return $this->_currentGroup['last'];
  739.     }
  740.  
  741.     // }}}
  742.     // {{{ max()
  743.  
  744.     /**
  745.      * @return integer maximum
  746.      * @access public
  747.      *
  748.      * @deprecated Use last() instead
  749.      */
  750.     function max()
  751.     {
  752.         return $this->last();
  753.     }
  754.  
  755.     // }}}
  756.     // {{{ first()
  757.  
  758.     /**
  759.      * Minimum article number in current group
  760.      *
  761.      * @return integer minimum
  762.      * @access public
  763.      * @since 0.3
  764.      * @see Net_NNTP::selectGroup()
  765.      * @see Net_NNTP::group()
  766.      * @see Net_NNTP::last()
  767.      * @see Net_NNTP::count()
  768.      */
  769.     function first()
  770.     {
  771.         return $this->_currentGroup['first'];
  772.     }
  773.  
  774.     // }}}
  775.     // {{{ min()
  776.  
  777.     /**
  778.      * @return integer minimum
  779.      * @access public
  780.      *
  781.      * @deprecated Use first() instead
  782.      */
  783.     function min()
  784.     {
  785.         return $this->first();
  786.     }
  787.  
  788.     // }}}
  789.     // {{{ group()
  790.  
  791.     /**
  792.      * Currently selected group
  793.      *
  794.      * @return string group
  795.      * @access public
  796.      * @since 0.3
  797.      * @see Net_NNTP::selectGroup()
  798.      * @see Net_NNTP::first()
  799.      * @see Net_NNTP::last()
  800.      * @see Net_NNTP::count()
  801.      */
  802.     function group()
  803.     {
  804.         return $this->_currentGroup['group'];
  805.     }
  806.  
  807.     // }}}
  808.     // {{{ splitHeaders()
  809.  
  810.     /**
  811.      * Get the headers of an article from the currently open connection, and parse them into a keyed array.
  812.      *
  813.      * @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
  814.      *
  815.      * @return mixed (array) Assoc array with headers names as key on success or (object) pear_error on failure
  816.      * @access public
  817.      */
  818.     function splitHeaders($article)
  819.     {
  820.         // Retrieve headers
  821.         $headers $this->getHeaderRaw($articlefalse);
  822.         if (PEAR::isError($headers)) {
  823.             return PEAR::throwError($headers);
  824.         }
  825.     
  826.         $return = array();
  827.  
  828.         // Loop through all header field lines
  829.         foreach ($headers as $field{
  830.             // Separate header name and value
  831.             if (!preg_match('/([\S]+)\:\s*(.*)\s*/'$field$matches)) {
  832.                 // Fail...
  833.             }
  834.             $name $matches[1];
  835.             $value $matches[2];
  836.             unset($matches);
  837.  
  838.             // Add header to $return array
  839.             if (isset($return[$name]AND is_array($return[$name])) {
  840.                 // The header name has already been used at least two times.
  841.                 $return[$name][$value;
  842.             elseif (isset($return[$name])) {
  843.                 // The header name has already been used one time -> change to nedted values.
  844.                 $return[$name= array($return[$name]$value);
  845.             else {
  846.                 // The header name has not used until now.
  847.             $return[$name$value;
  848.             }
  849.         }
  850.  
  851.         return $return;
  852.     }
  853.  
  854.     function split_headers($article)
  855.     {
  856.         return $this->splitHeaders($article);
  857.     }
  858.     
  859.     // }}}
  860.     // {{{ responseCode()
  861.  
  862.     /**
  863.      * returns the response code of a newsserver command
  864.      *
  865.      * @param string $response newsserver answer
  866.      *
  867.      * @return integer response code
  868.      * @access public
  869.      *
  870.      * @deprecated
  871.      */
  872.     function responseCode($response)
  873.     {
  874.         $parts explode(' 'ltrim($response)2);
  875.         return (int) $parts[0];
  876.     }
  877.  
  878.     // }}}
  879.     // {{{ _getData()
  880.  
  881.     /**
  882.      * Get data until a line with only a '.' in it is read and return data.
  883.      *
  884.      * @return mixed (string) data on success or (object) pear_error on failure
  885.      * @access private
  886.      *
  887.      * @deprecated Use _getTextResponse() instead
  888.      */
  889.     function _getData()
  890.     {
  891.         return $this->_getTextResponse();
  892.     }
  893.  
  894.     function get_data()
  895.     {
  896.     return $this->_getData();
  897.     }
  898.  
  899.     // }}}
  900.     // {{{ command()
  901.  
  902.     /**
  903.      * Issue a command to the NNTP server
  904.      *
  905.      * @param string $cmd The command to launch, ie: "ARTICLE 1004853"
  906.      *
  907.      * @return mixed (int) response code on success or (object) pear_error on failure
  908.      * @access public
  909.      */
  910.     function command($cmd)
  911.     {
  912.         $code $this->_sendCommand($cmd);
  913.         if (PEAR::isError($code)) {
  914.             return PEAR::throwError($code);
  915.         }
  916.     
  917.         return $code.' '.$this->currentStatusResponse()."\r\n";
  918.     }
  919.  
  920.     // }}}
  921.  
  922. }
  923.  
  924. // }}}
  925.  
  926. ?>

Documentation generated on Mon, 11 Mar 2019 14:13:03 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.