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.4 2004/08/21 12:15:00 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.4 2004/08/21 12:15:00 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.      */
  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.     // }}}
  237.     // {{{ authenticate()
  238.  
  239.     /**
  240.      * Auth process (not yet standarized but used any way)
  241.      * http://www.mibsoftware.com/userkt/nntpext/index.html
  242.      *
  243.      * @param string $user The user name
  244.      * @param optional string $pass The password if needed
  245.      * @param optional string $mode Authinfo type: original, simple, generic
  246.      *
  247.      * @return mixed (bool) true on success or (object) pear_error on failure
  248.      * @access public
  249.      * @since 0.3
  250.      * @see Net_NNTP::connect()
  251.      */
  252.     function authenticate($user$pass$mode = NET_NNTP_AUTHORIGINAL)
  253.     {
  254.         // Username is a must...
  255.         if ($user == null{
  256.             return PEAR::throwError('No username supplied'null);
  257.         }
  258.  
  259.         // Use selected authentication method
  260.         switch ($mode{
  261.             case NET_NNTP_AUTHORIGINAL:
  262.                 return $this->cmdAuthinfo($user$pass);
  263.                 break;
  264.             case NET_NNTP_AUTHSIMPLE:
  265.                 return $this->cmdAuthinfoSimple($user$pass);
  266.                 break;
  267.             case NET_NNTP_AUTHGENERIC:
  268.                 return $this->cmdAuthinfoGeneric($user$pass);
  269.                 break;
  270.             default:
  271.                 return PEAR::throwError("The auth mode: '$mode' is unknown"null);
  272.         }
  273.     }
  274.  
  275.     // }}}
  276.     // {{{ isConnected()
  277.  
  278.     /**
  279.      * Test whether we are connected or not.
  280.      *
  281.      * @return bool true or false
  282.      * @access public
  283.      * @see Net_NNTP::connect()
  284.      * @see Net_NNTP::quit()
  285.      */
  286.     function isConnected()
  287.     {
  288.         return parent::isConnected();
  289.     }
  290.  
  291.     // }}}
  292.     // {{{ selectGroup()
  293.  
  294.     /**
  295.      * Selects a news group (issue a GROUP command to the server)
  296.      *
  297.      * @param string $newsgroup The newsgroup name
  298.      *
  299.      * @return mixed (array) Groups info on success or (object) pear_error on failure
  300.      * @access public
  301.      * @see group()
  302.      * @see count()
  303.      * @see first()
  304.      * @see last()
  305.      */
  306.     function selectGroup($newsgroup)
  307.     {
  308.         $response_arr $this->cmdGroup($newsgroup);
  309.         if (PEAR::isError($response_arr)) {
  310.             return $response_arr;
  311.         }
  312.  
  313.         $this->_currentGroup $response_arr;
  314.  
  315.         // Deprecated / historical                      
  316.         $response_arr['min'=$response_arr['first'];
  317.         $response_arr['max'=$response_arr['last'];
  318.         $this->min =$response_arr['min'];
  319.         $this->max =$response_arr['max'];
  320.  
  321.         return $response_arr;
  322.     }
  323.  
  324.     // }}}
  325.     // {{{ getGroups()
  326.  
  327.     /**
  328.      * Fetches a list of all avaible newsgroups
  329.      *
  330.      * @return mixed (array) nested array with informations about existing newsgroups on success or (object) pear_error on failure
  331.      * @access public
  332.      */
  333.     function getGroups()
  334.     {
  335.         // Get groups
  336.         $groups $this->cmdList();
  337.         if (PEAR::isError($groups)) {
  338.             return $groups;
  339.         }
  340.  
  341.         // Deprecated / historical
  342.         foreach (array_keys($groupsas $k{
  343.             $groups[$k]['posting_allowed'=$groups[$k][3];
  344.         }
  345.  
  346.         // Get group descriptions
  347.         $descriptions $this->cmdListNewsgroups();
  348.         if (PEAR::isError($descriptions)) {
  349.             return $descriptions;
  350.         }
  351.     
  352.         // Set known descriptions for groups
  353.         if (count($descriptions> 0{
  354.             foreach ($descriptions as $k=>$v{
  355.                 $groups[$k]['desc'$v;
  356.             }
  357.         }
  358.  
  359.         return $groups;
  360.     }
  361.  
  362.     // }}}
  363.     // {{{ getOverview()
  364.  
  365.     /**
  366.      * Fetch message header from message number $first to $last
  367.      *
  368.      * The format of the returned array is:
  369.      * $messages[message_id][header_name]
  370.      *
  371.      * @param integer $first first article to fetch
  372.      * @param integer $last  last article to fetch
  373.      *
  374.      * @return mixed (array) nested array of message and there headers on success or (object) pear_error on failure
  375.      * @access public
  376.      * @see Net_NNTP::getOverviewFormat()
  377.      * @see Net_NNTP::getReferencesOverview()
  378.      */
  379.     function getOverview($first$last)
  380.     {
  381.         $overview $this->cmdXOver($first.'-'.$last);
  382.         if (PEAR::isError($overview)) {
  383.             return $overview;
  384.         }
  385.  
  386.         return $overview;
  387.     }
  388.  
  389.     // }}}
  390.     // {{{ getOverviewFormat()
  391.  
  392.     /**
  393.      * Returns a list of avaible headers which are send from newsserver to client for every news message
  394.      *
  395.      * @return mixed (array) header names on success or (object) pear_error on failure
  396.      * @access public
  397.      * @see Net_NNTP::getOverview()
  398.      */
  399.     function getOverviewFormat()
  400.     {
  401.         return $this->cmdListOverviewFMT();
  402.     }
  403.  
  404.     // }}}
  405.     // {{{ getOverviewFmt()
  406.  
  407.     /**
  408.      * Returns a list of avaible headers which are send from newsserver to client for every news message
  409.      *
  410.      * @return mixed (array) header names on success or (object) pear_error on failure
  411.      * @access public
  412.      * @deprecated use getOverviewFormat() instead
  413.      */
  414.     function getOverviewFmt()
  415.     {
  416.         return $this->getOverviewFormat();
  417.     }
  418.  
  419.     // }}}
  420.     // {{{ getReferencesOverview()
  421.  
  422.     /**
  423.      * Fetch a list of each message's reference header.
  424.      *
  425.      * @param integer $first first article to fetch
  426.      * @param integer $last  last article to fetch
  427.      *
  428.      * @return mixed (array) nested array of references on success or (object) pear_error on failure
  429.      *
  430.      * @return mixed (array) nested array of message and there headers on success or (object) pear_error on failure
  431.      * @access public
  432.      * @see Net_NNTP::getOverview()
  433.      */
  434.     function getReferencesOverview($first$last)
  435.     {
  436.         $overview $this->cmdXROver($first.'-'.$last);
  437.         if (PEAR::isError($overview)) {
  438.             return $overview;
  439.         }
  440.     
  441.         return $overview;
  442.     }
  443.  
  444.     // }}}
  445.     // {{{ post()
  446.  
  447.     /**
  448.      * Post an article to a number of newsgroups.
  449.      *
  450.      * (Among the aditional headers you might think of adding could be:
  451.      * "NNTP-Posting-Host: <ip-of-author>", which should contain the IP-adress
  452.      * of the author of the post, so the message can be traced back to him.
  453.      * Or "Organization: <org>" which contain the name of the organization
  454.      * the post originates from)
  455.      *
  456.      * @param string $subject The subject of the post.
  457.      * @param string $newsgroup The newsgroup to post to.
  458.      * @param string $from Name + email-adress of sender.
  459.      * @param string $body The body of the post itself.
  460.      * @param optional string $aditional Aditional headers to send.
  461.      *
  462.      * @return mixed (string) server response on success or (object) pear_error on failure
  463.      * @access public
  464.      */
  465.     function post($subject$newsgroup$from$body$aditional '')
  466.     {
  467.         return $this->cmdPost($newsgroup$subject$body$from$aditional);
  468.     }
  469.  
  470.     // }}}
  471.     // {{{ getArticleRaw()
  472.  
  473.     /**
  474.      * Get an article (raw data)
  475.      *
  476.      * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  477.      * @param bool  $implode When true the result array is imploded to a string, defaults to true.
  478.      *
  479.      * @return mixed (array/string) The headers on success or (object) pear_error on failure
  480.      * @access public
  481.      * @since 0.3
  482.      * @see getHeaderRaw()
  483.      * @see getBodyRaw()
  484.      */
  485.     function getArticleRaw($article$implode = true)
  486.     {
  487.         $data $this->cmdArticle($article);
  488.         if (PEAR::isError($data)) {
  489.             return $data;
  490.         }
  491.         if ($implode == true{
  492.             $data implode("\r\n"$data);
  493.         }
  494.         return $data;
  495.     }
  496.  
  497.     // }}}
  498.     // {{{ getArticle()
  499.  
  500.     /**
  501.      * Get an article (deprecated)
  502.      *
  503.      * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  504.      *
  505.      * @return mixed (string) The headers on success or (object) pear_error on failure
  506.      * @access public
  507.      * @deprecated Use getArticleRaw() instead
  508.      */
  509.     function getArticle($article)
  510.     {
  511.         return $this->getArticleRaw($article);
  512.     }
  513.  
  514.     // }}}
  515.     // {{{ getHeaderRaw()
  516.  
  517.     /**
  518.      * Get the headers of an article (raw data)
  519.      *
  520.      * @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
  521.      * @param bool  $implode When true the result array is imploded to a string, defaults to true.
  522.      *
  523.      * @return mixed (array/string) headers on success or (object) pear_error on failure
  524.      * @access public
  525.      * @since 0.3
  526.      * @see getArticleRaw()
  527.      * @see getBodyRaw()
  528.      */
  529.     function getHeaderRaw($article$implode = true)
  530.     {
  531.         $data $this->cmdHead($article);
  532.         if (PEAR::isError($data)) {
  533.             return $data;
  534.         }
  535.         if ($implode == true{
  536.             $data implode("\r\n"$data);
  537.         }
  538.         return $data;
  539.     }
  540.  
  541.     // }}}
  542.     // {{{ getHeaders()
  543.  
  544.     /**
  545.      * Get the headers of an article (deprecated)
  546.      *
  547.      * @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
  548.      *
  549.      * @return mixed (string) headers on success or (object) pear_error on failure
  550.      * @access public
  551.      * @deprecated Use getHeaderRaw() instead
  552.      */
  553.     function getHeaders($article)
  554.     {
  555.         return $this->getHeaderRaw($article);
  556.     }
  557.  
  558.     // }}}
  559.     // {{{ getBodyRaw()
  560.  
  561.     /**
  562.      * Get the body of an article (raw data)
  563.      *
  564.      * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  565.      * @param bool  $implode When true the result array is imploded to a string, defaults to true.
  566.      *
  567.      * @return mixed (array/string) headers on success or (object) pear_error on failure
  568.      * @access public
  569.      * @since 0.3
  570.      * @see getHeaderRaw()
  571.      * @see getArticleRaw()
  572.      */
  573.     function getBodyRaw($article$implode = true)
  574.     {
  575.         $data $this->cmdBody($article);
  576.         if (PEAR::isError($data)) {
  577.             return $data;
  578.         }
  579.         if ($implode == true{
  580.             $data implode("\r\n"$data);
  581.         }
  582.         return $data;
  583.     }
  584.  
  585.     // }}}
  586.     // {{{ getBody()
  587.  
  588.     /**
  589.      * Get the body of an article (deprecated)
  590.      *
  591.      * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  592.      *
  593.      * @return mixed (string) headers on success or (object) pear_error on failure
  594.      * @access public
  595.      * @deprecated Use getBodyRaw() instead
  596.      */
  597.     function getBody($article)
  598.     {
  599.         return $this->getBodyRaw($article);
  600.     }
  601.  
  602.     // }}}
  603.     // {{{ getGroupArticles()
  604.  
  605.     /**
  606.      * Experimental
  607.      *
  608.      * @access public
  609.      * @since 0.3
  610.      */
  611.     function getGroupArticles($newsgroup)
  612.     {
  613.         return $this->cmdListgroup($newsgroup);
  614.     }
  615.  
  616.     // }}}
  617.     // {{{ getNewGroups()
  618.  
  619.     /**
  620.      * Experimental
  621.      *
  622.      * @access public
  623.      * @since 0.3
  624.      */
  625.     function getNewGroups($time)
  626.     {
  627.         switch (gettype($time)) {
  628.             case 'integer':
  629.                 break;
  630.             case 'string':
  631.                 $time = (int) strtotime($time);
  632.                 break;
  633.             default:
  634.                 return PEAR::throwError('');
  635.         }
  636.  
  637.         return $this->cmdNewgroups($time);
  638.     }
  639.  
  640.     // }}}
  641.     // {{{ getNewNews()
  642.  
  643.     /**
  644.      * Experimental
  645.      *
  646.      * @access public
  647.      * @since 0.3
  648.      */
  649.     function getNewNews($time$newsgroups '*')
  650.     {
  651.         switch (gettype($time)) {
  652.             case 'integer':
  653.                 break;
  654.             case 'string':
  655.                 $time = (int) strtotime($time);
  656.                 break;
  657.             default:
  658.                 return PEAR::throwError('UPS...');
  659.         }
  660.  
  661.         return $this->cmdNewnews($time$newsgroups);
  662.     }
  663.  
  664.     // }}}
  665.     // {{{ getDate()
  666.  
  667.     /**
  668.      * Get the NNTP-server's internal date
  669.      *
  670.      * Get the date from the newsserver format of returned date:
  671.      *
  672.      * @param optional int $format
  673.      *   - 0: $date - timestamp
  674.      *   - 1: $date['y'] - year
  675.      *        $date['m'] - month
  676.      *        $date['d'] - day
  677.      *
  678.      * @return mixed (mixed) date on success or (object) pear_error on failure
  679.      * @access public
  680.      * @since 0.3
  681.      */
  682.     function getDate($format = 1)
  683.     {
  684.         $date $this->cmdDate();
  685.         if (PEAR::isError($date)) {
  686.             return $date;
  687.         }
  688.  
  689.         switch ($format{
  690.             case 1:
  691.                 return array('y' => substr($date04)'m' => substr($date42)'d' => substr($date62));
  692.                 break;
  693.  
  694.             case 0:
  695.             default:
  696.                 return $date;
  697.                 break;
  698.         }
  699.     }
  700.  
  701.     // }}}
  702.     // {{{ date()
  703.  
  704.     /**
  705.      * @return mixed (array) date on success or (object) pear_error on failure
  706.      * @access public
  707.      *
  708.      * @deprecated Use getDate() instead
  709.      */
  710.     function date()
  711.     {
  712.         return $this->getDate();
  713.     }
  714.  
  715.     // }}}
  716.     // {{{ count()
  717.  
  718.     /**
  719.      * Number of articles in currently selected group
  720.      *
  721.      * @return integer count
  722.      * @access public
  723.      * @since 0.3
  724.      * @see Net_NNTP::selectGroup()
  725.      * @see Net_NNTP::group()
  726.      * @see Net_NNTP::first()
  727.      * @see Net_NNTP::last()
  728.      */
  729.     function count()
  730.     {
  731.         return $this->_currentGroup['count'];
  732.     }
  733.  
  734.     // }}}
  735.     // {{{ last()
  736.  
  737.     /**
  738.      * Maximum article number in current group
  739.      *
  740.      * @return integer maximum
  741.      * @access public
  742.      * @since 0.3
  743.      * @see Net_NNTP::selectGroup()
  744.      * @see Net_NNTP::group()
  745.      * @see Net_NNTP::first()
  746.      * @see Net_NNTP::count()
  747.      */
  748.     function last()
  749.     {
  750.         return $this->_currentGroup['last'];
  751.     }
  752.  
  753.     // }}}
  754.     // {{{ max()
  755.  
  756.     /**
  757.      * @return integer maximum
  758.      * @access public
  759.      *
  760.      * @deprecated Use last() instead
  761.      */
  762.     function max()
  763.     {
  764.         return $this->last();
  765.     }
  766.  
  767.     // }}}
  768.     // {{{ first()
  769.  
  770.     /**
  771.      * Minimum article number in current group
  772.      *
  773.      * @return integer minimum
  774.      * @access public
  775.      * @since 0.3
  776.      * @see Net_NNTP::selectGroup()
  777.      * @see Net_NNTP::group()
  778.      * @see Net_NNTP::last()
  779.      * @see Net_NNTP::count()
  780.      */
  781.     function first()
  782.     {
  783.         return $this->_currentGroup['first'];
  784.     }
  785.  
  786.     // }}}
  787.     // {{{ min()
  788.  
  789.     /**
  790.      * @return integer minimum
  791.      * @access public
  792.      *
  793.      * @deprecated Use first() instead
  794.      */
  795.     function min()
  796.     {
  797.         return $this->first();
  798.     }
  799.  
  800.     // }}}
  801.     // {{{ group()
  802.  
  803.     /**
  804.      * Currently selected group
  805.      *
  806.      * @return string group
  807.      * @access public
  808.      * @since 0.3
  809.      * @see Net_NNTP::selectGroup()
  810.      * @see Net_NNTP::first()
  811.      * @see Net_NNTP::last()
  812.      * @see Net_NNTP::count()
  813.      */
  814.     function group()
  815.     {
  816.         return $this->_currentGroup['group'];
  817.     }
  818.  
  819.     // }}}
  820.     // {{{ splitHeaders()
  821.  
  822.     /**
  823.      * Get the headers of an article from the currently open connection, and parse them into a keyed array.
  824.      *
  825.      * @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
  826.      *
  827.      * @return mixed (array) Assoc array with headers names as key on success or (object) pear_error on failure
  828.      * @access public
  829.      */
  830.     function splitHeaders($article)
  831.     {
  832.         // Retrieve headers
  833.         $headers $this->getHeaderRaw($articlefalse);
  834.         if (PEAR::isError($headers)) {
  835.             return PEAR::throwError($headers);
  836.         }
  837.     
  838.         $return = array();
  839.  
  840.         // Loop through all header field lines
  841.         foreach ($headers as $field{
  842.             // Separate header name and value
  843.             if (!preg_match('/([\S]+)\:\s*(.*)\s*/'$field$matches)) {
  844.                 // Fail...
  845.             }
  846.             $name $matches[1];
  847.             $value $matches[2];
  848.             unset($matches);
  849.  
  850.             // Add header to $return array
  851.             if (isset($return[$name]AND is_array($return[$name])) {
  852.                 // The header name has already been used at least two times.
  853.                 $return[$name][$value;
  854.             elseif (isset($return[$name])) {
  855.                 // The header name has already been used one time -> change to nedted values.
  856.                 $return[$name= array($return[$name]$value);
  857.             else {
  858.                 // The header name has not used until now.
  859.             $return[$name$value;
  860.             }
  861.         }
  862.  
  863.         return $return;
  864.     }
  865.  
  866.     // }}}
  867.     // {{{ responseCode()
  868.  
  869.     /**
  870.      * returns the response code of a newsserver command
  871.      *
  872.      * @param string $response newsserver answer
  873.      *
  874.      * @return integer response code
  875.      * @access public
  876.      *
  877.      * @deprecated
  878.      */
  879.     function responseCode($response)
  880.     {
  881.         $parts explode(' 'ltrim($response)2);
  882.         return (int) $parts[0];
  883.     }
  884.  
  885.     // }}}
  886.     // {{{ _getData()
  887.  
  888.     /**
  889.      * Get data until a line with only a '.' in it is read and return data.
  890.      *
  891.      * @return mixed (string) data on success or (object) pear_error on failure
  892.      * @access private
  893.      *
  894.      * @deprecated Use _getTextResponse() instead
  895.      */
  896.     function _getData()
  897.     {
  898.         return $this->_getTextResponse();
  899.     }
  900.  
  901.     // }}}
  902.     // {{{ command()
  903.  
  904.     /**
  905.      * Issue a command to the NNTP server
  906.      *
  907.      * @param string $cmd The command to launch, ie: "ARTICLE 1004853"
  908.      *
  909.      * @return mixed (int) response code on success or (object) pear_error on failure
  910.      * @access public
  911.      */
  912.     function command($cmd)
  913.     {
  914.         $code $this->_sendCommand($cmd);
  915.         if (PEAR::isError($code)) {
  916.             return PEAR::throwError($code);
  917.         }
  918.     
  919.         return $code.' '.$this->currentStatusResponse()."\r\n";
  920.     }
  921.  
  922.     // }}}
  923.  
  924. }
  925.  
  926. // }}}
  927.  
  928. ?>

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