Source for file contact.php

Documentation is available at contact.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_contact
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 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.Administrator
  14.  * @subpackage  com_contact
  15.  */
  16. class ContactTableContact extends JTable
  17. {
  18.     /**
  19.      * Constructor
  20.      *
  21.      * @param   JDatabaseDriver  &$db  Database connector object
  22.      *
  23.      * @since   1.0
  24.      */
  25.     public function __construct(&$db)
  26.     {
  27.         parent::__construct('#__contact_details''id'$db);
  28.     }
  29.  
  30.     /**
  31.      * Overloaded bind function
  32.      *
  33.      * @param   array  $array   Named array to bind
  34.      * @param   mixed  $ignore  An optional array or space separated list of properties to ignore while binding.
  35.      *
  36.      * @return  mixed  Null if operation was satisfactory, otherwise returns an error
  37.      * @since   1.6
  38.      */
  39.     public function bind($array$ignore '')
  40.     {
  41.         if (isset($array['params']&& is_array($array['params']))
  42.         {
  43.             $registry new JRegistry;
  44.             $registry->loadArray($array['params']);
  45.             $array['params'= (string) $registry;
  46.         }
  47.  
  48.         if (isset($array['metadata']&& is_array($array['metadata']))
  49.         {
  50.             $registry new JRegistry;
  51.             $registry->loadArray($array['metadata']);
  52.             $array['metadata'= (string) $registry;
  53.         }
  54.  
  55.         return parent::bind($array$ignore);
  56.     }
  57.  
  58.     /**
  59.      * Stores a contact
  60.      *
  61.      * @param   boolean  True to update fields even if they are null.
  62.      *
  63.      * @return  boolean  True on success, false on failure.
  64.      *
  65.      * @since   1.6
  66.      */
  67.     public function store($updateNulls false)
  68.     {
  69.         // Transform the params field
  70.         if (is_array($this->params))
  71.         {
  72.             $registry new JRegistry;
  73.             $registry->loadArray($this->params);
  74.             $this->params = (string) $registry;
  75.         }
  76.  
  77.         $date    JFactory::getDate();
  78.         $user    JFactory::getUser();
  79.  
  80.         if ($this->id)
  81.         {
  82.             // Existing item
  83.             $this->modified        $date->toSql();
  84.             $this->modified_by    $user->get('id');
  85.         }
  86.         else
  87.         {
  88.             // New contact. A contact created and created_by field can be set by the user,
  89.             // so we don't touch either of these if they are set.
  90.             if (!(int) $this->created)
  91.             {
  92.                 $this->created $date->toSql();
  93.             }
  94.             if (empty($this->created_by))
  95.             {
  96.                 $this->created_by $user->get('id');
  97.             }
  98.         }
  99.  
  100.         // Set publish_up to null date if not set
  101.         if (!$this->publish_up)
  102.         {
  103.             $this->publish_up $this->_db->getNullDate();
  104.         }
  105.  
  106.         // Set publish_down to null date if not set
  107.         if (!$this->publish_down)
  108.         {
  109.             $this->publish_down $this->_db->getNullDate();
  110.         }
  111.  
  112.         // Set xreference to empty string if not set
  113.         if (!$this->xreference)
  114.         {
  115.             $this->xreference '';
  116.         }
  117.  
  118.         // Store utf8 email as punycode
  119.         $this->email_to JStringPunycode::emailToPunycode($this->email_to);
  120.  
  121.         // Convert IDN urls to punycode
  122.         $this->webpage JStringPunycode::urlToPunycode($this->webpage);
  123.  
  124.         // Verify that the alias is unique
  125.         $table JTable::getInstance('Contact''ContactTable');
  126.         if ($table->load(array('alias' => $this->alias'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0))
  127.         {
  128.             $this->setError(JText::_('COM_CONTACT_ERROR_UNIQUE_ALIAS'));
  129.  
  130.             return false;
  131.         }
  132.  
  133.         return parent::store($updateNulls);
  134.     }
  135.  
  136.     /**
  137.      * Overloaded check function
  138.      *
  139.      * @return  boolean  True on success, false on failure
  140.      *
  141.      * @see JTable::check
  142.      * @since 1.5
  143.      */
  144.     public function check()
  145.     {
  146.         $this->default_con = (int) $this->default_con;
  147.  
  148.         if (JFilterInput::checkAttribute(array ('href'$this->webpage)))
  149.         {
  150.             $this->setError(JText::_('COM_CONTACT_WARNING_PROVIDE_VALID_URL'));
  151.  
  152.             return false;
  153.         }
  154.  
  155.         /** check for valid name */
  156.         if (trim($this->name== '')
  157.         {
  158.             $this->setError(JText::_('COM_CONTACT_WARNING_PROVIDE_VALID_NAME'));
  159.  
  160.             return false;
  161.         }
  162.  
  163.         if (empty($this->alias))
  164.         {
  165.             $this->alias $this->name;
  166.         }
  167.         $this->alias JApplication::stringURLSafe($this->alias);
  168.         if (trim(str_replace('-'''$this->alias)) == '')
  169.         {
  170.             $this->alias JFactory::getDate()->format("Y-m-d-H-i-s");
  171.         }
  172.         /** check for valid category */
  173.         if (trim($this->catid== '')
  174.         {
  175.             $this->setError(JText::_('COM_CONTACT_WARNING_CATEGORY'));
  176.  
  177.             return false;
  178.         }
  179.  
  180.         // Check the publish down date is not earlier than publish up.
  181.         if ((int) $this->publish_down && $this->publish_down $this->publish_up)
  182.         {
  183.             $this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
  184.  
  185.             return false;
  186.         }
  187.  
  188.         // Clean up keywords -- eliminate extra spaces between phrases
  189.         // and cr (\r) and lf (\n) characters from string
  190.         if (!empty($this->metakey))
  191.         {
  192.             // Only process if not empty
  193.             $bad_characters array("\n""\r""\"""<"">")// array of characters to remove
  194.             $after_clean JString::str_ireplace($bad_characters""$this->metakey)// remove bad characters
  195.             $keys explode(','$after_clean)// create array using commas as delimiter
  196.             $clean_keys array();
  197.  
  198.             foreach($keys as $key)
  199.             {
  200.                 if (trim($key)) {  // ignore blank keywords
  201.                     $clean_keys[trim($key);
  202.                 }
  203.             }
  204.             $this->metakey implode(", "$clean_keys)// put array back together delimited by ", "
  205.         }
  206.  
  207.         // Clean up description -- eliminate quotes and <> brackets
  208.         if (!empty($this->metadesc))
  209.         {
  210.             // Only process if not empty
  211.             $bad_characters array("\"""<"">");
  212.             $this->metadesc JString::str_ireplace($bad_characters""$this->metadesc);
  213.         }
  214.  
  215.         return true;
  216.     }
  217. }

Documentation generated on Tue, 19 Nov 2013 14:56:38 +0100 by phpDocumentor 1.4.3