home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Contact_Vcard_Parse.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  25.4 KB  |  841 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ 
  3. // +----------------------------------------------------------------------+ 
  4. // | PHP version 4                                                        | 
  5. // +----------------------------------------------------------------------+ 
  6. // | Copyright (c) 1997-2002 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: Paul M. Jones <pmjones@php.net>                             | 
  17. // +----------------------------------------------------------------------+ 
  18. // 
  19. // $Id: Contact_Vcard_Parse.php,v 1.4 2005/05/28 15:40:17 pmjones Exp $ 
  20.  
  21.  
  22. /**
  23. * Parser for vCards.
  24. *
  25. * This class parses vCard 2.1 and 3.0 sources from file or text into a
  26. * structured array.
  27. * Usage:
  28. * <code>
  29. *     // include this class file
  30. *     require_once 'Contact_Vcard_Parse.php';
  31. *     
  32. *     // instantiate a parser object
  33. *     $parse = new Contact_Vcard_Parse();
  34. *     
  35. *     // parse a vCard file and store the data
  36. *     // in $cardinfo
  37. *     $cardinfo = $parse->fromFile('sample.vcf');
  38. *     
  39. *     // view the card info array
  40. *     echo '<pre>';
  41. *     print_r($cardinfo);
  42. *     echo '</pre>';
  43. * </code>
  44. *
  45. * @author Paul M. Jones <pmjones@php.net>
  46. * @package Contact_Vcard_Parse
  47. * @version 1.31
  48. */
  49.  
  50. class Contact_Vcard_Parse {
  51.     
  52.     
  53.     /**
  54.     * 
  55.     * Reads a file for parsing, then sends it to $this->fromText()
  56.     * and returns the results.
  57.     * 
  58.     * @access public
  59.     * 
  60.     * @param array $filename The filename to read for vCard information.
  61.     * 
  62.     * @return array An array of of vCard information extracted from the
  63.     * file.
  64.     * 
  65.     * @see Contact_Vcard_Parse::fromText()
  66.     * 
  67.     * @see Contact_Vcard_Parse::_fromArray()
  68.     * 
  69.     */
  70.     
  71.     function fromFile($filename, $decode_qp = true)
  72.     {
  73.         $text = $this->fileGetContents($filename);
  74.         
  75.         if ($text === false) {
  76.             return false;
  77.         } else {
  78.             // dump to, and get return from, the fromText() method.
  79.             return $this->fromText($text, $decode_qp);
  80.         }
  81.     }
  82.     
  83.     
  84.     /**
  85.     * 
  86.     * Reads the contents of a file.  Included for users whose PHP < 4.3.0.
  87.     * 
  88.     * @access public
  89.     * 
  90.     * @param array $filename The filename to read for vCard information.
  91.     * 
  92.     * @return string|bool The contents of the file if it exists and is
  93.     * readable, or boolean false if not.
  94.     * 
  95.     * @see Contact_Vcard_Parse::fromFile()
  96.     * 
  97.     */
  98.     
  99.     function fileGetContents($filename)
  100.     {
  101.         if (file_exists($filename) &&
  102.             is_readable($filename)) {
  103.             
  104.             $text = '';
  105.             $len = filesize($filename);
  106.             
  107.             $fp = fopen($filename, 'r');
  108.             while ($line = fread($fp, filesize($filename))) {
  109.                 $text .= $line;
  110.             }
  111.             fclose($fp);
  112.             
  113.             return $text;
  114.             
  115.         } else {
  116.         
  117.             return false;
  118.             
  119.         }
  120.     }
  121.     
  122.     
  123.     /**
  124.     * 
  125.     * Prepares a block of text for parsing, then sends it through and
  126.     * returns the results from $this->fromArray().
  127.     * 
  128.     * @access public
  129.     * 
  130.     * @param array $text A block of text to read for vCard information.
  131.     * 
  132.     * @return array An array of vCard information extracted from the
  133.     * source text.
  134.     * 
  135.     * @see Contact_Vcard_Parse::_fromArray()
  136.     * 
  137.     */
  138.     
  139.     function fromText($text, $decode_qp = true)
  140.     {
  141.         // convert all kinds of line endings to Unix-standard and get
  142.         // rid of double blank lines.
  143.         $this->convertLineEndings($text);
  144.         
  145.         // unfold lines.  concat two lines where line 1 ends in \n and
  146.         // line 2 starts with a whitespace character.  only removes
  147.         // the first whitespace character, leaves others in place.
  148.         $fold_regex = '(\n)([ |\t])';
  149.         $text = preg_replace("/$fold_regex/i", "", $text);
  150.         
  151.         // massage for Macintosh OS X Address Book (remove nulls that
  152.         // Address Book puts in for unicode chars)
  153.         $text = str_replace("\x00", '', $text);
  154.         
  155.         // convert the resulting text to an array of lines
  156.         $lines = explode("\n", $text);
  157.         
  158.         // parse the array of lines and return vCard info
  159.         return $this->_fromArray($lines, $decode_qp);
  160.     }
  161.     
  162.     
  163.     /**
  164.     * 
  165.     * Converts line endings in text.
  166.     * 
  167.     * Takes any text block and converts all line endings to UNIX
  168.     * standard. DOS line endings are \r\n, Mac are \r, and UNIX is \n.
  169.     *
  170.     * NOTE: Acts on the text block in-place; does not return a value.
  171.     * 
  172.     * @access public
  173.     * 
  174.     * @param string $text The string on which to convert line endings.
  175.     * 
  176.     * @return void
  177.     * 
  178.     */
  179.     
  180.     function convertLineEndings(&$text)
  181.     {
  182.         // DOS
  183.         $text = str_replace("\r\n", "\n", $text);
  184.         
  185.         // Mac
  186.         $text = str_replace("\r", "\n", $text);
  187.     }
  188.     
  189.     
  190.     /**
  191.     * 
  192.     * Splits a string into an array at semicolons.  Honors backslash-
  193.     * escaped semicolons (i.e., splits at ';' not '\;').
  194.     * 
  195.     * @access public
  196.     * 
  197.     * @param string $text The string to split into an array.
  198.     * 
  199.     * @param bool $convertSingle If splitting the string results in a
  200.     * single array element, return a string instead of a one-element
  201.     * array.
  202.     * 
  203.     * @return mixed An array of values, or a single string.
  204.     * 
  205.     */
  206.     
  207.     function splitBySemi($text, $convertSingle = false)
  208.     {
  209.         // we use these double-backs (\\) because they get get converted
  210.         // to single-backs (\) by preg_split.  the quad-backs (\\\\) end
  211.         // up as as double-backs (\\), which is what preg_split requires
  212.         // to indicate a single backslash (\). what a mess.
  213.         $regex = '(?<!\\\\)(\;)';
  214.         $tmp = preg_split("/$regex/i", $text);
  215.         
  216.         // if there is only one array-element and $convertSingle is
  217.         // true, then return only the value of that one array element
  218.         // (instead of returning the array).
  219.         if ($convertSingle && count($tmp) == 1) {
  220.             return $tmp[0];
  221.         } else {
  222.             return $tmp;
  223.         }
  224.     }
  225.     
  226.     
  227.     /**
  228.     * 
  229.     * Splits a string into an array at commas.  Honors backslash-
  230.     * escaped commas (i.e., splits at ',' not '\,').
  231.     * 
  232.     * @access public
  233.     * 
  234.     * @param string $text The string to split into an array.
  235.     * 
  236.     * @param bool $convertSingle If splitting the string results in a
  237.     * single array element, return a string instead of a one-element
  238.     * array.
  239.     * 
  240.     * @return mixed An array of values, or a single string.
  241.     * 
  242.     */
  243.     
  244.     function splitByComma($text, $convertSingle = false)
  245.     {
  246.         // we use these double-backs (\\) because they get get converted
  247.         // to single-backs (\) by preg_split.  the quad-backs (\\\\) end
  248.         // up as as double-backs (\\), which is what preg_split requires
  249.         // to indicate a single backslash (\). ye gods, how ugly.
  250.         $regex = '(?<!\\\\)(\,)';
  251.         $tmp = preg_split("/$regex/i", $text);
  252.         
  253.         // if there is only one array-element and $convertSingle is
  254.         // true, then return only the value of that one array element
  255.         // (instead of returning the array).
  256.         if ($convertSingle && count($tmp) == 1) {
  257.             return $tmp[0];
  258.         } else {
  259.             return $tmp;
  260.         }
  261.     }
  262.     
  263.     
  264.     /**
  265.     * 
  266.     * Used to make string human-readable after being a vCard value.
  267.     * 
  268.     * Converts...
  269.     *     \: => :
  270.     *     \; => ;
  271.     *     \, => ,
  272.     *     literal \n => newline
  273.     * 
  274.     * @access public
  275.     * 
  276.     * @param mixed $text The text to unescape.
  277.     * 
  278.     * @return void
  279.     * 
  280.     */
  281.     
  282.     function unescape(&$text)
  283.     {
  284.         if (is_array($text)) {
  285.             foreach ($text as $key => $val) {
  286.                 $this->unescape($val);
  287.                 $text[$key] = $val;
  288.             }
  289.         } else {
  290.             $text = str_replace('\:', ':', $text);
  291.             $text = str_replace('\;', ';', $text);
  292.             $text = str_replace('\,', ',', $text);
  293.             $text = str_replace('\n', "\n", $text);
  294.         }
  295.     }
  296.     
  297.     
  298.     /**
  299.     *
  300.     * Emulated destructor.
  301.     *
  302.     * @access private
  303.     * @return boolean true
  304.     *
  305.     */
  306.     
  307.     function _Contact_Vcard_Parse()
  308.     {
  309.         return true;
  310.     }
  311.     
  312.     
  313.     /**
  314.     * 
  315.     * Parses an array of source lines and returns an array of vCards.
  316.     * Each element of the array is itself an array expressing the types,
  317.     * parameters, and values of each part of the vCard. Processes both
  318.     * 2.1 and 3.0 vCard sources.
  319.     *
  320.     * @access private
  321.     * 
  322.     * @param array $source An array of lines to be read for vCard
  323.     * information.
  324.     * 
  325.     * @return array An array of of vCard information extracted from the
  326.     * source array.
  327.     * 
  328.     */
  329.     
  330.     function _fromArray($source, $decode_qp = true)
  331.     {
  332.         // the info array will hold all resulting vCard information.
  333.         $info = array();
  334.         
  335.         // tells us whether the source text indicates the beginning of a
  336.         // new vCard with a BEGIN:VCARD tag.
  337.         $begin = false;
  338.         
  339.         // holds information about the current vCard being read from the
  340.         // source text.
  341.         $card = array();
  342.         
  343.         // loop through each line in the source array
  344.         foreach ($source as $line) {
  345.             
  346.             // if the line is blank, skip it.
  347.             if (trim($line) == '') {
  348.                 continue;
  349.             }
  350.             
  351.             // find the first instance of ':' on the line.  The part
  352.             // to the left of the colon is the type and parameters;
  353.             // the part to the right of the colon is the value data.
  354.             $pos = strpos($line, ':');
  355.             
  356.             // if there is no colon, skip the line.
  357.             if ($pos === false) {
  358.                 continue;
  359.             }
  360.             
  361.             // get the left and right portions
  362.             $left = trim(substr($line, 0, $pos));
  363.             $right = trim(substr($line, $pos+1, strlen($line)));
  364.             
  365.             // have we started yet?
  366.             if (! $begin) {
  367.                 
  368.                 // nope.  does this line indicate the beginning of
  369.                 // a new vCard?
  370.                 if (strtoupper($left) == 'BEGIN' &&
  371.                     strtoupper($right) == 'VCARD') {
  372.                     
  373.                     // tell the loop that we've begun a new card
  374.                     $begin = true;
  375.                 }
  376.                 
  377.                 // regardless, loop to the next line of source. if begin
  378.                 // is still false, the next loop will check the line. if
  379.                 // begin has now been set to true, the loop will start
  380.                 // collecting card info.
  381.                 continue;
  382.                 
  383.             } else {
  384.                 
  385.                 // yep, we've started, but we don't know how far along
  386.                 // we are in the card. is this the ending line of the
  387.                 // current vCard?
  388.                 if (strtoupper($left) == 'END' &&
  389.                     strtoupper($right) == 'VCARD') {
  390.                     
  391.                     // yep, we're done. keep the info from the current
  392.                     // card...
  393.                     $info[] = $card;
  394.                     
  395.                     // ...and reset to grab a new card if one exists in
  396.                     // the source array.
  397.                     $begin = false;
  398.                     $card = array();
  399.                     
  400.                 } else {
  401.                     
  402.                     // we're not on an ending line, so collect info from
  403.                     // this line into the current card. split the
  404.                     // left-portion of the line into a type-definition
  405.                     // (the kind of information) and parameters for the
  406.                     // type.
  407.                     $typedef = $this->_getTypeDef($left);
  408.                     $params = $this->_getParams($left);
  409.                     
  410.                     // if we are decoding quoted-printable, do so now.
  411.                     // QUOTED-PRINTABLE is not allowed in version 3.0,
  412.                     // but we don't check for versioning, so we do it
  413.                     // regardless.  ;-)
  414.                     $this->_decode_qp($params, $right);
  415.                     
  416.                     // now get the value-data from the line, based on
  417.                     // the typedef
  418.                     switch ($typedef) {
  419.                         
  420.                     case 'N':
  421.                         // structured name of the person
  422.                         $value = $this->_parseN($right);
  423.                         break;
  424.                         
  425.                     case 'ADR':
  426.                         // structured address of the person
  427.                         $value = $this->_parseADR($right);
  428.                         break;
  429.                         
  430.                     case 'NICKNAME':
  431.                         // nicknames
  432.                         $value = $this->_parseNICKNAME($right);
  433.                         break;
  434.                         
  435.                     case 'ORG':
  436.                         // organizations the person belongs to
  437.                         $value = $this->_parseORG($right);
  438.                         break;
  439.                         
  440.                     case 'CATEGORIES':
  441.                         // categories to which this card is assigned
  442.                         $value = $this->_parseCATEGORIES($right);
  443.                         break;
  444.                         
  445.                     case 'GEO':
  446.                         // geographic coordinates
  447.                         $value = $this->_parseGEO($right);
  448.                         break;
  449.                         
  450.                     default:
  451.                         // by default, just grab the plain value. keep
  452.                         // as an array to make sure *all* values are
  453.                         // arrays.  for consistency. ;-)
  454.                         $value = array(array($right));
  455.                         break;
  456.                     }
  457.                     
  458.                     // add the type, parameters, and value to the
  459.                     // current card array.  note that we allow multiple
  460.                     // instances of the same type, which might be dumb
  461.                     // in some cases (e.g., N).
  462.                     $card[$typedef][] = array(
  463.                         'param' => $params,
  464.                         'value' => $value
  465.                     );
  466.                 }
  467.             }
  468.         }
  469.         
  470.         $this->unescape($info);
  471.         return $info;
  472.     }
  473.     
  474.     
  475.     /**
  476.     *
  477.     * Takes a vCard line and extracts the Type-Definition for the line.
  478.     * 
  479.     * @access private
  480.     *
  481.     * @param string $text A left-part (before-the-colon part) from a
  482.     * vCard line.
  483.     * 
  484.     * @return string The type definition for the line.
  485.     * 
  486.     */
  487.     
  488.     function _getTypeDef($text)
  489.     {
  490.         // split the text by semicolons
  491.         $split = $this->splitBySemi($text);
  492.         
  493.         // only return first element (the typedef)
  494.         return strtoupper($split[0]);
  495.     }
  496.     
  497.     
  498.     /**
  499.     *
  500.     * Finds the Type-Definition parameters for a vCard line.
  501.     * 
  502.     * @access private
  503.     * 
  504.     * @param string $text A left-part (before-the-colon part) from a
  505.     * vCard line.
  506.     * 
  507.     * @return mixed An array of parameters.
  508.     * 
  509.     */
  510.     
  511.     function _getParams($text)
  512.     {
  513.         // split the text by semicolons into an array
  514.         $split = $this->splitBySemi($text);
  515.         
  516.         // drop the first element of the array (the type-definition)
  517.         array_shift($split);
  518.         
  519.         // set up an array to retain the parameters, if any
  520.         $params = array();
  521.         
  522.         // loop through each parameter.  the params may be in the format...
  523.         // "TYPE=type1,type2,type3"
  524.         //    ...or...
  525.         // "TYPE=type1;TYPE=type2;TYPE=type3"
  526.         foreach ($split as $full) {
  527.             
  528.             // split the full parameter at the equal sign so we can tell
  529.             // the parameter name from the parameter value
  530.             $tmp = explode("=", $full);
  531.             
  532.             // the key is the left portion of the parameter (before
  533.             // '='). if in 2.1 format, the key may in fact be the
  534.             // parameter value, not the parameter name.
  535.             $key = strtoupper(trim($tmp[0]));
  536.             
  537.             // get the parameter name by checking to see if it's in
  538.             // vCard 2.1 or 3.0 format.
  539.             $name = $this->_getParamName($key);
  540.             
  541.             // list of all parameter values
  542.             $listall = trim($tmp[1]);
  543.             
  544.             // if there is a value-list for this parameter, they are
  545.             // separated by commas, so split them out too.
  546.             $list = $this->splitByComma($listall);
  547.             
  548.             // now loop through each value in the parameter and retain
  549.             // it.  if the value is blank, that means it's a 2.1-style
  550.             // param, and the key itself is the value.
  551.             foreach ($list as $val) {
  552.                 if (trim($val) != '') {
  553.                     // 3.0 formatted parameter
  554.                     $params[$name][] = trim($val);
  555.                 } else {
  556.                     // 2.1 formatted parameter
  557.                     $params[$name][] = $key;
  558.                 }
  559.             }
  560.             
  561.             // if, after all this, there are no parameter values for the
  562.             // parameter name, retain no info about the parameter (saves
  563.             // ram and checking-time later).
  564.             if (count($params[$name]) == 0) {
  565.                 unset($params[$name]);
  566.             }
  567.         }
  568.         
  569.         // return the parameters array.
  570.         return $params;
  571.     }
  572.     
  573.     
  574.     /**
  575.     *
  576.     * Looks at the parameters of a vCard line; if one of them is
  577.     * ENCODING[] => QUOTED-PRINTABLE then decode the text in-place.
  578.     * 
  579.     * @access private
  580.     * 
  581.     * @param array $params A parameter array from a vCard line.
  582.     * 
  583.     * @param string $text A right-part (after-the-colon part) from a
  584.     * vCard line.
  585.     *
  586.     * @return void
  587.     * 
  588.     */
  589.     
  590.     function _decode_qp(&$params, &$text)
  591.     {
  592.         // loop through each parameter
  593.         foreach ($params as $param_key => $param_val) {
  594.             
  595.             // check to see if it's an encoding param
  596.             if (trim(strtoupper($param_key)) == 'ENCODING') {
  597.             
  598.                 // loop through each encoding param value
  599.                 foreach ($param_val as $enc_key => $enc_val) {
  600.                 
  601.                     // if any of the values are QP, decode the text
  602.                     // in-place and return
  603.                     if (trim(strtoupper($enc_val)) == 'QUOTED-PRINTABLE') {
  604.                         $text = quoted_printable_decode($text);
  605.                         return;
  606.                     }
  607.                 }
  608.             }
  609.         }
  610.     }
  611.     
  612.     
  613.     /**
  614.     * 
  615.     * Returns parameter names from 2.1-formatted vCards.
  616.     *
  617.     * The vCard 2.1 specification allows parameter values without a
  618.     * name. The parameter name is then determined from the unique
  619.     * parameter value.
  620.     * 
  621.     * Shamelessly lifted from Frank Hellwig <frank@hellwig.org> and his
  622.     * vCard PHP project <http://vcardphp.sourceforge.net>.
  623.     * 
  624.     * @access private
  625.     * 
  626.     * @param string $value The first element in a parameter name-value
  627.     * pair.
  628.     * 
  629.     * @return string The proper parameter name (TYPE, ENCODING, or
  630.     * VALUE).
  631.     * 
  632.     */
  633.      
  634.     function _getParamName($value)
  635.     {
  636.         static $types = array (
  637.             'DOM', 'INTL', 'POSTAL', 'PARCEL','HOME', 'WORK',
  638.             'PREF', 'VOICE', 'FAX', 'MSG', 'CELL', 'PAGER',
  639.             'BBS', 'MODEM', 'CAR', 'ISDN', 'VIDEO',
  640.             'AOL', 'APPLELINK', 'ATTMAIL', 'CIS', 'EWORLD',
  641.             'INTERNET', 'IBMMAIL', 'MCIMAIL',
  642.             'POWERSHARE', 'PRODIGY', 'TLX', 'X400',
  643.             'GIF', 'CGM', 'WMF', 'BMP', 'MET', 'PMB', 'DIB',
  644.             'PICT', 'TIFF', 'PDF', 'PS', 'JPEG', 'QTIME',
  645.             'MPEG', 'MPEG2', 'AVI',
  646.             'WAVE', 'AIFF', 'PCM',
  647.             'X509', 'PGP'
  648.         );
  649.         
  650.         // CONTENT-ID added by pmj
  651.         static $values = array (
  652.             'INLINE', 'URL', 'CID', 'CONTENT-ID'
  653.         );
  654.         
  655.         // 8BIT added by pmj
  656.         static $encodings = array (
  657.             '7BIT', '8BIT', 'QUOTED-PRINTABLE', 'BASE64'
  658.         );
  659.         
  660.         // changed by pmj to the following so that the name defaults to
  661.         // whatever the original value was.  Frank Hellwig's original
  662.         // code was "$name = 'UNKNOWN'".
  663.         $name = $value;
  664.         
  665.         if (in_array($value, $types)) {
  666.             $name = 'TYPE';
  667.         } elseif (in_array($value, $values)) {
  668.             $name = 'VALUE';
  669.         } elseif (in_array($value, $encodings)) {
  670.             $name = 'ENCODING';
  671.         }
  672.         
  673.         return $name;
  674.     }
  675.     
  676.     
  677.     /**
  678.     *
  679.     * Parses a vCard line value identified as being of the "N"
  680.     * (structured name) type-defintion.
  681.     *
  682.     * @access private
  683.     *
  684.     * @param string $text The right-part (after-the-colon part) of a
  685.     * vCard line.
  686.     * 
  687.     * @return array An array of key-value pairs where the key is the
  688.     * portion-name and the value is the portion-value.  The value itself
  689.     * may be an array as well if multiple comma-separated values were
  690.     * indicated in the vCard source.
  691.     *
  692.     */
  693.     
  694.     function _parseN($text)
  695.     {
  696.         // make sure there are always at least 5 elements
  697.         $tmp = array_pad($this->splitBySemi($text), 5, '');
  698.         return array(
  699.             $this->splitByComma($tmp[0]), // family (last)
  700.             $this->splitByComma($tmp[1]), // given (first)
  701.             $this->splitByComma($tmp[2]), // addl (middle)
  702.             $this->splitByComma($tmp[3]), // prefix
  703.             $this->splitByComma($tmp[4])  // suffix
  704.         );
  705.     }
  706.     
  707.     
  708.     /**
  709.     *
  710.     * Parses a vCard line value identified as being of the "ADR"
  711.     * (structured address) type-defintion.
  712.     *
  713.     * @access private
  714.     *
  715.     * @param string $text The right-part (after-the-colon part) of a
  716.     * vCard line.
  717.     * 
  718.     * @return array An array of key-value pairs where the key is the
  719.     * portion-name and the value is the portion-value.  The value itself
  720.     * may be an array as well if multiple comma-separated values were
  721.     * indicated in the vCard source.
  722.     *
  723.     */
  724.     
  725.     function _parseADR($text)
  726.     {
  727.         // make sure there are always at least 7 elements
  728.         $tmp = array_pad($this->splitBySemi($text), 7, '');
  729.         return array(
  730.             $this->splitByComma($tmp[0]), // pob
  731.             $this->splitByComma($tmp[1]), // extend
  732.             $this->splitByComma($tmp[2]), // street
  733.             $this->splitByComma($tmp[3]), // locality (city)
  734.             $this->splitByComma($tmp[4]), // region (state)
  735.             $this->splitByComma($tmp[5]), // postcode (ZIP)
  736.             $this->splitByComma($tmp[6])  // country
  737.         );
  738.     }
  739.     
  740.     
  741.     /**
  742.     * 
  743.     * Parses a vCard line value identified as being of the "NICKNAME"
  744.     * (informal or descriptive name) type-defintion.
  745.     *
  746.     * @access private
  747.     * 
  748.     * @param string $text The right-part (after-the-colon part) of a
  749.     * vCard line.
  750.     * 
  751.     * @return array An array of nicknames.
  752.     *
  753.     */
  754.     
  755.     function _parseNICKNAME($text)
  756.     {
  757.         return array($this->splitByComma($text));
  758.     }
  759.     
  760.     
  761.     /**
  762.     * 
  763.     * Parses a vCard line value identified as being of the "ORG"
  764.     * (organizational info) type-defintion.
  765.     *
  766.     * @access private
  767.     *
  768.     * @param string $text The right-part (after-the-colon part) of a
  769.     * vCard line.
  770.     * 
  771.     * @return array An array of organizations; each element of the array
  772.     * is itself an array, which indicates primary organization and
  773.     * sub-organizations.
  774.     *
  775.     */
  776.     
  777.     function _parseORG($text)
  778.     {
  779.         $tmp = $this->splitbySemi($text);
  780.         $list = array();
  781.         foreach ($tmp as $val) {
  782.             $list[] = array($val);
  783.         }
  784.         
  785.         return $list;
  786.     }
  787.     
  788.     
  789.     /**
  790.     * 
  791.     * Parses a vCard line value identified as being of the "CATEGORIES"
  792.     * (card-category) type-defintion.
  793.     *
  794.     * @access private
  795.     * 
  796.     * @param string $text The right-part (after-the-colon part) of a
  797.     * vCard line.
  798.     * 
  799.     * @return mixed An array of categories.
  800.     *
  801.     */
  802.     
  803.     function _parseCATEGORIES($text)
  804.     {
  805.         return array($this->splitByComma($text));
  806.     }
  807.     
  808.     
  809.     /**
  810.     * 
  811.     * Parses a vCard line value identified as being of the "GEO"
  812.     * (geographic coordinate) type-defintion.
  813.     *
  814.     * @access private
  815.     *
  816.     * @param string $text The right-part (after-the-colon part) of a
  817.     * vCard line.
  818.     * 
  819.     * @return mixed An array of lat-lon geocoords.
  820.     *
  821.     */
  822.     
  823.     function _parseGEO($text)
  824.     {
  825.         // make sure there are always at least 2 elements
  826.         $tmp = array_pad($this->splitBySemi($text), 2, '');
  827.         return array(
  828.             array($tmp[0]), // lat
  829.             array($tmp[1])  // lon
  830.         );
  831.     }
  832. }
  833.  
  834. ?>