Joomla! PHP Cross Reference Web Portals

Source: /components/com_contact/views/contact/view.vcf.php - 95 lines - 2924 bytes - Summary - Text - Print

   1  <?php
   2  /**
   3   * @package     Joomla.Site
   4   * @subpackage  com_contact
   5   *
   6   * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   7   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  defined('_JEXEC') or die;
  11  
  12  /**
  13   * @package     Joomla.Site
  14   * @subpackage  com_contact
  15   */
  16  class ContactViewContact extends JViewLegacy
  17  {
  18      protected $state;
  19  
  20      protected $item;
  21  
  22  	public function display()
  23      {
  24          // Get model data.
  25          $state = $this->get('State');
  26          $item = $this->get('Item');
  27  
  28          // Check for errors.
  29          if (count($errors = $this->get('Errors'))) {
  30              JError::raiseWarning(500, implode("\n", $errors));
  31              return false;
  32          }
  33  
  34          $doc = JFactory::getDocument();
  35          $doc->setMetaData('Content-Type', 'text/directory', true);
  36  
  37          $app        = JFactory::getApplication();
  38          $params     = $app->getParams();
  39          $user        = JFactory::getUser();
  40          $dispatcher = JEventDispatcher::getInstance();
  41  
  42          // Compute lastname, firstname and middlename
  43          $item->name = trim($item->name);
  44  
  45          // "Lastname, Firstname Midlename" format support
  46          // e.g. "de Gaulle, Charles"
  47          $namearray = explode(',', $item->name);
  48          if (count($namearray) > 1 ) {
  49              $lastname = $namearray[0];
  50              $card_name = $lastname;
  51              $name_and_midname = trim($namearray[1]);
  52  
  53              $firstname = '';
  54              if (!empty($name_and_midname)) {
  55                  $namearray = explode(' ', $name_and_midname);
  56  
  57                  $firstname = $namearray[0];
  58                  $middlename = (count($namearray) > 1) ? $namearray[1] : '';
  59                  $card_name = $firstname . ' ' . ($middlename ? $middlename . ' ' : '') .  $card_name;
  60              }
  61          }
  62          // "Firstname Middlename Lastname" format support
  63          else {
  64              $namearray = explode(' ', $item->name);
  65  
  66              $middlename = (count($namearray) > 2) ? $namearray[1] : '';
  67              $firstname = array_shift($namearray);
  68              $lastname = count($namearray) ? end($namearray) : '';
  69              $card_name = $firstname . ($middlename ? ' ' . $middlename : '') . ($lastname ? ' ' . $lastname : '');
  70          }
  71  
  72          $rev = date('c', strtotime($item->modified));
  73  
  74          JResponse::setHeader('Content-disposition', 'attachment; filename="'.$card_name.'.vcf"', true);
  75  
  76          $vcard = array();
  77          $vcard[] .= 'BEGIN:VCARD';
  78          $vcard[] .= 'VERSION:3.0';
  79          $vcard[]  = 'N:'.$lastname.';'.$firstname.';'.$middlename;
  80          $vcard[]  = 'FN:'. $item->name;
  81          $vcard[]  = 'TITLE:'.$item->con_position;
  82          $vcard[]  = 'TEL;TYPE=WORK,VOICE:'.$item->telephone;
  83          $vcard[]  = 'TEL;TYPE=WORK,FAX:'.$item->fax;
  84          $vcard[]  = 'TEL;TYPE=WORK,MOBILE:'.$item->mobile;
  85          $vcard[]  = 'ADR;TYPE=WORK:;;'.$item->address.';'.$item->suburb.';'.$item->state.';'.$item->postcode.';'.$item->country;
  86          $vcard[]  = 'LABEL;TYPE=WORK:'.$item->address."\n".$item->suburb."\n".$item->state."\n".$item->postcode."\n".$item->country;
  87          $vcard[]  = 'EMAIL;TYPE=PREF,INTERNET:'.$item->email_to;
  88          $vcard[]  = 'URL:'.$item->webpage;
  89          $vcard[]  = 'REV:'.$rev.'Z';
  90          $vcard[]  = 'END:VCARD';
  91  
  92          echo implode("\n", $vcard);
  93          return true;
  94      }
  95  }

title

Description

title

Description

title

Description

title

title

Body