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

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