[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_newsfeeds/tables/ -> newsfeed.php (source)

   1  <?php
   2  /**
   3   * @package        Joomla.Administrator
   4   * @subpackage    com_newsfeeds
   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   * @package        Joomla.Administrator
  14   * @subpackage    com_newsfeeds
  15   */
  16  class NewsfeedsTableNewsfeed extends JTable
  17  {
  18      /**
  19       * Constructor
  20       *
  21       * @param JDatabase A database connector object
  22       */
  23  	public function __construct(&$db)
  24      {
  25          parent::__construct('#__newsfeeds', 'id', $db);
  26      }
  27  
  28      /**
  29       * Overloaded bind function to pre-process the params.
  30       *
  31       * @param    array        Named array
  32       * @return    null|string    null is operation was satisfactory, otherwise returns an error
  33       * @see        JTable:bind
  34       * @since    1.5
  35       */
  36  	public function bind($array, $ignore = '')
  37      {
  38          if (isset($array['params']) && is_array($array['params'])) {
  39              $registry = new JRegistry();
  40              $registry->loadArray($array['params']);
  41              $array['params'] = (string) $registry;
  42          }
  43  
  44          if (isset($array['metadata']) && is_array($array['metadata'])) {
  45              $registry = new JRegistry();
  46              $registry->loadArray($array['metadata']);
  47              $array['metadata'] = (string) $registry;
  48          }
  49          return parent::bind($array, $ignore);
  50      }
  51  
  52      /**
  53       * Overloaded check method to ensure data integrity.
  54       *
  55       * @return    boolean    True on success.
  56       */
  57  	function check()
  58      {
  59          // Check for valid name.
  60          if (trim($this->name) == '') {
  61              $this->setError(JText::_('COM_NEWSFEEDS_WARNING_PROVIDE_VALID_NAME'));
  62              return false;
  63          }
  64  
  65          if (empty($this->alias)) {
  66              $this->alias = $this->name;
  67          }
  68          $this->alias = JApplication::stringURLSafe($this->alias);
  69          if (trim(str_replace('-', '', $this->alias)) == '') {
  70              $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s");
  71          }
  72  
  73          // Check the publish down date is not earlier than publish up.
  74          if (intval($this->publish_down) > 0 && $this->publish_down < $this->publish_up) {
  75              $this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
  76              return false;
  77          }
  78  
  79          // clean up keywords -- eliminate extra spaces between phrases
  80          // and cr (\r) and lf (\n) characters from string
  81          if (!empty($this->metakey)) {
  82              // only process if not empty
  83              $bad_characters = array("\n", "\r", "\"", "<", ">"); // array of characters to remove
  84              $after_clean = JString::str_ireplace($bad_characters, "", $this->metakey); // remove bad characters
  85              $keys = explode(',', $after_clean); // create array using commas as delimiter
  86              $clean_keys = array();
  87              foreach($keys as $key) {
  88                  if (trim($key)) {  // ignore blank keywords
  89                      $clean_keys[] = trim($key);
  90                  }
  91              }
  92              $this->metakey = implode(", ", $clean_keys); // put array back together delimited by ", "
  93          }
  94  
  95          // clean up description -- eliminate quotes and <> brackets
  96          if (!empty($this->metadesc)) {
  97              // only process if not empty
  98              $bad_characters = array("\"", "<", ">");
  99              $this->metadesc = JString::str_ireplace($bad_characters, "", $this->metadesc);
 100          }
 101  
 102          return true;
 103      }
 104      /**
 105       * Overriden JTable::store to set modified data and user id.
 106       *
 107       * @param    boolean    True to update fields even if they are null.
 108       * @return    boolean    True on success.
 109       * @since    1.6
 110       */
 111  	public function store($updateNulls = false)
 112      {
 113          $date    = JFactory::getDate();
 114          $user    = JFactory::getUser();
 115          if ($this->id) {
 116              // Existing item
 117              $this->modified        = $date->toSql();
 118              $this->modified_by    = $user->get('id');
 119          } else {
 120              // New newsfeed. A feed created and created_by field can be set by the user,
 121              // so we don't touch either of these if they are set.
 122              if (!intval($this->created)) {
 123                  $this->created = $date->toSql();
 124              }
 125              if (empty($this->created_by)) {
 126                  $this->created_by = $user->get('id');
 127              }
 128          }
 129      // Verify that the alias is unique
 130          $table = JTable::getInstance('Newsfeed', 'NewsfeedsTable');
 131          if ($table->load(array('alias'=>$this->alias, 'catid'=>$this->catid)) && ($table->id != $this->id || $this->id==0)) {
 132              $this->setError(JText::_('COM_NEWSFEEDS_ERROR_UNIQUE_ALIAS'));
 133              return false;
 134          }
 135          return parent::store($updateNulls);
 136      }
 137  
 138  }


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