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

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