[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_weblinks/tables/ -> weblink.php (source)

   1  <?php
   2  /**
   3   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   4   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   5   */
   6  
   7  // No direct access
   8  defined('_JEXEC') or die;
   9  
  10  /**
  11   * Weblink Table class
  12   *
  13   * @package        Joomla.Administrator
  14   * @subpackage    com_weblinks
  15   * @since        1.5
  16   */
  17  class WeblinksTableWeblink extends JTable
  18  {
  19      /**
  20       * Constructor
  21       *
  22       * @param JDatabase A database connector object
  23       */
  24  	public function __construct(&$db)
  25      {
  26          parent::__construct('#__weblinks', 'id', $db);
  27      }
  28  
  29      /**
  30       * Overloaded bind function to pre-process the params.
  31       *
  32       * @param    array        Named array
  33       * @return    null|string    null is operation was satisfactory, otherwise returns an error
  34       * @see        JTable:bind
  35       * @since    1.5
  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          return parent::bind($array, $ignore);
  51      }
  52  
  53  
  54      /**
  55       * Overload the store method for the Weblinks table.
  56       *
  57       * @param    boolean    Toggle whether null values should be updated.
  58       * @return    boolean    True on success, false on failure.
  59       * @since    1.6
  60       */
  61  	public function store($updateNulls = false)
  62      {
  63          $date    = JFactory::getDate();
  64          $user    = JFactory::getUser();
  65          if ($this->id) {
  66              // Existing item
  67              $this->modified        = $date->toSql();
  68              $this->modified_by    = $user->get('id');
  69          } else {
  70              // New weblink. A weblink created and created_by field can be set by the user,
  71              // so we don't touch either of these if they are set.
  72              if (!intval($this->created)) {
  73                  $this->created = $date->toSql();
  74              }
  75              if (empty($this->created_by)) {
  76                  $this->created_by = $user->get('id');
  77              }
  78          }
  79  
  80      // Verify that the alias is unique
  81          $table = JTable::getInstance('Weblink', 'WeblinksTable');
  82          if ($table->load(array('alias'=>$this->alias, 'catid'=>$this->catid)) && ($table->id != $this->id || $this->id==0)) {
  83              $this->setError(JText::_('COM_WEBLINKS_ERROR_UNIQUE_ALIAS'));
  84              return false;
  85          }
  86          // Attempt to store the user data.
  87          return parent::store($updateNulls);
  88      }
  89  
  90      /**
  91       * Overloaded check method to ensure data integrity.
  92       *
  93       * @return    boolean    True on success.
  94       */
  95  	public function check()
  96      {
  97          if (JFilterInput::checkAttribute(array ('href', $this->url))) {
  98              $this->setError(JText::_('COM_WEBLINKS_ERR_TABLES_PROVIDE_URL'));
  99              return false;
 100          }
 101  
 102          // check for valid name
 103          if (trim($this->title) == '') {
 104              $this->setError(JText::_('COM_WEBLINKS_ERR_TABLES_TITLE'));
 105              return false;
 106          }
 107  
 108          // check for existing name
 109          $query = 'SELECT id FROM #__weblinks WHERE title = '.$this->_db->Quote($this->title).' AND catid = '.(int) $this->catid;
 110          $this->_db->setQuery($query);
 111  
 112          $xid = intval($this->_db->loadResult());
 113          if ($xid && $xid != intval($this->id)) {
 114              $this->setError(JText::_('COM_WEBLINKS_ERR_TABLES_NAME'));
 115              return false;
 116          }
 117  
 118          if (empty($this->alias)) {
 119              $this->alias = $this->title;
 120          }
 121          $this->alias = JApplication::stringURLSafe($this->alias);
 122          if (trim(str_replace('-', '', $this->alias)) == '') {
 123              $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s");
 124          }
 125  
 126          // Check the publish down date is not earlier than publish up.
 127          if ($this->publish_down > $this->_db->getNullDate() && $this->publish_down < $this->publish_up) {
 128              $this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
 129              return false;
 130          }
 131  
 132          // clean up keywords -- eliminate extra spaces between phrases
 133          // and cr (\r) and lf (\n) characters from string
 134          if (!empty($this->metakey)) {
 135              // only process if not empty
 136              $bad_characters = array("\n", "\r", "\"", "<", ">"); // array of characters to remove
 137              $after_clean = JString::str_ireplace($bad_characters, "", $this->metakey); // remove bad characters
 138              $keys = explode(',', $after_clean); // create array using commas as delimiter
 139              $clean_keys = array();
 140              foreach($keys as $key) {
 141                  if (trim($key)) {  // ignore blank keywords
 142                      $clean_keys[] = trim($key);
 143                  }
 144              }
 145              $this->metakey = implode(", ", $clean_keys); // put array back together delimited by ", "
 146          }
 147  
 148          return true;
 149      }
 150  
 151      /**
 152       * Method to set the publishing state for a row or list of rows in the database
 153       * table.  The method respects checked out rows by other users and will attempt
 154       * to checkin rows that it can after adjustments are made.
 155       *
 156       * @param    mixed    An optional array of primary key values to update.  If not
 157       *                    set the instance property value is used.
 158       * @param    integer The publishing state. eg. [0 = unpublished, 1 = published]
 159       * @param    integer The user id of the user performing the operation.
 160       * @return    boolean    True on success.
 161       * @since    1.0.4
 162       */
 163  	public function publish($pks = null, $state = 1, $userId = 0)
 164      {
 165          // Initialise variables.
 166          $k = $this->_tbl_key;
 167  
 168          // Sanitize input.
 169          JArrayHelper::toInteger($pks);
 170          $userId = (int) $userId;
 171          $state  = (int) $state;
 172  
 173          // If there are no primary keys set check to see if the instance key is set.
 174          if (empty($pks))
 175          {
 176              if ($this->$k) {
 177                  $pks = array($this->$k);
 178              }
 179              // Nothing to set publishing state on, return false.
 180              else {
 181                  $this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
 182                  return false;
 183              }
 184          }
 185  
 186          // Build the WHERE clause for the primary keys.
 187          $where = $k.'='.implode(' OR '.$k.'=', $pks);
 188  
 189          // Determine if there is checkin support for the table.
 190          if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time')) {
 191              $checkin = '';
 192          }
 193          else {
 194              $checkin = ' AND (checked_out = 0 OR checked_out = '.(int) $userId.')';
 195          }
 196  
 197          // Update the publishing state for rows with the given primary keys.
 198          $this->_db->setQuery(
 199              'UPDATE '.$this->_db->quoteName($this->_tbl) .
 200              ' SET '.$this->_db->quoteName('state').' = '.(int) $state .
 201              ' WHERE ('.$where.')' .
 202              $checkin
 203          );
 204          $this->_db->query();
 205  
 206          // Check for a database error.
 207          if ($this->_db->getErrorNum()) {
 208              $this->setError($this->_db->getErrorMsg());
 209              return false;
 210          }
 211  
 212          // If checkin is supported and all rows were adjusted, check them in.
 213          if ($checkin && (count($pks) == $this->_db->getAffectedRows()))
 214          {
 215              // Checkin the rows.
 216              foreach($pks as $pk)
 217              {
 218                  $this->checkin($pk);
 219              }
 220          }
 221  
 222          // If the JTable instance value is in the list of primary keys that were set, set the instance.
 223          if (in_array($this->$k, $pks)) {
 224              $this->state = $state;
 225          }
 226  
 227          $this->setError('');
 228          return true;
 229      }
 230  }


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