[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_contact/tables/ -> contact.php (source)

   1  <?php
   2  /**
   3   * @package        Joomla.Administrator
   4   * @subpackage    com_contact
   5   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   6   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   7   */
   8  
   9  // No direct access
  10  defined('_JEXEC') or die;
  11  
  12  
  13  /**
  14   * @package        Joomla.Administrator
  15   * @subpackage    com_contact
  16   */
  17  class ContactTableContact extends JTable
  18  {
  19      /**
  20       * Constructor
  21       *
  22       * @param object Database connector object
  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        Named array
  34       * @return    null|string    null is operation was satisfactory, otherwise returns an error
  35       * @since    1.6
  36       */
  37  	public function bind($array, $ignore = '')
  38      {
  39          if (isset($array['params']) && is_array($array['params'])) {
  40              $registry = new JRegistry();
  41              $registry->loadArray($array['params']);
  42              $array['params'] = (string) $registry;
  43          }
  44  
  45          if (isset($array['metadata']) && is_array($array['metadata'])) {
  46              $registry = new JRegistry();
  47              $registry->loadArray($array['metadata']);
  48              $array['metadata'] = (string) $registry;
  49          }
  50  
  51          return parent::bind($array, $ignore);
  52      }
  53  
  54      /**
  55       * Stores a contact
  56       *
  57       * @param    boolean    True to update fields even if they are null.
  58       * @return    boolean    True on success, false on failure.
  59       * @since    1.6
  60       */
  61  	public function store($updateNulls = false)
  62      {
  63          // Transform the params field
  64          if (is_array($this->params)) {
  65              $registry = new JRegistry();
  66              $registry->loadArray($this->params);
  67              $this->params = (string)$registry;
  68          }
  69  
  70          $date    = JFactory::getDate();
  71          $user    = JFactory::getUser();
  72          if ($this->id) {
  73              // Existing item
  74              $this->modified        = $date->toSql();
  75              $this->modified_by    = $user->get('id');
  76          } else {
  77              // New newsfeed. A feed created and created_by field can be set by the user,
  78              // so we don't touch either of these if they are set.
  79              if (!intval($this->created)) {
  80                  $this->created = $date->toSql();
  81              }
  82              if (empty($this->created_by)) {
  83                  $this->created_by = $user->get('id');
  84              }
  85          }
  86          // Verify that the alias is unique
  87          $table = JTable::getInstance('Contact', 'ContactTable');
  88          if ($table->load(array('alias'=>$this->alias, 'catid'=>$this->catid)) && ($table->id != $this->id || $this->id==0)) {
  89              $this->setError(JText::_('COM_CONTACT_ERROR_UNIQUE_ALIAS'));
  90              return false;
  91          }
  92  
  93          // Attempt to store the data.
  94          return parent::store($updateNulls);
  95      }
  96  
  97      /**
  98       * Overloaded check function
  99       *
 100       * @return boolean
 101       * @see JTable::check
 102       * @since 1.5
 103       */
 104  	function check()
 105      {
 106          $this->default_con = intval($this->default_con);
 107  
 108          if (JFilterInput::checkAttribute(array ('href', $this->webpage))) {
 109              $this->setError(JText::_('COM_CONTACT_WARNING_PROVIDE_VALID_URL'));
 110              return false;
 111          }
 112  
 113          /** check for valid name */
 114          if (trim($this->name) == '') {
 115              $this->setError(JText::_('COM_CONTACT_WARNING_PROVIDE_VALID_NAME'));
 116              return false;
 117          }
 118                  /** check for existing name */
 119          $query = 'SELECT id FROM #__contact_details WHERE name = '.$this->_db->Quote($this->name).' AND catid = '.(int) $this->catid;
 120          $this->_db->setQuery($query);
 121  
 122          $xid = intval($this->_db->loadResult());
 123          if ($xid && $xid != intval($this->id)) {
 124              $this->setError(JText::_('COM_CONTACT_WARNING_SAME_NAME'));
 125              return false;
 126          }
 127  
 128          if (empty($this->alias)) {
 129              $this->alias = $this->name;
 130          }
 131          $this->alias = JApplication::stringURLSafe($this->alias);
 132          if (trim(str_replace('-', '', $this->alias)) == '') {
 133              $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s");
 134          }
 135          /** check for valid category */
 136          if (trim($this->catid) == '') {
 137              $this->setError(JText::_('COM_CONTACT_WARNING_CATEGORY'));
 138              return false;
 139          }
 140  
 141          // Check the publish down date is not earlier than publish up.
 142          if (intval($this->publish_down) > 0 && $this->publish_down < $this->publish_up) {
 143              $this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
 144              return false;
 145          }
 146  
 147          return true;
 148          // clean up keywords -- eliminate extra spaces between phrases
 149          // and cr (\r) and lf (\n) characters from string
 150          if (!empty($this->metakey)) {
 151              // only process if not empty
 152              $bad_characters = array("\n", "\r", "\"", "<", ">"); // array of characters to remove
 153              $after_clean = JString::str_ireplace($bad_characters, "", $this->metakey); // remove bad characters
 154              $keys = explode(',', $after_clean); // create array using commas as delimiter
 155              $clean_keys = array();
 156              foreach($keys as $key) {
 157                  if (trim($key)) {  // ignore blank keywords
 158                      $clean_keys[] = trim($key);
 159                  }
 160              }
 161              $this->metakey = implode(", ", $clean_keys); // put array back together delimited by ", "
 162          }
 163  
 164          // clean up description -- eliminate quotes and <> brackets
 165          if (!empty($this->metadesc)) {
 166              // only process if not empty
 167              $bad_characters = array("\"", "<", ">");
 168              $this->metadesc = JString::str_ireplace($bad_characters, "", $this->metadesc);
 169          }
 170          return true;
 171      }
 172  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1